Python Program: --------------- import math def sieve_of_erastosthenes(num): input_list=[False if i % 2==0 or i % 3==0 or i % 5==0 else True for i in range(num)] input_list[0]=input_list[1]=False input_list[2]=input_list[3]=input_list[5]=True sqrt=math.sqrt(num) for serial in range(3,num,2): if serial>=sqrt : return input_list for s in range(serial**2,num,serial): input_list[s]=False primeTable=sieve_of_erastosthenes(13*(10**5)) while True : k=int(input()) if k==0 : break if primeTable[k]: print(0) else : i=k while primeTable[i]is False : i+=1 j=i-1 while primeTable[j]is False : j-=1 print(i-j) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var primeTable : OclAny := sieve_of_erastosthenes(13 * ((10)->pow(5))) ; while true do ( var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if k = 0 then ( break ) else skip ; if primeTable[k+1] then ( execute (0)->display() ) else ( var i : int := k ; while primeTable[i+1] <>= false do ( i := i + 1) ; var j : double := i - 1 ; while primeTable[j+1] <>= false do ( j := j - 1) ; execute (i - j)->display() )); operation sieve_of_erastosthenes(num : OclAny) : OclAny pre: true post: true activity: var input_list : Sequence := Integer.subrange(0, num-1)->select(i | true)->collect(i | (if i mod 2 = 0 or i mod 3 = 0 or i mod 5 = 0 then false else true endif)) ; input_list->first() := false; var input_list[1+1] : boolean := false ; input_list[2+1] := input_list[2+1](assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name input_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 3))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name input_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 5))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name True))))))))) ; var sqrt : double := (num)->sqrt() ; for serial : Integer.subrange(3, num-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if (serial->compareTo(sqrt)) >= 0 then ( return input_list ) else skip ; for s : Integer.subrange((serial)->pow(2), num-1)->select( $x | ($x - (serial)->pow(2)) mod serial = 0 ) do ( input_list[s+1] := false)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,t=map(int,input().split()) ans=0 inf=pow(10,9)+1 x=inf for i in range(n): s,d=map(int,input().split()) while ss : ans=i+1 x=s print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; var Math_PINFINITY : double := (10)->pow(9) + 1 ; var x : double := Math_PINFINITY ; for i : Integer.subrange(0, n-1) do ( var s : OclAny := null; var d : OclAny := null; Sequence{s,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; while (s->compareTo(t)) < 0 do ( s := s + d) ; if (x->compareTo(s)) > 0 then ( ans := i + 1 ; x := s ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import collections stdin=sys.stdin ns=lambda : stdin.readline().rstrip() ni=lambda : int(stdin.readline().rstrip()) nm=lambda : map(int,stdin.readline().split()) nl=lambda : list(map(int,stdin.readline().split())) x,y=nm() if(x>y): print("safe") else : print("unsafe") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var stdin : OclFile := OclFile["System.in"] ; var ns : Function := lambda $$ : OclAny in (stdin.readLine().rstrip()) ; var ni : Function := lambda $$ : OclAny in (("" + ((stdin.readLine().rstrip())))->toInteger()) ; var nm : Function := lambda $$ : OclAny in ((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var nl : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := nm->apply() ; if ((x->compareTo(y)) > 0) then ( execute ("safe")->display() ) else ( execute ("unsafe")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,a,b,c,d=map(int,input().split()) def fprice(n,p): count=0 price=0 while N>count : count+=n price+=p return price if fprice(a,b)>=fprice(c,d): print(fprice(c,d)) else : print(fprice(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{N,a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; if (fprice(a, b)->compareTo(fprice(c, d))) >= 0 then ( execute (fprice(c, d))->display() ) else ( execute (fprice(a, b))->display() ); operation fprice(n : OclAny, p : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var price : int := 0 ; while (N->compareTo(count)) > 0 do ( count := count + n ; price := price + p) ; return price; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,*A=map(int,open(0).read().split()) ans=0 for a in A : while True : a,r=divmod(a,2) if r==1 : break ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var A : OclAny := null; Sequence{n,A} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; for a : A do ( while true do ( var a : OclAny := null; var r : OclAny := null; Sequence{a,r} := Sequence{(a div 2), (a mod 2)} ; if r = 1 then ( break ) else skip ; ans := ans + 1)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): sum1=sum2=0 n=int(input()) if(n % 4!=0): print('NO') else : print('YES') for i in range(2,n+1,2): print(i,end=' ') sum1+=i for i in range(1,n-2,2): print(i,end=' ') sum2+=i print(sum1-sum2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var sum1 : OclAny := 0; var sum2 : int := 0 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n mod 4 /= 0) then ( execute ('NO')->display() ) else ( execute ('YES')->display() ; for i : Integer.subrange(2, n + 1-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( execute (i)->display() ; sum1 := sum1 + i) ; for i : Integer.subrange(1, n - 2-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( execute (i)->display() ; sum2 := sum2 + i) ; execute (sum1 - sum2)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect def getPairs(A,B,n): D=[0]*(n) for i in range(n): D[i]=A[i]-B[i] D.sort() total=0 for i in range(n-1,-1,-1): if(D[i]>0): total+=n-i-1 else : k=bisect.bisect_right(D,-D[i],0,len(D)) total+=n-k return total if __name__=="__main__" : n=5 A=[] B=[] A.append(4); A.append(8); A.append(2); A.append(6); A.append(2); B.append(4); B.append(5); B.append(4); B.append(1); B.append(3); print(getPairs(A,B,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 5 ; A := Sequence{} ; B := Sequence{} ; execute ((4) : A); ; execute ((8) : A); ; execute ((2) : A); ; execute ((6) : A); ; execute ((2) : A); ; execute ((4) : B); ; execute ((5) : B); ; execute ((4) : B); ; execute ((1) : B); ; execute ((3) : B); ; execute (getPairs(A, B, n))->display() ) else skip; operation getPairs(A : OclAny, B : OclAny, n : OclAny) : OclAny pre: true post: true activity: var D : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n)) ; for i : Integer.subrange(0, n-1) do ( D[i+1] := A[i+1] - B[i+1]) ; D := D->sort() ; var total : int := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (D[i+1] > 0) then ( total := total + n - i - 1 ) else ( var k : OclAny := bisect.bisect_right(D, -D[i+1], 0, (D)->size()) ; total := total + n - k )) ; return total; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findZeroes(arr,n,m): wL=wR=0 bestL=bestWindow=0 zeroCount=0 while wRm : if arr[wL]==0 : zeroCount-=1 wL+=1 if(wR-wL>bestWindow)and(zeroCount<=m): bestWindow=wR-wL bestL=wL for i in range(0,bestWindow): if arr[bestL+i]==0 : print(bestL+i,end=" ") arr=[1,0,0,1,1,0,1,0,1,1] m=2 n=len(arr) print("Indexes of zeroes to be flipped are",end=" ") findZeroes(arr,n,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 1 }))))))))) ; m := 2 ; n := (arr)->size() ; execute ("Indexes of zeroes to be flipped are")->display() ; findZeroes(arr, n, m); operation findZeroes(arr : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: var wL : OclAny := 0; var wR : int := 0 ; var bestL : OclAny := 0; var bestWindow : int := 0 ; var zeroCount : int := 0 ; while (wR->compareTo(n)) < 0 do ( if (zeroCount->compareTo(m)) <= 0 then ( if arr[wR+1] = 0 then ( zeroCount := zeroCount + 1 ) else skip ; wR := wR + 1 ) else skip ; if (zeroCount->compareTo(m)) > 0 then ( if arr[wL+1] = 0 then ( zeroCount := zeroCount - 1 ) else skip ; wL := wL + 1 ) else skip ; if ((wR - wL->compareTo(bestWindow)) > 0) & ((zeroCount->compareTo(m)) <= 0) then ( bestWindow := wR - wL ; bestL := wL ) else skip) ; for i : Integer.subrange(0, bestWindow-1) do ( if arr[bestL + i+1] = 0 then ( execute (bestL + i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100006 ; count=[0]*MAX ; def sieve(): i=2 ; while(i*i<=MAX): if(count[i]==0): for j in range(2*i,MAX,i): count[j]+=1 ; count[i]=1 ; i+=1 ; def query(l,r): sum=0 ; for i in range(l,r+1): sum+=count[i]; return sum ; sieve(); print(query(6,10),query(1,5)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 100006; ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX); ; skip ; skip ; sieve(); ; execute (query(6, 10))->display();; operation sieve() pre: true post: true activity: var i : int := 2; ; while ((i * i->compareTo(MAX)) <= 0) do ( if (count[i+1] = 0) then ( for j : Integer.subrange(2 * i, MAX-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ( count[j+1] := count[j+1] + 1;) ; count[i+1] := 1; ) else skip ; i := i + 1;); operation query(l : OclAny, r : OclAny) pre: true post: true activity: var sum : int := 0; ; for i : Integer.subrange(l, r + 1-1) do ( sum := sum + count[i+1];) ; return sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) cnt21=n % 2020 cnt20=(n-cnt21)/2020-cnt21 if cnt20>=0 and(cnt21*2021)+(cnt20*2020)==n : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cnt21 : int := n mod 2020 ; var cnt20 : double := (n - cnt21) / 2020 - cnt21 ; if cnt20 >= 0 & (cnt21 * 2021) + (cnt20 * 2020) = n then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) y=n % 2020 x=(n-y)/2020-y if x>=0 and 2020*x+2021*y==n : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var y : int := n mod 2020 ; var x : double := (n - y) / 2020 - y ; if x >= 0 & 2020 * x + 2021 * y = n then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) z=1 while(z<=t): n=int(input()) a=n//2020 b=n % 2020 if(b<=a): print("yes") else : print("no") z=z+1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var z : int := 1 ; while ((z->compareTo(t)) <= 0) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := n div 2020 ; var b : int := n mod 2020 ; if ((b->compareTo(a)) <= 0) then ( execute ("yes")->display() ) else ( execute ("no")->display() ) ; z := z + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) cnt2021=n % 2020 cnt2020=(n-cnt2021)/2020-cnt2021 if(cnt2020>=0 and cnt2020*2020+cnt2021*2021): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cnt2021 : int := n mod 2020 ; var cnt2020 : double := (n - cnt2021) / 2020 - cnt2021 ; if (cnt2020 >= 0 & cnt2020 * 2020 + cnt2021 * 2021) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (w,h,n)=map(int,input().split()) (x,y,a)=zip(*[map(int,input().split())for _ in range(n)]) x_min=0 x_max=w y_min=0 y_max=h for i in range(n): if a[i]==1 : x_min=max(x_min,x[i]) elif a[i]==2 : x_max=min(x_max,x[i]) elif a[i]==3 : y_min=max(y_min,y[i]) else : y_max=min(y_max,y[i]) if x_max>x_min : x_delta=x_max-x_min else : x_delta=0 if y_max>y_min : y_delta=y_max-y_min else : y_delta=0 print(x_delta*y_delta) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{w, h, n} : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var Sequence{x, y, a} : Sequence := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) ]))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) ]))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) ]))))))`third->at(_indx)} ) ; var x_min : int := 0 ; var x_max : OclAny := w ; var y_min : int := 0 ; var y_max : OclAny := h ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = 1 then ( x_min := Set{x_min, x[i+1]}->max() ) else (if a[i+1] = 2 then ( x_max := Set{x_max, x[i+1]}->min() ) else (if a[i+1] = 3 then ( y_min := Set{y_min, y[i+1]}->max() ) else ( y_max := Set{y_max, y[i+1]}->min() ) ) ) ) ; if (x_max->compareTo(x_min)) > 0 then ( var x_delta : double := x_max - x_min ) else ( x_delta := 0 ) ; if (y_max->compareTo(y_min)) > 0 then ( var y_delta : double := y_max - y_min ) else ( y_delta := 0 ) ; execute (x_delta * y_delta)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def mul_table(N,i): if(i>10): return print(N,"*",i,"=",N*i) return mul_table(N,i+1) N=8 mul_table(N,1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 8 ; mul_table(N, 1); operation mul_table(N : OclAny, i : OclAny) : OclAny pre: true post: true activity: if (i > 10) then ( return ) else skip ; execute (N)->display() ; return mul_table(N, i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from math import gcd,pi,sqrt INF=float("inf") import sys sys.setrecursionlimit(10**6) import itertools from collections import Counter,deque def i_input(): return int(input()) def i_map(): return map(int,input().split()) def i_list(): return list(i_map()) def i_row(N): return[i_input()for _ in range(N)] def i_row_list(N): return[i_list()for _ in range(N)] def s_input(): return input() def s_map(): return input().split() def s_list(): return list(s_map()) def s_row(N): return[s_input for _ in range(N)] def s_row_str(N): return[s_list()for _ in range(N)] def s_row_list(N): return[list(s_input())for _ in range(N)] def main(): w,h,n=i_map() up=h right=w down=0 left=0 for i in range(n): x,y,a=i_map() if a==1 : left=max(left,x) elif a==2 : right=min(right,x) elif a==3 : down=max(down,y) else : up=min(up,y) print(max((up-down),0)*max((right-left),0)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var INF : double := ("" + (("inf")))->toReal() ; skip ; sys.setrecursionlimit((10)->pow(6)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation i_input() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation i_map() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation i_list() : OclAny pre: true post: true activity: return (i_map()); operation i_row(N : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (i_input())); operation i_row_list(N : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (i_list())); operation s_input() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation s_map() : OclAny pre: true post: true activity: return input().split(); operation s_list() : OclAny pre: true post: true activity: return (s_map()); operation s_row(N : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (s_input)); operation s_row_str(N : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (s_list())); operation s_row_list(N : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | ((s_input()))); operation main() pre: true post: true activity: var w : OclAny := null; var h : OclAny := null; var n : OclAny := null; Sequence{w,h,n} := i_map() ; var up : OclAny := h ; var right : OclAny := w ; var down : int := 0 ; var left : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; var a : OclAny := null; Sequence{x,y,a} := i_map() ; if a = 1 then ( left := Set{left, x}->max() ) else (if a = 2 then ( right := Set{right, x}->min() ) else (if a = 3 then ( down := Set{down, y}->max() ) else ( up := Set{up, y}->min() ) ) ) ) ; execute (Set{(up - down), 0}->max() * Set{(right - left), 0}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np W,H,N=[int(x)for x in input().split()] matrix=np.array([[1 for i in range(W)]for j in range(H)]) rects=[] for i in range(N): rects.append([int(x)for x in input().split()]) for rect in rects : if rect[2]==1 : matrix[:,: rect[0]]=0 elif rect[2]==2 : matrix[:,rect[0]:]=0 elif rect[2]==3 : matrix[: rect[1],:]=0 elif rect[2]==4 : matrix[rect[1]:,:]=0 print(sum(sum(matrix))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var W : OclAny := null; var H : OclAny := null; var N : OclAny := null; Sequence{W,H,N} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var matrix : Sequence := (Integer.subrange(0, H-1)->select(j | true)->collect(j | (Integer.subrange(0, W-1)->select(i | true)->collect(i | (1))))) ; var rects : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute ((input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) : rects)) ; for rect : rects do ( if rect[2+1] = 1 then ( matrix->collect( _r | _r.subrange(1,rect->first()) ) := 0 ) else (if rect[2+1] = 2 then ( matrix->collect( _r | _r.subrange(rect->first()+1) ) := 0 ) else (if rect[2+1] = 3 then ( matrix.subrange(1,rect[1+1]) := 0 ) else (if rect[2+1] = 4 then ( matrix.subrange(rect[1+1]+1) := 0 ) else skip ) ) ) ) ; execute (((matrix)->sum())->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) if((n//2)% 2!=0): print("NO") else : l=list(range(2,n+1,2)) m=list(range(1,n,2)) a=m.pop() a=a+n//2 m.append(a) print("YES") z=l+m print(*z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if ((n div 2) mod 2 /= 0) then ( execute ("NO")->display() ) else ( var l : Sequence := (Integer.subrange(2, n + 1-1)->select( $x | ($x - 2) mod 2 = 0 )) ; var m : Sequence := (Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 2 = 0 )) ; var a : OclAny := m->last() ; m := m->front() ; a := a + n div 2 ; execute ((a) : m) ; execute ("YES")->display() ; var z : Sequence := l->union(m) ; execute ((argument * (test (logical_test (comparison (expr (atom (name z))))))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w,h,n=map(int,input().split()) x1=0 y1=0 x2=w y2=h f=0 for i in range(n): x,y,a=map(int,input().split()) if a==1 : x1=max(x,x1) elif a==2 : x2=min(x,x2) elif a==3 : y1=max(y,y1) elif a==4 : y2=min(y,y2) if x1>=x2 or y1>=y2 or x2<=0 or y2<=0 : f=1 if f : print("0") else : print((x2-x1)*(y2-y1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : OclAny := null; var h : OclAny := null; var n : OclAny := null; Sequence{w,h,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x1 : int := 0 ; var y1 : int := 0 ; var x2 : OclAny := w ; var y2 : OclAny := h ; var f : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; var a : OclAny := null; Sequence{x,y,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 1 then ( x1 := Set{x, x1}->max() ) else (if a = 2 then ( x2 := Set{x, x2}->min() ) else (if a = 3 then ( y1 := Set{y, y1}->max() ) else (if a = 4 then ( y2 := Set{y, y2}->min() ) else skip ) ) ) ; if (x1->compareTo(x2)) >= 0 or (y1->compareTo(y2)) >= 0 or x2 <= 0 or y2 <= 0 then ( f := 1 ) else skip) ; if f then ( execute ("0")->display() ) else ( execute ((x2 - x1) * (y2 - y1))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w,h,n=map(int,input().split()) xya=[list(map(int,input().split()))for i in range(n)] l=[["." for i in range(w)]for j in range(h)] for i in range(n): if xya[i][2]==1 : l=[["#" if j=xya[i][0]else "#" if l[k][j]=="#" else "." for j in range(w)]for k in range(h)] elif xya[i][2]==3 : l=[["#" if k=xya[i][1]else "#" if l[k][j]=="#" else "." for j in range(w)]for k in range(h)] ans=0 for i in range(h): for j in range(w): if l[i][j]=="." : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : OclAny := null; var h : OclAny := null; var n : OclAny := null; Sequence{w,h,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var xya : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var l : Sequence := Integer.subrange(0, h-1)->select(j | true)->collect(j | (Integer.subrange(0, w-1)->select(i | true)->collect(i | (".")))) ; for i : Integer.subrange(0, n-1) do ( if xya[i+1][2+1] = 1 then ( l := Integer.subrange(0, h-1)->select(k | true)->collect(k | (Integer.subrange(0, w-1)->select(j | true)->collect(j | (if (j->compareTo(xya[i+1]->first())) < 0 then "#" else if l[k+1][j+1] = "#" then "#" else "." endif endif)))) ) else (if xya[i+1][2+1] = 2 then ( l := Integer.subrange(0, h-1)->select(k | true)->collect(k | (Integer.subrange(0, w-1)->select(j | true)->collect(j | (if (j->compareTo(xya[i+1]->first())) >= 0 then "#" else if l[k+1][j+1] = "#" then "#" else "." endif endif)))) ) else (if xya[i+1][2+1] = 3 then ( l := Integer.subrange(0, h-1)->select(k | true)->collect(k | (Integer.subrange(0, w-1)->select(j | true)->collect(j | (if (k->compareTo(xya[i+1][1+1])) < 0 then "#" else if l[k+1][j+1] = "#" then "#" else "." endif endif)))) ) else (if xya[i+1][2+1] = 4 then ( l := Integer.subrange(0, h-1)->select(k | true)->collect(k | (Integer.subrange(0, w-1)->select(j | true)->collect(j | (if (k->compareTo(xya[i+1][1+1])) >= 0 then "#" else if l[k+1][j+1] = "#" then "#" else "." endif endif)))) ) else skip ) ) ) ) ; var ans : int := 0 ; for i : Integer.subrange(0, h-1) do ( for j : Integer.subrange(0, w-1) do ( if l[i+1][j+1] = "." then ( ans := ans + 1 ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) y=x-2 if x % 7==6 : z=1 else : z=0 if x % 7==1 : z1=1 else : z1=0 print((x//7)*2+z,end=' ') print(2+(y//7)*2+z1 if x>=7 else 1 if x==1 else 2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var y : double := x - 2 ; if x mod 7 = 6 then ( var z : int := 1 ) else ( z := 0 ) ; if x mod 7 = 1 then ( var z1 : int := 1 ) else ( z1 := 0 ) ; execute ((x div 7) * 2 + z)->display() ; execute (if x >= 7 then 2 + (y div 7) * 2 + z1 else if x = 1 then 1 else 2 endif endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==1 : print(0,1) else : min_holidays=(n//7)*2+(n % 7-5)if n % 7-5>0 else(n//7)*2 max_holidays=2+((n-2)//7)*2+((n-2)% 7-5)if(n-2)% 7-5>0 else 2+((n-2)//7)*2 print(min_holidays,max_holidays) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (0)->display() ) else ( var min_holidays : int := if n mod 7 - 5 > 0 then (n div 7) * 2 + (n mod 7 - 5) else (n div 7) * 2 endif ; var max_holidays : int := if (n - 2) mod 7 - 5 > 0 then 2 + ((n - 2) div 7) * 2 + ((n - 2) mod 7 - 5) else 2 + ((n - 2) div 7) * 2 endif ; execute (min_holidays)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) r=n % 7 q=int(n/7) if r>=2 : k=2 else : k=r maxi=(2*q)+k mini=2*q if r==6 : mini+=1 print(mini,maxi) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r : int := n mod 7 ; var q : int := ("" + ((n / 7)))->toInteger() ; if r >= 2 then ( var k : int := 2 ) else ( k := r ) ; var maxi : int := (2 * q) + k ; var mini : int := 2 * q ; if r = 6 then ( mini := mini + 1 ) else skip ; execute (mini)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(n//7+(n+1)//7,(n+5)//7+(n+6)//7) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n div 7 + (n + 1) div 7)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import os import random import re import sys from math import gcd from math import sqrt n=int(input()) a=n//7*2 ans=n//7 if n % 7==6 : a+=1 b=(n-2)//7*2+2 if(n-2)% 7==6 : b+=1 print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := n div 7 * 2 ; var ans : int := n div 7 ; if n mod 7 = 6 then ( a := a + 1 ) else skip ; var b : int := (n - 2) div 7 * 2 + 2 ; if (n - 2) mod 7 = 6 then ( b := b + 1 ) else skip ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=list(map(int,input().split())) if k==1 : print(min(a[0 : n])) elif k==2 : print(max(a[0],a[n-1])) else : print(max(a[0 : n])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if k = 1 then ( execute ((a.subrange(0+1, n))->min())->display() ) else (if k = 2 then ( execute (Set{a->first(), a[n - 1+1]}->max())->display() ) else ( execute ((a.subrange(0+1, n))->max())->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (lambda _,L : print(sum(L[0 : : 2])-sum(L[1 : : 2])))(input(),sorted([int(i)for i in input().split()],reverse=True)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: (lambda _anon : OclAny, L : OclAny in (((L(subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->sum() - (L(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->sum())->display()))((OclFile["System.in"]).readLine(), input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import floor,ceil,sqrt,factorial,log,gcd from itertools import accumulate,permutations,combinations,product,combinations_with_replacement from bisect import bisect_left,bisect_right from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heappushpop,heapify import copy import sys INF=float('inf') mod=10**9+7 sys.setrecursionlimit(10**6) def lcm(a,b): return a*b/gcd(a,b) def LI(): return list(map(int,sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] def SRL(n): return[list(S())for i in range(n)] def main(): n=I() a=sorted(LI(),reverse=True) alice=0 for i in range(0,n,2): alice+=a[i] print(2*alice-sum(a)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; sys.setrecursionlimit((10)->pow(6)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a * b / gcd(a, b); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation I() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.buffer.readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.buffer.readLine().rstrip().decode('utf-8').split(); operation S() : OclAny pre: true post: true activity: return sys.stdin.buffer.readLine().rstrip().decode('utf-8'); operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation SRL(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | ((S()))); operation main() pre: true post: true activity: n := I() ; a := LI()->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var alice : int := 0 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( alice := alice + a[i+1]) ; execute (2 * alice - (a)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) a=list(map(int,input().split())) a.sort() alice=0 bob=0 flag=0 for i in range(N): if flag==0 : alice+=a[N-(i+1)] flag=1 else : bob+=a[N-(i+1)] flag=0 print(alice-bob) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var alice : int := 0 ; var bob : int := 0 ; var flag : int := 0 ; for i : Integer.subrange(0, N-1) do ( if flag = 0 then ( alice := alice + a[N - (i + 1)+1] ; flag := 1 ) else ( bob := bob + a[N - (i + 1)+1] ; flag := 0 )) ; execute (alice - bob)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sol(n): if n==2 or(n//2)% 2==1 : return "NO" else : p=[str(_)for _ in range(2,n+1)if _ % 2==0] q=[str(int(p[_])-1)for _ in range(len(p)-1)] q.append(str(int(p[-1])+(len(p)-1))) return "YES"+"\n"+" ".join(p+q) t=int(input()) for _ in range(t): n=int(input()) print(sol(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (sol(n))->display()); operation sol(n : OclAny) : OclAny pre: true post: true activity: if n = 2 or (n div 2) mod 2 = 1 then ( return "NO" ) else ( var p : Sequence := Integer.subrange(2, n + 1-1)->select(_anon | _anon mod 2 = 0)->collect(_anon | (("" + ((_anon))))) ; var q : Sequence := Integer.subrange(0, (p)->size() - 1-1)->select(_anon | true)->collect(_anon | (("" + ((("" + ((p[_anon+1])))->toInteger() - 1))))) ; execute ((("" + ((("" + ((p->last())))->toInteger() + ((p)->size() - 1))))) : q) ; return "YES" + "\n" + StringLib.sumStringsWithSeparator((p->union(q)), " ") ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=(int)(input()) array=[] array_=input().split() for i in range(N): array.append((int)(array_[i])) array.sort(reverse=True) sum=0 for i in range(N): sum=sum+array[i]*(-1)**i print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := (OclType["int"])((OclFile["System.in"]).readLine()) ; var array : Sequence := Sequence{} ; var array_ : OclAny := input().split() ; for i : Integer.subrange(0, N-1) do ( execute (((OclType["int"])(array_[i+1])) : array)) ; array := array->sort() ; var sum : int := 0 ; for i : Integer.subrange(0, N-1) do ( sum := sum + array[i+1] * ((-1))->pow(i)) ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) A=sorted(list(map(int,input().split())),reverse=True) alice=sum(A[: : 2]) bob=sum(A[1 : : 2]) print(alice-bob) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var alice : OclAny := (A(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->sum() ; var bob : OclAny := (A(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->sum() ; execute (alice - bob)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) a,a1=map(int,input().split()) b,b1=map(int,input().split()) c,c1=map(int,input().split()) if(c+c1==a+a1): print('NO') elif(c/c1==a/a1): print('NO') elif((c-a)//abs(c-a)!=(b-a)//abs(b-a))or((c1-a1)//abs(c1-a1)!=(b1-a1)//abs(b1-a1)): print('NO') else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := null; var a1 : OclAny := null; Sequence{a,a1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : OclAny := null; var b1 : OclAny := null; Sequence{b,b1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : OclAny := null; var c1 : OclAny := null; Sequence{c,c1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (c + c1 = a + a1) then ( execute ('NO')->display() ) else (if (c / c1 = a / a1) then ( execute ('NO')->display() ) else (if ((c - a) div (c - a)->abs() /= (b - a) div (b - a)->abs()) or ((c1 - a1) div (c1 - a1)->abs() /= (b1 - a1) div (b1 - a1)->abs()) then ( execute ('NO')->display() ) else ( execute ('YES')->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ax,ay=map(int,input().split()) bx,by=map(int,input().split()) cx,cy=map(int,input().split()) if(1<=bxtoInteger() ; var ax : OclAny := null; var ay : OclAny := null; Sequence{ax,ay} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var bx : OclAny := null; var by : OclAny := null; Sequence{bx,by} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cx : OclAny := null; var cy : OclAny := null; Sequence{cx,cy} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (1 <= bx & (bx < ax) & 1 <= cx & (cx < ax)) & (1 <= by & (by < ay) & 1 <= cy & (cy < ay)) then ( execute ('YES')->display() ; exit(0) ) else (if (1 <= bx & (bx < ax) & 1 <= cx & (cx < ax)) & ((ay->compareTo(by)) < 0 & (by <= n) & (ay->compareTo(cy)) < 0 & (cy <= n)) then ( execute ('YES')->display() ; exit(0) ) else (if ((ax->compareTo(bx)) < 0 & (bx <= n) & (ax->compareTo(cx)) < 0 & (cx <= n)) & (1 <= by & (by < ay) & 1 <= cy & (cy < ay)) then ( execute ('YES')->display() ; exit(0) ) else (if ((ax->compareTo(bx)) < 0 & (bx <= n) & (ax->compareTo(cx)) < 0 & (cx <= n)) & ((ay->compareTo(by)) < 0 & (by <= n) & (ay->compareTo(cy)) < 0 & (cy <= n)) then ( execute ('YES')->display() ; exit(0) ) else ( execute ('NO')->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ax,ay=map(int,input().split()) bx,by=map(int,input().split()) cx,cy=map(int,input().split()) if(bx-ax)*(cx-ax)>0 and(by-ay)*(cy-ay)>0 : print("yes") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ax : OclAny := null; var ay : OclAny := null; Sequence{ax,ay} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var bx : OclAny := null; var by : OclAny := null; Sequence{bx,by} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cx : OclAny := null; var cy : OclAny := null; Sequence{cx,cy} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (bx - ax) * (cx - ax) > 0 & (by - ay) * (cy - ay) > 0 then ( execute ("yes")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,threading sys.setrecursionlimit(2147483647) input=sys.stdin.readline def print(*args,end='\n',sep=' ')->None : sys.stdout.write(sep.join(map(str,args))+end) def Solve(): n=int(input()) ax,ay=list(map(int,input().split())) bx,by=list(map(int,input().split())) cx,cy=list(map(int,input().split())) if bxax or cy>ay : print("NO") else : print("YES") elif bxay : if cx>ax or cyax and byay : print("NO") else : print("YES") else : if cxpow(8)) ; (expr (atom (name threading)) (trailer . (name Thread) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name Solve)))))))) ))) (trailer . (name start) (arguments ( )))) ) else skip; (funcdef def name print ( (typedargslist (args * (named_parameter (name args))) , (def_parameters (def_parameter (named_parameter (name end)) = (test (logical_test (comparison (expr (atom ' ')))))) , (def_parameter (named_parameter (name sep)) = (test (logical_test (comparison (expr (atom ' ')))))))) ) -> (test (logical_test (comparison (expr (atom None))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name sep)) (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name args)))))))) ))))))))) )))) + (expr (atom (name end))))))))) )))))))))))))) operation Solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ax : OclAny := null; var ay : OclAny := null; Sequence{ax,ay} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var bx : OclAny := null; var by : OclAny := null; Sequence{bx,by} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cx : OclAny := null; var cy : OclAny := null; Sequence{cx,cy} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (bx->compareTo(ax)) < 0 & (by->compareTo(ay)) < 0 then ( if (cx->compareTo(ax)) > 0 or (cy->compareTo(ay)) > 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ) ) else (if (bx->compareTo(ax)) < 0 & (by->compareTo(ay)) > 0 then ( if (cx->compareTo(ax)) > 0 or (cy->compareTo(ay)) < 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ) ) else (if (bx->compareTo(ax)) > 0 & (by->compareTo(ay)) < 0 then ( if (cx->compareTo(ax)) < 0 or (cy->compareTo(ay)) > 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ) ) else ( if (cx->compareTo(ax)) < 0 or (cy->compareTo(ay)) < 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,A,B,C,D=map(int,input().split()) print(min((N+A-1)//A*B,(N+C-1)//C*D)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var D : OclAny := null; Sequence{N,A,B,C,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{(N + A - 1) div A * B, (N + C - 1) div C * D}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[] a=list(map(int,input().split())) ax=a[0] ay=a[1] b=[] b=list(map(int,input().split())) c=[] c=list(map(int,input().split())) bx=b[0] by=b[1] cx=c[0] cy=c[1] ntbv=[] if(((bxax)or(by>ay))and((cx>ax)or(cy>ay))): if(bxtoInteger() ; var a : Sequence := Sequence{} ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ax : OclAny := a->first() ; var ay : OclAny := a[1+1] ; var b : Sequence := Sequence{} ; b := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : Sequence := Sequence{} ; c := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var bx : OclAny := b->first() ; var by : OclAny := b[1+1] ; var cx : OclAny := c->first() ; var cy : OclAny := c[1+1] ; var ntbv : Sequence := Sequence{} ; if ((((bx->compareTo(ax)) < 0) & ((by->compareTo(ay)) < 0)) & (((cx->compareTo(ax)) < 0) & ((cy->compareTo(ay)) < 0))) then ( execute ("Yes")->display() ) else (if ((((bx->compareTo(ax)) > 0) or ((by->compareTo(ay)) > 0)) & (((cx->compareTo(ax)) > 0) or ((cy->compareTo(ay)) > 0))) then ( if ((bx->compareTo(ax)) < 0 & (ax < cx)) or ((cx->compareTo(ax)) < 0 & (ax < bx)) then ( execute ("No")->display() ) else (if ((by->compareTo(ay)) < 0 & (ay < cy)) or ((cy->compareTo(ay)) < 0 & (ay < by)) then ( execute ("No")->display() ) else ( execute ("Yes")->display() ) ) ) else ( execute ("No")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def smallestNumber(num): num=list(num) n=len(num) rightMin=[0]*n right=0 rightMin[n-1]=-1 ; right=n-1 ; for i in range(n-2,0,-1): if num[i]>num[right]: rightMin[i]=right else : rightMin[i]=-1 right=i small=-1 for i in range(1,n): if num[i]!='0' : if small==-1 : if num[i]display() ) else skip; operation smallestNumber(num : OclAny) : OclAny pre: true post: true activity: num := (num) ; var n : int := (num)->size() ; var rightMin : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var right : int := 0 ; rightMin[n - 1+1] := -1; ; right := n - 1; ; for i : Integer.subrange(0 + 1, n - 2)->reverse() do ( if (num[i+1]->compareTo(num[right+1])) > 0 then ( rightMin[i+1] := right ) else ( rightMin[i+1] := -1 ; right := i )) ; var small : int := -1 ; for i : Integer.subrange(1, n-1) do ( if num[i+1] /= '0' then ( if small = -1 then ( if (num[i+1]->compareTo(num->first())) < 0 then ( small := i ) else skip ) else (if (num[i+1]->compareTo(num[small+1])) < 0 then ( small := i ) else skip) ) else skip) ; if small /= -1 then ( var num->first() : OclAny := null; var num[small+1] : OclAny := null; Sequence{num->first(),num[small+1]} := Sequence{num[small+1],num->first()} ) else ( for i : Integer.subrange(1, n-1) do ( if rightMin[i+1] /= -1 then ( var num[i+1] : OclAny := null; var num[rightMin[i+1]+1] : OclAny := null; Sequence{num[i+1],num[rightMin[i+1]+1]} := Sequence{num[rightMin[i+1]+1],num[i+1]} ; break ) else skip) ) ; return StringLib.sumStringsWithSeparator((num), ''); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def sumOfDiv(x): sum=1 ; for i in range(2,int(math.sqrt(x))): if x % i==0 : sum+=i if i!=x/i : sum+=x/i return int(sum); def isAmbicle(a,b): return(sumOfDiv(a)==b and sumOfDiv(b)==a) def countPairs(arr,n): s=set() count=0 for i in range(n): s.add(arr[i]) for i in range(n): if sumOfDiv(arr[i])in s : sum=sumOfDiv(arr[i]) if isAmbicle(arr[i],sum): count+=1 return int(count/2); arr1=[220,284,1184,1210,2,5] n1=len(arr1) print(countPairs(arr1,n1)) arr2=[2620,2924,5020,5564,6232,6368] n2=len(arr2) print(countPairs(arr2,n2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var arr1 : Sequence := Sequence{220}->union(Sequence{284}->union(Sequence{1184}->union(Sequence{1210}->union(Sequence{2}->union(Sequence{ 5 }))))) ; var n1 : int := (arr1)->size() ; execute (countPairs(arr1, n1))->display() ; var arr2 : Sequence := Sequence{2620}->union(Sequence{2924}->union(Sequence{5020}->union(Sequence{5564}->union(Sequence{6232}->union(Sequence{ 6368 }))))) ; var n2 : int := (arr2)->size() ; execute (countPairs(arr2, n2))->display(); operation sumOfDiv(x : OclAny) pre: true post: true activity: var sum : int := 1; ; for i : Integer.subrange(2, ("" + (((x)->sqrt())))->toInteger()-1) do ( if x mod i = 0 then ( sum := sum + i ; if i /= x / i then ( sum := sum + x / i ) else skip ) else skip) ; return ("" + ((sum)))->toInteger();; operation isAmbicle(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (sumOfDiv(a) = b & sumOfDiv(b) = a); operation countPairs(arr : OclAny, n : OclAny) pre: true post: true activity: var s : Set := Set{}->union(()) ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( execute ((arr[i+1]) : s)) ; for i : Integer.subrange(0, n-1) do ( if (s)->includes(sumOfDiv(arr[i+1])) then ( sum := sumOfDiv(arr[i+1]) ; if isAmbicle(arr[i+1], sum) then ( count := count + 1 ) else skip ) else skip) ; return ("" + ((count / 2)))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=map(int,input().split()) ans=t0=f0=num=0 for i in range(n): t,f=map(int,input().split()) f-=1 df=f-f0 if df<0 : df=-df dt=t-t0 if dt=f0+f : ans+=num*f0 num=0 else : if num+1>d : ans=-1 ; break ans+=num*dt f0,t0=f,t num+=1 print(-1 if ans<0 else ans+num*f0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; ans := ans(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name t0)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name f0)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name num)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for i : Integer.subrange(0, n-1) do ( var t : OclAny := null; var f : OclAny := null; Sequence{t,f} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; f := f - 1 ; var df : double := f - f0 ; if df < 0 then ( df := -df ) else skip ; var dt : double := t - t0 ; if (dt->compareTo(df)) < 0 then ( var ans : int := -1; break ) else skip ; if (dt->compareTo(f0 + f)) >= 0 then ( ans := ans + num * f0 ; var num : int := 0 ) else ( if (num + 1->compareTo(d)) > 0 then ( ans := -1; break ) else skip ; ans := ans + num * dt ) ; var f0 : OclAny := null; var t0 : OclAny := null; Sequence{f0,t0} := Sequence{f,t} ; num := num + 1) ; execute (if ans < 0 then -1 else ans + num * f0 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline x,y=[],[] n=int(input()) for i in range(n): a,b=map(int,input().split()) x.append(a+b) y.append(a-b) xmin,xmax=min(x),max(x) ymin,ymax=min(y),max(y) ans1=ans2=0 for i in range(n): d1=max(x[i]-xmin,y[i]-ymin) d2=max(xmax-x[i],ymax-y[i]) ans1=max(ans1,min(d1,d2)) d1=max(x[i]-xmin,ymax-y[i]) d2=max(xmax-x[i],y[i]-ymin) ans2=max(ans2,min(d1,d2)) print(min(ans1,ans2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{Sequence{},Sequence{}} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a + b) : x) ; execute ((a - b) : y)) ; var xmin : OclAny := null; var xmax : OclAny := null; Sequence{xmin,xmax} := Sequence{(x)->min(),(x)->max()} ; var ymin : OclAny := null; var ymax : OclAny := null; Sequence{ymin,ymax} := Sequence{(y)->min(),(y)->max()} ; var ans1 : OclAny := 0; var ans2 : int := 0 ; for i : Integer.subrange(0, n-1) do ( var d1 : OclAny := Set{x[i+1] - xmin, y[i+1] - ymin}->max() ; var d2 : OclAny := Set{xmax - x[i+1], ymax - y[i+1]}->max() ; ans1 := Set{ans1, Set{d1, d2}->min()}->max() ; d1 := Set{x[i+1] - xmin, ymax - y[i+1]}->max() ; d2 := Set{xmax - x[i+1], y[i+1] - ymin}->max() ; ans2 := Set{ans2, Set{d1, d2}->min()}->max()) ; execute (Set{ans1, ans2}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,D=map(int,input().split()) time=0 floor=1 num=0 result=0 for _ in[0]*N : t,f=map(int,input().split()) if floor-1+f-1<=t-time : result+=num*(floor-1) num=1 elif abs(floor-f)<=t-time and numcollect( _x | (OclType["int"])->apply(_x) ) ; var time : int := 0 ; var floor : int := 1 ; var num : int := 0 ; var result : int := 0 ; (compound_stmt for (exprlist (expr (atom (name _)))) in (testlist (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr (atom (name N)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) , (test (logical_test (comparison (expr (atom (name f))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (expr (expr (atom (name floor))) - (expr (atom (number (integer 1))))) + (expr (atom (name f)))) - (expr (atom (number (integer 1)))))) <= (comparison (expr (expr (atom (name t))) - (expr (atom (name time)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name result)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name num))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name floor))) - (expr (atom (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name num)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))) (elif_clause elif (test (logical_test (logical_test (comparison (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name floor))) - (expr (atom (name f))))))))) ))))) <= (comparison (expr (expr (atom (name t))) - (expr (atom (name time))))))) and (logical_test (comparison (comparison (expr (atom (name num)))) < (comparison (expr (atom (name D)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name result)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name num))) * (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name t))) - (expr (atom (name time))))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name num)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name time)))))) , (test (logical_test (comparison (expr (atom (name floor))))))) (assign_part = (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) , (test (logical_test (comparison (expr (atom (name f)))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name result)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name num))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name floor))) - (expr (atom (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name result)))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=map(int,input().split()) lst=sorted([list(map(int,input().split()))for _ in range(n)])+[[10**20,1]] cnt=0 time=0 floor=1 ans=0 for i in range(n): t,f=lst[i] if f-floor>t-time or cnt>=d : print(-1) break ans+=cnt*(t-time) cnt+=1 time=t floor=f next_t,next_f=lst[i+1] if time+(floor-1)+(next_f-1)<=next_t : ans+=cnt*(floor-1) cnt=0 time+=floor-1 floor=1 else : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lst : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))->sort()->union(Sequence{ Sequence{(10)->pow(20)}->union(Sequence{ 1 }) }) ; var cnt : int := 0 ; var time : int := 0 ; var floor : int := 1 ; var ans : int := 0 ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) , (test (logical_test (comparison (expr (atom (name f))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))))))) (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (expr (atom (name f))) - (expr (atom (name floor))))) > (comparison (expr (expr (atom (name t))) - (expr (atom (name time))))))) or (logical_test (comparison (comparison (expr (atom (name cnt)))) >= (comparison (expr (atom (name d)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name cnt))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name t))) - (expr (atom (name time)))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cnt)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name time)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name t)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name floor)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name f)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name next_t)))))) , (test (logical_test (comparison (expr (atom (name next_f))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (expr (atom (name time))) + (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name floor))) - (expr (atom (number (integer 1))))))))) )))) + (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name next_f))) - (expr (atom (number (integer 1))))))))) ))))) <= (comparison (expr (atom (name next_t))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name cnt))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name floor))) - (expr (atom (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cnt)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name time)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name floor))) - (expr (atom (number (integer 1))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name floor)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import log2 def givesum(A,n): max_element=max(A) maxBit=int(log2(max_element))+1 totalSubarrays=n*(n+1)//2 s=0 for i in range(maxBit): c1=0 vec=[] sum=0 for j in range(n): a=A[j]>>i if(not(a & 1)): vec.append(j) cntSubarrNotSet=0 cnt=1 for j in range(1,len(vec)): if(vec[j]-vec[j-1]==1): cnt+=1 else : cntSubarrNotSet+=cnt*(cnt+1)//2 cnt=1 cntSubarrNotSet+=cnt*(cnt+1)//2 if len(vec)==0 : cntSubarrNotSet=0 cntSubarrIthSet=totalSubarrays-cntSubarrNotSet s+=cntSubarrIthSet*pow(2,i) return s if __name__=="__main__" : A=[1,2,3,4,5] n=len(A) print(givesum(A,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( A := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ; n := (A)->size() ; execute (givesum(A, n))->display() ) else skip; operation givesum(A : OclAny, n : OclAny) : OclAny pre: true post: true activity: var max_element : OclAny := (A)->max() ; var maxBit : int := ("" + ((log2(max_element))))->toInteger() + 1 ; var totalSubarrays : int := n * (n + 1) div 2 ; var s : int := 0 ; for i : Integer.subrange(0, maxBit-1) do ( var c1 : int := 0 ; var vec : Sequence := Sequence{} ; var sum : int := 0 ; for j : Integer.subrange(0, n-1) do ( var a : int := A[j+1] /(2->pow(i)) ; if (not((MathLib.bitwiseAnd(a, 1)))) then ( execute ((j) : vec) ) else skip) ; var cntSubarrNotSet : int := 0 ; var cnt : int := 1 ; for j : Integer.subrange(1, (vec)->size()-1) do ( if (vec[j+1] - vec[j - 1+1] = 1) then ( cnt := cnt + 1 ) else ( cntSubarrNotSet := cntSubarrNotSet + cnt * (cnt + 1) div 2 ; cnt := 1 )) ; cntSubarrNotSet := cntSubarrNotSet + cnt * (cnt + 1) div 2 ; if (vec)->size() = 0 then ( cntSubarrNotSet := 0 ) else skip ; var cntSubarrIthSet : double := totalSubarrays - cntSubarrNotSet ; s := s + cntSubarrIthSet * (2)->pow(i)) ; return s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import functools for i in range(int(input())): input() print(functools.reduce(lambda x,y : x | y,map(int,input().split()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( input() ; execute (functools.reduce(lambda x : OclAny, y : OclAny in (MathLib.bitwiseOr(x, y)), (input().split())->collect( _x | (OclType["int"])->apply(_x) )))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for jj in range(int(input())): n=int(input()) arr=[int(i)for i in input().split()] ans=0 for i in range(n): ans |=arr[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for jj : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( ans := ans or arr[i+1]) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,A,B,C,D=map(int,input().split()) a=N//A b=N % A if b==0 : a=a else : a=a+1 c=N//C d=N % C if d==0 : c=c else : c=c+1 E=a*B F=c*D if E>F : print(F) else : print(E) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var D : OclAny := null; Sequence{N,A,B,C,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : int := N div A ; var b : int := N mod A ; if b = 0 then ( a := a ) else ( a := a + 1 ) ; var c : int := N div C ; var d : int := N mod C ; if d = 0 then ( c := c ) else ( c := c + 1 ) ; var E : double := a * B ; var F : double := c * D ; if (E->compareTo(F)) > 0 then ( execute (F)->display() ) else ( execute (E)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : n=int(input()) a=list(map(int,input().split())) res=0 for ele in a : res |=ele print(res) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : int := 0 ; for ele : a do ( res := res or ele) ; execute (res)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) def solve(): n=int(input()) arr=list(map(int,input().split())) ans=[0 for i in range(30)] for i in range(n): x=1 for j in range(30): if arr[i]& x!=0 : ans[j]=1 x<<=1 y=0 for i in range(30): y+=pow(2,i)if ans[i]==1 else 0 print(y) while t : solve() t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; while t do ( solve() ; t := t - 1); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : Sequence := Integer.subrange(0, 30-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( var x : int := 1 ; for j : Integer.subrange(0, 30-1) do ( if MathLib.bitwiseAnd(arr[i+1], x) /= 0 then ( ans[j+1] := 1 ) else skip ; x := x * (2->pow(1)))) ; var y : int := 0 ; for i : Integer.subrange(0, 30-1) do ( y := y + if ans[i+1] = 1 then (2)->pow(i) else 0 endif) ; execute (y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for t in range(0,T): n=int(input()) a=list(map(int,input().split())) ans=0 for i in range(0,n): ans=ans | a[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(0, T-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( ans := MathLib.bitwiseOr(ans, a[i+1])) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(Array,N,K): count_Arr=[0]*(N+2); factor=1 ; size=N ; while(size): start=1 ; end=size ; count_Arr[1]+=factor*N ; count_Arr[end+1]-=factor*N ; factor+=1 ; size//=2 ; for i in range(2,N+1): count_Arr[i]+=count_Arr[i-1]; element=[]; for i in range(N): element.append((Array[i],count_Arr[i+1])); element.sort(); start=1 ; for i in range(N): end=start+element[i][1]-1 ; if(K>=start and K<=end): return element[i][0]; start+=element[i][1]; return-1 ; if __name__=="__main__" : arr=[2,4,5,1]; N=len(arr); K=13 ; print(solve(arr,N,K)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var arr : Sequence := Sequence{2}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 1 }))); ; N := (arr)->size(); ; K := 13; ; execute (solve(arr, N, K))->display(); ) else skip; operation solve(Array : OclAny, N : OclAny, K : OclAny) pre: true post: true activity: var count_Arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 2)); ; var factor : int := 1; ; var size : OclAny := N; ; while (size) do ( var start : int := 1; ; var end : OclAny := size; ; count_Arr[1+1] := count_Arr[1+1] + factor * N; ; count_Arr[end + 1+1] := count_Arr[end + 1+1] - factor * N; ; factor := factor + 1; ; size := size div 2;) ; for i : Integer.subrange(2, N + 1-1) do ( count_Arr[i+1] := count_Arr[i+1] + count_Arr[i - 1+1];) ; var element : Sequence := Sequence{}; ; for i : Integer.subrange(0, N-1) do ( execute ((Sequence{Array[i+1], count_Arr[i + 1+1]}) : element);) ; element := element->sort(); ; start := 1; ; for i : Integer.subrange(0, N-1) do ( end := start + element[i+1][1+1] - 1; ; if ((K->compareTo(start)) >= 0 & (K->compareTo(end)) <= 0) then ( return element[i+1]->first(); ) else skip ; start := start + element[i+1][1+1];) ; return -1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- buf=str(input()) print(buf.swapcase()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var buf : String := ("" + (((OclFile["System.in"]).readLine()))) ; execute (StringLib.swapCase(buf))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a=int(input()) b=input().split() total=0 count=[0,0,0,0] for i in b : count[int(i)-1]+=1 total=count[3] if count[2]>=count[0]: total+=count[2] count[0]=0 else : total+=count[2] count[0]-=count[2] total+=math.floor(count[1]/2) count[1]-=(math.floor(count[1]/2))*2 if count[1]!=0 : total+=1 count[0]-=2 if count[0]>0 : total+=math.ceil(count[0]/4) print(total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : OclAny := input().split() ; var total : int := 0 ; var count : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))) ; for i : b do ( count[("" + ((i)))->toInteger() - 1+1] := count[("" + ((i)))->toInteger() - 1+1] + 1) ; total := count[3+1] ; if (count[2+1]->compareTo(count->first())) >= 0 then ( total := total + count[2+1] ; count->first() := 0 ) else ( total := total + count[2+1] ; count->first() := count->first() - count[2+1] ) ; total := total + (count[1+1] / 2)->floor() ; count[1+1] := count[1+1] - ((count[1+1] / 2)->floor()) * 2 ; if count[1+1] /= 0 then ( total := total + 1 ; count->first() := count->first() - 2 ) else skip ; if count->first() > 0 then ( total := total + (count->first() / 4)->ceil() ) else skip ; execute (total)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- str=list(input()) for i in range(len(str)): if str[i].islower(): str[i]=str[i].upper() elif str[i].isupper(): str[i]=str[i].lower() for i in range(len(str)): print(str[i],end='') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var OclType["String"] : Sequence := ((OclFile["System.in"]).readLine())->characters() ; for i : Integer.subrange(0, (OclType["String"])->size()-1) do ( if OclType["String"][i+1]->matches("[a-z ]*") then ( ("" + ([i+1])) := OclType["String"][i+1]->toUpperCase() ) else (if OclType["String"][i+1]->matches("[A-Z ]*") then ( ("" + ([i+1])) := OclType["String"][i+1]->toLowerCase() ) else skip)) ; for i : Integer.subrange(0, (OclType["String"])->size()-1) do ( execute (("" + ([i+1])))->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(input().translate(str.maketrans('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ','ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (input().translate(("" + (.maketrans('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz')))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys s=sys.stdin.readline() for c in s : if c.islower(): print(c.upper(),end='') elif c.isupper(): print(c.lower(),end='') else : print(c,end='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : String := (OclFile["System.in"]).readLine() ; for c : s->characters() do ( if c->matches("[a-z ]*") then ( execute (c->toUpperCase())->display() ) else (if c->matches("[A-Z ]*") then ( execute (c->toLowerCase())->display() ) else ( execute (c)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- string=input() out_string=[] for i in range(len(string)): if string[i].isupper(): out_string.append(string[i].lower()) else : out_string.append(string[i].upper()) print("".join(out_string)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var string : String := (OclFile["System.in"]).readLine() ; var out_string : Sequence := Sequence{} ; for i : Integer.subrange(0, (string)->size()-1) do ( if string[i+1]->matches("[A-Z ]*") then ( execute ((string[i+1]->toLowerCase()) : out_string) ) else ( execute ((string[i+1]->toUpperCase()) : out_string) )) ; execute (StringLib.sumStringsWithSeparator((out_string), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b,c,d=map(int,input().split()) costa=0 costb=0 num=0 while(numcollect( _x | (OclType["int"])->apply(_x) ) ; var costa : int := 0 ; var costb : int := 0 ; var num : int := 0 ; while ((num->compareTo(n)) < 0) do ( costa := costa + b ; num := num + a) ; num := 0 ; while ((num->compareTo(n)) < 0) do ( costb := costb + d ; num := num + c) ; execute (Set{costa, costb}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,t,k,d=list(map(int,input().split())) time_without_second_oven=math.ceil(n/k)*t spent_time=1 double_oven_spent_time=0 double_oven=False while n>0 : if spent_time==d : double_oven=True double_oven_spent_time=0 if spent_time % t==0 : n-=k if double_oven and double_oven_spent_time!=0 and double_oven_spent_time % t==0 : n-=k if n<=0 : break if double_oven==True : spent_time+=1 double_oven_spent_time+=1 else : spent_time+=1 if time_without_second_oven>spent_time : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var t : OclAny := null; var k : OclAny := null; var d : OclAny := null; Sequence{n,t,k,d} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var time_without_second_oven : double := (n / k)->ceil() * t ; var spent_time : int := 1 ; var double_oven_spent_time : int := 0 ; var double_oven : boolean := false ; while n > 0 do ( if spent_time = d then ( double_oven := true ; double_oven_spent_time := 0 ) else skip ; if spent_time mod t = 0 then ( n := n - k ) else skip ; if double_oven & double_oven_spent_time /= 0 & double_oven_spent_time mod t = 0 then ( n := n - k ) else skip ; if n <= 0 then ( break ) else skip ; if double_oven = true then ( spent_time := spent_time + 1 ; double_oven_spent_time := double_oven_spent_time + 1 ) else ( spent_time := spent_time + 1 )) ; if (time_without_second_oven->compareTo(spent_time)) > 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math cakes,cookingTime,cakesPerOven,buildingTime=map(int,input().split()) ovenTimes=math.ceil(cakes/cakesPerOven) o1=0 o2=buildingTime for i in range(ovenTimes): if o1<=o2 : o1+=cookingTime else : o2+=cookingTime t=max(o1,o2) oneOven=ovenTimes*cookingTime if tcollect( _x | (OclType["int"])->apply(_x) ) ; var ovenTimes : double := (cakes / cakesPerOven)->ceil() ; var o1 : int := 0 ; var o2 : OclAny := buildingTime ; for i : Integer.subrange(0, ovenTimes-1) do ( if (o1->compareTo(o2)) <= 0 then ( o1 := o1 + cookingTime ) else ( o2 := o2 + cookingTime )) ; var t : OclAny := Set{o1, o2}->max() ; var oneOven : double := ovenTimes * cookingTime ; if (t->compareTo(oneOven)) < 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t,k,d=map(int,input().split()) t1=((n+k-1)//k)*t t2=max(0,t1-d) if t2>t : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; var k : OclAny := null; var d : OclAny := null; Sequence{n,t,k,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t1 : double := ((n + k - 1) div k) * t ; var t2 : OclAny := Set{0, t1 - d}->max() ; if (t2->compareTo(t)) > 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t,k,d=input().split() n=int(n) t=int(t) k=int(k) d=int(d) import math loop=math.ceil(n/k) time_1=t*loop if n>k : if(time_1)>(t+d): print("YES") else : print("NO") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; var k : OclAny := null; var d : OclAny := null; Sequence{n,t,k,d} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var t : int := ("" + ((t)))->toInteger() ; var k : int := ("" + ((k)))->toInteger() ; var d : int := ("" + ((d)))->toInteger() ; skip ; var loop : double := (n / k)->ceil() ; var time var n : OclAny := null; var t : OclAny := null; var k : OclAny := null; var d : OclAny := null; Sequence{n,t,k,d} := input().split() : double := t * loop ; if (n->compareTo(k)) > 0 then ( if ((time var n : OclAny := null; var t : OclAny := null; var k : OclAny := null; var d : OclAny := null; Sequence{n,t,k,d} := input().split())->compareTo((t + d))) > 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t,k,d=input().split() n=int(n) t=int(t) k=int(k) d=int(d) import math loop=math.ceil(n/k) time_1=t*loop if n>k : if(time_1)>(t+d): print("YES") else : print("NO") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; var k : OclAny := null; var d : OclAny := null; Sequence{n,t,k,d} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var t : int := ("" + ((t)))->toInteger() ; var k : int := ("" + ((k)))->toInteger() ; var d : int := ("" + ((d)))->toInteger() ; skip ; var loop : double := (n / k)->ceil() ; var time var n : OclAny := null; var t : OclAny := null; var k : OclAny := null; var d : OclAny := null; Sequence{n,t,k,d} := input().split() : double := t * loop ; if (n->compareTo(k)) > 0 then ( if ((time var n : OclAny := null; var t : OclAny := null; var k : OclAny := null; var d : OclAny := null; Sequence{n,t,k,d} := input().split())->compareTo((t + d))) > 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def leastPrimeFactor(n): least_prime=[0]*(n+1) least_prime[1]=1 for i in range(2,n+1): if(least_prime[i]==0): least_prime[i]=i for j in range(2*i,n+1,i): if(least_prime[j]==0): least_prime[j]=i for i in range(1,n+1): print("Least Prime factor of ",i,": ",least_prime[i]) n=10 leastPrimeFactor(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 10 ; leastPrimeFactor(n); operation leastPrimeFactor(n : OclAny) pre: true post: true activity: var least_prime : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; least_prime[1+1] := 1 ; for i : Integer.subrange(2, n + 1-1) do ( if (least_prime[i+1] = 0) then ( least_prime[i+1] := i ; for j : Integer.subrange(2 * i, n + 1-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ( if (least_prime[j+1] = 0) then ( least_prime[j+1] := i ) else skip) ) else skip) ; for i : Integer.subrange(1, n + 1-1) do ( execute ("Least Prime factor of ")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) w=list(map(int,input().split())) a=w.count(1) b=w.count(2) c=w.count(3) d=w.count(4) cars=c+d if a<=c : cars+=math.ceil(b/2) else : cars+=math.ceil(b/2+(a-c)/4) print(cars) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : int := w->count(1) ; var b : int := w->count(2) ; var c : int := w->count(3) ; var d : int := w->count(4) ; var cars : int := c + d ; if (a->compareTo(c)) <= 0 then ( cars := cars + (b / 2)->ceil() ) else ( cars := cars + (b / 2 + (a - c) / 4)->ceil() ) ; execute (cars)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x,y,p,q=map(int,input().split()) d=abs(x-p)+abs(y-q) if(abs(x-p)==n): d=min(n+y+q,3*n-(y+q)) if(abs(y-q)==n): d=min(n+x+p,3*n-(x+p)) print(d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; var y : OclAny := null; var p : OclAny := null; var q : OclAny := null; Sequence{n,x,y,p,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : double := (x - p)->abs() + (y - q)->abs() ; if ((x - p)->abs() = n) then ( d := Set{n + y + q, 3 * n - (y + q)}->min() ) else skip ; if ((y - q)->abs() = n) then ( d := Set{n + x + p, 3 * n - (x + p)}->min() ) else skip ; execute (d)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input().split() n=int(I[0]) P1=(int(I[1]),int(I[2])) P2=(int(I[3]),int(I[4])) l=[0,n] adjacent=False opposite=False for i in range(2): if P1[i]in l : if P2[int(not i)]in l : adjacent=True if P2[i]in l : if P1[i]==P2[i]: adjacent=True else : opposite=True if adjacent : shortest_distance=abs(P1[0]-P2[0])+abs(P1[1]-P2[1]) print(shortest_distance) if opposite and not adjacent : distance=[] if P1[0]in l and P2[0]in l : distance.append(abs(P1[0]-P2[0])+abs(P1[1]-P2[1])+2*(min(P1[1],P2[1]))) distance.append(abs(P1[0]-P2[0])+abs(P1[1]-P2[1])+2*(n-max(P1[1],P2[1]))) else : distance.append(abs(P1[0]-P2[0])+abs(P1[1]-P2[1])+2*(min(P1[0],P2[0]))) distance.append(abs(P1[0]-P2[0])+abs(P1[1]-P2[1])+2*(n-max(P1[0],P2[0]))) shortest_distance=min(distance) print(shortest_distance) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input().split() ; var n : int := ("" + ((I->first())))->toInteger() ; var P1 : OclAny := Sequence{("" + ((I[1+1])))->toInteger(), ("" + ((I[2+1])))->toInteger()} ; var P2 : OclAny := Sequence{("" + ((I[3+1])))->toInteger(), ("" + ((I[4+1])))->toInteger()} ; var l : Sequence := Sequence{0}->union(Sequence{ n }) ; var adjacent : boolean := false ; var opposite : boolean := false ; for i : Integer.subrange(0, 2-1) do ( if (l)->includes(P1[i+1]) then ( if (l)->includes(P2[("" + ((not(i))))->toInteger()+1]) then ( adjacent := true ) else skip ; if (l)->includes(P2[i+1]) then ( if P1[i+1] = P2[i+1] then ( adjacent := true ) else ( opposite := true ) ) else skip ) else skip) ; if adjacent then ( var shortest_distance : double := (P1->first() - P2->first())->abs() + (P1[1+1] - P2[1+1])->abs() ; execute (shortest_distance)->display() ) else skip ; if opposite & not(adjacent) then ( var distance : Sequence := Sequence{} ; if (l)->includes(P1->first()) & (l)->includes(P2->first()) then ( execute (((P1->first() - P2->first())->abs() + (P1[1+1] - P2[1+1])->abs() + 2 * (Set{P1[1+1], P2[1+1]}->min())) : distance) ; execute (((P1->first() - P2->first())->abs() + (P1[1+1] - P2[1+1])->abs() + 2 * (n - Set{P1[1+1], P2[1+1]}->max())) : distance) ) else ( execute (((P1->first() - P2->first())->abs() + (P1[1+1] - P2[1+1])->abs() + 2 * (Set{P1->first(), P2->first()}->min())) : distance) ; execute (((P1->first() - P2->first())->abs() + (P1[1+1] - P2[1+1])->abs() + 2 * (n - Set{P1->first(), P2->first()}->max())) : distance) ) ; shortest_distance := (distance)->min() ; execute (shortest_distance)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import fabs n,x1,y1,x2,y2=map(int,input().split()) d=fabs(x1-x2)+fabs(y1-y2) if x1==x2 : t=min(x1,n-x1) d=d+2*t elif y1==y2 : t=min(y1,n-y1) d=d+2*t elif x1+x2==n : d=d+2*min(y1,y2) elif y1+y2==n : d=d+2*min(n-x1,n-x2) if x1+x2==n and y1+y2==n : d=2*n if x1==x2 and y1==y2 : d=0 print(min(int(d),4*n-int(d))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{n,x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : OclAny := fabs(x1 - x2) + fabs(y1 - y2) ; if x1 = x2 then ( var t : OclAny := Set{x1, n - x1}->min() ; d := d + 2 * t ) else (if y1 = y2 then ( t := Set{y1, n - y1}->min() ; d := d + 2 * t ) else (if x1 + x2 = n then ( d := d + 2 * Set{y1, y2}->min() ) else (if y1 + y2 = n then ( d := d + 2 * Set{n - x1, n - x2}->min() ) else skip ) ) ) ; if x1 + x2 = n & y1 + y2 = n then ( d := 2 * n ) else skip ; if x1 = x2 & y1 = y2 then ( d := 0 ) else skip ; execute (Set{("" + ((d)))->toInteger(), 4 * n - ("" + ((d)))->toInteger()}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def totalPairs(arr,n): m=dict() for i in range(n): x=bin(arr[i]).count('1') m[x]=m.get(x,0)+1 ; result=0 for it in m : result+=(m[it]*(m[it]-1))//2 return result arr=[7,5,3,9,1,2] n=len(arr) print(totalPairs(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{7}->union(Sequence{5}->union(Sequence{3}->union(Sequence{9}->union(Sequence{1}->union(Sequence{ 2 }))))) ; n := (arr)->size() ; execute (totalPairs(arr, n))->display(); operation totalPairs(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var m : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := bin(arr[i+1])->count('1') ; m[x+1] := m.get(x, 0) + 1;) ; var result : int := 0 ; for it : m->keys() do ( result := result + (m[it+1] * (m[it+1] - 1)) div 2) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(x,y,n): return x+y if y==0 or x==n else 4*n-x-y n,x1,y1,x2,y2=map(int,input().split()) d=abs(f(x1,y1,n)-f(x2,y2,n)) print(min(d,4*n-d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{n,x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : double := (f(x1, y1, n) - f(x2, y2, n))->abs() ; execute (Set{d, 4 * n - d}->min())->display(); operation f(x : OclAny, y : OclAny, n : OclAny) : OclAny pre: true post: true activity: return if y = 0 or x = n then x + y else 4 * n - x - y endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): from sys import stdin f_i=stdin def f(bm_i,bw_i): if bm_i>bw_i : d=bm_i-bw_i else : d=bw_i-bm_i return d*(d-30)**2 while True : M,W=map(int,f_i.readline().split()) if M==0 : break bm=list(map(int,f_i.readline().split())) bw=list(map(int,f_i.readline().split())) e_gen=[[f(m,w)for w in bw]for m in bm] bit_size=(1<dp2[s2]: dp2[s2]=e2 dp1=dp2[:] print(max(dp2)) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: skip ; var f_i : OclAny := stdin ; skip ; while true do ( var M : OclAny := null; var W : OclAny := null; Sequence{M,W} := (f_i.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if M = 0 then ( break ) else skip ; var bm : Sequence := ((f_i.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var bw : Sequence := ((f_i.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var e_gen : Sequence := bm->select(m | true)->collect(m | (bw->select(w | true)->collect(w | (f(m, w))))) ; var bit_size : int := (1 * (2->pow(W))) ; var dp1 : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, bit_size) ; var dp2 : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, bit_size) ; dp1->first() := 0 ; dp2->first() := 0 ; var add_bit : Sequence := Integer.subrange(0, W-1)->select(i | true)->collect(i | (1 * (2->pow(i)))) ; for i : Integer.subrange(0, M-1) do ( for _tuple : Integer.subrange(1, (dp1)->size())->collect( _indx | Sequence{_indx-1, (dp1)->at(_indx)} ) do (var _indx : int := 1; var s1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var e1 : OclAny := _tuple->at(_indx); if e1 = -1 then ( continue ) else skip ; for _tuple : Integer.subrange(1, add_bit->size())->collect( _indx | Sequence{add_bit->at(_indx), e_gen[i+1]->at(_indx)} ) do (var _indx : int := 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var e : OclAny := _tuple->at(_indx); if MathLib.bitwiseAnd(s1, b) then ( continue ) else skip ; var s2 : int := MathLib.bitwiseOr(s1, b) ; var e2 : OclAny := e1 + e ; if (e2->compareTo(dp2[s2+1])) > 0 then ( dp2[s2+1] := e2 ) else skip)) ; dp1 := dp2) ; execute ((dp2)->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): while True : m,w=map(int,input().split()) if m==0 : break if m>=w : long_lst=list(map(int,input().split())) short_lst=list(map(int,input().split())) rest=2**m-1 else : short_lst=list(map(int,input().split())) long_lst=list(map(int,input().split())) rest=2**w-1 mem=[None]*(rest+1) def elec(bm,bw): bd=abs(bm-bw) return bd*(bd-30)**2 def score(rest,index): if mem[rest]!=None : return mem[rest] if rest==0 or index<0 : return 0 mask=1 count=0 ret=0 while mask<=rest : if mask & rest : new_rest=rest & ~ mask ret=max(ret,score(new_rest,index-1)+elec(short_lst[index],long_lst[count])) mask<<=1 count+=1 mem[rest]=ret return ret print(score(rest,min(m,w)-1)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: while true do ( var m : OclAny := null; var w : OclAny := null; Sequence{m,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if m = 0 then ( break ) else skip ; if (m->compareTo(w)) >= 0 then ( var long_lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var short_lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var rest : double := (2)->pow(m) - 1 ) else ( short_lst := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; long_lst := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; rest := (2)->pow(w) - 1 ) ; var mem : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (rest + 1)) ; skip ; skip ; execute (score(rest, Set{m, w}->min() - 1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline def answer(): maxrank=min(n,x+y-1) if((x+y)<=n): minrank=1 else : m=min(x,y) if(m!=n): minrank=(x+y+1)-n else : minrank=n return[minrank,maxrank] for T in range(int(input())): n,x,y=map(int,input().split()) print(*answer()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; skip ; for T : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name answer)) (trailer (arguments ( )))))))))->display()); operation answer() : OclAny pre: true post: true activity: var maxrank : OclAny := Set{n, x + y - 1}->min() ; if (((x + y)->compareTo(n)) <= 0) then ( var minrank : int := 1 ) else ( var m : OclAny := Set{x, y}->min() ; if (m /= n) then ( minrank := (x + y + 1) - n ) else ( minrank := n ) ) ; return Sequence{minrank}->union(Sequence{ maxrank }); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,x,y=list(map(int,input().split())) print(max(1,min(x+y+1-n,n)),min(n,x+y-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (Set{1, Set{x + y + 1 - n, n}->min()}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline t=int(input()) for _ in range(t): n,x,y=map(int,input().split()) if x>y : x,y=y,x ma=min(n,x+y-1) mi=max(1,min(n,x+y-n+1)) print(mi,ma) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (x->compareTo(y)) > 0 then ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{y,x} ) else skip ; var ma : OclAny := Set{n, x + y - 1}->min() ; var mi : OclAny := Set{1, Set{n, x + y - n + 1}->min()}->max() ; execute (mi)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,heapq,queue fast_input=sys.stdin.readline for _ in range(int(fast_input())): n,x,y=map(int,fast_input().split()) res=n if x+y<=n : res=1 else : res=x+y+1-n print(min(res,n),min(n,x+y-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var fast_input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + ((fast_input())))->toInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,x,y} := (fast_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var res : OclAny := n ; if (x + y->compareTo(n)) <= 0 then ( res := 1 ) else ( res := x + y + 1 - n ) ; execute (Set{res, n}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) liczby=list(map(int,input().split())) tab=[] a=liczby.count(1) b=liczby.count(2) c=liczby.count(3) d=liczby.count(4) count=0 count=count+d count=count+b//2 b=b % 2 aib=0 if a<=c : a=0 count=count+c else : a=a-c count=count+c aib=2*b+a if aib % 4==0 and aib>0 : count=count+aib//4 elif aib % 4!=0 and aib>0 : count=count+aib//4+1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var liczby : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var tab : Sequence := Sequence{} ; var a : int := liczby->count(1) ; var b : int := liczby->count(2) ; var c : int := liczby->count(3) ; var d : int := liczby->count(4) ; var count : int := 0 ; count := count + d ; count := count + b div 2 ; b := b mod 2 ; var aib : int := 0 ; if (a->compareTo(c)) <= 0 then ( a := 0 ; count := count + c ) else ( a := a - c ; count := count + c ) ; aib := 2 * b + a ; if aib mod 4 = 0 & aib > 0 then ( count := count + aib div 4 ) else (if aib mod 4 /= 0 & aib > 0 then ( count := count + aib div 4 + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n,x,y=map(int,input().split()) best=0 worst=0 if(x+y+1-n<=0): best=1 elif(x+y+1-n>n): best=n else : best=x+y+1-n if(x+y-1>=1 and x+y-1<=n): worst=x+y-1 else : worst=n print(best,worst,sep=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var best : int := 0 ; var worst : int := 0 ; if (x + y + 1 - n <= 0) then ( best := 1 ) else (if ((x + y + 1 - n->compareTo(n)) > 0) then ( best := n ) else ( best := x + y + 1 - n ) ) ; if (x + y - 1 >= 1 & (x + y - 1->compareTo(n)) <= 0) then ( worst := x + y - 1 ) else ( worst := n ) ; execute (best)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countNumbers(x,n): if x>n : return 0 return(1+countNumbers(x*10,n)+countNumbers(x*10+1,n)) if __name__=='__main__' : n=120 ; print(countNumbers(1,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 120; ; execute (countNumbers(1, n))->display(); ) else skip; operation countNumbers(x : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (x->compareTo(n)) > 0 then ( return 0 ) else skip ; return (1 + countNumbers(x * 10, n) + countNumbers(x * 10 + 1, n)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def center_hexadecagonal_num(n): return 8*n*n-8*n+1 if __name__=='__main__' : n=2 print(n,"nd centered hexadecagonal "+"number : ",center_hexadecagonal_num(n)) n=12 print(n,"th centered hexadecagonal "+"number : ",center_hexadecagonal_num(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 2 ; execute (n)->display() ; n := 12 ; execute (n)->display() ) else skip; operation center_hexadecagonal_num(n : OclAny) : OclAny pre: true post: true activity: return 8 * n * n - 8 * n + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def two_sets(a,n): a.sort(); return(a[n//2]-a[(n//2)-1]); if __name__=="__main__" : a=[1,4,4,6,7,9]; n=len(a); print(two_sets(a,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{1}->union(Sequence{4}->union(Sequence{4}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 9 }))))); ; n := (a)->size(); ; execute (two_sets(a, n))->display(); ) else skip; operation two_sets(a : OclAny, n : OclAny) pre: true post: true activity: a := a->sort(); ; return (a[n div 2+1] - a[(n div 2) - 1+1]);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def getSum(arr,n): sum=0 for i in range(0,n): sqrtCurrent=math.sqrt(arr[i]) for j in range(0,n): x=arr[j] if(x==sqrtCurrent): sum+=(sqrtCurrent*sqrtCurrent) break return int(sum) if __name__=='__main__' : arr=[2,4,5,6,7,8,9,3] n=len(arr) print(getSum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{2}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{ 3 }))))))) ; n := (arr)->size() ; execute (getSum(arr, n))->display() ) else skip; operation getSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( var sqrtCurrent : double := (arr[i+1])->sqrt() ; for j : Integer.subrange(0, n-1) do ( var x : OclAny := arr[j+1] ; if (x = sqrtCurrent) then ( sum := sum + (sqrtCurrent * sqrtCurrent) ; break ) else skip)) ; return ("" + ((sum)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools,math def compute(): def integral(x): t=x-1.0 return t-(math.sqrt(x*(2.0-x))*t+math.asin(t))/2.0 lsectionarea=1.0-math.pi/4.0 for i in itertools.count(1): slope=1.0/i a=slope**2+1.0 b=-2.0*(slope+1.0) c=1.0 x=(2.0*c)/(-b+math.sqrt(b*b-4*a*c)) concavetrianglearea=(x**2*slope/2)+(integral(1.0)-integral(x)) if concavetrianglearea/lsectionarea<0.001 : return str(i) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: skip ; var lsectionarea : double := 1.0 - / 4.0 ; for i : itertools->count(1) do ( var slope : double := 1.0 / i ; var a : double := (slope)->pow(2) + 1.0 ; var b : double := -2.0 * (slope + 1.0) ; var c : double := 1.0 ; x := (2.0 * c) / (-b + (b * b - 4 * a * c)->sqrt()) ; var concavetrianglearea : double := ((x)->pow(2) * slope / 2) + (integral(1.0) - integral(x)) ; if concavetrianglearea / lsectionarea < 0.001 then ( return ("" + ((i))) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100 def printDiagonalSums(mat,n): principal=0 secondary=0 ; for i in range(0,n): for j in range(0,n): if(i==j): principal+=mat[i][j] if((i+j)==(n-1)): secondary+=mat[i][j] print("Principal Diagonal:",principal) print("Secondary Diagonal:",secondary) a=[[1,2,3,4],[5,6,7,8],[1,2,3,4],[5,6,7,8]] printDiagonalSums(a,4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 100 ; skip ; var a : Sequence := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })))}->union(Sequence{Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 8 })))}->union(Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })))}->union(Sequence{ Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 8 }))) }))) ; printDiagonalSums(a, 4); operation printDiagonalSums(mat : OclAny, n : OclAny) pre: true post: true activity: var principal : int := 0 ; var secondary : int := 0; ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if (i = j) then ( principal := principal + mat[i+1][j+1] ) else skip ; if ((i + j) = (n - 1)) then ( secondary := secondary + mat[i+1][j+1] ) else skip)) ; execute ("Principal Diagonal:")->display() ; execute ("Secondary Diagonal:")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100 def printDiagonalSums(mat,n): principal=0 secondary=0 for i in range(0,n): principal+=mat[i][i] secondary+=mat[i][n-i-1] print("Principal Diagonal:",principal) print("Secondary Diagonal:",secondary) a=[[1,2,3,4],[5,6,7,8],[1,2,3,4],[5,6,7,8]] printDiagonalSums(a,4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 100 ; skip ; var a : Sequence := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })))}->union(Sequence{Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 8 })))}->union(Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })))}->union(Sequence{ Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 8 }))) }))) ; printDiagonalSums(a, 4); operation printDiagonalSums(mat : OclAny, n : OclAny) pre: true post: true activity: var principal : int := 0 ; var secondary : int := 0 ; for i : Integer.subrange(0, n-1) do ( principal := principal + mat[i+1][i+1] ; secondary := secondary + mat[i+1][n - i - 1+1]) ; execute ("Principal Diagonal:")->display() ; execute ("Secondary Diagonal:")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x=input() s1=x+'a' s2='a'+x if s1[: :-1]!=s1 : print('YES'); print(s1) elif s2[: :-1]!=s2 : print('YES'); print(s2) else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : String := (OclFile["System.in"]).readLine() ; var s1 : String := x + 'a' ; var s2 : String := 'a' + x ; if s1(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) /= s1 then ( execute ('YES')->display(); execute (s1)->display() ) else (if s2(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) /= s2 then ( execute ('YES')->display(); execute (s2)->display() ) else ( execute ('NO')->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for l in range(t): m=input() if m!=m[: :-1]: print("YES") m1="a"+m m2=m+"a" if m1!=m1[: :-1]: print(m1) else : print(m2) else : m=m+"a" if m==m[: :-1]: print("NO") else : print("YES") print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for l : Integer.subrange(0, t-1) do ( var m : String := (OclFile["System.in"]).readLine() ; if m /= m(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( execute ("YES")->display() ; var m1 : String := "a" + m ; var m2 : String := m + "a" ; if m1 /= m1(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( execute (m1)->display() ) else ( execute (m2)->display() ) ) else ( m := m + "a" ; if m = m(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; execute (m)->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : t-=1 s=input() idx=-1 for i in range(len(s)): if(s[len(s)-i-1]!='a'): idx=i break if(idx!=-1): print('YES') print(s[: idx],end='') print('a',end='') print(s[idx :]) else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( t := t - 1 ; var s : String := (OclFile["System.in"]).readLine() ; var idx : int := -1 ; for i : Integer.subrange(0, (s)->size()-1) do ( if (s[(s)->size() - i - 1+1] /= 'a') then ( idx := i ; break ) else skip) ; if (idx /= -1) then ( execute ('YES')->display() ; execute (s.subrange(1,idx))->display() ; execute ('a')->display() ; execute (s.subrange(idx+1))->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=[int(num)for num in input().split()] c=b.count(1) d=b.count(2) e=b.count(3) f=b.count(4) count=f+d//2 d=d % 2 cd=0 if c<=e : count=count+e c=0 else : c=c-e count=count+e cd=2*d+c if cd>0 and cd % 4==0 : count+=cd//4 elif cd>0 and cd % 4!=0 : count=count+cd//4+1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var c : int := b->count(1) ; var d : int := b->count(2) ; var e : int := b->count(3) ; var f : int := b->count(4) ; var count : int := f + d div 2 ; d := d mod 2 ; var cd : int := 0 ; if (c->compareTo(e)) <= 0 then ( count := count + e ; c := 0 ) else ( c := c - e ; count := count + e ) ; cd := 2 * d + c ; if cd > 0 & cd mod 4 = 0 then ( count := count + cd div 4 ) else (if cd > 0 & cd mod 4 /= 0 then ( count := count + cd div 4 + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : t-=1 s=input() n=len(s) idx=-1 for i in range(n): if(s[n-i-1]!='a'): idx=i break if(idx==-1): print("NO") else : print("YES") print(s[: idx]+'a'+s[idx :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( t := t - 1 ; var s : String := (OclFile["System.in"]).readLine() ; var n : int := (s)->size() ; var idx : int := -1 ; for i : Integer.subrange(0, n-1) do ( if (s[n - i - 1+1] /= 'a') then ( idx := i ; break ) else skip) ; if (idx = -1) then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; execute (s.subrange(1,idx) + 'a' + s.subrange(idx+1))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q,h,s,d=map(int,input().split()) n=int(input()) pricesfor2=[q*8,h*4,s*2,d] pricesfor2=sorted(pricesfor2) nep=n % 2==1 n//=2 res=n*pricesfor2[0] if(nep): res+=min(q*4,min(h*2,s)) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : OclAny := null; var h : OclAny := null; var s : OclAny := null; var d : OclAny := null; Sequence{q,h,s,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var pricesfor2 : Sequence := Sequence{q * 8}->union(Sequence{h * 4}->union(Sequence{s * 2}->union(Sequence{ d }))) ; pricesfor2 := pricesfor2->sort() ; var nep : boolean := n mod 2 = 1 ; n := n div 2 ; var res : double := n * pricesfor2->first() ; if (nep) then ( res := res + Set{q * 4, Set{h * 2, s}->min()}->min() ) else skip ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import os import random import re import sys from math import gcd from math import sqrt from collections import Counter from itertools import compress from collections import deque for _ in range(int(input())): s=input() li=[] for i in s : li.append(i) fi=s+'a' se='a'+s if fi!=fi[: :-1]: print('YES') print(fi) elif se!=se[: :-1]: print('YES') print(se) else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var li : Sequence := Sequence{} ; for i : s->characters() do ( execute ((i) : li)) ; var fi : String := s + 'a' ; var se : String := 'a' + s ; if fi /= fi(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( execute ('YES')->display() ; execute (fi)->display() ) else (if se /= se(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( execute ('YES')->display() ; execute (se)->display() ) else ( execute ('NO')->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPrime(n): if n<=1 : return False for i in range(2,n): if n % i==0 : return False return True def isEmirp(n): n=int(n) if isPrime(n)==False : return False rev=0 while n!=0 : d=n % 10 rev=rev*10+d n=int(n/10) return isPrime(rev) n=13 if isEmirp(n): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 13 ; if isEmirp(n) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isPrime(n : OclAny) : OclAny pre: true post: true activity: if n <= 1 then ( return false ) else skip ; for i : Integer.subrange(2, n-1) do ( if n mod i = 0 then ( return false ) else skip) ; return true; operation isEmirp(n : OclAny) : OclAny pre: true post: true activity: n := ("" + ((n)))->toInteger() ; if isPrime(n) = false then ( return false ) else skip ; var rev : int := 0 ; while n /= 0 do ( var d : int := n mod 10 ; rev := rev * 10 + d ; n := ("" + ((n / 10)))->toInteger()) ; return isPrime(rev); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def power(x,y): res=1 ; while(y>0): if(y % 2==1): res=(res*x); y=int(y)>>1 ; x=(x*x); return res ; def solve(L): n=L/2+1 ; ans=power(n,n-2); return int(ans); L=6 ; print(solve(L)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; L := 6; ; execute (solve(L))->display();; operation power(x : OclAny, y : OclAny) pre: true post: true activity: var res : int := 1; ; while (y > 0) do ( if (y mod 2 = 1) then ( res := (res * x); ) else skip ; y := ("" + ((y)))->toInteger() /(2->pow(1)); ; x := (x * x);) ; return res;; operation solve(L : OclAny) pre: true post: true activity: var n : double := L / 2 + 1; ; var ans : OclAny := power(n, n - 2); ; return ("" + ((ans)))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=list(map(int,input().split())) s=input() s=list(s) for i in range(m): j=0 while jcollect( _x | (OclType["int"])->apply(_x) )) ; var s : String := (OclFile["System.in"]).readLine() ; s := (s)->characters() ; for i : Integer.subrange(0, m-1) do ( var j : int := 0 ; while (j->compareTo(n - 1)) < 0 do ( if s[j+1] = "B" & s[j + 1+1] = "G" then ( var s[j+1] : OclAny := null; var s[j + 1+1] : OclAny := null; Sequence{s[j+1],s[j + 1+1]} := Sequence{s[j + 1+1],s[j+1]} ; j := j + 1 ) else skip ; j := j + 1)) ; execute (StringLib.sumStringsWithSeparator((s), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=map(int,input().split()) s=input() list=[i for i in s] k=1 while True : if k>t : break j=0 while True : if j>=n-1 : break if list[j]=="B" and list[j+1]=="G" : list[j]="G" list[j+1]="B" j+=2 else : j+=1 k+=1 a=''.join([str(elem)for elem in list]) print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var OclType["Sequence"] : Sequence := s->characters()->select(i | true)->collect(i | (i)) ; var k : int := 1 ; while true do ( if (k->compareTo(t)) > 0 then ( break ) else skip ; var j : int := 0 ; while true do ( if (j->compareTo(n - 1)) >= 0 then ( break ) else skip ; if [j+1] = "B" & [j + 1+1] = "G" then ( [j+1] := "G" ; [j + 1+1] := "B" ; j := j + 2 ) else ( j := j + 1 )) ; k := k + 1) ; var a : String := StringLib.sumStringsWithSeparator((OclType["Sequence"]->select(elem | true)->collect(elem | (("" + ((elem)))))), '') ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=input().split() x=int(b) s=input() while x>0 : s=s.replace("BG","GB") x-=1 print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; var x : int := ("" + ((b)))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; while x > 0 do ( s := s.replace("BG", "GB") ; x := x - 1) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=map(int,input().split()) s=input() while(t): i=0 while(i<=n-2): if(s[i]=="B" and s[i+1]=="G"): s=s[: i]+"G"+s[i+1 :] s=s[: i+1]+"B"+s[i+2 :] i=i+2 else : i=i+1 t=t-1 print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; while (t) do ( var i : int := 0 ; while ((i->compareTo(n - 2)) <= 0) do ( if (s[i+1] = "B" & s[i + 1+1] = "G") then ( s := s.subrange(1,i) + "G" + s.subrange(i + 1+1) ; s := s.subrange(1,i + 1) + "B" + s.subrange(i + 2+1) ; i := i + 2 ) else ( i := i + 1 )) ; var t : double := t - 1) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) x=input() while m : x=x.replace("BG","GB") m-=1 print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : String := (OclFile["System.in"]).readLine() ; while m do ( x := x.replace("BG", "GB") ; m := m - 1) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s1=str(input()) s2=str(input()) s3=str() for i in range(len(s1)): if s1[i]!=s2[i]: s3=s3+'1' else : s3=s3+'0' print(s3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s1 : String := ("" + (((OclFile["System.in"]).readLine()))) ; var s2 : String := ("" + (((OclFile["System.in"]).readLine()))) ; var s3 : String := ("" + (())) ; for i : Integer.subrange(0, (s1)->size()-1) do ( if s1[i+1] /= s2[i+1] then ( s3 := s3 + '1' ) else ( s3 := s3 + '0' )) ; execute (s3)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) t=0 l3=0 l2=0 l1=0 for i in l : if i==4 : t+=1 elif i==3 : l3+=1 elif i==2 : l2+=1 else : l1+=1 t+=l2//2 left=l2 % 2 if l3>=l1 : t+=l3 t+=left else : t+=l3 l1-=l3 if l1<3 and left==1 : t+=1 elif l1<3 and left==0 : t+=1 elif l1>2 and left==0 : t+=l1//4 if l1 % 4>0 : t+=1 elif l1>2 and left==1 : t+=1 l1-=2 t+=l1//4 if l1 % 4>0 : t+=1 print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : int := 0 ; var l3 : int := 0 ; var l2 : int := 0 ; var l1 : int := 0 ; for i : l do ( if i = 4 then ( t := t + 1 ) else (if i = 3 then ( l3 := l3 + 1 ) else (if i = 2 then ( l2 := l2 + 1 ) else ( l1 := l1 + 1 ) ) ) ) ; t := t + l2 div 2 ; var left : int := l2 mod 2 ; if (l3->compareTo(l1)) >= 0 then ( t := t + l3 ; t := t + left ) else ( t := t + l3 ; l1 := l1 - l3 ; if l1 < 3 & left = 1 then ( t := t + 1 ) else (if l1 < 3 & left = 0 then ( t := t + 1 ) else (if l1 > 2 & left = 0 then ( t := t + l1 div 4 ; if l1 mod 4 > 0 then ( t := t + 1 ) else skip ) else (if l1 > 2 & left = 1 then ( t := t + 1 ; l1 := l1 - 2 ; t := t + l1 div 4 ; if l1 mod 4 > 0 then ( t := t + 1 ) else skip ) else skip ) ) ) ) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re from collections import deque,defaultdict,Counter from math import sqrt,hypot,factorial,pi,sin,cos,radians if sys.version_info.minor>=5 : from math import gcd else : from fractions import gcd from heapq import heappop,heappush,heapify,heappushpop from bisect import bisect_left,bisect_right from itertools import permutations,combinations,product from operator import itemgetter,mul from copy import deepcopy from functools import reduce,partial from fractions import Fraction from string import ascii_lowercase,ascii_uppercase,digits def input(): return sys.stdin.readline().strip() def ceil(a,b=1): return int(-(-a//b)) def round(x): return int((x*2+1)//2) def fermat(x,y,MOD): return x*pow(y,MOD-2,MOD)% MOD def lcm(x,y): return(x*y)//gcd(x,y) def lcm_list(nums): return reduce(lcm,nums,initial=1) def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) sys.setrecursionlimit(10**9) INF=float('inf') MOD=10**9+7 q,h,s,d=MAP() n=INT() best1L=min(q*4,h*2,s) best2L=min(d,best1L*2) if n % 2==0 : print(best2L*(n//2)) else : print(best2L*(n//2)+best1L) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if ((trailer . (name version_info))).minor >= 5 then ( skip ) else ( skip ) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; MOD := (10)->pow(9) + 7 ; var q : OclAny := null; var h : OclAny := null; var s : OclAny := null; var d : OclAny := null; Sequence{q,h,s,d} := MAP() ; var n : OclAny := INT() ; var best1L : OclAny := Set{q * 4, h * 2, s}->min() ; var best2L : OclAny := Set{d, best1L * 2}->min() ; if n mod 2 = 0 then ( execute (best2L * (n div 2))->display() ) else ( execute (best2L * (n div 2) + best1L)->display() ); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation ceil(a : OclAny, b : int) : OclAny pre: true post: true activity: if b->oclIsUndefined() then b := 1 else skip; return ("" + ((-(-a div b))))->toInteger(); operation round(x : OclAny) : OclAny pre: true post: true activity: return ("" + (((x * 2 + 1) div 2)))->toInteger(); operation fermat(x : OclAny, y : OclAny, MOD : OclAny) : OclAny pre: true post: true activity: return x * (y)->pow(MOD - 2) mod MOD; operation lcm(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return (x * y) div gcd(x, y); operation lcm_list(nums : OclAny) : OclAny pre: true post: true activity: return reduce(lcm, nums, (argument (test (logical_test (comparison (expr (atom (name initial)))))) = (test (logical_test (comparison (expr (atom (number (integer 1))))))))); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s1=input() s2=input() for i in range(len(s1)): if(s1[i]=="1" and s2[i]=="1"): print("0",end="") elif(s1[i]=="0" and s2[i]=="1"): print("1",end="") elif(s1[i]=="1" and s2[i]=="0"): print("1",end="") if(s1[i]=="0" and s2[i]=="0"): print("0",end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s1 : String := (OclFile["System.in"]).readLine() ; var s2 : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, (s1)->size()-1) do ( if (s1[i+1] = "1" & s2[i+1] = "1") then ( execute ("0")->display() ) else (if (s1[i+1] = "0" & s2[i+1] = "1") then ( execute ("1")->display() ) else (if (s1[i+1] = "1" & s2[i+1] = "0") then ( execute ("1")->display() ) else skip ) ) ; if (s1[i+1] = "0" & s2[i+1] = "0") then ( execute ("0")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- o=input() a=int(o,2) b=int(input(),2) p=bin(a ^ b)[2 :] p=(o.count("0")+o.count("1")-len(p))*"0"+p print(p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var o : String := (OclFile["System.in"]).readLine() ; var a : int := ("" + ((o, 2)))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine(), 2)))->toInteger() ; var p : OclAny := bin(MathLib.bitwiseXor(a, b)).subrange(2+1) ; p := (o->count("0") + o->count("1") - (p)->size()) * "0" + p ; execute (p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num1=input() num2=input() l=[] if abs(int(num1[0])-int(num2[0]))==0 : l.append("0") for i in range(1,len(num1)): if num1[i]!=num2[i]: l.append("1") else : l.append("0") else : for i in range(len(num1)): if num1[i]!=num2[i]: l.append("1") else : l.append("0") l=("".join(l)) print(l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num1 : String := (OclFile["System.in"]).readLine() ; var num2 : String := (OclFile["System.in"]).readLine() ; var l : Sequence := Sequence{} ; if (("" + ((num1->first())))->toInteger() - ("" + ((num2->first())))->toInteger())->abs() = 0 then ( execute (("0") : l) ; for i : Integer.subrange(1, (num1)->size()-1) do ( if num1[i+1] /= num2[i+1] then ( execute (("1") : l) ) else ( execute (("0") : l) )) ) else ( for i : Integer.subrange(0, (num1)->size()-1) do ( if num1[i+1] /= num2[i+1] then ( execute (("1") : l) ) else ( execute (("0") : l) )) ) ; l := (StringLib.sumStringsWithSeparator((l), "")) ; execute (l)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=input() n=len(a) for k in range(n): if((a[k]=="1" and b[k]=="1")or(a[k]=="0" and b[k]=="0")): print("0",end="") else : print("1",end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var n : int := (a)->size() ; for k : Integer.subrange(0, n-1) do ( if ((a[k+1] = "1" & b[k+1] = "1") or (a[k+1] = "0" & b[k+1] = "0")) then ( execute ("0")->display() ) else ( execute ("1")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def GCD(a,b): if(b==0): return a return GCD(b,a % b) def FillPrefixSuffix(prefix,arr,suffix,n): prefix[0]=arr[0] for i in range(1,n): prefix[i]=GCD(prefix[i-1],arr[i]) suffix[n-1]=arr[n-1] for i in range(n-2,-1,-1): suffix[i]=GCD(suffix[i+1],arr[i]) def GCDoutsideRange(l,r,prefix,suffix,n): if(l==0): return suffix[r+1] if(r==n-1): return prefix[l-1] return GCD(prefix[l-1],suffix[r+1]) arr=[2,6,9] n=len(arr) prefix=[] suffix=[] for i in range(n+1): prefix.append(0) suffix.append(0) FillPrefixSuffix(prefix,arr,suffix,n) l=0 r=0 print(GCDoutsideRange(l,r,prefix,suffix,n)) l=1 r=1 print(GCDoutsideRange(l,r,prefix,suffix,n)) l=1 r=2 print(GCDoutsideRange(l,r,prefix,suffix,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; arr := Sequence{2}->union(Sequence{6}->union(Sequence{ 9 })) ; n := (arr)->size() ; prefix := Sequence{} ; suffix := Sequence{} ; for i : Integer.subrange(0, n + 1-1) do ( execute ((0) : prefix) ; execute ((0) : suffix)) ; FillPrefixSuffix(prefix, arr, suffix, n) ; l := 0 ; r := 0 ; execute (GCDoutsideRange(l, r, prefix, suffix, n))->display() ; l := 1 ; r := 1 ; execute (GCDoutsideRange(l, r, prefix, suffix, n))->display() ; l := 1 ; r := 2 ; execute (GCDoutsideRange(l, r, prefix, suffix, n))->display(); operation GCD(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (b = 0) then ( return a ) else skip ; return GCD(b, a mod b); operation FillPrefixSuffix(prefix : OclAny, arr : OclAny, suffix : OclAny, n : OclAny) pre: true post: true activity: prefix->first() := arr->first() ; for i : Integer.subrange(1, n-1) do ( prefix[i+1] := GCD(prefix[i - 1+1], arr[i+1])) ; suffix[n - 1+1] := arr[n - 1+1] ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( suffix[i+1] := GCD(suffix[i + 1+1], arr[i+1])); operation GCDoutsideRange(l : OclAny, r : OclAny, prefix : OclAny, suffix : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (l = 0) then ( return suffix[r + 1+1] ) else skip ; if (r = n - 1) then ( return prefix[l - 1+1] ) else skip ; return GCD(prefix[l - 1+1], suffix[r + 1+1]); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input('')) s=int(input('')) l=[] c=0 for _ in range(n): l.append(int(input(''))) l.sort() for i in reversed(l): s-=i if s>0 : c+=1 print(c+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; var s : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; var l : Sequence := Sequence{} ; var c : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine(''))))->toInteger()) : l)) ; l := l->sort() ; for i : (l)->reverse() do ( s := s - i ; if s > 0 then ( c := c + 1 ) else skip) ; execute (c + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=int(input()) lis=[] for i in range(n): weight=int(input()) lis.append(weight) lis.sort(reverse=True) for j in range(len(lis)): if m<=lis[j]: print(j+1) break else : m-=lis[j] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lis : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var weight : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((weight) : lis)) ; lis := lis->sort() ; for j : Integer.subrange(0, (lis)->size()-1) do ( if (m->compareTo(lis[j+1])) <= 0 then ( execute (j + 1)->display() ; break ) else ( m := m - lis[j+1] )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=int(input()) sort=[] for i in range(0,n): x=int(input()) sort.append(x) sort.sort(reverse=True) i=0 while s>0 : s=s-sort[i] i+=1 print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sort : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((x) : sort)) ; sort := sort->sort() ; var i : int := 0 ; while s > 0 do ( s := s - sort[i+1] ; i := i + 1) ; execute (i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=int(input()) a=[0] for i in range(n): x=int(input()) a.append(x) a.sort() if(a[n]>=m): print(1) else : for i in range(2,n+1): s=sum(a[n : n-i :-1]) if(s>=m): print(i) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{ 0 } ; for i : Integer.subrange(0, n-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((x) : a)) ; a := a->sort() ; if ((a[n+1]->compareTo(m)) >= 0) then ( execute (1)->display() ) else ( for i : Integer.subrange(2, n + 1-1) do ( var s : OclAny := (a(subscript (test (logical_test (comparison (expr (atom (name n)))))) : (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (name i))))))) (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->sum() ; if ((s->compareTo(m)) >= 0) then ( execute (i)->display() ; break ) else skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def _input(): return map(int,input().split()) n=int(input()) m=int(input()) lst=sorted([int(input())for _ in range(n)]); res=0 i=n-1 while i>=0 : res+=lst[i] if res>=m : break i-=1 print(n-i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))->sort(); var res : int := 0 ; var i : double := n - 1 ; while i >= 0 do ( res := res + lst[i+1] ; if (res->compareTo(m)) >= 0 then ( break ) else skip ; i := i - 1) ; execute (n - i)->display(); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- li=input().split() S=int(li[0]) W=int(li[1]) if S-W>0 : print('safe') else : print('unsafe') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var li : OclAny := input().split() ; var S : int := ("" + ((li->first())))->toInteger() ; var W : int := ("" + ((li[1+1])))->toInteger() ; if S - W > 0 then ( execute ('safe')->display() ) else ( execute ('unsafe')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(Q,H,S,D,N,M): QQ=Q QH=H/2 QS=S/4 QD=D/8 if N==0 : return M if N==1 : if QQ==min(QQ,QH,QS): return M+(4*Q) if QH==min(QQ,QH,QS): return M+(2*H) if QS==min(QQ,QH,QS): return M+(S) else : if QQ==min(QQ,QH,QS,QD): return M+4*Q*N if QH==min(QQ,QH,QS,QD): return M+2*H*N if QS==min(QQ,QH,QS,QD): return M+S*N if QD==min(QQ,QH,QS,QD): if N % 2==0 : return M+(N//2)*D else : return f(Q,H,S,D,1,M+(N//2)*D) Q,H,S,D=map(int,input().split()) N=int(input()) print(f(Q,H,S,D,N,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{Q,H,S,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (f(Q, H, S, D, N, 0))->display(); operation f(Q : OclAny, H : OclAny, S : OclAny, D : OclAny, N : OclAny, M : OclAny) : OclAny pre: true post: true activity: var QQ : OclAny := Q ; var QH : double := H / 2 ; var QS : double := S / 4 ; var QD : double := D / 8 ; if N = 0 then ( return M ) else skip ; if N = 1 then ( if QQ = Set{QQ, QH, QS}->min() then ( return M + (4 * Q) ) else skip ; if QH = Set{QQ, QH, QS}->min() then ( return M + (2 * H) ) else skip ; if QS = Set{QQ, QH, QS}->min() then ( return M + (S) ) else skip ) else ( if QQ = Set{QQ, QH, QS, QD}->min() then ( return M + 4 * Q * N ) else skip ; if QH = Set{QQ, QH, QS, QD}->min() then ( return M + 2 * H * N ) else skip ; if QS = Set{QQ, QH, QS, QD}->min() then ( return M + S * N ) else skip ; if QD = Set{QQ, QH, QS, QD}->min() then ( if N mod 2 = 0 then ( return M + (N div 2) * D ) else ( return f(Q, H, S, D, 1, M + (N div 2) * D) ) ) else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,k=map(int,input().split()) H=[int(input())for i in range(n)] H.sort() ans=float('INF') for i in range(n-k+1): d_height=H[k+i-1]-H[i] ans=min(ans,d_height) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var H : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; H := H->sort() ; var ans : double := ("" + (('INF')))->toReal() ; for i : Integer.subrange(0, n - k + 1-1) do ( var d_height : double := H[k + i - 1+1] - H[i+1] ; ans := Set{ans, d_height}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def canBecomeEmpty(string,sub_str): while len(string)>0 : idx=string.find(sub_str) if idx==-1 : break string=string.replace(sub_str,"",1) return(len(string)==0) if __name__=="__main__" : string="GEEGEEKSKS" sub_str="GEEKS" if canBecomeEmpty(string,sub_str): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( string := "GEEGEEKSKS" ; sub_str := "GEEKS" ; if canBecomeEmpty(string, sub_str) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation canBecomeEmpty(string : OclAny, sub_str : OclAny) : OclAny pre: true post: true activity: while (string)->size() > 0 do ( var idx : int := string->indexOf(sub_str) - 1 ; if idx = -1 then ( break ) else skip ; string := string.replace(sub_str, "", 1)) ; return ((string)->size() = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def removeChar(s,c): counts=s.count(c) s=list(s) while counts : s.remove(c) counts-=1 s=''.join(s) print(s) if __name__=='__main__' : s="geeksforgeeks" removeChar(s,'g') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( s := "geeksforgeeks" ; removeChar(s, 'g') ) else skip; operation removeChar(s : OclAny, c : OclAny) pre: true post: true activity: var counts : int := s->count(c) ; s := (s) ; while counts do ( execute ((c) /: s) ; counts := counts - 1) ; s := StringLib.sumStringsWithSeparator((s), '') ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,q=map(int,input().split()) a=list(map(int,input().split())) a=deque(a) a0,b0=[0],[0] for _ in range(n): u,v=a.popleft(),a.popleft() a0.append(u) b0.append(v) if ucollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := (a) ; var a0 : OclAny := null; var b0 : OclAny := null; Sequence{a0,b0} := Sequence{Sequence{ 0 },Sequence{ 0 }} ; for _anon : Integer.subrange(0, n-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := Sequence{a->first(),a->first()} ; execute ((u) : a0) ; execute ((v) : b0) ; if (u->compareTo(v)) < 0 then ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := Sequence{v,u} ) else skip ; a := a->prepend(u) ; execute ((v) : a)) ; a := (a) ; var ma : OclAny := a->first() ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, q-1) do ( var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (m->compareTo(n)) <= 0 then ( var ans0 : Sequence := Sequence{a0[m+1]}->union(Sequence{ b0[m+1] }) ) else ( var u : int := (m - n - 1) mod (n - 1) + 1 ; ans0 := Sequence{ma}->union(Sequence{ a[u+1] }) ) ; execute ((StringLib.sumStringsWithSeparator(((ans0)->collect( _x | (OclType["String"])->apply(_x) )), " ")) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,functools,copy,statistics inf=float('inf') mod=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def LS(): return input().split() import time n,t=LI() arr=LI() max_index=arr.index(max(arr))+1 sub_arr=[] mem=[] cnt=1 dq=collections.deque(arr) mx=max(arr) while cnttoReal() ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := LI() ; var arr : OclAny := LI() ; var max_index : int := arr->indexOf((arr)->max()) - 1 + 1 ; var sub_arr : Sequence := Sequence{} ; var mem : Sequence := Sequence{} ; var cnt : int := 1 ; var dq : Sequence := (arr) ; var mx : OclAny := (arr)->max() ; while (cnt->compareTo(max_index)) < 0 do ( var x : OclAny := dq->first() ; dq := dq->tail() ; var y : OclAny := dq->first() ; dq := dq->tail() ; execute ((Set{x, y}->min()) : dq) ; dq := dq->prepend(Set{x, y}->max()) ; cnt := cnt + 1 ; execute ((Sequence{x}->union(Sequence{ y })) : mem)) ; dq := dq->tail() ; sub_arr := (dq) ; for _anon : Integer.subrange(0, t-1) do ( var a : OclAny := I() ; if (a->compareTo(max_index)) < 0 then ( execute (mem[a - 1+1]->first())->display() ) else ( a := a - max_index ; a := a mod (n - 1) ; execute (mx)->display() )); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation LS() : OclAny pre: true post: true activity: return input().split(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,functools,copy,statistics inf=float('inf') mod=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def LS(): return input().split() import time n,t=LI() arr=LI() max_index=arr.index(max(arr))+1 max_flag=False sub_arr=[] mx=max(arr) if t!=0 : for _ in range(t): a=I() if atoReal() ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := LI() ; var arr : OclAny := LI() ; var max_index : int := arr->indexOf((arr)->max()) - 1 + 1 ; var max_flag : boolean := false ; var sub_arr : Sequence := Sequence{} ; var mx : OclAny := (arr)->max() ; if t /= 0 then ( for _anon : Integer.subrange(0, t-1) do ( var a : OclAny := I() ; if (a->compareTo(max_index)) < 0 then ( var cnt : int := 1 ; var dq : Sequence := (arr) ; while true do ( if cnt = a then ( execute (dq->first())->display() ; break ) else skip ; var x : OclAny := dq->first() ; dq := dq->tail() ; var y : OclAny := dq->first() ; dq := dq->tail() ; execute ((Set{x, y}->min()) : dq) ; dq := dq->prepend(Set{x, y}->max()) ; cnt := cnt + 1) ) else ( if max_flag = false then ( cnt := 1 ; dq := (arr) ; while (cnt->compareTo(max_index)) < 0 do ( x := dq->first() ; dq := dq->tail() ; y := dq->first() ; dq := dq->tail() ; execute ((Set{x, y}->min()) : dq) ; dq := dq->prepend(Set{x, y}->max()) ; cnt := cnt + 1) ; sub_arr := OclType["Sequence"](dq)->tail() ; max_flag := true ) else skip ; a := a - max_index ; a := a mod (n - 1) ; execute (mx)->display() )) ) else skip; operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation LS() : OclAny pre: true post: true activity: return input().split(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque n,queries=map(int,input().split()) arr=list(map(int,input().split())) m=max(arr) q=deque(arr) temp=[] while q[0]!=m : a=q.popleft() b=q.popleft() temp.append([a,b]) if a>b : q.appendleft(a) q.append(b) else : q.appendleft(b) q.append(a) newarr=[] while q : newarr.append(q.popleft()) while queries : queries-=1 e=int(input()) e-=1 if ecollect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : OclAny := (arr)->max() ; var q : Sequence := (arr) ; var temp : Sequence := Sequence{} ; while q->first() /= m do ( var a : OclAny := q->first() ; q := q->tail() ; var b : OclAny := q->first() ; q := q->tail() ; execute ((Sequence{a}->union(Sequence{ b })) : temp) ; if (a->compareTo(b)) > 0 then ( q := q->prepend(a) ; execute ((b) : q) ) else ( q := q->prepend(b) ; execute ((a) : q) )) ; var newarr : Sequence := Sequence{} ; while q do ( execute ((q->first()) : newarr)) ; while queries do ( queries := queries - 1 ; var e : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; e := e - 1 ; if (e->compareTo((temp)->size())) < 0 then ( execute ((argument * (test (logical_test (comparison (expr (atom (name temp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name e)))))))) ]))))))))->display() ) else ( e := e - (temp)->size() ; var x : int := e mod (n - 1) ; execute (newarr->first())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def MinOperation(a,b,n): a.sort(reverse=False) b.sort(reverse=False) result=0 for i in range(0,n,1): if(a[i]>b[i]): result=result+abs(a[i]-b[i]) elif(a[i]union(Sequence{1}->union(Sequence{ 1 })) ; b := Sequence{1}->union(Sequence{2}->union(Sequence{ 2 })) ; n := (a)->size() ; execute (MinOperation(a, b, n))->display() ) else skip; operation MinOperation(a : OclAny, b : OclAny, n : OclAny) : OclAny pre: true post: true activity: a := a->sort() ; b := b->sort() ; var result : int := 0 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if ((a[i+1]->compareTo(b[i+1])) > 0) then ( result := result + (a[i+1] - b[i+1])->abs() ) else (if ((a[i+1]->compareTo(b[i+1])) < 0) then ( result := result + (a[i+1] - b[i+1])->abs() ) else skip)) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) def S(num): s=sum(map(int,list(str(num)))) return num/s ten=0 now=1 for _ in range(k): print(now) if S(now+10**ten)>S(now+10**(ten+1)): ten+=1 now+=10**ten ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; var ten : int := 0 ; var now : int := 1 ; for _anon : Integer.subrange(0, k-1) do ( execute (now)->display() ; if (S(now + (10)->pow(ten))->compareTo(S(now + (10)->pow((ten + 1))))) > 0 then ( ten := ten + 1 ) else skip ; now := now + (10)->pow(ten)); operation S(num : OclAny) : OclAny pre: true post: true activity: var s : OclAny := (((("" + ((num))))->characters())->collect( _x | (OclType["int"])->apply(_x) ))->sum() ; return num / s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import log10,ceil def S(n : int)->int : s=0 while n>0 : s+=n % 10 n//=10 return s def f(N : int)->int : if N<10 : return N D=ceil(log10(N)+1) x=10*(N//10+1)-1 for d in range(1,D+1): td=10**(d+1) nx=td*(N//td+1)-1 if nx/S(nx)toInteger() ; var N : int := 1 ; for _anon : Integer.subrange(0, K-1) do ( execute (N)->display() ; N := f(N + 1)) ) else skip; operation S(n : int) : int pre: true post: true activity: var s : int := 0 ; while n > 0 do ( s := s + n mod 10 ; n := n div 10) ; return s; operation f(N : int) : int pre: true post: true activity: if N < 10 then ( return N ) else skip ; var D : OclAny := ceil(log10(N) + 1) ; var x : double := 10 * (N div 10 + 1) - 1 ; for d : Integer.subrange(1, D + 1-1) do ( var td : double := (10)->pow((d + 1)) ; var nx : double := td * (N div td + 1) - 1 ; if (nx / S(nx)->compareTo(x / S(x))) < 0 then ( x := nx ) else skip) ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math input=sys.stdin.readline q,h,s,d=map(int,input().split()) n=int(input()) ans=0 if n>=2 : ans+=min(8*q,4*h,2*s,d)*math.floor(n/2) if n % 2==1 : ans+=min(4*q,2*h,s) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var q : OclAny := null; var h : OclAny := null; var s : OclAny := null; var d : OclAny := null; Sequence{q,h,s,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; if n >= 2 then ( ans := ans + Set{8 * q, 4 * h, 2 * s, d}->min() * (n / 2)->floor() ) else skip ; if n mod 2 = 1 then ( ans := ans + Set{4 * q, 2 * h, s}->min() ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sunuke_sum(arg): sum_digit=0 for char in arg : sum_digit+=int(char) return sum_digit input_num=int(input()) sunuke_dict={} min_sunuke_div=10**20 for d in reversed(range(1,16)): for n in reversed(range(10,1000)): i=n*(10**d)+(10**d-1) sunuke_div=i/sunuke_sum(str(i)) sunuke_dict[i]=sunuke_div for i in reversed(range(1,110)): sunuke_div=i/sunuke_sum(str(i)) sunuke_dict[i]=sunuke_div sunuke_sorted=sorted(sunuke_dict.items()) sunuke_list=[] for value,div_value in reversed(sunuke_sorted): if min_sunuke_div>=div_value : sunuke_list.append(value) min_sunuke_div=div_value sunuke_list.reverse() for i in range(0,input_num): print(str(sunuke_list[i])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input_num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sunuke_dict : OclAny := Set{} ; var min_sunuke_div : double := (10)->pow(20) ; for d : (Integer.subrange(1, 16-1))->reverse() do ( for n : (Integer.subrange(10, 1000-1))->reverse() do ( var i : double := n * ((10)->pow(d)) + ((10)->pow(d) - 1) ; var sunuke_div : double := i / sunuke_sum(("" + ((i)))) ; sunuke_dict[i+1] := sunuke_div)) ; for i : (Integer.subrange(1, 110-1))->reverse() do ( sunuke_div := i / sunuke_sum(("" + ((i)))) ; sunuke_dict[i+1] := sunuke_div) ; var sunuke_sorted : Sequence := sunuke_dict->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sort() ; var sunuke_list : Sequence := Sequence{} ; for _tuple : (sunuke_sorted)->reverse() do (var _indx : int := 1; var value : OclAny := _tuple->at(_indx); _indx := _indx + 1; var div_value : OclAny := _tuple->at(_indx); if (min_sunuke_div->compareTo(div_value)) >= 0 then ( execute ((value) : sunuke_list) ; min_sunuke_div := div_value ) else skip) ; sunuke_list := sunuke_list->reverse() ; for i : Integer.subrange(0, input_num-1) do ( execute (("" + ((sunuke_list[i+1]))))->display()); operation sunuke_sum(arg : OclAny) : OclAny pre: true post: true activity: var sum_digit : int := 0 ; for char : arg do ( sum_digit := sum_digit + ("" + ((char)))->toInteger()) ; return sum_digit; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def solve(data): ans=0 for d in data : while d % 2==0 : ans+=1 d//=2 return ans def main(args): N=int(input()) data=[int(i)for i in input().split()] ans=solve(data) print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(data : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for d : data do ( while d mod 2 = 0 do ( ans := ans + 1 ; d := d div 2)) ; return ans; operation main(args : OclAny) pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; data := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; ans := solve(data) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : N,K=map(int,input().split()) h=list() for i in range(N): h.append(int(input())) h=sorted(h) res=10**9+1 for i in range(N-K+1): if res>h[i+K-1]-h[i]: res=h[i+K-1]-h[i] print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h : Sequence := () ; for i : Integer.subrange(0, N-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : h)) ; h := h->sort() ; var res : double := (10)->pow(9) + 1 ; for i : Integer.subrange(0, N - K + 1-1) do ( if (res->compareTo(h[i + K - 1+1] - h[i+1])) > 0 then ( res := h[i + K - 1+1] - h[i+1] ) else skip) ; execute (res)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def s(n): return sum(map(int,list(str(n)))) def f(x): nines=max(0,len(str(x))-3) base=10**nines-1 d=10**nines snuke=x ratio=x/s(x) candidate=base+(x-base+d-1)//d*d for _ in range(150): new_ratio=candidate/s(candidate) if new_ratiocharacters())->collect( _x | (OclType["int"])->apply(_x) ))->sum(); operation f(x : OclAny) : OclAny pre: true post: true activity: var nines : OclAny := Set{0, (("" + ((x))))->size() - 3}->max() ; var base : double := (10)->pow(nines) - 1 ; var d : double := (10)->pow(nines) ; var snuke : OclAny := x ; var ratio : double := x / s(x) ; var candidate : OclAny := base + (x - base + d - 1) div d * d ; for _anon : Integer.subrange(0, 150-1) do ( var new_ratio : double := candidate / s(candidate) ; if (new_ratio->compareTo(ratio)) < 0 then ( snuke := candidate ; ratio := new_ratio ) else skip ; candidate := candidate + d) ; return snuke; operation main() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; snuke := 0 ; for _anon : Integer.subrange(0, k-1) do ( snuke := f(snuke + 1) ; execute (snuke)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def digitsum(n): s=str(n) array=list(map(int,s)) return sum(array) def list_to_num(l): s=0 for i in range(len(l)): s+=l[i]*pow(10,i) return s k=int(input()) def func(a): n=a+1 if a==0 : return 1 elif n/digitsum(n)==1 : return n else : s=str(n) array=list(map(int,s))[: :-1] if len(list(set(array)))==1 and list(set(array))[0]==9 : n=list_to_num(array)+1 s=str(n) array=list(map(int,s))[: :-1] min=pow(10,15) ans=0 for i in range(len(array)): for j in range(array[i]+1,10): array[i]=j temp=list_to_num(array)/digitsum(list_to_num(array)) if temptoInteger() ; skip ; n := 0 ; for i : Integer.subrange(0, k-1) do ( execute (func(n))->display() ; n := func(n)); operation digitsum(n : OclAny) : OclAny pre: true post: true activity: var s : String := ("" + ((n))) ; var array : Sequence := ((s)->collect( _x | (OclType["int"])->apply(_x) )) ; return (array)->sum(); operation list_to_num(l : OclAny) : OclAny pre: true post: true activity: s := 0 ; for i : Integer.subrange(0, (l)->size()-1) do ( s := s + l[i+1] * (10)->pow(i)) ; return s; operation func(a : OclAny) : OclAny pre: true post: true activity: n := a + 1 ; if a = 0 then ( return 1 ) else (if n / digitsum(n) = 1 then ( return n ) else ( s := ("" + ((n))) ; array := OclType["Sequence"]((s)->collect( _x | (OclType["int"])->apply(_x) ))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; if ((Set{}->union((array))))->size() = 1 & OclType["Sequence"](Set{}->union((array)))->first() = 9 then ( n := list_to_num(array) + 1 ; s := ("" + ((n))) ; array := OclType["Sequence"]((s)->collect( _x | (OclType["int"])->apply(_x) ))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ) else skip ; var min : double := (10)->pow(15) ; var ans : int := 0 ; for i : Integer.subrange(0, (array)->size()-1) do ( for j : Integer.subrange(array[i+1] + 1, 10-1) do ( array[i+1] := j ; var temp : double := list_to_num(array) / digitsum(list_to_num(array)) ; if (temp->compareTo(min)) < 0 then ( min := temp ; ans := list_to_num(array) ) else skip)) ; return ans ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def dfs(node,graph,vis): global count vis[node]=True count+=1 for i in graph[node]: if not vis[i]: dfs(i,graph,vis) n,m=map(int,input().split()) if m==0 : print(1) else : graph=defaultdict(list) for i in range(m): a,b=map(int,input().split()) graph[a].append(b) graph[b].append(a) vis=[False]*(n+1) ans=0 ans=0 for i in range(1,n+1): global count count=0 if not vis[i]: dfs(i,graph,vis) ans+=1 print(pow(2,n-ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute count : OclAny; attribute count : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if m = 0 then ( execute (1)->display() ) else ( graph := defaultdict(OclType["Sequence"]) ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; vis := MatrixLib.elementwiseMult(Sequence{ false }, (n + 1)) ; var ans : int := 0 ; ans := 0 ; for i : Integer.subrange(1, n + 1-1) do ( skip ; count := 0 ; if not(vis[i+1]) then ( dfs(i, graph, vis) ; ans := ans + 1 ) else skip) ; execute ((2)->pow(n - ans))->display() ); operation dfs(node : OclAny, graph : OclAny, vis : OclAny) pre: true post: true activity: skip ; vis[node+1] := true ; count := count + 1 ; for i : graph[node+1] do ( if not(vis[i+1]) then ( dfs(i, graph, vis) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict g=defaultdict(list) def dfs(i,visited): visited.add(i) for j in g[i]: if j not in visited : dfs(j,visited) n,e=map(int,input().split()) for _ in range(e): x,y=map(int,input().split()) g[x].append(y) g[y].append(x) visited=set() count=0 for i in g : if i not in visited : dfs(i,visited) count+=1 print(pow(2,len(visited)-count)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var g : OclAny := defaultdict(OclType["Sequence"]) ; skip ; var n : OclAny := null; var e : OclAny := null; Sequence{n,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for _anon : Integer.subrange(0, e-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))) ; visited := Set{}->union(()) ; var count : int := 0 ; for i : g do ( if (visited)->excludes(i) then ( dfs(i, visited) ; count := count + 1 ) else skip) ; execute ((2)->pow((visited)->size() - count))->display(); operation dfs(i : OclAny, visited : OclAny) pre: true post: true activity: execute ((i) : visited) ; for j : g[i+1] do ( if (visited)->excludes(j) then ( dfs(j, visited) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout def find(node): if node==dsu[node]: return node else : dsu[node]=find(dsu[node]) return dsu[node] n,m=map(int,input().split()) if m==0 : print(1) else : dsu=[i for i in range(n+1)] for __ in range(m): a,b=map(int,input().split()) dsu[find(b)]=find(a) maxm=[0 for i in range(n+1)] for i in range(1,n+1): maxm[find(i)]+=1 d=1 for i in maxm : if i>0 : d*=2**(i-1) print(d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if m = 0 then ( execute (1)->display() ) else ( var dsu : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (i)) ; for __ : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; dsu[find(b)+1] := find(a)) ; var maxm : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(1, n + 1-1) do ( maxm[find(i)+1] := maxm[find(i)+1] + 1) ; var d : int := 1 ; for i : maxm do ( if i > 0 then ( d := d * (2)->pow((i - 1)) ) else skip) ; execute (d)->display() ); operation find(node : OclAny) : OclAny pre: true post: true activity: if node = dsu[node+1] then ( return node ) else ( dsu[node+1] := find(dsu[node+1]) ; return dsu[node+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout from collections import defaultdict nmbr=lambda : int(stdin.readline()) lst=lambda : list(map(int,stdin.readline().split())) def dfs(src): global ans,sz vis[src]=1 sz+=1 for neigh in g[src]: if not vis[neigh]: dfs(neigh) for _ in range(1): n,eg=lst() g=defaultdict(list) for i in range(eg): u,v=lst() g[u]+=[v] g[v]+=[u] ans=0 vis=[0]*(1+n) for i in range(n): if not vis[i]: sz=0 dfs(i) ans+=sz-1 print(1<toInteger()) ; var lst : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; skip ; for _anon : Integer.subrange(0, 1-1) do ( var n : OclAny := null; var eg : OclAny := null; Sequence{n,eg} := lst->apply() ; var g : OclAny := defaultdict(OclType["Sequence"]) ; for i : Integer.subrange(0, eg-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := lst->apply() ; g[u+1] := g[u+1] + Sequence{ v } ; g[v+1] := g[v+1] + Sequence{ u }) ; ans := 0 ; var vis : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (1 + n)) ; for i : Integer.subrange(0, n-1) do ( if not(vis[i+1]) then ( sz := 0 ; dfs(i) ; ans := ans + sz - 1 ) else skip) ; execute (1 * (2->pow(ans)))->display()); operation dfs(src : OclAny) pre: true post: true activity: skip; skip ; vis[src+1] := 1 ; sz := sz + 1 ; for neigh : g[src+1] do ( if not(vis[neigh+1]) then ( dfs(neigh) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def printGreater(x,y): X=y*math.log(x); Y=x*math.log(y); if(abs(X-Y)<1e-9): print("Equal"); elif(X>Y): print(x,"^",y); else : print(y,"^",x); x=5 ; y=8 ; printGreater(x,y); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; x := 5; ; y := 8; ; printGreater(x, y);; operation printGreater(x : OclAny, y : OclAny) pre: true post: true activity: var X : double := y * (x)->log(); ; var Y : double := x * (y)->log(); ; if ((X - Y)->abs() < ("1e-9")->toReal()) then ( execute ("Equal")->display(); ) else (if ((X->compareTo(Y)) > 0) then ( execute (x)->display(); ) else ( execute (y)->display(); ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q,h,s,d=[int(i)for i in input().split()] n=int(input()) s=min(s,min(h*2,q*4)) d=min(d,s*2) print((n//2)*d+(n % 2)*s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : OclAny := null; var h : OclAny := null; var s : OclAny := null; var d : OclAny := null; Sequence{q,h,s,d} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := Set{s, Set{h * 2, q * 4}->min()}->min() ; var d : OclAny := Set{d, s * 2}->min() ; execute ((n div 2) * d + (n mod 2) * s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools def compute(): pentanum=PentagonalNumberHelper() min_d=None for i in itertools.count(2): pent_i=pentanum.term(i) if min_d is not None and pent_i-pentanum.term(i-1)>=min_d : break for j in range(i-1,0,-1): pent_j=pentanum.term(j) diff=pent_i-pent_j if min_d is not None and diff>=min_d : break elif pentanum.is_term(pent_i+pent_j)and pentanum.is_term(diff): min_d=diff return str(min_d) class PentagonalNumberHelper : def __init__(self): self.term_list=[0] self.term_set=set() def term(self,x): assert x>0 while len(self.term_list)<=x : n=len(self.term_list) term=(n*(n*3-1))>>1 self.term_list.append(term) self.term_set.add(term) return self.term_list[x] def is_term(self,y): assert y>0 while self.term_list[-1]>1 self.term_list.append(term) self.term_set.add(term) return y in self.term_set if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class PentagonalNumberHelper { static operation newPentagonalNumberHelper() : PentagonalNumberHelper pre: true post: PentagonalNumberHelper->exists( _x | result = _x ); attribute term_list : Sequence := Sequence{ 0 }; attribute term_set : Set := Set{}->union(()); operation initialise() : PentagonalNumberHelper pre: true post: true activity: self.term_list := Sequence{ 0 } ; self.term_set := Set{}->union(()); return self; operation term(x : OclAny) : OclAny pre: true post: true activity: assert x > 0 do "assertion failed" ; while ((self.term_list)->size()->compareTo(x)) <= 0 do ( var n : int := (self.term_list)->size() ; var term : int := (n * (n * 3 - 1)) /(2->pow(1)) ; (expr (atom (name self)) (trailer . (name term_list)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name term)))))))) )))) ; (expr (atom (name self)) (trailer . (name term_set)) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name term)))))))) ))))) ; return self.term_list[x+1]; operation is_term(y : OclAny) : OclAny pre: true post: true activity: assert y > 0 do "assertion failed" ; while (self.term_list->last()->compareTo(y)) < 0 do ( n := (self.term_list)->size() ; term := (n * (n * 3 - 1)) /(2->pow(1)) ; (expr (atom (name self)) (trailer . (name term_list)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name term)))))))) )))) ; (expr (atom (name self)) (trailer . (name term_set)) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name term)))))))) ))))) ; return (self.term_set)->includes(y); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var pentanum : OclAny := PentagonalNumberHelper() ; var min_d : OclAny := null ; for i : itertools->count(2) do ( var pent_i : OclAny := pentanum.term(i) ; if not(min_d <>= null) & (pent_i - pentanum.term(i - 1)->compareTo(min_d)) >= 0 then ( break ) else skip ; for j : Integer.subrange(0 + 1, i - 1)->reverse() do ( var pent_j : OclAny := pentanum.term(j) ; var diff : double := pent_i - pent_j ; if not(min_d <>= null) & (diff->compareTo(min_d)) >= 0 then ( break ) else (if pentanum.is_term(pent_i + pent_j) & pentanum.is_term(diff) then ( min_d := diff ) else skip))) ; return ("" + ((min_d))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def leonardo(n): dp=[]; dp.append(1); dp.append(1); for i in range(2,n+1): dp.append(dp[i-1]+dp[i-2]+1); return dp[n]; print(leonardo(3)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (leonardo(3))->display();; operation leonardo(n : OclAny) pre: true post: true activity: var dp : Sequence := Sequence{}; ; execute ((1) : dp); ; execute ((1) : dp); ; for i : Integer.subrange(2, n + 1-1) do ( execute ((dp[i - 1+1] + dp[i - 2+1] + 1) : dp);) ; return dp[n+1];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p=10**9 for _ in range(int(input())): n=int(input()) if pow(3,n-1)>p : print("NO") else : print("YES") print(" ".join([str(3**x)for x in range(n)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : double := (10)->pow(9) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if ((3)->pow(n - 1)->compareTo(p)) > 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; execute (StringLib.sumStringsWithSeparator((Integer.subrange(0, n-1)->select(x | true)->collect(x | (("" + (((3)->pow(x))))))), " "))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- [N,K]=list(map(int,input().split())) h=[] for i in range(N): h.append(int(input())) h.sort(reverse=True) out=10**9 L=0 R=K-1 while R<=N-1 : D=h[L]-h[R] if out>D : out=D L+=1 R+=1 print(out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: Sequence{N}->union(Sequence{ K }) := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var h : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : h)) ; h := h->sort() ; var out : double := (10)->pow(9) ; var L : int := 0 ; var R : double := K - 1 ; while (R->compareTo(N - 1)) <= 0 do ( var D : double := h[L+1] - h[R+1] ; if (out->compareTo(D)) > 0 then ( out := D ) else skip ; L := L + 1 ; R := R + 1) ; execute (out)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) if 3**(n-1)>10**9 : print("NO") else : print("YES") print(*[3**x for x in range(n)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if ((3)->pow((n - 1))->compareTo((10)->pow(9))) > 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 3)))) ** (expr (atom (name x))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) ])))))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for t in range(T): n=int(input()) if(n>19): print("NO") else : print("YES") x=1 for i in range(n): print(x,end=" ") x*=3 print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(0, T-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n > 19) then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; var x : int := 1 ; for i : Integer.subrange(0, n-1) do ( execute (x)->display() ; x := x * 3) ; execute (->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math testcases=int(input()) while(testcases>0): testcases-=1 n=int(input()) if(n>19): print("NO") else : print("YES") for i in range(0,n): print(pow(3,i),end="") print("") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var testcases : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (testcases > 0) do ( testcases := testcases - 1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n > 19) then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; for i : Integer.subrange(0, n-1) do ( execute ((3)->pow(i))->display()) ; execute ("")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(a==0): return b return gcd(b % a,a) def printAllDivisors(arr,N): g=arr[0] divisors=dict() for i in range(1,N): g=gcd(arr[i],g) for i in range(1,g+1): if i*i>g : break if(g % i==0): divisors[i]=1 if(g//i!=i): divisors[g//i]=1 for it in sorted(divisors): print(it,end=" ") if __name__=='__main__' : arr=[6,90,12,18,30,24] n=len(arr) printAllDivisors(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{6}->union(Sequence{90}->union(Sequence{12}->union(Sequence{18}->union(Sequence{30}->union(Sequence{ 24 }))))) ; var n : int := (arr)->size() ; printAllDivisors(arr, n) ) else skip; operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0) then ( return b ) else skip ; return gcd(b mod a, a); operation printAllDivisors(arr : OclAny, N : OclAny) pre: true post: true activity: var g : OclAny := arr->first() ; var divisors : Map := (arguments ( )) ; for i : Integer.subrange(1, N-1) do ( g := gcd(arr[i+1], g)) ; for i : Integer.subrange(1, g + 1-1) do ( if (i * i->compareTo(g)) > 0 then ( break ) else skip ; if (g mod i = 0) then ( divisors[i+1] := 1 ; if (g div i /= i) then ( divisors[g div i+1] := 1 ) else skip ) else skip) ; for it : divisors->keys()->sort() do ( execute (it)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* def cal(n): res=pow(ceil((pow(pow(10,(n-1)),1/4))),4) return int(res) n=1 print(cal(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 1 ; execute (cal(n))->display(); operation cal(n : OclAny) : OclAny pre: true post: true activity: var res : double := (ceil((((10)->pow((n - 1)))->pow(1 / 4))))->pow(4) ; return ("" + ((res)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def result(N): for num in range(N): if num % 3==0 and num % 5==0 : print(str(num)+"",end="") else : pass if __name__=="__main__" : N=100 result(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := 100 ; result(N) ) else skip; operation result(N : OclAny) pre: true post: true activity: for num : Integer.subrange(0, N-1) do ( if num mod 3 = 0 & num mod 5 = 0 then ( execute (("" + ((num))) + "")->display() ) else ( skip )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def soln(): n_arr_len,k_subarr=(int(_)for _ in input().split()) arr=[int(_a)for _a in input().split()] if k_subarr==1 : return min(arr) if k_subarr==2 : return max(arr[0],arr[n_arr_len-1]) else : return max(arr) print(soln()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (soln())->display(); operation soln() : OclAny pre: true post: true activity: var n_arr_len : OclAny := null; var k_subarr : OclAny := null; Sequence{n_arr_len,k_subarr} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name _)))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var arr : Sequence := input().split()->select(_a | true)->collect(_a | (("" + ((_a)))->toInteger())) ; if k_subarr = 1 then ( return (arr)->min() ) else skip ; if k_subarr = 2 then ( return Set{arr->first(), arr[n_arr_len - 1+1]}->max() ) else ( return (arr)->max() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def FirstAndLast(string): ch=list(string); i=0 ; while i=97 and ord(ch[k])<=122): ch[k]=chr(ord(ch[k])-32); else : ch[k]=ch[k] if(ord(ch[i-1])>=90 and ord(ch[i-1])<=122): ch[i-1]=chr(ord(ch[i-1])-32); else : ch[i-1]=ch[i-1] i+=1 return "".join(ch); if __name__=="__main__" : string="Geeks for Geeks" ; print(string); print(FirstAndLast(string)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( string := "Geeks for Geeks"; ; execute (string)->display(); ; execute (FirstAndLast(string))->display(); ) else skip; operation FirstAndLast(string : OclAny) pre: true post: true activity: var ch : Sequence := (string)->characters(); ; var i : int := 0; ; while (i->compareTo((ch)->size())) < 0 do ( var k : int := i; ; while ((i->compareTo((ch)->size())) < 0 & ch[i+1] /= ' ') do ( i := i + 1;) ; if ((ch[k+1])->char2byte() >= 97 & (ch[k+1])->char2byte() <= 122) then ( ch[k+1] := ((ch[k+1])->char2byte() - 32)->byte2char(); ) else ( ch[k+1] := ch[k+1] ) ; if ((ch[i - 1+1])->char2byte() >= 90 & (ch[i - 1+1])->char2byte() <= 122) then ( ch[i - 1+1] := ((ch[i - 1+1])->char2byte() - 32)->byte2char(); ) else ( ch[i - 1+1] := ch[i - 1+1] ) ; i := i + 1) ; return StringLib.sumStringsWithSeparator((ch), "");; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,r=map(int,input().split()) if(r*2>a or r*2>b): print("Second") else : print("First") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var r : OclAny := null; Sequence{a,b,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if ((r * 2->compareTo(a)) > 0 or (r * 2->compareTo(b)) > 0) then ( execute ("Second")->display() ) else ( execute ("First")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import io,os import math from heapq import* gcd=math.gcd sqrt=math.sqrt def ceil(a,b): a=-a k=a//b k=-k return k input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def strinp(testcases): k=5 if(testcases==-1 or testcases==1): k=1 f=str(input()) f=f[2 : len(f)-k] return f def main(): arr=list(map(int,input().split())) a=arr[0] b=arr[1] r=arr[2] if(a>=2*r and b>=2*r): print("First") else : print("Second") main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var gcd : OclAny := ; var sqrt : OclAny := ; skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; skip ; skip ; main(); operation ceil(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: a := -a ; var k : int := a div b ; k := -k ; return k; operation strinp(testcases : OclAny) : OclAny pre: true post: true activity: k := 5 ; if (testcases = -1 or testcases = 1) then ( k := 1 ) else skip ; var f : String := ("" + (((OclFile["System.in"]).readLine()))) ; f := f.subrange(2+1, (f)->size() - k) ; return f; operation main() pre: true post: true activity: var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := arr->first() ; b := arr[1+1] ; var r : OclAny := arr[2+1] ; if ((a->compareTo(2 * r)) >= 0 & (b->compareTo(2 * r)) >= 0) then ( execute ("First")->display() ) else ( execute ("Second")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,r=map(int,input().split()) print('Second' if min(a,b)collect( _x | (OclType["int"])->apply(_x) ) ; execute (if (Set{a, b}->min()->compareTo(r * 2)) < 0 then 'Second' else 'First' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input().split(" ") n=int(S[0]) k=int(S[1]) arr=[] for i in range(n): arr.append(int(input())) def calculate(n,k,arr): arr.sort() drr=[] for i in range(1,n): drr.append(arr[i]-arr[i-1]) j=0 s=0 sums=[] for i in range(len(drr)-(k-1)+1): while jfirst())))->toInteger() ; var k : int := ("" + ((S[1+1])))->toInteger() ; var arr : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : arr)) ; skip ; calculate(n, k, arr); operation calculate(n : OclAny, k : OclAny, arr : OclAny) pre: true post: true activity: arr := arr->sort() ; var drr : Sequence := Sequence{} ; for i : Integer.subrange(1, n-1) do ( execute ((arr[i+1] - arr[i - 1+1]) : drr)) ; var j : int := 0 ; var s : int := 0 ; var sums : Sequence := Sequence{} ; for i : Integer.subrange(0, (drr)->size() - (k - 1) + 1-1) do ( while (j->compareTo(i + (k - 1))) < 0 do ( s := s + drr[j+1] ; j := j + 1) ; execute ((s) : sums) ; s := s - drr[i+1]) ; execute ((sums)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,r=[int(x)for x in input().split()] if 2*r<=min(a,b): print('First') else : print('Second') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var r : OclAny := null; Sequence{a,b,r} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if (2 * r->compareTo(Set{a, b}->min())) <= 0 then ( execute ('First')->display() ) else ( execute ('Second')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def product(N): ans=1 ; val=2**(N-1); for i in range(1,N+1): ans*=(i**val); return ans ; if __name__=="__main__" : N=2 ; print(product(N)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := 2; ; execute (product(N))->display(); ) else skip; operation product(N : OclAny) pre: true post: true activity: var ans : int := 1; ; var val : double := (2)->pow((N - 1)); ; for i : Integer.subrange(1, N + 1-1) do ( ans := ans * ((i)->pow(val));) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkIfUnequal(n,q): s1=str(n) a=[0 for i in range(26)] for i in range(0,len(s1),1): a[ord(s1[i])-ord('0')]+=1 prod=n*q s2=str(prod) for i in range(0,len(s2),1): if(a[ord(s2[i])-ord('0')]): return False return True def countInRange(l,r,q): count=0 for i in range(l,r+1,1): if(checkIfUnequal(i,q)): count+=1 return count if __name__=='__main__' : l=10 r=12 q=2 print(countInRange(l,r,q)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( l := 10 ; r := 12 ; q := 2 ; execute (countInRange(l, r, q))->display() ) else skip; operation checkIfUnequal(n : OclAny, q : OclAny) : OclAny pre: true post: true activity: var s1 : String := ("" + ((n))) ; var a : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, (s1)->size()-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( a[(s1[i+1])->char2byte() - ('0')->char2byte()+1] := a[(s1[i+1])->char2byte() - ('0')->char2byte()+1] + 1) ; var prod : double := n * q ; var s2 : String := ("" + ((prod))) ; for i : Integer.subrange(0, (s2)->size()-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (a[(s2[i+1])->char2byte() - ('0')->char2byte()+1]) then ( return false ) else skip) ; return true; operation countInRange(l : OclAny, r : OclAny, q : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(l, r + 1-1)->select( $x | ($x - l) mod 1 = 0 ) do ( if (checkIfUnequal(i, q)) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfPrevK(N,K): arr=[0]*N ; prevsum=0 ; arr[0]=1 ; for i in range(N-1): if(i<=K): arr[i+1]=arr[i]+prevsum ; prevsum=arr[i+1]; else : arr[i+1]=arr[i]+prevsum-arr[i+1-K]; prevsum=arr[i]+prevsum ; for i in range(N): print(arr[i],end=" "); if __name__=='__main__' : N=8 ; K=3 ; sumOfPrevK(N,K); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( N := 8; ; K := 3; ; sumOfPrevK(N, K); ) else skip; operation sumOfPrevK(N : OclAny, K : OclAny) pre: true post: true activity: var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N); ; var prevsum : int := 0; ; arr->first() := 1; ; for i : Integer.subrange(0, N - 1-1) do ( if ((i->compareTo(K)) <= 0) then ( arr[i + 1+1] := arr[i+1] + prevsum; ; prevsum := arr[i + 1+1]; ) else ( arr[i + 1+1] := arr[i+1] + prevsum - arr[i + 1 - K+1]; ; prevsum := arr[i+1] + prevsum; )) ; for i : Integer.subrange(0, N-1) do ( execute (arr[i+1])->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compress(list01): newList=[] n=len(list01) now=1 count0=0 count1=0 list01.append((list01[-1]+1)% 2) for i in range(n+1): nex=list01[i] if now==0 : if nex==0 : count0+=1 if nex==1 : count1+=1 newList.append(count0) count0=0 if now==1 : if nex==0 : count0+=1 newList.append(count1) count1=0 if nex==1 : count1+=1 now=nex if list01[-2]==0 : newList.append(0) return newList def measure_insect(mixed_list,k): n=(len(mixed_list)-1)//2 now=sum(mixed_list[: 2*k+1]) maximum=now for i in range(n-k): now-=mixed_list[2*i] now-=mixed_list[2*i+1] now+=mixed_list[2*i+2*k+1] now+=mixed_list[2*i+2*k+2] if now>maximum : maximum=now return maximum N,K=map(int,input().split()) S=[int(_)for _ in input()] print(measure_insect(compress(S),K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : Sequence := (OclFile["System.in"]).readLine()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; execute (measure_insect(compress(S), K))->display(); operation compress(list01 : OclAny) : OclAny pre: true post: true activity: var newList : Sequence := Sequence{} ; var n : int := (list01)->size() ; var now : int := 1 ; var count0 : int := 0 ; var count1 : int := 0 ; execute (((list01->last() + 1) mod 2) : list01) ; for i : Integer.subrange(0, n + 1-1) do ( var nex : OclAny := list01[i+1] ; if now = 0 then ( if nex = 0 then ( count0 := count0 + 1 ) else skip ; if nex = 1 then ( count1 := count1 + 1 ; execute ((count0) : newList) ; count0 := 0 ) else skip ) else skip ; if now = 1 then ( if nex = 0 then ( count0 := count0 + 1 ; execute ((count1) : newList) ; count1 := 0 ) else skip ; if nex = 1 then ( count1 := count1 + 1 ) else skip ) else skip ; now := nex) ; if list01->front()->last() = 0 then ( execute ((0) : newList) ) else skip ; return newList; operation measure_insect(mixed_list : OclAny, k : OclAny) : OclAny pre: true post: true activity: n := ((mixed_list)->size() - 1) div 2 ; now := (mixed_list.subrange(1,2 * k + 1))->sum() ; var maximum : int := now ; for i : Integer.subrange(0, n - k-1) do ( now := now - mixed_list[2 * i+1] ; now := now - mixed_list[2 * i + 1+1] ; now := now + mixed_list[2 * i + 2 * k + 1+1] ; now := now + mixed_list[2 * i + 2 * k + 2+1] ; if (now->compareTo(maximum)) > 0 then ( maximum := now ) else skip) ; return maximum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countNumbers(L,R,K): if(K==9): K=0 totalnumbers=R-L+1 factor9=totalnumbers//9 rem=totalnumbers % 9 ans=factor9 for i in range(R,R-rem,-1): rem1=i % 9 if(rem1==K): ans+=1 return ans L=10 R=22 K=3 print(countNumbers(L,R,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; L := 10 ; R := 22 ; K := 3 ; execute (countNumbers(L, R, K))->display(); operation countNumbers(L : OclAny, R : OclAny, K : OclAny) : OclAny pre: true post: true activity: if (K = 9) then ( K := 0 ) else skip ; var totalnumbers : double := R - L + 1 ; var factor9 : int := totalnumbers div 9 ; var rem : int := totalnumbers mod 9 ; var ans : int := factor9 ; for i : Integer.subrange(R - rem + 1, R)->reverse() do ( var rem1 : int := i mod 9 ; if (rem1 = K) then ( ans := ans + 1 ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import groupby from collections import deque N,K=[int(x)for x in input().split()] blocks=[[tp,list(people)]for tp,people in groupby(input())] ans=0 cur=0 stand=0 target=deque() for tp,people in blocks : if tp=='0' : stand+=1 if stand>K : removed=target.popleft() cur-=len(removed[1]) if removed[0]=='1' and len(target)>0 : removed=target.popleft() cur-=len(removed[1]) target.append([tp,people]) cur+=len(people) ans=max(ans,cur) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var blocks : Sequence := groupby((OclFile["System.in"]).readLine())->select(_tuple | true)->collect(_tuple | let tp : OclAny = _tuple->at(1) in let people : OclAny = _tuple->at(2) in (Sequence{tp}->union(Sequence{ (people) }))) ; var ans : int := 0 ; var cur : int := 0 ; var stand : int := 0 ; var target : Sequence := () ; for _tuple : blocks do (var _indx : int := 1; var tp : OclAny := _tuple->at(_indx); _indx := _indx + 1; var people : OclAny := _tuple->at(_indx); if tp = '0' then ( stand := stand + 1 ; if (stand->compareTo(K)) > 0 then ( var removed : OclAny := target->first() ; target := target->tail() ; cur := cur - (removed[1+1])->size() ; if removed->first() = '1' & (target)->size() > 0 then ( removed := target->first() ; target := target->tail() ; cur := cur - (removed[1+1])->size() ) else skip ) else skip ) else skip ; execute ((Sequence{tp}->union(Sequence{ people })) : target) ; cur := cur + (people)->size() ; ans := Set{ans, cur}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,input().split()) S=list(input())+[-1] bw=[0]*N ind=0 for i in range(N): bw[ind]+=S[i]==S[i+1] if S[i]!=S[i+1]: bw[ind]+=1 ind+=1 ind=0 res=0 cumsumbw=[0]+[bw[0]]+[0]*(N-1) for i in range(1,N): cumsumbw[i+1]=cumsumbw[i]+bw[i] if N-2*K<=0 : print(N) exit(0) for i in range(N-2*K): if S[cumsumbw[i]]=="1" : res=max(res,cumsumbw[i+2*K+1]-cumsumbw[i]) else : res=max(res,cumsumbw[i+2*K]-cumsumbw[i]) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : Sequence := ((OclFile["System.in"]).readLine())->characters()->union(Sequence{ -1 }) ; var bw : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var ind : int := 0 ; for i : Integer.subrange(0, N-1) do ( bw[ind+1] := bw[ind+1] + S[i+1] = S[i + 1+1] ; if S[i+1] /= S[i + 1+1] then ( bw[ind+1] := bw[ind+1] + 1 ; ind := ind + 1 ) else skip) ; ind := 0 ; var res : int := 0 ; var cumsumbw : Sequence := Sequence{ 0 }->union(Sequence{ bw->first() })->union(MatrixLib.elementwiseMult(Sequence{ 0 }, (N - 1))) ; for i : Integer.subrange(1, N-1) do ( cumsumbw[i + 1+1] := cumsumbw[i+1] + bw[i+1]) ; if N - 2 * K <= 0 then ( execute (N)->display() ; exit(0) ) else skip ; for i : Integer.subrange(0, N - 2 * K-1) do ( if S[cumsumbw[i+1]+1] = "1" then ( res := Set{res, cumsumbw[i + 2 * K + 1+1] - cumsumbw[i+1]}->max() ) else ( res := Set{res, cumsumbw[i + 2 * K+1] - cumsumbw[i+1]}->max() )) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=[int(i)for i in input().split()] s=[0,1]+[int(i)for i in list(input())]+[1,0] down=[i for i in range(n+3)if s[i]==1 and s[i+1]==0] up=[i for i in range(n+3)if s[i]==0 and s[i+1]==1] ans=1 if k>=len(up): ans=n else : if down[k]-up[0]-1>ans : ans=down[k]-up[0]-1 for i in range(1,len(up)-k-1): if down[i+k]-up[i]>ans : ans=down[i+k]-up[i] if down[len(up)-1]-up[len(up)-k-1]-1>ans : ans=down[len(up)-1]-up[len(up)-k-1]-1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var s : Sequence := Sequence{0}->union(Sequence{ 1 })->union(((OclFile["System.in"]).readLine())->characters()->select(i | true)->collect(i | (("" + ((i)))->toInteger())))->union(Sequence{1}->union(Sequence{ 0 })) ; var down : Sequence := Integer.subrange(0, n + 3-1)->select(i | s[i+1] = 1 & s[i + 1+1] = 0)->collect(i | (i)) ; var up : Sequence := Integer.subrange(0, n + 3-1)->select(i | s[i+1] = 0 & s[i + 1+1] = 1)->collect(i | (i)) ; var ans : int := 1 ; if (k->compareTo((up)->size())) >= 0 then ( ans := n ) else ( if (down[k+1] - up->first() - 1->compareTo(ans)) > 0 then ( ans := down[k+1] - up->first() - 1 ) else skip ; for i : Integer.subrange(1, (up)->size() - k - 1-1) do ( if (down[i + k+1] - up[i+1]->compareTo(ans)) > 0 then ( ans := down[i + k+1] - up[i+1] ) else skip) ; if (down[(up)->size() - 1+1] - up[(up)->size() - k - 1+1] - 1->compareTo(ans)) > 0 then ( ans := down[(up)->size() - 1+1] - up[(up)->size() - k - 1+1] - 1 ) else skip ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) S=input()+"*" A=[0]if S[0]=="1" else[] cnt,fig=0,S[0] for i in range(n+1): if fig!=S[i]: A.append(cnt) fig=S[i] cnt=1 else : cnt+=1 if S[-2]=="0" : A.append(0) num=2*(k+1) B=[[0,0]]if S[0]=="0" else[] for i in range(1,len(A)): A[i]=A[i]+A[i-1] for i in range(0,len(A),2): B.append([A[i],A[i+1]]) C=[] left=0 for i in range(max(0,len(B)-k)): C.append(B[k+i][1]-B[left+i][0]) print(max(C)if len(B)-k>0 else B[-1][1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : String := (OclFile["System.in"]).readLine() + "*" ; var A : Sequence := if S->first() = "1" then Sequence{ 0 } else Sequence{} endif ; var cnt : OclAny := null; var fig : OclAny := null; Sequence{cnt,fig} := Sequence{0,S->first()} ; for i : Integer.subrange(0, n + 1-1) do ( if fig /= S[i+1] then ( execute ((cnt) : A) ; var fig : OclAny := S[i+1] ; var cnt : int := 1 ) else ( cnt := cnt + 1 )) ; if S->front()->last() = "0" then ( execute ((0) : A) ) else skip ; var num : double := 2 * (k + 1) ; var B : Sequence := if S->first() = "0" then Sequence{ Sequence{0}->union(Sequence{ 0 }) } else Sequence{} endif ; for i : Integer.subrange(1, (A)->size()-1) do ( A[i+1] := A[i+1] + A[i - 1+1]) ; for i : Integer.subrange(0, (A)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( execute ((Sequence{A[i+1]}->union(Sequence{ A[i + 1+1] })) : B)) ; var C : Sequence := Sequence{} ; var left : int := 0 ; for i : Integer.subrange(0, Set{0, (B)->size() - k}->max()-1) do ( execute ((B[k + i+1][1+1] - B[left + i+1]->first()) : C)) ; execute (if (B)->size() - k > 0 then (C)->max() else B->last()[1+1] endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math ; MAX=10000 ; primes=[]; def sieve(): n=MAX ; nNew=int(n/2); marked=[False]*(nNew+100); tmp=int(math.sqrt(n)); for i in range(1,int((tmp-1)/2)+1): for j in range((i*(i+1))<<1,nNew+1,2*i+1): marked[j]=True ; primes.append(2); for i in range(1,nNew+1): if(marked[i]==False): primes.append(2*i+1); def primeLcm(arr,n): factors=[0]*(MAX); for i in range(n): copy=arr[i]; sqr=int(math.sqrt(copy)); j=0 ; while(primes[j]<=sqr): if(copy % primes[j]==0): while(copy % primes[j]==0): copy=int(copy/primes[j]); factors[primes[j]]=1 ; j+=1 ; if(copy>1): factors[copy]=1 ; if(factors[2]==1): print("2 ",end=""); for i in range(3,MAX+1,2): if(factors[i]==1): print(i,end=" "); sieve(); arr=[20,10,15,60]; n=len(arr); primeLcm(arr,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; ; var MAX : int := 10000; ; var primes : Sequence := Sequence{}; ; skip ; skip ; sieve(); ; arr := Sequence{20}->union(Sequence{10}->union(Sequence{15}->union(Sequence{ 60 }))); ; n := (arr)->size(); ; primeLcm(arr, n);; operation sieve() pre: true post: true activity: var n : int := MAX; ; var nNew : int := ("" + ((n / 2)))->toInteger(); ; var marked : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (nNew + 100)); ; var tmp : int := ("" + (((n)->sqrt())))->toInteger(); ; for i : Integer.subrange(1, ("" + (((tmp - 1) / 2)))->toInteger() + 1-1) do ( for j : Integer.subrange((i * (i + 1)) * (2->pow(1)), nNew + 1-1)->select( $x | ($x - (i * (i + 1)) * (2->pow(1))) mod 2 * i + 1 = 0 ) do ( marked[j+1] := true;)) ; execute ((2) : primes); ; for i : Integer.subrange(1, nNew + 1-1) do ( if (marked[i+1] = false) then ( execute ((2 * i + 1) : primes); ) else skip); operation primeLcm(arr : OclAny, n : OclAny) pre: true post: true activity: var factors : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX)); ; for i : Integer.subrange(0, n-1) do ( var copy : OclAny := arr[i+1]; ; var sqr : int := ("" + (((copy)->sqrt())))->toInteger(); ; var j : int := 0; ; while ((primes[j+1]->compareTo(sqr)) <= 0) do ( if (copy mod primes[j+1] = 0) then ( while (copy mod primes[j+1] = 0) do ( copy := ("" + ((copy / primes[j+1])))->toInteger();) ; factors[primes[j+1]+1] := 1; ) else skip ; j := j + 1;) ; if (copy > 1) then ( factors[copy+1] := 1; ) else skip) ; if (factors[2+1] = 1) then ( execute ("2 ")->display(); ) else skip ; for i : Integer.subrange(3, MAX + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if (factors[i+1] = 1) then ( execute (i)->display(); ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,m=map(int,input().split()) h=[int(input())for _ in range(n)] h.sort() temp=[] for i in range(n-m+1): temp.append(h[i+m-1]-h[i]) temp.sort() print(temp[0]) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; h := h->sort() ; var temp : Sequence := Sequence{} ; for i : Integer.subrange(0, n - m + 1-1) do ( execute ((h[i + m - 1+1] - h[i+1]) : temp)) ; temp := temp->sort() ; execute (temp->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def makeAnagram(a,b): buffer=[0]*26 for char in a : buffer[ord(char)-ord('a')]+=1 for char in b : buffer[ord(char)-ord('a')]-=1 return sum(map(abs,buffer)) if __name__=="__main__" : str1="bcadeh" str2="hea" print(makeAnagram(str1,str2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var str1 : String := "bcadeh" ; var str2 : String := "hea" ; execute (makeAnagram(str1, str2))->display() ) else skip; operation makeAnagram(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var buffer : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for char : a do ( buffer[(char)->char2byte() - ('a')->char2byte()+1] := buffer[(char)->char2byte() - ('a')->char2byte()+1] + 1) ; for char : b do ( buffer[(char)->char2byte() - ('a')->char2byte()+1] := buffer[(char)->char2byte() - ('a')->char2byte()+1] - 1) ; return ((buffer)->collect( _x | (abs)->apply(_x) ))->sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def totalBoxesRemoved(arr,n): count=0 prev=arr[0] for i in range(1,n): if(arr[i]>prev): count+=(arr[i]-prev) arr[i]=prev prev=arr[i] else : prev=arr[i] return count arr=[5,4,7,3,2,1] n=len(arr) print(totalBoxesRemoved(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{5}->union(Sequence{4}->union(Sequence{7}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 1 }))))) ; n := (arr)->size() ; execute (totalBoxesRemoved(arr, n))->display(); operation totalBoxesRemoved(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var prev : OclAny := arr->first() ; for i : Integer.subrange(1, n-1) do ( if ((arr[i+1]->compareTo(prev)) > 0) then ( count := count + (arr[i+1] - prev) ; arr[i+1] := prev ; prev := arr[i+1] ) else ( prev := arr[i+1] )) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findProduct(arr,n): sorted(arr) prod=1 for i in range(0,n,1): if(arr[i-1]!=arr[i]): prod=prod*arr[i] return prod ; if __name__=='__main__' : arr=[1,2,3,1,1,4,5,6] n=len(arr) print(findProduct(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{1}->union(Sequence{1}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))))))) ; n := (arr)->size() ; execute (findProduct(arr, n))->display() ) else skip; operation findProduct(arr : OclAny, n : OclAny) pre: true post: true activity: sorted(arr) ; var prod : int := 1 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (arr[i - 1+1] /= arr[i+1]) then ( prod := prod * arr[i+1] ) else skip) ; return prod;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def centeredSquare_number(N): n=(9+sqrt(36*N+45))/18 ; if(n-int(n))==0 : return 1 else : return 0 if __name__=="__main__" : i=13 ; print(centeredSquare_number(i)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var i : int := 13; ; execute (centeredSquare_number(i))->display(); ) else skip; operation centeredSquare_number(N : OclAny) : OclAny pre: true post: true activity: var n : double := (9 + sqrt(36 * N + 45)) / 18; ; if (n - ("" + ((n)))->toInteger()) = 0 then ( return 1 ) else ( return 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline inp=lambda : list(map(int,input().split())) def answer(a,b,c,d,e,f): if(e>f): m=min(a,d) ans=e*m d-=m ans+=f*min(b,c,d) else : m=min(b,c,d) ans=f*m d-=m ans+=e*min(a,d) return ans for T in range(1): a=int(input()) b=int(input()) c=int(input()) d=int(input()) e=int(input()) f=int(input()) print(answer(a,b,c,d,e,f)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; var inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; skip ; for T : Integer.subrange(0, 1-1) do ( a := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; b := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; c := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; d := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; e := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; f := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (answer(a, b, c, d, e, f))->display()); operation answer(a : OclAny, b : OclAny, c : OclAny, d : OclAny, e : OclAny, f : OclAny) : OclAny pre: true post: true activity: if ((e->compareTo(f)) > 0) then ( var m : OclAny := Set{a, d}->min() ; var ans : double := e * m ; d := d - m ; ans := ans + f * Set{b, c, d}->min() ) else ( m := Set{b, c, d}->min() ; ans := f * m ; d := d - m ; ans := ans + e * Set{a, d}->min() ) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxLength(s,n): invalidOpenBraces=0 ; invalidCloseBraces=0 ; for i in range(n): if(s[i]=='('): invalidOpenBraces+=1 else : if(invalidOpenBraces==0): invalidCloseBraces+=1 else : invalidOpenBraces-=1 return(n-(invalidOpenBraces+invalidCloseBraces)) s="()(((((()" n=len(s) print(maxLength(s,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := "()(((((()" ; n := (s)->size() ; execute (maxLength(s, n))->display(); operation maxLength(s : OclAny, n : OclAny) : OclAny pre: true post: true activity: var invalidOpenBraces : int := 0; ; var invalidCloseBraces : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (s[i+1] = '(') then ( invalidOpenBraces := invalidOpenBraces + 1 ) else ( if (invalidOpenBraces = 0) then ( invalidCloseBraces := invalidCloseBraces + 1 ) else ( invalidOpenBraces := invalidOpenBraces - 1 ) )) ; return (n - (invalidOpenBraces + invalidCloseBraces)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def countPrimitiveRoots(p): result=1 for i in range(2,p,1): if(gcd(i,p)==1): result+=1 return result if __name__=='__main__' : p=5 print(countPrimitiveRoots(p-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( p := 5 ; execute (countPrimitiveRoots(p - 1))->display() ) else skip; operation countPrimitiveRoots(p : OclAny) : OclAny pre: true post: true activity: var result : int := 1 ; for i : Integer.subrange(2, p-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (gcd(i, p) = 1) then ( result := result + 1 ) else skip) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=4 def add(A,B,C): for i in range(N): for j in range(N): C[i][j]=A[i][j]+B[i][j] A=[[1,1,1,1],[2,2,2,2],[3,3,3,3],[4,4,4,4]] B=[[1,1,1,1],[2,2,2,2],[3,3,3,3],[4,4,4,4]] C=A[:][:] add(A,B,C) print("Result matrix is") for i in range(N): for j in range(N): print(C[i][j]," ",end='') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 4 ; skip ; A := Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })))}->union(Sequence{Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 2 })))}->union(Sequence{Sequence{3}->union(Sequence{3}->union(Sequence{3}->union(Sequence{ 3 })))}->union(Sequence{ Sequence{4}->union(Sequence{4}->union(Sequence{4}->union(Sequence{ 4 }))) }))) ; B := Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })))}->union(Sequence{Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 2 })))}->union(Sequence{Sequence{3}->union(Sequence{3}->union(Sequence{3}->union(Sequence{ 3 })))}->union(Sequence{ Sequence{4}->union(Sequence{4}->union(Sequence{4}->union(Sequence{ 4 }))) }))) ; C := A ; add(A, B, C) ; execute ("Result matrix is")->display() ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( execute (C[i+1][j+1])->display()) ; execute (->display()); operation add(A : OclAny, B : OclAny, C : OclAny) pre: true post: true activity: for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( C[i+1][j+1] := A[i+1][j+1] + B[i+1][j+1])); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=4 def subtract(A,B,C): for i in range(N): for j in range(N): C[i][j]=A[i][j]-B[i][j] A=[[1,1,1,1],[2,2,2,2],[3,3,3,3],[4,4,4,4]] B=[[1,1,1,1],[2,2,2,2],[3,3,3,3],[4,4,4,4]] C=A[:][:] subtract(A,B,C) print("Result matrix is") for i in range(N): for j in range(N): print(C[i][j]," ",end='') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 4 ; skip ; A := Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })))}->union(Sequence{Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 2 })))}->union(Sequence{Sequence{3}->union(Sequence{3}->union(Sequence{3}->union(Sequence{ 3 })))}->union(Sequence{ Sequence{4}->union(Sequence{4}->union(Sequence{4}->union(Sequence{ 4 }))) }))) ; B := Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })))}->union(Sequence{Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 2 })))}->union(Sequence{Sequence{3}->union(Sequence{3}->union(Sequence{3}->union(Sequence{ 3 })))}->union(Sequence{ Sequence{4}->union(Sequence{4}->union(Sequence{4}->union(Sequence{ 4 }))) }))) ; C := A ; subtract(A, B, C) ; execute ("Result matrix is")->display() ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( execute (C[i+1][j+1])->display()) ; execute (->display()); operation subtract(A : OclAny, B : OclAny, C : OclAny) pre: true post: true activity: for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( C[i+1][j+1] := A[i+1][j+1] - B[i+1][j+1])); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getRightMin(arr,n): min=arr[0] rightMin=0 i=1 while(i0): if(arr[i]==max): leftMax=i i=int(i/2) i=leftMax-1 while(i>=0 and arr[i]==max): leftMax=i i-=1 return leftMax if __name__=='__main__' : arr=[0,0,1,2,5,5,6,8,8] n=len(arr) print("Minimum left :",0) print("Minimum right :",getRightMin(arr,n)) print("Maximum left :",getLeftMax(arr,n)) print("Maximum right :",(n-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{2}->union(Sequence{5}->union(Sequence{5}->union(Sequence{6}->union(Sequence{8}->union(Sequence{ 8 })))))))) ; n := (arr)->size() ; execute ("Minimum left :")->display() ; execute ("Minimum right :")->display() ; execute ("Maximum left :")->display() ; execute ("Maximum right :")->display() ) else skip; operation getRightMin(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var min : OclAny := arr->first() ; var rightMin : int := 0 ; var i : int := 1 ; while ((i->compareTo(n)) < 0) do ( if (arr[i+1] = min) then ( rightMin := i ) else skip ; i := i * 2) ; i := rightMin + 1 ; while ((i->compareTo(n)) < 0 & arr[i+1] = min) do ( rightMin := i ; i := i + 1) ; return rightMin; operation getLeftMax(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var max : OclAny := arr[n - 1+1] ; var leftMax : double := n - 1 ; i := n - 2 ; while (i > 0) do ( if (arr[i+1] = max) then ( leftMax := i ) else skip ; i := ("" + ((i / 2)))->toInteger()) ; i := leftMax - 1 ; while (i >= 0 & arr[i+1] = max) do ( leftMax := i ; i := i - 1) ; return leftMax; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inf=2*(10**9) res=[] In=[0]*1001 out=[0]*1001 f=[0]*1001 s=input().split() n=int(s[0]) m=int(s[1]) u,v,d=(0,)*3 for i in range(1001): In[i],out[i],f[i]=(-1,)*3 for i in range(m): s=input().split() u,v,d=int(s[0]),int(s[1]),int(s[2]) f[u],In[v],out[u]=d,u,v for i in range(1,n+1): if(In[i]==-1): u,v,w,cnt,c=i,0,inf,0,0 while(out[u]!=-1): cnt+=1 if(cnt>n-1): c=1 break v=out[u] w=min(w,f[u]) u=v if(c or(w==inf)): continue res.append([i,v,w]) print(len(res),end='\n') for i in range(len(res)): print(res[i][0],res[i][1],res[i][2],sep=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Math_PINFINITY : double := 2 * ((10)->pow(9)) ; var res : Sequence := Sequence{} ; var In : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 1001) ; var out : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 1001) ; var f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 1001) ; var s : OclAny := input().split() ; var n : int := ("" + ((s->first())))->toInteger() ; var m : int := ("" + ((s[1+1])))->toInteger() ; var u : OclAny := null; var v : OclAny := null; var d : OclAny := null; Sequence{u,v,d} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) ,)} * 3 ; for i : Integer.subrange(0, 1001-1) do ( var In[i+1] : OclAny := null; var out[i+1] : OclAny := null; var f[i+1] : OclAny := null; Sequence{In[i+1],out[i+1],f[i+1]} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom - (number (integer 1))))))) ,)} * 3) ; for i : Integer.subrange(0, m-1) do ( s := input().split() ; var u : OclAny := null; var v : OclAny := null; var d : OclAny := null; Sequence{u,v,d} := Sequence{("" + ((s->first())))->toInteger(),("" + ((s[1+1])))->toInteger(),("" + ((s[2+1])))->toInteger()} ; var f[u+1] : OclAny := null; var In[v+1] : OclAny := null; var out[u+1] : OclAny := null; Sequence{f[u+1],In[v+1],out[u+1]} := Sequence{d,u,v}) ; for i : Integer.subrange(1, n + 1-1) do ( if (In[i+1] = -1) then ( var u : OclAny := null; var v : OclAny := null; var w : OclAny := null; var cnt : OclAny := null; var c : OclAny := null; Sequence{u,v,w,cnt,c} := Sequence{i,0,Math_PINFINITY,0,0} ; while (out[u+1] /= -1) do ( cnt := cnt + 1 ; if ((cnt->compareTo(n - 1)) > 0) then ( var c : int := 1 ; break ) else skip ; var v : OclAny := out[u+1] ; var w : OclAny := Set{w, f[u+1]}->min() ; var u : OclAny := v) ; if (c or (w = Math_PINFINITY)) then ( continue ) else skip ; execute ((Sequence{i}->union(Sequence{v}->union(Sequence{ w }))) : res) ) else skip) ; execute ((res)->size())->display() ; for i : Integer.subrange(0, (res)->size()-1) do ( execute (res[i+1]->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def angleequichord(z): print("The angle subtended at","the center is",z,"degrees"); if __name__=="__main__" : z=48 ; angleequichord(z); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( z := 48; ; angleequichord(z); ) else skip; operation angleequichord(z : OclAny) pre: true post: true activity: execute ("The angle subtended at")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) t,p=[],[[0,0,0]for i in range(n+1)] for i in range(m): a,b,d=map(int,input().split()) p[b][1],p[a][0],p[a][2]=a,b,d for a in range(1,n+1): if p[a][1]==0 : b,c,d=a,p[a][0],p[a][2] if not c : continue while c : if d>p[b][2]: d=p[b][2] b,c=c,p[c][0] t.append(str(a)+' '+str(b)+' '+str(d)) print(len(t)) print('\n'.join(t)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : OclAny := null; var p : OclAny := null; Sequence{t,p} := Sequence{Sequence{},Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))))} ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; var d : OclAny := null; Sequence{a,b,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p[b+1][1+1] : OclAny := null; var p[a+1]->first() : OclAny := null; var p[a+1][2+1] : OclAny := null; Sequence{p[b+1][1+1],p[a+1]->first(),p[a+1][2+1]} := Sequence{a,b,d}) ; for a : Integer.subrange(1, n + 1-1) do ( if p[a+1][1+1] = 0 then ( var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{b,c,d} := Sequence{a,p[a+1]->first(),p[a+1][2+1]} ; if not(c) then ( continue ) else skip ; while c do ( if (d->compareTo(p[b+1][2+1])) > 0 then ( var d : OclAny := p[b+1][2+1] ) else skip ; var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := Sequence{c,p[c+1]->first()}) ; execute ((("" + ((a))) + ' ' + ("" + ((b))) + ' ' + ("" + ((d)))) : t) ) else skip) ; execute ((t)->size())->display() ; execute (StringLib.sumStringsWithSeparator((t), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys sys.setrecursionlimit(1100) n,p=map(int,input().split()) neighList=[()for _ in range(n)] in_degrees=[0]*n for _ in range(p): a,b,d=map(int,input().split()) a-=1 ; b-=1 neighList[a]=(b,d) in_degrees[b]+=1 def dfs(u,d): if len(neighList[u])==0 : return(u,d) else : return dfs(neighList[u][0],min(d,neighList[u][1])) res=[] for u in range(n): if in_degrees[u]==0 and len(neighList[u])!=0 : b,d=dfs(u,math.inf) res.append((u+1,b+1,d)) res.sort() print(len(res)) for r in res : print(*r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit(1100) ; var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var neighList : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (())) ; var in_degrees : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for _anon : Integer.subrange(0, p-1) do ( var a : OclAny := null; var b : OclAny := null; var d : OclAny := null; Sequence{a,b,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := a - 1; b := b - 1 ; neighList[a+1] := Sequence{b, d} ; in_degrees[b+1] := in_degrees[b+1] + 1) ; skip ; var res : Sequence := Sequence{} ; for u : Integer.subrange(0, n-1) do ( if in_degrees[u+1] = 0 & (neighList[u+1])->size() /= 0 then ( var b : OclAny := null; Sequence{b,d} := dfs(u, ) ; execute ((Sequence{u + 1, b + 1, d}) : res) ) else skip) ; res := res->sort() ; execute ((res)->size())->display() ; for r : res do ( execute ((argument * (test (logical_test (comparison (expr (atom (name r))))))))->display()); operation dfs(u : OclAny, d : OclAny) : OclAny pre: true post: true activity: if (neighList[u+1])->size() = 0 then ( return Sequence{u, d} ) else ( return dfs(neighList[u+1]->first(), Set{d, neighList[u+1][1+1]}->min()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,p=map(int,input().split()) g=[[-1,-1]for _ in range(n+1)] t=set(range(1,n+1)) for i in range(p): a,b,d=map(int,input().split()) g[a]=[b,d] t.remove(b) ans=[] for tt in t : c=g[tt][0] m=g[tt][1] while g[c][0]!=-1 : m=min(m,g[c][1]) c=g[c][0] if m>-1 : ans.append('%i %i %i' %(tt,c,m)) print(len(ans)) if len(ans)!=0 : print('\n'.join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var g : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Sequence{-1}->union(Sequence{ -1 }))) ; var t : Set := Set{}->union((Integer.subrange(1, n + 1-1))) ; for i : Integer.subrange(0, p-1) do ( var a : OclAny := null; var b : OclAny := null; var d : OclAny := null; Sequence{a,b,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; g[a+1] := Sequence{b}->union(Sequence{ d }) ; execute ((b) /: t)) ; var ans : Sequence := Sequence{} ; for tt : t do ( var c : OclAny := g[tt+1]->first() ; var m : OclAny := g[tt+1][1+1] ; while g[c+1]->first() /= -1 do ( m := Set{m, g[c+1][1+1]}->min() ; c := g[c+1]->first()) ; if m > -1 then ( execute ((StringLib.format('%i %i %i',Sequence{tt, c, m})) : ans) ) else skip) ; execute ((ans)->size())->display() ; if (ans)->size() /= 0 then ( execute (StringLib.sumStringsWithSeparator((ans), ' '))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=(int(input())) b=(int(input())) c=(int(input())) d=(int(input())) e=(int(input())) f=(int(input())) cnt=0 l=min(a,d) d1=d-l m=min(b,c,d1) g=(l*e)+(m*f) o=min(b,c,d) d2=d-o h=min(a,d2) s=(o*f)+(h*e) print(max(g,s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var b : int := (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var c : int := (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var d : int := (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var e : int := (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var f : int := (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var cnt : int := 0 ; var l : OclAny := Set{a, d}->min() ; var d1 : double := d - l ; var m : OclAny := Set{b, c, d1}->min() ; var g : double := (l * e) + (m * f) ; var o : OclAny := Set{b, c, d}->min() ; var d2 : double := d - o ; var h : OclAny := Set{a, d2}->min() ; var s : double := (o * f) + (h * e) ; execute (Set{g, s}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) t,p=[],[[0,0,0]for i in range(n+1)] for i in range(m): a,b,d=map(int,input().split()) p[b][1],p[a][0],p[a][2]=a,b,d for a in range(1,n+1): if p[a][1]==0 : b,c,d=a,p[a][0],p[a][2] if not c : continue while c : if d>p[b][2]: d=p[b][2] b,c=c,p[c][0] t.append(str(a)+' '+str(b)+' '+str(d)) print(len(t)) print('\n'.join(t)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : OclAny := null; var p : OclAny := null; Sequence{t,p} := Sequence{Sequence{},Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))))} ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; var d : OclAny := null; Sequence{a,b,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p[b+1][1+1] : OclAny := null; var p[a+1]->first() : OclAny := null; var p[a+1][2+1] : OclAny := null; Sequence{p[b+1][1+1],p[a+1]->first(),p[a+1][2+1]} := Sequence{a,b,d}) ; for a : Integer.subrange(1, n + 1-1) do ( if p[a+1][1+1] = 0 then ( var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{b,c,d} := Sequence{a,p[a+1]->first(),p[a+1][2+1]} ; if not(c) then ( continue ) else skip ; while c do ( if (d->compareTo(p[b+1][2+1])) > 0 then ( var d : OclAny := p[b+1][2+1] ) else skip ; var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := Sequence{c,p[c+1]->first()}) ; execute ((("" + ((a))) + ' ' + ("" + ((b))) + ' ' + ("" + ((d)))) : t) ) else skip) ; execute ((t)->size())->display() ; execute (StringLib.sumStringsWithSeparator((t), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isCommonBase(base,s1,s2): for j in range(len(s1)): if(base[j % len(base)]!=s1[j]): return False for j in range(len(s2)): if(base[j % len(base)]!=s2[j]): return False return True def countCommonBases(s1,s2): n1=len(s1) n2=len(s2) count=0 for i in range(1,min(n1,n2)+1): base=s1[0 : i] if(isCommonBase(base,s1,s2)): count+=1 return count if __name__=="__main__" : s1="pqrspqrs" s2="pqrspqrspqrspqrs" print(countCommonBases(s1,s2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( s1 := "pqrspqrs" ; s2 := "pqrspqrspqrspqrs" ; execute (countCommonBases(s1, s2))->display() ) else skip; operation isCommonBase(base : OclAny, s1 : OclAny, s2 : OclAny) : OclAny pre: true post: true activity: for j : Integer.subrange(0, (s1)->size()-1) do ( if (base[j mod (base)->size()+1] /= s1[j+1]) then ( return false ) else skip) ; for j : Integer.subrange(0, (s2)->size()-1) do ( if (base[j mod (base)->size()+1] /= s2[j+1]) then ( return false ) else skip) ; return true; operation countCommonBases(s1 : OclAny, s2 : OclAny) : OclAny pre: true post: true activity: var n1 : int := (s1)->size() ; var n2 : int := (s2)->size() ; var count : int := 0 ; for i : Integer.subrange(1, Set{n1, n2}->min() + 1-1) do ( base := s1.subrange(0+1, i) ; if (isCommonBase(base, s1, s2)) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSetBits(n): dp=[0]*(n+1); print(dp[0],end=" "); for i in range(1,n+1): if(i % 2==0): dp[i]=dp[i//2]; else : dp[i]=dp[i//2]+1 ; print(dp[i],end=" "); if __name__=="__main__" : n=5 ; findSetBits(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 5; ; findSetBits(n); ) else skip; operation findSetBits(n : OclAny) pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); ; execute (dp->first())->display(); ; for i : Integer.subrange(1, n + 1-1) do ( if (i mod 2 = 0) then ( dp[i+1] := dp[i div 2+1]; ) else ( dp[i+1] := dp[i div 2+1] + 1; ) ; execute (dp[i+1])->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isMagic(n): sum=0 ; while(n>0 or sum>9): if(n==0): n=sum ; sum=0 ; sum=sum+n % 10 ; n=int(n/10); return True if(sum==1)else False ; n=1234 ; if(isMagic(n)): print("Magic Number"); else : print("Not a magic Number"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 1234; ; if (isMagic(n)) then ( execute ("Magic Number")->display(); ) else ( execute ("Not a magic Number")->display(); ); operation isMagic(n : OclAny) pre: true post: true activity: var sum : int := 0; ; while (n > 0 or sum > 9) do ( if (n = 0) then ( n := sum; ; sum := 0; ) else skip ; sum := sum + n mod 10; ; n := ("" + ((n / 10)))->toInteger();) ; return if (sum = 1) then true else false endif;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- NumUnsignBits=64 ; def findNum(x): for i in range(NumUnsignBits-1): if(((x>>i)& 1)!=((x>>(i+1))& 1)): x ^=(1<display(); ) else skip; operation findNum(x : OclAny) pre: true post: true activity: for i : Integer.subrange(0, NumUnsignBits - 1-1) do ( if ((MathLib.bitwiseAnd((x /(2->pow(i))), 1)) /= (MathLib.bitwiseAnd((x /(2->pow((i + 1)))), 1))) then ( x := x xor MathLib.bitwiseOr((1 * (2->pow(i))), (1 * (2->pow((i + 1))))); ; return x; ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() if len(s)>=6 and any([(c in s)for c in "1234567890"])and any([(c in s)for c in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"])and any([(c in s)for c in "abcdefghijklmnopqrstuvwxyz"]): print("VALID") else : print("INVALID") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; if (s)->size() >= 6 & ("1234567890"->characters()->select(c | true)->collect(c | (((s)->characters()->includes(c)))))->exists( _x | _x = true ) & ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"->characters()->select(c | true)->collect(c | (((s)->characters()->includes(c)))))->exists( _x | _x = true ) & ("abcdefghijklmnopqrstuvwxyz"->characters()->select(c | true)->collect(c | (((s)->characters()->includes(c)))))->exists( _x | _x = true ) then ( execute ("VALID")->display() ) else ( execute ("INVALID")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() A=[str(i)for i in range(10)] B=[chr(i)for i in range(97,97+26)] C=[chr(i)for i in range(65,65+26)] ng="INVALID" ok="VALID" if len(s)<6 : print(ng) exit() x=0 y=0 z=0 for i in s : a=i in A b=i in B c=i in C x+=a y+=b z+=c if a or b or c : pass else : print(ng) exit() if x and y and z : print(ok) else : print(ng) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var A : Sequence := Integer.subrange(0, 10-1)->select(i | true)->collect(i | (("" + ((i))))) ; var B : Sequence := Integer.subrange(97, 97 + 26-1)->select(i | true)->collect(i | ((i)->byte2char())) ; var C : Sequence := Integer.subrange(65, 65 + 26-1)->select(i | true)->collect(i | ((i)->byte2char())) ; var ng : String := "INVALID" ; var ok : String := "VALID" ; if (s)->size() < 6 then ( execute (ng)->display() ; exit() ) else skip ; var x : int := 0 ; var y : int := 0 ; var z : int := 0 ; for i : s->characters() do ( var a : boolean := (A)->includes(i) ; var b : boolean := (B)->includes(i) ; var c : boolean := (C)->includes(i) ; x := x + a ; y := y + b ; z := z + c ; if a or b or c then ( skip ) else ( execute (ng)->display() ; exit() )) ; if x & y & z then ( execute (ok)->display() ) else ( execute (ng)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pattern(n,d): for i in range(0,n-2): print("1",end=" ") print("2",end=" ") print(n+d) N=3 D=5 pattern(N,D) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 3 ; var D : int := 5 ; pattern(N, D); operation pattern(n : OclAny, d : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n - 2-1) do ( execute ("1")->display()) ; execute ("2")->display() ; execute (n + d)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() print('INVALID' if s.isalpha()or s.isdigit()or s.islower()or s.isupper()or len(s)<6 else 'VALID') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; execute (if s->matches("[a-zA-Z]*") or s->matches("[0-9]*") or s->matches("[a-z ]*") or s->matches("[A-Z ]*") or (s)->size() < 6 then 'INVALID' else 'VALID' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re lst=input() if len(lst)>=6 : if re.findall("[0-9]",lst): if re.findall("[A-Z]",lst): if re.findall("[a-z]",lst): print("VALID") else : print("INVALID") else : print("INVALID") else : print("INVALID") else : print("INVALID") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var lst : String := (OclFile["System.in"]).readLine() ; if (lst)->size() >= 6 then ( if (lst)->allMatches("[0-9]") then ( if (lst)->allMatches("[A-Z]") then ( if (lst)->allMatches("[a-z]") then ( execute ("VALID")->display() ) else ( execute ("INVALID")->display() ) ) else ( execute ("INVALID")->display() ) ) else ( execute ("INVALID")->display() ) ) else ( execute ("INVALID")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input('')) b=int(input('')) c=int(input('')) d=int(input('')) e=int(input('')) f=int(input('')) aa,bb,cc,dd=a,b,c,d z=min(a,d) first=e*z a-=z d-=z y=min(b,c,d) second=f*y y=min(bb,cc,dd) second2=f*y bb-=y dd-=y z=min(aa,dd) first2=e*z aa-=z dd-=z print(max([first+second,first2+second2])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; var c : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; var d : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; var e : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; var f : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; var aa : OclAny := null; var bb : OclAny := null; var cc : OclAny := null; var dd : OclAny := null; Sequence{aa,bb,cc,dd} := Sequence{a,b,c,d} ; var z : OclAny := Set{a, d}->min() ; var first : double := e * z ; a := a - z ; d := d - z ; var y : OclAny := Set{b, c, d}->min() ; var second : double := f * y ; y := Set{bb, cc, dd}->min() ; var second2 : double := f * y ; bb := bb - y ; dd := dd - y ; z := Set{aa, dd}->min() ; var first2 : double := e * z ; aa := aa - z ; dd := dd - z ; execute ((Sequence{first + second}->union(Sequence{ first2 + second2 }))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=str(input()) if len(s)<6 : print("INVALID") else : num=0 ABC=0 abc=0 for i in range(len(s)): if ord(s[i])>=48 and ord(s[i])<=57 : num+=1 if ord(s[i])>=97 and ord(s[i])<=122 : ABC+=1 if ord(s[i])>=65 and ord(s[i])<=90 : abc+=1 if num==0 or ABC==0 or abc==0 : print("INVALID") else : print("VALID") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; if (s)->size() < 6 then ( execute ("INVALID")->display() ) else ( var num : int := 0 ; var ABC : int := 0 ; var abc : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if (s[i+1])->char2byte() >= 48 & (s[i+1])->char2byte() <= 57 then ( num := num + 1 ) else skip ; if (s[i+1])->char2byte() >= 97 & (s[i+1])->char2byte() <= 122 then ( ABC := ABC + 1 ) else skip ; if (s[i+1])->char2byte() >= 65 & (s[i+1])->char2byte() <= 90 then ( abc := abc + 1 ) else skip) ; if num = 0 or ABC = 0 or abc = 0 then ( execute ("INVALID")->display() ) else ( execute ("VALID")->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H=int(input())+1 A=[0]+list(map(int,input().split())) def h(i): l=2*i ; r,g=l+1,[i,l][ltoInteger() + 1 ; var A : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; skip ; for i : Integer.subrange(0 + 1, H div 2)->reverse() do ( h(i)) ; execute (' ' + StringLib.sumStringsWithSeparator(((A->tail())->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); operation h(i : OclAny) pre: true post: true activity: var l : double := 2 * i; var r : OclAny := null; var g : OclAny := null; Sequence{r,g} := Sequence{l + 1,Sequence{i}->union(Sequence{ l })->select((l->compareTo(H)) < 0 & (A[i+1]->compareTo(A[l+1])) < 0)} ; if (r->compareTo(H)) < 0 & (A[g+1]->compareTo(A[r+1])) < 0 then ( var g : OclAny := r ) else skip ; if g /= i then ( var A[i+1] : OclAny := null; var A[g+1] : OclAny := null; Sequence{A[i+1],A[g+1]} := Sequence{A[g+1],A[i+1]}; h(g) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxHeapify(A,i): l=2*i r=2*i+1 if lA[i]: largest=l else : largest=i if rA[largest]: largest=r if not largest==i : A[i],A[largest]=A[largest],A[i] maxHeapify(A,largest) def buildMaxHeap(A,H): for i in range(H//2,0,-1): maxHeapify(A,i) H=int(input()) A=[int(i)for i in input().split()] A=[0]+A buildMaxHeap(A,H) tmp="" for i in A[1 :]: tmp+=" "+str(i) print(tmp) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; H := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; A := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; A := Sequence{ 0 }->union(A) ; buildMaxHeap(A, H) ; var tmp : String := "" ; for i : A->tail() do ( tmp := tmp + " " + ("" + ((i)))) ; execute (tmp)->display(); operation maxHeapify(A : OclAny, i : OclAny) pre: true post: true activity: var l : double := 2 * i ; var r : double := 2 * i + 1 ; if (l->compareTo((A)->size())) < 0 & (A[l+1]->compareTo(A[i+1])) > 0 then ( var largest : OclAny := l ) else ( largest := i ) ; if (r->compareTo((A)->size())) < 0 & (A[r+1]->compareTo(A[largest+1])) > 0 then ( largest := r ) else skip ; if not(largest = i) then ( var A[i+1] : OclAny := null; var A[largest+1] : OclAny := null; Sequence{A[i+1],A[largest+1]} := Sequence{A[largest+1],A[i+1]} ; maxHeapify(A, largest) ) else skip; operation buildMaxHeap(A : OclAny, H : OclAny) pre: true post: true activity: for i : Integer.subrange(0 + 1, H div 2)->reverse() do ( maxHeapify(A, i)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def swap(A,i,j): tmp=A[i] A[i]=A[j] A[j]=tmp def heap_size(A): return len(A)-1 def parent_node(k): return k//2 def left_node(k): return 2*k def right_node(k): return 2*k+1 def max_heapify(A,i): l=left_node(i) r=right_node(i) if l<=heap_size(A)and A[l]>A[i]: largest=l else : largest=i if r<=heap_size(A)and A[r]>A[largest]: largest=r if largest!=i : swap(A,i,largest) max_heapify(A,largest) def build_max_heap(A): for i in reversed(range(1,heap_size(A)//2+1)): max_heapify(A,i) def print_heap(A): for i in range(1,heap_size(A)+1): print("{}".format(A[i]),end="") print() def main(): _=int(input()) A=[None]+[int(x)for x in input().split()] build_max_heap(A) print_heap(A) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; main(); operation swap(A : OclAny, i : OclAny, j : OclAny) pre: true post: true activity: var tmp : OclAny := A[i+1] ; A[i+1] := A[j+1] ; A[j+1] := tmp; operation heap_size(A : OclAny) : OclAny pre: true post: true activity: return (A)->size() - 1; operation parent_node(k : OclAny) : OclAny pre: true post: true activity: return k div 2; operation left_node(k : OclAny) : OclAny pre: true post: true activity: return 2 * k; operation right_node(k : OclAny) : OclAny pre: true post: true activity: return 2 * k + 1; operation max_heapify(A : OclAny, i : OclAny) pre: true post: true activity: var l : OclAny := left_node(i) ; var r : OclAny := right_node(i) ; if (l->compareTo(heap_size(A))) <= 0 & (A[l+1]->compareTo(A[i+1])) > 0 then ( var largest : OclAny := l ) else ( largest := i ) ; if (r->compareTo(heap_size(A))) <= 0 & (A[r+1]->compareTo(A[largest+1])) > 0 then ( largest := r ) else skip ; if largest /= i then ( swap(A, i, largest) ; max_heapify(A, largest) ) else skip; operation build_max_heap(A : OclAny) pre: true post: true activity: for i : (Integer.subrange(1, heap_size(A) div 2 + 1-1))->reverse() do ( max_heapify(A, i)); operation print_heap(A : OclAny) pre: true post: true activity: for i : Integer.subrange(1, heap_size(A) + 1-1) do ( execute (StringLib.interpolateStrings("{}", Sequence{A[i+1]}))->display()) ; execute (->display(); operation main() pre: true post: true activity: var _anon : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; A := Sequence{ null }->union(input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) ; build_max_heap(A) ; print_heap(A); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def max_heapify(heap,i): l=2*i r=2*i+1 largest=i if(ltoInteger() ; heap := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; heap := heap.insertAt(0+1, -1) ; for i : Integer.subrange(0, n div 2 + 1-1) do ( max_heapify(heap, n div 2 + 1 - i)) ; for i : Integer.subrange(1, n + 1-1) do ( execute (StringLib.formattedString("{heap[i]}"))->display()) ; execute (->display(); operation max_heapify(heap : OclAny, i : OclAny) pre: true post: true activity: var l : double := 2 * i ; var r : double := 2 * i + 1 ; var largest : OclAny := i ; if ((l->compareTo((heap)->size())) < 0 & (heap[i+1]->compareTo(heap[l+1])) < 0) then ( largest := l ) else skip ; if ((r->compareTo((heap)->size())) < 0 & (heap[largest+1]->compareTo(heap[r+1])) < 0) then ( largest := r ) else skip ; if (i /= largest) then ( var heap[i+1] : OclAny := null; var heap[largest+1] : OclAny := null; Sequence{heap[i+1],heap[largest+1]} := Sequence{heap[largest+1],heap[i+1]} ; max_heapify(heap, largest) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- KEY_MIN=-2000000001 H=int(input()) A=[KEY_MIN]*(H+1) for cnt,key in enumerate(map(int,input().split())): A[cnt+1]=key index_min=1 index_max=len(A)-1 def index_exsist(i): if index_min<=i<=index_max : return i else : return 0 def max_heapify(A,i): l=index_exsist(2*i) r=index_exsist(2*i+1) largest=i if A[l]>A[largest]: largest=l if A[r]>A[largest]: largest=r if largest!=i : A[i],A[largest]=A[largest],A[i] max_heapify(A,largest) def build_maxheap(A): for i in range(1,(H//2)+1)[: :-1]: max_heapify(A,i) build_maxheap(A) print("",*A[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var KEY_MIN : int := -2000000001 ; var H : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := MatrixLib.elementwiseMult(Sequence{ KEY_MIN }, (H + 1)) ; for _tuple : Integer.subrange(1, ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->size())->collect( _indx | Sequence{_indx-1, ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->at(_indx)} ) do (var _indx : int := 1; var cnt : OclAny := _tuple->at(_indx); _indx := _indx + 1; var key : OclAny := _tuple->at(_indx); A[cnt + 1+1] := key) ; var index_min : int := 1 ; var index_max : double := (A)->size() - 1 ; skip ; skip ; skip ; build_maxheap(A) ; execute ("")->display(); operation index_exsist(i : OclAny) : OclAny pre: true post: true activity: if (index_min->compareTo(i)) <= 0 & (i <= index_max) then ( return i ) else ( return 0 ); operation max_heapify(A : OclAny, i : OclAny) pre: true post: true activity: var l : OclAny := index_exsist(2 * i) ; var r : OclAny := index_exsist(2 * i + 1) ; var largest : OclAny := i ; if (A[l+1]->compareTo(A[largest+1])) > 0 then ( largest := l ) else skip ; if (A[r+1]->compareTo(A[largest+1])) > 0 then ( largest := r ) else skip ; if largest /= i then ( var A[i+1] : OclAny := null; var A[largest+1] : OclAny := null; Sequence{A[i+1],A[largest+1]} := Sequence{A[largest+1],A[i+1]} ; max_heapify(A, largest) ) else skip; operation build_maxheap(A : OclAny) pre: true post: true activity: for i : range(1, (H div 2) + 1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( max_heapify(A, i)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=2147483647 N=4 def minCost(cost): dist=[0 for i in range(N)] for i in range(N): dist[i]=INF dist[0]=0 for i in range(N): for j in range(i+1,N): if(dist[j]>dist[i]+cost[i][j]): dist[j]=dist[i]+cost[i][j] return dist[N-1] cost=[[0,15,80,90],[INF,0,40,50],[INF,INF,0,70],[INF,INF,INF,0]] print("The Minimum cost to reach station ",N," is ",minCost(cost)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INF : int := 2147483647 ; var N : int := 4 ; skip ; cost := Sequence{Sequence{0}->union(Sequence{15}->union(Sequence{80}->union(Sequence{ 90 })))}->union(Sequence{Sequence{INF}->union(Sequence{0}->union(Sequence{40}->union(Sequence{ 50 })))}->union(Sequence{Sequence{INF}->union(Sequence{INF}->union(Sequence{0}->union(Sequence{ 70 })))}->union(Sequence{ Sequence{INF}->union(Sequence{INF}->union(Sequence{INF}->union(Sequence{ 0 }))) }))) ; execute ("The Minimum cost to reach station ")->display(); operation minCost(cost : OclAny) : OclAny pre: true post: true activity: var dist : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, N-1) do ( dist[i+1] := INF) ; dist->first() := 0 ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(i + 1, N-1) do ( if ((dist[j+1]->compareTo(dist[i+1] + cost[i+1][j+1])) > 0) then ( dist[j+1] := dist[i+1] + cost[i+1][j+1] ) else skip)) ; return dist[N - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : n=int(input()) num=n % 39 if num==0 : num=39 if num<10 : num="0"+str(num) print("3"+"C"+str(num)) except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var num : int := n mod 39 ; if num = 0 then ( num := 39 ) else skip ; if num < 10 then ( num := "0" + ("" + ((num))) ) else skip ; execute ("3" + "C" + ("" + ((num))))->display()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count(n): if n==0 : return 1 if n==1 : return 1 else : return(n*count(n-1))+((n-1)*count(n-2)) A=[1,2,3,9] print(count(len(A)-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var A : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 9 }))) ; execute (count((A)->size() - 1))->display(); operation count(n : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( return 1 ) else skip ; if n = 1 then ( return 1 ) else ( return (n * count(n - 1)) + ((n - 1) * count(n - 2)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : try : n=int(input()) except : break print("3C{:02d}".format(n % 39 if n % 39 else 39)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( try ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) catch (_e : OclException) do ( break) ; execute (StringLib.interpolateStrings("3C{:02d}", Sequence{if n mod 39 then n mod 39 else 39 endif}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) c=int(input()) d=int(input()) e=int(input()) f=int(input()) s=0 if e>f : s+=min(a,d)*e d-=min(a,d) s+=min(b,c,d)*f else : s+=min(b,c,d)*f d-=min(b,c,d) s+=min(a,d)*e print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var e : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var f : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : int := 0 ; if (e->compareTo(f)) > 0 then ( s := s + Set{a, d}->min() * e ; d := d - Set{a, d}->min() ; s := s + Set{b, c, d}->min() * f ) else ( s := s + Set{b, c, d}->min() * f ; d := d - Set{b, c, d}->min() ; s := s + Set{a, d}->min() * e ) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def main(args): for line in sys.stdin : candy=int(line) hit=candy % 39 if hit==0 : hit=39 print('3C{:02d}'.format(hit)) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation main(args : OclAny) pre: true post: true activity: for line : OclFile["System.in"] do ( var candy : int := ("" + ((line)))->toInteger() ; var hit : int := candy mod 39 ; if hit = 0 then ( hit := 39 ) else skip ; execute (StringLib.interpolateStrings('3C{:02d}', Sequence{hit}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_input(): while True : try : yield ''.join(input()) except EOFError : break N=list(get_input()) for l in range(len(N)): n=int(N[l]) print("3C",end="") ans=n % 39 if ans==0 : print(39) elif ans<10 : print("0",end="") print(ans) else : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : Sequence := (OclIterator.newOclIterator_Function(lambda _i : int in self.get_input(_i))) ; for l : Integer.subrange(0, (N)->size()-1) do ( var n : int := ("" + ((N[l+1])))->toInteger() ; execute ("3C")->display() ; var ans : int := n mod 39 ; if ans = 0 then ( execute (39)->display() ) else (if ans < 10 then ( execute ("0")->display() ; execute (ans)->display() ) else ( execute (ans)->display() ) ) ); operation get_input(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; while true do ( try ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return StringLib.sumStringsWithSeparator(((OclFile["System.in"]).readLine()), '')) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : print("3C",str((int(input())-1)% 39+1).zfill(2),sep="") except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( execute ("3C")->display()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import atexit import io import sys _OUTPUT_BUFFER=io.StringIO() sys.stdout=_OUTPUT_BUFFER @ atexit.register def write(): sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) def main(): (n,m,k)=map(int,input().split(' ')) lft=[(0,0)for _ in range(n)] top=[(0,0)for _ in range(m)] for i in range(k): tp,rc,a=map(int,input().split(' ')) if tp==1 : lft[rc-1]=(i+1,a) else : top[rc-1]=(i+1,a) for i in range(n): for j in range(m): color=lft[i][1] if top[j][0]>lft[i][0]: color=top[j][1] print(str(color),end=' ') print() if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var _OUTPUT_BUFFER : OclAny := io.StringIO() ; OclFile["System.out"] := _OUTPUT_BUFFER ; (compound_stmt (decorator @ (dotted_name (dotted_name (name atexit)) . (name register))) (funcdef def (name write) ( ) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name __stdout__)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name _OUTPUT_BUFFER)) (trailer . (name getvalue) (arguments ( ))))))))) ))))))))))))))) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: ; var Sequence{n, m, k} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var lft : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{0, 0})) ; var top : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (Sequence{0, 0})) ; for i : Integer.subrange(0, k-1) do ( var tp : OclAny := null; var rc : OclAny := null; var a : OclAny := null; Sequence{tp,rc,a} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; if tp = 1 then ( lft[rc - 1+1] := Sequence{i + 1, a} ) else ( top[rc - 1+1] := Sequence{i + 1, a} )) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( var color : OclAny := lft[i+1][1+1] ; if (top[j+1]->first()->compareTo(lft[i+1]->first())) > 0 then ( color := top[j+1][1+1] ) else skip ; execute (("" + ((color))))->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,m,k=map(int,input().split()) d=[[0]*m for _ in range(n)] a1=[(0,-1)for _ in range(n)] a2=[(0,-1)for _ in range(m)] for i in range(k): a,b,c=map(int,input().split()) if a==1 : a1[b-1]=(c,i) else : a2[b-1]=(c,i) for i in range(n): for j in range(m): d[i][j]=a1[i][0]if a1[i][1]>a2[j][1]else a2[j][0] for i in d : print(' '.join(map(str,i))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, m))) ; var a1 : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{0, -1})) ; var a2 : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (Sequence{0, -1})) ; for i : Integer.subrange(0, k-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 1 then ( a1[b - 1+1] := Sequence{c, i} ) else ( a2[b - 1+1] := Sequence{c, i} )) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( d[i+1][j+1] := if (a1[i+1][1+1]->compareTo(a2[j+1][1+1])) > 0 then a1[i+1]->first() else a2[j+1]->first() endif)) ; for i : d do ( execute (StringLib.sumStringsWithSeparator(((i)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict n,m,k=map(int,input().split()) ans=[[0 for _ in range(m)]for _ in range(n)] rows=defaultdict() cols=defaultdict() for i in range(k): a,b,c=map(int,input().split()) if a==1 : rows[b-1]=(c,i) if a==2 : cols[b-1]=(c,i) for i in range(n): for j in range(m): if rows.get(i)is None and cols.get(j)is None : print(0,end=" ") elif rows.get(i)is None : print(cols[j][0],end=" ") elif cols.get(j)is None : print(rows[i][0],end=" ") else : rc,rt=rows[i] cc,ct=cols[j] if rt>ct : print(rows[i][0],end=" ") else : print(cols[j][0],end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (0)))) ; var rows : OclAny := defaultdict() ; var cols : OclAny := defaultdict() ; for i : Integer.subrange(0, k-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 1 then ( rows[b - 1+1] := Sequence{c, i} ) else skip ; if a = 2 then ( cols[b - 1+1] := Sequence{c, i} ) else skip) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if rows.get(i) <>= null & cols.get(j) <>= null then ( execute (0)->display() ) else (if rows.get(i) <>= null then ( execute (cols[j+1]->first())->display() ) else (if cols.get(j) <>= null then ( execute (rows[i+1]->first())->display() ) else ( var rc : OclAny := null; var rt : OclAny := null; Sequence{rc,rt} := rows[i+1] ; var cc : OclAny := null; var ct : OclAny := null; Sequence{cc,ct} := cols[j+1] ; if (rt->compareTo(ct)) > 0 then ( execute (rows[i+1]->first())->display() ) else ( execute (cols[j+1]->first())->display() ) ) ) ) ) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict n,m,k=map(int,input().split()) ans=[[0 for _ in range(m)]for _ in range(n)] rows=defaultdict(lambda :(0,-1)) cols=defaultdict(lambda :(0,-1)) for i in range(k): a,b,c=map(int,input().split()) if a==1 : rows[b-1]=(c,i) if a==2 : cols[b-1]=(c,i) for i in range(n): for j in range(m): rc,rt=rows[i] cc,ct=cols[j] if rt>ct : print(rc,end=" ") else : print(cc,end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (0)))) ; var rows : OclAny := defaultdict(lambda $$ : OclAny in (Sequence{0, -1})) ; var cols : OclAny := defaultdict(lambda $$ : OclAny in (Sequence{0, -1})) ; for i : Integer.subrange(0, k-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 1 then ( rows[b - 1+1] := Sequence{c, i} ) else skip ; if a = 2 then ( cols[b - 1+1] := Sequence{c, i} ) else skip) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( var rc : OclAny := null; var rt : OclAny := null; Sequence{rc,rt} := rows[i+1] ; var cc : OclAny := null; var ct : OclAny := null; Sequence{cc,ct} := cols[j+1] ; if (rt->compareTo(ct)) > 0 then ( execute (rc)->display() ) else ( execute (cc)->display() )) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) a=list(map(int,input().split())) ans=0 for _ in range(n): for i in map(int,input().split()): for j in range(k): if a[j]==i : ans+=j c=j-1 while c>=0 : a[c],a[c+1]=a[c+1],a[c] c-=1 break print(ans+n*m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( for i : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( for j : Integer.subrange(0, k-1) do ( if a[j+1] = i then ( ans := ans + j ; var c : double := j - 1 ; while c >= 0 do ( var a[c+1] : OclAny := null; var a[c + 1+1] : OclAny := null; Sequence{a[c+1],a[c + 1+1]} := Sequence{a[c + 1+1],a[c+1]} ; c := c - 1) ; break ) else skip))) ; execute (ans + n * m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from bisect import bisect_right as rb from collections import deque from queue import PriorityQueue from math import* input_=lambda : sys.stdin.readline().strip("\n") ii=lambda : int(input_()) il=lambda : list(map(int,input_().split())) ilf=lambda : list(map(float,input_().split())) ip=lambda : input_() fi=lambda : float(input_()) ap=lambda ab,bc,cd : ab[bc].append(cd) li=lambda : list(input_()) pr=lambda x : print(x) prinT=lambda x : print(x) f=lambda : sys.stdout.flush() mod=10**9+7 n,m,k=il() p=il() ans=0 for i in range(n): x=il() for j in x : ind=p.index(j) ans+=ind+1 p.pop(ind) p.insert(0,j) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var input_ : Function := lambda $$ : OclAny in (sys.stdin.readLine()->trim()) ; var ii : Function := lambda $$ : OclAny in (("" + ((input_->apply())))->toInteger()) ; var il : Function := lambda $$ : OclAny in (((input_->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ilf : Function := lambda $$ : OclAny in (((input_->apply().split())->collect( _x | (OclType["double"])->apply(_x) ))) ; var ip : Function := lambda $$ : OclAny in (input_->apply()) ; var fi : Function := lambda $$ : OclAny in (("" + ((input_->apply())))->toReal()) ; var ap : Function := lambda ab : OclAny, bc : OclAny, cd : OclAny in (ab[bc+1].append(cd)) ; var li : Function := lambda $$ : OclAny in ((input_->apply())) ; var pr : Function := lambda x : OclAny in ((x)->display()) ; var prinT : Function := lambda x : OclAny in ((x)->display()) ; var f : Function := lambda $$ : OclAny in ((OclFile["System.out"]).flush()) ; var mod : double := (10)->pow(9) + 7 ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := il->apply() ; var p : OclAny := il->apply() ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := il->apply() ; for j : x do ( var ind : int := p->indexOf(j) - 1 ; ans := ans + ind + 1 ; p := p->excludingAt(ind+1) ; p := p.insertAt(0+1, j))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def findLengthOfLCIS(self,nums): if not nums or len(nums)==0 : return 0 ans=curr=1 for i in range(len(nums)-1): if nums[i]exists( _x | result = _x ); operation findLengthOfLCIS(nums : OclAny) : OclAny pre: true post: true activity: if not(nums) or (nums)->size() = 0 then ( return 0 ) else skip ; var ans : OclAny := 1; var curr : int := 1 ; for i : Integer.subrange(0, (nums)->size() - 1-1) do ( if (nums[i+1]->compareTo(nums[i + 1+1])) < 0 then ( curr := curr + 1 ; ans := Set{ans, curr}->max() ) else ( curr := 1 )) ; return ans; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d,e,f=int(input()),int(input()),int(input()),int(input()),int(input()),int(input()) m1=min(a,d) m2=min(b,c,d) if(e>f): print(m1*e+min(b,c,d-m1)*f) else : print(min(a,d-m2)*e+m2*f) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; var f : OclAny := null; Sequence{a,b,c,d,e,f} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),("" + (((OclFile["System.in"]).readLine())))->toInteger(),("" + (((OclFile["System.in"]).readLine())))->toInteger(),("" + (((OclFile["System.in"]).readLine())))->toInteger(),("" + (((OclFile["System.in"]).readLine())))->toInteger(),("" + (((OclFile["System.in"]).readLine())))->toInteger()} ; var m1 : OclAny := Set{a, d}->min() ; var m2 : OclAny := Set{b, c, d}->min() ; if ((e->compareTo(f)) > 0) then ( execute (m1 * e + Set{b, c, d - m1}->min() * f)->display() ) else ( execute (Set{a, d - m2}->min() * e + m2 * f)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import bisect from bisect import bisect_left as lb input_=lambda : sys.stdin.readline().strip("\n") from math import log from math import gcd from math import atan2,acos from random import randint sa=lambda : input_() sb=lambda : int(input_()) sc=lambda : input_().split() sd=lambda : list(map(int,input_().split())) se=lambda : float(input_()) sf=lambda : list(input_()) flsh=lambda : sys.stdout.flush() mod=10**9+7 gp=[] cost=[] dp=[] mx=[] ans1=[] ans2=[] special=[] specnode=[] a=0 kthpar=[] def dfs(root,par): if par!=-1 : dp[root]=dp[par]+1 for i in range(1,20): if kthpar[root][i-1]!=-1 : kthpar[root][i]=kthpar[kthpar[root][i-1]][i-1] for child in gp[root]: if child==par : continue kthpar[child][0]=root dfs(child,root) def hnbhai(): n,m,k=sd() pos=sd() tot=0 for i in range(n): temp=sd() for j in temp : tot+=pos.index(j)+1 pos.pop(pos.index(j)) pos.insert(0,j) print(tot) for _ in range(1): hnbhai() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input_ : Function := lambda $$ : OclAny in (sys.stdin.readLine()->trim()) ; skip ; skip ; skip ; skip ; var sa : Function := lambda $$ : OclAny in (input_->apply()) ; var sb : Function := lambda $$ : OclAny in (("" + ((input_->apply())))->toInteger()) ; var sc : Function := lambda $$ : OclAny in (input_->apply().split()) ; var sd : Function := lambda $$ : OclAny in (((input_->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var se : Function := lambda $$ : OclAny in (("" + ((input_->apply())))->toReal()) ; var sf : Function := lambda $$ : OclAny in ((input_->apply())) ; var flsh : Function := lambda $$ : OclAny in ((OclFile["System.out"]).flush()) ; var mod : double := (10)->pow(9) + 7 ; var gp : Sequence := Sequence{} ; var cost : Sequence := Sequence{} ; var dp : Sequence := Sequence{} ; var mx : Sequence := Sequence{} ; var ans1 : Sequence := Sequence{} ; var ans2 : Sequence := Sequence{} ; var special : Sequence := Sequence{} ; var specnode : Sequence := Sequence{} ; var a : int := 0 ; var kthpar : Sequence := Sequence{} ; skip ; skip ; for _anon : Integer.subrange(0, 1-1) do ( hnbhai()); operation dfs(root : OclAny, par : OclAny) pre: true post: true activity: if par /= -1 then ( dp[root+1] := dp[par+1] + 1 ) else skip ; for i : Integer.subrange(1, 20-1) do ( if kthpar[root+1][i - 1+1] /= -1 then ( kthpar[root+1][i+1] := kthpar[kthpar[root+1][i - 1+1]+1][i - 1+1] ) else skip) ; for child : gp[root+1] do ( if child = par then ( continue ) else skip ; kthpar[child+1]->first() := root ; dfs(child, root)); operation hnbhai() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := sd->apply() ; var pos : OclAny := sd->apply() ; var tot : int := 0 ; for i : Integer.subrange(0, n-1) do ( var temp : OclAny := sd->apply() ; for j : temp do ( tot := tot + pos->indexOf(j) - 1 + 1 ; pos := pos->excludingAt(pos->indexOf(j) - 1+1) ; pos := pos.insertAt(0+1, j))) ; execute (tot)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,m,k=map(int,input().split()) p=list(map(int,input().split())) ans=0 for _ in range(n): a=list(map(int,input().split())) for i in a : x=p.index(i) ans+=x+1 for j in range(x,0,-1): p[j-1],p[j]=p[j],p[j-1] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : a do ( var x : int := p->indexOf(i) - 1 ; ans := ans + x + 1 ; for j : Integer.subrange(0 + 1, x)->reverse() do ( var p[j - 1+1] : OclAny := null; var p[j+1] : OclAny := null; Sequence{p[j - 1+1],p[j+1]} := Sequence{p[j+1],p[j - 1+1]}))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) for i in range(4): ans=[-1]*n ans[0]=i for j in range(n-1): for k in range(4): if((ans[j]| k)==a[j]and(ans[j]& k)==b[j]): ans[j+1]=k if-1 not in ans : print('YES') print(*ans) exit(0) print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, 4-1) do ( var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; ans->first() := i ; for j : Integer.subrange(0, n - 1-1) do ( for k : Integer.subrange(0, 4-1) do ( if ((MathLib.bitwiseOr(ans[j+1], k)) = a[j+1] & (MathLib.bitwiseAnd(ans[j+1], k)) = b[j+1]) then ( ans[j + 1+1] := k ) else skip)) ; if (ans)->excludes(-1) then ( execute ('YES')->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ; exit(0) ) else skip) ; execute ('NO')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def number_of_digits(n): i=4 ; res=1 ; sum=0 ; while(True): i*=4 ; res+=1 ; sum+=i ; if(sum>=n): break ; return res ; n=21 ; print(number_of_digits(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 21; ; execute (number_of_digits(n))->display();; operation number_of_digits(n : OclAny) pre: true post: true activity: var i : int := 4; ; var res : int := 1; ; var sum : int := 0; ; while (true) do ( i := i * 4; ; res := res + 1; ; sum := sum + i; ; if ((sum->compareTo(n)) >= 0) then ( break; ) else skip) ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,m=map(int,input().split()) x=sorted(list(map(int,input().split()))) count=0 for j in range(n): if x[j+n]-x[j]>=m : count+=1 if count==n : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var count : int := 0 ; for j : Integer.subrange(0, n-1) do ( if (x[j + n+1] - x[j+1]->compareTo(m)) >= 0 then ( count := count + 1 ) else skip) ; if count = n then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def S(n,x,List): A=List[: n] B=List[n :] Min=B[0]-A[0] for y in range(n): c=B[y]-A[y] if Min>c : Min=c if Min>=x : print('YES') else : print('NO') t=int(input()) for t_0 in range(t): A=[int(x)for x in input().split()] n=A[0] x=A[1] List=[int(x)for x in input().split()] List.sort() S(n,x,List) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t_0 : Integer.subrange(0, t-1) do ( A := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; n := A->first() ; x := A[1+1] ; List := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; List := List->sort() ; S(n, x, List)); operation S(n : OclAny, x : OclAny, List : OclAny) pre: true post: true activity: var A : OclAny := List.subrange(1,n) ; var B : OclAny := List.subrange(n+1) ; var Min : double := B->first() - A->first() ; for y : Integer.subrange(0, n-1) do ( var c : double := B[y+1] - A[y+1] ; if (Min->compareTo(c)) > 0 then ( Min := c ) else skip) ; if (Min->compareTo(x)) >= 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,x=map(int,input().split()) al=sorted(list(map(int,input().split()))) mid=len(al)//2 vt=[al[mid :],al[: mid]] NoY=False for i in range(mid): if abs(vt[0][i]-vt[1][i])toInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var al : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var mid : int := (al)->size() div 2 ; var vt : Sequence := Sequence{al.subrange(mid+1)}->union(Sequence{ al.subrange(1,mid) }) ; var NoY : boolean := false ; for i : Integer.subrange(0, mid-1) do ( if ((vt->first()[i+1] - vt[1+1][i+1])->abs()->compareTo(x)) < 0 then ( NoY := true ; break ) else skip) ; if NoY then ( execute ('NO')->display() ) else ( execute ('YES')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): m,d=map(int,input().strip().split()) arr=list(map(int,input().rstrip().split())) arr.sort() count=0 for j in range(0,m): if(arr[j]+d)<=(arr[m+j]): count+=1 if count==m : print("yes") else : print("no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var m : OclAny := null; var d : OclAny := null; Sequence{m,d} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := arr->sort() ; var count : int := 0 ; for j : Integer.subrange(0, m-1) do ( if ((arr[j+1] + d)->compareTo((arr[m + j+1]))) <= 0 then ( count := count + 1 ) else skip) ; if count = m then ( execute ("yes")->display() ) else ( execute ("no")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,x=list(map(int,input().split())) h=sorted(list(map(int,input().split()))) a="YES" for i in range(n): if h[i+n]-h[i]toInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var h : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var a : String := "YES" ; for i : Integer.subrange(0, n-1) do ( if (h[i + n+1] - h[i+1]->compareTo(x)) < 0 then ( a := "NO" ; break ) else skip) ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p=lambda : list(map(int,input().split())) n,t=p() l=p() i=j=s=0 for j in range(n): s+=l[j] if s>t : s-=l[i] i+=1 print(n-i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := p->apply() ; var l : OclAny := p->apply() ; i := i(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name j)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for j : Integer.subrange(0, n-1) do ( s := s + l[j+1] ; if (s->compareTo(t)) > 0 then ( s := s - l[i+1] ; i := i + 1 ) else skip) ; execute (n - i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def russianPeasant(a,b): res=0 while(b>0): if(b & 1): res=res+a a=a<<1 b=b>>1 return res print(russianPeasant(18,1)) print(russianPeasant(20,12)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (russianPeasant(18, 1))->display() ; execute (russianPeasant(20, 12))->display(); operation russianPeasant(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; while (b > 0) do ( if (MathLib.bitwiseAnd(b, 1)) then ( res := res + a ) else skip ; a := a * (2->pow(1)) ; b := b /(2->pow(1))) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution : def Solve(self,A): ans=2 n=len(A) if n<=2 : return n llap=[2]*n A.sort() for j in range(n-2,-1,-1): i=j-1 k=j+1 while(i>=0 and kexists( _x | result = _x ); operation Solve(A : OclAny) : OclAny pre: true post: true activity: var ans : int := 2 ; var n : int := (A)->size() ; if n <= 2 then ( return n ) else skip ; var llap : Sequence := MatrixLib.elementwiseMult(Sequence{ 2 }, n) ; A := A->sort() ; for j : Integer.subrange(-1 + 1, n - 2)->reverse() do ( var i : double := j - 1 ; var k : OclAny := j + 1 ; while (i >= 0 & (k->compareTo(n)) < 0) do ( if A[i+1] + A[k+1] = 2 * A[j+1] then ( llap[j+1] := Set{llap[k+1] + 1, llap[j+1]}->max() ; ans := Set{ans, llap[j+1]}->max() ; i := i - 1 ; k := k + 1 ) else (if (A[i+1] + A[k+1]->compareTo(2 * A[j+1])) < 0 then ( k := k + 1 ) else ( i := i - 1 ) ) )) ; return ans; } class FromPython { operation initialise() pre: true post: true activity: skip ; var obj : Solution := (Solution.newSolution()).initialise() ; var a : Sequence := Sequence{9}->union(Sequence{4}->union(Sequence{7}->union(Sequence{2}->union(Sequence{ 10 })))) ; execute (obj.Solve(a))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r=l=0 for _ in range(int(input())): _,s,a=input().split() a=int(a) if s[0]=='(' : l+=a else : r+=a print(['No','Yes'][l==r]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : OclAny := 0; var l : int := 0 ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var _anon : OclAny := null; var s : OclAny := null; var a : OclAny := null; Sequence{_anon,s,a} := input().split() ; var a : int := ("" + ((a)))->toInteger() ; if s->first() = '(' then ( l := l + a ) else ( r := r + a ) ; execute (Sequence{'No'}->union(Sequence{ 'Yes' })->select(l = r))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=[int(i)for i in input().split()] arr=[int(i)for i in input().split()] total=0 ans=0 p,q=0,0 while pt : total-=arr[q] q=q+1 p=p+1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var arr : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var total : int := 0 ; var ans : int := 0 ; var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := Sequence{0,0} ; while (p->compareTo(n)) < 0 do ( total := total + arr[p+1] ; if (total->compareTo(t)) <= 0 then ( ans := Set{p - q + 1, ans}->max() ) else ( while (total->compareTo(t)) > 0 do ( total := total - arr[q+1] ; var q : OclAny := q + 1) ) ; var p : OclAny := p + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=list(map(int,input().split())) l=list(map(int,input().split())) pos1=pos2=0 Max=0 total=0 count=0 while pos2t : total-=l[pos1] pos1+=1 count-=1 if count>Max : Max=count print(Max) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var pos1 : OclAny := 0; var pos2 : int := 0 ; var Max : int := 0 ; var total : int := 0 ; var count : int := 0 ; while (pos2->compareTo(n)) < 0 do ( total := total + l[pos2+1] ; pos2 := pos2 + 1 ; count := count + 1 ; while (total->compareTo(t)) > 0 do ( total := total - l[pos1+1] ; pos1 := pos1 + 1 ; count := count - 1) ; if (count->compareTo(Max)) > 0 then ( Max := count ) else skip) ; execute (Max)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- [n,t]=[int(i)for i in input().split()] a=[int(i)for i in input().split()] j=0 ans=0 sm=0 for i in range(n): while junion(Sequence{ t }) := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var j : int := 0 ; var ans : int := 0 ; var sm : int := 0 ; for i : Integer.subrange(0, n-1) do ( while (j->compareTo(n)) < 0 & (a[j+1] + sm->compareTo(t)) <= 0 do ( sm := sm + a[j+1] ; ans := Set{ans, j - i + 1}->max() ; j := j + 1) ; sm := sm - a[i+1]) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=[int(i)for i in input().split()] nn=[int(i)for i in input().split()] k=-1 i=0 m=0 s=0 while k<=n[0]-2 : if s>n[1]: s-=nn[i] i+=1 continue else : m=max(m,k-i+1) k+=1 s+=nn[k] if s<=n[1]: m=max(m,k-i+1) print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var nn : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var k : int := -1 ; var i : int := 0 ; var m : int := 0 ; var s : int := 0 ; while (k->compareTo(n->first() - 2)) <= 0 do ( if (s->compareTo(n[1+1])) > 0 then ( s := s - nn[i+1] ; i := i + 1 ; continue ) else ( m := Set{m, k - i + 1}->max() ; k := k + 1 ) ; s := s + nn[k+1]) ; if (s->compareTo(n[1+1])) <= 0 then ( m := Set{m, k - i + 1}->max() ) else skip ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy def printSmallestSequence(s): m=copy.copy(s) for i in range(len(s)-1): if m>s[i :]+s[: i]: m=s[i :]+s[: i] return m if __name__=='__main__' : st='DCACBCAA' print(printSmallestSequence(st)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var st : String := 'DCACBCAA' ; execute (printSmallestSequence(st))->display() ) else skip; operation printSmallestSequence(s : OclAny) : OclAny pre: true post: true activity: var m : OclAny := copy->copy() ; for i : Integer.subrange(0, (s)->size() - 1-1) do ( if (m->compareTo(s.subrange(i+1) + s.subrange(1,i))) > 0 then ( m := s.subrange(i+1) + s.subrange(1,i) ) else skip) ; return m; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) s=list(input().rstrip()) ok=0 ans="Yes" for i in range(n-1): if s[i]==s[i+1]and s[i]^ 63 : ans="No" break elif s[i]==s[i+1]: ok=1 for i in range(1,n-1): if s[i]==63 and s[i-1]==s[i+1]: ok=1 break if s[0]==63 or s[-1]==63 : ok=1 if not ok : ans="No" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := (input().rstrip()) ; var ok : int := 0 ; var ans : String := "Yes" ; for i : Integer.subrange(0, n - 1-1) do ( if s[i+1] = s[i + 1+1] & MathLib.bitwiseXor(s[i+1], 63) then ( ans := "No" ; break ) else (if s[i+1] = s[i + 1+1] then ( ok := 1 ) else skip)) ; for i : Integer.subrange(1, n - 1-1) do ( if s[i+1] = 63 & s[i - 1+1] = s[i + 1+1] then ( ok := 1 ; break ) else skip) ; if s->first() = 63 or s->last() = 63 then ( ok := 1 ) else skip ; if not(ok) then ( ans := "No" ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() arr=input() yes=1*max(0,1-arr.count("MM"))*max(0,1-arr.count("CC"))*max(0,1-arr.count("YY")) found=min(1,max(arr.count("??"),int(arr[0]=="?"),int(arr[-1]=="?"))) for i in range(1,len(arr)-1): if(arr[i-1]==arr[i+1]and arr[i]=="?"): found=1 break print(["No","Yes"][yes*found]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var arr : String := (OclFile["System.in"]).readLine() ; var yes : double := 1 * Set{0, 1 - arr->count("MM")}->max() * Set{0, 1 - arr->count("CC")}->max() * Set{0, 1 - arr->count("YY")}->max() ; var found : OclAny := Set{1, Set{arr->count("??"), ("" + ((arr->first() = "?")))->toInteger(), ("" + ((arr->last() = "?")))->toInteger()}->max()}->min() ; for i : Integer.subrange(1, (arr)->size() - 1-1) do ( if (arr[i - 1+1] = arr[i + 1+1] & arr[i+1] = "?") then ( found := 1 ; break ) else skip) ; execute (Sequence{"No"}->union(Sequence{ "Yes" })[yes * found+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() S=[ch for ch in s] ok=True for i in range(len(S)-1): if S[i]==S[i+1]and S[i]!='?' : ok=False ko=0 for i in range(len(S)-2): if S[i]!=S[i+2]and S[i+1]=='?' and S[i]!='?' : ko+=1 z=S.count('?') if ok==True and '?' in S and z!=ko : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var S : Sequence := s->characters()->select(ch | true)->collect(ch | (ch)) ; var ok : boolean := true ; for i : Integer.subrange(0, (S)->size() - 1-1) do ( if S[i+1] = S[i + 1+1] & S[i+1] /= '?' then ( ok := false ) else skip) ; var ko : int := 0 ; for i : Integer.subrange(0, (S)->size() - 2-1) do ( if S[i+1] /= S[i + 2+1] & S[i + 1+1] = '?' & S[i+1] /= '?' then ( ko := ko + 1 ) else skip) ; var z : int := S->count('?') ; if ok = true & (S)->includes('?') & z /= ko then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() canBe=False if(s.count('MM')+s.count('CC')+s.count('YY')>=1): print('No') elif(s[0]=='?' or s[len(s)-1]=='?'): print('Yes') else : for i in range(1,len(s)-1): if(s[i]=='?' and(s[i-1]==s[i+1])): canBe=True break elif(s[i]=='?' and s[i+1]=='?'): canBe=True break if(canBe): print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var canBe : boolean := false ; if (s->count('MM') + s->count('CC') + s->count('YY') >= 1) then ( execute ('No')->display() ) else (if (s->first() = '?' or s[(s)->size() - 1+1] = '?') then ( execute ('Yes')->display() ) else ( for i : Integer.subrange(1, (s)->size() - 1-1) do ( if (s[i+1] = '?' & (s[i - 1+1] = s[i + 1+1])) then ( canBe := true ; break ) else (if (s[i+1] = '?' & s[i + 1+1] = '?') then ( canBe := true ; break ) else skip)) ; if (canBe) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minimumChanges(arr,n,d): maxFreq=-2147483648 freq={} for i in range(n): a0=arr[i]-i*d if a0 in freq : freq[a0]+=1 else : freq[a0]=1 if freq[a0]>maxFreq : maxFreq=freq[a0] return(n-maxFreq) n=5 d=1 arr=[1,3,3,4,6] ans=minimumChanges(arr,n,d) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; d := 1 ; arr := Sequence{1}->union(Sequence{3}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 6 })))) ; var ans : OclAny := minimumChanges(arr, n, d) ; execute (ans)->display(); operation minimumChanges(arr : OclAny, n : OclAny, d : OclAny) : OclAny pre: true post: true activity: var maxFreq : int := -2147483648 ; var freq : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var a0 : double := arr[i+1] - i * d ; if (freq)->includes(a0) then ( freq[a0+1] := freq[a0+1] + 1 ) else ( freq[a0+1] := 1 ) ; if (freq[a0+1]->compareTo(maxFreq)) > 0 then ( maxFreq := freq[a0+1] ) else skip) ; return (n - maxFreq); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sol(A): if len(A)==1 : if A[0]=="?" : return "YES" else : return "NO" count=0 for i in range(len(A)): if A[i]=="?" : count+=1 continue if i!=0 and A[i]==A[i-1]: return "NO" if count==0 : return "NO" if A[0]=="?" or A[-1]=="?" : return "YES" for i in range(1,len(A)): if A[i]=="?" : if A[i-1]=="?" : return "YES" if i!=len(A)-1 and A[i-1]==A[i+1]: return "YES" return "NO" n=int(input()) A=input() print(sol(A)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; A := (OclFile["System.in"]).readLine() ; execute (sol(A))->display(); operation sol(A : OclAny) : OclAny pre: true post: true activity: if (A)->size() = 1 then ( if A->first() = "?" then ( return "YES" ) else ( return "NO" ) ) else skip ; var count : int := 0 ; for i : Integer.subrange(0, (A)->size()-1) do ( if A[i+1] = "?" then ( count := count + 1 ; continue ) else skip ; if i /= 0 & A[i+1] = A[i - 1+1] then ( return "NO" ) else skip) ; if count = 0 then ( return "NO" ) else skip ; if A->first() = "?" or A->last() = "?" then ( return "YES" ) else skip ; for i : Integer.subrange(1, (A)->size()-1) do ( if A[i+1] = "?" then ( if A[i - 1+1] = "?" then ( return "YES" ) else skip ; if i /= (A)->size() - 1 & A[i - 1+1] = A[i + 1+1] then ( return "YES" ) else skip ) else skip) ; return "NO"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=0 for _ in range(int(input())): _,s,a=input().split() a=int(a) c+=a if s=='(' else-a print(['No','Yes'][not c]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : int := 0 ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var _anon : OclAny := null; var s : OclAny := null; var a : OclAny := null; Sequence{_anon,s,a} := input().split() ; var a : int := ("" + ((a)))->toInteger() ; c := c + if s = '(' then a else -a endif ; execute (Sequence{'No'}->union(Sequence{ 'Yes' })->select(not(c)))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=map(int,input().split()) print(min(n*a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{n * a, b}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- price=input().split() if int(price[0])*int(price[1])>int(price[2]): print(int(price[2])) else : print(int(price[0])*int(price[1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var price : OclAny := input().split() ; if (("" + ((price->first())))->toInteger() * ("" + ((price[1+1])))->toInteger()->compareTo(("" + ((price[2+1])))->toInteger())) > 0 then ( execute (("" + ((price[2+1])))->toInteger())->display() ) else ( execute (("" + ((price->first())))->toInteger() * ("" + ((price[1+1])))->toInteger())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,A,B=input().strip().split(' ') N,A,B=[int(N),int(A),int(B)] plan1=A*N plan2=B print(min(plan1,plan2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{N,A,B} := input()->trim().split(' ') ; var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{N,A,B} := Sequence{("" + ((N)))->toInteger()}->union(Sequence{("" + ((A)))->toInteger()}->union(Sequence{ ("" + ((B)))->toInteger() })) ; var plan1 : double := A * N ; var plan2 : OclAny := B ; execute (Set{plan1, plan2}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ABC_80_A(): N,A,B=map(int,input().split()) if A*N<=B : print(A*N) else : print(B) if __name__=='__main__' : ABC_80_A() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( ABC_80_A() ) else skip; operation ABC_80_A() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{N,A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (A * N->compareTo(B)) <= 0 then ( execute (A * N)->display() ) else ( execute (B)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- parking_time,time_price,anytime_price=map(int,input().split()) min_price_plan=min(parking_time*time_price,anytime_price) print(min_price_plan) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var parking_time : OclAny := null; var time_price : OclAny := null; var anytime_price : OclAny := null; Sequence{parking_time,time_price,anytime_price} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var min_price_plan : OclAny := Set{parking_time * time_price, anytime_price}->min() ; execute (min_price_plan)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=str(input()) L=len(N) X=0 ans=None for i in range(0,L): Y=int(N[i]) X=X+Y if X % 9==0 : ans="Yes" else : ans="No" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : String := ("" + (((OclFile["System.in"]).readLine()))) ; var L : int := (N)->size() ; var X : int := 0 ; var ans : OclAny := null ; for i : Integer.subrange(0, L-1) do ( var Y : int := ("" + ((N[i+1])))->toInteger() ; X := X + Y) ; if X mod 9 = 0 then ( ans := "Yes" ) else ( ans := "No" ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print('Yes' if int(input())% 9==0 else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (if ("" + (((OclFile["System.in"]).readLine())))->toInteger() mod 9 = 0 then 'Yes' else 'No' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N=map(lambda x : int(x),list((input()))) result=0 for item in N : result+=item if result % 9==0 : print("Yes") else : print("No") if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var N : Sequence := ((((OclFile["System.in"]).readLine()))->characters())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ) ; var result : int := 0 ; for item : N do ( result := result + item) ; if result mod 9 = 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[[*map(int,input().split()),i]for i in range(n)] a=*filter(lambda x : all(any(v>=u for u,v in zip(c[: 3],x[: 3]))for c in a),a), print(min(a,key=lambda x : x[3])[4]+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((input().split())->collect( _x | (OclType["int"])->apply(_x) )->union(Sequence{ i }))) ; a := (testlist_star_expr (star_expr * (expr (atom (name filter)) (trailer (arguments ( (arglist (argument (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name all)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name any)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (comparison (expr (atom (name v)))) >= (comparison (expr (atom (name u))))))) (comp_for for (exprlist (expr (atom (name u))) , (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (number (integer 3))))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (number (integer 3))))))))) ])))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name a)))))))) ))))))))) , (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ,) ; execute (min(a, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 3))))))))) ])))))))))[4+1] + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() ret=0 for s in n : ret*=10 ret %=9 ret+=int(s) ret %=9 if ret==0 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var ret : int := 0 ; for s : n->characters() do ( ret := ret * 10 ; ret := ret mod 9 ; ret := ret + ("" + ((s)))->toInteger() ; ret := ret mod 9) ; if ret = 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() tmp=0 for i in range(10): c=n.count(str(i)) tmp+=c*i if tmp % 9==0 : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var tmp : int := 0 ; for i : Integer.subrange(0, 10-1) do ( var c : int := n->count(("" + ((i)))) ; tmp := tmp + c * i) ; if tmp mod 9 = 0 then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=list(map(int,input().split())) ans=0 for i in range(30,0,-1): for j in range(N): if A[j]%(2**i)==0 : A[j]=1 ans+=i print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(0 + 1, 30)->reverse() do ( for j : Integer.subrange(0, N-1) do ( if A[j+1] mod ((2)->pow(i)) = 0 then ( A[j+1] := 1 ; ans := ans + i ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) lp=rp=0 for i in range(N): p,c,n=input().split() if c=='(' : lp+=int(n) else : rp+=int(n) print('Yes' if lp==rp else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lp : OclAny := 0; var rp : int := 0 ; for i : Integer.subrange(0, N-1) do ( var p : OclAny := null; var c : OclAny := null; var n : OclAny := null; Sequence{p,c,n} := input().split() ; if c = '(' then ( lp := lp + ("" + ((n)))->toInteger() ) else ( rp := rp + ("" + ((n)))->toInteger() ) ; execute (if lp = rp then 'Yes' else 'No' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d,e,f=map(int,input().split()) print('Ron' if a*e*ccollect( _x | (OclType["int"])->apply(_x) ) ; execute (if (a * e * c->compareTo(f * d * b)) < 0 or (c = 0 & d) or (a = 0 & b & d) then 'Ron' else 'Hermione' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d,e,f=map(int,input().split()) if c==0 and d!=0 : print("Ron") elif a==0 and b!=0 and d!=0 : print("Ron") elif b*d*f>a*c*e : print("Ron") else : print("Hermione") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; var f : OclAny := null; Sequence{a,b,c,d,e,f} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if c = 0 & d /= 0 then ( execute ("Ron")->display() ) else (if a = 0 & b /= 0 & d /= 0 then ( execute ("Ron")->display() ) else (if (b * d * f->compareTo(a * c * e)) > 0 then ( execute ("Ron")->display() ) else ( execute ("Hermione")->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d,e,f=map(int,input().split()) print('Ron' if a*e*ccollect( _x | (OclType["int"])->apply(_x) ) ; execute (if (a * e * c->compareTo(f * d * b)) < 0 or (c = 0 & d) or (a = 0 & b & d) then 'Ron' else 'Hermione' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d,e,f=map(int,input().split()) print('Ron' if a*e*ccollect( _x | (OclType["int"])->apply(_x) ) ; execute (if (a * e * c->compareTo(f * d * b)) < 0 or (c = 0 & d) or (a = 0 & b & d) then 'Ron' else 'Hermione' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d,e,f=map(int,input().split()) print('Ron' if a*e*ccollect( _x | (OclType["int"])->apply(_x) ) ; execute (if (a * e * c->compareTo(f * d * b)) < 0 or (c = 0 & d) or (a = 0 & b & d) then 'Ron' else 'Hermione' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countStrUtil(dp,n,bCount=1,cCount=2): if(bCount<0 or cCount<0): return 0 if(n==0): return 1 if(bCount==0 and cCount==0): return 1 if(dp[n][bCount][cCount]!=-1): return dp[n][bCount][cCount] res=countStrUtil(dp,n-1,bCount,cCount) res+=countStrUtil(dp,n-1,bCount-1,cCount) res+=countStrUtil(dp,n-1,bCount,cCount-1) dp[n][bCount][cCount]=res return dp[n][bCount][cCount] def countStr(n): dp=[[[-1 for x in range(n+2)]for y in range(3)]for z in range(4)] return countStrUtil(dp,n) if __name__=="__main__" : n=3 print(countStr(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 3 ; execute (countStr(n))->display() ) else skip; operation countStrUtil(dp : OclAny, n : OclAny, bCount : int, cCount : int) : OclAny pre: true post: true activity: if bCount->oclIsUndefined() then bCount := 1 else skip; if cCount->oclIsUndefined() then cCount := 2 else skip; if (bCount < 0 or cCount < 0) then ( return 0 ) else skip ; if (n = 0) then ( return 1 ) else skip ; if (bCount = 0 & cCount = 0) then ( return 1 ) else skip ; if (dp[n+1][bCount+1][cCount+1] /= -1) then ( return dp[n+1][bCount+1][cCount+1] ) else skip ; var res : OclAny := countStrUtil(dp, n - 1, bCount, cCount) ; res := res + countStrUtil(dp, n - 1, bCount - 1, cCount) ; res := res + countStrUtil(dp, n - 1, bCount, cCount - 1) ; dp[n+1][bCount+1][cCount+1] := res ; return dp[n+1][bCount+1][cCount+1]; operation countStr(n : OclAny) : OclAny pre: true post: true activity: dp := Integer.subrange(0, 4-1)->select(z | true)->collect(z | (Integer.subrange(0, 3-1)->select(y | true)->collect(y | (Integer.subrange(0, n + 2-1)->select(x | true)->collect(x | (-1)))))) ; return countStrUtil(dp, n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) input_array=[] for i in range(n): S,R,H,C=map(int,input().split()) input_array.append((S,R,H,C)) outdated=[] for i in range(n): for j in range(n): if(input_array[i][0]toInteger() ; var input_array : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var S : OclAny := null; var R : OclAny := null; var H : OclAny := null; var C : OclAny := null; Sequence{S,R,H,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{S, R, H, C}) : input_array)) ; var outdated : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if ((input_array[i+1]->first()->compareTo(input_array[j+1]->first())) < 0 & (input_array[i+1][1+1]->compareTo(input_array[j+1][1+1])) < 0 & (input_array[i+1][2+1]->compareTo(input_array[j+1][2+1])) < 0) then ( execute ((input_array[i+1]) : outdated) ) else skip)) ; outdated := Set{}->union((outdated)) ; var minimum_cost : int := 100000 ; var input_number : int := 0 ; for i : Integer.subrange(0, n-1) do ( var current_item : OclAny := input_array[i+1] ; var cost : OclAny := current_item[3+1] ; if ((outdated)->excludes(current_item) & (cost->compareTo(minimum_cost)) < 0) then ( minimum_cost := current_item[3+1] ; input_number := i + 1 ) else skip) ; execute (input_number)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) t,=R() while t : t-=1 ; w,h=R(); r=0 for x in[h,h,w,w]: k,m,*_,M=R(); r=max(r,x*(M-m)) print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := R->apply() ; while t do ( t := t - 1; var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := R->apply(); var r : int := 0 ; for x : Sequence{h}->union(Sequence{h}->union(Sequence{w}->union(Sequence{ w }))) do ( var k : OclAny := null; var m : OclAny := null; var _anon : OclAny := null; var M : OclAny := null; Sequence{k,m,_anon,M} := R->apply(); r := Set{r, x * (M - m)}->max()) ; execute (r)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cas=int(input()) for i in range(cas): w,h=[int(x)for x in input().split()] r=0 for j in range(2): a=[int(x)for x in input().split()] r=max(r,(a[-1]-a[1])*h) for j in range(2): a=[int(x)for x in input().split()] r=max(r,(a[-1]-a[1])*w) print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cas : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, cas-1) do ( var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var r : int := 0 ; for j : Integer.subrange(0, 2-1) do ( var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; r := Set{r, (a->last() - a[1+1]) * h}->max()) ; for j : Integer.subrange(0, 2-1) do ( a := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; r := Set{r, (a->last() - a[1+1]) * w}->max()) ; execute (r)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=map(int,input().split()) x1=list(map(int,input().split())) y1=list(map(int,input().split())) x2=list(map(int,input().split())) y2=list(map(int,input().split())) m1=x1[-1]-x1[1] m2=x2[-1]-x2[1] m3=y1[-1]-y1[1] m4=y2[-1]-y2[1] print(max(m1*m,m3*m,m2*n,m4*n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var y1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var y2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m1 : double := x1->last() - x1[1+1] ; var m2 : double := x2->last() - x2[1+1] ; var m3 : double := y1->last() - y1[1+1] ; var m4 : double := y2->last() - y2[1+1] ; execute (Set{m1 * m, m3 * m, m2 * n, m4 * n}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): w,h=map(int,input().split()) ans=0 for i in range(4): a=[int(x)for x in input().split()][1 :] ans=max(ans,(a[-1]-a[0])*(h if i<2 else w)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; for i : Integer.subrange(0, 4-1) do ( var a : OclAny := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))->tail() ; ans := Set{ans, (a->last() - a->first()) * (if i < 2 then h else w endif)}->max()) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] n=I() ni=0 t=0 while nipow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; var n : OclAny := I() ; var ni : int := 0 ; var t : int := 0 ; while (ni->compareTo(n)) < 0 do ( ni := ni + 1 ; var a : OclAny := LS() ; if a[1+1] = '(' then ( t := t - ("" + ((a[2+1])))->toInteger() ) else ( t := t + ("" + ((a[2+1])))->toInteger() ) ; if t = 0 then ( execute (('Yes') : rr) ) else ( execute (('No') : rr) )) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): w,h=map(int,input().split()) ans=0 for i in range(4): a=[int(x)for x in input().split()][1 :] ans=max(ans,(a[-1]-a[0])*(h if i<2 else w)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; for i : Integer.subrange(0, 4-1) do ( var a : OclAny := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))->tail() ; ans := Set{ans, (a->last() - a->first()) * (if i < 2 then h else w endif)}->max()) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nextGap(gap): if(gap<=1): return 0 ; res=(gap//2)+(gap % 2); return res ; def mergeTwoSortedArray(arr1,arr2,n,m): x=min(n,m); for i in range(x): if(arr1[n-i-1]>arr2[i]): arr1[n-i-1],arr2[i]=arr2[i],arr1[n-i-1]; gap=nextGap(n); while gap>0 : i=0 ; while i+gaparr1[i+gap]): arr1[i],arr1[i+gap]=arr1[i+gap],arr1[i]; i+=1 ; gap=nextGap(gap) gap=nextGap(m); while gap>0 : i=0 while i+gaparr2[i+gap]): arr2[i],arr2[i+gap]=arr2[i+gap],arr2[i]; i+=1 ; gap=nextGap(gap) for i in range(n): print(arr1[i],end=" "); for j in range(m): print(arr2[j],end=" "); if __name__=="__main__" : arr1=[1,5,9,10,15,20]; n=len(arr1); arr2=[2,3,8,13]; m=len(arr2); mergeTwoSortedArray(arr1,arr2,n,m); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr1 := Sequence{1}->union(Sequence{5}->union(Sequence{9}->union(Sequence{10}->union(Sequence{15}->union(Sequence{ 20 }))))); ; n := (arr1)->size(); ; arr2 := Sequence{2}->union(Sequence{3}->union(Sequence{8}->union(Sequence{ 13 }))); ; m := (arr2)->size(); ; mergeTwoSortedArray(arr1, arr2, n, m); ) else skip; operation nextGap(gap : OclAny) pre: true post: true activity: if (gap <= 1) then ( return 0; ) else skip ; var res : int := (gap div 2) + (gap mod 2); ; return res;; operation mergeTwoSortedArray(arr1 : OclAny, arr2 : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: var x : OclAny := Set{n, m}->min(); ; for i : Integer.subrange(0, x-1) do ( if ((arr1[n - i - 1+1]->compareTo(arr2[i+1])) > 0) then ( var arr1[n - i - 1+1] : OclAny := null; var arr2[i+1] : OclAny := null; Sequence{arr1[n - i - 1+1],arr2[i+1]} := Sequence{arr2[i+1],arr1[n - i - 1+1]}; ) else skip) ; gap := nextGap(n); ; while gap > 0 do ( var i : int := 0; ; while (i + gap->compareTo(n)) < 0 do ( if ((arr1[i+1]->compareTo(arr1[i + gap+1])) > 0) then ( var arr1[i+1] : OclAny := null; var arr1[i + gap+1] : OclAny := null; Sequence{arr1[i+1],arr1[i + gap+1]} := Sequence{arr1[i + gap+1],arr1[i+1]}; ) else skip ; i := i + 1;) ; gap := nextGap(gap)) ; gap := nextGap(m); ; while gap > 0 do ( i := 0 ; while (i + gap->compareTo(m)) < 0 do ( if ((arr2[i+1]->compareTo(arr2[i + gap+1])) > 0) then ( var arr2[i+1] : OclAny := null; var arr2[i + gap+1] : OclAny := null; Sequence{arr2[i+1],arr2[i + gap+1]} := Sequence{arr2[i + gap+1],arr2[i+1]}; ) else skip ; i := i + 1;) ; gap := nextGap(gap)) ; for i : Integer.subrange(0, n-1) do ( execute (arr1[i+1])->display();) ; for j : Integer.subrange(0, m-1) do ( execute (arr2[j+1])->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys ; min_val=sys.maxsize ; min_steps=0 ; def sumOfDigits(n): s=str(n); sum=0 ; for i in range(len(s)): sum+=(ord(s[i])-ord('0')); return sum ; def Transform(n,d,steps): global min_val ; global min_steps ; if(ndisplay(); ) else skip; operation sumOfDigits(n : OclAny) pre: true post: true activity: var s : String := ("" + ((n))); ; var sum : int := 0; ; for i : Integer.subrange(0, (s)->size()-1) do ( sum := sum + ((s[i+1])->char2byte() - ('0')->char2byte());) ; return sum;; operation Transform(n : OclAny, d : OclAny, steps : OclAny) pre: true post: true activity: skip; skip; ; if ((n->compareTo(min_val)) < 0) then ( min_val := n; ; min_steps := steps; ) else (if (n = min_val) then ( min_steps := Set{min_steps, steps}->min(); ) else skip) ; if (steps < 15) then ( Transform(sumOfDigits(n), d, steps + 1); ; Transform(n + d, d, steps + 1); ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque N=int(input()) idxs=[deque()for i in range(26)] def ctoi(c): return ord(c)-ord('a') cs=[] for i in range(N): c=input()[0] cs.append(c) ci=ctoi(c) idxs[ci].append(i) dp=[i for i in range(N)] dp[0]=0 for i in range(N): c=cs[i] ci=ctoi(c) if i>0 : dp[i]=min(dp[i],dp[i-1]+1) if len(idxs[ci])<2 : continue idxs[ci].popleft() pi=idxs[ci][0] dp[pi]=dp[i] print(dp[-1]+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var idxs : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | (())) ; skip ; var cs : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( c := input()->first() ; execute ((c) : cs) ; var ci : OclAny := ctoi(c) ; (expr (atom (name idxs)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ci)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var dp : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (i)) ; dp->first() := 0 ; for i : Integer.subrange(0, N-1) do ( c := cs[i+1] ; ci := ctoi(c) ; if i > 0 then ( dp[i+1] := Set{dp[i+1], dp[i - 1+1] + 1}->min() ) else skip ; if (idxs[ci+1])->size() < 2 then ( continue ) else skip ; (expr (atom (name idxs)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ci)))))))) ])) (trailer . (name popleft) (arguments ( )))) ; var pi : OclAny := idxs[ci+1]->first() ; dp[pi+1] := dp[i+1]) ; execute (dp->last() + 1)->display(); operation ctoi(c : OclAny) : OclAny pre: true post: true activity: return (c)->char2byte() - ('a')->char2byte(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countdig(m): if(m==0): return 0 else : return 1+countdig(m//10) def countSteps(x): c=0 last=x while(last): digits=countdig(last) digits-=1 divisor=pow(10,digits) first=last//divisor lastnumber=first*divisor skipped=(last-lastnumber)//first skipped+=1 c+=skipped last=last-(first*skipped) return c n=14 print(countSteps(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := 14 ; execute (countSteps(n))->display(); operation countdig(m : OclAny) : OclAny pre: true post: true activity: if (m = 0) then ( return 0 ) else ( return 1 + countdig(m div 10) ); operation countSteps(x : OclAny) : OclAny pre: true post: true activity: var c : int := 0 ; var last : OclAny := x ; while (last) do ( var digits : OclAny := countdig(last) ; digits := digits - 1 ; var divisor : double := (10)->pow(digits) ; var first : int := last div divisor ; var lastnumber : double := first * divisor ; var skipped : int := (last - lastnumber) div first ; skipped := skipped + 1 ; c := c + skipped ; last := last - (first * skipped)) ; return c; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from os import path if path.exists('input.txt'): sys.stdin=open('input.txt','r') sys.stdout=open('output.txt','w') n=int(input()) print(sorted(map(int,input().split()))[(n-1)//2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if path.exists('input.txt') then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('input.txt')) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile('output.txt')) ) else skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (sorted((input().split())->collect( _x | (OclType["int"])->apply(_x) ))[(n - 1) div 2+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x,n=map(int,input().split()) q,r=divmod(n-1,4) r+=1 if x % 2==0 : if r==1 : print(x-4*q-r) elif r==2 : print(x+1) elif r==3 : print(x+1+4*q+r) else : print(x) else : if r==1 : print(x+4*q+r) elif r==2 : print(x-1) elif r==3 : print(x-1-4*q-r) else : print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var n : OclAny := null; Sequence{x,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var q : OclAny := null; var r : OclAny := null; Sequence{q,r} := Sequence{(n - 1 div 4), (n - 1 mod 4)} ; r := r + 1 ; if x mod 2 = 0 then ( if r = 1 then ( execute (x - 4 * q - r)->display() ) else (if r = 2 then ( execute (x + 1)->display() ) else (if r = 3 then ( execute (x + 1 + 4 * q + r)->display() ) else ( execute (x)->display() ) ) ) ) else ( if r = 1 then ( execute (x + 4 * q + r)->display() ) else (if r = 2 then ( execute (x - 1)->display() ) else (if r = 3 then ( execute (x - 1 - 4 * q - r)->display() ) else ( execute (x)->display() ) ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) maps=[lambda x : 0,lambda x : x,lambda x :-1,lambda x :-x-1] for _ in range(t): x0,n=map(int,input().split()) d=maps[n % 4](n) print(x0-d if x0 % 2==0 else x0+d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var maps : Sequence := Sequence{lambda x : OclAny in (0)}->union(Sequence{lambda x : OclAny in (x)}->union(Sequence{lambda x : OclAny in (-1)}->union(Sequence{ lambda x : OclAny in (-x - 1) }))) ; for _anon : Integer.subrange(0, t-1) do ( var x0 : OclAny := null; var n : OclAny := null; Sequence{x0,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : OclAny := maps[n mod 4+1](n) ; execute (if x0 mod 2 = 0 then x0 - d else x0 + d endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): x,n=map(int,input().split()) if n % 4==1 : d=-n elif n % 4==2 : d=1 elif n % 4==3 : d=n+1 else : d=0 if x % 2==1 : print(x-d) else : print(x+d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var x : OclAny := null; var n : OclAny := null; Sequence{x,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n mod 4 = 1 then ( var d : OclAny := -n ) else (if n mod 4 = 2 then ( d := 1 ) else (if n mod 4 = 3 then ( d := n + 1 ) else ( d := 0 ) ) ) ; if x mod 2 = 1 then ( execute (x - d)->display() ) else ( execute (x + d)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) maps=[lambda x : 0,lambda x : x,lambda x :-1,lambda x :-x-1] for _ in range(t): x0,n=map(int,input().split()) d=maps[n % 4](n) print(x0-d if x0 % 2==0 else x0+d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var maps : Sequence := Sequence{lambda x : OclAny in (0)}->union(Sequence{lambda x : OclAny in (x)}->union(Sequence{lambda x : OclAny in (-1)}->union(Sequence{ lambda x : OclAny in (-x - 1) }))) ; for _anon : Integer.subrange(0, t-1) do ( var x0 : OclAny := null; var n : OclAny := null; Sequence{x0,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : OclAny := maps[n mod 4+1](n) ; execute (if x0 mod 2 = 0 then x0 - d else x0 + d endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x,n=list(map(int,input().split())) a=n % 4 b=n-a if a==0 : print(x) else : for i in range(1,a+1): if(x % 2)==0 : x=x-(i+b) else : x=x+(i+b) print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var n : OclAny := null; Sequence{x,n} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : int := n mod 4 ; var b : double := n - a ; if a = 0 then ( execute (x)->display() ) else ( for i : Integer.subrange(1, a + 1-1) do ( if (x mod 2) = 0 then ( var x : double := x - (i + b) ) else ( x := x + (i + b) )) ; execute (x)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r=0 for i in range(int(input())): l=list(input().split()) r+=int(l[2])*(2*(l[1]=='(')-1) print(['No','Yes'][r==0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : int := 0 ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var l : Sequence := (input().split()) ; r := r + ("" + ((l[2+1])))->toInteger() * (2 * (l[1+1] = '(') - 1) ; execute (Sequence{'No'}->union(Sequence{ 'Yes' })->select(r = 0))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkSpecialPrime(sieve,num): while(num): if(not sieve[num]): return False num//=10 return True def findSpecialPrime(N): sieve=[True]*(N+10) sieve[0]=sieve[1]=False ; for i in range(2,N+1): if(sieve[i]): for j in range(i*i,N+1,i): sieve[j]=False while(True): if(checkSpecialPrime(sieve,N)): print(N) break else : N-=1 if __name__=="__main__" : findSpecialPrime(379) findSpecialPrime(100) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( findSpecialPrime(379) ; findSpecialPrime(100) ) else skip; operation checkSpecialPrime(sieve : OclAny, num : OclAny) : OclAny pre: true post: true activity: while (num) do ( if (not(sieve[num+1])) then ( return false ) else skip ; num := num div 10) ; return true; operation findSpecialPrime(N : OclAny) pre: true post: true activity: sieve := MatrixLib.elementwiseMult(Sequence{ true }, (N + 10)) ; sieve->first() := false; var sieve[1+1] : boolean := false; ; for i : Integer.subrange(2, N + 1-1) do ( if (sieve[i+1]) then ( for j : Integer.subrange(i * i, N + 1-1)->select( $x | ($x - i * i) mod i = 0 ) do ( sieve[j+1] := false) ) else skip) ; while (true) do ( if (checkSpecialPrime(sieve, N)) then ( execute (N)->display() ; break ) else ( N := N - 1 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkSpecialPrime(sieve,num): while(num): if(sieve[num]==False): return False num=int(num/10) return True def findSpecialPrime(N): sieve=[True for i in range(N*10+1)] sieve[0]=False sieve[1]=False for i in range(2,N*10+1): if(sieve[i]): for j in range(i*i,N*10+1,i): sieve[j]=False while(True): if(checkSpecialPrime(sieve,N)): print(N) break else : N+=1 if __name__=='__main__' : N=379 findSpecialPrime(N) N=100 findSpecialPrime(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( N := 379 ; findSpecialPrime(N) ; N := 100 ; findSpecialPrime(N) ) else skip; operation checkSpecialPrime(sieve : OclAny, num : OclAny) : OclAny pre: true post: true activity: while (num) do ( if (sieve[num+1] = false) then ( return false ) else skip ; num := ("" + ((num / 10)))->toInteger()) ; return true; operation findSpecialPrime(N : OclAny) pre: true post: true activity: sieve := Integer.subrange(0, N * 10 + 1-1)->select(i | true)->collect(i | (true)) ; sieve->first() := false ; sieve[1+1] := false ; for i : Integer.subrange(2, N * 10 + 1-1) do ( if (sieve[i+1]) then ( for j : Integer.subrange(i * i, N * 10 + 1-1)->select( $x | ($x - i * i) mod i = 0 ) do ( sieve[j+1] := false) ) else skip) ; while (true) do ( if (checkSpecialPrime(sieve, N)) then ( execute (N)->display() ; break ) else ( N := N + 1 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import log2 def main(): t=int(input()) allAns=[] MOD=10**9+7 for _ in range(t): n,p=readIntArr() a=readIntArr() if p==1 : if n % 2==1 : ans=1 else : ans=0 else : a.sort(reverse=True) totalMOD=0 totalExact=0 prevPow=a[0] i=0 while ilog2(n): while i0 : totalExact*=(p**(prevPow-x)) prevPow=x if totalExact==0 : totalMOD+=pow(p,x,MOD) totalMOD %=MOD totalExact+=1 else : totalMOD-=pow(p,x,MOD) totalMOD=(totalMOD+MOD)% MOD totalExact-=1 i+=1 ans=totalMOD allAns.append(ans) multiLineArrayPrint(allAns) return import sys input=sys.stdin.buffer.readline def oneLineArrayPrint(arr): print(' '.join([str(x)for x in arr])) def multiLineArrayPrint(arr): print('\n'.join([str(x)for x in arr])) def multiLineArrayOfArraysPrint(arr): print('\n'.join([' '.join([str(x)for x in y])for y in arr])) def readIntArr(): return[int(x)for x in input().split()] main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := sys.stdin.buffer.readline ; skip ; skip ; skip ; skip ; main(); operation main() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var allAns : Sequence := Sequence{} ; var MOD : double := (10)->pow(9) + 7 ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := readIntArr() ; var a : OclAny := readIntArr() ; if p = 1 then ( if n mod 2 = 1 then ( var ans : int := 1 ) else ( ans := 0 ) ) else ( a := a->sort() ; var totalMOD : int := 0 ; var totalExact : int := 0 ; var prevPow : OclAny := a->first() ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( var x : OclAny := a[i+1] ; if totalExact /= 0 & (log2(totalExact) + (prevPow - x) * log2(p)->compareTo(log2(n))) > 0 then ( while (i->compareTo(n)) < 0 do ( x := a[i+1] ; totalMOD := totalMOD - (p)->pow(x) ; totalMOD := (totalMOD + MOD) mod MOD ; i := i + 1) ) else ( if totalExact > 0 then ( totalExact := totalExact * ((p)->pow((prevPow - x))) ) else skip ; prevPow := x ; if totalExact = 0 then ( totalMOD := totalMOD + (p)->pow(x) ; totalMOD := totalMOD mod MOD ; totalExact := totalExact + 1 ) else ( totalMOD := totalMOD - (p)->pow(x) ; totalMOD := (totalMOD + MOD) mod MOD ; totalExact := totalExact - 1 ) ) ; i := i + 1) ; ans := totalMOD ) ; execute ((ans) : allAns)) ; multiLineArrayPrint(allAns) ; return; operation oneLineArrayPrint(arr : OclAny) pre: true post: true activity: execute (StringLib.sumStringsWithSeparator((arr->select(x | true)->collect(x | (("" + ((x)))))), ' '))->display(); operation multiLineArrayPrint(arr : OclAny) pre: true post: true activity: execute (StringLib.sumStringsWithSeparator((arr->select(x | true)->collect(x | (("" + ((x)))))), ' '))->display(); operation multiLineArrayOfArraysPrint(arr : OclAny) pre: true post: true activity: execute (StringLib.sumStringsWithSeparator((arr->select(y | true)->collect(y | (StringLib.sumStringsWithSeparator((y->select(x | true)->collect(x | (("" + ((x)))))), ' ')))), ' '))->display(); operation readIntArr() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binsearch(l,r,pred): assert l1 : m=(l+r)//2 if pred(m): r=m else : l=m return r import sys def pred(n): assert 1<=n and n<=10**18 print('?',n) sys.stdout.flush() return input()=='Y' def solve(): s='' s+=str(binsearch(1,9+1,lambda c : not pred(int(s+str(c))))-1) if s=='9' : f=lambda k : pred(int('1'+'0'*k)) else : f=lambda k : not pred(int('9'*k)) k=1 while f(k): k+=1 if k>=13 : return 1 if k==1 : return binsearch(1,9+1,lambda c : pred(int(str(c)+'0'))) else : for _ in range(k-2): s+=str(binsearch(0,9+1,lambda c : not pred(int(s+str(c))))-1) s+=str(binsearch(0,9+1,lambda c : pred(int(s+str(c)+'0')))) return int(s) print('!',solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; execute ('!')->display(); operation binsearch(l : OclAny, r : OclAny, pred : OclAny) : OclAny pre: true post: true activity: assert (l->compareTo(r)) < 0 do "assertion failed" ; l := l - 1 ; while r - l > 1 do ( var m : int := (l + r) div 2 ; if pred(m) then ( r := m ) else ( l := m )) ; return r; operation pred(n : OclAny) : OclAny pre: true post: true activity: assert 1 <= n & (n->compareTo((10)->pow(18))) <= 0 do "assertion failed" ; execute ('?')->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))) ; return (OclFile["System.in"]).readLine() = 'Y'; operation solve() : OclAny pre: true post: true activity: var s : String := '' ; s := s + ("" + ((binsearch(1, 9 + 1, lambda c : OclAny in (not(pred(("" + ((s + ("" + ((c))))))->toInteger())))) - 1))) ; if s = '9' then ( var f : Function := lambda k : OclAny in (pred(("" + (('1' + StringLib.nCopies('0', k))))->toInteger())) ) else ( f := lambda k : OclAny in (not(pred(("" + ((StringLib.nCopies('9', k))))->toInteger()))) ) ; var k : int := 1 ; while f->apply(k) do ( k := k + 1 ; if k >= 13 then ( return 1 ) else skip) ; if k = 1 then ( return binsearch(1, 9 + 1, lambda c : OclAny in (pred(("" + ((("" + ((c))) + '0')))->toInteger()))) ) else ( for _anon : Integer.subrange(0, k - 2-1) do ( s := s + ("" + ((binsearch(0, 9 + 1, lambda c : OclAny in (not(pred(("" + ((s + ("" + ((c))))))->toInteger())))) - 1)))) ; s := s + ("" + ((binsearch(0, 9 + 1, lambda c : OclAny in (pred(("" + ((s + ("" + ((c))) + '0')))->toInteger())))))) ) ; return ("" + ((s)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() I=input n=int(I()) r=list(tuple(map(int,I().split()))for _ in '0'*n) s=set(r) d=set() for a in s : for b in s : y=1 for i in 0,1,2 : y=y and a[i]toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var I : OclAny := input ; var n : int := ("" + ((I())))->toInteger() ; var r : Sequence := ((argument (test (logical_test (comparison (expr (atom (name tuple)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name I)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (expr (atom '0')) * (expr (atom (name n))))))))) ; var s : Set := Set{}->union((r)) ; var d : Set := Set{}->union(()) ; for a : s do ((compound_stmt for (exprlist (expr (atom (name b)))) in (testlist (test (logical_test (comparison (expr (atom (name s))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name y)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))) , (test (logical_test (comparison (expr (atom (number (integer 1))))))) , (test (logical_test (comparison (expr (atom (number (integer 2)))))))) : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name y)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (logical_test (comparison (expr (atom (name y))))) and (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) < (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name y)))))) : (suite (simple_stmt (small_stmt break)))))) (else_clause else : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))))))))))))) ; execute (1 + r->indexOf(sorted(d, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))))))->first()) - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for k in range(1,10): print('?',10**k,flush=True) if input()=='N' : i=10**(k-1)+1 j=10**k-1 while icompareTo(right)) < 0 do ( var mid : double := (left + right) / 2 ; ans[i+1] := mid ; if check(ans, i) then ( left := mid ) else ( right := mid )) ; if i = dig - 1 then ( ans[i+1] := left + 1 ) else ( ans[i+1] := left )) ; var num : int := ("" + ((StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), ""))))->toInteger() ; answer(num); operation query(n : OclAny) : OclAny pre: true post: true activity: write(StringLib.format("? %d\n",n)) ; flush() ; return readline()->trim() = 'Y'; operation answer(n : OclAny) pre: true post: true activity: write(StringLib.format("! %d\n",n)) ; flush(); operation check(ans : OclAny, i : OclAny) : OclAny pre: true post: true activity: if i = dig - 1 then ( return not(query(("" + ((StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), ""))))->toInteger() * 10)) ) else skip ; return query(("" + ((StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), ""))))->toInteger()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def query(val): print('?',val) ans=input() if ans=='Y' : return True return False LIMIT=10**9 import sys if __name__=="__main__" : if(query(LIMIT)): res=1 while(True): if(query(2*res)): print('!',res) sys.exit() res*=10 digit=10 res=LIMIT while(True): if(query(res)): break res=res//10 digit-=1 query=10**(digit) keta=0 while(keta1): med=(right+left)//2 if keta==0 and med==0 : left=med continue val1=list(str(low)) val1[keta]=str(med) val1=int("".join(val1)) print("? %d" %(val1)) ans=input() if(ans=="Y"): if(keta==digit-1): query=val1 right=med continue else : if(ketapow(9) ; skip ; if __name__ = "__main__" then ( if (query(LIMIT)) then ( var res : int := 1 ; while (true) do ( if (query(2 * res)) then ( execute ('!')->display() ; sys.exit() ) else skip ; res := res * 10) ) else skip ; var digit : int := 10 ; res := LIMIT ; while (true) do ( if (query(res)) then ( break ) else skip ; res := res div 10 ; digit := digit - 1) ; var query : double := (10)->pow((digit)) ; var keta : int := 0 ; while ((keta->compareTo(digit)) < 0) do ( var low : OclAny := query ; var high : double := query * 10 ; var left : int := 0 ; var right : int := 10 ; while (right - left > 1) do ( var med : int := (right + left) div 2 ; if keta = 0 & med = 0 then ( left := med ; continue ) else skip ; var val1 : Sequence := (("" + ((low))))->characters() ; val1[keta+1] := ("" + ((med))) ; val1 := ("" + ((StringLib.sumStringsWithSeparator((val1), ""))))->toInteger() ; execute (StringLib.format("? %d",(val1)))->display() ; ans := (OclFile["System.in"]).readLine() ; if (ans = "Y") then ( if (keta = digit - 1) then ( query := val1 ) else skip ; right := med ; continue ) else ( if ((keta->compareTo(digit - 1)) < 0) then ( query := val1 ) else skip ; left := med ; continue )) ; keta := keta + 1) ; query := query div 10 ; execute (StringLib.format("! %d",(query)))->display() ) else skip; operation query(val : OclAny) : OclAny pre: true post: true activity: execute ('?')->display() ; var ans : String := (OclFile["System.in"]).readLine() ; if ans = 'Y' then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys ans=None for idx in range(0,11,1): print('? 1'+'0'*idx) sys.stdout.flush() kekka=input() if kekka=='N' : digits=idx break else : for idx in range(1,11,1): print('? '+'9'*idx) sys.stdout.flush() kekka=input() if kekka=='Y' : c=idx-1 break ans='! 1'+'0'*c if ans==None : kagen=10**(digits-1) jogen=10**(digits)-1 while jogen-kagen>1 : miru=(jogen+kagen)//2 print('? '+str(miru)+'0') sys.stdout.flush() kekka=input() if kekka=='Y' : jogen=miru else : kagen=miru ans='! '+str(jogen) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var ans : OclAny := null ; (compound_stmt for (exprlist (expr (atom (name idx)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 11)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom '? 1')) + (expr (expr (atom '0')) * (expr (atom (name idx)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name kekka)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name kekka)))) == (comparison (expr (atom 'N')))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name digits)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name idx)))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt for (exprlist (expr (atom (name idx)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 11)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom '? ')) + (expr (expr (atom '9')) * (expr (atom (name idx)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name kekka)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name kekka)))) == (comparison (expr (atom 'Y')))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name idx))) - (expr (atom (number (integer 1)))))))))))))) (stmt (simple_stmt (small_stmt break))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom '! 1')) + (expr (expr (atom '0')) * (expr (atom (name c))))))))))))))))) ; if ans = null then ( var kagen : double := (10)->pow((digits - 1)) ; var jogen : double := (10)->pow((digits)) - 1 ; while jogen - kagen > 1 do ( var miru : int := (jogen + kagen) div 2 ; execute ('? ' + ("" + ((miru))) + '0')->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))) ; var kekka : String := (OclFile["System.in"]).readLine() ; if kekka = 'Y' then ( jogen := miru ) else ( kagen := miru )) ; ans := '! ' + ("" + ((jogen))) ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countWaysToJump(arr,n): count_jump=[0 for i in range(n)] for i in range(n-2,-1,-1): if(arr[i]>=n-i-1): count_jump[i]+=1 j=i+1 while(junion(Sequence{3}->union(Sequence{5}->union(Sequence{8}->union(Sequence{9}->union(Sequence{1}->union(Sequence{0}->union(Sequence{7}->union(Sequence{6}->union(Sequence{8}->union(Sequence{ 9 })))))))))) ; n := (arr)->size() ; countWaysToJump(arr, n); operation countWaysToJump(arr : OclAny, n : OclAny) pre: true post: true activity: var count_jump : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( if ((arr[i+1]->compareTo(n - i - 1)) >= 0) then ( count_jump[i+1] := count_jump[i+1] + 1 ) else skip ; var j : OclAny := i + 1 ; while ((j->compareTo(n - 1)) < 0 & (j->compareTo(arr[i+1] + i)) <= 0) do ( if (count_jump[j+1] /= -1) then ( count_jump[i+1] := count_jump[i+1] + count_jump[j+1] ) else skip ; j := j + 1) ; if (count_jump[i+1] = 0) then ( count_jump[i+1] := -1 ) else skip) ; for i : Integer.subrange(0, n-1) do ( execute (count_jump[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def checkPolygonWithMidpoints(arr,N,midpoints): for j in range(midpoints): val=1 for k in range(j,N,midpoints): val &=arr[k] if(val and N//midpoints>2): print("Polygon possible with side length",(N//midpoints)) return True return False def isPolygonPossible(arr,N): limit=sqrt(N) for i in range(1,int(limit)+1): if(N % i==0): if(checkPolygonWithMidpoints(arr,N,i)or checkPolygonWithMidpoints(arr,N,(N//i))): return print("Not possiblen") if __name__=="__main__" : arr=[1,0,1,0,1,0,1,0,1,1] N=len(arr) isPolygonPossible(arr,N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 1 }))))))))) ; N := (arr)->size() ; isPolygonPossible(arr, N) ) else skip; operation checkPolygonWithMidpoints(arr : OclAny, N : OclAny, midpoints : OclAny) : OclAny pre: true post: true activity: for j : Integer.subrange(0, midpoints-1) do ( var val : int := 1 ; for k : Integer.subrange(j, N-1)->select( $x | ($x - j) mod midpoints = 0 ) do ( val := val & arr[k+1]) ; if (val & N div midpoints > 2) then ( execute ("Polygon possible with side length")->display() ; return true ) else skip) ; return false; operation isPolygonPossible(arr : OclAny, N : OclAny) pre: true post: true activity: var limit : OclAny := sqrt(N) ; for i : Integer.subrange(1, ("" + ((limit)))->toInteger() + 1-1) do ( if (N mod i = 0) then ( if (checkPolygonWithMidpoints(arr, N, i) or checkPolygonWithMidpoints(arr, N, (N div i))) then ( return ) else skip ) else skip) ; execute ("Not possiblen")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : N=int(input()) if N==0 : break S=[] for i in range(N): S.append(int(input())) print((sum(S)-max(S)-min(S))//(N-2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var S : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : S)) ; execute (((S)->sum() - (S)->max() - (S)->min()) div (N - 2))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def circle(x1,y1,x2,y2,r1,r2): distSq=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2); radSumSq=(r1+r2)*(r1+r2); if(distSq==radSumSq): return 1 elif(distSq>radSumSq): return-1 else : return 0 x1=-10 y1=8 x2=14 y2=-24 r1=30 r2=10 t=circle(x1,y1,x2,y2,r1,r2) if(t==1): print("Circle touch to each other.") elif(t<0): print("Circle not touch to each other.") else : print("Circle intersect to each other.") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x1 := -10 ; y1 := 8 ; x2 := 14 ; y2 := -24 ; r1 := 30 ; r2 := 10 ; var t : OclAny := circle(x1, y1, x2, y2, r1, r2) ; if (t = 1) then ( execute ("Circle touch to each other.")->display() ) else (if (t < 0) then ( execute ("Circle not touch to each other.")->display() ) else ( execute ("Circle intersect to each other.")->display() ) ) ; operation circle(x1 : OclAny, y1 : OclAny, x2 : OclAny, y2 : OclAny, r1 : OclAny, r2 : OclAny) : OclAny pre: true post: true activity: var distSq : double := (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); ; var radSumSq : double := (r1 + r2) * (r1 + r2); ; if (distSq = radSumSq) then ( return 1 ) else (if ((distSq->compareTo(radSumSq)) > 0) then ( return -1 ) else ( return 0 ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def print1(n,k): for i in range(0,n): print("\n") for j in range(0,(3*k+2)): if((i==0 and j!=k and j!=2*k+1)or((i==math.floor(n/2))and(j>1)and(j!=k)and(j!=2*k+1)and(j!=2*k+3))or((i==n-1)and(j!=k)and((j<=k)or(j>2*k+1)))or(j==0)or(j==k+1)or(j==(2*k+2))or((j==k-1 or j==3*k+1)and(i>math.floor(n/2)))): print("*",end="") else : print("",end="") n=7 k=5 print1(n,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 7 ; k := 5 ; print1(n, k); operation print1(n : OclAny, k : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute ("\n")->display() ; for j : Integer.subrange(0, (3 * k + 2)-1) do ( if ((i = 0 & j /= k & j /= 2 * k + 1) or ((i = (n / 2)->floor()) & (j > 1) & (j /= k) & (j /= 2 * k + 1) & (j /= 2 * k + 3)) or ((i = n - 1) & (j /= k) & (((j->compareTo(k)) <= 0) or ((j->compareTo(2 * k + 1)) > 0))) or (j = 0) or (j = k + 1) or (j = (2 * k + 2)) or ((j = k - 1 or j = 3 * k + 1) & ((i->compareTo((n / 2)->floor())) > 0))) then ( execute ("*")->display() ) else ( execute ("")->display() ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=map(int,input().split()) s=input() pp,ap=s.split('.') pp=list(map(int,pp)) for i,c in enumerate(map(int,ap)): if c>=5 : break t-=1 rnd=len(ap) if c>=5 : rnd=i-1 while t>0 and rnd>=0 and int(ap[rnd])+1>=5 : rnd-=1 t-=1 if rnd==-1 : i=len(pp)-1 while i>=0 : pp[i]+=1 if pp[i]>9 : pp[i]-=10 i-=1 else : break if i<0 : pp.insert(0,1) ap=list(map(int,ap)) if 0<=rnd=0 : print("".join(map(str,pp)),".","".join(map(str,ap[: rnd+1])),sep="") else : print("".join(map(str,pp))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var pp : OclAny := null; var ap : OclAny := null; Sequence{pp,ap} := s.split('.') ; var pp : Sequence := ((pp)->collect( _x | (OclType["int"])->apply(_x) )) ; for _tuple : Integer.subrange(1, ((ap)->collect( _x | (OclType["int"])->apply(_x) ))->size())->collect( _indx | Sequence{_indx-1, ((ap)->collect( _x | (OclType["int"])->apply(_x) ))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if c >= 5 then ( break ) else skip) ; t := t - 1 ; var rnd : int := (ap)->size() ; if c >= 5 then ( rnd := i - 1 ; while t > 0 & rnd >= 0 & ("" + ((ap[rnd+1])))->toInteger() + 1 >= 5 do ( rnd := rnd - 1 ; t := t - 1) ) else skip ; if rnd = -1 then ( var i : double := (pp)->size() - 1 ; while i >= 0 do ( pp[i+1] := pp[i+1] + 1 ; if pp[i+1] > 9 then ( pp[i+1] := pp[i+1] - 10 ; i := i - 1 ) else ( break )) ; if i < 0 then ( pp := pp.insertAt(0+1, 1) ) else skip ) else skip ; var ap : Sequence := ((ap)->collect( _x | (OclType["int"])->apply(_x) )) ; if 0 <= rnd & (rnd < (ap)->size()) then ( ap[rnd+1] := ap[rnd+1] + 1 ) else skip ; if rnd >= 0 then ( execute (StringLib.sumStringsWithSeparator(((pp)->collect( _x | (OclType["String"])->apply(_x) )), ""))->display() ) else ( execute (StringLib.sumStringsWithSeparator(((pp)->collect( _x | (OclType["String"])->apply(_x) )), ""))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) l=[]; ans=1001 for _ in range(t): s1,r1,h1,c1=map(int,input().split()) l1=[s1,r1,h1,c1] l.append(l1) for i in range(t): for j in range(t): if l[i][0]toInteger() ; var l : Sequence := Sequence{}; var ans : int := 1001 ; for _anon : Integer.subrange(0, t-1) do ( var s1 : OclAny := null; var r1 : OclAny := null; var h1 : OclAny := null; var c1 : OclAny := null; Sequence{s1,r1,h1,c1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l1 : Sequence := Sequence{s1}->union(Sequence{r1}->union(Sequence{h1}->union(Sequence{ c1 }))) ; execute ((l1) : l)) ; for i : Integer.subrange(0, t-1) do ((compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (logical_test (comparison (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) < (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))) and (logical_test (comparison (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) < (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))) and (logical_test (comparison (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))) < (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 3))))))))) ])))) < (comparison (expr (atom (name ans))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 3))))))))) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger())))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))))))))))))))) ; execute (ansans(ans(ans(ansans(ans(ans(ansans(ans(ans(ansans(ans(ans(ansans(ans(ans(ansans(ans(ans(ansans(ans(ans var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger())))->display())))->display())))->display())))->display())))->display())))->display())))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import* input=stdin.readline n,t=map(int,input().split()) num=input() idx=num.find(".") if idx<0 : print(num) exit() cnt=1 for i in range(idx+1,n): if num[i]<"5" : if 5-int(num[i])==1 : cnt+=1 else : cnt=1 if num[i]>="5" : j=min(cnt,t) if num[i-j]!="." : num=num[: i-j]+str(int(num[i-j])+1) else : curr=0 while num[idx-curr-1]=="9" and(idx-curr)!=0 : curr+=1 num=num[: idx-curr-1]+str(int(num[idx-curr-1])+1)+"0"*curr if curr!=idx else "1"+"0"*curr break print(num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var num : String := (OclFile["System.in"]).readLine() ; var idx : int := num->indexOf(".") - 1 ; if idx < 0 then ( execute (num)->display() ; exit() ) else skip ; var cnt : int := 1 ; for i : Integer.subrange(idx + 1, n-1) do ( if num[i+1] < "5" then ( if 5 - ("" + ((num[i+1])))->toInteger() = 1 then ( cnt := cnt + 1 ) else ( cnt := 1 ) ) else skip ; if num[i+1] >= "5" then ( var j : OclAny := Set{cnt, t}->min() ; if num[i - j+1] /= "." then ( num := num.subrange(1,i - j) + ("" + ((("" + ((num[i - j+1])))->toInteger() + 1))) ) else ( var curr : int := 0 ; while num[idx - curr - 1+1] = "9" & (idx - curr) /= 0 do ( curr := curr + 1) ; num := if curr /= idx then num.subrange(1,idx - curr - 1) + ("" + ((("" + ((num[idx - curr - 1+1])))->toInteger() + 1))) + StringLib.nCopies("0", curr) else "1" + StringLib.nCopies("0", curr) endif ) ; break ) else skip) ; execute (num)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=map(int,input().split()) num=input() idx=num.index(".") cnt=1 for i in range(idx+1,n): if num[i]<"5" : if 5-int(num[i])==1 : cnt+=1 else : cnt=1 if num[i]>="5" : j=min(cnt,t) if num[i-j]!="." : num=num[: i-j]+str(int(num[i-j])+1) else : curr=0 while num[idx-curr-1]=="9" and(idx-curr)!=0 : curr+=1 num=num[: idx-curr-1]+str(int(num[idx-curr-1])+1)+"0"*curr if curr!=idx else "1"+"0"*curr break print(num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var num : String := (OclFile["System.in"]).readLine() ; var idx : int := num->indexOf(".") - 1 ; var cnt : int := 1 ; for i : Integer.subrange(idx + 1, n-1) do ( if num[i+1] < "5" then ( if 5 - ("" + ((num[i+1])))->toInteger() = 1 then ( cnt := cnt + 1 ) else ( cnt := 1 ) ) else skip ; if num[i+1] >= "5" then ( var j : OclAny := Set{cnt, t}->min() ; if num[i - j+1] /= "." then ( num := num.subrange(1,i - j) + ("" + ((("" + ((num[i - j+1])))->toInteger() + 1))) ) else ( var curr : int := 0 ; while num[idx - curr - 1+1] = "9" & (idx - curr) /= 0 do ( curr := curr + 1) ; num := if curr /= idx then num.subrange(1,idx - curr - 1) + ("" + ((("" + ((num[idx - curr - 1+1])))->toInteger() + 1))) + StringLib.nCopies("0", curr) else "1" + StringLib.nCopies("0", curr) endif ) ; break ) else skip) ; execute (num)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=map(int,input().split()) s='0'+input() f=s.find('.') if f==-1 : print(s[1 :]) exit() r=list(s[: f]+s[f+1 :]) for i in range(f,len(r)): execute=False while r[i]>='5' and r[i]<='9' : if icollect( _x | (OclType["int"])->apply(_x) ) ; var s : String := '0' + (OclFile["System.in"]).readLine() ; var f : int := s->indexOf('.') - 1 ; if f = -1 then ( execute (s->tail())->display() ; exit() ) else skip ; var r : Sequence := (s.subrange(1,f) + s.subrange(f + 1+1)) ; for i : Integer.subrange(f, (r)->size()-1) do ( var execute : boolean := false ; while r[i+1] >= '5' & r[i+1] <= '9' do ( if (i->compareTo(f)) < 0 or t <= 0 then ( break ) else skip ; i := i - 1 ; var z : int := (r[i+1])->char2byte() + 1 ; while z = ("9")->char2byte() + 1 do ( i := i - 1 ; z := (r[i+1])->char2byte() + 1) ; while (r)->size() /= i + 1 do ( r := r->front()) ; r->last() := (z)->byte2char() ; t := t - 1 ; execute := true) ; if execute then ( break ) else skip) ; if r->first() = '0' then ( r := r->tail() ; f := f - 1 ) else skip ; r := r + MatrixLib.elementwiseMult(Sequence{ '0' }, Set{f - (r)->size(), 0}->max()) ; if (r)->size() = f then ( execute (StringLib.sumStringsWithSeparator(((r)->collect( _x | (OclType["String"])->apply(_x) )), ''))->display() ) else ( execute ((argument * (test (logical_test (comparison (expr (atom (name r)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name f)))))))) ]))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (n,t)=map(int,input().split()) x=input() i=x.find('.') for j in range(i+1,n): if x[j]>'4' : for k in range(t): j-=1 if x[j]!='4' : break if j==i : j-=1 while j and x[j]=='9' : j-=1 x=x[: j]+str(int(x[j])+1)+'0'*(i-j-1) else : x=x[: j]+str(int(x[j])+1) break print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{n, t} : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : String := (OclFile["System.in"]).readLine() ; var i : int := x->indexOf('.') - 1 ; for j : Integer.subrange(i + 1, n-1) do ( if x[j+1] > '4' then ( for k : Integer.subrange(0, t-1) do ( j := j - 1 ; if x[j+1] /= '4' then ( break ) else skip) ; if j = i then ( j := j - 1 ; while j & x[j+1] = '9' do ( j := j - 1) ; x := x.subrange(1,j) + ("" + ((("" + ((x[j+1])))->toInteger() + 1))) + StringLib.nCopies('0', (i - j - 1)) ) else ( x := x.subrange(1,j) + ("" + ((("" + ((x[j+1])))->toInteger() + 1))) ) ; break ) else skip) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys rd=sys.stdin.readline n=int(rd()) popdic={} for _ in range(n): name1,temp,name2=rd().strip().split() name1=name1.lower() name2=name2.lower() if popdic.get(name2): popdic[name1]=popdic[name2]+1 else : popdic[name2]=1 popdic[name1]=2 print(max(popdic.values())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var rd : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + ((rd())))->toInteger() ; var popdic : OclAny := Set{} ; for _anon : Integer.subrange(0, n-1) do ( var name1 : OclAny := null; var temp : OclAny := null; var name2 : OclAny := null; Sequence{name1,temp,name2} := rd()->trim().split() ; var name1 : String := name1->toLowerCase() ; var name2 : String := name2->toLowerCase() ; if popdic.get(name2) then ( popdic->at(name1) := popdic->at(name2) + 1 ) else ( popdic->at(name2) := 1 ; popdic->at(name1) := 2 )) ; execute ((popdic.values())->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d={} f=[i for i in range(501)] c=1 for _ in range(int(input())): a,temp,b=input().split() a=a.lower() b=b.lower() if a not in d : d[a]=c c+=1 if b not in d : d[b]=c c+=1 x=d[a] y=d[b] f[x]=y i=1 fans=0 while(i<=500): ans=1 j=i while(j!=f[j]): j=f[j] ans+=1 fans=max(ans,fans) i+=1 print(fans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : OclAny := Set{} ; var f : Sequence := Integer.subrange(0, 501-1)->select(i | true)->collect(i | (i)) ; var c : int := 1 ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var temp : OclAny := null; var b : OclAny := null; Sequence{a,temp,b} := input().split() ; var a : String := a->toLowerCase() ; var b : String := b->toLowerCase() ; if (d)->excludes(a) then ( d->at(a) := c ; c := c + 1 ) else skip ; if (d)->excludes(b) then ( d->at(b) := c ; c := c + 1 ) else skip ; var x : OclAny := d->at(a) ; var y : OclAny := d->at(b) ; f[x+1] := y) ; var i : int := 1 ; var fans : int := 0 ; while (i <= 500) do ( var ans : int := 1 ; var j : int := i ; while (j /= f[j+1]) do ( j := f[j+1] ; ans := ans + 1) ; fans := Set{ans, fans}->max() ; i := i + 1) ; execute (fans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution : def solve(self,reposts,n): lookup={'polycarp' : 1} for repost in reposts : name1,_,name2=repost.split(" ") lookup[name1]=1+lookup[name2] print(max(lookup.values())) return def main(): t=1 sol=Solution() while t : n=int(input()) reposts=[] for _ in range(n): reposts.append(input().lower()) sol.solve(reposts,n) t-=1 if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class Solution { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation solve(reposts : OclAny,n : OclAny) pre: true post: true activity: var lookup : Map := Map{ 'polycarp' |-> 1 } ; for repost : reposts do ( var name1 : OclAny := null; var _anon : OclAny := null; var name2 : OclAny := null; Sequence{name1,_anon,name2} := repost.split(" ") ; lookup[name1+1] := 1 + lookup[name2+1]) ; execute ((lookup.values())->max())->display() ; return; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var t : int := 1 ; var sol : Solution := (Solution.newSolution()).initialise() ; while t do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; reposts := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((input()->toLowerCase()) : reposts)) ; sol.solve(reposts, n) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import copy def average(points): sum=0 for i in points : sum+=i return sum/len(points) outputs=[] while True : num=int(input()) if num==0 : break points=[] for _ in range(num): point=int(input()) points.append(point) points=sorted(points) points=points[1 : len(points)-1] ave=average(points) outputs.append(int(ave)) for ave in outputs : print(ave) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var outputs : Sequence := Sequence{} ; while true do ( var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if num = 0 then ( break ) else skip ; points := Sequence{} ; for _anon : Integer.subrange(0, num-1) do ( var point : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((point) : points)) ; points := points->sort() ; points := points.subrange(1+1, (points)->size() - 1) ; var ave : OclAny := average(points) ; execute ((("" + ((ave)))->toInteger()) : outputs)) ; for ave : outputs do ( execute (ave)->display()); operation average(points : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : points do ( sum := sum + i) ; return sum / (points)->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input().split() d={} d[s[2].lower()]=1 d[s[0].lower()]=2 ans=2 for i in range(n-1): s=input().split() d[s[0].lower()]=d[s[2].lower()]+1 ans=max(ans,d[s[0].lower()]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := input().split() ; var d : OclAny := Set{} ; d[s[2+1]->toLowerCase()+1] := 1 ; d[s->first()->toLowerCase()+1] := 2 ; var ans : int := 2 ; for i : Integer.subrange(0, n - 1-1) do ( s := input().split() ; d[s->first()->toLowerCase()+1] := d[s[2+1]->toLowerCase()+1] + 1 ; ans := Set{ans, d[s->first()->toLowerCase()+1]}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) w={} w['polycarp']=1 a=[] for i in range(x): y=input().split() y[0]=y[0].lower() y[2]=y[2].lower() w[y[0]]=w[y[2]]+1 a.append(y[0]) m=0 for i in a : if(w[i]>m): m=w[i] print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : OclAny := Set{} ; w->at('polycarp') := 1 ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, x-1) do ( var y : OclAny := input().split() ; y->first() := y->first()->toLowerCase() ; y[2+1] := y[2+1]->toLowerCase() ; w[y->first()+1] := w[y[2+1]+1] + 1 ; execute ((y->first()) : a)) ; var m : int := 0 ; for i : a do ( if ((w[i+1]->compareTo(m)) > 0) then ( m := w[i+1] ) else skip) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) speed=[0]*n ram=[0]*n hdd=[0]*n cost=[0]*n result=0 costr=math.inf for i in range(n): speed[i],ram[i],hdd[i],cost[i]=map(int,input().split()) for i in range(n): for j in range(n): if speed[i]toInteger() ; var speed : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var ram : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var hdd : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var cost : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var result : int := 0 ; var costr : OclAny := ; for i : Integer.subrange(0, n-1) do ( var speed[i+1] : OclAny := null; var ram[i+1] : OclAny := null; var hdd[i+1] : OclAny := null; var cost[i+1] : OclAny := null; Sequence{speed[i+1],ram[i+1],hdd[i+1],cost[i+1]} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ((compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (logical_test (comparison (comparison (expr (atom (name speed)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) < (comparison (expr (atom (name speed)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))) and (logical_test (comparison (comparison (expr (atom (name ram)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) < (comparison (expr (atom (name ram)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))) and (logical_test (comparison (comparison (expr (atom (name hdd)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) < (comparison (expr (atom (name hdd)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name cost)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) < (comparison (expr (atom (name costr))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name costr)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cost)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name result)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))))))))))))))) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input('')) l=list(map(int,input().split())) k=l.count(1) m=[] print(k) for i in range(1,n): if l[i]==1 : m.append(str(l[i-1])) m.append(str(l[-1])) print(' '.join(m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k : int := l->count(1) ; var m : Sequence := Sequence{} ; execute (k)->display() ; for i : Integer.subrange(1, n-1) do ( if l[i+1] = 1 then ( execute ((("" + ((l[i - 1+1])))) : m) ) else skip) ; execute ((("" + ((l->last())))) : m) ; execute (StringLib.sumStringsWithSeparator((m), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) x=[] for i in range(1,n): if l[i]==1 : x.append(l[i-1]) x.append(l[-1]) print(len(x)) print(' '.join(map(str,x))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : Sequence := Sequence{} ; for i : Integer.subrange(1, n-1) do ( if l[i+1] = 1 then ( execute ((l[i - 1+1]) : x) ) else skip) ; execute ((l->last()) : x) ; execute ((x)->size())->display() ; execute (StringLib.sumStringsWithSeparator(((x)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[i for i in input().split()] res=0 lis=[] temp=0 i=n while i>0 : i-=1 temp+=1 if a[i]=='1' : res+=1 lis.append(temp) temp=0 print(res) print(*reversed(lis)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (i)) ; var res : int := 0 ; var lis : Sequence := Sequence{} ; var temp : int := 0 ; var i : int := n ; while i > 0 do ( i := i - 1 ; temp := temp + 1 ; if a[i+1] = '1' then ( res := res + 1 ; execute ((temp) : lis) ; temp := 0 ) else skip) ; execute (res)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name reversed)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name lis)))))))) )))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) print(l.count(1)) for i in range(1,n): if l[i]==1 : print(l[i-1],'',end="") print(l[n-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (l->count(1))->display() ; for i : Integer.subrange(1, n-1) do ( if l[i+1] = 1 then ( execute (l[i - 1+1])->display() ) else skip) ; execute (l[n - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a=int(input()),(int(i)for i in input().split()) res,prev=[],0 for i,e in enumerate(a): if i>0 and e==1 : res.append(i-prev) prev=i res.append(n-prev) print(len(res)) print(*res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))}} ; var res : OclAny := null; var prev : OclAny := null; Sequence{res,prev} := Sequence{Sequence{},0} ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var e : OclAny := _tuple->at(_indx); if i > 0 & e = 1 then ( execute ((i - prev) : res) ; var prev : OclAny := i ) else skip) ; execute ((n - prev) : res) ; execute ((res)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def lcm(x,y): return(x*y)//math.gcd(x,y) a,b,c,d=map(int,input().split()) e=lcm(c,d) n=(b//c)-((a-1)//c) m=(b//d)-((a-1)//d) o=(b//e)-((a-1)//e) print(b-a+1-n-m+o) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var e : OclAny := lcm(c, d) ; var n : double := (b div c) - ((a - 1) div c) ; var m : double := (b div d) - ((a - 1) div d) ; var o : double := (b div e) - ((a - 1) div e) ; execute (b - a + 1 - n - m + o)->display(); operation lcm(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return (x * y) div (x)->gcd(y); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B,C,D=map(int,input().split()) cnt=B-A+1 import fractions E=C*D//fractions.gcd(C,D) A_C=A//C A_dC=A % C B_C=B//C A_D=A//D A_dD=A % D B_D=B//D A_E=A//E A_dE=A % E B_E=B//E C_cnt=B_C-A_C if A_dC==0 : C_cnt+=1 D_cnt=B_D-A_D if A_dD==0 : D_cnt+=1 E_cnt=B_E-A_E if A_dE==0 : E_cnt+=1 ans=cnt-C_cnt-D_cnt+E_cnt print(int(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var D : OclAny := null; Sequence{A,B,C,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cnt : double := B - A + 1 ; skip ; var E : int := C * D div fractions.gcd(C, D) ; var A_C : int := A div C ; var A_dC : int := A mod C ; var B_C : int := B div C ; var A_D : int := A div D ; var A_dD : int := A mod D ; var B_D : int := B div D ; var A_E : int := A div E ; var A_dE : int := A mod E ; var B_E : int := B div E ; var C_cnt : double := B_C - A_C ; if A_dC = 0 then ( C_cnt := C_cnt + 1 ) else skip ; var D_cnt : double := B_D - A_D ; if A_dD = 0 then ( D_cnt := D_cnt + 1 ) else skip ; var E_cnt : double := B_E - A_E ; if A_dE = 0 then ( E_cnt := E_cnt + 1 ) else skip ; var ans : double := cnt - C_cnt - D_cnt + E_cnt ; execute (("" + ((ans)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from fractions import gcd from decimal import* getcontext().prec=56 def lcm(x,y): a=Decimal(max(x,y))/Decimal(gcd(x,y)) b=Decimal(min(x,y))*Decimal(a) return b//1 a,b,c,d=map(Decimal,input().split()) div_c_min=math.ceil(a/c)*c div_c_max=math.floor(b/c)*c if div_c_max>=div_c_min : div_c_cnt=(div_c_max-div_c_min)/c+1 else : div_c_cnt=0 div_d_min=math.ceil(a/d)*d div_d_max=math.floor(b/d)*d if div_d_max>=div_d_min : div_d_cnt=(div_d_max-div_d_min)/d+1 else : div_d_cnt=0 lcm_cd=lcm(c,d) div_cd_min=math.ceil(a/lcm_cd)*lcm_cd div_cd_max=math.floor(b/lcm_cd)*lcm_cd if div_cd_max>=div_cd_min : div_cd_cnt=(div_cd_max-div_cd_min)/lcm_cd+1 else : div_cd_cnt=0 print(int(b-a+1-(div_c_cnt+div_d_cnt-div_cd_cnt))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; getcontext().prec := 56 ; skip ; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (Decimal)->apply(_x) ) ; var div_c_min : double := (a / c)->ceil() * c ; var div_c_max : double := (b / c)->floor() * c ; if (div_c_max->compareTo(div_c_min)) >= 0 then ( var div_c_cnt : double := (div_c_max - div_c_min) / c + 1 ) else ( div_c_cnt := 0 ) ; var div_d_min : double := (a / d)->ceil() * d ; var div_d_max : double := (b / d)->floor() * d ; if (div_d_max->compareTo(div_d_min)) >= 0 then ( var div_d_cnt : double := (div_d_max - div_d_min) / d + 1 ) else ( div_d_cnt := 0 ) ; var lcm_cd : OclAny := lcm(c, d) ; var div_cd_min : double := (a / lcm_cd)->ceil() * lcm_cd ; var div_cd_max : double := (b / lcm_cd)->floor() * lcm_cd ; if (div_cd_max->compareTo(div_cd_min)) >= 0 then ( var div_cd_cnt : double := (div_cd_max - div_cd_min) / lcm_cd + 1 ) else ( div_cd_cnt := 0 ) ; execute (("" + ((b - a + 1 - (div_c_cnt + div_d_cnt - div_cd_cnt))))->toInteger())->display(); operation lcm(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var a : double := Decimal(Set{x, y}->max()) / Decimal(gcd(x, y)) ; var b : double := Decimal(Set{x, y}->min()) * Decimal(a) ; return b div 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=True while f : x=raw_input() x=int(x) l=[] for i in range(x): l.append(int(raw_input())) if x==0 : f=False else : print(sum(l)-min(l)-max(l))/(len(l)-2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : boolean := true ; while f do ( var x : OclAny := raw_input() ; x := ("" + ((x)))->toInteger() ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, x-1) do ( execute ((("" + ((raw_input())))->toInteger()) : l)) ; if x = 0 then ( f := false ) else ( (expr (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)))))))) )))) - (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)))))))) ))))) - (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)))))))) )))))))))) )))) / (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)))))))) )))) - (expr (atom (number (integer 2))))))))) )))) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import fractions d=[int(x)for x in input().split()] lcm=int(d[2]*d[3]//fractions.gcd(d[2],d[3])) b=d[1]-int(d[1]//d[2])-int(d[1]//d[3])+int(d[1]//lcm) a_1=d[0]-1 a=a_1-int(a_1//d[2])-int(a_1//d[3])+int(a_1//lcm) print(b-a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var d : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var lcm : int := ("" + ((d[2+1] * d[3+1] div fractions.gcd(d[2+1], d[3+1]))))->toInteger() ; var b : double := d[1+1] - ("" + ((d[1+1] div d[2+1])))->toInteger() - ("" + ((d[1+1] div d[3+1])))->toInteger() + ("" + ((d[1+1] div lcm)))->toInteger() ; var a skip : double := d->first() - 1 ; var a : double := a skip - ("" + ((a skip div d[2+1])))->toInteger() - ("" + ((a skip div d[3+1])))->toInteger() + ("" + ((a skip div lcm)))->toInteger() ; execute (b - a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPoints(n,m,a,b,x,y): a.sort() b.sort() j,count=0,0 for i in range(0,n): while j=a[i]-x and b[j]<=a[i]+y): count+=1 j+=1 break else : j+=1 return count if __name__=="__main__" : x,y=1,4 a=[1,5] n=len(a) b=[1,1,2] m=len(b) print(countPoints(n,m,a,b,x,y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{x,y} := Sequence{1,4} ; a := Sequence{1}->union(Sequence{ 5 }) ; n := (a)->size() ; b := Sequence{1}->union(Sequence{1}->union(Sequence{ 2 })) ; m := (b)->size() ; execute (countPoints(n, m, a, b, x, y))->display() ) else skip; operation countPoints(n : OclAny, m : OclAny, a : OclAny, b : OclAny, x : OclAny, y : OclAny) : OclAny pre: true post: true activity: a := a->sort() ; b := b->sort() ; var j : OclAny := null; var count : OclAny := null; Sequence{j,count} := Sequence{0,0} ; for i : Integer.subrange(0, n-1) do ( while (j->compareTo(m)) < 0 do ( if (a[i+1] + y->compareTo(b[j+1])) < 0 then ( break ) else skip ; if ((b[j+1]->compareTo(a[i+1] - x)) >= 0 & (b[j+1]->compareTo(a[i+1] + y)) <= 0) then ( count := count + 1 ; j := j + 1 ; break ) else ( j := j + 1 ))) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline A,B,C,D=map(int,input().split()) import math def gcd(a,b): while b : a,b=b,a % b return a def lcm(x,y): return(x*y)//gcd(x,y) E=lcm(C,D) x=B-A+1 y=B//C-(A-1)//C z=B//D-(A-1)//D w=B//E-(A-1)//E print(x-y-z+w) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var D : OclAny := null; Sequence{A,B,C,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; skip ; skip ; var E : OclAny := lcm(C, D) ; x := B - A + 1 ; y := B div C - (A - 1) div C ; var z : double := B div D - (A - 1) div D ; var w : double := B div E - (A - 1) div E ; execute (x - y - z + w)->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: while b do ( Sequence{a,b} := Sequence{b,a mod b}) ; return a; operation lcm(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return (x * y) div gcd(x, y); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfDigits(n): sum=0 while(n>0): sum+=n % 10 n=int(n/10) return sum def countDigits(num,limit): left=1 right=num result=0 while(left<=right): mid=int((right+left)/2) if((mid-sumOfDigits(mid))>=limit): result=num-mid+1 right=mid-1 else : left=mid+1 return result if __name__=='__main__' : N=1546300 L=30651 print(countDigits(N,L)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var N : int := 1546300 ; var L : int := 30651 ; execute (countDigits(N, L))->display() ) else skip; operation sumOfDigits(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; while (n > 0) do ( sum := sum + n mod 10 ; n := ("" + ((n / 10)))->toInteger()) ; return sum; operation countDigits(num : OclAny, limit : OclAny) : OclAny pre: true post: true activity: var left : int := 1 ; var right : OclAny := num ; var result : int := 0 ; while ((left->compareTo(right)) <= 0) do ( var mid : int := ("" + (((right + left) / 2)))->toInteger() ; if (((mid - sumOfDigits(mid))->compareTo(limit)) >= 0) then ( result := num - mid + 1 ; right := mid - 1 ) else ( left := mid + 1 )) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math t=int(input()) while t : n=int(input()) lst=input().split() prev=int(lst[0]) maxdiff=0 for i in range(1,n): curr=int(lst[i]) maxdiff=max(maxdiff,prev-curr) prev=max(prev,curr) if maxdiff==0 : print(0) else : print(int(math.log2(maxdiff))+1) t=t-1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : OclAny := input().split() ; var prev : int := ("" + ((lst->first())))->toInteger() ; var maxdiff : int := 0 ; for i : Integer.subrange(1, n-1) do ( var curr : int := ("" + ((lst[i+1])))->toInteger() ; maxdiff := Set{maxdiff, prev - curr}->max() ; prev := Set{prev, curr}->max()) ; if maxdiff = 0 then ( execute (0)->display() ) else ( execute (("" + (()))->toInteger() + 1)->display() ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=[*map(int,input().split())] q=a[0] w=0 for i in range(1,n): w=max(w,q-a[i]) q=max(a[i],q) r=1 e=0 while w>0 : w-=r e+=1 r*=2 print(e) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var q : OclAny := a->first() ; var w : int := 0 ; for i : Integer.subrange(1, n-1) do ( w := Set{w, q - a[i+1]}->max() ; q := Set{a[i+1], q}->max()) ; var r : int := 1 ; var e : int := 0 ; while w > 0 do ( w := w - r ; e := e + 1 ; r := r * 2) ; execute (e)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def get_max_Gap(arr): mx=arr[0] mx_gap=0 for i in range(len(arr)): mx_gap=max(mx_gap,mx-arr[i]) mx=max(mx,arr[i]) return mx_gap def solution(): t=int(input()) for _ in range(t): n=int(input()) arr=list(map(int,input().split())) mx=get_max_Gap(arr) if mx!=0 : res=math.ceil(math.log2(mx+1)) print(res) else : print(0) import sys import threading sys.setrecursionlimit(1<<30) threading.stack_size(1<<27) thread=threading.Thread(target=solution) thread.start(); thread.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1 * (2->pow(30))) ; threading.stack_size(1 * (2->pow(27))) ; var thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name solution)))))))) ; thread.start(); thread.join(); operation get_max_Gap(arr : OclAny) : OclAny pre: true post: true activity: var mx : OclAny := arr->first() ; var mx_gap : int := 0 ; for i : Integer.subrange(0, (arr)->size()-1) do ( mx_gap := Set{mx_gap, mx - arr[i+1]}->max() ; mx := Set{mx, arr[i+1]}->max()) ; return mx_gap; operation solution() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; arr := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; mx := get_max_Gap(arr) ; if mx /= 0 then ( var res : double := ()->ceil() ; execute (res)->display() ) else ( execute (0)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) a=list(map(int,input().split())) d=0 mx=a[0] for i in range(1,n): if mx-a[i]>d : d=mx-a[i] if a[i]>mx : mx=a[i] ans=0 c=0 p=1 while ctoInteger() ; for i : Integer.subrange(0, t-1) do ( execute (solve())->display()); operation solve() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : int := 0 ; var mx : OclAny := a->first() ; for i : Integer.subrange(1, n-1) do ( if (mx - a[i+1]->compareTo(d)) > 0 then ( d := mx - a[i+1] ) else skip ; if (a[i+1]->compareTo(mx)) > 0 then ( mx := a[i+1] ) else skip) ; var ans : int := 0 ; var c : int := 0 ; var p : int := 1 ; while (c->compareTo(d)) < 0 do ( c := c + p ; p := p * 2 ; ans := ans + 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from sys import stdin,stdout def next_line(): return stdin.readline().rstrip() def next_int(): return int(next_line()) def out(text): stdout.write(str(text)+'\n') def main(): amount=next_int() for i in range(amount): n=next_int() arr=next_line().split() out(solve(arr,n)) def solve(arr,n): max_val=int(arr[0]) max_dif=0 for i in range(1,n): val=int(arr[i]) max_val=max(max_val,val) max_dif=max(max_dif,max_val-val) return math.ceil(math.log2(max_dif+1))if max_dif else 0 main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; main(); operation next_line() : OclAny pre: true post: true activity: return stdin.readLine().rstrip(); operation next_int() : OclAny pre: true post: true activity: return ("" + ((next_line())))->toInteger(); operation out(text : OclAny) pre: true post: true activity: stdout.write(("" + ((text))) + ' '); operation main() pre: true post: true activity: var amount : OclAny := next_int() ; for i : Integer.subrange(0, amount-1) do ( var n : OclAny := next_int() ; var arr : OclAny := next_line().split() ; out(solve(arr, n))); operation solve(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var max_val : int := ("" + ((arr->first())))->toInteger() ; var max_dif : int := 0 ; for i : Integer.subrange(1, n-1) do ( var val : int := ("" + ((arr[i+1])))->toInteger() ; max_val := Set{max_val, val}->max() ; max_dif := Set{max_dif, max_val - val}->max()) ; return if max_dif then ()->ceil() else 0 endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def resolve(): S=input() T=input() can_insert=False for start in range(len(S)-len(T),-1,-1): can_insert=True for i,c in enumerate(T): if S[start+i]!=c and S[start+i]!="?" : can_insert=False if can_insert : list_s=list(S) list_s[start : start+len(T)]=T S="".join(list_s) print(S.replace("?","a")) break if not can_insert : print("UNRESTORABLE") resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; resolve(); operation resolve() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var T : String := (OclFile["System.in"]).readLine() ; var can_insert : boolean := false ; for start : Integer.subrange(-1 + 1, (S)->size() - (T)->size())->reverse() do ( can_insert := true ; for _tuple : Integer.subrange(1, (T)->size())->collect( _indx | Sequence{_indx-1, (T)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if S[start + i+1] /= c & S[start + i+1] /= "?" then ( can_insert := false ) else skip) ; if can_insert then ( var list_s : Sequence := (S)->characters() ; list_s.subrange(start+1, start + (T)->size()) := T ; S := StringLib.sumStringsWithSeparator((list_s), "") ; execute (S.replace("?", "a"))->display() ; break ) else skip) ; if not(can_insert) then ( execute ("UNRESTORABLE")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() t=input() res='UNRESTORABLE' def check(s,t): if len(s)!=len(t): return False else : for i in range(len(s)): if s[i]!='?' and s[i]!=t[i]: return False return True flg=False for i in range(len(s)-len(t),-1,-1): L=len(t) sub=s[i : L+i] if check(sub,t): new=s[: i]+t+s[L+i :] flg=True break if flg : print(new.replace('?','a')) else : print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var res : String := 'UNRESTORABLE' ; skip ; var flg : boolean := false ; for i : Integer.subrange(-1 + 1, (s)->size() - (t)->size())->reverse() do ( var L : int := (t)->size() ; var sub : OclAny := s.subrange(i+1, L + i) ; if check(sub, t) then ( var new : OclAny := s.subrange(1,i) + t + s.subrange(L + i+1) ; flg := true ; break ) else skip) ; if flg then ( execute (new.replace('?', 'a'))->display() ) else ( execute (res)->display() ); operation check(s : OclAny, t : OclAny) : OclAny pre: true post: true activity: if (s)->size() /= (t)->size() then ( return false ) else ( for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] /= '?' & s[i+1] /= t[i+1] then ( return false ) else skip) ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def q0(): while True : data=[] n=int(input()) if n==0 : return for i in range(n): data.append(int(input())) print((sum(data)-max(data)-min(data))//(n-2)) def q1(): while True : n,r=map(int,input().split()) if n==0 : return deck=[n-i for i in range(n)] for i in range(r): p,c=map(int,input().split()) deck=deck[p-1 : p-1+c]+deck[0 : p-1]+deck[p-1+c :] print(deck[0]) question=[q0,q1] question[0]() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var question : Sequence := Sequence{q0}->union(Sequence{ q1 }) ; (expr (atom (name question)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer (arguments ( )))); operation q0() pre: true post: true activity: while true do ( var data : Sequence := Sequence{} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( return ) else skip ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : data)) ; execute (((data)->sum() - (data)->max() - (data)->min()) div (n - 2))->display()); operation q1() pre: true post: true activity: while true do ( var r : OclAny := null; Sequence{n,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( return ) else skip ; var deck : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (n - i)) ; for i : Integer.subrange(0, r-1) do ( var p : OclAny := null; var c : OclAny := null; Sequence{p,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; deck := deck.subrange(p - 1+1, p - 1 + c) + deck.subrange(0+1, p - 1) + deck.subrange(p - 1 + c+1)) ; execute (deck->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def multiplyWith3Point5(x): return(x<<1)+x+(x>>1) x=4 print(multiplyWith3Point5(x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := 4 ; execute (multiplyWith3Point5(x))->display(); operation multiplyWith3Point5(x : OclAny) : OclAny pre: true post: true activity: return (x * (2->pow(1))) + x + (x /(2->pow(1))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reverse_enumerate(l): for i,l_i in zip(range(len(l)-1,-1,-1),l): yield i,l_i def n_gram(s,n): return[s[i : i+n]for i in range(len(s)-n+1)] def is_equal_match(s1,s2,all_match=[]): for i in range(len(s1)): if not(s1[i]==s2[i]or s1[i]in all_match): return False return True def fill_in_str(text,s,n): return text[: n]+s+text[n+len(s):] s_=input() t=input() for i,s_i in reverse_enumerate(n_gram(s_,len(t))[: :-1]): if is_equal_match(s_i,t,all_match="?"): print(fill_in_str(s_,t,i).replace("?","a")) exit() print("UNRESTORABLE") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var s_ : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; for _tuple : reverse_enumerate(n_gram(s_, (t)->size())(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s_i : OclAny := _tuple->at(_indx); if is_equal_match(s_i, t, (argument (test (logical_test (comparison (expr (atom (name all_match)))))) = (test (logical_test (comparison (expr (atom "?"))))))) then ( execute (fill_in_str(s_, t, i).replace("?", "a"))->display() ; exit() ) else skip) ; execute ("UNRESTORABLE")->display(); operation reverse_enumerate(l : OclAny) pre: true post: true activity: for _tuple : Integer.subrange(1, Integer.subrange(-1 + 1, (l)->size() - 1)->reverse()->size())->collect( _indx | Sequence{Integer.subrange(-1 + 1, (l)->size() - 1)->reverse()->at(_indx), l->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var l_i : OclAny := _tuple->at(_indx); if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return i, l_i); operation n_gram(s : OclAny, n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, (s)->size() - n + 1-1)->select(i | true)->collect(i | (s.subrange(i+1, i + n))); operation is_equal_match(s1 : OclAny, s2 : OclAny, all_match : OclAny) : OclAny pre: true post: true activity: if all_match->oclIsUndefined() then all_match := Sequence{} else skip; for i : Integer.subrange(0, (s1)->size()-1) do ( if not((s1[i+1] = s2[i+1] or (all_match)->includes(s1[i+1]))) then ( return false ) else skip) ; return true; operation fill_in_str(text : OclAny, s : OclAny, n : OclAny) : OclAny pre: true post: true activity: return text.subrange(1,n) + s + text.subrange(n + (s)->size()+1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 def LI(): return list(map(int,input().split())) def I(): return int(input()) def LS(): return input().split() def S(): return input() def main(): s=S() t=S() for i in range(len(s)-len(t)+1)[: :-1]: x=s[i : i+len(t)] f=True for j in range(len(t)): if t[j]!=x[j]and x[j]!='?' : f=False if f : return s[: i].replace('?','a')+t+s[i+len(t):].replace('?','a') return 'UNRESTORABLE' print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return input().split(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation main() : OclAny pre: true post: true activity: var s : OclAny := S() ; var t : OclAny := S() ; for i : range((s)->size() - (t)->size() + 1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( var x : OclAny := s.subrange(i+1, i + (t)->size()) ; var f : boolean := true ; for j : Integer.subrange(0, (t)->size()-1) do ( if t[j+1] /= x[j+1] & x[j+1] /= '?' then ( f := false ) else skip) ; if f then ( return s.subrange(1,i).replace('?', 'a') + t + s.subrange(i + (t)->size()+1).replace('?', 'a') ) else skip) ; return 'UNRESTORABLE'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): S=str(input()) T=str(input()) if len(S)size()->compareTo((T)->size())) < 0 then ( execute ("UNRESTORABLE")->display() ; return 0 ) else skip ; var answers : Sequence := Sequence{} ; for i : Integer.subrange(0, (S)->size() - (T)->size() + 1-1) do ( var is_ok : boolean := true ; for j : Integer.subrange(0, (T)->size()-1) do ( if S[i + j+1] /= "?" & S[i + j+1] /= T[j+1] then ( is_ok := false ) else skip) ; if is_ok then ( execute (((S(subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))) : (test (logical_test (comparison (expr (atom (name i)))))) (sliceop :)) + T + S(subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name T)))))))) )))))))) : (sliceop :))).replace("?", "a")) : answers) ) else skip) ; if (answers)->size() = 0 then ( execute ("UNRESTORABLE")->display() ; return 0 ) else ( var answer : OclAny := sorted(answers)->first() ; execute (answer)->display() ; return 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def _input(): return map(int,input().split()) n=int(input()) lst=list(_input()) pos1=1 ; pos2=10**6 res=0 i=0 ; j=n-1 while i<=j : if lst[i]-pos1toInteger() ; var lst : Sequence := (_input()) ; var pos1 : int := 1; var pos2 : double := (10)->pow(6) ; var res : int := 0 ; var i : int := 0; var j : double := n - 1 ; while (i->compareTo(j)) <= 0 do ( if (lst[i+1] - pos1->compareTo(pos2 - lst[j+1])) < 0 then ( res := res + lst[i+1] - pos1 ; pos2 := pos2 - lst[i+1] - pos1 ; pos1 := lst[i+1] ; i := i + 1 ) else ( res := res + pos2 - lst[j+1] ; pos1 := pos1 + pos2 - lst[j+1] ; pos2 := lst[j+1] ; j := j - 1 )) ; execute (res)->display(); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,arr=int(input()),list(map(int,input().strip().split())) x,y,c,d=1,1000000,0,0 for i in range(n): if arr[i]>500000 : break c+=arr[i]-x ; x=arr[i] arr.reverse() for j in range(n): if arr[j]<=500000 : break d+=y-arr[j]; y=arr[j] print(max(c,d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var arr : OclAny := null; Sequence{n,arr} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ))} ; var x : OclAny := null; var y : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{x,y,c,d} := Sequence{1,1000000,0,0} ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] > 500000 then ( break ) else skip ; c := c + arr[i+1] - x; var x : OclAny := arr[i+1]) ; arr := arr->reverse() ; for j : Integer.subrange(0, n-1) do ( if arr[j+1] <= 500000 then ( break ) else skip ; d := d + y - arr[j+1]; var y : OclAny := arr[j+1]) ; execute (Set{c, d}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline import bisect n=int(input()) w=list(map(int,input().split())) c=bisect.bisect_left(w,500001) if c==n : print(w[-1]-1) elif c==0 : print(1000000-w[0]) else : print(max(w[c-1]-1,1000000-w[c])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : OclAny := bisect.bisect_left(w, 500001) ; if c = n then ( execute (w->last() - 1)->display() ) else (if c = 0 then ( execute (1000000 - w->first())->display() ) else ( execute (Set{w[c - 1+1] - 1, 1000000 - w[c+1]}->max())->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) s=list(map(int,input().split())) q=0 w=0 for i in range(a): if s[i]<=500000 : q=s[i] else : w=s[i] break q-=1 if w!=0 : w=10**6-w print(max(q,w)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : int := 0 ; var w : int := 0 ; for i : Integer.subrange(0, a-1) do ( if s[i+1] <= 500000 then ( q := s[i+1] ) else ( w := s[i+1] ; break )) ; q := q - 1 ; if w /= 0 then ( w := (10)->pow(6) - w ) else skip ; execute (Set{q, w}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : max=100 arr=[0 for i in range(max)] arr[0]=0 arr[1]=1 for i in range(2,max): arr[i]=arr[i-1]+arr[i-2] for i in range(1,max-1): if((arr[i]% 10==0)and(arr[i+1]% 10==1)): break print("Sequence is repeating after index",i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var max : int := 100 ; var arr : Sequence := Integer.subrange(0, max-1)->select(i | true)->collect(i | (0)) ; arr->first() := 0 ; arr[1+1] := 1 ; for i : Integer.subrange(2, max-1) do ( arr[i+1] := arr[i - 1+1] + arr[i - 2+1]) ; for i : Integer.subrange(1, max - 1-1) do ( if ((arr[i+1] mod 10 = 0) & (arr[i + 1+1] mod 10 = 1)) then ( break ) else skip) ; execute ("Sequence is repeating after index")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function def reverse(a,n,k): if(k>n): print("Invalid k") return for i in range(0,(int)(k/2)): temp=a[i] a[i]=a[k-i-1] a[k-i-1]=temp a=[1,2,3,4,5,6] n=len(a) k=4 reverse(a,n,k); for i in range(0,n): print(a[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))))) ; n := (a)->size() ; k := 4 ; reverse(a, n, k); ; for i : Integer.subrange(0, n-1) do ( execute (a[i+1])->display()); operation reverse(a : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: if ((k->compareTo(n)) > 0) then ( execute ("Invalid k")->display() ; return ) else skip ; for i : Integer.subrange(0, (OclType["int"])(k / 2)-1) do ( var temp : OclAny := a[i+1] ; a[i+1] := a[k - i - 1+1] ; a[k - i - 1+1] := temp); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) one=100*(N-M)+1900*M count=2**M print(one*count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var one : double := 100 * (N - M) + 1900 * M ; var count : double := (2)->pow(M) ; execute (one * count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np from collections import defaultdict from math import gcd import time import sys from collections import Counter read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines start=time.time() N,M=map(int,input().split(' ')) if N>M : print('safe') else : print('unsafe') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; var start : OclAny := time.time() ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; if (N->compareTo(M)) > 0 then ( execute ('safe')->display() ) else ( execute ('unsafe')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy from test.support import _MemoryWatchdog BIG_NUM=2000000000 HUGE_NUM=99999999999999999 MOD=1000000007 EPS=0.000000001 sys.setrecursionlimit(100000) class Edge : def __init__(self,arg_to): self.to=arg_to M=int(input()) N=int(input()) in_num=[0]*(M+1) G=[[]for _ in range(M+1)] for _ in range(N): x,y=map(int,input().split()) in_num[y]+=1 G[x].append(Edge(y)) Q=deque() for i in range(1,M+1): if in_num[i]==0 : Q.append(i) while len(Q)>0 : node_id=Q.popleft() print("%d" %(node_id)) for edge in G[node_id]: in_num[edge.to]-=1 if in_num[edge.to]==0 : Q.append(edge.to) ------------------------------------------------------------ OCL File: --------- class Edge { static operation newEdge() : Edge pre: true post: Edge->exists( _x | result = _x ); attribute to : OclAny := arg_to; operation initialise(arg_to : OclAny) : Edge pre: true post: true activity: self.to := arg_to; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var HUGE_NUM : int := 99999999999999999 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; sys.setrecursionlimit(100000) ; skip ; var M : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var in_num : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (M + 1)) ; var G : Sequence := Integer.subrange(0, M + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, N-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; in_num[y+1] := in_num[y+1] + 1 ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name Edge)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) ))))))))) ))))) ; var Q : Sequence := () ; for i : Integer.subrange(1, M + 1-1) do ( if in_num[i+1] = 0 then ( execute ((i) : Q) ) else skip) ; while (Q)->size() > 0 do ( var node_id : OclAny := Q->first() ; Q := Q->tail() ; execute (StringLib.format("%d",(node_id)))->display() ; for edge : G[node_id+1] do ( in_num[edge.to+1] := in_num[edge.to+1] - 1 ; if in_num[edge.to+1] = 0 then ( execute ((edge.to) : Q) ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(20): n=int(input()) if n==0 : break data=list() for j in range(n): a=int(input()) data.extend([a]) x=sum(data)-min(data)-max(data) print(x//(n-2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, 20-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var data : Sequence := () ; for j : Integer.subrange(0, n-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; data := data->union(Sequence{ a })) ; var x : double := (data)->sum() - (data)->min() - (data)->max() ; execute (x div (n - 2))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) total_time=M*1900+(N-M)*100 e=0 err=10**(-3) prev=-1 i=0 while abs(prev-e)>err : prev=e e+=(1-(1/2)**M)**i*(1/2)**M*total_time*(i+1) i+=1 def floor(x,y): return((-x)//y)*(-1) print(int(floor(e,1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var total_time : double := M * 1900 + (N - M) * 100 ; var e : int := 0 ; var err : double := (10)->pow((-3)) ; var prev : int := -1 ; var i : int := 0 ; while ((prev - e)->abs()->compareTo(err)) > 0 do ( prev := e ; e := e + ((1 - ((1 / 2))->pow(M)))->pow(i) * ((1 / 2))->pow(M) * total_time * (i + 1) ; i := i + 1) ; skip ; execute (("" + ((floor(e, 1))))->toInteger())->display(); operation floor(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return ((-x) div y) * (-1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=[int(x)for x in input().split()] print(int((1900*M+100*(N-M))/0.5**M)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (("" + (((1900 * M + 100 * (N - M)) / (0.5)->pow(M))))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) E=0 i=1 a=(1900*(M)+100*(N-M))*(0.5)**(M) while a>10e-10 : a=(1900*(M*i)+100*(N-M)*i)*(((2**M-1)*(0.5)**M)**(i-1))*(0.5)**M E+=a i+=1 print(int(E)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var E : int := 0 ; var i : int := 1 ; var a : double := (1900 * (M) + 100 * (N - M)) * ((0.5))->pow((M)) ; while a > ("10e-10")->toReal() do ( a := (1900 * (M * i) + 100 * (N - M) * i) * (((((2)->pow(M) - 1) * ((0.5))->pow(M)))->pow((i - 1))) * ((0.5))->pow(M) ; E := E + a ; i := i + 1) ; execute (("" + ((E)))->toInteger() + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split(' ')) correct=(n-m)*100*(2**m) wrong=m*1900*(2**m) print(correct+wrong) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var correct : double := (n - m) * 100 * ((2)->pow(m)) ; var wrong : double := m * 1900 * ((2)->pow(m)) ; execute (correct + wrong)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def LucasSum(N): Sum=0 a=2 b=1 c=0 Sum+=a while(b<=N): Sum+=b c=a+b a=b b=c return Sum N=20 print(LucasSum(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 20 ; execute (LucasSum(N))->display(); operation LucasSum(N : OclAny) : OclAny pre: true post: true activity: var Sum : int := 0 ; var a : int := 2 ; var b : int := 1 ; var c : int := 0 ; Sum := Sum + a ; while ((b->compareTo(N)) <= 0) do ( Sum := Sum + b ; c := a + b ; a := b ; b := c) ; return Sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys file_input=sys.stdin V,E,r=map(int,file_input.readline().split()) edges=[] for line in file_input : edges.append(tuple(map(int,line.split()))) distance=[float("inf")]*V distance[r]=0 for i in range(V): notUpdated=True for e in edges : t=e[1] temp_d=distance[e[0]]+e[2] if temp_dcollect( _x | (OclType["int"])->apply(_x) ) ; var edges : Sequence := Sequence{} ; for line : file_input do ( execute ((((line.split())->collect( _x | (OclType["int"])->apply(_x) ))) : edges)) ; var distance : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (("inf")))->toReal() }, V) ; distance[r+1] := 0 ; for i : Integer.subrange(0, V-1) do ( var notUpdated : boolean := true ; for e : edges do ( var t : OclAny := e[1+1] ; var temp_d : OclAny := distance[e->first()+1] + e[2+1] ; if (temp_d->compareTo(distance[t+1])) < 0 then ( distance[t+1] := temp_d ; notUpdated := false ) else skip) ; if notUpdated then ( break ) else skip) ; if i = V - 1 & V /= 1 then ( execute ("NEGATIVE CYCLE")->display() ) else ( execute ((argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))) (trailer . (name upper) (arguments ( ))))))))) , (argument (test (logical_test (comparison (expr (atom (name distance)))))))) )))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=float('inf') def bellman_ford(graph,weights,s): d={v : INF for v in graph} d[s]=0 edges=[(u,v)for u,vs in graph.items()for v in vs] for _ in range(len(graph)-1): for(u,v)in edges : d_temp=d[u]+weights[u,v] if d_temptoReal() ; skip ; var n_vertex : OclAny := null; var n_edge : OclAny := null; Sequence{n_vertex,n_edge,s} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; graph := Integer.subrange(0, n_vertex-1)->select(i | true)->collect(i | Map{i |-> Sequence{}})->unionAll() ; weights := Set{} ; for i : Integer.subrange(0, n_edge-1) do ( var u : OclAny := null; var v : OclAny := null; var w : OclAny := null; Sequence{u,v,w} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) ; weights[u+1][v+1] := w) ; d := bellman_ford(graph, weights, s) ; if not(d <>= null) then ( for i : Integer.subrange(0, n_vertex-1) do ( execute (if not(d[i+1] <>= INF) then d[i+1] else 'INF' endif)->display()) ) else skip; operation bellman_ford(graph : OclAny, weights : OclAny, s : OclAny) : OclAny pre: true post: true activity: var d : Map := graph->select(v | true)->collect(v | Map{v |-> INF})->unionAll() ; d[s+1] := 0 ; var edges : Sequence := graph->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->select(_tuple | let u : OclAny = _tuple->at(1) in let vs : OclAny = _tuple->at(2) in true)->collect(_tuple | let u : OclAny = _tuple->at(1) in let vs : OclAny = _tuple->at(2) in (Sequence{u, v})) ; for _anon : Integer.subrange(0, (graph)->size() - 1-1) do ( for Sequence{u, v} : edges do ( var d_temp : OclAny := d[u+1] + weights[u+1][v+1] ; if (d_temp->compareTo(d[v+1])) < 0 then ( d[v+1] := d_temp ) else skip)) ; for Sequence{u, v} : edges do ( if (d[u+1] + weights[u+1][v+1]->compareTo(d[v+1])) < 0 then ( execute ('NEGATIVE CYCLE')->display() ; return null ) else skip) ; return d; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys inf=1<<60 def solve(): N,M,r=map(int,sys.stdin.readline().split()) edges=[None]*M for i in range(M): si,ti,di=map(int,sys.stdin.readline().split()) edges[i]=(si,ti,di) ans=BellmanFord(N,M,edges,r) print(*ans,sep='\n') def BellmanFord(N,M,edges,r): d=[inf]*N d[r]=0 for i in range(N): flag=False for(u,v,c)in edges : if d[u]!=inf and d[u]+cpow(60)) ; skip ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; var r : OclAny := null; Sequence{N,M,r} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var edges : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, M) ; for i : Integer.subrange(0, M-1) do ( var si : OclAny := null; var ti : OclAny := null; var di : OclAny := null; Sequence{si,ti,di} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; edges[i+1] := Sequence{si, ti, di}) ; var ans : OclAny := BellmanFord(N, M, edges, r) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); operation BellmanFord(N : OclAny, M : OclAny, edges : OclAny, r : OclAny) : OclAny pre: true post: true activity: var d : Sequence := MatrixLib.elementwiseMult(Sequence{ Math_PINFINITY }, N) ; d[r+1] := 0 ; for i : Integer.subrange(0, N-1) do ( var flag : boolean := false ; for Sequence{u, v, c} : edges do ( if d[u+1] /= Math_PINFINITY & (d[u+1] + c->compareTo(d[v+1])) < 0 then ( d[v+1] := d[u+1] + c ; flag := true ) else skip) ; if flag & i = N - 1 then ( return Sequence{ 'NEGATIVE CYCLE' } ) else skip) ; d := d->select(di | true)->collect(di | (if (di->compareTo(Math_PINFINITY)) < 0 then di else 'INF' endif)) ; return d; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_v,num_e,source=input().split() edges=[] verticies=[] for i in range(int(num_e)): v,u,w=input().split() e=(int(v),int(u),int(w)) edges.append(e) for v in range(int(num_v)): v=str(v) verticies.append(v) itn=int(num_v)-1 g=edges dist=[float('inf')]*(itn+1) dist[int(source)]=0 def BF(g): for i in range(itn): for edge in edges : v,u,w=edge if dist[v]!=float('inf'): if dist[v]+wtoInteger()-1) do ( var v : OclAny := null; var u : OclAny := null; var w : OclAny := null; Sequence{v,u,w} := input().split() ; var e : OclAny := Sequence{("" + ((v)))->toInteger(), ("" + ((u)))->toInteger(), ("" + ((w)))->toInteger()} ; execute ((e) : edges)) ; for v : Integer.subrange(0, ("" + ((num_v)))->toInteger()-1) do ( var v : String := ("" + ((v))) ; execute ((v) : verticies)) ; var itn : double := ("" + ((num_v)))->toInteger() - 1 ; var g : Sequence := edges ; var dist : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (('inf')))->toReal() }, (itn + 1)) ; dist[("" + ((source)))->toInteger()+1] := 0 ; skip ; BF(g); operation BF(g : OclAny) pre: true post: true activity: for i : Integer.subrange(0, itn-1) do ( for edge : edges do ( var u : OclAny := null; var w : OclAny := null; Sequence{v,u,w} := edge ; if dist->at(v) /= ("" + (('inf')))->toReal() then ( if (dist->at(v) + w->compareTo(dist[u+1])) < 0 then ( dist[u+1] := dist->at(v) + w ) else skip ) else skip)) ; var ngc : int := 0 ; for edge : edges do ( var u : OclAny := null; var w : OclAny := null; Sequence{v,u,w} := edge ; if dist->at(v) /= ("" + (('inf')))->toReal() then ( if (dist->at(v) + w->compareTo(dist[u+1])) < 0 then ( ngc := 1 ) else skip ) else skip) ; if ngc = 0 then ( for i : Integer.subrange(0, itn + 1-1) do ( if dist[i+1] = ("" + (('inf')))->toReal() then ( execute ("INF")->display() ) else ( execute (dist[i+1])->display() )) ) else ( execute ("NEGATIVE CYCLE")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- visited=[] def dfs(v): for i in edges[v]: if i not in visited : dfs(i) visited.append(v) if __name__=='__main__' : m=int(input()) n=int(input()) evidences=[] edges=[[]for i in range(m)] for i in range(n): x,y=map(int,input().split()) evidences.append((x,y)) edges[x-1].append(y-1) for i in range(m): if i not in visited : dfs(i) ans=reversed([i+1 for i in visited]) print('\n'.join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var visited : Sequence := Sequence{} ; skip ; if __name__ = '__main__' then ( var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var evidences : Sequence := Sequence{} ; var edges : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{x, y}) : evidences) ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (number (integer 1)))))))))) ))))) ; for i : Integer.subrange(0, m-1) do ( if (visited)->excludes(i) then ( dfs(i) ) else skip) ; var ans : Sequence := (visited->select(i | true)->collect(i | (i + 1)))->reverse() ; execute (StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ) else skip; operation dfs(v : OclAny) pre: true post: true activity: for i : edges[v+1] do ( if (visited)->excludes(i) then ( dfs(i) ) else skip) ; execute ((v) : visited); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin from collections import deque V,E,R=[int(x)for x in stdin.readline().split()] d={} tick=False INF=float('inf') for i in range(V): d[i]=INF d[R]=0 weight={} st=[] for i in range(1,V+1): for j in range(E): if i==1 : s,t,w=[int(x)for x in stdin.readline().split()] weight[(s,t)]=w st.append((s,t)) (s,t)=st[j] if d[t]>d[s]+weight[(s,t)]: d[t]=d[s]+weight[(s,t)] if i==V : print('NEGATIVE CYCLE') quit() for k in range(V): if d[k]==float('inf'): print("INF") else : print(d[k]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var V : OclAny := null; var E : OclAny := null; var R : OclAny := null; Sequence{V,E,R} := stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var d : OclAny := Set{} ; var tick : boolean := false ; var INF : double := ("" + (('inf')))->toReal() ; for i : Integer.subrange(0, V-1) do ( d[i+1] := INF) ; d[R+1] := 0 ; var weight : OclAny := Set{} ; var st : Sequence := Sequence{} ; for i : Integer.subrange(1, V + 1-1) do ( for j : Integer.subrange(0, E-1) do ( if i = 1 then ( var s : OclAny := null; var t : OclAny := null; var w : OclAny := null; Sequence{s,t,w} := stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; weight[Sequence{s, t}+1] := w ; execute ((Sequence{s, t}) : st) ) else skip)) ; var Sequence{s, t} : OclAny := st[j+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) aa=list(map(int,input().split())) cnts=[0]*(k+1) ans=1e6 existing=0 r=0 for l in range(n-k+1): while rcollect( _x | (OclType["int"])->apply(_x) ) ; var aa : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnts : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (k + 1)) ; var ans : double := ("1e6")->toReal() ; var existing : int := 0 ; var r : int := 0 ; for l : Integer.subrange(0, n - k + 1-1) do ( while (r->compareTo(n)) < 0 & (existing->compareTo(k)) < 0 do ( var a : OclAny := aa[r+1] ; if (a->compareTo(k)) <= 0 then ( cnts[a+1] := cnts[a+1] + 1 ; if cnts[a+1] = 1 then ( existing := existing + 1 ) else skip ) else skip ; r := r + 1) ; if k = existing then ( ans := Set{ans, r - l}->min() ) else skip ; a := aa[l+1] ; if (a->compareTo(k)) <= 0 then ( cnts[a+1] := cnts[a+1] - 1 ; if cnts[a+1] = 0 then ( existing := existing - 1 ) else skip ) else skip) ; execute (if ans < ("1e6")->toReal() then ans else 0 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isUnique(a,n,k): sum=0 for i in range(0,n,1): sum+=a[i] sum+=n-1 return(sum==k) if __name__=='__main__' : a=[3,3,3] n=len(a) k=12 if(isUnique(a,n,k)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := Sequence{3}->union(Sequence{3}->union(Sequence{ 3 })) ; n := (a)->size() ; k := 12 ; if (isUnique(a, n, k)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isUnique(a : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( sum := sum + a[i+1]) ; sum := sum + n - 1 ; return (sum = k); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPermutations(N,B): x=B**N y=B**(N-1) print(x-y) if __name__=="__main__" : N,B=6,4 countPermutations(N,B) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{N,B} := Sequence{6,4} ; countPermutations(N, B) ) else skip; operation countPermutations(N : OclAny, B : OclAny) pre: true post: true activity: var x : double := (B)->pow(N) ; var y : double := (B)->pow((N - 1)) ; execute (x - y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) tmp=[a[0]]*n for i in range(1,n): tmp[i]=a[i]-a[i-1] ans=[i for i in range(1,n+1)if tmp[i :]==tmp[:-i]] print(len(ans)) print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var tmp : Sequence := MatrixLib.elementwiseMult(Sequence{ a->first() }, n) ; for i : Integer.subrange(1, n-1) do ( tmp[i+1] := a[i+1] - a[i - 1+1]) ; var ans : Sequence := Integer.subrange(1, n + 1-1)->select(i | tmp.subrange(i+1) = tmp.subrange(1,-i))->collect(i | (i)) ; execute ((ans)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout,exit n=int(stdin.readline()) a=list(map(int,stdin.readline().split())) a.insert(0,0) k,step=0,set() for i in range(n): a[i]=a[i+1]-a[i] for i in range(n): k,tmp,flg=k+1,0,1 for j in range(i+1,n): if a[j]!=a[tmp]: flg=0 break tmp+=1 if tmp==k : tmp=0 if flg : for i in range(n): if not(i+1)% k : step.add(i+1) stdout.write('%d\n' % len(step)) step=sorted(step) for i in range(len(step)): stdout.write('%d ' % step[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + ((stdin.readLine())))->toInteger() ; var a : Sequence := ((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a.insertAt(0+1, 0) ; var k : OclAny := null; var step : OclAny := null; Sequence{k,step} := Sequence{0,Set{}->union(())} ; for i : Integer.subrange(0, n-1) do ( a[i+1] := a[i + 1+1] - a[i+1]) ; for i : Integer.subrange(0, n-1) do ( var k : OclAny := null; var tmp : OclAny := null; var flg : OclAny := null; Sequence{k,tmp,flg} := Sequence{k + 1,0,1} ; for j : Integer.subrange(i + 1, n-1) do ( if a[j+1] /= a[tmp+1] then ( var flg : int := 0 ; break ) else skip ; tmp := tmp + 1 ; if tmp = k then ( var tmp : int := 0 ) else skip) ; if flg then ( for i : Integer.subrange(0, n-1) do ( if not((i + 1) mod k) then ( execute ((i + 1) : step) ) else skip) ) else skip) ; stdout.write(StringLib.format('%d ',(step)->size())) ; var step : Sequence := step->sort() ; for i : Integer.subrange(0, (step)->size()-1) do ( stdout.write(StringLib.format('%d ',step[i+1]))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) x=[a[0]]+[a[i+1]-a[i]for i in range(n-1)] oks=[] for i in range(1,n+1): ok=True for j in range(i,n): if x[j]!=x[j % i]: ok=False break if ok : oks.append(i) print(len(oks)) print(' '.join(map(str,oks))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : Sequence := Sequence{ a->first() }->union(Integer.subrange(0, n - 1-1)->select(i | true)->collect(i | (a[i + 1+1] - a[i+1]))) ; var oks : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( var ok : boolean := true ; for j : Integer.subrange(i, n-1) do ( if x[j+1] /= x[j mod i+1] then ( ok := false ; break ) else skip) ; if ok then ( execute ((i) : oks) ) else skip) ; execute ((oks)->size())->display() ; execute (StringLib.sumStringsWithSeparator(((oks)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[*map(int,input().split())] i=n-1 while i : a[i]-=a[i-1]; i-=1 r=[i for i in range(1,n+1)if a[i :]==a[:-i]] print(len(r)) print(*r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var i : double := n - 1 ; while i do ( a[i+1] := a[i+1] - a[i - 1+1]; i := i - 1) ; var r : Sequence := Integer.subrange(1, n + 1-1)->select(i | a.subrange(i+1) = a.subrange(1,-i))->collect(i | (i)) ; execute ((r)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name r))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- temp=input() temp=input() a=[0]+temp.split() n=len(a) x=[] for i in range(1,n): x=x+[int(a[i])-int(a[i-1])] output=[len(x)] for i in range(1,n-1): combine=[] temp=x[: i] while(len(combine)<(n-1)): combine+=temp combine=combine[: n-1] if(combine==x): output=output+[len(temp)] output.sort() print(len(output)) for i in output : print(i,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var temp : String := (OclFile["System.in"]).readLine() ; temp := (OclFile["System.in"]).readLine() ; var a : Sequence := Sequence{ 0 }->union(temp.split()) ; var n : int := (a)->size() ; var x : Sequence := Sequence{} ; for i : Integer.subrange(1, n-1) do ( x := x->union(Sequence{ ("" + ((a[i+1])))->toInteger() - ("" + ((a[i - 1+1])))->toInteger() })) ; var output : Sequence := Sequence{ (x)->size() } ; for i : Integer.subrange(1, n - 1-1) do ( var combine : Sequence := Sequence{} ; temp := x.subrange(1,i) ; while (((combine)->size()->compareTo((n - 1))) < 0) do ( combine := combine + temp) ; combine := combine.subrange(1,n - 1) ; if (combine = x) then ( output := output->union(Sequence{ (temp)->size() }) ) else skip) ; output := output->sort() ; execute ((output)->size())->display() ; for i : output do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- Prefix=[0] def repeated_digit(n): a=[] while n!=0 : d=n % 10 if d in a : return 0 a.append(d) n=n//10 return 1 def pre_calculation(MAX): global Prefix Prefix.append(repeated_digit(1)) for i in range(2,MAX+1): Prefix.append(repeated_digit(i)+Prefix[i-1]) def calculate(L,R): return Prefix[R]-Prefix[L-1] MAX=1000 pre_calculation(MAX) L=1 R=100 print(calculate(L,R)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute Prefix : OclAny; operation initialise() pre: true post: true activity: var Prefix : Sequence := Sequence{ 0 } ; skip ; skip ; skip ; MAX := 1000 ; pre_calculation(MAX) ; L := 1 ; R := 100 ; execute (calculate(L, R))->display(); operation repeated_digit(n : OclAny) : OclAny pre: true post: true activity: var a : Sequence := Sequence{} ; while n /= 0 do ( var d : int := n mod 10 ; if (a)->includes(d) then ( return 0 ) else skip ; execute ((d) : a) ; n := n div 10) ; return 1; operation pre_calculation(MAX : OclAny) pre: true post: true activity: skip ; execute ((repeated_digit(1)) : Prefix) ; for i : Integer.subrange(2, MAX + 1-1) do ( execute ((repeated_digit(i) + Prefix[i - 1+1]) : Prefix)); operation calculate(L : OclAny, R : OclAny) : OclAny pre: true post: true activity: return Prefix[R+1] - Prefix[L - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import deque def bfs(u,result,out_edge,in_degree,processed): q=deque() q.append(u) processed[u]=True while q : u=q.popleft() result.append(u) for e in out_edge[u]: in_degree[e]-=1 if in_degree[e]==0 and processed[e]==False : processed[e]=True q.append(e) def solve(m,in_degree,out_edge): result=[] processed=[False for _ in range(m+1)] for i,u in enumerate(in_degree[1 :],start=1): if u==0 and processed[i]==False : bfs(i,result,out_edge,in_degree,processed) return result def main(args): m=int(input()) n=int(input()) in_degree=[0 for _ in range(m+1)] out_edge=[[]for _ in range(m+1)] for _ in range(n): s,t=[int(x)for x in input().split(' ')] out_edge[s].append(t) in_degree[t]+=1 result=solve(m,in_degree,out_edge) print('\n'.join(map(str,result))) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation bfs(u : OclAny, result : OclAny, out_edge : OclAny, in_degree : OclAny, processed : OclAny) pre: true post: true activity: var q : Sequence := () ; execute ((u) : q) ; processed[u+1] := true ; while q do ( u := q->first() ; q := q->tail() ; execute ((u) : result) ; for e : out_edge[u+1] do ( in_degree[e+1] := in_degree[e+1] - 1 ; if in_degree[e+1] = 0 & processed[e+1] = false then ( processed[e+1] := true ; execute ((e) : q) ) else skip)); operation solve(m : OclAny, in_degree : OclAny, out_edge : OclAny) : OclAny pre: true post: true activity: result := Sequence{} ; processed := Integer.subrange(0, m + 1-1)->select(_anon | true)->collect(_anon | (false)) ; for _tuple : Integer.subrange(1, (in_degree->tail(), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->size())->collect( _indx | Sequence{_indx-1, (in_degree->tail(), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var u : OclAny := _tuple->at(_indx); if u = 0 & processed[i+1] = false then ( bfs(i, result, out_edge, in_degree, processed) ) else skip) ; return result; operation main(args : OclAny) pre: true post: true activity: m := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; in_degree := Integer.subrange(0, m + 1-1)->select(_anon | true)->collect(_anon | (0)) ; out_edge := Integer.subrange(0, m + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, n-1) do ( var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; (expr (atom (name out_edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) )))) ; in_degree[t+1] := in_degree[t+1] + 1) ; result := solve(m, in_degree, out_edge) ; execute (StringLib.sumStringsWithSeparator(((result)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) word=list(input()) X1=['A','B','C','D','E','F','G','H','I','J','K','L','M'] X2=['N','O','P','Q','R','S','T','U','V','W','X','Y','Z'] Y1=['a','b','c','d','e','f','g','h','i','j','k','l','m'] Y2=['n','o','p','q','r','s','t','u','v','w','x','y','z'] x=0 y=0 answer="" for i in word : if i in X1 : x+=1 elif i in X2 : x-=1 elif i in Y1 : y+=1 elif i in Y2 : y-=1 print(abs(x)+abs(y)) if abs(x)+abs(y)>0 : if x>0 : answer+="A"*x elif x<0 : answer+="N"*abs(x) if y>0 : answer+="a"*y elif y<0 : answer+="n"*abs(y) print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var word : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var X1 : Sequence := Sequence{'A'}->union(Sequence{'B'}->union(Sequence{'C'}->union(Sequence{'D'}->union(Sequence{'E'}->union(Sequence{'F'}->union(Sequence{'G'}->union(Sequence{'H'}->union(Sequence{'I'}->union(Sequence{'J'}->union(Sequence{'K'}->union(Sequence{'L'}->union(Sequence{ 'M' })))))))))))) ; var X2 : Sequence := Sequence{'N'}->union(Sequence{'O'}->union(Sequence{'P'}->union(Sequence{'Q'}->union(Sequence{'R'}->union(Sequence{'S'}->union(Sequence{'T'}->union(Sequence{'U'}->union(Sequence{'V'}->union(Sequence{'W'}->union(Sequence{'X'}->union(Sequence{'Y'}->union(Sequence{ 'Z' })))))))))))) ; var Y1 : Sequence := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{'c'}->union(Sequence{'d'}->union(Sequence{'e'}->union(Sequence{'f'}->union(Sequence{'g'}->union(Sequence{'h'}->union(Sequence{'i'}->union(Sequence{'j'}->union(Sequence{'k'}->union(Sequence{'l'}->union(Sequence{ 'm' })))))))))))) ; var Y2 : Sequence := Sequence{'n'}->union(Sequence{'o'}->union(Sequence{'p'}->union(Sequence{'q'}->union(Sequence{'r'}->union(Sequence{'s'}->union(Sequence{'t'}->union(Sequence{'u'}->union(Sequence{'v'}->union(Sequence{'w'}->union(Sequence{'x'}->union(Sequence{'y'}->union(Sequence{ 'z' })))))))))))) ; var x : int := 0 ; var y : int := 0 ; var answer : String := "" ; for i : word do ( if (X1)->includes(i) then ( x := x + 1 ) else (if (X2)->includes(i) then ( x := x - 1 ) else (if (Y1)->includes(i) then ( y := y + 1 ) else (if (Y2)->includes(i) then ( y := y - 1 ) else skip ) ) ) ) ; execute ((x)->abs() + (y)->abs())->display() ; if (x)->abs() + (y)->abs() > 0 then ( if x > 0 then ( answer := answer + StringLib.nCopies("A", x) ) else (if x < 0 then ( answer := answer + StringLib.nCopies("N", (x)->abs()) ) else skip) ; if y > 0 then ( answer := answer + StringLib.nCopies("a", y) ) else (if y < 0 then ( answer := answer + StringLib.nCopies("n", (y)->abs()) ) else skip) ; execute (answer)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from string import ascii_letters from collections import defaultdict import sys def inpl(): return list(map(int,input().split())) M={s : i//13 for i,s in enumerate(ascii_letters)} D=defaultdict(int) ans="" input() for s in input(): D[M[s]]+=1 if D[0]>D[1]: ans="a"*(D[0]-D[1]) else : ans="z"*(D[1]-D[0]) if D[2]>D[3]: ans+="A"*(D[2]-D[3]) else : ans+="Z"*(D[3]-D[2]) print(len(ans)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var M : Map := Integer.subrange(1, (ascii_letters)->size())->collect( _indx | Sequence{_indx-1, (ascii_letters)->at(_indx)} )->select(_tuple | true)->collect(_tuple | Map{s |-> i div 13})->unionAll() ; var D : OclAny := defaultdict(OclType["int"]) ; var ans : String := "" ; input() ; for s : (OclFile["System.in"]).readLine() do ( D[M[s+1]+1] := D[M[s+1]+1] + 1) ; if (D->first()->compareTo(D[1+1])) > 0 then ( ans := StringLib.nCopies("a", (D->first() - D[1+1])) ) else ( ans := StringLib.nCopies("z", (D[1+1] - D->first())) ) ; if (D[2+1]->compareTo(D[3+1])) > 0 then ( ans := ans + StringLib.nCopies("A", (D[2+1] - D[3+1])) ) else ( ans := ans + StringLib.nCopies("Z", (D[3+1] - D[2+1])) ) ; execute ((ans)->size())->display() ; execute (ans)->display(); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def LI(): return list(map(int,input().split())) def II(): return int(input()) def LS(): return input().split() def S(): return input() def LIR(n): return[LI()for i in range(n)] def MI(): return map(int,input().split()) n,k=MI() a=LI() l=0 r=0 ans=float("inf") fl=[0 for i in range(k+1)] s=0 if k==1 and a[0]==1 : print(1) quit() if a[0]<=k : fl[a[0]]=1 s=1 while rtoReal() ; var fl : Sequence := Integer.subrange(0, k + 1-1)->select(i | true)->collect(i | (0)) ; var s : int := 0 ; if k = 1 & a->first() = 1 then ( execute (1)->display() ; quit() ) else skip ; if (a->first()->compareTo(k)) <= 0 then ( fl[a->first()+1] := 1 ; s := 1 ) else skip ; while (r->compareTo(n - 1)) < 0 do ( r := r + 1 ; if (a[r+1]->compareTo(k)) <= 0 then ( if not(fl[a[r+1]+1]) then ( s := s + 1 ) else skip ; fl[a[r+1]+1] := fl[a[r+1]+1] + 1 ) else skip ; if s = k then ( while s = k do ( l := l + 1 ; if (a[l - 1+1]->compareTo(k)) <= 0 then ( if fl[a[l - 1+1]+1] = 1 then ( s := s - 1 ) else skip ; fl[a[l - 1+1]+1] := fl[a[l - 1+1]+1] - 1 ) else skip) ; ans := Set{ans, r - l + 2}->min() ) else skip) ; if ans = ("" + (("inf")))->toReal() then ( execute (0)->display() ; quit() ) else skip ; execute (ans)->display(); operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return input().split(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation MI() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ns=0 ew=0 meirei=list(input()) for i in range(n): if 65<=ord(meirei[i])<=77 : ns+=1 elif 78<=ord(meirei[i])<=90 : ns-=1 elif 97<=ord(meirei[i])<=109 : ew+=1 else : ew-=1 print(abs(ns)+abs(ew)) if ns>0 : print('A'*ns,sep='',end='') elif ns<0 : print('Z'*(-ns),sep='',end='') if ew>0 : print('a'*ew,sep='',end='') elif ew<0 : print('z'*(-ew),sep='',end='') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ns : int := 0 ; var ew : int := 0 ; var meirei : Sequence := ((OclFile["System.in"]).readLine())->characters() ; for i : Integer.subrange(0, n-1) do ( if 65 <= (meirei[i+1])->char2byte() & ((meirei[i+1])->char2byte() <= 77) then ( ns := ns + 1 ) else (if 78 <= (meirei[i+1])->char2byte() & ((meirei[i+1])->char2byte() <= 90) then ( ns := ns - 1 ) else (if 97 <= (meirei[i+1])->char2byte() & ((meirei[i+1])->char2byte() <= 109) then ( ew := ew + 1 ) else ( ew := ew - 1 ) ) ) ) ; execute ((ns)->abs() + (ew)->abs())->display() ; if ns > 0 then ( execute (StringLib.nCopies('A', ns))->display() ) else (if ns < 0 then ( execute (StringLib.nCopies('Z', (-ns)))->display() ) else skip) ; if ew > 0 then ( execute (StringLib.nCopies('a', ew))->display() ) else (if ew < 0 then ( execute (StringLib.nCopies('z', (-ew)))->display() ) else skip) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) S=input() C=[chr(i)for i in range(97,97+13)] D=[chr(i)for i in range(97+13,97+26)] A=[chr(i)for i in range(65,65+13)] B=[chr(i)for i in range(65+13,65+26)] X=[0]*2 for s in S : if s in A : X[0]+=1 elif s in B : X[0]-=1 elif s in C : X[1]+=1 elif s in D : X[1]-=1 ans="" if X[0]<0 : ans+='N'*abs(X[0]) else : ans+='A'*X[0] if X[1]<0 : ans+='n'*abs(X[1]) else : ans+='a'*X[1] print(len(ans)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : String := (OclFile["System.in"]).readLine() ; var C : Sequence := Integer.subrange(97, 97 + 13-1)->select(i | true)->collect(i | ((i)->byte2char())) ; var D : Sequence := Integer.subrange(97 + 13, 97 + 26-1)->select(i | true)->collect(i | ((i)->byte2char())) ; var A : Sequence := Integer.subrange(65, 65 + 13-1)->select(i | true)->collect(i | ((i)->byte2char())) ; var B : Sequence := Integer.subrange(65 + 13, 65 + 26-1)->select(i | true)->collect(i | ((i)->byte2char())) ; var X : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 2) ; for s : S->characters() do ( if (A)->includes(s) then ( X->first() := X->first() + 1 ) else (if (B)->includes(s) then ( X->first() := X->first() - 1 ) else (if (C)->includes(s) then ( X[1+1] := X[1+1] + 1 ) else (if (D)->includes(s) then ( X[1+1] := X[1+1] - 1 ) else skip ) ) ) ) ; var ans : String := "" ; if X->first() < 0 then ( ans := ans + StringLib.nCopies('N', (X->first())->abs()) ) else ( ans := ans + StringLib.nCopies('A', X->first()) ) ; if X[1+1] < 0 then ( ans := ans + StringLib.nCopies('n', (X[1+1])->abs()) ) else ( ans := ans + StringLib.nCopies('a', X[1+1]) ) ; execute ((ans)->size())->display() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) S=input() n=s=e=w=0 for c in S : if 'A'<=c<='M' : n+=1 elif 'N'<=c<='Z' : s+=1 elif 'a'<=c<='m' : e+=1 else : w+=1 my=min(n,s) n-=my s-=my mx=min(e,w) e-=mx w-=mx ans='A'*n+'N'*s+'a'*e+'n'*w print(len(ans)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : String := (OclFile["System.in"]).readLine() ; n := n(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name e)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name w)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for c : S->characters() do ( if 'A' <= c & (c <= 'M') then ( n := n + 1 ) else (if 'N' <= c & (c <= 'Z') then ( s := s + 1 ) else (if 'a' <= c & (c <= 'm') then ( e := e + 1 ) else ( w := w + 1 ) ) ) ) ; var my : OclAny := Set{n, s}->min() ; n := n - my ; s := s - my ; var mx : OclAny := Set{e, w}->min() ; e := e - mx ; w := w - mx ; var ans : String := StringLib.nCopies('A', n) + StringLib.nCopies('N', s) + StringLib.nCopies('a', e) + StringLib.nCopies('n', w) ; execute ((ans)->size())->display() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(c): w,h=len(c[0]),len(c) dp=[[0]*w for _ in range(h)] for x in range(w): if c[1][x]==0 : dp[1][x]=1 for y in range(2,h): for x in range(w): if c[y][x]==1 : continue if c[y-2][x]==2 : dp[y][x]+=dp[y-2][x] if c[y-1][x]==0 : dp[y][x]+=dp[y-1][x] if c[y][x]==0 : if c[y-1][x-1]==0 : dp[y][x]+=dp[y-1][x-1] if c[y-1][x+1]==0 : dp[y][x]+=dp[y-1][x+1] return sum(dp[-1])+sum(dp[-2][x]for x in range(w)if c[-2][x]==2) import sys f=sys.stdin while True : w,h=map(int,f.readline().split()) if w==0 : break course=[[1]*(w+2)]+[[1]+list(map(int,f.readline().split()))+[1]for _ in range(h)] print(solve(course)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var f : OclFile := OclFile["System.in"] ; while true do ( var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := (f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if w = 0 then ( break ) else skip ; var course : Sequence := Sequence{ MatrixLib.elementwiseMult(Sequence{ 1 }, (w + 2)) }->union(Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (Sequence{ 1 }->union(((f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )))->union(Sequence{ 1 })))) ; execute (solve(course))->display()); operation solve(c : OclAny) : OclAny pre: true post: true activity: var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := Sequence{(c->first())->size(),(c)->size()} ; var dp : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, w))) ; for x : Integer.subrange(0, w-1) do ( if c[1+1][x+1] = 0 then ( dp[1+1][x+1] := 1 ) else skip) ; for y : Integer.subrange(2, h-1) do ( for x : Integer.subrange(0, w-1) do ( if c[y+1][x+1] = 1 then ( continue ) else skip ; if c[y - 2+1][x+1] = 2 then ( dp[y+1][x+1] := dp[y+1][x+1] + dp[y - 2+1][x+1] ) else skip ; if c[y - 1+1][x+1] = 0 then ( dp[y+1][x+1] := dp[y+1][x+1] + dp[y - 1+1][x+1] ) else skip ; if c[y+1][x+1] = 0 then ( if c[y - 1+1][x - 1+1] = 0 then ( dp[y+1][x+1] := dp[y+1][x+1] + dp[y - 1+1][x - 1+1] ) else skip ; if c[y - 1+1][x + 1+1] = 0 then ( dp[y+1][x+1] := dp[y+1][x+1] + dp[y - 1+1][x + 1+1] ) else skip ) else skip)) ; return (dp->last())->sum() + ((argument (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 2))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name w)))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 2))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))) == (comparison (expr (atom (number (integer 2))))))))))))->sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while(True): X,Y=map(int,input().split()) if X==0 and Y==0 : break ar=[list(map(int,input().split()))for _ in range(Y)] ar.append([0]*X) br=[[0]*X for _ in range(Y+1)] for j in range(X): if ar[-2][j]!=1 : br[-2][j]=1 br[-1][j]=1 for i in range(Y-2,-1,-1): for j in range(X): if j-1>=0 and ar[i][j]!=2 and ar[i+1][j-1]==0 : br[i][j]+=br[i+1][j-1] if j+1collect( _x | (OclType["int"])->apply(_x) ) ; if X = 0 & Y = 0 then ( break ) else skip ; var ar : Sequence := Integer.subrange(0, Y-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; execute ((MatrixLib.elementwiseMult(Sequence{ 0 }, X)) : ar) ; var br : Sequence := Integer.subrange(0, Y + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, X))) ; for j : Integer.subrange(0, X-1) do ( if ar->front()->last()[j+1] /= 1 then ( br->front()->last()[j+1] := 1 ) else skip ; br->last()[j+1] := 1) ; for i : Integer.subrange(-1 + 1, Y - 2)->reverse() do ( for j : Integer.subrange(0, X-1) do ( if j - 1 >= 0 & ar[i+1][j+1] /= 2 & ar[i + 1+1][j - 1+1] = 0 then ( br[i+1][j+1] := br[i+1][j+1] + br[i + 1+1][j - 1+1] ) else skip ; if (j + 1->compareTo(X)) < 0 & ar[i+1][j+1] /= 2 & ar[i + 1+1][j + 1+1] = 0 then ( br[i+1][j+1] := br[i+1][j+1] + br[i + 1+1][j + 1+1] ) else skip ; if ar[i+1][j+1] /= 2 & ar[i + 1+1][j+1] /= 1 then ( br[i+1][j+1] := br[i+1][j+1] + br[i + 1+1][j+1] ) else skip ; if ar[i+1][j+1] = 2 & ar[i + 2+1][j+1] /= 1 then ( br[i+1][j+1] := br[i+1][j+1] + br[i + 2+1][j+1] ) else skip) ; for j : Integer.subrange(0, X-1) do ( if ar[i+1][j+1] = 1 then ( br[i+1][j+1] := 0 ) else skip)) ; execute ((br->first())->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printF(field,w,h): for i in range(h): print(field[i]) def getp(f,p,y,x,h,w,v): if y<0 or x<0 or x>=w : return 0 if y>=h : if v==True : return 1 return 0 k=f[y][x] r=0 if k==0 : if p[y][x]>=0 : return p[y][x] r=getp(f,p,y+1,x-1,h,w,False)+getp(f,p,y+1,x,h,w,True)+getp(f,p,y+1,x+1,h,w,False) p[y][x]=r elif k==1 : r=0 elif k==2 : if v==True : if p[y][x]>=0 : return p[y][x] r=getp(f,p,y+2,x,h,w,True) p[y][x]=r else : r=0 return r w,h=map(int,input().split()) while w!=0 and h!=0 : field=[] for i in range(h): field.append(list(map(int,input().split()))) p=[] for i in range(h): p.append([-1]*w) print(sum(map(lambda x : getp(field,p,0,x,h,w,True),range(w)))) w,h=map(int,input().split()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; while w /= 0 & h /= 0 do ( field := Sequence{} ; for i : Integer.subrange(0, h-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : field)) ; p := Sequence{} ; for i : Integer.subrange(0, h-1) do ( execute ((MatrixLib.elementwiseMult(Sequence{ -1 }, w)) : p)) ; execute (((Integer.subrange(0, w-1))->collect( _x | (lambda x : OclAny in (getp(field, p, 0, x, h, w, true)))->apply(_x) ))->sum())->display() ; Sequence{w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation printF(field : OclAny, w : OclAny, h : OclAny) pre: true post: true activity: for i : Integer.subrange(0, h-1) do ( execute (field[i+1])->display()); operation getp(f : OclAny, p : OclAny, y : OclAny, x : OclAny, h : OclAny, w : OclAny, v : OclAny) : OclAny pre: true post: true activity: if y < 0 or x < 0 or (x->compareTo(w)) >= 0 then ( return 0 ) else skip ; if (y->compareTo(h)) >= 0 then ( if v = true then ( return 1 ) else skip ; return 0 ) else skip ; var k : OclAny := f[y+1][x+1] ; var r : int := 0 ; if k = 0 then ( if p[y+1][x+1] >= 0 then ( return p[y+1][x+1] ) else skip ; r := getp(f, p, y + 1, x - 1, h, w, false) + getp(f, p, y + 1, x, h, w, true) + getp(f, p, y + 1, x + 1, h, w, false) ; p[y+1][x+1] := r ) else (if k = 1 then ( r := 0 ) else (if k = 2 then ( if v = true then ( if p[y+1][x+1] >= 0 then ( return p[y+1][x+1] ) else skip ; r := getp(f, p, y + 2, x, h, w, true) ; p[y+1][x+1] := r ) else ( r := 0 ) ) else skip ) ) ; return r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : X,Y=map(int,input().split()) if X==0 : break a=[[1]+list(map(int,input().split()))+[1]for _ in[0]*Y]+[[0]*(X+2)] dp=[list(map(lambda x : x ^ 1,a[0]))]+[[0]*(X+2)for _ in[0]*Y] for y in range(Y-1): for x,(square,cnt)in enumerate(zip(a[y][1 :],dp[y][1 :-1]),start=1): if square==0 : for tx in range(x-1,x+2): if a[y+1][tx]==0 or a[y+1][tx]==2 and x==tx : dp[y+1][tx]+=cnt elif square==2 : dp[y+2][x]+=cnt for x in range(1,X+1): if a[Y-1][x]!=1 : dp[Y][x]+=dp[Y-1][x] print(sum(dp[-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var X : OclAny := null; var Y : OclAny := null; Sequence{X,Y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if X = 0 then ( break ) else skip ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, Y)->select(_anon | true)->collect(_anon | (Sequence{ 1 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->union(Sequence{ 1 })))->union(Sequence{ MatrixLib.elementwiseMult(Sequence{ 0 }, (X + 2)) }) ; var dp : Sequence := Sequence{ ((a->first())->collect( _x | (lambda x : OclAny in (MathLib.bitwiseXor(x, 1)))->apply(_x) )) }->union(MatrixLib.elementwiseMult(Sequence{ 0 }, Y)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (X + 2))))) ; for y : Integer.subrange(0, Y - 1-1) do ( for _tuple : Integer.subrange(1, (Integer.subrange(1, a[y+1]->tail()->size())->collect( _indx | Sequence{a[y+1]->tail()->at(_indx), dp[y+1].subrange(1+1, -1)->at(_indx)} ), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(1, a[y+1]->tail()->size())->collect( _indx | Sequence{a[y+1]->tail()->at(_indx), dp[y+1].subrange(1+1, -1)->at(_indx)} ), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{square, cnt} : OclAny := _tuple->at(_indx); if square = 0 then ( for tx : Integer.subrange(x - 1, x + 2-1) do ( if a[y + 1+1][tx+1] = 0 or a[y + 1+1][tx+1] = 2 & x = tx then ( dp[y + 1+1][tx+1] := dp[y + 1+1][tx+1] + cnt ) else skip) ) else (if square = 2 then ( dp[y + 2+1][x+1] := dp[y + 2+1][x+1] + cnt ) else skip))) ; for x : Integer.subrange(1, X + 1-1) do ( if a[Y - 1+1][x+1] /= 1 then ( dp[Y+1][x+1] := dp[Y+1][x+1] + dp[Y - 1+1][x+1] ) else skip) ; execute ((dp->last())->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def topological_sort(V,to): cnt=[0]*V for i in range(V): for j in to[i]: cnt[j]+=1 Q=[] for i in range(V): if cnt[i]==0 : Q.append(i) while len(Q)>0 : i=Q[0] del Q[0] print(i+1) for k in to[i]: cnt[k]-=1 if cnt[k]==0 : Q.append(k) m=int(input()) to=[[]for i in range(m)] n=int(input()) for i in range(n): x,y=list(map(int,input().split())) to[x-1].append(y-1) topological_sort(m,to) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; to := Integer.subrange(0, m-1)->select(i | true)->collect(i | (Sequence{})) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (expr (atom (name to)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (number (integer 1)))))))))) ))))) ; topological_sort(m, to); operation topological_sort(V : OclAny, to : OclAny) pre: true post: true activity: var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, V) ; for i : Integer.subrange(0, V-1) do ( for j : to[i+1] do ( cnt[j+1] := cnt[j+1] + 1)) ; var Q : Sequence := Sequence{} ; for i : Integer.subrange(0, V-1) do ( if cnt[i+1] = 0 then ( execute ((i) : Q) ) else skip) ; while (Q)->size() > 0 do ( var i : OclAny := Q->first() ; execute (Q->first())->isDeleted() ; execute (i + 1)->display() ; for k : to[i+1] do ( cnt[k+1] := cnt[k+1] - 1 ; if cnt[k+1] = 0 then ( execute ((k) : Q) ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : x,y=list(map(int,input().split())) if x==0 : break c=[list(map(int,input().split()))for _ in range(y)] c.append([0]*x) c.append([0]*x) dp=[[0]*x for _ in range(y+2)] for i in range(x): if c[0][i]==0 : dp[0][i]=1 for i in range(y): for j in range(x): if c[i][j]==0 : if i!=y-1 : if j!=0 and c[i+1][j-1]==0 : dp[i+1][j-1]+=dp[i][j] if j!=x-1 and c[i+1][j+1]==0 : dp[i+1][j+1]+=dp[i][j] if c[i+1][j]!=1 : dp[i+1][j]+=dp[i][j] elif c[i][j]==2 : if c[i+2][j]!=1 : dp[i+2][j]+=dp[i][j] ans=0 for i in dp[y-1 : y+1]: ans+=sum(i) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if x = 0 then ( break ) else skip ; var c : Sequence := Integer.subrange(0, y-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; execute ((MatrixLib.elementwiseMult(Sequence{ 0 }, x)) : c) ; execute ((MatrixLib.elementwiseMult(Sequence{ 0 }, x)) : c) ; var dp : Sequence := Integer.subrange(0, y + 2-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, x))) ; for i : Integer.subrange(0, x-1) do ( if c->first()[i+1] = 0 then ( dp->first()[i+1] := 1 ) else skip) ; for i : Integer.subrange(0, y-1) do ( for j : Integer.subrange(0, x-1) do ( if c[i+1][j+1] = 0 then ( if i /= y - 1 then ( if j /= 0 & c[i + 1+1][j - 1+1] = 0 then ( dp[i + 1+1][j - 1+1] := dp[i + 1+1][j - 1+1] + dp[i+1][j+1] ) else skip ; if j /= x - 1 & c[i + 1+1][j + 1+1] = 0 then ( dp[i + 1+1][j + 1+1] := dp[i + 1+1][j + 1+1] + dp[i+1][j+1] ) else skip ; if c[i + 1+1][j+1] /= 1 then ( dp[i + 1+1][j+1] := dp[i + 1+1][j+1] + dp[i+1][j+1] ) else skip ) else skip ) else (if c[i+1][j+1] = 2 then ( if c[i + 2+1][j+1] /= 1 then ( dp[i + 2+1][j+1] := dp[i + 2+1][j+1] + dp[i+1][j+1] ) else skip ) else skip))) ; var ans : int := 0 ; for i : dp.subrange(y - 1+1, y + 1) do ( ans := ans + (i)->sum()) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter,deque from collections import defaultdict from itertools import combinations,permutations,accumulate,groupby,product from bisect import bisect_left,bisect_right from heapq import heapify,heappop,heappush from math import floor,ceil from operator import itemgetter from copy import deepcopy def I(): return int(input()) def MI(): return map(int,input().split()) def LI(): return list(map(int,input().split())) def LI2(): return[int(input())for i in range(n)] def MXI(): return[[LI()]for i in range(n)] inf=10**17 mod=10**9+7 n=I() t,a=MI() hs=LI() u=[] mini=inf for i in range(n): k=abs(t-a-hs[i]*0.006) if kpow(7)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var Math_PINFINITY : double := (10)->pow(17) ; var mod : double := (10)->pow(9) + 7 ; var n : OclAny := I() ; var t : OclAny := null; var a : OclAny := null; Sequence{t,a} := MI() ; var hs : OclAny := LI() ; var u : Sequence := Sequence{} ; var mini : double := Math_PINFINITY ; for i : Integer.subrange(0, n-1) do ( var k : double := (t - a - hs[i+1] * 0.006)->abs() ; if (k->compareTo(mini)) < 0 then ( mini := k ; var num : OclAny := i ) else skip) ; execute (num + 1)->display(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LI2() : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())); operation MXI() : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{ LI() })); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) t,a=map(int,input().split()) h=list(map(int,input().split())) a*=1000 t*=1000 d=abs(t-h[0]*6-a) ans=0 for i in range(n): td=abs(t-h[i]*6-a) if tdtoInteger() ; var t : OclAny := null; var a : OclAny := null; Sequence{t,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a * 1000 ; t := t * 1000 ; var d : double := (t - h->first() * 6 - a)->abs() ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var td : double := (t - h[i+1] * 6 - a)->abs() ; if (td->compareTo(d)) < 0 then ( d := td ; ans := i ) else skip) ; execute (ans + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) a=list(map(int,input().split())) result=0 for el in a : flag=True while flag : if el % 2==0 : el//=2 result+=1 else : flag=False print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var result : int := 0 ; for el : a do ( var flag : boolean := true ; while flag do ( if el mod 2 = 0 then ( el := el div 2 ; result := result + 1 ) else ( flag := false ))) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Window : def __init__(self,k): self.k=k self.data=[0]*k self.zeros=set(range(k)) def add(self,i): if self.data[i-1]==0 : self.zeros.remove(i-1) self.data[i-1]+=1 def remove(self,i): if self.data[i-1]==1 : self.zeros.add(i-1) self.data[i-1]-=1 def removable(self,i): return self.data[i-1]>1 def open(self): return len(self.zeros)==0 def run(): n,k=[int(x)for x in input().split()] li=[int(x)for x in input().split()] w=Window(k) i=0 min_=n+1 for j,v in enumerate(li): if v<=k : w.add(v) while True : if li[i]>k : pass elif w.removable(li[i]): w.remove(li[i]) else : break i+=1 if w.open(): if min_>j-i+1 : min_=j-i+1 if min_>n : print(0) else : print(min_) if __name__=='__main__' : run() ------------------------------------------------------------ OCL File: --------- class Window { static operation newWindow() : Window pre: true post: Window->exists( _x | result = _x ); attribute k : OclAny := k; attribute data : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, k); attribute zeros : Set := Set{}->union((Integer.subrange(0, k-1))); operation initialise(k : OclAny) : Window pre: true post: true activity: self.k := k ; self.data := MatrixLib.elementwiseMult(Sequence{ 0 }, k) ; self.zeros := Set{}->union((Integer.subrange(0, k-1))); return self; operation add(i : OclAny) pre: true post: true activity: if self.data[i - 1+1] = 0 then ( (expr (atom (name self)) (trailer . (name zeros)) (trailer . (name remove) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) )))) ) else skip ; self.data[i - 1+1] := self.data[i - 1+1] + 1; operation remove(i : OclAny) pre: true post: true activity: if self.data[i - 1+1] = 1 then ( (expr (atom (name self)) (trailer . (name zeros)) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) )))) ) else skip ; self.data[i - 1+1] := self.data[i - 1+1] - 1; operation removable(i : OclAny) : OclAny pre: true post: true activity: return self.data[i - 1+1] > 1; operation open() : OclAny pre: true post: true activity: return (self.zeros)->size() = 0; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( run() ) else skip; operation run() pre: true post: true activity: var n : OclAny := null; Sequence{n,k} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var li : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var w : Window := (Window.newWindow()).initialise(k) ; i := 0 ; var min_ : OclAny := n + 1 ; for _tuple : Integer.subrange(1, (li)->size())->collect( _indx | Sequence{_indx-1, (li)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if (v->compareTo(k)) <= 0 then ( execute ((v) : w) ; while true do ( if (li[i+1]->compareTo(k)) > 0 then ( skip ) else (if w.removable(li[i+1]) then ( execute ((li[i+1]) /: w) ) else ( break ) ) ; i := i + 1) ; if w.open() then ( if (min_->compareTo(j - i + 1)) > 0 then ( min_ := j - i + 1 ) else skip ) else skip ) else skip) ; if (min_->compareTo(n)) > 0 then ( execute (0)->display() ) else ( execute (min_)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np N=int(input()) T,A=map(int,input().split()) H=np.array(list(map(int,input().split()))) H=T-H*0.006 H=list(abs(A-H)) min=min(H) print(int(H.index(min))+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var T : OclAny := null; var A : OclAny := null; Sequence{T,A} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var H : Sequence := (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; H := T - MatrixLib.elementwiseMult(H, 0.006) ; H := ((A - H)->abs()) ; var min : OclAny := (H)->min() ; execute (("" + ((H->indexOf(min) - 1)))->toInteger() + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys N=input() TA=input() T,A=TA.split() Hinp=input() H=Hinp.split() ansnum=None ans=0 def getdiff(A,ans): return abs(max(ans,A)-min(ans,A)) def chk(A,_ans,ans): new_d,old_d=getdiff(A,_ans),getdiff(A,ans) if new_dsize())->collect( _indx | Sequence{_indx-1, (H)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); _ans := ("" + ((T)))->toInteger() - ("" + ((x)))->toInteger() * 0.006 ; if _ans = A then ( showans(i + 1) ) else skip ; if not(ansnum) or chk(("" + ((A)))->toInteger(), _ans, ansnum) then ( ans := i + 1 ; ansnum := _ans ) else skip) ; showans(ans); operation getdiff(A : OclAny, ans : OclAny) : OclAny pre: true post: true activity: return (Set{ans, A}->max() - Set{ans, A}->min())->abs(); operation chk(A : OclAny, _ans : OclAny, ans : OclAny) : OclAny pre: true post: true activity: var new_d : OclAny := null; var old_d : OclAny := null; Sequence{new_d,old_d} := Sequence{getdiff(A, _ans),getdiff(A, ans)} ; if (new_d->compareTo(old_d)) < 0 then ( return true ) else skip ; return false; operation showans(ans : OclAny) pre: true post: true activity: execute (ans)->display() ; sys.exit(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math if __name__=='__main__' : n=int(input()) t,a=map(int,input().split()) h=map(int,input().split()) diff=0 answer=-1 first=True for index,height in enumerate(h): temp=t-height*0.006 current_diff=math.fabs(a-temp) if current_diff<=diff or first : diff=current_diff answer=index first=False print(answer+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : OclAny := null; var a : OclAny := null; Sequence{t,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var diff : int := 0 ; var answer : int := -1 ; var first : boolean := true ; for _tuple : Integer.subrange(1, (h)->size())->collect( _indx | Sequence{_indx-1, (h)->at(_indx)} ) do (var _indx : int := 1; var index : OclAny := _tuple->at(_indx); _indx := _indx + 1; var height : OclAny := _tuple->at(_indx); var temp : double := t - height * 0.006 ; var current_diff : double := (a - temp)->abs() ; if (current_diff->compareTo(diff)) <= 0 or first then ( diff := current_diff ; answer := index ; first := false ) else skip) ; execute (answer + 1)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def discriminant(a,b,c): discriminant=(b**2)-(4*a*c) if discriminant>0 : print('Discriminant is',discriminant,"which is Positive") print('Hence Two Solutions') elif discriminant==0 : print('Discriminant is',discriminant,"which is Zero") print('Hence One Solution') elif discriminant<0 : print('Discriminant is',discriminant,"which is Negative") print('Hence No Real Solutions') a=20 b=30 c=10 discriminant(a,b,c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 20 ; b := 30 ; c := 10 ; discriminant(a, b, c); operation discriminant(a : OclAny, b : OclAny, c : OclAny) pre: true post: true activity: var discriminant : double := ((b)->pow(2)) - (4 * a * c) ; if discriminant > 0 then ( execute ('Discriminant is')->display() ; execute ('Hence Two Solutions')->display() ) else (if discriminant = 0 then ( execute ('Discriminant is')->display() ; execute ('Hence One Solution')->display() ) else (if discriminant < 0 then ( execute ('Discriminant is')->display() ; execute ('Hence No Real Solutions')->display() ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,m=map(int,input().split()) if n==0 and m==0 : break sum=[] for i in range(m): sum.append(0) smax=0 for i in range(n): ans=list(map(int,input().split())) for i in range(m): if ans[i]==1 : sum[i]+=1 if smaxcollect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 & m = 0 then ( break ) else skip ; var sum : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( execute ((0) : sum)) ; var smax : int := 0 ; for i : Integer.subrange(0, n-1) do ( var ans : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, m-1) do ( if ans[i+1] = 1 then ( [i+1]->sum() := [i+1]->sum() + 1 ) else skip ; if (smax->compareTo([i+1]->sum())) < 0 then ( smax := [i+1]->sum() ) else skip)) ; ans := "" ; for i : (Integer.subrange(0, smax + 1-1))->reverse() do ( for j : Integer.subrange(0, m-1) do ( if [j+1]->sum() = i then ( ans := ans + ("" + ((j + 1))) + " " ) else skip)) ; ans := ans.rstrip(" ") ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=int(input()) n=int(input()) X=[0 for i in range(n)] Y=[0 for i in range(n)] for l in range(n): X[l],Y[l]=[int(i)for i in input().split()] ans=[] while True : flag=True for i in range(1,m+1): if not(i in Y)and not(i in ans): ans.append(i) for j in range(len(X))[: :-1]: if X[j]==i : X.pop(j) Y.pop(j) flag=False break if flag : break for i in range(len(ans)): print(ans[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var X : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var Y : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for l : Integer.subrange(0, n-1) do ( var X[l+1] : OclAny := null; var Y[l+1] : OclAny := null; Sequence{X[l+1],Y[l+1]} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))) ; var ans : Sequence := Sequence{} ; while true do ( var flag : boolean := true ; for i : Integer.subrange(1, m + 1-1) do ( if not(((Y)->includes(i))) & not(((ans)->includes(i))) then ( execute ((i) : ans) ; for j : range((X)->size())(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if X[j+1] = i then ( X := X->excludingAt(j+1) ; Y := Y->excludingAt(j+1) ) else skip) ; flag := false ; break ) else skip) ; if flag then ( break ) else skip) ; for i : Integer.subrange(0, (ans)->size()-1) do ( execute (ans[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- enqu=[] n=m=0 def solve(): score=[sum(enqu[i][j]for i in range(0,n))for j in range(0,m)] x=[[j+1,score[j]]for j in range(0,m)] x.sort(key=lambda y : y[1],reverse=True) print(" ".join(list(map(lambda y : str(y[0]),x)))) while True : enqu=[] line=input() n,m=map(int,line.split()) if n==0 and m==0 : break for _ in range(0,n): answer=list(map(int,list(input().split()))) enqu.append(answer) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var enqu : Sequence := Sequence{} ; var n : OclAny := 0; var m : int := 0 ; skip ; while true do ( enqu := Sequence{} ; var line : String := (OclFile["System.in"]).readLine() ; Sequence{n,m} := (line.split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 & m = 0 then ( break ) else skip ; for _anon : Integer.subrange(0, n-1) do ( var answer : Sequence := (((input().split()))->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((answer) : enqu)) ; solve()); operation solve() pre: true post: true activity: var score : Sequence := Integer.subrange(0, m-1)->select(j | true)->collect(j | (((argument (test (logical_test (comparison (expr (atom (name enqu)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->sum())) ; var x : Sequence := Integer.subrange(0, m-1)->select(j | true)->collect(j | (Sequence{j + 1}->union(Sequence{ score[j+1] }))) ; x := x->sort() ; execute (StringLib.sumStringsWithSeparator((((x)->collect( _x | (lambda y : OclAny in (("" + ((y->first())))))->apply(_x) ))), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,m=[int(x)for x in input().split()] if n==0 and m==0 : break L=[0]*m for _ in range(n): l=[int(x)for x in input().split()] for i in range(m): L[i]+=l[i] M=[] for i,j in enumerate(L,1): M.append((i,j)) M.sort(key=lambda x :(-x[1],x[0])) print(*[x for x,y in M]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if n = 0 & m = 0 then ( break ) else skip ; var L : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; for _anon : Integer.subrange(0, n-1) do ( var l : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for i : Integer.subrange(0, m-1) do ( L[i+1] := L[i+1] + l[i+1])) ; var M : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (L, 1)->size())->collect( _indx | Sequence{_indx-1, (L, 1)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); execute ((Sequence{i, j}) : M)) ; M := M->sort() ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name x)))))) (comp_for for (exprlist (expr (atom (name x))) , (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name M))))))) ])))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,m=map(int,raw_input().split()) if n==0 : break else : data=[] for i in range(n): student=map(int,raw_input().split()) data.append(student) result=[] for j in range(m): sum=0 for i in range(n): sum+=data[i][j] result.append(sum) ans=[] for i in range(1,m+1): ans.append(i) for i in range(1,m): for j in range(1,m-i+1): if result[j-1]collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else ( var data : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var student : Sequence := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((student) : data)) ; var result : Sequence := Sequence{} ; for j : Integer.subrange(0, m-1) do ( var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + data[i+1][j+1]) ; execute ((sum) : result)) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(1, m + 1-1) do ( execute ((i) : ans)) ; for i : Integer.subrange(1, m-1) do ( for j : Integer.subrange(1, m - i + 1-1) do ( if (result[j - 1+1]->compareTo(result[j+1])) < 0 then ( var tmp : OclAny := ans[j - 1+1] ; ans[j - 1+1] := ans[j+1] ; ans[j+1] := tmp ; tmp := result[j - 1+1] ; result[j - 1+1] := result[j+1] ; result[j+1] := tmp ) else skip)) ; var ans_text : String := "" ; for i : Integer.subrange(0, m - 1-1) do ( ans_text := ans_text + ("" + ((ans[i+1]))) + " ") ; ans_text := ans_text + ("" + ((ans[m - 1+1]))) ; execute (ans_text)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(): N,M=map(int,input().split()) if N==0 : return-1 A=[0]*M for i in range(N): T=[int(i)for i in map(int,input().split())] for j in range(M): if T[j]==1 : A[j]+=1 B=sorted([(v,i+1)for i,v in enumerate(A)],key=lambda t :(t[0],-t[1]),reverse=True) print(' '.join([str(t[1])for t in B])) return 1 def main(): while True : ret=f() if ret==-1 : return if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation f() : OclAny pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if N = 0 then ( return -1 ) else skip ; var A : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, M) ; for i : Integer.subrange(0, N-1) do ( var T : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; for j : Integer.subrange(0, M-1) do ( if T[j+1] = 1 then ( A[j+1] := A[j+1] + 1 ) else skip)) ; var B : Sequence := Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in (Sequence{v, i + 1}))->sortedBy($x | (lambda t : OclAny in (Sequence{t->first(), -t[1+1]}))->apply($x)) ; execute (StringLib.sumStringsWithSeparator((B->select(t | true)->collect(t | (("" + ((t[1+1])))))), ' '))->display() ; return 1; operation main() pre: true post: true activity: while true do ( var ret : String := f() ; if ret = -1 then ( return ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minSwaps(str1,str2): count=0 for i in range(len(str1)): if str1[i]!=str2[i]: count+=1 if count % 2==0 : print(count//2) else : print("Not Possible") if __name__=="__main__" : binaryString1="1110000" binaryString2="0001101" minSwaps(binaryString1,binaryString2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var binaryString1 : String := "1110000" ; var binaryString2 : String := "0001101" ; minSwaps(binaryString1, binaryString2) ) else skip; operation minSwaps(str1 : OclAny, str2 : OclAny) pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, (str1)->size()-1) do ( if str1[i+1] /= str2[i+1] then ( count := count + 1 ) else skip) ; if count mod 2 = 0 then ( execute (count div 2)->display() ) else ( execute ("Not Possible")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n,k=map(int,input().split()) a=list(map(int,input().split())) tmp=max(a) tmp2=max(tmp,n,k)+1 chk=[0]*(tmp2) for i in range(n): chk[a[i]]+=1 if 0 in chk[1 : k+1]: print(0) sys.exit() right=n-1 left=0 L=[] while right1 or a[right]>k : chk[a[right]]-=1 right-=1 ln=right-left+1 L.append(ln) while chk[a[left]]>1 or a[left]>k : chk[a[left]]-=1 left+=1 ln=right-left+1 L.append(ln) chk[a[left]]-=1 left+=1 while chk[a[left-1]]==0 : right+=1 if right>=n : break chk[a[right]]+=1 ln=right-left+1 L.append(ln) print(min(L)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var tmp : OclAny := (a)->max() ; var tmp2 : OclAny := Set{tmp, n, k}->max() + 1 ; var chk : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (tmp2)) ; for i : Integer.subrange(0, n-1) do ( chk[a[i+1]+1] := chk[a[i+1]+1] + 1) ; if (chk.subrange(1+1, k + 1))->includes(0) then ( execute (0)->display() ; sys.exit() ) else skip ; var right : double := n - 1 ; var left : int := 0 ; var L : Sequence := Sequence{} ; while (right->compareTo(n)) < 0 do ( while chk[a[right+1]+1] > 1 or (a[right+1]->compareTo(k)) > 0 do ( chk[a[right+1]+1] := chk[a[right+1]+1] - 1 ; right := right - 1) ; var ln : double := right - left + 1 ; execute ((ln) : L) ; while chk[a[left+1]+1] > 1 or (a[left+1]->compareTo(k)) > 0 do ( chk[a[left+1]+1] := chk[a[left+1]+1] - 1 ; left := left + 1) ; ln := right - left + 1 ; execute ((ln) : L) ; chk[a[left+1]+1] := chk[a[left+1]+1] - 1 ; left := left + 1 ; while chk[a[left - 1+1]+1] = 0 do ( right := right + 1 ; if (right->compareTo(n)) >= 0 then ( break ) else skip ; chk[a[right+1]+1] := chk[a[right+1]+1] + 1) ; ln := right - left + 1 ; execute ((ln) : L)) ; execute ((L)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(a==0): return b ; return gcd(b % a,a); def coprime(a,b): return(gcd(a,b)==1); def possibleTripletInRange(L,R): flag=False ; possibleA=0 ; possibleB=0 ; possibleC=0 ; for a in range(L,R+1): for b in range(a+1,R+1): for c in range(b+1,R+1): if(coprime(a,b)and coprime(b,c)and coprime(a,c)==False): flag=True ; possibleA=a ; possibleB=b ; possibleC=c ; break ; if(flag==True): print("(",possibleA,",",possibleB,",",possibleC,")is one such","possible triplet between",L,"and",R); else : print("No Such Triplet exists between",L,"and",R); L=2 ; R=10 ; possibleTripletInRange(L,R); L=23 ; R=46 ; possibleTripletInRange(L,R); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; L := 2; ; R := 10; ; possibleTripletInRange(L, R); ; L := 23; ; R := 46; ; possibleTripletInRange(L, R);; operation gcd(a : OclAny, b : OclAny) pre: true post: true activity: if (a = 0) then ( return b; ) else skip ; return gcd(b mod a, a);; operation coprime(a : OclAny, b : OclAny) pre: true post: true activity: return (gcd(a, b) = 1);; operation possibleTripletInRange(L : OclAny, R : OclAny) pre: true post: true activity: var flag : boolean := false; ; var possibleA : int := 0; ; var possibleB : int := 0; ; var possibleC : int := 0; ; for a : Integer.subrange(L, R + 1-1) do ( for b : Integer.subrange(a + 1, R + 1-1) do ( for c : Integer.subrange(b + 1, R + 1-1) do ( if (coprime(a, b) & coprime(b, c) & coprime(a, c) = false) then ( flag := true; ; possibleA := a; ; possibleB := b; ; possibleC := c; ; break; ) else skip))) ; if (flag = true) then ( execute ("(")->display(); ) else ( execute ("No Such Triplet exists between")->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) li=[] tmp=[] for j in range(1,n+1): tmp.append(j) for i in range(n,0,-1): if i>k : li.append(i) tmp.remove(i) elif itoInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var li : Sequence := Sequence{} ; var tmp : Sequence := Sequence{} ; for j : Integer.subrange(1, n + 1-1) do ( execute ((j) : tmp)) ; for i : Integer.subrange(0 + 1, n)->reverse() do ( if (i->compareTo(k)) > 0 then ( execute ((i) : li) ; execute ((i) /: tmp) ) else (if (i->compareTo(k)) < 0 then ( if (tmp)->includes(k - i) then ( if k - i /= i then ( execute ((i) : li) ; execute ((i) /: tmp) ; execute ((k - i) /: tmp) ) else ( execute ((i) : li) ; execute ((i) /: tmp) ) ) else skip ) else ( execute ((i) /: tmp) ) ) ; if tmp = Sequence{} then ( break ) else skip) ; if tmp /= Sequence{} then ( li := li + tmp ) else skip ; execute ((li)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name li))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: n,k=map(int,s.split()); print(n-k+k//2,*range(k+1>>1,k),*range(k+1,n+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ); execute (n - k + k div 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil def main(): t=int(input()) for _ in range(t): n,k=map(int,input().split()) print(n-ceil(k/2)) for i in range(ceil(k/2),k): print(i,end=" ") for j in range(k+1,n+1): print(j,end=" ") print() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (n - ceil(k / 2))->display() ; for i : Integer.subrange(ceil(k / 2), k-1) do ( execute (i)->display()) ; for j : Integer.subrange(k + 1, n + 1-1) do ( execute (j)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) A=list(map(int,input().split())) A.sort() print(A[(n-1)//2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; A := A->sort() ; execute (A[(n - 1) div 2+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math t=int(input()) while(t): n,k=[int(i)for i in input().split()] if(n==1): print(0) else : c=n-(k+1)+1 c+=k//2 m=math.ceil(k/2) print(c) for i in range(m,n+1): if(i!=k): print(i,end="") print("") t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (t) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if (n = 1) then ( execute (0)->display() ) else ( var c : double := n - (k + 1) + 1 ; c := c + k div 2 ; var m : double := (k / 2)->ceil() ; execute (c)->display() ; for i : Integer.subrange(m, n + 1-1) do ( if (i /= k) then ( execute (i)->display() ) else skip) ; execute ("")->display() ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math v=int(input()) while(v): n,k=[int(i)for i in input().split()] if(n==1): print(0) else : c=n-(k+1)+1 c+=k//2 m=math.ceil(k/2) print(c) for i in range(m,n+1): if(i!=k): print(i,end="") print("") v-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var v : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (v) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if (n = 1) then ( execute (0)->display() ) else ( var c : double := n - (k + 1) + 1 ; c := c + k div 2 ; var m : double := (k / 2)->ceil() ; execute (c)->display() ; for i : Integer.subrange(m, n + 1-1) do ( if (i /= k) then ( execute (i)->display() ) else skip) ; execute ("")->display() ) ; v := v - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def EulerTotientFunction(limit): copy=limit primes=[] for i in range(2,limit+1): if i*i>limit : break if(limit % i==0): while(limit % i==0): limit//=i primes.append(i) if(limit>=2): primes.append(limit) ans=copy for it in primes : ans=(ans//it)*(it-1) return ans def CountGCD(m,k): if(m % k!=0): print(0) return if(m==k): print(2) return limit=m//k ans=EulerTotientFunction(limit) print(ans) if __name__=='__main__' : M=9 K=1 CountGCD(M,K) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var M : int := 9 ; var K : int := 1 ; CountGCD(M, K) ) else skip; operation EulerTotientFunction(limit : OclAny) : OclAny pre: true post: true activity: var copy : OclAny := limit ; var primes : Sequence := Sequence{} ; for i : Integer.subrange(2, limit + 1-1) do ( if (i * i->compareTo(limit)) > 0 then ( break ) else skip ; if (limit mod i = 0) then ( while (limit mod i = 0) do ( limit := limit div i) ; execute ((i) : primes) ) else skip) ; if (limit >= 2) then ( execute ((limit) : primes) ) else skip ; var ans : OclAny := copy ; for it : primes do ( ans := (ans div it) * (it - 1)) ; return ans; operation CountGCD(m : OclAny, k : OclAny) pre: true post: true activity: if (m mod k /= 0) then ( execute (0)->display() ; return ) else skip ; if (m = k) then ( execute (2)->display() ; return ) else skip ; limit := m div k ; ans := EulerTotientFunction(limit) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from decimal import Decimal t=int(input()) for i in range(t): n=int(input()) a=list(map(int,input().split())) a=sorted(a) print(a[n-1]+a[n-2]-a[0]-a[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; execute (a[n - 1+1] + a[n - 2+1] - a->first() - a[1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,nums): nums.sort() return abs(nums[0]+nums[1]-nums[-1]-nums[-2]) t=int(input()) for T in range(t): n=int(input()) nums=list(map(int,input().split(' '))) print(solve(n,nums)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for T : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; nums := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; execute (solve(n, nums))->display()); operation solve(n : OclAny, nums : OclAny) : OclAny pre: true post: true activity: nums := nums->sort() ; return (nums->first() + nums[1+1] - nums->last() - nums->front()->last())->abs(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) lis=list(map(int,input().split())) lis.sort() print(lis[-1]+lis[-2]-lis[1]-lis[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lis : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; lis := lis->sort() ; execute (lis->last() + lis->front()->last() - lis[1+1] - lis->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict N,K=map(int,input().split()) A=[int(a)for a in input().split()] left,right,num=0,0,0 ans=float('inf') count=defaultdict(int) while True : while rightcollect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; var left : OclAny := null; var right : OclAny := null; var num : OclAny := null; Sequence{left,right,num} := Sequence{0,0,0} ; var ans : double := ("" + (('inf')))->toReal() ; var count : OclAny := defaultdict(OclType["int"]) ; while true do ( while (right->compareTo(N)) < 0 & (num->compareTo(K)) < 0 do ( if count[A[right+1]+1] = 0 & (A[right+1]->compareTo(K)) <= 0 then ( num := num + 1 ) else skip ; count[A[right+1]+1] := count[A[right+1]+1] + 1 ; right := right + 1) ; if (num->compareTo(K)) < 0 then ( break ) else skip ; ans := Set{ans, right - left}->min() ; if count[A[left+1]+1] = 1 & (A[left+1]->compareTo(K)) <= 0 then ( num := num - 1 ) else skip ; count[A[left+1]+1] := count[A[left+1]+1] - 1 ; left := left + 1) ; execute (if ans /= ("" + (('inf')))->toReal() then ans else 0 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) lis=sorted(list(map(int,input().split()))) print(lis[-1]+lis[-2]-lis[0]-lis[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lis : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; execute (lis->last() + lis->front()->last() - lis->first() - lis[1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): input() li=sorted(map(int,input().split())) li=list(li) print(li[-1]+li[-2]-li[0]-li[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( input() ; var li : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; li := (li) ; execute (li->last() + li->front()->last() - li->first() - li[1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printPairs(arr,n): for i in range(n): for j in range(n): print("(",arr[i],",",arr[j],")",end=",") arr=[1,2] n=len(arr) printPairs(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{ 2 }) ; n := (arr)->size() ; printPairs(arr, n); operation printPairs(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( execute ("(")->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(x): sum=0 for i in range(0,n): sum+=v[i]-x if sum>=s : return True else : return False t=1 while t>0 : t-=1 n,s=(int(_)for _ in input().strip().split(' ')) v=list(map(int,input().split())) sum=0 l=0 r=0x3f3f3f3f for i in range(0,n): sum+=v[i] r=min(v[i],r) if sum>1 if check(mid)==True : l=mid else : r=mid-1 print(l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := 1 ; while t > 0 do ( t := t - 1 ; var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name _)))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name strip) (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ' '))))))) ))))))))} ; var v : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; sum := 0 ; var l : int := 0 ; var r : int := 0x3f3f3f3f ; for i : Integer.subrange(0, n-1) do ( sum := sum + v[i+1] ; r := Set{v[i+1], r}->min()) ; if (sum->compareTo(s)) < 0 then ( execute (-1)->display() ) else ( while (l->compareTo(r)) < 0 do ( var mid : int := (l + r + 1) /(2->pow(1)) ; if check(mid) = true then ( l := mid ) else ( r := mid - 1 )) ; execute (l)->display() )); operation check(x : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + v[i+1] - x) ; if (sum->compareTo(s)) >= 0 then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def firstNonRepeating(arr,n): for i in range(n): j=0 while(junion(Sequence{4}->union(Sequence{9}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 4 }))))) ; n := (arr)->size() ; execute (firstNonRepeating(arr, n))->display(); operation firstNonRepeating(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( var j : int := 0 ; while ((j->compareTo(n)) < 0) do ( if (i /= j & arr[i+1] = arr[j+1]) then ( break ) else skip ; j := j + 1) ; if (j = n) then ( return arr[i+1] ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline import heapq N,M=(int(x)for x in input().split()) A=list(map(int,input().split())) BC=[] changeable=N broke=False for i in range(M): B,C=(int(x)for x in input().split()) BC.append((C*(-1),B)) heapq.heapify(A) heapq.heapify(BC) for i in range(M): t1=heapq.heappop(BC) if t1[1]collect( _x | (OclType["int"])->apply(_x) )) ; var BC : Sequence := Sequence{} ; var changeable : OclAny := N ; var broke : boolean := false ; for i : Integer.subrange(0, M-1) do ( var B : OclAny := null; var C : OclAny := null; Sequence{B,C} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; execute ((Sequence{C * (-1), B}) : BC)) ; heapq.heapify(A) ; heapq.heapify(BC) ; for i : Integer.subrange(0, M-1) do ( var t1 : OclAny := heapq.heappop(BC) ; if (t1[1+1]->compareTo(changeable)) < 0 then ( (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name t2)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name heapq)) (trailer . (name heappop) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name t2)))) < (comparison (expr (expr (atom (name t1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom - (number (integer 1)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name heapq)) (trailer . (name heappush) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name t1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom - (number (integer 1)))))))) ))))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name heapq)) (trailer . (name heappush) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A))))))) , (argument (test (logical_test (comparison (expr (atom (name t2)))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name broke)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name True)))))))))))) (stmt (simple_stmt (small_stmt break)))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name changeable)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (name t1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))))))))) ) else ( for j : Integer.subrange(0, changeable-1) do ( var t2 : OclAny := heapq.heappop(A) ; if (t2->compareTo(t1->first() * (-1))) < 0 then ( heapq.heappush(A, t1->first() * (-1)) ) else ( heapq.heappush(A, t2) ; break )) ; break ) ; if broke then ( break ) else skip) ; execute ((A)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np from collections import deque from collections import defaultdict import heapq import collections import itertools import bisect mod=10**9+7 N,M=list(map(int,input().split())) A=list(map(int,input().split())) heapq.heapify(A) change={} for i in range(M): b,c=list(map(int,input().split())) if c in change : change[c]+=b else : change[c]=b for key in sorted((change.keys()),reverse=True): for num in range(change[key]): min_=heapq.heappop(A) if min_pow(9) + 7 ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; heapq.heapify(A) ; var change : OclAny := Set{} ; for i : Integer.subrange(0, M-1) do ( var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (change)->includes(c) then ( change[c+1] := change[c+1] + b ) else ( change[c+1] := b )) ; for key : (change.keys())->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) do ( for num : Integer.subrange(0, change[key+1]-1) do ( var min_ : OclAny := heapq.heappop(A) ; if (min_->compareTo(key)) < 0 then ( heapq.heappush(A, key) ) else ( heapq.heappush(A, min_) ; execute ((A)->sum())->display() ; exit() ))) ; execute ((A)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from operator import itemgetter n,m=map(int,input().split()) a=sorted(list(map(int,input().split())),reverse=True) num=[] for _ in range(m): b,c=map(int,input().split()) num.append([b,c]) num=sorted(num,key=itemgetter(1),reverse=True) i=0 j=0 cnt=0 ans=0 while cntcollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var num : Sequence := Sequence{} ; for _anon : Integer.subrange(0, m-1) do ( var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{b}->union(Sequence{ c })) : num)) ; num := num->sortedBy($x | (itemgetter(1))->apply($x)) ; var i : int := 0 ; var j : int := 0 ; var cnt : int := 0 ; var ans : int := 0 ; while (cnt->compareTo(n)) < 0 do ( if (j->compareTo(m)) < 0 then ( if (a[i+1]->compareTo(num[j+1][1+1])) <= 0 then ( if (n - cnt->compareTo(num[j+1]->first())) <= 0 then ( ans := ans + (n - cnt) * num[j+1][1+1] ; execute (ans)->display() ; exit() ) else ( ans := ans + num[j+1]->first() * num[j+1][1+1] ; cnt := cnt + num[j+1]->first() ; j := j + 1 ) ) else ( ans := ans + a[i+1] ; i := i + 1 ; cnt := cnt + 1 ) ) else ( ans := ans + a[i+1] ; i := i + 1 ; cnt := cnt + 1 )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np N,M=map(int,input().split()) A=np.array([int(x)for x in input().split()],dtype=np.int64) A.sort() BC=np.array([[int(x)for x in input().split()]for _ in range(M)]) B=BC[:,0] C=BC[:,1] idx=C.argsort() B=B[idx][: :-1] C=C[idx][: :-1] p=0 for b,c in zip(B,C): A[p : p+b]=np.maximum(A[p : p+b],c) p+=b answer=A.sum() print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())), (argument (test (logical_test (comparison (expr (atom (name dtype)))))) = (test (logical_test (comparison (expr (atom (name np)) (trailer . (name int64)))))))) ; A := A->sort() ; var BC : Sequence := (Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))))) ; var B : Sequence := BC->collect( _r | _r->first() ) ; var C : Sequence := BC->collect( _r | _r[1+1] ) ; var idx : OclAny := C.argsort() ; B := B[idx+1](subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; C := C[idx+1](subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var p : int := 0 ; for _tuple : Integer.subrange(1, B->size())->collect( _indx | Sequence{B->at(_indx), C->at(_indx)} ) do (var _indx : int := 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); A.subrange(p+1, p + b) := ; p := p + b) ; var answer : OclAny := A.sum() ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque n,m=[int(v)for v in input().split()] a_s=[int(v)for v in input().split()] bc_s=[[int(v)for v in input().split()]for i in range(m)] bc_s_sorted_by_c=deque(sorted(bc_s,key=lambda x : x[1],reverse=True)) a_s_sorted=deque(sorted(a_s,reverse=True)) ans=0 room=n while True : if len(bc_s_sorted_by_c)>=1 and a_s_sorted[0]select(v | true)->collect(v | (("" + ((v)))->toInteger())) ; var a_s : Sequence := input().split()->select(v | true)->collect(v | (("" + ((v)))->toInteger())) ; var bc_s : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (input().split()->select(v | true)->collect(v | (("" + ((v)))->toInteger())))) ; var bc_s_sorted_by_c : Sequence := (bc_s->sortedBy($x | (lambda x : OclAny in (x[1+1]))->apply($x))) ; var a_s_sorted : Sequence := (a_s->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True))))))))) ; var ans : int := 0 ; var room : OclAny := n ; while true do ( if (bc_s_sorted_by_c)->size() >= 1 & (a_s_sorted->first()->compareTo(bc_s_sorted_by_c->first()[1+1])) < 0 then ( var bc : OclAny := bc_s_sorted_by_c->first() ; bc_s_sorted_by_c := bc_s_sorted_by_c->tail() ; var count : OclAny := null; var value : OclAny := null; Sequence{count,value} := bc ) else ( var count : OclAny := null; var value : OclAny := null; Sequence{count,value} := Sequence{1,a_s_sorted->first()} ) ; if (room->compareTo(count)) < 0 then ( var count : OclAny := room ) else skip ; ans := ans + value * count ; room := room - count ; if room <= 0 then ( break ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter from sys import stdin input=stdin.readline n=int(input()); beauty=list(map(int,input().split())); count=Counter(beauty) print(n-max(count.values())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var beauty : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); var count : OclAny := Counter(beauty) ; execute (n - (count.values())->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getSum(BITree,index): sum=0 while(index>0): sum+=BITree[index] index-=index &(-index) return sum def updateBIT(BITree,n,index,val): while(index<=n): BITree[index]+=val index+=index &(-index) def getInvCount(arr,n): invcount=0 maxElement=max(arr) BIT=[0]*(maxElement+1) for i in range(1,maxElement+1): BIT[i]=0 for i in range(n-1,-1,-1): invcount+=getSum(BIT,arr[i]-1) updateBIT(BIT,maxElement,arr[i],1) return invcount if __name__=="__main__" : arr=[8,4,2,1] n=4 print("Inversion Count : ",getInvCount(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{8}->union(Sequence{4}->union(Sequence{2}->union(Sequence{ 1 }))) ; n := 4 ; execute ("Inversion Count : ")->display() ) else skip; operation getSum(BITree : OclAny, index : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; while (index > 0) do ( sum := sum + BITree[index+1] ; index := index - MathLib.bitwiseAnd(index, (-index))) ; return sum; operation updateBIT(BITree : OclAny, n : OclAny, index : OclAny, val : OclAny) pre: true post: true activity: while ((index->compareTo(n)) <= 0) do ( BITree[index+1] := BITree[index+1] + val ; index := index + MathLib.bitwiseAnd(index, (-index))); operation getInvCount(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var invcount : int := 0 ; var maxElement : OclAny := (arr)->max() ; var BIT : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (maxElement + 1)) ; for i : Integer.subrange(1, maxElement + 1-1) do ( BIT[i+1] := 0) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( invcount := invcount + getSum(BIT, arr[i+1] - 1) ; updateBIT(BIT, maxElement, arr[i+1], 1)) ; return invcount; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from collections import Counter n=int(input()) w=Counter(map(int,input().split())) x=max(w.values()) print(n-x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : OclAny := Counter((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := (w.values())->max() ; execute (n - x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) beauty=[int(i)for i in input().split()] beauty=sorted(beauty) counts={} for k in beauty : counts[k]=counts.get(k,0)+1 freq=list(counts.values()) result=0 while freq!=[0]*len(freq): round=0 for i in range(len(freq)): if freq[i]>=1 : freq[i]-=1 round+=1 result+=(round-1) print(result) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var beauty : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; beauty := beauty->sort() ; var counts : OclAny := Set{} ; for k : beauty do ( counts[k+1] := counts.get(k, 0) + 1) ; var freq : Sequence := (counts.values()) ; var result : int := 0 ; while freq /= MatrixLib.elementwiseMult(Sequence{ 0 }, (freq)->size()) do ( var round : int := 0 ; for i : Integer.subrange(0, (freq)->size()-1) do ( if freq[i+1] >= 1 then ( freq[i+1] := freq[i+1] - 1 ; round := round + 1 ) else skip) ; result := result + (round - 1)) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,s=map(int,input().split()) a=list(map(int,input().split())) ss=s l=-1 if sum(a)>=s : nn=a.count(a[0]) if nn==len(a): r=math.ceil(s/len(a)) l=a[0]-r s=-1 else : mimi=min(a) su1=sum(a) a=[mimi]*n Masha=min(a) su2=sum(a) s=s-(su1-su2) mimi=min(a) if s>0 : while s>0 : mimi-=1000 a=[mimi]*n s-=n*1000 if s==0 : a=a if s<0 : mimimi=min(a) while s<0 and mimimi+1=sum(a)+n+ss : mimimi+=1 a=[mimimi]*n s+=n l=a[0] print(l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ss : OclAny := s ; var l : int := -1 ; if ((a)->sum()->compareTo(s)) >= 0 then ( var nn : int := a->count(a->first()) ; if nn = (a)->size() then ( var r : double := (s / (a)->size())->ceil() ; l := a->first() - r ; var s : int := -1 ) else ( var mimi : OclAny := (a)->min() ; var su1 : OclAny := (a)->sum() ; a := MatrixLib.elementwiseMult(Sequence{ mimi }, n) ; var Masha : OclAny := (a)->min() ; var su2 : OclAny := (a)->sum() ; s := s - (su1 - su2) ; mimi := (a)->min() ; if s > 0 then ( while s > 0 do ( mimi := mimi - 1000 ; a := MatrixLib.elementwiseMult(Sequence{ mimi }, n) ; s := s - n * 1000) ) else skip ; if s = 0 then ( a := a ) else skip ; if s < 0 then ( var mimimi : OclAny := (a)->min() ; while s < 0 & (mimimi + 1->compareTo(Masha)) < 0 & (su1->compareTo((a)->sum() + n + ss)) >= 0 do ( mimimi := mimimi + 1 ; a := MatrixLib.elementwiseMult(Sequence{ mimimi }, n) ; s := s + n) ) else skip ; l := a->first() ) ) else skip ; execute (l)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(x)for x in input().split()] a.sort() cnt=mx=0 li=[] for i in range(1,n): if a[i]==a[i-1]: cnt+=1 else : mx=max(mx,cnt) cnt=0 print(n-max(mx,cnt)-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; a := a->sort() ; var cnt : OclAny := 0; var mx : int := 0 ; var li : Sequence := Sequence{} ; for i : Integer.subrange(1, n-1) do ( if a[i+1] = a[i - 1+1] then ( cnt := cnt + 1 ) else ( mx := Set{mx, cnt}->max() ; cnt := 0 )) ; execute (n - Set{mx, cnt}->max() - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) f,b=0,l.copy() l.sort() for i in range(len(l)-1): if l[i+1]>l[i]: f+=1 s=list(set(l)) while 1 : for i in s : b.remove(i) if len(b)==0 : break b.sort() for i in range(len(b)-1): if b[i+1]>b[i]: f+=1 s=list(set(b)) print(f) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var f : OclAny := null; var b : OclAny := null; Sequence{f,b} := Sequence{0,l->copy()} ; l := l->sort() ; for i : Integer.subrange(0, (l)->size() - 1-1) do ( if (l[i + 1+1]->compareTo(l[i+1])) > 0 then ( f := f + 1 ) else skip) ; var s : Sequence := (Set{}->union((l))) ; while 1 do ( for i : s do ( execute ((i) /: b)) ; if (b)->size() = 0 then ( break ) else skip ; b := b->sort() ; for i : Integer.subrange(0, (b)->size() - 1-1) do ( if (b[i + 1+1]->compareTo(b[i+1])) > 0 then ( f := f + 1 ) else skip) ; s := (Set{}->union((b)))) ; execute (f)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def toggleLastMBits(n,m): num=(1<display(); operation toggleLastMBits(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var num : double := (1 * (2->pow(m))) - 1 ; return (MathLib.bitwiseXor(n, num)); operation unsetLastMBits(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: num := (1 * (2->pow(((trailer . (name getsizeof) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)))))))) ))) * 8 - 1)))) - 1 ; num := toggleLastMBits(num, m) ; return (MathLib.bitwiseAnd(n, num)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout import sys def get_ints(): return map(int,sys.stdin.readline().strip().split()) def get_arr(): return list(map(int,sys.stdin.readline().strip().split())) def get_string(): return sys.stdin.readline().strip() n,q,k=get_ints() a=get_arr() prefix=[] prefix.append(int(0)) for i in range(0,len(a)-1): prefix.append(a[i+1]-a[i]-1) for i in range(1,len(prefix)): prefix[i]=prefix[i-1]+prefix[i] while q : q-=1 l,h=get_ints() ans=2*(prefix[h-1]-prefix[l-1])+a[l-1]-1+k-a[h-1] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var n : OclAny := null; var q : OclAny := null; var k : OclAny := null; Sequence{n,q,k} := get_ints() ; var a : OclAny := get_arr() ; var prefix : Sequence := Sequence{} ; execute ((("" + ((0)))->toInteger()) : prefix) ; for i : Integer.subrange(0, (a)->size() - 1-1) do ( execute ((a[i + 1+1] - a[i+1] - 1) : prefix)) ; for i : Integer.subrange(1, (prefix)->size()-1) do ( prefix[i+1] := prefix[i - 1+1] + prefix[i+1]) ; while q do ( q := q - 1 ; var l : OclAny := null; var h : OclAny := null; Sequence{l,h} := get_ints() ; var ans : double := 2 * (prefix[h - 1+1] - prefix[l - 1+1]) + a[l - 1+1] - 1 + k - a[h - 1+1] ; execute (ans)->display()); operation get_ints() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ); operation get_arr() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation get_string() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inputs=[int(num)for num in input().split()] n=inputs[0] q=inputs[1] k=inputs[2] list1=[int(num)for num in input().split()] psum=[0] for i in range(0,len(list1)): if(i+1=0): vals=list1[i+1]-list1[i-1]-2 elif(i+1select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var n : OclAny := inputs->first() ; var q : OclAny := inputs[1+1] ; var k : OclAny := inputs[2+1] ; var list1 : Sequence := input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var psum : Sequence := Sequence{ 0 } ; for i : Integer.subrange(0, (list1)->size()-1) do ( if ((i + 1->compareTo(n)) < 0 & i - 1 >= 0) then ( var vals : double := list1[i + 1+1] - list1[i - 1+1] - 2 ) else (if ((i + 1->compareTo(n)) < 0) then ( vals := list1[i + 1+1] - 2 ) else ( vals := k + 1 - list1[i - 1+1] - 2 ) ) ; execute ((psum[i+1] + vals) : psum)) ; for i : Integer.subrange(0, q-1) do ( var ans : int := 0 ; inputs := input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var l : OclAny := inputs->first() ; var r : OclAny := inputs[1+1] ; if (l = r) then ( execute (k - 1)->display() ) else ( var l1 : OclAny := l + 1 ; var r1 : double := r - 1 ; ans := psum[r1+1] - psum[l1 - 1+1] ; ans := ans + list1[l+1] - 2 ; ans := ans + k + 1 - list1[r - 2+1] - 2 ; execute (ans)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def solve(): n,q,k=map(int,input().split()) arr=list(map(int,input().split())) ps=[0]*n curr=0 for i in range(1,n-1): curr+=(arr[i]-arr[i-1]-1)+(arr[i+1]-arr[i]-1) ps[i]=curr for _ in range(q): u,v=map(int,input().split()) u-=1 v-=1 if u==v : print(k-1) else : num=arr[u]-1+(arr[u+1]-arr[u]-1)+(arr[v]-arr[v-1]-1)+k-arr[v] num+=ps[v-1]-ps[u] print(num) return solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; solve(); operation solve() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; var k : OclAny := null; Sequence{n,q,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ps : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var curr : int := 0 ; for i : Integer.subrange(1, n - 1-1) do ( curr := curr + (arr[i+1] - arr[i - 1+1] - 1) + (arr[i + 1+1] - arr[i+1] - 1) ; ps[i+1] := curr) ; for _anon : Integer.subrange(0, q-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; u := u - 1 ; v := v - 1 ; if u = v then ( execute (k - 1)->display() ) else ( var num : double := arr[u+1] - 1 + (arr[u + 1+1] - arr[u+1] - 1) + (arr[v+1] - arr[v - 1+1] - 1) + k - arr[v+1] ; num := num + ps[v - 1+1] - ps[u+1] ; execute (num)->display() )) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def k_similar_list(n,q,k,a,q_lst): variation_by_position=[] lower_bound=1 last_sum=0 for i in range(n-1): upper_bound=a[i+1] last_sum=last_sum+(upper_bound-lower_bound-1) variation_by_position.append(last_sum) lower_bound=a[i]+1 variation_by_position.append(last_sum+k-a[n-1]) for query in q_lst : start_index=query[0]-1 end_index=query[1]-1 length=end_index-start_index+1 if length==1 : print(k-1) continue option=a[start_index+1]-2 option+=variation_by_position[end_index-1]-variation_by_position[start_index] option+=k-a[end_index-1]-1 print(option) v=[int(x)for x in input().split(' ')] n=v[0] q=v[1] k=v[2] a=[int(x)for x in input().split(' ')] q_lst=[] for i in range(q): v=[int(x)for x in input().split(' ')] q_lst.append((v[0],v[1])) k_similar_list(n,q,k,a,q_lst) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var v : Sequence := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; n := v->first() ; q := v[1+1] ; k := v[2+1] ; a := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; q_lst := Sequence{} ; for i : Integer.subrange(0, q-1) do ( v := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((Sequence{v->first(), v[1+1]}) : q_lst)) ; k_similar_list(n, q, k, a, q_lst); operation k_similar_list(n : OclAny, q : OclAny, k : OclAny, a : OclAny, q_lst : OclAny) pre: true post: true activity: var variation_by_position : Sequence := Sequence{} ; var lower_bound : int := 1 ; var last_sum : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( var upper_bound : OclAny := a[i + 1+1] ; last_sum := last_sum + (upper_bound - lower_bound - 1) ; execute ((last_sum) : variation_by_position) ; lower_bound := a[i+1] + 1) ; execute ((last_sum + k - a[n - 1+1]) : variation_by_position) ; for query : q_lst do ( var start_index : double := query->first() - 1 ; var end_index : double := query[1+1] - 1 ; var length : double := end_index - start_index + 1 ; if length = 1 then ( execute (k - 1)->display() ; continue ) else skip ; var option : double := a[start_index + 1+1] - 2 ; option := option + variation_by_position[end_index - 1+1] - variation_by_position[start_index+1] ; option := option + k - a[end_index - 1+1] - 1 ; execute (option)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,q,k=map(int,input().split()) l=[int(x)for x in input().split()] pre=[] for i in range(1,n-1): pre.append(l[i+1]-l[i-1]-2) pre.insert(n,0) pre.insert(0,0) for i in range(1,n,1): pre[i]+=pre[i-1] for _ in range(q): x,y=map(int,input().split()) if y-x==0 : print(k-1) elif y-x==1 : x-=1 y-=1 print(l[y]-2+k-l[x]-1) else : y-=1 y-=1 ans=l[x]-2+k-l[y]-1 print(ans+pre[y]-pre[x-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; var k : OclAny := null; Sequence{n,q,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var pre : Sequence := Sequence{} ; for i : Integer.subrange(1, n - 1-1) do ( execute ((l[i + 1+1] - l[i - 1+1] - 2) : pre)) ; pre := pre.insertAt(n+1, 0) ; pre := pre.insertAt(0+1, 0) ; for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( pre[i+1] := pre[i+1] + pre[i - 1+1]) ; for _anon : Integer.subrange(0, q-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if y - x = 0 then ( execute (k - 1)->display() ) else (if y - x = 1 then ( x := x - 1 ; y := y - 1 ; execute (l[y+1] - 2 + k - l[x+1] - 1)->display() ) else ( y := y - 1 ; y := y - 1 ; var ans : double := l[x+1] - 2 + k - l[y+1] - 1 ; execute (ans + pre[y+1] - pre[x - 1+1])->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) for i in range(n): if a[i]% 2==0 : a[i]=a[i]-1 for j in a : print(j,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( if a[i+1] mod 2 = 0 then ( a[i+1] := a[i+1] - 1 ) else skip) ; for j : a do ( execute (j)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys ; input=sys.stdin.readline for f in range(int(input())): n,s=int(input()),input() d=set([*input().split()][1 :]) p=r=0 for i in range(n): if s[i]in d : r=max(r,i-p) p=i print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; var input : OclAny := (OclFile["System.in"]).readline ; for f : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),(OclFile["System.in"]).readLine()} ; var d : Set := Set{}->union((input().split()->tail())) ; var p : OclAny := 0; var r : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (d)->includes(s[i+1]) then ( r := Set{r, i - p}->max() ; p := i ) else skip) ; execute (r)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(x): sum=0 for i in range(0,n): sum+=v[i]-x if sum>=s : return True else : return False t=1 while t>0 : t-=1 n,s=(int(_)for _ in input().strip().split(' ')) v=list(map(int,input().split())) sum=0 l=0 r=0x3f3f3f3f for i in range(0,n): sum+=v[i] r=min(v[i],r) if sum>1 if check(mid)==True : l=mid else : r=mid-1 print(l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := 1 ; while t > 0 do ( t := t - 1 ; var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name _)))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name strip) (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ' '))))))) ))))))))} ; var v : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; sum := 0 ; var l : int := 0 ; var r : int := 0x3f3f3f3f ; for i : Integer.subrange(0, n-1) do ( sum := sum + v[i+1] ; r := Set{v[i+1], r}->min()) ; if (sum->compareTo(s)) < 0 then ( execute (-1)->display() ) else ( while (l->compareTo(r)) < 0 do ( var mid : int := (l + r + 1) /(2->pow(1)) ; if check(mid) = true then ( l := mid ) else ( r := mid - 1 )) ; execute (l)->display() )); operation check(x : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + v[i+1] - x) ; if (sum->compareTo(s)) >= 0 then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,sys ; input=sys.stdin.readline ; S=lambda : input().rstrip(); I=lambda : int(S()); M=lambda : map(int,S().split()); L=lambda : list(M()); mod1=1000000007 ; mod2=998244353 for _ in range(I()): n=I() s=S() l=list(map(str,input().split())) k=int(l.pop(0)) i=0 ; m=0 while iapply())))->toInteger()); var M : Function := lambda $$ : OclAny in ((S->apply().split())->collect( _x | (OclType["int"])->apply(_x) )); var L : Function := lambda $$ : OclAny in ((M->apply())); var mod1 : int := 1000000007; var mod2 : int := 998244353 ; for _anon : Integer.subrange(0, I->apply()-1) do ( var n : OclAny := I->apply() ; var s : OclAny := S->apply() ; var l : Sequence := ((input().split())->collect( _x | (OclType["String"])->apply(_x) )) ; var k : int := ("" + ((l->at(0`firstArg+1))))->toInteger() ; var i : int := 0; var m : int := 0 ; while (i->compareTo(n)) < 0 do ( var j : int := i ; while (j->compareTo(n)) < 0 & (l)->excludes(s[j+1]) do ( j := j + 1) ; if j = n then ( break ) else skip ; if i = 0 then ( m := Set{m, j - i}->max() ) else ( m := Set{m, j - i + 1}->max() ) ; i := j + 1) ; execute (m)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def solve(n,s,forbidden): forbidden=set(forbidden) indexes=[0] for i,x in enumerate(s): if x in forbidden : indexes.append(i) if len(indexes)==1 : return 0 maxi=max(indexes) diff_index=[] for i in range(len(indexes)-1): diff_index.append(indexes[i+1]-indexes[i]) return max(diff_index) tot=0 counts={} for x in diff_index : counts[x]=counts.get(x,0)+1 remain=len(indexes)-1 if s[0]in forbidden : remain-=1 if maxi==0 : return 0 for i in range(1,max(diff_index)+2): tot+=remain remain-=counts.get(i,0) if tot>=maxi : return i return i import os import io if __name__=="__main__" : input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline T=int(input().decode().strip()) for t in range(T): n=int(input().decode().strip()) s=input().decode().strip() forbidden=[x for x in input().decode().strip().split()] lenf=forbidden.pop(0) assert int(lenf)==len(forbidden) res=solve(n,s,forbidden) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( var input : OclAny := io.BytesIO(os.readAll()).readline ; var T : int := ("" + ((input().decode()->trim())))->toInteger() ; for t : Integer.subrange(0, T-1) do ( n := ("" + ((input().decode()->trim())))->toInteger() ; s := input().decode()->trim() ; forbidden := input().decode()->trim().split()->select(x | true)->collect(x | (x)) ; var lenf : OclAny := forbidden->at(0`firstArg+1) ; forbidden := forbidden->excludingAt(0+1) ; assert ("" + ((lenf)))->toInteger() = (forbidden)->size() do "assertion failed" ; var res : OclAny := solve(n, s, forbidden) ; execute (res)->display()) ) else skip; operation solve(n : OclAny, s : OclAny, forbidden : OclAny) : OclAny pre: true post: true activity: forbidden := Set{}->union((forbidden)) ; var indexes : Sequence := Sequence{ 0 } ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); if (forbidden)->includes(x) then ( execute ((i) : indexes) ) else skip) ; if (indexes)->size() = 1 then ( return 0 ) else skip ; var maxi : OclAny := (indexes)->max() ; var diff_index : Sequence := Sequence{} ; for i : Integer.subrange(0, (indexes)->size() - 1-1) do ( execute ((indexes[i + 1+1] - indexes[i+1]) : diff_index)) ; return (diff_index)->max() ; var tot : int := 0 ; var counts : OclAny := Set{} ; for x : diff_index do ( counts[x+1] := counts.get(x, 0) + 1) ; var remain : double := (indexes)->size() - 1 ; if (forbidden)->includes(s->first()) then ( remain := remain - 1 ) else skip ; if maxi = 0 then ( return 0 ) else skip ; for i : Integer.subrange(1, (diff_index)->max() + 2-1) do ( tot := tot + remain ; remain := remain - counts.get(i, 0) ; if (tot->compareTo(maxi)) >= 0 then ( return i ) else skip) ; return i; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def lcm(a,b): GCD=gcd(a,b); return(a*b)//GCD ; def MinLCM(a,n): Prefix=[0]*(n+2); Suffix=[0]*(n+2); Prefix[1]=a[0]; for i in range(2,n+1): Prefix[i]=lcm(Prefix[i-1],a[i-1]); Suffix[n]=a[n-1]; for i in range(n-1,0,-1): Suffix[i]=lcm(Suffix[i+1],a[i-1]); ans=min(Suffix[2],Prefix[n-1]); for i in range(2,n): ans=min(ans,lcm(Prefix[i-1],Suffix[i+1])); return ans ; if __name__=="__main__" : a=[5,15,9,36]; n=len(a); print(MinLCM(a,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( a := Sequence{5}->union(Sequence{15}->union(Sequence{9}->union(Sequence{ 36 }))); ; n := (a)->size(); ; execute (MinLCM(a, n))->display(); ) else skip; operation lcm(a : OclAny, b : OclAny) pre: true post: true activity: var GCD : OclAny := gcd(a, b); ; return (a * b) div GCD;; operation MinLCM(a : OclAny, n : OclAny) pre: true post: true activity: var Prefix : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 2)); ; var Suffix : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 2)); ; Prefix[1+1] := a->first(); ; for i : Integer.subrange(2, n + 1-1) do ( Prefix[i+1] := lcm(Prefix[i - 1+1], a[i - 1+1]);) ; Suffix[n+1] := a[n - 1+1]; ; for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( Suffix[i+1] := lcm(Suffix[i + 1+1], a[i - 1+1]);) ; var ans : OclAny := Set{Suffix[2+1], Prefix[n - 1+1]}->min(); ; for i : Integer.subrange(2, n-1) do ( ans := Set{ans, lcm(Prefix[i - 1+1], Suffix[i + 1+1])}->min();) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=[[1],[0,1]] for i in range(n-1): t=[0]+p[-1] for j in range(len(p[i])): t[j]^=p[i][j] p.append(t) print(n) print(*p[n]) print(n-1) print(*p[-2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := Sequence{Sequence{ 1 }}->union(Sequence{ Sequence{0}->union(Sequence{ 1 }) }) ; for i : Integer.subrange(0, n - 1-1) do ( var t : Sequence := Sequence{ 0 }->union(p->last()) ; for j : Integer.subrange(0, (p[i+1])->size()-1) do ( t[j+1] := t[j+1] xor p[i+1][j+1]) ; execute ((t) : p)) ; execute (n)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n)))))))) ]))))))))->display() ; execute (n - 1)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 2))))))))) ]))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=[[1],[0,1]] n=int(input()) for i in range(2,n+1): l=[0]+f[i-1] for j in range(len(f[i-2])): l[j]=(l[j]+f[i-2][j])& 1 f.append(l) print(n) print(*f[n]) print(n-1) print(*f[n-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : Sequence := Sequence{Sequence{ 1 }}->union(Sequence{ Sequence{0}->union(Sequence{ 1 }) }) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(2, n + 1-1) do ( var l : Sequence := Sequence{ 0 }->union(f[i - 1+1]) ; for j : Integer.subrange(0, (f[i - 2+1])->size()-1) do ( l[j+1] := MathLib.bitwiseAnd((l[j+1] + f[i - 2+1][j+1]), 1)) ; execute ((l) : f)) ; execute (n)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name f)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n)))))))) ]))))))))->display() ; execute (n - 1)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name f)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) ]))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[1] b=[] for _ in range(n): c=[0]+a[:] d=a[:] for i,u in enumerate(b): c[i]+=u a=[u % 2 for u in c] b=[u % 2 for u in d] print(len(a)-1) print(*a) print(len(b)-1) print(*b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{ 1 } ; var b : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var c : Sequence := Sequence{ 0 }->union(a) ; var d : Sequence := a ; for _tuple : Integer.subrange(1, (b)->size())->collect( _indx | Sequence{_indx-1, (b)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var u : OclAny := _tuple->at(_indx); c[i+1] := c[i+1] + u) ; a := c->select(u | true)->collect(u | (u mod 2)) ; b := d->select(u | true)->collect(u | (u mod 2))) ; execute ((a)->size() - 1)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display() ; execute ((b)->size() - 1)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name b))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[1] b=[] for _ in range(n): c=[0]+a[:] d=a[:] for i,u in enumerate(b): c[i]+=u a=[u % 2 for u in c] b=[u % 2 for u in d] print(len(a)-1) print(*a) print(len(b)-1) print(*b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{ 1 } ; var b : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var c : Sequence := Sequence{ 0 }->union(a) ; var d : Sequence := a ; for _tuple : Integer.subrange(1, (b)->size())->collect( _indx | Sequence{_indx-1, (b)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var u : OclAny := _tuple->at(_indx); c[i+1] := c[i+1] + u) ; a := c->select(u | true)->collect(u | (u mod 2)) ; b := d->select(u | true)->collect(u | (u mod 2))) ; execute ((a)->size() - 1)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display() ; execute ((b)->size() - 1)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name b))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def alternateFib(n): if(n<0): return-1 ; f1=0 ; f2=1 ; print(f1,end=" "); for i in range(2,n+1): f3=f2+f1 ; if(i % 2==0): print(f3,end=" "); f1=f2 ; f2=f3 ; N=15 ; alternateFib(N); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 15; ; alternateFib(N);; operation alternateFib(n : OclAny) pre: true post: true activity: if (n < 0) then ( return -1; ) else skip ; var f1 : int := 0; ; var f2 : int := 1; ; execute (f1)->display(); ; for i : Integer.subrange(2, n + 1-1) do ( var f3 : int := f2 + f1; ; if (i mod 2 = 0) then ( execute (f3)->display(); ) else skip ; f1 := f2; ; f2 := f3;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import* from decimal import* from opcode import HAVE_ARGUMENT from re import I import sys from tkinter import N input_=sys.stdin.readline def _input(): return map(int,input().split()) def _list(): return list(map(int,input().split())) a=[] def solves(a): a,b,c,d=_input() ans=abs(a-c)+abs(b-d) if(a!=c and b!=d): ans+=2 print(ans) t=1 t=int(input()) for _ in range(0,t): solves(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var input_ : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; var a : Sequence := Sequence{} ; skip ; var t : int := 1 ; t := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( solves(a)); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation _list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation solves(a : OclAny) pre: true post: true activity: var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := _input() ; var ans : double := (a - c)->abs() + (b - d)->abs() ; if (a /= c & b /= d) then ( ans := ans + 2 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import os import random import re import sys from math import gcd from math import sqrt n=int(input()) arr=list(map(int,input().split())) li=[] for i in arr : if i % 2==0 : li.append(i-1) else : li.append(i) for i in li : print(i,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var li : Sequence := Sequence{} ; for i : arr do ( if i mod 2 = 0 then ( execute ((i - 1) : li) ) else ( execute ((i) : li) )) ; for i : li do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(x): sum=0 for i in range(0,n): sum+=v[i]-x if sum>=s : return True else : return False t=1 while t>0 : t-=1 n,s=(int(_)for _ in input().strip().split(' ')) v=list(map(int,input().split())) sum=0 l=0 r=0x3f3f3f3f for i in range(0,n): sum+=v[i] r=min(v[i],r) if sum>1 if check(mid): l=mid else : r=mid-1 print(l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := 1 ; while t > 0 do ( t := t - 1 ; var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name _)))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name strip) (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ' '))))))) ))))))))} ; var v : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; sum := 0 ; var l : int := 0 ; var r : int := 0x3f3f3f3f ; for i : Integer.subrange(0, n-1) do ( sum := sum + v[i+1] ; r := Set{v[i+1], r}->min()) ; if (sum->compareTo(s)) < 0 then ( execute (-1)->display() ) else ( while (l->compareTo(r)) < 0 do ( var mid : int := (l + r + 1) /(2->pow(1)) ; if check(mid) then ( l := mid ) else ( r := mid - 1 )) ; execute (l)->display() )); operation check(x : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + v[i+1] - x) ; if (sum->compareTo(s)) >= 0 then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for g in[*open(0)][1 :]: a,b,c,d=map(int,g.split()) print(abs(a-c)+abs(b-d)+2*(a!=c and b!=d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for g : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (g.split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a - c)->abs() + (b - d)->abs() + 2 * (a /= c & b /= d))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def solve(): x1,y1,x2,y2=map(int,input().split()) return max(abs(x1-x2),abs(y1-y2))if x1==x2 or y1==y2 else abs(x2-x1)+abs(y2-y1)+2 for _ in range(int(input())): print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (solve())->display()); operation solve() : OclAny pre: true post: true activity: var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; return if x1 = x2 or y1 = y2 then Set{(x1 - x2)->abs(), (y1 - y2)->abs()}->max() else (x2 - x1)->abs() + (y2 - y1)->abs() + 2 endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while(t>0): x1,y1,x2,y2=map(int,input().split()) if x1==x2 : time=abs(y1-y2) elif y1==y2 : time=abs(x1-x2) else : time=abs(x1-x2)+abs(y1-y2)+2 print(time) t=t-1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (t > 0) do ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x1 = x2 then ( var time : double := (y1 - y2)->abs() ) else (if y1 = y2 then ( time := (x1 - x2)->abs() ) else ( time := (x1 - x2)->abs() + (y1 - y2)->abs() + 2 ) ) ; execute (time)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : a,b,c,d=map(int,input().split()) if b==d : print(abs(c-a)) elif a==c : print(abs(d-b)) else : print((abs(c-a)+1)+(abs(b-d)+1)) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if b = d then ( execute ((c - a)->abs())->display() ) else (if a = c then ( execute ((d - b)->abs())->display() ) else ( execute (((c - a)->abs() + 1) + ((b - d)->abs() + 1))->display() ) ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n,m=map(int,input().split()) if n==m==0 : break a=m-1 while a<(m-1)*n : a=int(m*a/(m-1)+1) print(n*m-a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = m & (m == 0) then ( break ) else skip ; var a : double := m - 1 ; while (a->compareTo((m - 1) * n)) < 0 do ( a := ("" + ((m * a / (m - 1) + 1)))->toInteger()) ; execute (n * m - a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,m): A=[i for i in range(1,n+1)] i=n-1 while True : if len(A)==1 : break i=(i+m)% len(A) A.pop(i) i=i-1 if i>0 else len(A)-1 return A[0] while True : n,m=map(int,input().split()) if n==m==0 : break print(solve(n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = m & (m == 0) then ( break ) else skip ; execute (solve(n, m))->display()); operation solve(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var A : Sequence := Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | (i)) ; var i : double := n - 1 ; while true do ( if (A)->size() = 1 then ( break ) else skip ; i := (i + m) mod (A)->size() ; A := A->excludingAt(i+1) ; i := if i > 0 then i - 1 else (A)->size() - 1 endif) ; return A->first(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input2.txt","rt") def josephus_survivor(n,k): people=list(range(1,n+1)) current=(k-1)% n while len(people)>1 : removed=people.pop(current) current=(current+k-1)% len(people) return people[0] while True : n,m=[int(_)for _ in input().split()] if n==m==0 : break print(josephus_survivor(n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input2.txt")) ) else skip ; skip ; while true do ( var m : OclAny := null; Sequence{n,m} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; if n = m & (m == 0) then ( break ) else skip ; execute (josephus_survivor(n, m))->display()); operation josephus_survivor(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var people : Sequence := (Integer.subrange(1, n + 1-1)) ; var current : int := (k - 1) mod n ; while (people)->size() > 1 do ( var removed : OclAny := people->at(current`firstArg+1) ; people := people->excludingAt(current+1) ; current := (current + k - 1) mod (people)->size()) ; return people->first(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque while True : n,m=map(int,input().split()) if n==0 : break q=deque([i for i in range(n)]) i=0 while True : i+=1 if i==m : q.popleft() i=0 if len(q)==1 : print(q.pop()+1) break else : q.append(q.popleft()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var q : Sequence := (Integer.subrange(0, n-1)->select(i | true)->collect(i | (i))) ; var i : int := 0 ; while true do ( i := i + 1 ; if i = m then ( q := q->tail() ; i := 0 ; if (q)->size() = 1 then ( execute (q->last() + 1)->display() ; break ) else skip ) else ( execute ((q->first()) : q) ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,m=[int(i)for i in input().split()] if n==0 and m==0 : break table=[] for i in range(n): table.append(i+1) p=m-1 for i in range(n-1): table.pop(p) p=(p+m-1)% len(table) print(table[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if n = 0 & m = 0 then ( break ) else skip ; var table : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((i + 1) : table)) ; var p : double := m - 1 ; for i : Integer.subrange(0, n - 1-1) do ( table := table->excludingAt(p+1) ; p := (p + m - 1) mod (table)->size()) ; execute (table->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,m=map(int,input().split()) x=list(map(int,input().split())) t=list(map(int,input().split())) u,v=[],[] for i,j in zip(x,t): if j : u.append(i) else : v.append(i) ans=[0]*m for i in v : j=bisect.bisect_left(u,i) if not j : ans[0]+=1 elif not j ^ m : ans[-1]+=1 else : k=j-1 if i-u[k]<=u[j]-i : ans[k]+=1 else : ans[j]+=1 sys.stdout.write(" ".join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := Sequence{Sequence{},Sequence{}} ; for _tuple : Integer.subrange(1, x->size())->collect( _indx | Sequence{x->at(_indx), t->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if j then ( execute ((i) : u) ) else ( execute ((i) : v) )) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; for i : v do ( var j : OclAny := bisect.bisect_left(u, i) ; if not(j) then ( ans->first() := ans->first() + 1 ) else (if not(MathLib.bitwiseXor(j, m)) then ( ans->last() := ans->last() + 1 ) else ( var k : double := j - 1 ; if (i - u[k+1]->compareTo(u[j+1] - i)) <= 0 then ( ans[k+1] := ans[k+1] + 1 ) else ( ans[j+1] := ans[j+1] + 1 ) ) ) ) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " ") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S,W=(int(x)for x in input().split()) if W>=S : print("unsafe") else : print("safe") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : OclAny := null; var W : OclAny := null; Sequence{S,W} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; if (W->compareTo(S)) >= 0 then ( execute ("unsafe")->display() ) else ( execute ("safe")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(x): sum=0 for i in range(0,n): sum+=v[i]-x if sum>=s : return True else : return False n,s=(int(_)for _ in input().strip().split(' ')) v=list(map(int,input().split())) sum=0 l=0 r=0x3f3f3f3f for i in range(0,n): sum+=v[i] r=min(v[i],r) if sum>1 if check(mid)==True : l=mid else : r=mid-1 print(l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name _)))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name strip) (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ' '))))))) ))))))))} ; var v : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; sum := 0 ; var l : int := 0 ; var r : int := 0x3f3f3f3f ; for i : Integer.subrange(0, n-1) do ( sum := sum + v[i+1] ; r := Set{v[i+1], r}->min()) ; if (sum->compareTo(s)) < 0 then ( execute (-1)->display() ) else ( while (l->compareTo(r)) < 0 do ( var mid : int := (l + r + 1) /(2->pow(1)) ; if check(mid) = true then ( l := mid ) else ( r := mid - 1 )) ; execute (l)->display() ); operation check(x : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + v[i+1] - x) ; if (sum->compareTo(s)) >= 0 then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) m=[] for i in l : if i % 2==0 : m.append(i-1) else : m.append(i) for i in m : print(i,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : Sequence := Sequence{} ; for i : l do ( if i mod 2 = 0 then ( execute ((i - 1) : m) ) else ( execute ((i) : m) )) ; for i : m do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : n,m=map(int,input().split()) l=list(zip(map(int,input().split()),map(int,input().split()))) l.sort() p=[] k=-1 for i in range(n+m): if l[i][1]==1 : p.append(l[i][0]) if k==-1 : k=i+1 q=[0 for j in range(m)] i=0 j=1 q[i]=k-1 while kabs(l[k][0]-p[j]): q[j]+=1 else : q[i]+=1 else : i+=1 j+=1 k+=1 while kcollect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := (Integer.subrange(1, (input().split())->collect( _x | (OclType["int"])->apply(_x) )->size())->collect( _indx | Sequence{(input().split())->collect( _x | (OclType["int"])->apply(_x) )->at(_indx), (input().split())->collect( _x | (OclType["int"])->apply(_x) )->at(_indx)} )) ; l := l->sort() ; var p : Sequence := Sequence{} ; var k : int := -1 ; for i : Integer.subrange(0, n + m-1) do ( if l[i+1][1+1] = 1 then ( execute ((l[i+1]->first()) : p) ; if k = -1 then ( k := i + 1 ) else skip ) else skip) ; var q : Sequence := Integer.subrange(0, m-1)->select(j | true)->collect(j | (0)) ; var i : int := 0 ; var j : int := 1 ; q[i+1] := k - 1 ; while (k->compareTo(n + m)) < 0 & (j->compareTo((p)->size())) < 0 do ( if l[k+1][1+1] = 0 then ( if ((l[k+1]->first() - p[i+1])->abs()->compareTo((l[k+1]->first() - p[j+1])->abs())) > 0 then ( q[j+1] := q[j+1] + 1 ) else ( q[i+1] := q[i+1] + 1 ) ) else ( i := i + 1 ; j := j + 1 ) ; k := k + 1) ; while (k->compareTo(n + m)) < 0 do ( if l[k+1][1+1] = 0 then ( q[i+1] := q[i+1] + 1 ) else skip ; k := k + 1) ; execute ((argument * (test (logical_test (comparison (expr (atom (name q))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p=lambda : map(int,input().split()) n,m=p() a=[[],[]] for x,y in zip(p(),p()): a[y]+=[x] r,d=a s,i=[0]*m,0 for x in r : while id[i]+d[i+1]: i+=1 s[i]+=1 print(*s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := p->apply() ; var a : Sequence := Sequence{Sequence{}}->union(Sequence{ Sequence{} }) ; for _tuple : Integer.subrange(1, p->apply()->size())->collect( _indx | Sequence{p->apply()->at(_indx), p->apply()->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); a[y+1] := a[y+1] + Sequence{ x }) ; var r : OclAny := null; var d : OclAny := null; Sequence{r,d} := a ; var s : OclAny := null; var i : OclAny := null; Sequence{s,i} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, m),0} ; for x : r do ( while (i->compareTo(m - 1)) < 0 & (2 * x->compareTo(d[i+1] + d[i + 1+1])) > 0 do ( i := i + 1) ; s[i+1] := s[i+1] + 1) ; execute ((argument * (test (logical_test (comparison (expr (atom (name s))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().strip().split()) x=list(map(int,input().strip().split())) taxi=list(map(int,input().strip().split())) pos={} taxnum=0 for i in range(n+m): if taxi[i]==1 : pos[taxnum]=i taxnum+=1 ans=[0 for i in range(m)] curr=0 i=0 while taxi[i]==0 : ans[curr]+=1 i+=1 if i>=n+m : break for j in range(i,n+m): if taxi[j]==1 : curr+=int(j!=i) continue if curr+1trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var taxi : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var pos : OclAny := Set{} ; var taxnum : int := 0 ; for i : Integer.subrange(0, n + m-1) do ( if taxi[i+1] = 1 then ( pos[taxnum+1] := i ; taxnum := taxnum + 1 ) else skip) ; var ans : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (0)) ; var curr : int := 0 ; var i : int := 0 ; while taxi[i+1] = 0 do ( ans[curr+1] := ans[curr+1] + 1 ; i := i + 1 ; if (i->compareTo(n + m)) >= 0 then ( break ) else skip) ; for j : Integer.subrange(i, n + m-1) do ( if taxi[j+1] = 1 then ( curr := curr + ("" + ((j /= i)))->toInteger() ; continue ) else skip ; if (curr + 1->compareTo((pos)->size())) < 0 then ( if (x[pos[curr + 1+1]+1] - x[j+1]->compareTo(x[j+1] - x[pos[curr+1]+1])) < 0 then ( ans[curr + 1+1] := ans[curr + 1+1] + 1 ) else ( ans[curr+1] := ans[curr+1] + 1 ) ) else ( ans[curr+1] := ans[curr+1] + 1 )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def run(): s=input().strip() stack=[] res=0 for c in s : if len(stack)>0 and stack[-1]==c : stack.pop() res+=10 else : stack.append(c) res+=len(stack)//2*5 return res tc=int(input()) for i in range(tc): res=run() print("Case #%d: %s" %(i+1,res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var tc : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, tc-1) do ( res := run() ; execute (StringLib.format("Case #%d: %s",Sequence{i + 1, res}))->display()); operation run() : OclAny pre: true post: true activity: var s : OclAny := input()->trim() ; var stack : Sequence := Sequence{} ; var res : int := 0 ; for c : s do ( if (stack)->size() > 0 & stack->last() = c then ( stack := stack->front() ; res := res + 10 ) else ( execute ((c) : stack) )) ; res := res + (stack)->size() div 2 * 5 ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- __author__='Tianren Liu' import sys import numpy as np def solve(S): n=len(S) mat=np.zeros([n+1,n+1],int) for l in range(2,n+1,2): for s in range(n+1-l): t=s+l mat[s,t]=max([mat[s+1,j]+mat[j+1,t]+(10 if S[s]==S[j]else 5)for j in range(s+1,t+1,2)]) return mat[0,n] if __name__=="__main__" : T=int(sys.stdin.readline()) for t in range(T): S=sys.stdin.readline() S=[s for s in S if s in{'J','C'}] print("Case #{}:{}".format(t+1,solve(S))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var __author__ : String := 'Tianren Liu' ; skip ; skip ; skip ; if __name__ = "__main__" then ( var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(0, T-1) do ( S := (OclFile["System.in"]).readLine() ; S := S->select(s | (Set{'J'}->union(Set{ 'C' }))->includes(s))->collect(s | (s)) ; execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{t + 1, solve(S)}))->display()) ) else skip; operation solve(S : OclAny) : OclAny pre: true post: true activity: var n : int := (S)->size() ; var mat : Sequence := MatrixLib.singleValueMatrix(Sequence{n + 1}->union(Sequence{ n + 1 }), 0.0) ; for l : Integer.subrange(2, n + 1-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( for s : Integer.subrange(0, n + 1 - l-1) do ( var t : OclAny := s + l ; mat[s+1][t+1] := (Integer.subrange(s + 1, t + 1-1)->select( $x | ($x - s + 1) mod 2 = 0 )->select(j | true)->collect(j | (mat[s + 1+1][j+1] + mat[j + 1+1][t+1] + (if S[s+1] = S[j+1] then 10 else 5 endif))))->max())) ; return mat->first()[n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def initialize_solver(): pass def solve_testcase(): s=read(False,str) c1=0 c2=0 j1=0 j2=0 for i in range(len(s)): if i % 2==0 : if s[i]=="C" : c1+=1 else : j1+=1 else : if s[i]=="C" : c2+=1 else : j2+=1 return 10*(min([c1,c2])+min([j1,j2]))+5*abs(c1-c2) output_format="Case #%d: " filename=input().strip() sfile=None tfile=None if filename!="" : sfile=open(filename+".in","r") sfile.seek(0) tfile=open(filename+".out","w") def read(split=True,rettype=int): if sfile : input_line=sfile.readline().strip() else : input_line=input().strip() if split : return list(map(rettype,input_line.split())) else : return rettype(input_line) def write(s="\n"): if s is None : s="" if isinstance(s,list): s="".join(map(str,s)) s=str(s) if tfile : tfile.write(s) else : print(s,end="") if output_format==0 : solve_testcase() else : initialize_solver() total_cases=read(split=False) for case_number in range(1,total_cases+1): write(output_format.replace("%d",str(case_number))) write(solve_testcase()) write("\n") if tfile is not None : tfile.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var output_format : String := "Case #%d: " ; var filename : OclAny := input()->trim() ; var sfile : OclAny := null ; var tfile : OclAny := null ; if filename /= "" then ( sfile := OclFile.newOclFile_Write(OclFile.newOclFile(filename + ".in")) ; sfile.setPosition(0) ; tfile := OclFile.newOclFile_Write(OclFile.newOclFile(filename + ".out")) ) else skip ; skip ; skip ; if output_format = 0 then ( solve_testcase() ) else ( initialize_solver() ; var total_cases : OclAny := read((argument (test (logical_test (comparison (expr (atom (name split)))))) = (test (logical_test (comparison (expr (atom (name False)))))))) ; for case_number : Integer.subrange(1, total_cases + 1-1) do ( write(output_format.replace("%d", ("" + ((case_number))))) ; write(solve_testcase()) ; write("\n")) ) ; if not(tfile <>= null) then ( tfile.closeFile() ) else skip; operation initialize_solver() pre: true post: true activity: skip; operation solve_testcase() : OclAny pre: true post: true activity: var s : OclAny := read(false, OclType["String"]) ; var c1 : int := 0 ; var c2 : int := 0 ; var j1 : int := 0 ; var j2 : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if i mod 2 = 0 then ( if s[i+1] = "C" then ( c1 := c1 + 1 ) else ( j1 := j1 + 1 ) ) else ( if s[i+1] = "C" then ( c2 := c2 + 1 ) else ( j2 := j2 + 1 ) )) ; return 10 * ((Sequence{c1}->union(Sequence{ c2 }))->min() + (Sequence{j1}->union(Sequence{ j2 }))->min()) + 5 * (c1 - c2)->abs(); operation read(split : OclAny, rettype : OclAny) : OclAny pre: true post: true activity: if split->oclIsUndefined() then split := true else skip; if rettype->oclIsUndefined() then rettype := OclType["int"] else skip; if sfile then ( var input_line : OclAny := sfile.readLine()->trim() ) else ( input_line := input()->trim() ) ; if split then ( return ((input_line.split())->collect( _x | (rettype)->apply(_x) )) ) else ( return rettype(input_line) ); operation write(s : String) pre: true post: true activity: if s->oclIsUndefined() then s := "\n" else skip; if s <>= null then ( s := "" ) else skip ; if (OclType["Sequence"]).isInstance(s) then ( s := StringLib.sumStringsWithSeparator(((s)->collect( _x | (OclType["String"])->apply(_x) )), "") ) else skip ; s := ("" + ((s))) ; if tfile then ( tfile.write(s) ) else ( execute (s)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,inspect problemName='A' testCase='large' attempt=0 def solution(preferences): totalTaken=0 holding=[] points=0 for c in preferences : if len(holding)==0 or holding[-1]!=c : if totalTaken==len(preferences)/2 : holding.pop() points+=5 else : holding.append(c) totalTaken+=1 else : holding.pop() points+=10 return points currentDir=os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) if testCase in['large','example']: inputString=problemName+('-%s' % testCase) outputString=problemName+('-%s' % testCase) else : inputString=problemName+('-%s-attempt%d' %(testCase,attempt)) outputString=problemName+('-%s' % testCase) inFile=os.path.join(currentDir,'inputfiles','%s.in' % inputString) outFile=os.path.join(currentDir,'outputfiles','%s.out' % outputString) if os.path.exists(outFile): os.remove(outFile) with open(inFile,'r')as inputfile : numberOfCases=int(inputfile.readline()) for case in xrange(1,numberOfCases+1): result=solution(inputfile.readline().strip()) with open(outFile,'a')as f : f.write('Case #%d: %d\n' %(case,result)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var problemName : String := 'A' ; var testCase : String := 'large' ; var attempt : int := 0 ; skip ; var currentDir : OclAny := os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) ; if (Sequence{'large'}->union(Sequence{ 'example' }))->includes(testCase) then ( var inputString : String := problemName + (StringLib.format('-%s',testCase)) ; var outputString : String := problemName + (StringLib.format('-%s',testCase)) ) else ( inputString := problemName + (StringLib.format('-%s-attempt%d',Sequence{testCase, attempt})) ; outputString := problemName + (StringLib.format('-%s',testCase)) ) ; var inFile : OclAny := os.path.join(currentDir, 'inputfiles', StringLib.format('%s.in',inputString)) ; var outFile : OclAny := os.path.join(currentDir, 'outputfiles', StringLib.format('%s.out',outputString)) ; if os.path.exists(outFile) then ( execute ((outFile) /: os) ) else skip ; try (var inputfile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(inFile)); var numberOfCases : int := ("" + ((inputfile.readLine())))->toInteger() ; for case : xrange(1, numberOfCases + 1) do ( var result : OclAny := solution(inputfile.readLine()->trim()) ; try (var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(outFile)); f.write(StringLib.format('Case #%d: %d ',Sequence{case, result}))) catch (_e : OclException) do skip)) catch (_e : OclException) do skip; operation solution(preferences : OclAny) : OclAny pre: true post: true activity: var totalTaken : int := 0 ; var holding : Sequence := Sequence{} ; var points : int := 0 ; for c : preferences do ( if (holding)->size() = 0 or holding->last() /= c then ( if totalTaken = (preferences)->size() / 2 then ( holding := holding->front() ; points := points + 5 ) else ( execute ((c) : holding) ; totalTaken := totalTaken + 1 ) ) else ( holding := holding->front() ; points := points + 10 )) ; return points; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) def solve(s): assert(len(s)% 2==0) k=len(s)//2 stack=[] score=0 for i in range(len(s)): if(stack==[]or s[i]!=stack[-1])and k>0 : k-=1 stack.append(s[i]) else : e=stack.pop() if e==s[i]: score+=10 else : score+=5 return score for i in range(t): print("Case #%d:" %(i+1),end=" ") s=input().strip() print(solve(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; for i : Integer.subrange(0, t-1) do ( execute (StringLib.format("Case #%d:",(i + 1)))->display() ; s := input()->trim() ; execute (solve(s))->display()); operation solve(s : OclAny) : OclAny pre: true post: true activity: assert ((s)->size() mod 2 = 0) do "assertion failed" ; var k : int := (s)->size() div 2 ; var stack : Sequence := Sequence{} ; var score : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if (stack = Sequence{} or s[i+1] /= stack->last()) & k > 0 then ( k := k - 1 ; execute ((s[i+1]) : stack) ) else ( var e : OclAny := stack->last() ; stack := stack->front() ; if e = s[i+1] then ( score := score + 10 ) else ( score := score + 5 ) )) ; return score; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) W=list(map(int,input().split())) abs_list=list() for i in range(len(W)): abs_list.append(abs(sum(W[: i+1])-sum(W[i+1 :]))) print(min(abs_list)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var W : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var abs_list : Sequence := () ; for i : Integer.subrange(0, (W)->size()-1) do ( execute ((((W.subrange(1,i + 1))->sum() - (W.subrange(i + 1+1))->sum())->abs()) : abs_list)) ; execute ((abs_list)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def longestSubstring(s): cnt=1 ; maxi=1 ; n=len(s); for i in range(1,n): if(s[i]!=s[i-1]): cnt+=1 ; else : maxi=max(cnt,maxi); cnt=1 ; maxi=max(cnt,maxi); return maxi ; if __name__=="__main__" : s="ccccdeededff" ; print(longestSubstring(s)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "ccccdeededff"; ; execute (longestSubstring(s))->display(); ) else skip; operation longestSubstring(s : OclAny) pre: true post: true activity: var cnt : int := 1; ; var maxi : int := 1; ; var n : int := (s)->size(); ; for i : Integer.subrange(1, n-1) do ( if (s[i+1] /= s[i - 1+1]) then ( cnt := cnt + 1; ) else ( maxi := Set{cnt, maxi}->max(); ; cnt := 1; )) ; maxi := Set{cnt, maxi}->max(); ; return maxi;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,radians from itertools import accumulate,permutations,combinations,product,groupby from operator import itemgetter,mul from copy import deepcopy from string import ascii_lowercase,ascii_uppercase,digits from bisect import bisect,bisect_left from fractions import gcd from heapq import heappush,heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) def ZIP(n): return zip(*(MAP()for _ in range(n))) sys.setrecursionlimit(10**9) INF=float('inf') mod=10**9+7 N=INT() W=LIST() S1=W[0] S2=sum(W)-S1 diff=abs(S1-S2) for T in range(1,N-1): S1+=W[T] S2-=W[T] diff2=abs(S1-S2) diff=min(diff,diff2) print(diff) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var N : OclAny := INT() ; var W : OclAny := LIST() ; var S1 : OclAny := W->first() ; var S2 : double := (W)->sum() - S1 ; var diff : double := (S1 - S2)->abs() ; for T : Integer.subrange(1, N - 1-1) do ( S1 := S1 + W[T+1] ; S2 := S2 - W[T+1] ; var diff2 : double := (S1 - S2)->abs() ; diff := Set{diff, diff2}->min()) ; execute (diff)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ZIP(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))`third->at(_indx)} ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=[int(x)for x in input().split()] for i in range(len(arr)): if arr[i]% 2==0 : arr[i]=arr[i]-1 [print(x,end=" ")for x in arr] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for i : Integer.subrange(0, (arr)->size()-1) do ( if arr[i+1] mod 2 = 0 then ( arr[i+1] := arr[i+1] - 1 ) else skip) ; ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) W=[int(i)for i in input().split()] lr=[0]*N rl=[0]*N lr[0]=W[0] rl[-1]=W[-1] for i in range(1,N): lr[i]=W[i]+lr[i-1] for i in range(0,N-1)[: :-1]: rl[i]=W[i]+rl[i+1] sub=[10000]*N for i in range(N-1): sub[i]=abs(lr[i]-rl[i+1]) T=sub.index(min(sub)) print(abs(lr[T]-rl[T+1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var W : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var lr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var rl : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; lr->first() := W->first() ; rl->last() := W->last() ; for i : Integer.subrange(1, N-1) do ( lr[i+1] := W[i+1] + lr[i - 1+1]) ; for i : range(0, N - 1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( rl[i+1] := W[i+1] + rl[i + 1+1]) ; var sub : Sequence := MatrixLib.elementwiseMult(Sequence{ 10000 }, N) ; for i : Integer.subrange(0, N - 1-1) do ( sub[i+1] := (lr[i+1] - rl[i + 1+1])->abs()) ; var T : int := sub->indexOf((sub)->min()) - 1 ; execute ((lr[T+1] - rl[T + 1+1])->abs())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin N=int(stdin.readline().rstrip()) ws=[int(x)for x in stdin.readline().rstrip().split()] tmp1=0 tmp2=0 minv=1000000000 for i in range(1,N): tmp1=sum(ws[: i]) tmp2=sum(ws[i :]) minv=min(minv,abs(tmp1-tmp2)) print(minv) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + ((stdin.readLine().rstrip())))->toInteger() ; var ws : Sequence := stdin.readLine().rstrip().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var tmp1 : int := 0 ; var tmp2 : int := 0 ; var minv : int := 1000000000 ; for i : Integer.subrange(1, N-1) do ( tmp1 := (ws.subrange(1,i))->sum() ; tmp2 := (ws.subrange(i+1))->sum() ; minv := Set{minv, (tmp1 - tmp2)->abs()}->min()) ; execute (minv)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) w=list(map(int,input().split())) mini=abs(sum(w[0 : 1])-sum(w[1 :])) for k in range(1,n): sumL=sum(w[0 : k]) sumR=sum(w[k :]) diff=abs(sumL-sumR) if mini>diff : mini=diff print(mini) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mini : double := ((w.subrange(0+1, 1))->sum() - (w->tail())->sum())->abs() ; for k : Integer.subrange(1, n-1) do ( var sumL : OclAny := (w.subrange(0+1, k))->sum() ; var sumR : OclAny := (w.subrange(k+1))->sum() ; var diff : double := (sumL - sumR)->abs() ; if (mini->compareTo(diff)) > 0 then ( mini := diff ) else skip) ; execute (mini)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import fractions infile=sys.stdin def genprimes(): composites={} candidate=2 while True : if candidate not in composites : yield candidate composites[candidate*candidate]=[candidate] else : for p in composites[candidate]: composites.setdefault(p+candidate,[]).append(p) del composites[candidate] candidate+=1 powers=set() pmax=1e12 for p in genprimes(): power=p*p if power>pmax : break while power=p) T=int(infile.readline()) for i in xrange(T): N=int(infile.readline()) print("Case #%d: %d" %(i+1,get_spread(N))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var infile : OclFile := OclFile["System.in"] ; skip ; var powers : Set := Set{}->union(()) ; var pmax : double := ("1e12")->toReal() ; for p : OclIterator.newOclIterator_Function(lambda _i : int in self.genprimes(_i)) do ( var power : double := p * p ; if (power->compareTo(pmax)) > 0 then ( break ) else skip ; while (power->compareTo(pmax)) < 0 do ( execute ((power) : powers) ; power := power * p)) ; skip ; var T : int := ("" + ((infile.readLine())))->toInteger() ; for i : xrange(T) do ( N := ("" + ((infile.readLine())))->toInteger() ; execute (StringLib.format("Case #%d: %d",Sequence{i + 1, get_spread(N)}))->display()); operation genprimes(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; var composites : OclAny := Set{} ; var candidate : int := 2 ; while true do ( if (composites)->excludes(candidate) then ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return candidate ; composites[candidate * candidate+1] := Sequence{ candidate } ) else ( for p : composites[candidate+1] do ((expr (atom (name composites)) (trailer . (name setdefault) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name p))) + (expr (atom (name candidate)))))))) , (argument (test (logical_test (comparison (expr (atom [ ]))))))) ))) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p)))))))) ))))) ; execute (composites[candidate+1])->isDeleted() ) ; candidate := candidate + 1); operation get_spread(N : OclAny) : OclAny pre: true post: true activity: if N = 1 then ( return 0 ) else skip ; return 1 + ((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name p)))) in (logical_test (comparison (expr (atom (name powers))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name N)))) >= (comparison (expr (atom (name p)))))))))))->sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def memoized(func): mem={} def wrapped(*args): if args not in mem : mem[args]=func(*args) return mem[args] return wrapped TASK="C" print("Precalculation...") import math def isprime(num,primes): s=math.sqrt(num) for p in primes : if p>s : return True if num % p==0 : return False return True primes=[] for i in xrange(2,10**6+1): if isprime(i,primes): primes.append(i) print("Precalculation done.") print("Calculation...") with open(TASK+".in")as infile : with open(TASK+".out",mode="wt")as outfile : cases=int(infile.readline()) for ncase in range(cases): N=int(infile.readline()) s=math.sqrt(N) ans=0 for p in primes : if p>s : break ans+=int(math.log(N,p))-1 if N>1 : ans+=1 outfile.write("Case #{nc}:{data}\n".format(nc=ncase+1,data=ans)) print("Calculation done.") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var TASK : String := "C" ; execute ("Precalculation...")->display() ; skip ; skip ; primes := Sequence{} ; for i : xrange(2, (10)->pow(6) + 1) do ( if isprime(i, primes) then ( execute ((i) : primes) ) else skip) ; execute ("Precalculation done.")->display() ; execute ("Calculation...")->display() ; try (var infile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(TASK + ".in")); try (var outfile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(TASK + ".out")); var cases : int := ("" + ((infile.readLine())))->toInteger() ; for ncase : Integer.subrange(0, cases-1) do ( var N : int := ("" + ((infile.readLine())))->toInteger() ; s := (N)->sqrt() ; var ans : int := 0 ; for p : primes do ( if (p->compareTo(s)) > 0 then ( break ) else skip ; ans := ans + ("" + (((N, p)->log())))->toInteger() - 1) ; if N > 1 then ( ans := ans + 1 ) else skip ; outfile.write(StringLib.interpolateStrings("Case #{nc}:{data}\n", Sequence{(argument (test (logical_test (comparison (expr (atom (name nc)))))) = (test (logical_test (comparison (expr (expr (atom (name ncase))) + (expr (atom (number (integer 1))))))))), (argument (test (logical_test (comparison (expr (atom (name data)))))) = (test (logical_test (comparison (expr (atom (name ans)))))))})))) catch (_e : OclException) do skip) catch (_e : OclException) do skip ; execute ("Calculation done.")->display(); operation memoized(func : OclAny) : OclAny pre: true post: true activity: var mem : OclAny := Set{} ; skip ; return wrapped; operation isprime(num : OclAny, primes : OclAny) : OclAny pre: true post: true activity: var s : double := (num)->sqrt() ; for p : primes do ( if (p->compareTo(s)) > 0 then ( return true ) else skip ; if num mod p = 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys cache={} def is_prime(n): if n in cache : return cache[n] cache[n]=kk(n) return cache[n] def kk(n): if n==2 : return True if n % 2==0 : return False x=3 while x*x<=n : if n % x==0 : return False x+=2 return True def primes(n): res=[2] i=3 while i*i<=n : if is_prime(i): res.append(i) i+=2 return res def foo(ifile): n=int(ifile.readline()) if(n==1): return 0 res=0 for x in primes : if x*x>n : break t=x*x while t<=n : res+=1 t*=x return res+1 primes=[2] def create_primes(): x=3 while x*x<=10**12 : if is_prime(x): primes.append(x) x+=2 def main(ifile,ofile): create_primes() n=int(ifile.readline()) for i in range(n): ofile.write("Case #%s: %s\n" %(i+1,foo(ifile))) main(sys.stdin,sys.stdout) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var cache : OclAny := Set{} ; skip ; skip ; skip ; skip ; var primes : Sequence := Sequence{ 2 } ; skip ; skip ; main(OclFile["System.in"], OclFile["System.out"]); operation is_prime(n : OclAny) : OclAny pre: true post: true activity: if (cache)->includes(n) then ( return cache[n+1] ) else skip ; cache[n+1] := kk(n) ; return cache[n+1]; operation kk(n : OclAny) : OclAny pre: true post: true activity: if n = 2 then ( return true ) else skip ; if n mod 2 = 0 then ( return false ) else skip ; var x : int := 3 ; while (x * x->compareTo(n)) <= 0 do ( if n mod x = 0 then ( return false ) else skip ; x := x + 2) ; return true; operation primes(n : OclAny) : OclAny pre: true post: true activity: var res : Sequence := Sequence{ 2 } ; var i : int := 3 ; while (i * i->compareTo(n)) <= 0 do ( if is_prime(i) then ( execute ((i) : res) ) else skip ; i := i + 2) ; return res; operation foo(ifile : OclAny) : OclAny pre: true post: true activity: n := ("" + ((ifile.readLine())))->toInteger() ; if (n = 1) then ( return 0 ) else skip ; res := 0 ; for x : primes do ( if (x * x->compareTo(n)) > 0 then ( break ) else skip ; var t : int := x * x ; while (t->compareTo(n)) <= 0 do ( res := res + 1 ; t := t * x)) ; return MatrixLib.elementwiseAdd(res, 1); operation create_primes() pre: true post: true activity: x := 3 ; while (x * x->compareTo((10)->pow(12))) <= 0 do ( if is_prime(x) then ( execute ((x) : primes) ) else skip ; x := x + 2); operation main(ifile : OclAny, ofile : OclAny) pre: true post: true activity: create_primes() ; n := ("" + ((ifile.readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( ofile.write(StringLib.format("Case #%s: %s\n",Sequence{i + 1, foo(ifile)}))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* def sieve(n): s=[True]*n for i in range(3,int(n**0.5)+1,2): if s[i]: s[i*i : : 2*i]=[False]*((n-i*i-1)//(2*i)+1) return[2]+[i for i in range(3,n,2)if s[i]] with open('input.in','r')as fin : with open('output.txt','w')as fout : numcases=int(fin.readline()) primes=sieve(1000000) for casenum in range(1,numcases+1): print(casenum) numpeople=int(fin.readline()) spread=0 if numpeople>1 : spread=1 for i in range(len(primes)): if(primes[i]*primes[i]>numpeople): break mult=primes[i]*primes[i] while(mult<=numpeople): spread+=1 mult*=primes[i] i+=1 solnstr=str(spread) fout.write("Case #"+str(casenum)+": "+solnstr+'\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; try (var fin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('input.in')); try (var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('output.txt')); var numcases : int := ("" + ((fin.readLine())))->toInteger() ; var primes : OclAny := sieve(1000000) ; for casenum : Integer.subrange(1, numcases + 1-1) do ( execute (casenum)->display() ; var numpeople : int := ("" + ((fin.readLine())))->toInteger() ; var spread : int := 0 ; if numpeople > 1 then ( spread := 1 ) else skip ; for i : Integer.subrange(0, (primes)->size()-1) do ( if ((primes[i+1] * primes[i+1]->compareTo(numpeople)) > 0) then ( break ) else skip ; var mult : double := primes[i+1] * primes[i+1] ; while ((mult->compareTo(numpeople)) <= 0) do ( spread := spread + 1 ; mult := mult * primes[i+1]) ; i := i + 1) ; var solnstr : String := ("" + ((spread))) ; fout.write("Case #" + ("" + ((casenum))) + ": " + solnstr + ' '))) catch (_e : OclException) do skip) catch (_e : OclException) do skip; operation sieve(n : OclAny) : OclAny pre: true post: true activity: var s : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, n) ; for i : Integer.subrange(3, ("" + (((n)->pow(0.5))))->toInteger() + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if s[i+1] then ( s(subscript (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom (name i))))))) : (sliceop : (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name i))))))))) := MatrixLib.elementwiseMult(Sequence{ false }, ((n - i * i - 1) div (2 * i) + 1)) ) else skip) ; return Sequence{ 2 }->union(Integer.subrange(3, n-1)->select( $x | ($x - 3) mod 2 = 0 )->select(i | s[i+1])->collect(i | (i))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): while b>0 : (a,b)=(b,a % b) return a def isprime(n): if n==2 : return True i=2 while n % i!=0 and i**2 0 do (suite); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) ans=[i for i in range(50)] for i in range(50): ans[-1-i]+=k//50 for i in range(k % 50): ans[-1-i]+=1 print(50) print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Integer.subrange(0, 50-1)->select(i | true)->collect(i | (i)) ; for i : Integer.subrange(0, 50-1) do ( ans->reverse()->at(-(-1 - i)) := ans->reverse()->at(-(-1 - i)) + k div 50) ; for i : Integer.subrange(0, k mod 50-1) do ( ans->reverse()->at(-(-1 - i)) := ans->reverse()->at(-(-1 - i)) + 1) ; execute (50)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000000000 ; def findTriangle(S): X1=0 ; Y1=0 ; X2=MAX ; Y2=1 ; X3=(MAX-S % MAX)% MAX ; Y3=(S+X3)/MAX ; print("(",X1,",",Y1,")"); print("(",X2,",",Y2,")"); print("(",X3,",",Y3,")"); if __name__=="__main__" : S=4 ; findTriangle(S); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1000000000; ; skip ; if __name__ = "__main__" then ( S := 4; ; findTriangle(S); ) else skip; operation findTriangle(S : OclAny) pre: true post: true activity: var X1 : int := 0; var Y1 : int := 0; ; var X2 : int := MAX; var Y2 : int := 1; ; var X3 : int := (MAX - S mod MAX) mod MAX; ; var Y3 : double := (S + X3) / MAX; ; execute ("(")->display(); ; execute ("(")->display(); ; execute ("(")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s1=[] s2=[] a=0 s=input() for i in range(len(s)): if s[i]=="\\" : s1.append(i) elif s[i]=="/" and len(s1)>0 : j=s1.pop() a+=i-j a_splt=i-j while(len(s2)>0 and s2[-1][0]>j): a_splt+=s2.pop()[1] s2.append([j,a_splt]) print(a) ans="" ans+=str(len(s2)) for area in s2 : ans+=" "+str(area[1]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s1 : Sequence := Sequence{} ; var s2 : Sequence := Sequence{} ; var a : int := 0 ; var s : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = "\\" then ( execute ((i) : s1) ) else (if s[i+1] = "/" & (s1)->size() > 0 then ( var j : OclAny := s1->last() ; s1 := s1->front() ; a := a + i - j ; var a_splt : double := i - j ; while ((s2)->size() > 0 & (s2->last()->first()->compareTo(j)) > 0) do ( a_splt := a_splt + s2->last()[1+1]) ; execute ((Sequence{j}->union(Sequence{ a_splt })) : s2) ) else skip)) ; execute (a)->display() ; var ans : String := "" ; ans := ans + ("" + (((s2)->size()))) ; for area : s2 do ( ans := ans + " " + ("" + ((area[1+1])))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split()))[: n] l1=[] for i in l : if i % 2==0 : l1.append(i-1) else : l1.append(i) for i in l1 : print(i,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ; var l1 : Sequence := Sequence{} ; for i : l do ( if i mod 2 = 0 then ( execute ((i - 1) : l1) ) else ( execute ((i) : l1) )) ; for i : l1 do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calc(s): shape=[ch for ch in s] left_x=[] pool_area=[] for x,sh in enumerate(shape): if sh=="\\" : left_x.append(x) elif left_x and sh=="/" : lx=left_x.pop() area=x-lx while pool_area and(pool_area[-1])[0]>lx : area+=(pool_area.pop())[1] pool_area.append((lx,area)) return[p[1]for p in pool_area] def test(): assert calc(r"\ ".strip())==[] assert calc(r"/".strip())==[] assert calc(r"\/".strip())==[1] assert calc(r"\_/".strip())==[2] assert calc(r"\//".strip())==[1] assert calc(r"\\/".strip())==[1] assert calc(r"\\//".strip())==[4] assert calc(r"\\//\\//".strip())==[4,4] assert calc(r"\\/\//".strip())==[7] assert calc(r"\\/_\//".strip())==[8] assert calc(r"\//\\/".strip())==[1,1] assert calc(r"\//_\\/".strip())==[1,1] assert calc(r"\//\\//".strip())==[1,4] assert calc(r"\///\\\//".strip())==[1,4] assert calc(r"\///\\\//\ ".strip())==[1,4] exit() pool_area=calc(input()) print(sum(pool_area)) print(len(pool_area),*pool_area) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; pool_area := calc((OclFile["System.in"]).readLine()) ; execute ((pool_area)->sum())->display() ; execute ((pool_area)->size())->display(); operation calc(s : OclAny) : OclAny pre: true post: true activity: var shape : Sequence := s->select(ch | true)->collect(ch | (ch)) ; var left_x : Sequence := Sequence{} ; var pool_area : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (shape)->size())->collect( _indx | Sequence{_indx-1, (shape)->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var sh : OclAny := _tuple->at(_indx); if sh = "\\" then ( execute ((x) : left_x) ) else (if left_x & sh = "/" then ( var lx : OclAny := left_x->last() ; left_x := left_x->front() ; var area : double := x - lx ; while pool_area & ((pool_area->last())->first()->compareTo(lx)) > 0 do ( area := area + (pool_area->last())[1+1]) ; execute ((Sequence{lx, area}) : pool_area) ) else skip)) ; return pool_area->select(p | true)->collect(p | (p[1+1])); operation test() pre: true post: true activity: assert calc(StringLib.rawString("\ ")->trim()) = Sequence{} do "assertion failed" ; assert calc(StringLib.rawString("/")->trim()) = Sequence{} do "assertion failed" ; assert calc(StringLib.rawString("\/")->trim()) = Sequence{ 1 } do "assertion failed" ; assert calc(StringLib.rawString("\_/")->trim()) = Sequence{ 2 } do "assertion failed" ; assert calc(StringLib.rawString("\//")->trim()) = Sequence{ 1 } do "assertion failed" ; assert calc(StringLib.rawString("\\/")->trim()) = Sequence{ 1 } do "assertion failed" ; assert calc(StringLib.rawString("\\//")->trim()) = Sequence{ 4 } do "assertion failed" ; assert calc(StringLib.rawString("\\//\\//")->trim()) = Sequence{4}->union(Sequence{ 4 }) do "assertion failed" ; assert calc(StringLib.rawString("\\/\//")->trim()) = Sequence{ 7 } do "assertion failed" ; assert calc(StringLib.rawString("\\/_\//")->trim()) = Sequence{ 8 } do "assertion failed" ; assert calc(StringLib.rawString("\//\\/")->trim()) = Sequence{1}->union(Sequence{ 1 }) do "assertion failed" ; assert calc(StringLib.rawString("\//_\\/")->trim()) = Sequence{1}->union(Sequence{ 1 }) do "assertion failed" ; assert calc(StringLib.rawString("\//\\//")->trim()) = Sequence{1}->union(Sequence{ 4 }) do "assertion failed" ; assert calc(StringLib.rawString("\///\\\//")->trim()) = Sequence{1}->union(Sequence{ 4 }) do "assertion failed" ; assert calc(StringLib.rawString("\///\\\//\ ")->trim()) = Sequence{1}->union(Sequence{ 4 }) do "assertion failed" ; exit(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- data=input() xmax=len(data) data_list=list(data) data_list.reverse() reverse_data=[] for sig in data_list : if sig=="\\" : reverse_data.append("/") elif sig=="/" : reverse_data.append("\\") else : reverse_data.append(sig) reverse_data="".join(reverse_data) def partialSqu(h,sig): if sig=="\\" : squ=h+1/2 h+=1 elif sig=="/" : squ=h-1/2 h-=1 elif sig=="_" : squ=h return squ,h x_squ_dict={} cnt=0 sw,x,h,totalSqu=0,0,0,0 for sig in data : x+=1 if sw==0 and sig=="\\" : sw=1 if sw==1 : squ,h=partialSqu(h,sig) totalSqu+=squ if h==0 : x_squ_dict[x]=totalSqu totalSqu=0 sw=0 keys=x_squ_dict.keys() sw,x,h,totalSqu=0,0,0,0 for sig in reverse_data : x+=1 if sw==0 and sig=="\\" : sw=1 x_p=xmax-x+1 if sw==1 : squ,h=partialSqu(h,sig) totalSqu+=squ if h==0 : x_squ_dict[x_p]=totalSqu totalSqu=0 sw=0 keys=x_squ_dict.keys() keys=list(keys) keys.sort() squ_list=[] for key in keys : squ_list.append(x_squ_dict[key]) a=int(sum(squ_list)) print(a) squ_list.insert(0,len(keys)) squ_list=" ".join([str(int(num))for num in squ_list]) print(squ_list) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var data : String := (OclFile["System.in"]).readLine() ; var xmax : int := (data)->size() ; var data_list : Sequence := (data)->characters() ; data_list := data_list->reverse() ; var reverse_data : Sequence := Sequence{} ; for sig : data_list do ( if sig = "\\" then ( execute (("/") : reverse_data) ) else (if sig = "/" then ( execute (("\\") : reverse_data) ) else ( execute ((sig) : reverse_data) ) ) ) ; reverse_data := StringLib.sumStringsWithSeparator((reverse_data), "") ; skip ; var x_squ_dict : OclAny := Set{} ; var cnt : int := 0 ; var sw : OclAny := null; var x : OclAny := null; var totalSqu : OclAny := null; Sequence{sw,x,h,totalSqu} := Sequence{0,0,0,0} ; for sig : data->characters() do ( x := x + 1 ; if sw = 0 & sig = "\\" then ( var sw : int := 1 ) else skip ; if sw = 1 then ( Sequence{squ,h} := partialSqu(h, sig) ; totalSqu := totalSqu + squ ; if h = 0 then ( x_squ_dict[x+1] := totalSqu ; var totalSqu : int := 0 ; sw := 0 ) else skip ) else skip) ; var keys : OclAny := x_squ_dict.keys() ; var x : OclAny := null; Sequence{sw,x,h,totalSqu} := Sequence{0,0,0,0} ; for sig : reverse_data do ( x := x + 1 ; if sw = 0 & sig = "\\" then ( sw := 1 ; var x_p : double := xmax - x + 1 ) else skip ; if sw = 1 then ( Sequence{squ,h} := partialSqu(h, sig) ; totalSqu := totalSqu + squ ; if h = 0 then ( x_squ_dict[x_p+1] := totalSqu ; totalSqu := 0 ; sw := 0 ) else skip ) else skip) ; keys := x_squ_dict.keys() ; keys := (keys) ; keys := keys->sort() ; var squ_list : Sequence := Sequence{} ; for key : keys do ( execute ((x_squ_dict[key+1]) : squ_list)) ; var a : int := ("" + (((squ_list)->sum())))->toInteger() ; execute (a)->display() ; squ_list := squ_list.insertAt(0+1, (keys)->size()) ; squ_list := StringLib.sumStringsWithSeparator((squ_list->select(num | true)->collect(num | (("" + ((("" + ((num)))->toInteger())))))), " ") ; execute (squ_list)->display(); operation partialSqu(h : OclAny, sig : OclAny) : OclAny pre: true post: true activity: if sig = "\\" then ( var squ : OclAny := h + 1 / 2 ; h := h + 1 ) else (if sig = "/" then ( squ := h - 1 / 2 ; h := h - 1 ) else (if sig = "_" then ( squ := h ) else skip ) ) ; return squ, h; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- landform=[c for c in input()] down=[] areas=[] for i in range(len(landform)): if landform[i]=='\\' : down.append(i) if landform[i]=='/' : if down : pair=down.pop() area=i-pair while areas and areas[-1][0]>pair : area+=areas.pop()[1] areas.append([pair,area]) sum_area=0 for area in areas : sum_area+=area[1] print(sum_area) ans=[] ans.append(str(len(areas))) ans+=[str(area[1])for area in areas] print(' '.join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var landform : Sequence := (OclFile["System.in"]).readLine()->select(c | true)->collect(c | (c)) ; var down : Sequence := Sequence{} ; var areas : Sequence := Sequence{} ; for i : Integer.subrange(0, (landform)->size()-1) do ( if landform[i+1] = '\\' then ( execute ((i) : down) ) else skip ; if landform[i+1] = '/' then ( if down then ( var pair : OclAny := down->last() ; down := down->front() ; var area : double := i - pair ; while areas & (areas->last()->first()->compareTo(pair)) > 0 do ( area := area + areas->last()[1+1]) ; execute ((Sequence{pair}->union(Sequence{ area })) : areas) ) else skip ) else skip) ; var sum_area : int := 0 ; for area : areas do ( sum_area := sum_area + area[1+1]) ; execute (sum_area)->display() ; var ans : Sequence := Sequence{} ; execute ((("" + (((areas)->size())))) : ans) ; ans := ans + areas->select(area | true)->collect(area | (("" + ((area[1+1]))))) ; execute (StringLib.sumStringsWithSeparator((ans), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Stack : def __init__(self,data=None): if data is None : self.data=[] else : self.data=data def push(self,x): self.data.append(x) def pop(self): if self.is_empty()is True : return None else : return self.data.pop(-1) def is_empty(self): if len(self.data)==0 : return True else : return False def get_length(self): return len(self.data) def reverse(self): self.data.reverse() diagram=input() A=0 k=0 L=[] s1=Stack() s2=Stack() new_flood=False for i,vector in enumerate(diagram): if vector=='\\' : s1.push(i) new_flood=True elif vector=='/' : j=s1.pop() if j is not None : A+=i-j size=i-j if new_flood is True : s2.push({'first_pos' : j,'size' : size}) new_flood=False else : current_flood=s2.pop() current_flood['first_pos']=j current_flood['size']+=size while True : prev_flood=s2.pop() if prev_flood is not None : if prev_flood['first_pos']>j : current_flood['size']+=prev_flood['size'] else : s2.push(prev_flood) s2.push(current_flood) break else : s2.push(current_flood) break print(A) output=str(s2.get_length()) for elem in s2.data : output+=' '+str(elem['size']) print(output) ------------------------------------------------------------ OCL File: --------- class Stack { static operation newStack() : Stack pre: true post: Stack->exists( _x | result = _x ); operation initialise(data : OclAny) : Stack pre: true post: true activity: if data <>= null then ( self.data := Sequence{} ) else ( self.data := data ); return self; operation push(x : OclAny) pre: true post: true activity: (expr (atom (name self)) (trailer . (name data)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))); operation pop() : OclAny pre: true post: true activity: if self.is_empty() <>= true then ( return null ) else ( return self.data->at((atom - (number (integer 1)))+1) ); operation is_empty() : OclAny pre: true post: true activity: if (self.data)->size() = 0 then ( return true ) else ( return false ); operation get_length() : OclAny pre: true post: true activity: return (self.data)->size(); operation reverse() pre: true post: true activity: (expr (atom (name self)) (trailer . (name data)) (trailer . (name reverse) (arguments ( )))); } class FromPython { operation initialise() pre: true post: true activity: skip ; var diagram : String := (OclFile["System.in"]).readLine() ; var A : int := 0 ; var k : int := 0 ; var L : Sequence := Sequence{} ; var s1 : Stack := (Stack.newStack()).initialise() ; var s2 : Stack := (Stack.newStack()).initialise() ; var new_flood : boolean := false ; for _tuple : Integer.subrange(1, (diagram)->size())->collect( _indx | Sequence{_indx-1, (diagram)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var vector : OclAny := _tuple->at(_indx); if vector = '\\' then ( s1.push(i) ; new_flood := true ) else (if vector = '/' then ( var j : OclAny := s1->last() ; s1 := s1->front() ; if not(j <>= null) then ( A := A + i - j ; var size : double := i - j ; if new_flood <>= true then ( s2.push(Map{ 'first_pos' |-> j }->union(Map{ 'size' |-> size })) ; new_flood := false ) else ( var current_flood : OclAny := s2->last() ; s2 := s2->front() ; current_flood->at('first_pos') := j ; current_flood->at('size') := current_flood->at('size') + size ; while true do ( var prev_flood : OclAny := s2->last() ; s2 := s2->front() ; if not(prev_flood <>= null) then ( if (prev_flood->at('first_pos')->compareTo(j)) > 0 then ( current_flood->at('size') := current_flood->at('size') + prev_flood->at('size') ) else ( s2.push(prev_flood) ; s2.push(current_flood) ; break ) ) else ( s2.push(current_flood) ; break )) ) ) else skip ) else skip)) ; execute (A)->display() ; var output : String := ("" + ((s2.get_length()))) ; for elem : s2.data do ( output := output + ' ' + ("" + ((elem->at('size'))))) ; execute (output)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline cars=int(input()); enter=list(map(int,input().split())); out=list(map(int,input().split())) summ=0 ; visited=set(); l=0 ; r=0 while lr : r+=1 if enter[l]in visited : l+=1 ; continue if out[r]==enter[l]: l+=1 ; r+=1 else : visited.add(out[r]); r+=1 ; summ+=1 print(summ) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; var cars : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var enter : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); var out : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var summ : int := 0; var visited : Set := Set{}->union(()); var l : int := 0; var r : int := 0 ; while (l->compareTo(cars)) < 0 & (r->compareTo(cars)) < 0 do ( if (l->compareTo(r)) > 0 then ( r := r + 1 ) else skip ; if (visited)->includes(enter[l+1]) then ( l := l + 1; continue ) else skip ; if out[r+1] = enter[l+1] then ( l := l + 1; r := r + 1 ) else ( execute ((out[r+1]) : visited); r := r + 1; summ := summ + 1 )) ; execute (summ)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) s=set() i=0 j=0 c=0 while itoInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Set := Set{}->union(()) ; var i : int := 0 ; var j : int := 0 ; var c : int := 0 ; while (i->compareTo(n)) < 0 & (j->compareTo(n)) < 0 do ( if a[i+1] /= b[j+1] & (s)->excludes(a[i+1]) then ( c := c + 1 ; execute ((b[j+1]) : s) ; j := j + 1 ) else (if a[i+1] = b[j+1] then ( i := i + 1 ; j := j + 1 ) else (if (s)->includes(a[i+1]) then ( i := i + 1 ) else skip ) ) ) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) up=0 ; ans=n ; di=[0]*(n+1) for i in range(n): di[b[i]]=i+1 for i in range(n): pos=di[a[i]] if(pos>up): up=pos ans-=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var up : int := 0; var ans : int := n; var di : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(0, n-1) do ( di[b[i+1]+1] := i + 1) ; for i : Integer.subrange(0, n-1) do ( var pos : OclAny := di[a[i+1]+1] ; if ((pos->compareTo(up)) > 0) then ( up := pos ; ans := ans - 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter,deque from collections import defaultdict from itertools import combinations,permutations,accumulate,groupby,product from bisect import bisect_left,bisect_right from heapq import heapify,heappop,heappush from math import floor,ceil,pi,factorial from operator import itemgetter import copy def I(): return int(input()) def MI(): return map(int,input().split()) def LI(): return list(map(int,input().split())) def LI2(): return[int(input())for i in range(n)] def MXI(): return[[LI()]for i in range(n)] def SI(): return input().rstrip() def printns(x): print('\n'.join(x)) def printni(x): print('\n'.join(list(map(str,x)))) inf=10**17 mod=10**9+7 n=I() lis=[50 for i in range(50)] lists=[] for i in range(50): mx=-inf for j in range(50): if lis[j]>=mx : mx=lis[j] ind=j for j in range(50): lis[j]+=1 lis[ind]-=51 lists.append(copy.deepcopy(lis)) u=n % 50 x=n//50 base=lists[50-u-1] for i in range(50): base[i]+=x print(50) print(*base) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit((10)->pow(7)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var Math_PINFINITY : double := (10)->pow(17) ; var mod : double := (10)->pow(9) + 7 ; var n : OclAny := I() ; var lis : Sequence := Integer.subrange(0, 50-1)->select(i | true)->collect(i | (50)) ; var lists : Sequence := Sequence{} ; for i : Integer.subrange(0, 50-1) do ( var mx : double := -Math_PINFINITY ; for j : Integer.subrange(0, 50-1) do ( if (lis[j+1]->compareTo(mx)) >= 0 then ( mx := lis[j+1] ; var ind : OclAny := j ) else skip) ; for j : Integer.subrange(0, 50-1) do ( lis[j+1] := lis[j+1] + 1) ; lis[ind+1] := lis[ind+1] - 51 ; execute ((copy.deepcopy(lis)) : lists)) ; var u : int := n mod 50 ; x := n div 50 ; var base : OclAny := lists[50 - u - 1+1] ; for i : Integer.subrange(0, 50-1) do ( base[i+1] := base[i+1] + x) ; execute (50)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name base))))))))->display(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LI2() : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())); operation MXI() : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{ LI() })); operation SI() : OclAny pre: true post: true activity: return input().rstrip(); operation printns(x : OclAny) pre: true post: true activity: execute (StringLib.sumStringsWithSeparator((x), ' '))->display(); operation printni(x : OclAny) pre: true post: true activity: execute (StringLib.sumStringsWithSeparator((((x)->collect( _x | (OclType["String"])->apply(_x) ))), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): from sys import stdin,stdout n=int(stdin.readline()) ent=[int(i)for i in stdin.readline().split()] exit=[int(i)for i in stdin.readline().split()] up=0 ; ans=n ; di=[0]*(n+1) for i in range(n): di[exit[i]]=i+1 for i in range(n): posi=di[ent[i]] if posi>up : up=posi ans-=1 stdout.write(str(ans)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: skip ; var n : int := ("" + ((stdin.readLine())))->toInteger() ; var ent : Sequence := stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var exit : Sequence := stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var up : int := 0; var ans : int := n; var di : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(0, n-1) do ( di[exit[i+1]+1] := i + 1) ; for i : Integer.subrange(0, n-1) do ( var posi : OclAny := di[ent[i+1]+1] ; if (posi->compareTo(up)) > 0 then ( up := posi ; ans := ans - 1 ) else skip) ; stdout.write(("" + ((ans)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): LIMIT=10**8 isprime=eulerlib.list_primality(LIMIT+1) def is_prime_generating(n): return all((n % d!=0 or isprime[d+n//d])for d in range(2,eulerlib.sqrt(n)+1)) ans=sum(n for n in range(LIMIT+1)if isprime[n+1]and is_prime_generating(n)) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LIMIT : double := (10)->pow(8) ; var isprime : OclAny := eulerlib.list_primality(LIMIT + 1) ; skip ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name n)))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name LIMIT))) + (expr (atom (number (integer 1)))))))))) )))))) (comp_iter if (test (logical_test (logical_test (comparison (expr (atom (name isprime)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) ]))))) and (logical_test (comparison (expr (atom (name is_prime_generating)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))))))->sum() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- string=input(); str1="" ; count=0 ; set1=set(string) if len(set1)==1 : print(string) elif len(set1)==2 and "1" not in set1 : print(string) elif len(set1)==2 : print("".join(sorted(string))) else : for i in string : if i=="1" : count+=1 else : str1+=i x=str1.index('2') print(str1[0 : x]+"1"*count+str1[x :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var string : String := (OclFile["System.in"]).readLine(); var str1 : String := ""; var count : int := 0; var set1 : Set := Set{}->union((string)) ; if (set1)->size() = 1 then ( execute (string)->display() ) else (if (set1)->size() = 2 & (set1)->excludes("1") then ( execute (string)->display() ) else (if (set1)->size() = 2 then ( execute (StringLib.sumStringsWithSeparator((string->sort()), ""))->display() ) else ( for i : string->characters() do ( if i = "1" then ( count := count + 1 ) else ( str1 := str1 + i )) ; var x : int := str1->indexOf('2') - 1 ; execute (str1.subrange(0+1, x) + StringLib.nCopies("1", count) + str1.subrange(x+1))->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,data): self.val=data self.left=None self.right=None def diagonalprint(root): if root is None : return q=[] q.append(root) q.append(None) while len(q)>0 : temp=q.pop(0) if not temp : if len(q)==0 : return print(' ') q.append(None) else : while temp : print(temp.val,end=' ') if temp.left : q.append(temp.left) temp=temp.right root=Node(8) root.left=Node(3) root.right=Node(10) root.left.left=Node(1) root.left.right=Node(6) root.right.right=Node(14) root.right.right.left=Node(13) root.left.right.left=Node(4) root.left.right.right=Node(7) diagonalprint(root) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute val : OclAny := data; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.val := data ; self.left := null ; self.right := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; root := (Node.newNode()).initialise(8) ; root.left := (Node.newNode()).initialise(3) ; root.right := (Node.newNode()).initialise(10) ; root.left.left := (Node.newNode()).initialise(1) ; root.left.right := (Node.newNode()).initialise(6) ; root.right.right := (Node.newNode()).initialise(14) ; root.right.right.left := (Node.newNode()).initialise(13) ; root.left.right.left := (Node.newNode()).initialise(4) ; root.left.right.right := (Node.newNode()).initialise(7) ; diagonalprint(root); operation diagonalprint(root : OclAny) pre: true post: true activity: if root <>= null then ( return ) else skip ; var q : Sequence := Sequence{} ; execute ((root) : q) ; execute ((null) : q) ; while (q)->size() > 0 do ( var temp : OclAny := q->at(0`firstArg+1) ; q := q->excludingAt(0+1) ; if not(temp) then ( if (q)->size() = 0 then ( return ) else skip ; execute (' ')->display() ; execute ((null) : q) ) else ( while temp do ( execute (temp.val)->display() ; if temp.left then ( execute ((temp.left) : q) ) else skip ; temp := temp.right) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- st=input() o_c=0 zero_pos=[] two_pos=[] t_pos=float('inf') ans='' for i,s in enumerate(st): if s=='1' : o_c+=1 if s=='2' : t_pos=min(t_pos,i) two_pos.append(i) if s=='0' : if i>t_pos : zero_pos.append(i) else : ans+='0' ans+='1'*o_c i,j=0,0 k,m=len(two_pos),len(zero_pos) while itoReal() ; var ans : String := '' ; for _tuple : Integer.subrange(1, (st)->size())->collect( _indx | Sequence{_indx-1, (st)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); if s = '1' then ( o_c := o_c + 1 ) else skip ; if s = '2' then ( t_pos := Set{t_pos, i}->min() ; execute ((i) : two_pos) ) else skip ; if s = '0' then ( if (i->compareTo(t_pos)) > 0 then ( execute ((i) : zero_pos) ) else ( ans := ans + '0' ) ) else skip) ; ans := ans + StringLib.nCopies('1', o_c) ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,0} ; var k : OclAny := null; var m : OclAny := null; Sequence{k,m} := Sequence{(two_pos)->size(),(zero_pos)->size()} ; while (i->compareTo(k)) < 0 & (j->compareTo(m)) < 0 do ( if (two_pos[i+1]->compareTo(zero_pos[j+1])) < 0 then ( ans := ans + '2' ; i := i + 1 ) else ( ans := ans + '0' ; j := j + 1 )) ; if i = k then ( while (j->compareTo(m)) < 0 do ( ans := ans + '0' ; j := j + 1) ) else ( while (i->compareTo(k)) < 0 do ( ans := ans + '2' ; i := i + 1) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for iq in range(1): X=input() n_one=0 n_zero=0 i_prev=0 S_back='' for i in X : if i=='1' : n_one+=1 for i in X : if i=='0' and i_prev==0 : n_zero+=1 if i_prev==1 and i!='1' : S_back=S_back+i if i=='2' and i_prev==0 : S_back=S_back+i i_prev=1 S_final='' for j in range(n_zero): S_final=S_final+'0' for k in range(n_one): S_final=S_final+'1' S_final=S_final+S_back print(S_final) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for iq : Integer.subrange(0, 1-1) do ( var X : String := (OclFile["System.in"]).readLine() ; var n_one : int := 0 ; var n_zero : int := 0 ; var i_prev : int := 0 ; var S_back : String := '' ; for i : X->characters() do ( if i = '1' then ( n_one := n_one + 1 ) else skip) ; for i : X->characters() do ( if i = '0' & i_prev = 0 then ( n_zero := n_zero + 1 ) else skip ; if i_prev = 1 & i /= '1' then ( S_back := S_back + i ) else skip ; if i = '2' & i_prev = 0 then ( S_back := S_back + i ; i_prev := 1 ) else skip) ; var S_final : String := '' ; for j : Integer.subrange(0, n_zero-1) do ( S_final := S_final + '0') ; for k : Integer.subrange(0, n_one-1) do ( S_final := S_final + '1') ; S_final := S_final + S_back ; execute (S_final)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() i=0 k=a.count('1') while True : t=0 while icount('1') ; while true do ( var t : int := 0 ; while (i->compareTo((a)->size())) < 0 & a[i+1] /= '2' do ( if a[i+1] = '0' then ( t := t + 1 ) else skip ; i := i + 1) ; execute (StringLib.nCopies('0', t) + k * '1')->display() ; k := 0 ; while (i->compareTo((a)->size())) < 0 & a[i+1] = '2' do ( i := i + 1 ; execute ('2')->display()) ; if i = (a)->size() then ( break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() if a.find("2")==-1 : print(''.join(["0"]*a.count("0")+["1"]*a.count("1"))) else : print(''.join(["0"]*a[: a.find("2")].count("0")+["1"]*a.count("1")+[e for e in a[a.find("2"): len(a)]if e!="1"])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; if a->indexOf("2") - 1 = -1 then ( execute (StringLib.sumStringsWithSeparator((MatrixLib.elementwiseMult(Sequence{ "0" }, a->count("0"))->union(MatrixLib.elementwiseMult(Sequence{ "1" }, a->count("1")))), ''))->display() ) else ( execute (StringLib.sumStringsWithSeparator((MatrixLib.elementwiseMult(Sequence{ "0" }, a.subrange(1,a->indexOf("2") - 1)->count("0"))->union(MatrixLib.elementwiseMult(Sequence{ "1" }, a->count("1")))->union(a.subrange(a->indexOf("2") - 1+1, (a)->size())->select(e | e /= "1")->collect(e | (e)))), ''))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math PI=3.1415926535 def findAnglesA(a,b,c): A=math.acos((b*b+c*c-a*a)/(2*b*c)) return A*180/PI def findAnglesB(a,b,c): B=math.acos((a*a+c*c-b*b)/(2*a*c)) return B*180/PI def printAngles(a,b,c): x=a y=b z=c A=findAnglesA(x,y,z) B=findAnglesB(x,y,z) print("Angles are A=",A,",B=",B,",C=","90 ") def printOtherSides(n): if(n & 1): if(n==1): print("-1") else : b=(n*n-1)//2 c=(n*n+1)//2 print("Side b=",b," Side c=",c) else : if(n==2): print("-1") else : b=n*n//4-1 ; c=n*n//4+1 ; print("Side b=",b,",Side c=",c) printAngles(n,b,c) if __name__=="__main__" : a=12 printOtherSides(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PI : double := 3.1415926535 ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( a := 12 ; printOtherSides(a) ) else skip; operation findAnglesA(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: var A : double := ((b * b + c * c - a * a) / (2 * b * c))->acos() ; return A * 180 / PI; operation findAnglesB(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: var B : double := ((a * a + c * c - b * b) / (2 * a * c))->acos() ; return B * 180 / PI; operation printAngles(a : OclAny, b : OclAny, c : OclAny) pre: true post: true activity: var x : OclAny := a ; var y : OclAny := b ; var z : OclAny := c ; A := findAnglesA(x, y, z) ; B := findAnglesB(x, y, z) ; execute ("Angles are A=")->display(); operation printOtherSides(n : OclAny) pre: true post: true activity: if (MathLib.bitwiseAnd(n, 1)) then ( if (n = 1) then ( execute ("-1")->display() ) else ( b := (n * n - 1) div 2 ; c := (n * n + 1) div 2 ; execute ("Side b=")->display() ) ) else ( if (n = 2) then ( execute ("-1")->display() ) else ( b := n * n div 4 - 1; ; c := n * n div 4 + 1; ; execute ("Side b=")->display() ) ) ; printAngles(n, b, c); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSum(n): ans=0 ; temp=0 ; for i in range(1,n+1): if tempdisplay(); operation findSum(n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0; var temp : int := 0; ; for i : Integer.subrange(1, n + 1-1) do ( if (temp->compareTo(n)) < 0 then ( temp := i - 1 ; var num : int := 1 ; while (temp->compareTo(n)) < 0 do ( if (temp + i->compareTo(n)) <= 0 then ( ans := ans + i * num ) else ( ans := ans + (n - temp) * num ) ; temp := temp + i ; num := num + 1) ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=50 ; k,s=divmod(int(input()),N); print(N); print(*([49-s+k]*(N-s)+[100-s+k]*s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 50; var k : OclAny := null; var s : OclAny := null; Sequence{k,s} := Sequence{(("" + (((OclFile["System.in"]).readLine())))->toInteger() div N), (("" + (((OclFile["System.in"]).readLine())))->toInteger() mod N)}; execute (N)->display(); execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (number (integer 49)))) - (expr (atom (name s)))) + (expr (atom (name k)))))))) ])) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name N))) - (expr (atom (name s)))))))) )))) + (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (number (integer 100)))) - (expr (atom (name s)))) + (expr (atom (name k)))))))) ])) * (expr (atom (name s))))))))) ))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printProbability(L,n): p=(1<<(n-1)) return 1.0-(float(n)/float(p)) if __name__=='__main__' : n=3 L=5 print(printProbability(L,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 3 ; L := 5 ; execute (printProbability(L, n))->display() ) else skip; operation printProbability(L : OclAny, n : OclAny) : OclAny pre: true post: true activity: var p : int := (1 * (2->pow((n - 1)))) ; return 1.0 - (("" + ((n)))->toReal() / ("" + ((p)))->toReal()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,s,e=input().split() n=int(n) s=int(s) e=int(e) if not n+s+e : break s=s//100*60+s % 100 e=e//100*60+e % 100 t=[0]*(60*24+1) for i in range(n): m=int(input()) g=input().split() j=0 for o in g : a=int(o) if j % 2 : t[a//100*60+a % 100]+=1 else : t[a//100*60+a % 100]-=1 j+=1 cnt=n ans=0 ma=-1 for i in range(e): cnt+=t[i] if ians else ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var s : OclAny := null; var e : OclAny := null; Sequence{n,s,e} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var s : int := ("" + ((s)))->toInteger() ; var e : int := ("" + ((e)))->toInteger() ; if not(n + s + e) then ( break ) else skip ; s := s div 100 * 60 + s mod 100 ; e := e div 100 * 60 + e mod 100 ; var t : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (60 * 24 + 1)) ; for i : Integer.subrange(0, n-1) do ( var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var g : OclAny := input().split() ; var j : int := 0 ; for o : g do ( var a : int := ("" + ((o)))->toInteger() ; if j mod 2 then ( t[a div 100 * 60 + a mod 100+1] := t[a div 100 * 60 + a mod 100+1] + 1 ) else ( t[a div 100 * 60 + a mod 100+1] := t[a div 100 * 60 + a mod 100+1] - 1 ) ; j := j + 1)) ; var cnt : int := n ; var ans : int := 0 ; var ma : int := -1 ; for i : Integer.subrange(0, e-1) do ( cnt := cnt + t[i+1] ; if (i->compareTo(s)) < 0 then ( continue ) else skip ; if cnt then ( ans := ans + 1 ) else ( if (ma->compareTo(ans)) < 0 then ( ma := ans ) else skip ; ans := 0 )) ; execute (if (ma->compareTo(ans)) > 0 then ma else ans endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- conv=lambda t :(t//100)*60+(t % 100) while 1 : N,P,Q=map(int,input().split()) if N==P==Q==0 : break P=conv(P); Q=conv(Q) CM=[0]*(Q-P+1) for i in range(N): k=int(input()) *T,=map(int,input().split()) for s,t in zip(T[: : 2],T[1 : : 2]): s=conv(s); t=conv(t) CM[s-P]+=1 CM[t-P]-=1 cnt=ans=0 for i in range(Q-P): CM[i+1]+=CM[i] if CM[i]collect( _x | (OclType["int"])->apply(_x) ) ; if N = P & (P == Q) & (Q == 0) then ( break ) else skip ; var P : OclAny := conv->apply(P); var Q : OclAny := conv->apply(Q) ; var CM : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (Q - P + 1)) ; for i : Integer.subrange(0, N-1) do ( var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; (testlist_star_expr (star_expr * (expr (atom (name T)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name T)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def d2t(d): return(d//100)*60+(d % 100) while True : n,p,q=map(int,input().split()) if n==0 : break tbl=[0]*1500 p,q=d2t(p),d2t(q) for i in range(n): k=2*int(input()) a=list(map(int,input().split())) for j in range(0,k,2): t1,t2=d2t(a[j]),d2t(a[j+1]) for t in range(t1,t2): tbl[t]+=1 ans=k=0 for t in range(p,q): if tbl[t]0 : if k>ans : ans=k k=0 if k>ans : ans=k print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; while true do ( var n : OclAny := null; var p : OclAny := null; var q : OclAny := null; Sequence{n,p,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var tbl : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 1500) ; var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := Sequence{d2t(p),d2t(q)} ; for i : Integer.subrange(0, n-1) do ( var k : int := 2 * ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, k-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( var t1 : OclAny := null; var t2 : OclAny := null; Sequence{t1,t2} := Sequence{d2t(a[j+1]),d2t(a[j + 1+1])} ; for t : Integer.subrange(t1, t2-1) do ( tbl[t+1] := tbl[t+1] + 1))) ; var ans : OclAny := 0; k := 0 ; for t : Integer.subrange(p, q-1) do ( if (tbl[t+1]->compareTo(n)) < 0 then ( k := k + 1 ) else (if k > 0 then ( if (k->compareTo(ans)) > 0 then ( ans := k ) else skip ; k := 0 ) else skip)) ; if (k->compareTo(ans)) > 0 then ( ans := k ) else skip ; execute (ans)->display()); operation d2t(d : OclAny) : OclAny pre: true post: true activity: return (d div 100) * 60 + (d mod 100); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import cycle as c n=int(input()) for _ in range(n): t=input() l=[] bf="" for nn in map(int,t): if not nn : l.extend([bf]) bf="" continue if not bf : if nn : kl=[c(".,!? "),c("abc"),c("def"),c("ghi"),c("jkl"),c("mno"),c("pqrs"),c("tuv"),c("wxyz")] bf=next(kl[nn-1]) else : bf=next(kl[nn-1]) print("".join(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var t : String := (OclFile["System.in"]).readLine() ; var l : Sequence := Sequence{} ; var bf : String := "" ; for nn : (t)->collect( _x | (OclType["int"])->apply(_x) ) do ( if not(nn) then ( l := l->union(Sequence{ bf }) ; bf := "" ; continue ) else skip ; if not(bf = "") then ( if nn then ( var kl : Sequence := Sequence{c(".,!? ")}->union(Sequence{c("abc")}->union(Sequence{c("def")}->union(Sequence{c("ghi")}->union(Sequence{c("jkl")}->union(Sequence{c("mno")}->union(Sequence{c("pqrs")}->union(Sequence{c("tuv")}->union(Sequence{ c("wxyz") })))))))) ; bf := (kl[nn - 1+1]).next() ) else skip ) else ( bf := (kl[nn - 1+1]).next() )) ; execute (StringLib.sumStringsWithSeparator((l), ""))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 2==1 : k=(n+1)/2 print(int(k**2)) else : k=n/2 print(int(k*(k+1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 1 then ( var k : double := (n + 1) / 2 ; execute (("" + (((k)->pow(2))))->toInteger())->display() ) else ( k := n / 2 ; execute (("" + ((k * (k + 1))))->toInteger())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,W=map(int,input().split()) MOD=10**9+7 ws=[int(input())for i in range(N)] ws.sort(reverse=1) su=sum(ws) dp=[0]*(W+1) dp[0]=1 ans=0 if su<=W : ans+=1 for i in range(N): w=ws[i] su-=w ans+=sum(dp[max(W+1-w-su,0): max(W+1-su,0)])% MOD for j in range(W,w-1,-1): dp[j]+=dp[j-w] dp[j]%=MOD print(ans % MOD) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var W : OclAny := null; Sequence{N,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var MOD : double := (10)->pow(9) + 7 ; var ws : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; ws := ws->sort() ; var su : OclAny := (ws)->sum() ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (W + 1)) ; dp->first() := 1 ; var ans : int := 0 ; if (su->compareTo(W)) <= 0 then ( ans := ans + 1 ) else skip ; for i : Integer.subrange(0, N-1) do ( var w : OclAny := ws[i+1] ; su := su - w ; ans := ans + (dp.subrange(Set{W + 1 - w - su, 0}->max()+1, Set{W + 1 - su, 0}->max()))->sum() mod MOD ; for j : Integer.subrange(w - 1 + 1, W)->reverse() do ( dp[j+1] := dp[j+1] + dp[j - w+1] ; dp[j+1] := dp[j+1] mod MOD)) ; execute (ans mod MOD)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,W=map(int,input().split()) w=[] for i in range(N): w.append(int(input())) w.sort() summ=0 ans=0 for num,wi in enumerate(w): if num==N-1 : if sum(w)-w[-1]<=W and W-sum(w)-w[-1]=0 : dpn1[k]=dpn[k]+dpn[k-w[num+n+1]] else : dpn1[k]=dpn[k] for i in range(max(W-summ-wi+1,0),W-summ+1): ans+=dp[-1][i] ans %=10**9+7 summ+=wi if Wcollect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : w)) ; w := w->sort() ; var summ : int := 0 ; var ans : int := 0 ; for _tuple : Integer.subrange(1, (w)->size())->collect( _indx | Sequence{_indx-1, (w)->at(_indx)} ) do (var _indx : int := 1; var num : OclAny := _tuple->at(_indx); _indx := _indx + 1; var wi : OclAny := _tuple->at(_indx); if num = N - 1 then ( if ((w)->sum() - w->last()->compareTo(W)) <= 0 & (W - (w)->sum() - w->last()->compareTo(w->last())) < 0 then ( ans := ans + 1 ) else skip ; break ) else skip ; var dp : Sequence := Integer.subrange(0, N - num-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (W + 1)))) ; dp->first()->first() := 1 ; for n : Integer.subrange(0, N - num - 1-1) do ( var dpn1 : OclAny := dp[n + 1+1] ; var dpn : OclAny := dp[n+1] ; for k : Integer.subrange(0, W + 1-1) do ( if k - w[num + n + 1+1] >= 0 then ( dpn1[k+1] := dpn[k+1] + dpn[k - w[num + n + 1+1]+1] ) else ( dpn1[k+1] := dpn[k+1] ))) ; for i : Integer.subrange(Set{W - summ - wi + 1, 0}->max(), W - summ + 1-1) do ( ans := ans + dp->last()[i+1] ; ans := ans mod (10)->pow(9) + 7) ; summ := summ + wi ; if (W->compareTo(summ)) < 0 then ( break ) else skip) ; execute (ans mod ((10)->pow(9) + 7))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.buffer.readline()[:-1] while True : n,w,d=map(int,input().split()) if n==w==d==0 : break cakes=dict() cakes[1]=[w,d] for i in range(1,n+1): p,s=map(int,input().split()) w,d=cakes[p] for j in range(p,i): cakes[j]=cakes[j+1] s %=w+d if scollect( _x | (OclType["int"])->apply(_x) ) ; if n = w & (w == d) & (d == 0) then ( break ) else skip ; var cakes : Map := (arguments ( )) ; cakes[1+1] := Sequence{w}->union(Sequence{ d }) ; for i : Integer.subrange(1, n + 1-1) do ( var p : OclAny := null; var s : OclAny := null; Sequence{p,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : OclAny := null; var d : OclAny := null; Sequence{w,d} := cakes[p+1] ; for j : Integer.subrange(p, i-1) do ( cakes[j+1] := cakes[j + 1+1]) ; s := s mod w + d ; if (s->compareTo(w)) < 0 then ( cakes[i+1] := Sequence{Set{s, w - s}->min()}->union(Sequence{ d }) ; cakes[i + 1+1] := Sequence{Set{s, w - s}->max()}->union(Sequence{ d }) ) else ( cakes[i+1] := Sequence{w}->union(Sequence{ Set{s - w, w + d - s}->min() }) ; cakes[i + 1+1] := Sequence{w}->union(Sequence{ Set{s - w, w + d - s}->max() }) )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) * (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name cakes)) (trailer . (name values) (arguments ( ))))))))) )))))))))->display()); operation input() : OclAny pre: true post: true activity: return sys.stdin.buffer.readLine()->front(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- WIDTH=0 DEPTH=1 while True : N,W,D=[int(x)for x in input().split()] if N==W==D==0 : break if N==0 : print(W*D) continue p,s=zip(*[[int(x)for x in input().split()]for _ in range(N)]) cake=[[0,0],[W,D]]+[None]*N for i in range(N): id=p[i] w,d=cake[id] l=s[i] for j in range(id,i+1): cake[j]=cake[j+1][:] cake[i+1]=None l=l %(w+d) if lselect(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if N = W & (W == D) & (D == 0) then ( break ) else skip ; if N = 0 then ( execute (W * D)->display() ; continue ) else skip ; var p : OclAny := null; var s : OclAny := null; Sequence{p,s} := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( )))))))) ]))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))) ]))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( )))))))) ]))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))) ]))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( )))))))) ]))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))) ]))))))`third->at(_indx)} ) ; var cake : Sequence := Sequence{Sequence{0}->union(Sequence{ 0 })}->union(Sequence{ Sequence{W}->union(Sequence{ D }) })->union(MatrixLib.elementwiseMult(Sequence{ null }, N)) ; for i : Integer.subrange(0, N-1) do ( var id : OclAny := p[i+1] ; var w : OclAny := null; var d : OclAny := null; Sequence{w,d} := cake[id+1] ; var l : OclAny := s[i+1] ; for j : Integer.subrange(id, i + 1-1) do ( cake[j+1] := cake[j + 1+1]) ; cake[i + 1+1] := null ; l := l mod (w + d) ; if (l->compareTo(w)) < 0 then ( var w_min : OclAny := Set{l, w - l}->min() ; cake[i + 1+1] := Sequence{w_min}->union(Sequence{ d }) ; cake[i + 2+1] := Sequence{w - w_min}->union(Sequence{ d }) ) else ( l := l - w ; var d_min : OclAny := Set{l, d - l}->min() ; cake[i + 1+1] := Sequence{w}->union(Sequence{ d_min }) ; cake[i + 2+1] := Sequence{w}->union(Sequence{ d - d_min }) )) ; var area : Sequence := cake->select(Sequence{w, d} | true)->collect(Sequence{w, d} | (w * d)) ; area := area->sort() ; execute (StringLib.sumStringsWithSeparator(((area->tail())->collect( _x | (OclType["String"])->apply(_x) )), " "))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().rstrip() def pin(type=int): return map(type,input().split()) def tupin(t=int): return tuple(pin(t)) def resolve(): K,=pin() if K==0 : print(4) print(3,3,3,3) elif K==1 : print(3) print(1,0,3) elif K<=50 : print(K) t=[K]*K print(*t) else : print(50) s=K % 50 t=K//50 t=[50+t-1]*50 if s>0 : for i in range(s): t=[tt-1 for tt in t] t[i]+=51 print(*t) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; skip ; skip ; skip ; resolve(); operation pin(type : OclAny) : OclAny pre: true post: true activity: if type->oclIsUndefined() then type := OclType["int"] else skip; return (input->apply().split())->collect( _x | (type)->apply(_x) ); operation tupin(t : OclAny) : OclAny pre: true post: true activity: if t->oclIsUndefined() then t := OclType["int"] else skip; return (pin(t)); operation resolve() pre: true post: true activity: (testlist_star_expr (test (logical_test (comparison (expr (atom (name K)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name K)))))) ,)} := pin() ; if K = 0 then ( execute (4)->display() ; execute (3)->display() ) else (if K = 1 then ( execute (3)->display() ; execute (1)->display() ) else (if K <= 50 then ( execute (K)->display() ; t := MatrixLib.elementwiseMult(Sequence{ K }, K) ; execute ((argument * (test (logical_test (comparison (expr (atom (name t))))))))->display() ) else ( execute (50)->display() ; var s : int := K mod 50 ; t := K div 50 ; t := MatrixLib.elementwiseMult(Sequence{ 50 + t - 1 }, 50) ; if s > 0 then ( for i : Integer.subrange(0, s-1) do ( t := t->select(tt | true)->collect(tt | (tt - 1)) ; t[i+1] := t[i+1] + 51) ) else skip ; execute ((argument * (test (logical_test (comparison (expr (atom (name t))))))))->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.read readline=sys.stdin.readline readlines=sys.stdin.readlines class Cake : def __init__(self,h,w): self.height=h self.width=w def circumference(self): return 2*(self.height+self.width) def area(self): return self.height*self.width def main(): ans=[] while True : n,w,d=map(int,readline().split()) if(n,w,d)==(0,0,0): break piece=[Cake(d,w)] for _ in range(n): p,s=map(int,readline().split()) p-=1 c=piece.pop(p) s %=c.circumference()//2 if sexists( _x | result = _x ); attribute height : OclAny := h; attribute width : OclAny := w; operation initialise(h : OclAny,w : OclAny) : Cake pre: true post: true activity: self.height := h ; self.width := w; return self; operation circumference() : OclAny pre: true post: true activity: return 2 * (self.height + self.width); operation area() : OclAny pre: true post: true activity: return self.height * self.width; } class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := (OclFile["System.in"]).read ; var readline : OclAny := (OclFile["System.in"]).readline ; var readlines : OclAny := (OclFile["System.in"]).readlines ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var ans : Sequence := Sequence{} ; while true do ( var n : OclAny := null; var d : OclAny := null; Sequence{n,w,d} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if Sequence{n, w, d} = Sequence{0, 0, 0} then ( break ) else skip ; var piece : Sequence := Sequence{ (Cake.newCake()).initialise(d, w) } ; for _anon : Integer.subrange(0, n-1) do ( var p : OclAny := null; var s : OclAny := null; Sequence{p,s} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; p := p - 1 ; var c : OclAny := piece->at(p`firstArg+1) ; piece := piece->excludingAt(p+1) ; s := s mod c.circumference() div 2 ; if (s->compareTo(c.width)) < 0 then ( var h1 : OclAny := null; var h2 : OclAny := null; Sequence{h1,h2} := Sequence{c.height,c.height} ; var w1 : OclAny := null; var w2 : OclAny := null; Sequence{w1,w2} := Sequence{Set{s, c.width - s}->min(),Set{s, c.width - s}->max()} ) else ( h := s - c.width ; var h1 : OclAny := null; var h2 : OclAny := null; Sequence{h1,h2} := Sequence{Set{h, c.height - h}->min(),Set{h, c.height - h}->max()} ; var w1 : OclAny := null; var w2 : OclAny := null; Sequence{w1,w2} := Sequence{c.width,c.width} ) ; execute (((Cake.newCake()).initialise(h1, w1)) : piece) ; execute (((Cake.newCake()).initialise(h2, w2)) : piece)) ; execute ((piece->select(p | true)->collect(p | (p.area()))->sort()) : ans)) ; for a : ans do ( execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,queue,math,copy sys.setrecursionlimit(10**7) input=sys.stdin.readline LI=lambda :[int(x)for x in input().split()] _LI=lambda :[int(x)-1 for x in input().split()] while True : N,W,D=LI() if N==0 and W==0 and D==0 : break q=[(W*D,W,D)] for _ in range(N): p,s=LI() r=q.pop(p-1) w=r[1] d=r[2] s=s %(2*(w+d)) if snp2 : np1,np2=np2,np1 q.append(np1) q.append(np2) ans='' q.sort() for s,w,d in q : ans+=str(s)+' ' print(ans.rstrip()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var input : OclAny := (OclFile["System.in"]).readline ; var LI : Function := lambda $$ : OclAny in (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) ; var _LI : Function := lambda $$ : OclAny in (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1))) ; while true do ( var N : OclAny := null; var W : OclAny := null; var D : OclAny := null; Sequence{N,W,D} := LI->apply() ; if N = 0 & W = 0 & D = 0 then ( break ) else skip ; var q : Sequence := Sequence{ Sequence{W * D, W, D} } ; for _anon : Integer.subrange(0, N-1) do ( var p : OclAny := null; var s : OclAny := null; Sequence{p,s} := LI->apply() ; var r : OclAny := q->at((expr (expr (atom (name p))) - (expr (atom (number (integer 1)))))+1) ; q := q->excludingAt(p - 1+1) ; var w : String := r[1+1] ; var d : String := r[2+1] ; var s : int := s mod (2 * (w + d)) ; if s < w then ( var np1 : OclAny := Sequence{s * d, s, d} ; var np2 : OclAny := Sequence{(w - s) * d, w - s, d} ) else (if (s->compareTo(w + d)) < 0 then ( s := s - w ; np1 := Sequence{StringLib.nCopies(w, s), w, s} ; np2 := Sequence{StringLib.nCopies(w, (d - s)), w, d - s} ) else (if (s->compareTo(StringLib.nCopies(w, 2) + d)) < 0 then ( s := s - w + d ; np1 := Sequence{s * d, s, d} ; np2 := Sequence{(w - s) * d, w - s, d} ) else ( s := s - StringLib.nCopies(w, 2) + d ; np1 := Sequence{StringLib.nCopies(w, s), w, s} ; np2 := Sequence{StringLib.nCopies(w, (d - s)), w, d - s} ) ) ) ; if (np1->compareTo(np2)) > 0 then ( Sequence{np1,np2} := Sequence{np2,np1} ) else skip ; execute ((np1) : q) ; execute ((np2) : q)) ; var ans : String := '' ; q := q->sort() ; for _tuple : q do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var w : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); ans := ans + ("" + ((s))) + ' ') ; execute (StringLib.rightTrim(ans))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cut(d,w,s): s %=2*(d+w) sq=[] if 0p2[0]*p2[1]: p1,p2=p2,p1 return[p1,p2] while True : N,W,D=map(int,input().split()) if not(N | W | D): break square=[(D,W)] for _ in range(N): p,s=map(int,input().split()) d,w=square.pop(p-1) square.extend(cut(d,w,s)) print(*sorted(d*w for d,w in square)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var N : OclAny := null; var W : OclAny := null; var D : OclAny := null; Sequence{N,W,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if not((MathLib.bitwiseOr(MathLib.bitwiseOr(N, W), D))) then ( break ) else skip ; var square : Sequence := Sequence{ Sequence{D, W} } ; for _anon : Integer.subrange(0, N-1) do ( var p : OclAny := null; Sequence{p,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; Sequence{d,w} := square->at((expr (expr (atom (name p))) - (expr (atom (number (integer 1)))))+1) ; square := square->excludingAt(p - 1+1) ; square := square->union(cut(d, w, s))) ; execute ((argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name d))) * (expr (atom (name w))))))) (comp_for for (exprlist (expr (atom (name d))) , (expr (atom (name w)))) in (logical_test (comparison (expr (atom (name square)))))))) )))))))))->display()); operation cut(d : OclAny, w : OclAny, s : OclAny) : OclAny pre: true post: true activity: s := s mod 2 * (d + w) ; var sq : Sequence := Sequence{} ; if 0 < s & (s < w) then ( sq := Sequence{Sequence{d, s}}->union(Sequence{ Sequence{d, w - s} }) ) else (if (w->compareTo(s)) < 0 & (s < w + d) then ( s := s - w ; sq := Sequence{Sequence{s, w}}->union(Sequence{ Sequence{d - s, w} }) ) else (if (w + d->compareTo(s)) < 0 & (s < 2 * w + d) then ( s := s - w + d ; sq := Sequence{Sequence{d, s}}->union(Sequence{ Sequence{d, w - s} }) ) else (if (2 * w + d->compareTo(s)) < 0 & (s < 2 * (w + d)) then ( s := s - 2 * w + d ; sq := Sequence{Sequence{s, w}}->union(Sequence{ Sequence{d - s, w} }) ) else ( assert (false) do "assertion failed" ) ) ) ) ; var p1 : OclAny := null; var p2 : OclAny := null; Sequence{p1,p2} := sq ; if (p1->first() * p1[1+1]->compareTo(p2->first() * p2[1+1])) > 0 then ( var p1 : OclAny := null; var p2 : OclAny := null; Sequence{p1,p2} := Sequence{p2,p1} ) else skip ; return Sequence{p1}->union(Sequence{ p2 }); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def SieveofEratosthenes(prime,p_size): prime[0]=False prime[1]=False for p in range(2,p_size+1): if prime[p]: for i in range(p*2,p_size+1,p): prime[i]=False def sumProdOfPrimeFreq(s): prime=[True]*(len(s)+2) SieveofEratosthenes(prime,len(s)+1) i=0 j=0 m=dict() for i in range(len(s)): m[s[i]]=(m[s[i]]+1)if s[i]in m else 1 s=0 product=1 for it in m : if prime[m[it]]: s+=m[it] product*=m[it] print("Sum=",s) print("Product=",product) if __name__=="__main__" : s="geeksforgeeks" sumProdOfPrimeFreq(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( s := "geeksforgeeks" ; sumProdOfPrimeFreq(s) ) else skip; operation SieveofEratosthenes(prime : OclAny, p_size : OclAny) pre: true post: true activity: prime->first() := false ; prime[1+1] := false ; for p : Integer.subrange(2, p_size + 1-1) do ( if prime[p+1] then ( for i : Integer.subrange(p * 2, p_size + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip); operation sumProdOfPrimeFreq(s : OclAny) pre: true post: true activity: prime := MatrixLib.elementwiseMult(Sequence{ true }, ((s)->size() + 2)) ; SieveofEratosthenes(prime, (s)->size() + 1) ; var i : int := 0 ; var j : int := 0 ; var m : Map := (arguments ( )) ; for i : Integer.subrange(0, (s)->size()-1) do ( m[s[i+1]+1] := if (m)->includes(s[i+1]) then (m[s[i+1]+1] + 1) else 1 endif) ; s := 0 ; var product : int := 1 ; for it : m->keys() do ( if prime[m[it+1]+1] then ( s := s + m[it+1] ; product := product * m[it+1] ) else skip) ; execute ("Sum=")->display() ; execute ("Product=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def subset(arr,n): mp={i : 0 for i in range(10)} for i in range(n): mp[arr[i]]+=1 res=0 for key,value in mp.items(): res=max(res,value) return res if __name__=='__main__' : arr=[5,6,9,3,4,3,4] n=len(arr) print(subset(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{5}->union(Sequence{6}->union(Sequence{9}->union(Sequence{3}->union(Sequence{4}->union(Sequence{3}->union(Sequence{ 4 })))))) ; n := (arr)->size() ; execute (subset(arr, n))->display() ) else skip; operation subset(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var mp : Map := Integer.subrange(0, 10-1)->select(i | true)->collect(i | Map{i |-> 0})->unionAll() ; for i : Integer.subrange(0, n-1) do ( mp[arr[i+1]+1] := mp[arr[i+1]+1] + 1) ; var res : int := 0 ; for _tuple : mp->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); res := Set{res, value}->max()) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math class Node : def __init__(self,data): self.data=data self.next=None def newNode(data): new_node=Node(data) new_node.data=data new_node.next=None return new_node def modularNode(head,k): if(k<=0 or head==None): return None i=1 modularNode=None temp=head while(temp!=None): if(i % k==0): modularNode=temp i=i+1 temp=temp.next return modularNode if __name__=='__main__' : head=newNode(1) head.next=newNode(2) head.next.next=newNode(3) head.next.next.next=newNode(4) head.next.next.next.next=newNode(5) k=2 answer=modularNode(head,k) print("Modular node is",end=' ') if(answer!=None): print(answer.data,end=' ') else : print("None") ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.next := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( head := newNode(1) ; head.next := newNode(2) ; head.next.next := newNode(3) ; head.next.next.next := newNode(4) ; head.next.next.next.next := newNode(5) ; k := 2 ; var answer : OclAny := modularNode(head, k) ; execute ("Modular node is")->display() ; if (answer /= null) then ( execute (answer.data)->display() ) else ( execute ("None")->display() ) ) else skip; operation newNode(data : OclAny) : OclAny pre: true post: true activity: var new_node : Node := (Node.newNode()).initialise(data) ; new_node.data := data ; new_node.next := null ; return new_node; operation modularNode(head : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (k <= 0 or head = null) then ( return null ) else skip ; var i : int := 1 ; var modularNode : OclAny := null ; var temp : OclAny := head ; while (temp /= null) do ( if (i mod k = 0) then ( modularNode := temp ) else skip ; i := i + 1 ; temp := temp.next) ; return modularNode; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print((int(input())+1)**2//4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (((("" + (((OclFile["System.in"]).readLine())))->toInteger() + 1))->pow(2) div 4)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSol(coeff,start,end,rhs): if(rhs==0): return 1 result=0 for i in range(start,end+1): if(coeff[i]<=rhs): result+=countSol(coeff,i,end,rhs-coeff[i]) return result coeff=[2,2,5] rhs=4 n=len(coeff) print(countSol(coeff,0,n-1,rhs)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; coeff := Sequence{2}->union(Sequence{2}->union(Sequence{ 5 })) ; rhs := 4 ; var n : int := (coeff)->size() ; execute (countSol(coeff, 0, n - 1, rhs))->display(); operation countSol(coeff : OclAny, start : OclAny, end : OclAny, rhs : OclAny) : OclAny pre: true post: true activity: if (rhs = 0) then ( return 1 ) else skip ; var result : int := 0 ; for i : Integer.subrange(start, end + 1-1) do ( if ((coeff[i+1]->compareTo(rhs)) <= 0) then ( result := result + countSol(coeff, i, end, rhs - coeff[i+1]) ) else skip) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) arr=list(map(int,input().split())) arr.sort() hours=0 for i in arr : if k % i==0 : hours=k//i print(hours) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := arr->sort() ; var hours : int := 0 ; for i : arr do ( if k mod i = 0 then ( hours := k div i ) else skip) ; execute (hours)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) l=list(int(x)for x in input().split()) lt=[] for i in l : if k % i==0 : lt.append(i) print(k//(max(lt))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ; var lt : Sequence := Sequence{} ; for i : l do ( if k mod i = 0 then ( execute ((i) : lt) ) else skip) ; execute (k div ((lt)->max()))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline N=int(readline()) X=list(map(int,readline().split())) X.sort() ans=X[(N-1)//2] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var N : int := ("" + ((readline())))->toInteger() ; var X : Sequence := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ; X := X->sort() ; var ans : OclAny := X[(N - 1) div 2+1] ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (buckets,length_of_garden)=map(int,input().split(' ')) bucket=list(map(int,input().split(' '))) bucket.sort() best_bucket=0 for b in bucket : if length_of_garden % b==0 : best_bucket=b print(length_of_garden//best_bucket) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{buckets, length_of_garden} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var bucket : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; bucket := bucket->sort() ; var best_bucket : int := 0 ; for b : bucket do ( if length_of_garden mod b = 0 then ( best_bucket := b ) else skip) ; execute (length_of_garden div best_bucket)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=lambda : map(int,input().split()); _,l=x(); print(min(l//y for y in x()if l % y==0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); var _anon : OclAny := null; var l : OclAny := null; Sequence{_anon,l} := x->apply(); execute (((argument (test (logical_test (comparison (expr (expr (atom (name l))) // (expr (atom (name y))))))) (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name x)) (trailer (arguments ( )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (expr (atom (name l))) % (expr (atom (name y))))) == (comparison (expr (atom (number (integer 0))))))))))))->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) l=list(map(int,input().split())) j=[] for i in range(len(l)): if k % l[i]==0 : j.append(l[i]) print(k//max(j)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var j : Sequence := Sequence{} ; for i : Integer.subrange(0, (l)->size()-1) do ( if k mod l[i+1] = 0 then ( execute ((l[i+1]) : j) ) else skip) ; execute (k div (j)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findIntegers(n,x,y): ans=[] for i in range(n-1): ans.append(1) if(y-(n-1)<=0): print("-1",end="") return ans.append(y-(n-1)) store=0 for i in range(n): store+=ans[i]*ans[i] if(storedisplay() ; return ) else skip ; execute ((y - (n - 1)) : ans) ; var store : int := 0 ; for i : Integer.subrange(0, n-1) do ( store := store + ans[i+1] * ans[i+1]) ; if ((store->compareTo(x)) < 0) then ( execute ("-1")->display() ; return; ) else skip ; for i : Integer.subrange(0, n-1) do ( execute (ans[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def replaceConsonants(string): res="" ; i=0 ; count=0 ; while(i0): res+=str(count); res+=string[i]; i+=1 count=0 ; if(count>0): res+=str(count); return res ; if __name__=="__main__" : string="abcdeiop" ; print(replaceConsonants(string)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( string := "abcdeiop"; ; execute (replaceConsonants(string))->display(); ) else skip; operation replaceConsonants(string : OclAny) pre: true post: true activity: var res : String := ""; ; var i : int := 0; var count : int := 0; ; while ((i->compareTo((string)->size())) < 0) do ( if (string[i+1] /= 'a' & string[i+1] /= 'e' & string[i+1] /= 'i' & string[i+1] /= 'o' & string[i+1] /= 'u') then ( i := i + 1; ; count := count + 1; ) else ( if (count > 0) then ( res := res + ("" + ((count))); ) else skip ; res := res + string[i+1]; ; i := i + 1 ; count := 0; )) ; if (count > 0) then ( res := res + ("" + ((count))); ) else skip ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rearrangeArray(arr,n): arr.sort() tempArr=[0]*(n+1) ArrIndex=0 i=0 j=n-1 while(i<=n//2 or j>n//2): tempArr[ArrIndex]=arr[i] ArrIndex=ArrIndex+1 tempArr[ArrIndex]=arr[j] ArrIndex=ArrIndex+1 i=i+1 j=j-1 for i in range(0,n): arr[i]=tempArr[i] arr=[5,8,1,4,2,9,3,7,6] n=len(arr) rearrangeArray(arr,n) for i in range(0,n): print(arr[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{5}->union(Sequence{8}->union(Sequence{1}->union(Sequence{4}->union(Sequence{2}->union(Sequence{9}->union(Sequence{3}->union(Sequence{7}->union(Sequence{ 6 })))))))) ; n := (arr)->size() ; rearrangeArray(arr, n) ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); operation rearrangeArray(arr : OclAny, n : OclAny) pre: true post: true activity: arr := arr->sort() ; var tempArr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var ArrIndex : int := 0 ; var i : int := 0 ; var j : double := n - 1 ; while ((i->compareTo(n div 2)) <= 0 or (j->compareTo(n div 2)) > 0) do ( tempArr[ArrIndex+1] := arr[i+1] ; ArrIndex := ArrIndex + 1 ; tempArr[ArrIndex+1] := arr[j+1] ; ArrIndex := ArrIndex + 1 ; i := i + 1 ; j := j - 1) ; for i : Integer.subrange(0, n-1) do ( arr[i+1] := tempArr[i+1]); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p=int(input()) a=[int(item)for item in input().split()] fac=[1]+[0]*(p-1) facinv=[1]+[0]*(p-1) for i in range(1,p): fac[i]=fac[i-1]*i % p facinv[i]=facinv[i-1]*pow(i,p-2,p)% p comb=[0]*p for i in range(p): comb[i]=fac[p-1]*facinv[i]*facinv[p-1-i]% p ans=[0]*p ppowp=[[0]*(p+1)for _ in range(p+1)] for i in range(p+1): val=1 for j in range(p+1): ppowp[i][j]=val val*=i val %=p for i,item in enumerate(a): if item==1 : ans[0]+=1 for j in range(p): if j % 2==1 : ans[j]-=ppowp[i][p-1-j]*-1*comb[j]% p else : ans[j]-=ppowp[i][p-1-j]*comb[j]% p ans[j]%=p print(" ".join([str(item)for item in ans])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; var fac : Sequence := Sequence{ 1 }->union(MatrixLib.elementwiseMult(Sequence{ 0 }, (p - 1))) ; var facinv : Sequence := Sequence{ 1 }->union(MatrixLib.elementwiseMult(Sequence{ 0 }, (p - 1))) ; for i : Integer.subrange(1, p-1) do ( fac[i+1] := fac[i - 1+1] * i mod p ; facinv[i+1] := facinv[i - 1+1] * (i)->pow(p - 2) mod p) ; var comb : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, p) ; for i : Integer.subrange(0, p-1) do ( comb[i+1] := fac[p - 1+1] * facinv[i+1] * facinv[p - 1 - i+1] mod p) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, p) ; var ppowp : Sequence := Integer.subrange(0, p + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (p + 1)))) ; for i : Integer.subrange(0, p + 1-1) do ( var val : int := 1 ; for j : Integer.subrange(0, p + 1-1) do ( ppowp[i+1][j+1] := val ; val := val * i ; val := val mod p)) ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var item : OclAny := _tuple->at(_indx); if item = 1 then ( ans->first() := ans->first() + 1 ; for j : Integer.subrange(0, p-1) do ( if j mod 2 = 1 then ( ans[j+1] := ans[j+1] - ppowp[i+1][p - 1 - j+1] * -1 * comb[j+1] mod p ) else ( ans[j+1] := ans[j+1] - ppowp[i+1][p - 1 - j+1] * comb[j+1] mod p ) ; ans[j+1] := ans[j+1] mod p) ) else skip) ; execute (StringLib.sumStringsWithSeparator((ans->select(item | true)->collect(item | (("" + ((item)))))), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=0 if(n % 2==0): for i in range(0,n+1,2): ans+=i print(ans) else : for i in range(1,n+1,2): ans+=i print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; if (n mod 2 = 0) then ( for i : Integer.subrange(0, n + 1-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( ans := ans + i) ; execute (ans)->display() ) else ( for i : Integer.subrange(1, n + 1-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( ans := ans + i) ; execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): p=int(input()) *A,=map(int,input().split()) B=[0]*p C=[0]*p C[0]=1 zeros=[0]*p Y=[0]*p R=[0]*p for i in range(p): v=0 b=1 for j in range(i): v+=Y[j]*b b=b*(i-j)% p Y[i]=y=(A[i]-v)*pow(b,p-2,p)% p for j in range(i+1): R[j]+=y*C[j] if icollect( _x | (OclType["int"])->apply(_x) ); operation solve() pre: true post: true activity: var p : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import sys if os.getenv("LOCAL"): sys.stdin=open("_in.txt","r") sys.setrecursionlimit(2147483647) INF=float("inf") IINF=10**18 MOD=10**9+7 P=int(sys.stdin.readline()) A=list(map(int,sys.stdin.readline().split())) def mod_invs(max,mod): invs=[1]*(max+1) for x in range(2,max+1): invs[x]=(-(mod//x)*invs[mod % x])% mod return invs def get_ncrs(n,mod): invs=mod_invs(n,mod) ret=[1] ncr=1 for i in range(1,n+1): ncr=((ncr*(n-i+1)% mod)*invs[i])% mod ret.append(ncr) return ret ncr=get_ncrs(P-1,P) def poly(j): coef=[] c=1 for i in range(P): coef.append(-ncr[i]*c) c=c*-j % P coef.reverse() coef[0]+=1 return coef ans=[0]*P for j,a in enumerate(A): if a==1 : for k,b in enumerate(poly(j)): ans[k]+=b ans[k]%=P print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if os.getenv("LOCAL") then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("_in.txt")) ) else skip ; sys.setrecursionlimit(2147483647) ; var INF : double := ("" + (("inf")))->toReal() ; var IINF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; var P : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; skip ; ncr := get_ncrs(P - 1, P) ; skip ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, P) ; for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); if a = 1 then ( for _tuple : Integer.subrange(1, (poly(j))->size())->collect( _indx | Sequence{_indx-1, (poly(j))->at(_indx)} ) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); ans[k+1] := ans[k+1] + b ; ans[k+1] := ans[k+1] mod P) ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); operation mod_invs(max : OclAny, mod : OclAny) : OclAny pre: true post: true activity: var invs : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (max + 1)) ; for x : Integer.subrange(2, max + 1-1) do ( invs[x+1] := (-(mod div x) * invs[mod mod x+1]) mod mod) ; return invs; operation get_ncrs(n : OclAny, mod : OclAny) : OclAny pre: true post: true activity: invs := mod_invs(n, mod) ; var ret : Sequence := Sequence{ 1 } ; var ncr : int := 1 ; for i : Integer.subrange(1, n + 1-1) do ( ncr := ((ncr * (n - i + 1) mod mod) * invs[i+1]) mod mod ; execute ((ncr) : ret)) ; return ret; operation poly(j : OclAny) : OclAny pre: true post: true activity: var coef : Sequence := Sequence{} ; var c : int := 1 ; for i : Integer.subrange(0, P-1) do ( execute ((-ncr[i+1] * c) : coef) ; c := c * -j mod P) ; coef := coef->reverse() ; coef->first() := coef->first() + 1 ; return coef; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,itertools,bisect,copy,re,heapq from collections import Counter,deque,defaultdict from itertools import accumulate,permutations,combinations,takewhile,compress,cycle INF=float('inf') MOD=10**9+7 EPS=10**-7 sys.setrecursionlimit(1000000) K=int(input()) MAX=10**16 def f(i,j): P=K % 50 Q=i//50 if j

toReal() ; var MOD : double := (10)->pow(9) + 7 ; var EPS : double := (10)->pow(-7) ; sys.setrecursionlimit(1000000) ; var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var MAX : double := (10)->pow(16) ; skip ; var A : Sequence := Sequence{} ; for j : Integer.subrange(0, 50-1) do ( execute ((f(K, j)) : A)) ; execute (50)->display() ; execute (StringLib.sumStringsWithSeparator((A->select(x | true)->collect(x | (("" + ((x)))))), " "))->display(); operation f(i : OclAny, j : OclAny) : OclAny pre: true post: true activity: var P : int := K mod 50 ; var Q : int := i div 50 ; if (j->compareTo(P)) < 0 then ( var ret : double := 49 + 50 - P + 1 + Q ) else ( ret := 49 - P + Q ) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p=int(input()) b_list=[0 for _ in range(p-1)] a_list=list(map(int,input().split())) def frac(n): if a_list[n]==1 : t=1 for j in range(p-1): b_list[j]-=t t=(t*n)% p if a_list[0]==1 : b_list[0]-=1 for i in range(p-1): frac(i+1) b_list.reverse() print(a_list[0],end=' ') for j in b_list : print(j % p,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b_list : Sequence := Integer.subrange(0, p - 1-1)->select(_anon | true)->collect(_anon | (0)) ; var a_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; if a_list->first() = 1 then ( b_list->first() := b_list->first() - 1 ) else skip ; for i : Integer.subrange(0, p - 1-1) do ( frac(i + 1)) ; b_list := b_list->reverse() ; execute (a_list->first())->display() ; for j : b_list do ( execute (j mod p)->display()); operation frac(n : OclAny) pre: true post: true activity: if a_list[n+1] = 1 then ( var t : int := 1 ; for j : Integer.subrange(0, p - 1-1) do ( b_list[j+1] := b_list[j+1] - t ; t := (t * n) mod p) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline p=int(input()) A=tuple(map(int,input().split())) B=[0]*p U=p-1 MOD=p fact=[1]*(U+1) fact_inv=[1]*(U+1) for i in range(1,U+1): fact[i]=(fact[i-1]*i)% MOD fact_inv[U]=pow(fact[U],MOD-2,MOD) for i in range(U,0,-1): fact_inv[i-1]=(fact_inv[i]*i)% MOD def comb(n,k): if k<0 or k>n : return 0 z=fact[n] z*=fact_inv[k] z %=MOD z*=fact_inv[n-k] z %=MOD return z for j,a in enumerate(A): if a : B[0]+=1 temp=1 for i in range(p-1,-1,-1): B[i]-=(-1)**(i % 2)*temp*comb(p-1,i) temp*=j temp %=p B[i]%=p print(*B) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var p : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var B : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, p) ; var U : double := p - 1 ; var MOD : int := p ; var fact : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (U + 1)) ; var fact_inv : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (U + 1)) ; for i : Integer.subrange(1, U + 1-1) do ( fact[i+1] := (fact[i - 1+1] * i) mod MOD) ; fact_inv[U+1] := (fact[U+1])->pow(MOD - 2) ; for i : Integer.subrange(0 + 1, U)->reverse() do ( fact_inv[i - 1+1] := (fact_inv[i+1] * i) mod MOD) ; skip ; for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); if a then ( B->first() := B->first() + 1 ; var temp : int := 1 ; for i : Integer.subrange(-1 + 1, p - 1)->reverse() do ( B[i+1] := B[i+1] - ((-1))->pow((i mod 2)) * temp * comb(p - 1, i) ; temp := temp * j ; temp := temp mod p ; B[i+1] := B[i+1] mod p) ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name B))))))))->display(); operation comb(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if k < 0 or (k->compareTo(n)) > 0 then ( return 0 ) else skip ; var z : OclAny := fact[n+1] ; z := z * fact_inv[k+1] ; z := z mod MOD ; z := z * fact_inv[n - k+1] ; z := z mod MOD ; return z; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) print(min(n-k,1,k),min(n-k,2*k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{n - k, 1, k}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,k=map(int,input().split()) if n==k or k==0 : print(0,0) else : print(1,min(k*2,n-k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = k or k = 0 then ( execute (0)->display() ) else ( execute (1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) if k==n : print(0,0) elif k==0 : print(0,0) elif n//3>=k : print(1,k*2) else : print(1,n-k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if k = n then ( execute (0)->display() ) else (if k = 0 then ( execute (0)->display() ) else (if (n div 3->compareTo(k)) >= 0 then ( execute (1)->display() ) else ( execute (1)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q,w=map(int,input().split()) if q==w or w==0 : a=0 else : a=1 if w==0 : print(a,0) elif w<=q//3 : print(a,w*2) else : print(a,q-w) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : OclAny := null; var w : OclAny := null; Sequence{q,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if q = w or w = 0 then ( var a : int := 0 ) else ( a := 1 ) ; if w = 0 then ( execute (a)->display() ) else (if (w->compareTo(q div 3)) <= 0 then ( execute (a)->display() ) else ( execute (a)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def is_apartment(n,k): if k==0 or k==n : print('0','0') elif k<=n/3 : print('1',k*2) elif k>=n/3 : print('1',n-k) s=input().split() n,k=int(s[0]),int(s[1]) is_apartment(n,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : OclAny := input().split() ; Sequence{n,k} := Sequence{("" + ((s->first())))->toInteger(),("" + ((s[1+1])))->toInteger()} ; is_apartment(n, k); operation is_apartment(n : OclAny, k : OclAny) pre: true post: true activity: if k = 0 or k = n then ( execute ('0')->display() ) else (if (k->compareTo(n / 3)) <= 0 then ( execute ('1')->display() ) else (if (k->compareTo(n / 3)) >= 0 then ( execute ('1')->display() ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) print(a*b,(a+b)*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (a * b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=0 for i in range(n): s+=(n-i)//2+(n-i)% 2 print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : int := 0 ; for i : Integer.subrange(0, n-1) do ( s := s + (n - i) div 2 + (n - i) mod 2) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w=map(int,input().split()) w=list(w) print(w[0]*w[1],2*w[0]+2*w[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; w := (w) ; execute (w->first() * w[1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def zeroUpto(digits): first=int((pow(10,digits)-1)/9); second=int((pow(9,digits)-1)/8); return 9*(first-second); def countZero(num): k=len(num); total=zeroUpto(k-1); non_zero=0 ; for i in range(len(num)): if(num[i]=='0'): non_zero-=1 ; break ; non_zero+=(((ord(num[i])-ord('0'))-1)*(pow(9,k-1-i))); no=0 ; remaining=0 ; calculatedUpto=0 ; for i in range(len(num)): no=no*10+(ord(num[i])-ord('0')); if(i!=0): calculatedUpto=calculatedUpto*10+9 ; remaining=no-calculatedUpto ; ans=zeroUpto(k-1)+(remaining-non_zero-1); return ans ; num="107" ; print("Count of numbers from 1 to",num,"is",countZero(num)); num="1264" ; print("Count of numbers from 1 to",num,"is",countZero(num)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; num := "107"; ; execute ("Count of numbers from 1 to")->display(); ; num := "1264"; ; execute ("Count of numbers from 1 to")->display();; operation zeroUpto(digits : OclAny) pre: true post: true activity: var first : int := ("" + ((((10)->pow(digits) - 1) / 9)))->toInteger(); ; var second : int := ("" + ((((9)->pow(digits) - 1) / 8)))->toInteger(); ; return 9 * (first - second);; operation countZero(num : OclAny) pre: true post: true activity: var k : int := (num)->size(); ; var total : OclAny := zeroUpto(k - 1); ; var non_zero : int := 0; ; for i : Integer.subrange(0, (num)->size()-1) do ( if (num[i+1] = '0') then ( non_zero := non_zero - 1; ; break; ) else skip ; non_zero := non_zero + ((((num[i+1])->char2byte() - ('0')->char2byte()) - 1) * ((9)->pow(k - 1 - i)));) ; var no : int := 0; ; var remaining : int := 0; ; var calculatedUpto : int := 0; ; for i : Integer.subrange(0, (num)->size()-1) do ( no := no * 10 + ((num[i+1])->char2byte() - ('0')->char2byte()); ; if (i /= 0) then ( calculatedUpto := calculatedUpto * 10 + 9; ) else skip) ; remaining := no - calculatedUpto; ; var ans : OclAny := zeroUpto(k - 1) + (remaining - non_zero - 1); ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) if 1<=a<=100 and 1<=b<=100 : area=a*b perimeter=(a+b)*2 print(area,perimeter) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if 1 <= a & (a <= 100) & 1 <= b & (b <= 100) then ( var area : double := a * b ; var perimeter : double := (a + b) * 2 ; execute (area)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- line=input().split() a=int(line[0]) b=int(line[1]) print(str(a*b)+" "+str((a+b)*2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var line : OclAny := input().split() ; var a : int := ("" + ((line->first())))->toInteger() ; var b : int := ("" + ((line[1+1])))->toInteger() ; execute (("" + ((a * b))) + " " + ("" + (((a + b) * 2))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- line=input() a,b=map(int,line.split()) print(a*b,2*(a+b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var line : String := (OclFile["System.in"]).readLine() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (line.split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (a * b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() if a.isupper(): print("A") else : print("a") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; if a->matches("[A-Z ]*") then ( execute ("A")->display() ) else ( execute ("a")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys S=str(input()) A=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"] if S in A : print('A') else : print('a') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var S : String := ("" + (((OclFile["System.in"]).readLine()))) ; var A : Sequence := Sequence{"A"}->union(Sequence{"B"}->union(Sequence{"C"}->union(Sequence{"D"}->union(Sequence{"E"}->union(Sequence{"F"}->union(Sequence{"G"}->union(Sequence{"H"}->union(Sequence{"I"}->union(Sequence{"J"}->union(Sequence{"K"}->union(Sequence{"L"}->union(Sequence{"M"}->union(Sequence{"N"}->union(Sequence{"O"}->union(Sequence{"P"}->union(Sequence{"Q"}->union(Sequence{"R"}->union(Sequence{"S"}->union(Sequence{"T"}->union(Sequence{"U"}->union(Sequence{"V"}->union(Sequence{"W"}->union(Sequence{"X"}->union(Sequence{"Y"}->union(Sequence{ "Z" }))))))))))))))))))))))))) ; if (A)->includes(S) then ( execute ('A')->display() ) else ( execute ('a')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- z=input() print("A" if z==z.upper()else "a") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var z : String := (OclFile["System.in"]).readLine() ; execute (if z = z->toUpperCase() then "A" else "a" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- Alph=str(input()) type_Alph=Alph.isupper() if type_Alph==True : ans='A' else : ans='a' print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Alph : String := ("" + (((OclFile["System.in"]).readLine()))) ; var type_Alph : boolean := Alph->matches("[A-Z ]*") ; if type_Alph = true then ( var ans : String := 'A' ) else ( ans := 'a' ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- char=input() print('a')if char.lower()==char else print('A') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var char : String := (OclFile["System.in"]).readLine() ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'a'))))))) )))))) if (logical_test (comparison (comparison (expr (atom (name char)) (trailer . (name lower) (arguments ( ))))) == (comparison (expr (atom (name char)))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'A'))))))) )))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minElements(arr,n): halfSum=0 for i in range(n): halfSum=halfSum+arr[i] halfSum=int(halfSum/2) arr.sort(reverse=True) res=0 curr_sum=0 for i in range(n): curr_sum+=arr[i] res+=1 if curr_sum>halfSum : return res return res arr=[3,1,7,1] n=len(arr) print(minElements(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{3}->union(Sequence{1}->union(Sequence{7}->union(Sequence{ 1 }))) ; n := (arr)->size() ; execute (minElements(arr, n))->display(); operation minElements(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var halfSum : int := 0 ; for i : Integer.subrange(0, n-1) do ( halfSum := halfSum + arr[i+1]) ; halfSum := ("" + ((halfSum / 2)))->toInteger() ; arr := arr->sort() ; var res : int := 0 ; var curr_sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( curr_sum := curr_sum + arr[i+1] ; res := res + 1 ; if (curr_sum->compareTo(halfSum)) > 0 then ( return res ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=[1,2,4,6] if n<5 : print(s[n-1]) else : a,b=4,6 i=5 while itoInteger() ; var s : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 6 }))) ; if n < 5 then ( execute (s[n - 1+1])->display() ) else ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{4,6} ; var i : int := 5 ; while (i->compareTo(n)) < 0 do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a + i} ; i := i + 1) ; execute (a + i)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def cone(a): if(a<0): return-1 ; r=(a*math.sqrt(2))/3 ; h=(2*a)/3 ; V=3.14*math.pow(r,2)*h ; return V ; a=5 ; print(cone(a)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 5; ; execute (cone(a))->display();; operation cone(a : OclAny) pre: true post: true activity: if (a < 0) then ( return -1; ) else skip ; var r : double := (a * (2)->sqrt()) / 3; ; var h : double := (2 * a) / 3; ; var V : double := 3.14 * (r)->pow(2) * h; ; return V;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMin(arr,n): ans=1 for i in range(n): j=i+1 while(j=arr[j-1]): j+=1 ans=max(ans,j-i) i=j-1 return n-ans arr=[3,2,1] n=len(arr) print(findMin(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{3}->union(Sequence{2}->union(Sequence{ 1 })) ; n := (arr)->size() ; execute (findMin(arr, n))->display(); operation findMin(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := 1 ; for i : Integer.subrange(0, n-1) do ( var j : OclAny := i + 1 ; while ((j->compareTo(n)) < 0 & (arr[j+1]->compareTo(arr[j - 1+1])) >= 0) do ( j := j + 1) ; ans := Set{ans, j - i}->max() ; var i : double := j - 1) ; return n - ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=1000000007 eps=10**-9 def main(): import sys input=sys.stdin.readline N=bin(int(input()))[2 :] ans=[100,100]+list(range(1,len(N)))+list(range(1,len(N))) k=len(N) for i in range(len(N)-1): if N[-i-1]=="1" : for j in range(len(ans)): if ans[j]==i+1 : ans.insert(j,k) k+=1 break ans+=list(range(k-1,len(N)-1,-1)) print(len(ans)) print(*ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : int := 1000000007 ; var eps : double := (10)->pow(-9) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var N : OclAny := bin(("" + (((OclFile["System.in"]).readLine())))->toInteger()).subrange(2+1) ; var ans : Sequence := Sequence{100}->union(Sequence{ 100 })->union((Integer.subrange(1, (N)->size()-1)))->union((Integer.subrange(1, (N)->size()-1))) ; var k : int := (N)->size() ; for i : Integer.subrange(0, (N)->size() - 1-1) do ( if N->reverse()->at(-(-i - 1)) = "1" then ( for j : Integer.subrange(0, (ans)->size()-1) do ( if ans[j+1] = i + 1 then ( ans := ans.insertAt(j+1, k) ; k := k + 1 ; break ) else skip) ) else skip) ; ans := ans + (Integer.subrange((N)->size() - 1 + 1, k - 1)->reverse()) ; execute ((ans)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import deque read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines def f(N,i=1): if N==1 : return deque(),deque() if N % 2==0 : A,B=f(N//2,i+1) A.append(i) B.append(i) return A,B else : A,B=f(N-1,i+1) A.append(i) B.appendleft(i) return A,B N=int(read())+1 A,B=f(N) S=A+B print(len(S)) print(*S) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; skip ; N := ("" + ((read())))->toInteger() + 1 ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := f(N) ; var S : OclAny := A + B ; execute ((S)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name S))))))))->display(); operation f(N : OclAny, i : int) : OclAny pre: true post: true activity: if i->oclIsUndefined() then i := 1 else skip; if N = 1 then ( return (), () ) else skip ; if N mod 2 = 0 then ( var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := f(N div 2, i + 1) ; execute ((i) : A) ; execute ((i) : B) ; return A, B ) else ( var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := f(N - 1, i + 1) ; execute ((i) : A) ; B := B->prepend(i) ; return A, B ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- fact=[1] for i in range(1,101): fact.append(fact[-1]*i) def C(a,b): return fact[a]//(fact[b]*fact[a-b]) def sC(a,b): ret=0 for i in range(min(b,a-b)+1): ret+=C(b,i)*C(a-b,i) return ret def calc(n,k): if n<=0 : return[] i=0 while(1<<(i+1))-1<=n : i+=1 ret=[str(k)]*(i+1) rem=n-((1<0 : while True : tmp=sC(i,j) if tmp<=rem : ret.insert(j,str(kk)) ret.append(str(kk)) kk+=1 rem-=tmp else : break j-=1 return ret+calc(rem,kk) N=int(input()) X=calc(N,1) print(len(X)) print(" ".join(X)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var fact : Sequence := Sequence{ 1 } ; for i : Integer.subrange(1, 101-1) do ( execute ((fact->last() * i) : fact)) ; skip ; skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var X : OclAny := calc(N, 1) ; execute ((X)->size())->display() ; execute (StringLib.sumStringsWithSeparator((X), " "))->display(); operation C(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return fact[a+1] div (fact[b+1] * fact[a - b+1]); operation sC(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var ret : int := 0 ; for i : Integer.subrange(0, Set{b, a - b}->min() + 1-1) do ( ret := ret + C(b, i) * C(a - b, i)) ; return ret; operation calc(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if n <= 0 then ( return Sequence{} ) else skip ; var i : int := 0 ; while ((1 * (2->pow((i + 1)))) - 1->compareTo(n)) <= 0 do ( i := i + 1) ; ret := MatrixLib.elementwiseMult(Sequence{ ("" + ((k))) }, (i + 1)) ; var rem : double := n - ((1 * (2->pow(i))) - 1) ; var kk : OclAny := k + 1 ; i := i + 1 ; var j : int := i div 2 ; while j > 0 do ( while true do ( var tmp : OclAny := sC(i, j) ; if (tmp->compareTo(rem)) <= 0 then ( ret := ret.insertAt(j+1, ("" + ((kk)))) ; execute ((("" + ((kk)))) : ret) ; kk := kk + 1 ; rem := rem - tmp ) else ( break )) ; j := j - 1) ; return ret + calc(rem, kk); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input())+1 k=50 while ~ n>>k & 1 : k-=1 k-=1 a=[] b=[] now=1 while k>=0 : a=a+[now] b=b+[now] now+=1 if n>>k & 1 : a=a+[now] b=[now]+b now+=1 k-=1 print(len(a+b)) print(*(a+b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() + 1 ; var k : int := 50 ; while MathLib.bitwiseAnd(MathLib.bitwiseNot(n) /(2->pow(k)), 1) do ( k := k - 1) ; k := k - 1 ; var a : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; var now : int := 1 ; while k >= 0 do ( a := a->union(Sequence{ now }) ; b := b->union(Sequence{ now }) ; now := now + 1 ; if MathLib.bitwiseAnd(n /(2->pow(k)), 1) then ( a := a->union(Sequence{ now }) ; b := Sequence{ now }->union(b) ; now := now + 1 ) else skip ; k := k - 1) ; execute ((a->union(b))->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name a))) + (expr (atom (name b)))))))) ))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=[] y=[] k=1 for c in bin(n+1)[2 :][1 :]: x+=[k] y+=[k] k+=1 if int(c): x=[k]+x y+=[k] k+=1 print(len(x+y)) print(*(x+y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := Sequence{} ; var y : Sequence := Sequence{} ; var k : int := 1 ; for c : bin(n + 1).subrange(2+1)->tail() do ( x := x + Sequence{ k } ; y := y + Sequence{ k } ; k := k + 1 ; if ("" + ((c)))->toInteger() then ( x := Sequence{ k }->union(x) ; y := y + Sequence{ k } ; k := k + 1 ) else skip) ; execute ((x->union(y))->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (name y)))))))) ))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W=list(map(int,input().split())) if H % 3==0 or W % 3==0 : print(0) exit() a=[] a.append([H//3*W,(H-H//3)*(W//2),(H-H//3)*(W//2+W % 2)]) a.append([(H//3+1)*W,(H-H//3-1)*(W//2),(H-H//3-1)*(W//2+W % 2)]) t=W W=H H=t a.append([H//3*W,(H-H//3)*(W//2),(H-H//3)*(W//2+W % 2)]) a.append([(H//3+1)*W,(H-H//3-1)*(W//2),(H-H//3-1)*(W//2+W % 2)]) ans=min(W,H) for i in range(len(a)): if not 0 in a[i]: ans=min(ans,max(a[i])-min(a[i])) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if H mod 3 = 0 or W mod 3 = 0 then ( execute (0)->display() ; exit() ) else skip ; var a : Sequence := Sequence{} ; execute ((Sequence{H div 3 * W}->union(Sequence{(H - H div 3) * (W div 2)}->union(Sequence{ (H - H div 3) * (W div 2 + W mod 2) }))) : a) ; execute ((Sequence{(H div 3 + 1) * W}->union(Sequence{(H - H div 3 - 1) * (W div 2)}->union(Sequence{ (H - H div 3 - 1) * (W div 2 + W mod 2) }))) : a) ; var t : OclAny := W ; var W : OclAny := H ; var H : OclAny := t ; execute ((Sequence{H div 3 * W}->union(Sequence{(H - H div 3) * (W div 2)}->union(Sequence{ (H - H div 3) * (W div 2 + W mod 2) }))) : a) ; execute ((Sequence{(H div 3 + 1) * W}->union(Sequence{(H - H div 3 - 1) * (W div 2)}->union(Sequence{ (H - H div 3 - 1) * (W div 2 + W mod 2) }))) : a) ; var ans : OclAny := Set{W, H}->min() ; for i : Integer.subrange(0, (a)->size()-1) do ( if not((a[i+1])->includes(0)) then ( ans := Set{ans, (a[i+1])->max() - (a[i+1])->min()}->min() ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) int1=lambda x : int(x)-1 p2D=lambda x : print(*x,sep="\n") def MI(): return map(int,sys.stdin.readline().split()) def LI(): return list(map(int,sys.stdin.readline().split())) def LLI(rows_number): return[LI()for _ in range(rows_number)] def div2(h,w): if w % 2 and h % 2 : if wpow(6)) ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; var p2D : Function := lambda x : OclAny in (((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ; skip ; skip ; skip ; skip ; skip ; main(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LLI(rows_number : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows_number-1)->select(_anon | true)->collect(_anon | (LI())); operation div2(h : OclAny, w : OclAny) : OclAny pre: true post: true activity: if w mod 2 & h mod 2 then ( if (w->compareTo(h)) < 0 then ( Sequence{w,h} := Sequence{h,w} ) else skip ; return h * (w div 2), h * (w div 2 + 1) ) else ( return h * w div 2, h * w div 2 ); operation main() pre: true post: true activity: Sequence{h,w} := MI() ; var a : Sequence := Sequence{} ; for w1 : Integer.subrange(1, w div 2 + 1-1) do ( var p1 : double := w1 * h ; var p2 : OclAny := null; var p3 : OclAny := null; Sequence{p2,p3} := div2(h, w - w1) ; execute ((Set{p1, p2, p3}->max() - Set{p1, p2, p3}->min()) : a)) ; Sequence{h,w} := Sequence{w,h} ; for w1 : Integer.subrange(1, w div 2 + 1-1) do ( p1 := w1 * h ; var p2 : OclAny := null; var p3 : OclAny := null; Sequence{p2,p3} := div2(h, w - w1) ; execute ((Set{p1, p2, p3}->max() - Set{p1, p2, p3}->min()) : a)) ; execute ((a)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W=(int(i)for i in input().split()) ans=float("inf") for i in range(1,H): a,b=(i,W) S=W*(H-i) if a % 2==0 or b % 2==0 : ans=min(ans,abs(S-a*b//2)) else : if a==1 and b==1 : continue else : Sbig=(max(a,b)+1)*min(a,b)//2 Ssma=(max(a,b)-1)*min(a,b)//2 Sdiff=max(abs(S-Sbig),abs(S-Ssma),abs(Sbig-Ssma)) ans=min(ans,Sdiff) H,W=(W,H) for i in range(1,H): a,b=(i,W) S=W*(H-i) if a % 2==0 or b % 2==0 : ans=min(ans,abs(S-a*b//2)) else : if a==1 and b==1 : continue else : Sbig=(max(a,b)+1)*min(a,b)//2 Ssma=(max(a,b)-1)*min(a,b)//2 Sdiff=max(abs(S-Sbig),abs(S-Ssma),abs(Sbig-Ssma)) ans=min(ans,Sdiff) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var ans : double := ("" + (("inf")))->toReal() ; for i : Integer.subrange(1, H-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{i, W} ; var S : double := W * (H - i) ; if a mod 2 = 0 or b mod 2 = 0 then ( ans := Set{ans, (S - a * b div 2)->abs()}->min() ) else ( if a = 1 & b = 1 then ( continue ) else ( var Sbig : int := (Set{a, b}->max() + 1) * Set{a, b}->min() div 2 ; var Ssma : int := (Set{a, b}->max() - 1) * Set{a, b}->min() div 2 ; var Sdiff : OclAny := Set{(S - Sbig)->abs(), (S - Ssma)->abs(), (Sbig - Ssma)->abs()}->max() ; ans := Set{ans, Sdiff}->min() ) )) ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := Sequence{W, H} ; for i : Integer.subrange(1, H-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{i, W} ; S := W * (H - i) ; if a mod 2 = 0 or b mod 2 = 0 then ( ans := Set{ans, (S - a * b div 2)->abs()}->min() ) else ( if a = 1 & b = 1 then ( continue ) else ( Sbig := (Set{a, b}->max() + 1) * Set{a, b}->min() div 2 ; Ssma := (Set{a, b}->max() - 1) * Set{a, b}->min() div 2 ; Sdiff := Set{(S - Sbig)->abs(), (S - Ssma)->abs(), (Sbig - Ssma)->abs()}->max() ; ans := Set{ans, Sdiff}->min() ) )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read input=sys.stdin.buffer.readline inputs=sys.stdin.buffer.readlines import math def main(): H,W=map(int,input().split()) ans=[] target=H*W/3 if(H % 3)*(W % 3)==0 : ans.append(0) else : ans.append(H) ans.append(W) a1=math.floor(H/3)*W a2=(W//2)*(H-math.floor(H/3)) a3=H*W-a1-a2 ans.append(max(a1,a2,a3)-min(a1,a2,a3)) a1=math.ceil(H/3)*W a2=(W//2)*(H-math.ceil(H/3)) a3=H*W-a1-a2 ans.append(max(a1,a2,a3)-min(a1,a2,a3)) H,W=W,H a1=math.floor(H/3)*W a2=(W//2)*(H-math.floor(H/3)) a3=H*W-a1-a2 ans.append(max(a1,a2,a3)-min(a1,a2,a3)) a1=math.ceil(H/3)*W a2=(W//2)*(H-math.ceil(H/3)) a3=H*W-a1-a2 ans.append(max(a1,a2,a3)-min(a1,a2,a3)) print(min(ans)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var input : OclAny := sys.stdin.buffer.readline ; var inputs : OclAny := sys.stdin.buffer.readlines ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := Sequence{} ; var target : double := H * W / 3 ; if (H mod 3) * (W mod 3) = 0 then ( execute ((0) : ans) ) else ( execute ((H) : ans) ; execute ((W) : ans) ; var a1 : double := (H / 3)->floor() * W ; var a2 : double := (W div 2) * (H - (H / 3)->floor()) ; var a3 : double := H * W - a1 - a2 ; execute ((Set{a1, a2, a3}->max() - Set{a1, a2, a3}->min()) : ans) ; a1 := (H / 3)->ceil() * W ; a2 := (W div 2) * (H - (H / 3)->ceil()) ; a3 := H * W - a1 - a2 ; execute ((Set{a1, a2, a3}->max() - Set{a1, a2, a3}->min()) : ans) ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := Sequence{W,H} ; a1 := (H / 3)->floor() * W ; a2 := (W div 2) * (H - (H / 3)->floor()) ; a3 := H * W - a1 - a2 ; execute ((Set{a1, a2, a3}->max() - Set{a1, a2, a3}->min()) : ans) ; a1 := (H / 3)->ceil() * W ; a2 := (W div 2) * (H - (H / 3)->ceil()) ; a3 := H * W - a1 - a2 ; execute ((Set{a1, a2, a3}->max() - Set{a1, a2, a3}->min()) : ans) ) ; execute ((ans)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) i=10 while k : i+=9 if sum(map(int,str(i)))==10 : k-=1 print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 10 ; while k do ( i := i + 9 ; if ((("" + ((i))))->collect( _x | (OclType["int"])->apply(_x) ))->sum() = 10 then ( k := k - 1 ) else skip) ; execute (i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def Prime(n): if n==1 : return False for i in range(2,mt.ceil(mt.sqrt(n+1))): if n % i==0 : return False return True def checkSumPrime(string): summ=0 for i in range(1,len(string)): summ+=abs(int(string[i-1])-int(string[i])) if Prime(summ): return True else : return False num=142 string=str(num) s=[i for i in string] if checkSumPrime(s): print("Prime") else : print("Not Prime\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var num : int := 142 ; string := ("" + ((num))) ; var s : Sequence := string->select(i | true)->collect(i | (i)) ; if checkSumPrime(s) then ( execute ("Prime")->display() ) else ( execute ("Not Prime\n")->display() ); operation Prime(n : OclAny) : OclAny pre: true post: true activity: if n = 1 then ( return false ) else skip ; for i : Integer.subrange(2, mt.ceil(mt.sqrt(n + 1))-1) do ( if n mod i = 0 then ( return false ) else skip) ; return true; operation checkSumPrime(string : OclAny) : OclAny pre: true post: true activity: var summ : int := 0 ; for i : Integer.subrange(1, (string)->size()-1) do ( summ := summ + (("" + ((string[i - 1+1])))->toInteger() - ("" + ((string[i+1])))->toInteger())->abs()) ; if Prime(summ) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : x=int(input()) y=1000-x if x==0 : break else : a=y//500 b=y % 500 c=b//100 d=b % 100 e=d//50 f=d % 50 g=f//10 h=f % 10 i=h//5 j=h % 5 k=j//1 print(a+c+e+g+i+k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var y : double := 1000 - x ; if x = 0 then ( break ) else ( var a : int := y div 500 ; var b : int := y mod 500 ; var c : int := b div 100 ; var d : int := b mod 100 ; var e : int := d div 50 ; var f : int := d mod 50 ; var g : int := f div 10 ; var h : int := f mod 10 ; var i : int := h div 5 ; var j : int := h mod 5 ; var k : int := j div 1 ) ; execute (a + c + e + g + i + k)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w=map(int,input().split()) ans=h*w for x,y in[[h,w],[w,h]]: for margin_x in[0,1]: for second_cut in['x','y']: area=[0]*3 area[0]=(x//3+margin_x)*y x2=x-(x//3+margin_x) if(second_cut=='x'): area[1]=(x2//2)*y area[2]=(x2-x2//2)*y else : area[1]=x2*(y//2) area[2]=x2*(y-y//2) ans=min(ans,max(area)-min(area)) if(ans==0): print(ans) exit() print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : double := h * w ; for _tuple : Sequence{Sequence{h}->union(Sequence{ w })}->union(Sequence{ Sequence{w}->union(Sequence{ h }) }) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); for margin_x : Sequence{0}->union(Sequence{ 1 }) do ( for second_cut : Sequence{'x'}->union(Sequence{ 'y' }) do ( var area : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 3) ; area->first() := (x div 3 + margin_x) * y ; var x2 : double := x - (x div 3 + margin_x) ; if (second_cut = 'x') then ( area[1+1] := (x2 div 2) * y ; area[2+1] := (x2 - x2 div 2) * y ) else ( area[1+1] := x2 * (y div 2) ; area[2+1] := x2 * (y - y div 2) ) ; ans := Set{ans, (area)->max() - (area)->min()}->min() ; if (ans = 0) then ( execute (ans)->display() ; exit() ) else skip))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def otherEndPoint(x1,y1,m1,m2): x2=(2*m1-x1) y2=(2*m2-y1) print("x2={},y2={}".format(x2,y2)) x1=-4 y1=-1 m1=3 m2=5 otherEndPoint(x1,y1,m1,m2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x1 := -4 ; y1 := -1 ; m1 := 3 ; m2 := 5 ; otherEndPoint(x1, y1, m1, m2); operation otherEndPoint(x1 : OclAny, y1 : OclAny, m1 : OclAny, m2 : OclAny) pre: true post: true activity: var x2 : double := (2 * m1 - x1) ; var y2 : double := (2 * m2 - y1) ; execute (StringLib.interpolateStrings("x2={},y2={}", Sequence{x2, y2}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys arr=[] for line in sys.stdin : arr.append([int(x)for x in line.strip().split()]) arr2=[[1,1,1],[1,1,1],[1,1,1]] row=0 while row<=2 : col=0 while col<=2 : if(arr[row][col]% 2!=0): if(arr2[row][col]): arr2[row][col]=0 else : arr2[row][col]=1 if col+1<=2 : if(arr2[row][col+1]): arr2[row][col+1]=0 else : arr2[row][col+1]=1 if row+1<=2 : if(arr2[row+1][col]): arr2[row+1][col]=0 else : arr2[row+1][col]=1 if col-1<=2 and col-1>=0 : if(arr2[row][col-1]): arr2[row][col-1]=0 else : arr2[row][col-1]=1 if row-1<=2 and row-1>=0 : if(arr2[row-1][col]): arr2[row-1][col]=0 else : arr2[row-1][col]=1 col+=1 row+=1 row=0 while row<=2 : col=0 while col<=2 : print(arr2[row][col],end="") col+=1 print('') row+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var arr : Sequence := Sequence{} ; for line : OclFile["System.in"] do ( execute ((line->trim().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) : arr)) ; var arr2 : Sequence := Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))}->union(Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))}->union(Sequence{ Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })) })) ; var row : int := 0 ; while row <= 2 do ( var col : int := 0 ; while col <= 2 do ( if (arr[row+1][col+1] mod 2 /= 0) then ( if (arr2[row+1][col+1]) then ( arr2[row+1][col+1] := 0 ) else ( arr2[row+1][col+1] := 1 ) ; if col + 1 <= 2 then ( if (arr2[row+1][col + 1+1]) then ( arr2[row+1][col + 1+1] := 0 ) else ( arr2[row+1][col + 1+1] := 1 ) ) else skip ; if row + 1 <= 2 then ( if (arr2[row + 1+1][col+1]) then ( arr2[row + 1+1][col+1] := 0 ) else ( arr2[row + 1+1][col+1] := 1 ) ) else skip ; if col - 1 <= 2 & col - 1 >= 0 then ( if (arr2[row+1][col - 1+1]) then ( arr2[row+1][col - 1+1] := 0 ) else ( arr2[row+1][col - 1+1] := 1 ) ) else skip ; if row - 1 <= 2 & row - 1 >= 0 then ( if (arr2[row - 1+1][col+1]) then ( arr2[row - 1+1][col+1] := 0 ) else ( arr2[row - 1+1][col+1] := 1 ) ) else skip ) else skip ; col := col + 1) ; row := row + 1) ; row := 0 ; while row <= 2 do ( col := 0 ; while col <= 2 do ( execute (arr2[row+1][col+1])->display() ; col := col + 1) ; execute ('')->display() ; row := row + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=[] for _ in range(3): l1=list(map(int,input().split())) l.append(l1) grid=[[0]*3 for _ in range(3)] di=[(1,0),(-1,0),(0,1),(0,-1)] for i in range(3): for j in range(3): sm=l[i][j] for k in di : a=i+k[0] b=j+k[1] if a>=0 and a<3 and b>=0 and b<3 : sm+=l[a][b] if sm % 2==0 : print("1",end="") else : print("0",end="") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := Sequence{} ; for _anon : Integer.subrange(0, 3-1) do ( var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((l1) : l)) ; var grid : Sequence := Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 3))) ; var di : Sequence := Sequence{Sequence{1, 0}}->union(Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{ Sequence{0, -1} }))) ; for i : Integer.subrange(0, 3-1) do ( for j : Integer.subrange(0, 3-1) do ( var sm : OclAny := l[i+1][j+1] ; for k : di do ( var a : OclAny := i + k->first() ; var b : OclAny := j + k[1+1] ; if a >= 0 & a < 3 & b >= 0 & b < 3 then ( sm := sm + l[a+1][b+1] ) else skip) ; if sm mod 2 = 0 then ( execute ("1")->display() ) else ( execute ("0")->display() )) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- light_a=[[1 for i in range(3)]for j in range(3)] press_a=[] for i in range(3): l1=list(map(int,input().split())) l2=list(map(lambda x : x % 2,l1)) press_a.append(l2) for i in range(3): for j in range(3): if press_a[i][j]: try : if i==0 : pass elif light_a[i-1][j]==1 : light_a[i-1][j]=0 else : light_a[i-1][j]=1 except Exception : pass try : if light_a[i][j]==1 : light_a[i][j]=0 else : light_a[i][j]=1 except Exception : pass try : if light_a[i+1][j]==1 : light_a[i+1][j]=0 else : light_a[i+1][j]=1 except Exception : pass try : if light_a[i][j+1]==1 : light_a[i][j+1]=0 else : light_a[i][j+1]=1 except Exception : pass try : if j==0 : pass elif light_a[i][j-1]==1 : light_a[i][j-1]=0 else : light_a[i][j-1]=1 except Exception : pass for i in range(3): for j in range(3): print(light_a[i][j],end="") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var light_a : Sequence := Integer.subrange(0, 3-1)->select(j | true)->collect(j | (Integer.subrange(0, 3-1)->select(i | true)->collect(i | (1)))) ; var press_a : Sequence := Sequence{} ; for i : Integer.subrange(0, 3-1) do ( var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l2 : Sequence := ((l1)->collect( _x | (lambda x : OclAny in (x mod 2))->apply(_x) )) ; execute ((l2) : press_a)) ; for i : Integer.subrange(0, 3-1) do ( for j : Integer.subrange(0, 3-1) do ( if press_a[i+1][j+1] then ( try ( if i = 0 then ( skip ) else (if light_a[i - 1+1][j+1] = 1 then ( light_a[i - 1+1][j+1] := 0 ) else ( light_a[i - 1+1][j+1] := 1 ) ) ) (except_clause except (test (logical_test (comparison (expr (atom (name Exception)))))) : (suite (stmt (simple_stmt (small_stmt pass))))) ; try ( if light_a[i+1][j+1] = 1 then ( light_a[i+1][j+1] := 0 ) else ( light_a[i+1][j+1] := 1 )) (except_clause except (test (logical_test (comparison (expr (atom (name Exception)))))) : (suite (stmt (simple_stmt (small_stmt pass))))) ; try ( if light_a[i + 1+1][j+1] = 1 then ( light_a[i + 1+1][j+1] := 0 ) else ( light_a[i + 1+1][j+1] := 1 )) (except_clause except (test (logical_test (comparison (expr (atom (name Exception)))))) : (suite (stmt (simple_stmt (small_stmt pass))))) ; try ( if light_a[i+1][j + 1+1] = 1 then ( light_a[i+1][j + 1+1] := 0 ) else ( light_a[i+1][j + 1+1] := 1 )) (except_clause except (test (logical_test (comparison (expr (atom (name Exception)))))) : (suite (stmt (simple_stmt (small_stmt pass))))) ; try ( if j = 0 then ( skip ) else (if light_a[i+1][j - 1+1] = 1 then ( light_a[i+1][j - 1+1] := 0 ) else ( light_a[i+1][j - 1+1] := 1 ) ) ) (except_clause except (test (logical_test (comparison (expr (atom (name Exception)))))) : (suite (stmt (simple_stmt (small_stmt pass))))) ) else skip)) ; for i : Integer.subrange(0, 3-1) do ( for j : Integer.subrange(0, 3-1) do ( execute (light_a[i+1][j+1])->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mat=[] for _ in range(3): ls=list(map(int,input().split())) mat.append(ls) for i in range(3): for j in range(3): mat[i][j]%=2 ans=[[1,1,1],[1,1,1],[1,1,1]] for i in range(3): for j in range(3): if(mat[i][j]==1): ans[i][j]=1-ans[i][j] if(i-1>=0): ans[i-1][j]=1-(ans[i-1][j]) if(i+1<3): ans[i+1][j]=1-(ans[i+1][j]) if(j-1>=0): ans[i][j-1]=1-(ans[i][j-1]) if(j+1<3): ans[i][j+1]=1-(ans[i][j+1]) for i in range(3): for j in range(3): print(str(ans[i][j]),end="") if(i+1<3): print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mat : Sequence := Sequence{} ; for _anon : Integer.subrange(0, 3-1) do ( var ls : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((ls) : mat)) ; for i : Integer.subrange(0, 3-1) do ( for j : Integer.subrange(0, 3-1) do ( mat[i+1][j+1] := mat[i+1][j+1] mod 2)) ; var ans : Sequence := Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))}->union(Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))}->union(Sequence{ Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })) })) ; for i : Integer.subrange(0, 3-1) do ( for j : Integer.subrange(0, 3-1) do ( if (mat[i+1][j+1] = 1) then ( ans[i+1][j+1] := 1 - ans[i+1][j+1] ; if (i - 1 >= 0) then ( ans[i - 1+1][j+1] := 1 - (ans[i - 1+1][j+1]) ) else skip ; if (i + 1 < 3) then ( ans[i + 1+1][j+1] := 1 - (ans[i + 1+1][j+1]) ) else skip ; if (j - 1 >= 0) then ( ans[i+1][j - 1+1] := 1 - (ans[i+1][j - 1+1]) ) else skip ; if (j + 1 < 3) then ( ans[i+1][j + 1+1] := 1 - (ans[i+1][j + 1+1]) ) else skip ) else skip)) ; for i : Integer.subrange(0, 3-1) do ( for j : Integer.subrange(0, 3-1) do ( execute (("" + ((ans[i+1][j+1]))))->display()) ; if (i + 1 < 3) then ( execute (->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=10005 ; spf=[0]*MAX ; def sieve(): spf[0]=1 ; spf[1]=-1 ; i=2 ; while(i*iunion(Sequence{4}->union(Sequence{ 8 })); ; n := (arr)->size(); ; execute (smallestInteger(arr, n))->display();; operation sieve() pre: true post: true activity: spf->first() := 1; ; spf[1+1] := -1; ; var i : int := 2; ; while ((i * i->compareTo(MAX)) < 0) do ( if (spf[i+1] = 0) then ( for j : Integer.subrange(i * 2, MAX-1)->select( $x | ($x - i * 2) mod i = 0 ) do ( if (spf[j+1] = 0) then ( spf[j+1] := i; ) else skip) ) else skip ; i := i + 1;) ; for i : Integer.subrange(2, MAX-1) do ( if (spf[i+1] = 0) then ( spf[i+1] := i; ) else skip); operation __gcd(a : OclAny, b : OclAny) pre: true post: true activity: if (b = 0) then ( return a; ) else skip ; return __gcd(b, a mod b);; operation smallestInteger(arr : OclAny, n : OclAny) pre: true post: true activity: var gcd : int := 0; ; for i : Integer.subrange(0, n-1) do ( gcd := __gcd(gcd, arr[i+1]);) ; return spf[gcd+1];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) m=10**9+7 if k==0 : print(pow(n,n-1,m)) elif k==1 : print(pow(n,n,m)) else : c=1 x=k while x!=1 : x=(x*k)% n c+=1 print(pow(n,(n-1)//c,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : double := (10)->pow(9) + 7 ; if k = 0 then ( execute ((n)->pow(n - 1))->display() ) else (if k = 1 then ( execute ((n)->pow(n))->display() ) else ( var c : int := 1 ; var x : OclAny := k ; while x /= 1 do ( x := (x * k) mod n ; c := c + 1) ; execute ((n)->pow((n - 1) div c))->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin import sys sys.setrecursionlimit(10**6) n,k=map(int,stdin.readline().strip().split()) def dfs(n): visited[n]=True while not visited[adj[n]]: n=adj[n] visited[n]=True mod=10**9+7 adj=[-1 for i in range(n+1)] visited=[False for i in range(n+1)] for i in range(n): adj[i]=(i*k)% n pairs=0 for i in range(1,n): if not visited[i]: dfs(i) pairs+=1 if k==1 : print(pow(n,n,mod)) else : print(pow(n,pairs,mod)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(6)) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; var mod : double := (10)->pow(9) + 7 ; var adj : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (-1)) ; var visited : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (false)) ; for i : Integer.subrange(0, n-1) do ( adj[i+1] := (i * k) mod n) ; var pairs : int := 0 ; for i : Integer.subrange(1, n-1) do ( if not(visited[i+1]) then ( dfs(i) ; pairs := pairs + 1 ) else skip) ; if k = 1 then ( execute ((n)->pow(n))->display() ) else ( execute ((n)->pow(pairs))->display() ); operation dfs(n : OclAny) pre: true post: true activity: visited[n+1] := true ; while not(visited[adj[n+1]+1]) do ( n := adj[n+1] ; visited[n+1] := true); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sum(n): if n<2 : return 1 else : return 1/n+(sum(n-1)) print(sum(8)) print(sum(10)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute ((8)->sum())->display() ; execute ((10)->sum())->display(); operation sum(n : OclAny) : OclAny pre: true post: true activity: if n < 2 then ( return 1 ) else ( return 1 / n + ((n - 1)->sum()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=int(1e9+7) n,k=map(int,input().split()) if k<2 : p=n-(1-k) else : t=1 a=k while a!=1 : a=a*k % n t+=1 p=(n-1)//t print(pow(n,p,MOD)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : int := ("" + ((("1e9")->toReal() + 7)))->toInteger() ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if k < 2 then ( var p : double := n - (1 - k) ) else ( var t : int := 1 ; var a : OclAny := k ; while a /= 1 do ( a := a * k mod n ; t := t + 1) ; p := (n - 1) div t ) ; execute ((n)->pow(p))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=[500,100,50,10,5,1] def solve(n): t=1000-n cnt=0 for i in range(len(c)): while t//c[i]>0 : t-=c[i] cnt+=1 return cnt for i in range(5): n=int(input()) if n==0 : exit() print(solve(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : Sequence := Sequence{500}->union(Sequence{100}->union(Sequence{50}->union(Sequence{10}->union(Sequence{5}->union(Sequence{ 1 }))))) ; skip ; for i : Integer.subrange(0, 5-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( exit() ) else skip ; execute (solve(n))->display()); operation solve(n : OclAny) : OclAny pre: true post: true activity: var t : double := 1000 - n ; var cnt : int := 0 ; for i : Integer.subrange(0, (c)->size()-1) do ( while t div c[i+1] > 0 do ( t := t - c[i+1] ; cnt := cnt + 1)) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p,k=map(int,input().split()) M=1000000007 if k==0 : print(pow(p,p-1,M)),exit(0) if k==1 : print(pow(p,p,M)),exit(0) cnt,x=0,1 while 1 : cnt-=-1 x=(k*x)% p if x==1 : break print(pow(p,(p-1)//cnt,M)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : OclAny := null; var k : OclAny := null; Sequence{p,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var M : int := 1000000007 ; if k = 0 then ( ((p)->pow(p - 1))->display() ; exit(0) ) else skip ; if k = 1 then ( ((p)->pow(p))->display() ; exit(0) ) else skip ; var cnt : OclAny := null; var x : OclAny := null; Sequence{cnt,x} := Sequence{0,1} ; while 1 do ( cnt := cnt - -1 ; var x : int := (k * x) mod p ; if x = 1 then ( break ) else skip) ; execute ((p)->pow((p - 1) div cnt))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque import sys import bisect input=sys.stdin.readline mod=1000000007 def bfs(root,k,p): queue=deque() queue.append(root) while queue : child=queue.popleft() if(k*child)% p not in vis : vis.add((k*child)% p) queue.append((k*child)% p) p,k=map(int,input().split()) vis=set() count=0 for i in range(1,p): if i not in vis : bfs(i,k,p) count+=1 if k==1 : count+=1 print(pow(p,count,mod)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var mod : int := 1000000007 ; skip ; Sequence{p,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var vis : Set := Set{}->union(()) ; var count : int := 0 ; for i : Integer.subrange(1, p-1) do ( if (vis)->excludes(i) then ( bfs(i, k, p) ; count := count + 1 ) else skip) ; if k = 1 then ( count := count + 1 ) else skip ; execute ((p)->pow(count))->display(); operation bfs(root : OclAny, k : OclAny, p : OclAny) pre: true post: true activity: var queue : Sequence := () ; execute ((root) : queue) ; while queue do ( var child : OclAny := queue->first() ; queue := queue->tail() ; if (vis)->excludes((k * child) mod p) then ( execute (((k * child) mod p) : vis) ; execute (((k * child) mod p) : queue) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) l={i+1 :[]for i in range(n)} for _ in range(n-1): a,b=map(int,input().split()) l[a].append(b) l[b].append(a) d={i+1 :-1 for i in range(n)} d[1]=0 q=[1] while q : q1=[] for a in q : for b in l[a]: if d[b]==-1 : d[b]=d[a]+1 q1.append(b) q=q1 ind={i+1 : 0 for i in range(n)} ind[1]=len(l[1]) for i in range(2,n+1): ind[i]=len(l[i])-1 size={i+1 : 0 for i in range(n)} q=[] for i in range(1,n+1): if ind[i]==0 : q.append(i) ind[i]=-1 while q : q1=[] for a in q : for b in l[a]: if d[a]==d[b]+1 : size[b]+=size[a]+1 ind[b]-=1 if ind[b]==0 : q1.append(b) q=q1 x=[] for i in range(1,n+1): x.append(d[i]-size[i]) x=sorted(x) print(sum(x[n-k :])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Map := Integer.subrange(0, n-1)->select(i | true)->collect(i | Map{i + 1 |-> Sequence{}})->unionAll() ; for _anon : Integer.subrange(0, n - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var d : Map := Integer.subrange(0, n-1)->select(i | true)->collect(i | Map{i + 1 |-> -1})->unionAll() ; d[1+1] := 0 ; var q : Sequence := Sequence{ 1 } ; while q do ( var q1 : Sequence := Sequence{} ; for a : q do ( for b : l[a+1] do ( if d[b+1] = -1 then ( d[b+1] := d[a+1] + 1 ; execute ((b) : q1) ) else skip)) ; q := q1) ; var ind : Map := Integer.subrange(0, n-1)->select(i | true)->collect(i | Map{i + 1 |-> 0})->unionAll() ; ind[1+1] := (l[1+1])->size() ; for i : Integer.subrange(2, n + 1-1) do ( ind[i+1] := (l[i+1])->size() - 1) ; var size : Map := Integer.subrange(0, n-1)->select(i | true)->collect(i | Map{i + 1 |-> 0})->unionAll() ; q := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( if ind[i+1] = 0 then ( execute ((i) : q) ; ind[i+1] := -1 ) else skip) ; while q do ( q1 := Sequence{} ; for a : q do ( for b : l[a+1] do ( if d[a+1] = d[b+1] + 1 then ( size[b+1] := size[b+1] + size[a+1] + 1 ; ind[b+1] := ind[b+1] - 1 ; if ind[b+1] = 0 then ( execute ((b) : q1) ) else skip ) else skip)) ; q := q1) ; var x : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( execute ((d[i+1] - size[i+1]) : x)) ; x := x->sort() ; execute ((x.subrange(n - k+1))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict import sys import threading sys.setrecursionlimit(10**6) threading.stack_size(10**8) buffer=[] def dfs(graph,n,p,level): penalty=1 for c in graph[n]: if c==p : continue penalty+=dfs(graph,c,n,level+1) buffer.append(level-penalty) return penalty def main(): n,k=map(int,input().split()) graph=defaultdict(list) for i in range(n-1): a,b=map(int,input().split()) graph[a].append(b) graph[b].append(a) try : dfs(graph,1,None,1) except Exception as e : print(e) print(sum(sorted(buffer,reverse=True)[: k])) t=threading.Thread(target=main) t.start() t.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(6)) ; threading.stack_size((10)->pow(8)) ; var buffer : Sequence := Sequence{} ; skip ; skip ; var t : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ; t.start() ; t.join(); operation dfs(graph : OclAny, n : OclAny, p : OclAny, level : OclAny) : OclAny pre: true post: true activity: var penalty : int := 1 ; for c : graph[n+1] do ( if c = p then ( continue ) else skip ; penalty := penalty + dfs(graph, c, n, level + 1)) ; execute ((level - penalty) : buffer) ; return penalty; operation main() pre: true post: true activity: var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; graph := defaultdict(OclType["Sequence"]) ; for i : Integer.subrange(0, n - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; try ( dfs(graph, 1, null, 1)) catch (e : ProgramException) do ( execute (e)->display()) ; execute ((sorted(buffer, (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))).subrange(1,k))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict import sys import threading sys.setrecursionlimit(10**6) threading.stack_size(10**8) s=[] def dfs(graph,n,p,level): penalty=1 for c in graph[n]: if c==p : continue penalty+=dfs(graph,c,n,level+1) s.append(level-penalty) return penalty def main(): n,k=map(int,input().split()) g=[[]for i in range(n)] for i in range(n-1): u,v=map(int,input().split(' ')) g[u-1].append(v-1) g[v-1].append(u-1) try : dfs(g,0,None,1) except Exception as e : print(e) m=sorted(s,reverse=True) print(sum(m[: k])) t=threading.Thread(target=main) t.start() t.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(6)) ; threading.stack_size((10)->pow(8)) ; var s : Sequence := Sequence{} ; skip ; skip ; var t : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ; t.start() ; t.join(); operation dfs(graph : OclAny, n : OclAny, p : OclAny, level : OclAny) : OclAny pre: true post: true activity: var penalty : int := 1 ; for c : graph[n+1] do ( if c = p then ( continue ) else skip ; penalty := penalty + dfs(graph, c, n, level + 1)) ; execute ((level - penalty) : s) ; return penalty; operation main() pre: true post: true activity: var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var g : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, n - 1-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name u))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name u))) - (expr (atom (number (integer 1)))))))))) ))))) ; try ( dfs(g, 0, null, 1)) catch (e : ProgramException) do ( execute (e)->display()) ; var m : Sequence := s->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; execute ((m.subrange(1,k))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import threading from collections import defaultdict sys.setrecursionlimit(10**6) threading.stack_size(10**8) input=sys.stdin.readline def main(): n,k=map(int,input().split()) tree=defaultdict(list) for edge in range(n-1): u,v=map(int,input().split()) tree[u].append(v); tree[v].append(u) res=[] def dfs(cn,p,d): sz=1 for nn in tree[cn]: if nn!=p : sz+=dfs(nn,cn,d+1) res.append(d-sz) return sz dfs(1,-1,1) res.sort(reverse=True) ans=0 for i in range(k): ans+=res[i] print(ans) t=threading.Thread(target=main) t.start() t.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(6)) ; threading.stack_size((10)->pow(8)) ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var t : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ; t.start() ; t.join(); operation main() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var tree : OclAny := defaultdict(OclType["Sequence"]) ; for edge : Integer.subrange(0, n - 1-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name tree)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) ))));(expr (atom (name tree)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)))))))) ))))) ; var res : Sequence := Sequence{} ; skip ; dfs(1, -1, 1) ; res := res->sort() ; var ans : int := 0 ; for i : Integer.subrange(0, k-1) do ( ans := ans + res[i+1]) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from collections import Counter,deque from sys import stdout import time from math import factorial,log,gcd import sys from decimal import Decimal import threading from heapq import* def S(): return sys.stdin.readline().split() def I(): return[int(i)for i in sys.stdin.readline().split()] def II(): return int(sys.stdin.readline()) def IS(): return sys.stdin.readline().replace('\n','') def main(): n,k=I() tree=[[]for _ in range(n)] for _ in range(n-1): u,v=I() tree[u-1].append(v-1) tree[v-1].append(u-1) deap=[0]*n size=[0]*n visited=[False]*n visited[0]=True def dfs(x,d): s=1 deap[x]=d for r in tree[x]: if not visited[r]: visited[r]=True s+=dfs(r,d+1) size[x]=s-1 return s dfs(0,0) ans=list(sorted([size[i]-deap[i]for i in range(n)])) print(sum(ans[: :-1][: n-k])) threading.stack_size(10**8+5) sys.setrecursionlimit(2*10**5+10) threading.Thread(target=main).start() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; threading.stack_size((10)->pow(8) + 5) ; sys.setrecursionlimit(2 * (10)->pow(5) + 10) ; (expr (atom (name threading)) (trailer . (name Thread) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ))) (trailer . (name start) (arguments ( )))); operation S() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation IS() : OclAny pre: true post: true activity: return sys.stdin.readLine().replace(' ', ''); operation main() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := I() ; var tree : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, n - 1-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := I() ; (expr (atom (name tree)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name u))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name tree)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name u))) - (expr (atom (number (integer 1)))))))))) ))))) ; var deap : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var size : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ; visited->first() := true ; skip ; dfs(0, 0) ; var ans : Sequence := (Integer.subrange(0, n-1)->select(i | true)->collect(i | (size[i+1] - deap[i+1]))->sort()) ; execute ((ans(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))).subrange(1,n - k))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def missing_elements(vec): mis=[] for i in range(len(vec)): temp=abs(vec[i])-1 if vec[temp]>0 : vec[temp]=-vec[temp] for i in range(len(vec)): if(vec[i]>0): mis.append(i+1) return mis vec=[3,3,3,5,1] miss_ele=missing_elements(vec) for i in range(len(miss_ele)): print(miss_ele[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; vec := Sequence{3}->union(Sequence{3}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 1 })))) ; var miss_ele : OclAny := missing_elements(vec) ; for i : Integer.subrange(0, (miss_ele)->size()-1) do ( execute (miss_ele[i+1])->display()); operation missing_elements(vec : OclAny) : OclAny pre: true post: true activity: var mis : Sequence := Sequence{} ; for i : Integer.subrange(0, (vec)->size()-1) do ( var temp : double := (vec[i+1])->abs() - 1 ; if vec[temp+1] > 0 then ( vec[temp+1] := -vec[temp+1] ) else skip) ; for i : Integer.subrange(0, (vec)->size()-1) do ( if (vec[i+1] > 0) then ( execute ((i + 1) : mis) ) else skip) ; return mis; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countElements(p,n): ans=0 ; for i in range(1,n-1): if(p[i-1]>p[i]and p[i]>p[i+1]): ans+=1 ; elif(p[i-1]union(Sequence{5}->union(Sequence{1}->union(Sequence{3}->union(Sequence{ 4 })))); ; n := (p)->size(); ; execute (countElements(p, n))->display(); ) else skip; operation countElements(p : OclAny, n : OclAny) pre: true post: true activity: var ans : int := 0; ; for i : Integer.subrange(1, n - 1-1) do ( if ((p[i - 1+1]->compareTo(p[i+1])) > 0 & (p[i+1]->compareTo(p[i + 1+1])) > 0) then ( ans := ans + 1; ) else (if ((p[i - 1+1]->compareTo(p[i+1])) < 0 & (p[i+1]->compareTo(p[i + 1+1])) < 0) then ( ans := ans + 1; ) else skip)) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,a,b=map(int,input().split()) ans=0 for i in range(a,b+1): if h % i==0 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{h,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; for i : Integer.subrange(a, b + 1-1) do ( if h mod i = 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,A,B=[int(i)for i in input().split()] cnt=0 for i in range(A,B+1): if(H//i)*i==H : cnt=cnt+1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{H,A,B} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var cnt : int := 0 ; for i : Integer.subrange(A, B + 1-1) do ( if (H div i) * i = H then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break ans=0 while(n<=500): n+=500 ans+=1 while(n<=900): n+=100 ans+=1 while(n<=950): n+=50 ans+=1 while(n<=990): n+=10 ans+=1 while(n<=995): n+=5 ans+=1 while(n<=999): n+=1 ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var ans : int := 0 ; while (n <= 500) do ( n := n + 500 ; ans := ans + 1) ; while (n <= 900) do ( n := n + 100 ; ans := ans + 1) ; while (n <= 950) do ( n := n + 50 ; ans := ans + 1) ; while (n <= 990) do ( n := n + 10 ; ans := ans + 1) ; while (n <= 995) do ( n := n + 5 ; ans := ans + 1) ; while (n <= 999) do ( n := n + 1 ; ans := ans + 1) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,a,b=map(int,input().split()) print([(h %(a+c)==0)for c in range(b-a+1)].count(True)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{h,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Integer.subrange(0, b - a + 1-1)->select(c | true)->collect(c | ((h mod (a + c) = 0)))->count(true))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,A,B=map(int,input().split()) i=0 while A<=B : if H % A==0 : i=i+1 A=A+1 print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{H,A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var i : int := 0 ; while (A->compareTo(B)) <= 0 do ( if H mod A = 0 then ( i := i + 1 ) else skip ; var A : OclAny := A + 1) ; execute (i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,A,B=map(int,input().split()) a=list(range(A,B+1)) x=0 for i in a : if H % i==0 : x+=1 print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{H,A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := (Integer.subrange(A, B + 1-1)) ; var x : int := 0 ; for i : a do ( if H mod i = 0 then ( x := x + 1 ) else skip) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : print(len(str(sum(map(int,input().split()))))) except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( execute ((("" + ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum()))))->size())->display()) catch (_e : OclException) do ( break) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def digit_check(n): digit=1 while int(n/(10**digit))!=0 : digit+=1 return digit def main(): for line in sys.stdin : ls=list(map(int,line.split(' '))) print(digit_check(ls[0]+ls[1])) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation digit_check(n : OclAny) : OclAny pre: true post: true activity: var digit : int := 1 ; while ("" + ((n / ((10)->pow(digit)))))->toInteger() /= 0 do ( digit := digit + 1) ; return digit; operation main() pre: true post: true activity: for line : OclFile["System.in"] do ( var ls : Sequence := ((line.split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; execute (digit_check(ls->first() + ls[1+1]))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") for line in sys.stdin : a,b=[int(_)for _ in line.split()] print(len(str(a+b))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; for line : OclFile["System.in"] do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := line.split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; execute ((("" + ((a + b))))->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : try : a,b=map(int,input().split()) ans=1 while(a+b)/(10**ans)>=1 : ans+=1 print(str(ans)) except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( try ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 1 ; while (a + b) / ((10)->pow(ans)) >= 1 do ( ans := ans + 1) ; execute (("" + ((ans))))->display()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=input().split() print('=' if x==y else '>' if x>y else '<') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := input().split() ; execute (if x = y then '=' else if (x->compareTo(y)) > 0 then '>' else '<' endif endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys l=sys.stdin.readlines() for line in l : data=map(int,line.split(" ")) print(len(str(data[0]+data[1]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var l : OclAny := (OclFile["System.in"]).readlines() ; for line : l do ( var data : Sequence := (line.split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((("" + ((data->first() + data[1+1]))))->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r,g,b=map(int,input().split()) m=min(r,g,b) ans=(m+(r-m)//3+(g-m)//3+(b-m)//3) if m>0 : ans=max(ans,m-1+(r-m+1)//3+(g-m+1)//3+(b-m+1)//3) if m>1 : ans=max(ans,m-2+(r-m+2)//3+(g-m+2)//3+(b-m+2)//3) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : OclAny := null; var g : OclAny := null; var b : OclAny := null; Sequence{r,g,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : OclAny := Set{r, g, b}->min() ; var ans : OclAny := (m + (r - m) div 3 + (g - m) div 3 + (b - m) div 3) ; if m > 0 then ( ans := Set{ans, m - 1 + (r - m + 1) div 3 + (g - m + 1) div 3 + (b - m + 1) div 3}->max() ) else skip ; if m > 1 then ( ans := Set{ans, m - 2 + (r - m + 2) div 3 + (g - m + 2) div 3 + (b - m + 2) div 3}->max() ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def answer(a,b,c,mn): a-=mn b-=mn c-=mn ans=mn+a//3+b//3+c//3 return ans for _ in range(1): a=[int(i)for i in input().split()] a.sort() ans=a[0]//3+a[1]//3+a[2]//3 for mn in range(min(3,a[0])): ans=max(ans,answer(*a,mn)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, 1-1) do ( a := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; a := a->sort() ; ans := a->first() div 3 + a[1+1] div 3 + a[2+1] div 3 ; for mn : Integer.subrange(0, Set{3, a->first()}->min()-1) do ( ans := Set{ans, answer((argument * (test (logical_test (comparison (expr (atom (name a))))))), mn)}->max()) ; execute (ans)->display()); operation answer(a : OclAny, b : OclAny, c : OclAny, mn : OclAny) : OclAny pre: true post: true activity: a := a - mn ; b := b - mn ; c := c - mn ; var ans : OclAny := mn + a div 3 + b div 3 + c div 3 ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def keisan(a): p=1000-a otsurifh=p//500 otsurih=(p-otsurifh*500)//100 otsurifj=(p-otsurifh*500-otsurih*100)//50 otsurij=(p-otsurifh*500-otsurih*100-otsurifj*50)//10 otsurig=(p-otsurifh*500-otsurih*100-otsurifj*50-otsurij*10)//5 otsurii=(p-otsurifh*500-otsurih*100-otsurifj*50-otsurij*10-otsurig*5) return(otsurifh+otsurih+otsurifj+otsurij+otsurig+otsurii) for i in range(5): c=int(input()) if c==0 : break b=keisan(c) print(b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, 5-1) do ( var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if c = 0 then ( break ) else skip ; var b : OclAny := keisan(c) ; execute (b)->display()); operation keisan(a : OclAny) : OclAny pre: true post: true activity: var p : double := 1000 - a ; var otsurifh : int := p div 500 ; var otsurih : int := (p - otsurifh * 500) div 100 ; var otsurifj : int := (p - otsurifh * 500 - otsurih * 100) div 50 ; var otsurij : int := (p - otsurifh * 500 - otsurih * 100 - otsurifj * 50) div 10 ; var otsurig : int := (p - otsurifh * 500 - otsurih * 100 - otsurifj * 50 - otsurij * 10) div 5 ; var otsurii : double := (p - otsurifh * 500 - otsurih * 100 - otsurifj * 50 - otsurij * 10 - otsurig * 5) ; return (otsurifh + otsurih + otsurifj + otsurij + otsurig + otsurii); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter import math hpop=heappop hpush=heappush def solution(): arr=list(map(int,input().split())) h=arr.copy() res=0 for i in range(3): res+=arr[i]//3 arr[i]%=3 if sorted(arr)==[0,2,2]: res+=all([val>0 for val in h]) res+=min(arr) print(res) def main(): t=1 for _ in range(t): solution() import sys import threading sys.setrecursionlimit(1<<30) threading.stack_size(1<<27) thread=threading.Thread(target=main) thread.start(); thread.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1 * (2->pow(30))) ; threading.stack_size(1 * (2->pow(27))) ; var thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ; thread.start(); thread.join(); operation solution() pre: true post: true activity: var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var h : OclAny := arr->copy() ; var res : int := 0 ; for i : Integer.subrange(0, 3-1) do ( res := res + arr[i+1] div 3 ; arr[i+1] := arr[i+1] mod 3) ; if arr->sort() = Sequence{0}->union(Sequence{2}->union(Sequence{ 2 })) then ( res := res + (h->select(val | true)->collect(val | (val > 0)))->forAll( _x | _x = true ) ) else skip ; res := res + (arr)->min() ; execute (res)->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter import math hpop=heappop hpush=heappush def solution(): r,g,b=list(map(int,input().split())) i,j,k=0,0,0 i=sum([val//3 for val in[r,g,b]]) if r>0 and g>0 and b>0 : j=sum([val//3 for val in[r-1,g-1,b-1]])+1 if r>1 and g>1 and b>1 : k=sum([val//3 for val in[r-2,g-2,b-2]])+2 print(max(i,j,k)) def main(): t=1 for _ in range(t): solution() import sys import threading sys.setrecursionlimit(1<<30) threading.stack_size(1<<27) thread=threading.Thread(target=main) thread.start(); thread.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1 * (2->pow(30))) ; threading.stack_size(1 * (2->pow(27))) ; var thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ; thread.start(); thread.join(); operation solution() pre: true post: true activity: var r : OclAny := null; var g : OclAny := null; var b : OclAny := null; Sequence{r,g,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var i : OclAny := null; var j : OclAny := null; var k : OclAny := null; Sequence{i,j,k} := Sequence{0,0,0} ; var i : OclAny := (Sequence{r}->union(Sequence{g}->union(Sequence{ b }))->select(val | true)->collect(val | (val div 3)))->sum() ; if r > 0 & g > 0 & b > 0 then ( var j : OclAny := (Sequence{r - 1}->union(Sequence{g - 1}->union(Sequence{ b - 1 }))->select(val | true)->collect(val | (val div 3)))->sum() + 1 ) else skip ; if r > 1 & g > 1 & b > 1 then ( var k : OclAny := (Sequence{r - 2}->union(Sequence{g - 2}->union(Sequence{ b - 2 }))->select(val | true)->collect(val | (val div 3)))->sum() + 2 ) else skip ; execute (Set{i, j, k}->max())->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_VAL=1000000000 def printClosest(arr,n,x): res_l,res_r=0,0 l,r,diff=0,n-1,MAX_VAL while r>l : if abs(arr[l]+arr[r]-x)x : r-=1 else : l+=1 print('The closest pair is{}and{}'.format(arr[res_l],arr[res_r])) if __name__=="__main__" : arr=[10,22,28,29,30,40] n=len(arr) x=54 printClosest(arr,n,x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_VAL : int := 1000000000 ; skip ; if __name__ = "__main__" then ( arr := Sequence{10}->union(Sequence{22}->union(Sequence{28}->union(Sequence{29}->union(Sequence{30}->union(Sequence{ 40 }))))) ; n := (arr)->size() ; x := 54 ; printClosest(arr, n, x) ) else skip; operation printClosest(arr : OclAny, n : OclAny, x : OclAny) pre: true post: true activity: var res_l : OclAny := null; var res_r : OclAny := null; Sequence{res_l,res_r} := Sequence{0,0} ; var l : OclAny := null; var r : OclAny := null; var diff : OclAny := null; Sequence{l,r,diff} := Sequence{0,n - 1,MAX_VAL} ; while (r->compareTo(l)) > 0 do ( if ((arr[l+1] + arr[r+1] - x)->abs()->compareTo(diff)) < 0 then ( var res_l : OclAny := l ; var res_r : OclAny := r ; var diff : double := (arr[l+1] + arr[r+1] - x)->abs() ) else skip ; if (arr[l+1] + arr[r+1]->compareTo(x)) > 0 then ( r := r - 1 ) else ( l := l + 1 )) ; execute (StringLib.interpolateStrings('The closest pair is{}and{}', Sequence{arr[res_l+1], arr[res_r+1]}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=10 y=5 x=x+y y=x-y x=x-y print("After Swapping: x=",x," y=",y); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 10 ; var y : int := 5 ; x := x + y ; y := x - y ; x := x - y ; execute ("After Swapping: x=")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p,n=map(int,input().split()) listy=[] for i in range(n): listy.append(int(input())) def solve(listy,p): dicty={} for i in range(n): mod=listy[i]% p if mod in dicty.values(): return i+1 else : dicty.update({i : mod}) return-1 print(solve(listy,p)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : OclAny := null; var n : OclAny := null; Sequence{p,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var listy : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : listy)) ; skip ; execute (solve(listy, p))->display(); operation solve(listy : OclAny, p : OclAny) : OclAny pre: true post: true activity: var dicty : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var mod : int := listy[i+1] mod p ; if (dicty.values())->includes(mod) then ( return i + 1 ) else ( execute ((Map{ i |-> mod }) <: dicty) )) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p,n=map(int,input().split()) d={} for i in range(n): x=int(input())% p if x in d : print(i+1) quit() d[x]=1 print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : OclAny := null; var n : OclAny := null; Sequence{p,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() mod p ; if (d)->includes(x) then ( execute (i + 1)->display() ; quit() ) else skip ; d[x+1] := 1) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input_lines=input().split(" ") X=int(input_lines[0],16) Y=int(input_lines[1],16) if XY : print(">") else : print("=") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var input_lines : OclAny := input().split(" ") ; var X : int := ("" + ((input_lines->first(), 16)))->toInteger() ; var Y : int := ("" + ((input_lines[1+1], 16)))->toInteger() ; if (X->compareTo(Y)) < 0 then ( execute ("<")->display() ) else (if (X->compareTo(Y)) > 0 then ( execute (">")->display() ) else ( execute ("=")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()); c=[] for _ in range(b): f=int(input())% a ; c+=[f] if c.count(f)>1 : print(_+1); exit() print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var c : Sequence := Sequence{} ; for _anon : Integer.subrange(0, b-1) do ( var f : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() mod a; c := c + Sequence{ f } ; if c->count(f) > 1 then ( execute (_anon + 1)->display(); exit() ) else skip) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=list(map(int,input().split())) p=n[0] n=n[1] temp=[] for i in range(n): y=int(input()) if y % p in temp : print(i+1) break else : temp.append(y % p) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var p : OclAny := n->first() ; n := n[1+1] ; var temp : Sequence := Sequence{} ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name y)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name y))) % (expr (atom (name p))))) in (comparison (expr (atom (name temp))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name temp)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name y))) % (expr (atom (name p))))))))) ))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p,n=map(int,input().split()) c=0 l=[] for i in range(n): a=int(input()) if a % p not in l : l.append(a % p) else : c=-1 break if c==-1 : print(len(l)+1) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : OclAny := null; var n : OclAny := null; Sequence{p,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : int := 0 ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (l)->excludes(a mod p) then ( execute ((a mod p) : l) ) else ( c := -1 ; break )) ; if c = -1 then ( execute ((l)->size() + 1)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bankNotes(A,B,S,N): numerator=S-(B*N) denominator=A-B if(numerator % denominator==0): return(numerator//denominator) return-1 A,B,S,N=1,2,7,5 print(bankNotes(A,B,S,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{A,B,S,N} := Sequence{1,2,7,5} ; execute (bankNotes(A, B, S, N))->display(); operation bankNotes(A : OclAny, B : OclAny, S : OclAny, N : OclAny) : OclAny pre: true post: true activity: var numerator : double := S - (B * N) ; var denominator : double := A - B ; if (numerator mod denominator = 0) then ( return (numerator div denominator) ) else skip ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calc(n): a=1000-n y=[500,100,50,10,5,1] ans=0 for i in y : ans+=a//i a %=i if a==0 : return ans def resolve(): while True : v=int(input()) if v==0 : return print(calc(v)) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; resolve(); operation calc(n : OclAny) : OclAny pre: true post: true activity: var a : double := 1000 - n ; var y : Sequence := Sequence{500}->union(Sequence{100}->union(Sequence{50}->union(Sequence{10}->union(Sequence{5}->union(Sequence{ 1 }))))) ; var ans : int := 0 ; for i : y do ( ans := ans + a div i ; a := a mod i ; if a = 0 then ( return ans ) else skip); operation resolve() pre: true post: true activity: while true do ( var v : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if v = 0 then ( return ) else skip ; execute (calc(v))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def TwentyoneMatchstick(arr,N): for i in range(N): print(5-arr[i],end=" ") arr=[3,4,2,2] N=len(arr) TwentyoneMatchstick(arr,N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{3}->union(Sequence{4}->union(Sequence{2}->union(Sequence{ 2 }))) ; N := (arr)->size() ; TwentyoneMatchstick(arr, N); operation TwentyoneMatchstick(arr : OclAny, N : OclAny) pre: true post: true activity: for i : Integer.subrange(0, N-1) do ( execute (5 - arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() n=len(s) ans=n for i in range(n-1): if s[i]!=s[i+1]: ans=min(ans,max(i+1,n-i-1)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var n : int := (s)->size() ; var ans : int := n ; for i : Integer.subrange(0, n - 1-1) do ( if s[i+1] /= s[i + 1+1] then ( ans := Set{ans, Set{i + 1, n - i - 1}->max()}->min() ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**15 mod=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): s=S() l=len(s) a=[c=='1' for c in s] r=l//2+l % 2 b=l//2-1 c=l//2+l % 2 for i in range(b+1): if a[b-i]!=a[b-i+1]or a[c+i]!=a[c+i-1]: break r+=1 return r print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(15) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: s := S() ; var l : int := (s)->size() ; var a : Sequence := s->select(c | true)->collect(c | (c = '1')) ; var r : int := l div 2 + l mod 2 ; var b : double := l div 2 - 1 ; var c : int := l div 2 + l mod 2 ; for i : Integer.subrange(0, b + 1-1) do ( if a[b - i+1] /= a[b - i + 1+1] or a[c + i+1] /= a[c + i - 1+1] then ( break ) else skip ; r := r + 1) ; return r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=list(map(int,input())) N=len(S) def solve(c): cond=0 f=[0]*N if S[0]==1 : f[0]=1 cnt=1 for i in range(1,N-c+1): if i=c : f[i]=f[i-1]-f[i-c] if(S[i]+f[i])% 2==1 : f[i]+=1 cnt+=1 if cnt>=c : cond=1 break if cond==0 : for i in range(N-c+1,N): f[i]=f[i-1]-f[i-c] if(S[i]+f[i])% 2==0 : cnt+=1 else : break if cnt>=c : cond=1 break return cond def binary_search(s,f): if s==f : return s elif s+1==f : if solve(f): return f else : return s c=(s+f)//2 if solve(c): return binary_search(c,f) else : return binary_search(s,c) print(binary_search(1,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : Sequence := (((OclFile["System.in"]).readLine())->collect( _x | (OclType["int"])->apply(_x) )) ; var N : int := (S)->size() ; skip ; skip ; execute (binary_search(1, N))->display(); operation solve(c : OclAny) : OclAny pre: true post: true activity: var cond : int := 0 ; var f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; if S->first() = 1 then ( f->first() := 1 ) else skip ; var cnt : int := 1 ; for i : Integer.subrange(1, N - c + 1-1) do ( if (i->compareTo(c)) < 0 then ( f[i+1] := f[i - 1+1] ; if (S[i+1] + f[i+1]) mod 2 = 1 then ( f[i+1] := f[i+1] + 1 ) else skip ; cnt := cnt + 1 ) else skip ; if (i->compareTo(c)) >= 0 then ( f[i+1] := f[i - 1+1] - f[i - c+1] ; if (S[i+1] + f[i+1]) mod 2 = 1 then ( f[i+1] := f[i+1] + 1 ) else skip ; cnt := cnt + 1 ) else skip ; if (cnt->compareTo(c)) >= 0 then ( cond := 1 ; break ) else skip) ; if cond = 0 then ( for i : Integer.subrange(N - c + 1, N-1) do ( f[i+1] := f[i - 1+1] - f[i - c+1] ; if (S[i+1] + f[i+1]) mod 2 = 0 then ( cnt := cnt + 1 ) else ( break ) ; if (cnt->compareTo(c)) >= 0 then ( cond := 1 ; break ) else skip) ) else skip ; return cond; operation binary_search(s : OclAny, f : OclAny) : OclAny pre: true post: true activity: if s = f then ( return s ) else (if s + 1 = f then ( if solve(f) then ( return f ) else ( return s ) ) else skip) ; c := (s->union(f)) div 2 ; if solve(c) then ( return binary_search(c, f) ) else ( return binary_search(s, c) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() N=len(S) if len(set(S))==1 : print(N) exit() ans=N//2 l=r=N//2 if N % 2==0 : l-=1 inside=None while l>=0 : if not inside : if N % 2 : if S[l]==1 : print(N//2+1) exit() else : if S[l]!=S[r]: print(N//2) exit() inside=S[l] continue if S[l]!=inside or S[r]!=inside : break inside=S[l] l-=1 r+=1 ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var N : int := (S)->size() ; if (Set{}->union((S)))->size() = 1 then ( execute (N)->display() ; exit() ) else skip ; var ans : int := N div 2 ; var l : OclAny := N div 2; var r : int := N div 2 ; if N mod 2 = 0 then ( l := l - 1 ) else skip ; var inside : OclAny := null ; while l >= 0 do ( if not(inside) then ( if N mod 2 then ( if S[l+1] = 1 then ( execute (N div 2 + 1)->display() ; exit() ) else skip ) else ( if S[l+1] /= S[r+1] then ( execute (N div 2)->display() ; exit() ) else skip ) ; inside := S[l+1] ; continue ) else skip ; if S[l+1] /= inside or S[r+1] /= inside then ( break ) else skip ; inside := S[l+1] ; l := l - 1 ; r := r + 1 ; ans := ans + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math def main(x,y): if xy : return '>' else : return '=' if __name__=="__main__" : X,Y=map(str,input().split()) print(main(X,Y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( var X : OclAny := null; var Y : OclAny := null; Sequence{X,Y} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; execute (main(X, Y))->display() ) else skip; operation main(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (x->compareTo(y)) < 0 then ( return '<' ) else (if (x->compareTo(y)) > 0 then ( return '>' ) else ( return '=' ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import takewhile S=input() N=len(S) M=N//2 ans=M+len(list(takewhile(lambda i : S[M]==S[M-i-1]==S[M+i]if N % 2==0 else S[M]==S[M-i]==S[M+i],range(N-M)))) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var S : String := (OclFile["System.in"]).readLine() ; var N : int := (S)->size() ; var M : int := N div 2 ; var ans : int := M + ((takewhile(lambda i : OclAny in (if N mod 2 = 0 then S[M+1] = S[M - i - 1+1] & (S[M - i - 1+1] == S[M + i+1]) else S[M+1] = S[M - i+1] & (S[M - i+1] == S[M + i+1]) endif), Integer.subrange(0, N - M-1))))->size() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxLength(a,n): maximum=1 ; left=[0]*n ; right=[0]*n ; for i in range(n): left[i]=1 ; right[i]=1 ; for i in range(n-2,-1,-1): if(a[i]>a[i+1]): right[i]=right[i+1]+1 ; maximum=max(maximum,right[i]); for i in range(1,n): if(a[i]2): for i in range(1,n-1): if(a[i-1]>a[i+1]): maximum=max(maximum,left[i-1]+right[i+1]); return maximum ; if __name__=="__main__" : arr=[8,7,3,5,2,9]; n=len(arr); print(maxLength(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var arr : Sequence := Sequence{8}->union(Sequence{7}->union(Sequence{3}->union(Sequence{5}->union(Sequence{2}->union(Sequence{ 9 }))))); ; n := (arr)->size(); ; execute (maxLength(arr, n))->display(); ) else skip; operation maxLength(a : OclAny, n : OclAny) pre: true post: true activity: var maximum : int := 1; ; var left : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; var right : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; for i : Integer.subrange(0, n-1) do ( left[i+1] := 1; ; right[i+1] := 1;) ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( if ((a[i+1]->compareTo(a[i + 1+1])) > 0) then ( right[i+1] := right[i + 1+1] + 1; ) else skip ; maximum := Set{maximum, right[i+1]}->max();) ; for i : Integer.subrange(1, n-1) do ( if ((a[i+1]->compareTo(a[i - 1+1])) < 0) then ( left[i+1] := left[i - 1+1] + 1; ) else skip) ; if (n > 2) then ( for i : Integer.subrange(1, n - 1-1) do ( if ((a[i - 1+1]->compareTo(a[i + 1+1])) > 0) then ( maximum := Set{maximum, left[i - 1+1] + right[i + 1+1]}->max(); ) else skip) ) else skip ; return maximum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CountSegments(N,a): frequency=[0]*10001 c=0 for i in range(N): frequency[a[i]]+=1 for i in range(10001): c=max(c,frequency[i]) print(c) if __name__=="__main__" : N=6 a=[1,3,4,3,2,3] CountSegments(N,a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := 6 ; a := Sequence{1}->union(Sequence{3}->union(Sequence{4}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 3 }))))) ; CountSegments(N, a) ) else skip; operation CountSegments(N : OclAny, a : OclAny) pre: true post: true activity: var frequency : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10001) ; var c : int := 0 ; for i : Integer.subrange(0, N-1) do ( frequency[a[i+1]+1] := frequency[a[i+1]+1] + 1) ; for i : Integer.subrange(0, 10001-1) do ( c := Set{c, frequency[i+1]}->max()) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) for i in range(1,n+1): if n % i==0 : for j in range(n): if j>=i and a[j]!=a[j-i]: break else : print(n//i); exit() print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(1, n + 1-1) do ( if n mod i = 0 then ( (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name j)))) >= (comparison (expr (atom (name i)))))) and (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) != (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name j))) - (expr (atom (name i))))))))) ])))))))) : (suite (simple_stmt (small_stmt break)))))) (else_clause else : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) // (expr (atom (name i))))))))) )))))))))) ; (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name exit)) (trailer (arguments ( )))))))))))))) ) else skip) ; execute (1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) Ss=input().split() res=1 for t in range(1,N+1): if(N % t!=0): continue f=False for i in range(N-t): if(Ss[i]==Ss[i+t]): continue f=True break if(f): continue res=N//t break print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var Ss : OclAny := input().split() ; var res : int := 1 ; for t : Integer.subrange(1, N + 1-1) do ( if (N mod t /= 0) then ( continue ) else skip ; var f : boolean := false ; for i : Integer.subrange(0, N - t-1) do ( if (Ss[i+1] = Ss[i + t+1]) then ( continue ) else skip ; f := true ; break) ; if (f) then ( continue ) else skip ; res := N div t ; break) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- keymap=[[".",",","!","?",""],["a","b","c"],["d","e","f"],["g","h","i"],["j","k","l"],["m","n","o"],["p","q","r","s"],["t","u","v"],["w","x","y","z"]] n=int(input()) for i in range(n): keys=str(input()) message="" currentChar="" currentKey="X" push_counter=0 for key in keys : if key=="0" : message+=currentChar currentChar="" currentKey="0" continue if currentKey==key : push_counter+=1 else : push_counter=0 currentKey=key key_int=int(currentKey)-1 count=push_counter % len(keymap[key_int]) currentChar=keymap[key_int][count] print(message) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var keymap : Sequence := Sequence{Sequence{"."}->union(Sequence{","}->union(Sequence{"!"}->union(Sequence{"?"}->union(Sequence{ "" }))))}->union(Sequence{Sequence{"a"}->union(Sequence{"b"}->union(Sequence{ "c" }))}->union(Sequence{Sequence{"d"}->union(Sequence{"e"}->union(Sequence{ "f" }))}->union(Sequence{Sequence{"g"}->union(Sequence{"h"}->union(Sequence{ "i" }))}->union(Sequence{Sequence{"j"}->union(Sequence{"k"}->union(Sequence{ "l" }))}->union(Sequence{Sequence{"m"}->union(Sequence{"n"}->union(Sequence{ "o" }))}->union(Sequence{Sequence{"p"}->union(Sequence{"q"}->union(Sequence{"r"}->union(Sequence{ "s" })))}->union(Sequence{Sequence{"t"}->union(Sequence{"u"}->union(Sequence{ "v" }))}->union(Sequence{ Sequence{"w"}->union(Sequence{"x"}->union(Sequence{"y"}->union(Sequence{ "z" }))) })))))))) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var keys : String := ("" + (((OclFile["System.in"]).readLine()))) ; var message : String := "" ; var currentChar : String := "" ; var currentKey : String := "X" ; var push_counter : int := 0 ; for key : keys->characters() do ( if key = "0" then ( message := message + currentChar ; currentChar := "" ; currentKey := "0" ; continue ) else skip ; if currentKey = key then ( push_counter := push_counter + 1 ) else ( push_counter := 0 ; currentKey := key ) ; var key_int : double := ("" + ((currentKey)))->toInteger() - 1 ; var count : int := push_counter mod (keymap[key_int+1])->size() ; currentChar := keymap[key_int+1][count+1]) ; execute (message)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=4 def printSolution(sol): for i in sol : for j in i : print(str(j)+"",end="") print("") def isSafe(maze,x,y): if x>=0 and x=0 and yunion(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))}->union(Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 1 })))}->union(Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 0 })))}->union(Sequence{ Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))) }))) ; solveMaze(maze) ) else skip; operation printSolution(sol : OclAny) pre: true post: true activity: for i : sol do ( for j : i do ( execute (("" + ((j))) + "")->display()) ; execute ("")->display()); operation isSafe(maze : OclAny, x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if x >= 0 & (x->compareTo(N)) < 0 & y >= 0 & (y->compareTo(N)) < 0 & maze[x+1][y+1] = 1 then ( return true ) else skip ; return false; operation solveMaze(maze : OclAny) : OclAny pre: true post: true activity: sol := Integer.subrange(0, 4-1)->select(i | true)->collect(i | (Integer.subrange(0, 4-1)->select(j | true)->collect(j | (0)))) ; if solveMazeUtil(maze, 0, 0, sol) = false then ( execute ("Solution doesn't exist")->display(); ; return false ) else skip ; printSolution(sol) ; return true; operation solveMazeUtil(maze : OclAny, x : OclAny, y : OclAny, sol : OclAny) : OclAny pre: true post: true activity: if x = N - 1 & y = N - 1 & maze[x+1][y+1] = 1 then ( sol[x+1][y+1] := 1 ; return true ) else skip ; if isSafe(maze, x, y) = true then ( sol[x+1][y+1] := 1 ; if solveMazeUtil(maze, x + 1, y, sol) = true then ( return true ) else skip ; if solveMazeUtil(maze, x, y + 1, sol) = true then ( return true ) else skip ; sol[x+1][y+1] := 0 ; return false ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkDigits(n): while(n>0): if((n % 10)% 2): return False ; n=int(n/10); return True ; def largestNumber(n): for i in range(n,-1,-1): if(checkDigits(i)): return i ; N=23 ; print(largestNumber(N)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := 23; ; execute (largestNumber(N))->display();; operation checkDigits(n : OclAny) pre: true post: true activity: while (n > 0) do ( if ((n mod 10) mod 2) then ( return false; ) else skip ; n := ("" + ((n / 10)))->toInteger();) ; return true;; operation largestNumber(n : OclAny) pre: true post: true activity: for i : Integer.subrange(-1 + 1, n)->reverse() do ( if (checkDigits(i)) then ( return i; ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) mojiretu=''.join(sorted([input()for i in range(a)])) print(mojiretu) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mojiretu : String := StringLib.sumStringsWithSeparator((Integer.subrange(0, a-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine()))->sort()), '') ; execute (mojiretu)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- Tmp=[] Tmp=input().rstrip().split('') nN=int(Tmp[0]) nL=int(Tmp[1]) sWord=[] for i in range(nN): S=input() sWord.append(S) sWord.sort() for i in range(nN): print('%s' %(sWord[i]),end='') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Tmp : Sequence := Sequence{} ; Tmp := input().rstrip().split('') ; var nN : int := ("" + ((Tmp->first())))->toInteger() ; var nL : int := ("" + ((Tmp[1+1])))->toInteger() ; var sWord : Sequence := Sequence{} ; for i : Integer.subrange(0, nN-1) do ( var S : String := (OclFile["System.in"]).readLine() ; execute ((S) : sWord)) ; sWord := sWord->sort() ; for i : Integer.subrange(0, nN-1) do ( execute (StringLib.format('%s',(sWord[i+1])))->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dic={'A' : 10,'B' : 11,'C' : 12,'D' : 13,'E' : 14,'F' : 15} x,y=input().split() if dic[x]>dic[y]: print('>') elif dic[x] 10 }->union(Map{ 'B' |-> 11 }->union(Map{ 'C' |-> 12 }->union(Map{ 'D' |-> 13 }->union(Map{ 'E' |-> 14 }->union(Map{ 'F' |-> 15 }))))) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := input().split() ; if (dic[x+1]->compareTo(dic[y+1])) > 0 then ( execute ('>')->display() ) else (if (dic[x+1]->compareTo(dic[y+1])) < 0 then ( execute ('<')->display() ) else ( execute ('=')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import heapq,math from itertools import zip_longest,permutations,combinations,combinations_with_replacement from itertools import accumulate,dropwhile,takewhile,groupby from functools import lru_cache from copy import deepcopy N,L=map(int,input().split()) S=[input()for _ in range(N)] S.sort() print("".join(S)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var N : OclAny := null; var L : OclAny := null; Sequence{N,L} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; S := S->sort() ; execute (StringLib.sumStringsWithSeparator((S), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,_=[int(x)for x in input().split()] S=sorted([input()for _ in range(N)]) print(''.join(S)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var _anon : OclAny := null; Sequence{N,_anon} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var S : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine()))->sort() ; execute (StringLib.sumStringsWithSeparator((S), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,l=map(int,input().split()) a=[] for i in range(n): a.append(input()) a.sort() b="" for i in a : b+=i print(b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; Sequence{n,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : a)) ; a := a->sort() ; var b : String := "" ; for i : a do ( b := b + i) ; execute (b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) A=[input()for i in range(N)] B=[input()for i in range(M)] dxy=[] for y in range(M): for x in range(M): dxy.append((x,y)) flag=0 for y in range(N): for x in range(N): if A[y][x]==B[0][0]and flag==0 : counter=0 for dx,dy in dxy : if flag==0 : nx=x+dx ny=y+dy if not(0<=nx<=N-1): break if not(0<=ny<=N-1): break if A[ny][nx]==B[dy][dx]: counter+=1 if counter==M**2 : flag=1 if flag==1 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var B : Sequence := Integer.subrange(0, M-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var dxy : Sequence := Sequence{} ; for y : Integer.subrange(0, M-1) do ( for x : Integer.subrange(0, M-1) do ( execute ((Sequence{x, y}) : dxy))) ; var flag : int := 0 ; for y : Integer.subrange(0, N-1) do ( for x : Integer.subrange(0, N-1) do ( if A[y+1][x+1] = B->first()->first() & flag = 0 then ( var counter : int := 0 ; for _tuple : dxy do (var _indx : int := 1; var dx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dy : OclAny := _tuple->at(_indx); if flag = 0 then ( var nx : OclAny := x + dx ; var ny : OclAny := y + dy ; if not((0 <= nx & (nx <= N - 1))) then ( break ) else skip ; if not((0 <= ny & (ny <= N - 1))) then ( break ) else skip ; if A[ny+1][nx+1] = B[dy+1][dx+1] then ( counter := counter + 1 ) else skip ) else skip) ; if counter = (M)->pow(2) then ( flag := 1 ) else skip ) else skip)) ; if flag = 1 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re n,m=[int(x)for x in input().split()] nm="" ss="" for _ in range(n): nm+=input() for i in range(m): ss+=".{{{}}}".format(n-m)if i>0 else "" ss+=input().replace(".","\.") print("Yes")if re.search(ss,nm)else print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var nm : String := "" ; var ss : String := "" ; for _anon : Integer.subrange(0, n-1) do ( nm := nm + (OclFile["System.in"]).readLine()) ; for i : Integer.subrange(0, m-1) do ( ss := ss + if i > 0 then StringLib.interpolateStrings(".{{{}}}", Sequence{n - m}) else "" endif ; ss := ss + input().replace(".", "\.")) ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Yes"))))))) )))))) if (logical_test (comparison (expr (atom (name re)) (trailer . (name search) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ss))))))) , (argument (test (logical_test (comparison (expr (atom (name nm)))))))) )))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "No"))))))) )))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) A=[[]for _ in range(N)] B=[[]for _ in range(M)] for i in range(N): A[i]=input() for j in range(M): B[j]=input() for k in range(N-M+1): for l in range(N-M+1): f=0 for p in range(M): for q in range(M): if not A[k+p][l+q]==B[p][q]: f=1 break if f==1 : break if f==0 : print('Yes') exit() print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var B : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, N-1) do ( A[i+1] := (OclFile["System.in"]).readLine()) ; for j : Integer.subrange(0, M-1) do ( B[j+1] := (OclFile["System.in"]).readLine()) ; for k : Integer.subrange(0, N - M + 1-1) do ( for l : Integer.subrange(0, N - M + 1-1) do ( var f : int := 0 ; for p : Integer.subrange(0, M-1) do ( for q : Integer.subrange(0, M-1) do ( if not(A[k + p+1][l + q+1] = B[p+1][q+1]) then ( f := 1 ; break ) else skip) ; if f = 1 then ( break ) else skip) ; if f = 0 then ( execute ('Yes')->display() ; exit() ) else skip)) ; execute ('No')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys N,M=map(int,input().split()) A=[] B=[] for i in range(N): A.append(input()) for j in range(M): B.append(input()) for b in range(N-M+1): for a in range(N-M+1): count=0 for i in range(M): if B[i]==A[i+b][a : a+M]: count+=1 if count==M : print('Yes') sys.exit() print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := Sequence{} ; var B : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute (((OclFile["System.in"]).readLine()) : A)) ; for j : Integer.subrange(0, M-1) do ( execute (((OclFile["System.in"]).readLine()) : B)) ; for b : Integer.subrange(0, N - M + 1-1) do ( for a : Integer.subrange(0, N - M + 1-1) do ( var count : int := 0 ; for i : Integer.subrange(0, M-1) do ( if B[i+1] = A[i + b+1].subrange(a+1, a + M) then ( count := count + 1 ) else skip) ; if count = M then ( execute ('Yes')->display() ; sys.exit() ) else skip)) ; execute ('No')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countFact(low,high): fact=1 x=1 while(factdisplay(); operation countFact(low : OclAny, high : OclAny) : OclAny pre: true post: true activity: var fact : int := 1 ; var x : int := 1 ; while ((fact->compareTo(low)) < 0) do ( fact := fact * x ; x := x + 1) ; var res : int := 0 ; while ((fact->compareTo(high)) <= 0) do ( res := res + 1 ; fact := fact * x ; x := x + 1) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np N,M=map(int,input().split()) A=np.array([list(input())for _ in range(N)]) B=np.array([list(input())for _ in range(M)]) bl=False for i in range(N-M+1): for j in range(N-M+1): if(A[i : i+M,j : j+M]==B).all(): bl=True answer='Yes' if bl else 'No' print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := (Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((OclFile["System.in"]).readLine())->characters()))) ; var B : Sequence := (Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (((OclFile["System.in"]).readLine())->characters()))) ; var bl : boolean := false ; for i : Integer.subrange(0, N - M + 1-1) do ( for j : Integer.subrange(0, N - M + 1-1) do ( if (A.subrange(i+1, i + M).subrange(j+1, j + M) = B).all() then ( bl := true ) else skip)) ; var answer : String := if bl then 'Yes' else 'No' endif ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getMinNumberForPattern(seq): n=len(seq) if(n>=9): return "-1" result=[None]*(n+1) count=1 for i in range(n+1): if(i==n or seq[i]=='I'): for j in range(i-1,-2,-1): result[j+1]=int('0'+str(count)) count+=1 if(j>=0 and seq[j]=='I'): break return result if __name__=='__main__' : inputs=["IDID","I","DD","II","DIDI","IIDDD","DDIDDIID"] for Input in inputs : print(*(getMinNumberForPattern(Input))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var inputs : Sequence := Sequence{"IDID"}->union(Sequence{"I"}->union(Sequence{"DD"}->union(Sequence{"II"}->union(Sequence{"DIDI"}->union(Sequence{"IIDDD"}->union(Sequence{ "DDIDDIID" })))))) ; for Input : inputs do ( execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name getMinNumberForPattern)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name Input)))))))) )))))))) ))))))))->display()) ) else skip; operation getMinNumberForPattern(seq : OclAny) : OclAny pre: true post: true activity: var n : int := (seq)->size() ; if (n >= 9) then ( return "-1" ) else skip ; var result : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (n + 1)) ; var count : int := 1 ; for i : Integer.subrange(0, n + 1-1) do ( if (i = n or seq[i+1] = 'I') then ( for j : Integer.subrange(-2 + 1, i - 1)->reverse() do ( result[j + 1+1] := ("" + (('0' + ("" + ((count))))))->toInteger() ; count := count + 1 ; if (j >= 0 & seq[j+1] = 'I') then ( break ) else skip) ) else skip) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline N=int(readline()) X=list(map(int,readline().split())) X.sort() ans=X[(N-1)//2] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var N : int := ("" + ((readline())))->toInteger() ; var X : Sequence := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ; X := X->sort() ; var ans : OclAny := X[(N - 1) div 2+1] ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): LIMIT=150000000 INCREMENTS=[1,3,7,9,13,27] NON_INCREMENTS=set(range(INCREMENTS[-1]))-set(INCREMENTS) maxnumber=LIMIT**2+INCREMENTS[-1] primes=eulerlib.list_primes(eulerlib.sqrt(maxnumber)) def has_consecutive_primes(n): n2=n**2 temp=[(n2+k)for k in INCREMENTS] if any((x!=p and x % p==0)for p in primes for x in temp): return False return all((not is_prime(n2+k))for k in NON_INCREMENTS) def is_prime(n): end=eulerlib.sqrt(n) for p in primes : if p>end : break if n % p==0 : return False return True ans=sum(n for n in range(0,LIMIT,10)if has_consecutive_primes(n)) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LIMIT : int := 150000000 ; var INCREMENTS : Sequence := Sequence{1}->union(Sequence{3}->union(Sequence{7}->union(Sequence{9}->union(Sequence{13}->union(Sequence{ 27 }))))) ; var NON_INCREMENTS : double := Set{}->union((Integer.subrange(0, INCREMENTS->last()-1))) - Set{}->union((INCREMENTS)) ; var maxnumber : double := (LIMIT)->pow(2) + INCREMENTS->last() ; var primes : OclAny := eulerlib.list_primes(eulerlib.sqrt(maxnumber)) ; skip ; skip ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name n)))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom (name LIMIT))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 10))))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (atom (name has_consecutive_primes)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))))->sum() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import string import collections import fractions import random from operator import itemgetter import itertools from collections import deque import copy import heapq import bisect MOD=10**9+7 INF=float('inf') input=lambda : sys.stdin.readline().strip() sys.setrecursionlimit(10**8) H,W=map(int,input().split()) A=[list(map(int,input().split()))for _ in range(H)] ans=INF for i in range(H): for j in range(W): temp_sum=0 for l in range(H): for k in range(W): temp_sum+=A[l][k]*min(abs(l-i),abs(k-j)) ans=min(temp_sum,ans) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var MOD : double := (10)->pow(9) + 7 ; var INF : double := ("" + (('inf')))->toReal() ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine()->trim()) ; sys.setrecursionlimit((10)->pow(8)) ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ans : OclAny := INF ; for i : Integer.subrange(0, H-1) do ( for j : Integer.subrange(0, W-1) do ( var temp_sum : int := 0 ; for l : Integer.subrange(0, H-1) do ( for k : Integer.subrange(0, W-1) do ( temp_sum := temp_sum + A[l+1][k+1] * Set{(l - i)->abs(), (k - j)->abs()}->min())) ; ans := Set{temp_sum, ans}->min())) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- hw=list(map(int,input().split())) h=hw[0] w=hw[1] city=[] distance=0 distance_all=[] for i in range(h): city.append(list(map(int,input().split()))) for i in range(h): for j in range(w): for x in range(h): for y in range(w): distance=distance+min(abs(x-i),abs(y-j))*city[x][y] distance_all.append(distance) distance=0 print(min(distance_all)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var hw : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var h : OclAny := hw->first() ; var w : OclAny := hw[1+1] ; var city : Sequence := Sequence{} ; var distance : int := 0 ; var distance_all : Sequence := Sequence{} ; for i : Integer.subrange(0, h-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : city)) ; for i : Integer.subrange(0, h-1) do ( for j : Integer.subrange(0, w-1) do ( for x : Integer.subrange(0, h-1) do ( for y : Integer.subrange(0, w-1) do ( distance := distance + Set{(x - i)->abs(), (y - j)->abs()}->min() * city[x+1][y+1])) ; execute ((distance) : distance_all) ; distance := 0)) ; execute ((distance_all)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections as co class Vec(co.namedtuple('Vec','x y')): def __add__(self,v): return Vec(self.x+v.x,self.y+v.y) field=dict() h,w=map(int,input().split()) for y in range(h): ma=map(int,input().split()) for x,population in enumerate(ma): field[Vec(x,y)]=population def distmapFor(v0): distmap=dict() for v in field.keys(): distmap[v]=min(abs(v0.x-v.x),abs(v0.y-v.y)) return distmap def totalFor(v): total=0 distmap=distmapFor(v) for v in field.keys(): total+=distmap[v]*field[v] return total mi=min(map(totalFor,list(field.keys()))) print(mi) ------------------------------------------------------------ OCL File: --------- class Vec extends co.namedtuple('Vec', 'x y') { static operation newVec() : Vec pre: true post: Vec->exists( _x | result = _x ); operation __add__(v : OclAny) : OclAny pre: true post: true activity: return Vec(self.x + v.x, self.y + v.y); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var field : Map := (arguments ( )) ; var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for y : Integer.subrange(0, h-1) do ( var ma : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for _tuple : Integer.subrange(1, (ma)->size())->collect( _indx | Sequence{_indx-1, (ma)->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var population : OclAny := _tuple->at(_indx); field[(Vec.newVec()).initialise(x, y)+1] := population)) ; skip ; skip ; var mi : OclAny := (((field.keys()))->collect( _x | (totalFor)->apply(_x) ))->min() ; execute (mi)->display(); operation distmapFor(v0 : OclAny) : OclAny pre: true post: true activity: var distmap : Map := (arguments ( )) ; for v : field.keys() do ( distmap[v+1] := Set{(v0.x - v.x)->abs(), (v0.y - v.y)->abs()}->min()) ; return distmap; operation totalFor(v : OclAny) : OclAny pre: true post: true activity: var total : int := 0 ; distmap := distmapFor(v) ; for v : field.keys() do ( total := total + distmap[v+1] * field[v+1]) ; return total; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math H,W=map(int,input().split()) y_list=[0]*H x_list=[0]*W val_list=[[0 for i in range(W)]for j in range(H)] for i in range(H): tmp_list=list(map(int,input().split())) y_list[i]=sum(tmp_list) for j in range(W): x_list[j]+=tmp_list[j] val_list[i][j]=tmp_list[j] min_val=math.inf for y_loc in range(H): for x_loc in range(W): wa=0 for i in range(H): y_weight=abs(i-y_loc) for j in range(W): x_weight=abs(j-x_loc) if y_weight>x_weight : wa+=x_weight*val_list[i][j] else : wa+=y_weight*val_list[i][j] min_val=min(min_val,wa) print(min_val) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var y_list : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, H) ; var x_list : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, W) ; var val_list : Sequence := Integer.subrange(0, H-1)->select(j | true)->collect(j | (Integer.subrange(0, W-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, H-1) do ( var tmp_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; y_list[i+1] := (tmp_list)->sum() ; for j : Integer.subrange(0, W-1) do ( x_list[j+1] := x_list[j+1] + tmp_list[j+1] ; val_list[i+1][j+1] := tmp_list[j+1])) ; var min_val : OclAny := ; for y_loc : Integer.subrange(0, H-1) do ( for x_loc : Integer.subrange(0, W-1) do ( var wa : int := 0 ; for i : Integer.subrange(0, H-1) do ( var y_weight : double := (i - y_loc)->abs() ; for j : Integer.subrange(0, W-1) do ( var x_weight : double := (j - x_loc)->abs() ; if (y_weight->compareTo(x_weight)) > 0 then ( wa := wa + x_weight * val_list[i+1][j+1] ) else ( wa := wa + y_weight * val_list[i+1][j+1] ))) ; min_val := Set{min_val, wa}->min())) ; execute (min_val)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ew_number,sn_number=list(map(int,input().split())) people_num=[] for i in range(ew_number): people_num.append(list(map(int,input().split()))) answer=100**10 for i in range(ew_number): for j in range(sn_number): dist=0 for k in range(ew_number): for l in range(sn_number): dist+=min(abs(k-i),abs(l-j))*people_num[k][l] answer=min(answer,dist) print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ew_number : OclAny := null; var sn_number : OclAny := null; Sequence{ew_number,sn_number} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var people_num : Sequence := Sequence{} ; for i : Integer.subrange(0, ew_number-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : people_num)) ; var answer : double := (100)->pow(10) ; for i : Integer.subrange(0, ew_number-1) do ( for j : Integer.subrange(0, sn_number-1) do ( var dist : int := 0 ; for k : Integer.subrange(0, ew_number-1) do ( for l : Integer.subrange(0, sn_number-1) do ( dist := dist + Set{(k - i)->abs(), (l - j)->abs()}->min() * people_num[k+1][l+1])) ; answer := Set{answer, dist}->min())) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): ans="" for n in range(2,10): for i in range(1,10**(9//n)): s="".join(str(i*j)for j in range(1,n+1)) if "".join(sorted(s))=="123456789" : ans=max(s,ans) return ans if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : String := "" ; for n : Integer.subrange(2, 10-1) do ( for i : Integer.subrange(1, (10)->pow((9 div n))-1) do ( var s : String := StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom (name j))))))))) ))))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) ))))))))), "") ; if StringLib.sumStringsWithSeparator((s->sort()), "") = "123456789" then ( ans := Set{s, ans}->max() ) else skip)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=lambda : map(int,input().split()) n,k=I() a=*I(), x=min(a) print([sum((y-x)//k for y in a),-1][any(y % k!=x % k for y in a)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := I->apply() ; var a : OclAny := (testlist_star_expr (star_expr * (expr (atom (name I)) (trailer (arguments ( ))))) ,) ; var x : OclAny := (a)->min() ; execute (Sequence{((argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (name x)))))))) ))) // (expr (atom (name k))))))) (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name a))))))))->sum()}->union(Sequence{ -1 })->select(((argument (test (logical_test (comparison (comparison (expr (expr (atom (name y))) % (expr (atom (name k))))) != (comparison (expr (expr (atom (name x))) % (expr (atom (name k)))))))) (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name a))))))))->exists( _x | _x = true )))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findOccurrences(str1,substr): n=len(str1) preLeft=[0 for i in range(n)] preRight=[0 for i in range(n)] if(str1[0]==substr[0]): preLeft[0]+=1 for i in range(1,n): if(str1[i]==substr[0]): preLeft[i]=preLeft[i-1]+1 else : preLeft[i]=preLeft[i-1] if(str1[n-1]==substr[2]): preRight[n-1]+=1 i=n-2 while(i>=0): if(str1[i]==substr[2]): preRight[i]=preRight[i+1]+1 else : preRight[i]=preRight[i+1] i-=1 counter=0 for i in range(1,n-1): if(str1[i]==str1[1]): total=preLeft[i-1]*preRight[i+1] counter+=total return counter if __name__=='__main__' : str1="GFGFGYSYIOIWIN" substr="GFG" print(findOccurrences(str1,substr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( str1 := "GFGFGYSYIOIWIN" ; substr := "GFG" ; execute (findOccurrences(str1, substr))->display() ) else skip; operation findOccurrences(str1 : OclAny, substr : OclAny) : OclAny pre: true post: true activity: var n : int := (str1)->size() ; var preLeft : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var preRight : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; if (str1->first() = substr->first()) then ( preLeft->first() := preLeft->first() + 1 ) else skip ; for i : Integer.subrange(1, n-1) do ( if (str1[i+1] = substr->first()) then ( preLeft[i+1] := preLeft[i - 1+1] + 1 ) else ( preLeft[i+1] := preLeft[i - 1+1] )) ; if (str1[n - 1+1] = substr[2+1]) then ( preRight[n - 1+1] := preRight[n - 1+1] + 1 ) else skip ; var i : double := n - 2 ; while (i >= 0) do ( if (str1[i+1] = substr[2+1]) then ( preRight[i+1] := preRight[i + 1+1] + 1 ) else ( preRight[i+1] := preRight[i + 1+1] ) ; i := i - 1) ; var counter : int := 0 ; for i : Integer.subrange(1, n - 1-1) do ( if (str1[i+1] = str1[1+1]) then ( var total : double := preLeft[i - 1+1] * preRight[i + 1+1] ; counter := counter + total ) else skip) ; return counter; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=list(map(int,input().split())) mn=min(a) ans=0 for i in range(n): q=a[i]-mn w=q//m if w*m+mn==a[i]: ans+=w else : ans=-1 break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mn : OclAny := (a)->min() ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var q : double := a[i+1] - mn ; var w : int := q div m ; if w * m + mn = a[i+1] then ( ans := ans + w ) else ( ans := -1 ; break )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=map(str,input().split()) if x') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; if (x->compareTo(y)) < 0 then ( execute ('<')->display() ) else (if x = y then ( execute ('=')->display() ) else ( execute ('>')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (number_of_share_prices,rubles_decreases_each_second)=map(int,input().split(' ')) initial_prices=list(map(int,input().split(' '))) seconds=0 lowest_price_share=min(initial_prices) for price in initial_prices : if price!=lowest_price_share : if(price-lowest_price_share)% rubles_decreases_each_second!=0 : seconds=-1 break else : seconds+=(price-lowest_price_share)//rubles_decreases_each_second print(seconds) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{number_of_share_prices, rubles_decreases_each_second} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var initial_prices : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var seconds : int := 0 ; var lowest_price_share : OclAny := (initial_prices)->min() ; for price : initial_prices do ( if price /= lowest_price_share then ( if (price - lowest_price_share) mod rubles_decreases_each_second /= 0 then ( seconds := -1 ; break ) else ( seconds := seconds + (price - lowest_price_share) div rubles_decreases_each_second ) ) else skip) ; execute (seconds)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=lambda : map(int,input().split()) n,k=I() a=*I(), x=min(a) print([sum((y-x)//k for y in a),-1][any(y % k!=x % k for y in a)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := I->apply() ; var a : OclAny := (testlist_star_expr (star_expr * (expr (atom (name I)) (trailer (arguments ( ))))) ,) ; var x : OclAny := (a)->min() ; execute (Sequence{((argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (name x)))))))) ))) // (expr (atom (name k))))))) (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name a))))))))->sum()}->union(Sequence{ -1 })->select(((argument (test (logical_test (comparison (comparison (expr (expr (atom (name y))) % (expr (atom (name k))))) != (comparison (expr (expr (atom (name x))) % (expr (atom (name k)))))))) (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name a))))))))->exists( _x | _x = true )))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=lambda : map(int,input().split()) n,k=I() a=*I(), x=min(a) print([sum((y-x)//k for y in a),-1][any(y % k!=x % k for y in a)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := I->apply() ; var a : OclAny := (testlist_star_expr (star_expr * (expr (atom (name I)) (trailer (arguments ( ))))) ,) ; var x : OclAny := (a)->min() ; execute (Sequence{((argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (name x)))))))) ))) // (expr (atom (name k))))))) (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name a))))))))->sum()}->union(Sequence{ -1 })->select(((argument (test (logical_test (comparison (comparison (expr (expr (atom (name y))) % (expr (atom (name k))))) != (comparison (expr (expr (atom (name x))) % (expr (atom (name k)))))))) (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name a))))))))->exists( _x | _x = true )))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fact(n): num=1 for i in range(1,n+1): num=num*i return num def Special_Factorial_Number(k): for i in range(1,k+1): if(fact(i)% k==0): return i return 0 if __name__=='__main__' : k=16 print(Special_Factorial_Number(k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( k := 16 ; execute (Special_Factorial_Number(k))->display() ) else skip; operation fact(n : OclAny) : OclAny pre: true post: true activity: var num : int := 1 ; for i : Integer.subrange(1, n + 1-1) do ( num := num * i) ; return num; operation Special_Factorial_Number(k : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(1, k + 1-1) do ( if (fact(i) mod k = 0) then ( return i ) else skip) ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def minDistance(A,B,E): AB=[None,None]; AB[0]=B[0]-A[0]; AB[1]=B[1]-A[1]; BE=[None,None]; BE[0]=E[0]-B[0]; BE[1]=E[1]-B[1]; AE=[None,None]; AE[0]=E[0]-A[0]; AE[1]=E[1]-A[1]; AB_BE=AB[0]*BE[0]+AB[1]*BE[1]; AB_AE=AB[0]*AE[0]+AB[1]*AE[1]; reqAns=0 ; if(AB_BE>0): y=E[1]-B[1]; x=E[0]-B[0]; reqAns=sqrt(x*x+y*y); elif(AB_AE<0): y=E[1]-A[1]; x=E[0]-A[0]; reqAns=sqrt(x*x+y*y); else : x1=AB[0]; y1=AB[1]; x2=AE[0]; y2=AE[1]; mod=sqrt(x1*x1+y1*y1); reqAns=abs(x1*y2-y1*x2)/mod ; return reqAns ; if __name__=="__main__" : A=[0,0]; B=[2,0]; E=[1,1]; print(minDistance(A,B,E)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( A := Sequence{0}->union(Sequence{ 0 }); ; B := Sequence{2}->union(Sequence{ 0 }); ; E := Sequence{1}->union(Sequence{ 1 }); ; execute (minDistance(A, B, E))->display(); ) else skip; operation minDistance(A : OclAny, B : OclAny, E : OclAny) pre: true post: true activity: var AB : Sequence := Sequence{null}->union(Sequence{ null }); ; AB->first() := B->first() - A->first(); ; AB[1+1] := B[1+1] - A[1+1]; ; var BE : Sequence := Sequence{null}->union(Sequence{ null }); ; BE->first() := E->first() - B->first(); ; BE[1+1] := E[1+1] - B[1+1]; ; var AE : Sequence := Sequence{null}->union(Sequence{ null }); ; AE->first() := E->first() - A->first(); ; AE[1+1] := E[1+1] - A[1+1]; ; var AB_BE : double := AB->first() * BE->first() + AB[1+1] * BE[1+1]; ; var AB_AE : double := AB->first() * AE->first() + AB[1+1] * AE[1+1]; ; var reqAns : int := 0; ; if (AB_BE > 0) then ( var y : double := E[1+1] - B[1+1]; ; var x : double := E->first() - B->first(); ; reqAns := sqrt(x * x + y * y); ) else (if (AB_AE < 0) then ( y := E[1+1] - A[1+1]; ; x := E->first() - A->first(); ; reqAns := sqrt(x * x + y * y); ) else ( var x1 : OclAny := AB->first(); ; var y1 : OclAny := AB[1+1]; ; var x2 : OclAny := AE->first(); ; var y2 : OclAny := AE[1+1]; ; var mod : OclAny := sqrt(x1 * x1 + y1 * y1); ; reqAns := (x1 * y2 - y1 * x2)->abs() / mod; ) ) ; return reqAns;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math lista=[] lista.append(2) def prime(a): counter=0 for i in range(1,math.ceil(math.sqrt(a)+1)): if a % i==0 : counter+=1 if counter<=1 : lista.append(a) n=int(input()) counter=0 for j in range(2,math.ceil(math.sqrt(n)+1)): prime(j) res=1 for i in range(len(lista)): if n % lista[i]==0 : d=lista[i] if n % 2==0 : res=n//d break else : res=((n-d)//2)+1 break print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var lista : Sequence := Sequence{} ; execute ((2) : lista) ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; counter := 0 ; for j : Integer.subrange(2, ((n)->sqrt() + 1)->ceil()-1) do ( prime(j)) ; var res : int := 1 ; for i : Integer.subrange(0, (lista)->size()-1) do ( if n mod lista[i+1] = 0 then ( var d : OclAny := lista[i+1] ; if n mod 2 = 0 then ( res := n div d ; break ) else ( res := ((n - d) div 2) + 1 ; break ) ) else skip) ; execute (res)->display(); operation prime(a : OclAny) pre: true post: true activity: var counter : int := 0 ; for i : Integer.subrange(1, ((a)->sqrt() + 1)->ceil()-1) do ( if a mod i = 0 then ( counter := counter + 1 ) else skip) ; if counter <= 1 then ( execute ((a) : lista) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) def findsmprime(x): if x<4 : return x for i in range(2,int(math.sqrt(x))+1): if x % i==0 : return i return x if n % 2==0 : print(n//2) else : x=findsmprime(n) print(1+(n-x)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; if n mod 2 = 0 then ( execute (n div 2)->display() ) else ( x := findsmprime(n) ; execute (1 + (n - x) div 2)->display() ); operation findsmprime(x : OclAny) : OclAny pre: true post: true activity: if x < 4 then ( return x ) else skip ; for i : Integer.subrange(2, ("" + (((x)->sqrt())))->toInteger() + 1-1) do ( if x mod i = 0 then ( return i ) else skip) ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- nn=int(input()) def sieve(n): p=2 while p*p<=n : if n % p==0 : return p p+=1 return n c=0 if nn % 2==1 : d=sieve(nn) nn=nn-d c+=1 c+=(nn//2) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var nn : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; var c : int := 0 ; if nn mod 2 = 1 then ( var d : OclAny := sieve(nn) ; nn := nn - d ; c := c + 1 ) else skip ; c := c + (nn div 2) ; execute (c)->display(); operation sieve(n : OclAny) : OclAny pre: true post: true activity: var p : int := 2 ; while (p * p->compareTo(n)) <= 0 do ( if n mod p = 0 then ( return p ) else skip ; p := p + 1) ; return n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def prime(n): for i in range(2,int(n**0.5)+1): if n % i==0 : return i else : return n n=int(input()) if n % 2==0 : print(n//2) else : n-=prime(n) print(n//2+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( execute (n div 2)->display() ) else ( n := n - prime(n) ; execute (n div 2 + 1)->display() ); operation prime(n : OclAny) pre: true post: true activity: (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) ** (expr (atom (number 0.5))))))))) )))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name n))) % (expr (atom (name i))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name i)))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name n))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B,C=map(str,input().split()) print((A[0]+B[0]+C[0]).upper()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{A,B,C} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; execute ((A->first() + B->first() + C->first())->toUpperCase())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findVolume(l,b,h): return((l*b*h)/2) l=18 b=12 h=9 print("Volume of triangular prism: ",findVolume(l,b,h)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; l := 18 ; b := 12 ; h := 9 ; execute ("Volume of triangular prism: ")->display(); operation findVolume(l : OclAny, b : OclAny, h : OclAny) : OclAny pre: true post: true activity: return ((l * b * h) / 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout def solve(): n=int(stdin.readline()) Max=100001 primes=[1]*Max primes[0]=primes[1]=0 i=2 while(i*itoInteger() ; var Max : int := 100001 ; var primes : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, Max) ; primes->first() := 0; var primes[1+1] : int := 0 ; var i : int := 2 ; while ((i * i->compareTo(Max)) < 0) do ( if (primes[i+1] = 1) then ( var j : int := i * i ; while ((j->compareTo(Max)) < 0) do ( primes[j+1] := 0 ; j := j + i) ) else skip ; i := i + 1) ; j := 2 ; var check : boolean := true ; while ((j * j->compareTo(n)) <= 0) do ( if (n mod j = 0) then ( check := false ) else skip ; j := j + 1) ; if check then ( return 1 ) else skip ; if n mod 2 = 0 then ( return n div 2 ) else skip ; for i : Integer.subrange(2, Max-1) do ( if (primes[i+1] = 1 & n mod i = 0) then ( return ((n - i) div 2) + 1 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def SumF(S,n): sum=0 for i in range(n): sum=sum+(S[i]*pow(2,n-i-1)) return sum def SumL(S,n): sum=0 for i in range(n): sum=sum+(S[i]*pow(2,i)) return sum def sumSetDiff(S,n): return SumL(S,n)-SumF(S,n) n=4 S=[5,2,9,6] print(sumSetDiff(S,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 4 ; S := Sequence{5}->union(Sequence{2}->union(Sequence{9}->union(Sequence{ 6 }))) ; execute (sumSetDiff(S, n))->display(); operation SumF(S : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + (S[i+1] * (2)->pow(n - i - 1))) ; return sum; operation SumL(S : OclAny, n : OclAny) : OclAny pre: true post: true activity: sum := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + (S[i+1] * (2)->pow(i))) ; return sum; operation sumSetDiff(S : OclAny, n : OclAny) : OclAny pre: true post: true activity: return SumL(S, n) - SumF(S, n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numberOfSolutions(n): c=0 for x in range(n+1): if(n==(x+(n ^ x))): c+=1 return c if __name__=="__main__" : n=3 print(numberOfSolutions(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 3 ; execute (numberOfSolutions(n))->display() ) else skip; operation numberOfSolutions(n : OclAny) : OclAny pre: true post: true activity: var c : int := 0 ; for x : Integer.subrange(0, n + 1-1) do ( if (n = (x + (MathLib.bitwiseXor(n, x)))) then ( c := c + 1 ) else skip) ; return c; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) a=0 i=1 while i**2<=n : a+=1 i+=1 b=0 i=1 while i**3<=n : b+=1 i+=1 c=0 i=1 while i**6<=n : c+=1 i+=1 print(a+b-c) t=int(input()) while t>0 : solve() t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( solve() ; t := t - 1); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := 0 ; var i : int := 1 ; while ((i)->pow(2)->compareTo(n)) <= 0 do ( a := a + 1 ; i := i + 1) ; var b : int := 0 ; i := 1 ; while ((i)->pow(3)->compareTo(n)) <= 0 do ( b := b + 1 ; i := i + 1) ; var c : int := 0 ; i := 1 ; while ((i)->pow(6)->compareTo(n)) <= 0 do ( c := c + 1 ; i := i + 1) ; execute (a + b - c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) num=set() for i in range(1,n+1): if(i*i<=n): num.add(i*i) else : break for i in range(1,n+1): if(i*i*i<=n): num.add(i*i*i) else : break print(len(num)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var num : Set := Set{}->union(()) ; for i : Integer.subrange(1, n + 1-1) do ( if ((i * i->compareTo(n)) <= 0) then ( execute ((i * i) : num) ) else ( break )) ; for i : Integer.subrange(1, n + 1-1) do ( if ((i * i * i->compareTo(n)) <= 0) then ( execute ((i * i * i) : num) ) else ( break )) ; execute ((num)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math t=int(input()) for abcd2 in range(t): a=int(input()) myset=set() i=1 while i*i<=a : myset.add(i*i) i+=1 i=1 while i*i*i<=a : myset.add(i*i*i) i+=1 print(len(myset)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for abcd2 : Integer.subrange(0, t-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var myset : Set := Set{}->union(()) ; var i : int := 1 ; while (i * i->compareTo(a)) <= 0 do ( execute ((i * i) : myset) ; i := i + 1) ; i := 1 ; while (i * i * i->compareTo(a)) <= 0 do ( execute ((i * i * i) : myset) ; i := i + 1) ; execute ((myset)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) sq_cb=[] for i in range(1,int((10**9)**(1/2))+1): sq_cb.append(i**2) for i in range(1,int((10**9)**(1/3))+2): if i**3 not in sq_cb : sq_cb.append(i**3) sq_cb.sort() for _ in range(t): n=int(input()) counter=0 for i in range(len(sq_cb)): if n==sq_cb[i]: print(i+1) break elif ntoInteger() ; var sq_cb : Sequence := Sequence{} ; for i : Integer.subrange(1, ("" + (((((10)->pow(9)))->pow((1 / 2)))))->toInteger() + 1-1) do ( execute (((i)->pow(2)) : sq_cb)) ; for i : Integer.subrange(1, ("" + (((((10)->pow(9)))->pow((1 / 3)))))->toInteger() + 2-1) do ( if (sq_cb)->excludes((i)->pow(3)) then ( execute (((i)->pow(3)) : sq_cb) ) else skip) ; sq_cb := sq_cb->sort() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var counter : int := 0 ; for i : Integer.subrange(0, (sq_cb)->size()-1) do ( if n = sq_cb[i+1] then ( execute (i + 1)->display() ; break ) else (if (n->compareTo(sq_cb[i+1])) < 0 then ( execute (i)->display() ; break ) else skip))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) a=0 i=1 while i**2<=n : a+=1 i+=1 b=0 i=1 while i**3<=n : b+=1 i+=1 c=0 i=1 while i**6<=n : c+=1 i+=1 print(a+b-c) t=int(input()) while t>0 : solve() t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( solve() ; t := t - 1); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := 0 ; var i : int := 1 ; while ((i)->pow(2)->compareTo(n)) <= 0 do ( a := a + 1 ; i := i + 1) ; var b : int := 0 ; i := 1 ; while ((i)->pow(3)->compareTo(n)) <= 0 do ( b := b + 1 ; i := i + 1) ; var c : int := 0 ; i := 1 ; while ((i)->pow(6)->compareTo(n)) <= 0 do ( c := c + 1 ; i := i + 1) ; execute (a + b - c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxLen(arr,n): min_val=min(arr); freq=0 ; for i in range(n): if(arr[i]==min_val): freq+=1 ; return freq ; if __name__=="__main__" : arr=[1,3,1]; n=len(arr); print(maxLen(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{3}->union(Sequence{ 1 })); ; n := (arr)->size(); ; execute (maxLen(arr, n))->display(); ) else skip; operation maxLen(arr : OclAny, n : OclAny) pre: true post: true activity: var min_val : OclAny := (arr)->min(); ; var freq : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] = min_val) then ( freq := freq + 1; ) else skip) ; return freq;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class node : def __init__(self,data): self.data=data self.next=next def push(head_ref,new_data): new_node=node(0) new_node.data=new_data new_node.next=(head_ref) (head_ref)=new_node return head_ref def kAltReverse(head,k): return _kAltReverse(head,k,True) def _kAltReverse(Node,k,b): if(Node==None): return None count=1 prev=None current=Node next=None while(current!=None and count<=k): next=current.next if(b==True): current.next=prev prev=current current=next count=count+1 if(b==True): Node.next=_kAltReverse(current,k,not b) return prev else : prev.next=_kAltReverse(current,k,not b) return Node def printList(node): count=0 while(node!=None): print(node.data,end=" ") node=node.next count=count+1 head=None i=20 while(i>0): head=push(head,i) i=i-1 print("Given linked list ") printList(head) head=kAltReverse(head,3) print("\nModified Linked list ") printList(head) ------------------------------------------------------------ OCL File: --------- class node { static operation newnode() : node pre: true post: node->exists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := next; operation initialise(data : OclAny) : node pre: true post: true activity: self.data := data ; self.next := next; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var (head_ref) : OclAny := new_node; operation push(head_ref : OclAny, new_data : OclAny) pre: true post: true activity: var new_node : node := (node.newnode()).initialise(0) ; new_node.data := new_data ; new_node.next := (head_ref); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n): s=0 while(n!=0): s+=n % 10 n//=10 return True if s==10 else False n=int(input()) i=19 while(n>0): if solve(i): n-=1 i+=9 print(i-9) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 19 ; while (n > 0) do ( if solve(i) then ( n := n - 1 ) else skip ; i := i + 9) ; execute (i - 9)->display(); operation solve(n : OclAny) : OclAny pre: true post: true activity: var s : int := 0 ; while (n /= 0) do ( s := s + n mod 10 ; n := n div 10) ; return if s = 10 then true else false endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) s=input() count=[0]*26 for c in s : count[ord(c)-ord("A")]+=1 count.sort(reverse=True) res=0 for i in range(26): if count[i]>=k : res+=k*k print(res) exit() k-=count[i] res+=count[i]**2 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for c : s->characters() do ( count[(c)->char2byte() - ("A")->char2byte()+1] := count[(c)->char2byte() - ("A")->char2byte()+1] + 1) ; count := count->sort() ; var res : int := 0 ; for i : Integer.subrange(0, 26-1) do ( if (count[i+1]->compareTo(k)) >= 0 then ( res := res + k * k ; execute (res)->display() ; exit() ) else skip ; k := k - count[i+1] ; res := res + (count[i+1])->pow(2)) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print("".join(s[0].upper()for s in input().split())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer . (name upper) (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math class Node : def __init__(self,data): self.data=data self.next=None def kAltReverse(head,k): current=head next=None prev=None count=0 while(current!=None and countexists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.next := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( head := null ; for i : Integer.subrange(0 + 1, 20)->reverse() do ( head := push(head, i)) ; execute ("Given linked list ")->display() ; prList(head) ; head := kAltReverse(head, 3) ; execute ("\nModified Linked list")->display() ; prList(head) ) else skip; operation kAltReverse(head : OclAny, k : OclAny) : OclAny pre: true post: true activity: var current : OclAny := head ; var next : OclAny := null ; var prev : OclAny := null ; var count : int := 0 ; while (current /= null & (count->compareTo(k)) < 0) do ( next := current.next ; current.next := prev ; prev := current ; current := next ; count := count + 1;) ; if (head /= null) then ( head.next := current ) else skip ; count := 0 ; while ((count->compareTo(k - 1)) < 0 & current /= null) do ( current := current.next ; count := count + 1) ; if (current /= null) then ( current.next := kAltReverse(current.next, k) ) else skip ; return prev; operation push(head_ref : OclAny, new_data : OclAny) : OclAny pre: true post: true activity: var new_node : Node := (Node.newNode()).initialise(new_data) ; new_node.next := head_ref ; head_ref := new_node ; return head_ref; operation prList(node : OclAny) pre: true post: true activity: count := 0 ; while (node /= null) do ( execute (node.data)->display() ; node := node.next ; count := count + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- y=int(input()) e2=list(map(int,input().split())) while(0 in e2): e2.remove(0) e2=set(e2) print(len(e2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var y : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var e2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; while ((e2)->includes(0)) do ( execute ((0) /: e2)) ; e2 := Set{}->union((e2)) ; execute ((e2)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- kl=int(input()) u=list(map(int,input().split())) while(0 in u): u.remove(0) u=set(u) print(len(u)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var kl : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var u : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; while ((u)->includes(0)) do ( execute ((0) /: u)) ; u := Set{}->union((u)) ; execute ((u)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) arr=list(map(int,input().split())) arr.sort() c=1 for i in range(a-1): if arr[i]!=arr[i+1]and arr[i]!=0 : c=c+1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := arr->sort() ; var c : int := 1 ; for i : Integer.subrange(0, a - 1-1) do ( if arr[i+1] /= arr[i + 1+1] & arr[i+1] /= 0 then ( c := c + 1 ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mvarrrrrr1=int(input()) mvarrrrrr2=list(map(int,input().split())) while(0 in mvarrrrrr2): mvarrrrrr2.remove(0) mvarrrrrr2=set(mvarrrrrr2) print(len(mvarrrrrr2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mvarrrrrr1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mvarrrrrr2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; while ((mvarrrrrr2)->includes(0)) do ( execute ((0) /: mvarrrrrr2)) ; mvarrrrrr2 := Set{}->union((mvarrrrrr2)) ; execute ((mvarrrrrr2)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- siri=int(input()) teja=list(map(int,input().split())) teja=[x for x in teja if(x!=0)] print(len(set(teja))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var siri : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var teja : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; teja := teja->select(x | (x /= 0))->collect(x | (x)) ; execute ((Set{}->union((teja)))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getMissingNo(a,n): x1=a[0] x2=1 for i in range(1,n): x1=x1 ^ a[i] for i in range(2,n+2): x2=x2 ^ i return x1 ^ x2 if __name__=='__main__' : a=[1,2,4,5,6] n=len(a) miss=getMissingNo(a,n) print(miss) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 })))) ; n := (a)->size() ; var miss : OclAny := getMissingNo(a, n) ; execute (miss)->display() ) else skip; operation getMissingNo(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var x1 : OclAny := a->first() ; var x2 : int := 1 ; for i : Integer.subrange(1, n-1) do ( x1 := MathLib.bitwiseXor(x1, a[i+1])) ; for i : Integer.subrange(2, n + 2-1) do ( x2 := MathLib.bitwiseXor(x2, i)) ; return MathLib.bitwiseXor(x1, x2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline inf=float('inf') def getInt(): return int(input()) def getStr(): return input().strip() def getList(split=True): s=getStr() if split : s=s.split() return map(int,s) t=getInt() def solve(): n=getInt() a=list(getList()) print(a==sorted(a)and "NO" or "YES") for _ in range(t): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; skip ; skip ; skip ; var t : OclAny := getInt() ; skip ; for _anon : Integer.subrange(0, t-1) do ( solve()); operation getInt() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation getStr() : OclAny pre: true post: true activity: return input()->trim(); operation getList(split : OclAny) : OclAny pre: true post: true activity: if split->oclIsUndefined() then split := true else skip; var s : OclAny := getStr() ; if split then ( s := s.split() ) else skip ; return (s)->collect( _x | (OclType["int"])->apply(_x) ); operation solve() pre: true post: true activity: var n : OclAny := getInt() ; var a : Sequence := (getList()) ; execute (a = a->sort() & "NO" or "YES")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) l=list(map(int,input().split()))[: n] l1=sorted(l) if l==l1 : print('NO') else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ; var l1 : Sequence := l->sort() ; if l = l1 then ( execute ('NO')->display() ) else ( execute ('YES')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter def solve(cards,k): ans,cur=0,0 for(_,cnt)in sorted(Counter(cards).items(),key=lambda x : x[1],reverse=True): can_take=k-cur if can_take>=cnt : ans+=cnt*cnt cur+=cnt else : ans+=can_take*can_take break return ans _,k=map(int,input().split()) print(solve(input(),k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var _anon : OclAny := null; Sequence{_anon,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (solve((OclFile["System.in"]).readLine(), k))->display(); operation solve(cards : OclAny, k : OclAny) : OclAny pre: true post: true activity: var ans : OclAny := null; var cur : OclAny := null; Sequence{ans,cur} := Sequence{0,0} ; for Sequence{_anon, cnt} : Counter(cards)->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sortedBy($x | (lambda x : OclAny in (x[1+1]))->apply($x)) do ( var can_take : double := k - cur ; if (can_take->compareTo(cnt)) >= 0 then ( ans := ans + cnt * cnt ; cur := cur + cnt ) else ( ans := ans + can_take * can_take ; break )) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def helper(arr): m=sorted(arr) for i in range(len(arr)): if arr[i]!=m[i]: return 'YES' return 'NO' for i in range(int(input())): n=int(input()) arr=list(map(int,input().split())) print(helper(arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; arr := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (helper(arr))->display()); operation helper(arr : OclAny) : OclAny pre: true post: true activity: var m : Sequence := arr->sort() ; for i : Integer.subrange(0, (arr)->size()-1) do ( if arr[i+1] /= m[i+1] then ( return 'YES' ) else skip) ; return 'NO'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(str,input().split()) listA=list(a) listB=list(b) listC=list(c) answer="" answer+=listA[0].upper()+listB[0].upper()+listC[0].upper() print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; var listA : Sequence := (a) ; var listB : Sequence := (b) ; var listC : Sequence := (c) ; var answer : String := "" ; answer := answer + listA->first()->toUpperCase() + listB->first()->toUpperCase() + listC->first()->toUpperCase() ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=list(map(int,input().split(' '))) if a==sorted(a): print('NO') else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; if a = a->sort() then ( execute ('NO')->display() ) else ( execute ('YES')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) num=list(map(int,input().split())) if(sorted(num)==num): print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var num : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (num->sort() = num) then ( execute ("NO")->display() ) else ( execute ("YES")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def toggleBitsFromLToR(n,l,r): num=((1<display(); operation toggleBitsFromLToR(n : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var num : int := MathLib.bitwiseXor(((1 * (2->pow(r))) - 1), ((1 * (2->pow((l - 1)))) - 1)) ; return (MathLib.bitwiseXor(n, num)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isValidSubString(r,K,p): c=0 for i in range(0,len(r)): if ord(r[i])>p : c+=1 if c==K : return True else : return False def countSubStrings(s,K,p): l=len(s) count=0 for i in range(0,l): for j in range(K,l-i+1): r=s[i : i+j] if isValidSubString(r,K,p)==True : count+=1 print(count) if __name__=="__main__" : s="abepztydba" K,p=4,110 countSubStrings(s,K,p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( s := "abepztydba" ; Sequence{K,p} := Sequence{4,110} ; countSubStrings(s, K, p) ) else skip; operation isValidSubString(r : OclAny, K : OclAny, p : OclAny) : OclAny pre: true post: true activity: var c : int := 0 ; for i : Integer.subrange(0, (r)->size()-1) do ( if ((r[i+1])->char2byte()->compareTo(p)) > 0 then ( c := c + 1 ) else skip) ; if c = K then ( return true ) else ( return false ); operation countSubStrings(s : OclAny, K : OclAny, p : OclAny) pre: true post: true activity: var l : int := (s)->size() ; var count : int := 0 ; for i : Integer.subrange(0, l-1) do ( for j : Integer.subrange(K, l - i + 1-1) do ( r := s.subrange(i+1, i + j) ; if isValidSubString(r, K, p) = true then ( count := count + 1 ) else skip)) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def printTwins(low,high): prime=[True]*(high+1); twin=False ; prime[0]=prime[1]=False ; for p in range(2,int(math.floor(math.sqrt(high))+2)): if(prime[p]): for i in range(p*2,high+1,p): prime[i]=False ; for i in range(low,high+1): if(prime[i]and prime[i+2]): print("Smallest twins in given range:(",i,",",(i+2),")"); twin=True ; break ; if(twin==False): print("No such pair exists"); printTwins(10,100); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; printTwins(10, 100);; operation printTwins(low : OclAny, high : OclAny) pre: true post: true activity: var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (high + 1)); ; var twin : boolean := false; ; prime->first() := false; var prime[1+1] : boolean := false; ; for p : Integer.subrange(2, ("" + ((((high)->sqrt())->floor() + 2)))->toInteger()-1) do ( if (prime[p+1]) then ( for i : Integer.subrange(p * 2, high + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false;) ) else skip) ; for i : Integer.subrange(low, high + 1-1) do ( if (prime[i+1] & prime[i + 2+1]) then ( execute ("Smallest twins in given range:(")->display(); ; twin := true; ; break; ) else skip) ; if (twin = false) then ( execute ("No such pair exists")->display(); ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lenOfLongIncSubArr(arr,n): m=1 l=1 for i in range(1,n): if(arr[i]>arr[i-1]): l=l+1 else : if(munion(Map{ 'l' |-> long }->union(Map{ 'f' |-> OclType["double"] }->union(Map{ 's' |-> OclType["String"] }))) ; var _buffer : Sequence := Sequence{} ; skip ; skip ; skip ; skip ; getcontext().prec := 40 ; var base : OclAny := Decimal('5.2360679774997896964091736687312762354406') ; skip ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name num_cases)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name num_cases)))))) ,)} := scanf('%d') ; for case_num : xrange(num_cases) do ( result := solve() ; printf('Case #%d: %s ', case_num + 1, result)); operation next_token() : OclAny pre: true post: true activity: if not(_buffer) then ( var line : String := (OclFile["System.in"]).readLine() ; _buffer := _buffer->union(line.split()) ) else skip ; return _buffer->at(0`firstArg+1); operation scanf(format : OclAny) : OclAny pre: true post: true activity: if (format)->size() mod 2 /= 0 then ( error IncorrectElementException.newIncorrectElementException ) else skip ; for i : xrange(0, (format)->size(), 2) do ( if ([i+1] + "") /= '%' then ( error IncorrectElementException.newIncorrectElementException ) else skip ; if ('dfs')->characters()->excludes(([i + 1+1] + "")) then ( error IncorrectElementException.newIncorrectElementException ) else skip) ; var result : Sequence := Sequence{} ; for i : xrange(1, (format)->size(), 2) do ( var token : OclAny := next_token() ; var value : OclAny := _TYPE[([i+1] + "")+1](token) ; execute ((value) : result)) ; return (result); operation printf(format : OclAny, args : OclAny : Sequence(OclAny)) : OclAny pre: true post: true activity: (args * (named_parameter (name args))) var message : int := format mod args ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name message)))))))) )))) ; return (message)->size(); operation solve() : OclAny pre: true post: true activity: (testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,)} := scanf('%d') ; var y : String := ("" + (((base)->pow(n)))) ; var point_pos : int := y->indexOf('.') - 1 ; return y.subrange(1,point_pos).subrange(-3+1).zfill(3); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math from decimal import Decimal,getcontext def main(): fin=file(sys.argv[1]) fout=file(sys.argv[2],"wt") getcontext().prec=50 K=Decimal(3)+Decimal(5).sqrt() numCases=int(fin.readline()) for case in xrange(numCases): exp=int(fin.readline()) answer=Decimal(1) for n in xrange(exp): answer*=K fout.write("Case #%d: %s\n" %(case+1,("000"+str(int(answer)))[-3 :])) if __name__=="__main__" : import doctest doctest.testmod() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( skip ; doctest.testmod() ; main() ) else skip; operation main() pre: true post: true activity: var fin : OclAny := file((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) ; var fout : OclAny := file((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])), "wt") ; getcontext().prec := 50 ; var K : OclAny := Decimal(3) + Decimal(5).sqrt() ; var numCases : int := ("" + ((fin.readLine())))->toInteger() ; for case : xrange(numCases) do ( var exp : int := ("" + ((fin.readLine())))->toInteger() ; var answer : OclAny := Decimal(1) ; for n : xrange(exp) do ( answer := answer * K) ; fout.write(StringLib.format("Case #%d: %s\n",Sequence{case + 1, ("000" + ("" + ((("" + ((answer)))->toInteger())))).subrange(-3+1)}))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) s=input() mp={} for i in s : if i in mp : mp[i]+=1 else : mp[i]=1 val=sorted(list(mp.values()),reverse=True) ans=0 for i in val : if i<=k : ans+=i*i k-=i elif k and i>k : ans+=k*k break else : break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var mp : OclAny := Set{} ; for i : s->characters() do ( if (mp)->includes(i) then ( mp[i+1] := mp[i+1] + 1 ) else ( mp[i+1] := 1 )) ; var val : Sequence := (mp.values())->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var ans : int := 0 ; for i : val do ( if (i->compareTo(k)) <= 0 then ( ans := ans + i * i ; k := k - i ) else (if k & (i->compareTo(k)) > 0 then ( ans := ans + k * k ; break ) else ( break ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): N=int(input()) c=[int(i)for i in input().split()] if N==1 : return c[0]*2 r=c[0]*2 x=[c[0]] for i in range(1,N): r_=c[i] r_n=r_ for j in range(i): b=c[j] x_=x[j] dt=2*((r_*b)**(1/2)) x_+=dt r_n=max(r_n,x_) x.append(r_n) if rdisplay(); operation solve() : OclAny pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if N = 1 then ( return c->first() * 2 ) else skip ; var r : double := c->first() * 2 ; var x : Sequence := Sequence{ c->first() } ; for i : Integer.subrange(1, N-1) do ( var r_ : OclAny := c[i+1] ; var r_n : OclAny := r_ ; for j : Integer.subrange(0, i-1) do ( var b : OclAny := c[j+1] ; var x_ : OclAny := x[j+1] ; var dt : double := 2 * (((r_ * b))->pow((1 / 2))) ; x_ := x_ + dt ; r_n := Set{r_n, x_}->max()) ; execute ((r_n) : x) ; if (r->compareTo(r_n + r_)) < 0 then ( r := r_n + r_ ) else skip) ; return r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline write=sys.stdout.write def solve(): N,L=map(int,readline().split()) if N==0 : return False ma=0 P=[list(map(int,readline().split()))for i in range(N)] ma=max(u for s,t,u in P) K=86400 EPS=1e-8 def check(x,M=2): rest=L R=[0]*M for i in range(M): prv=0 for s,t,u in P : rest=min(rest+(s-prv)*x,L) rest=min(rest+(t-s)*(x-u),L) prv=t if rest<0 : return 0 rest=min(rest+(K-prv)*x,L) R[i]=rest return R[-2]-EPScollect( _x | (OclType["int"])->apply(_x) ) ; if N = 0 then ( return false ) else skip ; var ma : int := 0 ; var P : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((readline().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; ma := ((argument (test (logical_test (comparison (expr (atom (name u)))))) (comp_for for (exprlist (expr (atom (name s))) , (expr (atom (name t))) , (expr (atom (name u)))) in (logical_test (comparison (expr (atom (name P))))))))->max() ; var K : int := 86400 ; var EPS : double := ("1e-8")->toReal() ; skip ; var left : int := 0; var right : int := ma ; while (left + EPS->compareTo(right)) < 0 do ( var mid : double := (left + right) / 2 ; if check(mid) then ( right := mid ) else ( left := mid )) ; write(StringLib.format("%.016f\n",right)) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s1,s2,s3=input().split() S1=str.upper(s1) S2=str.upper(s2) S3=str.upper(s3) print(S1[0]+S2[0]+S3[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s1 : OclAny := null; var s2 : OclAny := null; var s3 : OclAny := null; Sequence{s1,s2,s3} := input().split() ; var S1 : String := ("" + (->toUpperCase())) ; var S2 : String := ("" + (->toUpperCase())) ; var S3 : String := ("" + (->toUpperCase())) ; execute (S1->first() + S2->first() + S3->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n): if n<=1 : return 0 elif n==2 : return 1 elif n==3 : return 2 elif n % 2==0 : return 2 else : return 3 if __name__=="__main__" : t=int(input()) for i in range(0,t): n=int(input()) print(solve(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (solve(n))->display()) ) else skip; operation solve(n : OclAny) : OclAny pre: true post: true activity: if n <= 1 then ( return 0 ) else (if n = 2 then ( return 1 ) else (if n = 3 then ( return 2 ) else (if n mod 2 = 0 then ( return 2 ) else ( return 3 ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: n=int(s); print(min(n-1,2+n % 2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var n : int := ("" + ((s)))->toInteger(); execute (Set{n - 1, 2 + n mod 2}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) return min(n-1,2+n % 2) t=int(input()) ans=[] while t : ans.append(str(solve())) t-=1 print("\n".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; while t do ( execute ((("" + ((solve())))) : ans) ; t := t - 1) ; execute (StringLib.sumStringsWithSeparator((ans), "\n"))->display(); operation solve() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; return Set{n - 1, 2 + n mod 2}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) u=0 j=0 while n>1 : if n==2 : u+=1 break else : if n % 2==1 : n-=1 u+=1 else : p=n//2 n//=p u+=1 print(u) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var u : int := 0 ; var j : int := 0 ; while n > 1 do ( if n = 2 then ( u := u + 1 ; break ) else ( if n mod 2 = 1 then ( n := n - 1 ; u := u + 1 ) else ( var p : int := n div 2 ; n := n div p ; u := u + 1 ) )) ; execute (u)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) if(n<=1): print(0) elif(n==2): print(1) elif(n==3): print(2) elif(n % 2==0): print(2) else : print(3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n <= 1) then ( execute (0)->display() ) else (if (n = 2) then ( execute (1)->display() ) else (if (n = 3) then ( execute (2)->display() ) else (if (n mod 2 = 0) then ( execute (2)->display() ) else ( execute (3)->display() ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if(n % 4==0 or n % 7==0 or n % 44==0 or n % 47==0 or n % 74==0 or n % 77==0 or n % 444==0 or n % 447==0 or n % 474==0 or n % 477==0 or n % 744==0 or n % 747==0 or n % 774==0 or n % 777==0): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n mod 4 = 0 or n mod 7 = 0 or n mod 44 = 0 or n mod 47 = 0 or n mod 74 = 0 or n mod 77 = 0 or n mod 444 = 0 or n mod 447 = 0 or n mod 474 = 0 or n mod 477 = 0 or n mod 744 = 0 or n mod 747 = 0 or n mod 774 = 0 or n mod 777 = 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) list1=[4,7] i=0 while(1): x=list1[i]*10+4 y=list1[i]*10+7 a=[x,y] list1.extend(a) i+=1 if x>=1000 : break list2=[] for i in range(n): if(i+1)% 4==0 or(i+1)% 7==0 or(i+1)% 44==0 or(i+1)% 47==0 : b=[i+1] list2.extend(b) if n in list1 or n in list2 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var list1 : Sequence := Sequence{4}->union(Sequence{ 7 }) ; var i : int := 0 ; while (1) do ( var x : double := list1[i+1] * 10 + 4 ; var y : double := list1[i+1] * 10 + 7 ; var a : Sequence := Sequence{x}->union(Sequence{ y }) ; list1 := list1->union(a) ; i := i + 1 ; if x >= 1000 then ( break ) else skip) ; var list2 : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if (i + 1) mod 4 = 0 or (i + 1) mod 7 = 0 or (i + 1) mod 44 = 0 or (i + 1) mod 47 = 0 then ( var b : Sequence := Sequence{ i + 1 } ; list2 := list2->union(b) ) else skip) ; if (list1)->includes(n) or (list2)->includes(n) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=input().split() n=int(f[0]) k=int(f[1]) l=input() d={} q=[] c=0 for i in l : if i not in d : d[i]=1 else : d[i]+=1 for i in d.values(): q.append(i) q.sort(reverse=True) j=0 while(1): if k<=0 : break if q[j]<=k : k=k-q[j] c+=q[j]*q[j] elif q[j]>k : c+=k*k break j+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : OclAny := input().split() ; var n : int := ("" + ((f->first())))->toInteger() ; var k : int := ("" + ((f[1+1])))->toInteger() ; var l : String := (OclFile["System.in"]).readLine() ; var d : OclAny := Set{} ; var q : Sequence := Sequence{} ; var c : int := 0 ; for i : l->characters() do ( if (d)->excludes(i) then ( d[i+1] := 1 ) else ( d[i+1] := d[i+1] + 1 )) ; for i : d.values() do ( execute ((i) : q)) ; q := q->sort() ; var j : int := 0 ; while (1) do ( if k <= 0 then ( break ) else skip ; if (q[j+1]->compareTo(k)) <= 0 then ( k := k - q[j+1] ; c := c + q[j+1] * q[j+1] ) else (if (q[j+1]->compareTo(k)) > 0 then ( c := c + k * k ; break ) else skip) ; j := j + 1) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=0 n=int(input()) if str(n).count('4')+str(n).count('7')==len(str(n)): print('YES') k=1 else : for i in range(1,n): if str(i).count('4')+str(i).count('7')==len(str(i)): if n % i==0 : print('YES') k=1 break if k==0 : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := 0 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if OclType["String"](n)->count('4') + OclType["String"](n)->count('7') = (("" + ((n))))->size() then ( execute ('YES')->display() ; k := 1 ) else ( for i : Integer.subrange(1, n-1) do ( if OclType["String"](i)->count('4') + OclType["String"](i)->count('7') = (("" + ((i))))->size() then ( if n mod i = 0 then ( execute ('YES')->display() ; k := 1 ; break ) else skip ) else skip) ) ; if k = 0 then ( execute ('NO')->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[4,7,47,74,447,474,477,744,747,777,774] for i in a : if n % i==0 : print('YES') break else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{4}->union(Sequence{7}->union(Sequence{47}->union(Sequence{74}->union(Sequence{447}->union(Sequence{474}->union(Sequence{477}->union(Sequence{744}->union(Sequence{747}->union(Sequence{777}->union(Sequence{ 774 })))))))))) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name a))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name n))) % (expr (atom (name i))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 4==0 or n % 7==0 or n % 44==0 or n % 47==0 or n % 74==0 or n % 77==0 or n % 444==0 or n % 447==0 or n % 474==0 or n % 744==0 or n % 477==0 or n % 747==0 or n % 774==0 or n % 777==0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 4 = 0 or n mod 7 = 0 or n mod 44 = 0 or n mod 47 = 0 or n mod 74 = 0 or n mod 77 = 0 or n mod 444 = 0 or n mod 447 = 0 or n mod 474 = 0 or n mod 744 = 0 or n mod 477 = 0 or n mod 747 = 0 or n mod 774 = 0 or n mod 777 = 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sList=list(map(str,input().split())) string="" for i in sList : string+=i[0] print(string.upper()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sList : Sequence := ((input().split())->collect( _x | (OclType["String"])->apply(_x) )) ; var string : String := "" ; for i : sList do ( string := string + i->first()) ; execute (string->toUpperCase())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math number=int(input()) def tr(number): x=(number*(number+1))/2 return x index=1 while True : x=tr(index) if x==number : print("YES") break elif x>number : print("NO") break else : index+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var number : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; var index : int := 1 ; while true do ( x := tr(index) ; if x = number then ( execute ("YES")->display() ; break ) else (if (x->compareTo(number)) > 0 then ( execute ("NO")->display() ; break ) else ( index := index + 1 ) ) ); operation tr(number : OclAny) : OclAny pre: true post: true activity: var x : double := (number * (number + 1)) / 2 ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) triangular=1 i=1 while triangulartoInteger() ; var triangular : int := 1 ; var i : int := 1 ; while (triangular->compareTo(n)) < 0 do ( i := i + 1 ; triangular := triangular + i) ; if triangular = n then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) x=8*x+1 print("NO" if(x**.5)% 1>0 else "YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; x := 8 * x + 1 ; execute (if ((x)->pow(.5)) mod 1 > 0 then "NO" else "YES" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) count=1 data=1 while datatoInteger() ; var count : int := 1 ; var data : int := 1 ; while (data->compareTo(n)) < 0 do ( data := (count * (count + 1)) div 2 ; count := count + 1) ; if data = n then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) t=1 i=1 while ttoInteger() ; var t : int := 1 ; var i : int := 1 ; while (t->compareTo(n)) < 0 do ( i := i + 1 ; t := t + i;) ; if t = n then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def distinctChars(s): freq=[0]*26 ; count=0 ; for i in range(len(s)): freq[ord(s[i])-ord('a')]+=1 ; for i in range(26): if(freq[i]>0): count+=1 ; return count ; def waysToSplit(s): n=len(s); answer=0 ; for i in range(1,n): left=s[0 : i]; right=s[i : n]; if(distinctChars(left)==distinctChars(right)): answer+=1 ; return answer ; if __name__=="__main__" : s="ababa" ; print(waysToSplit(s)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( s := "ababa"; ; execute (waysToSplit(s))->display(); ) else skip; operation distinctChars(s : OclAny) pre: true post: true activity: var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26); ; var count : int := 0; ; for i : Integer.subrange(0, (s)->size()-1) do ( freq[(s[i+1])->char2byte() - ('a')->char2byte()+1] := freq[(s[i+1])->char2byte() - ('a')->char2byte()+1] + 1;) ; for i : Integer.subrange(0, 26-1) do ( if (freq[i+1] > 0) then ( count := count + 1; ) else skip) ; return count;; operation waysToSplit(s : OclAny) pre: true post: true activity: var n : int := (s)->size(); ; var answer : int := 0; ; for i : Integer.subrange(1, n-1) do ( var left : OclAny := s.subrange(0+1, i); ; var right : OclAny := s.subrange(i+1, n); ; if (distinctChars(left) = distinctChars(right)) then ( answer := answer + 1; ) else skip) ; return answer;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n,k=[int(i)for i in input().split()] s=input() cnt=Counter(s) z=sorted([i for i in cnt.values()],reverse=True) ans=0 for i in range(n): ans+=min(k,z[i])**2 k-=min(k,z[i]) if k==0 : break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var s : String := (OclFile["System.in"]).readLine() ; var cnt : OclAny := Counter(s) ; var z : Sequence := cnt.values()->select(i | true)->collect(i | (i))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( ans := ans + (Set{k, z[i+1]}->min())->pow(2) ; k := k - Set{k, z[i+1]}->min() ; if k = 0 then ( break ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=float(input()) print(int(n)+1 if n*math.sqrt(2)toReal() ; execute (if (n * (2)->sqrt()->compareTo(("" + ((n)))->toInteger() + 1)) < 0 then ("" + ((n)))->toInteger() + 1 else n * (2)->sqrt() endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 dd=[(0,-1),(1,0),(0,1),(-1,0)] ddn=[(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)] def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): n=F() nn=n**2 r=n*(2**0.5) for i in range(int(n)+1): kk=nn-i**2 if kk<0 : break k=kk**0.5 tr=i+k if k<1 : tr+=1-k if rpow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; var dd : Sequence := Sequence{Sequence{0, -1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{ Sequence{-1, 0} }))) ; var ddn : Sequence := Sequence{Sequence{0, -1}}->union(Sequence{Sequence{1, -1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{1, 1}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{-1, -1}}->union(Sequence{Sequence{-1, 0}}->union(Sequence{ Sequence{-1, 1} }))))))) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var n : OclAny := F() ; var nn : double := (n)->pow(2) ; var r : double := n * ((2)->pow(0.5)) ; for i : Integer.subrange(0, ("" + ((n)))->toInteger() + 1-1) do ( var kk : double := nn - (i)->pow(2) ; if kk < 0 then ( break ) else skip ; var k : double := (kk)->pow(0.5) ; var tr : OclAny := i + k ; if k < 1 then ( tr := tr + 1 - k ) else skip ; if (r->compareTo(tr)) < 0 then ( r := tr ) else skip) ; return r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d=float(input()) ans=d*pow(2,0.5) for i in range(1,11): if i<=d<=pow(1+i**2,0.5): ans=max(ans,i+1) print("{:.020f}".format(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; var ans : double := d * (2)->pow(0.5) ; for i : Integer.subrange(1, 11-1) do ( if (i->compareTo(d)) <= 0 & (d <= (1 + (i)->pow(2))->pow(0.5)) then ( ans := Set{ans, i + 1}->max() ) else skip) ; execute (StringLib.interpolateStrings("{:.020f}", Sequence{ans}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d=float(input()); print(max(int(d)+1,d*2**0.5)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : double := ("" + (((OclFile["System.in"]).readLine())))->toReal(); execute (Set{("" + ((d)))->toInteger() + 1, d * (2)->pow(0.5)}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findTerm(n): if n==1 : return n else : term=7 for i in range(2,n+1): term=term*2+(i-1); return term ; print(findTerm(5)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (findTerm(5))->display(); operation findTerm(n : OclAny) : OclAny pre: true post: true activity: if n = 1 then ( return n ) else ( var term : int := 7 ; for i : Integer.subrange(2, n + 1-1) do ( term := term * 2 + (i - 1);) ) ; return term;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d=float(input()) ans=max(2**0.5*d,int(d)+1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; var ans : OclAny := Set{(2)->pow(0.5) * d, ("" + ((d)))->toInteger() + 1}->max() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def Triplets(n): ans=0 for i in range(1,n+1): for j in range(i,n+1): x=i*i+j*j y=int(math.sqrt(x)) if(y*y==x and y<=n): ans+=1 return ans if __name__=="__main__" : n=10 print(Triplets(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 10 ; execute (Triplets(n))->display() ) else skip; operation Triplets(n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(i, n + 1-1) do ( var x : double := i * i + j * j ; var y : int := ("" + (((x)->sqrt())))->toInteger() ; if (y * y = x & (y->compareTo(n)) <= 0) then ( ans := ans + 1 ) else skip)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countUnvisited(n,m): i=0 X=(m*n)-m-n queue=[] queue.append(X) count=0 while(len(queue)>0): curr=queue[0] queue.remove(queue[0]) count+=1 if(curr-m>0): queue.append(curr-m) if(curr-n>0): queue.append(curr-n) return count if __name__=='__main__' : n=2 m=5 print(countUnvisited(n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 2 ; m := 5 ; execute (countUnvisited(n, m))->display() ) else skip; operation countUnvisited(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; var X : double := (m * n) - m - n ; var queue : Sequence := Sequence{} ; execute ((X) : queue) ; var count : int := 0 ; while ((queue)->size() > 0) do ( var curr : OclAny := queue->first() ; execute ((queue->first()) /: queue) ; count := count + 1 ; if (curr - m > 0) then ( execute ((curr - m) : queue) ) else skip ; if (curr - n > 0) then ( execute ((curr - n) : queue) ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dist(x1,y1,x2,y2,r): print("The shortest distance between a point and a circle is ",((((x2-x1)**2)+((y2-y1)**2))**(1/2))-r); x1=4 ; y1=6 ; x2=35 ; y2=42 ; r=5 ; dist(x1,y1,x2,y2,r); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x1 := 4; ; y1 := 6; ; x2 := 35; ; y2 := 42; ; r := 5; ; dist(x1, y1, x2, y2, r);; operation dist(x1 : OclAny, y1 : OclAny, x2 : OclAny, y2 : OclAny, r : OclAny) pre: true post: true activity: execute ("The shortest distance between a point and a circle is ")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=[int(s)for s in input().split()] hito=[0 for i in range(N)] edge=[set()for _ in range(N)] for i in range(M): a,b=[int(s)for s in input().split()] edge[a-1].add(b-1) edge[b-1].add(a-1) def dfs(start): count=1 reach=set() reach.add(start) hito[start]=1 while reach : _from=reach.pop() for _to in edge[_from]: if not(_to in reach)and hito[_to]==0 : reach.add(_to) count+=1 hito[_to]=1 return(count) ans=set() for h in range(N): if hito[h]==0 : ans.add(dfs(h)) print(max(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; var hito : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; var edge : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; for i : Integer.subrange(0, M-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ))))) ; skip ; var ans : Set := Set{}->union(()) ; for h : Integer.subrange(0, N-1) do ( if hito[h+1] = 0 then ( execute ((dfs(h)) : ans) ) else skip) ; execute ((ans)->max())->display(); operation dfs(start : OclAny) : OclAny pre: true post: true activity: var count : int := 1 ; var reach : Set := Set{}->union(()) ; execute ((start) : reach) ; hito[start+1] := 1 ; while reach do ( var _from : OclAny := reach->last() ; reach := reach->front() ; for _to : edge[_from+1] do ( if not(((reach)->includes(_to))) & hito[_to+1] = 0 then ( execute ((_to) : reach) ; count := count + 1 ; hito[_to+1] := 1 ) else skip)) ; return (count); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate N,K=map(int,input().split()) S=input() q=[] pre=S[0] ans=cnt=0 for s in S : if pre!=s : q.append(cnt) cnt=1 pre=s else : cnt+=1 q.append(cnt) J=2*K+1 acc=list(accumulate(q)) acc+=[acc[-1]] if len(q)<=J : ans=acc[-1]-1 else : ans=acc[J-1]-1+acc[-1]-acc[J]-(len(q)-J) for i,a in enumerate(acc): if i+Jans : ans=tot print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : String := (OclFile["System.in"]).readLine() ; var q : Sequence := Sequence{} ; var pre : OclAny := S->first() ; var ans : OclAny := 0; var cnt : int := 0 ; for s : S->characters() do ( if pre /= s then ( execute ((cnt) : q) ; cnt := 1 ; pre := s ) else ( cnt := cnt + 1 )) ; execute ((cnt) : q) ; var J : double := 2 * K + 1 ; var acc : Sequence := (accumulate(q)) ; acc := acc + Sequence{ acc->last() } ; if ((q)->size()->compareTo(J)) <= 0 then ( ans := acc->last() - 1 ) else ( ans := acc[J - 1+1] - 1 + acc->last() - acc[J+1] - ((q)->size() - J) ; for _tuple : Integer.subrange(1, (acc)->size())->collect( _indx | Sequence{_indx-1, (acc)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); if (i + J->compareTo((q)->size())) < 0 then ( var tot : double := acc[i + J+1] - acc[i+1] - 1 ; tot := tot + acc[i+1] + acc->last() - acc[i + J + 1+1] - ((q)->size() - J) ; if (tot->compareTo(ans)) > 0 then ( ans := tot ) else skip ) else skip) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque class Graph(): def __init__(self): self.adjacency_dict={} def add_vertex(self,v): self.adjacency_dict[v]=[] def add_edge(self,v1,v2): self.adjacency_dict[v1].append(v2) self.adjacency_dict[v2].append(v1) def next_vertices(self,v): return self.adjacency_dict[v] def bfs(start): visited[start]=True q=deque() q.append(start) group_size=1 while q : v_now=q.popleft() for v_next in graph.next_vertices(v_now): if visited[v_next]==False : visited[v_next]=True q.append(v_next) group_size+=1 return group_size N,M=map(int,input().split()) AB=[list(map(int,input().split()))for _ in range(M)] graph=Graph() for i in range(1,N+1): graph.add_vertex(i) for v1,v2 in AB : graph.add_edge(v1,v2) visited=[False]*(N+1) max_group_size=1 for i in range(1,N+1): if visited[i]==False : group_size=bfs(i) max_group_size=max(max_group_size,group_size) print(max_group_size) ------------------------------------------------------------ OCL File: --------- class Graph { static operation newGraph() : Graph pre: true post: Graph->exists( _x | result = _x ); attribute adjacency_dict : OclAny := Set{}; operation initialise() : pre: true post: true activity: self.adjacency_dict := Set{}; return self; operation add_vertex(v : OclAny) pre: true post: true activity: self.adjacency_dict[v+1] := Sequence{}; operation add_edge(v1 : OclAny,v2 : OclAny) pre: true post: true activity: (expr (atom (name self)) (trailer . (name adjacency_dict) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v1)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v2)))))))) )))) ; (expr (atom (name self)) (trailer . (name adjacency_dict) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v2)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v1)))))))) )))); operation next_vertices(v : OclAny) : OclAny pre: true post: true activity: return self.adjacency_dict[v+1]; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var AB : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var graph : Graph := (Graph.newGraph()).initialise() ; for i : Integer.subrange(1, N + 1-1) do ( graph.add_vertex(i)) ; for _tuple : AB do (var _indx : int := 1; var v1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v2 : OclAny := _tuple->at(_indx); graph.add_edge(v1, v2)) ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (N + 1)) ; var max_group_size : int := 1 ; for i : Integer.subrange(1, N + 1-1) do ( if visited[i+1] = false then ( group_size := bfs(i) ; max_group_size := Set{max_group_size, group_size}->max() ) else skip) ; execute (max_group_size)->display(); operation bfs(start : OclAny) : OclAny pre: true post: true activity: visited[start+1] := true ; var q : Sequence := () ; execute ((start) : q) ; var group_size : int := 1 ; while q do ( var v_now : OclAny := q->first() ; q := q->tail() ; for v_next : graph.next_vertices(v_now) do ( if visited[v_next+1] = false then ( visited[v_next+1] := true ; execute ((v_next) : q) ; group_size := group_size + 1 ) else skip)) ; return group_size; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.buffer.readline()[:-1] class UnionFind(): def __init__(self,size): self.table=[-1 for _ in range(size)] self.size=[1 for _ in range(size)] def find(self,x): while self.table[x]>=0 : if self.table[self.table[x]]>=0 : self.table[x]=self.table[self.table[x]] x=self.table[x] return x def unite(self,x,y): s1=self.find(x) s2=self.find(y) if s1!=s2 : if self.table[s1]>self.table[s2]: self.table[s2]=s1 self.table[s1]-=1 self.size[s1]+=self.size[s2] self.size[s2]=0 else : self.table[s1]=s2 self.table[s2]-=1 self.size[s2]+=self.size[s1] self.size[s1]=0 return n,m=map(int,input().split()) uf=UnionFind(n) for _ in range(m): a,b=map(int,input().split()) uf.unite(a-1,b-1) print(max(uf.size)) ------------------------------------------------------------ OCL File: --------- class UnionFind { static operation newUnionFind() : UnionFind pre: true post: UnionFind->exists( _x | result = _x ); attribute table : Sequence := Integer.subrange(0, size-1)->select(_anon | true)->collect(_anon | (-1)); attribute size : Sequence := Integer.subrange(0, size-1)->select(_anon | true)->collect(_anon | (1)); operation initialise(size : OclAny) : pre: true post: true activity: self.table := Integer.subrange(0, size-1)->select(_anon | true)->collect(_anon | (-1)) ; self.size := Integer.subrange(0, size-1)->select(_anon | true)->collect(_anon | (1)); return self; operation find(x : OclAny) : OclAny pre: true post: true activity: while self.table[x+1] >= 0 do ( if self.table[self.table[x+1]+1] >= 0 then ( self.table[x+1] := self.table[self.table[x+1]+1] ) else skip ; x := self.table[x+1]) ; return x; operation unite(x : OclAny,y : OclAny) pre: true post: true activity: var s1 : int := self->indexOf(x) - 1 ; var s2 : int := self->indexOf(y) - 1 ; if s1 /= s2 then ( if (self.table[s1+1]->compareTo(self.table[s2+1])) > 0 then ( self.table[s2+1] := s1 ; self.table[s1+1] := self.table[s1+1] - 1 ; self.size[s1+1] := self.size[s1+1] + self.size[s2+1] ; self.size[s2+1] := 0 ) else ( self.table[s1+1] := s2 ; self.table[s2+1] := self.table[s2+1] - 1 ; self.size[s2+1] := self.size[s2+1] + self.size[s1+1] ; self.size[s1+1] := 0 ) ) else skip ; return; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var uf : UnionFind := (UnionFind.newUnionFind()).initialise(n) ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; uf.unite(a - 1, b - 1)) ; execute ((uf.size)->max())->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.buffer.readLine()->front(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class UnionFind : def __init__(self,n): self.par=[i for i in range(n)] self.rank=[0 for _ in range(n)] def find(self,x): if self.par[x]==x : return x else : self.par[x]=self.find(self.par[x]) return self.par[x] def unite(self,x,y): x=self.find(x) y=self.find(y) if x==y : return if self.rank[x]exists( _x | result = _x ); attribute par : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)); attribute rank : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)); operation initialise(n : OclAny) : UnionFind pre: true post: true activity: self.par := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)) ; self.rank := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)); return self; operation find(x : OclAny) : OclAny pre: true post: true activity: if self.par[x+1] = x then ( return x ) else ( self.par[x+1] := self->indexOf(self.par[x+1]) - 1 ; return self.par[x+1] ); operation unite(x : OclAny,y : OclAny) pre: true post: true activity: x := self->indexOf(x) - 1 ; y := self->indexOf(y) - 1 ; if x = y then ( return ) else skip ; if (self.rank[x+1]->compareTo(self.rank[y+1])) < 0 then ( self.par[x+1] := y ) else ( self.par[y+1] := x ; if self.rank[x+1] = self.rank[y+1] then ( self.rank[x+1] := self.rank[x+1] + 1 ) else skip ); operation same(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: return self->indexOf(x) - 1 = self->indexOf(y) - 1; } class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var L : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var uf : UnionFind := (UnionFind.newUnionFind()).initialise(N) ; for i : Integer.subrange(0, M-1) do ( uf.unite(L[i+1]->first() - 1, L[i+1][1+1] - 1)) ; var team : OclAny := Set{} ; for i : Integer.subrange(0, N-1) do ( var tmp : int := uf->indexOf(i) - 1 ; if (team)->excludes(tmp) then ( team[tmp+1] := 1 ) else ( team[tmp+1] := team[tmp+1] + 1 )) ; var ans : int := 0 ; for _tuple : team->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); ans := Set{ans, v}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict from itertools import accumulate import bisect import sys input=sys.stdin.readline def solve(n,m): graph=defaultdict(list) for _ in range(m): a,b=map(int,input().split()) a-=1 b-=1 graph[a].append(b) graph[b].append(a) connected=[] unseen=set(range(n)) while unseen : aa=unseen.pop() unseen.add(aa) stack=[aa] cnt=0 while stack : bb=stack.pop() if bb in unseen : stack.extend(graph[bb]) unseen.remove(bb) cnt+=1 connected.append(cnt) print(max(connected)) def main(): n,m=map(int,input().split()) solve(n,m) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation solve(n : OclAny, m : OclAny) pre: true post: true activity: var graph : OclAny := defaultdict(OclType["Sequence"]) ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := a - 1 ; b := b - 1 ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var connected : Sequence := Sequence{} ; var unseen : Set := Set{}->union((Integer.subrange(0, n-1))) ; while unseen do ( var aa : OclAny := unseen->last() ; unseen := unseen->front() ; execute ((aa) : unseen) ; var stack : Sequence := Sequence{ aa } ; var cnt : int := 0 ; while stack do ( var bb : OclAny := stack->last() ; stack := stack->front() ; if (unseen)->includes(bb) then ( stack := stack->union(graph[bb+1]) ; execute ((bb) /: unseen) ; cnt := cnt + 1 ) else skip) ; execute ((cnt) : connected)) ; execute ((connected)->max())->display(); operation main() pre: true post: true activity: Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; solve(n, m); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSubArr(arr,n): for i in range(n-1): if(abs(arr[i]-arr[i+1])>=2): print(arr[i],arr[i+1],end=""); return ; print(-1); if __name__=="__main__" : arr=[1,2,4,6,7]; n=len(arr); findSubArr(arr,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{6}->union(Sequence{ 7 })))); ; n := (arr)->size(); ; findSubArr(arr, n); ) else skip; operation findSubArr(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n - 1-1) do ( if ((arr[i+1] - arr[i + 1+1])->abs() >= 2) then ( execute (arr[i+1])->display(); ; return; ) else skip) ; execute (-1)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution : def findKthNumber(self,m : int,n : int,k : int)->int : def enough(x): count=0 for i in range(1,m+1): count+=min(x//i,n) return count>=k lo,hi=1,m*n while loexists( _x | result = _x ); operation findKthNumber(m : int,n : int,k : int) : int pre: true post: true activity: skip ; var lo : OclAny := null; var hi : OclAny := null; Sequence{lo,hi} := Sequence{1,m * n} ; while (lo->compareTo(hi)) < 0 do ( var mi : int := (lo + hi) div 2 ; if not(enough(mi)) then ( var lo : int := mi + 1 ) else ( var hi : int := mi )) ; return lo; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countFibs(low,high): f1,f2,f3=0,1,1 result=0 while(f1<=high): if(f1>=low): result+=1 f1=f2 f2=f3 f3=f1+f2 return result low,high=10,100 print("Count of Fibonacci Numbers is",countFibs(low,high)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{low,high} := Sequence{10,100} ; execute ("Count of Fibonacci Numbers is")->display(); operation countFibs(low : OclAny, high : OclAny) : OclAny pre: true post: true activity: var f1 : OclAny := null; var f2 : OclAny := null; var f3 : OclAny := null; Sequence{f1,f2,f3} := Sequence{0,1,1} ; var result : int := 0 ; while ((f1->compareTo(high)) <= 0) do ( if ((f1->compareTo(low)) >= 0) then ( result := result + 1 ) else skip ; var f1 : OclAny := f2 ; var f2 : OclAny := f3 ; var f3 : OclAny := f1 + f2) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def findNthDigit(self,n): count=9 start=1 curr_len=1 while n>curr_len*count : n-=curr_len*count curr_len+=1 count*=10 start*=10 start+=(n-1)/curr_len s=str(start) return int(s[(n-1)% curr_len]) ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation findNthDigit(n : OclAny) : OclAny pre: true post: true activity: var count : int := 9 ; var start : int := 1 ; var curr_len : int := 1 ; while (n->compareTo(curr_len * count)) > 0 do ( n := n - curr_len * count ; curr_len := curr_len + 1 ; count := count * 10 ; start := start * 10) ; start := start + (n - 1) / curr_len ; var s : String := ("" + ((start))) ; return ("" + ((s[(n - 1) mod curr_len+1])))->toInteger(); } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countDecodingDP(digits,n): count=[0]*(n+1); count[0]=1 ; count[1]=1 ; for i in range(2,n+1): count[i]=0 ; if(digits[i-1]>'0'): count[i]=count[i-1]; if(digits[i-2]=='1' or(digits[i-2]=='2' and digits[i-1]<'7')): count[i]+=count[i-2]; return count[n]; digits="1234" ; n=len(digits); print("Count is",countDecodingDP(digits,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; digits := "1234"; ; n := (digits)->size(); ; execute ("Count is")->display();; operation countDecodingDP(digits : OclAny, n : OclAny) pre: true post: true activity: var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); ; count->first() := 1; ; count[1+1] := 1; ; for i : Integer.subrange(2, n + 1-1) do ( count[i+1] := 0; ; if (digits[i - 1+1] > '0') then ( count[i+1] := count[i - 1+1]; ) else skip ; if (digits[i - 2+1] = '1' or (digits[i - 2+1] = '2' & digits[i - 1+1] < '7')) then ( count[i+1] := count[i+1] + count[i - 2+1]; ) else skip) ; return count[n+1];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printNos(n): if n>0 : printNos(n-1) print(n,end=' ') printNos(100) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; printNos(100); operation printNos(n : OclAny) pre: true post: true activity: if n > 0 then ( printNos(n - 1) ; execute (n)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import* n,k=map(int,input().split()) print(min(sum(len(list(l))-1 for _,l in groupby(input()))+2*k,n-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{((argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)))))))) ))))))))) )))) - (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name _))) , (expr (atom (name l)))) in (logical_test (comparison (expr (atom (name groupby)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) )))))))))->sum() + 2 * k, n - 1}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def leafSimilar(self,root1,root2): if not root1 and not root2 : return True leaf1=[] leaf2=[] self.dfs(root1,leaf1) self.dfs(root2,leaf2) if leaf1==leaf2 : return True return False def dfs(self,node,leavels): if not node : return if not node.left and not node.right : leavels.append(node.val) self.dfs(node.left,leavels) self.dfs(node.right,leavels) ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation leafSimilar(root1 : OclAny,root2 : OclAny) : OclAny pre: true post: true activity: if not(root1) & not(root2) then ( return true ) else skip ; var leaf1 : Sequence := Sequence{} ; var leaf2 : Sequence := Sequence{} ; self.dfs(root1, leaf1) ; self.dfs(root2, leaf2) ; if leaf1 = leaf2 then ( return true ) else skip ; return false; operation dfs(node : OclAny,leavels : OclAny) pre: true post: true activity: if not(node) then ( return ) else skip ; if not(node.left) & not(node.right) then ( execute ((node.val) : leavels) ) else skip ; self.dfs(node.left, leavels) ; self.dfs(node.right, leavels); } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=list(map(int,input().split())) if(a//b)& 1==1 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if MathLib.bitwiseAnd((a div b), 1) = 1 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=n//m if(a % 2==0): print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : int := n div m ; if (a mod 2 = 0) then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) if int(n//k)% 2==0 : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if ("" + ((n div k)))->toInteger() mod 2 = 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) if(n//k)% 2==0 : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (n div k) mod 2 = 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) m=n//k if m % 2==0 : print('NO') else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : int := n div k ; if m mod 2 = 0 then ( execute ('NO')->display() ) else ( execute ('YES')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input(),2) i=0 while True : s=4**i if s>=n : break else : i+=1 print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine(), 2)))->toInteger() ; var i : int := 0 ; while true do ( var s : double := (4)->pow(i) ; if (s->compareTo(n)) >= 0 then ( break ) else ( i := i + 1 )) ; execute (i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def set(mess): Mess=list(mess.split("0")) Ml=len(Mess) for i in range(Ml): if("" in Mess): Mess.remove("") else : break ML=len(Mess) change(Mess,ML) def change(Mess,ML): one=[".",",","!","?",""] alpha=[chr(i)for i in range(97,97+26)] Num=list() Cnt=list() for i in range(ML): a=list(Mess[i]) Num.append(a[0]) Cnt.append(len(a)) ans=list() for i in range(ML): if(Num[i]=="1"): ans.append(one[Cnt[i]% 5-1]) elif(Num[i]=="7"): ans.append(alpha[(Cnt[i]-1)% 4+15]) elif(Num[i]=="8"): ans.append(alpha[(Cnt[i]-1)% 3+19]) elif(Num[i]=="9"): ans.append(alpha[(Cnt[i]-1)% 4+22]) else : x=3*(int(Num[i])-2) ans.append(alpha[(Cnt[i]-1)% 3+x]) for j in range(len(ans)): if(j==len(ans)-1): print(ans[j]) else : print(ans[j],end="") N=int(input()) for i in range(N): mess=input() set(mess) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, N-1) do ( mess := (OclFile["System.in"]).readLine() ; OclType["Set"](mess)); operation set(mess : OclAny) pre: true post: true activity: var Mess : Sequence := (mess.split("0")) ; var Ml : int := (Mess)->size() ; for i : Integer.subrange(0, Ml-1) do ( if ((Mess)->includes("")) then ( execute (("") /: Mess) ) else ( break )) ; var ML : int := (Mess)->size() ; change(Mess, ML); operation change(Mess : OclAny, ML : OclAny) pre: true post: true activity: var one : Sequence := Sequence{"."}->union(Sequence{","}->union(Sequence{"!"}->union(Sequence{"?"}->union(Sequence{ "" })))) ; var alpha : Sequence := Integer.subrange(97, 97 + 26-1)->select(i | true)->collect(i | ((i)->byte2char())) ; var Num : Sequence := () ; var Cnt : Sequence := () ; for i : Integer.subrange(0, ML-1) do ( var a : Sequence := (Mess[i+1]) ; execute ((a->first()) : Num) ; execute (((a)->size()) : Cnt)) ; var ans : Sequence := () ; for i : Integer.subrange(0, ML-1) do ( if (Num[i+1] = "1") then ( execute ((one[Cnt[i+1] mod 5 - 1+1]) : ans) ) else (if (Num[i+1] = "7") then ( execute ((alpha[(Cnt[i+1] - 1) mod 4 + 15+1]) : ans) ) else (if (Num[i+1] = "8") then ( execute ((alpha[(Cnt[i+1] - 1) mod 3 + 19+1]) : ans) ) else (if (Num[i+1] = "9") then ( execute ((alpha[(Cnt[i+1] - 1) mod 4 + 22+1]) : ans) ) else ( var x : double := 3 * (("" + ((Num[i+1])))->toInteger() - 2) ; execute ((alpha[(Cnt[i+1] - 1) mod 3 + x+1]) : ans) ) ) ) ) ) ; for j : Integer.subrange(0, (ans)->size()-1) do ( if (j = (ans)->size() - 1) then ( execute (ans[j+1])->display() ) else ( execute (ans[j+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find_numbers(N): if(N==1): print(-1,end=""); else : print(N,N+1,N*(N+1)); if __name__=="__main__" : N=5 ; find_numbers(N); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := 5; ; find_numbers(N); ) else skip; operation find_numbers(N : OclAny) pre: true post: true activity: if (N = 1) then ( execute (-1)->display(); ) else ( execute (N)->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=list(map(int,input().split())) b=list(map(int,input().split())) if sum(a)>sum(b): print(sum(a)) else : print(sum(b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if ((a)->sum()->compareTo((b)->sum())) > 0 then ( execute ((a)->sum())->display() ) else ( execute ((b)->sum())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from _collections import deque def parser(): while 1 : data=list(input().split(' ')) for number in data : if len(number)>0 : yield(number) input_parser=parser() def gw(): global input_parser return next(input_parser) def gi(): data=gw() return int(data) MOD=int(1e9+7) import numpy import scipy from collections import deque N=gi() K=gi() S=gw() seg_cnt=0 for i in range(0,N-1): if S[i]!=S[i+1]: seg_cnt+=1 cur_happy=N-1-seg_cnt if 2*K>=seg_cnt : ans=N-1 else : ans=cur_happy+2*K print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute input_parser : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; var input_parser : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.parser(_i)) ; skip ; skip ; var MOD : int := ("" + ((("1e9")->toReal() + 7)))->toInteger() ; skip ; skip ; skip ; var N : OclAny := gi() ; var K : OclAny := gi() ; var S : OclAny := gw() ; var seg_cnt : int := 0 ; for i : Integer.subrange(0, N - 1-1) do ( if S[i+1] /= S[i + 1+1] then ( seg_cnt := seg_cnt + 1 ) else skip) ; var cur_happy : double := N - 1 - seg_cnt ; if (2 * K->compareTo(seg_cnt)) >= 0 then ( var ans : double := N - 1 ) else ( ans := cur_happy + 2 * K ) ; execute (ans)->display(); operation parser(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; while 1 do ( var data : Sequence := (input().split(' ')) ; for number : data do ( if (number)->size() > 0 then ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return (number) ) else skip)); operation gw() : OclAny pre: true post: true activity: skip ; return (input_parser).next(); operation gi() : OclAny pre: true post: true activity: data := gw() ; return ("" + ((data)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A=raw_input() S=0 X=0 for i in A : if(i==" "): S+=X X=0 else : X*=10 X+=int(i) S+=X B=raw_input() T=0 Y=0 for i in B : if(i==" "): T+=Y Y=0 else : Y*=10 Y+=int(i) T+=Y if(S>T): print(S) else : print(T) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := raw_input() ; var S : int := 0 ; var X : int := 0 ; for i : A do ( if (i = " ") then ( S := S + X ; X := 0 ) else ( X := X * 10 ; X := X + ("" + ((i)))->toInteger() )) ; S := S + X ; var B : OclAny := raw_input() ; var T : int := 0 ; var Y : int := 0 ; for i : B do ( if (i = " ") then ( T := T + Y ; Y := 0 ) else ( Y := Y * 10 ; Y := Y + ("" + ((i)))->toInteger() )) ; T := T + Y ; if ((S->compareTo(T)) > 0) then ( execute (S)->display() ) else ( execute (T)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- culc_score=lambda : sum(int(score)for score in input().split()) x=culc_score() y=culc_score() print(x if x>y else y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var culc_score : Function := lambda $$ : OclAny in (((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name score)))))))) ))))))) (comp_for for (exprlist (expr (atom (name score)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( )))))))))->sum()) ; var x : OclAny := culc_score->apply() ; var y : OclAny := culc_score->apply() ; execute (if (x->compareTo(y)) > 0 then x else y endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(max(sum(map(int,input().split())),sum(map(int,input().split())))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (Set{((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum(), ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum()}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys ia,ma,sa,ea=map(int,input().split()) ib,mb,sb,eb=map(int,input().split()) sum_a=ia+ma+sa+ea sum_b=ib+mb+sb+eb if(sum_a>=sum_b): print(sum_a) else : print(sum_b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var ia : OclAny := null; var ma : OclAny := null; var sa : OclAny := null; var ea : OclAny := null; Sequence{ia,ma,sa,ea} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ib : OclAny := null; var mb : OclAny := null; var sb : OclAny := null; var eb : OclAny := null; Sequence{ib,mb,sb,eb} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sum_a : OclAny := ia + ma + sa + ea ; var sum_b : OclAny := ib + mb + sb + eb ; if ((sum_a->compareTo(sum_b)) >= 0) then ( execute (sum_a)->display() ) else ( execute (sum_b)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rightRotate(arr,n,outOfPlace,cur): temp=arr[cur] for i in range(cur,outOfPlace,-1): arr[i]=arr[i-1] arr[outOfPlace]=temp return arr def rearrange(arr,n): outOfPlace=-1 for index in range(n): if(outOfPlace>=0): if((arr[index]>=0 and arr[outOfPlace]<0)or(arr[index]<0 and arr[outOfPlace]>=0)): arr=rightRotate(arr,n,outOfPlace,index) if(index-outOfPlace>2): outOfPlace+=2 else : outOfPlace=-1 if(outOfPlace==-1): if((arr[index]>=0 and index % 2==0)or(arr[index]<0 and index % 2==1)): outOfPlace=index return arr arr=[-5,-2,5,2,4,7,1,8,0,-8] print("Given Array is:") print(arr) print("\nRearranged array is:") print(rearrange(arr,len(arr))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{-5}->union(Sequence{-2}->union(Sequence{5}->union(Sequence{2}->union(Sequence{4}->union(Sequence{7}->union(Sequence{1}->union(Sequence{8}->union(Sequence{0}->union(Sequence{ -8 }))))))))) ; execute ("Given Array is:")->display() ; execute (arr)->display() ; execute ("\nRearranged array is:")->display() ; execute (rearrange(arr, (arr)->size()))->display(); operation rightRotate(arr : OclAny, n : OclAny, outOfPlace : OclAny, cur : OclAny) : OclAny pre: true post: true activity: var temp : OclAny := arr[cur+1] ; for i : Integer.subrange(outOfPlace + 1, cur)->reverse() do ( arr[i+1] := arr[i - 1+1]) ; arr[outOfPlace+1] := temp ; return arr; operation rearrange(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: outOfPlace := -1 ; for index : Integer.subrange(0, n-1) do ( if (outOfPlace >= 0) then ( if ((arr[index+1] >= 0 & arr[outOfPlace+1] < 0) or (arr[index+1] < 0 & arr[outOfPlace+1] >= 0)) then ( arr := rightRotate(arr, n, outOfPlace, index) ; if (index - outOfPlace > 2) then ( outOfPlace := outOfPlace + 2 ) else ( outOfPlace := -1 ) ) else skip ) else skip ; if (outOfPlace = -1) then ( if ((arr[index+1] >= 0 & index mod 2 = 0) or (arr[index+1] < 0 & index mod 2 = 1)) then ( outOfPlace := index ) else skip ) else skip) ; return arr; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect S=list(input()) T=list(input()) s_dic={} for i,s in enumerate(S): if s not in s_dic.keys(): s_dic[s]=[i] else : s_dic[s].append(i) def main(): pre,n_repeat=-1,0 cur=-1 for t in T : if t not in s_dic.keys(): return-1 i=bisect.bisect_right(s_dic[t],cur) if i>=len(s_dic[t]): cur=s_dic[t][0] n_repeat+=1 else : cur=s_dic[t][i] if cur<=pre : n_repeat+=1 pre=cur return n_repeat*len(S)+cur+1 print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var S : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var T : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var s_dic : OclAny := Set{} ; for _tuple : Integer.subrange(1, (S)->size())->collect( _indx | Sequence{_indx-1, (S)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); if (s_dic.keys())->excludes(s) then ( s_dic[s+1] := Sequence{ i } ) else ( (expr (atom (name s_dic)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) )) ; skip ; execute (main())->display(); operation main() : OclAny pre: true post: true activity: var pre : OclAny := null; var n_repeat : OclAny := null; Sequence{pre,n_repeat} := Sequence{-1,0} ; var cur : int := -1 ; for t : T do ( if (s_dic.keys())->excludes(t) then ( return -1 ) else skip ; var i : OclAny := bisect.bisect_right(s_dic[t+1], cur) ; if (i->compareTo((s_dic[t+1])->size())) >= 0 then ( cur := s_dic[t+1]->first() ; n_repeat := n_repeat + 1 ) else ( cur := s_dic[t+1][i+1] ; if (cur->compareTo(pre)) <= 0 then ( n_repeat := n_repeat + 1 ) else skip ) ; var pre : int := cur) ; return n_repeat * (S)->size() + cur + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import re import math import collections import bisect import itertools import fractions import functools import copy import heapq import decimal import statistics import queue sys.setrecursionlimit(10**9) INF=10**16 MOD=10**9+7 ni=lambda : int(sys.stdin.readline()) ns=lambda : map(int,sys.stdin.readline().split()) na=lambda : list(map(int,sys.stdin.readline().split())) nb=lambda : list(map(lambda x : int(x)-1,sys.stdin.readline().split())) def main(): s=list(input()) t=collections.deque(list(input())) jump=[[0]*26 for _ in range(len(s)+1)] for i in range(len(s)-1,-1,-1): jump[i]=jump[i+1].copy() jump[i][ord(s[i])-97]=i+1 ans=0 point=0 while len(t)>0 : tmp=t.popleft() character=ord(tmp)-97 if jump[point][character]==0 and point==0 : print(-1) exit(0) point=jump[point][character] if point==0 : t.appendleft(tmp) ans+=1 print(ans*len(s)+point) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := (10)->pow(16) ; var MOD : double := (10)->pow(9) + 7 ; var ni : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var ns : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var na : Function := lambda $$ : OclAny in (((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var nb : Function := lambda $$ : OclAny in (((sys.stdin.readLine().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ))) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var t : Sequence := (((OclFile["System.in"]).readLine())->characters()) ; var jump : Sequence := Integer.subrange(0, (s)->size() + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 26))) ; for i : Integer.subrange(-1 + 1, (s)->size() - 1)->reverse() do ( jump[i+1] := jump[i + 1+1]->copy() ; jump[i+1][(s[i+1])->char2byte() - 97+1] := i + 1) ; var ans : int := 0 ; var point : int := 0 ; while (t)->size() > 0 do ( var tmp : OclAny := t->first() ; t := t->tail() ; var character : double := (tmp)->char2byte() - 97 ; if jump[point+1][character+1] = 0 & point = 0 then ( execute (-1)->display() ; exit(0) ) else skip ; point := jump[point+1][character+1] ; if point = 0 then ( t := t->prepend(tmp) ; ans := ans + 1 ) else skip) ; execute (ans * (s)->size() + point)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left import sys s=input() t=input() d={char :[]for char in 'abcdefghijklmnopqrstuvwxyz'} for i in range(len(s)): d[s[i]].append(i) cnt=0 index=0 for char in t : if not d[char]: print(-1) sys.exit() i=bisect_left(d[char],index) if i==len(d[char]): cnt+=1 index=d[char][0] else : index=d[char][i] index+=1 ans=cnt*len(s)+index print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var d : Map := 'abcdefghijklmnopqrstuvwxyz'->characters()->select(char | true)->collect(char | Map{char |-> Sequence{}})->unionAll() ; for i : Integer.subrange(0, (s)->size()-1) do ((expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var cnt : int := 0 ; var index : int := 0 ; for char : t->characters() do ( if not(d[char+1]) then ( execute (-1)->display() ; sys.exit() ) else skip ; var i : OclAny := bisect_left(d[char+1], index) ; if i = (d[char+1])->size() then ( cnt := cnt + 1 ; index := d[char+1]->first() ) else ( index := d[char+1][i+1] ) ; index := index + 1) ; var ans : int := cnt * (s)->size() + index ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin sys.setrecursionlimit(10**7) def li(): return map(int,stdin.readline().split()) def li_(): return map(lambda x : int(x)-1,stdin.readline().split()) def lf(): return map(float,stdin.readline().split()) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) from collections import defaultdict from bisect import bisect_right s=ns() t=ns() ok=True sset=set(list(s)) for ti in t : if ti not in sset : ok=False break if not ok : print(-1) else : n=len(s) charidx=defaultdict(list) for i,si in enumerate(s): charidx[si].append(i) for i,si in enumerate(s): charidx[si].append(n+i) ks=charidx.keys() move=[{ki :-1 for ki in ks}for _ in range(n)] for i,si in enumerate(s): for ki in ks : idxlist=charidx[ki] nexidx=bisect_right(idxlist,i) move[i][ki]=(idxlist[nexidx]-i)%(n+1) cur=s.index(t[: 1]) ans=cur for ti in t[1 :]: nex=move[cur][ti] ans+=nex cur=(cur+nex)% n print(ans+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stdin : OclFile := OclFile["System.in"] ; sys.setrecursionlimit((10)->pow(7)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var s : OclAny := ns() ; var t : OclAny := ns() ; var ok : boolean := true ; var sset : Set := Set{}->union(((s))) ; for ti : t do ( if (sset)->excludes(ti) then ( ok := false ; break ) else skip) ; if not(ok) then ( execute (-1)->display() ) else ( var n : int := (s)->size() ; var charidx : OclAny := defaultdict(OclType["Sequence"]) ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var si : OclAny := _tuple->at(_indx); (expr (atom (name charidx)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name si)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var si : OclAny := _tuple->at(_indx); (expr (atom (name charidx)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name si)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (name i))))))))) ))))) ; var ks : OclAny := charidx.keys() ; var move : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (ks->select(ki | true)->collect(ki | Map{ki |-> -1})->unionAll())) ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var si : OclAny := _tuple->at(_indx); for ki : ks do ( var idxlist : OclAny := charidx[ki+1] ; var nexidx : OclAny := bisect_right(idxlist, i) ; move[i+1][ki+1] := (idxlist[nexidx+1] - i) mod (n + 1))) ; var cur : int := s->indexOf(t.subrange(1,1)) - 1 ; var ans : int := cur ; for ti : t->tail() do ( var nex : OclAny := move[cur+1][ti+1] ; ans := ans + nex ; cur := (cur + nex) mod n) ; execute (ans + 1)->display() ); operation li() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation li_() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ); operation lf() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ); operation ls() : OclAny pre: true post: true activity: return stdin.readLine().split(); operation ns() : OclAny pre: true post: true activity: return stdin.readLine().rstrip(); operation lc() : OclAny pre: true post: true activity: return (ns()); operation ni() : OclAny pre: true post: true activity: return ("" + ((stdin.readLine())))->toInteger(); operation nf() : OclAny pre: true post: true activity: return ("" + ((stdin.readLine())))->toReal(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sortDiagonal(a,M,N): for i in range(M): sm=a[i][i] pos=i for j in range(i+1,N): if(sm>a[j][j]): sm=a[j][j] pos=j a[i][i],a[pos][pos]=a[pos][pos],a[i][i] for i in range(M): for j in range(N): print(a[i][j],end=" ") print() a=[[4,2],[3,1]] sortDiagonal(a,2,2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{Sequence{4}->union(Sequence{ 2 })}->union(Sequence{ Sequence{3}->union(Sequence{ 1 }) }) ; sortDiagonal(a, 2, 2); operation sortDiagonal(a : OclAny, M : OclAny, N : OclAny) pre: true post: true activity: for i : Integer.subrange(0, M-1) do ( var sm : OclAny := a[i+1][i+1] ; var pos : OclAny := i ; for j : Integer.subrange(i + 1, N-1) do ( if ((sm->compareTo(a[j+1][j+1])) > 0) then ( sm := a[j+1][j+1] ; pos := j ) else skip) ; var a[i+1][i+1] : OclAny := null; var a[pos+1][pos+1] : OclAny := null; Sequence{a[i+1][i+1],a[pos+1][pos+1]} := Sequence{a[pos+1][pos+1],a[i+1][i+1]}) ; for i : Integer.subrange(0, M-1) do ( for j : Integer.subrange(0, N-1) do ( execute (a[i+1][j+1])->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) a.sort() if n % 2==0 : print(a[n//2-1]) else : print(a[n//2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; if n mod 2 = 0 then ( execute (a[n div 2 - 1+1])->display() ) else ( execute (a[n div 2+1])->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_answer(input_list): so=input_list[0] t=input_list[1] s_len=len(so) t_i=[-1]*len(t) s=so+so s_index=0 for i in range(len(t)): index=s.find(t[i],s_index) if index<0 : break index=index % s_len t_i[i]=index s_index=index+1 s_index=s_index % s_len if-1 in t_i : return-1 t_len=len(t_i) ret=0 ret_i=0 for i in range(t_len): t1=t_i[i] ret=t1 if i=t2 : ret_i+=1 return ret_i*s_len+ret+1 if __name__=="__main__" : input_list=[] while True : try : input1=input() if not input1 : break if len(input1)==0 : break input_list.append(input1) except EOFError : break print(get_answer(input_list)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( input_list := Sequence{} ; while true do ( try ( var input1 : String := (OclFile["System.in"]).readLine() ; if not(input1 = "") then ( break ) else skip ; if (input1)->size() = 0 then ( break ) else skip ; execute ((input1) : input_list)) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))) ; execute (get_answer(input_list))->display() ) else skip; operation get_answer(input_list : OclAny) : OclAny pre: true post: true activity: var so : OclAny := input_list->first() ; var t : OclAny := input_list[1+1] ; var s_len : int := (so)->size() ; var t_i : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (t)->size()) ; var s : OclAny := so + so ; var s_index : int := 0 ; for i : Integer.subrange(0, (t)->size()-1) do ( var index : int := s->indexOf(t[i+1], s_index) - 1 ; if index < 0 then ( break ) else skip ; index := index mod s_len ; t_i[i+1] := index ; s_index := index + 1 ; s_index := s_index mod s_len) ; if (t_i)->includes(-1) then ( return -1 ) else skip ; var t_len : int := (t_i)->size() ; var ret : int := 0 ; var ret_i : int := 0 ; for i : Integer.subrange(0, t_len-1) do ( var t1 : OclAny := t_i[i+1] ; ret := t1 ; if (i->compareTo(t_len - 1)) < 0 then ( var t2 : OclAny := t_i[i + 1+1] ; if (t1->compareTo(t2)) >= 0 then ( ret_i := ret_i + 1 ) else skip ) else skip) ; return ret_i * s_len + ret + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=100005 def SieveOfEratosthenes(composite): for p in range(2,N): if p*p>N : break if(composite[p]==False): for i in range(2*p,N,p): composite[i]=True def sumOfElements(arr,n): composite=[False]*N SieveOfEratosthenes(composite) m=dict(); for i in range(n): m[arr[i]]=m.get(arr[i],0)+1 sum=0 for it in m : if(composite[m[it]]): sum+=(it) return sum if __name__=='__main__' : arr=[1,2,1,1,1,3,3,2,4] n=len(arr) print(sumOfElements(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 100005 ; skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{3}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 4 })))))))) ; n := (arr)->size() ; execute (sumOfElements(arr, n))->display() ) else skip; operation SieveOfEratosthenes(composite : OclAny) pre: true post: true activity: for p : Integer.subrange(2, N-1) do ( if (p * p->compareTo(N)) > 0 then ( break ) else skip ; if (composite[p+1] = false) then ( for i : Integer.subrange(2 * p, N-1)->select( $x | ($x - 2 * p) mod p = 0 ) do ( composite[i+1] := true) ) else skip); operation sumOfElements(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: composite := MatrixLib.elementwiseMult(Sequence{ false }, N) ; SieveOfEratosthenes(composite) ; var m : Map := (arguments ( )); ; for i : Integer.subrange(0, n-1) do ( m[arr[i+1]+1] := m.get(arr[i+1], 0) + 1) ; var sum : int := 0 ; for it : m->keys() do ( if (composite[m[it+1]+1]) then ( sum := sum + (it) ) else skip) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) def solve(n): for i in range(n): item=input() firstBit=(ord(item[0])-ord('a'))*25 if item[0]=='a' : secondBit=(ord(item[1])-ord('a')) elif item[1]>item[0]: secondBit=(ord(item[1])-ord('a')) elif item[1]toInteger() ; skip ; solve(n); operation solve(n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( var item : String := (OclFile["System.in"]).readLine() ; var firstBit : double := ((item->first())->char2byte() - ('a')->char2byte()) * 25 ; if item->first() = 'a' then ( var secondBit : double := ((item[1+1])->char2byte() - ('a')->char2byte()) ) else (if (item[1+1]->compareTo(item->first())) > 0 then ( secondBit := ((item[1+1])->char2byte() - ('a')->char2byte()) ) else (if (item[1+1]->compareTo(item->first())) < 0 then ( secondBit := ((item[1+1])->char2byte() - ('a')->char2byte()) + 1 ) else skip ) ) ; execute (StringLib.formattedString('{firstBit+secondBit}'))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solution(param): pass if __name__=='__main__' : for _ in range(int(input())): word=input() diff=ord(word[0])-ord('a') ans=((diff)*25)+(ord(word[1])-ord('a')) if word[0]>word[1]: ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var word : String := (OclFile["System.in"]).readLine() ; var diff : double := (word->first())->char2byte() - ('a')->char2byte() ; var ans : double := ((diff) * 25) + ((word[1+1])->char2byte() - ('a')->char2byte()) ; if (word->first()->compareTo(word[1+1])) > 0 then ( ans := ans + 1 ) else skip ; execute (ans)->display()) ) else skip; operation solution(param : OclAny) pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): letter=input() x,y=letter[0],letter[1] count,c=0,0 for i in range(26): if chr(97+i)==x : break c+=25 for i in range(26): if chr(97+i)==x : continue if chr(97+i)==y : count+=1 break count+=1 print(c+count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var letter : String := (OclFile["System.in"]).readLine() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{letter->first(),letter[1+1]} ; var count : OclAny := null; var c : OclAny := null; Sequence{count,c} := Sequence{0,0} ; for i : Integer.subrange(0, 26-1) do ( if (97 + i)->byte2char() = x then ( break ) else skip ; c := c + 25) ; for i : Integer.subrange(0, 26-1) do ( if (97 + i)->byte2char() = x then ( continue ) else skip ; if (97 + i)->byte2char() = y then ( count := count + 1 ; break ) else skip ; count := count + 1) ; execute (c + count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): s=input() l=list(s) p=[0,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] if p.index(l[0])!=0 : if p.index(l[1])toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var l : Sequence := (s)->characters() ; var p : Sequence := Sequence{0}->union(Sequence{'a'}->union(Sequence{'b'}->union(Sequence{'c'}->union(Sequence{'d'}->union(Sequence{'e'}->union(Sequence{'f'}->union(Sequence{'g'}->union(Sequence{'h'}->union(Sequence{'i'}->union(Sequence{'j'}->union(Sequence{'k'}->union(Sequence{'l'}->union(Sequence{'m'}->union(Sequence{'n'}->union(Sequence{'o'}->union(Sequence{'p'}->union(Sequence{'q'}->union(Sequence{'r'}->union(Sequence{'s'}->union(Sequence{'t'}->union(Sequence{'u'}->union(Sequence{'v'}->union(Sequence{'w'}->union(Sequence{'x'}->union(Sequence{'y'}->union(Sequence{ 'z' })))))))))))))))))))))))))) ; if p->indexOf(l->first()) - 1 /= 0 then ( if (p->indexOf(l[1+1]) - 1->compareTo(p->indexOf(l->first()) - 1)) < 0 then ( var sum : double := (p->indexOf(l->first()) - 1 - 1) * 25 + p->indexOf(l[1+1]) - 1 ) else ( sum := (p->indexOf(l->first()) - 1 - 1) * 25 + p->indexOf(l[1+1]) - 1 - 1 ) ) else ( sum := p->indexOf(l[1+1]) - 1 ) ; execute (sum)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import string chars=string.ascii_lowercase counter=1 dict={} for char1 in chars : for char2 in chars : if char1!=char2 : dict[char1+char2]=counter counter+=1 N=int(input()) for _ in range(N): line=input() print(dict[line]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var chars : OclAny := string.ascii_lowercase ; var counter : int := 1 ; var OclType["Map"] : OclAny := Set{} ; for char1 : chars do ( for char2 : chars do ( if char1 /= char2 then ( (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name char1))) + (expr (atom (name char2))))))))) ]) := counter ; counter := counter + 1 ) else skip)) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, N-1) do ( var line : String := (OclFile["System.in"]).readLine() ; execute ((arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name line)))))))) ]))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def frequency(fre,s,n): for i in range(0,n): string=s[i] for j in range(0,len(string)): fre[i][ord(string[j])-ord('a')]+=1 def LongestSequence(fre,n): for i in range(MAX_CHAR-1,-1,-1): mi=fre[0][i] for j in range(1,n): mi=min(fre[j][i],mi) while mi : print(chr(ord('a')+i),end="") mi-=1 if __name__=="__main__" : s=["loo","lol","olive"] n=len(s) MAX_CHAR=26 fre=[[0 for i in range(26)]for j in range(n)] frequency(fre,s,n) LongestSequence(fre,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( s := Sequence{"loo"}->union(Sequence{"lol"}->union(Sequence{ "olive" })) ; n := (s)->size() ; var MAX_CHAR : int := 26 ; fre := Integer.subrange(0, n-1)->select(j | true)->collect(j | (Integer.subrange(0, 26-1)->select(i | true)->collect(i | (0)))) ; frequency(fre, s, n) ; LongestSequence(fre, n) ) else skip; operation frequency(fre : OclAny, s : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( var string : OclAny := s[i+1] ; for j : Integer.subrange(0, (string)->size()-1) do ( fre[i+1][(string[j+1])->char2byte() - ('a')->char2byte()+1] := fre[i+1][(string[j+1])->char2byte() - ('a')->char2byte()+1] + 1)); operation LongestSequence(fre : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(-1 + 1, MAX_CHAR - 1)->reverse() do ( var mi : OclAny := fre->first()[i+1] ; for j : Integer.subrange(1, n-1) do ( mi := Set{fre[j+1][i+1], mi}->min()) ; while mi do ( execute ((('a')->char2byte() + i)->byte2char())->display() ; mi := mi - 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input().split() n=int(s[0]) m=int(s[1]) mod=10**9+7 print(pow((pow(2,m,mod)-1),n,mod)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := input().split() ; var n : int := ("" + ((s->first())))->toInteger() ; var m : int := ("" + ((s[1+1])))->toInteger() ; var mod : double := (10)->pow(9) + 7 ; execute ((((2)->pow(m) - 1))->pow(n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) print(pow(2**m-1,n,10**9+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (((2)->pow(m) - 1)->pow(n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,input().split()) S=list(input()) S_2=[S[0]] ans=0 if N==1 : print(0) else : for i in range(N-1): if S[i+1]!=S_2[-1]: S_2.append(S[i+1]) if S[i+1]==S[i]: ans+=1 num_lr=len(S_2) num=num_lr//2 if num_lr==1 : ans=ans elif num_lr % 2==0 : if num>K : ans+=(K*2) elif num<=K : ans+=((num*2)-1) elif num_lr % 2==1 : if num>=K : ans+=(K*2) elif numcollect( _x | (OclType["int"])->apply(_x) ) ; var S : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var S:= Sequence{ S->first() } : Sequence := Sequence{ S->first() } ; var ans : int := 0 ; if N = 1 then ( execute (0)->display() ) else ( for i : Integer.subrange(0, N - 1-1) do ( if S[i + 1+1] /= S execute ((S[i + 1+1]) : S.append(S[i + 1+1]))->last() then ( execute ((S[i + 1+1]) : S.append(S[i + 1+1])) ) else skip ; if S[i + 1+1] = S[i+1] then ( ans := ans + 1 ) else skip) ; var num_lr : int := (S_2)->size() ; var num : int := num_lr div 2 ; if num_lr = 1 then ( ans := ans ) else (if num_lr mod 2 = 0 then ( if (num->compareTo(K)) > 0 then ( ans := ans + (K * 2) ) else (if (num->compareTo(K)) <= 0 then ( ans := ans + ((num * 2) - 1) ) else skip) ) else (if num_lr mod 2 = 1 then ( if (num->compareTo(K)) >= 0 then ( ans := ans + (K * 2) ) else (if (num->compareTo(K)) < 0 then ( ans := ans + (num * 2) ) else skip) ) else skip ) ) ; execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkPermutation(arr,n): sum=0 ; for i in range(n): sum+=arr[i]; prefix=[0]*(n+1); prefix[0]=arr[0]; for i in range(n): prefix[i]=prefix[i-1]+arr[i]; for i in range(n-1): lsum=prefix[i]; rsum=sum-prefix[i]; l_len=i+1 r_len=n-i-1 ; if(((2*lsum)==(l_len*(l_len+1)))and((2*rsum)==(r_len*(r_len+1)))): return True ; return False ; if __name__=='__main__' : arr=[1,2,5,3,4,1,2] n=len(arr) if(checkPermutation(arr,n)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{5}->union(Sequence{3}->union(Sequence{4}->union(Sequence{1}->union(Sequence{ 2 })))))) ; n := (arr)->size() ; if (checkPermutation(arr, n)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ) else skip; operation checkPermutation(arr : OclAny, n : OclAny) pre: true post: true activity: var sum : int := 0; ; for i : Integer.subrange(0, n-1) do ( sum := sum + arr[i+1];) ; var prefix : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); ; prefix->first() := arr->first(); ; for i : Integer.subrange(0, n-1) do ( prefix[i+1] := prefix[i - 1+1] + arr[i+1];) ; for i : Integer.subrange(0, n - 1-1) do ( var lsum : OclAny := prefix[i+1]; ; var rsum : double := sum - prefix[i+1]; ; var l_len : OclAny := i + 1 ; var r_len : double := n - i - 1; ; if (((2 * lsum) = (l_len * (l_len + 1))) & ((2 * rsum) = (r_len * (r_len + 1)))) then ( return true; ) else skip) ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) M=1000000007 x=(pow(2,m,M)-1+M)% M print(pow(x,n,M)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var M : int := 1000000007 ; var x : int := ((2)->pow(m) - 1 + M) mod M ; execute ((x)->pow(n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=input().split() n=int(n) m=int(m) mod=1000000007 ; print(pow((pow(2,m,mod)-1),n,mod)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var m : int := ("" + ((m)))->toInteger() ; var mod : int := 1000000007; ; execute ((((2)->pow(m) - 1))->pow(n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,m=map(int,input().split()) mod=pow(10,9)+7 ans=pow(pow(2,m,mod)-1,n,mod) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mod : double := (10)->pow(9) + 7 ; var ans : double := ((2)->pow(m) - 1)->pow(n) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMinOpeartion(matrix,n): sumRow=[0]*n sumCol=[0]*n for i in range(n): for j in range(n): sumRow[i]+=matrix[i][j] sumCol[j]+=matrix[i][j] maxSum=0 for i in range(n): maxSum=max(maxSum,sumRow[i]) maxSum=max(maxSum,sumCol[i]) count=0 i=0 j=0 while iunion(Sequence{ 2 })}->union(Sequence{ Sequence{3}->union(Sequence{ 4 }) }) ; execute (findMinOpeartion(matrix, 2))->display() ; printMatrix(matrix, 2) ) else skip; operation findMinOpeartion(matrix : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sumRow : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var sumCol : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( sumRow[i+1] := sumRow[i+1] + matrix[i+1][j+1] ; sumCol[j+1] := sumCol[j+1] + matrix[i+1][j+1])) ; var maxSum : int := 0 ; for i : Integer.subrange(0, n-1) do ( maxSum := Set{maxSum, sumRow[i+1]}->max() ; maxSum := Set{maxSum, sumCol[i+1]}->max()) ; var count : int := 0 ; var i : int := 0 ; var j : int := 0 ; while (i->compareTo(n)) < 0 & (j->compareTo(n)) < 0 do ( var diff : OclAny := Set{maxSum - sumRow[i+1], maxSum - sumCol[j+1]}->min() ; matrix[i+1][j+1] := matrix[i+1][j+1] + diff ; sumRow[i+1] := sumRow[i+1] + diff ; sumCol[j+1] := sumCol[j+1] + diff ; count := count + diff ; if (sumRow[i+1] = maxSum) then ( i := i + 1 ) else skip ; if (sumCol[j+1] = maxSum) then ( j := j + 1 ) else skip) ; return count; operation printMatrix(matrix : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( execute (matrix[i+1][j+1])->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPossible(n,k,arr): sum=arr[0] maxVal=arr[0]; for i in range(1,n): sum+=arr[i] maxVal=max(maxVal,arr[i]) if(int(maxVal)>int((sum+k)/n)): return False return True if __name__=='__main__' : k=8 arr=[1,2,3,4] n=len(arr) if(isPossible(n,k,arr)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( k := 8 ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))) ; n := (arr)->size() ; if (isPossible(n, k, arr)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isPossible(n : OclAny, k : OclAny, arr : OclAny) : OclAny pre: true post: true activity: var sum : OclAny := arr->first() ; var maxVal : OclAny := arr->first(); ; for i : Integer.subrange(1, n-1) do ( sum := sum + arr[i+1] ; maxVal := Set{maxVal, arr[i+1]}->max()) ; if ((("" + ((maxVal)))->toInteger()->compareTo(("" + (((sum + k) / n)))->toInteger())) > 0) then ( return false ) else skip ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=[] for i in range(n): s.append(input()) s.sort() print(s[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : s)) ; s := s->sort() ; execute (s->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input() print(sorted(list(sys.stdin))[0],end='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; input() ; execute (sorted((OclFile["System.in"]))->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lst=[] for i in range(n): lst.append(input()) c="zzzzzzzzzzzzzzzzzzzzzzz" for j in lst : if jtoInteger() ; var lst : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : lst)) ; var c : String := "zzzzzzzzzzzzzzzzzzzzzzz" ; for j : lst do ( if j < c then ( c := j ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : n=int(input()) words_list=[] for i in range(n): word=input() words_list.append(word) words_list.sort() print(words_list[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var words_list : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var word : String := (OclFile["System.in"]).readLine() ; execute ((word) : words_list)) ; words_list := words_list->sort() ; execute (words_list->first())->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def summ(x): ans=0 while(x): ans+=x % 10 x//=10 return ans n=int(input()) i=10 while n>0 : i+=9 if summ(i)==10 : n-=1 print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 10 ; while n > 0 do ( i := i + 9 ; if summ(i) = 10 then ( n := n - 1 ) else skip) ; execute (i)->display(); operation summ(x : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; while (x) do ( ans := ans + x mod 10 ; x := x div 10) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) s=input() prev='e' flag=0 count=0 for i in range(n): if s[i]=='L' : if prev=='R' : if k==0 : pass elif flag==0 : flag=1 else : count+=2 k-=1 flag=0 elif prev=='L' : count+=1 else : if prev=='L' : if k==0 : pass elif flag==0 : flag=1 else : count+=2 k-=1 flag=0 elif prev=='R' : count+=1 if i==n-1 : if flag==1 : count+=1 prev=s[i] print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var prev : String := 'e' ; var flag : int := 0 ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = 'L' then ( if prev = 'R' then ( if k = 0 then ( skip ) else (if flag = 0 then ( flag := 1 ) else ( count := count + 2 ; k := k - 1 ; flag := 0 ) ) ) else (if prev = 'L' then ( count := count + 1 ) else skip) ) else ( if prev = 'L' then ( if k = 0 then ( skip ) else (if flag = 0 then ( flag := 1 ) else ( count := count + 2 ; k := k - 1 ; flag := 0 ) ) ) else (if prev = 'R' then ( count := count + 1 ) else skip) ) ; if i = n - 1 then ( if flag = 1 then ( count := count + 1 ) else skip ) else skip ; prev := s[i+1]) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) strarray=[] for i in range(n): string=str(input()) strarray.append(string) strarray.sort() print(strarray[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var strarray : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var string : String := ("" + (((OclFile["System.in"]).readLine()))) ; execute ((string) : strarray)) ; strarray := strarray->sort() ; execute (strarray->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthHarmonic(N): harmonic=1.00 for i in range(2,N+1): harmonic+=1/i return harmonic if __name__=="__main__" : N=8 print(round(nthHarmonic(N),5)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := 8 ; execute (MathLib.roundN(nthHarmonic(N), 5))->display() ) else skip; operation nthHarmonic(N : OclAny) : OclAny pre: true post: true activity: var harmonic : double := 1.00 ; for i : Integer.subrange(2, N + 1-1) do ( harmonic := harmonic + 1 / i) ; return harmonic; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() string=input() list=[i for i in string] black_before=False black_current=False groups=0 encrypting=[] number_squares=0 for i in range(len(list)): if(list[i]=="B"): black_current=True number_squares+=1 if(i==len(list)-1): groups+=1 encrypting.append(number_squares) elif(black_before==True): black_current=False groups+=1 encrypting.append(number_squares) number_squares=0 black_before=black_current print(groups) if(len(encrypting)!=0): phrase="" for i in encrypting : phrase+=str(i)+" " print(phrase) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var string : String := (OclFile["System.in"]).readLine() ; var OclType["Sequence"] : Sequence := string->characters()->select(i | true)->collect(i | (i)) ; var black_before : boolean := false ; var black_current : boolean := false ; var groups : int := 0 ; var encrypting : Sequence := Sequence{} ; var number_squares : int := 0 ; for i : Integer.subrange(0, (OclType["Sequence"])->size()-1) do ( if ([i+1] = "B") then ( black_current := true ; number_squares := number_squares + 1 ; if (i = (OclType["Sequence"])->size() - 1) then ( groups := groups + 1 ; execute ((number_squares) : encrypting) ) else skip ) else (if (black_before = true) then ( black_current := false ; groups := groups + 1 ; execute ((number_squares) : encrypting) ; number_squares := 0 ) else skip) ; black_before := black_current) ; execute (groups)->display() ; if ((encrypting)->size() /= 0) then ( var phrase : String := "" ; for i : encrypting do ( phrase := phrase + ("" + ((i))) + " ") ; execute (phrase)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input().split('W') s=list(filter(''.__ne__,s)) print(len(s)) for i in s : print(len(i),end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := input().split('W') ; s := ((s)->select( _x | (''.__ne__)->apply(_x) = true )) ; execute ((s)->size())->display() ; for i : s do ( execute ((i)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class OneDimensionalJapaneseCrossword : def __init__(self): self.lastChar='W' self.groups=[] def addChar(self,char): if char=='B' : if self.lastChar=='W' : self.groups.append(1) else : self.groups[-1]+=1 self.lastChar=char if __name__=="__main__" : n=int(input()) row=input() crossword=OneDimensionalJapaneseCrossword() for c in row : crossword.addChar(c) k=len(crossword.groups) print(k) print(*crossword.groups) ------------------------------------------------------------ OCL File: --------- class OneDimensionalJapaneseCrossword { static operation newOneDimensionalJapaneseCrossword() : OneDimensionalJapaneseCrossword pre: true post: OneDimensionalJapaneseCrossword->exists( _x | result = _x ); attribute lastChar : String := 'W'; attribute groups : Sequence := Sequence{}; operation initialise() : OneDimensionalJapaneseCrossword pre: true post: true activity: self.lastChar := 'W' ; self.groups := Sequence{}; return self; operation addChar(char : OclAny) pre: true post: true activity: if char = 'B' then ( if self.lastChar = 'W' then ( (expr (atom (name self)) (trailer . (name groups)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))) ) else ( self.groups->last() := self.groups->last() + 1 ) ) else skip ; self.lastChar := char; } class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var row : String := (OclFile["System.in"]).readLine() ; var crossword : OneDimensionalJapaneseCrossword := (OneDimensionalJapaneseCrossword.newOneDimensionalJapaneseCrossword()).initialise() ; for c : row->characters() do ( crossword.addChar(c)) ; var k : int := (crossword.groups)->size() ; execute (k)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name crossword)) (trailer . (name groups))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): nelem=int(input()) lista=input() nofgroups=0 length=0 prevblack=False strgroups="" for i in range(nelem): if(lista[i]=='B' and prevblack): length+=1 if(i==(nelem-1)): strgroups+=(str(length)+' ') elif(lista[i]=='B'): nofgroups+=1 length+=1 prevblack=True if(i==(nelem-1)): strgroups+=(str(length)+' ') elif(lista[i]=='W' and prevblack): strgroups+=(str(length)+' ') length=0 prevblack=False print(nofgroups) print(strgroups) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var nelem : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lista : String := (OclFile["System.in"]).readLine() ; var nofgroups : int := 0 ; var length : int := 0 ; var prevblack : boolean := false ; var strgroups : String := "" ; for i : Integer.subrange(0, nelem-1) do ( if (lista[i+1] = 'B' & prevblack) then ( length := length + 1 ; if (i = (nelem - 1)) then ( strgroups := strgroups + (("" + ((length))) + ' ') ) else skip ) else (if (lista[i+1] = 'B') then ( nofgroups := nofgroups + 1 ; length := length + 1 ; prevblack := true ; if (i = (nelem - 1)) then ( strgroups := strgroups + (("" + ((length))) + ' ') ) else skip ) else (if (lista[i+1] = 'W' & prevblack) then ( strgroups := strgroups + (("" + ((length))) + ' ') ; length := 0 ; prevblack := false ) else skip ) ) ) ; execute (nofgroups)->display() ; execute (strgroups)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) vec=input() last='W' stack=[] current=0 for letter in vec : if letter=='W' : if current>0 : stack.append(str(current)) current=0 elif letter=='B' : current+=1 if current>0 : stack.append(str(current)) print(len(stack)) print(" ".join(stack)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var vec : String := (OclFile["System.in"]).readLine() ; var last : String := 'W' ; var stack : Sequence := Sequence{} ; var current : int := 0 ; for letter : vec->characters() do ( if letter = 'W' then ( if current > 0 then ( execute ((("" + ((current)))) : stack) ) else skip ; current := 0 ) else (if letter = 'B' then ( current := current + 1 ) else skip)) ; if current > 0 then ( execute ((("" + ((current)))) : stack) ) else skip ; execute ((stack)->size())->display() ; execute (StringLib.sumStringsWithSeparator((stack), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) x0,y0=map(int,input().split()) c=0 for i in range(n-1): x,y=map(int,input().split()) c+=((x-x0)**2+(y-y0)**2)**0.5 x0=x y0=y print(c*k/50) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x0 : OclAny := null; var y0 : OclAny := null; Sequence{x0,y0} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; c := c + ((((x - x0))->pow(2) + ((y - y0))->pow(2)))->pow(0.5) ; var x0 : OclAny := x ; var y0 : OclAny := y) ; execute (c * k / 50)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()); x,y=map(int,input().split()); v=0 for i in range(n-1): a,b=map(int,input().split()) t=(a-x)**2+(b-y)**2 ; v+=t**0.5 x,y=a,b print(v*k/50) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var v : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : double := ((a - x))->pow(2) + ((b - y))->pow(2); v := v + (t)->pow(0.5) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{a,b}) ; execute (v * k / 50)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a,b=map(int,input().split()) m,n=[],[] for i in range(a): x,y=map(int,input().split()) m.append(x) n.append(y) distance=0 for i in range(a-1): distance+=math.sqrt(math.pow((m[i]-m[-1*a+i+1]),2)+math.pow((n[i]-n[-1*a+i+1]),2)) time=(distance/50)*b print(format(time,".9f")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := Sequence{Sequence{},Sequence{}} ; for i : Integer.subrange(0, a-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((x) : m) ; execute ((y) : n)) ; var distance : int := 0 ; for i : Integer.subrange(0, a - 1-1) do ( distance := distance + (((m[i+1] - m->reverse()->at(-(-1 * a + i + 1))))->pow(2) + ((n[i+1] - n->reverse()->at(-(-1 * a + i + 1))))->pow(2))->sqrt()) ; var time : double := (distance / 50) * b ; execute ((time + ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): i=286 j=166 k=144 while True : triangle=i*(i+1)//2 pentagon=j*(j*3-1)//2 hexagon=k*(k*2-1) minimum=min(triangle,pentagon,hexagon) if minimum==max(triangle,pentagon,hexagon): return str(triangle) if minimum==triangle : i+=1 if minimum==pentagon : j+=1 if minimum==hexagon : k+=1 if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var i : int := 286 ; var j : int := 166 ; var k : int := 144 ; while true do ( var triangle : int := i * (i + 1) div 2 ; var pentagon : int := j * (j * 3 - 1) div 2 ; var hexagon : double := k * (k * 2 - 1) ; var minimum : OclAny := Set{triangle, pentagon, hexagon}->min() ; if minimum = Set{triangle, pentagon, hexagon}->max() then ( return ("" + ((triangle))) ) else skip ; if minimum = triangle then ( i := i + 1 ) else skip ; if minimum = pentagon then ( j := j + 1 ) else skip ; if minimum = hexagon then ( k := k + 1 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input().split() n=int(a[0]) k=int(a[1]) lista=[] for l in range(n): coord=[] b=input().split() for i in b : coord.append(int(i)) lista.append(coord) total=0 for i in range(len(lista)-1): x1=lista[i][0] x2=lista[i+1][0] y1=lista[i][1] y2=lista[i+1][1] dist=((x2-x1)**2+(y2-y1)**2)**(1/2) total+=dist print(total*k/50) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := input().split() ; var n : int := ("" + ((a->first())))->toInteger() ; var k : int := ("" + ((a[1+1])))->toInteger() ; var lista : Sequence := Sequence{} ; for l : Integer.subrange(0, n-1) do ( var coord : Sequence := Sequence{} ; var b : OclAny := input().split() ; for i : b do ( execute ((("" + ((i)))->toInteger()) : coord)) ; execute ((coord) : lista)) ; var total : int := 0 ; for i : Integer.subrange(0, (lista)->size() - 1-1) do ( var x1 : OclAny := lista[i+1]->first() ; var x2 : OclAny := lista[i + 1+1]->first() ; var y1 : OclAny := lista[i+1][1+1] ; var y2 : OclAny := lista[i + 1+1][1+1] ; var dist : double := ((((x2 - x1))->pow(2) + ((y2 - y1))->pow(2)))->pow((1 / 2)) ; total := total + dist) ; execute (total * k / 50)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=list(map(int,input().split(' '))) sum=0 x0,y0=list(map(int,input().split(' '))) for i in range(n-1): x,y=list(map(int,input().split(' '))) sum+=((x-x0)**2+(y-y0)**2)**0.5 x0,y0=x,y sum*=(k/50) print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var sum : int := 0 ; var x0 : OclAny := null; var y0 : OclAny := null; Sequence{x0,y0} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n - 1-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; sum := sum + ((((x - x0))->pow(2) + ((y - y0))->pow(2)))->pow(0.5) ; var x0 : OclAny := null; var y0 : OclAny := null; Sequence{x0,y0} := Sequence{x,y}) ; sum := sum * (k / 50) ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculateAlternateSum(n): if(n<=0): return 0 fibo=[0]*(n+1) fibo[0]=0 fibo[1]=1 sum=pow(fibo[0],2)+pow(fibo[1],2) for i in range(2,n+1): fibo[i]=fibo[i-1]+fibo[i-2] if(i % 2==0): sum-=fibo[i] else : sum+=fibo[i] return sum if __name__=="__main__" : n=8 print("Alternating Fibonacci Sum upto ",n," terms: ",calculateAlternateSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 8 ; execute ("Alternating Fibonacci Sum upto ")->display() ) else skip; operation calculateAlternateSum(n : OclAny) : OclAny pre: true post: true activity: if (n <= 0) then ( return 0 ) else skip ; var fibo : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; fibo->first() := 0 ; fibo[1+1] := 1 ; var sum : double := (fibo->first())->pow(2) + (fibo[1+1])->pow(2) ; for i : Integer.subrange(2, n + 1-1) do ( fibo[i+1] := fibo[i - 1+1] + fibo[i - 2+1] ; if (i mod 2 = 0) then ( sum := sum - fibo[i+1] ) else ( sum := sum + fibo[i+1] )) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- M=3 ; N=3 ; def reverseArray(arr): for i in range(M): start=0 ; end=N-1 ; while(startunion(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))}->union(Sequence{ Sequence{7}->union(Sequence{8}->union(Sequence{ 9 })) })); ; reverseArray(arr); ) else skip; operation reverseArray(arr : OclAny) pre: true post: true activity: for i : Integer.subrange(0, M-1) do ( var start : int := 0; ; var end : double := N - 1; ; while ((start->compareTo(end)) < 0) do ( var arr[i+1][start+1] : OclAny := null; var arr[i+1][end+1] : OclAny := null; Sequence{arr[i+1][start+1],arr[i+1][end+1]} := Sequence{arr[i+1][end+1],arr[i+1][start+1]}; ; start := start + 1; ; end := end - 1;)) ; for i : Integer.subrange(0, M-1) do ( for j : Integer.subrange(0, N-1) do ( execute (arr[i+1][j+1])->display();) ; execute (->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def printUpperHalf(str): first=0 second=0 pos=0 for i in range(1,5): first=str[pos] second=str[pos+1] pos+=2 for j in range(4-i,0,-1): print("",end="") print(first,end="") for j in range(1,i): print("--",end="") print(second) def printLowerHalf(str): first=0 second=0 pos=0 for i in range(1,5): first=str[pos] second=str[pos+1] pos+=2 for j in range(1,i): print("",end="") print(first,end="") for j in range(4-i,0,-1): print("--",end="") print(second) def printDNA(str,n): for i in range(0,n): x=i % 6 if(x % 2==0): printUpperHalf(str[x]) else : printLowerHalf(str[x]) n=8 DNA=["ATTAATTA","TAGCTAGC","CGCGATAT","TAATATGC","ATCGTACG","CGTAGCAT"] printDNA(DNA,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; n := 8 ; var DNA : Sequence := Sequence{"ATTAATTA"}->union(Sequence{"TAGCTAGC"}->union(Sequence{"CGCGATAT"}->union(Sequence{"TAATATGC"}->union(Sequence{"ATCGTACG"}->union(Sequence{ "CGTAGCAT" }))))) ; printDNA(DNA, n); operation printUpperHalf(OclType["String"] : OclAny) pre: true post: true activity: var first : int := 0 ; var second : int := 0 ; var pos : int := 0 ; for i : Integer.subrange(1, 5-1) do ( first := ("" + ([pos+1])) ; second := ("" + ([pos + 1+1])) ; pos := pos + 2 ; for j : Integer.subrange(0 + 1, 4 - i)->reverse() do ( execute ("")->display()) ; execute (first)->display() ; for j : Integer.subrange(1, i-1) do ( execute ("--")->display()) ; execute (second)->display()); operation printLowerHalf(OclType["String"] : OclAny) pre: true post: true activity: first := 0 ; second := 0 ; pos := 0 ; for i : Integer.subrange(1, 5-1) do ( first := ("" + ([pos+1])) ; second := ("" + ([pos + 1+1])) ; pos := pos + 2 ; for j : Integer.subrange(1, i-1) do ( execute ("")->display()) ; execute (first)->display() ; for j : Integer.subrange(0 + 1, 4 - i)->reverse() do ( execute ("--")->display()) ; execute (second)->display()); operation printDNA(OclType["String"] : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( var x : int := i mod 6 ; if (x mod 2 = 0) then ( printUpperHalf(("" + ([x+1]))) ) else ( printLowerHalf(("" + ([x+1]))) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def remainingArea(N,M,K): while(K>0 and N>0 and M>0): if(N>M): N=N-M ; else : M=M-N ; K=K-1 ; if(N>0 and M>0): return N*M ; else : return 0 ; N=5 ; M=3 ; K=2 ; print(remainingArea(N,M,K)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 5; ; M := 3; ; K := 2; ; execute (remainingArea(N, M, K))->display();; operation remainingArea(N : OclAny, M : OclAny, K : OclAny) pre: true post: true activity: while (K > 0 & N > 0 & M > 0) do ( if ((N->compareTo(M)) > 0) then ( N := N - M; ) else ( M := M - N; ) ; K := K - 1;) ; if (N > 0 & M > 0) then ( return N * M; ) else ( return 0; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from typing import List def werify_message(n : int,words : List[str],message : str)->str : true_message=''.join(['<3','<3'.join(words),'<3']) i=0 for litera in message : if len(true_message)!=i : if litera==true_message[i]: i+=1 else : return 'yes' if i==len(true_message): return 'yes' else : return 'no' n=int(input()) words=list() for i in range(n): word=input() words.append(word) message=input() print(werify_message(n,words,message)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var words : Sequence := () ; for i : Integer.subrange(0, n-1) do ( var word : String := (OclFile["System.in"]).readLine() ; execute ((word) : words)) ; var message : String := (OclFile["System.in"]).readLine() ; execute (werify_message(n, words, message))->display(); operation werify_message(n : int, words : List[OclType["String"]+1], message : String) : String pre: true post: true activity: var true_message : String := StringLib.sumStringsWithSeparator((Sequence{'<3'}->union(Sequence{StringLib.sumStringsWithSeparator((words), '<3')}->union(Sequence{ '<3' }))), '') ; var i : int := 0 ; for litera : message->characters() do ( if (true_message)->size() /= i then ( if litera = true_message[i+1] then ( i := i + 1 ) else skip ) else ( return 'yes' )) ; if i = (true_message)->size() then ( return 'yes' ) else ( return 'no' ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans='' flag=0 for i in range(n): s=input() ans+='<3'+s ans+='<3' s=input() j=0 for i in range(len(ans)): while jtoInteger() ; var ans : String := '' ; var flag : int := 0 ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; ans := ans + '<3' + s) ; ans := ans + '<3' ; s := (OclFile["System.in"]).readLine() ; var j : int := 0 ; for i : Integer.subrange(0, (ans)->size()-1) do ( while (j->compareTo((s)->size())) < 0 & s[j+1] /= ans[i+1] do ( j := j + 1) ; if j = (s)->size() then ( flag := 1 ; break ) else skip ; j := j + 1) ; if flag = 0 then ( execute ("yes")->display() ) else ( execute ("no")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(sys.stdin.readline().rstrip("\n")) message="<3" for i in range(n): x=sys.stdin.readline().rstrip("\n") message+=x+"<3" sent=sys.stdin.readline().rstrip("\n") ind=0 correct=False for i in sent : if i==message[ind]: ind+=1 if ind>=len(message): correct=True break if correct : print("yes") else : print("no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + ((sys.stdin.readLine().rstrip("\n"))))->toInteger() ; var message : String := "<3" ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := sys.stdin.readLine().rstrip("\n") ; message := message + x + "<3") ; var sent : OclAny := sys.stdin.readLine().rstrip("\n") ; var ind : int := 0 ; var correct : boolean := false ; for i : sent do ( if i = message[ind+1] then ( ind := ind + 1 ) else skip ; if (ind->compareTo((message)->size())) >= 0 then ( correct := true ; break ) else skip) ; if correct then ( execute ("yes")->display() ) else ( execute ("no")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- base=[] for _ in range((int)(input())): base.append('<'); base.append('3'); temp=(list)(input()) for x in temp : base.append(x) str=input() base.append('<'); base.append('3'); ptr=0 for i in str : if ptrcharacters() do ( if (ptr->compareTo((base)->size())) < 0 & i = base[ptr+1] then ( ptr := ptr + 1 ) else skip) ; execute (if ptr = (base)->size() then "yes" else "no" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxPrimefactorNum(N): if(N<2): return 0 ; arr=[True]*(N+1); prod=1 ; res=0 ; p=2 ; while(p*p<=N): if(arr[p]==True): for i in range(p*2,N+1,p): arr[i]=False ; prod*=p ; if(prod>N): return res ; res+=1 ; p+=1 ; return res ; N=500 ; print(maxPrimefactorNum(N)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 500; ; execute (maxPrimefactorNum(N))->display();; operation maxPrimefactorNum(N : OclAny) pre: true post: true activity: if (N < 2) then ( return 0; ) else skip ; var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (N + 1)); ; var prod : int := 1; ; var res : int := 0; ; var p : int := 2; ; while ((p * p->compareTo(N)) <= 0) do ( if (arr[p+1] = true) then ( for i : Integer.subrange(p * 2, N + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( arr[i+1] := false;) ; prod := prod * p; ; if ((prod->compareTo(N)) > 0) then ( return res; ) else skip ; res := res + 1; ) else skip ; p := p + 1;) ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=[] for i in range(int(input())): s.append(input()) s="<3"+'<3'.join(s)+"<3" cur=0 t=input() for i in t : if i==s[cur]: cur+=1 if cur==len(s): break print('yes' if cur==len(s)else 'no') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := Sequence{} ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (((OclFile["System.in"]).readLine()) : s)) ; s := "<3" + StringLib.sumStringsWithSeparator((s), '<3') + "<3" ; var cur : int := 0 ; var t : String := (OclFile["System.in"]).readLine() ; for i : t->characters() do ( if i = s[cur+1] then ( cur := cur + 1 ) else skip ; if cur = (s)->size() then ( break ) else skip) ; execute (if cur = (s)->size() then 'yes' else 'no' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def oddDays(N): hund1=N//100 hund4=N//400 leap=N>>2 ordd=N-leap if(hund1): ordd+=hund1 leap-=hund1 if(hund4): ordd-=hund4 leap+=hund4 days=ordd+leap*2 odd=days % 7 return odd N=100 print(oddDays(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 100 ; execute (oddDays(N))->display(); operation oddDays(N : OclAny) : OclAny pre: true post: true activity: var hund1 : int := N div 100 ; var hund4 : int := N div 400 ; var leap : int := N /(2->pow(2)) ; var ordd : double := N - leap ; if (hund1) then ( ordd := ordd + hund1 ; leap := leap - hund1 ) else skip ; if (hund4) then ( ordd := ordd - hund4 ; leap := leap + hund4 ) else skip ; var days : OclAny := ordd + leap * 2 ; var odd : int := days mod 7 ; return odd; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : N=3 N-=1 r=5 for i in range(r): if i<=r//2 : count=N+1 for j in range(i+1): N+=1 print(str(N),end=" ") print() else : N=count-(r-i) count=N for j in range(i,r): print(str(N),end=" ") N+=1 print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var N : int := 3 ; N := N - 1 ; var r : int := 5 ; for i : Integer.subrange(0, r-1) do ( if (i->compareTo(r div 2)) <= 0 then ( var count : int := N + 1 ; for j : Integer.subrange(0, i + 1-1) do ( N := N + 1 ; execute (("" + ((N))))->display()) ; execute (->display() ) else ( N := count - (r - i) ; count := N ; for j : Integer.subrange(i, r-1) do ( execute (("" + ((N))))->display() ; N := N + 1) ; execute (->display() )) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.buffer.readline def process(S): lower_counts=[0 for i in range(26)] upper_counts=0 for c in S : if 'a'<=c<='z' : lower_counts[ord(c)-ord('a')]+=1 elif c=='B' : upper_counts+=1 target=[0 for i in range(26)] target1=0 for c in 'Bulbasaur' : if 'a'<=c<='z' : target[ord(c)-ord('a')]+=1 else : target1+=1 answer=float('inf') for i in range(26): if target[i]>0 : answer=min(answer,lower_counts[i]//target[i]) answer=min(answer,upper_counts//target1) print(answer) return S=input().decode().strip() process(S) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := sys.stdin.buffer.readline ; skip ; S := input().decode()->trim() ; process(S); operation process(S : OclAny) pre: true post: true activity: var lower_counts : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | (0)) ; var upper_counts : int := 0 ; for c : S do ( if 'a' <= c & (c <= 'z') then ( lower_counts[(c)->char2byte() - ('a')->char2byte()+1] := lower_counts[(c)->char2byte() - ('a')->char2byte()+1] + 1 ) else (if c = 'B' then ( upper_counts := upper_counts + 1 ) else skip)) ; var target : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | (0)) ; var target1 : int := 0 ; for c : 'Bulbasaur'->characters() do ( if 'a' <= c & (c <= 'z') then ( target[(c)->char2byte() - ('a')->char2byte()+1] := target[(c)->char2byte() - ('a')->char2byte()+1] + 1 ) else ( target1 := target1 + 1 )) ; var answer : double := ("" + (('inf')))->toReal() ; for i : Integer.subrange(0, 26-1) do ( if target[i+1] > 0 then ( answer := Set{answer, lower_counts[i+1] div target[i+1]}->min() ) else skip) ; answer := Set{answer, upper_counts div target1}->min() ; execute (answer)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numberOfTriangles(n): ans=2*(pow(3,n))-1 ; return ans ; n=2 print(numberOfTriangles(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 2 ; execute (numberOfTriangles(n))->display(); operation numberOfTriangles(n : OclAny) pre: true post: true activity: var ans : double := 2 * ((3)->pow(n)) - 1; ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: a=s.split() n=sum(int(x)% 2 for x in a) print('YNeos'[n==2 or n>2 and '0' in a[: 3]: : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var a : OclAny := s.split() ; var n : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) % (expr (atom (number (integer 2)))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a))))))))->sum() ; execute ('YNeos'(subscript (test (logical_test (logical_test (comparison (comparison (expr (atom (name n)))) == (comparison (expr (atom (number (integer 2))))))) or (logical_test (logical_test (comparison (comparison (expr (atom (name n)))) > (comparison (expr (atom (number (integer 2))))))) and (logical_test (comparison (comparison (expr (atom '0'))) in (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (number (integer 3))))))))) ]))))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(0,int(input())): v=list(map(int,input().split())) c1=sum([i % 2 for i in v])<2 v2=[v[0]-1,v[1]-1,v[2]-1,v[3]+3] c2=all(v[:-1])>0 and sum([i % 2 for i in v2])<2 if c1 or c2 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var v : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c1 : boolean := (v->select(i | true)->collect(i | (i mod 2)))->sum() < 2 ; var v2 : Sequence := Sequence{v->first() - 1}->union(Sequence{v[1+1] - 1}->union(Sequence{v[2+1] - 1}->union(Sequence{ v[3+1] + 3 }))) ; var c2 : boolean := (v->front())->forAll( _x | _x = true ) > 0 & (v2->select(i | true)->collect(i | (i mod 2)))->sum() < 2 ; if c1 or c2 then ( execute ("Yes")->display() ) else ( execute ("No")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : arr=list(map(int,input().split())) q=0 ans='No' w=0 e=0 for i in arr : if i % 2 : q+=1 if q==0 or q==1 : ans='Yes' for j in arr[: 3]: if j % 2==0 : w+=1 if j : e+=1 if arr[-1]% 2==0 and e==3 : w+=1 if w==0 or w==1 and e==3 : ans='Yes' print(ans) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : int := 0 ; var ans : String := 'No' ; var w : int := 0 ; var e : int := 0 ; for i : arr do ( if i mod 2 then ( q := q + 1 ) else skip) ; if q = 0 or q = 1 then ( ans := 'Yes' ) else skip ; for j : arr.subrange(1,3) do ( if j mod 2 = 0 then ( w := w + 1 ) else skip ; if j then ( e := e + 1 ) else skip) ; if arr->last() mod 2 = 0 & e = 3 then ( w := w + 1 ) else skip ; if w = 0 or w = 1 & e = 3 then ( ans := 'Yes' ) else skip ; execute (ans)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(r,g,b,w): return False if r % 2+g % 2+b % 2+w % 2>1 else True if __name__=='__main__' : T=int(input()) for ttt in range(T): r,g,b,w=map(int,input().split()) if check(r,g,b,w): print("Yes") elif r>0 and g>0 and b>0 and check(r-1,g-1,b-1,w+1): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for ttt : Integer.subrange(0, T-1) do ( Sequence{r,g,b,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if check(r, g, b, w) then ( execute ("Yes")->display() ) else (if r > 0 & g > 0 & b > 0 & check(r - 1, g - 1, b - 1, w + 1) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) ) ) else skip; operation check(r : OclAny, g : OclAny, b : OclAny, w : OclAny) : OclAny pre: true post: true activity: return if r mod 2 + g mod 2 + b mod 2 + w mod 2 > 1 then false else true endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a=list(map(int,input().split())) od=0 ev=0 for i in a : if i % 2==0 : ev+=1 else : od+=1 if ev>=3 or(od>=3 and 0 not in a[: 3]): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var od : int := 0 ; var ev : int := 0 ; for i : a do ( if i mod 2 = 0 then ( ev := ev + 1 ) else ( od := od + 1 )) ; if ev >= 3 or (od >= 3 & (a.subrange(1,3))->excludes(0)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def checkDivisors(a,n): X=max(a) b=[] for i in range(1,int(sqrt(X))+1): if(X % i==0): b.append(i) if(X//i!=i): b.append(X//i) if(len(b)!=n): return False a.sort(reverse=False) b.sort(reverse=False) for i in range(n): if(b[i]!=a[i]): return False return True if __name__=='__main__' : arr=[8,1,2,12,48,6,4,24,16,3] N=len(arr) if(checkDivisors(arr,N)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var arr : Sequence := Sequence{8}->union(Sequence{1}->union(Sequence{2}->union(Sequence{12}->union(Sequence{48}->union(Sequence{6}->union(Sequence{4}->union(Sequence{24}->union(Sequence{16}->union(Sequence{ 3 }))))))))) ; var N : int := (arr)->size() ; if (checkDivisors(arr, N)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation checkDivisors(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var X : OclAny := (a)->max() ; var b : Sequence := Sequence{} ; for i : Integer.subrange(1, ("" + ((sqrt(X))))->toInteger() + 1-1) do ( if (X mod i = 0) then ( execute ((i) : b) ; if (X div i /= i) then ( execute ((X div i) : b) ) else skip ) else skip) ; if ((b)->size() /= n) then ( return false ) else skip ; a := a->sort() ; b := b->sort() ; for i : Integer.subrange(0, n-1) do ( if (b[i+1] /= a[i+1]) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) o="" for i in range(1,n+1): if(i % 3)==0 : o=o+" "+str(i) else : x=i while x>0 : if(x % 10)==3 : o=o+" "+str(i) break x//=10 print(o) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var o : String := "" ; for i : Integer.subrange(1, n + 1-1) do ( if (i mod 3) = 0 then ( o := o + " " + ("" + ((i))) ) else ( var x : OclAny := i ; while x > 0 do ( if (x mod 10) = 3 then ( o := o + " " + ("" + ((i))) ; break ) else skip ; x := x div 10) )) ; execute (o)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) tmp=' ' for i in range(1,n+1): str_i=str(i) if i % 3==0 or str_i.find('3')!=-1 : tmp+=str_i+' ' print(tmp[:-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var tmp : String := ' ' ; for i : Integer.subrange(1, n + 1-1) do ( var str_i : String := ("" + ((i))) ; if i mod 3 = 0 or str_i->indexOf('3') - 1 /= -1 then ( tmp := tmp + str_i + ' ' ) else skip) ; execute (tmp->front())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) _list=list(range(1,n+1)) for x in _list : if x % 3==0 or any(list(map(lambda x : x==3,list(map(int,list(str(x))))))): print(' %d' % x,end='') print() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var _list : Sequence := (Integer.subrange(1, n + 1-1)) ; for x : _list do ( if x mod 3 = 0 or ((((((("" + ((x))))->characters())->collect( _x | (OclType["int"])->apply(_x) )))->collect( _x | (lambda x : OclAny in (x = 3))->apply(_x) )))->exists( _x | _x = true ) then ( execute (StringLib.format(' %d',x))->display() ) else skip) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=1 x=i n=int(input()) while i<=n : x=i check=False while True : if x % 3==0 and check==False : print(" %s" % i,end="") break elif x % 10==3 : print(" %s" % i,end="") break else : x/=10 x=int(x) check=True if x<=0 : break i+=1 print("") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : int := 1 ; var x : int := i ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (i->compareTo(n)) <= 0 do ( x := i ; var check : boolean := false ; while true do ( if x mod 3 = 0 & check = false then ( execute (StringLib.format(" %s",i))->display() ; break ) else (if x mod 10 = 3 then ( execute (StringLib.format(" %s",i))->display() ; break ) else ( x := x / 10 ; x := ("" + ((x)))->toInteger() ; check := true ; if x <= 0 then ( break ) else skip ) ) ) ; i := i + 1) ; execute ("")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a="Bulbsar" A=input() D={"B" : 0,"u" : 0,"l" : 0,"b" : 0,"s" : 0,"a" : 0,"r" : 0} for k in A : if k in a : D[k]+=1 D["a"]//=2 D["u"]//=2 print(min(D.values())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := "Bulbsar" ; var A : String := (OclFile["System.in"]).readLine() ; var D : Map := Map{ "B" |-> 0 }->union(Map{ "u" |-> 0 }->union(Map{ "l" |-> 0 }->union(Map{ "b" |-> 0 }->union(Map{ "s" |-> 0 }->union(Map{ "a" |-> 0 }->union(Map{ "r" |-> 0 })))))) ; for k : A->characters() do ( if (a)->characters()->includes(k) then ( D[k+1] := D[k+1] + 1 ) else skip) ; D->at("a") := D->at("a") div 2 ; D->at("u") := D->at("u") div 2 ; execute ((D.values())->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) for i in range(3,n+1): if i % 3==0 or '3' in str(i): print('',i,end='') print() if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(3, n + 1-1) do ( if i mod 3 = 0 or (("" + ((i))))->includes('3') then ( execute ('')->display() ) else skip) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd as __gcd from collections import deque as queue def minStepsNeeded(k,d1,d2,x): gcd=__gcd(d1,d2) if((k-x)% gcd!=0): return-1 q=queue() visited=dict() q.appendleft([k,0]) visited[k]=1 while(len(q)>0): sr=q.pop() s,stp=sr[0],sr[1] if(s==x): return stp if(s+d1 not in visited): q.appendleft([(s+d1),stp+1]) visited[(s+d1)]=1 if(s+d2 not in visited): q.appendleft([(s+d2),stp+1]) visited[(s+d2)]=1 if(s-d1 not in visited): q.appendleft([(s-d1),stp+1]) visited[(s-d1)]=1 if(s-d2 not in visited): q.appendleft([(s-d2),stp+1]) visited[(s-d2)]=1 k=10 d1=4 d2=6 x=8 print(minStepsNeeded(k,d1,d2,x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; k := 10 ; d1 := 4 ; d2 := 6 ; x := 8 ; execute (minStepsNeeded(k, d1, d2, x))->display(); operation minStepsNeeded(k : OclAny, d1 : OclAny, d2 : OclAny, x : OclAny) : OclAny pre: true post: true activity: var gcd : OclAny := __gcd(d1, d2) ; if ((k - x) mod gcd /= 0) then ( return -1 ) else skip ; var q : OclAny := queue() ; var visited : Map := (arguments ( )) ; q := q->prepend(Sequence{k}->union(Sequence{ 0 })) ; visited[k+1] := 1 ; while ((q)->size() > 0) do ( var sr : OclAny := q->last() ; q := q->front() ; var s : OclAny := null; var stp : OclAny := null; Sequence{s,stp} := Sequence{sr->first(),sr[1+1]} ; if (s = x) then ( return stp ) else skip ; if ((visited)->excludes(s + d1)) then ( q := q->prepend(Sequence{(s + d1)}->union(Sequence{ stp + 1 })) ; visited[(s + d1)+1] := 1 ) else skip ; if ((visited)->excludes(s + d2)) then ( q := q->prepend(Sequence{(s + d2)}->union(Sequence{ stp + 1 })) ; visited[(s + d2)+1] := 1 ) else skip ; if ((visited)->excludes(s - d1)) then ( q := q->prepend(Sequence{(s - d1)}->union(Sequence{ stp + 1 })) ; visited[(s - d1)+1] := 1 ) else skip ; if ((visited)->excludes(s - d2)) then ( q := q->prepend(Sequence{(s - d2)}->union(Sequence{ stp + 1 })) ; visited[(s - d2)+1] := 1 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countFactor(P,X): if(Xdisplay();; operation countFactor(P : OclAny, X : OclAny) pre: true post: true activity: if ((X->compareTo(P)) < 0) then ( return 0; ) else skip ; return (X div P + countFactor(P, X div P));; operation findSmallestX(Y : OclAny) pre: true post: true activity: var low : int := 0; ; var high : double := 5 * Y; ; var N : int := 0; ; while ((low->compareTo(high)) <= 0) do ( var mid : int := (high + low) div 2; ; if ((countFactor(5, mid)->compareTo(Y)) < 0) then ( low := mid + 1; ) else ( N := mid; ; high := mid - 1; )) ; return N;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_K=15 fac=[1 for i in range(MAX_K)] def factorial(k): fac[0]=1 for i in range(1,k+2): fac[i]=(i*fac[i-1]) def bin(a,b): ans=fac[a]//(fac[a-b]*fac[b]) return ans def sumofn(n,k): p=0 num1,temp=1,1 arr=[1 for i in range(1000)] for j in range(1,k+1): if j==1 : num1=(n*(n+1))//2 arr[p]=num1 p+=1 else : temp=pow(n+1,j+1)-1-n for s in range(1,j): temp=temp-(arr[j-s-1]*bin(j+1,s+1)) temp=temp//(j+1) arr[p]=temp p+=1 temp=arr[p-1] return temp n,k=5,2 factorial(k) print(sumofn(n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_K : int := 15 ; var fac : Sequence := Integer.subrange(0, MAX_K-1)->select(i | true)->collect(i | (1)) ; skip ; skip ; skip ; Sequence{n,k} := Sequence{5,2} ; factorial(k) ; execute (sumofn(n, k))->display(); operation factorial(k : OclAny) pre: true post: true activity: fac->first() := 1 ; for i : Integer.subrange(1, k + 2-1) do ( fac[i+1] := (i * fac[i - 1+1])); operation bin(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var ans : int := fac[a+1] div (fac[a - b+1] * fac[b+1]) ; return ans; operation sumofn(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var p : int := 0 ; var num1 : OclAny := null; var temp : OclAny := null; Sequence{num1,temp} := Sequence{1,1} ; var arr : Sequence := Integer.subrange(0, 1000-1)->select(i | true)->collect(i | (1)) ; for j : Integer.subrange(1, k + 1-1) do ( if j = 1 then ( var num1 : int := (n * (n + 1)) div 2 ; arr[p+1] := num1 ; p := p + 1 ) else ( var temp : double := (n + 1)->pow(j + 1) - 1 - n ; for s : Integer.subrange(1, j-1) do ( temp := temp - (arr[j - s - 1+1] * bin(j + 1, s + 1))) ; temp := temp div (j + 1) ; arr[p+1] := temp ; p := p + 1 )) ; temp := arr[p - 1+1] ; return temp; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def reachTheNums(nums,k,d1,d2,n): ans=[0 for i in range(n)] gcd=mt.gcd(d1,d2) for i in range(n): x=nums[i]-k if(x % gcd==0): ans[i]=1 else : ans[i]=0 for i in range(n): print(ans[i],end=" ") nums=[9,4] n=len(nums) k=8 d1,d2=3,2 reachTheNums(nums,k,d1,d2,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; nums := Sequence{9}->union(Sequence{ 4 }) ; n := (nums)->size() ; k := 8 ; Sequence{d1,d2} := Sequence{3,2} ; reachTheNums(nums, k, d1, d2, n); operation reachTheNums(nums : OclAny, k : OclAny, d1 : OclAny, d2 : OclAny, n : OclAny) pre: true post: true activity: var ans : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var gcd : int := mt.gcd(d1, d2) ; for i : Integer.subrange(0, n-1) do ( var x : double := nums[i+1] - k ; if (x mod gcd = 0) then ( ans[i+1] := 1 ) else ( ans[i+1] := 0 )) ; for i : Integer.subrange(0, n-1) do ( execute (ans[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def subArray(arr,n): for i in range(0,n): for j in range(i,n): for k in range(i,j+1): print(arr[k],end="") print("\n",end="") arr=[1,2,3,4] n=len(arr) print("All Non-empty Subarrays") subArray(arr,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))) ; n := (arr)->size() ; execute ("All Non-empty Subarrays")->display() ; subArray(arr, n);; operation subArray(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i, n-1) do ( for k : Integer.subrange(i, j + 1-1) do ( execute (arr[k+1])->display()) ; execute ("\n")->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,S=map(int,input().split()) A=list(map(int,input().split())) MOD=998244353 dp=[[0]*(S+1)for i in range(N+1)] dp[0][0]=1 for i in range(N): for j in range(S+1): dp[i+1][j]=(dp[i][j]*2+dp[i+1][j])% MOD if j+A[i]<=S : dp[i+1][j+A[i]]=(dp[i][j]+dp[i+1][j+A[i]])% MOD print(dp[N][S]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var S : OclAny := null; Sequence{N,S} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var MOD : int := 998244353 ; var dp : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (S + 1)))) ; dp->first()->first() := 1 ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, S + 1-1) do ( dp[i + 1+1][j+1] := (dp[i+1][j+1] * 2 + dp[i + 1+1][j+1]) mod MOD ; if (j + A[i+1]->compareTo(S)) <= 0 then ( dp[i + 1+1][j + A[i+1]+1] := (dp[i+1][j+1] + dp[i + 1+1][j + A[i+1]+1]) mod MOD ) else skip)) ; execute (dp[N+1][S+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import copy import heapq import sys import itertools import math import queue input=sys.stdin.readline sys.setrecursionlimit(1000000) mod=998244353 def read_values(): return map(int,input().split()) def read_index(): return map(lambda x : int(x)-1,input().split()) def read_list(): return list(read_values()) def read_lists(N): return[read_list()for n in range(N)] def main(): N,S=read_values() A=read_list() dp=[[0 for _ in range(S+1)]for _ in range(N+1)] dp[0][0]=1 for i,a in enumerate(A): for s in range(S+1): dp[i+1][s]+=2*dp[i][s] dp[i+1][s]%=mod if s+a<=S : dp[i+1][s+a]+=dp[i][s] dp[i+1][s+a]%=mod print(dp[N][S]) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit(1000000) ; var mod : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation read_values() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation read_index() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ); operation read_list() : OclAny pre: true post: true activity: return (read_values()); operation read_lists(N : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, N-1)->select(n | true)->collect(n | (read_list())); operation main() pre: true post: true activity: var S : OclAny := null; Sequence{N,S} := read_values() ; var A : OclAny := read_list() ; var dp : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, S + 1-1)->select(_anon | true)->collect(_anon | (0)))) ; dp->first()->first() := 1 ; for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); for s : Integer.subrange(0, S + 1-1) do ( dp[i + 1+1][s+1] := dp[i + 1+1][s+1] + 2 * dp[i+1][s+1] ; dp[i + 1+1][s+1] := dp[i + 1+1][s+1] mod mod ; if (s + a->compareTo(S)) <= 0 then ( dp[i + 1+1][s + a+1] := dp[i + 1+1][s + a+1] + dp[i+1][s+1] ; dp[i + 1+1][s + a+1] := dp[i + 1+1][s + a+1] mod mod ) else skip)) ; execute (dp[N+1][S+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod1,mod2=10**9+7,998244353 mod=mod2 n,s=map(int,input().split()) dp=[0]*(s+1) dp[0]=1 for a in map(int,input().split()): dp=[(2*dp[i]+(0 if ipow(9) + 7,998244353} ; var mod : OclAny := mod2 ; var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (s + 1)) ; dp->first() := 1 ; for a : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( dp := Integer.subrange(0, s + 1-1)->select(i | true)->collect(i | ((2 * dp[i+1] + (if (i->compareTo(a)) < 0 then 0 else dp[i - a+1] endif)) mod mod))) ; execute (dp->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.readline().strip() from functools import lru_cache sys.setrecursionlimit(10**9) mod=998244353 def main(): N,S=map(int,input().split()) A=list(map(int,input().split())) dp=[[0]*(S+1)for _ in range(N)] dp[0][0]=1 for n in range(1,N): dp[n][0]=(dp[n-1][0]*2+1)% mod for s in range(1,S+1): dp[0][s]=1 if s==A[0]else 0 for n in range(1,N): for s in range(1,S+1): dp[n][s]=(dp[n-1][s]*2+dp[n-1][s-A[n]])if s>=A[n]else dp[n-1][s]*2 if A[n]==s : dp[n][s]+=1 dp[n][s]%=mod print(dp[N-1][S]) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var mod : int := 998244353 ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation main() pre: true post: true activity: var N : OclAny := null; var S : OclAny := null; Sequence{N,S} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dp : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (S + 1)))) ; dp->first()->first() := 1 ; for n : Integer.subrange(1, N-1) do ( dp[n+1]->first() := (dp[n - 1+1]->first() * 2 + 1) mod mod) ; for s : Integer.subrange(1, S + 1-1) do ( dp->first()[s+1] := if s = A->first() then 1 else 0 endif) ; for n : Integer.subrange(1, N-1) do ( for s : Integer.subrange(1, S + 1-1) do ( dp[n+1][s+1] := if (s->compareTo(A[n+1])) >= 0 then (dp[n - 1+1][s+1] * 2 + dp[n - 1+1][s - A[n+1]+1]) else dp[n - 1+1][s+1] * 2 endif ; if A[n+1] = s then ( dp[n+1][s+1] := dp[n+1][s+1] + 1 ) else skip ; dp[n+1][s+1] := dp[n+1][s+1] mod mod)) ; execute (dp[N - 1+1][S+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- Q=998244353 def main(): N,S=map(int,input().split()) A=list(map(int,input().split())) invtwo=pow(2,Q-2,Q) dp=[pow(2,N,Q)]+[0]*S for i in range(N): a=A[i] for i in range(S,a-1,-1): if dp[i-a]>0 : dp[i]+=dp[i-a]*invtwo % Q dp[i]%=Q print(dp[S]) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Q : int := 998244353 ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var S : OclAny := null; Sequence{N,S} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var invtwo : double := (2)->pow(Q - 2) ; var dp : Sequence := Sequence{ (2)->pow(N) }->union(MatrixLib.elementwiseMult(Sequence{ 0 }, S)) ; for i : Integer.subrange(0, N-1) do ( var a : OclAny := A[i+1] ; for i : Integer.subrange(a - 1 + 1, S)->reverse() do ( if dp[i - a+1] > 0 then ( dp[i+1] := dp[i+1] + dp[i - a+1] * invtwo mod Q ; dp[i+1] := dp[i+1] mod Q ) else skip)) ; execute (dp[S+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() w=input() c=[w.count(l)for l in "Bulbasr"] c[1]//=2 c[4]//=2 print(min(c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var w : String := (OclFile["System.in"]).readLine() ; var c : Sequence := "Bulbasr"->characters()->select(l | true)->collect(l | (w->count(l))) ; c[1+1] := c[1+1] div 2 ; c[4+1] := c[4+1] div 2 ; execute ((c)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def productArray(arr,n): if n==1 : print(0) return i,temp=1,1 prod=[1 for i in range(n)] for i in range(n): prod[i]=temp temp*=arr[i] temp=1 for i in range(n-1,-1,-1): prod[i]*=temp temp*=arr[i] for i in range(n): print(prod[i],end=" ") return arr=[10,3,5,6,2] n=len(arr) print("The product array is: n") productArray(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{10}->union(Sequence{3}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 2 })))) ; n := (arr)->size() ; execute ("The product array is: n")->display() ; productArray(arr, n); operation productArray(arr : OclAny, n : OclAny) pre: true post: true activity: if n = 1 then ( execute (0)->display() ; return ) else skip ; var i : OclAny := null; var temp : OclAny := null; Sequence{i,temp} := Sequence{1,1} ; var prod : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (1)) ; for i : Integer.subrange(0, n-1) do ( prod[i+1] := temp ; temp := temp * arr[i+1]) ; var temp : int := 1 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( prod[i+1] := prod[i+1] * temp ; temp := temp * arr[i+1]) ; for i : Integer.subrange(0, n-1) do ( execute (prod[i+1])->display()) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def productArray(arr,n): if(n==1): print(0) return left=[0]*n right=[0]*n prod=[0]*n left[0]=1 right[n-1]=1 for i in range(1,n): left[i]=arr[i-1]*left[i-1] for j in range(n-2,-1,-1): right[j]=arr[j+1]*right[j+1] for i in range(n): prod[i]=left[i]*right[i] for i in range(n): print(prod[i],end=' ') arr=[10,3,5,6,2] n=len(arr) print("The product array is:") productArray(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{10}->union(Sequence{3}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 2 })))) ; n := (arr)->size() ; execute ("The product array is:")->display() ; productArray(arr, n); operation productArray(arr : OclAny, n : OclAny) pre: true post: true activity: if (n = 1) then ( execute (0)->display() ; return ) else skip ; var left : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var right : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var prod : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; left->first() := 1 ; right[n - 1+1] := 1 ; for i : Integer.subrange(1, n-1) do ( left[i+1] := arr[i - 1+1] * left[i - 1+1]) ; for j : Integer.subrange(-1 + 1, n - 2)->reverse() do ( right[j+1] := arr[j + 1+1] * right[j + 1+1]) ; for i : Integer.subrange(0, n-1) do ( prod[i+1] := left[i+1] * right[i+1]) ; for i : Integer.subrange(0, n-1) do ( execute (prod[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys X,Y=map(int,input().split()) for a in range(101): for b in range(101): if a+b==X and 2*a+4*b==Y : print("Yes") sys.exit() print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var X : OclAny := null; var Y : OclAny := null; Sequence{X,Y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for a : Integer.subrange(0, 101-1) do ( for b : Integer.subrange(0, 101-1) do ( if a + b = X & 2 * a + 4 * b = Y then ( execute ("Yes")->display() ; sys.exit() ) else skip)) ; execute ("No")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np def is_integer(n): try : float(n) except ValueError : return False else : return float(n).is_integer() X,Y=map(int,input().split()) mat=np.array([[2,-0.5],[-1,0.5]]) matb=np.array([[X],[Y]]) Ans=np.dot(mat,matb) if(is_integer(Ans[0])is True)and(is_integer(Ans[1])is True): if(Ans[0]>=0)and(Ans[1]>=0): print("Yes") else : print("No") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var X : OclAny := null; var Y : OclAny := null; Sequence{X,Y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mat : Sequence := (Sequence{Sequence{2}->union(Sequence{ -0.5 })}->union(Sequence{ Sequence{-1}->union(Sequence{ 0.5 }) })) ; var matb : Sequence := (Sequence{Sequence{ X }}->union(Sequence{ Sequence{ Y } })) ; var Ans : (trailer . (name dot) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name mat))))))) , (argument (test (logical_test (comparison (expr (atom (name matb)))))))) ))) := ; if (is_integer(Ans->first()) <>= true) & (is_integer(Ans[1+1]) <>= true) then ( if (Ans->first() >= 0) & (Ans[1+1] >= 0) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else ( execute ("No")->display() ); operation is_integer(n : OclAny) pre: true post: true activity: try ( OclType["double"](n)) (except_clause except (test (logical_test (comparison (expr (atom (name ValueError)))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name False)))))))))))) else ( return OclType["double"](n).is_integer() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for n in[*map(int,open(0))][1 :]: print(*((0--n//6,n//4),[-1])[n % 2 or n<3]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for n : (OclFile.newOclFile_Write(OclFile.newOclFile(0)))->collect( _x | (OclType["int"])->apply(_x) )->tail() do ( execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 0)))) - (expr (expr - (expr (atom (name n)))) // (expr (atom (number (integer 6))))))))) , (test (logical_test (comparison (expr (expr (atom (name n))) // (expr (atom (number (integer 4))))))))) )))))) , (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom - (number (integer 1)))))))) ])))))) )) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (logical_test (comparison (expr (expr (atom (name n))) % (expr (atom (number (integer 2))))))) or (logical_test (comparison (comparison (expr (atom (name n)))) < (comparison (expr (atom (number (integer 3))))))))))) ]))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import deque sys.setrecursionlimit(10**6) def S(): return sys.stdin.readline().rstrip() def SL(): return map(str,sys.stdin.readline().rstrip().split()) def I(): return int(sys.stdin.readline().rstrip()) def IL(): return map(int,sys.stdin.readline().rstrip().split()) def LS(): return list(sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def main(): x,y=IL() if 4*xpow(6)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation S() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation SL() : OclAny pre: true post: true activity: return (sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["String"])->apply(_x) ); operation I() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.readLine().rstrip())))->toInteger(); operation IL() : OclAny pre: true post: true activity: return (sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LS() : OclAny pre: true post: true activity: return (sys.stdin.readLine().rstrip().split()); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )); operation main() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := IL() ; if (4 * x->compareTo(y)) < 0 or y mod 2 /= 0 then ( execute ('No')->display() ; exit() ) else skip ; for i : Integer.subrange(0, x + 1-1) do ( if 4 * i + 2 * (x - i) = y then ( execute ('Yes')->display() ; exit() ) else skip) ; execute ('No')->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=[int(i)for i in input().split()] if(x*2==y or x*4==y): print('Yes') else : poss=0 for i in range(1,x+1): legs=i*2+(x-i)*4 if(legs==y): poss=1 break if(poss): print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if (x * 2 = y or x * 4 = y) then ( execute ('Yes')->display() ) else ( var poss : int := 0 ; for i : Integer.subrange(1, x + 1-1) do ( var legs : double := i * 2 + (x - i) * 4 ; if (legs = y) then ( poss := 1 ; break ) else skip) ; if (poss) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from heapq import heappush,heappop from bisect import bisect_left,bisect_right import sys,random,itertools,math sys.setrecursionlimit(10**5) input=sys.stdin.readline sqrt=math.sqrt def LI(): return list(map(int,input().split())) def LF(): return list(map(float,input().split())) def LI_(): return list(map(lambda x : int(x)-1,input().split())) def II(): return int(input()) def IF(): return float(input()) def S(): return input().rstrip() def LS(): return S().split() def IR(n): return[II()for _ in range(n)] def LIR(n): return[LI()for _ in range(n)] def FR(n): return[IF()for _ in range(n)] def LFR(n): return[LI()for _ in range(n)] def LIR_(n): return[LI_()for _ in range(n)] def SR(n): return[S()for _ in range(n)] def LSR(n): return[LS()for _ in range(n)] mod=1000000007 inf=float("INF") def solve(): x,y=LI() for i in range(x+1): j=x-i if i*2+j*4==y : print("Yes") return print("No") return if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(5)) ; var input : OclAny := (OclFile["System.in"]).readline ; var sqrt : OclAny := ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : int := 1000000007 ; var Math_PINFINITY : double := ("" + (("INF")))->toReal() ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LF() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["double"])->apply(_x) )); operation LI_() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) )); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation IF() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return input().rstrip(); operation LS() : OclAny pre: true post: true activity: return S().split(); operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (II())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI())); operation FR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (IF())); operation LFR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI())); operation LIR_(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI_())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LS())); operation solve() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := LI() ; for i : Integer.subrange(0, x + 1-1) do ( var j : double := x - i ; if i * 2 + j * 4 = y then ( execute ("Yes")->display() ; return ) else skip) ; execute ("No")->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binaryToDecimal(n): num=n ; dec_value=0 ; base=1 ; temp=num ; while(temp): last_digit=temp % 10 ; temp=int(temp/10); dec_value+=last_digit*base ; base=base*2 ; return dec_value ; num=10101001 ; print(binaryToDecimal(num)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; num := 10101001; ; execute (binaryToDecimal(num))->display();; operation binaryToDecimal(n : OclAny) pre: true post: true activity: var num : OclAny := n; ; var dec_value : int := 0; ; var base : int := 1; ; var temp : OclAny := num; ; while (temp) do ( var last_digit : int := temp mod 10; ; temp := ("" + ((temp / 10)))->toInteger(); ; dec_value := dec_value + last_digit * base; ; base := base * 2;) ; return dec_value;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): a,k=input().split() k1=int(k) while k1>1 and '0' not in a : a=str(int(a)+int(min(a))*int(max(a))); k1-=1 print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var k : OclAny := null; Sequence{a,k} := input().split() ; var k1 : int := ("" + ((k)))->toInteger() ; while k1 > 1 & (a)->excludes('0') do ( var a : String := ("" + ((("" + ((a)))->toInteger() + ("" + (((a)->min())))->toInteger() * ("" + (((a)->max())))->toInteger()))); k1 := k1 - 1) ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) def product(num): mini=10 maxi=-1 while num>0 : mini=min(mini,num % 10) maxi=max(maxi,num % 10) num=num//10 return maxi*mini for i in range(t): a,k=map(int,input().split()) for i in range(k-1): pro=product(a) if pro==0 : break a+=pro print(a,'\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var k : OclAny := null; Sequence{a,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, k - 1-1) do ( var pro : OclAny := product(a) ; if pro = 0 then ( break ) else skip ; a := a + pro) ; execute (a)->display()); operation product(num : OclAny) : OclAny pre: true post: true activity: var mini : int := 10 ; var maxi : int := -1 ; while num > 0 do ( mini := Set{mini, num mod 10}->min() ; maxi := Set{maxi, num mod 10}->max() ; num := num div 10) ; return maxi * mini; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() sDct={} letters=['B','u','l','b','a','s','r'] for i in range(len(s)): if s[i]in letters : if s[i]not in sDct : sDct[s[i]]=1 else : sDct[s[i]]+=1 cnt=0 if('B' in sDct and 'u' in sDct and 'l' in sDct and 'b' in sDct and 'a' in sDct and 's' in sDct and 'r' in sDct): while(sDct['B']>0 and sDct['u']>1 and sDct['l']>0 and sDct['b']>0 and sDct['a']>1 and sDct['s']>0 and sDct['r']>0): cnt+=1 sDct['B']-=1 sDct['u']-=2 sDct['l']-=1 sDct['b']-=1 sDct['a']-=2 sDct['s']-=1 sDct['r']-=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var sDct : OclAny := Set{} ; var letters : Sequence := Sequence{'B'}->union(Sequence{'u'}->union(Sequence{'l'}->union(Sequence{'b'}->union(Sequence{'a'}->union(Sequence{'s'}->union(Sequence{ 'r' })))))) ; for i : Integer.subrange(0, (s)->size()-1) do ( if (letters)->includes(s[i+1]) then ( if (sDct)->excludes(s[i+1]) then ( sDct[s[i+1]+1] := 1 ) else ( sDct[s[i+1]+1] := sDct[s[i+1]+1] + 1 ) ) else skip) ; var cnt : int := 0 ; if ((sDct)->includes('B') & (sDct)->includes('u') & (sDct)->includes('l') & (sDct)->includes('b') & (sDct)->includes('a') & (sDct)->includes('s') & (sDct)->includes('r')) then ( while (sDct->at('B') > 0 & sDct->at('u') > 1 & sDct->at('l') > 0 & sDct->at('b') > 0 & sDct->at('a') > 1 & sDct->at('s') > 0 & sDct->at('r') > 0) do ( cnt := cnt + 1 ; sDct->at('B') := sDct->at('B') - 1 ; sDct->at('u') := sDct->at('u') - 2 ; sDct->at('l') := sDct->at('l') - 1 ; sDct->at('b') := sDct->at('b') - 1 ; sDct->at('a') := sDct->at('a') - 2 ; sDct->at('s') := sDct->at('s') - 1 ; sDct->at('r') := sDct->at('r') - 1) ) else skip ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- iter=int(input()) for _ in range(iter): n,k=list(map(int,input().split(' '))) for i in range(k-1): t=n max=-1 min=10 while(t): if(t % 10>max): max=t % 10 if(t % 10toInteger() ; for _anon : Integer.subrange(0, iter-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, k - 1-1) do ( var t : OclAny := n ; var max : int := -1 ; var min : int := 10 ; while (t) do ( if ((t mod 10->compareTo(max)) > 0) then ( max := t mod 10 ) else skip ; if ((t mod 10->compareTo(min)) < 0) then ( min := t mod 10 ) else skip ; t := t div 10) ; if (min = 0) then ( break ) else skip ; var n : OclAny := n + max * min) ; execute (n)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for j in range(int(input())): n,k=map(int,input().split()) S=str(n) while k>1 : if S.count("0")>0 : break maxi=mini=0 for j in range(9,0,-1): if S.count(str(j))>0 : maxi=j break for j in range(0,10): if S.count(str(j))>0 : mini=j break n+=maxi*mini k=k-1 S=str(n) print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for j : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : String := ("" + ((n))) ; while k > 1 do ( if S->count("0") > 0 then ( break ) else skip ; var maxi : OclAny := 0; var mini : int := 0 ; for j : Integer.subrange(0 + 1, 9)->reverse() do ( if S->count(("" + ((j)))) > 0 then ( maxi := j ; break ) else skip) ; for j : Integer.subrange(0, 10-1) do ( if S->count(("" + ((j)))) > 0 then ( mini := j ; break ) else skip) ; n := n + maxi * mini ; var k : double := k - 1 ; S := ("" + ((n)))) ; execute (n)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,k=map(int,input().split()) s=0 for i in range(k-1): b=str(a) x=int(min(b)) y=int(max(b)) a=a+x*y if "0" in b : break print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var k : OclAny := null; Sequence{a,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : int := 0 ; for i : Integer.subrange(0, k - 1-1) do ( var b : String := ("" + ((a))) ; var x : int := ("" + (((b)->min())))->toInteger() ; var y : int := ("" + (((b)->max())))->toInteger() ; var a : OclAny := a + x * y ; if (b)->characters()->includes("0") then ( break ) else skip) ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findAnswer(n,arr): arr.sort(reverse=False) sum=0 for i in range(int(n/2)): sum+=((arr[i]+arr[n-i-1])*(arr[i]+arr[n-i-1])) return sum if __name__=='__main__' : arr=[53,28,143,5] n=len(arr) print(findAnswer(n,arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{53}->union(Sequence{28}->union(Sequence{143}->union(Sequence{ 5 }))) ; n := (arr)->size() ; execute (findAnswer(n, arr))->display() ) else skip; operation findAnswer(n : OclAny, arr : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var sum : int := 0 ; for i : Integer.subrange(0, ("" + ((n / 2)))->toInteger()-1) do ( sum := sum + ((arr[i+1] + arr[n - i - 1+1]) * (arr[i+1] + arr[n - i - 1+1]))) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) s=input() t=input() D={t[-1]: 1} for i in range(N-2,0,-1): si=s[i]; ti=t[i] v=D.get(si,0) D[ti]=(D.get(ti,0)+v)%(10**9+7) print(D.get(s[0],0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var D : Map := Map{ t->last() |-> 1 } ; for i : Integer.subrange(0 + 1, N - 2)->reverse() do ( var si : OclAny := s[i+1]; var ti : OclAny := t[i+1] ; var v : OclAny := D.get(si, 0) ; D[ti+1] := (D.get(ti, 0) + v) mod ((10)->pow(9) + 7)) ; execute (D.get(s->first(), 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict MOD=1000000007 n=int(input()) s=input() t=input() dic=defaultdict(int) dic[s[0]]=1 for cs,ct in zip(s[1 : n-1],t[1 : n-1]): dic[cs]+=dic[ct] dic[cs]%=MOD print(dic[t[-1]]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MOD : int := 1000000007 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var dic : OclAny := defaultdict(OclType["int"]) ; dic[s->first()+1] := 1 ; for _tuple : Integer.subrange(1, s.subrange(1+1, n - 1)->size())->collect( _indx | Sequence{s.subrange(1+1, n - 1)->at(_indx), t.subrange(1+1, n - 1)->at(_indx)} ) do (var _indx : int := 1; var cs : OclAny := _tuple->at(_indx); _indx := _indx + 1; var ct : OclAny := _tuple->at(_indx); dic[cs+1] := dic[cs+1] + dic[ct+1] ; dic[cs+1] := dic[cs+1] mod MOD) ; execute (dic[t->last()+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() if len(x)>7 : if "0000000" in x or "1111111" in x : print("YES") else : print("NO") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := (OclFile["System.in"]).readLine() ; if (x)->size() > 7 then ( if (x)->characters()->includes("0000000") or (x)->characters()->includes("1111111") then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- chain=input() if chain.__contains__('1111111')or chain.__contains__('0000000'): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var chain : String := (OclFile["System.in"]).readLine() ; if chain.__contains__('1111111') or chain.__contains__('0000000') then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): s=input() if s.count('0000000')or s.count('1111111'): print('YES') else : print('NO') if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; if s->count('0000000') or s->count('1111111') then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() ans=0 a='' for i in n : if a==i : ans+=1 if ans==7 : break else : ans=1 a=i if ans==7 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; var a : String := '' ; for i : n->characters() do ( if a = i then ( ans := ans + 1 ; if ans = 7 then ( break ) else skip ) else ( ans := 1 ; a := i )) ; if ans = 7 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() o=0 k=0 for i in range(len(a)-1): k+=1 if(a[i]!=a[i+1]): k=0 if(k+1>=7): o=1 if(o==1): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var o : int := 0 ; var k : int := 0 ; for i : Integer.subrange(0, (a)->size() - 1-1) do ( k := k + 1 ; if (a[i+1] /= a[i + 1+1]) then ( k := 0 ) else skip ; if (k + 1 >= 7) then ( o := 1 ) else skip) ; if (o = 1) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() B=S.count('B') l=S.count('l') u=(S.count('u'))/2 a=(S.count('a'))/2 b=S.count('b') s=S.count('s') r=S.count('r') n=min(B,l,u,a,b,s,r) print(int(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var B : int := S->count('B') ; var l : int := S->count('l') ; var u : double := (S->count('u')) / 2 ; var a : double := (S->count('a')) / 2 ; var b : int := S->count('b') ; var s : int := S->count('s') ; var r : int := S->count('r') ; var n : OclAny := Set{B, l, u, a, b, s, r}->min() ; execute (("" + ((n)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binomialCoeff(x,n,k): sum=0 ; term=1 ; i=1 ; while(i<=n and sumdisplay();; operation binomialCoeff(x : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var sum : int := 0; ; var term : int := 1; ; var i : int := 1; ; while ((i->compareTo(n)) <= 0 & (sum->compareTo(k)) < 0) do ( term := term * x - i + 1; ; term := term / i; ; sum := sum + term; ; i := i + 1;) ; return sum;; operation minTrials(n : OclAny, k : OclAny) pre: true post: true activity: var low : int := 1; ; var high : OclAny := k; ; while ((low->compareTo(high)) < 0) do ( var mid : double := (low + high) / 2; ; if ((binomialCoeff(mid, n, k)->compareTo(k)) < 0) then ( low := mid + 1; ) else ( high := mid; )) ; return ("" + ((low)))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxSum(p0,p1,a,pos,n): if(pos==n): if(p0==p1): return p0 ; else : return 0 ; ans=maxSum(p0,p1,a,pos+1,n); ans=max(ans,maxSum(p0+a[pos],p1,a,pos+1,n)); ans=max(ans,maxSum(p0,p1+a[pos],a,pos+1,n)); return ans ; if __name__=="__main__" : n=4 ; a=[1,2,3,6]; print(maxSum(0,0,a,0,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 4; ; a := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 6 }))); ; execute (maxSum(0, 0, a, 0, n))->display(); ) else skip; operation maxSum(p0 : OclAny, p1 : OclAny, a : OclAny, pos : OclAny, n : OclAny) pre: true post: true activity: if (pos = n) then ( if (p0 = p1) then ( return p0; ) else ( return 0; ) ) else skip ; var ans : OclAny := maxSum(p0, p1, a, pos + 1, n); ; ans := Set{ans, maxSum(p0 + a[pos+1], p1, a, pos + 1, n)}->max(); ; ans := Set{ans, maxSum(p0, p1 + a[pos+1], a, pos + 1, n)}->max(); ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxSum(a,n): a.sort(); sum=0 ; for i in range(0,n-1,2): sum+=a[i]; return sum ; if __name__=="__main__" : arr=[1,3,2,1,4,5]; n=len(arr); print(maxSum(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var arr : Sequence := Sequence{1}->union(Sequence{3}->union(Sequence{2}->union(Sequence{1}->union(Sequence{4}->union(Sequence{ 5 }))))); ; n := (arr)->size(); ; execute (maxSum(arr, n))->display(); ) else skip; operation maxSum(a : OclAny, n : OclAny) pre: true post: true activity: a := a->sort(); ; var sum : int := 0; ; for i : Integer.subrange(0, n - 1-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( sum := sum + a[i+1];) ; return sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d,n=map(int,input().split()) print((n+n//100)*100**d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : OclAny := null; var n : OclAny := null; Sequence{d,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((n + n div 100) * (100)->pow(d))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input().split() D=int(n[0]) N=int(n[1]) if D==0 : if N==100 : print('101') else : print(str(N)) elif D==1 : if N==100 : print('10100') else : print(str(N*100)) else : if N==100 : print('1010000') else : print(str(N*10000)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := input().split() ; var D : int := ("" + ((n->first())))->toInteger() ; var N : int := ("" + ((n[1+1])))->toInteger() ; if D = 0 then ( if N = 100 then ( execute ('101')->display() ) else ( execute (("" + ((N))))->display() ) ) else (if D = 1 then ( if N = 100 then ( execute ('10100')->display() ) else ( execute (("" + ((N * 100))))->display() ) ) else ( if N = 100 then ( execute ('1010000')->display() ) else ( execute (("" + ((N * 10000))))->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def getInt(): return int(input()) def getIntList(): return[int(x)for x in input().split()] def zeros(n): return[0]*n def dmp(x): global debug if debug : print(x) def abc100b(): D,N=getIntList() if N % 100==0 : return(N+1)*100**D else : return N*100**D debug=False print(abc100b()) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute debug : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; debug := false ; execute (abc100b())->display(); operation getInt() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation getIntList() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation zeros(n : OclAny) : OclAny pre: true post: true activity: return MatrixLib.elementwiseMult(Sequence{ 0 }, n); operation dmp(x : OclAny) pre: true post: true activity: skip ; if debug then ( execute (x)->display() ) else skip; operation abc100b() : OclAny pre: true post: true activity: var D : OclAny := null; var N : OclAny := null; Sequence{D,N} := getIntList() ; if N mod 100 = 0 then ( return (N + 1) * (100)->pow(D) ) else ( return N * (100)->pow(D) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys x=sys.stdin.readline() [d,n]=x.split(' ') if int(d)==0 : if int(n)==100 : print(101) else : print(n) elif int(d)==1 or int(d)==2 : if int(n)==100 : print((100**int(d))*(int(n)+1)) else : print((100**int(d))*int(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : String := (OclFile["System.in"]).readLine() ; Sequence{d}->union(Sequence{ n }) := x.split(' ') ; if ("" + ((d)))->toInteger() = 0 then ( if ("" + ((n)))->toInteger() = 100 then ( execute (101)->display() ) else ( execute (n)->display() ) ) else (if ("" + ((d)))->toInteger() = 1 or ("" + ((d)))->toInteger() = 2 then ( if ("" + ((n)))->toInteger() = 100 then ( execute (((100)->pow(("" + ((d)))->toInteger())) * (("" + ((n)))->toInteger() + 1))->display() ) else ( execute (((100)->pow(("" + ((d)))->toInteger())) * ("" + ((n)))->toInteger())->display() ) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- D,N=[int(i)for i in input().split()] ans=(N+N//100)*pow(100,D) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var D : OclAny := null; var N : OclAny := null; Sequence{D,N} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : double := (N + N div 100) * (100)->pow(D) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def oddEquivalent(s,n): count=0 for i in range(0,n): if(s[i]=='1'): count=count+1 return count if __name__=='__main__' : s="1011011" n=len(s) print(oddEquivalent(s,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( s := "1011011" ; n := (s)->size() ; execute (oddEquivalent(s, n))->display() ) else skip; operation oddEquivalent(s : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (s[i+1] = '1') then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools def compute(): LIMIT=200 minoperations=[0,0]+[None]*(LIMIT-1) numunknown=[LIMIT-1] def explore_chains(chain,maxops): if len(chain)>maxops or numunknown[0]==0 : return max=chain[-1] for i in reversed(range(len(chain))): for j in reversed(range(i+1)): x=chain[i]+chain[j] if x<=max : break if x<=LIMIT : chain.append(x) if minoperations[x]is None : minoperations[x]=len(chain)-1 numunknown[0]-=1 explore_chains(chain,maxops) chain.pop() for ops in itertools.count(1): if numunknown[0]==0 : return str(sum(minoperations)) explore_chains([1],ops) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LIMIT : int := 200 ; var minoperations : Sequence := Sequence{0}->union(Sequence{ 0 })->union(MatrixLib.elementwiseMult(Sequence{ null }, (LIMIT - 1))) ; var numunknown : Sequence := Sequence{ LIMIT - 1 } ; skip ; for ops : itertools->count(1) do ( if numunknown->first() = 0 then ( return ("" + (((minoperations)->sum()))) ) else skip ; explore_chains(Sequence{ 1 }, ops)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def MinimizeleftOverSum(a,n): v1,v2=[],[]; for i in range(n): if(a[i]% 2): v1.append(a[i]); else : v2.append(a[i]); if(len(v1)>len(v2)): v1.sort(); v2.sort(); x=len(v1)-len(v2)-1 ; sum=0 ; i=0 ; while(ilen(v1)): v1.sort(); v2.sort(); x=len(v2)-len(v1)-1 ; sum=0 ; i=0 ; while(iunion(Sequence{2}->union(Sequence{2}->union(Sequence{ 2 }))); ; n := (a)->size(); ; execute (MinimizeleftOverSum(a, n))->display(); ) else skip; operation MinimizeleftOverSum(a : OclAny, n : OclAny) pre: true post: true activity: var v1 : OclAny := null; var v2 : OclAny := null; Sequence{v1,v2} := Sequence{Sequence{},Sequence{}}; ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] mod 2) then ( execute ((a[i+1]) : v1); ) else ( execute ((a[i+1]) : v2); )) ; if (((v1)->size()->compareTo((v2)->size())) > 0) then ( v1 := v1->sort(); ; v2 := v2->sort(); ; var x : double := (v1)->size() - (v2)->size() - 1; ; var sum : int := 0; ; var i : int := 0; ; while ((i->compareTo(x)) < 0) do ( sum := sum + v1[i+1]; ; i := i + 1) ; return sum; ) else (if (((v2)->size()->compareTo((v1)->size())) > 0) then ( v1 := v1->sort(); ; v2 := v2->sort(); ; x := (v2)->size() - (v1)->size() - 1; ; sum := 0; ; i := 0; ; while ((i->compareTo(x)) < 0) do ( sum := sum + v2[i+1]; ; i := i + 1) ; return sum; ) else ( return 0; ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d=[1,'.,!? ','abc','def','ghi','jkl','mno','pqrs','tuv','wxyz'];[print(''.join(d[int(s[0])][len(s)% len(d[int(s[0])])-1]if s!='' else '' for s in t))for t in[input().split('0')for _ in[0]*int(input())]] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : Sequence := Sequence{1}->union(Sequence{'.,!? '}->union(Sequence{'abc'}->union(Sequence{'def'}->union(Sequence{'ghi'}->union(Sequence{'jkl'}->union(Sequence{'mno'}->union(Sequence{'pqrs'}->union(Sequence{'tuv'}->union(Sequence{ 'wxyz' })))))))));; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def smallestSum(n): if(n==1): return 0 return(2*pow(10,n-1)) def largestSum(n): return(2*(pow(10,n)-1)) n=4 print("Largest=",largestSum(n)) print("Smallest=",smallestSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 4 ; execute ("Largest=")->display() ; execute ("Smallest=")->display(); operation smallestSum(n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return 0 ) else skip ; return (2 * (10)->pow(n - 1)); operation largestSum(n : OclAny) : OclAny pre: true post: true activity: return (2 * ((10)->pow(n) - 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxSum(arr,n): arr.sort() sum=0 for i in range(n): sum+=arr[i]*i return sum arr=[3,5,6,1] n=len(arr) print(maxSum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{3}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 1 }))) ; n := (arr)->size() ; execute (maxSum(arr, n))->display(); operation maxSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + arr[i+1] * i) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def convertToBinary(num,a,n): pointer=n-1 while(num>0): a[pointer]=num % 2 num=num//2 pointer-=1 def checkforsum(a,n): sum1=0 sum2=0 mid=n//2 for i in range(mid): sum1=sum1+a[i] for j in range(mid,n): sum2=sum2+a[j] if(sum1==sum2): for i in range(n): print(a[i],end="") print() def print_seq(m): n=(2*m) a=[0 for i in range(n)] for i in range(pow(2,n)): convertToBinary(i,a,n) checkforsum(a,n) m=2 print_seq(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; m := 2 ; print_seq(m); operation convertToBinary(num : OclAny, a : OclAny, n : OclAny) pre: true post: true activity: var pointer : double := n - 1 ; while (num > 0) do ( a[pointer+1] := num mod 2 ; num := num div 2 ; pointer := pointer - 1); operation checkforsum(a : OclAny, n : OclAny) pre: true post: true activity: var sum1 : int := 0 ; var sum2 : int := 0 ; var mid : int := n div 2 ; for i : Integer.subrange(0, mid-1) do ( sum1 := sum1 + a[i+1]) ; for j : Integer.subrange(mid, n-1) do ( sum2 := sum2 + a[j+1]) ; if (sum1 = sum2) then ( for i : Integer.subrange(0, n-1) do ( execute (a[i+1])->display()) ; execute (->display() ) else skip; operation print_seq(m : OclAny) pre: true post: true activity: n := (2 * m) ; a := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, (2)->pow(n)-1) do ( convertToBinary(i, a, n) ; checkforsum(a, n)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printArr(arr,k): for i in range(k): print(arr[i],end=" "); print(); def printSeqUtil(n,k,len1,arr): if(len1==k): printArr(arr,k); return ; i=1 if(len1==0)else(arr[len1-1]+1); len1+=1 ; while(i<=n): arr[len1-1]=i ; printSeqUtil(n,k,len1,arr); i+=1 ; len1-=1 ; def printSeq(n,k): arr=[0]*k ; len1=0 ; printSeqUtil(n,k,len1,arr); k=3 ; n=7 ; printSeq(n,k); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; k := 3; ; n := 7; ; printSeq(n, k);; operation printArr(arr : OclAny, k : OclAny) pre: true post: true activity: for i : Integer.subrange(0, k-1) do ( execute (arr[i+1])->display();) ; execute (->display();; operation printSeqUtil(n : OclAny, k : OclAny, len1 : OclAny, arr : OclAny) : OclAny pre: true post: true activity: if (len1 = k) then ( printArr(arr, k); ; return; ) else skip ; var i : int := if (len1 = 0) then 1 else (arr[len1 - 1+1] + 1) endif; ; len1 := len1 + 1; ; while ((i->compareTo(n)) <= 0) do ( arr[len1 - 1+1] := i; ; printSeqUtil(n, k, len1, arr); ; i := i + 1;) ; len1 := len1 - 1;; operation printSeq(n : OclAny, k : OclAny) pre: true post: true activity: arr := MatrixLib.elementwiseMult(Sequence{ 0 }, k); ; len1 := 0; ; printSeqUtil(n, k, len1, arr);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(n): if n % 2==1 and n>5 : print('YES') else : print('NO') def main(): a=3 b=7 check(a) check(b) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation check(n : OclAny) pre: true post: true activity: if n mod 2 = 1 & n > 5 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); operation main() pre: true post: true activity: var a : int := 3 ; var b : int := 7 ; check(a) ; check(b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) if ncollect( _x | (OclType["int"])->apply(_x) ) ; if (n->compareTo(k + 1)) < 0 then ( execute (-1)->display() ) else ( execute ((argument * (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (expr (expr (atom (name n))) - (expr (atom (name k)))) + (expr (atom (number (integer 1)))))))))) )))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdout def solve(): n,k=map(int,input().rstrip().split()) if k>=n : print(-1) else : ls=[i for i in range(1,n+1)] k=n-k-1 swaps=k//2 i=0 while icollect( _x | (OclType["int"])->apply(_x) ) ; if (k->compareTo(n)) >= 0 then ( execute (-1)->display() ) else ( var ls : Sequence := Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | (i)) ; var k : double := n - k - 1 ; var swaps : int := k div 2 ; var i : int := 0 ; while (i->compareTo(swaps)) < 0 do ( var ls[2 * i + 1+1] : OclAny := null; var ls[2 * i + 2+1] : OclAny := null; Sequence{ls[2 * i + 1+1],ls[2 * i + 2+1]} := Sequence{ls[2 * i + 2+1],ls[2 * i + 1+1]} ; i := i + 1) ; if k mod 2 = 1 then ( var ls[2 * i + 1+1] : OclAny := null; var ls->first() : OclAny := null; Sequence{ls[2 * i + 1+1],ls->first()} := Sequence{ls->first(),ls[2 * i + 1+1]} ) else skip ; for elt : ls do ( stdout.write(("" + ((elt))) + ' ')) ; execute (->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys def solve(r,w): data=[int(v)for v in r.readline().split()] n=data[0] k=data[1] if n==k : print(-1) else : ans=[i for i in range(n+1)] for i in range(n-k,1,-1): ans[i]=ans[i-1] ans[1]=n-k del ans[0] for elem in ans : print(elem,end=" ") if __name__=="__main__" : solve(sys.stdin,sys.stdout) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( solve(OclFile["System.in"], OclFile["System.out"]) ) else skip; operation solve(r : OclAny, w : OclAny) pre: true post: true activity: var data : Sequence := r.readLine().split()->select(v | true)->collect(v | (("" + ((v)))->toInteger())) ; var n : OclAny := data->first() ; var k : OclAny := data[1+1] ; if n = k then ( execute (-1)->display() ) else ( var ans : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (i)) ; for i : Integer.subrange(1 + 1, n - k)->reverse() do ( ans[i+1] := ans[i - 1+1]) ; ans[1+1] := n - k ; execute (ans->first())->isDeleted() ; for elem : ans do ( execute (elem)->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) if n==k : print(-1) else : print(n-k,end=' ') for i in range(2,n+1): if icollect( _x | (OclType["int"])->apply(_x) ) ; if n = k then ( execute (-1)->display() ) else ( execute (n - k)->display() ; for i : Integer.subrange(2, n + 1-1) do ( if (i->compareTo(n - k + 1)) < 0 then ( execute (i - 1)->display() ) else ( execute (i)->display() )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) if n==k : print('-1') elif k==n-1 : for i in range(1,n+1): print(i,end=' ') print(end='\n') else : ans=[0]*n d={} for i in range(n): if i+1 not in d : d[i+1]=1 c=0 i=1 while ccollect( _x | (OclType["int"])->apply(_x) ) ; if n = k then ( execute ('-1')->display() ) else (if k = n - 1 then ( for i : Integer.subrange(1, n + 1-1) do ( execute (i)->display()) ; execute ((argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom ' ')))))))->display() ) else ( var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var d : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( if (d)->excludes(i + 1) then ( d[i + 1+1] := 1 ) else skip) ; var c : int := 0 ; var i : int := 1 ; while (c->compareTo(k)) < 0 do ( ans[i+1] := i + 1 ; d[i + 1+1] := d[i + 1+1] - 1 ; c := c + 1 ; i := i + 1) ; for i : Integer.subrange(i, n-1) do ( if i = n - 1 then ( ans[i+1] := 1 ; d[1+1] := d[1+1] - 1 ) else ( ans[i+1] := i + 2 ; d[i + 2+1] := d[i + 2+1] - 1 )) ; for i : Integer.subrange(0, n-1) do ( if d[i + 1+1] = 1 then ( ans->first() := i + 1 ) else skip) ; for i : Integer.subrange(0, n-1) do ( execute (ans[i+1])->display()) ; execute ((argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom ' ')))))))->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import exit,setrecursionlimit,stderr from functools import reduce from itertools import* from collections import* from bisect import bisect def read(): return int(input()) def reads(): return[int(x)for x in input().split()] N,K=reads() a=reads() ppsum=[0]*(N+1) psum=[0]*(N+1) for i in range(N): ppsum[i+1]=ppsum[i]+max(0,a[i]) psum[i+1]=psum[i]+a[i] ansb=max(ppsum[i]+psum[i+K]-psum[i]+ppsum[N]-ppsum[i+K]for i in range(N-K+1)) answ=max(ppsum[i]+ppsum[N]-ppsum[i+K]for i in range(N-K+1)) print(max(ansb,answ)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := reads() ; var a : OclAny := reads() ; var ppsum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; var psum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; for i : Integer.subrange(0, N-1) do ( ppsum[i + 1+1] := ppsum[i+1] + Set{0, a[i+1]}->max() ; psum[i + 1+1] := psum[i+1] + a[i+1]) ; var ansb : OclAny := ((argument (test (logical_test (comparison (expr (expr (expr (expr (expr (atom (name ppsum)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name psum)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name K))))))))) ])))) - (expr (atom (name psum)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) + (expr (atom (name ppsum)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name N)))))))) ])))) - (expr (atom (name ppsum)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name K))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name N))) - (expr (atom (name K)))) + (expr (atom (number (integer 1)))))))))) )))))))))->max() ; var answ : OclAny := ((argument (test (logical_test (comparison (expr (expr (expr (atom (name ppsum)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name ppsum)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name N)))))))) ])))) - (expr (atom (name ppsum)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name K))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name N))) - (expr (atom (name K)))) + (expr (atom (number (integer 1)))))))))) )))))))))->max() ; execute (Set{ansb, answ}->max())->display(); operation read() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation reads() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,input().split()) A=list(map(int,input().split())) plusminus=[0]*len(A) plusor0=[0]*len(A) plusminus[0]=A[0] plusor0[0]=max(0,A[0]) for i in range(1,N): plusminus[i]=plusminus[i-1]+A[i] plusor0[i]=plusor0[i-1]+max(0,A[i]) plusminus.insert(0,0) plusor0.insert(0,0) ans=0 for i in range(N-K+1): s=plusminus[i+K]-plusminus[i] if i==0 : s+=plusor0[N]-plusor0[K] elif i==N-K : s+=plusor0[N-K] else : s+=plusor0[i]+plusor0[N]-plusor0[i+K] if ans<=s : ans=s for i in range(N-K+1): s=0 if i==0 : s+=plusor0[N]-plusor0[K] elif i==N-K : s+=plusor0[N-K] else : s+=plusor0[i]+plusor0[N]-plusor0[i+K] if ans<=s : ans=s print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var plusminus : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (A)->size()) ; var plusor0 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (A)->size()) ; plusminus->first() := A->first() ; plusor0->first() := Set{0, A->first()}->max() ; for i : Integer.subrange(1, N-1) do ( plusminus[i+1] := plusminus[i - 1+1] + A[i+1] ; plusor0[i+1] := plusor0[i - 1+1] + Set{0, A[i+1]}->max()) ; plusminus := plusminus.insertAt(0+1, 0) ; plusor0 := plusor0.insertAt(0+1, 0) ; var ans : int := 0 ; for i : Integer.subrange(0, N - K + 1-1) do ( var s : double := plusminus[i + K+1] - plusminus[i+1] ; if i = 0 then ( s := s + plusor0[N+1] - plusor0[K+1] ) else (if i = N - K then ( s := s + plusor0[N - K+1] ) else ( s := s + plusor0[i+1] + plusor0[N+1] - plusor0[i + K+1] ) ) ; if (ans->compareTo(s)) <= 0 then ( ans := s ) else skip) ; for i : Integer.subrange(0, N - K + 1-1) do ( s := 0 ; if i = 0 then ( s := s + plusor0[N+1] - plusor0[K+1] ) else (if i = N - K then ( s := s + plusor0[N - K+1] ) else ( s := s + plusor0[i+1] + plusor0[N+1] - plusor0[i + K+1] ) ) ; if (ans->compareTo(s)) <= 0 then ( ans := s ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys k,p=map(int,sys.stdin.readline().split()) ans=0 ans2=0 i=1 while ans2collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; var ans2 : int := 0 ; var i : int := 1 ; while (ans2->compareTo(k)) < 0 do ( var s : String := ("" + ((i))) ; ans := ans + ("" + ((s + s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))))->toInteger() ; ans2 := ans2 + 1 ; i := i + 1) ; execute (ans mod p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def countRectangles(l,w): squareSide=math.gcd(l,w) return(l*w)/(squareSide*squareSide) if __name__=='__main__' : l=4 w=6 ans=countRectangles(l,w) print(int(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( l := 4 ; w := 6 ; var ans : OclAny := countRectangles(l, w) ; execute (("" + ((ans)))->toInteger())->display() ) else skip; operation countRectangles(l : OclAny, w : OclAny) : OclAny pre: true post: true activity: var squareSide : long := (l)->gcd(w) ; return (l * w) / (squareSide * squareSide); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque,Counter from heapq import heappush,heappop,heapify import math import bisect import random from itertools import permutations,accumulate,combinations,product import sys from pprint import pprint from copy import deepcopy import string from bisect import bisect_left,bisect_right from math import factorial,ceil,floor from operator import mul from functools import reduce from pprint import pprint sys.setrecursionlimit(2147483647) INF=10**15 def LI(): return list(map(int,sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] def SRL(n): return[list(S())for i in range(n)] def MSRL(n): return[[int(j)for j in list(S())]for i in range(n)] mod=1000000007 n,k=LI() A=LI() acc=[0]+list(accumulate(A)) plus_acc=[0]+list(accumulate([i if i>0 else 0 for i in A])) ans=-INF for l in range(n-k+1): r=l+k ans=max(ans,max(acc[r]-acc[l],0)+plus_acc[l]+plus_acc[n]-plus_acc[r]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(2147483647) ; var INF : double := (10)->pow(15) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : int := 1000000007 ; var k : OclAny := null; Sequence{n,k} := LI() ; var A : OclAny := LI() ; var acc : Sequence := Sequence{ 0 }->union((accumulate(A))) ; var plus_acc : Sequence := Sequence{ 0 }->union((accumulate(A->select(i | true)->collect(i | (if i > 0 then i else 0 endif))))) ; var ans : OclAny := -INF ; for l : Integer.subrange(0, n - k + 1-1) do ( var r : OclAny := l + k ; ans := Set{ans, Set{acc[r+1] - acc[l+1], 0}->max() + plus_acc[l+1] + plus_acc[n+1] - plus_acc[r+1]}->max()) ; execute (ans)->display(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation I() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.buffer.readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.buffer.readLine().rstrip().decode('utf-8').split(); operation S() : OclAny pre: true post: true activity: return sys.stdin.buffer.readLine().rstrip().decode('utf-8'); operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation SRL(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | ((S()))); operation MSRL(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | ((S())->select(j | true)->collect(j | (("" + ((j)))->toInteger())))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=list(map(int,input().split())) plus_a=[0]*n minus_a=[0]*n ans=0 for i in range(n): if a[i]>0 : plus_a[i]=a[i] else : minus_a[i]=a[i] ans+=plus_a[i] ruiseki_plus=[0]*(n+1) ruiseki_minus=[0]*(n+1) for i in range(n): ruiseki_plus[i+1]=ruiseki_plus[i]+plus_a[i] ruiseki_minus[i+1]=ruiseki_minus[i]+minus_a[i] min_decreasing=-float("inf") for i in range(n-k+1): tmp_plus=ruiseki_plus[i+k]-ruiseki_plus[i] tmp_minus=ruiseki_minus[i+k]-ruiseki_minus[i] min_decreasing=max(min_decreasing,-tmp_plus,tmp_minus) print(ans+min_decreasing) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var plus_a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var minus_a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if a[i+1] > 0 then ( plus_a[i+1] := a[i+1] ) else ( minus_a[i+1] := a[i+1] ) ; ans := ans + plus_a[i+1]) ; var ruiseki_plus : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var ruiseki_minus : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(0, n-1) do ( ruiseki_plus[i + 1+1] := ruiseki_plus[i+1] + plus_a[i+1] ; ruiseki_minus[i + 1+1] := ruiseki_minus[i+1] + minus_a[i+1]) ; var min_decreasing : double := -("" + (("inf")))->toReal() ; for i : Integer.subrange(0, n - k + 1-1) do ( var tmp_plus : double := ruiseki_plus[i + k+1] - ruiseki_plus[i+1] ; var tmp_minus : double := ruiseki_minus[i + k+1] - ruiseki_minus[i+1] ; min_decreasing := Set{min_decreasing, -tmp_plus, tmp_minus}->max()) ; execute (ans + min_decreasing)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import*; A=accumulate ; N,K,*a=map(int,open(0).read().split()); a=[0]+a ;*c,=A(a);*d,=A(max(0,i)for i in a); print(max(d[i]+max(0,c[i+K]-c[i])+d[N]-d[i+K]for i in range(N-K+1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; var A : OclAny := accumulate; var N : OclAny := null; var K : OclAny := null; var a : OclAny := null; Sequence{N,K,a} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ); var a : Sequence := Sequence{ 0 }->union(a);(testlist_star_expr (star_expr * (expr (atom (name c)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name c)))) ,)} := A(a);(testlist_star_expr (star_expr * (expr (atom (name d)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name d)))) ,)} := A((argument (test (logical_test (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name a)))))))); execute (((argument (test (logical_test (comparison (expr (expr (expr (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name K))))))))) ]))) - (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))) ))))) + (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name N)))))))) ])))) - (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name K))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name N))) - (expr (atom (name K)))) + (expr (atom (number (integer 1)))))))))) )))))))))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getMissingNo(a,n): i,total=0,1 for i in range(2,n+2): total+=i total-=a[i-2] return total arr=[1,2,3,5] print(getMissingNo(arr,len(arr))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var arr : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 5 }))) ; execute (getMissingNo(arr, (arr)->size()))->display(); operation getMissingNo(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var i : OclAny := null; var total : OclAny := null; Sequence{i,total} := Sequence{0,1} ; for i : Integer.subrange(2, n + 2-1) do ( total := total + i ; total := total - a[i - 2+1]) ; return total; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def MaximumDivisors(X,Y): arr=[0]*(Y-X+1) mx=0 cnt=0 i=1 while i*i<=Y : sq=i*i if((X//i)*i>=X): first_divisible=(X//i)*i else : first_divisible=(X//i+1)*i for j in range(first_divisible,Y+1,i): if jmx : cnt=1 mx=arr[i-X] elif arr[i-X]==mx : cnt+=1 return cnt if __name__=="__main__" : X=1 Y=10 print(MaximumDivisors(X,Y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( X := 1 ; Y := 10 ; execute (MaximumDivisors(X, Y))->display() ) else skip; operation MaximumDivisors(X : OclAny, Y : OclAny) : OclAny pre: true post: true activity: var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (Y - X + 1)) ; var mx : int := 0 ; var cnt : int := 0 ; var i : int := 1 ; while (i * i->compareTo(Y)) <= 0 do ( var sq : int := i * i ; if (((X div i) * i->compareTo(X)) >= 0) then ( var first_divisible : int := (X div i) * i ) else ( first_divisible := (X div i + 1) * i ) ; for j : Integer.subrange(first_divisible, Y + 1-1)->select( $x | ($x - first_divisible) mod i = 0 ) do ( if (j->compareTo(sq)) < 0 then ( continue ) else (if j = sq then ( arr[j - X+1] := arr[j - X+1] + 1 ) else ( arr[j - X+1] := arr[j - X+1] + 2 ) ) ) ; i := i + 1) ; for i : Integer.subrange(X, Y + 1-1) do ( if (arr[i - X+1]->compareTo(mx)) > 0 then ( cnt := 1 ; mx := arr[i - X+1] ) else (if arr[i - X+1] = mx then ( cnt := cnt + 1 ) else skip)) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countStaircases(N): memo=[[0 for x in range(N+5)]for y in range(N+5)] for i in range(N+1): for j in range(N+1): memo[i][j]=0 memo[3][2]=memo[4][2]=1 for i in range(5,N+1): for j in range(2,i+1): if(j==2): memo[i][j]=memo[i-j][j]+1 else : memo[i][j]=(memo[i-j][j]+memo[i-j][j-1]) answer=0 for i in range(1,N+1): answer=answer+memo[N][i] return answer if __name__=="__main__" : N=7 print(countStaircases(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := 7 ; execute (countStaircases(N))->display() ) else skip; operation countStaircases(N : OclAny) : OclAny pre: true post: true activity: var memo : Sequence := Integer.subrange(0, N + 5-1)->select(y | true)->collect(y | (Integer.subrange(0, N + 5-1)->select(x | true)->collect(x | (0)))) ; for i : Integer.subrange(0, N + 1-1) do ( for j : Integer.subrange(0, N + 1-1) do ( memo[i+1][j+1] := 0)) ; memo[3+1][2+1] := 1; var memo[4+1][2+1] : int := 1 ; for i : Integer.subrange(5, N + 1-1) do ( for j : Integer.subrange(2, i + 1-1) do ( if (j = 2) then ( memo[i+1][j+1] := memo[i - j+1][j+1] + 1 ) else ( memo[i+1][j+1] := (memo[i - j+1][j+1] + memo[i - j+1][j - 1+1]) ))) ; var answer : int := 0 ; for i : Integer.subrange(1, N + 1-1) do ( answer := answer + memo[N+1][i+1]) ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find_sub(s,k): Len=len(s) lp,rp=0,0 ans=0 hash_char=[0 for i in range(256)] for rp in range(Len): hash_char[ord(s[rp])]+=1 while(hash_char[ord(s[rp])]>k): hash_char[ord(s[lp])]-=1 lp+=1 ans+=rp-lp+1 return ans s="aaabb" k=2 ; print(find_sub(s,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := "aaabb" ; k := 2; ; execute (find_sub(s, k))->display(); operation find_sub(s : OclAny, k : OclAny) : OclAny pre: true post: true activity: var Len : int := (s)->size() ; var lp : OclAny := null; var rp : OclAny := null; Sequence{lp,rp} := Sequence{0,0} ; var ans : int := 0 ; var hash_char : Sequence := Integer.subrange(0, 256-1)->select(i | true)->collect(i | (0)) ; for rp : Integer.subrange(0, Len-1) do ( hash_char[(s[rp+1])->char2byte()+1] := hash_char[(s[rp+1])->char2byte()+1] + 1 ; while ((hash_char[(s[rp+1])->char2byte()+1]->compareTo(k)) > 0) do ( hash_char[(s[lp+1])->char2byte()+1] := hash_char[(s[lp+1])->char2byte()+1] - 1 ; lp := lp + 1) ; ans := ans + rp - lp + 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(p,n): temp=p count=0 f=5 while(f<=temp): count+=temp/f f=f*5 return(count>=n) def findNum(n): if(n==1): return 5 low=0 high=5*n while(low>1 if(check(mid,n)): high=mid else : low=mid+1 return low n=6 print(findNum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 6 ; execute (findNum(n))->display(); operation check(p : OclAny, n : OclAny) : OclAny pre: true post: true activity: var temp : OclAny := p ; var count : int := 0 ; var f : int := 5 ; while ((f->compareTo(temp)) <= 0) do ( count := count + temp / f ; f := f * 5) ; return ((count->compareTo(n)) >= 0); operation findNum(n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return 5 ) else skip ; var low : int := 0 ; var high : double := 5 * n ; while ((low->compareTo(high)) < 0) do ( var mid : int := (low + high) /(2->pow(1)) ; if (check(mid, n)) then ( high := mid ) else ( low := mid + 1 )) ; return low; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def firstEven(arr,n): map1={} for i in range(0,n): if arr[i]not in map1 : map1[arr[i]]=False else : map1[arr[i]]=not map1[arr[i]] for j in range(0,n): if map1[arr[j]]==True : break return arr[j] if __name__=="__main__" : arr=[2,4,6,8,1,6] print(firstEven(arr,6)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{2}->union(Sequence{4}->union(Sequence{6}->union(Sequence{8}->union(Sequence{1}->union(Sequence{ 6 }))))) ; execute (firstEven(arr, 6))->display() ) else skip; operation firstEven(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var map1 : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( if (map1)->excludes(arr[i+1]) then ( map1[arr[i+1]+1] := false ) else ( map1[arr[i+1]+1] := not(map1[arr[i+1]+1]) )) ; for j : Integer.subrange(0, n-1) do ( if map1[arr[j+1]+1] = true then ( break ) else skip) ; return arr[j+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math k=int(input()) stack=[] x=int(1e9+1) id=10 count=0 for i in range(0,x): id+=9 s=id o=0 while s>=1 and o<=10 : o+=s % 10 s=s//10 if o==10 and s<1 : count+=1 if count==k : print(id) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var stack : Sequence := Sequence{} ; var x : int := ("" + ((("1e9")->toReal() + 1)))->toInteger() ; var id : int := 10 ; var count : int := 0 ; for i : Integer.subrange(0, x-1) do ( id := id + 9 ; var s : int := id ; var o : int := 0 ; while s >= 1 & o <= 10 do ( o := o + s mod 10 ; s := s div 10) ; if o = 10 & s < 1 then ( count := count + 1 ) else skip ; if count = k then ( execute (id)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSum(arr,n): arr.sort() sum=arr[0] for i in range(0,n-1): if(arr[i]!=arr[i+1]): sum=sum+arr[i+1] return sum def main(): arr=[1,2,3,1,1,4,5,6] n=len(arr) print(findSum(arr,n)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation findSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var sum : OclAny := arr->first() ; for i : Integer.subrange(0, n - 1-1) do ( if (arr[i+1] /= arr[i + 1+1]) then ( sum := sum + arr[i + 1+1] ) else skip) ; return sum; operation main() pre: true post: true activity: arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{1}->union(Sequence{1}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))))))) ; n := (arr)->size() ; execute (findSum(arr, n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printUnion(arr1,arr2,n1,n2): hs=set() for i in range(0,n1): hs.add(arr1[i]) for i in range(0,n2): hs.add(arr2[i]) print("Union:") for i in hs : print(i,end=" ") print("\n") def printIntersection(arr1,arr2,n1,n2): hs=set() for i in range(0,n1): hs.add(arr1[i]) print("Intersection:") for i in range(0,n2): if arr2[i]in hs : print(arr2[i],end=" ") arr1=[7,1,5,2,3,6] arr2=[3,8,6,20,7] n1=len(arr1) n2=len(arr2) printUnion(arr1,arr2,n1,n2) printIntersection(arr1,arr2,n1,n2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr1 := Sequence{7}->union(Sequence{1}->union(Sequence{5}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 6 }))))) ; arr2 := Sequence{3}->union(Sequence{8}->union(Sequence{6}->union(Sequence{20}->union(Sequence{ 7 })))) ; n1 := (arr1)->size() ; n2 := (arr2)->size() ; printUnion(arr1, arr2, n1, n2) ; printIntersection(arr1, arr2, n1, n2); operation printUnion(arr1 : OclAny, arr2 : OclAny, n1 : OclAny, n2 : OclAny) pre: true post: true activity: var hs : Set := Set{}->union(()) ; for i : Integer.subrange(0, n1-1) do ( execute ((arr1[i+1]) : hs)) ; for i : Integer.subrange(0, n2-1) do ( execute ((arr2[i+1]) : hs)) ; execute ("Union:")->display() ; for i : hs do ( execute (i)->display()) ; execute ("\n")->display(); operation printIntersection(arr1 : OclAny, arr2 : OclAny, n1 : OclAny, n2 : OclAny) pre: true post: true activity: hs := Set{}->union(()) ; for i : Integer.subrange(0, n1-1) do ( execute ((arr1[i+1]) : hs)) ; execute ("Intersection:")->display() ; for i : Integer.subrange(0, n2-1) do ( if (hs)->includes(arr2[i+1]) then ( execute (arr2[i+1])->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isUgly(n): while n % 2==0 : n=n//2 while n % 3==0 : n=n//3 while n % 5==0 : n=n//5 if n==1 : return True return False def sortUglyNumbers(arr,n): list=[] for i in range(0,n): if isUgly(arr[i]): list.append(arr[i]) arr[i]=-1 list.sort() j=0 for i in range(0,n): if arr[i]==-1 : print(list[j],end=" ") j+=1 else : print(arr[i],end=" ") if __name__=="__main__" : arr=[1,2,3,7,12,10] n=len(arr) sortUglyNumbers(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{7}->union(Sequence{12}->union(Sequence{ 10 }))))) ; n := (arr)->size() ; sortUglyNumbers(arr, n) ) else skip; operation isUgly(n : OclAny) : OclAny pre: true post: true activity: while n mod 2 = 0 do ( n := n div 2) ; while n mod 3 = 0 do ( n := n div 3) ; while n mod 5 = 0 do ( n := n div 5) ; if n = 1 then ( return true ) else skip ; return false; operation sortUglyNumbers(arr : OclAny, n : OclAny) pre: true post: true activity: var OclType["Sequence"] : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if isUgly(arr[i+1]) then ( execute ((arr[i+1]) : OclType["Sequence"]) ; arr[i+1] := -1 ) else skip) ; OclType["Sequence"] := OclType["Sequence"]->sort() ; var j : int := 0 ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] = -1 then ( execute ([j+1])->display() ; j := j + 1 ) else ( execute (arr[i+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binaryToDecimal(n): num=n ; dec_value=0 ; base1=1 ; len1=len(num); for i in range(len1-1,-1,-1): if(num[i]=='1'): dec_value+=base1 ; base1=base1*2 ; return dec_value ; num="10101001" ; print(binaryToDecimal(num)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; num := "10101001"; ; execute (binaryToDecimal(num))->display();; operation binaryToDecimal(n : OclAny) pre: true post: true activity: var num : OclAny := n; ; var dec_value : int := 0; ; var base1 : int := 1; ; var len1 : int := (num)->size(); ; for i : Integer.subrange(-1 + 1, len1 - 1)->reverse() do ( if (num[i+1] = '1') then ( dec_value := dec_value + base1; ) else skip ; base1 := base1 * 2;) ; return dec_value;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B=[int(i)for i in input().split()] Flag=False price1=int(A//0.08)+1 price2=int(B//0.1)+1 if price1select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var Flag : boolean := false ; var price1 : int := ("" + ((A div 0.08)))->toInteger() + 1 ; var price2 : int := ("" + ((B div 0.1)))->toInteger() + 1 ; if (price1->compareTo(price2)) < 0 then ( var start : int := price1 ; var end : int := price2 ) else ( start := price2 ; end := price1 ) ; for i : Integer.subrange(start, end + 1-1) do ( if ("" + ((i * 0.08)))->toInteger() = A & ("" + ((i * 0.1)))->toInteger() = B then ( Flag := true ; var price : OclAny := i ; break ) else skip) ; if Flag = true then ( execute (price)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque,Counter from heapq import heappush,heappop from itertools import permutations,accumulate from math import sqrt,ceil,floor,factorial from bisect import bisect_left,bisect_right from copy import deepcopy from operator import itemgetter from fractions import gcd import sys def I(): return int(input()) def Is(): return map(int,input().split()) def LI(): return list(map(int,input().split())) def TI(): return tuple(map(int,input().split())) def IR(n): return[I()for _ in range(n)] def LIR(n): return[LI()for _ in range(n)] def TIR(n): return[TI()for _ in range(n)] def S(): return input() def Ss(): return input().split() def LS(): return list(input()) def SR(n): return[S()for _ in range(n)] def SsR(n): return[Ss()for _ in range(n)] def LSR(n): return[LS()for _ in range(n)] sys.setrecursionlimit(1000000) MOD=1000000007 INF=float('inf') a,b=Is() ax=a*12.5 bx=b*10 for i in range(floor(bx-15),floor(bx-15)+40): if a==floor(i*0.08)and b==floor(i*0.1): print(i) exit() print("-1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1000000) ; var MOD : int := 1000000007 ; var INF : double := ("" + (('inf')))->toReal() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Is() ; var ax : double := a * 12.5 ; var bx : double := b * 10 ; for i : Integer.subrange(floor(bx - 15), floor(bx - 15) + 40-1) do ( if a = floor(i * 0.08) & b = floor(i * 0.1) then ( execute (i)->display() ; exit() ) else skip) ; execute ("-1")->display(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation Is() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation TI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI())); operation TIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (TI())); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation Ss() : OclAny pre: true post: true activity: return input().split(); operation LS() : OclAny pre: true post: true activity: return ((OclFile["System.in"]).readLine())->characters(); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (S())); operation SsR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Ss())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LS())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import numpy as np s=input() num=s.split(" ") A=int(num[0]) B=int(num[1]) tax_8=[] tax_10=[] for i in range(10001): tax_8.append([math.floor(i*0.08)]) tax_10.append([math.floor(i*0.1)]) tax_8_np=np.array(tax_8) tax_10_np=np.array(tax_10) tax_8_candidate=list(np.where(tax_8_np==A)[0]) tax_10_candidate=list(np.where(tax_10_np==B)[0]) candidate=list(set(tax_8_candidate)& set(tax_10_candidate)) if len(candidate)==0 : print(-1) else : print(int(np.array(candidate).min())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var s : String := (OclFile["System.in"]).readLine() ; var num : OclAny := s.split(" ") ; var A : int := ("" + ((num->first())))->toInteger() ; var B : int := ("" + ((num[1+1])))->toInteger() ; var tax_8 : Sequence := Sequence{} ; var tax skip0 : Sequence := Sequence{} ; for i : Integer.subrange(0, 10001-1) do ( execute ((Sequence{ (i * 0.08)->floor() }) : tax_8) ; execute ((Sequence{ (i * 0.1)->floor() }) : taxtaxtaxtaxtaxtaxtax execute ((Sequence{ (i * 0.08)->floor() }) : tax_8)0.append(Sequence{ (i * 0.1)->floor() })0.append(Sequence{ (i * 0.1)->floor() })0.append(Sequence{ (i * 0.1)->floor() })0.append(Sequence{ (i * 0.1)->floor() })0.append(Sequence{ (i * 0.1)->floor() })0.append(Sequence{ (i * 0.1)->floor() })0)) ; var tax_8_np : Sequence := (tax_8) ; var tax skip0_np : Sequence := (tax.array(tax skip0)0) ; var tax_8_candidate : Sequence := (np.where(tax_8_np = A)->first()) ; var tax skip0_candidate : Sequence := (np.where(tax skip0_np = B)->first()) ; var candidate : Sequence := (MathLib.bitwiseAnd(Set{}->union((tax_8_candidate)), Set{}->union((tax skip0_candidate)))) ; if (candidate)->size() = 0 then ( execute (-1)->display() ) else ( execute (("" + ((np.array(candidate)->min())))->toInteger())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) if(int(12.5*a)+(a % 2))>10*b+9 or(int(12.5*a)+(a % 2))+12-(a % 2)<10*b : print(-1) else : print(max((int(12.5*a)+(a % 2)),10*b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if ((("" + ((12.5 * a)))->toInteger() + (a mod 2))->compareTo(10 * b + 9)) > 0 or ((("" + ((12.5 * a)))->toInteger() + (a mod 2)) + 12 - (a mod 2)->compareTo(10 * b)) < 0 then ( execute (-1)->display() ) else ( execute (Set{(("" + ((12.5 * a)))->toInteger() + (a mod 2)), 10 * b}->max())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from functools import reduce from collections import deque import sys sys.setrecursionlimit(10**7) def get_nums_l(): return[int(s)for s in input().split(" ")] def get_nums_n(n): return[int(input())for _ in range(n)] def get_all_int(): return map(int,open(0).read().split()) def log(*args): print("DEBUG:",*args,file=sys.stderr) a,b=get_nums_l() for x in range(10000): if int(x*0.08)==a and int(x*0.1)==b : print(x) exit() print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; skip ; skip ; skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := get_nums_l() ; for x : Integer.subrange(0, 10000-1) do ( if ("" + ((x * 0.08)))->toInteger() = a & ("" + ((x * 0.1)))->toInteger() = b then ( execute (x)->display() ; exit() ) else skip) ; execute (-1)->display(); operation get_nums_l() : OclAny pre: true post: true activity: return input().split(" ")->select(s | true)->collect(s | (("" + ((s)))->toInteger())); operation get_nums_n(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())); operation get_all_int() : OclAny pre: true post: true activity: return (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ); operation log(args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) execute ("DEBUG:")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findExtra(arr1,arr2,n): for i in range(0,n): if(arr1[i]!=arr2[i]): return i return n arr1=[2,4,6,8,10,12,13] arr2=[2,4,6,8,10,12] n=len(arr2) print(findExtra(arr1,arr2,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr1 := Sequence{2}->union(Sequence{4}->union(Sequence{6}->union(Sequence{8}->union(Sequence{10}->union(Sequence{12}->union(Sequence{ 13 })))))) ; arr2 := Sequence{2}->union(Sequence{4}->union(Sequence{6}->union(Sequence{8}->union(Sequence{10}->union(Sequence{ 12 }))))) ; n := (arr2)->size() ; execute (findExtra(arr1, arr2, n))->display(); operation findExtra(arr1 : OclAny, arr2 : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if (arr1[i+1] /= arr2[i+1]) then ( return i ) else skip) ; return n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def search(arr,start,end,value): for i in range(start,end+1): if arr[i]==value : return i return-1 def getHeight(inOrder,levelOrder,start,end,height,n): if start>end : return 0 getIndex=search(inOrder,start,end,levelOrder[0]) if getIndex==-1 : return 0 leftCount=getIndex-start rightCount=end-getIndex newLeftLevel=[None for _ in range(leftCount)] newRightLevel=[None for _ in range(rightCount)] lheight,rheight,k=0,0,0 for i in range(n): for j in range(start,getIndex): if levelOrder[i]==inOrder[j]: newLeftLevel[k]=levelOrder[i] k+=1 break k=0 for i in range(n): for j in range(getIndex+1,end+1): if levelOrder[i]==inOrder[j]: newRightLevel[k]=levelOrder[i] k+=1 break if leftCount>0 : lheight=getHeight(inOrder,newLeftLevel,start,getIndex-1,height,leftCount) if rightCount>0 : rheight=getHeight(inOrder,newRightLevel,getIndex+1,end,height,rightCount) height=max(lheight+1,rheight+1) return height if __name__=='__main__' : inOrder=[4,8,10,12,14,20,22] levelOrder=[20,8,22,4,12,10,14] n,h=len(inOrder),0 print(getHeight(inOrder,levelOrder,0,n-1,h,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( inOrder := Sequence{4}->union(Sequence{8}->union(Sequence{10}->union(Sequence{12}->union(Sequence{14}->union(Sequence{20}->union(Sequence{ 22 })))))) ; levelOrder := Sequence{20}->union(Sequence{8}->union(Sequence{22}->union(Sequence{4}->union(Sequence{12}->union(Sequence{10}->union(Sequence{ 14 })))))) ; var h : OclAny := null; Sequence{n,h} := Sequence{(inOrder)->size(),0} ; execute (getHeight(inOrder, levelOrder, 0, n - 1, h, n))->display() ) else skip; operation search(arr : OclAny, start : OclAny, end : OclAny, value : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(start, end + 1-1) do ( if arr[i+1] = value then ( return i ) else skip) ; return -1; operation getHeight(inOrder : OclAny, levelOrder : OclAny, start : OclAny, end : OclAny, height : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (start->compareTo(end)) > 0 then ( return 0 ) else skip ; var getIndex : OclAny := search(inOrder, start, end, levelOrder->first()) ; if getIndex = -1 then ( return 0 ) else skip ; var leftCount : double := getIndex - start ; var rightCount : double := end - getIndex ; var newLeftLevel : Sequence := Integer.subrange(0, leftCount-1)->select(_anon | true)->collect(_anon | (null)) ; var newRightLevel : Sequence := Integer.subrange(0, rightCount-1)->select(_anon | true)->collect(_anon | (null)) ; var lheight : OclAny := null; var rheight : OclAny := null; var k : OclAny := null; Sequence{lheight,rheight,k} := Sequence{0,0,0} ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(start, getIndex-1) do ( if levelOrder[i+1] = inOrder[j+1] then ( newLeftLevel[k+1] := levelOrder[i+1] ; k := k + 1 ; break ) else skip)) ; var k : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(getIndex + 1, end + 1-1) do ( if levelOrder[i+1] = inOrder[j+1] then ( newRightLevel[k+1] := levelOrder[i+1] ; k := k + 1 ; break ) else skip)) ; if leftCount > 0 then ( var lheight : OclAny := getHeight(inOrder, newLeftLevel, start, getIndex - 1, height, leftCount) ) else skip ; if rightCount > 0 then ( var rheight : OclAny := getHeight(inOrder, newRightLevel, getIndex + 1, end, height, rightCount) ) else skip ; height := Set{lheight + 1, rheight + 1}->max() ; return height; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _MIN=-2147483648 _MAX=2147483648 class newnode : def __init__(self,data): self.data=data self.left=None self.right=None def getDeepestRightLeafNode(root): if(not root): return None q=[] q.append(root) result=None while(len(q)): temp=q[0] q.pop(0) if(temp.left): q.append(temp.left) if(temp.right): q.append(temp.right) if(not temp.right.left and not temp.right.right): result=temp.right return result if __name__=='__main__' : root=newnode(1) root.left=newnode(2) root.right=newnode(3) root.left.right=newnode(4) root.right.left=newnode(5) root.right.right=newnode(6) root.right.left.right=newnode(7) root.right.right.right=newnode(8) root.right.left.right.left=newnode(9) root.right.right.right.right=newnode(10) result=getDeepestRightLeafNode(root) if result : print("Deepest Right Leaf Node ::",result.data) else : print("No result,right leaf not found") ------------------------------------------------------------ OCL File: --------- class newnode { static operation newnewnode() : newnode pre: true post: newnode->exists( _x | result = _x ); attribute data : OclAny := data; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(data : OclAny) : newnode pre: true post: true activity: self.data := data ; self.left := null ; self.right := null; return self; } class FromPython { operation initialise() pre: true post: true activity: var _MIN : int := -2147483648 ; var _MAX : int := 2147483648 ; skip ; skip ; if __name__ = '__main__' then ( root := (newnode.newnewnode()).initialise(1) ; root.left := (newnode.newnewnode()).initialise(2) ; root.right := (newnode.newnewnode()).initialise(3) ; root.left.right := (newnode.newnewnode()).initialise(4) ; root.right.left := (newnode.newnewnode()).initialise(5) ; root.right.right := (newnode.newnewnode()).initialise(6) ; root.right.left.right := (newnode.newnewnode()).initialise(7) ; root.right.right.right := (newnode.newnewnode()).initialise(8) ; root.right.left.right.left := (newnode.newnewnode()).initialise(9) ; root.right.right.right.right := (newnode.newnewnode()).initialise(10) ; result := getDeepestRightLeafNode(root) ; if result then ( execute ("Deepest Right Leaf Node ::")->display() ) else ( execute ("No result,right leaf not found")->display() ) ) else skip; operation getDeepestRightLeafNode(root : OclAny) : OclAny pre: true post: true activity: if (not(root)) then ( return null ) else skip ; var q : Sequence := Sequence{} ; execute ((root) : q) ; var result : OclAny := null ; while ((q)->size()) do ( var temp : OclAny := q->first() ; q := q->excludingAt(0+1) ; if (temp.left) then ( execute ((temp.left) : q) ) else skip ; if (temp.right) then ( execute ((temp.right) : q) ; if (not(temp.right.left) & not(temp.right.right)) then ( result := temp.right ) else skip ) else skip) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from typing import Tuple def get_zone(t,unified_times): if tunified_times[2]: return 3 if t>unified_times[0]and tunified_times[1]and tstr : h,m,s=time unified_times=[] t1=t1*60*60 t2=t2*60*60 unified_times.append(h*3600+m*60+s) unified_times.append(m*720+s*12) unified_times.append(s*720) unified_times.sort() if get_zone(t1,unified_times)==get_zone(t2,unified_times): return 'YES' return 'NO' def main(): inp=input() h,m,s,t1,t2=[int(i)for i in inp.split()] print(can_prepare_contest([h,m,s],t1,t2)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; main(); operation get_zone(t : OclAny, unified_times : OclAny) : OclAny pre: true post: true activity: if (t->compareTo(unified_times->first())) < 0 or (t->compareTo(unified_times[2+1])) > 0 then ( return 3 ) else skip ; if (t->compareTo(unified_times->first())) > 0 & (t->compareTo(unified_times[1+1])) < 0 then ( return 1 ) else skip ; if (t->compareTo(unified_times[1+1])) > 0 & (t->compareTo(unified_times[2+1])) < 0 then ( return 2 ) else skip; operation can_prepare_contest(time : Tuple[OclType["int"]+1][OclType["int"]+1][OclType["int"]+1], t1 : int, t2 : int) : String pre: true post: true activity: var h : OclAny := null; var m : OclAny := null; var s : OclAny := null; Sequence{h,m,s} := time ; unified_times := Sequence{} ; var t1 : int := t1 * 60 * 60 ; var t2 : int := t2 * 60 * 60 ; execute ((h * 3600 + m * 60 + s) : unified_times) ; execute ((m * 720 + s * 12) : unified_times) ; execute ((s * 720) : unified_times) ; unified_times := unified_times->sort() ; if get_zone(t1, unified_times) = get_zone(t2, unified_times) then ( return 'YES' ) else skip ; return 'NO'; operation main() pre: true post: true activity: var inp : String := (OclFile["System.in"]).readLine() ; var h : OclAny := null; var m : OclAny := null; var s : OclAny := null; Sequence{h,m,s,t1,t2} := inp.split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute (can_prepare_contest(Sequence{h}->union(Sequence{m}->union(Sequence{ s })), t1, t2))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,m,s,t1,t2=map(int,input().split()) c=[0]*3600*12 h=h % 12 t1=t1 % 12 t2=t2 % 12 c[3600*h+60*m+s]=1 c[720*m+12*s]=1 c[720*s]=1 t1,t2=min(t1,t2),max(t1,t2) t1*=3600 t2*=3600 flag=False for i in range(t1+1,t2): if(c[i]): flag=True break if(not flag): print('YES') else : flag=False for i in range(3600*12-1,t2,-1): if(c[i]): flag=True break for i in range(t1): if(c[i]): flag=True break if(not flag): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var m : OclAny := null; var s : OclAny := null; var t1 : OclAny := null; var t2 : OclAny := null; Sequence{h,m,s,t1,t2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : Sequence := MatrixLib.elementwiseMult(MatrixLib.elementwiseMult(Sequence{ 0 }, 3600), 12) ; var h : int := h mod 12 ; var t1 : int := t1 mod 12 ; var t2 : int := t2 mod 12 ; c[3600 * h + 60 * m + s+1] := 1 ; c[720 * m + 12 * s+1] := 1 ; c[720 * s+1] := 1 ; Sequence{t1,t2} := Sequence{Set{t1, t2}->min(),Set{t1, t2}->max()} ; t1 := t1 * 3600 ; t2 := t2 * 3600 ; var flag : boolean := false ; for i : Integer.subrange(t1 + 1, t2-1) do ( if (c[i+1]) then ( flag := true ; break ) else skip) ; if (not(flag)) then ( execute ('YES')->display() ) else ( flag := false ; for i : Integer.subrange(t2 + 1, 3600 * 12 - 1)->reverse() do ( if (c[i+1]) then ( flag := true ; break ) else skip) ; for i : Integer.subrange(0, t1-1) do ( if (c[i+1]) then ( flag := true ; break ) else skip) ; if (not(flag)) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): cnt_1,cnt_2,cnt_3,cnt_4=map(int,[input()for i in range(4)]) open=0 closed=0 if cnt_1==0 and cnt_4==0 and cnt_3>0 : print(0) return open+=cnt_1*2 open+=cnt_3 closed+=cnt_4*2 closed+=cnt_3 if closed-open==0 : print(1) else : print(0) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: var cntcnt skip,cnt:= (Integer.subrange(0, 4-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())))->collect( _x | (OclType["int"])->apply(_x) ),cnt_3,cnt_4 : OclAny := null; var cnt:= (Integer.subrange(0, 4-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())))->collect( _x | (OclType["int"])->apply(_x) ) : OclAny := null; var cnt_3 : OclAny := null; var cnt_4 : OclAny := null; Sequence{cnt skip,cnt:= (Integer.subrange(0, 4-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())))->collect( _x | (OclType["int"])->apply(_x) ),cnt_3,cnt_4} := (Integer.subrange(0, 4-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())))->collect( _x | (OclType["int"])->apply(_x) ) ; var open : int := 0 ; var closed : int := 0 ; if cnt var cntcnt skip,cnt:= (Integer.subrange(0, 4-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())))->collect( _x | (OclType["int"])->apply(_x) ),cnt_3,cnt_4 : OclAny := null; var cnt:= (Integer.subrange(0, 4-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())))->collect( _x | (OclType["int"])->apply(_x) ) : OclAny := null; var cnt_3 : OclAny := null; var cnt_4 : OclAny := null; Sequence{cnt skip,cnt:= (Integer.subrange(0, 4-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())))->collect( _x | (OclType["int"])->apply(_x) ),cnt_3,cnt_4} := (Integer.subrange(0, 4-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())))->collect( _x | (OclType["int"])->apply(_x) ) = 0 & cnt_4 = 0 & cnt_3 > 0 then ( execute (0)->display() ; return ) else skip ; open := open + cnt var cntcnt skip,cnt:= (Integer.subrange(0, 4-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())))->collect( _x | (OclType["int"])->apply(_x) ),cnt_3,cnt_4 : OclAny := null; var cnt:= (Integer.subrange(0, 4-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())))->collect( _x | (OclType["int"])->apply(_x) ) : OclAny := null; var cnt_3 : OclAny := null; var cnt_4 : OclAny := null; Sequence{cnt skip,cnt:= (Integer.subrange(0, 4-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())))->collect( _x | (OclType["int"])->apply(_x) ),cnt_3,cnt_4} := (Integer.subrange(0, 4-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())))->collect( _x | (OclType["int"])->apply(_x) ) * 2 ; open := open + cnt_3 ; closed := closed + cnt_4 * 2 ; closed := closed + cnt_3 ; if closed - open = 0 then ( execute (1)->display() ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def mn_range(arr): mn=min(arr) mx=max(arr) return[mn,mx] def y_n(arr,r_arr,h,m,s): if h not in arr and m not in arr and s not in arr : print("yes") elif h not in r_arr and m not in r_arr and s not in r_arr : print("yes") else : print("no") def r_rr(arr): r_arr=[int(i)for i in range(arr[1],13)] for i in range(1,arr[0]): r_arr.append(i) return(r_arr) a=[int(i)for i in input().split()] h=a[0] m=a[1] s=a[2] p=a[3] to=a[4] b=mn_range([p,to]) if m>0 or s>0 : arr=[i for i in range(b[0],b[1])] else : arr=[i for i in range(b[0]+1,b[1])] m=int(m/5) s=int(s/5) if m==0 : m=12 if s==0 : s=12 r_arr=r_rr(b) y_n(arr,r_arr,h,m,s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; h := a->first() ; m := a[1+1] ; s := a[2+1] ; var p : OclAny := a[3+1] ; var to : OclAny := a[4+1] ; var b : OclAny := mn_range(Sequence{p}->union(Sequence{ to })) ; if m > 0 or s > 0 then ( arr := Integer.subrange(b->first(), b[1+1]-1)->select(i | true)->collect(i | (i)) ) else ( arr := Integer.subrange(b->first() + 1, b[1+1]-1)->select(i | true)->collect(i | (i)) ) ; m := ("" + ((m / 5)))->toInteger() ; s := ("" + ((s / 5)))->toInteger() ; if m = 0 then ( m := 12 ) else skip ; if s = 0 then ( s := 12 ) else skip ; r_arr := r_rr(b) ; y_n(arr, r_arr, h, m, s); operation mn_range(arr : OclAny) : OclAny pre: true post: true activity: var mn : OclAny := (arr)->min() ; var mx : OclAny := (arr)->max() ; return Sequence{mn}->union(Sequence{ mx }); operation y_n(arr : OclAny, r_arr : OclAny, h : OclAny, m : OclAny, s : OclAny) pre: true post: true activity: if (arr)->excludes(h) & (arr)->excludes(m) & (arr)->excludes(s) then ( execute ("yes")->display() ) else (if (r_arr)->excludes(h) & (r_arr)->excludes(m) & (r_arr)->excludes(s) then ( execute ("yes")->display() ) else ( execute ("no")->display() ) ) ; operation r_rr(arr : OclAny) : OclAny pre: true post: true activity: r_arr := Integer.subrange(arr[1+1], 13-1)->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; for i : Integer.subrange(1, arr->first()-1) do ( execute ((i) : r_arr)) ; return (r_arr); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from typing import Tuple def get_zone(t,unified_times): if t>unified_times[0]and tunified_times[1]and tstr : h,m,s=time unified_times=[] t1=t1*60*60 t2=t2*60*60 unified_times.append(h*3600+m*60+s) unified_times.append(m*720+s*12) unified_times.append(s*720) unified_times.sort() if get_zone(t1,unified_times)==get_zone(t2,unified_times): return 'YES' return 'NO' def main(): inp=input() h,m,s,t1,t2=[int(i)for i in inp.split()] print(can_prepare_contest([h,m,s],t1,t2)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; main(); operation get_zone(t : OclAny, unified_times : OclAny) : OclAny pre: true post: true activity: if (t->compareTo(unified_times->first())) > 0 & (t->compareTo(unified_times[1+1])) < 0 then ( return 1 ) else skip ; if (t->compareTo(unified_times[1+1])) > 0 & (t->compareTo(unified_times[2+1])) < 0 then ( return 2 ) else skip ; return 3; operation can_prepare_contest(time : Tuple[OclType["int"]+1][OclType["int"]+1][OclType["int"]+1], t1 : int, t2 : int) : String pre: true post: true activity: var h : OclAny := null; var m : OclAny := null; var s : OclAny := null; Sequence{h,m,s} := time ; unified_times := Sequence{} ; var t1 : int := t1 * 60 * 60 ; var t2 : int := t2 * 60 * 60 ; execute ((h * 3600 + m * 60 + s) : unified_times) ; execute ((m * 720 + s * 12) : unified_times) ; execute ((s * 720) : unified_times) ; unified_times := unified_times->sort() ; if get_zone(t1, unified_times) = get_zone(t2, unified_times) then ( return 'YES' ) else skip ; return 'NO'; operation main() pre: true post: true activity: var inp : String := (OclFile["System.in"]).readLine() ; var h : OclAny := null; var m : OclAny := null; var s : OclAny := null; Sequence{h,m,s,t1,t2} := inp.split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute (can_prepare_contest(Sequence{h}->union(Sequence{m}->union(Sequence{ s })), t1, t2))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def subarrayXor(arr,n,m): ans=0 for i in range(0,n): xorSum=0 for j in range(i,n): xorSum=xorSum ^ arr[j] if(xorSum==m): ans+=1 return ans def main(): arr=[4,2,2,6,4] n=len(arr) m=6 print("Number of subarrays having given XOR is ",subarrayXor(arr,n,m)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation subarrayXor(arr : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var xorSum : int := 0 ; for j : Integer.subrange(i, n-1) do ( xorSum := MathLib.bitwiseXor(xorSum, arr[j+1]) ; if (xorSum = m) then ( ans := ans + 1 ) else skip)) ; return ans; operation main() pre: true post: true activity: arr := Sequence{4}->union(Sequence{2}->union(Sequence{2}->union(Sequence{6}->union(Sequence{ 4 })))) ; n := (arr)->size() ; m := 6 ; execute ("Number of subarrays having given XOR is ")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=[int(x)for x in input().strip().split(" ")] m=~-n*(n-2)//2 if k>m : print(-1) else : m-=k print(m+n-1) for i in range(1,n): print(i,n) for i in range(1,n): for j in range(i+1,n): if m==0 : break print(i,j) m-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input()->trim().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var m : int := MathLib.bitwiseNot(-n) * (n - 2) div 2 ; if (k->compareTo(m)) > 0 then ( execute (-1)->display() ) else ( m := m - k ; execute (m + n - 1)->display() ; for i : Integer.subrange(1, n-1) do ( execute (i)->display()) ; for i : Integer.subrange(1, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if m = 0 then ( break ) else skip ; execute (i)->display() ; m := m - 1)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,k=[int(x)for x in input().split()] ans=[] for i in range(2,n+1): ans.append([1,i]) dic2=(n-1)*(n-2)//2 if k>dic2 : print(-1) sys.exit() a=2 b=3 while kn : a+=1 b=a+1 if a>=n and dic2>k : print(-1) sys.exit() print(len(ans)) for i in ans : print(*i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(2, n + 1-1) do ( execute ((Sequence{1}->union(Sequence{ i })) : ans)) ; var dic2 : int := (n - 1) * (n - 2) div 2 ; if (k->compareTo(dic2)) > 0 then ( execute (-1)->display() ; sys.exit() ) else skip ; var a : int := 2 ; var b : int := 3 ; while (k->compareTo(dic2)) < 0 do ( execute ((Sequence{a}->union(Sequence{ b })) : ans) ; dic2 := dic2 - 1 ; b := b + 1 ; if (b->compareTo(n)) > 0 then ( a := a + 1 ; b := a + 1 ) else skip ; if (a->compareTo(n)) >= 0 & (dic2->compareTo(k)) > 0 then ( execute (-1)->display() ; sys.exit() ) else skip) ; execute ((ans)->size())->display() ; for i : ans do ( execute ((argument * (test (logical_test (comparison (expr (atom (name i))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,input().split()) max_edge=(N-1)*(N-2)//2 all_edges=[[i,j]for i in range(N)for j in range(i+1,N)] if 0<=K<=max_edge : minus=max_edge-K count=0 answer=[] for edge in all_edges : if edge[0]==0 : answer.append(edge) elif countcollect( _x | (OclType["int"])->apply(_x) ) ; var max_edge : int := (N - 1) * (N - 2) div 2 ; var all_edges : Sequence := Integer.subrange(0, N-1)->select(i; j : Integer.subrange(i + 1, N-1) | true)->collect(i; j : Integer.subrange(i + 1, N-1) | (Sequence{i}->union(Sequence{ j }))) ; if 0 <= K & (K <= max_edge) then ( var minus : double := max_edge - K ; var count : int := 0 ; var answer : Sequence := Sequence{} ; for edge : all_edges do ( if edge->first() = 0 then ( execute ((edge) : answer) ) else (if (count->compareTo(minus)) < 0 then ( execute ((edge) : answer) ; count := count + 1 ) else skip)) ; execute ((answer)->size())->display() ; for i : Integer.subrange(0, (answer)->size()-1) do ( execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 1)))))))))) ))))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name answer)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))), (" ")))->display()) ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter from collections import deque from functools import reduce from pprint import pprint import bisect import copy import fractions import itertools import math import queue import random import sys import time sys.setrecursionlimit(10**7) INF=10**18 MOD=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def MI(): return map(int,sys.stdin.readline().split()) def II(): return int(sys.stdin.readline()) def IS(): return input() def C(x): return Counter(x) def GCD_LIST(numbers): return reduce(fractions.gcd,numbers) def LCM_LIST(numbers): return reduce(LCM,numbers) def LCM(m,n): return(m*n//fractions.gcd(m,n)) n,k=MI() if((n-1)*(n-2))//2pow(7)) ; var INF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var k : OclAny := null; Sequence{n,k} := MI() ; if (((n - 1) * (n - 2)) div 2->compareTo(k)) < 0 then ( execute (-1)->display() ) else ( m := (n * (n - 1)) div 2 - k ; execute (m)->display() ; var graph : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(i, n + 1-1) do ( if i /= j then ( execute ((Sequence{i}->union(Sequence{ j })) : graph) ) else skip)) ; for i : Integer.subrange(0, m-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))->display()) ); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation IS() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation C(x : OclAny) : OclAny pre: true post: true activity: return Counter(x); operation GCD_LIST(numbers : OclAny) : OclAny pre: true post: true activity: return reduce(fractions.gcd, numbers); operation LCM_LIST(numbers : OclAny) : OclAny pre: true post: true activity: return reduce(LCM, numbers); operation LCM(m : OclAny, n : OclAny) : OclAny pre: true post: true activity: return (m * n div fractions.gcd(m, n)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _MIN=-2147483648 _MAX=2147483648 class newnode : def __init__(self,data): self.data=data self.left=None self.right=None def getDeepestLeftLeafNode(root): if(not root): return None q=[] q.append(root) result=None while(len(q)): temp=q[0] q.pop(0) if(temp.left): q.append(temp.left) if(not temp.left.left and not temp.left.right): result=temp.left if(temp.right): q.append(temp.right) return result if __name__=='__main__' : root=newnode(1) root.left=newnode(2) root.right=newnode(3) root.left.Left=newnode(4) root.right.left=newnode(5) root.right.right=newnode(6) root.right.left.right=newnode(7) root.right.right.right=newnode(8) root.right.left.right.left=newnode(9) root.right.right.right.right=newnode(10) result=getDeepestLeftLeafNode(root) if result : print("Deepest Left Leaf Node ::",result.data) else : print("No result,Left leaf not found") ------------------------------------------------------------ OCL File: --------- class newnode { static operation newnewnode() : newnode pre: true post: newnode->exists( _x | result = _x ); attribute data : OclAny := data; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(data : OclAny) : newnode pre: true post: true activity: self.data := data ; self.left := null ; self.right := null; return self; } class FromPython { operation initialise() pre: true post: true activity: var _MIN : int := -2147483648 ; var _MAX : int := 2147483648 ; skip ; skip ; if __name__ = '__main__' then ( root := (newnode.newnewnode()).initialise(1) ; root.left := (newnode.newnewnode()).initialise(2) ; root.right := (newnode.newnewnode()).initialise(3) ; root.left.Left := (newnode.newnewnode()).initialise(4) ; root.right.left := (newnode.newnewnode()).initialise(5) ; root.right.right := (newnode.newnewnode()).initialise(6) ; root.right.left.right := (newnode.newnewnode()).initialise(7) ; root.right.right.right := (newnode.newnewnode()).initialise(8) ; root.right.left.right.left := (newnode.newnewnode()).initialise(9) ; root.right.right.right.right := (newnode.newnewnode()).initialise(10) ; result := getDeepestLeftLeafNode(root) ; if result then ( execute ("Deepest Left Leaf Node ::")->display() ) else ( execute ("No result,Left leaf not found")->display() ) ) else skip; operation getDeepestLeftLeafNode(root : OclAny) : OclAny pre: true post: true activity: if (not(root)) then ( return null ) else skip ; var q : Sequence := Sequence{} ; execute ((root) : q) ; var result : OclAny := null ; while ((q)->size()) do ( var temp : OclAny := q->first() ; q := q->excludingAt(0+1) ; if (temp.left) then ( execute ((temp.left) : q) ; if (not(temp.left.left) & not(temp.left.right)) then ( result := temp.left ) else skip ) else skip ; if (temp.right) then ( execute ((temp.right) : q) ) else skip) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sol_act(n,k): from itertools import combinations if k>(n-1)*(n-2)//2 : return-1 res=set((i,n)for i in range(1,n)) for _,c in zip(range((n-1)*(n-2)//2-k),combinations(range(1,n),2)): res.add(c) return res def sol(inp=input): n,k=map(int,inp().split()) res=sol_act(n,k) if res==-1 : return('-1') return '\n'.join([str(len(res))]+['{}{}'.format(*l)for l in res]) print(sol()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; execute (sol())->display(); operation sol_act(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: skip ; if (k->compareTo((n - 1) * (n - 2) div 2)) > 0 then ( return -1 ) else skip ; var res : Set := Set{}->union(((argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) , (test (logical_test (comparison (expr (atom (name n))))))) )))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))) ; for _tuple : Integer.subrange(1, Integer.subrange(0, (n - 1) * (n - 2) div 2 - k-1)->size())->collect( _indx | Sequence{Integer.subrange(0, (n - 1) * (n - 2) div 2 - k-1)->at(_indx), combinations(Integer.subrange(1, n-1), 2)->at(_indx)} ) do (var _indx : int := 1; var _anon : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); execute ((c) : res)) ; return res; operation sol(inp : OclAny) : OclAny pre: true post: true activity: if inp->oclIsUndefined() then inp := input else skip; Sequence{n,k} := (inp().split())->collect( _x | (OclType["int"])->apply(_x) ) ; res := sol_act(n, k) ; if res = -1 then ( return ('-1') ) else skip ; return StringLib.sumStringsWithSeparator((Sequence{ ("" + (((res)->size()))) }->union(res->select(l | true)->collect(l | (StringLib.interpolateStrings('{}{}', Sequence{(argument * (test (logical_test (comparison (expr (atom (name l)))))))}))))), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSmallest(a,n): for i in range(0,n): for j in range(0,n): if((a[j]% a[i])>=1): break if(j==n-1): return a[i] return-1 a=[25,20,5,10,100] n=len(a) print(findSmallest(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{25}->union(Sequence{20}->union(Sequence{5}->union(Sequence{10}->union(Sequence{ 100 })))) ; n := (a)->size() ; execute (findSmallest(a, n))->display(); operation findSmallest(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if ((a[j+1] mod a[i+1]) >= 1) then ( break ) else skip) ; if (j = n - 1) then ( return a[i+1] ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left,bisect_right,insort_left dict={} keytbl=[] q=int(input()) for i in range(q): a=list(input().split()) ki=a[1] if a[0]=='0' : if ki not in dict : insort_left(keytbl,ki) dict[ki]=int(a[2]) elif a[0]=='1' : print(dict[ki]if ki in dict else 0) elif a[0]=='2' : if ki in dict : dict[ki]=0 else : L=bisect_left(keytbl,a[1]) R=bisect_right(keytbl,a[2],L) for j in range(L,R): if dict[keytbl[j]]>0 : print(keytbl[j],dict[keytbl[j]]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var OclType["Map"] : OclAny := Set{} ; var keytbl : Sequence := Sequence{} ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( var a : Sequence := (input().split()) ; var ki : OclAny := a[1+1] ; if a->first() = '0' then ( if (OclType["Map"])->excludes(ki) then ( insort_left(keytbl, ki) ) else skip ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ki)))))))) ]) := ("" + ((a[2+1])))->toInteger() ) else (if a->first() = '1' then ( execute (if (OclType["Map"])->includes(ki) then (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ki)))))))) ]) else 0 endif)->display() ) else (if a->first() = '2' then ( if (OclType["Map"])->includes(ki) then ( (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ki)))))))) ]) := 0 ) else skip ) else ( var L : OclAny := bisect_left(keytbl, a[1+1]) ; var R : OclAny := bisect_right(keytbl, a[2+1], L) ; for j : Integer.subrange(L, R-1) do ( if (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name keytbl)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) ]) > 0 then ( execute (keytbl[j+1])->display() ) else skip) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) c=int(input()) d=int(input()) print(int(a==d and(c==0 or a>0))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (("" + ((a = d & (c = 0 or a > 0))))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def resolve(): import sys import bisect input=sys.stdin.readline n=int(input()) ans=dict() need_sort=True sorted_keys=None for _ in range(n): q,key,*x=input().split() if q=="0" : if key in ans : ans[key]=x[0] else : ans[key]=x[0] need_sort=True elif q=="1" : if key in ans : print(ans[key]) else : print(0) elif q=="2" : ans[key]="0" else : if sorted_keys is None : sorted_keys=sorted(ans.keys()) if need_sort : sorted_keys=sorted(ans.keys()) need_sort=False l,r=key,x[0] fr=bisect.bisect_left(sorted_keys,l) to=bisect.bisect_right(sorted_keys,r) for i in range(fr,to): if ans[sorted_keys[i]]!="0" : print(sorted_keys[i],ans[sorted_keys[i]]) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; resolve(); operation resolve() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Map := (arguments ( )) ; var need_sort : boolean := true ; var sorted_keys : OclAny := null ; for _anon : Integer.subrange(0, n-1) do ( var q : OclAny := null; var key : OclAny := null; var x : OclAny := null; Sequence{q,key,x} := input().split() ; if q = "0" then ( if (ans)->includes(key) then ( ans[key+1] := x->first() ) else ( ans[key+1] := x->first() ; need_sort := true ) ) else (if q = "1" then ( if (ans)->includes(key) then ( execute (ans[key+1])->display() ) else ( execute (0)->display() ) ) else (if q = "2" then ( ans[key+1] := "0" ) else ( if sorted_keys <>= null then ( sorted_keys := ans.keys()->sort() ) else skip ; if need_sort then ( sorted_keys := ans.keys()->sort() ; need_sort := false ) else skip ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{key,x->first()} ; var fr : OclAny := bisect.bisect_left(sorted_keys, l) ; var to : OclAny := bisect.bisect_right(sorted_keys, r) ; for i : Integer.subrange(fr, to-1) do ( if ans[sorted_keys[i+1]+1] /= "0" then ( execute (sorted_keys[i+1])->display() ) else skip) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import insort,bisect_right,bisect_left class Range_map : def __init__(self): self.rm=dict() self.lr=[] def insert(self,x,y): if x not in self.rm : insort(self.lr,x) self.rm[x]=y def get(self,x): print(self.rm.get(x,0)) def delete(self,x): if x in self.rm : self.rm[x]=0 def dump(self,l,r): lb=bisect_left(self.lr,l) ub=bisect_right(self.lr,r) for i in range(lb,ub): k=self.lr[i] if k in self.rm and self.rm[k]!=0 : print(f'{k}{self.rm[k]}') rm=Range_map() for _ in range(int(input())): op,x,y=(input()+' 1').split()[: 3] if op=='0' : rm.insert(x,int(y)) elif op=='1' : rm.get(x) elif op=='2' : rm.delete(x) else : rm.dump(x,y) ------------------------------------------------------------ OCL File: --------- class Range_map { static operation newRange_map() : Range_map pre: true post: Range_map->exists( _x | result = _x ); attribute rm : Map := (arguments ( )); attribute lr : Sequence := Sequence{}; operation initialise() : Range_map pre: true post: true activity: self.rm := (arguments ( )) ; self.lr := Sequence{}; return self; operation insert(x : OclAny,y : OclAny) pre: true post: true activity: if (self.rm)->excludes(x) then ( insort(self.lr, x) ) else skip ; self.rm[x+1] := y; operation get(x : OclAny) pre: true post: true activity: execute (self.rm.get(x, 0))->display(); operation delete(x : OclAny) pre: true post: true activity: if (self.rm)->includes(x) then ( self.rm[x+1] := 0 ) else skip; operation dump(l : OclAny,r : OclAny) pre: true post: true activity: var lb : OclAny := bisect_left(self.lr, l) ; var ub : OclAny := bisect_right(self.lr, r) ; for i : Integer.subrange(lb, ub-1) do ( var k : OclAny := self.lr[i+1] ; if (self.rm)->includes(k) & self.rm[k+1] /= 0 then ( execute (StringLib.formattedString('{k}{self.rm[k]}'))->display() ) else skip); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var rm : Range_map := (Range_map.newRange_map()).initialise() ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var op : OclAny := null; Sequence{op,x,y} := ((OclFile["System.in"]).readLine() + ' 1').split().subrange(1,3) ; if op = '0' then ( rm := rm.insertAt(x+1, ("" + ((y)))->toInteger()) ) else (if op = '1' then ( rm.get(x) ) else (if op = '2' then ( rm.delete(x) ) else ( rm.dump(x, y) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) s=[] rs=[] for i in range(q): s.append(input().split()) if s[i][0]=='3' : rs.append(s[i][1]) rs.append(s[i][2]) else : rs.append(s[i][1]) rs=sorted(list(set(rs))) index={rs[i]: i for i in range(len(rs))} d=[None for i in range(len(rs))] for i in range(q): op,key=int(s[i][0]),s[i][1] idx=index[key] if op==0 : d[idx]=s[i][2] elif op==1 : if d[idx]==None : print(0) else : print(d[idx]) elif op==2 : d[idx]=None else : l=idx r=index[s[i][2]] for j in range(l,r+1): if d[j]!=None : print(rs[j],d[j]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := Sequence{} ; var rs : Sequence := Sequence{} ; for i : Integer.subrange(0, q-1) do ( execute ((input().split()) : s) ; if s[i+1]->first() = '3' then ( execute ((s[i+1][1+1]) : rs) ; execute ((s[i+1][2+1]) : rs) ) else ( execute ((s[i+1][1+1]) : rs) )) ; rs := (Set{}->union((rs)))->sort() ; var index : Map := Integer.subrange(0, (rs)->size()-1)->select(i | true)->collect(i | Map{rs[i+1] |-> i})->unionAll() ; var d : Sequence := Integer.subrange(0, (rs)->size()-1)->select(i | true)->collect(i | (null)) ; for i : Integer.subrange(0, q-1) do ( var op : OclAny := null; var key : OclAny := null; Sequence{op,key} := Sequence{("" + ((s[i+1]->first())))->toInteger(),s[i+1][1+1]} ; var idx : OclAny := index[key+1] ; if op = 0 then ( d[idx+1] := s[i+1][2+1] ) else (if op = 1 then ( if d[idx+1] = null then ( execute (0)->display() ) else ( execute (d[idx+1])->display() ) ) else (if op = 2 then ( d[idx+1] := null ) else ( var l : OclAny := idx ; var r : OclAny := index[s[i+1][2+1]+1] ; for j : Integer.subrange(l, r + 1-1) do ( if d[j+1] /= null then ( execute (rs[j+1])->display() ) else skip) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect q=int(input()) M={} list_key_sorted=[] for _ in range(q): command,*list_num=input().split() if command=="0" : key=list_num[0] x=int(list_num[1]) if key not in M : bisect.insort_left(list_key_sorted,key) M[key]=x elif command=="1" : key=list_num[0] if key in M : if M[key]==None : print(0) else : print(M[key]) else : print(0) elif command=="2" : key=list_num[0] if key in M : M[key]=None elif command=="3" : L=list_num[0] R=list_num[1] index_left=bisect.bisect_left(list_key_sorted,L) index_right=bisect.bisect_right(list_key_sorted,R) for index in range(index_left,index_right): key_ans=list_key_sorted[index] if M[key_ans]!=None : print(key_ans,M[key_ans]) else : raise ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var M : OclAny := Set{} ; var list_key_sorted : Sequence := Sequence{} ; for _anon : Integer.subrange(0, q-1) do ( var command : OclAny := null; var list_num : OclAny := null; Sequence{command,list_num} := input().split() ; if command = "0" then ( var key : OclAny := list_num->first() ; var x : int := ("" + ((list_num[1+1])))->toInteger() ; if (M)->excludes(key) then ( bisect.insort_left(list_key_sorted, key) ) else skip ; M[key+1] := x ) else (if command = "1" then ( key := list_num->first() ; if (M)->includes(key) then ( if M[key+1] = null then ( execute (0)->display() ) else ( execute (M[key+1])->display() ) ) else ( execute (0)->display() ) ) else (if command = "2" then ( key := list_num->first() ; if (M)->includes(key) then ( M[key+1] := null ) else skip ) else (if command = "3" then ( var L : OclAny := list_num->first() ; var R : OclAny := list_num[1+1] ; var index_left : OclAny := bisect.bisect_left(list_key_sorted, L) ; var index_right : OclAny := bisect.bisect_right(list_key_sorted, R) ; for index : Integer.subrange(index_left, index_right-1) do ( var key_ans : OclAny := list_key_sorted[index+1] ; if M[key_ans+1] /= null then ( execute (key_ans)->display() ) else skip) ) else ( (small_stmt raise) ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) l=list(map(int,input().split())) if 1 in l : print('HARD') else : print('EASY') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (l)->includes(1) then ( execute ('HARD')->display() ) else ( execute ('EASY')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=[int(x)for x in input().split()] for i in p : if i==1 : print('HARD') break else : print('EASY') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name p))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name i)))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'HARD'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'EASY'))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=2 b=1 for i in range(n-1): old_a=a a=b b=old_a+b print(b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := 2 ; var b : int := 1 ; for i : Integer.subrange(0, n - 1-1) do ( var old_a : int := a ; a := b ; b := old_a + b) ; execute (b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) if a.count(1)>=1 : print("HARD") else : print("EASY") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if a->count(1) >= 1 then ( execute ("HARD")->display() ) else ( execute ("EASY")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(x)for x in input().split(' ')] hard=a.count(1) if hard>0 : print('HARD') else : print('EASY') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var hard : int := a->count(1) ; if hard > 0 then ( execute ('HARD')->display() ) else ( execute ('EASY')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) res=input().split() if '1' in res : print("HARD") else : print("EASY") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : OclAny := input().split() ; if (res)->includes('1') then ( execute ("HARD")->display() ) else ( execute ("EASY")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter N=input() S=input().split('+') dic_chr_num=Counter(S) dic_num_kind=Counter(dic_chr_num.values()) ans=4*len(dic_chr_num)-1 for num,kind in dic_num_kind.items(): if num==1 : ans-=2*kind elif kind>=2 : ans-=2*(kind-2) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : String := (OclFile["System.in"]).readLine() ; var S : OclAny := input().split('+') ; var dic_chr_num : OclAny := Counter(S) ; var dic_num_kind : OclAny := Counter(dic_chr_num.values()) ; var ans : double := 4 * (dic_chr_num)->size() - 1 ; for _tuple : dic_num_kind->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var num : OclAny := _tuple->at(_indx); _indx := _indx + 1; var kind : OclAny := _tuple->at(_indx); if num = 1 then ( ans := ans - 2 * kind ) else (if kind >= 2 then ( ans := ans - 2 * (kind - 2) ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cnt=[0]*4 for i in range(0,4): cnt[i]=int(input()) if cnt[0]!=cnt[3]: res=0 elif cnt[0]==0 and cnt[2]!=0 : res=0 else : res=1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 4) ; for i : Integer.subrange(0, 4-1) do ( cnt[i+1] := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; if cnt->first() /= cnt[3+1] then ( var res : int := 0 ) else (if cnt->first() = 0 & cnt[2+1] /= 0 then ( res := 0 ) else ( res := 1 ) ) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() s=input().split('+') t=[s.count(x)for x in set(s)] a=sum(min(3*t.count(x),t.count(x)+4)for x in set(t)if x!=1)+len(t)-1+t.count(1) print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var s : OclAny := input().split('+') ; var t : Sequence := Set{}->union((s))->select(x | true)->collect(x | (s->count(x))) ; var a : double := ((argument (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (number (integer 3)))) * (expr (atom (name t)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name t)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) + (expr (atom (number (integer 4)))))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name x)))) != (comparison (expr (atom (number (integer 1))))))))))))->sum() + (t)->size() - 1 + t->count(1) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() s=input().split('+') t=[s.count(x)for x in set(s)] print(sum(min(3*t.count(x),t.count(x)+4)for x in set(t)if x!=1)+len(t)-1+t.count(1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var s : OclAny := input().split('+') ; var t : Sequence := Set{}->union((s))->select(x | true)->collect(x | (s->count(x))) ; execute (((argument (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (number (integer 3)))) * (expr (atom (name t)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name t)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) + (expr (atom (number (integer 4)))))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name x)))) != (comparison (expr (atom (number (integer 1))))))))))))->sum() + (t)->size() - 1 + t->count(1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() s=input() cs=s.split("+") ns=[] ds=[] for c in cs : cont=False i=0 for a in ds : if(a==c): cont=True ns[i]+=1 break i+=1 if(not cont): ds.append(c) ns.append(1) nums=[0 for i in range(9)] for n in ns : nums[n-1]+=1 res=0 res+=2*nums[0] for i in range(1,9): if(nums[i]>=3): res+=2*nums[i]+4 else : res+=4*nums[i] res-=1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var s : String := (OclFile["System.in"]).readLine() ; var cs : OclAny := s.split("+") ; var ns : Sequence := Sequence{} ; var ds : Sequence := Sequence{} ; for c : cs do ( var cont : boolean := false ; var i : int := 0 ; for a : ds do ( if (a = c) then ( cont := true ; ns[i+1] := ns[i+1] + 1 ; break ) else skip ; i := i + 1) ; if (not(cont)) then ( execute ((c) : ds) ; execute ((1) : ns) ) else skip) ; var nums : Sequence := Integer.subrange(0, 9-1)->select(i | true)->collect(i | (0)) ; for n : ns do ( nums[n - 1+1] := nums[n - 1+1] + 1) ; var res : int := 0 ; res := res + 2 * nums->first() ; for i : Integer.subrange(1, 9-1) do ( if (nums[i+1] >= 3) then ( res := res + 2 * nums[i+1] + 4 ) else ( res := res + 4 * nums[i+1] )) ; res := res - 1 ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n=int(input()) s=input() counter=Counter(s[0 : : 2]) counter2=Counter(counter.values()) ans=0 for k,v in counter2.items(): if k==1 : ans+=2*v else : if v==1 : ans+=4 else : ans+=4+v*2 print(ans-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var counter : OclAny := Counter(s(subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) ; var counter2 : OclAny := Counter(counter.values()) ; var ans : int := 0 ; for _tuple : counter2->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if k = 1 then ( ans := ans + 2 * v ) else ( if v = 1 then ( ans := ans + 4 ) else ( ans := ans + 4 + v * 2 ) )) ; execute (ans - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=list(map(int,input().split())) bits=list(bin(k+1)[2 :]) bits=list(map(int,bits)) stack=[0]*40 ans=0 for i in a : num=bin(i)[2 :] for j in range(len(num)): if num[j]=="1" : stack[len(num)-j-1]+=1 for i in range(len(bits)): possible_ans=[q for q in bits] ans_stack=0 if possible_ans[i]==0 : continue possible_ans[i]=0 for j in range(40): if jcollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var bits : Sequence := (bin(k + 1).subrange(2+1)) ; bits := ((bits)->collect( _x | (OclType["int"])->apply(_x) )) ; var stack : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 40) ; var ans : int := 0 ; for i : a do ( var num : OclAny := bin(i).subrange(2+1) ; for j : Integer.subrange(0, (num)->size()-1) do ( if num[j+1] = "1" then ( stack[(num)->size() - j - 1+1] := stack[(num)->size() - j - 1+1] + 1 ) else skip)) ; for i : Integer.subrange(0, (bits)->size()-1) do ( var possible_ans : Sequence := bits->select(q | true)->collect(q | (q)) ; var ans_stack : int := 0 ; if possible_ans[i+1] = 0 then ( continue ) else skip ; possible_ans[i+1] := 0 ; for j : Integer.subrange(0, 40-1) do ( if (j->compareTo((bits)->size() - i - 1)) < 0 then ( ans_stack := ans_stack + Set{stack[j+1] * (2)->pow(j), (n - stack[j+1]) * (2)->pow(j)}->max() ) else (if (j->compareTo((bits)->size())) < 0 & possible_ans[(bits)->size() - j - 1+1] = 1 then ( ans_stack := ans_stack + (n - stack[j+1]) * (2)->pow(j) ) else ( ans_stack := ans_stack + stack[j+1] * (2)->pow(j) ) ) ) ; ans := Set{ans, ans_stack}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import lru_cache @ lru_cache(maxsize=None) def ryuka(n): if n==0 : return 2 elif n==1 : return 1 else : return ryuka(n-1)+ryuka(n-2) N=int(input()) print(ryuka(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; (compound_stmt (decorator @ (dotted_name (name lru_cache)) ( (arglist (argument (test (logical_test (comparison (expr (atom (name maxsize)))))) = (test (logical_test (comparison (expr (atom None))))))) )) (funcdef def (name ryuka) ( (typedargslist (def_parameters (def_parameter (named_parameter (name n))))) ) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name n)))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 2)))))))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name n)))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (expr (atom (name ryuka)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) )))) + (expr (atom (name ryuka)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 2)))))))))) ))))))))))))))))))) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (ryuka(N))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def makelist(n,m): return[[0 for _ in range(m)]for _ in range(n)] N,K=map(int,input().split()) A=list(map(int,input().split())) kb=format(K,'b')[: :-1] l=len(kb) ab=[""]*(N) for i in range(N): ab[i]=format(A[i],'b').zfill(l)[: :-1] res=0 for i in reversed(range(l)): cnt=0 for e in ab : if e[i]=='0' : cnt+=1 if cnt>N//2 and res+2**i<=K : res+=2**i ans=0 for e in A : ans+=res ^ e print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var kb : OclAny := format(K, 'b')(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var l : int := (kb)->size() ; var ab : Sequence := MatrixLib.elementwiseMult(Sequence{ "" }, (N)) ; for i : Integer.subrange(0, N-1) do ( ab[i+1] := format(A[i+1], 'b').zfill(l)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ; var res : int := 0 ; for i : (Integer.subrange(0, l-1))->reverse() do ( var cnt : int := 0 ; for e : ab do ( if e[i+1] = '0' then ( cnt := cnt + 1 ) else skip) ; if (cnt->compareTo(N div 2)) > 0 & (res + (2)->pow(i)->compareTo(K)) <= 0 then ( res := res + (2)->pow(i) ) else skip) ; var ans : int := 0 ; for e : A do ( ans := ans + MathLib.bitwiseXor(res, e)) ; execute (ans)->display(); operation makelist(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (0)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000,10**9)) write=lambda x : sys.stdout.write(x+"\n") n,k=list(map(int,input().split())) a=list(map(int,input().split())) l=k.bit_length() vs=[0]*(l) for i in range(l): tmp=sum((item &(1<=2*tmp : vs[i]=n*(1<>i)& 1 : ans=max(ans,tmp+sum(vs[: i])) tmp+=vs[i] ans=max(ans,tmp) print(ans+sum(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; sys.setrecursionlimit(Set{1000, (10)->pow(9)}->max()) ; var write : Function := lambda x : OclAny in ((OclFile["System.out"]).write(x + "\n")) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : OclAny := k.bit_length() ; var vs : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (l)) ; for i : Integer.subrange(0, l-1) do ( var tmp : OclAny := ((argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name item))) & (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name i)))))))) )))))))) )))))) (comp_for for (exprlist (expr (atom (name item)))) in (logical_test (comparison (expr (atom (name a))))))))->sum() ; if (n * (1 * (2->pow(i)))->compareTo(2 * tmp)) >= 0 then ( vs[i+1] := n * (1 * (2->pow(i))) - 2 * tmp ) else skip) ; var ans : int := 0 ; tmp := 0 ; for i : Integer.subrange(-1 + 1, l - 1)->reverse() do ( if MathLib.bitwiseAnd((k /(2->pow(i))), 1) then ( ans := Set{ans, tmp + (vs.subrange(1,i))->sum()}->max() ; tmp := tmp + vs[i+1] ) else skip) ; ans := Set{ans, tmp}->max() ; execute (ans + (a)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from collections import defaultdict sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod=10**9+7 def I(): return int(input()) def II(): return map(int,input().split()) def III(): return list(map(int,input().split())) def Line(N): read_all=[tuple(map(int,input().split()))for _ in range(N)] return map(list,zip(*read_all)) N,K=II() A=III() k=format(K,'b') k=k.zfill(50) B=['0']*N for i in range(N): B[i]=str(format(A[i],'b')).zfill(50) val=str() flag=False for i in range(50): count0=0 count1=0 for j in range(N): if B[j][i]=='0' : count0+=1 else : count1+=1 if k[i]=='1' : if count0>count1 : val+='1' else : val+='0' flag=True else : if count0>=count1 : if flag : val+='1' else : val+='0' else : val+='0' val=int(val,2) ans=0 for i in range(N): ans+=val ^ A[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; var K : OclAny := null; Sequence{N,K} := II() ; var A : OclAny := III() ; var k : String := (K + "") ; k := k.zfill(50) ; var B : Sequence := MatrixLib.elementwiseMult(Sequence{ '0' }, N) ; for i : Integer.subrange(0, N-1) do ( B[i+1] := OclType["String"]((A[i+1] + "")).zfill(50)) ; var val : String := ("" + (())) ; var flag : boolean := false ; for i : Integer.subrange(0, 50-1) do ( var count0 : int := 0 ; var count1 : int := 0 ; for j : Integer.subrange(0, N-1) do ( if B[j+1][i+1] = '0' then ( count0 := count0 + 1 ) else ( count1 := count1 + 1 )) ; if k[i+1] = '1' then ( if (count0->compareTo(count1)) > 0 then ( val := val + '1' ) else ( val := val + '0' ; flag := true ) ) else ( if (count0->compareTo(count1)) >= 0 then ( if flag then ( val := val + '1' ) else ( val := val + '0' ) ) else ( val := val + '0' ) )) ; val := ("" + ((val, 2)))->toInteger() ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( ans := ans + MathLib.bitwiseXor(val, A[i+1])) ; execute (ans)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation II() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation III() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation Line(N : OclAny) : OclAny pre: true post: true activity: var read_all : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; return (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name read_all)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name read_all)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name read_all)))))))`third->at(_indx)} ))->collect( _x | (OclType["Sequence"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k,*a=map(int,open(0).read().split()) d=[0]*41 for i in range(n): for j in range(41): d[j]+=(a[i]>>j)& 1 f=0 la=len(bin(max(a)))-2 lk=len(bin(k))-2 b=[0]*41 for i in range(lk-1,-1,-1): if(k>>i)& 1==1 : if d[i]>i)& 1==0 : if d[i]collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 41) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, 41-1) do ( d[j+1] := d[j+1] + MathLib.bitwiseAnd((a[i+1] /(2->pow(j))), 1))) ; var f : int := 0 ; var la : double := (bin((a)->max()))->size() - 2 ; var lk : double := (bin(k))->size() - 2 ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 41) ; for i : Integer.subrange(-1 + 1, lk - 1)->reverse() do ( if MathLib.bitwiseAnd((k /(2->pow(i))), 1) = 1 then ( if (d[i+1]->compareTo(n - d[i+1])) < 0 then ( b[i+1] := 1 ) else ( b[i+1] := 0 ; f := 1 ) ) else skip ; if MathLib.bitwiseAnd((k /(2->pow(i))), 1) = 0 then ( if (d[i+1]->compareTo(n - d[i+1])) < 0 & f = 1 then ( b[i+1] := 1 ) else ( b[i+1] := 0 ) ) else skip) ; var ans : int := 0 ; for i : Integer.subrange(0, Set{lk, la}->max()-1) do ( ans := ans + (1 * (2->pow(i))) * Sequence{d[i+1]}->union(Sequence{ n - d[i+1] })[b[i+1]+1]) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() if len(set(el for el in s))==1 : print(s[0]) elif n==1 : print(s) elif n==2 : if "R" not in s : print("R") elif "G" not in s : print("G") else : print("B") else : a=s.count("R") b=s.count("G") c=s.count("B") p=sum(int(el>=2)for el in[a,b,c]) if a and b and c : print('BGR') elif p>=2 : print("BGR") else : if a>1 : if b or c : print("BG") else : print("R") elif b>1 : if a or c : print("BR") else : print("G") else : if a or b : print("GR") else : print("B") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; if (Set{}->union(((argument (test (logical_test (comparison (expr (atom (name el)))))) (comp_for for (exprlist (expr (atom (name el)))) in (logical_test (comparison (expr (atom (name s))))))))))->size() = 1 then ( execute (s->first())->display() ) else (if n = 1 then ( execute (s)->display() ) else (if n = 2 then ( if (s)->characters()->excludes("R") then ( execute ("R")->display() ) else (if (s)->characters()->excludes("G") then ( execute ("G")->display() ) else ( execute ("B")->display() ) ) ) else ( var a : int := s->count("R") ; var b : int := s->count("G") ; var c : int := s->count("B") ; var p : OclAny := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (comparison (expr (atom (name el)))) >= (comparison (expr (atom (number (integer 2)))))))))) ))))))) (comp_for for (exprlist (expr (atom (name el)))) in (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name b)))))) , (test (logical_test (comparison (expr (atom (name c))))))) ])))))))->sum() ; if a & b & c then ( execute ('BGR')->display() ) else (if p >= 2 then ( execute ("BGR")->display() ) else ( if a > 1 then ( if b or c then ( execute ("BG")->display() ) else ( execute ("R")->display() ) ) else (if b > 1 then ( if a or c then ( execute ("BR")->display() ) else ( execute ("G")->display() ) ) else ( if a or b then ( execute ("GR")->display() ) else ( execute ("B")->display() ) ) ) ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) c=int(input()) d=int(input()) if c and(a<=0 or d<=0): print(0) exit(0) a-=1 d-=1 if a!=d : print(0) exit(0) print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if c & (a <= 0 or d <= 0) then ( execute (0)->display() ; exit(0) ) else skip ; a := a - 1 ; d := d - 1 ; if a /= d then ( execute (0)->display() ; exit(0) ) else skip ; execute (1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() r,b,g=0,0,0 for i in s : if i=='R' : r+=1 if i=='G' : g+=1 if i=='B' : b+=1 if r*b*g>0 : print('BGR') elif(r>1 and b>1)or(r>1 and g>1)or(b>1 and g>1): print('BGR') elif b==n : print('B') elif g==n : print('G') elif r==n : print('R') elif n==2 : x=(set('BGR')-set(s)) print(str(x)[2 : 3]) elif r==0 and b==1 : print('BR') elif r==1 and b==0 : print('BR') elif g==0 and b==1 : print('BG') elif g==1 and b==0 : print('BG') elif r==0 and g==1 : print('GR') elif r==1 and g==0 : print('GR') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var r : OclAny := null; var b : OclAny := null; var g : OclAny := null; Sequence{r,b,g} := Sequence{0,0,0} ; for i : s->characters() do ( if i = 'R' then ( r := r + 1 ) else skip ; if i = 'G' then ( g := g + 1 ) else skip ; if i = 'B' then ( b := b + 1 ) else skip) ; if r * b * g > 0 then ( execute ('BGR')->display() ) else (if (r > 1 & b > 1) or (r > 1 & g > 1) or (b > 1 & g > 1) then ( execute ('BGR')->display() ) else (if b = n then ( execute ('B')->display() ) else (if g = n then ( execute ('G')->display() ) else (if r = n then ( execute ('R')->display() ) else (if n = 2 then ( var x : double := (Set{}->union(('BGR')) - Set{}->union((s))) ; execute (OclType["String"](x).subrange(2+1, 3))->display() ) else (if r = 0 & b = 1 then ( execute ('BR')->display() ) else (if r = 1 & b = 0 then ( execute ('BR')->display() ) else (if g = 0 & b = 1 then ( execute ('BG')->display() ) else (if g = 1 & b = 0 then ( execute ('BG')->display() ) else (if r = 0 & g = 1 then ( execute ('GR')->display() ) else (if r = 1 & g = 0 then ( execute ('GR')->display() ) else skip ) ) ) ) ) ) ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import Counter,defaultdict sys.setrecursionlimit(20000) def get_ints(): return list(map(int,sys.stdin.readline().strip().split())) def get_chars(): return list(sys.stdin.readline().strip()) n=int(input()) c=get_chars() counter=Counter(c) if len(counter)==3 : print("BGR") if len(counter)==2 : ans=[] temp=["R","G","B"] for el in["R","G","B"]: if counter[el]==0 : ans.append(el) temp.remove(el) el1,el2=temp if counter[el1]==1 and counter[el2]==1 : pass elif counter[el1]==1 : ans.append(el1) elif counter[el2]==1 : ans.append(el2) else : ans.append(el1) ans.append(el2) ans.sort() for x in ans : print(x,end="") if len(counter)==1 : for el in["R","G","B"]: if counter[el]>0 : print(el) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit(20000) ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : OclAny := get_chars() ; var counter : OclAny := Counter(c) ; if (counter)->size() = 3 then ( execute ("BGR")->display() ) else skip ; if (counter)->size() = 2 then ( var ans : Sequence := Sequence{} ; var temp : Sequence := Sequence{"R"}->union(Sequence{"G"}->union(Sequence{ "B" })) ; for el : Sequence{"R"}->union(Sequence{"G"}->union(Sequence{ "B" })) do ( if counter[el+1] = 0 then ( execute ((el) : ans) ; execute ((el) /: temp) ) else skip) ; var el1 : OclAny := null; var el2 : OclAny := null; Sequence{el1,el2} := temp ; if counter[el1+1] = 1 & counter[el2+1] = 1 then ( skip ) else (if counter[el1+1] = 1 then ( execute ((el1) : ans) ) else (if counter[el2+1] = 1 then ( execute ((el2) : ans) ) else ( execute ((el1) : ans) ; execute ((el2) : ans) ) ) ) ; ans := ans->sort() ; for x : ans do ( execute (x)->display()) ) else skip ; if (counter)->size() = 1 then ( for el : Sequence{"R"}->union(Sequence{"G"}->union(Sequence{ "B" })) do ( if counter[el+1] > 0 then ( execute (el)->display() ) else skip) ) else skip; operation get_ints() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation get_chars() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() if 'R' in s and 'G' in s and 'B' in s : print('BGR') quit() ans='' if 'R' in s and 'G' in s : ans+='B' if s.count('R')>1 : ans+='G' if s.count('G')>1 : ans+='R' elif 'B' in s and 'G' in s : ans+='R' if s.count('B')>1 : ans+='G' if s.count('G')>1 : ans+='B' elif 'R' in s and 'B' in s : ans+='G' if s.count('R')>1 : ans+='B' if s.count('B')>1 : ans+='R' else : ans=s[0] print(*sorted(ans),sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; if (s)->characters()->includes('R') & (s)->characters()->includes('G') & (s)->characters()->includes('B') then ( execute ('BGR')->display() ; quit() ) else skip ; var ans : String := '' ; if (s)->characters()->includes('R') & (s)->characters()->includes('G') then ( ans := ans + 'B' ; if s->count('R') > 1 then ( ans := ans + 'G' ) else skip ; if s->count('G') > 1 then ( ans := ans + 'R' ) else skip ) else (if (s)->characters()->includes('B') & (s)->characters()->includes('G') then ( ans := ans + 'R' ; if s->count('B') > 1 then ( ans := ans + 'G' ) else skip ; if s->count('G') > 1 then ( ans := ans + 'B' ) else skip ) else (if (s)->characters()->includes('R') & (s)->characters()->includes('B') then ( ans := ans + 'G' ; if s->count('R') > 1 then ( ans := ans + 'B' ) else skip ; if s->count('B') > 1 then ( ans := ans + 'R' ) else skip ) else ( ans := s->first() ) ) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) )))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import permutations for p in list(permutations(range(1,int(input())+1))): print(*p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for p : (permutations(Integer.subrange(1, ("" + (((OclFile["System.in"]).readLine())))->toInteger() + 1-1))) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name p))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- Lucas=[2,1] for i in range(86): Lucas.append(Lucas[-1]+Lucas[-2]) N=int(input()) print(Lucas[N]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Lucas : Sequence := Sequence{2}->union(Sequence{ 1 }) ; for i : Integer.subrange(0, 86-1) do ( execute ((Lucas->last() + Lucas->front()->last()) : Lucas)) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (Lucas[N+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from collections import deque class enumeration : def __init__(self,n): self.n=n self.depth=0 self.wnum=0 self.nq=[] self.bits=[pow(2,i)for i in range(n+1)] self.mk_permutation(0,0,0) def mk_permutation(self,depth,bflag,wnum): if self.n==depth : self.nq.append(wnum) return for i in range(1,self.n+1): if bflag & self.bits[i-1]!=0 : continue self.mk_permutation(depth+1,bflag+self.bits[i-1],wnum*10+i) def printList(self): l=self.nq self.nq.sort() for i in l : c="" for j in str(i): c+=j+" " print(c.strip()) def main(): n=int(input()) i=enumeration(n) i.printList() if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class enumeration { static operation newenumeration() : enumeration pre: true post: enumeration->exists( _x | result = _x ); attribute n : OclAny := n; attribute depth : int := 0; attribute wnum : int := 0; attribute nq : Sequence := Sequence{}; attribute bits : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | ((2)->pow(i))); operation initialise(n : OclAny) : enumeration pre: true post: true activity: self.n := n ; self.depth := 0 ; self.wnum := 0 ; self.nq := Sequence{} ; self.bits := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | ((2)->pow(i))) ; self.mk_permutation(0, 0, 0); return self; operation mk_permutation(depth : OclAny,bflag : OclAny,wnum : OclAny) pre: true post: true activity: if self.n = depth then ( (expr (atom (name self)) (trailer . (name nq)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name wnum)))))))) )))) ; return ) else skip ; for i : Integer.subrange(1, self.n + 1-1) do ( if MathLib.bitwiseAnd(bflag, self.bits[i - 1+1]) /= 0 then ( continue ) else skip ; self.mk_permutation(depth + 1, bflag + self.bits[i - 1+1], wnum * 10 + i)); operation printList() pre: true post: true activity: var l : OclAny := self.nq ; (expr (atom (name self)) (trailer . (name nq)) (trailer . (name sort) (arguments ( )))) ; for i : l do ( var c : String := "" ; for j : ("" + ((i))) do ( c := c + j + " ") ; execute (c->trim())->display()); } class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : enumeration := (enumeration.newenumeration()).initialise(n) ; i.printList(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def permutations(n): xs=list(range(1,n+1)) yield xs[:] while True : i=n-1 while i>0 and xs[i-1]>xs[i]: i-=1 if i>0 : i-=1 j=i+1 while jxs[i]: j+=1 xs[i],xs[j-1]=xs[j-1],xs[i] xs=xs[: i+1]+list(reversed(xs[i+1 :])) yield xs[:] else : break def run(): n=int(input()) for ps in permutations(n): print(" ".join([str(x)for x in ps])) if __name__=='__main__' : run() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( run() ) else skip; operation permutations(n : OclAny) pre: true post: true activity: var xs : Sequence := (Integer.subrange(1, n + 1-1)) ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return xs ; while true do ( var i : double := n - 1 ; while i > 0 & (xs[i - 1+1]->compareTo(xs[i+1])) > 0 do ( i := i - 1) ; if i > 0 then ( i := i - 1 ; var j : OclAny := i + 1 ; while (j->compareTo((xs)->size())) < 0 & (xs[j+1]->compareTo(xs[i+1])) > 0 do ( j := j + 1) ; var xs[i+1] : OclAny := null; var xs[j - 1+1] : OclAny := null; Sequence{xs[i+1],xs[j - 1+1]} := Sequence{xs[j - 1+1],xs[i+1]} ; xs := xs.subrange(1,i + 1)->union(((xs.subrange(i + 1+1))->reverse())) ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return xs ) else ( break )); operation run() pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for ps : permutations(n) do ( execute (StringLib.sumStringsWithSeparator((ps->select(x | true)->collect(x | (("" + ((x)))))), " "))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) nl=[str(i)for i in range(1,n+1)] def perm(nl): if len(nl)==0 : return[] if len(nl)==1 : return[nl] l=[] for i in range(len(nl)): m=nl[i] rest=nl[: i]+nl[i+1 :] for p in perm(rest): l.append([m]+p) return l for i in perm(nl): print(" ".join(i)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nl : Sequence := Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | (("" + ((i))))) ; skip ; for i : perm(nl) do ( execute (StringLib.sumStringsWithSeparator((i), " "))->display()); operation perm(nl : OclAny) : OclAny pre: true post: true activity: if (nl)->size() = 0 then ( return Sequence{} ) else skip ; if (nl)->size() = 1 then ( return Sequence{ nl } ) else skip ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, (nl)->size()-1) do ( var m : OclAny := nl[i+1] ; var rest : OclAny := nl.subrange(1,i) + nl.subrange(i + 1+1) ; for p : perm(rest) do ( execute ((Sequence{ m }->union(p)) : l))) ; return l; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rec(lst,d): for i in range(1,len(lst)+1): if i not in lst : lst[d]=i if d+1==len(lst): a=list(lst) P.append(a) lst[d]=0 return else : rec(lst,d+1) lst[d]=0 N=int(input()) P=[] lst=[] for i in range(N): lst.append(0) rec(lst,0) for i in range(len(P)): print(*P[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var P : Sequence := Sequence{} ; lst := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute ((0) : lst)) ; rec(lst, 0) ; for i : Integer.subrange(0, (P)->size()-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name P)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))->display()); operation rec(lst : OclAny, d : OclAny) pre: true post: true activity: for i : Integer.subrange(1, (lst)->size() + 1-1) do ( if (lst)->excludes(i) then ( lst[d+1] := i ; if d + 1 = (lst)->size() then ( var a : Sequence := (lst) ; execute ((a) : P) ; lst[d+1] := 0 ; return ) else ( rec(lst, d + 1) ; lst[d+1] := 0 ) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPowerOfTwo(n): return(n and(not(n &(n-1)))) def findPosition(n): if not isPowerOfTwo(n): return-1 count=0 while(n): n=n>>1 count+=1 return count if __name__=="__main__" : n=0 pos=findPosition(n) if pos==-1 : print("n=",n,"Invalid number") else : print("n=",n,"Position",pos) n=12 pos=findPosition(n) if pos==-1 : print("n=",n,"Invalid number") else : print("n=",n,"Position",pos) n=128 pos=findPosition(n) if pos==-1 : print("n=",n,"Invalid number") else : print("n=",n,"Position",pos) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 0 ; var pos : OclAny := findPosition(n) ; if pos = -1 then ( execute ("n=")->display() ) else ( execute ("n=")->display() ) ; n := 12 ; pos := findPosition(n) ; if pos = -1 then ( execute ("n=")->display() ) else ( execute ("n=")->display() ) ; n := 128 ; pos := findPosition(n) ; if pos = -1 then ( execute ("n=")->display() ) else ( execute ("n=")->display() ) ) else skip; operation isPowerOfTwo(n : OclAny) : OclAny pre: true post: true activity: return (n & (not((MathLib.bitwiseAnd(n, (n - 1)))))); operation findPosition(n : OclAny) : OclAny pre: true post: true activity: if not(isPowerOfTwo(n)) then ( return -1 ) else skip ; var count : int := 0 ; while (n) do ( n := n /(2->pow(1)) ; count := count + 1) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Log2n(n): if(n>1): return(1+Log2n(n/2)) else : return 0 def isPowerOfTwo(n): return n and(not(n &(n-1))) def findPosition(n): if(not isPowerOfTwo(n)): return-1 return Log2n(n)+1 n=0 pos=findPosition(n) if(pos==-1): print("n=",n,",Invalid number") else : print("n=",n,",Position ",pos) n=12 pos=findPosition(n) if(pos==-1): print("n=",n,",Invalid number") else : print("n=",n,",Position ",pos) n=128 pos=findPosition(n) if(pos==-1): print("n=",n,",Invalid number") else : print("n=",n,",Position ",pos) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 0 ; var pos : OclAny := findPosition(n) ; if (pos = -1) then ( execute ("n=")->display() ) else ( execute ("n=")->display() ) ; n := 12 ; pos := findPosition(n) ; if (pos = -1) then ( execute ("n=")->display() ) else ( execute ("n=")->display() ) ; n := 128 ; pos := findPosition(n) ; if (pos = -1) then ( execute ("n=")->display() ) else ( execute ("n=")->display() ); operation Log2n(n : OclAny) : OclAny pre: true post: true activity: if (n > 1) then ( return (1 + Log2n(n / 2)) ) else ( return 0 ); operation isPowerOfTwo(n : OclAny) : OclAny pre: true post: true activity: return n & (not((MathLib.bitwiseAnd(n, (n - 1))))); operation findPosition(n : OclAny) : OclAny pre: true post: true activity: if (not(isPowerOfTwo(n))) then ( return -1 ) else skip ; return Log2n(n) + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline a=int(input()[:-1]) b=int(input()[:-1]) c=int(input()[:-1]) d=int(input()[:-1]) if a==d : if a>0 : print(1) else : if c>0 : print(0) else : print(1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var a : int := ("" + ((input()->front())))->toInteger() ; var b : int := ("" + ((input()->front())))->toInteger() ; var c : int := ("" + ((input()->front())))->toInteger() ; var d : int := ("" + ((input()->front())))->toInteger() ; if a = d then ( if a > 0 then ( execute (1)->display() ) else ( if c > 0 then ( execute (0)->display() ) else ( execute (1)->display() ) ) ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* def findfactors(n): vec=[] for i in range(1,int(sqrt(n))+1): if n % i==0 : vec.append(i) vec.append(n//i) vec.sort() print("All the factors are->",end="") for i in range(len(vec)): print(vec[i],end=" ") print() maxProduct=1 flag=1 for i in range(0,len(vec)): for j in range(i,len(vec)): for k in range(j,len(vec)): y=n-vec[i]-vec[j]-vec[k] if y<=0 : break if n % y==0 : flag=0 maxProduct=max(vec[i]*vec[j]*vec[k]*y,maxProduct) if flag==0 : print("Product is->",maxProduct) else : print("Not possible") if __name__=="__main__" : n=50 findfactors(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 50 ; findfactors(n) ) else skip; operation findfactors(n : OclAny) pre: true post: true activity: var vec : Sequence := Sequence{} ; for i : Integer.subrange(1, ("" + ((sqrt(n))))->toInteger() + 1-1) do ( if n mod i = 0 then ( execute ((i) : vec) ; execute ((n div i) : vec) ) else skip) ; vec := vec->sort() ; execute ("All the factors are->")->display() ; for i : Integer.subrange(0, (vec)->size()-1) do ( execute (vec[i+1])->display()) ; execute (->display() ; var maxProduct : int := 1 ; var flag : int := 1 ; for i : Integer.subrange(0, (vec)->size()-1) do ( for j : Integer.subrange(i, (vec)->size()-1) do ( for k : Integer.subrange(j, (vec)->size()-1) do ( var y : double := n - vec[i+1] - vec[j+1] - vec[k+1] ; if y <= 0 then ( break ) else skip ; if n mod y = 0 then ( flag := 0 ; maxProduct := Set{vec[i+1] * vec[j+1] * vec[k+1] * y, maxProduct}->max() ) else skip))) ; if flag = 0 then ( execute ("Product is->")->display() ) else ( execute ("Not possible")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from heapq import heappush,heappop import sys import math import bisect import random def LI(): return[int(x)for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return[list(x)for x in sys.stdin.readline().split()] def S(): return list(sys.stdin.readline())[:-1] def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] sys.setrecursionlimit(1000000) mod=1000000007 def solve(): d=defaultdict(lambda : 0) n=I() for i in range(n): u=input() d[u]=1 ans=["Opened by","Closed by"] m=I() k=0 for i in range(m): t=input() if not d[t]: print("Unknown",t) else : print(ans[k],t) k ^=1 return if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1000000) ; var mod : int := 1000000007 ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | ((x))); operation S() : OclAny pre: true post: true activity: return OclType["Sequence"]((OclFile["System.in"]).readLine())->front(); operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation solve() pre: true post: true activity: var d : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; n := I() ; for i : Integer.subrange(0, n-1) do ( var u : String := (OclFile["System.in"]).readLine() ; d->at(u) := 1) ; var ans : Sequence := Sequence{"Opened by"}->union(Sequence{ "Closed by" }) ; var m : OclAny := I() ; var k : int := 0 ; for i : Integer.subrange(0, m-1) do ( var t : String := (OclFile["System.in"]).readLine() ; if not(d->at(t)) then ( execute ("Unknown")->display() ) else ( execute (ans[k+1])->display() ; k := k xor 1 )) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- U=[] T=[] N=int(input()) for i in range(N): U.append(input()) M=int(input()) for i in range(M): T.append(input()) count=0 for i in range(len(T)): for j in range(len(U)): if T[i]==U[j]: if count==0 : print("Opened by",T[i]) count=1 break if count==1 : print("Closed by",T[i]) count=0 break if j==int(len(U))-1 : print("Unknown",T[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var U : Sequence := Sequence{} ; var T : Sequence := Sequence{} ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, N-1) do ( execute (((OclFile["System.in"]).readLine()) : U)) ; var M : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, M-1) do ( execute (((OclFile["System.in"]).readLine()) : T)) ; var count : int := 0 ; for i : Integer.subrange(0, (T)->size()-1) do ( for j : Integer.subrange(0, (U)->size()-1) do ( if T[i+1] = U[j+1] then ( if count = 0 then ( execute ("Opened by")->display() ; count := 1 ; break ) else skip ; if count = 1 then ( execute ("Closed by")->display() ; count := 0 ; break ) else skip ) else skip ; if j = ("" + (((U)->size())))->toInteger() - 1 then ( execute ("Unknown")->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) k={} def y(p): if p in k.keys(): return k[p] if p==0 : return 2 elif p==1 : return 1 else : k[p]=y(p-2)+y(p-1) return k[p] print(y(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : OclAny := Set{} ; skip ; execute (y(N))->display(); operation y(p : OclAny) : OclAny pre: true post: true activity: if (k.keys())->includes(p) then ( return k[p+1] ) else skip ; if p = 0 then ( return 2 ) else (if p = 1 then ( return 1 ) else ( k[p+1] := y(p - 2) + y(p - 1) ; return k[p+1] ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**3 eps=1.0/10**10 mod=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] n=I() a=[S()for _ in range(n)] m=I() b=[S()for _ in range(m)] d=1 for c in b : if c not in a : rr.append('Unknown{}'.format(c)) elif d==1 : rr.append('Opened by{}'.format(c)) d=0 else : rr.append('Closed by{}'.format(c)) d=1 return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(3) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; var n : OclAny := I() ; var a : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (S())) ; var m : OclAny := I() ; var b : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (S())) ; var d : int := 1 ; for c : b do ( if (a)->excludes(c) then ( execute ((StringLib.interpolateStrings('Unknown{}', Sequence{c})) : rr) ) else (if d = 1 then ( execute ((StringLib.interpolateStrings('Opened by{}', Sequence{c})) : rr) ; d := 0 ) else ( execute ((StringLib.interpolateStrings('Closed by{}', Sequence{c})) : rr) ; d := 1 ) ) ) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=[input()for _ in range(int(input()))] a=1 for _ in range(int(input())): b=input() if b in k : print(('Opened' if a>0 else 'Closed')+' by '+b); a=~ a else : print('Unknown '+b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : Sequence := Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var a : int := 1 ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var b : String := (OclFile["System.in"]).readLine() ; if (k)->includes(b) then ( execute ((if a > 0 then 'Opened' else 'Closed' endif) + ' by ' + b)->display(); a := MathLib.bitwiseNot(a) ) else ( execute ('Unknown ' + b)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Open(x): print("Opened by",x) door=1 return door def Close(x): print("Closed by",x) door=0 return door def Out(x): print("Unknown",x) N=int(input()) U=list() for i in range(N): U.append(input()) M=int(input()) T=list() for i in range(M): T.append(input()) door=0 for i in range(M): if(T[i]in U): if(door==0): door=Open(T[i]) else : door=Close(T[i]) else : Out(T[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var U : Sequence := () ; for i : Integer.subrange(0, N-1) do ( execute (((OclFile["System.in"]).readLine()) : U)) ; var M : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var T : Sequence := () ; for i : Integer.subrange(0, M-1) do ( execute (((OclFile["System.in"]).readLine()) : T)) ; door := 0 ; for i : Integer.subrange(0, M-1) do ( if ((U)->includes(T[i+1])) then ( if (door = 0) then ( door := Open(T[i+1]) ) else ( door := Close(T[i+1]) ) ) else ( Out(T[i+1]) )); operation Open(x : OclAny) : OclAny pre: true post: true activity: execute ("Opened by")->display() ; var door : int := 1 ; return door; operation Close(x : OclAny) : OclAny pre: true post: true activity: execute ("Closed by")->display() ; door := 0 ; return door; operation Out(x : OclAny) pre: true post: true activity: execute ("Unknown")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sol(s): cnt=0 days=1 string_list=[] for i in s : if i in string_list : pass else : if cnt>=3 : cnt=0 days+=1 string_list=[] string_list.append(i) cnt+=1 return days for i in range(int(input())): print(sol(input())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (sol((OclFile["System.in"]).readLine()))->display()); operation sol(s : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; var days : int := 1 ; var string_list : Sequence := Sequence{} ; for i : s do ( if (string_list)->includes(i) then ( skip ) else ( if cnt >= 3 then ( cnt := 0 ; days := days + 1 ; string_list := Sequence{} ) else skip ; execute ((i) : string_list) ; cnt := cnt + 1 )) ; return days; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): s=input() ans=0 se=set() for i in s : if i not in se and len(se)==3 : ans+=1 se=set() se.add(i) if len(se): ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; var se : Set := Set{}->union(()) ; for i : s->characters() do ( if (se)->excludes(i) & (se)->size() = 3 then ( ans := ans + 1 ; se := Set{}->union(()) ) else skip ; execute ((i) : se)) ; if (se)->size() then ( ans := ans + 1 ) else skip ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(0,t): m=input() l=list(m) p=0 k=[] c=0 while(ptoInteger() ; for i : Integer.subrange(0, t-1) do ( var m : String := (OclFile["System.in"]).readLine() ; var l : Sequence := (m)->characters() ; var p : int := 0 ; var k : Sequence := Sequence{} ; var c : int := 0 ; while ((p->compareTo((l)->size())) < 0) do ( if (k)->size() <= 3 & (k)->excludes(l[p+1]) then ( execute ((l[p+1]) : k) ; if ((k)->size() = 4) then ( c := c + 1 ; k := Sequence{ k->last() } ) else skip ) else skip ; p := p + 1) ; if (k)->size() < 4 then ( c := c + 1 ) else skip ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys II=lambda : int(input()) LI=lambda : list(map(int,list(input().split(" ")))) MI=lambda : map(int,LI()) SI=lambda : input() def res(s): counter=0 days=1 string_list=[] for i in s : if i in string_list : pass else : if counter>=3 : counter=0 days+=1 string_list=[] string_list.append(i) counter+=1 return days for i in range(int(input())): print(res(input())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var II : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var LI : Function := lambda $$ : OclAny in ((((input().split(" ")))->collect( _x | (OclType["int"])->apply(_x) ))) ; var MI : Function := lambda $$ : OclAny in ((LI->apply())->collect( _x | (OclType["int"])->apply(_x) )) ; var SI : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (res((OclFile["System.in"]).readLine()))->display()); operation res(s : OclAny) : OclAny pre: true post: true activity: var counter : int := 0 ; var days : int := 1 ; var string_list : Sequence := Sequence{} ; for i : s do ( if (string_list)->includes(i) then ( skip ) else ( if counter >= 3 then ( counter := 0 ; days := days + 1 ; string_list := Sequence{} ) else skip ; execute ((i) : string_list) ; counter := counter + 1 )) ; return days; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def print(u,v): sys.stdout.write("%d %d\n" %(u,v)) n,m=map(int,input().split()) ans=[] for i in range(n//2): u,v=i+1,n-i for j in range(m): ans.append((u,j+1)) ans.append((v,m-j)) if n % 2 : u=n//2+1 for i in range(m//2): ans.append((u,i+1)) ans.append((u,m-i)) if m % 2 : v=m//2+1 ans.append((u,v)) for u,v in ans : print(u,v) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, n div 2-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := Sequence{i + 1,n - i} ; for j : Integer.subrange(0, m-1) do ( execute ((Sequence{u, j + 1}) : ans) ; execute ((Sequence{v, m - j}) : ans))) ; if n mod 2 then ( var u : int := n div 2 + 1 ; for i : Integer.subrange(0, m div 2-1) do ( execute ((Sequence{u, i + 1}) : ans) ; execute ((Sequence{u, m - i}) : ans)) ; if m mod 2 then ( var v : int := m div 2 + 1 ; execute ((Sequence{u, v}) : ans) ) else skip ) else skip ; for _tuple : ans do (var _indx : int := 1; var u : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); execute (u)->display()); (funcdef def name print ( (typedargslist (def_parameters (def_parameter (named_parameter (name u))) , (def_parameter (named_parameter (name v))))) ) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom "%d %d\n")) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name u)))))) , (test (logical_test (comparison (expr (atom (name v))))))) ))))))))) ))))))))))))))} ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def answer_func(word): memory=set() todays_letters=0 days=0 for letter in word : if not(letter in memory)and(len(memory)>=3): memory.clear() days+=1 todays_letters=0 memory.add(letter) todays_letters+=1 if todays_letters>0 : days+=1 return days tests=int(input()) for test in range(tests): word=input() print(answer_func(word)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var tests : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for test : Integer.subrange(0, tests-1) do ( word := (OclFile["System.in"]).readLine() ; execute (answer_func(word))->display()); operation answer_func(word : OclAny) : OclAny pre: true post: true activity: var memory : Set := Set{}->union(()) ; var todays_letters : int := 0 ; var days : int := 0 ; for letter : word do ( if not(((memory)->includes(letter))) & ((memory)->size() >= 3) then ( execute (memory /<: memory) ; days := days + 1 ; todays_letters := 0 ) else skip ; execute ((letter) : memory) ; todays_letters := todays_letters + 1) ; if todays_letters > 0 then ( days := days + 1 ) else skip ; return days; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def EvenOddLength(arr,n): even=0 for i in range(n): x=str(arr[i]) if(len(x)% 2==0): even+=1 print("Number of even length elements=",even) print("Number of odd length elements=",n-even) if __name__=='__main__' : arr=[12,44,213,232,3433] n=len(arr) EvenOddLength(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{12}->union(Sequence{44}->union(Sequence{213}->union(Sequence{232}->union(Sequence{ 3433 })))) ; n := (arr)->size() ; EvenOddLength(arr, n) ) else skip; operation EvenOddLength(arr : OclAny, n : OclAny) pre: true post: true activity: var even : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x : String := ("" + ((arr[i+1]))) ; if ((x)->size() mod 2 = 0) then ( even := even + 1 ) else skip) ; execute ("Number of even length elements=")->display() ; execute ("Number of odd length elements=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) b,c=1,2+1 if N==1 : print(b) if N==2 : print(c) for _ in range(3,N+1): b,c=c,c+b if N not in{1,2}: print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := Sequence{1,2 + 1} ; if N = 1 then ( execute (b)->display() ) else skip ; if N = 2 then ( execute (c)->display() ) else skip ; for _anon : Integer.subrange(3, N + 1-1) do ( var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := Sequence{c,c + b}) ; if (Set{1}->union(Set{ 2 }))->excludes(N) then ( execute (c)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def func(): n=int(input()) n1=n k=1 ans=0 while True : if n % 2==0 : n/=2 k+=1 else : break while True : m=(2**k-1)*2**(k-1) if n1 % m==0 : print(m) break else : k-=1 func() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; func(); operation func() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n1 : int := n ; var k : int := 1 ; var ans : int := 0 ; while true do ( if n mod 2 = 0 then ( n := n / 2 ; k := k + 1 ) else ( break )) ; while true do ( var m : double := ((2)->pow(k) - 1) * (2)->pow((k - 1)) ; if n1 mod m = 0 then ( execute (m)->display() ; break ) else ( k := k - 1 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def is_pretty(num): zero_count=0 one_count=0 current=0 result=True while num : if num % 2 : one_count+=1 if current==0 : current=1 else : zero_count+=1 if current==1 : result=False break num//=2 return result and zero_count+1==one_count def main(): n=int(input()) result=1 for i in range(3,n+1): if n % i==0 and is_pretty(i): result=i print(result) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation is_pretty(num : OclAny) : OclAny pre: true post: true activity: var zero_count : int := 0 ; var one_count : int := 0 ; var current : int := 0 ; var result : boolean := true ; while num do ( if num mod 2 then ( one_count := one_count + 1 ; if current = 0 then ( current := 1 ) else skip ) else ( zero_count := zero_count + 1 ; if current = 1 then ( result := false ; break ) else skip ) ; num := num div 2) ; return result & zero_count + 1 = one_count; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; result := 1 ; for i : Integer.subrange(3, n + 1-1) do ( if n mod i = 0 & is_pretty(i) then ( result := i ) else skip) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x="111111110000000" n=int(input()) res=0 while True : if n % int(x,2)==0 : print(int(x,2)) break x=x[1 :-1] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := "111111110000000" ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : int := 0 ; while true do ( if n mod ("" + ((x, 2)))->toInteger() = 0 then ( execute (("" + ((x, 2)))->toInteger())->display() ; break ) else skip ; x := x.subrange(1+1, -1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fast(n): perfect=[32640,8128,2016,496,120,28,6,1] for j in perfect : if n % j==0 : return j n=int(input()) print(fast(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (fast(n))->display(); operation fast(n : OclAny) : OclAny pre: true post: true activity: var perfect : Sequence := Sequence{32640}->union(Sequence{8128}->union(Sequence{2016}->union(Sequence{496}->union(Sequence{120}->union(Sequence{28}->union(Sequence{6}->union(Sequence{ 1 }))))))) ; for j : perfect do ( if n mod j = 0 then ( return j ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) k=1 x,a=False,1 if bin(n)[2 :]=='1'*(len(bin(n)[2 :])//2+1)+'0'*(len(bin(n)[2 :])//2): print(n) else : while(2**k-1)*(2**(k-1))<=n//2 : if n %((2**k-1)*(2**(k-1)))==0 : a=(2**k-1)*(2**(k-1)) k+=1 print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := 1 ; var x : OclAny := null; var a : OclAny := null; Sequence{x,a} := Sequence{false,1} ; if bin(n).subrange(2+1) = StringLib.nCopies('1', ((bin(n).subrange(2+1))->size() div 2 + 1)) + StringLib.nCopies('0', ((bin(n).subrange(2+1))->size() div 2)) then ( execute (n)->display() ) else ( while (((2)->pow(k) - 1) * ((2)->pow((k - 1)))->compareTo(n div 2)) <= 0 do ( if n mod (((2)->pow(k) - 1) * ((2)->pow((k - 1)))) = 0 then ( var a : double := ((2)->pow(k) - 1) * ((2)->pow((k - 1))) ) else skip ; k := k + 1) ; execute (a)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,k=map(int,input().split()) for i in range(max(a,b),0,-1): if a % i==0 and b % i==0 : k-=1 if k==0 : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var k : OclAny := null; Sequence{a,b,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0 + 1, Set{a, b}->max())->reverse() do ( if a mod i = 0 & b mod i = 0 then ( k := k - 1 ; if k = 0 then ( execute (i)->display() ) else skip ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- data=input().split() A=int(data[0]) B=int(data[1]) k=int(data[2]) ans=[] i=1 ma=max(A,B) while i<=ma : if(A % i==0)&(B % i==0): ans.append(i) i+=1 ind=len(ans) print(ans[ind-k]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var data : OclAny := input().split() ; var A : int := ("" + ((data->first())))->toInteger() ; var B : int := ("" + ((data[1+1])))->toInteger() ; var k : int := ("" + ((data[2+1])))->toInteger() ; var ans : Sequence := Sequence{} ; var i : int := 1 ; var ma : OclAny := Set{A, B}->max() ; while (i->compareTo(ma)) <= 0 do ( if MathLib.bitwiseAnd((A mod i = 0), (B mod i = 0)) then ( execute ((i) : ans) ) else skip ; i := i + 1) ; var ind : int := (ans)->size() ; execute (ans[ind - k+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import gcd A,B,K=[int(i)for i in input().split()] def divisor_list(n): ret=[] for k in range(1,int(n**0.5)+1): if n % k==0 : ret.append(k) if k!=n//k : ret.append(n//k) return list(sorted(ret,reverse=True)) print(divisor_list(gcd(A,B))[K-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var A : OclAny := null; var B : OclAny := null; var K : OclAny := null; Sequence{A,B,K} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; skip ; execute (divisor_list(gcd(A, B))[K - 1+1])->display(); operation divisor_list(n : OclAny) : OclAny pre: true post: true activity: var ret : Sequence := Sequence{} ; for k : Integer.subrange(1, ("" + (((n)->pow(0.5))))->toInteger() + 1-1) do ( if n mod k = 0 then ( execute ((k) : ret) ; if k /= n div k then ( execute ((n div k) : ret) ) else skip ) else skip) ; return (ret->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(k)for k in input().split()] res=[] for j in range(n//2): for k in range(m): res.append(str(j+1)+" "+str(k+1)) res.append(str(n-j)+" "+str(m-k)) if n % 2 : for j in range(m//2): res.append(f"{n//2+1}{j+1}") res.append(f"{n//2+1}{m-j}") if m % 2 : res.append(f"{n//2+1}{m//2+1}") print("\n".join(res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger())) ; var res : Sequence := Sequence{} ; for j : Integer.subrange(0, n div 2-1) do ( for k : Integer.subrange(0, m-1) do ( execute ((("" + ((j + 1))) + " " + ("" + ((k + 1)))) : res) ; execute ((("" + ((n - j))) + " " + ("" + ((m - k)))) : res))) ; if n mod 2 then ( for j : Integer.subrange(0, m div 2-1) do ( execute ((StringLib.formattedString("{n//2+1}{j+1}")) : res) ; execute ((StringLib.formattedString("{n//2+1}{m-j}")) : res)) ; if m mod 2 then ( execute ((StringLib.formattedString("{n//2+1}{m//2+1}")) : res) ) else skip ) else skip ; execute (StringLib.sumStringsWithSeparator((res), "\n"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B,K=map(int,input().split()) count=0 index=0 if A>=B : for i in reversed(range(1,B+1)): if A % i==0 and B % i==0 : index=i count=count+1 if count==K : break elif Acollect( _x | (OclType["int"])->apply(_x) ) ; var count : int := 0 ; var index : int := 0 ; if (A->compareTo(B)) >= 0 then ( for i : (Integer.subrange(1, B + 1-1))->reverse() do ( if A mod i = 0 & B mod i = 0 then ( index := i ; count := count + 1 ; if count = K then ( break ) else skip ) else skip) ) else (if (A->compareTo(B)) < 0 then ( for i : (Integer.subrange(1, A + 1-1))->reverse() do ( if A mod (i) = 0 & B mod (i) = 0 then ( index := i ; count := count + 1 ; if count = K then ( break ) else skip ) else skip) ) else skip) ; execute (index)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def printRatio(a,b,c,d): if(b*c>a*d): swap(c,d) swap(a,b) lcm=(a*c)/math.gcd(a,c) x=lcm/a b=int(b*x) y=lcm/c d=int(d*y) k=math.gcd(b,d) b=int(b/k) d=int(d/k) print(b,":",d) if __name__=='__main__' : a=4 b=3 c=2 d=2 printRatio(a,b,c,d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( a := 4 ; b := 3 ; c := 2 ; d := 2 ; printRatio(a, b, c, d) ) else skip; operation printRatio(a : OclAny, b : OclAny, c : OclAny, d : OclAny) pre: true post: true activity: if ((b * c->compareTo(a * d)) > 0) then ( swap(c, d) ; swap(a, b) ) else skip ; var lcm : double := (a * c) / (a)->gcd(c) ; var x : double := lcm / a ; b := ("" + ((b * x)))->toInteger() ; var y : double := lcm / c ; d := ("" + ((d * y)))->toInteger() ; var k : long := (b)->gcd(d) ; b := ("" + ((b / k)))->toInteger() ; d := ("" + ((d / k)))->toInteger() ; execute (b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B,K=[int(_)for _ in input().split()] a_divisors=set() b_divisors=set() for i in range(1,101): if A % i==0 : a_divisors.add(i) if B % i==0 : b_divisors.add(i) common_divisors=a_divisors & b_divisors print(sorted(list(common_divisors))[-K]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var K : OclAny := null; Sequence{A,B,K} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var a_divisors : Set := Set{}->union(()) ; var b_divisors : Set := Set{}->union(()) ; for i : Integer.subrange(1, 101-1) do ( if A mod i = 0 then ( execute ((i) : a_divisors) ) else skip ; if B mod i = 0 then ( execute ((i) : b_divisors) ) else skip) ; var common_divisors : int := MathLib.bitwiseAnd(a_divisors, b_divisors) ; execute (sorted((common_divisors))->reverse()->at(-(-K)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- W,H=map(int,input().split()) *A,=map(int,input().split()) *B,=map(int,input().split()) A.sort(reverse=1) ok=+(sum(A)==sum(B)) for a in A : B.sort(reverse=1) for i in range(a): if i>=len(B)or B[i]==0 : ok=0 break B[i]-=1 print(ok) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var W : OclAny := null; var H : OclAny := null; Sequence{W,H} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (testlist_star_expr (star_expr * (expr (atom (name A)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name A)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (testlist_star_expr (star_expr * (expr (atom (name B)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name B)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; A := A->sort() ; var ok : boolean := ((A)->sum() = (B)->sum()) ; for a : A do ( B := B->sort() ; for i : Integer.subrange(0, a-1) do ( if (i->compareTo((B)->size())) >= 0 or B[i+1] = 0 then ( ok := 0 ; break ) else skip ; B[i+1] := B[i+1] - 1)) ; execute (ok)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,heapq _,a,q=[[-int(e)for e in sys.stdin.readline().split()if e!='0']for _ in[0]*3] heapq.heapify(q) for e in a : t=[] for _ in[0]*-e : if not q : print(0); exit() if q[0]!=-1 : heapq.heappush(t,q[0]+1) heapq.heappop(q) while t : heapq.heappush(q,t[0]); heapq.heappop(t) print(int(not q)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var _anon : OclAny := null; var a : OclAny := null; var q : OclAny := null; Sequence{_anon,a,q} := MatrixLib.elementwiseMult(Sequence{ 0 }, 3)->select(_anon | true)->collect(_anon | (sys.stdin.readLine().split()->select(e | e /= '0')->collect(e | (-("" + ((e)))->toInteger())))) ; heapq.heapify(q) ; for e : a do ( var t : Sequence := Sequence{} ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, -e) do ( if not(q) then ( execute (0)->display(); exit() ) else skip ; if q->first() /= -1 then ( heapq.heappush(t, q->first() + 1) ) else skip ; heapq.heappop(q)) ; while t do ( heapq.heappush(q, t->first()); heapq.heappop(t))) ; execute (("" + ((not(q))))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() A=[int(x)for x in input().split()] B=[int(x)for x in input().split()] ans=0 A.sort(reverse=True) for a in A : B.sort(reverse=True) for i in range(a): B[i]-=1 if min(B)<0 : ans=0 break if max(B)==0 : ans=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var B : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : int := 0 ; A := A->sort() ; for a : A do ( B := B->sort() ; for i : Integer.subrange(0, a-1) do ( B[i+1] := B[i+1] - 1) ; if (B)->min() < 0 then ( ans := 0 ; break ) else skip) ; if (B)->max() = 0 then ( ans := 1 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w,h=map(int,input().split()) lst1=sorted(map(int,input().split())) lst2=sorted(map(int,input().split())) while lst1 : num=lst1.pop() for i in range(-1,-num-1,-1): lst2[i]-=1 lst2.sort() if sum(lst2)==0 and min(lst2)==0 : print(1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lst1 : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var lst2 : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; while lst1 do ( var num : OclAny := lst1->last() ; lst1 := lst1->front() ; for i : Integer.subrange(-num - 1 + 1, -1)->reverse() do ( lst2[i+1] := lst2[i+1] - 1) ; lst2 := lst2->sort()) ; if (lst2)->sum() = 0 & (lst2)->min() = 0 then ( execute (1)->display() ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys w,h=map(int,input().split()) sumC=0 sumR=0 col=list(map(int,input().split())) row=list(map(int,input().split())) for c in col : sumC+=c for r in row : sumR+=r if sumR!=sumC : print(0) sys.exit(0) for i in range(w): row.sort(reverse=True) for j in range(h): if not col[i]or not row[j]: break row[j]-=1 col[i]-=1 if col[i]>0 : print(0) sys.exit(0) print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sumC : int := 0 ; var sumR : int := 0 ; var col : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var row : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for c : col do ( sumC := sumC + c) ; for r : row do ( sumR := sumR + r) ; if sumR /= sumC then ( execute (0)->display() ; sys.exit(0) ) else skip ; for i : Integer.subrange(0, w-1) do ( row := row->sort() ; for j : Integer.subrange(0, h-1) do ( if not(col[i+1]) or not(row[j+1]) then ( break ) else skip ; row[j+1] := row[j+1] - 1 ; col[i+1] := col[i+1] - 1) ; if col[i+1] > 0 then ( execute (0)->display() ; sys.exit(0) ) else skip) ; execute (1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def flip(ch): return '1' if(ch=='0')else '0' def getFlipWithStartingCharcter(str,expected): flipCount=0 for i in range(len(str)): if(str[i]!=expected): flipCount+=1 expected=flip(expected) return flipCount def minFlipToMakeStringAlternate(str): return min(getFlipWithStartingCharcter(str,'0'),getFlipWithStartingCharcter(str,'1')) if __name__=="__main__" : str="0001010111" print(minFlipToMakeStringAlternate(str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( OclType["String"] := "0001010111" ; execute (minFlipToMakeStringAlternate(OclType["String"]))->display() ) else skip; operation flip(ch : OclAny) : OclAny pre: true post: true activity: return if (ch = '0') then '1' else '0' endif; operation getFlipWithStartingCharcter(OclType["String"] : OclAny, expected : OclAny) : OclAny pre: true post: true activity: var flipCount : int := 0 ; for i : Integer.subrange(0, (OclType["String"])->size()-1) do ( if (("" + ([i+1])) /= expected) then ( flipCount := flipCount + 1 ) else skip ; expected := flip(expected)) ; return flipCount; operation minFlipToMakeStringAlternate(OclType["String"] : OclAny) : OclAny pre: true post: true activity: return Set{getFlipWithStartingCharcter(OclType["String"], '0'), getFlipWithStartingCharcter(OclType["String"], '1')}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) s=input() if s.index("G")>s.index("T"): s=s[: :-1] if "T" in s[s.index("G"): : k].split("#")[0]: print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; if (s->indexOf("G") - 1->compareTo(s->indexOf("T") - 1)) > 0 then ( s := s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ) else skip ; if (s(subscript (test (logical_test (comparison (expr (atom (name s)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "G"))))))) ))))))) : (sliceop : (test (logical_test (comparison (expr (atom (name k)))))))).split("#")->first())->includes("T") then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input().split()[1]) s=input().strip(".#") print("NO" if(len(s)-1)% k or "#" in s[0 : len(s): k]else "YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + ((input().split()[1+1])))->toInteger() ; var s : OclAny := input()->trim() ; execute (if ((s)->size() - 1) mod k or (s(subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))) : (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (sliceop : (test (logical_test (comparison (expr (atom (name k)))))))))->includes("#") then "NO" else "YES" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys litter=[""] litter.append(list(".,!? ")) litter.append(list(" abc")) litter.append(list(" def")) litter.append(list(" ghi")) litter.append(list(" jkl")) litter.append(list(" mno")) litter.append(list(" pqrs")) litter.append(list(" tuv")) litter.append(list(" wxyz")) n=input() for count in range(n): ls=map(int,list(raw_input())) button,times=None,0 for i in ls : if i==0 : if button!=None : sys.stdout.write(litter[button][times]) button,times=None,0 else : button,times=i,times+1 if times==len(litter[button]): times=1 sys.stdout.write('\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var litter : Sequence := Sequence{ "" } ; execute (((".,!? ")->characters()) : litter) ; execute (((" abc")->characters()) : litter) ; execute (((" def")->characters()) : litter) ; execute (((" ghi")->characters()) : litter) ; execute (((" jkl")->characters()) : litter) ; execute (((" mno")->characters()) : litter) ; execute (((" pqrs")->characters()) : litter) ; execute (((" tuv")->characters()) : litter) ; execute (((" wxyz")->characters()) : litter) ; var n : String := (OclFile["System.in"]).readLine() ; for count : Integer.subrange(0, n-1) do ( var ls : Sequence := ((raw_input()))->collect( _x | (OclType["int"])->apply(_x) ) ; var button : OclAny := null; var times : OclAny := null; Sequence{button,times} := Sequence{null,0} ; for i : ls do ( if i = 0 then ( if button /= null then ( (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name litter)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name button)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name times)))))))) ])))))))) )))) ; var button : OclAny := null; var times : OclAny := null; Sequence{button,times} := Sequence{null,0} ) else skip ) else ( var button : OclAny := null; var times : OclAny := null; Sequence{button,times} := Sequence{i,times + 1} ; if times = (litter[button+1])->size() then ( var times : int := 1 ) else skip )) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ' '))))))) ))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxsum_SIS(arr,n): max_sum=0 current_sum=arr[0] for i in range(1,n): if(arr[i-1]first() ; for i : Integer.subrange(1, n-1) do ( if ((arr[i - 1+1]->compareTo(arr[i+1])) < 0) then ( current_sum := current_sum + arr[i+1] ) else ( max_sum := Set{max_sum, current_sum}->max() ; current_sum := arr[i+1] )) ; return Set{max_sum, current_sum}->max(); operation main() pre: true post: true activity: arr := Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 4 }))) ; n := (arr)->size() ; (testlist_star_expr (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Maximum sum : ")))))) , (argument (test (logical_test (comparison (expr (atom (name maxsum_SIS)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))) ))))))) ,); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,m=map(int,input().split()) ans=[] for i in range(n//2): u,v=str(i+1)+" ",str(n-i)+" " for j in range(m): ans.append(u+str(j+1)) ans.append(v+str(m-j)) if n % 2 : u=str(n//2+1)+" " for i in range(m//2): ans.append(u+str(i+1)) ans.append(u+str(m-i)) if m % 2 : v=str(m//2+1) ans.append(u+v) sys.stdout.write("\n".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, n div 2-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := Sequence{("" + ((i + 1))) + " ",("" + ((n - i))) + " "} ; for j : Integer.subrange(0, m-1) do ( execute ((u + ("" + ((j + 1)))) : ans) ; execute ((v + ("" + ((m - j)))) : ans))) ; if n mod 2 then ( var u : String := ("" + ((n div 2 + 1))) + " " ; for i : Integer.subrange(0, m div 2-1) do ( execute ((u + ("" + ((i + 1)))) : ans) ; execute ((u + ("" + ((m - i)))) : ans)) ; if m mod 2 then ( var v : String := ("" + ((m div 2 + 1))) ; execute ((u + v) : ans) ) else skip ) else skip ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def _input(): return map(int,input().split()) n,k=_input() s=input() g=s.index('G'); t=s.index('T') if t==g : print("YES"); exit() elif t=0 and s[i]!='T' and s[i]!='#' : i+=k if i>=n or s[i]!='T' : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := _input() ; var s : String := (OclFile["System.in"]).readLine() ; var g : int := s->indexOf('G') - 1; var t : int := s->indexOf('T') - 1 ; if t = g then ( execute ("YES")->display(); exit() ) else (if (t->compareTo(g)) < 0 then ( var k : OclAny := -k ) else skip) ; var i : int := g ; while (i->compareTo(n)) < 0 & i >= 0 & s[i+1] /= 'T' & s[i+1] /= '#' do ( i := i + k) ; if (i->compareTo(n)) >= 0 or s[i+1] /= 'T' then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def add_possible_jumps(n,k,visited,current,stack): if current-k>=0 and not visited[current-k]: stack.append(current-k) if current+k0 : current=stack.pop() if sequence[current]=="T" : return True else : visited[current]=True if sequence[current]=="." : add_possible_jumps(n,k,visited,current,stack) return False if __name__=='__main__' : [n,k]=input().split(" ") sequence=input() output=ostap_and_grasshopper(int(n),int(k),sequence) print("YES" if output else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( ; Sequence{n}->union(Sequence{ k }) := input().split(" ") ; sequence := (OclFile["System.in"]).readLine() ; var output : OclAny := ostap_and_grasshopper(("" + ((n)))->toInteger(), ("" + ((k)))->toInteger(), sequence) ; execute (if output then "YES" else "NO" endif)->display() ) else skip; operation add_possible_jumps(n : OclAny, k : OclAny, visited : OclAny, current : OclAny, stack : OclAny) pre: true post: true activity: if current - k >= 0 & not(visited[current - k+1]) then ( execute ((current - k) : stack) ) else skip ; if (current + k->compareTo(n)) < 0 & not(visited[current + k+1]) then ( execute ((current + k) : stack) ) else skip; operation ostap_and_grasshopper(n : OclAny, k : OclAny, sequence : OclAny) : OclAny pre: true post: true activity: visited := MatrixLib.elementwiseMult(Sequence{ false }, n) ; var start : int := sequence->indexOf("G") - 1 ; visited[start+1] := true ; stack := Sequence{} ; add_possible_jumps(n, k, visited, start, stack) ; while (stack)->size() > 0 do ( current := stack->last() ; stack := stack->front() ; if sequence[current+1] = "T" then ( return true ) else ( visited[current+1] := true ; if sequence[current+1] = "." then ( add_possible_jumps(n, k, visited, current, stack) ) else skip )) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def soln(): n_num_cells,k_len_jmp=(int(_)for _ in input().split()) cells=list(input()) g_indx=cells.index('G') t_indx=cells.index('T') dist=t_indx-g_indx if dist % k_len_jmp!=0 : print("NO") return go_right=True if(g_indx<=t_indx)else False while(g_indx!=t_indx): if(g_indx<0 or g_indx>=n_num_cells)or(cells[g_indx]=='#'): print("NO") return g_indx=(g_indx+k_len_jmp)if go_right else(g_indx-k_len_jmp) print("YES") return soln() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; soln(); operation soln() pre: true post: true activity: var n_num_cells : OclAny := null; var k_len_jmp : OclAny := null; Sequence{n_num_cells,k_len_jmp} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name _)))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var cells : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var g_indx : int := cells->indexOf('G') - 1 ; var t_indx : int := cells->indexOf('T') - 1 ; var dist : double := t_indx - g_indx ; if dist mod k_len_jmp /= 0 then ( execute ("NO")->display() ; return ) else skip ; var go_right : boolean := if ((g_indx->compareTo(t_indx)) <= 0) then true else false endif ; while (g_indx /= t_indx) do ( if (g_indx < 0 or (g_indx->compareTo(n_num_cells)) >= 0) or (cells[g_indx+1] = '#') then ( execute ("NO")->display() ; return ) else skip ; g_indx := if go_right then (g_indx + k_len_jmp) else (g_indx - k_len_jmp) endif) ; execute ("YES")->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np def Sum(arr,l,r): s=0 ; for i in range(l,r+1): s+=arr[i]; return s ; dp=np.zeros((101,101,101)); def solve(arr,l,r,k): if(r-l+1<=k): return Sum(arr,l,r); if(dp[l][r][k]): return dp[l][r][k]; sum_=Sum(arr,l,r); len_r=(r-l+1)-k ; length=(r-l+1); ans=0 ; for i in range(length-len_r+1): sum_sub=Sum(arr,i+l,i+l+len_r-1); ans=max(ans,(sum_-sum_sub)+(sum_sub-solve(arr,i+l,i+l+len_r-1,k))); dp[l][r][k]=ans ; return ans ; if __name__=="__main__" : arr=[10,15,20,9,2,5]; k=2 ; n=len(arr); print(solve(arr,0,n-1,k)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var dp : Sequence := MatrixLib.singleValueMatrix(Sequence{101, 101, 101}, 0.0); ; skip ; if __name__ = "__main__" then ( arr := Sequence{10}->union(Sequence{15}->union(Sequence{20}->union(Sequence{9}->union(Sequence{2}->union(Sequence{ 5 }))))); k := 2; ; var n : int := (arr)->size(); ; execute (solve(arr, 0, n - 1, k))->display(); ) else skip; operation Sum(arr : OclAny, l : OclAny, r : OclAny) pre: true post: true activity: var s : int := 0; ; for i : Integer.subrange(l, r + 1-1) do ( s := s + arr[i+1];) ; return s;; operation solve(arr : OclAny, l : OclAny, r : OclAny, k : OclAny) pre: true post: true activity: if ((r - l + 1->compareTo(k)) <= 0) then ( return Sum(arr, l, r); ) else skip ; if (dp[l+1][r+1][k+1]) then ( return dp[l+1][r+1][k+1]; ) else skip ; var sum_ : OclAny := Sum(arr, l, r); ; var len_r : double := (r - l + 1) - k; ; var length : double := (r - l + 1); ; var ans : int := 0; ; for i : Integer.subrange(0, length - len_r + 1-1) do ( var sum_sub : OclAny := Sum(arr, i + l, i + l + len_r - 1); ; ans := Set{ans, (sum_ - sum_sub) + (sum_sub - solve(arr, i + l, i + l + len_r - 1, k))}->max();) ; dp[l+1][r+1][k+1] := ans; ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- y,n=map(int,input().split()) a,b,c=map(int,input().split()) print(max(0,2*a+b-y)+max(0,3*c+b-n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var y : OclAny := null; var n : OclAny := null; Sequence{y,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{0, 2 * a + b - y}->max() + Set{0, 3 * c + b - n}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) x,y,z=map(int,input().split()) a1=x*2+y-a b1=z*3+y-b print((a1 if a1>=0 else 0)+(b1 if b1>=0 else 0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a1 : double := x * 2 + y - a ; var b1 : double := z * 3 + y - b ; execute ((if a1 >= 0 then a1 else 0 endif) + (if b1 >= 0 then b1 else 0 endif))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) x,y,z=map(int,input().split()) p=(2*x)+(y) q=(y)+(3*z) c=0 if p>=a : c+=(p-a) if q>=b : c+=(q-b) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : double := (2 * x) + (y) ; var q : OclAny := (y) + (3 * z) ; var c : int := 0 ; if (p->compareTo(a)) >= 0 then ( c := c + (p - a) ) else skip ; if (q->compareTo(b)) >= 0 then ( c := c + (q - b) ) else skip ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) x,y,z=map(int,input().split()) yellow=2*x+y blue=y+3*z ans=max(0,yellow-a)+max(0,blue-b) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var yellow : double := 2 * x + y ; var blue : OclAny := y + 3 * z ; var ans : OclAny := Set{0, yellow - a}->max() + Set{0, blue - b}->max() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- yc,bc=map(int,input().split()) yb,gb,bb=map(int,input().split()) y=2*yb+gb b=3*bb+gb sumx=0 yr=y-yc br=b-bc if y>yc : sumx+=yr if b>bc : sumx+=br print(sumx) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var yc : OclAny := null; var bc : OclAny := null; Sequence{yc,bc} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var yb : OclAny := null; var gb : OclAny := null; var bb : OclAny := null; Sequence{yb,gb,bb} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var y : double := 2 * yb + gb ; var b : double := 3 * bb + gb ; var sumx : int := 0 ; var yr : double := y - yc ; var br : double := b - bc ; if (y->compareTo(yc)) > 0 then ( sumx := sumx + yr ) else skip ; if (b->compareTo(bc)) > 0 then ( sumx := sumx + br ) else skip ; execute (sumx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- kite=int(input()) i=10 while kite : i+=9 if sum(map(int,str(i)))==10 : kite-=1 print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var kite : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 10 ; while kite do ( i := i + 9 ; if ((("" + ((i))))->collect( _x | (OclType["int"])->apply(_x) ))->sum() = 10 then ( kite := kite - 1 ) else skip) ; execute (i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools as it k,p=[int(elem)for elem in input().split()] def build_palindroms(k : int,p : int): val=0 digits=2 while 1 : n=digits//2 values=[10**(digits-1-i)+10**i for i in range(n)] for comb in it.product(range(1,10),*[range(0,10)for i in range(n-1)]): if not k : return val % p for j,dig in enumerate(comb): val+=dig*values[j] k-=1 digits+=2 return val % p print(build_palindroms(k,p)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var k : OclAny := null; var p : OclAny := null; Sequence{k,p} := input().split()->select(elem | true)->collect(elem | (("" + ((elem)))->toInteger())) ; skip ; execute (build_palindroms(k, p))->display(); operation build_palindroms(k : int, p : int) : OclAny pre: true post: true activity: var val : int := 0 ; var digits : int := 2 ; while 1 do ( var n : int := digits div 2 ; var values : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((10)->pow((digits - 1 - i)) + (10)->pow(i))) ; for comb : it.product(Integer.subrange(1, 10-1), (argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 10))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) )))))))) ]))))))) do ( if not(k) then ( return val mod p ) else skip ; for _tuple : Integer.subrange(1, (comb)->size())->collect( _indx | Sequence{_indx-1, (comb)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dig : OclAny := _tuple->at(_indx); val := val + dig * values[j+1]) ; k := k - 1) ; digits := digits + 2) ; return val mod p; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def factorial(n): res=1 for i in range(2,n+1): res*=i return res num=5 ; print("Factorial of",num,"is",factorial(num)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var num : int := 5; ; execute ("Factorial of")->display(); operation factorial(n : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; for i : Integer.subrange(2, n + 1-1) do ( res := res * i) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def print(u,v): sys.stdout.write("%d %d\n" %(u,v)) n,m=map(int,input().split()) ans=[] for i in range(n//2): u,v=i+1,n-i for j in range(m): print(u,j+1) print(v,m-j) if n % 2 : u=n//2+1 for i in range(m//2): print(u,i+1) print(u,m-i) if m % 2 : v=m//2+1 print(u,v) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, n div 2-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := Sequence{i + 1,n - i} ; for j : Integer.subrange(0, m-1) do ( execute (u)->display() ; execute (v)->display())) ; if n mod 2 then ( var u : int := n div 2 + 1 ; for i : Integer.subrange(0, m div 2-1) do ( execute (u)->display() ; execute (u)->display()) ; if m mod 2 then ( var v : int := m div 2 + 1 ; execute (u)->display() ) else skip ) else skip; (funcdef def name print ( (typedargslist (def_parameters (def_parameter (named_parameter (name u))) , (def_parameter (named_parameter (name v))))) ) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom "%d %d\n")) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name u)))))) , (test (logical_test (comparison (expr (atom (name v))))))) ))))))))) ))))))))))))))} ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def xorPairCount(arr,n,x): result=0 m=dict() for i in range(n): curr_xor=x ^ arr[i] if(curr_xor in m.keys()): result+=m[curr_xor] if arr[i]in m.keys(): m[arr[i]]+=1 else : m[arr[i]]=1 return result arr=[2,5,2] n=len(arr) x=0 print("Count of pairs with given XOR=",xorPairCount(arr,n,x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{5}->union(Sequence{ 2 })) ; n := (arr)->size() ; x := 0 ; execute ("Count of pairs with given XOR=")->display(); operation xorPairCount(arr : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; var m : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( var curr_xor : int := MathLib.bitwiseXor(x, arr[i+1]) ; if ((m.keys())->includes(curr_xor)) then ( result := result + m[curr_xor+1] ) else skip ; if (m.keys())->includes(arr[i+1]) then ( m[arr[i+1]+1] := m[arr[i+1]+1] + 1 ) else ( m[arr[i+1]+1] := 1 )) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() l=0 r=0 u=0 d=0 for x in s : if x=='U' : u+=1 elif x=='D' : d+=1 elif x=='L' : l+=1 else : r+=1 print(min(l,r)*2+min(u,d)*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var l : int := 0 ; var r : int := 0 ; var u : int := 0 ; var d : int := 0 ; for x : s->characters() do ( if x = 'U' then ( u := u + 1 ) else (if x = 'D' then ( d := d + 1 ) else (if x = 'L' then ( l := l + 1 ) else ( r := r + 1 ) ) ) ) ; execute (Set{l, r}->min() * 2 + Set{u, d}->min() * 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() x=0 y=0 ct=0 ans=0 for i in s : if(i=='L'): x-=1 elif(i=='R'): x+=1 elif(i=='U'): y+=1 else : y-=1 print(n-(abs(x)+abs(y))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var x : int := 0 ; var y : int := 0 ; var ct : int := 0 ; var ans : int := 0 ; for i : s->characters() do ( if (i = 'L') then ( x := x - 1 ) else (if (i = 'R') then ( x := x + 1 ) else (if (i = 'U') then ( y := y + 1 ) else ( y := y - 1 ) ) ) ) ; execute (n - ((x)->abs() + (y)->abs()))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(input()) x,y=0,0 for i in a : if i=='U' : y+=1 elif i=='D' : y-=1 elif i=='L' : x-=1 else : x+=1 print(n-abs(x)-abs(y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{0,0} ; for i : a do ( if i = 'U' then ( y := y + 1 ) else (if i = 'D' then ( y := y - 1 ) else (if i = 'L' then ( x := x - 1 ) else ( x := x + 1 ) ) ) ) ; execute (n - (x)->abs() - (y)->abs())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() l,r,u,d=0,0,0,0 for x in s : if x=='L' : l+=1 if x=='R' : r+=1 if x=='U' : u+=1 if x=='D' : d+=1 print(min(l,r)*2+min(u,d)*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var l : OclAny := null; var r : OclAny := null; var u : OclAny := null; var d : OclAny := null; Sequence{l,r,u,d} := Sequence{0,0,0,0} ; for x : s->characters() do ( if x = 'L' then ( l := l + 1 ) else skip ; if x = 'R' then ( r := r + 1 ) else skip ; if x = 'U' then ( u := u + 1 ) else skip ; if x = 'D' then ( d := d + 1 ) else skip) ; execute (Set{l, r}->min() * 2 + Set{u, d}->min() * 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=0 y=0 for i in input(): if i=="L" : x-=1 elif i=="R" : x+=1 elif i=="U" : y+=1 elif i=="D" : y-=1 print(n-abs(x)-abs(y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := 0 ; var y : int := 0 ; for i : (OclFile["System.in"]).readLine() do ( if i = "L" then ( x := x - 1 ) else (if i = "R" then ( x := x + 1 ) else (if i = "U" then ( y := y + 1 ) else (if i = "D" then ( y := y - 1 ) else skip ) ) ) ) ; execute (n - (x)->abs() - (y)->abs())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,sys,io,math from tokenize import Triple from math import* I=lambda :[*map(int,sys.stdin.readline().split())] IS=lambda : input() IN=lambda : int(input()) IF=lambda : float(input()) s=IS() n=IN() f=1 i=1 start=0 if len(s)/n==len(s)//n : count=len(s)//n while n>0 : t='' for i in range(start,count+start): t+=s[i] r=t[: :-1] if r!=t : print("NO") f=0 break start+=count n-=1 i+=n if f : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var I : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var IS : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var IN : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var IF : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toReal()) ; var s : OclAny := IS->apply() ; var n : OclAny := IN->apply() ; var f : int := 1 ; var i : int := 1 ; var start : int := 0 ; if (s)->size() / n = (s)->size() div n then ( var count : int := (s)->size() div n ; while n > 0 do ( var t : String := '' ; for i : Integer.subrange(start, count + start-1) do ( t := t + s[i+1]) ; var r : OclAny := t(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; if r /= t then ( execute ("NO")->display() ; f := 0 ; break ) else skip ; start := start + count ; n := n - 1 ; i := i + n) ; if f then ( execute ("YES")->display() ) else skip ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(s,k): if len(s)% k==0 : k=len(s)//k for i in range(0,len(s),k): if s[i : i+k][: :-1]!=s[i : i+k]: return "NO" return "YES" return "NO" print(f(input(),int(input()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (f((OclFile["System.in"]).readLine(), ("" + (((OclFile["System.in"]).readLine())))->toInteger()))->display(); operation f(s : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (s)->size() mod k = 0 then ( k := (s)->size() div k ; for i : Integer.subrange(0, (s)->size()-1)->select( $x | ($x - 0) mod k = 0 ) do ( if s.subrange(i+1, i + k)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) /= s.subrange(i+1, i + k) then ( return "NO" ) else skip) ; return "YES" ) else skip ; return "NO"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,d=map(int,input().split()) points=[list(map(int,input().split()))for _ in range(n)] def dist(x,y): tmp=0.0 for i in range(d): tmp+=(x[i]-y[i])**2 return math.sqrt(tmp) count=0 for i,elm in enumerate(points): for j in range(i+1,n): if dist(elm,points[j]).is_integer(): count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var points : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; skip ; var count : int := 0 ; for _tuple : Integer.subrange(1, (points)->size())->collect( _indx | Sequence{_indx-1, (points)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var elm : OclAny := _tuple->at(_indx); for j : Integer.subrange(i + 1, n-1) do ( if dist(elm, points[j+1]).is_integer() then ( count := count + 1 ) else skip)) ; execute (count)->display(); operation dist(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var tmp : double := 0.0 ; for i : Integer.subrange(0, d-1) do ( tmp := tmp + ((x[i+1] - y[i+1]))->pow(2)) ; return (tmp)->sqrt(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- string=input() partskitnekarnehai=int(input()) if len(string)% partskitnekarnehai!=0 : print('NO') exit() nayalength=len(string)//partskitnekarnehai for j in range(partskitnekarnehai): seedha_part=string[j*nayalength :(j+1)*nayalength] ulta_part=reversed(seedha_part) if seedha_part!="".join(ulta_part): print("NO") exit() print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var string : String := (OclFile["System.in"]).readLine() ; var partskitnekarnehai : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (string)->size() mod partskitnekarnehai /= 0 then ( execute ('NO')->display() ; exit() ) else skip ; var nayalength : int := (string)->size() div partskitnekarnehai ; for j : Integer.subrange(0, partskitnekarnehai-1) do ( var seedha_part : OclAny := string.subrange(j * nayalength+1, (j + 1) * nayalength) ; var ulta_part : Sequence := (seedha_part)->reverse() ; if seedha_part /= StringLib.sumStringsWithSeparator((ulta_part), "") then ( execute ("NO")->display() ; exit() ) else skip) ; execute ("YES")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=int(input()) def A(x): for i in range(int(len(x)/2)): if x[i]!=x[-1-i]: return False return True if len(a)% b!=0 : print('NO') else : j=1 flag=1 for i in range(0,len(a),len(a)//b): flag*=A(a[i :(len(a)//b)*j]) j+=1 if flag==0 : print('NO') else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; if (a)->size() mod b /= 0 then ( execute ('NO')->display() ) else ( var j : int := 1 ; var flag : int := 1 ; for i : Integer.subrange(0, (a)->size()-1)->select( $x | ($x - 0) mod (a)->size() div b = 0 ) do ( flag := flag * A(a.subrange(i+1, ((a)->size() div b) * j)) ; j := j + 1) ; if flag = 0 then ( execute ('NO')->display() ) else ( execute ('YES')->display() ) ); operation A(x : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, ("" + (((x)->size() / 2)))->toInteger()-1) do ( if x[i+1] /= x->reverse()->at(-(-1 - i)) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) P=list(map(int,input().split())) me=[0] for i in range(n): p=(P[i]*(P[i]+1)/2)/P[i] me.append(me[(i+1)-1]+p) ans=0 for i in range(k,n+1): ans=max(ans,me[i]-me[i-k]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var P : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var me : Sequence := Sequence{ 0 } ; for i : Integer.subrange(0, n-1) do ( var p : double := (P[i+1] * (P[i+1] + 1) / 2) / P[i+1] ; execute ((me[(i + 1) - 1+1] + p) : me)) ; var ans : int := 0 ; for i : Integer.subrange(k, n + 1-1) do ( ans := Set{ans, me[i+1] - me[i - k+1]}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(input()) k=int(input()) if len(s)% k==0 : i=0 while icharacters() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (s)->size() mod k = 0 then ( var i : int := 0 ; while (i->compareTo((s)->size())) < 0 do ( var ss : OclAny := s.subrange(i+1, i + (s)->size() div k) ; var t : Sequence := ((ss)->reverse()) ; if ss /= t then ( execute ("NO")->display(); exit() ) else skip ; i := i + ((s)->size() div k)) ; execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def san(x): y=q/2 while True : y=y-(y**3-x)/(3*y**2) if abs(y**3-x)<0.00001*x : break print(f'{y:.6f}') while True : q=int(input()) if q==-1 : break san(q) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if q = -1 then ( break ) else skip ; san(q)); operation san(x : OclAny) pre: true post: true activity: var y : double := q / 2 ; while true do ( y := y - ((y)->pow(3) - x) / (3 * (y)->pow(2)) ; if (((y)->pow(3) - x)->abs()->compareTo(0.00001 * x)) < 0 then ( break ) else skip) ; execute (StringLib.formattedString('{y:.6f}'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for e in iter(input,'-1'): q=float(e) x=q/2 while abs(x**3-q)>=q*1e-5 : x-=(x**3-q)/3/x/x print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for e : OclIterator.newOclIterator_Sequence(input, '-1') do ( var q : double := ("" + ((e)))->toReal() ; var x : double := q / 2 ; while (((x)->pow(3) - q)->abs()->compareTo(q * ("1e-5")->toReal())) >= 0 do ( x := x - ((x)->pow(3) - q) / 3 / x / x) ; execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import os import math def f(x,q): return x-(x**3-q)/(3*(x**2)) for s in sys.stdin : q=int(s) if q==-1 : break x=q/2 while abs(x**3-q)>=0.00001*q : x=f(x,q) print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; for s : OclFile["System.in"] do ( q := ("" + ((s)))->toInteger() ; if q = -1 then ( break ) else skip ; x := q / 2 ; while (((x)->pow(3) - q)->abs()->compareTo(0.00001 * q)) >= 0 do ( x := f(x, q)) ; execute (x)->display()); operation f(x : OclAny, q : OclAny) : OclAny pre: true post: true activity: return x - ((x)->pow(3) - q) / (3 * ((x)->pow(2))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rec(x1,q): return x1-((x1**3-q)/(3*(x1**2))) q=[] while True : try : tmp=int(input()) if tmp==-1 : break q.append(tmp) except EOFError : break for i in range(len(q)): x1=float(q[i]/2) while True : x1=rec(x1,q[i]) if abs(x1**3-q[i])<0.00001*q[i]: break print(x1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; q := Sequence{} ; while true do ( try ( var tmp : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if tmp = -1 then ( break ) else skip ; execute ((tmp) : q)) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))) ; for i : Integer.subrange(0, (q)->size()-1) do ( x1 := ("" + ((q[i+1] / 2)))->toReal() ; while true do ( x1 := rec(x1, q[i+1]) ; if (((x1)->pow(3) - q[i+1])->abs()->compareTo(0.00001 * q[i+1])) < 0 then ( break ) else skip) ; execute (x1)->display()); operation rec(x1 : OclAny, q : OclAny) : OclAny pre: true post: true activity: return x1 - (((x1)->pow(3) - q) / (3 * ((x1)->pow(2)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys for q in map(int,sys.stdin): if q==-1 : break x=q/2 while abs(x**3-q)>0.00001*q : x=x-(x**3-q)/(3*x**2) print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for q : (OclFile["System.in"])->collect( _x | (OclType["int"])->apply(_x) ) do ( if q = -1 then ( break ) else skip ; var x : double := q / 2 ; while (((x)->pow(3) - q)->abs()->compareTo(0.00001 * q)) > 0 do ( x := x - ((x)->pow(3) - q) / (3 * (x)->pow(2))) ; execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dsu=[] def find(key,v=set()): if len(v)==len(dsu): return if key not in v : if dsu[key]==key : return key x=find(dsu[key],v.union({key})) if x : dsu[key]=x return dsu[key] def check(x,y): find(x) a=dsu[x] find(y) b=dsu[y] if a==b : return True return False def change(x,y): find(x) a=dsu[x] find(y) b=dsu[y] dsu[a]=b def Solve(): global dsu n,m=list(map(int,input().split())) dsu=[i for i in range(m+1)] langs=set(); z=0 for i in range(n): line=list(map(int,input().split()))[1 :] if not line : z+=1 continue y=line[0] langs.add(y) for x in line[1 :]: change(x,y) langs.add(x) for i in range(m+1): check(i,0) ans=0 for i in langs : if i in dsu : ans+=1 print(ans+z-(ans!=0)) if __name__=="__main__" : Solve() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute dsu : OclAny; operation initialise() pre: true post: true activity: var dsu : Sequence := Sequence{} ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( Solve() ) else skip; operation find(key : OclAny, v : OclAny) : OclAny pre: true post: true activity: if v->oclIsUndefined() then v := Set{}->union(()) else skip; if (v)->size() = (dsu)->size() then ( return ) else skip ; if (v)->excludes(key) then ( if dsu[key+1] = key then ( return key ) else skip ; var x : OclAny := find(dsu[key+1], v.union(Set{ key })) ; if x then ( dsu[key+1] := x ) else skip ; return dsu[key+1] ) else skip; operation check(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: find(x) ; var a : OclAny := dsu[x+1] ; find(y) ; var b : OclAny := dsu[y+1] ; if a = b then ( return true ) else skip ; return false; operation change(x : OclAny, y : OclAny) pre: true post: true activity: find(x) ; a := dsu[x+1] ; find(y) ; b := dsu[y+1] ; dsu[a+1] := b; operation Solve() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; dsu := Integer.subrange(0, m + 1-1)->select(i | true)->collect(i | (i)) ; var langs : Set := Set{}->union(()); var z : int := 0 ; for i : Integer.subrange(0, n-1) do ( var line : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->tail() ; if not(line) then ( z := z + 1 ; continue ) else skip ; y := line->first() ; execute ((y) : langs) ; for x : line->tail() do ( change(x, y) ; execute ((x) : langs))) ; for i : Integer.subrange(0, m + 1-1) do ( check(i, 0)) ; var ans : int := 0 ; for i : langs do ( if (dsu)->includes(i) then ( ans := ans + 1 ) else skip) ; execute (ans + z - (ans /= 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function import sys input=sys.stdin.readline def eprint(*args,**kwargs): print(*args,file=sys.stderr,**kwargs) return def main(): n,d=map(int,input().strip().split()) ll=[[]for i in range(n)] for i in range(n): ll[i]=list(map(int,input().strip().split())) cnt=0 for i in range(n): for j in range(i+1,n): dist=0 for k in range(0,d): dist+=(ll[i][k]-ll[j][k])**2 dist_sqr=dist**(1/2) if dist_sqr.is_integer()is True : cnt+=1 print(cnt) return if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation eprint(args : OclAny : Sequence(OclAny), kwargs : OclAny : Map(String, OclAny)) pre: true post: true activity: (args * (named_parameter (name args)))(kwargs ** (named_parameter (name kwargs))) execute ((argument * (test (logical_test (comparison (expr (atom (name args))))))))->display() ; return; operation main() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ll : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, n-1) do ( ll[i+1] := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( var dist : int := 0 ; for k : Integer.subrange(0, d-1) do ( dist := dist + ((ll[i+1][k+1] - ll[j+1][k+1]))->pow(2)) ; var dist_sqr : double := (dist)->pow((1 / 2)) ; if dist_sqr.is_integer() <>= true then ( cnt := cnt + 1 ) else skip)) ; execute (cnt)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict class UnionFind : def __init__(self,size): self.root=[i for i in range(size)] self.rank=[1]*size def find(self,x): while x!=self.root[x]: x=self.root[x] return x def union(self,x,y): rootX=self.find(x) rootY=self.find(y) if rootX!=rootY : if self.rank[rootX]>self.rank[rootY]: self.root[rootY]=rootX elif self.rank[rootX]exists( _x | result = _x ); attribute root : Sequence := Integer.subrange(0, size-1)->select(i | true)->collect(i | (i)); attribute rank : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, size); operation initialise(size : OclAny) : UnionFind pre: true post: true activity: self.root := Integer.subrange(0, size-1)->select(i | true)->collect(i | (i)) ; self.rank := MatrixLib.elementwiseMult(Sequence{ 1 }, size); return self; operation find(x : OclAny) : OclAny pre: true post: true activity: while x /= self.root[x+1] do ( x := self.root[x+1]) ; return x; operation union(x : OclAny,y : OclAny) pre: true post: true activity: var rootX : int := self->indexOf(x) - 1 ; var rootY : int := self->indexOf(y) - 1 ; if rootX /= rootY then ( if (self.rank[rootX+1]->compareTo(self.rank[rootY+1])) > 0 then ( self.root[rootY+1] := rootX ) else (if (self.rank[rootX+1]->compareTo(self.rank[rootY+1])) < 0 then ( self.root[rootX+1] := rootY ) else ( self.root[rootY+1] := rootX ; self.rank[rootX+1] := self.rank[rootX+1] + 1 ) ) ) else skip; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var uf : UnionFind := (UnionFind.newUnionFind()).initialise(m) ; var merge : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if arr->first() /= 0 then ( var rep : int := uf->indexOf(arr[1+1] - 1) - 1 ; merge[i+1] := rep ; for j : arr.subrange(2+1) do ( uf.union(uf->indexOf(j - 1) - 1, rep)) ) else ( c := c + 1 ; merge[i+1] := -1 )) ; var counter : Set := Set{}->union(()) ; for j : Integer.subrange(0, n-1) do ( var i : OclAny := merge[j+1] ; if i /= -1 then ( execute ((uf->indexOf(i) - 1) : counter) ) else skip) ; var n : int := (counter)->size() ; if n = 0 then ( execute (c)->display() ) else ( execute (c + n - 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict class UnionFind : def __init__(self,size): self.root=[i for i in range(size)] self.rank=[1]*size def find(self,x): while x!=self.root[x]: x=self.root[x] return x def union(self,x,y): rootX=self.find(x) rootY=self.find(y) if rootX!=rootY : if self.rank[rootX]>self.rank[rootY]: self.root[rootY]=rootX elif self.rank[rootX]exists( _x | result = _x ); attribute root : Sequence := Integer.subrange(0, size-1)->select(i | true)->collect(i | (i)); attribute rank : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, size); operation initialise(size : OclAny) : UnionFind pre: true post: true activity: self.root := Integer.subrange(0, size-1)->select(i | true)->collect(i | (i)) ; self.rank := MatrixLib.elementwiseMult(Sequence{ 1 }, size); return self; operation find(x : OclAny) : OclAny pre: true post: true activity: while x /= self.root[x+1] do ( x := self.root[x+1]) ; return x; operation union(x : OclAny,y : OclAny) pre: true post: true activity: var rootX : int := self->indexOf(x) - 1 ; var rootY : int := self->indexOf(y) - 1 ; if rootX /= rootY then ( if (self.rank[rootX+1]->compareTo(self.rank[rootY+1])) > 0 then ( self.root[rootY+1] := rootX ) else (if (self.rank[rootX+1]->compareTo(self.rank[rootY+1])) < 0 then ( self.root[rootX+1] := rootY ) else ( self.root[rootY+1] := rootX ; self.rank[rootX+1] := self.rank[rootX+1] + 1 ) ) ) else skip; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var uf : UnionFind := (UnionFind.newUnionFind()).initialise(m) ; var lang : Set := Set{}->union(()) ; var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if arr->first() /= 0 then ( var rep : int := uf->indexOf(arr[1+1] - 1) - 1 ; execute ((arr[1+1]) : lang) ; for j : arr.subrange(2+1) do ( uf.union(uf->indexOf(j - 1) - 1, rep) ; execute ((j) : lang)) ) else ( c := c + 1 )) ; var counter : OclAny := defaultdict(OclType["Sequence"]) ; for i : lang do ((expr (atom (name counter)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name uf)) (trailer . (name find) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var n : OclAny := Set{(counter)->size() - 1, 0}->max() ; execute (c + n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,threading sys.setrecursionlimit(2147483647) input=sys.stdin.readline def print(*args,end='\n',sep=' ')->None : sys.stdout.write(sep.join(map(str,args))+end) def dfs(node): global graph,visited visited[node]=1 for child in graph[node]: if not visited[child]: dfs(child) def Solve(): global graph,visited n,m=list(map(int,input().split())) graph={x : set()for x in range(1,n+1)} langs={} z=0 for x in range(1,n+1): line=list(map(int,input().split())) k,list_=line[0],line[1 :] for c in list_ : if c not in langs.keys(): langs[c]=set() for co in langs[c]: graph[x].add(co); graph[co].add(x) langs[c].add(x) if k==0 : z+=1 visited=[0]*(n+1) ans=0 for node in graph.keys(): if not visited[node]: ans+=1 dfs(node) print(ans-1*(z!=n)) if __name__=="__main__" : threading.stack_size(10**8) threading.Thread(target=Solve).start() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute graph : OclAny; attribute visited : OclAny; attribute graph : OclAny; attribute visited : OclAny; operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(2147483647) ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; if __name__ = "__main__" then ( threading.stack_size((10)->pow(8)) ; (expr (atom (name threading)) (trailer . (name Thread) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name Solve)))))))) ))) (trailer . (name start) (arguments ( )))) ) else skip; (funcdef def name print ( (typedargslist (args * (named_parameter (name args))) , (def_parameters (def_parameter (named_parameter (name end)) = (test (logical_test (comparison (expr (atom ' ')))))) , (def_parameter (named_parameter (name sep)) = (test (logical_test (comparison (expr (atom ' ')))))))) ) -> (test (logical_test (comparison (expr (atom None))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name sep)) (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name args)))))))) ))))))))) )))) + (expr (atom (name end))))))))) )))))))))))))) operation dfs(node : OclAny) pre: true post: true activity: skip; skip ; visited[node+1] := 1 ; for child : graph[node+1] do ( if not(visited[child+1]) then ( dfs(child) ) else skip); operation Solve() pre: true post: true activity: skip; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; graph := Integer.subrange(1, n + 1-1)->select(x | true)->collect(x | Map{x |-> Set{}->union(())})->unionAll() ; var langs : OclAny := Set{} ; var z : int := 0 ; for x : Integer.subrange(1, n + 1-1) do ( var line : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k : OclAny := null; var list_ : OclAny := null; Sequence{k,list_} := Sequence{line->first(),line->tail()} ; for c : list_ do ( if (langs.keys())->excludes(c) then ( langs[c+1] := Set{}->union(()) ) else skip ; for co : langs[c+1] do ((expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name co)))))))) ))));(expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name co)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))) ; (expr (atom (name langs)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name c)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))) ; if k = 0 then ( z := z + 1 ) else skip) ; visited := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var ans : int := 0 ; for node : graph.keys() do ( if not(visited[node+1]) then ( ans := ans + 1 ; dfs(node) ) else skip) ; execute (ans - 1 * (z /= n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline MOD=10**9+7 INF=float('INF') sys.setrecursionlimit(10**5) def main(): N,K=map(int,readline().split()) P=[0]+list(map(int,readline().split())) cur=sum(P[: K]) s_max=0 for i in range(N-K+1): cur+=P[K+i] cur-=P[i] s_max=max(s_max,cur) print((s_max+K)/2) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var MOD : double := (10)->pow(9) + 7 ; var INF : double := ("" + (('INF')))->toReal() ; sys.setrecursionlimit((10)->pow(5)) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var P : Sequence := Sequence{ 0 }->union(((readline().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var cur : OclAny := (P.subrange(1,K))->sum() ; var s_max : int := 0 ; for i : Integer.subrange(0, N - K + 1-1) do ( cur := cur + P[K + i+1] ; cur := cur - P[i+1] ; s_max := Set{s_max, cur}->max()) ; execute ((s_max + K) / 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dsu=[] def find(key,v=set()): if len(v)==len(dsu): return if key not in v : if dsu[key]==key : return key x=find(dsu[key],v.union({key})) if x : dsu[key]=x return dsu[key] def check(x,y): find(x) a=dsu[x] find(y) b=dsu[y] if a==b : return True return False def change(x,y): find(x) a=dsu[x] find(y) b=dsu[y] dsu[a]=b def Solve(): global dsu n,m=list(map(int,input().split())) dsu=[i for i in range(m+1)] langs=set(); z=0 for i in range(n): line=list(map(int,input().split()))[1 :] if not line : z+=1 continue y=line[0] langs.add(y) for x in line[1 :]: change(x,y) langs.add(x) for i in range(m+1): check(i,0) ans=0 for i in langs : if i in dsu : ans+=1 print(ans+z-(ans!=0)) if __name__=="__main__" : Solve() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute dsu : OclAny; operation initialise() pre: true post: true activity: var dsu : Sequence := Sequence{} ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( Solve() ) else skip; operation find(key : OclAny, v : OclAny) : OclAny pre: true post: true activity: if v->oclIsUndefined() then v := Set{}->union(()) else skip; if (v)->size() = (dsu)->size() then ( return ) else skip ; if (v)->excludes(key) then ( if dsu[key+1] = key then ( return key ) else skip ; var x : OclAny := find(dsu[key+1], v.union(Set{ key })) ; if x then ( dsu[key+1] := x ) else skip ; return dsu[key+1] ) else skip; operation check(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: find(x) ; var a : OclAny := dsu[x+1] ; find(y) ; var b : OclAny := dsu[y+1] ; if a = b then ( return true ) else skip ; return false; operation change(x : OclAny, y : OclAny) pre: true post: true activity: find(x) ; a := dsu[x+1] ; find(y) ; b := dsu[y+1] ; dsu[a+1] := b; operation Solve() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; dsu := Integer.subrange(0, m + 1-1)->select(i | true)->collect(i | (i)) ; var langs : Set := Set{}->union(()); var z : int := 0 ; for i : Integer.subrange(0, n-1) do ( var line : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->tail() ; if not(line) then ( z := z + 1 ; continue ) else skip ; y := line->first() ; execute ((y) : langs) ; for x : line->tail() do ( change(x, y) ; execute ((x) : langs))) ; for i : Integer.subrange(0, m + 1-1) do ( check(i, 0)) ; var ans : int := 0 ; for i : langs do ( if (dsu)->includes(i) then ( ans := ans + 1 ) else skip) ; execute (ans + z - (ans /= 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def recamanGenerator(arr,n): arr[0]=0 for i in range(1,n): temp=arr[i-1]-i j=0 for j in range(i): if((arr[j]==temp)or temp<0): temp=arr[i-1]+i break arr[i]=temp def recamanArray(arr,n): s=dict() recaman=[0 for i in range(n)] recamanGenerator(recaman,n) for i in range(n): s[recaman[i]]=s.get(recaman[i],0)+1 for i in range(n): if arr[i]in s.keys(): del s[arr[i]] return len(s) arr=[7,11,20,4,2,1,8,6] n=len(arr) print(recamanArray(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{7}->union(Sequence{11}->union(Sequence{20}->union(Sequence{4}->union(Sequence{2}->union(Sequence{1}->union(Sequence{8}->union(Sequence{ 6 }))))))) ; n := (arr)->size() ; execute (recamanArray(arr, n))->display(); operation recamanGenerator(arr : OclAny, n : OclAny) pre: true post: true activity: arr->first() := 0 ; for i : Integer.subrange(1, n-1) do ( var temp : double := arr[i - 1+1] - i ; var j : int := 0 ; for j : Integer.subrange(0, i-1) do ( if ((arr[j+1] = temp) or temp < 0) then ( temp := arr[i - 1+1] + i ; break ) else skip) ; arr[i+1] := temp); operation recamanArray(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var s : Map := (arguments ( )) ; var recaman : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; recamanGenerator(recaman, n) ; for i : Integer.subrange(0, n-1) do ( s[recaman[i+1]+1] := s.get(recaman[i+1], 0) + 1) ; for i : Integer.subrange(0, n-1) do ( if (s.keys())->includes(arr[i+1]) then ( execute (s[arr[i+1]+1])->isDeleted() ) else skip) ; return (s)->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import random import sys from collections import defaultdict from functools import lru_cache from math import inf sys.setrecursionlimit(2*10**6) def test(): pass def main(): n,m=map(int,input().split()) ps=[0]*(n+1) ns=[0]*(n+1) stm=[] for _ in range(n): s=int(input()) if s>0 : ps[s]+=1 else : ns[-s]+=1 stm.append(s) pss=sum(ps) nss=sum(ns) ts=[set()for _ in range(n+1)] ss=set() for s in range(1,n+1): mm=ps[s]+nss-ns[s] if mm==m : ss.add(s) for st in stm : if st>0 : if len(ss)==1 and st in ss : print('Truth') continue if st not in ss : print('Lie') continue else : if len(ss)==1 and-st in ss : print('Lie') continue if-st not in ss : print('Truth') continue print('Not defined') def init(): import sys import os if 'CP_LOCAL_ENV' in os.environ : test() sys.stdin=open('test.txt') if __name__=='__main__' : init() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(2 * (10)->pow(6)) ; skip ; skip ; skip ; if __name__ = '__main__' then ( init() ; main() ) else skip; operation test() pre: true post: true activity: skip; operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ps : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var ns : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var stm : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if s > 0 then ( ps[s+1] := ps[s+1] + 1 ) else ( ns->reverse()->at(-(-s)) := ns->reverse()->at(-(-s)) + 1 ) ; execute ((s) : stm)) ; var pss : OclAny := (ps)->sum() ; var nss : OclAny := (ns)->sum() ; var ts : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; var ss : Set := Set{}->union(()) ; for s : Integer.subrange(1, n + 1-1) do ( var mm : double := ps[s+1] + nss - ns[s+1] ; if mm = m then ( execute ((s) : ss) ) else skip) ; for st : stm do ( if st > 0 then ( if (ss)->size() = 1 & (ss)->includes(st) then ( execute ('Truth')->display() ; continue ) else skip ; if (ss)->excludes(st) then ( execute ('Lie')->display() ; continue ) else skip ) else ( if (ss)->size() = 1 & (ss)->includes(-st) then ( execute ('Lie')->display() ; continue ) else skip ; if (ss)->excludes(-st) then ( execute ('Truth')->display() ; continue ) else skip ) ; execute ('Not defined')->display()); operation init() pre: true post: true activity: skip ; skip ; if (os.environ)->includes('CP_LOCAL_ENV') then ( test() ; OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('test.txt')) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=list(map(int,input().split())) a=[[0,0]for i in range(n)] b=[] e=0 f=0 for i in range(n): c=input() d=int(c[1 :]) if c[0]=='+' : a[d-1][0]+=1 e+=1 else : a[d-1][1]+=1 f+=1 b.append([c[0],d]) g=[a[i][0]+f-a[i][1]for i in range(n)] h=g.count(m) for i in range(n): d=b[i][1] if b[i][0]=='+' : if g[d-1]==m : if h>1 : print('Not defined') else : print('Truth') else : print('Lie') else : if h>1 or h==1 and g[d-1]!=m : if g[d-1]==m : print('Not defined') else : print('Truth') else : print('Lie') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{0}->union(Sequence{ 0 }))) ; var b : Sequence := Sequence{} ; var e : int := 0 ; var f : int := 0 ; for i : Integer.subrange(0, n-1) do ( var c : String := (OclFile["System.in"]).readLine() ; var d : int := ("" + ((c->tail())))->toInteger() ; if c->first() = '+' then ( a[d - 1+1]->first() := a[d - 1+1]->first() + 1 ; e := e + 1 ) else ( a[d - 1+1][1+1] := a[d - 1+1][1+1] + 1 ; f := f + 1 ) ; execute ((Sequence{c->first()}->union(Sequence{ d })) : b)) ; var g : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (a[i+1]->first() + f - a[i+1][1+1])) ; var h : int := g->count(m) ; for i : Integer.subrange(0, n-1) do ( d := b[i+1][1+1] ; if b[i+1]->first() = '+' then ( if g[d - 1+1] = m then ( if h > 1 then ( execute ('Not defined')->display() ) else ( execute ('Truth')->display() ) ) else ( execute ('Lie')->display() ) ) else ( if h > 1 or h = 1 & g[d - 1+1] /= m then ( if g[d - 1+1] = m then ( execute ('Not defined')->display() ) else ( execute ('Truth')->display() ) ) else ( execute ('Lie')->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import copy import gc import itertools from array import array from fractions import Fraction import heapq import math import operator import os,sys import profile import cProfile import random import re import string from bisect import bisect_left,bisect_right from collections import defaultdict,deque,Counter from functools import reduce,lru_cache from io import IOBase,BytesIO from itertools import count,groupby,accumulate,permutations,combinations_with_replacement,product from math import gcd from operator import xor,add from typing import List input=lambda : sys.stdin.readline().rstrip("\n") def read_int_list(): return list(map(int,input().split())) def read_int_tuple(): return tuple(map(int,input().split())) def read_int(): return int(input()) def main(): for _ in range(1): n,m=read_int_tuple() yes,no=[0]*(n+1),[0]*(n+1) res=[] for _ in range(n): x=read_int() res.append(x) [no,yes][x>0][abs(x)]+=1 yes_cnt,no_cnt=sum(yes),sum(no) crimers=set() for i in range(1,n+1): true_cnt=yes[i]+no_cnt-no[i] if true_cnt==m : crimers.add(i) for x in res : if len(crimers)==1 : print([['Truth','Lie'],['Lie','Truth']][x>0][abs(x)in crimers]) else : print([['Truth','Not defined'],['Lie','Not defined']][x>0][abs(x)in crimers]) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip("\n")) ; skip ; skip ; skip ; skip ; Sequence{no}->union(Sequence{ yes })->select(x > 0)[(x)->abs()+1] := Sequence{no}->union(Sequence{ yes })->select(x > 0)[(x)->abs()+1] + 1; operation read_int_list() : OclAny pre: true post: true activity: return ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )); operation read_int_tuple() : OclAny pre: true post: true activity: return ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )); operation read_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation main() pre: true post: true activity: for _anon : Integer.subrange(0, 1-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := read_int_tuple() ; var yes : OclAny := null; var no : OclAny := null; Sequence{yes,no} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)),MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1))} ; var res : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := read_int() ; execute ((x) : res))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import defaultdict sys.setrecursionlimit(2*10**6) def solve(n,m,arr)->None : ps=defaultdict(int) ns=defaultdict(int) for a in arr : if a>0 : ps[a]+=1 else : ns[-a]+=1 cs=set() sns=sum(ns.values()) for c in range(1,10**5+1): t=sns if c in ps : t+=ps[c] if c in ns : t-=ns[c] if t==m : cs.add(c) ans=[] for a in arr : if a>0 : if a in cs : if len(cs)==1 : ans.append('Truth') else : ans.append('Not defined') else : ans.append('Lie') else : if-a in cs : if len(cs)==1 : ans.append('Lie') else : ans.append('Not defined') else : ans.append('Truth') for a in ans : print(a) def test(): pass def main(): n,m=map(int,input().split()) arr=[] for _ in range(n): arr.append(int(input())) solve(n,m,arr) def init(): import sys import os if 'DOCKER_HOST' in os.environ : test() sys.stdin=open('test.txt') if __name__=='__main__' : init() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit(2 * (10)->pow(6)) ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( init() ; main() ) else skip; operation solve(n : OclAny, m : OclAny, arr : OclAny) : OclAny pre: true post: true activity: var ps : OclAny := defaultdict(OclType["int"]) ; var ns : OclAny := defaultdict(OclType["int"]) ; for a : arr do ( if a > 0 then ( ps[a+1] := ps[a+1] + 1 ) else ( ns->reverse()->at(-(-a)) := ns->reverse()->at(-(-a)) + 1 )) ; var cs : Set := Set{}->union(()) ; var sns : OclAny := (ns.values())->sum() ; for c : Integer.subrange(1, (10)->pow(5) + 1-1) do ( var t : OclAny := sns ; if (ps)->includes(c) then ( t := t + ps[c+1] ) else skip ; if (ns)->includes(c) then ( t := t - ns[c+1] ) else skip ; if t = m then ( execute ((c) : cs) ) else skip) ; var ans : Sequence := Sequence{} ; for a : arr do ( if a > 0 then ( if (cs)->includes(a) then ( if (cs)->size() = 1 then ( execute (('Truth') : ans) ) else ( execute (('Not defined') : ans) ) ) else ( execute (('Lie') : ans) ) ) else ( if (cs)->includes(-a) then ( if (cs)->size() = 1 then ( execute (('Lie') : ans) ) else ( execute (('Not defined') : ans) ) ) else ( execute (('Truth') : ans) ) )) ; for a : ans do ( execute (a)->display()); operation test() pre: true post: true activity: skip; operation main() pre: true post: true activity: Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; arr := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : arr)) ; solve(n, m, arr); operation init() pre: true post: true activity: skip ; skip ; if (os.environ)->includes('DOCKER_HOST') then ( test() ; OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('test.txt')) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np N,D=map(int,input().split()) X=np.empty((0,D),int) for i in range(N): X=np.append(X,np.array([list(map(int,input().split()))]),axis=0) ans=0 for i in range(N): for j in range(i+1,N): diff=X[j]-X[i] d=np.linalg.norm(diff) if d.is_integer(): ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var D : OclAny := null; Sequence{N,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var X : Sequence := MatrixLib.singleValueMatrix(Sequence{0, D}, 0.0) ; for i : Integer.subrange(0, N-1) do ( X := ) ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(i + 1, N-1) do ( var diff : double := X[j+1] - X[i+1] ; var d : OclAny := np.linalg.norm(diff) ; if d.is_integer() then ( ans := ans + 1 ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- [n,m]=input().split() n=int(n) m=int(m) arr=[] ps=[] ns=[] suspects=[] for i in range(0,n): a=input() a=int(a) arr.append(a) ps.append(0) ns.append(0) suspects.append(0) sum_ns=0 for i in arr : if i>0 : ps[i-1]+=1 else : ns[-i-1]+=1 sum_ns+=1 num_suspects=0 for i in range(0,n): if ps[i]+sum_ns-ns[i]==m : suspects[i]=1 num_suspects+=1 for i in arr : if i>0 : if suspects[i-1]: if num_suspects==1 : print("Truth") else : print("Not defined") else : print("Lie") else : if suspects[-i-1]: if num_suspects==1 : print("Lie") else : print("Not defined") else : print("Truth") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: Sequence{n}->union(Sequence{ m }) := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var m : int := ("" + ((m)))->toInteger() ; var arr : Sequence := Sequence{} ; var ps : Sequence := Sequence{} ; var ns : Sequence := Sequence{} ; var suspects : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : String := (OclFile["System.in"]).readLine() ; a := ("" + ((a)))->toInteger() ; execute ((a) : arr) ; execute ((0) : ps) ; execute ((0) : ns) ; execute ((0) : suspects)) ; var sum_ns : int := 0 ; for i : arr do ( if i > 0 then ( ps[i - 1+1] := ps[i - 1+1] + 1 ) else ( ns->reverse()->at(-(-i - 1)) := ns->reverse()->at(-(-i - 1)) + 1 ; sum_ns := sum_ns + 1 )) ; var num_suspects : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ps[i+1] + sum_ns - ns[i+1] = m then ( suspects[i+1] := 1 ; num_suspects := num_suspects + 1 ) else skip) ; for i : arr do ( if i > 0 then ( if suspects[i - 1+1] then ( if num_suspects = 1 then ( execute ("Truth")->display() ) else ( execute ("Not defined")->display() ) ) else ( execute ("Lie")->display() ) ) else ( if suspects->reverse()->at(-(-i - 1)) then ( if num_suspects = 1 then ( execute ("Lie")->display() ) else ( execute ("Not defined")->display() ) ) else ( execute ("Truth")->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import pow def isAutoBio(num): autoStr=str(num) for i in range(0,len(autoStr)): index=int(autoStr[i]) cnt=0 for j in range(0,len(autoStr)): number=int(autoStr[j]) if number==i : cnt+=1 if cnt!=index : return False return True def findAutoBios(n): low=int(pow(10,n-1)) high=int(pow(10,n)-1) flag=0 for i in range(low,high+1): if isAutoBio(i): flag=1 print(i,end=',') if flag==0 : print("There is no Autobiographical Number with "+str(n)+" digits") if __name__=="__main__" : N=0 findAutoBios(N) N=4 findAutoBios(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( var N : int := 0 ; findAutoBios(N) ; N := 4 ; findAutoBios(N) ) else skip; operation isAutoBio(num : OclAny) : OclAny pre: true post: true activity: var autoStr : String := ("" + ((num))) ; for i : Integer.subrange(0, (autoStr)->size()-1) do ( var index : int := ("" + ((autoStr[i+1])))->toInteger() ; var cnt : int := 0 ; for j : Integer.subrange(0, (autoStr)->size()-1) do ( var number : int := ("" + ((autoStr[j+1])))->toInteger() ; if number = i then ( cnt := cnt + 1 ) else skip) ; if cnt /= index then ( return false ) else skip) ; return true; operation findAutoBios(n : OclAny) pre: true post: true activity: var low : int := ("" + (((10)->pow(n - 1))))->toInteger() ; var high : int := ("" + (((10)->pow(n) - 1)))->toInteger() ; var flag : int := 0 ; for i : Integer.subrange(low, high + 1-1) do ( if isAutoBio(i) then ( flag := 1 ; execute (i)->display() ) else skip) ; if flag = 0 then ( execute ("There is no Autobiographical Number with " + ("" + ((n))) + " digits")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def factorial(n): res=1 ; for i in range(2,n+1): res*=i ; return res ; def printNComposite(n): fact=factorial(n+1); for i in range(2,n+2): print(fact+i,end=" "); n=4 ; printNComposite(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 4; ; printNComposite(n);; operation factorial(n : OclAny) pre: true post: true activity: var res : int := 1; ; for i : Integer.subrange(2, n + 1-1) do ( res := res * i;) ; return res;; operation printNComposite(n : OclAny) pre: true post: true activity: var fact : OclAny := factorial(n + 1); ; for i : Integer.subrange(2, n + 2-1) do ( execute (fact + i)->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) count=[0]*m d=n//m r=n % m for i in range(m): if i>0 and i<=r : count[(i*i)% m]+=d+1 else : count[(i*i)% m]+=d ans=count[0]*count[0] for i in range(1,m): if i>m-i : break if m-i==i : ans+=count[i]*count[i] else : ans+=2*count[i]*count[m-i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; var d : int := n div m ; var r : int := n mod m ; for i : Integer.subrange(0, m-1) do ( if i > 0 & (i->compareTo(r)) <= 0 then ( count[(i * i) mod m+1] := count[(i * i) mod m+1] + d + 1 ) else ( count[(i * i) mod m+1] := count[(i * i) mod m+1] + d )) ; var ans : double := count->first() * count->first() ; for i : Integer.subrange(1, m-1) do ( if (i->compareTo(m - i)) > 0 then ( break ) else skip ; if m - i = i then ( ans := ans + count[i+1] * count[i+1] ) else ( ans := ans + 2 * count[i+1] * count[m - i+1] )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=input().split() N=int(N) K=int(K) kobetu_kitaiti=[(int(i)+1)/2 for i in input().split()] sum_=sum(kobetu_kitaiti[0 : K]) max_=sum_ for i in range(N-K): sum_=sum_-kobetu_kitaiti[i]+kobetu_kitaiti[i+K] max_=max(sum_,max_) print(max_) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := input().split() ; var N : int := ("" + ((N)))->toInteger() ; var K : int := ("" + ((K)))->toInteger() ; var kobetu_kitaiti : Sequence := input().split()->select(i | true)->collect(i | ((("" + ((i)))->toInteger() + 1) / 2)) ; var sum_ : OclAny := (kobetu_kitaiti.subrange(0+1, K))->sum() ; var max_ : OclAny := sum_ ; for i : Integer.subrange(0, N - K-1) do ( sum_ := sum_ - kobetu_kitaiti[i+1] + kobetu_kitaiti[i + K+1] ; max_ := Set{sum_, max_}->max()) ; execute (max_)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def DivideCandies(n,m): paresCount=0 cociente,resto=divmod(n,m) for i in range(1,m+1): for j in range(1,i+1): if(i**2+j**2)% m==0 : filaCount=cociente colCount=cociente if j<=resto : colCount+=1 if i<=resto : filaCount+=1 actualCount=filaCount*colCount if i!=j : actualCount*=2 paresCount+=actualCount return paresCount if __name__=="__main__" : n,m=map(int,input().split()) paresCount=DivideCandies(n,m) print(paresCount) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; paresCount := DivideCandies(n, m) ; execute (paresCount)->display() ) else skip; operation DivideCandies(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var paresCount : int := 0 ; var cociente : OclAny := null; var resto : OclAny := null; Sequence{cociente,resto} := Sequence{(n div m), (n mod m)} ; for i : Integer.subrange(1, m + 1-1) do ( for j : Integer.subrange(1, i + 1-1) do ( if ((i)->pow(2) + (j)->pow(2)) mod m = 0 then ( var filaCount : OclAny := cociente ; var colCount : OclAny := cociente ; if (j->compareTo(resto)) <= 0 then ( colCount := colCount + 1 ) else skip ; if (i->compareTo(resto)) <= 0 then ( filaCount := filaCount + 1 ) else skip ; var actualCount : double := filaCount * colCount ; if i /= j then ( actualCount := actualCount * 2 ) else skip ; paresCount := paresCount + actualCount ) else skip)) ; return paresCount; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout from math import floor,gcd,fabs,factorial,fmod,sqrt,inf,log from collections import defaultdict as dd,deque from heapq import merge,heapify,heappop,heappush,nsmallest from bisect import bisect_left as bl,bisect_right as br,bisect mod=pow(10,9)+7 mod2=998244353 def inp(): return stdin.readline().strip() def iinp(): return int(inp()) def out(var,end="\n"): stdout.write(str(var)+"\n") def outa(*var,end="\n"): stdout.write(' '.join(map(str,var))+end) def lmp(): return list(mp()) def mp(): return map(int,inp().split()) def l1d(n,val=0): return[val for i in range(n)] def l2d(n,m,val=0): return[l1d(m,val)for j in range(n)] def ceil(a,b): return(a+b-1)//b S1='abcdefghijklmnopqrstuvwxyz' S2='ABCDEFGHIJKLMNOPQRSTUVWXYZ' def isprime(x): if x<=1 : return False if x in(2,3): return True if x % 2==0 : return False for i in range(3,int(sqrt(x))+1,2): if x % i==0 : return False return True n,m=mp() ans=0 for i in range(1,m+1): for j in range(1,m+1): if((i*i)% m+(j*j)% m)% m==0 : ans+=((n-i)//m+1)*((n-j)//m+1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; var mod2 : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var S1 : String := 'abcdefghijklmnopqrstuvwxyz' ; var S2 : String := 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ; skip ; Sequence{n,m} := mp() ; var ans : int := 0 ; for i : Integer.subrange(1, m + 1-1) do ( for j : Integer.subrange(1, m + 1-1) do ( if ((i * i) mod m + (j * j) mod m) mod m = 0 then ( ans := ans + ((n - i) div m + 1) * ((n - j) div m + 1) ) else skip)) ; execute (ans)->display(); operation inp() : OclAny pre: true post: true activity: return stdin.readLine()->trim(); operation iinp() : OclAny pre: true post: true activity: return ("" + ((inp())))->toInteger(); operation out(var : OclAny, end : String) pre: true post: true activity: if end->oclIsUndefined() then end := "\n" else skip; stdout.write(("" + ((var))) + "\n"); operation outa(var : OclAny : Sequence(OclAny), end : String) pre: true post: true activity: (args * (named_parameter (name var))) if end->oclIsUndefined() then end := "\n" else skip; stdout.write(StringLib.sumStringsWithSeparator(((var)->collect( _x | (OclType["String"])->apply(_x) )), ' ') + end); operation lmp() : OclAny pre: true post: true activity: return (mp()); operation mp() : OclAny pre: true post: true activity: return (inp().split())->collect( _x | (OclType["int"])->apply(_x) ); operation l1d(n : OclAny, val : int) : OclAny pre: true post: true activity: if val->oclIsUndefined() then val := 0 else skip; return Integer.subrange(0, n-1)->select(i | true)->collect(i | (val)); operation l2d(n : OclAny, m : OclAny, val : int) : OclAny pre: true post: true activity: if val->oclIsUndefined() then val := 0 else skip; return Integer.subrange(0, n-1)->select(j | true)->collect(j | (l1d(m, val))); operation ceil(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a + b - 1) div b; operation isprime(x : OclAny) : OclAny pre: true post: true activity: if x <= 1 then ( return false ) else skip ; if (Sequence{2, 3})->includes(x) then ( return true ) else skip ; if x mod 2 = 0 then ( return false ) else skip ; for i : Integer.subrange(3, ("" + ((sqrt(x))))->toInteger() + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if x mod i = 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def DivideCandies(n,m): paresCount=0 cociente,resto=divmod(n,m) for i in range(1,m+1): for j in range(1,i+1): if(i**2+j**2)% m==0 : filaCount=cociente colCount=cociente if j<=resto : colCount+=1 if i<=resto : filaCount+=1 actualCount=filaCount*colCount if i!=j : actualCount*=2 paresCount+=actualCount return paresCount if __name__=="__main__" : n,m=map(int,input().split()) paresCount=DivideCandies(n,m) print(paresCount) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; paresCount := DivideCandies(n, m) ; execute (paresCount)->display() ) else skip; operation DivideCandies(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var paresCount : int := 0 ; var cociente : OclAny := null; var resto : OclAny := null; Sequence{cociente,resto} := Sequence{(n div m), (n mod m)} ; for i : Integer.subrange(1, m + 1-1) do ( for j : Integer.subrange(1, i + 1-1) do ( if ((i)->pow(2) + (j)->pow(2)) mod m = 0 then ( var filaCount : OclAny := cociente ; var colCount : OclAny := cociente ; if (j->compareTo(resto)) <= 0 then ( colCount := colCount + 1 ) else skip ; if (i->compareTo(resto)) <= 0 then ( filaCount := filaCount + 1 ) else skip ; var actualCount : double := filaCount * colCount ; if i /= j then ( actualCount := actualCount * 2 ) else skip ; paresCount := paresCount + actualCount ) else skip)) ; return paresCount; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def line2int(linea): temp="" for i in linea : if i=="" : if temp!="" : val1=int(temp) temp="" else : temp=temp+i val2=int(temp) return(val1,val2) (a,b)=line2int(input()) num2a=num2b=0 num3a=num3b=0 num5a=num5b=0 while a % 2==0 : a=int(a/2) num2a=num2a+1 while a % 3==0 : a=int(a/3) num3a=num3a+1 while a % 5==0 : a=int(a/5) num5a=num5a+1 while b % 2==0 : b=int(b/2) num2b=num2b+1 while b % 3==0 : b=int(b/3) num3b=num3b+1 while b % 5==0 : b=int(b/5) num5b=num5b+1 if a==b : print(abs(num2a-num2b)+abs(num3a-num3b)+abs(num5a-num5b)) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var Sequence{a, b} : OclAny := line2int((OclFile["System.in"]).readLine()) ; var num2a : OclAny := 0; var num2b : int := 0 ; var num3a : OclAny := 0; var num3b : int := 0 ; var num5a : OclAny := 0; var num5b : int := 0 ; while a mod 2 = 0 do ( var a : int := ("" + ((a / 2)))->toInteger() ; num2a := num2a + 1) ; while a mod 3 = 0 do ( a := ("" + ((a / 3)))->toInteger() ; num3a := num3a + 1) ; while a mod 5 = 0 do ( a := ("" + ((a / 5)))->toInteger() ; num5a := num5a + 1) ; while b mod 2 = 0 do ( var b : int := ("" + ((b / 2)))->toInteger() ; num2b := num2b + 1) ; while b mod 3 = 0 do ( b := ("" + ((b / 3)))->toInteger() ; num3b := num3b + 1) ; while b mod 5 = 0 do ( b := ("" + ((b / 5)))->toInteger() ; num5b := num5b + 1) ; if a = b then ( execute ((num2a - num2b)->abs() + (num3a - num3b)->abs() + (num5a - num5b)->abs())->display() ) else ( execute (-1)->display() ); operation line2int(linea : OclAny) : OclAny pre: true post: true activity: var temp : String := "" ; for i : linea do ( if i = "" then ( if temp /= "" then ( var val1 : int := ("" + ((temp)))->toInteger() ; temp := "" ) else skip ) else ( temp := temp + i )) ; var val2 : int := ("" + ((temp)))->toInteger() ; return Sequence{val1, val2}; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin import math def ssolve(): a,b=(map(int,stdin.readline().split())) l=[0,0,0] while a % 5==0 : a=a//5 l[0]+=1 while a % 3==0 : a=a//3 l[1]+=1 while a % 2==0 : a=a//2 l[2]+=1 while b % 5==0 : b=b//5 l[0]-=1 while b % 3==0 : b=b//3 l[1]-=1 while b % 2==0 : b=b//2 l[2]-=1 if b==a : tot=0 for i in l : tot+=abs(i) return tot else : return-1 print(ssolve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; execute (ssolve())->display(); operation ssolve() : OclAny pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) ; while a mod 5 = 0 do ( var a : int := a div 5 ; l->first() := l->first() + 1) ; while a mod 3 = 0 do ( a := a div 3 ; l[1+1] := l[1+1] + 1) ; while a mod 2 = 0 do ( a := a div 2 ; l[2+1] := l[2+1] + 1) ; while b mod 5 = 0 do ( var b : int := b div 5 ; l->first() := l->first() - 1) ; while b mod 3 = 0 do ( b := b div 3 ; l[1+1] := l[1+1] - 1) ; while b mod 2 = 0 do ( b := b div 2 ; l[2+1] := l[2+1] - 1) ; if b = a then ( var tot : int := 0 ; for i : l do ( tot := tot + (i)->abs()) ; return tot ) else ( return -1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import ceil,floor,sqrt,sin,cos,pi from itertools import accumulate,permutations,combinations from fractions import gcd from collections import deque,Counter from operator import itemgetter from heapq import heappop,heappush sys.setrecursionlimit(10**7) def lcm(x,y): return((x*y)//gcd(x,y)) n,d=map(int,input().split()) x=[] for _ in range(n): x.append(list(map(int,input().split()))) cnt=0 for i in range(n-1): for j in range(i+1,n): ans=0.0 for k in range(d): ans+=(x[i][k]-x[j][k])**2 if sqrt(ans).is_integer(): cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; x := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : x)) ; var cnt : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(i + 1, n-1) do ( var ans : double := 0.0 ; for k : Integer.subrange(0, d-1) do ( ans := ans + ((x[i+1][k+1] - x[j+1][k+1]))->pow(2)) ; if sqrt(ans).is_integer() then ( cnt := cnt + 1 ) else skip)) ; execute (cnt)->display(); operation lcm(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return ((x * y) div gcd(x, y)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) ans=0 for i in(2,3,5): while a % i==0 and b % i==0 : a/=i b/=i while a % i==0 : a/=i ans+=1 while b % i==0 : b/=i ans+=1 if a==b : print(ans) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; for i : Sequence{2, 3, 5} do ( while a mod i = 0 & b mod i = 0 do ( a := a / i ; b := b / i) ; while a mod i = 0 do ( a := a / i ; ans := ans + 1) ; while b mod i = 0 do ( b := b / i ; ans := ans + 1)) ; if a = b then ( execute (ans)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- divide=[2,3,5] def minEats(a,b): eats=0 for d in divide : aCount=0 ; bCount=0 while a % d==0 : a//=d aCount+=1 while b % d==0 : b//=d bCount+=1 eats+=abs(aCount-bCount) if a==b : return eats return-1 a,b=list(map(int,input().split(' '))) print(minEats(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var divide : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{ 5 })) ; skip ; Sequence{a,b} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; execute (minEats(a, b))->display(); operation minEats(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var eats : int := 0 ; for d : divide do ( var aCount : int := 0; var bCount : int := 0 ; while a mod d = 0 do ( a := a div d ; aCount := aCount + 1) ; while b mod d = 0 do ( b := b div d ; bCount := bCount + 1) ; eats := eats + (aCount - bCount)->abs()) ; if a = b then ( return eats ) else skip ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=[int(x)for x in input().split()] da={2 : 0,3 : 0,5 : 0} db={2 : 0,3 : 0,5 : 0} while a % 2==0 or a % 3==0 or a % 5==0 : if a % 2==0 : da[2]+=1 a=a/2 continue if a % 3==0 : da[3]+=1 a=a/3 continue if a % 5==0 : da[5]+=1 a=a/5 continue while b % 2==0 or b % 3==0 or b % 5==0 : if b % 2==0 : db[2]+=1 b=b/2 continue if b % 3==0 : db[3]+=1 b=b/3 continue if b % 5==0 : db[5]+=1 b=b/5 continue if a!=b : print(-1) else : ans=abs(da[2]-db[2])+abs(da[3]-db[3])+abs(da[5]-db[5]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var da : Map := Map{ 2 |-> 0 }->union(Map{ 3 |-> 0 }->union(Map{ 5 |-> 0 })) ; var db : Map := Map{ 2 |-> 0 }->union(Map{ 3 |-> 0 }->union(Map{ 5 |-> 0 })) ; while a mod 2 = 0 or a mod 3 = 0 or a mod 5 = 0 do ( if a mod 2 = 0 then ( da[2+1] := da[2+1] + 1 ; var a : double := a / 2 ; continue ) else skip ; if a mod 3 = 0 then ( da[3+1] := da[3+1] + 1 ; a := a / 3 ; continue ) else skip ; if a mod 5 = 0 then ( da[5+1] := da[5+1] + 1 ; a := a / 5 ; continue ) else skip) ; while b mod 2 = 0 or b mod 3 = 0 or b mod 5 = 0 do ( if b mod 2 = 0 then ( db[2+1] := db[2+1] + 1 ; var b : double := b / 2 ; continue ) else skip ; if b mod 3 = 0 then ( db[3+1] := db[3+1] + 1 ; b := b / 3 ; continue ) else skip ; if b mod 5 = 0 then ( db[5+1] := db[5+1] + 1 ; b := b / 5 ; continue ) else skip) ; if a /= b then ( execute (-1)->display() ) else ( var ans : double := (da[2+1] - db[2+1])->abs() + (da[3+1] - db[3+1])->abs() + (da[5+1] - db[5+1])->abs() ; execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNumbers(N): v=[]; while(N): n,m,p=N,0,1 while(n): if(n % 10): m+=p n//=10 p*=10 v.append(m); N-=m for i in range(len(v)): print(v[i],end=" ") if __name__=="__main__" : N=31 findNumbers(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := 31 ; findNumbers(N) ) else skip; operation findNumbers(N : OclAny) pre: true post: true activity: var v : Sequence := Sequence{}; ; while (N) do ( var n : OclAny := null; var m : OclAny := null; var p : OclAny := null; Sequence{n,m,p} := Sequence{N,0,1} ; while (n) do ( if (n mod 10) then ( m := m + p ) else skip ; n := n div 10 ; p := p * 10) ; execute ((m) : v); ; N := N - m) ; for i : Integer.subrange(0, (v)->size()-1) do ( execute (v[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): FACTORS=(2,3,5,7,11,13,17,19,23,29,31,37,41,43) factorsols=[[j for j in range(fact)if pow(j,3,fact)==1]for fact in FACTORS] def build_and_sum_solutions(i,x,mod): if i==len(FACTORS): return x else : fact=FACTORS[i] return sum(build_and_sum_solutions(i+1,chinese_remainder_theorem(x,mod,sol,fact),mod*fact)for sol in factorsols[i]) ans=build_and_sum_solutions(0,0,1)-1 return str(ans) def chinese_remainder_theorem(a,p,b,q): return(a+(b-a)*eulerlib.reciprocal_mod(p % q,q)*p)%(p*q) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var FACTORS : OclAny := Sequence{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43} ; var factorsols : Sequence := FACTORS->select(fact | true)->collect(fact | (Integer.subrange(0, fact-1)->select(j | (j)->pow(3) = 1)->collect(j | (j)))) ; skip ; var ans : double := build_and_sum_solutions(0, 0, 1) - 1 ; return ("" + ((ans))); operation chinese_remainder_theorem(a : OclAny, p : OclAny, b : OclAny, q : OclAny) : OclAny pre: true post: true activity: return (a + (b - a) * eulerlib.reciprocal_mod(p mod q, q) * p) mod (p * q); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) P=list(map(int,input().split())) ExP=list(map(lambda x :(x+1)/2,P)) ans=0 prev=0 now=sum(ExP[0 : k]) ans=max(ans,now) prev=now for i in range(1,n-k+1): now=prev-ExP[i-1]+ExP[i+k-1] ans=max(ans,now) prev=now print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var P : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ExP : Sequence := ((P)->collect( _x | (lambda x : OclAny in ((x + 1) / 2))->apply(_x) )) ; var ans : int := 0 ; var prev : int := 0 ; var now : OclAny := (ExP.subrange(0+1, k))->sum() ; ans := Set{ans, now}->max() ; prev := now ; for i : Integer.subrange(1, n - k + 1-1) do ( now := prev - ExP[i - 1+1] + ExP[i + k - 1+1] ; ans := Set{ans, now}->max() ; prev := now) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def factorial(n): return 1 if(n==1 or n==0)else n*factorial(n-1); num=5 ; print("Factorial of",num,"is",factorial(num)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var num : int := 5; ; execute ("Factorial of")->display();; operation factorial(n : OclAny) pre: true post: true activity: return if (n = 1 or n = 0) then 1 else n * factorial(n - 1) endif;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dp=[[0 for i in range(15001)]for j in range(1001)] def computeDpArray(arr,n): for i in range(n): for j in range(1,15001,1): if(i==0): dp[i][j]=(j==arr[i]) else : dp[i][j]=dp[i-1][j]+(arr[i]==j) def countTripletSum(arr,n): computeDpArray(arr,n) ans=0 for i in range(0,n-2,1): for j in range(i+1,n-1,1): for k in range(1,25,1): cube=k*k*k rem=cube-(arr[i]+arr[j]) if(rem>0): ans+=dp[n-1][rem]-dp[j][rem] return ans if __name__=='__main__' : arr=[2,5,1,20,6] n=len(arr) print(countTripletSum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dp : Sequence := Integer.subrange(0, 1001-1)->select(j | true)->collect(j | (Integer.subrange(0, 15001-1)->select(i | true)->collect(i | (0)))) ; skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{2}->union(Sequence{5}->union(Sequence{1}->union(Sequence{20}->union(Sequence{ 6 })))) ; n := (arr)->size() ; execute (countTripletSum(arr, n))->display() ) else skip; operation computeDpArray(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(1, 15001-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if (i = 0) then ( dp[i+1][j+1] := (j = arr[i+1]) ) else ( dp[i+1][j+1] := dp[i - 1+1][j+1] + (arr[i+1] = j) ))); operation countTripletSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: computeDpArray(arr, n) ; var ans : int := 0 ; for i : Integer.subrange(0, n - 2-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( for j : Integer.subrange(i + 1, n - 1-1)->select( $x | ($x - i + 1) mod 1 = 0 ) do ( for k : Integer.subrange(1, 25-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( var cube : double := k * k * k ; var rem : double := cube - (arr[i+1] + arr[j+1]) ; if (rem > 0) then ( ans := ans + dp[n - 1+1][rem+1] - dp[j+1][rem+1] ) else skip))) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def print(*args,end='\n',sep=' ')->None : sys.stdout.write(sep.join(map(str,args))+end) def Solve(): input(); l=input().split() print("YES" if(l.count("1")% 2==0 and l.count("2")% 2==0)or(l.count("1")>=2 and(l.count("1"))% 2==0)else "NO") if __name__=="__main__" : for t in range(int(input())): Solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; if __name__ = "__main__" then ( for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( Solve()) ) else skip; (funcdef def name print ( (typedargslist (args * (named_parameter (name args))) , (def_parameters (def_parameter (named_parameter (name end)) = (test (logical_test (comparison (expr (atom ' ')))))) , (def_parameter (named_parameter (name sep)) = (test (logical_test (comparison (expr (atom ' ')))))))) ) -> (test (logical_test (comparison (expr (atom None))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name sep)) (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name args)))))))) ))))))))) )))) + (expr (atom (name end))))))))) )))))))))))))) operation Solve() pre: true post: true activity: input(); var l : OclAny := input().split() ; execute (if (l->count("1") mod 2 = 0 & l->count("2") mod 2 = 0) or (l->count("1") >= 2 & (l->count("1")) mod 2 = 0) then "YES" else "NO" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) li=list(map(int,input().split())) o=li.count(1) t=li.count(2) if o==0 and t % 2==0 : print("YES") elif t==0 and o % 2==0 : print("YES") elif o % 2==0 and t % 2==0 : print("YES") elif o % 2!=0 and t % 2==0 and t==o : print("YES") elif o % 2==0 and t % 2!=0 and o>1 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var o : int := li->count(1) ; var t : int := li->count(2) ; if o = 0 & t mod 2 = 0 then ( execute ("YES")->display() ) else (if t = 0 & o mod 2 = 0 then ( execute ("YES")->display() ) else (if o mod 2 = 0 & t mod 2 = 0 then ( execute ("YES")->display() ) else (if o mod 2 /= 0 & t mod 2 = 0 & t = o then ( execute ("YES")->display() ) else (if o mod 2 = 0 & t mod 2 /= 0 & o > 1 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,d=list(map(int,input().split())) ls1=[] for i in range(n): ls1.append(list(map(int,input().split()))) flag=0 for i in range(n): for j in range(i+1,n): total=0 for k in range(d): total=total+(ls1[i][k]-ls1[j][k])**2 total_root=math.sqrt(total) if total_root.is_integer(): flag+=1 print(flag) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ls1 : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : ls1)) ; var flag : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( var total : int := 0 ; for k : Integer.subrange(0, d-1) do ( total := total + ((ls1[i+1][k+1] - ls1[j+1][k+1]))->pow(2)) ; var total_root : double := (total)->sqrt() ; if total_root.is_integer() then ( flag := flag + 1 ) else skip)) ; execute (flag)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) for i in range(a): b=int(input()) d=[int(num)for num in input().split()] if sum(d)% 2==0 : if b % 2!=0 and min(d)==max(d): print("NO") else : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, a-1) do ( var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Sequence := input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; if (d)->sum() mod 2 = 0 then ( if b mod 2 /= 0 & (d)->min() = (d)->max() then ( execute ("NO")->display() ) else ( execute ("YES")->display() ) ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def print(*args,end='\n',sep=' ')->None : sys.stdout.write(sep.join(map(str,args))+end) def Solve(): input(); l=input().split() print("YES" if(l.count("1")% 2==0 and l.count("2")% 2==0)or(l.count("1")>=2 and(l.count("2")+1)% 2==0 and(l.count("1")-2)% 2==0)else "NO") if __name__=="__main__" : for t in range(int(input())): Solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; if __name__ = "__main__" then ( for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( Solve()) ) else skip; (funcdef def name print ( (typedargslist (args * (named_parameter (name args))) , (def_parameters (def_parameter (named_parameter (name end)) = (test (logical_test (comparison (expr (atom ' ')))))) , (def_parameter (named_parameter (name sep)) = (test (logical_test (comparison (expr (atom ' ')))))))) ) -> (test (logical_test (comparison (expr (atom None))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name sep)) (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name args)))))))) ))))))))) )))) + (expr (atom (name end))))))))) )))))))))))))) operation Solve() pre: true post: true activity: input(); var l : OclAny := input().split() ; execute (if (l->count("1") mod 2 = 0 & l->count("2") mod 2 = 0) or (l->count("1") >= 2 & (l->count("2") + 1) mod 2 = 0 & (l->count("1") - 2) mod 2 = 0) then "YES" else "NO" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def print(*args,end='\n',sep=' ')->None : sys.stdout.write(sep.join(map(str,args))+end) def Solve(): input(); l=input().split() print("YES" if(l.count("1")% 2==0 and l.count("2")% 2==0)or(l.count("1")>=2 and(l.count("1"))% 2==0)else "NO") if __name__=="__main__" : for t in range(int(input())): Solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; if __name__ = "__main__" then ( for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( Solve()) ) else skip; (funcdef def name print ( (typedargslist (args * (named_parameter (name args))) , (def_parameters (def_parameter (named_parameter (name end)) = (test (logical_test (comparison (expr (atom ' ')))))) , (def_parameter (named_parameter (name sep)) = (test (logical_test (comparison (expr (atom ' ')))))))) ) -> (test (logical_test (comparison (expr (atom None))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name sep)) (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name args)))))))) ))))))))) )))) + (expr (atom (name end))))))))) )))))))))))))) operation Solve() pre: true post: true activity: input(); var l : OclAny := input().split() ; execute (if (l->count("1") mod 2 = 0 & l->count("2") mod 2 = 0) or (l->count("1") >= 2 & (l->count("1")) mod 2 = 0) then "YES" else "NO" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B,C=map(int,input().split(' ')) K=int(input()) x=max(A,B,C) y=x*(1-2**K)/(1-2) print(int(A+B+C+y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{A,B,C} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : OclAny := Set{A, B, C}->max() ; var y : double := x * (1 - (2)->pow(K)) / (1 - 2) ; execute (("" + ((A + B + C + y)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import string def readints(): return list(map(int,input().split())) def nCr(n,r): return math.factorial(n)//(math.factorial(n-r)*math.factorial(r)) def has_duplicates2(seq): seen=[] for item in seq : if not(item in seen): seen.append(item) return len(seq)!=len(seen) def divisor(n): divisor=[] for i in range(1,n+1): if n % i==0 : divisor.append(i) return divisor dx=[-1,-1,-1,0,0,1,1,1] dy=[-1,0,1,-1,1,-1,0,1] abc=readints() k=int(input()) x=sorted(abc) xx=x[2] for _ in range(k): xx*=2 print(x[0]+x[1]+xx) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var dx : Sequence := Sequence{-1}->union(Sequence{-1}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))))))) ; var dy : Sequence := Sequence{-1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{-1}->union(Sequence{1}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{ 1 }))))))) ; var abc : OclAny := readints() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := abc->sort() ; var xx : OclAny := x[2+1] ; for _anon : Integer.subrange(0, k-1) do ( xx := xx * 2) ; execute (x->first() + x[1+1] + xx)->display(); operation readints() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation nCr(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: return MathLib.factorial(n) div (MathLib.factorial(n - r) * MathLib.factorial(r)); operation has_duplicates2(seq : OclAny) : OclAny pre: true post: true activity: var seen : Sequence := Sequence{} ; for item : seq do ( if not(((seen)->includes(item))) then ( execute ((item) : seen) ) else skip) ; return (seq)->size() /= (seen)->size(); operation divisor(n : OclAny) : OclAny pre: true post: true activity: var divisor : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( if n mod i = 0 then ( execute ((i) : divisor) ) else skip) ; return divisor; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- line=input() a,b,c=[int(n)for n in line.split()] k=int(input()) max_val=max(a,b,c) max_val_mem=max_val amax=False bmax=False cmax=False for _ in range(k): max_val*=2 if max_val_mem==a : amax=True print(str(max_val+b+c)) elif max_val_mem==b : bmax=True print(str(max_val+a+c)) elif max_val_mem==c : cmax=True print(str(max_val+a+b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var line : String := (OclFile["System.in"]).readLine() ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := line.split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var max_val : OclAny := Set{a, b, c}->max() ; var max_val_mem : OclAny := max_val ; var amax : boolean := false ; var bmax : boolean := false ; var cmax : boolean := false ; for _anon : Integer.subrange(0, k-1) do ( max_val := max_val * 2) ; if max_val_mem = a then ( amax := true ; execute (("" + ((max_val + b + c))))->display() ) else (if max_val_mem = b then ( bmax := true ; execute (("" + ((max_val + a + c))))->display() ) else (if max_val_mem = c then ( cmax := true ; execute (("" + ((max_val + a + b))))->display() ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import queue N,K=map(int,input().split()) p=list(map(int,input().split())) for i in range(len(p)): p[i]=p[i]+1 queue=queue.Queue() currentSum=0 maxSum=0 for i in range(len(p)): currentSum=currentSum+p[i] queue.put(p[i]) if i>=K : currentSum=currentSum-queue.get() if i>=K-1 : maxSum=max(maxSum,currentSum) print("{:.12f}".format(maxSum/2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, (p)->size()-1) do ( p[i+1] := p[i+1] + 1) ; var queue : OclAny := queue.Queue() ; var currentSum : int := 0 ; var maxSum : int := 0 ; for i : Integer.subrange(0, (p)->size()-1) do ( currentSum := currentSum + p[i+1] ; queue.put(p[i+1]) ; if (i->compareTo(K)) >= 0 then ( currentSum := currentSum - queue.get() ) else skip ; if (i->compareTo(K - 1)) >= 0 then ( maxSum := Set{maxSum, currentSum}->max() ) else skip) ; execute (StringLib.interpolateStrings("{:.12f}", Sequence{maxSum / 2}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- abclist=[int(x)for x in input().split()] k=int(input()) abclist.sort(reverse=True) abclist[0]=abclist[0]*(2**k) print(sum(abclist)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var abclist : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; abclist := abclist->sort() ; abclist->first() := abclist->first() * ((2)->pow(k)) ; execute ((abclist)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) k=int(input()) if(a>b and a>c): for aa in range(k): a=a*2 elif(b>a and b>c): for bb in range(k): b=b*2 else : for cc in range(k): c=c*2 print(a+b+c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if ((a->compareTo(b)) > 0 & (a->compareTo(c)) > 0) then ( for aa : Integer.subrange(0, k-1) do ( var a : double := a * 2) ) else (if ((b->compareTo(a)) > 0 & (b->compareTo(c)) > 0) then ( for bb : Integer.subrange(0, k-1) do ( var b : double := b * 2) ) else ( for cc : Integer.subrange(0, k-1) do ( var c : double := c * 2) ) ) ; execute (a + b + c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.readline()[:-1] def main(): N=int(input()) P=[] for k in range(1,1+int((N-1)**(1/2))): if(N-1)% k==0 : P.append((N-1)//k) P.append(k) P=set(P) ans=len(P) for k in range(2,1+int(N**(1/2))): if N % k==0 : t=N//k while t % k==0 : t//=k if t % k==1 : ans+=1 print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var P : Sequence := Sequence{} ; for k : Integer.subrange(1, 1 + ("" + ((((N - 1))->pow((1 / 2)))))->toInteger()-1) do ( if (N - 1) mod k = 0 then ( execute (((N - 1) div k) : P) ; execute ((k) : P) ) else skip) ; P := Set{}->union((P)) ; var ans : int := (P)->size() ; for k : Integer.subrange(2, 1 + ("" + (((N)->pow((1 / 2)))))->toInteger()-1) do ( if N mod k = 0 then ( var t : int := N div k ; while t mod k = 0 do ( t := t div k) ; if t mod k = 1 then ( ans := ans + 1 ) else skip ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def GCD(a,b): if(b==0): return a return GCD(b,a % b) def findMaxSumUtil(arr,n): finalGCD=arr[0] for i in range(1,n): finalGCD=GCD(arr[i],finalGCD) return finalGCD def findMaxSum(arr,n): maxElement=findMaxSumUtil(arr,n) return(maxElement*n) arr=[8,20,12,36] n=len(arr) print(findMaxSum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; arr := Sequence{8}->union(Sequence{20}->union(Sequence{12}->union(Sequence{ 36 }))) ; n := (arr)->size() ; execute (findMaxSum(arr, n))->display(); operation GCD(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (b = 0) then ( return a ) else skip ; return GCD(b, a mod b); operation findMaxSumUtil(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var finalGCD : OclAny := arr->first() ; for i : Integer.subrange(1, n-1) do ( finalGCD := GCD(arr[i+1], finalGCD)) ; return finalGCD; operation findMaxSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var maxElement : OclAny := findMaxSumUtil(arr, n) ; return (maxElement * n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools from collections import deque sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 DR=[1,-1,0,0] DC=[0,0,1,-1] def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def get_yakusu(n): ans=set() for i in range(1,int(math.sqrt(n))+1): if n % i==0 : if i!=1 : ans.add(i) if n//i!=i : ans.add(n//i) return ans def main(): N=I() cnt=0 if N==2 : print(1) return yakusu=get_yakusu(N) n1yakusu=get_yakusu(N-1) for n in yakusu : cpN=N while True : if cpN % n==0 : cpN=cpN//n else : break if cpN % n==1 : cnt+=1 cnt+=len(n1yakusu) print(cnt) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var mod : double := (10)->pow(9) + 7 ; var DR : Sequence := Sequence{1}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{ 0 }))) ; var DC : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ -1 }))) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; main(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation get_yakusu(n : OclAny) : OclAny pre: true post: true activity: var ans : Set := Set{}->union(()) ; for i : Integer.subrange(1, ("" + (((n)->sqrt())))->toInteger() + 1-1) do ( if n mod i = 0 then ( if i /= 1 then ( execute ((i) : ans) ) else skip ; if n div i /= i then ( execute ((n div i) : ans) ) else skip ) else skip) ; return ans; operation main() pre: true post: true activity: var N : OclAny := I() ; var cnt : int := 0 ; if N = 2 then ( execute (1)->display() ; return ) else skip ; var yakusu : OclAny := get_yakusu(N) ; var n1yakusu : OclAny := get_yakusu(N - 1) ; for n : yakusu do ( var cpN : OclAny := N ; while true do ( if cpN mod n = 0 then ( cpN := cpN div n ) else ( break )) ; if cpN mod n = 1 then ( cnt := cnt + 1 ) else skip) ; cnt := cnt + (n1yakusu)->size() ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input=raw_input n=int(input()) def fctr1(n): f=[] c=0 r=int(n**0.5) for i in range(2,r+2): while n % i==0 : c+=1 n=n//i if c!=0 : f.append([i,c]) c=0 if n!=1 : f.append([n,1]) return f def make_divisors(n): divisors=[] for i in range(1,int(n**0.5)+1): if n % i==0 : divisors.append(i) if i!=n//i : divisors.append(n//i) return divisors def f(n,k): tmp=[n] while True : q=n % k if q==0 : n/=k tmp.append(n) elif q==1 : tmp.append(q) return True else : return False elms=fctr1(n-1) out1=1 for a,b in elms : out1*=(b+1) out1-=1 yaku2=make_divisors(n) out2=0 yaku2.remove(n) yaku2.remove(1) for ya1 in yaku2 : ya2=n//ya1 while ya1 % ya2==0 : ya1//=ya2 if ya1 % ya2==1 : out2+=1 out2+=1 out=out1+out2 print(out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var input : OclAny := raw_input ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; skip ; skip ; var elms : OclAny := fctr1(n - 1) ; var out1 : int := 1 ; for _tuple : elms do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); out1 := out1 * (b + 1)) ; out1 := out1 - 1 ; var yaku2 : OclAny := make_divisors(n) ; var out2 : int := 0 ; execute ((n) /: yaku2) ; execute ((1) /: yaku2) ; for ya1 : yaku2 do ( var ya2 : int := n div ya1 ; while ya1 mod ya2 = 0 do ( ya1 := ya1 div ya2) ; if ya1 mod ya2 = 1 then ( out2 := out2 + 1 ) else skip) ; out2 := out2 + 1 ; var out : int := out1 + out2 ; execute (out)->display(); operation fctr1(n : OclAny) : OclAny pre: true post: true activity: var f : Sequence := Sequence{} ; var c : int := 0 ; var r : int := ("" + (((n)->pow(0.5))))->toInteger() ; for i : Integer.subrange(2, r + 2-1) do ( while n mod i = 0 do ( c := c + 1 ; n := n div i) ; if c /= 0 then ( execute ((Sequence{i}->union(Sequence{ c })) : f) ; c := 0 ) else skip) ; if n /= 1 then ( execute ((Sequence{n}->union(Sequence{ 1 })) : f) ) else skip ; return f; operation make_divisors(n : OclAny) : OclAny pre: true post: true activity: var divisors : Sequence := Sequence{} ; for i : Integer.subrange(1, ("" + (((n)->pow(0.5))))->toInteger() + 1-1) do ( if n mod i = 0 then ( execute ((i) : divisors) ; if i /= n div i then ( execute ((n div i) : divisors) ) else skip ) else skip) ; return divisors; operation f(n : OclAny, k : OclAny) pre: true post: true activity: var tmp : Sequence := Sequence{ n } ; while true do ( var q : int := n mod k ; if q = 0 then ( n := n / k ; execute ((n) : tmp) ) else (if q = 1 then ( execute ((q) : tmp) ; return true ) else ( return false ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import random import sys sys.setrecursionlimit(10**7) input=sys.stdin.readline MAX_INT=2**62-1 def main(): def check(num,k): mod=num % k if mod==1 : return True if mod : return False exp=k while num % exp==0 : num//=exp exp*=exp return check(num,k) N=int(input()) ans=2 for i in range(2,round(N**0.5)+1): ans+=((N-1)% i==0)*2 if N % i==0 : ans+=check(N,i) print(ans-(round((N-1)**0.5)**2==N-1)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; var input : OclAny := (OclFile["System.in"]).readline ; var MAX_INT : double := (2)->pow(62) - 1 ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 2 ; for i : Integer.subrange(2, ((N)->pow(0.5))->round() + 1-1) do ( ans := ans + ((N - 1) mod i = 0) * 2 ; if N mod i = 0 then ( ans := ans + check(N, i) ) else skip) ; execute (ans - (((((N - 1))->pow(0.5))->round())->pow(2) = N - 1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) cnt=0 import math result=set([]) for i in range(1,int(math.sqrt(n-1))+1): if(n-1)% i==0 : for item in[i,(n-1)//i]: if item!=1 : result.add(item) for i in range(1,int(math.sqrt(n))+1): if n % i==0 : for item in[i,n//i]: if item!=1 : N=n while N % item==0 : N=N//item if N==1 : result.add(item) elif N % item==1 : result.add(item) print(len(result)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cnt : int := 0 ; skip ; var result : Set := Set{}->union((Sequence{})) ; for i : Integer.subrange(1, ("" + (((n - 1)->sqrt())))->toInteger() + 1-1) do ( if (n - 1) mod i = 0 then ( for item : Sequence{i}->union(Sequence{ (n - 1) div i }) do ( if item /= 1 then ( execute ((item) : result) ) else skip) ) else skip) ; for i : Integer.subrange(1, ("" + (((n)->sqrt())))->toInteger() + 1-1) do ( if n mod i = 0 then ( for item : Sequence{i}->union(Sequence{ n div i }) do ( if item /= 1 then ( var N : int := n ; while N mod item = 0 do ( N := N div item) ; if N = 1 then ( execute ((item) : result) ) else (if N mod item = 1 then ( execute ((item) : result) ) else skip) ) else skip) ) else skip) ; execute ((result)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pairs_count(arr,n,sum): ans=0 arr=sorted(arr) i,j=0,n-1 while(isum): j-=1 else : x=arr[i] xx=i while(i=i and arr[j]==y): j-=1 if(x==y): temp=i-xx+yy-j-1 ans+=(temp*(temp+1))//2 else : ans+=(i-xx)*(yy-j) return ans arr=[1,5,7,5,-1] n=len(arr) sum=6 print(pairs_count(arr,n,sum)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{5}->union(Sequence{7}->union(Sequence{5}->union(Sequence{ -1 })))) ; n := (arr)->size() ; sum := 6 ; execute (pairs_count(arr, n, sum))->display(); operation pairs_count(arr : OclAny, n : OclAny, sum : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; arr := arr->sort() ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,n - 1} ; while ((i->compareTo(j)) < 0) do ( if ((arr[i+1] + arr[j+1]->compareTo(sum)) < 0) then ( i := i + 1 ) else (if ((arr[i+1] + arr[j+1]->compareTo(sum)) > 0) then ( j := j - 1 ) else ( var x : OclAny := arr[i+1] ; var xx : OclAny := i ; while ((i->compareTo(j)) < 0 & arr[i+1] = x) do ( i := i + 1) ; var y : OclAny := arr[j+1] ; var yy : OclAny := j ; while ((j->compareTo(i)) >= 0 & arr[j+1] = y) do ( j := j - 1) ; if (x = y) then ( var temp : double := i - xx + yy - j - 1 ; ans := ans + (temp * (temp + 1)) div 2 ) else ( ans := ans + (i - xx) * (yy - j) ) ) ) ) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math n=int(sys.stdin.readline()) for i in range(n): n1=int(sys.stdin.readline()) n2=int(sys.stdin.readline()) if n1+n2<100000000000000000000000000000000000000000000000000000000000000000000000000000000 : print(n1+n2) else : print("overflow") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var n1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n2 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n1 + n2 < 100000000000000000000000000000000000000000000000000000000000000000000000000000000 then ( execute (n1 + n2)->display() ) else ( execute ("overflow")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Add(numa,numb): longer=(numa if len(numa)>=len(numb)else numb) shorter=(numa if len(numa)=10 : result=str(ans % 10)+result carry=1 else : result=str(ans)+result carry=0 for l in range(-len(shorter)-1,-len(longer)-1,-1): ans=int(longer[l])+carry if ans>=10 : result=str(ans % 10)+result carry=1 else : result=str(ans)+result carry=0 return(result if carry==0 else '1'+result) N=eval(input()) for _ in range(N): a=input() b=input() ans=Add(a,b) print('overflow' if len(ans)>80 else ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := (OclFile["System.in"]).readLine() ; for _anon : Integer.subrange(0, N-1) do ( var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; ans := Add(a, b) ; execute (if (ans)->size() > 80 then 'overflow' else ans endif)->display()); operation Add(numa : OclAny, numb : OclAny) : OclAny pre: true post: true activity: var longer : OclAny := (if ((numa)->size()->compareTo((numb)->size())) >= 0 then numa else numb endif) ; var shorter : OclAny := (if ((numa)->size()->compareTo((numb)->size())) < 0 then numa else numb endif) ; var carry : int := 0 ; var result : String := '' ; for s : Integer.subrange(-(shorter)->size() - 1 + 1, -1)->reverse() do ( var ans : int := ("" + ((longer[s+1])))->toInteger() + ("" + ((shorter[s+1])))->toInteger() + carry ; if ans >= 10 then ( result := ("" + ((ans mod 10))) + result ; carry := 1 ) else ( result := ("" + ((ans))) + result ; carry := 0 )) ; for l : Integer.subrange(-(longer)->size() - 1 + 1, -(shorter)->size() - 1)->reverse() do ( ans := ("" + ((longer[l+1])))->toInteger() + carry ; if ans >= 10 then ( result := ("" + ((ans mod 10))) + result ; carry := 1 ) else ( result := ("" + ((ans))) + result ; carry := 0 )) ; return (if carry = 0 then result else '1' + result endif); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def leftRotate(arr,d,n): for i in range(d): leftRotatebyOne(arr,n) def leftRotatebyOne(arr,n): temp=arr[0] for i in range(n-1): arr[i]=arr[i+1] arr[n-1]=temp def printArray(arr,size): for i in range(size): print("% d" % arr[i],end=" ") arr=[1,2,3,4,5,6,7] leftRotate(arr,2,7) printArray(arr,7) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 7 })))))) ; leftRotate(arr, 2, 7) ; printArray(arr, 7); operation leftRotate(arr : OclAny, d : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, d-1) do ( leftRotatebyOne(arr, n)); operation leftRotatebyOne(arr : OclAny, n : OclAny) pre: true post: true activity: var temp : OclAny := arr->first() ; for i : Integer.subrange(0, n - 1-1) do ( arr[i+1] := arr[i + 1+1]) ; arr[n - 1+1] := temp; operation printArray(arr : OclAny, size : OclAny) pre: true post: true activity: for i : Integer.subrange(0, size-1) do ( execute (StringLib.format("% d",arr[i+1]))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import re def line(): return sys.stdin.readline().strip() N=input() while True : try : a=int(line()) b=int(line()) if a+b>=10**80 : print("overflow") else : print(a+b) except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var N : String := (OclFile["System.in"]).readLine() ; while true do ( try ( var a : int := ("" + ((line())))->toInteger() ; var b : int := ("" + ((line())))->toInteger() ; if (a + b->compareTo((10)->pow(80))) >= 0 then ( execute ("overflow")->display() ) else ( execute (a + b)->display() )) catch (_e : OclException) do ( break) ); operation line() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- max=10**80 for i in range(int(input())): total=int(input())+int(input()) print(total if totalpow(80) ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var total : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() + ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (if (total->compareTo(max)) < 0 then total else "overflow" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def gcd(a,b): while(b!=0): t=b b=a % b a=t return a def findMinDiff(a,b,x,y): g=gcd(a,b) diff=abs(x-y)% g return min(diff,g-diff) a,b,x,y=20,52,5,7 print(findMinDiff(a,b,x,y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; Sequence{a,b,x,y} := Sequence{20,52,5,7} ; execute (findMinDiff(a, b, x, y))->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: while (b /= 0) do ( var t : OclAny := b ; b := a mod b ; a := t) ; return a; operation findMinDiff(a : OclAny, b : OclAny, x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var g : OclAny := gcd(a, b) ; var diff : int := (x - y)->abs() mod g ; return Set{diff, g - diff}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) list=[] for n in range(0,N): tmp=[] for _ in range(0,2): tmp.append(int(input())) list.append(tmp) for a,b in list : c=a+b if c>=10**80 : print('overflow') else : print(str(c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var OclType["Sequence"] : Sequence := Sequence{} ; for n : Integer.subrange(0, N-1) do ( var tmp : Sequence := Sequence{} ; for _anon : Integer.subrange(0, 2-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : tmp)) ; execute ((tmp) : OclType["Sequence"])) ; for _tuple : OclType["Sequence"] do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); var c : OclAny := a + b ; if (c->compareTo((10)->pow(80))) >= 0 then ( execute ('overflow')->display() ) else ( execute (("" + ((c))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def FindAllElements(n,k): sum=k A=[1 for i in range(k)] i=k-1 while(i>=0): while(sum+A[i]<=n): sum+=A[i] A[i]*=2 i-=1 if(sum!=n): print("Impossible") else : for i in range(0,k,1): print(A[i],end=' ') if __name__=='__main__' : n=12 k=6 FindAllElements(n,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 12 ; k := 6 ; FindAllElements(n, k) ) else skip; operation FindAllElements(n : OclAny, k : OclAny) pre: true post: true activity: var sum : OclAny := k ; var A : Sequence := Integer.subrange(0, k-1)->select(i | true)->collect(i | (1)) ; var i : double := k - 1 ; while (i >= 0) do ( while ((sum + A[i+1]->compareTo(n)) <= 0) do ( sum := sum + A[i+1] ; A[i+1] := A[i+1] * 2) ; i := i - 1) ; if (sum /= n) then ( execute ("Impossible")->display() ) else ( for i : Integer.subrange(0, k-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( execute (A[i+1])->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() l=list(map(int,input().split())) n=int(input()) for i in range(n): q=list(map(int,input().split())) li=l[q[1]: q[2]] if q[0]==0 : print(min(li)) else : print(max(li)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var q : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var li : OclAny := l.subrange(q[1+1]+1, q[2+1]) ; if q->first() = 0 then ( execute ((li)->min())->display() ) else ( execute ((li)->max())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.stdin.readline() a=list(map(int,sys.stdin.readline().split())) f=[min,max] for _ in range(int(sys.stdin.readline())): c,b,e=map(int,sys.stdin.readline().split()) print(f[c](a[b : e])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; (expr (atom (name sys)) (trailer . (name stdin)) (trailer . (name readline) (arguments ( )))) ; var a : Sequence := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var f : Sequence := Sequence{min}->union(Sequence{ max }) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var c : OclAny := null; var b : OclAny := null; var e : OclAny := null; Sequence{c,b,e} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (f[c+1](a.subrange(b+1, e)))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): param=input() param=input().split(" ") seq=[int(a)for a in param] n=int(input()) for _ in range(n): param=input().split(" ") if param[0]=="0" : print(min(seq[int(param[1]): int(param[2])])) elif param[0]=="1" : print(max(seq[int(param[1]): int(param[2])])) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var param : String := (OclFile["System.in"]).readLine() ; param := input().split(" ") ; var seq : Sequence := param->characters()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( param := input().split(" ") ; if param->first() = "0" then ( execute ((seq.subrange(("" + ((param[1+1])))->toInteger()+1, ("" + ((param[2+1])))->toInteger()))->min())->display() ) else (if param->first() = "1" then ( execute ((seq.subrange(("" + ((param[1+1])))->toInteger()+1, ("" + ((param[2+1])))->toInteger()))->max())->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin n=int(stdin.readline()) l=list(map(int,stdin.readline().split())) num=int(stdin.readline()) for i in range(num): inp=list(stdin.readline().split()) start=int(inp[1]) end=int(inp[2]) if inp[0]=='0' : print(min(l[start : end])) else : print(max(l[start : end])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + ((stdin.readLine())))->toInteger() ; var l : Sequence := ((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var num : int := ("" + ((stdin.readLine())))->toInteger() ; for i : Integer.subrange(0, num-1) do ( var inp : Sequence := (stdin.readLine().split()) ; var start : int := ("" + ((inp[1+1])))->toInteger() ; var end : int := ("" + ((inp[2+1])))->toInteger() ; if inp->first() = '0' then ( execute ((l.subrange(start+1, end))->min())->display() ) else ( execute ((l.subrange(start+1, end))->max())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) q=int(input()) for i in range(q): tmp=list(map(int,input().split())) if tmp[0]==0 : ans=float('inf') for j in range(tmp[1],tmp[2]): ans=min(ans,a[j]) print(ans) else : ans=float('inf')*(-1) for j in range(tmp[1],tmp[2]): ans=max(ans,a[j]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( var tmp : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if tmp->first() = 0 then ( var ans : double := ("" + (('inf')))->toReal() ; for j : Integer.subrange(tmp[1+1], tmp[2+1]-1) do ( ans := Set{ans, a[j+1]}->min()) ; execute (ans)->display() ) else ( ans := ("" + (('inf')))->toReal() * (-1) ; for j : Integer.subrange(tmp[1+1], tmp[2+1]-1) do ( ans := Set{ans, a[j+1]}->max()) ; execute (ans)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import pow def printf(n,k): print(int(k),end=" ") for i in range(2,n+1,1): x=pow(k,i)-pow(k,i-1) print(int(x),end=" ") if __name__=='__main__' : N=3 K=4 printf(N,K) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var N : int := 3 ; var K : int := 4 ; printf(N, K) ) else skip; operation printf(n : OclAny, k : OclAny) pre: true post: true activity: execute (("" + ((k)))->toInteger())->display() ; for i : Integer.subrange(2, n + 1-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( var x : double := (k)->pow(i) - (k)->pow(i - 1) ; execute (("" + ((x)))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solver(nums): st=[float('inf')] res=nums[0]^ nums[1] for i,num in enumerate(nums): while num>st[-1]: cur=st.pop() if len(st)>1 : res=max([res,cur ^ st[-1],cur ^ num]) else : res=max(res,cur ^ num) break st.append(num) while len(st)>2 : cur=st.pop() res=max(res,cur ^ st[-1]) return res if __name__=='__main__' : n=int(sys.stdin.readline().strip('/n').split()[0]) nums=sys.stdin.readline().strip('/n').split() nums=list(map(int,nums)) print(solver(nums)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var n : int := ("" + ((sys.stdin.readLine()->trim().split()->first())))->toInteger() ; nums := sys.stdin.readLine()->trim().split() ; nums := ((nums)->collect( _x | (OclType["int"])->apply(_x) )) ; execute (solver(nums))->display() ) else skip; operation solver(nums : OclAny) : OclAny pre: true post: true activity: var st : Sequence := Sequence{ ("" + (('inf')))->toReal() } ; var res : int := MathLib.bitwiseXor(nums->first(), nums[1+1]) ; for _tuple : Integer.subrange(1, (nums)->size())->collect( _indx | Sequence{_indx-1, (nums)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var num : OclAny := _tuple->at(_indx); while (num->compareTo(st->last())) > 0 do ( var cur : OclAny := st->last() ; st := st->front() ; if (st)->size() > 1 then ( res := (Sequence{res}->union(Sequence{MathLib.bitwiseXor(cur, st->last())}->union(Sequence{ MathLib.bitwiseXor(cur, num) })))->max() ) else ( res := Set{res, MathLib.bitwiseXor(cur, num)}->max() ; break )) ; execute ((num) : st)) ; while (st)->size() > 2 do ( cur := st->last() ; st := st->front() ; res := Set{res, MathLib.bitwiseXor(cur, st->last())}->max()) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def splitString(str): alpha="" num="" special="" for i in range(len(str)): if(str[i].isdigit()): num=num+str[i] elif((str[i]>='A' and str[i]<='Z')or(str[i]>='a' and str[i]<='z')): alpha+=str[i] else : special+=str[i] print(alpha) print(num) print(special) if __name__=="__main__" : str="geeks01$$for02geeks03!@!!" splitString(str) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( OclType["String"] := "geeks01$$for02geeks03!@!!" ; splitString(OclType["String"]) ) else skip; operation splitString(OclType["String"] : OclAny) pre: true post: true activity: var alpha : String := "" ; var num : String := "" ; var special : String := "" ; for i : Integer.subrange(0, (OclType["String"])->size()-1) do ( if (OclType["String"][i+1]->matches("[0-9]*")) then ( num := num + ("" + ([i+1])) ) else (if ((("" + ([i+1])) >= 'A' & ("" + ([i+1])) <= 'Z') or (("" + ([i+1])) >= 'a' & ("" + ([i+1])) <= 'z')) then ( alpha := alpha + ("" + ([i+1])) ) else ( special := special + ("" + ([i+1])) ) ) ) ; execute (alpha)->display() ; execute (num)->display() ; execute (special)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): x,y,w,h=map(int,input().split()) n=int(input()) ans=0 for _ in range(n): cx,cy=map(int,input().split()) if x<=cx<=x+w and y<=cy<=y+h : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var x : OclAny := null; var y : OclAny := null; var w : OclAny := null; var h : OclAny := null; Sequence{x,y,w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var cx : OclAny := null; var cy : OclAny := null; Sequence{cx,cy} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (x->compareTo(cx)) <= 0 & (cx <= x + w) & (y->compareTo(cy)) <= 0 & (cy <= y + h) then ( ans := ans + 1 ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib,sys def compute(): sys.setrecursionlimit(3000) ans=max(range(1,1000000),key=collatz_chain_length) return str(ans) @ eulerlib.memoize def collatz_chain_length(x): if x==1 : return 1 if x % 2==0 : y=x//2 else : y=x*3+1 return collatz_chain_length(y)+1 if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; (compound_stmt (decorator @ (dotted_name (dotted_name (name eulerlib)) . (name memoize))) (funcdef def (name collatz_chain_length) ( (typedargslist (def_parameters (def_parameter (named_parameter (name x))))) ) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name x)))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name x))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name y)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name x))) // (expr (atom (number (integer 2))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name y)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (name x))) * (expr (atom (number (integer 3))))) + (expr (atom (number (integer 1)))))))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (expr (atom (name collatz_chain_length)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))) + (expr (atom (number (integer 1))))))))))))))) ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: sys.setrecursionlimit(3000) ; var ans : OclAny := Set{Integer.subrange(1, 1000000-1), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name collatz_chain_length)))))))}->max() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dupLastIndex(arr,n): if(arr==None or n<=0): return for i in range(n-1,0,-1): if(arr[i]==arr[i-1]): print("Last index:",i,"\nLast","duplicate item:",arr[i]) return print("no duplicate found") arr=[1,5,5,6,6,7,9] n=len(arr) dupLastIndex(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{5}->union(Sequence{5}->union(Sequence{6}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 9 })))))) ; n := (arr)->size() ; dupLastIndex(arr, n); operation dupLastIndex(arr : OclAny, n : OclAny) pre: true post: true activity: if (arr = null or n <= 0) then ( return ) else skip ; for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( if (arr[i+1] = arr[i - 1+1]) then ( execute ("Last index:")->display() ; return ) else skip) ; execute ("no duplicate found")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(sum([int(input())for i in range(n)])//n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())))->sum() div n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def main(args): n=int(input()) total=0 for _ in range(n): total+=int(input()) print('{}'.format(total//n)) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation main(args : OclAny) pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var total : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( total := total + ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; execute (StringLib.interpolateStrings('{}', Sequence{total div n}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) v_list=[] for i in range(n): v=int(input()) v_list.append(v) print(int(sum(v_list)/n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var v_list : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var v : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((v) : v_list)) ; execute (("" + (((v_list)->sum() / n)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from statistics import mean inputCount=int(input()) prices=[int(input())for lp in range(inputCount)] average=mean(prices) print(int(average)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var inputCount : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var prices : Sequence := Integer.subrange(0, inputCount-1)->select(lp | true)->collect(lp | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var average : OclAny := mean(prices) ; execute (("" + ((average)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sum=0 n=int(input()) for i in range(n): sum+=int(input()) print(sum//n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sum : int := 0 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( sum := sum + ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; execute (sum div n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def findTheDifference(self,s,t): res=ord(t[-1]) for i in range(len(s)): res+=ord(t[i]) res-=ord(s[i]) return chr(res) ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation findTheDifference(s : OclAny,t : OclAny) : OclAny pre: true post: true activity: var res : int := (t->last())->char2byte() ; for i : Integer.subrange(0, (s)->size()-1) do ( res := res + (t[i+1])->char2byte() ; res := res - (s[i+1])->char2byte()) ; return (res)->byte2char(); } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def expressDigit(arr,n): min=9 index=0 temp=0 temp=arr[0] for i in range(1,10): if(arr[i]union(Sequence{2}->union(Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{1}->union(Sequence{3}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))))))))) ; var N : int := 10 ; expressDigit(arr, N); operation expressDigit(arr : OclAny, n : OclAny) pre: true post: true activity: var min : int := 9 ; var index : int := 0 ; var temp : int := 0 ; temp := arr->first() ; for i : Integer.subrange(1, 10-1) do ( if ((arr[i+1]->compareTo(min)) < 0) then ( min := arr[i+1] ; index := i ) else skip) ; if ((temp->compareTo(min)) < 0) then ( execute (1)->display() ; for i : Integer.subrange(1, temp + 1-1) do ( execute (0)->display()) ) else ( for i : Integer.subrange(0, min-1) do ( execute (index)->display()) ; execute (index)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(input()) a=list(map(int,input().split())) b=[a[0]] m=0 for i in range(1,n): if len(b)>0 : m=max(m,b[-1]^ a[i]) while len(b)>0 and a[i]>b[-1]: m=max(m,b[-1]^ a[i]) b.pop() if len(b)>0 : m=max(m,b[-1]^ a[i]) b.append(a[i]) print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := Sequence{ a->first() } ; var m : int := 0 ; for i : Integer.subrange(1, n-1) do ( if (b)->size() > 0 then ( m := Set{m, MathLib.bitwiseXor(b->last(), a[i+1])}->max() ) else skip ; while (b)->size() > 0 & (a[i+1]->compareTo(b->last())) > 0 do ( m := Set{m, MathLib.bitwiseXor(b->last(), a[i+1])}->max() ; b := b->front()) ; if (b)->size() > 0 then ( m := Set{m, MathLib.bitwiseXor(b->last(), a[i+1])}->max() ) else skip ; execute ((a[i+1]) : b)) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): X,Y,W,H=map(int,input().split()) x1,y1,x2,y2=X,Y,X+W,Y+H cnt=0 for _ in range(int(input())): x,y=map(int,input().split()) if(x>=x1 and x<=x2)and(y>=y1 and y<=y2): cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var X : OclAny := null; var Y : OclAny := null; var W : OclAny := null; var H : OclAny := null; Sequence{X,Y,W,H} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := Sequence{X,Y,X + W,Y + H} ; var cnt : int := 0 ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if ((x->compareTo(x1)) >= 0 & (x->compareTo(x2)) <= 0) & ((y->compareTo(y1)) >= 0 & (y->compareTo(y2)) <= 0) then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt ; N=100005 ; isprime=[True]*N ; can=[False]*N ; def SieveOfEratosthenes(): for p in range(2,int(sqrt(N))+1): if(isprime[p]==True): for i in range(p*p,N,p): isprime[i]=False ; primes=[]; for i in range(2,N): if(isprime[i]): primes.append(i); return primes ; def Prime_Numbers(n): primes=SieveOfEratosthenes(); for i in range(len(primes)-1): if(primes[i]+primes[i+1]+1display(); ) else skip; operation SieveOfEratosthenes() pre: true post: true activity: for p : Integer.subrange(2, ("" + ((sqrt(N))))->toInteger() + 1-1) do ( if (isprime[p+1] = true) then ( for i : Integer.subrange(p * p, N-1)->select( $x | ($x - p * p) mod p = 0 ) do ( isprime[i+1] := false;) ) else skip) ; var primes : Sequence := Sequence{}; ; for i : Integer.subrange(2, N-1) do ( if (isprime[i+1]) then ( execute ((i) : primes); ) else skip) ; return primes;; operation Prime_Numbers(n : OclAny) pre: true post: true activity: primes := SieveOfEratosthenes(); ; for i : Integer.subrange(0, (primes)->size() - 1-1) do ( if ((primes[i+1] + primes[i + 1+1] + 1->compareTo(N)) < 0) then ( can[primes[i+1] + primes[i + 1+1] + 1+1] := true; ) else skip) ; var ans : int := 0; ; for i : Integer.subrange(2, n + 1-1) do ( if (can[i+1] & isprime[i+1]) then ( ans := ans + 1; ) else skip) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: n,m=map(int,s.split()) a=['W'+'B'*(m-1)]+['B'*m]*(n-1) print(*a,sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{ 'W' + StringLib.nCopies('B', (m - 1)) }->union(MatrixLib.elementwiseMult(Sequence{ StringLib.nCopies('B', m) }, (n - 1))) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for i in range(int(input())): n,m=map(int,input().split()) print('B'+'W'*(m-1)) for i in range(n-1): print('B'*m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ('B' + StringLib.nCopies('W', (m - 1)))->display() ; for i : Integer.subrange(0, n - 1-1) do ( execute (StringLib.nCopies('B', m))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for i in range(int(input())): n,m=map(int,input().split()) print('W'+'B'*(m-1)) for i in range(n-1): print('B'*m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ('W' + StringLib.nCopies('B', (m - 1)))->display() ; for i : Integer.subrange(0, n - 1-1) do ( execute (StringLib.nCopies('B', m))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): a,b=map(int,input().split()) l=[] for i in range(a): for j in range(b): if(i==0 and j==0): print("W",end="") else : print("B",end="") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, a-1) do ( for j : Integer.subrange(0, b-1) do ( if (i = 0 & j = 0) then ( execute ("W")->display() ) else ( execute ("B")->display() )) ; execute (->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,m=list(map(int,input().split())) print("B"+"W"*(m-1)) for i in range(1,n): print("B"*m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ("B" + StringLib.nCopies("W", (m - 1)))->display() ; for i : Integer.subrange(1, n-1) do ( execute (StringLib.nCopies("B", m))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fact(n): if(n==0): return 1 return n*fact(n-1) def div(x): ans=0 ; for i in range(1,x+1): if(x % i==0): ans+=i return ans def sumFactDiv(n): return div(fact(n)) n=4 print(sumFactDiv(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 4 ; execute (sumFactDiv(n))->display(); operation fact(n : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return 1 ) else skip ; return n * fact(n - 1); operation div(x : OclAny) : OclAny pre: true post: true activity: var ans : int := 0; ; for i : Integer.subrange(1, x + 1-1) do ( if (x mod i = 0) then ( ans := ans + i ) else skip) ; return ans; operation sumFactDiv(n : OclAny) : OclAny pre: true post: true activity: return div(fact(n)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def longestSubarry(arr,n): res=0 for i in range(n): curr_count=0 while(i=0): curr_count+=1 i+=1 res=max(res,curr_count) return res arr=[1,0,4,0,1,-1,-1,0,0,1,0] n=len(arr) print(longestSubarry(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{0}->union(Sequence{4}->union(Sequence{0}->union(Sequence{1}->union(Sequence{-1}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 0 })))))))))) ; n := (arr)->size() ; execute (longestSubarry(arr, n))->display(); operation longestSubarry(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( var curr_count : int := 0 ; while ((i->compareTo(n)) < 0 & arr[i+1] >= 0) do ( curr_count := curr_count + 1 ; i := i + 1) ; res := Set{res, curr_count}->max()) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def e(x,y): A[y][x]='0' for dx,dy in[[-3,0],[-2,0],[-1,0],[1,0],[2,0],[3,0],[0,-3],[0,-2],[0,-1],[0,1],[0,2],[0,3]]: if 0<=x+dx<8 and 0<=y+dy<8 and A[y+dy][x+dx]=='1' : e(x+dx,y+dy) for i in range(int(input())): print(f'Data{i+1}:') input() A=[list(input())for _ in[0]*8] e(int(input())-1,int(input())-1) for r in A : print(''.join(r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (StringLib.formattedString('Data{i+1}:'))->display() ; input() ; var A : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 8)->select(_anon | true)->collect(_anon | (((OclFile["System.in"]).readLine())->characters())) ; e(("" + (((OclFile["System.in"]).readLine())))->toInteger() - 1, ("" + (((OclFile["System.in"]).readLine())))->toInteger() - 1) ; for r : A do ( execute (StringLib.sumStringsWithSeparator((r), ''))->display())); operation e(x : OclAny, y : OclAny) pre: true post: true activity: A[y+1][x+1] := '0' ; for _tuple : Sequence{Sequence{-3}->union(Sequence{ 0 })}->union(Sequence{Sequence{-2}->union(Sequence{ 0 })}->union(Sequence{Sequence{-1}->union(Sequence{ 0 })}->union(Sequence{Sequence{1}->union(Sequence{ 0 })}->union(Sequence{Sequence{2}->union(Sequence{ 0 })}->union(Sequence{Sequence{3}->union(Sequence{ 0 })}->union(Sequence{Sequence{0}->union(Sequence{ -3 })}->union(Sequence{Sequence{0}->union(Sequence{ -2 })}->union(Sequence{Sequence{0}->union(Sequence{ -1 })}->union(Sequence{Sequence{0}->union(Sequence{ 1 })}->union(Sequence{Sequence{0}->union(Sequence{ 2 })}->union(Sequence{ Sequence{0}->union(Sequence{ 3 }) }))))))))))) do (var _indx : int := 1; var dx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dy : OclAny := _tuple->at(_indx); if 0 <= x + dx & (x + dx < 8) & 0 <= y + dy & (y + dy < 8) & A[y + dy+1][x + dx+1] = '1' then ( e(x + dx, y + dy) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_Y=8 MAX_X=8 def main(): N=int(raw_input()) for i,j in enumerate(range(N)): raw_input() data=[] for j in range(MAX_Y): input_list=map(int,raw_input()) data.append(input_list) bomb_X=int(raw_input()) bomb_Y=int(raw_input()) bomb_town=explosion(data,((bomb_X-1,bomb_Y-1),)) print("Data "+str(i+1)+":") printBomb(bomb_town) def printBomb(bomb): for x in bomb : print(reduce(lambda x,y : x+y,(map(str,x)))) def isIn(x,y): return 0<=xtoInteger() ; for _tuple : Integer.subrange(1, (Integer.subrange(0, N-1))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(0, N-1))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); raw_input() ; var data : Sequence := Sequence{} ; for j : Integer.subrange(0, MAX_Y-1) do ( var input_list : Sequence := (raw_input())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((input_list) : data)) ; var bomb_X : int := ("" + ((raw_input())))->toInteger() ; var bomb_Y : int := ("" + ((raw_input())))->toInteger() ; var bomb_town : OclAny := explosion(data, Sequence{(testlist_comp (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name bomb_X))) - (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (expr (atom (name bomb_Y))) - (expr (atom (number (integer 1))))))))) )))))) ,)}) ; execute ("Data " + ("" + ((i + 1))) + ":")->display() ; printBomb(bomb_town)); operation printBomb(bomb : OclAny) pre: true post: true activity: for x : bomb do ( execute (reduce(lambda x : OclAny, y : OclAny in (x + y), ((x)->collect( _x | (OclType["String"])->apply(_x) ))))->display()); operation isIn(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return 0 <= x & (x < MAX_X) & 0 <= y & (y < MAX_Y); operation explosion(data : OclAny, bomb : OclAny) : OclAny pre: true post: true activity: for b : bomb do ( if data[b[1+1]+1][b->first()+1] = 1 then ( var new_bomb : OclAny := bom(data, b) ; var burned_data : OclAny := burned(data, b) ; data := explosion(burned_data, new_bomb) ) else skip) ; return data; operation burned(data : OclAny, b : OclAny) : OclAny pre: true post: true activity: data[b[1+1]+1][b->first()+1] := 0 ; return data; operation bom(data : OclAny, b : OclAny) : OclAny pre: true post: true activity: var bom_area : Sequence := Sequence{Sequence{-3, 0}}->union(Sequence{Sequence{-2, 0}}->union(Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{2, 0}}->union(Sequence{Sequence{3, 0}}->union(Sequence{Sequence{0, -3}}->union(Sequence{Sequence{0, -2}}->union(Sequence{Sequence{0, -1}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{0, 2}}->union(Sequence{ Sequence{0, 3} }))))))))))) ; new_bomb := Sequence{} ; for x : bom_area do ( bomb := (Integer.subrange(1, x->size())->collect( _indx | Sequence{x->at(_indx), b->at(_indx)} )->select(x | true)->collect(x | ((x)->sum()))) ; if isIn((argument * (test (logical_test (comparison (expr (atom (name bomb)))))))) then ( execute ((bomb) : new_bomb) ) else skip) ; return new_bomb; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline INF=1<<60 if __name__=='__main__' : n,t=map(int,readline().split()) ans=0 value=INF for i in range(1,n+1): s,d=map(int,readline().split()) a=max(0,(t-s+d-1)//d) tmp=s+d*a if tmppow(60)) ; if __name__ = '__main__' then ( var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; var value : int := INF ; for i : Integer.subrange(1, n + 1-1) do ( var s : OclAny := null; var d : OclAny := null; Sequence{s,d} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := Set{0, (t - s + d - 1) div d}->max() ; var tmp : OclAny := s + d * a ; if (tmp->compareTo(value)) < 0 then ( value := tmp ; ans := i ) else skip) ; execute (ans)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt MAX=100000 prime=[True]*MAX def sieve(): for p in range(2,int(sqrt(MAX))+1): if prime[p]==True : for i in range(p*2,MAX,p): prime[i]=False def printPrimeQuad(n): for i in range(n-7): if(prime[i]and prime[i+2]and prime[i+6]and prime[i+8]): print(i,i+2,i+6,i+8) if __name__=="__main__" : sieve() n=20 printPrimeQuad(20) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MAX : int := 100000 ; var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, MAX) ; skip ; skip ; if __name__ = "__main__" then ( sieve() ; n := 20 ; printPrimeQuad(20) ) else skip; operation sieve() pre: true post: true activity: for p : Integer.subrange(2, ("" + ((sqrt(MAX))))->toInteger() + 1-1) do ( if prime[p+1] = true then ( for i : Integer.subrange(p * 2, MAX-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip); operation printPrimeQuad(n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n - 7-1) do ( if (prime[i+1] & prime[i + 2+1] & prime[i + 6+1] & prime[i + 8+1]) then ( execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for _ in range(n): x1,y1,w,h=map(int,input().split()) x2=x1+w y2=y1+h m=int(input()) cnt=0 for _ in range(m): x,y=map(int,input().split()) if x1<=x<=x2 and y1<=y<=y2 : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; var w : OclAny := null; var h : OclAny := null; Sequence{x1,y1,w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x2 : OclAny := x1 + w ; var y2 : OclAny := y1 + h ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cnt : int := 0 ; for _anon : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (x1->compareTo(x)) <= 0 & (x <= x2) & (y1->compareTo(y)) <= 0 & (y <= y2) then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- NA=-1 def moveToEnd(mPlusN,size): i=0 j=size-1 for i in range(size-1,-1,-1): if(mPlusN[i]!=NA): mPlusN[j]=mPlusN[i] j-=1 def merge(mPlusN,N,m,n): i=n j=0 k=0 while(k<(m+n)): if((i<(m+n)and mPlusN[i]<=N[j])or(j==n)): mPlusN[k]=mPlusN[i] k+=1 i+=1 else : mPlusN[k]=N[j] k+=1 j+=1 def printArray(arr,size): for i in range(size): print(arr[i],"",end="") print() mPlusN=[2,8,NA,NA,NA,13,NA,15,20] N=[5,7,9,25] n=len(N) m=len(mPlusN)-n moveToEnd(mPlusN,m+n) merge(mPlusN,N,m,n) printArray(mPlusN,m+n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var NA : int := -1 ; skip ; skip ; skip ; mPlusN := Sequence{2}->union(Sequence{8}->union(Sequence{NA}->union(Sequence{NA}->union(Sequence{NA}->union(Sequence{13}->union(Sequence{NA}->union(Sequence{15}->union(Sequence{ 20 })))))))) ; N := Sequence{5}->union(Sequence{7}->union(Sequence{9}->union(Sequence{ 25 }))) ; n := (N)->size() ; m := (mPlusN)->size() - n ; moveToEnd(mPlusN, m + n) ; merge(mPlusN, N, m, n) ; printArray(mPlusN, m + n); operation moveToEnd(mPlusN : OclAny, size : OclAny) pre: true post: true activity: var i : int := 0 ; var j : double := size - 1 ; for i : Integer.subrange(-1 + 1, size - 1)->reverse() do ( if (mPlusN[i+1] /= NA) then ( mPlusN[j+1] := mPlusN[i+1] ; j := j - 1 ) else skip); operation merge(mPlusN : OclAny, N : OclAny, m : OclAny, n : OclAny) pre: true post: true activity: i := n ; j := 0 ; var k : int := 0 ; while ((k->compareTo((m + n))) < 0) do ( if (((i->compareTo((m + n))) < 0 & (mPlusN[i+1]->compareTo(N[j+1])) <= 0) or (j = n)) then ( mPlusN[k+1] := mPlusN[i+1] ; k := k + 1 ; i := i + 1 ) else ( mPlusN[k+1] := N[j+1] ; k := k + 1 ; j := j + 1 )); operation printArray(arr : OclAny, size : OclAny) pre: true post: true activity: for i : Integer.subrange(0, size-1) do ( execute (arr[i+1])->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def xor(a,b): return a ^ b def solve(l): ans=xor(l[0],l[1]) st=[l[0],l[1]] for i in range(2,n): while len(st)>0 and st[-1]=2 : ans=max(ans,xor(st[-1],st[-2])) return ans n=int(input()) l=input() l=[int(i)for i in l.split()] ans=solve(l) l.reverse() ans=max(ans,solve(l)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; l := (OclFile["System.in"]).readLine() ; l := l.split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; ans := solve(l) ; l := l->reverse() ; ans := Set{ans, solve(l)}->max() ; execute (ans)->display(); operation xor(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return MathLib.bitwiseXor(a, b); operation solve(l : OclAny) : OclAny pre: true post: true activity: var ans : OclAny := xor(l->first(), l[1+1]) ; var st : Sequence := Sequence{l->first()}->union(Sequence{ l[1+1] }) ; for i : Integer.subrange(2, n-1) do ( while (st)->size() > 0 & (st->last()->compareTo(l[i+1])) < 0 do ( st := st->front()) ; execute ((l[i+1]) : st) ; if (st)->size() >= 2 then ( ans := Set{ans, xor(st->last(), st->front()->last())}->max() ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) def f(l,m): if m==[]: return l else : m2=[] for s in m : y,x=s[0],s[1] l[y][x]='0' for i in range(y-3,y+4): if 0<=i<=7 and l[i][x]=='1' : m2.append((i,x)) for i in range(x-3,x+4): if 0<=i<=7 and l[y][i]=='1' : m2.append((y,i)) return f(l,m2) c=0 while n>0 : c+=1 input() l=[] for i in range(8): l.append([j for j in input()]) x=int(input())-1 y=int(input())-1 a=f(l,[(y,x)]) print('Data '+str(c)+':') for i in a : b='' for j in i : b+=j print(b) n-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; var c : int := 0 ; while n > 0 do ( c := c + 1 ; input() ; l := Sequence{} ; for i : Integer.subrange(0, 8-1) do ( execute (((OclFile["System.in"]).readLine()->select(j | true)->collect(j | (j))) : l)) ; var x : double := ("" + (((OclFile["System.in"]).readLine())))->toInteger() - 1 ; var y : double := ("" + (((OclFile["System.in"]).readLine())))->toInteger() - 1 ; var a : String := f(l, Sequence{ Sequence{y, x} }) ; execute ('Data ' + ("" + ((c))) + ':')->display() ; for i : a->characters() do ( var b : String := '' ; for j : i do ( b := b + j) ; execute (b)->display()) ; n := n - 1); operation f(l : OclAny, m : OclAny) : OclAny pre: true post: true activity: if m = Sequence{} then ( return l ) else ( var m2 : Sequence := Sequence{} ; for s : m do ( var y : OclAny := null; var x : OclAny := null; Sequence{y,x} := Sequence{s->first(),s[1+1]} ; l[y+1][x+1] := '0' ; for i : Integer.subrange(y - 3, y + 4-1) do ( if 0 <= i & (i <= 7) & l[i+1][x+1] = '1' then ( execute ((Sequence{i, x}) : m2) ) else skip) ; for i : Integer.subrange(x - 3, x + 4-1) do ( if 0 <= i & (i <= 7) & l[y+1][i+1] = '1' then ( execute ((Sequence{y, i}) : m2) ) else skip)) ; return f(l, m2) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys f=sys.stdin def bomb(board,x,y): if x<0 or y<0 or len(board)<=x or len(board)<=y : return if board[y][x]=='0' : return board[y]=board[y][: x]+'0'+board[y][x+1 :] for dx,dy in[[0,-3],[0,-2],[0,-1],[3,0],[2,0],[1,0],[0,3],[0,2],[0,1],[-3,0],[-2,0],[-1,0]]: bomb(board,x+dx,y+dy) n=int(f.readline()) for i in range(n): f.readline() board=[f.readline().strip()for _ in range(8)] x,y=map(int,[f.readline()for _ in range(2)]) bomb(board,x-1,y-1) print('Data{}:'.format(i+1)) for line in board : print(line) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var f : OclFile := OclFile["System.in"] ; skip ; var n : int := ("" + ((f.readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( f.readLine() ; board := Integer.subrange(0, 8-1)->select(_anon | true)->collect(_anon | (f.readLine()->trim())) ; Sequence{x,y} := (Integer.subrange(0, 2-1)->select(_anon | true)->collect(_anon | (f.readLine())))->collect( _x | (OclType["int"])->apply(_x) ) ; bomb(board, x - 1, y - 1) ; execute (StringLib.interpolateStrings('Data{}:', Sequence{i + 1}))->display() ; for line : board do ( execute (line)->display())); operation bomb(board : OclAny, x : OclAny, y : OclAny) pre: true post: true activity: if x < 0 or y < 0 or ((board)->size()->compareTo(x)) <= 0 or ((board)->size()->compareTo(y)) <= 0 then ( return ) else skip ; if board[y+1][x+1] = '0' then ( return ) else skip ; board[y+1] := board[y+1].subrange(1,x) + '0' + board[y+1].subrange(x + 1+1) ; for _tuple : Sequence{Sequence{0}->union(Sequence{ -3 })}->union(Sequence{Sequence{0}->union(Sequence{ -2 })}->union(Sequence{Sequence{0}->union(Sequence{ -1 })}->union(Sequence{Sequence{3}->union(Sequence{ 0 })}->union(Sequence{Sequence{2}->union(Sequence{ 0 })}->union(Sequence{Sequence{1}->union(Sequence{ 0 })}->union(Sequence{Sequence{0}->union(Sequence{ 3 })}->union(Sequence{Sequence{0}->union(Sequence{ 2 })}->union(Sequence{Sequence{0}->union(Sequence{ 1 })}->union(Sequence{Sequence{-3}->union(Sequence{ 0 })}->union(Sequence{Sequence{-2}->union(Sequence{ 0 })}->union(Sequence{ Sequence{-1}->union(Sequence{ 0 }) }))))))))))) do (var _indx : int := 1; var dx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dy : OclAny := _tuple->at(_indx); bomb(board, x + dx, y + dy)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import chain,repeat def solve(a,x,y): a[y][x]=0 for dx,dy in chain(zip(range(-3,4),repeat(0)),zip(repeat(0),range(-3,4))): if a[y+dy][x+dx]: solve(a,x+dx,y+dy) for i in range(1,int(input())+1): input() empty=[[0]*14]*3 a=empty+[[0,0,0]+list(map(int,input()))+[0,0,0]for _ in[0]*8]+empty x,y=int(input()),int(input()) solve(a,x+2,y+2) print("Data{}:".format(i)) for l in a[3 :-3]: print("".join(map(str,l[3 :-3]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for i : Integer.subrange(1, ("" + (((OclFile["System.in"]).readLine())))->toInteger() + 1-1) do ( input() ; var empty : Sequence := MatrixLib.elementwiseMult(Sequence{ MatrixLib.elementwiseMult(Sequence{ 0 }, 14) }, 3) ; a := empty->union(MatrixLib.elementwiseMult(Sequence{ 0 }, 8)->select(_anon | true)->collect(_anon | (Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))->union((((OclFile["System.in"]).readLine())->collect( _x | (OclType["int"])->apply(_x) )))->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))))))->union(empty) ; Sequence{x,y} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),("" + (((OclFile["System.in"]).readLine())))->toInteger()} ; solve(a, x + 2, y + 2) ; execute (StringLib.interpolateStrings("Data{}:", Sequence{i}))->display() ; for l : a.subrange(3+1, -3) do ( execute (StringLib.sumStringsWithSeparator(((l.subrange(3+1, -3))->collect( _x | (OclType["String"])->apply(_x) )), ""))->display())); operation solve(a : OclAny, x : OclAny, y : OclAny) pre: true post: true activity: a[y+1][x+1] := 0 ; for _tuple : chain(Integer.subrange(1, Integer.subrange(-3, 4-1)->size())->collect( _indx | Sequence{Integer.subrange(-3, 4-1)->at(_indx), repeat(0)->at(_indx)} ), Integer.subrange(1, repeat(0)->size())->collect( _indx | Sequence{repeat(0)->at(_indx), Integer.subrange(-3, 4-1)->at(_indx)} )) do (var _indx : int := 1; var dx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dy : OclAny := _tuple->at(_indx); if a[y + dy+1][x + dx+1] then ( solve(a, x + dx, y + dy) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def gen(N,S,W): g=S for i in range(N): yield(g//7)% 10 if g % 2==0 : g//=2 else : g=(g//2)^ W def solve(): N,S,W,Q=map(int,input().split()) if N==0 : return False bs=list(gen(N,S,W)) ans=0 if Q==2 or Q==5 : cnt=0 for i in range(N): b=bs[i] if b!=0 : cnt+=1 if b % Q==0 : ans+=cnt else : rev10=pow(10,Q-2,Q) D=defaultdict(int) D[0]=1 s=0 ; v=1 first=1 for i in range(N): b=bs[i] if first and b==0 : continue s=(s+v*b)% Q v=v*rev10 % Q ans+=D[s] if icollect( _x | (OclType["int"])->apply(_x) ) ; if N = 0 then ( return false ) else skip ; var bs : Sequence := (gen(N, S, W)) ; var ans : int := 0 ; if Q = 2 or Q = 5 then ( var cnt : int := 0 ; for i : Integer.subrange(0, N-1) do ( var b : OclAny := bs[i+1] ; if b /= 0 then ( cnt := cnt + 1 ) else skip ; if b mod Q = 0 then ( ans := ans + cnt ) else skip) ) else ( var rev10 : double := (10)->pow(Q - 2) ; var D : OclAny := defaultdict(OclType["int"]) ; D->first() := 1 ; var s : int := 0; var v : int := 1 ; var first : int := 1 ; for i : Integer.subrange(0, N-1) do ( b := bs[i+1] ; if first & b = 0 then ( continue ) else skip ; s := (s + v * b) mod Q ; v := v * rev10 mod Q ; ans := ans + D[s+1] ; if (i->compareTo(N - 1)) < 0 & bs[i + 1+1] /= 0 then ( D[s+1] := D[s+1] + 1 ) else skip ; first := 0) ) ; execute (ans)->display() ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findLargest(m,s): if(s==0): if(m==1): print("Largest number is ","0",end="") else : print("Not possible",end="") return if(s>9*m): print("Not possible",end="") return res=[0]*m for i in range(0,m): if(s>=9): res[i]=9 s=s-9 else : res[i]=s s=0 print("Largest number is ",end="") for i in range(0,m): print(res[i],end="") s=9 m=2 findLargest(m,s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := 9 ; m := 2 ; findLargest(m, s); operation findLargest(m : OclAny, s : OclAny) pre: true post: true activity: if (s = 0) then ( if (m = 1) then ( execute ("Largest number is ")->display() ) else ( execute ("Not possible")->display() ) ; return ) else skip ; if ((s->compareTo(9 * m)) > 0) then ( execute ("Not possible")->display() ; return ) else skip ; var res : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; for i : Integer.subrange(0, m-1) do ( if (s >= 9) then ( res[i+1] := 9 ; s := s - 9 ) else ( res[i+1] := s ; s := 0 )) ; execute ("Largest number is ")->display() ; for i : Integer.subrange(0, m-1) do ( execute (res[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSmallest(m,s): if(s==0): if(m==1): print("Smallest number is 0") else : print("Not possible") return if(s>9*m): print("Not possible") return res=[0 for i in range(m+1)] s-=1 for i in range(m-1,0,-1): if(s>9): res[i]=9 s-=9 else : res[i]=s s=0 res[0]=s+1 print("Smallest number is ",end="") for i in range(m): print(res[i],end="") s=9 m=2 findSmallest(m,s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := 9 ; m := 2 ; findSmallest(m, s); operation findSmallest(m : OclAny, s : OclAny) pre: true post: true activity: if (s = 0) then ( if (m = 1) then ( execute ("Smallest number is 0")->display() ) else ( execute ("Not possible")->display() ) ; return ) else skip ; if ((s->compareTo(9 * m)) > 0) then ( execute ("Not possible")->display() ; return ) else skip ; var res : Sequence := Integer.subrange(0, m + 1-1)->select(i | true)->collect(i | (0)) ; s := s - 1 ; for i : Integer.subrange(0 + 1, m - 1)->reverse() do ( if (s > 9) then ( res[i+1] := 9 ; s := s - 9 ) else ( res[i+1] := s ; s := 0 )) ; res->first() := s + 1 ; execute ("Smallest number is ")->display() ; for i : Integer.subrange(0, m-1) do ( execute (res[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printLines(n,k): for i in range(n): print(k*(6*i+1),k*(6*i+2),k*(6*i+3),k*(6*i+5)) if __name__=="__main__" : n,k=2,2 printLines(n,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{n,k} := Sequence{2,2} ; printLines(n, k) ) else skip; operation printLines(n : OclAny, k : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (k * (6 * i + 1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- index=[0]*100001 n=int(input()) a=list(map(int,input().split())) for i in range(n): index[a[i]]=i+1 m=int(input()) b=list(map(int,input().split())) vasya=petya=0 for i in range(m): vasya+=index[b[i]] petya+=(n+1-index[b[i]]) print(vasya,petya) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var index : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100001) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( index[a[i+1]+1] := i + 1) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var vasya : OclAny := 0; var petya : int := 0 ; for i : Integer.subrange(0, m-1) do ( vasya := vasya + index[b[i+1]+1] ; petya := petya + (n + 1 - index[b[i+1]+1])) ; execute (vasya)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rev(s): t='' for i in s : t=i+t return t n,mod=map(int,input().split()) t=0 res=0 for i in ' '*n : t+=1 res=(res+int(str(t)+rev(str(t))))% mod print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var mod : OclAny := null; Sequence{n,mod} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; t := 0 ; var res : int := 0 ; for i : StringLib.nCopies(' ', n) do ( t := t + 1 ; res := (res + ("" + ((("" + ((t))) + rev(("" + ((t)))))))->toInteger()) mod mod) ; execute (res)->display(); operation rev(s : OclAny) : OclAny pre: true post: true activity: var t : String := '' ; for i : s do ( t := i + t) ; return t; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- number_of_ele=int(input()) date={'counter' :-1} def fun(i): date['counter']+=1 date[f'{i}']=date['counter'] return int(i) list(map(lambda i : fun(i),input().split())) number_of_q=int(input()) arr_of_q=list(map(int,input().split())) res=[0,0] for i in range(0,number_of_q): x=date[f'{arr_of_q[i]}'] res[0]+=x+1 res[1]+=number_of_ele-x print(f'{res[0]}{res[1]}') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var number_of_ele : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var date : Map := Map{ 'counter' |-> -1 } ; skip ; OclType["Sequence"]((input().split())->collect( _x | (lambda i : OclAny in (fun(i)))->apply(_x) )) ; var number_of_q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr_of_q : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : Sequence := Sequence{0}->union(Sequence{ 0 }) ; for i : Integer.subrange(0, number_of_q-1) do ( var x : OclAny := date[StringLib.formattedString('{arr_of_q[i]}')+1] ; res->first() := res->first() + x + 1 ; res[1+1] := res[1+1] + number_of_ele - x) ; execute (StringLib.formattedString('{res[0]}{res[1]}'))->display(); operation fun(i : OclAny) : OclAny pre: true post: true activity: date->at('counter') := date->at('counter') + 1 ; date[StringLib.formattedString('{i}')+1] := date->at('counter') ; return ("" + ((i)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) arr=input().split() q=int(input()) q_arr=input().split() c1=0 c2=0 map_front={} map_rev={} for i in range(1,t+1): map_front[arr[i-1]]=i map_rev[arr[-i]]=i for i in q_arr : c1+=map_front[i] c2+=map_rev[i] print(f'{c1}{c2}') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : OclAny := input().split() ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var q_arr : OclAny := input().split() ; var c1 : int := 0 ; var c2 : int := 0 ; var map_front : OclAny := Set{} ; var map_rev : OclAny := Set{} ; for i : Integer.subrange(1, t + 1-1) do ( map_front[arr[i - 1+1]+1] := i ; map_rev[arr->reverse()->at(-(-i))+1] := i) ; for i : q_arr do ( c1 := c1 + map_front[i+1] ; c2 := c2 + map_rev[i+1]) ; execute (StringLib.formattedString('{c1}{c2}'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(v : list): ans=v[0]^ v[1] st=[] n=len(v) for i in range(n): while len(st)>0 and st[-1]=2 : ans=max(ans,st[-1]^ st[-2]) return ans if __name__=='__main__' : n=int(input()) arr=list(map(int,input().split())) ans=solve(arr) arr.reverse() print(max(ans,solve(arr))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; ans := solve(arr) ; arr := arr->reverse() ; execute (Set{ans, solve(arr)}->max())->display() ) else skip; operation solve(v : Sequence(OclAny)) : OclAny pre: true post: true activity: var ans : int := MathLib.bitwiseXor(v->first(), v[1+1]) ; var st : Sequence := Sequence{} ; var n : int := (v)->size() ; for i : Integer.subrange(0, n-1) do ( while (st)->size() > 0 & (st->last()->compareTo(v[i+1])) < 0 do ( st := st->excludingAt(-1+1)) ; execute ((v[i+1]) : st) ; if (st)->size() >= 2 then ( ans := Set{ans, MathLib.bitwiseXor(st->last(), st->front()->last())}->max() ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) d=dict() for i in range(n): d[l[i]]=i q=int(input()) l1=list(map(int,input().split())) sm1=sm2=0 for a in l1 : x=d[a] x1=x+1 x2=n-x sm1+=x1 sm2+=x2 print(sm1,sm2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( d[l[i+1]+1] := i) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sm1 : OclAny := 0; var sm2 : int := 0 ; for a : l1 do ( var x : OclAny := d[a+1] ; var x1 : OclAny := x + 1 ; var x2 : double := n - x ; sm1 := sm1 + x1 ; sm2 := sm2 + x2) ; execute (sm1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) d={a : i+1 for i,a in enumerate(map(int,input().split()))} m=int(input()) x=sum(d[i]for i in map(int,input().split())) print(x,(n+1)*m-x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Map := Integer.subrange(1, ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->size())->collect( _indx | Sequence{_indx-1, ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->at(_indx)} )->select(_tuple | true)->collect(_tuple | Map{a |-> i + 1})->unionAll() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : OclAny := ((argument (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))))))->sum() ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def division_of_string(string,k): n=len(string); has={}; cnt=0 ; i=0 ; while(isize(); ; var has : OclAny := Set{}; ; var cnt : int := 0; var i : int := 0; ; while ((i->compareTo(n)) < 0) do ( if (has)->excludes(string[i+1]) then ( cnt := cnt + 1; ; has[string[i+1]+1] := true; ) else skip ; if (cnt = k) then ( var ans : int := i; ; break; ) else skip ; i := i + 1;) ; execute (has /<: has); ; cnt := 0; ; while ((i->compareTo(n)) < 0) do ( if ((has)->excludes(string[i+1])) then ( cnt := cnt + 1; ; has[string[i+1]+1] := true; ) else skip ; if (cnt = k) then ( break; ) else skip ; i := i + 1;) ; if ((cnt->compareTo(k)) < 0) then ( execute ("Not possible")->display(); ) else ( i := 0; ; while ((i->compareTo(ans)) <= 0) do ( execute (string[i+1])->display(); ; i := i + 1;) ; execute (->display(); ; while ((i->compareTo(n)) < 0) do ( execute (string[i+1])->display(); ; i := i + 1;) ; execute (->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count_pairs(s1,s2,n1,n2): mp={s1[i]: 0 for i in range(len(s1))} for i in range(n1): mp[s1[i]]+=1 cnt=0 for i in range(n2): if(mp[s2[i]]>0): cnt+=1 mp[s2[i]]-=1 return cnt if __name__=='__main__' : s1=["abc","def"] s2=["abc","abc"] n1=len(s1) n2=len(s2) print(count_pairs(s1,s2,n1,n2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( s1 := Sequence{"abc"}->union(Sequence{ "def" }) ; s2 := Sequence{"abc"}->union(Sequence{ "abc" }) ; n1 := (s1)->size() ; n2 := (s2)->size() ; execute (count_pairs(s1, s2, n1, n2))->display() ) else skip; operation count_pairs(s1 : OclAny, s2 : OclAny, n1 : OclAny, n2 : OclAny) : OclAny pre: true post: true activity: var mp : Map := Integer.subrange(0, (s1)->size()-1)->select(i | true)->collect(i | Map{s1[i+1] |-> 0})->unionAll() ; for i : Integer.subrange(0, n1-1) do ( mp[s1[i+1]+1] := mp[s1[i+1]+1] + 1) ; var cnt : int := 0 ; for i : Integer.subrange(0, n2-1) do ( if (mp[s2[i+1]+1] > 0) then ( cnt := cnt + 1 ; mp[s2[i+1]+1] := mp[s2[i+1]+1] - 1 ) else skip) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fact(n): res=1 for i in range(2,n+1,1): res=res*i return res def nCr(n,r): return fact(n)//(fact(r)*fact(n-r)) def NumberOfWays(X,Y,M,N): return fact(X+Y)*nCr(M,X)*nCr(N,Y) if __name__=='__main__' : X=2 Y=2 M=3 N=3 print(NumberOfWays(X,Y,M,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( X := 2 ; Y := 2 ; M := 3 ; N := 3 ; execute (NumberOfWays(X, Y, M, N))->display() ) else skip; operation fact(n : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; for i : Integer.subrange(2, n + 1-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( res := res * i) ; return res; operation nCr(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: return fact(n) div (fact(r) * fact(n - r)); operation NumberOfWays(X : OclAny, Y : OclAny, M : OclAny, N : OclAny) : OclAny pre: true post: true activity: return fact(X + Y) * nCr(M, X) * nCr(N, Y); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findCountOfSolutions(n,p): ans=0 ; for x in range(1,p): if((x*x)% p==1): last=x+p*(n/p); if(last>n): last-=p ; ans+=((last-x)/p+1); return int(ans); n=10 ; p=5 ; print(findCountOfSolutions(n,p)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 10; ; p := 5; ; execute (findCountOfSolutions(n, p))->display();; operation findCountOfSolutions(n : OclAny, p : OclAny) pre: true post: true activity: var ans : int := 0; ; for x : Integer.subrange(1, p-1) do ( if ((x * x) mod p = 1) then ( var last : OclAny := x + p * (n / p); ; if ((last->compareTo(n)) > 0) then ( last := last - p; ) else skip ; ans := ans + ((last - x) / p + 1); ) else skip) ; return ("" + ((ans)))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np LAS=np.zeros((1000,2)) for i in range(1000): for j in range(2): LAS[i][j]=False def solve(arr,n,i,pos): if(i==n): return 0 ; if(LAS[i][pos]): return LAS[i][pos]; inc=0 ; exc=0 ; if(arr[i]>0 and pos==True): pos=False ; inc=1+solve(arr,n,i+1,pos); elif(arr[i]<0 and pos==False): pos=True ; inc=1+solve(arr,n,i+1,pos); exc=solve(arr,n,i+1,pos); LAS[i][pos]=max(inc,exc); return LAS[i][pos]; if __name__=="__main__" : arr=[-1,2,3,4,5,-6,8,-99]; n=len(arr); print(max(solve(arr,n,0,0),solve(arr,n,0,1))); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var LAS : Sequence := MatrixLib.singleValueMatrix(Sequence{1000, 2}, 0.0) ; for i : Integer.subrange(0, 1000-1) do ( for j : Integer.subrange(0, 2-1) do ( LAS[i+1][j+1] := false)) ; skip ; if __name__ = "__main__" then ( arr := Sequence{-1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{-6}->union(Sequence{8}->union(Sequence{ -99 }))))))); ; n := (arr)->size(); ; execute (Set{solve(arr, n, 0, 0), solve(arr, n, 0, 1)}->max())->display(); ) else skip; operation solve(arr : OclAny, n : OclAny, i : OclAny, pos : OclAny) pre: true post: true activity: if (i = n) then ( return 0; ) else skip ; if (LAS[i+1][pos+1]) then ( return LAS[i+1][pos+1]; ) else skip ; var inc : int := 0; var exc : int := 0; ; if (arr[i+1] > 0 & pos = true) then ( pos := false; ; inc := 1 + solve(arr, n, i + 1, pos); ) else (if (arr[i+1] < 0 & pos = false) then ( pos := true; ; inc := 1 + solve(arr, n, i + 1, pos); ) else skip) ; exc := solve(arr, n, i + 1, pos); ; LAS[i+1][pos+1] := Set{inc, exc}->max(); ; return LAS[i+1][pos+1];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x,y,w,h=map(int,input().split()) c=0 for _ in range(int(input())): a,b=map(int,input().split()) if x<=a and a<=x+w and y<=b and b<=y+h : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; var w : OclAny := null; var h : OclAny := null; Sequence{x,y,w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : int := 0 ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (x->compareTo(a)) <= 0 & (a->compareTo(x + w)) <= 0 & (y->compareTo(b)) <= 0 & (b->compareTo(y + h)) <= 0 then ( c := c + 1 ) else skip) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import numpy as np read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines def main(A,X,Y): N=len(A) count=np.zeros(N+1,np.int64) covered=np.zeros(N+1,np.int64) for x in A : count[x]+=1 y=x-count[x]+1 if y>0 : covered[y]+=1 spell=np.sum(covered[1 :]==0) for i in range(len(X)): x,y=X[i],Y[i] before=A[x-1] after=y A[x-1]=y rem=before-count[before]+1 count[before]-=1 add=after-count[after] count[after]+=1 if rem>0 : covered[rem]-=1 if not covered[rem]: spell+=1 if add>0 : if not covered[add]: spell-=1 covered[add]+=1 print(spell) if sys.argv[-1]=='ONLINE_JUDGE' : import numba from numba.pycc import CC i8=numba.from_dtype(np.int64) signature=(i8[:],i8[:],i8[:]) cc=CC('my_module') cc.export('main',signature)(main) cc.compile() from my_module import main N,M=map(int,readline().split()) A=np.array(readline().split(),np.int64) XY=np.array(read().split(),np.int64) X=XY[: : 2] Y=XY[1 : : 2] main(A,X,Y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; skip ; if (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) = 'ONLINE_JUDGE' then ( skip ; skip ; var i8 : OclAny := numba.from_dtype() ; var signature : OclAny := Sequence{i8, i8, i8} ; var cc : OclAny := CC('my_module') ; (expr (atom (name cc)) (trailer . (name export) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'main')))))) , (argument (test (logical_test (comparison (expr (atom (name signature)))))))) ))) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name main)))))))) )))) ; cc.compile() ) else skip ; skip ; var M : OclAny := null; Sequence{N,M} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; A := (readline().split(), ) ; var XY : Sequence := (read().split(), ) ; X := XY(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ; Y := XY(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ; main(A, X, Y); operation main(A : OclAny, X : OclAny, Y : OclAny) pre: true post: true activity: var N : int := (A)->size() ; var count : Sequence := MatrixLib.singleValueMatrix(N + 1, 0.0) ; var covered : Sequence := MatrixLib.singleValueMatrix(N + 1, 0.0) ; for x : A do ( count[x+1] := count[x+1] + 1 ; var y : double := x - count[x+1] + 1 ; if y > 0 then ( covered[y+1] := covered[y+1] + 1 ) else skip) ; var spell : double := MatrixLib.sumMatrix(covered->tail() = 0) ; for i : Integer.subrange(0, (X)->size()-1) do ( var x : OclAny := null; Sequence{x,y} := Sequence{X[i+1],Y[i+1]} ; var before : OclAny := A[x - 1+1] ; var after : OclAny := y ; A[x - 1+1] := y ; var rem : double := before - count[before+1] + 1 ; count[before+1] := count[before+1] - 1 ; var add : double := after - count[after+1] ; count[after+1] := count[after+1] + 1 ; if rem > 0 then ( covered[rem+1] := covered[rem+1] - 1 ; if not(covered[rem+1]) then ( spell := spell + 1 ) else skip ) else skip ; if add > 0 then ( if not(covered[add+1]) then ( spell := spell - 1 ) else skip ; covered[add+1] := covered[add+1] + 1 ) else skip ; execute (spell)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline N,M=map(int,input().split()) A=[int(x)for x in input().split()] XY=[tuple(int(x)for x in input().split())for _ in range(M)] def subscore_solution(): from collections import Counter for x,y in XY : A[x-1]=y covered=[False]*(N+N+10) for key,cnt in Counter(A).items(): for i in range(cnt): covered[max(0,key-i)]=True print(sum(not bl for bl in covered[1 : N+1])) counter=[0]*(N+1) covered=[0]*(N+N+10) for a in A : counter[a]+=1 covered[a-counter[a]+1]+=1 magic=sum(x==0 for x in covered[1 : N+1]) for i,y in XY : x=A[i-1] A[i-1]=y rem=x-counter[x]+1 counter[x]-=1 counter[y]+=1 add=y-counter[y]+1 covered[rem]-=1 if 1<=rem<=N and covered[rem]==0 : magic+=1 if 1<=add<=N and covered[add]==0 : magic-=1 covered[add]+=1 print(magic) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var XY : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))))) ; skip ; var counter : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; covered := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + N + 10)) ; for a : A do ( counter[a+1] := counter[a+1] + 1 ; covered[a - counter[a+1] + 1+1] := covered[a - counter[a+1] + 1+1] + 1) ; var magic : OclAny := ((argument (test (logical_test (comparison (comparison (expr (atom (name x)))) == (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name covered)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (test (logical_test (comparison (expr (expr (atom (name N))) + (expr (atom (number (integer 1)))))))))) ]))))))))->sum() ; for _tuple : XY do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); var x : OclAny := A[i - 1+1] ; A[i - 1+1] := y ; var rem : double := x - counter[x+1] + 1 ; counter[x+1] := counter[x+1] - 1 ; counter[y+1] := counter[y+1] + 1 ; var add : double := y - counter[y+1] + 1 ; covered[rem+1] := covered[rem+1] - 1 ; if 1 <= rem & (rem <= N) & covered[rem+1] = 0 then ( magic := magic + 1 ) else skip ; if 1 <= add & (add <= N) & covered[add+1] = 0 then ( magic := magic - 1 ) else skip ; covered[add+1] := covered[add+1] + 1 ; execute (magic)->display()); operation subscore_solution() pre: true post: true activity: skip ; for _tuple : XY do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); A[x - 1+1] := y ; var covered : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (N + N + 10)) ; for _tuple : Counter(A)->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var cnt : OclAny := _tuple->at(_indx); for i : Integer.subrange(0, cnt-1) do ( covered[Set{0, key - i}->max()+1] := true)) ; execute (((argument (test (logical_test not (logical_test (comparison (expr (atom (name bl))))))) (comp_for for (exprlist (expr (atom (name bl)))) in (logical_test (comparison (expr (atom (name covered)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (test (logical_test (comparison (expr (expr (atom (name N))) + (expr (atom (number (integer 1)))))))))) ]))))))))->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter N,M=map(int,input().split()) A=list(map(int,input().split())) src=[tuple(map(int,input().split()))for i in range(M)] ctr=Counter(A) cover=[0]*(2*N+1) for k,v in ctr.items(): for i in range(k,k-v,-1): cover[i+N]+=1 ans=cover[N+1 :].count(0) for x,y in src : ctr[A[x-1]]-=1 ai=A[x-1]+N-ctr[A[x-1]] cover[ai]-=1 if ai>N and cover[ai]==0 : ans+=1 A[x-1]=y bi=y+N-ctr[y] if bi>N and cover[bi]==0 : ans-=1 cover[bi]+=1 ctr[y]+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var src : Sequence := Integer.subrange(0, M-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ctr : OclAny := Counter(A) ; var cover : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * N + 1)) ; for _tuple : ctr->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); for i : Integer.subrange(k - v + 1, k)->reverse() do ( cover[i + N+1] := cover[i + N+1] + 1)) ; var ans : OclAny := cover.subrange(N + 1+1)->count(0) ; for _tuple : src do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); ctr[A[x - 1+1]+1] := ctr[A[x - 1+1]+1] - 1 ; var ai : double := A[x - 1+1] + N - ctr[A[x - 1+1]+1] ; cover[ai+1] := cover[ai+1] - 1 ; if (ai->compareTo(N)) > 0 & cover[ai+1] = 0 then ( ans := ans + 1 ) else skip ; A[x - 1+1] := y ; var bi : double := y + N - ctr[y+1] ; if (bi->compareTo(N)) > 0 & cover[bi+1] = 0 then ( ans := ans - 1 ) else skip ; cover[bi+1] := cover[bi+1] + 1 ; ctr[y+1] := ctr[y+1] + 1 ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(arr): l=[] l.append(arr[0]) i=1 mx=0 while i0 : mx=max(mx,arr[i]^ l[-1]) if arr[i]>l[-1]: l.pop() else : break l.append(arr[i]) i+=1 return mx n=int(input()) arr=list(map(int,input().split())) print(check(arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; arr := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (check(arr))->display(); operation check(arr : OclAny) : OclAny pre: true post: true activity: var l : Sequence := Sequence{} ; execute ((arr->first()) : l) ; var i : int := 1 ; var mx : int := 0 ; while (i->compareTo((arr)->size())) < 0 do ( while (l)->size() > 0 do ( mx := Set{mx, MathLib.bitwiseXor(arr[i+1], l->last())}->max() ; if (arr[i+1]->compareTo(l->last())) > 0 then ( l := l->front() ) else ( break )) ; execute ((arr[i+1]) : l) ; i := i + 1) ; return mx; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys N,M=map(int,sys.stdin.readline().split()) E=N ; c=[0]*300000 ; l=[0]*300000 A=list(map(int,sys.stdin.readline().split())) def Z(e): global E p=e-c[e] c[e]+=1 if p>0 : if not l[p]: E-=1 l[p]+=1 for e in A : Z(e) A=[0]+A for m in range(M): x,y=map(int,sys.stdin.readline().split()) p=A[x]-c[A[x]]+1 c[A[x]]-=1 if p>0 : l[p]-=1 if not l[p]: E+=1 A[x]=y Z(A[x]) print(E) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute E : OclAny; operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var E : OclAny := N; var c : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 300000); var l : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 300000) ; var A : Sequence := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; for e : A do ( Z(e)) ; A := Sequence{ 0 }->union(A) ; for m : Integer.subrange(0, M-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; p := A[x+1] - c[A[x+1]+1] + 1 ; c[A[x+1]+1] := c[A[x+1]+1] - 1 ; if p > 0 then ( l[p+1] := l[p+1] - 1 ; if not(l[p+1]) then ( E := E + 1 ) else skip ) else skip ; A[x+1] := y ; Z(A[x+1]) ; execute (E)->display()); operation Z(e : OclAny) pre: true post: true activity: skip ; var p : double := e - c[e+1] ; c[e+1] := c[e+1] + 1 ; if p > 0 then ( if not(l[p+1]) then ( E := E - 1 ) else skip ; l[p+1] := l[p+1] + 1 ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n,m=map(int,input().split()) an=list(map(int,input().split())) ac_=Counter(an) ac={i : ac_[i]if i in ac_ else 0 for i in range(1,n+1)} ad=[0]*n for a,c in ac.items(): for i in range(max(0,a-c),a): ad[i]+=1 ans=ad.count(0) anss=[] for x,y in(map(int,input().split())for _ in range(m)): ax=an[x-1] xdi=ax-ac[ax] if xdi>=0 : ad[xdi]-=1 if ad[xdi]==0 : ans+=1 ac[ax]-=1 ac[y]+=1 ydi=y-ac[y] if ydi>=0 : ad[ydi]+=1 if ad[ydi]==1 : ans-=1 an[x-1]=y anss.append(ans) print('\n'.join(map(str,anss))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var an : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ac_ : OclAny := Counter(an) ; var ac : Map := Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | Map{i |-> if (ac_)->includes(i) then ac_[i+1] else 0 endif})->unionAll() ; var ad : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for _tuple : ac->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); for i : Integer.subrange(Set{0, a - c}->max(), a-1) do ( ad[i+1] := ad[i+1] + 1)) ; var ans : int := ad->count(0) ; var anss : Sequence := Sequence{} ; for _tuple : Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name m)))))))) ))))))))} do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); var ax : OclAny := an[x - 1+1] ; var xdi : double := ax - ac[ax+1] ; if xdi >= 0 then ( ad[xdi+1] := ad[xdi+1] - 1 ; if ad[xdi+1] = 0 then ( ans := ans + 1 ) else skip ) else skip ; ac[ax+1] := ac[ax+1] - 1 ; ac[y+1] := ac[y+1] + 1 ; var ydi : double := y - ac[y+1] ; if ydi >= 0 then ( ad[ydi+1] := ad[ydi+1] + 1 ; if ad[ydi+1] = 1 then ( ans := ans - 1 ) else skip ) else skip ; an[x - 1+1] := y ; execute ((ans) : anss)) ; execute (StringLib.sumStringsWithSeparator(((anss)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMin(arr,n): sum=0 for i in range(0,n): sum=sum+arr[i] arr.sort() min=arr[0] max=0 for i in range(n-1,0,-1): num=arr[i] total=num+min for j in range(2,num+1): if(num % j==0): d=j now=(num//d)+(min*d) reduce=total-now if(reduce>max): max=reduce print(sum-max) arr=[1,2,3,4,5] n=len(arr) findMin(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ; n := (arr)->size() ; findMin(arr, n); operation findMin(arr : OclAny, n : OclAny) pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + arr[i+1]) ; arr := arr->sort() ; var min : OclAny := arr->first() ; var max : int := 0 ; for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( var num : OclAny := arr[i+1] ; var total : OclAny := num + min ; for j : Integer.subrange(2, num + 1-1) do ( if (num mod j = 0) then ( var d : OclAny := j ; var now : int := (num div d) + (min * d) ; var reduce : double := total - now ; if ((reduce->compareTo(max)) > 0) then ( max := reduce ) else skip ) else skip)) ; execute (sum - max)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(A,n): cnt=0 parent=[None]*(n+1) vis=[None]*(n+1) for i in range(0,n+1): parent[i]=-1 vis[i]=0 for i in range(0,n): j=i if(parent[j]==-1): while(parent[j]==-1): parent[j]=i j=(j+A[j]+1)% n if(parent[j]==i): while(vis[j]==0): vis[j]=1 cnt=cnt+1 j=(j+A[j]+1)% n return cnt A=[0,0,0,2] n=len(A) print(solve(A,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; A := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 2 }))) ; n := (A)->size() ; execute (solve(A, n))->display(); operation solve(A : OclAny, n : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; var parent : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (n + 1)) ; var vis : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (n + 1)) ; for i : Integer.subrange(0, n + 1-1) do ( parent[i+1] := -1 ; vis[i+1] := 0) ; for i : Integer.subrange(0, n-1) do ( var j : OclAny := i ; if (parent[j+1] = -1) then ( while (parent[j+1] = -1) do ( parent[j+1] := i ; j := (j + A[j+1] + 1) mod n) ; if (parent[j+1] = i) then ( while (vis[j+1] = 0) do ( vis[j+1] := 1 ; cnt := cnt + 1 ; j := (j + A[j+1] + 1) mod n) ) else skip ) else skip) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- onsite_finalists=int(input()) ranks_of_finalists=list(map(int,input().split(' '))) ranks_of_finalists.sort() if ranks_of_finalists[-1]<=25 : print(0) else : print(ranks_of_finalists[-1]-25) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var onsite_finalists : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ranks_of_finalists : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; ranks_of_finalists := ranks_of_finalists->sort() ; if ranks_of_finalists->last() <= 25 then ( execute (0)->display() ) else ( execute (ranks_of_finalists->last() - 25)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) data=list(map(int,input().split())) print(max(max(data)-25,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var data : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (Set{(data)->max() - 25, 0}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d=int(input()) for i in range(d): X,Y,W,H=map(int,input().split()) count=0 n=int(input()) for j in range(n): x,y=map(int,input().split()) if X<=x<=X+W and Y<=y<=Y+H : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, d-1) do ( var X : OclAny := null; var Y : OclAny := null; var W : OclAny := null; var H : OclAny := null; Sequence{X,Y,W,H} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var count : int := 0 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (X->compareTo(x)) <= 0 & (x <= X + W) & (Y->compareTo(y)) <= 0 & (y <= Y + H) then ( count := count + 1 ) else skip) ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys import itertools import fractions if __name__=='__main__' : wtf=sys.stdin.read() wtf=wtf.strip().split('\n') n=int(wtf[0]) A=sorted(map(int,wtf[1].split())) if A[-1]>25 : print(A[-1]-25) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var wtf : String := (OclFile["System.in"]).readAll() ; wtf := wtf->trim().split(' ') ; var n : int := ("" + ((wtf->first())))->toInteger() ; var A : Sequence := (wtf[1+1].split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; if A->last() > 25 then ( execute (A->last() - 25)->display() ) else ( execute (0)->display() ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=[int(c)for c in input().split()] print(max(0,max(arr)-25)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := input().split()->select(c | true)->collect(c | (("" + ((c)))->toInteger())) ; execute (Set{0, (arr)->max() - 25}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input(); print(max(0,max(map(int,input().split()))-25)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input(); execute (Set{0, ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->max() - 25}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def findPowerOfP(N,p): count=0 r=p while(r<=N): count+=int(N/r) r=r*p return count def primeFactorsofB(B): ans=[] i=2 while(B!=1): if(B % i==0): count=0 while(B % i==0): B=int(B/i) count+=1 ans.append((i,count)) i+=1 return ans def largestPowerOfB(N,B): vec=[] vec=primeFactorsofB(B) ans=sys.maxsize ans=min(ans,int(findPowerOfP(N,vec[0][0])/vec[0][1])) return ans if __name__=='__main__' : print(largestPowerOfB(5,2)) print(largestPowerOfB(6,9)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( execute (largestPowerOfB(5, 2))->display() ; execute (largestPowerOfB(6, 9))->display() ) else skip; operation findPowerOfP(N : OclAny, p : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var r : OclAny := p ; while ((r->compareTo(N)) <= 0) do ( count := count + ("" + ((N / r)))->toInteger() ; r := r * p) ; return count; operation primeFactorsofB(B : OclAny) : OclAny pre: true post: true activity: var ans : Sequence := Sequence{} ; var i : int := 2 ; while (B /= 1) do ( if (B mod i = 0) then ( count := 0 ; while (B mod i = 0) do ( B := ("" + ((B / i)))->toInteger() ; count := count + 1) ; execute ((Sequence{i, count}) : ans) ) else skip ; i := i + 1) ; return ans; operation largestPowerOfB(N : OclAny, B : OclAny) : OclAny pre: true post: true activity: var vec : Sequence := Sequence{} ; vec := primeFactorsofB(B) ; ans := (trailer . (name maxsize)) ; ans := Set{ans, ("" + ((findPowerOfP(N, vec->first()->first()) / vec->first()[1+1])))->toInteger()}->min() ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find_digit(s,n): first_digit=-1 for i in range(n-1,-1,-1): if s[i]<'0' or s[i]>'9' : first_digit=i break first_digit+=1 s_len=first_digit num=0 pw=1 i=n-1 while i>=0 : if s[i]>='0' and s[i]<='9' : digit=ord(s[i])-ord('0') num=num+(pw*digit) if num>=s_len : return-1 pw=pw*10 i-=1 num=num*10 req=s_len-num if req>9 or req<0 : return-1 return req if __name__=="__main__" : s="abcd0" n=len(s) print(find_digit(s,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "abcd0" ; n := (s)->size() ; execute (find_digit(s, n))->display() ) else skip; operation find_digit(s : OclAny, n : OclAny) : OclAny pre: true post: true activity: var first_digit : int := -1 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if s[i+1] < '0' or s[i+1] > '9' then ( first_digit := i ; break ) else skip) ; first_digit := first_digit + 1 ; var s_len : int := first_digit ; var num : int := 0 ; var pw : int := 1 ; var i : double := n - 1 ; while i >= 0 do ( if s[i+1] >= '0' & s[i+1] <= '9' then ( var digit : double := (s[i+1])->char2byte() - ('0')->char2byte() ; num := num + (pw * digit) ; if (num->compareTo(s_len)) >= 0 then ( return -1 ) else skip ; pw := pw * 10 ) else skip ; i := i - 1) ; num := num * 10 ; var req : double := s_len - num ; if req > 9 or req < 0 then ( return -1 ) else skip ; return req; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def largest_alphabet(a,n): max='A' for i in range(n): if(a[i]>max): max=a[i] return max def smallest_alphabet(a,n): min='z' ; for i in range(n-1): if(a[i]size() ; execute ("Largest and smallest alphabet is : ")->display() ; execute (largest_alphabet(a, size))->display() ; execute (smallest_alphabet(a, size))->display() ) else skip; operation largest_alphabet(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var max : String := 'A' ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] > max) then ( max := a[i+1] ) else skip) ; return max; operation smallest_alphabet(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var min : String := 'z'; ; for i : Integer.subrange(0, n - 1-1) do ( if (a[i+1] < min) then ( min := a[i+1] ) else skip) ; return min; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) r=[] for i in range(q): x=list(map(int,input().split())) n=x[0] a=x[1] b=x[2] if a>=b : c=n//2 d=c*b c1=n-c*2 d1=c1*a r.append(d+d1) else : if b>=(2*a): d=a*n r.append(d) else : c=n//2 d=c*b c1=n-c*2 d1=c1*a r.append(d+d1) for i in range(len(r)): print(r[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r : Sequence := Sequence{} ; for i : Integer.subrange(0, q-1) do ( var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := x->first() ; var a : OclAny := x[1+1] ; var b : OclAny := x[2+1] ; if (a->compareTo(b)) >= 0 then ( var c : int := n div 2 ; var d : double := c * b ; var c1 : double := n - c * 2 ; var d1 : double := c1 * a ; execute ((d + d1) : r) ) else ( if (b->compareTo((2 * a))) >= 0 then ( d := a * n ; execute ((d) : r) ) else ( c := n div 2 ; d := c * b ; c1 := n - c * 2 ; d1 := c1 * a ; execute ((d + d1) : r) ) )) ; for i : Integer.subrange(0, (r)->size()-1) do ( execute (r[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): a,b,c=map(int,input().split()) k=((a//2)*c)+((a % 2)*b) print(min((a*b),k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : double := ((a div 2) * c) + ((a mod 2) * b) ; execute (Set{(a * b), k}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,a,b=(int(i)for i in input().split()) res=min(n*a,(n//2)*b+(n % 2)*a) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var res : OclAny := Set{n * a, (n div 2) * b + (n mod 2) * a}->min() ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,a,b=map(int,input().split()) print(min(n*a,n//2*b+n % 2*a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{n * a, n div 2 * b + n mod 2 * a}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def divisibleby37(n): l=len(n) if(n==0): return True if(l % 3==1): n="00"+n l+=2 elif(l % 3==2): n="0"+n l+=1 gSum=0 while(l!=0): group=int(n[l-3 : l]) l=l-3 gSum=gSum+group if(gSum>=1000): return(divisibleby37(str(gSum))) else : return(gSum % 37==0) print(divisibleby37("8955795758")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (divisibleby37("8955795758"))->display(); operation divisibleby37(n : OclAny) : OclAny pre: true post: true activity: var l : int := (n)->size() ; if (n = 0) then ( return true ) else skip ; if (l mod 3 = 1) then ( n := "00" + n ; l := l + 2 ) else (if (l mod 3 = 2) then ( n := "0" + n ; l := l + 1 ) else skip) ; var gSum : int := 0 ; while (l /= 0) do ( var group : int := ("" + ((n.subrange(l - 3+1, l))))->toInteger() ; l := l - 3 ; gSum := gSum + group) ; if (gSum >= 1000) then ( return (divisibleby37(("" + ((gSum))))) ) else ( return (gSum mod 37 = 0) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) res=0 for i in range(q): n,a,b=[int(i)for i in input().split()] if b/2>=a : res=a*n else : if n % 2==0 : res=b*n//2 else : res=b*(n-1)//2+a print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : int := 0 ; for i : Integer.subrange(0, q-1) do ( var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if (b / 2->compareTo(a)) >= 0 then ( res := a * n ) else ( if n mod 2 = 0 then ( res := b * n div 2 ) else ( res := b * (n - 1) div 2 + a ) ) ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=10005 MOD=1000000007 def countNum(idx,sum,tight,num,len1,k): if(len1==idx): if(sum==0): return 1 else : return 0 if(dp[idx][sum][tight]!=-1): return dp[idx][sum][tight] res=0 if(tight==0): limit=num[idx] else : limit=9 for i in range(limit+1): new_tight=tight if(tight==0 and isize() ; k := 58 ; var dp : Sequence := Integer.subrange(0, MAX-1)->select(k | true)->collect(k | (Integer.subrange(0, 101-1)->select(j | true)->collect(j | (Integer.subrange(0, 2-1)->select(i | true)->collect(i | (-1)))))) ; num := process(n) ; execute (countNum(0, 0, 0, num, len1, k))->display() ) else skip; operation countNum(idx : OclAny, sum : OclAny, tight : OclAny, num : OclAny, len1 : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (len1 = idx) then ( if (sum = 0) then ( return 1 ) else ( return 0 ) ) else skip ; if (dp[idx+1][sum+1][tight+1] /= -1) then ( return dp[idx+1][sum+1][tight+1] ) else skip ; var res : int := 0 ; if (tight = 0) then ( var limit : OclAny := num[idx+1] ) else ( limit := 9 ) ; for i : Integer.subrange(0, limit + 1-1) do ( var new_tight : OclAny := tight ; if (tight = 0 & (i->compareTo(limit)) < 0) then ( new_tight := 1 ) else skip ; res := res + countNum(idx + 1, (sum + i) mod k, new_tight, num, len1, k) ; res := res mod MOD) ; if (res < 0) then ( res := res + MOD ) else skip ; dp[idx+1][sum+1][tight+1] := res ; return dp[idx+1][sum+1][tight+1]; operation process(s : OclAny) : OclAny pre: true post: true activity: num := Sequence{} ; for i : Integer.subrange(0, (s)->size()-1) do ( execute (((s[i+1])->char2byte() - ('0')->char2byte()) : num)) ; return num; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Segment(x,l,n): if(n==1): return 1 ans=2 for i in range(1,n-1): if(x[i]-l[i]>x[i-1]): ans+=1 elif(x[i]+l[i]union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 8 })))) ; l := Sequence{10}->union(Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 5 })))) ; n := (x)->size() ; execute (Segment(x, l, n))->display(); operation Segment(x : OclAny, l : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return 1 ) else skip ; var ans : int := 2 ; for i : Integer.subrange(1, n - 1-1) do ( if ((x[i+1] - l[i+1]->compareTo(x[i - 1+1])) > 0) then ( ans := ans + 1 ) else (if ((x[i+1] + l[i+1]->compareTo(x[i + 1+1])) < 0) then ( x[i+1] := x[i+1] + l[i+1] ; ans := ans + 1 ) else skip)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNumber(n,m): num=(m-1)*9+n ; return num ; if __name__=="__main__" : n=2 ; m=5 ; print(findNumber(n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 2; ; m := 5; ; execute (findNumber(n, m))->display() ) else skip; operation findNumber(n : OclAny, m : OclAny) pre: true post: true activity: var num : double := (m - 1) * 9 + n; ; return num;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def oddIntegers(n,k): if(n % 2!=k % 2): print("-1"); return ; sum=0 ; i=1 ; j=1 ; while(jdisplay(); ; return; ) else skip ; var sum : int := 0; ; var i : int := 1; ; var j : int := 1; ; while ((j->compareTo(k)) < 0) do ( sum := sum + i; ; execute (i)->display(); ; i := i + 2; ; j := j + 1;) ; var finalOdd : double := n - sum; ; execute (finalOdd)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,m,k=map(int,input().split()) a=list(map(int,input().split())) x=n//2+1 if not n % 2 or mcollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : int := n div 2 + 1 ; if not(n mod 2) or (m->compareTo(x)) < 0 then ( var ans : int := 0 ) else ( var c : double := (10)->pow(9) + 1 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( c := Set{c, a[i+1]}->min()) ; var u : int := m div x ; ans := Set{u * k, c}->min() ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B=map(int,input().split()) if A % 3==0 or B % 3==0 or(A+B)% 3==0 : print("Possible") else : print("Impossible") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if A mod 3 = 0 or B mod 3 = 0 or (A + B) mod 3 = 0 then ( execute ("Possible")->display() ) else ( execute ("Impossible")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): a,b=map(int,input().split()) if a % 3==0 or b % 3==0 or(a+b)% 3==0 : print('Possible') else : print('Impossible') if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a mod 3 = 0 or b mod 3 = 0 or (a + b) mod 3 = 0 then ( execute ('Possible')->display() ) else ( execute ('Impossible')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=list(map(int,input().split())) print("Possible" if a % 3==0 or b % 3==0 or(a+b)% 3==0 else "Impossible") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (if a mod 3 = 0 or b mod 3 = 0 or (a + b) mod 3 = 0 then "Possible" else "Impossible" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S_list=list(map(int,input().split())) A,B=S_list[0],S_list[1] if(A*B*(A+B))% 3==0 : result="Possible" else : result="Impossible" print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := Sequence{S_list->first(),S_list[1+1]} ; if (A * B * (A + B)) mod 3 = 0 then ( var result : String := "Possible" ) else ( result := "Impossible" ) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,x,y=map(int,input().split()) ans=[-1]if ycollect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := if (y->compareTo(n)) < 0 or (n - 1 + (y - n + 1)->pow(2)->compareTo(x)) < 0 then Sequence{ -1 } else MatrixLib.elementwiseMult(Sequence{ 1 }, (n - 1))->union(Sequence{ y - n + 1 }) endif ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) print('Possible' if a % 3==0 or b % 3==0 or(a+b)% 3==0 else 'Impossible') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if a mod 3 = 0 or b mod 3 = 0 or (a + b) mod 3 = 0 then 'Possible' else 'Impossible' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): NUM_DAYS=30 MAX_ABSENT=2 MAX_LATE=1 num_prize_strings=create_nested_lists(0,NUM_DAYS+1,MAX_ABSENT+1,MAX_LATE+1) num_prize_strings[0][0][0]=1 for i in range(1,len(num_prize_strings)): for j in range(len(num_prize_strings[i])): for k in range(len(num_prize_strings[i][j])): if j==0 : s=0 for l in range(MAX_ABSENT+1): s+=num_prize_strings[i-1][l][k] if k>0 : for l in range(MAX_ABSENT+1): s+=num_prize_strings[i-1][l][k-1] else : s=num_prize_strings[i-1][j-1][k] num_prize_strings[i][j][k]=s ans=sum(map(sum,num_prize_strings[NUM_DAYS])) return str(ans) def create_nested_lists(value,*dimensions): if len(dimensions)==0 : raise ValueError() elif len(dimensions)==1 : return[value]*dimensions[0] else : return[create_nested_lists(value,*dimensions[1 :])for _ in range(dimensions[0])] if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var NUM_DAYS : int := 30 ; var MAX_ABSENT : int := 2 ; var MAX_LATE : int := 1 ; var num_prize_strings : OclAny := create_nested_lists(0, NUM_DAYS + 1, MAX_ABSENT + 1, MAX_LATE + 1) ; num_prize_strings->first()->first()->first() := 1 ; for i : Integer.subrange(1, (num_prize_strings)->size()-1) do ( for j : Integer.subrange(0, (num_prize_strings[i+1])->size()-1) do ( for k : Integer.subrange(0, (num_prize_strings[i+1][j+1])->size()-1) do ( if j = 0 then ( var s : int := 0 ; for l : Integer.subrange(0, MAX_ABSENT + 1-1) do ( s := s + num_prize_strings[i - 1+1][l+1][k+1]) ; if k > 0 then ( for l : Integer.subrange(0, MAX_ABSENT + 1-1) do ( s := s + num_prize_strings[i - 1+1][l+1][k - 1+1]) ) else skip ) else ( s := num_prize_strings[i - 1+1][j - 1+1][k+1] ) ; num_prize_strings[i+1][j+1][k+1] := s))) ; var ans : OclAny := ((num_prize_strings[NUM_DAYS+1])->collect( _x | (sum)->apply(_x) ))->sum() ; return ("" + ((ans))); operation create_nested_lists(value : OclAny, dimensions : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name dimensions))) if (dimensions)->size() = 0 then ( error IncorrectElementException.newIncorrectElementException() ) else (if (dimensions)->size() = 1 then ( return MatrixLib.elementwiseMult(Sequence{ value }, dimensions->first()) ) else ( return Integer.subrange(0, dimensions->first()-1)->select(_anon | true)->collect(_anon | (create_nested_lists(value, (argument * (test (logical_test (comparison (expr (atom (name dimensions)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))))))))) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) f=l[0] s=l[-1] a=[] a.append(f) a.append(s) while n : m=min(l) if m in a : print(m) break else : a.append(l[l.index(m)+1]) a.append(l[l.index(m)-1]) l.remove(m) n=n-1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var f : OclAny := l->first() ; var s : OclAny := l->last() ; var a : Sequence := Sequence{} ; execute ((f) : a) ; execute ((s) : a) ; while n do ( var m : OclAny := (l)->min() ; if (a)->includes(m) then ( execute (m)->display() ; break ) else ( execute ((l[l->indexOf(m) - 1 + 1+1]) : a) ; execute ((l[l->indexOf(m) - 1 - 1+1]) : a) ; execute ((m) /: l) ) ; n := n - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,threading,os.path import collections,heapq,math,bisect import string sys.setrecursionlimit(10**6) threading.stack_size(2**27) def main(): if os.path.exists('in.txt'): input=open('in.txt','r') else : input=sys.stdin n=int(input.readline()) lis=list(map(int,input.readline().split())) ans=lis[0] cont_next=False for i,x in enumerate(lis): if cont_next or i==n-1 : cont_next=False continue if i+1==n-1 : ans=min(ans,lis[i+1]) break if lis[i+1]<=lis[i+2]: cont_next=True ans=min(ans,lis[i+2]) else : ans=min(ans,lis[i+1]) output=ans if os.path.exists('out.txt'): open('out.txt','w').writelines(str(output)) else : sys.stdout.write(str(output)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(6)) ; threading.stack_size((2)->pow(27)) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: if os.path.exists('in.txt') then ( var input : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('in.txt')) ) else ( input := OclFile["System.in"] ) ; var n : int := ("" + (((OclFile["System.in"]).readLine.readLine())))->toInteger() ; var lis : Sequence := ((input.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : OclAny := lis->first() ; var cont_next : boolean := false ; for _tuple : Integer.subrange(1, (lis)->size())->collect( _indx | Sequence{_indx-1, (lis)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); if cont_next or i = n - 1 then ( cont_next := false ; continue ) else skip ; if i + 1 = n - 1 then ( ans := Set{ans, lis[i + 1+1]}->min() ; break ) else skip ; if (lis[i + 1+1]->compareTo(lis[i + 2+1])) <= 0 then ( cont_next := true ; ans := Set{ans, lis[i + 2+1]}->min() ) else ( ans := Set{ans, lis[i + 1+1]}->min() )) ; var output : OclAny := ans ; if os.path.exists('out.txt') then ( (expr (atom (name open)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'out.txt')))))) , (argument (test (logical_test (comparison (expr (atom 'w'))))))) ))) (trailer . (name writelines) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name output)))))))) ))))))))) )))) ) else ( (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name output)))))))) ))))))))) )))) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=[0]+list(map(int,input().split()))+[0] print(min(max(arr[i],arr[i+1])for i in range(n+1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->union(Sequence{ 0 }) ; execute (((argument (test (logical_test (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) )))))))))->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) hmm=10**12 k=min(l[0],l[-1]) for i in range(1,n-1): sum=max(l[i],l[i+1]) if sumtoInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var hmm : double := (10)->pow(12) ; var k : OclAny := Set{l->first(), l->last()}->min() ; for i : Integer.subrange(1, n - 1-1) do ( var sum : OclAny := Set{l[i+1], l[i + 1+1]}->max() ; if (sum->compareTo(hmm)) < 0 then ( hmm := sum ) else skip) ; execute (Set{k, hmm}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) a=list(map(int,input().split())) if n % 2==0 : print('0') else : print(min(m//(n//2+1)*k,min(a[: : 2]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n mod 2 = 0 then ( execute ('0')->display() ) else ( execute (Set{m div (n div 2 + 1) * k, (a(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->min()}->min())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) c=9999 for i in range(n-1): if(l[i]<=l[i+1]and l[i+1]l[i+1]and l[i]toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 9999 ; for i : Integer.subrange(0, n - 1-1) do ( if ((l[i+1]->compareTo(l[i + 1+1])) <= 0 & (l[i + 1+1]->compareTo(c)) < 0) then ( c := l[i + 1+1] ) else (if ((l[i+1]->compareTo(l[i + 1+1])) > 0 & (l[i+1]->compareTo(c)) < 0) then ( c := l[i+1] ) else skip)) ; execute (Set{l->first(), l[n - 1+1], c}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def replace(A,B): n,m=len(A),len(B) count,i=0,0 while i=n or A[i+j]!=B[j]: break j+=1 if j==m : count+=1 i+=m-1 i+=1 return count if __name__=="__main__" : str1="aaaaaaaa" str2="aaa" print(replace(str1,str2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var str1 : String := "aaaaaaaa" ; var str2 : String := "aaa" ; execute (replace(str1, str2))->display() ) else skip; operation replace(A : OclAny, B : OclAny) : OclAny pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{(A)->size(),(B)->size()} ; var count : OclAny := null; var i : OclAny := null; Sequence{count,i} := Sequence{0,0} ; while (i->compareTo(n)) < 0 do ( var j : int := 0 ; while (j->compareTo(m)) < 0 do ( if (i + j->compareTo(n)) >= 0 or A[i + j+1] /= B[j+1] then ( break ) else skip ; j := j + 1) ; if j = m then ( count := count + 1 ; i := i + m - 1 ) else skip ; i := i + 1) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) t,=R() exec(t*'n,l,r,k=R();i=s=0\nfor x in sorted(x for x in R()if l<=x<=r):s+=x;i+=s<=k\nprint(i)\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := R->apply() ; (expr (expr (atom (name t))) * (expr (atom 'n,l,r,k=R();i=s=0 for x in sorted(x for x in R()if l<=x<=r):s+=x;i+=s<=k print(i) '))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x,y=map(int,input().split()) if(n<=y and(y-n+1)**2+n-1>=x): for i in range(n-1): print(1) print(y-n+1) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if ((n->compareTo(y)) <= 0 & (((y - n + 1))->pow(2) + n - 1->compareTo(x)) >= 0) then ( for i : Integer.subrange(0, n - 1-1) do ( execute (1)->display()) ; execute (y - n + 1)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) t,=R() while t : t-=1 ; n,l,r,k=R(); i=s=0 for x in sorted(x for x in R()if l<=x<=r): s+=x ; i+=s<=k print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := R->apply() ; while t do ( t := t - 1; var n : OclAny := null; var l : OclAny := null; var r : OclAny := null; var k : OclAny := null; Sequence{n,l,r,k} := R->apply(); var i : OclAny := 0; var s : int := 0 ; for x : (argument (test (logical_test (comparison (expr (atom (name x)))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name R)) (trailer (arguments ( )))))) (comp_iter if (test (logical_test (comparison (comparison (comparison (expr (atom (name l)))) <= (comparison (expr (atom (name x))))) <= (comparison (expr (atom (name r))))))))))->sort() do ( s := s + x; i := i + (s->compareTo(k)) <= 0) ; execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,lf,r,k=list(map(int,input().split(' '))) a=sorted(list(map(int,input().split(' ')))) s=0 for i in a : if lf<=i<=r and i<=k : s+=1 k-=i print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var lf : OclAny := null; var r : OclAny := null; var k : OclAny := null; Sequence{n,lf,r,k} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var s : int := 0 ; for i : a do ( if (lf->compareTo(i)) <= 0 & (i <= r) & (i->compareTo(k)) <= 0 then ( s := s + 1 ; k := k - i ) else skip) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for l in range(t): n,l,r,k=map(int,input().split()) lists=list(map(int,input().split())) amt=choc=0 lists.sort() for m in lists : if l<=m<=r : amt+=m if(amt<=k): choc+=1 print(choc) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for l : Integer.subrange(0, t-1) do ( var n : OclAny := null; var l : OclAny := null; var r : OclAny := null; var k : OclAny := null; Sequence{n,l,r,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lists : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var amt : OclAny := 0; var choc : int := 0 ; lists := lists->sort() ; for m : lists do ( if (l->compareTo(m)) <= 0 & (m <= r) then ( amt := amt + m ; if ((amt->compareTo(k)) <= 0) then ( choc := choc + 1 ) else skip ) else skip) ; execute (choc)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,l,r,k=map(int,input().split()) arr=list(map(int,input().split())) arr.sort() i=0 cnt=0 while(k>0 and i<=n-1): if(arr[i]>=l and arr[i]<=r): k-=arr[i] cnt+=1 if(k<0): cnt-=1 i+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var l : OclAny := null; var r : OclAny := null; var k : OclAny := null; Sequence{n,l,r,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := arr->sort() ; var i : int := 0 ; var cnt : int := 0 ; while (k > 0 & (i->compareTo(n - 1)) <= 0) do ( if ((arr[i+1]->compareTo(l)) >= 0 & (arr[i+1]->compareTo(r)) <= 0) then ( k := k - arr[i+1] ; cnt := cnt + 1 ) else skip ; if (k < 0) then ( cnt := cnt - 1 ) else skip ; i := i + 1) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline INF=float('inf') N,M=map(int,input().split()) cost=[[INF]*N for _ in[0]*N] to=[set()for _ in[0]*N] for _ in[0]*M : a,b,c=map(int,input().split()) cost[a][b]=c to[b].add(a) K=1<>j & 1==0] if tmp : dist=min(tmp) if dp[bit][i]>dist : dp[bit][i]=dist ans=dp[0][0] print(ans if anstoReal() ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cost : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ INF }, N))) ; var to : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, M) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; cost[a+1][b+1] := c ; (expr (atom (name to)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var K : int := 1 * (2->pow(N)) ; var dp : Sequence := Integer.subrange(0, K-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ INF }, N))) ; dp[K - 1+1]->first() := 0 ; for bit : Integer.subrange(-1 + 1, K - 1)->reverse() do ( for i : Integer.subrange(0, N-1) do ( var tmp : Sequence := to[i+1]->select(j | MathLib.bitwiseAnd(bit /(2->pow(j)), 1) = 0)->collect(j | (dp[MathLib.bitwiseOr(bit, 1 * (2->pow(j)))+1][j+1] + cost[j+1][i+1])) ; if tmp then ( var dist : OclAny := (tmp)->min() ; if (dp[bit+1][i+1]->compareTo(dist)) > 0 then ( dp[bit+1][i+1] := dist ) else skip ) else skip)) ; var ans : OclAny := dp->first()->first() ; execute (if (ans->compareTo(INF)) < 0 then ans else -1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def memoize(f): table={} def func(*args): if not args in table : table[args]=f(*args) return table[args] return func @ memoize def tsp(p,v): if(1<collect( _x | (OclType["int"])->apply(_x) ) ; var distance_table : Sequence := Integer.subrange(0, point_size-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ ("" + (('inf')))->toReal() }, point_size))) ; for _anon : Integer.subrange(0, e-1) do ( var s : OclAny := null; var t : OclAny := null; var d : OclAny := null; Sequence{s,t,d} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; distance_table[s+1][t+1] := d) ; var ans : OclAny := tsp(0, 1) ; execute (if isinf(ans) then -1 else ans endif)->display(); operation memoize(f : OclAny) : OclAny pre: true post: true activity: var table : OclAny := Set{} ; skip ; return func; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,radians from itertools import accumulate,permutations,combinations,product from operator import itemgetter,mul from copy import deepcopy from string import ascii_lowercase,ascii_uppercase,digits from bisect import bisect,bisect_left from fractions import gcd from heapq import heappush,heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) def ZIP(n): return zip(*(MAP()for _ in range(n))) sys.setrecursionlimit(10**9) INF=float('inf') mod=10**9+7 def main(): V,E=MAP() graph=[[]for _ in range(V)] for _ in range(E): s,t,d=MAP() graph[s].append((t,d)) dp=[[INF]*V for _ in range(1<>to)& 1): dp[S][v]=min(dp[S][v],dp[S | 1<pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ZIP(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))`third->at(_indx)} ); operation main() pre: true post: true activity: var V : OclAny := null; var E : OclAny := null; Sequence{V,E} := MAP() ; var graph : Sequence := Integer.subrange(0, V-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, E-1) do ( var s : OclAny := null; var t : OclAny := null; var d : OclAny := null; Sequence{s,t,d} := MAP() ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name t)))))) , (test (logical_test (comparison (expr (atom (name d))))))) )))))))) ))))) ; var dp : Sequence := Integer.subrange(0, 1 * (2->pow(V))-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ INF }, V))) ; dp[(1 * (2->pow(V))) - 1+1]->first() := 0 ; for S : Integer.subrange(-1 + 1, (1 * (2->pow(V))) - 2)->reverse() do ( for v : Integer.subrange(0, V-1) do ( for _tuple : graph[v+1] do (var _indx : int := 1; var to : OclAny := _tuple->at(_indx); _indx := _indx + 1; var cost : OclAny := _tuple->at(_indx); if not((MathLib.bitwiseAnd((S /(2->pow(to))), 1))) then ( dp[S+1][v+1] := Set{dp[S+1][v+1], dp[MathLib.bitwiseOr(S, 1 * (2->pow(to)))+1][to+1] + cost}->min() ) else skip))) ; if dp->first()->first() /= INF then ( execute (dp->first()->first())->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) a=list(map(int,input().split())) if n % 2==0 : print('0') else : print(min(m//(n//2+1)*k,min(a[: : 2]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n mod 2 = 0 then ( execute ('0')->display() ) else ( execute (Set{m div (n div 2 + 1) * k, (a(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->min()}->min())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict v,e=map(int,input().split()) links=[set()for _ in range(v)] bests=[None]*(1<collect( _x | (OclType["int"])->apply(_x) ) ; var links : Sequence := Integer.subrange(0, v-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; var bests : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (1 * (2->pow(v)))) ; for _anon : Integer.subrange(0, e-1) do ( var s : OclAny := null; var t : OclAny := null; var d : OclAny := null; Sequence{s,t,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name links)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name t)))))) , (test (logical_test (comparison (expr (atom (name d))))))) )))))))) ))))) ; bests->first() := Map{ 0 |-> 0 } ; for _tuple : Integer.subrange(1, (bests)->size())->collect( _indx | Sequence{_indx-1, (bests)->at(_indx)} ) do (var _indx : int := 1; var visited : OclAny := _tuple->at(_indx); _indx := _indx + 1; var best : OclAny := _tuple->at(_indx); if best <>= null then ( continue ) else skip ; for _tuple : best->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var last : OclAny := _tuple->at(_indx); _indx := _indx + 1; var cost : OclAny := _tuple->at(_indx); for _tuple : links[last+1] do (var _indx : int := 1; var t : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); var new_visited : int := MathLib.bitwiseOr(visited, (1 * (2->pow(t)))) ; if visited = new_visited then ( continue ) else skip ; var new_best : OclAny := bests[new_visited+1] ; if new_best <>= null then ( bests[new_visited+1] := defaultdict(lambda $$ : OclAny in (15001), Sequence{ Sequence{t, cost + d} }) ) else ( new_best[t+1] := Set{new_best[t+1], cost + d}->min() )))) ; var result : OclAny := bests->last() ; execute (if result <>= null then -1 else if result->first() = 15001 then -1 else result->first() endif endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools,queue sys.setrecursionlimit(10**7) INF=20000 EPS=1.0/10**10 MOD=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] n,e=LI() dist=[[INF for _ in range(n)]for _ in range(n)] for _ in range(e): a,b,c=LI() dist[a][b]=c dp=[[INF for _ in range(n)]for _ in range(1<pow(7)) ; var INF : int := 20000 ; var EPS : double := 1.0 / (10)->pow(10) ; var MOD : double := (10)->pow(9) + 7 ; skip ; var n : OclAny := null; var e : OclAny := null; Sequence{n,e} := LI() ; var dist : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (INF)))) ; for _anon : Integer.subrange(0, e-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := LI() ; dist[a+1][b+1] := c) ; var dp : Sequence := Integer.subrange(0, 1 * (2->pow(n))-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (INF)))) ; var q : OclAny := queue.Queue() ; for i : Integer.subrange(1, n-1) do ( if (dist->first()[i+1]->compareTo(INF)) < 0 then ( dp[MathLib.bitwiseOr(1, (1 * (2->pow(i))))+1][i+1] := dist->first()[i+1] ; q.put(Sequence{MathLib.bitwiseOr(1, (1 * (2->pow(i)))), i}) ) else skip) ; while not(q.empty()) do ( var bit : OclAny := null; var v : OclAny := null; Sequence{bit,v} := q.get() ; for u : Integer.subrange(1, n-1) do ( if (dist[v+1][u+1]->compareTo(INF)) < 0 & not((MathLib.bitwiseAnd(bit, (1 * (2->pow(u)))))) then ( var next_bit : int := MathLib.bitwiseOr(bit, (1 * (2->pow(u)))) ; if dp[next_bit+1][u+1] = INF then ( q.put(Sequence{next_bit, u}) ) else skip ; dp[next_bit+1][u+1] := Set{dp[next_bit+1][u+1], dp[bit+1][v+1] + dist[v+1][u+1]}->min() ) else skip)) ; var ans : int := INF ; for i : Integer.subrange(1, n-1) do ( ans := Set{ans, dp[(1 * (2->pow(n))) - 1+1][i+1] + dist[i+1]->first()}->min()) ; if (ans->compareTo(INF)) < 0 then ( execute (ans)->display() ) else ( execute (-1)->display() ); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x,y=map(int,input().split()) if(n<=y and(y-n+1)**2+n-1>=x): for i in range(n-1): print(1) print(y-n+1) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if ((n->compareTo(y)) <= 0 & (((y - n + 1))->pow(2) + n - 1->compareTo(x)) >= 0) then ( for i : Integer.subrange(0, n - 1-1) do ( execute (1)->display()) ; execute (y - n + 1)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_v,num_e=input().split() edges=[] verticies=[] for i in range(int(num_e)): v,u,w=input().split() e=(v,u,int(w)) edges.append(e) for v in range(int(num_v)): v=str(v) verticies.append(v) graph={'verticies' : verticies,'edges' : edges} parent={} g_len={} def group(v): parent[v]=v g_len[v]=0 def my_parent(v): if parent[v]!=v : parent[v]=my_parent(parent[v]) return parent[v] def union(v,u): g_v=my_parent(v) g_u=my_parent(u) if g_v!=g_u : if g_len[g_v]>=g_len[g_u]: parent[g_u]=parent[g_v] g_len[g_v]+=1 else : parent[g_v]=parent[g_u] g_len[g_u]+=1 def kruskal(graph): g_list=[] sum_w=0 for v in graph['verticies']: group(v) edges=graph['edges'] edges.sort(key=lambda edges : edges[2]) for edge in edges : v,u,weight=edge if my_parent(v)!=my_parent(u): union(v,u) g_list.append(edge) sum_w=sum_w+weight return sum_w print(kruskal(graph)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_v : OclAny := null; var num_e : OclAny := null; Sequence{num_v,num_e} := input().split() ; var edges : Sequence := Sequence{} ; var verticies : Sequence := Sequence{} ; for i : Integer.subrange(0, ("" + ((num_e)))->toInteger()-1) do ( var v : OclAny := null; var u : OclAny := null; var w : OclAny := null; Sequence{v,u,w} := input().split() ; var e : OclAny := Sequence{v, u, ("" + ((w)))->toInteger()} ; execute ((e) : edges)) ; for v : Integer.subrange(0, ("" + ((num_v)))->toInteger()-1) do ( var v : String := ("" + ((v))) ; execute ((v) : verticies)) ; var graph : Map := Map{ 'verticies' |-> verticies }->union(Map{ 'edges' |-> edges }) ; var parent : OclAny := Set{} ; var g_len : OclAny := Set{} ; skip ; skip ; skip ; skip ; execute (kruskal(graph))->display(); operation group(v : OclAny) pre: true post: true activity: parent->at(v) := v ; g_len->at(v) := 0; operation my_parent(v : OclAny) : OclAny pre: true post: true activity: if parent->at(v) /= v then ( parent->at(v) := my_parent(parent->at(v)) ) else skip ; return parent->at(v); operation union(v : OclAny, u : OclAny) pre: true post: true activity: var g_v : OclAny := my_parent(v) ; var g_u : OclAny := my_parent(u) ; if g_v /= g_u then ( if (g_len[g_v+1]->compareTo(g_len[g_u+1])) >= 0 then ( parent[g_u+1] := parent[g_v+1] ; g_len[g_v+1] := g_len[g_v+1] + 1 ) else ( parent[g_v+1] := parent[g_u+1] ; g_len[g_u+1] := g_len[g_u+1] + 1 ) ) else skip; operation kruskal(graph : OclAny) : OclAny pre: true post: true activity: var g_list : Sequence := Sequence{} ; var sum_w : int := 0 ; for v : graph->at('verticies') do ( group(v)) ; edges := graph->at('edges') ; edges := edges->sort() ; for edge : edges do ( var weight : OclAny := null; Sequence{v,u,weight} := edge ; if my_parent(v) /= my_parent(u) then ( union(v, u) ; execute ((edge) : g_list) ; sum_w := sum_w + weight ) else skip) ; return sum_w; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.buffer.readline()[:-1].decode('utf-8') sys.setrecursionlimit(10**8) inf=float('inf') mod=10**9+7 class UnionFind : __slots__=['id','sz'] def __init__(self,n): self.id=[-1]*n self.sz=n def root(self,x): if self.id[x]<0 : return x else : self.id[x]=self.root(self.id[x]) return self.id[x] def find(self,x,y): return self.root(x)==self.root(y) def union(self,x,y): s1,s2=self.root(x),self.root(y) if s1!=s2 : if self.id[s1]<=self.id[s2]: self.id[s1]+=self.id[s2] self.id[s2]=s1 else : self.id[s2]+=self.id[s1] self.id[s1]=s2 self.sz-=1 return True return False V,E=map(int,input().split()) uf=UnionFind(V) ans=0 stw=[list(map(int,input().split()))for i in range(E)] stw.sort(key=lambda tup : tup[2]) for s,t,w in stw : if not uf.find(s,t): uf.union(s,t) ans+=w print(ans) ------------------------------------------------------------ OCL File: --------- class UnionFind { static operation newUnionFind() : UnionFind pre: true post: UnionFind->exists( _x | result = _x ); static attribute __slots__ : Sequence := Sequence{'id'}->union(Sequence{ 'sz' }); attribute id : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n); attribute sz : OclAny := n; operation initialise(n : OclAny) : UnionFind pre: true post: true activity: self.id := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; self.sz := n; return self; operation root(x : OclAny) : OclAny pre: true post: true activity: if self.id[x+1] < 0 then ( return x ) else ( self.id[x+1] := self.root(self.id[x+1]) ; return self.id[x+1] ); operation find(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: return self.root(x) = self.root(y); operation union(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: var s1 : OclAny := null; var s2 : OclAny := null; Sequence{s1,s2} := Sequence{self.root(x),self.root(y)} ; if s1 /= s2 then ( if (self.id[s1+1]->compareTo(self.id[s2+1])) <= 0 then ( self.id[s1+1] := self.id[s1+1] + self.id[s2+1] ; self.id[s2+1] := s1 ) else ( self.id[s2+1] := self.id[s2+1] + self.id[s1+1] ; self.id[s1+1] := s2 ) ; self.sz := self.sz - 1 ; return true ) else skip ; return false; } class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.buffer.readLine()->front().decode('utf-8')) ; sys.setrecursionlimit((10)->pow(8)) ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; skip ; var V : OclAny := null; var E : OclAny := null; Sequence{V,E} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var uf : UnionFind := (UnionFind.newUnionFind()).initialise(V) ; var ans : int := 0 ; var stw : Sequence := Integer.subrange(0, E-1)->select(i | true)->collect(i | (((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; stw := stw->sort() ; for _tuple : stw do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); _indx := _indx + 1; var w : OclAny := _tuple->at(_indx); if not(uf->indexOf(s, t) - 1) then ( uf.union(s, t) ; ans := ans + w ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,collections sys.setrecursionlimit(10000) INF=float("inf") V,E=map(int,sys.stdin.readline().split()) stw=tuple(tuple(map(int,sys.stdin.readline().rstrip().split()))for _ in range(E)) wst=[[w,s,t]for s,t,w in stw] wst.sort() parents=list(range(V)) def find(x): while parents[x]!=x : x=parents[x] parents[x]=parents[parents[x]] return x def union(s,t): sp=find(s) tp=find(t) if sp==tp : pass elif sptoReal() ; var V : OclAny := null; var E : OclAny := null; Sequence{V,E} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var stw : Sequence := ((argument (test (logical_test (comparison (expr (atom (name tuple)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin)) (trailer . (name readline) (arguments ( ))) (trailer . (name rstrip) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name E)))))))) ))))))))) ; var wst : Sequence := stw->select(_tuple | true)->collect(_tuple | let s : OclAny = _tuple->at(1) in let t : OclAny = _tuple->at(2) in (Sequence{w}->union(Sequence{s}->union(Sequence{ t })))) ; wst := wst->sort() ; var parents : Sequence := (Integer.subrange(0, V-1)) ; skip ; skip ; INF := ("" + (("inf")))->toReal() ; var ret : int := 0 ; for _tuple : wst do (var _indx : int := 1; var w : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); if find(s) /= find(t) then ( union(s, t) ; ret := ret + w ) else skip) ; execute (ret)->display(); operation find(x : OclAny) : OclAny pre: true post: true activity: while parents[x+1] /= x do ( x := parents[x+1] ; parents[x+1] := parents[parents[x+1]+1]) ; return x; operation union(s : OclAny, t : OclAny) pre: true post: true activity: var sp : OclAny := find(s) ; var tp : OclAny := find(t) ; if sp = tp then ( skip ) else (if (sp->compareTo(tp)) < 0 then ( parents[sp+1] := tp ) else ( parents[tp+1] := sp ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline from collections import defaultdict MAX=10000 infty=-1 class Disjoint(): def __init__(): return def getRoot(x): global v for _ in range(v+1): if dic[x]["parent"]==x : return x x=dic[x]["parent"] def unite(x,y): r=getRoot(x) l=getRoot(y) a=dic[r]["rank"] b=dic[l]["rank"] if a==b : dic[r]["rank"]+=1 dic[l]["parent"]=r elif a>b : dic[l]["rank"]=0 dic[l]["parent"]=r elif aexists( _x | result = _x ); static operation __init__() pre: true post: true activity: return; } class FromPython { attribute v : OclAny; operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; skip ; var MAX : int := 10000 ; var infty : int := -1 ; skip ; skip ; skip ; var lines : OclAny := stdin.readlines() ; var dic : OclAny := defaultdict() ; var e : OclAny := null; Sequence{v,e} := (lines->first().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var E : Sequence := Integer.subrange(0, e-1)->select(i | true)->collect(i | (((lines[i + 1+1].split())->collect( _x | (OclType["int"])->apply(_x) )))) ; E := E->sortedBy($x | (lambda x : OclAny in (x[2+1]))->apply($x)) ; E := E->sortedBy($x | (lambda x : OclAny in (x[2+1]))->apply($x)) ; for _anon : Integer.subrange(0, v-1) do ( dic[_anon+1] := Map{ "rank" |-> 0 }->union(Map{ "parent" |-> _anon })) ; var k : int := 0 ; var total : int := 0 ; for edge : E do ( if getRoot(edge->first()) /= getRoot(edge[1+1]) then ( unite(edge->first(), edge[1+1]) ; k := k + 1 ; total := total + edge[2+1] ) else skip) ; execute (total)->display(); operation getRoot(x : OclAny) : OclAny pre: true post: true activity: skip ; for _anon : Integer.subrange(0, v + 1-1) do ( if dic[x+1]->at("parent") = x then ( return x ) else skip ; x := dic[x+1]->at("parent")); operation unite(x : OclAny, y : OclAny) pre: true post: true activity: var r : OclAny := getRoot(x) ; var l : OclAny := getRoot(y) ; var a : OclAny := dic[r+1]->at("rank") ; var b : OclAny := dic[l+1]->at("rank") ; if a = b then ( dic[r+1]->at("rank") := dic[r+1]->at("rank") + 1 ; dic[l+1]->at("parent") := r ) else (if (a->compareTo(b)) > 0 then ( dic[l+1]->at("rank") := 0 ; dic[l+1]->at("parent") := r ) else (if (a->compareTo(b)) < 0 then ( dic[r+1]->at("rank") := 0 ; dic[r+1]->at("parent") := l ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class UnionFind : def __init__(self,size): self.parent=range(size) self.rank=[0]*size def findset(self,x): if self.parent[x]==x : return x else : self.parent[x]=self.findset(self.parent[x]) return self.parent[x] def unite(self,x,y): x=self.findset(x) y=self.findset(y) if x==y : return if self.rank[x]exists( _x | result = _x ); attribute parent : Sequence := Integer.subrange(0, size-1); attribute rank : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, size); operation initialise(size : OclAny) : UnionFind pre: true post: true activity: self.parent := Integer.subrange(0, size-1) ; self.rank := MatrixLib.elementwiseMult(Sequence{ 0 }, size); return self; operation findset(x : OclAny) : OclAny pre: true post: true activity: if self.parent[x+1] = x then ( return x ) else ( self.parent[x+1] := self.findset(self.parent[x+1]) ; return self.parent[x+1] ); operation unite(x : OclAny,y : OclAny) pre: true post: true activity: x := self.findset(x) ; y := self.findset(y) ; if x = y then ( return ) else skip ; if (self.rank[x+1]->compareTo(self.rank[y+1])) < 0 then ( self.parent[x+1] := y ) else ( self.parent[y+1] := x ; if self.rank[x+1] = self.rank[y+1] then ( self.rank[x+1] := self.rank[x+1] + 1 ) else skip ); operation same(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: if self.findset(x) = self.findset(y) then ( return true ) else ( return false ); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{n,m} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; edges := Sequence{} ; for i : xrange(m) do ( var s : OclAny := null; var t : OclAny := null; var w : OclAny := null; Sequence{s,t,w} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{w}->union(Sequence{s}->union(Sequence{ t }))) : edges)) ; execute (kruskal(n, m, edges))->display(); operation kruskal(n : OclAny, m : OclAny, edges : OclAny) : OclAny pre: true post: true activity: edges := edges->sort() ; var node : UnionFind := (UnionFind.newUnionFind()).initialise(n) ; var ret : int := 0 ; for i : xrange(m) do ( var cost : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{cost,a,b} := Sequence{edges[i+1]->first(),edges[i+1][1+1],edges[i+1][2+1]} ; if node.same(a, b) then ( continue ) else ( ret := ret + cost ; node.unite(a, b) )) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- last=31 def findSubset(temp,k): global last ans=[] for i in range(last,-1,-1): cnt=0 for it in temp : bit=it &(1<0): cnt+=1 if(cnt>=k): for it in temp : bit=it &(1<0): ans.append(it) last=i-1 return ans return ans def findMaxiumAnd(a,n,k): global last temp1,temp2,=[],[] for i in range(n): temp2.append(a[i]) while len(temp2)>=k : temp1=temp2 temp2=findSubset(temp2,k) ans=temp1[0] for i in range(k): ans=ans & temp1[i] return ans a=[255,127,31,5,24,37,15] n=len(a) k=4 print(findMaxiumAnd(a,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute last : OclAny; attribute last : OclAny; operation initialise() pre: true post: true activity: var last : int := 31 ; skip ; skip ; a := Sequence{255}->union(Sequence{127}->union(Sequence{31}->union(Sequence{5}->union(Sequence{24}->union(Sequence{37}->union(Sequence{ 15 })))))) ; n := (a)->size() ; k := 4 ; execute (findMaxiumAnd(a, n, k))->display(); operation findSubset(temp : OclAny, k : OclAny) : OclAny pre: true post: true activity: skip ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(-1 + 1, last)->reverse() do ( var cnt : int := 0 ; for it : temp do ( var bit : int := MathLib.bitwiseAnd(it, (1 * (2->pow(i)))) ; if (bit > 0) then ( cnt := cnt + 1 ) else skip) ; if ((cnt->compareTo(k)) >= 0) then ( for it : temp do ( bit := MathLib.bitwiseAnd(it, (1 * (2->pow(i)))) ; if (bit > 0) then ( execute ((it) : ans) ) else skip) ; last := i - 1 ; return ans ) else skip) ; return ans; operation findMaxiumAnd(a : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: skip ; var temp1 : OclAny := null; (declareIfNecessary (test (logical_test (comparison (expr (atom (name temp2)))))) ,) Sequence{temp1,(testlist_star_expr (test (logical_test (comparison (expr (atom (name temp2)))))) ,)} := Sequence{Sequence{},Sequence{}} ; for i : Integer.subrange(0, n-1) do ( execute ((a[i+1]) : temp2)) ; while ((temp2)->size()->compareTo(k)) >= 0 do ( var temp1 : OclAny := temp2 ; var temp2 : OclAny := findSubset(temp2, k)) ; ans := temp1->first() ; for i : Integer.subrange(0, k-1) do ( ans := MathLib.bitwiseAnd(ans, temp1[i+1])) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : sorted(map(int,input().split())) exec(R()[0]*'R();print(*R()+R());') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort()) ; (expr (expr (atom (name R)) (trailer (arguments ( ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) * (expr (atom 'R();print(*R()+R());'))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) A=sorted(list(map(int,input().split()))) B=sorted(list(map(int,input().split()))) print(*A) print(*B) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var B : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; execute ((argument * (test (logical_test (comparison (expr (atom (name A))))))))->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name B))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin n,m,k=[int(x)for x in stdin.readline().split()] d=[int(x)for x in stdin.readline().split()] splitD=[x for x in d[: : 2]] if n==1 : print(min(d[0],k*m)) elif n==2 : print(0) elif d[0]==0 or d[-1]==0 : print(0) elif n % 2==0 : print(0) else : if m>=n//2+1 : times=m//(n//2+1) print(min(times*k,min(splitD))) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var d : Sequence := stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var splitD : Sequence := d(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->select(x | true)->collect(x | (x)) ; if n = 1 then ( execute (Set{d->first(), k * m}->min())->display() ) else (if n = 2 then ( execute (0)->display() ) else (if d->first() = 0 or d->last() = 0 then ( execute (0)->display() ) else (if n mod 2 = 0 then ( execute (0)->display() ) else ( if (m->compareTo(n div 2 + 1)) >= 0 then ( var times : int := m div (n div 2 + 1) ; execute (Set{times * k, (splitD)->min()}->min())->display() ) else ( execute (0)->display() ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): input() a=list(map(int,input().split(' '))) b=list(map(int,input().split(' '))) a.sort() b.sort() print(' '.join(str(x)for x in a)) print(' '.join(str(x)for x in b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( input() ; var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; b := b->sort() ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a)))))))), ' '))->display() ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name b)))))))), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x,y=map(int,input().split()) n-=1 t=y-n print(['1\n'*n+str(t),-1][t<1 or t*t+ncollect( _x | (OclType["int"])->apply(_x) ) ; n := n - 1 ; var t : double := y - n ; execute (Sequence{StringLib.nCopies('1 ', n) + ("" + ((t)))}->union(Sequence{ -1 })->select(t < 1 or (t * t + n->compareTo(x)) < 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solution(n,a,b): sa="" a.sort() for e in a : sa+=str(e)+"" sb="" b.sort() for e in b : sb+=str(e)+"" return[sa.strip(),sb.strip()] t=int(input()) while t : n=int(input()) a=[int(x)for x in input().strip().split("")] b=[int(x)for x in input().strip().split("")] ans=solution(n,a,b) print(ans[0]) print(ans[1]) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := input()->trim().split("")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; b := input()->trim().split("")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : OclAny := solution(n, a, b) ; execute (ans->first())->display() ; execute (ans[1+1])->display() ; t := t - 1); operation solution(n : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var sa : String := "" ; a := a->sort() ; for e : a do ( sa := sa + ("" + ((e))) + "") ; var sb : String := "" ; b := b->sort() ; for e : b do ( sb := sb + ("" + ((e))) + "") ; return Sequence{sa->trim()}->union(Sequence{ sb->trim() }); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) nek=list(map(int,input().split())) brc=list(map(int,input().split())) nek.sort() brc.sort() print(*nek) print(*brc) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nek : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var brc : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; nek := nek->sort() ; brc := brc->sort() ; execute ((argument * (test (logical_test (comparison (expr (atom (name nek))))))))->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name brc))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkConcurrent(a1,b1,c1,a2,b2,c2,a3,b3,c3): return(a3*(b1*c2-b2*c1)+b3*(c1*a2-c2*a1)+c3*(a1*b2-a2*b1)==0) a1=2 b1=-3 c1=5 a2=3 b2=4 c2=-7 a3=9 b3=-5 c3=8 if(checkConcurrent(a1,b1,c1,a2,b2,c2,a3,b3,c3)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a1 := 2 ; b1 := -3 ; c1 := 5 ; a2 := 3 ; b2 := 4 ; c2 := -7 ; a3 := 9 ; b3 := -5 ; c3 := 8 ; if (checkConcurrent(a1, b1, c1, a2, b2, c2, a3, b3, c3)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation checkConcurrent(a1 : OclAny, b1 : OclAny, c1 : OclAny, a2 : OclAny, b2 : OclAny, c2 : OclAny, a3 : OclAny, b3 : OclAny, c3 : OclAny) : OclAny pre: true post: true activity: return (a3 * (b1 * c2 - b2 * c1) + b3 * (c1 * a2 - c2 * a1) + c3 * (a1 * b2 - a2 * b1) = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sameSetBits(arr,n): v=[] for i in range(0,n,1): v.append(bin(arr[i]).count('1')) current_count=1 max_count=1 for i in range(1,len(v)-1,1): if(v[i+1]==v[i]): current_count+=1 else : current_count=1 max_count=max(max_count,current_count) return max_count if __name__=='__main__' : arr=[9,75,14,7,13,11] n=len(arr) print(sameSetBits(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{9}->union(Sequence{75}->union(Sequence{14}->union(Sequence{7}->union(Sequence{13}->union(Sequence{ 11 }))))) ; n := (arr)->size() ; execute (sameSetBits(arr, n))->display() ) else skip; operation sameSetBits(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var v : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( execute ((bin(arr[i+1])->count('1')) : v)) ; var current_count : int := 1 ; var max_count : int := 1 ; for i : Integer.subrange(1, (v)->size() - 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if (v[i + 1+1] = v[i+1]) then ( current_count := current_count + 1 ) else ( current_count := 1 ) ; max_count := Set{max_count, current_count}->max()) ; return max_count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def value(x): return(ord(x)-ord('a')) def maximumProduct(strr,n): answer="" curr="" maxProduct=0 product=1 for i in range(n): product*=value(strr[i]) curr+=strr[i] if(product>=maxProduct): maxProduct=product answer=curr if(product==0): product=1 curr="" return answer if __name__=='__main__' : strr="sdtfakdhdahdzz" n=len(strr) print(maximumProduct(strr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( strr := "sdtfakdhdahdzz" ; n := (strr)->size() ; execute (maximumProduct(strr, n))->display() ) else skip; operation value(x : OclAny) : OclAny pre: true post: true activity: return ((x)->char2byte() - ('a')->char2byte()); operation maximumProduct(strr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var answer : String := "" ; var curr : String := "" ; var maxProduct : int := 0 ; var product : int := 1 ; for i : Integer.subrange(0, n-1) do ( product := product * value(strr[i+1]) ; curr := curr + strr[i+1] ; if ((product->compareTo(maxProduct)) >= 0) then ( maxProduct := product ; answer := curr ) else skip ; if (product = 0) then ( product := 1 ; curr := "" ) else skip) ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- hi=[[0 for j in range(51)]for i in range(51)] W,H,T=map(int,input().split()) P=int(input()) for i in range(P): x,y,t=map(int,input().split()) hi[x][y]+=1 ans=0 ; for y in range(H): v=list(map(int,input().split())) for x in range(W): if v[x]: ans+=hi[x][y] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var hi : Sequence := Integer.subrange(0, 51-1)->select(i | true)->collect(i | (Integer.subrange(0, 51-1)->select(j | true)->collect(j | (0)))) ; var W : OclAny := null; var H : OclAny := null; var T : OclAny := null; Sequence{W,H,T} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var P : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, P-1) do ( var x : OclAny := null; var y : OclAny := null; var t : OclAny := null; Sequence{x,y,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; hi[x+1][y+1] := hi[x+1][y+1] + 1) ; var ans : int := 0; ; for y : Integer.subrange(0, H-1) do ( var v : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for x : Integer.subrange(0, W-1) do ( if v[x+1] then ( ans := ans + hi[x+1][y+1] ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools import math def main(): w,h,t=map(int,input().split()) p=int(input()) fert=[] for _ in range(p): x,y,_=map(int,input().split()) fert.append((y,x)) stage=[list(map(int,input().split()))for _ in range(h)] for r,c in itertools.product(range(h),range(w)): if stage[r][c]==0 : stage[r][c]=float("inf") elif stage[r][c]==1 : stage[r][c]=0 for r,c in fert : stage[r][c]+=1 ans=sum(sum(filter(lambda x : x!=float("inf"),row))for row in stage) print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var w : OclAny := null; var h : OclAny := null; var t : OclAny := null; Sequence{w,h,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var fert : Sequence := Sequence{} ; for _anon : Integer.subrange(0, p-1) do ( var x : OclAny := null; var y : OclAny := null; var _anon : OclAny := null; Sequence{x,y,_anon} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{y, x}) : fert)) ; var stage : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for _tuple : itertools.product(Integer.subrange(0, h-1), Integer.subrange(0, w-1)) do (var _indx : int := 1; var r : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if stage[r+1][c+1] = 0 then ( stage[r+1][c+1] := ("" + (("inf")))->toReal() ) else (if stage[r+1][c+1] = 1 then ( stage[r+1][c+1] := 0 ) else skip)) ; for _tuple : fert do (var _indx : int := 1; var r : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); stage[r+1][c+1] := stage[r+1][c+1] + 1) ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name filter)) (trailer (arguments ( (arglist (argument (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (comparison (expr (atom (name x)))) != (comparison (expr (atom (name float)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "inf"))))))) )))))))))) , (argument (test (logical_test (comparison (expr (atom (name row)))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name row)))) in (logical_test (comparison (expr (atom (name stage))))))))->sum() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w,h,t=map(int,input().split()) p=int(input()) hiryo=[] for i in range(p): x,y,t=list(map(int,input().split())) hiryo.append([x,y,t]) hatake=[[0 for i in range(w)]for j in range(h)] hatake_boolean=[] for i in range(h): row=list(map(int,input().split())) row_boolean=[] for j in row : if j : row_boolean.append(True) else : row_boolean.append(False) hatake_boolean.append(row_boolean) for i in range(p): x,y,t=hiryo[i] if hatake_boolean[y][x]: hatake[y][x]+=1 ans=0 for row in hatake : ans+=sum(row) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : OclAny := null; var h : OclAny := null; var t : OclAny := null; Sequence{w,h,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var hiryo : Sequence := Sequence{} ; for i : Integer.subrange(0, p-1) do ( var x : OclAny := null; var y : OclAny := null; var t : OclAny := null; Sequence{x,y,t} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((Sequence{x}->union(Sequence{y}->union(Sequence{ t }))) : hiryo)) ; var hatake : Sequence := Integer.subrange(0, h-1)->select(j | true)->collect(j | (Integer.subrange(0, w-1)->select(i | true)->collect(i | (0)))) ; var hatake_boolean : Sequence := Sequence{} ; for i : Integer.subrange(0, h-1) do ( var row : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var row_boolean : Sequence := Sequence{} ; for j : row do ( if j then ( execute ((true) : row_boolean) ) else ( execute ((false) : row_boolean) )) ; execute ((row_boolean) : hatake_boolean)) ; for i : Integer.subrange(0, p-1) do ( var x : OclAny := null; var y : OclAny := null; var t : OclAny := null; Sequence{x,y,t} := hiryo[i+1] ; if hatake_boolean[y+1][x+1] then ( hatake[y+1][x+1] := hatake[y+1][x+1] + 1 ) else skip) ; var ans : int := 0 ; for row : hatake do ( ans := ans + (row)->sum()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w,h,t=map(int,input().split()) p=int(input()) c=[tuple(map(int,input().split()))for _ in range(p)] area=[tuple(map(int,input().split()))for _ in range(h)] print(sum([area[i[1]][i[0]]for i in c])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : OclAny := null; var h : OclAny := null; var t : OclAny := null; Sequence{w,h,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : Sequence := Integer.subrange(0, p-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var area : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; execute ((c->select(i | true)->collect(i | (area[i[1+1]+1][i->first()+1])))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- L,N=map(int,input().split()) snake=input() cnt=0 for i in range(L-1): if snake[i : i+2]=='oo' : cnt+=1 for i in range(N): L+=cnt*3 cnt*=2 print(L) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var L : OclAny := null; var N : OclAny := null; Sequence{L,N} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var snake : String := (OclFile["System.in"]).readLine() ; var cnt : int := 0 ; for i : Integer.subrange(0, L - 1-1) do ( if snake.subrange(i+1, i + 2) = 'oo' then ( cnt := cnt + 1 ) else skip) ; for i : Integer.subrange(0, N-1) do ( L := L + cnt * 3 ; cnt := cnt * 2) ; execute (L)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x,y=map(int,input().split()) if x<=(n-1)+(y-(n-1))**2 and y>=(n-1)+(y-(n-1))and(y-(n-1))>0 : for i in range(n-1): print(1) print(y-(n-1)) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (x->compareTo((n - 1) + ((y - (n - 1)))->pow(2))) <= 0 & (y->compareTo((n - 1) + (y - (n - 1)))) >= 0 & (y - (n - 1)) > 0 then ( for i : Integer.subrange(0, n - 1-1) do ( execute (1)->display()) ; execute (y - (n - 1))->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w,h,t=map(int,input().split()) c=[tuple(map(int,input().split()))for _ in range(int(input()))] area=[tuple(map(int,input().split()))for _ in range(h)] print(sum([area[i[1]][i[0]]for i in c])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : OclAny := null; var h : OclAny := null; var t : OclAny := null; Sequence{w,h,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : Sequence := Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var area : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; execute ((c->select(i | true)->collect(i | (area[i[1+1]+1][i->first()+1])))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a3=""" aab b.b baa """ a6=""" aabccd b.bd.d baadcc ccdaab d.db.b dccbaa """ g4=""" aaca bbca cabb cacc """ g4=list(map(list,g4.split())) g5=""" aabba bcc.a b..cb a..cb abbaa """ g5=list(map(list,g5.split())) g7=""" caabb.. cb..cc. aba.... a.a..aa c..a..b c..a..b .aaccaa """ g7=list(map(list,g7.split())) def main(): N=int(input()) if N==2 : print(-1) elif N==3 : print("\n".join(a3.split())) elif N==6 : print("\n".join(a6.split())) else : x=[['.']*N for i in range(N)] for v4 in range(N//4+1): for v5 in range((N-v4*4)//5+1): v7=(N-v4*4-v5*5)//7 if v4*4+v5*5+v7*7!=N : continue idx=0 for i in range(v4): for j in range(4): x[idx+j][idx : idx+4]=g4[j] idx+=4 for i in range(v5): for j in range(5): x[idx+j][idx : idx+5]=g5[j] idx+=5 for i in range(v7): for j in range(7): x[idx+j][idx : idx+7]=g7[j] idx+=7 for q in x : print(''.join(q)) return if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a3 : String := (atom "" "\r\naab\r\nb.b\r\nbaa\r\n" "") ; var a6 : String := (atom "" "\r\naabccd\r\nb.bd.d\r\nbaadcc\r\nccdaab\r\nd.db.b\r\ndccbaa\r\n" "") ; var g4 : String := (atom "" "\r\naaca\r\nbbca\r\ncabb\r\ncacc\r\n" "") ; g4 := ((g4.split())->collect( _x | (OclType["Sequence"])->apply(_x) )) ; var g5 : String := (atom "" "\r\naabba\r\nbcc.a\r\nb..cb\r\na..cb\r\nabbaa\r\n" "") ; g5 := ((g5.split())->collect( _x | (OclType["Sequence"])->apply(_x) )) ; var g7 : String := (atom "" "\r\ncaabb..\r\ncb..cc.\r\naba....\r\na.a..aa\r\nc..a..b\r\nc..a..b\r\n.aaccaa\r\n" "") ; g7 := ((g7.split())->collect( _x | (OclType["Sequence"])->apply(_x) )) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 2 then ( execute (-1)->display() ) else (if N = 3 then ( execute (StringLib.sumStringsWithSeparator((a3.split()), "\n"))->display() ) else (if N = 6 then ( execute (StringLib.sumStringsWithSeparator((a6.split()), "\n"))->display() ) else ( var x : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ '.' }, N))) ; for v4 : Integer.subrange(0, N div 4 + 1-1) do ( for v5 : Integer.subrange(0, (N - v4 * 4) div 5 + 1-1) do ( var v7 : int := (N - v4 * 4 - v5 * 5) div 7 ; if v4 * 4 + v5 * 5 + v7 * 7 /= N then ( continue ) else skip ; var idx : int := 0 ; for i : Integer.subrange(0, v4-1) do ( for j : Integer.subrange(0, 4-1) do ( x[idx + j+1].subrange(idx+1, idx + 4) := g4[j+1]) ; idx := idx + 4) ; for i : Integer.subrange(0, v5-1) do ( for j : Integer.subrange(0, 5-1) do ( x[idx + j+1].subrange(idx+1, idx + 5) := g5[j+1]) ; idx := idx + 5) ; for i : Integer.subrange(0, v7-1) do ( for j : Integer.subrange(0, 7-1) do ( x[idx + j+1].subrange(idx+1, idx + 7) := g7[j+1]) ; idx := idx + 7) ; for q : x do ( execute (StringLib.sumStringsWithSeparator((q), ''))->display()) ; return)) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 3==0 : for i in range(n//3): print("a.."*(n//3)) print("a.."*(n//3)) print(".aa"*(n//3)) elif n % 2==0 and n>=4 : x="aacd"+"."*(n-4) y="bbcd"+"."*(n-4) for i in range(n//2): print(x) print(y) x=x[2 :]+x[: 2] y=y[2 :]+y[: 2] elif n>=13 : x="aacd"+"."*(n-13) y="bbcd"+"."*(n-13) for i in range((n-9)//2): print(x+"."*9) print(y+"."*9) x=x[2 :]+x[: 2] y=y[2 :]+y[: 2] for i in range(3): print("."*(n-9)+"a..a..a..") print("."*(n-9)+"a..a..a..") print("."*(n-9)+".aa.aa.aa") elif n==5 : print("aabba") print("bc..a") print("bc..b") print("a.ddb") print("abbaa") elif n==7 : print("aabbcc.") print("dd.dd.a") print("..e..ea") print("..e..eb") print("dd.dd.b") print("..e..ec") print("..e..ec") elif n==11 : print("aabbcc.....") print("dd.dd.a....") print("..e..ea....") print("..e..eb....") print("dd.dd.b....") print("..e..ec....") print("..e..ec....") print(".......aacd") print(".......bbcd") print(".......cdaa") print(".......cdbb") else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 3 = 0 then ( for i : Integer.subrange(0, n div 3-1) do ( execute (StringLib.nCopies("a..", (n div 3)))->display() ; execute (StringLib.nCopies("a..", (n div 3)))->display() ; execute (StringLib.nCopies(".aa", (n div 3)))->display()) ) else (if n mod 2 = 0 & n >= 4 then ( var x : String := "aacd" + StringLib.nCopies(".", (n - 4)) ; var y : String := "bbcd" + StringLib.nCopies(".", (n - 4)) ; for i : Integer.subrange(0, n div 2-1) do ( execute (x)->display() ; execute (y)->display() ; x := x.subrange(2+1) + x.subrange(1,2) ; y := y.subrange(2+1) + y.subrange(1,2)) ) else (if n >= 13 then ( x := "aacd" + StringLib.nCopies(".", (n - 13)) ; y := "bbcd" + StringLib.nCopies(".", (n - 13)) ; for i : Integer.subrange(0, (n - 9) div 2-1) do ( execute (x + StringLib.nCopies(".", 9))->display() ; execute (y + StringLib.nCopies(".", 9))->display() ; x := x.subrange(2+1) + x.subrange(1,2) ; y := y.subrange(2+1) + y.subrange(1,2)) ; for i : Integer.subrange(0, 3-1) do ( execute (StringLib.nCopies(".", (n - 9)) + "a..a..a..")->display() ; execute (StringLib.nCopies(".", (n - 9)) + "a..a..a..")->display() ; execute (StringLib.nCopies(".", (n - 9)) + ".aa.aa.aa")->display()) ) else (if n = 5 then ( execute ("aabba")->display() ; execute ("bc..a")->display() ; execute ("bc..b")->display() ; execute ("a.ddb")->display() ; execute ("abbaa")->display() ) else (if n = 7 then ( execute ("aabbcc.")->display() ; execute ("dd.dd.a")->display() ; execute ("..e..ea")->display() ; execute ("..e..eb")->display() ; execute ("dd.dd.b")->display() ; execute ("..e..ec")->display() ; execute ("..e..ec")->display() ) else (if n = 11 then ( execute ("aabbcc.....")->display() ; execute ("dd.dd.a....")->display() ; execute ("..e..ea....")->display() ; execute ("..e..eb....")->display() ; execute ("dd.dd.b....")->display() ; execute ("..e..ec....")->display() ; execute ("..e..ec....")->display() ; execute (".......aacd")->display() ; execute (".......bbcd")->display() ; execute (".......cdaa")->display() ; execute (".......cdbb")->display() ) else ( execute (-1)->display() ) ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) if N==2 : print(-1) exit() if N==3 : print("""aa. ..b ..b""") exit() P4="""abcc abdd ccab ddab""" P5="""abbaa a..db b..db bcc.a aabba""" P6="""aa.ccd ..bd.d ..bdcc ccdaa. d.d..b dcc..b""" P7=""".ccbbaa c...ccd c...d.d b...dcc bccd... ad.d... adcc...""" P=[P4,P5,P6,P7] def construct(L): P_split=[p.split()for p in P] ans=[] offset=0 for l in L : r=N-offset-l for p in P_split[l-4]: ans.append("."*offset+p+"."*r) offset+=l return "\n".join(ans) def sep(n): if n==6 : return[6] elif n==7 : return[7] elif n==11 : return[5,6] res=[4]*(n//4) for i in range(n % 4): res[i]+=1 return res print(construct(sep(N))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 2 then ( execute (-1)->display() ; exit() ) else skip ; if N = 3 then ( execute ((atom "" "aa.\r\n..b\r\n..b" ""))->display() ; exit() ) else skip ; var P4 : String := (atom "" "abcc\r\nabdd\r\nccab\r\nddab" "") ; var P5 : String := (atom "" "abbaa\r\na..db\r\nb..db\r\nbcc.a\r\naabba" "") ; var P6 : String := (atom "" "aa.ccd\r\n..bd.d\r\n..bdcc\r\nccdaa.\r\nd.d..b\r\ndcc..b" "") ; var P7 : String := (atom "" ".ccbbaa\r\nc...ccd\r\nc...d.d\r\nb...dcc\r\nbccd...\r\nad.d...\r\nadcc..." "") ; var P : Sequence := Sequence{P4}->union(Sequence{P5}->union(Sequence{P6}->union(Sequence{ P7 }))) ; skip ; skip ; execute (construct(sep(N)))->display(); operation construct(L : OclAny) : OclAny pre: true post: true activity: var P_split : Sequence := P->select(p | true)->collect(p | (p.split())) ; var ans : Sequence := Sequence{} ; var offset : int := 0 ; for l : L do ( var r : double := N - offset - l ; for p : P_split[l - 4+1] do ( execute ((StringLib.nCopies(".", offset) + p + StringLib.nCopies(".", r)) : ans)) ; offset := offset + l) ; return StringLib.sumStringsWithSeparator((ans), "\n"); operation sep(n : OclAny) : OclAny pre: true post: true activity: if n = 6 then ( return Sequence{ 6 } ) else (if n = 7 then ( return Sequence{ 7 } ) else (if n = 11 then ( return Sequence{5}->union(Sequence{ 6 }) ) else skip ) ) ; var res : Sequence := MatrixLib.elementwiseMult(Sequence{ 4 }, (n div 4)) ; for i : Integer.subrange(0, n mod 4-1) do ( res[i+1] := res[i+1] + 1) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()); f=["aabbc","hi..c","hi..d","g.jjd","gffee"]; x=list("cdcd"); a=[n*["."]for _ in range(n)]; z={2 :[-1],3 :["abb","a.c","ddc"],5 :["aabbc","hi..c","hi..d","g.jjd","gffee"],7 :["..abc..","..abc..","aax..aa","bbx..bb","cc.yycc","..abc..","..abc.."]} if n in z : print(*z[n]); exit() if n % 2 : for i in range(5): for j in range(5): a[-i-1][-j-1]=f[i][j] n-=5 for i in range(0,n,2): a[i][i],a[i][i+1],a[i+1][i],a[i+1][i+1]=list("aabb") if n % 4 : for i in range(0,n,2): a[i][(i+2)% n],a[i][(i+3)% n],a[i+1][(i+2)% n],a[i+1][(i+3)% n]=x else : for i in range(0,n,2): a[n-i-2][i],a[n-i-2][i+1],a[n-i-1][i],a[n-i-1][i+1]=x for i in a : print("".join(i)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var f : Sequence := Sequence{"aabbc"}->union(Sequence{"hi..c"}->union(Sequence{"hi..d"}->union(Sequence{"g.jjd"}->union(Sequence{ "gffee" })))); var x : Sequence := ("cdcd")->characters(); var a : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ "." }, n))); var z : Map := Map{ 2 |-> Sequence{ -1 } }->union(Map{ 3 |-> Sequence{"abb"}->union(Sequence{"a.c"}->union(Sequence{ "ddc" })) }->union(Map{ 5 |-> Sequence{"aabbc"}->union(Sequence{"hi..c"}->union(Sequence{"hi..d"}->union(Sequence{"g.jjd"}->union(Sequence{ "gffee" })))) }->union(Map{ 7 |-> Sequence{"..abc.."}->union(Sequence{"..abc.."}->union(Sequence{"aax..aa"}->union(Sequence{"bbx..bb"}->union(Sequence{"cc.yycc"}->union(Sequence{"..abc.."}->union(Sequence{ "..abc.." })))))) }))) ; if (z)->includes(n) then ( execute ((argument * (test (logical_test (comparison (expr (atom (name z)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n)))))))) ]))))))))->display(); exit() ) else skip ; if n mod 2 then ( for i : Integer.subrange(0, 5-1) do ( for j : Integer.subrange(0, 5-1) do ( a->reverse()->at(-(-i - 1))->reverse()->at(-(-j - 1)) := f[i+1][j+1])) ; n := n - 5 ) else skip ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( var a[i+1][i+1] : OclAny := null; var a[i+1][i + 1+1] : OclAny := null; var a[i + 1+1][i+1] : OclAny := null; var a[i + 1+1][i + 1+1] : OclAny := null; Sequence{a[i+1][i+1],a[i+1][i + 1+1],a[i + 1+1][i+1],a[i + 1+1][i + 1+1]} := ("aabb")->characters()) ; if n mod 4 then ( for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( var a[i+1][(i + 2) mod n+1] : OclAny := null; var a[i+1][(i + 3) mod n+1] : OclAny := null; var a[i + 1+1][(i + 2) mod n+1] : OclAny := null; var a[i + 1+1][(i + 3) mod n+1] : OclAny := null; Sequence{a[i+1][(i + 2) mod n+1],a[i+1][(i + 3) mod n+1],a[i + 1+1][(i + 2) mod n+1],a[i + 1+1][(i + 3) mod n+1]} := x) ) else ( for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( var a[n - i - 2+1][i+1] : OclAny := null; var a[n - i - 2+1][i + 1+1] : OclAny := null; var a[n - i - 1+1][i+1] : OclAny := null; var a[n - i - 1+1][i + 1+1] : OclAny := null; Sequence{a[n - i - 2+1][i+1],a[n - i - 2+1][i + 1+1],a[n - i - 1+1][i+1],a[n - i - 1+1][i + 1+1]} := x) ) ; for i : a do ( execute (StringLib.sumStringsWithSeparator((i), ""))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) if N==3 : ans=[".aa","b..","b.."] for i in ans : print(i) elif N>=4 : four=["abcc","abdd","hhfg","eefg"] five=["ahhgg","ai..f","bi..f","b.jje","ccdde"] six=["add.ff","a.ce..","bbce..",".ffadd","e..a.c","e..bbc"] seven=[".iijjkk","fadd...","fa.c...","gbbc...","g...add","h...a.c","h...bbc"] ans=[["."]*N for i in range(N)] now=0 while N-now>7 : for i in range(4): for j in range(4): ans[i+now][j+now]=four[i][j] now+=4 if N-now==4 : for i in range(4): for j in range(4): ans[i+now][j+now]=four[i][j] elif N-now==5 : for i in range(5): for j in range(5): ans[i+now][j+now]=five[i][j] elif N-now==6 : for i in range(6): for j in range(6): ans[i+now][j+now]=six[i][j] else : for i in range(7): for j in range(7): ans[i+now][j+now]=seven[i][j] for i in range(N): print("".join(ans[i])) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 3 then ( var ans : Sequence := Sequence{".aa"}->union(Sequence{"b.."}->union(Sequence{ "b.." })) ; for i : ans do ( execute (i)->display()) ) else (if N >= 4 then ( var four : Sequence := Sequence{"abcc"}->union(Sequence{"abdd"}->union(Sequence{"hhfg"}->union(Sequence{ "eefg" }))) ; var five : Sequence := Sequence{"ahhgg"}->union(Sequence{"ai..f"}->union(Sequence{"bi..f"}->union(Sequence{"b.jje"}->union(Sequence{ "ccdde" })))) ; var six : Sequence := Sequence{"add.ff"}->union(Sequence{"a.ce.."}->union(Sequence{"bbce.."}->union(Sequence{".ffadd"}->union(Sequence{"e..a.c"}->union(Sequence{ "e..bbc" }))))) ; var seven : Sequence := Sequence{".iijjkk"}->union(Sequence{"fadd..."}->union(Sequence{"fa.c..."}->union(Sequence{"gbbc..."}->union(Sequence{"g...add"}->union(Sequence{"h...a.c"}->union(Sequence{ "h...bbc" })))))) ; ans := Integer.subrange(0, N-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ "." }, N))) ; var now : int := 0 ; while N - now > 7 do ( for i : Integer.subrange(0, 4-1) do ( for j : Integer.subrange(0, 4-1) do ( ans[i + now+1][j + now+1] := four[i+1][j+1])) ; now := now + 4) ; if N - now = 4 then ( for i : Integer.subrange(0, 4-1) do ( for j : Integer.subrange(0, 4-1) do ( ans[i + now+1][j + now+1] := four[i+1][j+1])) ) else (if N - now = 5 then ( for i : Integer.subrange(0, 5-1) do ( for j : Integer.subrange(0, 5-1) do ( ans[i + now+1][j + now+1] := five[i+1][j+1])) ) else (if N - now = 6 then ( for i : Integer.subrange(0, 6-1) do ( for j : Integer.subrange(0, 6-1) do ( ans[i + now+1][j + now+1] := six[i+1][j+1])) ) else ( for i : Integer.subrange(0, 7-1) do ( for j : Integer.subrange(0, 7-1) do ( ans[i + now+1][j + now+1] := seven[i+1][j+1])) ) ) ) ; for i : Integer.subrange(0, N-1) do ( execute (StringLib.sumStringsWithSeparator((ans[i+1]), ""))->display()) ) else ( execute (-1)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minOperation(S,N,K): if N % K : print("Not Possible") return count=[0]*26 for i in range(0,N): count[ord(S[i])-97]+=1 E=N//K greaterE=[] lessE=[] for i in range(0,26): if count[i]=set1 and len(lessE)>=set2): step1,step2=0,0 for j in range(0,set1): step1+=greaterE[j] for j in range(0,set2): step2+=lessE[j] mi=min(mi,max(step1,step2)) print(mi) if __name__=="__main__" : S="accb" N=len(S) K=2 minOperation(S,N,K) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( S := "accb" ; N := (S)->size() ; K := 2 ; minOperation(S, N, K) ) else skip; operation minOperation(S : OclAny, N : OclAny, K : OclAny) pre: true post: true activity: if N mod K then ( execute ("Not Possible")->display() ; return ) else skip ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for i : Integer.subrange(0, N-1) do ( count[(S[i+1])->char2byte() - 97+1] := count[(S[i+1])->char2byte() - 97+1] + 1) ; var E : int := N div K ; var greaterE : Sequence := Sequence{} ; var lessE : Sequence := Sequence{} ; for i : Integer.subrange(0, 26-1) do ( if (count[i+1]->compareTo(E)) < 0 then ( execute ((E - count[i+1]) : lessE) ) else ( execute ((count[i+1] - E) : greaterE) )) ; greaterE := greaterE->sort() ; lessE := lessE->sort() ; var mi : double := ("" + (('inf')))->toReal() ; for i : Integer.subrange(0, K + 1-1) do ( var set1 : OclAny := null; var set2 : OclAny := null; Sequence{set1,set2} := Sequence{i,K - i} ; if (((greaterE)->size()->compareTo(set1)) >= 0 & ((lessE)->size()->compareTo(set2)) >= 0) then ( var step1 : OclAny := null; var step2 : OclAny := null; Sequence{step1,step2} := Sequence{0,0} ; for j : Integer.subrange(0, set1-1) do ( step1 := step1 + greaterE[j+1]) ; for j : Integer.subrange(0, set2-1) do ( step2 := step2 + lessE[j+1]) ; mi := Set{mi, Set{step1, step2}->max()}->min() ) else skip) ; execute (mi)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minimize(string): mstr="" flagchar=[0]*26 l=len(string) for i in range(0,len(string)): ch=string[i] if flagchar[ord(ch)-97]==0 : mstr=mstr+ch flagchar[ord(ch)-97]=1 return mstr def replaceMinimizeUtil(string): finalStr="" l=len(string) minimizedStr=minimize(string) for i in range(0,len(minimizedStr)): ch=ord(minimizedStr[i]) index=(ch*ch)% l finalStr=finalStr+string[index] print("Final string:",finalStr) if __name__=="__main__" : string="geeks" replaceMinimizeUtil(string) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( string := "geeks" ; replaceMinimizeUtil(string) ) else skip; operation minimize(string : OclAny) : OclAny pre: true post: true activity: var mstr : String := "" ; var flagchar : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; var l : int := (string)->size() ; for i : Integer.subrange(0, (string)->size()-1) do ( var ch : OclAny := string[i+1] ; if flagchar[(ch)->char2byte() - 97+1] = 0 then ( mstr := mstr + ch ; flagchar[(ch)->char2byte() - 97+1] := 1 ) else skip) ; return mstr; operation replaceMinimizeUtil(string : OclAny) pre: true post: true activity: var finalStr : String := "" ; l := (string)->size() ; var minimizedStr : OclAny := minimize(string) ; for i : Integer.subrange(0, (minimizedStr)->size()-1) do ( ch := (minimizedStr[i+1])->char2byte() ; var index : int := (ch * ch) mod l ; finalStr := finalStr + string[index+1]) ; execute ("Final string:")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSetBits(n): count=0 while(n): n &=(n-1) count+=1 return count i=9 print(countSetBits(i)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var i : int := 9 ; execute (countSetBits(i))->display(); operation countSetBits(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while (n) do ( n := n & (n - 1) ; count := count + 1) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSetBits(n): count=0 while(n): count+=n & 1 n>>=1 return count i=9 print(countSetBits(i)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var i : int := 9 ; execute (countSetBits(i))->display(); operation countSetBits(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while (n) do ( count := count + MathLib.bitwiseAnd(n, 1) ; n := n div (2->pow(1))) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) print('ACL'*k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (StringLib.nCopies('ACL', k))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import datetime while 1 : a,b,c,d,e,f=map(int,raw_input().split(" ")) if a==b==c==d==e==f==-1 : break print(datetime.date(d,e,f)-datetime.date(a,b,c)).days ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while 1 do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; var f : OclAny := null; Sequence{a,b,c,d,e,f} := (raw_input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; if a = b & (b == c) & (c == d) & (d == e) & (e == f) & (f == -1) then ( break ) else skip ; (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name datetime)) (trailer . (name date) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name d))))))) , (argument (test (logical_test (comparison (expr (atom (name e))))))) , (argument (test (logical_test (comparison (expr (atom (name f)))))))) )))) - (expr (atom (name datetime)) (trailer . (name date) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name b))))))) , (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))))))))) ))) (trailer . (name days)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l,n=map(int,input().split()) s=input() c=0 for i in range(l-1): if s[i : i+2]=="oo" : c+=1 while n : l+=c*3 c*=2 n-=1 print(l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := null; var n : OclAny := null; Sequence{l,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var c : int := 0 ; for i : Integer.subrange(0, l - 1-1) do ( if s.subrange(i+1, i + 2) = "oo" then ( c := c + 1 ) else skip) ; while n do ( l := l + c * 3 ; c := c * 2 ; n := n - 1) ; execute (l)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def max_intersection(center,length,k): center.sort(); if(center[2]-center[0]>=2*k+length): return 0 ; elif(center[2]-center[0]>=2*k): return(2*k-(center[2]-center[0]-length)); else : return length ; center=[1,2,3]; L=1 ; K=1 ; print(max_intersection(center,L,K)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; center := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })); ; var L : int := 1; ; var K : int := 1; ; execute (max_intersection(center, L, K))->display();; operation max_intersection(center : OclAny, length : OclAny, k : OclAny) pre: true post: true activity: center := center->sort(); ; if ((center[2+1] - center->first()->compareTo(2 * k + length)) >= 0) then ( return 0; ) else (if ((center[2+1] - center->first()->compareTo(2 * k)) >= 0) then ( return (2 * k - (center[2+1] - center->first() - length)); ) else ( return length; ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def hexagonside(a): if a<0 : return-1 x=a//3 return x a=6 print(hexagonside(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 6 ; execute (hexagonside(a))->display(); operation hexagonside(a : OclAny) : OclAny pre: true post: true activity: if a < 0 then ( return -1 ) else skip ; var x : int := a div 3 ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findLargest(N): largest=strings(N,'7'); return largest ; def findSmallest(N): smallest="1"+strings((N-1),'0'); return smallest ; def strings(N,c): temp="" ; for i in range(N): temp+=c ; return temp ; def printLargestSmallest(N): print("Largest: ",findLargest(N)); print("Smallest: ",findSmallest(N)); if __name__=='__main__' : N=4 ; printLargestSmallest(N); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( N := 4; ; printLargestSmallest(N); ) else skip; operation findLargest(N : OclAny) pre: true post: true activity: var largest : OclAny := strings(N, '7'); ; return largest;; operation findSmallest(N : OclAny) pre: true post: true activity: var smallest : String := "1" + strings((N - 1), '0'); ; return smallest;; operation strings(N : OclAny, c : OclAny) pre: true post: true activity: var temp : String := ""; ; for i : Integer.subrange(0, N-1) do ( temp := temp + c;) ; return temp;; operation printLargestSmallest(N : OclAny) pre: true post: true activity: execute ("Largest: ")->display(); ; execute ("Smallest: ")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isVowel(c): if(c=='a' or c=='A' or c=='e' or c=='E' or c=='i' or c=='I' or c=='o' or c=='O' or c=='u' or c=='U'): return True return False def reverserVowel(string): j=0 vowel=[0]*len(string) string=list(string) for i in range(len(string)): if isVowel(string[i]): vowel[j]=string[i] j+=1 for i in range(len(string)): if isVowel(string[i]): j-=1 string[i]=vowel[j] return ''.join(string) if __name__=="__main__" : string="hello world" print(reverserVowel(string)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( string := "hello world" ; execute (reverserVowel(string))->display() ) else skip; operation isVowel(c : OclAny) : OclAny pre: true post: true activity: if (c = 'a' or c = 'A' or c = 'e' or c = 'E' or c = 'i' or c = 'I' or c = 'o' or c = 'O' or c = 'u' or c = 'U') then ( return true ) else skip ; return false; operation reverserVowel(string : OclAny) : OclAny pre: true post: true activity: var j : int := 0 ; var vowel : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (string)->size()) ; string := (string)->characters() ; for i : Integer.subrange(0, (string)->size()-1) do ( if isVowel(string[i+1]) then ( vowel[j+1] := string[i+1] ; j := j + 1 ) else skip) ; for i : Integer.subrange(0, (string)->size()-1) do ( if isVowel(string[i+1]) then ( j := j - 1 ; string[i+1] := vowel[j+1] ) else skip) ; return StringLib.sumStringsWithSeparator((string), ''); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=[] ans=0 def subsetSum(): global ans L=len(c) mul=pow(2,L-1) i=0 while(iunion(Sequence{ 1 }) ; n := (arr)->size() ; subsetGen(arr, 0, n) ; execute (ans)->display() ) else skip; operation subsetSum() pre: true post: true activity: skip ; var L : int := (c)->size() ; var mul : double := (2)->pow(L - 1) ; var i : int := 0 ; while ((i->compareTo((c)->size())) < 0) do ( ans := ans + c[i+1] * mul ; i := i + 1); operation subsetGen(arr : OclAny, i : OclAny, n : OclAny) pre: true post: true activity: if (i = n) then ( subsetSum() ; return ) else skip ; subsetGen(arr, i + 1, n) ; execute ((arr[i+1]) : c) ; subsetGen(arr, i + 1, n) ; c := c->front(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=map(int,input().split()) if x*y<0 : print(abs(abs(x)-abs(y))+1) elif 0<=xcollect( _x | (OclType["int"])->apply(_x) ) ; if x * y < 0 then ( execute (((x)->abs() - (y)->abs())->abs() + 1)->display() ) else (if 0 <= x & (x < y) then ( execute (y - x)->display() ) else (if 0 < y & (y < x) then ( execute (2 + x - y)->display() ) else (if y = 0 & (y->compareTo(x)) < 0 then ( execute (1 + x)->display() ) else (if (x->compareTo(y)) < 0 & (y <= 0) then ( execute (y - x)->display() ) else (if (y->compareTo(x)) < 0 & (x < 0) then ( execute (2 + x - y)->display() ) else (if x = 0 & (y->compareTo(x)) < 0 then ( execute (1 - y)->display() ) else skip ) ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement from collections import deque,defaultdict,Counter from bisect import bisect_left,bisect_right from operator import itemgetter from heapq import heapify,heappop,heappush from queue import Queue,LifoQueue,PriorityQueue from copy import deepcopy from time import time from functools import reduce import string import sys sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(MAP()) x,y=MAP() a=[x,-x,x,-x] b=[y,y,-y,-y] c=[0,1,1,2] ans=inf for i in range(4): if a[i]<=b[i]: ans=min(ans,b[i]-a[i]+c[i]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; skip ; skip ; skip ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := MAP() ; var a : Sequence := Sequence{x}->union(Sequence{-x}->union(Sequence{x}->union(Sequence{ -x }))) ; var b : Sequence := Sequence{y}->union(Sequence{y}->union(Sequence{-y}->union(Sequence{ -y }))) ; var c : Sequence := Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 2 }))) ; var ans : double := Math_PINFINITY ; for i : Integer.subrange(0, 4-1) do ( if (a[i+1]->compareTo(b[i+1])) <= 0 then ( ans := Set{ans, b[i+1] - a[i+1] + c[i+1]}->min() ) else skip) ; execute (ans)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return (MAP()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math from functools import lru_cache import heapq sys.setrecursionlimit(10**9) MOD=10**9+7 def input(): return sys.stdin.readline()[:-1] def mi(): return map(int,input().split()) def ii(): return int(input()) def i2(n): tmp=[list(mi())for i in range(n)] return[list(i)for i in zip(*tmp)] def solve(s,e,x,y): cnt=0 if s : x*=-1 cnt+=1 if e : y*=-1 cnt+=1 if y-x>=0 : cnt+=y-x return cnt else : return math.inf def main(): x,y=mi() ss=[True,True,False,False] es=[True,False,True,False] m=math.inf for i in range(4): m=min(m,solve(ss[i],es[i],x,y)) print(m) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation mi() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation ii() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation i2(n : OclAny) : OclAny pre: true post: true activity: var tmp : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((mi()))) ; return Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name tmp)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name tmp)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name tmp)))))))`third->at(_indx)} )->select(i | true)->collect(i | ((i))); operation solve(s : OclAny, e : OclAny, x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; if s then ( x := x * -1 ; cnt := cnt + 1 ) else skip ; if e then ( y := y * -1 ; cnt := cnt + 1 ) else skip ; if y - x >= 0 then ( cnt := cnt + y - x ; return cnt ) else ( return ); operation main() pre: true post: true activity: Sequence{x,y} := mi() ; var ss : Sequence := Sequence{true}->union(Sequence{true}->union(Sequence{false}->union(Sequence{ false }))) ; var es : Sequence := Sequence{true}->union(Sequence{false}->union(Sequence{true}->union(Sequence{ false }))) ; var m : OclAny := ; for i : Integer.subrange(0, 4-1) do ( m := Set{m, solve(ss[i+1], es[i+1], x, y)}->min()) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=map(int,input().split()) ans=0 minxy=min(abs(x),abs(y)) maxxy=max(abs(x),abs(y)) tmp=abs(maxxy-minxy) if x==0 : if y<0 : ans=tmp+1 else : ans=tmp elif y==0 : if x<0 : ans=tmp else : ans=tmp+1 elif x>=0 and y>=0 : if xcollect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; var minxy : OclAny := Set{(x)->abs(), (y)->abs()}->min() ; var maxxy : OclAny := Set{(x)->abs(), (y)->abs()}->max() ; var tmp : double := (maxxy - minxy)->abs() ; if x = 0 then ( if y < 0 then ( ans := tmp + 1 ) else ( ans := tmp ) ) else (if y = 0 then ( if x < 0 then ( ans := tmp ) else ( ans := tmp + 1 ) ) else (if x >= 0 & y >= 0 then ( if (x->compareTo(y)) < 0 then ( ans := tmp ) else ( ans := tmp + 2 ) ) else (if x <= 0 & y <= 0 then ( if (y->compareTo(x)) < 0 then ( ans := tmp + 2 ) else ( ans := tmp ) ) else ( ans := tmp + 1 ) ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy common=[31,28,31,30,31,30,31,31,30,31,30,31,365] leep=copy.deepcopy(common) leep[1]+=1 leep[12]+=1 def get_days(year): if year % 400==0 : return leep elif year % 100==0 : return common elif year % 4==0 : return leep else : return common if __name__=='__main__' : while True : y1,m1,d1,y2,m2,d2=map(int,raw_input().split()) if y1<0 or y2<0 or m1<0 or m2<0 or d1<0 or d2<0 : break ans=0 if y2-y1==0 : if m2-m1==0 : ans=d2-d1 else : days=get_days(y2) ans+=days[m1-1]-d1 ans+=d2 nm=m1 while nm+1union(Sequence{28}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{ 365 })))))))))))) ; var leep : OclAny := copy.deepcopy(common) ; leep[1+1] := leep[1+1] + 1 ; leep[12+1] := leep[12+1] + 1 ; skip ; if __name__ = '__main__' then ( while true do ( var y1 : OclAny := null; var m1 : OclAny := null; var d1 : OclAny := null; var y2 : OclAny := null; var m2 : OclAny := null; var d2 : OclAny := null; Sequence{y1,m1,d1,y2,m2,d2} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if y1 < 0 or y2 < 0 or m1 < 0 or m2 < 0 or d1 < 0 or d2 < 0 then ( break ) else skip ; var ans : int := 0 ; if y2 - y1 = 0 then ( if m2 - m1 = 0 then ( ans := d2 - d1 ) else ( var days : OclAny := get_days(y2) ; ans := ans + days[m1 - 1+1] - d1 ; ans := ans + d2 ; var nm : OclAny := m1 ; while (nm + 1->compareTo(m2)) < 0 do ( ans := ans + days[nm+1] ; nm := nm + 1) ) ) else ( days := get_days(y1) ; ans := ans + days[m1 - 1+1] - d1 + 1 ; nm := m1 + 1 ; while nm <= 12 do ( ans := ans + days[nm - 1+1] ; nm := nm + 1) ; days := get_days(y2) ; nm := 0 ; while (nm + 1->compareTo(m2)) < 0 do ( ans := ans + days[nm+1] ; nm := nm + 1) ; ans := ans + d2 - 1 ; var ny : OclAny := y1 + 1 ; for i : xrange(y2 - y1 - 1) do ( days := get_days(ny + i) ; ans := ans + days[12+1]) ) ; execute (ans)->display()) ) else skip; operation get_days(year : OclAny) : OclAny pre: true post: true activity: if year mod 400 = 0 then ( return leep ) else (if year mod 100 = 0 then ( return common ) else (if year mod 4 = 0 then ( return leep ) else ( return common ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=[int(i)for i in input().split()] res=0 if abs(y)>abs(x): if x<0 : res=res+1 if y<0 : res=res+1 res=res+abs(abs(y)-abs(x)) else : if x>0 : res=res+1 if y>0 : res=res+1 res=res+abs(abs(y)-abs(x)) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var res : int := 0 ; if ((y)->abs()->compareTo((x)->abs())) > 0 then ( if x < 0 then ( res := res + 1 ) else skip ; if y < 0 then ( res := res + 1 ) else skip ; res := res + ((y)->abs() - (x)->abs())->abs() ) else ( if x > 0 then ( res := res + 1 ) else skip ; if y > 0 then ( res := res + 1 ) else skip ; res := res + ((y)->abs() - (x)->abs())->abs() ) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print((lambda x : int(x[0])+int(x[1])+1-(lambda*x,f=lambda f,x,y : f(f,y,x % y)if y else x : f(f,*x))(int(x[0]),int(x[1])))(input().split())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((lambda x : OclAny in (("" + ((x->first())))->toInteger() + ("" + ((x[1+1])))->toInteger() + 1 - (lambda x : Sequence(OclAny), f : OclAny in (f(f, (argument * (test (logical_test (comparison (expr (atom (name x))))))))))(("" + ((x->first())))->toInteger(), ("" + ((x[1+1])))->toInteger())))(input().split()))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- L,N=[int(i)for i in input().split()] snake=input() d=0 for i in range(L-1): if snake[i]=="o" and snake[i+1]=="o" : d+=1 ans=L for i in range(N): ans+=d*3 d*=2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var L : OclAny := null; var N : OclAny := null; Sequence{L,N} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var snake : String := (OclFile["System.in"]).readLine() ; var d : int := 0 ; for i : Integer.subrange(0, L - 1-1) do ( if snake[i+1] = "o" & snake[i + 1+1] = "o" then ( d := d + 1 ) else skip) ; var ans : OclAny := L ; for i : Integer.subrange(0, N-1) do ( ans := ans + d * 3 ; d := d * 2) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : c=[int(x)for x in input().split()] if c[0]==0 : break L=[] for i in c : if i>10 : L.append(10) else : L.append(i) p=[] for i in range(L.count(1)+1): t=sum(L)+10*i if t>21 : t=0 p.append(t) print(max(p)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var c : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if c->first() = 0 then ( break ) else skip ; var L : Sequence := Sequence{} ; for i : c do ( if i > 10 then ( execute ((10) : L) ) else ( execute ((i) : L) )) ; var p : Sequence := Sequence{} ; for i : Integer.subrange(0, L->count(1) + 1-1) do ( var t : OclAny := (L)->sum() + 10 * i ; if t > 21 then ( t := 0 ) else skip ; execute ((t) : p)) ; execute ((p)->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : *C,=map(int,input().split()) if C==[0]: break s=0 C.sort(reverse=1) one=0 for c in C : if c==1 : s+=1 one+=1 elif c>10 : s+=10 else : s+=c while one and s+10<=21 : s+=10 one-=1 if s>21 : s=0 print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( ; (testlist_star_expr (star_expr * (expr (atom (name C)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name C)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if C = Sequence{ 0 } then ( break ) else skip ; var s : int := 0 ; C := C->sort() ; var one : int := 0 ; for c : C do ( if c = 1 then ( s := s + 1 ; one := one + 1 ) else (if c > 10 then ( s := s + 10 ) else ( s := s + c ) ) ) ; while one & s + 10 <= 21 do ( s := s + 10 ; one := one - 1) ; if s > 21 then ( s := 0 ) else skip ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter def point(lst): counter=Counter(lst) acc=0 for i in range(2,10): acc+=i*counter[i] for i in range(10,14): acc+=10*counter[i] one_num=counter[1] for i in range(one_num+1): if i+(one_num-i)*11+acc<=21 : acc+=i+(one_num-i)*11 break else : acc+=one_num if acc>21 : return 0 else : return acc while True : s=input() if s=="0" : break lst=list(map(int,s.split())) print(point(lst)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( var s : String := (OclFile["System.in"]).readLine() ; if s = "0" then ( break ) else skip ; lst := ((s.split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (point(lst))->display()); operation point(lst : OclAny) : OclAny pre: true post: true activity: var counter : OclAny := Counter(lst) ; var acc : int := 0 ; for i : Integer.subrange(2, 10-1) do ( acc := acc + i * counter[i+1]) ; for i : Integer.subrange(10, 14-1) do ( acc := acc + 10 * counter[i+1]) ; var one_num : OclAny := counter[1+1] ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name one_num))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (expr (atom (name i))) + (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name one_num))) - (expr (atom (name i)))))))) ))) * (expr (atom (number (integer 11)))))) + (expr (atom (name acc))))) <= (comparison (expr (atom (number (integer 21)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name acc)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name one_num))) - (expr (atom (name i)))))))) ))) * (expr (atom (number (integer 11)))))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name acc)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name one_num)))))))))))))) ; if acc > 21 then ( return 0 ) else ( return acc ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): c=list(map(int,input().split())) c=[min(10,e)for e in c] if c==[0]: return 1 if len(c)>21 : print(0) return 0 else : ans=0 for bit in range(1<>i & 1 : s+=11 else : s+=1 if s<=21 : ans=max(ans,s) print(ans) return 0 def main(): while solve()==0 : pass if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve() : OclAny pre: true post: true activity: var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; c := c->select(e | true)->collect(e | (Set{10, e}->min())) ; if c = Sequence{ 0 } then ( return 1 ) else skip ; if (c)->size() > 21 then ( execute (0)->display() ; return 0 ) else ( var ans : int := 0 ; for bit : Integer.subrange(0, 1 * (2->pow((c)->size()))-1) do ( var s : int := 0 ; for i : Integer.subrange(0, (c)->size()-1) do ( if c[i+1] /= 1 then ( s := s + c[i+1] ) else ( if MathLib.bitwiseAnd(bit /(2->pow(i)), 1) then ( s := s + 11 ) else ( s := s + 1 ) )) ; if s <= 21 then ( ans := Set{ans, s}->max() ) else skip) ; execute (ans)->display() ; return 0 ); operation main() pre: true post: true activity: while solve() = 0 do ( skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : N=list(map(int,input().split())) if N[0]==0 : break total,ace=0,0 for n in N : if n==1 : n=0 ace+=1 elif n>=10 : n=10 total+=n if total+ace>21 : break if total+ace>21 : print(0) elif 0collect( _x | (OclType["int"])->apply(_x) )) ; if N->first() = 0 then ( break ) else skip ; var total : OclAny := null; var ace : OclAny := null; Sequence{total,ace} := Sequence{0,0} ; for n : N do ( if n = 1 then ( var n : int := 0 ; ace := ace + 1 ) else (if n >= 10 then ( n := 10 ) else skip) ; total := total + n ; if total + ace > 21 then ( break ) else skip) ; if total + ace > 21 then ( execute (0)->display() ) else (if 0 < ace & total + ace <= 11 then ( execute (total + ace + 10)->display() ) else ( execute (total + ace)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y,z=map(int,input().split()) a=x %(y+z) b=x//(y+z) if(a>=z): print(b) else : print(b-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : int := x mod (y + z) ; var b : int := x div (y + z) ; if ((a->compareTo(z)) >= 0) then ( execute (b)->display() ) else ( execute (b - 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import os from collections import Counter,deque from fractions import gcd from functools import lru_cache from functools import reduce import functools import heapq import itertools import math import numpy as np import re import sys if os.getenv("LOCAL"): sys.stdin=open("_in.txt","r") sys.setrecursionlimit(2147483647) INF=float("inf") X,Y,Z=list(map(int,sys.stdin.readline().split())) X-=Z X//=(Y+Z) print(X) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if os.getenv("LOCAL") then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("_in.txt")) ) else skip ; sys.setrecursionlimit(2147483647) ; var INF : double := ("" + (("inf")))->toReal() ; var X : OclAny := null; var Y : OclAny := null; var Z : OclAny := null; Sequence{X,Y,Z} := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; X := X - Z ; X := X div (Y + Z) ; execute (X)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from heapq import heappush,heappop import sys import math import bisect import random def LI(): return[int(x)for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return[list(x)for x in sys.stdin.readline().split()] def S(): return list(sys.stdin.readline())[:-1] def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] sys.setrecursionlimit(1000000) mod=1000000007 M=1500000 l=[1]*(M+1) p=2 prime=[] while p<=M : while p<=M and not l[p]: p+=1 j=p while j<=M : l[j]=0 j+=p prime.append(p) def solve(k): i=bisect.bisect_left(prime,k) if prime[i]==k : print(0) else : print(prime[i]-prime[i-1]) return if __name__=="__main__" : while 1 : k=I() if k==0 : break solve(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1000000) ; var mod : int := 1000000007 ; var M : int := 1500000 ; var l : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (M + 1)) ; var p : int := 2 ; var prime : Sequence := Sequence{} ; while (p->compareTo(M)) <= 0 do ( while (p->compareTo(M)) <= 0 & not(l[p+1]) do ( p := p + 1) ; var j : int := p ; while (j->compareTo(M)) <= 0 do ( l[j+1] := 0 ; j := j + p) ; execute ((p) : prime)) ; skip ; if __name__ = "__main__" then ( while 1 do ( k := I() ; if k = 0 then ( break ) else skip ; solve(k)) ) else skip; operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | ((x))); operation S() : OclAny pre: true post: true activity: return OclType["Sequence"]((OclFile["System.in"]).readLine())->front(); operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation solve(k : OclAny) pre: true post: true activity: var i : OclAny := bisect.bisect_left(prime, k) ; if prime[i+1] = k then ( execute (0)->display() ) else ( execute (prime[i+1] - prime[i - 1+1])->display() ) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : total_width,width_per_person,span=list(map(int,input().split())) result=(total_width-span)//(width_per_person+span) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var total_width : OclAny := null; var width_per_person : OclAny := null; var span : OclAny := null; Sequence{total_width,width_per_person,span} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var result : int := (total_width - span) div (width_per_person + span) ; execute (result)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y,z=map(int,input().split()) x=x-y-2*z for i in range(50000): x=x-y-z if x<0 : print(i+1) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : double := x - y - 2 * z ; for i : Integer.subrange(0, 50000-1) do ( x := x - y - z ; if x < 0 then ( execute (i + 1)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=list(map(int,input().split())) b=(a[0]-a[2])//(a[1]+a[2]) print(b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : int := (a->first() - a[2+1]) div (a[1+1] + a[2+1]) ; execute (b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l,n=map(int,input().split()) maru=0 snake=input() for i in range(l-1): if snake[i : i+2]=="oo" : maru+=1 for i in range(n): l+=maru*3 maru*=2 print(l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := null; var n : OclAny := null; Sequence{l,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var maru : int := 0 ; var snake : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, l - 1-1) do ( if snake.subrange(i+1, i + 2) = "oo" then ( maru := maru + 1 ) else skip) ; for i : Integer.subrange(0, n-1) do ( l := l + maru * 3 ; maru := maru * 2) ; execute (l)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) res='' res+="VIBGYOR"*int(n//7) n=n % 7 if(n//4!=0): res+="GYOR" n=n % 4 res+="GYOR"[0 : n] print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : String := '' ; res := res + StringLib.nCopies("VIBGYOR", ("" + ((n div 7)))->toInteger()) ; n := n mod 7 ; if (n div 4 /= 0) then ( res := res + "GYOR" ; n := n mod 4 ) else skip ; res := res + "GYOR".subrange(0+1, n) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque number=int(input()) arr=deque(['R','O','Y','G','B','I','V']) string='' arr_check=[] for i in range(0,number,2): if i+2>number : break x=arr.pop() y=arr.pop() string=y+string+x arr.appendleft(x) arr.appendleft(y) if number % 2!=0 : string=string+arr.pop() print(string) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var number : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := (Sequence{'R'}->union(Sequence{'O'}->union(Sequence{'Y'}->union(Sequence{'G'}->union(Sequence{'B'}->union(Sequence{'I'}->union(Sequence{ 'V' }))))))) ; var string : String := '' ; var arr_check : Sequence := Sequence{} ; for i : Integer.subrange(0, number-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( if (i + 2->compareTo(number)) > 0 then ( break ) else skip ; var x : OclAny := arr->last() ; arr := arr->front() ; var y : OclAny := arr->last() ; arr := arr->front() ; string := y + string + x ; arr := arr->prepend(x) ; arr := arr->prepend(y)) ; if number mod 2 /= 0 then ( string := string + arr->last() ) else skip ; execute (string)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) c=('ROYGBIV') s=(n//7)*c if n % 7==1 : s+='G' elif n % 7==2 : s+='GB' elif n % 7==3 : s+='YGB' elif n % 7==4 : s+='YGBI' elif n % 7==5 : s+='OYGBI' elif n % 7==6 : s+='OYGBIV' print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : String := ('ROYGBIV') ; var s : double := (n div 7) * c ; if n mod 7 = 1 then ( s := s + 'G' ) else (if n mod 7 = 2 then ( s := s + 'GB' ) else (if n mod 7 = 3 then ( s := s + 'YGB' ) else (if n mod 7 = 4 then ( s := s + 'YGBI' ) else (if n mod 7 = 5 then ( s := s + 'OYGBI' ) else (if n mod 7 = 6 then ( s := s + 'OYGBIV' ) else skip ) ) ) ) ) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,sys,io,math from tokenize import Triple from math import* I=lambda :[*map(int,sys.stdin.readline().split())] IS=lambda : input() IN=lambda : int(input()) IF=lambda : float(input()) n=IN() s='GYOR' r='OYGBIV' print('VIB',end='') for i in range(n-3): print(s[i % 4],end='') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var I : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var IS : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var IN : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var IF : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toReal()) ; var n : OclAny := IN->apply() ; var s : String := 'GYOR' ; var r : String := 'OYGBIV' ; execute ('VIB')->display() ; for i : Integer.subrange(0, n - 3-1) do ( execute (s[i mod 4+1])->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) colors=['R','O','Y','G','B','I','V'] ans='' for i in range(n-3): ans+=colors[i % 4] ans+='BIV' print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var colors : Sequence := Sequence{'R'}->union(Sequence{'O'}->union(Sequence{'Y'}->union(Sequence{'G'}->union(Sequence{'B'}->union(Sequence{'I'}->union(Sequence{ 'V' })))))) ; var ans : String := '' ; for i : Integer.subrange(0, n - 3-1) do ( ans := ans + colors[i mod 4+1]) ; ans := ans + 'BIV' ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def reverse(q): s=len(q) ans=deque() for i in range(s): for j in range(s-1): x=q.popleft() q.appendleft(x) ans.appendleft(q.popleft()) return ans q=deque() q.append(1) q.append(2) q.append(3) q.append(4) q.append(5) q=reverse(q) while(len(q)>0): print(q.popleft(),end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; q := () ; execute ((1) : q) ; execute ((2) : q) ; execute ((3) : q) ; execute ((4) : q) ; execute ((5) : q) ; q := reverse(q) ; while ((q)->size() > 0) do ( execute (q->first())->display()); operation reverse(q : OclAny) : OclAny pre: true post: true activity: var s : int := (q)->size() ; var ans : Sequence := () ; for i : Integer.subrange(0, s-1) do ( for j : Integer.subrange(0, s - 1-1) do ( var x : OclAny := q->first() ; q := q->tail() ; q := q->prepend(x)) ; ans := ans->prepend(q->first())) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def closestNumber(n,m): q=int(n/m) n1=m*q if((n*m)>0): n2=(m*(q+1)) else : n2=(m*(q-1)) if(abs(n-n1)display() ; n := -15; m := 6 ; execute (closestNumber(n, m))->display() ; n := 0; m := 8 ; execute (closestNumber(n, m))->display() ; n := 18; m := -7 ; execute (closestNumber(n, m))->display(); operation closestNumber(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var q : int := ("" + ((n / m)))->toInteger() ; var n1 : double := m * q ; if ((n * m) > 0) then ( var n2 : double := (m * (q + 1)) ) else ( n2 := (m * (q - 1)) ) ; if (((n - n1)->abs()->compareTo((n - n2)->abs())) < 0) then ( return n1 ) else skip ; return n2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w,s,t=map(int,input().split()) if h*w % 2==1 : if(s+t)% 2==1 : print("No") else : print("Yes") else : print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; var s : OclAny := null; var t : OclAny := null; Sequence{h,w,s,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if h * w mod 2 = 1 then ( if (s + t) mod 2 = 1 then ( execute ("No")->display() ) else ( execute ("Yes")->display() ) ) else ( execute ("Yes")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w,x,y=map(int,input().split()) print(["Yes","No"][h*w % 2==1 and(x+y)% 2==1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{h,w,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Sequence{"Yes"}->union(Sequence{ "No" })->select(h * w mod 2 = 1 & (x + y) mod 2 = 1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w,s,t=map(int,input().split()) if h % 2==1 and w % 2==1 : if(s+t)% 2==1 : print("No") else : print("Yes") else : print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; var s : OclAny := null; var t : OclAny := null; Sequence{h,w,s,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if h mod 2 = 1 & w mod 2 = 1 then ( if (s + t) mod 2 = 1 then ( execute ("No")->display() ) else ( execute ("Yes")->display() ) ) else ( execute ("Yes")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W,x,y=map(int,input().split()) if H*W % 2==1 and(x+y)% 2==1 : print("No") else : print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{H,W,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if H * W mod 2 = 1 & (x + y) mod 2 = 1 then ( execute ("No")->display() ) else ( execute ("Yes")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l,n=map(int,input().split()) s=input() oocnt=0 for i in range(len(s)-1): if s[i]=='o' and s[i+1]=='o' : oocnt=oocnt+1 total_oocnt=0 for i in range(n): total_oocnt=total_oocnt+oocnt oocnt=oocnt*2 print(3*total_oocnt+l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := null; var n : OclAny := null; Sequence{l,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var oocnt : int := 0 ; for i : Integer.subrange(0, (s)->size() - 1-1) do ( if s[i+1] = 'o' & s[i + 1+1] = 'o' then ( oocnt := oocnt + 1 ) else skip) ; var total_oocnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( total_oocnt := total_oocnt + oocnt ; oocnt := oocnt * 2) ; execute (3 * total_oocnt + l)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W,X,Y=[int(x)for x in input().split()] ans='No' if(H*W)% 2+(X+Y)% 2==2 else 'Yes' print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; var X : OclAny := null; var Y : OclAny := null; Sequence{H,W,X,Y} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : String := if (H * W) mod 2 + (X + Y) mod 2 = 2 then 'No' else 'Yes' endif ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w,x,y=map(int,input().split()); print(["Yes","No"][h*w % 2*(x+y)% 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{h,w,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); execute (Sequence{"Yes"}->union(Sequence{ "No" })[h * w mod 2 * (x + y) mod 2+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=map(int,input().split()) print("No" if((a*b)% 2)*((c+d)% 2)==1 else "Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if ((a * b) mod 2) * ((c + d) mod 2) = 1 then "No" else "Yes" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W,X,Y=map(int,input().split()) if((H*W)*(X+Y))% 2 : print('No') else : print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; var X : OclAny := null; var Y : OclAny := null; Sequence{H,W,X,Y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if ((H * W) * (X + Y)) mod 2 then ( execute ('No')->display() ) else ( execute ('Yes')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthTerm(N): return N*N+(N+1)*(N+1) if __name__=="__main__" : N=3 print(nthTerm(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := 3 ; execute (nthTerm(N))->display() ) else skip; operation nthTerm(N : OclAny) : OclAny pre: true post: true activity: return N * N + (N + 1) * (N + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def make(k): s=str(k) t='' for i in s : t=i+t return int(s+t) k,p=map(int,input().split()) summ=0 for i in range(1,k+1): summ+=make(i) summ=summ % p print(summ) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var p : OclAny := null; Sequence{k,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var summ : int := 0 ; for i : Integer.subrange(1, k + 1-1) do ( summ := summ + make(i)) ; summ := summ mod p ; execute (summ)->display(); operation make(k : OclAny) : OclAny pre: true post: true activity: var s : String := ("" + ((k))) ; var t : String := '' ; for i : s->characters() do ( t := i + t) ; return ("" + ((s + t)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printModulus(X,Y): d=abs(X-Y); i=1 ; while(i*i<=d): if(d % i==0): print(i,end=""); if(d//i!=i): print(d//i,end=" "); i+=1 ; if __name__=='__main__' : X=10 ; Y=26 ; printModulus(X,Y); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( X := 10; ; Y := 26; ; printModulus(X, Y); ) else skip; operation printModulus(X : OclAny, Y : OclAny) pre: true post: true activity: var d : double := (X - Y)->abs(); ; var i : int := 1; ; while ((i * i->compareTo(d)) <= 0) do ( if (d mod i = 0) then ( execute (i)->display(); ; if (d div i /= i) then ( execute (d div i)->display(); ) else skip ) else skip ; i := i + 1;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def ipToInt(self,ip): ans=0 for x in ip.split('.'): ans=256*ans+int(x) return ans def intToIP(self,x): return ".".join(str((x>>i)% 256)for i in(24,16,8,0)) def ipToCIDR(self,ip,n): start=self.ipToInt(ip) ans=[] while n : mask=max(33-(start &-start).bit_length(),33-n.bit_length()) ans.append(self.intToIP(start)+'/'+str(mask)) start+=1<<(32-mask) n-=1<<(32-mask) return ans ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation ipToInt(ip : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for x : ip.split('.') do ( ans := 256 * ans + ("" + ((x)))->toInteger()) ; return ans; operation intToIP(x : OclAny) : OclAny pre: true post: true activity: return StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) >> (expr (atom (name i)))))))) ))) % (expr (atom (number (integer 256)))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 24))))))) , (test (logical_test (comparison (expr (atom (number (integer 16))))))) , (test (logical_test (comparison (expr (atom (number (integer 8))))))) , (test (logical_test (comparison (expr (atom (number (integer 0)))))))) )))))))), "."); operation ipToCIDR(ip : OclAny,n : OclAny) : OclAny pre: true post: true activity: var start : OclAny := self.ipToInt(ip) ; ans := Sequence{} ; while n do ( var mask : OclAny := Set{33 - (MathLib.bitwiseAnd(start, -start)).bit_length(), 33 - n.bit_length()}->max() ; execute ((self.intToIP(start) + '/' + ("" + ((mask)))) : ans) ; start := start + 1 * (2->pow((32 - mask))) ; n := n - 1 * (2->pow((32 - mask)))) ; return ans; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ispalindrome(s): l=len(s) i=0 j=l-1 while i<=j : if(s[i]!=s[j]): return False i+=1 j-=1 return True if __name__=="__main__" : s="BABABAA" cnt=0 flag=0 while(len(s)>0): if(ispalindrome(s)): flag=1 break else : cnt+=1 s=s[:-1] if(flag): print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "BABABAA" ; var cnt : int := 0 ; var flag : int := 0 ; while ((s)->size() > 0) do ( if (ispalindrome(s)) then ( flag := 1 ; break ) else ( cnt := cnt + 1 ; s := s->front() )) ; if (flag) then ( execute (cnt)->display() ) else skip ) else skip; operation ispalindrome(s : OclAny) : OclAny pre: true post: true activity: var l : int := (s)->size() ; var i : int := 0 ; var j : double := l - 1 ; while (i->compareTo(j)) <= 0 do ( if (s[i+1] /= s[j+1]) then ( return false ) else skip ; i := i + 1 ; j := j - 1) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reVal(num): if(num>=0 and num<=9): return chr(num+ord('0')); else : return chr(num-10+ord('A')); def strev(str): len=len(str); for i in range(int(len/2)): temp=str[i]; str[i]=str[len-i-1]; str[len-i-1]=temp ; def fromDeci(res,base,inputNum): index=0 ; while(inputNum>0): res+=reVal(inputNum % base); inputNum=int(inputNum/base); res=res[: :-1]; return res ; inputNum=282 ; base=16 ; res="" ; print("Equivalent of",inputNum,"in base",base,"is",fromDeci(res,base,inputNum)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; inputNum := 282; ; base := 16; ; res := ""; ; execute ("Equivalent of")->display();; operation reVal(num : OclAny) pre: true post: true activity: if (num >= 0 & num <= 9) then ( return (num + ('0')->char2byte())->byte2char(); ) else ( return (num - 10 + ('A')->char2byte())->byte2char(); ); operation strev(OclType["String"] : OclAny) pre: true post: true activity: var len : int := (OclType["String"])->size(); ; for i : Integer.subrange(0, ("" + ((len / 2)))->toInteger()-1) do ( var temp : String := ("" + ([i+1])); ; ("" + ([i+1])) := ("" + ([len - i - 1+1])); ; ("" + ([len - i - 1+1])) := temp;); operation fromDeci(res : OclAny, base : OclAny, inputNum : OclAny) pre: true post: true activity: var index : int := 0; ; while (inputNum > 0) do ( res := res + reVal(inputNum mod base); ; inputNum := ("" + ((inputNum / base)))->toInteger();) ; res := res(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lcs(i,j,count): if(i==0 or j==0): return count if(X[i-1]==Y[j-1]): count=lcs(i-1,j-1,count+1) count=max(count,max(lcs(i,j-1,0),lcs(i-1,j,0))) return count if __name__=="__main__" : X="abcdxyz" Y="xyzabcd" n=len(X) m=len(Y) print(lcs(n,m,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var X : String := "abcdxyz" ; var Y : String := "xyzabcd" ; var n : int := (X)->size() ; var m : int := (Y)->size() ; execute (lcs(n, m, 0))->display() ) else skip; operation lcs(i : OclAny, j : OclAny, count : OclAny) : OclAny pre: true post: true activity: if (i = 0 or j = 0) then ( return count ) else skip ; if (X[i - 1+1] = Y[j - 1+1]) then ( count := lcs(i - 1, j - 1, count + 1) ) else skip ; count := Set{count, Set{lcs(i, j - 1, 0), lcs(i - 1, j, 0)}->max()}->max() ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numberOfCuts(M,N): result=0 result=(M-1)*(N-1) return result if __name__=='__main__' : M,N=4,4 Cuts=numberOfCuts(M,N) print("Maximum cuts=",Cuts) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( Sequence{M,N} := Sequence{4,4} ; var Cuts : OclAny := numberOfCuts(M, N) ; execute ("Maximum cuts=")->display() ) else skip; operation numberOfCuts(M : OclAny, N : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; result := (M - 1) * (N - 1) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np q=int(input()) for _ in range(q): a,b=sorted(list(map(int,input().split(' ')))) n=int(np.floor(np.sqrt(a*b))) cnt=(n-1)*2 if a!=b : if a==n : if n*(n+1)=a*b : cnt-=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var n : int := ("" + ((MatrixLib.elementwiseApply(MatrixLib.elementwiseApply(a * b, lambda x : double in (x->sqrt())), lambda x : double in (x->floor())))))->toInteger() ; var cnt : double := (n - 1) * 2 ; if a /= b then ( if a = n then ( if (n * (n + 1)->compareTo(a * b)) < 0 then ( cnt := cnt + 1 ) else skip ) else ( cnt := cnt + 1 ; if (n)->pow(2) = a * b then ( cnt := cnt - 1 ) else skip ; if (n * (n + 1)->compareTo(a * b)) >= 0 then ( cnt := cnt - 1 ) else skip ) ) else skip ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binsearch(good,bad,fn): while abs(good-bad)>1 : m=(good+bad)//2 if fn(m): good=m else : bad=m return good def solve(a,b): if a>b : a,b=b,a if a==b : return 2*(a-1) t=binsearch(1,a*b,lambda x :(x+1)//2*(x//2+1)abs() > 1 do ( var m : int := (good + bad) div 2 ; if fn(m) then ( good := m ) else ( bad := m )) ; return good; operation solve(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a->compareTo(b)) > 0 then ( Sequence{a,b} := Sequence{b,a} ) else skip ; if a = b then ( return 2 * (a - 1) ) else skip ; var t : OclAny := binsearch(1, a * b, lambda x : OclAny in (((x + 1) div 2 * (x div 2 + 1)->compareTo(a * b)) < 0)) ; return t - 1; operation main() pre: true post: true activity: var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, Q-1) do ( Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (solve(a, b))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys input=sys.stdin.readline Q=int(input()) AB=[list(map(int,input().split()))for _ in range(Q)] for A,B in AB : P=A*B-1 b=int(math.sqrt(P)) if b<=1 : if P<=1 : print(0) else : print(1) continue K=[] for n in[b-1,b,b+1]: if P//n>n : border=n K.append(min(n,P//n)) ans=2*border if P//(border+1)==border+1 : ans+=1 if min(A,B)<=max(K): ans-=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var AB : Sequence := Integer.subrange(0, Q-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for _tuple : AB do (var _indx : int := 1; var A : OclAny := _tuple->at(_indx); _indx := _indx + 1; var B : OclAny := _tuple->at(_indx); var P : double := A * B - 1 ; var b : int := ("" + (((P)->sqrt())))->toInteger() ; if b <= 1 then ( if P <= 1 then ( execute (0)->display() ) else ( execute (1)->display() ) ; continue ) else skip ; var K : Sequence := Sequence{} ; for n : Sequence{b - 1}->union(Sequence{b}->union(Sequence{ b + 1 })) do ( if (P div n->compareTo(n)) > 0 then ( var border : OclAny := n ) else skip ; execute ((Set{n, P div n}->min()) : K)) ; var ans : double := 2 * border ; if P div (border + 1) = border + 1 then ( ans := ans + 1 ) else skip ; if (Set{A, B}->min()->compareTo((K)->max())) <= 0 then ( ans := ans - 1 ) else skip ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def main(): q=int(input()) ans=[None]*q for i in range(q): a,b=map(int,input().split()) score=a*b tmp=0 if b=score : tmp-=1 ans[i]=tmp for v in ans : print(v) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, q) ; for i : Integer.subrange(0, q-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var score : double := a * b ; var tmp : int := 0 ; if (b->compareTo(a)) < 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a} ) else skip ; if a = b then ( tmp := (a - 1) + (b - 1) ) else (if a + 1 = b then ( tmp := (a - 1) + (a - 1) ) else ( var p : int := ("" + ((sqrt(score))))->toInteger() ; if (p)->pow(2) = score then ( p := p - 1 ) else skip ; tmp := 2 * p - 1 ; if (p * (p + 1)->compareTo(score)) >= 0 then ( tmp := tmp - 1 ) else skip ) ) ; ans[i+1] := tmp) ; for v : ans do ( execute (v)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ut2jd(year,month,day): if month<=2 : year-=1 month+=12 s=3+year//4-year//100+year//400 s+=1720994+year*365+(month+1)*30+(month+1)*3//5+day ; return s while True : y1,m1,d1,y2,m2,d2=list(map(int,input().split())) if y1<0 or m1<0 or d1<0 or y2<0 or m2<0 or d2<0 : break print(ut2jd(y2,m2,d2)-ut2jd(y1,m1,d1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var y1 : OclAny := null; var m1 : OclAny := null; var d1 : OclAny := null; var y2 : OclAny := null; var m2 : OclAny := null; var d2 : OclAny := null; Sequence{y1,m1,d1,y2,m2,d2} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if y1 < 0 or m1 < 0 or d1 < 0 or y2 < 0 or m2 < 0 or d2 < 0 then ( break ) else skip ; execute (ut2jd(y2, m2, d2) - ut2jd(y1, m1, d1))->display()); operation ut2jd(year : OclAny, month : OclAny, day : OclAny) : OclAny pre: true post: true activity: if month <= 2 then ( year := year - 1 ; month := month + 12 ) else skip ; var s : double := 3 + year div 4 - year div 100 + year div 400 ; s := s + 1720994 + year * 365 + (month + 1) * 30 + (month + 1) * 3 div 5 + day; ; return s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- Q=int(input()) qs=[tuple(map(int,input().split()))for _ in range(Q)] for i in range(Q): A,B=qs[i] A,B=min(A,B),max(A,B) if A==B : C=A print(2*(C-1)) elif B==A+1 : C=A print(C-1+C-1) else : C=int((A*B)**(1/2)) if C**2==A*B : C=C-1 if C*(C+1)>=A*B : print(2*C-2) else : print(2*C-1) continue C=A n=B-C ans=C-1 MIN=1 MAX=B-1+1 middle=(MIN+MAX)//2 i=middle while MAX-MIN>1 : if(A*B-1)//i!=(A*B-1)//(i+1)and(A*B-1)//i>=A+1 : MIN=middle i=middle=(MIN+MAX)//2 else : MAX=middle i=middle=(MIN+MAX)//2 print("min:{},max:{}".format(MIN,MAX)) print(ans+i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var qs : Sequence := Integer.subrange(0, Q-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for i : Integer.subrange(0, Q-1) do ( var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := qs[i+1] ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := Sequence{Set{A, B}->min(),Set{A, B}->max()} ; if A = B then ( var C : OclAny := A ; execute (2 * (C - 1))->display() ) else (if B = A + 1 then ( C := A ; execute (C - 1 + C - 1)->display() ) else ( C := ("" + ((((A * B))->pow((1 / 2)))))->toInteger() ; if (C)->pow(2) = A * B then ( C := C - 1 ) else skip ; if (C * (C + 1)->compareTo(A * B)) >= 0 then ( execute (2 * C - 2)->display() ) else ( execute (2 * C - 1)->display() ) ; continue ; C := A ; var n : double := B - C ; var ans : double := C - 1 ; var MIN : int := 1 ; var MAX : double := B - 1 + 1 ; var middle : int := (MIN + MAX) div 2 ; var i : int := middle ; while MAX - MIN > 1 do ( if (A * B - 1) div i /= (A * B - 1) div (i + 1) & ((A * B - 1) div i->compareTo(A + 1)) >= 0 then ( MIN := middle ; i := (MIN + MAX) div 2; middle := (MIN + MAX) div 2 ) else ( MAX := middle ; i := (MIN + MAX) div 2; middle := (MIN + MAX) div 2 )) ; execute (StringLib.interpolateStrings("min:{},max:{}", Sequence{MIN, MAX}))->display() ; execute (ans + i)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def generateString(A,B): rt="" while(0compareTo(B)) < 0) then ( if (0 < B) then ( rt := rt + 'b' ; B := B - 1 ) else skip ; if (0 < B) then ( rt := rt + 'b' ; B := B - 1 ) else skip ; if (0 < A) then ( rt := rt + 'a' ; A := A - 1 ) else skip ) else (if ((B->compareTo(A)) < 0) then ( if (0 < A) then ( rt := rt + 'a' ; A := A - 1 ) else skip ; if (0 < A) then ( rt := rt + 'a' ; A := A - 1 ) else skip ; if (0 < B) then ( rt := rt + 'b' ; B := B - 1 ) else skip ) else ( if (0 < A) then ( rt := rt + 'a' ; A := A - 1 ) else skip ; if (0 < B) then ( rt := rt + 'b' ; B := B - 1 ) else skip ) ) ) ; execute (rt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.readline().strip() def list2d(a,b,c): return[[c]*b for i in range(a)] def list3d(a,b,c,d): return[[[d]*c for j in range(b)]for i in range(a)] def list4d(a,b,c,d,e): return[[[[e]*d for j in range(c)]for j in range(b)]for i in range(a)] def ceil(x,y=1): return int(-(-x//y)) def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(N=None): return list(MAP())if N is None else[INT()for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10**9) INF=float('inf') MOD=10**9+7 T=input() P=input() N=len(T) M=len(P) ans=[] p=P for i in range(N-M+1): t=T[i : i+M] if t==p : ans.append(i) if len(ans): [print(i)for i in ans] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; var T : String := (OclFile["System.in"]).readLine() ; var P : String := (OclFile["System.in"]).readLine() ; N := (T)->size() ; var M : int := (P)->size() ; var ans : Sequence := Sequence{} ; var p : String := P ; for i : Integer.subrange(0, N - M + 1-1) do ( var t : OclAny := T.subrange(i+1, i + M) ; if t = p then ( execute ((i) : ans) ) else skip) ; if (ans)->size() then ( ; ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation list2d(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, a-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ c }, b))); operation list3d(a : OclAny, b : OclAny, c : OclAny, d : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, a-1)->select(i | true)->collect(i | (Integer.subrange(0, b-1)->select(j | true)->collect(j | (MatrixLib.elementwiseMult(Sequence{ d }, c))))); operation list4d(a : OclAny, b : OclAny, c : OclAny, d : OclAny, e : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, a-1)->select(i | true)->collect(i | (Integer.subrange(0, b-1)->select(j | true)->collect(j | (Integer.subrange(0, c-1)->select(j | true)->collect(j | (MatrixLib.elementwiseMult(Sequence{ e }, d))))))); operation ceil(x : OclAny, y : int) : OclAny pre: true post: true activity: if y->oclIsUndefined() then y := 1 else skip; return ("" + ((-(-x div y))))->toInteger(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST(N : OclAny) : OclAny pre: true post: true activity: if N->oclIsUndefined() then N := null else skip; return if N <>= null then (MAP()) else Integer.subrange(0, N-1)->select(i | true)->collect(i | (INT())) endif; operation Yes() pre: true post: true activity: execute ('Yes')->display(); operation No() pre: true post: true activity: execute ('No')->display(); operation YES() pre: true post: true activity: execute ('YES')->display(); operation NO() pre: true post: true activity: execute ('NO')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class RKSearch : shift=40 size=33554393 def __init__(self,s1,s2): self.haystack=self._encode(s1) self.needle=self._encode(s2) def find(self): m,n=len(self.haystack),len(self.needle) if mexists( _x | result = _x ); static attribute shift : int := 40; static attribute size : int := 33554393; attribute haystack : OclAny := self._encode(s1); attribute needle : OclAny := self._encode(s2); operation initialise(s1 : OclAny,s2 : OclAny) : RKSearch pre: true post: true activity: self.haystack := self._encode(s1) ; self.needle := self._encode(s2); return self; operation find() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := Sequence{(self.haystack)->size(),(self.needle)->size()} ; if (m->compareTo(n)) < 0 then ( return ) else skip ; var h1 : OclAny := self._hash(self.haystack, n) ; var h2 : OclAny := self._hash(self.needle, n) ; var dm : int := (self.shift)->pow((n - 1)) mod self.size ; for i : Integer.subrange(0, m - n + 1-1) do ( if h1 = h2 then ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return i ) else skip ; if (i + n->compareTo(m)) < 0 then ( h1 := ((h1 - self.haystack[i+1] * dm) * self.shift + self.haystack[i + n+1]) mod self.size ) else skip); operation _hash(s : OclAny,length : OclAny) : OclAny pre: true post: true activity: var h : int := 0 ; for i : Integer.subrange(0, length-1) do ( h := (h * self.shift + s[i+1]) mod self.size) ; return h; operation _encode(cls : OclAny , s : OclAny) : OclAny pre: true post: true activity: var basea : int := ("" + (.from_bytes((atom b 'a'), 'little')))->toInteger() ; var based : int := ("" + (.from_bytes((atom b '0'), 'little')))->toInteger() ; var bs : Sequence := Sequence{} ; for c : s do ( if c->matches("[0-9]*") then ( execute ((("" + (.from_bytes(c.encode('utf8'), 'little')))->toInteger() - based + 27) : bs) ) else ( execute ((("" + (.from_bytes(c.encode('utf8'), 'little')))->toInteger() - basea) : bs) )) ; return bs; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( run() ) else skip; operation run() pre: true post: true activity: s1 := (OclFile["System.in"]).readLine() ; s2 := (OclFile["System.in"]).readLine() ; var rk : RKSearch := (RKSearch.newRKSearch()).initialise(s1, s2) ; for i : rk->indexOf() - 1 do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): import sys input=sys.stdin.readline class RollingHash : def __init__(self,S,base,mod): self.S=S self.mod=mod self._hash=[0]*(len(S)+1) self.pow=[1]*(len(S)+1) for i,s in enumerate(S): self._hash[i+1]=(self._hash[i]*base+s)% mod self.pow[i+1]=(self.pow[i]*base)% mod def get(self,l,r): return(self._hash[r]-self._hash[l]*self.pow[r-l])% self.mod S=[ord(s)for s in input().rstrip('\n')] T=[ord(t)for t in input().rstrip('\n')] RH_S=RollingHash(S,1007,1000000007) RH_T=RollingHash(T,1007,1000000007) lt=len(T) T_hash=RH_T.get(0,lt) for i in range(len(S)-len(T)+1): if RH_S.get(i,i+lt)==T_hash : print(i) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; S := input().rstrip(' ')->select(s | true)->collect(s | ((s)->char2byte())) ; var T : Sequence := input().rstrip(' ')->select(t | true)->collect(t | ((t)->char2byte())) ; var RH_S : RollingHash := (RollingHash.newRollingHash()).initialise(S, 1007, 1000000007) ; var RH_T : RollingHash := (RollingHash.newRollingHash()).initialise(T, 1007, 1000000007) ; var lt : int := (T)->size() ; var T_hash : OclAny := RH_T.get(0, lt) ; for i : Integer.subrange(0, (S)->size() - (T)->size() + 1-1) do ( if RH_S.get(i, i + lt) = T_hash then ( execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def kmpTable(w): lw=len(w) nx=[-1]*(lw+1) j=-1 for i in xrange(lw): while j>=0 and w[i]!=w[j]: j=nx[j] j+=1 nx[i+1]=j return nx def kmpSearch(s,w): ls=len(s) start=0 w_idx=0 ret=[] nx=kmpTable(w) while start+w_idxdisplay()); operation kmpTable(w : OclAny) : OclAny pre: true post: true activity: var lw : int := (w)->size() ; var nx : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (lw + 1)) ; var j : int := -1 ; for i : xrange(lw) do ( while j >= 0 & w[i+1] /= w[j+1] do ( j := nx[j+1]) ; j := j + 1 ; nx[i + 1+1] := j) ; return nx; operation kmpSearch(s : OclAny, w : OclAny) : OclAny pre: true post: true activity: var ls : int := (s)->size() ; var start : int := 0 ; var w_idx : int := 0 ; var ret : Sequence := Sequence{} ; nx := kmpTable(w) ; while (start + w_idx->compareTo(ls)) < 0 do ( if s[start + w_idx+1] = w[w_idx+1] then ( w_idx := w_idx + 1 ; if w_idx = (w)->size() then ( execute ((start) : ret) ; start := start + w_idx - nx[w_idx+1] ; w_idx := nx[w_idx+1] ) else skip ) else ( if w_idx = 0 then ( start := start + 1 ) else ( start := start + w_idx - nx[w_idx+1] ; w_idx := nx[w_idx+1] ) )) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printPattern(n): line_no=1 curr_star=0 line_no=1 while(line_no<=n): if(curr_starcompareTo(n)) <= 0) do ( if ((curr_star->compareTo(line_no)) < 0) then ( execute ("*")->display() ; curr_star := curr_star + 1 ; continue ) else skip ; if (curr_star = line_no) then ( execute ("")->display() ; line_no := line_no + 1 ; curr_star := 0 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calc_prefix(pattern): pattern_len=len(pattern) matched_table=[0]*pattern_len for calc_idx in range(1,pattern_len): matched_len=matched_table[calc_idx-1] while matched_len>0 and pattern[matched_len]!=pattern[calc_idx]: matched_len=matched_table[matched_len-1] if pattern[matched_len]==pattern[calc_idx]: matched_len+=1 matched_table[calc_idx]=matched_len return matched_table def kmp(text,pattern): matched_table=calc_prefix(pattern) pattern_len=len(pattern) text_len=len(text) text_idx=0 pattern_idx=0 matched_idxs=[] while text_idxsize() ; var matched_table : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, pattern_len) ; for calc_idx : Integer.subrange(1, pattern_len-1) do ( var matched_len : OclAny := matched_table[calc_idx - 1+1] ; while matched_len > 0 & pattern[matched_len+1] /= pattern[calc_idx+1] do ( matched_len := matched_table[matched_len - 1+1]) ; if pattern[matched_len+1] = pattern[calc_idx+1] then ( matched_len := matched_len + 1 ) else skip ; matched_table[calc_idx+1] := matched_len) ; return matched_table; operation kmp(text : OclAny, pattern : OclAny) : OclAny pre: true post: true activity: matched_table := calc_prefix(pattern) ; pattern_len := (pattern)->size() ; var text_len : int := (text)->size() ; var text_idx : int := 0 ; var pattern_idx : int := 0 ; var matched_idxs : Sequence := Sequence{} ; while (text_idx->compareTo(text_len)) < 0 do ( if pattern[pattern_idx+1] = text[text_idx+1] then ( pattern_idx := pattern_idx + 1 ; text_idx := text_idx + 1 ) else skip ; if pattern_idx = pattern_len then ( execute ((text_idx - pattern_idx) : matched_idxs) ; pattern_idx := matched_table[pattern_idx - 1+1] ) else (if (text_idx->compareTo(text_len)) < 0 & pattern[pattern_idx+1] /= text[text_idx+1] then ( if pattern_idx = 0 then ( text_idx := text_idx + 1 ) else ( pattern_idx := matched_table[pattern_idx - 1+1] ) ) else skip)) ; return matched_idxs; operation main() pre: true post: true activity: text := (OclFile["System.in"]).readLine() ; pattern := (OclFile["System.in"]).readLine() ; var matched : OclAny := kmp(text, pattern) ; for match_idx : matched do ( execute (match_idx)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- BIN=[0]*32 v=1 for i in range(24,0,-1): BIN[i]=v v*=2 v=float(1)/2 for i in range(25,32): BIN[i]=v v/=2 Q=int(input()) for i in range(Q): inp=format(int(input(),16),'b').zfill(32) res=float(0) for j,v in enumerate(list(inp)[1 :]): res+=BIN[j+1]*int(v) print(('-' if inp[0]=='1' else '')+str(res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var BIN : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 32) ; var v : int := 1 ; for i : Integer.subrange(0 + 1, 24)->reverse() do ( BIN[i+1] := v ; v := v * 2) ; v := ("" + ((1)))->toReal() / 2 ; for i : Integer.subrange(25, 32-1) do ( BIN[i+1] := v ; v := v / 2) ; var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, Q-1) do ( var inp : OclAny := format(("" + (((OclFile["System.in"]).readLine(), 16)))->toInteger(), 'b').zfill(32) ; var res : double := ("" + ((0)))->toReal() ; for _tuple : Integer.subrange(1, (OclType["Sequence"](inp)->tail())->size())->collect( _indx | Sequence{_indx-1, (OclType["Sequence"](inp)->tail())->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); res := res + BIN[j + 1+1] * ("" + ((v)))->toInteger()) ; execute ((if inp->first() = '1' then '-' else '' endif) + ("" + ((res))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- hex_to_dig={"0" : "0000","1" : "0001","2" : "0010","3" : "0011","4" : "0100","5" : "0101","6" : "0110","7" : "0111","8" : "1000","9" : "1001","a" : "1010","b" : "1011","c" : "1100","d" : "1101","e" : "1110","f" : "1111"} def dig_to_dec(digit): tf=digit[0] x=digit[1 : 25][: :-1] y=digit[25 : 32] sumx=0 acc=1 for i,c in enumerate(x): if c=="1" : sumx+=acc acc*=2 sumy=0 acc=0.5 for i,c in enumerate(y): if c=="1" : sumy+=acc acc/=2 tf="-" if int(tf)==1 else "" if sumy==0 : print(tf+str(sumx)+"."+"0") else : print(tf+str(sumx+sumy)) n=int(input()) for _ in range(n): h=input() d="" for c in h : d+=hex_to_dig[c] dig_to_dec(d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var hex_to_dig : Map := Map{ "0" |-> "0000" }->union(Map{ "1" |-> "0001" }->union(Map{ "2" |-> "0010" }->union(Map{ "3" |-> "0011" }->union(Map{ "4" |-> "0100" }->union(Map{ "5" |-> "0101" }->union(Map{ "6" |-> "0110" }->union(Map{ "7" |-> "0111" }->union(Map{ "8" |-> "1000" }->union(Map{ "9" |-> "1001" }->union(Map{ "a" |-> "1010" }->union(Map{ "b" |-> "1011" }->union(Map{ "c" |-> "1100" }->union(Map{ "d" |-> "1101" }->union(Map{ "e" |-> "1110" }->union(Map{ "f" |-> "1111" }))))))))))))))) ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var h : String := (OclFile["System.in"]).readLine() ; var d : String := "" ; for c : h->characters() do ( d := d + hex_to_dig[c+1]) ; dig_to_dec(d)); operation dig_to_dec(digit : OclAny) pre: true post: true activity: var tf : OclAny := digit->first() ; var x : OclAny := digit.subrange(1+1, 25)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var y : OclAny := digit.subrange(25+1, 32) ; var sumx : int := 0 ; var acc : int := 1 ; for _tuple : Integer.subrange(1, (x)->size())->collect( _indx | Sequence{_indx-1, (x)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if c = "1" then ( sumx := sumx + acc ) else skip ; acc := acc * 2) ; var sumy : int := 0 ; acc := 0.5 ; for _tuple : Integer.subrange(1, (y)->size())->collect( _indx | Sequence{_indx-1, (y)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if c = "1" then ( sumy := sumy + acc ) else skip ; acc := acc / 2) ; tf := if ("" + ((tf)))->toInteger() = 1 then "-" else "" endif ; if sumy = 0 then ( execute (tf + ("" + ((sumx))) + "." + "0")->display() ) else ( execute (tf + ("" + ((sumx + sumy))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import os import math from datetime import date for s in sys.stdin : y1,m1,d1,y2,m2,d2=map(int,s.split()) if y1==m1==d1==y2==m2==d2==-1 : break day1=date(y1,m1,d1) day2=date(y2,m2,d2) delta=day2-day1 print(delta.days) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; for s : OclFile["System.in"] do ( var y1 : OclAny := null; var m1 : OclAny := null; var d1 : OclAny := null; var y2 : OclAny := null; var m2 : OclAny := null; var d2 : OclAny := null; Sequence{y1,m1,d1,y2,m2,d2} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ) ; if y1 = m1 & (m1 == d1) & (d1 == y2) & (y2 == m2) & (m2 == d2) & (d2 == -1) then ( break ) else skip ; var day1 : OclAny := date(y1, m1, d1) ; var day2 : OclAny := date(y2, m2, d2) ; var delta : double := day2 - day1 ; execute (delta.days)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,datetime PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") n=int(input()) for _ in range(n): k=int(input(),16) s=1<<31 p="" if k & s!=0 : k ^=s p="-" a=int(k*1.0/(1<<7)) print(p+str(a)+str(abs(k*1.0/(1<<7)-a))[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var k : int := ("" + (((OclFile["System.in"]).readLine(), 16)))->toInteger() ; var s : int := 1 * (2->pow(31)) ; var p : String := "" ; if MathLib.bitwiseAnd(k, s) /= 0 then ( k := k xor s ; p := "-" ) else skip ; var a : int := ("" + ((k * 1.0 / (1 * (2->pow(7))))))->toInteger() ; execute (p + ("" + ((a))) + OclType["String"]((k * 1.0 / (1 * (2->pow(7))) - a)->abs())->tail())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(): bits=f'{int(input(),16):032b}' sign='-' if bits[0]=='1' else '' integer=sum([2**i for i,b in enumerate(bits[1 : 25][: :-1])if b=='1']) fraction=sum([0.5**i for i,b in enumerate(bits[25 :],start=1)if b=='1']) return sign+str(float(integer+fraction)) def main(args): Q=int(input()) for _ in range(Q): ans=solve() print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve() : OclAny pre: true post: true activity: var bits : String := StringLib.formattedString('{int(input(),16):032b}') ; var sign : String := if bits->first() = '1' then '-' else '' endif ; var integer : OclAny := (Integer.subrange(1, (bits.subrange(1+1, 25)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->size())->collect( _indx | Sequence{_indx-1, (bits.subrange(1+1, 25)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->at(_indx)} )->select(_tuple | let i : OclAny = _tuple->at(1) in let b : OclAny = _tuple->at(2) in b = '1')->collect(_tuple | let i : OclAny = _tuple->at(1) in let b : OclAny = _tuple->at(2) in ((2)->pow(i))))->sum() ; var fraction : OclAny := (Integer.subrange(1, (bits.subrange(25+1), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->size())->collect( _indx | Sequence{_indx-1, (bits.subrange(25+1), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->at(_indx)} )->select(_tuple | let i : OclAny = _tuple->at(1) in let b : OclAny = _tuple->at(2) in b = '1')->collect(_tuple | let i : OclAny = _tuple->at(1) in let b : OclAny = _tuple->at(2) in ((0.5)->pow(i))))->sum() ; return sign + ("" + ((("" + ((integer + fraction)))->toReal()))); operation main(args : OclAny) pre: true post: true activity: var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, Q-1) do ( var ans : OclAny := solve() ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) for i in range(N): s=int(input(),16) ans=(s & ~(1<<31))>>7 v=0.5 for i in range(6,-1,-1): if(s>>i)& 1 : ans+=v v/=2 if s &(1<<31): t="-%.10f" % ans else : t="%.10f" % ans i=len(t) while t[i-1]=='0' : i-=1 if t[i-1]=='.' : i+=1 print(t[: i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, N-1) do ( var s : int := ("" + (((OclFile["System.in"]).readLine(), 16)))->toInteger() ; var ans : int := (MathLib.bitwiseAnd(s, MathLib.bitwiseNot((1 * (2->pow(31)))))) /(2->pow(7)) ; var v : double := 0.5 ; for i : Integer.subrange(-1 + 1, 6)->reverse() do ( if MathLib.bitwiseAnd((s /(2->pow(i))), 1) then ( ans := ans + v ) else skip ; v := v / 2) ; if MathLib.bitwiseAnd(s, (1 * (2->pow(31)))) then ( var t : String := StringLib.format("-%.10f",ans) ) else ( t := StringLib.format("%.10f",ans) ) ; var i : int := (t)->size() ; while t[i - 1+1] = '0' do ( i := i - 1) ; if t[i - 1+1] = '.' then ( i := i + 1 ) else skip ; execute (t.subrange(1,i))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPerfectSquare(n): i=1 the_sum=0 while the_sumcompareTo(n)) < 0 do ( the_sum := the_sum + i ; if the_sum = n then ( return true ) else skip ; i := i + 2) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countTriplets(arr,n): freq=[0 for i in range(100)] for i in range(n): freq[arr[i]]+=1 count=0 for i in range(n): for j in range(i+1,n,1): if(freq[arr[i]+arr[j]]): count+=1 return count if __name__=='__main__' : n=4 arr=[1,5,3,2] print(countTriplets(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 4 ; arr := Sequence{1}->union(Sequence{5}->union(Sequence{3}->union(Sequence{ 2 }))) ; execute (countTriplets(arr, n))->display() ) else skip; operation countTriplets(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var freq : Sequence := Integer.subrange(0, 100-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( freq[arr[i+1]+1] := freq[arr[i+1]+1] + 1) ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1)->select( $x | ($x - i + 1) mod 1 = 0 ) do ( if (freq[arr[i+1] + arr[j+1]+1]) then ( count := count + 1 ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(str,input().split()) if a==b : print("H") elif a!=b : print("D") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; if a = b then ( execute ("H")->display() ) else (if a /= b then ( execute ("D")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input(); print(['D','H'][s[0]==s[2]]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine(); execute (Sequence{'D'}->union(Sequence{ 'H' })->select(s->first() = s[2+1]))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def getMinNum(N): lcm=1 ; for i in range(2,N+1): lcm=((i*lcm)//(gcd(i,lcm))); return(lcm+1); if __name__=="__main__" : N=5 ; print(getMinNum(N)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( N := 5; ; execute (getMinNum(N))->display(); ) else skip; operation getMinNum(N : OclAny) pre: true post: true activity: var lcm : int := 1; ; for i : Integer.subrange(2, N + 1-1) do ( lcm := ((i * lcm) div (gcd(i, lcm)));) ; return (lcm + 1);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda : sys.stdin.readline().rstrip() YesNo=lambda b : bool([print('Yes')]if b else print('No')) YESNO=lambda b : bool([print('YES')]if b else print('NO')) int1=lambda x : int(x)-1 def main(): a,b=input().split() if a=='H' : print(b) else : if b=='H' : print('D') else : print('H') if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var YesNo : Function := lambda b : OclAny in ((if b then Sequence{ ('Yes')->display() } else ('No')->display() endif)->toBoolean()) ; var YESNO : Function := lambda b : OclAny in ((if b then Sequence{ ('YES')->display() } else ('NO')->display() endif)->toBoolean()) ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input->apply().split() ; if a = 'H' then ( execute (b)->display() ) else ( if b = 'H' then ( execute ('D')->display() ) else ( execute ('H')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input().split() a=n[0] b=n[1] if a=='H' : if b=='H' : print('H') else : print('D') else : if b=='H' : print('D') else : print('H') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := input().split() ; var a : OclAny := n->first() ; var b : OclAny := n[1+1] ; if a = 'H' then ( if b = 'H' then ( execute ('H')->display() ) else ( execute ('D')->display() ) ) else ( if b = 'H' then ( execute ('D')->display() ) else ( execute ('H')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def uru(y): return y % 4==0 and y % 100!=0 or y % 400==0 def y_to_d(y): ret=0 for i in range(y): if uru(i): ret+=366 else : ret+=365 return ret month=[31,28,31,30,31,30,31,31,30,31,30,31] def m_to_d(y,m): m-=1 ret=0 for i in range(m): ret+=month[i] if m>=2 and uru(y): ret+=1 return ret while True : y1,m1,d1,y2,m2,d2=map(int,input().split()) if min(y1,m1,d1,y2,m2,d2)<0 : quit() ymd1=y_to_d(y1)+m_to_d(y1,m1)+d1 ymd2=y_to_d(y2)+m_to_d(y2,m2)+d2 print(ymd2-ymd1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var month : Sequence := Sequence{31}->union(Sequence{28}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{ 31 }))))))))))) ; skip ; while true do ( var y1 : OclAny := null; var m1 : OclAny := null; var d1 : OclAny := null; var y2 : OclAny := null; var m2 : OclAny := null; var d2 : OclAny := null; Sequence{y1,m1,d1,y2,m2,d2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if Set{y1, m1, d1, y2, m2, d2}->min() < 0 then ( quit() ) else skip ; var ymd1 : OclAny := y_to_d(y1) + m_to_d(y1, m1) + d1 ; var ymd2 : OclAny := y_to_d(y2) + m_to_d(y2, m2) + d2 ; execute (ymd2 - ymd1)->display()); operation uru(y : OclAny) : OclAny pre: true post: true activity: return y mod 4 = 0 & y mod 100 /= 0 or y mod 400 = 0; operation y_to_d(y : OclAny) : OclAny pre: true post: true activity: var ret : int := 0 ; for i : Integer.subrange(0, y-1) do ( if uru(i) then ( ret := ret + 366 ) else ( ret := ret + 365 )) ; return ret; operation m_to_d(y : OclAny, m : OclAny) : OclAny pre: true post: true activity: m := m - 1 ; ret := 0 ; for i : Integer.subrange(0, m-1) do ( ret := ret + month[i+1]) ; if m >= 2 & uru(y) then ( ret := ret + 1 ) else skip ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print("HD"[len(set(input().split()))-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ("HD"[(Set{}->union((input().split())))->size() - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r,c=(int(i)for i in input().split()) a=[[v for v in input()]for _ in range(r)] rs=[any(a[i][j]=="S" for j in range(c))for i in range(r)] cs=[any(a[i][j]=="S" for i in range(r))for j in range(c)] res=0 for i in range(r): for j in range(c): if not rs[i]or not cs[j]: res+=1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var a : Sequence := Integer.subrange(0, r-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine()->select(v | true)->collect(v | (v)))) ; var rs : Sequence := Integer.subrange(0, r-1)->select(i | true)->collect(i | (((argument (test (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) == (comparison (expr (atom "S")))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))))))))->exists( _x | _x = true ))) ; var cs : Sequence := Integer.subrange(0, c-1)->select(j | true)->collect(j | (((argument (test (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) == (comparison (expr (atom "S")))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name r)))))))) )))))))))->exists( _x | _x = true ))) ; var res : int := 0 ; for i : Integer.subrange(0, r-1) do ( for j : Integer.subrange(0, c-1) do ( if not(rs[i+1]) or not(cs[j+1]) then ( res := res + 1 ) else skip)) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) s=[] count=0 for i in range(a): s.append(list(str(input()))) for i in range(a): if 'S' in s[i]: pass else : for j in range(len(s[i])): s[i][j]='!' count+=1 curr=0 flag=True for j in range(b): for i in range(a): if s[i][j]!='S' and s[i][j]=='.' : s[i][j]='!' curr+=1 elif s[i][j]!='S' and s[i][j]=='!' : continue else : curr=0 flag=False break if flag : count+=curr curr=0 flag=True print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := Sequence{} ; var count : int := 0 ; for i : Integer.subrange(0, a-1) do ( execute (((("" + (((OclFile["System.in"]).readLine()))))->characters()) : s)) ; for i : Integer.subrange(0, a-1) do ( if (s[i+1])->includes('S') then ( skip ) else ( for j : Integer.subrange(0, (s[i+1])->size()-1) do ( s[i+1][j+1] := '!' ; count := count + 1) )) ; var curr : int := 0 ; var flag : boolean := true ; for j : Integer.subrange(0, b-1) do ( for i : Integer.subrange(0, a-1) do ( if s[i+1][j+1] /= 'S' & s[i+1][j+1] = '.' then ( s[i+1][j+1] := '!' ; curr := curr + 1 ) else (if s[i+1][j+1] /= 'S' & s[i+1][j+1] = '!' then ( continue ) else ( curr := 0 ; flag := false ; break ) ) ) ; if flag then ( count := count + curr ; curr := 0 ) else skip ; flag := true) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r,c=map(int,input().split()) s_r=set() s_c=set() t=0 t_r=0 for i in range(r): s=input() for j in range(c): if s[j]=="S" : if i not in s_r : s_r.add(i) t_r+=1 s_c.add(j) for i in range(r): if i not in s_r : t+=c for j in range(c): if j not in s_c : t+=t_r print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s_r : Set := Set{}->union(()) ; var s_c : Set := Set{}->union(()) ; var t : int := 0 ; var t_r : int := 0 ; for i : Integer.subrange(0, r-1) do ( var s : String := (OclFile["System.in"]).readLine() ; for j : Integer.subrange(0, c-1) do ( if s[j+1] = "S" then ( if (s_r)->excludes(i) then ( execute ((i) : s_r) ; t_r := t_r + 1 ) else skip ; execute ((j) : s_c) ) else skip)) ; for i : Integer.subrange(0, r-1) do ( if (s_r)->excludes(i) then ( t := t + c ) else skip) ; for j : Integer.subrange(0, c-1) do ( if (s_c)->excludes(j) then ( t := t + t_r ) else skip) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : r,c=map(int,input().split()) row=[] for _ in range(r): row.append(list(input())) col=[] for _ in range(c): col.append([]) total_cake=0 r_cake=0 c_cake=0 for r in row : for i in range(c): col[i].append(r[i]) if 'S' not in r : total_cake+=len(r) r_cake+=1 for c in col : if 'S' not in c : total_cake+=len(c)-r_cake print(total_cake) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var row : Sequence := Sequence{} ; for _anon : Integer.subrange(0, r-1) do ( execute ((((OclFile["System.in"]).readLine())->characters()) : row)) ; var col : Sequence := Sequence{} ; for _anon : Integer.subrange(0, c-1) do ( execute ((Sequence{}) : col)) ; var total_cake : int := 0 ; var r_cake : int := 0 ; var c_cake : int := 0 ; for r : row do ( for i : Integer.subrange(0, c-1) do ((expr (atom (name col)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name r)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))) ; if (r)->excludes('S') then ( total_cake := total_cake + (r)->size() ; r_cake := r_cake + 1 ) else skip) ; for c : col do ( if (c)->excludes('S') then ( total_cake := total_cake + (c)->size() - r_cake ) else skip) ; execute (total_cake)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- arr=input() arr=arr.split(" ") r=int(arr[0]) c=int(arr[1]) row=[] col=[] for i in range(r): text=input() for j in range(c): if text[j]=="S" : if j not in col : col.append(j) if i not in row : row.append(i) print((r-len(row))*c+(c-len(col))*r-((r-len(row))*(c-len(col)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var arr : String := (OclFile["System.in"]).readLine() ; arr := arr.split(" ") ; var r : int := ("" + ((arr->first())))->toInteger() ; var c : int := ("" + ((arr[1+1])))->toInteger() ; var row : Sequence := Sequence{} ; var col : Sequence := Sequence{} ; for i : Integer.subrange(0, r-1) do ( var text : String := (OclFile["System.in"]).readLine() ; for j : Integer.subrange(0, c-1) do ( if text[j+1] = "S" then ( if (col)->excludes(j) then ( execute ((j) : col) ) else skip ; if (row)->excludes(i) then ( execute ((i) : row) ) else skip ) else skip)) ; execute ((r - (row)->size()) * c + (c - (col)->size()) * r - ((r - (row)->size()) * (c - (col)->size())))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re while 1 : try : N=re.split("[.,]",input()) ans=[] for i in N : if 3<=len(i)<=6 : ans.append(i) print(*ans) except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while 1 do ( try ( var N : Sequence(String) := ((OclFile["System.in"]).readLine())->split("[.,]") ; var ans : Sequence := Sequence{} ; for i : N do ( if 3 <= (i)->size() & ((i)->size() <= 6) then ( execute ((i) : ans) ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()) catch (_e : OclException) do ( break) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(*filter(lambda x : 2display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import operator import itertools import functools import math from collections import deque def bfs(i): res=False visited=[0]*(N+1) q=deque([node[i]]) while len(q): n=q.popleft() if visited[n[0]]: res=True return res else : visited[n[0]]=1 for x in n[1 :]: q.append(node[x]) fn=open('1.in') ofn=open('1.out','w') TC=int(fn.readline()) for tc in range(TC): N=int(fn.readline().strip()) node=[None]*(N+1) for i in range(1,N+1): r=map(int,fn.readline().strip().split()) node[i]=[i]+r[1 :] for i in range(1,N+1): if bfs(i): print>>ofn,'Case #{}:{}'.format(tc+1,'Yes') break else : print>>ofn,'Case #{}:{}'.format(tc+1,'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var fn : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('1.in')) ; var ofn : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('1.out')) ; var TC : int := ("" + ((fn.readLine())))->toInteger() ; for tc : Integer.subrange(0, TC-1) do ( var N : int := ("" + ((fn.readLine()->trim())))->toInteger() ; var node : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (N + 1)) ; for i : Integer.subrange(1, N + 1-1) do ( var r : Sequence := (fn.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; node[i+1] := Sequence{ i }->union(r->tail())) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name N))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name bfs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (expr (atom print)) >> (expr (atom (name ofn))))))) , (test (logical_test (comparison (expr (atom 'Case #{}:{}') (trailer . (name format) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name tc))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom 'Yes'))))))) ))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (expr (atom print)) >> (expr (atom (name ofn))))))) , (test (logical_test (comparison (expr (atom 'Case #{}:{}') (trailer . (name format) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name tc))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom 'No'))))))) ))))))))))))))); operation bfs(i : OclAny) : OclAny pre: true post: true activity: var res : boolean := false ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; var q : Sequence := (Sequence{ node[i+1] }) ; while (q)->size() do ( var n : OclAny := q->first() ; q := q->tail() ; if visited[n->first()+1] then ( res := true ; return res ) else ( visited[n->first()+1] := 1 ) ; for x : n->tail() do ( execute ((node[x+1]) : q))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy BIG_NUM=2000000000 HUGE_NUM=99999999999999999 MOD=1000000007 EPS=0.000000001 sys.setrecursionlimit(100000) input_str=input() length=0 work=deque() is_First=True for i in range(len(input_str)): ch=input_str[i] if ch in[' ',',','.']or i==len(input_str)-1 : if length>=3 and length<=6 : if is_First==False : print("",end="") while len(work)>0 : print("%s" %(work.popleft()),end="") is_First=False else : while len(work)>0 : work.popleft() length=0 else : work.append(ch) length+=1 print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var HUGE_NUM : int := 99999999999999999 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; sys.setrecursionlimit(100000) ; var input_str : String := (OclFile["System.in"]).readLine() ; var length : int := 0 ; var work : Sequence := () ; var is_First : boolean := true ; for i : Integer.subrange(0, (input_str)->size()-1) do ( var ch : OclAny := input_str[i+1] ; if (Sequence{' '}->union(Sequence{','}->union(Sequence{ '.' })))->includes(ch) or i = (input_str)->size() - 1 then ( if length >= 3 & length <= 6 then ( if is_First = false then ( execute ("")->display() ) else skip ; while (work)->size() > 0 do ( execute (StringLib.format("%s",(work->first())))->display()) ; is_First := false ) else ( while (work)->size() > 0 do ( work := work->tail()) ) ; length := 0 ) else ( execute ((ch) : work) ; length := length + 1 )) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lcs(X,Y,m,n): L=[[0 for i in range(n+1)]for i in range(m+1)] for i in range(m+1): for j in range(n+1): if i==0 or j==0 : L[i][j]=0 elif X[i-1]==Y[j-1]: L[i][j]=L[i-1][j-1]+1 else : L[i][j]=max(L[i-1][j],L[i][j-1]) return L[m][n] def findMinCost(X,Y,costX,costY): m=len(X) n=len(Y) len_LCS=lcs(X,Y,m,n) return(costX*(m-len_LCS)+costY*(n-len_LCS)) X="ef" Y="gh" print('Minimum Cost to make two strings ',end='') print('identical is=',findMinCost(X,Y,10,20)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; X := "ef" ; Y := "gh" ; execute ('Minimum Cost to make two strings ')->display() ; execute ('identical is=')->display(); operation lcs(X : OclAny, Y : OclAny, m : OclAny, n : OclAny) : OclAny pre: true post: true activity: var L : Sequence := Integer.subrange(0, m + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, m + 1-1) do ( for j : Integer.subrange(0, n + 1-1) do ( if i = 0 or j = 0 then ( L[i+1][j+1] := 0 ) else (if X[i - 1+1] = Y[j - 1+1] then ( L[i+1][j+1] := L[i - 1+1][j - 1+1] + 1 ) else ( L[i+1][j+1] := Set{L[i - 1+1][j+1], L[i+1][j - 1+1]}->max() ) ) )) ; return L[m+1][n+1]; operation findMinCost(X : OclAny, Y : OclAny, costX : OclAny, costY : OclAny) : OclAny pre: true post: true activity: m := (X)->size() ; n := (Y)->size() ; var len_LCS : OclAny := lcs(X, Y, m, n) ; return (costX * (m - len_LCS) + costY * (n - len_LCS)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sent=input() sent=sent.replace("."," ") sent=sent.replace(","," ") words=sent.split() words=[i for i in words if len(i)<=6] words=[i for i in words if len(i)>2] print(*words,sep=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sent : String := (OclFile["System.in"]).readLine() ; sent := sent.replace(".", " ") ; sent := sent.replace(",", " ") ; var words : OclAny := sent.split() ; words := words->select(i | (i)->size() <= 6)->collect(i | (i)) ; words := words->select(i | (i)->size() > 2)->collect(i | (i)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name words))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- kensaku=list(input()) moji=0 n=[] ans=[] for i in range(len(kensaku)): if kensaku[i]=='' or kensaku[i]=='.' or kensaku[i]==',' : if 3<=moji<=6 : ans=ans+n+[''] n.clear() moji=0 else : n.append(kensaku[i]) moji+=1 del ans[-1] for i in range(len(ans)): print(ans[i],end='') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var kensaku : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var moji : int := 0 ; var n : Sequence := Sequence{} ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, (kensaku)->size()-1) do ( if kensaku[i+1] = '' or kensaku[i+1] = '.' or kensaku[i+1] = ',' then ( if 3 <= moji & (moji <= 6) then ( ans := ans->union(n)->union(Sequence{ '' }) ) else skip ; execute (n /<: n) ; moji := 0 ) else ( execute ((kensaku[i+1]) : n) ; moji := moji + 1 )) ; execute (ans->last())->isDeleted() ; for i : Integer.subrange(0, (ans)->size()-1) do ( execute (ans[i+1])->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findXorSum(arr,n): Sum=0 mul=1 for i in range(30): c_odd=0 odd=0 for j in range(n): if((arr[j]&(1<0): odd=(~ odd) if(odd): c_odd+=1 for j in range(n): Sum+=(mul*c_odd) if((arr[j]&(1<0): c_odd=(n-j-c_odd) mul*=2 return Sum arr=[3,8,13] n=len(arr) print(findXorSum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{3}->union(Sequence{8}->union(Sequence{ 13 })) ; n := (arr)->size() ; execute (findXorSum(arr, n))->display(); operation findXorSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var Sum : int := 0 ; var mul : int := 1 ; for i : Integer.subrange(0, 30-1) do ( var c_odd : int := 0 ; var odd : int := 0 ; for j : Integer.subrange(0, n-1) do ( if ((MathLib.bitwiseAnd(arr[j+1], (1 * (2->pow(i))))) > 0) then ( odd := (MathLib.bitwiseNot(odd)) ) else skip ; if (odd) then ( c_odd := c_odd + 1 ) else skip) ; for j : Integer.subrange(0, n-1) do ( Sum := Sum + (mul * c_odd) ; if ((MathLib.bitwiseAnd(arr[j+1], (1 * (2->pow(i))))) > 0) then ( c_odd := (n - j - c_odd) ) else skip) ; mul := mul * 2) ; return Sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt N=100005 def AMICABLE(): Sum=[0 for i in range(N)] for i in range(1,N): Sum[i]+=1 for j in range(2,mt.ceil(mt.sqrt(i))): if(i % j==0): Sum[i]+=j if(i//j!=j): Sum[i]+=i//j s=set() for i in range(2,N): if(i!=Sum[i]and Sum[i]display(); operation AMICABLE() : OclAny pre: true post: true activity: var Sum : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(1, N-1) do ( Sum[i+1] := Sum[i+1] + 1 ; for j : Integer.subrange(2, mt.ceil(mt.sqrt(i))-1) do ( if (i mod j = 0) then ( Sum[i+1] := Sum[i+1] + j ; if (i div j /= j) then ( Sum[i+1] := Sum[i+1] + i div j ) else skip ) else skip)) ; var s : Set := Set{}->union(()) ; for i : Integer.subrange(2, N-1) do ( if (i /= Sum[i+1] & (Sum[i+1]->compareTo(N)) < 0 & i = Sum[Sum[i+1]+1] & (s)->excludes(i) & (s)->excludes(Sum[i+1])) then ( execute ((i) : s) ; execute ((Sum[i+1]) : s) ) else skip) ; return s; operation SumOfAmicable(n : OclAny) : OclAny pre: true post: true activity: Sum := 0 ; s := AMICABLE() ; s := s->sort() ; for i : s do ( if ((i->compareTo(n)) <= 0) then ( Sum := Sum + i ) else ( break )) ; return Sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,t=map(int,input().split()) if x>=t : print(x-t) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var t : OclAny := null; Sequence{x,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (x->compareTo(t)) >= 0 then ( execute (x - t)->display() ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(max(0,eval(input().replace(' ','-')))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (Set{0, input().replace(' ', '-')}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=[int(x)for x in input().split()] print(max(0,x[0]-x[1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (Set{0, x->first() - x[1+1]}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- xtstr=input().split() x,t=int(xtstr[0]),int(xtstr[1]) if x>=t : print(x-t) else : print('0') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var xtstr : OclAny := input().split() ; var x : OclAny := null; var t : OclAny := null; Sequence{x,t} := Sequence{("" + ((xtstr->first())))->toInteger(),("" + ((xtstr[1+1])))->toInteger()} ; if (x->compareTo(t)) >= 0 then ( execute (x - t)->display() ) else ( execute ('0')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()); print(max(a-b,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); execute (Set{a - b, 0}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools class DiamondFound(Exception): pass def find_ancestors(class_num,inheritance,ancestors): if ancestors[class_num]: return direct_fathers=inheritance[class_num] ancestors[class_num].update(direct_fathers) for direct_father in direct_fathers : find_ancestors(direct_father,inheritance,ancestors) ancestors_of_direct_father=ancestors[direct_father] before=len(ancestors[class_num]) ancestors[class_num].update(ancestors_of_direct_father) after=len(ancestors[class_num]) if after-before!=len(ancestors_of_direct_father): raise DiamondFound() def solve(num_of_classes,inheritance): ancestors=dict((i,set())for i in xrange(1,num_of_classes+1)) for class_num in inheritance : try : find_ancestors(class_num,inheritance,ancestors) except DiamondFound : return 'Yes' return 'No' def process_files(in_file,out_file): num_of_test_cases=int(in_file.next().strip()) for test_number in xrange(num_of_test_cases): num_of_classes=int(in_file.next().strip()) inheritance={} for class_num in xrange(1,num_of_classes+1): params=in_file.next().strip().split() assert len(params)-1==int(params[0]) inheritance[class_num]=[int(i)for i in params[1 :]] result=solve(num_of_classes,inheritance) out_file.write('Case #%d: %s\n' %(test_number+1,result)) if __name__=='__main__' : with open('A-large.in','rb')as in_file : with open('A-large.out','wb')as out_file : process_files(in_file,out_file) ------------------------------------------------------------ OCL File: --------- class DiamondFound extends ProgramException { static operation newDiamondFound() : DiamondFound pre: true post: DiamondFound->exists( _x | result = _x ); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( try (var in_file : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('A-large.in')); try (var out_file : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('A-large.out')); process_files(in_file, out_file)) catch (_e : OclException) do skip) catch (_e : OclException) do skip ) else skip; operation find_ancestors(class_num : OclAny, inheritance : OclAny, ancestors : OclAny) pre: true post: true activity: if ancestors[class_num+1] then ( return ) else skip ; var direct_fathers : OclAny := inheritance[class_num+1] ; (expr (atom (name ancestors)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name class_num)))))))) ])) (trailer . (name update) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name direct_fathers)))))))) )))) ; for direct_father : direct_fathers do ( find_ancestors(direct_father, inheritance, ancestors) ; var ancestors_of_direct_father : OclAny := ancestors[direct_father+1] ; var before : int := (ancestors[class_num+1])->size() ; (expr (atom (name ancestors)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name class_num)))))))) ])) (trailer . (name update) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ancestors_of_direct_father)))))))) )))) ; var after : int := (ancestors[class_num+1])->size() ; if after - before /= (ancestors_of_direct_father)->size() then ( error DiamondFound.newDiamondFound() ) else skip); operation solve(num_of_classes : OclAny, inheritance : OclAny) : OclAny pre: true post: true activity: ancestors := ((argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) , (test (logical_test (comparison (expr (atom (name set)) (trailer (arguments ( )))))))) )))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name xrange)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name num_of_classes))) + (expr (atom (number (integer 1)))))))))) ))))))))) ; for class_num : inheritance do ( try ( find_ancestors(class_num, inheritance, ancestors)) (except_clause except (test (logical_test (comparison (expr (atom (name DiamondFound)))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom 'Yes')))))))))))) ; return 'No'; operation process_files(in_file : OclAny, out_file : OclAny) pre: true post: true activity: var num_of_test_cases : int := ("" + ((in_file.next()->trim())))->toInteger() ; for test_number : xrange(num_of_test_cases) do ( num_of_classes := ("" + ((in_file.next()->trim())))->toInteger() ; inheritance := Set{} ; for class_num : xrange(1, num_of_classes + 1) do ( var params : OclAny := in_file.next()->trim().split() ; assert (params)->size() - 1 = ("" + ((params->first())))->toInteger() do "assertion failed" ; inheritance[class_num+1] := params->tail()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))) ; var result : OclAny := solve(num_of_classes, inheritance) ; out_file.write(StringLib.format('Case #%d: %s ',Sequence{test_number + 1, result}))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numberOfSquares(base): base=(base-2) base=base/2 return base*(base+1)/2 base=8 print(numberOfSquares(base)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; base := 8 ; execute (numberOfSquares(base))->display(); operation numberOfSquares(base : OclAny) : OclAny pre: true post: true activity: base := (base - 2) ; base := base / 2 ; return base * (base + 1) / 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def findSurfaceArea(a,h): Area=0 ; Area=(6*a*h+3*math.sqrt(3)*a*a); print("Surface Area:",round(Area,3)); def findVolume(a,h): Volume=0 ; Volume=(3*math.sqrt(3)*a*a*h/2); print("Volume:",round(Volume,3)); a=5 ; h=10 ; findSurfaceArea(a,h); findVolume(a,h); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; a := 5; ; h := 10; ; findSurfaceArea(a, h); ; findVolume(a, h);; operation findSurfaceArea(a : OclAny, h : OclAny) pre: true post: true activity: var Area : int := 0; ; Area := (6 * a * h + 3 * (3)->sqrt() * a * a); ; execute ("Surface Area:")->display();; operation findVolume(a : OclAny, h : OclAny) pre: true post: true activity: var Volume : int := 0; ; Volume := (3 * (3)->sqrt() * a * a * h / 2); ; execute ("Volume:")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def isPrime(N): k=int(sqrt(N))+1 for i in range(2,k,1): if(N % i==0): return False return True def getDifference(N): if(N==0): return 2 elif(N==1): return 1 elif(isPrime(N)): return 0 aboveN=-1 belowN=-1 n1=N+1 while(True): if(isPrime(n1)): aboveN=n1 break else : n1+=1 n1=N-1 while(True): if(isPrime(n1)): belowN=n1 break else : n1-=1 diff1=aboveN-N diff2=N-belowN return min(diff1,diff2) if __name__=='__main__' : N=25 print(getDifference(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( N := 25 ; execute (getDifference(N))->display() ) else skip; operation isPrime(N : OclAny) : OclAny pre: true post: true activity: var k : int := ("" + ((sqrt(N))))->toInteger() + 1 ; for i : Integer.subrange(2, k-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (N mod i = 0) then ( return false ) else skip) ; return true; operation getDifference(N : OclAny) : OclAny pre: true post: true activity: if (N = 0) then ( return 2 ) else (if (N = 1) then ( return 1 ) else (if (isPrime(N)) then ( return 0 ) else skip ) ) ; var aboveN : int := -1 ; var belowN : int := -1 ; var n1 : OclAny := N + 1 ; while (true) do ( if (isPrime(n1)) then ( aboveN := n1 ; break ) else ( n1 := n1 + 1 )) ; n1 := N - 1 ; while (true) do ( if (isPrime(n1)) then ( belowN := n1 ; break ) else ( n1 := n1 - 1 )) ; var diff1 : double := aboveN - N ; var diff2 : double := N - belowN ; return Set{diff1, diff2}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(input()) cnt=s.count('W') a=[i for i,x in enumerate(s)if x=='W'] ans=0 for i in range(cnt): ans+=a[i]-i print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var cnt : int := s->count('W') ; var a : Sequence := Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} )->select(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in x = 'W')->collect(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in (i)) ; var ans : int := 0 ; for i : Integer.subrange(0, cnt-1) do ( ans := ans + a[i+1] - i) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from heapq import heappush,heappop from bisect import bisect_left,bisect_right import sys,random,itertools,math sys.setrecursionlimit(10**5) input=sys.stdin.readline sqrt=math.sqrt def LI(): return list(map(int,input().split())) def LF(): return list(map(float,input().split())) def LI_(): return list(map(lambda x : int(x)-1,input().split())) def II(): return int(input()) def IF(): return float(input()) def LS(): return list(map(list,input().split())) def S(): return list(input().rstrip()) def IR(n): return[II()for _ in range(n)] def LIR(n): return[LI()for _ in range(n)] def FR(n): return[IF()for _ in range(n)] def LFR(n): return[LI()for _ in range(n)] def LIR_(n): return[LI_()for _ in range(n)] def SR(n): return[S()for _ in range(n)] def LSR(n): return[LS()for _ in range(n)] mod=1000000007 inf=1e10 def solve(): s=S() ans=0 w=0 for i,si in enumerate(s): if si=="W" : ans+=i-w w+=1 print(ans) return if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(5)) ; var input : OclAny := (OclFile["System.in"]).readline ; var sqrt : OclAny := ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : int := 1000000007 ; var Math_PINFINITY : double := ("1e10")->toReal() ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LF() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["double"])->apply(_x) )); operation LI_() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) )); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation IF() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation LS() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["Sequence"])->apply(_x) )); operation S() : OclAny pre: true post: true activity: return (input().rstrip()); operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (II())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI())); operation FR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (IF())); operation LFR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI())); operation LIR_(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI_())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LS())); operation solve() pre: true post: true activity: var s : OclAny := S() ; var ans : int := 0 ; var w : int := 0 ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var si : OclAny := _tuple->at(_indx); if si = "W" then ( ans := ans + i - w ; w := w + 1 ) else skip) ; execute (ans)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def query_sum(bit,idx): sum_=0 while idx>0 : sum_+=bit[idx] idx-=idx &-idx return sum_ def add_sum(bit,idx,value): while idx<=len(bit): bit[idx]+=value idx+=idx &-idx S=input() bit=[0]*(len(S)+1000) num_whites=0 for i,char in enumerate(S,start=1): if char=="W" : add_sum(bit,i,1) num_whites+=1 num_flips=0 for i,char in enumerate(S,start=1): if char=="B" : this_num_flips=num_whites-query_sum(bit,i) num_flips+=this_num_flips print(num_flips) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var S : String := (OclFile["System.in"]).readLine() ; bit := MatrixLib.elementwiseMult(Sequence{ 0 }, ((S)->size() + 1000)) ; var num_whites : int := 0 ; for _tuple : Integer.subrange(1, (S, (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->size())->collect( _indx | Sequence{_indx-1, (S, (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var char : OclAny := _tuple->at(_indx); if char = "W" then ( add_sum(bit, i, 1) ; num_whites := num_whites + 1 ) else skip) ; var num_flips : int := 0 ; for _tuple : Integer.subrange(1, (S, (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->size())->collect( _indx | Sequence{_indx-1, (S, (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var char : OclAny := _tuple->at(_indx); if char = "B" then ( var this_num_flips : double := num_whites - query_sum(bit, i) ; num_flips := num_flips + this_num_flips ) else skip) ; execute (num_flips)->display(); operation query_sum(bit : OclAny, idx : OclAny) : OclAny pre: true post: true activity: var sum_ : int := 0 ; while idx > 0 do ( sum_ := sum_ + bit[idx+1] ; idx := idx - MathLib.bitwiseAnd(idx, -idx)) ; return sum_; operation add_sum(bit : OclAny, idx : OclAny, value : OclAny) pre: true post: true activity: while (idx->compareTo((bit)->size())) <= 0 do ( bit[idx+1] := bit[idx+1] + value ; idx := idx + MathLib.bitwiseAnd(idx, -idx)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,setrecursionlimit def main(): input=stdin.buffer.readline s=list(input()[:-1].decode()) ans=0 count=0 for i in range(len(s)): if s[i]=='W' : ans+=i-count count+=1 print(ans) if __name__=="__main__" : setrecursionlimit(10000) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( setrecursionlimit(10000) ; main() ) else skip; operation main() pre: true post: true activity: var input : OclAny := stdin.buffer.readline ; var s : Sequence := (input()->front().decode()) ; var ans : int := 0 ; var count : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = 'W' then ( ans := ans + i - count ; count := count + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- gos=input() ans=0 longgo=len(gos) whites=0 for i in range(longgo): if gos[i]=='W' : ans+=i whites+=1 else : pass def triangle(n): ret=0 i=n while(i>0): ret+=i i=i-1 return ret print(ans-triangle(whites-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var gos : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; var longgo : int := (gos)->size() ; var whites : int := 0 ; for i : Integer.subrange(0, longgo-1) do ( if gos[i+1] = 'W' then ( ans := ans + i ; whites := whites + 1 ) else ( skip )) ; skip ; execute (ans - triangle(whites - 1))->display(); operation triangle(n : OclAny) : OclAny pre: true post: true activity: var ret : int := 0 ; var i : OclAny := n ; while (i > 0) do ( ret := ret + i ; i := i - 1) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxi(x,y): if x>y : return x else : return y def longestPalindromic(strn,i,j,count): if i>j : return count if i==j : return(count+1) if strn[i]==strn[j]: count=longestPalindromic(strn,i+1,j-1,count+2) return maxi(count,maxi(longestPalindromic(strn,i+1,j,0),longestPalindromic(strn,i,j-1,0))) return maxi(longestPalindromic(strn,i+1,j,0),longestPalindromic(strn,i,j-1,0)) def longest_palindromic_substr(strn): k=len(strn)-1 return longestPalindromic(strn,0,k,0) strn="aaaabbaa" print(longest_palindromic_substr(strn)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; strn := "aaaabbaa" ; execute (longest_palindromic_substr(strn))->display(); operation maxi(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (x->compareTo(y)) > 0 then ( return x ) else ( return y ); operation longestPalindromic(strn : OclAny, i : OclAny, j : OclAny, count : OclAny) : OclAny pre: true post: true activity: if (i->compareTo(j)) > 0 then ( return count ) else skip ; if i = j then ( return (count + 1) ) else skip ; if strn[i+1] = strn[j+1] then ( count := longestPalindromic(strn, i + 1, j - 1, count + 2) ; return maxi(count, maxi(longestPalindromic(strn, i + 1, j, 0), longestPalindromic(strn, i, j - 1, 0))) ) else skip ; return maxi(longestPalindromic(strn, i + 1, j, 0), longestPalindromic(strn, i, j - 1, 0)); operation longest_palindromic_substr(strn : OclAny) : OclAny pre: true post: true activity: var k : double := (strn)->size() - 1 ; return longestPalindromic(strn, 0, k, 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k,m=map(int,input().split()) a=list(map(int,input().split())) e={} for item in a : u=item % m if e.get(u): e[u].append(item) else : e[u]=[item] things=sorted(list(e.values()),key=lambda x : len(x),reverse=True) the_one=things[0] if len(the_one)collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var e : OclAny := Set{} ; for item : a do ( var u : int := item mod m ; if e.get(u) then ( (expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name item)))))))) )))) ) else ( e[u+1] := Sequence{ item } )) ; var things : Sequence := (e.values())->sortedBy($x | (lambda x : OclAny in ((x)->size()))->apply($x)) ; var the_one : OclAny := things->first() ; if ((the_one)->size()->compareTo(k)) < 0 then ( execute ("No")->display() ) else ( execute ("Yes")->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name the_one)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name k)))))))) ]))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from collections import OrderedDict def check(m,nums,S): tmp=0 tmparr=[nums[i]for i in range(len(nums))] for i in range(len(nums)): tmparr[i]+=(i+1)*m ans=math.inf tmparr.sort() for i in range(m): tmp+=tmparr[i] return tmp def solve(n,k,m,nums): od=OrderedDict() d=dict() found=False ansfound=False keymain=-1 for i in range(len(nums)): d[nums[i]% m]=d.get(nums[i]% m,0)+1 if d[nums[i]% m]>=k : ansfound=True keymain=nums[i]% m break if ansfound : print('Yes') for i in range(len(nums)): if nums[i]% m==keymain : print(nums[i],end=' ') k-=1 if k<=0 : break print() else : print('No') return arr=[int(j)for j in input().split()] nums=[int(k)for k in input().split()] solve(arr[0],arr[1],arr[2],nums) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var arr : Sequence := input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; nums := input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger())) ; solve(arr->first(), arr[1+1], arr[2+1], nums); operation check(m : OclAny, nums : OclAny, S : OclAny) : OclAny pre: true post: true activity: var tmp : int := 0 ; var tmparr : Sequence := Integer.subrange(0, (nums)->size()-1)->select(i | true)->collect(i | (nums[i+1])) ; for i : Integer.subrange(0, (nums)->size()-1) do ( tmparr[i+1] := tmparr[i+1] + (i + 1) * m) ; var ans : OclAny := ; tmparr := tmparr->sort() ; for i : Integer.subrange(0, m-1) do ( tmp := tmp + tmparr[i+1]) ; return tmp; operation solve(n : OclAny, k : OclAny, m : OclAny, nums : OclAny) pre: true post: true activity: var od : OclAny := () ; var d : Map := (arguments ( )) ; var found : boolean := false ; var ansfound : boolean := false ; var keymain : int := -1 ; for i : Integer.subrange(0, (nums)->size()-1) do ( d[nums[i+1] mod m+1] := d.get(nums[i+1] mod m, 0) + 1 ; if (d[nums[i+1] mod m+1]->compareTo(k)) >= 0 then ( ansfound := true ; keymain := nums[i+1] mod m ; break ) else skip) ; if ansfound then ( execute ('Yes')->display() ; for i : Integer.subrange(0, (nums)->size()-1) do ( if nums[i+1] mod m = keymain then ( execute (nums[i+1])->display() ; k := k - 1 ) else skip ; if k <= 0 then ( break ) else skip) ; execute (->display() ) else ( execute ('No')->display() ) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math as mt import bisect input=sys.stdin.readline t=1 def ncr_util(): inv[0]=inv[1]=1 fact[0]=fact[1]=1 for i in range(2,300001): inv[i]=(inv[i % p]*(p-p//i))% p for i in range(1,300001): inv[i]=(inv[i-1]*inv[i])% p fact[i]=(fact[i-1]*i)% p def solve(): s='ACL' for i in range(k): print(s,end="") print() for _ in range(t): k=int(input()) (solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var t : int := 1 ; skip ; skip ; for _anon : Integer.subrange(0, t-1) do ( var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; ; operation ncr_util() pre: true post: true activity: inv->first() := 1; var inv[1+1] : int := 1 ; fact->first() := 1; var fact[1+1] : int := 1 ; for i : Integer.subrange(2, 300001-1) do ( inv[i+1] := (inv[i mod p+1] * (p - p div i)) mod p) ; for i : Integer.subrange(1, 300001-1) do ( inv[i+1] := (inv[i - 1+1] * inv[i+1]) mod p ; fact[i+1] := (fact[i - 1+1] * i) mod p); operation solve() pre: true post: true activity: var s : String := 'ACL' ; for i : Integer.subrange(0, k-1) do ( execute (s)->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def rmsValue(arr,n): square=0 mean=0.0 root=0.0 for i in range(0,n): square+=(arr[i]**2) mean=(square/(float)(n)) root=math.sqrt(mean) return root if __name__=='__main__' : arr=[10,4,6,8] n=len(arr) print(rmsValue(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{10}->union(Sequence{4}->union(Sequence{6}->union(Sequence{ 8 }))) ; n := (arr)->size() ; execute (rmsValue(arr, n))->display() ) else skip; operation rmsValue(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var square : int := 0 ; var mean : double := 0.0 ; var root : double := 0.0 ; for i : Integer.subrange(0, n-1) do ( square := square + ((arr[i+1])->pow(2))) ; mean := (square / (OclType["double"])(n)) ; root := (mean)->sqrt() ; return root; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(5000) def check(i,graph,seen,mini): if seen[i]==True : return True,seen else : seen[i]=True for j in range(0,len(graph)): if graph[i][j]: res,seen=check(j,graph,seen,mini) if res : return True,seen return False,seen inFile=open('A-large.in','r') outFile=open('diamond.out','w') T=int(inFile.readline()) for n in range(1,T+1): N=int(inFile.readline()) graph=[[False for i in range(N)]for i in range(N)] for i in range(N): l=[int(x)for x in inFile.readline().split()] for j in range(1,len(l)): graph[i][l[j]-1]=True res=False for i in range(N): res,seen=check(i,graph,[False for i in range(N)],i+1) if res : break if res : print('Case #'+str(n)+': Yes') outFile.write('Case #'+str(n)+': Yes\n') else : print('Case #'+str(n)+': No') outFile.write('Case #'+str(n)+': No\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(5000) ; skip ; var inFile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('A-large.in')) ; var outFile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('diamond.out')) ; var T : int := ("" + ((inFile.readLine())))->toInteger() ; for n : Integer.subrange(1, T + 1-1) do ( var N : int := ("" + ((inFile.readLine())))->toInteger() ; graph := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Integer.subrange(0, N-1)->select(i | true)->collect(i | (false)))) ; for i : Integer.subrange(0, N-1) do ( var l : Sequence := inFile.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for j : Integer.subrange(1, (l)->size()-1) do ( graph[i+1][l[j+1] - 1+1] := true)) ; var res : boolean := false ; for i : Integer.subrange(0, N-1) do ( Sequence{res,seen} := check(i, graph, Integer.subrange(0, N-1)->select(i | true)->collect(i | (false)), i + 1) ; if res then ( break ) else skip) ; if res then ( execute ('Case #' + ("" + ((n))) + ': Yes')->display() ; outFile.write('Case #' + ("" + ((n))) + ': Yes ') ) else ( execute ('Case #' + ("" + ((n))) + ': No')->display() ; outFile.write('Case #' + ("" + ((n))) + ': No ') )); operation check(i : OclAny, graph : OclAny, seen : OclAny, mini : OclAny) : OclAny pre: true post: true activity: if seen[i+1] = true then ( return true, seen ) else ( seen[i+1] := true ) ; for j : Integer.subrange(0, (graph)->size()-1) do ( if graph[i+1][j+1] then ( var res : OclAny := null; Sequence{res,seen} := check(j, graph, seen, mini) ; if res then ( return true, seen ) else skip ) else skip) ; return false, seen; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from collections import OrderedDict def check(m,nums,S): tmp=0 tmparr=[nums[i]for i in range(len(nums))] for i in range(len(nums)): tmparr[i]+=(i+1)*m ans=math.inf tmparr.sort() for i in range(m): tmp+=tmparr[i] return tmp def solve(n,k,m,nums): od=OrderedDict() d=dict() found=False ansfound=False keymain=-1 for i in range(len(nums)): d[nums[i]% m]=d.get(nums[i]% m,0)+1 if d[nums[i]% m]>=k : ansfound=True keymain=nums[i]% m break if ansfound : print('Yes') for i in range(len(nums)): if nums[i]% m==keymain : print(nums[i],end=' ') k-=1 if k<=0 : break print() else : print('No') return arr=[int(j)for j in input().split()] nums=[int(k)for k in input().split()] solve(arr[0],arr[1],arr[2],nums) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var arr : Sequence := input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; nums := input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger())) ; solve(arr->first(), arr[1+1], arr[2+1], nums); operation check(m : OclAny, nums : OclAny, S : OclAny) : OclAny pre: true post: true activity: var tmp : int := 0 ; var tmparr : Sequence := Integer.subrange(0, (nums)->size()-1)->select(i | true)->collect(i | (nums[i+1])) ; for i : Integer.subrange(0, (nums)->size()-1) do ( tmparr[i+1] := tmparr[i+1] + (i + 1) * m) ; var ans : OclAny := ; tmparr := tmparr->sort() ; for i : Integer.subrange(0, m-1) do ( tmp := tmp + tmparr[i+1]) ; return tmp; operation solve(n : OclAny, k : OclAny, m : OclAny, nums : OclAny) pre: true post: true activity: var od : OclAny := () ; var d : Map := (arguments ( )) ; var found : boolean := false ; var ansfound : boolean := false ; var keymain : int := -1 ; for i : Integer.subrange(0, (nums)->size()-1) do ( d[nums[i+1] mod m+1] := d.get(nums[i+1] mod m, 0) + 1 ; if (d[nums[i+1] mod m+1]->compareTo(k)) >= 0 then ( ansfound := true ; keymain := nums[i+1] mod m ; break ) else skip) ; if ansfound then ( execute ('Yes')->display() ; for i : Integer.subrange(0, (nums)->size()-1) do ( if nums[i+1] mod m = keymain then ( execute (nums[i+1])->display() ; k := k - 1 ) else skip ; if k <= 0 then ( break ) else skip) ; execute (->display() ) else ( execute ('No')->display() ) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k,m=map(int,input().split()) a=list(map(int,input().split())) d={} for i in a : if i % m not in d : d[i % m]={} d[i % m][i]=1 else : if i not in d[i % m]: d[i % m][i]=1 else : d[i % m][i]+=1 for mod in d.keys(): count=0 flag=0 req=[] for num in d[mod].keys(): for i in range(d[mod][num]): count+=1 req.append(num) if count==k : flag=1 break if flag==1 : break if flag==1 : break if flag==1 : print("Yes") print(*req) else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var m : OclAny := null; Sequence{n,k,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := Set{} ; for i : a do ( if (d)->excludes(i mod m) then ( d[i mod m+1] := Set{} ; d[i mod m+1][i+1] := 1 ) else ( if (d[i mod m+1])->excludes(i) then ( d[i mod m+1][i+1] := 1 ) else ( d[i mod m+1][i+1] := d[i mod m+1][i+1] + 1 ) )) ; for mod : d.keys() do ( var count : int := 0 ; var flag : int := 0 ; var req : Sequence := Sequence{} ; for num : d[mod+1].keys() do ( for i : Integer.subrange(0, d[mod+1][num+1]-1) do ( count := count + 1 ; execute ((num) : req) ; if count = k then ( flag := 1 ; break ) else skip) ; if flag = 1 then ( break ) else skip) ; if flag = 1 then ( break ) else skip) ; if flag = 1 then ( execute ("Yes")->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name req))))))))->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys dp=[[[-1 for i in range(100)]for j in range(100)]for k in range(100)] def countString(m,n,arr,i): if(m<0 or n<0): return-sys.maxsize-1 if(i>=len(arr)): return 0 if(dp[m][n][i]!=-1): return dp[m][n][i] zero=0 one=0 for c in arr[i]: if(c=='0'): zero+=1 else : one+=1 x=1+countString(m-zero,n-one,arr,i+1) y=countString(m,n,arr,i+1) dp[m][n][i]=max(x,y) return dp[m][n][i] if __name__=='__main__' : arr=["10","0001","1","111001","0"] N=3 M=5 print(countString(M,N,arr,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var dp : Sequence := Integer.subrange(0, 100-1)->select(k | true)->collect(k | (Integer.subrange(0, 100-1)->select(j | true)->collect(j | (Integer.subrange(0, 100-1)->select(i | true)->collect(i | (-1)))))) ; skip ; if __name__ = '__main__' then ( arr := Sequence{"10"}->union(Sequence{"0001"}->union(Sequence{"1"}->union(Sequence{"111001"}->union(Sequence{ "0" })))) ; var N : int := 3 ; var M : int := 5 ; execute (countString(M, N, arr, 0))->display() ) else skip; operation countString(m : OclAny, n : OclAny, arr : OclAny, i : OclAny) : OclAny pre: true post: true activity: if (m < 0 or n < 0) then ( return -(trailer . (name maxsize)) - 1 ) else skip ; if ((i->compareTo((arr)->size())) >= 0) then ( return 0 ) else skip ; if (dp[m+1][n+1][i+1] /= -1) then ( return dp[m+1][n+1][i+1] ) else skip ; var zero : int := 0 ; var one : int := 0 ; for c : arr[i+1] do ( if (c = '0') then ( zero := zero + 1 ) else ( one := one + 1 )) ; var x : int := 1 + countString(m - zero, n - one, arr, i + 1) ; var y : OclAny := countString(m, n, arr, i + 1) ; dp[m+1][n+1][i+1] := Set{x, y}->max() ; return dp[m+1][n+1][i+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def LCM(arr,n): max_num=0 ; for i in range(n): if(max_num=2): for j in range(len(indexes)): arr[indexes[j]]=int(arr[indexes[j]]/x); res=res*x ; else : x+=1 ; for i in range(n): res=res*arr[i]; return res ; arr=[1,2,3,4,5,10,20,35]; n=len(arr); print(LCM(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{10}->union(Sequence{20}->union(Sequence{ 35 }))))))); ; n := (arr)->size(); ; execute (LCM(arr, n))->display();; operation LCM(arr : OclAny, n : OclAny) pre: true post: true activity: var max_num : int := 0; ; for i : Integer.subrange(0, n-1) do ( if ((max_num->compareTo(arr[i+1])) < 0) then ( max_num := arr[i+1]; ) else skip) ; var res : int := 1; ; var x : int := 2; ; while ((x->compareTo(max_num)) <= 0) do ( var indexes : Sequence := Sequence{}; ; for j : Integer.subrange(0, n-1) do ( if (arr[j+1] mod x = 0) then ( execute ((j) : indexes); ) else skip) ; if ((indexes)->size() >= 2) then ( for j : Integer.subrange(0, (indexes)->size()-1) do ( arr[indexes[j+1]+1] := ("" + ((arr[indexes[j+1]+1] / x)))->toInteger();) ; res := res * x; ) else ( x := x + 1; )) ; for i : Integer.subrange(0, n-1) do ( res := res * arr[i+1];) ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def min_elimination(n,arr): count=0 prev_val=arr[0] for i in range(1,n): curr_val=arr[i]; if(curr_val % 2==prev_val % 2): count=count+1 prev_val=curr_val return count arr=[1,2,3,7,9] n=len(arr) print(min_elimination(n,arr)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{7}->union(Sequence{ 9 })))) ; n := (arr)->size() ; execute (min_elimination(n, arr))->display();; operation min_elimination(n : OclAny, arr : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var prev_val : OclAny := arr->first() ; for i : Integer.subrange(1, n-1) do ( var curr_val : OclAny := arr[i+1]; ; if (curr_val mod 2 = prev_val mod 2) then ( count := count + 1 ) else skip ; prev_val := curr_val) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tn=int(input()) for t in range(1,tn+1): r,v=map(int,input().split()) mn,mx=0,v while mnv : mx=av-1 else : mn=av print("Case #%d: %d" %(t,mn)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var tn : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(1, tn + 1-1) do ( var r : OclAny := null; var v : OclAny := null; Sequence{r,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mn : OclAny := null; var mx : OclAny := null; Sequence{mn,mx} := Sequence{0,v} ; while (mn->compareTo(mx)) < 0 do ( var av : int := (mn + mx + 1) div 2 ; var tt : double := 2 * av * (r + av) - av ; if (tt->compareTo(v)) > 0 then ( var mx : double := av - 1 ) else ( var mn : int := av )) ; execute (StringLib.format("Case #%d: %d",Sequence{t, mn}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def paint_needed(r,n): return(2*r+1+2*(n-1))*n T=int(input()) for test in range(1,T+1): r,t=[int(x)for x in input().split()] lo,hi=1,t+1 while hi-lo>1 : med=(hi+lo)//2 if paint_needed(r,med)<=t : lo=med else : hi=med print('Case #{}:{}'.format(test,lo)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for test : Integer.subrange(1, T + 1-1) do ( var t : OclAny := null; Sequence{r,t} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var lo : OclAny := null; var hi : OclAny := null; Sequence{lo,hi} := Sequence{1,t + 1} ; while hi - lo > 1 do ( var med : int := (hi + lo) div 2 ; if (paint_needed(r, med)->compareTo(t)) <= 0 then ( var lo : int := med ) else ( var hi : int := med )) ; execute (StringLib.interpolateStrings('Case #{}:{}', Sequence{test, lo}))->display()); operation paint_needed(r : OclAny, n : OclAny) : OclAny pre: true post: true activity: return (2 * r + 1 + 2 * (n - 1)) * n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def comp(x,r): return 2*x*x+(3+2*r)*x+2*r+1 def solve(): R,T=map(int,input().split()) l=0 r=T+1 while l+1toInteger() ; for tn : Integer.subrange(0, T-1) do ( execute (StringLib.interpolateStrings("Case #{0}:{1}", Sequence{tn + 1, solve()}))->display()); operation comp(x : OclAny, r : OclAny) : OclAny pre: true post: true activity: return 2 * x * x + (3 + 2 * r) * x + 2 * r + 1; operation solve() : OclAny pre: true post: true activity: var R : OclAny := null; var T : OclAny := null; Sequence{R,T} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : int := 0 ; r := T + 1 ; while (l + 1->compareTo(r)) < 0 do ( var m : int := (l + r) div 2 ; if (comp(m - 1, R)->compareTo(T)) <= 0 then ( l := m ) else ( r := m )) ; return l; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def can(r,t,n): paint_needed=n*(2*r+1)+2*n*(n-1) return paint_needed<=t def solve(r,t): lo=1 hi=(t+1)//2 while lotoInteger() ; for tt : Integer.subrange(0, T-1) do ( Sequence{r,t} := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name tok)))))))) ))))))) (comp_for for (exprlist (expr (atom (name tok)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ; execute (StringLib.interpolateStrings('Case #{}:{}', Sequence{tt + 1, solve(r, t)}))->display()); operation can(r : OclAny, t : OclAny, n : OclAny) : OclAny pre: true post: true activity: var paint_needed : double := n * (2 * r + 1) + 2 * n * (n - 1) ; return (paint_needed->compareTo(t)) <= 0; operation solve(r : OclAny, t : OclAny) : OclAny pre: true post: true activity: var lo : int := 1 ; var hi : int := (t + 1) div 2 ; while (lo->compareTo(hi)) < 0 do ( var mid : int := (lo + hi + 1) div 2 ; if can(r, t, mid) then ( lo := mid ) else ( hi := mid - 1 )) ; return lo; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,n=map(int,raw_input().split()) p=[int(raw_input())for _ in xrange(m)] ce=[map(int,raw_input().split())for _ in xrange(n)] dp=[[float('inf')]*(m+1)for _ in xrange(n+1)] for i in xrange(n+1): dp[i][0]=0 for i in xrange(n): for j in xrange(1,m+1): if jcollect( _x | (OclType["int"])->apply(_x) ) ; var p : Sequence := xrange(m)->select(_anon | true)->collect(_anon | (("" + ((raw_input())))->toInteger())) ; var ce : Sequence := xrange(n)->select(_anon | true)->collect(_anon | ((raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var dp : Sequence := xrange(n + 1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ ("" + (('inf')))->toReal() }, (m + 1)))) ; for i : xrange(n + 1) do ( dp[i+1]->first() := 0) ; for i : xrange(n) do ( for j : xrange(1, m + 1) do ( if (j->compareTo(ce[i+1]->first())) < 0 then ( dp[i + 1+1][j+1] := Set{dp[i+1][j+1], ce[i+1][1+1]}->min() ; continue ) else skip ; dp[i + 1+1][j+1] := Set{dp[i+1][j+1], dp[i+1][j - ce[i+1]->first()+1] + ce[i+1][1+1]}->min())) ; p := p->sort() ; p := p->reverse() ; var sump : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (m + 1)) ; for i : xrange(m) do ( sump[i + 1+1] := sump[i + 1+1] + sump[i+1] + p[i+1]) ; var ans : int := 0 ; for i : xrange(1, m + 1) do ( ans := Set{ans, sump[i+1] - dp[n+1][i+1]}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import* inf=open('A-large.in') ouf=open('output.txt','w') input=lambda : inf.readline().strip() print=partial(print,file=ouf) def solve(): r,t=map(int,input().split()) le=1 ri=10**18 while le+1trim()) ; var print : OclAny := partial(print, (argument (test (logical_test (comparison (expr (atom (name file)))))) = (test (logical_test (comparison (expr (atom (name ouf)))))))) ; skip ; var tests : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for z : Integer.subrange(0, tests-1) do ( execute (StringLib.interpolateStrings("Case #{}: ", Sequence{z + 1}))->display() ; solve()) ; ouf.closeFile(); operation solve() pre: true post: true activity: var r : OclAny := null; var t : OclAny := null; Sequence{r,t} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var le : int := 1 ; var ri : double := (10)->pow(18) ; while (le + 1->compareTo(ri)) < 0 do ( var m : int := (le + ri) div 2 ; if ((2 * r + 1) * m + 2 * (m - 1) * m->compareTo(t)) <= 0 then ( le := m ) else ( ri := m )) ; execute (le)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inp=open('./A-large.in','r') outp=open('./A.out','w') T=int(inp.readline()) def solve(i): N=int(inp.readline()) classes=[] for n in range(N): classes.append(set([int(x)for x in inp.readline().replace('\n','').split(' ')][1 :])) for n in range(N): for m in range(N): if n+1 in classes[m]: k=len(classes[n])+len(classes[m]) classes[m]=classes[n]| classes[m] if len(classes[m])!=k : outp.write('Case #'+str(i)+': Yes\n') return outp.write('Case #'+str(i)+': No\n') for k in range(T): solve(k+1) inp.close() outp.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inp : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('./A-large.in')) ; var outp : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('./A.out')) ; var T : int := ("" + ((inp.readLine())))->toInteger() ; skip ; for k : Integer.subrange(0, T-1) do ( solve(k + 1)) ; inp.closeFile() ; outp.closeFile(); operation solve(i : OclAny) pre: true post: true activity: var N : int := ("" + ((inp.readLine())))->toInteger() ; var classes : Sequence := Sequence{} ; for n : Integer.subrange(0, N-1) do ( execute ((Set{}->union((inp.readLine().replace(' ', '').split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger()))->tail()))) : classes)) ; for n : Integer.subrange(0, N-1) do ( for m : Integer.subrange(0, N-1) do ( if (classes[m+1])->includes(n + 1) then ( var k : int := (classes[n+1])->size() + (classes[m+1])->size() ; classes[m+1] := MathLib.bitwiseOr(classes[n+1], classes[m+1]) ; if (classes[m+1])->size() /= k then ( outp.write('Case #' + ("" + ((i))) + ': Yes ') ; return ) else skip ) else skip)) ; outp.write('Case #' + ("" + ((i))) + ': No '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt R=3 C=3 def minInitialPoints(points): dp=[[0 for x in range(C+1)]for y in range(R+1)] m,n=R,C if points[m-1][n-1]>0 : dp[m-1][n-1]=1 else : dp[m-1][n-1]=abs(points[m-1][n-1])+1 for i in range(m-2,-1,-1): dp[i][n-1]=max(dp[i+1][n-1]-points[i][n-1],1) for i in range(2,-1,-1): dp[m-1][i]=max(dp[m-1][i+1]-points[m-1][i],1) for i in range(m-2,-1,-1): for j in range(n-2,-1,-1): min_points_on_exit=min(dp[i+1][j],dp[i][j+1]) dp[i][j]=max(min_points_on_exit-points[i][j],1) return dp[0][0] points=[[-2,-3,3],[-5,-10,1],[10,30,-5]] print("Minimum Initial Points Required:",minInitialPoints(points)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var R : int := 3 ; var C : int := 3 ; skip ; points := Sequence{Sequence{-2}->union(Sequence{-3}->union(Sequence{ 3 }))}->union(Sequence{Sequence{-5}->union(Sequence{-10}->union(Sequence{ 1 }))}->union(Sequence{ Sequence{10}->union(Sequence{30}->union(Sequence{ -5 })) })) ; execute ("Minimum Initial Points Required:")->display(); operation minInitialPoints(points : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, R + 1-1)->select(y | true)->collect(y | (Integer.subrange(0, C + 1-1)->select(x | true)->collect(x | (0)))) ; var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := Sequence{R,C} ; if points[m - 1+1][n - 1+1] > 0 then ( dp[m - 1+1][n - 1+1] := 1 ) else ( dp[m - 1+1][n - 1+1] := (points[m - 1+1][n - 1+1])->abs() + 1 ) ; for i : Integer.subrange(-1 + 1, m - 2)->reverse() do ( dp[i+1][n - 1+1] := Set{dp[i + 1+1][n - 1+1] - points[i+1][n - 1+1], 1}->max()) ; for i : Integer.subrange(-1 + 1, 2)->reverse() do ( dp[m - 1+1][i+1] := Set{dp[m - 1+1][i + 1+1] - points[m - 1+1][i+1], 1}->max()) ; for i : Integer.subrange(-1 + 1, m - 2)->reverse() do ( for j : Integer.subrange(-1 + 1, n - 2)->reverse() do ( var min_points_on_exit : OclAny := Set{dp[i + 1+1][j+1], dp[i+1][j + 1+1]}->min() ; dp[i+1][j+1] := Set{min_points_on_exit - points[i+1][j+1], 1}->max())) ; return dp->first()->first(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def judgeSquareSum(n): i=2 ; while(i*i<=n): count=0 ; if(n % i==0): while(n % i==0): count+=1 ; n=int(n/i); if(i % 4==3 and count % 2!=0): return False ; i+=1 ; return n % 4!=3 ; n=17 ; if(judgeSquareSum(n)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 17; ; if (judgeSquareSum(n)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ); operation judgeSquareSum(n : OclAny) pre: true post: true activity: var i : int := 2; ; while ((i * i->compareTo(n)) <= 0) do ( var count : int := 0; ; if (n mod i = 0) then ( while (n mod i = 0) do ( count := count + 1; ; n := ("" + ((n / i)))->toInteger();) ; if (i mod 4 = 3 & count mod 2 /= 0) then ( return false; ) else skip ) else skip ; i := i + 1;) ; return n mod 4 /= 3;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxSortedAdjacentDiff(arr,n): maxVal,minVal=arr[0],arr[0] for i in range(1,n): maxVal=max(maxVal,arr[i]) minVal=min(minVal,arr[i]) maxBucket=[INT_MIN]*(n-1) minBucket=[INT_MAX]*(n-1) delta=(maxVal-minVal)//(n-1) for i in range(0,n): if arr[i]==maxVal or arr[i]==minVal : continue index=(arr[i]-minVal)//delta if maxBucket[index]==INT_MIN : maxBucket[index]=arr[i] else : maxBucket[index]=max(maxBucket[index],arr[i]) if minBucket[index]==INT_MAX : minBucket[index]=arr[i] else : minBucket[index]=min(minBucket[index],arr[i]) prev_val,max_gap=minVal,0 for i in range(0,n-1): if minBucket[i]==INT_MAX : continue max_gap=max(max_gap,minBucket[i]-prev_val) prev_val=maxBucket[i] max_gap=max(max_gap,maxVal-prev_val) return max_gap if __name__=="__main__" : arr=[1,10,5] n=len(arr) INT_MIN,INT_MAX=float('-inf'),float('inf') print(maxSortedAdjacentDiff(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{10}->union(Sequence{ 5 })) ; n := (arr)->size() ; var INT_MIN : OclAny := null; var INT_MAX : OclAny := null; Sequence{INT_MIN,INT_MAX} := Sequence{("" + (('-inf')))->toReal(),("" + (('inf')))->toReal()} ; execute (maxSortedAdjacentDiff(arr, n))->display() ) else skip; operation maxSortedAdjacentDiff(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var maxVal : OclAny := null; var minVal : OclAny := null; Sequence{maxVal,minVal} := Sequence{arr->first(),arr->first()} ; for i : Integer.subrange(1, n-1) do ( var maxVal : OclAny := Set{maxVal, arr[i+1]}->max() ; var minVal : OclAny := Set{minVal, arr[i+1]}->min()) ; var maxBucket : Sequence := MatrixLib.elementwiseMult(Sequence{ INT_MIN }, (n - 1)) ; var minBucket : Sequence := MatrixLib.elementwiseMult(Sequence{ INT_MAX }, (n - 1)) ; var delta : int := (maxVal - minVal) div (n - 1) ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] = maxVal or arr[i+1] = minVal then ( continue ) else skip ; var index : int := (arr[i+1] - minVal) div delta ; if maxBucket[index+1] = INT_MIN then ( maxBucket[index+1] := arr[i+1] ) else ( maxBucket[index+1] := Set{maxBucket[index+1], arr[i+1]}->max() ) ; if minBucket[index+1] = INT_MAX then ( minBucket[index+1] := arr[i+1] ) else ( minBucket[index+1] := Set{minBucket[index+1], arr[i+1]}->min() )) ; var prev_val : OclAny := null; var max_gap : OclAny := null; Sequence{prev_val,max_gap} := Sequence{minVal,0} ; for i : Integer.subrange(0, n - 1-1) do ( if minBucket[i+1] = INT_MAX then ( continue ) else skip ; var max_gap : OclAny := Set{max_gap, minBucket[i+1] - prev_val}->max() ; var prev_val : OclAny := maxBucket[i+1]) ; max_gap := Set{max_gap, maxVal - prev_val}->max() ; return max_gap; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printTaxicab2(N): i,count=1,0 while(countcompareTo(N)) < 0) do ( var int_count : int := 0 ; for j : Integer.subrange(1, ("" + (((i)->pow(1.0 / 3))))->toInteger() + 1-1) do ( for k : Integer.subrange(j + 1, ("" + (((i)->pow(1.0 / 3))))->toInteger() + 1-1) do ( if (j * j * j + k * k * k = i) then ( int_count := int_count + 1 ) else skip)) ; if (int_count = 2) then ( count := count + 1 ; execute (count)->display() ) else skip ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=sorted(input()) t=sorted(input()) if ssort() ; var t : Sequence := (OclFile["System.in"]).readLine()->sort() ; if (s->compareTo(t(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))) < 0 then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a=input() b=input() res="".join(sorted(a))<"".join(reversed(sorted(b))) print("Yes" if res else "No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var res : boolean := (StringLib.sumStringsWithSeparator((a->sort()), "")->compareTo(StringLib.sumStringsWithSeparator(((b->sort())->reverse()), ""))) < 0 ; execute (if res then "Yes" else "No" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=sorted(list(input())) t=sorted(list(input()),reverse=True) s_iter=iter(s) t_iter=iter(t) len_s,len_t=len(s),len(t) for _ in range(min(len_s,len_t)): next_s=next(s_iter) next_t=next(t_iter) if next_s>next_t : print('No') break elif next_s=len_t : print('No') else : print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := ((OclFile["System.in"]).readLine())->characters()->sort() ; var t : Sequence := ((OclFile["System.in"]).readLine())->characters()->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var s_iter : OclAny := OclIterator.newOclIterator_Sequence(s) ; var t_iter : OclAny := OclIterator.newOclIterator_Sequence(t) ; var len_s : OclAny := null; var len_t : OclAny := null; Sequence{len_s,len_t} := Sequence{(s)->size(),(t)->size()} ; (compound_stmt for (exprlist (expr (atom (name _)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len_s))))))) , (argument (test (logical_test (comparison (expr (atom (name len_t)))))))) ))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name next_s)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name next)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s_iter)))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name next_t)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name next)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t_iter)))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name next_s)))) > (comparison (expr (atom (name next_t))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'No'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name next_s)))) < (comparison (expr (atom (name next_t))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'Yes'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name len_s)))) >= (comparison (expr (atom (name len_t))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'No'))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'Yes'))))))) ))))))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import Counter s=input() t=input() s_list=[] t_list=[] for i in s : s_list.append(ord(i)) for i in t : t_list.append(ord(i)) s_list.sort() t_list.sort(reverse=True) for i in range(min(len(s_list),len(t_list))): if t_list[i]>s_list[i]: print('Yes') sys.exit() if set(s_list)==set(t_list)and len(s_list)characters() do ( execute (((i)->char2byte()) : s_list)) ; for i : t->characters() do ( execute (((i)->char2byte()) : t_list)) ; s_list := s_list->sort() ; t_list := t_list->sort() ; for i : Integer.subrange(0, Set{(s_list)->size(), (t_list)->size()}->min()-1) do ( if (t_list[i+1]->compareTo(s_list[i+1])) > 0 then ( execute ('Yes')->display() ; sys.exit() ) else skip) ; if Set{}->union((s_list)) = Set{}->union((t_list)) & ((s_list)->size()->compareTo((t_list)->size())) < 0 then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=10**20 m,n=map(int,input().split()) manju_lst=[int(input())for i in range(m)] manju_lst.sort(reverse=True) acc=0 cum_sum=[0] for manju in manju_lst : acc+=manju cum_sum.append(acc) clst=[] elst=[] for i in range(n): c,e=map(int,input().split()) clst.append(c) elst.append(e) dp=[[INF]*(m+1)for _ in range(n)] for i in range(n): dp[i][0]=0 for x in range(n): cx=clst[x] ex=elst[x] for y in range(m,0,-1): if y>=cx : dp[x][y]=min(dp[x-1][y],dp[x-1][y-cx]+ex) else : if y+1<=m : dp[x][y]=min(dp[x-1][y],dp[x][y+1]) else : dp[x][y]=min(dp[x-1][y],ex) print(max([cum_sum[x]-dp[n-1][x]for x in range(m+1)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INF : double := (10)->pow(20) ; var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var manju_lst : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; manju_lst := manju_lst->sort() ; var acc : int := 0 ; var cum_sum : Sequence := Sequence{ 0 } ; for manju : manju_lst do ( acc := acc + manju ; execute ((acc) : cum_sum)) ; var clst : Sequence := Sequence{} ; var elst : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var c : OclAny := null; var e : OclAny := null; Sequence{c,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((c) : clst) ; execute ((e) : elst)) ; var dp : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ INF }, (m + 1)))) ; for i : Integer.subrange(0, n-1) do ( dp[i+1]->first() := 0) ; for x : Integer.subrange(0, n-1) do ( var cx : OclAny := clst[x+1] ; var ex : OclAny := elst[x+1] ; for y : Integer.subrange(0 + 1, m)->reverse() do ( if (y->compareTo(cx)) >= 0 then ( dp[x+1][y+1] := Set{dp[x - 1+1][y+1], dp[x - 1+1][y - cx+1] + ex}->min() ) else ( if (y + 1->compareTo(m)) <= 0 then ( dp[x+1][y+1] := Set{dp[x - 1+1][y+1], dp[x+1][y + 1+1]}->min() ) else ( dp[x+1][y+1] := Set{dp[x - 1+1][y+1], ex}->min() ) ))) ; execute ((Integer.subrange(0, m + 1-1)->select(x | true)->collect(x | (cum_sum[x+1] - dp[n - 1+1][x+1])))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys s=input() t=input() s1,t1="","" for i in range(len(s)): if i!=0 : if s1[0]>=s[i]: s1=s[i]+s1 else : s1+=s[i] else : s1=s[i] for i in range(len(t)): if i!=0 : if t1[0]<=t[i]: t1=t[i]+t1 else : t1+=t[i] if t1>s1 : print("Yes") sys.exit() else : t1=t[i] print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var s1 : OclAny := null; var t1 : OclAny := null; Sequence{s1,t1} := Sequence{"",""} ; for i : Integer.subrange(0, (s)->size()-1) do ( if i /= 0 then ( if (s1->first()->compareTo(s[i+1])) >= 0 then ( var s1 : OclAny := s[i+1] + s1 ) else ( s1 := s1 + s[i+1] ) ) else ( s1 := s[i+1] )) ; for i : Integer.subrange(0, (t)->size()-1) do ( if i /= 0 then ( if (t1->first()->compareTo(t[i+1])) <= 0 then ( var t1 : OclAny := t[i+1] + t1 ) else ( t1 := t1 + t[i+1] ) ; if (t1->compareTo(s1)) > 0 then ( execute ("Yes")->display() ; sys.exit() ) else skip ) else ( t1 := t[i+1] )) ; execute ("No")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sinkingShip(n,members): ordered_crew={'rat' :[],'woman' :[],'man' :[],'captain' :[]} for name,designation in members : if designation=='child' : designation='woman' ordered_crew[designation].append(name) return ordered_crew.values() def main(): n=int(input()) members=[] for _ in range(n): members.append(input().split()) for items in sinkingShip(n,members): if items : print('\n'.join(items)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation sinkingShip(n : OclAny, members : OclAny) : OclAny pre: true post: true activity: var ordered_crew : Map := Map{ 'rat' |-> Sequence{} }->union(Map{ 'woman' |-> Sequence{} }->union(Map{ 'man' |-> Sequence{} }->union(Map{ 'captain' |-> Sequence{} }))) ; for _tuple : members do (var _indx : int := 1; var name : OclAny := _tuple->at(_indx); _indx := _indx + 1; var designation : OclAny := _tuple->at(_indx); if designation = 'child' then ( var designation : String := 'woman' ) else skip ; (expr (atom (name ordered_crew)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name designation)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name name)))))))) ))))) ; return ordered_crew.values(); operation main() pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; members := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((input().split()) : members)) ; for items : sinkingShip(n, members) do ( if items then ( execute (StringLib.sumStringsWithSeparator((items), ' '))->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def GCD(M,N): while True : if Ncollect( _x | (OclType["int"])->apply(_x) ) ; var gcd : OclAny := GCD(x, y) ; var x : double := x / gcd ; var y : double := y / gcd ; execute (("" + ((x - 1 + y - 1 + 1)))->toInteger() * gcd + 1)->display(); operation GCD(M : OclAny, N : OclAny) : OclAny pre: true post: true activity: while true do ( if (N->compareTo(M)) < 0 then ( Sequence{N,M} := Sequence{M,N} ) else skip ; var amari : int := N mod M ; if amari = 0 then ( break ) else ( Sequence{N,M} := Sequence{M,amari} )) ; return M; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(3000) def diamond_inheritance(M): visited=set() for node in M : if not node in visited : curr_visited=set() if visit(M,node,curr_visited): return True visited.update(curr_visited) return False def visit(M,k,visited): for node in M[k]: if not node in visited : if visit(M,node,visited): return True else : return True visited.add(k) return False fi=open("A.in","r") fo=open("A.out","w") T=int(fi.readline()) for t in range(T): N=int(fi.readline()) M={} for i in range(N): line=map(int,fi.readline().split()) M[i+1]=line[1 :] result=diamond_inheritance(M) if result : fo.write('Case #{0}: Yes\n'.format(t+1)) else : fo.write('Case #{0}: No\n'.format(t+1)) fi.close() fo.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(3000) ; skip ; skip ; var fi : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("A.in")) ; var fo : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("A.out")) ; var T : int := ("" + ((fi.readLine())))->toInteger() ; for t : Integer.subrange(0, T-1) do ( var N : int := ("" + ((fi.readLine())))->toInteger() ; M := Set{} ; for i : Integer.subrange(0, N-1) do ( var line : Sequence := (fi.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; M[i + 1+1] := line->tail()) ; var result : OclAny := diamond_inheritance(M) ; if result then ( fo.write(StringLib.interpolateStrings('Case #{0}: Yes ', Sequence{t + 1})) ) else ( fo.write(StringLib.interpolateStrings('Case #{0}: No ', Sequence{t + 1})) )) ; fi.closeFile() ; fo.closeFile(); operation diamond_inheritance(M : OclAny) : OclAny pre: true post: true activity: var visited : Set := Set{}->union(()) ; for node : M do ( if not((visited)->includes(node)) then ( var curr_visited : Set := Set{}->union(()) ; if visit(M, node, curr_visited) then ( return true ) else skip ; execute ((curr_visited) <: visited) ) else skip) ; return false; operation visit(M : OclAny, k : OclAny, visited : OclAny) : OclAny pre: true post: true activity: for node : M[k+1] do ( if not((visited)->includes(node)) then ( if visit(M, node, visited) then ( return true ) else skip ) else ( return true )) ; execute ((k) : visited) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) o=dict(zip('tminp',[0,1,1,2,3])) a=sorted(enumerate([input().split()for _ in[0]*n]),key=lambda x :(o[x[1][1][2]],x[0])) for x in a : print(x[1][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var o : Map := ((expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'tminp')))))) , (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) , (test (logical_test (comparison (expr (atom (number (integer 1))))))) , (test (logical_test (comparison (expr (atom (number (integer 1))))))) , (test (logical_test (comparison (expr (atom (number (integer 2))))))) , (test (logical_test (comparison (expr (atom (number (integer 3)))))))) ]))))))) ))))) ; var a : Sequence := Integer.subrange(1, (MatrixLib.elementwiseMult(Sequence{ 0 }, n)->select(_anon | true)->collect(_anon | (input().split())))->size())->collect( _indx | Sequence{_indx-1, (MatrixLib.elementwiseMult(Sequence{ 0 }, n)->select(_anon | true)->collect(_anon | (input().split())))->at(_indx)} )->sortedBy($x | (lambda x : OclAny in (Sequence{o[x[1+1][1+1][2+1]+1], x->first()}))->apply($x)) ; for x : a do ( execute (x[1+1]->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ship(): n=int(input()) ar=[input().split()for i in range(n)] for i in[['rat'],['woman','child'],['man'],['captain']]: for j in ar : if j[1]in i : print(j[0]) ship() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; ship(); operation ship() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ar : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (input().split())) ; for i : Sequence{Sequence{ 'rat' }}->union(Sequence{Sequence{'woman'}->union(Sequence{ 'child' })}->union(Sequence{Sequence{ 'man' }}->union(Sequence{ Sequence{ 'captain' } }))) do ( for j : ar do ( if (i)->includes(j[1+1]) then ( execute (j->first())->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=[] for _ in range(n): name,role=input().split() arr.append((name,role)) for i in range(n): if arr[i][1]=='rat' : print(arr[i][0]) for i in range(n): if arr[i][1]=='woman' or arr[i][1]=='child' : print(arr[i][0]) for i in range(n): if arr[i][1]=='man' : print(arr[i][0]) for i in range(n): if arr[i][1]=='captain' : print(arr[i][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var name : OclAny := null; var role : OclAny := null; Sequence{name,role} := input().split() ; execute ((Sequence{name, role}) : arr)) ; for i : Integer.subrange(0, n-1) do ( if arr[i+1][1+1] = 'rat' then ( execute (arr[i+1]->first())->display() ) else skip) ; for i : Integer.subrange(0, n-1) do ( if arr[i+1][1+1] = 'woman' or arr[i+1][1+1] = 'child' then ( execute (arr[i+1]->first())->display() ) else skip) ; for i : Integer.subrange(0, n-1) do ( if arr[i+1][1+1] = 'man' then ( execute (arr[i+1]->first())->display() ) else skip) ; for i : Integer.subrange(0, n-1) do ( if arr[i+1][1+1] = 'captain' then ( execute (arr[i+1]->first())->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) rat=[] wAc=[] man=[] captin=[] for i in range(n): name=input().split() if name[1]=='captain' : captin.append(name[0]) elif name[1]=='rat' : rat.append(name[0]) elif name[1]=='woman' or name[1]=='child' : wAc.append(name[0]) else : man.append(name[0]) if rat : print(*rat,sep='\n') if wAc : print(*wAc,sep='\n') if man : print(*man,sep='\n') if captin : print(*captin,sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var rat : Sequence := Sequence{} ; var wAc : Sequence := Sequence{} ; var man : Sequence := Sequence{} ; var captin : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var name : OclAny := input().split() ; if name[1+1] = 'captain' then ( execute ((name->first()) : captin) ) else (if name[1+1] = 'rat' then ( execute ((name->first()) : rat) ) else (if name[1+1] = 'woman' or name[1+1] = 'child' then ( execute ((name->first()) : wAc) ) else ( execute ((name->first()) : man) ) ) ) ) ; if rat then ( execute ((argument * (test (logical_test (comparison (expr (atom (name rat))))))))->display() ) else skip ; if wAc then ( execute ((argument * (test (logical_test (comparison (expr (atom (name wAc))))))))->display() ) else skip ; if man then ( execute ((argument * (test (logical_test (comparison (expr (atom (name man))))))))->display() ) else skip ; if captin then ( execute ((argument * (test (logical_test (comparison (expr (atom (name captin))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def squareRootExists(n,p): n=n % p for x in range(2,p,1): if((x*x)% p==n): return True return False if __name__=='__main__' : p=7 n=2 if(squareRootExists(n,p)==True): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( p := 7 ; n := 2 ; if (squareRootExists(n, p) = true) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation squareRootExists(n : OclAny, p : OclAny) : OclAny pre: true post: true activity: n := n mod p ; for x : Integer.subrange(2, p-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if ((x * x) mod p = n) then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) ar=list(map(int,input().split(" "))) br=list(map(int,input().split(" "))) cr=[] for i in range(1,a+1): count=sum(ar[0 : i])+sum(br[i-1 : a]) cr.append(count) print(max(cr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ar : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var br : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var cr : Sequence := Sequence{} ; for i : Integer.subrange(1, a + 1-1) do ( var count : OclAny := (ar.subrange(0+1, i))->sum() + (br.subrange(i - 1+1, a))->sum() ; execute ((count) : cr)) ; execute ((cr)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=10**20 def main(): m,n=map(int,input().split()) manju_lst=[int(input())for i in range(m)] manju_lst.sort(reverse=True) acc=0 cum_sum=[0] for manju in manju_lst : acc+=manju cum_sum.append(acc) clst=[] elst=[] for i in range(n): c,e=map(int,input().split()) clst.append(c) elst.append(e) dp=[[INF]*(m+1)for _ in range(n+1)] for i in range(n+1): dp[i][0]=0 for x in range(1,n+1): cx=clst[x-1] ex=elst[x-1] predp=dp[x-1] for y in range(m,0,-1): predp_y=predp[y] if y>=cx : comp=predp[y-cx]+ex elif y+1<=m : comp=dp[x][y+1] else : comp=ex if predp_y<=comp : dp[x][y]=predp_y else : dp[x][y]=comp dpn=dp[n] print(max([cum_sum[x]-dpn[x]for x in range(m+1)])) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INF : double := (10)->pow(20) ; skip ; main(); operation main() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var manju_lst : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; manju_lst := manju_lst->sort() ; var acc : int := 0 ; var cum_sum : Sequence := Sequence{ 0 } ; for manju : manju_lst do ( acc := acc + manju ; execute ((acc) : cum_sum)) ; var clst : Sequence := Sequence{} ; var elst : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var c : OclAny := null; var e : OclAny := null; Sequence{c,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((c) : clst) ; execute ((e) : elst)) ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ INF }, (m + 1)))) ; for i : Integer.subrange(0, n + 1-1) do ( dp[i+1]->first() := 0) ; for x : Integer.subrange(1, n + 1-1) do ( var cx : OclAny := clst[x - 1+1] ; var ex : OclAny := elst[x - 1+1] ; var predp : OclAny := dp[x - 1+1] ; for y : Integer.subrange(0 + 1, m)->reverse() do ( var predp_y : OclAny := predp[y+1] ; if (y->compareTo(cx)) >= 0 then ( var comp : OclAny := predp[y - cx+1] + ex ) else (if (y + 1->compareTo(m)) <= 0 then ( comp := dp[x+1][y + 1+1] ) else ( comp := ex ) ) ; if (predp_y->compareTo(comp)) <= 0 then ( dp[x+1][y+1] := predp_y ) else ( dp[x+1][y+1] := comp ))) ; var dpn : OclAny := dp[n+1] ; execute ((Integer.subrange(0, m + 1-1)->select(x | true)->collect(x | (cum_sum[x+1] - dpn[x+1])))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) _A1=[int(x)for x in input().split()] _A2=[int(x)for x in input().split()] A1=[0]*(N) A2=[0]*(N) for i in range(0,N): if i==0 : A1[i]=_A1[i] A2[i]=_A2[i] else : A1[i]=A1[i-1]+_A1[i] A2[i]=A2[i-1]+_A2[i] sum=0 for i in range(0,N): u=A1[i] if i==0 : d=A2[N-1] else : d=A2[N-1]-A2[i-1] sum=max(u+d,sum) print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var _A1 : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var _A2 : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var A1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N)) ; var A2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N)) ; for i : Integer.subrange(0, N-1) do ( if i = 0 then ( A1[i+1] := _A1[i+1] ; A2[i+1] := _A2[i+1] ) else ( A1[i+1] := A1[i - 1+1] + _A1[i+1] ; A2[i+1] := A2[i - 1+1] + _A2[i+1] )) ; var sum : int := 0 ; for i : Integer.subrange(0, N-1) do ( var u : OclAny := A1[i+1] ; if i = 0 then ( var d : OclAny := A2[N - 1+1] ) else ( d := A2[N - 1+1] - A2[i - 1+1] ) ; sum := Set{u + d, sum}->max()) ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) arr=[list(map(int,input().rstrip().split()))for _ in range(2)] ans=0 for i in range(n): ans=max(ans,sum(arr[0][: i+1])+sum(arr[1][i :])) print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Integer.subrange(0, 2-1)->select(_anon | true)->collect(_anon | (((input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( ans := Set{ans, (arr->first().subrange(1,i + 1))->sum() + (arr[1+1].subrange(i+1))->sum()}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin N=int(stdin.readline().rstrip()) A=[[int(x)for x in stdin.readline().rstrip().split()]for _ in range(2)] dp=[[0]*N for _ in range(2)] for n in range(N): dp[0][n]=sum(A[0][: n+1]) dp[1][0]=A[0][0]+A[1][0] for n in range(1,N): dp[1][n]=max(dp[0][n],dp[1][n-1])+A[1][n] print(dp[1][N-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + ((stdin.readLine().rstrip())))->toInteger() ; var A : Sequence := Integer.subrange(0, 2-1)->select(_anon | true)->collect(_anon | (stdin.readLine().rstrip().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))) ; var dp : Sequence := Integer.subrange(0, 2-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, N))) ; for n : Integer.subrange(0, N-1) do ( dp->first()[n+1] := (A->first().subrange(1,n + 1))->sum()) ; dp[1+1]->first() := A->first()->first() + A[1+1]->first() ; for n : Integer.subrange(1, N-1) do ( dp[1+1][n+1] := Set{dp->first()[n+1], dp[1+1][n - 1+1]}->max() + A[1+1][n+1]) ; execute (dp[1+1][N - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate def inpl(): return tuple(map(int,input().split())) N=int(input()) A=inpl() B=inpl() res=0 for i in range(N): res=max(res,sum(A[: i+1])+sum(B[i :])) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : OclAny := inpl() ; var B : OclAny := inpl() ; var res : int := 0 ; for i : Integer.subrange(0, N-1) do ( res := Set{res, (A.subrange(1,i + 1))->sum() + (B.subrange(i+1))->sum()}->max()) ; execute (res)->display(); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib,fractions def compute(): LIMIT=1500000 triples=set() for s in range(3,eulerlib.sqrt(LIMIT)+1,2): for t in range(s-2,0,-2): if fractions.gcd(s,t)==1 : a=s*t b=(s*s-t*t)//2 c=(s*s+t*t)//2 if a+b+c<=LIMIT : triples.add((a,b,c)) ways=[0]*(LIMIT+1) for triple in triples : sigma=sum(triple) for i in range(sigma,len(ways),sigma): ways[i]+=1 ans=ways.count(1) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LIMIT : int := 1500000 ; var triples : Set := Set{}->union(()) ; for s : Integer.subrange(3, eulerlib.sqrt(LIMIT) + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( for t : Integer.subrange(s - 2, 0-1)->select( $x | ($x - s - 2) mod -2 = 0 ) do ( if fractions.gcd(s, t) = 1 then ( var a : double := s * t ; var b : int := (s * s - t * t) div 2 ; var c : int := (s * s + t * t) div 2 ; if (a + b + c->compareTo(LIMIT)) <= 0 then ( execute ((Sequence{a, b, c}) : triples) ) else skip ) else skip)) ; var ways : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (LIMIT + 1)) ; for triple : triples do ( var sigma : OclAny := (triple)->sum() ; for i : Integer.subrange(sigma, (ways)->size()-1)->select( $x | ($x - sigma) mod sigma = 0 ) do ( ways[i+1] := ways[i+1] + 1)) ; var ans : int := ways->count(1) ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def mask(n): n1=str(n) n2=[int(i)for i in n1] m=[] for j in n2 : if j==4 or j==7 : m.append(j) if m==[]: m.append(0) m1="".join(str(ele)for ele in m) return int(m1) L=input().split() a=int(L[0]) b=int(L[1]) i=a+1 while i>a and mask(i)!=b : i=i+1 print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var L : OclAny := input().split() ; var a : int := ("" + ((L->first())))->toInteger() ; var b : int := ("" + ((L[1+1])))->toInteger() ; var i : int := a + 1 ; while (i->compareTo(a)) > 0 & mask(i) /= b do ( i := i + 1) ; execute (i)->display(); operation mask(n : OclAny) : OclAny pre: true post: true activity: var n1 : String := ("" + ((n))) ; var n2 : Sequence := n1->characters()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var m : Sequence := Sequence{} ; for j : n2 do ( if j = 4 or j = 7 then ( execute ((j) : m) ) else skip) ; if m = Sequence{} then ( execute ((0) : m) ) else skip ; var m1 : String := StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ele)))))))) ))))))) (comp_for for (exprlist (expr (atom (name ele)))) in (logical_test (comparison (expr (atom (name m)))))))), "") ; return ("" + ((m1)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) for i in range(a,1777778): x=str(i) y="" for j in x : if(j=='4' or j=='7'): y+=j if(y==""): y="0" if(int(y)==b and i>a): print(x) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(a, 1777778-1) do ( var x : String := ("" + ((i))) ; var y : String := "" ; for j : x->characters() do ( if (j = '4' or j = '7') then ( y := y + j ) else skip) ; if (y = "") then ( y := "0" ) else skip ; if (("" + ((y)))->toInteger() = b & (i->compareTo(a)) > 0) then ( execute (x)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def fx(a): sa=str(a) m="" for i in range(len(sa)): if sa[i]=='4' or sa[i]=='7' : m+=sa[i] if len(m)>0 : n=int(m) else : n=0 return n a,b=map(int,input().split()) while 1 : a+=1 x=fx(a) if x==b : print(a) exit(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; while 1 do ( a := a + 1 ; var x : OclAny := fx(a) ; if x = b then ( execute (a)->display() ; exit(0) ) else skip); operation fx(a : OclAny) : OclAny pre: true post: true activity: var sa : String := ("" + ((a))) ; var m : String := "" ; for i : Integer.subrange(0, (sa)->size()-1) do ( if sa[i+1] = '4' or sa[i+1] = '7' then ( m := m + sa[i+1] ) else skip) ; if (m)->size() > 0 then ( var n : int := ("" + ((m)))->toInteger() ) else ( n := 0 ) ; return n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def mask(n): res="" for c in n : if(c=='4' or c=='7'): res+=c return res [a,b]=[i for i in input().split(" ")] k=int(a)+1 while(mask(str(k))!=mask(b)): k+=1 print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{a}->union(Sequence{ b }) := input().split(" ")->select(i | true)->collect(i | (i)) ; var k : int := ("" + ((a)))->toInteger() + 1 ; while (mask(("" + ((k)))) /= mask(b)) do ( k := k + 1) ; execute (k)->display(); operation mask(n : OclAny) : OclAny pre: true post: true activity: var res : String := "" ; for c : n do ( if (c = '4' or c = '7') then ( res := res + c ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def mask(n): ans="" for i in str(n): if i=="4" or i=="7" : ans+=i return ans a,b=input().split() a=int(a)+1 while mask(a)!=b : a+=1 print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; var a : int := ("" + ((a)))->toInteger() + 1 ; while mask(a) /= b do ( a := a + 1) ; execute (a)->display(); operation mask(n : OclAny) : OclAny pre: true post: true activity: var ans : String := "" ; for i : ("" + ((n))) do ( if i = "4" or i = "7" then ( ans := ans + i ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Heap : def __init__(self): self._nodes=[] @ classmethod def create(cls,li): heap=cls() heap._nodes=li return heap def __iter__(self): self.cur=0 return self def __next__(self): if self.cur>=len(self._nodes): raise StopIteration self.cur+=1 node=self._nodes[self.cur-1] if self.cur//2-1>=0 : parent=self._nodes[self.cur//2-1] else : parent=None if self.cur*2-1exists( _x | result = _x ); attribute _nodes : Sequence := Sequence{}; operation initialise() : Heap pre: true post: true activity: self._nodes := Sequence{}; return self; operation __iter__() : OclAny pre: true post: true activity: self.cur := 0 ; return self; operation __next__() : OclAny pre: true post: true activity: if (self.cur->compareTo((self._nodes)->size())) >= 0 then ( error StopIteration.newStopIteration ) else skip ; self.cur := self.cur + 1 ; var node : OclAny := self._nodes[self.cur - 1+1] ; if self.cur div 2 - 1 >= 0 then ( var parent : OclAny := self._nodes[self.cur div 2 - 1+1] ) else ( parent := null ) ; if (self.cur * 2 - 1->compareTo((self._nodes)->size())) < 0 then ( var left : OclAny := self._nodes[self.cur * 2 - 1+1] ) else ( left := null ) ; if (self.cur * 2->compareTo((self._nodes)->size())) < 0 then ( var right : OclAny := self._nodes[self.cur * 2+1] ) else ( right := null ) ; return Sequence{node, parent, left, right}; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( run() ) else skip; operation run() pre: true post: true activity: var _anon : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nodes : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; heap := (Heap.newHeap()).initialise.create(nodes) ; for Sequence{i, node} : Integer.subrange(1, (heap)->size())->collect( _indx | Sequence{_indx-1, (heap)->at(_indx)} ) do ( var n : OclAny := null; var p : OclAny := null; var nl : OclAny := null; var nr : OclAny := null; Sequence{n,p,nl,nr} := node ; var s : String := StringLib.interpolateStrings("node{}: key={},", Sequence{i + 1, n}) ; if not(p <>= null) then ( s := s + StringLib.interpolateStrings("parent key={},", Sequence{p}) ) else skip ; if not(nl <>= null) then ( s := s + StringLib.interpolateStrings("left key={},", Sequence{nl}) ) else skip ; if not(nr <>= null) then ( s := s + StringLib.interpolateStrings("right key={},", Sequence{nr}) ) else skip ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calc(n,m): ans=0 while(m>1): ans+=n//m n,m=m,n % m if m==0 : return float("inf") return ans+n-1 n=int(input()) ans=n-1 for i in range(1,n+1): ans=min(ans,calc(n,i)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; ans := n - 1 ; for i : Integer.subrange(1, n + 1-1) do ( ans := Set{ans, calc(n, i)}->min()) ; execute (ans)->display(); operation calc(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; while (m > 1) do ( ans := ans + n div m ; Sequence{n,m} := Sequence{m,n mod m}) ; if m = 0 then ( return ("" + (("inf")))->toReal() ) else skip ; return ans + n - 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n): ans=n-1 for i in range(2,n//2+1): j=n k=0 while i>1 and j>1 : k+=1 if j>=i : j-=i else : i-=j if i<1 or j<1 : continue elif i==1 : ans=min(ans,k+j-1) elif j==1 : ans=min(ans,k+i-1) return ans if __name__=="__main__" : ans=solve(int(input())) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( ans := solve(("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; execute (ans)->display() ) else skip; operation solve(n : OclAny) : OclAny pre: true post: true activity: var ans : double := n - 1 ; for i : Integer.subrange(2, n div 2 + 1-1) do ( var j : OclAny := n ; var k : int := 0 ; while i > 1 & j > 1 do ( k := k + 1 ; if (j->compareTo(i)) >= 0 then ( j := j - i ) else ( i := i - j )) ; if i < 1 or j < 1 then ( continue ) else (if i = 1 then ( ans := Set{ans, k + j - 1}->min() ) else (if j = 1 then ( ans := Set{ans, k + i - 1}->min() ) else skip ) ) ) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as m def hcf(a,b): while(a!=b): if(a>b): a=a-b else : b=b-a return a n=int(input()) if(n==1 or n==2): print(n-1) exit() mnm=m.inf for k in range(m.ceil(n/2),n): if(hcf(n,k)!=1): continue p=k q=n-k count=2 while(p!=2): diff=p-q if(q>diff): p=q q=diff else : p=diff count+=1 if(counttoInteger() ; if (n = 1 or n = 2) then ( execute (n - 1)->display() ; exit() ) else skip ; var mnm : OclAny := m.Math_PINFINITY ; for k : Integer.subrange(m.ceil(n / 2), n-1) do ( if (hcf(n, k) /= 1) then ( continue ) else skip ; var p : OclAny := k ; var q : double := n - k ; var count : int := 2 ; while (p /= 2) do ( var diff : double := p - q ; if ((q->compareTo(diff)) > 0) then ( p := q ; q := diff ) else ( p := diff ) ; count := count + 1) ; if ((count->compareTo(mnm)) < 0) then ( mnm := count ) else skip) ; execute (mnm)->display(); operation hcf(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: while (a /= b) do ( if ((a->compareTo(b)) > 0) then ( a := a - b ) else ( b := b - a )) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gc(a,b,rs): if b==1 : return[1,rs+a-1] if b==0 : return[a,rs] rs+=(a//b) return gc(b,a % b,rs) x=int(input()) res=10**9 for n in range(1,x): u=gc(x,n,0) if u[0]==1 : res=min(res,u[1]) if res==10**9 : res=0 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : double := (10)->pow(9) ; for n : Integer.subrange(1, x-1) do ( var u : OclAny := gc(x, n, 0) ; if u->first() = 1 then ( res := Set{res, u[1+1]}->min() ) else skip) ; if res = (10)->pow(9) then ( res := 0 ) else skip ; execute (res)->display(); operation gc(a : OclAny, b : OclAny, rs : OclAny) : OclAny pre: true post: true activity: if b = 1 then ( return Sequence{1}->union(Sequence{ rs + a - 1 }) ) else skip ; if b = 0 then ( return Sequence{a}->union(Sequence{ rs }) ) else skip ; rs := rs + (a div b) ; return gc(b, a mod b, rs); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,ans=int(input()),1000000 for i in range(1,n+1): k,a,b=0,n,i while b>1 : k+=a//b a,b=b,a % b if b!=0 : ans=min(ans,a-1+k) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var ans : OclAny := null; Sequence{n,ans} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),1000000} ; for i : Integer.subrange(1, n + 1-1) do ( var k : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{k,a,b} := Sequence{0,n,i} ; while b > 1 do ( k := k + a div b ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a mod b}) ; if b /= 0 then ( var ans : OclAny := Set{ans, a - 1 + k}->min() ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys from collections import deque,OrderedDict,defaultdict import heapq,re from collections import Counter def inp(): return sys.stdin.readline().rstrip() def mpp(): return map(int,inp().split()) def lis(): return list(mpp()) def yn(n): if n : return "YES" else : return "NO" def cd(s): return ord(s)-ord('a')+1 def fn(s): arr=[i for i in s] if arr!=sorted(arr): return False di=Counter(s) if di["a"]==0 or di["b"]==0 : return False if di["c"]==di["a"]or di["c"]==di["b"]: return True return False def main(): s=inp() print(yn(fn(s))) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation inp() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation mpp() : OclAny pre: true post: true activity: return (inp().split())->collect( _x | (OclType["int"])->apply(_x) ); operation lis() : OclAny pre: true post: true activity: return (mpp()); operation yn(n : OclAny) : OclAny pre: true post: true activity: if n then ( return "YES" ) else ( return "NO" ); operation cd(s : OclAny) : OclAny pre: true post: true activity: return (s)->char2byte() - ('a')->char2byte() + 1; operation fn(s : OclAny) : OclAny pre: true post: true activity: var arr : Sequence := s->select(i | true)->collect(i | (i)) ; if arr /= arr->sort() then ( return false ) else skip ; var di : OclAny := Counter(s) ; if di->at("a") = 0 or di->at("b") = 0 then ( return false ) else skip ; if di->at("c") = di->at("a") or di->at("c") = di->at("b") then ( return true ) else skip ; return false; operation main() pre: true post: true activity: s := inp() ; execute (yn(fn(s)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import os import re def extract_numbers(s): lst=re.findall('[0-9]+',s) return list(map(int,lst)) sum_value=0 for s in sys.stdin : s=s.strip() lst=extract_numbers(s) sum_value+=sum(lst) print(sum_value) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var sum_value : int := 0 ; for s : OclFile["System.in"] do ( s := s->trim() ; lst := extract_numbers(s) ; sum_value := sum_value + (lst)->sum()) ; execute (sum_value)->display(); operation extract_numbers(s : OclAny) : OclAny pre: true post: true activity: var lst : Sequence(String) := (s)->allMatches('[0-9]+') ; return ((lst)->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s="" li=[str(i)for i in xrange(10)] while 1 : try : s+=raw_input() except : ans=0 num="" for i in s : if i in li : num+=i else : if num!="" : ans+=int(num) num="" print(ans) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := "" ; var li : Sequence := xrange(10)->select(i | true)->collect(i | (("" + ((i))))) ; while 1 do ( try ( s := s + raw_input()) catch (_e : OclException) do ( var ans : int := 0 ; var num : String := "" ; for i : s->characters() do ( if (li)->includes(i) then ( num := num + i ) else ( if num /= "" then ( ans := ans + ("" + ((num)))->toInteger() ; num := "" ) else skip )) ; execute (ans)->display() ; break) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys f=sys.stdin import string secret=0 for line in f : line=list(line) for i in range(len(line)): if line[i]not in string.digits : line[i]='' secret+=sum(map(int,''.join(line).split())) print(secret) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var f : OclFile := OclFile["System.in"] ; skip ; var secret : int := 0 ; for line : f do ( var line : Sequence := (line) ; for i : Integer.subrange(0, (line)->size()-1) do ( if (string.digits)->excludes(line[i+1]) then ( line[i+1] := '' ) else skip) ; secret := secret + ((''.join(line).split())->collect( _x | (OclType["int"])->apply(_x) ))->sum()) ; execute (secret)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans=0 while True : try : s=list(input()) numlst=[] anslst=[] for num,i in enumerate(s): try : k=int(i) numlst.append(num) except : pass for i in range(len(numlst)-1): if numlst[i+1]-numlst[i]==1 : s[numlst[i+1]]=s[numlst[i]]+s[numlst[i+1]] else : anslst.append(numlst[i]) if numlst!=[]: anslst.append(numlst[-1]) for i in anslst : ans=ans+int(s[i]) except EOFError : break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ans : int := 0 ; while true do ( try ( var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var numlst : Sequence := Sequence{} ; var anslst : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var num : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); try ( var k : int := ("" + ((i)))->toInteger() ; execute ((num) : numlst)) catch (_e : OclException) do ( skip) ) ; for i : Integer.subrange(0, (numlst)->size() - 1-1) do ( if numlst[i + 1+1] - numlst[i+1] = 1 then ( s[numlst[i + 1+1]+1] := s[numlst[i+1]+1] + s[numlst[i + 1+1]+1] ) else ( execute ((numlst[i+1]) : anslst) )) ; if numlst /= Sequence{} then ( execute ((numlst->last()) : anslst) ) else skip ; for i : anslst do ( ans := ans + ("" + ((s[i+1])))->toInteger())) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=input().split() a=int(a) b=int(b) c=1 v=0 n=0 while ntoInteger() ; var b : int := ("" + ((b)))->toInteger() ; var c : int := 1 ; var v : int := 0 ; var n : int := 0 ; while (n->compareTo(a)) < 0 do ( v := v + ("" + ((("" + ((c))) + (OclType["String"](c)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))))))->toInteger() ; c := c + 1 ; n := n + 1) ; execute (v mod b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") N=0 while True : try : string=input().strip() except EOFError : break string=''.join([s if '0'<=s<='9' else ' ' for s in string]) for k in string.split(): N+=int(k) print(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; var N : int := 0 ; while true do ( try ( var string : OclAny := input()->trim()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))) ; string := StringLib.sumStringsWithSeparator((string->select(s | true)->collect(s | (if '0' <= s & (s <= '9') then s else ' ' endif))), '') ; for k : string.split() do ( N := N + ("" + ((k)))->toInteger())) ; execute (N)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairs(s): st=set(); st.add('a'); st.add('e'); st.add('i'); st.add('o'); st.add('u'); count=0 ; n=len(s); for i in range(n-1): if(s[i]not in st and s[i+1]in st): count+=1 ; return count ; if __name__=="__main__" : s="geeksforgeeks" ; print(countPairs(s)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "geeksforgeeks"; ; execute (countPairs(s))->display(); ) else skip; operation countPairs(s : OclAny) pre: true post: true activity: var st : Set := Set{}->union(()); ; execute (('a') : st); ; execute (('e') : st); ; execute (('i') : st); ; execute (('o') : st); ; execute (('u') : st); ; var count : int := 0; ; var n : int := (s)->size(); ; for i : Integer.subrange(0, n - 1-1) do ( if ((st)->excludes(s[i+1]) & (st)->includes(s[i + 1+1])) then ( count := count + 1; ) else skip) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def fun(p,d): if d==0 : return p pos=int(math.log(d)/math.log(10)) k="9"*pos sr=p-d f=pow(10,pos) gap=d//f st=str(sr) n=len(st) get=st[: n-pos] if len(get)==0 : get="1" stp=str(p) stp=stp[: len(stp)-pos] e="" for i in range(int(get),int(get)+gap+1): if int(str(i)+k)<=p : e=str(i) if str(i)[-1]=="9" : if int(e+k)<=p : break return e+k p,d=map(int,input().split()) print(fun(p,d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{p,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (fun(p, d))->display(); operation fun(p : OclAny, d : OclAny) : OclAny pre: true post: true activity: if d = 0 then ( return p ) else skip ; var pos : int := ("" + (((d)->log() / (10)->log())))->toInteger() ; var k : String := StringLib.nCopies("9", pos) ; var sr : double := p - d ; var f : double := (10)->pow(pos) ; var gap : int := d div f ; var st : String := ("" + ((sr))) ; var n : int := (st)->size() ; var get : OclAny := st.subrange(1,n - pos) ; if (get)->size() = 0 then ( get := "1" ) else skip ; var stp : String := ("" + ((p))) ; stp := stp.subrange(1,(stp)->size() - pos) ; var e : String := "" ; for i : Integer.subrange(("" + ((get)))->toInteger(), ("" + ((get)))->toInteger() + gap + 1-1) do ( if (("" + ((("" + ((i))) + k)))->toInteger()->compareTo(p)) <= 0 then ( e := ("" + ((i))) ; if OclType["String"](i)->last() = "9" then ( if (("" + ((e + k)))->toInteger()->compareTo(p)) <= 0 then ( break ) else skip ) else skip ) else skip) ; return e + k; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,p=map(int,input().split()) d=n if p==0 : print(n) else : total=0 for i in range(len(str(p))): l_d=d % 10 d=d//10 if l_d!=9 : sub=l_d+1 d=d-1 if total+(sub*pow(10,i))>p : break else : total=total+(sub*pow(10,i)) print(n-total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : OclAny := n ; if p = 0 then ( execute (n)->display() ) else ( var total : int := 0 ; for i : Integer.subrange(0, (("" + ((p))))->size()-1) do ( var l_d : int := d mod 10 ; d := d div 10 ; if l_d /= 9 then ( var sub : int := l_d + 1 ; d := d - 1 ; if (total + (sub * (10)->pow(i))->compareTo(p)) > 0 then ( break ) else ( total := total + (sub * (10)->pow(i)) ) ) else skip) ; execute (n - total)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input().split() (p,d)=(int(i)for i in s) c=0 price=0 s=str(p) s=s[: :-1] i=0 while(icountp): print(c[: :-1]) else : print(p[: :-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := input().split() ; var Sequence{p, d} : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name s)))))))} ; var c : int := 0 ; var price : int := 0 ; s := ("" + ((p))) ; s := s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var i : int := 0 ; while ((i->compareTo((s)->size())) < 0) do ( if (i = (s)->size() - 1) then ( var t : String := StringLib.nCopies('9', ((s)->size())) ; price := ("" + ((t)))->toInteger() ) else (if (((i + 1)->compareTo((s)->size())) < 0 & s[i + 1+1] = '0') then ( t := StringLib.nCopies('9', (i + 1)) + '0' + s.subrange(Set{i + 2, (s)->size()}->min()+1) ; price := ("" + ((t(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))))->toInteger() ) else (if (((i + 1)->compareTo((s)->size())) < 0) then ( t := StringLib.nCopies('9', (i + 1)) + ("" + ((("" + ((s[i + 1+1])))->toInteger() - 1))) + s.subrange(Set{i + 2, (s)->size()}->min()+1) ; price := ("" + ((t(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))))->toInteger() ) else ( price := ("" + ((s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))))->toInteger() ) ) ) ; i := i + 1 ; if ((price->compareTo(p)) <= 0 & (p - price->compareTo(d)) <= 0) then ( c := price ) else skip) ; c := OclType["String"](c)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var p : OclAny := OclType["String"](p)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var countc : int := 0 ; var countp : int := 0 ; i := 0 ; while ((i->compareTo((c)->size())) < 0 & c[i+1] = '9') do ( countc := countc + 1 ; i := i + 1) ; i := 0 ; while ((i->compareTo((p)->size())) < 0 & p[i+1] = '9') do ( countp := countp + 1 ; i := i + 1) ; if ((countc->compareTo(countp)) > 0) then ( execute (c(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->display() ) else ( execute (p(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def trail(s): c=0 for i in s[: :-1]: if i=='9' : c+=1 else : return c return c def solve(): for i in range(len(str(n))-1,0,-1): if n %(10**i)x2 : return new else : return max(n,new) return n from sys import stdin input=stdin.readline n,d=[int(x)for x in input().split()] print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := stdin.readline ; var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (solve())->display(); operation trail(s : OclAny) : OclAny pre: true post: true activity: var c : int := 0 ; for i : s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if i = '9' then ( c := c + 1 ) else ( return c )) ; return c; operation solve() : OclAny pre: true post: true activity: for i : Integer.subrange(0 + 1, (("" + ((n))))->size() - 1)->reverse() do ( if (n mod ((10)->pow(i))->compareTo(d)) < 0 then ( var new : double := n - n mod ((10)->pow(i)) - 1 ; var x1 : OclAny := trail(("" + ((new)))) ; var x2 : OclAny := trail(("" + ((n)))) ; if (x1->compareTo(x2)) > 0 then ( return new ) else ( return Set{n, new}->max() ) ) else skip) ; return n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n=list(input()) d=Counter(n) if(d['c']==d['b']!=0 or d['a']==d['c']!=0 or d['b']==d['c']!=0)and n==sorted(n)and 'a' in n and 'b' in n : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var d : OclAny := Counter(n) ; if (d->at('c') = d->at('b') & (d->at('b') != 0) or d->at('a') = d->at('c') & (d->at('c') != 0) or d->at('b') = d->at('c') & (d->at('c') != 0)) & n = n->sort() & (n)->includes('a') & (n)->includes('b') then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) flg=0 for i in range(15): for j in range(26): if i*7+j*4==n : flg=1 if flg : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var flg : int := 0 ; for i : Integer.subrange(0, 15-1) do ( for j : Integer.subrange(0, 26-1) do ( if i * 7 + j * 4 = n then ( flg := 1 ) else skip)) ; if flg then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=input() N=int(N) flag=False q=N//4 for i in range(q): if(N % 7)==0 : print("Yes") flag=True break elif(N-(4*(i+1)))% 7==0 : print("Yes") flag=True break if not flag : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : String := (OclFile["System.in"]).readLine() ; N := ("" + ((N)))->toInteger() ; var flag : boolean := false ; var q : int := N div 4 ; for i : Integer.subrange(0, q-1) do ( if (StringLib.format(N,7)) = 0 then ( execute ("Yes")->display() ; flag := true ; break ) else (if (N - (4 * (i + 1))) mod 7 = 0 then ( execute ("Yes")->display() ; flag := true ; break ) else skip)) ; if not(flag) then ( execute ("No")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) c=25 d=14 judge="No" for i in range(d+1): for j in range(c+1): payment=7*i+4*j if payment==n : judge="Yes" print(judge) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := 25 ; var d : int := 14 ; var judge : String := "No" ; for i : Integer.subrange(0, d + 1-1) do ( for j : Integer.subrange(0, c + 1-1) do ( var payment : double := 7 * i + 4 * j ; if payment = n then ( judge := "Yes" ) else skip)) ; execute (judge)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def has_child(data,n): data_len=len(data)-1 if data_len=(n*2)+1 : return 2 else : return 1 if __name__=='__main__' : num_of_data=int(input()) data=[int(x)for x in input().split('')] data.insert(0,None) for i in range(1,num_of_data+1): print('node{0}: key={1},'.format(i,data[i]),end='') if i>1 : print('parent key={0},'.format(data[i//2]),end='') child=has_child(data,i) if child==1 : print('left key={0},'.format(data[i*2]),end='') if child==2 : print('left key={0},right key={1},'.format(data[i*2],data[i*2+1]),end='') print('') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var num_of_data : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; data := input().split('')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; data := data.insertAt(0+1, null) ; for i : Integer.subrange(1, num_of_data + 1-1) do ( execute (StringLib.interpolateStrings('node{0}: key={1},', Sequence{i, data[i+1]}))->display() ; if i > 1 then ( execute (StringLib.interpolateStrings('parent key={0},', Sequence{data[i div 2+1]}))->display() ) else skip ; var child : OclAny := has_child(data, i) ; if child = 1 then ( execute (StringLib.interpolateStrings('left key={0},', Sequence{data[i * 2+1]}))->display() ) else skip ; if child = 2 then ( execute (StringLib.interpolateStrings('left key={0},right key={1},', Sequence{data[i * 2+1], data[i * 2 + 1+1]}))->display() ) else skip ; execute ('')->display()) ) else skip; operation has_child(data : OclAny, n : OclAny) : OclAny pre: true post: true activity: var data_len : double := (data)->size() - 1 ; if (data_len->compareTo(n * 2)) < 0 then ( return 0 ) else ( if (data_len->compareTo((n * 2) + 1)) >= 0 then ( return 2 ) else ( return 1 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) def Div(i): if i==1 or i==2 or i==3 or i==5 or i==6 : return False elif i==4 or i==7 : return True else : if Div(i-4)or Div(i-7): return True else : return False print("Yes" if Div(N)else "No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; execute (if Div(N) then "Yes" else "No" endif)->display(); operation Div(i : OclAny) : OclAny pre: true post: true activity: if i = 1 or i = 2 or i = 3 or i = 5 or i = 6 then ( return false ) else (if i = 4 or i = 7 then ( return true ) else ( if Div(i - 4) or Div(i - 7) then ( return true ) else ( return false ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) maxCake=N//4+1 maxDon=N//7+1 flg=False for i in range(maxCake): for j in range(maxDon): if i*4+j*7==N : print('Yes') flg=True break ; if flg==True : break if flg==False : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var maxCake : int := N div 4 + 1 ; var maxDon : int := N div 7 + 1 ; var flg : boolean := false ; for i : Integer.subrange(0, maxCake-1) do ( for j : Integer.subrange(0, maxDon-1) do ( if i * 4 + j * 7 = N then ( execute ('Yes')->display() ; flg := true ; break; ) else skip) ; if flg = true then ( break ) else skip) ; if flg = false then ( execute ('No')->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isTidy(num): prev=10 while(num): rem=num % 10 num/=10 if rem>prev : return False prev=rem return True num=1556 if isTidy(num): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; num := 1556 ; if isTidy(num) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isTidy(num : OclAny) : OclAny pre: true post: true activity: var prev : int := 10 ; while (num) do ( var rem : int := num mod 10 ; num := num / 10 ; if (rem->compareTo(prev)) > 0 then ( return false ) else skip ; prev := rem) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) a.sort() import collections d=collections.Counter(a) if-(-max(a)//2)!=min(a): print("Impossible") exit() if max(a)% 2==0 : if d[min(a)]!=1 : print("Impossible") exit() else : if d[min(a)]!=2 : print("Impossible") exit() for num in range(min(a)+1,max(a)+1): if d[num]<2 : print("Impossible") exit() print("Possible") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; skip ; var d : OclAny := .Counter(a) ; if -(-(a)->max() div 2) /= (a)->min() then ( execute ("Impossible")->display() ; exit() ) else skip ; if (a)->max() mod 2 = 0 then ( if d[(a)->min()+1] /= 1 then ( execute ("Impossible")->display() ; exit() ) else skip ) else ( if d[(a)->min()+1] /= 2 then ( execute ("Impossible")->display() ; exit() ) else skip ) ; for num : Integer.subrange((a)->min() + 1, (a)->max() + 1-1) do ( if d[num+1] < 2 then ( execute ("Impossible")->display() ; exit() ) else skip) ; execute ("Possible")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import sys from collections import Counter if os.getenv("LOCAL"): sys.stdin=open("_in.txt","r") sys.setrecursionlimit(2147483647) INF=float("inf") IINF=10**18 MOD=10**9+7 N=int(sys.stdin.readline()) A=list(map(int,sys.stdin.readline().split())) counts=Counter(A) ma=max(A) mi=min(A) ok=True if ma % 2==0 : ok &=mi==ma//2 ok &=counts[mi]==1 else : ok &=mi==ma//2+1 ok &=counts[mi]==2 for d in range(ma,mi,-1): ok &=counts[d]>=2 if ok : print('Possible') else : print('Impossible') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if os.getenv("LOCAL") then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("_in.txt")) ) else skip ; sys.setrecursionlimit(2147483647) ; var INF : double := ("" + (("inf")))->toReal() ; var IINF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var counts : OclAny := Counter(A) ; var ma : OclAny := (A)->max() ; var mi : OclAny := (A)->min() ; var ok : boolean := true ; if ma mod 2 = 0 then ( ok := ok & mi = ma div 2 ; ok := ok & counts[mi+1] = 1 ) else ( ok := ok & mi = ma div 2 + 1 ; ok := ok & counts[mi+1] = 2 ) ; for d : Integer.subrange(mi + 1, ma)->reverse() do ( ok := ok & counts[d+1] >= 2) ; if ok then ( execute ('Possible')->display() ) else ( execute ('Impossible')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def N(): return int(input()) def NM(): return map(int,input().split()) def L(): return list(NM()) def LN(n): return[N()for i in range(n)] def LL(n): return[L()for i in range(n)] n=N() l=L() l.sort() def im(): print("Impossible") quit() def po(): print("Possible") quit() if l[0]!=(l[-1]+1)//2 : im() import collections c=collections.Counter(l) if l[-1]% 2 : if c[l[0]]!=2 : im() for i in range(l[0]+1,l[-1]+1): if c[i]<2 : im() po() if c[l[0]]!=1 : im() for i in range(l[0]+1,l[-1]+1): if c[i]<2 : im() po() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; n := N() ; var l : OclAny := L() ; l := l->sort() ; skip ; skip ; if l->first() /= (l->last() + 1) div 2 then ( im() ) else skip ; skip ; var c : OclAny := .Counter(l) ; if l->last() mod 2 then ( if c[l->first()+1] /= 2 then ( im() ) else skip ; for i : Integer.subrange(l->first() + 1, l->last() + 1-1) do ( if c[i+1] < 2 then ( im() ) else skip) ; po() ) else skip ; if c[l->first()+1] /= 1 then ( im() ) else skip ; for i : Integer.subrange(l->first() + 1, l->last() + 1-1) do ( if c[i+1] < 2 then ( im() ) else skip) ; po(); operation N() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation NM() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation L() : OclAny pre: true post: true activity: return (NM()); operation LN(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (N())); operation LL(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (L())); operation im() pre: true post: true activity: execute ("Impossible")->display() ; quit(); operation po() pre: true post: true activity: execute ("Possible")->display() ; quit(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def getlist(): return list(map(int,input().split())) def main(): N=int(input()) D=defaultdict(int) a=sorted(getlist()) if N==2 : if a[0]!=1 or a[1]!=1 : print("Impossible") else : print("Possible") else : for i in range(N): D[a[i]]+=1 if a[-1]% 2!=0 : if a[0]*2-1!=a[-1]: print("Impossible") else : judge="Possible" if D[a[0]]!=2 : judge="Impossible" for i in range(a[0],a[-1]+1): if D[i]<2 : judge="Impossible" break print(judge) else : judge="Possible" if a[0]*2!=a[-1]: print("Impossible") else : judge="Possible" if D[a[0]]!=1 : judge="Impossible" for i in range(a[0]+1,a[-1]+1): if D[i]<2 : judge="Impossible" break print(judge) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation getlist() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var D : OclAny := defaultdict(OclType["int"]) ; var a : Sequence := getlist()->sort() ; if N = 2 then ( if a->first() /= 1 or a[1+1] /= 1 then ( execute ("Impossible")->display() ) else ( execute ("Possible")->display() ) ) else ( for i : Integer.subrange(0, N-1) do ( D[a[i+1]+1] := D[a[i+1]+1] + 1) ; if a->last() mod 2 /= 0 then ( if a->first() * 2 - 1 /= a->last() then ( execute ("Impossible")->display() ) else ( var judge : String := "Possible" ; if D[a->first()+1] /= 2 then ( judge := "Impossible" ) else skip ; for i : Integer.subrange(a->first(), a->last() + 1-1) do ( if D[i+1] < 2 then ( judge := "Impossible" ; break ) else skip) ; execute (judge)->display() ) ) else ( judge := "Possible" ; if a->first() * 2 /= a->last() then ( execute ("Impossible")->display() ) else ( judge := "Possible" ; if D[a->first()+1] /= 1 then ( judge := "Impossible" ) else skip ; for i : Integer.subrange(a->first() + 1, a->last() + 1-1) do ( if D[i+1] < 2 then ( judge := "Impossible" ; break ) else skip) ; execute (judge)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() a_indexes=[] b_indexes=[] c_indexes=[] for i in range(len(s)): if s[i]=='a' : a_indexes.append(i) elif s[i]=='b' : b_indexes.append(i) elif s[i]=='c' : c_indexes.append(i) if(len(a_indexes)>=1 and len(b_indexes)>=1)and(len(c_indexes)==len(a_indexes)or len(c_indexes)==len(b_indexes))and(a_indexes[-1]size()-1) do ( if s[i+1] = 'a' then ( execute ((i) : a_indexes) ) else (if s[i+1] = 'b' then ( execute ((i) : b_indexes) ) else (if s[i+1] = 'c' then ( execute ((i) : c_indexes) ) else skip ) ) ) ; if ((a_indexes)->size() >= 1 & (b_indexes)->size() >= 1) & ((c_indexes)->size() = (a_indexes)->size() or (c_indexes)->size() = (b_indexes)->size()) & ((a_indexes->last()->compareTo(b_indexes->first())) < 0 & (b_indexes->last()->compareTo(c_indexes->first())) < 0) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter N=int(input()) A=[int(x)for x in input().split()] diag=max(A) def solve_even(): depth=[x-diag//2 for x in A] if any(x<0 for x in depth): return False counter=Counter(depth) if counter[0]!=1 : return False for i in range(1,diag//2+1): if counter[i]<2 : return False return True def solve_odd(): depth=[x-(diag+1)//2 for x in A] if any(x<0 for x in depth): return False counter=Counter(depth) if counter[0]!=2 : return False for i in range((diag+1)//2): if counter[i]<2 : return False return True bl=solve_odd()if diag & 1 else solve_even() answer='Possible' if bl else 'Impossible' print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit((10)->pow(7)) ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var diag : OclAny := (A)->max() ; skip ; skip ; var bl : OclAny := if MathLib.bitwiseAnd(diag, 1) then solve_odd() else solve_even() endif ; var answer : String := if bl then 'Possible' else 'Impossible' endif ; execute (answer)->display(); operation solve_even() : OclAny pre: true post: true activity: var depth : Sequence := A->select(x | true)->collect(x | (x - diag div 2)) ; if ((argument (test (logical_test (comparison (comparison (expr (atom (name x)))) < (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name depth))))))))->exists( _x | _x = true ) then ( return false ) else skip ; var counter : OclAny := Counter(depth) ; if counter->first() /= 1 then ( return false ) else skip ; for i : Integer.subrange(1, diag div 2 + 1-1) do ( if counter[i+1] < 2 then ( return false ) else skip) ; return true; operation solve_odd() : OclAny pre: true post: true activity: depth := A->select(x | true)->collect(x | (x - (diag + 1) div 2)) ; if ((argument (test (logical_test (comparison (comparison (expr (atom (name x)))) < (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name depth))))))))->exists( _x | _x = true ) then ( return false ) else skip ; counter := Counter(depth) ; if counter->first() /= 2 then ( return false ) else skip ; for i : Integer.subrange(0, (diag + 1) div 2-1) do ( if counter[i+1] < 2 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,pow def isPerfectPower(n): if(n==1): return True for x in range(2,int(sqrt(n))+1): y=2 p=pow(x,y) while(p<=n and p>0): if(p==n): return True y+=1 p=pow(x,y) return False def isStrongNumber(n): count={i : 0 for i in range(n)} while(n % 2==0): n=int(n/2) count[2]+=1 for i in range(3,int(sqrt(n))+1,2): while(n % i==0): n=int(n/i) count[i]+=1 if(n>2): count[n]+=1 flag=0 for ket,value in count.items(): if(value==1): flag=1 break if(flag==1): return False else : return True def isTrojan(n): if(isPerfectPower(n)==False and isStrongNumber(n)): return True else : return False if __name__=='__main__' : n=108 if(isTrojan(n)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( n := 108 ; if (isTrojan(n)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; operation isPerfectPower(n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return true ) else skip ; for x : Integer.subrange(2, ("" + ((sqrt(n))))->toInteger() + 1-1) do ( var y : int := 2 ; var p : double := (x)->pow(y) ; while ((p->compareTo(n)) <= 0 & p > 0) do ( if (p = n) then ( return true ) else skip ; y := y + 1 ; p := (x)->pow(y))) ; return false; operation isStrongNumber(n : OclAny) : OclAny pre: true post: true activity: var count : Map := Integer.subrange(0, n-1)->select(i | true)->collect(i | Map{i |-> 0})->unionAll() ; while (n mod 2 = 0) do ( n := ("" + ((n / 2)))->toInteger() ; count[2+1] := count[2+1] + 1) ; for i : Integer.subrange(3, ("" + ((sqrt(n))))->toInteger() + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( while (n mod i = 0) do ( n := ("" + ((n / i)))->toInteger() ; count[i+1] := count[i+1] + 1)) ; if (n > 2) then ( count[n+1] := count[n+1] + 1 ) else skip ; var flag : int := 0 ; for _tuple : count->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var ket : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); if (value = 1) then ( flag := 1 ; break ) else skip) ; if (flag = 1) then ( return false ) else ( return true ); operation isTrojan(n : OclAny) : OclAny pre: true post: true activity: if (isPerfectPower(n) = false & isStrongNumber(n)) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline write=sys.stdout.write err=2*(10**9)+1 class Node : def __init__(self,k,l,r,p): self.key=k self.left=l self.right=r self.parent=p n=int(input()) keys=list(map(int,readline().split())) Heap=[Node(err,None,None,None)for i in range(n+1)] for i in range(1,n+1): Heap[i].key=keys[i-1] if 2*i1 : Heap[i].parent=Heap[int(i/2)] for i in range(1,n+1): write("node "+str(i)+": key="+str(Heap[i].key)+",") if Heap[i].parent is not None : write("parent key="+str(Heap[i].parent.key)+",") if Heap[i].left is not None : write("left key="+str(Heap[i].left.key)+",") if Heap[i].right is not None : write("right key="+str(Heap[i].right.key)+",") write("\n") ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute key : OclAny := k; attribute left : OclAny := l; attribute right : OclAny := r; attribute parent : OclAny := p; operation initialise(k : OclAny,l : OclAny,r : OclAny,p : OclAny) : Node pre: true post: true activity: self.key := k ; self.left := l ; self.right := r ; self.parent := p; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var write : OclAny := (OclFile["System.out"]).write ; var err : double := 2 * ((10)->pow(9)) + 1 ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var keys : Sequence := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var Heap : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | ((Node.newNode()).initialise(err, null, null, null))) ; for i : Integer.subrange(1, n + 1-1) do ( Heap[i+1].key := keys[i - 1+1] ; if (2 * i->compareTo(n + 1)) < 0 then ( Heap[i+1].left := Heap[2 * i+1] ) else skip ; if (2 * i + 1->compareTo(n + 1)) < 0 then ( Heap[i+1].right := Heap[2 * i + 1+1] ) else skip ; if i > 1 then ( Heap[i+1].parent := Heap[("" + ((i / 2)))->toInteger()+1] ) else skip) ; for i : Integer.subrange(1, n + 1-1) do ( write("node " + ("" + ((i))) + ": key=" + ("" + ((Heap[i+1].key))) + ",") ; if not(Heap[i+1].parent <>= null) then ( write("parent key=" + ("" + ((Heap[i+1].parent.key))) + ",") ) else skip ; if not(Heap[i+1].left <>= null) then ( write("left key=" + ("" + ((Heap[i+1].left.key))) + ",") ; if not(Heap[i+1].right <>= null) then ( write("right key=" + ("" + ((Heap[i+1].right.key))) + ",") ) else skip ) else skip ; write("\n")); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Case : def __init__(self,fin,fout,n): self._fin=fin self._fout=fout self._n=n self._line=None def readInt(self): if self._line is None : self._line=self._fin.readline().split(" ") result=int(self._line.pop(0)) if len(self._line)==0 : self._line=None return result def readLine(self): line=self._fin.readline() if line[-1]=="\n" : return line[:-1] return line def output(self,s): if s is None : return s=str(s) if "\n" in s : self._fout.write("Case #%d:%s" %(self._n,s)) else : self._fout.write("Case #%d: %s\n" %(self._n,s)) def run(fileName,solve): fin=open(fileName) fout=open(fileName+".out","w") caseCount=int(fin.readline()) for i in range(caseCount): case=Case(fin,fout,i+1) case.output(solve(case)) ------------------------------------------------------------ OCL File: --------- class Case { static operation newCase() : Case pre: true post: Case->exists( _x | result = _x ); attribute _fin : OclAny := fin; attribute _fout : OclAny := fout; attribute _n : OclAny := n; attribute _line : OclAny := null; operation initialise(fin : OclAny,fout : OclAny,n : OclAny) : Case pre: true post: true activity: self._fin := fin ; self._fout := fout ; self._n := n ; self._line := null; return self; operation readInt() : OclAny pre: true post: true activity: if self._line <>= null then ( self._line := self._fin.readLine().split(" ") ) else skip ; var result : int := ("" + ((self._line->at(0`firstArg+1))))->toInteger() ; if (self._line)->size() = 0 then ( self._line := null ) else skip ; return result; operation readLine() : OclAny pre: true post: true activity: var line : OclAny := self._fin.readLine() ; if line->last() = "\n" then ( return line->front() ) else skip ; return line; operation output(s : OclAny) pre: true post: true activity: if s <>= null then ( return ) else skip ; s := ("" + ((s))) ; if (s)->includes("\n") then ( (expr (atom (name self)) (trailer . (name _fout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom "Case #%d:%s")) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name self)) (trailer . (name _n)))))) , (test (logical_test (comparison (expr (atom (name s))))))) ))))))))) )))) ) else ( (expr (atom (name self)) (trailer . (name _fout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom "Case #%d: %s\n")) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name self)) (trailer . (name _n)))))) , (test (logical_test (comparison (expr (atom (name s))))))) ))))))))) )))) ); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip; operation run(fileName : OclAny, solve : OclAny) pre: true post: true activity: fin := OclFile.newOclFile_Write(OclFile.newOclFile(fileName)) ; fout := OclFile.newOclFile_Write(OclFile.newOclFile(fileName + ".out")) ; var caseCount : int := ("" + ((fin.readLine())))->toInteger() ; for i : Integer.subrange(0, caseCount-1) do ( var case : Case := (Case.newCase()).initialise(fin, fout, i + 1) ; case.output(solve(case))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import io,sys import datetime,copy fin=None def solve(): s=sstrip() res='' for c in s : res=max(c+res,res+c) return res def main(): fname='a.in' if len(sys.argv)>1 : fname=sys.argv[1] global fin fin=io.open(fname) fout=io.open(fname+'.out','w') t0=datetime.datetime.now() t=int(fin.readline()) for i in range(t): fout.write('Case #%d: ' %(i+1)) fout.write('%s\n' % str(solve())) print('Time=%s' % str(datetime.datetime.now()-t0)) fin.close() fout.close() def nums(): return[int(x)for x in fin.readline().split()] def fnums(): return[float(x)for x in fin.readline().split()] def num(): return int(fin.readline()) def sstrip(): return fin.readline().strip() def strs(): return fin.readline().split() def arrstr(a,sep=' '): return sep.join([str(x)for x in a]) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute fin : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; var fin : OclAny := null ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve() : OclAny pre: true post: true activity: var s : OclAny := sstrip() ; var res : String := '' ; for c : s do ( res := Set{c + res, res + c}->max()) ; return res; operation main() pre: true post: true activity: var fname : String := 'a.in' ; if ((trailer . (name argv)))->size() > 1 then ( fname := (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) ) else skip ; skip ; fin := io.open(fname) ; var fout : OclAny := io.open(fname + '.out', 'w') ; var t0 : OclAny := datetime.datetime.now() ; var t : int := ("" + ((fin.readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( fout.write(StringLib.format('Case #%d: ',(i + 1))) ; fout.write(StringLib.format('%s ',("" + ((solve())))))) ; execute (StringLib.format('Time=%s',("" + ((datetime.datetime.now() - t0)))))->display() ; fin.closeFile() ; fout.closeFile(); operation nums() : OclAny pre: true post: true activity: return fin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation fnums() : OclAny pre: true post: true activity: return fin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation num() : OclAny pre: true post: true activity: return ("" + ((fin.readLine())))->toInteger(); operation sstrip() : OclAny pre: true post: true activity: return fin.readLine()->trim(); operation strs() : OclAny pre: true post: true activity: return fin.readLine().split(); operation arrstr(a : OclAny, sep : String) : OclAny pre: true post: true activity: if sep->oclIsUndefined() then sep := ' ' else skip; return StringLib.sumStringsWithSeparator((a->select(x | true)->collect(x | (("" + ((x)))))), sep); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- task='A' type=2 if type==0 : inp=open('sample.in','r') elif type==1 : inp=open('%s-small.in' %(task,)) else : inp=open('%s-large.in' %(task),) outp=open('%s.out' %(task,),'w') T=int(inp.readline()[:-1]) for i in range(T): ans='' st=inp.readline()[:-1] curmax=0 for c in st : if ord(c)>=curmax : ans=c+ans curmax=ord(c) else : ans=ans+c outp.write("Case #%s: %s\n" %(i+1,ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var task : String := 'A' ; var type : int := 2 ; if type = 0 then ( var inp : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('sample.in')) ) else (if type = 1 then ( inp := OclFile.newOclFile_Write(OclFile.newOclFile(StringLib.format('%s-small.in',Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name task)))))) ,)}))) ) else ( inp := OclFile.newOclFile_Write(OclFile.newOclFile(StringLib.format('%s-large.in',(task)))) ) ) ; var outp : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(StringLib.format('%s.out',Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name task)))))) ,)}))) ; var T : int := ("" + ((inp.readLine()->front())))->toInteger() ; for i : Integer.subrange(0, T-1) do ( var ans : String := '' ; var st : OclAny := inp.readLine()->front() ; var curmax : int := 0 ; for c : st do ( if ((c)->char2byte()->compareTo(curmax)) >= 0 then ( ans := c + ans ; curmax := (c)->char2byte() ) else ( ans := ans + c )) ; outp.write(StringLib.format("Case #%s: %s\n",Sequence{i + 1, ans}))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def one_test(): s=input() res="" for c in s : res=max(c+res,res+c) return res t=int(input()) for i in range(1,t+1): print("Case #{}:{}".format(i,one_test())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(1, t + 1-1) do ( execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{i, one_test()}))->display()); operation one_test() : OclAny pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var res : String := "" ; for c : s->characters() do ( res := Set{c + res, res + c}->max()) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys fin=open(sys.argv[1],"r") fout=open("p1.out","w") T=int(fin.readline()) for tt in xrange(T): S=fin.readline().strip() ans='' for c in S : if c+anstoInteger() ; for tt : xrange(T) do ( var S : OclAny := fin.readLine()->trim() ; var ans : String := '' ; for c : S do ( if (c + ans->compareTo(ans + c)) < 0 then ( ans := ans + c ) else ( ans := c + ans )) ; fout.write("Case #" + ("" + ((tt + 1))) + ": " + ans + "\n")); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin def want(l,r,lb,rb): if l>r : return 0 elif l==r : return A[l]*(lb+rb) nmin=float("inf") for i in range(l,r+1): nmin=min(nmin,A[i]*(lb+rb)+want(l,i-1,lb,lb+rb)+want(i+1,r,lb+rb,rb)) return nmin N=int(stdin.readline()) A=list(map(int,stdin.readline().split())) print(A[0]+A[-1]+want(1,N-2,1,1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := ("" + ((stdin.readLine())))->toInteger() ; var A : Sequence := ((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (A->first() + A->last() + want(1, N - 2, 1, 1))->display(); operation want(l : OclAny, r : OclAny, lb : OclAny, rb : OclAny) : OclAny pre: true post: true activity: if (l->compareTo(r)) > 0 then ( return 0 ) else (if l = r then ( return A[l+1] * (lb + rb) ) else skip) ; var nmin : double := ("" + (("inf")))->toReal() ; for i : Integer.subrange(l, r + 1-1) do ( nmin := Set{nmin, A[i+1] * (lb + rb) + want(l, i - 1, lb, lb + rb) + want(i + 1, r, lb + rb, rb)}->min()) ; return nmin; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=list(map(int,input().split())) memo={} def dp(i,j,L,R): if(i,j,L,R)in memo : return memo[(i,j,L,R)] if i==j : memo[(i,j,L,R)]=0 memo[(i,j,L,R)]=(L+R)*A[i] return(L+R)*A[i] elif i>j : return 0 ans=10**18 for k in range(i,j+1): test=dp(i,k-1,L,L+R)+dp(k+1,j,L+R,R)+A[k]*(L+R) ans=min(ans,test) memo[(i,j,L,R)]=0 memo[(i,j,L,R)]=ans return ans res=dp(1,N-2,1,1) print(res+A[0]+A[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var memo : OclAny := Set{} ; skip ; var res : OclAny := dp(1, N - 2, 1, 1) ; execute (res + A->first() + A->last())->display(); operation dp(i : OclAny, j : OclAny, L : OclAny, R : OclAny) : OclAny pre: true post: true activity: if (memo)->includes(Sequence{i, j, L, R}) then ( return memo[Sequence{i, j, L, R}+1] ) else skip ; if i = j then ( memo[Sequence{i, j, L, R}+1] := 0 ; memo[Sequence{i, j, L, R}+1] := (L + R) * A[i+1] ; return (L + R) * A[i+1] ) else (if (i->compareTo(j)) > 0 then ( return 0 ) else skip) ; var ans : double := (10)->pow(18) ; for k : Integer.subrange(i, j + 1-1) do ( var test : OclAny := dp(i, k - 1, L, L + R) + dp(k + 1, j, L + R, R) + A[k+1] * (L + R) ; ans := Set{ans, test}->min()) ; memo[Sequence{i, j, L, R}+1] := 0 ; memo[Sequence{i, j, L, R}+1] := ans ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import lru_cache N=int(input()) A=[int(i)for i in input().split()] @ lru_cache(maxsize=None) def rec(l,r,xl,xr): if l+1==r : return 0 return min(rec(l,m,xl,xl+xr)+rec(m,r,xl+xr,xr)+A[m]*(xl+xr)for m in range(l+1,r)) print(A[0]+rec(0,N-1,1,1)+A[N-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; (compound_stmt (decorator @ (dotted_name (name lru_cache)) ( (arglist (argument (test (logical_test (comparison (expr (atom (name maxsize)))))) = (test (logical_test (comparison (expr (atom None))))))) )) (funcdef def (name rec) ( (typedargslist (def_parameters (def_parameter (named_parameter (name l))) , (def_parameter (named_parameter (name r))) , (def_parameter (named_parameter (name xl))) , (def_parameter (named_parameter (name xr))))) ) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name l))) + (expr (atom (number (integer 1)))))) == (comparison (expr (atom (name r))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name rec)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l))))))) , (argument (test (logical_test (comparison (expr (atom (name m))))))) , (argument (test (logical_test (comparison (expr (atom (name xl))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name xl))) + (expr (atom (name xr))))))))) )))) + (expr (atom (name rec)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name m))))))) , (argument (test (logical_test (comparison (expr (atom (name r))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name xl))) + (expr (atom (name xr)))))))) , (argument (test (logical_test (comparison (expr (atom (name xr)))))))) ))))) + (expr (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name m)))))))) ]))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name xl))) + (expr (atom (name xr)))))))) )))))))) (comp_for for (exprlist (expr (atom (name m)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name l))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name r)))))))) ))))))))) )))))))))))))) ; execute (A->first() + rec(0, N - 1, 1, 1) + A[N - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() a=s.count('a') b=s.count('b') c=s.count('c') a_last_index=len(s)-s[: :-1].find('a')-1 b_first_index=s.find('b') b_last_index=len(s)-s[: :-1].find('b')-1 c_first_index=s.find('c') if(a>=1 and b>=1)and(c==a or c==b)and(a_last_indexcount('a') ; var b : int := s->count('b') ; var c : int := s->count('c') ; var a_last_index : double := (s)->size() - s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->indexOf('a') - 1 - 1 ; var b_first_index : int := s->indexOf('b') - 1 ; var b_last_index : double := (s)->size() - s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->indexOf('b') - 1 - 1 ; var c_first_index : int := s->indexOf('c') - 1 ; if (a >= 1 & b >= 1) & (c = a or c = b) & ((a_last_index->compareTo(b_first_index)) < 0 & (b_last_index->compareTo(c_first_index)) < 0) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import lru_cache def solve(n,aaa): @ lru_cache(maxsize=None) def search_min(li,ri,lc,rc): w=ri-li base=aaa[li]*lc if w==1 : return base lrc=lc+rc if w==2 : return base+aaa[li+1]*lrc if w==3 : a1,a2=aaa[li+1],aaa[li+2] return base+(a1+a2)*lrc+min(a1*lc,a2*rc) ret=min(search_min(li,i,lc,lrc)+search_min(i,ri,lrc,rc)for i in range(li+1,ri)) return ret return search_min(0,n-1,1,1)+aaa[-1] n=int(input()) aaa=list(map(int,input().split())) print(solve(n,aaa)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; aaa := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (solve(n, aaa))->display(); operation solve(n : OclAny, aaa : OclAny) : OclAny pre: true post: true activity: (compound_stmt (decorator @ (dotted_name (name lru_cache)) ( (arglist (argument (test (logical_test (comparison (expr (atom (name maxsize)))))) = (test (logical_test (comparison (expr (atom None))))))) )) (funcdef def (name search_min) ( (typedargslist (def_parameters (def_parameter (named_parameter (name li))) , (def_parameter (named_parameter (name ri))) , (def_parameter (named_parameter (name lc))) , (def_parameter (named_parameter (name rc))))) ) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name w)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name ri))) - (expr (atom (name li))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name base)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name aaa)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name li)))))))) ]))) * (expr (atom (name lc))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name w)))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name base))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name lrc)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name lc))) + (expr (atom (name rc))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name w)))) == (comparison (expr (atom (number (integer 2)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (expr (atom (name base))) + (expr (expr (atom (name aaa)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name li))) + (expr (atom (number (integer 1)))))))))) ]))) * (expr (atom (name lrc))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name w)))) == (comparison (expr (atom (number (integer 3)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name a1)))))) , (test (logical_test (comparison (expr (atom (name a2))))))) (assign_part = (testlist_star_expr (test (logical_test (comparison (expr (atom (name aaa)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name li))) + (expr (atom (number (integer 1)))))))))) ])))))) , (test (logical_test (comparison (expr (atom (name aaa)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name li))) + (expr (atom (number (integer 2)))))))))) ]))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (expr (expr (atom (name base))) + (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name a1))) + (expr (atom (name a2)))))))) ))) * (expr (atom (name lrc))))) + (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a1))) * (expr (atom (name lc)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name a2))) * (expr (atom (name rc))))))))) ))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ret)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name search_min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name li))))))) , (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (name lc))))))) , (argument (test (logical_test (comparison (expr (atom (name lrc)))))))) )))) + (expr (atom (name search_min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (name ri))))))) , (argument (test (logical_test (comparison (expr (atom (name lrc))))))) , (argument (test (logical_test (comparison (expr (atom (name rc)))))))) )))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name li))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name ri)))))))) ))))))))) ))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name ret))))))))))))) ; return search_min(0, n - 1, 1, 1) + aaa->last(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) elements=list(map(int,input().split(""))) class Node(): def __init__(self,value): self.value=value self.parent=-1 self.kids=[] def addParent(self,parent): self.parent=parent def addKid(self,kids): self.kids=kids nodes={} for i in range(len(elements)): nodes[i]=Node(int(elements[i])) parentIndex=0 def checkKids(index): leftKid=index*2+1 rightKid=index*2+2 kids=[] if leftKid in nodes : kids.append(leftKid) nodes[leftKid].addParent(index) checkKids(leftKid) if rightKid in nodes : kids.append(rightKid) nodes[rightKid].addParent(index) checkKids(rightKid) nodes[index].addKid(kids) checkKids(parentIndex) for id in nodes : ans="" ans+="node "+str(id+1) ans+=": key="+str(nodes[id].value) if not nodes[id].parent==-1 : ans+=",parent key="+str(nodes[nodes[id].parent].value) if len(nodes[id].kids)==1 : ans+=",left key="+str(nodes[nodes[id].kids[0]].value) elif len(nodes[id].kids)==2 : ans+=",left key="+str(nodes[nodes[id].kids[0]].value) ans+=",right key="+str(nodes[nodes[id].kids[1]].value) print(ans+",") ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute value : OclAny := value; attribute parent : int := -1; attribute kids : Sequence := Sequence{}; operation initialise(value : OclAny) : pre: true post: true activity: self.value := value ; self.parent := -1 ; self.kids := Sequence{}; return self; operation addParent(parent : OclAny) pre: true post: true activity: self.parent := parent; operation addKid(kids : OclAny) pre: true post: true activity: self.kids := kids; } class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var elements : Sequence := ((input().split(""))->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; var nodes : OclAny := Set{} ; for i : Integer.subrange(0, (elements)->size()-1) do ( nodes[i+1] := (Node.newNode()).initialise(("" + ((elements[i+1])))->toInteger())) ; var parentIndex : int := 0 ; skip ; checkKids(parentIndex) ; for id : nodes do ( var ans : String := "" ; ans := ans + "node " + ("" + ((id + 1))) ; ans := ans + ": key=" + ("" + ((nodes[id+1].value))) ; if not(nodes[id+1].parent = -1) then ( ans := ans + ",parent key=" + ("" + ((nodes[nodes[id+1].parent+1].value))) ) else skip ; if (nodes[id+1].kids)->size() = 1 then ( ans := ans + ",left key=" + ("" + ((nodes[nodes[id+1].kids->first()+1].value))) ) else (if (nodes[id+1].kids)->size() = 2 then ( ans := ans + ",left key=" + ("" + ((nodes[nodes[id+1].kids->first()+1].value))) ; ans := ans + ",right key=" + ("" + ((nodes[nodes[id+1].kids[1+1]+1].value))) ) else skip) ; execute (ans + ",")->display()); operation checkKids(index : OclAny) pre: true post: true activity: var leftKid : double := index * 2 + 1 ; var rightKid : double := index * 2 + 2 ; kids := Sequence{} ; if (nodes)->includes(leftKid) then ( execute ((leftKid) : kids) ; (expr (atom (name nodes)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name leftKid)))))))) ])) (trailer . (name addParent) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name index)))))))) )))) ; checkKids(leftKid) ) else skip ; if (nodes)->includes(rightKid) then ( execute ((rightKid) : kids) ; (expr (atom (name nodes)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name rightKid)))))))) ])) (trailer . (name addParent) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name index)))))))) )))) ; checkKids(rightKid) ) else skip ; (expr (atom (name nodes)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name index)))))))) ])) (trailer . (name addKid) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name kids)))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) def kukan(l,r,el=1,er=1): em=el+er if l+1==r : return 0 if l+2==r : return a[l+1]*em t=(l,r,el,er) if t in memo : return memo[t] re=10**11 for m in range(l+1,r): tmp=kukan(l,m,el,em)+kukan(m,r,em,er)+a[m]*em if tmppow(6)) ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var memo : OclAny := Set{} ; execute (a->first() + kukan(0, n - 1) + a->last())->display(); operation kukan(l : OclAny, r : OclAny, el : int, er : int) : OclAny pre: true post: true activity: if el->oclIsUndefined() then el := 1 else skip; if er->oclIsUndefined() then er := 1 else skip; var em : int := el + er ; if l + 1 = r then ( return 0 ) else skip ; if l + 2 = r then ( return a[l + 1+1] * em ) else skip ; var t : OclAny := Sequence{l, r, el, er} ; if (memo)->includes(t) then ( return memo[t+1] ) else skip ; var re : double := (10)->pow(11) ; for m : Integer.subrange(l + 1, r-1) do ( var tmp : OclAny := kukan(l, m, el, em) + kukan(m, r, em, er) + a[m+1] * em ; if (tmp->compareTo(re)) < 0 then ( re := tmp ) else skip) ; memo[t+1] := re ; return re; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Sum(k,n): Summ=0 for i in range(n+1): p=1 for j in range(n-i): p=p*k for j in range(i): p=p*(k-1) Summ=Summ+p return Summ n=3 K=3 print(Sum(K,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3 ; var K : int := 3 ; execute (Sum(K, n))->display(); operation Sum(k : OclAny, n : OclAny) : OclAny pre: true post: true activity: var Summ : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( var p : int := 1 ; for j : Integer.subrange(0, n - i-1) do ( p := p * k) ; for j : Integer.subrange(0, i-1) do ( p := p * (k - 1)) ; Summ := Summ + p) ; return Summ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(4): t,n=map(int,input().split()) if t==1 : print(6000*n) elif t==2 : print(4000*n) elif t==3 : print(3000*n) else : print(2000*n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, 4-1) do ( var t : OclAny := null; var n : OclAny := null; Sequence{t,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if t = 1 then ( execute (6000 * n)->display() ) else (if t = 2 then ( execute (4000 * n)->display() ) else (if t = 3 then ( execute (3000 * n)->display() ) else ( execute (2000 * n)->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ticket_price=[0,6000,4000,3000,2000] if __name__=="__main__" : for i in range(4): sales=list(map(int,input().split())) print("{0}".format(ticket_price[sales[0]]*sales[1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ticket_price : Sequence := Sequence{0}->union(Sequence{6000}->union(Sequence{4000}->union(Sequence{3000}->union(Sequence{ 2000 })))) ; if __name__ = "__main__" then ( for i : Integer.subrange(0, 4-1) do ( var sales : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (StringLib.interpolateStrings("{0}", Sequence{ticket_price[sales->first()+1] * sales[1+1]}))->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,A=map(int,input().split()) b,B=map(int,input().split()) c,C=map(int,input().split()) d,D=map(int,input().split()) if(a==1): print(A*6000) elif(a==2): print(A*4000) elif(a==3): print(A*3000) elif(a==4): print(A*2000) if(b==1): print(B*6000) elif(b==2): print(B*4000) elif(b==3): print(B*3000) elif(b==4): print(B*2000) if(c==1): print(C*6000) elif(c==2): print(C*4000) elif(c==3): print(C*3000) elif(c==4): print(C*2000) if(d==1): print(D*6000) elif(d==2): print(D*4000) elif(d==3): print(D*3000) elif(d==4): print(D*2000) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var A : OclAny := null; Sequence{a,A} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : OclAny := null; var B : OclAny := null; Sequence{b,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : OclAny := null; var C : OclAny := null; Sequence{c,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : OclAny := null; var D : OclAny := null; Sequence{d,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a = 1) then ( execute (A * 6000)->display() ) else (if (a = 2) then ( execute (A * 4000)->display() ) else (if (a = 3) then ( execute (A * 3000)->display() ) else (if (a = 4) then ( execute (A * 2000)->display() ) else skip ) ) ) ; if (b = 1) then ( execute (B * 6000)->display() ) else (if (b = 2) then ( execute (B * 4000)->display() ) else (if (b = 3) then ( execute (B * 3000)->display() ) else (if (b = 4) then ( execute (B * 2000)->display() ) else skip ) ) ) ; if (c = 1) then ( execute (C * 6000)->display() ) else (if (c = 2) then ( execute (C * 4000)->display() ) else (if (c = 3) then ( execute (C * 3000)->display() ) else (if (c = 4) then ( execute (C * 2000)->display() ) else skip ) ) ) ; if (d = 1) then ( execute (D * 6000)->display() ) else (if (d = 2) then ( execute (D * 4000)->display() ) else (if (d = 3) then ( execute (D * 3000)->display() ) else (if (d = 4) then ( execute (D * 2000)->display() ) else skip ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t1,n1=map(int,input().split()) t2,n2=map(int,input().split()) t3,n3=map(int,input().split()) t4,n4=map(int,input().split()) i=1 while i<=4 : if t1==1 : t1=6000 elif t1==2 : t1=4000 elif t1==3 : t1=3000 elif t1==4 : t1=2000 elif t2==1 : t2=6000 elif t2==2 : t2=4000 elif t2==3 : t2=3000 elif t2==4 : t2=2000 elif t3==1 : t3=6000 elif t3==2 : t3=4000 elif t3==3 : t3=3000 elif t3==4 : t3=2000 elif t4==1 : t4=6000 elif t4==2 : t4=4000 elif t4==3 : t4=3000 elif t4==4 : t4=2000 i+=1 print(t1*n1) print(t2*n2) print(t3*n3) print(t4*n4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t1 : OclAny := null; var n1 : OclAny := null; Sequence{t1,n1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t2 : OclAny := null; var n2 : OclAny := null; Sequence{t2,n2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t3 : OclAny := null; var n3 : OclAny := null; Sequence{t3,n3} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t4 : OclAny := null; var n4 : OclAny := null; Sequence{t4,n4} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var i : int := 1 ; while i <= 4 do ( if t1 = 1 then ( var t1 : int := 6000 ) else (if t1 = 2 then ( t1 := 4000 ) else (if t1 = 3 then ( t1 := 3000 ) else (if t1 = 4 then ( t1 := 2000 ) else (if t2 = 1 then ( var t2 : int := 6000 ) else (if t2 = 2 then ( t2 := 4000 ) else (if t2 = 3 then ( t2 := 3000 ) else (if t2 = 4 then ( t2 := 2000 ) else (if t3 = 1 then ( var t3 : int := 6000 ) else (if t3 = 2 then ( t3 := 4000 ) else (if t3 = 3 then ( t3 := 3000 ) else (if t3 = 4 then ( t3 := 2000 ) else (if t4 = 1 then ( var t4 : int := 6000 ) else (if t4 = 2 then ( t4 := 4000 ) else (if t4 = 3 then ( t4 := 3000 ) else (if t4 = 4 then ( t4 := 2000 ) else skip ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ; i := i + 1) ; execute (t1 * n1)->display() ; execute (t2 * n2)->display() ; execute (t3 * n3)->display() ; execute (t4 * n4)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t1,n1=map(int,input().split()) t2,n2=map(int,input().split()) t3,n3=map(int,input().split()) t4,n4=map(int,input().split()) if t1==1 : print(6000*n1) elif t1==2 : print(4000*n1) elif t1==3 : print(3000*n1) elif t1==4 : print(2000*n1) if t2==1 : print(6000*n2) elif t2==2 : print(4000*n2) elif t2==3 : print(3000*n2) elif t2==4 : print(2000*n2) if t3==1 : print(6000*n3) elif t3==2 : print(4000*n3) elif t3==3 : print(3000*n3) elif t3==4 : print(2000*n3) if t4==1 : print(6000*n4) elif t4==2 : print(4000*n4) elif t4==3 : print(3000*n4) elif t4==4 : print(2000*n4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t1 : OclAny := null; var n1 : OclAny := null; Sequence{t1,n1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t2 : OclAny := null; var n2 : OclAny := null; Sequence{t2,n2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t3 : OclAny := null; var n3 : OclAny := null; Sequence{t3,n3} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t4 : OclAny := null; var n4 : OclAny := null; Sequence{t4,n4} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if t1 = 1 then ( execute (6000 * n1)->display() ) else (if t1 = 2 then ( execute (4000 * n1)->display() ) else (if t1 = 3 then ( execute (3000 * n1)->display() ) else (if t1 = 4 then ( execute (2000 * n1)->display() ) else skip ) ) ) ; if t2 = 1 then ( execute (6000 * n2)->display() ) else (if t2 = 2 then ( execute (4000 * n2)->display() ) else (if t2 = 3 then ( execute (3000 * n2)->display() ) else (if t2 = 4 then ( execute (2000 * n2)->display() ) else skip ) ) ) ; if t3 = 1 then ( execute (6000 * n3)->display() ) else (if t3 = 2 then ( execute (4000 * n3)->display() ) else (if t3 = 3 then ( execute (3000 * n3)->display() ) else (if t3 = 4 then ( execute (2000 * n3)->display() ) else skip ) ) ) ; if t4 = 1 then ( execute (6000 * n4)->display() ) else (if t4 = 2 then ( execute (4000 * n4)->display() ) else (if t4 = 3 then ( execute (3000 * n4)->display() ) else (if t4 = 4 then ( execute (2000 * n4)->display() ) else skip ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda : sys.stdin.readline().rstrip() YesNo=lambda b : bool([print('Yes')]if b else print('No')) YESNO=lambda b : bool([print('YES')]if b else print('NO')) int1=lambda x : int(x)-1 def main(): N=int(input()) s=input() s=s+s[0] for j in range(4): l=[-1]*(N+2) for k in range(2): l[k]=(j>>k)& 1 for i in range(1,N+1): if l[i]==0 : if s[i-1]=='o' : l[i+1]=l[i-1] else : l[i+1]=int(not l[i-1]) else : if s[i-1]=='o' : l[i+1]=int(not l[i-1]) else : l[i+1]=l[i-1] if l[0]==l[-2]and l[1]==l[-1]: for x in l[1 : N+1]: if x==0 : print('S',end='') else : print('W',end='') print('') exit() print(-1) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var YesNo : Function := lambda b : OclAny in ((if b then Sequence{ ('Yes')->display() } else ('No')->display() endif)->toBoolean()) ; var YESNO : Function := lambda b : OclAny in ((if b then Sequence{ ('YES')->display() } else ('NO')->display() endif)->toBoolean()) ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; s := s + s->first() ; for j : Integer.subrange(0, 4-1) do ( var l : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (N + 2)) ; for k : Integer.subrange(0, 2-1) do ( l[k+1] := MathLib.bitwiseAnd((j /(2->pow(k))), 1)) ; for i : Integer.subrange(1, N + 1-1) do ( if l[i+1] = 0 then ( if s[i - 1+1] = 'o' then ( l[i + 1+1] := l[i - 1+1] ) else ( l[i + 1+1] := ("" + ((not(l[i - 1+1]))))->toInteger() ) ) else ( if s[i - 1+1] = 'o' then ( l[i + 1+1] := ("" + ((not(l[i - 1+1]))))->toInteger() ) else ( l[i + 1+1] := l[i - 1+1] ) )) ; if l->first() = l->front()->last() & l[1+1] = l->last() then ( for x : l.subrange(1+1, N + 1) do ( if x = 0 then ( execute ('S')->display() ) else ( execute ('W')->display() )) ; execute ('')->display() ; exit() ) else skip) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) slist=[x=="o" for x in input()] answer_list=[0]*N ok=False for p1,p2 in[(1,1),(1,-1),(-1,1),(-1,-1)]: answer_list[0]=p1 answer_list[1]=p2 for i in range(2,N): if answer_list[i-1]==1 : if slist[i-1]: answer_list[i]=answer_list[i-2] else : answer_list[i]=-answer_list[i-2] else : if slist[i-1]: answer_list[i]=-answer_list[i-2] else : answer_list[i]=answer_list[i-2] contra=False for i in range(N): l=(i-1)% N r=(i+1)% N if answer_list[i]==1 : if slist[i]: if answer_list[l]!=answer_list[r]: contra=True else : if answer_list[l]==answer_list[r]: contra=True else : if slist[i]: if answer_list[l]==answer_list[r]: contra=True else : if answer_list[l]!=answer_list[r]: contra=True if not contra : ok=True break if ok : sw_list=[] for ans in answer_list : if ans==1 : sw_list.append("S") else : sw_list.append("W") print("".join(sw_list)) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var slist : Sequence := (OclFile["System.in"]).readLine()->select(x | true)->collect(x | (x = "o")) ; var answer_list : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var ok : boolean := false ; for _tuple : Sequence{Sequence{1, 1}}->union(Sequence{Sequence{1, -1}}->union(Sequence{Sequence{-1, 1}}->union(Sequence{ Sequence{-1, -1} }))) do (var _indx : int := 1; var p1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p2 : OclAny := _tuple->at(_indx); answer_list->first() := p1 ; answer_list[1+1] := p2 ; for i : Integer.subrange(2, N-1) do ( if answer_list[i - 1+1] = 1 then ( if slist[i - 1+1] then ( answer_list[i+1] := answer_list[i - 2+1] ) else ( answer_list[i+1] := -answer_list[i - 2+1] ) ) else ( if slist[i - 1+1] then ( answer_list[i+1] := -answer_list[i - 2+1] ) else ( answer_list[i+1] := answer_list[i - 2+1] ) )) ; var contra : boolean := false ; for i : Integer.subrange(0, N-1) do ( var l : int := (i - 1) mod N ; var r : int := (i + 1) mod N ; if answer_list[i+1] = 1 then ( if slist[i+1] then ( if answer_list[l+1] /= answer_list[r+1] then ( contra := true ) else skip ) else ( if answer_list[l+1] = answer_list[r+1] then ( contra := true ) else skip ) ) else ( if slist[i+1] then ( if answer_list[l+1] = answer_list[r+1] then ( contra := true ) else skip ) else ( if answer_list[l+1] /= answer_list[r+1] then ( contra := true ) else skip ) )) ; if not(contra) then ( ok := true ; break ) else skip) ; if ok then ( var sw_list : Sequence := Sequence{} ; for ans : answer_list do ( if ans = 1 then ( execute (("S") : sw_list) ) else ( execute (("W") : sw_list) )) ; execute (StringLib.sumStringsWithSeparator((sw_list), ""))->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() def func(s): ca=0 cb=0 cc=0 for i in range(1,len(s)): if s[i-1]>s[i]: return "NO" for i in range(0,len(s)): if s[i]=="a" : ca+=1 if s[i]=="b" : cb+=1 if s[i]=="c" : cc+=1 if(cc==ca or cc==cb): if ca<=0 or cb<=0 : return "NO" return "YES" else : return 'NO' print(func(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; skip ; execute (func(s))->display(); operation func(s : OclAny) : OclAny pre: true post: true activity: var ca : int := 0 ; var cb : int := 0 ; var cc : int := 0 ; for i : Integer.subrange(1, (s)->size()-1) do ( if (s[i - 1+1]->compareTo(s[i+1])) > 0 then ( return "NO" ) else skip) ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = "a" then ( ca := ca + 1 ) else skip ; if s[i+1] = "b" then ( cb := cb + 1 ) else skip ; if s[i+1] = "c" then ( cc := cc + 1 ) else skip) ; if (cc = ca or cc = cb) then ( if ca <= 0 or cb <= 0 then ( return "NO" ) else skip ; return "YES" ) else ( return 'NO' ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_list(L,i): return L[i]if len(L)>i else None def print_key(key_name,val): print(key_name,"key={0},".format(val),end="") H=int(input()) hp=list(map(int,input().split())) if H>0 : print_key("node 1:",hp[0]) l=get_list(hp,1) r=get_list(hp,2) if l : print_key("left",l) if r : print_key("right",r) print("") if H>1 : for i in range(2,H+1): print_key("node{0}:".format(i),hp[i-1]) print_key("parent",hp[i//2-1]) l=get_list(hp,i*2-1) r=get_list(hp,i*2) if l : print_key("left",l) if r : print_key("right",r) print("") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var H : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var hp : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if H > 0 then ( print_key("node 1:", hp->first()) ; var l : OclAny := get_list(hp, 1) ; var r : OclAny := get_list(hp, 2) ; if l then ( print_key("left", l) ) else skip ; if r then ( print_key("right", r) ) else skip ; execute ("")->display() ) else skip ; if H > 1 then ( for i : Integer.subrange(2, H + 1-1) do ( print_key(StringLib.interpolateStrings("node{0}:", Sequence{i}), hp[i - 1+1]) ; print_key("parent", hp[i div 2 - 1+1]) ; l := get_list(hp, i * 2 - 1) ; r := get_list(hp, i * 2) ; if l then ( print_key("left", l) ) else skip ; if r then ( print_key("right", r) ) else skip ; execute ("")->display()) ) else skip; operation get_list(L : OclAny, i : OclAny) : OclAny pre: true post: true activity: return if ((L)->size()->compareTo(i)) > 0 then L[i+1] else null endif; operation print_key(key_name : OclAny, val : OclAny) pre: true post: true activity: execute (key_name)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def make(l,ai): global N for i in range(2,N): ai.append(ai[i-2]==(ai[i-1]==l[i-1])) return ai def check(l,ai): return ai[0]==(ai[-2]==(ai[-1]==l[-1]))and ai[1]==(ai[-1]==(ai[0]==l[0])) N=int(input()) l=[c=='o' for c in input()] f=False a=[[True,True],[True,False],[False,True],[False,False]] for ai in a : ai=make(l,ai) f=False for ai in a : if check(l,ai): for aij in ai : print('S' if aij else 'W',end='') f=True break if not f : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute N : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; l := (OclFile["System.in"]).readLine()->select(c | true)->collect(c | (c = 'o')) ; var f : boolean := false ; var a : Sequence := Sequence{Sequence{true}->union(Sequence{ true })}->union(Sequence{Sequence{true}->union(Sequence{ false })}->union(Sequence{Sequence{false}->union(Sequence{ true })}->union(Sequence{ Sequence{false}->union(Sequence{ false }) }))) ; for ai : a do ( ai := make(l, ai)) ; f := false ; for ai : a do ( if check(l, ai) then ( for aij : ai do ( execute (if aij then 'S' else 'W' endif)->display()) ; f := true ; break ) else skip) ; if not(f) then ( execute (-1)->display() ) else skip; operation make(l : OclAny, ai : OclAny) : OclAny pre: true post: true activity: skip ; for i : Integer.subrange(2, N-1) do ( execute ((ai[i - 2+1] = (ai[i - 1+1] = l[i - 1+1])) : ai)) ; return ai; operation check(l : OclAny, ai : OclAny) : OclAny pre: true post: true activity: return ai->first() = (ai->front()->last() = (ai->last() = l->last())) & ai[1+1] = (ai->last() = (ai->first() = l->first())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import product N=int(input()) s=input() answer=['']*N for i,j in product(['S','W'],repeat=2): answer[0]=i answer[1]=j for k in range(2,N): if answer[k-1]=='S' : if s[k-1]=='o' : answer[k]=answer[k-2] else : if answer[k-2]=='W' : answer[k]='S' else : answer[k]='W' else : if s[k-1]=='x' : answer[k]=answer[k-2] else : if answer[k-2]=='W' : answer[k]='S' else : answer[k]='W' for k in[-1,0]: if answer[k]=='S' : if s[k]=='o' : if answer[k-1]!=answer[k+1]: break else : if answer[k-1]==answer[k+1]: break else : if s[k]=='x' : if answer[k-1]!=answer[k+1]: break else : if answer[k-1]==answer[k+1]: break else : print(''.join(answer)) exit() print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var answer : Sequence := MatrixLib.elementwiseMult(Sequence{ '' }, N) ; for _tuple : product(Sequence{'S'}->union(Sequence{ 'W' }), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); answer->first() := i ; answer[1+1] := j ; for k : Integer.subrange(2, N-1) do ( if answer[k - 1+1] = 'S' then ( if s[k - 1+1] = 'o' then ( answer[k+1] := answer[k - 2+1] ) else ( if answer[k - 2+1] = 'W' then ( answer[k+1] := 'S' ) else ( answer[k+1] := 'W' ) ) ) else ( if s[k - 1+1] = 'x' then ( answer[k+1] := answer[k - 2+1] ) else ( if answer[k - 2+1] = 'W' then ( answer[k+1] := 'S' ) else ( answer[k+1] := 'W' ) ) )) ; (compound_stmt for (exprlist (expr (atom (name k)))) in (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom - (number (integer 1))))))) , (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name answer)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])))) == (comparison (expr (atom 'S')))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])))) == (comparison (expr (atom 'o')))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name answer)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name k))) - (expr (atom (number (integer 1)))))))))) ])))) != (comparison (expr (atom (name answer)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name k))) + (expr (atom (number (integer 1)))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name answer)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name k))) - (expr (atom (number (integer 1)))))))))) ])))) == (comparison (expr (atom (name answer)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name k))) + (expr (atom (number (integer 1)))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt break))))))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])))) == (comparison (expr (atom 'x')))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name answer)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name k))) - (expr (atom (number (integer 1)))))))))) ])))) != (comparison (expr (atom (name answer)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name k))) + (expr (atom (number (integer 1)))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name answer)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name k))) - (expr (atom (number (integer 1)))))))))) ])))) == (comparison (expr (atom (name answer)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name k))) + (expr (atom (number (integer 1)))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt break))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name answer)))))))) ))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name exit)) (trailer (arguments ( )))))))))))))))) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(100000000) def input(): return sys.stdin.readline()[:-1] from bisect import* from collections import* from heapq import* from math import* n=int(input()) s=input() s=[0 if t=='o' else 1 for t in s] x=[None]*n for a,b in[(0,0),(0,1),(1,0),(1,1)]: x[0],x[1]=a,b flag=1 for i in range(2,n): x[i]=1 ^ x[i-2]if x[i-1]^ s[i-1]else x[i-2] for i in range(n-1): if(x[i]^ s[i])^(x[i-1]!=x[i+1]): flag=0 break if flag and((x[n-1]^ s[n-1])^(x[n-2]!=x[0]))==0 : x=['S' if t==0 else 'W' for t in x] print(*x,sep='') exit() print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(100000000) ; skip ; skip ; skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; s := s->characters()->select(t | true)->collect(t | (if t = 'o' then 0 else 1 endif)) ; var x : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; for _tuple : Sequence{Sequence{0, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{ Sequence{1, 1} }))) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); var x->first() : OclAny := null; var x[1+1] : OclAny := null; Sequence{x->first(),x[1+1]} := Sequence{a,b} ; var flag : int := 1 ; for i : Integer.subrange(2, n-1) do ( x[i+1] := if MathLib.bitwiseXor(x[i - 1+1], s[i - 1+1]) then MathLib.bitwiseXor(1, x[i - 2+1]) else x[i - 2+1] endif) ; for i : Integer.subrange(0, n - 1-1) do ( if MathLib.bitwiseXor((MathLib.bitwiseXor(x[i+1], s[i+1])), (x[i - 1+1] /= x[i + 1+1])) then ( flag := 0 ; break ) else skip) ; if flag & (MathLib.bitwiseXor((MathLib.bitwiseXor(x[n - 1+1], s[n - 1+1])), (x[n - 2+1] /= x->first()))) = 0 then ( x := x->select(t | true)->collect(t | (if t = 0 then 'S' else 'W' endif)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display() ; exit() ) else skip) ; execute (-1)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findTrailingZeros(n): count=0 i=5 while(n/i>=1): count+=int(n/i) i*=5 return int(count) n=100 print("Count of trailing 0s "+"in 100! is",findTrailingZeros(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 100 ; execute ("Count of trailing 0s " + "in 100! is")->display(); operation findTrailingZeros(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var i : int := 5 ; while (n / i >= 1) do ( count := count + ("" + ((n / i)))->toInteger() ; i := i * 5) ; return ("" + ((count)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numRay=[0,4,3,2,7,8,2,3,1]; arr_size=len(numRay); for i in range(arr_size): numRay[numRay[i]% arr_size]=numRay[numRay[i]% arr_size]+arr_size ; print("The repeating elements are : "); for i in range(arr_size): if(numRay[i]>=arr_size*2): print(i," "); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var numRay : Sequence := Sequence{0}->union(Sequence{4}->union(Sequence{3}->union(Sequence{2}->union(Sequence{7}->union(Sequence{8}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 1 })))))))); ; var arr_size : int := (numRay)->size(); ; for i : Integer.subrange(0, arr_size-1) do ( numRay[numRay[i+1] mod arr_size+1] := numRay[numRay[i+1] mod arr_size+1] + arr_size;) ; execute ("The repeating elements are : ")->display(); ; for i : Integer.subrange(0, arr_size-1) do ( if ((numRay[i+1]->compareTo(arr_size * 2)) >= 0) then ( execute (i)->display(); ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class getNode : def __init__(self,data): self.data=data self.left=None self.right=None def isFullBinaryTree(root): if(not root): return True q=[] q.append(root) while(not len(q)): node=q[0] q.pop(0) if(node.left==None and node.right==None): continue if(node.left==None or node.right==None): return False q.append(node.left) q.append(node.right) return True if __name__=='__main__' : root=getNode(1) root.left=getNode(2) root.right=getNode(3) root.left.left=getNode(4) root.left.right=getNode(5) if(isFullBinaryTree(root)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class getNode { static operation newgetNode() : getNode pre: true post: getNode->exists( _x | result = _x ); attribute data : OclAny := data; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(data : OclAny) : getNode pre: true post: true activity: self.data := data ; self.left := null ; self.right := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( root := (getNode.newgetNode()).initialise(1) ; root.left := (getNode.newgetNode()).initialise(2) ; root.right := (getNode.newgetNode()).initialise(3) ; root.left.left := (getNode.newgetNode()).initialise(4) ; root.left.right := (getNode.newgetNode()).initialise(5) ; if (isFullBinaryTree(root)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isFullBinaryTree(root : OclAny) : OclAny pre: true post: true activity: if (not(root)) then ( return true ) else skip ; var q : Sequence := Sequence{} ; execute ((root) : q) ; while (not((q)->size())) do ( var node : OclAny := q->first() ; q := q->excludingAt(0+1) ; if (node.left = null & node.right = null) then ( continue ) else skip ; if (node.left = null or node.right = null) then ( return false ) else skip ; execute ((node.left) : q) ; execute ((node.right) : q)) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findCount(arr,n): countOdd=0 ; for i in range(n): if(arr[i]% 2==1): countOdd+=1 ; if(countOdd % 2==0): return 1 ; else : return 0 ; if __name__=="__main__" : arr=[1,2,3,5,1]; n=len(arr); print(findCount(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 1 })))); ; n := (arr)->size(); ; execute (findCount(arr, n))->display(); ) else skip; operation findCount(arr : OclAny, n : OclAny) pre: true post: true activity: var countOdd : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] mod 2 = 1) then ( countOdd := countOdd + 1; ) else skip) ; if (countOdd mod 2 = 0) then ( return 1; ) else ( return 0; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumArr(arr,n): sum=0 for i in range(n): sum+=arr[i] return sum def maxSum(arr,n,k): arr.sort(reverse=False) i=0 while(i0 and arr[i]<0): arr[i]*=-1 k-=1 i+=1 if(k % 2==1): min=0 for i in range(1,n): if(arr[min]>arr[i]): min=i arr[min]*=-1 return sumArr(arr,n) if __name__=='__main__' : arr=[-5,4,1,3,2] n=len(arr) k=4 print(maxSum(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{-5}->union(Sequence{4}->union(Sequence{1}->union(Sequence{3}->union(Sequence{ 2 })))) ; n := (arr)->size() ; k := 4 ; execute (maxSum(arr, n, k))->display() ) else skip; operation sumArr(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + arr[i+1]) ; return sum; operation maxSum(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var i : int := 0 ; while ((i->compareTo(n)) < 0 & k > 0 & arr[i+1] < 0) do ( arr[i+1] := arr[i+1] * -1 ; k := k - 1 ; i := i + 1) ; if (k mod 2 = 1) then ( var min : int := 0 ; for i : Integer.subrange(1, n-1) do ( if ((arr[min+1]->compareTo(arr[i+1])) > 0) then ( min := i ) else skip) ; arr[min+1] := arr[min+1] * -1 ) else skip ; return sumArr(arr, n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,ceil def compositeSumProduct(arr,n,k): max_val=arr[0]; for i in range(len(arr)): if(max_valunion(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 7 })))))) ; n := (arr)->size() ; k := 2 ; compositeSumProduct(arr, n, k) ) else skip; operation compositeSumProduct(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var max_val : OclAny := arr->first(); ; for i : Integer.subrange(0, (arr)->size()-1) do ( if ((max_val->compareTo(arr[i+1])) < 0) then ( max_val := arr[i+1] ) else skip) ; var prime : Sequence := Integer.subrange(0, max_val + 1-1)->select(i | true)->collect(i | (true)) ; k := ("" + ((sqrt(max_val))))->toInteger() ; for p : Integer.subrange(2, k + 1-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (prime[p+1] = true) then ( for i : Integer.subrange(p * 2, max_val-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip) ; var sum : int := 0 ; var product : int := 1 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (prime[arr[i+1]+1] = false & arr[i+1] mod k = 0) then ( sum := sum + arr[i+1] ; product := product * arr[i+1] ) else skip) ; execute ("Sum of composite numbers")->display() ; execute ("Product of composite numbers")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import os import math from collections import defaultdict for s in sys.stdin : n=int(s) if n==0 : break d=defaultdict(int) keys=[] for i in range(n): e,p,q=map(int,input().split()) d[e]+=p*q if e not in keys : keys.append(e) is_exist=False for key in keys : v=d[key] if v>=1000000 : print(key) is_exist=True if not is_exist : print('NA') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; for s : OclFile["System.in"] do ( var n : int := ("" + ((s)))->toInteger() ; if n = 0 then ( break ) else skip ; var d : OclAny := defaultdict(OclType["int"]) ; var keys : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var e : OclAny := null; var p : OclAny := null; var q : OclAny := null; Sequence{e,p,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; d[e+1] := d[e+1] + p * q ; if (keys)->excludes(e) then ( execute ((e) : keys) ) else skip) ; var is_exist : boolean := false ; for key : keys do ( var v : OclAny := d[key+1] ; if v >= 1000000 then ( execute (key)->display() ; is_exist := true ) else skip) ; if not(is_exist) then ( execute ('NA')->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fastPow(N,K): if(K==0): return 1 ; temp=fastPow(N,int(K/2)); if(K % 2==0): return temp*temp ; else : return N*temp*temp ; def countWays(N,K): return K*fastPow(K-1,N-1); N=3 ; K=3 ; print(countWays(N,K)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; N := 3; ; K := 3; ; execute (countWays(N, K))->display();; operation fastPow(N : OclAny, K : OclAny) pre: true post: true activity: if (K = 0) then ( return 1; ) else skip ; var temp : OclAny := fastPow(N, ("" + ((K / 2)))->toInteger()); ; if (K mod 2 = 0) then ( return temp * temp; ) else ( return N * temp * temp; ); operation countWays(N : OclAny, K : OclAny) pre: true post: true activity: return K * fastPow(K - 1, N - 1);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np n=6 ; m=6 ; def maxSum(arr): dp=np.zeros((n+1,3)); for i in range(n): m1=0 ; m2=0 ; m3=0 ; for j in range(m): if((j//(m//3))==0): m1=max(m1,arr[i][j]); elif((j//(m//3))==1): m2=max(m2,arr[i][j]); elif((j//(m//3))==2): m3=max(m3,arr[i][j]); dp[i+1][0]=max(dp[i][1],dp[i][2])+m1 ; dp[i+1][1]=max(dp[i][0],dp[i][2])+m2 ; dp[i+1][2]=max(dp[i][1],dp[i][0])+m3 ; print(max(max(dp[n][0],dp[n][1]),dp[n][2])); if __name__=="__main__" : arr=[[1,3,5,2,4,6],[6,4,5,1,3,2],[1,3,5,2,4,6],[6,4,5,1,3,2],[6,4,5,1,3,2],[1,3,5,2,4,6]]; maxSum(arr); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := 6; var m : int := 6; ; skip ; if __name__ = "__main__" then ( arr := Sequence{Sequence{1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 6 })))))}->union(Sequence{Sequence{6}->union(Sequence{4}->union(Sequence{5}->union(Sequence{1}->union(Sequence{3}->union(Sequence{ 2 })))))}->union(Sequence{Sequence{1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 6 })))))}->union(Sequence{Sequence{6}->union(Sequence{4}->union(Sequence{5}->union(Sequence{1}->union(Sequence{3}->union(Sequence{ 2 })))))}->union(Sequence{Sequence{6}->union(Sequence{4}->union(Sequence{5}->union(Sequence{1}->union(Sequence{3}->union(Sequence{ 2 })))))}->union(Sequence{ Sequence{1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 6 }))))) }))))); ; maxSum(arr); ) else skip; operation maxSum(arr : OclAny) pre: true post: true activity: var dp : Sequence := MatrixLib.singleValueMatrix(Sequence{n + 1, 3}, 0.0); ; for i : Integer.subrange(0, n-1) do ( var m1 : int := 0; var m2 : int := 0; var m3 : int := 0; ; for j : Integer.subrange(0, m-1) do ( if ((j div (m div 3)) = 0) then ( m1 := Set{m1, arr[i+1][j+1]}->max(); ) else (if ((j div (m div 3)) = 1) then ( m2 := Set{m2, arr[i+1][j+1]}->max(); ) else (if ((j div (m div 3)) = 2) then ( m3 := Set{m3, arr[i+1][j+1]}->max(); ) else skip ) ) ) ; dp[i + 1+1]->first() := Set{dp[i+1][1+1], dp[i+1][2+1]}->max() + m1; ; dp[i + 1+1][1+1] := Set{dp[i+1]->first(), dp[i+1][2+1]}->max() + m2; ; dp[i + 1+1][2+1] := Set{dp[i+1][1+1], dp[i+1]->first()}->max() + m3;) ; execute (Set{Set{dp[n+1]->first(), dp[n+1][1+1]}->max(), dp[n+1][2+1]}->max())->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) accums=[0] for i in range(n-1): accums.append(accums[-1]+int(input())) result=0 k=0 for i in range(m): a=int(input()) result+=abs(accums[k+a]-accums[k]) k+=a print(result % 100000) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var accums : Sequence := Sequence{ 0 } ; for i : Integer.subrange(0, n - 1-1) do ( execute ((accums->last() + ("" + (((OclFile["System.in"]).readLine())))->toInteger()) : accums)) ; var result : int := 0 ; var k : int := 0 ; for i : Integer.subrange(0, m-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; result := result + (accums[k + a+1] - accums[k+1])->abs() ; k := k + a) ; execute (result mod 100000)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=int(input()) while l!=0 : k=0 A=[] B=[] for l in range(0,l): li=input().split() if li[0]in A : i=A.index(li[0]) B[i]=B[i]+(int(li[1])*int(li[2])) else : A.append(li[0]) B.append(int(li[1])*int(li[2])) for j,b in enumerate(B): if b>=10**6 : print(A[j]) k=1 if k==0 : print("NA") l=int(input()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while l /= 0 do ( var k : int := 0 ; var A : Sequence := Sequence{} ; var B : Sequence := Sequence{} ; for l : Integer.subrange(0, l-1) do ( var li : OclAny := input().split() ; if (A)->includes(li->first()) then ( var i : int := A->indexOf(li->first()) - 1 ; B[i+1] := B[i+1] + (("" + ((li[1+1])))->toInteger() * ("" + ((li[2+1])))->toInteger()) ) else ( execute ((li->first()) : A) ; execute ((("" + ((li[1+1])))->toInteger() * ("" + ((li[2+1])))->toInteger()) : B) )) ; for _tuple : Integer.subrange(1, (B)->size())->collect( _indx | Sequence{_indx-1, (B)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if (b->compareTo((10)->pow(6))) >= 0 then ( execute (A[j+1])->display() ; k := 1 ) else skip) ; if k = 0 then ( execute ("NA")->display() ) else skip ; l := ("" + (((OclFile["System.in"]).readLine())))->toInteger()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def searchEmployeeSales(employeeId): for data in employeeSalesList : if data[0]==employeeId : return data newData=[employeeId,0] employeeSalesList.append(newData) return newData dataCount=int(input()) while dataCount>0 : employeeSalesList=[] for _ in range(dataCount): dataList=input().split(" ") employeeId,price=dataList[0],int(dataList[1])*int(dataList[2]) employeeSales=searchEmployeeSales(employeeId) employeeSales[1]+=price answerList=[data[0]for data in employeeSalesList if data[1]>=1000000] if answerList : print("\n".join(map(str,answerList))) else : print("NA") dataCount=int(input()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var dataCount : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while dataCount > 0 do ( var employeeSalesList : Sequence := Sequence{} ; for _anon : Integer.subrange(0, dataCount-1) do ( var dataList : OclAny := input().split(" ") ; var price : OclAny := null; Sequence{employeeId,price} := Sequence{dataList->first(),("" + ((dataList[1+1])))->toInteger() * ("" + ((dataList[2+1])))->toInteger()} ; var employeeSales : OclAny := searchEmployeeSales(employeeId) ; employeeSales[1+1] := employeeSales[1+1] + price) ; var answerList : Sequence := employeeSalesList->select(data | data[1+1] >= 1000000)->collect(data | (data->first())) ; if answerList then ( execute (StringLib.sumStringsWithSeparator(((answerList)->collect( _x | (OclType["String"])->apply(_x) )), "\n"))->display() ) else ( execute ("NA")->display() ) ; dataCount := ("" + (((OclFile["System.in"]).readLine())))->toInteger()); operation searchEmployeeSales(employeeId : OclAny) : OclAny pre: true post: true activity: for data : employeeSalesList do ( if data->first() = employeeId then ( return data ) else skip) ; var newData : Sequence := Sequence{employeeId}->union(Sequence{ 0 }) ; execute ((newData) : employeeSalesList) ; return newData; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while(True): inputCount=int(input()) if inputCount==0 : break employeeNumber=[] employeePrice=[] while 0toInteger() ; if inputCount = 0 then ( break ) else skip ; var employeeNumber : Sequence := Sequence{} ; var employeePrice : Sequence := Sequence{} ; while 0 < inputCount do ( var inputNum : Sequence := input().split(" ")->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; var price : double := inputNum[1+1] * inputNum[2+1] ; if (employeeNumber)->includes(inputNum->first()) then ( var index : int := employeeNumber->indexOf(inputNum->first()) - 1 ; employeePrice[index+1] := employeePrice[index+1] + price ) else ( execute ((inputNum->first()) : employeeNumber) ; execute ((price) : employeePrice) ) ; inputCount := inputCount - 1) ; var isExist : boolean := false ; for index : Integer.subrange(0, (employeeNumber)->size()-1) do ( if 1000000 <= employeePrice[index+1] then ( execute (employeeNumber[index+1])->display() ; isExist := true ) else skip) ; if not(isExist) then ( execute ("NA")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : input_n=int(input()) key=0 if input_n==0 : break id_list=[[0 for i in range(2)]for i in range(input_n)] for i in range(input_n): id_line=input().split() for j in id_list : if j[0]==int(id_line[0]): j[1]+=int(id_line[1])*int(id_line[2]) uriage=j[1] break else : id_list[i][0]=int(id_line[0]) id_list[i][1]=int(id_line[1])*int(id_line[2]) uriage=id_list[i][1] if uriage>=1000000 : key=1 for i in id_list : if key==0 : print("NA") break if i[1]>=1000000 : print(i[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var input_n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var key : int := 0 ; if input_n = 0 then ( break ) else skip ; var id_list : Sequence := Integer.subrange(0, input_n-1)->select(i | true)->collect(i | (Integer.subrange(0, 2-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, input_n-1) do ( var id_line : OclAny := input().split() ; (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name id_list))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name j)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) == (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name id_line)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name j)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name id_line)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))) * (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name id_line)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name uriage)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name j)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name id_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name id_line)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name id_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name id_line)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))) * (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name id_line)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))) )))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name uriage)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name id_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))))))))))) ; if uriage >= 1000000 then ( key := 1 ) else skip) ; for i : id_list do ( if key = 0 then ( execute ("NA")->display() ; break ) else skip ; if i[1+1] >= 1000000 then ( execute (i->first())->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=list(map(int,input().split())) import math flag=0 count=0 while flag==0 : for n in range(N): A[n]=A[n]/2 if math.modf(A[n])[0]!=0 : flag=1 break if flag==0 : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; var flag : int := 0 ; var count : int := 0 ; while flag = 0 do ( for n : Integer.subrange(0, N-1) do ( A[n+1] := A[n+1] / 2 ; if math.modf(A[n+1])->first() /= 0 then ( flag := 1 ; break ) else skip) ; if flag = 0 then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def li(): return list(map(int,input().split())) def mi(): return map(int,input().split()) def ii(): return int(input()) N=ii() A=li() cnt=0 while all(e % 2==0 for e in A): cnt+=1 A=list(map(lambda x : x//2,A)) print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var N : OclAny := ii() ; var A : OclAny := li() ; var cnt : int := 0 ; while ((argument (test (logical_test (comparison (comparison (expr (expr (atom (name e))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name e)))) in (logical_test (comparison (expr (atom (name A))))))))->forAll( _x | _x = true ) do ( cnt := cnt + 1 ; A := ((A)->collect( _x | (lambda x : OclAny in (x div 2))->apply(_x) ))) ; execute (cnt)->display(); operation li() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation mi() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation ii() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import collections import itertools import array import inspect sys.setrecursionlimit(10000) def chkprint(*args): names={id(v): k for k,v in inspect.currentframe().f_back.f_locals.items()} print(','.join(names.get(id(arg),'???')+'='+repr(arg)for arg in args)) def to_bin(x): return bin(x)[2 :] def li_input(): return[int(_)for _ in input().split()] dp=None def main(): N=int(input()) A=li_input() ans=0 while True : A_=[] is_end=False for a in A : if a % 2!=0 : is_end=True break else : A_.append(a//2) if is_end : break else : ans+=1 A=A_[:] print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(10000) ; skip ; skip ; skip ; var dp : OclAny := null ; skip ; main(); operation chkprint(args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) var names : Map := inspect.currentframe().f_back.f_locals->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->select(_tuple | true)->collect(_tuple | Map{?(v) |-> k})->unionAll() ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (expr (expr (atom (name names)) (trailer . (name get) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name id)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arg)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom '???'))))))) )))) + (expr (atom '='))) + (expr (atom (name repr)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arg)))))))) )))))))) (comp_for for (exprlist (expr (atom (name arg)))) in (logical_test (comparison (expr (atom (name args)))))))), ','))->display(); operation to_bin(x : OclAny) : OclAny pre: true post: true activity: return bin(x).subrange(2+1); operation li_input() : OclAny pre: true post: true activity: return input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())); operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : OclAny := li_input() ; var ans : int := 0 ; while true do ( var A_ : Sequence := Sequence{} ; var is_end : boolean := false ; for a : A do ( if a mod 2 /= 0 then ( is_end := true ; break ) else ( execute ((a div 2) : A_) )) ; if is_end then ( break ) else ( ans := ans + 1 ; A := A_ )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def kisu(s,num): for n in range(len(s)): if s[n]% 2==1 : return s,num,1 s[n]=s[n]/2 return s,num+1,0 n=int(input()) check=0 num=0 a=list(map(int,input().split())) while check==0 : a,num,check=kisu(a,num) print(num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var check : int := 0 ; num := 0 ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; while check = 0 do ( Sequence{a,num,check} := kisu(a, num)) ; execute (num)->display(); operation kisu(s : OclAny, num : OclAny) : OclAny pre: true post: true activity: for n : Integer.subrange(0, (s)->size()-1) do ( if s[n+1] mod 2 = 1 then ( return s, num, 1 ) else skip ; s[n+1] := s[n+1] / 2) ; return s, num + 1, 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda : sys.stdin.readline().rstrip() YesNo=lambda b : bool([print('Yes')]if b else print('No')) YESNO=lambda b : bool([print('YES')]if b else print('NO')) int1=lambda x : int(x)-1 def main(): N=int(input()) A=list(map(int,input().split())) ans=INF for x in A : tmp=0 while True : if x % 2==0 : tmp+=1 x//=2 else : break ans=min(ans,tmp) print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var YesNo : Function := lambda b : OclAny in ((if b then Sequence{ ('Yes')->display() } else ('No')->display() endif)->toBoolean()) ; var YESNO : Function := lambda b : OclAny in ((if b then Sequence{ ('YES')->display() } else ('NO')->display() endif)->toBoolean()) ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : OclAny := INF ; for x : A do ( var tmp : int := 0 ; while true do ( if x mod 2 = 0 then ( tmp := tmp + 1 ; x := x div 2 ) else ( break )) ; ans := Set{ans, tmp}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def FindPoints(x1,y1,x2,y2,x3,y3,x4,y4): x5=max(x1,x3) y5=max(y1,y3) x6=min(x2,x4) y6=min(y2,y4) if(x5>x6 or y5>y6): print("No intersection") return print("(",x5,",",y5,")",end=" ") print("(",x6,",",y6,")",end=" ") x7=x5 y7=y6 print("(",x7,",",y7,")",end=" ") x8=x6 y8=y5 print("(",x8,",",y8,")") if __name__=="__main__" : x1=0 y1=0 x2=10 y2=8 x3=2 y3=3 x4=7 y4=9 FindPoints(x1,y1,x2,y2,x3,y3,x4,y4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( x1 := 0 ; y1 := 0 ; x2 := 10 ; y2 := 8 ; x3 := 2 ; y3 := 3 ; x4 := 7 ; y4 := 9 ; FindPoints(x1, y1, x2, y2, x3, y3, x4, y4) ) else skip; operation FindPoints(x1 : OclAny, y1 : OclAny, x2 : OclAny, y2 : OclAny, x3 : OclAny, y3 : OclAny, x4 : OclAny, y4 : OclAny) pre: true post: true activity: var x5 : OclAny := Set{x1, x3}->max() ; var y5 : OclAny := Set{y1, y3}->max() ; var x6 : OclAny := Set{x2, x4}->min() ; var y6 : OclAny := Set{y2, y4}->min() ; if ((x5->compareTo(x6)) > 0 or (y5->compareTo(y6)) > 0) then ( execute ("No intersection")->display() ; return ) else skip ; execute ("(")->display() ; execute ("(")->display() ; var x7 : OclAny := x5 ; var y7 : OclAny := y6 ; execute ("(")->display() ; var x8 : OclAny := x6 ; var y8 : OclAny := y5 ; execute ("(")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getStrings(strr,arr): for i in range(len(arr)): if(check(arr[i],strr)): print(arr[i],end=" ") def check(s,strr): chars=s for c in chars : if c not in strr : return False for i in range(len(chars)-1): if(chars[i]==chars[i+1]): return False return True strr="ABCD" arr=["AABCDA","ABCDZADC","ABCDBCA","ABCDABDCA"] getStrings(strr,arr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; strr := "ABCD" ; arr := Sequence{"AABCDA"}->union(Sequence{"ABCDZADC"}->union(Sequence{"ABCDBCA"}->union(Sequence{ "ABCDABDCA" }))) ; getStrings(strr, arr); operation getStrings(strr : OclAny, arr : OclAny) pre: true post: true activity: for i : Integer.subrange(0, (arr)->size()-1) do ( if (check(arr[i+1], strr)) then ( execute (arr[i+1])->display() ) else skip); operation check(s : OclAny, strr : OclAny) : OclAny pre: true post: true activity: var chars : OclAny := s ; for c : chars do ( if (strr)->excludes(c) then ( return false ) else skip) ; for i : Integer.subrange(0, (chars)->size() - 1-1) do ( if (chars[i+1] = chars[i + 1+1]) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate def data_req(): n_yado,m_ryotei=[int(i)for i in input().split(" ")] yado_distance=[] ryotei=[] for _ in range(n_yado-1): yado_distance.append(int(input())) for _ in range(m_ryotei): ryotei.append(int(input())) return yado_distance,ryotei def search(distance,ryotei): acc=[0]+list(accumulate(distance,lambda x,y : x+y)) ryotei_index=[0]+list(accumulate(ryotei,lambda x,y : x+y)) res=[] for index in enumerate(ryotei_index): if index[0]==0 : continue index=index[0] dist=abs(acc[ryotei_index[index]]-acc[ryotei_index[index-1]]) res.append(dist) return sum(res) if __name__=='__main__' : dis,ryotei=data_req() print(search(dis,ryotei)% 100000) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( var dis : OclAny := null; Sequence{dis,ryotei} := data_req() ; execute (search(dis, ryotei) mod 100000)->display() ) else skip; operation data_req() : OclAny pre: true post: true activity: var n_yado : OclAny := null; var m_ryotei : OclAny := null; Sequence{n_yado,m_ryotei} := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var yado_distance : Sequence := Sequence{} ; var ryotei : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n_yado - 1-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : yado_distance)) ; for _anon : Integer.subrange(0, m_ryotei-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : ryotei)) ; return yado_distance, ryotei; operation search(distance : OclAny, ryotei : OclAny) : OclAny pre: true post: true activity: var acc : Sequence := Sequence{ 0 }->union((accumulate(distance, lambda x : OclAny, y : OclAny in (x + y)))) ; var ryotei_index : Sequence := Sequence{ 0 }->union((accumulate(ryotei, lambda x : OclAny, y : OclAny in (x + y)))) ; var res : Sequence := Sequence{} ; for index : Integer.subrange(1, (ryotei_index)->size())->collect( _indx | Sequence{_indx-1, (ryotei_index)->at(_indx)} ) do ( if index->first() = 0 then ( continue ) else skip ; var index : OclAny := index->first() ; var dist : double := (acc[ryotei_index[index+1]+1] - acc[ryotei_index[index - 1+1]+1])->abs() ; execute ((dist) : res)) ; return (res)->sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=map(int,input().split()) if n>a*b : print("-1") else : ans=[[0 for i in range(b)]for j in range(a)] k=1 for i in range(a): if i % 2==0 : for j in range(b): if k<=n : ans[i][j]=k k+=1 else : for j in range(b-1,-1,-1): if k<=n : ans[i][j]=k k+=1 for i in ans : print(*i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (n->compareTo(a * b)) > 0 then ( execute ("-1")->display() ) else ( var ans : Sequence := Integer.subrange(0, a-1)->select(j | true)->collect(j | (Integer.subrange(0, b-1)->select(i | true)->collect(i | (0)))) ; var k : int := 1 ; for i : Integer.subrange(0, a-1) do ( if i mod 2 = 0 then ( for j : Integer.subrange(0, b-1) do ( if (k->compareTo(n)) <= 0 then ( ans[i+1][j+1] := k ; k := k + 1 ) else skip) ) else ( for j : Integer.subrange(-1 + 1, b - 1)->reverse() do ( if (k->compareTo(n)) <= 0 then ( ans[i+1][j+1] := k ; k := k + 1 ) else skip) )) ; for i : ans do ( execute ((argument * (test (logical_test (comparison (expr (atom (name i))))))))->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=map(int,input().split()) if a*bcollect( _x | (OclType["int"])->apply(_x) ) ; if (a * b->compareTo(n)) < 0 then ( execute (-1)->display() ) else ( for i : Integer.subrange(0, a-1) do ( var s : String := "" ; for j : Integer.subrange(0, b-1) do ( if i mod 2 = 0 then ( s := s + ("" + ((n))) + " " ) else ( s := ("" + ((n))) + " " + s ) ; var n : OclAny := Set{0, n - 1}->max()) ; execute (s)->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import exit n,a,b=map(int,input().split()) odd1=(a*b)% 2==1 odd2=n % 2==1 if odd1==odd2 : if n>a*b : print(-1) exit() else : if n+1>a*b : print(-1) exit() numb=[1,2] for i in range(a): for j in range(b): party=(i % 2+j % 2+odd1+1)% 2 c=numb[party] if c>n : c=0 numb[party]+=2 print(c,end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var odd1 : boolean := (a * b) mod 2 = 1 ; var odd2 : boolean := n mod 2 = 1 ; if odd1 = odd2 then ( if (n->compareTo(a * b)) > 0 then ( execute (-1)->display() ; exit() ) else skip ) else ( if (n + 1->compareTo(a * b)) > 0 then ( execute (-1)->display() ; exit() ) else skip ) ; var numb : Sequence := Sequence{1}->union(Sequence{ 2 }) ; for i : Integer.subrange(0, a-1) do ( for j : Integer.subrange(0, b-1) do ( var party : int := (i mod 2 + j mod 2 + odd1 + 1) mod 2 ; var c : OclAny := numb[party+1] ; if (c->compareTo(n)) > 0 then ( c := 0 ) else skip ; numb[party+1] := numb[party+1] + 2 ; execute (c)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,a,b=map(int,input().split()) if n>a*b : print(-1) else : for i in range(a): if i % 2==0 : w=list(range(i*b+1,i*b+b+1)) for _ in range(b): if w[_]>n : w[_]=0 print(' '.join(map(str,w))) else : w=list(range(i*b+1,i*b+b+1))[: :-1] for _ in range(b): if w[_]>n : w[_]=0 print(' '.join(map(str,w))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (n->compareTo(a * b)) > 0 then ( execute (-1)->display() ) else ( for i : Integer.subrange(0, a-1) do ( if i mod 2 = 0 then ( var w : Sequence := (Integer.subrange(i * b + 1, i * b + b + 1-1)) ; for _anon : Integer.subrange(0, b-1) do ( if (w[_anon+1]->compareTo(n)) > 0 then ( w[_anon+1] := 0 ) else skip) ; execute (StringLib.sumStringsWithSeparator(((w)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ) else ( w := OclType["Sequence"](Integer.subrange(i * b + 1, i * b + b + 1-1))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; for _anon : Integer.subrange(0, b-1) do ( if (w[_anon+1]->compareTo(n)) > 0 then ( w[_anon+1] := 0 ) else skip) ; execute (StringLib.sumStringsWithSeparator(((w)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,r,c=[int(i)for i in input().split()] if n>r*c : print(-1) import sys sys.exit(0) p=[[0 for i in range(c)]for j in range(r)] if c % 2 : num=1 x=0 y=0 while num<=n : p[x][y]=num num+=1 y+=1 if y==c : y=0 x+=1 elif r % 2 : num=1 x=0 y=0 while num<=n : p[x][y]=num num+=1 x+=1 if x==r : x=0 y+=1 else : num=1 x=0 y=0 while num<=n : p[x][y]=num num+=1 y+=1 if y==c-1 : y=0 x+=1 if x==r : break if num % 2==0 : for i in range(r): if num>n : break p[i][c-1]=num num+=1 else : for i in range(r-1,-1,-1): if num>n : break p[i][c-1]=num num+=1 for row in p : print(*row) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var r : OclAny := null; var c : OclAny := null; Sequence{n,r,c} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if (n->compareTo(r * c)) > 0 then ( execute (-1)->display() ; skip ; sys.exit(0) ) else skip ; var p : Sequence := Integer.subrange(0, r-1)->select(j | true)->collect(j | (Integer.subrange(0, c-1)->select(i | true)->collect(i | (0)))) ; if c mod 2 then ( var num : int := 1 ; var x : int := 0 ; var y : int := 0 ; while (num->compareTo(n)) <= 0 do ( p[x+1][y+1] := num ; num := num + 1 ; y := y + 1 ; if y = c then ( y := 0 ; x := x + 1 ) else skip) ) else (if r mod 2 then ( num := 1 ; x := 0 ; y := 0 ; while (num->compareTo(n)) <= 0 do ( p[x+1][y+1] := num ; num := num + 1 ; x := x + 1 ; if x = r then ( x := 0 ; y := y + 1 ) else skip) ) else ( num := 1 ; x := 0 ; y := 0 ; while (num->compareTo(n)) <= 0 do ( p[x+1][y+1] := num ; num := num + 1 ; y := y + 1 ; if y = c - 1 then ( y := 0 ; x := x + 1 ) else skip ; if x = r then ( break ) else skip) ; if num mod 2 = 0 then ( for i : Integer.subrange(0, r-1) do ( if (num->compareTo(n)) > 0 then ( break ) else skip ; p[i+1][c - 1+1] := num ; num := num + 1) ) else ( for i : Integer.subrange(-1 + 1, r - 1)->reverse() do ( if (num->compareTo(n)) > 0 then ( break ) else skip ; p[i+1][c - 1+1] := num ; num := num + 1) ) ) ) ; for row : p do ( execute ((argument * (test (logical_test (comparison (expr (atom (name row))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from heapq import heappush,heappop from bisect import bisect_left,bisect_right import sys,random,itertools,math sys.setrecursionlimit(10**5) input=sys.stdin.readline sqrt=math.sqrt def LI(): return list(map(int,input().split())) def LF(): return list(map(float,input().split())) def LI_(): return list(map(lambda x : int(x)-1,input().split())) def II(): return int(input()) def IF(): return float(input()) def LS(): return list(map(list,input().split())) def S(): return list(input().rstrip()) def IR(n): return[II()for _ in range(n)] def LIR(n): return[LI()for _ in range(n)] def FR(n): return[IF()for _ in range(n)] def LFR(n): return[LI()for _ in range(n)] def LIR_(n): return[LI_()for _ in range(n)] def SR(n): return[S()for _ in range(n)] def LSR(n): return[LS()for _ in range(n)] mod=1000000007 inf=float('INF') def solve(): n=II() s=input().rstrip() print(s.count("ABC")) return if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(5)) ; var input : OclAny := (OclFile["System.in"]).readline ; var sqrt : OclAny := ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : int := 1000000007 ; var Math_PINFINITY : double := ("" + (('INF')))->toReal() ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LF() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["double"])->apply(_x) )); operation LI_() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) )); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation IF() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation LS() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["Sequence"])->apply(_x) )); operation S() : OclAny pre: true post: true activity: return (input().rstrip()); operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (II())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI())); operation FR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (IF())); operation LFR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI())); operation LIR_(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI_())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LS())); operation solve() pre: true post: true activity: n := II() ; var s : OclAny := input().rstrip() ; execute (s->count("ABC"))->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() print(s.count('ABC')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; execute (s->count('ABC'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) S=input() x=0 y=0 for i in range(N): if S[i]=='A' : x=1 elif S[i]=="B" and x==1 : x=2 elif S[i]=="C" and x==2 : y+=1 x=0 else : x=0 print(y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : String := (OclFile["System.in"]).readLine() ; var x : int := 0 ; var y : int := 0 ; for i : Integer.subrange(0, N-1) do ( if S[i+1] = 'A' then ( x := 1 ) else (if S[i+1] = "B" & x = 1 then ( x := 2 ) else (if S[i+1] = "C" & x = 2 then ( y := y + 1 ; x := 0 ) else ( x := 0 ) ) ) ) ; execute (y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n_hamsters : int=int(input()) hamsters=input() hamsters_standing=len([ham for ham in hamsters if ham=="X"]) hamsters_sitting=n_hamsters-hamsters_standing if hamsters_standing==hamsters_sitting : print(0) print(hamsters) elif hamsters_standing>hamsters_sitting : num_change=(hamsters_standing-hamsters_sitting)//2 print(num_change) result="" for hamster in hamsters : if hamster=="X" and num_change>0 : result+="x" num_change-=1 else : result+=hamster print(result) else : num_change=(hamsters_sitting-hamsters_standing)//2 print(num_change) result="" for hamster in hamsters : if hamster=="x" and num_change>0 : result+="X" num_change-=1 else : result+=hamster print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n_hamsters : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var hamsters : String := (OclFile["System.in"]).readLine() ; var hamsters_standing : int := (hamsters->characters()->select(ham | ham = "X")->collect(ham | (ham)))->size() ; var hamsters_sitting : double := n_hamsters - hamsters_standing ; if hamsters_standing = hamsters_sitting then ( execute (0)->display() ; execute (hamsters)->display() ) else (if (hamsters_standing->compareTo(hamsters_sitting)) > 0 then ( var num_change : int := (hamsters_standing - hamsters_sitting) div 2 ; execute (num_change)->display() ; var result : String := "" ; for hamster : hamsters->characters() do ( if hamster = "X" & num_change > 0 then ( result := result + "x" ; num_change := num_change - 1 ) else ( result := result + hamster )) ; execute (result)->display() ) else ( num_change := (hamsters_sitting - hamsters_standing) div 2 ; execute (num_change)->display() ; result := "" ; for hamster : hamsters->characters() do ( if hamster = "x" & num_change > 0 then ( result := result + "X" ; num_change := num_change - 1 ) else ( result := result + hamster )) ; execute (result)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines N=int(readline()) S=readline().decode('utf8') print(S.count('ABC')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; var N : int := ("" + ((readline())))->toInteger() ; var S : OclAny := readline().decode('utf8') ; execute (S->count('ABC'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=str(input()) cnt=0 for i in range(n-2): if s[i]=="A" and s[i+1]=="B" and s[i+2]=="C" : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; var cnt : int := 0 ; for i : Integer.subrange(0, n - 2-1) do ( if s[i+1] = "A" & s[i + 1+1] = "B" & s[i + 2+1] = "C" then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin from itertools import accumulate input=stdin.readline import array def main(args): n,m=map(int,input().split()) distances=[int(input())for _ in range(n-1)] inns=list(accumulate(distances)) moves=[int(input())for _ in range(m)] inns.insert(0,0) pos=0 total_distance=0 for m in moves : new_pos=pos+m total_distance+=abs(inns[new_pos]-inns[pos]) pos=new_pos print(total_distance % 100000) def main2(args): n,m=map(int,input().split()) pos=0 inns=array.array('Q',[0]) for _ in range(n-1): pos+=int(input()) inns.append(pos) moves=[int(input())for _ in range(m)] pos=0 total_distance=0 for m in moves : new_pos=pos+m total_distance+=abs(inns[new_pos]-inns[pos]) pos=new_pos print(total_distance % 100000) def main3(args): n,m=map(int,input().split()) pos=0 inns={0 : 0} for i in range(n-1): pos+=int(input()) inns[i+1]=pos moves=[int(input())for _ in range(m)] pos=0 total_distance=0 for m in moves : new_pos=pos+m total_distance+=abs(inns[new_pos]-inns[pos]) pos=new_pos print(total_distance % 100000) if __name__=='__main__' : main3(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main3((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation main(args : OclAny) pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var distances : Sequence := Integer.subrange(0, n - 1-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var inns : Sequence := (accumulate(distances)) ; var moves : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; inns := inns.insertAt(0+1, 0) ; var pos : int := 0 ; var total_distance : int := 0 ; for m : moves do ( var new_pos : int := pos + m ; total_distance := total_distance + (inns[new_pos+1] - inns[pos+1])->abs() ; pos := new_pos) ; execute (total_distance mod 100000)->display(); operation main2(args : OclAny) pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; pos := 0 ; inns := array.array('Q', Sequence{ 0 }) ; for _anon : Integer.subrange(0, n - 1-1) do ( pos := pos + ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((pos) : inns)) ; moves := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; pos := 0 ; total_distance := 0 ; for m : moves do ( new_pos := pos + m ; total_distance := total_distance + (inns[new_pos+1] - inns[pos+1])->abs() ; pos := new_pos) ; execute (total_distance mod 100000)->display(); operation main3(args : OclAny) pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; pos := 0 ; inns := Map{ 0 |-> 0 } ; for i : Integer.subrange(0, n - 1-1) do ( pos := pos + ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; inns[i + 1+1] := pos) ; moves := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; pos := 0 ; total_distance := 0 ; for m : moves do ( new_pos := pos + m ; total_distance := total_distance + (inns[new_pos+1] - inns[pos+1])->abs() ; pos := new_pos) ; execute (total_distance mod 100000)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=1000000007 ; def countSubsets(a,n): answer=0 ; for i in range(1<union(Sequence{3}->union(Sequence{2}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 1 }))))); ; execute (countSubsets(A, N))->display(); ) else skip; operation countSubsets(a : OclAny, n : OclAny) pre: true post: true activity: var answer : int := 0; ; for i : Integer.subrange(0, 1 * (2->pow(n))-1) do ( var bitwiseAND : int := -1; ; var bitwiseOR : int := 0; ; var bitwiseXOR : int := 0; ; for j : Integer.subrange(0, n-1) do ( if (MathLib.bitwiseAnd(i, (1 * (2->pow(j))))) then ( if (bitwiseAND = -1) then ( bitwiseAND := a[j+1]; ) else ( bitwiseAND := bitwiseAND & a[j+1]; ) ; bitwiseOR := bitwiseOR or a[j+1]; ; bitwiseXOR := bitwiseXOR xor a[j+1]; ) else skip) ; if (bitwiseAND = bitwiseOR & bitwiseOR = bitwiseXOR) then ( answer := (answer + 1) mod mod; ) else skip) ; return answer;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def segregate0and1(arr,size): left,right=0,size-1 while leftunion(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))))) ; var arr_size : int := (arr)->size() ; execute ("Array after segregation")->display() ; execute (segregate0and1(arr, arr_size))->display(); operation segregate0and1(arr : OclAny, size : OclAny) : OclAny pre: true post: true activity: var left : OclAny := null; var right : OclAny := null; Sequence{left,right} := Sequence{0,size - 1} ; while (left->compareTo(right)) < 0 do ( while arr[left+1] = 0 & (left->compareTo(right)) < 0 do ( left := left + 1) ; while arr[right+1] = 1 & (left->compareTo(right)) < 0 do ( right := right - 1) ; if (left->compareTo(right)) < 0 then ( arr[left+1] := 0 ; arr[right+1] := 1 ; left := left + 1 ; right := right - 1 ) else skip) ; return arr; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def main(): N=int(input()) A=list(map(int,input().split())) tmp_o=[0 for i in range(N+1)] tmp_e=[0 for i in range(N+1)] count_o=0 count_e=0 for i in range(N): tmp_o[i+1]=tmp_o[i]+A[i] if i % 2==1 and tmp_o[i+1]<=0 : count_o+=1-tmp_o[i+1] tmp_o[i+1]=1 elif i % 2==0 and tmp_o[i+1]>=0 : count_o+=tmp_o[i+1]+1 tmp_o[i+1]=-1 else : continue for i in range(N): tmp_e[i+1]=tmp_e[i]+A[i] if i % 2==0 and tmp_e[i+1]<=0 : count_e+=1-tmp_e[i+1] tmp_e[i+1]=1 elif i % 2==1 and tmp_e[i+1]>=0 : count_e+=tmp_e[i+1]+1 tmp_e[i+1]=-1 else : continue print(min(count_o,count_e)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var tmp_o : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (0)) ; var tmp_e : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (0)) ; var count_o : int := 0 ; var count_e : int := 0 ; for i : Integer.subrange(0, N-1) do ( tmp_o[i + 1+1] := tmp_o[i+1] + A[i+1] ; if i mod 2 = 1 & tmp_o[i + 1+1] <= 0 then ( count_o := count_o + 1 - tmp_o[i + 1+1] ; tmp_o[i + 1+1] := 1 ) else (if i mod 2 = 0 & tmp_o[i + 1+1] >= 0 then ( count_o := count_o + tmp_o[i + 1+1] + 1 ; tmp_o[i + 1+1] := -1 ) else ( continue ) ) ) ; for i : Integer.subrange(0, N-1) do ( tmp_e[i + 1+1] := tmp_e[i+1] + A[i+1] ; if i mod 2 = 0 & tmp_e[i + 1+1] <= 0 then ( count_e := count_e + 1 - tmp_e[i + 1+1] ; tmp_e[i + 1+1] := 1 ) else (if i mod 2 = 1 & tmp_e[i + 1+1] >= 0 then ( count_e := count_e + tmp_e[i + 1+1] + 1 ; tmp_e[i + 1+1] := -1 ) else ( continue ) ) ) ; execute (Set{count_o, count_e}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) prog=list(map(int,input().split())) def seq(prog,first_Ev=False): sign=-1 if first_Ev else 1 if sign*prog[0]>0 : answer=0 result=prog[0] else : answer=abs(sign-prog[0]) result=sign for i in prog[1 :]: sign*=-1 result+=i if result*sign<=0 : answer+=abs(sign-result) result=sign return answer print(min(seq(prog),seq(prog,first_Ev=True))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var prog : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; execute (Set{seq(prog), seq(prog, (argument (test (logical_test (comparison (expr (atom (name first_Ev)))))) = (test (logical_test (comparison (expr (atom (name True))))))))}->min())->display(); operation seq(prog : OclAny, first_Ev : OclAny) : OclAny pre: true post: true activity: if first_Ev->oclIsUndefined() then first_Ev := false else skip; var sign : int := if first_Ev then -1 else 1 endif ; if sign * prog->first() > 0 then ( var answer : int := 0 ; var result : OclAny := prog->first() ) else ( answer := (sign - prog->first())->abs() ; result := sign ) ; for i : prog->tail() do ( sign := sign * -1 ; result := result + i ; if result * sign <= 0 then ( answer := answer + (sign - result)->abs() ; result := sign ) else skip) ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import os n=int(input()) BASE=list(map(int,input().split())) answers=[] for v in[0,1]: A=BASE[:] sum_value=0 add_num=0 for i,a in enumerate(A): sum_value+=a if i % 2==v : if sum_value<=0 : A[i]=A[i]-sum_value+1 add_num+=(-sum_value+1) sum_value=1 else : if sum_value>=0 : A[i]=A[i]-sum_value-1 add_num+=(sum_value+1) sum_value=-1 answers.append(add_num) print(min(answers)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var BASE : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var answers : Sequence := Sequence{} ; for v : Sequence{0}->union(Sequence{ 1 }) do ( var A : Sequence := BASE ; var sum_value : int := 0 ; var add_num : int := 0 ; for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); sum_value := sum_value + a ; if i mod 2 = v then ( if sum_value <= 0 then ( A[i+1] := A[i+1] - sum_value + 1 ; add_num := add_num + (-sum_value + 1) ; sum_value := 1 ) else skip ) else ( if sum_value >= 0 then ( A[i+1] := A[i+1] - sum_value - 1 ; add_num := add_num + (sum_value + 1) ; sum_value := -1 ) else skip )) ; execute ((add_num) : answers)) ; execute ((answers)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) r=[int(i)for i in input().split()] for i in range(1,n): r[i]+=r[i-1] a=r.copy() ans_a=0 ; change_v=0 for i in range(n): a[i]+=change_v if i % 2==1 : ans_a+=max(0,1-a[i]) change_v+=max(0,1-a[i]) else : ans_a+=max(0,a[i]+1) change_v-=max(0,a[i]+1) a=r.copy() ans_b=0 ; change_v=0 for i in range(n): a[i]+=change_v if i % 2==0 : ans_b+=max(0,1-a[i]) change_v+=max(0,1-a[i]) else : ans_b+=max(0,a[i]+1) change_v-=max(0,a[i]+1) print(min(ans_a,ans_b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; for i : Integer.subrange(1, n-1) do ( r[i+1] := r[i+1] + r[i - 1+1]) ; var a : String := r->copy() ; var ans_a : int := 0; var change_v : int := 0 ; for i : Integer.subrange(0, n-1) do ( a[i+1] := a[i+1] + change_v ; if i mod 2 = 1 then ( ans_a := ans_a + Set{0, 1 - a[i+1]}->max() ; change_v := change_v + Set{0, 1 - a[i+1]}->max() ) else ( ans_a := ans_a + Set{0, a[i+1] + 1}->max() ; change_v := change_v - Set{0, a[i+1] + 1}->max() )) ; a := r->copy() ; var ans_b : int := 0; change_v := 0 ; for i : Integer.subrange(0, n-1) do ( a[i+1] := a[i+1] + change_v ; if i mod 2 = 0 then ( ans_b := ans_b + Set{0, 1 - a[i+1]}->max() ; change_v := change_v + Set{0, 1 - a[i+1]}->max() ) else ( ans_b := ans_b + Set{0, a[i+1] + 1}->max() ; change_v := change_v - Set{0, a[i+1] + 1}->max() )) ; execute (Set{ans_a, ans_b}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def main(): n=int(input()) lst=tuple(map(int,input().split())) cur,cnt_1=0,0 for i,j in enumerate(lst): new=cur+j if i % 2==0 and new<=0 : cnt_1+=abs(new)+1 cur=1 elif i % 2==1 and new>=0 : cnt_1+=abs(new)+1 cur=-1 else : cur+=j cur,cnt_2=0,0 for i,j in enumerate(lst): new=cur+j if i % 2==0 and new>=0 : cnt_2+=abs(new)+1 cur=-1 elif i % 2==1 and new<=0 : cnt_2+=abs(new)+1 cur=1 else : cur+=j print(min(cnt_1,cnt_2)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cur : OclAny := null; var cntcur : OclAny := null; Sequence{cur,cntcur} := Sequence{0,0} ; for _tuple : Integer.subrange(1, (lst)->size())->collect( _indx | Sequence{_indx-1, (lst)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); var new : OclAny := cur + j ; if i mod 2 = 0 & new <= 0 then ( cnt var new : OclAny := cur + j := cnt var new : OclAny := cur + j + (new)->abs() + 1 ; var cur : int := 1 ) else (if i mod 2 = 1 & new >= 0 then ( cnt var new : OclAny := cur + j := cnt var new : OclAny := cur + j + (new)->abs() + 1 ; cur := -1 ) else ( cur := cur + j ) ) ) ; var cnt:= 0,0 : OclAny := null; Sequence{cur,cnt:= 0,0} := Sequence{0,0} ; for _tuple : Integer.subrange(1, (lst)->size())->collect( _indx | Sequence{_indx-1, (lst)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); new := cur + j ; if i mod 2 = 0 & new >= 0 then ( cnt + (new)->abs() + 1 := cnt + (new)->abs() + 1 + (new)->abs() + 1 ; cur := -1 ) else (if i mod 2 = 1 & new <= 0 then ( cnt + (new)->abs() + 1 := cnt + (new)->abs() + 1 + (new)->abs() + 1 ; cur := 1 ) else ( cur := cur + j ) ) ) ; execute (Set{cnt(cnt(cntSet{cnt(cnt(cnt(Set{cnt(cnt(cnt(Set{cnt(cnt(cnt(Set{cnt(cnt(cntSet{cnt(cnt(cnt(Set{cnt(cnt(cnt(Set{cnt(cnt(cnt(Set{cnt(cnt(cntSet{cnt(cnt(cnt(Set{cnt(cnt(cnt(Set{cnt(cnt(cnt(Set{cnt(cnt(cntSet{cnt(cnt(cnt(Set{cnt(cnt(cnt(Set{cnt(cnt(cnt(Set{cnt(cnt(cntSet{cnt(cnt(cnt(Set{cnt(cnt(cnt(Set{cnt(cnt(cnt(Set{cnt(cnt(cntSet{cnt(cnt(cnt(Set{cnt(cnt(cnt(Set{cnt(cnt(cnt(Set{cnt(cnt(cntSet{cnt(cnt(cnt(Set{cnt(cnt(cnt(Set{cnt(cnt(cnt var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(), cnt_2), cnt_2), cnt_2}->min()), cnt_2), cnt_2), cnt_2}->min()), cnt_2), cnt_2), cnt_2}->min(), cnt_2), cnt_2), cnt_2}->min())->display(), cnt_2), cnt_2), cnt_2}->min()), cnt_2), cnt_2), cnt_2}->min()), cnt_2), cnt_2), cnt_2}->min(), cnt_2), cnt_2), cnt_2}->min())->display(), cnt_2), cnt_2), cnt_2}->min()), cnt_2), cnt_2), cnt_2}->min()), cnt_2), cnt_2), cnt_2}->min(), cnt_2), cnt_2), cnt_2}->min())->display(), cnt_2), cnt_2), cnt_2}->min()), cnt_2), cnt_2), cnt_2}->min()), cnt_2), cnt_2), cnt_2}->min(), cnt_2), cnt_2), cnt_2}->min())->display(), cnt_2), cnt_2), cnt_2}->min()), cnt_2), cnt_2), cnt_2}->min()), cnt_2), cnt_2), cnt_2}->min(), cnt_2), cnt_2), cnt_2}->min())->display(), cnt_2), cnt_2), cnt_2}->min()), cnt_2), cnt_2), cnt_2}->min()), cnt_2), cnt_2), cnt_2}->min(), cnt_2), cnt_2), cnt_2}->min())->display(), cnt_2), cnt_2), cnt_2}->min()), cnt_2), cnt_2), cnt_2}->min()), cnt_2), cnt_2), cnt_2}->min(), cnt_2), cnt_2), cnt_2}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(input()) u=l.count("X") d=l.count('x') if u==d : print(0) print(''.join(l)) else : if utoInteger() ; var l : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var u : int := l->count("X") ; var d : int := l->count('x') ; if u = d then ( execute (0)->display() ; execute (StringLib.sumStringsWithSeparator((l), ''))->display() ) else ( if (u->compareTo(d)) < 0 then ( execute (n div 2 - u)->display() ; var i : int := 0 ; while ((u->compareTo(n div 2)) < 0 & (i->compareTo(n)) < 0) do ( if l[i+1] = "x" then ( l[i+1] := 'X' ; i := i + 1 ; u := u + 1 ) else ( i := i + 1 )) ; execute (StringLib.sumStringsWithSeparator((l), ''))->display() ) else ( execute (n div 2 - d)->display() ; i := 0 ; while ((d->compareTo(n div 2)) < 0 & (i->compareTo(n)) < 0) do ( if l[i+1] = "X" then ( l[i+1] := 'x' ; i := i + 1 ; d := d + 1 ) else ( i := i + 1 )) ; execute (StringLib.sumStringsWithSeparator((l), ''))->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import fractions def lcm(a,b): return(a*b)//fractions.gcd(a,b) N=int(input()) print(lcm(2,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (lcm(2, N))->display(); operation lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a * b) div fractions.gcd(a, b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(): mod=1000000007 inf=float('inf') sys.setrecursionlimit(10**6) def input(): return sys.stdin.readline().rstrip() def ii(): return int(input()) def mi(): return map(int,input().split()) def mi_0(): return map(lambda x : int(x)-1,input().split()) def lmi(): return list(map(int,input().split())) def lmi_0(): return list(map(lambda x : int(x)-1,input().split())) def li(): return list(input()) n=ii() print(2*n)if n % 2==1 else print(n) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var mod : int := 1000000007 ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; sys.setrecursionlimit((10)->pow(6)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := ii() ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name n))))))))) )))))) if (logical_test (comparison (comparison (expr (expr (atom (name n))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 1))))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) if(x % 2==0): print(x) else : mdc=x*2 print(mdc) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (x mod 2 = 0) then ( execute (x)->display() ) else ( var mdc : int := x * 2 ; execute (mdc)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(p,q): if pcollect( _x | (OclType["int"])->apply(_x) ) ; execute (x + y + 1 - gcd(x, y))->display(); operation gcd(p : OclAny, q : OclAny) : OclAny pre: true post: true activity: if (p->compareTo(q)) < 0 then ( return gcd(q, p) ) else skip ; if p mod q = 0 then ( return q ) else ( return gcd(q, p mod q) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline M,BigM=100000,1000000000 n,m=map(int,input().split()) s=[0]*(n+1) for i in range(2,n+1): s[i]=s[i-1]+int(input()) ans,p1=0,1 for i in range(m): p2=p1+int(input()) x=s[p2]-s[p1] if x>=0 : ans+=x else : ans-=x if ans>=BigM : ans %=M p1=p2 ; print(ans % M) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; var M : OclAny := null; var BigM : OclAny := null; Sequence{M,BigM} := Sequence{100000,1000000000} ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(2, n + 1-1) do ( s[i+1] := s[i - 1+1] + ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var ans : OclAny := null; var p1 : OclAny := null; Sequence{ans,p1} := Sequence{0,1} ; for i : Integer.subrange(0, m-1) do ( var p2 : OclAny := p1 + ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : double := s[p2+1] - s[p1+1] ; if x >= 0 then ( ans := ans + x ) else ( ans := ans - x ) ; if (ans->compareTo(BigM)) >= 0 then ( ans := ans mod M ) else skip ; var p1 : OclAny := p2;) ; execute (ans mod M)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(n*(n % 2+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n * (n mod 2 + 1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) c=1 while True : if(n*c)% 2==0 : print(n*c) break c+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := 1 ; while true do ( if (n * c) mod 2 = 0 then ( execute (n * c)->display() ; break ) else skip ; c := c + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def compute(): ans=sum(i for i in range(3,10000000)if i==factorial_digit_sum(i)) return str(ans) def factorial_digit_sum(n): result=0 while n>=10000 : result+=FACTORIAL_DIGITS_SUM_WITH_LEADING_ZEROS[n % 10000] n//=10000 return result+FACTORIAL_DIGITS_SUM_WITHOUT_LEADING_ZEROS[n] FACTORIAL_DIGITS_SUM_WITHOUT_LEADING_ZEROS=[sum(math.factorial(int(c))for c in str(i))for i in range(10000)] FACTORIAL_DIGITS_SUM_WITH_LEADING_ZEROS=[sum(math.factorial(int(c))for c in str(i).zfill(4))for i in range(10000)] if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var FACTORIAL_DIGITS_SUM_WITHOUT_LEADING_ZEROS : Sequence := Integer.subrange(0, 10000-1)->select(i | true)->collect(i | (((argument (test (logical_test (comparison (expr (atom (name math)) (trailer . (name factorial) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))->sum())) ; var FACTORIAL_DIGITS_SUM_WITH_LEADING_ZEROS : Sequence := Integer.subrange(0, 10000-1)->select(i | true)->collect(i | (((argument (test (logical_test (comparison (expr (atom (name math)) (trailer . (name factorial) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))) (trailer . (name zfill) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 4))))))))) )))))))))->sum())) ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 3)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 10000000))))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name i)))) == (comparison (expr (atom (name factorial_digit_sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))))))->sum() ; return ("" + ((ans))); operation factorial_digit_sum(n : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; while n >= 10000 do ( result := result + FACTORIAL_DIGITS_SUM_WITH_LEADING_ZEROS[n mod 10000+1] ; n := n div 10000) ; return result + FACTORIAL_DIGITS_SUM_WITHOUT_LEADING_ZEROS[n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,collections input=lambda : sys.stdin.readline().rstrip("\n") n,x=map(int,input().split()) a=[int(x)for x in input().split()] m=collections.Counter() res=0 for i in a : res+=m[i ^ x] m[i]+=1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip("\n")) ; var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := input->apply().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var m : OclAny := .Counter() ; var res : int := 0 ; for i : a do ( res := res + m[MathLib.bitwiseXor(i, x)+1] ; m[i+1] := m[i+1] + 1) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=map(int,input().split()) arr=[int(z)for z in input().split()] binarr=[] lenbin=len(bin(x))-2 for i in arr : lenbin=max(lenbin,len(bin(i))-2) xbin=bin(x)[2 :].zfill(lenbin) for i in arr : bin_num=bin(i)[2 :] bn1=bin_num.zfill(lenbin) binarr.append(bn1) res=0 occ={} for i in binarr : occ[i]=occ.get(i,0)+1 takencareof=set() for elem in binarr : if elem in takencareof : continue ref='' for i in range(lenbin): if xbin[i]=='0' : if elem[i]=='1' : ref+='1' else : ref+='0' else : if elem[i]=='1' : ref+='0' else : ref+='1' if elem==ref : res+=occ[elem]*(occ[elem]-1) takencareof.add(elem) else : res+=occ.get(ref,0) print(res//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := input().split()->select(z | true)->collect(z | (("" + ((z)))->toInteger())) ; var binarr : Sequence := Sequence{} ; var lenbin : double := (bin(x))->size() - 2 ; for i : arr do ( lenbin := Set{lenbin, (bin(i))->size() - 2}->max()) ; var xbin : OclAny := bin(x).subrange(2+1).zfill(lenbin) ; for i : arr do ( var bin_num : OclAny := bin(i).subrange(2+1) ; var bn1 : OclAny := bin_num.zfill(lenbin) ; execute ((bn1) : binarr)) ; var res : int := 0 ; var occ : OclAny := Set{} ; for i : binarr do ( occ[i+1] := occ.get(i, 0) + 1) ; var takencareof : Set := Set{}->union(()) ; for elem : binarr do ( if (takencareof)->includes(elem) then ( continue ) else skip ; var ref : String := '' ; for i : Integer.subrange(0, lenbin-1) do ( if xbin[i+1] = '0' then ( if elem[i+1] = '1' then ( ref := ref + '1' ) else ( ref := ref + '0' ) ) else ( if elem[i+1] = '1' then ( ref := ref + '0' ) else ( ref := ref + '1' ) )) ; if elem = ref then ( res := res + occ[elem+1] * (occ[elem+1] - 1) ; execute ((elem) : takencareof) ) else ( res := res + occ.get(ref, 0) )) ; execute (res div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ln=int(input()) lis=[] inp=input() for i in inp : lis.append(i) s=inp.count('x') l=inp.count('X') print(abs(l-s)//2) if s==l : print(inp) else : if s>l : for i in range(abs(s-l)//2): m=lis.index('x') lis[m]='X' else : for i in range(abs(s-l)//2): m=lis.index('X') lis[m]='x' for i in lis : print(i,end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ln : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lis : Sequence := Sequence{} ; var inp : String := (OclFile["System.in"]).readLine() ; for i : inp->characters() do ( execute ((i) : lis)) ; var s : int := inp->count('x') ; var l : int := inp->count('X') ; execute ((l - s)->abs() div 2)->display() ; if s = l then ( execute (inp)->display() ) else ( if (s->compareTo(l)) > 0 then ( for i : Integer.subrange(0, (s - l)->abs() div 2-1) do ( var m : int := lis->indexOf('x') - 1 ; lis[m+1] := 'X') ) else ( for i : Integer.subrange(0, (s - l)->abs() div 2-1) do ( m := lis->indexOf('X') - 1 ; lis[m+1] := 'x') ) ; for i : lis do ( execute (i)->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n,x=[int(k)for k in input().split()] w=[int(k)for k in input().split()] c=Counter(w) zxc=0 if x!=0 : for j in range(n): a=bin(w[j])[2 :] b=bin(x)[2 :] if x>=w[j]: a=a.zfill(len(b)) else : b=b.zfill(len(a)) y=len(a) res="" for j in range(y): if b[j]=="0" : res+=a[j] else : res+=str(int(not int(a[j]))) zxc+=c[int(res,2)] print(zxc//2) else : for j in c.keys(): if c[j]>1 : zxc+=c[j]*(c[j]-1)//2 print(zxc) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger())) ; var w : Sequence := input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger())) ; var c : OclAny := Counter(w) ; var zxc : int := 0 ; if x /= 0 then ( for j : Integer.subrange(0, n-1) do ( var a : OclAny := bin(w[j+1]).subrange(2+1) ; var b : OclAny := bin(x).subrange(2+1) ; if (x->compareTo(w[j+1])) >= 0 then ( a := a.zfill((b)->size()) ) else ( b := b.zfill((a)->size()) ) ; var y : int := (a)->size() ; var res : String := "" ; for j : Integer.subrange(0, y-1) do ( if b[j+1] = "0" then ( res := res + a[j+1] ) else ( res := res + ("" + ((("" + ((not(("" + ((a[j+1])))->toInteger()))))->toInteger()))) )) ; zxc := zxc + c[("" + ((res, 2)))->toInteger()+1]) ; execute (zxc div 2)->display() ) else ( for j : c.keys() do ( if c[j+1] > 1 then ( zxc := zxc + c[j+1] * (c[j+1] - 1) div 2 ) else skip) ; execute (zxc)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reverse(s): if len(s)==0 : return s else : return reverse(s[1 :])+s[0] def findNthNo(n): res="" ; while(n>=1): if(n & 1): res=res+"3" ; n=(int)((n-1)/2); else : res=res+"5" ; n=(int)((n-2)/2); return reverse(res); n=5 ; print(findNthNo(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 5; ; execute (findNthNo(n))->display();; operation reverse(s : OclAny) : OclAny pre: true post: true activity: if (s)->size() = 0 then ( return s ) else ( return reverse(s->tail()) + s->first() ); operation findNthNo(n : OclAny) pre: true post: true activity: var res : String := ""; ; while (n >= 1) do ( if (MathLib.bitwiseAnd(n, 1)) then ( res := res + "3"; ; n := (OclType["int"])((n - 1) / 2); ) else ( res := res + "5"; ; n := (OclType["int"])((n - 2) / 2); )) ; return reverse(res);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reverse(s): if len(s)==0 : return s else : return reverse(s[1 :])+s[0] def findNthNo(n): res="" ; while(n>=1): if(n & 1): res=res+"4" ; n=(int)((n-1)/2); else : res=res+"7" ; n=(int)((n-2)/2); return reverse(res); n=13 ; print(findNthNo(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 13; ; execute (findNthNo(n))->display();; operation reverse(s : OclAny) : OclAny pre: true post: true activity: if (s)->size() = 0 then ( return s ) else ( return reverse(s->tail()) + s->first() ); operation findNthNo(n : OclAny) pre: true post: true activity: var res : String := ""; ; while (n >= 1) do ( if (MathLib.bitwiseAnd(n, 1)) then ( res := res + "4"; ; n := (OclType["int"])((n - 1) / 2); ) else ( res := res + "7"; ; n := (OclType["int"])((n - 2) / 2); )) ; return reverse(res);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) sx,sy=0,0 upper=[] lower=[] for i in range(n): x,y=map(int,input().split()) upper.append(x) lower.append(y) def solve(upper,lower): sx=sum(upper) sy=sum(lower) if sx % 2==0 and sy % 2==0 : return 0 elif sx % 2==1 and sy % 2==1 : flag=0 for i in range(n): if(upper[i]% 2!=lower[i]% 2): return 1 else : flag=1 if flag==1 : return-1 else : return-1 print(solve(upper,lower)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sx : OclAny := null; var sy : OclAny := null; Sequence{sx,sy} := Sequence{0,0} ; var upper : Sequence := Sequence{} ; var lower : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((x) : upper) ; execute ((y) : lower)) ; skip ; execute (solve(upper, lower))->display(); operation solve(upper : OclAny, lower : OclAny) : OclAny pre: true post: true activity: var sx : OclAny := (upper)->sum() ; var sy : OclAny := (lower)->sum() ; if sx mod 2 = 0 & sy mod 2 = 0 then ( return 0 ) else (if sx mod 2 = 1 & sy mod 2 = 1 then ( var flag : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (upper[i+1] mod 2 /= lower[i+1] mod 2) then ( return 1 ) else ( flag := 1 )) ; if flag = 1 then ( return -1 ) else skip ) else ( return -1 ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def miis(): return map(int,input().split()) a=[0,0] have=0 for _ in range(int(input())): n,m=miis() if n % 2 ^ m % 2 : have=1 a[0]+=n a[1]+=m if a[0]% 2 and a[1]% 2 : if have : print(1) else : print(-1) elif a[0]% 2 ^ a[1]% 2 : print(-1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : Sequence := Sequence{0}->union(Sequence{ 0 }) ; var have : int := 0 ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := miis() ; if MathLib.bitwiseXor(n mod 2, m mod 2) then ( have := 1 ) else skip ; a->first() := a->first() + n ; a[1+1] := a[1+1] + m) ; if a->first() mod 2 & a[1+1] mod 2 then ( if have then ( execute (1)->display() ) else ( execute (-1)->display() ) ) else (if MathLib.bitwiseXor(a->first() mod 2, a[1+1] mod 2) then ( execute (-1)->display() ) else ( execute (0)->display() ) ) ; operation miis() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) kyori=[0 for _ in range(n+1)] cum_k=[0 for _ in range(n+1)] for ni in range(1,n): si=int(input()) kyori[ni]=si cum_k[ni+1]=cum_k[ni]+si ans,pos=0,1 for mi in range(m): nex=pos+int(input()) ans+=abs(cum_k[nex]-cum_k[pos]) pos=nex print(ans % 100000) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var kyori : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (0)) ; var cum_k : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (0)) ; for ni : Integer.subrange(1, n-1) do ( var si : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; kyori[ni+1] := si ; cum_k[ni + 1+1] := cum_k[ni+1] + si) ; var ans : OclAny := null; var pos : OclAny := null; Sequence{ans,pos} := Sequence{0,1} ; for mi : Integer.subrange(0, m-1) do ( var nex : OclAny := pos + ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; ans := ans + (cum_k[nex+1] - cum_k[pos+1])->abs() ; var pos : OclAny := nex) ; execute (ans mod 100000)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- number=int(input()) dominoes=[] for i in range(number): domino=list(map(int,input().split())) dominoes.append(domino) left=0 right=0 for i in range(len(dominoes)): left+=dominoes[i][0] right+=dominoes[i][1] different=0 for i in range(len(dominoes)): if(dominoes[i][0]% 2==0 and dominoes[i][1]% 2==1)or(dominoes[i][0]% 2==1 and dominoes[i][1]% 2==0): different+=1 if left % 2==0 and right % 2==0 : print(0) elif left % 2==1 and right % 2==1 and number!=1 and different>=2 : print(1) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var number : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var dominoes : Sequence := Sequence{} ; for i : Integer.subrange(0, number-1) do ( var domino : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((domino) : dominoes)) ; var left : int := 0 ; var right : int := 0 ; for i : Integer.subrange(0, (dominoes)->size()-1) do ( left := left + dominoes[i+1]->first() ; right := right + dominoes[i+1][1+1]) ; var different : int := 0 ; for i : Integer.subrange(0, (dominoes)->size()-1) do ( if (dominoes[i+1]->first() mod 2 = 0 & dominoes[i+1][1+1] mod 2 = 1) or (dominoes[i+1]->first() mod 2 = 1 & dominoes[i+1][1+1] mod 2 = 0) then ( different := different + 1 ) else skip) ; if left mod 2 = 0 & right mod 2 = 0 then ( execute (0)->display() ) else (if left mod 2 = 1 & right mod 2 = 1 & number /= 1 & different >= 2 then ( execute (1)->display() ) else ( execute (-1)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(lst1,lst2): return list(set(lst1)& set(lst2)) x,y=[],[] a,b=[],[] n=int(input()) for p in range(n): j,k=list(map(int,input().split())) x.append(j) y.append(k) for i in range(n): if x[i]% 2 : a.append(i) if y[i]% 2 : b.append(i) if len(a)% 2 and len(b)% 2==0 : print(-1) elif len(b)% 2 and len(a)% 2==0 : print(-1) elif len(a)% 2==0 and len(b)% 2==0 : print(0) else : p=len(solve(a,b)) if len(a)-p>0 or len(b)-p>0 : print(1) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{Sequence{},Sequence{}} ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{Sequence{},Sequence{}} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for p : Integer.subrange(0, n-1) do ( var j : OclAny := null; var k : OclAny := null; Sequence{j,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((j) : x) ; execute ((k) : y)) ; for i : Integer.subrange(0, n-1) do ( if x[i+1] mod 2 then ( execute ((i) : a) ) else skip ; if y[i+1] mod 2 then ( execute ((i) : b) ) else skip) ; if (a)->size() mod 2 & (b)->size() mod 2 = 0 then ( execute (-1)->display() ) else (if (b)->size() mod 2 & (a)->size() mod 2 = 0 then ( execute (-1)->display() ) else (if (a)->size() mod 2 = 0 & (b)->size() mod 2 = 0 then ( execute (0)->display() ) else ( var p : int := (solve(a, b))->size() ; if (a)->size() - p > 0 or (b)->size() - p > 0 then ( execute (1)->display() ) else ( execute (-1)->display() ) ) ) ) ; operation solve(lst1 : OclAny, lst2 : OclAny) : OclAny pre: true post: true activity: return (MathLib.bitwiseAnd(Set{}->union((lst1)), Set{}->union((lst2)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) upper=[] lower=[] for i in range(n): a,b=map(int,input().split()) upper.append(a % 2) lower.append(b % 2) upEven=sum(upper)% 2 lowEven=sum(lower)% 2 if upEven==0 and lowEven % 2==0 : print(0) exit() if upEven!=lowEven : print(-1) exit() if upEven==1 and lowEven==1 : for i in range(n): if upper[i]!=lower[i]: print(1) exit() print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var upper : Sequence := Sequence{} ; var lower : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a mod 2) : upper) ; execute ((b mod 2) : lower)) ; var upEven : int := (upper)->sum() mod 2 ; var lowEven : int := (lower)->sum() mod 2 ; if upEven = 0 & lowEven mod 2 = 0 then ( execute (0)->display() ; exit() ) else skip ; if upEven /= lowEven then ( execute (-1)->display() ; exit() ) else skip ; if upEven = 1 & lowEven = 1 then ( for i : Integer.subrange(0, n-1) do ( if upper[i+1] /= lower[i+1] then ( execute (1)->display() ; exit() ) else skip) ; execute (-1)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=input() K=int(input()) m=len(N) dp=[[[0]*(K+1)for _ in range(2)]for _ in range(m+1)] dp[0][0][0]=1 for i in range(1,m+1): l=int(N[i-1]) for k in range(K+1): if k==0 : dp[i][0][k]=0 dp[i][1][k]=1 else : if l!=0 : dp[i][0][k]=dp[i-1][0][k-1] dp[i][1][k]=dp[i-1][1][k]+9*dp[i-1][1][k-1]+dp[i-1][0][k]+(l-1)*dp[i-1][0][k-1] else : dp[i][0][k]=dp[i-1][0][k] dp[i][1][k]=dp[i-1][1][k]+9*dp[i-1][1][k-1] print(dp[m][0][K]+dp[m][1][K]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : String := (OclFile["System.in"]).readLine() ; var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := (N)->size() ; var dp : Sequence := Integer.subrange(0, m + 1-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, 2-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (K + 1)))))) ; dp->first()->first()->first() := 1 ; for i : Integer.subrange(1, m + 1-1) do ( var l : int := ("" + ((N[i - 1+1])))->toInteger() ; for k : Integer.subrange(0, K + 1-1) do ( if k = 0 then ( dp[i+1]->first()[k+1] := 0 ; dp[i+1][1+1][k+1] := 1 ) else ( if l /= 0 then ( dp[i+1]->first()[k+1] := dp[i - 1+1]->first()[k - 1+1] ; dp[i+1][1+1][k+1] := dp[i - 1+1][1+1][k+1] + 9 * dp[i - 1+1][1+1][k - 1+1] + dp[i - 1+1]->first()[k+1] + (l - 1) * dp[i - 1+1]->first()[k - 1+1] ) else ( dp[i+1]->first()[k+1] := dp[i - 1+1]->first()[k+1] ; dp[i+1][1+1][k+1] := dp[i - 1+1][1+1][k+1] + 9 * dp[i - 1+1][1+1][k - 1+1] ) ))) ; execute (dp[m+1]->first()[K+1] + dp[m+1][1+1][K+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() stand_up_hamsters=s.count('X') sit_down_hamsters=n-stand_up_hamsters if stand_up_hamsters==sit_down_hamsters : print(0) print(s) else : difference=n//2-min(stand_up_hamsters,sit_down_hamsters) print(difference) convert_to_list=list(s) i=0 j=0 if stand_up_hamsters>sit_down_hamsters : while jtoInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var stand_up_hamsters : int := s->count('X') ; var sit_down_hamsters : double := n - stand_up_hamsters ; if stand_up_hamsters = sit_down_hamsters then ( execute (0)->display() ; execute (s)->display() ) else ( var difference : double := n div 2 - Set{stand_up_hamsters, sit_down_hamsters}->min() ; execute (difference)->display() ; var convert_to_list : Sequence := (s)->characters() ; var i : int := 0 ; var j : int := 0 ; if (stand_up_hamsters->compareTo(sit_down_hamsters)) > 0 then ( while (j->compareTo(difference)) < 0 do ( if convert_to_list[i+1] = 'X' then ( convert_to_list[i+1] := 'x' ; j := j + 1 ) else skip ; i := i + 1) ) else ( while (j->compareTo(difference)) < 0 do ( if convert_to_list[i+1] = 'x' then ( convert_to_list[i+1] := 'X' ; j := j + 1 ) else skip ; i := i + 1) ) ; execute (StringLib.sumStringsWithSeparator((convert_to_list), ''))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines from functools import lru_cache N,K=map(int,read().split()) @ lru_cache(None) def F(N,K): assert N>=0 if N<10 : if K==0 : return 1 if K==1 : return N return 0 q,r=divmod(N,10) ret=0 if K>=1 : ret+=F(q,K-1)*r ret+=F(q-1,K-1)*(9-r) ret+=F(q,K) return ret print(F(N,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (read().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (compound_stmt (decorator @ (dotted_name (name lru_cache)) ( (arglist (argument (test (logical_test (comparison (expr (atom None))))))) )) (funcdef def (name F) ( (typedargslist (def_parameters (def_parameter (named_parameter (name N))) , (def_parameter (named_parameter (name K))))) ) : (suite (stmt (simple_stmt (small_stmt assert (test (logical_test (comparison (comparison (expr (atom (name N)))) >= (comparison (expr (atom (number (integer 0))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name N)))) < (comparison (expr (atom (number (integer 10)))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name K)))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name K)))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name N))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name q)))))) , (test (logical_test (comparison (expr (atom (name r))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name divmod)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 10))))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ret)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name K)))) >= (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ret)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name F)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name q))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name K))) - (expr (atom (number (integer 1)))))))))) )))) * (expr (atom (name r)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ret)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name F)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name q))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name K))) - (expr (atom (number (integer 1)))))))))) )))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 9)))) - (expr (atom (name r)))))))) ))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ret)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name F)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name q))))))) , (argument (test (logical_test (comparison (expr (atom (name K)))))))) )))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name ret))))))))))))) ; execute (F(N, K))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict N=input().strip() K=int(input().strip()) lenN=len(N) memo=defaultdict(lambda : defaultdict(lambda : defaultdict(int))) def f(keta,flag,k): if keta==lenN-1 : if k==K : return 1 else : return 0 if keta in memo and flag in memo[keta]and k in memo[keta][flag]: return memo[keta][flag][k] nketa=keta+1 maxi=int(N[nketa])if flag else 9 res=0 for i in range(maxi+1): nflag=flag and(int(N[nketa])==i) nk=k if i==0 else k+1 if nk>K : continue res+=f(nketa,nflag,nk) memo[keta][flag][k]=res return res print(f(-1,True,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := input()->trim() ; var K : int := ("" + ((input()->trim())))->toInteger() ; var lenN : int := (N)->size() ; var memo : OclAny := defaultdict(lambda $$ : OclAny in (defaultdict(lambda $$ : OclAny in (defaultdict(OclType["int"]))))) ; skip ; execute (f(-1, true, 0))->display(); operation f(keta : OclAny, flag : OclAny, k : OclAny) : OclAny pre: true post: true activity: if keta = lenN - 1 then ( if k = K then ( return 1 ) else ( return 0 ) ) else skip ; if (memo)->includes(keta) & (memo[keta+1])->includes(flag) & (memo[keta+1][flag+1])->includes(k) then ( return memo[keta+1][flag+1][k+1] ) else skip ; var nketa : OclAny := keta + 1 ; var maxi : int := if flag then ("" + ((N[nketa+1])))->toInteger() else 9 endif ; var res : int := 0 ; for i : Integer.subrange(0, maxi + 1-1) do ( var nflag : boolean := flag & (("" + ((N[nketa+1])))->toInteger() = i) ; var nk : OclAny := if i = 0 then k else k + 1 endif ; if (nk->compareTo(K)) > 0 then ( continue ) else skip ; res := res + f(nketa, nflag, nk)) ; memo[keta+1][flag+1][k+1] := res ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import numpy as np import itertools n=int(input()) k=int(input()) a=n p=0 nn=[] while a>0 : p+=1 r=a % 10 nn.insert(0,r) a=a//10 dp0=np.zeros((p+1,k+2),dtype="int64") dp1=np.zeros((p+1,k+2),dtype="int64") dp1[0][0]=1 for i in range(p): for j in range(k+1): dp0[i+1][j]+=dp0[i][j]+dp1[i][j]*(nn[i]>0) dp0[i+1][j+1]+=dp0[i][j]*9+dp1[i][j]*max(nn[i]-1,0) dp1[i+1][j]+=dp1[i][j]*(nn[i]==0) dp1[i+1][j+1]+=dp1[i][j]*(nn[i]!=0) answer=dp0[p][k]+dp1[p][k] print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := n ; var p : int := 0 ; var nn : Sequence := Sequence{} ; while a > 0 do ( p := p + 1 ; var r : int := a mod 10 ; nn := nn.insertAt(0+1, r) ; a := a div 10) ; var dp0 : Sequence := MatrixLib.singleValueMatrix(Sequence{p + 1, k + 2}, 0.0) ; var dp1 : Sequence := MatrixLib.singleValueMatrix(Sequence{p + 1, k + 2}, 0.0) ; dp1->first()->first() := 1 ; for i : Integer.subrange(0, p-1) do ( for j : Integer.subrange(0, k + 1-1) do ( dp0[i + 1+1][j+1] := dp0[i + 1+1][j+1] + dp0[i+1][j+1] + dp1[i+1][j+1] * (nn[i+1] > 0) ; dp0[i + 1+1][j + 1+1] := dp0[i + 1+1][j + 1+1] + dp0[i+1][j+1] * 9 + dp1[i+1][j+1] * Set{nn[i+1] - 1, 0}->max() ; dp1[i + 1+1][j+1] := dp1[i + 1+1][j+1] + dp1[i+1][j+1] * (nn[i+1] = 0) ; dp1[i + 1+1][j + 1+1] := dp1[i + 1+1][j + 1+1] + dp1[i+1][j+1] * (nn[i+1] /= 0))) ; var answer : OclAny := dp0[p+1][k+1] + dp1[p+1][k+1] ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=input() K=int(input()) k=len(N) ans=0 if ktoInteger() ; var k : int := (N)->size() ; var ans : int := 0 ; if (k->compareTo(K)) < 0 then ( execute (0)->display() ; exit() ) else skip ; skip ; execute (solve(N, K))->display(); operation solve(N : OclAny, K : OclAny) : OclAny pre: true post: true activity: if ((N)->size()->compareTo(K)) < 0 then ( return 0 ) else skip ; if N->first() = '0' then ( return solve(N->tail(), K) ) else skip ; if K = 1 then ( return ((N)->size() - 1) * 9 + ("" + ((N->first())))->toInteger() ) else skip ; var res : int := 0 ; if K = 2 then ( res := res + ((9)->pow(2)) * ((N)->size() - 1) * ((N)->size() - 2) div 2 ; res := res + 9 * ((N)->size() - 1) * (("" + ((N->first())))->toInteger() - 1) ; res := res + solve(N->tail(), K - 1) ) else skip ; if K = 3 then ( res := res + ((9)->pow(3)) * ((N)->size() - 1) * ((N)->size() - 2) * ((N)->size() - 3) div 6 ; res := res + ((9)->pow(2)) * ((N)->size() - 1) * ((N)->size() - 2) div 2 * (("" + ((N->first())))->toInteger() - 1) ; res := res + solve(N->tail(), K - 1) ) else skip ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def go(n,k): i=1 i2=0 while k>=i : i2+=1 i+=i2 i-=i2 k-=i print("a"*(n-i2-1)+"b"+"a"*(n-(n-i2-1)-k-2)+"b"+"a"*(k)) t=int(input()) for j in range(t): n,k=[int(i)for i in input().split()] go(n,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, t-1) do ( Sequence{n,k} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; go(n, k)); operation go(n : OclAny, k : OclAny) pre: true post: true activity: var i : int := 1 ; var i2 : int := 0 ; while (k->compareTo(i)) >= 0 do ( i2 := i2 + 1 ; i := i + i2) ; i := i - i2 ; k := k - i ; execute (StringLib.nCopies("a", (n - i2 - 1)) + "b" + StringLib.nCopies("a", (n - (n - i2 - 1) - k - 2)) + "b" + StringLib.nCopies("a", (k)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) left=n-2 i=1 while((i*(i+1))//2toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var left : double := n - 2 ; var i : int := 1 ; while (((i * (i + 1)) div 2->compareTo(k)) < 0) do ( left := left - 1 ; i := i + 1) ; var x : int := (i * (i - 1)) div 2 ; var right : double := k - x - 1 ; var middle : double := (n - 2) - (left + right) ; execute (StringLib.nCopies("a", left) + "b" + StringLib.nCopies("a", middle) + "b" + StringLib.nCopies("a", right))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) c=[list(map(int,input().split()))for _ in range(n)] d=[[x[0],0]for x in c]+[[y[1],1]for y in c] d.sort() r=0 p=0 for z in d : if z[1]==0 : r+=1 p=max(r,p) else : r-=1 print(p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var d : Sequence := c->select(x | true)->collect(x | (Sequence{x->first()}->union(Sequence{ 0 })))->union(c->select(y | true)->collect(y | (Sequence{y[1+1]}->union(Sequence{ 1 })))) ; d := d->sort() ; var r : int := 0 ; var p : int := 0 ; for z : d do ( if z[1+1] = 0 then ( r := r + 1 ; p := Set{r, p}->max() ) else ( r := r - 1 )) ; execute (p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): wah=list(map(int,input().split(' '))) n,k=wah[0],wah[1] pos=n-1 for i in range(1,wah[0]): if k-i<=0 : print((pos-1)*'a'+'b'+'a'*((n-k)-pos)+'b'+'a'*(n-(n-k+1))) break else : k-=i pos-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var wah : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := Sequence{wah->first(),wah[1+1]} ; var pos : double := n - 1 ; for i : Integer.subrange(1, wah->first()-1) do ( if k - i <= 0 then ( execute ((pos - 1) * 'a' + 'b' + StringLib.nCopies('a', ((n - k) - pos)) + 'b' + StringLib.nCopies('a', (n - (n - k + 1))))->display() ; break ) else ( k := k - i ; pos := pos - 1 ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil,floor,sqrt t=int(input()) for _ in range(t): n,k=(int(num)for num in input().split(" ")) ans=['a']*n x=int(ceil((-1+sqrt(1+4*2*k))/2)) first_b=n-x-1 ans[first_b]='b' summation=(x-1)/2*x rem=k-summation second_b=int(n-rem) ans[second_b]='b' print(''.join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) ))))))) (comp_for for (exprlist (expr (atom (name num)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " "))))))) ))))))))} ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 'a' }, n) ; var x : int := ("" + ((ceil((-1 + sqrt(1 + 4 * 2 * k)) / 2))))->toInteger() ; var first_b : double := n - x - 1 ; ans[first_b+1] := 'b' ; var summation : double := (x - 1) / 2 * x ; var rem : double := k - summation ; var second_b : int := ("" + ((n - rem)))->toInteger() ; ans[second_b+1] := 'b' ; execute (StringLib.sumStringsWithSeparator((ans), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) for i in range(n): if(k<=i): break k=k-i print('a'*(n-i-1)+'b'+'a'*(i-k)+'b'+'a'*(k-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, n-1) do ( if ((k->compareTo(i)) <= 0) then ( break ) else skip ; var k : double := k - i) ; execute (StringLib.nCopies('a', (n - i - 1)) + 'b' + StringLib.nCopies('a', (i - k)) + 'b' + StringLib.nCopies('a', (k - 1)))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=list(map(int,input().split())) a_to_i={a : i for i,a in enumerate(A,start=1)} L=[i-1 for i in range(N+2)] R=[i+1 for i in range(N+2)] ans=0 for a in range(N,0,-1): i=a_to_i[a] ans+=a*(R[i]-i)*(i-L[i]) L[R[i]]=L[i] R[L[i]]=R[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a_to_i : Map := Integer.subrange(1, (A, (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->size())->collect( _indx | Sequence{_indx-1, (A, (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->at(_indx)} )->select(_tuple | true)->collect(_tuple | Map{a |-> i})->unionAll() ; var L : Sequence := Integer.subrange(0, N + 2-1)->select(i | true)->collect(i | (i - 1)) ; var R : Sequence := Integer.subrange(0, N + 2-1)->select(i | true)->collect(i | (i + 1)) ; var ans : int := 0 ; for a : Integer.subrange(0 + 1, N)->reverse() do ( var i : OclAny := a_to_i[a+1] ; ans := ans + a * (R[i+1] - i) * (i - L[i+1]) ; L[R[i+1]+1] := L[i+1] ; R[L[i+1]+1] := R[i+1]) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,m,a,b,ds): is_waste=[False for _ in range(n)] for i in range(n): if ds[i]>=a : is_waste[i]=True else : break if sum(is_waste)>n-m : for i in range(n)[: :-1]: if is_waste[i]: if ds[i]<=b : is_waste[i]=False else : break return sum(is_waste) def main(): n,m,a,b=map(int,input().split()) ds=list(map(int,input().split())) print(solve(n,m,a,b,ds)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(n : OclAny, m : OclAny, a : OclAny, b : OclAny, ds : OclAny) : OclAny pre: true post: true activity: var is_waste : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (false)) ; for i : Integer.subrange(0, n-1) do ( if (ds[i+1]->compareTo(a)) >= 0 then ( is_waste[i+1] := true ) else ( break )) ; if ((is_waste)->sum()->compareTo(n - m)) > 0 then ( for i : range(n)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if is_waste[i+1] then ( if (ds[i+1]->compareTo(b)) <= 0 then ( is_waste[i+1] := false ) else ( break ) ) else skip) ) else skip ; return (is_waste)->sum(); operation main() pre: true post: true activity: Sequence{n,m,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; ds := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (solve(n, m, a, b, ds))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=10**9+7 def factorial(n,p): res=1 for i in range(2,n+1): res=(res*i)% p return res def power(x,y,p): res=1 x=x % p while(y>0): if(y & 1): res=(res*x)% p y=y>>1 x=(x*x)% p return res def modInverse(n,p): return power(n,p-2,p) def nCrModP(n,r,p): if(r==0): return 1 fac=[0 for i in range(n+1)] fac[0]=1 for i in range(1,n+1): fac[i]=fac[i-1]*i % p return(fac[n]*modInverse(fac[r],p)% p*modInverse(fac[n-r],p)% p)% p def countArrangements(n,k,p): return(factorial(n,p)*nCrModP(k,n,p))% p N=5 K=8 print(countArrangements(N,K,mod)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; var N : int := 5 ; var K : int := 8 ; execute (countArrangements(N, K, mod))->display(); operation factorial(n : OclAny, p : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; for i : Integer.subrange(2, n + 1-1) do ( res := (res * i) mod p) ; return res; operation power(x : OclAny, y : OclAny, p : OclAny) : OclAny pre: true post: true activity: res := 1 ; x := x mod p ; while (y > 0) do ( if (MathLib.bitwiseAnd(y, 1)) then ( res := (res * x) mod p ) else skip ; y := y /(2->pow(1)) ; x := (x * x) mod p) ; return res; operation modInverse(n : OclAny, p : OclAny) : OclAny pre: true post: true activity: return power(n, p - 2, p); operation nCrModP(n : OclAny, r : OclAny, p : OclAny) : OclAny pre: true post: true activity: if (r = 0) then ( return 1 ) else skip ; var fac : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; fac->first() := 1 ; for i : Integer.subrange(1, n + 1-1) do ( fac[i+1] := fac[i - 1+1] * i mod p) ; return (fac[n+1] * modInverse(fac[r+1], p) mod p * modInverse(fac[n - r+1], p) mod p) mod p; operation countArrangements(n : OclAny, k : OclAny, p : OclAny) : OclAny pre: true post: true activity: return (factorial(n, p) * nCrModP(k, n, p)) mod p; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=3 C=3 def minCost(cost,m,n): tc=[[0 for x in range(C)]for x in range(R)] tc[0][0]=cost[0][0] for i in range(1,m+1): tc[i][0]=tc[i-1][0]+cost[i][0] for j in range(1,n+1): tc[0][j]=tc[0][j-1]+cost[0][j] for i in range(1,m+1): for j in range(1,n+1): tc[i][j]=min(tc[i-1][j-1],tc[i-1][j],tc[i][j-1])+cost[i][j] return tc[m][n] cost=[[1,2,3],[4,8,2],[1,5,3]] print(minCost(cost,2,2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : int := 3 ; var C : int := 3 ; skip ; cost := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{Sequence{4}->union(Sequence{8}->union(Sequence{ 2 }))}->union(Sequence{ Sequence{1}->union(Sequence{5}->union(Sequence{ 3 })) })) ; execute (minCost(cost, 2, 2))->display(); operation minCost(cost : OclAny, m : OclAny, n : OclAny) : OclAny pre: true post: true activity: var tc : Sequence := Integer.subrange(0, R-1)->select(x | true)->collect(x | (Integer.subrange(0, C-1)->select(x | true)->collect(x | (0)))) ; tc->first()->first() := cost->first()->first() ; for i : Integer.subrange(1, m + 1-1) do ( tc[i+1]->first() := tc[i - 1+1]->first() + cost[i+1]->first()) ; for j : Integer.subrange(1, n + 1-1) do ( tc->first()[j+1] := tc->first()[j - 1+1] + cost->first()[j+1]) ; for i : Integer.subrange(1, m + 1-1) do ( for j : Integer.subrange(1, n + 1-1) do ( tc[i+1][j+1] := Set{tc[i - 1+1][j - 1+1], tc[i - 1+1][j+1], tc[i+1][j - 1+1]}->min() + cost[i+1][j+1])) ; return tc[m+1][n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin,stdout from math import* import math,random,operator from itertools import product,permutations,combinations from collections import deque,defaultdict,Counter input=sys.stdin.readline def hi(): n=int(input()) l=list(map(int,input().split())) l.sort() res=[] p=0 q=n-1 for i in range(n): if i & 1 : res.append(l[q]) q-=1 else : res.append(l[p]) p+=1 print(*res,sep=' ') if __name__=="__main__" : hi() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = "__main__" then ( hi() ) else skip; operation hi() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := l->sort() ; var res : Sequence := Sequence{} ; var p : int := 0 ; var q : double := n - 1 ; for i : Integer.subrange(0, n-1) do ( if MathLib.bitwiseAnd(i, 1) then ( execute ((l[q+1]) : res) ; q := q - 1 ) else ( execute ((l[p+1]) : res) ; p := p + 1 )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=eval(input()) y=list(map(int,input().split())) res=[] while len(y)>=2 : res+=[min(y),max(y)] y.remove(max(y)) y.remove(min(y)) res+=y for x in res : print(x,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := (OclFile["System.in"]).readLine() ; var y : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : Sequence := Sequence{} ; while (y)->size() >= 2 do ( res := res + Sequence{(y)->min()}->union(Sequence{ (y)->max() }) ; execute (((y)->max()) /: y) ; execute (((y)->min()) /: y)) ; res := res + y ; for x : res do ( execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=list(map(int,input().split())) b.sort() i=0 while(itoInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; b := b->sort() ; var i : int := 0 ; while ((i->compareTo(a div 2)) < 0) do ( execute (b[i+1])->display() ; i := i + 1) ; if a mod 2 then ( execute (b[a div 2+1])->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) nums=sorted(list(map(int,input().split()))) for i in range(n//2+1): print(nums[i],end=" ") if n//2+i+1toInteger() ; var nums : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; for i : Integer.subrange(0, n div 2 + 1-1) do ( execute (nums[i+1])->display() ; if (n div 2 + i + 1->compareTo(n)) < 0 then ( execute (nums[n div 2 + i + 1+1])->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[] for _ in[0]*n : a,b=map(int,input().split()) l.extend([(a,1),(b+1,-1)]) l.sort() c=0 a=0 for _,v in l : c+=v a=max(a,c) print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, n) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; l := l->union(Sequence{Sequence{a, 1}}->union(Sequence{ Sequence{b + 1, -1} }))) ; l := l->sort() ; var c : int := 0 ; var a : int := 0 ; for _tuple : l do (var _indx : int := 1; var _anon : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); c := c + v ; a := Set{a, c}->max()) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) a=int(input()) b=list(map(int,input().split())) b.sort() i=0 while(itoInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; b := b->sort() ; var i : int := 0 ; while ((i->compareTo(a div 2)) < 0) do ( execute (b[i+1])->display() ; i := i + 1) ; if a mod 2 then ( execute (b[a div 2+1])->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumArr(arr,n): sum=0 for i in range(n): sum+=arr[i] return sum def sumModArr(arr,n): for i in range(n-1): subSum=0 for j in range(i+1,n): subSum+=arr[j] arr[i]-=subSum return sumArr(arr,n) arr=[40,25,12,10] n=len(arr) print(sumModArr(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{40}->union(Sequence{25}->union(Sequence{12}->union(Sequence{ 10 }))) ; n := (arr)->size() ; execute (sumModArr(arr, n))->display(); operation sumArr(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + arr[i+1]) ; return sum; operation sumModArr(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n - 1-1) do ( var subSum : int := 0 ; for j : Integer.subrange(i + 1, n-1) do ( subSum := subSum + arr[j+1]) ; arr[i+1] := arr[i+1] - subSum) ; return sumArr(arr, n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n=int(input()) s=input() c=Counter(s) if c['x']==c['X']: print(0) print(s) else : p=n//2 a=p-c['x'] b=p-c['X'] s=list(s) if ab : print(abs(b)) c=0 for i in range(len(s)): if c!=abs(b): if s[i]=='X' : s[i]='x' c+=1 else : break print(''.join(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var c : OclAny := Counter(s) ; if c->at('x') = c->at('X') then ( execute (0)->display() ; execute (s)->display() ) else ( var p : int := n div 2 ; var a : double := p - c->at('x') ; var b : double := p - c->at('X') ; s := (s)->characters() ; if (a->compareTo(b)) < 0 then ( execute ((a)->abs())->display() ; c := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if c /= (a)->abs() then ( if s[i+1] = 'x' then ( s[i+1] := 'X' ; c := c + 1 ) else skip ) else ( break )) ) else (if (a->compareTo(b)) > 0 then ( execute ((b)->abs())->display() ; c := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if c /= (b)->abs() then ( if s[i+1] = 'X' then ( s[i+1] := 'x' ; c := c + 1 ) else skip ) else ( break )) ) else skip) ; execute (StringLib.sumStringsWithSeparator((s), ''))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numberOfLines(S,widths): if(S==""): return 0,0 lines,width=1,0 for c in S : w=widths[ord(c)-ord('a')] width+=w if width>10 : lines+=1 width=w return lines,width S="bbbcccdddaa" Widths=[4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] print(numberOfLines(S,Widths)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; S := "bbbcccdddaa" ; var Widths : Sequence := Sequence{4}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))))))))))))))))))))))))) ; execute (numberOfLines(S, Widths))->display(); operation numberOfLines(S : OclAny, widths : OclAny) : OclAny pre: true post: true activity: if (S = "") then ( return 0, 0 ) else skip ; var lines : OclAny := null; var width : OclAny := null; Sequence{lines,width} := Sequence{1,0} ; for c : S do ( var w : OclAny := widths[(c)->char2byte() - ('a')->char2byte()+1] ; width := width + w ; if width > 10 then ( lines := lines + 1 ; var width : OclAny := w ) else skip) ; return lines, width; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkPair(arr,n): s=set() sum=0 for i in range(n): sum+=arr[i] if sum % 2!=0 : return False sum=sum/2 for i in range(n): val=sum-arr[i] if arr[i]not in s : s.add(arr[i]) if val in s : print("Pair elements are",arr[i],"and",int(val)) arr=[2,11,5,1,4,7] n=len(arr) if checkPair(arr,n)==False : print("No pair found") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{11}->union(Sequence{5}->union(Sequence{1}->union(Sequence{4}->union(Sequence{ 7 }))))) ; n := (arr)->size() ; if checkPair(arr, n) = false then ( execute ("No pair found")->display() ) else skip; operation checkPair(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var s : Set := Set{}->union(()) ; var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + arr[i+1]) ; if sum mod 2 /= 0 then ( return false ) else skip ; sum := sum / 2 ; for i : Integer.subrange(0, n-1) do ( var val : double := sum - arr[i+1] ; if (s)->excludes(arr[i+1]) then ( execute ((arr[i+1]) : s) ) else skip ; if (s)->includes(val) then ( execute ("Pair elements are")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def difference(n): S=(n*(n+1))//2 ; res=S*(S-1); return res ; if __name__=="__main__" : n=5 ; print(difference(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 5; ; execute (difference(n))->display(); ) else skip; operation difference(n : OclAny) pre: true post: true activity: var S : int := (n * (n + 1)) div 2; ; var res : double := S * (S - 1); ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=500 size=1 def factorial(prevFact,prev,n): global size for x in range((prev+1),n+1): size=multiply(x,prevFact,size) for i in range((size-1),-1,-1): print(prevFact[i],end="") print(end=" ") def printfibFactorials(limit): if(limit<1): return a=1 b=1 c=2 print(a,b,end=" ") prevFact=[0]*MAX prevFact[0]=1 while(creverse() do ( execute (prevFact[i+1])->display()) ; execute ((argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom " ")))))))->display(); operation printfibFactorials(limit : OclAny) pre: true post: true activity: if (limit < 1) then ( return ) else skip ; var a : int := 1 ; var b : int := 1 ; var c : int := 2 ; execute (a)->display() ; prevFact := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX) ; prevFact->first() := 1 ; while ((c->compareTo(limit)) < 0) do ( factorial(prevFact, b, c) ; a := b ; b := c ; c := a + b); operation multiply(x : OclAny, prevFact : OclAny, size : OclAny) : OclAny pre: true post: true activity: var carry : int := 0 ; for i : Integer.subrange(0, size-1) do ( var prod : double := prevFact[i+1] * x + carry ; prevFact[i+1] := prod mod 10 ; carry := prod div 10) ; while (carry /= 0) do ( prevFact[size+1] := carry mod 10 ; carry := carry div 10 ; size := size + 1) ; return size; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isKAlternating(s,k): if(len(s)0): return False checker=checker |(1<display() ) else ( execute ("No")->display() ) ) else skip; operation isKAlternating(s : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (((s)->size()->compareTo(k)) < 0) then ( return false ) else skip ; var checker : int := 0 ; for i : Integer.subrange(0, k-1) do ( var bitAtIndex : double := (s[i+1])->char2byte() - ('a')->char2byte() ; if ((MathLib.bitwiseAnd(checker, (1 * (2->pow(bitAtIndex))))) > 0) then ( return false ) else skip ; checker := MathLib.bitwiseOr(checker, (1 * (2->pow(bitAtIndex))))) ; for i : Integer.subrange(k, (s)->size()-1) do ( if (s[i - k+1] /= s[i+1]) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) L=[int(i)for i in input().split()] L.sort() def out_detect(n,L): flag=0 if n % 2==0 : for i in range(n): if L[i]!=-(-(i+1)//2)*2-1 : flag=1 break else : if L[0]!=0 : flag=1 return(flag) for i in range(1,n): if L[i]!=(-(-i//2)*2): flag=1 break return(flag) if out_detect(n,L)==1 : print(0) else : if n % 2==0 : out=pow(2,n//2) else : out=pow(2,(n-1)//2) print(out %(pow(10,9)+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var L : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; L := L->sort() ; skip ; if out_detect(n, L) = 1 then ( execute (0)->display() ) else ( if n mod 2 = 0 then ( var out : double := (2)->pow(n div 2) ) else ( out := (2)->pow((n - 1) div 2) ) ; execute (out mod ((10)->pow(9) + 7))->display() ); operation out_detect(n : OclAny, L : OclAny) : OclAny pre: true post: true activity: var flag : int := 0 ; if n mod 2 = 0 then ( for i : Integer.subrange(0, n-1) do ( if L[i+1] /= -(-(i + 1) div 2) * 2 - 1 then ( flag := 1 ; break ) else skip) ) else ( if L->first() /= 0 then ( flag := 1 ; return (flag) ) else skip ; for i : Integer.subrange(1, n-1) do ( if L[i+1] /= (-(-i div 2) * 2) then ( flag := 1 ; break ) else skip) ) ; return (flag); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def inpl(): return input().split() n=int(input()) a=sorted(list(map(int,inpl()))) p=10**9+7 if a[0]==0 : st=1 next_value=2 else : st=0 next_value=1 ans=1 found=False for i in range(st,n): if(next_value==a[i]): if found : next_value+=2 found=False ans*=2 if ans>p : ans %=p else : found=True else : ans=0 break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((inpl())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var p : double := (10)->pow(9) + 7 ; if a->first() = 0 then ( var st : int := 1 ; var next_value : int := 2 ) else ( st := 0 ; next_value := 1 ) ; var ans : int := 1 ; var found : boolean := false ; for i : Integer.subrange(st, n-1) do ( if (next_value = a[i+1]) then ( if found then ( next_value := next_value + 2 ; found := false ; ans := ans * 2 ; if (ans->compareTo(p)) > 0 then ( ans := ans mod p ) else skip ) else ( found := true ) ) else ( ans := 0 ; break )) ; execute (ans)->display(); operation inpl() : OclAny pre: true post: true activity: return input().split(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) import numpy as np a=np.sort(np.array(input().split(),dtype=int)) DIV=10**9+7 if n % 2==1 : if a[0]!=0 : print(0) exit(0) a=a[1 :] a-=1 for i in range(len(a)): if a[i]!=i+(i % 2==0): print(0) exit(0) print((2**(len(a)//2))% DIV) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; var a : (trailer . (name sort) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name np)) (trailer . (name array) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( )))))))) , (argument (test (logical_test (comparison (expr (atom (name dtype)))))) = (test (logical_test (comparison (expr (atom (name int)))))))) ))))))))) ))) := ; var DIV : double := (10)->pow(9) + 7 ; if n mod 2 = 1 then ( if a->first() /= 0 then ( execute (0)->display() ; exit(0) ) else skip ; a := a->tail() ; a := a - 1 ) else skip ; for i : Integer.subrange(0, (a)->size()-1) do ( if a[i+1] /= i + (i mod 2 = 0) then ( execute (0)->display() ; exit(0) ) else skip) ; execute (((2)->pow(((a)->size() div 2))) mod DIV)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isVowel(c): if(c=='a' or c=='e' or c=='i' or c=='o' or c=='u'): return True return False def checkPossibility(s1,s2): l1=len(s1) l2=len(s2) if(l1!=l2): return False for i in range(l1): if(isVowel(s1[i])and isVowel(s2[i])): continue elif((isVowel(s1[i]))==False and(isVowel(s2[i])==False)): continue else : return False return True S1,S2="abcgle","ezggli" if(checkPossibility(S1,S2)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var S1 : OclAny := null; var S2 : OclAny := null; Sequence{S1,S2} := Sequence{"abcgle","ezggli"} ; if (checkPossibility(S1, S2)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isVowel(c : OclAny) : OclAny pre: true post: true activity: if (c = 'a' or c = 'e' or c = 'i' or c = 'o' or c = 'u') then ( return true ) else skip ; return false; operation checkPossibility(s1 : OclAny, s2 : OclAny) : OclAny pre: true post: true activity: var l1 : int := (s1)->size() ; var l2 : int := (s2)->size() ; if (l1 /= l2) then ( return false ) else skip ; for i : Integer.subrange(0, l1-1) do ( if (isVowel(s1[i+1]) & isVowel(s2[i+1])) then ( continue ) else (if ((isVowel(s1[i+1])) = false & (isVowel(s2[i+1]) = false)) then ( continue ) else ( return false ) ) ) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline MOD=10**9+7 INF=float('INF') sys.setrecursionlimit(10**5) def main(): from collections import Counter n=int(readline()) a=list(map(int,readline().split())) counter=Counter(a) ok=True if n % 2==1 : if counter[0]!=1 : ok=False for i in range(2,n,2): if counter[i]!=2 : ok=False else : for i in range(1,n,2): if counter[i]!=2 : ok=False if ok : print(pow(2,n//2,MOD)) else : print(0) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var MOD : double := (10)->pow(9) + 7 ; var INF : double := ("" + (('INF')))->toReal() ; sys.setrecursionlimit((10)->pow(5)) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: skip ; var n : int := ("" + ((readline())))->toInteger() ; var a : Sequence := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var counter : OclAny := Counter(a) ; var ok : boolean := true ; if n mod 2 = 1 then ( if counter->first() /= 1 then ( ok := false ) else skip ; for i : Integer.subrange(2, n-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( if counter[i+1] /= 2 then ( ok := false ) else skip) ) else ( for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( if counter[i+1] /= 2 then ( ok := false ) else skip) ) ; if ok then ( execute ((2)->pow(n div 2))->display() ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) d=int(input()) e=int(input()) dm=d em=e*5 max=max(dm,em) min=min(dm,em) rem=n % max div=int((n-rem)/max) i=div ans=rem while i>-1 : dum=0 dum+=n rl=dum-(i*max) fin=rl % min if fintoInteger() ; var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var e : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var dm : int := d ; var em : int := e * 5 ; var max : OclAny := Set{dm, em}->max() ; var min : OclAny := Set{dm, em}->min() ; var rem : int := n mod max ; var div : int := ("" + (((n - rem) / max)))->toInteger() ; var i : int := div ; var ans : int := rem ; while i > -1 do ( var dum : int := 0 ; dum := dum + n ; var rl : double := dum - (i * max) ; var fin : int := rl mod min ; if (fin->compareTo(ans)) < 0 then ( if fin = 0 then ( ans := 0 ; i := -1 ) else ( ans := fin ) ) else skip ; i := i - 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter,defaultdict import sys,heapq,bisect,math,itertools,string,queue sys.setrecursionlimit(10**8) mod=10**9+7 def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int,sys.stdin.readline().split())) def inpl_str(): return list(sys.stdin.readline().split()) def inpln(n): return list(int(sys.stdin.readline())for i in range(n)) n=inp() a=inpl() cnt=Counter(a) if n % 2==0 : for key in cnt.keys(): if key % 2 and keypow(8)) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; n := inp() ; var a : OclAny := inpl() ; var cnt : OclAny := Counter(a) ; if n mod 2 = 0 then ( for key : cnt.keys() do ( if key mod 2 & (key->compareTo(n)) < 0 & cnt[key+1] = 2 then ( continue ) else ( execute (0)->display() ; quit() )) ; execute (((2)->pow((n div 2))) mod mod)->display() ) else ( for key : cnt.keys() do ( if key mod 2 = 0 & (key->compareTo(n)) < 0 & cnt[key+1] = 2 then ( continue ) else (if key = 0 & cnt[key+1] = 1 then ( continue ) else ( execute (0)->display() ; quit() ) ) ) ; execute (((2)->pow((n div 2))) mod mod)->display() ); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inpl() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inpl_str() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split()); operation inpln(n : OclAny) : OclAny pre: true post: true activity: return ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin)) (trailer . (name readline) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break t=list(map(int,input().split())) s=sum(t) ans=s>>1 if ans in t : print(s-2*ans) continue a=[v for v in t if vtoInteger() ; if n = 0 then ( break ) else skip ; var t : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : OclAny := (t)->sum() ; var ans : int := s /(2->pow(1)) ; if (t)->includes(ans) then ( execute (s - 2 * ans)->display() ; continue ) else skip ; var a : Sequence := t->select(v | (v->compareTo(ans)) < 0)->collect(v | (v)) ; var S : OclAny := null; var f : OclAny := null; var Q : OclAny := null; var qlen : OclAny := null; Sequence{S,f,Q,qlen} := Sequence{Set{}->union(()),true,Sequence{ 0 },1} ; for v : a do ( var i : OclAny := null; var k : OclAny := null; Sequence{i,k} := Sequence{0,qlen} ; while k do ( var v2 : OclAny := v + Q[i+1] ; var k : OclAny := null; var i : OclAny := null; Sequence{k,i} := Sequence{k - 1,i + 1} ; if v2 = ans then ( var f : boolean := false ; break ) else skip ; if (v2->compareTo(ans)) < 0 & (S)->excludes(v2) then ( execute ((v2) : S) ; execute ((v2) : Q) ; qlen := qlen + 1 ) else skip)) ; if f then ( while true do ( ans := ans - 1 ; if ans = 0 then ( break ) else skip ; if (S)->includes(ans) then ( break; ) else skip) ) else skip ; execute (s - 2 * ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break a=list(map(int,input().split())) b=sum(a) ans=b>>1 if ans in a : print(b-2*ans) continue c=[v for v in a if vtoInteger() ; if n = 0 then ( break ) else skip ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : OclAny := (a)->sum() ; var ans : int := b /(2->pow(1)) ; if (a)->includes(ans) then ( execute (b - 2 * ans)->display() ; continue ) else skip ; var c : Sequence := a->select(v | (v->compareTo(ans)) < 0)->collect(v | (v)) ; var s : OclAny := null; var f : OclAny := null; var q : OclAny := null; var qlen : OclAny := null; Sequence{s,f,q,qlen} := Sequence{Set{}->union(()),true,Sequence{ 0 },1} ; for v : c do ( var i : OclAny := null; var k : OclAny := null; Sequence{i,k} := Sequence{0,qlen} ; while k do ( var v2 : OclAny := v + q[i+1] ; var k : OclAny := null; var i : OclAny := null; Sequence{k,i} := Sequence{k - 1,i + 1} ; if v2 = ans then ( var f : boolean := false ; break ) else skip ; if (v2->compareTo(ans)) < 0 & (s)->excludes(v2) then ( execute ((v2) : s) ; execute ((v2) : q) ; qlen := qlen + 1 ) else skip)) ; if f then ( while true do ( ans := ans - 1 ; if ans = 0 then ( break ) else skip ; if (s)->includes(ans) then ( break ) else skip) ) else skip ; execute (b - 2 * ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): while True : n=int(input()) if n==0 : break alst=list(map(int,input().split())) s=sum(alst) alst=[a*2 for a in alst] lst=[-s] for a in alst : lst.extend([i+a for i in lst]) print(min(map(abs,lst))) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var alst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : OclAny := (alst)->sum() ; alst := alst->select(a | true)->collect(a | (a * 2)) ; var lst : Sequence := Sequence{ -s } ; for a : alst do ( lst := lst->union(lst->select(i | true)->collect(i | (i + a)))) ; execute (((lst)->collect( _x | (abs)->apply(_x) ))->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) n=N//2 S=N+(N % 2==0) groups=[[i,S-i]for i in range(1,n+1)] if N % 2==1 : groups.append([S]) ans=[] from itertools import* for g1,g2 in combinations(groups,2): for s,t in product(g1,g2): ans.append((s,t)) print(len(ans)) for s,t in ans : print(s,t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := N div 2 ; var S : int := N + (N mod 2 = 0) ; var groups : Sequence := Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | (Sequence{i}->union(Sequence{ S - i }))) ; if N mod 2 = 1 then ( execute ((Sequence{ S }) : groups) ) else skip ; var ans : Sequence := Sequence{} ; skip ; for _tuple : combinations(groups, 2) do (var _indx : int := 1; var g1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var g2 : OclAny := _tuple->at(_indx); for _tuple : product(g1, g2) do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); execute ((Sequence{s, t}) : ans))) ; execute ((ans)->size())->display() ; for _tuple : ans do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- 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(100000) 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(N): se=N+1 if N % 2==0 else N return list(filter(lambda x : x[0]+x[1]!=se,combinations(range(1,N+1),2))) def main(): N=read_int() E=slv(N) print(len(E)) for e in E : print('%d %d' % e) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(100000) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; (compound_stmt (decorator @ (dotted_name (name mt))) (funcdef def (name slv) ( (typedargslist (def_parameters (def_parameter (named_parameter (name N))))) ) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name se)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name N))) + (expr (atom (number (integer 1))))))) if (logical_test (comparison (comparison (expr (expr (atom (name N))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 0))))))) else (test (logical_test (comparison (expr (atom (name N))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name filter)) (trailer (arguments ( (arglist (argument (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (comparison (expr (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) + (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))) != (comparison (expr (atom (name se))))))))) , (argument (test (logical_test (comparison (expr (atom (name combinations)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name N))) + (expr (atom (number (integer 1)))))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ))))))))) ))))))))) )))))))))))))) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation read_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation read_int_n() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation read_float() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation read_float_n() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["double"])->apply(_x) )); operation read_str() : OclAny pre: true post: true activity: return input()->trim(); operation read_str_n() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["String"])->apply(_x) )); operation error_print(args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) execute ((argument * (test (logical_test (comparison (expr (atom (name args))))))))->display(); operation mt(f : OclAny) : OclAny pre: true post: true activity: skip ; skip ; return wrap; operation main() pre: true post: true activity: var N : OclAny := read_int() ; var E : OclAny := slv(N) ; execute ((E)->size())->display() ; for e : E do ( execute (StringLib.format('%d %d',e))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,tan,asin,acos,atan,radians,degrees,log2,gcd from itertools import accumulate,permutations,combinations,combinations_with_replacement,product,groupby from operator import itemgetter,mul from copy import deepcopy from string import ascii_lowercase,ascii_uppercase,digits from bisect import bisect,bisect_left,insort,insort_left from heapq import heappush,heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) def ZIP(n): return zip(*(MAP()for _ in range(n))) sys.setrecursionlimit(10**9) INF=float('inf') mod=10**9+7 from decimal import* N=INT() if N % 2==0 : print(N*(N-1)//2-N//2) for i,j in combinations(range(1,N+1),2): if i+j==N+1 : continue print(i,j) else : print(N*(N-1)//2-(N-1)//2) for i,j in combinations(range(1,N+1),2): if i+j==N : continue print(i,j) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; skip ; var N : OclAny := INT() ; if N mod 2 = 0 then ( execute (N * (N - 1) div 2 - N div 2)->display() ; for _tuple : combinations(Integer.subrange(1, N + 1-1), 2) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if i + j = N + 1 then ( continue ) else skip ; execute (i)->display()) ) else ( execute (N * (N - 1) div 2 - (N - 1) div 2)->display() ; for _tuple : combinations(Integer.subrange(1, N + 1-1), 2) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if i + j = N then ( continue ) else skip ; execute (i)->display()) ); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ZIP(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))`third->at(_indx)} ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) sm=n*(n+1)//2 if n==3 : print(2) print(1,3) print(2,3) elif n==4 : print(4) print(1,2) print(1,3) print(2,4) print(3,4) elif n % 2 : m=(n-1)//2 print(m*4) a=[[i,n-i-2]for i in range(m)] for i in range(m-1): for j in range(2): for k in range(2): print(a[i][j]+1,a[i+1][k]+1) for i in range(2): print(a[m-1][i]+1,n) print(n,a[0][i]+1) else : print(n*2) a=[[i,n-i-1]for i in range(n//2)] for i in range(n//2): for j in range(2): for k in range(2): print(a[i][j]+1,a[(i+1)%(n//2)][k]+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sm : int := n * (n + 1) div 2 ; if n = 3 then ( execute (2)->display() ; execute (1)->display() ; execute (2)->display() ) else (if n = 4 then ( execute (4)->display() ; execute (1)->display() ; execute (1)->display() ; execute (2)->display() ; execute (3)->display() ) else (if n mod 2 then ( var m : int := (n - 1) div 2 ; execute (m * 4)->display() ; var a : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (Sequence{i}->union(Sequence{ n - i - 2 }))) ; for i : Integer.subrange(0, m - 1-1) do ( for j : Integer.subrange(0, 2-1) do ( for k : Integer.subrange(0, 2-1) do ( execute (a[i+1][j+1] + 1)->display()))) ; for i : Integer.subrange(0, 2-1) do ( execute (a[m - 1+1][i+1] + 1)->display() ; execute (n)->display()) ) else ( execute (n * 2)->display() ; a := Integer.subrange(0, n div 2-1)->select(i | true)->collect(i | (Sequence{i}->union(Sequence{ n - i - 1 }))) ; for i : Integer.subrange(0, n div 2-1) do ( for j : Integer.subrange(0, 2-1) do ( for k : Integer.subrange(0, 2-1) do ( execute (a[i+1][j+1] + 1)->display()))) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def examB(): N=I() M=(N-1)**2//2 ans=[] for i in range(1,N+1): if N % 2==0 : for j in range(i+1,N+1): if i+j!=N+1 : ans.append([i,j]) else : for j in range(i+1,N): if i+j!=N : ans.append([i,j]) if i!=N : ans.append([i,N]) print(M) for v in ans : print(" ".join(map(str,v))) from string import digits import sys,copy,bisect,itertools,math from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() mod=10**9+7 inf=float('inf') examB() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; examB(); operation examB() pre: true post: true activity: var N : OclAny := I() ; var M : int := ((N - 1))->pow(2) div 2 ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(1, N + 1-1) do ( if N mod 2 = 0 then ( for j : Integer.subrange(i + 1, N + 1-1) do ( if i + j /= N + 1 then ( execute ((Sequence{i}->union(Sequence{ j })) : ans) ) else skip) ) else ( for j : Integer.subrange(i + 1, N-1) do ( if i + j /= N then ( execute ((Sequence{i}->union(Sequence{ j })) : ans) ) else skip) ; if i /= N then ( execute ((Sequence{i}->union(Sequence{ N })) : ans) ) else skip )) ; execute (M)->display() ; for v : ans do ( execute (StringLib.sumStringsWithSeparator(((v)->collect( _x | (OclType["String"])->apply(_x) )), " "))->display()); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation SI() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import deque input=sys.stdin.readline n,m=map(int,input().split()) G=[[]for _ in range(3*(n+1))] for _ in range(m): u,v=map(int,input().split()) G[3*u].append(3*v+2) G[3*u+1].append(3*v) G[3*u+2].append(3*v+1) s,t=map(int,input().split()) Q=deque() Q.append(s*3) D=[-3 for _ in range(3*(n+1))] D[s*3]=0 while Q : q=Q.popleft() for i in G[q]: if D[i]==-3 : D[i]=D[q]+1 Q.append(i) print(D[t*3]//3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var G : Sequence := Integer.subrange(0, 3 * (n + 1)-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, m-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (number (integer 3)))) * (expr (atom (name u))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (number (integer 3)))) * (expr (atom (name v)))) + (expr (atom (number (integer 2)))))))))) )))) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (number (integer 3)))) * (expr (atom (name u)))) + (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (number (integer 3)))) * (expr (atom (name v))))))))) )))) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (number (integer 3)))) * (expr (atom (name u)))) + (expr (atom (number (integer 2)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (number (integer 3)))) * (expr (atom (name v)))) + (expr (atom (number (integer 1)))))))))) ))))) ; var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var Q : Sequence := () ; execute ((s * 3) : Q) ; var D : Sequence := Integer.subrange(0, 3 * (n + 1)-1)->select(_anon | true)->collect(_anon | (-3)) ; D[s * 3+1] := 0 ; while Q do ( var q : OclAny := Q->first() ; Q := Q->tail() ; for i : G[q+1] do ( if D[i+1] = -3 then ( D[i+1] := D[q+1] + 1 ; execute ((i) : Q) ) else skip)) ; execute (D[t * 3+1] div 3)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) d=int(input()) e=int(input()) e*=5 mi=n % d while(n-e)>=0 : n-=e mi=min(mi,n % d) print(mi) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var e : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; e := e * 5 ; var mi : int := n mod d ; while (n - e) >= 0 do ( n := n - e ; mi := Set{mi, n mod d}->min()) ; execute (mi)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CountOfOddSum(a,n): dp=[[0 for i in range(2)]for i in range(n)] cnt=[[0 for i in range(2)]for i in range(n)] for i in range(n): for j in range(2): if(a[i][j]% 2==0): cnt[i][0]+=1 else : cnt[i][1]+=1 dp[0][0]=cnt[0][0] dp[0][1]=cnt[0][1] for i in range(1,n): dp[i][0]=(dp[i-1][0]*cnt[i][0]+dp[i-1][1]*cnt[i][1]) dp[i][1]=(dp[i-1][0]*cnt[i][1]+dp[i-1][1]*cnt[i][0]) return dp[n-1][1] a=[[1,2],[3,6]] n=len(a) ans=CountOfOddSum(a,n) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{Sequence{1}->union(Sequence{ 2 })}->union(Sequence{ Sequence{3}->union(Sequence{ 6 }) }) ; n := (a)->size() ; var ans : OclAny := CountOfOddSum(a, n) ; execute (ans)->display(); operation CountOfOddSum(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, 2-1)->select(i | true)->collect(i | (0)))) ; var cnt : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, 2-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, 2-1) do ( if (a[i+1][j+1] mod 2 = 0) then ( cnt[i+1]->first() := cnt[i+1]->first() + 1 ) else ( cnt[i+1][1+1] := cnt[i+1][1+1] + 1 ))) ; dp->first()->first() := cnt->first()->first() ; dp->first()[1+1] := cnt->first()[1+1] ; for i : Integer.subrange(1, n-1) do ( dp[i+1]->first() := (dp[i - 1+1]->first() * cnt[i+1]->first() + dp[i - 1+1][1+1] * cnt[i+1][1+1]) ; dp[i+1][1+1] := (dp[i - 1+1]->first() * cnt[i+1][1+1] + dp[i - 1+1][1+1] * cnt[i+1]->first())) ; return dp[n - 1+1][1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def WindowtoViewport(x_w,y_w,x_wmax,y_wmax,x_wmin,y_wmin,x_vmax,y_vmax,x_vmin,y_vmin): sx=(x_vmax-x_vmin)/(x_wmax-x_wmin) sy=(y_vmax-y_vmin)/(y_wmax-y_wmin) x_v=x_vmin+((x_w-x_wmin)*sx) y_v=y_vmin+((y_w-y_wmin)*sy) print("The point on viewport:(",int(x_v),",",int(y_v),")") if __name__=='__main__' : x_wmax=80 y_wmax=80 x_wmin=20 y_wmin=40 x_vmax=60 y_vmax=60 x_vmin=30 y_vmin=40 x_w=30 y_w=80 WindowtoViewport(30,80,80,80,20,40,60,60,30,40) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( x_wmax := 80 ; y_wmax := 80 ; x_wmin := 20 ; y_wmin := 40 ; x_vmax := 60 ; y_vmax := 60 ; x_vmin := 30 ; y_vmin := 40 ; x_w := 30 ; y_w := 80 ; WindowtoViewport(30, 80, 80, 80, 20, 40, 60, 60, 30, 40) ) else skip; operation WindowtoViewport(x_w : OclAny, y_w : OclAny, x_wmax : OclAny, y_wmax : OclAny, x_wmin : OclAny, y_wmin : OclAny, x_vmax : OclAny, y_vmax : OclAny, x_vmin : OclAny, y_vmin : OclAny) pre: true post: true activity: var sx : double := (x_vmax - x_vmin) / (x_wmax - x_wmin) ; var sy : double := (y_vmax - y_vmin) / (y_wmax - y_wmin) ; var x_v : OclAny := x_vmin + ((x_w - x_wmin) * sx) ; var y_v : OclAny := y_vmin + ((y_w - y_wmin) * sy) ; execute ("The point on viewport:(")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def powerSet(string,index,curr): if index==len(string): print(curr) return powerSet(string,index+1,curr+string[index]) powerSet(string,index+1,curr) if __name__=="__main__" : s1="abc" index=0 curr="" powerSet(s1,index,curr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var s1 : String := "abc" ; index := 0 ; curr := "" ; powerSet(s1, index, curr) ) else skip; operation powerSet(string : OclAny, index : OclAny, curr : OclAny) pre: true post: true activity: if index = (string)->size() then ( execute (curr)->display() ; return ) else skip ; powerSet(string, index + 1, curr + string[index+1]) ; powerSet(string, index + 1, curr); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inputNum=input().split() numPeople=int(inputNum[0]) games=int(inputNum[1]) i=0 powers=input().split() j=0 while jnumPeople : print(max(powers)) else : while queue[0][1]!=games : if queue[0][0]>queue[1][0]: queue.append([queue[1][0],queue[1][1]]) queue[0][1]+=1 queue.pop(1) else : queue.append([queue[0][0],queue[0][1]]) queue[1][1]+=1 queue.pop(0) print(queue[0][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inputNum : OclAny := input().split() ; var numPeople : int := ("" + ((inputNum->first())))->toInteger() ; var games : int := ("" + ((inputNum[1+1])))->toInteger() ; var i : int := 0 ; var powers : OclAny := input().split() ; var j : int := 0 ; while (j->compareTo(numPeople)) < 0 do ( powers[j+1] := ("" + ((powers[j+1])))->toInteger() ; j := j + 1) ; var queue : Sequence := Sequence{} ; while (i->compareTo(numPeople)) < 0 do ( execute ((Sequence{powers[i+1]}->union(Sequence{ 0 })) : queue) ; i := i + 1) ; if (games->compareTo(numPeople)) > 0 then ( execute ((powers)->max())->display() ) else ( while queue->first()[1+1] /= games do ( if (queue->first()->first()->compareTo(queue[1+1]->first())) > 0 then ( execute ((Sequence{queue[1+1]->first()}->union(Sequence{ queue[1+1][1+1] })) : queue) ; queue->first()[1+1] := queue->first()[1+1] + 1 ; queue := queue->excludingAt(1+1) ) else ( execute ((Sequence{queue->first()->first()}->union(Sequence{ queue->first()[1+1] })) : queue) ; queue[1+1][1+1] := queue[1+1][1+1] + 1 ; queue := queue->excludingAt(0+1) )) ; execute (queue->first()->first())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) l=list(map(int,input().split())) if l[0]==max(l[0 : min(k+1,len(l))]): print(l[0]) else : for i in range(1,n): if l[i]==max(l[i : min(i+k,len(l))]): print(l[i]) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if l->first() = (l.subrange(0+1, Set{k + 1, (l)->size()}->min()))->max() then ( execute (l->first())->display() ) else ( for i : Integer.subrange(1, n-1) do ( if l[i+1] = (l.subrange(i+1, Set{i + k, (l)->size()}->min()))->max() then ( execute (l[i+1])->display() ; break ) else skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) g=map(int,input().split()) L=list(g) if L[0]==max(L[0 : min(k+1,len(L))]): print(L[0]) else : for i in range(1,n): if L[i]==max(L[i : min(i+k,len(L))]): print(L[i]) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var g : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var L : Sequence := (g) ; if L->first() = (L.subrange(0+1, Set{k + 1, (L)->size()}->min()))->max() then ( execute (L->first())->display() ) else ( for i : Integer.subrange(1, n-1) do ( if L[i+1] = (L.subrange(i+1, Set{i + k, (L)->size()}->min()))->max() then ( execute (L[i+1])->display() ; break ) else skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=0 s=list(map(int,input().split())) n=list(map(int,input().split())) b=n[0] for i in range(1,s[0]): if(c>=s[1]): break if(b>n[i]): c+=1 else : c=1 b=n[i] print(b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : int := 0 ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : OclAny := n->first() ; for i : Integer.subrange(1, s->first()-1) do ( if ((c->compareTo(s[1+1])) >= 0) then ( break ) else skip ; if ((b->compareTo(n[i+1])) > 0) then ( c := c + 1 ) else ( c := 1 ; b := n[i+1] )) ; execute (b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) v=list(map(int,input().split())) occ=0 pre=v[0] for i in range(1,n): if pre>v[i]: occ+=1 else : pre=v[i] occ=1 if occ==k : break print(pre) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var v : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var occ : int := 0 ; var pre : OclAny := v->first() ; for i : Integer.subrange(1, n-1) do ( if (pre->compareTo(v[i+1])) > 0 then ( occ := occ + 1 ) else ( pre := v[i+1] ; occ := 1 ) ; if occ = k then ( break ) else skip) ; execute (pre)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,next=None,data=None): self.next=next self.data=data def push(head_ref,new_data): new_node=Node() new_node.data=new_data new_node.next=(head_ref) (head_ref)=new_node return head_ref def getCount(head): count=0 current=head while(current!=None): count=count+1 current=current.next return count def getNth(head,n): curr=head i=0 while(i0): print(stk[-1].data,end=" ") stk.pop() print(" ") head=None head=push(head,5) head=push(head,4) head=push(head,3) head=push(head,2) head=push(head,1) printReverse(head) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute next : OclAny := next; attribute data : OclAny := data; operation initialise(next : OclAny,data : OclAny) : Node pre: true post: true activity: self.next := next ; self.data := data; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var (head_ref) : OclAny := new_node; operation push(head_ref : OclAny, new_data : OclAny) pre: true post: true activity: var new_node : Node := (Node.newNode()).initialise() ; new_node.data := new_data ; new_node.next := (head_ref); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def findAndSum(arr,n): Sum=0 mul=1 for i in range(30): count_on=0 l=0 for j in range(n): if((arr[j]&(1<0): if(count_on): l+=1 else : count_on=1 l+=1 elif(count_on): Sum+=((mul*l*(l+1))//2) count_on=0 l=0 if(count_on): Sum+=((mul*l*(l+1))//2) count_on=0 l=0 mul*=2 return Sum arr=[7,1,1,5] n=len(arr) print(findAndSum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{7}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 5 }))) ; n := (arr)->size() ; execute (findAndSum(arr, n))->display(); operation findAndSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var Sum : int := 0 ; var mul : int := 1 ; for i : Integer.subrange(0, 30-1) do ( var count_on : int := 0 ; var l : int := 0 ; for j : Integer.subrange(0, n-1) do ( if ((MathLib.bitwiseAnd(arr[j+1], (1 * (2->pow(i))))) > 0) then ( if (count_on) then ( l := l + 1 ) else ( count_on := 1 ; l := l + 1 ) ) else (if (count_on) then ( Sum := Sum + ((mul * l * (l + 1)) div 2) ; count_on := 0 ; l := 0 ) else skip)) ; if (count_on) then ( Sum := Sum + ((mul * l * (l + 1)) div 2) ; count_on := 0 ; l := 0 ) else skip ; mul := mul * 2) ; return Sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isValid(string,length): for i in range(1,length): if string[i]==string[i-1]: return False return True if __name__=="__main__" : string="0110" length=len(string) if isValid(string,length): print("Valid") else : print("Invalid") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( string := "0110" ; length := (string)->size() ; if isValid(string, length) then ( execute ("Valid")->display() ) else ( execute ("Invalid")->display() ) ) else skip; operation isValid(string : OclAny, length : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(1, length-1) do ( if string[i+1] = string[i - 1+1] then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) d=int(input()) e=int(input()) k=0 answer=n while k*5*e<=n : answer=min(answer,(n-k*5*e)% d) k+=1 print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var e : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := 0 ; var answer : int := n ; while (k * 5 * e->compareTo(n)) <= 0 do ( answer := Set{answer, (n - k * 5 * e) mod d}->min() ; k := k + 1) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq as hq def bfs(connections : list,s,t): inf=float('inf') costs=[[inf,inf,inf]for i in connections] visited=[[False,False,False]for i in connections] costs[s][0]=0 q=[] hq.heappush(q,(0,0,s)) while q : cost,step,node=hq.heappop(q) if visited[node][step]: continue visited[node][step]=True for target in connections[node]: if costs[target][(step+1)% 3]>cost+1 : costs[target][(step+1)% 3]=cost+1 hq.heappush(q,(cost+1,(step+1)% 3,target)) ans=costs[t][0] if ans==inf : print(-1) else : print(ans//3) def resolve(): N,M=map(int,input().split()) connections=[[]for i in range(N)] for i in range(M): u,v=map(int,input().split()) connections[u-1].append(v-1) S,T=map(int,input().split()) bfs(connections,S-1,T-1) if __name__=="__main__" : resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( resolve() ) else skip; operation bfs(connections : Sequence(OclAny), s : OclAny, t : OclAny) pre: true post: true activity: var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; var costs : Sequence := connections->select(i | true)->collect(i | (Sequence{Math_PINFINITY}->union(Sequence{Math_PINFINITY}->union(Sequence{ Math_PINFINITY })))) ; var visited : Sequence := connections->select(i | true)->collect(i | (Sequence{false}->union(Sequence{false}->union(Sequence{ false })))) ; costs[s+1]->first() := 0 ; var q : Sequence := Sequence{} ; hq.heappush(q, Sequence{0, 0, s}) ; while q do ( var cost : OclAny := null; var step : OclAny := null; var node : OclAny := null; Sequence{cost,step,node} := hq.heappop(q) ; if visited[node+1][step+1] then ( continue ) else skip ; visited[node+1][step+1] := true ; for target : connections[node+1] do ( if (costs[target+1][(step + 1) mod 3+1]->compareTo(cost + 1)) > 0 then ( costs[target+1][(step + 1) mod 3+1] := cost + 1 ; hq.heappush(q, Sequence{cost + 1, (step + 1) mod 3, target}) ) else skip)) ; var ans : OclAny := costs[t+1]->first() ; if ans = Math_PINFINITY then ( execute (-1)->display() ) else ( execute (ans div 3)->display() ); operation resolve() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var connections : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, M-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name connections)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name u))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1)))))))))) ))))) ; var S : OclAny := null; var T : OclAny := null; Sequence{S,T} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; bfs(connections, S - 1, T - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import pow def __builtin_popcount(n): count=0 while n>0 : if n % 2==1 : count+=1 n=n//2 return count def count_values(n): set_bits=__builtin_popcount(n) print(int(pow(2,set_bits))) if __name__=="__main__" : n=27 count_values(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( n := 27 ; count_values(n) ) else skip; operation __builtin_popcount(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while n > 0 do ( if n mod 2 = 1 then ( count := count + 1 ) else skip ; n := n div 2) ; return count; operation count_values(n : OclAny) pre: true post: true activity: var set_bits : OclAny := __builtin_popcount(n) ; execute (("" + (((2)->pow(set_bits))))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) sa=sorted(a) r=[] su=0 for i in range(n): su+=sa[i] r.append(su) ans=1 for i in range(n-1): if(r[~ i-1]*2>=sa[~ i]): ans+=1 else : break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sa : Sequence := a->sort() ; var r : Sequence := Sequence{} ; var su : int := 0 ; for i : Integer.subrange(0, n-1) do ( su := su + sa[i+1] ; execute ((su) : r)) ; var ans : int := 1 ; for i : Integer.subrange(0, n - 1-1) do ( if ((r[MathLib.bitwiseNot(i) - 1+1] * 2->compareTo(sa[MathLib.bitwiseNot(i)+1])) >= 0) then ( ans := ans + 1 ) else ( break )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate n=int(input()) a=sorted(list(map(int,input().split()))) a2=list(accumulate([2*i for i in a])) l=[i+1 for i in range(n)] t=0 for j,k,i in zip(a[1 :],a2,l): if ktoInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var a2 : Sequence := (accumulate(a->select(i | true)->collect(i | (2 * i)))) ; var l : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i + 1)) ; var t : int := 0 ; for _tuple : Integer.subrange(1, a->tail()->size())->collect( _indx | Sequence{a->tail()->at(_indx), a2->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); if (k->compareTo(j)) < 0 then ( t := i ) else skip) ; execute (n - t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) *A,=map(int,input().split()) A.sort() ans=1 S=0 i=0 while i+1=A[i+1]: ans+=1 else : ans=1 i+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (testlist_star_expr (star_expr * (expr (atom (name A)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name A)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; A := A->sort() ; var ans : int := 1 ; var S : int := 0 ; var i : int := 0 ; while (i + 1->compareTo(N)) < 0 do ( S := S + A[i+1] ; if (2 * S->compareTo(A[i + 1+1])) >= 0 then ( ans := ans + 1 ) else ( ans := 1 ) ; i := i + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline N=int(readline()) A=list(map(int,readline().split())) A=sorted(A) cur=0 ng=0 for i in range(N): if A[i]>cur*2 : ng=i cur+=A[i] print(N-ng) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var N : int := ("" + ((readline())))->toInteger() ; var A : Sequence := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ; A := A->sort() ; var cur : int := 0 ; var ng : int := 0 ; for i : Integer.subrange(0, N-1) do ( if (A[i+1]->compareTo(cur * 2)) > 0 then ( ng := i ) else skip ; cur := cur + A[i+1]) ; execute (N - ng)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect n=int(input()) a=sorted(list(map(int,input().split()))) a_t=[0] for i in range(n): a_t.append(a[i]+a_t[i]) a_t=a_t[1 :] ans=0 mi=0 for i in range(n): index=bisect.bisect_right(a,a[i]*2)-1 if index==n-1 : if not mi : mi=i for i in range(n-1,-1,-1): index=bisect.bisect_right(a,a_t[i]*2)-1 if index>=mi : mi=i ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var a_t : Sequence := Sequence{ 0 } ; for i : Integer.subrange(0, n-1) do ( execute ((a[i+1] + a_t[i+1]) : a_t)) ; a_t := a_t->tail() ; var ans : int := 0 ; var mi : int := 0 ; for i : Integer.subrange(0, n-1) do ( var index : double := bisect.bisect_right(a, a[i+1] * 2) - 1 ; if index = n - 1 then ( if not(mi) then ( mi := i ) else skip ) else skip) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( index := bisect.bisect_right(a, a_t[i+1] * 2) - 1 ; if (index->compareTo(mi)) >= 0 then ( mi := i ; ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math phi=0.5*(1.0+math.sqrt(5.0)) def countWinners(minA,maxA,minB,maxB): result=0 numberOfBs=maxB-minB+1 for A in range(minA,maxA+1): minLosingB=math.ceil(A/phi) maxLosingB=math.floor(A*phi) loosers=min(maxB,maxLosingB)-max(minB,minLosingB)+1 if loosers<0 : loosers=0 result+=numberOfBs-loosers return result def invalidInput(): sys.exit('Invalid input') firstLine=next(sys.stdin) numbers=[int(s)for s in firstLine.split()] if len(numbers)!=1 : invalidInput() T=numbers[0] for caseNumber in range(1,T+1): thisLine=next(sys.stdin) numbers=[int(s)for s in thisLine.split()] if len(numbers)!=4 : invalidInput() (minA,maxA,minB,maxB)=tuple(numbers) assert(1<=minA<=maxA<=10**6) assert(1<=minB<=maxB<=10**6) result=countWinners(minA,maxA,minB,maxB) print('Case #{0}:{1}'.format(caseNumber,result)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var phi : double := 0.5 * (1.0 + (5.0)->sqrt()) ; skip ; skip ; var firstLine : OclAny := (OclFile["System.in"]).next() ; var numbers : Sequence := firstLine.split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; if (numbers)->size() /= 1 then ( invalidInput() ) else skip ; var T : OclAny := numbers->first() ; for caseNumber : Integer.subrange(1, T + 1-1) do ( var thisLine : OclAny := (OclFile["System.in"]).next() ; numbers := thisLine.split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; if (numbers)->size() /= 4 then ( invalidInput() ) else skip) ; var Sequence{minA, maxA, minB, maxB} : Sequence := (numbers); operation countWinners(minA : OclAny, maxA : OclAny, minB : OclAny, maxB : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; var numberOfBs : double := maxB - minB + 1 ; for A : Integer.subrange(minA, maxA + 1-1) do ( var minLosingB : double := (A / phi)->ceil() ; var maxLosingB : double := (A * phi)->floor() ; var loosers : double := Set{maxB, maxLosingB}->min() - Set{minB, minLosingB}->max() + 1 ; if loosers < 0 then ( loosers := 0 ) else skip ; result := result + numberOfBs - loosers) ; return result; operation invalidInput() pre: true post: true activity: sys.exit('Invalid input'); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) def win(x,y): if x=2*y : return True return not win(y,x-y) for C in range(1,T+1): A1,A2,B1,B2=input().split(' ') A1,A2,B1,B2=int(A1),int(A2),int(B1),int(B2) cnt=0 for A in range(A1,A2+1): for B in range(B1,B2+1): if win(A,B): cnt+=1 print('Case #%d: %s' %(C,cnt)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; for C : Integer.subrange(1, T + 1-1) do ( var A1 : OclAny := null; var A2 : OclAny := null; var B1 : OclAny := null; var B2 : OclAny := null; Sequence{A1,A2,B1,B2} := input().split(' ') ; var A1 : OclAny := null; var A2 : OclAny := null; var B1 : OclAny := null; var B2 : OclAny := null; Sequence{A1,A2,B1,B2} := Sequence{("" + ((A1)))->toInteger(),("" + ((A2)))->toInteger(),("" + ((B1)))->toInteger(),("" + ((B2)))->toInteger()} ; var cnt : int := 0 ; for A : Integer.subrange(A1, A2 + 1-1) do ( for B : Integer.subrange(B1, B2 + 1-1) do ( if win(A, B) then ( cnt := cnt + 1 ) else skip)) ; execute (StringLib.format('Case #%d: %s',Sequence{C, cnt}))->display()); operation win(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (x->compareTo(y)) < 0 then ( Sequence{x,y} := Sequence{y,x} ) else skip ; if x = y then ( return false ) else skip ; if (x->compareTo(2 * y)) >= 0 then ( return true ) else skip ; return not(win(y, x - y)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def readline(): return next(sys.stdin).strip() def readvals(t): return map(t,readline().split()) wcache={} def winning(a,b): global wcache if a==b : return False a,b=sorted((a,b)) if b % a==0 : return True if(a,b)in wcache : return wcache[a,b] res=any(not winning(a,b-i*a)for i in reversed(range(1,b//a+1))) if len(wcache)>10000000 : wcache={} wcache[a,b]=res return res ncases=int(readline()) for caseno in range(ncases): a1,a2,b1,b2=readvals(int) res=sum(winning(i,j)for i in range(a1,a2+1)for j in range(b1,b2+1)) print('Case #{}:{}'.format(caseno+1,res)) sys.stdout.flush() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute wcache : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; var wcache : OclAny := Set{} ; skip ; var ncases : int := ("" + ((readline())))->toInteger() ; for caseno : Integer.subrange(0, ncases-1) do ( var a1 : OclAny := null; var a2 : OclAny := null; var b1 : OclAny := null; var b2 : OclAny := null; Sequence{a1,a2,b1,b2} := readvals(OclType["int"]) ; res := ((argument (test (logical_test (comparison (expr (atom (name winning)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (name j)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a1))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name a2))) + (expr (atom (number (integer 1)))))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b1))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name b2))) + (expr (atom (number (integer 1)))))))))) )))))))))))->sum() ; execute (StringLib.interpolateStrings('Case #{}:{}', Sequence{caseno + 1, res}))->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( ))))); operation readline() : OclAny pre: true post: true activity: return next(OclFile["System.in"])->trim(); operation readvals(t : OclAny) : OclAny pre: true post: true activity: return (readline().split())->collect( _x | (t)->apply(_x) ); operation winning(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: skip ; if a = b then ( return false ) else skip ; Sequence{a,b} := Sequence{a, b}->sort() ; if b mod a = 0 then ( return true ) else skip ; if (wcache)->includes(Sequence{a, b}) then ( return wcache[a+1][b+1] ) else skip ; var res : boolean := ((argument (test (logical_test not (logical_test (comparison (expr (atom (name winning)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (expr (atom (name i))) * (expr (atom (name a)))))))))) )))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name reversed)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (expr (atom (name b))) // (expr (atom (name a)))) + (expr (atom (number (integer 1)))))))))) ))))))))) )))))))))->exists( _x | _x = true ) ; if (wcache)->size() > 10000000 then ( wcache := Set{} ) else skip ; wcache[a+1][b+1] := res ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) d=int(input()) e=int(input()) k=0 a=n while 5*k*e<=n : a=min(a,(n-k*5*e)% d) k+=1 print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var e : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := 0 ; var a : int := n ; while (5 * k * e->compareTo(n)) <= 0 do ( a := Set{a, (n - k * 5 * e) mod d}->min() ; k := k + 1) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- TASK="C" print("Precalculation...") NUM=1000001 top=[0]*NUM btm=[0]*NUM cbtm=0 for i in range(1,NUM): if top[cbtm]display() ; var NUM : int := 1000001 ; var top : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, NUM) ; var btm : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, NUM) ; var cbtm : int := 0 ; for i : Integer.subrange(1, NUM-1) do ( if (top[cbtm+1]->compareTo(i)) < 0 then ( cbtm := cbtm + 1 ) else skip ; btm[i+1] := cbtm ; top[i+1] := cbtm + i) ; execute ("Precalculation done.")->display() ; try (var infile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(TASK + ".in")); try (var outfile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(TASK + ".out")); var cases : int := ("" + ((infile.readLine())))->toInteger() ; for ncase : Integer.subrange(0, cases-1) do ( var A1 : OclAny := null; var A2 : OclAny := null; var B1 : OclAny := null; var B2 : OclAny := null; Sequence{A1,A2,B1,B2} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name infile)) (trailer . (name readline) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var lost : int := 0 ; execute ("Now:")->display() ; for i : Integer.subrange(A1, A2 + 1-1) do ( var b : OclAny := Set{B1, btm[i - 1+1] + 1}->max() ; var t : OclAny := Set{B2, top[i - 1+1] + 1}->min() ; lost := lost + Set{0, t - b + 1}->max()) ; outfile.write(StringLib.interpolateStrings("Case #{nc}:{data}\n", Sequence{(argument (test (logical_test (comparison (expr (atom (name nc)))))) = (test (logical_test (comparison (expr (expr (atom (name ncase))) + (expr (atom (number (integer 1))))))))), (argument (test (logical_test (comparison (expr (atom (name data)))))) = (test (logical_test (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name A2))) - (expr (atom (name A1)))) + (expr (atom (number (integer 1))))))))) ))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name B2))) - (expr (atom (name B1)))) + (expr (atom (number (integer 1))))))))) )))) - (expr (atom (name lost))))))))})))) catch (_e : OclException) do skip) catch (_e : OclException) do skip ; execute ("Ready")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import deque from collections import defaultdict def main(): mod=1000000007 inf=float('inf') sys.setrecursionlimit(10**6) def input(): return sys.stdin.readline().rstrip() def ii(): return int(input()) def mi(): return map(int,input().split()) def mi_0(): return map(lambda x : int(x)-1,input().split()) def lmi(): return list(map(int,input().split())) def lmi_0(): return list(map(lambda x : int(x)-1,input().split())) def li(): return list(input()) n,m=mi() adj=[[]for _ in range(n*3)] for _ in range(m): a,b=mi_0() adj[a*3].append(b*3+1) adj[a*3+1].append(b*3+2) adj[a*3+2].append(b*3) start,goal=mi_0() start*=3 goal*=3 q=deque([(start,0)]) visited=[False]*(n*3) while q : u,dist=q.popleft() if dist>3*n : break if u==goal : assert(dist % 3==0) print(dist//3) return if not visited[u]: visited[u]=True for v in adj[u]: if not visited[v]: q.append((v,dist+1)) print(-1) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var mod : int := 1000000007 ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; sys.setrecursionlimit((10)->pow(6)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := mi() ; var adj : Sequence := Integer.subrange(0, n * 3-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := mi_0() ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name a))) * (expr (atom (number (integer 3)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name b))) * (expr (atom (number (integer 3))))) + (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name a))) * (expr (atom (number (integer 3))))) + (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name b))) * (expr (atom (number (integer 3))))) + (expr (atom (number (integer 2)))))))))) )))) ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name a))) * (expr (atom (number (integer 3))))) + (expr (atom (number (integer 2)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name b))) * (expr (atom (number (integer 3)))))))))) ))))) ; var start : OclAny := null; var goal : OclAny := null; Sequence{start,goal} := mi_0() ; start := start * 3 ; goal := goal * 3 ; var q : Sequence := (Sequence{ Sequence{start, 0} }) ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (n * 3)) ; while q do ( var u : OclAny := null; var dist : OclAny := null; Sequence{u,dist} := q->first() ; q := q->tail() ; if (dist->compareTo(3 * n)) > 0 then ( break ) else skip ; if u = goal then ( assert (dist mod 3 = 0) do "assertion failed" ; execute (dist div 3)->display() ; return ) else skip ; if not(visited[u+1]) then ( visited[u+1] := true ; for v : adj[u+1] do ( if not(visited[v+1]) then ( execute ((Sequence{v, dist + 1}) : q) ) else skip) ) else skip) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() count4=count7=0 for c in s : if c=='4' : count4+=1 elif c=='7' : count7+=1 if count4==0 and count7==0 : print(-1) elif count4>=count7 : print(4) else : print(7) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var count4 : OclAny := 0; var count7 : int := 0 ; for c : s->characters() do ( if c = '4' then ( count4 := count4 + 1 ) else (if c = '7' then ( count7 := count7 + 1 ) else skip)) ; if count4 = 0 & count7 = 0 then ( execute (-1)->display() ) else (if (count4->compareTo(count7)) >= 0 then ( execute (4)->display() ) else ( execute (7)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() count4=count7=0 for c in s : if c=='4' : count4+=1 elif c=='7' : count7+=1 if count4==0 and count7==0 : print(-1) elif count4>=count7 : print(4) else : print(7) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var count4 : OclAny := 0; var count7 : int := 0 ; for c : s->characters() do ( if c = '4' then ( count4 := count4 + 1 ) else (if c = '7' then ( count7 := count7 + 1 ) else skip)) ; if count4 = 0 & count7 = 0 then ( execute (-1)->display() ) else (if (count4->compareTo(count7)) >= 0 then ( execute (4)->display() ) else ( execute (7)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() count4=count7=0 for c in s : if c=='4' : count4+=1 elif c=='7' : count7+=1 if count4==0 and count7==0 : print(-1) elif count4>=count7 : print(4) else : print(7) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var count4 : OclAny := 0; var count7 : int := 0 ; for c : s->characters() do ( if c = '4' then ( count4 := count4 + 1 ) else (if c = '7' then ( count7 := count7 + 1 ) else skip)) ; if count4 = 0 & count7 = 0 then ( execute (-1)->display() ) else (if (count4->compareTo(count7)) >= 0 then ( execute (4)->display() ) else ( execute (7)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() count4=count7=0 for c in s : if c=='4' : count4+=1 elif c=='7' : count7+=1 if count4==0 and count7==0 : print(-1) elif count4>=count7 : print(4) else : print(7) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var count4 : OclAny := 0; var count7 : int := 0 ; for c : s->characters() do ( if c = '4' then ( count4 := count4 + 1 ) else (if c = '7' then ( count7 := count7 + 1 ) else skip)) ; if count4 = 0 & count7 = 0 then ( execute (-1)->display() ) else (if (count4->compareTo(count7)) >= 0 then ( execute (4)->display() ) else ( execute (7)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() count4=count7=0 for c in s : if c=='4' : count4+=1 elif c=='7' : count7+=1 if count4==0 and count7==0 : print(-1) elif count4>=count7 : print(4) else : print(7) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var count4 : OclAny := 0; var count7 : int := 0 ; for c : s->characters() do ( if c = '4' then ( count4 := count4 + 1 ) else (if c = '7' then ( count7 := count7 + 1 ) else skip)) ; if count4 = 0 & count7 = 0 then ( execute (-1)->display() ) else (if (count4->compareTo(count7)) >= 0 then ( execute (4)->display() ) else ( execute (7)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def watering(): n,a,b=map(int,input().split()) s=list(map(int,input().split())) volume=s[0]*(a/b-1) rest_holes_sum=sum(s[1 :]) k=0 delta=volume-rest_holes_sum s_rest=sorted(s[1 :],reverse=True) while delta<0 : delta+=s_rest[k] k+=1 print(k) watering() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; watering(); operation watering() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var volume : double := s->first() * (a / b - 1) ; var rest_holes_sum : OclAny := (s->tail())->sum() ; var k : int := 0 ; var delta : double := volume - rest_holes_sum ; var s_rest : Sequence := s->tail()->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; while delta < 0 do ( delta := delta + s_rest[k+1] ; k := k + 1) ; execute (k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,A,B=[int(x)for x in str(input()).split(" ")] s=[int(x)for x in str(input()).split(" ")] S=sum(s) s1=s[0] s=s[1 :] s.sort(reverse=True) c=0 i=0 while(A*s1)/Sselect(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var s : Sequence := OclType["String"]((OclFile["System.in"]).readLine()).split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var S : OclAny := (s)->sum() ; var s1 : OclAny := s->first() ; s := s->tail() ; s := s->sort() ; var c : int := 0 ; var i : int := 0 ; while ((A * s1) / S->compareTo(B)) < 0 & (i->compareTo((s)->size())) < 0 do ( S := S - s[i+1] ; c := c + 1 ; i := i + 1) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=map(int,input().split()) pipe=list(map(int,input().split()[: n])) primeiro=pipe[0] pipe.pop(0) pipe.sort() bloqueados=0 atual_tam=primeiro for x in pipe : atual_tam=atual_tam+x atual_vol=int(a*primeiro/atual_tam) while(atual_volcollect( _x | (OclType["int"])->apply(_x) ) ; var pipe : Sequence := ((input().split().subrange(1,n))->collect( _x | (OclType["int"])->apply(_x) )) ; var primeiro : OclAny := pipe->first() ; pipe := pipe->excludingAt(0+1) ; pipe := pipe->sort() ; var bloqueados : int := 0 ; var atual_tam : OclAny := primeiro ; for x : pipe do ( atual_tam := atual_tam + x) ; var atual_vol : int := ("" + ((a * primeiro / atual_tam)))->toInteger() ; while ((atual_vol->compareTo(b)) < 0) do ( bloqueados := bloqueados + 1 ; atual_tam := atual_tam - pipe->at((atom - (number (integer 1)))+1) ; atual_vol := ("" + ((a * primeiro / atual_tam)))->toInteger()) ; execute (bloqueados)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) d=int(input()) e=int(input()) k=0 s=n min_e=5*e while k*min_e<=n : if((n-k*min_e)% d)toInteger() ; var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var e : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := 0 ; var s : int := n ; var min_e : int := 5 * e ; while (k * min_e->compareTo(n)) <= 0 do ( if (((n - k * min_e) mod d)->compareTo(s)) < 0 then ( s := ((n - k * min_e) mod d) ) else skip ; k := k + 1) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=map(int,input().split()) pipe=list(map(int,input().split()[: n])) primeiro=pipe[0] pipe.pop(0) pipe.sort() bloqueados=0 atual_tam=primeiro for x in pipe : atual_tam=atual_tam+x atual_vol=int(a*primeiro/atual_tam) while(atual_volcollect( _x | (OclType["int"])->apply(_x) ) ; var pipe : Sequence := ((input().split().subrange(1,n))->collect( _x | (OclType["int"])->apply(_x) )) ; var primeiro : OclAny := pipe->first() ; pipe := pipe->excludingAt(0+1) ; pipe := pipe->sort() ; var bloqueados : int := 0 ; var atual_tam : OclAny := primeiro ; for x : pipe do ( atual_tam := atual_tam + x) ; var atual_vol : int := ("" + ((a * primeiro / atual_tam)))->toInteger() ; while ((atual_vol->compareTo(b)) < 0) do ( bloqueados := bloqueados + 1 ; atual_tam := atual_tam - pipe->at((atom - (number (integer 1)))+1) ; atual_vol := ("" + ((a * primeiro / atual_tam)))->toInteger()) ; execute (bloqueados)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=map(int,input().split()) holes=[int(i)for i in input().split()] counter,total=0,0 for i in range(n): total+=holes[i] first=holes[0] holes.remove(holes[0]) holes.sort() holes.insert(0,first) for j in range(n-1,0,-1): if(first*a/total)>=b : break total-=holes[j] counter+=1 print(counter) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var holes : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var counter : OclAny := null; var total : OclAny := null; Sequence{counter,total} := Sequence{0,0} ; for i : Integer.subrange(0, n-1) do ( total := total + holes[i+1]) ; var first : OclAny := holes->first() ; execute ((holes->first()) /: holes) ; holes := holes->sort() ; holes := holes.insertAt(0+1, first) ; for j : Integer.subrange(0 + 1, n - 1)->reverse() do ( if ((first * a / total)->compareTo(b)) >= 0 then ( break ) else skip ; total := total - holes[j+1] ; counter := counter + 1) ; execute (counter)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=[int(i)for i in input().split()] UVm=[[int(i)for i in input().split()]for _ in range(M)] S,T=[int(i)for i in input().split()] graphs=[[]for _ in range(3*N)] dists=[-1 for _ in range(3*N)] for uv in UVm : u=uv[0]-1 v=uv[1]-1 graphs[u].append(v+N) graphs[u+N].append(v+2*N) graphs[u+2*N].append(v) from collections import deque que=deque() que.append(S-1) dists[S-1]=0 while len(que)>0 : nex=que.popleft() for edge in graphs[nex]: if dists[edge]!=-1 : continue que.append(edge) dists[edge]=dists[nex]+1 print(dists[T-1]//3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var UVm : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())))) ; var S : OclAny := null; var T : OclAny := null; Sequence{S,T} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var graphs : Sequence := Integer.subrange(0, 3 * N-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var dists : Sequence := Integer.subrange(0, 3 * N-1)->select(_anon | true)->collect(_anon | (-1)) ; for uv : UVm do ( var u : double := uv->first() - 1 ; var v : double := uv[1+1] - 1 ; (expr (atom (name graphs)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name v))) + (expr (atom (name N))))))))) )))) ; (expr (atom (name graphs)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name u))) + (expr (atom (name N))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name v))) + (expr (expr (atom (number (integer 2)))) * (expr (atom (name N)))))))))) )))) ; (expr (atom (name graphs)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name u))) + (expr (expr (atom (number (integer 2)))) * (expr (atom (name N)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) ))))) ; skip ; var que : Sequence := () ; execute ((S - 1) : que) ; dists[S - 1+1] := 0 ; while (que)->size() > 0 do ( var nex : OclAny := que->first() ; que := que->tail() ; for edge : graphs[nex+1] do ( if dists[edge+1] /= -1 then ( continue ) else skip ; execute ((edge) : que) ; dists[edge+1] := dists[nex+1] + 1)) ; execute (dists[T - 1+1] div 3)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def no_of_ways(a,n): count_0=0 count_1=0 for i in range(0,n): if(a[i]==0): count_0+=1 else : count_1+=1 if(count_1 % 2==0): return count_0 else : return count_1 if __name__=='__main__' : n=4 a1=[1,1,0,0] print(no_of_ways(a1,n)) n=5 a2=[1,1,1,0,0] print(no_of_ways(a2,n)) n=5 a3=[1,1,0,0,0] print(no_of_ways(a3,n)) n=6 a4=[1,1,1,0,0,0] print(no_of_ways(a4,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 4 ; var a1 : Sequence := Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 0 }))) ; execute (no_of_ways(a1, n))->display() ; n := 5 ; var a2 : Sequence := Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 0 })))) ; execute (no_of_ways(a2, n))->display() ; n := 5 ; var a3 : Sequence := Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))) ; execute (no_of_ways(a3, n))->display() ; n := 6 ; var a4 : Sequence := Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))))) ; execute (no_of_ways(a4, n))->display() ) else skip; operation no_of_ways(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count_0 : int := 0 ; var count var count_0 : int := 0 : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] = 0) then ( count_0 := count_0 + 1 ) else ( count var count_0 : int := 0 := count var count_0 : int := 0 + 1 )) ; if (count var count_0 : int := 0 mod 2 = 0) then ( return count_0 ) else ( return count var count_0 : int := 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def distantAdjacentElement(a,n): m=dict() for i in range(n): if a[i]in m : m[a[i]]+=1 else : m[a[i]]=1 mx=0 for i in range(n): if mx(n+1)//2 : print("NO") else : print("YES") if __name__=="__main__" : a=[7,7,7,7] n=len(a) distantAdjacentElement(a,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{7}->union(Sequence{7}->union(Sequence{7}->union(Sequence{ 7 }))) ; n := (a)->size() ; distantAdjacentElement(a, n) ) else skip; operation distantAdjacentElement(a : OclAny, n : OclAny) pre: true post: true activity: var m : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( if (m)->includes(a[i+1]) then ( m[a[i+1]+1] := m[a[i+1]+1] + 1 ) else ( m[a[i+1]+1] := 1 )) ; var mx : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (mx->compareTo(m[a[i+1]+1])) < 0 then ( mx := m[a[i+1]+1] ) else skip) ; if (mx->compareTo((n + 1) div 2)) > 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def sortedSquares(self,A): pos=0 while pos=0 : if A[npos]**2=0 : res.append(A[npos]**2) npos-=1 while posexists( _x | result = _x ); operation sortedSquares(A : OclAny) : OclAny pre: true post: true activity: var pos : int := 0 ; while (pos->compareTo((A)->size())) < 0 & A[pos+1] < 0 do ( pos := pos + 1) ; var npos : double := pos - 1 ; var res : Sequence := Sequence{} ; while (pos->compareTo((A)->size())) < 0 & npos >= 0 do ( if ((A[npos+1])->pow(2)->compareTo((A[pos+1])->pow(2))) < 0 then ( execute (((A[npos+1])->pow(2)) : res) ; npos := npos - 1 ) else ( execute (((A[pos+1])->pow(2)) : res) ; pos := pos + 1 )) ; while npos >= 0 do ( execute (((A[npos+1])->pow(2)) : res) ; npos := npos - 1) ; while (pos->compareTo((A)->size())) < 0 do ( execute (((A[pos+1])->pow(2)) : res) ; pos := pos + 1) ; return res; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getSteps(arr,n): count=0 modulus=[0 for i in range(4)] Sum=0 i=0 for i in range(n): mod=arr[i]% 4 Sum+=mod modulus[mod]+=1 if(Sum % 4!=0): return-1 else : if(modulus[1]>modulus[3]): count+=modulus[3] else : count+=modulus[1] modulus[1]-=count modulus[3]-=count modulus[2]+=modulus[1]//2 modulus[2]+=modulus[3]//2 count+=modulus[1]//2 count+=modulus[3]//2 count+=modulus[2]//2 return count n=7 arr=[1,2,3,1,2,3,8] count=getSteps(arr,n) print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 7 ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 8 })))))) ; count := getSteps(arr, n) ; execute (count)->display(); operation getSteps(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var modulus : Sequence := Integer.subrange(0, 4-1)->select(i | true)->collect(i | (0)) ; var Sum : int := 0 ; var i : int := 0 ; for i : Integer.subrange(0, n-1) do ( var mod : int := arr[i+1] mod 4 ; Sum := Sum + mod ; modulus[mod+1] := modulus[mod+1] + 1) ; if (Sum mod 4 /= 0) then ( return -1 ) else ( if ((modulus[1+1]->compareTo(modulus[3+1])) > 0) then ( count := count + modulus[3+1] ) else ( count := count + modulus[1+1] ) ; modulus[1+1] := modulus[1+1] - count ; modulus[3+1] := modulus[3+1] - count ; modulus[2+1] := modulus[2+1] + modulus[1+1] div 2 ; modulus[2+1] := modulus[2+1] + modulus[3+1] div 2 ; count := count + modulus[1+1] div 2 ; count := count + modulus[3+1] div 2 ; count := count + modulus[2+1] div 2 ; return count ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sub_segments(string,n): l=len(string) for x in range(0,l,n): newlist=string[x : x+n] arr=[] for y in newlist : if y not in arr : arr.append(y) print(''.join(arr)) string="geeksforgeeksgfg" n=4 sub_segments(string,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; string := "geeksforgeeksgfg" ; n := 4 ; sub_segments(string, n); operation sub_segments(string : OclAny, n : OclAny) pre: true post: true activity: var l : int := (string)->size() ; for x : Integer.subrange(0, l-1)->select( $x | ($x - 0) mod n = 0 ) do ( var newlist : OclAny := string.subrange(x+1, x + n) ; var arr : Sequence := Sequence{} ; for y : newlist do ( if (arr)->excludes(y) then ( execute ((y) : arr) ) else skip) ; execute (StringLib.sumStringsWithSeparator((arr), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def MinRemove(a,n,k): cnt=[0]*k for i in range(n): if(a[i]==0): cnt[0]+=1 ; elif(cnt[a[i]-1]>0): cnt[a[i]-1]-=1 ; cnt[a[i]]+=1 ; return n-(k*cnt[k-1]); if __name__=="__main__" : a=[0,1,2,3,4,0,1,0,1,2,3,4] k=5 ; n=len(a); print(MinRemove(a,n,k)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{0}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))))))))))) ; k := 5; ; n := (a)->size(); ; execute (MinRemove(a, n, k))->display(); ) else skip; operation MinRemove(a : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, k) ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] = 0) then ( cnt->first() := cnt->first() + 1; ) else (if (cnt[a[i+1] - 1+1] > 0) then ( cnt[a[i+1] - 1+1] := cnt[a[i+1] - 1+1] - 1; ; cnt[a[i+1]+1] := cnt[a[i+1]+1] + 1; ) else skip)) ; return n - (k * cnt[k - 1+1]);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def SquareCube(N): cnt,i=0,1 while(i**6<=N): cnt+=1 i+=1 return cnt N=100000 print(SquareCube(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 100000 ; execute (SquareCube(N))->display(); operation SquareCube(N : OclAny) : OclAny pre: true post: true activity: var cnt : OclAny := null; var i : OclAny := null; Sequence{cnt,i} := Sequence{0,1} ; while (((i)->pow(6)->compareTo(N)) <= 0) do ( cnt := cnt + 1 ; i := i + 1) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def knapSack(W,wt,val,n): maxratio=-sys.maxsize-1 ; maxindex=0 ; for i in range(n): if((val[i]/wt[i])>maxratio): maxratio=(val[i]/wt[i]); maxindex=i ; return(W*maxratio); val=[14,27,44,19]; wt=[6,7,9,8]; n=len(val); W=50 ; print(knapSack(W,wt,val,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; val := Sequence{14}->union(Sequence{27}->union(Sequence{44}->union(Sequence{ 19 }))); ; wt := Sequence{6}->union(Sequence{7}->union(Sequence{9}->union(Sequence{ 8 }))); ; n := (val)->size(); ; W := 50; ; execute (knapSack(W, wt, val, n))->display();; operation knapSack(W : OclAny, wt : OclAny, val : OclAny, n : OclAny) pre: true post: true activity: var maxratio : double := -(trailer . (name maxsize)) - 1; ; var maxindex : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (((val[i+1] / wt[i+1])->compareTo(maxratio)) > 0) then ( maxratio := (val[i+1] / wt[i+1]); ; maxindex := i; ) else skip) ; return (W * maxratio);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import subprocess import gzip, base64, os, stat gz = b'IbZ5JTahf8NDAhHCD0mAwA=' bin = gzip.decompress(base64.b64decode(gz)) p = os.path.dirname(os.path.abspath(__file__)) pymain = os.path.join(p, "a.out") with open(pymain, "wb") as f: f.write(bin) os.chmod(pymain, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) subprocess.call([pymain]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var gz : OclAny := (atom b 'IbZ5JTahf8NDAhHCD0mAwA=') ; var bin : OclAny := gzip.decompress(base64.b64decode(gz)) ; var p : OclAny := os.path.dirname(os.path.abspath(__file__)) ; var pymain : OclAny := os.path.join(p, "a.out") ; try (var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(pymain)); f.write(bin)) catch (_e : OclException) do skip ; os.chmod(pymain, MathLib.bitwiseOr(MathLib.bitwiseOr(stat.S_IRUSR, stat.S_IWUSR), stat.S_IXUSR)) ; subprocess.call(Sequence{ pymain }); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,*s=open(0) h,w=map(int,h.split()) r=range a,b,c,d=eval('eval("w*[0],"*h),'*4) for i in r(h*w): i,j=i//w,i % w ; f=s[i][j]>'#' ; a[i][j]=-~ a[i][j-1]*f ; b[i][~ j]=-~ b[i][-j]*(s[i][-j-2]>'#'); c[i][j]=-~ c[i-1][j]*f ; d[~ i][j]=-~ d[-i][j]*(s[~ i][j]>'#') print(max(a[i][j]+b[i][j]+c[i][j]+d[i][j]-3 for i in r(h)for j in r(w))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var s : OclAny := null; Sequence{h,s} := OclFile.newOclFile_Write(OclFile.newOclFile(0)) ; var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (h.split())->collect( _x | (OclType["int"])->apply(_x) ) ; var r : OclAny := range ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := StringLib.nCopies('eval("w*[0],"*h),', 4) ; for i : r(h * w) do ( var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{i div w,i mod w}; var f : boolean := s[i+1][j+1] > '#'; a[i+1][j+1] := -MathLib.bitwiseNot(a[i+1][j - 1+1]) * f; b[i+1][MathLib.bitwiseNot(j)+1] := -MathLib.bitwiseNot(b[i+1]->reverse()->at(-(-j))) * (s[i+1]->reverse()->at(-(-j - 2)) > '#'); c[i+1][j+1] := -MathLib.bitwiseNot(c[i - 1+1][j+1]) * f; d[MathLib.bitwiseNot(i)+1][j+1] := -MathLib.bitwiseNot(d->reverse()->at(-(-i))[j+1]) * (s[MathLib.bitwiseNot(i)+1][j+1] > '#')) ; execute (((argument (test (logical_test (comparison (expr (expr (expr (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))) + (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) + (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) + (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) - (expr (atom (number (integer 3)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name r)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name h)))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name r)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name w)))))))) )))))))))))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import numpy as np def solve(H : int,W : int,S : "List[List[str]]"): arr_s=np.array(S) arr_s=np.where(arr_s==".",1,0) arr_v=np.zeros((H,W),dtype=int) arr_h=np.zeros((H,W),dtype=int) arr_v[0,:]=arr_s[0,:] arr_h[:,0]=arr_s[:,0] for i in range(H-1): arr_v[i+1,:]=(arr_v[i,:]+1)*arr_s[i+1,:] for i in range(H-2,-1,-1): arr_v[i,:]=np.where(arr_v[i,:]>0,np.maximum(arr_v[i+1,:],arr_v[i,:]),0) for i in range(W-1): arr_h[:,i+1]=(arr_h[:,i]+1)*arr_s[:,i+1] for i in range(W-2,-1,-1): arr_h[:,i]=np.where(arr_h[:,i]>0,np.maximum(arr_h[:,i+1],arr_h[:,i]),0) print(np.max(arr_v+arr_h)-1) return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() H=int(next(tokens)) W=int(next(tokens)) S=[[c for c in next(tokens)]for _ in range(H)] solve(H,W,S) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(H : int, W : int, S : "List[List[str]]") pre: true post: true activity: var arr_s : Sequence := (S) ; arr_s := ; var arr_v : Sequence := MatrixLib.singleValueMatrix(Sequence{H, W}, 0.0) ; var arr_h : Sequence := MatrixLib.singleValueMatrix(Sequence{H, W}, 0.0) ; arr_v->first() := arr_s->first() ; arr_h->collect( _r | _r->first() ) := arr_s->collect( _r | _r->first() ) ; for i : Integer.subrange(0, H - 1-1) do ( arr_v[i + 1+1] := MatrixLib.dotProduct((MatrixLib.elementwiseAdd(arr_v[i+1], 1)),arr_s[i + 1+1])) ; for i : Integer.subrange(-1 + 1, H - 2)->reverse() do ( arr_v[i+1] := ) ; for i : Integer.subrange(0, W - 1-1) do ( arr_h->collect( _r | _r[i + 1+1] ) := MatrixLib.dotProduct((MatrixLib.elementwiseAdd(arr_h->collect( _r | _r[i+1] ), 1)),arr_s->collect( _r | _r[i + 1+1] ))) ; for i : Integer.subrange(-1 + 1, W - 2)->reverse() do ( arr_h->collect( _r | _r[i+1] ) := ) ; execute ( - 1)->display() ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var H : int := ("" + (((tokens).next())))->toInteger() ; var W : int := ("" + (((tokens).next())))->toInteger() ; var S : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | ((tokens).next()->select(c | true)->collect(c | (c)))) ; solve(H, W, S); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(300000) from collections import deque def I(): return int(sys.stdin.readline()) def MI(): return map(int,sys.stdin.readline().split()) def LMI(): return list(map(int,sys.stdin.readline().split())) MOD=10**9+7 INF=float('inf') N,M=MI() adj=[list()for _ in range(N)] for _ in range(M): u,v=map(lambda s : int(s)-1,sys.stdin.readline().split()) adj[u].append(v) S,T=map(lambda s : int(s)-1,sys.stdin.readline().split()) q=deque([(0,S,0)]) seen={S} while len(q)>0 : dim,v,cnt=q.popleft() if v==T and dim==0 : print(cnt//3) exit(0) ndim=(dim+1)% 3 for nxt in adj[v]: if(ndim*N+nxt)not in seen : q.append((ndim,nxt,cnt+1)) seen.add(ndim*N+nxt) print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(300000) ; skip ; skip ; skip ; skip ; var MOD : double := (10)->pow(9) + 7 ; var INF : double := ("" + (('inf')))->toReal() ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := MI() ; var adj : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (())) ; for _anon : Integer.subrange(0, M-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := (sys.stdin.readLine().split())->collect( _x | (lambda s : OclAny in (("" + ((s)))->toInteger() - 1))->apply(_x) ) ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) ))))) ; var S : OclAny := null; var T : OclAny := null; Sequence{S,T} := (sys.stdin.readLine().split())->collect( _x | (lambda s : OclAny in (("" + ((s)))->toInteger() - 1))->apply(_x) ) ; var q : Sequence := (Sequence{ Sequence{0, S, 0} }) ; var seen : Set := Set{ S } ; while (q)->size() > 0 do ( var dim : OclAny := null; var v : OclAny := null; var cnt : OclAny := null; Sequence{dim,v,cnt} := q->first() ; q := q->tail() ; if v = T & dim = 0 then ( execute (cnt div 3)->display() ; exit(0) ) else skip ; var ndim : int := (dim + 1) mod 3 ; for nxt : adj[v+1] do ( if (seen)->excludes((ndim * N + nxt)) then ( execute ((Sequence{ndim, nxt, cnt + 1}) : q) ; execute ((ndim * N + nxt) : seen) ) else skip)) ; execute (-1)->display(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LMI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w=map(int,input().split()) S=[list(input())for _ in range(h)] toUP=[[0]*w for _ in range(h)] for i in range(w): cnt=0 for j in range(h): if S[j][i]=="." : cnt+=1 toUP[j][i]=cnt else : cnt=0 toDOWN=[[0]*w for _ in range(h)] for i in range(w): cnt=0 for j in range(h-1,-1,-1): if S[j][i]=="." : cnt+=1 toDOWN[j][i]=cnt else : cnt=0 toLEFT=[[0]*w for _ in range(h)] for i in range(h): cnt=0 for j in range(w): if S[i][j]=="." : cnt+=1 toLEFT[i][j]=cnt else : cnt=0 toRIGHT=[[0]*w for _ in range(h)] for i in range(h): cnt=0 for j in range(w-1,-1,-1): if S[i][j]=="." : cnt+=1 toRIGHT[i][j]=cnt else : cnt=0 ans=0 for i in range(h): for j in range(w): if S[i][j]=="." : ans=max(ans,toUP[i][j]+toDOWN[i][j]+toLEFT[i][j]+toRIGHT[i][j]-3) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (((OclFile["System.in"]).readLine())->characters())) ; var toUP : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, w))) ; for i : Integer.subrange(0, w-1) do ( var cnt : int := 0 ; for j : Integer.subrange(0, h-1) do ( if S[j+1][i+1] = "." then ( cnt := cnt + 1 ; toUP[j+1][i+1] := cnt ) else ( cnt := 0 ))) ; var toDOWN : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, w))) ; for i : Integer.subrange(0, w-1) do ( cnt := 0 ; for j : Integer.subrange(-1 + 1, h - 1)->reverse() do ( if S[j+1][i+1] = "." then ( cnt := cnt + 1 ; toDOWN[j+1][i+1] := cnt ) else ( cnt := 0 ))) ; var toLEFT : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, w))) ; for i : Integer.subrange(0, h-1) do ( cnt := 0 ; for j : Integer.subrange(0, w-1) do ( if S[i+1][j+1] = "." then ( cnt := cnt + 1 ; toLEFT[i+1][j+1] := cnt ) else ( cnt := 0 ))) ; var toRIGHT : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, w))) ; for i : Integer.subrange(0, h-1) do ( cnt := 0 ; for j : Integer.subrange(-1 + 1, w - 1)->reverse() do ( if S[i+1][j+1] = "." then ( cnt := cnt + 1 ; toRIGHT[i+1][j+1] := cnt ) else ( cnt := 0 ))) ; var ans : int := 0 ; for i : Integer.subrange(0, h-1) do ( for j : Integer.subrange(0, w-1) do ( if S[i+1][j+1] = "." then ( ans := Set{ans, toUP[i+1][j+1] + toDOWN[i+1][j+1] + toLEFT[i+1][j+1] + toRIGHT[i+1][j+1] - 3}->max() ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import os from collections import Counter,deque from fractions import gcd from functools import lru_cache from functools import reduce import functools import heapq import itertools import math import numpy as np import re import sys if os.getenv("LOCAL"): sys.stdin=open("_in.txt","r") sys.setrecursionlimit(2147483647) INF=float("inf") H,W=list(map(int,sys.stdin.readline().split())) S=np.array([list(sys.stdin.readline().rstrip())for _ in range(H)])=='.' ups=np.zeros((H,W),dtype=int) downs=np.zeros((H,W),dtype=int) rights=np.zeros((H,W),dtype=int) lefts=np.zeros((H,W),dtype=int) for h in range(1,H): ups[h]=(ups[h-1]+1)*S[h-1] for h in reversed(range(H-1)): downs[h]=(downs[h+1]+1)*S[h+1] for w in range(1,W): lefts[:,w]=(lefts[:,w-1]+1)*S[:,w-1] for w in reversed(range(W-1)): rights[:,w]=(rights[:,w+1]+1)*S[:,w+1] print(((ups+downs+lefts+rights)*S).max()+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if os.getenv("LOCAL") then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("_in.txt")) ) else skip ; sys.setrecursionlimit(2147483647) ; var INF : double := ("" + (("inf")))->toReal() ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var S : boolean := (Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | ((sys.stdin.readLine().rstrip())))) = '.' ; var ups : Sequence := MatrixLib.singleValueMatrix(Sequence{H, W}, 0.0) ; var downs : Sequence := MatrixLib.singleValueMatrix(Sequence{H, W}, 0.0) ; var rights : Sequence := MatrixLib.singleValueMatrix(Sequence{H, W}, 0.0) ; var lefts : Sequence := MatrixLib.singleValueMatrix(Sequence{H, W}, 0.0) ; for h : Integer.subrange(1, H-1) do ( ups[h+1] := (ups[h - 1+1] + 1) * S[h - 1+1]) ; for h : (Integer.subrange(0, H - 1-1))->reverse() do ( downs[h+1] := (downs[h + 1+1] + 1) * S[h + 1+1]) ; for w : Integer.subrange(1, W-1) do ( lefts->collect( _r | _r[w+1] ) := MatrixLib.dotProduct((MatrixLib.elementwiseAdd(lefts->collect( _r | _r[w - 1+1] ), 1)),S->collect( _r | _r[w - 1+1] ))) ; for w : (Integer.subrange(0, W - 1-1))->reverse() do ( rights->collect( _r | _r[w+1] ) := MatrixLib.dotProduct((MatrixLib.elementwiseAdd(rights->collect( _r | _r[w + 1+1] ), 1)),S->collect( _r | _r[w + 1+1] ))) ; execute ((MatrixLib.elementwiseMult((ups->union(downs)->union(lefts)->union(rights)), S))->max() + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def primeFactors(n,freq): cnt=0 while n % 2==0 : cnt=cnt+1 n=int(n//2) freq[2]=cnt i=3 while i<=math.sqrt(n): cnt=0 while(n % i==0): cnt=cnt+1 n=int(n//i) freq[int(i)]=cnt i=i+2 if(n>2): freq[int(n)]=1 def getMaximumPower(n,m): freq1=[0]*(n+1) freq2=[0]*(m+1) primeFactors(n,freq1) primeFactors(m,freq2) maxi=0 i=2 while i<=m : if(freq1[i]==0 and freq2[i]==0): i=i+1 continue if(freq2[i]>freq1[i]): return 0 if(freq2[i]): maxi=max(maxi,int(freq1[i]//freq2[i])) i=i+1 return maxi n=48 m=4 print(getMaximumPower(n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 48 ; m := 4 ; execute (getMaximumPower(n, m))->display(); operation primeFactors(n : OclAny, freq : OclAny) pre: true post: true activity: var cnt : int := 0 ; while n mod 2 = 0 do ( cnt := cnt + 1 ; n := ("" + ((n div 2)))->toInteger()) ; freq[2+1] := cnt ; var i : int := 3 ; while (i->compareTo((n)->sqrt())) <= 0 do ( cnt := 0 ; while (n mod i = 0) do ( cnt := cnt + 1 ; n := ("" + ((n div i)))->toInteger()) ; freq[("" + ((i)))->toInteger()+1] := cnt ; i := i + 2) ; if (n > 2) then ( freq[("" + ((n)))->toInteger()+1] := 1 ) else skip; operation getMaximumPower(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var freq1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var freq2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (m + 1)) ; primeFactors(n, freq1) ; primeFactors(m, freq2) ; var maxi : int := 0 ; i := 2 ; while (i->compareTo(m)) <= 0 do ( if (freq1[i+1] = 0 & freq2[i+1] = 0) then ( i := i + 1 ; continue ) else skip ; if ((freq2[i+1]->compareTo(freq1[i+1])) > 0) then ( return 0 ) else skip ; if (freq2[i+1]) then ( maxi := Set{maxi, ("" + ((freq1[i+1] div freq2[i+1])))->toInteger()}->max() ) else skip ; i := i + 1) ; return maxi; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from queue import Queue def generateNumbersUtil(): global vec q=Queue() q.put("9") for count in range(MAX_COUNT,-1,-1): s1=q.queue[0] q.get() vec.append(s1) s2=s1 s1+="0" q.put(s1) s2+="9" q.put(s2) def findSmallestMultiple(n): global vec for i in range(len(vec)): if(int(vec[i])% n==0): return vec[i] MAX_COUNT=10000 vec=[] generateNumbersUtil() n=7 print(findSmallestMultiple(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute vec : OclAny; attribute vec : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; var MAX_COUNT : int := 10000 ; vec := Sequence{} ; generateNumbersUtil() ; n := 7 ; execute (findSmallestMultiple(n))->display(); operation generateNumbersUtil() pre: true post: true activity: skip ; var q : OclAny := Queue() ; q.put("9") ; for count : Integer.subrange(-1 + 1, MAX_COUNT)->reverse() do ( var s1 : OclAny := q.queue->first() ; q.get() ; execute ((s1) : vec) ; var s2 : OclAny := s1 ; s1 := s1 + "0" ; q.put(s1) ; s2 := s2 + "9" ; q.put(s2)); operation findSmallestMultiple(n : OclAny) : OclAny pre: true post: true activity: skip ; for i : Integer.subrange(0, (vec)->size()-1) do ( if (("" + ((vec[i+1])))->toInteger() mod n = 0) then ( return vec[i+1] ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPrime(p): checkNumber=2**p-1 nextval=4 % checkNumber for i in range(1,p-1): nextval=(nextval*nextval-2)% checkNumber if(nextval==0): return True else : return False p=7 checkNumber=2**p-1 if isPrime(p): print(checkNumber,'is Prime.') else : print(checkNumber,'is not Prime') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; p := 7 ; checkNumber := (2)->pow(p) - 1 ; if isPrime(p) then ( execute (checkNumber)->display() ) else ( execute (checkNumber)->display() ); operation isPrime(p : OclAny) : OclAny pre: true post: true activity: var checkNumber : double := (2)->pow(p) - 1 ; var nextval : int := 4 mod checkNumber ; for i : Integer.subrange(1, p - 1-1) do ( nextval := (nextval * nextval - 2) mod checkNumber) ; if (nextval = 0) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=eval(input()) for i in range(t): m=input() d=eval(m)-10**(len(m)-1) print(d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, t-1) do ( var m : String := (OclFile["System.in"]).readLine() ; var d : double := m - (10)->pow(((m)->size() - 1)) ; execute (d)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def AlternateRearrange(arr,n): arr.sort() v1=list() v2=list() for i in range(n): if(arr[i]% 2==0): v1.append(arr[i]) else : v2.append(arr[i]) index=0 i=0 j=0 flag=False if(arr[0]% 2==0): flag=True while(indexunion(Sequence{8}->union(Sequence{13}->union(Sequence{2}->union(Sequence{19}->union(Sequence{ 14 }))))) ; n := (arr)->size() ; AlternateRearrange(arr, n); operation AlternateRearrange(arr : OclAny, n : OclAny) pre: true post: true activity: arr := arr->sort() ; var v1 : Sequence := () ; var v2 : Sequence := () ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] mod 2 = 0) then ( execute ((arr[i+1]) : v1) ) else ( execute ((arr[i+1]) : v2) )) ; var index : int := 0 ; var i : int := 0 ; var j : int := 0 ; var flag : boolean := false ; if (arr->first() mod 2 = 0) then ( flag := true ) else skip ; while ((index->compareTo(n)) < 0) do ( if (flag = true) then ( arr[index+1] := v1[i+1] ; index := index + 1 ; i := i + 1 ; flag := MathLib.bitwiseNot(flag) ) else ( arr[index+1] := v2[j+1] ; index := index + 1 ; j := j + 1 ; flag := MathLib.bitwiseNot(flag) )) ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): m=input() ans=int(m)-10**(len(m)-1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var m : String := (OclFile["System.in"]).readLine() ; var ans : double := ("" + ((m)))->toInteger() - (10)->pow(((m)->size() - 1)) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): m=int(input()) k=len(str(m)) print(m-(10**(k-1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := (("" + ((m))))->size() ; execute (m - ((10)->pow((k - 1))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=input() if n=='0' or set(str(int(n[0])-1)+n[1 : :])=={'0'}: print(0) else : print(int(str(int(n[0])-1)+n[1 : :])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : String := (OclFile["System.in"]).readLine() ; if n = '0' or Set{}->union((("" + ((("" + ((n->first())))->toInteger() - 1))) + n(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop :)))) = Set{ '0' } then ( execute (0)->display() ) else ( execute (("" + ((("" + ((("" + ((n->first())))->toInteger() - 1))) + n(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop :)))))->toInteger())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math test=int(input()) for _ in range(test): n=int(input()) print(n-pow(10,(int(math.log10(n))))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var test : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, test-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n - (10)->pow((("" + (((n)->log10())))->toInteger())))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def intersection(x,y): g=math.gcd(x,y) if g==1 : return x+y return intersection(x//g,y//g)*g-(g-1) print(intersection(*map(int,input().split()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; execute (intersection((argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))))->display(); operation intersection(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var g : long := (x)->gcd(y) ; if g = 1 then ( return x + y ) else skip ; return intersection(x div g, y div g) * g - (g - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) print(x**3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((x)->pow(3))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input(); l=sorted(map(int,input().split())); s=count=0 while s<=sum(l): s+=l.pop(); count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input(); var l : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort(); var s : OclAny := 0; var count : int := 0 ; while (s->compareTo((l)->sum())) <= 0 do ( s := s + l->last() ; l := l->front(); count := count + 1) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) c=[int(x)for x in input().split()] c_sort=sorted(c,reverse=True) th=sum(c)//2 v=0 for i in range(n): v+=c_sort[i] if v>th : print(i+1) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var c_sort : Sequence := c->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var th : int := (c)->sum() div 2 ; var v : int := 0 ; for i : Integer.subrange(0, n-1) do ( v := v + c_sort[i+1] ; if (v->compareTo(th)) > 0 then ( execute (i + 1)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n : int,arr : list): half=sum(arr)//2 arr=sorted(arr) res=[] for i in range(n): res.append(arr[n-i-1]) if sum(res)>half : return len(res) def main(): n=int(input()) arr=list(map(int,input().split())) print(solve(n,arr)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation solve(n : int, arr : Sequence(OclAny)) : OclAny pre: true post: true activity: var half : int := (arr)->sum() div 2 ; var arr : Sequence := arr->sort() ; var res : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((arr[n - i - 1+1]) : res) ; if ((res)->sum()->compareTo(half)) > 0 then ( return (res)->size() ) else skip); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; arr := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (solve(n, arr))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input(); l=sorted(map(int,input().split())); s=count=0 while s<=sum(l): s+=l.pop(); count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input(); var l : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort(); var s : OclAny := 0; var count : int := 0 ; while (s->compareTo((l)->sum())) <= 0 do ( s := s + l->last() ; l := l->front(); count := count + 1) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B,C=map(int,input().split()) if A<=C and B>=C : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{A,B,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (A->compareTo(C)) <= 0 & (B->compareTo(C)) >= 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) A=[int(x)for x in input().split()] B=[] flag=True A=sorted(A) res=B.insert(len(B),A.pop(len(A)-1)) if sum(A)(sum(A)-A[i]): print(len(B)+1) flag=not(flag) break if flag : res=B.insert(len(B),A.pop(len(A)-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var B : Sequence := Sequence{} ; var flag : boolean := true ; A := A->sort() ; var res : OclAny := B.insert((B)->size(), A->at((expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)))))))) )))) - (expr (atom (number (integer 1)))))+1)) ; if ((A)->sum()->compareTo((B)->sum())) < 0 then ( execute ((B)->size())->display() ) else ( while flag do ( for i : Integer.subrange(0, (A)->size()-1) do ( if (((B)->sum() + A[i+1])->compareTo(((A)->sum() - A[i+1]))) > 0 then ( execute ((B)->size() + 1)->display() ; flag := not((flag)) ; break ) else skip) ; if flag then ( res := B.insert((B)->size(), A->at((expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)))))))) )))) - (expr (atom (number (integer 1)))))+1)) ) else skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) s=input() a=s.find('>') b=s.rfind('<') num=0 if(a>b or a==-1 or b==-1): num=len(s) elif(atoInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var a : int := s->indexOf('>') - 1 ; var b : OclAny := s.rfind('<') ; num := 0 ; if ((a->compareTo(b)) > 0 or a = -1 or b = -1) then ( num := (s)->size() ) else (if ((a->compareTo(b)) < 0) then ( num := (s)->size() - (b - a + 1) ) else skip) ; execute (num)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() wyn=0 l=0 while l=0 : if s[l]==">" : wyn+=1 l-=1 else : break print(wyn) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var wyn : int := 0 ; var l : int := 0 ; while (l->compareTo(n)) < 0 do ( if s[l+1] = "<" then ( wyn := wyn + 1 ; l := l + 1 ) else ( break )) ; l := n - 1 ; while l >= 0 do ( if s[l+1] = ">" then ( wyn := wyn + 1 ; l := l - 1 ) else ( break )) ; execute (wyn)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() i=0 while i=0 and s[i]=='>' : i-=1 ans+=n-1-i print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var i : int := 0 ; while (i->compareTo(n)) < 0 & s[i+1] = '<' do ( i := i + 1) ; var ans : int := i ; i := n - 1 ; while i >= 0 & s[i+1] = '>' do ( i := i - 1) ; ans := ans + n - 1 - i ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- __author__='artyom' def main(): n=read() s=read(0) c=0 while c=0 and s[n]=='>' : n-=1 c+=1 return c def read(mode=1,size=None): if mode==0 : return input().strip() if mode==1 : return int(input().strip()) if mode==2 : return input().strip().split() if mode==3 : return list(map(int,input().strip().split())) a=[] for _ in range(size): a.append(read(3)) return a def write(s='\n'): if s is None : s='' if isinstance(s,tuple)or isinstance(s,list): s=' '.join(map(str,s)) s=str(s) print(s) write(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var __author__ : String := 'artyom' ; skip ; skip ; skip ; write(main()); operation main() : OclAny pre: true post: true activity: var n : OclAny := read() ; var s : OclAny := read(0) ; var c : int := 0 ; while (c->compareTo(n)) < 0 & s[c+1] = '<' do ( c := c + 1) ; n := n - 1 ; while n >= 0 & s[n+1] = '>' do ( n := n - 1 ; c := c + 1) ; return c; operation read(mode : int, size : OclAny) : OclAny pre: true post: true activity: if mode->oclIsUndefined() then mode := 1 else skip; if size->oclIsUndefined() then size := null else skip; if mode = 0 then ( return input()->trim() ) else skip ; if mode = 1 then ( return ("" + ((input()->trim())))->toInteger() ) else skip ; if mode = 2 then ( return input()->trim().split() ) else skip ; if mode = 3 then ( return ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ) else skip ; var a : Sequence := Sequence{} ; for _anon : Integer.subrange(0, size-1) do ( execute ((read(3)) : a)) ; return a; operation write(s : String) pre: true post: true activity: if s->oclIsUndefined() then s := ' ' else skip; if s <>= null then ( s := '' ) else skip ; if (tuple).isInstance(s) or (OclType["Sequence"]).isInstance(s) then ( s := StringLib.sumStringsWithSeparator(((s)->collect( _x | (OclType["String"])->apply(_x) )), ' ') ) else skip ; s := ("" + ((s))) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- size=int(input()) s=input() r=0 for i in range(size): if s[i]=='<' : r+=1 else : break for i in range(size-1,-1,-1): if s[i]=='>' : r+=1 else : break print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var size : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var r : int := 0 ; for i : Integer.subrange(0, size-1) do ( if s[i+1] = '<' then ( r := r + 1 ) else ( break )) ; for i : Integer.subrange(-1 + 1, size - 1)->reverse() do ( if s[i+1] = '>' then ( r := r + 1 ) else ( break )) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- code=""" #include using namespace std; int main() { int x; cin>>x; cout<\r\nusing namespace std;\r\nint main()\r\n{\r\n int x; cin>>x;\r\n cout<display() ) else ( execute ("Consonant")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPalindrome(string : str,low : int,high : int): while low=n : x=currPart.copy() allPart.append(x) return for i in range(start,n): if isPalindrome(string,start,i): currPart.append(string[start : i+1]) allPalPartUtil(allPart,currPart,i+1,n,string) currPart.pop() def allPalPartitions(string : str): n=len(string) allPart=[] currPart=[] allPalPartUtil(allPart,currPart,0,n,string) for i in range(len(allPart)): for j in range(len(allPart[i])): print(allPart[i][j],end=" ") print() if __name__=="__main__" : string="nitin" allPalPartitions(string) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( var string : String := "nitin" ; allPalPartitions(string) ) else skip; operation isPalindrome(string : String, low : int, high : int) : OclAny pre: true post: true activity: while (low->compareTo(high)) < 0 do ( if string[low+1] /= string[high+1] then ( return false ) else skip ; low := low + 1 ; high := high - 1) ; return true; operation allPalPartUtil(allPart : Sequence(OclAny), currPart : Sequence(OclAny), start : int, n : int, string : String) pre: true post: true activity: if (start->compareTo(n)) >= 0 then ( var x : OclAny := currPart->copy() ; execute ((x) : allPart) ; return ) else skip ; for i : Integer.subrange(start, n-1) do ( if isPalindrome(string, start, i) then ( execute ((string.subrange(start+1, i + 1)) : currPart) ; allPalPartUtil(allPart, currPart, i + 1, n, string) ; currPart := currPart->front() ) else skip); operation allPalPartitions(string : String) pre: true post: true activity: var n : int := (string)->size() ; var allPart : Sequence := Sequence{} ; var currPart : Sequence := Sequence{} ; allPalPartUtil(allPart, currPart, 0, n, string) ; for i : Integer.subrange(0, (allPart)->size()-1) do ( for j : Integer.subrange(0, (allPart[i+1])->size()-1) do ( execute (allPart[i+1][j+1])->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): x=input() if x.find("r")toInteger()-1) do ( var x : String := (OclFile["System.in"]).readLine() ; if (x->indexOf("r") - 1->compareTo(x->indexOf("R") - 1)) < 0 & (x->indexOf("g") - 1->compareTo(x->indexOf("G") - 1)) < 0 & (x->indexOf("b") - 1->compareTo(x->indexOf("B") - 1)) < 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()); print('YNeos'[not((a<=c)and(c<=b)): : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); execute ('YNeos'(subscript (test (logical_test not (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name a)))) <= (comparison (expr (atom (name c)))))))) ))))) and (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name c)))) <= (comparison (expr (atom (name b)))))))) )))))))) ))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) i=1 while True : if i>t : break s=input() list=[k for k in s] a=b=c=0 for k in list : if k=='r' : a=1 if k=='g' : b=1 if k=='b' : c=1 if k=='R' and a!=1 : break if k=='G' and b!=1 : break if k=='B' and c!=1 : break if a==1 and b==1 and c==1 : print("YES") if a==0 or b==0 or c==0 : print("NO") i=i+1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 1 ; while true do ( if (i->compareTo(t)) > 0 then ( break ) else skip ; var s : String := (OclFile["System.in"]).readLine() ; var OclType["Sequence"] : Sequence := s->characters()->select(k | true)->collect(k | (k)) ; a := a(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for k : OclType["Sequence"] do ( if k = 'r' then ( var a : int := 1 ) else skip ; if k = 'g' then ( var b : int := 1 ) else skip ; if k = 'b' then ( var c : int := 1 ) else skip ; if k = 'R' & a /= 1 then ( break ) else skip ; if k = 'G' & b /= 1 then ( break ) else skip ; if k = 'B' & c /= 1 then ( break ) else skip) ; if a = 1 & b = 1 & c = 1 then ( execute ("YES")->display() ) else skip ; if a = 0 or b = 0 or c = 0 then ( execute ("NO")->display() ) else skip ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): str=input() if(str.index('r')toInteger()-1) do ( var OclType["String"] : String := (OclFile["System.in"]).readLine() ; if ((("" + (->indexOf('r') - 1))->compareTo(("" + (->indexOf('R') - 1)))) < 0) & ((("" + (->indexOf('g') - 1))->compareTo(("" + (->indexOf('G') - 1)))) < 0) & ((("" + (->indexOf('b') - 1))->compareTo(("" + (->indexOf('B') - 1)))) < 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : s=input() countr=0 countb=0 countg=0 flag=0 for i in s : if i=="r" : countr+=1 flag+=1 elif i=="b" : countb+=1 flag+=1 elif i=="g" : countg+=1 flag+=1 elif i=="R" and countr==1 : flag+=1 elif i=="B" and countb==1 : flag+=1 elif i=="G" and countg==1 : flag+=1 if flag==6 : print("YES") else : print("NO") t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( var s : String := (OclFile["System.in"]).readLine() ; var countr : int := 0 ; var countb : int := 0 ; var countg : int := 0 ; var flag : int := 0 ; for i : s->characters() do ( if i = "r" then ( countr := countr + 1 ; flag := flag + 1 ) else (if i = "b" then ( countb := countb + 1 ; flag := flag + 1 ) else (if i = "g" then ( countg := countg + 1 ; flag := flag + 1 ) else (if i = "R" & countr = 1 then ( flag := flag + 1 ) else (if i = "B" & countb = 1 then ( flag := flag + 1 ) else (if i = "G" & countg = 1 then ( flag := flag + 1 ) else skip ) ) ) ) ) ) ; if flag = 6 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for _ in range(n): keys=list() data=input() for i in data : if i.islower(): keys.append(i) elif i.lower()not in keys : print("NO") break else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var keys : Sequence := () ; var data : String := (OclFile["System.in"]).readLine() ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name data))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name i)) (trailer . (name islower) (arguments ( ))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name keys)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name i)) (trailer . (name lower) (arguments ( ))))) not in (comparison (expr (atom (name keys))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* def nextFibonacci(n): a=n*(1+sqrt(5))/2.0 return round(a) n=5 print(nextFibonacci(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 5 ; execute (nextFibonacci(n))->display(); operation nextFibonacci(n : OclAny) : OclAny pre: true post: true activity: var a : double := n * (1 + sqrt(5)) / 2.0 ; return (a)->round(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def shiftGrid(self,grid,k): new_grid=[[0]*len(grid[0])for _ in range(len(grid))] m=len(grid) n=len(grid[0]) true_k=k %(m*n) move_i=true_k/n move_j=true_k % n for i in range(m): for j in range(n): new_i=i+move_i if move_j+j>=n : new_i+=1 new_i %=m new_j=(j+move_j)% n new_grid[new_i][new_j]=grid[i][j] return new_grid ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation shiftGrid(grid : OclAny,k : OclAny) : OclAny pre: true post: true activity: var new_grid : Sequence := Integer.subrange(0, (grid)->size()-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (grid->first())->size()))) ; var m : int := (grid)->size() ; var n : int := (grid->first())->size() ; var true_k : int := k mod (m * n) ; var move_i : double := true_k / n ; var move_j : int := true_k mod n ; for i : Integer.subrange(0, m-1) do ( for j : Integer.subrange(0, n-1) do ( var new_i : OclAny := i + move_i ; if (move_j + j->compareTo(n)) >= 0 then ( new_i := new_i + 1 ) else skip ; new_i := new_i mod m ; var new_j : int := (j + move_j) mod n ; new_grid[new_i+1][new_j+1] := grid[i+1][j+1])) ; return new_grid; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=3 ; def printMatrix(mat): for i in range(N): for j in range(N): print(mat[i][j],end=""); print(""); def printDistribution(mat): tr=[[0 for x in range(N)]for y in range(N)]; for i in range(N): for j in range(N): tr[i][j]=mat[j][i]; symm=[[0 for x in range(N)]for y in range(N)]; skewsymm=[[0 for x in range(N)]for y in range(N)]; for i in range(N): for j in range(N): symm[i][j]=(mat[i][j]+tr[i][j])/2 ; skewsymm[i][j]=(mat[i][j]-tr[i][j])/2 ; print("Symmetric matrix-"); printMatrix(symm); print("Skew Symmetric matrix"); printMatrix(skewsymm); mat=[[2,-2,-4],[-1,3,4],[1,-2,-3]]; printDistribution(mat); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 3; ; skip ; skip ; mat := Sequence{Sequence{2}->union(Sequence{-2}->union(Sequence{ -4 }))}->union(Sequence{Sequence{-1}->union(Sequence{3}->union(Sequence{ 4 }))}->union(Sequence{ Sequence{1}->union(Sequence{-2}->union(Sequence{ -3 })) })); ; printDistribution(mat);; operation printMatrix(mat : OclAny) pre: true post: true activity: for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( execute (mat[i+1][j+1])->display();) ; execute ("")->display();); operation printDistribution(mat : OclAny) pre: true post: true activity: var tr : Sequence := Integer.subrange(0, N-1)->select(y | true)->collect(y | (Integer.subrange(0, N-1)->select(x | true)->collect(x | (0)))); ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( tr[i+1][j+1] := mat[j+1][i+1];)) ; var symm : Sequence := Integer.subrange(0, N-1)->select(y | true)->collect(y | (Integer.subrange(0, N-1)->select(x | true)->collect(x | (0)))); ; var skewsymm : Sequence := Integer.subrange(0, N-1)->select(y | true)->collect(y | (Integer.subrange(0, N-1)->select(x | true)->collect(x | (0)))); ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( symm[i+1][j+1] := (mat[i+1][j+1] + tr[i+1][j+1]) / 2; ; skewsymm[i+1][j+1] := (mat[i+1][j+1] - tr[i+1][j+1]) / 2;)) ; execute ("Symmetric matrix-")->display(); ; printMatrix(symm); ; execute ("Skew Symmetric matrix")->display(); ; printMatrix(skewsymm);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cube(x): return x**3 print(cube(input())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (cube((OclFile["System.in"]).readLine()))->display(); operation cube(x : OclAny) : OclAny pre: true post: true activity: return (x)->pow(3); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=float('inf') def judge(src): x_max=INF x_min=-INF for i,(s1,s2)in enumerate(zip(src,src[1 :])): if s1==s2 : return 'none' if i % 2 : s1,s2=s2,s1 if s1!='x' and s2!='x' : if s1toReal() ; skip ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; src := Sequence{ INF }->union(((input().split())->collect( _x | (lambda x : OclAny in (if x = 'x' then x else ("" + ((x)))->toInteger() endif))->apply(_x) )))->union(Sequence{ if N mod 2 then INF else -INF endif }) ; execute (judge(src))->display()); operation judge(src : OclAny) : OclAny pre: true post: true activity: var x_max : OclAny := INF ; var x_min : OclAny := -INF ; for _tuple : Integer.subrange(1, (Integer.subrange(1, src->size())->collect( _indx | Sequence{src->at(_indx), src->tail()->at(_indx)} ))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(1, src->size())->collect( _indx | Sequence{src->at(_indx), src->tail()->at(_indx)} ))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{s1, s2} : OclAny := _tuple->at(_indx); if s1 = s2 then ( return 'none' ) else skip ; if i mod 2 then ( var s1 : OclAny := null; var s2 : OclAny := null; Sequence{s1,s2} := Sequence{s2,s1} ) else skip ; if s1 /= 'x' & s2 /= 'x' then ( if (s1->compareTo(s2)) < 0 then ( return 'none' ) else ( continue ) ) else skip ; if s1 = 'x' then ( if (x_max->compareTo(s2)) <= 0 then ( return 'none' ) else skip ; x_min := Set{x_min, s2 + 1}->max() ) else (if s2 = 'x' then ( if (s1->compareTo(x_min)) <= 0 then ( return 'none' ) else skip ; x_max := Set{x_max, s1 - 1}->min() ) else skip) ; if (x_max->compareTo(x_min)) < 0 then ( return 'none' ) else skip) ; return if x_max = x_min then x_max else 'ambiguous' endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cm=1000 ; meter=cm/100.0 ; kilometer=cm/100000.0 ; print("Length in meter=",meter,"m"); print("Length in Kilometer=",kilometer,"km"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cm : int := 1000; ; var meter : double := cm / 100.0; ; var kilometer : double := cm / 100000.0; ; execute ("Length in meter=")->display(); ; execute ("Length in Kilometer=")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- root=lambda x : x if par[x]==x else root(par[x]) same=lambda x,y : root(x)==root(y) def unite(*z): x,y=map(root,z) if x!=y : if rank[x]0 and a[k-1]>a[k]: l+=size[root(k-1)] unite(k-1,k) if k+1a[k]: r+=size[root(k+1)] unite(k+1,k) c+=l*r*a[k] print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var root : Function := lambda x : OclAny in (if par[x+1] = x then x else root(par[x+1]) endif) ; var same : Function := lambda x : OclAny, y : OclAny in (root->apply(x) = root->apply(y)) ; skip ; var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (testlist_star_expr (star_expr * (expr (atom (name par)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name par)))) ,)} := Integer.subrange(0, n-1) ; var rank : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, n) ; var size : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, n) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); b[t - 1+1] := i) ; var c : int := 0 ; for k : b(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( var l : OclAny := 1; var r : int := 1 ; if k > 0 & (a[k - 1+1]->compareTo(a[k+1])) > 0 then ( l := l + size[root->apply(k - 1)+1] ; unite(k - 1, k) ) else skip ; if (k + 1->compareTo(n)) < 0 & (a[k + 1+1]->compareTo(a[k+1])) > 0 then ( r := r + size[root->apply(k + 1)+1] ; unite(k + 1, k) ) else skip ; c := c + l * r * a[k+1]) ; execute (c)->display(); operation unite(z : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name z))) var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (z)->collect( _x | (root)->apply(_x) ) ; if x /= y then ( if (rank[x+1]->compareTo(rank[y+1])) < 0 then ( par[x+1] := y ; size[y+1] := size[y+1] + size[x+1] ) else ( par[y+1] := x ; size[x+1] := size[x+1] + size[y+1] ; if rank[x+1] = rank[y+1] then ( rank[x+1] := rank[x+1] + 1 ) else skip ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import* import sys q=[] while True : a=sys.stdin.readline().split() if a[0]=='end' : break if a[0]=='insert' : heappush(q,-int(a[1])) else : print(-heappop(q)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var q : Sequence := Sequence{} ; while true do ( var a : OclAny := sys.stdin.readLine().split() ; if a->first() = 'end' then ( break ) else skip ; if a->first() = 'insert' then ( heappush(q, -("" + ((a[1+1])))->toInteger()) ) else ( execute (-heappop(q))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq class PQueue(object): def __init__(self): self.pqueue=[] def insert(self,x): heapq.heappush(self.pqueue,-x) def extractMax(self): return-heapq.heappop(self.pqueue) if __name__=='__main__' : pqueue=PQueue() result=[] while True : line=input() if line=='end' : break if line.split()[0]=='insert' : pqueue.insert(int(line.split()[1])) elif line.split()[0]=='extract' : result.append(pqueue.extractMax()) for i in range(len(result)): print(result[i]) ------------------------------------------------------------ OCL File: --------- class PQueue extends object { static operation newPQueue() : PQueue pre: true post: PQueue->exists( _x | result = _x ); attribute pqueue : Sequence := Sequence{}; operation initialise() : pre: true post: true activity: self.pqueue := Sequence{}; return self; operation insert(x : OclAny) pre: true post: true activity: heapq.heappush(self.pqueue, -x); operation extractMax() : OclAny pre: true post: true activity: return -heapq.heappop(self.pqueue); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var pqueue : PQueue := (PQueue.newPQueue()).initialise() ; var result : Sequence := Sequence{} ; while true do ( var line : String := (OclFile["System.in"]).readLine() ; if line = 'end' then ( break ) else skip ; if line.split()->first() = 'insert' then ( pqueue := pqueue.insertAt(("" + ((line.split()[1+1])))->toInteger()+1, ("" + ((line.split()[1+1])))->toInteger()) ) else (if line.split()->first() = 'extract' then ( execute ((pqueue.extractMax()) : result) ) else skip)) ; for i : Integer.subrange(0, (result)->size()-1) do ( execute (result[i+1])->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from heapq import heapify,heappush,heappop hq=[] S=[] for s in sys.stdin : if s[2]=="s" : heappush(hq,-int(s[7 :])) elif s[2]=="t" : S.append(-heappop(hq)) else : break print("\n".join(map(str,S))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var hq : Sequence := Sequence{} ; var S : Sequence := Sequence{} ; for s : OclFile["System.in"] do ( if s[2+1] = "s" then ( heappush(hq, -("" + ((s.subrange(7+1))))->toInteger()) ) else (if s[2+1] = "t" then ( execute ((-heappop(hq)) : S) ) else ( break ) ) ) ; execute (StringLib.sumStringsWithSeparator(((S)->collect( _x | (OclType["String"])->apply(_x) )), "\n"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def setHeapDown_max(heap,pos): targetkey=heap[pos] while pos>0 : parentpos=(pos-1)>>1 parent=heap[parentpos] if parentfirst() = 'i' then ( var k : int := ("" + ((x.subrange(7+1))))->toInteger() ; heapPush_max(S, k) ) else (if x[1+1] = 'x' then ( execute (heapPop_max(S))->display() ) else ( skip ) ) ); operation setHeapDown_max(heap : OclAny, pos : OclAny) pre: true post: true activity: var targetkey : OclAny := heap[pos+1] ; while pos > 0 do ( var parentpos : int := (pos - 1) /(2->pow(1)) ; var parent : OclAny := heap[parentpos+1] ; if (parent->compareTo(targetkey)) < 0 then ( heap[pos+1] := parent ; pos := parentpos ; continue ) else skip ; break) ; heap[pos+1] := targetkey; operation setHeapUp_max(heap : OclAny, pos : OclAny) pre: true post: true activity: var endpos : int := (heap)->size() ; targetkey := heap[pos+1] ; var childpos : double := 2 * pos + 1 ; while (childpos->compareTo(endpos)) < 0 do ( var rightpos : OclAny := childpos + 1 ; if (rightpos->compareTo(endpos)) < 0 & not((heap[rightpos+1]->compareTo(heap[childpos+1])) < 0) then ( childpos := rightpos ) else skip ; heap[pos+1] := heap[childpos+1] ; pos := childpos ; childpos := 2 * pos + 1) ; heap[pos+1] := targetkey ; setHeapDown_max(heap, pos); operation heapPush_max(heap : OclAny, key : OclAny) pre: true post: true activity: execute ((key) : heap) ; setHeapDown_max(heap, (heap)->size() - 1); operation heapPop_max(heap : OclAny) : OclAny pre: true post: true activity: var lastkey : OclAny := heap->last() ; heap := heap->front() ; if heap then ( var returnkey : OclAny := heap->first() ; heap->first() := lastkey ; setHeapUp_max(heap, 0) ; return returnkey ) else skip ; return lastkey; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq def insert(a,key): key2=-key heapq.heappush(a,key2) def extract(a): key=heapq.heappop(a) return-key a=[] cmds=input().split() while(cmds[0]!='end'): if(cmds[0]=='insert'): op=int(cmds[1]) insert(a,op) elif(cmds[0]=='extract'): print(extract(a)) cmds=input().split() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; a := Sequence{} ; var cmds : OclAny := input().split() ; while (cmds->first() /= 'end') do ( if (cmds->first() = 'insert') then ( var op : int := ("" + ((cmds[1+1])))->toInteger() ; insert(a, op) ) else (if (cmds->first() = 'extract') then ( execute (extract(a))->display() ) else skip) ; cmds := input().split()); operation insert(a : OclAny, key : OclAny) pre: true post: true activity: var key2 : OclAny := -key ; heapq.heappush(a, key2); operation extract(a : OclAny) : OclAny pre: true post: true activity: key := heapq.heappop(a) ; return -key; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,r=map(int,input().split()) if h>=r or h>=0 : print(1) else : print(0 if h+r==0 else-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var r : OclAny := null; Sequence{h,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (h->compareTo(r)) >= 0 or h >= 0 then ( execute (1)->display() ) else ( execute (if h + r = 0 then 0 else -1 endif)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(h,r): ret=r+h if ret!=0 : ret//=abs(ret) return ret def main(): h,r=map(int,input().split()) print(f(h,r)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation f(h : OclAny, r : OclAny) : OclAny pre: true post: true activity: var ret : OclAny := r + h ; if ret /= 0 then ( ret := ret div (ret)->abs() ) else skip ; return ret; operation main() pre: true post: true activity: Sequence{h,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (f(h, r))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p=sum([int(s)for s in input().split()]) if p==0 : print(0) elif p<0 : print(-1) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : OclAny := (input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())))->sum() ; if p = 0 then ( execute (0)->display() ) else (if p < 0 then ( execute (-1)->display() ) else ( execute (1)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- code=""" $x=<>; print($x**3,"\n"); """ import os,tempfile (_,filename)=tempfile.mkstemp(".pl") f=open(filename,"w") f.write(code) f.close() os.system("perl{}".format(filename)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var code : String := (atom "" "\r\n$x=<>;\r\nprint($x**3," ");\r\n" "") ; skip ; var Sequence{_anon, filename} : OclAny := tempfile.mkstemp(".pl") ; var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(filename)) ; f.write(code) ; f.closeFile() ; os.system(StringLib.interpolateStrings("perl{}", Sequence{filename})); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=sum(list(map(int,input().split()))) if i==0 : print("0") elif i>0 : print("1") else : print("-1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : OclAny := (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->sum() ; if i = 0 then ( execute ("0")->display() ) else (if i > 0 then ( execute ("1")->display() ) else ( execute ("-1")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=input().split() a=int(a) b=int(b) c=int(c) if a<=c and c<=b : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := input().split() ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; var c : int := ("" + ((c)))->toInteger() ; if (a->compareTo(c)) <= 0 & (c->compareTo(b)) <= 0 then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,R=map(int,input().split()) print(0 if H+R==0 else(1 if 0<=H+R else-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var R : OclAny := null; Sequence{H,R} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if H + R = 0 then 0 else (if 0 <= H + R then 1 else -1 endif) endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) import math sum=0 modulo=1073741824*pow(2,30) def factors(number): if number==1 : counter=1 return counter counter=2 for i in range(2,int(math.sqrt((number))+1)): if number % i==0 : if i*i==number : counter+=1 else : counter+=2 return counter from collections import defaultdict factor=defaultdict(int) for a in range(1,a+1): for b in range(1,b+1): for c in range(1,c+1): multiplication=a*b*c if multiplication not in factor : factor[multiplication]=factors(multiplication) sum+=factor[multiplication] sum %=modulo print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; var sum : int := 0 ; var modulo : double := 1073741824 * (2)->pow(30) ; skip ; skip ; var factor : OclAny := defaultdict(OclType["int"]) ; for a : Integer.subrange(1, a + 1-1) do ( for b : Integer.subrange(1, b + 1-1) do ( for c : Integer.subrange(1, c + 1-1) do ( var multiplication : double := a * b * c ; if (factor)->excludes(multiplication) then ( factor[multiplication+1] := factors(multiplication) ) else skip ; sum := sum + factor[multiplication+1] ; sum := sum mod modulo))) ; execute (sum)->display(); operation factors(number : OclAny) : OclAny pre: true post: true activity: if number = 1 then ( var counter : int := 1 ; return counter ) else skip ; counter := 2 ; for i : Integer.subrange(2, ("" + ((((number))->sqrt() + 1)))->toInteger()-1) do ( if number mod i = 0 then ( if i * i = number then ( counter := counter + 1 ) else ( counter := counter + 2 ) ) else skip) ; return counter; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- primes=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97] def divisor(num): res=1 for i in primes : n_div=1 if num=i : num/=i n_div+=1 res*=n_div return res a,b,c=map(int,input().split()) y=0 dict1={} for i in range(1,a+1): for j in range(1,b+1): for k in range(1,c+1): d=i*j*k if d not in dict1 : dict1[d]=divisor(d) y+=dict1[d] print(y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var primes : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{11}->union(Sequence{13}->union(Sequence{17}->union(Sequence{19}->union(Sequence{23}->union(Sequence{29}->union(Sequence{31}->union(Sequence{37}->union(Sequence{41}->union(Sequence{43}->union(Sequence{47}->union(Sequence{53}->union(Sequence{59}->union(Sequence{61}->union(Sequence{67}->union(Sequence{71}->union(Sequence{73}->union(Sequence{79}->union(Sequence{83}->union(Sequence{89}->union(Sequence{ 97 })))))))))))))))))))))))) ; skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var y : int := 0 ; var dict1 : OclAny := Set{} ; for i : Integer.subrange(1, a + 1-1) do ( for j : Integer.subrange(1, b + 1-1) do ( for k : Integer.subrange(1, c + 1-1) do ( var d : double := i * j * k ; if (dict1)->excludes(d) then ( dict1[d+1] := divisor(d) ) else skip ; y := y + dict1[d+1]))) ; execute (y)->display(); operation divisor(num : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; for i : primes do ( var n_div : int := 1 ; if (num->compareTo(i)) < 0 then ( break ) else skip ; while num mod i = 0 & (num->compareTo(i)) >= 0 do ( num := num / i ; n_div := n_div + 1) ; res := res * n_div) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin primes=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97] def find_div(num): res=1 for i in primes : n_div=1 if num=i : num/=i n_div+=1 res*=n_div return res def get_data(a,b,c): suma=0 already_check={} for i in range(1,a+1): for j in range(1,b+1): for k in range(1,c+1): d=j*k*i if d not in already_check : already_check[d]=find_div(d) suma+=already_check[d] return suma def main(): [a,b,c]=[int(x)for x in stdin.readline().split()] print(get_data(a,b,c)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var primes : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{11}->union(Sequence{13}->union(Sequence{17}->union(Sequence{19}->union(Sequence{23}->union(Sequence{29}->union(Sequence{31}->union(Sequence{37}->union(Sequence{41}->union(Sequence{43}->union(Sequence{47}->union(Sequence{53}->union(Sequence{59}->union(Sequence{61}->union(Sequence{67}->union(Sequence{71}->union(Sequence{73}->union(Sequence{79}->union(Sequence{83}->union(Sequence{89}->union(Sequence{ 97 })))))))))))))))))))))))) ; skip ; skip ; skip ; main(); operation find_div(num : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; for i : primes do ( var n_div : int := 1 ; if (num->compareTo(i)) < 0 then ( break ) else skip ; while num mod i = 0 & (num->compareTo(i)) >= 0 do ( num := num / i ; n_div := n_div + 1) ; res := res * n_div) ; return res; operation get_data(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: var suma : int := 0 ; var already_check : OclAny := Set{} ; for i : Integer.subrange(1, a + 1-1) do ( for j : Integer.subrange(1, b + 1-1) do ( for k : Integer.subrange(1, c + 1-1) do ( var d : double := j * k * i ; if (already_check)->excludes(d) then ( already_check[d+1] := find_div(d) ) else skip ; suma := suma + already_check[d+1]))) ; return suma; operation main() pre: true post: true activity: ; Sequence{a}->union(Sequence{b}->union(Sequence{ c })) := stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (get_data(a, b, c))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import time import math def div(x,y,z): n=x*y*z if n in d : return d[n] ans=0 for i in range(1,math.floor(math.sqrt(n))+1): if n % i==0 : ans+=2 if math.floor(math.sqrt(n))==math.sqrt(n): ans-=1 d[n]=ans return ans d={} M=1073741824 a,b,c=map(int,input().split()) ans=0 for i in range(a): for j in range(b): for k in range(c): ans+=div(i+1,j+1,k+1)% M print(ans % M) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var d : OclAny := Set{} ; var M : int := 1073741824 ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; ans := 0 ; for i : Integer.subrange(0, a-1) do ( for j : Integer.subrange(0, b-1) do ( for k : Integer.subrange(0, c-1) do ( ans := ans + div(i + 1, j + 1, k + 1) mod M))) ; execute (ans mod M)->display(); operation div(x : OclAny, y : OclAny, z : OclAny) : OclAny pre: true post: true activity: var n : double := x * y * z ; if (d)->includes(n) then ( return d[n+1] ) else skip ; var ans : int := 0 ; for i : Integer.subrange(1, ((n)->sqrt())->floor() + 1-1) do ( if n mod i = 0 then ( ans := ans + 2 ) else skip) ; if ((n)->sqrt())->floor() = (n)->sqrt() then ( ans := ans - 1 ) else skip ; d[n+1] := ans ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict import math primes=[dict()for _ in range(101)] for i in range(2,100+1): if len(primes[i])==0 : p=i primes[p][p]=1 for j in range(p*2,100+1,p): divisible_by=p power=1 while j %(divisible_by*p)==0 : power+=1 divisible_by*=p primes[j][p]=power a,b,c=map(int,input().split()) result=0 for i in range(1,a+1): for j in range(1,b+1): for k in range(1,c+1): sum_of_primes_power=defaultdict(int) for prime,power in primes[i].items(): sum_of_primes_power[prime]+=power for prime,power in primes[j].items(): sum_of_primes_power[prime]+=power for prime,power in primes[k].items(): sum_of_primes_power[prime]+=power total=1 for prime,power in sum_of_primes_power.items(): total*=power+1 result+=total result %=1073741824 print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var primes : Sequence := Integer.subrange(0, 101-1)->select(_anon | true)->collect(_anon | ((arguments ( )))) ; for i : Integer.subrange(2, 100 + 1-1) do ( if (primes[i+1])->size() = 0 then ( var p : OclAny := i ; primes[p+1][p+1] := 1 ; for j : Integer.subrange(p * 2, 100 + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( var divisible_by : OclAny := p ; var power : int := 1 ; while j mod (divisible_by * p) = 0 do ( power := power + 1 ; divisible_by := divisible_by * p) ; primes[j+1][p+1] := power) ) else skip) ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var result : int := 0 ; for i : Integer.subrange(1, a + 1-1) do ( for j : Integer.subrange(1, b + 1-1) do ( for k : Integer.subrange(1, c + 1-1) do ( var sum_of_primes_power : OclAny := defaultdict(OclType["int"]) ; for _tuple : primes[i+1]->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var prime : OclAny := _tuple->at(_indx); _indx := _indx + 1; var power : OclAny := _tuple->at(_indx); sum_of_primes_power[prime+1] := sum_of_primes_power[prime+1] + power) ; for _tuple : primes[j+1]->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var prime : OclAny := _tuple->at(_indx); _indx := _indx + 1; var power : OclAny := _tuple->at(_indx); sum_of_primes_power[prime+1] := sum_of_primes_power[prime+1] + power) ; for _tuple : primes[k+1]->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var prime : OclAny := _tuple->at(_indx); _indx := _indx + 1; var power : OclAny := _tuple->at(_indx); sum_of_primes_power[prime+1] := sum_of_primes_power[prime+1] + power) ; var total : int := 1 ; for _tuple : sum_of_primes_power->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var prime : OclAny := _tuple->at(_indx); _indx := _indx + 1; var power : OclAny := _tuple->at(_indx); total := total * power + 1) ; result := result + total ; result := result mod 1073741824))) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findRemainder(n): x=n & 3 return x if __name__=='__main__' : N=43 ans=findRemainder(N) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var N : int := 43 ; var ans : OclAny := findRemainder(N) ; execute (ans)->display() ) else skip; operation findRemainder(n : OclAny) : OclAny pre: true post: true activity: var x : int := MathLib.bitwiseAnd(n, 3) ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ReverseCharBridge(n): for i in range(n): for j in range(ord('A'),ord('A')+(2*n)-1): if j>=(ord('A')+n-1)+i : print(chr((ord('A')+n-1)-(j %(ord('A')+n-1))),end='') elif j<=(ord('A')+n-1)-i : print(chr(j),end='') else : print(end=" ") print("\n",end='') n=6 ReverseCharBridge(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 6 ; ReverseCharBridge(n); operation ReverseCharBridge(n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(('A')->char2byte(), ('A')->char2byte() + (2 * n) - 1-1) do ( if (j->compareTo((('A')->char2byte() + n - 1) + i)) >= 0 then ( execute (((('A')->char2byte() + n - 1) - (j mod (('A')->char2byte() + n - 1)))->byte2char())->display() ) else (if (j->compareTo((('A')->char2byte() + n - 1) - i)) <= 0 then ( execute ((j)->byte2char())->display() ) else ( execute ((argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom " ")))))))->display() ) ) ) ; execute ("\n")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k,r=[int(x)for x in input().split()] b=10 c=1 while True : l=c*k rem=l % b if rem==0 : print(c) break elif rem==r : print(c) break c+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : OclAny := null; var r : OclAny := null; Sequence{k,r} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var b : int := 10 ; var c : int := 1 ; while true do ( var l : double := c * k ; var rem : int := l mod b ; if rem = 0 then ( execute (c)->display() ; break ) else (if rem = r then ( execute (c)->display() ; break ) else skip) ; c := c + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : print(int(input())**3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger())->pow(3))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B,C=map(int,open(0).readline().split()) print('Yes' if A<=C<=B else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{A,B,C} := (open(0).readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if (A->compareTo(C)) <= 0 & (C <= B) then 'Yes' else 'No' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) c=a count=1 while a % 10!=0 and a % 10!=b : count+=1 a+=c print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : OclAny := a ; var count : int := 1 ; while a mod 10 /= 0 & a mod 10 /= b do ( count := count + 1 ; a := a + c) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k,r=[int(i)for i in input().strip().split()] t=k % 10 a=t ans=10 for i in range(1,10): if t==r or t==0 : ans=i break t+=a t %=10 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : OclAny := null; var r : OclAny := null; Sequence{k,r} := input()->trim().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var t : int := k mod 10 ; var a : int := t ; var ans : int := 10 ; for i : Integer.subrange(1, 10-1) do ( if t = r or t = 0 then ( ans := i ; break ) else skip ; t := t + a ; t := t mod 10) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=input().split() a=1 while int(n)*a % 10!=int(k)and int(n)*a % 10 : a+=1 print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split() ; var a : int := 1 ; while ("" + ((n)))->toInteger() * a mod 10 /= ("" + ((k)))->toInteger() & ("" + ((n)))->toInteger() * a mod 10 do ( a := a + 1) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k,c=map(int,input().split()) for ii in range(1,11): if(k*ii)% 10==0 or(k*ii-c)% 10==0 : print(ii) break else : continue ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : OclAny := null; var c : OclAny := null; Sequence{k,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for ii : Integer.subrange(1, 11-1) do ( if (k * ii) mod 10 = 0 or (k * ii - c) mod 10 = 0 then ( execute (ii)->display() ; break ) else ( continue )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,x=map(int,input().split()) w=list(map(int,input().split())) if sum(w)==x : print('NO') else : print('YES') j=0 s=0 while jtoInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (w)->sum() = x then ( execute ('NO')->display() ) else ( execute ('YES')->display() ; var j : int := 0 ; var s : int := 0 ; while (j->compareTo(n)) < 0 do ( s := s + w[j+1] ; if s = x then ( var w[j+1] : OclAny := null; var w[j + 1+1] : OclAny := null; Sequence{w[j+1],w[j + 1+1]} := Sequence{w[j + 1+1],w[j+1]} ; break ) else skip ; j := j + 1) ; execute ((argument * (test (logical_test (comparison (expr (atom (name w))))))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for j in range(t): n,x=map(int,input().split(' ')) w=list(map(int,input().split(' '))) w.sort() s=0 res=[] i=0 while(itoInteger() ; for j : Integer.subrange(0, t-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; w := w->sort() ; var s : int := 0 ; var res : Sequence := Sequence{} ; var i : int := 0 ; while ((i->compareTo(n)) < 0) do ( if (s + w[i+1] /= x) then ( s := s + w[i+1] ; execute ((w[i+1]) : res) ; i := i + 1 ) else (if ((i + 1->compareTo(n)) < 0) then ( execute ((w[i + 1+1]) : res) ; execute ((w[i+1]) : res) ; i := i + 2 ) else ( break ) ) ) ; if ((i->compareTo(n)) < 0) then ( execute ('NO')->display() ) else ( execute ('YES')->display() ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name res)))))))), ' '))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect def codeforces(weight,x,n): weight.sort() res=[] s=0 for i in weight : s+=i res.append(s) ind=bisect.bisect(res,x) if ind==n : if res[ind-1]==x : print('NO') else : print('YES') for i in weight : print(i,end='') print('') elif ind==0 : print('YES') for i in weight : print(i,end='') print('') else : print('YES') if res[ind-1]==x : for i in range(ind-1): print(weight[i],end='') for i in range(n-1,ind-2,-1): print(weight[i],end='') else : for i in range(n): print(weight[i],end='') print('') t=int(input()) for test in range(t): n,x=map(int,input().split()) weight=[int(i)for i in input().split()] codeforces(weight,x,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for test : Integer.subrange(0, t-1) do ( Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; weight := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; codeforces(weight, x, n)); operation codeforces(weight : OclAny, x : OclAny, n : OclAny) pre: true post: true activity: weight := weight->sort() ; var res : Sequence := Sequence{} ; var s : int := 0 ; for i : weight do ( s := s + i ; execute ((s) : res)) ; var ind : OclAny := bisect.bisect(res, x) ; if ind = n then ( if res[ind - 1+1] = x then ( execute ('NO')->display() ) else ( execute ('YES')->display() ; for i : weight do ( execute (i)->display()) ; execute ('')->display() ) ) else (if ind = 0 then ( execute ('YES')->display() ; for i : weight do ( execute (i)->display()) ; execute ('')->display() ) else ( execute ('YES')->display() ; if res[ind - 1+1] = x then ( for i : Integer.subrange(0, ind - 1-1) do ( execute (weight[i+1])->display()) ; for i : Integer.subrange(ind - 2 + 1, n - 1)->reverse() do ( execute (weight[i+1])->display()) ) else ( for i : Integer.subrange(0, n-1) do ( execute (weight[i+1])->display()) ) ; execute ('')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import* from math import* from decimal import* from collections import* import numbers from operator import index import sys def _input(): return map(int,input().split()) def _list(): return list(map(int,input().split())) def _int(): return int(input()) def solves(): n,m=_input() lst=sorted(_list()) if n==1 and lst[0]==m : print("NO") elif sum(lst)==m : print("NO") elif(sum(lst)toInteger() ; for _anon : Integer.subrange(0, t-1) do ( solves()); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation _list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation _int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation solves() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := _input() ; var lst : Sequence := _list()->sort() ; if n = 1 & lst->first() = m then ( execute ("NO")->display() ) else (if (lst)->sum() = m then ( execute ("NO")->display() ) else (if (((lst)->sum()->compareTo(m)) < 0) then ( execute ("YES")->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name lst))))))))->display() ) else ( execute ("YES")->display() ; var s : int := 0 ; for i : Integer.subrange(0, n-1) do ( s := s + lst[i+1] ; if (s = m) then ( s := s - lst[i+1] ; s := s + lst[i + 1+1] ; var lst[i+1] : OclAny := null; var lst[i + 1+1] : OclAny := null; Sequence{lst[i+1],lst[i + 1+1]} := Sequence{lst[i + 1+1],lst[i+1]} ) else skip ; execute (lst[i+1])->display()) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,x=map(int,input().split()) l=list(map(int,input().split())) if sum(l)==x or min(l)==max(l)==x : print('NO') elif sum(l)toInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (l)->sum() = x or (l)->min() = (l)->max() & ((l)->max() == x) then ( execute ('NO')->display() ) else (if ((l)->sum()->compareTo(x)) < 0 then ( execute ('YES')->display() ; execute (StringLib.sumStringsWithSeparator(((l)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ) else ( var r : Sequence := Sequence{} ; var total : int := 0 ; while l do ( var num : OclAny := l->last() + total ; if num = x then ( total := total + l->first() ; execute ((l->first()) : r) ; execute ((l->first()) /: l) ) else ( total := total + l->last() ; execute ((l->last()) : r) )) ; execute ('YES')->display() ; execute (StringLib.sumStringsWithSeparator(((r)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a=[list(map(int,input().split()))for i in range(2)] cnt=sum([sum(a[i])for i in range(2)]) if cnt==0 : print(0) elif cnt==4 : print(2) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : Sequence := Integer.subrange(0, 2-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var cnt : OclAny := (Integer.subrange(0, 2-1)->select(i | true)->collect(i | ((a[i+1])->sum())))->sum() ; if cnt = 0 then ( execute (0)->display() ) else (if cnt = 4 then ( execute (2)->display() ) else ( execute (1)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import deque,defaultdict,Counter from itertools import accumulate,product,permutations,combinations from operator import itemgetter from bisect import bisect_left,bisect_right from heapq import heappop,heappush from math import ceil,floor,sqrt,gcd,inf from copy import deepcopy import numpy as np import scipy as sp INF=inf MOD=1000000007 k=int(input()) tmp=0 res="" for i in range(k): res+="ACL" print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var INF : double := Math_PINFINITY ; var MOD : int := 1000000007 ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var tmp : int := 0 ; var res : String := "" ; for i : Integer.subrange(0, k-1) do ( res := res + "ACL") ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) print(["No","Yes"][a<=c<=b]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Sequence{"No"}->union(Sequence{ "Yes" })->select((a->compareTo(c)) <= 0 & (c <= b)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t=int(input()) ans=[] for _ in range(t): l,r,m=map(int,input().split()) d=r-l ok=0 for i in range(l,r+1): n=m//i for _ in range(2): d0=abs(i*n-m) if d0<=d and n : ok=1 a=i if i*n-m>0 : b,c=r-d0,r else : b,c=r,r-d0 break n+=1 if ok : break ans.append(" ".join(map(str,(a,b,c)))) sys.stdout.write("\n".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, t-1) do ( var l : OclAny := null; var r : OclAny := null; var m : OclAny := null; Sequence{l,r,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : double := r - l ; var ok : int := 0 ; for i : Integer.subrange(l, r + 1-1) do ( var n : int := m div i ; for _anon : Integer.subrange(0, 2-1) do ( var d0 : double := (i * n - m)->abs() ; if (d0->compareTo(d)) <= 0 & n then ( ok := 1 ; var a : OclAny := i ; if i * n - m > 0 then ( var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := Sequence{r - d0,r} ) else ( var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := Sequence{r,r - d0} ) ; break ) else skip ; n := n + 1) ; if ok then ( break ) else skip) ; execute ((StringLib.sumStringsWithSeparator(((Sequence{a, b, c})->collect( _x | (OclType["String"])->apply(_x) )), " ")) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): s=0 for i in range(2): s+=sum(list(map(int,input().split()))) if s==0 : print(0) elif s==4 : print(2) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : int := 0 ; for i : Integer.subrange(0, 2-1) do ( s := s + (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->sum()) ; if s = 0 then ( execute (0)->display() ) else (if s = 4 then ( execute (2)->display() ) else ( execute (1)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) lst=[] for i in range(t): a1,a2=map(int,input().split()) b1,b2=map(int,input().split()) lst.append([a1,a2,b1,b2]) cnt=lst[0].count(1) if cnt==0 : print(0) elif cnt==4 : print(2) else : print(1) lst.clear() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( var a1 : OclAny := null; var a2 : OclAny := null; Sequence{a1,a2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b1 : OclAny := null; var b2 : OclAny := null; Sequence{b1,b2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a1}->union(Sequence{a2}->union(Sequence{b1}->union(Sequence{ b2 })))) : lst) ; var cnt : OclAny := lst->first()->count(1) ; if cnt = 0 then ( execute (0)->display() ) else (if cnt = 4 then ( execute (2)->display() ) else ( execute (1)->display() ) ) ; execute (lst /<: lst)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): arr1=list(map(int,input().split())) arr2=list(map(int,input().split())) if(arr1[0]==0 and arr1[1]==0 and arr2[0]==0 and arr2[1]==0): print(0) elif(arr1[0]==1 and arr1[1]==1 and arr2[0]==1 and arr2[1]==1): print(2) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var arr1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var arr2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (arr1->first() = 0 & arr1[1+1] = 0 & arr2->first() = 0 & arr2[1+1] = 0) then ( execute (0)->display() ) else (if (arr1->first() = 1 & arr1[1+1] = 1 & arr2->first() = 1 & arr2[1+1] = 1) then ( execute (2)->display() ) else ( execute (1)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a=[list(map(int,input().split()))for i in range(2)] cnt=sum([sum(a[i])for i in range(2)]) if cnt==0 : print(0) elif cnt==4 : print(2) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : Sequence := Integer.subrange(0, 2-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var cnt : OclAny := (Integer.subrange(0, 2-1)->select(i | true)->collect(i | ((a[i+1])->sum())))->sum() ; if cnt = 0 then ( execute (0)->display() ) else (if cnt = 4 then ( execute (2)->display() ) else ( execute (1)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def findMaxConsecutiveOnes(self,nums): ans=0 curr=0 for n in nums : if n==1 : curr+=1 if curr>ans : ans=curr else : curr=0 return ans ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation findMaxConsecutiveOnes(nums : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; var curr : int := 0 ; for n : nums do ( if n = 1 then ( curr := curr + 1 ; if (curr->compareTo(ans)) > 0 then ( ans := curr ) else skip ) else ( curr := 0 )) ; return ans; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def setBitNumber(n): if(n==0): return 0 ; msb=0 ; while(n>0): n=int(n/2); msb+=1 ; return(1<display();; operation setBitNumber(n : OclAny) pre: true post: true activity: if (n = 0) then ( return 0; ) else skip ; var msb : int := 0; ; while (n > 0) do ( n := ("" + ((n / 2)))->toInteger(); ; msb := msb + 1;) ; return (1 * (2->pow(msb)));; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w=map(int,input().split()) t=[list(input())for i in range(h)] def check(x,y): dx=[0,0,1,-1] dy=[1,-1,0,0] jugde=False for k in range(4): i=x+dx[k] j=y+dy[k] if 0<=i and icollect( _x | (OclType["int"])->apply(_x) ) ; var t : Sequence := Integer.subrange(0, h-1)->select(i | true)->collect(i | (((OclFile["System.in"]).readLine())->characters())) ; skip ; for i : Integer.subrange(0, h-1) do ( for j : Integer.subrange(0, w-1) do ( if t[i+1][j+1] = "#" then ( if check(i, j) then ( jugde := true ) else ( execute ("No")->display() ; exit() ) ) else skip)) ; execute ("Yes")->display(); operation check(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var dx : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ -1 }))) ; var dy : Sequence := Sequence{1}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{ 0 }))) ; var jugde : boolean := false ; for k : Integer.subrange(0, 4-1) do ( var i : OclAny := x + dx[k+1] ; var j : OclAny := y + dy[k+1] ; if 0 <= i & (i->compareTo(h)) < 0 & 0 <= j & (j->compareTo(w)) < 0 & t[i+1][j+1] = "#" then ( jugde := true ) else skip) ; if jugde = false then ( return false ) else skip ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W=map(int,input().split()) campus=[] for i in range(H): campus.append(list(input())) def search_lonely_sharp(l : list)->list : _lonely_sharps=[] ls=['.']+l+['.'] for i in range(1,len(ls)-1): if ls[i]=='#' and ls[i]!=ls[i-1]and ls[i]!=ls[i+1]: _lonely_sharps.append(i-1) return _lonely_sharps for i in range(1,H-1): before_line=campus[i-1] line=campus[i] after_line=campus[i+1] lonely_sharps=search_lonely_sharp(line) for j in lonely_sharps : if before_line[j]!='#' and after_line[j]!='#' : print('No') exit() print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var campus : Sequence := Sequence{} ; for i : Integer.subrange(0, H-1) do ( execute ((((OclFile["System.in"]).readLine())->characters()) : campus)) ; skip ; for i : Integer.subrange(1, H - 1-1) do ( var before_line : OclAny := campus[i - 1+1] ; var line : OclAny := campus[i+1] ; var after_line : OclAny := campus[i + 1+1] ; var lonely_sharps : OclAny := search_lonely_sharp(line) ; for j : lonely_sharps do ( if before_line[j+1] /= '#' & after_line[j+1] /= '#' then ( execute ('No')->display() ; exit() ) else skip)) ; execute ('Yes')->display(); operation search_lonely_sharp(l : Sequence(OclAny)) : Sequence pre: true post: true activity: var _lonely_sharps : Sequence := Sequence{} ; var ls : Sequence := Sequence{ '.' }->union(l)->union(Sequence{ '.' }) ; for i : Integer.subrange(1, (ls)->size() - 1-1) do ( if ls[i+1] = '#' & ls[i+1] /= ls[i - 1+1] & ls[i+1] /= ls[i + 1+1] then ( execute ((i - 1) : _lonely_sharps) ) else skip) ; return _lonely_sharps; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w=list(map(int,input().split())) rows=[input()for i in range(h)] grid=[list(row)for row in rows] expanded_grid=[] expanded_grid.append(list('&'*(w+2))) for row in rows : expanded_grid.append(list('&'+row+'&')) expanded_grid.append(list('&'*(w+2))) judge=True for i in range(h): for j in range(w): if(grid[i])[j]=='#' : nearby=[(expanded_grid[i])[j+1],(expanded_grid[i+1])[j],(expanded_grid[i+1])[j+2],(expanded_grid[i+2])[j+1]] if nearby.count('#')==0 : judge=False if judge : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var rows : Sequence := Integer.subrange(0, h-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var grid : Sequence := rows->select(row | true)->collect(row | ((row))) ; var expanded_grid : Sequence := Sequence{} ; execute (((StringLib.nCopies('&', (w + 2)))->characters()) : expanded_grid) ; for row : rows do ( execute ((('&' + row + '&')->characters()) : expanded_grid)) ; execute (((StringLib.nCopies('&', (w + 2)))->characters()) : expanded_grid) ; var judge : boolean := true ; for i : Integer.subrange(0, h-1) do ( for j : Integer.subrange(0, w-1) do ( if (grid[i+1])[j+1] = '#' then ( var nearby : Sequence := Sequence{(expanded_grid[i+1])[j + 1+1]}->union(Sequence{(expanded_grid[i + 1+1])[j+1]}->union(Sequence{(expanded_grid[i + 1+1])[j + 2+1]}->union(Sequence{ (expanded_grid[i + 2+1])[j + 1+1] }))) ; if nearby->count('#') = 0 then ( judge := false ) else skip ) else skip)) ; if judge then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def decToBinary(n): binaryNum=[0 for i in range(32)] i=0 while(n>0): binaryNum[i]=n % 2 n=n//2 i+=1 binary="" for j in range(i-1,-1,-1): binary+=str(binaryNum[j]) return binary def countFreq(pat,txt): M=len(pat) N=len(txt) res=0 for i in range(N-M+1): j=0 while(junion(Sequence{106}->union(Sequence{7}->union(Sequence{ 8 }))) ; pattern := "10" ; n := (arr)->size() ; findOccurrence(arr, n, pattern); operation decToBinary(n : OclAny) : OclAny pre: true post: true activity: var binaryNum : Sequence := Integer.subrange(0, 32-1)->select(i | true)->collect(i | (0)) ; var i : int := 0 ; while (n > 0) do ( binaryNum[i+1] := n mod 2 ; n := n div 2 ; i := i + 1) ; var binary : String := "" ; for j : Integer.subrange(-1 + 1, i - 1)->reverse() do ( binary := binary + ("" + ((binaryNum[j+1])))) ; return binary; operation countFreq(pat : OclAny, txt : OclAny) : OclAny pre: true post: true activity: var M : int := (pat)->size() ; var N : int := (txt)->size() ; var res : int := 0 ; for i : Integer.subrange(0, N - M + 1-1) do ( var j : int := 0 ; while ((j->compareTo(M)) < 0) do ( if (txt[i + j+1] /= pat[j+1]) then ( break ) else skip ; j := j + 1) ; if (j = M) then ( res := res + 1 ; j := 0 ) else skip) ; return res; operation findOccurrence(arr : OclAny, n : OclAny, pattern : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( binary := decToBinary(arr[i+1]) ; execute (countFreq(pattern, binary))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import heapq import math import fractions import bisect import itertools from collections import Counter from collections import deque from operator import itemgetter def input(): return sys.stdin.readline().strip() def mp(): return map(int,input().split()) def lmp(): return list(map(int,input().split())) h,w=mp() g=["."*(w+2)] for i in range(h): g.append("."+input()+".") g.append("."*(w+2)) v=[[1,0],[-1,0],[0,1],[0,-1]] for i in range(1,h+1): for j in range(1,w+1): if g[i][j]=="#" : c=True for x,y in v : if g[i+x][j+y]=="#" : c=False if c : print("No") exit() print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := mp() ; var g : Sequence := Sequence{ StringLib.nCopies(".", (w + 2)) } ; for i : Integer.subrange(0, h-1) do ( execute (("." + (OclFile["System.in"]).readLine() + ".") : g)) ; execute ((StringLib.nCopies(".", (w + 2))) : g) ; var v : Sequence := Sequence{Sequence{1}->union(Sequence{ 0 })}->union(Sequence{Sequence{-1}->union(Sequence{ 0 })}->union(Sequence{Sequence{0}->union(Sequence{ 1 })}->union(Sequence{ Sequence{0}->union(Sequence{ -1 }) }))) ; for i : Integer.subrange(1, h + 1-1) do ( for j : Integer.subrange(1, w + 1-1) do ( if g[i+1][j+1] = "#" then ( var c : boolean := true ; for _tuple : v do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if g[i + x+1][j + y+1] = "#" then ( c := false ) else skip) ; if c then ( execute ("No")->display() ; exit() ) else skip ) else skip)) ; execute ("Yes")->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation mp() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation lmp() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().rstrip() def solve(): l,r,m=map(int,input().split()) for a in range(l,r+1): if(((m+r-l)% a)<=2*(r-l)): p=(m+r-l)% a-(r-l) print(a,max(p,0)+l,max(-p,0)+l) return T=int(input()) for i in range(T): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; skip ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, T-1) do ( solve()); operation solve() pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; var m : OclAny := null; Sequence{l,r,m} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for a : Integer.subrange(l, r + 1-1) do ( if ((((m + r - l) mod a)->compareTo(2 * (r - l))) <= 0) then ( var p : double := (m + r - l) mod a - (r - l) ; execute (a)->display() ; return ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W=(int(i)for i in input().split()) t=[] t.append(['.']*(H+2)) for j in range(H): tmp=input() tmp='.'+tmp+'.' t.append(list(tmp)) t.append(['.']*(H+2)) def CheckBlock(i,k): if t[i][k-1]=='#' : return 0 elif t[i-1][k]=='#' : return 1 elif t[i+1][k]=='#' : return 2 elif t[i][k+1]=='#' : return 3 else : return 4 for k in range(1,W+1): for i in range(1,H+1): if t[i][k]=='#' : marker=CheckBlock(i,k) if marker==4 : print('No') quit() print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var t : Sequence := Sequence{} ; execute ((MatrixLib.elementwiseMult(Sequence{ '.' }, (H + 2))) : t) ; for j : Integer.subrange(0, H-1) do ( var tmp : String := (OclFile["System.in"]).readLine() ; tmp := '.' + tmp + '.' ; execute (((tmp)->characters()) : t)) ; execute ((MatrixLib.elementwiseMult(Sequence{ '.' }, (H + 2))) : t) ; skip ; for k : Integer.subrange(1, W + 1-1) do ( for i : Integer.subrange(1, H + 1-1) do ( if t[i+1][k+1] = '#' then ( var marker : OclAny := CheckBlock(i, k) ; if marker = 4 then ( execute ('No')->display() ; quit() ) else skip ) else skip)) ; execute ('Yes')->display(); operation CheckBlock(i : OclAny, k : OclAny) : OclAny pre: true post: true activity: if t[i+1][k - 1+1] = '#' then ( return 0 ) else (if t[i - 1+1][k+1] = '#' then ( return 1 ) else (if t[i + 1+1][k+1] = '#' then ( return 2 ) else (if t[i+1][k + 1+1] = '#' then ( return 3 ) else ( return 4 ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq N,W=[int(n)for n in input().split()] tmpw=0 tmpv=0 minheap=[] for i in range(N): w,v=[int(n)for n in input().split()] if(w<0): tmpw+=w tmpv+=v w*=-1 v*=-1 if(v>0): if w==0 : tmpv+=v else : heapq.heappush(minheap,(-(v/w),w,v)) while(W-tmpw>1e-9 and not minheap==[]): p=heapq.heappop(minheap) w=p[1] v=p[2] x=min(1,(W-tmpw)/w) tmpw+=x*w tmpv+=x*v print(tmpv) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var W : OclAny := null; Sequence{N,W} := input().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; var tmpw : int := 0 ; var tmpv : int := 0 ; var minheap : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var w : OclAny := null; var v : OclAny := null; Sequence{w,v} := input().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; if (w < 0) then ( tmpw := tmpw + w ; tmpv := tmpv + v ; w := w * -1 ; v := v * -1 ) else skip ; if (v > 0) then ( if w = 0 then ( tmpv := tmpv + v ) else ( heapq.heappush(minheap, Sequence{-(v / w), w, v}) ) ) else skip) ; while (W - tmpw > ("1e-9")->toReal() & not(minheap = Sequence{})) do ( var p : OclAny := heapq.heappop(minheap) ; var w : OclAny := p[1+1] ; var v : OclAny := p[2+1] ; var x : OclAny := Set{1, (W - tmpw) / w}->min() ; tmpw := tmpw + x * w ; tmpv := tmpv + x * v) ; execute (tmpv)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isVowel(c): c=c.lower() if(c=='a' or c=='e' or c=='i' or c=='o' or c=='u'): return True return False def firstXvowels(s,x): result="" for i in range(0,len(s),1): if(isVowel(s[i])): result+=s[i] if(len(result)==x): return result return "-1" if __name__=='__main__' : str="GeeksForGeeks" x=3 print(firstXvowels(str,x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var OclType["String"] : String := "GeeksForGeeks" ; x := 3 ; execute (firstXvowels(OclType["String"], x))->display() ) else skip; operation isVowel(c : OclAny) : OclAny pre: true post: true activity: c := c->toLowerCase() ; if (c = 'a' or c = 'e' or c = 'i' or c = 'o' or c = 'u') then ( return true ) else skip ; return false; operation firstXvowels(s : OclAny, x : OclAny) : OclAny pre: true post: true activity: var result : String := "" ; for i : Integer.subrange(0, (s)->size()-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (isVowel(s[i+1])) then ( result := result + s[i+1] ) else skip ; if ((result)->size() = x) then ( return result ) else skip) ; return "-1"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**8) n,*a=map(int,open(0).read().split()) lose_to=[[]for _ in range(n)] for i,x in enumerate(a,start=1): lose_to[x-1].append(i) def dfs(x): if not lose_to[x]: return 0 else : s=sorted([dfs(y)for y in lose_to[x]],reverse=True) return max(i+z for i,z in enumerate(s,start=1)) print(dfs(0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(8)) ; var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lose_to : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _tuple : Integer.subrange(1, (a, (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->size())->collect( _indx | Sequence{_indx-1, (a, (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); (expr (atom (name lose_to)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; skip ; execute (dfs(0))->display(); operation dfs(x : OclAny) : OclAny pre: true post: true activity: if not(lose_to[x+1]) then ( return 0 ) else ( var s : Sequence := lose_to[x+1]->select(y | true)->collect(y | (dfs(y)))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; return ((argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name z))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name z)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s))))))) , (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))))))->max() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,*A=[int(_)for _ in open(0).read().split()] win_lose={i : set()for i in range(1,N+1)} for win,lose in zip(A,range(2,N+1)): win_lose[win].add(lose) s1=[1] s2=[] while s1 : a=s1.pop() s2+=[a] for b in win_lose[a]: s1+=[b] dp=[0]*(N+1) for x in s2[: :-1]: if win_lose[x]==set(): dp[x]=0 else : dp[x]=max(a+b for a,b in zip(sorted(dp[y]for y in win_lose[x])[: :-1],range(1,N+1))) print(dp[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; Sequence{N,A} := open(0).readAll().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var win_lose : Map := Integer.subrange(1, N + 1-1)->select(i | true)->collect(i | Map{i |-> Set{}->union(())})->unionAll() ; for _tuple : Integer.subrange(1, A->size())->collect( _indx | Sequence{A->at(_indx), Integer.subrange(2, N + 1-1)->at(_indx)} ) do (var _indx : int := 1; var win : OclAny := _tuple->at(_indx); _indx := _indx + 1; var lose : OclAny := _tuple->at(_indx); (expr (atom (name win_lose)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name win)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name lose)))))))) ))))) ; var s1 : Sequence := Sequence{ 1 } ; var s2 : Sequence := Sequence{} ; while s1 do ( var a : OclAny := s1->last() ; s1 := s1->front() ; s2 := s2 + Sequence{ a } ; for b : win_lose[a+1] do ( s1 := s1 + Sequence{ b })) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; for x : s2(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if win_lose[x+1] = Set{}->union(()) then ( dp[x+1] := 0 ) else ( dp[x+1] := ((argument (test (logical_test (comparison (expr (expr (atom (name a))) + (expr (atom (name b))))))) (comp_for for (exprlist (expr (atom (name a))) , (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])))))) (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name win_lose)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))))))) ))) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name N))) + (expr (atom (number (integer 1)))))))))) ))))))))) )))))))))->max() )) ; execute (dp[1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys ; input=sys.stdin.buffer.readline sys.setrecursionlimit(10**7) from collections import defaultdict con=10**9+7 ; INF=float("inf") class Graph(object): def __init__(self): self.graph=defaultdict(list) def __len__(self): return len(self.graph) def add_edge(self,a,b): self.graph[a].append(b) def get_nodes(self): return self.graph.keys() def DFS(G,W,node): cnt=0 child=[] for i in G.graph[node]: DFS(G,W,i) child.append(W[i]) cnt+=1 child.sort() rev=[i for i in range(cnt,-1,-1)] weight=0 for i in range(cnt): weight=max(weight,rev[i]+child[i]) W[node]=weight def getlist(): return list(map(int,input().split())) def main(): N=int(input()) G=Graph() for i in range(N-1): a=int(input())-1 b=i+1 G.add_edge(a,b) W=[0]*N DFS(G,W,0) print(W[0]) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class Graph extends object { static operation newGraph() : Graph pre: true post: Graph->exists( _x | result = _x ); attribute graph : OclAny := defaultdict(OclType["Sequence"]); operation initialise() : pre: true post: true activity: self.graph := defaultdict(OclType["Sequence"]); return self; operation __len__() : OclAny pre: true post: true activity: return (self.graph)->size(); operation add_edge(a : OclAny,b : OclAny) pre: true post: true activity: (expr (atom (name self)) (trailer . (name graph) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))); operation get_nodes() : OclAny pre: true post: true activity: return self.graph.keys(); } class FromPython { operation initialise() pre: true post: true activity: skip; var input : OclAny := sys.stdin.buffer.readline ; sys.setrecursionlimit((10)->pow(7)) ; skip ; var con : double := (10)->pow(9) + 7; var INF : double := ("" + (("inf")))->toReal() ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation DFS(G : OclAny, W : OclAny, node : OclAny) pre: true post: true activity: var cnt : int := 0 ; var child : Sequence := Sequence{} ; for i : G.graph[node+1] do ( DFS(G, W, i) ; execute ((W[i+1]) : child) ; cnt := cnt + 1) ; child := child->sort() ; var rev : Sequence := Integer.subrange(-1 + 1, cnt)->reverse()->select(i | true)->collect(i | (i)) ; var weight : int := 0 ; for i : Integer.subrange(0, cnt-1) do ( weight := Set{weight, rev[i+1] + child[i+1]}->max()) ; W[node+1] := weight; operation getlist() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; G := (Graph.newGraph()).initialise() ; for i : Integer.subrange(0, N - 1-1) do ( a := ("" + (((OclFile["System.in"]).readLine())))->toInteger() - 1 ; b := i + 1 ; G.add_edge(a, b)) ; W := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; DFS(G, W, 0) ; execute (W->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from subprocess import* call(('python3','-c',""" import sys sys.setrecursionlimit(10**6) e=enumerate def dfs(v): d=sorted(map(dfs,t[v])) l=len(d) return max([0]+[l-i+d for i,d in e(d)]) n,*a=map(int,open(0)) t=[[]for _ in[0]+a] for i,v in e(a,1):t[v-1]+=i, print(dfs(0)) """)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; call(Sequence{'python3', '-c', (atom "" "\r\nimport sys\r\nsys.setrecursionlimit(10**6)\r\ne=enumerate\r\ndef dfs(v):\r\n d=sorted(map(dfs,t[v]))\r\n l=len(d)\r\n return max([0]+[l-i+d for i,d in e(d)])\r\nn,*a=map(int,open(0))\r\nt=[[]for _ in[0]+a]\r\nfor i,v in e(a,1):t[v-1]+=i,\r\nprint(dfs(0))\r\n" "")}); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(1000000) N=int(input()) edge={i :[]for i in range(1,N+1)} parent={i : 0 for i in range(1,N+1)} for i in range(0,N-1): a=int(input()) edge[a].append(i+2) edge[i+2].append(a) parent[i+2]=a memo={i :-1 for i in range(1,N+1)} def dp(num): if memo[num]!=-1 : return memo[num] if edge[num]==[parent[num]]: memo[num]=0 return memo[num] test=[] for i in edge[num]: if i!=parent[num]: test.append(dp(i)) test.sort(reverse=True) memo[num]=max(i+1+test[i]for i in range(0,len(test))) return memo[num] print(dp(1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(1000000) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var edge : Map := Integer.subrange(1, N + 1-1)->select(i | true)->collect(i | Map{i |-> Sequence{}})->unionAll() ; var parent : Map := Integer.subrange(1, N + 1-1)->select(i | true)->collect(i | Map{i |-> 0})->unionAll() ; for i : Integer.subrange(0, N - 1-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 2)))))))))) )))) ; (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 2)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))) ; parent[i + 2+1] := a) ; var memo : Map := Integer.subrange(1, N + 1-1)->select(i | true)->collect(i | Map{i |-> -1})->unionAll() ; skip ; execute (dp(1))->display(); operation dp(num : OclAny) : OclAny pre: true post: true activity: if memo[num+1] /= -1 then ( return memo[num+1] ) else skip ; if edge[num+1] = Sequence{ parent[num+1] } then ( memo[num+1] := 0 ; return memo[num+1] ) else skip ; var test : Sequence := Sequence{} ; for i : edge[num+1] do ( if i /= parent[num+1] then ( execute ((dp(i)) : test) ) else skip) ; test := test->sort() ; memo[num+1] := ((argument (test (logical_test (comparison (expr (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))) + (expr (atom (name test)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name test)))))))) ))))))))) )))))))))->max() ; return memo[num+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def makearrayequal(arr,n): x=0 ; for i in range(n): x+=arr[i]& 1 ; print(min(x,n-x)); if __name__=="__main__" : arr=[4,3,2,1]; n=len(arr); makearrayequal(arr,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{4}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 1 }))); ; n := (arr)->size(); ; makearrayequal(arr, n); ) else skip; operation makearrayequal(arr : OclAny, n : OclAny) pre: true post: true activity: var x : int := 0; ; for i : Integer.subrange(0, n-1) do ( x := x + MathLib.bitwiseAnd(arr[i+1], 1);) ; execute (Set{x, n - x}->min())->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def _input(): return map(int,input().split()) l1,r1,l2,r2,k=_input() m=max(l1,l2); M=min(r1,r2) if m>M : print(0) else : res=-m+M+1 if k>=m and k<=M : res-=1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var l1 : OclAny := null; var r1 : OclAny := null; var l2 : OclAny := null; var r2 : OclAny := null; var k : OclAny := null; Sequence{l1,r1,l2,r2,k} := _input() ; var m : OclAny := Set{l1, l2}->max(); var M : OclAny := Set{r1, r2}->min() ; if (m->compareTo(M)) > 0 then ( execute (0)->display() ) else ( var res : OclAny := -m + M + 1 ; if (k->compareTo(m)) >= 0 & (k->compareTo(M)) <= 0 then ( res := res - 1 ) else skip ; execute (res)->display() ); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- text=input() num=text.split(" ") num=[int(x)for x in num] l1=num[0] r1=num[1] l2=num[2] r2=num[3] k=num[4] if(l2>r1 or r2=max(l1,l2)and k<=min(r1,r2)): print(min(r1,r2)-max(l1,l2)) else : print(min(r1,r2)-max(l1,l2)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var text : String := (OclFile["System.in"]).readLine() ; var num : OclAny := text.split(" ") ; num := num->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var l1 : OclAny := num->first() ; var r1 : OclAny := num[1+1] ; var l2 : OclAny := num[2+1] ; var r2 : OclAny := num[3+1] ; var k : OclAny := num[4+1] ; if ((l2->compareTo(r1)) > 0 or (r2->compareTo(l1)) < 0) then ( execute (0)->display() ) else ( if ((k->compareTo(Set{l1, l2}->max())) >= 0 & (k->compareTo(Set{r1, r2}->min())) <= 0) then ( execute (Set{r1, r2}->min() - Set{l1, l2}->max())->display() ) else ( execute (Set{r1, r2}->min() - Set{l1, l2}->max() + 1)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): l,r,m=[int(__)for __ in input().split()] for i in range(l,r+1): if mtoInteger()-1) do ( var l : OclAny := null; var r : OclAny := null; var m : OclAny := null; Sequence{l,r,m} := input().split()->select(__ | true)->collect(__ | (("" + ((__)))->toInteger())) ; for i : Integer.subrange(l, r + 1-1) do ( if (m->compareTo(i)) < 0 then ( if (i - m mod i->compareTo(r - l)) <= 0 then ( execute (i)->display() ; break ) else skip ) else ( if (m mod i->compareTo(r - l)) <= 0 then ( execute (i)->display() ; break ) else (if (i - m mod i->compareTo(r - l)) <= 0 then ( execute (i)->display() ; break ) else skip) ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i1,r1,i2,r2,k=map(int,input().split()) if i2r1 : if i1<=k<=r1 : s=r1-i1 else : s=r1-i1+1 elif i1r2 : if i2<=k<=r2 : s=r2-i2 else : s=r2-i2+1 elif i2<=i1 and r2<=r1 : if i1<=k<=r2 : s=r2-i1 else : s=r2-i1+1 elif i2>=i1 and r2>=r1 : if i2<=k<=r1 : s=r1-i2 else : s=r1-i2+1 else : print("wrong input") if s<0 : print(0) else : print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i1 : OclAny := null; var r1 : OclAny := null; var i2 : OclAny := null; var r2 : OclAny := null; var k : OclAny := null; Sequence{i1,r1,i2,r2,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (i2->compareTo(i1)) < 0 & (r2->compareTo(r1)) > 0 then ( if (i1->compareTo(k)) <= 0 & (k <= r1) then ( var s : double := r1 - i1 ) else ( s := r1 - i1 + 1 ) ) else (if (i1->compareTo(i2)) < 0 & (r1->compareTo(r2)) > 0 then ( if (i2->compareTo(k)) <= 0 & (k <= r2) then ( s := r2 - i2 ) else ( s := r2 - i2 + 1 ) ) else (if (i2->compareTo(i1)) <= 0 & (r2->compareTo(r1)) <= 0 then ( if (i1->compareTo(k)) <= 0 & (k <= r2) then ( s := r2 - i1 ) else ( s := r2 - i1 + 1 ) ) else (if (i2->compareTo(i1)) >= 0 & (r2->compareTo(r1)) >= 0 then ( if (i2->compareTo(k)) <= 0 & (k <= r1) then ( s := r1 - i2 ) else ( s := r1 - i2 + 1 ) ) else ( execute ("wrong input")->display() ) ) ) ) ; if s < 0 then ( execute (0)->display() ) else ( execute (s)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(a,b,c,d): ans=min(b,d)-max(a,c) ans+=1 if ans<0 : ans=0 return ans def solve(a,b,c,d,e): if a>b : a,b=b,a if c>d : c,d=d,c ans=f(a,b,c,d) if e>=a and e<=b and e>=c and e<=d : ans-=1 return ans a,b,c,d,e=map(int,input().split()) print(solve(a,b,c,d,e)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{a,b,c,d,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (solve(a, b, c, d, e))->display(); operation f(a : OclAny, b : OclAny, c : OclAny, d : OclAny) : OclAny pre: true post: true activity: var ans : double := Set{b, d}->min() - Set{a, c}->max() ; ans := ans + 1 ; if ans < 0 then ( ans := 0 ) else skip ; return ans; operation solve(a : OclAny, b : OclAny, c : OclAny, d : OclAny, e : OclAny) : OclAny pre: true post: true activity: if (a->compareTo(b)) > 0 then ( Sequence{a,b} := Sequence{b,a} ) else skip ; if (c->compareTo(d)) > 0 then ( Sequence{c,d} := Sequence{d,c} ) else skip ; ans := f(a, b, c, d) ; if (e->compareTo(a)) >= 0 & (e->compareTo(b)) <= 0 & (e->compareTo(c)) >= 0 & (e->compareTo(d)) <= 0 then ( ans := ans - 1 ) else skip ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l1,l2,r1,r2,k=map(int,input().split()) if r1collect( _x | (OclType["int"])->apply(_x) ) ; if (r1->compareTo(l1)) < 0 & (r2->compareTo(l1)) < 0 then ( execute (0)->display() ) else ( if (r1->compareTo(l2)) <= 0 then ( if (r1->compareTo(l1)) <= 0 then ( if (r2->compareTo(l2)) <= 0 then ( if (l1->compareTo(k)) <= 0 & (k <= r2) then ( execute (r2 - l1)->display() ) else ( execute (r2 - l1 + 1)->display() ) ) else ( if (l1->compareTo(k)) <= 0 & (k <= l2) then ( execute (l2 - l1)->display() ) else ( execute (l2 - l1 + 1)->display() ) ) ) else ( if (r2->compareTo(l2)) <= 0 then ( if (r1->compareTo(k)) <= 0 & (k <= r2) then ( execute (r2 - r1)->display() ) else ( execute (r2 - r1 + 1)->display() ) ) else ( if (r1->compareTo(k)) <= 0 & (k <= l2) then ( execute (l2 - r1)->display() ) else ( execute (l2 - r1 + 1)->display() ) ) ) ) else ( execute (0)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def findkth(n,k): v1=list() v2=list() for i in range(1,mt.ceil(n**(.5))): if(n % i==0): v1.append(i) if(i!=mt.ceil(mt.sqrt(n))): v2.append(n//i) v2[: :-1] if(k>(len(v1)+len(v2))): print("Doesn't Exist",end="") else : if(k<=len(v1)): print(v1[k-1]) else : print(v2[k-len(v1)-1]) n=15 k=2 findkth(n,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 15 ; k := 2 ; findkth(n, k); operation findkth(n : OclAny, k : OclAny) pre: true post: true activity: var v1 : Sequence := () ; var v2 : Sequence := () ; for i : Integer.subrange(1, mt.ceil((n)->pow((.5)))-1) do ( if (n mod i = 0) then ( execute ((i) : v1) ; if (i /= mt.ceil(mt.sqrt(n))) then ( execute ((n div i) : v2) ) else skip ) else skip) ; v2(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; if ((k->compareTo(((v1)->size() + (v2)->size()))) > 0) then ( execute ("Doesn't Exist")->display() ) else ( if ((k->compareTo((v1)->size())) <= 0) then ( execute (v1[k - 1+1])->display() ) else ( execute (v2[k - (v1)->size() - 1+1])->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- seg=[6,2,5,5,4,5,6,3,7,6] def LedRequired(s,led): count=0 for i in range(len(s)): count+=seg[ord(s[i])-48] if(count<=led): return "YES" else : return "NO" if __name__=="__main__" : S="123456789" led=20 print(LedRequired(S,led)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var seg : Sequence := Sequence{6}->union(Sequence{2}->union(Sequence{5}->union(Sequence{5}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{3}->union(Sequence{7}->union(Sequence{ 6 }))))))))) ; skip ; if __name__ = "__main__" then ( var S : String := "123456789" ; led := 20 ; execute (LedRequired(S, led))->display() ) else skip; operation LedRequired(s : OclAny, led : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( count := count + seg[(s[i+1])->char2byte() - 48+1]) ; if ((count->compareTo(led)) <= 0) then ( return "YES" ) else ( return "NO" ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxSum1(arr,n): dp=[0]*n maxi=0 for i in range(n-1): dp[i]=arr[i] if(maxiunion(Sequence{2}->union(Sequence{3}->union(Sequence{ 1 }))) ; n := (arr)->size() ; execute (findMaxSum(arr, n))->display() ) else skip; operation maxSum1(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var maxi : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( dp[i+1] := arr[i+1] ; if ((maxi->compareTo(arr[i+1])) < 0) then ( maxi := arr[i+1] ) else skip) ; for i : Integer.subrange(2, n - 1-1) do ( for j : Integer.subrange(0, i - 1-1) do ( if ((dp[i+1]->compareTo(dp[j+1] + arr[i+1])) < 0) then ( dp[i+1] := dp[j+1] + arr[i+1] ; if ((maxi->compareTo(dp[i+1])) < 0) then ( maxi := dp[i+1] ) else skip ) else skip)) ; return maxi; operation maxSum2(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: dp := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; maxi := 0 ; for i : Integer.subrange(1, n-1) do ( dp[i+1] := arr[i+1] ; if ((maxi->compareTo(arr[i+1])) < 0) then ( maxi := arr[i+1] ) else skip) ; for i : Integer.subrange(3, n-1) do ( for j : Integer.subrange(1, i - 1-1) do ( if ((dp[i+1]->compareTo(arr[i+1] + dp[j+1])) < 0) then ( dp[i+1] := arr[i+1] + dp[j+1] ; if ((maxi->compareTo(dp[i+1])) < 0) then ( maxi := dp[i+1] ) else skip ) else skip)) ; return maxi; operation findMaxSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: return Set{maxSum1(arr, n), maxSum2(arr, n)}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxRectangles(L,B,l,b): horizontal,vertical=0,0 if l<=L and b<=B : columns=B//b rows=L//l horizontal=rows*columns if l<=B and b<=L : columns=L//b rows=B//l vertical=rows*columns return max(horizontal,vertical) if __name__=="__main__" : L,B,l,b=10,7,4,3 print(maxRectangles(L,B,l,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{L,B,l,b} := Sequence{10,7,4,3} ; execute (maxRectangles(L, B, l, b))->display() ) else skip; operation maxRectangles(L : OclAny, B : OclAny, l : OclAny, b : OclAny) : OclAny pre: true post: true activity: var horizontal : OclAny := null; var vertical : OclAny := null; Sequence{horizontal,vertical} := Sequence{0,0} ; if (l->compareTo(L)) <= 0 & (b->compareTo(B)) <= 0 then ( var columns : int := B div b ; var rows : int := L div l ; var horizontal : int := rows * columns ) else skip ; if (l->compareTo(B)) <= 0 & (b->compareTo(L)) <= 0 then ( columns := L div b ; rows := B div l ; var vertical : int := rows * columns ) else skip ; return Set{horizontal, vertical}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def findKthLargest(self,nums,k): random.shuffle(nums) return self.quickSelection(nums,0,len(nums)-1,len(nums)-k) def quickSelection(self,nums,start,end,k): if start>end : return float('inf') pivot=nums[end] left=start for i in range(start,end): if nums[i]<=pivot : nums[left],nums[i]=nums[i],nums[left] left+=1 nums[left],nums[end]=nums[end],nums[left] if left==k : return nums[left] elif leftexists( _x | result = _x ); operation findKthLargest(nums : OclAny,k : OclAny) : OclAny pre: true post: true activity: random.shuffle(nums) ; return self.quickSelection(nums, 0, (nums)->size() - 1, (nums)->size() - k); operation quickSelection(nums : OclAny,start : OclAny,end : OclAny,k : OclAny) : OclAny pre: true post: true activity: if (start->compareTo(end)) > 0 then ( return ("" + (('inf')))->toReal() ) else skip ; var pivot : OclAny := nums[end+1] ; var left : OclAny := start ; for i : Integer.subrange(start, end-1) do ( if (nums[i+1]->compareTo(pivot)) <= 0 then ( var nums[left+1] : OclAny := null; var nums[i+1] : OclAny := null; Sequence{nums[left+1],nums[i+1]} := Sequence{nums[i+1],nums[left+1]} ; left := left + 1 ) else skip) ; var nums[left+1] : OclAny := null; var nums[end+1] : OclAny := null; Sequence{nums[left+1],nums[end+1]} := Sequence{nums[end+1],nums[left+1]} ; if left = k then ( return nums[left+1] ) else (if (left->compareTo(k)) < 0 then ( return self.quickSelection(nums, left + 1, end, k) ) else ( return self.quickSelection(nums, start, left - 1, k) ) ) ; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfTheSeries(n): return(float(n)/(n+1)) if __name__=='__main__' : n=10 ans=sumOfTheSeries(n) print(round(ans,6)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 10 ; var ans : OclAny := sumOfTheSeries(n) ; execute (MathLib.roundN(ans, 6))->display() ) else skip; operation sumOfTheSeries(n : OclAny) : OclAny pre: true post: true activity: return (("" + ((n)))->toReal() / (n + 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def sum_digit(n): sum=0 for i in n : sum+=int(i) return str(sum) n=input() result=0 while(len(n)>1): n=sum_digit(n) result+=1 print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := (OclFile["System.in"]).readLine() ; var result : int := 0 ; while ((n)->size() > 1) do ( n := sum_digit(n) ; result := result + 1) ; execute (result)->display(); operation sum_digit(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : n do ( sum := sum + ("" + ((i)))->toInteger()) ; return ("" + ((sum))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) nl=list(str(n)) op=0 while len(nl)!=1 : sum=0 for i in nl : sum+=int(i) nl=list(str(sum)) op+=1 print(op) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nl : Sequence := (("" + ((n))))->characters() ; var op : int := 0 ; while (nl)->size() /= 1 do ( var sum : int := 0 ; for i : nl do ( sum := sum + ("" + ((i)))->toInteger()) ; nl := (("" + ((sum))))->characters() ; op := op + 1) ; execute (op)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): l,r,m=map(int,input().split()) d=r-l for i in range(l,r+1): v=m % i if v<=d and m>=i : print(i,l+v,l) break elif v>=i-d : print(i,l,l+i-v) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var l : OclAny := null; var r : OclAny := null; var m : OclAny := null; Sequence{l,r,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : double := r - l ; for i : Integer.subrange(l, r + 1-1) do ( var v : int := m mod i ; if (v->compareTo(d)) <= 0 & (m->compareTo(i)) >= 0 then ( execute (i)->display() ; break ) else (if (v->compareTo(i - d)) >= 0 then ( execute (i)->display() ; break ) else skip))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() c=0 while len(n)>1 : n=str(sum(map(int,n))) c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var c : int := 0 ; while (n)->size() > 1 do ( n := ("" + ((((n)->collect( _x | (OclType["int"])->apply(_x) ))->sum()))) ; c := c + 1) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def sum_digit(n): sum=0 for i in n : sum+=int(i) return str(sum) n=input() result=0 while(len(n)>1): n=sum_digit(n) result+=1 print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := (OclFile["System.in"]).readLine() ; var result : int := 0 ; while ((n)->size() > 1) do ( n := sum_digit(n) ; result := result + 1) ; execute (result)->display(); operation sum_digit(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : n do ( sum := sum + ("" + ((i)))->toInteger()) ; return ("" + ((sum))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def sum_digit(n): sum=0 for i in n : sum+=int(i) return str(sum) n=input() result=0 while(len(n)>1): n=sum_digit(n) result+=1 print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := (OclFile["System.in"]).readLine() ; var result : int := 0 ; while ((n)->size() > 1) do ( n := sum_digit(n) ; result := result + 1) ; execute (result)->display(); operation sum_digit(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : n do ( sum := sum + ("" + ((i)))->toInteger()) ; return ("" + ((sum))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countDigitsToBeRemoved(N,K): s=str(N); res=0 ; f_zero=0 ; for i in range(len(s)-1,-1,-1): if(K==0): return res ; if(s[i]=='0'): f_zero=1 ; K-=1 ; else : res+=1 ; if(K==0): return res ; elif(f_zero>0): return len(s)-1 ; return-1 ; N=10904025 ; K=2 ; print(countDigitsToBeRemoved(N,K)); N=1000 ; K=5 ; print(countDigitsToBeRemoved(N,K)); N=23985 ; K=2 ; print(countDigitsToBeRemoved(N,K)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 10904025; ; K := 2; ; execute (countDigitsToBeRemoved(N, K))->display(); ; N := 1000; ; K := 5; ; execute (countDigitsToBeRemoved(N, K))->display(); ; N := 23985; ; K := 2; ; execute (countDigitsToBeRemoved(N, K))->display();; operation countDigitsToBeRemoved(N : OclAny, K : OclAny) pre: true post: true activity: var s : String := ("" + ((N))); ; var res : int := 0; ; var f_zero : int := 0; ; for i : Integer.subrange(-1 + 1, (s)->size() - 1)->reverse() do ( if (K = 0) then ( return res; ) else skip ; if (s[i+1] = '0') then ( f_zero := 1; ; K := K - 1; ) else ( res := res + 1; )) ; if (K = 0) then ( return res; ) else (if (f_zero > 0) then ( return (s)->size() - 1; ) else skip) ; return -1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,floor def isPerfect(N): if(sqrt(N)-floor(sqrt(N))!=0): return False return True def getClosestPerfectSquare(N): if(isPerfect(N)): print(N,"0") return aboveN=-1 belowN=-1 n1=0 n1=N+1 while(True): if(isPerfect(n1)): aboveN=n1 break else : n1+=1 n1=N-1 while(True): if(isPerfect(n1)): belowN=n1 break else : n1-=1 diff1=aboveN-N diff2=N-belowN if(diff1>diff2): print(belowN,diff2) else : print(aboveN,diff1) N=1500 getClosestPerfectSquare(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; N := 1500 ; getClosestPerfectSquare(N); operation isPerfect(N : OclAny) : OclAny pre: true post: true activity: if (sqrt(N) - floor(sqrt(N)) /= 0) then ( return false ) else skip ; return true; operation getClosestPerfectSquare(N : OclAny) pre: true post: true activity: if (isPerfect(N)) then ( execute (N)->display() ; return ) else skip ; var aboveN : int := -1 ; var belowN : int := -1 ; var n1 : int := 0 ; n1 := N + 1 ; while (true) do ( if (isPerfect(n1)) then ( aboveN := n1 ; break ) else ( n1 := n1 + 1 )) ; n1 := N - 1 ; while (true) do ( if (isPerfect(n1)) then ( belowN := n1 ; break ) else ( n1 := n1 - 1 )) ; var diff1 : double := aboveN - N ; var diff2 : double := N - belowN ; if ((diff1->compareTo(diff2)) > 0) then ( execute (belowN)->display() ) else ( execute (aboveN)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def Prime(n): for j in range(2,int(sqrt(n))+1,1): if(n % j==0): return False return True def find_prime(x,xsqmodp,y,ysqmodp): n=x*x-xsqmodp n1=y*y-ysqmodp for j in range(2,max(int(sqrt(n)),int(sqrt(n1))),1): if(n % j==0 and(x*x)% j==xsqmodp and n1 % j==0 and(y*y)% j==ysqmodp): if(Prime(j)): return j j1=n//j if(n % j1==0 and(x*x)% j1==xsqmodp and n1 % j1==0 and(y*y)% j1==ysqmodp): if(Prime(j1)): return j1 j1=n1//j if(n % j1==0 and(x*x)% j1==xsqmodp and n1 % j1==0 and(y*y)% j1==ysqmodp): if(Prime(j1)): return j1 if(n==n1): return n if __name__=='__main__' : x=3 xsqmodp=0 y=5 ysqmodp=1 print(find_prime(x,xsqmodp,y,ysqmodp)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( x := 3 ; xsqmodp := 0 ; y := 5 ; ysqmodp := 1 ; execute (find_prime(x, xsqmodp, y, ysqmodp))->display() ) else skip; operation Prime(n : OclAny) : OclAny pre: true post: true activity: for j : Integer.subrange(2, ("" + ((sqrt(n))))->toInteger() + 1-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (n mod j = 0) then ( return false ) else skip) ; return true; operation find_prime(x : OclAny, xsqmodp : OclAny, y : OclAny, ysqmodp : OclAny) : OclAny pre: true post: true activity: n := x * x - xsqmodp ; var n1 : double := y * y - ysqmodp ; for j : Integer.subrange(2, Set{("" + ((sqrt(n))))->toInteger(), ("" + ((sqrt(n1))))->toInteger()}->max()-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (n mod j = 0 & (x * x) mod j = xsqmodp & n1 mod j = 0 & (y * y) mod j = ysqmodp) then ( if (Prime(j)) then ( return j ) else skip ) else skip ; var j1 : int := n div j ; if (n mod j1 = 0 & (x * x) mod j1 = xsqmodp & n1 mod j1 = 0 & (y * y) mod j1 = ysqmodp) then ( if (Prime(j1)) then ( return j1 ) else skip ) else skip ; j1 := n1 div j ; if (n mod j1 = 0 & (x * x) mod j1 = xsqmodp & n1 mod j1 = 0 & (y * y) mod j1 = ysqmodp) then ( if (Prime(j1)) then ( return j1 ) else skip ) else skip) ; if (n = n1) then ( return n ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) b=[x!='YES' for x in input().split()] q={chr(ord('A')+x)for x in range(26)}|{chr(ord('A')+x)+chr(ord('a')+y)for x in range(26)for y in range(26)} ls=[] c=k for x in q : if c : ls.append(x) c-=1 else : break if b[0]: ls[-1]=ls[0] for j in range(1,n-k+1): if b[j]: ls.append(ls[j]) else : v=set(ls[j : j+k]) for x in q : if x not in v : ls.append(x) break print(' '.join(ls)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : Sequence := input().split()->select(x | true)->collect(x | (x /= 'YES')) ; var q : int := MathLib.bitwiseOr(Integer.subrange(0, 26-1)->select(x | true)->collect(x | (('A')->char2byte() + x)->byte2char())->asSet(), Integer.subrange(0, 26-1)->select(x; y : Integer.subrange(0, 26-1) | true)->collect(x; y : Integer.subrange(0, 26-1) | (('A')->char2byte() + x)->byte2char() + (('a')->char2byte() + y)->byte2char())->asSet()) ; var ls : Sequence := Sequence{} ; var c : OclAny := k ; for x : q do ( if c then ( execute ((x) : ls) ; c := c - 1 ) else ( break )) ; if b->first() then ( ls->last() := ls->first() ) else skip ; for j : Integer.subrange(1, n - k + 1-1) do ( if b[j+1] then ( execute ((ls[j+1]) : ls) ) else ( var v : Set := Set{}->union((ls.subrange(j+1, j + k))) ; for x : q do ( if (v)->excludes(x) then ( execute ((x) : ls) ; break ) else skip) )) ; execute (StringLib.sumStringsWithSeparator((ls), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) for _ in range(k): n=int(input()) s=input() i1=s.find('1') i2=s.rfind('1') if i1==-1 : print(n) else : print(max(2*(i1+1),2*(n-i1),2*(i2+1),2*(n-i2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, k-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var i1 : int := s->indexOf('1') - 1 ; var i2 : OclAny := s.rfind('1') ; if i1 = -1 then ( execute (n)->display() ) else ( execute (Set{2 * (i1 + 1), 2 * (n - i1), 2 * (i2 + 1), 2 * (n - i2)}->max())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() I,l=input,len for i in '0'*int(I()): I(); s=I(); print(2*max(l(s.lstrip(i)),l(s.rstrip(i)))or l(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var I : OclAny := null; var l : OclAny := null; Sequence{I,l} := Sequence{input,len} ; for i : StringLib.nCopies('0', ("" + ((I())))->toInteger()) do ( I(); var s : OclAny := I(); execute (2 * Set{l(s.lstrip(i)), l(s.rstrip(i))}->max() or l(s))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t=int(input()) ans=[] for _ in range(t): n=int(input()) s=list(input().rstrip()) ans0=n for i in range(n): if s[i]& 1 : ans0=max(ans0,2*(n-i)) break for i in range(n-1,-1,-1): if s[i]& 1 : ans0=max(ans0,2*(i+1)) break ans.append(ans0) sys.stdout.write("\n".join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := (input().rstrip()) ; var ans0 : int := n ; for i : Integer.subrange(0, n-1) do ( if MathLib.bitwiseAnd(s[i+1], 1) then ( ans0 := Set{ans0, 2 * (n - i)}->max() ; break ) else skip) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if MathLib.bitwiseAnd(s[i+1], 1) then ( ans0 := Set{ans0, 2 * (i + 1)}->max() ; break ) else skip) ; execute ((ans0) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) out=[] for _ in range(t): n=int(input()) s=input() left=-1 right=-1 one=False for i in range(n): if s[i]=="1" : left=i one=True break for i in range(n-1,-1,-1): if s[i]=="1" : right=n-i-1 break ans=2*(n-min(left,right))if one else n out.append(ans) for i in out : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var out : Sequence := Sequence{} ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var left : int := -1 ; var right : int := -1 ; var one : boolean := false ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = "1" then ( left := i ; one := true ; break ) else skip) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if s[i+1] = "1" then ( right := n - i - 1 ; break ) else skip) ; var ans : double := if one then 2 * (n - Set{left, right}->min()) else n endif ; execute ((ans) : out)) ; for i : out do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[-1]*26 all=set(i for i in "abcdefghijklmnoprqstuvwxyz") bad=set("") res_cnt=0 flag=False for i in range(n-1): cmd,word=input().split() if flag : if cmd in "!?" : res_cnt+=1 continue if cmd=="." : for c in set(word): pos=ord(c)-ord("a") a[pos]=0 all.discard(c) bad.discard(c) elif cmd=="!" : curr_bad=set() for c in set(word): pos=ord(c)-ord("a") if a[pos]==0 : all.discard(c) else : curr_bad.add(c) if not bad : bad=curr_bad else : old_bad=bad.copy() bad=bad.intersection(curr_bad) for c in old_bad-bad : pos=ord(c)-ord("a") a[pos]=0 all.discard(c) for c in curr_bad-bad : pos=ord(c)-ord("a") a[pos]=0 all.discard(c) else : c=word[0] pos=ord(c)-ord("a") a[pos]=0 all.discard(c) bad.discard(c) if len(bad)==1 or len(all)==1 : flag=True print(res_cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, 26) ; var all : Set := Set{}->union(((argument (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom "abcdefghijklmnoprqstuvwxyz")))))))) ; var bad : Set := Set{}->union(("")) ; var res_cnt : int := 0 ; var flag : boolean := false ; for i : Integer.subrange(0, n - 1-1) do ( var cmd : OclAny := null; var word : OclAny := null; Sequence{cmd,word} := input().split() ; if flag then ( if ("!?")->characters()->includes(cmd) then ( res_cnt := res_cnt + 1 ) else skip ; continue ) else skip ; if cmd = "." then ( for c : Set{}->union((word)) do ( var pos : double := (c)->char2byte() - ("a")->char2byte() ; a[pos+1] := 0 ; execute ((c) /: all) ; execute ((c) /: bad)) ) else (if cmd = "!" then ( var curr_bad : Set := Set{}->union(()) ; for c : Set{}->union((word)) do ( pos := (c)->char2byte() - ("a")->char2byte() ; if a[pos+1] = 0 then ( execute ((c) /: all) ) else ( execute ((c) : curr_bad) )) ; if not(bad) then ( bad := curr_bad ) else ( var old_bad : OclAny := bad->copy() ; bad := bad->intersection(curr_bad) ; for c : old_bad - bad do ( pos := (c)->char2byte() - ("a")->char2byte() ; a[pos+1] := 0 ; execute ((c) /: all)) ; for c : curr_bad - bad do ( pos := (c)->char2byte() - ("a")->char2byte() ; a[pos+1] := 0 ; execute ((c) /: all)) ) ) else ( var c : OclAny := word->first() ; pos := (c)->char2byte() - ("a")->char2byte() ; a[pos+1] := 0 ; execute ((c) /: all) ; execute ((c) /: bad) ) ) ; if (bad)->size() = 1 or (all)->size() = 1 then ( flag := true ) else skip) ; execute (res_cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) s=input() st=None en=None for i in range(n): if s[i]=="1" : if st==None : st=i en=i if st==None : print(n) else : print(max(en+1+max(en+1,n-en),n-st+max(n-st,st+1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var st : OclAny := null ; var en : OclAny := null ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = "1" then ( if st = null then ( st := i ) else skip ; en := i ) else skip) ; if st = null then ( execute (n)->display() ) else ( execute (Set{en + 1 + Set{en + 1, n - en}->max(), n - st + Set{n - st, st + 1}->max()}->max())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printSum(m,s,n): total=0 for i in range(n): total+=s[i] total+=(m[i]*60) print(int(total/3600),end=" : ") total %=3600 print(int(total/60),end=": ") total %=60 print(int(total)) m=[0,2,3,2,1] s=[45,31,11,27,28] n=len(m) printSum(m,s,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; m := Sequence{0}->union(Sequence{2}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 1 })))) ; s := Sequence{45}->union(Sequence{31}->union(Sequence{11}->union(Sequence{27}->union(Sequence{ 28 })))) ; n := (m)->size() ; printSum(m, s, n); operation printSum(m : OclAny, s : OclAny, n : OclAny) pre: true post: true activity: var total : int := 0 ; for i : Integer.subrange(0, n-1) do ( total := total + s[i+1] ; total := total + (m[i+1] * 60)) ; execute (("" + ((total / 3600)))->toInteger())->display() ; total := total mod 3600 ; execute (("" + ((total / 60)))->toInteger())->display() ; total := total mod 60 ; execute (("" + ((total)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countWays(n,k): total=k mod=1000000007 same,diff=0,k for i in range(2,n+1): same=diff diff=total*(k-1) diff=diff % mod total=(same+diff)% mod return total if __name__=="__main__" : n,k=3,2 print(countWays(n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{n,k} := Sequence{3,2} ; execute (countWays(n, k))->display() ) else skip; operation countWays(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var total : OclAny := k ; var mod : int := 1000000007 ; var same : OclAny := null; var diff : OclAny := null; Sequence{same,diff} := Sequence{0,k} ; for i : Integer.subrange(2, n + 1-1) do ( var same : OclAny := diff ; var diff : double := total * (k - 1) ; diff := diff mod mod ; total := (same + diff) mod mod) ; return total; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq n,k=map(int,input().split()) z=[0,1] for i in range(1,n): z.append(z[i]+2) s=sorted([list(map(int,input().split()))for _ in range(n)],key=lambda x :-x[1]) q=[] v=0 ans=0 l=[0]*-~ n for a in s[: k]: if not l[a[0]]: v+=1 ans+=z[v] else : heapq.heappush(q,a[1]) l[a[0]]=1 ans+=a[1] tem=ans for a in s[k :]: if not q : break if l[a[0]]: continue l[a[0]]=1 v+=1 t=heapq.heappop(q) tem=tem-t+a[1]+z[v] ans=max(ans,tem) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var z : Sequence := Sequence{0}->union(Sequence{ 1 }) ; for i : Integer.subrange(1, n-1) do ( execute ((z[i+1] + 2) : z)) ; var s : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))->sortedBy($x | (lambda x : OclAny in (-x[1+1]))->apply($x)) ; var q : Sequence := Sequence{} ; var v : int := 0 ; var ans : int := 0 ; var l : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, -MathLib.bitwiseNot(n)) ; for a : s.subrange(1,k) do ( if not(l[a->first()+1]) then ( v := v + 1 ; ans := ans + z[v+1] ) else ( heapq.heappush(q, a[1+1]) ) ; l[a->first()+1] := 1 ; ans := ans + a[1+1]) ; var tem : int := ans ; for a : s.subrange(k+1) do ( if not(q) then ( break ) else skip ; if l[a->first()+1] then ( continue ) else skip ; l[a->first()+1] := 1 ; v := v + 1 ; var t : OclAny := heapq.heappop(q) ; tem := tem - t + a[1+1] + z[v+1] ; ans := Set{ans, tem}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def 解(): input=sys.stdin.readline N,K=[int(_)for _ in input().split()] aP=sorted([[int(_)for _ in input().split()]for _ in range(N)],key=lambda x : x[1],reverse=True) dS=set() aPK=aP[: K] for t,d in aPK : dS.add(t) dSall=dS.copy() for t,d in aP[K :]: dSall.add(t) iSall=len(dSall) iSum=sum(x[1]for x in aPK) i種類=len(dS) iTotal=iSum+i種類**2 if iSall==len(dS): print(iTotal) exit() else : dPK={} for t,d in aPK : if t in dPK : dPK[t].append(d) else : dPK[t]=[d] vT=set() j=K-1 for nt,nd in aP[K :]: if i種類==iSall : break if nt not in dS : for i in range(j,-1,-1): t,d=aPK[i] if t not in vT : dPK[t].sort() vT.add(t) aT=dPK[t] if 1select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var aP : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger()))))->sortedBy($x | (lambda x : OclAny in (x[1+1]))->apply($x)) ; var dS : Set := Set{}->union(()) ; var aPK : OclAny := aP.subrange(1,K) ; for _tuple : aPK do (var _indx : int := 1; var t : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); execute ((t) : dS)) ; var dSall : OclAny := dS->copy() ; for _tuple : aP.subrange(K+1) do (var _indx : int := 1; var t : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); execute ((t) : dSall)) ; var iSall : int := (dSall)->size() ; var iSum : OclAny := ((argument (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name aPK))))))))->sum() ; var i?? : int := (dS)->size() ; var iTotal : OclAny := iSum + (i??)->pow(2) ; if iSall = (dS)->size() then ( execute (iTotal)->display() ; exit() ) else ( var dPK : OclAny := Set{} ; for _tuple : aPK do (var _indx : int := 1; var t : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); if (dPK)->includes(t) then ( (expr (atom (name dPK)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name d)))))))) )))) ) else ( dPK[t+1] := Sequence{ d } )) ; var vT : Set := Set{}->union(()) ; var j : double := K - 1 ; for _tuple : aP.subrange(K+1) do (var _indx : int := 1; var nt : OclAny := _tuple->at(_indx); _indx := _indx + 1; var nd : OclAny := _tuple->at(_indx); if i?? = iSall then ( break ) else skip ; if (dS)->excludes(nt) then ( for i : Integer.subrange(-1 + 1, j)->reverse() do ( var t : OclAny := null; var d : OclAny := null; Sequence{t,d} := aPK[i+1] ; if (vT)->excludes(t) then ( (expr (atom (name dPK)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name sort) (arguments ( )))) ; execute ((t) : vT) ) else skip ; var aT : OclAny := dPK[t+1] ; if 1 < (aT)->size() then ( var iNewTotal : double := iSum - d + nd + ((i?? + 1))->pow(2) ; if (iTotal->compareTo(iNewTotal)) < 0 then ( iTotal := iNewTotal ) else skip ; execute (dPK[t+1]->first())->isDeleted() ; dPK[nt+1] := Sequence{ nd } ; aPK[i+1] := Sequence{nt}->union(Sequence{ nd }) ; i?? := i?? + 1 ; iSum := iSum - d + nd ; execute ((nt) : dS) ; break ) else skip) ; j := i - 1 ) else skip) ; execute (iTotal)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- names=['Edurounds','Flushed',"Orz",'Yt','Ggh','Fg','Fdg','Fdga','Fgs','sdcv','anantcool','anantorz','bruhone','lol',"geniosity","bruhtwo","bruhthree","bruhprime","twoprime" 'q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m',"anantgh","eduround","brickedu","moorz","bruh","qw","we","er","rt"] names1=[] for b in names : names1.append(b.title()) n,k=map(int,input().split()) p=0 a=input().split() res=names1[: n] for i in range(n-k+1): if a[i]=='NO' : res[i+k-1]=res[i] print(*res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var names : Sequence := Sequence{'Edurounds'}->union(Sequence{'Flushed'}->union(Sequence{"Orz"}->union(Sequence{'Yt'}->union(Sequence{'Ggh'}->union(Sequence{'Fg'}->union(Sequence{'Fdg'}->union(Sequence{'Fdga'}->union(Sequence{'Fgs'}->union(Sequence{'sdcv'}->union(Sequence{'anantcool'}->union(Sequence{'anantorz'}->union(Sequence{'bruhone'}->union(Sequence{'lol'}->union(Sequence{"geniosity"}->union(Sequence{"bruhtwo"}->union(Sequence{"bruhthree"}->union(Sequence{"bruhprime"}->union(Sequence{(atom "twoprime" 'q')}->union(Sequence{'w'}->union(Sequence{'e'}->union(Sequence{'r'}->union(Sequence{'t'}->union(Sequence{'y'}->union(Sequence{'u'}->union(Sequence{'i'}->union(Sequence{'o'}->union(Sequence{'p'}->union(Sequence{'a'}->union(Sequence{'s'}->union(Sequence{'d'}->union(Sequence{'f'}->union(Sequence{'g'}->union(Sequence{'h'}->union(Sequence{'j'}->union(Sequence{'k'}->union(Sequence{'l'}->union(Sequence{'z'}->union(Sequence{'x'}->union(Sequence{'c'}->union(Sequence{'v'}->union(Sequence{'b'}->union(Sequence{'n'}->union(Sequence{'m'}->union(Sequence{"anantgh"}->union(Sequence{"eduround"}->union(Sequence{"brickedu"}->union(Sequence{"moorz"}->union(Sequence{"bruh"}->union(Sequence{"qw"}->union(Sequence{"we"}->union(Sequence{"er"}->union(Sequence{ "rt" })))))))))))))))))))))))))))))))))))))))))))))))))))) ; var names1 : Sequence := Sequence{} ; for b : names do ( execute ((StringLib.toTitleCase(b)) : names1)) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : int := 0 ; var a : OclAny := input().split() ; var res : OclAny := names1.subrange(1,n) ; for i : Integer.subrange(0, n - k + 1-1) do ( if a[i+1] = 'NO' then ( res[i + k - 1+1] := res[i+1] ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq as hq from collections import deque from copy import deepcopy N,K=map(int,input().split()) Sushi=[None for _ in range(N)] TotalType=set() for _ in range(N): t,d=map(int,input().split()) Sushi[_]=[d,t] Sushi.sort(reverse=True) ChosenType=set() Double=[] hq.heapify(Double) BasePoint=0 for goodsushi in Sushi[: K]: BasePoint+=goodsushi[0] if goodsushi[1]in ChosenType : hq.heappush(Double,goodsushi) else : ChosenType |={goodsushi[1]} NotChosen=deque(deepcopy(Sushi[K :])) MaxHappiness=BasePoint+len(ChosenType)**2 while Double and NotChosen : TrushPoint,TrushType=hq.heappop(Double) BasePoint-=TrushPoint while NotChosen : addPoint,addType=NotChosen.popleft() if addType not in ChosenType : BasePoint+=addPoint ChosenType |={addType} break MaxHappiness=max(MaxHappiness,BasePoint+len(ChosenType)**2) print(MaxHappiness) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var Sushi : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (null)) ; var TotalType : Set := Set{}->union(()) ; for _anon : Integer.subrange(0, N-1) do ( var t : OclAny := null; var d : OclAny := null; Sequence{t,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; Sushi[_anon+1] := Sequence{d}->union(Sequence{ t })) ; Sushi := Sushi->sort() ; var ChosenType : Set := Set{}->union(()) ; var Double : Sequence := Sequence{} ; hq.heapify(Double) ; var BasePoint : int := 0 ; for goodsushi : Sushi.subrange(1,K) do ( BasePoint := BasePoint + goodsushi->first() ; if (ChosenType)->includes(goodsushi[1+1]) then ( hq.heappush(Double, goodsushi) ) else ( ChosenType := ChosenType or Set{ goodsushi[1+1] } )) ; var NotChosen : Sequence := (deepcopy(Sushi.subrange(K+1))) ; var MaxHappiness : int := BasePoint + ((ChosenType)->size())->pow(2) ; while Double & NotChosen do ( var TrushPoint : OclAny := null; var TrushType : OclAny := null; Sequence{TrushPoint,TrushType} := hq.heappop(Double) ; BasePoint := BasePoint - TrushPoint ; while NotChosen do ( var addPoint : OclAny := null; var addType : OclAny := null; Sequence{addPoint,addType} := NotChosen->first() ; NotChosen := NotChosen->tail() ; if (ChosenType)->excludes(addType) then ( BasePoint := BasePoint + addPoint ; ChosenType := ChosenType or Set{ addType } ; break ) else skip) ; MaxHappiness := Set{MaxHappiness, BasePoint + ((ChosenType)->size())->pow(2)}->max()) ; execute (MaxHappiness)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict from heapq import heappush,heappop N,K,*L=map(int,open(0).read().split()) dic=defaultdict(list) ls=[] for i,(t,d)in enumerate(zip(*[iter(L)]*2)): dic[t].append(d) heappush(ls,(-d,t)) S=set() pre=[] ans=0 num=0 for i in range(K): d,t=heappop(ls) ans-=d if t not in S : num+=1 S.add(t) else : heappush(pre,-d) ans+=num*num if pre==[]: print(ans) exit() m=ans for i in range(N-K): d,t=heappop(ls) if t in S : continue S.add(t) m-=heappop(pre) m+=-d+2*num+1 num+=1 ans=max(ans,m) if pre==[]: break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := null; var K : OclAny := null; var L : OclAny := null; Sequence{N,K,L} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dic : OclAny := defaultdict(OclType["Sequence"]) ; var ls : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))`third->at(_indx)} ))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))`third->at(_indx)} ))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{t, d} : OclAny := _tuple->at(_indx); (expr (atom (name dic)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name d)))))))) )))) ; heappush(ls, Sequence{-d, t})) ; var S : Set := Set{}->union(()) ; var pre : Sequence := Sequence{} ; var ans : int := 0 ; var num : int := 0 ; for i : Integer.subrange(0, K-1) do ( var d : OclAny := null; var t : OclAny := null; Sequence{d,t} := heappop(ls) ; ans := ans - d ; if (S)->excludes(t) then ( num := num + 1 ; execute ((t) : S) ) else ( heappush(pre, -d) )) ; ans := ans + num * num ; if pre = Sequence{} then ( execute (ans)->display() ; exit() ) else skip ; var m : int := ans ; for i : Integer.subrange(0, N - K-1) do ( var d : OclAny := null; var t : OclAny := null; Sequence{d,t} := heappop(ls) ; if (S)->includes(t) then ( continue ) else skip ; execute ((t) : S) ; m := m - heappop(pre) ; m := m + -d + 2 * num + 1 ; num := num + 1 ; ans := Set{ans, m}->max() ; if pre = Sequence{} then ( break ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from operator import itemgetter N,K=map(int,input().split()) td=[list(map(int,input().split()))for _ in range(N)] td.sort(key=itemgetter(1,0),reverse=True) t,d=zip(*td) s=set() q=[] tmp=0 now=0 for i in range(K): if t[i]not in s : s.add(t[i]) else : q.append(d[i]) tmp+=d[i] now+=1 kind=len(s) sums=[-100000000000]*(kind+1) sums[kind]=tmp for i in range(K,N): if not q : break if t[i]not in s : s.add(t[i]) tmp=q.pop() kind+=1 sums.append(sums[kind-1]+d[i]-tmp) for i in range(len(sums)): sums[i]+=i**2 print(max(sums)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var td : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; td := td->sort() ; var t : OclAny := null; var d : OclAny := null; Sequence{t,d} := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name td)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name td)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name td)))))))`third->at(_indx)} ) ; var s : Set := Set{}->union(()) ; var q : Sequence := Sequence{} ; var tmp : int := 0 ; var now : int := 0 ; for i : Integer.subrange(0, K-1) do ( if (s)->excludes(t[i+1]) then ( execute ((t[i+1]) : s) ) else ( execute ((d[i+1]) : q) ) ; tmp := tmp + d[i+1] ; now := now + 1) ; var kind : int := (s)->size() ; var sums : Sequence := MatrixLib.elementwiseMult(Sequence{ -100000000000 }, (kind + 1)) ; sums[kind+1] := tmp ; for i : Integer.subrange(K, N-1) do ( if not(q) then ( break ) else skip ; if (s)->excludes(t[i+1]) then ( execute ((t[i+1]) : s) ; tmp := q->last() ; q := q->front() ; kind := kind + 1 ; execute ((sums[kind - 1+1] + d[i+1] - tmp) : sums) ) else skip) ; for i : Integer.subrange(0, (sums)->size()-1) do ( sums[i+1] := sums[i+1] + (i)->pow(2)) ; execute ((sums)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() co=s.count("a") sk="" n=len(s) if co==n : sk=s[: n-1]+"z" elif co==0 : for i in range(n): sk+=chr(ord(s[i])-1) elif s[0]=="a" and co==1 : sk="a" for i in range(1,n): sk+=chr(ord(s[i])-1) elif s[0]=="a" : a=0 for i in range(n): if s[i]!="a" : a=i break sk+=s[: a] b=n for i in range(a,n): if s[i]=="a" : b=i break sk+=chr(ord(s[i])-1) sk+=s[b :] else : p=s.index("a") for i in range(p): sk+=chr(ord(s[i])-1) sk+=s[p :] print(sk) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var co : int := s->count("a") ; var sk : String := "" ; var n : int := (s)->size() ; if co = n then ( sk := s.subrange(1,n - 1) + "z" ) else (if co = 0 then ( for i : Integer.subrange(0, n-1) do ( sk := sk + ((s[i+1])->char2byte() - 1)->byte2char()) ) else (if s->first() = "a" & co = 1 then ( sk := "a" ; for i : Integer.subrange(1, n-1) do ( sk := sk + ((s[i+1])->char2byte() - 1)->byte2char()) ) else (if s->first() = "a" then ( var a : int := 0 ; for i : Integer.subrange(0, n-1) do ( if s[i+1] /= "a" then ( a := i ; break ) else skip) ; sk := sk + s.subrange(1,a) ; var b : int := n ; for i : Integer.subrange(a, n-1) do ( if s[i+1] = "a" then ( b := i ; break ) else skip ; sk := sk + ((s[i+1])->char2byte() - 1)->byte2char()) ; sk := sk + s.subrange(b+1) ) else ( var p : int := s->indexOf("a") - 1 ; for i : Integer.subrange(0, p-1) do ( sk := sk + ((s[i+1])->char2byte() - 1)->byte2char()) ; sk := sk + s.subrange(p+1) ) ) ) ) ; execute (sk)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input(); foundl=foundr=False for x in range(0,len(s)): if s[x]is not 'a' : left=x foundl=True break if not foundl : c=s[0 : len(s)-1] c+='z' else : for x in range(left,len(s)): if s[x]is 'a' : right=x foundr=True break c=s[: left] if foundr : for x in range(left,right): c+=chr(ord(s[x])-1) c+=s[right :] else : for x in range(left,len(s)): c+=chr(ord(s[x])-1) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine(); ; var foundl : OclAny := false; var foundr : boolean := false ; for x : Integer.subrange(0, (s)->size()-1) do ( if not(s[x+1] <>= 'a') then ( var left : OclAny := x ; foundl := true ; break ) else skip) ; if not(foundl) then ( var c : OclAny := s.subrange(0+1, (s)->size() - 1) ; c := c + 'z' ) else ( for x : Integer.subrange(left, (s)->size()-1) do ( if s[x+1] <>= 'a' then ( var right : OclAny := x ; foundr := true ; break ) else skip) ; c := s.subrange(1,left) ; if foundr then ( for x : Integer.subrange(left, right-1) do ( c := c + ((s[x+1])->char2byte() - 1)->byte2char()) ; c := c + s.subrange(right+1) ) else ( for x : Integer.subrange(left, (s)->size()-1) do ( c := c + ((s[x+1])->char2byte() - 1)->byte2char()) ) ) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calGCD(x,y): while(y>0): x,y=y,x % y return x x,y=[int(i)for i in input().split()] d=calGCD(x,y) ans=(x-1)+(y-1)+2-(d-1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{x,y} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var d : OclAny := calGCD(x, y) ; var ans : double := (x - 1) + (y - 1) + 2 - (d - 1) ; execute (ans)->display(); operation calGCD(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: while (y > 0) do ( Sequence{x,y} := Sequence{y,x mod y}) ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[1]*26 t=0 yd=0 for i in range(n-1): s=input() os=s[: 1] s=s[2 :] b=[0]*26 for i in range(len(s)): b[ord(s[i])-ord("a")]=1 if os=="." or os=="?" : if t==1 and os=="?" : yd+=1 for j in range(26): if b[j]==1 : a[j]=0 else : if t==1 : yd+=1 for j in range(26): if b[j]==0 : a[j]=0 if sum(a)==1 : t=1 s=input() print(yd) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, 26) ; var t : int := 0 ; var yd : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var os : OclAny := s.subrange(1,1) ; s := s.subrange(2+1) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for i : Integer.subrange(0, (s)->size()-1) do ( b[(s[i+1])->char2byte() - ("a")->char2byte()+1] := 1) ; if os = "." or os = "?" then ( if t = 1 & os = "?" then ( yd := yd + 1 ) else skip ; for j : Integer.subrange(0, 26-1) do ( if b[j+1] = 1 then ( a[j+1] := 0 ) else skip) ) else ( if t = 1 then ( yd := yd + 1 ) else skip ; for j : Integer.subrange(0, 26-1) do ( if b[j+1] = 0 then ( a[j+1] := 0 ) else skip) ) ; if (a)->sum() = 1 then ( t := 1 ) else skip) ; s := (OclFile["System.in"]).readLine() ; execute (yd)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys s=input() L=len(s) t="" i=0 while isize() ; var t : String := "" ; var i : int := 0 ; while (i->compareTo(L)) < 0 & s[i+1] = 'a' do ( t := t + s[i+1] ; i := i + 1) ; if (t)->size() = L then ( execute (s.subrange(1,L - 1) + 'z')->display() ; sys.exit() ) else skip ; while (i->compareTo(L)) < 0 & s[i+1] /= 'a' do ( t := t + ((s[i+1])->char2byte() - 1)->byte2char() ; i := i + 1) ; t := t + s.subrange(i+1) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys s=input() L=len(s) t="" i=0 ; while isize() ; var t : String := "" ; var i : int := 0; ; while (i->compareTo(L)) < 0 & s[i+1] = 'a' do ( t := t + s[i+1] ; i := i + 1) ; if (t)->size() = L then ( execute (s.subrange(1,L - 1) + 'z')->display() ; sys.exit() ) else skip ; while (i->compareTo(L)) < 0 & s[i+1] /= 'a' do ( t := t + ((s[i+1])->char2byte() - 1)->byte2char() ; i := i + 1) ; t := t + s.subrange(i+1) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- array=list(input()) def replace(array): i=0 len_array_set=len(set(array)) len_array=len(array) for i in range(0,len_array): if len_array_set==1 and array[i]=='a' : array[-1]='z' return 0 if array[i]=='a' : continue while len_array>i and array[i]<='z' and array[i]!='a' : array[i]=chr(ord(array[i])-1) i+=1 return 0 replace(array) for i in array : print(i,end='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var array : Sequence := ((OclFile["System.in"]).readLine())->characters() ; skip ; replace(array) ; for i : array do ( execute (i)->display()); operation replace(array : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; var len_array_set : int := (Set{}->union((array)))->size() ; var len_array : int := (array)->size() ; for i : Integer.subrange(0, len_array-1) do ( if len_array_set = 1 & array[i+1] = 'a' then ( array->last() := 'z' ; return 0 ) else skip ; if array[i+1] = 'a' then ( continue ) else skip ; while (len_array->compareTo(i)) > 0 & array[i+1] <= 'z' & array[i+1] /= 'a' do ( array[i+1] := ((array[i+1])->char2byte() - 1)->byte2char() ; i := i + 1) ; return 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=input().split() l=[] for i in range(n): if i<26 : l.append(chr(i+65)) else : l.append('A'+chr(i-26+97)) for i in range(n-k+1): if a[i]=='NO' : l[i+k-1]=l[i] print(*l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := input().split() ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if i < 26 then ( execute (((i + 65)->byte2char()) : l) ) else ( execute (('A' + (i - 26 + 97)->byte2char()) : l) )) ; for i : Integer.subrange(0, n - k + 1-1) do ( if a[i+1] = 'NO' then ( l[i + k - 1+1] := l[i+1] ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name l))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n<=2 : print('No') else : print('Yes') print(1,n) ans=[] for i in range(1,n): ans.append(i) print(n-1,' '.join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n <= 2 then ( execute ('No')->display() ) else ( execute ('Yes')->display() ; execute (1)->display() ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(1, n-1) do ( execute ((i) : ans)) ; execute (n - 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n<=2 : print('No') else : print('Yes') if n % 2==0 : one=[x for x in range(1,n,2)] one.append(n) two=[x for x in range(2,n,2)] print((n//2)+1,*one) print((n//2)-1,*two) else : one=[] two=[] len1=0 len2=0 for i in range(1,(n//2)+1): if i % 2==0 : one.append(i) one.append(n-i) len1+=2 else : two.append(i) two.append(n-i) len2+=2 one.append(n) len1+=1 print(len1,*one) print(len2,*two) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n <= 2 then ( execute ('No')->display() ) else ( execute ('Yes')->display() ; if n mod 2 = 0 then ( var one : Sequence := Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 2 = 0 )->select(x | true)->collect(x | (x)) ; execute ((n) : one) ; var two : Sequence := Integer.subrange(2, n-1)->select( $x | ($x - 2) mod 2 = 0 )->select(x | true)->collect(x | (x)) ; execute ((n div 2) + 1)->display() ; execute ((n div 2) - 1)->display() ) else ( one := Sequence{} ; two := Sequence{} ; var len1 : int := 0 ; var len2 : int := 0 ; for i : Integer.subrange(1, (n div 2) + 1-1) do ( if i mod 2 = 0 then ( execute ((i) : one) ; execute ((n - i) : one) ; len1 := len1 + 2 ) else ( execute ((i) : two) ; execute ((n - i) : two) ; len2 := len2 + 2 )) ; execute ((n) : one) ; len1 := len1 + 1 ; execute (len1)->display() ; execute (len2)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n<=2 : print('No') exit() O=[] E=[] for i in range(1,n+1): if i % 2==1 : O.append(i) else : E.append(i) print('Yes') print(len(O),*O) print(len(E),*E) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n <= 2 then ( execute ('No')->display() ; exit() ) else skip ; var O : Sequence := Sequence{} ; var E : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( if i mod 2 = 1 then ( execute ((i) : O) ) else ( execute ((i) : E) )) ; execute ('Yes')->display() ; execute ((O)->size())->display() ; execute ((E)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPalindrome(n): divisor=1 while(n/divisor>=10): divisor*=10 while(n!=0): leading=n//divisor trailing=n % 10 if(leading!=trailing): return False n=(n % divisor)//10 divisor=divisor//100 return True def largestPalindrome(A,n): A.sort() for i in range(n-1,-1,-1): if(isPalindrome(A[i])): return A[i] return-1 if __name__=="__main__" : A=[1,232,54545,999991] n=len(A) print(largestPalindrome(A,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( A := Sequence{1}->union(Sequence{232}->union(Sequence{54545}->union(Sequence{ 999991 }))) ; n := (A)->size() ; execute (largestPalindrome(A, n))->display() ) else skip; operation isPalindrome(n : OclAny) : OclAny pre: true post: true activity: var divisor : int := 1 ; while (n / divisor >= 10) do ( divisor := divisor * 10) ; while (n /= 0) do ( var leading : int := n div divisor ; var trailing : int := n mod 10 ; if (leading /= trailing) then ( return false ) else skip ; n := (n mod divisor) div 10 ; divisor := divisor div 100) ; return true; operation largestPalindrome(A : OclAny, n : OclAny) : OclAny pre: true post: true activity: A := A->sort() ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (isPalindrome(A[i+1])) then ( return A[i+1] ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPalindrome(n): divisor=1 while(int(n/divisor)>=10): divisor*=10 while(n!=0): leading=int(n/divisor) trailing=n % 10 if(leading!=trailing): return False n=int((n % divisor)/10) divisor=int(divisor/100) return True def largestPalindrome(A,n): currentMax=-1 for i in range(0,n,1): if(A[i]>currentMax and isPalindrome(A[i])): currentMax=A[i] return currentMax if __name__=='__main__' : A=[1,232,54545,999991] n=len(A) print(largestPalindrome(A,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( A := Sequence{1}->union(Sequence{232}->union(Sequence{54545}->union(Sequence{ 999991 }))) ; n := (A)->size() ; execute (largestPalindrome(A, n))->display() ) else skip; operation isPalindrome(n : OclAny) : OclAny pre: true post: true activity: var divisor : int := 1 ; while (("" + ((n / divisor)))->toInteger() >= 10) do ( divisor := divisor * 10) ; while (n /= 0) do ( var leading : int := ("" + ((n / divisor)))->toInteger() ; var trailing : int := n mod 10 ; if (leading /= trailing) then ( return false ) else skip ; n := ("" + (((n mod divisor) / 10)))->toInteger() ; divisor := ("" + ((divisor / 100)))->toInteger()) ; return true; operation largestPalindrome(A : OclAny, n : OclAny) : OclAny pre: true post: true activity: var currentMax : int := -1 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if ((A[i+1]->compareTo(currentMax)) > 0 & isPalindrome(A[i+1])) then ( currentMax := A[i+1] ) else skip) ; return currentMax; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isAlphabaticOrder(s): n=len(s) for i in range(1,n): if(s[i]display() ) else ( execute ("No")->display() ) ) else skip; operation isAlphabaticOrder(s : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; for i : Integer.subrange(1, n-1) do ( if ((s[i+1]->compareTo(s[i - 1+1])) < 0) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(s): freq=[0]*26 n=len(s) for i in range(n): freq[ord(s[i])-97]+=1 for i in range(26): if(freq[i]% 2==1): return False return True s="abaccaba" if(check(s)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := "abaccaba" ; if (check(s)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation check(s : OclAny) : OclAny pre: true post: true activity: var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; var n : int := (s)->size() ; for i : Integer.subrange(0, n-1) do ( freq[(s[i+1])->char2byte() - 97+1] := freq[(s[i+1])->char2byte() - 97+1] + 1) ; for i : Integer.subrange(0, 26-1) do ( if (freq[i+1] mod 2 = 1) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) k=0 r=set('abcdefghijklmnopqrstuvwxyz') for i in range(n-1): s=input().split() if len(r)==1 and s[0]!='.' : k+=1 if s[0]=='!' : r &=set(s[1]) else : r-=set(s[1]) print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := 0 ; var r : Set := Set{}->union(('abcdefghijklmnopqrstuvwxyz')) ; for i : Integer.subrange(0, n - 1-1) do ( var s : OclAny := input().split() ; if (r)->size() = 1 & s->first() /= '.' then ( k := k + 1 ) else skip ; if s->first() = '!' then ( r := r & Set{}->union((s[1+1])) ) else ( r := r - Set{}->union((s[1+1])) )) ; execute (k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(s): n=len(s) for i in range(n-1): if(s[i]>s[i+1]): return True return False if __name__=='__main__' : s="geeksforgeeks" if(check(s)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( s := "geeksforgeeks" ; if (check(s)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation check(s : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; for i : Integer.subrange(0, n - 1-1) do ( if ((s[i+1]->compareTo(s[i + 1+1])) > 0) then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSubSeq(arr,n): arr.sort(); count=[1]*n ; prev=[-1]*n ; max=0 ; maxprev=-1 ; for i in range(n): for j in range(i-1,-1,-1): if(arr[i]% arr[j]==0 and count[j]+1>count[i]): count[i]=count[j]+1 ; prev[i]=j ; if(max=0): if(arr[i]!=-1): print(arr[i],end=" "); i=prev[i]; if __name__=="__main__" : arr=[1,2,3,4,5]; n=len(arr); findSubSeq(arr,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))); ; n := (arr)->size(); ; findSubSeq(arr, n); ) else skip; operation findSubSeq(arr : OclAny, n : OclAny) pre: true post: true activity: arr := arr->sort(); ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, n); ; var prev : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n); ; var max : int := 0; ; var maxprev : int := -1; ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(-1 + 1, i - 1)->reverse() do ( if (arr[i+1] mod arr[j+1] = 0 & (count[j+1] + 1->compareTo(count[i+1])) > 0) then ( count[i+1] := count[j+1] + 1; ; prev[i+1] := j; ) else skip) ; if ((max->compareTo(count[i+1])) < 0) then ( max := count[i+1]; ; maxprev := i; ) else skip) ; var i : int := maxprev; ; while (i >= 0) do ( if (arr[i+1] /= -1) then ( execute (arr[i+1])->display(); ) else skip ; i := prev[i+1];); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=input().split() l=[chr(i+65)if i<26 else 'A'+chr(i-26+97)for i in range(n)] for i in range(n-k+1): l[i+k-1]=l[i]if a[i]=='NO' else l[i+k-1] print(*l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := input().split() ; var l : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (if i < 26 then (i + 65)->byte2char() else 'A' + (i - 26 + 97)->byte2char() endif)) ; for i : Integer.subrange(0, n - k + 1-1) do ( l[i + k - 1+1] := if a[i+1] = 'NO' then l[i+1] else l[i + k - 1+1] endif) ; execute ((argument * (test (logical_test (comparison (expr (atom (name l))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=100005 def LIS(a,n): dp=[0 for i in range(N)] d=[0 for i in range(N)] ans=0 for i in range(n): dp[a[i]]=1 for j in range(2,a[i]): if j*j>a[i]: break if(a[i]% j==0): dp[a[i]]=max(dp[a[i]],dp[d[j]]+1) dp[a[i]]=max(dp[a[i]],dp[d[a[i]//j]]+1) d[j]=a[i] d[a[i]//j]=a[i] ans=max(ans,dp[a[i]]) d[a[i]]=a[i] return ans a=[1,2,3,4,5,6] n=len(a) print(LIS(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 100005 ; skip ; a := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))))) ; n := (a)->size() ; execute (LIS(a, n))->display(); operation LIS(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; var d : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( dp[a[i+1]+1] := 1 ; for j : Integer.subrange(2, a[i+1]-1) do ( if (j * j->compareTo(a[i+1])) > 0 then ( break ) else skip ; if (a[i+1] mod j = 0) then ( dp[a[i+1]+1] := Set{dp[a[i+1]+1], dp[d[j+1]+1] + 1}->max() ; dp[a[i+1]+1] := Set{dp[a[i+1]+1], dp[d[a[i+1] div j+1]+1] + 1}->max() ; d[j+1] := a[i+1] ; d[a[i+1] div j+1] := a[i+1] ) else skip) ; ans := Set{ans, dp[a[i+1]+1]}->max() ; d[a[i+1]+1] := a[i+1]) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfTheSeries(n): sum=0 for i in range(1,n+1): sum+=1.0/(i*(i+1)); return sum if __name__=='__main__' : ans=sumOfTheSeries(10) print(round(ans,6)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var ans : OclAny := sumOfTheSeries(10) ; execute (MathLib.roundN(ans, 6))->display() ) else skip; operation sumOfTheSeries(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( sum := sum + 1.0 / (i * (i + 1));) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(i)for i in input().split()] a=[int(i)for i in input().split()] print(sum(x>m for x in a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute (((argument (test (logical_test (comparison (comparison (expr (atom (name x)))) > (comparison (expr (atom (name m))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) print(m-len(list(filter(lambda x : x<=m,[int(x)for x in input().split()])))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (m - (((input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))->select( _x | (lambda x : OclAny in ((x->compareTo(m)) <= 0))->apply(_x) = true )))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=list(map(int,input().split())) num=m for i in range(m): if a[i]<=m : num-=1 print(num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var num : OclAny := m ; for i : Integer.subrange(0, m-1) do ( if (a[i+1]->compareTo(m)) <= 0 then ( num := num - 1 ) else skip) ; execute (num)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect n,m=map(int,input().split()) a=list(map(int,input().split())) x=bisect.bisect_left(a,m+1) print(m-x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := bisect.bisect_left(a, m + 1) ; execute (m - x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=(int(x)for x in input().split()) A=(int(x)for x in input().split()) print(M-len([x for x in A if x<=M])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var A : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; execute (M - (A->select(x | (x->compareTo(M)) <= 0)->collect(x | (x)))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def conver(m,n): if(m==n): return 0 if(m>n): return m-n if(m<=0 and n>0): return-1 if(n % 2==1): return 1+conver(m,n+1) else : return 1+conver(m,n/2) m=3 n=11 print("Minimum number of operations :",conver(m,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; m := 3 ; n := 11 ; execute ("Minimum number of operations :")->display(); operation conver(m : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (m = n) then ( return 0 ) else skip ; if ((m->compareTo(n)) > 0) then ( return m - n ) else skip ; if (m <= 0 & n > 0) then ( return -1 ) else skip ; if (n mod 2 = 1) then ( return 1 + conver(m, n + 1) ) else ( return 1 + conver(m, n / 2) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[input()for h in range(n)] s=[0]*26 ss=[0]*26 was=0 re=0 count=0 for i in range(n-1): if(sum(s)==1 or sum(ss)==-25)and was==0 : was=1 if a[i][0]=='!' : q=1 if was==1 : re+=1 count+=1 elif a[i][0]=='.' : q=2 else : if was==1 : re+=1 s[ord(a[i][2])-ord('a')]=0 ss[ord(a[i][2])-ord('a')]=-1 continue if was==0 : s1=[0]*26 for j in range(2,len(a[i])): if q==2 : s[ord(a[i][j])-ord('a')]=0 ss[ord(a[i][j])-ord('a')]=-1 else : if ss[ord(a[i][j])-ord('a')]==0 and(s[ord(a[i][j])-ord('a')]==1 or count==1): s1[ord(a[i][j])-ord('a')]=1 if q==1 : s=s1.copy() print(re) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(h | true)->collect(h | ((OclFile["System.in"]).readLine())) ; var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; var ss : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; var was : int := 0 ; var re : int := 0 ; var count : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if ((s)->sum() = 1 or (ss)->sum() = -25) & was = 0 then ( was := 1 ) else skip ; if a[i+1]->first() = '!' then ( var q : int := 1 ; if was = 1 then ( re := re + 1 ) else skip ; count := count + 1 ) else (if a[i+1]->first() = '.' then ( q := 2 ) else ( if was = 1 then ( re := re + 1 ) else skip ; s[(a[i+1][2+1])->char2byte() - ('a')->char2byte()+1] := 0 ; ss[(a[i+1][2+1])->char2byte() - ('a')->char2byte()+1] := -1 ; continue ) ) ; if was = 0 then ( var s1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for j : Integer.subrange(2, (a[i+1])->size()-1) do ( if q = 2 then ( s[(a[i+1][j+1])->char2byte() - ('a')->char2byte()+1] := 0 ; ss[(a[i+1][j+1])->char2byte() - ('a')->char2byte()+1] := -1 ) else ( if ss[(a[i+1][j+1])->char2byte() - ('a')->char2byte()+1] = 0 & (s[(a[i+1][j+1])->char2byte() - ('a')->char2byte()+1] = 1 or count = 1) then ( s1[(a[i+1][j+1])->char2byte() - ('a')->char2byte()+1] := 1 ) else skip )) ; if q = 1 then ( s := s1->copy() ) else skip ) else skip) ; execute (re)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minSteps(arr,n): maxVal=max(arr) return maxVal arr=[1,2,4] n=len(arr) print(minSteps(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{ 4 })) ; n := (arr)->size() ; execute (minSteps(arr, n))->display(); operation minSteps(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var maxVal : OclAny := (arr)->max() ; return maxVal; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sr=lambda : sys.stdin.readline().rstrip() ir=lambda : int(sr()) lr=lambda : list(map(int,sr().split())) N=ir() A=lr() def min_range(A): smaller=[[0,-1]] ret=[] for i,a in enumerate(A): while smaller[-1][0]>a : smaller.pop() ret.append(i-smaller[-1][1]) smaller.append([a,i]) return ret B=min_range(A) C=min_range(A[: :-1])[: :-1] answer=0 for i in range(N): answer+=A[i]*B[i]*C[i] print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var sr : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var ir : Function := lambda $$ : OclAny in (("" + ((sr->apply())))->toInteger()) ; var lr : Function := lambda $$ : OclAny in (((sr->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var N : OclAny := ir->apply() ; var A : OclAny := lr->apply() ; skip ; var B : OclAny := min_range(A) ; var C : OclAny := min_range(A(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var answer : int := 0 ; for i : Integer.subrange(0, N-1) do ( answer := answer + A[i+1] * B[i+1] * C[i+1]) ; execute (answer)->display(); operation min_range(A : OclAny) : OclAny pre: true post: true activity: var smaller : Sequence := Sequence{ Sequence{0}->union(Sequence{ -1 }) } ; var ret : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); while (smaller->last()->first()->compareTo(a)) > 0 do ( smaller := smaller->front()) ; execute ((i - smaller->last()[1+1]) : ret) ; execute ((Sequence{a}->union(Sequence{ i })) : smaller)) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[['\'',',','.',' ! ',' ? '],[' a ',' b',' c ',' A ',' B',' C '],[' d ',' e ',' f',' D ',' E ',' F'],[' g ',' h ',' i ',' G ',' H ',' I '],[' j ',' k ',' l ',' J ',' K ',' L '],[' m ',' n ',' o ',' M ',' N ',' O '],[' p ',' q ',' r',' s ',' P ',' Q ',' R',' S '],[' t ',' u',' v ',' T ',' U',' V '],[' w ',' x ',' y ',' z ',' W ',' X ',' Y ',' Z ']] while 1 : try : b=input()+'@' except : break c=0 ans='' for i in range(len(b)-1): if b[i]!=b[i+1]: if b[i]!='0' : d=int(b[i])-1 ans+=a[d][c % len(a[d])] c=0 else : c+=1 if b[i]==b[i+1]=='0' : ans+=' ' print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Sequence{Sequence{'\''}->union(Sequence{','}->union(Sequence{'.'}->union(Sequence{' ! '}->union(Sequence{ ' ? ' }))))}->union(Sequence{Sequence{' a '}->union(Sequence{' b'}->union(Sequence{' c '}->union(Sequence{' A '}->union(Sequence{' B'}->union(Sequence{ ' C ' })))))}->union(Sequence{Sequence{' d '}->union(Sequence{' e '}->union(Sequence{' f'}->union(Sequence{' D '}->union(Sequence{' E '}->union(Sequence{ ' F' })))))}->union(Sequence{Sequence{' g '}->union(Sequence{' h '}->union(Sequence{' i '}->union(Sequence{' G '}->union(Sequence{' H '}->union(Sequence{ ' I ' })))))}->union(Sequence{Sequence{' j '}->union(Sequence{' k '}->union(Sequence{' l '}->union(Sequence{' J '}->union(Sequence{' K '}->union(Sequence{ ' L ' })))))}->union(Sequence{Sequence{' m '}->union(Sequence{' n '}->union(Sequence{' o '}->union(Sequence{' M '}->union(Sequence{' N '}->union(Sequence{ ' O ' })))))}->union(Sequence{Sequence{' p '}->union(Sequence{' q '}->union(Sequence{' r'}->union(Sequence{' s '}->union(Sequence{' P '}->union(Sequence{' Q '}->union(Sequence{' R'}->union(Sequence{ ' S ' })))))))}->union(Sequence{Sequence{' t '}->union(Sequence{' u'}->union(Sequence{' v '}->union(Sequence{' T '}->union(Sequence{' U'}->union(Sequence{ ' V ' })))))}->union(Sequence{ Sequence{' w '}->union(Sequence{' x '}->union(Sequence{' y '}->union(Sequence{' z '}->union(Sequence{' W '}->union(Sequence{' X '}->union(Sequence{' Y '}->union(Sequence{ ' Z ' }))))))) })))))))) ; while 1 do ( try ( var b : String := (OclFile["System.in"]).readLine() + '@') catch (_e : OclException) do ( break) ; var c : int := 0 ; var ans : String := '' ; for i : Integer.subrange(0, (b)->size() - 1-1) do ( if b[i+1] /= b[i + 1+1] then ( if b[i+1] /= '0' then ( var d : double := ("" + ((b[i+1])))->toInteger() - 1 ; ans := ans + a[d+1][c mod (a[d+1])->size()+1] ) else skip ; c := 0 ) else ( c := c + 1 ) ; if b[i+1] = b[i + 1+1] & (b[i + 1+1] == '0') then ( ans := ans + ' ' ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=[None,"',.!?","abcABC","defDEF","ghiGHI","jklJKL","mnoMNO","pqrsPQRS","tuvTUV","wxyzWXYZ",] try : while 1 : ans=[] *S,=map(int,input()) S.append(0) prv=0 cur=-1 for c in S : if c==prv : if c==0 : ans.append(" ") cur=0 else : cur+=1 else : if prv!=0 : t=T[int(prv)] ans.append(t[cur % len(t)]) cur=0 prv=c print(*ans,sep='') except EOFError : ... ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : Sequence := Sequence{null}->union(Sequence{"',.!?"}->union(Sequence{"abcABC"}->union(Sequence{"defDEF"}->union(Sequence{"ghiGHI"}->union(Sequence{"jklJKL"}->union(Sequence{"mnoMNO"}->union(Sequence{"pqrsPQRS"}->union(Sequence{"tuvTUV"}->union(Sequence{ "wxyzWXYZ" }))))))))) ; try ( while 1 do ( var ans : Sequence := Sequence{})) ; (testlist_star_expr (star_expr * (expr (atom (name S)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name S)))) ,)} := ((OclFile["System.in"]).readLine())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import fileinput chr_master=['','\',.! ? ',' abcABC ',' defDEF ',' ghiGHI ',' jklJKL ',' mnoMNO ',' pqrsPQRS ',' tuvTUV ',' wxyzWXYZ '] for s in(line.strip()for line in fileinput.input()): s+='!' prev_c,cnt=0,1 ans='' for c in s : if c==prev_c : cnt+=1 continue if prev_c=='0' : if cnt>1 : ans+=''*(cnt-1) else : ans+=chr_master[int(prev_c)][cnt-1] prev_c,cnt=c,1 print(ans[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var chr_master : Sequence := Sequence{''}->union(Sequence{'\',.! ? '}->union(Sequence{' abcABC '}->union(Sequence{' defDEF '}->union(Sequence{' ghiGHI '}->union(Sequence{' jklJKL '}->union(Sequence{' mnoMNO '}->union(Sequence{' pqrsPQRS '}->union(Sequence{' tuvTUV '}->union(Sequence{ ' wxyzWXYZ ' }))))))))) ; for s : Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name line)) (trailer . (name strip) (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name line)))) in (logical_test (comparison (expr (atom (name fileinput)) (trailer . (name input) (arguments ( ))))))))} do ( s := s + '!' ; var prev_c : OclAny := null; var cnt : OclAny := null; Sequence{prev_c,cnt} := Sequence{0,1} ; var ans : String := '' ; for c : s do ( if c = prev_c then ( cnt := cnt + 1 ; continue ) else skip ; if prev_c = '0' then ( if cnt > 1 then ( ans := ans + StringLib.nCopies('', (cnt - 1)) ) else skip ) else ( ans := ans + chr_master[("" + ((prev_c)))->toInteger()+1][cnt - 1+1] ) ; var prev_c : OclAny := null; var cnt : OclAny := null; Sequence{prev_c,cnt} := Sequence{c,1}) ; execute (ans->tail())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tbl=["","',.!?","abcABC","defDEF","ghiGHI","jklJKL","mnoMNO","pqrsPQRS","tuvTUV","wxyzWXYZ"] while True : try : s=input().strip() except : break ans,i='',0 while iunion(Sequence{"',.!?"}->union(Sequence{"abcABC"}->union(Sequence{"defDEF"}->union(Sequence{"ghiGHI"}->union(Sequence{"jklJKL"}->union(Sequence{"mnoMNO"}->union(Sequence{"pqrsPQRS"}->union(Sequence{"tuvTUV"}->union(Sequence{ "wxyzWXYZ" }))))))))) ; while true do ( try ( var s : OclAny := input()->trim()) catch (_e : OclException) do ( break) ; var ans : OclAny := null; var i : OclAny := null; Sequence{ans,i} := Sequence{'',0} ; while (i->compareTo((s)->size())) < 0 do ( var c : OclAny := s[i+1] ; var w : OclAny := null; var d : OclAny := null; var i : OclAny := null; Sequence{w,d,i} := Sequence{0,("" + ((c)))->toInteger(),i + 1} ; while (i->compareTo((s)->size())) < 0 & s[i+1] = c do ( var i : OclAny := null; var w : OclAny := null; Sequence{i,w} := Sequence{i + 1,w + 1}) ; if d = 0 then ( ans := ans + StringLib.nCopies(' ', w) ) else ( ans := ans + tbl[d+1][w mod (tbl[d+1])->size()+1] )) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import fileinput chr_master=['','\',.! ? ',' abcABC ',' defDEF ',' ghiGHI ',' jklJKL ',' mnoMNO ',' pqrsPQRS ',' tuvTUV ',' wxyzWXYZ '] for s in(line.strip()for line in fileinput.input()): s+='!' prev_c=None cnt=0 chr_list=[] for c in s : if c==prev_c : cnt+=1 continue if prev_c=='0' : if cnt>1 : chr_list.extend([(0,0)]*(cnt-1)) else : if prev_c is not None : chr_list.append((int(prev_c),cnt-1)) prev_c=c cnt=1 print(''.join(chr_master[i][j]for i,j in chr_list)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var chr_master : Sequence := Sequence{''}->union(Sequence{'\',.! ? '}->union(Sequence{' abcABC '}->union(Sequence{' defDEF '}->union(Sequence{' ghiGHI '}->union(Sequence{' jklJKL '}->union(Sequence{' mnoMNO '}->union(Sequence{' pqrsPQRS '}->union(Sequence{' tuvTUV '}->union(Sequence{ ' wxyzWXYZ ' }))))))))) ; for s : Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name line)) (trailer . (name strip) (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name line)))) in (logical_test (comparison (expr (atom (name fileinput)) (trailer . (name input) (arguments ( ))))))))} do ( s := s + '!' ; var prev_c : OclAny := null ; var cnt : int := 0 ; var chr_list : Sequence := Sequence{} ; for c : s do ( if c = prev_c then ( cnt := cnt + 1 ; continue ) else skip ; if prev_c = '0' then ( if cnt > 1 then ( chr_list := chr_list->union(MatrixLib.elementwiseMult(Sequence{ Sequence{0, 0} }, (cnt - 1))) ) else skip ) else ( if not(prev_c <>= null) then ( execute ((Sequence{("" + ((prev_c)))->toInteger(), cnt - 1}) : chr_list) ) else skip ) ; prev_c := c ; cnt := 1) ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name chr_master)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name chr_list)))))))), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CountCharacters(str,k): cnt=0 l=len(str) for i in range(l): if(ord(str[i])display() ; execute ("Characters with ASCII values")->display() ) else skip; operation CountCharacters(OclType["String"] : OclAny, k : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; var l : int := (OclType["String"])->size() ; for i : Integer.subrange(0, l-1) do ( if (((("" + ([i+1])))->char2byte()->compareTo(k)) < 0) then ( cnt := cnt + 1 ) else skip) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(i)for i in input().split()] dic={} for i in range(n): if a[i]in dic : dic[a[i]]+=1 else : dic[a[i]]=1 a,b=0,0 for k,v in sorted(dic.items(),key=lambda x :-x[0]): if a==0 : if 4<=v : a,b=k,k break elif 2<=v : a=k elif 2<=v : b=k break if not a==0 or not b==0 : print(a*b) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var dic : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( if (dic)->includes(a[i+1]) then ( dic[a[i+1]+1] := dic[a[i+1]+1] + 1 ) else ( dic[a[i+1]+1] := 1 )) ; var b : OclAny := null; Sequence{a,b} := Sequence{0,0} ; for _tuple : dic->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sortedBy($x | (lambda x : OclAny in (-x->first()))->apply($x)) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if a = 0 then ( if 4 <= v then ( var b : OclAny := null; Sequence{a,b} := Sequence{k,k} ; break ) else (if 2 <= v then ( a := k ) else skip) ) else (if 2 <= v then ( var b : OclAny := k ; break ) else skip)) ; if not(a = 0) or not(b = 0) then ( execute (MatrixLib.elementwiseMult(a, b))->display() ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,fractions,itertools,collections def solve(N : int,A : "List[int]"): c=collections.Counter(A).items() a=[aa[0]for aa in c if aa[1]>1] a.sort() s=[aa[0]for aa in c if aa[1]>3] s.sort() if len(a)>1 : r=a[-1]*a[-2] else : r=0 if len(s)>0 : ss=s[-1]**2 else : ss=0 print(max(r,ss)) return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() N=int(next(tokens)) A=[int(next(tokens))for _ in range(N)] solve(N,A) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(N : int, A : "List[int]") pre: true post: true activity: var c : OclAny := collections.Counter(A)->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) ; var a : Sequence := c->select(aa | aa[1+1] > 1)->collect(aa | (aa->first())) ; a := a->sort() ; var s : Sequence := c->select(aa | aa[1+1] > 3)->collect(aa | (aa->first())) ; s := s->sort() ; if (a)->size() > 1 then ( var r : double := a->last() * a->front()->last() ) else ( r := 0 ) ; if (s)->size() > 0 then ( var ss : double := (s->last())->pow(2) ) else ( ss := 0 ) ; execute (Set{r, ss}->max())->display() ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var N : int := ("" + (((tokens).next())))->toInteger() ; var A : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((tokens).next())))->toInteger())) ; solve(N, A); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(N : int,A : "List[int]"): A.sort(reverse=True) i=0 tmp=[] while i1 : ret=tmp[0]*tmp[1] else : ret=0 print(ret) return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() N=int(next(tokens)) A=[int(next(tokens))for _ in range(N)] solve(N,A) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(N : int, A : "List[int]") pre: true post: true activity: A := A->sort() ; var i : int := 0 ; var tmp : Sequence := Sequence{} ; while (i->compareTo(N - 1)) < 0 do ( if A[i+1] = A[i + 1+1] then ( execute ((A[i+1]) : tmp) ; i := i + 1 ) else skip ; i := i + 1) ; if (tmp)->size() > 1 then ( var ret : double := tmp->first() * tmp[1+1] ) else ( ret := 0 ) ; execute (ret)->display() ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var N : int := ("" + (((tokens).next())))->toInteger() ; var A : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((tokens).next())))->toInteger())) ; solve(N, A); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[-1]*26 all=set(i for i in "abcdefghijklmnoprqstuvwxyz") bad=set("") res_cnt=0 flag=False for i in range(n-1): cmd,word=input().split() if flag : if cmd in "!?" : res_cnt+=1 continue if cmd=="." : for c in set(word): pos=ord(c)-ord("a") a[pos]=0 all.discard(c) bad.discard(c) elif cmd=="!" : curr_bad=set() for c in set(word): pos=ord(c)-ord("a") if a[pos]==0 : all.discard(c) else : curr_bad.add(c) if not bad : bad=curr_bad else : old_bad=bad.copy() bad=bad.intersection(curr_bad) for c in old_bad-bad : pos=ord(c)-ord("a") a[pos]=0 all.discard(c) for c in curr_bad-bad : pos=ord(c)-ord("a") a[pos]=0 all.discard(c) else : c=word[0] pos=ord(c)-ord("a") a[pos]=0 all.discard(c) bad.discard(c) if len(bad)==1 or len(all)==1 : flag=True print(res_cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, 26) ; var all : Set := Set{}->union(((argument (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom "abcdefghijklmnoprqstuvwxyz")))))))) ; var bad : Set := Set{}->union(("")) ; var res_cnt : int := 0 ; var flag : boolean := false ; for i : Integer.subrange(0, n - 1-1) do ( var cmd : OclAny := null; var word : OclAny := null; Sequence{cmd,word} := input().split() ; if flag then ( if ("!?")->characters()->includes(cmd) then ( res_cnt := res_cnt + 1 ) else skip ; continue ) else skip ; if cmd = "." then ( for c : Set{}->union((word)) do ( var pos : double := (c)->char2byte() - ("a")->char2byte() ; a[pos+1] := 0 ; execute ((c) /: all) ; execute ((c) /: bad)) ) else (if cmd = "!" then ( var curr_bad : Set := Set{}->union(()) ; for c : Set{}->union((word)) do ( pos := (c)->char2byte() - ("a")->char2byte() ; if a[pos+1] = 0 then ( execute ((c) /: all) ) else ( execute ((c) : curr_bad) )) ; if not(bad) then ( bad := curr_bad ) else ( var old_bad : OclAny := bad->copy() ; bad := bad->intersection(curr_bad) ; for c : old_bad - bad do ( pos := (c)->char2byte() - ("a")->char2byte() ; a[pos+1] := 0 ; execute ((c) /: all)) ; for c : curr_bad - bad do ( pos := (c)->char2byte() - ("a")->char2byte() ; a[pos+1] := 0 ; execute ((c) /: all)) ) ) else ( var c : OclAny := word->first() ; pos := (c)->char2byte() - ("a")->char2byte() ; a[pos+1] := 0 ; execute ((c) /: all) ; execute ((c) /: bad) ) ) ; if (bad)->size() = 1 or (all)->size() = 1 then ( flag := true ) else skip) ; execute (res_cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=input().split() ans=[] for i in range(n): if i<26 : ans.append(chr(i+65)) else : ans.append('Anubhab'+chr(i+71)) for i in range(n-k+1): if a[i]=='NO' : ans[i+k-1]=ans[i] print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := input().split() ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if i < 26 then ( execute (((i + 65)->byte2char()) : ans) ) else ( execute (('Anubhab' + (i + 71)->byte2char()) : ans) )) ; for i : Integer.subrange(0, n - k + 1-1) do ( if a[i+1] = 'NO' then ( ans[i + k - 1+1] := ans[i+1] ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) A=tuple(map(int,input().split())) A=sorted(A,reverse=True) from collections import Counter CA=Counter(A) b=0 for a in A : if CA[a]>=2 : CA[a]-=2 b=a break c=0 for a in A : if CA[a]>=2 : c=a break print(b*c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; A := A->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; skip ; var CA : OclAny := Counter(A) ; var b : int := 0 ; for a : A do ( if CA[a+1] >= 2 then ( CA[a+1] := CA[a+1] - 2 ; b := a ; break ) else skip) ; var c : int := 0 ; for a : A do ( if CA[a+1] >= 2 then ( c := a ; break ) else skip) ; execute (b * c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections N=int(input()) A=list(map(int,input().split())) S=collections.Counter(A) T=[] sq=-1 ; r1=-1 ; r2=-1 T=S.most_common() T.sort(reverse=True,key=lambda x : x[0]) for i in range(len(T)): if T[i][1]>3 : if sq==-1 : sq=i if r1==-1 : r1=i else : if r2==-1 : r2=i elif T[i][1]>1 : if r1==-1 : r1=i else : if r2==-1 : r2=i if r1!=-1 and r2!=-1 : if sq!=-1 : print(max(T[sq][0]**2,T[r1][0]*T[r2][0])) else : print(T[r1][0]*T[r2][0]) elif sq!=-1 : print(T[sq][0]**2) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var S : OclAny := .Counter(A) ; var T : Sequence := Sequence{} ; var sq : int := -1; var r1 : int := -1; var r2 : int := -1 ; T := S.most_common() ; T := T->sort() ; for i : Integer.subrange(0, (T)->size()-1) do ( if T[i+1][1+1] > 3 then ( if sq = -1 then ( sq := i ; if r1 = -1 then ( r1 := i ) else ( if r2 = -1 then ( r2 := i ) else skip ) ) else skip ) else (if T[i+1][1+1] > 1 then ( if r1 = -1 then ( r1 := i ) else ( if r2 = -1 then ( r2 := i ) else skip ) ) else skip)) ; if r1 /= -1 & r2 /= -1 then ( if sq /= -1 then ( execute (Set{(T[sq+1]->first())->pow(2), T[r1+1]->first() * T[r2+1]->first()}->max())->display() ) else ( execute (T[r1+1]->first() * T[r2+1]->first())->display() ) ) else (if sq /= -1 then ( execute ((T[sq+1]->first())->pow(2))->display() ) else ( execute (0)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSteps(x,y): if xdisplay() ) else skip; operation countSteps(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (x->compareTo(y)) < 0 then ( return x + y + 2 * ((y - x) div 2) ) else ( return x + y + 2 * (((x - y) + 1) div 2) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSolutions(n): x=0 res=0 yCount=0 while(yCount*yCount=n)): yCount=yCount-1 return res print("Total Number of distinct ",,countSolutions(6)) ------------------------------------------------------------ OCL File: --------- class FromPython { small_stmt`nestedAttributeDefinitions operation initialise() pre: true post: true activity: skip ; small_stmt(stmt (simple_stmt (small_stmt print) ( )) (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom "Total Number of distinct "))))) ,)) ,)) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name countSolutions)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 6))))))))) ))))))))))) )); operation countSolutions(n : OclAny) : OclAny pre: true post: true activity: var x : int := 0 ; var res : int := 0 ; var yCount : int := 0 ; while ((yCount * yCount->compareTo(n)) < 0) do ( yCount := yCount + 1) ; while (yCount /= 0) do ( res := res + yCount ; x := x + 1 ; while (yCount /= 0 & ((x * x + (yCount - 1) * (yCount - 1)->compareTo(n)) >= 0)) do ( yCount := yCount - 1)) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys ; def rotateRec(n,L,B): m=sys.maxsize ; for i in range(n): if(max(L[i],B[i])<=m): m=max(L[i],B[i]); elif(min(L[i],B[i])<=m): m=min(L[i],B[i]); else : return 0 ; return 1 ; n=3 ; L=[5,5,6]; B=[6,7,8]; if(rotateRec(n,L,B)==1): print("YES"); else : print("NO"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; ; skip ; n := 3; ; L := Sequence{5}->union(Sequence{5}->union(Sequence{ 6 })); ; B := Sequence{6}->union(Sequence{7}->union(Sequence{ 8 })); ; if (rotateRec(n, L, B) = 1) then ( execute ("YES")->display(); ) else ( execute ("NO")->display(); ); operation rotateRec(n : OclAny, L : OclAny, B : OclAny) pre: true post: true activity: var m : (trailer . (name maxsize)) := (trailer . (name maxsize)); ; for i : Integer.subrange(0, n-1) do ( if ((Set{L[i+1], B[i+1]}->max()->compareTo(m)) <= 0) then ( m := Set{L[i+1], B[i+1]}->max(); ) else (if ((Set{L[i+1], B[i+1]}->min()->compareTo(m)) <= 0) then ( m := Set{L[i+1], B[i+1]}->min(); ) else ( return 0; ) ) ) ; return 1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys class Node : __slots__=['key','left','right'] def __init__(self,key): self.key=key self.left=self.right=None root=None def insert(key): global root x,y=root,None while x!=None : x,y=x.left if keyexists( _x | result = _x ); static attribute __slots__ : Sequence := Sequence{'key'}->union(Sequence{'left'}->union(Sequence{ 'right' })); attribute key : OclAny := key; attribute left : OclAny := null; var self.right : OclAny := null; operation initialise(key : OclAny) : Node pre: true post: true activity: self.key := key ; self.left := null; var self.right : OclAny := null; return self; } class FromPython { attribute root : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; var root : OclAny := null ; skip ; skip ; skip ; skip ; input() ; for e : OclFile["System.in"] do ( if e->first() = 'i' then ( insert(("" + ((e.subrange(7+1))))->toInteger()) ) else (if e->first() = 'f' then ( execute (Sequence{'no'}->union(Sequence{ 'yes' })[find(("" + ((e.subrange(5+1))))->toInteger())+1])->display() ) else ( execute (inorder(root))->display(); execute (preorder(root))->display() ) ) ); operation insert(key : OclAny) pre: true post: true activity: skip ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{root,null} ; while x /= null do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{if (key->compareTo(x.key)) < 0 then x.left else x.right endif,x}) ; if y = null then ( root := (Node.newNode()).initialise(key) ) else (if (key->compareTo(y.key)) < 0 then ( y.left := (Node.newNode()).initialise(key) ) else ( y.right := (Node.newNode()).initialise(key) ) ) ; operation find(target : OclAny) : OclAny pre: true post: true activity: var result : OclAny := root ; while result & target /= result.key do ( result := if (target->compareTo(result.key)) < 0 then result.left else result.right endif) ; return result /= null; operation inorder(node : OclAny) : OclAny pre: true post: true activity: return if node then inorder(node.left) + StringLib.formattedString('{node.key}') + inorder(node.right) else '' endif; operation preorder(node : OclAny) : OclAny pre: true post: true activity: return if node then StringLib.formattedString('{node.key}') + preorder(node.left) + preorder(node.right) else '' endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class BinarySearchTree(object): __slots__=['root'] def __init__(self): self.root=None def insert(self,key): new_node=[key,None,None] if self.root is None : self.root=new_node return parent,child=None,self.root while child : parent=child child=child[1]if keyexists( _x | result = _x ); static attribute __slots__ : Sequence := Sequence{ 'root' }; attribute root : OclAny := null; operation initialise() : pre: true post: true activity: self.root := null; return self; operation insert(key : OclAny) pre: true post: true activity: var new_node : Sequence := Sequence{key}->union(Sequence{null}->union(Sequence{ null })) ; if self.root <>= null then ( self.root := new_node ; return ) else skip ; var parent : OclAny := null; var child : OclAny := null; Sequence{parent,child} := Sequence{null,self.root} ; while child do ( var parent : OclAny := child ; var child : OclAny := if (key->compareTo(child->first())) < 0 then child[1+1] else child[2+1] endif) ; if (key->compareTo(parent->first())) < 0 then ( parent[1+1] := new_node ) else ( parent[2+1] := new_node ); operation find(key : OclAny) : OclAny pre: true post: true activity: var current : OclAny := self.root ; while current & current->first() /= key do ( current := if (key->compareTo(current->first())) < 0 then current[1+1] else current[2+1] endif) ; return current; operation walk(walk_type : OclAny) : OclAny pre: true post: true activity: var a : Sequence := Sequence{} ; self._walk(self.root, a, walk_type) ; return a; operation _walk(node : OclAny,a : OclAny,walk_type : OclAny) pre: true post: true activity: if walk_type = 0 then ( execute ((node->first()) : a) ) else skip ; if node[1+1] then ( self._walk(node[1+1], a, walk_type) ) else skip ; if walk_type = 1 then ( execute ((node->first()) : a) ) else skip ; if node[2+1] then ( self._walk(node[2+1], a, walk_type) ) else skip; } class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( skip ; input() ; var tree : BinarySearchTree := (BinarySearchTree.newBinarySearchTree()).initialise() ; for cmd : Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name l)) (trailer . (name split) (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name l)))) in (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin)))))))} do ( if cmd->first() = 'insert' then ( tree := tree.insertAt(("" + ((cmd[1+1])))->toInteger()+1, ("" + ((cmd[1+1])))->toInteger()) ) else (if cmd->first() = 'find' then ( execute (if tree->indexOf(("" + ((cmd[1+1])))->toInteger()) - 1 then 'yes' else 'no' endif)->display() ) else ( execute ('')->display() ; execute ('')->display() ) ) ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,key,parent=None,left=None,right=None): self.key=key self.parent=parent self.left=left self.right=right root=None def insert(k): global root y=None x=root z=Node(k) while x is not None : y=x if z.keyexists( _x | result = _x ); attribute key : OclAny := key; attribute parent : OclAny := parent; attribute left : OclAny := left; attribute right : OclAny := right; operation initialise(key : OclAny,parent : OclAny,left : OclAny,right : OclAny) : Node pre: true post: true activity: self.key := key ; self.parent := parent ; self.left := left ; self.right := right; return self; } class FromPython { attribute root : OclAny; operation initialise() pre: true post: true activity: skip ; var root : OclAny := null ; skip ; skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var cmd : OclAny := input().split() ; if cmd->first() = 'insert' then ( insert(("" + ((cmd[1+1])))->toInteger()) ) else (if cmd->first() = 'find' then ( if not(find(root, ("" + ((cmd[1+1])))->toInteger()) <>= null) then ( execute ('yes')->display() ) else ( execute ('no')->display() ) ) else (if cmd->first() = 'print' then ( inorder(root) ; execute (->display() ; preorder(root) ; execute (->display() ) else skip ) ) ); operation insert(k : OclAny) pre: true post: true activity: skip ; var y : OclAny := null ; var x : OclAny := root ; var z : Node := (Node.newNode()).initialise(k) ; while not(x <>= null) do ( y := x ; if (z.key->compareTo(x.key)) < 0 then ( x := x.left ) else ( x := x.right )) ; z.parent := y ; if y <>= null then ( root := z ) else ( if (z.key->compareTo(y.key)) < 0 then ( y.left := z ) else ( y.right := z ) ); operation find(u : OclAny, k : OclAny) : OclAny pre: true post: true activity: while not(u <>= null) & k /= u.key do ( if (k->compareTo(u.key)) < 0 then ( u := u.left ) else ( u := u.right )) ; return u; operation inorder(u : OclAny) pre: true post: true activity: if u <>= null then ( return ) else skip ; inorder(u.left) ; execute (StringLib.format(' %d',u.key))->display() ; inorder(u.right); operation preorder(u : OclAny) pre: true post: true activity: if u <>= null then ( return ) else skip ; execute (StringLib.format(' %d',u.key))->display() ; preorder(u.left) ; preorder(u.right); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys class Node : def __init__(self,data): self.data=data self.left=self.right=None rt=None def inorder(node): return inorder(node.left)+f'{node.data}'+inorder(node.right)if node else '' def preorder(node): return f'{node.data}'+preorder(node.left)+preorder(node.right)if node else '' def find(node,k): while node : if node.data==k : return True if kexists( _x | result = _x ); attribute data : OclAny := data; attribute left : OclAny := null; var self.right : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.left := null; var self.right : OclAny := null; return self; } class FromPython { attribute rt : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; var rt : OclAny := null ; skip ; skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; for e : b do ( if e->first() = 'i' then ( insert(("" + ((e.subrange(7+1))))->toInteger()) ) else (if e->first() = 'f' then ( if find(rt, ("" + ((e.subrange(5+1))))->toInteger()) then ( execute ('yes')->display() ) else ( execute ('no')->display() ) ) else ( execute (inorder(rt))->display() ; execute (preorder(rt))->display() ) ) ); operation inorder(node : OclAny) : OclAny pre: true post: true activity: return if node then inorder(node.left) + StringLib.formattedString('{node.data}') + inorder(node.right) else '' endif; operation preorder(node : OclAny) : OclAny pre: true post: true activity: return if node then StringLib.formattedString('{node.data}') + preorder(node.left) + preorder(node.right) else '' endif; operation find(node : OclAny, k : OclAny) : OclAny pre: true post: true activity: while node do ( if node.data = k then ( return true ) else skip ; if (k->compareTo(node.data)) < 0 then ( node := node.left ) else ( node := node.right )) ; return false; operation insert(data : OclAny) pre: true post: true activity: skip ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{rt,null} ; while x do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{if (data->compareTo(x.data)) < 0 then x.left else x.right endif,x}) ; if y <>= null then ( rt := (Node.newNode()).initialise(data) ) else (if (data->compareTo(y.data)) < 0 then ( y.left := (Node.newNode()).initialise(data) ) else ( y.right := (Node.newNode()).initialise(data) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys class Node : __slots__=['key','left','right'] def __init__(self,key): self.key=key self.left=self.right=None root=None def insert(key): global root x,y=root,None while x : x,y=x.left if keyexists( _x | result = _x ); static attribute __slots__ : Sequence := Sequence{'key'}->union(Sequence{'left'}->union(Sequence{ 'right' })); attribute key : OclAny := key; attribute left : OclAny := null; var self.right : OclAny := null; operation initialise(key : OclAny) : Node pre: true post: true activity: self.key := key ; self.left := null; var self.right : OclAny := null; return self; } class FromPython { attribute root : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; var root : OclAny := null ; skip ; skip ; skip ; skip ; input() ; for e : OclFile["System.in"] do ( if e->first() = 'i' then ( insert(("" + ((e.subrange(7+1))))->toInteger()) ) else (if e->first() = 'f' then ( execute (Sequence{'yes'}->union(Sequence{ 'no' })[find(("" + ((e.subrange(5+1))))->toInteger())+1])->display() ) else ( execute (inorder(root))->display(); execute (preorder(root))->display() ) ) ); operation insert(key : OclAny) pre: true post: true activity: skip ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{root,null} ; while x do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{if (key->compareTo(x.key)) < 0 then x.left else x.right endif,x}) ; if y <>= null then ( root := (Node.newNode()).initialise(key) ) else (if (key->compareTo(y.key)) < 0 then ( y.left := (Node.newNode()).initialise(key) ) else ( y.right := (Node.newNode()).initialise(key) ) ) ; operation find(target : OclAny) : OclAny pre: true post: true activity: var result : OclAny := root ; while result & target /= result.key do ( result := if (target->compareTo(result.key)) < 0 then result.left else result.right endif) ; return result <>= null; operation inorder(node : OclAny) : OclAny pre: true post: true activity: return if node then inorder(node.left) + StringLib.formattedString('{node.key}') + inorder(node.right) else '' endif; operation preorder(node : OclAny) : OclAny pre: true post: true activity: return if node then StringLib.formattedString('{node.key}') + preorder(node.left) + preorder(node.right) else '' endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd from math import factorial as f from math import ceil,floor,sqrt import math import bisect import re import heapq from copy import deepcopy import itertools from itertools import permutations from sys import exit ii=lambda : int(input()) mi=lambda : map(int,input().split()) li=lambda : list(map(int,input().split())) yes="Yes" no="No" def main(): a='ACL' n=ii() ans='' for i in range(n): ans+=a print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var ii : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var mi : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var li : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var yes : String := "Yes" ; var no : String := "No" ; skip ; main(); operation main() pre: true post: true activity: var a : String := 'ACL' ; var n : OclAny := ii->apply() ; var ans : String := '' ; for i : Integer.subrange(0, n-1) do ( ans := ans + a) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isDivisible(n): temp=n while(n): k=n % 10 if(temp % k==0): return "YES" n/=10 ; return "NO" n=9876543 print(isDivisible(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 9876543 ; execute (isDivisible(n))->display(); operation isDivisible(n : OclAny) : OclAny pre: true post: true activity: var temp : OclAny := n ; while (n) do ( var k : int := n mod 10 ; if (temp mod k = 0) then ( return "YES" ) else skip ; n := n / 10;) ; return "NO"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkPerfectSquare(n): if n<0 : return False else : return n**0.5==int(n**0.5) for _ in range(int(input())): n=int(input()) if checkPerfectSquare(n/2)or checkPerfectSquare(n/4): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if checkPerfectSquare(n / 2) or checkPerfectSquare(n / 4) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); operation checkPerfectSquare(n : OclAny) : OclAny pre: true post: true activity: if n < 0 then ( return false ) else ( return (n)->pow(0.5) = ("" + (((n)->pow(0.5))))->toInteger() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPiles(n,a): occ=dict() for i in a : if i in occ.keys(): occ[i]+=1 else : occ[i]=1 pile=0 while(len(occ)>0): pile+=1 size=0 toRemove=dict() for tm in occ : mx=tm ct=occ[tm] use=min(ct,mx-size+1) occ[mx]-=use size+=use if(occ[mx]==0): toRemove[mx]=1 for tm in toRemove : del occ[tm] return pile a=[0,0,1,1,2] n=len(a) print(countPiles(n,a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 2 })))) ; n := (a)->size() ; execute (countPiles(n, a))->display(); operation countPiles(n : OclAny, a : OclAny) : OclAny pre: true post: true activity: var occ : Map := (arguments ( )) ; for i : a do ( if (occ.keys())->includes(i) then ( occ[i+1] := occ[i+1] + 1 ) else ( occ[i+1] := 1 )) ; var pile : int := 0 ; while ((occ)->size() > 0) do ( pile := pile + 1 ; var size : int := 0 ; var toRemove : Map := (arguments ( )) ; for tm : occ->keys() do ( var mx : OclAny := tm ; var ct : OclAny := occ[tm+1] ; var use : OclAny := Set{ct, mx - size + 1}->min() ; occ[mx+1] := occ[mx+1] - use ; size := size + use ; if (occ[mx+1] = 0) then ( toRemove[mx+1] := 1 ) else skip) ; for tm : toRemove->keys() do ( execute (occ[tm+1])->isDeleted())) ; return pile; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printMaxValPair(v,n): v.sort() N=v[n-1] if N % 2==1 : first_maxima=N//2 second_maxima=first_maxima+1 ans1,ans2=3*(10**18),3*(10**18) from_left,from_right=-1,-1 _from=-1 for i in range(0,n): if v[i]>first_maxima : _from=i break else : diff=first_maxima-v[i] if diffunion(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{6}->union(Sequence{ 1 }))))) ; n := (v)->size() ; printMaxValPair(v, n) ) else skip; operation printMaxValPair(v : OclAny, n : OclAny) pre: true post: true activity: v := v->sort() ; var N : OclAny := v[n - 1+1] ; if N mod 2 = 1 then ( var first_maxima : int := N div 2 ; var second_maxima : int := first_maxima + 1 ; var ans1 : OclAny := null; var ans2 : OclAny := null; Sequence{ans1,ans2} := Sequence{3 * ((10)->pow(18)),3 * ((10)->pow(18))} ; var from_left : OclAny := null; var from_right : OclAny := null; Sequence{from_left,from_right} := Sequence{-1,-1} ; var _from : int := -1 ; for i : Integer.subrange(0, n-1) do ( if (v[i+1]->compareTo(first_maxima)) > 0 then ( _from := i ; break ) else ( var diff : double := first_maxima - v[i+1] ; if (diff->compareTo(ans1)) < 0 then ( var ans1 : OclAny := diff ; var from_left : OclAny := v[i+1] ) else skip )) ; var from_right : OclAny := v[_from+1] ; var diff1 : double := first_maxima - from_left ; var diff2 : double := from_right - second_maxima ; if (diff1->compareTo(diff2)) < 0 then ( execute (N)->display() ) else ( execute (N)->display() ) ) else ( var maxima : int := N div 2 ; ans1 := 3 * ((10)->pow(18)) ; var R : int := -1 ; for i : Integer.subrange(0, n - 1-1) do ( diff := (v[i+1] - maxima)->abs() ; if (diff->compareTo(ans1)) < 0 then ( ans1 := diff ; R := v[i+1] ) else skip) ; execute (N)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,raw_input().split(' ')) q=[int(input())for _ in range(N)] poll=set() cnt=0 for _ in reversed(q): if not _ in poll : print(_) cnt=cnt+1 if cnt==M : break poll.add(_) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (raw_input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var q : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var poll : Set := Set{}->union(()) ; var cnt : int := 0 ; for _anon : (q)->reverse() do ( if not((poll)->includes(_anon)) then ( execute (_anon)->display() ; cnt := cnt + 1 ; if cnt = M then ( break ) else skip ; execute ((_anon) : poll) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findTriangularNumber(n): return(n*(n+1))/2 def printSeries(n): prev=0 for i in range(1,n+1): curr=findTriangularNumber(i) curr=int(curr+prev) print(curr,end=' ') prev=curr n=10 printSeries(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 10 ; printSeries(n); operation findTriangularNumber(n : OclAny) : OclAny pre: true post: true activity: return (n * (n + 1)) / 2; operation printSeries(n : OclAny) pre: true post: true activity: var prev : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( var curr : OclAny := findTriangularNumber(i) ; curr := ("" + ((curr + prev)))->toInteger() ; execute (curr)->display() ; prev := curr); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=map(int,input().split()) ans=0 cnt=[0]*n+[0] for i in a : if i>n : ans+=1 else : cnt[i]+=1 for i in range(n+1): ans+=cnt[i]-i if cnt[i]>=i else cnt[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n)->union(Sequence{ 0 }) ; for i : a do ( if (i->compareTo(n)) > 0 then ( ans := ans + 1 ) else ( cnt[i+1] := cnt[i+1] + 1 )) ; for i : Integer.subrange(0, n + 1-1) do ( ans := ans + if (cnt[i+1]->compareTo(i)) >= 0 then cnt[i+1] - i else cnt[i+1] endif) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**9) def int1(x): return int(x)-1 def II(): return int(input()) def MI(): return map(int,input().split()) def MI1(): return map(int1,input().split()) def LI(): return list(map(int,input().split())) def LI1(): return list(map(int1,input().split())) def LLI(rows_number): return[LI()for _ in range(rows_number)] def MS(): return input().split() def LS(): return list(input()) def LLS(rows_number): return[LS()for _ in range(rows_number)] def printlist(lst,k=' '): print(k.join(list(map(str,lst)))) INF=float('inf') from collections import deque,defaultdict def solve(): N=II() A=LI() dct=defaultdict(lambda : 0) for a in A : dct[a]+=1 ans=0 for key,val in dct.items(): if key==val : continue elif keypow(9)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var INF : double := ("" + (('inf')))->toReal() ; skip ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation int1(x : OclAny) : OclAny pre: true post: true activity: return ("" + ((x)))->toInteger() - 1; operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation MI1() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (int1)->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LI1() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (int1)->apply(_x) )); operation LLI(rows_number : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows_number-1)->select(_anon | true)->collect(_anon | (LI())); operation MS() : OclAny pre: true post: true activity: return input().split(); operation LS() : OclAny pre: true post: true activity: return ((OclFile["System.in"]).readLine())->characters(); operation LLS(rows_number : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows_number-1)->select(_anon | true)->collect(_anon | (LS())); operation printlist(lst : OclAny, k : String) pre: true post: true activity: if k->oclIsUndefined() then k := ' ' else skip; execute (StringLib.sumStringsWithSeparator((((lst)->collect( _x | (OclType["String"])->apply(_x) ))), k))->display(); operation solve() pre: true post: true activity: var N : OclAny := II() ; var A : OclAny := LI() ; var dct : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; for a : A do ( dct[a+1] := dct[a+1] + 1) ; var ans : int := 0 ; for _tuple : dct->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var val : OclAny := _tuple->at(_indx); if key = val then ( continue ) else (if (key->compareTo(val)) < 0 then ( ans := ans + val - key ) else ( ans := ans + val ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=[int(x)for x in input().split()] D={} for a in A : if not a in D : D[a]=1 else : D[a]=D[a]+1 ret=0 for k in D.keys(): if D[k]>k : ret+=D[k]-k elif D[k]toInteger() ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var D : OclAny := Set{} ; for a : A do ( if not((D)->includes(a)) then ( D[a+1] := 1 ) else ( D[a+1] := D[a+1] + 1 )) ; var ret : int := 0 ; for k : D.keys() do ( if (D[k+1]->compareTo(k)) > 0 then ( ret := ret + D[k+1] - k ) else (if (D[k+1]->compareTo(k)) < 0 then ( ret := ret + D[k+1] ) else skip)) ; execute (ret)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,*a=map(int,open(0).read().split()) d={} for i in a : d[i]=d.get(i,0)+1 print(sum(d[i]-i*(d[i]>=i)for i in d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : OclAny := Set{} ; for i : a do ( d[i+1] := d.get(i, 0) + 1) ; execute (((argument (test (logical_test (comparison (expr (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (expr (atom (name i))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) >= (comparison (expr (atom (name i)))))))) )))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name d))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) a.sort() good_val=0 total_cnt=0 tmp_cnt=0 over=0 for i in range(n): if good_val==0 : good_val=a[i] if a[i]==good_val : tmp_cnt+=1 if over==0 and tmp_cnt==good_val : tmp_cnt=0 over=1 if i==n-1 : total_cnt+=tmp_cnt else : total_cnt+=tmp_cnt good_val=a[i] tmp_cnt=1 over=0 if i==n-1 : total_cnt+=tmp_cnt print(total_cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var good_val : int := 0 ; var total_cnt : int := 0 ; var tmp_cnt : int := 0 ; var over : int := 0 ; for i : Integer.subrange(0, n-1) do ( if good_val = 0 then ( good_val := a[i+1] ) else skip ; if a[i+1] = good_val then ( tmp_cnt := tmp_cnt + 1 ; if over = 0 & tmp_cnt = good_val then ( tmp_cnt := 0 ; over := 1 ) else skip ; if i = n - 1 then ( total_cnt := total_cnt + tmp_cnt ) else skip ) else ( total_cnt := total_cnt + tmp_cnt ; good_val := a[i+1] ; tmp_cnt := 1 ; over := 0 ; if i = n - 1 then ( total_cnt := total_cnt + tmp_cnt ) else skip )) ; execute (total_cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isDivisible(n): temp=n sum=0 ; while(n): k=n % 10 ; sum+=k ; n/=10 ; if(temp % sum==0): return "YES" ; return "NO" ; n=123 ; print(isDivisible(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 123; ; execute (isDivisible(n))->display();; operation isDivisible(n : OclAny) pre: true post: true activity: var temp : OclAny := n ; var sum : int := 0; ; while (n) do ( var k : int := n mod 10; ; sum := sum + k; ; n := n / 10;) ; if (temp mod sum = 0) then ( return "YES"; ) else skip ; return "NO";; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math flag=0 for _ in range(int(input())): a=int(input()) if a % 2==0 : print(a//2) else : if flag==0 : print(math.floor(a/2)) flag=1 else : print(math.ceil(a/2)) flag=0 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var flag : int := 0 ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if a mod 2 = 0 then ( execute (a div 2)->display() ) else ( if flag = 0 then ( execute ((a / 2)->floor())->display() ; flag := 1 ) else ( execute ((a / 2)->ceil())->display() ; flag := 0 ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def per_sq(n): sq=int(pow(n,0.5)) if sq*sq==n : return 1 return 0 for i in range(int(input())): n=int(input()) if n % 2==1 : print("NO") elif per_sq(n)==1 : print("YES") else : n//=2 if per_sq(n)==1 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 1 then ( execute ("NO")->display() ) else (if per_sq(n) = 1 then ( execute ("YES")->display() ) else ( n := n div 2 ; if per_sq(n) = 1 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) ) ); operation per_sq(n : OclAny) : OclAny pre: true post: true activity: var sq : int := ("" + (((n)->pow(0.5))))->toInteger() ; if sq * sq = n then ( return 1 ) else skip ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math number=int(input()) up=0 for i in range(0,number): x=int(input()) if x % 2==0 : print(int(x/2)) else : if up==0 or up==-1 : print(math.ceil(x/2)) up=1 else : print(math.floor(x/2)) up=-1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var number : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var up : int := 0 ; for i : Integer.subrange(0, number-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if x mod 2 = 0 then ( execute (("" + ((x / 2)))->toInteger())->display() ) else ( if up = 0 or up = -1 then ( execute ((x / 2)->ceil())->display() ; up := 1 ) else ( execute ((x / 2)->floor())->display() ; up := -1 ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[] for _ in range(n): a.append(int(input())) ans=[a[i]//2 for i in range(n)] curr_sum=sum(ans) i=0 while itoInteger() ; var a : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : a)) ; var ans : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (a[i+1] div 2)) ; var curr_sum : OclAny := (ans)->sum() ; var i : int := 0 ; while (i->compareTo(n)) < 0 & curr_sum < 0 do ( if a[i+1] mod 2 = 1 then ( ans[i+1] := ans[i+1] + 1 ; curr_sum := curr_sum + 1 ) else skip ; i := i + 1) ; for i : Integer.subrange(0, n-1) do ( execute (ans[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def print(*args,end='\n',sep=' ')->None : sys.stdout.write(sep.join(map(str,args))+end) def Solve(): numbers=[] type_=[] for n in range(int(input())): num=int(input()) if num % 2==0 : numbers.append(num//2) type_.append("e") else : numbers.append(num//2) type_.append("o") Sum=sum(numbers) if Sum>0 : i=0 while Sum!=0 : if type_[i]=="o" : numbers[i]-=1 Sum-=1 i+=1 else : i=0 while Sum!=0 : if type_[i]=="o" : numbers[i]+=1 Sum+=1 i+=1 print(*numbers,sep="\n") if __name__=="__main__" : Solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; if __name__ = "__main__" then ( Solve() ) else skip; (funcdef def name print ( (typedargslist (args * (named_parameter (name args))) , (def_parameters (def_parameter (named_parameter (name end)) = (test (logical_test (comparison (expr (atom ' ')))))) , (def_parameter (named_parameter (name sep)) = (test (logical_test (comparison (expr (atom ' ')))))))) ) -> (test (logical_test (comparison (expr (atom None))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name sep)) (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name args)))))))) ))))))))) )))) + (expr (atom (name end))))))))) )))))))))))))) operation Solve() pre: true post: true activity: var numbers : Sequence := Sequence{} ; var type_ : Sequence := Sequence{} ; for n : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if num mod 2 = 0 then ( execute ((num div 2) : numbers) ; execute (("e") : type_) ) else ( execute ((num div 2) : numbers) ; execute (("o") : type_) )) ; var Sum : OclAny := (numbers)->sum() ; if Sum > 0 then ( var i : int := 0 ; while Sum /= 0 do ( if type_[i+1] = "o" then ( numbers[i+1] := numbers[i+1] - 1 ; Sum := Sum - 1 ) else skip ; i := i + 1) ) else ( i := 0 ; while Sum /= 0 do ( if type_[i+1] = "o" then ( numbers[i+1] := numbers[i+1] + 1 ; Sum := Sum + 1 ) else skip ; i := i + 1) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name numbers))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) z=[] z2=[] for i in range(t): n=int(input()) if n % 2==0 : z2.append('e') else : z2.append('o') z.append((n//2)) sum_=sum(z) if sum_<0 : for i in range(len(z)): if z2[i]=='o' : z[i]+=1 sum_+=1 if sum_==0 : break print(*z,sep='\n') elif sum_>0 : for i in range(len(z)): if z2[i]=='0' : z[i]-=1 sum_-=1 if sum_==0 : break print(*z,sep='\n') else : print(*z,sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var z : Sequence := Sequence{} ; var z2 : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( execute (('e') : z2) ) else ( execute (('o') : z2) ) ; execute (((n div 2)) : z)) ; var sum_ : OclAny := (z)->sum() ; if sum_ < 0 then ( for i : Integer.subrange(0, (z)->size()-1) do ( if z2[i+1] = 'o' then ( z[i+1] := z[i+1] + 1 ; sum_ := sum_ + 1 ) else skip ; if sum_ = 0 then ( break ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name z))))))))->display() ) else (if sum_ > 0 then ( for i : Integer.subrange(0, (z)->size()-1) do ( if z2[i+1] = '0' then ( z[i+1] := z[i+1] - 1 ; sum_ := sum_ - 1 ) else skip ; if sum_ = 0 then ( break ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name z))))))))->display() ) else ( execute ((argument * (test (logical_test (comparison (expr (atom (name z))))))))->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def smallestString(N,A): ch='a' S="" if(N<1 or A[0]!=1): S="-1" return S S+=str(ch) ch=chr(ord(ch)+1) for i in range(1,N): diff=A[i]-A[i-1] if(diff>1 or diff<0 or A[i]>26): S="-1" return S elif(diff==0): S+='a' else : S+=ch ch=chr(ord(ch)+1) return S arr=[1,1,2,3,3] n=len(arr) print(smallestString(n,arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var arr : Sequence := Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 3 })))) ; var n : int := (arr)->size() ; execute (smallestString(n, arr))->display(); operation smallestString(N : OclAny, A : OclAny) : OclAny pre: true post: true activity: var ch : String := 'a' ; var S : String := "" ; if (N < 1 or A->first() /= 1) then ( S := "-1" ; return S ) else skip ; S := S + ("" + ((ch))) ; ch := ((ch)->char2byte() + 1)->byte2char() ; for i : Integer.subrange(1, N-1) do ( var diff : double := A[i+1] - A[i - 1+1] ; if (diff > 1 or diff < 0 or A[i+1] > 26) then ( S := "-1" ; return S ) else (if (diff = 0) then ( S := S + 'a' ) else ( S := S + ch ; ch := ((ch)->char2byte() + 1)->byte2char() ) ) ) ; return S; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def returnMaxSum(A,B,n): mp=set() result=0 curr_sum=curr_begin=0 for i in range(0,n): while A[i]in mp : mp.remove(A[curr_begin]) curr_sum-=B[curr_begin] curr_begin+=1 mp.add(A[i]) curr_sum+=B[i] result=max(result,curr_sum) return result if __name__=="__main__" : A=[0,1,2,3,0,1,4] B=[9,8,1,2,3,4,5] n=len(A) print(returnMaxSum(A,B,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( A := Sequence{0}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 4 })))))) ; B := Sequence{9}->union(Sequence{8}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))))) ; n := (A)->size() ; execute (returnMaxSum(A, B, n))->display() ) else skip; operation returnMaxSum(A : OclAny, B : OclAny, n : OclAny) : OclAny pre: true post: true activity: var mp : Set := Set{}->union(()) ; var result : int := 0 ; var curr_sum : OclAny := 0; var curr_begin : int := 0 ; for i : Integer.subrange(0, n-1) do ( while (mp)->includes(A[i+1]) do ( execute ((A[curr_begin+1]) /: mp) ; curr_sum := curr_sum - B[curr_begin+1] ; curr_begin := curr_begin + 1) ; execute ((A[i+1]) : mp) ; curr_sum := curr_sum + B[i+1] ; result := Set{result, curr_sum}->max()) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isDivisible(arr,n,y): d,i=0,0 while iunion(Sequence{2}->union(Sequence{1}->union(Sequence{5}->union(Sequence{ 6 })))) ; var x : int := (arr)->size() ; y := 4 ; if (isDivisible(arr, x, y)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isDivisible(arr : OclAny, n : OclAny, y : OclAny) : OclAny pre: true post: true activity: var d : OclAny := null; var i : OclAny := null; Sequence{d,i} := Sequence{0,0} ; while (i->compareTo(n)) < 0 do ( while (d->compareTo(y)) < 0 & (i->compareTo(n)) < 0 do ( var d : double := d * 10 + arr[i+1] ; i := i + 1) ; d := d mod y) ; if d = 0 then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def seriesFunc(n): sumSquare=(n*(n+1)*(2*n+1))/6 sumNatural=(n*(n+1)/2) return(sumSquare+sumNatural+1) n=8 print(int(seriesFunc(n))) n=13 print(int(seriesFunc(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 8 ; execute (("" + ((seriesFunc(n))))->toInteger())->display() ; n := 13 ; execute (("" + ((seriesFunc(n))))->toInteger())->display(); operation seriesFunc(n : OclAny) : OclAny pre: true post: true activity: var sumSquare : double := (n * (n + 1) * (2 * n + 1)) / 6 ; var sumNatural : double := (n * (n + 1) / 2) ; return (sumSquare + sumNatural + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) print("GREATER" if a>b else "LESS" if atoInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (if (a->compareTo(b)) > 0 then "GREATER" else if (a->compareTo(b)) < 0 then "LESS" else "EQUAL" endif endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Alphabet_N_Pattern(N): Right=1 Left=1 Diagonal=2 for index in range(N): print(Left,end="") Left+=1 for side_index in range(0,2*(index),1): print("",end="") if(index!=0 and index!=N-1): print(Diagonal,end="") Diagonal+=1 else : print("",end="") for side_index in range(0,2*(N-index-1),1): print("",end="") print(Right,end="") Right+=1 print("\n",end="") if __name__=='__main__' : Size=6 Alphabet_N_Pattern(Size) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var Size : int := 6 ; Alphabet_N_Pattern(Size) ) else skip; operation Alphabet_N_Pattern(N : OclAny) pre: true post: true activity: var Right : int := 1 ; var Left : int := 1 ; var Diagonal : int := 2 ; for index : Integer.subrange(0, N-1) do ( execute (Left)->display() ; Left := Left + 1 ; for side_index : Integer.subrange(0, 2 * (index)-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( execute ("")->display()) ; if (index /= 0 & index /= N - 1) then ( execute (Diagonal)->display() ; Diagonal := Diagonal + 1 ) else ( execute ("")->display() ) ; for side_index : Integer.subrange(0, 2 * (N - index - 1)-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( execute ("")->display()) ; execute (Right)->display() ; Right := Right + 1 ; execute ("\n")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=100005 lazy=[0]*(4*N); se=set() def update(x,y,value,id,l,r): if(x>=r or l>=y): return ; if(x<=l and r<=y): lazy[id]=value ; return ; mid=(l+r)//2 ; if(lazy[id]): lazy[2*id]=lazy[2*id+1]=lazy[id]; lazy[id]=0 ; update(x,y,value,2*id,l,mid); update(x,y,value,2*id+1,mid,r); def query(id,l,r): if(lazy[id]): se.add(lazy[id]); return ; if(r-l<2): return ; mid=(l+r)//2 ; query(2*id,l,mid); query(2*id+1,mid,r); if __name__=="__main__" : n=5 ; q=3 ; update(1,4,1,1,0,n); update(0,2,2,1,0,n); update(3,4,3,1,0,n); query(1,0,n); print(len(se)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 100005 ; var lazy : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (4 * N)); ; var se : Set := Set{}->union(()) ; skip ; skip ; if __name__ = "__main__" then ( var n : int := 5; var q : int := 3; ; update(1, 4, 1, 1, 0, n); ; update(0, 2, 2, 1, 0, n); ; update(3, 4, 3, 1, 0, n); ; query(1, 0, n); ; execute ((se)->size())->display(); ) else skip; operation update(x : OclAny, y : OclAny, value : OclAny, id : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: if ((x->compareTo(r)) >= 0 or (l->compareTo(y)) >= 0) then ( return; ) else skip ; if ((x->compareTo(l)) <= 0 & (r->compareTo(y)) <= 0) then ( lazy[id+1] := value; ; return; ) else skip ; var mid : int := (l + r) div 2; ; if (lazy[id+1]) then ( lazy[2 * id+1] := lazy[id+1]; var lazy[2 * id + 1+1] : OclAny := lazy[id+1]; ) else skip ; lazy[id+1] := 0; ; update(x, y, value, 2 * id, l, mid); ; update(x, y, value, 2 * id + 1, mid, r);; operation query(id : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: if (lazy[id+1]) then ( execute ((lazy[id+1]) : se); ; return; ) else skip ; if (r - l < 2) then ( return; ) else skip ; mid := (l + r) div 2; ; query(2 * id, l, mid); ; query(2 * id + 1, mid, r);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for _ in range(int(input())): n=int(input()) if(n/2)**0.5==int((n/2)**0.5)or(n/4)**0.5==int((n/4)**0.5): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if ((n / 2))->pow(0.5) = ("" + ((((n / 2))->pow(0.5))))->toInteger() or ((n / 4))->pow(0.5) = ("" + ((((n / 4))->pow(0.5))))->toInteger() then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): k=0 while b!=0 : r=a % b a,b=b,r k+=1 return[a,k] while True : x,y=list(map(int,input().split())) if x==0 : break if xcollect( _x | (OclType["int"])->apply(_x) )) ; if x = 0 then ( break ) else skip ; if (x->compareTo(y)) < 0 then ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{y,x} ) else skip ; var ans : OclAny := gcd(x, y) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var k : int := 0 ; while b /= 0 do ( var r : int := a mod b ; Sequence{a,b} := Sequence{b,r} ; k := k + 1) ; return Sequence{a}->union(Sequence{ k }); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,m=map(int,input().split()) if n==0 and m==0 : break else : if n>=m : x,y=n,m else : x,y=m,n s=0 while True : if y!=0 : x=x % y x,y=y,x s+=1 else : break print(x,s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 & m = 0 then ( break ) else ( if (n->compareTo(m)) >= 0 then ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{n,m} ) else ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{m,n} ) ; var s : int := 0 ; while true do ( if y /= 0 then ( var x : int := x mod y ; var y : OclAny := null; Sequence{x,y} := Sequence{y,x} ; s := s + 1 ) else ( break )) ) ; execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def f(d,x,y): t=x % y x=y y=t if y!=0 : return f(d+1,x,y) else : return(x,d+1) while 1 : y,x=sorted(list(map(int,input().split()))) if x==0 : break ans=f(0,x,y) print(ans[0],ans[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while 1 do ( Sequence{y,x} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; if x = 0 then ( break ) else skip ; var ans : String := f(0, x, y) ; execute (ans->first())->display()); operation f(d : OclAny, x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var t : int := x mod y ; x := y ; y := t ; if y /= 0 then ( return f(d + 1, x, y) ) else ( return Sequence{x, d + 1} ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : x,y=map(int,input().split()) if x==0 and y==0 : break num=0 while True : num+=1 if x==0 : print(y,num-1) break elif y==0 : print(x,num-1) break elif x>=y : x=x % y elif xcollect( _x | (OclType["int"])->apply(_x) ) ; if x = 0 & y = 0 then ( break ) else skip ; var num : int := 0 ; while true do ( num := num + 1 ; if x = 0 then ( execute (y)->display() ; break ) else (if y = 0 then ( execute (x)->display() ; break ) else (if (x->compareTo(y)) >= 0 then ( var x : int := x mod y ) else (if (x->compareTo(y)) < 0 then ( var y : int := y mod x ) else skip ) ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : m=list(map(int,input().split())) if m[0]==0 and m[1]==0 : break except EOFError : break m.sort(reverse=True) x=m[0] y=m[1] a=0 while y!=0 : a+=1 x=x % y x,y=y,x print(x,a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var m : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if m->first() = 0 & m[1+1] = 0 then ( break ) else skip) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))) ; m := m->sort() ; var x : OclAny := m->first() ; var y : OclAny := m[1+1] ; var a : int := 0 ; while y /= 0 do ( a := a + 1 ; x := x mod y ; Sequence{x,y} := Sequence{y,x}) ; execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a1,a2=int(input()),input(),input() x,y=0,0 k1,k2=len(a1),len(a2) for i in range(k1*k2): if i>=n : break c1,c2=a1[i % k1],a2[i % k2] if c1==c2 : continue elif c1=="R" and c2=="S" or c1=="P" and c2=="R" or c1=='S' and c2=="P" : x+=(n-i+k1*k2-1)//(k1*k2) else : y+=(n-i+k1*k2-1)//(k1*k2) print(y,x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a1 : OclAny := null; var a2 : OclAny := null; Sequence{n,a1,a2} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine()} ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{0,0} ; var k1 : OclAny := null; var k2 : OclAny := null; Sequence{k1,k2} := Sequence{(a1)->size(),(a2)->size()} ; for i : Integer.subrange(0, k1 * k2-1) do ( if (i->compareTo(n)) >= 0 then ( break ) else skip ; var c1 : OclAny := null; var c2 : OclAny := null; Sequence{c1,c2} := Sequence{a1[i mod k1+1],a2[i mod k2+1]} ; if c1 = c2 then ( continue ) else (if c1 = "R" & c2 = "S" or c1 = "P" & c2 = "R" or c1 = 'S' & c2 = "P" then ( x := x + (n - i + k1 * k2 - 1) div (k1 * k2) ) else ( y := y + (n - i + k1 * k2 - 1) div (k1 * k2) ) ) ) ; execute (y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def co(x,y,s): if x==y : return 0 z=(x=="P" and y=="R")or(x=="S" and y=="P")or(x=="R" and y=="S") if s : return int(z) return int(not z) from math import gcd as gh a=int(input()); b=input(); c=input() b1=len(b); c1=len(c) z=((b1*c1)//gh(b1,c1)) w=[0]*(z+1); w1=[0]*(z+1) for i in range(1,z+1): w[i]=co(b[(i-1)% b1],c[(i-1)% c1],0)+w[i-1] w1[i]=co(b[(i-1)% b1],c[(i-1)% c1],1)+w1[i-1] print(w[-1]*(a//z)+w[a % z],w1[-1]*(a//z)+w1[a % z]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var b : String := (OclFile["System.in"]).readLine(); var c : String := (OclFile["System.in"]).readLine() ; var b1 : int := (b)->size(); var c1 : int := (c)->size() ; z := ((b1 * c1) div gh(b1, c1)) ; var w : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (z + 1)); var w1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (z + 1)) ; for i : Integer.subrange(1, z + 1-1) do ( w[i+1] := co(b[(i - 1) mod b1+1], c[(i - 1) mod c1+1], 0) + w[i - 1+1] ; w1[i+1] := co(b[(i - 1) mod b1+1], c[(i - 1) mod c1+1], 1) + w1[i - 1+1]) ; execute (w->last() * (a div z) + w[a mod z+1])->display(); operation co(x : OclAny, y : OclAny, s : OclAny) : OclAny pre: true post: true activity: if x = y then ( return 0 ) else skip ; var z : boolean := (x = "P" & y = "R") or (x = "S" & y = "P") or (x = "R" & y = "S") ; if s then ( return ("" + ((z)))->toInteger() ) else skip ; return ("" + ((not(z))))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=input() la=len(a) lb=len(b) def B(): if la>lb : return "GREATER" elif labi : return "GREATER" elif aisize() ; var lb : int := (b)->size() ; skip ; execute (B())->display(); operation B() : OclAny pre: true post: true activity: if (la->compareTo(lb)) > 0 then ( return "GREATER" ) else (if (la->compareTo(lb)) < 0 then ( return "LESS" ) else ( for i : Integer.subrange(0, la-1) do ( var ai : int := ("" + ((a[i+1])))->toInteger() ; var bi : int := ("" + ((b[i+1])))->toInteger() ; if (ai->compareTo(bi)) > 0 then ( return "GREATER" ) else (if (ai->compareTo(bi)) < 0 then ( return "LESS" ) else skip)) ; return "EQUAL" ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) s1=input() s2=input() s1=list(s1) s2=list(s2) lcm=(len(s1)*len(s2))//(math.gcd(len(s1),len(s2))) l2=n % lcm c1=0 c2=0 c3=0 c4=0 for i in range(1,lcm+1): if s1[(i % len(s1))-1]!=s2[(i % len(s2))-1]: p=s1[(i % len(s1))-1] q=s2[(i % len(s2))-1] if p=='R' and q=='S' : c1+=1 elif p=='S' and q=='P' : c1+=1 elif p=='P' and q=='R' : c1+=1 else : c2+=1 if i==l2 : c3=c1 c4=c2 if ntoInteger() ; var s1 : String := (OclFile["System.in"]).readLine() ; var s2 : String := (OclFile["System.in"]).readLine() ; s1 := (s1)->characters() ; s2 := (s2)->characters() ; var lcm : int := ((s1)->size() * (s2)->size()) div (((s1)->size())->gcd((s2)->size())) ; var l2 : int := n mod lcm ; var c1 : int := 0 ; var c2 : int := 0 ; var c3 : int := 0 ; var c4 : int := 0 ; for i : Integer.subrange(1, lcm + 1-1) do ( if s1[(i mod (s1)->size()) - 1+1] /= s2[(i mod (s2)->size()) - 1+1] then ( var p : OclAny := s1[(i mod (s1)->size()) - 1+1] ; var q : OclAny := s2[(i mod (s2)->size()) - 1+1] ; if p = 'R' & q = 'S' then ( c1 := c1 + 1 ) else (if p = 'S' & q = 'P' then ( c1 := c1 + 1 ) else (if p = 'P' & q = 'R' then ( c1 := c1 + 1 ) else ( c2 := c2 + 1 ) ) ) ) else skip ; if i = l2 then ( c3 := c1 ; c4 := c2 ) else skip) ; if (n->compareTo(lcm)) < 0 then ( execute (c4)->display() ) else ( execute (c4 + c2 * (n div lcm))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a1,a2=int(input()),input(),input() x,y=0,0 k1,k2=len(a1),len(a2) for i in range(k1*k2): if i>=n : break c1,c2=a1[i % k1],a2[i % k2] if c1==c2 : continue elif c1=="R" and c2=="S" or c1=="P" and c2=="R" or c1=='S' and c2=="P" : x+=(n-i+k1*k2-1)//(k1*k2) else : y+=(n-i+k1*k2-1)//(k1*k2) print(y,x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a1 : OclAny := null; var a2 : OclAny := null; Sequence{n,a1,a2} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine()} ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{0,0} ; var k1 : OclAny := null; var k2 : OclAny := null; Sequence{k1,k2} := Sequence{(a1)->size(),(a2)->size()} ; for i : Integer.subrange(0, k1 * k2-1) do ( if (i->compareTo(n)) >= 0 then ( break ) else skip ; var c1 : OclAny := null; var c2 : OclAny := null; Sequence{c1,c2} := Sequence{a1[i mod k1+1],a2[i mod k2+1]} ; if c1 = c2 then ( continue ) else (if c1 = "R" & c2 = "S" or c1 = "P" & c2 = "R" or c1 = 'S' & c2 = "P" then ( x := x + (n - i + k1 * k2 - 1) div (k1 * k2) ) else ( y := y + (n - i + k1 * k2 - 1) div (k1 * k2) ) ) ) ; execute (y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(b==0): return a else : return gcd(b,a % b) def lcm(a,b): return(a*b)//gcd(a,b) n_loser,p_loser=0,0 n=int(input()) player_n=input() player_p=input() a=set(player_n) b=set(player_p) x=len(a) y=len(b) if(a==b and x==y and player_p[: x]==player_n[: y]): print(0,0) else : temp=0 x_n=len(player_n) x_p=len(player_p) lcm_=lcm(x_n,x_p) i=0 player_n=((lcm_//x_n)*player_n)[: n] player_p=((lcm_//x_p)*player_p)[: n] for q in range(0,n): if player_n[i]=="P" and player_p[i]=="S" : n_loser+=1 elif player_n[i]=="P" and player_p[i]=="R" : p_loser+=1 elif player_n[i]=="R" and player_p[i]=="P" : n_loser+=1 elif player_n[i]=="R" and player_p[i]=="S" : p_loser+=1 elif player_n[i]=="S" and player_p[i]=="P" : p_loser+=1 elif player_n[i]=="S" and player_p[i]=="R" : n_loser+=1 i+=1 if(i==lcm_ and temp==0): i=0 temp=1 n_loser=n_loser*(n//lcm_) p_loser=p_loser*(n//lcm_) if(n % lcm_==0): break elif(i==(n-(lcm_*(n//lcm_)))and temp==1): break print(n_loser,p_loser) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n_loser : OclAny := null; var p_loser : OclAny := null; Sequence{n_loser,p_loser} := Sequence{0,0} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var player_n : String := (OclFile["System.in"]).readLine() ; var player_p : String := (OclFile["System.in"]).readLine() ; a := Set{}->union((player_n)) ; b := Set{}->union((player_p)) ; var x : int := (a)->size() ; var y : int := (b)->size() ; if (a = b & x = y & player_p.subrange(1,x) = player_n.subrange(1,y)) then ( execute (0)->display() ) else ( var temp : int := 0 ; var x_n : int := (player_n)->size() ; var x_p : int := (player_p)->size() ; var lcm_ : OclAny := lcm(x_n, x_p) ; var i : int := 0 ; player_n := ((lcm_ div x_n) * player_n).subrange(1,n) ; player_p := ((lcm_ div x_p) * player_p).subrange(1,n) ; for q : Integer.subrange(0, n-1) do ( if player_n[i+1] = "P" & player_p[i+1] = "S" then ( n_loser := n_loser + 1 ) else (if player_n[i+1] = "P" & player_p[i+1] = "R" then ( p_loser := p_loser + 1 ) else (if player_n[i+1] = "R" & player_p[i+1] = "P" then ( n_loser := n_loser + 1 ) else (if player_n[i+1] = "R" & player_p[i+1] = "S" then ( p_loser := p_loser + 1 ) else (if player_n[i+1] = "S" & player_p[i+1] = "P" then ( p_loser := p_loser + 1 ) else (if player_n[i+1] = "S" & player_p[i+1] = "R" then ( n_loser := n_loser + 1 ) else skip ) ) ) ) ) ; i := i + 1 ; if (i = lcm_ & temp = 0) then ( i := 0 ; temp := 1 ; var n_loser : double := n_loser * (n div lcm_) ; var p_loser : double := p_loser * (n div lcm_) ; if (n mod lcm_ = 0) then ( break ) else skip ) else (if (i = (n - (lcm_ * (n div lcm_))) & temp = 1) then ( break ) else skip)) ; execute (n_loser)->display() ); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (b = 0) then ( return a ) else ( return gcd(b, a mod b) ); operation lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a * b) div gcd(a, b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) def solve(n): a=n//2 b=n//4 check_a=int(a**(1/2)) check_b=int(b**(1/2)) if check_a*check_a==a : print("YES") return 0 if check_b*check_b==b and n % 4==0 : print("YES") return 0 print("NO") return 0 for _ in range(t): n=int(input()) if n % 2!=0 : print("NO") else : solve(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; for _anon : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 /= 0 then ( execute ("NO")->display() ) else ( solve(n) )); operation solve(n : OclAny) : OclAny pre: true post: true activity: var a : int := n div 2 ; var b : int := n div 4 ; var check_a : int := ("" + (((a)->pow((1 / 2)))))->toInteger() ; var check_b : int := ("" + (((b)->pow((1 / 2)))))->toInteger() ; if check_a * check_a = a then ( execute ("YES")->display() ; return 0 ) else skip ; if check_b * check_b = b & n mod 4 = 0 then ( execute ("YES")->display() ; return 0 ) else skip ; execute ("NO")->display() ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) sc=[list(map(int,input().split()))for _ in range(M)] sc.sort(key=lambda x : x[0]) ans=0 for i in range(M): s1,c1=sc[i] if s1>N : ans=-1 break for j in range(i+1,M): s2,c2=sc[j] if s1==s2 and c1!=c2 : ans=-1 break if M>0 and N>1 and sc[0][0]==1 and sc[0][1]==0 : ans=-1 if ans!=-1 : ans_={1 : 1,2 : 0,3 : 0} for i in range(M): s,c=sc[i] ans_[s]=c for i in range(1,N+1): ans=ans*10+ans_[i] if N==1 and M==0 : ans=0 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sc : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; sc := sc->sort() ; var ans : int := 0 ; for i : Integer.subrange(0, M-1) do ( var s1 : OclAny := null; var c1 : OclAny := null; Sequence{s1,c1} := sc[i+1] ; if (s1->compareTo(N)) > 0 then ( ans := -1 ; break ) else skip ; for j : Integer.subrange(i + 1, M-1) do ( var s2 : OclAny := null; var c2 : OclAny := null; Sequence{s2,c2} := sc[j+1] ; if s1 = s2 & c1 /= c2 then ( ans := -1 ; break ) else skip)) ; if M > 0 & N > 1 & sc->first()->first() = 1 & sc->first()[1+1] = 0 then ( ans := -1 ) else skip ; if ans /= -1 then ( var ans_ : Map := Map{ 1 |-> 1 }->union(Map{ 2 |-> 0 }->union(Map{ 3 |-> 0 })) ; for i : Integer.subrange(0, M-1) do ( var s : OclAny := null; var c : OclAny := null; Sequence{s,c} := sc[i+1] ; ans_[s+1] := c) ; for i : Integer.subrange(1, N + 1-1) do ( ans := ans * 10 + ans_[i+1]) ) else skip ; if N = 1 & M = 0 then ( ans := 0 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N,M=[int(i)for i in input().split()] S=[] for i in range(M): S.append([int(i)for i in input().split()]) S.sort(reverse=True) answer="0"*N if N!=1 and[1,0]in S : print(-1) return for s in S : if answer[int(s[0])-1]=="0" : answer=answer[: int(s[0])-1]+str(s[1])+answer[int(s[0]):] elif answer[int(s[0])-1]!=str(s[1]): print(-1) return else : continue if answer[0]=="0" and len(answer)!=1 : print("1"+answer[1 :]) else : print(answer) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var S : Sequence := Sequence{} ; for i : Integer.subrange(0, M-1) do ( execute ((input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))) : S)) ; S := S->sort() ; var answer : String := StringLib.nCopies("0", N) ; if N /= 1 & (S)->includes(Sequence{1}->union(Sequence{ 0 })) then ( execute (-1)->display() ; return ) else skip ; for s : S do ( if answer[("" + ((s->first())))->toInteger() - 1+1] = "0" then ( answer := answer.subrange(1,("" + ((s->first())))->toInteger() - 1) + ("" + ((s[1+1]))) + answer.subrange(("" + ((s->first())))->toInteger()+1) ) else (if answer[("" + ((s->first())))->toInteger() - 1+1] /= ("" + ((s[1+1]))) then ( execute (-1)->display() ; return ) else ( continue ) ) ) ; if answer->first() = "0" & (answer)->size() /= 1 then ( execute ("1" + answer->tail())->display() ) else ( execute (answer)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) if M==0 : if N==1 : print(0) else : print("1"+"0"*(N-1)) exit() dic={} for _ in range(M): s,c=map(int,input().split()) if s==1 and c==0 and N!=1 : print(-1) exit() n=dic.get(s) if n is not None and n!=c : print(-1) exit() dic[s]=c lst=[0]*N for k,v in dic.items(): lst[k-1]=v if len(lst)!=1 and lst[0]==0 : lst[0]=1 print("".join(map(str,lst))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if M = 0 then ( if N = 1 then ( execute (0)->display() ) else ( execute ("1" + StringLib.nCopies("0", (N - 1)))->display() ) ; exit() ) else skip ; var dic : OclAny := Set{} ; for _anon : Integer.subrange(0, M-1) do ( var s : OclAny := null; var c : OclAny := null; Sequence{s,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if s = 1 & c = 0 & N /= 1 then ( execute (-1)->display() ; exit() ) else skip ; var n : OclAny := dic.get(s) ; if not(n <>= null) & n /= c then ( execute (-1)->display() ; exit() ) else skip ; dic[s+1] := c) ; var lst : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for _tuple : dic->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); lst[k - 1+1] := v) ; if (lst)->size() /= 1 & lst->first() = 0 then ( lst->first() := 1 ) else skip ; execute (StringLib.sumStringsWithSeparator(((lst)->collect( _x | (OclType["String"])->apply(_x) )), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(i)for i in input().split()] keta=[-1 for i in range(n)] flg=True for i in range(m): s,c=[int(j)for j in input().split()] if keta[s-1]!=-1 and keta[s-1]!=c : flg=False keta[s-1]=c if flg : if keta[0]==-1 and n>1 : keta[0]=1 if keta[0]==0 and n>1 : print(-1) else : for i in range(n): if keta[i]==-1 : keta[i]=0 print(*keta,sep="") else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var keta : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (-1)) ; var flg : boolean := true ; for i : Integer.subrange(0, m-1) do ( var s : OclAny := null; var c : OclAny := null; Sequence{s,c} := input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; if keta[s - 1+1] /= -1 & keta[s - 1+1] /= c then ( flg := false ) else skip ; keta[s - 1+1] := c) ; if flg then ( if keta->first() = -1 & n > 1 then ( keta->first() := 1 ) else skip ; if keta->first() = 0 & n > 1 then ( execute (-1)->display() ) else ( for i : Integer.subrange(0, n-1) do ( if keta[i+1] = -1 then ( keta[i+1] := 0 ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name keta))))))))->display() ) ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) slist=[] clist=[] def check(numlist,slist,clist): for i in range(m): if int(numlist[slist[i]])!=clist[i]: return False return True for i in range(m): s,c=map(int,input().split()) slist.append(s-1) clist.append(c) start=10**(n-1) end=10**n if n==1 : start=0 flag=0 for num in range(start,end): numstring=str(num) numlist=list(numstring) if check(numlist,slist,clist): print(num) flag=1 break if not flag : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var slist : Sequence := Sequence{} ; var clist : Sequence := Sequence{} ; skip ; for i : Integer.subrange(0, m-1) do ( var s : OclAny := null; var c : OclAny := null; Sequence{s,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((s - 1) : slist) ; execute ((c) : clist)) ; var start : double := (10)->pow((n - 1)) ; var end : double := (10)->pow(n) ; if n = 1 then ( start := 0 ) else skip ; var flag : int := 0 ; for num : Integer.subrange(start, end-1) do ( var numstring : String := ("" + ((num))) ; numlist := (numstring)->characters() ; if check(numlist, slist, clist) then ( execute (num)->display() ; flag := 1 ; break ) else skip) ; if not(flag) then ( execute (-1)->display() ) else skip; operation check(numlist : OclAny, slist : OclAny, clist : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, m-1) do ( if ("" + ((numlist[slist[i+1]+1])))->toInteger() /= clist[i+1] then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() ans=s[0] count=0 for i in s : if i==ans : count+=1 if count==3 : print("Yes") break else : count=1 ans=i if count<=2 : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var ans : OclAny := s->first() ; var count : int := 0 ; for i : s->characters() do ( if i = ans then ( count := count + 1 ; if count = 3 then ( execute ("Yes")->display() ; break ) else skip ) else ( count := 1 ) ; ans := i) ; if count <= 2 then ( execute ("No")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A=int(input()) B=int(input()) if A>B : print('GREATER') elif A==B : print('EQUAL') else : print('LESS') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (A->compareTo(B)) > 0 then ( execute ('GREATER')->display() ) else (if A = B then ( execute ('EQUAL')->display() ) else ( execute ('LESS')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import itertools read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines N=readline().decode('utf8') print('Yes' if N[1]==N[2]and(N[0]==N[1]or N[2]==N[3])else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; var N : OclAny := readline().decode('utf8') ; execute (if N[1+1] = N[2+1] & (N->first() = N[1+1] or N[2+1] = N[3+1]) then 'Yes' else 'No' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=list(input()); print("NYoe s"[b==c and(a==b or c==d): : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := ((OclFile["System.in"]).readLine())->characters(); execute ("NYoe s"(subscript (test (logical_test (logical_test (comparison (comparison (expr (atom (name b)))) == (comparison (expr (atom (name c)))))) and (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom (name a)))) == (comparison (expr (atom (name b)))))) or (logical_test (comparison (comparison (expr (atom (name c)))) == (comparison (expr (atom (name d))))))))) ))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from statistics import* from collections import* from operator import itemgetter stdin=sys.stdin ni=lambda : int(ns()) na=lambda : list(map(int,stdin.readline().split())) ns=lambda : stdin.readline() n=input() ct=1 l=n[0] r=n[-1] print("Yes" if n[: 3].count(l)==3 or n[1 :].count(r)==3 else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var stdin : OclFile := OclFile["System.in"] ; var ni : Function := lambda $$ : OclAny in (("" + ((ns())))->toInteger()) ; var na : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ns : Function := lambda $$ : OclAny in (stdin.readLine()) ; var n : String := (OclFile["System.in"]).readLine() ; var ct : int := 1 ; var l : OclAny := n->first() ; var r : OclAny := n->last() ; execute (if n.subrange(1,3)->count(l) = 3 or n->tail()->count(r) = 3 then "Yes" else 'No' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() def check(n): if n[0]==n[1]: if n[1]==n[2]: return "Yes" else : return "No" else : if n[1]==n[2]: if n[2]==n[3]: return "Yes" else : return "No" else : return "No" print(check(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; skip ; execute (check(a))->display(); operation check(n : OclAny) : OclAny pre: true post: true activity: if n->first() = n[1+1] then ( if n[1+1] = n[2+1] then ( return "Yes" ) else ( return "No" ) ) else ( if n[1+1] = n[2+1] then ( if n[2+1] = n[3+1] then ( return "Yes" ) else ( return "No" ) ) else ( return "No" ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: n=int(s); f=0 while n & 1 ^ 1 : n>>=1 ; f=1 print('YNEOS'[f*int(n**.5)**2tail() do ( var n : int := ("" + ((s)))->toInteger(); var f : int := 0 ; while MathLib.bitwiseXor(MathLib.bitwiseAnd(n, 1), 1) do ( n := n div (2->pow(1)); f := 1) ; execute ('YNEOS'(subscript (test (logical_test (comparison (comparison (expr (expr (atom (name f))) * (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) ** (expr (atom (number .5))))))))) )))) ** (expr (atom (number (integer 2))))))) < (comparison (expr (atom (name n))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def complement(number): for i in range(0,len(number)): if(number[i]!='.'): a=9-int(number[i]) number=(number[: i]+str(a)+number[i+1 :]) print("9's complement is : ",number) if __name__=='__main__' : number="345.45" complement(number) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( number := "345.45" ; complement(number) ) else skip; operation complement(number : OclAny) pre: true post: true activity: for i : Integer.subrange(0, (number)->size()-1) do ( if (number[i+1] /= '.') then ( var a : double := 9 - ("" + ((number[i+1])))->toInteger() ; number := (number.subrange(1,i) + ("" + ((a))) + number.subrange(i + 1+1)) ) else skip) ; execute ("9's complement is : ")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) points=["0"]*n for i in range(n//2+1,n): points[i]=str(m) print(" ".join(points)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var points : Sequence := MatrixLib.elementwiseMult(Sequence{ "0" }, n) ; for i : Integer.subrange(n div 2 + 1, n-1) do ( points[i+1] := ("" + ((m)))) ; execute (StringLib.sumStringsWithSeparator((points), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (n,m)=[int(a)for a in input().split()] for i in range(n): if i : print("",end="") if i<=n/2 : print("0",end="") else : print("{}".format(m),end="") print("") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{n, m} : Sequence := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; for i : Integer.subrange(0, n-1) do ( if i then ( execute ("")->display() ) else skip ; if (i->compareTo(n / 2)) <= 0 then ( execute ("0")->display() ) else ( execute (StringLib.interpolateStrings("{}", Sequence{m}))->display() )) ; execute ("")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()); p=n//2+1 ; print(*[0]*p+[m]*(n-p)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var p : int := n div 2 + 1; execute ((argument * (test (logical_test (comparison (expr (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr (atom (name p)))) + (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name m))))))) ])) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (name p)))))))) ))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) if n % 2 : print(*[0]*(n//2)+[m]*(n//2+1)) else : print(*[0]*(n//2-1)+[m]*(n//2+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n mod 2 then ( execute ((argument * (test (logical_test (comparison (expr (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name n))) // (expr (atom (number (integer 2))))))))) )))) + (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name m))))))) ])) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name n))) // (expr (atom (number (integer 2))))) + (expr (atom (number (integer 1))))))))) ))))))))))->display() ) else ( execute ((argument * (test (logical_test (comparison (expr (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name n))) // (expr (atom (number (integer 2))))) - (expr (atom (number (integer 1))))))))) )))) + (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name m))))))) ])) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name n))) // (expr (atom (number (integer 2))))) + (expr (atom (number (integer 1))))))))) ))))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) if a>b : print("GREATER") if atoInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (a->compareTo(b)) > 0 then ( execute ("GREATER")->display() ) else skip ; if (a->compareTo(b)) < 0 then ( execute ("LESS")->display() ) else skip ; if a = b then ( execute ("EQUAL")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isprime(x): i=2 while(i*i<=x): if(x % i==0): return 0 return 1 def isSumOfKprimes(N,K): if(N<2*K): return 0 if(K==1): return isprime(N) if(K==2): if(N % 2==0): return 1 return isprime(N-2); return 1 n=10 k=2 if(isSumOfKprimes(n,k)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := 10 ; var k : int := 2 ; if (isSumOfKprimes(n, k)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isprime(x : OclAny) : OclAny pre: true post: true activity: var i : int := 2 ; while ((i * i->compareTo(x)) <= 0) do ( if (x mod i = 0) then ( return 0 ) else skip) ; return 1; operation isSumOfKprimes(N : OclAny, K : OclAny) : OclAny pre: true post: true activity: if ((N->compareTo(2 * K)) < 0) then ( return 0 ) else skip ; if (K = 1) then ( return isprime(N) ) else skip ; if (K = 2) then ( if (N mod 2 = 0) then ( return 1 ) else skip ; return isprime(N - 2); ) else skip ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def run(): n,l=tuple(int(x)for x in input().split()) G=input().split() B=input().strip() if B in G : return "IMPOSSIBLE" if l==1 : p1="?" p2="0" else : p1="?"*(l-1) p2="10?"+"10"*l return "%s %s" %(p1,p2) tc=int(input()) for i in range(tc): res=run() print("Case #%d: %s" %(i+1,res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var tc : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, tc-1) do ( var res : OclAny := run() ; execute (StringLib.format("Case #%d: %s",Sequence{i + 1, res}))->display()); operation run() : OclAny pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; Sequence{n,l} := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ; var G : OclAny := input().split() ; var B : OclAny := input()->trim() ; if (G)->includes(B) then ( return "IMPOSSIBLE" ) else skip ; if l = 1 then ( var p1 : String := "?" ; var p2 : String := "0" ) else ( p1 := StringLib.nCopies("?", (l - 1)) ; p2 := "10?" + StringLib.nCopies("10", l) ) ; return StringLib.format("%s %s",Sequence{p1, p2}); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def initialize_solver(): pass def solve_testcase(): n,l=read() g=read(rettype=str) b=read(False,str) if b in g : return "IMPOSSIBLE" return["?0"*l,"1"*(l-1)+"0"] output_format="Case #%d: " filename=input().strip() sfile=None tfile=None if filename!="" : sfile=open(filename+".in","r") sfile.seek(0) tfile=open(filename+".out","w") def read(split=True,rettype=int): if sfile : input_line=sfile.readline().strip() else : input_line=input().strip() if split : return list(map(rettype,input_line.split())) else : return rettype(input_line) def write(s="\n"): if s is None : s="" if isinstance(s,list): s="".join(map(str,s)) s=str(s) if tfile : tfile.write(s) else : print(s,end="") if output_format==0 : solve_testcase() else : initialize_solver() total_cases=read(split=False) for case_number in range(1,total_cases+1): write(output_format.replace("%d",str(case_number))) write(solve_testcase()) write("\n") if tfile is not None : tfile.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var output_format : String := "Case #%d: " ; var filename : OclAny := input()->trim() ; var sfile : OclAny := null ; var tfile : OclAny := null ; if filename /= "" then ( sfile := OclFile.newOclFile_Write(OclFile.newOclFile(filename + ".in")) ; sfile.setPosition(0) ; tfile := OclFile.newOclFile_Write(OclFile.newOclFile(filename + ".out")) ) else skip ; skip ; skip ; if output_format = 0 then ( solve_testcase() ) else ( initialize_solver() ; var total_cases : OclAny := read((argument (test (logical_test (comparison (expr (atom (name split)))))) = (test (logical_test (comparison (expr (atom (name False)))))))) ; for case_number : Integer.subrange(1, total_cases + 1-1) do ( write(output_format.replace("%d", ("" + ((case_number))))) ; write(solve_testcase()) ; write("\n")) ) ; if not(tfile <>= null) then ( tfile.closeFile() ) else skip; operation initialize_solver() pre: true post: true activity: skip; operation solve_testcase() : OclAny pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; Sequence{n,l} := read() ; var g : OclAny := read((argument (test (logical_test (comparison (expr (atom (name rettype)))))) = (test (logical_test (comparison (expr (atom (name str)))))))) ; var b : OclAny := read(false, OclType["String"]) ; if (g)->includes(b) then ( return "IMPOSSIBLE" ) else skip ; return Sequence{StringLib.nCopies("?0", l)}->union(Sequence{ StringLib.nCopies("1", (l - 1)) + "0" }); operation read(split : OclAny, rettype : OclAny) : OclAny pre: true post: true activity: if split->oclIsUndefined() then split := true else skip; if rettype->oclIsUndefined() then rettype := OclType["int"] else skip; if sfile then ( var input_line : OclAny := sfile.readLine()->trim() ) else ( input_line := input()->trim() ) ; if split then ( return ((input_line.split())->collect( _x | (rettype)->apply(_x) )) ) else ( return rettype(input_line) ); operation write(s : String) pre: true post: true activity: if s->oclIsUndefined() then s := "\n" else skip; if s <>= null then ( s := "" ) else skip ; if (OclType["Sequence"]).isInstance(s) then ( s := StringLib.sumStringsWithSeparator(((s)->collect( _x | (OclType["String"])->apply(_x) )), "") ) else skip ; s := ("" + ((s))) ; if tfile then ( tfile.write(s) ) else ( execute (s)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for tc in range(1,T+1): N,L=[int(x)for x in input().split()] G=list(input().split()) B=input().strip() if B in G : print('Case #{}: IMPOSSIBLE'.format(tc)) continue if L==1 : print('Case #{}:{}{}'.format(tc,'0','?')) continue print('Case #{}:{}{}'.format(tc,'10'*27+'?'+'10'*27,'?'*(L-1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for tc : Integer.subrange(1, T + 1-1) do ( var N : OclAny := null; var L : OclAny := null; Sequence{N,L} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var G : Sequence := (input().split()) ; var B : OclAny := input()->trim() ; if (G)->includes(B) then ( execute (StringLib.interpolateStrings('Case #{}: IMPOSSIBLE', Sequence{tc}))->display() ; continue ) else skip ; if L = 1 then ( execute (StringLib.interpolateStrings('Case #{}:{}{}', Sequence{tc, '0', '?'}))->display() ; continue ) else skip ; execute (StringLib.interpolateStrings('Case #{}:{}{}', Sequence{tc, StringLib.nCopies('10', 27) + '?' + StringLib.nCopies('10', 27), StringLib.nCopies('?', (L - 1))}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import io,sys import datetime import random fin=None def solve(): n,l=nums() good=strs() bad=sstrip() if '1'*l in good : return 'IMPOSSIBLE' if l==1 : return '0 ?' return '0%s?%s %s' %('10'*l,'1'*(l-1),'?'*(l-1)) def main(): fname='test.in' if len(sys.argv)>1 : fname=sys.argv[1] global fin fin=io.open(fname) fout=io.open(fname+'.out','w') t0=datetime.datetime.now() t=int(fin.readline()) for i in range(t): fout.write('Case #%d: ' %(i+1)) fout.write('%s\n' % str(solve())) print('Time=%s' % str(datetime.datetime.now()-t0)) fin.close() fout.close() def nums(): return[int(x)for x in fin.readline().split()] def fnums(): return[float(x)for x in fin.readline().split()] def num(): return int(fin.readline()) def sstrip(): return fin.readline().strip() def strs(): return fin.readline().split() def arrstr(a,sep=' '): return sep.join([str(x)for x in a]) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute fin : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; var fin : OclAny := null ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve() : OclAny pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; Sequence{n,l} := nums() ; var good : OclAny := strs() ; var bad : OclAny := sstrip() ; if (good)->includes(StringLib.nCopies('1', l)) then ( return 'IMPOSSIBLE' ) else skip ; if l = 1 then ( return '0 ?' ) else skip ; return StringLib.format('0%s?%s %s',Sequence{StringLib.nCopies('10', l), StringLib.nCopies('1', (l - 1)), StringLib.nCopies('?', (l - 1))}); operation main() pre: true post: true activity: var fname : String := 'test.in' ; if ((trailer . (name argv)))->size() > 1 then ( fname := (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) ) else skip ; skip ; fin := io.open(fname) ; var fout : OclAny := io.open(fname + '.out', 'w') ; var t0 : OclAny := datetime.datetime.now() ; var t : int := ("" + ((fin.readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( fout.write(StringLib.format('Case #%d: ',(i + 1))) ; fout.write(StringLib.format('%s ',("" + ((solve())))))) ; execute (StringLib.format('Time=%s',("" + ((datetime.datetime.now() - t0)))))->display() ; fin.closeFile() ; fout.closeFile(); operation nums() : OclAny pre: true post: true activity: return fin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation fnums() : OclAny pre: true post: true activity: return fin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation num() : OclAny pre: true post: true activity: return ("" + ((fin.readLine())))->toInteger(); operation sstrip() : OclAny pre: true post: true activity: return fin.readLine()->trim(); operation strs() : OclAny pre: true post: true activity: return fin.readLine().split(); operation arrstr(a : OclAny, sep : String) : OclAny pre: true post: true activity: if sep->oclIsUndefined() then sep := ' ' else skip; return StringLib.sumStringsWithSeparator((a->select(x | true)->collect(x | (("" + ((x)))))), sep); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) i=1 count=0 while(i<=n): count+=n-i+1 i*=10 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 1 ; var count : int := 0 ; while ((i->compareTo(n)) <= 0) do ( count := count + n - i + 1 ; i := i * 10) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def debug(*args): print(*args,file=sys.stderr) def invert(char): if char=='1' : return '0' elif char=='0' : return '1' else : raise Exception(char) fin=sys.stdin T=int(fin.readline()) for case in range(1,T+1): N,L=map(int,fin.readline().split()) G=fin.readline().split() B=fin.readline().strip() if B in G : result='IMPOSSIBLE' elif L==1 : if B=='0' : result='1 1?' else : result='0 0?' else : a='' b='' for c in B : b+=invert(c)+'?' if c=='1' : a+='01' else : a+='10' a=a[:-2] if len(a)+len(b)>4*L : raise Exception("Too large") result=a+' '+b print("Case #%d: %s" %(case,result)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var fin : OclFile := OclFile["System.in"] ; var T : int := ("" + ((fin.readLine())))->toInteger() ; for case : Integer.subrange(1, T + 1-1) do ( var N : OclAny := null; var L : OclAny := null; Sequence{N,L} := (fin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var G : OclAny := fin.readLine().split() ; var B : OclAny := fin.readLine()->trim() ; if (G)->includes(B) then ( var result : String := 'IMPOSSIBLE' ) else (if L = 1 then ( if B = '0' then ( result := '1 1?' ) else ( result := '0 0?' ) ) else ( var a : String := '' ; var b : String := '' ; for c : B do ( b := b + invert(c) + '?' ; if c = '1' then ( a := a + '01' ) else ( a := a + '10' )) ; a := a->front()->front() ; if ((a)->size() + (b)->size()->compareTo(4 * L)) > 0 then ( error ProgramException.newProgramException("Too large") ) else skip ; result := a + ' ' + b ) ) ; execute (StringLib.format("Case #%d: %s",Sequence{case, result}))->display()); operation debug(args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) execute ((argument * (test (logical_test (comparison (expr (atom (name args))))))))->display(); operation invert(char : OclAny) : OclAny pre: true post: true activity: if char = '1' then ( return '0' ) else (if char = '0' then ( return '1' ) else ( error ProgramException.newProgramException(char) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check_elements(arr,n,A,B): rangeV=B-A for i in range(0,n): if(abs(arr[i])>=A and abs(arr[i])<=B): z=abs(arr[i])-A if(arr[z]>0): arr[z]=arr[z]*-1 count=0 for i in range(0,rangeV+1): if i>=n : break if(arr[i]>0): return False else : count=count+1 if(count!=(rangeV+1)): return False return True arr=[1,4,5,2,7,8,3] n=len(arr) A=2 B=5 if(check_elements(arr,n,A,B)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{4}->union(Sequence{5}->union(Sequence{2}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 3 })))))) ; n := (arr)->size() ; A := 2 ; B := 5 ; if (check_elements(arr, n, A, B)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation check_elements(arr : OclAny, n : OclAny, A : OclAny, B : OclAny) : OclAny pre: true post: true activity: var rangeV : double := B - A ; for i : Integer.subrange(0, n-1) do ( if (((arr[i+1])->abs()->compareTo(A)) >= 0 & ((arr[i+1])->abs()->compareTo(B)) <= 0) then ( var z : double := (arr[i+1])->abs() - A ; if (arr[z+1] > 0) then ( arr[z+1] := arr[z+1] * -1 ) else skip ) else skip) ; var count : int := 0 ; for i : Integer.subrange(0, rangeV + 1-1) do ( if (i->compareTo(n)) >= 0 then ( break ) else skip ; if (arr[i+1] > 0) then ( return false ) else ( count := count + 1 )) ; if (count /= (rangeV + 1)) then ( return false ) else skip ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def findPowerPrime(fact,p): res=0 while fact : res+=fact//p fact//=p return res def findPowerComposite(fact,n): res=math.inf for i in range(2,int(n**0.5)+1): count=0 if not n % i : count+=1 n=n//i if count : curr_pow=findPowerPrime(fact,i)//count res=min(res,curr_pow) if n>=2 : curr_pow=findPowerPrime(fact,n) res=min(res,curr_pow) return res fact=146 ; n=5 print(findPowerComposite(fact,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; fact := 146; n := 5 ; execute (findPowerComposite(fact, n))->display(); operation findPowerPrime(fact : OclAny, p : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; while fact do ( res := res + fact div p ; fact := fact div p) ; return res; operation findPowerComposite(fact : OclAny, n : OclAny) : OclAny pre: true post: true activity: res := ; for i : Integer.subrange(2, ("" + (((n)->pow(0.5))))->toInteger() + 1-1) do ( var count : int := 0 ; if not(n mod i) then ( count := count + 1 ; n := n div i ) else skip ; if count then ( var curr_pow : int := findPowerPrime(fact, i) div count ; res := Set{res, curr_pow}->min() ) else skip) ; if n >= 2 then ( curr_pow := findPowerPrime(fact, n) ; res := Set{res, curr_pow}->min() ) else skip ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) a=len(set(map(int,input().split()))) if k==1 and a>1 : print(-1) elif k>=a : print(1) else : print(1+(a-2)//(k-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : int := (Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))->size() ; if k = 1 & a > 1 then ( execute (-1)->display() ) else (if (k->compareTo(a)) >= 0 then ( execute (1)->display() ) else ( execute (1 + (a - 2) div (k - 1))->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) print("EQUAL" if a==b else "GREATER" if a>b else "LESS") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (if a = b then "EQUAL" else if (a->compareTo(b)) > 0 then "GREATER" else "LESS" endif endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n,k=map(int,input().split()) lst=list(map(int,input().split())) s=set(lst) l=len(s) if k==1 and l>1 : print(-1) elif k==1 and l==1 : print(1) elif k=l : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Set := Set{}->union((lst)) ; var l : int := (s)->size() ; if k = 1 & l > 1 then ( execute (-1)->display() ) else (if k = 1 & l = 1 then ( execute (1)->display() ) else (if (k->compareTo(l)) < 0 then ( if (l - 1) mod (k - 1) = 0 then ( execute ((l - 1) div (k - 1))->display() ) else ( execute ((l - 1) div (k - 1) + 1)->display() ) ) else (if (k->compareTo(l)) >= 0 then ( execute (1)->display() ) else skip ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math MOD=1000000007 def solve(): pass for _ in range(int(input())): n,k=map(int,input().split()) a=list(map(int,input().split())) c=len(set(a)) if k>=c : print(1) elif k==1 : print(-1) else : print(math.ceil((c-1)/(k-1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var MOD : int := 1000000007 ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := (Set{}->union((a)))->size() ; if (k->compareTo(c)) >= 0 then ( execute (1)->display() ) else (if k = 1 then ( execute (-1)->display() ) else ( execute (((c - 1) / (k - 1))->ceil())->display() ) ) ); operation solve() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- y=lambda : map(int,input().split()) for _ in range(int(input())): n,k=y(); b=len(set(y())) if k<2 : print(1-2*(b>1)) else : print(max(1,-((1-b)//(k-1)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var y : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := y->apply(); var b : int := (Set{}->union((y->apply())))->size() ; if k < 2 then ( execute (1 - 2 * (b > 1))->display() ) else ( execute (Set{1, -((1 - b) div (k - 1))}->max())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printUnique(l,r): for i in range(l,r+1): num=i ; visited=[0,0,0,0,0,0,0,0,0,0]; while(num): if visited[num % 10]==1 : break ; visited[num % 10]=1 ; num=(int)(num/10); if num==0 : print(i,end=" "); l=1 ; r=20 ; printUnique(l,r); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; l := 1; ; r := 20; ; printUnique(l, r);; operation printUnique(l : OclAny, r : OclAny) pre: true post: true activity: for i : Integer.subrange(l, r + 1-1) do ( var num : OclAny := i; ; var visited : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))))))))); ; while (num) do ( if visited[num mod 10+1] = 1 then ( break; ) else skip ; visited[num mod 10+1] := 1; ; num := (OclType["int"])(num / 10);) ; if num = 0 then ( execute (i)->display(); ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printTrib(n): if(n<1): return first=0 second=0 third=1 print(first,"",end="") if(n>1): print(second,"",end="") if(n>2): print(second,"",end="") for i in range(3,n): curr=first+second+third first=second second=third third=curr print(curr,"",end="") n=10 printTrib(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 10 ; printTrib(n); operation printTrib(n : OclAny) pre: true post: true activity: if (n < 1) then ( return ) else skip ; var first : int := 0 ; var second : int := 0 ; var third : int := 1 ; execute (first)->display() ; if (n > 1) then ( execute (second)->display() ) else skip ; if (n > 2) then ( execute (second)->display() ) else skip ; for i : Integer.subrange(3, n-1) do ( var curr : int := first + second + third ; first := second ; second := third ; third := curr ; execute (curr)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd as __gcd def isDivisible(num,x,y): while(num % x==0 or num % y==0): if(num % x==0): num//=x if(num % y==0): num//=y if(num>1): return False return True def isPossible(arr,n,x,y): gcd=arr[0] for i in range(1,n): gcd=__gcd(gcd,arr[i]) for i in range(n): if(isDivisible(arr[i]//gcd,x,y)==False): return False return True arr=[2,4,6,8] n=len(arr) x=2 y=3 if(isPossible(arr,n,x,y)==True): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; arr := Sequence{2}->union(Sequence{4}->union(Sequence{6}->union(Sequence{ 8 }))) ; n := (arr)->size() ; x := 2 ; y := 3 ; if (isPossible(arr, n, x, y) = true) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isDivisible(num : OclAny, x : OclAny, y : OclAny) : OclAny pre: true post: true activity: while (num mod x = 0 or num mod y = 0) do ( if (num mod x = 0) then ( num := num div x ) else skip ; if (num mod y = 0) then ( num := num div y ) else skip) ; if (num > 1) then ( return false ) else skip ; return true; operation isPossible(arr : OclAny, n : OclAny, x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var gcd : OclAny := arr->first() ; for i : Integer.subrange(1, n-1) do ( gcd := __gcd(gcd, arr[i+1])) ; for i : Integer.subrange(0, n-1) do ( if (isDivisible(arr[i+1] div gcd, x, y) = false) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def computeTotient(n): phi=[] for i in range(n+2): phi.append(0) for i in range(1,n+1): phi[i]=i for p in range(2,n+1): if(phi[p]==p): phi[p]=p-1 for i in range(2*p,n+1,p): phi[i]=(phi[i]//p)*(p-1) for i in range(1,n+1): print("Totient of ",i," is ",phi[i]) n=12 computeTotient(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 12 ; computeTotient(n); operation computeTotient(n : OclAny) pre: true post: true activity: var phi : Sequence := Sequence{} ; for i : Integer.subrange(0, n + 2-1) do ( execute ((0) : phi)) ; for i : Integer.subrange(1, n + 1-1) do ( phi[i+1] := i) ; for p : Integer.subrange(2, n + 1-1) do ( if (phi[p+1] = p) then ( phi[p+1] := p - 1 ; for i : Integer.subrange(2 * p, n + 1-1)->select( $x | ($x - 2 * p) mod p = 0 ) do ( phi[i+1] := (phi[i+1] div p) * (p - 1)) ) else skip) ; for i : Integer.subrange(1, n + 1-1) do ( execute ("Totient of ")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() n=len(a) ans=0 ; check=9 for i in range(1,n): ans+=check*i check*=10 if n>1 : ans+=(int(a)-int('9'*(n-1)))*n else : ans=a print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var n : int := (a)->size() ; var ans : int := 0; ; var check : int := 9 ; for i : Integer.subrange(1, n-1) do ( ans := ans + check * i ; check := check * 10) ; if n > 1 then ( ans := ans + (("" + ((a)))->toInteger() - ("" + ((StringLib.nCopies('9', (n - 1)))))->toInteger()) * n ) else ( ans := a ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def power(a,n): if n==0 : return 1 p=power(a,n//2) p=p*p if n & 1 : p=p*a return p def countIntegers(l,r): ans,i=0,1 v=power(2,i) while v<=r : while v<=r : if v>=l : ans+=1 v=v*3 i+=1 v=power(2,i) if l==1 : ans+=1 return ans if __name__=="__main__" : l,r=12,21 print(countIntegers(l,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( Sequence{l,r} := Sequence{12,21} ; execute (countIntegers(l, r))->display() ) else skip; operation power(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( return 1 ) else skip ; var p : OclAny := power(a, n div 2) ; p := p * p ; if MathLib.bitwiseAnd(n, 1) then ( p := p * a ) else skip ; return p; operation countIntegers(l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var ans : OclAny := null; var i : OclAny := null; Sequence{ans,i} := Sequence{0,1} ; var v : OclAny := power(2, i) ; while (v->compareTo(r)) <= 0 do ( while (v->compareTo(r)) <= 0 do ( if (v->compareTo(l)) >= 0 then ( ans := ans + 1 ) else skip ; v := v * 3) ; i := i + 1 ; v := power(2, i)) ; if l = 1 then ( ans := ans + 1 ) else skip ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=3 def maxPathSum(tri): ans=0 ; for i in range(N-2,-1,-1): for j in range(0,N-i): if(j-1>=0): tri[i][j]+=max(tri[i+1][j],tri[i+1][j-1]); else : tri[i][j]+=tri[i+1][j]; ans=max(ans,tri[i][j]); return ans tri=[[1,5,3],[4,8,0],[1,0,0]] print(maxPathSum(tri)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 3 ; skip ; tri := Sequence{Sequence{1}->union(Sequence{5}->union(Sequence{ 3 }))}->union(Sequence{Sequence{4}->union(Sequence{8}->union(Sequence{ 0 }))}->union(Sequence{ Sequence{1}->union(Sequence{0}->union(Sequence{ 0 })) })) ; execute (maxPathSum(tri))->display(); operation maxPathSum(tri : OclAny) : OclAny pre: true post: true activity: var ans : int := 0; ; for i : Integer.subrange(-1 + 1, N - 2)->reverse() do ( for j : Integer.subrange(0, N - i-1) do ( if (j - 1 >= 0) then ( tri[i+1][j+1] := tri[i+1][j+1] + Set{tri[i + 1+1][j+1], tri[i + 1+1][j - 1+1]}->max(); ) else ( tri[i+1][j+1] := tri[i+1][j+1] + tri[i + 1+1][j+1]; ) ; ans := Set{ans, tri[i+1][j+1]}->max();)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculateAreaSum(l,b): size=1 maxSize=min(l,b) totalArea=0 for i in range(1,maxSize+1): totalSquares=((l-size+1)*(b-size+1)) area=(totalSquares*size*size) totalArea+=area size+=1 return totalArea if __name__=="__main__" : l=4 b=3 print(calculateAreaSum(l,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( l := 4 ; b := 3 ; execute (calculateAreaSum(l, b))->display() ) else skip; operation calculateAreaSum(l : OclAny, b : OclAny) : OclAny pre: true post: true activity: var size : int := 1 ; var maxSize : OclAny := Set{l, b}->min() ; var totalArea : int := 0 ; for i : Integer.subrange(1, maxSize + 1-1) do ( var totalSquares : double := ((l - size + 1) * (b - size + 1)) ; var area : double := (totalSquares * size * size) ; totalArea := totalArea + area ; size := size + 1) ; return totalArea; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import heapq def main(): N,M=map(int,input().split()) A=[int(i)for i in input().split()] a=[] for i in A : heapq.heappush(a,-i) for _ in range(M): m=heapq.heappop(a) heapq.heappush(a,-(-m//2)) sum=0 for i in a : sum+=i print(-sum) return if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a : Sequence := Sequence{} ; for i : A do ( heapq.heappush(a, -i)) ; for _anon : Integer.subrange(0, M-1) do ( var m : OclAny := heapq.heappop(a) ; heapq.heappush(a, -(-m div 2))) ; var sum : int := 0 ; for i : a do ( sum := sum + i) ; execute (-sum)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heappop,heappush from math import ceil,floor def p_d(): N,M=map(int,input().split()) A=list(map(int,input().split())) H=[] for a in A : heappush(H,a*-1) for _ in range(M): x=heappop(H) heappush(H,ceil(x/2)) ans=0 for a in H : ans-=a print(ans) if __name__=='__main__' : p_d() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( p_d() ) else skip; operation p_d() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var H : Sequence := Sequence{} ; for a : A do ( heappush(H, a * -1)) ; for _anon : Integer.subrange(0, M-1) do ( var x : OclAny := heappop(H) ; heappush(H, ceil(x / 2))) ; var ans : int := 0 ; for a : H do ( ans := ans - a) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin sys.setrecursionlimit(10**7) def li(): return map(int,stdin.readline().split()) def li_(): return map(lambda x : int(x)-1,stdin.readline().split()) def lf(): return map(float,stdin.readline().split()) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) from heapq import heappush,heappop n,m=li() a=list(li()) heap=[] for ai in a : heappush(heap,-ai) for _ in range(m): cur=-heappop(heap) heappush(heap,-(cur//2)) ans=0 for hi in heap : ans+=-hi print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stdin : OclFile := OclFile["System.in"] ; sys.setrecursionlimit((10)->pow(7)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := li() ; var a : Sequence := (li()) ; var heap : Sequence := Sequence{} ; for ai : a do ( heappush(heap, -ai)) ; for _anon : Integer.subrange(0, m-1) do ( var cur : OclAny := -heappop(heap) ; heappush(heap, -(cur div 2))) ; var ans : int := 0 ; for hi : heap do ( ans := ans + -hi) ; execute (ans)->display(); operation li() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation li_() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ); operation lf() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ); operation ls() : OclAny pre: true post: true activity: return stdin.readLine().split(); operation ns() : OclAny pre: true post: true activity: return stdin.readLine().rstrip(); operation lc() : OclAny pre: true post: true activity: return (ns()); operation ni() : OclAny pre: true post: true activity: return ("" + ((stdin.readLine())))->toInteger(); operation nf() : OclAny pre: true post: true activity: return ("" + ((stdin.readLine())))->toReal(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,m=map(int,input().split()) list1=list(map(int,input().split())) list1.sort() list1.reverse() i=0 s=math.floor(list1[0]/2) if n==1 : print(math.floor(list1[0]/(2**m))) exit() while True : while True : if i+1>n : break if list1[i]collect( _x | (OclType["int"])->apply(_x) ) ; var list1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; list1 := list1->sort() ; list1 := list1->reverse() ; var i : int := 0 ; var s : double := (list1->first() / 2)->floor() ; if n = 1 then ( execute ((list1->first() / ((2)->pow(m)))->floor())->display() ; exit() ) else skip ; while true do ( while true do ( if (i + 1->compareTo(n)) > 0 then ( break ) else skip ; if (list1[i+1]->compareTo(s)) < 0 or m = 0 then ( break ) else skip ; list1[i+1] := (list1[i+1] / 2)->floor() ; m := m - 1 ; i := i + 1) ; if m = 0 then ( break ) else skip ; list1 := list1->sort() ; list1 := list1->reverse() ; s := (list1->first() / 2)->floor() ; i := 0) ; execute ((list1)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from bisect import* from collections import* from copy import deepcopy from heapq import* from itertools import* from math import* from operator import* from pprint import* sys.setrecursionlimit(10**8) input=sys.stdin.readline def main(): N,M=map(int,input().split()) AS=list(map(lambda x :-int(x),input().split())) heapify(AS) for _ in range(M): a=heappop(AS) a=-(-a//2) heappush(AS,a) print(-sum(AS)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var AS : Sequence := ((input().split())->collect( _x | (lambda x : OclAny in (-("" + ((x)))->toInteger()))->apply(_x) )) ; heapify(AS) ; for _anon : Integer.subrange(0, M-1) do ( var a : OclAny := heappop(AS) ; a := -(-a div 2) ; heappush(AS, a)) ; execute (-(AS)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import pow,ceil,floor import random def nthRoot(A,N): xPre=(random.randint(0,9))% 10 eps=1e-3 delX=sys.maxsize while(delX>eps): xK=((N-1.0)*xPre+A/pow(xPre,N-1))/N delX=abs(xK-xPre) xPre=xK return xK def countPowers(a,b,k): return(floor(nthRoot(b,k))-ceil(nthRoot(a,k))+1) if __name__=='__main__' : a=7 b=28 k=2 print("Count of Powers is",countPowers(a,b,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( a := 7 ; b := 28 ; k := 2 ; execute ("Count of Powers is")->display() ) else skip; operation nthRoot(A : OclAny, N : OclAny) : OclAny pre: true post: true activity: var xPre : int := ((0 + (OclRandom.defaultInstanceOclRandom()).nextInt(9 - 0))) mod 10 ; var eps : double := ("1e-3")->toReal() ; var delX : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; while ((delX->compareTo(eps)) > 0) do ( var xK : double := ((N - 1.0) * xPre + A / (xPre)->pow(N - 1)) / N ; delX := (xK - xPre)->abs() ; xPre := xK) ; return xK; operation countPowers(a : OclAny, b : OclAny, k : OclAny) : OclAny pre: true post: true activity: return (floor(nthRoot(b, k)) - ceil(nthRoot(a, k)) + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkSparse(n): if(n &(n>>1)): return 0 return 1 print(checkSparse(72)) print(checkSparse(12)) print(checkSparse(2)) print(checkSparse(30)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (checkSparse(72))->display() ; execute (checkSparse(12))->display() ; execute (checkSparse(2))->display() ; execute (checkSparse(30))->display(); operation checkSparse(n : OclAny) : OclAny pre: true post: true activity: if (MathLib.bitwiseAnd(n, (n /(2->pow(1))))) then ( return 0 ) else skip ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minRadius(k,x,y,n): dis=[0]*n for i in range(0,n): dis[i]=x[i]*x[i]+y[i]*y[i] dis.sort() return dis[k-1] k=3 x=[1,-1,1] y=[1,-1,-1] n=len(x) print(minRadius(k,x,y,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; k := 3 ; x := Sequence{1}->union(Sequence{-1}->union(Sequence{ 1 })) ; y := Sequence{1}->union(Sequence{-1}->union(Sequence{ -1 })) ; n := (x)->size() ; execute (minRadius(k, x, y, n))->display(); operation minRadius(k : OclAny, x : OclAny, y : OclAny, n : OclAny) : OclAny pre: true post: true activity: var dis : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( dis[i+1] := x[i+1] * x[i+1] + y[i+1] * y[i+1]) ; dis := dis->sort() ; return dis[k - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=len(a) d=int(a) c=0 for i in range(1,b): c+=i*9*10**(i-1) c+=(d-10**(b-1)+1)*b print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : int := (a)->size() ; var d : int := ("" + ((a)))->toInteger() ; var c : int := 0 ; for i : Integer.subrange(1, b-1) do ( c := c + i * 9 * (10)->pow((i - 1))) ; c := c + (d - (10)->pow((b - 1)) + 1) * b ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) res=[] for p in range(n//2,-n//2,-1): p=abs(p) res.append("*"*p+"D"*(n-2*p)+"*"*p) res="\n".join(res) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : Sequence := Sequence{} ; for p : Integer.subrange(-n div 2 + 1, n div 2)->reverse() do ( var p : double := (p)->abs() ; execute ((StringLib.nCopies("*", p) + StringLib.nCopies("D", (n - 2 * p)) + StringLib.nCopies("*", p)) : res)) ; res := StringLib.sumStringsWithSeparator((res), "\n") ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def arrange(N): if(N==1): print("1") return if(N==2 or N==3): print("-1") return even=-1 odd=-1 if(N % 2==0): even=N odd=N-1 else : odd=N even=N-1 while(odd>=1): print(odd,end=" ") odd=odd-2 while(even>=2): print(even,end=" ") even=even-2 if __name__=="__main__" : N=5 arrange(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := 5 ; arrange(N) ) else skip; operation arrange(N : OclAny) pre: true post: true activity: if (N = 1) then ( execute ("1")->display() ; return ) else skip ; if (N = 2 or N = 3) then ( execute ("-1")->display() ; return ) else skip ; var even : int := -1 ; var odd : int := -1 ; if (N mod 2 = 0) then ( even := N ; odd := N - 1 ) else ( odd := N ; even := N - 1 ) ; while (odd >= 1) do ( execute (odd)->display() ; odd := odd - 2) ; while (even >= 2) do ( execute (even)->display() ; even := even - 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def print(*args,end='\n',sep=' ')->None : sys.stdout.write(sep.join(map(str,args))+end) def Solve(): n=int(input()) list_=[] x=1 for i in range(1,n//2+1): list_.append("*"*((n-x)//2)+"D"*x+"*"*((n-x)//2)) x+=2 list_.append("D"*n) list_+=list_[:-1][: :-1] print(*list_,sep="\n") if __name__=="__main__" : Solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; if __name__ = "__main__" then ( Solve() ) else skip; (funcdef def name print ( (typedargslist (args * (named_parameter (name args))) , (def_parameters (def_parameter (named_parameter (name end)) = (test (logical_test (comparison (expr (atom ' ')))))) , (def_parameter (named_parameter (name sep)) = (test (logical_test (comparison (expr (atom ' ')))))))) ) -> (test (logical_test (comparison (expr (atom None))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name sep)) (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name args)))))))) ))))))))) )))) + (expr (atom (name end))))))))) )))))))))))))) operation Solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var list_ : Sequence := Sequence{} ; var x : int := 1 ; for i : Integer.subrange(1, n div 2 + 1-1) do ( execute ((StringLib.nCopies("*", ((n - x) div 2)) + StringLib.nCopies("D", x) + StringLib.nCopies("*", ((n - x) div 2))) : list_) ; x := x + 2) ; execute ((StringLib.nCopies("D", n)) : list_) ; list_ := list_ + list_->front()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; execute ((argument * (test (logical_test (comparison (expr (atom (name list_))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math number=int(input()) new_number=math.floor(number/2) counter=new_number while counter!=-1 : string='*'*counter string2='D'*(number-counter*2) print(string+string2+string) counter-=1 counter=1 while counter<=new_number : string='*'*counter string2='D'*(number-counter*2) print(string+string2+string) counter+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var number : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var new_number : double := (number / 2)->floor() ; var counter : OclAny := new_number ; while counter /= -1 do ( var string : String := StringLib.nCopies('*', counter) ; var string2 : String := StringLib.nCopies('D', (number - counter * 2)) ; execute (string + string2 + string)->display() ; counter := counter - 1) ; counter := 1 ; while (counter->compareTo(new_number)) <= 0 do ( string := StringLib.nCopies('*', counter) ; string2 := StringLib.nCopies('D', (number - counter * 2)) ; execute (string + string2 + string)->display() ; counter := counter + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): a=abs(n//2-i) print(a*'*'+((n//2-a)*2+1)*'D'+a*'*') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var a : double := (n div 2 - i)->abs() ; execute (a * '*' + ((n div 2 - a) * 2 + 1) * 'D' + a * '*')->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): a=abs(n//2-i); print(a*'*'+((n//2-a)*2+1)*'D'+a*'*') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var a : double := (n div 2 - i)->abs(); execute (a * '*' + ((n div 2 - a) * 2 + 1) * 'D' + a * '*')->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(): fin=sys.stdin fout=sys.stdout n=int(fin.readline()) s=list(fin.readline()) i=0 while itoInteger() ; var s : Sequence := (fin.readLine())->characters() ; var i : int := 0 ; while (i->compareTo(n)) < 0 & s[i+1] = '1' do ( i := i + 1) ; execute (Set{i + 1, n}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input(); print((input()[:-1]+'0').find("0")+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input(); execute ((input()->front() + '0')->indexOf("0") - 1 + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input().split('0') print(min(len(s[0])+1,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := input().split('0') ; execute (Set{(s->first())->size() + 1, n}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input(); print((input()[:-1]+'0').find("0")+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input(); execute ((input()->front() + '0')->indexOf("0") - 1 + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) cell=input() b=0 place=cell.find("0") if place==(-1): print(n) else : print(place+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cell : String := (OclFile["System.in"]).readLine() ; var b : int := 0 ; var place : int := cell->indexOf("0") - 1 ; if place = (-1) then ( execute (n)->display() ) else ( execute (place + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- books_in_the_library=int(input()) if len(str(books_in_the_library))==1 : print(books_in_the_library) else : digits=9 for i in range(2,len(str(books_in_the_library))): digits+=i*(90*10**(i-2)) digits+=(books_in_the_library-int('1'+'0'*(len(str(books_in_the_library))-1))+1)*len(str(books_in_the_library)) print(digits) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var books_in_the_library : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (("" + ((books_in_the_library))))->size() = 1 then ( execute (books_in_the_library)->display() ) else ( var digits : int := 9 ; for i : Integer.subrange(2, (("" + ((books_in_the_library))))->size()-1) do ( digits := digits + i * (90 * (10)->pow((i - 2)))) ; digits := digits + (books_in_the_library - ("" + (('1' + StringLib.nCopies('0', ((("" + ((books_in_the_library))))->size() - 1)))))->toInteger() + 1) * (("" + ((books_in_the_library))))->size() ; execute (digits)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- par=[0]*202020 size=[0]*202020 def find(x): if par[x]==x : return x else : par[x]=find(par[x]) return par[x] def unite(x,y): x=find(x) y=find(y) res=size[x]*size[y] size[x]+=size[y] par[y]=x return res n=int(input()) for i in range(202020): par[i]=i size[i]=1 a=[0]+list(map(int,input().split())) b=[0]*(n+1) for i in range(1,n+1): b[a[i]]=i ans=0 for j in reversed(range(1,n+1)): i=b[j] ans+=a[i] if i-1>=1 and a[i-1]>a[i]: ans+=unite(i-1,i)*a[i] if i+1<=n and a[i+1]>a[i]: ans+=unite(i+1,i)*a[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var par : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 202020) ; var size : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 202020) ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, 202020-1) do ( par[i+1] := i ; size[i+1] := 1) ; var a : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(1, n + 1-1) do ( b[a[i+1]+1] := i) ; var ans : int := 0 ; for j : (Integer.subrange(1, n + 1-1))->reverse() do ( var i : OclAny := b[j+1] ; ans := ans + a[i+1] ; if i - 1 >= 1 & (a[i - 1+1]->compareTo(a[i+1])) > 0 then ( ans := ans + unite(i - 1, i) * a[i+1] ) else skip ; if (i + 1->compareTo(n)) <= 0 & (a[i + 1+1]->compareTo(a[i+1])) > 0 then ( ans := ans + unite(i + 1, i) * a[i+1] ) else skip) ; execute (ans)->display(); operation find(x : OclAny) : OclAny pre: true post: true activity: if par[x+1] = x then ( return x ) else ( par[x+1] := find(par[x+1]) ; return par[x+1] ); operation unite(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: x := find(x) ; y := find(y) ; var res : double := size[x+1] * size[y+1] ; size[x+1] := size[x+1] + size[y+1] ; par[y+1] := x ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countBits(n): count=0 ; while(n): count+=1 ; n>>=1 ; return count ; n=32 ; print("Minimum value of K is=",countBits(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 32; ; execute ("Minimum value of K is=")->display();; operation countBits(n : OclAny) pre: true post: true activity: var count : int := 0; ; while (n) do ( count := count + 1; ; n := n div (2->pow(1));) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin from collections import namedtuple from math import sqrt input=stdin.readline color=namedtuple('color',['name','r','g','b']) def main(args): references=[color('black',0x00,0x00,0x00),color('blue',0x00,0x00,0xff),color('lime',0x00,0xff,0x00),color('aqua',0x00,0xff,0xff),color('red',0xff,0x00,0x00),color('fuchsia',0xff,0x00,0xff),color('yellow',0xff,0xff,0x00),color('white',0xff,0xff,0xff)] while True : data=input().strip() if data[0]=='0' : break my_r=int(data[1 : 3],16) my_g=int(data[3 : 5],16) my_b=int(data[5 : 7],16) distances=[((c.r-my_r)**2+(c.g-my_g)**2+(c.b-my_b)**2)for c in references] closest_distance=min(distances) closest_color=distances.index(closest_distance) print(references[closest_color].name) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var input : OclAny := stdin.readline ; var color : OclAny := namedtuple('color', Sequence{'name'}->union(Sequence{'r'}->union(Sequence{'g'}->union(Sequence{ 'b' })))) ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation main(args : OclAny) pre: true post: true activity: var references : Sequence := Sequence{color('black', 0x00, 0x00, 0x00)}->union(Sequence{color('blue', 0x00, 0x00, 0xff)}->union(Sequence{color('lime', 0x00, 0xff, 0x00)}->union(Sequence{color('aqua', 0x00, 0xff, 0xff)}->union(Sequence{color('red', 0xff, 0x00, 0x00)}->union(Sequence{color('fuchsia', 0xff, 0x00, 0xff)}->union(Sequence{color('yellow', 0xff, 0xff, 0x00)}->union(Sequence{ color('white', 0xff, 0xff, 0xff) }))))))) ; while true do ( var data : OclAny := input()->trim() ; if data->first() = '0' then ( break ) else skip ; var my_r : int := ("" + ((data.subrange(1+1, 3), 16)))->toInteger() ; var my_g : int := ("" + ((data.subrange(3+1, 5), 16)))->toInteger() ; var my_b : int := ("" + ((data.subrange(5+1, 7), 16)))->toInteger() ; var distances : Sequence := references->select(c | true)->collect(c | ((((c.r - my_r))->pow(2) + ((c.g - my_g))->pow(2) + ((c.b - my_b))->pow(2)))) ; var closest_distance : OclAny := (distances)->min() ; var closest_color : int := distances->indexOf(closest_distance) - 1 ; execute (references[closest_color+1].name)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=10**10 dic={} for i in range(10): dic[str(i)]=i for i in range(ord("a"),ord("f")+1): dic[chr(i)]=i-ord("a")+10 def hex_to_dec(s): return dic[s[0]]*16+dic[s[1]] colors=[("black",list(map(hex_to_dec,["00","00","00"]))),("blue",list(map(hex_to_dec,["00","00","ff"]))),("lime",list(map(hex_to_dec,["00","ff","00"]))),("aqua",list(map(hex_to_dec,["00","ff","ff"]))),("red",list(map(hex_to_dec,["ff","00","00"]))),("fuchsia",list(map(hex_to_dec,["ff","00","ff"]))),("yellow",list(map(hex_to_dec,["ff","ff","00"]))),("white",list(map(hex_to_dec,["ff","ff","ff"])))] while True : s=input() if s=="0" : break r,g,b=map(hex_to_dec,[s[1 : 3],s[3 : 5],s[5 : 7]]) lowest_name="KUWA" lowest_score=INF for name,rgb in colors : rc,gc,bc=rgb score=(r-rc)**2+(g-gc)**2+(b-bc)**2 if scorepow(10) ; var dic : OclAny := Set{} ; for i : Integer.subrange(0, 10-1) do ( dic[("" + ((i)))+1] := i) ; for i : Integer.subrange(("a")->char2byte(), ("f")->char2byte() + 1-1) do ( dic[(i)->byte2char()+1] := i - ("a")->char2byte() + 10) ; skip ; var colors : Sequence := Sequence{Sequence{"black", ((Sequence{"00"}->union(Sequence{"00"}->union(Sequence{ "00" })))->collect( _x | (hex_to_dec)->apply(_x) ))}}->union(Sequence{Sequence{"blue", ((Sequence{"00"}->union(Sequence{"00"}->union(Sequence{ "ff" })))->collect( _x | (hex_to_dec)->apply(_x) ))}}->union(Sequence{Sequence{"lime", ((Sequence{"00"}->union(Sequence{"ff"}->union(Sequence{ "00" })))->collect( _x | (hex_to_dec)->apply(_x) ))}}->union(Sequence{Sequence{"aqua", ((Sequence{"00"}->union(Sequence{"ff"}->union(Sequence{ "ff" })))->collect( _x | (hex_to_dec)->apply(_x) ))}}->union(Sequence{Sequence{"red", ((Sequence{"ff"}->union(Sequence{"00"}->union(Sequence{ "00" })))->collect( _x | (hex_to_dec)->apply(_x) ))}}->union(Sequence{Sequence{"fuchsia", ((Sequence{"ff"}->union(Sequence{"00"}->union(Sequence{ "ff" })))->collect( _x | (hex_to_dec)->apply(_x) ))}}->union(Sequence{Sequence{"yellow", ((Sequence{"ff"}->union(Sequence{"ff"}->union(Sequence{ "00" })))->collect( _x | (hex_to_dec)->apply(_x) ))}}->union(Sequence{ Sequence{"white", ((Sequence{"ff"}->union(Sequence{"ff"}->union(Sequence{ "ff" })))->collect( _x | (hex_to_dec)->apply(_x) ))} }))))))) ; while true do ( s := (OclFile["System.in"]).readLine() ; if s = "0" then ( break ) else skip ; var r : OclAny := null; var g : OclAny := null; var b : OclAny := null; Sequence{r,g,b} := (Sequence{s.subrange(1+1, 3)}->union(Sequence{s.subrange(3+1, 5)}->union(Sequence{ s.subrange(5+1, 7) })))->collect( _x | (hex_to_dec)->apply(_x) ) ; var lowest_name : String := "KUWA" ; var lowest_score : OclAny := INF ; for _tuple : colors do (var _indx : int := 1; var name : OclAny := _tuple->at(_indx); _indx := _indx + 1; var rgb : OclAny := _tuple->at(_indx); var rc : OclAny := null; var gc : OclAny := null; var bc : OclAny := null; Sequence{rc,gc,bc} := rgb ; var score : double := ((r - rc))->pow(2) + ((g - gc))->pow(2) + ((b - bc))->pow(2) ; if (score->compareTo(lowest_score)) < 0 then ( Sequence{lowest_name,lowest_score} := Sequence{name,score} ) else skip) ; execute (lowest_name)->display()); operation hex_to_dec(s : OclAny) : OclAny pre: true post: true activity: return dic[s->first()+1] * 16 + dic[s[1+1]+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def solve(line): R=int(line[1 : 3],16) G=int(line[3 : 5],16) B=int(line[5 : 7],16) sa_black=math.sqrt(R**2+G**2+B**2) sa_max=sa_black ans_color="black" sa_blue=math.sqrt(R**2+G**2+(B-255)**2) if sa_bluedisplay()); operation solve(line : OclAny) : OclAny pre: true post: true activity: var R : int := ("" + ((line.subrange(1+1, 3), 16)))->toInteger() ; var G : int := ("" + ((line.subrange(3+1, 5), 16)))->toInteger() ; var B : int := ("" + ((line.subrange(5+1, 7), 16)))->toInteger() ; var sa_black : double := ((R)->pow(2) + (G)->pow(2) + (B)->pow(2))->sqrt() ; var sa_max : OclAny := sa_black ; var ans_color : String := "black" ; var sa_blue : double := ((R)->pow(2) + (G)->pow(2) + ((B - 255))->pow(2))->sqrt() ; if (sa_blue->compareTo(sa_max)) < 0 then ( sa_max := sa_blue ; ans_color := "blue" ) else skip ; var sa_lime : double := ((R)->pow(2) + ((G - 255))->pow(2) + (B)->pow(2))->sqrt() ; if (sa_lime->compareTo(sa_max)) < 0 then ( sa_max := sa_lime ; ans_color := "lime" ) else skip ; var sa_aqua : double := ((R)->pow(2) + ((G - 255))->pow(2) + ((B - 255))->pow(2))->sqrt() ; if (sa_aqua->compareTo(sa_max)) < 0 then ( sa_max := sa_aqua ; ans_color := "aqua" ) else skip ; var sa_red : double := (((R - 255))->pow(2) + (G)->pow(2) + (B)->pow(2))->sqrt() ; if (sa_red->compareTo(sa_max)) < 0 then ( sa_max := sa_red ; ans_color := "red" ) else skip ; var sa_fuchsia : double := (((R - 255))->pow(2) + (G)->pow(2) + ((B - 255))->pow(2))->sqrt() ; if (sa_fuchsia->compareTo(sa_max)) < 0 then ( sa_max := sa_fuchsia ; ans_color := "fuchsia" ) else skip ; var sa_yellow : double := (((R - 255))->pow(2) + ((G - 255))->pow(2) + (B)->pow(2))->sqrt() ; if (sa_yellow->compareTo(sa_max)) < 0 then ( sa_max := sa_yellow ; ans_color := "yellow" ) else skip ; var sa_white : double := (((R - 255))->pow(2) + ((G - 255))->pow(2) + ((B - 255))->pow(2))->sqrt() ; if (sa_white->compareTo(sa_max)) < 0 then ( sa_max := sa_white ; ans_color := "white" ) else skip ; return ans_color; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math while True : color=[[0,0,0],[0,0,255],[0,255,0],[0,255,255],[255,0,0],[255,0,255],[255,255,0],[255,255,255]] color_16=input() if color_16=="0" : break color_R=int(color_16[1]+color_16[2],16) color_G=int(color_16[3]+color_16[4],16) color_B=int(color_16[5]+color_16[6],16) min_d=500 for i in range(8): R=color[i][0] G=color[i][1] B=color[i][2] d=math.sqrt((R-color_R)**2+(G-color_G)**2+(B-color_B)**2) if min_d>d : min_d=d color_num=i if color_num==0 : print("black") elif color_num==1 : print("blue") elif color_num==2 : print("lime") elif color_num==3 : print("aqua") elif color_num==4 : print("red") elif color_num==5 : print("fuchsia") elif color_num==6 : print("yellow") else : print("white") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var color : Sequence := Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{ 255 }))}->union(Sequence{Sequence{0}->union(Sequence{255}->union(Sequence{ 0 }))}->union(Sequence{Sequence{0}->union(Sequence{255}->union(Sequence{ 255 }))}->union(Sequence{Sequence{255}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{Sequence{255}->union(Sequence{0}->union(Sequence{ 255 }))}->union(Sequence{Sequence{255}->union(Sequence{255}->union(Sequence{ 0 }))}->union(Sequence{ Sequence{255}->union(Sequence{255}->union(Sequence{ 255 })) }))))))) ; var color var color : Sequence := Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{ 255 }))}->union(Sequence{Sequence{0}->union(Sequence{255}->union(Sequence{ 0 }))}->union(Sequence{Sequence{0}->union(Sequence{255}->union(Sequence{ 255 }))}->union(Sequence{Sequence{255}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{Sequence{255}->union(Sequence{0}->union(Sequence{ 255 }))}->union(Sequence{Sequence{255}->union(Sequence{255}->union(Sequence{ 0 }))}->union(Sequence{ Sequence{255}->union(Sequence{255}->union(Sequence{ 255 })) })))))))6 : String := (OclFile["System.in"]).readLine() ; if color var color : Sequence := Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{ 255 }))}->union(Sequence{Sequence{0}->union(Sequence{255}->union(Sequence{ 0 }))}->union(Sequence{Sequence{0}->union(Sequence{255}->union(Sequence{ 255 }))}->union(Sequence{Sequence{255}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{Sequence{255}->union(Sequence{0}->union(Sequence{ 255 }))}->union(Sequence{Sequence{255}->union(Sequence{255}->union(Sequence{ 0 }))}->union(Sequence{ Sequence{255}->union(Sequence{255}->union(Sequence{ 255 })) })))))))6 = "0" then ( break ) else skip ; var color_R : int := ("" + ((color var color : Sequence := Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{ 255 }))}->union(Sequence{Sequence{0}->union(Sequence{255}->union(Sequence{ 0 }))}->union(Sequence{Sequence{0}->union(Sequence{255}->union(Sequence{ 255 }))}->union(Sequence{Sequence{255}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{Sequence{255}->union(Sequence{0}->union(Sequence{ 255 }))}->union(Sequence{Sequence{255}->union(Sequence{255}->union(Sequence{ 0 }))}->union(Sequence{ Sequence{255}->union(Sequence{255}->union(Sequence{ 255 })) })))))))6[1+1] + color var color : Sequence := Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{ 255 }))}->union(Sequence{Sequence{0}->union(Sequence{255}->union(Sequence{ 0 }))}->union(Sequence{Sequence{0}->union(Sequence{255}->union(Sequence{ 255 }))}->union(Sequence{Sequence{255}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{Sequence{255}->union(Sequence{0}->union(Sequence{ 255 }))}->union(Sequence{Sequence{255}->union(Sequence{255}->union(Sequence{ 0 }))}->union(Sequence{ Sequence{255}->union(Sequence{255}->union(Sequence{ 255 })) })))))))6[2+1], 16)))->toInteger() ; var color_G : int := ("" + ((color var color : Sequence := Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{ 255 }))}->union(Sequence{Sequence{0}->union(Sequence{255}->union(Sequence{ 0 }))}->union(Sequence{Sequence{0}->union(Sequence{255}->union(Sequence{ 255 }))}->union(Sequence{Sequence{255}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{Sequence{255}->union(Sequence{0}->union(Sequence{ 255 }))}->union(Sequence{Sequence{255}->union(Sequence{255}->union(Sequence{ 0 }))}->union(Sequence{ Sequence{255}->union(Sequence{255}->union(Sequence{ 255 })) })))))))6[3+1] + color var color : Sequence := Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{ 255 }))}->union(Sequence{Sequence{0}->union(Sequence{255}->union(Sequence{ 0 }))}->union(Sequence{Sequence{0}->union(Sequence{255}->union(Sequence{ 255 }))}->union(Sequence{Sequence{255}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{Sequence{255}->union(Sequence{0}->union(Sequence{ 255 }))}->union(Sequence{Sequence{255}->union(Sequence{255}->union(Sequence{ 0 }))}->union(Sequence{ Sequence{255}->union(Sequence{255}->union(Sequence{ 255 })) })))))))6[4+1], 16)))->toInteger() ; var color_B : int := ("" + ((color var color : Sequence := Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{ 255 }))}->union(Sequence{Sequence{0}->union(Sequence{255}->union(Sequence{ 0 }))}->union(Sequence{Sequence{0}->union(Sequence{255}->union(Sequence{ 255 }))}->union(Sequence{Sequence{255}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{Sequence{255}->union(Sequence{0}->union(Sequence{ 255 }))}->union(Sequence{Sequence{255}->union(Sequence{255}->union(Sequence{ 0 }))}->union(Sequence{ Sequence{255}->union(Sequence{255}->union(Sequence{ 255 })) })))))))6[5+1] + color var color : Sequence := Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{ 255 }))}->union(Sequence{Sequence{0}->union(Sequence{255}->union(Sequence{ 0 }))}->union(Sequence{Sequence{0}->union(Sequence{255}->union(Sequence{ 255 }))}->union(Sequence{Sequence{255}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{Sequence{255}->union(Sequence{0}->union(Sequence{ 255 }))}->union(Sequence{Sequence{255}->union(Sequence{255}->union(Sequence{ 0 }))}->union(Sequence{ Sequence{255}->union(Sequence{255}->union(Sequence{ 255 })) })))))))6[6+1], 16)))->toInteger() ; var min_d : int := 500 ; for i : Integer.subrange(0, 8-1) do ( var R : OclAny := color[i+1]->first() ; var G : OclAny := color[i+1][1+1] ; var B : OclAny := color[i+1][2+1] ; var d : double := (((R - color_R))->pow(2) + ((G - color_G))->pow(2) + ((B - color_B))->pow(2))->sqrt() ; if (min_d->compareTo(d)) > 0 then ( min_d := d ; var color_num : OclAny := i ) else skip) ; if color_num = 0 then ( execute ("black")->display() ) else (if color_num = 1 then ( execute ("blue")->display() ) else (if color_num = 2 then ( execute ("lime")->display() ) else (if color_num = 3 then ( execute ("aqua")->display() ) else (if color_num = 4 then ( execute ("red")->display() ) else (if color_num = 5 then ( execute ("fuchsia")->display() ) else (if color_num = 6 then ( execute ("yellow")->display() ) else ( execute ("white")->display() ) ) ) ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- color={'black' : '#000000','blue' : '#0000ff','lime' : '#00ff00','aqua' : '#00ffff','red' : '#ff0000','fuchsia' : '#ff00ff','yellow' : '#ffff00','white' : '#ffffff',} def list_chunk(arr,n): return[arr[i : i+3]for i in range(0,15,n)] def code2rgb(code): code=code.lstrip('#') r,g,b=[code[i : i+2]for i in range(0,len(code),2)] return[int(v,16)for v in[r,g,b]] def dk2(a,b): return sum([(a[i]-b[i])**2 for i in range(0,3)]) while True : v=input() if(v is '0'): break rgb=code2rgb(v) dks=[dk2(code2rgb(c),rgb)for c in color.values()] k=list(color.keys()) print(k[dks.index(min(dks))]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var color : Map := Map{ 'black' |-> '#000000' }->union(Map{ 'blue' |-> '#0000ff' }->union(Map{ 'lime' |-> '#00ff00' }->union(Map{ 'aqua' |-> '#00ffff' }->union(Map{ 'red' |-> '#ff0000' }->union(Map{ 'fuchsia' |-> '#ff00ff' }->union(Map{ 'yellow' |-> '#ffff00' }->union((dictorsetmaker (test (logical_test (comparison (expr (atom 'white'))))) : (test (logical_test (comparison (expr (atom '#ffffff'))))) ,)))))))) ; skip ; skip ; skip ; while true do ( var v : String := (OclFile["System.in"]).readLine() ; if (v <>= '0') then ( break ) else skip ; var rgb : OclAny := code2rgb(v) ; var dks : Sequence := color.values()->select(c | true)->collect(c | (dk2(code2rgb(c), rgb))) ; var k : Sequence := (color.keys()) ; execute (k[dks->indexOf((dks)->min()) - 1+1])->display()); operation list_chunk(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, 15-1)->select( $x | ($x - 0) mod n = 0 )->select(i | true)->collect(i | (arr.subrange(i+1, i + 3))); operation code2rgb(code : OclAny) : OclAny pre: true post: true activity: code := code.lstrip('#') ; var r : OclAny := null; var g : OclAny := null; var b : OclAny := null; Sequence{r,g,b} := Integer.subrange(0, (code)->size()-1)->select( $x | ($x - 0) mod 2 = 0 )->select(i | true)->collect(i | (code.subrange(i+1, i + 2))) ; return Sequence{r}->union(Sequence{g}->union(Sequence{ b }))->select(v | true)->collect(v | (("" + ((v, 16)))->toInteger())); operation dk2(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (Integer.subrange(0, 3-1)->select(i | true)->collect(i | (((a[i+1] - b[i+1]))->pow(2))))->sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import gcd import math from math import factorial as f from math import ceil,floor,sqrt import bisect import re import heapq from copy import deepcopy import itertools from sys import exit ii=lambda : int(input()) mi=lambda : map(int,input().split()) li=lambda : list(map(int,input().split())) yes="Yes" no="No" def main(): n,k=mi() cnt=0 while n : n//=k cnt+=1 print(cnt) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var ii : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var mi : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var li : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var yes : String := "Yes" ; var no : String := "No" ; skip ; main(); operation main() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := mi->apply() ; var cnt : int := 0 ; while n do ( n := n div k ; cnt := cnt + 1) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,k=map(int,input().split()) print(int(math.log(n,k))+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (("" + (((n, k)->log())))->toInteger() + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) i=0 if n==0 : print(1) exit() else : while k**i<=n : i+=1 print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var i : int := 0 ; if n = 0 then ( execute (1)->display() ; exit() ) else ( while ((k)->pow(i)->compareTo(n)) <= 0 do ( i := i + 1) ) ; execute (i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def baseConv(n,ro,ri=10): n=int(str(n),base=ri) s="" nums="0123456789abcdefghijklmnopqrstuvwxyz" while n : s+=nums[n % ro] n//=ro return s[: :-1] n,k=map(int,input().split()) print(len(baseConv(n,k))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((baseConv(n, k))->size())->display(); operation baseConv(n : OclAny, ro : OclAny, ri : int) : OclAny pre: true post: true activity: if ri->oclIsUndefined() then ri := 10 else skip; n := ("" + ((("" + ((n))), (argument (test (logical_test (comparison (expr (atom (name base)))))) = (test (logical_test (comparison (expr (atom (name ri))))))))))->toInteger() ; var s : String := "" ; var nums : String := "0123456789abcdefghijklmnopqrstuvwxyz" ; while n do ( s := s + nums[n mod ro+1] ; n := n div ro) ; return s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print("ACL"*int(input())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (StringLib.nCopies("ACL", ("" + (((OclFile["System.in"]).readLine())))->toInteger()))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def findMinEqualSums(a,N): sum=0 for i in range(0,N): sum=sum+a[i] sum1=0 sum2=0 min=sys.maxsize for i in range(0,N-1): sum1+=a[i] sum2=sum-sum1 if(abs(sum1-sum2)union(Sequence{2}->union(Sequence{1}->union(Sequence{5}->union(Sequence{7}->union(Sequence{ 8 }))))) ; N := (a)->size() ; execute (findMinEqualSums(a, N))->display() ) else skip; operation findMinEqualSums(a : OclAny, N : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, N-1) do ( sum := sum + a[i+1]) ; var sum1 : int := 0 ; var sum2 : int := 0 ; var min : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; for i : Integer.subrange(0, N - 1-1) do ( sum1 := sum1 + a[i+1] ; sum2 := sum - sum1 ; if (((sum1 - sum2)->abs()->compareTo(min)) < 0) then ( min := (sum1 - sum2)->abs() ) else skip ; if (min = 0) then ( break ) else skip) ; return min; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) i=1 count=0 while(i<=n): count+=n-i+1 i*=10 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 1 ; var count : int := 0 ; while ((i->compareTo(n)) <= 0) do ( count := count + n - i + 1 ; i := i * 10) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numbers=input().rstrip().split() n=int(numbers[0]) k=int(numbers[1]) i=1 while n>=k**i : i=i+1 print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var numbers : OclAny := input().rstrip().split() ; var n : int := ("" + ((numbers->first())))->toInteger() ; var k : int := ("" + ((numbers[1+1])))->toInteger() ; var i : int := 1 ; while (n->compareTo((k)->pow(i))) >= 0 do ( i := i + 1) ; execute (i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sum(N): S1=((N//2))*(2*2+(N//2-1)*2)//2 S2=((N//7))*(2*7+(N//7-1)*7)//2 S3=((N//14))*(2*14+(N//14-1)*14)//2 return S1+S2-S3 if __name__=='__main__' : N=20 print(sum(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( N := 20 ; execute ((N)->sum())->display() ) else skip; operation sum(N : OclAny) : OclAny pre: true post: true activity: var S1 : int := ((N div 2)) * (2 * 2 + (N div 2 - 1) * 2) div 2 ; var S2 : int := ((N div 7)) * (2 * 7 + (N div 7 - 1) * 7) div 2 ; var S3 : int := ((N div 14)) * (2 * 14 + (N div 14 - 1) * 14) div 2 ; return S1 + S2 - S3; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n,m=map(int,input().split()) if n==0 : break p=list(map(int,input().split())) p.sort(reverse=True) ans=0 for i in range(1,n+1): if i % m : ans+=p[i-1] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; p := p->sort() ; var ans : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( if i mod m then ( ans := ans + p[i - 1+1] ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(1,101): count=0 temp=0 SetCount=0 try : str1=input() list1=str1.split(" ") str2=input() list2=str2.split(" ") list2.sort(key=int,reverse=True) for m in range(0,int(list1[0])): if(m+1)% int(list1[1])==0 : SetCount=SetCount+1 else : count=count+int(list2[m]) print(count) except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(1, 101-1) do ( var count : int := 0 ; var temp : int := 0 ; var SetCount : int := 0 ; try ( var str1 : String := (OclFile["System.in"]).readLine() ; var list1 : OclAny := str1.split(" ") ; var str2 : String := (OclFile["System.in"]).readLine() ; var list2 : OclAny := str2.split(" ") ; list2 := list2->sort() ; for m : Integer.subrange(0, ("" + ((list1->first())))->toInteger()-1) do ( if (m + 1) mod ("" + ((list1[1+1])))->toInteger() = 0 then ( SetCount := SetCount + 1 ) else ( count := count + ("" + ((list2[m+1])))->toInteger() )) ; execute (count)->display()) catch (_e : OclException) do ( break) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,bisect PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") while True : n,m=[int(_)for _ in input().split()] if n==m==0 : break prices=sorted([int(_)for _ in input().split()],reverse=True) for i in range(m-1,n,m): prices[i]=0 print(sum(prices)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; if n = m & (m == 0) then ( break ) else skip ; var prices : Sequence := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger()))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; for i : Integer.subrange(m - 1, n-1)->select( $x | ($x - m - 1) mod m = 0 ) do ( prices[i+1] := 0) ; execute ((prices)->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : n,m=list(map(int,input().split())) if n==0 and m==0 : break amari=n % m yasai=list(map(int,input().split())) yasai.sort() s=0 if amari>0 : s=sum(yasai[0 : amari]) i=0 for y in yasai[amari :]: if i % m>0 : s+=y i+=1 print(s) except : pass ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = 0 & m = 0 then ( break ) else skip ; var amari : int := n mod m ; var yasai : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; yasai := yasai->sort() ; var s : int := 0 ; if amari > 0 then ( s := (yasai.subrange(0+1, amari))->sum() ) else skip ; var i : int := 0 ; for y : yasai.subrange(amari+1) do ( if i mod m > 0 then ( s := s + y ) else skip ; i := i + 1) ; execute (s)->display()) catch (_e : OclException) do ( skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(n,m,prices): ans=0 for i in range(0,n,m): t=prices[i : i+m] if len(t)==m : t[-1]=0 ans+=sum(t) return ans def main(args): while True : n,m=map(int,input().split()) if n==0 and m==0 : break prices=sorted([int(p)for p in input().split()],reverse=True) ans=solve(n,m,prices) print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(n : OclAny, m : OclAny, prices : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod m = 0 ) do ( var t : OclAny := prices.subrange(i+1, i + m) ; if (t)->size() = m then ( t->last() := 0 ) else skip ; ans := ans + (t)->sum()) ; return ans; operation main(args : OclAny) pre: true post: true activity: while true do ( Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 & m = 0 then ( break ) else skip ; prices := input().split()->select(p | true)->collect(p | (("" + ((p)))->toInteger()))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; ans := solve(n, m, prices) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def findAnagrams(self,s,p): res=[] if s is None or p is None or len(s)==0 or len(p)==0 : return res char_map=[0]*256 for c in p : char_map[ord(c)]+=1 left,right,count=0,0,len(p) while right=1 : count-=1 char_map[ord(s[right])]-=1 right+=1 if count==0 : res.append(left) if right-left==len(p): if char_map[ord(s[left])]>=0 : count+=1 char_map[ord(s[left])]+=1 left+=1 return res ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation findAnagrams(s : OclAny,p : OclAny) : OclAny pre: true post: true activity: var res : Sequence := Sequence{} ; if s <>= null or p <>= null or (s)->size() = 0 or (p)->size() = 0 then ( return res ) else skip ; var char_map : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 256) ; for c : p do ( char_map[(c)->char2byte()+1] := char_map[(c)->char2byte()+1] + 1) ; var left : OclAny := null; var right : OclAny := null; var count : OclAny := null; Sequence{left,right,count} := Sequence{0,0,(p)->size()} ; while (right->compareTo((s)->size())) < 0 do ( if char_map[(s[right+1])->char2byte()+1] >= 1 then ( count := count - 1 ) else skip ; char_map[(s[right+1])->char2byte()+1] := char_map[(s[right+1])->char2byte()+1] - 1 ; right := right + 1 ; if count = 0 then ( execute ((left) : res) ) else skip ; if right - left = (p)->size() then ( if char_map[(s[left+1])->char2byte()+1] >= 0 then ( count := count + 1 ) else skip ; char_map[(s[left+1])->char2byte()+1] := char_map[(s[left+1])->char2byte()+1] + 1 ; left := left + 1 ) else skip) ; return res; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): x=input().split() n=int(x[0]) m=int(x[1]) for i in range(n): x=input().split() start=int(x[0]) finish=int(x[1]) timeinit=int(x[2]) if(start==finish): print(timeinit) elif(start2*trips*(m-1)+start-1): trips+=1 timef=2*trips*(m-1)+finish-1 print(timef) else : trips=0 while(timeinit>2*(m-1)*(trips+1)-start+1): trips+=1 timef=2*(m-1)*(trips+1)+1-finish print(timef) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var x : OclAny := input().split() ; var n : int := ("" + ((x->first())))->toInteger() ; var m : int := ("" + ((x[1+1])))->toInteger() ; for i : Integer.subrange(0, n-1) do ( x := input().split() ; var start : int := ("" + ((x->first())))->toInteger() ; var finish : int := ("" + ((x[1+1])))->toInteger() ; var timeinit : int := ("" + ((x[2+1])))->toInteger() ; if (start = finish) then ( execute (timeinit)->display() ) else (if ((start->compareTo(finish)) < 0) then ( var trips : int := 0 ; while ((timeinit->compareTo(2 * trips * (m - 1) + start - 1)) > 0) do ( trips := trips + 1) ; var timef : double := 2 * trips * (m - 1) + finish - 1 ; execute (timef)->display() ) else ( trips := 0 ; while ((timeinit->compareTo(2 * (m - 1) * (trips + 1) - start + 1)) > 0) do ( trips := trips + 1) ; timef := 2 * (m - 1) * (trips + 1) + 1 - finish ; execute (timef)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) if n==1 or n==2 : print(n) else : u=str() v=n//3 w=n % 3 u+='21'*v if w==1 : u='1'+u elif w==2 : u+='2' print(u) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 or n = 2 then ( execute (n)->display() ) else ( var u : String := ("" + (())) ; var v : int := n div 3 ; var w : int := n mod 3 ; u := u + StringLib.nCopies('21', v) ; if w = 1 then ( u := '1' + u ) else (if w = 2 then ( u := u + '2' ) else skip) ; execute (u)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math ans=[] input=sys.stdin.readline n,m=map(int,input().strip().split()) for _ in range(n): start,end,t=map(int,input().strip().split()) start-=1 end-=1 if start==end : ans.append(t) continue if starttrim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for _anon : Integer.subrange(0, n-1) do ( var start : OclAny := null; var end : OclAny := null; var t : OclAny := null; Sequence{start,end,t} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; start := start - 1 ; end := end - 1 ; if start = end then ( execute ((t) : ans) ; continue ) else skip ; if (start->compareTo(end)) < 0 then ( var full : double := 2 * (m - 1) ; execute ((((t - start) / full)->ceil() * full + end) : ans) ; continue ) else skip ; full := 2 * (m - 1) ; execute ((((t - (full - start)) / full)->ceil() * full + (full - end)) : ans)) ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name res)))))))) ))))))) (comp_for for (exprlist (expr (atom (name res)))) in (logical_test (comparison (expr (atom (name ans)))))))), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkArray(a,b,n): operations=0 ; i=0 ; while(iunion(Sequence{7}->union(Sequence{1}->union(Sequence{4}->union(Sequence{1}->union(Sequence{ 2 }))))); ; b := Sequence{3}->union(Sequence{7}->union(Sequence{3}->union(Sequence{6}->union(Sequence{3}->union(Sequence{ 2 }))))); ; var size : int := (a)->size(); ; checkArray(a, b, size); ) else skip; operation checkArray(a : OclAny, b : OclAny, n : OclAny) pre: true post: true activity: var operations : int := 0; ; var i : int := 0; ; while ((i->compareTo(n)) < 0) do ( if (a[i+1] - b[i+1] = 0) then ( i := i + 1; ; continue; ) else skip ; var diff : double := a[i+1] - b[i+1]; ; i := i + 1; ; while ((i->compareTo(n)) < 0 & a[i+1] - b[i+1] = diff) do ( i := i + 1;) ; operations := operations + 1;) ; execute (operations)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,m=map(int,input().split()) for i in range(n): a,b,c=map(int,input().split()) if a==b : print(c) continue y=c %(m-1) x=c//(m-1) if x % 2==0 : z=1+y if ab : if z>=a : print(z-b+c) else : print(z-1+m-1+m-b+c) else : print(z-1+b-1+c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = b then ( execute (c)->display() ; continue ) else skip ; var y : int := c mod (m - 1) ; var x : int := c div (m - 1) ; if x mod 2 = 0 then ( var z : int := 1 + y ; if (a->compareTo(b)) < 0 then ( if (z->compareTo(a)) <= 0 then ( execute (b - z + c)->display() ) else ( execute (b - 1 + m - z + m - 1 + c)->display() ) ) else ( execute (m - z + m - b + c)->display() ) ) else ( z := m - y ; if (a->compareTo(b)) > 0 then ( if (z->compareTo(a)) >= 0 then ( execute (z - b + c)->display() ) else ( execute (z - 1 + m - 1 + m - b + c)->display() ) ) else ( execute (z - 1 + b - 1 + c)->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): x=input().split() n=int(x[0]) m=int(x[1]) for i in range(n): x=input().split() start=int(x[0]) finish=int(x[1]) timeinit=int(x[2]) if(start==finish): print(timeinit) elif(start2*trips*(m-1)+start-1): trips+=1 timef=2*trips*(m-1)+finish-1 print(timef) else : trips=0 while(timeinit>2*(m-1)*(trips+1)-start+1): trips+=1 timef=2*(m-1)*(trips+1)+1-finish print(timef) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var x : OclAny := input().split() ; var n : int := ("" + ((x->first())))->toInteger() ; var m : int := ("" + ((x[1+1])))->toInteger() ; for i : Integer.subrange(0, n-1) do ( x := input().split() ; var start : int := ("" + ((x->first())))->toInteger() ; var finish : int := ("" + ((x[1+1])))->toInteger() ; var timeinit : int := ("" + ((x[2+1])))->toInteger() ; if (start = finish) then ( execute (timeinit)->display() ) else (if ((start->compareTo(finish)) < 0) then ( var trips : int := 0 ; while ((timeinit->compareTo(2 * trips * (m - 1) + start - 1)) > 0) do ( trips := trips + 1) ; var timef : double := 2 * trips * (m - 1) + finish - 1 ; execute (timef)->display() ) else ( trips := 0 ; while ((timeinit->compareTo(2 * (m - 1) * (trips + 1) - start + 1)) > 0) do ( trips := trips + 1) ; timef := 2 * (m - 1) * (trips + 1) + 1 - finish ; execute (timef)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from itertools import zip_longest as zip T=int(sys.stdin.readline().strip()) for t in range(T): A,B,K=tuple(int(i)for i in sys.stdin.readline().strip().split()) cnt=0 for a in range(A): for b in range(B): if a & btrim())))->toInteger() ; for t : Integer.subrange(0, T-1) do ( var A : OclAny := null; var B : OclAny := null; var K : OclAny := null; Sequence{A,B,K} := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin)) (trailer . (name readline) (arguments ( ))) (trailer . (name strip) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ; var cnt : int := 0 ; for a : Integer.subrange(0, A-1) do ( for b : Integer.subrange(0, B-1) do ( if (MathLib.bitwiseAnd(a, b)->compareTo(K)) < 0 then ( cnt := cnt + 1 ) else skip)) ; execute (StringLib.format("Case #%d: %d",Sequence{t + 1, cnt}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys infile=None outfile=None def readline(): x=infile.readline() if len(x)>0 : return x[:-1] else : return x def readint(): return int(readline()) def readfloat(): return float(readline()) def readints(): xs=readline().split() return[int(x)for x in xs] def readfloats(): xs=readline().split() return[float(x)for x in xs] def writeline(x): outfile.write(x+'\n') def run(main): global infile,outfile args=sys.argv if len(args)==1 : infile=sys.stdin outfile=sys.stdout elif len(args)==2 : if args[1]=='-' : infile=sys.stdin else : infile=open(args[1],'r') if args[1].endswith('.in'): outfile=open(args[1][:-3]+'.out','w') else : outfile=sys.stdout elif len(args)==3 : if args[1]=='-' : infile=sys.stdin else : infile=open(args[1],'r') if args[2]=='-' : outfile=sys.stdout else : outfile=open(args[2],'w') else : print("Expected 0,1,or 2 args,not{:d}".format(len(args)-1)) print(args) return t=readint() for casenum in range(1,t+1): main(casenum) if infile is not sys.stdin : infile.close() if outfile is not sys.stdout : outfile.close() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute infile : OclAny; attribute outfile : OclAny; operation initialise() pre: true post: true activity: skip ; var infile : OclAny := null ; var outfile : OclAny := null ; skip ; skip ; skip ; skip ; skip ; skip ; skip; operation readline() : OclAny pre: true post: true activity: var x : String := infile.readLine() ; if (x)->size() > 0 then ( return x->front() ) else ( return x ); operation readint() : OclAny pre: true post: true activity: return ("" + ((readline())))->toInteger(); operation readfloat() : OclAny pre: true post: true activity: return ("" + ((readline())))->toReal(); operation readints() : OclAny pre: true post: true activity: var xs : OclAny := readline().split() ; return xs->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation readfloats() : OclAny pre: true post: true activity: xs := readline().split() ; return xs->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation writeline(x : OclAny) pre: true post: true activity: outfile.write(x + ' '); operation run(main : OclAny) pre: true post: true activity: skip; skip ; var args : (trailer . (name argv)) := (trailer . (name argv)) ; if (args)->size() = 1 then ( infile := OclFile["System.in"] ; outfile := OclFile["System.out"] ) else (if (args)->size() = 2 then ( if args[1+1] = '-' then ( infile := OclFile["System.in"] ) else ( infile := OclFile.newOclFile_Write(OclFile.newOclFile(args[1+1])) ) ; if args[1+1]->hasSuffix('.in') then ( outfile := OclFile.newOclFile_Write(OclFile.newOclFile(args[1+1].subrange(1,-3) + '.out')) ) else ( outfile := OclFile["System.out"] ) ) else (if (args)->size() = 3 then ( if args[1+1] = '-' then ( infile := OclFile["System.in"] ) else ( infile := OclFile.newOclFile_Write(OclFile.newOclFile(args[1+1])) ) ; if args[2+1] = '-' then ( outfile := OclFile["System.out"] ) else ( outfile := OclFile.newOclFile_Write(OclFile.newOclFile(args[2+1])) ) ) else ( execute (StringLib.interpolateStrings("Expected 0,1,or 2 args,not{:d}", Sequence{(args)->size() - 1}))->display() ; execute (args)->display() ; return ) ) ) ; var t : OclAny := readint() ; for casenum : Integer.subrange(1, t + 1-1) do ( main(casenum)) ; if not(infile <>= OclFile["System.in"]) then ( infile.closeFile() ) else skip ; if not(outfile <>= OclFile["System.out"]) then ( outfile.closeFile() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def emit(text,*args): msg=text % args sys.stderr.write(msg) sys.stdout.write(msg) def getline(): return sys.stdin.readline().rstrip('\n') def solve(a,b,k): count=0 for i in range(a): for j in range(b): if(i & j)toInteger() ; for casenr : Integer.subrange(1, ncases + 1-1) do ( Sequence{a,b,k} := getline().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; emit("Case #%d: %s\n", casenr, solve(a, b, k))); operation emit(text : OclAny, args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) var msg : int := text mod args ; (expr (atom (name sys)) (trailer . (name stderr)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name msg)))))))) )))) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name msg)))))))) )))); operation getline() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(' '); operation solve(a : OclAny, b : OclAny, k : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, a-1) do ( for j : Integer.subrange(0, b-1) do ( if ((MathLib.bitwiseAnd(i, j))->compareTo(k)) < 0 then ( count := count + 1 ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for tc in range(int(input())): A,B,K=(int(x)-1 for x in input().split()) dp=[[-1]*8 for i in range(31)] def DP(pos,a,b,k): if pos<0 : return 1 if dp[pos][a*4+b*2+k]==-1 : dp[pos][a*4+b*2+k]=0 bita=0 if(A &(1<toInteger()-1) do ( var A : OclAny := null; var B : OclAny := null; var K : OclAny := null; Sequence{A,B,K} := Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) - (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var dp : Sequence := Integer.subrange(0, 31-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ -1 }, 8))) ; skip ; execute (StringLib.interpolateStrings('Case #{}:{}', Sequence{tc + 1, DP(30, 0, 0, 0)}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=lambda : map(int,input().split()) n,x=I() p,w=0,0 for _ in range(n): l,r=I() while pcollect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := I->apply() ; var p : OclAny := null; var w : OclAny := null; Sequence{p,w} := Sequence{0,0} ; for _anon : Integer.subrange(0, n-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := I->apply() ; while (p->compareTo(l - x)) < 0 do ( p := p + x) ; w := w + (r - p); var p : OclAny := r) ; execute (w)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=map(int,input().strip().split()) array=[] for i in range(n): row=list(map(int,input().strip().split())) array.append(row) min=0 gap=(array[0][0]-1)% x for i in range(n): min+=array[i][1]-array[i][0]+1 for i in range(n-1): gap+=((array[i+1][0]-array[i][1]-1)% x) print(min+gap) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var array : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var row : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((row) : array)) ; var min : int := 0 ; var gap : int := (array->first()->first() - 1) mod x ; for i : Integer.subrange(0, n-1) do ( min := min + array[i+1][1+1] - array[i+1]->first() + 1) ; for i : Integer.subrange(0, n - 1-1) do ( gap := gap + ((array[i + 1+1]->first() - array[i+1][1+1] - 1) mod x)) ; execute (min + gap)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) if n % 3==1 : while n>0 : if n>0 : n-=1 print(1,end="") if n>0 : n-=2 print(2,end="") else : while n>0 : if n>0 : n-=2 print(2,end="") if n>0 : n-=1 print(1,end="") print() i-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 3 = 1 then ( while n > 0 do ( if n > 0 then ( n := n - 1 ; execute (1)->display() ) else skip ; if n > 0 then ( n := n - 2 ; execute (2)->display() ) else skip) ) else ( while n > 0 do ( if n > 0 then ( n := n - 2 ; execute (2)->display() ) else skip ; if n > 0 then ( n := n - 1 ; execute (1)->display() ) else skip) ) ; execute (->display() ; i := i - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() I=lambda : map(int,input().split()) n,x=I() i=1 a=0 for _ in range(n): l,r=I() a,i=a+(l-i)% x+r+1-l,r+1 print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var I : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := I->apply() ; var i : int := 1 ; var a : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := I->apply() ; Sequence{a,i} := Sequence{a + (l - i) mod x + r + 1 - l,r + 1}) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=map(int,input().split()) res=0 cur=1 for i in range(n): l,r=map(int,input().split()) res=res+(l-cur)% x+(r-l+1) cur=r+1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var res : int := 0 ; var cur : int := 1 ; for i : Integer.subrange(0, n-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; res := res + (l - cur) mod x + (r - l + 1) ; cur := r + 1) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printVertically(s): s=s.split("") result="" map=dict() mx=0 for i in s : mx=max(mx,len(i)) n=mx i=0 while(i=len(j): map[i]=map.get(i,"")+"$" else : map[i]=map.get(i,"")+j[i] i+=1 for j in range(mx): result+=map[j]+"" return result if __name__=='__main__' : st="ge ek sfor ge eks" print(printVertically(st)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var st : String := "ge ek sfor ge eks" ; execute (printVertically(st))->display() ) else skip; operation printVertically(s : OclAny) : OclAny pre: true post: true activity: s := s.split("") ; var result : String := "" ; var map : Map := (arguments ( )) ; var mx : int := 0 ; for i : s do ( mx := Set{mx, (i)->size()}->max()) ; var n : int := mx ; var i : int := 0 ; while ((i->compareTo(mx)) < 0) do ( for j : s do ( if (i->compareTo((j)->size())) >= 0 then ( ([i+1]`third)->collect( _x | ([i+1])->apply(_x) ) := ((trailer . (name get) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom ""))))))) ))))->collect( _x | ((trailer . (name get) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom ""))))))) ))))->apply(_x) )->union("$") ) else ( ([i+1]`third)->collect( _x | ([i+1])->apply(_x) ) := ((trailer . (name get) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom ""))))))) ))))->collect( _x | ((trailer . (name get) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom ""))))))) ))))->apply(_x) )->union(j[i+1]) )) ; i := i + 1) ; for j : Integer.subrange(0, mx-1) do ( result := result + ([j+1]`third)->collect( _x | ([j+1])->apply(_x) )->union("")) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): n,x=map(int,input().split()) last=1 res=0 for _ in range(n): l,r=map(int,input().split()) res+=(l-1-last+1)% x res+=r-l+1 last=r+1 print(res) def main(): t=1 for _ in range(t): solution() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; main(); operation solution() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var last : int := 1 ; var res : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; res := res + (l - 1 - last + 1) mod x ; res := res + r - l + 1 ; last := r + 1) ; execute (res)->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=3 def minimumflip(mat,n): transpose=[[0]*n]*n for i in range(n): for j in range(n): transpose[i][j]=mat[j][i] flip=0 for i in range(n): for j in range(n): if transpose[i][j]!=mat[i][j]: flip+=1 return int(flip/2) n=3 mat=[[0,0,1],[1,1,1],[1,0,0]] print(minimumflip(mat,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 3 ; skip ; n := 3 ; mat := Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{ 1 }))}->union(Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))}->union(Sequence{ Sequence{1}->union(Sequence{0}->union(Sequence{ 0 })) })) ; execute (minimumflip(mat, n))->display(); operation minimumflip(mat : OclAny, n : OclAny) : OclAny pre: true post: true activity: var transpose : Sequence := MatrixLib.elementwiseMult(Sequence{ MatrixLib.elementwiseMult(Sequence{ 0 }, n) }, n) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( transpose[i+1][j+1] := mat[j+1][i+1])) ; var flip : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if transpose[i+1][j+1] /= mat[i+1][j+1] then ( flip := flip + 1 ) else skip)) ; return ("" + ((flip / 2)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K,*L=map(int,open(0).read().split()); print(sum(sorted(L)[-K :])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; var L : OclAny := null; Sequence{N,K,L} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ); execute ((sorted(L).subrange(-K+1))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=[int(i)for i in input().split()] lst=[int(i)for i in input().split()] lst.sort() lst.reverse() ans=0 for i in range(k): ans+=lst[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var lst : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; lst := lst->sort() ; lst := lst->reverse() ; var ans : int := 0 ; for i : Integer.subrange(0, k-1) do ( ans := ans + lst[i+1]) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import reduce n,k=map(lambda x : int(x),input().split(' ')) l=list(map(lambda x : int(x),input().split(' '))) def add_num(a,b): return int(a)+int(b) k*=-1 l.sort() print(reduce(add_num,l[k :])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split(' '))->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ) ; var l : Sequence := ((input().split(' '))->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) )) ; skip ; k := k * -1 ; l := l->sort() ; execute (reduce(add_num, l.subrange(k+1)))->display(); operation add_num(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return ("" + ((a)))->toInteger() + ("" + ((b)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N,K=(int(i)for i in input().split()) A=[int(i)for i in input().split()] A.sort(reverse=True) print(sum(A[: K])) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var A : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; A := A->sort() ; execute ((A.subrange(1,K))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=[int(e)for e in input().split()] sticks_length=list(map(int,input().split())) sticks_length.sort(reverse=True) print(sum(sticks_length[: k : 1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(e | true)->collect(e | (("" + ((e)))->toInteger())) ; var sticks_length : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; sticks_length := sticks_length->sort() ; execute ((sticks_length(subscript : (test (logical_test (comparison (expr (atom (name k)))))) (sliceop : (test (logical_test (comparison (expr (atom (number (integer 1))))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for n in[*map(int,open(0))][1 :]: r=n % 3 ; print(n//3*('21','12')[r==1],r or '',sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for n : (OclFile.newOclFile_Write(OclFile.newOclFile(0)))->collect( _x | (OclType["int"])->apply(_x) )->tail() do ( var r : int := n mod 3; execute (n div 3 * Sequence{'21', '12'}->select(r = 1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def mp(): return list(map(int,input().split())) def it(): return int(input()) mod=10**9+7 def solve(): n,k=mp() dep,left=divmod(n-1,k) ans=dep*2+(2 if left>=2 else 1 if left>=1 else 0) print(ans) node=1 for i in range(k): root=0 for j in range(dep+1 if ipow(9) + 7 ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation mp() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation it() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation solve() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := mp() ; var dep : OclAny := null; var left : OclAny := null; Sequence{dep,left} := Sequence{(n - 1 div k), (n - 1 mod k)} ; var ans : double := dep * 2 + (if left >= 2 then 2 else if left >= 1 then 1 else 0 endif endif) ; execute (ans)->display() ; var node : int := 1 ; for i : Integer.subrange(0, k-1) do ( var root : int := 0 ; for j : Integer.subrange(0, if (i->compareTo(left)) < 0 then dep + 1 else dep endif-1) do ( execute (StringLib.formattedString("{root+1}{node+1}"))->display() ; root := node ; node := node + 1)) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from collections import defaultdict,deque import heapq n,k=map(int,sys.stdin.readline().split()) graph=defaultdict(list) st=2 q=deque() for i in range(k): graph[1].append(st) q.append(st) st+=1 leaves=[1 for _ in range(k)] cnt=0 while q and st<=n : a=q.popleft() graph[a].append(st) q.append(st) leaves[(cnt)% k]+=1 cnt+=1 st+=1 dis=leaves[0]+leaves[1] leaves.sort() dis=leaves[-1]+leaves[-2] q=deque() q.append(1) vis=defaultdict(int) print(dis) while q : a=q.popleft() for x in graph[a]: print(a,x) q.append(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var graph : OclAny := defaultdict(OclType["Sequence"]) ; var st : int := 2 ; var q : Sequence := () ; for i : Integer.subrange(0, k-1) do ((expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name st)))))))) )))) ; execute ((st) : q) ; st := st + 1) ; var leaves : Sequence := Integer.subrange(0, k-1)->select(_anon | true)->collect(_anon | (1)) ; var cnt : int := 0 ; while q & (st->compareTo(n)) <= 0 do ( var a : OclAny := q->first() ; q := q->tail() ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name st)))))))) )))) ; execute ((st) : q) ; leaves[(cnt) mod k+1] := leaves[(cnt) mod k+1] + 1 ; cnt := cnt + 1 ; st := st + 1) ; var dis : OclAny := leaves->first() + leaves[1+1] ; leaves := leaves->sort() ; dis := leaves->last() + leaves->front()->last() ; q := () ; execute ((1) : q) ; var vis : OclAny := defaultdict(OclType["int"]) ; execute (dis)->display() ; while q do ( a := q->first() ; q := q->tail() ; for x : graph[a+1] do ( execute (a)->display() ; execute ((x) : q))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,k=map(int,input().split()) sum=math.floor((n-1)/k)*2+min(2,(n-1)% k) print(sum) for i in range(2,n+1): print(i,max(i-k,1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sum : double := ((n - 1) / k)->floor() * 2 + Set{2, (n - 1) mod k}->min() ; execute (sum)->display() ; for i : Integer.subrange(2, n + 1-1) do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=list(map(float,input().split())) if n==1 : print(p[0]) quit() M=[0.0]*n f=[0.0]*n f[0]=1.0 for i in range(1,n): f[i]=p[i]*f[i-1]+1-p[i] res=p[0]*p[1] ans=res for i in range(2,n): temp=(1-p[i-1])+p[i-1]*(1-p[i-2]) res=p[i]*p[i-1]*(1-p[i-2])+p[i]*(res+1-temp) ans+=res print(sum(p)+2*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["double"])->apply(_x) )) ; if n = 1 then ( execute (p->first())->display() ; quit() ) else skip ; var M : Sequence := MatrixLib.elementwiseMult(Sequence{ 0.0 }, n) ; var f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0.0 }, n) ; f->first() := 1.0 ; for i : Integer.subrange(1, n-1) do ( f[i+1] := p[i+1] * f[i - 1+1] + 1 - p[i+1]) ; var res : double := p->first() * p[1+1] ; var ans : OclAny := res ; for i : Integer.subrange(2, n-1) do ( var temp : double := (1 - p[i - 1+1]) + p[i - 1+1] * (1 - p[i - 2+1]) ; res := p[i+1] * p[i - 1+1] * (1 - p[i - 2+1]) + p[i+1] * (res + 1 - temp) ; ans := ans + res) ; execute ((p)->sum() + 2 * ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) x=(n-1)//k r=(n-1)% k edges=[] u=1 for j in range(k): prv=0 for i in range(x+1 if j=2 else 1 if r>=1 else 0) print(cost) for u,v in edges : print(u+1,v+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : int := (n - 1) div k ; var r : int := (n - 1) mod k ; var edges : Sequence := Sequence{} ; var u : int := 1 ; for j : Integer.subrange(0, k-1) do ( var prv : int := 0 ; for i : Integer.subrange(0, if (j->compareTo(r)) < 0 then x + 1 else x endif-1) do ( execute ((Sequence{u, prv}) : edges) ; prv := u ; u := u + 1)) ; var cost : int := 2 * x + (if r >= 2 then 2 else if r >= 1 then 1 else 0 endif endif) ; execute (cost)->display() ; for _tuple : edges do (var _indx : int := 1; var u : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); execute (u + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys m=166666 ; s=[1]*m ; t=[1]*m for i in range(m): if s[i]: k=6*i+5 s[i+k : : k]=[0]*len(s[i+k : : k]) t[-2-i+k : : k]=[0]*len(t[-2-i+k : : k]) if t[i]: k=6*i+7 s[-2-i+k : : k]=[0]*len(s[-2-i+k : : k]) t[i+k : : k]=[0]*len(t[i+k : : k]) for e in sys.stdin : e=int(e) print([e-1,sum(s[:(e+1)//6])+sum(t[:(e-1)//6])+2][e>3]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var m : int := 166666; var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, m); var t : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, m) ; for i : Integer.subrange(0, m-1) do ( if s[i+1] then ( var k : double := 6 * i + 5 ; s(subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name k))))))) : (sliceop : (test (logical_test (comparison (expr (atom (name k)))))))) := MatrixLib.elementwiseMult(Sequence{ 0 }, (s(subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name k))))))) : (sliceop : (test (logical_test (comparison (expr (atom (name k)))))))))->size()) ; t(subscript (test (logical_test (comparison (expr (expr (expr (atom - (number (integer 2)))) - (expr (atom (name i)))) + (expr (atom (name k))))))) : (sliceop : (test (logical_test (comparison (expr (atom (name k)))))))) := MatrixLib.elementwiseMult(Sequence{ 0 }, (t(subscript (test (logical_test (comparison (expr (expr (expr (atom - (number (integer 2)))) - (expr (atom (name i)))) + (expr (atom (name k))))))) : (sliceop : (test (logical_test (comparison (expr (atom (name k)))))))))->size()) ) else skip ; if t[i+1] then ( k := 6 * i + 7 ; s(subscript (test (logical_test (comparison (expr (expr (expr (atom - (number (integer 2)))) - (expr (atom (name i)))) + (expr (atom (name k))))))) : (sliceop : (test (logical_test (comparison (expr (atom (name k)))))))) := MatrixLib.elementwiseMult(Sequence{ 0 }, (s(subscript (test (logical_test (comparison (expr (expr (expr (atom - (number (integer 2)))) - (expr (atom (name i)))) + (expr (atom (name k))))))) : (sliceop : (test (logical_test (comparison (expr (atom (name k)))))))))->size()) ; t(subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name k))))))) : (sliceop : (test (logical_test (comparison (expr (atom (name k)))))))) := MatrixLib.elementwiseMult(Sequence{ 0 }, (t(subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name k))))))) : (sliceop : (test (logical_test (comparison (expr (atom (name k)))))))))->size()) ) else skip) ; for e : OclFile["System.in"] do ( var e : int := ("" + ((e)))->toInteger() ; execute (Sequence{e - 1}->union(Sequence{ (s.subrange(1,(e + 1) div 6))->sum() + (t.subrange(1,(e - 1) div 6))->sum() + 2 })->select(e > 3))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math prim_no={2 : True} def is_prime(no): if no==2 or no==1 : return True if no % 2==0 : return False if prim_no.get(no)is not None : return prim_no.get(no) max_check=int(math.sqrt(no)) for i in range(3,max_check+1,2): if no % i==0 : prim_no[no]=False return False prim_no[no]=True return True def main(): prim_vals={} num_data=[] while True : num=sys.stdin.readline() if num is None or num.strip()=='' : break num=int(num.strip()) num_data.append(num) sorted_num_data=sorted(num_data) prim_num={} for num in sorted_num_data : if prim_vals.get(num)is not None : cnt=prim_vals.get(num) else : if num==1 : cnt=0 else : cnt=0 if num % 2==0 : start_num=num-1 else : start_num=num for i in range(start_num,0,-2): if prim_vals.get(i)is not None : cnt+=prim_vals.get(i) break if is_prime(i): cnt+=1 prim_vals[num]=cnt prim_num[num]=cnt for num in num_data : print(prim_num[num]) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var prim_no : Map := Map{ 2 |-> true } ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation is_prime(no : OclAny) : OclAny pre: true post: true activity: if no = 2 or no = 1 then ( return true ) else skip ; if no mod 2 = 0 then ( return false ) else skip ; if not(prim_no.get(no) <>= null) then ( return prim_no.get(no) ) else skip ; var max_check : int := ("" + (((no)->sqrt())))->toInteger() ; for i : Integer.subrange(3, max_check + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if no mod i = 0 then ( prim_no[no+1] := false ; return false ) else skip) ; prim_no[no+1] := true ; return true; operation main() pre: true post: true activity: var prim_vals : OclAny := Set{} ; var num_data : Sequence := Sequence{} ; while true do ( var num : String := (OclFile["System.in"]).readLine() ; if num <>= null or num->trim() = '' then ( break ) else skip ; num := ("" + ((num->trim())))->toInteger() ; execute ((num) : num_data)) ; var sorted_num_data : Sequence := num_data->sort() ; var prim_num : OclAny := Set{} ; for num : sorted_num_data do ( if not(prim_vals.get(num) <>= null) then ( var cnt : OclAny := prim_vals.get(num) ) else ( if num = 1 then ( cnt := 0 ) else ( cnt := 0 ; if StringLib.format(num,2) = 0 then ( var start_num : double := num - 1 ) else ( start_num := num ) ; for i : Integer.subrange(start_num, 0-1)->select( $x | ($x - start_num) mod -2 = 0 ) do ( if not(prim_vals.get(i) <>= null) then ( cnt := cnt + prim_vals.get(i) ; break ) else skip ; if is_prime(i) then ( cnt := cnt + 1 ) else skip) ; prim_vals->at(num) := cnt ) ) ; prim_num->at(num) := cnt) ; for num : num_data do ( execute (prim_num->at(num))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys sup=1000000 is_prime=[0]*sup count=[0]*sup def setup(): is_prime[2]=1 for n in range(3,sup,2): flag=True for i in range(3,int(math.floor(math.sqrt(n)+1)),2): if n % i==0 : flag=False break if flag : is_prime[n]=1 def precount(): for n in range(2,sup): count[n]=count[n-1]+is_prime[n] def main(): setup() precount() l=[] for line in sys.stdin : l.append(int(line)) for line in l : print(count[line]) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var sup : int := 1000000 ; var is_prime : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, sup) ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, sup) ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation setup() pre: true post: true activity: is_prime[2+1] := 1 ; for n : Integer.subrange(3, sup-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( var flag : boolean := true ; for i : Integer.subrange(3, ("" + ((((n)->sqrt() + 1)->floor())))->toInteger()-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if n mod i = 0 then ( flag := false ; break ) else skip) ; if flag then ( is_prime[n+1] := 1 ) else skip); operation precount() pre: true post: true activity: for n : Integer.subrange(2, sup-1) do ( count[n+1] := count[n - 1+1] + is_prime[n+1]); operation main() pre: true post: true activity: setup() ; precount() ; var l : Sequence := Sequence{} ; for line : OclFile["System.in"] do ( execute ((("" + ((line)))->toInteger()) : l)) ; for line : l do ( execute (count[line+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import(division,absolute_import,print_function,unicode_literals) from sys import stdin def enum_prime(n): if n<2 : return[] if n==2 : return[2] L=list(range(2,n+1)) PL=[] while True : PL.append(L[0]) L=[i for i in L if i % PL[-1]!=0] if L[-1]toInteger() ; var cnt : int := 0 ; for p : primelist do ( if (n->compareTo(p)) < 0 then ( break ) else skip ; cnt := cnt + 1) ; execute (cnt)->display()); operation enum_prime(n : OclAny) : OclAny pre: true post: true activity: if n < 2 then ( return Sequence{} ) else skip ; if n = 2 then ( return Sequence{ 2 } ) else skip ; var L : Sequence := (Integer.subrange(2, n + 1-1)) ; var PL : Sequence := Sequence{} ; while true do ( execute ((L->first()) : PL) ; L := L->select(i | i mod PL->last() /= 0)->collect(i | (i)) ; if (L->last()->compareTo((PL->last())->pow(2))) < 0 then ( return PL->union(L) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys array=[] for i in sys.stdin : array.append(int(i)) m=max(array) prime=[1]*(m+1) prime[0]=prime[1]=0 for i in range(2,int(m**0.5)+1): if prime[i]==1 : for j in range(i*i,m+1,i): prime[j]=0 for i in range(len(array)): print(sum(prime[: array[i]+1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var array : Sequence := Sequence{} ; for i : OclFile["System.in"] do ( execute ((("" + ((i)))->toInteger()) : array)) ; var m : OclAny := (array)->max() ; var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (m + 1)) ; prime->first() := 0; var prime[1+1] : int := 0 ; for i : Integer.subrange(2, ("" + (((m)->pow(0.5))))->toInteger() + 1-1) do ( if prime[i+1] = 1 then ( for j : Integer.subrange(i * i, m + 1-1)->select( $x | ($x - i * i) mod i = 0 ) do ( prime[j+1] := 0) ) else skip) ; for i : Integer.subrange(0, (array)->size()-1) do ( execute ((prime.subrange(1,array[i+1] + 1))->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) if n<=2 : print(n) else : lis=list() cnt=0 ans=str() while n>0 : if cnt % 2==0 and n>=2 : n-=2 lis.append(2) else : n-=1 ; lis.append(1) cnt+=1 if lis.count(1)==lis.count(2): ans=str() for i in range(lis.count(1)): ans+='2' ans+='1' elif lis.count(1)>lis.count(2): ans='1' for i in range(lis.count(2)): ans+='2' ans+='1' else : ans='2' for i in range(lis.count(1)): ans+='1' ans+='2' print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n <= 2 then ( execute (n)->display() ) else ( var lis : Sequence := () ; var cnt : int := 0 ; var ans : String := ("" + (())) ; while n > 0 do ( if cnt mod 2 = 0 & n >= 2 then ( n := n - 2 ; execute ((2) : lis) ) else ( n := n - 1; execute ((1) : lis) ) ; cnt := cnt + 1) ; if lis->count(1) = lis->count(2) then ( ans := ("" + (())) ; for i : Integer.subrange(0, lis->count(1)-1) do ( ans := ans + '2' ; ans := ans + '1') ) else (if (lis->count(1)->compareTo(lis->count(2))) > 0 then ( ans := '1' ; for i : Integer.subrange(0, lis->count(2)-1) do ( ans := ans + '2' ; ans := ans + '1') ) else ( ans := '2' ; for i : Integer.subrange(0, lis->count(1)-1) do ( ans := ans + '1' ; ans := ans + '2') ) ) ; execute (ans)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def survival(S,N,M): if(((N*6)<(M*7)and S>6)or M>N): print("No") else : days=(M*S)/N if(((M*S)% N)!=0): days+=1 print("Yes "), print(days) S=10 ; N=16 ; M=2 survival(S,N,M) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; S := 10; N := 16; M := 2 ; survival(S, N, M); operation survival(S : OclAny, N : OclAny, M : OclAny) pre: true post: true activity: if ((((N * 6)->compareTo((M * 7))) < 0 & S > 6) or (M->compareTo(N)) > 0) then ( execute ("No")->display() ) else ( var days : double := (M * S) / N ; if (((M * S) mod N) /= 0) then ( days := days + 1 ) else skip ; (testlist_star_expr (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Yes "))))))) ))))))) ,) ; execute (days)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in ' '*int(input()): s=input(); print('YES' if not len(s)& 1 and s[0]!=')' and s[-1]!='(' else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : StringLib.nCopies(' ', ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var s : String := (OclFile["System.in"]).readLine(); execute (if not(MathLib.bitwiseAnd((s)->size(), 1)) & s->first() /= ')' & s->last() /= '(' then 'YES' else 'NO' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): s=input() n=len(s) a=[s[i]for i in range(n)] cnt=n//2-1 for j in range(n): if a[j]=='?' : if cnt>0 : cnt-=1 a[j]='(' else : a[j]=')' bal=0 minbal=0 for j in range(n): if a[j]=='(' : bal+=1 else : bal-=1 minbal=min(bal,minbal) print('YES' if bal==0 and minbal>=0 else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var n : int := (s)->size() ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (s[i+1])) ; var cnt : double := n div 2 - 1 ; for j : Integer.subrange(0, n-1) do ( if a[j+1] = '?' then ( if cnt > 0 then ( cnt := cnt - 1 ; a[j+1] := '(' ) else ( a[j+1] := ')' ) ) else skip) ; var bal : int := 0 ; var minbal : int := 0 ; for j : Integer.subrange(0, n-1) do ( if a[j+1] = '(' then ( bal := bal + 1 ) else ( bal := bal - 1 ) ; minbal := Set{bal, minbal}->min()) ; execute (if bal = 0 & minbal >= 0 then 'YES' else 'NO' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): s=input() if len(s)% 2 : print("NO") else : if s[0]==")" or s[-1]=="(" : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if (s)->size() mod 2 then ( execute ("NO")->display() ) else ( if s->first() = ")" or s->last() = "(" then ( execute ("NO")->display() ) else ( execute ("YES")->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() lst=list(map(float,input().split())) ds=[] ds.append(0) for i,elem in enumerate(lst[1 :]): ds.append(ds[i]*elem+lst[i]*elem) ans=2*sum(ds)+sum(lst) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var lst : Sequence := ((input().split())->collect( _x | (OclType["double"])->apply(_x) )) ; var ds : Sequence := Sequence{} ; execute ((0) : ds) ; for _tuple : Integer.subrange(1, (lst->tail())->size())->collect( _indx | Sequence{_indx-1, (lst->tail())->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var elem : OclAny := _tuple->at(_indx); execute ((ds[i+1] * elem + lst[i+1] * elem) : ds)) ; var ans : double := 2 * (ds)->sum() + (lst)->sum() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): s=input() if len(s)% 2==0 and s[0]!=')' and s[-1]!='(' : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if (s)->size() mod 2 = 0 & s->first() /= ')' & s->last() /= '(' then ( execute ('Yes')->display() ) else ( execute ('No')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ALPHABET_SIZE=26 indexs=0 class TrieNode : def __init__(self): self.isLeaf=False self.children=[None]*ALPHABET_SIZE def insert(key,root): pCrawl=root for level in range(len(key)): index=ord(key[level])-ord('a') if pCrawl.children[index]==None : pCrawl.children[index]=TrieNode() pCrawl=pCrawl.children[index] pCrawl.isLeaf=True def constructTrie(arr,n,root): for i in range(n): insert(arr[i],root) def countChildren(node): count=0 for i in range(ALPHABET_SIZE): if node.children[i]!=None : count+=1 global indexs indexs=i return count def walkTrie(root): pCrawl=root prefix="" while(countChildren(pCrawl)==1 and pCrawl.isLeaf==False): pCrawl=pCrawl.children[indexs] prefix+=chr(97+indexs) return prefix or-1 def commonPrefix(arr,n,root): constructTrie(arr,n,root) return walkTrie(root) n=4 arr=["geeksforgeeks","geeks","geek","geezer"] root=TrieNode() print(commonPrefix(arr,n,root)) ------------------------------------------------------------ OCL File: --------- class TrieNode { static operation newTrieNode() : TrieNode pre: true post: TrieNode->exists( _x | result = _x ); attribute isLeaf : boolean := false; attribute children : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, ALPHABET_SIZE); operation initialise() : TrieNode pre: true post: true activity: self.isLeaf := false ; self.children := MatrixLib.elementwiseMult(Sequence{ null }, ALPHABET_SIZE); return self; } class FromPython { attribute indexs : OclAny; operation initialise() pre: true post: true activity: var ALPHABET_SIZE : int := 26 ; var indexs : int := 0 ; skip ; skip ; skip ; skip ; skip ; skip ; n := 4 ; arr := Sequence{"geeksforgeeks"}->union(Sequence{"geeks"}->union(Sequence{"geek"}->union(Sequence{ "geezer" }))) ; root := (TrieNode.newTrieNode()).initialise() ; execute (commonPrefix(arr, n, root))->display(); operation insert(key : OclAny, root : OclAny) pre: true post: true activity: var pCrawl : OclAny := root ; for level : Integer.subrange(0, (key)->size()-1) do ( var index : double := (key[level+1])->char2byte() - ('a')->char2byte() ; if pCrawl.children[index+1] = null then ( pCrawl.children[index+1] := (TrieNode.newTrieNode()).initialise() ) else skip ; pCrawl := pCrawl.children[index+1]) ; pCrawl.isLeaf := true; operation constructTrie(arr : OclAny, n : OclAny, root : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( insert(arr[i+1], root)); operation countChildren(node : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, ALPHABET_SIZE-1) do ( if node.children[i+1] /= null then ( count := count + 1 ; skip ; indexs := i ) else skip) ; return count; operation walkTrie(root : OclAny) : OclAny pre: true post: true activity: pCrawl := root ; var prefix : String := "" ; while (countChildren(pCrawl) = 1 & pCrawl.isLeaf = false) do ( pCrawl := pCrawl.children[indexs+1] ; prefix := prefix + (97 + indexs)->byte2char()) ; return if prefix /= "" then prefix else -1 endif; operation commonPrefix(arr : OclAny, n : OclAny, root : OclAny) : OclAny pre: true post: true activity: constructTrie(arr, n, root) ; return walkTrie(root); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) s=input() def solve(first,second): sheep=[] sheep.append(first) sheep.append(second) for i in range(1,n): rep=s[i]=="o" if not rep ^ sheep[i]: sheep.append(sheep[i-1]) else : sheep.append(not sheep[i-1]) if sheep[0]==sheep[-1]: rep=s[0]=="o" same=sheep[-2]==sheep[1] if sheep[0]^ rep!=same : for a in sheep[:-1]: if a : print("S",end="") else : print("W",end="") exit() fir=[True,False] sec=[True,False] for i in fir : for j in sec : solve(i,j) print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; skip ; var fir : Sequence := Sequence{true}->union(Sequence{ false }) ; var sec : Sequence := Sequence{true}->union(Sequence{ false }) ; for i : fir do ( for j : sec do ( solve(i, j))) ; execute (-1)->display(); operation solve(first : OclAny, second : OclAny) pre: true post: true activity: var sheep : Sequence := Sequence{} ; execute ((first) : sheep) ; execute ((second) : sheep) ; for i : Integer.subrange(1, n-1) do ( var rep : boolean := s[i+1] = "o" ; if not(MathLib.bitwiseXor(rep, sheep[i+1])) then ( execute ((sheep[i - 1+1]) : sheep) ) else ( execute ((not(sheep[i - 1+1])) : sheep) )) ; if sheep->first() = sheep->last() then ( rep := s->first() = "o" ; var same : boolean := sheep->front()->last() = sheep[1+1] ; if MathLib.bitwiseXor(sheep->first(), rep) /= same then ( for a : sheep->front() do ( if a then ( execute ("S")->display() ) else ( execute ("W")->display() )) ; exit() ) else skip ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) S=input() start_set=[] start_set.append("SS") start_set.append("SW") start_set.append("WS") start_set.append("WW") def listed_goal_set(i): goal_set=[] if S[i]=="o" : goal_set.append("SSS") goal_set.append("WSW") goal_set.append("WWS") goal_set.append("SWW") else : goal_set.append("WSS") goal_set.append("SSW") goal_set.append("WWW") goal_set.append("SWS") return goal_set goal_set1=listed_goal_set(0) goal_set2=listed_goal_set(-1) isok=False for st in start_set : O=[] O.append(st[0]) O.append(st[1]) for i in range(1,N-1): if O[i-1]=="S" : if O[i]=="S" : if S[i]=="o" : O.append("S") else : O.append("W") else : if S[i]=="o" : O.append("W") else : O.append("S") if O[i-1]=="W" : if O[i]=="S" : if S[i]=="o" : O.append("W") else : O.append("S") else : if S[i]=="o" : O.append("S") else : O.append("W") goals1=O[-1]+O[0]+O[1] goals2=O[-2]+O[-1]+O[0] if goals1 in goal_set1 and goals2 in goal_set2 : isok=True break if isok : print("".join(O)) else : print("-1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : String := (OclFile["System.in"]).readLine() ; var start_set : Sequence := Sequence{} ; execute (("SS") : start_set) ; execute (("SW") : start_set) ; execute (("WS") : start_set) ; execute (("WW") : start_set) ; skip ; var goal_set1 : OclAny := listed_goal_set(0) ; var goal_set2 : OclAny := listed_goal_set(-1) ; var isok : boolean := false ; for st : start_set do ( var O : Sequence := Sequence{} ; execute ((st->first()) : O) ; execute ((st[1+1]) : O) ; for i : Integer.subrange(1, N - 1-1) do ( if O[i - 1+1] = "S" then ( if O[i+1] = "S" then ( if S[i+1] = "o" then ( execute (("S") : O) ) else ( execute (("W") : O) ) ) else ( if S[i+1] = "o" then ( execute (("W") : O) ) else ( execute (("S") : O) ) ) ) else skip ; if O[i - 1+1] = "W" then ( if O[i+1] = "S" then ( if S[i+1] = "o" then ( execute (("W") : O) ) else ( execute (("S") : O) ) ) else ( if S[i+1] = "o" then ( execute (("S") : O) ) else ( execute (("W") : O) ) ) ) else skip) ; var goals1 : OclAny := O->last() + O->first() + O[1+1] ; var goals2 : OclAny := O->front()->last() + O->last() + O->first() ; if (goal_set1)->includes(goals1) & (goal_set2)->includes(goals2) then ( isok := true ; break ) else skip) ; if isok then ( execute (StringLib.sumStringsWithSeparator((O), ""))->display() ) else ( execute ("-1")->display() ); operation listed_goal_set(i : OclAny) : OclAny pre: true post: true activity: var goal_set : Sequence := Sequence{} ; if S[i+1] = "o" then ( execute (("SSS") : goal_set) ; execute (("WSW") : goal_set) ; execute (("WWS") : goal_set) ; execute (("SWW") : goal_set) ) else ( execute (("WSS") : goal_set) ; execute (("SSW") : goal_set) ; execute (("WWW") : goal_set) ; execute (("SWS") : goal_set) ) ; return goal_set; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) S=list(input()) for a0,a1 in[[1,1],[1,-1],[-1,1],[-1,-1]]: ans=[0]*N ans[0],ans[1]=a0,a1 for i in range(2,N): if S[i-1]=="o" : ans[i]=ans[i-2]*ans[i-1] else : ans[i]=-ans[i-2]*ans[i-1] if S[N-1]=="o" : if ans[0]==ans[N-2]*ans[N-1]: if S[0]=="o" : if ans[1]==ans[N-1]*ans[0]: print("".join(map(lambda x : "S" if x==1 else "W",ans))) exit() else : if ans[1]==-ans[N-1]*ans[0]: print("".join(map(lambda x : "S" if x==1 else "W",ans))) exit() else : if ans[0]==-ans[N-2]*ans[N-1]: if S[0]=="o" : if ans[1]==ans[N-1]*ans[0]: print("".join(map(lambda x : "S" if x==1 else "W",ans))) exit() else : if ans[1]==-ans[N-1]*ans[0]: print("".join(map(lambda x : "S" if x==1 else "W",ans))) exit() print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : Sequence := ((OclFile["System.in"]).readLine())->characters() ; for _tuple : Sequence{Sequence{1}->union(Sequence{ 1 })}->union(Sequence{Sequence{1}->union(Sequence{ -1 })}->union(Sequence{Sequence{-1}->union(Sequence{ 1 })}->union(Sequence{ Sequence{-1}->union(Sequence{ -1 }) }))) do (var _indx : int := 1; var a0 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a1 : OclAny := _tuple->at(_indx); var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var ans->first() : OclAny := null; var ans[1+1] : OclAny := null; Sequence{ans->first(),ans[1+1]} := Sequence{a0,a1} ; for i : Integer.subrange(2, N-1) do ( if S[i - 1+1] = "o" then ( ans[i+1] := ans[i - 2+1] * ans[i - 1+1] ) else ( ans[i+1] := -ans[i - 2+1] * ans[i - 1+1] )) ; if S[N - 1+1] = "o" then ( if ans->first() = ans[N - 2+1] * ans[N - 1+1] then ( if S->first() = "o" then ( if ans[1+1] = ans[N - 1+1] * ans->first() then ( execute (StringLib.sumStringsWithSeparator(((ans)->collect( _x | (lambda x : OclAny in (if x = 1 then "S" else "W" endif))->apply(_x) )), ""))->display() ; exit() ) else skip ) else ( if ans[1+1] = -ans[N - 1+1] * ans->first() then ( execute (StringLib.sumStringsWithSeparator(((ans)->collect( _x | (lambda x : OclAny in (if x = 1 then "S" else "W" endif))->apply(_x) )), ""))->display() ; exit() ) else skip ) ) else skip ) else ( if ans->first() = -ans[N - 2+1] * ans[N - 1+1] then ( if S->first() = "o" then ( if ans[1+1] = ans[N - 1+1] * ans->first() then ( execute (StringLib.sumStringsWithSeparator(((ans)->collect( _x | (lambda x : OclAny in (if x = 1 then "S" else "W" endif))->apply(_x) )), ""))->display() ; exit() ) else skip ) else ( if ans[1+1] = -ans[N - 1+1] * ans->first() then ( execute (StringLib.sumStringsWithSeparator(((ans)->collect( _x | (lambda x : OclAny in (if x = 1 then "S" else "W" endif))->apply(_x) )), ""))->display() ; exit() ) else skip ) ) else skip )) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=['1','2'] for i in range(2,1000,3): a.append(a[i-1]+'1') a.append('1'+a[i]) a.append('2'+a[i-2]+'2') for _ in range(int(input())): print(a[int(input())-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Sequence{'1'}->union(Sequence{ '2' }) ; for i : Integer.subrange(2, 1000-1)->select( $x | ($x - 2) mod 3 = 0 ) do ( execute ((a[i - 1+1] + '1') : a) ; execute (('1' + a[i+1]) : a) ; execute (('2' + a[i - 2+1] + '2') : a)) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (a[("" + (((OclFile["System.in"]).readLine())))->toInteger() - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) s=input() xs=[1 if c=='o' else-1 for c in s] dp={l :{r :[0 for _ in range(N+2)]for r in(1,-1)}for l in(1,-1)} for l in(1,-1): for r in(1,-1): dp[l][r][0]=l dp[l][r][1]=r for i in range(2,N+2): dp[l][r][i]=dp[l][r][i-2]*dp[l][r][i-1]*xs[(i-1)% N] def f(l,r): return ''.join('S' if dp[l][r][i]==1 else for i in range(N))DEDENT ans=next((f(l,r)for l in(1,-1)for r in(1,-1)if dp[l][r][N]==l and dp[l][r][N+1]==r),)print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var xs : Sequence := s->characters()->select(c | true)->collect(c | (if c = 'o' then 1 else -1 endif)) ; var dp : Map := Sequence{1, -1}->select(l | true)->collect(l | Map{l |-> Sequence{1, -1}->select(r | true)->collect(r | Map{r |-> Integer.subrange(0, N + 2-1)->select(_anon | true)->collect(_anon | (0))})->unionAll()})->unionAll() ; for l : Sequence{1, -1} do ( for r : Sequence{1, -1} do ( dp[l+1][r+1]->first() := l ; dp[l+1][r+1][1+1] := r ; for i : Integer.subrange(2, N + 2-1) do ( dp[l+1][r+1][i+1] := dp[l+1][r+1][i - 2+1] * dp[l+1][r+1][i - 1+1] * xs[(i - 1) mod N+1]))) ; skip; operation f(l : OclAny, r : OclAny) : OclAny pre: true post: true activity: return ''.join(if dp[l+1][r+1][i+1] = 1 then 'S' else (test for (logical_test (comparison (comparison (expr (atom (name i)))) in (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))) endif) ; ; var ans : OclAny := ((arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name f)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l))))))) , (argument (test (logical_test (comparison (expr (atom (name r)))))))) ))))))) (comp_for for (exprlist (expr (atom (name l)))) in (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1))))))) , (test (logical_test (comparison (expr (atom - (number (integer 1)))))))) ))))) (comp_iter (comp_for for (exprlist (expr (atom (name r)))) in (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1))))))) , (test (logical_test (comparison (expr (atom - (number (integer 1)))))))) ))))) (comp_iter if (test (logical_test (logical_test (comparison (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name l)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name N)))))))) ])))) == (comparison (expr (atom (name l)))))) and (logical_test (comparison (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name l)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name N))) + (expr (atom (number (integer 1)))))))))) ])))) == (comparison (expr (atom (name r))))))))))))) ))))))) ,)).next() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(a : int,b : int)->list : ret,cur,prev=[],a,b for i in S : ret+=[cur] if cur ^(i=="o"): prev,cur=cur,prev ^ 1 else : prev,cur=cur,prev flg=cur==a and prev==b return ret if flg else[] def main(): global S N=int(input()) S=input().rstrip() for a in range(2): for b in range(2): ans=check(a,b) if ans : print("".join("S" if i else "W" for i in ans),sep="") return print(-1) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute S : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation check(a : int, b : int) : Sequence pre: true post: true activity: var ret : OclAny := null; var cur : OclAny := null; var prev : OclAny := null; Sequence{ret,cur,prev} := Sequence{Sequence{},a,b} ; for i : S do ( ret := ret + Sequence{ cur } ; if MathLib.bitwiseXor(cur, (i = "o")) then ( var prev : OclAny := null; var cur : OclAny := null; Sequence{prev,cur} := Sequence{cur,MathLib.bitwiseXor(prev, 1)} ) else ( var prev : OclAny := null; var cur : OclAny := null; Sequence{prev,cur} := Sequence{cur,prev} )) ; var flg : boolean := cur = a & prev = b ; return if flg then ret else Sequence{} endif; operation main() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; S := input().rstrip() ; for a : Integer.subrange(0, 2-1) do ( for b : Integer.subrange(0, 2-1) do ( var ans : OclAny := check(a, b) ; if ans then ( execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom "S")))) if (logical_test (comparison (expr (atom (name i))))) else (test (logical_test (comparison (expr (atom "W")))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name ans)))))))), ""))->display() ; return ) else skip)) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate from collections import defaultdict,deque def resolve(): N,K=map(int,input().split()) A=list(map(int,input().split())) A=accumulate([a % K for a in A]) A=[0]+list(A) cnt=defaultdict(int) q=deque() ans=0 for r in range(N+1): t=(A[r]-r)% K ans+=cnt[t] cnt[t]+=1 q.append(t) if len(q)==K : left=q.popleft() cnt[left]-=1 print(ans) if __name__=="__main__" : resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( resolve() ) else skip; operation resolve() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; A := accumulate(A->select(a | true)->collect(a | (a mod K))) ; A := Sequence{ 0 }->union((A)) ; var cnt : OclAny := defaultdict(OclType["int"]) ; var q : Sequence := () ; var ans : int := 0 ; for r : Integer.subrange(0, N + 1-1) do ( var t : int := (A[r+1] - r) mod K ; ans := ans + cnt[t+1] ; cnt[t+1] := cnt[t+1] + 1 ; execute ((t) : q) ; if (q)->size() = K then ( var left : OclAny := q->first() ; q := q->tail() ; cnt[left+1] := cnt[left+1] - 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from queue import Queue from collections import defaultdict n,k=map(int,input().split()) a=list(map(int,input().split())) for i in range(n): a[i]-=1 s=[0]*(n+1) for i in range(n): s[i+1]=(s[i]+a[i])% k d=defaultdict(int) ans=0 q=Queue() for j in range(n+1): ans+=d[s[j]] d[s[j]]+=1 q.put(s[j]) if q.qsize()==k : d[q.get()]-=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( a[i+1] := a[i+1] - 1) ; var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(0, n-1) do ( s[i + 1+1] := (s[i+1] + a[i+1]) mod k) ; var d : OclAny := defaultdict(OclType["int"]) ; var ans : int := 0 ; var q : OclAny := Queue() ; for j : Integer.subrange(0, n + 1-1) do ( ans := ans + d[s[j+1]+1] ; d[s[j+1]+1] := d[s[j+1]+1] + 1 ; q.put(s[j+1]) ; if q.qsize() = k then ( d[q.get()+1] := d[q.get()+1] - 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): from itertools import accumulate from sys import stdin f_i=stdin N,K=map(int,f_i.readline().split()) A=map(int,f_i.readline().split()) S=accumulate(a-1 for a in A) S=(0,)+tuple(s % K for s in S) rec={} ans=0 for j,S_j in enumerate(S): if j>=K : rec[S[j-K]]-=1 if S_j in rec : ans+=rec[S_j] rec[S_j]+=1 else : rec[S_j]=1 print(ans) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: skip ; skip ; var f_i : OclAny := stdin ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (f_i.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := (f_i.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : OclAny := accumulate((argument (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name A)))))))) ; S := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) ,)}->union(((argument (test (logical_test (comparison (expr (expr (atom (name s))) % (expr (atom (name K))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name S))))))))) ; var rec : OclAny := Set{} ; var ans : int := 0 ; for _tuple : Integer.subrange(1, (S)->size())->collect( _indx | Sequence{_indx-1, (S)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var S_j : OclAny := _tuple->at(_indx); if (j->compareTo(K)) >= 0 then ( rec[S[j - K+1]+1] := rec[S[j - K+1]+1] - 1 ) else skip ; if (rec)->includes(S_j) then ( ans := ans + rec[S_j+1] ; rec[S_j+1] := rec[S_j+1] + 1 ) else ( rec[S_j+1] := 1 )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=list(map(float,input().split())) val=[0.0] for j in range(n): val.append((val[-1]+1.0)*p[j]) dp=[0 for i in range(n+1)] for i in range(1,n+1): dp[i]=p[i-1]*(1.0+dp[i-1]+2*val[i-1])+(1-p[i-1])*(dp[i-1]) print(dp[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["double"])->apply(_x) )) ; var val : Sequence := Sequence{ 0.0 } ; for j : Integer.subrange(0, n-1) do ( execute (((val->last() + 1.0) * p[j+1]) : val)) ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(1, n + 1-1) do ( dp[i+1] := p[i - 1+1] * (1.0 + dp[i - 1+1] + 2 * val[i - 1+1]) + (1 - p[i - 1+1]) * (dp[i - 1+1])) ; execute (dp->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque import sys,heapq,bisect,math,itertools,string,queue,copy,time sys.setrecursionlimit(10**8) INF=float('inf') mod=10**9+7 eps=10**-7 def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int,sys.stdin.readline().split())) def inpl_str(): return list(sys.stdin.readline().split()) N,K=inpl() AA=inpl() rAA=[0] for a in AA : rAA.append(rAA[-1]+a) AA=[(A+N-i)% K for i,A in enumerate(rAA)] cnts=defaultdict(int) ans=0 for i,a in enumerate(AA): if i>=K : cnts[AA[i-K]]-=1 ans+=cnts[a] cnts[a]+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var eps : double := (10)->pow(-7) ; skip ; skip ; skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := inpl() ; var AA : OclAny := inpl() ; var rAA : Sequence := Sequence{ 0 } ; for a : AA do ( execute ((rAA->last() + a) : rAA)) ; AA := Integer.subrange(1, (rAA)->size())->collect( _indx | Sequence{_indx-1, (rAA)->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let A : OclAny = _tuple->at(2) in ((A + N - i) mod K)) ; var cnts : OclAny := defaultdict(OclType["int"]) ; var ans : int := 0 ; for _tuple : Integer.subrange(1, (AA)->size())->collect( _indx | Sequence{_indx-1, (AA)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); if (i->compareTo(K)) >= 0 then ( cnts[AA[i - K+1]+1] := cnts[AA[i - K+1]+1] - 1 ) else skip ; ans := ans + cnts[a+1] ; cnts[a+1] := cnts[a+1] + 1) ; execute (ans)->display(); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inpl() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inpl_str() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from collections import deque N,K=map(int,input().split()) A=list(map(int,input().split())) B=[0] for a in A : b=(B[-1]+(a-1))% K B.append(b) ans=0 dic={} for i,b in enumerate(B): if b in dic : dic[b].append(i) else : dic[b]=deque() dic[b].append(i) while len(dic[b])>0 and dic[b][0]<=i-K : dic[b].popleft() ans+=len(dic[b])-1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var B : Sequence := Sequence{ 0 } ; for a : A do ( var b : int := (B->last() + (a - 1)) mod K ; execute ((b) : B)) ; var ans : int := 0 ; var dic : OclAny := Set{} ; for _tuple : Integer.subrange(1, (B)->size())->collect( _indx | Sequence{_indx-1, (B)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if (dic)->includes(b) then ( (expr (atom (name dic)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ) else ( dic[b+1] := () ; (expr (atom (name dic)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ) ; while (dic[b+1])->size() > 0 & (dic[b+1]->first()->compareTo(i - K)) <= 0 do ((expr (atom (name dic)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name popleft) (arguments ( ))))) ; ans := ans + (dic[b+1])->size() - 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- z=list(map(int,input().split(' '))) n=z[0] k=z[1] if ncollect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := z->first() ; var k : OclAny := z[1+1] ; if (n->compareTo(k)) < 0 then ( execute (n + k)->display() ) else ( for i : Integer.subrange(0 + 1, k - 1)->reverse() do ( if n mod i = 0 then ( execute (("" + (((n * k / i) + i)))->toInteger())->display() ; break ) else skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(map(int,input().split())) n=s[0] k=s[1] nums=[] for i in range(1,k): if n % i==0 : nums.append(n//i*k+i % k) print(min(nums)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := s->first() ; var k : OclAny := s[1+1] ; var nums : Sequence := Sequence{} ; for i : Integer.subrange(1, k-1) do ( if n mod i = 0 then ( execute ((n div i * k + i mod k) : nums) ) else skip) ; execute ((nums)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findOptimalSolution(a,N): a.sort() points=0 for i in range(0,N): points+=a[i]*i return points if __name__=="__main__" : a=[1,4,2,3,9] N=len(a) print(findOptimalSolution(a,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{1}->union(Sequence{4}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 9 })))) ; N := (a)->size() ; execute (findOptimalSolution(a, N))->display() ) else skip; operation findOptimalSolution(a : OclAny, N : OclAny) : OclAny pre: true post: true activity: a := a->sort() ; var points : int := 0 ; for i : Integer.subrange(0, N-1) do ( points := points + a[i+1] * i) ; return points; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- temp=list(map(int,input().strip().split())) n,k=temp[0],temp[1] minn=2147483647 for r in range(1,k): if n % r==0 : x=((k*n)/r)+r if xtrim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := Sequence{temp->first(),temp[1+1]} ; var minn : int := 2147483647 ; for r : Integer.subrange(1, k-1) do ( if n mod r = 0 then ( var x : double := ((k * n) / r) + r ; if (x->compareTo(minn)) < 0 then ( minn := x ) else skip ) else skip) ; execute (("" + ((minn)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- nk=list(map(int,input().split())) for i in range(1,nk[0]+1): if(nk[0]% i==0)and(nk[0]/icollect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(1, nk->first() + 1-1) do ( if (nk->first() mod i = 0) & ((nk->first() / i->compareTo(nk[1+1])) < 0) then ( execute (("" + ((nk[1+1] * i + (nk->first() / i))))->toInteger())->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=list(map(int,input().split())) c=0 i=1 while c==0 : t=k*(i)+n//i if(t//k)*(t % k)==n : c+=1 else : c=0 i+=1 print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; var i : int := 1 ; while c = 0 do ( var t : double := k * (i) + n div i ; if (t div k) * (t mod k) = n then ( c := c + 1 ) else ( c := 0 ) ; i := i + 1) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- outfile="output.txt" def popinput(input): return int(input.readline().split()[0]) def solve(file): input=open(file,'r') output=open(outfile,'w') cases=popinput(input) for i in range(cases): output.write("Case #%(number)d: %(answer)s\n" %{"number" : i+1,"answer" : solvecase(input)}) print('Case solved:',i) def solvecase(input): n=popinput(input) highest=list(map(int,input.readline().split())) height={} height[n]=1000000000 height[n-1]=999900000 for i in range(1,n): for j in range(i+1,highest[i-1]): if highest[j-1]>highest[i-1]: return 'Impossible' for i in range(2,n): j=n-i a=highest[j-1] if a==n : height[j]=height[a]-100000*i+2*(i-1)+1 else : print(a) b=highest[a-1] c=height[a]-(height[b]-height[a])*(a-j)/(b-a) height[j]=c-4 height=list(map(int,height.values())) return str.replace(str(height).strip('[]'),',','') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var outfile : String := "output.txt" ; skip ; skip ; skip; operation popinput(input : OclAny) : OclAny pre: true post: true activity: return ("" + ((input.readLine().split()->first())))->toInteger(); operation solve(file : OclAny) pre: true post: true activity: input := OclFile.newOclFile_Write(OclFile.newOclFile(file)) ; var output : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(outfile)) ; var cases : OclAny := popinput(input) ; for i : Integer.subrange(0, cases-1) do ( output.write(StringLib.format("Case #%(number)d: %(answer)s\n",Map{ "number" |-> i + 1 }->union(Map{ "answer" |-> solvecase(input) }))) ; execute ('Case solved:')->display()); operation solvecase(input : OclAny) : OclAny pre: true post: true activity: var n : OclAny := popinput(input) ; var highest : Sequence := ((input.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var height : OclAny := Set{} ; height[n+1] := 1000000000 ; height[n - 1+1] := 999900000 ; for i : Integer.subrange(1, n-1) do ( for j : Integer.subrange(i + 1, highest[i - 1+1]-1) do ( if (highest[j - 1+1]->compareTo(highest[i - 1+1])) > 0 then ( return 'Impossible' ) else skip)) ; for i : Integer.subrange(2, n-1) do ( var j : double := n - i ; var a : OclAny := highest[j - 1+1] ; if a = n then ( height[j+1] := height[a+1] - 100000 * i + 2 * (i - 1) + 1 ) else ( execute (a)->display() ; var b : OclAny := highest[a - 1+1] ; var c : double := height[a+1] - (height[b+1] - height[a+1]) * (a - j) / (b - a) ; height[j+1] := c - 4 )) ; height := ((height.values())->collect( _x | (OclType["int"])->apply(_x) )) ; return ("" + (.replace(OclType["String"](height)->trim(), ',', ''))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- testCount=int(raw_input()) for testIndex in range(testCount): ans="Case #"+str(testIndex+1)+": " n=int(raw_input()) see=[int(x)-1 for x in raw_input().split(" ")] m=[n-1]*n cm=0 for i in range(n-1): if i>=m[cm]: cm-=1 if see[i]>m[cm]: ans+="Impossible" break if see[i]toInteger() ; for testIndex : Integer.subrange(0, testCount-1) do ( var ans : String := "Case #" + ("" + ((testIndex + 1))) + ": " ; var n : int := ("" + ((raw_input())))->toInteger() ; var see : Sequence := raw_input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)) ; var m : Sequence := MatrixLib.elementwiseMult(Sequence{ n - 1 }, n) ; var cm : int := 0 ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name i)))) >= (comparison (expr (atom (name m)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name cm)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cm)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name see)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) > (comparison (expr (atom (name m)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name cm)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom "Impossible")))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name see)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) < (comparison (expr (atom (name m)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name cm)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cm)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name m)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name cm)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name see)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name height)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr (atom (name n))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name count)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom - (number (integer 1)))))))) ])) * (expr (atom (name n))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name see))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name count)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name angle)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr (atom (name n))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (atom - (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name angle)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name count)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name see)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ]))) + (expr (atom (name angle)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name see)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ]))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name count)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name see)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name height)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name see)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name i)))))))) ))) * (expr (atom (name angle)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) + (expr (atom (name height)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name see)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name m)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name height)))))))) ))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name height))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name m))) - (expr (atom (name i))))))))) )))) + (expr (atom " "))))))))))))))))) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import fractions f=fractions.Fraction def rat(a,b): if v[a]==v[b]: return 0 return f(v[b]-v[a],b-a) cases=int(input()) for case in range(cases): N=int(input()) x=list(int(s)-1 for s in input().split()) possible=True for i,xi in enumerate(x): if xi>i+1 : if max(x[i+1 : xi])>xi : possible=False break if not possible : print("Case #{}:{}".format(case+1,"Impossible")) continue v=[1]*N cg=True while cg : cg=False for i,xi in enumerate(x): cl=True while cl : cl=False if xi-i>1 : while rat(i,xi)<=max(rat(i,j)for j in range(i+1,xi)): v[xi]+=1 cg=cl=True if N-xi>1 : while rat(i,xi)toInteger() ; for case : Integer.subrange(0, cases-1) do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))) - (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ; var possible : boolean := true ; for _tuple : Integer.subrange(1, (x)->size())->collect( _indx | Sequence{_indx-1, (x)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var xi : OclAny := _tuple->at(_indx); if (xi->compareTo(i + 1)) > 0 then ( if ((x.subrange(i + 1+1, xi))->max()->compareTo(xi)) > 0 then ( possible := false ; break ) else skip ) else skip) ; if not(possible) then ( execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{case + 1, "Impossible"}))->display() ; continue ) else skip ; var v : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, N) ; var cg : boolean := true ; while cg do ( cg := false ; for _tuple : Integer.subrange(1, (x)->size())->collect( _indx | Sequence{_indx-1, (x)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var xi : OclAny := _tuple->at(_indx); var cl : boolean := true ; while cl do ( cl := false ; if xi - i > 1 then ( while (rat(i, xi)->compareTo(((argument (test (logical_test (comparison (expr (atom (name rat)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (name j)))))))) ))))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name xi)))))))) )))))))))->max())) <= 0 do ( v[xi+1] := v[xi+1] + 1 ; cg := true; cl := true) ) else skip ; if N - xi > 1 then ( while (rat(i, xi)->compareTo(((argument (test (logical_test (comparison (expr (atom (name rat)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (name j)))))))) ))))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name xi))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))))->max())) < 0 do ( v[xi+1] := v[xi+1] + 1 ; cg := true; cl := true) ) else skip))) ; execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{case + 1, StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name vi)))))))) ))))))) (comp_for for (exprlist (expr (atom (name vi)))) in (logical_test (comparison (expr (atom (name v)))))))), " ")}))->display()); operation rat(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if v[a+1] = v[b+1] then ( return 0 ) else skip ; return f(v[b+1] - v[a+1], b - a); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : n=int(input()) nums=input().split(" ") a=0.0 sol=0 for i in range(n): a=a*float(nums[i]) sol+=2*a+float(nums[i]) a+=float(nums[i]) print(sol) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nums : OclAny := input().split(" ") ; var a : double := 0.0 ; var sol : int := 0 ; for i : Integer.subrange(0, n-1) do ( a := a * ("" + ((nums[i+1])))->toReal() ; sol := sol + 2 * a + ("" + ((nums[i+1])))->toReal() ; a := a + ("" + ((nums[i+1])))->toReal()) ; execute (sol)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) C=list(input()) RCnt=C.count("R") RCnt2=C[: RCnt].count("R") print(RCnt-RCnt2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var C : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var RCnt : int := C->count("R") ; var RCnt2 : OclAny := C.subrange(1,RCnt)->count("R") ; execute (RCnt - RCnt2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) S=input() c_w=0 c_r=0 for i in range(len(S)): if S[i]=='W' : c_w+=1 else : c_r+=1 p_1=c_w p_2=c_r p_3=0 for i in range(c_r): if S[i]=='W' : p_3+=1 print(min(p_1,p_2,p_3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : String := (OclFile["System.in"]).readLine() ; var c_w : int := 0 ; var c_r : int := 0 ; for i : Integer.subrange(0, (S)->size()-1) do ( if S[i+1] = 'W' then ( c_w := c_w + 1 ) else ( c_r := c_r + 1 )) ; var p var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() : int := c_w ; var p:= c_r : int := c_r ; var p_3 : int := 0 ; for i : Integer.subrange(0, c_r-1) do ( if S[i+1] = 'W' then ( p_3 := p_3 + 1 ) else skip) ; execute (Set{p(p(pSet{p(p(p(Set{p(p(p(Set{p(p(p(Set{p(p(pSet{p(p(p(Set{p(p(p(Set{p(p(p(Set{p(p(pSet{p(p(p(Set{p(p(p(Set{p(p(p(Set{p(p(pSet{p(p(p(Set{p(p(p(Set{p(p(p(Set{p(p(pSet{p(p(p(Set{p(p(p(Set{p(p(p(Set{p(p(pSet{p(p(p(Set{p(p(p(Set{p(p(p(Set{p(p(pSet{p(p(p(Set{p(p(p(Set{p(p(p var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(), p_2, p_3), p_2, p_3), p_2, p_3}->min()), p_2, p_3), p_2, p_3), p_2, p_3}->min()), p_2, p_3), p_2, p_3), p_2, p_3}->min(), p_2, p_3), p_2, p_3), p_2, p_3}->min())->display(), p_2, p_3), p_2, p_3), p_2, p_3}->min()), p_2, p_3), p_2, p_3), p_2, p_3}->min()), p_2, p_3), p_2, p_3), p_2, p_3}->min(), p_2, p_3), p_2, p_3), p_2, p_3}->min())->display(), p_2, p_3), p_2, p_3), p_2, p_3}->min()), p_2, p_3), p_2, p_3), p_2, p_3}->min()), p_2, p_3), p_2, p_3), p_2, p_3}->min(), p_2, p_3), p_2, p_3), p_2, p_3}->min())->display(), p_2, p_3), p_2, p_3), p_2, p_3}->min()), p_2, p_3), p_2, p_3), p_2, p_3}->min()), p_2, p_3), p_2, p_3), p_2, p_3}->min(), p_2, p_3), p_2, p_3), p_2, p_3}->min())->display(), p_2, p_3), p_2, p_3), p_2, p_3}->min()), p_2, p_3), p_2, p_3), p_2, p_3}->min()), p_2, p_3), p_2, p_3), p_2, p_3}->min(), p_2, p_3), p_2, p_3), p_2, p_3}->min())->display(), p_2, p_3), p_2, p_3), p_2, p_3}->min()), p_2, p_3), p_2, p_3), p_2, p_3}->min()), p_2, p_3), p_2, p_3), p_2, p_3}->min(), p_2, p_3), p_2, p_3), p_2, p_3}->min())->display(), p_2, p_3), p_2, p_3), p_2, p_3}->min()), p_2, p_3), p_2, p_3), p_2, p_3}->min()), p_2, p_3), p_2, p_3), p_2, p_3}->min(), p_2, p_3), p_2, p_3), p_2, p_3}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) c=input() idxl=-1 idxr=N cnt=0 while(1): while(1): idxl=idxl+1 if(idxl>=N): break if(c[idxl]=="W"): break if(idxl>=N): break while(1): idxr=idxr-1 if(idxr<=0): break if(c[idxr]=="R"): break if(idxr<=0): break if(idxl>=idxr): break ; cnt=cnt+1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : String := (OclFile["System.in"]).readLine() ; var idxl : int := -1 ; var idxr : int := N ; var cnt : int := 0 ; while (1) do ( while (1) do ( idxl := idxl + 1 ; if ((idxl->compareTo(N)) >= 0) then ( break ) else skip ; if (c[idxl+1] = "W") then ( break ) else skip) ; if ((idxl->compareTo(N)) >= 0) then ( break ) else skip ; while (1) do ( idxr := idxr - 1 ; if (idxr <= 0) then ( break ) else skip ; if (c[idxr+1] = "R") then ( break ) else skip) ; if (idxr <= 0) then ( break ) else skip ; if ((idxl->compareTo(idxr)) >= 0) then ( break; ) else skip ; cnt := cnt + 1) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,b=map(int,input().split()) time=0 queue=[] for i in range(n): t,d=map(int,input().split()) while len(queue)!=0 and t>=queue[0]: queue.pop(0) if len(queue)<=b : time=max(t,time)+d queue.append(time) print(time,end=" ") else : print(-1,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var b : OclAny := null; Sequence{n,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var time : int := 0 ; var queue : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var t : OclAny := null; var d : OclAny := null; Sequence{t,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; while (queue)->size() /= 0 & (t->compareTo(queue->first())) >= 0 do ( queue := queue->excludingAt(0+1)) ; if ((queue)->size()->compareTo(b)) <= 0 then ( time := Set{t, time}->max() + d ; execute ((time) : queue) ; execute (time)->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import Counter N=int(sys.stdin.readline().strip()) C=sys.stdin.readline().strip() counter=Counter(C) if len(counter)==1 : print(0) sys.exit() limit=counter["R"] ok=0 for i in range(limit): if C[i]=="R" : ok+=1 print(limit-ok) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := ("" + ((sys.stdin.readLine()->trim())))->toInteger() ; var C : OclAny := sys.stdin.readLine()->trim() ; var counter : OclAny := Counter(C) ; if (counter)->size() = 1 then ( execute (0)->display() ; sys.exit() ) else skip ; var limit : OclAny := counter->at("R") ; var ok : int := 0 ; for i : Integer.subrange(0, limit-1) do ( if C[i+1] = "R" then ( ok := ok + 1 ) else skip) ; execute (limit - ok)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): import sys pin=sys.stdin.readline pout=sys.stdout.write perr=sys.stderr.write N=int(pin()) c=pin()[:-1] r=0 w=0 for i in c : if i=="R" : r+=1 else : w+=1 nL=0 nR=r num=max(nL,nR) for i in c : if i=="R" : nR-=1 else : nL+=1 if num>max(nL,nR): num=max(nL,nR) print(num) return main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: skip ; var pin : OclAny := (OclFile["System.in"]).readline ; var pout : OclAny := (OclFile["System.out"]).write ; var perr : OclAny := (OclFile["System.err"]).write ; var N : int := ("" + ((pin())))->toInteger() ; var c : OclAny := pin()->front() ; var r : int := 0 ; var w : int := 0 ; for i : c do ( if i = "R" then ( r := r + 1 ) else ( w := w + 1 )) ; var nL : int := 0 ; var nR : int := r ; var num : OclAny := Set{nL, nR}->max() ; for i : c do ( if i = "R" then ( nR := nR - 1 ) else ( nL := nL + 1 ) ; if (num->compareTo(Set{nL, nR}->max())) > 0 then ( num := Set{nL, nR}->max() ) else skip) ; execute (num)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def addBinaryUtil(a,b): result="" ; s=0 ; i=len(a)-1 ; j=len(b)-1 ; while(i>=0 or j>=0 or s==1): s+=(ord(a[i])-ord('0'))if(i>=0)else 0 ; s+=(ord(b[j])-ord('0'))if(j>=0)else 0 ; result=chr(s % 2+ord('0'))+result ; s//=2 ; i-=1 ; j-=1 ; return result ; def addBinary(arr,n): result="" ; for i in range(n): result=addBinaryUtil(result,arr[i]); return result ; arr=["1","10","11"]; n=len(arr); print(addBinary(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{"1"}->union(Sequence{"10"}->union(Sequence{ "11" })); ; n := (arr)->size(); ; execute (addBinary(arr, n))->display();; operation addBinaryUtil(a : OclAny, b : OclAny) pre: true post: true activity: var result : String := ""; ; var s : int := 0; ; var i : double := (a)->size() - 1; ; var j : double := (b)->size() - 1; ; while (i >= 0 or j >= 0 or s = 1) do ( s := s + if (i >= 0) then ((a[i+1])->char2byte() - ('0')->char2byte()) else 0 endif; ; s := s + if (j >= 0) then ((b[j+1])->char2byte() - ('0')->char2byte()) else 0 endif; ; result := (s mod 2 + ('0')->char2byte())->byte2char() + result; ; s := s div 2; ; i := i - 1; ; j := j - 1;) ; return result;; operation addBinary(arr : OclAny, n : OclAny) pre: true post: true activity: result := ""; ; for i : Integer.subrange(0, n-1) do ( result := addBinaryUtil(result, arr[i+1]);) ; return result;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,m=map(int,input().split()) a=list(map(int,input().split())) cnt=[0]*105 for i in a : cnt[i]+=1 ans=0 while True : x=ans+1 c=0 for i in cnt : c+=i//x if n>c : break ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 105) ; for i : a do ( cnt[i+1] := cnt[i+1] + 1) ; var ans : int := 0 ; while true do ( var x : int := ans + 1 ; var c : int := 0 ; for i : cnt do ( c := c + i div x) ; if (n->compareTo(c)) > 0 then ( break ) else skip ; ans := ans + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=list(map(int,input().split())) d={} for chr in a : if chr not in d : d[chr]=1 else : d[chr]+=1 p=list(d.values()) z=k//n if z==0 : print(0) else : o=[] if len(a)>=n : o.append(1) for i in range(2,z+1): c=0 for j in range(len(p)): c+=p[j]//i if c>=n : o.append(i) print(max(o)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := Set{} ; for chr : a do ( if (d)->excludes(chr) then ( d[chr+1] := 1 ) else ( d[chr+1] := d[chr+1] + 1 )) ; var p : Sequence := (d.values()) ; var z : int := k div n ; if z = 0 then ( execute (0)->display() ) else ( var o : Sequence := Sequence{} ; if ((a)->size()->compareTo(n)) >= 0 then ( execute ((1) : o) ) else skip ; for i : Integer.subrange(2, z + 1-1) do ( var c : int := 0 ; for j : Integer.subrange(0, (p)->size()-1) do ( c := c + p[j+1] div i) ; if (c->compareTo(n)) >= 0 then ( execute ((i) : o) ) else skip) ; execute ((o)->max())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def produs_cifre(numar): produs=1 for i in numar : produs=produs*int(i) return(produs) def functie(nodul,vectorul,cate,culori,vizitat): if vizitat[nodul]==0 : vizitat[nodul]=1 if culori[nodul-1]!=noi_culori[nodul-1]: cate[0]=1+cate[0] noi_culori[nodul-1]=culori[nodul-1] for j in vectorul[nodul]: if vizitat[j]==0 : noi_culori[j-1]=culori[nodul-1] functie(j,vectorul,cate,culori,vizitat) return(sum(cate)) for contor in range(0,1): n,m=list(map(int,input().split())) lista=list(map(int,input().split())) vector=[0]*101 for i in lista : vector[i]+=1 answ=0 for posibil in range(100,-1,-1): cati=0 for j in range(100,-1,-1): if posibil>0 : cati+=vector[j]//posibil if cati>=n : answ=max(answ,posibil) print(answ) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for contor : Integer.subrange(0, 1-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lista : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var vector : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 101) ; for i : lista do ( vector[i+1] := vector[i+1] + 1) ; var answ : int := 0 ; for posibil : Integer.subrange(-1 + 1, 100)->reverse() do ( var cati : int := 0 ; for j : Integer.subrange(-1 + 1, 100)->reverse() do ( if posibil > 0 then ( cati := cati + vector[j+1] div posibil ) else skip) ; if (cati->compareTo(n)) >= 0 then ( answ := Set{answ, posibil}->max() ) else skip) ; execute (answ)->display()); operation produs_cifre(numar : OclAny) : OclAny pre: true post: true activity: var produs : int := 1 ; for i : numar do ( produs := produs * ("" + ((i)))->toInteger()) ; return (produs); operation functie(nodul : OclAny, vectorul : OclAny, cate : OclAny, culori : OclAny, vizitat : OclAny) : OclAny pre: true post: true activity: if vizitat[nodul+1] = 0 then ( vizitat[nodul+1] := 1 ; if culori[nodul - 1+1] /= noi_culori[nodul - 1+1] then ( cate->first() := 1 + cate->first() ; noi_culori[nodul - 1+1] := culori[nodul - 1+1] ) else skip ; for j : vectorul[nodul+1] do ( if vizitat[j+1] = 0 then ( noi_culori[j - 1+1] := culori[nodul - 1+1] ; functie(j, vectorul, cate, culori, vizitat) ) else skip) ) else skip ; return ((cate)->sum()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from collections import Counter n,m=map(int,input().split()) c=Counter() for i in map(int,input().split()): c[i]+=1 d=0 while 1 : x=n for i in c : x-=c[i]//(d+1) if x<=0 : break if x<=0 : d+=1 else : break print(d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : OclAny := Counter() ; for i : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( c[i+1] := c[i+1] + 1) ; var d : int := 0 ; while 1 do ( var x : OclAny := n ; for i : c do ( x := x - c[i+1] div (d + 1) ; if x <= 0 then ( break ) else skip) ; if x <= 0 then ( d := d + 1 ) else ( break )) ; execute (d)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isBinary(number): while(number>0): digit=number % 10 if(digit>1): return False number//=10 return True if __name__=="__main__" : n=1000111 if(isBinary(n)==1): print("true") else : print("false") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var n : int := 1000111 ; if (isBinary(n) = 1) then ( execute ("true")->display() ) else ( execute ("false")->display() ) ) else skip; operation isBinary(number : OclAny) : OclAny pre: true post: true activity: while (number > 0) do ( var digit : int := number mod 10 ; if (digit > 1) then ( return false ) else skip ; number := number div 10) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ModifiedSieveOfEratosthenes(N,Expo_Prime): primes=[True]*N ; for i in range(2,N): if(primes[i]): no=i ; while(no<=N): Expo_Prime[no]=True ; no*=i ; for j in range(i*i,N,i): primes[j]=False ; def Display(arr,Expo_Prime,n): for i in range(n): if(Expo_Prime[arr[i]]): print(arr[i],end=" "); def FindExpoPrime(arr,n): max=0 ; for i in range(n): if(maxunion(Sequence{6}->union(Sequence{9}->union(Sequence{16}->union(Sequence{1}->union(Sequence{3}->union(Sequence{12}->union(Sequence{36}->union(Sequence{625}->union(Sequence{ 1000 }))))))))); ; n := (arr)->size(); ; FindExpoPrime(arr, n); ) else skip; operation ModifiedSieveOfEratosthenes(N : OclAny, Expo_Prime : OclAny) pre: true post: true activity: var primes : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, N); ; for i : Integer.subrange(2, N-1) do ( if (primes[i+1]) then ( var no : OclAny := i; ; while ((no->compareTo(N)) <= 0) do ( Expo_Prime[no+1] := true; ; no := no * i;) ; for j : Integer.subrange(i * i, N-1)->select( $x | ($x - i * i) mod i = 0 ) do ( primes[j+1] := false;) ) else skip); operation Display(arr : OclAny, Expo_Prime : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if (Expo_Prime[arr[i+1]+1]) then ( execute (arr[i+1])->display(); ) else skip); operation FindExpoPrime(arr : OclAny, n : OclAny) pre: true post: true activity: var max : int := 0; ; for i : Integer.subrange(0, n-1) do ( if ((max->compareTo(arr[i+1])) < 0) then ( max := arr[i+1]; ) else skip) ; Expo_Prime := MatrixLib.elementwiseMult(Sequence{ false }, (max + 1)); ; ModifiedSieveOfEratosthenes(max + 1, Expo_Prime); ; Display(arr, Expo_Prime, n);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=list(map(float,input().split())) score=0 length=0 for i in p : score+=(2*length+1)*i length=(length+1)*i print("%.15f" % score) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["double"])->apply(_x) )) ; var score : int := 0 ; var length : int := 0 ; for i : p do ( score := score + (2 * length + 1) * i ; length := (length + 1) * i) ; execute (StringLib.format("%.15f",score))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import queue n,b=list(map(int,input().split())) class Task : def __init__(self,time : int,duration : int,index : int)->None : super().__init__() self.time=time self.duration=duration self.index=index remaining=queue.Queue() running=False finish_time=0 def run_task(remaining : queue.Queue,finish_time : int): task_to_run=remaining.get() finish_time=max(finish_time,task_to_run.time)+task_to_run.duration result[task_to_run.index]=finish_time return finish_time,result result={} for i in range(n): time,duration=list(map(int,input().split())) task=Task(time,duration,index=i) result.update({i : 0}) if task.time>finish_time and remaining.empty(): running=True finish_time=task.time+task.duration result[i]=finish_time else : if task.time>=finish_time and not remaining.empty(): finish_time,result=run_task(remaining=remaining,finish_time=finish_time) if remaining.qsize()exists( _x | result = _x ); operation __init__(time : int,duration : int,index : int) : OclAny pre: true post: true activity: (expr (atom (name super)) (trailer (arguments ( ))) (trailer . (name __init__) (arguments ( )))) ; self.time := time ; self.duration := duration ; self.index := index; } class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var b : OclAny := null; Sequence{n,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; var remaining : OclAny := queue.Queue() ; var running : boolean := false ; var finish_time : int := 0 ; skip ; var result : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var time : OclAny := null; var duration : OclAny := null; Sequence{time,duration} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var task : Task := (Task.newTask()).initialise(time, duration, (argument (test (logical_test (comparison (expr (atom (name index)))))) = (test (logical_test (comparison (expr (atom (name i)))))))) ; execute ((Map{ i |-> 0 }) <: result) ; if (task.time->compareTo(finish_time)) > 0 & remaining.empty() then ( running := true ; finish_time := task.time + task.duration ; result[i+1] := finish_time ) else ( if (task.time->compareTo(finish_time)) >= 0 & not(remaining.empty()) then ( Sequence{finish_time,result} := run_task((argument (test (logical_test (comparison (expr (atom (name remaining)))))) = (test (logical_test (comparison (expr (atom (name remaining))))))), (argument (test (logical_test (comparison (expr (atom (name finish_time)))))) = (test (logical_test (comparison (expr (atom (name finish_time)))))))) ) else skip ; if (remaining.qsize()->compareTo(b)) < 0 then ( remaining.put(task) ) else ( result[i+1] := -1 ) )) ; while not(remaining.empty()) do ( Sequence{finish_time,result} := run_task((argument (test (logical_test (comparison (expr (atom (name remaining)))))) = (test (logical_test (comparison (expr (atom (name remaining))))))), (argument (test (logical_test (comparison (expr (atom (name finish_time)))))) = (test (logical_test (comparison (expr (atom (name finish_time))))))))) ; for key : result do ( execute (result.get(key))->display()); operation run_task(remaining : queue.Queue, finish_time : int) : OclAny pre: true post: true activity: var task_to_run : OclAny := remaining.get() ; finish_time := Set{finish_time, task_to_run.time}->max() + task_to_run.duration ; result[task_to_run.index+1] := finish_time ; return finish_time, result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=list(map(int,input().split())) if(mcollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if ((m->compareTo(n)) < 0) then ( execute (0)->display() ) else (if (m = n) then ( execute (1)->display() ) else ( var s : Sequence := (Set{}->union((a))) ; var o : Sequence := Sequence{} ; if ((s)->size() = (a)->size()) then ( execute (1)->display() ) else (if ((s)->size() = 1) then ( execute (m div n)->display() ) else ( for i : Integer.subrange(0, (s)->size()-1) do ( execute ((a->count(s[i+1])) : o)) ; for i : Integer.subrange(1, 102-1) do ( s := 0 ; for j : Integer.subrange(0, (o)->size()-1) do ( s := MatrixLib.elementwiseAdd(s, (o[j+1] div i))) ; if ((s->compareTo(n)) < 0) then ( execute (i - 1)->display() ; break ) else skip) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def isSemiPrime(num): cnt=0 for i in range(2,int(math.sqrt(num))+1): while num % i==0 : num/=i cnt+=1 if cnt>=2 : break if(num>1): cnt+=1 return cnt==2 def isPrime(n): if(n<=1): return False if(n<=3): return True if(n % 2==0 or n % 3==0): return False i=5 while(i*i<=n): if(n % i==0 or n %(i+2)==0): return False i=i+6 return True def isChenPrime(n): if(isPrime(n)and(isSemiPrime(n+2)or isPrime(n+2))): return True else : return False n=7 if(isChenPrime(n)): print("YES"); else : print("NO"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; n := 7 ; if (isChenPrime(n)) then ( execute ("YES")->display(); ) else ( execute ("NO")->display(); ); operation isSemiPrime(num : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; for i : Integer.subrange(2, ("" + (((num)->sqrt())))->toInteger() + 1-1) do ( while num mod i = 0 do ( num := num / i ; cnt := cnt + 1) ; if cnt >= 2 then ( break ) else skip) ; if (num > 1) then ( cnt := cnt + 1 ) else skip ; return cnt = 2; operation isPrime(n : OclAny) : OclAny pre: true post: true activity: if (n <= 1) then ( return false ) else skip ; if (n <= 3) then ( return true ) else skip ; if (n mod 2 = 0 or n mod 3 = 0) then ( return false ) else skip ; var i : int := 5 ; while ((i * i->compareTo(n)) <= 0) do ( if (n mod i = 0 or n mod (i + 2) = 0) then ( return false ) else skip ; i := i + 6) ; return true; operation isChenPrime(n : OclAny) : OclAny pre: true post: true activity: if (isPrime(n) & (isSemiPrime(n + 2) or isPrime(n + 2))) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() i=c=p=0 ; b='' while ip : r=b ; p=c c=0 b=s[i] i+=[3,7][s[i]=='c'] c+=1 if c>p : r=b print(['chicken','egg'][r=='e']) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; i := i(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name p)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))); var b : String := '' ; while (i->compareTo((s)->size())) < 0 do ( if s[i+1] = b then ( if (c->compareTo(p)) > 0 then ( var r : String := b; var p : OclAny := c ) else skip ; var c : int := 0 ) else skip ; b := s[i+1] ; i := i + Sequence{3}->union(Sequence{ 7 })->select(s[i+1] = 'c') ; c := c + 1) ; if (c->compareTo(p)) > 0 then ( r := b ) else skip ; execute (Sequence{'chicken'}->union(Sequence{ 'egg' })->select(r = 'e'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countMinimalReplacements(s): n=len(s) cnt=0 for i in range(1,n): if(s[i]==s[i-1]): cnt+=1 ; if(i!=(n-1)): s=list(s) for j in "012" : if(j!=s[i+1]and j!=s[i-1]): s[i]=j break s=''.join(s) else : s=list(s) for k in "012" : if(k!=s[i-1]): s[i]=k break s=''.join(s) return cnt if __name__=='__main__' : s="201220211" print(countMinimalReplacements(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( s := "201220211" ; execute (countMinimalReplacements(s))->display() ) else skip; operation countMinimalReplacements(s : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; var cnt : int := 0 ; for i : Integer.subrange(1, n-1) do ( if (s[i+1] = s[i - 1+1]) then ( cnt := cnt + 1; ; if (i /= (n - 1)) then ( s := (s) ; for j : "012"->characters() do ( if (j /= s[i + 1+1] & j /= s[i - 1+1]) then ( s[i+1] := j ; break ) else skip) ; s := StringLib.sumStringsWithSeparator((s), '') ) else ( s := (s) ; for k : "012"->characters() do ( if (k /= s[i - 1+1]) then ( s[i+1] := k ; break ) else skip) ; s := StringLib.sumStringsWithSeparator((s), '') ) ) else skip) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys s=sys.stdin.readline() if 'A' in s : print('T') elif 'G' in s : print('C') elif 'C' in s : print('G') else : print('A') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : String := (OclFile["System.in"]).readLine() ; if (s)->characters()->includes('A') then ( execute ('T')->display() ) else (if (s)->characters()->includes('G') then ( execute ('C')->display() ) else (if (s)->characters()->includes('C') then ( execute ('G')->display() ) else ( execute ('A')->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- b=str(input()) strings="A","C","G","T" if b=="A" : print("T") elif b=="C" : print("G") elif b=="G" : print("C") else : print("A") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var b : String := ("" + (((OclFile["System.in"]).readLine()))) ; var strings : String := "A","C","G","T" ; if b = "A" then ( execute ("T")->display() ) else (if b = "C" then ( execute ("G")->display() ) else (if b = "G" then ( execute ("C")->display() ) else ( execute ("A")->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print('ATCG'['TAGC'.index(input())]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ('ATCG'['TAGC'->indexOf((OclFile["System.in"]).readLine()) - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() if s=='A' : print("T") if s=='T' : print("A") if s=='C' : print("G") if s=='G' : print("C") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; if s = 'A' then ( execute ("T")->display() ) else skip ; if s = 'T' then ( execute ("A")->display() ) else skip ; if s = 'C' then ( execute ("G")->display() ) else skip ; if s = 'G' then ( execute ("C")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d={"A" : "T","T" : "A","C" : "G","G" : "C"} print(d[input()]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : Map := Map{ "A" |-> "T" }->union(Map{ "T" |-> "A" }->union(Map{ "C" |-> "G" }->union(Map{ "G" |-> "C" }))) ; execute (d[(OclFile["System.in"]).readLine()+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binomialCoeff(n,k): C=[[0 for i in range(n+1)]for j in range(k+1)] for i in range(0,n+1): for j in range(0,min(i,k)+1): if(j==0 or j==i): C[i][j]=1 else : C[i][j]=C[i-1][j-1]+C[i-1][j] return C[n][k] def cntSubSeq(arr,n,k): arr.sort() num=arr[k-1]; Y=0 ; for i in range(k-1,-1,1): if(arr[i]==num): Y+=1 cntX=Y ; for i in range(k,n): if(arr[i]==num): cntX+=1 return binomialCoeff(cntX,Y) arr=[1,2,3,4] n=len(arr) k=2 print(cntSubSeq(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))) ; n := (arr)->size() ; k := 2 ; execute (cntSubSeq(arr, n, k))->display(); operation binomialCoeff(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var C : Sequence := Integer.subrange(0, k + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, n + 1-1) do ( for j : Integer.subrange(0, Set{i, k}->min() + 1-1) do ( if (j = 0 or j = i) then ( C[i+1][j+1] := 1 ) else ( C[i+1][j+1] := C[i - 1+1][j - 1+1] + C[i - 1+1][j+1] ))) ; return C[n+1][k+1]; operation cntSubSeq(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var num : OclAny := arr[k - 1+1]; ; var Y : int := 0; ; for i : Integer.subrange(k - 1, -1-1)->select( $x | ($x - k - 1) mod 1 = 0 ) do ( if (arr[i+1] = num) then ( Y := Y + 1 ) else skip) ; var cntX : int := Y; ; for i : Integer.subrange(k, n-1) do ( if (arr[i+1] = num) then ( cntX := cntX + 1 ) else skip) ; return binomialCoeff(cntX, Y); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import queue n,b=map(int,input().split()) q=queue.Queue() prc=0 for _ in range(n): t,d=map(int,input().split()) while q.qsize()!=0 and t>=q.queue[0]: q.get() if q.qsize()<=b : prc=max(t,prc)+d q.put(prc) print(prc,end=' ') else : print(-1,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var b : OclAny := null; Sequence{n,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var q : OclAny := queue.Queue() ; var prc : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var t : OclAny := null; var d : OclAny := null; Sequence{t,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; while q.qsize() /= 0 & (t->compareTo(q.queue->first())) >= 0 do ( q.get()) ; if (q.qsize()->compareTo(b)) <= 0 then ( prc := Set{t, prc}->max() + d ; q.put(prc) ; execute (prc)->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools def solve(money,dislike_numbers): for dm in itertools.count(): pay=money+dm if set(map(int,str(pay))).isdisjoint(dislike_numbers): return pay def main(): money,_=map(int,input().split()) dislike_numbers=set(map(int,input().split())) print(solve(money,dislike_numbers)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(money : OclAny, dislike_numbers : OclAny) : OclAny pre: true post: true activity: for dm : itertools->count() do ( var pay : OclAny := money + dm ; if Set{}->union(((("" + ((pay))))->collect( _x | (OclType["int"])->apply(_x) )))->intersection(dislike_numbers)->isEmpty() then ( return pay ) else skip); operation main() pre: true post: true activity: var _anon : OclAny := null; Sequence{money,_anon} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; dislike_numbers := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; execute (solve(money, dislike_numbers))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,os,sys,random def single_test(IN,OUT): X,Y=map(int,IN.readline().split()) x,y=0,0 result='' step=1 while True : E=X-x+random.random() N=Y-y+random.random() W=-E+random.random() S=-N+random.random() d=max(E,N,W,S) nx,ny=x,y r='O' if E==d : nx+=step r='E' elif N==d : ny+=step r='N' elif W==d : nx-=step r='W' elif S==d : ny-=step r='S' if abs(X-nx)+abs(Y-ny)y : result+='SN' y+=1 elif Yx : result+='WE' x+=1 elif Xsize() = 2 do "assertion failed" ; IN := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) ; OUT := OclFile.newOclFile_Write(OclFile.newOclFile(StringLib.format('%s.out',((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))).subrange(1,-3)))) ; main(IN, OUT) ; OUT.closeFile() ; IN.closeFile() ) else skip; operation single_test(IN : OclAny, OUT : OclAny) : OclAny pre: true post: true activity: var X : OclAny := null; var Y : OclAny := null; Sequence{X,Y} := (IN.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{0,0} ; var result : String := '' ; var step : int := 1 ; while true do ( var E : double := X - x + (OclRandom.defaultInstanceOclRandom()).nextDouble() ; var N : double := Y - y + (OclRandom.defaultInstanceOclRandom()).nextDouble() ; var W : OclAny := -E + (OclRandom.defaultInstanceOclRandom()).nextDouble() ; var S : OclAny := -N + (OclRandom.defaultInstanceOclRandom()).nextDouble() ; var d : OclAny := Set{E, N, W, S}->max() ; var nx : OclAny := null; var ny : OclAny := null; Sequence{nx,ny} := Sequence{x,y} ; var r : String := 'O' ; if E = d then ( nx := nx + step ; r := 'E' ) else (if N = d then ( ny := ny + step ; r := 'N' ) else (if W = d then ( nx := nx - step ; r := 'W' ) else (if S = d then ( ny := ny - step ; r := 'S' ) else skip ) ) ) ; if ((X - nx)->abs() + (Y - ny)->abs()->compareTo((X - x)->abs() + (Y - y)->abs())) < 0 then ( step := step + 1 ; result := result + r ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{nx,ny} ) else ( break )) ; while Sequence{x, y} /= Sequence{X, Y} do ( if (Y->compareTo(y)) > 0 then ( result := result + 'SN' ; y := y + 1 ) else (if (Y->compareTo(y)) < 0 then ( result := result + 'NS' ; y := y - 1 ) else (if (X->compareTo(x)) > 0 then ( result := result + 'WE' ; x := x + 1 ) else (if (X->compareTo(x)) < 0 then ( result := result + 'EW' ; x := x - 1 ) else skip ) ) ) ) ; return result; operation main(IN : OclAny, OUT : OclAny) pre: true post: true activity: var T : int := ("" + ((IN.readLine())))->toInteger() ; for i : Integer.subrange(1, T + 1-1) do ( OUT.write(StringLib.format('Case #%d: %s ',Sequence{i, single_test(IN, OUT)}))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(xx,yy): points=set([(0,0)]) for step in range(30): t1=(0,0)in points t2=step % 4 in(0,3) d=step+1 if(xx,yy)in points : return step points=set([a for b in[[(x+d,y),(x-d,y),(x,y+d),(x,y-d)]for x,y in points]for a in b]) def calc(x,y): d=s=0 while sabs(y)and x>0 : x-=i res='E'+res elif abs(x)>abs(y): x+=i res='W'+res elif y>0 : y-=i res='N'+res else : y+=i res='S'+res assert(x,y)==(0,0),(x,y,d) return res def solve(): x,y=map(int,input().split()) res=calc(x,y) print(res) if __name__=="__main__" : T=int(input()) for t in range(1,T+1): print("Case #%d:" % t,end=' ') solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(1, T + 1-1) do ( execute (StringLib.format("Case #%d:",t))->display() ; solve()) ) else skip; operation check(xx : OclAny, yy : OclAny) : OclAny pre: true post: true activity: var points : Set := Set{}->union((Sequence{ Sequence{0, 0} })) ; for step : Integer.subrange(0, 30-1) do ( var t1 : boolean := (points)->includes(Sequence{0, 0}) ; var t2 : boolean := (Sequence{0, 3})->includes(step mod 4) ; var d : OclAny := step + 1 ; if (points)->includes(Sequence{xx, yy}) then ( return step ) else skip ; points := Set{}->union((points->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (Sequence{Sequence{x + d, y}}->union(Sequence{Sequence{x - d, y}}->union(Sequence{Sequence{x, y + d}}->union(Sequence{ Sequence{x, y - d} })))))->select(b; a : b | true)->collect(b; a : b | (a))))); operation calc(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: d := 0; var s : int := 0 ; while (s->compareTo((x)->abs() + (y)->abs())) < 0 do ( d := d + 1 ; s := s + d) ; var add_zero : boolean := (Sequence{0, 3})->includes(d mod 4) ; while (((x)->abs() + (y)->abs()) mod 2 = 0) /= ((Sequence{0, 3})->includes(d mod 4)) do ( d := d + 1 ; s := s + d) ; var res : String := '' ; for i : Integer.subrange(0 + 1, d)->reverse() do ( if ((x)->abs()->compareTo((y)->abs())) > 0 & x > 0 then ( x := x - i ; res := 'E' + res ) else (if ((x)->abs()->compareTo((y)->abs())) > 0 then ( x := x + i ; res := 'W' + res ) else (if y > 0 then ( y := y - i ; res := 'N' + res ) else ( y := y + i ; res := 'S' + res ) ) ) ) ; assert Sequence{x, y} = Sequence{0, 0} do Sequence{x, y, d} ; return res; operation solve() pre: true post: true activity: Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; res := calc(x, y) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(raw_input()) for kei in xrange(t): x,y=(int(j)for j in raw_input().split()) ans=[] while x>0 : ans.append('WE') x-=1 while x<0 : ans.append('EW') x+=1 while y>0 : ans.append('SN') y-=1 while y<0 : ans.append('NS') y+=1 print('Case #%d: %s' %(kei+1,''.join(ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + ((raw_input())))->toInteger() ; for kei : xrange(t) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) ))))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name raw_input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var ans : Sequence := Sequence{} ; while x > 0 do ( execute (('WE') : ans) ; x := x - 1) ; while x < 0 do ( execute (('EW') : ans) ; x := x + 1) ; while y > 0 do ( execute (('SN') : ans) ; y := y - 1) ; while y < 0 do ( execute (('NS') : ans) ; y := y + 1) ; execute (StringLib.format('Case #%d: %s',Sequence{kei + 1, StringLib.sumStringsWithSeparator((ans), '')}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(100000) def puts(s): print(s,end='') def direction(x,y): if x>0 : return "E" if x<0 : return "W" if y>0 : return "N" if y<0 : return "S" def movesReq(x,y): mandis=abs(x)+abs(y) dis=0 moves=0 while mandis>dis or dis % 2!=mandis % 2 : moves+=1 dis+=moves return moves def solutions(x,y,num): if num==0 and x==0 and y==0 : yield "" elif movesReq(x,y)<=num : for d,xp,yp in[("E",x-num,y),("W",x+num,y),("S",x,y+num),("N",x,y-num)]: for s in solutions(xp,yp,num-1): yield s+d def solve(case): x,y=map(int,input().split()) num=movesReq(x,y) for s in solutions(x,y,num): print(s) break for case in range(1,1+int(input())): puts("Case #"+str(case)+": ") solve(case) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(100000) ; skip ; skip ; skip ; skip ; skip ; for case : Integer.subrange(1, 1 + ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( puts("Case #" + ("" + ((case))) + ": ") ; solve(case)); operation puts(s : OclAny) pre: true post: true activity: execute (s)->display(); operation direction(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if x > 0 then ( return "E" ) else skip ; if x < 0 then ( return "W" ) else skip ; if y > 0 then ( return "N" ) else skip ; if y < 0 then ( return "S" ) else skip; operation movesReq(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var mandis : double := (x)->abs() + (y)->abs() ; var dis : int := 0 ; var moves : int := 0 ; while (mandis->compareTo(dis)) > 0 or dis mod 2 /= mandis mod 2 do ( moves := moves + 1 ; dis := dis + moves) ; return moves; operation solutions(x : OclAny, y : OclAny, num : OclAny) pre: true post: true activity: if num = 0 & x = 0 & y = 0 then ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return "" ) else (if (movesReq(x, y)->compareTo(num)) <= 0 then ( for _tuple : Sequence{Sequence{"E", x - num, y}}->union(Sequence{Sequence{"W", x + num, y}}->union(Sequence{Sequence{"S", x, y + num}}->union(Sequence{ Sequence{"N", x, y - num} }))) do (var _indx : int := 1; var d : OclAny := _tuple->at(_indx); _indx := _indx + 1; var xp : OclAny := _tuple->at(_indx); _indx := _indx + 1; var yp : OclAny := _tuple->at(_indx); for s : solutions(xp, yp, num - 1) do ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return s + d)) ) else skip); operation solve(case : OclAny) pre: true post: true activity: Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; num := movesReq(x, y) ; for s : solutions(x, y, num) do ( execute (s)->display() ; break); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for TT in range(1,T+1): x,y=[int(tmp)for tmp in input().split()] s=0 now=1 ans="" while stoInteger() ; for TT : Integer.subrange(1, T + 1-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := input().split()->select(tmp | true)->collect(tmp | (("" + ((tmp)))->toInteger())) ; var s : int := 0 ; var now : int := 1 ; var ans : String := "" ; while (s->compareTo((x)->abs() + (y)->abs())) < 0 or s mod 2 /= (x + y)->abs() mod 2 do ( s := s + now ; now := now + 1) ; for i : Integer.subrange(0 + 1, now - 1)->reverse() do ( s := s - i ; if ((x - i)->abs() + (y)->abs()->compareTo(s)) <= 0 then ( x := x - i ; ans := ans + 'E' ) else (if ((x + i)->abs() + (y)->abs()->compareTo(s)) <= 0 then ( x := x + i ; ans := ans + 'W' ) else (if ((x)->abs() + (y - i)->abs()->compareTo(s)) <= 0 then ( y := y - i ; ans := ans + 'N' ) else ( y := y + i ; ans := ans + 'S' ) ) ) ) ; ans := ans(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; execute ("Case #" + ("" + ((TT))) + ": " + ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k,p,x,y=[int(i)for i in input().split()] left=0 right=0 for a in input().split(): a=int(a) x-=a if a=y : right+=1 if left>n//2 : print(-1) exit() elif right>n//2 : ans=[1]*(n-k) else : ans=[1]*(n//2-left)+[y]*((n+1)//2-right) if sum(ans)>x : print(-1) else : print(" ".join([str(i)for i in ans])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var p : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,k,p,x,y} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var left : int := 0 ; var right : int := 0 ; for a : input().split() do ( var a : int := ("" + ((a)))->toInteger() ; x := x - a ; if (a->compareTo(y)) < 0 then ( left := left + 1 ) else (if (a->compareTo(y)) >= 0 then ( right := right + 1 ) else skip)) ; if (left->compareTo(n div 2)) > 0 then ( execute (-1)->display() ; exit() ) else (if (right->compareTo(n div 2)) > 0 then ( var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n - k)) ) else ( ans := MatrixLib.elementwiseMult(Sequence{ 1 }, (n div 2 - left))->union(MatrixLib.elementwiseMult(Sequence{ y }, ((n + 1) div 2 - right))) ) ) ; if ((ans)->sum()->compareTo(x)) > 0 then ( execute (-1)->display() ) else ( execute (StringLib.sumStringsWithSeparator((ans->select(i | true)->collect(i | (("" + ((i)))))), " "))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k,p,x,y=tuple(map(lambda x : int(x),input().strip().split())) l=sorted(list(map(lambda x : int(x),input().strip().split()))) ss=sum(l) idx=k for i in range(k): if l[i]>=y : idx=i break part1=idx part2=k-idx if part1>n//2 : print(-1) else : if part2>n//2+1 : fill_y=0 fill_1=n-k else : fill_y=n//2+1-part2 fill_1=n//2-part1 ss+=fill_y*y+fill_1 if ss>x : print(-1) else : print(' '.join(['1']*fill_1+[str(y)]*fill_y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var p : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,k,p,x,y} := ((input()->trim().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) )) ; var l : Sequence := ((input()->trim().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ))->sort() ; var ss : OclAny := (l)->sum() ; var idx : OclAny := k ; for i : Integer.subrange(0, k-1) do ( if (l[i+1]->compareTo(y)) >= 0 then ( idx := i ; break ) else skip) ; var part1 : OclAny := idx ; var part2 : double := k - idx ; if (part1->compareTo(n div 2)) > 0 then ( execute (-1)->display() ) else ( if (part2->compareTo(n div 2 + 1)) > 0 then ( var fill_y : int := 0 ; var fill var fill_y : int := 0 : double := n - k ) else ( fill_y := n div 2 + 1 - part2 ; fill fill_y := n div 2 + 1 - part2 := n div 2 - part1 ) ; ss := ss + fill_y * y + fill if (part2->compareTo(n div 2 + 1)) > 0 then ( var fill_y : int := 0 ; var fill var fill_y : int := 0 : double := n - k ) else ( fill_y := n div 2 + 1 - part2 ; fill fill_y := n div 2 + 1 - part2 := n div 2 - part1 ) ; if (ss->compareTo(x)) > 0 then ( execute (-1)->display() ) else ( execute (StringLib.sumStringsWithSeparator((MatrixLib.elementwiseMult(Sequence{ '1' }, fill' ')->union(MatrixLib.elementwiseMult(Sequence{ ("" + ((y))) }, fill_y))), ' '))->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k,p,maxsum,minmed=[int(x)for x in input().split()] left=n-k stillnow=0 lessthanmed=0 ks=[int(x)for x in input().split()] for i in ks : stillnow+=i if in//2 : print(-1) exit() minpermit=min(n//2-lessthanmed,n-k) toprint=[1]*minpermit+[minmed]*(n-k-minpermit) if sum(toprint)+stillnow>maxsum : print(-1) exit() print(' '.join([str(x)for x in toprint])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var p : OclAny := null; var maxsum : OclAny := null; var minmed : OclAny := null; Sequence{n,k,p,maxsum,minmed} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var left : double := n - k ; var stillnow : int := 0 ; var lessthanmed : int := 0 ; var ks : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for i : ks do ( stillnow := stillnow + i ; if (i->compareTo(minmed)) < 0 then ( lessthanmed := lessthanmed + 1 ) else skip) ; if (lessthanmed->compareTo(n div 2)) > 0 then ( execute (-1)->display() ; exit() ) else skip ; var minpermit : OclAny := Set{n div 2 - lessthanmed, n - k}->min() ; var toprint : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, minpermit)->union(MatrixLib.elementwiseMult(Sequence{ minmed }, (n - k - minpermit))) ; if ((toprint)->sum() + stillnow->compareTo(maxsum)) > 0 then ( execute (-1)->display() ; exit() ) else skip ; execute (StringLib.sumStringsWithSeparator((toprint->select(x | true)->collect(x | (("" + ((x)))))), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k,p,x,y=map(int,input().split()) a=list(map(int,input().split())) l,u=[],[] for v in a : if vn//2 : print(-1) exit(0) ans=[] while len(l)x : print(-1) else : print(' '.join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var p : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,k,p,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : OclAny := null; var u : OclAny := null; Sequence{l,u} := Sequence{Sequence{},Sequence{}} ; for v : a do ( if (v->compareTo(y)) < 0 then ( execute ((v) : l) ) else ( execute ((v) : u) )) ; if ((l)->size()->compareTo(n div 2)) > 0 then ( execute (-1)->display() ; exit(0) ) else skip ; var ans : Sequence := Sequence{} ; while ((l)->size()->compareTo(Set{n div 2, n - (u)->size()}->min())) < 0 do ( execute ((1) : l) ; execute ((1) : ans)) ; while ((u)->size()->compareTo(n - (l)->size())) < 0 do ( execute ((y) : u) ; execute ((y) : ans)) ; if ((l)->sum() + (u)->sum()->compareTo(x)) > 0 then ( execute (-1)->display() ) else ( execute (StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000 def maxSubsequenceSubstring(x,y,n,m): dp=[[0 for i in range(MAX)]for i in range(MAX)] for i in range(1,m+1): for j in range(1,n+1): if(x[j-1]==y[i-1]): dp[i][j]=1+dp[i-1][j-1] else : dp[i][j]=dp[i][j-1] ans=0 for i in range(1,m+1): ans=max(ans,dp[i][n]) return ans x="ABCD" y="BACDBDCD" n=len(x) m=len(y) print(maxSubsequenceSubstring(x,y,n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1000 ; skip ; x := "ABCD" ; y := "BACDBDCD" ; n := (x)->size() ; m := (y)->size() ; execute (maxSubsequenceSubstring(x, y, n, m))->display(); operation maxSubsequenceSubstring(x : OclAny, y : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(1, m + 1-1) do ( for j : Integer.subrange(1, n + 1-1) do ( if (x[j - 1+1] = y[i - 1+1]) then ( dp[i+1][j+1] := 1 + dp[i - 1+1][j - 1+1] ) else ( dp[i+1][j+1] := dp[i+1][j - 1+1] ))) ; var ans : int := 0 ; for i : Integer.subrange(1, m + 1-1) do ( ans := Set{ans, dp[i+1][n+1]}->max()) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=[int(i)for i in input().split()] def f(A): P=[0]*(N+1) S=[(-1,0)] for i,a in enumerate(A): while S[-1][1]>a : S.pop() t=i-S[-1][0] P[a]=t S.append((i,a)) return P P=f(A) Q=f(A[: :-1]) print(sum(a*P[a]*Q[a]for a in A)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; skip ; P := f(A) ; var Q : String := f(A(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ; execute (((argument (test (logical_test (comparison (expr (expr (expr (atom (name a))) * (expr (atom (name P)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])))) * (expr (atom (name Q)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name A))))))))->sum())->display(); operation f(A : OclAny) : OclAny pre: true post: true activity: var P : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; var S : Sequence := Sequence{ Sequence{-1, 0} } ; for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); while (S->last()[1+1]->compareTo(a)) > 0 do ( S := S->front()) ; var t : double := i - S->last()->first() ; P[a+1] := t ; execute ((Sequence{i, a}) : S)) ; return P; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k,p,x,y=map(int,input().split()) s,g,l=0,0,[] for a in map(int,input().split()): s+=a g+=a>=y for i in range(n-k): c=1 if g>=n//2+1 else y s+=c g+=c==y l.append(c) print(' '.join(map(str,l))if s<=x and g>=n//2+1 else-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var p : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,k,p,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := null; var g : OclAny := null; var l : OclAny := null; Sequence{s,g,l} := Sequence{0,0,Sequence{}} ; for a : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( s := s + a ; g := g + (a->compareTo(y)) >= 0) ; for i : Integer.subrange(0, n - k-1) do ( var c : int := if (g->compareTo(n div 2 + 1)) >= 0 then 1 else y endif ; s := s + c ; g := g + c = y ; execute ((c) : l)) ; execute (if (s->compareTo(x)) <= 0 & (g->compareTo(n div 2 + 1)) >= 0 then StringLib.sumStringsWithSeparator(((l)->collect( _x | (OclType["String"])->apply(_x) )), ' ') else -1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function from __future__ import unicode_literals from __future__ import division from __future__ import absolute_import import math import string import itertools import fractions import heapq import collections import re import array import bisect def array2d(d1,d2,init=None): return[[init for _ in range(d2)]for _ in range(d1)] N,K=map(int,input().split(" ")) ds=list(map(int,input().split(" "))) cs=[] for i in range(10): if i not in ds : cs.append(i) ns=str(N) def solve(N,digit): if digit==-1 : return N n=int((N//(10**digit))% 10) if n not in ds : return solve(N,digit-1) else : new_N=N//(10**(digit+1)) new_N=new_N*(10**(digit+1)) for i in range(n+1,10): if i not in ds : new_N=new_N+(10**digit)*i return solve(new_N,digit-1) else : new_N=new_N+10**(digit+1) return solve(new_N,len(str(new_N))-1) print(solve(N,len(str(N))-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var ds : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var cs : Sequence := Sequence{} ; for i : Integer.subrange(0, 10-1) do ( if (ds)->excludes(i) then ( execute ((i) : cs) ) else skip) ; var ns : String := ("" + ((N))) ; skip ; execute (solve(N, (("" + ((N))))->size() - 1))->display(); operation array2d(d1 : OclAny, d2 : OclAny, init : OclAny) : OclAny pre: true post: true activity: if init->oclIsUndefined() then init := null else skip; return Integer.subrange(0, d1-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, d2-1)->select(_anon | true)->collect(_anon | (init)))); operation solve(N : OclAny, digit : OclAny) : OclAny pre: true post: true activity: if digit = -1 then ( return N ) else skip ; var n : int := ("" + (((N div ((10)->pow(digit))) mod 10)))->toInteger() ; if (ds)->excludes(n) then ( return solve(N, digit - 1) ) else ( var new_N : int := N div ((10)->pow((digit + 1))) ; new_N := new_N * ((10)->pow((digit + 1))) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 10))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name i)))) not in (comparison (expr (atom (name ds))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name new_N)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name new_N))) + (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 10)))) ** (expr (atom (name digit)))))))) ))) * (expr (atom (name i)))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name solve)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name new_N))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name digit))) - (expr (atom (number (integer 1)))))))))) ))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name new_N)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name new_N))) + (expr (expr (atom (number (integer 10)))) ** (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name digit))) + (expr (atom (number (integer 1))))))))) )))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name solve)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name new_N))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name new_N)))))))) ))))))))) )))) - (expr (atom (number (integer 1)))))))))) )))))))))))))) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumKRepeating(arr,n,k): sum=0 visited=[False for i in range(n)] for i in range(0,n,1): if(visited[i]==True): continue count=1 for j in range(i+1,n,1): if(arr[i]==arr[j]): count+=1 visited[j]=True if(count==k): sum+=arr[i] return sum if __name__=='__main__' : arr=[9,9,10,11,8,8,9,8] n=len(arr) k=3 print(sumKRepeating(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{9}->union(Sequence{9}->union(Sequence{10}->union(Sequence{11}->union(Sequence{8}->union(Sequence{8}->union(Sequence{9}->union(Sequence{ 8 }))))))) ; n := (arr)->size() ; k := 3 ; execute (sumKRepeating(arr, n, k))->display() ) else skip; operation sumKRepeating(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; var visited : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (false)) ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (visited[i+1] = true) then ( continue ) else skip ; var count : int := 1 ; for j : Integer.subrange(i + 1, n-1)->select( $x | ($x - i + 1) mod 1 = 0 ) do ( if (arr[i+1] = arr[j+1]) then ( count := count + 1 ; visited[j+1] := true ) else skip) ; if (count = k) then ( sum := sum + arr[i+1] ) else skip) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findStrictlyIncreasingNum(start,out,n): if(n==0): print(out,end="") return for i in range(start,10): str1=out+str(i) findStrictlyIncreasingNum(i+1,str1,n-1) n=3 findStrictlyIncreasingNum(0,"",n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3 ; findStrictlyIncreasingNum(0, "", n); operation findStrictlyIncreasingNum(start : OclAny, out : OclAny, n : OclAny) pre: true post: true activity: if (n = 0) then ( execute (out)->display() ; return ) else skip ; for i : Integer.subrange(start, 10-1) do ( var str1 : OclAny := out + ("" + ((i))) ; findStrictlyIncreasingNum(i + 1, str1, n - 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=list(map(int,input().split())) flag=True if n<=3 : print('no') else : for i in range(0,n-1): left=min(x[i],x[i+1]) right=max(x[i],x[i+1]) for idx in range(i+2,n-1): tmp_left=min(x[idx],x[idx+1]) tmp_right=max(x[idx],x[idx+1]) if(lefttmp_left): print('yes') flag=False break if not flag : break if flag : print('no') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var flag : boolean := true ; if n <= 3 then ( execute ('no')->display() ) else ( for i : Integer.subrange(0, n - 1-1) do ( var left : OclAny := Set{x[i+1], x[i + 1+1]}->min() ; var right : OclAny := Set{x[i+1], x[i + 1+1]}->max() ; for idx : Integer.subrange(i + 2, n - 1-1) do ( var tmp_left : OclAny := Set{x[idx+1], x[idx + 1+1]}->min() ; var tmp_right : OclAny := Set{x[idx+1], x[idx + 1+1]}->max() ; if ((left->compareTo(tmp_left)) < 0 & (tmp_left < right) & (right->compareTo(tmp_right)) < 0) or ((left->compareTo(tmp_right)) < 0 & (tmp_right < right) & (left->compareTo(tmp_left)) > 0) then ( execute ('yes')->display() ; flag := false ; break ) else skip) ; if not(flag) then ( break ) else skip) ; if flag then ( execute ('no')->display() ) else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) L=list(map(int,input().split())) X=[] for i in range(1,n,1): u=[L[i-1],L[i]] u.sort() X.append(u) ok=True for i in range(n-1): for j in range(n-1): if X[i][0]toInteger() ; var L : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var X : Sequence := Sequence{} ; for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( var u : Sequence := Sequence{L[i - 1+1]}->union(Sequence{ L[i+1] }) ; u := u->sort() ; execute ((u) : X)) ; var ok : boolean := true ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(0, n - 1-1) do ( if (X[i+1]->first()->compareTo(X[j+1]->first())) < 0 & (X[j+1]->first()->compareTo(X[i+1][1+1])) < 0 & (X[i+1][1+1]->compareTo(X[j+1][1+1])) < 0 then ( ok := false ) else skip)) ; if ok = false then ( execute ("yes")->display() ) else ( execute ("no")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input().split() s=[int(i)for i in s] flag=1 for i in range(n-1): x1,x2=(min(s[i],s[i+1]),max(s[i],s[i+1])) for j in range(n-1): x3,x4=(min(s[j],s[j+1]),max(s[j],s[j+1])) if(((x1toInteger() ; var s : OclAny := input().split() ; s := s->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var flag : int := 1 ; for i : Integer.subrange(0, n - 1-1) do ( var x1 : OclAny := null; var x2 : OclAny := null; Sequence{x1,x2} := Sequence{Set{s[i+1], s[i + 1+1]}->min(), Set{s[i+1], s[i + 1+1]}->max()} ; for j : Integer.subrange(0, n - 1-1) do ( var x3 : OclAny := null; var x4 : OclAny := null; Sequence{x3,x4} := Sequence{Set{s[j+1], s[j + 1+1]}->min(), Set{s[j+1], s[j + 1+1]}->max()} ; if ((((x1->compareTo(x3)) < 0) & ((x3->compareTo(x2)) < 0) & ((x2->compareTo(x4)) < 0)) or (((x3->compareTo(x1)) < 0) & ((x1->compareTo(x4)) < 0) & ((x4->compareTo(x2)) < 0))) then ( flag := 0 ; break ) else skip)) ; if (flag = 1) then ( execute ('no')->display() ) else ( execute ('yes')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): a=[] for i in range(n-1): for j in a : mn=min(arr[i],arr[i+1]) mx=max(arr[i],arr[i+1]) if(mn>j[0]and mnj[1])or(mx>j[0]and mxtoInteger() ; var arr : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (solve())->display(); operation solve() : OclAny pre: true post: true activity: var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( for j : a do ( var mn : OclAny := Set{arr[i+1], arr[i + 1+1]}->min() ; var mx : OclAny := Set{arr[i+1], arr[i + 1+1]}->max() ; if ((mn->compareTo(j->first())) > 0 & (mn->compareTo(j[1+1])) < 0 & (mx->compareTo(j[1+1])) > 0) or ((mx->compareTo(j->first())) > 0 & (mx->compareTo(j[1+1])) < 0 & (mn->compareTo(j->first())) < 0) then ( return 'yes' ) else skip) ; execute ((Sequence{Set{arr[i+1], arr[i + 1+1]}->min()}->union(Sequence{ Set{arr[i+1], arr[i + 1+1]}->max() })) : a)) ; return 'no'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findIndices(arr,n): leftMin,rightMin=0,0 leftMax,rightMax=0,0 min_element=arr[0] max_element=arr[0] for i in range(n): if(arr[i]max_element): leftMax=rightMax=i max_element=arr[i] elif(arr[i]==max_element): rightMax=i print("Minimum left : ",leftMin) print("Minimum right : ",rightMin) print("Maximum left : ",leftMax) print("Maximum right : ",rightMax) if __name__=="__main__" : arr=[2,1,1,2,1,5,6,5] n=len(arr) findIndices(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{2}->union(Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 5 }))))))) ; n := (arr)->size() ; findIndices(arr, n) ) else skip; operation findIndices(arr : OclAny, n : OclAny) pre: true post: true activity: var leftMin : OclAny := null; var rightMin : OclAny := null; Sequence{leftMin,rightMin} := Sequence{0,0} ; var leftMax : OclAny := null; var rightMax : OclAny := null; Sequence{leftMax,rightMax} := Sequence{0,0} ; var min_element : OclAny := arr->first() ; var max_element : OclAny := arr->first() ; for i : Integer.subrange(0, n-1) do ( if ((arr[i+1]->compareTo(min_element)) < 0) then ( var leftMin : OclAny := i; var rightMin : OclAny := i ; min_element := arr[i+1] ) else (if (arr[i+1] = min_element) then ( rightMin := i ) else skip) ; if ((arr[i+1]->compareTo(max_element)) > 0) then ( var leftMax : OclAny := i; var rightMax : OclAny := i ; max_element := arr[i+1] ) else (if (arr[i+1] = max_element) then ( rightMax := i ) else skip)) ; execute ("Minimum left : ")->display() ; execute ("Minimum right : ")->display() ; execute ("Maximum left : ")->display() ; execute ("Maximum right : ")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def squareRoot(number,precision): start=0 end,ans=number,1 while(start<=end): mid=int((start+end)/2) if(mid*mid==number): ans=mid break if(mid*middisplay() ; execute (MathLib.roundN(squareRoot(10, 4), 4))->display(); operation squareRoot(number : OclAny, precision : OclAny) : OclAny pre: true post: true activity: var start : int := 0 ; var end : OclAny := null; var ans : OclAny := null; Sequence{end,ans} := Sequence{number,1} ; while ((start->compareTo(end)) <= 0) do ( var mid : int := ("" + (((start + end) / 2)))->toInteger() ; if (mid * mid = number) then ( var ans : int := mid ; break ) else skip ; if ((mid * mid->compareTo(number)) < 0) then ( start := mid + 1 ) else ( var end : double := mid - 1 )) ; var increment : double := 0.1 ; for i : Integer.subrange(0, precision-1) do ( while ((ans * ans->compareTo(number)) <= 0) do ( ans := ans + increment) ; ans := ans - increment ; increment := increment / 10) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def processQueries(): n_k=input().split() n=int(n_k[0]) k=int(n_k[1]) lst_queries=[] for i in range(n): s_t=input().split() lst_queries.append((int(s_t[0]),int(s_t[1]))) queue_queries=[] res=[-1]*n time=lst_queries[0][0] current=None i=0 while i0 : index=0 if len(queue_queries)>0 : i_current=queue_queries.pop(0) index=i_current[0] current=i_current[1] else : current=lst_queries[i] index=i i+=1 time=max(time,current[0])+current[1] res[index]=time for j in range(i,n): if time>lst_queries[j][0]: if len(queue_queries)collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); operation processQueries() : OclAny pre: true post: true activity: var n_k : OclAny := input().split() ; var n : int := ("" + ((n_k->first())))->toInteger() ; var k : int := ("" + ((n_k[1+1])))->toInteger() ; var lst_queries : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var s_t : OclAny := input().split() ; execute ((Sequence{("" + ((s_t->first())))->toInteger(), ("" + ((s_t[1+1])))->toInteger()}) : lst_queries)) ; var queue_queries : Sequence := Sequence{} ; var res : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; var time : OclAny := lst_queries->first()->first() ; var current : OclAny := null ; var i : int := 0 ; while (i->compareTo(n)) < 0 or (queue_queries)->size() > 0 do ( var index : int := 0 ; if (queue_queries)->size() > 0 then ( var i_current : OclAny := queue_queries->at(0`firstArg+1) ; queue_queries := queue_queries->excludingAt(0+1) ; index := i_current->first() ; current := i_current[1+1] ) else ( current := lst_queries[i+1] ; index := i ; i := i + 1 ) ; time := Set{time, current->first()}->max() + current[1+1] ; res[index+1] := time ; for j : Integer.subrange(i, n-1) do ( if (time->compareTo(lst_queries[j+1]->first())) > 0 then ( if ((queue_queries)->size()->compareTo(k)) < 0 then ( execute ((Sequence{j, lst_queries[j+1]}) : queue_queries) ) else skip ; i := i + 1 ) else ( break ))) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**7) rl=sys.stdin.readline def solve(): a=input() if a[2]==a[3]and a[4]==a[5]: print('Yes') else : print('No') if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var rl : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; if a[2+1] = a[3+1] & a[4+1] = a[5+1] then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=[0]+list(input()) print('Yes' if S[3]==S[4]and S[5]==S[6]else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : Sequence := Sequence{ 0 }->union(((OclFile["System.in"]).readLine())->characters()) ; execute (if S[3+1] = S[4+1] & S[5+1] = S[6+1] then 'Yes' else 'No' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a=open(0) n=int(n.split()[0]) while set(a)& set(str(n)): n+=1 print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := OclFile.newOclFile_Write(OclFile.newOclFile(0)) ; var n : int := ("" + ((n.split()->first())))->toInteger() ; while MathLib.bitwiseAnd(Set{}->union((a)), Set{}->union((("" + ((n)))))) do ( n := n + 1) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**8) input=sys.stdin.readline def main(): S=input().strip() if S[2]==S[3]and S[4]==S[5]: print("Yes") else : print("No") if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(8)) ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var S : OclAny := input()->trim() ; if S[2+1] = S[3+1] & S[4+1] = S[5+1] then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isCoffee(s): return s[2]==s[3]and s[4]==s[5] s=input() res='Yes' if isCoffee(s)else 'No' print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := (OclFile["System.in"]).readLine() ; var res : String := if isCoffee(s) then 'Yes' else 'No' endif ; execute (res)->display(); operation isCoffee(s : OclAny) : OclAny pre: true post: true activity: return s[2+1] = s[3+1] & s[4+1] = s[5+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S_list=input() if S_list[2]==S_list[3]: if S_list[4]==S_list[5]: print('Yes') else : print('No') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S_list : String := (OclFile["System.in"]).readLine() ; if S_list[2+1] = S_list[3+1] then ( if S_list[4+1] = S_list[5+1] then ( execute ('Yes')->display() ) else ( execute ('No')->display() ) ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k,x=map(int,input().split()) A=[int(x)for x in input().split()] ms=[] for i in range(n): if A[i]==x : l=i j=i while j=2 : ms.append((l,j-1)) ans=0 for l,r in ms : tt=r-l+1 l-=1 r+=1 while l>=0 or r=0 : x=A[l] if r=0 and A[l]==x : c+=1 l-=1 while r=3 : tt+=c else : break ans=max(ans,tt) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var x : OclAny := null; Sequence{n,k,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ms : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if A[i+1] = x then ( var l : OclAny := i ; var j : OclAny := i ; while (j->compareTo(n)) < 0 & A[j+1] = x do ( j := j + 1) ; if j - l >= 2 then ( execute ((Sequence{l, j - 1}) : ms) ) else skip ) else skip) ; var ans : int := 0 ; for _tuple : ms do (var _indx : int := 1; var l : OclAny := _tuple->at(_indx); _indx := _indx + 1; var r : OclAny := _tuple->at(_indx); var tt : double := r - l + 1 ; l := l - 1 ; r := r + 1 ; while l >= 0 or (r->compareTo(n)) < 0 do ( if l >= 0 then ( var x : OclAny := A[l+1] ) else skip ; if (r->compareTo(n)) < 0 then ( x := A[r+1] ) else skip ; var c : int := 0 ; while l >= 0 & A[l+1] = x do ( c := c + 1 ; l := l - 1) ; while (r->compareTo(n)) < 0 & A[r+1] = x do ( c := c + 1 ; r := r + 1) ; if c >= 3 then ( tt := tt + c ) else ( break )) ; ans := Set{ans, tt}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import sys from io import BytesIO,IOBase from collections import Counter,defaultdict from sys import stdin,stdout import io import math import heapq import bisect import collections def ceil(a,b): return(a+b-1)//b inf=float('inf') def get(): return stdin.readline().rstrip() mod=10**5+7 n,k,y=map(int,get().split()) l=list(map(int,get().split())) ans=0 for x in range(n-1): if l[x]!=y : continue i=x j=x+1 c=1 a=y while 0<=i and j=0 and l[i]==a : c+=1 i-=1 while j=3 : c=0 ans=max(j-i-1,ans) a=l[i] continue else : break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; skip ; var mod : double := (10)->pow(5) + 7 ; var n : OclAny := null; var k : OclAny := null; var y : OclAny := null; Sequence{n,k,y} := (get().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((get().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for x : Integer.subrange(0, n - 1-1) do ( if l[x+1] /= y then ( continue ) else skip ; var i : OclAny := x ; var j : OclAny := x + 1 ; var c : int := 1 ; a := y ; while 0 <= i & (j->compareTo(n)) < 0 do ( while i >= 0 & l[i+1] = a do ( c := c + 1 ; i := i - 1) ; while (j->compareTo(n)) < 0 & l[j+1] = a do ( c := c + 1 ; j := j + 1) ; if c >= 3 then ( c := 0 ; ans := Set{j - i - 1, ans}->max() ; a := l[i+1] ; continue ) else ( break ))) ; execute (ans)->display(); operation ceil(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a + b - 1) div b; operation get() : OclAny pre: true post: true activity: return stdin.readLine().rstrip(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k,x=map(int,input().split()) f=list(map(int,input().split())) res=0 if n>=2 : for i in range(n-1): if f[i]==x and f[i+1]!=x : new=f[: :] new.insert(i,x) nr=0 while True : pre=0 lian=0 flag=1 for i in range(len(new)): if new[i]!=pre : if lian>=3 : del new[i-lian : i] nr+=lian flag=0 lian=0 break else : pre=new[i] lian=1 else : lian+=1 if lian>=3 : del new[len(new)-lian :] nr+=lian flag=0 if flag : break res=max(nr-1,res) new=f[: :] new.insert(i,x) nr=0 while True : pre=0 lian=0 flag=1 for i in range(len(new)): if new[i]!=pre : if lian>=3 : del new[i-lian : i] nr+=lian flag=0 lian=0 break else : pre=new[i] lian=1 else : lian+=1 if lian>=3 : del new[len(new)-lian :] nr+=lian flag=0 if flag : break res=max(nr-1,res) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var x : OclAny := null; Sequence{n,k,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var f : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : int := 0 ; if n >= 2 then ( for i : Integer.subrange(0, n - 1-1) do ( if f[i+1] = x & f[i + 1+1] /= x then ( var new : String := f(subscript : (sliceop :)) ; new := new.insertAt(i+1, x) ; var nr : int := 0 ; while true do ( var pre : int := 0 ; var lian : int := 0 ; var flag : int := 1 ; for i : Integer.subrange(0, (new)->size()-1) do ( if new[i+1] /= pre then ( if lian >= 3 then ( execute (new.subrange(i - lian+1, i))->isDeleted() ; nr := nr + lian ; flag := 0 ; lian := 0 ; break ) else ( pre := new[i+1] ; lian := 1 ) ) else ( lian := lian + 1 )) ; if lian >= 3 then ( execute (new.subrange((new)->size() - lian+1))->isDeleted() ; nr := nr + lian ; flag := 0 ) else skip ; if flag then ( break ) else skip) ; res := Set{nr - 1, res}->max() ) else skip) ; new := f(subscript : (sliceop :)) ; new := new.insertAt(i+1, x) ; nr := 0 ; while true do ( pre := 0 ; lian := 0 ; flag := 1 ; for i : Integer.subrange(0, (new)->size()-1) do ( if new[i+1] /= pre then ( if lian >= 3 then ( execute (new.subrange(i - lian+1, i))->isDeleted() ; nr := nr + lian ; flag := 0 ; lian := 0 ; break ) else ( pre := new[i+1] ; lian := 1 ) ) else ( lian := lian + 1 )) ; if lian >= 3 then ( execute (new.subrange((new)->size() - lian+1))->isDeleted() ; nr := nr + lian ; flag := 0 ) else skip ; if flag then ( break ) else skip) ; res := Set{nr - 1, res}->max() ) else skip ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import heapq import sys import math import itertools import bisect from io import BytesIO,IOBase import os def value(): return tuple(map(int,input().split())) def values(): return tuple(map(int,sys.stdin.readline().split())) def inlst(): return[int(i)for i in input().split()] def inlsts(): return[int(i)for i in sys.stdin.readline().split()] def inp(): return int(input()) def inps(): return int(sys.stdin.readline()) def instr(): return input() def stlst(): return[i for i in input().split()] def solve(): n,k,x=values() l=inlsts() mx=0 ele=[] elecount=[] c=itertools.groupby(l) for i,j in c : ele.append(i) elecount.append(len(list(j))) for i in range(len(ele)): if ele[i]==x and elecount[i]==2 : l,r=i-1,i+1 temp=2 while l>=0 and r<=len(ele)-1 : if ele[l]==ele[r]: s=elecount[r]+elecount[l] if s>2 : temp+=s l-=1 ; r+=1 else : break else : break mx=max(mx,temp) print(mx) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; solve(); operation value() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation values() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inlsts() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inps() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation instr() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation stlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (i)); operation solve() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var x : OclAny := null; Sequence{n,k,x} := values() ; var l : OclAny := inlsts() ; var mx : int := 0 ; var ele : Sequence := Sequence{} ; var elecount : Sequence := Sequence{} ; var c : OclAny := itertools.groupby(l) ; for _tuple : c do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); execute ((i) : ele) ; execute ((((j))->size()) : elecount)) ; for i : Integer.subrange(0, (ele)->size()-1) do ( if ele[i+1] = x & elecount[i+1] = 2 then ( var r : OclAny := null; Sequence{l,r} := Sequence{i - 1,i + 1} ; var temp : int := 2 ; while l >= 0 & (r->compareTo((ele)->size() - 1)) <= 0 do ( if ele[l+1] = ele[r+1] then ( var s : OclAny := elecount[r+1] + elecount[l+1] ; if s > 2 then ( temp := temp + s ; l := l - 1; r := r + 1 ) else ( break ) ) else ( break )) ; mx := Set{mx, temp}->max() ) else skip) ; execute (mx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) q=[] time_free=0 for _ in range(n): s,t=map(int,input().split()) while q and q[0]<=s : q=q[1 :] if scollect( _x | (OclType["int"])->apply(_x) ) ; var q : Sequence := Sequence{} ; var time_free : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; while q & (q->first()->compareTo(s)) <= 0 do ( q := q->tail()) ; if (s->compareTo(time_free)) < 0 then ( if (q)->size() = m then ( execute (-1)->display() ) else ( execute ((time_free) : q) ; time_free := time_free + t ; execute (time_free)->display() ) ) else ( time_free := Set{time_free, s}->max() + t ; execute (time_free)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k,x=map(int,input().split()) A=[int(x)for x in input().split()] ms=[] for i in range(n): if A[i]==x : l=i j=i while j=2 : ms.append((l,j-1)) ans=0 for l,r in ms : tt=r-l+1 l-=1 r+=1 while 1 : lc,rc=0,0 lv=rv=-1 if l>=0 : lv=A[l] while l>=0 and A[l]==lv : lc+=1 l-=1 if r=3 : tt+=lc+rc else : break else : break ans=max(ans,tt) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var x : OclAny := null; Sequence{n,k,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ms : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if A[i+1] = x then ( var l : OclAny := i ; var j : OclAny := i ; while (j->compareTo(n)) < 0 & A[j+1] = x do ( j := j + 1) ; if j - l >= 2 then ( execute ((Sequence{l, j - 1}) : ms) ) else skip ) else skip) ; var ans : int := 0 ; for _tuple : ms do (var _indx : int := 1; var l : OclAny := _tuple->at(_indx); _indx := _indx + 1; var r : OclAny := _tuple->at(_indx); var tt : double := r - l + 1 ; l := l - 1 ; r := r + 1 ; while 1 do ( var lc : OclAny := null; var rc : OclAny := null; Sequence{lc,rc} := Sequence{0,0} ; var lv : OclAny := -1; var rv : int := -1 ; if l >= 0 then ( lv := A[l+1] ; while l >= 0 & A[l+1] = lv do ( lc := lc + 1 ; l := l - 1) ) else skip ; if (r->compareTo(n)) < 0 then ( rv := A[r+1] ; while (r->compareTo(n)) < 0 & A[r+1] = rv do ( rc := rc + 1 ; r := r + 1) ) else skip ; if lv = rv & lv /= -1 then ( if lc + rc >= 3 then ( tt := tt + lc + rc ) else ( break ) ) else ( break )) ; ans := Set{ans, tt}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def returnWinner(s,l): freq=[0 for i in range(26)] for i in range(0,l,1): freq[ord(s[i])-ord('a')]+=1 cnt=0 for i in range(26): if(freq[i]% 2!=0): cnt+=1 if(cnt==0 or cnt & 1==1): return 1 else : return 2 if __name__=='__main__' : s="abaaab" l=len(s) winner=returnWinner(s,l) print("Player-",winner) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( s := "abaaab" ; l := (s)->size() ; var winner : OclAny := returnWinner(s, l) ; execute ("Player-")->display() ) else skip; operation returnWinner(s : OclAny, l : OclAny) : OclAny pre: true post: true activity: var freq : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, l-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( freq[(s[i+1])->char2byte() - ('a')->char2byte()+1] := freq[(s[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; var cnt : int := 0 ; for i : Integer.subrange(0, 26-1) do ( if (freq[i+1] mod 2 /= 0) then ( cnt := cnt + 1 ) else skip) ; if (cnt = 0 or MathLib.bitwiseAnd(cnt, 1) = 1) then ( return 1 ) else ( return 2 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=int(input()) n,m=0,0 for i in range(0,s//4+1): if(s-4*i)% 7==0 : n=i m=(s-4*i)//7 break if n==0 and m==0 : print(-1) else : print('4'*n+'7'*m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{0,0} ; for i : Integer.subrange(0, s div 4 + 1-1) do ( if (s - 4 * i) mod 7 = 0 then ( var n : OclAny := i ; var m : int := (s - 4 * i) div 7 ; break ) else skip) ; if n = 0 & m = 0 then ( execute (-1)->display() ) else ( execute (StringLib.nCopies('4', n) + StringLib.nCopies('7', m))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=input().split() k=int(n) li=list(input().split()) for i in range(k,100000): for e in li : if e in str(i): break else : print(i) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split() ; var k : int := ("" + ((n)))->toInteger() ; var li : Sequence := (input().split()) ; for i : Integer.subrange(k, 100000-1) do ((compound_stmt for (exprlist (expr (atom (name e)))) in (testlist (test (logical_test (comparison (expr (atom (name li))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name e)))) in (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- readline=lambda : map(int,input().split()); n,=readline(); div7,res7=n//7,n % 7 ; div4,res4=res7//4,res7 % 4 ; print(-1 if div7collect( _x | (OclType["int"])->apply(_x) )); ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,)} := readline->apply(); ; var div7 : OclAny := null; var res7 : OclAny := null; Sequence{div7,res7} := Sequence{n div 7,n mod 7}; ; var div4 : OclAny := null; var res4 : OclAny := null; Sequence{div4,res4} := Sequence{res7 div 4,res7 mod 4}; ; execute (if (div7->compareTo(res4)) < 0 then -1 else StringLib.nCopies('4', (div4 + 2 * res4)) + StringLib.nCopies('7', (div7 - res4)) endif)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n//7+1): for j in range((n-7*(n//7-i))//4+1): if(n//7-i)*7+j*4==n : print("4"*j+"7"*(n//7-i)) quit() elif(n//7-i)*7+j*4>n : break print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n div 7 + 1-1) do ( for j : Integer.subrange(0, (n - 7 * (n div 7 - i)) div 4 + 1-1) do ( if (n div 7 - i) * 7 + j * 4 = n then ( execute (StringLib.nCopies("4", j) + StringLib.nCopies("7", (n div 7 - i)))->display() ; quit() ) else (if ((n div 7 - i) * 7 + j * 4->compareTo(n)) > 0 then ( break ) else skip))) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ii=int(input()) for n in range(ii//7+1): for m in range((ii-7*(ii//7-n))//4+1): if(ii//7-n)*7+m*4==ii : print("4"*m+"7"*(ii//7-n)) quit() elif(ii//7-n)*7+m*4>ii : break print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ii : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for n : Integer.subrange(0, ii div 7 + 1-1) do ( for m : Integer.subrange(0, (ii - 7 * (ii div 7 - n)) div 4 + 1-1) do ( if (ii div 7 - n) * 7 + m * 4 = ii then ( execute (StringLib.nCopies("4", m) + StringLib.nCopies("7", (ii div 7 - n)))->display() ; quit() ) else (if ((ii div 7 - n) * 7 + m * 4->compareTo(ii)) > 0 then ( break ) else skip))) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict import sys sys.stdin=open("input.txt","r") sys.stdout=open("output.txt","w") n=int(input())*2 a=[int(i)for i in input().split()] c=defaultdict(list) for i in range(n): c[a[i]].append(i+1) ans=[] for[k,v]in c.items(): l=len(v) if l % 2 : print('-1') exit() else : for i in range(0,l-1,2): ans.append(f'{v[i]}{v[i+1]}') print('\n'.join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() * 2 ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var c : OclAny := defaultdict(OclType["Sequence"]) ; for i : Integer.subrange(0, n-1) do ((expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ))))) ; var ans : Sequence := Sequence{} ; for Sequence{k}->union(Sequence{ v }) : c->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do ( var l : int := (v)->size() ; if l mod 2 then ( execute ('-1')->display() ; exit() ) else ( for i : Integer.subrange(0, l - 1-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( execute ((StringLib.formattedString('{v[i]}{v[i+1]}')) : ans)) )) ; execute (StringLib.sumStringsWithSeparator((ans), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.stdin=open("input.txt") sys.stdout=open("output.txt",'w') n=int(input()) a=list(map(int,input().split())) d={}; m=[] for i in range(2*n): if a[i]not in d : d[a[i]]=[i+1] else : d[a[i]]+=i+1, if len(d[a[i]])==2 : x=str(d[a[i]][0])+" "+str(d[a[i]][1]) m.append(x) del d[a[i]] if len(m)==n : for i in m : print(i) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := Set{}; var m : Sequence := Sequence{} ; for i : Integer.subrange(0, 2 * n-1) do ( if (d)->excludes(a[i+1]) then ( d[a[i+1]+1] := Sequence{ i + 1 } ) else ( d[a[i+1]+1] := d[a[i+1]+1] + (testlist (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))) ,) ) ; if (d[a[i+1]+1])->size() = 2 then ( var x : String := ("" + ((d[a[i+1]+1]->first()))) + " " + ("" + ((d[a[i+1]+1][1+1]))) ; execute ((x) : m) ; execute (d[a[i+1]+1])->isDeleted() ) else skip) ; if (m)->size() = n then ( for i : m do ( execute (i)->display()) ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.stdin=open("input.txt") sys.stdout=open("output.txt",'w') n=int(input()) a=list(map(int,input().split())) finl=[]; cnt={} for i in range(2*n): if a[i]not in cnt : cnt[a[i]]=[i+1] else : cnt[a[i]]+=i+1, if(len(cnt[a[i]])==2): s=str(cnt[a[i]][0])+" "+str(cnt[a[i]][1]) finl.append(s) del cnt[a[i]] if(len(finl)==n): for i in finl : print(i) else : print("-1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var finl : Sequence := Sequence{}; var cnt : OclAny := Set{} ; for i : Integer.subrange(0, 2 * n-1) do ( if (cnt)->excludes(a[i+1]) then ( cnt[a[i+1]+1] := Sequence{ i + 1 } ) else ( cnt[a[i+1]+1] := cnt[a[i+1]+1] + (testlist (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))) ,) ) ; if ((cnt[a[i+1]+1])->size() = 2) then ( var s : String := ("" + ((cnt[a[i+1]+1]->first()))) + " " + ("" + ((cnt[a[i+1]+1][1+1]))) ; execute ((s) : finl) ; execute (cnt[a[i+1]+1])->isDeleted() ) else skip) ; if ((finl)->size() = n) then ( for i : finl do ( execute (i)->display()) ) else ( execute ("-1")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): nm=input() nm=nm.split() inp=input() inp=inp.split() for i in range(int(nm[0])): inp.append(int(inp[0])) inp.pop(0) inp.sort() sum1=0 for i in range(int(nm[0])): sum1+=max(inp[i-1],inp[i]) if(sum1+int(nm[0]))<=int(nm[1]): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var nm : String := (OclFile["System.in"]).readLine() ; nm := nm.split() ; var inp : String := (OclFile["System.in"]).readLine() ; inp := inp.split() ; for i : Integer.subrange(0, ("" + ((nm->first())))->toInteger()-1) do ( execute ((("" + ((inp->first())))->toInteger()) : inp) ; inp := inp->excludingAt(0+1)) ; inp := inp->sort() ; var sum1 : int := 0 ; for i : Integer.subrange(0, ("" + ((nm->first())))->toInteger()-1) do ( sum1 := sum1 + Set{inp[i - 1+1], inp[i+1]}->max()) ; if ((sum1 + ("" + ((nm->first())))->toInteger())->compareTo(("" + ((nm[1+1])))->toInteger())) <= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.stdin,sys.stdout=open('input.txt','r'),open('output.txt','w') n=int(input()) w=input().split() d=[] e={} for i in range(2*n): if w[i]not in e : e[w[i]]=i+1 else : d.append(str(i+1)+' '+str(e[w[i]])) del(e[w[i]]) if len(e)==0 : print(' '.join(d)) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var OclFile["System.in"] : OclAny := null; var OclFile["System.out"] : OclAny := null; Sequence{OclFile["System.in"],OclFile["System.out"]} := Sequence{OclFile.newOclFile_Write(OclFile.newOclFile('input.txt')),OclFile.newOclFile_Write(OclFile.newOclFile('output.txt'))} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : OclAny := input().split() ; var d : Sequence := Sequence{} ; var e : OclAny := Set{} ; for i : Integer.subrange(0, 2 * n-1) do ( if (e)->excludes(w[i+1]) then ( e[w[i+1]+1] := i + 1 ) else ( execute ((("" + ((i + 1))) + ' ' + ("" + ((e[w[i+1]+1])))) : d) ; execute ((e[w[i+1]+1]))->isDeleted() )) ; if (e)->size() = 0 then ( execute (StringLib.sumStringsWithSeparator((d), ' '))->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.stdin=open("input.txt","r") sys.stdout=open("output.txt","w") _=input() cards=list(map(int,input().split())) from collections import defaultdict card_indices=defaultdict(list) for i,card in enumerate(cards,start=1): card_indices[card].append(i) output=[] for card,indices in card_indices.items(): if len(indices)% 2 : print(-1) exit() for i in range(0,len(indices),2): output.append(f'{indices[i]}{indices[i+1]}') print('\n'.join(output)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ; var _anon : String := (OclFile["System.in"]).readLine() ; var cards : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; var card_indices : OclAny := defaultdict(OclType["Sequence"]) ; for _tuple : Integer.subrange(1, (cards, (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->size())->collect( _indx | Sequence{_indx-1, (cards, (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var card : OclAny := _tuple->at(_indx); (expr (atom (name card_indices)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name card)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var output : Sequence := Sequence{} ; for _tuple : card_indices->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var card : OclAny := _tuple->at(_indx); _indx := _indx + 1; var indices : OclAny := _tuple->at(_indx); if (indices)->size() mod 2 then ( execute (-1)->display() ; exit() ) else skip ; for i : Integer.subrange(0, (indices)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( execute ((StringLib.formattedString('{indices[i]}{indices[i+1]}')) : output))) ; execute (StringLib.sumStringsWithSeparator((output), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_to_bits=[0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4]; def countSetBitsRec(num): nibble=0 ; if(0==num): return num_to_bits[0]; nibble=num & 0xf ; return num_to_bits[nibble]+countSetBitsRec(num>>4); num=31 ; print(countSetBitsRec(num)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_to_bits : Sequence := Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{3}->union(Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{3}->union(Sequence{2}->union(Sequence{3}->union(Sequence{3}->union(Sequence{ 4 }))))))))))))))); ; skip ; num := 31; ; execute (countSetBitsRec(num))->display();; operation countSetBitsRec(num : OclAny) pre: true post: true activity: var nibble : int := 0; ; if (0 = num) then ( return num_to_bits->first(); ) else skip ; nibble := MathLib.bitwiseAnd(num, 0xf); ; return num_to_bits[nibble+1] + countSetBitsRec(num /(2->pow(4)));; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def computeCost(arr,N,X): cost=0 for i in range(N): cost+=abs(arr[i]-X) return cost def minCostToMakeElementEqual(arr,N): low=high=arr[0] for i in range(N): if(low>arr[i]): low=arr[i] if(high2): mid1=low+(high-low)//3 mid2=high-(high-low)//3 cost1=computeCost(arr,N,mid1) cost2=computeCost(arr,N,mid2) if(cost1union(Sequence{100}->union(Sequence{ 101 })) ; N := (arr)->size() ; execute (minCostToMakeElementEqual(arr, N))->display(); operation computeCost(arr : OclAny, N : OclAny, X : OclAny) : OclAny pre: true post: true activity: var cost : int := 0 ; for i : Integer.subrange(0, N-1) do ( cost := cost + (arr[i+1] - X)->abs()) ; return cost; operation minCostToMakeElementEqual(arr : OclAny, N : OclAny) : OclAny pre: true post: true activity: var low : OclAny := arr->first(); var high : OclAny := arr->first() ; for i : Integer.subrange(0, N-1) do ( if ((low->compareTo(arr[i+1])) > 0) then ( low := arr[i+1] ) else skip ; if ((high->compareTo(arr[i+1])) < 0) then ( high := arr[i+1] ) else skip) ; while ((high - low) > 2) do ( var mid1 : OclAny := low + (high - low) div 3 ; var mid2 : double := high - (high - low) div 3 ; var cost1 : OclAny := computeCost(arr, N, mid1) ; var cost2 : OclAny := computeCost(arr, N, mid2) ; if ((cost1->compareTo(cost2)) < 0) then ( high := mid2 ) else ( low := mid1 )) ; return computeCost(arr, N, (low + high) div 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkDigit(n): d=[] for i in range(9): if n % 10 in D : return False n//=10 if n==0 : return True def solve(n): for i in range(N,1000000): if checkDigit(i): return i N,K=[int(x)for x in input().split()] D=[int(x)for x in input().split()] print(solve(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var D : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (solve(N))->display(); operation checkDigit(n : OclAny) : OclAny pre: true post: true activity: var d : Sequence := Sequence{} ; for i : Integer.subrange(0, 9-1) do ( if (D)->includes(n mod 10) then ( return false ) else skip ; n := n div 10 ; if n = 0 then ( return true ) else skip); operation solve(n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(N, 1000000-1) do ( if checkDigit(i) then ( return i ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=3 s=[int(x)for x in input().split()] flag=1 now=1 while nowselect(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var flag : int := 1 ; var now : int := 1 ; while (now->compareTo(s->first())) < 0 do ( now := now * s[2+1]) ; while (now->compareTo(s[1+1])) <= 0 do ( execute (now)->display() ; flag := 0 ; now := now * s[2+1]) ; if flag then ( execute ("-1")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l,r,k=map(int,input().split()) s=1 ans=[] while True : if s>r : break if s>=l and s<=r : ans.append(s) s=s*k if len(ans)==0 : print(-1) else : for i in ans : print(i,end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; var k : OclAny := null; Sequence{l,r,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : int := 1 ; var ans : Sequence := Sequence{} ; while true do ( if (s->compareTo(r)) > 0 then ( break ) else skip ; if (s->compareTo(l)) >= 0 & (s->compareTo(r)) <= 0 then ( execute ((s) : ans) ) else skip ; s := s * k) ; if (ans)->size() = 0 then ( execute (-1)->display() ) else ( for i : ans do ( execute (i)->display()) ; execute (->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- min,max,num=[int(x)for x in input().split()] vdd=0 i=0 pot=num**i while pot<=max : if min<=pot and pot<=max : print(pot,end=" ") vdd=1 i=i+1 pot=num**i if vdd==0 : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var min : OclAny := null; var max : OclAny := null; var num : OclAny := null; Sequence{min,max,num} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var vdd : int := 0 ; var i : int := 0 ; var pot : double := (num)->pow(i) ; while (pot->compareTo(max)) <= 0 do ( if (min->compareTo(pot)) <= 0 & (pot->compareTo(max)) <= 0 then ( execute (pot)->display() ; vdd := 1 ) else skip ; i := i + 1 ; pot := (num)->pow(i)) ; if vdd = 0 then ( execute (-1)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l,r,k=map(int,input().split()) s=1 b=1 while s<=r : if s>=l and s<=r : print(s) b=0 s*=k if b==1 : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; var k : OclAny := null; Sequence{l,r,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : int := 1 ; var b : int := 1 ; while (s->compareTo(r)) <= 0 do ( if (s->compareTo(l)) >= 0 & (s->compareTo(r)) <= 0 then ( execute (s)->display() ; b := 0 ) else skip ; s := s * k) ; if b = 1 then ( execute (-1)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=3 s=[int(x)for x in input().split()] flag=1 now=1 while nowselect(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var flag : int := 1 ; var now : int := 1 ; while (now->compareTo(s->first())) < 0 do ( now := now * s[2+1]) ; while (now->compareTo(s[1+1])) <= 0 do ( execute (now)->display() ; flag := 0 ; now := now * s[2+1]) ; if flag then ( execute ("-1")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=list(map(int,input().split())) a=list(map(int,input().split())) a.sort(reverse=True) need=0 need+=n need+=a[0] r=0 for i in range(n-1): need+=a[i] if need>m : r=1 break if r==0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var need : int := 0 ; need := need + n ; need := need + a->first() ; var r : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( need := need + a[i+1] ; if (need->compareTo(m)) > 0 then ( r := 1 ; break ) else skip) ; if r = 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printPartition(n,m): k=int(n/m) ct=n % m for i in range(1,ct+1,1): print(k+1,end=" ") count=i for i in range(count,m,1): print(k,end=" ") if __name__=='__main__' : n=5 m=2 printPartition(n,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 5 ; m := 2 ; printPartition(n, m) ) else skip; operation printPartition(n : OclAny, m : OclAny) pre: true post: true activity: var k : int := ("" + ((n / m)))->toInteger() ; var ct : int := n mod m ; for i : Integer.subrange(1, ct + 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( execute (k + 1)->display()) ; var count : OclAny := i ; for i : Integer.subrange(count, m-1)->select( $x | ($x - count) mod 1 = 0 ) do ( execute (k)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count_element(N,K,arr): mp=dict() for i in range(N): mp[arr[i]]=mp.get(arr[i],0)+1 answer=0 for i in mp : if i+K in mp : answer+=mp[i] return answer if __name__=='__main__' : arr=[3,6,2,8,7,6,5,9] N=len(arr) K=2 print(count_element(N,K,arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{3}->union(Sequence{6}->union(Sequence{2}->union(Sequence{8}->union(Sequence{7}->union(Sequence{6}->union(Sequence{5}->union(Sequence{ 9 }))))))) ; N := (arr)->size() ; K := 2 ; execute (count_element(N, K, arr))->display() ) else skip; operation count_element(N : OclAny, K : OclAny, arr : OclAny) : OclAny pre: true post: true activity: var mp : Map := (arguments ( )) ; for i : Integer.subrange(0, N-1) do ( mp[arr[i+1]+1] := mp.get(arr[i+1], 0) + 1) ; var answer : int := 0 ; for i : mp->keys() do ( if (mp)->includes(i + K) then ( answer := answer + mp[i+1] ) else skip) ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- arr=[] def generateDivisors(n): for i in range(1,int(n**(0.5))+1): if n % i==0 : if n//i==i : arr.append(i) else : arr.append(i) arr.append(n//i) def harmonicMean(n): generateDivisors(n) Sum=0 length=len(arr) for i in range(0,length): Sum=Sum+(n/arr[i]) Sum=Sum/n return length/Sum def isOreNumber(n): mean=harmonicMean(n) if mean-int(mean)==0 : return True else : return False if __name__=="__main__" : n=28 if isOreNumber(n)==True : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var arr : Sequence := Sequence{} ; skip ; skip ; skip ; if __name__ = "__main__" then ( n := 28 ; if isOreNumber(n) = true then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; operation generateDivisors(n : OclAny) pre: true post: true activity: for i : Integer.subrange(1, ("" + (((n)->pow((0.5)))))->toInteger() + 1-1) do ( if n mod i = 0 then ( if n div i = i then ( execute ((i) : arr) ) else ( execute ((i) : arr) ; execute ((n div i) : arr) ) ) else skip); operation harmonicMean(n : OclAny) : OclAny pre: true post: true activity: generateDivisors(n) ; var Sum : int := 0 ; var length : int := (arr)->size() ; for i : Integer.subrange(0, length-1) do ( Sum := Sum + (n / arr[i+1])) ; Sum := Sum / n ; return length / Sum; operation isOreNumber(n : OclAny) : OclAny pre: true post: true activity: var mean : OclAny := harmonicMean(n) ; if mean - ("" + ((mean)))->toInteger() = 0 then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def subsetSum(arr,n,i,sum,count): if(i==n): if(sum==0): count+=1 return count count=subsetSum(arr,n,i+1,sum-arr[i],count) count=subsetSum(arr,n,i+1,sum,count) return count arr=[1,2,3,4,5] sum=10 n=len(arr) print(subsetSum(arr,n,0,sum,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ; sum := 10 ; n := (arr)->size() ; execute (subsetSum(arr, n, 0, sum, 0))->display(); operation subsetSum(arr : OclAny, n : OclAny, i : OclAny, sum : OclAny, count : OclAny) : OclAny pre: true post: true activity: if (i = n) then ( if (sum = 0) then ( count := count + 1 ) else skip ; return count ) else skip ; count := subsetSum(arr, n, i + 1, sum - arr[i+1], count) ; count := subsetSum(arr, n, i + 1, sum, count) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for tc in range(1,T+1): L=int(input()) histo=list(map(int,input().split())) if L==1 : print(histo[0]) else : total=0 total+=histo[0] for i in range(1,L): total+=abs(histo[i]-histo[i-1]) total+=histo[L-1] for index in range(1,L-1): if histo[index]>histo[index-1]and histo[index]>histo[index+1]: total-=abs(max(histo[index-1],histo[index+1])-histo[index]) histo[index]=max(histo[index-1],histo[index+1]) if histo[0]>histo[1]: total-=(histo[0]-histo[1]) if histo[L-1]>histo[L-2]: total-=(histo[L-1]-histo[L-2]) print(total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for tc : Integer.subrange(1, T + 1-1) do ( var L : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var histo : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if L = 1 then ( execute (histo->first())->display() ) else ( var total : int := 0 ; total := total + histo->first() ; for i : Integer.subrange(1, L-1) do ( total := total + (histo[i+1] - histo[i - 1+1])->abs()) ; total := total + histo[L - 1+1] ; for index : Integer.subrange(1, L - 1-1) do ( if (histo[index+1]->compareTo(histo[index - 1+1])) > 0 & (histo[index+1]->compareTo(histo[index + 1+1])) > 0 then ( total := total - (Set{histo[index - 1+1], histo[index + 1+1]}->max() - histo[index+1])->abs() ; histo[index+1] := Set{histo[index - 1+1], histo[index + 1+1]}->max() ) else skip) ; if (histo->first()->compareTo(histo[1+1])) > 0 then ( total := total - (histo->first() - histo[1+1]) ) else skip ; if (histo[L - 1+1]->compareTo(histo[L - 2+1])) > 0 then ( total := total - (histo[L - 1+1] - histo[L - 2+1]) ) else skip ; execute (total)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sum(x,n): total=1.0 ; previous=1.0 ; for i in range(1,n+1): previous=(previous*x)/(i+1); total=total+previous ; return total ; if __name__=='__main__' : x=5 ; n=4 ; print("Sum is: ",sum(x,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( x := 5; ; n := 4; ; execute ("Sum is: ")->display(); ) else skip; operation sum(x : OclAny, n : OclAny) pre: true post: true activity: var total : double := 1.0; ; var previous : double := 1.0; ; for i : Integer.subrange(1, n + 1-1) do ( previous := (previous * x) / (i + 1); ; total := total + previous;) ; return total;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in[0]*int(input()): n=int(input()) m=list(map(int,input().split())) k=0 m=[0]+m+[0] for j in range(0,n+1): k+=abs(m[j]-m[j+1]) for i in range(1,n+1): if m[i-1]toInteger()) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k : int := 0 ; m := Sequence{ 0 }->union(m)->union(Sequence{ 0 }) ; for j : Integer.subrange(0, n + 1-1) do ( k := k + (m[j+1] - m[j + 1+1])->abs()) ; for i : Integer.subrange(1, n + 1-1) do ( if (m[i - 1+1]->compareTo(m[i+1])) < 0 & (m[i + 1+1]->compareTo(m[i+1])) < 0 then ( k := k - m[i+1] - Set{m[i + 1+1], m[i - 1+1]}->max() ) else skip) ; execute (k)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def solve(): n=int(input()) a=list(map(int,input().split())) c=0 for i in range(n): if i>0 : l=a[i-1] else : l=0 if i+1toInteger()-1) do ( solve()); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( if i > 0 then ( var l : OclAny := a[i - 1+1] ) else ( l := 0 ) ; if (i + 1->compareTo(n)) < 0 then ( var r : OclAny := a[i + 1+1] ) else ( r := 0 ) ; var v : OclAny := Set{l, r}->max() ; if (v->compareTo(a[i+1])) < 0 then ( c := c + a[i+1] - v ; a[i+1] := v ) else skip) ; var p : int := 0 ; for i : Integer.subrange(0, n-1) do ( c := c + (a[i+1] - p)->abs() ; p := a[i+1]) ; c := c + (p)->abs() ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) temp=0 arr=list(map(int,input().strip().split())) arr=[0]+arr s=sum(arr) arr.append(0) for i in range(1,n+1): if arr[i]>arr[i+1]and arr[i]>arr[i-1]: arr[i]=max(arr[i+1],arr[i-1]) cout=0 for i in range(len(arr)-1): cout+=abs(arr[i]-arr[i+1]) print(cout+s-sum(arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var temp : int := 0 ; var arr : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := Sequence{ 0 }->union(arr) ; var s : OclAny := (arr)->sum() ; execute ((0) : arr) ; for i : Integer.subrange(1, n + 1-1) do ( if (arr[i+1]->compareTo(arr[i + 1+1])) > 0 & (arr[i+1]->compareTo(arr[i - 1+1])) > 0 then ( arr[i+1] := Set{arr[i + 1+1], arr[i - 1+1]}->max() ) else skip) ; var cout : int := 0 ; for i : Integer.subrange(0, (arr)->size() - 1-1) do ( cout := cout + (arr[i+1] - arr[i + 1+1])->abs()) ; execute (cout + s - (arr)->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(A,B,n): cnt=0 ; for i in range(n): for j in range(i,n): c=A[i]& A[j] if(bin(c).count('1')==B[j]): cnt+=1 ; return cnt ; if __name__=="__main__" : A=[2,3,1,4,5]; B=[2,2,1,4,2]; size=len(A); print(solve(A,B,size)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( A := Sequence{2}->union(Sequence{3}->union(Sequence{1}->union(Sequence{4}->union(Sequence{ 5 })))); ; B := Sequence{2}->union(Sequence{2}->union(Sequence{1}->union(Sequence{4}->union(Sequence{ 2 })))); ; var size : int := (A)->size(); ; execute (solve(A, B, size))->display(); ) else skip; operation solve(A : OclAny, B : OclAny, n : OclAny) pre: true post: true activity: var cnt : int := 0; ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i, n-1) do ( var c : int := MathLib.bitwiseAnd(A[i+1], A[j+1]) ; if (bin(c)->count('1') = B[j+1]) then ( cnt := cnt + 1; ) else skip)) ; return cnt;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=map(int,input().split()) a=sorted(map(int,input().split())) if n>=m : print('NO') else : total_seat=2*a[0]+1-min(a[0],a[-1]) for i in range(1,n): total_seat+=2*a[i]+1-min(a[i-1],a[i]) if total_seat>m : print('NO') break else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; if (n->compareTo(m)) >= 0 then ( execute ('NO')->display() ) else ( var total_seat : double := 2 * a->first() + 1 - Set{a->first(), a->last()}->min() ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name total_seat)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (expr (expr (atom (number (integer 2)))) * (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) + (expr (atom (number (integer 1))))) - (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name total_seat)))) > (comparison (expr (atom (name m))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) ))))))))))))))) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(A,B,n): cnt=0 ; for i in range(n): for j in range(i,n): if(bin(A[i]| A[j]).count('1')==B[j]): cnt+=1 ; return cnt if __name__=="__main__" : A=[5,3,2,4,6,1]; B=[2,2,1,4,2,3]; size=len(A); print(solve(A,B,size)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( A := Sequence{5}->union(Sequence{3}->union(Sequence{2}->union(Sequence{4}->union(Sequence{6}->union(Sequence{ 1 }))))); ; B := Sequence{2}->union(Sequence{2}->union(Sequence{1}->union(Sequence{4}->union(Sequence{2}->union(Sequence{ 3 }))))); ; var size : int := (A)->size(); ; execute (solve(A, B, size))->display(); ) else skip; operation solve(A : OclAny, B : OclAny, n : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0; ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i, n-1) do ( if (bin(MathLib.bitwiseOr(A[i+1], A[j+1]))->count('1') = B[j+1]) then ( cnt := cnt + 1; ) else skip)) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import log10 def rightRotationDivisor(N): lastDigit=N % 10 rightRotation=(lastDigit*10**int(log10(N))+N//10) return rightRotation % N==0 def generateNumbers(m): for i in range(10**(m-1),10**m): if rightRotationDivisor(i): print(i) m=3 generateNumbers(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; m := 3 ; generateNumbers(m); operation rightRotationDivisor(N : OclAny) : OclAny pre: true post: true activity: var lastDigit : int := N mod 10 ; var rightRotation : double := (lastDigit * (10)->pow(("" + ((log10(N))))->toInteger()) + N div 10) ; return rightRotation mod N = 0; operation generateNumbers(m : OclAny) pre: true post: true activity: for i : Integer.subrange((10)->pow((m - 1)), (10)->pow(m)-1) do ( if rightRotationDivisor(i) then ( execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printArr(arr,n): for i in arr : print(i,end=" ") def generateArr(A,n): B=[0 for i in range(n)] for i in range(n): cnt=0 for j in range(i): if(A[j]% A[i]==0): cnt+=1 B[i]=cnt printArr(B,n) A=[3,5,1] n=len(A) generateArr(A,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; A := Sequence{3}->union(Sequence{5}->union(Sequence{ 1 })) ; n := (A)->size() ; generateArr(A, n); operation printArr(arr : OclAny, n : OclAny) pre: true post: true activity: for i : arr do ( execute (i)->display()); operation generateArr(A : OclAny, n : OclAny) pre: true post: true activity: var B : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( var cnt : int := 0 ; for j : Integer.subrange(0, i-1) do ( if (A[j+1] mod A[i+1] = 0) then ( cnt := cnt + 1 ) else skip) ; B[i+1] := cnt) ; printArr(B, n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countUnique(arr,n): s=set(); for i in range(n): s.add(arr[i]); count=pow(len(s),2); return count ; if __name__=="__main__" : arr=[1,2,2,4,2,5,3,5]; n=len(arr); print(countUnique(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{4}->union(Sequence{2}->union(Sequence{5}->union(Sequence{3}->union(Sequence{ 5 }))))))); ; n := (arr)->size(); ; execute (countUnique(arr, n))->display(); ) else skip; operation countUnique(arr : OclAny, n : OclAny) pre: true post: true activity: var s : Set := Set{}->union(()); ; for i : Integer.subrange(0, n-1) do ( execute ((arr[i+1]) : s);) ; var count : double := ((s)->size())->pow(2); ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math class Node : def __init__(self,data): self.data=data self.next=None def push(head,data): if not head : return Node(data) temp=Node(data) temp.next=head head=temp return head def countMinimun(head): freq={} temp=head while(temp): d=temp.data if d in freq : freq[d]=freq.get(d)+1 else : freq[d]=1 temp=temp.next minimum_freq=sys.maxsize for i in freq : minimum_freq=min(minimum_freq,freq.get(i)) countMin=0 for i in freq : if freq.get(i)==minimum_freq : countMin+=1 return countMin if __name__=='__main__' : head=None head=push(head,10) head=push(head,30) head=push(head,11) head=push(head,10) head=push(head,10) print(countMinimun(head)) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.next := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( head := null ; head := push(head, 10) ; head := push(head, 30) ; head := push(head, 11) ; head := push(head, 10) ; head := push(head, 10) ; execute (countMinimun(head))->display() ) else skip; operation push(head : OclAny, data : OclAny) : OclAny pre: true post: true activity: if not(head) then ( return (Node.newNode()).initialise(data) ) else skip ; var temp : Node := (Node.newNode()).initialise(data) ; temp.next := head ; head := temp ; return head; operation countMinimun(head : OclAny) : OclAny pre: true post: true activity: var freq : OclAny := Set{} ; temp := head ; while (temp) do ( var d : OclAny := temp.data ; if (freq)->includes(d) then ( freq[d+1] := freq.get(d) + 1 ) else ( freq[d+1] := 1 ) ; temp := temp.next) ; var minimum_freq : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; for i : freq do ( minimum_freq := Set{minimum_freq, freq.get(i)}->min()) ; var countMin : int := 0 ; for i : freq do ( if freq.get(i) = minimum_freq then ( countMin := countMin + 1 ) else skip) ; return countMin; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) s=2000000000000 for i in range(-100,101): su=0 for j in l : su+=(i-j)*(i-j) if sutoInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : int := 2000000000000 ; for i : Integer.subrange(-100, 101-1) do ( var su : int := 0 ; for j : l do ( su := su + (i - j) * (i - j)) ; if (su->compareTo(s)) < 0 then ( s := su ) else skip) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- EPS=0.0001 while True : try : a=list(map(float,input().split())) dd=a[0]*a[4]-a[3]*a[1] d1=a[2]*a[4]-a[5]*a[1] d2=a[0]*a[5]-a[3]*a[2] print("{0:.3f}{1:.3f}".format(d1/dd+EPS,d2/dd+EPS)) except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var EPS : double := 0.0001 ; while true do ( try ( var a : Sequence := ((input().split())->collect( _x | (OclType["double"])->apply(_x) )) ; var dd : double := a->first() * a[4+1] - a[3+1] * a[1+1] ; var d1 : double := a[2+1] * a[4+1] - a[5+1] * a[1+1] ; var d2 : double := a->first() * a[5+1] - a[3+1] * a[2+1] ; execute (StringLib.interpolateStrings("{0:.3f}{1:.3f}", Sequence{d1 / dd + EPS, d2 / dd + EPS}))->display()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=[int(i)for i in input().split()] ave=sum(A)//len(A) def cost(A,ave): return sum(map(lambda x :(x-ave)**2,A)) c=cost(A,ave) c1=cost(A,ave+1) if cc1 : ave+=1 c,c1=c1,cost(A,ave) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ave : int := (A)->sum() div (A)->size() ; skip ; var c : OclAny := cost(A, ave) ; var c1 : OclAny := cost(A, ave + 1) ; if (c->compareTo(c1)) < 0 then ( while (c->compareTo(c1)) < 0 do ( ave := ave - 1 ; Sequence{c,c1} := Sequence{cost(A, ave),c}) ; execute (c1)->display() ) else ( while (c->compareTo(c1)) > 0 do ( ave := ave + 1 ; Sequence{c,c1} := Sequence{c1,cost(A, ave)}) ; execute (c)->display() ); operation cost(A : OclAny, ave : OclAny) : OclAny pre: true post: true activity: return ((A)->collect( _x | (lambda x : OclAny in (((x - ave))->pow(2)))->apply(_x) ))->sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import statistics N=int(input()) a=list(input().split()) a=[int(i)for i in a] res=[] for i in range(min(int(statistics.mean(a)),int(statistics.median(a))),max(int(statistics.mean(a))+1,int(statistics.median(a))+1+1)): res.append(0) for j in a : res[-1]+=(j-i)**2 print(min(res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (input().split()) ; a := a->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var res : Sequence := Sequence{} ; for i : Integer.subrange(Set{("" + ((statistics.mean(a))))->toInteger(), ("" + ((statistics.median(a))))->toInteger()}->min(), Set{("" + ((statistics.mean(a))))->toInteger() + 1, ("" + ((statistics.median(a))))->toInteger() + 1 + 1}->max()-1) do ( execute ((0) : res) ; for j : a do ( res->last() := res->last() + ((j - i))->pow(2))) ; execute ((res)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin ni=lambda : int(ns()) na=lambda : list(map(int,stdin.readline().split())) ns=lambda : stdin.readline() n=ni() li=na() ans=float("inf") for j in range(-100,101): ct=0 for i in range(n): ct+=(li[i]-j)**2 ans=min(ans,ct) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stdin : OclFile := OclFile["System.in"] ; var ni : Function := lambda $$ : OclAny in (("" + ((ns())))->toInteger()) ; var na : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ns : Function := lambda $$ : OclAny in (stdin.readLine()) ; var n : OclAny := ni->apply() ; var li : OclAny := na->apply() ; var ans : double := ("" + (("inf")))->toReal() ; for j : Integer.subrange(-100, 101-1) do ( var ct : int := 0 ; for i : Integer.subrange(0, n-1) do ( ct := ct + ((li[i+1] - j))->pow(2)) ; ans := Set{ans, ct}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,m=map(int,input().split()) res='NO' a=sorted([int(x)for x in input().split()]) a.reverse() s=a[0]+1+a[0] for x in a[1 : n-1]: s+=x+1 s+=1 if s<=m : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var res : String := 'NO' ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))->sort() ; a := a->reverse() ; var s : OclAny := a->first() + 1 + a->first() ; for x : a.subrange(1+1, n - 1) do ( s := s + x + 1) ; s := s + 1 ; if (s->compareTo(m)) <= 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np N=int(input()) a=list(map(int,input().split())) ans=10**6 for i in range(min(a),max(a)+1): b=np.array(a) ans=min(ans,np.sum((b-i)**2)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : double := (10)->pow(6) ; for i : Integer.subrange((a)->min(), (a)->max() + 1-1) do ( var b : Sequence := (a) ; ans := Set{ans, MatrixLib.sumMatrix(((b - i))->pow(2))}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nextGreater(num1): l=len(num1); num=list(num1); i=l-1 ; while(i>=0): if(num[i]=='0'): num[i]='1' ; break ; else : num[i]='0' ; i-=1 ; num1=''.join(num); if(i<0): num1='1'+num1 ; return num1 ; num="10011" ; print("Binary representation of next number=",nextGreater(num)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; num := "10011"; ; execute ("Binary representation of next number=")->display();; operation nextGreater(num1 : OclAny) pre: true post: true activity: var l : int := (num1)->size(); ; var num : Sequence := (num1); ; var i : double := l - 1; ; while (i >= 0) do ( if (num[i+1] = '0') then ( num[i+1] := '1'; ; break; ) else ( num[i+1] := '0'; ) ; i := i - 1;) ; num1 := StringLib.sumStringsWithSeparator((num), ''); ; if (i < 0) then ( num1 := '1' + num1; ) else skip ; return num1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def _input(): return map(int,input().split()) n=int(input()) A=list(_input()) B=list(_input()) a=[A.count(i+1)for i in range(5)] b=[B.count(i+1)for i in range(5)] r1=r2=0 for i in range(5): if(a[i]+b[i])% 2!=0 : print(-1); exit() r1+=abs(a[i]-(a[i]+b[i])//2) r2+=abs(b[i]-(a[i]+b[i])//2) print(r1//2 if r1==r2 else-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := (_input()) ; var B : Sequence := (_input()) ; var a : Sequence := Integer.subrange(0, 5-1)->select(i | true)->collect(i | (A->count(i + 1))) ; var b : Sequence := Integer.subrange(0, 5-1)->select(i | true)->collect(i | (B->count(i + 1))) ; var r1 : OclAny := 0; var r2 : int := 0 ; for i : Integer.subrange(0, 5-1) do ( if (a[i+1] + b[i+1]) mod 2 /= 0 then ( execute (-1)->display(); exit() ) else skip ; r1 := r1 + (a[i+1] - (a[i+1] + b[i+1]) div 2)->abs() ; r2 := r2 + (b[i+1] - (a[i+1] + b[i+1]) div 2)->abs()) ; execute (if r1 = r2 then r1 div 2 else -1 endif)->display(); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def group_redistribution(): n_students=int(input()) students_a=list(map(int,input().split())) students_b=list(map(int,input().split())) grade_a=[] grade_b=[] changes=0 for i in range(5): grade_a.append(students_a.count(i+1)) grade_b.append(students_b.count(i+1)) if((students_a.count(i+1)-students_b.count(i+1))% 2!=0): print(-1) return changes+=abs(students_a.count(i+1)-students_b.count(i+1))/2 print(str(int(changes/2))) group_redistribution() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; group_redistribution(); operation group_redistribution() pre: true post: true activity: var n_students : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var students_a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var students_b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var grade_a : Sequence := Sequence{} ; var grade_b : Sequence := Sequence{} ; var changes : int := 0 ; for i : Integer.subrange(0, 5-1) do ( execute ((students_a->count(i + 1)) : grade_a) ; execute ((students_b->count(i + 1)) : grade_b) ; if ((students_a->count(i + 1) - students_b->count(i + 1)) mod 2 /= 0) then ( execute (-1)->display() ; return ) else skip ; changes := changes + (students_a->count(i + 1) - students_b->count(i + 1))->abs() / 2) ; execute (("" + ((("" + ((changes / 2)))->toInteger()))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : n=int(input()) a=[int(x)for x in input().split()] b=[int(x)for x in input().split()] va=[0]*10 vb=[0]*10 for i in range(n): va[a[i]-1]+=1 vb[b[i]-1]+=1 ca=[0]*10 cb=[0]*10 for i in range(len(va)): if va[i]!=vb[i]and(va[i]+vb[i])% 2==0 : if va[i]-vb[i]>0 : ca[i]=va[i]-((va[i]+vb[i])//2) else : cb[i]=vb[i]-((va[i]+vb[i])//2) elif va[i]!=vb[i]and(va[i]+vb[i])% 2!=0 : ca=[1] cb=[0] break if sum(ca)==sum(cb): print(sum(cb)) else : print("-1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var b : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var va : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; var vb : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; for i : Integer.subrange(0, n-1) do ( va[a[i+1] - 1+1] := va[a[i+1] - 1+1] + 1 ; vb[b[i+1] - 1+1] := vb[b[i+1] - 1+1] + 1) ; var ca : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; var cb : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; for i : Integer.subrange(0, (va)->size()-1) do ( if va[i+1] /= vb[i+1] & (va[i+1] + vb[i+1]) mod 2 = 0 then ( if va[i+1] - vb[i+1] > 0 then ( ca[i+1] := va[i+1] - ((va[i+1] + vb[i+1]) div 2) ) else ( cb[i+1] := vb[i+1] - ((va[i+1] + vb[i+1]) div 2) ) ) else (if va[i+1] /= vb[i+1] & (va[i+1] + vb[i+1]) mod 2 /= 0 then ( ca := Sequence{ 1 } ; cb := Sequence{ 0 } ; break ) else skip)) ; if (ca)->sum() = (cb)->sum() then ( execute ((cb)->sum())->display() ) else ( execute ("-1")->display() ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : n=int(input()) a=[int(x)for x in input().split()] b=[int(x)for x in input().split()] va=[0]*10 vb=[0]*10 for i in range(n): va[a[i]-1]+=1 vb[b[i]-1]+=1 ca=[0]*10 cb=[0]*10 for i in range(len(va)): if va[i]!=vb[i]and(va[i]+vb[i])% 2==0 : if va[i]-vb[i]>0 : ca[i]=va[i]-((va[i]+vb[i])//2) else : cb[i]=vb[i]-((va[i]+vb[i])//2) elif va[i]!=vb[i]and(va[i]+vb[i])% 2!=0 : ca=[1] cb=[0] break if sum(ca)==sum(cb): print(sum(cb)) else : print("-1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var b : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var va : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; var vb : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; for i : Integer.subrange(0, n-1) do ( va[a[i+1] - 1+1] := va[a[i+1] - 1+1] + 1 ; vb[b[i+1] - 1+1] := vb[b[i+1] - 1+1] + 1) ; var ca : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; var cb : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; for i : Integer.subrange(0, (va)->size()-1) do ( if va[i+1] /= vb[i+1] & (va[i+1] + vb[i+1]) mod 2 = 0 then ( if va[i+1] - vb[i+1] > 0 then ( ca[i+1] := va[i+1] - ((va[i+1] + vb[i+1]) div 2) ) else ( cb[i+1] := vb[i+1] - ((va[i+1] + vb[i+1]) div 2) ) ) else (if va[i+1] /= vb[i+1] & (va[i+1] + vb[i+1]) mod 2 /= 0 then ( ca := Sequence{ 1 } ; cb := Sequence{ 0 } ; break ) else skip)) ; if (ca)->sum() = (cb)->sum() then ( execute ((cb)->sum())->display() ) else ( execute ("-1")->display() ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) input() A,B=input(),input() D=[abs(A.count(x)-B.count(x))for x in '12345'] print(-1 if any(d % 2 for d in D)else sum(D)//4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; input() ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine()} ; var D : Sequence := '12345'->characters()->select(x | true)->collect(x | ((A->count(x) - B->count(x))->abs())) ; execute (if ((argument (test (logical_test (comparison (expr (expr (atom (name d))) % (expr (atom (number (integer 2)))))))) (comp_for for (exprlist (expr (atom (name d)))) in (logical_test (comparison (expr (atom (name D))))))))->exists( _x | _x = true ) then -1 else (D)->sum() div 4 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def inverse(a,b,d,e): deta=a*e-b*d return(deta,e,-b,-d,a) while True : data=sys.stdin.readline() if data is None or data.strip()=='' : break data=data.strip().split(' ') a,b,c,d,e,f=[float(i)for i in data] inv=inverse(a,b,d,e) x=(inv[1]*c+inv[2]*f)/inv[0]+0 y=(inv[3]*c+inv[4]*f)/inv[0]+0 print('%.3f %.3f' %(x,y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( var data : String := (OclFile["System.in"]).readLine() ; if data <>= null or data->trim() = '' then ( break ) else skip ; data := data->trim().split(' ') ; var c : OclAny := null; var f : OclAny := null; Sequence{a,b,c,d,e,f} := data->characters()->select(i | true)->collect(i | (("" + ((i)))->toReal())) ; var inv : OclAny := inverse(a, b, d, e) ; var x : double := (inv[1+1] * c + inv[2+1] * f) / inv->first() + 0 ; var y : double := (inv[3+1] * c + inv[4+1] * f) / inv->first() + 0 ; execute (StringLib.format('%.3f %.3f',Sequence{x, y}))->display()); operation inverse(a : OclAny, b : OclAny, d : OclAny, e : OclAny) : OclAny pre: true post: true activity: var deta : double := a * e - b * d ; return Sequence{deta, e, -b, -d, a}; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNumber(s,d): num="" ; val=s//d ; rem=s % d ; for i in range(1,d-rem+1): num=num+str(val); if(rem): val+=1 ; for i in range(d-rem+1,d+1): num=num+str(val); return num ; if __name__=="__main__" : s=25 ; d=4 ; print(findNumber(s,d)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := 25; d := 4; ; execute (findNumber(s, d))->display(); ) else skip; operation findNumber(s : OclAny, d : OclAny) pre: true post: true activity: var num : String := ""; ; var val : int := s div d; ; var rem : int := s mod d; ; for i : Integer.subrange(1, d - rem + 1-1) do ( num := num + ("" + ((val)));) ; if (rem) then ( val := val + 1; ; for i : Integer.subrange(d - rem + 1, d + 1-1) do ( num := num + ("" + ((val)));) ) else skip ; return num;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=100 def pre_process(dp,s): n=len(s) for i in range(n): for j in range(n): dp[i][j]=False for j in range(1,n+1): for i in range(n-j+1): if(j<=2): if(s[i]==s[i+j-1]): dp[i][i+j-1]=True elif(s[i]==s[i+j-1]): dp[i][i+j-1]=dp[i+1][i+j-2] def answerQuery(l,r,dp): if(dp[l][r]): print("Yes") else : print("No") s="abaaab" dp=[[0 for i in range(N)]for i in range(N)] pre_process(dp,s) queries=[[0,1],[1,5]] q=len(queries) for i in range(q): answerQuery(queries[i][0],queries[i][1],dp) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 100 ; skip ; skip ; s := "abaaab" ; dp := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)))) ; pre_process(dp, s) ; var queries : Sequence := Sequence{Sequence{0}->union(Sequence{ 1 })}->union(Sequence{ Sequence{1}->union(Sequence{ 5 }) }) ; var q : int := (queries)->size() ; for i : Integer.subrange(0, q-1) do ( answerQuery(queries[i+1]->first(), queries[i+1][1+1], dp)); operation pre_process(dp : OclAny, s : OclAny) pre: true post: true activity: var n : int := (s)->size() ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( dp[i+1][j+1] := false)) ; for j : Integer.subrange(1, n + 1-1) do ( for i : Integer.subrange(0, n - j + 1-1) do ( if (j <= 2) then ( if (s[i+1] = s[i + j - 1+1]) then ( dp[i+1][i + j - 1+1] := true ) else skip ) else (if (s[i+1] = s[i + j - 1+1]) then ( dp[i+1][i + j - 1+1] := dp[i + 1+1][i + j - 2+1] ) else skip))); operation answerQuery(l : OclAny, r : OclAny, dp : OclAny) pre: true post: true activity: if (dp[l+1][r+1]) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) graph=[[]for i in range(n)] for i in range(n): a,b=list(map(int,input().split())) graph[i]=[a,b] def inasi(ls,i): n=[] for j in range(len(ls)): if j==i : continue n.append(ls[j]) return n def kyori(ls): ans=0 for i in range(len(ls)-1): ans+=math.sqrt((graph[ls[i]][0]-graph[ls[i+1]][0])**2+(graph[ls[i]][1]-graph[ls[i+1]][1])**2) return ans check=0 count=0 def keisan(n,pls,ls): global check,count if len(ls)==0 : check+=kyori(pls) count+=1 return for i in range(len(ls)): pls.append(ls[i]) keisan(n-1,pls,inasi(ls,i)) try : pls.pop() except : pass return keisan(10,[],[i for i in range(n)]) print(check/count) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute check : OclAny; attribute count : OclAny; operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var graph : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; graph[i+1] := Sequence{a}->union(Sequence{ b })) ; skip ; skip ; var check : int := 0 ; var count : int := 0 ; skip ; keisan(10, Sequence{}, Integer.subrange(0, n-1)->select(i | true)->collect(i | (i))) ; execute (check / count)->display(); operation inasi(ls : OclAny, i : OclAny) : OclAny pre: true post: true activity: n := Sequence{} ; for j : Integer.subrange(0, (ls)->size()-1) do ( if j = i then ( continue ) else skip ; execute ((ls[j+1]) : n)) ; return n; operation kyori(ls : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, (ls)->size() - 1-1) do ( ans := ans + (((graph[ls[i+1]+1]->first() - graph[ls[i + 1+1]+1]->first()))->pow(2) + ((graph[ls[i+1]+1][1+1] - graph[ls[i + 1+1]+1][1+1]))->pow(2))->sqrt()) ; return ans; operation keisan(n : OclAny, pls : OclAny, ls : OclAny) pre: true post: true activity: skip; skip ; if (ls)->size() = 0 then ( check := check + kyori(pls) ; count := count + 1 ; return ) else skip ; for i : Integer.subrange(0, (ls)->size()-1) do ( execute ((ls[i+1]) : pls) ; keisan(n - 1, pls, inasi(ls, i)) ; try ( pls := pls->front()) catch (_e : OclException) do ( skip) ) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,A,B=map(int,input().split()) X=list(map(int,input().split())) ans=0 for i in range(N-1): if(X[i+1]-X[i])*A<=B : ans+=(X[i+1]-X[i])*A else : ans+=B print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{N,A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var X : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(0, N - 1-1) do ( if ((X[i + 1+1] - X[i+1]) * A->compareTo(B)) <= 0 then ( ans := ans + (X[i + 1+1] - X[i+1]) * A ) else ( ans := ans + B )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.readline().strip() def input_int(): return int(input()) def input_int_list(): return[int(i)for i in input().split()] def main(): n,a,b=input_int_list() X=input_int_list() dp=[0]*(n) for i in range(1,n): dp[i]=min(dp[i-1]+(X[i]-X[i-1])*a,dp[i-1]+b) print(dp[n-1]) return if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation input_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation input_int_list() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation main() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := input_int_list() ; var X : OclAny := input_int_list() ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n)) ; for i : Integer.subrange(1, n-1) do ( dp[i+1] := Set{dp[i - 1+1] + (X[i+1] - X[i - 1+1]) * a, dp[i - 1+1] + b}->min()) ; execute (dp[n - 1+1])->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): [n,a,b]=list(map(int,input().split())) m=list(map(int,input().split())) cost=0 for i in range(1,n): cost+=min([a*(m[i]-m[i-1]),b]) print(cost) if __name__=="__main__" : import sys import os if len(sys.argv)>1 : if sys.argv[1]=="-d" : filename="input1.txt" fd=os.open(filename,os.O_RDONLY) os.dup2(fd,sys.stdin.fileno()) main() else : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( skip ; skip ; if ((trailer . (name argv)))->size() > 1 then ( if (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) = "-d" then ( var filename : String := "input1.txt" ; var fd : OclAny := os.open(filename, os.O_RDONLY) ; os.dup2(fd, (OclFile["System.in"]).fileno()) ; main() ) else skip ) else ( main() ) ) else skip; operation main() pre: true post: true activity: ; Sequence{n}->union(Sequence{a}->union(Sequence{ b })) := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cost : int := 0 ; for i : Integer.subrange(1, n-1) do ( cost := cost + (Sequence{a * (m[i+1] - m[i - 1+1])}->union(Sequence{ b }))->min()) ; execute (cost)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,A,B=[int(i)for i in input().split()] X=[int(i)for i in input().split()] res=0 for i in range(N-1): dist=X[i+1]-X[i] res+=min(A*dist,B) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{N,A,B} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var X : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var res : int := 0 ; for i : Integer.subrange(0, N - 1-1) do ( var dist : double := X[i + 1+1] - X[i+1] ; res := res + Set{A * dist, B}->min()) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,A,B=map(int,input().split(" ")) X=list(map(int,input().split(" "))) print(sum([min(A*(X[i+1]-X[i]),B)for i in range(N-1)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{N,A,B} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var X : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((Integer.subrange(0, N - 1-1)->select(i | true)->collect(i | (Set{A * (X[i + 1+1] - X[i+1]), B}->min())))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- with open("input.txt","r")as inp : n,m=map(int,inp.read().split()) res="" if m>=n : for i in range(n): res+="GB" res+="G"*(m-n) else : for i in range(m): res+="BG" res+="B"*(n-m) with open("output.txt","w")as out : out.write(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: try (var inp : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")); var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (inp.readAll().split())->collect( _x | (OclType["int"])->apply(_x) )) catch (_e : OclException) do skip ; var res : String := "" ; if (m->compareTo(n)) >= 0 then ( for i : Integer.subrange(0, n-1) do ( res := res + "GB") ; res := res + StringLib.nCopies("G", (m - n)) ) else ( for i : Integer.subrange(0, m-1) do ( res := res + "BG") ; res := res + StringLib.nCopies("B", (n - m)) ) ; try (var out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")); out.write(res)) catch (_e : OclException) do skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=open("input.txt",'r') n,m=map(int,f.readline().split()) ans='' if n>m : for i in range(n+m): if i<2*m : if i % 2==0 : ans+='B' else : ans+='G' else : ans+='B' else : for i in range(n+m): if i<2*n : if i % 2==0 : ans+='G' else : ans+='B' else : ans+='G' o=open('output.txt','w') o.write(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : String := '' ; if (n->compareTo(m)) > 0 then ( for i : Integer.subrange(0, n + m-1) do ( if (i->compareTo(2 * m)) < 0 then ( if i mod 2 = 0 then ( ans := ans + 'B' ) else ( ans := ans + 'G' ) ) else ( ans := ans + 'B' )) ) else ( for i : Integer.subrange(0, n + m-1) do ( if (i->compareTo(2 * n)) < 0 then ( if i mod 2 = 0 then ( ans := ans + 'G' ) else ( ans := ans + 'B' ) ) else ( ans := ans + 'G' )) ) ; var o : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('output.txt')) ; o.write(ans); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=open("input.txt",'r'); g=open("output.txt",'w') n,m=map(int,f.readline().split()) g.write(['BG'*m+'B'*(n-m),'GB'*n+'G'*(m-n)][ncollect( _x | (OclType["int"])->apply(_x) ) ; g.write(Sequence{StringLib.nCopies('BG', m) + StringLib.nCopies('B', (n - m))}->union(Sequence{ StringLib.nCopies('GB', n) + StringLib.nCopies('G', (m - n)) })->select((n->compareTo(m)) < 0)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- try : while True : a,b,c,d,e,f=map(float,input().split()) if a-d==0 : y=(c-f)/(b-e) x=(c-b*y)/a else : A=a*d D=d*a B=b*d C=c*d E=e*a F=f*a if Ccollect( _x | (OclType["double"])->apply(_x) ) ; if a - d = 0 then ( var y : double := (c - f) / (b - e) ; var x : double := (c - b * y) / a ) else ( var A : double := a * d ; var D : double := d * a ; var B : double := b * d ; var C : double := c * d ; var E : double := e * a ; var F : double := f * a ; if (C->compareTo(F)) < 0 then ( y := (C - F) / (B - E) ; x := (c - b * y) / a ) else ( y := (F - C) / (E - B) ; x := (c - b * y) / a ) ) ; execute (StringLib.formattedString('{round(x,3):.03f}'))->display())) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt pass))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter import math hpop=heappop hpush=heappush def solution(): file=open("input.txt",'r') b,g=map(int,file.readline().split()) res=[] if b>g : res.append("B") b-=1 else : res.append("G") g-=1 while b and g : if res[-1]=="G" : res.append("B") b-=1 else : res.append("G") g-=1 res.append("B"*b) res.append("G"*g) file.close() file=open("output.txt",'w') file.write("".join(res)) def main(): t=1 for _ in range(t): solution() import sys import threading sys.setrecursionlimit(1<<30) threading.stack_size(1<<27) thread=threading.Thread(target=main) thread.start(); thread.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1 * (2->pow(30))) ; threading.stack_size(1 * (2->pow(27))) ; var thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ; thread.start(); thread.join(); operation solution() pre: true post: true activity: var file : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ; var b : OclAny := null; var g : OclAny := null; Sequence{b,g} := (file.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var res : Sequence := Sequence{} ; if (b->compareTo(g)) > 0 then ( execute (("B") : res) ; b := b - 1 ) else ( execute (("G") : res) ; g := g - 1 ) ; while b & g do ( if res->last() = "G" then ( execute (("B") : res) ; b := b - 1 ) else ( execute (("G") : res) ; g := g - 1 )) ; execute ((StringLib.nCopies("B", b)) : res) ; execute ((StringLib.nCopies("G", g)) : res) ; file.closeFile() ; file := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ; file.write(StringLib.sumStringsWithSeparator((res), "")); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines import numpy as np N=int(readline()) XY=np.array(read().split(),np.int64) X=XY[: : 2]; Y=XY[1 : : 2] dx=X[:,None]-X[None,:] dy=Y[:,None]-Y[None,:] dist_mat=(dx*dx+dy*dy)**.5 answer=dist_mat.sum()/N print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; skip ; var N : int := ("" + ((readline())))->toInteger() ; var XY : Sequence := (read().split(), ) ; var X : OclAny := XY(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))); var Y : OclAny := XY(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ; var dx : double := X->collect( _r | _r[null+1] ) - X[null+1] ; var dy : double := Y->collect( _r | _r[null+1] ) - Y[null+1] ; var dist_mat : double := ((dx * dx + dy * dy))->pow(.5) ; var answer : double := dist_mat.sum() / N ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inputs=open("input.txt","r") outputs=open("output.txt","w") n,m=map(int,inputs.readline().split()) if(n>=m): for i in range(m): outputs.write("BG") outputs.write("B"*(n-m)) else : for i in range(n): outputs.write("GB") outputs.write("G"*(m-n)) inputs.close() outputs.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inputs : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ; var outputs : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (inputs.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if ((n->compareTo(m)) >= 0) then ( for i : Integer.subrange(0, m-1) do ( outputs.write("BG")) ; outputs.write(StringLib.nCopies("B", (n - m))) ) else ( for i : Integer.subrange(0, n-1) do ( outputs.write("GB")) ; outputs.write(StringLib.nCopies("G", (m - n))) ) ; inputs.closeFile() ; outputs.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sortArrays(arr): length=len(arr) j=0 while jarr[j+1]): temp=arr[j] arr[j]=arr[j+1] arr[j+1]=temp j=-1 j+=1 return arr if __name__=='__main__' : arr=[1,2,99,9,8,7,6,0,5,4,3] print("Original array: ",arr) arr=sortArrays(arr) print("Sorted array: ",arr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{99}->union(Sequence{9}->union(Sequence{8}->union(Sequence{7}->union(Sequence{6}->union(Sequence{0}->union(Sequence{5}->union(Sequence{4}->union(Sequence{ 3 })))))))))) ; execute ("Original array: ")->display() ; arr := sortArrays(arr) ; execute ("Sorted array: ")->display() ) else skip; operation sortArrays(arr : OclAny) : OclAny pre: true post: true activity: var length : int := (arr)->size() ; var j : int := 0 ; while (j->compareTo(length - 1)) < 0 do ( if ((arr[j+1]->compareTo(arr[j + 1+1])) > 0) then ( var temp : OclAny := arr[j+1] ; arr[j+1] := arr[j + 1+1] ; arr[j + 1+1] := temp ; j := -1 ) else skip ; j := j + 1) ; return arr; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def squareSum(n): return int(2*n*(n+1)*(2*n+1)/3) ans=squareSum(8) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var ans : OclAny := squareSum(8) ; execute (ans)->display(); operation squareSum(n : OclAny) : OclAny pre: true post: true activity: return ("" + ((2 * n * (n + 1) * (2 * n + 1) / 3)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def squaresum(n): return(n*(n+1)/2)*(2*n+1)/3 n=4 print(squaresum(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute (squaresum(n))->display();; operation squaresum(n : OclAny) : OclAny pre: true post: true activity: return (n * (n + 1) / 2) * (2 * n + 1) / 3; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def intersection(n): return n*(n-1); print(intersection(3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (intersection(3))->display(); operation intersection(n : OclAny) pre: true post: true activity: return n * (n - 1);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def sumOfSeries(n): return int((n*(2*n-1)*(2*n+1))/3) n=10 print(sumOfSeries(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 10 ; execute (sumOfSeries(n))->display(); operation sumOfSeries(n : OclAny) : OclAny pre: true post: true activity: return ("" + (((n * (2 * n - 1) * (2 * n + 1)) / 3)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def squaresum(n): return(n*(n+1)*(2*n+1))//6 n=4 print(squaresum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute (squaresum(n))->display(); operation squaresum(n : OclAny) : OclAny pre: true post: true activity: return (n * (n + 1) * (2 * n + 1)) div 6; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) arr=list(map(int,input().split())) a=[0]*3 for x in arr : a[x % 3]+=1 while a[1]and a[2]: a[0]+=1 a[1]-=1 a[2]-=1 a[0]+=a[1]//3 a[0]+=a[2]//3 print(a[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 3) ; for x : arr do ( a[x mod 3+1] := a[x mod 3+1] + 1) ; while a[1+1] & a[2+1] do ( a->first() := a->first() + 1 ; a[1+1] := a[1+1] - 1 ; a[2+1] := a[2+1] - 1) ; a->first() := a->first() + a[1+1] div 3 ; a->first() := a->first() + a[2+1] div 3 ; execute (a->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math t=int(input()) for _ in range(t): n=int(input()) arr=list(map(int,input().split())) mem=[0 for i in range(3)] for i in range(len(arr)): mem[arr[i]% 3]+=1 ans=0 ans+=mem[0] pos=min(mem[1],mem[2]) mem[1]-=pos mem[2]-=pos ans+=pos ans+=(mem[1]+mem[2])//3 print(int(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mem : Sequence := Integer.subrange(0, 3-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, (arr)->size()-1) do ( mem[arr[i+1] mod 3+1] := mem[arr[i+1] mod 3+1] + 1) ; var ans : int := 0 ; ans := ans + mem->first() ; var pos : OclAny := Set{mem[1+1], mem[2+1]}->min() ; mem[1+1] := mem[1+1] - pos ; mem[2+1] := mem[2+1] - pos ; ans := ans + pos ; ans := ans + (mem[1+1] + mem[2+1]) div 3 ; execute (("" + ((ans)))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import fileinput input=fileinput.input() while True : n=int(next(input).strip()) if not n : break t=[0,0] for _ in range(n): [a,b]=map(int,next(input).strip().split()) if a==b : t[0]+=a t[1]+=b else : t[atrim())))->toInteger() ; if not(n) then ( break ) else skip ; var t : Sequence := Sequence{0}->union(Sequence{ 0 }) ; for _anon : Integer.subrange(0, n-1) do (suite)) ; Sequence{a}->union(Sequence{ b }) := (next(input)->trim().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calc_dist(x1,x2,y1,y2): return((x1-x2)**2+(y1-y2)**2)**0.5 def main(): from itertools import permutations n=int(input()) xy=[list(map(int,input().split()))for _ in range(n)] total=0 m=len(list(permutations(range(n)))) for p in permutations(range(n)): for i in range(len(p)-1): a=p[i] b=p[i+1] total+=calc_dist(xy[a][0],xy[b][0],xy[a][1],xy[b][1]) print(total/m) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation calc_dist(x1 : OclAny, x2 : OclAny, y1 : OclAny, y2 : OclAny) : OclAny pre: true post: true activity: return ((((x1 - x2))->pow(2) + ((y1 - y2))->pow(2)))->pow(0.5); operation main() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var xy : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var total : int := 0 ; var m : int := ((permutations(Integer.subrange(0, n-1))))->size() ; for p : permutations(Integer.subrange(0, n-1)) do ( for i : Integer.subrange(0, (p)->size() - 1-1) do ( var a : OclAny := p[i+1] ; var b : OclAny := p[i + 1+1] ; total := total + calc_dist(xy[a+1]->first(), xy[b+1]->first(), xy[a+1][1+1], xy[b+1][1+1]))) ; execute (total / m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : (a,b,c,d,e,f)=map(int,input().split()) except : break g=(a*e)-(b*d) ans1="{0:.3f}".format(((e*c)+(-b*f))/g+0) ans2="{0:.3f}".format(((-d*c)+(a*f))/g+0) print(ans1,ans2) ------------------------------------------------------------ OCL File: --------- class FromPython { suite`nestedAttributeDefinitions operation initialise() pre: true post: true activity: while true do ( try (suite)) ; var Sequence{a, b, c, d, e, f} : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t = int(input()) for i in range(t): n = int(input()) a = input().split() for e in range(len(a)): a[e] = int(a[e]) divisibleby3 = [] mod1 = [] mod2 = [] for number in a: if number % 3 == 0: divisibleby3.append(number) elif number % 3 == 1: mod1.append(number) else: mod2.append(number) if len(mod1) == len(mod2): print(len(divisibleby3) + len(mod1)) elif len(mod1) > len(mod2): print(len(divisibleby3) + len(mod2) + (len(mod1) - len(mod2)) // 3) else: print(len(divisibleby3) + len(mod1) + (len(mod2) - len(mod1)) // 3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := input().split() ; for e : Integer.subrange(0, (a)->size()-1) do ( a[e+1] := ("" + ((a[e+1])))->toInteger()) ; var divisibleby3 : Sequence := Sequence{} ; var mod1 : Sequence := Sequence{} ; var mod2 : Sequence := Sequence{} ; for number : a do ( if number mod 3 = 0 then ( execute ((number) : divisibleby3) ) else (if number mod 3 = 1 then ( execute ((number) : mod1) ) else ( execute ((number) : mod2) ) ) ) ; if (mod1)->size() = (mod2)->size() then ( execute ((divisibleby3)->size() + (mod1)->size())->display() ) else (if ((mod1)->size()->compareTo((mod2)->size())) > 0 then ( execute ((divisibleby3)->size() + (mod2)->size() + ((mod1)->size() - (mod2)->size()) div 3)->display() ) else ( execute ((divisibleby3)->size() + (mod1)->size() + ((mod2)->size() - (mod1)->size()) div 3)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): l=[] n=int(input()) y=0 temp=list(map(int,input().split())) for i in temp : if i % 3!=0 : l.append(i % 3) else : y+=1 t1=l.count(1) t2=l.count(2) x=min(t1,t2) t1=t1-x t2=t2-x if t1!=0 : x+=t1//3 if t2!=0 : x+=t2//3 print(y+x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var l : Sequence := Sequence{} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var y : int := 0 ; var temp : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : temp do ( if i mod 3 /= 0 then ( execute ((i mod 3) : l) ) else ( y := y + 1 )) ; var t1 : int := l->count(1) ; var t2 : int := l->count(2) ; var x : OclAny := Set{t1, t2}->min() ; t1 := t1 - x ; t2 := t2 - x ; if t1 /= 0 then ( x := x + t1 div 3 ) else skip ; if t2 /= 0 then ( x := x + t2 div 3 ) else skip ; execute (y + x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys for i in range(int(input())): n=int(input()) arr=list(map(int,input().split())) d1=0 d2=0 d3=0 for i in range(n): if(arr[i]% 3==0): d3+=1 elif(arr[i]% 3==1): d1+=1 else : d2+=1 m=min(d2,d1) d2=d2-m d1=d1-m d=d1//3 x=d2//3 d3=d3+(m+d+x) print(d3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d1 : int := 0 ; var d2 : int := 0 ; var d3 : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] mod 3 = 0) then ( d3 := d3 + 1 ) else (if (arr[i+1] mod 3 = 1) then ( d1 := d1 + 1 ) else ( d2 := d2 + 1 ) ) ) ; var m : OclAny := Set{d2, d1}->min() ; d2 := d2 - m ; d1 := d1 - m ; var d : int := d1 div 3 ; var x : int := d2 div 3 ; d3 := d3 + (m + d + x) ; execute (d3)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def costToPanagram(string,cost): n=len(string) occurrences=[0]*26 for i in range(n): occurrences[ord(string[i])-ord('a')]+=1 gain=0 for i in range(26): if occurrences[i]==0 : gain-=2*cost[i] elif occurrences[i]>1 : gain+=cost[i]*(occurrences[i]-1) if gain>=0 : return 0 return gain*-1 if __name__=="__main__" : cost=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] string="geeksforgeeks" print(costToPanagram(string,cost)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( cost := Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))))))))))))))))))))))))) ; string := "geeksforgeeks" ; execute (costToPanagram(string, cost))->display() ) else skip; operation costToPanagram(string : OclAny, cost : OclAny) : OclAny pre: true post: true activity: var n : int := (string)->size() ; var occurrences : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for i : Integer.subrange(0, n-1) do ( occurrences[(string[i+1])->char2byte() - ('a')->char2byte()+1] := occurrences[(string[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; var gain : int := 0 ; for i : Integer.subrange(0, 26-1) do ( if occurrences[i+1] = 0 then ( gain := gain - 2 * cost[i+1] ) else (if occurrences[i+1] > 1 then ( gain := gain + cost[i+1] * (occurrences[i+1] - 1) ) else skip)) ; if gain >= 0 then ( return 0 ) else skip ; return gain * -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,f,b=map(int,input().split()) if m>=b : print(0) elif(m+f)>=b : print(b-m) else : print("NA") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var f : OclAny := null; var b : OclAny := null; Sequence{m,f,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (m->compareTo(b)) >= 0 then ( execute (0)->display() ) else (if ((m + f)->compareTo(b)) >= 0 then ( execute (b - m)->display() ) else ( execute ("NA")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,list(input().split(" "))) m=max(0,c-a) if(a+b>=c): print(m) else : print("NA") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := ((input().split(" ")))->collect( _x | (OclType["int"])->apply(_x) ) ; var m : OclAny := Set{0, c - a}->max() ; if ((a + b->compareTo(c)) >= 0) then ( execute (m)->display() ) else ( execute ("NA")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,f,b=map(int,input().split()) if mf : print("NA") else : print(b-m) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var f : OclAny := null; var b : OclAny := null; Sequence{m,f,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (m->compareTo(b)) < 0 then ( if (b - m->compareTo(f)) > 0 then ( execute ("NA")->display() ) else ( execute (b - m)->display() ) ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,f,b=[int(s)for s in input().split()] x=b-m if m>=b : print(0) elif f>=x : print(x) else : print('NA') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var f : OclAny := null; var b : OclAny := null; Sequence{m,f,b} := input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; var x : double := b - m ; if (m->compareTo(b)) >= 0 then ( execute (0)->display() ) else (if (f->compareTo(x)) >= 0 then ( execute (x)->display() ) else ( execute ('NA')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,f,b=map(int,input().split()) lending=max(b-m,0) if lending<=f : print(lending) else : print("NA") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var f : OclAny := null; var b : OclAny := null; Sequence{m,f,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lending : OclAny := Set{b - m, 0}->max() ; if (lending->compareTo(f)) <= 0 then ( execute (lending)->display() ) else ( execute ("NA")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSum(n,a,b): sum=0 for i in range(0,n,1): if(i % a==0 or i % b==0): sum+=i return sum if __name__=='__main__' : n=10 a=3 b=5 print(findSum(n,a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 10 ; a := 3 ; b := 5 ; execute (findSum(n, a, b))->display() ) else skip; operation findSum(n : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (i mod a = 0 or i mod b = 0) then ( sum := sum + i ) else skip) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt from itertools import permutations def dist(x1,y1,x2,y2): return sqrt((x1-x2)**2+(y1-y2)**2) n=int(input()) xy=[list(map(float,input().split()))for _ in range(n)] sm=0 cnt=0 for pat in permutations(xy,n): l=0 cnt+=1 for e1,e2 in zip(pat,pat[1 :]): x1,y1=e1 x2,y2=e2 l+=dist(x1,y1,x2,y2) sm+=l ans=sm/cnt print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var xy : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["double"])->apply(_x) )))) ; var sm : int := 0 ; var cnt : int := 0 ; for pat : permutations(xy, n) do ( var l : int := 0 ; cnt := cnt + 1 ; for _tuple : Integer.subrange(1, pat->size())->collect( _indx | Sequence{pat->at(_indx), pat->tail()->at(_indx)} ) do (var _indx : int := 1; var e1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var e2 : OclAny := _tuple->at(_indx); Sequence{x1,y1} := e1 ; Sequence{x2,y2} := e2 ; l := l + dist(x1, y1, x2, y2)) ; sm := sm + l) ; var ans : double := sm / cnt ; execute (ans)->display(); operation dist(x1 : OclAny, y1 : OclAny, x2 : OclAny, y2 : OclAny) : OclAny pre: true post: true activity: return sqrt(((x1 - x2))->pow(2) + ((y1 - y2))->pow(2)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def xorPairCount(arr,n,x): result=0 s=set() for i in range(0,n): if(x ^ arr[i]in s): result=result+1 s.add(arr[i]) return result if __name__=="__main__" : arr=[5,4,10,15,7,6] n=len(arr) x=5 print("Count of pair with given XOR="+str(xorPairCount(arr,n,x))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{5}->union(Sequence{4}->union(Sequence{10}->union(Sequence{15}->union(Sequence{7}->union(Sequence{ 6 }))))) ; n := (arr)->size() ; x := 5 ; execute ("Count of pair with given XOR=" + ("" + ((xorPairCount(arr, n, x)))))->display() ) else skip; operation xorPairCount(arr : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; var s : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( if ((s)->includes(MathLib.bitwiseXor(x, arr[i+1]))) then ( result := result + 1 ) else skip ; execute ((arr[i+1]) : s)) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys for line in sys.stdin : a,b,c,d,e,f=list(map(int,line.split())) y=(f-(d*c)/a)/((a*e-d*b)/a) x=(c-b*y)/a print('%03.3f' % x,'%03.3f' % y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for line : OclFile["System.in"] do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; var f : OclAny := null; Sequence{a,b,c,d,e,f} := ((line.split())->collect( _x | (OclType["int"])->apply(_x) )) ; var y : double := (f - (d * c) / a) / ((a * e - d * b) / a) ; var x : double := (c - b * y) / a ; execute (StringLib.format('%03.3f',x))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minSum(arr,n): evenArr=[] oddArr=[] arr.sort() for i in range(n): if(iunion(Sequence{5}->union(Sequence{8}->union(Sequence{9}->union(Sequence{6}->union(Sequence{7}->union(Sequence{3}->union(Sequence{4}->union(Sequence{2}->union(Sequence{ 0 }))))))))) ; n := (arr)->size() ; execute ("Minimum required sum=")->display() ; execute ("Sorted array in required format : ")->display() ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()) ) else skip; operation minSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var evenArr : Sequence := Sequence{} ; var oddArr : Sequence := Sequence{} ; arr := arr->sort() ; for i : Integer.subrange(0, n-1) do ( if ((i->compareTo(n div 2)) < 0) then ( execute ((arr[i+1]) : oddArr) ) else ( execute ((arr[i+1]) : evenArr) )) ; evenArr := evenArr->sort() ; var i : int := 0 ; var sum : int := 0 ; for j : Integer.subrange(0, (evenArr)->size()-1) do ( arr[i+1] := evenArr[j+1] ; i := i + 1 ; arr[i+1] := oddArr[j+1] ; i := i + 1 ; sum := sum + evenArr[j+1] * oddArr[j+1]) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) t,=R() while t : t-=1 n,x,y=R() if((x==0 and y==0)or(x!=0 and y!=0)or((n-1)% x!=0 if x!=0 else(n-1)% y!=0)): print(-1) else : win_record=[] current_win_record=[1,0] if(x==0): current_win_record[0]=2 for i in range(n-1): if(current_win_record[1]collect( _x | (OclType["int"])->apply(_x) )) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := R->apply() ; while t do ( t := t - 1 ; var n : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,x,y} := R->apply() ; if ((x = 0 & y = 0) or (x /= 0 & y /= 0) or (if x /= 0 then (n - 1) mod x /= 0 else (n - 1) mod y /= 0 endif)) then ( execute (-1)->display() ) else ( var win_record : Sequence := Sequence{} ; var current_win_record : Sequence := Sequence{1}->union(Sequence{ 0 }) ; if (x = 0) then ( current_win_record->first() := 2 ) else skip ; for i : Integer.subrange(0, n - 1-1) do ( if ((current_win_record[1+1]->compareTo(x)) < 0 or (current_win_record[1+1]->compareTo(y)) < 0) then ( current_win_record := Sequence{current_win_record->first()}->union(Sequence{ current_win_record[1+1] + 1 }) ; execute ((current_win_record->first()) : win_record) ) else ( current_win_record := Sequence{i + 2}->union(Sequence{ 1 }) ; execute ((current_win_record->first()) : win_record) )) ; execute (StringLib.sumStringsWithSeparator(((win_record)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,x,y=map(int,input().split()) x,y=min(x,y),max(x,y) if(x or y==0 or(n-1)% y!=0): print(-1) else : for i in range(2,n+1,y): for _ in range(y): print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{Set{x, y}->min(),Set{x, y}->max()} ; if (x or y = 0 or (n - 1) mod y /= 0) then ( execute (-1)->display() ) else ( for i : Integer.subrange(2, n + 1-1)->select( $x | ($x - 2) mod y = 0 ) do ( for _anon : Integer.subrange(0, y-1) do ( execute (i)->display())) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : t-=1 n,x,y=tuple(map(int,input().split())) m=max(x,y) if min(x,y)!=0 or m==0 or(n-1)% m!=0 : print(-1) continue r=[] for i in range((n-1)//m): r+=[i*m+2]*m print(*r,sep=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( t := t - 1 ; var n : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : OclAny := Set{x, y}->max() ; if Set{x, y}->min() /= 0 or m = 0 or (n - 1) mod m /= 0 then ( execute (-1)->display() ; continue ) else skip ; var r : Sequence := Sequence{} ; for i : Integer.subrange(0, (n - 1) div m-1) do ( r := r + MatrixLib.elementwiseMult(Sequence{ i * m + 2 }, m)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name r))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- reps=int(input()) for _ in range(reps): n,x,y=map(int,input().split()) mod=min(x,y) sub=max(x,y) if mod==sub or(n-1)% sub or(x>0 and y>0): print(-1) else : ans=[] for i in range(1,n,sub): ans.extend([i+1]*sub) print(*ans,end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var reps : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, reps-1) do ( var n : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mod : OclAny := Set{x, y}->min() ; var sub : OclAny := Set{x, y}->max() ; if mod = sub or (n - 1) mod sub or (x > 0 & y > 0) then ( execute (-1)->display() ) else ( var ans : Sequence := Sequence{} ; for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod sub = 0 ) do ( ans := ans->union(MatrixLib.elementwiseMult(Sequence{ i + 1 }, sub))) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ; execute (->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for T in range(t): n,x,y=map(int,input().split()) if min(x,y)!=0 or(x==0 and y==0): print('-1') else : matches=n-1 if matches % max(x,y)!=0 : print('-1') else : for i in range(2,n+1,max(x,y)): for j in range(max(x,y)): print(i,end='') print('') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for T : Integer.subrange(0, t-1) do ( var n : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if Set{x, y}->min() /= 0 or (x = 0 & y = 0) then ( execute ('-1')->display() ) else ( var matches : double := n - 1 ; if matches mod Set{x, y}->max() /= 0 then ( execute ('-1')->display() ) else ( for i : Integer.subrange(2, n + 1-1)->select( $x | ($x - 2) mod Set{x, y}->max() = 0 ) do ( for j : Integer.subrange(0, Set{x, y}->max()-1) do ( execute (i)->display())) ; execute ('')->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): n,m,sx,sy,d=str(input()).split() n,m,sx,sy,d=int(n),int(m),int(sx),int(sy),int(d) pos1,pos2,pos3,pos4=sx-d,sx+d,sy-d,sy+d if min(sx-1,m-sy)<=d and min(n-sx,sy-1)<=d : print(-1) else : print(n-1+m-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var m : OclAny := null; var sx : OclAny := null; var sy : OclAny := null; var d : OclAny := null; Sequence{n,m,sx,sy,d} := OclType["String"]((OclFile["System.in"]).readLine()).split() ; var m : OclAny := null; var sx : OclAny := null; var sy : OclAny := null; var d : OclAny := null; Sequence{n,m,sx,sy,d} := Sequence{("" + ((n)))->toInteger(),("" + ((m)))->toInteger(),("" + ((sx)))->toInteger(),("" + ((sy)))->toInteger(),("" + ((d)))->toInteger()} ; var pos1 : OclAny := null; var pos2 : OclAny := null; var pos3 : OclAny := null; var pos4 : OclAny := null; Sequence{pos1,pos2,pos3,pos4} := Sequence{sx - d,sx + d,sy - d,sy + d} ; if (Set{sx - 1, m - sy}->min()->compareTo(d)) <= 0 & (Set{n - sx, sy - 1}->min()->compareTo(d)) <= 0 then ( execute (-1)->display() ) else ( execute (n - 1 + m - 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for x in range(t): n,m,x,y,d=map(int,input().split()) if(d==0): print(n+m-2) else : bottom_wall=False r=x+d c=y if(r>=n): bottom_wall=True right_wall=False r=x c=y+d if(c>=m): right_wall=True top_wall=False r=x-d c=y if(r<=1): top_wall=True left_wall=False r=x c=y-d if(c<=1): left_wall=True if(bottom_wall==True and right_wall==True): print(-1) elif(top_wall==True and left_wall==True): print(-1) elif(right_wall==True and left_wall==True): print(-1) elif(top_wall==True and bottom_wall==True): print(-1) else : print(n+m-2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for x : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; var x : OclAny := null; var y : OclAny := null; var d : OclAny := null; Sequence{n,m,x,y,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (d = 0) then ( execute (n + m - 2)->display() ) else ( var bottom_wall : boolean := false ; var r : OclAny := x + d ; var c : OclAny := y ; if ((r->compareTo(n)) >= 0) then ( bottom_wall := true ) else skip ; var right_wall : boolean := false ; r := x ; c := y + d ; if ((c->compareTo(m)) >= 0) then ( right_wall := true ) else skip ; var top_wall : boolean := false ; r := x - d ; c := y ; if (r <= 1) then ( top_wall := true ) else skip ; var left_wall : boolean := false ; r := x ; c := y - d ; if (c <= 1) then ( left_wall := true ) else skip ; if (bottom_wall = true & right_wall = true) then ( execute (-1)->display() ) else (if (top_wall = true & left_wall = true) then ( execute (-1)->display() ) else (if (right_wall = true & left_wall = true) then ( execute (-1)->display() ) else (if (top_wall = true & bottom_wall = true) then ( execute (-1)->display() ) else ( execute (n + m - 2)->display() ) ) ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import gcd def lcm(a,b): return a*b/gcd(a,b) MOD=10**9+7 N=int(input()) A=list(map(int,input().split())) _lcm=1 for a in A : _lcm=_lcm*a//gcd(_lcm,a) ans=_lcm*sum([pow(s,MOD-2,MOD)for s in A])% MOD print(int(ans % MOD)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var MOD : double := (10)->pow(9) + 7 ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var _lcm : int := 1 ; for a : A do ( _lcm := _lcm * a div gcd(_lcm, a)) ; var ans : int := _lcm * (A->select(s | true)->collect(s | ((s)->pow(MOD - 2))))->sum() mod MOD ; execute (("" + ((ans mod MOD)))->toInteger())->display(); operation lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a * b / gcd(a, b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque for _ in range(int(input())): n,m,a,b,d=map(int,input().split()) p,q=a-1,b-1 o=n-a l=m-b c=0 if(p<=d and q<=d)or(o<=d and l<=d)or(p<=d and o<=d)or(l<=d and q<=d): print(-1) else : print(m+n-2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; var a : OclAny := null; var b : OclAny := null; var d : OclAny := null; Sequence{n,m,a,b,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := Sequence{a - 1,b - 1} ; var o : double := n - a ; var l : double := m - b ; var c : int := 0 ; if ((p->compareTo(d)) <= 0 & (q->compareTo(d)) <= 0) or ((o->compareTo(d)) <= 0 & (l->compareTo(d)) <= 0) or ((p->compareTo(d)) <= 0 & (o->compareTo(d)) <= 0) or ((l->compareTo(d)) <= 0 & (q->compareTo(d)) <= 0) then ( execute (-1)->display() ) else ( execute (m + n - 2)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: n,m,x,y,d=map(int,s.split()); print((-1,n+m-2)[max(min(x-1,m-y),min(y-1,n-x))>d]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var n : OclAny := null; var m : OclAny := null; var x : OclAny := null; var y : OclAny := null; var d : OclAny := null; Sequence{n,m,x,y,d} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ); execute (Sequence{-1, n + m - 2}->select((Set{Set{x - 1, m - y}->min(), Set{y - 1, n - x}->min()}->max()->compareTo(d)) > 0))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math MAX=1000000 ; primes=[]; def sieveSundaram(): marked=[False]*(int(MAX/2)+1); for i in range(1,int((math.sqrt(MAX)-1)/2)+1): for j in range(((i*(i+1))<<1),(int(MAX/2)+1),(2*i+1)): marked[j]=True ; primes.append(2); for i in range(1,int(MAX/2)): if(marked[i]==False): primes.append(2*i+1); def calculatePrimorial(n): result=1 ; for i in range(n): result=result*primes[i]; return result ; n=5 ; sieveSundaram(); for i in range(1,n+1): print("Primorial(P#)of",i,"is",calculatePrimorial(i)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MAX : int := 1000000; ; var primes : Sequence := Sequence{}; ; skip ; skip ; n := 5; ; sieveSundaram(); ; for i : Integer.subrange(1, n + 1-1) do ( execute ("Primorial(P#)of")->display();); operation sieveSundaram() pre: true post: true activity: var marked : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (("" + ((MAX / 2)))->toInteger() + 1)); ; for i : Integer.subrange(1, ("" + ((((MAX)->sqrt() - 1) / 2)))->toInteger() + 1-1) do ( for j : Integer.subrange(((i * (i + 1)) * (2->pow(1))), (("" + ((MAX / 2)))->toInteger() + 1)-1)->select( $x | ($x - ((i * (i + 1)) * (2->pow(1)))) mod (2 * i + 1) = 0 ) do ( marked[j+1] := true;)) ; execute ((2) : primes); ; for i : Integer.subrange(1, ("" + ((MAX / 2)))->toInteger()-1) do ( if (marked[i+1] = false) then ( execute ((2 * i + 1) : primes); ) else skip); operation calculatePrimorial(n : OclAny) pre: true post: true activity: var result : int := 1; ; for i : Integer.subrange(0, n-1) do ( result := result * primes[i+1];) ; return result;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m,x,y,d=map(int,input().split()); print(n+m-2)if dtoInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; var x : OclAny := null; var y : OclAny := null; var d : OclAny := null; Sequence{n,m,x,y,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) );(test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name n))) + (expr (atom (name m)))) - (expr (atom (number (integer 2)))))))))) )))))) if (logical_test (logical_test (comparison (comparison (expr (atom (name d)))) < (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name m))) - (expr (atom (name y))))))))) ))))))) or (logical_test (comparison (comparison (expr (atom (name d)))) < (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (name x))))))))) )))))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a,b,c,d=map(int,input().split()) m=a*d n=c*b if a==0 and c==0 : print(0) elif m==n : print(0) elif a==0 or c==0 : print(1) elif m % n==0 or n % m==0 : print(1) else : print(2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : double := a * d ; var n : double := c * b ; if a = 0 & c = 0 then ( execute (0)->display() ) else (if m = n then ( execute (0)->display() ) else (if a = 0 or c = 0 then ( execute (1)->display() ) else (if m mod n = 0 or n mod m = 0 then ( execute (1)->display() ) else ( execute (2)->display() ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b,c,d=map(int,input().split()) if a*d==b*c : print(0) elif a==0 or b==0 or(b*c)%(a*d)==0 or(a*d)%(b*c)==0 : print(1) else : print(2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a * d = b * c then ( execute (0)->display() ) else (if a = 0 or b = 0 or (b * c) mod (a * d) = 0 or (a * d) mod (b * c) = 0 then ( execute (1)->display() ) else ( execute (2)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from decimal import Decimal t=int(input()) for i in range(t): a,b,c,d=map(int,input().split()) if a==0 and c==0 : print(0) continue if a==0 or c==0 : print(1) continue if Decimal(a)/Decimal(b)==Decimal(c)/Decimal(d): print(0) continue if not(a*d)%(b*c)or not(b*c)%(a*d): print(1) continue else : print(2) continue ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 0 & c = 0 then ( execute (0)->display() ; continue ) else skip ; if a = 0 or c = 0 then ( execute (1)->display() ; continue ) else skip ; if Decimal(a) / Decimal(b) = Decimal(c) / Decimal(d) then ( execute (0)->display() ; continue ) else skip ; if not((a * d) mod (b * c)) or not((b * c) mod (a * d)) then ( execute (1)->display() ; continue ) else ( execute (2)->display() ; continue )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): a,b,c,d=(int(x)for x in input().split()) if a*d==b*c : print(0) elif a==0 or c==0 : print(1) elif(a*d)%(b*c)==0 or(b*c)%(a*d)==0 : print(1) else : print(2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; if a * d = b * c then ( execute (0)->display() ) else (if a = 0 or c = 0 then ( execute (1)->display() ) else (if (a * d) mod (b * c) = 0 or (b * c) mod (a * d) = 0 then ( execute (1)->display() ) else ( execute (2)->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): a,b,c,d=map(int,input().split()) x=a*d y=b*c if(x==y): print(0) elif(x==0 or y==0 or max(x,y)% min(x,y)==0): print(1) else : print(2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : double := a * d ; var y : double := b * c ; if (x = y) then ( execute (0)->display() ) else (if (x = 0 or y = 0 or Set{x, y}->max() mod Set{x, y}->min() = 0) then ( execute (1)->display() ) else ( execute (2)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) c=[input()for i in range(n)] MOD=10**9+7 dp=[[0]*(n+1)for i in range(n+1)] dp[0][0]=1 for i,char in enumerate(c): if char=="-" : for j in range(n+1): if j+1toInteger() ; var c : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var MOD : double := (10)->pow(9) + 7 ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)))) ; dp->first()->first() := 1 ; for _tuple : Integer.subrange(1, (c)->size())->collect( _indx | Sequence{_indx-1, (c)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var char : OclAny := _tuple->at(_indx); if char = "-" then ( for j : Integer.subrange(0, n + 1-1) do ( if (j + 1->compareTo(n + 1)) < 0 then ( dp[i + 1+1][j + 1+1] := dp[i + 1+1][j + 1+1] + dp[i+1][j+1] ; dp[i + 1+1][j + 1+1] := dp[i + 1+1][j + 1+1] mod MOD ) else skip) ) else skip ; if char = "U" then ( for j : Integer.subrange(0, n + 1-1) do ( dp[i + 1+1][j+1] := dp[i + 1+1][j+1] + dp[i+1][j+1] ; dp[i + 1+1][j+1] := dp[i + 1+1][j+1] mod MOD ; if (j + 1->compareTo(n + 1)) < 0 then ( dp[i + 1+1][j + 1+1] := dp[i + 1+1][j + 1+1] + dp[i+1][j+1] * (i - j) ; dp[i + 1+1][j + 1+1] := dp[i + 1+1][j + 1+1] mod MOD ) else skip) ) else skip ; if char = "D" then ( for j : Integer.subrange(0, n + 1-1) do ( if (j + 1->compareTo(n + 1)) < 0 then ( dp[i + 1+1][j + 1+1] := dp[i + 1+1][j + 1+1] + dp[i+1][j+1] * (i - j) ; dp[i + 1+1][j + 1+1] := dp[i + 1+1][j + 1+1] mod MOD ) else skip ; if (j + 2->compareTo(n + 1)) < 0 then ( dp[i + 1+1][j + 2+1] := dp[i + 1+1][j + 2+1] + dp[i+1][j+1] * ((i - j))->pow(2) ; dp[i + 1+1][j + 2+1] := dp[i + 1+1][j + 2+1] mod MOD ) else skip) ) else skip) ; execute (dp->last()->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import itertools def solve(N : int,x : "List[int]",y : "List[int]"): indices=[i for i in range(N)] permutations=itertools.permutations(indices) distances=[] for permutation in permutations : total_distance=0 for i in range(0,N-1): f,t=permutation[i : i+2] distance=((x[t]-x[f])**2+(y[t]-y[f])**2)**0.5 total_distance+=distance distances.append(total_distance) result=sum(distances)/len(distances) print(result) return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() N=int(next(tokens)) x=[int()]*(N) y=[int()]*(N) for i in range(N): x[i]=int(next(tokens)) y[i]=int(next(tokens)) solve(N,x,y) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation solve(N : int, x : "List[int]", y : "List[int]") pre: true post: true activity: var indices : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (i)) ; var permutations : OclAny := itertools.permutations(indices) ; var distances : Sequence := Sequence{} ; for permutation : permutations do ( var total_distance : int := 0 ; for i : Integer.subrange(0, N - 1-1) do ( var f : OclAny := null; var t : OclAny := null; Sequence{f,t} := permutation.subrange(i+1, i + 2) ; var distance : double := ((((x[t+1] - x[f+1]))->pow(2) + ((y[t+1] - y[f+1]))->pow(2)))->pow(0.5) ; total_distance := total_distance + distance) ; execute ((total_distance) : distances)) ; var result : double := (distances)->sum() / (distances)->size() ; execute (result)->display() ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var N : int := ("" + (((tokens).next())))->toInteger() ; var x : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (()))->toInteger() }, (N)) ; var y : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (()))->toInteger() }, (N)) ; for i : Integer.subrange(0, N-1) do ( x[i+1] := ("" + (((tokens).next())))->toInteger() ; y[i+1] := ("" + (((tokens).next())))->toInteger()) ; solve(N, x, y); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush,heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod=10**9+7 inf=float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) n=I() dp=[[0]*(n+2)for _ in range(n+1)] dp[0][0]=1 for i in range(n): s=input() if s=='U' : for j in range(n): dp[i+1][j]+=dp[i][j] dp[i+1][j+1]+=dp[i][j]*(i-j) dp[i+1][j+1]%=mod elif s=='-' : for j in range(n): dp[i+1][j+1]+=dp[i][j] else : for j in range(n): dp[i+1][j+2]+=dp[i][j]*(i-j)*(i-j) dp[i+1][j+2]%=mod dp[i+1][j+1]+=dp[i][j]*(i-j) dp[i+1][j+1]%=mod print(dp[n][n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; sys.setrecursionlimit(2147483647) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; skip ; skip ; var n : OclAny := I() ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 2)))) ; dp->first()->first() := 1 ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if s = 'U' then ( for j : Integer.subrange(0, n-1) do ( dp[i + 1+1][j+1] := dp[i + 1+1][j+1] + dp[i+1][j+1] ; dp[i + 1+1][j + 1+1] := dp[i + 1+1][j + 1+1] + dp[i+1][j+1] * (i - j) ; dp[i + 1+1][j + 1+1] := dp[i + 1+1][j + 1+1] mod mod) ) else (if s = '-' then ( for j : Integer.subrange(0, n-1) do ( dp[i + 1+1][j + 1+1] := dp[i + 1+1][j + 1+1] + dp[i+1][j+1]) ) else ( for j : Integer.subrange(0, n-1) do ( dp[i + 1+1][j + 2+1] := dp[i + 1+1][j + 2+1] + dp[i+1][j+1] * (i - j) * (i - j) ; dp[i + 1+1][j + 2+1] := dp[i + 1+1][j + 2+1] mod mod ; dp[i + 1+1][j + 1+1] := dp[i + 1+1][j + 1+1] + dp[i+1][j+1] * (i - j) ; dp[i + 1+1][j + 1+1] := dp[i + 1+1][j + 1+1] mod mod) ) ) ) ; execute (dp[n+1][n+1])->display(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline write=sys.stdout.write def solve(): MOD=10**9+7 N=int(readline()) S=[] for i in range(N): s=readline().strip() if s=="-" : N-=1 continue S.append(s=="D") memo={} def dfs(i,a,b): if i==N : return(a==b==0) key=(i,a,b) if key in memo : return memo[key] r=0 if S[i]: if a>0 : r+=dfs(i+1,a,b)*a % MOD if a>0 and b>0 : r+=dfs(i+1,a-1,b-1)*a*b % MOD else : r+=dfs(i+1,a+1,b+1) if b>0 : r+=dfs(i+1,a,b)*b % MOD memo[key]=r=r % MOD return r write("%d\n" % dfs(0,0,0)) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var write : OclAny := (OclFile["System.out"]).write ; skip ; solve(); operation solve() pre: true post: true activity: var MOD : double := (10)->pow(9) + 7 ; var N : int := ("" + ((readline())))->toInteger() ; var S : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var s : OclAny := readline()->trim() ; if s = "-" then ( N := N - 1 ; continue ) else skip ; execute ((s = "D") : S)) ; var memo : OclAny := Set{} ; skip ; write(StringLib.format("%d\n",dfs(0, 0, 0))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import sys if os.getenv("LOCAL"): sys.stdin=open("_in.txt","r") sys.setrecursionlimit(2147483647) INF=float("inf") IINF=10**18 MOD=10**9+7 N=int(sys.stdin.readline()) C=[sys.stdin.readline().rstrip()for _ in range(N)] C=[c for c in C if c!='-'] N=len(C) dp=[[0]*(N+1)for _ in range(N+1)] dp[0][0]=1 for i,c in enumerate(C): for j in range(N): if c=='D' : if j-1>=0 : dp[i+1][j-1]+=dp[i][j]*j*j dp[i+1][j-1]%=MOD dp[i+1][j]+=dp[i][j]*j dp[i+1][j]%=MOD if c=='U' : dp[i+1][j]+=dp[i][j]*j dp[i+1][j]%=MOD dp[i+1][j+1]+=dp[i][j] dp[i+1][j+1]%=MOD print(dp[-1][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if os.getenv("LOCAL") then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("_in.txt")) ) else skip ; sys.setrecursionlimit(2147483647) ; var INF : double := ("" + (("inf")))->toReal() ; var IINF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var C : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (sys.stdin.readLine().rstrip())) ; C := C->select(c | c /= '-')->collect(c | (c)) ; N := (C)->size() ; var dp : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)))) ; dp->first()->first() := 1 ; for _tuple : Integer.subrange(1, (C)->size())->collect( _indx | Sequence{_indx-1, (C)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); for j : Integer.subrange(0, N-1) do ( if c = 'D' then ( if j - 1 >= 0 then ( dp[i + 1+1][j - 1+1] := dp[i + 1+1][j - 1+1] + dp[i+1][j+1] * j * j ; dp[i + 1+1][j - 1+1] := dp[i + 1+1][j - 1+1] mod MOD ) else skip ; dp[i + 1+1][j+1] := dp[i + 1+1][j+1] + dp[i+1][j+1] * j ; dp[i + 1+1][j+1] := dp[i + 1+1][j+1] mod MOD ) else skip ; if c = 'U' then ( dp[i + 1+1][j+1] := dp[i + 1+1][j+1] + dp[i+1][j+1] * j ; dp[i + 1+1][j+1] := dp[i + 1+1][j+1] mod MOD ; dp[i + 1+1][j + 1+1] := dp[i + 1+1][j + 1+1] + dp[i+1][j+1] ; dp[i + 1+1][j + 1+1] := dp[i + 1+1][j + 1+1] mod MOD ) else skip)) ; execute (dp->last()->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): return gcd(b,a % b)if b>0 else a def countGCD(L,R,g): L=(L+g-1)//g R=R//g ans=0 for i in range(L,R+1): for j in range(L,R+1): if(gcd(i,j)==1): ans=ans+1 return ans L=1 R=11 g=5 print(countGCD(L,R,g)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; L := 1 ; R := 11 ; g := 5 ; execute (countGCD(L, R, g))->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return if b > 0 then gcd(b, a mod b) else a endif; operation countGCD(L : OclAny, R : OclAny, g : OclAny) : OclAny pre: true post: true activity: L := (L + g - 1) div g ; R := R div g ; var ans : int := 0 ; for i : Integer.subrange(L, R + 1-1) do ( for j : Integer.subrange(L, R + 1-1) do ( if (gcd(i, j) = 1) then ( ans := ans + 1 ) else skip)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=10**9+7 n=int(input()) dp=[[0 for _ in range(n+1)]for _ in range(n+1)] dp[0][0]=1 for i in range(1,n+1): s=input() for j in range(n+1): if s=="U" : if j>0 : dp[i][j]+=dp[i-1][j-1] dp[i][j]+=j*dp[i-1][j] elif s=="-" : dp[i][j]+=dp[i-1][j] else : if jpow(9) + 7 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (0)))) ; dp->first()->first() := 1 ; for i : Integer.subrange(1, n + 1-1) do ( var s : String := (OclFile["System.in"]).readLine() ; for j : Integer.subrange(0, n + 1-1) do ( if s = "U" then ( if j > 0 then ( dp[i+1][j+1] := dp[i+1][j+1] + dp[i - 1+1][j - 1+1] ) else skip ; dp[i+1][j+1] := dp[i+1][j+1] + j * dp[i - 1+1][j+1] ) else (if s = "-" then ( dp[i+1][j+1] := dp[i+1][j+1] + dp[i - 1+1][j+1] ) else ( if (j->compareTo(n)) < 0 then ( dp[i+1][j+1] := dp[i+1][j+1] + (j + 1) * (j + 1) * dp[i - 1+1][j + 1+1] ) else skip ; dp[i+1][j+1] := dp[i+1][j+1] + j * dp[i - 1+1][j+1] ) ) ; dp[i+1][j+1] := dp[i+1][j+1] mod MOD)) ; execute (dp[n+1]->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout T=int(stdin.readline()) for i in range(T): N=int(stdin.readline()) A=list(map(int,stdin.readline().strip().split())) if sum(A)==0 : OP=0 else : START="X" END="X" for j in range(len(A)): if A[j]!=0 : START=j break for j in range(len(A)-1,-1,-1): if A[j]!=0 : END=j break A=A[START : END+1] if 0 in A : OP=2 else : OP=1 stdout.write(f"{OP}\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var T : int := ("" + ((stdin.readLine())))->toInteger() ; for i : Integer.subrange(0, T-1) do ( var N : int := ("" + ((stdin.readLine())))->toInteger() ; var A : Sequence := ((stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (A)->sum() = 0 then ( var OP : int := 0 ) else ( var START : String := "X" ; var END : String := "X" ; for j : Integer.subrange(0, (A)->size()-1) do ( if A[j+1] /= 0 then ( START := j ; break ) else skip) ; for j : Integer.subrange(-1 + 1, (A)->size() - 1)->reverse() do ( if A[j+1] /= 0 then ( END := j ; break ) else skip) ; A := A.subrange(START+1, END + 1) ; if (A)->includes(0) then ( OP := 2 ) else ( OP := 1 ) ) ; stdout.write(StringLib.formattedString("{OP}\n"))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) c=0 c1=0 c2=0 m=list(map(int,input().split())) for i in range(n): if m[i]!=0 : if not c : c=i+1 c1=i+1 c2+=1 if not c2 : print(0); elif c1-c+1==c2 : print(1); else : print(2); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := 0 ; var c1 : int := 0 ; var c2 : int := 0 ; var m : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( if m[i+1] /= 0 then ( if not(c) then ( c := i + 1 ) else skip ; c1 := i + 1 ; c2 := c2 + 1 ) else skip) ; if not(c2) then ( execute (0)->display(); ) else (if c1 - c + 1 = c2 then ( execute (1)->display(); ) else ( execute (2)->display(); ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() t=num_inp() for _ in range(t): n=num_inp() l=arr_inp() count=l.count(0) if(count==n): print(0) continue count=0 ind=-1 for i in range(n): if(l[i]==0): if((i-ind)>1): count+=1 ind=i if(n-ind>=2): count+=1 if(count>=2): print(2) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var t : OclAny := num_inp->apply() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := num_inp->apply() ; var l : OclAny := arr_inp->apply() ; var count : int := l->count(0) ; if (count = n) then ( execute (0)->display() ; continue ) else skip ; count := 0 ; var ind : int := -1 ; for i : Integer.subrange(0, n-1) do ( if (l[i+1] = 0) then ( if ((i - ind) > 1) then ( count := count + 1 ) else skip ; ind := i ) else skip) ; if (n - ind >= 2) then ( count := count + 1 ) else skip ; if (count >= 2) then ( execute (2)->display() ) else ( execute (1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) l=list(map(int,input().split())) while len(l)and l[0]==0 : del l[0] while len(l)and l[-1]==0 : del l[-1] if len(l): if 0 in l : print(2) else : print(1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; while (l)->size() & l->first() = 0 do ( execute (l->first())->isDeleted()) ; while (l)->size() & l->last() = 0 do ( execute (l->last())->isDeleted()) ; if (l)->size() then ( if (l)->includes(0) then ( execute (2)->display() ) else ( execute (1)->display() ) ) else ( execute (0)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for tc in range(int(input())): n=int(input()) a=list(map(int,input().split())) z=list() c=0 for i in range(len(a)): if(a[i]==0): z.append(i) if(n==1 and len(z)!=1): c=1 elif(len(z)==n): c=0 else : beg=last=0 for i in range(len(a)): if(a[i]!=0): beg=i break for i in range(len(a)-1,-1,-1): if(a[i]!=0): last=i break if(beg+(n-1-last)==len(z)): c=1 else : c=2 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for tc : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var z : Sequence := () ; var c : int := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( if (a[i+1] = 0) then ( execute ((i) : z) ) else skip) ; if (n = 1 & (z)->size() /= 1) then ( c := 1 ) else (if ((z)->size() = n) then ( c := 0 ) else ( var beg : OclAny := 0; var last : int := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( if (a[i+1] /= 0) then ( beg := i ; break ) else skip) ; for i : Integer.subrange(-1 + 1, (a)->size() - 1)->reverse() do ( if (a[i+1] /= 0) then ( last := i ; break ) else skip) ; if (beg + (n - 1 - last) = (z)->size()) then ( c := 1 ) else ( c := 2 ) ) ) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getPairs(a): count=0 for i in range(len(a)): for j in range(len(a)): if(a[i]union(Sequence{4}->union(Sequence{3}->union(Sequence{ 1 }))) ; execute (getPairs(a))->display() ) else skip; operation getPairs(a : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( for j : Integer.subrange(0, (a)->size()-1) do ( if ((a[i+1]->compareTo(a[j+1])) < 0) then ( count := count + 1 ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd N=9 def addEgde(adj,u,v): adj[u].append(v) adj[v].append(u) def DFS(node,parent,G,leaf,val,adj): if(node==leaf): G=gcd(G,val[node]) print(G,end="") return for it in adj[node]: if(it!=parent): DFS(it,node,gcd(G,val[it]),leaf,val,adj) if __name__=='__main__' : n=8 adj=[[0 for i in range(n+1)]for j in range(n+1)] addEgde(adj,1,2) addEgde(adj,2,4) addEgde(adj,1,3) addEgde(adj,3,5) addEgde(adj,3,6) addEgde(adj,6,7) addEgde(adj,6,8) leaf=5 val=[-1,6,2,6,3,4,12,10,18] G=val[1] DFS(1,-1,G,leaf,val,adj) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 9 ; skip ; skip ; if __name__ = '__main__' then ( var n : int := 8 ; adj := Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)))) ; addEgde(adj, 1, 2) ; addEgde(adj, 2, 4) ; addEgde(adj, 1, 3) ; addEgde(adj, 3, 5) ; addEgde(adj, 3, 6) ; addEgde(adj, 6, 7) ; addEgde(adj, 6, 8) ; leaf := 5 ; val := Sequence{-1}->union(Sequence{6}->union(Sequence{2}->union(Sequence{6}->union(Sequence{3}->union(Sequence{4}->union(Sequence{12}->union(Sequence{10}->union(Sequence{ 18 })))))))) ; G := val[1+1] ; DFS(1, -1, G, leaf, val, adj) ) else skip; operation addEgde(adj : OclAny, u : OclAny, v : OclAny) pre: true post: true activity: (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)))))))) )))); operation DFS(node : OclAny, parent : OclAny, G : OclAny, leaf : OclAny, val : OclAny, adj : OclAny) pre: true post: true activity: if (node = leaf) then ( G := gcd(G, val[node+1]) ; execute (G)->display() ; return ) else skip ; for it : adj[node+1] do ( if (it /= parent) then ( DFS(it, node, gcd(G, val[it+1]), leaf, val, adj) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calc_imos(one_day): day=[] cum_sum=0 for i in one_day : cum_sum+=i day.append(cum_sum) return max(day) def calc_time(time): h,m,s=map(int,time.split(":")) return h*60*60+m*60+s while True : N=int(input()) if N==0 : break one_day=[0]*(24*60*60+1) for i in range(N): start,end=input().split() start=calc_time(start) end=calc_time(end) one_day[start+1]+=1 one_day[end+1]-=1 print(calc_imos(one_day)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; one_day := MatrixLib.elementwiseMult(Sequence{ 0 }, (24 * 60 * 60 + 1)) ; for i : Integer.subrange(0, N-1) do ( var start : OclAny := null; var end : OclAny := null; Sequence{start,end} := input().split() ; var start : OclAny := calc_time(start) ; var end : OclAny := calc_time(end) ; one_day[start + 1+1] := one_day[start + 1+1] + 1 ; one_day[end + 1+1] := one_day[end + 1+1] - 1) ; execute (calc_imos(one_day))->display()); operation calc_imos(one_day : OclAny) : OclAny pre: true post: true activity: var day : Sequence := Sequence{} ; var cum_sum : int := 0 ; for i : one_day do ( cum_sum := cum_sum + i ; execute ((cum_sum) : day)) ; return (day)->max(); operation calc_time(time : OclAny) : OclAny pre: true post: true activity: var h : OclAny := null; var m : OclAny := null; var s : OclAny := null; Sequence{h,m,s} := (time.split(":"))->collect( _x | (OclType["int"])->apply(_x) ) ; return h * 60 * 60 + m * 60 + s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque import sys,heapq,bisect,math,itertools,string,queue sys.setrecursionlimit(10**8) INF=float('inf') mod=10**9+7 eps=10**-7 def inp(): return int(input()) def inpl(): return list(map(int,input().split())) def inpl_str(): return list(input().split()) def calc(t): h,m,s=map(int,t.split(':')) return(h*60+m)*60+s while True : n=inp() if n==0 : break else : imos=[0]*(60*60*24+5) for _ in range(n): ts,tt=input().split() ts=calc(ts) tt=calc(tt) imos[ts]+=1 imos[tt]-=1 tmp=0 for i in range(60*60*24+5): tmp+=imos[i] imos[i]=tmp print(max(imos)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var eps : double := (10)->pow(-7) ; skip ; skip ; skip ; skip ; while true do ( var n : OclAny := inp() ; if n = 0 then ( break ) else ( var imos : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (60 * 60 * 24 + 5)) ; for _anon : Integer.subrange(0, n-1) do ( var ts : OclAny := null; var tt : OclAny := null; Sequence{ts,tt} := input().split() ; var ts : OclAny := calc(ts) ; var tt : OclAny := calc(tt) ; imos[ts+1] := imos[ts+1] + 1 ; imos[tt+1] := imos[tt+1] - 1) ; var tmp : int := 0 ; for i : Integer.subrange(0, 60 * 60 * 24 + 5-1) do ( tmp := tmp + imos[i+1] ; imos[i+1] := tmp) ; execute ((imos)->max())->display() )); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inpl_str() : OclAny pre: true post: true activity: return (input().split()); operation calc(t : OclAny) : OclAny pre: true post: true activity: var h : OclAny := null; var m : OclAny := null; var s : OclAny := null; Sequence{h,m,s} := (t.split(':'))->collect( _x | (OclType["int"])->apply(_x) ) ; return (h * 60 + m) * 60 + s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools ft=24*60*60 while True : n=int(input()) if n==0 : break c=[0]*(ft+1) for i in range(n): t1,t2=input().split() tt1=(int(t1[0 : 2])*60+int(t1[3 : 5]))*60+int(t1[6 : 8]) tt2=(int(t2[0 : 2])*60+int(t2[3 : 5]))*60+int(t2[6 : 8]) c[tt1]+=1 c[tt2]-=1 cc=itertools.accumulate(c) cc=list(cc) print(max(cc[: ft+1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var ft : int := 24 * 60 * 60 ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var c : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (ft + 1)) ; for i : Integer.subrange(0, n-1) do ( var t1 : OclAny := null; var t2 : OclAny := null; Sequence{t1,t2} := input().split() ; var tt1 : int := (("" + ((t1.subrange(0+1, 2))))->toInteger() * 60 + ("" + ((t1.subrange(3+1, 5))))->toInteger()) * 60 + ("" + ((t1.subrange(6+1, 8))))->toInteger() ; var tt2 : int := (("" + ((t2.subrange(0+1, 2))))->toInteger() * 60 + ("" + ((t2.subrange(3+1, 5))))->toInteger()) * 60 + ("" + ((t2.subrange(6+1, 8))))->toInteger() ; c[tt1+1] := c[tt1+1] + 1 ; c[tt2+1] := c[tt2+1] - 1) ; var cc : OclAny := itertools.accumulate(c) ; cc := (cc) ; execute ((cc.subrange(1,ft + 1))->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import sqrt def solve(N : int,X : int): answer=N a,b=max(N-X,X),min(N-X,X) while True : answer+=2*(a//b)*b if a % b==0 : answer-=b break a,b=b,a % b print(answer) return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() N=int(next(tokens)) X=int(next(tokens)) solve(N,X) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(N : int, X : int) pre: true post: true activity: var answer : int := N ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{Set{N - X, X}->max(),Set{N - X, X}->min()} ; while true do ( answer := answer + 2 * (a div b) * b ; if a mod b = 0 then ( answer := answer - b ; break ) else skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a mod b}) ; execute (answer)->display() ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var N : int := ("" + (((tokens).next())))->toInteger() ; var X : int := ("" + (((tokens).next())))->toInteger() ; solve(N, X); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def conv(l): ret=0 for e in l : ret=ret*60+e return ret while True : N=int(sys.stdin.readline()) if N==0 : exit() a=tuple(tuple(sys.stdin.readline().split())for _ in range(N)) a=[[conv(list(map(int,s.split(":")))),conv(list(map(int,e.split(":"))))]for s,e in a] N=24*60*60 imos=[0]*(N+1) for s,e in a : imos[s]+=1 if etoInteger() ; if N = 0 then ( exit() ) else skip ; var a : Sequence := ((argument (test (logical_test (comparison (expr (atom (name tuple)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin)) (trailer . (name readline) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) ))))))))) ; a := a->select(_tuple | true)->collect(_tuple | let s : OclAny = _tuple->at(1) in let e : OclAny = _tuple->at(2) in (Sequence{conv(((s.split(":"))->collect( _x | (OclType["int"])->apply(_x) )))}->union(Sequence{ conv(((e.split(":"))->collect( _x | (OclType["int"])->apply(_x) ))) }))) ; N := 24 * 60 * 60 ; var imos : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; for _tuple : a do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var e : OclAny := _tuple->at(_indx); imos[s+1] := imos[s+1] + 1 ; if (e->compareTo(N + 1)) < 0 then ( imos[e+1] := imos[e+1] - 1 ) else skip) ; var cur : int := 0 ; ret := 0 ; for i : Integer.subrange(0, N-1) do ( cur := cur + imos[i+1] ; ret := Set{ret, cur}->max()) ; execute (ret)->display()); operation conv(l : OclAny) : OclAny pre: true post: true activity: var ret : int := 0 ; for e : l do ( ret := ret * 60 + e) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(s): return(s[0]*60+s[1])*60+s[2] a=86401 while 1 : t=[0]*a n=int(input()) if n==0 : break for _ in range(n): b,c=input().split() b,c=list(map(int,b.split(':'))),list(map(int,c.split(':'))) t[f(b)]+=1 ; t[f(c)]-=1 d=0 for i in range(1,a): t[i]+=t[i-1] d=max(d,t[i]) print(d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : int := 86401 ; while 1 do ( var t : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, a) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; for _anon : Integer.subrange(0, n-1) do ( var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := input().split() ; var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := Sequence{((b.split(':'))->collect( _x | (OclType["int"])->apply(_x) )),((c.split(':'))->collect( _x | (OclType["int"])->apply(_x) ))} ; t[f(b)+1] := t[f(b)+1] + 1; t[f(c)+1] := t[f(c)+1] - 1) ; var d : int := 0 ; for i : Integer.subrange(1, a-1) do ( t[i+1] := t[i+1] + t[i - 1+1] ; d := Set{d, t[i+1]}->max()) ; execute (d)->display()); operation f(s : OclAny) : OclAny pre: true post: true activity: return (s->first() * 60 + s[1+1]) * 60 + s[2+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumBaseB(a,b,base): len_a=len(a) len_b=len(b) s="" ; sum="" ; diff=abs(len_a-len_b); for i in range(1,diff+1): s+="0" if(len_a0): sum=chr(carry+ord('0'))+sum ; return sum a="123" b="234" base=6 sum=sumBaseB(a,b,base); print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := "123" ; b := "234" ; base := 6 ; sum := sumBaseB(a, b, base); ; execute (sum)->display(); operation sumBaseB(a : OclAny, b : OclAny, base : OclAny) : OclAny pre: true post: true activity: var len_a : int := (a)->size() ; var len_b : int := (b)->size() ; var s : String := ""; ; var sum : String := ""; ; var diff : double := (len_a - len_b)->abs(); ; for i : Integer.subrange(1, diff + 1-1) do ( s := s + "0") ; if ((len_a->compareTo(len_b)) < 0) then ( a := s + a ) else ( b := s + b; ) ; var carry : int := 0; ; for i : Integer.subrange(-1 + 1, Set{len_a, len_b}->max() - 1)->reverse() do ( var curr : int := carry + ((a[i+1])->char2byte() - ('0')->char2byte()) + ((b[i+1])->char2byte() - ('0')->char2byte()); ; carry := curr div base ; curr := curr mod base; ; sum := (curr + ('0')->char2byte())->byte2char() + sum) ; if (carry > 0) then ( sum := (carry + ('0')->char2byte())->byte2char() + sum; ) else skip ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) from math import gcd samu=0 for i in range(1,k+1): for j in range(1,k+1): for k in range(1,k+1): samu+=gcd(gcd(i,j),k) print(samu) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; var samu : int := 0 ; for i : Integer.subrange(1, k + 1-1) do ( for j : Integer.subrange(1, k + 1-1) do ( for k : Integer.subrange(1, k + 1-1) do ( samu := samu + gcd(gcd(i, j), k)))) ; execute (samu)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def GCD(p,q): if(p % q==0): return q return GCD(q,p % q) s=0 k=int(sys.stdin.readline()) for i in range(1,k+1): for j in range(1,k+1): for m in range(1,k+1): s+=GCD(GCD(i,j),m) sys.stdout.write(str(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var s : int := 0 ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(1, k + 1-1) do ( for j : Integer.subrange(1, k + 1-1) do ( for m : Integer.subrange(1, k + 1-1) do ( s := s + GCD(GCD(i, j), m)))) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))))) )))); operation GCD(p : OclAny, q : OclAny) : OclAny pre: true post: true activity: if (p mod q = 0) then ( return q ) else skip ; return GCD(q, p mod q); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) s=input() if k==0 : print(s) elif int(s)<=9 : print(0) else : c=0 condition=0 ans='' for i in range(len(s)): if i==0 and condition==0 : ans+='1' if s[i]=='1' : c+=0 else : c+=1 elif condition==0 : ans+='0' if s[i]=='0' : c+=0 else : c+=1 if c==k : condition=1 for j in range(i+1,len(s)): ans+=s[j] if j==len(s)-1 : c=-1 break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; if k = 0 then ( execute (s)->display() ) else (if ("" + ((s)))->toInteger() <= 9 then ( execute (0)->display() ) else ( var c : int := 0 ; var condition : int := 0 ; var ans : String := '' ; for i : Integer.subrange(0, (s)->size()-1) do ( if i = 0 & condition = 0 then ( ans := ans + '1' ; if s[i+1] = '1' then ( c := c + 0 ) else ( c := c + 1 ) ) else (if condition = 0 then ( ans := ans + '0' ; if s[i+1] = '0' then ( c := c + 0 ) else ( c := c + 1 ) ) else skip) ; if c = k then ( condition := 1 ; for j : Integer.subrange(i + 1, (s)->size()-1) do ( ans := ans + s[j+1] ; if j = (s)->size() - 1 then ( c := -1 ; break ) else skip) ) else skip) ; execute (ans)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import combinations_with_replacement from math import gcd K=int(input()) memo={} ans=0 for a,b,c in combinations_with_replacement(range(1,K+1),3): v=gcd(a,gcd(b,c)) n=len(set([a,b,c])) ans+=v if n==1 else(3*v if n==2 else 6*v) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var memo : OclAny := Set{} ; var ans : int := 0 ; for _tuple : combinations_with_replacement(Integer.subrange(1, K + 1-1), 3) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); var v : OclAny := gcd(a, gcd(b, c)) ; var n : int := (Set{}->union((Sequence{a}->union(Sequence{b}->union(Sequence{ c })))))->size() ; ans := ans + if n = 1 then v else (if n = 2 then 3 * v else 6 * v endif) endif) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from functools import reduce def gcd(*numbers): return reduce(math.gcd,numbers) def gcd_list(numbers): return reduce(math.gcd,numbers) n=int(input()) ans=0 for i in range(1,n+1): for j in range(1,n+1): for k in range(1,n+1): a=[i,j,k] ans+=gcd_list(a) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, n + 1-1) do ( for k : Integer.subrange(1, n + 1-1) do ( var a : Sequence := Sequence{i}->union(Sequence{j}->union(Sequence{ k })) ; ans := ans + gcd_list(a)))) ; execute (ans)->display(); operation gcd(numbers : OclAny : Sequence(OclAny)) : OclAny pre: true post: true activity: (args * (named_parameter (name numbers))) return reduce(, numbers); operation gcd_list(numbers : OclAny) : OclAny pre: true post: true activity: return reduce(, numbers); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) import math s=0 result=0 for a in range(1,k+1,1): for b in range(a,k+1,1): for c in range(b,k+1,1): gcd=math.gcd(math.gcd(a,b),math.gcd(b,c)) if a==b==c : pass elif(a==b and b!=c)or(b==c and b!=a)or(a==c and a!=c): gcd=3*gcd else : gcd=6*gcd result+=gcd print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; var s : int := 0 ; var result : int := 0 ; for a : Integer.subrange(1, k + 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( for b : Integer.subrange(a, k + 1-1)->select( $x | ($x - a) mod 1 = 0 ) do ( for c : Integer.subrange(b, k + 1-1)->select( $x | ($x - b) mod 1 = 0 ) do ( var gcd : long := ((a)->gcd(b))->gcd((b)->gcd(c)) ; if a = b & (b == c) then ( skip ) else (if (a = b & b /= c) or (b = c & b /= a) or (a = c & a /= c) then ( gcd := 3 * gcd ) else ( gcd := 6 * gcd ) ) ; result := result + gcd))) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calNum(year): return(year//4)-(year//100)+(year//400); def leapNum(l,r): l-=1 ; num1=calNum(r); num2=calNum(l); print(num1-num2); if __name__=="__main__" : l1=1 ; r1=400 ; leapNum(l1,r1); l2=400 ; r2=2000 ; leapNum(l2,r2); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var l1 : int := 1; var r1 : int := 400; ; leapNum(l1, r1); ; var l2 : int := 400; var r2 : int := 2000; ; leapNum(l2, r2); ) else skip; operation calNum(year : OclAny) pre: true post: true activity: return (year div 4) - (year div 100) + (year div 400);; operation leapNum(l : OclAny, r : OclAny) pre: true post: true activity: l := l - 1; ; var num1 : OclAny := calNum(r); ; var num2 : OclAny := calNum(l); ; execute (num1 - num2)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans,low=[0]*62,[0]*62 while True : n,i,j=map(int,input().split()) if n==0 : break i-=1 ; j-=1 for k in range(1,n+1): low[n-k]=(i>>(n-k))& 1 if low[n-k]==0 : i=~ i for k in range(1,n+1): ans[k]='L' if((j>>(n-k))& 1)==low[k-1]else 'R' if low[k-1]==0 : j=~ j print(''.join(ans[1 : n+1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ans : OclAny := null; var low : OclAny := null; Sequence{ans,low} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, 62),MatrixLib.elementwiseMult(Sequence{ 0 }, 62)} ; while true do ( var n : OclAny := null; var i : OclAny := null; var j : OclAny := null; Sequence{n,i,j} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; i := i - 1; j := j - 1 ; for k : Integer.subrange(1, n + 1-1) do ( low[n - k+1] := MathLib.bitwiseAnd((i /(2->pow((n - k)))), 1) ; if low[n - k+1] = 0 then ( var i : int := MathLib.bitwiseNot(i) ) else skip) ; for k : Integer.subrange(1, n + 1-1) do ( ans[k+1] := if (MathLib.bitwiseAnd((j /(2->pow((n - k)))), 1)) = low[k - 1+1] then 'L' else 'R' endif ; if low[k - 1+1] = 0 then ( var j : int := MathLib.bitwiseNot(j) ) else skip) ; execute (StringLib.sumStringsWithSeparator((ans.subrange(1+1, n + 1)), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=map(int,input().split()) import math def f(x,y): a=min(x,y) b=max(x,y) if a==0 : return 0 elif b % a==0 : return 2*b-a else : return 2*a*math.floor(b/a)+f(a,b % a) print(n+f(x,n-x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; skip ; execute (n + f(x, n - x))->display(); operation f(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var a : OclAny := Set{x, y}->min() ; var b : OclAny := Set{x, y}->max() ; if a = 0 then ( return 0 ) else (if b mod a = 0 then ( return 2 * b - a ) else ( return 2 * a * (b / a)->floor() + f(a, b mod a) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : s=input() n,i,j=map(int,s.split()) if n==0 : break updown=[None for _ in range(n+1)]; whole=2**n fold=n from_top=i while 1 : if whole==1 : assert fold==0 break half=whole//2 if from_top<=half : updown[fold]=0 else : updown[fold]=1 fold-=1 whole=half if half>=from_top : from_top=half-from_top+1 else : from_top=from_top-half whole=2**n from_left=j output="" for i in range(1,n+1): half=whole//2 if from_left<=half : is_right=0 else : is_right=1 if(updown[i]+is_right)% 2==0 : output+="L" if half>=from_left : from_left=half-from_left+1 else : from_left=from_left-half else : output+="R" if halfcollect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var updown : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (null)); ; var whole : double := (2)->pow(n) ; var fold : OclAny := n ; var from_top : OclAny := i ; while 1 do ( if whole = 1 then ( assert fold = 0 do "assertion failed" ; break ) else skip ; var half : int := whole div 2 ; if (from_top->compareTo(half)) <= 0 then ( updown[fold+1] := 0 ) else ( updown[fold+1] := 1 ) ; fold := fold - 1 ; whole := half ; if (half->compareTo(from_top)) >= 0 then ( from_top := half - from_top + 1 ) else ( from_top := from_top - half )) ; whole := (2)->pow(n) ; var from_left : OclAny := j ; var output : String := "" ; for i : Integer.subrange(1, n + 1-1) do ( half := whole div 2 ; if (from_left->compareTo(half)) <= 0 then ( var is_right : int := 0 ) else ( is_right := 1 ) ; if (updown[i+1] + is_right) mod 2 = 0 then ( output := output + "L" ; if (half->compareTo(from_left)) >= 0 then ( from_left := half - from_left + 1 ) else ( from_left := from_left - half ) ) else ( output := output + "R" ; if (half->compareTo(from_left)) < 0 then ( from_left := whole - from_left + 1 ) else skip ) ; whole := half) ; execute (output)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rdp_trace(n : int,i : int)->list : def loop(n : int,i : int)->list : if n==1 : return[] if i<=n//2 : rval=loop(n//2,(n//2)-i+1) rval.append(i) return rval else : rval=loop(n//2,i-(n//2)) rval.append(i) return rval return loop(2**n,i) def rdp_connect()->bool : global n,i,j n,i,j=map(int,input().split()) if n==i==j==0 : return False return True if __name__=='__main__' : while rdp_connect(): rval=[] for k,lv in zip(range(n),rdp_trace(n,i)): if(lv<=(2**(k+1))//2): if(j<=(2**(n-k))//2): rval.append('L') j=(2**(n-k))//2-j+1 else : rval.append('R') j=(2**(n-k))-j+1 else : if(j<=(2**(n-k))//2): rval.append('R') else : rval.append('L') j=j-(2**(n-k))//2 print(''.join(rval)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute n : OclAny; attribute i : OclAny; attribute j : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( while rdp_connect() do ( rval := Sequence{} ; for _tuple : Integer.subrange(1, Integer.subrange(0, n-1)->size())->collect( _indx | Sequence{Integer.subrange(0, n-1)->at(_indx), rdp_trace(n, i)->at(_indx)} ) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var lv : OclAny := _tuple->at(_indx); if ((lv->compareTo(((2)->pow((k + 1))) div 2)) <= 0) then ( if ((j->compareTo(((2)->pow((n - k))) div 2)) <= 0) then ( execute (('L') : rval) ; j := ((2)->pow((n - k))) div 2 - j + 1 ) else ( execute (('R') : rval) ; j := ((2)->pow((n - k))) - j + 1 ) ) else ( if ((j->compareTo(((2)->pow((n - k))) div 2)) <= 0) then ( execute (('R') : rval) ) else ( execute (('L') : rval) ; j := j - ((2)->pow((n - k))) div 2 ) )) ; execute (StringLib.sumStringsWithSeparator((rval), ''))->display()) ) else skip; operation rdp_trace(n : int, i : int) : Sequence pre: true post: true activity: skip ; return loop((2)->pow(n), i); operation rdp_connect() : boolean pre: true post: true activity: skip; skip; skip ; Sequence{n,i,j} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = i & (i == j) & (j == 0) then ( return false ) else skip ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n,a,b=map(int,input().split()) if n==0 : break h_pos=[a] all=2**n for i in range(n): if 1<=h_pos[-1]<=all//4 : h_pos.append(all//4+all//4-h_pos[-1]+1) elif all//4+1<=h_pos[-1]<=all//2 : h_pos.append(all//2-h_pos[-1]+1) elif all//2+1<=h_pos[-1]<=3*all//4 : h_pos.append(h_pos[-1]-all//2) else : h_pos.append(h_pos[-1]-3*all//4+all//4) all//=2 h_pos=h_pos[: :-1] all=2**n s='' for i in range(n): if 1<=b<=all//2 : if h_pos[i+1]<=2**(i+1)//2 : b=all//2-b+1 s+='L' else : s+='R' else : if h_pos[i+1]<=2**(i+1)//2 : b=all-b+1 s+='R' else : b=b-all//2 s+='L' all//=2 print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var h_pos : Sequence := Sequence{ a } ; var all : double := (2)->pow(n) ; for i : Integer.subrange(0, n-1) do ( if 1 <= h_pos->last() & (h_pos->last() <= all div 4) then ( execute ((all div 4 + all div 4 - h_pos->last() + 1) : h_pos) ) else (if (all div 4 + 1->compareTo(h_pos->last())) <= 0 & (h_pos->last() <= all div 2) then ( execute ((all div 2 - h_pos->last() + 1) : h_pos) ) else (if (all div 2 + 1->compareTo(h_pos->last())) <= 0 & (h_pos->last() <= 3 * all div 4) then ( execute ((h_pos->last() - all div 2) : h_pos) ) else ( execute ((h_pos->last() - 3 * all div 4 + all div 4) : h_pos) ) ) ) ; all := all div 2) ; h_pos := h_pos(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; all := (2)->pow(n) ; var s : String := '' ; for i : Integer.subrange(0, n-1) do ( if 1 <= b & (b <= all div 2) then ( if (h_pos[i + 1+1]->compareTo((2)->pow((i + 1)) div 2)) <= 0 then ( var b : double := all div 2 - b + 1 ; s := s + 'L' ) else ( s := s + 'R' ) ) else ( if (h_pos[i + 1+1]->compareTo((2)->pow((i + 1)) div 2)) <= 0 then ( b := all - b + 1 ; s := s + 'R' ) else ( b := b - all div 2 ; s := s + 'L' ) ) ; all := all div 2) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n,i,j=map(int,input().split()) if n+i+j==0 : break i=2**n-i up=[0]*n for k in range(n): if 2**(n-1-k)<=i : up[k]=1 i=2**(n-k)-1-i up.reverse() ans="" j-=1 for k in range(n): if up[k]==0 and j<2**(n-1-k): j=j ans+="R" elif up[k]==0 and 2**(n-1-k)<=j : j=j-2**(n-1-k) ans+="L" elif up[k]==1 and j<2**(n-1-k): j=2**(n-1-k)-1-j ans+="L" elif up[k]==1 and 2**(n-1-k)<=j : j=2**(n-k)-1-j ans+="R" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : OclAny := null; var i : OclAny := null; var j : OclAny := null; Sequence{n,i,j} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n + i + j = 0 then ( break ) else skip ; var i : double := (2)->pow(n) - i ; var up : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for k : Integer.subrange(0, n-1) do ( if ((2)->pow((n - 1 - k))->compareTo(i)) <= 0 then ( up[k+1] := 1 ; i := (2)->pow((n - k)) - 1 - i ) else skip) ; up := up->reverse() ; var ans : String := "" ; j := j - 1 ; for k : Integer.subrange(0, n-1) do ( if up[k+1] = 0 & (j->compareTo((2)->pow((n - 1 - k)))) < 0 then ( var j : OclAny := j ; ans := ans + "R" ) else (if up[k+1] = 0 & ((2)->pow((n - 1 - k))->compareTo(j)) <= 0 then ( j := j - (2)->pow((n - 1 - k)) ; ans := ans + "L" ) else (if up[k+1] = 1 & (j->compareTo((2)->pow((n - 1 - k)))) < 0 then ( j := (2)->pow((n - 1 - k)) - 1 - j ; ans := ans + "L" ) else (if up[k+1] = 1 & ((2)->pow((n - 1 - k))->compareTo(j)) <= 0 then ( j := (2)->pow((n - k)) - 1 - j ; ans := ans + "R" ) else skip ) ) ) ) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (n,k)=map(int,input().split('')) S=input() convert_to_list=list(S) if k>0 : if len(S)==1 : print(0) else : i=0 j=0 while jcollect( _x | (OclType["int"])->apply(_x) ) ; var S : String := (OclFile["System.in"]).readLine() ; var convert_to_list : Sequence := (S)->characters() ; if k > 0 then ( if (S)->size() = 1 then ( execute (0)->display() ) else ( var i : int := 0 ; var j : int := 0 ; while (j->compareTo(k)) < 0 do ( if i = 0 then ( if convert_to_list[i+1] /= '1' then ( convert_to_list[i+1] := '1' ; j := j + 1 ) else skip ) else ( if convert_to_list[i+1] /= '0' then ( convert_to_list[i+1] := '0' ; j := j + 1 ) else skip ) ; if i = n - 1 then ( break ) else skip ; i := i + 1) ; execute (StringLib.sumStringsWithSeparator((convert_to_list), ''))->display() ) ) else ( execute (S)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printExpansion(str): for i in range(len(str)-1,-1,-1): for j in range(i,len(str)): print(str[j],end="") str="geeks" printExpansion(str) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclType["String"] := "geeks" ; printExpansion(OclType["String"]); operation printExpansion(OclType["String"] : OclAny) pre: true post: true activity: for i : Integer.subrange(-1 + 1, (OclType["String"])->size() - 1)->reverse() do ( for j : Integer.subrange(i, (OclType["String"])->size()-1) do ( execute (("" + ([j+1])))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() a=(int(n[0])+1)*(10**(len(n)-1)) print(a-int(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var a : double := (("" + ((n->first())))->toInteger() + 1) * ((10)->pow(((n)->size() - 1))) ; execute (a - ("" + ((n)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n>=0 and n<=9 : print(1) else : s=str(n) k=(int(s[0])+1)*(10**(len(s)-1)) print(k-n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n >= 0 & n <= 9 then ( execute (1)->display() ) else ( var s : String := ("" + ((n))) ; var k : double := (("" + ((s->first())))->toInteger() + 1) * ((10)->pow(((s)->size() - 1))) ; execute (k - n)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- y=input()[1 :] print(10**len(y)-int(y or 0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var y : OclAny := input()->tail() ; execute ((10)->pow((y)->size()) - ("" + ((y or 0)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if len(str(n))==1 : print(1) else : x=str(int(str(n)[0])+1) y=len(str(n))-1 z='0'*y x=x+z x=int(x) print(x-n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (("" + ((n))))->size() = 1 then ( execute (1)->display() ) else ( var x : String := ("" + ((("" + ((OclType["String"](n)->first())))->toInteger() + 1))) ; var y : double := (("" + ((n))))->size() - 1 ; var z : String := StringLib.nCopies('0', y) ; x := x + z ; x := ("" + ((x)))->toInteger() ; execute (x - n)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r,g,b=map(int,input().split()) if(2*g+b)% 4==0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : OclAny := null; var g : OclAny := null; var b : OclAny := null; Sequence{r,g,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (2 * g + b) mod 4 = 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- 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(N,X): if N % 2==0 and X==N//2 : return 3*X ans=0 if X>N//2 : X=N-X ans=X def f(n,x): ans=0 ans+=n n_x=n//x ans+=2*n_x*x-x if n % x!=0 : ans+=f(x,n-n_x*x) return ans return ans+f(N-X,X) def main(): N,X=read_int_n() print(slv(N,X)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(10000) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; (compound_stmt (decorator @ (dotted_name (name mt))) (funcdef def (name slv) ( (typedargslist (def_parameters (def_parameter (named_parameter (name N))) , (def_parameter (named_parameter (name X))))) ) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (expr (atom (name N))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 0))))))) and (logical_test (comparison (comparison (expr (atom (name X)))) == (comparison (expr (expr (atom (name N))) // (expr (atom (number (integer 2)))))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (expr (atom (number (integer 3)))) * (expr (atom (name X)))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name X)))) > (comparison (expr (expr (atom (name N))) // (expr (atom (number (integer 2))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name X)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name N))) - (expr (atom (name X)))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name X)))))))))))) (stmt (compound_stmt (funcdef def (name f) ( (typedargslist (def_parameters (def_parameter (named_parameter (name n))) , (def_parameter (named_parameter (name x))))) ) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name n))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name n_x)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name n))) // (expr (atom (name x))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (expr (expr (atom (number (integer 2)))) * (expr (atom (name n_x)))) * (expr (atom (name x)))) - (expr (atom (name x)))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name n))) % (expr (atom (name x))))) != (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name f)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (expr (atom (name n_x))) * (expr (atom (name x)))))))))) ))))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name ans)))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (expr (atom (name ans))) + (expr (atom (name f)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name N))) - (expr (atom (name X)))))))) , (argument (test (logical_test (comparison (expr (atom (name X)))))))) ))))))))))))))) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation read_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation read_int_n() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation read_float() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation read_float_n() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["double"])->apply(_x) )); operation read_str() : OclAny pre: true post: true activity: return input()->trim(); operation read_str_n() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["String"])->apply(_x) )); operation error_print(args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) execute ((argument * (test (logical_test (comparison (expr (atom (name args))))))))->display(); operation mt(f : OclAny) : OclAny pre: true post: true activity: skip ; skip ; return wrap; operation main() pre: true post: true activity: var N : OclAny := null; var X : OclAny := null; Sequence{N,X} := read_int_n() ; execute (slv(N, X))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r,g,b=(int(i)for i in input().split()) print('YES' if(r*100+g*10+b)% 4==0 else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : OclAny := null; var g : OclAny := null; var b : OclAny := null; Sequence{r,g,b} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; execute (if (r * 100 + g * 10 + b) mod 4 = 0 then 'YES' else 'NO' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=list(input().split()) num=int("".join(num)) if num % 4==0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : Sequence := (input().split()) ; num := ("" + ((StringLib.sumStringsWithSeparator((num), ""))))->toInteger() ; if num mod 4 = 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r,g,b=map(int,input().split()) print('YES' if((100*r)+(10*g)+b)% 4==0 else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : OclAny := null; var g : OclAny := null; var b : OclAny := null; Sequence{r,g,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if ((100 * r) + (10 * g) + b) mod 4 = 0 then 'YES' else 'NO' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=list(map(int,input().split())) s,g=input(),0 if n==1 and k>0 : print(0) elif k==0 : print(s) elif k>=n : print("1"*1+"0"*(n-1)) else : for i in range(n): if i==0 : if s[i]=="1" : print(s[i],end="") else : print("1",end="") g+=1 else : if s[i]=="0" : print(s[i],end="") else : print("0",end="") g+=1 if g==k : break print(s[i+1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : OclAny := null; var g : OclAny := null; Sequence{s,g} := Sequence{(OclFile["System.in"]).readLine(),0} ; if n = 1 & k > 0 then ( execute (0)->display() ) else (if k = 0 then ( execute (s)->display() ) else (if (k->compareTo(n)) >= 0 then ( execute (StringLib.nCopies("1", 1) + StringLib.nCopies("0", (n - 1)))->display() ) else ( for i : Integer.subrange(0, n-1) do ( if i = 0 then ( if s[i+1] = "1" then ( execute (s[i+1])->display() ) else ( execute ("1")->display() ; g := g + 1 ) ) else ( if s[i+1] = "0" then ( execute (s[i+1])->display() ) else ( execute ("0")->display() ; g := g + 1 ) ) ; if g = k then ( break ) else skip) ; execute (s.subrange(i + 1+1))->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r,g,b=input().split() x=r+g+b y=int(x) if y % 4==0 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : OclAny := null; var g : OclAny := null; var b : OclAny := null; Sequence{r,g,b} := input().split() ; var x : OclAny := r + g + b ; var y : int := ("" + ((x)))->toInteger() ; if y mod 4 = 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def shuffle(N,key): NO_OF_BITS=N reverse_num=0 for i in range(NO_OF_BITS): temp=(key &(1<pow(i))))) ; if (temp) then ( reverse_num := reverse_num or (1 * (2->pow(((NO_OF_BITS - 1) - i)))) ) else skip) ; execute (reverse_num)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def recaman(n): if(n<=0): return print(0,",",end='') s=set([]) s.add(0) prev=0 for i in range(1,n): curr=prev-i if(curr<0 or curr in s): curr=prev+i s.add(curr) print(curr,",",end='') prev=curr if __name__=='__main__' : n=17 recaman(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 17 ; recaman(n) ) else skip; operation recaman(n : OclAny) pre: true post: true activity: if (n <= 0) then ( return ) else skip ; execute (0)->display() ; var s : Set := Set{}->union((Sequence{})) ; execute ((0) : s) ; var prev : int := 0 ; for i : Integer.subrange(1, n-1) do ( var curr : double := prev - i ; if (curr < 0 or (s)->includes(curr)) then ( curr := prev + i ) else skip ; execute ((curr) : s) ; execute (curr)->display() ; prev := curr); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findFoot(a,b,c,x1,y1): temp=(-1*(a*x1+b*y1+c)//(a*a+b*b)) x=temp*a+x1 y=temp*b+y1 return(x,y) if __name__=="__main__" : a,b,c=0.0,1.0,-2 x1,y1=3.0,3.0 foot=findFoot(a,b,c,x1,y1) print(int(foot[0]),int(foot[1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{a,b,c} := Sequence{0.0,1.0,-2} ; Sequence{x1,y1} := Sequence{3.0,3.0} ; var foot : OclAny := findFoot(a, b, c, x1, y1) ; execute (("" + ((foot->first())))->toInteger())->display() ) else skip; operation findFoot(a : OclAny, b : OclAny, c : OclAny, x1 : OclAny, y1 : OclAny) : OclAny pre: true post: true activity: var temp : int := (-1 * (a * x1 + b * y1 + c) div (a * a + b * b)) ; var x : double := temp * a + x1 ; var y : double := temp * b + y1 ; return Sequence{x, y}; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count(n): table=[0 for i in range(n+1)] table[0]=1 for i in range(3,n+1): table[i]+=table[i-3] for i in range(5,n+1): table[i]+=table[i-5] for i in range(10,n+1): table[i]+=table[i-10] return table[n] n=20 print('Count for',n,'is',count(n)) n=13 print('Count for',n,'is',count(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 20 ; execute ('Count for')->display() ; n := 13 ; execute ('Count for')->display(); operation count(n : OclAny) : OclAny pre: true post: true activity: var table : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; table->first() := 1 ; for i : Integer.subrange(3, n + 1-1) do ( table[i+1] := table[i+1] + table[i - 3+1]) ; for i : Integer.subrange(5, n + 1-1) do ( table[i+1] := table[i+1] + table[i - 5+1]) ; for i : Integer.subrange(10, n + 1-1) do ( table[i+1] := table[i+1] + table[i - 10+1]) ; return table[n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def moveZerosToEnd(arr,n): count=0 ; for i in range(0,n): if(arr[i]!=0): arr[count],arr[i]=arr[i],arr[count] count+=1 def printArray(arr,n): for i in range(0,n): print(arr[i],end=" ") arr=[0,1,9,8,4,0,0,2,7,0,6,0,9] n=len(arr) print("Original array:",end=" ") printArray(arr,n) moveZerosToEnd(arr,n) print("\nModified array: ",end=" ") printArray(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{0}->union(Sequence{1}->union(Sequence{9}->union(Sequence{8}->union(Sequence{4}->union(Sequence{0}->union(Sequence{0}->union(Sequence{2}->union(Sequence{7}->union(Sequence{0}->union(Sequence{6}->union(Sequence{0}->union(Sequence{ 9 })))))))))))) ; n := (arr)->size() ; execute ("Original array:")->display() ; printArray(arr, n) ; moveZerosToEnd(arr, n) ; execute ("\nModified array: ")->display() ; printArray(arr, n); operation moveZerosToEnd(arr : OclAny, n : OclAny) pre: true post: true activity: var count : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] /= 0) then ( var arr[count+1] : OclAny := null; var arr[i+1] : OclAny := null; Sequence{arr[count+1],arr[i+1]} := Sequence{arr[i+1],arr[count+1]} ; count := count + 1 ) else skip); operation printArray(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math A=int(input()) numerador=0 denominador=A-2 for base in range(2,A): sum=0 n=A while(n): sum+=n % base n=n//base numerador+=int(sum) gcd=math.gcd(int(numerador),int(denominador)) numerador=numerador/gcd denominador=denominador/gcd print(int(numerador),int(denominador),sep='/') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var numerador : int := 0 ; var denominador : double := A - 2 ; for base : Integer.subrange(2, A-1) do ( var sum : int := 0 ; var n : int := A ; while (n) do ( sum := sum + n mod base ; n := n div base) ; numerador := numerador + ("" + ((sum)))->toInteger()) ; var gcd : long := (("" + ((numerador)))->toInteger())->gcd(("" + ((denominador)))->toInteger()) ; numerador := numerador / gcd ; denominador := denominador / gcd ; execute (("" + ((numerador)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import gcd n,k=map(int,input().split(' ')) print(3*(n-gcd(n,k))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; execute (3 * (n - gcd(n, k)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def baseb(m,b,result=0): e=m//b q=m % b if e==0 : result+=q return result else : result+=q return baseb(e,b,result) n=int(input()) res=0 for i in range(2,n): res+=baseb(n,i) a=res b=n-2 while a!=0 and b!=0 : if a>b : a=a % b else : b=b % a nod=a+b print(str(res//nod)+'/'+str((n-2)//nod)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : int := 0 ; for i : Integer.subrange(2, n-1) do ( res := res + baseb(n, i)) ; var a : int := res ; b := n - 2 ; while a /= 0 & b /= 0 do ( if (a->compareTo(b)) > 0 then ( a := a mod b ) else ( b := b mod a )) ; var nod : int := a + b ; execute (("" + ((res div nod))) + '/' + ("" + (((n - 2) div nod))))->display(); operation baseb(m : OclAny, b : OclAny, result : int) : OclAny pre: true post: true activity: if result->oclIsUndefined() then result := 0 else skip; var e : int := m div b ; var q : int := m mod b ; if e = 0 then ( result := result + q ; return result ) else ( result := result + q ; return baseb(e, b, result) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) str=input() a=[] b=[] for i in range(n): a.append(int(str[i])) b.append(int(str[i])) def check(x): for i in range(n): if x[i]>b[i]: return True elif x[i]collect( _x | (OclType["int"])->apply(_x) ) ; var OclType["String"] : String := (OclFile["System.in"]).readLine() ; var a : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + ((("" + ([i+1])))))->toInteger()) : a) ; execute ((("" + ((("" + ([i+1])))))->toInteger()) : b)) ; skip ; for i : Integer.subrange(0, k-1) do ( for j : Integer.subrange(i, n-1)->select( $x | ($x - i) mod k = 0 ) do ( a[j+1] := a[i+1])) ; if check(a) <>= false then ( a[k - 1+1] := a[k - 1+1] + 1 ; for i : Integer.subrange(k - 1 + k, n-1)->select( $x | ($x - k - 1 + k) mod k = 0 ) do ( a[i+1] := a[k - 1+1]) ) else skip ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if a[i+1] = 10 then ( a[i - 1+1] := a[i - 1+1] + 1 ; a[i+1] := 0 ) else skip) ; for i : Integer.subrange(0, k-1) do ( for j : Integer.subrange(i, n-1)->select( $x | ($x - i) mod k = 0 ) do ( a[j+1] := a[i+1])) ; execute (n)->display() ; for i : Integer.subrange(0, n-1) do ( execute (a[i+1])->display()); operation check(x : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if (x[i+1]->compareTo(b[i+1])) > 0 then ( return true ) else (if (x[i+1]->compareTo(b[i+1])) < 0 then ( return false ) else skip)) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys from collections import deque,OrderedDict,defaultdict import heapq from collections import Counter def inp(): return sys.stdin.readline().rstrip() def mpp(): return map(int,inp().split()) def lis(): return list(mpp()) def yn(n): if n : return "YES" else : return "NO" def fn(arr,k): i=0 if len(arr)==1 and k>=1 : return["0"] while k>0 and icollect( _x | (OclType["int"])->apply(_x) ); operation lis() : OclAny pre: true post: true activity: return (mpp()); operation yn(n : OclAny) : OclAny pre: true post: true activity: if n then ( return "YES" ) else ( return "NO" ); operation fn(arr : OclAny, k : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; if (arr)->size() = 1 & k >= 1 then ( return Sequence{ "0" } ) else skip ; while k > 0 & (i->compareTo((arr)->size())) < 0 do ( if i = 0 then ( if arr[i+1] = 1 then ( skip ) else ( arr[i+1] := 1 ; k := k - 1 ) ) else ( if arr[i+1] = 0 then ( skip ) else ( arr[i+1] := 0 ; k := k - 1 ) ) ; i := i + 1) ; arr := arr->select(i | true)->collect(i | (("" + ((i))))) ; return arr; operation main() pre: true post: true activity: Sequence{n,k} := mpp() ; var s : OclAny := inp() ; arr := s->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute (StringLib.sumStringsWithSeparator((fn(arr, k)), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) s=list(input()) i=0 s_k=s[: k] change=0 for i in range(k,n): if s_k[i % k]>s[i]: change=0 break elif s_k[i % k]collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var i : int := 0 ; var s_k : OclAny := s.subrange(1,k) ; var change : int := 0 ; for i : Integer.subrange(k, n-1) do ( if (s_k[i mod k+1]->compareTo(s[i+1])) > 0 then ( change := 0 ; break ) else (if (s_k[i mod k+1]->compareTo(s[i+1])) < 0 then ( change := 1 ; break ) else skip)) ; if change = 1 then ( var br : int := 0 ; for i : Integer.subrange(1, (s_k)->size() + 1-1) do ( br := i ; if s_k->reverse()->at(-(-i)) /= '9' then ( s_k->reverse()->at(-(-i)) := ((s_k->reverse()->at(-(-i)))->char2byte() + 1)->byte2char() ; break ) else skip) ; s_k := s_k.subrange(1,k - br + 1)->union(MatrixLib.elementwiseMult(Sequence{ '0' }, (br - 1))) ) else skip ; var ans : String := StringLib.sumStringsWithSeparator((s_k * (n div k) + s_k.subrange(1,n mod k)), "") ; execute (n)->display() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) s=input() curp=s[: k] cur=str(curp*(n//k+1))[: n] if int(cur)>=int(s): print(n) print(cur) exit(0) curp=str(int(curp)+1) c=10**k if int(curp)collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var curp : OclAny := s.subrange(1,k) ; var cur : OclAny := OclType["String"](curp * (n div k + 1)).subrange(1,n) ; if (("" + ((cur)))->toInteger()->compareTo(("" + ((s)))->toInteger())) >= 0 then ( execute (n)->display() ; execute (cur)->display() ; exit(0) ) else skip ; curp := ("" + ((("" + ((curp)))->toInteger() + 1))) ; var c : double := (10)->pow(k) ; if (("" + ((curp)))->toInteger()->compareTo(c)) < 0 then ( cur := OclType["String"](curp * (n div k + 1)).subrange(1,n) ; execute (n)->display() ; execute (cur)->display() ; exit(0) ) else ( cur := OclType["String"](("" + ((c))) * (n div k + 1)).subrange(1,(n + 1)) ; execute (n + 1)->display() ; execute (cur)->display() ; exit(0) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=list(input()) b=a[:] for i in range(k): for j in range(i+k,n,k): b[j]=b[i] if ''.join(b)<''.join(a): for i in range(k-1,-1,-1): m=str(int(b[i])+1) if m!='10' : for j in range(i,n,k): b[j]=m break else : for j in range(i,n,k): b[j]='0' print(n) print(''.join(b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var b : Sequence := a ; for i : Integer.subrange(0, k-1) do ( for j : Integer.subrange(i + k, n-1)->select( $x | ($x - i + k) mod k = 0 ) do ( b[j+1] := b[i+1])) ; if (StringLib.sumStringsWithSeparator((b), '')->compareTo(StringLib.sumStringsWithSeparator((a), ''))) < 0 then ( for i : Integer.subrange(-1 + 1, k - 1)->reverse() do ( var m : String := ("" + ((("" + ((b[i+1])))->toInteger() + 1))) ; if m /= '10' then ( for j : Integer.subrange(i, n-1)->select( $x | ($x - i) mod k = 0 ) do ( b[j+1] := m) ; break ) else ( for j : Integer.subrange(i, n-1)->select( $x | ($x - i) mod k = 0 ) do ( b[j+1] := '0') )) ) else skip ; execute (n)->display() ; execute (StringLib.sumStringsWithSeparator((b), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) str=input() a=[] b=[] for i in range(n): a.append(int(str[i])) b.append(int(str[i])) def check(x): for i in range(n): if x[i]>b[i]: return True elif x[i]collect( _x | (OclType["int"])->apply(_x) ) ; var OclType["String"] : String := (OclFile["System.in"]).readLine() ; var a : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + ((("" + ([i+1])))))->toInteger()) : a) ; execute ((("" + ((("" + ([i+1])))))->toInteger()) : b)) ; skip ; for i : Integer.subrange(0, k-1) do ( for j : Integer.subrange(i, n-1)->select( $x | ($x - i) mod k = 0 ) do ( a[j+1] := a[i+1])) ; if check(a) <>= false then ( a[k - 1+1] := a[k - 1+1] + 1 ; for i : Integer.subrange(k - 1 + k, n-1)->select( $x | ($x - k - 1 + k) mod k = 0 ) do ( a[i+1] := a[k - 1+1]) ) else skip ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if a[i+1] = 10 then ( a[i - 1+1] := a[i - 1+1] + 1 ; a[i+1] := 0 ) else skip) ; for i : Integer.subrange(0, k-1) do ( for j : Integer.subrange(i, n-1)->select( $x | ($x - i) mod k = 0 ) do ( a[j+1] := a[i+1])) ; execute (n)->display() ; for i : Integer.subrange(0, n-1) do ( execute (a[i+1])->display()); operation check(x : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if (x[i+1]->compareTo(b[i+1])) > 0 then ( return true ) else (if (x[i+1]->compareTo(b[i+1])) < 0 then ( return false ) else skip)) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def longestsubarray(arr,n,k): current_count=0 max_count=0 for i in range(0,n,1): if(arr[i]% k==0): current_count+=1 else : current_count=0 max_count=max(current_count,max_count) return max_count if __name__=='__main__' : arr=[2,5,11,32,64,88] n=len(arr) k=8 print(longestsubarray(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{2}->union(Sequence{5}->union(Sequence{11}->union(Sequence{32}->union(Sequence{64}->union(Sequence{ 88 }))))) ; n := (arr)->size() ; k := 8 ; execute (longestsubarray(arr, n, k))->display() ) else skip; operation longestsubarray(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var current_count : int := 0 ; var max_count : int := 0 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (arr[i+1] mod k = 0) then ( current_count := current_count + 1 ) else ( current_count := 0 ) ; max_count := Set{current_count, max_count}->max()) ; return max_count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=3 M=3 def majorityInMatrix(arr): mp={i : 0 for i in range(7)} for i in range(len(arr)): for j in range(len(arr)): mp[arr[i][j]]+=1 countMajority=0 for key,value in mp.items(): if(value>=(int((N*M)/2))): countMajority+=1 return countMajority if __name__=='__main__' : mat=[[1,2,2],[1,3,2],[1,2,6]] print(majorityInMatrix(mat)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 3 ; var M : int := 3 ; skip ; if __name__ = '__main__' then ( var mat : Sequence := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 2 }))}->union(Sequence{Sequence{1}->union(Sequence{3}->union(Sequence{ 2 }))}->union(Sequence{ Sequence{1}->union(Sequence{2}->union(Sequence{ 6 })) })) ; execute (majorityInMatrix(mat))->display() ) else skip; operation majorityInMatrix(arr : OclAny) : OclAny pre: true post: true activity: var mp : Map := Integer.subrange(0, 7-1)->select(i | true)->collect(i | Map{i |-> 0})->unionAll() ; for i : Integer.subrange(0, (arr)->size()-1) do ( for j : Integer.subrange(0, (arr)->size()-1) do ( mp[arr[i+1][j+1]+1] := mp[arr[i+1][j+1]+1] + 1)) ; var countMajority : int := 0 ; for _tuple : mp->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); if ((value->compareTo((("" + (((N * M) / 2)))->toInteger()))) >= 0) then ( countMajority := countMajority + 1 ) else skip) ; return countMajority; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) if a>0 : print(a) else : x=abs(a) if x==10 : print(0) else : y=x//10 z=(x//100)*10+x % 10 print(min(y,z)*(-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if a > 0 then ( execute (a)->display() ) else ( var x : double := (a)->abs() ; if x = 10 then ( execute (0)->display() ) else ( var y : int := x div 10 ; var z : int := (x div 100) * 10 + x mod 10 ; execute (Set{y, z}->min() * (-1))->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n>=0 : print(n) else : s=str(n) if int(s[-2])<=int(s[-1]): s_new=s[:-1] else : s_new=s[:-2]+s[-1] print(int(s_new)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n >= 0 then ( execute (n)->display() ) else ( var s : String := ("" + ((n))) ; if (("" + ((s->front()->last())))->toInteger()->compareTo(("" + ((s->last())))->toInteger())) <= 0 then ( var s_new : OclAny := s->front() ) else ( s_new := s->front()->front() + s->last() ) ; execute (("" + ((s_new)))->toInteger())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline sys.setrecursionlimit(1000000) from collections import deque,Counter def getN(): return int(input()) def getList(): return list(map(int,input().split())) import math INF=10**10 def bfs(graph,visited,position,root): visited[root]=1 position[root]=0 deq=deque([root]) while(deq): cur=deq.pop() for nxt,dist in graph[cur]: if position[cur]+dist!=position[nxt]: if position[nxt]!=INF : return False else : position[nxt]=position[cur]+dist if not visited[nxt]: deq.append(nxt) visited[nxt]=1 return True def main(): n,x=getList() ans=n mx,mn=x,n-x if mxpow(10) ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation getN() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation getList() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation bfs(graph : OclAny, visited : OclAny, position : OclAny, root : OclAny) : OclAny pre: true post: true activity: visited[root+1] := 1 ; position[root+1] := 0 ; var deq : Sequence := (Sequence{ root }) ; while (deq) do ( var cur : OclAny := deq->last() ; deq := deq->front() ; for _tuple : graph[cur+1] do (var _indx : int := 1; var nxt : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dist : OclAny := _tuple->at(_indx); if position[cur+1] + dist /= position[nxt+1] then ( if position[nxt+1] /= INF then ( return false ) else ( position[nxt+1] := position[cur+1] + dist ) ) else skip ; if not(visited[nxt+1]) then ( execute ((nxt) : deq) ; visited[nxt+1] := 1 ) else skip)) ; return true; operation main() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := getList() ; var ans : OclAny := n ; var mx : OclAny := null; var mn : OclAny := null; Sequence{mx,mn} := Sequence{x,n - x} ; if (mx->compareTo(mn)) < 0 then ( var mx : OclAny := null; var mn : OclAny := null; Sequence{mx,mn} := Sequence{mn,mx} ) else skip ; while (true) do ( if mx mod mn = 0 then ( ans := ans + 2 * mn * (mx div mn) - mn ; break ) else ( ans := ans + mn * 2 * (mx div mn) ; var mx : OclAny := null; var mn : OclAny := null; Sequence{mx,mn} := Sequence{mn,mx mod mn} )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n>0 : print(n) else : n=n*-1 m=min(n % 10,n//10 % 10) b='-'+str(n//100)+str(m) print(int(b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n > 0 then ( execute (n)->display() ) else ( n := n * -1 ; var m : OclAny := Set{n mod 10, n div 10 mod 10}->min() ; var b : String := '-' + ("" + ((n div 100))) + ("" + ((m))) ; execute (("" + ((b)))->toInteger())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) c=input() g=[] n=0 for i in c : i=int(i) g.append(i) if g[0]==1 and len(g)>2 : for u in range(1,len(g)): if n==b : break elif g[u]!=0 : g[u]=0 n+=1 elif len(g)==1 and b==1 : g[0]=0 elif c=='0' : g=[c] elif g[0]==1 and len(g)==2 : g[1]=0 else : for h in range(0,len(g)): if n==b : break if h==0 : g[h]=1 n+=1 elif g[h]!=0 : g[h]=0 n+=1 print(*g,sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : String := (OclFile["System.in"]).readLine() ; var g : Sequence := Sequence{} ; var n : int := 0 ; for i : c->characters() do ( var i : int := ("" + ((i)))->toInteger() ; execute ((i) : g)) ; if g->first() = 1 & (g)->size() > 2 then ( for u : Integer.subrange(1, (g)->size()-1) do ( if n = b then ( break ) else (if g[u+1] /= 0 then ( g[u+1] := 0 ; n := n + 1 ) else skip)) ) else (if (g)->size() = 1 & b = 1 then ( g->first() := 0 ) else (if c = '0' then ( g := Sequence{ c } ) else (if g->first() = 1 & (g)->size() = 2 then ( g[1+1] := 0 ) else ( for h : Integer.subrange(0, (g)->size()-1) do ( if n = b then ( break ) else skip ; if h = 0 then ( g[h+1] := 1 ; n := n + 1 ) else (if g[h+1] /= 0 then ( g[h+1] := 0 ; n := n + 1 ) else skip)) ) ) ) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name g))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n>=0 : print(n) elif int(str(n)[-1])>int(str(n)[-2])and int(str(n)[:-1])==0 : print(0) elif int(str(n)[-1])>=int(str(n)[-2])and int(str(n)[:-1])!=0 : print(int(str(n)[:-1])) elif int(str(n)[-1])toInteger() ; if n >= 0 then ( execute (n)->display() ) else (if (("" + ((OclType["String"](n)->last())))->toInteger()->compareTo(("" + ((OclType["String"](n)->front()->last())))->toInteger())) > 0 & ("" + ((OclType["String"](n)->front())))->toInteger() = 0 then ( execute (0)->display() ) else (if (("" + ((OclType["String"](n)->last())))->toInteger()->compareTo(("" + ((OclType["String"](n)->front()->last())))->toInteger())) >= 0 & ("" + ((OclType["String"](n)->front())))->toInteger() /= 0 then ( execute (("" + ((OclType["String"](n)->front())))->toInteger())->display() ) else (if (("" + ((OclType["String"](n)->last())))->toInteger()->compareTo(("" + ((OclType["String"](n)->front()->last())))->toInteger())) < 0 & ("" + ((OclType["String"](n)->front())))->toInteger() = 0 then ( execute (0)->display() ) else (if (("" + ((OclType["String"](n)->last())))->toInteger()->compareTo(("" + ((OclType["String"](n)->front()->last())))->toInteger())) < 0 & ("" + ((OclType["String"](n)->front())))->toInteger() /= 0 then ( execute (("" + ((OclType["String"](n)->front()->front() + OclType["String"](n)->last())))->toInteger())->display() ) else ( execute (n)->display() ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w=input() w1=w[:-1] w2=w[:-2]+w[-1] print(max([int(w),int(w1),int(w2)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : String := (OclFile["System.in"]).readLine() ; var w1 : OclAny := w->front() ; var w2 : OclAny := w->front()->front() + w->last() ; execute ((Sequence{("" + ((w)))->toInteger()}->union(Sequence{("" + ((w1)))->toInteger()}->union(Sequence{ ("" + ((w2)))->toInteger() })))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkFunny(word): i=1 j=len(word)-2 word=word.lower() while(i<=j): if((abs(ord(word[i])-ord(word[i-1])))!=abs((ord(word[j])-ord(word[j+1])))): return False i=i+1 j=j-1 return True def printFunnyWords(str): str=str+"" word="" i=0 for i in range(len(str)): ch=str[i] if(ch!=' '): word=word+ch else : if(checkFunny(word)): print(word) word="" printFunnyWords("Miss Arora teaches us malayalam bdwy ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; printFunnyWords("Miss Arora teaches us malayalam bdwy "); operation checkFunny(word : OclAny) : OclAny pre: true post: true activity: var i : int := 1 ; var j : double := (word)->size() - 2 ; word := word->toLowerCase() ; while ((i->compareTo(j)) <= 0) do ( if ((((word[i+1])->char2byte() - (word[i - 1+1])->char2byte())->abs()) /= (((word[j+1])->char2byte() - (word[j + 1+1])->char2byte()))->abs()) then ( return false ) else skip ; i := i + 1 ; j := j - 1) ; return true; operation printFunnyWords(OclType["String"] : OclAny) pre: true post: true activity: OclType["String"] := OclType["String"] + "" ; word := "" ; i := 0 ; for i : Integer.subrange(0, (OclType["String"])->size()-1) do ( var ch : String := ("" + ([i+1])) ; if (ch /= ' ') then ( word := word + ch ) else ( if (checkFunny(word)) then ( execute (word)->display() ) else skip ; word := "" )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkDistinct(x): last=x % 10 while(x): if(x % 10!=last): return False x=x//10 return True def findCount(L,R): count=0 for i in range(L,R+1): if(checkDistinct(i)): count+=1 return count L=10 R=50 print(findCount(L,R)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; L := 10 ; R := 50 ; execute (findCount(L, R))->display(); operation checkDistinct(x : OclAny) : OclAny pre: true post: true activity: var last : int := x mod 10 ; while (x) do ( if (x mod 10 /= last) then ( return false ) else skip ; x := x div 10) ; return true; operation findCount(L : OclAny, R : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(L, R + 1-1) do ( if (checkDistinct(i)) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() w=s.replace("WUB"," ") print(w) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var w : String := s.replace("WUB", " ") ; execute (w)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- song=list(input().split("WUB")) original_song=[] for i in song : if i!='' : original_song+=[i] i=" ".join(original_song) print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var song : Sequence := (input().split("WUB")) ; var original_song : Sequence := Sequence{} ; for i : song do ( if i /= '' then ( original_song := original_song + Sequence{ i } ) else skip) ; var i : String := StringLib.sumStringsWithSeparator((original_song), " ") ; execute (i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input(" ") x=n.split("WUB") str='' for i in x : if i=='' : pass else : str+=i+' ' print(str) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine(" ") ; var x : OclAny := n.split("WUB") ; var OclType["String"] : String := '' ; for i : x do ( if i = '' then ( skip ) else ( OclType["String"] := OclType["String"] + i + ' ' )) ; execute (OclType["String"])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input().split("WUB") print(" ".join(n).strip()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := input().split("WUB") ; execute (" ".join(n)->trim())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() s1='' i=0 f=0 while icompareTo((s)->size())) < 0 do ( if s.subrange(i+1, i + 3) = 'WUB' & f = 1 then ( s1 := s1 + ' ' ; f := 0 ) else skip ; if s.subrange(i+1, i + 3) = 'WUB' then ( i := i + 3 ) else ( s1 := s1 + s[i+1] ; i := i + 1 ; f := 1 )) ; execute (s1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline def main(): N,M=map(int,readline().rstrip().split()) ans=min(N,M//2) M-=ans*2 ans+=M//4 print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (readline().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : OclAny := Set{N, M div 2}->min() ; M := M - ans * 2 ; ans := ans + M div 4 ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[] for i in range(4): data=input().split() a.append([int(i)for i in data]) def func(a): band=0 for i in range(4): if a[i][3]==1 : if a[(i+2)% 4][1]: band=1 if a[(i+1)% 4][0]or a[(i+3)% 4][2]: band=1 if a[i][0]or a[i][1]or a[i][2]: band=1 if band : print("YES") else : print("NO") func(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Sequence{} ; for i : Integer.subrange(0, 4-1) do ( var data : OclAny := input().split() ; execute ((data->select(i | true)->collect(i | (("" + ((i)))->toInteger()))) : a)) ; skip ; func(a); operation func(a : OclAny) pre: true post: true activity: var band : int := 0 ; for i : Integer.subrange(0, 4-1) do ( if a[i+1][3+1] = 1 then ( if a[(i + 2) mod 4+1][1+1] then ( band := 1 ) else skip ; if a[(i + 1) mod 4+1]->first() or a[(i + 3) mod 4+1][2+1] then ( band := 1 ) else skip ; if a[i+1]->first() or a[i+1][1+1] or a[i+1][2+1] then ( band := 1 ) else skip ) else skip) ; if band then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Valid(a,b,c): if((a+b+c==180)and a!=0 and b!=0 and c!=0): return True else : return False if __name__=="__main__" : a=60 b=40 c=80 if(Valid(a,b,c)): print("Valid") else : print("Invalid") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := 60 ; b := 40 ; c := 80 ; if (Valid(a, b, c)) then ( execute ("Valid")->display() ) else ( execute ("Invalid")->display() ) ) else skip; operation Valid(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: if ((a + b + c = 180) & a /= 0 & b /= 0 & c /= 0) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkValidity(a,b,c): if(a+b<=c)or(a+c<=b)or(b+c<=a): return False else : return True a=7 b=10 c=5 if checkValidity(a,b,c): print("Valid") else : print("Invalid") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 7 ; b := 10 ; c := 5 ; if checkValidity(a, b, c) then ( execute ("Valid")->display() ) else ( execute ("Invalid")->display() ); operation checkValidity(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: if ((a + b->compareTo(c)) <= 0) or ((a + c->compareTo(b)) <= 0) or ((b + c->compareTo(a)) <= 0) then ( return false ) else ( return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=0 for i in range(3): s=input() c=0 if i==0 or i==2 : for i in s : if i in 'aeiou' : c+=1 if c!=5 : x+=1 else : for i in s : if i in 'aeiou' : c+=1 if c!=7 : x+=1 if not x : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 0 ; for i : Integer.subrange(0, 3-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var c : int := 0 ; if i = 0 or i = 2 then ( for i : s->characters() do ( if ('aeiou')->characters()->includes(i) then ( c := c + 1 ) else skip) ; if c /= 5 then ( x := x + 1 ) else skip ) else ( for i : s->characters() do ( if ('aeiou')->characters()->includes(i) then ( c := c + 1 ) else skip) ; if c /= 7 then ( x := x + 1 ) else skip )) ; if not(x) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(s): st={"a","e","i","o","u"} d=0 for c in s : if(c in st): d+=1 return d print(("NO","YES")[f(input())==5 and f(input())==7 and f(input())==5]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (Sequence{"NO", "YES"}->select(f((OclFile["System.in"]).readLine()) = 5 & f((OclFile["System.in"]).readLine()) = 7 & f((OclFile["System.in"]).readLine()) = 5))->display(); operation f(s : OclAny) : OclAny pre: true post: true activity: var st : Set := Set{"a"}->union(Set{"e"}->union(Set{"i"}->union(Set{"o"}->union(Set{ "u" })))) ; var d : int := 0 ; for c : s do ( if ((st)->includes(c)) then ( d := d + 1 ) else skip) ; return d; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p1=input() p2=input() p3=input() syllaList=['a','e','i','o','u'] c1=c2=c3=0 for i in p1 : if i in syllaList : c1+=1 for i in p2 : if i in syllaList : c2+=1 for i in p3 : if i in syllaList : c3+=1 if c1==c3==5 and c2==7 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p1 : String := (OclFile["System.in"]).readLine() ; var p2 : String := (OclFile["System.in"]).readLine() ; var p3 : String := (OclFile["System.in"]).readLine() ; var syllaList : Sequence := Sequence{'a'}->union(Sequence{'e'}->union(Sequence{'i'}->union(Sequence{'o'}->union(Sequence{ 'u' })))) ; c1 := c1(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c2)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c3)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for i : p1->characters() do ( if (syllaList)->includes(i) then ( c1 := c1 + 1 ) else skip) ; for i : p2->characters() do ( if (syllaList)->includes(i) then ( c2 := c2 + 1 ) else skip) ; for i : p3->characters() do ( if (syllaList)->includes(i) then ( c3 := c3 + 1 ) else skip) ; if c1 = c3 & (c3 == 5) & c2 = 7 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- first=input() sec=input() third=input() comp="aeiou" f1=0 f2=0 f3=0 for i in range(len(first)): if first[i]in comp : f1+=1 if f1==5 : for i in range(len(sec)): if sec[i]in comp : f2+=1 if f2==7 : for i in range(len(third)): if third[i]in comp : f3+=1 if f3==5 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var first : String := (OclFile["System.in"]).readLine() ; var sec : String := (OclFile["System.in"]).readLine() ; var third : String := (OclFile["System.in"]).readLine() ; var comp : String := "aeiou" ; var f1 : int := 0 ; var f2 : int := 0 ; var f3 : int := 0 ; for i : Integer.subrange(0, (first)->size()-1) do ( if (comp)->characters()->includes(first[i+1]) then ( f1 := f1 + 1 ) else skip) ; if f1 = 5 then ( for i : Integer.subrange(0, (sec)->size()-1) do ( if (comp)->characters()->includes(sec[i+1]) then ( f2 := f2 + 1 ) else skip) ) else skip ; if f2 = 7 then ( for i : Integer.subrange(0, (third)->size()-1) do ( if (comp)->characters()->includes(third[i+1]) then ( f3 := f3 + 1 ) else skip) ) else skip ; if f3 = 5 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- vocales=['a','e','i','o','u'] a=str(input()) b=str(input()) c=str(input()) ia=0 ib=0 ic=0 for l in a : if l in vocales : ia+=1 for l in b : if l in vocales : ib+=1 for l in c : if l in vocales : ic+=1 if ia==5 and ib==7 and ic==5 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var vocales : Sequence := Sequence{'a'}->union(Sequence{'e'}->union(Sequence{'i'}->union(Sequence{'o'}->union(Sequence{ 'u' })))) ; var a : String := ("" + (((OclFile["System.in"]).readLine()))) ; var b : String := ("" + (((OclFile["System.in"]).readLine()))) ; var c : String := ("" + (((OclFile["System.in"]).readLine()))) ; var ia : int := 0 ; var ib : int := 0 ; var ic : int := 0 ; for l : a->characters() do ( if (vocales)->includes(l) then ( ia := ia + 1 ) else skip) ; for l : b->characters() do ( if (vocales)->includes(l) then ( ib := ib + 1 ) else skip) ; for l : c->characters() do ( if (vocales)->includes(l) then ( ic := ic + 1 ) else skip) ; if ia = 5 & ib = 7 & ic = 5 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculateSum(n): return(2*(n*(n+1)*(2*n+1)//6)+n*(n+1)//2+2*(n)) if __name__=="__main__" : n=3 print("Sum=",calculateSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 3 ; execute ("Sum=")->display() ) else skip; operation calculateSum(n : OclAny) : OclAny pre: true post: true activity: return (2 * (n * (n + 1) * (2 * n + 1) div 6) + n * (n + 1) div 2 + 2 * (n)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculateSum(n): return(n*(n+1)//2+n*(n+1)*(2*n+1)//6) n=3 print("Sum=",calculateSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3 ; execute ("Sum=")->display(); operation calculateSum(n : OclAny) : OclAny pre: true post: true activity: return (n * (n + 1) div 2 + n * (n + 1) * (2 * n + 1) div 6); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sum(n): if n==0 : return 1 return 1/pow(3,n)+sum(n-1) n=5 ; print(sum(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5; ; execute ((n)->sum())->display();; operation sum(n : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( return 1 ) else skip ; return 1 / (3)->pow(n) + (n - 1)->sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfAP(a,d,n): sum=0 i=0 while idisplay(); operation sumOfAP(a : OclAny, d : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( sum := sum + a ; a := a + d ; i := i + 1) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict as dd st=dd(int) av=dd(int) s=input() t=input() se=set() for i in s : se.add(i.lower()) for i in t : av[i]+=1 for i in s : st[i]+=1 y,w=0,0 for i in se : j=i.upper() a,b=min(st[i],av[i]),min(st[j],av[j]) y+=a+b st[i]-=a st[j]-=b av[i]-=a av[j]-=b c,d=min(st[i],av[j]),min(st[j],av[i]) w+=c+d print(y,w) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var st : OclAny := dd(OclType["int"]) ; var av : OclAny := dd(OclType["int"]) ; var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var se : Set := Set{}->union(()) ; for i : s->characters() do ( execute ((i->toLowerCase()) : se)) ; for i : t->characters() do ( av[i+1] := av[i+1] + 1) ; for i : s->characters() do ( st[i+1] := st[i+1] + 1) ; var y : OclAny := null; var w : OclAny := null; Sequence{y,w} := Sequence{0,0} ; for i : se do ( var j : String := i->toUpperCase() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{Set{st[i+1], av[i+1]}->min(),Set{st->at(j), av->at(j)}->min()} ; y := y + a + b ; st[i+1] := st[i+1] - a ; st->at(j) := st->at(j) - b ; av[i+1] := av[i+1] - a ; av->at(j) := av->at(j) - b ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := Sequence{Set{st[i+1], av->at(j)}->min(),Set{st->at(j), av[i+1]}->min()} ; w := w + c + d) ; execute (y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin data=[] for _ in range(0,4): data.append(list(map(int,stdin.readline().rstrip().split()))) l,s,r,p=0,1,2,3 for i in range(0,4): pval=data[i][p] if pval==1 and(pval==data[(i+1)% 4][l]or pval==data[(i+2)% 4][s]or pval==data[(i+3)% 4][r]or 1==data[i][l]or 1==data[i][s]or 1==data[i][r]): print("YES") exit() print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var data : Sequence := Sequence{} ; for _anon : Integer.subrange(0, 4-1) do ( execute ((((stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ))) : data)) ; var l : OclAny := null; var s : OclAny := null; var r : OclAny := null; var p : OclAny := null; Sequence{l,s,r,p} := Sequence{0,1,2,3} ; for i : Integer.subrange(0, 4-1) do ( var pval : OclAny := data[i+1][p+1] ; if pval = 1 & (pval = data[(i + 1) mod 4+1][l+1] or pval = data[(i + 2) mod 4+1][s+1] or pval = data[(i + 3) mod 4+1][r+1] or 1 = data[i+1][l+1] or 1 = data[i+1][s+1] or 1 = data[i+1][r+1]) then ( execute ("YES")->display() ; exit() ) else skip) ; execute ("NO")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : a=0 b=0 n=int(input()) if n==0 : break else : e=[[int(i)for i in input().split()]for i in range(n)] for i in e : if i[0]>i[1]: a+=sum(i) elif i[1]>i[0]: b+=sum(i) else : a+=i[0] b+=i[1] print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var a : int := 0 ; var b : int := 0 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else ( var e : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())))) ; for i : e do ( if (i->first()->compareTo(i[1+1])) > 0 then ( a := a + (i)->sum() ) else (if (i[1+1]->compareTo(i->first())) > 0 then ( b := b + (i)->sum() ) else ( a := a + i->first() ; b := b + i[1+1] ) ) ) ; execute (a)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys H=pow(10,9)+7 def _main(): n_s,n_c=map(int,sys.stdin.readline().split(' ')) if 2*n_s<=n_c : result=n_s+int((n_c-n_s*2)/4) else : result=int(n_c/2) print(result) if __name__=='__main__' : _main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var H : double := (10)->pow(9) + 7 ; skip ; if __name__ = '__main__' then ( _main() ) else skip; operation _main() pre: true post: true activity: var n_s : OclAny := null; var n_c : OclAny := null; Sequence{n_s,n_c} := (sys.stdin.readLine().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; if (2 * n_s->compareTo(n_c)) <= 0 then ( var result : OclAny := n_s + ("" + (((n_c - n_s * 2) / 4)))->toInteger() ) else ( result := ("" + ((n_c / 2)))->toInteger() ) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter print("YES" if Counter(input()+input())==Counter(input())else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (if Counter((OclFile["System.in"]).readLine() + (OclFile["System.in"]).readLine()) = Counter((OclFile["System.in"]).readLine()) then "YES" else "NO" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=input() c=list(str(x)for x in input()) flag=0 for i in a : if i in c : c.remove(i) else : flag=1 break for j in b : if j in c : c.remove(j) else : flag=1 break if flag==0 and len(c)==0 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var c : Sequence := ((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ; var flag : int := 0 ; for i : a->characters() do ( if (c)->includes(i) then ( execute ((i) /: c) ) else ( flag := 1 ; break )) ; for j : b->characters() do ( if (c)->includes(j) then ( execute ((j) /: c) ) else ( flag := 1 ; break )) ; if flag = 0 & (c)->size() = 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() b=input() c=list(str(x)for x in input()) flag=0 for i in s : if i in c : c.remove(i) else : flag=1 break for j in b : if j in c : c.remove(j) else : flag=1 break if flag==0 and len(c)==0 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var c : Sequence := ((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ; var flag : int := 0 ; for i : s->characters() do ( if (c)->includes(i) then ( execute ((i) /: c) ) else ( flag := 1 ; break )) ; for j : b->characters() do ( if (c)->includes(j) then ( execute ((j) /: c) ) else ( flag := 1 ; break )) ; if flag = 0 & (c)->size() = 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=input().upper() s=input().upper() l=input().upper() if len(f)<=100 and len(s)<=100 and len(l)<=100 : m=f+s last=sorted(l) mix=sorted(m) if last==mix : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : OclAny := input()->toUpperCase() ; var s : OclAny := input()->toUpperCase() ; var l : OclAny := input()->toUpperCase() ; if (f)->size() <= 100 & (s)->size() <= 100 & (l)->size() <= 100 then ( var m : OclAny := f + s ; var last : Sequence := l->sort() ; var mix : Sequence := m->sort() ; if last = mix then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- g=[x for x in input()] r=[x for x in input()] p=[x for x in input()] g=g+r c=0 if len(g)==len(p): for i in g : if i in p : p.remove(i) c+=1 if c==len(g): print("YES") else : print("NO") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var g : Sequence := (OclFile["System.in"]).readLine()->select(x | true)->collect(x | (x)) ; var r : Sequence := (OclFile["System.in"]).readLine()->select(x | true)->collect(x | (x)) ; var p : Sequence := (OclFile["System.in"]).readLine()->select(x | true)->collect(x | (x)) ; g := g->union(r) ; var c : int := 0 ; if (g)->size() = (p)->size() then ( for i : g do ( if (p)->includes(i) then ( execute ((i) /: p) ; c := c + 1 ) else skip) ; if c = (g)->size() then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMissingNo(arr,n): for i in range(n): if(arr[i]<=0 or arr[i]>n): continue val=arr[i] while(arr[val-1]!=val): nextval=arr[val-1] arr[val-1]=val val=nextval if(val<=0 or val>n): break for i in range(n): if(arr[i]!=i+1): return i+1 return n+1 if __name__=="__main__" : arr=[2,3,7,6,8,-1,-10,15] arr_size=len(arr) missing=findMissingNo(arr,arr_size) print("The smallest positive","missing number is ",missing) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{2}->union(Sequence{3}->union(Sequence{7}->union(Sequence{6}->union(Sequence{8}->union(Sequence{-1}->union(Sequence{-10}->union(Sequence{ 15 }))))))) ; var arr_size : int := (arr)->size() ; var missing : OclAny := findMissingNo(arr, arr_size) ; execute ("The smallest positive")->display() ) else skip; operation findMissingNo(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if (arr[i+1] <= 0 or (arr[i+1]->compareTo(n)) > 0) then ( continue ) else skip ; var val : OclAny := arr[i+1] ; while (arr[val - 1+1] /= val) do ( var nextval : OclAny := arr[val - 1+1] ; arr[val - 1+1] := val ; val := nextval ; if (val <= 0 or (val->compareTo(n)) > 0) then ( break ) else skip)) ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] /= i + 1) then ( return i + 1 ) else skip) ; return n + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reduceArray(arr,n,K): vec=[]; size=0 ; curr_ele=arr[0]; curr_freq=1 ; for i in range(n): if(curr_ele==arr[i]and curr_freq<=K): vec.append(arr[i]); size+=1 ; elif(curr_ele!=arr[i]): curr_ele=arr[i]; vec.append(arr[i]); size+=1 ; curr_freq=1 ; curr_freq+=1 ; print("{",end=""); for i in range(size): print(vec[i],end=","); print("}",end=""); if __name__=="__main__" : arr=[1,1,1,2,2,2,3,3,3,3,3,3,4,5]; n=len(arr) K=2 ; reduceArray(arr,n,K); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{3}->union(Sequence{3}->union(Sequence{3}->union(Sequence{3}->union(Sequence{3}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 }))))))))))))); ; n := (arr)->size() ; K := 2; ; reduceArray(arr, n, K); ) else skip; operation reduceArray(arr : OclAny, n : OclAny, K : OclAny) pre: true post: true activity: var vec : Sequence := Sequence{}; ; var size : int := 0; ; var curr_ele : OclAny := arr->first(); var curr_freq : int := 1; ; for i : Integer.subrange(0, n-1) do ( if (curr_ele = arr[i+1] & (curr_freq->compareTo(K)) <= 0) then ( execute ((arr[i+1]) : vec); ; size := size + 1; ) else (if (curr_ele /= arr[i+1]) then ( curr_ele := arr[i+1]; ; execute ((arr[i+1]) : vec); ; size := size + 1; ; curr_freq := 1; ) else skip) ; curr_freq := curr_freq + 1;) ; execute ("{")->display(); ; for i : Integer.subrange(0, size-1) do ( execute (vec[i+1])->display();) ; execute ("}")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def highestPowerof2(n): res=0 ; for i in range(n,0,-1): if((i &(i-1))==0): res=i ; break ; return res ; n=10 ; print(highestPowerof2(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 10; ; execute (highestPowerof2(n))->display();; operation highestPowerof2(n : OclAny) pre: true post: true activity: var res : int := 0; ; for i : Integer.subrange(0 + 1, n)->reverse() do ( if ((MathLib.bitwiseAnd(i, (i - 1))) = 0) then ( res := i; ; break; ) else skip) ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- road=[list(map(int,input().split()))for i in range(4)] for i in range(4): if road[i][3]==1 : if any([road[i][0],road[i][1],road[i][2],road[(i+1)% 4][0],road[(i+2)% 4][1],road[(i+3)% 4][2]]): print("YES") break else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var road : Sequence := Integer.subrange(0, 4-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 4))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name road)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 3))))))))) ])))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name any)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name road)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))) , (test (logical_test (comparison (expr (atom (name road)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))) , (test (logical_test (comparison (expr (atom (name road)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))) , (test (logical_test (comparison (expr (atom (name road)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) ))) % (expr (atom (number (integer 4)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))) , (test (logical_test (comparison (expr (atom (name road)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 2))))))))) ))) % (expr (atom (number (integer 4)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))) , (test (logical_test (comparison (expr (atom (name road)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 3))))))))) ))) % (expr (atom (number (integer 4)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ]))))))) ]))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSetBits(n): n+=1 ; powerOf2=2 ; cnt=n//2 ; while(powerOf2<=n): totalPairs=n//powerOf2 ; cnt+=(totalPairs//2)*powerOf2 ; if(totalPairs & 1): cnt+=(n % powerOf2) else : cnt+=0 powerOf2<<=1 ; return cnt ; if __name__=="__main__" : n=14 ; print(countSetBits(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 14; ; execute (countSetBits(n))->display(); ) else skip; operation countSetBits(n : OclAny) pre: true post: true activity: n := n + 1; ; var powerOf2 : int := 2; ; var cnt : int := n div 2; ; while ((powerOf2->compareTo(n)) <= 0) do ( var totalPairs : int := n div powerOf2; ; cnt := cnt + (totalPairs div 2) * powerOf2; ; if (MathLib.bitwiseAnd(totalPairs, 1)) then ( cnt := cnt + (n mod powerOf2) ) else ( cnt := cnt + 0 ) ; powerOf2 := powerOf2 * (2->pow(1));) ; return cnt;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def GCD(a,b): if(b==0): return a ; return GCD(b,a % b); def findReachable(arr,D,A,B,n): gcd_AB=GCD(A,B); count=0 ; for i in range(n): if((arr[i]-D)% gcd_AB==0): count+=1 ; return count ; arr=[4,5,6,7,8,9]; n=len(arr); D=4 ; A=4 ; B=6 ; print(findReachable(arr,D,A,B,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 9 }))))); ; n := (arr)->size(); ; D := 4; A := 4; B := 6; ; execute (findReachable(arr, D, A, B, n))->display();; operation GCD(a : OclAny, b : OclAny) pre: true post: true activity: if (b = 0) then ( return a; ) else skip ; return GCD(b, a mod b);; operation findReachable(arr : OclAny, D : OclAny, A : OclAny, B : OclAny, n : OclAny) pre: true post: true activity: var gcd_AB : OclAny := GCD(A, B); ; var count : int := 0; ; for i : Integer.subrange(0, n-1) do ( if ((arr[i+1] - D) mod gcd_AB = 0) then ( count := count + 1; ) else skip) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=list(map(int,input().split(" "))) result=0 c_need=N*2 if c_need>=M : result+=M//2 print(result) else : result+=(N+(M-c_need)//4) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var result : int := 0 ; var c_need : double := N * 2 ; if (c_need->compareTo(M)) >= 0 then ( result := result + M div 2 ; execute (result)->display() ) else ( result := result + (N + (M - c_need) div 4) ; execute (result)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def judgeSquareSum(c): a=0 ; while(a*a<=c): b=c-int(a*a); if(binary_search(0,b,b)): return 1 ; a+=1 ; return 0 ; def binary_search(s,e,n): if(s>e): return 0 ; mid=s+int((e-s)/2); if(int(mid*mid)==n): return 1 ; if(int(mid*mid)>n): return binary_search(s,mid-1,n); return binary_search(mid+1,e,n); c=17 ; if(judgeSquareSum(c)): print("true"); else : print("false"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; c := 17; ; if (judgeSquareSum(c)) then ( execute ("true")->display(); ) else ( execute ("false")->display(); ); operation judgeSquareSum(c : OclAny) pre: true post: true activity: var a : int := 0; ; while ((a * a->compareTo(c)) <= 0) do ( var b : double := c - ("" + ((a * a)))->toInteger(); ; if (binary_search(0, b, b)) then ( return 1; ) else skip ; a := a + 1;) ; return 0;; operation binary_search(s : OclAny, e : OclAny, n : OclAny) pre: true post: true activity: if ((s->compareTo(e)) > 0) then ( return 0; ) else skip ; var mid : OclAny := s + ("" + (((e - s) / 2)))->toInteger(); ; if (("" + ((mid * mid)))->toInteger() = n) then ( return 1; ) else skip ; if ((("" + ((mid * mid)))->toInteger()->compareTo(n)) > 0) then ( return binary_search(s, mid - 1, n); ) else skip ; return binary_search(mid + 1, e, n);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys class MagicalTiles(): def __init__(self,data): self.map=data[:] self.pos=(0,0) self.path=[(0,0)] self.mark=self.map[0][0] self.loop=False def move(self): x,y=self.pos[0],self.pos[1] self.mark=self.map[y][x] if self.mark=='>' : x+=1 elif self.mark=='<' : x-=1 elif self.mark=='^' : y-=1 elif self.mark=='v' : y+=1 if self.mark!='.' and(x,y)in self.path : self.loop=True else : self.path.append((x,y)) self.pos=(x,y) def main(args): while True : h,w=[int(x)for x in input().split(' ')] if h==0 and w==0 : break data=[input()for _ in range(h)] m=MagicalTiles(data) while m.mark!='.' : m.move() if m.loop : break if m.loop : print('LOOP') else : print(m.pos[0],m.pos[1]) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class MagicalTiles { static operation newMagicalTiles() : MagicalTiles pre: true post: MagicalTiles->exists( _x | result = _x ); attribute map : Sequence := data; attribute pos : OclAny := Sequence{0, 0}; attribute path : Sequence := Sequence{ Sequence{0, 0} }; attribute mark : OclAny := self.map->first()->first(); attribute loop : boolean := false; operation initialise(data : OclAny) : pre: true post: true activity: self.map := data ; self.pos := Sequence{0, 0} ; self.path := Sequence{ Sequence{0, 0} } ; self.mark := self.map->first()->first() ; self.loop := false; return self; operation move() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{self.pos->first(),self.pos[1+1]} ; self.mark := self.map[y+1][x+1] ; if self.mark = '>' then ( x := x + 1 ) else (if self.mark = '<' then ( x := x - 1 ) else (if self.mark = '^' then ( y := y - 1 ) else (if self.mark = 'v' then ( y := y + 1 ) else skip ) ) ) ; if self.mark /= '.' & (self.path)->includes(Sequence{x, y}) then ( self.loop := true ) else ( (expr (atom (name self)) (trailer . (name path)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name x)))))) , (test (logical_test (comparison (expr (atom (name y))))))) )))))))) )))) ) ; self.pos := Sequence{x, y}; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation main(args : OclAny) pre: true post: true activity: while true do ( var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if h = 0 & w = 0 then ( break ) else skip ; data := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var m : MagicalTiles := (MagicalTiles.newMagicalTiles()).initialise(data) ; while m.mark /= '.' do ( m.move() ; if m.loop then ( break ) else skip) ; if m.loop then ( execute ('LOOP')->display() ) else ( execute (m.pos->first())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- STATE={"NOTHING" : ".","LOOP" : "E"} DIRECT={">" :[0,1],"<" :[0,-1],"^" :[-1,0],"v" :[1,0]} output=[] while True : width,height=[int(item)for item in input().split(" ")] if width==0 and height==0 : break tiles=[] for lp in range(width): splits=[item for item in input()] tiles.append(splits) row,col=0,0 while True : if tiles[row][col]==STATE["NOTHING"]: output.append(str(col)+" "+str(row)) break elif tiles[row][col]==STATE["LOOP"]: output.append("LOOP") break for key in DIRECT : if tiles[row][col]==key : tiles[row][col]=STATE["LOOP"] row+=DIRECT[key][0] col+=DIRECT[key][1] break print("\n".join(output)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var STATE : Map := Map{ "NOTHING" |-> "." }->union(Map{ "LOOP" |-> "E" }) ; var DIRECT : Map := Map{ ">" |-> Sequence{0}->union(Sequence{ 1 }) }->union(Map{ "<" |-> Sequence{0}->union(Sequence{ -1 }) }->union(Map{ "^" |-> Sequence{-1}->union(Sequence{ 0 }) }->union(Map{ "v" |-> Sequence{1}->union(Sequence{ 0 }) }))) ; var output : Sequence := Sequence{} ; while true do ( var width : OclAny := null; var height : OclAny := null; Sequence{width,height} := input().split(" ")->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; if width = 0 & height = 0 then ( break ) else skip ; var tiles : Sequence := Sequence{} ; for lp : Integer.subrange(0, width-1) do ( var splits : Sequence := (OclFile["System.in"]).readLine()->select(item | true)->collect(item | (item)) ; execute ((splits) : tiles)) ; var row : OclAny := null; var col : OclAny := null; Sequence{row,col} := Sequence{0,0} ; while true do ( if tiles[row+1][col+1] = STATE->at("NOTHING") then ( execute ((("" + ((col))) + " " + ("" + ((row)))) : output) ; break ) else (if tiles[row+1][col+1] = STATE->at("LOOP") then ( execute (("LOOP") : output) ; break ) else skip) ; for key : DIRECT->keys() do ( if tiles[row+1][col+1] = key then ( tiles[row+1][col+1] := STATE->at("LOOP") ; row := row + DIRECT[key+1]->first() ; col := col + DIRECT[key+1][1+1] ; break ) else skip))) ; execute (StringLib.sumStringsWithSeparator((output), "\n"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy BIG_NUM=2000000000 HUGE_NUM=99999999999999999 MOD=1000000007 EPS=0.000000001 sys.setrecursionlimit(100000) North=0 East=1 South=2 West=3 DICT={"^" : North,">" : East,"v" : South,"<" : West} while True : H,W=map(int,input().split()) if H==0 and W==0 : break base_map=[input()for _ in range(H)] check=[[False]*W for row in range(H)] row=0 col=0 while True : if base_map[row][col]=='.' : print("%d %d" %(col,row)) break else : if check[row][col]==True : print("LOOP") break check[row][col]=True tmp_dir=DICT[base_map[row][col]] if tmp_dir==North : row-=1 elif tmp_dir==East : col+=1 elif tmp_dir==South : row+=1 else : col-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var HUGE_NUM : int := 99999999999999999 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; sys.setrecursionlimit(100000) ; var North : int := 0 ; var East : int := 1 ; var South : int := 2 ; var West : int := 3 ; var DICT : Map := Map{ "^" |-> North }->union(Map{ ">" |-> East }->union(Map{ "v" |-> South }->union(Map{ "<" |-> West }))) ; while true do ( var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if H = 0 & W = 0 then ( break ) else skip ; var base_map : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var check : Sequence := Integer.subrange(0, H-1)->select(row | true)->collect(row | (MatrixLib.elementwiseMult(Sequence{ false }, W))) ; var row : int := 0 ; var col : int := 0 ; while true do ( if base_map[row+1][col+1] = '.' then ( execute (StringLib.format("%d %d",Sequence{col, row}))->display() ; break ) else ( if check[row+1][col+1] = true then ( execute ("LOOP")->display() ; break ) else skip ; check[row+1][col+1] := true ; var tmp_dir : OclAny := DICT[base_map[row+1][col+1]+1] ; if tmp_dir = North then ( row := row - 1 ) else (if tmp_dir = East then ( col := col + 1 ) else (if tmp_dir = South then ( row := row + 1 ) else ( col := col - 1 ) ) ) ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for a in iter(input,'0 0'): m=[input()for _ in[0]*int(a.split()[0])] y=x=0 ; s={(0,0)} while 1 : c=m[y][x] if '>'==c : x+=1 ; if 'v'==c : y+=1 ; if '<'==c : x-=1 ; if '^'==c : y-=1 ; if '.'==c : print(x,y); break if(x,y)in s : print('LOOP'); break else : s |={(x,y)} ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for a : OclIterator.newOclIterator_Sequence(input, '0 0') do ( var m : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + ((a.split()->first())))->toInteger())->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var y : OclAny := 0; var x : int := 0; var s : Set := Set{ Sequence{0, 0} } ; while 1 do ( var c : OclAny := m[y+1][x+1] ; if '>' = c then ( x := x + 1; ) else skip ; if 'v' = c then ( y := y + 1; ) else skip ; if '<' = c then ( x := x - 1; ) else skip ; if '^' = c then ( y := y - 1; ) else skip ; if '.' = c then ( execute (x)->display(); break ) else skip ; if (s)->includes(Sequence{x, y}) then ( execute ('LOOP')->display(); break ) else ( s := s or Set{ Sequence{x, y} } ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def run_magic_tiles(magic_tiles,past_matrix): def move_up(x,y): return x-1,y def move_down(x,y): return x+1,y def move_left(x,y): return x,y-1 def move_right(x,y): return x,y+1 def goal(): return-1,-1 i,j=0,0 while True : res={'^' : move_up(i,j),'v' : move_down(i,j),'<' : move_left(i,j),'>' : move_right(i,j),'.' : goal()}.get(magic_tiles[i][j]) if res[0]==-1 and res[1]==-1 : return j,i else : i,j=res if past_matrix[i][j]: return 'LOOP' past_matrix[i][j]=1 def main(): while True : c,r=map(int,input().split(' ')) if c==0 and r==0 : break past_matrix=[[0 for _ in range(r)]for _ in range(c)] tiles=[] for _ in range(c): tiles.append(list(input())) res=run_magic_tiles(tiles,past_matrix) print('LOOP' if res=='LOOP' else '%d %d' %(res[0],res[1])) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation run_magic_tiles(magic_tiles : OclAny, past_matrix : OclAny) : OclAny pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,0} ; while true do ( var res : OclAny := Map{ '^' |-> move_up(i, j) }->union(Map{ 'v' |-> move_down(i, j) }->union(Map{ '<' |-> move_left(i, j) }->union(Map{ '>' |-> move_right(i, j) }->union(Map{ '.' |-> goal() })))).get(magic_tiles[i+1][j+1]) ; if res->first() = -1 & res[1+1] = -1 then ( return j, i ) else ( var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := res ; if past_matrix[i+1][j+1] then ( return 'LOOP' ) else skip ; past_matrix[i+1][j+1] := 1 )); operation main() pre: true post: true activity: while true do ( var c : OclAny := null; var r : OclAny := null; Sequence{c,r} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; if c = 0 & r = 0 then ( break ) else skip ; past_matrix := Integer.subrange(0, c-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, r-1)->select(_anon | true)->collect(_anon | (0)))) ; var tiles : Sequence := Sequence{} ; for _anon : Integer.subrange(0, c-1) do ( execute ((((OclFile["System.in"]).readLine())->characters()) : tiles)) ; res := run_magic_tiles(tiles, past_matrix) ; execute (if res = 'LOOP' then 'LOOP' else StringLib.format('%d %d',Sequence{res->first(), res[1+1]}) endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys d={} input() for e in sys.stdin : c,g=e.split() if 'i'==c[0]: d[g]=0 else : print(['no','yes'][g in d]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var d : OclAny := Set{} ; input() ; for e : OclFile["System.in"] do ( var c : OclAny := null; var g : OclAny := null; Sequence{c,g} := e.split() ; if 'i' = c->first() then ( d[g+1] := 0 ) else ( execute (Sequence{'no'}->union(Sequence{ 'yes' })->select((d)->includes(g)))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import Counter read=sys.stdin.read def min_factor(n): sieve=list(range(n+1)) sieve[2 : : 2]=[2]*(n//2) for i in range(3,int(n**0.5)+2,2): if sieve[i]==i : sieve[i*i : : 2*i]=[i]*((n-i*i-1)//(2*i)+1) return sieve def prime_factorize(n): a=[] while n!=1 : a.append(table[n]) n//=table[n] return a N,*A=map(int,read().split()) mod=10**9+7 table=min_factor(10**6) dic={} for i in A : if i==1 : continue tmp=Counter(prime_factorize(i)) for key,value in tmp.items(): if dic.get(key): if dic[key]collect( _x | (OclType["int"])->apply(_x) ) ; var mod : double := (10)->pow(9) + 7 ; var table : OclAny := min_factor((10)->pow(6)) ; var dic : OclAny := Set{} ; for i : A do ( if i = 1 then ( continue ) else skip ; var tmp : OclAny := Counter(prime_factorize(i)) ; for _tuple : tmp->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); if dic.get(key) then ( if (dic[key+1]->compareTo(value)) < 0 then ( dic[key+1] := value ) else skip ) else ( dic[key+1] := value ))) ; var lcm : int := 1 ; for _tuple : dic->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if j = 0 then ( continue ) else skip ; lcm := lcm * (i)->pow(j) ; lcm := lcm mod mod) ; var answer : int := 0 ; for i : A do ( answer := answer + lcm * (i)->pow(mod - 2) ; answer := answer mod mod) ; execute (answer)->display(); operation min_factor(n : OclAny) : OclAny pre: true post: true activity: var sieve : Sequence := (Integer.subrange(0, n + 1-1)) ; sieve(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) := MatrixLib.elementwiseMult(Sequence{ 2 }, (n div 2)) ; for i : Integer.subrange(3, ("" + (((n)->pow(0.5))))->toInteger() + 2-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if sieve[i+1] = i then ( sieve(subscript (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom (name i))))))) : (sliceop : (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name i))))))))) := MatrixLib.elementwiseMult(Sequence{ i }, ((n - i * i - 1) div (2 * i) + 1)) ) else skip) ; return sieve; operation prime_factorize(n : OclAny) : OclAny pre: true post: true activity: var a : Sequence := Sequence{} ; while n /= 1 do ( execute ((table[n+1]) : a) ; n := n div table[n+1]) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) h_num=10000 L=[[]for x in range(h_num)] def string_to_hash(S): S_num=0 i=0 for s in S : i+=1 if s=='A' : S_num+=1*i elif s=='C' : S_num+=10*i elif s=='G' : S_num+=100*i elif s=='T' : S_num+=1000*i return(S_num % h_num) for n in range(N): cmd,str_=input().split() h=string_to_hash(str_) if cmd=='insert' : L[h].append(str_) elif cmd=='find' : L_temp=L[h] if str_ in L_temp : print('yes') else : print('no') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var h_num : int := 10000 ; var L : Sequence := Integer.subrange(0, h_num-1)->select(x | true)->collect(x | (Sequence{})) ; skip ; for n : Integer.subrange(0, N-1) do ( var cmd : OclAny := null; var str_ : OclAny := null; Sequence{cmd,str_} := input().split() ; var h : OclAny := string_to_hash(str_) ; if cmd = 'insert' then ( (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name h)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str_)))))))) )))) ) else (if cmd = 'find' then ( var L_temp : OclAny := L[h+1] ; if (L_temp)->includes(str_) then ( execute ('yes')->display() ) else ( execute ('no')->display() ) ) else skip)); operation string_to_hash(S : OclAny) : OclAny pre: true post: true activity: var S_num : int := 0 ; var i : int := 0 ; for s : S do ( i := i + 1 ; if s = 'A' then ( S_num := S_num + 1 * i ) else (if s = 'C' then ( S_num := S_num + 10 * i ) else (if s = 'G' then ( S_num := S_num + 100 * i ) else (if s = 'T' then ( S_num := S_num + 1000 * i ) else skip ) ) ) ) ; return (S_num mod h_num); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def h1(key): return key % m def h2(key): return 1+(key %(m-1)) def h(key,i): return(h1(key)+i*h2(key))% m def insert(key): i=0 while True : j=h(key,i) if T[j]=='NULL' : T[j]=key return j else : i+=1 def search(key): i=0 while True : j=h(key,i) if T[j]==key : print('yes') return j elif T[j]=='NULL' or i>=m : print('no') return 'NULL' else : i+=1 def str_to_key(_str): _length=len(_str) _sum,p=0,1 for i in range(_length): _sum+=p*(ord(_str[i])-64) p*=5 return _sum def action(command,content): key=str_to_key(content) if command[0]=='i' : insert(key=key) elif command[0]=='f' : search(key=key) return None if __name__=='__main__' : _input=sys.stdin.readlines() m=1046527 length=int(_input[0]) command_list=list(map(lambda x : x.split(),_input[1 :])) T=['NULL' for _ in range(m)] for command,content in command_list : action(command=command,content=content) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var _input : OclAny := (OclFile["System.in"]).readlines() ; var m : int := 1046527 ; var length : int := ("" + ((_input->first())))->toInteger() ; var command_list : Sequence := ((_input->tail())->collect( _x | (lambda x : OclAny in (x.split()))->apply(_x) )) ; var T : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | ('NULL')) ; for _tuple : command_list do (var _indx : int := 1; var command : OclAny := _tuple->at(_indx); _indx := _indx + 1; var content : OclAny := _tuple->at(_indx); action((argument (test (logical_test (comparison (expr (atom (name command)))))) = (test (logical_test (comparison (expr (atom (name command))))))), (argument (test (logical_test (comparison (expr (atom (name content)))))) = (test (logical_test (comparison (expr (atom (name content))))))))) ) else skip; operation h1(key : OclAny) : OclAny pre: true post: true activity: return key mod m; operation h2(key : OclAny) : OclAny pre: true post: true activity: return 1 + (key mod (m - 1)); operation h(key : OclAny, i : OclAny) : OclAny pre: true post: true activity: return (h1(key) + i * h2(key)) mod m; operation insert(key : OclAny) : OclAny pre: true post: true activity: i := 0 ; while true do ( var j : OclAny := h(key, i) ; if T[j+1] = 'NULL' then ( T[j+1] := key ; return j ) else ( i := i + 1 )); operation search(key : OclAny) : OclAny pre: true post: true activity: i := 0 ; while true do ( j := h(key, i) ; if T[j+1] = key then ( execute ('yes')->display() ; return j ) else (if T[j+1] = 'NULL' or (i->compareTo(m)) >= 0 then ( execute ('no')->display() ; return 'NULL' ) else ( i := i + 1 ) ) ); operation str_to_key(_str : OclAny) : OclAny pre: true post: true activity: var _length : int := (_str)->size() ; var _sum : OclAny := null; var p : OclAny := null; Sequence{_sum,p} := Sequence{0,1} ; for i : Integer.subrange(0, _length-1) do ( _sum := _sum + p * ((_str[i+1])->char2byte() - 64) ; p := p * 5) ; return _sum; operation action(command : OclAny, content : OclAny) : OclAny pre: true post: true activity: key := str_to_key(content) ; if command->first() = 'i' then ( insert((argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name key)))))))) ) else (if command->first() = 'f' then ( search((argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name key)))))))) ) else skip) ; return null; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def readinput(): n=int(input()) commands=[] for i in range(n): command=input().split() commands.append(command) return n,commands def main(n,commands): d=dict() for cmd in commands : if(cmd[0]=='insert'): d[cmd[1]]=cmd[1] elif(cmd[0]=='find'): if(cmd[1]in d): print('yes') else : print('no') if __name__=='__main__' : n,commands=readinput() main(n,commands) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( Sequence{n,commands} := readinput() ; main(n, commands) ) else skip; operation readinput() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var commands : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var command : OclAny := input().split() ; execute ((command) : commands)) ; return n, commands; operation main(n : OclAny, commands : OclAny) pre: true post: true activity: var d : Map := (arguments ( )) ; for cmd : commands do ( if (cmd->first() = 'insert') then ( d[cmd[1+1]+1] := cmd[1+1] ) else (if (cmd->first() = 'find') then ( if ((d)->includes(cmd[1+1])) then ( execute ('yes')->display() ) else ( execute ('no')->display() ) ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def scc_puzzle(N : int,M : int)->int : if 2*Ncollect( _x | (OclType["int"])->apply(_x) ) ; var ans : OclAny := scc_puzzle(N, M) ; execute (ans)->display() ) else skip; operation scc_puzzle(N : int, M : int) : int pre: true post: true activity: if (2 * N->compareTo(M)) < 0 then ( return N + (M - 2 * N) div 4 ) else skip ; return M div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class c : def __init__(self): self.d={} def insert(self,s): self.d[s]=1 def find(self,s): try : if self.d[s]: print('yes') except KeyError : print('no') n=int(input()) d=c() for i in range(n): s,k=input().split() if s=='insert' : d.insert(k) else : d.find(k) ------------------------------------------------------------ OCL File: --------- class c { static operation newc() : c pre: true post: c->exists( _x | result = _x ); attribute d : OclAny := Set{}; operation initialise() : c pre: true post: true activity: self.d := Set{}; return self; operation insert(s : OclAny) pre: true post: true activity: self.d[s+1] := 1; operation find(s : OclAny) pre: true post: true activity: try ( if self.d[s+1] then ( execute ('yes')->display() ) else skip) (except_clause except (test (logical_test (comparison (expr (atom (name KeyError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'no'))))))) )))))))))))))); } class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : c := (c.newc()).initialise() ; for i : Integer.subrange(0, n-1) do ( var k : OclAny := null; Sequence{s,k} := input().split() ; if s = 'insert' then ( d := d.insertAt(k+1, k) ) else ( d->indexOf(k) - 1 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def subset(ar,n): res=0 ar.sort() for i in range(0,n): count=1 for i in range(n-1): if ar[i]==ar[i+1]: count+=1 else : break res=max(res,count) return res ar=[5,6,9,3,4,3,4] n=len(ar) print(subset(ar,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; ar := Sequence{5}->union(Sequence{6}->union(Sequence{9}->union(Sequence{3}->union(Sequence{4}->union(Sequence{3}->union(Sequence{ 4 })))))) ; n := (ar)->size() ; execute (subset(ar, n))->display(); operation subset(ar : OclAny, n : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; ar := ar->sort() ; for i : Integer.subrange(0, n-1) do ( var count : int := 1 ; for i : Integer.subrange(0, n - 1-1) do ( if ar[i+1] = ar[i + 1+1] then ( count := count + 1 ) else ( break )) ; res := Set{res, count}->max()) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k,c=map(int,input().split()) s=input() fastest_schedule=[None for i in range(n)] latest_schedule=[None for i in range(n)] count=1 last_workday=-10**10 for i in range(n): if s[i]=='o' and i-last_workday>c : fastest_schedule[i]=count last_workday=i if countc : latest_schedule[i]=count last_workday=i if count>1 : count-=1 else : break for i in range(n): if fastest_schedule[i]==latest_schedule[i]and fastest_schedule[i]!=None : print(i+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var c : OclAny := null; Sequence{n,k,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var fastest_schedule : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; var latest_schedule : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; var count : int := 1 ; var last_workday : double := (-10)->pow(10) ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = 'o' & (i - last_workday->compareTo(c)) > 0 then ( fastest_schedule[i+1] := count ; last_workday := i ; if (count->compareTo(k)) < 0 then ( count := count + 1 ) else ( break ) ) else skip) ; count := k ; last_workday := (10)->pow(18) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if s[i+1] = 'o' & (last_workday - i->compareTo(c)) > 0 then ( latest_schedule[i+1] := count ; last_workday := i ; if count > 1 then ( count := count - 1 ) else ( break ) ) else skip) ; for i : Integer.subrange(0, n-1) do ( if fastest_schedule[i+1] = latest_schedule[i+1] & fastest_schedule[i+1] /= null then ( execute (i + 1)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.buffer.readline def RD(): return sys.stdin.read() def II(): return int(input()) def MI(): return map(int,input().split()) def MF(): return map(float,input().split()) def LI(): return list(map(int,input().split())) def LF(): return list(map(float,input().split())) def TI(): return tuple(map(int,input().split())) def main(): n,k,c=MI() s=input().rstrip().decode() kk=k i=0 L=[] while kk : if s[i]=="o" : L.append(i+1) i+=c+1 kk-=1 else : i+=1 kk=k i=n-1 R=[] while kk : if s[i]=="o" : R.append(i+1) i-=c+1 kk-=1 else : i-=1 R.sort() for i,j in zip(L,R): if i==j : print(i) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := sys.stdin.buffer.readline ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation RD() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readAll(); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation MF() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["double"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LF() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["double"])->apply(_x) )); operation TI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation main() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var c : OclAny := null; Sequence{n,k,c} := MI() ; var s : OclAny := input().rstrip().decode() ; var kk : OclAny := k ; var i : int := 0 ; var L : Sequence := Sequence{} ; while kk do ( if s[i+1] = "o" then ( execute ((i + 1) : L) ; i := i + c + 1 ; kk := kk - 1 ) else ( i := i + 1 )) ; kk := k ; i := n - 1 ; var R : Sequence := Sequence{} ; while kk do ( if s[i+1] = "o" then ( execute ((i + 1) : R) ; i := i - c + 1 ; kk := kk - 1 ) else ( i := i - 1 )) ; R := R->sort() ; for _tuple : Integer.subrange(1, L->size())->collect( _indx | Sequence{L->at(_indx), R->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if i = j then ( execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect n,k,c=map(int,input().split()) s=input() a=[] for i in range(n): if s[i]=='o' : a.append(i+1) m=len(a) l=[0 for _ in range(m)] r=[0 for _ in range(m)] cur=0 l[0]=a[0] while True : to=bisect.bisect_left(a,a[cur]+c+1) if to==m : break l[to]=l[cur]+1 cur=to for i in range(m-1): if l[i]>l[i+1]: l[i+1]=l[i] r[m-1]=1 cur=m-1 while True : to=bisect.bisect_left(a,a[cur]-c)-1 if to==-1 : break r[to]=r[cur]+1 cur=to for i in range(m-1): x=m-2-i if r[x]collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = 'o' then ( execute ((i + 1) : a) ) else skip) ; var m : int := (a)->size() ; var l : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (0)) ; var r : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (0)) ; var cur : int := 0 ; l->first() := a->first() ; while true do ( var to : OclAny := bisect.bisect_left(a, a[cur+1] + c + 1) ; if to = m then ( break ) else skip ; l[to+1] := l[cur+1] + 1 ; cur := to) ; for i : Integer.subrange(0, m - 1-1) do ( if (l[i+1]->compareTo(l[i + 1+1])) > 0 then ( l[i + 1+1] := l[i+1] ) else skip) ; r[m - 1+1] := 1 ; cur := m - 1 ; while true do ( to := bisect.bisect_left(a, a[cur+1] - c) - 1 ; if to = -1 then ( break ) else skip ; r[to+1] := r[cur+1] + 1 ; cur := to) ; for i : Integer.subrange(0, m - 1-1) do ( var x : double := m - 2 - i ; if (r[x+1]->compareTo(r[x + 1+1])) < 0 then ( r[x+1] := r[x + 1+1] ) else skip) ; l := Sequence{ 0 }->union(l) ; r := Sequence{ r->first() }->union(r)->union(Sequence{ 0 }) ; for i : Integer.subrange(1, m + 1-1) do ( if (l[i - 1+1] + r[i + 1+1]->compareTo(k)) < 0 then ( execute (a[i - 1+1])->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 def input(): return sys.stdin.readline().rstrip() def main(): N,K,C=map(int,input().split()) S=list(map(int,input().replace('o','1').replace('x','0'))) T=[0]*(N+1) l0=[] l1=[] r0=-INF r1=-INF for i in range(N): if len(l0)r0 and S[i]==1 : l0.append(i) r0=i+C if len(l1)r1 and S[N-1-i]==1 : l1.append(N-1-i) r1=i+C l1.reverse() ans=[] for i in range(K): if l0[i]==l1[i]: ans.append(l0[i]) ans.sort() for x in ans : print(x+1) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation main() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; var C : OclAny := null; Sequence{N,K,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : Sequence := ((input().replace('o', '1').replace('x', '0'))->collect( _x | (OclType["int"])->apply(_x) )) ; var T : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; var l0 : Sequence := Sequence{} ; var l1 : Sequence := Sequence{} ; var r0 : OclAny := -INF ; var r1 : OclAny := -INF ; for i : Integer.subrange(0, N-1) do ( if ((l0)->size()->compareTo(K)) < 0 & (i->compareTo(r0)) > 0 & S[i+1] = 1 then ( execute ((i) : l0) ; r0 := i + C ) else skip ; if ((l1)->size()->compareTo(K)) < 0 & (i->compareTo(r1)) > 0 & S[N - 1 - i+1] = 1 then ( execute ((N - 1 - i) : l1) ; r1 := i + C ) else skip) ; l1 := l1->reverse() ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, K-1) do ( if l0[i+1] = l1[i+1] then ( execute ((l0[i+1]) : ans) ) else skip) ; ans := ans->sort() ; for x : ans do ( execute (x + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r=[list(map(int,input().split()))for _ in range(4)] pre=0 if r[0][3]and(r[0][0]or r[0][1]or r[0][2]or r[1][0]or r[2][1]or r[3][2]): pre=1 if r[1][3]and(r[1][0]or r[1][1]or r[1][2]or r[2][0]or r[3][1]or r[0][2]): pre=1 if r[2][3]and(r[2][0]or r[2][1]or r[2][2]or r[3][0]or r[0][1]or r[1][2]): pre=1 if r[3][3]and(r[3][0]or r[3][1]or r[3][2]or r[0][0]or r[1][1]or r[2][2]): pre=1 if pre : print("YES") else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : Sequence := Integer.subrange(0, 4-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var pre : int := 0 ; if r->first()[3+1] & (r->first()->first() or r->first()[1+1] or r->first()[2+1] or r[1+1]->first() or r[2+1][1+1] or r[3+1][2+1]) then ( pre := 1 ) else skip ; if r[1+1][3+1] & (r[1+1]->first() or r[1+1][1+1] or r[1+1][2+1] or r[2+1]->first() or r[3+1][1+1] or r->first()[2+1]) then ( pre := 1 ) else skip ; if r[2+1][3+1] & (r[2+1]->first() or r[2+1][1+1] or r[2+1][2+1] or r[3+1]->first() or r->first()[1+1] or r[1+1][2+1]) then ( pre := 1 ) else skip ; if r[3+1][3+1] & (r[3+1]->first() or r[3+1][1+1] or r[3+1][2+1] or r->first()->first() or r[1+1][1+1] or r[2+1][2+1]) then ( pre := 1 ) else skip ; if pre then ( execute ("YES")->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k,c=map(int,input().split()) c+=1 a=input() b=a[: :-1] form=[0] lat=[0] for i in range(n): if a[i]=='x' : form.append(form[-1]) else : try : form.append(max(form[-c]+1,form[-1])) except : form.append(1) if b[i]=='x' : lat.append(lat[-1]) else : try : lat.append(max(lat[-c]+1,lat[-1])) except : lat.append(1) form.append(form[-1]) lat.append(lat[-1]) lat.reverse() for i in range(n): if form[i]+lat[i+2]==k-1 : print(i+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var c : OclAny := null; Sequence{n,k,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; c := c + 1 ; var a : String := (OclFile["System.in"]).readLine() ; var b : OclAny := a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var form : Sequence := Sequence{ 0 } ; var lat : Sequence := Sequence{ 0 } ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = 'x' then ( execute ((form->last()) : form) ) else ( try ( execute ((Set{form->reverse()->at(-(-c)) + 1, form->last()}->max()) : form)) catch (_e : OclException) do ( execute ((1) : form)) ) ; if b[i+1] = 'x' then ( execute ((lat->last()) : lat) ) else ( try ( execute ((Set{lat->reverse()->at(-(-c)) + 1, lat->last()}->max()) : lat)) catch (_e : OclException) do ( execute ((1) : lat)) )) ; execute ((form->last()) : form) ; execute ((lat->last()) : lat) ; lat := lat->reverse() ; for i : Integer.subrange(0, n-1) do ( if form[i+1] + lat[i + 2+1] = k - 1 then ( execute (i + 1)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=int(input()) count=0 i=1 while True : if nm : m=m+1 count=count+i if m==n : break else : n=n-1 count=count+i if n==m : break i=i+1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := 0 ; var i : int := 1 ; while true do ( if (n->compareTo(m)) < 0 then ( n := n + 1 ; count := count + i ; if n = m then ( break ) else ( m := m - 1 ; count := count + i ) ) else skip ; if (n->compareTo(m)) > 0 then ( m := m + 1 ; count := count + i ; if m = n then ( break ) else ( n := n - 1 ; count := count + i ) ) else skip ; if n = m then ( break ) else skip ; i := i + 1) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) def tiredness(point_one,point_two): difference=abs(point_one-point_two) steps_for_each=int(difference/2) result=steps_for_each*(steps_for_each+1) if(difference % 2!=0): result+=(steps_for_each+1) return result print(tiredness(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; execute (tiredness(a, b))->display(); operation tiredness(point_one : OclAny, point_two : OclAny) : OclAny pre: true post: true activity: var difference : double := (point_one - point_two)->abs() ; var steps_for_each : int := ("" + ((difference / 2)))->toInteger() ; var result : int := steps_for_each * (steps_for_each + 1) ; if (difference mod 2 /= 0) then ( result := result + (steps_for_each + 1) ) else skip ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math x=int(input()) y=int(input()) t=abs(x-y) if(t % 2==0): m=math.floor(t/2) print(m*(m+1)) else : p=t//2 q=p*(p+1) print(q+(p+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var y : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : double := (x - y)->abs() ; if (t mod 2 = 0) then ( var m : double := (t / 2)->floor() ; execute (m * (m + 1))->display() ) else ( var p : int := t div 2 ; var q : int := p * (p + 1) ; execute (q + (p + 1))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) restC=m-n*2 print(n+restC//4 if restC>=0 else m//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var restC : double := m - n * 2 ; execute (if restC >= 0 then n + restC div 4 else m div 2 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) n=max(b-a,a-b) m=n//2 liststep=[] for i in range(1,n): liststep.append(i) if n==1 : tired=1 elif n % 2==0 : tired=m*(m+1) elif n % 2!=0 : tired=m*(m+1)+liststep[m] print(tired) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : OclAny := Set{b - a, a - b}->max() ; var m : int := n div 2 ; var liststep : Sequence := Sequence{} ; for i : Integer.subrange(1, n-1) do ( execute ((i) : liststep)) ; if n = 1 then ( var tired : int := 1 ) else (if n mod 2 = 0 then ( tired := m * (m + 1) ) else (if n mod 2 /= 0 then ( tired := m * (m + 1) + liststep[m+1] ) else skip ) ) ; execute (tired)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) d=abs(b-a) n1=d//2 n2=d-n1 sum1=(n1*(n1+1))//2 sum2=(n2*(n2+1))//2 print((sum1+sum2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : double := (b - a)->abs() ; var n1 : int := d div 2 ; var n2 : double := d - n1 ; var sum1 : int := (n1 * (n1 + 1)) div 2 ; var sum2 : int := (n2 * (n2 + 1)) div 2 ; execute ((sum1 + sum2))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def K_multiple(a,n,k): a.sort(); s=set(); for i in range(n): if((a[i]% k==0 and a[i]//k not in s)or a[i]% k!=0): s.add(a[i]); for i in s : print(i,end=" ") if __name__=="__main__" : a=[2,3,4,5,6,10]; k=2 ; n=len(a); K_multiple(a,n,k); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 10 }))))); ; k := 2; ; n := (a)->size(); ; K_multiple(a, n, k); ) else skip; operation K_multiple(a : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: a := a->sort(); ; var s : Set := Set{}->union(()); ; for i : Integer.subrange(0, n-1) do ( if ((a[i+1] mod k = 0 & (s)->excludes(a[i+1] div k)) or a[i+1] mod k /= 0) then ( execute ((a[i+1]) : s); ) else skip) ; for i : s do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math class Node : def __init__(self,data): self.data=data self.next=None def reversePrint(head_ref): tail=head_ref while(tail.next!=None): tail=tail.next while(tail!=head_ref): print(tail.data,end=" ") tail=tail.prev print(tail.data) def push(head_ref,new_data): new_node=Node(new_data) new_node.data=new_data new_node.prev=None new_node.next=head_ref if(head_ref!=None): head_ref.prev=new_node head_ref=new_node return head_ref if __name__=='__main__' : head=None head=push(head,2) head=push(head,4) head=push(head,8) head=push(head,10) print("Linked List elements in reverse order : ") reversePrint(head) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.next := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var head : OclAny := null ; head := push(head, 2) ; head := push(head, 4) ; head := push(head, 8) ; head := push(head, 10) ; execute ("Linked List elements in reverse order : ")->display() ; reversePrint(head) ) else skip; operation reversePrint(head_ref : OclAny) pre: true post: true activity: var tail : OclAny := head_ref ; while (tail.next /= null) do ( tail := tail.next) ; while (tail /= head_ref) do ( execute (tail.data)->display() ; tail := tail.prev) ; execute (tail.data)->display(); operation push(head_ref : OclAny, new_data : OclAny) : OclAny pre: true post: true activity: var new_node : Node := (Node.newNode()).initialise(new_data) ; new_node.data := new_data ; new_node.prev := null ; new_node.next := head_ref ; if (head_ref /= null) then ( head_ref.prev := new_node ) else skip ; head_ref := new_node ; return head_ref; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) from collections import Counter b=[] c=[] for i in range(n): b.append(i+1+a[i]) c.append(i+1-a[i]) b=Counter(b) c=Counter(c) ans=0 for i,v in b.items(): ans+=v*c[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; var b : Sequence := Sequence{} ; var c : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((i + 1 + a[i+1]) : b) ; execute ((i + 1 - a[i+1]) : c)) ; b := Counter(b) ; c := Counter(c) ; var ans : int := 0 ; for _tuple : b->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); ans := ans + v * c[i+1]) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline g=[list(map(int,input().split()))for _ in range(4)] c=0 if g[0][3]==1 : for i in[g[3][2],g[2][1],g[1][0]]: if i==1 : c=1 if g[1][3]==1 : for i in[g[3][1],g[2][0],g[0][2]]: if i==1 : c=1 if g[2][3]==1 : for i in[g[3][0],g[1][2],g[0][1]]: if i==1 : c=1 if g[3][3]==1 : for i in[g[2][2],g[1][1],g[0][0]]: if i==1 : c=1 for i in g : if sum(i)>1 and i[3]==1 : c=1 print("YES" if c==1 else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var g : Sequence := Integer.subrange(0, 4-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var c : int := 0 ; if g->first()[3+1] = 1 then ( for i : Sequence{g[3+1][2+1]}->union(Sequence{g[2+1][1+1]}->union(Sequence{ g[1+1]->first() })) do ( if i = 1 then ( c := 1 ) else skip) ) else skip ; if g[1+1][3+1] = 1 then ( for i : Sequence{g[3+1][1+1]}->union(Sequence{g[2+1]->first()}->union(Sequence{ g->first()[2+1] })) do ( if i = 1 then ( c := 1 ) else skip) ) else skip ; if g[2+1][3+1] = 1 then ( for i : Sequence{g[3+1]->first()}->union(Sequence{g[1+1][2+1]}->union(Sequence{ g->first()[1+1] })) do ( if i = 1 then ( c := 1 ) else skip) ) else skip ; if g[3+1][3+1] = 1 then ( for i : Sequence{g[2+1][2+1]}->union(Sequence{g[1+1][1+1]}->union(Sequence{ g->first()->first() })) do ( if i = 1 then ( c := 1 ) else skip) ) else skip ; for i : g do ( if (i)->sum() > 1 & i[3+1] = 1 then ( c := 1 ) else skip) ; execute (if c = 1 then "YES" else 'NO' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline sys.setrecursionlimit(10**7) n=int(input()) a=list(map(int,input().split())) m1=dict() for i,v in enumerate(a): t=(i+1)+v if t not in m1 : m1[t]=set() m1[t].add(i+1) m2=dict() for i,v in enumerate(a): t=(i+1)-v if t<=1 : continue if t not in m1 : continue if t not in m2 : m2[t]=set() m2[t].add(i+1) ans=0 for k in m2 : ans+=len(m1[k])*len(m2[k]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit((10)->pow(7)) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m1 : Map := (arguments ( )) ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); var t : OclAny := (i + 1) + v ; if (m1)->excludes(t) then ( m1[t+1] := Set{}->union(()) ) else skip ; (expr (atom (name m1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ))))) ; var m2 : Map := (arguments ( )) ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); t := (i + 1) - v ; if t <= 1 then ( continue ) else skip ; if (m1)->excludes(t) then ( continue ) else skip ; if (m2)->excludes(t) then ( m2[t+1] := Set{}->union(()) ) else skip ; (expr (atom (name m2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ))))) ; var ans : int := 0 ; for k : m2->keys() do ( ans := ans + (m1[k+1])->size() * (m2[k+1])->size()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections N=int(input()) A=list(map(int,input().split())) plus=[0]*N minus=[0]*N for i in range(N): plus[i]=i+1+A[i] minus[i]=i+1-A[i] plus=dict(collections.Counter(plus)) minus=dict(collections.Counter(minus)) ans=0 for i in plus.keys(): if i in minus : ans+=plus[i]*minus[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var plus : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var minus : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for i : Integer.subrange(0, N-1) do ( plus[i+1] := i + 1 + A[i+1] ; minus[i+1] := i + 1 - A[i+1]) ; plus := ((expr (atom (name collections)) (trailer . (name Counter) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name plus)))))))) ))))) ; minus := ((expr (atom (name collections)) (trailer . (name Counter) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name minus)))))))) ))))) ; var ans : int := 0 ; for i : plus.keys() do ( if (minus)->includes(i) then ( ans := ans + plus[i+1] * minus[i+1] ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np N=int(input()) A=[int(_)for _ in input().split()] nmax=int(2e5+1) X=[0]*nmax Y=[0]*nmax for n,a in enumerate(A): x=n-a y=n+a if x>=0 and x=0 and ytoInteger() ; var A : Sequence := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var nmax : int := ("" + ((("2e5")->toReal() + 1)))->toInteger() ; var X : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, nmax) ; var Y : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, nmax) ; for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1; var n : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); var x : double := n - a ; var y : OclAny := n + a ; if x >= 0 & (x->compareTo(nmax)) < 0 then ( X[x+1] := X[x+1] + 1 ) else skip ; if y >= 0 & (y->compareTo(nmax)) < 0 then ( Y[y+1] := Y[y+1] + 1 ) else skip) ; var ret : int := 0 ; for _tuple : Integer.subrange(1, X->size())->collect( _indx | Sequence{X->at(_indx), Y->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); ret := ret + x * y) ; execute (ret)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin from sys import setrecursionlimit setrecursionlimit(10**7) n=int(stdin.readline().rstrip()) a=list(map(int,stdin.readline().rstrip().split())) dic={} point=0 for i,j in enumerate(a): if i+j in dic : dic[i+j]+=1 else : dic[i+j]=1 for i,j in enumerate(a): if i-j in dic : point+=dic[i-j] print(point) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; setrecursionlimit((10)->pow(7)) ; var n : int := ("" + ((stdin.readLine().rstrip())))->toInteger() ; var a : Sequence := ((stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dic : OclAny := Set{} ; var point : int := 0 ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if (dic)->includes(i + j) then ( dic[i + j+1] := dic[i + j+1] + 1 ) else ( dic[i + j+1] := 1 )) ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if (dic)->includes(i - j) then ( point := point + dic[i - j+1] ) else skip) ; execute (point)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque n,m=map(int,input().split()) INF=100050 q=deque() class Room : def __init__(self,num): self.number=num self.frontier=True self.neighbor=[] self.arrow=0 self.deepness=INF def set(self,room): self.neighbor.append(room) def search(self,num,deps): self.arrow=num self.deepness=deps self.frontier=False def dfs(self): for i in self.neighbor : if rooms[i].frontier : rooms[i].search(self.number,self.deepness+1) q.append(i) rooms=[] for i in range(n+1): rooms.append(Room(i)) for _ in range(m): a,b=map(int,input().split()) rooms[a].set(b) rooms[b].set(a) q.append(1) while q : rooms[q.popleft()].dfs() print("Yes") for i in range(2,len(rooms)): if rooms[i].frontier==False : print(rooms[i].arrow) ------------------------------------------------------------ OCL File: --------- class Room { static operation newRoom() : Room pre: true post: Room->exists( _x | result = _x ); attribute number : OclAny := num; attribute frontier : boolean := true; attribute neighbor : Sequence := Sequence{}; attribute arrow : int := 0; attribute deepness : int := INF; operation initialise(num : OclAny) : Room pre: true post: true activity: self.number := num ; self.frontier := true ; self.neighbor := Sequence{} ; self.arrow := 0 ; self.deepness := INF; return self; operation set(room : OclAny) pre: true post: true activity: (expr (atom (name self)) (trailer . (name neighbor)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name room)))))))) )))); operation search(num : OclAny,deps : OclAny) pre: true post: true activity: self.arrow := num ; self.deepness := deps ; self.frontier := false; operation dfs() pre: true post: true activity: for i : self.neighbor do ( if rooms[i+1].frontier then ( (expr (atom (name rooms)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name search) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name self)) (trailer . (name number))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name self)) (trailer . (name deepness))) + (expr (atom (number (integer 1)))))))))) )))) ; execute ((i) : q) ) else skip); } class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var INF : int := 100050 ; var q : Sequence := () ; skip ; var rooms : Sequence := Sequence{} ; for i : Integer.subrange(0, n + 1-1) do ( execute (((Room.newRoom()).initialise(i)) : rooms)) ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name rooms)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name set) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name rooms)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name set) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; execute ((1) : q) ; while q do ((expr (atom (name rooms)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name q)) (trailer . (name popleft) (arguments ( ))))))))) ])) (trailer . (name dfs) (arguments ( ))))) ; execute ("Yes")->display() ; for i : Integer.subrange(2, (rooms)->size()-1) do ( if rooms[i+1].frontier = false then ( execute (rooms[i+1].arrow)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def subString(Str,n): for Len in range(1,n+1): for i in range(n-Len+1): j=i+Len-1 for k in range(i,j+1): print(Str[k],end="") print() Str="abc" subString(Str,len(Str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Str := "abc" ; subString(Str, (Str)->size()); operation subString(Str : OclAny, n : OclAny) pre: true post: true activity: for Len : Integer.subrange(1, n + 1-1) do ( for i : Integer.subrange(0, n - Len + 1-1) do ( var j : double := i + Len - 1 ; for k : Integer.subrange(i, j + 1-1) do ( execute (Str[k+1])->display()) ; execute (->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import networkx as nx n,m=map(int,input().split()) s=[list(map(int,input().split()))for _ in range(m)] g=nx.Graph() g.add_edges_from(s) di=nx.predecessor(g,source=1) print("Yes") for x in range(2,n+1): print(di[x][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var g : OclAny := nx.Graph() ; g.add_edges_from(s) ; var di : OclAny := nx.predecessor(g, (argument (test (logical_test (comparison (expr (atom (name source)))))) = (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ; execute ("Yes")->display() ; for x : Integer.subrange(2, n + 1-1) do ( execute (di[x+1]->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import deque s2nn=lambda s :[int(c)for c in s.split(' ')] ss2nn=lambda ss :[int(s)for s in list(ss)] ss2nnn=lambda ss :[s2nn(s)for s in list(ss)] i2s=lambda : sys.stdin.readline().rstrip() i2n=lambda : int(i2s()) i2nn=lambda : s2nn(i2s()) ii2ss=lambda n :[i2s()for _ in range(n)] ii2nn=lambda n : ss2nn(ii2ss(n)) ii2nnn=lambda n : ss2nnn(ii2ss(n)) def main(): N,M=i2nn() tree=[set()for _ in range(N+1)] sign=[None]*(N+1) cnt=0 for _ in range(M): A,B=i2nn() tree[A].add(B) tree[B].add(A) que=deque([1]) while que : seek=que.popleft() for n in tree[seek]: if sign[n]is not None : continue cnt+=1 sign[n]=seek tree[n].discard(seek) que.append(n) if cntselect(c | true)->collect(c | (("" + ((c)))->toInteger()))) ; var ss2nn : Function := lambda ss : OclAny in ((ss)->select(s | true)->collect(s | (("" + ((s)))->toInteger()))) ; var ss2nnn : Function := lambda ss : OclAny in ((ss)->select(s | true)->collect(s | (s2nn->apply(s)))) ; var i2s : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var i2n : Function := lambda $$ : OclAny in (("" + ((i2s->apply())))->toInteger()) ; var i2nn : Function := lambda $$ : OclAny in (s2nn->apply(i2s->apply())) ; var ii2ss : Function := lambda n : OclAny in (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (i2s->apply()))) ; var ii2nn : Function := lambda n : OclAny in (ss2nn->apply(ii2ss->apply(n))) ; var ii2nnn : Function := lambda n : OclAny in (ss2nnn->apply(ii2ss->apply(n))) ; skip ; main(); operation main() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := i2nn->apply() ; var tree : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; var sign : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (N + 1)) ; var cnt : int := 0 ; for _anon : Integer.subrange(0, M-1) do ( var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := i2nn->apply() ; (expr (atom (name tree)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name A)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name B)))))))) )))) ; (expr (atom (name tree)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name B)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)))))))) ))))) ; var que : Sequence := (Sequence{ 1 }) ; while que do ( var seek : OclAny := que->first() ; que := que->tail() ; for n : tree[seek+1] do ( if not(sign[n+1] <>= null) then ( continue ) else skip ; cnt := cnt + 1 ; sign[n+1] := seek ; (expr (atom (name tree)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n)))))))) ])) (trailer . (name discard) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name seek)))))))) )))) ; execute ((n) : que))) ; if (cnt->compareTo(N - 1)) < 0 then ( execute ('No')->display() ; return ) else skip ; execute ('Yes')->display() ; for s : sign.subrange(2+1) do ( execute (s)->display()) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import queue from collections import defaultdict n,m=map(int,input().split()) g=defaultdict(set) ans=[0]*n for _ in range(m): a,b=map(int,input().split()) a-=1 b-=1 g[a].add(b) g[b].add(a) visited=[False]*n visited[0]=True q=queue.Queue() q.put(0) while not q.empty(): v=q.get() for p in g[v]: if not visited[p]: ans[p]=v q.put(p) visited[p]=True print('Yes') for x in ans[1 :]: print(x+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var g : OclAny := defaultdict(OclType["Set"]) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := a - 1 ; b := b - 1 ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ; visited->first() := true ; var q : OclAny := queue.Queue() ; q.put(0) ; while not(q.empty()) do ( var v : OclAny := q.get() ; for p : g[v+1] do ( if not(visited[p+1]) then ( ans[p+1] := v ; q.put(p) ; visited[p+1] := true ) else skip)) ; execute ('Yes')->display() ; for x : ans->tail() do ( execute (x + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): from collections import deque n,m,*ab=map(int,open(0).read().split()) l={i :[]for i in range(n+1)} for i,j in zip(*[iter(ab)]*2): l[i].append(j) l[j].append(i) ll=[None]*(n+1) vis=[False]*(n+1) que=deque([1]) vis[1]=True while que : now=que.popleft() nx=l[now] for i in nx : if vis[i]: continue vis[i]=True ll[i]=now que.append(i) if all(vis[1 :]): print("Yes") s="\n".join(map(str,ll[2 :])) print(s) else : print("No") if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; var ab : OclAny := null; Sequence{n,m,ab} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Map := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | Map{i |-> Sequence{}})->unionAll() ; for _tuple : Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ab)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ab)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ab)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))`third->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) ; (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var ll : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (n + 1)) ; var vis : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (n + 1)) ; var que : Sequence := (Sequence{ 1 }) ; vis[1+1] := true ; while que do ( var now : OclAny := que->first() ; que := que->tail() ; var nx : OclAny := l[now+1] ; for i : nx do ( if vis[i+1] then ( continue ) else skip ; vis[i+1] := true ; ll[i+1] := now ; execute ((i) : que))) ; if (vis->tail())->forAll( _x | _x = true ) then ( execute ("Yes")->display() ; var s : String := StringLib.sumStringsWithSeparator(((ll.subrange(2+1))->collect( _x | (OclType["String"])->apply(_x) )), "\n") ; execute (s)->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=10000 ; MOD=1000000007 ; F=[0]*N ; def precompute(): F[1]=2 ; F[2]=3 ; F[3]=4 ; for i in range(4,N): F[i]=(F[i-1]+F[i-2])% MOD ; n=8 ; precompute(); print(F[n]); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 10000; ; var MOD : int := 1000000007; ; var F : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N); ; skip ; var n : int := 8; ; precompute(); ; execute (F[n+1])->display();; operation precompute() pre: true post: true activity: F[1+1] := 2; ; F[2+1] := 3; ; F[3+1] := 4; ; for i : Integer.subrange(4, N-1) do ( F[i+1] := (F[i - 1+1] + F[i - 2+1]) mod MOD;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from sys import stdin input=stdin.readline def f(cnt,cost,qt): d={} q=[] for i in range(len(cnt)): d[i]=[cost[i],cnt[i]] q.append([cost[i],cnt[i],i]) bad=[0]*len(cnt) heapq.heapify(q) for t,freq in qt : cs=0 temp=min(freq,d[t][1]) d[t][1]-=temp freq-=temp cs+=temp*(cost[t]) while freq and q : temp=heapq.heappop(q) temp[1]=d[temp[2]][1] mn=min(temp[1],freq) temp[1]-=mn freq-=mn d[temp[2]][1]-=mn cs+=temp[0]*mn if temp[1]: heapq.heappush(q,temp) if freq==0 : print(cs) else : print(0) n,m=map(int,input().strip().split()) cnt=list(map(int,input().strip().split())) cost=list(map(int,input().strip().split())) q=[] for i in range(m): t,d=map(int,input().strip().split()) q.append((t-1,d)) f(cnt,cost,q) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; cnt := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; cost := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; q := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var t : OclAny := null; Sequence{t,d} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{t - 1, d}) : q)) ; f(cnt, cost, q); operation f(cnt : OclAny, cost : OclAny, qt : OclAny) pre: true post: true activity: var d : OclAny := Set{} ; var q : Sequence := Sequence{} ; for i : Integer.subrange(0, (cnt)->size()-1) do ( d[i+1] := Sequence{cost[i+1]}->union(Sequence{ cnt[i+1] }) ; execute ((Sequence{cost[i+1]}->union(Sequence{cnt[i+1]}->union(Sequence{ i }))) : q)) ; var bad : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (cnt)->size()) ; heapq.heapify(q) ; for _tuple : qt do (var _indx : int := 1; var t : OclAny := _tuple->at(_indx); _indx := _indx + 1; var freq : OclAny := _tuple->at(_indx); var cs : int := 0 ; var temp : OclAny := Set{freq, d[t+1][1+1]}->min() ; d[t+1][1+1] := d[t+1][1+1] - temp ; freq := freq - temp ; cs := cs + temp * (cost[t+1]) ; while freq & q do ( temp := heapq.heappop(q) ; temp[1+1] := d[temp[2+1]+1][1+1] ; var mn : OclAny := Set{temp[1+1], freq}->min() ; temp[1+1] := temp[1+1] - mn ; freq := freq - mn ; d[temp[2+1]+1][1+1] := d[temp[2+1]+1][1+1] - mn ; cs := cs + temp->first() * mn ; if temp[1+1] then ( heapq.heappush(q, temp) ) else skip) ; if freq = 0 then ( execute (cs)->display() ) else ( execute (0)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from sys import stdin input=stdin.readline def f(cnt,cost,qt): d={} q=[] for i in range(len(cnt)): d[i]=[cost[i],cnt[i]] q.append([cost[i],cnt[i],i]) bad=[0]*len(cnt) heapq.heapify(q) for t,freq in qt : cs=0 temp=min(freq,d[t][1]) d[t][1]-=temp freq-=temp cs+=temp*(cost[t]) while freq and q : temp=heapq.heappop(q) temp[1]=d[temp[2]][1] mn=min(temp[1],freq) temp[1]-=mn freq-=mn d[temp[2]][1]-=mn cs+=temp[0]*mn if temp[1]: heapq.heappush(q,temp) if freq==0 : print(cs) else : print(0) n,m=map(int,input().strip().split()) cnt=list(map(int,input().strip().split())) cost=list(map(int,input().strip().split())) q=[] for i in range(m): t,d=map(int,input().strip().split()) q.append((t-1,d)) f(cnt,cost,q) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; cnt := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; cost := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; q := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var t : OclAny := null; Sequence{t,d} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{t - 1, d}) : q)) ; f(cnt, cost, q); operation f(cnt : OclAny, cost : OclAny, qt : OclAny) pre: true post: true activity: var d : OclAny := Set{} ; var q : Sequence := Sequence{} ; for i : Integer.subrange(0, (cnt)->size()-1) do ( d[i+1] := Sequence{cost[i+1]}->union(Sequence{ cnt[i+1] }) ; execute ((Sequence{cost[i+1]}->union(Sequence{cnt[i+1]}->union(Sequence{ i }))) : q)) ; var bad : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (cnt)->size()) ; heapq.heapify(q) ; for _tuple : qt do (var _indx : int := 1; var t : OclAny := _tuple->at(_indx); _indx := _indx + 1; var freq : OclAny := _tuple->at(_indx); var cs : int := 0 ; var temp : OclAny := Set{freq, d[t+1][1+1]}->min() ; d[t+1][1+1] := d[t+1][1+1] - temp ; freq := freq - temp ; cs := cs + temp * (cost[t+1]) ; while freq & q do ( temp := heapq.heappop(q) ; temp[1+1] := d[temp[2+1]+1][1+1] ; var mn : OclAny := Set{temp[1+1], freq}->min() ; temp[1+1] := temp[1+1] - mn ; freq := freq - mn ; d[temp[2+1]+1][1+1] := d[temp[2+1]+1][1+1] - mn ; cs := cs + temp->first() * mn ; if temp[1+1] then ( heapq.heappush(q, temp) ) else skip) ; if freq = 0 then ( execute (cs)->display() ) else ( execute (0)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def maxDiff(arr,n): SubsetSum_1=0 SubsetSum_2=0 for i in range(0,n): isSingleOccurance=True for j in range(i+1,n): if(arr[i]==arr[j]): isSingleOccurance=False arr[i]=arr[j]=0 break if(isSingleOccurance==True): if(arr[i]>0): SubsetSum_1+=arr[i] else : SubsetSum_2+=arr[i] return abs(SubsetSum_1-SubsetSum_2) arr=[4,2,-3,3,-2,-2,8] n=len(arr) print("Maximum Difference={}".format(maxDiff(arr,n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{4}->union(Sequence{2}->union(Sequence{-3}->union(Sequence{3}->union(Sequence{-2}->union(Sequence{-2}->union(Sequence{ 8 })))))) ; n := (arr)->size() ; execute (StringLib.interpolateStrings("Maximum Difference={}", Sequence{maxDiff(arr, n)}))->display(); operation maxDiff(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var SubsetSum skip : int := 0 ; var SubsetSum:= 0 : int := 0 ; for i : Integer.subrange(0, n-1) do ( var isSingleOccurance : boolean := true ; for j : Integer.subrange(i + 1, n-1) do ( if (arr[i+1] = arr[j+1]) then ( isSingleOccurance := false ; arr[i+1] := 0; var arr[j+1] : int := 0 ; break ) else skip) ; if (isSingleOccurance = true) then ( if (arr[i+1] > 0) then ( SubsetSum var isSingleOccurance : boolean := true := SubsetSum var isSingleOccurance : boolean := true + arr[i+1] ) else ( SubsetSum + arr[i+1] := SubsetSum + arr[i+1] + arr[i+1] ) ) else skip) ; return (SubsetSum var SubsetSum skip : int := 0 - SubsetSum_2)->abs(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) adj=[0]*n for i in range(n): adj[i]=[] for i in range(m): u,v=map(int,input().split()) adj[u-1].append(v-1) adj[v-1].append(u-1) res=int(1e6) for i in range(n): curr=set(adj[i]) for j in adj[i]: for k in adj[j]: if k in curr : res=min(res,len(adj[i])+len(adj[j])+len(adj[k])-6) print(-1 if res==int(1e6)else res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var adj : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( adj[i+1] := Sequence{}) ; for i : Integer.subrange(0, m-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name u))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name u))) - (expr (atom (number (integer 1)))))))))) ))))) ; var res : int := ("" + ((("1e6")->toReal())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var curr : Set := Set{}->union((adj[i+1])) ; for j : adj[i+1] do ( for k : adj[j+1] do ( if (curr)->includes(k) then ( res := Set{res, (adj[i+1])->size() + (adj[j+1])->size() + (adj[k+1])->size() - 6}->min() ) else skip))) ; execute (if res = ("" + ((("1e6")->toReal())))->toInteger() then -1 else res endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) connections=[[]for i in range(n)] for _ in range(m): a,b=map(int,input().split()) connections[a-1].append(b-1) connections[b-1].append(a-1) min_=100000000000000000000000 for i in range(n): for j in connections[i]: for k in connections[j]: if k in connections[i]: min_=min(len(connections[i])+len(connections[j])+len(connections[k])-6,min_) print(-1 if min_==100000000000000000000000 else min_) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var connections : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name connections)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name connections)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ))))) ; var min_ : double := 100000000000000000000000 ; for i : Integer.subrange(0, n-1) do ( for j : connections[i+1] do ( for k : connections[j+1] do ( if (connections[i+1])->includes(k) then ( min_ := Set{(connections[i+1])->size() + (connections[j+1])->size() + (connections[k+1])->size() - 6, min_}->min() ) else skip))) ; execute (if min_ = 100000000000000000000000 then -1 else min_ endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) adj=[[]for i in range(n)] for i in range(m): joints=list(map(int,input().split())) adj[joints[0]-1].append(joints[1]-1) adj[joints[1]-1].append(joints[0]-1) popularity=[] for i in range(n): popularity.append(len(adj[i])) min_popularity=m+1 for first in range(0,n-2): if popularity[first]>=2 : for second in range(first+1,n-1): if popularity[second]>=2 and second in adj[first]: for third in range(second+1,n): if third in adj[first]and third in adj[second]and(popularity[first]+popularity[second]+popularity[third]-6)collect( _x | (OclType["int"])->apply(_x) ) ; var adj : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, m-1) do ( var joints : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name joints)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name joints)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name joints)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name joints)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) - (expr (atom (number (integer 1)))))))))) ))))) ; var popularity : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((adj[i+1])->size()) : popularity)) ; var min_popularity : OclAny := m + 1 ; for first : Integer.subrange(0, n - 2-1) do ( if popularity[first+1] >= 2 then ( for second : Integer.subrange(first + 1, n - 1-1) do ( if popularity[second+1] >= 2 & (adj[first+1])->includes(second) then ( for third : Integer.subrange(second + 1, n-1) do ( if (adj[first+1])->includes(third) & (adj[second+1])->includes(third) & ((popularity[first+1] + popularity[second+1] + popularity[third+1] - 6)->compareTo(min_popularity)) < 0 then ( min_popularity := popularity[first+1] + popularity[second+1] + popularity[third+1] - 6 ) else skip) ) else skip) ) else skip) ; execute (Sequence{-1, min_popularity}->select(min_popularity /= m + 1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def firstElement(arr,n,k): count_map={}; for i in range(0,n): if(arr[i]in count_map.keys()): count_map[arr[i]]+=1 else : count_map[arr[i]]=1 i+=1 for i in range(0,n): if(count_map[arr[i]]==k): return arr[i] i+=1 return-1 if __name__=="__main__" : arr=[1,7,4,3,4,8,7]; n=len(arr) k=2 print(firstElement(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{7}->union(Sequence{4}->union(Sequence{3}->union(Sequence{4}->union(Sequence{8}->union(Sequence{ 7 })))))); ; n := (arr)->size() ; k := 2 ; execute (firstElement(arr, n, k))->display() ) else skip; operation firstElement(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var count_map : OclAny := Set{}; ; for i : Integer.subrange(0, n-1) do ( if ((count_map.keys())->includes(arr[i+1])) then ( count_map[arr[i+1]+1] := count_map[arr[i+1]+1] + 1 ) else ( count_map[arr[i+1]+1] := 1 ) ; i := i + 1) ; for i : Integer.subrange(0, n-1) do ( if (count_map[arr[i+1]+1] = k) then ( return arr[i+1] ) else skip ; i := i + 1) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) d=[0]*n t=[] for i in range(n): t.append([0]*n) for i in range(m): a,b=map(int,input().split()) t[a-1][b-1]=t[b-1][a-1]=1 d[a-1]+=1 d[b-1]+=1 res=10000005 for i in range(n): for j in range(i+1,n): if t[i][j]: for k in range(j+1,n): if t[i][k]and t[j][k]: res=min(res,d[i]+d[j]+d[k]) if res==10000005 : print(-1) else : print(res-6) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var t : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((MatrixLib.elementwiseMult(Sequence{ 0 }, n)) : t)) ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; t[a - 1+1][b - 1+1] := 1; var t[b - 1+1][a - 1+1] : int := 1 ; d[a - 1+1] := d[a - 1+1] + 1 ; d[b - 1+1] := d[b - 1+1] + 1) ; var res : int := 10000005 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if t[i+1][j+1] then ( for k : Integer.subrange(j + 1, n-1) do ( if t[i+1][k+1] & t[j+1][k+1] then ( res := Set{res, d[i+1] + d[j+1] + d[k+1]}->min() ) else skip) ) else skip)) ; if res = 10000005 then ( execute (-1)->display() ) else ( execute (res - 6)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools import math from math import gcd as gcd import sys import queue import itertools from heapq import heappop,heappush import random def solve(): n,m=map(int,input().split()) g=[set()for i in range(n)] for i in range(m): a,b=map(int,input().split()) a-=1 b-=1 g[a].add(b) g[b].add(a) res=1<<60 for f in range(n): for s in g[f]: cand=g[f]& g[s] if len(cand)!=0 : for k in cand : res=min(res,len(g[f])+len(g[s])-4+len(g[k])-2) if res==1<<60 : print(-1) else : print(res) if __name__=='__main__' : multi_test=0 if multi_test : t=int(sys.stdin.readline()) for _ in range(t): solve() else : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var multi_test : int := 0 ; if multi_test then ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( solve()) ) else ( solve() ) ) else skip; operation solve() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var g : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Set{}->union(()))) ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := a - 1 ; b := b - 1 ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var res : int := 1 * (2->pow(60)) ; for f : Integer.subrange(0, n-1) do ( for s : g[f+1] do ( var cand : int := MathLib.bitwiseAnd(g[f+1], g[s+1]) ; if (cand)->size() /= 0 then ( for k : cand do ( res := Set{res, (g[f+1])->size() + (g[s+1])->size() - 4 + (g[k+1])->size() - 2}->min()) ) else skip)) ; if res = 1 * (2->pow(60)) then ( execute (-1)->display() ) else ( execute (res)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,s,c=int(input()),input(),3 for i in range(n-1): c+=s[i]!=s[i+1] print(min(n,c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var s : OclAny := null; var c : OclAny := null; Sequence{n,s,c} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),(OclFile["System.in"]).readLine(),3} ; for i : Integer.subrange(0, n - 1-1) do ( c := c + s[i+1] /= s[i + 1+1]) ; execute (Set{n, c}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break num=2 cnt=0 while True : ini=num*(num+1)//2 if ntoInteger() ; if n = 0 then ( break ) else skip ; var num : int := 2 ; var cnt : int := 0 ; while true do ( var ini : int := num * (num + 1) div 2 ; if (n->compareTo(ini)) < 0 then ( break ) else skip ; while (ini->compareTo(n)) <= 0 do ( if ini = n then ( cnt := cnt + 1 ; break ) else skip ; ini := ini + num) ; num := num + 1) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import inf from collections import* import math,os,sys,heapq,bisect,random from functools import lru_cache from itertools import* def inp(): return sys.stdin.readline().rstrip("\n") def out(var): sys.stdout.write(str(var)) def inpu(): return int(inp()) def lis(): return list(map(int,inp().split())) def stringlis(): return list(map(str,inp().split())) def sep(): return map(int,inp().split()) def strsep(): return map(str,inp().split()) def fsep(): return map(float,inp().split()) M,M1=1000000007,998244353 def main(): how_much_noob_I_am=1 for __ in range(how_much_noob_I_am): n=inpu() s=inp() ans=[0]*(n) p=s[0] ans[0]=1 for i in range(1,n): if s[i]!=p : ans[i]=ans[i-1]+1 p=s[i] else : ans[i]=ans[i-1] print(min(n,max(ans)+2)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var M : OclAny := null; var M1 : OclAny := null; Sequence{M,M1} := Sequence{1000000007,998244353} ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation inp() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip("\n"); operation out(var : OclAny) pre: true post: true activity: (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name var)))))))) ))))))))) )))); operation inpu() : OclAny pre: true post: true activity: return ("" + ((inp())))->toInteger(); operation lis() : OclAny pre: true post: true activity: return ((inp().split())->collect( _x | (OclType["int"])->apply(_x) )); operation stringlis() : OclAny pre: true post: true activity: return ((inp().split())->collect( _x | (OclType["String"])->apply(_x) )); operation sep() : OclAny pre: true post: true activity: return (inp().split())->collect( _x | (OclType["int"])->apply(_x) ); operation strsep() : OclAny pre: true post: true activity: return (inp().split())->collect( _x | (OclType["String"])->apply(_x) ); operation fsep() : OclAny pre: true post: true activity: return (inp().split())->collect( _x | (OclType["double"])->apply(_x) ); operation main() pre: true post: true activity: var how_much_noob_I_am : int := 1 ; for __ : Integer.subrange(0, how_much_noob_I_am-1) do ( var n : OclAny := inpu() ; var s : OclAny := inp() ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n)) ; var p : OclAny := s->first() ; ans->first() := 1 ; for i : Integer.subrange(1, n-1) do ( if s[i+1] /= p then ( ans[i+1] := ans[i - 1+1] + 1 ; p := s[i+1] ) else ( ans[i+1] := ans[i - 1+1] )) ; execute (Set{n, (ans)->max() + 2}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,s,c=int(input()),input(),3 for i in range(n-1): c+=s[i]!=s[i+1] print(min(n,c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var s : OclAny := null; var c : OclAny := null; Sequence{n,s,c} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),(OclFile["System.in"]).readLine(),3} ; for i : Integer.subrange(0, n - 1-1) do ( c := c + s[i+1] /= s[i + 1+1]) ; execute (Set{n, c}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,s,c=int(input()),input(),3 for i in range(n-1): c+=s[i]!=s[i+1] print(min(n,c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var s : OclAny := null; var c : OclAny := null; Sequence{n,s,c} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),(OclFile["System.in"]).readLine(),3} ; for i : Integer.subrange(0, n - 1-1) do ( c := c + s[i+1] /= s[i + 1+1]) ; execute (Set{n, c}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import os import pprint def judge(lst): x0,y0,x1,y1,x2,y2,x3,y3=lst v0=(x1-x0,y1-y0) v1=(x3-x2,y3-y2) dot=v0[0]*v1[0]+v0[1]*v1[1] cross=v0[0]*v1[1]-v0[1]*v1[0] if dot==0 : print(1) elif cross==0 : print(2) else : print(0) N=int(input()) for i in range(N): lst=list(map(int,input().split())) judge(lst) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, N-1) do ( lst := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; judge(lst)); operation judge(lst : OclAny) pre: true post: true activity: var x0 : OclAny := null; var y0 : OclAny := null; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; var x3 : OclAny := null; var y3 : OclAny := null; Sequence{x0,y0,x1,y1,x2,y2,x3,y3} := lst ; var v0 : OclAny := Sequence{x1 - x0, y1 - y0} ; var v1 : OclAny := Sequence{x3 - x2, y3 - y2} ; var dot : double := v0->first() * v1->first() + v0[1+1] * v1[1+1] ; var cross : double := v0->first() * v1[1+1] - v0[1+1] * v1->first() ; if dot = 0 then ( execute (1)->display() ) else (if cross = 0 then ( execute (2)->display() ) else ( execute (0)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import starmap import sys readline=sys.stdin.readline q=int(readline()) for _ in[0]*q : p0,p1,p2,p3=starmap(complex,zip(*[map(int,readline().split())]*2)) prod=(p1-p0).conjugate()*(p3-p2) print(2 if abs(prod.imag)<1e-6 else 1 if abs(prod.real)<1e-6 else 0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var q : int := ("" + ((readline())))->toInteger() ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, q) do ( var p0 : OclAny := null; var p1 : OclAny := null; var p2 : OclAny := null; var p3 : OclAny := null; Sequence{p0,p1,p2,p3} := starmap(complex, Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name readline)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name readline)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name readline)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))`third->at(_indx)} )) ; var prod : double := (p1 - p0).conjugate() * (p3 - p2) ; execute (if (prod.imag)->abs() < ("1e-6")->toReal() then 2 else if (prod.real)->abs() < ("1e-6")->toReal() then 1 else 0 endif endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def vector_product(vect1,vect2): return[el1*el2 for el1,el2 in zip(vect1,vect2)] def inner_product(vect1,vect2): return sum(vector_product(vect1,vect2)) def cross_product(vect1,vect2): return vect1[0]*vect2[1]-vect1[1]*vect2[0] def vector_minus(vect1,vect2): return[el1-el2 for el1,el2 in zip(vect1,vect2)] def line_slope(line_from,line_to): try : slope=(line_to[1]-line_from[1])/(line_to[0]-line_from[0]) except ZeroDivisionError : slope="未定義" return slope def is_parallel(l_from1,l_to1,l_from2,l_to2): line1=vector_minus(l_to1,l_from1) line2=vector_minus(l_to2,l_from2) if cross_product(line1,line2)==0 : return 1 return 0 def is_orthogonal(l_from1,l_to1,l_from2,l_to2): line1=vector_minus(l_to1,l_from1) line2=vector_minus(l_to2,l_from2) if inner_product(line1,line2)==0 : return 1 return 0 if __name__=='__main__' : Q=int(input()) for i in range(Q): all_list=list(map(int,input().split())) p0_list=all_list[: 2] p1_list=all_list[2 : 4] p2_list=all_list[4 : 6] p3_list=all_list[6 :] if is_parallel(p0_list,p1_list,p2_list,p3_list): print("2") elif is_orthogonal(p0_list,p1_list,p2_list,p3_list): print("1") else : print("0") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, Q-1) do ( var all_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var p0_list : OclAny := all_list.subrange(1,2) ; var p1_list : OclAny := all_list.subrange(2+1, 4) ; var p2_list : OclAny := all_list.subrange(4+1, 6) ; var p3_list : OclAny := all_list.subrange(6+1) ; if is_parallel(p0_list, p1_list, p2_list, p3_list) then ( execute ("2")->display() ) else (if is_orthogonal(p0_list, p1_list, p2_list, p3_list) then ( execute ("1")->display() ) else ( execute ("0")->display() ) ) ) ) else skip; operation vector_product(vect1 : OclAny, vect2 : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(1, vect1->size())->collect( _indx | Sequence{vect1->at(_indx), vect2->at(_indx)} )->select(_tuple | true)->collect(_tuple | let el1 : OclAny = _tuple->at(1) in let el2 : OclAny = _tuple->at(2) in (el1 * el2)); operation inner_product(vect1 : OclAny, vect2 : OclAny) : OclAny pre: true post: true activity: return (vector_product(vect1, vect2))->sum(); operation cross_product(vect1 : OclAny, vect2 : OclAny) : OclAny pre: true post: true activity: return vect1->first() * vect2[1+1] - vect1[1+1] * vect2->first(); operation vector_minus(vect1 : OclAny, vect2 : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(1, vect1->size())->collect( _indx | Sequence{vect1->at(_indx), vect2->at(_indx)} )->select(_tuple | true)->collect(_tuple | let el1 : OclAny = _tuple->at(1) in let el2 : OclAny = _tuple->at(2) in (el1 - el2)); operation line_slope(line_from : OclAny, line_to : OclAny) : OclAny pre: true post: true activity: try ( var slope : double := (line_to[1+1] - line_from[1+1]) / (line_to->first() - line_from->first())) (except_clause except (test (logical_test (comparison (expr (atom (name ZeroDivisionError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name slope)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom "???"))))))))))))) ; return slope; operation is_parallel(l_from1 : OclAny, l_to1 : OclAny, l_from2 : OclAny, l_to2 : OclAny) : OclAny pre: true post: true activity: var line1 : OclAny := vector_minus(l_to1, l_from1) ; var line2 : OclAny := vector_minus(l_to2, l_from2) ; if cross_product(line1, line2) = 0 then ( return 1 ) else skip ; return 0; operation is_orthogonal(l_from1 : OclAny, l_to1 : OclAny, l_from2 : OclAny, l_to2 : OclAny) : OclAny pre: true post: true activity: line1 := vector_minus(l_to1, l_from1) ; line2 := vector_minus(l_to2, l_from2) ; if inner_product(line1, line2) = 0 then ( return 1 ) else skip ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) def dot(a,b): return a[0]*b[0]+a[1]*b[1] def s(a): return a[0]**2+a[1]**2 for i in range(n): points=[int(j)for j in input().split()] p0=points[: 2] p1=points[2 : 4] p2=points[4 : 6] p3=points[6 : 8] a=[p0[0]-p1[0],p0[1]-p1[1]] b=[p2[0]-p3[0],p2[1]-p3[1]] c=dot(a,b)**2/(s(a)*s(b)) if c==0 : print(1) elif c==1 : print(2) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; skip ; for i : Integer.subrange(0, n-1) do ( var points : Sequence := input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; var p0 : OclAny := points.subrange(1,2) ; var p1 : OclAny := points.subrange(2+1, 4) ; var p2 : OclAny := points.subrange(4+1, 6) ; var p3 : OclAny := points.subrange(6+1, 8) ; a := Sequence{p0->first() - p1->first()}->union(Sequence{ p0[1+1] - p1[1+1] }) ; b := Sequence{p2->first() - p3->first()}->union(Sequence{ p2[1+1] - p3[1+1] }) ; var c : double := (dot(a, b))->pow(2) / (s(a) * s(b)) ; if c = 0 then ( execute (1)->display() ) else (if c = 1 then ( execute (2)->display() ) else ( execute (0)->display() ) ) ); operation dot(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a->first() * b->first() + a[1+1] * b[1+1]; operation s(a : OclAny) : OclAny pre: true post: true activity: return (a->first())->pow(2) + (a[1+1])->pow(2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def softDrinking(): (n,k,l,c,d,p,nl,np)=map(int,input().split()) toastOfdrinkings=int((k*l)/nl) toastOfLimes=int(c*d) toastOfSalts=int(p/np) print(int(min(toastOfdrinkings,min(toastOfLimes,toastOfSalts))/n)) return softDrinking() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; softDrinking(); operation softDrinking() pre: true post: true activity: ; var Sequence{n, k, l, c, d, p, nl, np} : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var toastOfdrinkings : int := ("" + (((k * l) / nl)))->toInteger() ; var toastOfLimes : int := ("" + ((c * d)))->toInteger() ; var toastOfSalts : int := ("" + ((p / np)))->toInteger() ; execute (("" + ((Set{toastOfdrinkings, Set{toastOfLimes, toastOfSalts}->min()}->min() / n)))->toInteger())->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,sys try : sys.stdin=open('in.in','r') except : pass class Point : def __init__(self,x,y): self.x=x self.y=y def __add__(self,p): return Point(self.x+p.x,self.y+p.y) def __sub__(self,p): return Point(self.x-p.x,self.y-p.y) def __mul__(self,p): return Point(self.x*p,self.y*p) def Dot(a,b): return a.x*b.x+a.y*b.y def Cross(a,b): return a.x*b.y-a.y*b.x def Dis(a,b): return math.sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)) def Dis2(a,b): return(a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y) q=int(input()) for i in range(q): x0,y0,x1,y1,x2,y2,x3,y3=map(int,input().split()) p0=Point(x0,y0) p1=Point(x1,y1) p2=Point(x2,y2) p3=Point(x3,y3) l1=p0-p1 l2=p3-p2 if Dot(l1,l2)==0 : print('1') elif Cross(l1,l2)==0 : print('2') else : print('0') ------------------------------------------------------------ OCL File: --------- class Point { static operation newPoint() : Point pre: true post: Point->exists( _x | result = _x ); attribute x : OclAny := x; attribute y : OclAny := y; operation initialise(x : OclAny,y : OclAny) : Point pre: true post: true activity: self.x := x ; self.y := y; return self; operation __add__(p : OclAny) : OclAny pre: true post: true activity: return Point(self.x + p.x, self.y + p.y); operation __sub__(p : OclAny) : OclAny pre: true post: true activity: return Point(self.x - p.x, self.y - p.y); operation __mul__(p : OclAny) : OclAny pre: true post: true activity: return Point(self.x * p, self.y * p); } class FromPython { operation initialise() pre: true post: true activity: skip ; try ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('in.in'))) catch (_e : OclException) do ( skip) ; skip ; skip ; skip ; skip ; skip ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( var x0 : OclAny := null; var y0 : OclAny := null; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; var x3 : OclAny := null; var y3 : OclAny := null; Sequence{x0,y0,x1,y1,x2,y2,x3,y3} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p0 : Point := (Point.newPoint()).initialise(x0, y0) ; var p1 : Point := (Point.newPoint()).initialise(x1, y1) ; var p2 : Point := (Point.newPoint()).initialise(x2, y2) ; var p3 : Point := (Point.newPoint()).initialise(x3, y3) ; var l1 : double := p0 - p1 ; var l2 : double := p3 - p2 ; if Dot(l1, l2) = 0 then ( execute ('1')->display() ) else (if Cross(l1, l2) = 0 then ( execute ('2')->display() ) else ( execute ('0')->display() ) ) ); operation Dot(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a.x * b.x + a.y * b.y; operation Cross(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a.x * b.y - a.y * b.x; operation Dis(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return ((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y))->sqrt(); operation Dis2(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter,deque import io,os,math t=int(input()) def GO_LIFE(): n,m=map(int,input().split()) if n==1 and m==1 : print(0) elif n==1 or m==1 : print(1) else : print(2) while t>0 : GO_LIFE() t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; while t > 0 do ( GO_LIFE() ; t := t - 1); operation GO_LIFE() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 1 & m = 1 then ( execute (0)->display() ) else (if n = 1 or m = 1 then ( execute (1)->display() ) else ( execute (2)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while(True): target=int(input()) if target==0 : break answer=0 for i in range(target-1): index=i+2 if(target-(0.5*index*(index-1)))% index==0 and(target-(0.5*index*(index-1)))>0 : answer+=1 print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while (true) do ( var target : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if target = 0 then ( break ) else skip ; var answer : int := 0 ; for i : Integer.subrange(0, target - 1-1) do ( var index : OclAny := i + 2 ; if (target - (0.5 * index * (index - 1))) mod index = 0 & (target - (0.5 * index * (index - 1))) > 0 then ( answer := answer + 1 ) else skip) ; execute (answer)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(0,n): a,b=map(int,input().split()) if a==1 and b==1 : print(0) elif a==1 or b==1 : print(1) else : print(2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 1 & b = 1 then ( execute (0)->display() ) else (if a = 1 or b = 1 then ( execute (1)->display() ) else ( execute (2)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=[int(x)for x in input().split()] if n==1 and m==1 : print(0) elif n==1 or m==1 : print(1) else : print(2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if n = 1 & m = 1 then ( execute (0)->display() ) else (if n = 1 or m = 1 then ( execute (1)->display() ) else ( execute (2)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=map(int,input().split()) if n==m==1 : n=0 print(min(min(n,m),2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = m & (m == 1) then ( var n : int := 0 ) else skip ; execute (Set{Set{n, m}->min(), 2}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=list(map(int,input().split())) if n==1 and m==1 : print("0") elif n==1 or m==1 : print("1") else : print("2") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = 1 & m = 1 then ( execute ("0")->display() ) else (if n = 1 or m = 1 then ( execute ("1")->display() ) else ( execute ("2")->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def min_element(a): m=10000000 for i in range(0,len(a)): if(a[i]=1): return-1 return smallest a=[25,20,5,10,100] n=len(a) print(findSmallest(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := Sequence{25}->union(Sequence{20}->union(Sequence{5}->union(Sequence{10}->union(Sequence{ 100 })))) ; n := (a)->size() ; execute (findSmallest(a, n))->display(); operation min_element(a : OclAny) : OclAny pre: true post: true activity: var m : int := 10000000 ; for i : Integer.subrange(0, (a)->size()-1) do ( if ((a[i+1]->compareTo(m)) < 0) then ( m := a[i+1] ) else skip) ; return m; operation findSmallest(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var smallest : OclAny := min_element(a) ; for i : Integer.subrange(1, n-1) do ( if (a[i+1] mod smallest >= 1) then ( return -1 ) else skip) ; return smallest; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt maxSize=10**5+1 ; isPrime=[0]*maxSize ; prefix=[0]*maxSize ; def digitSum(num): s=0 ; while(num!=0): s=s+num % 10 ; num=num//10 ; return s ; def sieveOfEratosthenes(): for i in range(2,maxSize): isPrime[i]=True ; for i in range(2,int(sqrt(maxSize))+1): if(isPrime[i]): for j in range(i*i,maxSize,i): isPrime[j]=False ; def precompute(k): sieveOfEratosthenes(); for i in range(1,maxSize): sum=digitSum(i); if(isPrime[sum]==True and sum % k==0): prefix[i]+=1 ; for i in range(1,maxSize): prefix[i]=prefix[i]+prefix[i-1]; def performQueries(k,q,query): precompute(k); for i in range(q): l=query[i][0]; r=query[i][1]; cnt=prefix[r]-prefix[l-1]; print(cnt); if __name__=="__main__" : query=[[1,11],[5,15],[2,24]]; k=2 ; q=len(query); performQueries(k,q,query); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var maxSize : double := (10)->pow(5) + 1; ; var isPrime : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, maxSize); ; var prefix : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, maxSize); ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( query := Sequence{Sequence{1}->union(Sequence{ 11 })}->union(Sequence{Sequence{5}->union(Sequence{ 15 })}->union(Sequence{ Sequence{2}->union(Sequence{ 24 }) })); ; k := 2; q := (query)->size(); ; performQueries(k, q, query); ) else skip; operation digitSum(num : OclAny) pre: true post: true activity: var s : int := 0; ; while (num /= 0) do ( s := s + num mod 10; ; num := num div 10;) ; return s;; operation sieveOfEratosthenes() pre: true post: true activity: for i : Integer.subrange(2, maxSize-1) do ( isPrime[i+1] := true;) ; for i : Integer.subrange(2, ("" + ((sqrt(maxSize))))->toInteger() + 1-1) do ( if (isPrime[i+1]) then ( for j : Integer.subrange(i * i, maxSize-1)->select( $x | ($x - i * i) mod i = 0 ) do ( isPrime[j+1] := false;) ) else skip); operation precompute(k : OclAny) pre: true post: true activity: sieveOfEratosthenes(); ; for i : Integer.subrange(1, maxSize-1) do ( var sum : OclAny := digitSum(i); ; if (isPrime[sum+1] = true & sum mod k = 0) then ( prefix[i+1] := prefix[i+1] + 1; ) else skip) ; for i : Integer.subrange(1, maxSize-1) do ( prefix[i+1] := prefix[i+1] + prefix[i - 1+1];); operation performQueries(k : OclAny, q : OclAny, query : OclAny) pre: true post: true activity: precompute(k); ; for i : Integer.subrange(0, q-1) do ( var l : OclAny := query[i+1]->first(); var r : OclAny := query[i+1][1+1]; ; var cnt : double := prefix[r+1] - prefix[l - 1+1]; ; execute (cnt)->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countOfAnagramSubstring(s): n=len(s) mp=dict() for i in range(n): sb='' for j in range(i,n): sb=''.join(sorted(sb+s[j])) mp[sb]=mp.get(sb,0) mp[sb]+=1 anas=0 for k,v in mp.items(): anas+=(v*(v-1))//2 return anas s="xyyx" print(countOfAnagramSubstring(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := "xyyx" ; execute (countOfAnagramSubstring(s))->display(); operation countOfAnagramSubstring(s : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; var mp : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( var sb : String := '' ; for j : Integer.subrange(i, n-1) do ( sb := StringLib.sumStringsWithSeparator((sb + s[j+1]->sort()), '') ; mp->at(sb) := mp.get(sb, 0) ; mp->at(sb) := mp->at(sb) + 1)) ; var anas : int := 0 ; for _tuple : mp->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); anas := anas + (v * (v - 1)) div 2) ; return anas; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CountPairs(n): k=n imin=1 ans=0 while(imin<=n): imax=n/k ans+=k*(imax-imin+1) imin=imax+1 k=n/imin return ans print(CountPairs(1)) print(CountPairs(2)) print(CountPairs(3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (CountPairs(1))->display() ; execute (CountPairs(2))->display() ; execute (CountPairs(3))->display(); operation CountPairs(n : OclAny) : OclAny pre: true post: true activity: var k : OclAny := n ; var imin : int := 1 ; var ans : int := 0 ; while ((imin->compareTo(n)) <= 0) do ( var imax : double := n / k ; ans := ans + k * (imax - imin + 1) ; imin := imax + 1 ; k := n / imin) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ip=list(map(int,input().split())) n=ip[0]; k=ip[1]; l=ip[2]; c=ip[3]; d=ip[4]; p=ip[5]; nl=ip[6]; np=ip[7] gls=k*l//nl lim=c*d slt=p//np if sltcollect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := ip->first(); var k : OclAny := ip[1+1]; var l : OclAny := ip[2+1]; var c : OclAny := ip[3+1]; var d : OclAny := ip[4+1]; var p : OclAny := ip[5+1]; var nl : OclAny := ip[6+1]; var np : OclAny := ip[7+1] ; var gls : int := k * l div nl ; var lim : double := c * d ; var slt : int := p div np ; if (slt->compareTo(gls)) < 0 then ( gls := slt ) else skip ; if (lim->compareTo(gls)) < 0 then ( gls := lim ) else skip ; execute (gls div n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() r=input() n=len(s) nn=len(r) m=0 c=0 x=0 for i in range(n-nn+1): t=s[i : i+nn] c=0 for j in range(nn): if(t[j]==r[j]): c+=1 m=max(m,c) print(nn-m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var r : String := (OclFile["System.in"]).readLine() ; var n : int := (s)->size() ; var nn : int := (r)->size() ; var m : int := 0 ; var c : int := 0 ; var x : int := 0 ; for i : Integer.subrange(0, n - nn + 1-1) do ( var t : OclAny := s.subrange(i+1, i + nn) ; c := 0 ; for j : Integer.subrange(0, nn-1) do ( if (t[j+1] = r[j+1]) then ( c := c + 1 ) else skip) ; m := Set{m, c}->max()) ; execute (nn - m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**3 eps=1.0/10**10 mod=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] while True : n=I() if n==0 : break r=0 for i in range(1,n): t=i while tpow(7)) ; var Math_PINFINITY : double := (10)->pow(3) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var n : OclAny := I() ; if n = 0 then ( break ) else skip ; var r : int := 0 ; for i : Integer.subrange(1, n-1) do ( var t : OclAny := i ; while (t->compareTo(n)) < 0 do ( i := i + 1 ; t := t + i) ; if t = n then ( r := r + 1 ) else skip) ; execute ((r) : rr)) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ma=lambda : map(int,input().split()) lma=lambda : list(map(int,input().split())) tma=lambda : tuple(map(int,input().split())) ni=lambda : int(input()) yn=lambda fl : print("Yes")if fl else print("No") import collections import math import itertools import heapq as hq ceil=math.ceil s=input() t=input() ls=len(s) lt=len(t) ans=10**9 for i in range(0,ls-lt+1): tmp=0 for j in range(lt): if t[j]!=s[i+j]: tmp+=1 ans=min(ans,tmp) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ma : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lma : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var tma : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ni : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var yn : Function := lambda fl : OclAny in (if fl then ("Yes")->display() else ("No")->display() endif) ; skip ; skip ; skip ; skip ; var ceil : OclAny := ; var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var ls : int := (s)->size() ; var lt : int := (t)->size() ; var ans : double := (10)->pow(9) ; for i : Integer.subrange(0, ls - lt + 1-1) do ( var tmp : int := 0 ; for j : Integer.subrange(0, lt-1) do ( if t[j+1] /= s[i + j+1] then ( tmp := tmp + 1 ) else skip) ; ans := Set{ans, tmp}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() T=input() Nmax=len(T) for i in range(len(S)-len(T)+1): diff=0 for j in range(len(T)): if(S[i+j]!=T[j]): diff+=1 Nmax=min(diff,Nmax) print(Nmax) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var T : String := (OclFile["System.in"]).readLine() ; var Nmax : int := (T)->size() ; for i : Integer.subrange(0, (S)->size() - (T)->size() + 1-1) do ( var diff : int := 0 ; for j : Integer.subrange(0, (T)->size()-1) do ( if (S[i + j+1] /= T[j+1]) then ( diff := diff + 1 ) else skip) ; Nmax := Set{diff, Nmax}->min()) ; execute (Nmax)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import bisect as bi import math from collections import defaultdict as dd import heapq import itertools input=sys.stdin.readline from random import randint mo=10**9+7 def cin(): return map(int,sin().split()) def ain(): return list(map(int,sin().split())) def sin(): return input() def inin(): return int(input()) for _ in range(1): s=sin().strip() t=sin().strip() ls,lt=len(s),len(t) ans=ls for i in range(0,ls-lt+1): c=0 for j in range(i,i+lt): if(s[j]!=t[j-i]): c+=1 ans=min(ans,c) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var mo : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; for _anon : Integer.subrange(0, 1-1) do ( var s : OclAny := sin()->trim() ; var t : OclAny := sin()->trim() ; var ls : OclAny := null; var lt : OclAny := null; Sequence{ls,lt} := Sequence{(s)->size(),(t)->size()} ; var ans : OclAny := ls ; for i : Integer.subrange(0, ls - lt + 1-1) do ( var c : int := 0 ; for j : Integer.subrange(i, i + lt-1) do ( if (s[j+1] /= t[j - i+1]) then ( c := c + 1 ) else skip) ; ans := Set{ans, c}->min()) ; execute (ans)->display()); operation cin() : OclAny pre: true post: true activity: return (sin().split())->collect( _x | (OclType["int"])->apply(_x) ); operation ain() : OclAny pre: true post: true activity: return ((sin().split())->collect( _x | (OclType["int"])->apply(_x) )); operation sin() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation inin() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): s_long=input() s_shor=input() ans=len(s_shor) max_len=len(s_long)-len(s_shor)+1 for i in range(max_len): cnt=0 for j in range(len(s_shor)): short=s_shor[j] longg=s_long[i+j] if(short!=longg): cnt+=1 ans=min(ans,cnt) print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var s_long : String := (OclFile["System.in"]).readLine() ; var s_shor : String := (OclFile["System.in"]).readLine() ; var ans : int := (s_shor)->size() ; var max_len : double := (s_long)->size() - (s_shor)->size() + 1 ; for i : Integer.subrange(0, max_len-1) do ( var cnt : int := 0 ; for j : Integer.subrange(0, (s_shor)->size()-1) do ( var short : OclAny := s_shor[j+1] ; var longg : OclAny := s_long[i + j+1] ; if (short /= longg) then ( cnt := cnt + 1 ) else skip) ; ans := Set{ans, cnt}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) if a>-128 and a<128 : print('byte') elif a>-32768 and a<32768 : print('short') elif a>-2147483648 and a<2147483648 : print('int') elif a>-9223372036854775808 and a<9223372036854775808 : print('long') else : print('BigInteger') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if a > -128 & a < 128 then ( execute ('byte')->display() ) else (if a > -32768 & a < 32768 then ( execute ('short')->display() ) else (if a > -2147483648 & a < 2147483648 then ( execute ('int')->display() ) else (if a > -9223372036854775808 & a < 9223372036854775808 then ( execute ('long')->display() ) else ( execute ('BigInteger')->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n in range(-128,128): print('byte') elif n in range(-32768,32768): print('short') elif n in range(-2147483648,2147483648): print('int') elif n in range(-9223372036854775808,9223372036854775808): print('long') else : print('BigInteger') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (Integer.subrange(-128, 128-1))->includes(n) then ( execute ('byte')->display() ) else (if (Integer.subrange(-32768, 32768-1))->includes(n) then ( execute ('short')->display() ) else (if (Integer.subrange(-2147483648, 2147483648-1))->includes(n) then ( execute ('int')->display() ) else (if (Integer.subrange(-9223372036854775808, 9223372036854775808-1))->includes(n) then ( execute ('long')->display() ) else ( execute ('BigInteger')->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if-128<=n<=127 : print("byte") elif-32768<=n<=32767 : print("short") elif-2147483648<=n<=2147483647 : print("int") elif-9223372036854775808<=n<=9223372036854775807 : print("long") else : print("BigInteger") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if -128 <= n & (n <= 127) then ( execute ("byte")->display() ) else (if -32768 <= n & (n <= 32767) then ( execute ("short")->display() ) else (if -2147483648 <= n & (n <= 2147483647) then ( execute ("int")->display() ) else (if -9223372036854775808 <= n & (n <= 9223372036854775807) then ( execute ("long")->display() ) else ( execute ("BigInteger")->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n): if n<=127 : return 'byte' if n<=32767 : return 'short' if n<=2147483647 : return 'int' if n<=9223372036854775807 : return 'long' return 'BigInteger' x=int(input()) print(solve(x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (solve(x))->display(); operation solve(n : OclAny) : OclAny pre: true post: true activity: if n <= 127 then ( return 'byte' ) else skip ; if n <= 32767 then ( return 'short' ) else skip ; if n <= 2147483647 then ( return 'int' ) else skip ; if n <= 9223372036854775807 then ( return 'long' ) else skip ; return 'BigInteger'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) if(t>=-128 and t<=127): print("byte") elif(t>=-32768 and t<=32767): print("short") elif(t>=-2147483648 and t<=2147483647): print("int") elif(t>=-9223372036854775808 and t<=9223372036854775807): print("long") else : print("BigInteger") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (t >= -128 & t <= 127) then ( execute ("byte")->display() ) else (if (t >= -32768 & t <= 32767) then ( execute ("short")->display() ) else (if (t >= -2147483648 & t <= 2147483647) then ( execute ("int")->display() ) else (if (t >= -9223372036854775808 & t <= 9223372036854775807) then ( execute ("long")->display() ) else ( execute ("BigInteger")->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k,l,c,d,p,a,b=map(int,input().split()) print(min(k*l//a,c*d,p//b)//n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var l : OclAny := null; var c : OclAny := null; var d : OclAny := null; var p : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,k,l,c,d,p,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{k * l div a, c * d, p div b}->min() div n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- items=[] while True : item=int(input()) if item==0 : break else : items.append(item) for item in items : cnt=0 tmp=list(range(1,item+1)) for i in range(2,item+1): for j in range(item-i): win=tmp[j : j+i] win=sum(win) if win==item : cnt+=1 break elif win>item : break print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var items : Sequence := Sequence{} ; while true do ( var item : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if item = 0 then ( break ) else ( execute ((item) : items) )) ; for item : items do ( var cnt : int := 0 ; var tmp : Sequence := (Integer.subrange(1, item + 1-1)) ; for i : Integer.subrange(2, item + 1-1) do ( for j : Integer.subrange(0, item - i-1) do ( var win : OclAny := tmp.subrange(j+1, j + i) ; win := (win)->sum() ; if win = item then ( cnt := cnt + 1 ; break ) else (if (win->compareTo(item)) > 0 then ( break ) else skip))) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def SubarraysWithSumS(n,k,s): for i in range(k): print(s,end=" ") for i in range(k,n): print(s+1,end=" ") n=4 k=2 s=3 SubarraysWithSumS(n,k,s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; k := 2 ; s := 3 ; SubarraysWithSumS(n, k, s); operation SubarraysWithSumS(n : OclAny, k : OclAny, s : OclAny) pre: true post: true activity: for i : Integer.subrange(0, k-1) do ( execute (s)->display()) ; for i : Integer.subrange(k, n-1) do ( execute (s + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def poorPigs(self,buckets,minutesToDie,minutesToTest): pigs=0 while(minutesToTest/minutesToDie+1)**pigsexists( _x | result = _x ); operation poorPigs(buckets : OclAny,minutesToDie : OclAny,minutesToTest : OclAny) : OclAny pre: true post: true activity: var pigs : int := 0 ; while (((minutesToTest / minutesToDie + 1))->pow(pigs)->compareTo(buckets)) < 0 do ( pigs := pigs + 1) ; return pigs; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def constructMaximumBinaryTree(self,nums): if nums is None or len(nums)==0 : return None max_index,max_value=0,0 for i,value in enumerate(nums): if value>=max_value : max_value=value max_index=i root=TreeNode(max_value) root.left=self.constructMaximumBinaryTree(nums[: max_index]) root.right=self.constructMaximumBinaryTree(nums[max_index+1 :]) return root ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation constructMaximumBinaryTree(nums : OclAny) : OclAny pre: true post: true activity: if nums <>= null or (nums)->size() = 0 then ( return null ) else skip ; var max_index : OclAny := null; var max_value : OclAny := null; Sequence{max_index,max_value} := Sequence{0,0} ; for _tuple : Integer.subrange(1, (nums)->size())->collect( _indx | Sequence{_indx-1, (nums)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); if (value->compareTo(max_value)) >= 0 then ( var max_value : OclAny := value ; var max_index : OclAny := i ) else skip) ; var root : OclAny := TreeNode(max_value) ; root.left := self.constructMaximumBinaryTree(nums.subrange(1,max_index)) ; root.right := self.constructMaximumBinaryTree(nums.subrange(max_index + 1+1)) ; return root; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- st=[]; def push_digits(number): while(number!=0): st.append(number % 10); number=int(number/10); def reverse_number(number): push_digits(number); reverse=0 ; i=1 ; while(len(st)>0): reverse=reverse+(st[len(st)-1]*i); st.pop(); i=i*10 ; return reverse ; number=39997 ; print(reverse_number(number)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var st : Sequence := Sequence{}; ; skip ; skip ; number := 39997; ; execute (reverse_number(number))->display();; operation push_digits(number : OclAny) pre: true post: true activity: while (number /= 0) do ( execute ((number mod 10) : st); ; number := ("" + ((number / 10)))->toInteger();); operation reverse_number(number : OclAny) pre: true post: true activity: push_digits(number); ; var reverse : int := 0; ; var i : int := 1; ; while ((st)->size() > 0) do ( reverse := reverse + (st[(st)->size() - 1+1] * i); ; st := st->front(); ; i := i * 10;) ; return reverse;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=4 C=4 def reverseColumns(arr): for i in range(C): j=0 k=C-1 while junion(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })))}->union(Sequence{Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 8 })))}->union(Sequence{Sequence{9}->union(Sequence{10}->union(Sequence{11}->union(Sequence{ 12 })))}->union(Sequence{ Sequence{13}->union(Sequence{14}->union(Sequence{15}->union(Sequence{ 16 }))) }))); ; rotate180(arr); ; printMatrix(arr);; operation reverseColumns(arr : OclAny) pre: true post: true activity: for i : Integer.subrange(0, C-1) do ( var j : int := 0 ; var k : double := C - 1 ; while (j->compareTo(k)) < 0 do ( var t : OclAny := arr[j+1][i+1] ; arr[j+1][i+1] := arr[k+1][i+1] ; arr[k+1][i+1] := t ; j := j + 1 ; k := k - 1)); operation transpose(arr : OclAny) pre: true post: true activity: for i : Integer.subrange(0, R-1) do ( for j : Integer.subrange(i, C-1) do ( t := arr[i+1][j+1] ; arr[i+1][j+1] := arr[j+1][i+1] ; arr[j+1][i+1] := t)); operation printMatrix(arr : OclAny) pre: true post: true activity: for i : Integer.subrange(0, R-1) do ( for j : Integer.subrange(0, C-1) do ( execute (arr[i+1][j+1])->display();) ; execute (->display();); operation rotate180(arr : OclAny) pre: true post: true activity: transpose(arr); ; reverseColumns(arr); ; transpose(arr); ; reverseColumns(arr);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) N,S,*XP=map(int,read().split()) X=XP[: : 2] P=XP[1 : : 2] leftN=sum(xy else y-x for x,y in zip(visit,visit[1 :])) print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; sys.setrecursionlimit((10)->pow(7)) ; var N : OclAny := null; var S : OclAny := null; var XP : OclAny := null; Sequence{N,S,XP} := (read().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var X : OclAny := XP(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ; var P : OclAny := XP(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ; var leftN : OclAny := ((argument (test (logical_test (comparison (comparison (expr (atom (name x)))) < (comparison (expr (atom (name S))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name X))))))))->sum() ; var leftX : OclAny := X(subscript (test (logical_test (comparison (expr (expr (atom (name leftN))) - (expr (atom (number (integer 1)))))))) : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var leftP : OclAny := P(subscript (test (logical_test (comparison (expr (expr (atom (name leftN))) - (expr (atom (number (integer 1)))))))) : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var rightN : double := N - leftN ; var rightX : OclAny := X.subrange(leftN+1) ; var rightP : OclAny := P.subrange(leftN+1) ; var visit : Sequence := Sequence{} ; while leftN & rightN do ( var p1 : OclAny := leftP->last(); var x1 : OclAny := leftX->last() ; var p2 : OclAny := rightP->last(); var x2 : OclAny := rightX->last() ; if (p1->compareTo(p2)) < 0 then ( execute ((x1) : visit) ; leftP := leftP->front(); leftX := leftX->front(); leftN := leftN - 1 ; rightP->last() := p1 + p2 ) else ( execute ((x2) : visit) ; rightP := rightP->front(); rightX := rightX->front(); rightN := rightN - 1 ; leftP->last() := p1 + p2 )) ; if leftN then ( visit := visit + leftX(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ) else ( visit := visit + rightX(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ) ; execute ((S) : visit) ; var answer : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (name y)))))) if (logical_test (comparison (comparison (expr (atom (name x)))) > (comparison (expr (atom (name y)))))) else (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (name x)))))))) (comp_for for (exprlist (expr (atom (name x))) , (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name visit))))))) , (argument (test (logical_test (comparison (expr (atom (name visit)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))))))) )))))))))->sum() ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np def solve(l,r): l.reverse() stops=[] if l and r : while l and r : lx,lp=l.pop() rx,rp=r.pop() if lp>=rp : l.append((lx,lp+rp)) stops.append(rx) else : r.append((rx,lp+rp)) stops.append(lx) if l : stops.append(l[-1][0]) else : stops.append(r[-1][0]) stops.append(s) return abs(np.diff(np.array(stops,dtype=np.int64))).sum() n,s=map(int,input().split()) l,r=[],[] for _ in range(n): x,p=map(int,input().split()) if xcollect( _x | (OclType["int"])->apply(_x) ) ; Sequence{l,r} := Sequence{Sequence{},Sequence{}} ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var p : OclAny := null; Sequence{x,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (x->compareTo(s)) < 0 then ( execute ((Sequence{x, p}) : l) ) else ( execute ((Sequence{x, p}) : r) )) ; execute (solve(l, r))->display(); operation solve(l : OclAny, r : OclAny) : OclAny pre: true post: true activity: l := l->reverse() ; var stops : Sequence := Sequence{} ; if l & r then ( while l & r do ( var lx : OclAny := null; var lp : OclAny := null; Sequence{lx,lp} := l->last() ; l := l->front() ; var rx : OclAny := null; var rp : OclAny := null; Sequence{rx,rp} := r->last() ; r := r->front() ; if (lp->compareTo(rp)) >= 0 then ( execute ((Sequence{lx, lp + rp}) : l) ; execute ((rx) : stops) ) else ( execute ((Sequence{rx, lp + rp}) : r) ; execute ((lx) : stops) )) ) else skip ; if l then ( execute ((l->last()->first()) : stops) ) else ( execute ((r->last()->first()) : stops) ) ; execute ((s) : stops) ; return abs().sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(arr,n): b=[0 for i in range(n)] p=0 i=n-1 while i>=0 : b[p]=arr[i] i-=1 if(i>=0): b[n-1-p]=arr[i] p+=1 i-=1 return b arr=[1,2,3,4] n=len(arr) b=solve(arr,n) print(b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))) ; n := (arr)->size() ; b := solve(arr, n) ; execute (b)->display(); operation solve(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var b : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var p : int := 0 ; var i : double := n - 1 ; while i >= 0 do ( b[p+1] := arr[i+1] ; i := i - 1 ; if (i >= 0) then ( b[n - 1 - p+1] := arr[i+1] ) else skip ; p := p + 1 ; i := i - 1) ; return b; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import os for s in sys.stdin : N=int(s) if N==0 : break X=[] Y=[] visited=[False]*N for i in range(N): x,y=map(float,input().split(',')) X.append(x) Y.append(y) def paint(start_i,is_right,is_up): x_start=X[start_i] y_start=Y[start_i] visited[start_i]=True if is_right : dir_sign=1 else : dir_sign=-1 if(is_up and is_right)or(not is_up and not is_right): min_max_sign=1 else : min_max_sign=-1 tangent_min_i=None tangent_min=None for i,x in enumerate(X): if dir_sign*(x-x_start)>0 : y=Y[i] tangent=(y-y_start)/(x-x_start) if tangent_min is None : tangent_min=tangent tangent_min_i=i else : if min_max_sign*(tangent_min-tangent)>0 : tangent_min=tangent tangent_min_i=i if tangent_min_i is not None : paint(tangent_min_i,is_right,is_up) start_index=Y.index(min(Y)) visited[start_index]=True paint(start_index,is_right=True,is_up=True) paint(start_index,is_right=False,is_up=True) start_index=Y.index(max(Y)) visited[start_index]=True paint(start_index,is_right=True,is_up=False) paint(start_index,is_right=False,is_up=False) visit_num=0 for is_visit in visited : if is_visit : visit_num+=1 print(len(X)-visit_num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for s : OclFile["System.in"] do ( var N : int := ("" + ((s)))->toInteger() ; if N = 0 then ( break ) else skip ; var X : Sequence := Sequence{} ; var Y : Sequence := Sequence{} ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, N) ; for i : Integer.subrange(0, N-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split(','))->collect( _x | (OclType["double"])->apply(_x) ) ; execute ((x) : X) ; execute ((y) : Y)) ; skip ; var start_index : int := Y->indexOf((Y)->min()) - 1 ; visited[start_index+1] := true ; paint(start_index, (argument (test (logical_test (comparison (expr (atom (name is_right)))))) = (test (logical_test (comparison (expr (atom (name True))))))), (argument (test (logical_test (comparison (expr (atom (name is_up)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; paint(start_index, (argument (test (logical_test (comparison (expr (atom (name is_right)))))) = (test (logical_test (comparison (expr (atom (name False))))))), (argument (test (logical_test (comparison (expr (atom (name is_up)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; start_index := Y->indexOf((Y)->max()) - 1 ; visited[start_index+1] := true ; paint(start_index, (argument (test (logical_test (comparison (expr (atom (name is_right)))))) = (test (logical_test (comparison (expr (atom (name True))))))), (argument (test (logical_test (comparison (expr (atom (name is_up)))))) = (test (logical_test (comparison (expr (atom (name False)))))))) ; paint(start_index, (argument (test (logical_test (comparison (expr (atom (name is_right)))))) = (test (logical_test (comparison (expr (atom (name False))))))), (argument (test (logical_test (comparison (expr (atom (name is_up)))))) = (test (logical_test (comparison (expr (atom (name False)))))))) ; var visit_num : int := 0 ; for is_visit : visited do ( if is_visit then ( visit_num := visit_num + 1 ) else skip) ; execute ((X)->size() - visit_num)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") def distance(p1,p2): return math.sqrt((p1[0]-p2[0])**2+(p1[1]-p2[1])**2) def is_to_the_left(p1,p2,p3): position=(p2[0]-p1[0])*(p3[1]-p1[1])-(p2[1]-p1[1])*(p3[0]-p1[0]) return position<0 def jarvis(points): max_y=max([p[1]for p in points]) pointOnHull=[p for p in points if p[1]==max_y][0] convex_hull=[pointOnHull] while len(convex_hull)==1 or convex_hull[-1]!=convex_hull[0]: p=convex_hull[-1] endpoint=points[0] for j in range(len(points)): if endpoint==pointOnHull or is_to_the_left(p,endpoint,points[j]): endpoint=points[j] pointOnHull=endpoint convex_hull.append(pointOnHull) return convex_hull[: :-1] while True : N=int(input()) if N==0 : break points=[[float(_)for _ in input().split(',')]for __ in range(N)] print(N-(len(jarvis(points))-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; skip ; skip ; skip ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; points := Integer.subrange(0, N-1)->select(__ | true)->collect(__ | (input().split(',')->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toReal())))) ; execute (N - ((jarvis(points))->size() - 1))->display()); operation distance(p1 : OclAny, p2 : OclAny) : OclAny pre: true post: true activity: return (((p1->first() - p2->first()))->pow(2) + ((p1[1+1] - p2[1+1]))->pow(2))->sqrt(); operation is_to_the_left(p1 : OclAny, p2 : OclAny, p3 : OclAny) : OclAny pre: true post: true activity: var position : double := (p2->first() - p1->first()) * (p3[1+1] - p1[1+1]) - (p2[1+1] - p1[1+1]) * (p3->first() - p1->first()) ; return position < 0; operation jarvis(points : OclAny) : OclAny pre: true post: true activity: var max_y : OclAny := (points->select(p | true)->collect(p | (p[1+1])))->max() ; var pointOnHull : OclAny := points->select(p | p[1+1] = max_y)->collect(p | (p))->first() ; var convex_hull : Sequence := Sequence{ pointOnHull } ; while (convex_hull)->size() = 1 or convex_hull->last() /= convex_hull->first() do ( var p : OclAny := convex_hull->last() ; var endpoint : OclAny := points->first() ; for j : Integer.subrange(0, (points)->size()-1) do ( if endpoint = pointOnHull or is_to_the_left(p, endpoint, points[j+1]) then ( endpoint := points[j+1] ) else skip) ; pointOnHull := endpoint ; execute ((pointOnHull) : convex_hull)) ; return convex_hull(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=input() e=input() alpha="abcdefghijklmnopqrstuvwxyz" a=0 b=0 t=dict() s=dict() for i in(alpha+alpha.upper()): t[i]=e.count(i) s[i]=q.count(i) p=min(s[i],t[i]) a+=p s[i]-=p t[i]-=p for e in alpha : b+=min(s[e]+s[e.upper()],t[e]+t[e.upper()]) print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : String := (OclFile["System.in"]).readLine() ; var e : String := (OclFile["System.in"]).readLine() ; var alpha : String := "abcdefghijklmnopqrstuvwxyz" ; var a : int := 0 ; var b : int := 0 ; var t : Map := (arguments ( )) ; var s : Map := (arguments ( )) ; for i : (alpha + alpha->toUpperCase()) do ( t[i+1] := e->count(i) ; s[i+1] := q->count(i) ; var p : OclAny := Set{s[i+1], t[i+1]}->min() ; a := a + p ; s[i+1] := s[i+1] - p ; t[i+1] := t[i+1] - p) ; for e : alpha->characters() do ( b := b + Set{s->at(e) + s[e->toUpperCase()+1], t->at(e) + t[e->toUpperCase()+1]}->min()) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def sum_of_num(target,num): return(((2*target)/num)-num+1)/2 while True : target_num=int(input()) if target_num==0 : break count=0 for i in range(2,int(target_num)): n=sum_of_num(target_num,i) if n.is_integer()and n>0 : count=count+1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( var target_num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if target_num = 0 then ( break ) else skip ; var count : int := 0 ; for i : Integer.subrange(2, ("" + ((target_num)))->toInteger()-1) do ( var n : OclAny := sum_of_num(target_num, i) ; if n.is_integer() & n > 0 then ( count := count + 1 ) else skip) ; execute (count)->display()); operation sum_of_num(target : OclAny, num : OclAny) : OclAny pre: true post: true activity: return (((2 * target) / num) - num + 1) / 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input_data=[int(string)for string in input().split()] kl=input_data[1]*input_data[2] cd=input_data[3]*input_data[4] tosts=kl//input_data[6] salt=input_data[5]//input_data[7] print(min(tosts,salt,cd)//input_data[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var input_data : Sequence := input().split()->select(string | true)->collect(string | (("" + ((string)))->toInteger())) ; var kl : double := input_data[1+1] * input_data[2+1] ; var cd : double := input_data[3+1] * input_data[4+1] ; var tosts : int := kl div input_data[6+1] ; var salt : int := input_data[5+1] div input_data[7+1] ; execute (Set{tosts, salt, cd}->min() div input_data->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import(division,absolute_import,print_function,unicode_literals) from sys import stdin from math import copysign def gradient(p): def fn(t): dx=p[0]-t[0] dy=p[1]-t[1] if dx : return dy/dx return copysign(float('inf'),-dy) return fn def solve(n): L=[] for i in range(n): L.append(tuple(float(s)for s in stdin.readline().split(','))) L.sort() p=p0=L.pop(0) while True : p=max((t for t in L if t[0]>=p[0]),key=gradient(p)) if p==L[-1]: break L.remove(p) p=p0 while True : p=min((t for t in L if t[0]>=p[0]),key=gradient(p)) if p==L[-1]: break L.remove(p) return len(L)-1 while True : n=int(stdin.readline()) if not n : break print(solve(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; while true do ( n := ("" + ((stdin.readLine())))->toInteger() ; if not(n) then ( break ) else skip ; execute (solve(n))->display()); operation gradient(p : OclAny) : OclAny pre: true post: true activity: skip ; return fn; operation solve(n : OclAny) : OclAny pre: true post: true activity: var L : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((((argument (test (logical_test (comparison (expr (atom (name float)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name stdin)) (trailer . (name readline) (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ','))))))) )))))))))) : L)) ; L := L->sort() ; p := L->at(0`firstArg+1); var p0 : OclAny := L->at(0`firstArg+1) ; while true do ( p := Set{Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name t)))))) (comp_for for (exprlist (expr (atom (name t)))) in (logical_test (comparison (expr (atom (name L))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name t)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) >= (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))))))}, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name gradient)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p)))))))) ))))))))}->max() ; if p = L->last() then ( break ) else skip ; execute ((p) /: L)) ; p := p0 ; while true do ( p := Set{Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name t)))))) (comp_for for (exprlist (expr (atom (name t)))) in (logical_test (comparison (expr (atom (name L))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name t)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) >= (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))))))}, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name gradient)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p)))))))) ))))))))}->min() ; if p = L->last() then ( break ) else skip ; execute ((p) /: L)) ; return (L)->size() - 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def op(x,y): return(complex.conjugate(x)*y).imag def isrm(q,i,x): for j in q : if op(i-x,j-x)<0 : return(False) return(True) def rightmost(p,x): for i in[i for i in p if i!=x]: q=p.copy() q.remove(i) if isrm(q,i,x): return(i) raise ValueError('Do not come here') def solve(p,pf,orig): nx=rightmost(p,orig) ni=p.index(nx) if pf[ni]: return(pf) pf[ni]=True return(solve(p,pf,nx)) while True : p=[] n=int(input().strip()) if n==0 : break for i in range(n): x,y=list(map(float,input().strip().split(','))) p.append(x+y*1j) print(solve(p,[False for _ in range(n)],2000.0+0.0*1j).count(False)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; while true do ( p := Sequence{} ; var n : int := ("" + ((input()->trim())))->toInteger() ; if n = 0 then ( break ) else skip ; for i : Integer.subrange(0, n-1) do ( Sequence{x,y} := ((input()->trim().split(','))->collect( _x | (OclType["double"])->apply(_x) )) ; execute ((x + y * 1j) : p)) ; execute (solve(p, Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (false)), 2000.0 + 0.0 * 1j)->count(false))->display()); operation op(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return (complex.conjugate(x) * y).imag; operation isrm(q : OclAny, i : OclAny, x : OclAny) : OclAny pre: true post: true activity: for j : q do ( if op(i - x, j - x) < 0 then ( return (false) ) else skip) ; return (true); operation rightmost(p : OclAny, x : OclAny) : OclAny pre: true post: true activity: for i : p->select(i | i /= x)->collect(i | (i)) do ( q := p->copy() ; execute ((i) /: q) ; if isrm(q, i, x) then ( return (i) ) else skip) ; error IncorrectElementException.newIncorrectElementException('Do not come here'); operation solve(p : OclAny, pf : OclAny, orig : OclAny) : OclAny pre: true post: true activity: var nx : OclAny := rightmost(p, orig) ; var ni : int := p->indexOf(nx) - 1 ; if pf[ni+1] then ( return (pf) ) else skip ; pf[ni+1] := true ; return (solve(p, pf, nx)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cross(a,b): return a.real*b.imag-a.imag*b.real def convex_hull(p): pp=sorted(p,key=lambda x :(x.imag,x.real)) n=len(pp) ans,j=[0]*(n+1),0 for i in range(n): while j>1 and cross(ans[j-1]-ans[j-2],pp[i]-ans[j-1])<0 : j-=1 ans[j]=pp[i] j+=1 k=j for i in range(n-2,-1,-1): while j>k and cross(ans[j-1]-ans[j-2],pp[i]-ans[j-1])<0 : j-=1 ans[j]=pp[i] j+=1 return ans[0 : j-1] while 1 : n=int(input()) if n==0 : break p=[] for i in range(n): x,y=list(map(float,input().split(','))) p.append(complex(x,y)) print(n-len(convex_hull(p))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while 1 do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; p := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split(','))->collect( _x | (OclType["double"])->apply(_x) )) ; execute ((complex(x, y)) : p)) ; execute (n - (convex_hull(p))->size())->display()); operation cross(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a.real * b.imag - a.imag * b.real; operation convex_hull(p : OclAny) : OclAny pre: true post: true activity: var pp : Sequence := p->sortedBy($x | (lambda x : OclAny in (Sequence{x.imag, x.real}))->apply($x)) ; var n : int := (pp)->size() ; var ans : OclAny := null; var j : OclAny := null; Sequence{ans,j} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)),0} ; for i : Integer.subrange(0, n-1) do ( while j > 1 & cross(ans[j - 1+1] - ans[j - 2+1], pp[i+1] - ans[j - 1+1]) < 0 do ( j := j - 1) ; ans[j+1] := pp[i+1] ; j := j + 1) ; var k : OclAny := j ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( while (j->compareTo(k)) > 0 & cross(ans[j - 1+1] - ans[j - 2+1], pp[i+1] - ans[j - 1+1]) < 0 do ( j := j - 1) ; ans[j+1] := pp[i+1] ; j := j + 1) ; return ans.subrange(0+1, j - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def canBeEqual(a,b,n): A=[] B=[] for i in range(n): if a[i]!=b[i]: A.append(a[i]) B.append(b[i]) if len(A)==len(B)==0 : return True if len(A)==len(B)==2 : if A[0]==A[1]and B[0]==B[1]: return True return False A='SEEKSFORGEEKS' B='GEEKSFORGEEKG' if(canBeEqual(A,B,len(A))): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; A := 'SEEKSFORGEEKS' ; B := 'GEEKSFORGEEKG' ; if (canBeEqual(A, B, (A)->size())) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation canBeEqual(a : OclAny, b : OclAny, n : OclAny) : OclAny pre: true post: true activity: var A : Sequence := Sequence{} ; var B : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if a[i+1] /= b[i+1] then ( execute ((a[i+1]) : A) ; execute ((b[i+1]) : B) ) else skip) ; if (A)->size() = (B)->size() & ((B)->size() == 0) then ( return true ) else skip ; if (A)->size() = (B)->size() & ((B)->size() == 2) then ( if A->first() = A[1+1] & B->first() = B[1+1] then ( return true ) else skip ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,m,s=map(int,input().split()) if not n : break n2=n**2 dpp=[0]*(s+1) dpp[0]=1 for i in range(1,n2+1): dpn=[0]*(s+1) for j in range(i*(i+1)//2,s+1): dpn[j]+=dpp[j-i]+dpn[j-i] if j-m-1>=0 : dpn[j]-=dpp[j-m-1] dpn[j]%=100000 dpp=dpn print(dpp[s]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var m : OclAny := null; var s : OclAny := null; Sequence{n,m,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if not(n) then ( break ) else skip ; var n2 : double := (n)->pow(2) ; var dpp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (s + 1)) ; dpp->first() := 1 ; for i : Integer.subrange(1, n2 + 1-1) do ( var dpn : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (s + 1)) ; for j : Integer.subrange(i * (i + 1) div 2, s + 1-1) do ( dpn[j+1] := dpn[j+1] + dpp[j - i+1] + dpn[j - i+1] ; if j - m - 1 >= 0 then ( dpn[j+1] := dpn[j+1] - dpp[j - m - 1+1] ) else skip ; dpn[j+1] := dpn[j+1] mod 100000) ; dpp := dpn) ; execute (dpp[s+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): while True : N,M,S=map(int,input().split()) if max(N,M,S)==0 : break ans=solve(N,M,S) print(ans) def solve(N,M,S): MOD=10**5 p=N*N q=M-p T=S-(p*(p+1))//2 dp=[[0 for i in range(T+1)]for j in range(p+1)] dp[0][0]=1 for i in range(1,p+1): for j in range(T+1): dp[i][j]=dp[i-1][j] if j-i>=0 : dp[i][j]+=dp[i][j-i] if j-i-q>=0 : dp[i][j]-=dp[i-1][j-i-q] dp[i][j]%=MOD ans=dp[p][T] return ans main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: while true do ( var N : OclAny := null; var M : OclAny := null; var S : OclAny := null; Sequence{N,M,S} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if Set{N, M, S}->max() = 0 then ( break ) else skip ; var ans : OclAny := solve(N, M, S) ; execute (ans)->display()); operation solve(N : OclAny, M : OclAny, S : OclAny) : OclAny pre: true post: true activity: var MOD : double := (10)->pow(5) ; var p : double := N * N ; var q : double := M - p ; var T : double := S - (p * (p + 1)) div 2 ; var dp : Sequence := Integer.subrange(0, p + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, T + 1-1)->select(i | true)->collect(i | (0)))) ; dp->first()->first() := 1 ; for i : Integer.subrange(1, p + 1-1) do ( for j : Integer.subrange(0, T + 1-1) do ( dp[i+1][j+1] := dp[i - 1+1][j+1] ; if j - i >= 0 then ( dp[i+1][j+1] := dp[i+1][j+1] + dp[i+1][j - i+1] ) else skip ; if j - i - q >= 0 then ( dp[i+1][j+1] := dp[i+1][j+1] - dp[i - 1+1][j - i - q+1] ) else skip ; dp[i+1][j+1] := dp[i+1][j+1] mod MOD)) ; ans := dp[p+1][T+1] ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline MOD=100000 def inpl(): return list(map(int,input().split())) while 1 : N,M,S=inpl() if N==0 : break N*=N dp=[[0]*(S+1)for _ in range(N+1)] dp[0][0]=1 for i in range(1,N+1): for j in range(S+1): if i<=j : dp[i][j]+=dp[i][j-i]+dp[i-1][j-i] if j-1>=M : dp[i][j]-=dp[i-1][j-1-M] dp[i][j]%=MOD print(dp[N][S]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var MOD : int := 100000 ; skip ; while 1 do ( var N : OclAny := null; var M : OclAny := null; var S : OclAny := null; Sequence{N,M,S} := inpl() ; if N = 0 then ( break ) else skip ; N := N * N ; var dp : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (S + 1)))) ; dp->first()->first() := 1 ; for i : Integer.subrange(1, N + 1-1) do ( for j : Integer.subrange(0, S + 1-1) do ( if (i->compareTo(j)) <= 0 then ( dp[i+1][j+1] := dp[i+1][j+1] + dp[i+1][j - i+1] + dp[i - 1+1][j - i+1] ) else skip ; if (j - 1->compareTo(M)) >= 0 then ( dp[i+1][j+1] := dp[i+1][j+1] - dp[i - 1+1][j - 1 - M+1] ) else skip ; dp[i+1][j+1] := dp[i+1][j+1] mod MOD)) ; execute (dp[N+1][S+1])->display()); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for e in iter(input,'0 0 0'): N,M,S=map(int,e.split()); N*=N d=[[0]*-~ S for _ in[0]*-~ N]; d[0][0]=1 for i in range(1,N+1): for j in range(i,S+1): d[i][j]+=d[i][j-i]+d[i-1][j-i]-(M+1<=j and d[i-1][j-M-1]) print(d[N][S]% 10**5) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for e : OclIterator.newOclIterator_Sequence(input, '0 0 0') do ( var N : OclAny := null; var M : OclAny := null; var S : OclAny := null; Sequence{N,M,S} := (e.split())->collect( _x | (OclType["int"])->apply(_x) ); N := N * N ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, -MathLib.bitwiseNot(N))->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, -MathLib.bitwiseNot(S)))); d->first()->first() := 1 ; for i : Integer.subrange(1, N + 1-1) do ( for j : Integer.subrange(i, S + 1-1) do ( d[i+1][j+1] := d[i+1][j+1] + d[i+1][j - i+1] + d[i - 1+1][j - i+1] - ((M + 1->compareTo(j)) <= 0 & d[i - 1+1][j - M - 1+1]))) ; execute (d[N+1][S+1] mod (10)->pow(5))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def listrep(n,m,s): tab=[[0]*(s+1)for j in range(n+1)] tab[0][0]=1 for i in range(1,n+1): for k in range(s+1): if i<=k : tab[i][k]+=tab[i][k-i]+tab[i-1][k-i] if k-1>=m : tab[i][k]-=tab[i-1][k-1-m] tab[i][k]%=100000 return tab[n][s] while True : n,m,s=map(int,input().split()) if n==0 : break n*=n print(listrep(n,m,s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( Sequence{n,m,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; n := n * n ; execute (listrep(n, m, s))->display()); operation listrep(n : OclAny, m : OclAny, s : OclAny) : OclAny pre: true post: true activity: var tab : Sequence := Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (MatrixLib.elementwiseMult(Sequence{ 0 }, (s + 1)))) ; tab->first()->first() := 1 ; for i : Integer.subrange(1, n + 1-1) do ( for k : Integer.subrange(0, s + 1-1) do ( if (i->compareTo(k)) <= 0 then ( tab[i+1][k+1] := tab[i+1][k+1] + tab[i+1][k - i+1] + tab[i - 1+1][k - i+1] ) else skip ; if (k - 1->compareTo(m)) >= 0 then ( tab[i+1][k+1] := tab[i+1][k+1] - tab[i - 1+1][k - 1 - m+1] ) else skip ; tab[i+1][k+1] := tab[i+1][k+1] mod 100000)) ; return tab[n+1][s+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CeilIndex(A,l,r,key): while(r-l>1): m=l+(r-l)//2 if(A[m]>=key): r=m else : l=m return r def LongestIncreasingSubsequenceLength(A,size): tailTable=[0 for i in range(size+1)] len=0 tailTable[0]=A[0] len=1 for i in range(1,size): if(A[i]tailTable[len-1]): tailTable[len]=A[i] len+=1 else : tailTable[CeilIndex(tailTable,-1,len-1,A[i])]=A[i] return len A=[2,5,3,7,11,8,10,13,6] n=len(A) print("Length of Longest Increasing Subsequence is ",LongestIncreasingSubsequenceLength(A,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; A := Sequence{2}->union(Sequence{5}->union(Sequence{3}->union(Sequence{7}->union(Sequence{11}->union(Sequence{8}->union(Sequence{10}->union(Sequence{13}->union(Sequence{ 6 })))))))) ; var n : int := (A)->size() ; execute ("Length of Longest Increasing Subsequence is ")->display(); operation CeilIndex(A : OclAny, l : OclAny, r : OclAny, key : OclAny) : OclAny pre: true post: true activity: while (r - l > 1) do ( var m : OclAny := l + (r - l) div 2 ; if ((A[m+1]->compareTo(key)) >= 0) then ( r := m ) else ( l := m )) ; return r; operation LongestIncreasingSubsequenceLength(A : OclAny, size : OclAny) : OclAny pre: true post: true activity: var tailTable : Sequence := Integer.subrange(0, size + 1-1)->select(i | true)->collect(i | (0)) ; var len : int := 0 ; tailTable->first() := A->first() ; len := 1 ; for i : Integer.subrange(1, size-1) do ( if ((A[i+1]->compareTo(tailTable->first())) < 0) then ( tailTable->first() := A[i+1] ) else (if ((A[i+1]->compareTo(tailTable[len - 1+1])) > 0) then ( tailTable[len+1] := A[i+1] ; len := len + 1 ) else ( tailTable[CeilIndex(tailTable, -1, len - 1, A[i+1])+1] := A[i+1] ) ) ) ; return len; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution : def runningSum(self,nums : List[int])->List[int]: if nums is None or len(nums)==0 : return nums for i in range(1,len(nums)): nums[i]+=nums[i-1] return nums ------------------------------------------------------------ OCL File: --------- class Solution { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation runningSum(nums : List[OclType["int"]+1]) : OclAny pre: true post: true activity: if nums <>= null or (nums)->size() = 0 then ( return nums ) else skip ; for i : Integer.subrange(1, (nums)->size()-1) do ( nums[i+1] := nums[i+1] + nums[i - 1+1]) ; return nums; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys d=0 for e in sys.stdin : c=list(map(int,e.split())) if len(c)>1 : s,t=c ; d=1 if s>t : a+=s+t elif scollect( _x | (OclType["int"])->apply(_x) )) ; if (c)->size() > 1 then ( var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := c; d := 1 ; if (s->compareTo(t)) > 0 then ( a := a + s + t ) else (if (s->compareTo(t)) < 0 then ( b := b + s + t ) else ( a := a + s; b := b + t ) ) ) else ( if d then ( execute (a)->display() ) else skip ; var a : OclAny := 0; var b : int := 0 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n,k,l,c,d,p,nl,np=map(int,sys.stdin.readline().split()) ans=min(k*l//(n*nl),c*d//n,p//(n*np)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; var l : OclAny := null; var c : OclAny := null; var d : OclAny := null; var p : OclAny := null; var nl : OclAny := null; var np : OclAny := null; Sequence{n,k,l,c,d,p,nl,np} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : OclAny := Set{k * l div (n * nl), c * d div n, p div (n * np)}->min() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): ans=sum(len(to_english(i))for i in range(1,1001)) return str(ans) def to_english(n): if 0<=n<20 : return ONES[n] elif 20<=n<100 : return TENS[n//10]+(ONES[n % 10]if(n % 10!=0)else "") elif 100<=n<1000 : return ONES[n//100]+"hundred"+(("and"+to_english(n % 100))if(n % 100!=0)else "") elif 1000<=n<1000000 : return to_english(n//1000)+"thousand"+(to_english(n % 1000)if(n % 1000!=0)else "") else : raise ValueError() ONES=["zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"] TENS=["","","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"] if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var ONES : Sequence := Sequence{"zero"}->union(Sequence{"one"}->union(Sequence{"two"}->union(Sequence{"three"}->union(Sequence{"four"}->union(Sequence{"five"}->union(Sequence{"six"}->union(Sequence{"seven"}->union(Sequence{"eight"}->union(Sequence{"nine"}->union(Sequence{"ten"}->union(Sequence{"eleven"}->union(Sequence{"twelve"}->union(Sequence{"thirteen"}->union(Sequence{"fourteen"}->union(Sequence{"fifteen"}->union(Sequence{"sixteen"}->union(Sequence{"seventeen"}->union(Sequence{"eighteen"}->union(Sequence{ "nineteen" }))))))))))))))))))) ; var TENS : Sequence := Sequence{""}->union(Sequence{""}->union(Sequence{"twenty"}->union(Sequence{"thirty"}->union(Sequence{"forty"}->union(Sequence{"fifty"}->union(Sequence{"sixty"}->union(Sequence{"seventy"}->union(Sequence{"eighty"}->union(Sequence{ "ninety" }))))))))) ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name to_english)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1001))))))))) )))))))))->sum() ; return ("" + ((ans))); operation to_english(n : OclAny) : OclAny pre: true post: true activity: if 0 <= n & (n < 20) then ( return ONES[n+1] ) else (if 20 <= n & (n < 100) then ( return TENS[n div 10+1] + (if (n mod 10 /= 0) then ONES[n mod 10+1] else "" endif) ) else (if 100 <= n & (n < 1000) then ( return ONES[n div 100+1] + "hundred" + (if (n mod 100 /= 0) then ("and" + to_english(n mod 100)) else "" endif) ) else (if 1000 <= n & (n < 1000000) then ( return to_english(n div 1000) + "thousand" + (if (n mod 1000 /= 0) then to_english(n mod 1000) else "" endif) ) else ( error IncorrectElementException.newIncorrectElementException() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) a.sort() ans=0 for i in range(n): if a[i]==i+1 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = i + 1 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) mx,c=0,0 for i in range(len(l)): mx=max(mx,l[i]) if(i+1==mx): c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mx : OclAny := null; var c : OclAny := null; Sequence{mx,c} := Sequence{0,0} ; for i : Integer.subrange(0, (l)->size()-1) do ( var mx : OclAny := Set{mx, l[i+1]}->max() ; if (i + 1 = mx) then ( c := c + 1 ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) w=list(map(int,input().split())) c,d=0,0 for i in range(1,n+1): d=max(w[i-1],d) if i==d and w[i-1]<=d : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := Sequence{0,0} ; for i : Integer.subrange(1, n + 1-1) do ( var d : OclAny := Set{w[i - 1+1], d}->max() ; if i = d & (w[i - 1+1]->compareTo(d)) <= 0 then ( c := c + 1 ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin n=int(stdin.readline()) a=list(map(int,stdin.readline().split())) m=0 i=1 count=0 for x in a : m=max(x,m) count+=(m==i) i+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + ((stdin.readLine())))->toInteger() ; var a : Sequence := ((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := 0 ; var i : int := 1 ; var count : int := 0 ; for x : a do ( m := Set{x, m}->max() ; count := count + (m = i) ; i := i + 1) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() n=int(input()) l=list(map(int,input().split())) c=0 for x in range(n): if max(l[: x+1])==x+1 : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; for x : Integer.subrange(0, n-1) do ( if (l.subrange(1,x + 1))->max() = x + 1 then ( c := c + 1 ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sqmake(n): if sq[n-1 : n]: pass else : sqmake(n-1) sq_n=[] for j in sq[n-1]: for k in range(len(j)): sq_n_i=j[:] sq_n_i[k]+=1 sq_n_i.sort(reverse=True) if sq_n_i in sq_n : pass else : sq_n.append(sq_n_i) sq_n_i=j[:] sq_n_i.append(1) sq_n.append(sq_n_i) sq_n.sort(reverse=True) sq.append(sq_n) sq=[[[0]],[[1]]] while 1 : n=int(input()) if n==0 : break sqmake(n) for i in sq[n]: print(' '.join(map(str,i))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var sq : Sequence := Sequence{Sequence{ Sequence{ 0 } }}->union(Sequence{ Sequence{ Sequence{ 1 } } }) ; while 1 do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; sqmake(n) ; for i : sq[n+1] do ( execute (StringLib.sumStringsWithSeparator(((i)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display())); operation sqmake(n : OclAny) pre: true post: true activity: if sq.subrange(n - 1+1, n) then ( skip ) else ( sqmake(n - 1) ) ; var sq_n : Sequence := Sequence{} ; for j : sq[n - 1+1] do ( for k : Integer.subrange(0, (j)->size()-1) do ( var sq_n_i : Sequence := j ; sq_n_i[k+1] := sq_n_i[k+1] + 1 ; sq_n_i := sq_n_i->sort() ; if (sq_n)->includes(sq_n_i) then ( skip ) else ( execute ((sq_n_i) : sq_n) ))) ; sq_n_i := j ; execute ((1) : sq_n_i) ; execute ((sq_n_i) : sq_n) ; sq_n := sq_n->sort() ; execute ((sq_n) : sq); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) X=list(map(int,input().split())) Xmn,Xmx=min(X),max(X) temp=[] res=Xmx-Xmn for x in range(Xmn,Xmx+1): for n in range(N): temp.append(abs(X[n]-x)) if max(temp)toInteger() ; var X : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var Xmn : OclAny := null; var Xmx : OclAny := null; Sequence{Xmn,Xmx} := Sequence{(X)->min(),(X)->max()} ; var temp : Sequence := Sequence{} ; var res : double := Xmx - Xmn ; for x : Integer.subrange(Xmn, Xmx + 1-1) do ( for n : Integer.subrange(0, N-1) do ( execute (((X[n+1] - x)->abs()) : temp)) ; if ((temp)->max()->compareTo(res)) < 0 then ( res := (temp)->max() ) else skip ; temp := Sequence{}) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): ans=[] def square(n,rest,limit): if rest==0 : print(*ans) else : for i in range(rest,0,-1): if i>limit : continue ans.append(i) square(n,rest-i,i) ans.pop() import sys for n in map(int,sys.stdin.readlines()): if n==0 : break square(n,n,n) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: var ans : Sequence := Sequence{} ; skip ; skip ; for n : ((OclFile["System.in"]).readlines())->collect( _x | (OclType["int"])->apply(_x) ) do ( if n = 0 then ( break ) else skip ; square(n, n, n)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dfs(s,com): if s==0 : ans.append(" ".join(map(str,com))) return for i in xrange(s,0,-1): if len(com)>0 and com[-1]toInteger() ; if n = 0 then ( break ) else skip ; var ans : Sequence := Sequence{} ; com := Sequence{} ; ans := dfs(n, com) ; for i : xrange((ans)->size()) do ( execute (ans[i+1])->display())); operation dfs(s : OclAny, com : OclAny) : OclAny pre: true post: true activity: if s = 0 then ( execute ((StringLib.sumStringsWithSeparator(((com)->collect( _x | (OclType["String"])->apply(_x) )), " ")) : ans) ; return ) else skip ; for i : xrange(s, 0, -1) do ( if (com)->size() > 0 & (com->last()->compareTo(i)) < 0 then ( continue ) else skip ; execute ((i) : com) ; dfs(s - i, com) ; execute (com->last())->isDeleted()) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def solve(n,a=0): result=[] in_progress=[[[],n]] while in_progress : arr,rem=in_progress.pop() ub=min(arr[-1]if arr else rem,rem) for i in range(ub,0,-1): if rem-i==0 : result.append(arr+[i]) else : in_progress.append([arr+[i],rem-i]) return sorted(result,reverse=True) def main(args): while True : n=int(input()) if n==0 : break ans=solve(n) for row in ans : print(*row,sep=' ') if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(n : OclAny, a : int) : OclAny pre: true post: true activity: if a->oclIsUndefined() then a := 0 else skip; var result : Sequence := Sequence{} ; var in_progress : Sequence := Sequence{ Sequence{Sequence{}}->union(Sequence{ n }) } ; while in_progress do ( var arr : OclAny := null; var rem : OclAny := null; Sequence{arr,rem} := in_progress->last() ; in_progress := in_progress->front() ; var ub : OclAny := Set{if arr then arr->last() else rem endif, rem}->min() ; for i : Integer.subrange(0 + 1, ub)->reverse() do ( if rem - i = 0 then ( execute ((arr->union(Sequence{ i })) : result) ) else ( execute ((Sequence{arr->union(Sequence{ i })}->union(Sequence{ rem - i })) : in_progress) ))) ; return result->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))); operation main(args : OclAny) pre: true post: true activity: while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var ans : OclAny := solve(n) ; for row : ans do ( execute ((argument * (test (logical_test (comparison (expr (atom (name row))))))))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def canMake(s): o=0 ; z=0 ; for i in range(len(s)): if(ord(s[i])-ord('0')==1): o+=1 ; else : z+=1 ; if(o % 2==1 and z % 2==1): return "NO" ; else : return "YES" ; if __name__=="__main__" : s="01011" ; print(canMake(s)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "01011"; ; execute (canMake(s))->display(); ) else skip; operation canMake(s : OclAny) pre: true post: true activity: var o : int := 0; var z : int := 0; ; for i : Integer.subrange(0, (s)->size()-1) do ( if ((s[i+1])->char2byte() - ('0')->char2byte() = 1) then ( o := o + 1; ) else ( z := z + 1; )) ; if (o mod 2 = 1 & z mod 2 = 1) then ( return "NO"; ) else ( return "YES"; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if not n : break results={(n,)} for i in range(1,n): right_list=list((k,)for k in range(1,n//(i+1)+1)) for j in range(i-1): next_list=[] for right in right_list : for k in range(right[0],(n-sum(right))//(i-j)+1): next_list.append((k,)+right) right_list=next_list for right in right_list : results.add((n-sum(right),)+right) for result in sorted(results,reverse=True): print(*result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(n) then ( break ) else skip ; var results : Set := Set{ Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name n)))))) ,)} } ; for i : Integer.subrange(1, n-1) do ( var right_list : Sequence := ((argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name k)))))) ,) )))))) (comp_for for (exprlist (expr (atom (name k)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (expr (atom (name n))) // (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) )))) + (expr (atom (number (integer 1)))))))))) ))))))))) ; for j : Integer.subrange(0, i - 1-1) do ( var next_list : Sequence := Sequence{} ; for right : right_list do ( for k : Integer.subrange(right->first(), (n - (right)->sum()) div (i - j) + 1-1) do ( execute ((Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name k)))))) ,)} + right) : next_list))) ; right_list := next_list) ; for right : right_list do ( execute ((Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name right)))))))) )))))))) ,)} + right) : results))) ; for result : results->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name result))))))))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=input a=[int(m().split()[1])for _ in[0]*int(m())] k=int(m()) print(sum(x>=k for x in a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := input ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + ((m())))->toInteger())->select(_anon | true)->collect(_anon | (("" + ((m().split()[1+1])))->toInteger())) ; var k : int := ("" + ((m())))->toInteger() ; execute (((argument (test (logical_test (comparison (comparison (expr (atom (name x)))) >= (comparison (expr (atom (name k))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=[] for i in range(a): c,d=map(int,input().split()) b.append([c,d]) d=int(input()) ans=0 for i in b : if d<=i[1]: ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := Sequence{} ; for i : Integer.subrange(0, a-1) do ( var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{c}->union(Sequence{ d })) : b)) ; var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; for i : b do ( if (d->compareTo(i[1+1])) <= 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- no_of_chapters=int(input()) ls=[] while no_of_chapters>0 : no_of_chapters-=1 ls.append(int(input().split()[1])) k=int(input()) for index,value in enumerate(ls): if k<=value : print(len(ls)-index) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var no_of_chapters : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ls : Sequence := Sequence{} ; while no_of_chapters > 0 do ( no_of_chapters := no_of_chapters - 1 ; execute ((("" + ((input().split()[1+1])))->toInteger()) : ls)) ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _tuple : Integer.subrange(1, (ls)->size())->collect( _indx | Sequence{_indx-1, (ls)->at(_indx)} ) do (var _indx : int := 1; var index : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); if (k->compareTo(value)) <= 0 then ( execute ((ls)->size() - index)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import heapq import bisect def solution(): n=int(input()) chapEnds=[] for i in range(n): l,r=input().split(" ") chapEnds.append(int(r)) k=int(input()) print(n-bisect.bisect_left(chapEnds,k)) solution() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; solution(); operation solution() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var chapEnds : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := input().split(" ") ; execute ((("" + ((r)))->toInteger()) : chapEnds)) ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n - bisect.bisect_left(chapEnds, k))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=input a=[int(m().split()[1])for _ in[0]*int(m())] k=int(m()) print(sum(x>=k for x in a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := input ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + ((m())))->toInteger())->select(_anon | true)->collect(_anon | (("" + ((m().split()[1+1])))->toInteger())) ; var k : int := ("" + ((m())))->toInteger() ; execute (((argument (test (logical_test (comparison (comparison (expr (atom (name x)))) >= (comparison (expr (atom (name k))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=10**6+1 mod=10**9+7 inv_l=[0,1] for i in range(2,N): inv_l+=[inv_l[mod % i]*(mod-int(mod/i))% mod] prime_list=[] min_prime=[1]*(N+1) is_prime=[0,0]+[1]*(N-1) for i in range(2,N+1): if is_prime[i]==1 : prime_list.append(i) j=i while j<=N : is_prime[j]=0 if min_prime[j]==1 : min_prime[j]=i j+=i def lcm(l,mod): max_count=[0]*(N+1) for a in l : a_min_prime=min_prime[a] a_count=0 while a>1 : if min_prime[a]==a_min_prime : a_count+=1 a//=a_min_prime else : max_count[a_min_prime]=max(max_count[a_min_prime],a_count) a_min_prime=min_prime[a] a//=a_min_prime a_count=1 if a==1 : max_count[a_min_prime]=max(max_count[a_min_prime],a_count) ret=1 for i in range(1,N+1): if max_count[i]!=0 : ret=(ret*i**max_count[i])% mod return ret n=int(input()) A=list(map(int,input().split())) L=lcm(A,mod) ans=0 for i in range(n): ans=(ans+L*inv_l[A[i]])% mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : double := (10)->pow(6) + 1 ; var mod : double := (10)->pow(9) + 7 ; var inv_l : Sequence := Sequence{0}->union(Sequence{ 1 }) ; for i : Integer.subrange(2, N-1) do ( inv_l := inv_l + Sequence{ inv_l[mod mod i+1] * (mod - ("" + ((mod / i)))->toInteger()) mod mod }) ; var prime_list : Sequence := Sequence{} ; var min_prime : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (N + 1)) ; var is_prime : Sequence := Sequence{0}->union(Sequence{ 0 })->union(MatrixLib.elementwiseMult(Sequence{ 1 }, (N - 1))) ; for i : Integer.subrange(2, N + 1-1) do ( if is_prime[i+1] = 1 then ( execute ((i) : prime_list) ; var j : OclAny := i ; while (j->compareTo(N)) <= 0 do ( is_prime[j+1] := 0 ; if min_prime[j+1] = 1 then ( min_prime[j+1] := i ) else skip ; j := j + i) ) else skip) ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var L : OclAny := lcm(A, mod) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( ans := (ans + L * inv_l[A[i+1]+1]) mod mod) ; execute (ans)->display(); operation lcm(l : OclAny, mod : OclAny) : OclAny pre: true post: true activity: var max_count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; for a : l do ( var a_min_prime : OclAny := min_prime[a+1] ; var a_count : int := 0 ; while a > 1 do ( if min_prime[a+1] = a_min_prime then ( a_count := a_count + 1 ; a := a div a_min_prime ) else ( max_count[a_min_prime+1] := Set{max_count[a_min_prime+1], a_count}->max() ; a_min_prime := min_prime[a+1] ; a := a div a_min_prime ; a_count := 1 ) ; if a = 1 then ( max_count[a_min_prime+1] := Set{max_count[a_min_prime+1], a_count}->max() ) else skip)) ; var ret : int := 1 ; for i : Integer.subrange(1, N + 1-1) do ( if max_count[i+1] /= 0 then ( ret := (ret * (i)->pow(max_count[i+1])) mod mod ) else skip) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def allBitsSetInTheGivenRange(n,l,r): num=((1<display() ) else ( execute ("No")->display() ) ) else skip; operation allBitsSetInTheGivenRange(n : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var num : int := MathLib.bitwiseXor(((1 * (2->pow(r))) - 1), ((1 * (2->pow((l - 1)))) - 1)) ; var new_num : int := MathLib.bitwiseAnd(n, num) ; if (num = new_num) then ( return true ) else skip ; return false; operation bitsAreComplement(a : OclAny, b : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var xor_value : int := MathLib.bitwiseXor(a, b) ; return allBitsSetInTheGivenRange(xor_value, l, r); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- X=int(input()) print(['No','Yes'][X>=30]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var X : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (Sequence{'No'}->union(Sequence{ 'Yes' })->select(X >= 30))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal import functools def v(): return input() def k(): return int(input()) def S(): return input().split() def I(): return map(int,input().split()) def X(): return list(input()) def L(): return list(input().split()) def l(): return list(map(int,input().split())) def lcm(a,b): return a*b//math.gcd(a,b) sys.setrecursionlimit(10**9) mod=10**9+7 cnt=0 ans=0 inf=float("inf") x=k() print("Yes" if x>=30 else "No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var mod : double := (10)->pow(9) + 7 ; var cnt : int := 0 ; var ans : int := 0 ; var Math_PINFINITY : double := ("" + (("inf")))->toReal() ; var x : OclAny := k() ; execute (if x >= 30 then "Yes" else "No" endif)->display(); operation v() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation k() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation S() : OclAny pre: true post: true activity: return input().split(); operation I() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation X() : OclAny pre: true post: true activity: return ((OclFile["System.in"]).readLine())->characters(); operation L() : OclAny pre: true post: true activity: return (input().split()); operation l() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a * b div (a)->gcd(b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import os def int_array(): return list(map(int,input().strip().split())) def str_array(): return input().strip().split() def gcd(a,b): if b==0 : return a return gcd(b,a % b); x def take_input(): if os.environ.get("check"): sys.stdin=open('input.txt','r') sys.stdout=open('output.txt','w') take_input() n=int(input()) if n>=30 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; take_input() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n >= 30 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation int_array() : OclAny pre: true post: true activity: return ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation str_array() : OclAny pre: true post: true activity: return input()->trim().split(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if b = 0 then ( return a ) else skip ; return gcd(b, a mod b);; operation take_input() pre: true post: true activity: if os.environ.get("check") then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('input.txt')) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile('output.txt')) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printNthElement(n): arr=[0]*(n+1); arr[1]=1 arr[2]=2 for i in range(3,n+1): if(i % 2!=0): arr[i]=arr[i//2]*10+1 else : arr[i]=arr[(i//2)-1]*10+2 return arr[n] n=5 print(printNthElement(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; execute (printNthElement(n))->display(); operation printNthElement(n : OclAny) : OclAny pre: true post: true activity: var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); ; arr[1+1] := 1 ; arr[2+1] := 2 ; for i : Integer.subrange(3, n + 1-1) do ( if (i mod 2 /= 0) then ( arr[i+1] := arr[i div 2+1] * 10 + 1 ) else ( arr[i+1] := arr[(i div 2) - 1+1] * 10 + 2 )) ; return arr[n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import itertools import queue import bisect from collections import deque,defaultdict import heapq as hpq from sys import stdin,setrecursionlimit ipt=stdin.readline setrecursionlimit(10**7) mod=10**9+7 alp="abcdefghijklmnopqrstuvwxyz" def main(): x=int(ipt()) if x>=30 : print("Yes") else : print("No") return None if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var ipt : OclAny := stdin.readline ; setrecursionlimit((10)->pow(7)) ; var mod : double := (10)->pow(9) + 7 ; var alp : String := "abcdefghijklmnopqrstuvwxyz" ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() : OclAny pre: true post: true activity: var x : int := ("" + ((ipt())))->toInteger() ; if x >= 30 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ; return null; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print('Yes' if int(input())>=30 else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (if ("" + (((OclFile["System.in"]).readLine())))->toInteger() >= 30 then 'Yes' else 'No' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def makePermutation(a,n): count=dict() for i in range(n): if count.get(a[i]): count[a[i]]+=1 else : count[a[i]]=1 ; next_missing=1 for i in range(n): if count[a[i]]!=1 or a[i]>n or a[i]<1 : count[a[i]]-=1 while count.get(next_missing): next_missing+=1 a[i]=next_missing count[next_missing]=1 A=[2,2,3,3] n=len(A) makePermutation(A,n) for i in range(n): print(A[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var A : Sequence := Sequence{2}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 3 }))) ; n := (A)->size() ; makePermutation(A, n) ; for i : Integer.subrange(0, n-1) do ( execute (A[i+1])->display()); operation makePermutation(a : OclAny, n : OclAny) pre: true post: true activity: var count : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( if count.get(a[i+1]) then ( count[a[i+1]+1] := count[a[i+1]+1] + 1 ) else ( count[a[i+1]+1] := 1; )) ; var next_missing : int := 1 ; for i : Integer.subrange(0, n-1) do ( if count[a[i+1]+1] /= 1 or (a[i+1]->compareTo(n)) > 0 or a[i+1] < 1 then ( count[a[i+1]+1] := count[a[i+1]+1] - 1 ; while count.get(next_missing) do ( next_missing := next_missing + 1) ; a[i+1] := next_missing ; count[next_missing+1] := 1 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def kFactors(n,k): a=list() while n % 2==0 : a.append(2) n=n//2 for i in range(3,mt.ceil(mt.sqrt(n)),2): while n % i==0 : n=n/i ; a.append(i) if n>2 : a.append(n) if len(a)select( $x | ($x - 3) mod 2 = 0 ) do ( while n mod i = 0 do ( n := n / i; ; execute ((i) : a))) ; if n > 2 then ( execute ((n) : a) ) else skip ; if ((a)->size()->compareTo(k)) < 0 then ( execute ("-1")->display() ; return ) else skip ; for i : Integer.subrange(0, k - 1-1) do ( execute (a[i+1])->display()) ; var product : int := 1 ; for i : Integer.subrange(k - 1, (a)->size()-1) do ( product := product * a[i+1]) ; execute (product)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- z,n,m=[int(x)for x in input().split()] adj=[] vis=[] for i in range(15): adj.append([]) vis.append([]) for j in range(15): adj[i].append([""]*15) vis[i].append([False]*15) for i in range(1,z+1): input() for j in range(1,n+1): c=list(input()) for l in range(1,len(c)+1): adj[i][j][l]=c[l-1] input() x,y=[int(e)for e in input().split()] def dfs(l,x,y,z): if(x>0 and y>0 and l>0 and l<=z and x<=n and y<=m and not vis[l][x][y]): if(adj[l][x][y]=='#'): return vis[l][x][y]=True dfs(l+1,x,y,z) dfs(l-1,x,y,z) dfs(l,x+1,y,z) dfs(l,x-1,y,z) dfs(l,x,y+1,z) dfs(l,x,y-1,z) dfs(1,x,y,z) out=0 for i in range(1,z+1): for j in range(1,n+1): for l in range(1,m+1): if(vis[i][j][l]): out+=1 print(out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var z : OclAny := null; var n : OclAny := null; var m : OclAny := null; Sequence{z,n,m} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var adj : Sequence := Sequence{} ; var vis : Sequence := Sequence{} ; for i : Integer.subrange(0, 15-1) do ( execute ((Sequence{}) : adj) ; execute ((Sequence{}) : vis) ; for j : Integer.subrange(0, 15-1) do ((expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom "")))))) ])) * (expr (atom (number (integer 15)))))))))) )))) ; (expr (atom (name vis)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name False))))))) ])) * (expr (atom (number (integer 15)))))))))) )))))) ; for i : Integer.subrange(1, z + 1-1) do ( input() ; for j : Integer.subrange(1, n + 1-1) do ( var c : Sequence := ((OclFile["System.in"]).readLine())->characters() ; for l : Integer.subrange(1, (c)->size() + 1-1) do ( adj[i+1][j+1][l+1] := c[l - 1+1]))) ; input() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := input().split()->select(e | true)->collect(e | (("" + ((e)))->toInteger())) ; skip ; dfs(1, x, y, z) ; var out : int := 0 ; for i : Integer.subrange(1, z + 1-1) do ( for j : Integer.subrange(1, n + 1-1) do ( for l : Integer.subrange(1, m + 1-1) do ( if (vis[i+1][j+1][l+1]) then ( out := out + 1 ) else skip))) ; execute (out)->display(); operation dfs(l : OclAny, x : OclAny, y : OclAny, z : OclAny) pre: true post: true activity: if (x > 0 & y > 0 & l > 0 & (l->compareTo(z)) <= 0 & (x->compareTo(n)) <= 0 & (y->compareTo(m)) <= 0 & not(vis[l+1][x+1][y+1])) then ( if (adj[l+1][x+1][y+1] = '#') then ( return ) else skip ; vis[l+1][x+1][y+1] := true ; dfs(l + 1, x, y, z) ; dfs(l - 1, x, y, z) ; dfs(l, x + 1, y, z) ; dfs(l, x - 1, y, z) ; dfs(l, x, y + 1, z) ; dfs(l, x, y - 1, z) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math h=int(input()) p=list(map(int,input().split())) print(math.ceil((max(p)-min(p))/2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var h : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((((p)->max() - (p)->min()) / 2)->ceil())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[] b=list(map(int,input().split())) input() for i in range(b[0]): a.append([]) for j in range(b[1]): a[i].append([]) for z in input(): a[i][j].append(z) input() x,y=map(int,input().split()); x-=1 ; y-=1 ans=[0] def wv(k,x,y): if(k<0)or(k==b[0])or(x<0)or(x==b[1])or(y<0)or(y==b[2])or(a[k][x][y]=='#'): return ans[0]+=1 a[k][x][y]='#' wv(k-1,x,y) wv(k+1,x,y) wv(k,x-1,y) wv(k,x+1,y) wv(k,x,y-1) wv(k,x,y+1) wv(0,x,y) print(ans[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Sequence{} ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; input() ; for i : Integer.subrange(0, b->first()-1) do ( execute ((Sequence{}) : a) ; for j : Integer.subrange(0, b[1+1]-1) do ((expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ ]))))))) )))) ; for z : (OclFile["System.in"]).readLine() do ((expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name z)))))))) )))))) ; input()) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); x := x - 1; y := y - 1 ; var ans : Sequence := Sequence{ 0 } ; skip ; wv(0, x, y) ; execute (ans->first())->display(); operation wv(k : OclAny, x : OclAny, y : OclAny) pre: true post: true activity: if (k < 0) or (k = b->first()) or (x < 0) or (x = b[1+1]) or (y < 0) or (y = b[2+1]) or (a[k+1][x+1][y+1] = '#') then ( return ) else skip ; ans->first() := ans->first() + 1 ; a[k+1][x+1][y+1] := '#' ; wv(k - 1, x, y) ; wv(k + 1, x, y) ; wv(k, x - 1, y) ; wv(k, x + 1, y) ; wv(k, x, y - 1) ; wv(k, x, y + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[] b=list(map(int,input().split())) input() for i in range(b[0]): a.append([]) for j in range(b[1]): a[i].append([]) for z in input(): a[i][j].append(z) input() x,y=map(int,input().split()); x-=1 ; y-=1 ans=[0] def wv(k,x,y): if(k<0)or(k==b[0])or(x<0)or(x==b[1])or(y<0)or(y==b[2])or(a[k][x][y]=='#'): return ans[0]+=1 a[k][x][y]='#' wv(k-1,x,y) wv(k+1,x,y) wv(k,x-1,y) wv(k,x+1,y) wv(k,x,y-1) wv(k,x,y+1) wv(0,x,y) print(ans[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Sequence{} ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; input() ; for i : Integer.subrange(0, b->first()-1) do ( execute ((Sequence{}) : a) ; for j : Integer.subrange(0, b[1+1]-1) do ((expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ ]))))))) )))) ; for z : (OclFile["System.in"]).readLine() do ((expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name z)))))))) )))))) ; input()) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); x := x - 1; y := y - 1 ; var ans : Sequence := Sequence{ 0 } ; skip ; wv(0, x, y) ; execute (ans->first())->display(); operation wv(k : OclAny, x : OclAny, y : OclAny) pre: true post: true activity: if (k < 0) or (k = b->first()) or (x < 0) or (x = b[1+1]) or (y < 0) or (y = b[2+1]) or (a[k+1][x+1][y+1] = '#') then ( return ) else skip ; ans->first() := ans->first() + 1 ; a[k+1][x+1][y+1] := '#' ; wv(k - 1, x, y) ; wv(k + 1, x, y) ; wv(k, x - 1, y) ; wv(k, x + 1, y) ; wv(k, x, y - 1) ; wv(k, x, y + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque k,n,m=map(int,input().split()) graph=defaultdict(set) input() empty=set() for i in range(k): for j in range(n): for l,c in enumerate(input()): if c!='.' : continue empty.add((i,j,l)) for x1,x2,x3 in[(i-1,j,l),(i,j-1,l),(i,j,l-1)]: if x1>=0 and x2>=0 and x3>=0 and(x1,x2,x3)in empty : graph[(x1,x2,x3)].add((i,j,l)) graph[(i,j,l)].add((x1,x2,x3)) input() x,y=map(int,input().split()) x-=1 y-=1 queue=deque([(0,x,y)]) visited=set([(0,x,y)]) while queue : q=queue.pop() for nbr in graph[q]: if nbr not in visited : visited.add(nbr) queue.append(nbr) print(len(visited)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var k : OclAny := null; var n : OclAny := null; var m : OclAny := null; Sequence{k,n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var graph : OclAny := defaultdict(OclType["Set"]) ; input() ; var empty : Set := Set{}->union(()) ; for i : Integer.subrange(0, k-1) do ( for j : Integer.subrange(0, n-1) do ( for _tuple : Integer.subrange(1, ((OclFile["System.in"]).readLine())->size())->collect( _indx | Sequence{_indx-1, ((OclFile["System.in"]).readLine())->at(_indx)} ) do (var _indx : int := 1; var l : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if c /= '.' then ( continue ) else skip ; execute ((Sequence{i, j, l}) : empty) ; for _tuple : Sequence{Sequence{i - 1, j, l}}->union(Sequence{Sequence{i, j - 1, l}}->union(Sequence{ Sequence{i, j, l - 1} })) do (var _indx : int := 1; var x1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x2 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x3 : OclAny := _tuple->at(_indx); if x1 >= 0 & x2 >= 0 & x3 >= 0 & (empty)->includes(Sequence{x1, x2, x3}) then ( (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name x1)))))) , (test (logical_test (comparison (expr (atom (name x2)))))) , (test (logical_test (comparison (expr (atom (name x3))))))) )))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) , (test (logical_test (comparison (expr (atom (name j)))))) , (test (logical_test (comparison (expr (atom (name l))))))) )))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) , (test (logical_test (comparison (expr (atom (name j)))))) , (test (logical_test (comparison (expr (atom (name l))))))) )))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name x1)))))) , (test (logical_test (comparison (expr (atom (name x2)))))) , (test (logical_test (comparison (expr (atom (name x3))))))) )))))))) )))) ) else skip))) ; input()) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; x := x - 1 ; y := y - 1 ; var queue : Sequence := (Sequence{ Sequence{0, x, y} }) ; var visited : Set := Set{}->union((Sequence{ Sequence{0, x, y} })) ; while queue do ( var q : OclAny := queue->last() ; queue := queue->front() ; for nbr : graph[q+1] do ( if (visited)->excludes(nbr) then ( execute ((nbr) : visited) ; execute ((nbr) : queue) ) else skip)) ; execute ((visited)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin import numpy as np def main(): readline=stdin.readline n,k=map(int,readline().split()) A=np.array(list(map(int,readline().split())),dtype=np.int64) A=np.sort(A)[: :-1] F=np.array(list(map(int,readline().split())),dtype=np.int64) F=np.sort(F) l=-1 r=10**12 while lcollect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := (((readline().split())->collect( _x | (OclType["int"])->apply(_x) )), (argument (test (logical_test (comparison (expr (atom (name dtype)))))) = (test (logical_test (comparison (expr (atom (name np)) (trailer . (name int64)))))))) ; A := np->sort()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var F : Sequence := (((readline().split())->collect( _x | (OclType["int"])->apply(_x) )), (argument (test (logical_test (comparison (expr (atom (name dtype)))))) = (test (logical_test (comparison (expr (atom (name np)) (trailer . (name int64)))))))) ; F := ; var l : int := -1 ; var r : double := (10)->pow(12) ; while (l->compareTo(r - 1)) < 0 do ( var x : int := (l + r) div 2 ; var A_after : (trailer . (name minimum) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) // (expr (atom (name F)))))))) , (argument (test (logical_test (comparison (expr (atom (name A)))))))) ))) := ; var cnt : OclAny := (A - A_after).sum() ; if (cnt->compareTo(k)) <= 0 then ( r := x ) else ( l := x )) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math N,K=map(int,input().split()) X=[(b,a*b)for a,b in zip(sorted(list(map(int,input().split()))),sorted(list(map(int,input().split())))[: :-1])] m,M,i=0,10**12,1 exec("i,M,m=((i+m)//2,i,m)if sum(math.ceil(max(0,c-i)/b)for b,c in X)<=K else((i+M)//2,M,i);"*50) print(M) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var X : Sequence := Integer.subrange(1, ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort()->size())->collect( _indx | Sequence{((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort()->at(_indx), sorted(((input().split())->collect( _x | (OclType["int"])->apply(_x) )))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->at(_indx)} )->select(_tuple | true)->collect(_tuple | let a : OclAny = _tuple->at(1) in let b : OclAny = _tuple->at(2) in (Sequence{b, a * b})) ; var m : OclAny := null; var M : OclAny := null; var i : OclAny := null; Sequence{m,M,i} := Sequence{0,(10)->pow(12),1} ; (expr (expr (atom "i,M,m=((i+m)//2,i,m)if sum(math.ceil(max(0,c-i)/b)for b,c in X)<=K else((i+M)//2,M,i);")) * (expr (atom (number (integer 50))))) ; execute (M)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printNthElement(n): arr=[0]*(n+1); arr[1]=4 arr[2]=7 for i in range(3,n+1): if(i % 2!=0): arr[i]=arr[i//2]*10+4 else : arr[i]=arr[(i//2)-1]*10+7 return arr[n] n=6 print(printNthElement(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 6 ; execute (printNthElement(n))->display(); operation printNthElement(n : OclAny) : OclAny pre: true post: true activity: var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); ; arr[1+1] := 4 ; arr[2+1] := 7 ; for i : Integer.subrange(3, n + 1-1) do ( if (i mod 2 /= 0) then ( arr[i+1] := arr[i div 2+1] * 10 + 4 ) else ( arr[i+1] := arr[(i div 2) - 1+1] * 10 + 7 )) ; return arr[n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(1000000000) ii=lambda : int(input()) ii0=lambda : ii()-1 mis=lambda : map(int,input().split()) lmis=lambda : list(mis()) INF=float('inf') def main(): N,K=mis() A=lmis() A.sort(reverse=True) F=lmis() F.sort() class solver : def __getitem__(self,score_limit): k=K for i in range(N): if A[i]*F[i]>score_limit : k-=A[i]-score_limit//F[i] if k<0 : return False return True import bisect print(bisect.bisect_left(solver(),True,hi=A[0]*F[-1])) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(1000000000) ; var ii : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var ii0 : Function := lambda $$ : OclAny in (ii->apply() - 1) ; var mis : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lmis : Function := lambda $$ : OclAny in ((mis->apply())) ; var INF : double := ("" + (('inf')))->toReal() ; skip ; main(); operation main() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := mis->apply() ; var A : OclAny := lmis->apply() ; A := A->sort() ; var F : OclAny := lmis->apply() ; F := F->sort() ; skip ; skip ; execute (bisect.bisect_left((solver.newsolver()).initialise(), true, (argument (test (logical_test (comparison (expr (atom (name hi)))))) = (test (logical_test (comparison (expr (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) * (expr (atom (name F)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(x,A,F): result=0 for i in range(N): t=x//F[i] if tcollect( _x | (OclType["int"])->apply(_x) ) ; A := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; F := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; A := A->sort() ; F := F->sort() ; var lo : int := 0 ; var hi : double := A->last() * F->first() ; while (lo->compareTo(hi)) < 0 do ( var mid : int := (lo + hi) div 2 ; if K - f(mid, A, F) < 0 then ( lo := mid + 1 ) else ( hi := mid )) ; execute (lo)->display(); operation f(x : OclAny, A : OclAny, F : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; for i : Integer.subrange(0, N-1) do ( var t : int := x div F[i+1] ; if (t->compareTo(A[i+1])) < 0 then ( result := result + A[i+1] - t ) else skip) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(1000000) from heapq import heappush,heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations from itertools import product mod=10**9+7 inf=float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) def f_x(x): s=0 for A,F in zip(a,f): s+=max(0,A-x//F) if s<=k : return True return False n,k=LI() a=LI() f=LI() a.sort() f.sort(reverse=True) ok,ng=10**12,-1 while ok-ng>1 : mid=(ok+ng)//2 if f_x(mid): ok=mid else : ng=mid print(ok) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; sys.setrecursionlimit(1000000) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; skip ; skip ; skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := LI() ; var a : OclAny := LI() ; var f : OclAny := LI() ; a := a->sort() ; f := f->sort() ; var ok : OclAny := null; var ng : OclAny := null; Sequence{ok,ng} := Sequence{(10)->pow(12),-1} ; while ok - ng > 1 do ( var mid : int := (ok + ng) div 2 ; if f_x(mid) then ( var ok : int := mid ) else ( var ng : int := mid )) ; execute (ok)->display(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation f_x(x : OclAny) : OclAny pre: true post: true activity: var s : int := 0 ; for _tuple : Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), f->at(_indx)} ) do (var _indx : int := 1; var A : OclAny := _tuple->at(_indx); _indx := _indx + 1; var F : OclAny := _tuple->at(_indx); s := s + Set{0, A - x div F}->max()) ; if (s->compareTo(k)) <= 0 then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=100000 def createHash(hash,maxElement): prev=0 curr=1 hash.add(prev) hash.add(curr) while(curr<=maxElement): temp=curr+prev hash.add(temp) prev=curr curr=temp def longestFibSubarray(arr,n): max_val=max(arr) hash={int} createHash(hash,max_val) left=[0 for i in range(n)] right=[0 for i in range(n)] fibcount=0 res=-1 for i in range(n): left[i]=fibcount if(arr[i]in hash): fibcount+=1 else : fibcount=0 fibcount=0 for i in range(n-1,-1,-1): right[i]=fibcount if(arr[i]in hash): fibcount+=1 else : fibcount=0 for i in range(0,n): res=max(res,left[i]+right[i]) return res arr=[2,8,5,7,3,5,7] n=len(arr) print(longestFibSubarray(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 100000 ; skip ; skip ; arr := Sequence{2}->union(Sequence{8}->union(Sequence{5}->union(Sequence{7}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 7 })))))) ; n := (arr)->size() ; execute (longestFibSubarray(arr, n))->display(); operation createHash(hash : OclAny, maxElement : OclAny) pre: true post: true activity: var prev : int := 0 ; var curr : int := 1 ; execute ((prev) : hash) ; execute ((curr) : hash) ; while ((curr->compareTo(maxElement)) <= 0) do ( var temp : int := curr + prev ; execute ((temp) : hash) ; prev := curr ; curr := temp); operation longestFibSubarray(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var max_val : OclAny := (arr)->max() ; hash := Set{ OclType["int"] } ; createHash(hash, max_val) ; var left : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var right : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var fibcount : int := 0 ; var res : int := -1 ; for i : Integer.subrange(0, n-1) do ( left[i+1] := fibcount ; if ((hash)->includes(arr[i+1])) then ( fibcount := fibcount + 1 ) else ( fibcount := 0 )) ; fibcount := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( right[i+1] := fibcount ; if ((hash)->includes(arr[i+1])) then ( fibcount := fibcount + 1 ) else ( fibcount := 0 )) ; for i : Integer.subrange(0, n-1) do ( res := Set{res, left[i+1] + right[i+1]}->max()) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=sorted([int(s)for s in input().split()]) memory=max([abs(int(p)-a[0])for p in a]) for i in range(a[0]+1,a[n-1]+1): memory1=max([abs(int(t)-i)for t in a]) memory=min(memory,memory1) print(memory) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger()))->sort() ; var memory : OclAny := (a->select(p | true)->collect(p | ((("" + ((p)))->toInteger() - a->first())->abs())))->max() ; for i : Integer.subrange(a->first() + 1, a[n - 1+1] + 1-1) do ( var memory1 : OclAny := (a->select(t | true)->collect(t | ((("" + ((t)))->toInteger() - i)->abs())))->max() ; memory := Set{memory, memory1}->min()) ; execute (memory)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def findNumberOfTimes(str1,str2): freq=[0]*26 l1=len(str1) for i in range(l1): freq[ord(str1[i])-ord("a")]+=1 l2=len(str2) count=sys.maxsize for i in range(l2): count=min(count,freq[ord(str2[i])-ord('a')]) return count if __name__=='__main__' : str1="foreeksgekseg" str2="geeks" print(findNumberOfTimes(str1,str2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( str1 := "foreeksgekseg" ; str2 := "geeks" ; execute (findNumberOfTimes(str1, str2))->display() ) else skip; operation findNumberOfTimes(str1 : OclAny, str2 : OclAny) : OclAny pre: true post: true activity: var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; var l1 : int := (str1)->size() ; for i : Integer.subrange(0, l1-1) do ( freq[(str1[i+1])->char2byte() - ("a")->char2byte()+1] := freq[(str1[i+1])->char2byte() - ("a")->char2byte()+1] + 1) ; var l2 : int := (str2)->size() ; var count : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; for i : Integer.subrange(0, l2-1) do ( count := Set{count, freq[(str2[i+1])->char2byte() - ('a')->char2byte()+1]}->min()) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countUnique(arr,n): s=set() for i in range(n): for j in range(n): s.add((arr[i],arr[j])) return len(s) arr=[1,2,2,4,2,5,3,5] n=len(arr) print(countUnique(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{4}->union(Sequence{2}->union(Sequence{5}->union(Sequence{3}->union(Sequence{ 5 }))))))) ; n := (arr)->size() ; execute (countUnique(arr, n))->display(); operation countUnique(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var s : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( execute ((Sequence{arr[i+1], arr[j+1]}) : s))) ; return (s)->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def ratiotang(r1,r2): print("The ratio is",int(r1/gcd(r1,r2)),":",int(r2/gcd(r1,r2))) if __name__=='__main__' : r1=4 r2=6 ratiotang(r1,r2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( r1 := 4 ; r2 := 6 ; ratiotang(r1, r2) ) else skip; operation ratiotang(r1 : OclAny, r2 : OclAny) pre: true post: true activity: execute ("The ratio is")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys class Rope : def __init__(self,point1,point2): self.A=point1 self.B=point2 def intersects(self,rope): if((self.A-rope.A)*(self.B-rope.B))>0 : return False else : return True def main(argv): n=int(sys.stdin.readline()) for i in range(1,n+1): T=int(sys.stdin.readline()) ropes=[] intersects=0 for j in range(T): line=sys.stdin.readline().split(" ") thisRope=Rope(int(line[0]),int(line[1])) for otherRope in ropes : if thisRope.intersects(otherRope): intersects+=1 ropes.append(thisRope) print("Case #%d: %d" %(i,intersects)) main(sys.argv) ------------------------------------------------------------ OCL File: --------- class Rope { static operation newRope() : Rope pre: true post: Rope->exists( _x | result = _x ); attribute A : OclAny := point1; attribute B : OclAny := point2; operation initialise(point1 : OclAny,point2 : OclAny) : Rope pre: true post: true activity: self.A := point1 ; self.B := point2; return self; operation intersects(rope : OclAny) : OclAny pre: true post: true activity: if ((self.A - rope.A) * (self.B - rope.B)) > 0 then ( return false ) else ( return true ); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; main((trailer . (name argv))); operation main(argv : OclAny) pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(1, n + 1-1) do ( var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ropes : Sequence := Sequence{} ; var intersects : int := 0 ; for j : Integer.subrange(0, T-1) do ( var line : OclAny := sys.stdin.readLine().split(" ") ; var thisRope : Rope := (Rope.newRope()).initialise(("" + ((line->first())))->toInteger(), ("" + ((line[1+1])))->toInteger()) ; for otherRope : ropes do ( if thisRope.intersects(otherRope) then ( intersects := intersects + 1 ) else skip) ; execute ((thisRope) : ropes)) ; execute (StringLib.format("Case #%d: %d",Sequence{i, intersects}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def debug(*args): return def memoizing(func): memos=dict() def memoize(*args): if args in memos : return memos[args] res=func(*args) memos[args]=res return res return memoize def run_process(args): res=solve_problem(*args) return res def process_file(fin,fout): def get_problem(): N=int(fin.readline().strip('\n')) W=[list(map(int,fin.readline().split(' ')))for n in range(N)] return(W,) numLines=int(fin.readline()) problem_list=[get_problem()for i in range(numLines)] if False : from multiprocessing import Pool p=Pool(8) solution_list=p.map(run_process,problem_list) else : solution_list=map(run_process,problem_list) for i,s in enumerate(solution_list): fout.write("Case #%s: %s\n" %(i+1,s)) def wires_intersect(a,b): c=(a[0]-b[0],a[1]-b[1]) return(c[0]<0)^(c[1]<0) def solve_problem(W): L=list() intersections=0 for w in W : for l in L : if wires_intersect(w,l): intersections+=1 L.append(w) return intersections if __name__=='__main__' : from sys import argv process_file(open(argv[1]),open(argv[1].replace("in","out"),"w")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( skip ; process_file(OclFile.newOclFile_Write(OclFile.newOclFile(argv[1+1])), OclFile.newOclFile_Write(OclFile.newOclFile(argv[1+1].replace("in", "out")))) ) else skip; operation debug(args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) return; operation memoizing(func : OclAny) : OclAny pre: true post: true activity: var memos : Map := (arguments ( )) ; skip ; return memoize; operation run_process(args : OclAny) : OclAny pre: true post: true activity: res := solve_problem((argument * (test (logical_test (comparison (expr (atom (name args)))))))) ; return res; operation process_file(fin : OclAny, fout : OclAny) pre: true post: true activity: skip ; var numLines : int := ("" + ((fin.readLine())))->toInteger() ; var problem_list : Sequence := Integer.subrange(0, numLines-1)->select(i | true)->collect(i | (get_problem())) ; if false then ( skip ; var p : OclAny := Pool(8) ; var solution_list : OclAny := p.map(run_process, problem_list) ) else ( solution_list := (problem_list)->collect( _x | (run_process)->apply(_x) ) ) ; for _tuple : Integer.subrange(1, (solution_list)->size())->collect( _indx | Sequence{_indx-1, (solution_list)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); fout.write(StringLib.format("Case #%s: %s\n",Sequence{i + 1, s}))); operation wires_intersect(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var c : OclAny := Sequence{a->first() - b->first(), a[1+1] - b[1+1]} ; return MathLib.bitwiseXor((c->first() < 0), (c[1+1] < 0)); operation solve_problem(W : OclAny) : OclAny pre: true post: true activity: var L : Sequence := () ; var intersections : int := 0 ; for w : W do ( for l : L do ( if wires_intersect(w, l) then ( intersections := intersections + 1 ) else skip) ; execute ((w) : L)) ; return intersections; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : f=open("A-large.in","r") fout=open("A-large.out","w") T=int(f.readline()) for i in xrange(T): N=int(f.readline()) a_list=[] b_list=[] for j in xrange(N): a,b=[int(x)for x in f.readline().split()] a_list.append(a) b_list.append(b) result=0 for j in xrange(N): for k in xrange(j+1,N): if a_list[j]b_list[k]: result+=1 if a_list[j]>a_list[k]and b_list[j]toInteger() ; for i : xrange(T) do ( var N : int := ("" + ((f.readLine())))->toInteger() ; var a_list : Sequence := Sequence{} ; var b_list : Sequence := Sequence{} ; for j : xrange(N) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := f.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((a) : a_list) ; execute ((b) : b_list)) ; var result : int := 0 ; for j : xrange(N) do ( for k : xrange(j + 1, N) do ( if (a_list[j+1]->compareTo(a_list[k+1])) < 0 & (b_list[j+1]->compareTo(b_list[k+1])) > 0 then ( result := result + 1 ) else skip ; if (a_list[j+1]->compareTo(a_list[k+1])) > 0 & (b_list[j+1]->compareTo(b_list[k+1])) < 0 then ( result := result + 1 ) else skip)) ; fout.write(StringLib.sumStringsWithSeparator((Sequence{'Case #', ("" + ((i + 1))), ': ', ("" + ((result))), ' '}), ''))) ; fout.closeFile() ; f.closeFile() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printNthElement(n): arr=[0]*(n+1); arr[1]=3 arr[2]=5 for i in range(3,n+1): if(i % 2!=0): arr[i]=arr[i//2]*10+3 else : arr[i]=arr[(i//2)-1]*10+5 return arr[n] n=6 print(printNthElement(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 6 ; execute (printNthElement(n))->display(); operation printNthElement(n : OclAny) : OclAny pre: true post: true activity: var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); ; arr[1+1] := 3 ; arr[2+1] := 5 ; for i : Integer.subrange(3, n + 1-1) do ( if (i mod 2 /= 0) then ( arr[i+1] := arr[i div 2+1] * 10 + 3 ) else ( arr[i+1] := arr[(i div 2) - 1+1] * 10 + 5 )) ; return arr[n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,itertools from pprint import pprint from collections import namedtuple output_line="Case #{X:d}:{Y:d}" Rope=namedtuple("Rope","a b") if __name__=="__main__" : infile,outfile=sys.argv[1 :] with open(infile,"r")as inhandle,open(outfile,"w")as outhandle : T=int(inhandle.readline()) for t in range(T): N=int(inhandle.readline()) ropes=[Rope(*map(int,inhandle.readline().split()))for n in range(N)] ropes.sort() total=0 for ropeA in ropes : for ropeB in ropes : if((ropeA.aropeB.b)or(ropeA.a>ropeB.a and ropeA.btoInteger() ; for t : Integer.subrange(0, T-1) do ( var N : int := ("" + ((inhandle.readLine())))->toInteger() ; var ropes : Sequence := Integer.subrange(0, N-1)->select(n | true)->collect(n | (Rope((argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name inhandle)) (trailer . (name readline) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))))) ; ropes := ropes->sort() ; var total : int := 0 ; for ropeA : ropes do ( for ropeB : ropes do ( if (((ropeA.a->compareTo(ropeB.a)) < 0 & (ropeA.b->compareTo(ropeB.b)) > 0) or ((ropeA.a->compareTo(ropeB.a)) > 0 & (ropeA.b->compareTo(ropeB.b)) < 0)) then ( total := total + 1 ) else skip)) ; assert (total mod 2 = 0) do "assertion failed" ; total := total div 2 ; execute (StringLib.interpolateStrings(output_line, Sequence{(argument (test (logical_test (comparison (expr (atom (name X)))))) = (test (logical_test (comparison (expr (expr (atom (name t))) + (expr (atom (number (integer 1))))))))), (argument (test (logical_test (comparison (expr (atom (name Y)))))) = (test (logical_test (comparison (expr (atom (name total)))))))}))->display())) catch (_e : OclException) do skip ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for testCase in range(0,T): N=int(input()) A=[] for n in range(0,N): line=input().split() A.append((int(line[0]),int(line[1]))) A.sort() s=0 for a0,b0 in A : i=0 while A[i][0]b0 : s+=1 i+=1 print('Case #{0}:{1}'.format(testCase+1,s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for testCase : Integer.subrange(0, T-1) do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := Sequence{} ; for n : Integer.subrange(0, N-1) do ( var line : OclAny := input().split() ; execute ((Sequence{("" + ((line->first())))->toInteger(), ("" + ((line[1+1])))->toInteger()}) : A)) ; A := A->sort() ; var s : int := 0 ; for _tuple : A do (var _indx : int := 1; var a0 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b0 : OclAny := _tuple->at(_indx); var i : int := 0 ; while (A[i+1]->first()->compareTo(a0)) < 0 do ( if (A[i+1][1+1]->compareTo(b0)) > 0 then ( s := s + 1 ) else skip ; i := i + 1)) ; execute (StringLib.interpolateStrings('Case #{0}:{1}', Sequence{testCase + 1, s}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from decimal import Decimal,getcontext d1=Decimal(1) while True : n,k,m,r=map(int,input().split()) if not n : break getcontext().prec=r+1 ans=d1/Decimal(n) if m : ans*=1+sum(d1/Decimal(i)for i in range(1,n)) print('{{:.{}f}}'.format(r+1).format(ans)[:-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var d1 : OclAny := Decimal(1) ; while true do ( var n : OclAny := null; var k : OclAny := null; var m : OclAny := null; var r : OclAny := null; Sequence{n,k,m,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if not(n) then ( break ) else skip ; getcontext().prec := r + 1 ; var ans : double := d1 / Decimal(n) ; if m then ( ans := ans * 1 + ((argument (test (logical_test (comparison (expr (expr (atom (name d1))) / (expr (atom (name Decimal)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->sum() ) else skip ; execute ('{{:.{}f}}'.format(r + 1).format(ans)->front())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) a=list(map(int,input().split())) A=max(a) B=min(a) C=(math.ceil((A+B)/2)) if abs(A-C)>abs(B-C): print(abs(A-C)) elif abs(A-C)toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var A : OclAny := (a)->max() ; var B : OclAny := (a)->min() ; var C : double := (((A + B) / 2)->ceil()) ; if ((A - C)->abs()->compareTo((B - C)->abs())) > 0 then ( execute ((A - C)->abs())->display() ) else (if ((A - C)->abs()->compareTo((B - C)->abs())) < 0 then ( execute ((B - C)->abs())->display() ) else ( execute ((A - C)->abs())->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from decimal import* while True : n,k,m,r=map(int,input().split()) if n==0 : break setcontext(Context(prec=r,rounding=ROUND_HALF_UP)) one=Decimal(1) ans=one/Decimal(n) if m==1 : s=0 for i in range(1,n): s+=one/Decimal(i) ans*=1+s ans=str(ans)[: r+2] if len(ans)collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; setcontext(Context((argument (test (logical_test (comparison (expr (atom (name prec)))))) = (test (logical_test (comparison (expr (atom (name r))))))), (argument (test (logical_test (comparison (expr (atom (name rounding)))))) = (test (logical_test (comparison (expr (atom (name ROUND_HALF_UP))))))))) ; var one : OclAny := Decimal(1) ; var ans : double := one / Decimal(n) ; if m = 1 then ( var s : int := 0 ; for i : Integer.subrange(1, n-1) do ( s := s + one / Decimal(i)) ; ans := ans * 1 + s ) else skip ; ans := OclType["String"](ans).subrange(1,r + 2) ; if ((ans)->size()->compareTo(r + 2)) < 0 then ( ans := ans + StringLib.nCopies('0', (r + 2 - (ans)->size())) ) else skip ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) H=[] for i in range(n): H.append(float(input())) c1=0 c2=0 c3=0 c4=0 c5=0 c6=0 for j in range(n): if H[j]<165.0 : c1+=1 elif 165.0<=H[j]<170.0 : c2+=1 elif 170.0<=H[j]<175.0 : c3+=1 elif 175.0<=H[j]<180.0 : c4+=1 elif 180.0<=H[j]<185.0 : c5+=1 else : c6+=1 print("1:"+c1*"*",sep="") print("2:"+c2*"*",sep="") print("3:"+c3*"*",sep="") print("4:"+c4*"*",sep="") print("5:"+c5*"*",sep="") print("6:"+c6*"*",sep="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var H : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toReal()) : H)) ; var c1 : int := 0 ; var c2 : int := 0 ; var c3 : int := 0 ; var c4 : int := 0 ; var c5 : int := 0 ; var c6 : int := 0 ; for j : Integer.subrange(0, n-1) do ( if H[j+1] < 165.0 then ( c1 := c1 + 1 ) else (if 165.0 <= H[j+1] & (H[j+1] < 170.0) then ( c2 := c2 + 1 ) else (if 170.0 <= H[j+1] & (H[j+1] < 175.0) then ( c3 := c3 + 1 ) else (if 175.0 <= H[j+1] & (H[j+1] < 180.0) then ( c4 := c4 + 1 ) else (if 180.0 <= H[j+1] & (H[j+1] < 185.0) then ( c5 := c5 + 1 ) else ( c6 := c6 + 1 ) ) ) ) ) ) ; execute ("1:" + c1 * "*")->display() ; execute ("2:" + c2 * "*")->display() ; execute ("3:" + c3 * "*")->display() ; execute ("4:" + c4 * "*")->display() ; execute ("5:" + c5 * "*")->display() ; execute ("6:" + c6 * "*")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- HEIGHT_BASE=[165,170,175,180,185,1000] distribution=[0,0,0,0,0,0] input_data=[float(input())for lp in range(int(input()))] for item in input_data : for index,base in enumerate(HEIGHT_BASE): if itemunion(Sequence{170}->union(Sequence{175}->union(Sequence{180}->union(Sequence{185}->union(Sequence{ 1000 }))))) ; var distribution : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))))) ; var input_data : Sequence := Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1)->select(lp | true)->collect(lp | (("" + (((OclFile["System.in"]).readLine())))->toReal())) ; for item : input_data do ( for _tuple : Integer.subrange(1, (HEIGHT_BASE)->size())->collect( _indx | Sequence{_indx-1, (HEIGHT_BASE)->at(_indx)} ) do (var _indx : int := 1; var index : OclAny := _tuple->at(_indx); _indx := _indx + 1; var base : OclAny := _tuple->at(_indx); if (item->compareTo(base)) < 0 then ( distribution[index+1] := distribution[index+1] + 1 ; break ) else skip)) ; for index : Integer.subrange(0, 6-1) do ( execute (("" + ((index + 1))) + ":" + StringLib.nCopies("*", distribution[index+1]))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) height=[0 for i in range(6)] for i in range(n): tmp=float(input()) if tmp<165 : height[0]+=1 elif tmp<170 : height[1]+=1 elif tmp<175 : height[2]+=1 elif tmp<180 : height[3]+=1 elif tmp<185 : height[4]+=1 else : height[5]+=1 for i,j in enumerate(height,1): print(str(i)+":"+"*"*j) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var height : Sequence := Integer.subrange(0, 6-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( var tmp : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; if tmp < 165 then ( height->first() := height->first() + 1 ) else (if tmp < 170 then ( height[1+1] := height[1+1] + 1 ) else (if tmp < 175 then ( height[2+1] := height[2+1] + 1 ) else (if tmp < 180 then ( height[3+1] := height[3+1] + 1 ) else (if tmp < 185 then ( height[4+1] := height[4+1] + 1 ) else ( height[5+1] := height[5+1] + 1 ) ) ) ) ) ) ; for _tuple : Integer.subrange(1, (height, 1)->size())->collect( _indx | Sequence{_indx-1, (height, 1)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); execute (("" + ((i))) + ":" + StringLib.nCopies("*", j))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def main(args): ranks=[0]*6 n=int(input()) for _ in range(n): h=float(input()) if h<160.0 : h=160.0 if h>=190.0 : h=189.9 pos=int((h-160.0)/5) ranks[pos]+=1 for i,f in enumerate(ranks): print('{}:{}'.format(i+1,'*'*f)) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation main(args : OclAny) pre: true post: true activity: var ranks : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 6) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var h : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; if h < 160.0 then ( h := 160.0 ) else skip ; if h >= 190.0 then ( h := 189.9 ) else skip ; var pos : int := ("" + (((h - 160.0) / 5)))->toInteger() ; ranks[pos+1] := ranks[pos+1] + 1) ; for _tuple : Integer.subrange(1, (ranks)->size())->collect( _indx | Sequence{_indx-1, (ranks)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var f : OclAny := _tuple->at(_indx); execute (StringLib.interpolateStrings('{}:{}', Sequence{i + 1, StringLib.nCopies('*', f)}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,copy PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input2.txt","rt") limits={1 :[0,165],2 :[165,170],3 :[170,175],4 :[175,180],5 :[180,185],6 :[185,9999999]} dist={k : 0 for k in range(1,7)} N=int(input()) for _ in range(N): h=float(input()) for k in range(1,7): if h Sequence{0}->union(Sequence{ 165 }) }->union(Map{ 2 |-> Sequence{165}->union(Sequence{ 170 }) }->union(Map{ 3 |-> Sequence{170}->union(Sequence{ 175 }) }->union(Map{ 4 |-> Sequence{175}->union(Sequence{ 180 }) }->union(Map{ 5 |-> Sequence{180}->union(Sequence{ 185 }) }->union(Map{ 6 |-> Sequence{185}->union(Sequence{ 9999999 }) }))))) ; var dist : Map := Integer.subrange(1, 7-1)->select(k | true)->collect(k | Map{k |-> 0})->unionAll() ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, N-1) do ( var h : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; for k : Integer.subrange(1, 7-1) do ( if (h->compareTo(limits[k+1][1+1])) < 0 then ( dist[k+1] := dist[k+1] + 1 ; break ) else skip)) ; for k : Integer.subrange(1, 7-1) do ( execute (StringLib.format("%d:%s",Sequence{k, StringLib.nCopies('*', dist[k+1])}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxSum(arr,n): cum_sum=0 for i in range(0,n): cum_sum+=arr[i] curr_val=0 for i in range(0,n): curr_val+=i*arr[i] res=curr_val for i in range(1,n): next_val=(curr_val-(cum_sum-arr[i-1])+arr[i-1]*(n-1)) curr_val=next_val res=max(res,next_val) return res arr=[8,3,1,2] n=len(arr) print(maxSum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{8}->union(Sequence{3}->union(Sequence{1}->union(Sequence{ 2 }))) ; n := (arr)->size() ; execute (maxSum(arr, n))->display(); operation maxSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var cum_sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( cum_sum := cum_sum + arr[i+1]) ; var curr_val : int := 0 ; for i : Integer.subrange(0, n-1) do ( curr_val := curr_val + i * arr[i+1]) ; var res : int := curr_val ; for i : Integer.subrange(1, n-1) do ( var next_val : double := (curr_val - (cum_sum - arr[i - 1+1]) + arr[i - 1+1] * (n - 1)) ; curr_val := next_val ; res := Set{res, next_val}->max()) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dimensions=input().split(' ') n=int(dimensions[0]) m=int(dimensions[1]) dir_horiz=input() dir_vert=input() answer=True if not(dir_horiz[0]=='<' or(dir_vert[0]=='^' and dir_vert[-1]=='v' and '<' in dir_horiz)): answer=False if not(dir_horiz[-1]=='>' or(dir_vert[0]=='^' and dir_vert[-1]=='v' and '>' in dir_horiz)): answer=False if not(dir_vert[0]=='v' or(dir_horiz[0]=='>' and dir_horiz[-1]=='<' and 'v' in dir_vert)): answer=False if not(dir_vert[-1]=='^' or(dir_horiz[0]=='>' and dir_horiz[-1]=='<' and '^' in dir_vert)): answer=False if answer : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dimensions : OclAny := input().split(' ') ; var n : int := ("" + ((dimensions->first())))->toInteger() ; var m : int := ("" + ((dimensions[1+1])))->toInteger() ; var dir_horiz : String := (OclFile["System.in"]).readLine() ; var dir_vert : String := (OclFile["System.in"]).readLine() ; var answer : boolean := true ; if not((dir_horiz->first() = '<' or (dir_vert->first() = '^' & dir_vert->last() = 'v' & (dir_horiz)->characters()->includes('<')))) then ( answer := false ) else skip ; if not((dir_horiz->last() = '>' or (dir_vert->first() = '^' & dir_vert->last() = 'v' & (dir_horiz)->characters()->includes('>')))) then ( answer := false ) else skip ; if not((dir_vert->first() = 'v' or (dir_horiz->first() = '>' & dir_horiz->last() = '<' & (dir_vert)->characters()->includes('v')))) then ( answer := false ) else skip ; if not((dir_vert->last() = '^' or (dir_horiz->first() = '>' & dir_horiz->last() = '<' & (dir_vert)->characters()->includes('^')))) then ( answer := false ) else skip ; if answer then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate n=int(input()) mp=[list(map(int,input().split()))for _ in range(n)] acc_arr=[list(accumulate([0]+line))for line in mp] ans=max([max(line)for line in mp]) for i in range(n+1): for j in range(i+1,n+1): acc=0 for k in range(n): add=acc_arr[k][j]-acc_arr[k][i] if acc+add>0 : acc=acc+add ans=max(acc,ans) else : acc=0 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mp : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var acc_arr : Sequence := mp->select(line | true)->collect(line | ((accumulate(Sequence{ 0 }->union(line))))) ; var ans : OclAny := (mp->select(line | true)->collect(line | ((line)->max())))->max() ; for i : Integer.subrange(0, n + 1-1) do ( for j : Integer.subrange(i + 1, n + 1-1) do ( var acc : int := 0 ; for k : Integer.subrange(0, n-1) do ( var add : double := acc_arr[k+1][j+1] - acc_arr[k+1][i+1] ; if acc + add > 0 then ( acc := acc + add ; ans := Set{acc, ans}->max() ) else ( acc := 0 )))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) dp=[[0]*(n)for _ in range(n)] ans=-10**9 a=[list(map(int,input().split()))for i in range(n)] for i in range(n): s=[0]*101 for j in range(n): s[j+1]=s[j]+a[i][j] for j in range(n): for k in range(j,n): dp[j][k]=max(dp[j][k],0)+s[k+1]-s[j] ans=max(ans,dp[j][k]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var dp : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (n)))) ; var ans : double := (-10)->pow(9) ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for i : Integer.subrange(0, n-1) do ( var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 101) ; for j : Integer.subrange(0, n-1) do ( s[j + 1+1] := s[j+1] + a[i+1][j+1]) ; for j : Integer.subrange(0, n-1) do ( for k : Integer.subrange(j, n-1) do ( dp[j+1][k+1] := Set{dp[j+1][k+1], 0}->max() + s[k + 1+1] - s[j+1] ; ans := Set{ans, dp[j+1][k+1]}->max()))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) a=list(map(int,input().split())) min=a[0] i=0 for i in range(N): if a[i]max : k=0 k=a[i] a[i]=max max=k i+=1 c=max-min import math print(int(math.ceil(c/2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var min : OclAny := a->first() ; var i : int := 0 ; for i : Integer.subrange(0, N-1) do ( if (a[i+1]->compareTo(min)) < 0 then ( var k : int := 0 ; k := a[i+1] ; a[i+1] := min ; min := k ) else skip ; i := i + 1) ; var max : OclAny := a->first() ; i := 0 ; for i : Integer.subrange(0, N-1) do ( if (a[i+1]->compareTo(max)) > 0 then ( k := 0 ; k := a[i+1] ; a[i+1] := max ; max := k ) else skip ; i := i + 1) ; var c : double := max - min ; skip ; execute (("" + (((c / 2)->ceil())))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import division,print_function from sys import stdin,exit,maxsize def find(n,data): temp=[0]*(n*(n+1)//2) maximum=-maxsize for row in data : index=0 num_cell=1 for end in range(n,-1,-1): for i in range(end): k=index+i now=sum(row[i : i+num_cell]) if temp[k]<0 : temp[k]=now else : temp[k]+=now if maximumreverse() do ( for i : Integer.subrange(0, end-1) do ( var k : int := index + i ; var now : OclAny := (row.subrange(i+1, i + num_cell))->sum() ; if temp[k+1] < 0 then ( temp[k+1] := now ) else ( temp[k+1] := temp[k+1] + now ) ; if (maximum->compareTo(temp[k+1])) < 0 then ( maximum := temp[k+1] ) else skip) ; index := index + end ; num_cell := num_cell + 1)) ; return maximum; operation main(readline : OclAny) pre: true post: true activity: if readline->oclIsUndefined() then readline := stdin.readline else skip; n := ("" + ((readline())))->toInteger() ; var a : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((readline().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger()))) : a)) ; execute (find(n, a))->display() ; exit(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[[0 for c in range(102)]for r in range(102)] s=[[0 for c in range(102)]for r in range(102)] n=int(input()) for r in range(n): a[r]=list(map(int,input().split())) for r in range(n): for c in range(n): s[r][c+1]+=s[r][c]+a[r][c] ans=s[0][1]; for c in range(n): for k in range(c+1,n+1): t=0 for r in range(n): if t<0 : t=s[r][k]-s[r][c] else : t+=s[r][k]-s[r][c] if t>ans : ans=t print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Integer.subrange(0, 102-1)->select(r | true)->collect(r | (Integer.subrange(0, 102-1)->select(c | true)->collect(c | (0)))) ; var s : Sequence := Integer.subrange(0, 102-1)->select(r | true)->collect(r | (Integer.subrange(0, 102-1)->select(c | true)->collect(c | (0)))) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for r : Integer.subrange(0, n-1) do ( a[r+1] := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; for r : Integer.subrange(0, n-1) do ( for c : Integer.subrange(0, n-1) do ( s[r+1][c + 1+1] := s[r+1][c + 1+1] + s[r+1][c+1] + a[r+1][c+1])) ; var ans : OclAny := s->first()[1+1]; ; for c : Integer.subrange(0, n-1) do ( for k : Integer.subrange(c + 1, n + 1-1) do ( var t : int := 0 ; for r : Integer.subrange(0, n-1) do ( if t < 0 then ( t := s[r+1][k+1] - s[r+1][c+1] ) else ( t := t + s[r+1][k+1] - s[r+1][c+1] ) ; if (t->compareTo(ans)) > 0 then ( ans := t ) else skip))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline write=sys.stdout.write def solve(): N=int(readline()) A=[list(map(int,readline().split()))for i in range(N)] B=[[0]*(N+1)for i in range(N+1)] for i in range(N): c=0 Ai=A[i] Bi=B[i] Bj=B[i+1] for j in range(N): Bj[j+1]=Bi[j+1]+Ai[j] def gen(): for i0 in range(N): Ba=B[i0] for i1 in range(i0+1,N+1): Bb=B[i1] mi=su=0 for j in range(N): su+=Bb[j+1]-Ba[j+1] yield su-mi mi=min(mi,su) write("%d\n" % max(gen())) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var write : OclAny := (OclFile["System.out"]).write ; skip ; solve(); operation solve() pre: true post: true activity: var N : int := ("" + ((readline())))->toInteger() ; var A : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((readline().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var B : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)))) ; for i : Integer.subrange(0, N-1) do ( var c : int := 0 ; var Ai : OclAny := A[i+1] ; var Bi : OclAny := B[i+1] ; var Bj : OclAny := B[i + 1+1] ; for j : Integer.subrange(0, N-1) do ( Bj[j + 1+1] := Bi[j + 1+1] + Ai[j+1])) ; skip ; write(StringLib.format("%d\n",(OclIterator.newOclIterator_Function(lambda _i : int in self.gen(_i)))->max())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k,*a=map(int,open(0).read().split()) l,r,*b=[[]for _ in range(10**6)] for i,v in enumerate(a): b[v]+=i, l+=len(b[v]), s=a[0] i=c=0 while ik-2)>j : r+=s, i+=1 else : i=b[s][j]+1 c+=j<1 s=a[i % n] print(*r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var a : OclAny := null; Sequence{n,k,a} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : OclAny := null; var r : OclAny := null; var b : OclAny := null; Sequence{l,r,b} := Integer.subrange(0, (10)->pow(6)-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); b[v+1] := b[v+1] + (testlist (test (logical_test (comparison (expr (atom (name i)))))) ,) ; l := l + (testlist (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])))))))) ))))))) ,)) ; var s : OclAny := a->first() ; var i : OclAny := 0; var c : int := 0 ; while (i->compareTo(n)) < 0 do ( var j : int := l[i+1] mod (b[s+1])->size() ; c := c + j < 1 ; i := b[s+1][j+1] + 1 ; s := a[i mod n+1]) ; k := k mod c + 1 ; i := 0; c := 0 ; while (i->compareTo(n)) < 0 do ( j := l[i+1] mod (b[s+1])->size() ; if (((c->compareTo(k - 2)) > 0)->compareTo(j)) > 0 then ( r := r + (testlist (test (logical_test (comparison (expr (atom (name s)))))) ,) ; i := i + 1 ) else ( i := b[s+1][j+1] + 1 ) ; c := c + j < 1 ; s := a[i mod n+1]) ; execute ((argument * (test (logical_test (comparison (expr (atom (name r))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin sys.setrecursionlimit(10**7) def li(): return map(int,stdin.readline().split()) def li_(): return map(lambda x : int(x)-1,stdin.readline().split()) def lf(): return map(float,stdin.readline().split()) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) from collections import defaultdict from bisect import bisect_left n,k=li() a=list(li()) a=a+a jump=defaultdict(lambda :-1) buf=defaultdict(lambda :-1) for i,ai in enumerate(a): if buf[ai]!=-1 : jump[buf[ai]]=i-buf[ai] buf[ai]=i checkpoint=[0] cur=0 while cur==0 or cur % n>0 : cur+=jump[cur % n] cur+=1 checkpoint.append(cur) cycle=cur//n mod=k % cycle if mod==0 : print() else : last_idx=n*mod start_idx=checkpoint[bisect_left(checkpoint,last_idx)-1] s=[] idx=start_idx while idxpow(7)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := li() ; var a : Sequence := (li()) ; a := a->union(a) ; var jump : OclAny := defaultdict(lambda $$ : OclAny in (-1)) ; var buf : OclAny := defaultdict(lambda $$ : OclAny in (-1)) ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var ai : OclAny := _tuple->at(_indx); if buf[ai+1] /= -1 then ( jump[buf[ai+1]+1] := i - buf[ai+1] ) else skip ; buf[ai+1] := i) ; var checkpoint : Sequence := Sequence{ 0 } ; var cur : int := 0 ; while cur = 0 or cur mod n > 0 do ( cur := cur + jump[cur mod n+1] ; cur := cur + 1 ; execute ((cur) : checkpoint)) ; var cycle : int := cur div n ; var mod : int := k mod cycle ; if mod = 0 then ( execute (->display() ) else ( var last_idx : double := n * mod ; var start_idx : OclAny := checkpoint[bisect_left(checkpoint, last_idx) - 1+1] ; var s : Sequence := Sequence{} ; var idx : OclAny := start_idx ; while (idx->compareTo(last_idx)) < 0 do ( if (idx + jump[idx mod n+1]->compareTo(last_idx)) < 0 then ( idx := idx + jump[idx mod n+1] + 1 ) else ( execute ((a[idx mod n+1]) : s) ; idx := idx + 1 )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name s))))))))->display() ); operation li() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation li_() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ); operation lf() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ); operation ls() : OclAny pre: true post: true activity: return stdin.readLine().split(); operation ns() : OclAny pre: true post: true activity: return stdin.readLine().rstrip(); operation lc() : OclAny pre: true post: true activity: return (ns()); operation ni() : OclAny pre: true post: true activity: return ("" + ((stdin.readLine())))->toInteger(); operation nf() : OclAny pre: true post: true activity: return ("" + ((stdin.readLine())))->toReal(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_right from collections import defaultdict N,K=map(int,input().split()) As=list(map(int,input().split())) indices_of_elem=defaultdict(list) for i,A in enumerate(As): indices_of_elem[A].append(i) empty_index=[0] while True : cur_index=empty_index[-1] look_for_elem=As[cur_index % N] index_of_indices=bisect_right(indices_of_elem[look_for_elem],cur_index % N) if len(indices_of_elem[look_for_elem])==index_of_indices : pair_end_index=(cur_index//N)*N+indices_of_elem[look_for_elem][0]+N else : pair_end_index=(cur_index//N)*N+indices_of_elem[look_for_elem][index_of_indices] new_index=pair_end_index+1 empty_index.append(new_index) if new_index % N==0 : break loop=new_index//N K %=loop if K==0 : exit() else : start=empty_index[bisect_right(empty_index,K*N)-1]% N tmp_ans=As[start :] index_for_tmp_ans=dict() split=[] for i,elem in enumerate(tmp_ans): if elem in index_for_tmp_ans : split.append((index_for_tmp_ans[elem],i)) while True : k,v=index_for_tmp_ans.popitem() if k==elem : break else : index_for_tmp_ans[elem]=i for start,end in split : tmp_ans[start : end+1]=[-1]*(end-start+1) for ans in tmp_ans : if ans!=-1 : print(ans,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var As : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var indices_of_elem : OclAny := defaultdict(OclType["Sequence"]) ; for _tuple : Integer.subrange(1, (As)->size())->collect( _indx | Sequence{_indx-1, (As)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var A : OclAny := _tuple->at(_indx); (expr (atom (name indices_of_elem)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name A)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var empty_index : Sequence := Sequence{ 0 } ; while true do ( var cur_index : OclAny := empty_index->last() ; var look_for_elem : OclAny := As[cur_index mod N+1] ; var index_of_indices : OclAny := bisect_right(indices_of_elem[look_for_elem+1], cur_index mod N) ; if (indices_of_elem[look_for_elem+1])->size() = index_of_indices then ( var pair_end_index : double := (cur_index div N) * N + indices_of_elem[look_for_elem+1]->first() + N ) else ( pair_end_index := (cur_index div N) * N + indices_of_elem[look_for_elem+1][index_of_indices+1] ) ; var new_index : OclAny := pair_end_index + 1 ; execute ((new_index) : empty_index) ; if new_index mod N = 0 then ( break ) else skip) ; var loop : int := new_index div N ; K := K mod loop ; if K = 0 then ( exit() ) else ( var start : int := empty_index[bisect_right(empty_index, K * N) - 1+1] mod N ; var tmp_ans : OclAny := As.subrange(start+1) ) ; var index_for_tmp_ans : Map := (arguments ( )) ; var split : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (tmp_ans)->size())->collect( _indx | Sequence{_indx-1, (tmp_ans)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var elem : OclAny := _tuple->at(_indx); if (index_for_tmp_ans)->includes(elem) then ( execute ((Sequence{index_for_tmp_ans[elem+1], i}) : split) ; while true do ( var k : OclAny := null; var v : OclAny := null; Sequence{k,v} := index_for_tmp_ans.popitem() ; if k = elem then ( break ) else skip) ) else ( index_for_tmp_ans[elem+1] := i )) ; for _tuple : split do (var _indx : int := 1; var start : OclAny := _tuple->at(_indx); _indx := _indx + 1; var end : OclAny := _tuple->at(_indx); tmp_ans.subrange(start+1, end + 1) := MatrixLib.elementwiseMult(Sequence{ -1 }, (end - start + 1))) ; for ans : tmp_ans do ( if ans /= -1 then ( execute (ans)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from collections import* N,K=map(int,input().split()) A=list(map(int,input().split())) log_size=65 dp=[[-1]*N for _ in range(log_size)] idx=defaultdict(int) for i in range(2*N): if A[i % N]in idx and idx[A[i % N]]=0 : NK-=dp[i][now] now=(now+dp[i][now])% N if NK==0 : print() exit() q=deque([]) cnt=defaultdict(int) for i in range(now,N): if cnt[A[i]]>0 : while cnt[A[i]]>0 : rem=q.pop() cnt[rem]-=1 else : cnt[A[i]]+=1 q.append(A[i]) print(*q) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var log_size : int := 65 ; var dp : Sequence := Integer.subrange(0, log_size-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ -1 }, N))) ; var idx : OclAny := defaultdict(OclType["int"]) ; for i : Integer.subrange(0, 2 * N-1) do ( if (idx)->includes(A[i mod N+1]) & (idx[A[i mod N+1]+1]->compareTo(N)) < 0 then ( dp->first()[idx[A[i mod N+1]+1]+1] := i + 1 - idx[A[i mod N+1]+1] ) else skip ; idx[A[i mod N+1]+1] := i) ; for i : Integer.subrange(1, log_size-1) do ( for j : Integer.subrange(0, N-1) do ( dp[i+1][j+1] := Set{(10)->pow(18), dp[i - 1+1][j+1] + dp[i - 1+1][(j + dp[i - 1+1][j+1]) mod N+1]}->min())) ; var now : int := 0 ; var NK : double := N * K ; for i : Integer.subrange(-1 + 1, log_size - 1)->reverse() do ( if NK - dp[i+1][now+1] >= 0 then ( NK := NK - dp[i+1][now+1] ; now := (now + dp[i+1][now+1]) mod N ) else skip) ; if NK = 0 then ( execute (->display() ; exit() ) else skip ; var q : Sequence := (Sequence{}) ; var cnt : OclAny := defaultdict(OclType["int"]) ; for i : Integer.subrange(now, N-1) do ( if cnt[A[i+1]+1] > 0 then ( while cnt[A[i+1]+1] > 0 do ( var rem : OclAny := q->last() ; q := q->front() ; cnt[rem+1] := cnt[rem+1] - 1) ) else ( cnt[A[i+1]+1] := cnt[A[i+1]+1] + 1 ; execute ((A[i+1]) : q) )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name q))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n,k=map(int,input().split()) a=list(map(int,input().split())) if n==1 : if k % 2==1 : print(a[0]) else : print("") else : aa=a+a skip=[0 for _ in range(n)] ind=dict() for i in range(2*n-1,-1,-1): if aa[i]in ind and in : ans.append(a[cnt]) cnt+=1 elif cnt+skip[cnt % n]<=n : cnt+=skip[cnt % n] print(*ans) sys.exit() cnt=0 while cnt==0 or(cnt+skip[cnt % n]<=n*k and cnt % n!=0): cnt+=skip[cnt % n] if cnt % n==0 : l=cnt//n k %=l if k==0 : print("") sys.exit() cnt=0 while cnt==0 or cnt+skip[cnt % n]<=n*k : cnt+=skip[cnt % n] ans=[] cnt=cnt % n while cntn : ans.append(a[cnt]) cnt+=1 elif cnt+skip[cnt % n]<=n : cnt+=skip[cnt % n] print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = 1 then ( if k mod 2 = 1 then ( execute (a->first())->display() ) else ( execute ("")->display() ) ) else ( var aa : Sequence := a->union(a) ; var skip : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)) ; var ind : Map := (arguments ( )) ; for i : Integer.subrange(-1 + 1, 2 * n - 1)->reverse() do ( if (ind)->includes(aa[i+1]) & (i->compareTo(n)) < 0 then ( skip[i+1] := ind[aa[i+1]+1] - i + 1 ) else skip ; ind[aa[i+1]+1] := i) ; if k = 1 then ( var ans : Sequence := Sequence{} ; var cnt : int := 0 ; while (cnt->compareTo(n)) < 0 do ( if (cnt + skip[cnt mod n+1]->compareTo(n)) > 0 then ( execute ((a[cnt+1]) : ans) ; cnt := cnt + 1 ) else (if (cnt + skip[cnt mod n+1]->compareTo(n)) <= 0 then ( cnt := cnt + skip[cnt mod n+1] ) else skip)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ; sys.exit() ) else skip ; cnt := 0 ; while cnt = 0 or ((cnt + skip[cnt mod n+1]->compareTo(n * k)) <= 0 & cnt mod n /= 0) do ( cnt := cnt + skip[cnt mod n+1]) ; if cnt mod n = 0 then ( var l : int := cnt div n ; k := k mod l ; if k = 0 then ( execute ("")->display() ; sys.exit() ) else skip ; cnt := 0 ; while cnt = 0 or (cnt + skip[cnt mod n+1]->compareTo(n * k)) <= 0 do ( cnt := cnt + skip[cnt mod n+1]) ) else skip ; ans := Sequence{} ; cnt := cnt mod n ; while (cnt->compareTo(n)) < 0 do ( if (cnt + skip[cnt mod n+1]->compareTo(n)) > 0 then ( execute ((a[cnt+1]) : ans) ; cnt := cnt + 1 ) else (if (cnt + skip[cnt mod n+1]->compareTo(n)) <= 0 then ( cnt := cnt + skip[cnt mod n+1] ) else skip)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def instr(): return input() def solve(): d=defaultdict(list) n,m=tuple(map(int,input().split())) s1=instr() s2=instr() l=[0]*(n*m) for i in range(n): for j in range(m-1): if s1[i]=='>' : d[m*i+j].append(m*i+j+1); l[m*i+j+1]+=1 else : d[m*i+j+1].append(m*i+j); l[m*i+j]+=1 for i in range(n-1): for j in range(m): if s2[j]=='v' : d[m*i+j].append(m*(i+1)+j); l[m*(i+1)+j]+=1 else : d[m*(i+1)+j].append(m*i+j); l[m*i+j]+=1 for i in range(m*n): if d[i]==0 or l[i]==0 : return 'NO' return('YES') print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; execute (solve())->display(); operation instr() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation solve() : OclAny pre: true post: true activity: var d : OclAny := defaultdict(OclType["Sequence"]) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s1 : OclAny := instr() ; var s2 : OclAny := instr() ; var l : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n * m)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m - 1-1) do ( if s1[i+1] = '>' then ( (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name m))) * (expr (atom (name i)))) + (expr (atom (name j))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (expr (atom (name m))) * (expr (atom (name i)))) + (expr (atom (name j)))) + (expr (atom (number (integer 1)))))))))) )))); l[m * i + j + 1+1] := l[m * i + j + 1+1] + 1 ) else ( (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (expr (atom (name m))) * (expr (atom (name i)))) + (expr (atom (name j)))) + (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name m))) * (expr (atom (name i)))) + (expr (atom (name j))))))))) )))); l[m * i + j+1] := l[m * i + j+1] + 1 ))) ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(0, m-1) do ( if s2[j+1] = 'v' then ( (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name m))) * (expr (atom (name i)))) + (expr (atom (name j))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name m))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) )))) + (expr (atom (name j))))))))) )))); l[m * (i + 1) + j+1] := l[m * (i + 1) + j+1] + 1 ) else ( (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name m))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) )))) + (expr (atom (name j))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name m))) * (expr (atom (name i)))) + (expr (atom (name j))))))))) )))); l[m * i + j+1] := l[m * i + j+1] + 1 ))) ; for i : Integer.subrange(0, m * n-1) do ( if d[i+1] = 0 or l[i+1] = 0 then ( return 'NO' ) else skip) ; return ('YES'); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): while b!=0 : r=a % b a,b=b,r return a N,M=map(int,input().split()) a=list(map(int,input().split())) a.extend(a) step=gcd(N,M) group=N//step ; ans=0 for i in range(group): k=i*step mi=ma=a[k]; for j in range(1,M): mi=min(mi,a[k+j]) ma=max(ma,a[k+j]) ans+=ma-mi print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->union(a) ; var step : OclAny := gcd(N, M) ; var group : int := N div step; ; var ans : int := 0 ; for i : Integer.subrange(0, group-1) do ( var k : double := i * step ; var mi : OclAny := a[k+1]; var ma : OclAny := a[k+1]; ; for j : Integer.subrange(1, M-1) do ( mi := Set{mi, a[k + j+1]}->min() ; ma := Set{ma, a[k + j+1]}->max()) ; ans := ans + ma - mi) ; execute (ans)->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: while b /= 0 do ( var r : int := a mod b ; Sequence{a,b} := Sequence{b,r}) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def compute(): LIMIT=10**6 ans=sum(1 for i in range(LIMIT)if get_chain_length(i)==60) return str(ans) def get_chain_length(n): seen=set() while True : seen.add(n) n=factorialize(n) if n in seen : return len(seen) def factorialize(n): result=0 while n!=0 : result+=FACTORIAL[n % 10] n//=10 return result FACTORIAL=[math.factorial(i)for i in range(10)] if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var FACTORIAL : Sequence := Integer.subrange(0, 10-1)->select(i | true)->collect(i | (MathLib.factorial(i))) ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LIMIT : double := (10)->pow(6) ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name LIMIT)))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name get_chain_length)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) == (comparison (expr (atom (number (integer 60))))))))))))->sum() ; return ("" + ((ans))); operation get_chain_length(n : OclAny) : OclAny pre: true post: true activity: var seen : Set := Set{}->union(()) ; while true do ( execute ((n) : seen) ; n := factorialize(n) ; if (seen)->includes(n) then ( return (seen)->size() ) else skip); operation factorialize(n : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; while n /= 0 do ( result := result + FACTORIAL[n mod 10+1] ; n := n div 10) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def list_eq(get_num,first): if first==1 : return False for i in range(len(get_num)-1): if get_num[0]!=get_num[i+1]: return False return True a_raw=input().split(' ') b_raw=input().split(' ') a=[int(n)for n in a_raw] b=[int(n)for n in b_raw] get_num=[0 for _ in range(a[0])] first=1 next_num=0 res=0 while list_eq(get_num,first)==False : first=0 weight=[] for i in range(a[1]): weight.append(b[next_num]) get_num[next_num]+=1 next_num+=1 if next_num>a[0]-1 : next_num=0 res+=max(weight)-min(weight) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a_raw : OclAny := input().split(' ') ; var b_raw : OclAny := input().split(' ') ; var a : Sequence := a_raw->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; var b : Sequence := b_raw->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; get_num := Integer.subrange(0, a->first()-1)->select(_anon | true)->collect(_anon | (0)) ; first := 1 ; var next_num : int := 0 ; var res : int := 0 ; while list_eq(get_num, first) = false do ( first := 0 ; var weight : Sequence := Sequence{} ; for i : Integer.subrange(0, a[1+1]-1) do ( execute ((b[next_num+1]) : weight) ; get_num[next_num+1] := get_num[next_num+1] + 1 ; next_num := next_num + 1 ; if (next_num->compareTo(a->first() - 1)) > 0 then ( next_num := 0 ) else skip) ; res := res + (weight)->max() - (weight)->min()) ; execute (res)->display(); operation list_eq(get_num : OclAny, first : OclAny) : OclAny pre: true post: true activity: if first = 1 then ( return false ) else skip ; for i : Integer.subrange(0, (get_num)->size() - 1-1) do ( if get_num->first() /= get_num[i + 1+1] then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 def LI(): return list(map(int,input().split())) def LF(): return list(map(float,input().split())) def II(): return int(input()) def LS(): return input().split() def S(): return input() def main(): n,m=LI() a=LI() r=0 i=0 while True : mi=ma=a[i % n] for j in range(1,m): t=a[(i+j)% n] if mi>t : mi=t elif mapow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LF() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["double"])->apply(_x) )); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return input().split(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation main() : OclAny pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := LI() ; var a : OclAny := LI() ; var r : int := 0 ; var i : int := 0 ; while true do ( var mi : OclAny := a[i mod n+1]; var ma : OclAny := a[i mod n+1] ; for j : Integer.subrange(1, m-1) do ( var t : OclAny := a[(i + j) mod n+1] ; if (mi->compareTo(t)) > 0 then ( mi := t ) else (if (ma->compareTo(t)) < 0 then ( ma := t ) else skip)) ; r := r + ma - mi ; i := i + m ; if i mod n = 0 then ( break ) else skip) ; return r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def GCD(a,b): while(b): a,b=b,a % b return(a) def LCM(a,b): return(a*b//GCD(a,b)) def main(): N,M=map(int,input().split()) A=list(map(int,input().split())) lcm=LCM(N,M) l=[] if(N!=lcm): for i in range(lcm//N): for j in range(N): l.append(A[j]) else : l=A ans=0 for i in range(lcm//M): temp=[] for j in range(M): temp.append(l[M*i+j]) ans+=max(temp)-min(temp) print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation GCD(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: while (b) do ( Sequence{a,b} := Sequence{b,a mod b}) ; return (a); operation LCM(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a * b div GCD(a, b)); operation main() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lcm : OclAny := LCM(N, M) ; var l : Sequence := Sequence{} ; if (N /= lcm) then ( for i : Integer.subrange(0, lcm div N-1) do ( for j : Integer.subrange(0, N-1) do ( execute ((A[j+1]) : l))) ) else ( l := A ) ; var ans : int := 0 ; for i : Integer.subrange(0, lcm div M-1) do ( var temp : Sequence := Sequence{} ; for j : Integer.subrange(0, M-1) do ( execute ((l[M * i + j+1]) : temp)) ; ans := ans + (temp)->max() - (temp)->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd n,m=map(int,input().split()) alst=list(map(int,input().split())) loop=m//gcd(n,m) alst=alst*loop ans=0 for i in range(0,loop*n,m): ans+=max(alst[i : i+m])-min(alst[i : i+m]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var alst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var loop : int := m div gcd(n, m) ; alst := MatrixLib.elementwiseMult(alst, loop) ; var ans : int := 0 ; for i : Integer.subrange(0, loop * n-1)->select( $x | ($x - 0) mod m = 0 ) do ( ans := ans + (alst.subrange(i+1, i + m))->max() - (alst.subrange(i+1, i + m))->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def phi(n): result=n p=2 while(p*p<=n): if(n % p==0): while(n % p==0): n=n//p result=result*(1.0-(1.0/(float)(p))) p=p+1 if(n>1): result=result*(1.0-(1.0/(float)(n))) return(int)(result) for n in range(1,11): print("phi(",n,")=",phi(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for n : Integer.subrange(1, 11-1) do ( execute ("phi(")->display()); operation phi(n : OclAny) : OclAny pre: true post: true activity: var result : OclAny := n ; var p : int := 2 ; while ((p * p->compareTo(n)) <= 0) do ( if (n mod p = 0) then ( while (n mod p = 0) do ( n := n div p) ; result := result * (1.0 - (1.0 / (OclType["double"])(p))) ) else skip ; p := p + 1) ; if (n > 1) then ( result := result * (1.0 - (1.0 / (OclType["double"])(n))) ) else skip ; return (OclType["int"])(result); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def phi(n): result=n ; p=2 ; while(p*p<=n): if(n % p==0): while(n % p==0): n=int(n/p); result-=int(result/p); p+=1 ; if(n>1): result-=int(result/n); return result ; for n in range(1,11): print("phi(",n,")=",phi(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for n : Integer.subrange(1, 11-1) do ( execute ("phi(")->display();); operation phi(n : OclAny) pre: true post: true activity: var result : OclAny := n; ; var p : int := 2; ; while ((p * p->compareTo(n)) <= 0) do ( if (n mod p = 0) then ( while (n mod p = 0) do ( n := ("" + ((n / p)))->toInteger();) ; result := result - ("" + ((result / p)))->toInteger(); ) else skip ; p := p + 1;) ; if (n > 1) then ( result := result - ("" + ((result / n)))->toInteger(); ) else skip ; return result;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s,a,b=input(),input(),input() rs=s[: :-1] a1=s.find(a); a2=rs.find(a) if a1<0 : if a2<0 : print('fantasy'); exit() b2=rs[a2+len(a):].find(b) print('fantasy' if b2<0 else 'backward') else : b1=s[a1+len(a):].find(b) if a2<0 : print('fantasy' if b1<0 else 'forward'); exit() b2=rs[a2+len(a):].find(b) if b1<0 : print('fantasy' if b2<0 else 'backward') else : print('forward' if b2<0 else 'both') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{s,a,b} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine()} ; var rs : OclAny := s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var a1 : int := s->indexOf(a) - 1; var a2 : int := rs->indexOf(a) - 1 ; if a1 < 0 then ( if a2 < 0 then ( execute ('fantasy')->display(); exit() ) else skip ; var b2 : OclAny := rs.subrange(a2 + (a)->size()+1)->indexOf(b) - 1 ; execute (if b2 < 0 then 'fantasy' else 'backward' endif)->display() ) else ( var b1 : OclAny := s.subrange(a1 + (a)->size()+1)->indexOf(b) - 1 ; if a2 < 0 then ( execute (if b1 < 0 then 'fantasy' else 'forward' endif)->display(); exit() ) else skip ; b2 := rs.subrange(a2 + (a)->size()+1)->indexOf(b) - 1 ; if b1 < 0 then ( execute (if b2 < 0 then 'fantasy' else 'backward' endif)->display() ) else ( execute (if b2 < 0 then 'forward' else 'both' endif)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def helper(a,flag1,flag2): chk1,chk2=False,False n=len(a) i=0 while idisplay() ) else (if (forward) then ( execute ("forward")->display() ) else (if (backward) then ( execute ("backward")->display() ) else ( execute ("fantasy")->display() ) ) ) ; operation helper(a : OclAny, flag1 : OclAny, flag2 : OclAny) : OclAny pre: true post: true activity: var chk1 : OclAny := null; var chk2 : OclAny := null; Sequence{chk1,chk2} := Sequence{false,false} ; var n : int := (a)->size() ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( if a.subrange(i+1, i + (flag1)->size()) = flag1 & not(chk1) then ( var chk1 : boolean := true ; i := i + (flag1)->size() ; continue ) else skip ; if a.subrange(i+1, i + (flag2)->size()) = flag2 & chk1 then ( var chk2 : boolean := true ) else skip ; i := i + 1) ; return chk1 & chk2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s,x,y,t=input(),input(),input(),0 e=s[: :-1] if x in s : q=s.index(x)+len(x) if y in s[q :]: t+=1 if x in e : q=e.index(x)+len(x) if y in e[q :]: t+=2 print(["fantasy","forward","backward","both"][t]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := null; var x : OclAny := null; var y : OclAny := null; var t : OclAny := null; Sequence{s,x,y,t} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine(),0} ; var e : OclAny := s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; if (s)->includes(x) then ( var q : int := s->indexOf(x) - 1 + (x)->size() ; if (s.subrange(q+1))->includes(y) then ( t := t + 1 ) else skip ) else skip ; if (e)->includes(x) then ( q := e->indexOf(x) - 1 + (x)->size() ; if (e.subrange(q+1))->includes(y) then ( t := t + 2 ) else skip ) else skip ; execute (Sequence{"fantasy"}->union(Sequence{"forward"}->union(Sequence{"backward"}->union(Sequence{ "both" })))[t+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dimensions=input().split(' ') n=int(dimensions[0]) m=int(dimensions[1]) dir_horiz=input() dir_vert=input() answer=True if not(dir_horiz[0]=='<' or(dir_vert[0]=='^' and dir_vert[-1]=='v' and '<' in dir_horiz)): answer=False if not(dir_horiz[-1]=='>' or(dir_vert[0]=='^' and dir_vert[-1]=='v' and '>' in dir_horiz)): answer=False if not(dir_vert[0]=='v' or(dir_horiz[0]=='>' and dir_horiz[-1]=='<' and 'v' in dir_vert)): answer=False if not(dir_vert[-1]=='^' or(dir_horiz[0]=='>' and dir_horiz[-1]=='<' and '^' in dir_vert)): answer=False if answer : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dimensions : OclAny := input().split(' ') ; var n : int := ("" + ((dimensions->first())))->toInteger() ; var m : int := ("" + ((dimensions[1+1])))->toInteger() ; var dir_horiz : String := (OclFile["System.in"]).readLine() ; var dir_vert : String := (OclFile["System.in"]).readLine() ; var answer : boolean := true ; if not((dir_horiz->first() = '<' or (dir_vert->first() = '^' & dir_vert->last() = 'v' & (dir_horiz)->characters()->includes('<')))) then ( answer := false ) else skip ; if not((dir_horiz->last() = '>' or (dir_vert->first() = '^' & dir_vert->last() = 'v' & (dir_horiz)->characters()->includes('>')))) then ( answer := false ) else skip ; if not((dir_vert->first() = 'v' or (dir_horiz->first() = '>' & dir_horiz->last() = '<' & (dir_vert)->characters()->includes('v')))) then ( answer := false ) else skip ; if not((dir_vert->last() = '^' or (dir_horiz->first() = '>' & dir_horiz->last() = '<' & (dir_vert)->characters()->includes('^')))) then ( answer := false ) else skip ; if answer then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def colourVisible(height,colour,K): arr=[0 for i in range(K+1)] visible=0 max=height[K-1] arr[colour[K-1]]=1 i=K-2 while(i>=0): if(height[i]>max): max=height[i] arr[colour[i]]=1 i-=1 for i in range(1,K+1,1): if(arr[i]==1): visible+=1 return visible if __name__=='__main__' : height=[3,5,1,2,3] colour=[1,2,3,4,3] K=len(colour) print(colourVisible(height,colour,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( height := Sequence{3}->union(Sequence{5}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })))) ; colour := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 3 })))) ; K := (colour)->size() ; execute (colourVisible(height, colour, K))->display() ) else skip; operation colourVisible(height : OclAny, colour : OclAny, K : OclAny) : OclAny pre: true post: true activity: var arr : Sequence := Integer.subrange(0, K + 1-1)->select(i | true)->collect(i | (0)) ; var visible : int := 0 ; var max : OclAny := height[K - 1+1] ; arr[colour[K - 1+1]+1] := 1 ; var i : double := K - 2 ; while (i >= 0) do ( if ((height[i+1]->compareTo(max)) > 0) then ( max := height[i+1] ; arr[colour[i+1]+1] := 1 ) else skip ; i := i - 1) ; for i : Integer.subrange(1, K + 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if (arr[i+1] = 1) then ( visible := visible + 1 ) else skip) ; return visible; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() a=input() b=input() if s.find(a)!=-1 and s[: :-1].find(a)!=-1 : i=s.find(a)+len(a) j=s[: :-1].find(a)+len(a) if s[i :].find(b)!=-1 and s[: :-1][j :].find(b)!=-1 : print("both") else : if s[i :].find(b)!=-1 : print("forward") elif s[: :-1][j :].find(b)!=-1 : print("backward") else : print("fantasy") elif s.find(a)!=-1 : i=s.find(a)+len(a) if s[i :].find(b)!=-1 : print("forward") else : print("fantasy") elif s[: :-1].find(a)!=-1 : j=s[: :-1].find(a)+len(a) if s[: :-1][j :].find(b)!=-1 : print("backward") else : print("fantasy") else : print("fantasy") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; if s->indexOf(a) - 1 /= -1 & s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->indexOf(a) - 1 /= -1 then ( var i : int := s->indexOf(a) - 1 + (a)->size() ; var j : OclAny := s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->indexOf(a) - 1 + (a)->size() ; if s.subrange(i+1)->indexOf(b) - 1 /= -1 & s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))).subrange(j+1)->indexOf(b) - 1 /= -1 then ( execute ("both")->display() ) else ( if s.subrange(i+1)->indexOf(b) - 1 /= -1 then ( execute ("forward")->display() ) else (if s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))).subrange(j+1)->indexOf(b) - 1 /= -1 then ( execute ("backward")->display() ) else ( execute ("fantasy")->display() ) ) ) ) else (if s->indexOf(a) - 1 /= -1 then ( i := s->indexOf(a) - 1 + (a)->size() ; if s.subrange(i+1)->indexOf(b) - 1 /= -1 then ( execute ("forward")->display() ) else ( execute ("fantasy")->display() ) ) else (if s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->indexOf(a) - 1 /= -1 then ( j := s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->indexOf(a) - 1 + (a)->size() ; if s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))).subrange(j+1)->indexOf(b) - 1 /= -1 then ( execute ("backward")->display() ) else ( execute ("fantasy")->display() ) ) else ( execute ("fantasy")->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=input() c=input() m=0 if c in a[a.find(b)+len(b):]and b in a and c in a : m=1 a=a[: :-1] if c in a[a.find(b)+len(b):]: if m==1 : m=3 else : m=2 if m==1 : print('forward') elif m==2 : print('backward') elif m==3 : print('both') else : print('fantasy') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var c : String := (OclFile["System.in"]).readLine() ; var m : int := 0 ; if (a.subrange(a->indexOf(b) - 1 + (b)->size()+1))->includes(c) & (a)->characters()->includes(b) & (a)->characters()->includes(c) then ( m := 1 ) else skip ; a := a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; if (a.subrange(a->indexOf(b) - 1 + (b)->size()+1))->includes(c) then ( if m = 1 then ( m := 3 ) else ( m := 2 ) ) else skip ; if m = 1 then ( execute ('forward')->display() ) else (if m = 2 then ( execute ('backward')->display() ) else (if m = 3 then ( execute ('both')->display() ) else ( execute ('fantasy')->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B,C,X,Y=map(int,input().split()) AB_flag=C*2<=A+B total=0 if AB_flag : if X>=Y : total=C*2*Y if C*2>=A : total+=(X-Y)*A else : total+=(X-Y)*C*2 else : total=C*2*X if C*2>=B : total+=(Y-X)*B else : total+=(Y-X)*C*2 else : total=A*X+B*Y print(total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var X : OclAny := null; var Y : OclAny := null; Sequence{A,B,C,X,Y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var AB_flag : boolean := (C * 2->compareTo(A + B)) <= 0 ; var total : int := 0 ; if AB_flag then ( if (X->compareTo(Y)) >= 0 then ( total := C * 2 * Y ; if (C * 2->compareTo(A)) >= 0 then ( total := total + (X - Y) * A ) else ( total := total + (X - Y) * C * 2 ) ) else ( total := C * 2 * X ; if (C * 2->compareTo(B)) >= 0 then ( total := total + (Y - X) * B ) else ( total := total + (Y - X) * C * 2 ) ) ) else ( total := A * X + B * Y ) ; execute (total)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(a,b,c,x,y): if 2*c>=a+b : return a*x+b*y m=min(x,y) return 2*c*m+min(a,2*c)*(x-m)+min(b,2*c)*(y-m) def main(): a,b,c,x,y=map(int,input().split()) print(solve(a,b,c,x,y)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(a : OclAny, b : OclAny, c : OclAny, x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (2 * c->compareTo(a + b)) >= 0 then ( return a * x + b * y ) else skip ; var m : OclAny := Set{x, y}->min() ; return 2 * c * m + Set{a, 2 * c}->min() * (x - m) + Set{b, 2 * c}->min() * (y - m); operation main() pre: true post: true activity: Sequence{a,b,c,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (solve(a, b, c, x, y))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys A,B,C,X,Y=map(int,input().split()) a=min(A,2*C) b=min(B,2*C) ab=min(A+B,2*C) cost=0 if ab<(a+b): if X==Y : print(ab*X) sys.exit() elif X>Y : cost+=ab*Y if ab<=a : cost+=ab*(X-Y) print(cost) sys.exit() else : cost+=a*(X-Y) print(cost) sys.exit() else : cost+=ab*X if ab<=b : cost+=ab*(Y-X) print(cost) sys.exit() else : cost+=b*(Y-X) print(cost) sys.exit() else : print(a*X+b*Y) sys.exit() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var X : OclAny := null; var Y : OclAny := null; Sequence{A,B,C,X,Y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := Set{A, 2 * C}->min() ; var b : OclAny := Set{B, 2 * C}->min() ; var ab : OclAny := Set{A + B, 2 * C}->min() ; var cost : int := 0 ; if (ab->compareTo((a + b))) < 0 then ( if X = Y then ( execute (ab * X)->display() ; sys.exit() ) else (if (X->compareTo(Y)) > 0 then ( cost := cost + ab * Y ; if (ab->compareTo(a)) <= 0 then ( cost := cost + ab * (X - Y) ; execute (cost)->display() ; sys.exit() ) else ( cost := cost + a * (X - Y) ; execute (cost)->display() ; sys.exit() ) ) else ( cost := cost + ab * X ; if (ab->compareTo(b)) <= 0 then ( cost := cost + ab * (Y - X) ; execute (cost)->display() ; sys.exit() ) else ( cost := cost + b * (Y - X) ; execute (cost)->display() ; sys.exit() ) ) ) ) else ( execute (a * X + b * Y)->display() ; sys.exit() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inline=list(map(int,input().split())) A=inline[0] B=inline[1] C=inline[2] X=inline[3] Y=inline[4] kouho1=A*X+B*Y less=min(X,Y) many=max(X,Y) if A+B>2*C : kouho1-=less*(A+B-2*C) kouho2=many*2*C print(min(kouho1,kouho2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inline : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var A : OclAny := inline->first() ; var B : OclAny := inline[1+1] ; var C : OclAny := inline[2+1] ; var X : OclAny := inline[3+1] ; var Y : OclAny := inline[4+1] ; var kouho1 : double := A * X + B * Y ; var less : OclAny := Set{X, Y}->min() ; var many : OclAny := Set{X, Y}->max() ; if (A + B->compareTo(2 * C)) > 0 then ( kouho1 := kouho1 - less * (A + B - 2 * C) ) else skip ; var kouho2 : double := many * 2 * C ; execute (Set{kouho1, kouho2}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,x,y=list(map(int,input().split(" "))) print(min(map(lambda i : max(0,x-(i//2))*a+max(0,y-(i//2))*b+i*c,range(0,max(x,y)*2+2,2)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{a,b,c,x,y} := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; execute (((Integer.subrange(0, Set{x, y}->max() * 2 + 2-1)->select( $x | ($x - 0) mod 2 = 0 ))->collect( _x | (lambda i : OclAny in (Set{0, x - (i div 2)}->max() * a + Set{0, y - (i div 2)}->max() * b + i * c))->apply(_x) ))->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for TT in range(T): aaa=input().split(" ") n=int(aaa[0]) k=int(aaa[1]) print(pow(n,k,int(1e9+7))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for TT : Integer.subrange(0, T-1) do ( var aaa : OclAny := input().split(" ") ; var n : int := ("" + ((aaa->first())))->toInteger() ; var k : int := ("" + ((aaa[1+1])))->toInteger() ; execute ((n)->pow(k))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,k=map(int,input().split()) print((n**k)%(10**9+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (((n)->pow(k)) mod ((10)->pow(9) + 7))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for pratyush in range(int(input())): n,k=list(map(int,input().split())) print((n**k)%(10**9+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for pratyush : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (((n)->pow(k)) mod ((10)->pow(9) + 7))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s,t=input(),input() freqs=dict() freqt=dict() yay,whoops=0,0 for letra in s : if letra in freqs : freqs[letra]+=1 else : freqs[letra]=1 for letra in t : if letra in freqt : freqt[letra]+=1 else : freqt[letra]=1 for letra in freqs.keys(): while(freqs[letra]>0 and letra in freqt and freqt[letra]>0): yay+=1 freqs[letra]-=1 freqt[letra]-=1 for letra in freqs.keys(): while(freqs[letra]>0): if letra.islower()and letra.upper()in freqt.keys()and freqt[letra.upper()]>0 : whoops+=1 freqs[letra]-=1 freqt[letra.upper()]-=1 elif letra.isupper()and letra.lower()in freqt.keys()and freqt[letra.lower()]>0 : whoops+=1 freqs[letra]-=1 freqt[letra.lower()]-=1 else : break ; print(yay,whoops) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine()} ; var freqs : Map := (arguments ( )) ; var freqt : Map := (arguments ( )) ; var yay : OclAny := null; var whoops : OclAny := null; Sequence{yay,whoops} := Sequence{0,0} ; for letra : s do ( if (freqs)->includes(letra) then ( freqs[letra+1] := freqs[letra+1] + 1 ) else ( freqs[letra+1] := 1 )) ; for letra : t do ( if (freqt)->includes(letra) then ( freqt[letra+1] := freqt[letra+1] + 1 ) else ( freqt[letra+1] := 1 )) ; for letra : freqs.keys() do ( while (freqs[letra+1] > 0 & (freqt)->includes(letra) & freqt[letra+1] > 0) do ( yay := yay + 1 ; freqs[letra+1] := freqs[letra+1] - 1 ; freqt[letra+1] := freqt[letra+1] - 1)) ; for letra : freqs.keys() do ( while (freqs[letra+1] > 0) do ( if letra->matches("[a-z ]*") & (freqt.keys())->includes(letra->toUpperCase()) & freqt[letra->toUpperCase()+1] > 0 then ( whoops := whoops + 1 ; freqs[letra+1] := freqs[letra+1] - 1 ; freqt[letra->toUpperCase()+1] := freqt[letra->toUpperCase()+1] - 1 ) else (if letra->matches("[A-Z ]*") & (freqt.keys())->includes(letra->toLowerCase()) & freqt[letra->toLowerCase()+1] > 0 then ( whoops := whoops + 1 ; freqs[letra+1] := freqs[letra+1] - 1 ; freqt[letra->toLowerCase()+1] := freqt[letra->toLowerCase()+1] - 1 ) else ( break; ) ) )) ; execute (yay)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import log,trunc def checkPowerof8(n): i=log(n,8) return(i-trunc(i)<0.000001); n=65 if checkPowerof8(n): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 65 ; if checkPowerof8(n) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation checkPowerof8(n : OclAny) pre: true post: true activity: var i : OclAny := log(n, 8) ; return (i - trunc(i) < 0.000001);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input_1=input().split() [n,m]=list(map(int,input_1)) input_n=input() input_m=input() n_list=[*input_n] m_list=[*input_m] if(n_list[0]=="<" and m_list[0]=="^")or(n_list[0]==">" and m_list[m-1]=="^")or(n_list[n-1]==">" and m_list[m-1]=="v")or(n_list[n-1]=="<" and m_list[0]=="v"): print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var input_1 : OclAny := input().split() ; Sequence{n}->union(Sequence{ m }) := ((inputOclType["int"], inputOclType["int"])->collect( _x | (OclType["int"])->apply(_x) )) ; var input_n : String := (OclFile["System.in"]).readLine() ; var input_m : String := (OclFile["System.in"]).readLine() ; var n_list : Sequence := input_n ; var m_list : Sequence := input_m ; if (n_list->first() = "<" & m_list->first() = "^") or (n_list->first() = ">" & m_list[m - 1+1] = "^") or (n_list[n - 1+1] = ">" & m_list[m - 1+1] = "v") or (n_list[n - 1+1] = "<" & m_list->first() = "v") then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b=map(int,input().split()) print(a**b %(10**9+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a)->pow(b) mod ((10)->pow(9) + 7))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split(' ')) print((n**k)%(10**9+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; execute (((n)->pow(k)) mod ((10)->pow(9) + 7))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- K,S=map(int,input().split()) c=0 for x in range(K+1): if x>S : break for y in range(S-x+1): if y>K : break z=S-x-y if 0<=z<=K : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var K : OclAny := null; var S : OclAny := null; Sequence{K,S} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : int := 0 ; for x : Integer.subrange(0, K + 1-1) do ( if (x->compareTo(S)) > 0 then ( break ) else skip ; for y : Integer.subrange(0, S - x + 1-1) do ( if (y->compareTo(K)) > 0 then ( break ) else skip ; var z : double := S - x - y ; if 0 <= z & (z <= K) then ( c := c + 1 ) else skip)) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k,s=map(int,input().split()) counter=0 for z in range(0,k+1): if 2*kcollect( _x | (OclType["int"])->apply(_x) ) ; var counter : int := 0 ; for z : Integer.subrange(0, k + 1-1) do ( if (2 * k->compareTo(s - z)) < 0 then ( continue ) else skip ; for y : Integer.subrange(0, k + 1-1) do ( if (k + y + z->compareTo(s)) < 0 then ( continue ) else (if s - y - z < 0 then ( break ) else ( counter := counter + 1 ) ) )) ; execute (counter)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- K,S=map(int,input().split()) print(sum([1 for j in range(0,K+1)for i in range(0,K+1)if 0<=S-i-j<=K])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var K : OclAny := null; var S : OclAny := null; Sequence{K,S} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Integer.subrange(0, K + 1-1)->select(j; i : Integer.subrange(0, K + 1-1) | true)->collect(j; i : Integer.subrange(0, K + 1-1) | (1)))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- K,S=input().strip().split() K,S=[int(K),int(S)] A=0 for x in range(K+1): for y in range(K+1): if S-x-y<=K and S-x-y>=0 : A=A+1 print(A) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var K : OclAny := null; var S : OclAny := null; Sequence{K,S} := input()->trim().split() ; var K : OclAny := null; var S : OclAny := null; Sequence{K,S} := Sequence{("" + ((K)))->toInteger()}->union(Sequence{ ("" + ((S)))->toInteger() }) ; var A : int := 0 ; for x : Integer.subrange(0, K + 1-1) do ( for y : Integer.subrange(0, K + 1-1) do ( if (S - x - y->compareTo(K)) <= 0 & S - x - y >= 0 then ( A := A + 1 ) else skip)) ; execute (A)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): k,s=list(map(int,input().split())) ans=0 for x in range(k+1): for y in range(k+1): z=s-x-y if z>=0 and z<=k : ans+=1 print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var k : OclAny := null; var s : OclAny := null; Sequence{k,s} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for x : Integer.subrange(0, k + 1-1) do ( for y : Integer.subrange(0, k + 1-1) do ( var z : double := s - x - y ; if z >= 0 & (z->compareTo(k)) <= 0 then ( ans := ans + 1 ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): LIMIT=51 ans=sum(1 for x1 in range(LIMIT)for y1 in range(LIMIT)for x2 in range(LIMIT)for y2 in range(LIMIT)if y2*x1display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LIMIT : int := 51 ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name x1)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name LIMIT)))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name y1)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name LIMIT)))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name x2)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name LIMIT)))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name y2)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name LIMIT)))))))) )))))) (comp_iter if (test (logical_test (logical_test (comparison (comparison (expr (expr (atom (name y2))) * (expr (atom (name x1))))) < (comparison (expr (expr (atom (name y1))) * (expr (atom (name x2))))))) and (logical_test (comparison (expr (atom (name is_right_triangle)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x1))))))) , (argument (test (logical_test (comparison (expr (atom (name y1))))))) , (argument (test (logical_test (comparison (expr (atom (name x2))))))) , (argument (test (logical_test (comparison (expr (atom (name y2)))))))) ))))))))))))))))))->sum() ; return ("" + ((ans))); operation is_right_triangle(x1 : OclAny, y1 : OclAny, x2 : OclAny, y2 : OclAny) : OclAny pre: true post: true activity: var a : double := (x1)->pow(2) + (y1)->pow(2) ; var b : double := (x2)->pow(2) + (y2)->pow(2) ; var c : double := ((x2 - x1))->pow(2) + ((y2 - y1))->pow(2) ; return (a + b = c) or (b + c = a) or (c + a = b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def permutatedRows(mat,m,n,r): s=set() for j in range(n): s.add(mat[r][j]) for i in range(m): if i==r : continue for j in range(n): if mat[i][j]not in s : j=j-2 break ; if j+1!=n : continue print(i) m=4 n=4 r=3 mat=[[3,1,4,2],[1,6,9,3],[1,2,3,4],[4,3,2,1]] permutatedRows(mat,m,n,r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; m := 4 ; n := 4 ; r := 3 ; mat := Sequence{Sequence{3}->union(Sequence{1}->union(Sequence{4}->union(Sequence{ 2 })))}->union(Sequence{Sequence{1}->union(Sequence{6}->union(Sequence{9}->union(Sequence{ 3 })))}->union(Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })))}->union(Sequence{ Sequence{4}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 1 }))) }))) ; permutatedRows(mat, m, n, r); operation permutatedRows(mat : OclAny, m : OclAny, n : OclAny, r : OclAny) pre: true post: true activity: var s : Set := Set{}->union(()) ; for j : Integer.subrange(0, n-1) do ( execute ((mat[r+1][j+1]) : s)) ; for i : Integer.subrange(0, m-1) do ( if i = r then ( continue ) else skip ; for j : Integer.subrange(0, n-1) do ( if (s)->excludes(mat[i+1][j+1]) then ( var j : double := j - 2 ; break; ) else skip) ; if j + 1 /= n then ( continue ) else skip ; execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b=map(int,input().split()) if a==b : print((a+b)//4) else : print(min(min(a,b),(a+b)//4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = b then ( execute ((a + b) div 4)->display() ) else ( execute (Set{Set{a, b}->min(), (a + b) div 4}->min())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- code=list(input()) even=1 total=0 ind=1 while ind<=len(code)-1 : if code[ind]==code[ind-1]or even==0 : even+=1 else : if even % 2==0 : total+=1 even=1 ind+=1 if even % 2==0 : total+=1 print(total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var code : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var even : int := 1 ; var total : int := 0 ; var ind : int := 1 ; while (ind->compareTo((code)->size() - 1)) <= 0 do ( if code[ind+1] = code[ind - 1+1] or even = 0 then ( even := even + 1 ) else ( if even mod 2 = 0 then ( total := total + 1 ) else skip ; even := 1 ) ; ind := ind + 1) ; if even mod 2 = 0 then ( total := total + 1 ) else skip ; execute (total)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dimensions=input().split(' ') n=int(dimensions[0]) m=int(dimensions[1]) dir_horiz=input() dir_vert=input() answer=True if not(dir_horiz[0]=='<' or(dir_vert[0]=='^' and dir_vert[-1]=='v' and '<' in dir_horiz)): answer=False if not(dir_horiz[-1]=='>' or(dir_vert[0]=='^' and dir_vert[-1]=='v' and '>' in dir_horiz)): answer=False if not(dir_vert[0]=='v' or(dir_horiz[0]=='>' and dir_horiz[-1]=='<' and 'v' in dir_vert)): answer=False if not(dir_vert[-1]=='^' or(dir_horiz[0]=='>' and dir_horiz[-1]=='<' and '^' in dir_vert)): answer=False if answer : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dimensions : OclAny := input().split(' ') ; var n : int := ("" + ((dimensions->first())))->toInteger() ; var m : int := ("" + ((dimensions[1+1])))->toInteger() ; var dir_horiz : String := (OclFile["System.in"]).readLine() ; var dir_vert : String := (OclFile["System.in"]).readLine() ; var answer : boolean := true ; if not((dir_horiz->first() = '<' or (dir_vert->first() = '^' & dir_vert->last() = 'v' & (dir_horiz)->characters()->includes('<')))) then ( answer := false ) else skip ; if not((dir_horiz->last() = '>' or (dir_vert->first() = '^' & dir_vert->last() = 'v' & (dir_horiz)->characters()->includes('>')))) then ( answer := false ) else skip ; if not((dir_vert->first() = 'v' or (dir_horiz->first() = '>' & dir_horiz->last() = '<' & (dir_vert)->characters()->includes('v')))) then ( answer := false ) else skip ; if not((dir_vert->last() = '^' or (dir_horiz->first() = '>' & dir_horiz->last() = '<' & (dir_vert)->characters()->includes('^')))) then ( answer := false ) else skip ; if answer then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[] s=input() cnt=1 for i in range(1,len(s)): if s[i]==s[i-1]: cnt+=1 else : a.append(cnt) cnt=1 a.append(cnt) cnt=0 for i in range(len(a)): if a[i]% 2==0 : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Sequence{} ; var s : String := (OclFile["System.in"]).readLine() ; var cnt : int := 1 ; for i : Integer.subrange(1, (s)->size()-1) do ( if s[i+1] = s[i - 1+1] then ( cnt := cnt + 1 ) else ( execute ((cnt) : a) ; cnt := 1 )) ; execute ((cnt) : a) ; cnt := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( if a[i+1] mod 2 = 0 then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() ans=0 sum=1 j=s[0] for i in range(1,len(s)): if s[i]==j : sum+=1 else : if sum % 2==0 : ans+=1 j=s[i] sum=1 if sum % 2==0 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; var sum : int := 1 ; var j : OclAny := s->first() ; for i : Integer.subrange(1, (s)->size()-1) do ( if s[i+1] = j then ( sum := sum + 1 ) else ( if sum mod 2 = 0 then ( ans := ans + 1 ) else skip ; j := s[i+1] ; sum := 1 )) ; if sum mod 2 = 0 then ( ans := ans + 1 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import groupby print(sum([1 for i,j in groupby(input())if len(list(j))% 2==0])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute ((groupby((OclFile["System.in"]).readLine())->select(_tuple | let i : OclAny = _tuple->at(1) in let j : OclAny = _tuple->at(2) in ((j))->size() mod 2 = 0)->collect(_tuple | let i : OclAny = _tuple->at(1) in let j : OclAny = _tuple->at(2) in (1)))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[] s=input() cnt=1 for i in range(1,len(s)): if s[i]==s[i-1]: cnt+=1 else : a.append(cnt) cnt=1 a.append(cnt) cnt=0 for i in range(len(a)): if a[i]% 2==0 : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Sequence{} ; var s : String := (OclFile["System.in"]).readLine() ; var cnt : int := 1 ; for i : Integer.subrange(1, (s)->size()-1) do ( if s[i+1] = s[i - 1+1] then ( cnt := cnt + 1 ) else ( execute ((cnt) : a) ; cnt := 1 )) ; execute ((cnt) : a) ; cnt := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( if a[i+1] mod 2 = 0 then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- allPrimes=[]; def sieve(n): prime=[True]*(n+1); p=2 ; while(p*p<=n): if(prime[p]==True): for i in range(p*2,n+1,p): prime[i]=False ; p+=1 ; for p in range(2,n+1): if(prime[p]): allPrimes.append(p); def factorialDivisors(n): sieve(n); result=1 ; for i in range(len(allPrimes)): p=allPrimes[i]; exp=0 ; while(p<=n): exp=exp+int(n/p); p=p*allPrimes[i]; result=int(result*(pow(allPrimes[i],exp+1)-1)/(allPrimes[i]-1)); return result ; print(factorialDivisors(4)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var allPrimes : Sequence := Sequence{}; ; skip ; skip ; execute (factorialDivisors(4))->display();; operation sieve(n : OclAny) pre: true post: true activity: var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (n + 1)); ; var p : int := 2; ; while ((p * p->compareTo(n)) <= 0) do ( if (prime[p+1] = true) then ( for i : Integer.subrange(p * 2, n + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false;) ) else skip ; p := p + 1;) ; for p : Integer.subrange(2, n + 1-1) do ( if (prime[p+1]) then ( execute ((p) : allPrimes); ) else skip); operation factorialDivisors(n : OclAny) pre: true post: true activity: sieve(n); ; var result : int := 1; ; for i : Integer.subrange(0, (allPrimes)->size()-1) do ( p := allPrimes[i+1]; ; var exp : int := 0; ; while ((p->compareTo(n)) <= 0) do ( exp := exp + ("" + ((n / p)))->toInteger(); ; p := p * allPrimes[i+1];) ; result := ("" + ((result * ((allPrimes[i+1])->pow(exp + 1) - 1) / (allPrimes[i+1] - 1))))->toInteger();) ; return result;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- allPrimes=[]; def sieve(n): prime=[True]*(n+1); p=2 ; while(p*p<=n): if(prime[p]==True): i=p*2 ; while(i<=n): prime[i]=False ; i+=p ; p+=1 ; for p in range(2,n+1): if(prime[p]): allPrimes.append(p); def factorialDivisors(n): sieve(n); result=1 ; for i in range(len(allPrimes)): p=allPrimes[i]; exp=0 ; while(p<=n): exp=exp+int(n/p); p=p*allPrimes[i]; result=result*(exp+1); return result ; print(factorialDivisors(6)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var allPrimes : Sequence := Sequence{}; ; skip ; skip ; execute (factorialDivisors(6))->display();; operation sieve(n : OclAny) pre: true post: true activity: var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (n + 1)); ; var p : int := 2; ; while ((p * p->compareTo(n)) <= 0) do ( if (prime[p+1] = true) then ( var i : int := p * 2; ; while ((i->compareTo(n)) <= 0) do ( prime[i+1] := false; ; i := i + p;) ) else skip ; p := p + 1;) ; for p : Integer.subrange(2, n + 1-1) do ( if (prime[p+1]) then ( execute ((p) : allPrimes); ) else skip); operation factorialDivisors(n : OclAny) pre: true post: true activity: sieve(n); ; var result : int := 1; ; for i : Integer.subrange(0, (allPrimes)->size()-1) do ( p := allPrimes[i+1]; ; var exp : int := 0; ; while ((p->compareTo(n)) <= 0) do ( exp := exp + ("" + ((n / p)))->toInteger(); ; p := p * allPrimes[i+1];) ; result := result * (exp + 1);) ; return result;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def post_from_pre_in(preorder_elements,inorder_elements): if preorder_elements : global cnt root=preorder_elements[0] root_index=inorder_elements.index(root) preorder_left=preorder_elements[1 : root_index+1] inorder_left=inorder_elements[: root_index] preorder_right=preorder_elements[root_index+1 :] inorder_right=inorder_elements[root_index+1 :] post_from_pre_in(preorder_left,inorder_left) post_from_pre_in(preorder_right,inorder_right) if cnt : print(root,end=' ') cnt-=1 else : print(root) cnt=int(input())-1 a=list(map(int,input().split())) b=list(map(int,input().split())) post_from_pre_in(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute cnt : OclAny; operation initialise() pre: true post: true activity: skip ; cnt := ("" + (((OclFile["System.in"]).readLine())))->toInteger() - 1 ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; post_from_pre_in(a, b); operation post_from_pre_in(preorder_elements : OclAny, inorder_elements : OclAny) pre: true post: true activity: if preorder_elements then ( skip ; var root : OclAny := preorder_elements->first() ; var root_index : int := inorder_elements->indexOf(root) - 1 ; var preorder_left : OclAny := preorder_elements.subrange(1+1, root_index + 1) ; var inorder_left : OclAny := inorder_elements.subrange(1,root_index) ; var preorder_right : OclAny := preorder_elements.subrange(root_index + 1+1) ; var inorder_right : OclAny := inorder_elements.subrange(root_index + 1+1) ; post_from_pre_in(preorder_left, inorder_left) ; post_from_pre_in(preorder_right, inorder_right) ; if cnt then ( execute (root)->display() ; cnt := cnt - 1 ) else ( execute (root)->display() ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def print_postorder(A,B,n): C=[] def reconstruction(l,r): if l>=r : return c=A.popleft() m=B.index(c) reconstruction(l,m) reconstruction(m+1,r) C.append(c) reconstruction(0,n) print(*C,sep=" ") n=int(input()) A=deque([int(i)for i in input().split()]) B=[int(i)for i in input().split()] print_postorder(A,B,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; A := (input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))) ; B := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; print_postorder(A, B, n); operation print_postorder(A : OclAny, B : OclAny, n : OclAny) pre: true post: true activity: var C : Sequence := Sequence{} ; skip ; reconstruction(0, n) ; execute ((argument * (test (logical_test (comparison (expr (atom (name C))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for k in range(t): a,b=map(int,input().split()) if a>0 and b>0 and a+b>3 : if max(a,b)>=min(a,b)*3 : print(min(a,b)) elif max(a,b)>=min(a,b)*2 : print(max(a,b)//3+(min(a,b)-max(a,b)//3+max(a,b)% 3)//4) elif max(a,b)>min(a,b): print((a+b)//4) elif max(a,b)==min(a,b): print(a//2) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for k : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a > 0 & b > 0 & a + b > 3 then ( if (Set{a, b}->max()->compareTo(Set{a, b}->min() * 3)) >= 0 then ( execute (Set{a, b}->min())->display() ) else (if (Set{a, b}->max()->compareTo(Set{a, b}->min() * 2)) >= 0 then ( execute (Set{a, b}->max() div 3 + (Set{a, b}->min() - Set{a, b}->max() div 3 + Set{a, b}->max() mod 3) div 4)->display() ) else (if (Set{a, b}->max()->compareTo(Set{a, b}->min())) > 0 then ( execute ((a + b) div 4)->display() ) else (if Set{a, b}->max() = Set{a, b}->min() then ( execute (a div 2)->display() ) else skip ) ) ) ) else ( execute (0)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=0 L=1 R=2 P=3 B=4 D=5 H=6 def getidx(Tree,value): idx=-1 for i in range(len(Tree)): if Tree[i][I]==value : idx=i break return idx def search(Tree,A,B,num): root=A[0] rootidx=getidx(Tree,root) ld=num for i in range(num): if B[i]==root : ld=i break if ld>0 : left,lidx=search(Tree,A[1 : ld+1],B[: ld],ld) Tree[rootidx][L]=lidx rt=ld+1 if rtsize()-1) do ( if Tree[i+1][I+1] = value then ( idx := i ; break ) else skip) ; return idx; operation search(Tree : OclAny, A : OclAny, B : OclAny, num : OclAny) : OclAny pre: true post: true activity: var root : OclAny := A->first() ; var rootidx : OclAny := getidx(Tree, root) ; var ld : OclAny := num ; for i : Integer.subrange(0, num-1) do ( if B[i+1] = root then ( ld := i ; break ) else skip) ; if ld > 0 then ( var left : OclAny := null; var lidx : OclAny := null; Sequence{left,lidx} := search(Tree, A.subrange(1+1, ld + 1), B.subrange(1,ld), ld) ; Tree[rootidx+1][L+1] := lidx ) else skip ; var rt : OclAny := ld + 1 ; if (rt->compareTo(num)) < 0 then ( var right : OclAny := null; var ridx : OclAny := null; Sequence{right,ridx} := search(Tree, A.subrange(rt+1), B.subrange(rt+1), num - rt) ; Tree[rootidx+1][R+1] := ridx ) else skip ; return Sequence{root, rootidx}; operation postorder(Tree : OclAny, nidx : OclAny, A : OclAny) pre: true post: true activity: if nidx < 0 then ( return ) else skip ; postorder(Tree, Tree[nidx+1][L+1], A) ; postorder(Tree, Tree[nidx+1][R+1], A) ; execute ((Tree[nidx+1][I+1]) : A); operation main() pre: true post: true activity: num := ("" + ((input()->trim())))->toInteger() ; var plist : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ilist : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var tree : Sequence := Sequence{} ; for i : plist do ( execute ((Sequence{i}->union(Sequence{-1}->union(Sequence{-1}->union(Sequence{-1}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{ 0 }))))))) : tree)) ; var ridx : OclAny := null; Sequence{root,ridx} := search(tree, plist, ilist, num) ; var pos : Sequence := Sequence{} ; postorder(tree, ridx, pos) ; execute (StringLib.sumStringsWithSeparator(((pos)->collect( _x | (OclType["String"])->apply(_x) )), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,name): self.name=name self.left=-1 self.right=-1 self.parent=-1 def mk_tree(Tree,p_order,in_order): tmp_p_order=[] tmp_in_order=[] root=p_order[0] root_ind=0 while(in_order[root_ind]!=root): root_ind+=1 if(root_ind!=0): Tree[root].left=p_order[1] Tree[p_order[1]].parent=root tmp_in_order=in_order[0 : root_ind] tmp_p_order=p_order[1 : root_ind+1] mk_tree(Tree,tmp_p_order,tmp_in_order) if(root_ind!=len(p_order)-1): Tree[root].right=p_order[root_ind+1] Tree[p_order[root_ind+1]].parent=root tmp_in_order=in_order[root_ind+1 :] tmp_p_order=p_order[root_ind+1 :] mk_tree(Tree,tmp_p_order,tmp_in_order) def Postorder(Tree,root,order): if(Tree[root].left!=-1): Postorder(Tree,Tree[root].left,order) if(Tree[root].right!=-1): Postorder(Tree,Tree[root].right,order) order.append(root) n=int(input()) p_order=list(map(int,input().split())) root=p_order[0] in_order=list(map(int,input().split())) Tree=[None] for i in range(n): Tree.append(Node(i+1)) mk_tree(Tree,p_order,in_order) post_order=[] Postorder(Tree,root,post_order) print(" ".join(list(map(str,post_order)))) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute name : int := name; attribute left : int := -1; attribute right : int := -1; attribute parent : int := -1; operation initialise(name : OclAny) : Node pre: true post: true activity: self.name := name ; self.left := -1 ; self.right := -1 ; self.parent := -1; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; p_order := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; root := p_order->first() ; in_order := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; Tree := Sequence{ null } ; for i : Integer.subrange(0, n-1) do ( execute (((Node.newNode()).initialise(i + 1)) : Tree)) ; mk_tree(Tree, p_order, in_order) ; var post_order : Sequence := Sequence{} ; Postorder(Tree, root, post_order) ; execute (StringLib.sumStringsWithSeparator((((post_order)->collect( _x | (OclType["String"])->apply(_x) ))), " "))->display(); operation mk_tree(Tree : OclAny, p_order : OclAny, in_order : OclAny) pre: true post: true activity: var tmp_p_order : Sequence := Sequence{} ; var tmp_in_order : Sequence := Sequence{} ; var root : OclAny := p_order->first() ; var root_ind : int := 0 ; while (in_order[root_ind+1] /= root) do ( root_ind := root_ind + 1) ; if (root_ind /= 0) then ( Tree[root+1].left := p_order[1+1] ; Tree[p_order[1+1]+1].parent := root ; tmp_in_order := in_order.subrange(0+1, root_ind) ; tmp_p_order := p_order.subrange(1+1, root_ind + 1) ; mk_tree(Tree, tmp_p_order, tmp_in_order) ) else skip ; if (root_ind /= (p_order)->size() - 1) then ( Tree[root+1].right := p_order[root_ind + 1+1] ; Tree[p_order[root_ind + 1+1]+1].parent := root ; tmp_in_order := in_order.subrange(root_ind + 1+1) ; tmp_p_order := p_order.subrange(root_ind + 1+1) ; mk_tree(Tree, tmp_p_order, tmp_in_order) ) else skip; operation Postorder(Tree : OclAny, root : OclAny, order : OclAny) pre: true post: true activity: if (Tree[root+1].left /= -1) then ( Postorder(Tree, Tree[root+1].left, order) ) else skip ; if (Tree[root+1].right /= -1) then ( Postorder(Tree, Tree[root+1].right, order) ) else skip ; execute ((root) : order); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import sys l=collections.deque(sys.stdin.readlines()) l.pop() s="" while l : a=0 b=0 for i in range(int(l.popleft())): x,y=map(int,l.popleft().split()) if x>y : a=a+x+y elif xfront() ; var s : String := "" ; while l do ( var a : int := 0 ; var b : int := 0 ; for i : Integer.subrange(0, ("" + ((l->first())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (l->first().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (x->compareTo(y)) > 0 then ( a := a + x + y ) else (if (x->compareTo(y)) < 0 then ( b := b + x + y ) else ( a := a + x ; b := b + y ) ) ) ; s := s + ("" + ((a))) + "" + ("" + ((b))) + "\n") ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(X,Y,Z,V,E,A): dp=[[0.0]*6001 for _ in range(Y+max(V)+1)] dp[0][0]=1.0 for i in range(Y): for j in range(5001): if dp[i][j]<=0.0 : continue for k in V : t=i+k if t>Y : dp[Y][j]+=dp[i][j]/X elif E[t]==1 : dp[min(Y,t+A[t])][j]+=dp[i][j]/X else : dp[t][max(0,j+A[t])]+=dp[i][j]/X s=0 for i in range(5001): if dp[Y][i]<=0.0 : continue s+=i*dp[Y][i] print(int(s)) if __name__=="__main__" : import sys while True : X,Y,Z=map(int,raw_input().split()) if X | Y | Z==0 : sys.exit() V=map(int,raw_input().split()) E=[0]*100 A=[0]*100 for _ in range(Z): n,e,a=map(int,raw_input().split()) E[n]=e if e==3 : A[n]=-a else : A[n]=a solve(X,Y,Z,V,E,A) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( skip ; while true do ( Sequence{X,Y,Z} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if MathLib.bitwiseOr(MathLib.bitwiseOr(X, Y), Z) = 0 then ( sys.exit() ) else skip ; V := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; E := MatrixLib.elementwiseMult(Sequence{ 0 }, 100) ; A := MatrixLib.elementwiseMult(Sequence{ 0 }, 100) ; for _anon : Integer.subrange(0, Z-1) do ( var n : OclAny := null; var e : OclAny := null; var a : OclAny := null; Sequence{n,e,a} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; E[n+1] := e ; if e = 3 then ( A[n+1] := -a ) else ( A[n+1] := a )) ; solve(X, Y, Z, V, E, A)) ) else skip; operation solve(X : OclAny, Y : OclAny, Z : OclAny, V : OclAny, E : OclAny, A : OclAny) pre: true post: true activity: var dp : Sequence := Integer.subrange(0, Y + (V)->max() + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0.0 }, 6001))) ; dp->first()->first() := 1.0 ; for i : Integer.subrange(0, Y-1) do ( for j : Integer.subrange(0, 5001-1) do ( if dp[i+1][j+1] <= 0.0 then ( continue ) else skip ; for k : V do ( var t : OclAny := i + k ; if (t->compareTo(Y)) > 0 then ( dp[Y+1][j+1] := dp[Y+1][j+1] + dp[i+1][j+1] / X ) else (if E[t+1] = 1 then ( dp[Set{Y, t + A[t+1]}->min()+1][j+1] := dp[Set{Y, t + A[t+1]}->min()+1][j+1] + dp[i+1][j+1] / X ) else ( dp[t+1][Set{0, j + A[t+1]}->max()+1] := dp[t+1][Set{0, j + A[t+1]}->max()+1] + dp[i+1][j+1] / X ) ) ))) ; var s : int := 0 ; for i : Integer.subrange(0, 5001-1) do ( if dp[Y+1][i+1] <= 0.0 then ( continue ) else skip ; s := s + i * dp[Y+1][i+1]) ; execute (("" + ((s)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- j,a=0,[] def f(l,r): if ltoInteger() ; var P : OclAny := input().split() ; var I : OclAny := input().split() ; f(0, N) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display(); operation f(l : OclAny, r : OclAny) pre: true post: true activity: if (l->compareTo(r)) < 0 then ( skip; skip ; var c : OclAny := P[j+1] ; j := j + 1 ; var m : int := I->indexOf(c) - 1 ; f(l, m) ; f(m + 1, r) ; a := a + Sequence{ c } ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) from collections import defaultdict a=list(map(int,input().split())) ans=[] dt=defaultdict(lambda : 0) for i in a : if i in dt : dt[i]+=1 else : dt[i]=1 if 5 in a or 7 in a : print(-1) else : if dt[1]!=0 and dt[2]!=0 and dt[4]!=0 : x=min(dt[1],dt[2],dt[4]) dt[1]-=x dt[2]-=x dt[4]-=x while x : ans.append([1,2,4]) x=x-1 if dt[1]!=0 and dt[2]!=0 and dt[6]!=0 : y=min(dt[1],dt[2],dt[6]) dt[1]-=y dt[2]-=y dt[6]-=y while y : ans.append([1,2,6]) y=y-1 if dt[1]!=0 and dt[3]!=0 and dt[6]!=0 : z=min(dt[1],dt[3],dt[6]) dt[1]-=z dt[3]-=z dt[6]-=z while z : ans.append([1,3,6]) z=z-1 if sum(dt.values())==0 : for i in ans : print(*i) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : Sequence := Sequence{} ; var dt : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; for i : a do ( if (dt)->includes(i) then ( dt[i+1] := dt[i+1] + 1 ) else ( dt[i+1] := 1 )) ; if (a)->includes(5) or (a)->includes(7) then ( execute (-1)->display() ) else ( if dt[1+1] /= 0 & dt[2+1] /= 0 & dt[4+1] /= 0 then ( var x : OclAny := Set{dt[1+1], dt[2+1], dt[4+1]}->min() ; dt[1+1] := dt[1+1] - x ; dt[2+1] := dt[2+1] - x ; dt[4+1] := dt[4+1] - x ; while x do ( execute ((Sequence{1}->union(Sequence{2}->union(Sequence{ 4 }))) : ans) ; x := x - 1) ) else skip ; if dt[1+1] /= 0 & dt[2+1] /= 0 & dt[6+1] /= 0 then ( var y : OclAny := Set{dt[1+1], dt[2+1], dt[6+1]}->min() ; dt[1+1] := dt[1+1] - y ; dt[2+1] := dt[2+1] - y ; dt[6+1] := dt[6+1] - y ; while y do ( execute ((Sequence{1}->union(Sequence{2}->union(Sequence{ 6 }))) : ans) ; y := y - 1) ) else skip ; if dt[1+1] /= 0 & dt[3+1] /= 0 & dt[6+1] /= 0 then ( var z : OclAny := Set{dt[1+1], dt[3+1], dt[6+1]}->min() ; dt[1+1] := dt[1+1] - z ; dt[3+1] := dt[3+1] - z ; dt[6+1] := dt[6+1] - z ; while z do ( execute ((Sequence{1}->union(Sequence{3}->union(Sequence{ 6 }))) : ans) ; z := z - 1) ) else skip ; if (dt.values())->sum() = 0 then ( for i : ans do ( execute ((argument * (test (logical_test (comparison (expr (atom (name i))))))))->display()) ) else ( execute (-1)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) numbers=[int(i)for i in input().split()] a=numbers.count(1) b=numbers.count(2) c=numbers.count(3) d=numbers.count(4) e=numbers.count(6) if(n/3==a and n/3==d+e and n/3==b+c and e>=c and b>=d): for i in range(d): print("1 2 4") for i in range(b-d): print("1 2 6") for i in range(e-b+d): print("1 3 6") else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var numbers : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a : int := numbers->count(1) ; var b : int := numbers->count(2) ; var c : int := numbers->count(3) ; var d : int := numbers->count(4) ; var e : int := numbers->count(6) ; if (n / 3 = a & n / 3 = d + e & n / 3 = b + c & (e->compareTo(c)) >= 0 & (b->compareTo(d)) >= 0) then ( for i : Integer.subrange(0, d-1) do ( execute ("1 2 4")->display()) ; for i : Integer.subrange(0, b - d-1) do ( execute ("1 2 6")->display()) ; for i : Integer.subrange(0, e - b + d-1) do ( execute ("1 3 6")->display()) ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) count=[0]*8 for i in range(n): if a[i]==5 or a[i]==7 : print(-1) exit() count[a[i]]+=1 if count[1]!=n//3 or count[2]+count[3]!=n//3 or count[4]+count[6]!=n//3 or count[2]toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 8) ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = 5 or a[i+1] = 7 then ( execute (-1)->display() ; exit() ) else skip ; count[a[i+1]+1] := count[a[i+1]+1] + 1) ; if count[1+1] /= n div 3 or count[2+1] + count[3+1] /= n div 3 or count[4+1] + count[6+1] /= n div 3 or (count[2+1]->compareTo(count[4+1])) < 0 then ( execute (-1)->display() ; exit() ) else skip ; var res : Sequence := Integer.subrange(0, n div 3-1)->select(_anon | true)->collect(_anon | (Sequence{ 1 })) ; for i : Integer.subrange(0, count[2+1]-1) do ((expr (atom (name res)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ))))) ; for i : Integer.subrange(0, count[3+1]-1) do ((expr (atom (name res)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name count)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ]))) + (expr (atom (name i))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 3))))))))) ))))) ; for i : Integer.subrange(0, count[4+1]-1) do ((expr (atom (name res)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 4))))))))) ))))) ; for i : Integer.subrange(0, count[6+1]-1) do ((expr (atom (name res)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name count)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 4))))))))) ]))) + (expr (atom (name i))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 6))))))))) ))))) ; for x : res do ( execute ((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() a=list(map(int,input().split())) n=[0]*8 for x in a : n[x]+=1 if n[1]>=n[4]<=n[2]: k1=n[4] n[1]-=n[4] n[2]-=n[4] n[4]=0 if n[1]>=n[3]<=n[6]: k2=n[3] n[1]-=n[3] n[6]-=n[3] n[3]=0 if n[1]>=n[2]<=n[6]: k3=n[2] n[1]-=n[2] n[6]-=n[2] n[2]=0 if n[1]==n[2]==n[3]==n[4]==n[5]==n[6]==n[7]==0 : for _ in range(k1): print('1 2 4') for _ in range(k2): print('1 3 6') for _ in range(k3): print('1 2 6') else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; n := MatrixLib.elementwiseMult(Sequence{ 0 }, 8) ; for x : a do ( n[x+1] := n[x+1] + 1) ; if (n[1+1]->compareTo(n[4+1])) >= 0 & (n[4+1] <= n[2+1]) then ( var k1 : OclAny := n[4+1] ; n[1+1] := n[1+1] - n[4+1] ; n[2+1] := n[2+1] - n[4+1] ; n[4+1] := 0 ) else skip ; if (n[1+1]->compareTo(n[3+1])) >= 0 & (n[3+1] <= n[6+1]) then ( var k2 : OclAny := n[3+1] ; n[1+1] := n[1+1] - n[3+1] ; n[6+1] := n[6+1] - n[3+1] ; n[3+1] := 0 ) else skip ; if (n[1+1]->compareTo(n[2+1])) >= 0 & (n[2+1] <= n[6+1]) then ( var k3 : OclAny := n[2+1] ; n[1+1] := n[1+1] - n[2+1] ; n[6+1] := n[6+1] - n[2+1] ; n[2+1] := 0 ) else skip ; if n[1+1] = n[2+1] & (n[2+1] == n[3+1]) & (n[3+1] == n[4+1]) & (n[4+1] == n[5+1]) & (n[5+1] == n[6+1]) & (n[6+1] == n[7+1]) & (n[7+1] == 0) then ( for _anon : Integer.subrange(0, k1-1) do ( execute ('1 2 4')->display()) ; for _anon : Integer.subrange(0, k2-1) do ( execute ('1 3 6')->display()) ; for _anon : Integer.subrange(0, k3-1) do ( execute ('1 2 6')->display()) ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) elems=list(sorted(map(int,input().split(' ')))) triplets=[] for _ in range(n//3): triplets.append([elems.pop()]) for i in range(2): for j in range(len(triplets)): x=triplets[j][-1] prev_len=len(triplets[j]) for k in range(len(elems)-1,-1,-1): y=elems[k] if x % y==0 and x>y : triplets[j].append(y) del elems[k] break if len(triplets[j])==prev_len : print(-1) return for t in reversed(triplets): print(' '.join(map(str,reversed(t)))) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var elems : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )->sort()) ; var triplets : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n div 3-1) do ( execute ((Sequence{ elems->last() }) : triplets)) ; for i : Integer.subrange(0, 2-1) do ( for j : Integer.subrange(0, (triplets)->size()-1) do ( var x : OclAny := triplets[j+1]->last() ; var prev_len : int := (triplets[j+1])->size() ; for k : Integer.subrange(-1 + 1, (elems)->size() - 1)->reverse() do ( var y : OclAny := elems[k+1] ; if x mod y = 0 & (x->compareTo(y)) > 0 then ( (expr (atom (name triplets)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))) ; execute (elems[k+1])->isDeleted() ; break ) else skip) ; if (triplets[j+1])->size() = prev_len then ( execute (-1)->display() ; return ) else skip)) ; for t : (triplets)->reverse() do ( execute (StringLib.sumStringsWithSeparator((((t)->reverse())->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for k in range(t): a,b=map(int,input().split()) print(min(a,b,(a+b)//4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for k : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{a, b, (a + b) div 4}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np import heapq (n,k),p=[list(map(int,s.split()))for s in open(0)] p_np=np.array(p) p_cumsum=(p_np[1 :]>p_np[:-1]).cumsum() c=[False]*n _min=p[: k].copy() _max=[-x for x in p[: k]] heapq.heapify(_min) heapq.heapify(_max) ans=n-k+1 no_change=False if p_cumsum[k-2]==k-1 : no_change=True for i in range(n-k): decrease=False heapq.heappush(_min,p[i+k]) heapq.heappush(_max,-p[i+k]) while c[_min[0]]: heapq.heappop(_min) while c[-_max[0]]: heapq.heappop(_max) if(_min[0]==p[i]and-_max[0]==p[i+k]): ans-=1 decrease=True c[p[i]]=True if p_cumsum[i]+k-1==p_cumsum[i+k-1]: if no_change and not decrease : ans-=1 no_change=True print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var Sequence{n, k} : OclAny := null; var p : OclAny := null; Sequence{Sequence{n, k},p} := OclFile.newOclFile_Write(OclFile.newOclFile(0))->select(s | true)->collect(s | (((s.split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var p_np : Sequence := (p) ; var p_cumsum : OclAny := ((p_np->tail()->compareTo(p_np->front())) > 0).cumsum() ; var c : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ; var _min : OclAny := p.subrange(1,k)->copy() ; var _max : Sequence := p.subrange(1,k)->select(x | true)->collect(x | (-x)) ; heapq.heapify(_min) ; heapq.heapify(_max) ; var ans : double := n - k + 1 ; var no_change : boolean := false ; if p_cumsum[k - 2+1] = k - 1 then ( no_change := true ) else skip ; for i : Integer.subrange(0, n - k-1) do ( var decrease : boolean := false ; heapq.heappush(_min, p[i + k+1]) ; heapq.heappush(_max, -p[i + k+1]) ; while c[_min->first()+1] do ( heapq.heappop(_min)) ; while c->reverse()->at(-(-_max->first())) do ( heapq.heappop(_max)) ; if (_min->first() = p[i+1] & -_max->first() = p[i + k+1]) then ( ans := ans - 1 ; decrease := true ) else skip ; c[p[i+1]+1] := true ; if p_cumsum[i+1] + k - 1 = p_cumsum[i + k - 1+1] then ( if no_change & not(decrease) then ( ans := ans - 1 ) else skip ; no_change := true ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) while n!=0 : val=pow(n,m) x=["","Man","Oku","Cho","Kei","Gai","Jo","Jou","Ko","Kan","Sei","Sai","Gok","Ggs","Asg","Nyt","Fks","Mts"] ans=[] for i in x : if val % 10000>0 : ans.append(str(val % 10000)+i) val//=10000 print(''.join(ans[: :-1])) n,m=map(int,input().split()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; while n /= 0 do ( var val : double := (n)->pow(m) ; var x : Sequence := Sequence{""}->union(Sequence{"Man"}->union(Sequence{"Oku"}->union(Sequence{"Cho"}->union(Sequence{"Kei"}->union(Sequence{"Gai"}->union(Sequence{"Jo"}->union(Sequence{"Jou"}->union(Sequence{"Ko"}->union(Sequence{"Kan"}->union(Sequence{"Sei"}->union(Sequence{"Sai"}->union(Sequence{"Gok"}->union(Sequence{"Ggs"}->union(Sequence{"Asg"}->union(Sequence{"Nyt"}->union(Sequence{"Fks"}->union(Sequence{ "Mts" }))))))))))))))))) ; var ans : Sequence := Sequence{} ; for i : x do ( if val mod 10000 > 0 then ( execute ((("" + ((val mod 10000))) + i) : ans) ) else skip ; val := val div 10000) ; execute (StringLib.sumStringsWithSeparator((ans(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))), ''))->display() ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : m,n=map(int,input().split()) if m==0 : break m**=n s="" d=68 ls=['Mts','Fks','Nyt','Asg','Ggs','Gok','Sai','Sei','Kan','Ko','Jou','Jo','Gai','Kei','Cho','Oku','Man'][: :-1] while d : if int(m/10**d)>=1 : s+=str(int(m/10**d))+ls[int((d-4)/4)] m %=10**d d-=4 if m : s+=str(m) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if m = 0 then ( break ) else skip ; m := m->pow(n) ; var s : String := "" ; var d : int := 68 ; var ls : OclAny := Sequence{'Mts'}->union(Sequence{'Fks'}->union(Sequence{'Nyt'}->union(Sequence{'Asg'}->union(Sequence{'Ggs'}->union(Sequence{'Gok'}->union(Sequence{'Sai'}->union(Sequence{'Sei'}->union(Sequence{'Kan'}->union(Sequence{'Ko'}->union(Sequence{'Jou'}->union(Sequence{'Jo'}->union(Sequence{'Gai'}->union(Sequence{'Kei'}->union(Sequence{'Cho'}->union(Sequence{'Oku'}->union(Sequence{ 'Man' }))))))))))))))))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; while d do ( if ("" + ((m / (10)->pow(d))))->toInteger() >= 1 then ( s := s + ("" + ((("" + ((m / (10)->pow(d))))->toInteger()))) + ls[("" + (((d - 4) / 4)))->toInteger()+1] ; m := m mod (10)->pow(d) ) else skip ; d := d - 4) ; if m then ( s := s + ("" + ((m))) ) else skip ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def solve(m,n): units=[('Mts',68),('Fks',64),('Nyt',60),('Asg',56),('Ggs',52),('Gok',48),('Sai',44),('Sei',40),('Kan',36),('Ko',32),('Jou',28),('Jo',24),('Gai',20),('Kei',16),('Cho',12),('Oku',8),('Man',4)] num=m**n ans='' for u,i in units : if num>=10**i : ans+=str(num//10**i)+u num %=10**i if num : ans+=str(num) return ans def main(args): while True : m,n=map(int,input().split()) if m==0 and n==0 : break ans=solve(m,n) print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(m : OclAny, n : OclAny) : OclAny pre: true post: true activity: var units : Sequence := Sequence{Sequence{'Mts', 68}}->union(Sequence{Sequence{'Fks', 64}}->union(Sequence{Sequence{'Nyt', 60}}->union(Sequence{Sequence{'Asg', 56}}->union(Sequence{Sequence{'Ggs', 52}}->union(Sequence{Sequence{'Gok', 48}}->union(Sequence{Sequence{'Sai', 44}}->union(Sequence{Sequence{'Sei', 40}}->union(Sequence{Sequence{'Kan', 36}}->union(Sequence{Sequence{'Ko', 32}}->union(Sequence{Sequence{'Jou', 28}}->union(Sequence{Sequence{'Jo', 24}}->union(Sequence{Sequence{'Gai', 20}}->union(Sequence{Sequence{'Kei', 16}}->union(Sequence{Sequence{'Cho', 12}}->union(Sequence{Sequence{'Oku', 8}}->union(Sequence{ Sequence{'Man', 4} })))))))))))))))) ; var num : double := (m)->pow(n) ; var ans : String := '' ; for _tuple : units do (var _indx : int := 1; var u : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); if (num->compareTo((10)->pow(i))) >= 0 then ( ans := ans + ("" + ((num div (10)->pow(i)))) + u ; num := num mod (10)->pow(i) ) else skip) ; if num then ( ans := ans + ("" + ((num))) ) else skip ; return ans; operation main(args : OclAny) pre: true post: true activity: while true do ( Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if m = 0 & n = 0 then ( break ) else skip ; ans := solve(m, n) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heappush,heappop def main(): while True : x,y,z=map(int,input().split()) if x==0 : break vlst=list(map(int,input().split())) events={} for _ in range(z): n,e,a=map(int,input().split()) events[n]=(e,a) que=[] heappush(que,(0,0)) cnt=[[0]*(100*y+1)for _ in range(y+1)] init=x**y cnt[0][0]=init visited={} while que : pos,score=heappop(que) for v in vlst : new_pos=pos+v new_score=score if new_pos in events : event,value=events[new_pos] if event==1 : new_pos+=value elif event==2 : new_score+=value else : new_score=max(new_score-value,0) if new_pos>=y : cnt[y][new_score]+=cnt[pos][score]//x else : cnt[new_pos][new_score]+=cnt[pos][score]//x if(new_pos,new_score)not in visited : visited[(new_pos,new_score)]=True heappush(que,(new_pos,new_score)) total=0 for score in range(100*y+1): total+=cnt[y][score]*score print(total//init) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: while true do ( var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x = 0 then ( break ) else skip ; var vlst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var events : OclAny := Set{} ; for _anon : Integer.subrange(0, z-1) do ( var n : OclAny := null; var e : OclAny := null; var a : OclAny := null; Sequence{n,e,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; events[n+1] := Sequence{e, a}) ; var que : Sequence := Sequence{} ; heappush(que, Sequence{0, 0}) ; var cnt : Sequence := Integer.subrange(0, y + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (100 * y + 1)))) ; var init : double := (x)->pow(y) ; cnt->first()->first() := init ; var visited : OclAny := Set{} ; while que do ( var pos : OclAny := null; var score : OclAny := null; Sequence{pos,score} := heappop(que) ; for v : vlst do ( var new_pos : OclAny := pos + v ; var new_score : OclAny := score ; if (events)->includes(new_pos) then ( var event : OclAny := null; var value : OclAny := null; Sequence{event,value} := events[new_pos+1] ; if event = 1 then ( new_pos := new_pos + value ) else (if event = 2 then ( new_score := new_score + value ) else ( new_score := Set{new_score - value, 0}->max() ) ) ) else skip ; if (new_pos->compareTo(y)) >= 0 then ( cnt[y+1][new_score+1] := cnt[y+1][new_score+1] + cnt[pos+1][score+1] div x ) else ( cnt[new_pos+1][new_score+1] := cnt[new_pos+1][new_score+1] + cnt[pos+1][score+1] div x ; if (visited)->excludes(Sequence{new_pos, new_score}) then ( visited[Sequence{new_pos, new_score}+1] := true ; heappush(que, Sequence{new_pos, new_score}) ) else skip ))) ; var total : int := 0 ; for score : Integer.subrange(0, 100 * y + 1-1) do ( total := total + cnt[y+1][score+1] * score) ; execute (total div init)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tanni=['Man','Oku','Cho','Kei','Gai','Jo','Jou','Ko','Kan','Sei','Sai','Gok','Ggs','Asg','Nyt','Fks','Mts','end'] while True : m,n=map(int,input().split()) if m==0 and n==0 : break s=m**n ans=[] i=0 while True : ans.append(s % 10**4) s=s//10**4 if s==0 : break else : if tanni[i]!='end' : ans.append(tanni[i]) if tanni[i]!='end' : i+=1 ans.reverse() switch=False for j in range(len(ans)): if ans[j]==0 : switch=True elif switch==False : if switch==True : switch=False else : print(ans[j],end='') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var tanni : Sequence := Sequence{'Man'}->union(Sequence{'Oku'}->union(Sequence{'Cho'}->union(Sequence{'Kei'}->union(Sequence{'Gai'}->union(Sequence{'Jo'}->union(Sequence{'Jou'}->union(Sequence{'Ko'}->union(Sequence{'Kan'}->union(Sequence{'Sei'}->union(Sequence{'Sai'}->union(Sequence{'Gok'}->union(Sequence{'Ggs'}->union(Sequence{'Asg'}->union(Sequence{'Nyt'}->union(Sequence{'Fks'}->union(Sequence{'Mts'}->union(Sequence{ 'end' }))))))))))))))))) ; while true do ( var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if m = 0 & n = 0 then ( break ) else skip ; var s : double := (m)->pow(n) ; var ans : Sequence := Sequence{} ; var i : int := 0 ; while true do ( execute ((s mod (10)->pow(4)) : ans) ; s := s div (10)->pow(4) ; if s = 0 then ( break ) else ( if tanni[i+1] /= 'end' then ( execute ((tanni[i+1]) : ans) ) else skip ) ; if tanni[i+1] /= 'end' then ( i := i + 1 ) else skip) ; ans := ans->reverse() ; var switch : boolean := false ; for j : Integer.subrange(0, (ans)->size()-1) do ( if ans[j+1] = 0 then ( switch := true ) else (if switch = false then ( if switch = true then ( switch := false ) else ( execute (ans[j+1])->display() ) ) else skip)) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,Counter from itertools import product,groupby,count,permutations,combinations from math import pi,sqrt from collections import deque from bisect import bisect,bisect_left,bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF=float("inf") YES,Yes,yes,NO,No,no="YES","Yes","yes","NO","No","no" def main(): num=[10**4,10**8,10**12,10**16,10**20,10**24,10**28,10**32,10**36,10**40,10**44,10**48,10**52,10**56,10**60,10**64,10**68] uni=["Man","Oku","Cho","Kei","Gai","Jo","Jou","Ko","Kan","Sei","Sai","Gok","Ggs","Asg","Nyt","Fks","Mts"] while True : m,n=map(int,input().split()) if m==0 and n==0 : break a=m**n ans="" for i in range(len(num)-1,-1,-1): if a>=num[i]: ans+=str(a//num[i])+uni[i] a %=num[i] print(ans+str(a if a!=0 else "")) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(10000) ; var INF : double := ("" + (("inf")))->toReal() ; var YES : OclAny := null; var Yes : OclAny := null; var yes : OclAny := null; var NO : OclAny := null; var No : OclAny := null; var no : OclAny := null; Sequence{YES,Yes,yes,NO,No,no} := Sequence{"YES","Yes","yes","NO","No","no"} ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var num : Sequence := Sequence{(10)->pow(4)}->union(Sequence{(10)->pow(8)}->union(Sequence{(10)->pow(12)}->union(Sequence{(10)->pow(16)}->union(Sequence{(10)->pow(20)}->union(Sequence{(10)->pow(24)}->union(Sequence{(10)->pow(28)}->union(Sequence{(10)->pow(32)}->union(Sequence{(10)->pow(36)}->union(Sequence{(10)->pow(40)}->union(Sequence{(10)->pow(44)}->union(Sequence{(10)->pow(48)}->union(Sequence{(10)->pow(52)}->union(Sequence{(10)->pow(56)}->union(Sequence{(10)->pow(60)}->union(Sequence{(10)->pow(64)}->union(Sequence{ (10)->pow(68) })))))))))))))))) ; var uni : Sequence := Sequence{"Man"}->union(Sequence{"Oku"}->union(Sequence{"Cho"}->union(Sequence{"Kei"}->union(Sequence{"Gai"}->union(Sequence{"Jo"}->union(Sequence{"Jou"}->union(Sequence{"Ko"}->union(Sequence{"Kan"}->union(Sequence{"Sei"}->union(Sequence{"Sai"}->union(Sequence{"Gok"}->union(Sequence{"Ggs"}->union(Sequence{"Asg"}->union(Sequence{"Nyt"}->union(Sequence{"Fks"}->union(Sequence{ "Mts" })))))))))))))))) ; while true do ( var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if m = 0 & n = 0 then ( break ) else skip ; var a : double := (m)->pow(n) ; var ans : String := "" ; for i : Integer.subrange(-1 + 1, (num)->size() - 1)->reverse() do ( if (a->compareTo(num[i+1])) >= 0 then ( ans := ans + ("" + ((a div num[i+1]))) + uni[i+1] ; a := a mod num[i+1] ) else skip) ; execute (ans + ("" + ((if a /= 0 then a else "" endif))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,a,b=map(int,input().split()) if a>b : print(0) exit() if n==1 and a!=b : print(0) exit() if n==2 : print(1) exit() q=b*(n-2)-a*(n-2)+1 print(q) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(b)) > 0 then ( execute (0)->display() ; exit() ) else skip ; if n = 1 & a /= b then ( execute (0)->display() ; exit() ) else skip ; if n = 2 then ( execute (1)->display() ; exit() ) else skip ; var q : double := b * (n - 2) - a * (n - 2) + 1 ; execute (q)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def read(): N,A,B=map(int,input().strip().split()) return N,A,B def solve(N,A,B): low=(N-1)*A+B-1 high=A+(N-1)*B return max(high-low,0) if __name__=='__main__' : inputs=read() outputs=solve(*inputs) if outputs is not None : print("%s" % str(outputs)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; if __name__ = '__main__' then ( var inputs : OclAny := read() ; var outputs : OclAny := solve((argument * (test (logical_test (comparison (expr (atom (name inputs)))))))) ; if not(outputs <>= null) then ( execute (StringLib.format("%s",("" + ((outputs)))))->display() ) else skip ) else skip; operation read() : OclAny pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{N,A,B} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; return N, A, B; operation solve(N : OclAny, A : OclAny, B : OclAny) : OclAny pre: true post: true activity: var low : double := (N - 1) * A + B - 1 ; var high : OclAny := A + (N - 1) * B ; return Set{high - low, 0}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,A,B=[int(n)for n in input().split()] min_=(N-1)*A+B max_=A+(N-1)*B print(max(max_-min_+1,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{N,A,B} := input().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; var min_ : double := (N - 1) * A + B ; var max_ : OclAny := A + (N - 1) * B ; execute (Set{max_ - min_ + 1, 0}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(ang,n): if((ang*n)>(180*(n-2))): return 0 elif((ang*n)% 180!=0): return 0 ans=1 freq=(ang*n)//180 ans=ans*(n-1-freq) ans=ans*n return ans ang=90 n=4 print(solve(ang,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; ang := 90 ; n := 4 ; execute (solve(ang, n))->display(); operation solve(ang : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (((ang * n)->compareTo((180 * (n - 2)))) > 0) then ( return 0 ) else (if ((ang * n) mod 180 /= 0) then ( return 0 ) else skip) ; var ans : int := 1 ; var freq : int := (ang * n) div 180 ; ans := ans * (n - 1 - freq) ; ans := ans * n ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict from collections import deque import itertools import math def readInt(): return int(input()) def readInts(): return list(map(int,input().split())) def readChar(): return input() def readChars(): return input().split() n,a,b=readInts() print(max(0,(b-a)*(n-2)+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := readInts() ; execute (Set{0, (b - a) * (n - 2) + 1}->max())->display(); operation readInt() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation readInts() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation readChar() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation readChars() : OclAny pre: true post: true activity: return input().split(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=list(map(int,input().split())) mx=a+(n-1)*b mn=a*(n-1)+b result=mx-mn+1 if result<0 : ans=0 else : ans=result print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mx : OclAny := a + (n - 1) * b ; var mn : double := a * (n - 1) + b ; var result : double := mx - mn + 1 ; if result < 0 then ( var ans : int := 0 ) else ( ans := result ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countNumbers(X,Y,N): count=0 ; for i in range(1,N+1): if((i % X==0)and(i % Y!=0)): count+=1 ; return count ; X=2 ; Y=3 ; N=10 ; print(countNumbers(X,Y,N)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; X := 2; ; Y := 3; ; N := 10; ; execute (countNumbers(X, Y, N))->display();; operation countNumbers(X : OclAny, Y : OclAny, N : OclAny) pre: true post: true activity: var count : int := 0; ; for i : Integer.subrange(1, N + 1-1) do ( if ((i mod X = 0) & (i mod Y /= 0)) then ( count := count + 1; ) else skip) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=1000000007 def findSum(n): return((n % mod)*(n % mod))% mod n=229137999 print(findSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : int := 1000000007 ; skip ; n := 229137999 ; execute (findSum(n))->display(); operation findSum(n : OclAny) : OclAny pre: true post: true activity: return ((n mod mod) * (n mod mod)) mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(arr,n,k): m={}; for i in range(0,n-1): if(arr[i]in m.keys()): m[arr[i]]+=1 ; else : m[arr[i]]=1 ; i+=1 ; max=sys.maxsize ; for i in range(0,n-1): if(m[arr[i]]==k and max==sys.maxsize): max=arr[i]; elif(m[arr[i]]==k and maxunion(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{5}->union(Sequence{6}->union(Sequence{6}->union(Sequence{ 6 })))))))))) ; k := 4; ; n := (arr)->size() ; solve(arr, n, k); operation solve(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var m : OclAny := Set{}; ; for i : Integer.subrange(0, n - 1-1) do ( if ((m.keys())->includes(arr[i+1])) then ( m[arr[i+1]+1] := m[arr[i+1]+1] + 1; ) else ( m[arr[i+1]+1] := 1; ) ; i := i + 1;) ; var max : (trailer . (name maxsize)) := (trailer . (name maxsize)); ; for i : Integer.subrange(0, n - 1-1) do ( if (m[arr[i+1]+1] = k & max = (trailer . (name maxsize))) then ( max := arr[i+1]; ) else (if (m[arr[i+1]+1] = k & (max->compareTo(arr[i+1])) < 0) then ( max := arr[i+1]; ) else skip) ; i := i + 1) ; if (max = (trailer . (name maxsize))) then ( execute ("No such element")->display(); ) else ( execute (max)->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(X,Y,Z,V,E,A): dp=[[0.0]*6001 for _ in range(Y+11)] dp[0][0]=1.0 for i in range(Y): for j in range(5001): if dp[i][j]<=0.0 : continue for k in V : t=i+k if t>Y : dp[Y][j]+=dp[i][j]/X elif E[t]==1 : dp[min(Y,t+A[t])][j]+=dp[i][j]/X else : dp[t][max(0,j+A[t])]+=dp[i][j]/X s=0 for i in range(5001): s+=i*dp[Y][i] print(int(s)) if __name__=="__main__" : while True : X,Y,Z=map(int,input().split()) if X | Y | Z==0 : break V=list(map(int,input().split())) E=[0]*100 A=[0]*100 for _ in range(Z): n,e,a=map(int,input().split()) E[n]=e if e==3 : A[n]=-a else : A[n]=a solve(X,Y,Z,V,E,A) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( while true do ( Sequence{X,Y,Z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if MathLib.bitwiseOr(MathLib.bitwiseOr(X, Y), Z) = 0 then ( break ) else skip ; V := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; E := MatrixLib.elementwiseMult(Sequence{ 0 }, 100) ; A := MatrixLib.elementwiseMult(Sequence{ 0 }, 100) ; for _anon : Integer.subrange(0, Z-1) do ( var n : OclAny := null; var e : OclAny := null; var a : OclAny := null; Sequence{n,e,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; E[n+1] := e ; if e = 3 then ( A[n+1] := -a ) else ( A[n+1] := a )) ; solve(X, Y, Z, V, E, A)) ) else skip; operation solve(X : OclAny, Y : OclAny, Z : OclAny, V : OclAny, E : OclAny, A : OclAny) pre: true post: true activity: var dp : Sequence := Integer.subrange(0, Y + 11-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0.0 }, 6001))) ; dp->first()->first() := 1.0 ; for i : Integer.subrange(0, Y-1) do ( for j : Integer.subrange(0, 5001-1) do ( if dp[i+1][j+1] <= 0.0 then ( continue ) else skip ; for k : V do ( var t : OclAny := i + k ; if (t->compareTo(Y)) > 0 then ( dp[Y+1][j+1] := dp[Y+1][j+1] + dp[i+1][j+1] / X ) else (if E[t+1] = 1 then ( dp[Set{Y, t + A[t+1]}->min()+1][j+1] := dp[Set{Y, t + A[t+1]}->min()+1][j+1] + dp[i+1][j+1] / X ) else ( dp[t+1][Set{0, j + A[t+1]}->max()+1] := dp[t+1][Set{0, j + A[t+1]}->max()+1] + dp[i+1][j+1] / X ) ) ))) ; var s : int := 0 ; for i : Integer.subrange(0, 5001-1) do ( s := s + i * dp[Y+1][i+1]) ; execute (("" + ((s)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def main(args): while True : hands=[0]*5 hands[0]=int(input()) if hands[0]==0 : break hands[1]=int(input()) hands[2]=int(input()) hands[3]=int(input()) hands[4]=int(input()) if 1 in hands and 2 in hands and 3 in hands : for _ in range(5): print(3) elif hands.count(hands[0])==5 : for _ in range(5): print(3) else : for h in hands : if(h+1 in hands)or(h==3 and 1 in hands): print(1) else : print(2) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation main(args : OclAny) pre: true post: true activity: while true do ( var hands : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 5) ; hands->first() := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if hands->first() = 0 then ( break ) else skip ; hands[1+1] := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; hands[2+1] := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; hands[3+1] := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; hands[4+1] := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (hands)->includes(1) & (hands)->includes(2) & (hands)->includes(3) then ( for _anon : Integer.subrange(0, 5-1) do ( execute (3)->display()) ) else (if hands->count(hands->first()) = 5 then ( for _anon : Integer.subrange(0, 5-1) do ( execute (3)->display()) ) else ( for h : hands do ( if ((hands)->includes(h + 1)) or (h = 3 & (hands)->includes(1)) then ( execute (1)->display() ) else ( execute (2)->display() )) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check_aiko(arr): if all(arr[0]==a for a in arr): return True rps=[1,2,3] for t in rps : if t not in arr : return False return True def check_v(arr): rps={} o=[] for t in arr : if t not in rps : rps[t]=0 if 1 in rps.keys()and 2 in rps.keys(): rps[1],rps[2]=1,2 elif 2 in rps.keys()and 3 in rps.keys(): rps[2],rps[3]=1,2 elif 1 in rps.keys()and 3 in rps.keys(): rps[3],rps[1]=1,2 for n in arr : o.append(rps.get(n)) return o def algorithm(): g=[] out=[] while True : inp=int(input()) if inp==0 : break g.append(inp) if len(g)==5 : if check_aiko(g): out=[3]*5 else : out=check_v(g) for o in out : print(o) g.clear() out.clear() def main(): algorithm() if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation check_aiko(arr : OclAny) : OclAny pre: true post: true activity: if ((argument (test (logical_test (comparison (comparison (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) == (comparison (expr (atom (name a))))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name arr))))))))->forAll( _x | _x = true ) then ( return true ) else skip ; var rps : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; for t : rps do ( if (arr)->excludes(t) then ( return false ) else skip) ; return true; operation check_v(arr : OclAny) : OclAny pre: true post: true activity: rps := Set{} ; var o : Sequence := Sequence{} ; for t : arr do ( if (rps)->excludes(t) then ( rps[t+1] := 0 ) else skip) ; if (rps.keys())->includes(1) & (rps.keys())->includes(2) then ( var rps[1+1] : OclAny := null; var rps[2+1] : OclAny := null; Sequence{rps[1+1],rps[2+1]} := Sequence{1,2} ) else (if (rps.keys())->includes(2) & (rps.keys())->includes(3) then ( var rps[2+1] : OclAny := null; var rps[3+1] : OclAny := null; Sequence{rps[2+1],rps[3+1]} := Sequence{1,2} ) else (if (rps.keys())->includes(1) & (rps.keys())->includes(3) then ( var rps[3+1] : OclAny := null; var rps[1+1] : OclAny := null; Sequence{rps[3+1],rps[1+1]} := Sequence{1,2} ) else skip ) ) ; for n : arr do ( execute ((rps.get(n)) : o)) ; return o; operation algorithm() pre: true post: true activity: var g : Sequence := Sequence{} ; var out : Sequence := Sequence{} ; while true do ( var inp : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if inp = 0 then ( break ) else skip ; execute ((inp) : g) ; if (g)->size() = 5 then ( if check_aiko(g) then ( out := MatrixLib.elementwiseMult(Sequence{ 3 }, 5) ) else ( out := check_v(g) ) ; for o : out do ( execute (o)->display()) ; execute (g /<: g) ; execute (out /<: out) ) else skip); operation main() pre: true post: true activity: algorithm(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def judge(h,hset): rest=hset-{h} if len(rest)in(0,2): return 3 if h % 3+1 in rest : return 1 else : return 2 while True : h1=int(input()) if h1==0 : break hlst=[] hset=set() hlst.append(h1) hset.add(h1) for _ in range(4): h=int(input()) hlst.append(h) hset.add(h) for h in hlst : print(judge(h,hset)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var h1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if h1 = 0 then ( break ) else skip ; var hlst : Sequence := Sequence{} ; hset := Set{}->union(()) ; execute ((h1) : hlst) ; execute ((h1) : hset) ; for _anon : Integer.subrange(0, 4-1) do ( h := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((h) : hlst) ; execute ((h) : hset)) ; for h : hlst do ( execute (judge(h, hset))->display())); operation judge(h : OclAny, hset : OclAny) : OclAny pre: true post: true activity: var rest : double := hset - Set{ h } ; if (Sequence{0, 2})->includes((rest)->size()) then ( return 3 ) else skip ; if (rest)->includes(h mod 3 + 1) then ( return 1 ) else ( return 2 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- win=[0,2,3,1] lose=[0,3,1,2] while True : exist=[False for i in range(4)] h=[0 for i in range(5)] h[0]=int(input()) exist[h[0]]=True if h[0]==0 : break for i in range(1,5): h[i]=int(input()) exist[h[i]]=True for i in range(5): if exist[win[h[i]]]and not exist[lose[h[i]]]: print(1) elif not exist[win[h[i]]]and exist[lose[h[i]]]: print(2) else : print(3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var win : Sequence := Sequence{0}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 1 }))) ; var lose : Sequence := Sequence{0}->union(Sequence{3}->union(Sequence{1}->union(Sequence{ 2 }))) ; while true do ( var exist : Sequence := Integer.subrange(0, 4-1)->select(i | true)->collect(i | (false)) ; var h : Sequence := Integer.subrange(0, 5-1)->select(i | true)->collect(i | (0)) ; h->first() := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; exist[h->first()+1] := true ; if h->first() = 0 then ( break ) else skip ; for i : Integer.subrange(1, 5-1) do ( h[i+1] := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; exist[h[i+1]+1] := true) ; for i : Integer.subrange(0, 5-1) do ( if exist[win[h[i+1]+1]+1] & not(exist[lose[h[i+1]+1]+1]) then ( execute (1)->display() ) else (if not(exist[win[h[i+1]+1]+1]) & exist[lose[h[i+1]+1]+1] then ( execute (2)->display() ) else ( execute (3)->display() ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import reduce import fractions def lcm_base(x,y): return(x*y)//fractions.gcd(x,y) def lcm_list(numbers): return reduce(lcm_base,numbers,1) n=int(input()) inp_list=list(map(int,(input().split()))) lcm=lcm_list(inp_list) ans=0 for i in inp_list : ans+=lcm//i print(ans %(10**9+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var inp_list : Sequence := (((input().split()))->collect( _x | (OclType["int"])->apply(_x) )) ; var lcm : OclAny := lcm_list(inp_list) ; var ans : int := 0 ; for i : inp_list do ( ans := ans + lcm div i) ; execute (ans mod ((10)->pow(9) + 7))->display(); operation lcm_base(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return (x * y) div fractions.gcd(x, y); operation lcm_list(numbers : OclAny) : OclAny pre: true post: true activity: return reduce(lcm_base, numbers, 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h=[0]*5 while True : try : for i in range(5): h[i]=int(input()) except : break if len(set(h))==1 or len(set(h))==3 : print(*[3]*5,sep='\n') continue ans=[1]*5 for i in range(5): if h[i]==1 : ans[i]+=(h.count(3)>0) elif h[i]==2 : ans[i]+=(h.count(1)>0) else : ans[i]+=(h.count(2)>0) print(*ans,sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 5) ; while true do ( try ( for i : Integer.subrange(0, 5-1) do ( h[i+1] := ("" + (((OclFile["System.in"]).readLine())))->toInteger())) catch (_e : OclException) do ( break) ; if (Set{}->union((h)))->size() = 1 or (Set{}->union((h)))->size() = 3 then ( execute ((argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 3)))))))) ])) * (expr (atom (number (integer 5))))))))))->display() ; continue ) else skip ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, 5) ; for i : Integer.subrange(0, 5-1) do ( if h[i+1] = 1 then ( ans[i+1] := ans[i+1] + (h->count(3) > 0) ) else (if h[i+1] = 2 then ( ans[i+1] := ans[i+1] + (h->count(1) > 0) ) else ( ans[i+1] := ans[i+1] + (h->count(2) > 0) ) ) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=18 tbl=[i**2 for i in range(0,N)] dp=[[0 for j in range(600)]for i in range(N)] dp[0][0]=1 for i in range(1,N): for n in range(300): dp[i][n]+=dp[i-1][n] for j in range(tbl[i],300,tbl[i]): dp[i][n+j]+=dp[i-1][n] while True : n=int(input()) if n==0 : break print(dp[N-1][n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 18 ; var tbl : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | ((i)->pow(2))) ; var dp : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Integer.subrange(0, 600-1)->select(j | true)->collect(j | (0)))) ; dp->first()->first() := 1 ; for i : Integer.subrange(1, N-1) do ( for n : Integer.subrange(0, 300-1) do ( dp[i+1][n+1] := dp[i+1][n+1] + dp[i - 1+1][n+1] ; for j : Integer.subrange(tbl[i+1], 300-1)->select( $x | ($x - tbl[i+1]) mod tbl[i+1] = 0 ) do ( dp[i+1][n + j+1] := dp[i+1][n + j+1] + dp[i - 1+1][n+1]))) ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; execute (dp[N - 1+1][n+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dp=[1]*300 for i in range(2,18): for j in range(i**2,300): dp[j]+=dp[j-i**2] while True : n=int(input()) if n==0 : break print(dp[n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, 300) ; for i : Integer.subrange(2, 18-1) do ( for j : Integer.subrange((i)->pow(2), 300-1) do ( dp[j+1] := dp[j+1] + dp[j - (i)->pow(2)+1])) ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; execute (dp[n+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dp=[1]*301 for i in range(2,18): for j in range(i*i,301): dp[j]+=dp[j-i*i] while 1 : n=int(input()) if n==0 : break print(dp[n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, 301) ; for i : Integer.subrange(2, 18-1) do ( for j : Integer.subrange(i * i, 301-1) do ( dp[j+1] := dp[j+1] + dp[j - i * i+1])) ; while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; execute (dp[n+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dp=[1]*300 for i in range(2,18): for j in range(i**2,300): dp[j]+=dp[j-i**2] while True : n=int(input()) if n==0 : break print(dp[n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, 300) ; for i : Integer.subrange(2, 18-1) do ( for j : Integer.subrange((i)->pow(2), 300-1) do ( dp[j+1] := dp[j+1] + dp[j - (i)->pow(2)+1])) ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; execute (dp[n+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline write=sys.stdout.write dp=[0]*601 dp[0]=1 V=[1,4,9,16,25,36,49,64,81,100,121,144,169,196,225,256,289] for v in V : for k in range(300,-1,-1): x=dp[k] w=v while k+w<=300 : dp[k+w]+=x w+=v while 1 : N=int(readline()) if not N : break write("%d\n" % dp[N]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var write : OclAny := (OclFile["System.out"]).write ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 601) ; dp->first() := 1 ; var V : Sequence := Sequence{1}->union(Sequence{4}->union(Sequence{9}->union(Sequence{16}->union(Sequence{25}->union(Sequence{36}->union(Sequence{49}->union(Sequence{64}->union(Sequence{81}->union(Sequence{100}->union(Sequence{121}->union(Sequence{144}->union(Sequence{169}->union(Sequence{196}->union(Sequence{225}->union(Sequence{256}->union(Sequence{ 289 })))))))))))))))) ; for v : V do ( for k : Integer.subrange(-1 + 1, 300)->reverse() do ( var x : OclAny := dp[k+1] ; var w : OclAny := v ; while k + w <= 300 do ( dp[k + w+1] := dp[k + w+1] + x ; w := w + v))) ; while 1 do ( var N : int := ("" + ((readline())))->toInteger() ; if not(N) then ( break ) else skip ; write(StringLib.format("%d\n",dp[N+1]))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(X,Y,Z,V,E,A): dp=[[0.0]*6001 for _ in range(Y+max(V)+1)] dp[0][0]=1.0 for i in range(Y): for j in range(5001): if dp[i][j]<=0.0 : continue for k in V : t=i+k if t>Y : dp[Y][j]+=dp[i][j]/X elif E[t]==1 : dp[min(Y,t+A[t])][j]+=dp[i][j]/X else : dp[t][max(0,j+A[t])]+=dp[i][j]/X s=0 for i in range(5001): if dp[Y][i]<=0.0 : continue s+=i*dp[Y][i] print(int(s)) while True : X,Y,Z=map(int,raw_input().split()) if X | Y | Z==0 : sys.exit() V=map(int,raw_input().split()) E=[0]*100 A=[0]*100 for _ in range(Z): n,e,a=map(int,raw_input().split()) E[n]=e if e==3 : A[n]=-a else : A[n]=a solve(X,Y,Z,V,E,A) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( Sequence{X,Y,Z} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if MathLib.bitwiseOr(MathLib.bitwiseOr(X, Y), Z) = 0 then ( sys.exit() ) else skip ; V := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; E := MatrixLib.elementwiseMult(Sequence{ 0 }, 100) ; A := MatrixLib.elementwiseMult(Sequence{ 0 }, 100) ; for _anon : Integer.subrange(0, Z-1) do ( var n : OclAny := null; var e : OclAny := null; var a : OclAny := null; Sequence{n,e,a} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; E[n+1] := e ; if e = 3 then ( A[n+1] := -a ) else ( A[n+1] := a )) ; solve(X, Y, Z, V, E, A)); operation solve(X : OclAny, Y : OclAny, Z : OclAny, V : OclAny, E : OclAny, A : OclAny) pre: true post: true activity: var dp : Sequence := Integer.subrange(0, Y + (V)->max() + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0.0 }, 6001))) ; dp->first()->first() := 1.0 ; for i : Integer.subrange(0, Y-1) do ( for j : Integer.subrange(0, 5001-1) do ( if dp[i+1][j+1] <= 0.0 then ( continue ) else skip ; for k : V do ( var t : OclAny := i + k ; if (t->compareTo(Y)) > 0 then ( dp[Y+1][j+1] := dp[Y+1][j+1] + dp[i+1][j+1] / X ) else (if E[t+1] = 1 then ( dp[Set{Y, t + A[t+1]}->min()+1][j+1] := dp[Set{Y, t + A[t+1]}->min()+1][j+1] + dp[i+1][j+1] / X ) else ( dp[t+1][Set{0, j + A[t+1]}->max()+1] := dp[t+1][Set{0, j + A[t+1]}->max()+1] + dp[i+1][j+1] / X ) ) ))) ; var s : int := 0 ; for i : Integer.subrange(0, 5001-1) do ( if dp[Y+1][i+1] <= 0.0 then ( continue ) else skip ; s := s + i * dp[Y+1][i+1]) ; execute (("" + ((s)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minOperations(A,n): if n & 1 : return-1 zeros,consZeros,ones=0,0,0 for i in range(n): if A[i]: zeros+=1 else : ones+=1 if(i+1union(Sequence{1}->union(Sequence{0}->union(Sequence{ 0 }))) ; n := (A)->size() ; execute (minOperations(A, n))->display() ) else skip; operation minOperations(A : OclAny, n : OclAny) : OclAny pre: true post: true activity: if MathLib.bitwiseAnd(n, 1) then ( return -1 ) else skip ; var zeros : OclAny := null; var consZeros : OclAny := null; var ones : OclAny := null; Sequence{zeros,consZeros,ones} := Sequence{0,0,0} ; for i : Integer.subrange(0, n-1) do ( if A[i+1] then ( zeros := zeros + 1 ) else ( ones := ones + 1 ) ; if ((i + 1->compareTo(n)) < 0) then ( if A[i+1] = 0 & A[i + 1+1] = 0 then ( consZeros := consZeros + 1 ) else skip ) else skip) ; if A->first() = A[n - 1+1] & A->first() = 0 then ( consZeros := consZeros + 1 ) else skip ; if zeros = ones then ( return consZeros ) else ( return -1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def SieveOfSundaram(n): nNew=int((n-2)/2); marked=[0]*(nNew+1); for i in range(1,nNew+1): j=i ; while((i+j+2*i*j)<=nNew): marked[i+j+2*i*j]=1 ; j+=1 ; if(n>2): print(2,end=" "); for i in range(1,nNew+1): if(marked[i]==0): print((2*i+1),end=" "); n=20 ; SieveOfSundaram(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 20; ; SieveOfSundaram(n);; operation SieveOfSundaram(n : OclAny) pre: true post: true activity: var nNew : int := ("" + (((n - 2) / 2)))->toInteger(); ; var marked : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (nNew + 1)); ; for i : Integer.subrange(1, nNew + 1-1) do ( var j : OclAny := i; ; while (((i + j + 2 * i * j)->compareTo(nNew)) <= 0) do ( marked[i + j + 2 * i * j+1] := 1; ; j := j + 1;)) ; if (n > 2) then ( execute (2)->display(); ) else skip ; for i : Integer.subrange(1, nNew + 1-1) do ( if (marked[i+1] = 0) then ( execute ((2 * i + 1))->display(); ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def setallbitgivenrange(n,l,r): range=(((1<<(l-1))-1)^((1<<(r))-1)) return(n | range) n,l,r=17,2,3 print(setallbitgivenrange(n,l,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{n,l,r} := Sequence{17,2,3} ; execute (setallbitgivenrange(n, l, r))->display(); operation setallbitgivenrange(n : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var range : int := (MathLib.bitwiseXor(((1 * (2->pow((l - 1)))) - 1), ((1 * (2->pow((r)))) - 1))) ; return (MathLib.bitwiseOr(n, range)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a,b=map(int,input().split()) f=0 if(a>b): if(b*3<=a): print((b+(b*3))//4) else : f=1 elif(b>a): if(a*3<=b): print((a+(a*3))//4) else : f=1 if(a==b or f==1): print((a+b)//4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var f : int := 0 ; if ((a->compareTo(b)) > 0) then ( if ((b * 3->compareTo(a)) <= 0) then ( execute ((b + (b * 3)) div 4)->display() ) else ( f := 1 ) ) else (if ((b->compareTo(a)) > 0) then ( if ((a * 3->compareTo(b)) <= 0) then ( execute ((a + (a * 3)) div 4)->display() ) else ( f := 1 ) ) else skip) ; if (a = b or f = 1) then ( execute ((a + b) div 4)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printSorted(a,n): front=-1 back=-1 for i in range(1,n,1): if(a[i]=0): if(a[i]>a[i+1]): back=i+1 break i-=1 if(front==-1 and back==-1): for i in range(0,n,1): print(a[i],end=" ") return while(front<=back): temp=a[front] a[front]=a[back] a[back]=temp front+=1 back-=1 for i in range(0,n,1): print(a[i],end=" ") if __name__=='__main__' : a=[1,7,6,5,4,3,2,8] n=len(a) printSorted(a,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := Sequence{1}->union(Sequence{7}->union(Sequence{6}->union(Sequence{5}->union(Sequence{4}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 8 }))))))) ; n := (a)->size() ; printSorted(a, n) ) else skip; operation printSorted(a : OclAny, n : OclAny) pre: true post: true activity: var front : int := -1 ; var back : int := -1 ; for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if ((a[i+1]->compareTo(a[i - 1+1])) < 0) then ( front := i - 1 ; break ) else skip) ; var i : double := n - 2 ; while (i >= 0) do ( if ((a[i+1]->compareTo(a[i + 1+1])) > 0) then ( back := i + 1 ; break ) else skip ; i := i - 1) ; if (front = -1 & back = -1) then ( for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( execute (a[i+1])->display()) ; return ) else skip ; while ((front->compareTo(back)) <= 0) do ( var temp : OclAny := a[front+1] ; a[front+1] := a[back+1] ; a[back+1] := temp ; front := front + 1 ; back := back - 1) ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( execute (a[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) i=a.index(max(a)) a=a[: :-1] k=(-(a.index(min(a))))-1 a=a[: :-1] k1=a[0] ind=0 for j in range(1,n): if a[j]<=k1 : ind=j k1=a[j] if a[0]==max(a)and a[-1]==min(a): print(0) elif itoInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var i : int := a->indexOf((a)->max()) - 1 ; a := a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var k : double := (-(a->indexOf((a)->min()) - 1)) - 1 ; a := a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var k1 : OclAny := a->first() ; var ind : int := 0 ; for j : Integer.subrange(1, n-1) do ( if (a[j+1]->compareTo(k1)) <= 0 then ( ind := j ; k1 := a[j+1] ) else skip) ; if a->first() = (a)->max() & a->last() = (a)->min() then ( execute (0)->display() ) else (if (i->compareTo(ind)) < 0 then ( execute (i + (k)->abs() - 1)->display() ) else ( execute (i + (k)->abs() - 2)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=input() l=a.split() maxi=0 mini=101 pos_maxi=0 pos_mini=0 for i in range(len(l)): l[i]=int(l[i]) if maxi=l[i]: mini=l[i] pos_mini=i ans=len(l)-1-pos_mini+pos_maxi if pos_maxi>pos_mini : print(ans-1) else : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : String := (OclFile["System.in"]).readLine() ; var l : OclAny := a.split() ; var maxi : int := 0 ; var mini : int := 101 ; var pos_maxi : int := 0 ; var pos_mini : int := 0 ; for i : Integer.subrange(0, (l)->size()-1) do ( l[i+1] := ("" + ((l[i+1])))->toInteger() ; if (maxi->compareTo(l[i+1])) < 0 then ( maxi := l[i+1] ; pos_maxi := i ) else skip ; if (mini->compareTo(l[i+1])) >= 0 then ( mini := l[i+1] ; pos_mini := i ) else skip) ; var ans : double := (l)->size() - 1 - pos_mini + pos_maxi ; if (pos_maxi->compareTo(pos_mini)) > 0 then ( execute (ans - 1)->display() ) else ( execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) line=input().split(' ') distance=0 smallest=[101,0] greatest=[0,0] for i in range(len(line)): if int(line[i])<=smallest[0]: smallest=[int(line[i]),i] if int(line[i])>greatest[0]: greatest=[int(line[i]),i] distance+=len(line)-(smallest[1]+1) distance+=greatest[1]-(0 if smallest[1]>greatest[1]else 1) print(distance) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var line : OclAny := input().split(' ') ; var distance : int := 0 ; var smallest : Sequence := Sequence{101}->union(Sequence{ 0 }) ; var greatest : Sequence := Sequence{0}->union(Sequence{ 0 }) ; for i : Integer.subrange(0, (line)->size()-1) do ( if (("" + ((line[i+1])))->toInteger()->compareTo(smallest->first())) <= 0 then ( smallest := Sequence{("" + ((line[i+1])))->toInteger()}->union(Sequence{ i }) ) else skip ; if (("" + ((line[i+1])))->toInteger()->compareTo(greatest->first())) > 0 then ( greatest := Sequence{("" + ((line[i+1])))->toInteger()}->union(Sequence{ i }) ) else skip) ; distance := distance + (line)->size() - (smallest[1+1] + 1) ; distance := distance + greatest[1+1] - (if (smallest[1+1]->compareTo(greatest[1+1])) > 0 then 0 else 1 endif) ; execute (distance)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) Max=max(a) Min=min(a) Count=a.index(Max) a.insert(0,a[Count]) a.pop(Count+1) for x in range(len(a)-1,-1,-1): if a[x]==Min : Count+=(len(a)-1)-x break print(Count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var Max : OclAny := (a)->max() ; var Min : OclAny := (a)->min() ; var Count : int := a->indexOf(Max) - 1 ; a := a.insertAt(0+1, a[Count+1]) ; a := a->excludingAt(Count + 1+1) ; for x : Integer.subrange(-1 + 1, (a)->size() - 1)->reverse() do ( if a[x+1] = Min then ( Count := Count + ((a)->size() - 1) - x ; break ) else skip) ; execute (Count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def changeToOnes(string): ctr=0 ; l=len(string); for i in range(l-1,-1,-1): if(string[i]=='1'): ctr+=1 ; else : break ; return l-ctr ; def removeZeroesFromFront(string): s="" ; i=0 ; while(idisplay(); ) else skip; operation changeToOnes(string : OclAny) pre: true post: true activity: var ctr : int := 0; ; var l : int := (string)->size(); ; for i : Integer.subrange(-1 + 1, l - 1)->reverse() do ( if (string[i+1] = '1') then ( ctr := ctr + 1; ) else ( break; )) ; return l - ctr;; operation removeZeroesFromFront(string : OclAny) pre: true post: true activity: var s : String := ""; ; var i : int := 0; ; while ((i->compareTo((string)->size())) < 0 & string[i+1] = '0') do ( i := i + 1;) ; if (i = (string)->size()) then ( s := "0"; ) else ( s := string.subrange(i+1, (string)->size() - i); ) ; return s;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=list(map(int,input().split())) lst=[] for i in range(0,m): x,y=map(int,input().split()) lst.append([x,y]) dp1=[0 for i in range(0,n)] dp2=[0 for i in range(0,n)] for i in range(1,n): if a[i]a[i]: dp2[i]=dp2[i+1]+a[i+1]-a[i] else : dp2[i]=dp2[i+1] for item in lst : if item[0]collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lst : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{x}->union(Sequence{ y })) : lst)) ; var dp1 : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var dp2 : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(1, n-1) do ( if (a[i+1]->compareTo(a[i - 1+1])) < 0 then ( dp1[i+1] := dp1[i - 1+1] + a[i - 1+1] - a[i+1] ) else ( dp1[i+1] := dp1[i - 1+1] )) ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( if (a[i + 1+1]->compareTo(a[i+1])) > 0 then ( dp2[i+1] := dp2[i + 1+1] + a[i + 1+1] - a[i+1] ) else ( dp2[i+1] := dp2[i + 1+1] )) ; for item : lst do ( if (item->first()->compareTo(item[1+1])) < 0 then ( var ans : double := dp1[item[1+1] - 1+1] - dp1[item->first() - 1+1] ) else ( ans := dp2[item[1+1] - 1+1] - dp2[item->first() - 1+1] ) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(X,Y,Z,V,E,A): dp=[[0.0]*6001 for _ in range(Y+11)] dp[0][0]=1.0 for i in range(Y): for j in range(5001): if dp[i][j]<=0.0 : continue for k in V : t=i+k if t>Y : dp[Y][j]+=dp[i][j]/X elif E[t]==1 : dp[min(Y,t+A[t])][j]+=dp[i][j]/X else : dp[t][max(0,j+A[t])]+=dp[i][j]/X s=0 for i in range(5001): if dp[Y][i]<=0.0 : continue s+=i*dp[Y][i] print(int(s)) if __name__=="__main__" : import sys while True : X,Y,Z=map(int,input().split()) if X | Y | Z==0 : sys.exit() V=list(map(int,input().split())) E=[0]*100 A=[0]*100 for _ in range(Z): n,e,a=map(int,input().split()) E[n]=e if e==3 : A[n]=-a else : A[n]=a solve(X,Y,Z,V,E,A) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( skip ; while true do ( Sequence{X,Y,Z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if MathLib.bitwiseOr(MathLib.bitwiseOr(X, Y), Z) = 0 then ( sys.exit() ) else skip ; V := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; E := MatrixLib.elementwiseMult(Sequence{ 0 }, 100) ; A := MatrixLib.elementwiseMult(Sequence{ 0 }, 100) ; for _anon : Integer.subrange(0, Z-1) do ( var n : OclAny := null; var e : OclAny := null; var a : OclAny := null; Sequence{n,e,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; E[n+1] := e ; if e = 3 then ( A[n+1] := -a ) else ( A[n+1] := a )) ; solve(X, Y, Z, V, E, A)) ) else skip; operation solve(X : OclAny, Y : OclAny, Z : OclAny, V : OclAny, E : OclAny, A : OclAny) pre: true post: true activity: var dp : Sequence := Integer.subrange(0, Y + 11-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0.0 }, 6001))) ; dp->first()->first() := 1.0 ; for i : Integer.subrange(0, Y-1) do ( for j : Integer.subrange(0, 5001-1) do ( if dp[i+1][j+1] <= 0.0 then ( continue ) else skip ; for k : V do ( var t : OclAny := i + k ; if (t->compareTo(Y)) > 0 then ( dp[Y+1][j+1] := dp[Y+1][j+1] + dp[i+1][j+1] / X ) else (if E[t+1] = 1 then ( dp[Set{Y, t + A[t+1]}->min()+1][j+1] := dp[Set{Y, t + A[t+1]}->min()+1][j+1] + dp[i+1][j+1] / X ) else ( dp[t+1][Set{0, j + A[t+1]}->max()+1] := dp[t+1][Set{0, j + A[t+1]}->max()+1] + dp[i+1][j+1] / X ) ) ))) ; var s : int := 0 ; for i : Integer.subrange(0, 5001-1) do ( if dp[Y+1][i+1] <= 0.0 then ( continue ) else skip ; s := s + i * dp[Y+1][i+1]) ; execute (("" + ((s)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=(int(v)for v in input().split()) list1=[int(v)for v in input().split()] listp=[0] listn=[0] sump=0 sumn=0 for i in range(n-1): d=list1[i+1]-list1[i] if d<0 : listp.append(d*(-1)+sump) sump=listp[i+1] else : listp.append(sump+0) for j in range(n-1): rd=list1[n-j-2]-list1[n-j-1] if rd<0 : listn.append(rd*(-1)+sumn) sumn=listn[j+1] else : listn.append(sumn+0) for k in range(m): s,t=(int(v)for v in input().split()) if sselect(v | true)->collect(v | (("" + ((v)))->toInteger())) ; var listp : Sequence := Sequence{ 0 } ; var listn : Sequence := Sequence{ 0 } ; var sump : int := 0 ; var sumn : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( var d : double := list1[i + 1+1] - list1[i+1] ; if d < 0 then ( execute ((d * (-1) + sump) : listp) ; sump := listp[i + 1+1] ) else ( execute ((sump + 0) : listp) )) ; for j : Integer.subrange(0, n - 1-1) do ( var rd : double := list1[n - j - 2+1] - list1[n - j - 1+1] ; if rd < 0 then ( execute ((rd * (-1) + sumn) : listn) ; sumn := listn[j + 1+1] ) else ( execute ((sumn + 0) : listn) )) ; for k : Integer.subrange(0, m-1) do ( var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) ))))))) (comp_for for (exprlist (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; if (s->compareTo(t)) < 0 then ( execute (listp[t - 1+1] - listp[s - 1+1])->display() ) else ( execute (listn[n - t+1] - listn[n - s+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class solution : def __init__(self)->None : self.world=[int(x)for x in input().split()] self.l=[0]+[max(0,self.world[i]-self.world[i+1])for i in range(len(self.world)-1)] self.r=[0]+[max(0,self.world[i]-self.world[i-1])for i in range(1,len(self.world))] for i in range(len(self.world)-1): self.l[i+1]+=self.l[i] self.r[i+1]+=self.r[i] def minimumfalldamage(self,start,end): if start0 : start,end=map(int,input().split()) print(s1.minimumfalldamage(start,end)) m-=1 ------------------------------------------------------------ OCL File: --------- class solution { static operation newsolution() : solution pre: true post: solution->exists( _x | result = _x ); operation __init__() : OclAny pre: true post: true activity: self.world := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; self.l := Sequence{ 0 }->union(Integer.subrange(0, (self.world)->size() - 1-1)->select(i | true)->collect(i | (Set{0, self.world[i+1] - self.world[i + 1+1]}->max()))) ; self.r := Sequence{ 0 }->union(Integer.subrange(1, (self.world)->size()-1)->select(i | true)->collect(i | (Set{0, self.world[i+1] - self.world[i - 1+1]}->max()))) ; for i : Integer.subrange(0, (self.world)->size() - 1-1) do ( self.l[i + 1+1] := self.l[i + 1+1] + self.l[i+1] ; self.r[i + 1+1] := self.r[i + 1+1] + self.r[i+1]); operation minimumfalldamage(start : OclAny,end : OclAny) : OclAny pre: true post: true activity: if (start->compareTo(end)) < 0 then ( return self.l[end - 1+1] - self.l[start - 1+1] ) else skip ; return self.r[start - 1+1] - self.r[end - 1+1]; } class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s1 : solution := (solution.newsolution()).initialise() ; while m > 0 do ( Sequence{start,end} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (s1.minimumfalldamage(start, end))->display() ; m := m - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b=map(int,input().split()) if a+b<4 or a==0 or b==0 : print(0) continue if a>b : a,b=b,a if a==b : print(a//2) elif b<3*a : res=(b-a)//2 print(res+(a-res)//2) else : print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a + b < 4 or a = 0 or b = 0 then ( execute (0)->display() ; continue ) else skip ; if (a->compareTo(b)) > 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a} ) else skip ; if a = b then ( execute (a div 2)->display() ) else (if (b->compareTo(3 * a)) < 0 then ( var res : int := (b - a) div 2 ; execute (res + (a - res) div 2)->display() ) else ( execute (a)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) w=list(map(int,input().split())) a=[0 for x in range(n)] s=0 for i in range(1,n): if w[i-1]>w[i]: s+=w[i-1]-w[i] a[i]=s b=[0 for x in range(n)] w=w[: :-1] s=0 for i in range(1,n): if w[i-1]>w[i]: s+=w[i-1]-w[i] b[i]=s for _ in range(m): f,l=map(int,input().split()) if f>l : f=n-f l=n-l s=b[l]-b[f] else : s=a[l-1]-a[f-1] print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := Integer.subrange(0, n-1)->select(x | true)->collect(x | (0)) ; var s : int := 0 ; for i : Integer.subrange(1, n-1) do ( if (w[i - 1+1]->compareTo(w[i+1])) > 0 then ( s := s + w[i - 1+1] - w[i+1] ) else skip ; a[i+1] := s) ; var b : Sequence := Integer.subrange(0, n-1)->select(x | true)->collect(x | (0)) ; w := w(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; s := 0 ; for i : Integer.subrange(1, n-1) do ( if (w[i - 1+1]->compareTo(w[i+1])) > 0 then ( s := s + w[i - 1+1] - w[i+1] ) else skip ; b[i+1] := s) ; for _anon : Integer.subrange(0, m-1) do ( var f : OclAny := null; var l : OclAny := null; Sequence{f,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (f->compareTo(l)) > 0 then ( var f : double := n - f ; var l : double := n - l ; s := b[l+1] - b[f+1] ) else ( s := a[l - 1+1] - a[f - 1+1] ) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=list(map(int,input().split())) left,right=[0 for i in range(n)],[0 for i in range(n)] for i in range(n-1,0,-1): left[i-1]=left[i]+max(0,a[i]-a[i-1]) for i in range(n-1): right[i+1]=right[i]+max(0,a[i]-a[i+1]) for _ in range(m): b,c=map(int,input().split()) if b<=c : print(right[c-1]-right[b-1]) else : print(left[c-1]-left[b-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var left : OclAny := null; var right : OclAny := null; Sequence{left,right} := Sequence{Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)),Integer.subrange(0, n-1)->select(i | true)->collect(i | (0))} ; for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( left[i - 1+1] := left[i+1] + Set{0, a[i+1] - a[i - 1+1]}->max()) ; for i : Integer.subrange(0, n - 1-1) do ( right[i + 1+1] := right[i+1] + Set{0, a[i+1] - a[i + 1+1]}->max()) ; for _anon : Integer.subrange(0, m-1) do ( var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (b->compareTo(c)) <= 0 then ( execute (right[c - 1+1] - right[b - 1+1])->display() ) else ( execute (left[c - 1+1] - left[b - 1+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def largest_sum(arr,n): maximum=-1 m=dict() for i in arr : m[i]=m.get(i,0)+1 for j in list(m): if((j in m)and m[j]>1): x,y=0,0 if 2*j in m : m[2*j]=m[2*j]+m[j]//2 else : m[2*j]=m[j]//2 if(2*j>maximum): maximum=2*j return maximum if __name__=='__main__' : arr=[1,1,2,4,7,8] n=len(arr) print(largest_sum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{7}->union(Sequence{ 8 }))))) ; n := (arr)->size() ; execute (largest_sum(arr, n))->display() ) else skip; operation largest_sum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var maximum : int := -1 ; var m : Map := (arguments ( )) ; for i : arr do ( m[i+1] := m.get(i, 0) + 1) ; for j : (m) do ( if (((m)->includes(j)) & m[j+1] > 1) then ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{0,0} ; if (m)->includes(2 * j) then ( m[2 * j+1] := m[2 * j+1] + m[j+1] div 2 ) else ( m[2 * j+1] := m[j+1] div 2 ) ; if ((2 * j->compareTo(maximum)) > 0) then ( maximum := 2 * j ) else skip ) else skip) ; return maximum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): ans="YES" columnst=int(input()) wcolumn=list(map(int,input().split(" "))) minwcolumn=min(wcolumn) if minwcolumn!=0 : for j in range(len(wcolumn)): wcolumn[j]=wcolumn[j]-minwcolumn for k in wcolumn : if k % 2!=0 : ans="NO" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var ans : String := "YES" ; var columnst : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var wcolumn : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var minwcolumn : OclAny := (wcolumn)->min() ; if minwcolumn /= 0 then ( for j : Integer.subrange(0, (wcolumn)->size()-1) do ( wcolumn[j+1] := wcolumn[j+1] - minwcolumn) ) else skip ; for k : wcolumn do ( if k mod 2 /= 0 then ( ans := "NO" ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) cnto=sum(list(map(lambda x : int(x)% 2,input().split()))) print('YES' if cnto==0 or cnto==n else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cnto : OclAny := (((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() mod 2))->apply(_x) )))->sum() ; execute (if cnto = 0 or cnto = n then 'YES' else 'NO' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) arr=list(map(int,input().split())) temp=arr[0]% 2 ans="YES" for i in arr : if i % 2!=temp : ans="NO" break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var temp : int := arr->first() mod 2 ; var ans : String := "YES" ; for i : arr do ( if i mod 2 /= temp then ( ans := "NO" ; break ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) count_odd=sum(x % 2 for x in a) if count_odd==0 or count_odd==n : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count_odd : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name x))) % (expr (atom (number (integer 2)))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a))))))))->sum() ; if count_odd = 0 or count_odd = n then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) even=0 odd=0 secondLine=list(map(int,input().split())) for i in range(len(secondLine)): if(secondLine[i]% 2==0): even+=1 else : odd+=1 if(even==len(secondLine)or odd==len(secondLine)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var even : int := 0 ; var odd : int := 0 ; var secondLine : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, (secondLine)->size()-1) do ( if (secondLine[i+1] mod 2 = 0) then ( even := even + 1 ) else ( odd := odd + 1 )) ; if (even = (secondLine)->size() or odd = (secondLine)->size()) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() a=[0]*n if(s[0]=='W'): a[0]=1 for i in range(1,n): if(s[i]=='W'): a[i]=a[i-1]+1 else : a[i]=a[i-1] ans=min(n-a[n-1]+a[0]-1,a[n-2]) for j in range(1,n-1): x=a[j-1]+(n-j-1)-(a[n-1]-a[j]) if(xtoInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; if (s->first() = 'W') then ( a->first() := 1 ) else skip ; for i : Integer.subrange(1, n-1) do ( if (s[i+1] = 'W') then ( a[i+1] := a[i - 1+1] + 1 ) else ( a[i+1] := a[i - 1+1] )) ; var ans : OclAny := Set{n - a[n - 1+1] + a->first() - 1, a[n - 2+1]}->min() ; for j : Integer.subrange(1, n - 1-1) do ( var x : double := a[j - 1+1] + (n - j - 1) - (a[n - 1+1] - a[j+1]) ; if ((x->compareTo(ans)) < 0) then ( ans := x ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): l=list(map(int,input().split())) c=0 for i in range(1,4): if(l[i]>l[0]): c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; for i : Integer.subrange(1, 4-1) do ( if ((l[i+1]->compareTo(l->first())) > 0) then ( c := c + 1 ) else skip) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,m=map(int,input().split()) if n==m==0 : break students=[0 for _ in range(n)] for _ in range(m): scores=list(map(int,input().split())) for i in range(n): students[i]+=scores[i] print(max(students)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = m & (m == 0) then ( break ) else skip ; var students : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)) ; for _anon : Integer.subrange(0, m-1) do ( var scores : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( students[i+1] := students[i+1] + scores[i+1])) ; execute ((students)->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for test in range(t): a,b,c,d=map(int,input().split()) rs=(b>a)+(c>a)+(d>a) print(rs) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for test : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var rs : boolean := ((b->compareTo(a)) > 0) + ((c->compareTo(a)) > 0) + ((d->compareTo(a)) > 0) ; execute (rs)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): a=[int(x)for x in input().split()] m,cnt=a[0],0 for j in range(1,4): if a[j]>m : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var m : OclAny := null; var cnt : OclAny := null; Sequence{m,cnt} := Sequence{a->first(),0} ; for j : Integer.subrange(1, 4-1) do ( if (a[j+1]->compareTo(m)) > 0 then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for _ in range(T): a=list(map(int,input().split())) n=a[0] a=a[1 :] cnt=0 for x in a : if n<=x : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, T-1) do ( var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := a->first() ; a := a->tail() ; var cnt : int := 0 ; for x : a do ( if (n->compareTo(x)) <= 0 then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tc=int(input()) for k in range(tc): l=list(int(x)for x in input().split()) ct=0 for i in range(3): if l[i+1]>l[0]: ct+=1 print(ct) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var tc : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for k : Integer.subrange(0, tc-1) do ( var l : Sequence := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ; var ct : int := 0 ; for i : Integer.subrange(0, 3-1) do ( if (l[i + 1+1]->compareTo(l->first())) > 0 then ( ct := ct + 1 ) else skip) ; execute (ct)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(N,X,D): if D==0 : if X==0 : return 1 return N+1 L={0 :[(0,1),(1,-1)]} coef_l=0 coef_r=1 for coef_x in range(1,N+1): m=X*coef_x % D l=X*coef_x//D+coef_l r=X*coef_x//D+coef_x*N-coef_r coef_l=coef_r coef_r+=coef_x+1 if m not in L : L[m]=[] L[m].append((l,1)) L[m].append((r+1,-1)) ans=0 for Q in L.values(): Q.sort() cnt=0 last=None for val,sign in Q : if cnt>0 : ans+=val-last cnt+=sign last=val return ans N,X,D=map(int,input().split()) print(solve(N,X,D)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{N,X,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (solve(N, X, D))->display(); operation solve(N : OclAny, X : OclAny, D : OclAny) : OclAny pre: true post: true activity: if D = 0 then ( if X = 0 then ( return 1 ) else skip ; return N + 1 ) else skip ; var L : Map := Map{ 0 |-> Sequence{Sequence{0, 1}}->union(Sequence{ Sequence{1, -1} }) } ; var coef_l : int := 0 ; var coef_r : int := 1 ; for coef_x : Integer.subrange(1, N + 1-1) do ( var m : int := X * coef_x mod D ; var l : int := X * coef_x div D + coef_l ; var r : double := X * coef_x div D + coef_x * N - coef_r ; coef_l := coef_r ; coef_r := coef_r + coef_x + 1 ; if (L)->excludes(m) then ( L[m+1] := Sequence{} ) else skip ; (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name m)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name l)))))) , (test (logical_test (comparison (expr (atom (number (integer 1)))))))) )))))))) )))) ; (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name m)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name r))) + (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (atom - (number (integer 1)))))))) )))))))) ))))) ; var ans : int := 0 ; for Q : L.values() do ( Q := Q->sort() ; var cnt : int := 0 ; var last : OclAny := null ; for _tuple : Q do (var _indx : int := 1; var val : OclAny := _tuple->at(_indx); _indx := _indx + 1; var sign : OclAny := _tuple->at(_indx); if cnt > 0 then ( ans := ans + val - last ) else skip ; cnt := cnt + sign ; last := val)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.buffer.readline n,x,d=map(int,input().split()) if d==0 : if x==0 : print(1) else : print(n+1) exit(0) m={} for i in range(n+1): t=i*x % d start=i*x//d l=(i-1)*i//2 r=(2*n-i-1)*i//2 if m.get(t): m[t].append([start+l,start+r]) else : m[t]=[[start+l,start+r]] inf=float('inf') ans=0 for x in m : now=m[x] now.sort() pl=-inf for l,r in now : if r<=pl : continue if l>pl : ans+=r-l+1 else : ans+=r-pl pl=r print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.buffer.readline ; var n : OclAny := null; var x : OclAny := null; var d : OclAny := null; Sequence{n,x,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if d = 0 then ( if x = 0 then ( execute (1)->display() ) else ( execute (n + 1)->display() ) ; exit(0) ) else skip ; var m : OclAny := Set{} ; for i : Integer.subrange(0, n + 1-1) do ( var t : int := i * x mod d ; var start : int := i * x div d ; var l : int := (i - 1) * i div 2 ; var r : int := (2 * n - i - 1) * i div 2 ; if m.get(t) then ( (expr (atom (name m)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name start))) + (expr (atom (name l))))))) , (test (logical_test (comparison (expr (expr (atom (name start))) + (expr (atom (name r)))))))) ]))))))) )))) ) else ( m[t+1] := Sequence{ Sequence{start + l}->union(Sequence{ start + r }) } )) ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; var ans : int := 0 ; for x : m do ( var now : OclAny := m[x+1] ; now := now->sort() ; var pl : double := -Math_PINFINITY ; for _tuple : now do (var _indx : int := 1; var l : OclAny := _tuple->at(_indx); _indx := _indx + 1; var r : OclAny := _tuple->at(_indx); if (r->compareTo(pl)) <= 0 then ( continue ) else skip ; if (l->compareTo(pl)) > 0 then ( ans := ans + r - l + 1 ) else ( ans := ans + r - pl ) ; pl := r)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda : sys.stdin.readline().rstrip() from collections import defaultdict def resolve(): n,a,d=map(int,input().split()) if(d==0): if(a!=0): print(n+1) else : print(1) return if(d<0): a,d=-a,-d D=defaultdict(list) for k in range(n+1): q,r=divmod(k*a,d) L=q+k*(k-1)//2 R=q+k*(2*n-k-1)//2 D[r].append((L,1)) D[r].append((R,2)) ans=0 for arr in D.values(): arr.sort() over=0 for v,q in arr : if(q==1 and over==0): left=v over+=1 if(q==1)else-1 if(over==0): ans+=v-left+1 print(ans) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(2147483647) ; var INF : double := ("" + (("inf")))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; skip ; skip ; resolve(); operation resolve() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var d : OclAny := null; Sequence{n,a,d} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (d = 0) then ( if (a /= 0) then ( execute (n + 1)->display() ) else ( execute (1)->display() ) ; return ) else skip ; if (d < 0) then ( var a : OclAny := null; var d : OclAny := null; Sequence{a,d} := Sequence{-a,-d} ) else skip ; var D : OclAny := defaultdict(OclType["Sequence"]) ; for k : Integer.subrange(0, n + 1-1) do ( var q : OclAny := null; var r : OclAny := null; Sequence{q,r} := Sequence{(k * a div d), (k * a mod d)} ; var L : OclAny := q + k * (k - 1) div 2 ; var R : OclAny := q + k * (2 * n - k - 1) div 2 ; (expr (atom (name D)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name L)))))) , (test (logical_test (comparison (expr (atom (number (integer 1)))))))) )))))))) )))) ; (expr (atom (name D)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name R)))))) , (test (logical_test (comparison (expr (atom (number (integer 2)))))))) )))))))) ))))) ; var ans : int := 0 ; for arr : D.values() do ( arr := arr->sort() ; var over : int := 0 ; for _tuple : arr do (var _indx : int := 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var q : OclAny := _tuple->at(_indx); if (q = 1 & over = 0) then ( var left : OclAny := v ) else skip ; over := over + if (q = 1) then 1 else -1 endif ; if (over = 0) then ( ans := ans + v - left + 1 ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from fractions import gcd n,x,d=map(int,input().split()) if x==d==0 : print(1); sys.exit() elif d==0 : print(n+1); sys.exit() if x<0 and x+(n-1)*d<0 : x,d=-x,-d if x>=0 and d<0 : x,d=x+(n-1)*d,-d g=gcd(x,d); ans=1 if x>=0 : for i in range(1,n+1): k=max((i-d//g)*(2*n-1-i+d//g)//2-x//g,i*(i-1)//2-1) ans+=max((i*(2*n-1-i))//2-k,0) else : for i in range(1,n+1): overlap_u=min((i-d//g)*(2*n-1-i+d//g)//2-x//g,i*(2*n-1-i)//2) overlap_l=max((i-d//g)*(i-d//g-1)//2-x//g,i*(i-1)//2) ans+=i*(2*n-1-i)//2-i*(i-1)//2+1-max(overlap_u-overlap_l+1,0) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var x : OclAny := null; var d : OclAny := null; Sequence{n,x,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x = d & (d == 0) then ( execute (1)->display(); sys.exit() ) else (if d = 0 then ( execute (n + 1)->display(); sys.exit() ) else skip) ; if x < 0 & x + (n - 1) * d < 0 then ( var x : OclAny := null; var d : OclAny := null; Sequence{x,d} := Sequence{-x,-d} ) else skip ; if x >= 0 & d < 0 then ( var x : OclAny := null; var d : OclAny := null; Sequence{x,d} := Sequence{x + (n - 1) * d,-d} ) else skip ; var g : OclAny := gcd(x, d); var ans : int := 1 ; if x >= 0 then ( for i : Integer.subrange(1, n + 1-1) do ( var k : OclAny := Set{(i - d div g) * (2 * n - 1 - i + d div g) div 2 - x div g, i * (i - 1) div 2 - 1}->max() ; ans := ans + Set{(i * (2 * n - 1 - i)) div 2 - k, 0}->max()) ) else ( for i : Integer.subrange(1, n + 1-1) do ( var overlap_u : OclAny := Set{(i - d div g) * (2 * n - 1 - i + d div g) div 2 - x div g, i * (2 * n - 1 - i) div 2}->min() ; var overlap_l : OclAny := Set{(i - d div g) * (i - d div g - 1) div 2 - x div g, i * (i - 1) div 2}->max() ; ans := ans + i * (2 * n - 1 - i) div 2 - i * (i - 1) div 2 + 1 - Set{overlap_u - overlap_l + 1, 0}->max()) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict ri=lambda : list(map(int,input().split(' '))) def solve(): n,a,d=ri() if d==0 : print(1 if a==0 else n+1) return if d<0 : a,d=-a,-d dic=defaultdict(list) for i in range(n+1): l=a*i+i*(i-1)//2*d r=a*i+(n-i+n-1)*i//2*d dic[l % d].append((l//d,r//d+1)) ans=0 for p in dic.values(): end=-1e18 p.sort() for t in p : s,e=t if endcollect( _x | (OclType["int"])->apply(_x) ))) ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var d : OclAny := null; Sequence{n,a,d} := ri->apply() ; if d = 0 then ( execute (if a = 0 then 1 else n + 1 endif)->display() ; return ) else skip ; if d < 0 then ( var a : OclAny := null; var d : OclAny := null; Sequence{a,d} := Sequence{-a,-d} ) else skip ; var dic : OclAny := defaultdict(OclType["Sequence"]) ; for i : Integer.subrange(0, n + 1-1) do ( var l : double := a * i + i * (i - 1) div 2 * d ; var r : double := a * i + (n - i + n - 1) * i div 2 * d ; (expr (atom (name dic)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name l))) % (expr (atom (name d))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name l))) // (expr (atom (name d))))))) , (test (logical_test (comparison (expr (expr (expr (atom (name r))) // (expr (atom (name d)))) + (expr (atom (number (integer 1))))))))) )))))))) ))))) ; var ans : int := 0 ; for p : dic.values() do ( var end : double := -("1e18")->toReal() ; p := p->sort() ; for t : p do ( var s : OclAny := null; var e : OclAny := null; Sequence{s,e} := t ; if (end->compareTo(s)) < 0 then ( ans := ans + (e - s) ; end := e ) else skip ; if (end->compareTo(e)) < 0 then ( ans := ans + (e - end) ; end := e ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input(); s=input(); m=c=s.count("E") for t in s : c-=t<"W" ; m=min(m,c); c+=t>"E" print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input(); var s : String := (OclFile["System.in"]).readLine(); var m : OclAny := s->count("E"); var c : int := s->count("E") ; for t : s->characters() do ( c := c - t < "W"; m := Set{m, c}->min(); c := c + t > "E") ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,re,sys,operator from collections import Counter,deque from operator import itemgetter from itertools import accumulate,combinations,groupby from sys import stdin,setrecursionlimit from copy import deepcopy import heapq setrecursionlimit(10**6) while 1 : n,m=map(int,stdin.readline().rstrip().split()) if(n,m)==(0,0): break a=[list(map(int,stdin.readline().rstrip().split()))for _ in range(m)] print(max(sum(i)for i in zip(*a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; setrecursionlimit((10)->pow(6)) ; while 1 do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if Sequence{n, m} = Sequence{0, 0} then ( break ) else skip ; var a : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (((stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; execute (((argument (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom (name a)))))))) )))))))))->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() lst=[] for i in range(n-1): sub=s[i : i+2] lst.append(sub) ans=max(lst,key=lst.count) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var lst : Sequence := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( var sub : OclAny := s.subrange(i+1, i + 2) ; execute ((sub) : lst)) ; var ans : OclAny := Set{lst, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name lst)) (trailer . (name count)))))))}->max() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() d={} for x,y in zip(s[:-1],s[1 :]): if x+y not in d : d[x+y]=0 d[x+y]+=1 keys=sorted(d.keys(),key=lambda k : d[k],reverse=True) print(keys[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var d : OclAny := Set{} ; for _tuple : Integer.subrange(1, s->front()->size())->collect( _indx | Sequence{s->front()->at(_indx), s->tail()->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if (d)->excludes(x + y) then ( d[x + y+1] := 0 ) else skip ; d[x + y+1] := d[x + y+1] + 1) ; var keys : Sequence := d.keys()->sortedBy($x | (lambda k : OclAny in (d[k+1]))->apply($x)) ; execute (keys->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() l1=[] for i in range(n-1): l1.append(s[i]+s[i+1]) s1=set(l1) a=0 c=a for item in s1 : a=l1.count(item) if a>c : c=a ans=item print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var l1 : Sequence := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( execute ((s[i+1] + s[i + 1+1]) : l1)) ; var s1 : Set := Set{}->union((l1)) ; var a : int := 0 ; var c : int := a ; for item : s1 do ( a := l1->count(item) ; if (a->compareTo(c)) > 0 then ( c := a ; var ans : OclAny := item ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() a=[] b=[] for i in range(n-1): if s[i : i+2]not in a : a.append(s[i : i+2]) b.append(1) else : x=a.index(s[i : i+2]) b[x]+=1 c=b.index(max(b)) print(a[c]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var a : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( if (a)->excludes(s.subrange(i+1, i + 2)) then ( execute ((s.subrange(i+1, i + 2)) : a) ; execute ((1) : b) ) else ( var x : int := a->indexOf(s.subrange(i+1, i + 2)) - 1 ; b[x+1] := b[x+1] + 1 )) ; var c : int := b->indexOf((b)->max()) - 1 ; execute (a[c+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() a=[s[i : i+2]for i in range(n-1)] print(max(a,key=a.count)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var a : Sequence := Integer.subrange(0, n - 1-1)->select(i | true)->collect(i | (s.subrange(i+1, i + 2))) ; execute (Set{a, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name a)) (trailer . (name count)))))))}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dig=[1,1,2,6,4,2,2,4,2,8] def lastNon0Digit(n): if(n<10): return dig[n] if(((n//10)% 10)% 2==0): return(6*lastNon0Digit(n//5)*dig[n % 10])% 10 else : return(4*lastNon0Digit(n//5)*dig[n % 10])% 10 return 0 n=14 print(lastNon0Digit(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dig : Sequence := Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{6}->union(Sequence{4}->union(Sequence{2}->union(Sequence{2}->union(Sequence{4}->union(Sequence{2}->union(Sequence{ 8 }))))))))) ; skip ; n := 14 ; execute (lastNon0Digit(n))->display(); operation lastNon0Digit(n : OclAny) : OclAny pre: true post: true activity: if (n < 10) then ( return dig[n+1] ) else skip ; if (((n div 10) mod 10) mod 2 = 0) then ( return (6 * lastNon0Digit(n div 5) * dig[n mod 10+1]) mod 10 ) else ( return (4 * lastNon0Digit(n div 5) * dig[n mod 10+1]) mod 10 ) ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=map(int,input().split()) if min(n,m)==1 and max(n,m)>2 : print(-1) elif abs(m-n)% 2==0 : print(m+n-2+abs(m-n)) else : print(m+n-3+abs(m-n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if Set{n, m}->min() = 1 & Set{n, m}->max() > 2 then ( execute (-1)->display() ) else (if (m - n)->abs() mod 2 = 0 then ( execute (m + n - 2 + (m - n)->abs())->display() ) else ( execute (m + n - 3 + (m - n)->abs())->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : n,m=map(int,input().split()) if n==1 and m>2 or m==1 and n>2 : print(-1) else : print(n-1+m-1+(max(n,m)-min(n,m))-(max(n,m)-min(n,m))% 2) t=t-1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 1 & m > 2 or m = 1 & n > 2 then ( execute (-1)->display() ) else ( execute (n - 1 + m - 1 + (Set{n, m}->max() - Set{n, m}->min()) - (Set{n, m}->max() - Set{n, m}->min()) mod 2)->display() ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=map(int,input().split()) maxi=max(n,m) if(n==1 and m>=3)or(m==1 and n>=3): print(-1) elif(n+m)& 1 : print(2*maxi-3) else : print(2*(maxi-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var maxi : OclAny := Set{n, m}->max() ; if (n = 1 & m >= 3) or (m = 1 & n >= 3) then ( execute (-1)->display() ) else (if MathLib.bitwiseAnd((n + m), 1) then ( execute (2 * maxi - 3)->display() ) else ( execute (2 * (maxi - 1))->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout def solution(n,m): if(n>2 and m==1)or(m>2 and n==1): return-1 if abs(n-m)% 2==0 : return n-1+m-1+abs(m-n) return n-1+m-1+abs(m-n)-1 test_cases=int(stdin.readline()) for it in range(test_cases): n,m=(int(x)for x in stdin.readline().split()) stdout.write(str(solution(n,m))+'\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var test_cases : int := ("" + ((stdin.readLine())))->toInteger() ; for it : Integer.subrange(0, test_cases-1) do ( Sequence{n,m} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name stdin)) (trailer . (name readline) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; stdout.write(("" + ((solution(n, m)))) + ' ')); operation solution(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: if (n > 2 & m = 1) or (m > 2 & n = 1) then ( return -1 ) else skip ; if (n - m)->abs() mod 2 = 0 then ( return n - 1 + m - 1 + (m - n)->abs() ) else skip ; return n - 1 + m - 1 + (m - n)->abs() - 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s,t=input(),input() freqs=dict() freqt=dict() yay,whoops=0,0 for letra in s : if letra in freqs : freqs[letra]+=1 else : freqs[letra]=1 for letra in t : if letra in freqt : freqt[letra]+=1 else : freqt[letra]=1 for letra in freqs.keys(): while(freqs[letra]>0 and letra in freqt and freqt[letra]>0): yay+=1 freqs[letra]-=1 freqt[letra]-=1 for letra in freqs.keys(): while(freqs[letra]>0): if letra.islower()and letra.upper()in freqt.keys()and freqt[letra.upper()]>0 : whoops+=1 freqs[letra]-=1 freqt[letra.upper()]-=1 elif letra.isupper()and letra.lower()in freqt.keys()and freqt[letra.lower()]>0 : whoops+=1 freqs[letra]-=1 freqt[letra.lower()]-=1 else : break ; print(yay,whoops) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine()} ; var freqs : Map := (arguments ( )) ; var freqt : Map := (arguments ( )) ; var yay : OclAny := null; var whoops : OclAny := null; Sequence{yay,whoops} := Sequence{0,0} ; for letra : s do ( if (freqs)->includes(letra) then ( freqs[letra+1] := freqs[letra+1] + 1 ) else ( freqs[letra+1] := 1 )) ; for letra : t do ( if (freqt)->includes(letra) then ( freqt[letra+1] := freqt[letra+1] + 1 ) else ( freqt[letra+1] := 1 )) ; for letra : freqs.keys() do ( while (freqs[letra+1] > 0 & (freqt)->includes(letra) & freqt[letra+1] > 0) do ( yay := yay + 1 ; freqs[letra+1] := freqs[letra+1] - 1 ; freqt[letra+1] := freqt[letra+1] - 1)) ; for letra : freqs.keys() do ( while (freqs[letra+1] > 0) do ( if letra->matches("[a-z ]*") & (freqt.keys())->includes(letra->toUpperCase()) & freqt[letra->toUpperCase()+1] > 0 then ( whoops := whoops + 1 ; freqs[letra+1] := freqs[letra+1] - 1 ; freqt[letra->toUpperCase()+1] := freqt[letra->toUpperCase()+1] - 1 ) else (if letra->matches("[A-Z ]*") & (freqt.keys())->includes(letra->toLowerCase()) & freqt[letra->toLowerCase()+1] > 0 then ( whoops := whoops + 1 ; freqs[letra+1] := freqs[letra+1] - 1 ; freqt[letra->toLowerCase()+1] := freqt[letra->toLowerCase()+1] - 1 ) else ( break; ) ) )) ; execute (yay)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(n,m): scores=[[int(x)for x in input().split()]for _ in range(m)] return max([sum(z)for z in zip(*scores)]) def main(args): while True : n,m=map(int,input().split()) if n==0 and m==0 : break ans=solve(n,m) print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var scores : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))) ; return (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name scores)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name scores)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name scores)))))))`third->at(_indx)} )->select(z | true)->collect(z | ((z)->sum())))->max(); operation main(args : OclAny) pre: true post: true activity: while true do ( Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 & m = 0 then ( break ) else skip ; var ans : OclAny := solve(n, m) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def examC(): N=I() S=SI() E=S.count("E"); W=N-E curW=0 ; curE=0 ans=N-1 for i in range(N): if S[i]=="W" : curW+=1 cur=N-1-(W-curW)-curE if S[i]=="E" : curE+=1 ans=min(ans,cur) print(ans) return def examD(): return import sys,copy,bisect,itertools,heapq,math from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) def LSI(): return list(map(str,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod,mod2,inf,alphabet,ALPHABET mod=10**9+7 mod2=998244353 inf=10**18 alphabet=[chr(ord('a')+i)for i in range(26)] ALPHABET=[chr(ord('A')+i)for i in range(26)] if __name__=='__main__' : examC() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute mod : OclAny; attribute mod2 : OclAny; attribute inf : OclAny; attribute alphabet : OclAny; attribute ALPHABET : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip; skip; skip; skip; skip ; mod := (10)->pow(9) + 7 ; mod2 := 998244353 ; Math_PINFINITY := (10)->pow(18) ; alphabet := Integer.subrange(0, 26-1)->select(i | true)->collect(i | ((('a')->char2byte() + i)->byte2char())) ; ALPHABET := Integer.subrange(0, 26-1)->select(i | true)->collect(i | ((('A')->char2byte() + i)->byte2char())) ; if __name__ = '__main__' then ( examC() ) else skip; operation examC() pre: true post: true activity: var N : OclAny := I() ; var S : OclAny := SI() ; var E : int := S->count("E"); var W : double := N - E ; var curW : int := 0; var curE : int := 0 ; var ans : double := N - 1 ; for i : Integer.subrange(0, N-1) do ( if S[i+1] = "W" then ( curW := curW + 1 ) else skip ; var cur : double := N - 1 - (W - curW) - curE ; if S[i+1] = "E" then ( curE := curE + 1 ) else skip ; ans := Set{ans, cur}->min()) ; execute (ans)->display() ; return; operation examD() pre: true post: true activity: return; operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LSI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["String"])->apply(_x) )); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation SI() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math n=int(input()) if n>1 and n<4 : if n==2 : print('1'+'\n'+'1') else : print('2'+'\n'+'1 3') sys.exit() print(n) i=2 while i<=n : print(i,end=' '); i+=2 i=1 while i<=n : print(i,end=' '); i+=2 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n > 1 & n < 4 then ( if n = 2 then ( execute ('1' + ' ' + '1')->display() ) else ( execute ('2' + ' ' + '1 3')->display() ) ; sys.exit() ) else skip ; execute (n)->display() ; var i : int := 2 ; while (i->compareTo(n)) <= 0 do ( execute (i)->display(); i := i + 2) ; i := 1 ; while (i->compareTo(n)) <= 0 do ( execute (i)->display(); i := i + 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[] for i in range(1,n+1): l.append(i) if n!=1 and n!=2 and n!=3 and n!=4 : print(n) for i in range(0,n,2): print(l[i],end=" ") for i in range(1,n,2): print(l[i],end=" ") else : if n==1 : print(n) print(1) elif n==2 : print(n-1) print(1) elif n==3 : print(n-1) print(1,3) else : print(n) print(3,1,4,2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( execute ((i) : l)) ; if n /= 1 & n /= 2 & n /= 3 & n /= 4 then ( execute (n)->display() ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( execute (l[i+1])->display()) ; for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( execute (l[i+1])->display()) ) else ( if n = 1 then ( execute (n)->display() ; execute (1)->display() ) else (if n = 2 then ( execute (n - 1)->display() ; execute (1)->display() ) else (if n = 3 then ( execute (n - 1)->display() ; execute (1)->display() ) else ( execute (n)->display() ; execute (3)->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==1 or n==2 : print(1) print(1) elif n==3 : print(2) print(1,3) else : print(n) nums=[2,4,1,3] left=True for i in range(4,n,1): if left : nums.insert(0,i+1) else : nums.append(i+1) left=not left [print(num,end=" ")for num in nums] print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 or n = 2 then ( execute (1)->display() ; execute (1)->display() ) else (if n = 3 then ( execute (2)->display() ; execute (1)->display() ) else ( execute (n)->display() ; var nums : Sequence := Sequence{2}->union(Sequence{4}->union(Sequence{1}->union(Sequence{ 3 }))) ; var left : boolean := true ; for i : Integer.subrange(4, n-1)->select( $x | ($x - 4) mod 1 = 0 ) do ( if left then ( nums := nums.insertAt(0+1, i + 1) ) else ( execute ((i + 1) : nums) ) ; left := not(left)) ) ) ; ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) li=[i+1 for i in range(n)] e=[i for i in li if i % 2==0] o=[i for i in li if i % 2] if n==2 or n==3 : e.pop() if n==4 : print(4); print('2 4 1 3') else : print(len(e)+len(o)) print(*o,*e) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i + 1)) ; var e : Sequence := li->select(i | i mod 2 = 0)->collect(i | (i)) ; var o : Sequence := li->select(i | i mod 2)->collect(i | (i)) ; if n = 2 or n = 3 then ( e := e->front() ) else skip ; if n = 4 then ( execute (4)->display(); execute ('2 4 1 3')->display() ) else ( execute ((e)->size() + (o)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name o))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==2 or n==1 : print(1,'\n1') elif n==3 : print(2,'\n1 3') else : odd=[i for i in range(1,n+1)if i % 2][: :-1] even=[i for i in range(1,n+1)if i % 2==0][: :-1] print(n) for i in odd : print(i,end=' ') for i in even : print(i,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 2 or n = 1 then ( execute (1)->display() ) else (if n = 3 then ( execute (2)->display() ) else ( var odd : OclAny := Integer.subrange(1, n + 1-1)->select(i | i mod 2)->collect(i | (i))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var even : OclAny := Integer.subrange(1, n + 1-1)->select(i | i mod 2 = 0)->collect(i | (i))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; execute (n)->display() ; for i : odd do ( execute (i)->display()) ; for i : even do ( execute (i)->display()) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math N,A,B=map(int,input().split()) H=[int(input())for _ in range(N)] def enough(T): temp=0 ch=H[:] for h in ch : left=h-B*T if left>0 : temp+=(left+A-B-1)//(A-B) if temp>T : return False else : return True ok=10**15 ng=0 while ok-ng>1 : mid=(ok+ng)//2 if enough(mid): ok=mid else : ng=mid print(ok) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{N,A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var H : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; skip ; var ok : double := (10)->pow(15) ; var ng : int := 0 ; while ok - ng > 1 do ( var mid : int := (ok + ng) div 2 ; if enough(mid) then ( ok := mid ) else ( ng := mid )) ; execute (ok)->display(); operation enough(T : OclAny) : OclAny pre: true post: true activity: var temp : int := 0 ; var ch : Sequence := H ; for h : ch do ( var left : double := h - B * T ; if left > 0 then ( temp := temp + (left + A - B - 1) div (A - B) ) else skip) ; if (temp->compareTo(T)) > 0 then ( return false ) else ( return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,Counter from itertools import product,groupby,count,permutations,combinations from math import pi,sqrt from collections import deque from bisect import bisect,bisect_left,bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF=float("inf") YES,Yes,yes,NO,No,no="YES","Yes","yes","NO","No","no" dy4,dx4=[0,1,0,-1],[1,0,-1,0] dy8,dx8=[0,-1,0,1,1,-1,-1,1],[1,0,-1,0,1,1,-1,-1] def inside(y,x,H,W): return 0<=y0 : num+=ceil(r,(A-B)) return num<=n def main(): N,A,B=map(int,input().split()) H=sorted([int(input())for _ in range(N)]) low,high=0,10**10 ans=0 while high-low>1 : middle=(low+high)//2 if ok(middle,A,B,H): ans=middle high=middle else : low=middle print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(10000) ; var INF : double := ("" + (("inf")))->toReal() ; var YES : OclAny := null; var Yes : OclAny := null; var yes : OclAny := null; var NO : OclAny := null; var No : OclAny := null; var no : OclAny := null; Sequence{YES,Yes,yes,NO,No,no} := Sequence{"YES","Yes","yes","NO","No","no"} ; var dy4 : OclAny := null; var dx4 : OclAny := null; Sequence{dy4,dx4} := Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ -1 }))),Sequence{1}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{ 0 })))} ; var dy8 : OclAny := null; var dx8 : OclAny := null; Sequence{dy8,dx8} := Sequence{Sequence{0}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{-1}->union(Sequence{-1}->union(Sequence{ 1 }))))))),Sequence{1}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{-1}->union(Sequence{ -1 })))))))} ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation inside(y : OclAny, x : OclAny, H : OclAny, W : OclAny) : OclAny pre: true post: true activity: return 0 <= y & (y < H) & 0 <= x & (x < W); operation ceil(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a + b - 1) div b; operation ok(n : OclAny, A : OclAny, B : OclAny, H : OclAny) : OclAny pre: true post: true activity: var num : int := 0 ; for h : H do ( var r : double := h - n * B ; if r > 0 then ( num := num + ceil(r, (A - B)) ) else skip) ; return (num->compareTo(n)) <= 0; operation main() pre: true post: true activity: var N : OclAny := null; Sequence{N,A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; H := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))->sort() ; var low : OclAny := null; var high : OclAny := null; Sequence{low,high} := Sequence{0,(10)->pow(10)} ; var ans : int := 0 ; while high - low > 1 do ( var middle : int := (low + high) div 2 ; if ok(middle, A, B, H) then ( ans := middle ; var high : int := middle ) else ( var low : int := middle )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=map(int,input().split()) ls=[int(input())for _ in range(n)] m=max(ls) lo=(m+a-1)//a hi=(m+b-1)//b+1 mi=(hi+lo)//2 while hi>lo+1 : mi=(hi+lo)//2 if sum([(max(x-mi*b,0)+a-b-1)//(a-b)for x in ls])<=mi : hi=mi else : lo=mi if sum([(max(x-lo*b,0)+a-b-1)//(a-b)for x in ls])<=lo : print(lo) else : print(hi) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ls : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var m : OclAny := (ls)->max() ; var lo : int := (m + a - 1) div a ; var hi : int := (m + b - 1) div b + 1 ; var mi : int := (hi + lo) div 2 ; while (hi->compareTo(lo + 1)) > 0 do ( mi := (hi + lo) div 2 ; if ((ls->select(x | true)->collect(x | ((Set{x - mi * b, 0}->max() + a - b - 1) div (a - b))))->sum()->compareTo(mi)) <= 0 then ( hi := mi ) else ( lo := mi )) ; if ((ls->select(x | true)->collect(x | ((Set{x - lo * b, 0}->max() + a - b - 1) div (a - b))))->sum()->compareTo(lo)) <= 0 then ( execute (lo)->display() ) else ( execute (hi)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin def input(): return stdin.readline().strip() n,a,b=map(int,input().split()) h=[] for _ in range(n): h.append(int(input())) sum_h=sum(h) left=sum_h//(a+b*(n-1)) right=min([sum_h//a+n,max(h)//b+1]) while left0 : num+=(i-1)//(a-b)+1 if num<=center : right=center else : left=center+1 print(left) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : h)) ; var sum_h : OclAny := (h)->sum() ; var left : int := sum_h div (a + b * (n - 1)) ; var right : OclAny := (Sequence{sum_h div a + n}->union(Sequence{ (h)->max() div b + 1 }))->min() ; while (left->compareTo(right)) < 0 do ( var center : int := (left + right) div 2 ; var base : double := center * b ; var num : int := 0 ; for i : h do ( i := i - base ; if i > 0 then ( num := num + (i - 1) div (a - b) + 1 ) else skip) ; if (num->compareTo(center)) <= 0 then ( right := center ) else ( left := center + 1 )) ; execute (left)->display(); operation input() : OclAny pre: true post: true activity: return stdin.readLine()->trim(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=[int(e)for e in input().split()] if(n[0]==0)and(n[1]==0): break m=[[0 for i in range(n[0])]for j in range(n[1]+1)] for j in range(n[1]): m[j]=[int(e)for e in input().split()] for k in range(n[0]): score=0 for j in range(n[1]): score=m[j][k]+score m[(n[1])][k]=score max_=m[(n[1])][0] for k in range(n[0]): if max_select(e | true)->collect(e | (("" + ((e)))->toInteger())) ; if (n->first() = 0) & (n[1+1] = 0) then ( break ) else skip ; var m : Sequence := Integer.subrange(0, n[1+1] + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, n->first()-1)->select(i | true)->collect(i | (0)))) ; for j : Integer.subrange(0, n[1+1]-1) do ( m[j+1] := input().split()->select(e | true)->collect(e | (("" + ((e)))->toInteger()))) ; for k : Integer.subrange(0, n->first()-1) do ( var score : int := 0 ; for j : Integer.subrange(0, n[1+1]-1) do ( score := m[j+1][k+1] + score) ; m[(n[1+1])+1][k+1] := score) ; var max_ : OclAny := m[(n[1+1])+1]->first() ; for k : Integer.subrange(0, n->first()-1) do ( if (max_->compareTo(m[(n[1+1])+1][k+1])) < 0 then ( max_ := m[(n[1+1])+1][k+1] ) else skip) ; execute (max_)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import numpy as np read=sys.stdin.read N,A,B,*h=map(int,read().split()) h=np.array(h,np.int64) l=0 r=max(h)//B+2 a=A-B while l+10] tmp=tmp//a+np.minimum(tmp % a,1) if tmp.sum()<=mid : r=mid else : l=mid print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var read : OclAny := (OclFile["System.in"]).read ; var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; var h : OclAny := null; Sequence{N,A,B,h} := (read().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h : Sequence := (h, ) ; var l : int := 0 ; var r : int := (h)->max() div B + 2 ; var a : double := A - B ; while (l + 1->compareTo(r)) < 0 do ( var mid : int := (l + r) div 2 ; var w : double := B * mid ; var tmp : double := h - w ; tmp := tmp->select(tmp > 0) ; tmp := tmp div a + ; if (tmp.sum()->compareTo(mid)) <= 0 then ( r := mid ) else ( l := mid )) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import*; input(); s=input(); print(min(w+e for w,e in zip(*[([0]+list(accumulate(map(int,s[: : a].translate(str.maketrans("EW","01"[: : a])))))[:-1])[: : a]for a in[-1,1]]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; input(); var s : String := (OclFile["System.in"]).readLine(); execute (((argument (test (logical_test (comparison (expr (expr (atom (name w))) + (expr (atom (name e))))))) (comp_for for (exprlist (expr (atom (name w))) , (expr (atom (name e)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) + (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name accumulate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom (name a))))))))) ])) (trailer . (name translate) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)) (trailer . (name maketrans) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "EW")))))) , (argument (test (logical_test (comparison (expr (atom "01") (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom (name a))))))))) ])))))))) ))))))))) ))))))))) ))))))))) ))))))))) ))) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))))) )) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom (name a))))))))) ])))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom - (number (integer 1))))))) , (test (logical_test (comparison (expr (atom (number (integer 1)))))))) ])))))) ]))))))) )))))))))->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=list(map(int,input().split(' '))) if(m-n+1<3): print(-1) elif(n % 2==0): print(n,' ',n+1,' ',n+2) elif(m-n+1>3): print(n+1,' ',n+2,' ',n+3) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; if (m - n + 1 < 3) then ( execute (-1)->display() ) else (if (n mod 2 = 0) then ( execute (n)->display() ) else (if (m - n + 1 > 3) then ( execute (n + 1)->display() ) else ( execute (-1)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- li=[int(l)for l in input().split()] l=li[0]; r=li[1] quit=0 odd=3 even=2 if r-l<2 : print(-1) else : for i in range(l,r+1): if quit==1 : break for j in range(i,r+1): if j<=(r-2)and i % 2==0 and(j+1)% 2!=0 and(j+2)% 2==0 : if i % even==0 and(j+2)% even==0 : print(i,j+1,j+2) quit=1 break else : even+=2 elif j<=(r-2)and i % 2!=0 and(j+1)% 2==0 and(j+2)% 2!=0 : if i % odd==0 and(j+2)% odd==0 : print(i,j+1,j+2) quit=1 break else : odd+=2 if quit!=1 : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var li : Sequence := input().split()->select(l | true)->collect(l | (("" + ((l)))->toInteger())) ; var l : OclAny := li->first(); var r : OclAny := li[1+1] ; var quit : int := 0 ; var odd : int := 3 ; var even : int := 2 ; if r - l < 2 then ( execute (-1)->display() ) else ( for i : Integer.subrange(l, r + 1-1) do ( if quit = 1 then ( break ) else skip ; for j : Integer.subrange(i, r + 1-1) do ( if (j->compareTo((r - 2))) <= 0 & i mod 2 = 0 & (j + 1) mod 2 /= 0 & (j + 2) mod 2 = 0 then ( if i mod even = 0 & (j + 2) mod even = 0 then ( execute (i)->display() ; quit := 1 ; break ) else ( even := even + 2 ) ) else (if (j->compareTo((r - 2))) <= 0 & i mod 2 /= 0 & (j + 1) mod 2 = 0 & (j + 2) mod 2 /= 0 then ( if i mod odd = 0 & (j + 2) mod odd = 0 then ( execute (i)->display() ; quit := 1 ; break ) else ( odd := odd + 2 ) ) else skip))) ; if quit /= 1 then ( execute (-1)->display() ) else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l,r=[int(l)for l in input().split()] if l % 2==1 : l+=1 if r-l<2 : print(-1); exit() print(l,l+1,l+2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := input().split()->select(l | true)->collect(l | (("" + ((l)))->toInteger())) ; if l mod 2 = 1 then ( l := l + 1 ) else skip ; if r - l < 2 then ( execute (-1)->display(); exit() ) else skip ; execute (l)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) c=abs(b-a) if c==1 or c==0 : print(-1) elif a % 2==0 and b % 2==0 : print(f'{a}{a+1}{a+2}') elif a % 2==1 and b % 2==1 : if c==2 : print(-1) else : print(f'{a+1}{a+2}{a+3}') else : if a % 2==0 : print(f'{a}{a+1}{a+2}') elif a % 2==1 : print(f'{a+1}{a+2}{a+3}') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : double := (b - a)->abs() ; if c = 1 or c = 0 then ( execute (-1)->display() ) else (if a mod 2 = 0 & b mod 2 = 0 then ( execute (StringLib.formattedString('{a}{a+1}{a+2}'))->display() ) else (if a mod 2 = 1 & b mod 2 = 1 then ( if c = 2 then ( execute (-1)->display() ) else ( execute (StringLib.formattedString('{a+1}{a+2}{a+3}'))->display() ) ) else ( if a mod 2 = 0 then ( execute (StringLib.formattedString('{a}{a+1}{a+2}'))->display() ) else (if a mod 2 = 1 then ( execute (StringLib.formattedString('{a+1}{a+2}{a+3}'))->display() ) else skip) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd l,r=map(int,input().split()) if l % 2==0 and r>l+1 : print(l,l+1,l+2) elif l % 2==1 and r>l+2 : print(l+1,l+2,l+3) elif l % 2==1 : if gcd(l,l+2)>1 : print(l,l+1,l+2) else : print(-1) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if l mod 2 = 0 & (r->compareTo(l + 1)) > 0 then ( execute (l)->display() ) else (if l mod 2 = 1 & (r->compareTo(l + 2)) > 0 then ( execute (l + 1)->display() ) else (if l mod 2 = 1 then ( if gcd(l, l + 2) > 1 then ( execute (l)->display() ) else ( execute (-1)->display() ) ) else ( execute (-1)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minSteps(arr,n): v=[0 for i in range(n)] q=[] q.append(0) depth=0 while(len(q)!=0): x=len(q) while(x>=1): i=q[0] q.remove(i) x-=1 if(v[i]): continue ; if(i==n-1): return depth v[i]=1 if(i+arr[i]=0): q.append(i-arr[i]) depth+=1 return-1 if __name__=='__main__' : arr=[1,1,1,1,1,1] n=len(arr) print(minSteps(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))))) ; n := (arr)->size() ; execute (minSteps(arr, n))->display() ) else skip; operation minSteps(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var v : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var q : Sequence := Sequence{} ; execute ((0) : q) ; var depth : int := 0 ; while ((q)->size() /= 0) do ( var x : int := (q)->size() ; while (x >= 1) do ( var i : OclAny := q->first() ; execute ((i) /: q) ; x := x - 1 ; if (v[i+1]) then ( continue; ) else skip ; if (i = n - 1) then ( return depth ) else skip ; v[i+1] := 1 ; if ((i + arr[i+1]->compareTo(n)) < 0) then ( execute ((i + arr[i+1]) : q) ) else skip ; if (i - arr[i+1] >= 0) then ( execute ((i - arr[i+1]) : q) ) else skip) ; depth := depth + 1) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isEven(n): if(n ^ 1==n+1): return True ; else : return False ; if __name__=="__main__" : n=100 ; print("Even")if isEven(n)else print("Odd"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 100; ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Even"))))))) )))))) if (logical_test (comparison (expr (atom (name isEven)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Odd"))))))) )))))))); ) else skip; operation isEven(n : OclAny) pre: true post: true activity: if (MathLib.bitwiseXor(n, 1) = n + 1) then ( return true; ) else ( return false; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isEven(n): return(not(n & 1)) n=101 ; print("Even" if isEven(n)else "Odd") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 101; ; execute (if isEven(n) then "Even" else "Odd" endif)->display(); operation isEven(n : OclAny) : OclAny pre: true post: true activity: return (not((MathLib.bitwiseAnd(n, 1)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import array from fractions import Fraction import functools import itertools import math import os import sys def main(): while True : N,M=read_ints() if(N,M)==(0,0): break P=[read_ints()for _ in range(M)] print(solve(N,M,P)) def solve(N,M,P): T=[[P[j][i]for j in range(M)]for i in range(N)] return max([sum(t)for t in T]) DEBUG='DEBUG' in os.environ def inp(): return sys.stdin.readline().rstrip() def read_int(): return int(inp()) def read_ints(): return[int(e)for e in inp().split()] def dprint(*value,sep=' ',end='\n'): if DEBUG : print(*value,sep=sep,end=end) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var DEBUG : boolean := (os.environ)->includes('DEBUG') ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: while true do ( var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := read_ints() ; if Sequence{N, M} = Sequence{0, 0} then ( break ) else skip ; var P : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (read_ints())) ; execute (solve(N, M, P))->display()); operation solve(N : OclAny, M : OclAny, P : OclAny) : OclAny pre: true post: true activity: var T : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Integer.subrange(0, M-1)->select(j | true)->collect(j | (P[j+1][i+1])))) ; return (T->select(t | true)->collect(t | ((t)->sum())))->max(); operation inp() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation read_int() : OclAny pre: true post: true activity: return ("" + ((inp())))->toInteger(); operation read_ints() : OclAny pre: true post: true activity: return inp().split()->select(e | true)->collect(e | (("" + ((e)))->toInteger())); operation dprint(value : OclAny : Sequence(OclAny), sep : String, end : String) pre: true post: true activity: (args * (named_parameter (name value))) if sep->oclIsUndefined() then sep := ' ' else skip; if end->oclIsUndefined() then end := ' ' else skip; if DEBUG then ( execute ((argument * (test (logical_test (comparison (expr (atom (name value))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isEven(n): return(n % 2==0) n=101 print("Even" if isEven(n)else "Odd") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 101 ; execute (if isEven(n) then "Even" else "Odd" endif)->display(); operation isEven(n : OclAny) : OclAny pre: true post: true activity: return (n mod 2 = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isEven(n): return(not(n & 1)); if __name__=="__main__" : n=101 ; if isEven(n): print("Even") else : print("Odd"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 101; ; if isEven(n) then ( execute ("Even")->display() ) else ( execute ("Odd")->display(); ) ) else skip; operation isEven(n : OclAny) pre: true post: true activity: return (not((MathLib.bitwiseAnd(n, 1))));; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline N=int(input()) S=input() int_s=[0]*N cum_sum_w=[0]*(N+1) cum_sum_e=[0]*(N+1) answers=[0]*N for i in range(N): if(S[i]=='W'): int_s[i]=1 else : int_s[i]=0 cum_sum_w[i+1]=cum_sum_w[i]+int_s[i] for i in range(N): if(S[i]=='E'): int_s[i]=1 else : int_s[i]=0 cum_sum_e[i+1]=cum_sum_e[i]+int_s[i] for i in range(N): answers[i]=cum_sum_w[i]+(cum_sum_e[N]-cum_sum_e[i+1]) print(min(answers)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : String := (OclFile["System.in"]).readLine() ; var int_s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var cum_sum_w : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; var cum_sum_e : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; var answers : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for i : Integer.subrange(0, N-1) do ( if (S[i+1] = 'W') then ( int_s[i+1] := 1 ) else ( int_s[i+1] := 0 ) ; cum_sum_w[i + 1+1] := cum_sum_w[i+1] + int_s[i+1]) ; for i : Integer.subrange(0, N-1) do ( if (S[i+1] = 'E') then ( int_s[i+1] := 1 ) else ( int_s[i+1] := 0 ) ; cum_sum_e[i + 1+1] := cum_sum_e[i+1] + int_s[i+1]) ; for i : Integer.subrange(0, N-1) do ( answers[i+1] := cum_sum_w[i+1] + (cum_sum_e[N+1] - cum_sum_e[i + 1+1])) ; execute ((answers)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for ROUND in range(int(input())): n=int(input()) l=[input()for x in range(n)] k=len(set(l)) if(n==k): print(0) print(*l,sep="\n") continue print(n-k) for i in range(n): if l[i]in l[i+1 :]: j=0 while l[i]in l[i+1 :]+l[: i]: l[i]=l[i][: 3]+str(j) j+=1 print(*l,sep="\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for ROUND : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Integer.subrange(0, n-1)->select(x | true)->collect(x | ((OclFile["System.in"]).readLine())) ; var k : int := (Set{}->union((l)))->size() ; if (n = k) then ( execute (0)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name l))))))))->display() ; continue ) else skip ; execute (n - k)->display() ; for i : Integer.subrange(0, n-1) do ( if (l.subrange(i + 1+1))->includes(l[i+1]) then ( var j : int := 0 ; while (l.subrange(i + 1+1) + l.subrange(1,i))->includes(l[i+1]) do ( l[i+1] := l[i+1].subrange(1,3) + ("" + ((j))) ; j := j + 1) ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name l))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for t in range(T): n=int(input()) A=[] for i in range(n): A.append(input()) set_A=set(A) changes=0 if(len(A)!=len(set_A)): A=[list(l)for l in A] max_l=-1 max_i=-1 for i in range(4): length=len(set([l[i]for l in A])) if(length>max_l): max_i=i max_l=length used=(set([int(l[max_i])for l in A])) use=-1 for i in range(len(A)): if(A[i]in A[i+1 :]): changes=changes+1 use=use+1 while(use in used): use=use+1 A[i][max_i]=str(use) A=["".join(l)for l in A] print(changes) for l in A : print(l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(0, T-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : A)) ; var set_A : Set := Set{}->union((A)) ; var changes : int := 0 ; if ((A)->size() /= (set_A)->size()) then ( A := A->select(l | true)->collect(l | ((l))) ; var max_l : int := -1 ; var max_i : int := -1 ; for i : Integer.subrange(0, 4-1) do ( var length : int := (Set{}->union((A->select(l | true)->collect(l | (l[i+1])))))->size() ; if ((length->compareTo(max_l)) > 0) then ( max_i := i ; max_l := length ) else skip) ; var used : Set := (Set{}->union((A->select(l | true)->collect(l | (("" + ((l[max_i+1])))->toInteger()))))) ; var use : int := -1 ; for i : Integer.subrange(0, (A)->size()-1) do ( if ((A.subrange(i + 1+1))->includes(A[i+1])) then ( changes := changes + 1 ; use := use + 1 ; while ((used)->includes(use)) do ( use := use + 1) ; A[i+1][max_i+1] := ("" + ((use))) ) else skip) ; A := A->select(l | true)->collect(l | (StringLib.sumStringsWithSeparator((l), ""))) ) else skip ; execute (changes)->display() ; for l : A do ( execute (l)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) p=[(input())for j in range(n)] ans=0 for i in range(n): if p[i]in p[i+1 :]: ans+=1 j=0 while p[i]in p[i+1 :]+p[: i]: p[i]=p[i][: 3]+str(j) j+=1 print(ans) for i in range(n): print(p[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (((OclFile["System.in"]).readLine()))) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (p.subrange(i + 1+1))->includes(p[i+1]) then ( ans := ans + 1 ; var j : int := 0 ; while (p.subrange(i + 1+1) + p.subrange(1,i))->includes(p[i+1]) do ( p[i+1] := p[i+1].subrange(1,3) + ("" + ((j))) ; j := j + 1) ) else skip) ; execute (ans)->display() ; for i : Integer.subrange(0, n-1) do ( execute (p[i+1])->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline t=int(input()) ans=[] for _ in range(t): n=int(input()) p=[list(input().rstrip())for _ in range(n)] s=set() for p0 in p : s.add("".join(p0)) s0=set() k=0 ans0=[] for i in range(n): pi=p[i] if not "".join(pi)in s0 : s0.add("".join(pi)) else : k+=1 for j in range(10): pi[0]=str(j) if not "".join(pi)in s : s.add("".join(pi)) s0.add("".join(pi)) ok=1 break ans0.append("".join(pi)) ans.append(str(k)) ans.append("\n".join(ans0)) sys.stdout.write("\n".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((input().rstrip()))) ; var s : Set := Set{}->union(()) ; for p0 : p do ( execute ((StringLib.sumStringsWithSeparator((p0), "")) : s)) ; var s0 : Set := Set{}->union(()) ; var k : int := 0 ; var ans0 : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var pi : OclAny := p[i+1] ; if not((s0)->includes(StringLib.sumStringsWithSeparator((pi), ""))) then ( execute ((StringLib.sumStringsWithSeparator((pi), "")) : s0) ) else ( k := k + 1 ; for j : Integer.subrange(0, 10-1) do ( pi->first() := ("" + ((j))) ; if not((s)->includes(StringLib.sumStringsWithSeparator((pi), ""))) then ( execute ((StringLib.sumStringsWithSeparator((pi), "")) : s) ; execute ((StringLib.sumStringsWithSeparator((pi), "")) : s0) ; var ok : int := 1 ; break ) else skip) ) ; execute ((StringLib.sumStringsWithSeparator((pi), "")) : ans0)) ; execute ((("" + ((k)))) : ans) ; execute ((StringLib.sumStringsWithSeparator((ans0), "\n")) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): mp={} n=int(input()) st=set() for __ in range(n): pin=int(input()) if pin in mp : mp[pin].append(__) else : mp[pin]=[__] st.add(pin) def modify(s): return((4-len(s))*"0")+s arr=[0]*n ans=0 for v in mp : ans+=(len(mp[v])-1) while len(mp[v])>1 : for i in range(10): new_pin=i*1000+v % 1000 if new_pin not in st : arr[mp[v].pop()]=modify(str(new_pin)) st.add(new_pin) break else : arr[mp[v].pop()]=modify(str(v)) print(ans) for v in arr : print(v) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var mp : OclAny := Set{} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var st : Set := Set{}->union(()) ; for __ : Integer.subrange(0, n-1) do ( var pin : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (mp)->includes(pin) then ( (expr (atom (name mp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name pin)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name __)))))))) )))) ) else ( mp[pin+1] := Sequence{ __ } ) ; execute ((pin) : st)) ; skip ; var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var ans : int := 0 ; for v : mp do ( ans := ans + ((mp[v+1])->size() - 1) ; (compound_stmt while (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name mp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])))))))) ))))) > (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 10))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name new_pin)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (name i))) * (expr (atom (number (integer 1000))))) + (expr (expr (atom (name v))) % (expr (atom (number (integer 1000))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name new_pin)))) not in (comparison (expr (atom (name st))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name mp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name pop) (arguments ( ))))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name modify)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name new_pin)))))))) ))))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name st)) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name new_pin)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name mp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name pop) (arguments ( ))))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name modify)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) ))))))))) ))))))))))))))))) ; execute (ans)->display() ; for v : arr do ( execute (v)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSubstring(S,n): ans=0 ; i=0 ; while(isize(); ; execute (countSubstring(S, n))->display(); ) else skip; operation countSubstring(S : OclAny, n : OclAny) pre: true post: true activity: var ans : int := 0; ; var i : int := 0; ; while ((i->compareTo(n)) < 0) do ( var cnt0 : int := 0; var cnt1 : int := 0; ; if (S[i+1] = '0') then ( while ((i->compareTo(n)) < 0 & S[i+1] = '0') do ( cnt0 := cnt0 + 1; ; i := i + 1;) ; var j : int := i; ; while ((j->compareTo(n)) < 0 & S[j+1] = '1') do ( cnt1 := cnt1 + 1; ; j := j + 1;) ) else ( while ((i->compareTo(n)) < 0 & S[i+1] = '1') do ( cnt1 := cnt1 + 1; ; i := i + 1;) ; j := i; ; while ((j->compareTo(n)) < 0 & S[j+1] = '0') do ( cnt0 := cnt0 + 1; ; j := j + 1;) ) ; ans := ans + Set{cnt0, cnt1}->min();) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def canConstruct(self,ransomNote,magazine): letter_map={} for letter in magazine : letter_map[letter]=letter_map.get(letter,0)+1 for letter in ransomNote : letter_map[letter]=letter_map.get(letter,0)-1 if letter_map[letter]<0 : return False return True ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation canConstruct(ransomNote : OclAny,magazine : OclAny) : OclAny pre: true post: true activity: var letter_map : OclAny := Set{} ; for letter : magazine do ( letter_map[letter+1] := letter_map.get(letter, 0) + 1) ; for letter : ransomNote do ( letter_map[letter+1] := letter_map.get(letter, 0) - 1 ; if letter_map[letter+1] < 0 then ( return false ) else skip) ; return true; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) now=-1 for i in range(n): l,r=map(int,input().split()) if now<=l : print(l,end=' ') now=l+1 elif now<=r : print(now,end=' ') now+=1 else : print(0,end=' ') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var now : int := -1 ; for i : Integer.subrange(0, n-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (now->compareTo(l)) <= 0 then ( execute (l)->display() ; now := l + 1 ) else (if (now->compareTo(r)) <= 0 then ( execute (now)->display() ; now := now + 1 ) else ( execute (0)->display() ) ) ) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lis(arr,n): result=0 lis=[0 for i in range(n)] for i in range(n): lis[i]=1 for i in range(1,n): for j in range(i): if(arr[i]>arr[j]and lis[i]toInteger(); operation reads() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): while b!=0 : a,b=b,a % b return a N,X=map(int,input().split()) x=list(map(int,input().split())) kari=[] for i in range(N): kari.append(abs(x[i]-X)) ans=gcd(min(kari),max(kari)) for i in range(N): ans=gcd(ans,kari[i]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var X : OclAny := null; Sequence{N,X} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var kari : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute (((x[i+1] - X)->abs()) : kari)) ; var ans : OclAny := gcd((kari)->min(), (kari)->max()) ; for i : Integer.subrange(0, N-1) do ( ans := gcd(ans, kari[i+1])) ; execute (ans)->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: while b /= 0 do ( Sequence{a,b} := Sequence{b,a mod b}) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): while True : n=int(input()) if n : aa,ba=0,0 a,b=[None]*n,[None]*n for i in range(n): a[i],b[i]=map(int,input().split()) if a[i]>b[i]: aa+=(a[i]+b[i]) elif a[i]toInteger() ; if n then ( var aa : OclAny := null; var ba : OclAny := null; Sequence{aa,ba} := Sequence{0,0} ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{MatrixLib.elementwiseMult(Sequence{ null }, n),MatrixLib.elementwiseMult(Sequence{ null }, n)} ; for i : Integer.subrange(0, n-1) do ( var a[i+1] : OclAny := null; var b[i+1] : OclAny := null; Sequence{a[i+1],b[i+1]} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a[i+1]->compareTo(b[i+1])) > 0 then ( aa := aa + (a[i+1] + b[i+1]) ) else (if (a[i+1]->compareTo(b[i+1])) < 0 then ( ba := ba + (a[i+1] + b[i+1]) ) else ( aa := aa + a[i+1] ; ba := ba + b[i+1] ) ) ) ; execute (aa)->display() ) else ( break )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def perfectSquare(s): n=len(s) ans=-1 num="" for i in range(1,(1<>j)& 1): str=str+s[j] if(str[0]!='0'): temp=0 ; for j in range(0,len(str)): temp=(temp*10+(ord(str[j])-ord('0'))) k=int(math.sqrt(temp)) if(k*k==temp): if(ansdisplay() ; execute (perfectSquare("753"))->display();; operation perfectSquare(s : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; var ans : int := -1 ; var num : String := "" ; for i : Integer.subrange(1, (1 * (2->pow(n)))-1) do ( var OclType["String"] : String := "" ; for j : Integer.subrange(0, n-1) do ( if (MathLib.bitwiseAnd((i /(2->pow(j))), 1)) then ( OclType["String"] := OclType["String"] + s[j+1] ) else skip) ; if (("" + (->first())) /= '0') then ( var temp : int := 0; ; for j : Integer.subrange(0, (OclType["String"])->size()-1) do ( temp := (temp * 10 + ((("" + ([j+1])))->char2byte() - ('0')->char2byte()))) ; var k : int := ("" + (((temp)->sqrt())))->toInteger() ; if (k * k = temp) then ( if ((ans->compareTo((OclType["String"])->size())) < 0) then ( ans := (OclType["String"])->size() ; num := OclType["String"] ) else skip ) else skip ) else skip) ; if (ans = -1) then ( return ans ) else ( execute (StringLib.interpolateStrings("{}", Sequence{num}))->display() ; return n - ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,x=map(int,input().split()) num_list=list(map(int,input().split())) res=0 for i in num_list : res=math.gcd(res,abs(i-x)) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var num_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : int := 0 ; for i : num_list do ( res := (res)->gcd((i - x)->abs())) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a : int,b : int)->int : if aint : sorted_x=sorted([X]+x) dists=[sorted_x[i+1]-sorted_x[i]for i in range(len(x))] before=0 for d in dists : before=gcd(before,d) return before if __name__=="__main__" : N,X=map(int,input().split()) x=[int(s)for s in input().split()] ans=skip(N,X,x) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var N : OclAny := null; var X : OclAny := null; Sequence{N,X} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; var ans : OclAny := skip(N, X, x) ; execute (ans)->display() ) else skip; operation gcd(a : int, b : int) : int pre: true post: true activity: if (a->compareTo(b)) < 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a} ) else skip ; if b = 0 then ( return a ) else skip ; return gcd(b, a mod b); operation skip(N : int, X : int, x : Sequence(OclAny)) : int pre: true post: true activity: var sorted_x : Sequence := Sequence{ X }->union(x)->sort() ; var dists : Sequence := Integer.subrange(0, (x)->size()-1)->select(i | true)->collect(i | (sorted_x[i + 1+1] - sorted_x[i+1])) ; var before : int := 0 ; for d : dists do ( before := gcd(before, d)) ; return before; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys import queue from collections import Counter from itertools import accumulate from fractions import gcd from functools import reduce def lcm(a,b): return a*b//gcd(a,b) def combination_count(n,r): return math.factorial(n)//(math.factorial(n-r)*math.factorial(r)) def permutations_count(n,r): return math.factorial(n)//math.factorial(n-r) sys.setrecursionlimit(10000) mod=1000000007 if __name__=="__main__" : N,X=map(int,sys.stdin.readline().split()) L=list(map(int,sys.stdin.readline().split())) L.append(X) L.sort() D=[abs(x2-x1)for x1,x2 in zip(L,L[1 : :])] print(reduce(gcd,D)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(10000) ; var mod : int := 1000000007 ; if __name__ = "__main__" then ( var N : OclAny := null; var X : OclAny := null; Sequence{N,X} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var L : Sequence := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((X) : L) ; L := L->sort() ; var D : Sequence := Integer.subrange(1, L->size())->collect( _indx | Sequence{L->at(_indx), L(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop :))->at(_indx)} )->select(_tuple | true)->collect(_tuple | let x1 : OclAny = _tuple->at(1) in let x2 : OclAny = _tuple->at(2) in ((x2 - x1)->abs())) ; execute (reduce(gcd, D))->display() ) else skip; operation lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a * b div gcd(a, b); operation combination_count(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: return MathLib.factorial(n) div (MathLib.factorial(n - r) * MathLib.factorial(r)); operation permutations_count(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: return MathLib.factorial(n) div MathLib.factorial(n - r); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from gcjt import* from math import sqrt for t in tests(): n=int(t.rl()) a=[0]*6 for i in range(n): aa=tuple(t.ri()) for i in range(6): a[i]+=aa[i] for i in range(6): a[i]/=n x,y,z,vx,vy,vz=a d=vx**2+vy**2+vz**2 if d==0 : tt=0 else : tt=-(x*vx+y*vy+z*vz)/(vx**2+vy**2+vz**2) if tt<0 : tt=0 x,y,z=x+vx*tt,y+vy*tt,z+vz*tt s=sqrt(x**2+y**2+z**2) t.answer('{0:.8f}{1:.8f}'.format(s,tt)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for t : tests() do ( var n : int := ("" + ((t.rl())))->toInteger() ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 6) ; for i : Integer.subrange(0, n-1) do ( var aa : Sequence := (t.ri()) ; for i : Integer.subrange(0, 6-1) do ( a[i+1] := a[i+1] + aa[i+1])) ; for i : Integer.subrange(0, 6-1) do ( a[i+1] := a[i+1] / n) ; var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; var vx : OclAny := null; var vy : OclAny := null; var vz : OclAny := null; Sequence{x,y,z,vx,vy,vz} := a ; var d : double := (vx)->pow(2) + (vy)->pow(2) + (vz)->pow(2) ; if d = 0 then ( var tt : int := 0 ) else ( tt := -(x * vx + y * vy + z * vz) / ((vx)->pow(2) + (vy)->pow(2) + (vz)->pow(2)) ; if tt < 0 then ( tt := 0 ) else skip ) ; var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := Sequence{x + vx * tt,y + vy * tt,z + vz * tt} ; var s : OclAny := sqrt((x)->pow(2) + (y)->pow(2) + (z)->pow(2)) ; t.answer(StringLib.interpolateStrings('{0:.8f}{1:.8f}', Sequence{s, tt}))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sq(p): return sum([x*x for x in p]) def dist(p): return sq(p)**.5 if __name__=="__main__" : T=int(input()) for X in range(1,T+1): N=int(input()) t0t=[0,0,0] t1t=[0,0,0] for f in range(N): x,y,z,vx,vy,vz=[int(w)for w in input().split()] t0t[0]+=x t0t[1]+=y t0t[2]+=z t1t[0]+=x+vx t1t[1]+=y+vy t1t[2]+=z+vz t0m=[float(x)/float(N)for x in t0t] t1m=[float(x)/float(N)for x in t1t] U=[t1m[i]-t0m[i]for i in range(3)] tmin=0.0 denom=sq(U) if denom>0 : num=sum([-t0m[i]*U[i]for i in range(3)]) tmin=num/denom if tmin<0 : tmin=0.0 newp=[t0m[i]+tmin*U[i]for i in range(3)] dmin=dist(newp) print("Case #"+str(X)+": "+str(dmin)+" "+str(tmin)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for X : Integer.subrange(1, T + 1-1) do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t0t : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) ; var t1t : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) ; for f : Integer.subrange(0, N-1) do ( var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; var vx : OclAny := null; var vy : OclAny := null; var vz : OclAny := null; Sequence{x,y,z,vx,vy,vz} := input().split()->select(w | true)->collect(w | (("" + ((w)))->toInteger())) ; t0t->first() := t0t->first() + x ; t0t[1+1] := t0t[1+1] + y ; t0t[2+1] := t0t[2+1] + z ; t1t->first() := t1t->first() + x + vx ; t1t[1+1] := t1t[1+1] + y + vy ; t1t[2+1] := t1t[2+1] + z + vz) ; var t0m : Sequence := t0t->select(x | true)->collect(x | (("" + ((x)))->toReal() / ("" + ((N)))->toReal())) ; var t1m : Sequence := t1t->select(x | true)->collect(x | (("" + ((x)))->toReal() / ("" + ((N)))->toReal())) ; var U : Sequence := Integer.subrange(0, 3-1)->select(i | true)->collect(i | (t1m[i+1] - t0m[i+1])) ; var tmin : double := 0.0 ; var denom : OclAny := sq(U) ; if denom > 0 then ( var num : OclAny := (Integer.subrange(0, 3-1)->select(i | true)->collect(i | (-t0m[i+1] * U[i+1])))->sum() ; tmin := num / denom ) else skip ; if tmin < 0 then ( tmin := 0.0 ) else skip ; var newp : Sequence := Integer.subrange(0, 3-1)->select(i | true)->collect(i | (t0m[i+1] + tmin * U[i+1])) ; var dmin : OclAny := dist(newp) ; execute ("Case #" + ("" + ((X))) + ": " + ("" + ((dmin))) + " " + ("" + ((tmin))))->display()) ) else skip; operation sq(p : OclAny) : OclAny pre: true post: true activity: return (p->select(x | true)->collect(x | (x * x)))->sum(); operation dist(p : OclAny) : OclAny pre: true post: true activity: return (sq(p))->pow(.5); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections t=int(input()) for i in range(t): n=int(input()) res=["0"]*n queue=collections.deque() for j in range(n): l,r=map(int,input().split()) queue.append((l,r,j)) time=0 while queue : l,r,index=queue.popleft() if time<=l : res[index]=str(l) time=l+1 elif ltoInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : Sequence := MatrixLib.elementwiseMult(Sequence{ "0" }, n) ; var queue : Sequence := () ; for j : Integer.subrange(0, n-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{l, r, j}) : queue)) ; var time : int := 0 ; while queue do ( var l : OclAny := null; var r : OclAny := null; var index : OclAny := null; Sequence{l,r,index} := queue->first() ; queue := queue->tail() ; if (time->compareTo(l)) <= 0 then ( res[index+1] := ("" + ((l))) ; time := l + 1 ) else (if (l->compareTo(time)) < 0 & (time <= r) then ( res[index+1] := ("" + ((time))) ; time := time + 1 ) else skip)) ; execute (StringLib.sumStringsWithSeparator((res), " "))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math fin=open('input.txt','r') fout=open('output.txt','w') l=int(fin.readline()) for case in range(l): N=int(fin.readline()) px,py,pz=0.0,0.0,0.0 vx,vy,vz=0.0,0.0,0.0 for i in range(N): ix,iy,iz,ivx,ivy,ivz=map(float,fin.readline().strip().split()) px+=ix py+=iy pz+=iz vx+=ivx vy+=ivy vz+=ivz px/=N py/=N pz/=N vx/=N vy/=N vz/=N if vx==0 and vy==0 and vz==0 : fout.write("Case #%d: %.8f 0.00000000\n" %(case+1,math.pow(px*px+py*py+pz*pz,0.5))) continue t=(-px*vx-py*vy-pz*vz)/(vx*vx+vy*vy+vz*vz) if t<0 : fout.write("Case #%d: %.8f 0.00000000\n" %(case+1,math.pow(px*px+py*py+pz*pz,0.5))) continue else : px+=vx*t py+=vy*t pz+=vz*t fout.write("Case #%d: %.8f %.8f\n" %(case+1,math.pow(px*px+py*py+pz*pz,0.5),t)) fin.close() fout.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var fin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('input.txt')) ; var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('output.txt')) ; var l : int := ("" + ((fin.readLine())))->toInteger() ; for case : Integer.subrange(0, l-1) do ( var N : int := ("" + ((fin.readLine())))->toInteger() ; var px : OclAny := null; var py : OclAny := null; var pz : OclAny := null; Sequence{px,py,pz} := Sequence{0.0,0.0,0.0} ; var vx : OclAny := null; var vy : OclAny := null; var vz : OclAny := null; Sequence{vx,vy,vz} := Sequence{0.0,0.0,0.0} ; for i : Integer.subrange(0, N-1) do ( var ix : OclAny := null; var iy : OclAny := null; var iz : OclAny := null; var ivx : OclAny := null; var ivy : OclAny := null; var ivz : OclAny := null; Sequence{ix,iy,iz,ivx,ivy,ivz} := (fin.readLine()->trim().split())->collect( _x | (OclType["double"])->apply(_x) ) ; px := px + ix ; py := py + iy ; pz := pz + iz ; vx := vx + ivx ; vy := vy + ivy ; vz := vz + ivz) ; px := px / N ; py := py / N ; pz := pz / N ; vx := vx / N ; vy := vy / N ; vz := vz / N ; if vx = 0 & vy = 0 & vz = 0 then ( fout.write(StringLib.format("Case #%d: %.8f 0.00000000\n",Sequence{case + 1, (px * px + py * py + pz * pz)->pow(0.5)})) ; continue ) else skip ; var t : double := (-px * vx - py * vy - pz * vz) / (vx * vx + vy * vy + vz * vz) ; if t < 0 then ( fout.write(StringLib.format("Case #%d: %.8f 0.00000000\n",Sequence{case + 1, (px * px + py * py + pz * pz)->pow(0.5)})) ; continue ) else ( px := px + vx * t ; py := py + vy * t ; pz := pz + vz * t ; fout.write(StringLib.format("Case #%d: %.8f %.8f\n",Sequence{case + 1, (px * px + py * py + pz * pz)->pow(0.5), t})) )) ; fin.closeFile() ; fout.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countStrings(s): sum=1 for i in range(len(s)): if(i % 2==0 and s[i]=='$'): sum*=21 elif(s[i]=='$'): sum*=5 return sum if __name__=="__main__" : str="s$$e$" print(countStrings(str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var OclType["String"] : String := "s$$e$" ; execute (countStrings(OclType["String"]))->display() ) else skip; operation countStrings(s : OclAny) : OclAny pre: true post: true activity: var sum : int := 1 ; for i : Integer.subrange(0, (s)->size()-1) do ( if (i mod 2 = 0 & s[i+1] = '$') then ( sum := sum * 21 ) else (if (s[i+1] = '$') then ( sum := sum * 5 ) else skip)) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) a=[] for i in range(1,k+1): if k>=i : a.append(i) k-=i else : a[-1]+=k break str_a=[str(x)for x in a] print(len(a)) print(" ".join(str_a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; for i : Integer.subrange(1, k + 1-1) do ( if (k->compareTo(i)) >= 0 then ( execute ((i) : a) ; k := k - i ) else ( a->last() := a->last() + k ; break )) ; var str_a : Sequence := a->select(x | true)->collect(x | (("" + ((x))))) ; execute ((a)->size())->display() ; execute (StringLib.sumStringsWithSeparator((str_a), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[] while n>len(a): a+=[len(a)+1] n-=a[-1] a[-1]+=n print(len(a)) print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; while (n->compareTo((a)->size())) > 0 do ( a := a + Sequence{ (a)->size() + 1 } ; n := n - a->last()) ; a->last() := a->last() + n ; execute ((a)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) i=1 s=[] while n!=0 : if ntoInteger() ; var i : int := 1 ; var s : Sequence := Sequence{} ; while n /= 0 do ( if (n->compareTo(i)) < 0 then ( s->last() := s->last() + n ; n := 0 ) else ( execute ((i) : s) ; n := n - i ; i := i + 1 )) ; execute ((s)->size())->display() ; execute (StringLib.sumStringsWithSeparator(((s)->collect( _x | (OclType["String"])->apply(_x) )), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def squarearea(a,b): if(a<0 or b<0): return-1 area=4*(((pow(a,2)+pow(b,2))/(pow(a,2)*pow(b,2)))) return area if __name__=='__main__' : a=4 b=2 print(squarearea(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := 4 ; b := 2 ; execute (squarearea(a, b))->display() ) else skip; operation squarearea(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a < 0 or b < 0) then ( return -1 ) else skip ; var area : double := 4 * ((((a)->pow(2) + (b)->pow(2)) / ((a)->pow(2) * (b)->pow(2)))) ; return area; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==1 : print(1) print(1) else : a=[] b=[] i=1 s=1 while s<=n : a.append(i) i+=1 s+=i rem=n-sum(a) if rem<=a[-1]: a[-1]+=rem else : a.append(rem) print(len(a)) print(' '.join(str(x)for x in a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (1)->display() ; execute (1)->display() ) else ( var a : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; var i : int := 1 ; var s : int := 1 ; while (s->compareTo(n)) <= 0 do ( execute ((i) : a) ; i := i + 1 ; s := s + i) ; var rem : double := n - (a)->sum() ; if (rem->compareTo(a->last())) <= 0 then ( a->last() := a->last() + rem ) else ( execute ((rem) : a) ) ; execute ((a)->size())->display() ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a)))))))), ' '))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) result=0 mu=0 while mu*(mu+1)/2<=n : result=mu mu+=1 print(result) p=1 while ptoInteger() ; var result : int := 0 ; var mu : int := 0 ; while (mu * (mu + 1) / 2->compareTo(n)) <= 0 do ( result := mu ; mu := mu + 1) ; execute (result)->display() ; var p : int := 1 ; while (p->compareTo(result)) < 0 do ( execute (p)->display() ; p := p + 1) ; execute (n - p * (p - 1) div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def GIF(n): return int(math.floor(n)); n=2.3 ; print(GIF(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 2.3; ; execute (GIF(n))->display();; operation GIF(n : OclAny) pre: true post: true activity: return ("" + (((n)->floor())))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,k=map(int,input().split()) if k % 2 : ans=b-a else : ans=a-b print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var k : OclAny := null; Sequence{a,b,c,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if k mod 2 then ( var ans : double := b - a ) else ( ans := a - b ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) ans=[0]*n i=1 for z in range(n): l,r=map(int,input().split()) if l<=i : if r>=i : ans[z]=i i+=1 else : ans[z]=0 else : if r>=i : i=l ans[z]=i i+=1 else : ans[z]=0 print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var i : int := 1 ; for z : Integer.subrange(0, n-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (l->compareTo(i)) <= 0 then ( if (r->compareTo(i)) >= 0 then ( ans[z+1] := i ; i := i + 1 ) else ( ans[z+1] := 0 ) ) else ( if (r->compareTo(i)) >= 0 then ( i := l ; ans[z+1] := i ; i := i + 1 ) else ( ans[z+1] := 0 ) )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,k=[int(w)for w in input().split()] print(a-b if k % 2==0 else b-a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var k : OclAny := null; Sequence{a,b,c,k} := input().split()->select(w | true)->collect(w | (("" + ((w)))->toInteger())) ; execute (if k mod 2 = 0 then a - b else b - a endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def main(): ans=0 A,B,C,K=map(int,input().split()) if K % 2==0 : ans=A-B else : ans=B-A if ans>=10**18 : ans='Unfair' print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var ans : int := 0 ; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var K : OclAny := null; Sequence{A,B,C,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if K mod 2 = 0 then ( ans := A - B ) else ( ans := B - A ) ; if (ans->compareTo((10)->pow(18))) >= 0 then ( ans := 'Unfair' ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B,C,K=list(map(int,input().split())) if K % 2!=0 : r=B-A else : r=A-B if abs(r)>10**18 : print('Unfair') else : print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var K : OclAny := null; Sequence{A,B,C,K} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if K mod 2 /= 0 then ( var r : double := B - A ) else ( r := A - B ) ; if ((r)->abs()->compareTo((10)->pow(18))) > 0 then ( execute ('Unfair')->display() ) else ( execute (r)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): A,B,C,K=map(int,open(0).read().split()) if abs(A-B)>10**18 : print('Unfair') else : if K % 2 : print(B-A) else : print(A-B) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var K : OclAny := null; Sequence{A,B,C,K} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if ((A - B)->abs()->compareTo((10)->pow(18))) > 0 then ( execute ('Unfair')->display() ) else ( if K mod 2 then ( execute (B - A)->display() ) else ( execute (A - B)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def findMinValue(arr,n): arr.sort() val=0 for i in range(n): val+=(math.log(arr[i])) left=arr[0] right=arr[n-1]+1 while(left<=right): mid=(left+right)//2 temp=n*(math.log(mid)) if(valunion(Sequence{2}->union(Sequence{1}->union(Sequence{10}->union(Sequence{ 6 })))) ; n := (arr)->size() ; execute (findMinValue(arr, n))->display() ) else skip; operation findMinValue(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var val : int := 0 ; for i : Integer.subrange(0, n-1) do ( val := val + ((arr[i+1])->log())) ; var left : OclAny := arr->first() ; var right : OclAny := arr[n - 1+1] + 1 ; while ((left->compareTo(right)) <= 0) do ( var mid : int := (left + right) div 2 ; var temp : double := n * ((mid)->log()) ; if ((val->compareTo(temp)) < 0) then ( var ans : int := mid ; right := mid - 1 ) else ( left := mid + 1 )) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countZeros(a,n): count2=0 count5=0 for i in range(0,n): while(a[i]% 2==0): a[i]=a[i]//2 count2=count2+1 while(a[i]% 5==0): a[i]=a[i]//5 count5=count5+1 if(count2union(Sequence{100}->union(Sequence{20}->union(Sequence{30}->union(Sequence{50}->union(Sequence{90}->union(Sequence{12}->union(Sequence{ 80 }))))))) ; n := (a)->size() ; execute (countZeros(a, n))->display(); operation countZeros(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count2 : int := 0 ; var count5 : int := 0 ; for i : Integer.subrange(0, n-1) do ( while (a[i+1] mod 2 = 0) do ( a[i+1] := a[i+1] div 2 ; count2 := count2 + 1) ; while (a[i+1] mod 5 = 0) do ( a[i+1] := a[i+1] div 5 ; count5 := count5 + 1)) ; if ((count2->compareTo(count5)) < 0) then ( return count2 ) else ( return count5 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) def out(case): x=0 while(True): if case.count("01")==0 and case.count("10")==0 : break elif case.count("01")>0 : case=case.replace("01","",1) else : case=case.replace("10","",1) x+=1 if x % 2==1 : print("DA") else : print("NET") for i in range(n): case=str(input()) x=0 out(case) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; for i : Integer.subrange(0, n-1) do ( case := ("" + (((OclFile["System.in"]).readLine()))) ; x := 0 ; out(case)); operation out(case : OclAny) pre: true post: true activity: var x : int := 0 ; while (true) do ( if case->count("01") = 0 & case->count("10") = 0 then ( break ) else (if case->count("01") > 0 then ( case := case.replace("01", "", 1) ) else ( case := case.replace("10", "", 1) ) ) ; x := x + 1) ; if x mod 2 = 1 then ( execute ("DA")->display() ) else ( execute ("NET")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printTribRec(n): if(n==0 or n==1 or n==2): return 0 elif(n==3): return 1 else : return(printTribRec(n-1)+printTribRec(n-2)+printTribRec(n-3)) def printTrib(n): for i in range(1,n): print(printTribRec(i),"",end="") n=10 printTrib(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 10 ; printTrib(n); operation printTribRec(n : OclAny) : OclAny pre: true post: true activity: if (n = 0 or n = 1 or n = 2) then ( return 0 ) else (if (n = 3) then ( return 1 ) else ( return (printTribRec(n - 1) + printTribRec(n - 2) + printTribRec(n - 3)) ) ) ; operation printTrib(n : OclAny) pre: true post: true activity: for i : Integer.subrange(1, n-1) do ( execute (printTribRec(i))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findCount(N): list=[] sum=0 for i in range(0,20): sum+=2**i list.append(sum) for value in list : if(value>N): return(list.index(value)+1) N=10 print(findCount(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 10 ; execute (findCount(N))->display(); operation findCount(N : OclAny) : OclAny pre: true post: true activity: var OclType["Sequence"] : Sequence := Sequence{} ; var sum : int := 0 ; for i : Integer.subrange(0, 20-1) do ( sum := sum + (2)->pow(i) ; execute ((sum) : OclType["Sequence"])) ; for value : OclType["Sequence"] do ( if ((value->compareTo(N)) > 0) then ( return (MatrixLib.elementwiseAdd(->indexOf(value) - 1, 1)) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def SplitAndAdd(A,length,rotation): tmp=[0 for i in range(length*2)] for i in range(length): tmp[i]=A[i] tmp[i+length]=A[i] for i in range(rotation,rotation+length,1): A[i-rotation]=tmp[i]; arr=[12,10,5,6,52,36] n=len(arr) position=2 SplitAndAdd(arr,n,position); for i in range(n): print(arr[i],end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var arr : Sequence := Sequence{12}->union(Sequence{10}->union(Sequence{5}->union(Sequence{6}->union(Sequence{52}->union(Sequence{ 36 }))))) ; var n : int := (arr)->size() ; var position : int := 2 ; SplitAndAdd(arr, n, position); ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()) ; execute (->display(); operation SplitAndAdd(A : OclAny, length : OclAny, rotation : OclAny) pre: true post: true activity: var tmp : Sequence := Integer.subrange(0, length * 2-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, length-1) do ( tmp[i+1] := A[i+1] ; tmp[i + length+1] := A[i+1]) ; for i : Integer.subrange(rotation, rotation + length-1)->select( $x | ($x - rotation) mod 1 = 0 ) do ( A[i - rotation+1] := tmp[i+1];); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import defaultdict mod=10**9+7 def factorization(n): arr=[] tmp=n for i in range(2,int(-(-n**0.5//1))+1): if tmp % i==0 : cnt=0 while tmp % i==0 : cnt+=1 tmp//=i arr.append([i,cnt]) if tmp!=1 : arr.append([tmp,1]) if arr==[]: arr.append([n,1]) return arr def main(): N=int(sys.stdin.readline().rstrip()) A=[int(x)for x in sys.stdin.readline().rstrip().split()] p=defaultdict(int) for a in A : for x,y in factorization(a): p[x]=max(p[x],y) U=1 for x,y in p.items(): U=(U*pow(x,y,mod))% mod ans=0 for a in A : ans=(ans+U*pow(a,mod-2,mod))% mod print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; main(); operation factorization(n : OclAny) : OclAny pre: true post: true activity: var arr : Sequence := Sequence{} ; var tmp : OclAny := n ; for i : Integer.subrange(2, ("" + ((-(-(n)->pow(0.5) div 1))))->toInteger() + 1-1) do ( if tmp mod i = 0 then ( var cnt : int := 0 ; while tmp mod i = 0 do ( cnt := cnt + 1 ; tmp := tmp div i) ; execute ((Sequence{i}->union(Sequence{ cnt })) : arr) ) else skip) ; if tmp /= 1 then ( execute ((Sequence{tmp}->union(Sequence{ 1 })) : arr) ) else skip ; if arr = Sequence{} then ( execute ((Sequence{n}->union(Sequence{ 1 })) : arr) ) else skip ; return arr; operation main() pre: true post: true activity: var N : int := ("" + ((sys.stdin.readLine().rstrip())))->toInteger() ; var A : Sequence := sys.stdin.readLine().rstrip().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var p : OclAny := defaultdict(OclType["int"]) ; for a : A do ( for _tuple : factorization(a) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); p[x+1] := Set{p[x+1], y}->max())) ; var U : int := 1 ; for _tuple : p->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); U := (U * (x)->pow(y)) mod mod) ; var ans : int := 0 ; for a : A do ( ans := (ans + U * (a)->pow(mod - 2)) mod mod) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): for i in reversed(range(len(triangle)-1)): for j in range(len(triangle[i])): triangle[i][j]+=max(triangle[i+1][j],triangle[i+1][j+1]) return str(triangle[0][0]) triangle=[[75],[95,64],[17,47,82],[18,35,87,10],[20,4,82,47,65],[19,1,23,75,3,34],[88,2,77,73,7,63,67],[99,65,4,28,6,16,70,92],[41,41,26,56,83,40,80,70,33],[41,48,72,33,47,32,37,16,94,29],[53,71,44,65,25,43,91,52,97,51,14],[70,11,33,28,77,73,17,78,39,68,17,57],[91,71,52,38,17,14,91,43,58,50,27,29,48],[63,66,4,68,89,53,67,30,73,16,69,87,40,31],[4,62,98,27,23,9,70,98,73,93,38,53,60,4,23],] if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var triangle : Sequence := Sequence{Sequence{ 75 }}->union(Sequence{Sequence{95}->union(Sequence{ 64 })}->union(Sequence{Sequence{17}->union(Sequence{47}->union(Sequence{ 82 }))}->union(Sequence{Sequence{18}->union(Sequence{35}->union(Sequence{87}->union(Sequence{ 10 })))}->union(Sequence{Sequence{20}->union(Sequence{4}->union(Sequence{82}->union(Sequence{47}->union(Sequence{ 65 }))))}->union(Sequence{Sequence{19}->union(Sequence{1}->union(Sequence{23}->union(Sequence{75}->union(Sequence{3}->union(Sequence{ 34 })))))}->union(Sequence{Sequence{88}->union(Sequence{2}->union(Sequence{77}->union(Sequence{73}->union(Sequence{7}->union(Sequence{63}->union(Sequence{ 67 }))))))}->union(Sequence{Sequence{99}->union(Sequence{65}->union(Sequence{4}->union(Sequence{28}->union(Sequence{6}->union(Sequence{16}->union(Sequence{70}->union(Sequence{ 92 })))))))}->union(Sequence{Sequence{41}->union(Sequence{41}->union(Sequence{26}->union(Sequence{56}->union(Sequence{83}->union(Sequence{40}->union(Sequence{80}->union(Sequence{70}->union(Sequence{ 33 }))))))))}->union(Sequence{Sequence{41}->union(Sequence{48}->union(Sequence{72}->union(Sequence{33}->union(Sequence{47}->union(Sequence{32}->union(Sequence{37}->union(Sequence{16}->union(Sequence{94}->union(Sequence{ 29 })))))))))}->union(Sequence{Sequence{53}->union(Sequence{71}->union(Sequence{44}->union(Sequence{65}->union(Sequence{25}->union(Sequence{43}->union(Sequence{91}->union(Sequence{52}->union(Sequence{97}->union(Sequence{51}->union(Sequence{ 14 }))))))))))}->union(Sequence{Sequence{70}->union(Sequence{11}->union(Sequence{33}->union(Sequence{28}->union(Sequence{77}->union(Sequence{73}->union(Sequence{17}->union(Sequence{78}->union(Sequence{39}->union(Sequence{68}->union(Sequence{17}->union(Sequence{ 57 })))))))))))}->union(Sequence{Sequence{91}->union(Sequence{71}->union(Sequence{52}->union(Sequence{38}->union(Sequence{17}->union(Sequence{14}->union(Sequence{91}->union(Sequence{43}->union(Sequence{58}->union(Sequence{50}->union(Sequence{27}->union(Sequence{29}->union(Sequence{ 48 }))))))))))))}->union(Sequence{Sequence{63}->union(Sequence{66}->union(Sequence{4}->union(Sequence{68}->union(Sequence{89}->union(Sequence{53}->union(Sequence{67}->union(Sequence{30}->union(Sequence{73}->union(Sequence{16}->union(Sequence{69}->union(Sequence{87}->union(Sequence{40}->union(Sequence{ 31 })))))))))))))}->union(Sequence{ Sequence{4}->union(Sequence{62}->union(Sequence{98}->union(Sequence{27}->union(Sequence{23}->union(Sequence{9}->union(Sequence{70}->union(Sequence{98}->union(Sequence{73}->union(Sequence{93}->union(Sequence{38}->union(Sequence{53}->union(Sequence{60}->union(Sequence{4}->union(Sequence{ 23 })))))))))))))) })))))))))))))) ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: for i : (Integer.subrange(0, (triangle)->size() - 1-1))->reverse() do ( for j : Integer.subrange(0, (triangle[i+1])->size()-1) do ( triangle[i+1][j+1] := triangle[i+1][j+1] + Set{triangle[i + 1+1][j+1], triangle[i + 1+1][j + 1+1]}->max())) ; return ("" + ((triangle->first()->first()))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,k,f=[0]*3,[0]*3,[0]*3 a=list(map(int,input().split())) if sum(a)==0 : break for i in range(3): n[i]+=a[i]+a[3+i] ans=0 for i in range(3): if n[i]>=3 : f[i]=1 ans+=n[i]//3 n[i]%=3 k[n[i]]+=1 if k[0]>0 : if k[2]==2 : i=0 while n[i]: i+=1 if f[i]: ans+=1 elif k[1]>0 : ans+=1 elif k[2]>0 : ans+=2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var k : OclAny := null; var f : OclAny := null; Sequence{n,k,f} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, 3),MatrixLib.elementwiseMult(Sequence{ 0 }, 3),MatrixLib.elementwiseMult(Sequence{ 0 }, 3)} ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (a)->sum() = 0 then ( break ) else skip ; for i : Integer.subrange(0, 3-1) do ( n[i+1] := n[i+1] + a[i+1] + a[3 + i+1]) ; var ans : int := 0 ; for i : Integer.subrange(0, 3-1) do ( if n[i+1] >= 3 then ( f[i+1] := 1 ) else skip ; ans := ans + n[i+1] div 3 ; n[i+1] := n[i+1] mod 3 ; k[n[i+1]+1] := k[n[i+1]+1] + 1) ; if k->first() > 0 then ( if k[2+1] = 2 then ( var i : int := 0 ; while n[i+1] do ( i := i + 1) ; if f[i+1] then ( ans := ans + 1 ) else skip ) else skip ) else (if k[1+1] > 0 then ( ans := ans + 1 ) else (if k[2+1] > 0 then ( ans := ans + 2 ) else skip ) ) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : ns=list(map(int,input().split())) if not any(ns): break a=ns[0]+ns[3] b=ns[1]+ns[4] c=ns[2]+ns[5] av,ar=a//3,a % 3 bv,br=b//3,b % 3 cv,cr=c//3,c % 3 if max(ar,br,cr)==0 : print(av+bv+cv) elif max(ar,br,cr)==1 : print(av+bv+cv+min(ar,br,cr)) elif max(ar,br,cr)==2 : if[ar,br,cr].count(2)==3 : print(av+bv+cv+2) elif[ar,br,cr].count(2)==2 : for xr,xv in((ar,av),(br,bv),(cr,cv)): if xr==2 : continue if xv==0 : print(av+bv+cv+xr) else : print(av+bv+cv+1) break else : print(av+bv+cv+min(ar,br,cr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var ns : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if not((ns)->exists( _x | _x = true )) then ( break ) else skip ; var a : OclAny := ns->first() + ns[3+1] ; var b : OclAny := ns[1+1] + ns[4+1] ; var c : OclAny := ns[2+1] + ns[5+1] ; var av : OclAny := null; var ar : OclAny := null; Sequence{av,ar} := Sequence{a div 3,a mod 3} ; var bv : OclAny := null; var br : OclAny := null; Sequence{bv,br} := Sequence{b div 3,b mod 3} ; var cv : OclAny := null; var cr : OclAny := null; Sequence{cv,cr} := Sequence{c div 3,c mod 3} ; if Set{ar, br, cr}->max() = 0 then ( execute (av + bv + cv)->display() ) else (if Set{ar, br, cr}->max() = 1 then ( execute (av + bv + cv + Set{ar, br, cr}->min())->display() ) else (if Set{ar, br, cr}->max() = 2 then ( if Sequence{ar}->union(Sequence{br}->union(Sequence{ cr }))->count(2) = 3 then ( execute (av + bv + cv + 2)->display() ) else (if Sequence{ar}->union(Sequence{br}->union(Sequence{ cr }))->count(2) = 2 then ( for _tuple : Sequence{Sequence{ar, av}, Sequence{br, bv}, Sequence{cr, cv}} do (var _indx : int := 1; var xr : OclAny := _tuple->at(_indx); _indx := _indx + 1; var xv : OclAny := _tuple->at(_indx); if xr = 2 then ( continue ) else skip ; if xv = 0 then ( execute (av + bv + cv + xr)->display() ) else ( execute (av + bv + cv + 1)->display() ) ; break) ) else ( execute (av + bv + cv + Set{ar, br, cr}->min())->display() ) ) ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import datetime y1,m1,d1,y2,m2,d2=map(int,input().split()) qq,y1=divmod(y1,400) y1+=400 qq-=1 q=(y2-y1)//400 y2-=400*q a=688*(q-qq) d=datetime.date(y1,m1,d1) while d<=datetime.date(y2,m2,d2): if d.day==13 and d.weekday()==4 : a+=1 d+=datetime.timedelta(days=1) print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var y1 : OclAny := null; var m1 : OclAny := null; var d1 : OclAny := null; var y2 : OclAny := null; var m2 : OclAny := null; var d2 : OclAny := null; Sequence{y1,m1,d1,y2,m2,d2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var qq : OclAny := null; var y1 : OclAny := null; Sequence{qq,y1} := Sequence{(y1 div 400), (y1 mod 400)} ; y1 := y1 + 400 ; qq := qq - 1 ; var q : int := (y2 - y1) div 400 ; y2 := y2 - 400 * q ; var a : double := 688 * (q - qq) ; var d : OclAny := ; while (d->compareTo()) <= 0 do ( if d.getDate() = 13 & d.weekday() = 4 then ( a := a + 1 ) else skip ; d := d + ) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check_uruu(y): if y % 400==0 : return True elif y % 100==0 : return False elif y % 4==0 : return True else : return False nouruu=[31,28,31,30,31,30,31,31,30,31,30,31] uruu=[31,29,31,30,31,30,31,31,30,31,30,31] Y1,M1,D1,Y2,M2,D2=map(int,input().split()) L=[0]*(2800*366) idx=0 di,Y1=divmod(Y1,2800) ans1=di*4816 di,Y2=divmod(Y2,2800) ans2=di*4816 for y in range(0,2800): if check_uruu(y): l=uruu else : l=nouruu for m,n_days in enumerate(l,1): d_13=idx+12 if d_13 % 7==6 : L[d_13]=1 if Y1==y and M1==m : ans1+=sum(L[: idx+(D1-1)]) if Y2==y and M2==m : ans2+=sum(L[: idx+(D2)]) idx+=n_days print(ans2-ans1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var nouruu : Sequence := Sequence{31}->union(Sequence{28}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{ 31 }))))))))))) ; var uruu : Sequence := Sequence{31}->union(Sequence{29}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{ 31 }))))))))))) ; var Y1 : OclAny := null; var M1 : OclAny := null; var D1 : OclAny := null; var Y2 : OclAny := null; var M2 : OclAny := null; var D2 : OclAny := null; Sequence{Y1,M1,D1,Y2,M2,D2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var L : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (2800 * 366)) ; var idx : int := 0 ; var di : OclAny := null; var Y1 : OclAny := null; Sequence{di,Y1} := Sequence{(Y1 div 2800), (Y1 mod 2800)} ; var ans1 : double := di * 4816 ; var di : OclAny := null; var Y2 : OclAny := null; Sequence{di,Y2} := Sequence{(Y2 div 2800), (Y2 mod 2800)} ; var ans2 : double := di * 4816 ; for y : Integer.subrange(0, 2800-1) do ( if check_uruu(y) then ( var l : Sequence := uruu ) else ( l := nouruu ) ; for _tuple : Integer.subrange(1, (l, 1)->size())->collect( _indx | Sequence{_indx-1, (l, 1)->at(_indx)} ) do (var _indx : int := 1; var m : OclAny := _tuple->at(_indx); _indx := _indx + 1; var n_days : OclAny := _tuple->at(_indx); var d if check_uruu(y) then ( var l : Sequence := uruu ) else ( l := nouruu )3 : int := idx + 12 ; if d var d if check_uruu(y) then ( var l : Sequence := uruu ) else ( l := nouruu )3 : int := idx + 123 mod 7 = 6 then ( L[d var d if check_uruu(y) then ( var l : Sequence := uruu ) else ( l := nouruu )3 : int := idx + 123+1] := 1 ) else skip ; if Y1 = y & M1 = m then ( ans1 := ans1 + (L.subrange(1,idx + (D1 - 1)))->sum() ) else skip ; if Y2 = y & M2 = m then ( ans2 := ans2 + (L.subrange(1,idx + (D2)))->sum() ) else skip ; idx := idx + n_days)) ; execute (ans2 - ans1)->display(); operation check_uruu(y : OclAny) : OclAny pre: true post: true activity: if y mod 400 = 0 then ( return true ) else (if y mod 100 = 0 then ( return false ) else (if y mod 4 = 0 then ( return true ) else ( return false ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isMultipleOf10(n): return(n % 15==0) n=30 if(isMultipleOf10(n)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 30 ; if (isMultipleOf10(n)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ); operation isMultipleOf10(n : OclAny) : OclAny pre: true post: true activity: return (n mod 15 = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**9) def input(): return sys.stdin.readline()[:-1] EPS=1e-10 k,L,R=map(int,input().split()) p=float(input()) e=float(input()) t=float(input()) def search(l,r,prob,depth): if depth==k : h=(l+r)/2 if abs(h-t)+EPSt+e or r+EPSt-e and t+e>r-EPS : return prob else : h=(l+r)/2 if h>=t : return search(h,r,prob*p,depth+1)+search(l,h,prob*(1-p),depth+1) else : return search(h,r,prob*(1-p),depth+1)+search(l,h,prob*p,depth+1) ans=search(L,R,1,0) print('{:.12f}'.format(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(9)) ; skip ; var EPS : double := ("1e-10")->toReal() ; var k : OclAny := null; var L : OclAny := null; var R : OclAny := null; Sequence{k,L,R} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; var e : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; var t : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; skip ; var ans : OclAny := search(L, R, 1, 0) ; execute (StringLib.interpolateStrings('{:.12f}', Sequence{ans}))->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation search(l : OclAny, r : OclAny, prob : OclAny, depth : OclAny) : OclAny pre: true post: true activity: if depth = k then ( var h : double := (l + r) / 2 ; if ((h - t)->abs() + EPS->compareTo(e)) < 0 then ( return prob ) else ( return 0 ) ) else ( if (l - EPS->compareTo(t + e)) > 0 or (r + EPS->compareTo(t - e)) < 0 then ( return 0 ) else (if (l + EPS->compareTo(t - e)) > 0 & (t + e->compareTo(r - EPS)) > 0 then ( return prob ) else ( h := (l + r) / 2 ; if (h->compareTo(t)) >= 0 then ( return search(h, r, prob * p, depth + 1) + search(l, h, prob * (1 - p), depth + 1) ) else ( return search(h, r, prob * (1 - p), depth + 1) + search(l, h, prob * p, depth + 1) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) i=1 while True : if i>t : break s=input() a=b=0 for j in s : if j=='0' : a=a+1 elif j=='1' : b=b+1 if a<=b : if a % 2!=0 : print("DA") else : print("NET") else : if b % 2!=0 : print("DA") else : print("NET") i=i+1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 1 ; while true do ( if (i->compareTo(t)) > 0 then ( break ) else skip ; var s : String := (OclFile["System.in"]).readLine() ; var a : OclAny := 0; var b : int := 0 ; for j : s->characters() do ( if j = '0' then ( a := a + 1 ) else (if j = '1' then ( b := b + 1 ) else skip)) ; if (a->compareTo(b)) <= 0 then ( if a mod 2 /= 0 then ( execute ("DA")->display() ) else ( execute ("NET")->display() ) ) else ( if b mod 2 /= 0 then ( execute ("DA")->display() ) else ( execute ("NET")->display() ) ) ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if(n % 2==0): print("Mahmoud") else : print("Ehab") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n mod 2 = 0) then ( execute ("Mahmoud")->display() ) else ( execute ("Ehab")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 2==0 : print("Mahmoud") else : print("Ehab") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( execute ("Mahmoud")->display() ) else ( execute ("Ehab")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) ans=[0]*n i=1 for z in range(n): l,r=map(int,input().split()) if l<=i : if r>=i : ans[z]=i i+=1 else : ans[z]=0 else : if r>=i : i=l ans[z]=i i+=1 else : ans[z]=0 print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var i : int := 1 ; for z : Integer.subrange(0, n-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (l->compareTo(i)) <= 0 then ( if (r->compareTo(i)) >= 0 then ( ans[z+1] := i ; i := i + 1 ) else ( ans[z+1] := 0 ) ) else ( if (r->compareTo(i)) >= 0 then ( i := l ; ans[z+1] := i ; i := i + 1 ) else ( ans[z+1] := 0 ) )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 2==1 : print('Ehab') else : print('Mahmoud') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 1 then ( execute ('Ehab')->display() ) else ( execute ('Mahmoud')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 2==0 : print("Mahmoud") else : print("Ehab") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( execute ("Mahmoud")->display() ) else ( execute ("Ehab")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) print('Mahmoud' if x % 2==0 else 'Ehab') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (if x mod 2 = 0 then 'Mahmoud' else 'Ehab' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import array def is_valid_number(sequence): q=lambda n :(n+1)if 1<=n<=6 else(n-5) sum_pq=0 for index in range(1,12): sum_pq+=sequence[index]*q(index) rem_pq=sum_pq % 11 check_digit=0 if rem_pq<=1 else(11-rem_pq) return sequence[0]==check_digit def string2array(st): return array.array("B",map(int,st[: :-1])) def solve(s): candidates=set() for r in range(0,10): sequence=string2array(s.replace("?",str(r))) if is_valid_number(sequence): candidates.add(r) if len(candidates)==1 : return candidates.pop() else : return-1 def main(): answer=solve(input()) print("MULTIPLE" if answer==-1 else answer) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation is_valid_number(sequence : OclAny) : OclAny pre: true post: true activity: var q : Function := lambda n : OclAny in (if 1 <= n & (n <= 6) then (n + 1) else (n - 5) endif) ; var sum_pq : int := 0 ; for index : Integer.subrange(1, 12-1) do ( sum_pq := sum_pq + sequence[index+1] * q->apply(index)) ; var rem_pq : int := sum_pq mod 11 ; var check_digit : int := if rem_pq <= 1 then 0 else (11 - rem_pq) endif ; return sequence->first() = check_digit; operation string2array(st : OclAny) : OclAny pre: true post: true activity: return array.array("B", (st(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->collect( _x | (OclType["int"])->apply(_x) )); operation solve(s : OclAny) : OclAny pre: true post: true activity: var candidates : Set := Set{}->union(()) ; for r : Integer.subrange(0, 10-1) do ( sequence := string2array(s.replace("?", ("" + ((r))))) ; if is_valid_number(sequence) then ( execute ((r) : candidates) ) else skip) ; if (candidates)->size() = 1 then ( return candidates->last() ) else ( return -1 ); operation main() pre: true post: true activity: var answer : OclAny := solve((OclFile["System.in"]).readLine()) ; execute (if answer = -1 then "MULTIPLE" else answer endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- P=list(input()) xi=P.index('?') Q=[6,5,4,3,2,7,6,5,4,3,2] pqsum=0 for i in range(11): if P[i]=='?' : pass else : pqsum+=int(P[i])*Q[i] if xi<11 : Pxi=[] for i in range(10): PQS=pqsum+i*Q[xi] if PQS % 11<=1 : P0=0 if 1characters() ; var xi : int := P->indexOf('?') - 1 ; var Q : Sequence := Sequence{6}->union(Sequence{5}->union(Sequence{4}->union(Sequence{3}->union(Sequence{2}->union(Sequence{7}->union(Sequence{6}->union(Sequence{5}->union(Sequence{4}->union(Sequence{3}->union(Sequence{ 2 })))))))))) ; var pqsum : int := 0 ; for i : Integer.subrange(0, 11-1) do ( if P[i+1] = '?' then ( skip ) else ( pqsum := pqsum + ("" + ((P[i+1])))->toInteger() * Q[i+1] )) ; if xi < 11 then ( var Pxi : Sequence := Sequence{} ; for i : Integer.subrange(0, 10-1) do ( var PQS : int := pqsum + i * Q[xi+1] ; if PQS mod 11 <= 1 then ( var P0 : int := 0 ) else skip ; if 1 < PQS mod 11 then ( P0 := 11 - (PQS mod 11) ) else skip ; if P0 = ("" + ((P[11+1])))->toInteger() then ( execute ((i) : Pxi) ) else skip) ; if (Pxi)->size() = 1 then ( execute (Pxi->first())->display() ) else ( execute ('MULTIPLE')->display() ) ) else skip ; if xi = 11 then ( if pqsum mod 11 <= 1 then ( P0 := 0 ) else skip ; if 1 < pqsum mod 11 then ( P0 := 11 - (pqsum mod 11) ) else skip ; execute (P0)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CheckDisit(a): tmp=0 for i in range(11): if i<=4 : tmp+=int(a[i])*(6-i) else : tmp+=int(a[i])*(12-i) tmp=tmp % 11 if tmp<=1 : return 0 else : return(11-tmp) m=list(input()) if m[11]=='?' : print(CheckDisit(m)) else : ans=[] x=m.index('?') for i in range(10): m[x]=str(i) if int(m[11])==CheckDisit(m): ans.append(i) if len(ans)==1 : print(ans[0]) else : print("MULTIPLE") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var m : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if m[11+1] = '?' then ( execute (CheckDisit(m))->display() ) else ( var ans : Sequence := Sequence{} ; var x : int := m->indexOf('?') - 1 ; for i : Integer.subrange(0, 10-1) do ( m[x+1] := ("" + ((i))) ; if ("" + ((m[11+1])))->toInteger() = CheckDisit(m) then ( execute ((i) : ans) ) else skip) ; if (ans)->size() = 1 then ( execute (ans->first())->display() ) else ( execute ("MULTIPLE")->display() ) ); operation CheckDisit(a : OclAny) : OclAny pre: true post: true activity: var tmp : int := 0 ; for i : Integer.subrange(0, 11-1) do ( if i <= 4 then ( tmp := tmp + ("" + ((a[i+1])))->toInteger() * (6 - i) ) else ( tmp := tmp + ("" + ((a[i+1])))->toInteger() * (12 - i) )) ; tmp := tmp mod 11 ; if tmp <= 1 then ( return 0 ) else ( return (11 - tmp) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def is_collect(fixed_number): score=0 for i in range(1,7): score+=int(fixed_number[i])*(i+1) for i in range(7,12): score+=int(fixed_number[i])*(i-5) last=11-score % 11 if str(last)==fixed_number[0]or(last>=10 and fixed_number[0]=="0"): return True else : return False def check(s): index=s.index("?") cnt=0 for i in range(10): c=str(i) fixed_number=s[: index]+c+s[index+1 :] if is_collect(fixed_number): cnt+=1 ret=i if cnt==1 : return ret else : return None ans=check(input()[: :-1]) print(ans if ans!=None else "MULTIPLE") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var ans : OclAny := check(input()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ; execute (if ans /= null then ans else "MULTIPLE" endif)->display(); operation is_collect(fixed_number : OclAny) : OclAny pre: true post: true activity: var score : int := 0 ; for i : Integer.subrange(1, 7-1) do ( score := score + ("" + ((fixed_number[i+1])))->toInteger() * (i + 1)) ; for i : Integer.subrange(7, 12-1) do ( score := score + ("" + ((fixed_number[i+1])))->toInteger() * (i - 5)) ; var last : double := 11 - score mod 11 ; if ("" + ((last))) = fixed_number->first() or (last >= 10 & fixed_number->first() = "0") then ( return true ) else ( return false ); operation check(s : OclAny) : OclAny pre: true post: true activity: var index : int := s->indexOf("?") - 1 ; var cnt : int := 0 ; for i : Integer.subrange(0, 10-1) do ( var c : String := ("" + ((i))) ; fixed_number := s.subrange(1,index) + c + s.subrange(index + 1+1) ; if is_collect(fixed_number) then ( cnt := cnt + 1 ; var ret : OclAny := i ) else skip) ; if cnt = 1 then ( return ret ) else ( return null ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution : def duplicateZeros(self,arr : List[int])->None : move_pos=0 last_pos=len(arr)-1 for i in range(last_pos+1): if i>last_pos-move_pos : break if arr[i]==0 : if i==last_pos-move_pos : arr[last_pos]=0 last_pos-=1 break move_pos+=1 last_pos-=move_pos for i in range(last,-1,-1): if arr[i]==0 : arr[i+move_pos]=0 move_pos-=1 arr[i+move_pos]=0 else : arr[i+move_pos]=arr[i] ------------------------------------------------------------ OCL File: --------- class Solution { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation duplicateZeros(arr : List[OclType["int"]+1]) : OclAny pre: true post: true activity: var move_pos : int := 0 ; var last_pos : double := (arr)->size() - 1 ; for i : Integer.subrange(0, last_pos + 1-1) do ( if (i->compareTo(last_pos - move_pos)) > 0 then ( break ) else skip ; if arr[i+1] = 0 then ( if i = last_pos - move_pos then ( arr[last_pos+1] := 0 ; last_pos := last_pos - 1 ; break ) else skip ; move_pos := move_pos + 1 ) else skip) ; last_pos := last_pos - move_pos ; for i : Integer.subrange(-1 + 1, last)->reverse() do ( if arr[i+1] = 0 then ( arr[i + move_pos+1] := 0 ; move_pos := move_pos - 1 ; arr[i + move_pos+1] := 0 ) else ( arr[i + move_pos+1] := arr[i+1] )); } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): s=input() if min(s.count('0'),s.count('1'))% 2==0 : print("NET") else : print("DA") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if Set{s->count('0'), s->count('1')}->min() mod 2 = 0 then ( execute ("NET")->display() ) else ( execute ("DA")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPalindrome(str,i,j): while(isize(); ; ch := 'p'; ; execute (maxLenPalindrome(OclType["String"], n, ch))->display();; operation isPalindrome(OclType["String"] : OclAny, i : OclAny, j : OclAny) pre: true post: true activity: while ((i->compareTo(j)) < 0) do ( if (("" + ([i+1])) /= ("" + ([j+1]))) then ( return false; ) else skip ; i := i + 1; ; j := j - 1;) ; return true;; operation maxLenPalindrome(OclType["String"] : OclAny, n : OclAny, ch : OclAny) pre: true post: true activity: var maxLen : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (("" + ([i+1])) = ch) then ( for j : Integer.subrange(i + 1 + 1, n - 1)->reverse() do ( if (("" + ([j+1])) = ch) then ( if (isPalindrome(OclType["String"], i, j)) then ( maxLen := Set{maxLen, j - i + 1}->max(); ; break; ) else skip ) else skip) ) else skip) ; return maxLen;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): d=[] c=0 for i in range(int(input())): l,r=map(int,input().split()) if c>r : d.append(0) else : c=l+1 if c<=l else c+1 d.append(c-1) print(' '.join(map(str,d))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var d : Sequence := Sequence{} ; var c : int := 0 ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (c->compareTo(r)) > 0 then ( execute ((0) : d) ) else ( c := if (c->compareTo(l)) <= 0 then l + 1 else c + 1 endif ; execute ((c - 1) : d) )) ; execute (StringLib.sumStringsWithSeparator(((d)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getFirstDigit(x): while(x>=10): x/=10 return x def getCountWithSameStartAndEndFrom1(x): if(x<10): return x tens=x/10 res=tens+9 firstDigit=getFirstDigit(x) lastDigit=x % 10 if(lastDigitdisplay(); operation getFirstDigit(x : OclAny) : OclAny pre: true post: true activity: while (x >= 10) do ( x := x / 10) ; return x; operation getCountWithSameStartAndEndFrom1(x : OclAny) : OclAny pre: true post: true activity: if (x < 10) then ( return x ) else skip ; var tens : double := x / 10 ; var res : OclAny := tens + 9 ; var firstDigit : OclAny := getFirstDigit(x) ; var lastDigit : int := x mod 10 ; if ((lastDigit->compareTo(firstDigit)) < 0) then ( res := res - 1 ) else skip ; return res; operation getCountWithSameStartAndEnd(start : OclAny, end : OclAny) : OclAny pre: true post: true activity: return (getCountWithSameStartAndEndFrom1(end) - getCountWithSameStartAndEndFrom1(start - 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) mass=list(map(int,input().split())) r=min(mass)//n otv=0 for i in range(n): if mass[i]-n*r-i<=0 : otv=i+1 break if otv==0 : r+=1 for i in range(n): if mass[i]-n*r-i<=0 : otv=i+1 break print(otv) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mass : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var r : int := (mass)->min() div n ; var otv : int := 0 ; for i : Integer.subrange(0, n-1) do ( if mass[i+1] - n * r - i <= 0 then ( otv := i + 1 ; break ) else skip) ; if otv = 0 then ( r := r + 1 ; for i : Integer.subrange(0, n-1) do ( if mass[i+1] - n * r - i <= 0 then ( otv := i + 1 ; break ) else skip) ) else skip ; execute (otv)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(x)for x in input().split()] t=min(a) while a[t % n]>t : t+=1 print(t % n+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var t : OclAny := (a)->min() ; while (a[t mod n+1]->compareTo(t)) > 0 do ( t := t + 1) ; execute (t mod n + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math x,a,m,res=int(input()),[*(map(int,input().split()))],10e9,-1 k=[math.ceil((ai-i)/x)for i,ai in enumerate(a)] print(k.index(min(k))+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : OclAny := null; var a : OclAny := null; var m : OclAny := null; var res : OclAny := null; Sequence{x,a,m,res} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),((input().split())->collect( _x | (OclType["int"])->apply(_x) )),("10e9")->toReal(),-1} ; var k : Sequence := Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let ai : OclAny = _tuple->at(2) in (((ai - i) / x)->ceil())) ; execute (k->indexOf((k)->min()) - 1 + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,a,m,res=int(input()),[*(map(int,input().split()))],10e9,-1 k=[math.ceil((ai-i)/n)for i,ai in enumerate(a)] print(k.index(min(k))+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var a : OclAny := null; var m : OclAny := null; var res : OclAny := null; Sequence{n,a,m,res} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),((input().split())->collect( _x | (OclType["int"])->apply(_x) )),("10e9")->toReal(),-1} ; var k : Sequence := Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let ai : OclAny = _tuple->at(2) in (((ai - i) / n)->ceil())) ; execute (k->indexOf((k)->min()) - 1 + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) a=list(map(int,input().split())) ans=0 inf=2*pow(10,9)+1 x=inf for i in range(n): u=((a[i]-i)//n+min((a[i]-i)% n,1))*n+i if x>u : x=u ans=i+1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; var Math_PINFINITY : double := 2 * (10)->pow(9) + 1 ; var x : double := Math_PINFINITY ; for i : Integer.subrange(0, n-1) do ( var u : int := ((a[i+1] - i) div n + Set{(a[i+1] - i) mod n, 1}->min()) * n + i ; if (x->compareTo(u)) > 0 then ( x := u ; ans := i + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools n,m=map(int,input().split()) linelist=[list(map(int,input().split()))for i in range(m)] numlist=[i for i in range(1,n+1)] plist=list(itertools.permutations(numlist)) sum=0 for challenger in plist : if challenger[0]!=1 : pass else : needlist=[] for i in range(n-1): tmp=[] tmp.extend([challenger[i],challenger[i+1]]) tmp.sort() needlist.append(tmp) addflag=True for need in needlist : if not need in linelist : addflag=False if addflag : sum+=1 print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var linelist : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var numlist : Sequence := Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | (i)) ; var plist : Sequence := (itertools.permutations(numlist)) ; var sum : int := 0 ; for challenger : plist do ( if challenger->first() /= 1 then ( skip ) else ( var needlist : Sequence := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( var tmp : Sequence := Sequence{} ; tmp := tmp->union(Sequence{challenger[i+1]}->union(Sequence{ challenger[i + 1+1] })) ; tmp := tmp->sort() ; execute ((tmp) : needlist)) ; var addflag : boolean := true ; for need : needlist do ( if not((linelist)->includes(need)) then ( addflag := false ) else skip) ; if addflag then ( sum := sum + 1 ) else skip )) ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(4100000) def Dfs(G,v,n,visited): all_visited=True for i in range(n): if visited[i]==False : all_visited=False if all_visited : return 1 ret=0 for i in range(n): if not G[v][i]: continue if visited[i]: continue visited[i]=True ret+=Dfs(G,i,n,visited) visited[i]=False return ret def main(): input=sys.stdin.readline n,m=map(int,input().split()) e=[list(map(int,input().split()))for i in range(m)] g=[[False for j in range(n)]for i in range(n)] for i,j in e : g[i-1][j-1]=True g[j-1][i-1]=True visited=[False for i in range(n)] visited[0]=True print(Dfs(g,0,n,visited)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(4100000) ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation Dfs(G : OclAny, v : OclAny, n : OclAny, visited : OclAny) : OclAny pre: true post: true activity: var all_visited : boolean := true ; for i : Integer.subrange(0, n-1) do ( if visited[i+1] = false then ( all_visited := false ) else skip) ; if all_visited then ( return 1 ) else skip ; var ret : int := 0 ; for i : Integer.subrange(0, n-1) do ( if not(G[v+1][i+1]) then ( continue ) else skip ; if visited[i+1] then ( continue ) else skip ; visited[i+1] := true ; ret := ret + Dfs(G, i, n, visited) ; visited[i+1] := false) ; return ret; operation main() pre: true post: true activity: var input : OclAny := (OclFile["System.in"]).readline ; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var e : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var g : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, n-1)->select(j | true)->collect(j | (false)))) ; for _tuple : e do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); g[i - 1+1][j - 1+1] := true ; g[j - 1+1][i - 1+1] := true) ; visited := Integer.subrange(0, n-1)->select(i | true)->collect(i | (false)) ; visited->first() := true ; execute (Dfs(g, 0, n, visited))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) original_paths={} for n in range(1,N+1): original_paths[n]=[] for m in range(1,M+1): s,e=map(int,input().split()) original_paths[s].append(e) original_paths[e].append(s) visited=[1] current_point=1 answer=0 import copy paths=copy.deepcopy(original_paths) while len(paths[1])!=0 : if len(paths[current_point])!=0 : next_point=paths[current_point][0] if next_point in visited : if len(paths[current_point])!=1 : paths[current_point].remove(next_point) else : if len(visited)==N : answer+=1 prior_point=visited[-2] paths[current_point]=original_paths[current_point].copy() paths[prior_point].remove(current_point) visited.remove(current_point) current_point=prior_point else : visited.append(next_point) current_point=next_point else : prior_point=visited[-2] paths[current_point]=original_paths[current_point].copy() paths[prior_point].remove(current_point) visited.remove(current_point) current_point=prior_point print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var original_paths : OclAny := Set{} ; for n : Integer.subrange(1, N + 1-1) do ( original_paths[n+1] := Sequence{}) ; for m : Integer.subrange(1, M + 1-1) do ( var s : OclAny := null; var e : OclAny := null; Sequence{s,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name original_paths)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name e)))))))) )))) ; (expr (atom (name original_paths)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name e)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))) ; var visited : Sequence := Sequence{ 1 } ; var current_point : int := 1 ; var answer : int := 0 ; skip ; var paths : OclAny := copy.deepcopy(original_paths) ; while (paths[1+1])->size() /= 0 do ( if (paths[current_point+1])->size() /= 0 then ( var next_point : OclAny := paths[current_point+1]->first() ; if (visited)->includes(next_point) then ( if (paths[current_point+1])->size() /= 1 then ( (expr (atom (name paths)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name current_point)))))))) ])) (trailer . (name remove) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name next_point)))))))) )))) ) else ( if (visited)->size() = N then ( answer := answer + 1 ) else skip ; var prior_point : OclAny := visited->front()->last() ; paths[current_point+1] := original_paths[current_point+1]->copy() ; (expr (atom (name paths)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name prior_point)))))))) ])) (trailer . (name remove) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name current_point)))))))) )))) ; execute ((current_point) /: visited) ; current_point := prior_point ) ) else ( execute ((next_point) : visited) ; current_point := next_point ) ) else ( prior_point := visited->front()->last() ; paths[current_point+1] := original_paths[current_point+1]->copy() ; (expr (atom (name paths)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name prior_point)))))))) ])) (trailer . (name remove) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name current_point)))))))) )))) ; execute ((current_point) /: visited) ; current_point := prior_point )) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) for i in range(a): text=input() turn=0 while True : if '01' in text : turn+=1 text=text.replace('01','',1) continue elif '10' in text : turn+=1 text=text.replace('10','',1) continue break result='DA' if turn % 2==1 else 'net' print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, a-1) do ( var text : String := (OclFile["System.in"]).readLine() ; var turn : int := 0 ; while true do ( if (text)->characters()->includes('01') then ( turn := turn + 1 ; text := text.replace('01', '', 1) ; continue ) else (if (text)->characters()->includes('10') then ( turn := turn + 1 ; text := text.replace('10', '', 1) ; continue ) else skip) ; break) ; var result : String := if turn mod 2 = 1 then 'DA' else 'net' endif ; execute (result)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countWays(n,m): count=[] for i in range(n+2): count.append(0) count[0]=0 for i in range(1,n+1): if(i>m): count[i]=count[i-1]+count[i-m] elif(iapply(_x) ) ; var route : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Sequence{})) ; var already : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; already.subrange(0+1, 2) := Sequence{1}->union(Sequence{ 1 }) ; var cnt : int := 0 ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name route)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name route)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; skip ; trace(1, already) ; execute (cnt)->display(); operation trace(index : OclAny, already : OclAny) pre: true post: true activity: skip ; if not(((already)->includes(0))) then ( cnt := cnt + 1 ) else ( for new_point : route[index+1] do ( if already[new_point+1] /= 1 then ( var new_already : OclAny := copy->copy() ; new_already[new_point+1] := 1 ; trace(new_point, new_already) ) else skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import permutations N,M,*ab=map(int,open(0).read().split()) g=[[]for _ in range(N)] for a,b in zip(*[iter(ab)]*2): a-=1 b-=1 g[a].append(b) g[b].append(a) ans=0 for path in permutations(range(1,N)): v=0 for nv in path : if nv not in g[v]: break v=nv else : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; var ab : OclAny := null; Sequence{N,M,ab} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var g : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _tuple : Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ab)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ab)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ab)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))`third->at(_indx)} ) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); a := a - 1 ; b := b - 1 ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var ans : int := 0 ; for path : permutations(Integer.subrange(1, N-1)) do ( var v : int := 0 ; (compound_stmt for (exprlist (expr (atom (name nv)))) in (testlist (test (logical_test (comparison (expr (atom (name path))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name nv)))) not in (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name v)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name nv))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=list(input()) T=list(input()) c=0 for s in range(len(S)): if S[s]!=T[s]: c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var T : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var c : int := 0 ; for s : Integer.subrange(0, (S)->size()-1) do ( if S[s+1] /= T[s+1] then ( c := c + 1 ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=[input()for i in range(2)] count=0 out=0 if a==b : print("0") else : c=list(a) d=list(b) for i in c : if i==d[count]: pass else : out=out+1 count=count+1 print(str(out)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Integer.subrange(0, 2-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var count : int := 0 ; var out : int := 0 ; if a = b then ( execute ("0")->display() ) else ( var c : Sequence := (a) ; var d : Sequence := (b) ; for i : c do ( if i = d[count+1] then ( skip ) else ( out := out + 1 ) ; count := count + 1) ; execute (("" + ((out))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() t=input() ans=0 for a,b in zip(s,t): ans+=(a!=b) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; for _tuple : Integer.subrange(1, s->size())->collect( _indx | Sequence{s->at(_indx), t->at(_indx)} ) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); ans := ans + (a /= b)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inp=[input()for str in range(2)] out=0 for i in range(len(inp[0])): if inp[0][i]!=inp[1][i]: out+=1 print(out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inp : Sequence := Integer.subrange(0, 2-1)->select(OclType["String"] | true)->collect(OclType["String"] | ((OclFile["System.in"]).readLine())) ; var out : int := 0 ; for i : Integer.subrange(0, (inp->first())->size()-1) do ( if inp->first()[i+1] /= inp[1+1][i+1] then ( out := out + 1 ) else skip) ; execute (out)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=str(input()) t=str(input()) n=len(s) num=0 ans=0 while numsize() ; var num : int := 0 ; var ans : int := 0 ; while (num->compareTo(n)) < 0 do ( if s[num+1] /= t[num+1] then ( ans := ans + 1 ) else skip ; num := num + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def fact(n): if(n<=1): return 1 return n*fact(n-1) def nPr(n,r): return math.floor(fact(n)/fact(n-r)) n=5 r=2 print(n,"P",r,"=",nPr(n,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 5 ; r := 2 ; execute (n)->display(); operation fact(n : OclAny) : OclAny pre: true post: true activity: if (n <= 1) then ( return 1 ) else skip ; return n * fact(n - 1); operation nPr(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: return (fact(n) / fact(n - r))->floor(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) A=list(map(int,input().split())) def constRange(A): l,r=0,1 d={} d[A[l]]=l d[A[r]]=r mx=max(A[l],A[r]) mi=min(A[l],A[r]) ans=0 while r=len(A): break d[A[r]]=r if A[r]>=mx : mx=A[r] if A[r]<=mi : mi=A[r] ans=max(ans,r-l) if r>=len(A): break if A[r]>mi : l=d[mi]+1 mi+=1 else : l=d[mx]+1 mx-=1 return ans print(constRange(A)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; execute (constRange(A))->display(); operation constRange(A : OclAny) : OclAny pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,1} ; var d : OclAny := Set{} ; d[A[l+1]+1] := l ; d[A[r+1]+1] := r ; var mx : OclAny := Set{A[l+1], A[r+1]}->max() ; var mi : OclAny := Set{A[l+1], A[r+1]}->min() ; var ans : int := 0 ; while (r->compareTo((A)->size())) < 0 do ( while mx - mi <= 1 do ( r := r + 1 ; if (r->compareTo((A)->size())) >= 0 then ( break ) else skip ; d[A[r+1]+1] := r ; if (A[r+1]->compareTo(mx)) >= 0 then ( mx := A[r+1] ) else skip ; if (A[r+1]->compareTo(mi)) <= 0 then ( mi := A[r+1] ) else skip) ; ans := Set{ans, r - l}->max() ; if (r->compareTo((A)->size())) >= 0 then ( break ) else skip ; if (A[r+1]->compareTo(mi)) > 0 then ( var l : OclAny := d[mi+1] + 1 ; mi := mi + 1 ) else ( l := d[mx+1] + 1 ; mx := mx - 1 )) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) fre=[0]*(10**5+5) diff=0 j=0 longest_range=0 for i in range(n): if fre[a[i]]==0 : diff+=1 fre[a[i]]+=1 while j2 : if fre[a[j]]==1 : diff-=1 fre[a[j]]-=1 j+=1 longest_range=max(longest_range,i-j+1) print(longest_range) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var fre : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((10)->pow(5) + 5)) ; var diff : int := 0 ; var j : int := 0 ; var longest_range : int := 0 ; for i : Integer.subrange(0, n-1) do ( if fre[a[i+1]+1] = 0 then ( diff := diff + 1 ) else skip ; fre[a[i+1]+1] := fre[a[i+1]+1] + 1 ; while (j->compareTo(n)) < 0 & diff > 2 do ( if fre[a[j+1]+1] = 1 then ( diff := diff - 1 ) else skip ; fre[a[j+1]+1] := fre[a[j+1]+1] - 1 ; j := j + 1) ; longest_range := Set{longest_range, i - j + 1}->max()) ; execute (longest_range)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s,t=input(),input() letrasT=dict() letrasS=dict() for i in range(ord('a'),ord('z')+1): letrasT[chr(i)]=0 letrasS[chr(i)]=0 for i in range(ord('A'),ord('Z')+1): letrasT[chr(i)]=0 letrasS[chr(i)]=0 for e in t : letrasT[e]+=1 for e in s : letrasS[e]+=1 yay=0 for e in letrasS : quant=min(letrasS[e],letrasT[e]); yay+=quant ; letrasS[e]-=quant letrasT[e]-=quant whoops=0 for e in letrasS : if(e.islower()): quant=min(letrasS[e],letrasT[e.upper()]) whoops+=quant letrasS[e]-=quant letrasT[e.upper()]-=quant else : quant=min(letrasS[e],letrasT[e.lower()]) whoops+=quant letrasS[e]-=quant letrasT[e.lower()]-=quant print(yay,whoops) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine()} ; var letrasT : Map := (arguments ( )) ; var letrasS : Map := (arguments ( )) ; for i : Integer.subrange(('a')->char2byte(), ('z')->char2byte() + 1-1) do ( letrasT[(i)->byte2char()+1] := 0 ; letrasS[(i)->byte2char()+1] := 0) ; for i : Integer.subrange(('A')->char2byte(), ('Z')->char2byte() + 1-1) do ( letrasT[(i)->byte2char()+1] := 0 ; letrasS[(i)->byte2char()+1] := 0) ; for e : t do ( letrasT[e+1] := letrasT[e+1] + 1) ; for e : s do ( letrasS[e+1] := letrasS[e+1] + 1) ; var yay : int := 0 ; for e : letrasS->keys() do ( var quant : OclAny := Set{letrasS[e+1], letrasT[e+1]}->min(); ; yay := yay + quant; ; letrasS[e+1] := letrasS[e+1] - quant ; letrasT[e+1] := letrasT[e+1] - quant) ; var whoops : int := 0 ; for e : letrasS->keys() do ( if (e->matches("[a-z ]*")) then ( quant := Set{letrasS[e+1], letrasT[e->toUpperCase()+1]}->min() ; whoops := whoops + quant ; letrasS[e+1] := letrasS[e+1] - quant ; letrasT[e->toUpperCase()+1] := letrasT[e->toUpperCase()+1] - quant ) else ( quant := Set{letrasS[e+1], letrasT[e->toLowerCase()+1]}->min() ; whoops := whoops + quant ; letrasS[e+1] := letrasS[e+1] - quant ; letrasT[e->toLowerCase()+1] := letrasT[e->toLowerCase()+1] - quant )) ; execute (yay)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bomb_required(n): print(n+n//2) for i in range(2,n+1,2): print(i,end=" ") for i in range(1,n+1,2): print(i,end=" ") for i in range(2,n,2): print(i,end=" ") bomb_required(3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; bomb_required(3); operation bomb_required(n : OclAny) pre: true post: true activity: execute (n + n div 2)->display() ; for i : Integer.subrange(2, n + 1-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( execute (i)->display()) ; for i : Integer.subrange(1, n + 1-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( execute (i)->display()) ; for i : Integer.subrange(2, n-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): s=input() c1=s.count("0") c2=s.count("1") if min(c1,c2)% 2!=0 : print("DA") else : print("NET") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var c1 : int := s->count("0") ; var c2 : int := s->count("1") ; if Set{c1, c2}->min() mod 2 /= 0 then ( execute ("DA")->display() ) else ( execute ("NET")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin def get_data(n,values): rango=0 if min(values)==max(values): return n for cont in range(1,n): if n-cont=2 : if values[cont-2]!=values[cont]or values[cont]!=values[cont-1]: fl=True if cont==1 or fl : if values[cont]>values[cont-1]: max_=values[cont] min_=values[cont-1] elif values[cont]values[cont]: max_=values[pos] break if values[pos]max_ or values[pos]min() = (values)->max() then ( return n ) else skip ; for cont : Integer.subrange(1, n-1) do ( if (n - cont->compareTo(rango)) < 0 then ( break ) else skip ; var fl : boolean := false ; if cont >= 2 then ( if values[cont - 2+1] /= values[cont+1] or values[cont+1] /= values[cont - 1+1] then ( fl := true ) else skip ) else skip ; if cont = 1 or fl then ( if (values[cont+1]->compareTo(values[cont - 1+1])) > 0 then ( var max_ : OclAny := values[cont+1] ; var min_ : OclAny := values[cont - 1+1] ) else (if (values[cont+1]->compareTo(values[cont - 1+1])) < 0 then ( max_ := values[cont - 1+1] ; min_ := values[cont+1] ) else ( max_ := values[cont+1] ; min_ := values[cont+1] ; for pos : Integer.subrange(cont + 1, n-1) do ( if (values[pos+1]->compareTo(values[cont+1])) > 0 then ( max_ := values[pos+1] ; break ) else skip ; if (values[pos+1]->compareTo(values[cont+1])) < 0 then ( min_ := values[pos+1] ; break ) else skip) ) ) ; var length : int := 1 ; for pos : Integer.subrange(cont, n-1) do ( if (values[pos+1]->compareTo(max_)) > 0 or (values[pos+1]->compareTo(min_)) < 0 then ( break ) else ( length := length + 1 )) ; rango := Set{rango, length}->max() ) else skip) ; return rango; operation main() pre: true post: true activity: n := ("" + ((stdin.readLine())))->toInteger() ; values := stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (get_data(n, values))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=-1 p=[0]*100003 ar=input().split() for i in range(1,n+1): x=int(ar[i-1]) if p[x-1]>p[x+1]: ans=max(ans,i-max(p[x+1],p[x-2])) else : ans=max(ans,i-max(p[x-1],p[x+2])) p[x]=i print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := -1 ; var p : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100003) ; var ar : OclAny := input().split() ; for i : Integer.subrange(1, n + 1-1) do ( var x : int := ("" + ((ar[i - 1+1])))->toInteger() ; if (p[x - 1+1]->compareTo(p[x + 1+1])) > 0 then ( ans := Set{ans, i - Set{p[x + 1+1], p[x - 2+1]}->max()}->max() ) else ( ans := Set{ans, i - Set{p[x - 1+1], p[x + 2+1]}->max()}->max() ) ; p[x+1] := i) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- arr=[1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,4,1,2,3,1,2,3,4]; def countKeyPressed(string,length): count=0 ; for i in range(length): count+=arr[ord(string[i])-ord('a')]; return count ; if __name__=="__main__" : string="abcdef" ; length=len(string); print(countKeyPressed(string,length)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var arr : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))))))))))))))))))))))))); ; skip ; if __name__ = "__main__" then ( string := "abcdef"; ; length := (string)->size(); ; execute (countKeyPressed(string, length))->display(); ) else skip; operation countKeyPressed(string : OclAny, length : OclAny) pre: true post: true activity: var count : int := 0; ; for i : Integer.subrange(0, length-1) do ( count := count + arr[(string[i+1])->char2byte() - ('a')->char2byte()+1];) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline if __name__=='__main__' : N,M,H=map(int,readline().split()) A=list(map(int,readline().split())) B=list(map(int,readline().split())) C=[list(map(int,readline().split()))for _ in range(N)] ans=[[0]*M for _ in range(N)] for i in range(N): for j in range(M): if C[i][j]: ans[i][j]=min(A[j],B[i]) for tmp in ans : print(*tmp) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; if __name__ = '__main__' then ( var N : OclAny := null; var M : OclAny := null; var H : OclAny := null; Sequence{N,M,H} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var B : Sequence := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var C : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((readline().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ans : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, M))) ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, M-1) do ( if C[i+1][j+1] then ( ans[i+1][j+1] := Set{A[j+1], B[i+1]}->min() ) else skip)) ; for tmp : ans do ( execute ((argument * (test (logical_test (comparison (expr (atom (name tmp))))))))->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mat=[] n,m,h=map(int,input().split()) front_view=list(map(int,input().split())) top_view=list(map(int,input().split())) for i in range(n): temp=list(map(int,input().split())) mat.append(temp) res=[[0]*m for i in range(n)] for row in range(n): for col in range(m): if mat[row][col]==1 : res[row][col]=min(front_view[col],top_view[row]) for i in range(n): print(*res[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mat : Sequence := Sequence{} ; var n : OclAny := null; var m : OclAny := null; var h : OclAny := null; Sequence{n,m,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var front_view : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var top_view : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( var temp : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((temp) : mat)) ; var res : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, m))) ; for row : Integer.subrange(0, n-1) do ( for col : Integer.subrange(0, m-1) do ( if mat[row+1][col+1] = 1 then ( res[row+1][col+1] := Set{front_view[col+1], top_view[row+1]}->min() ) else skip)) ; for i : Integer.subrange(0, n-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name res)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,h=map(int,input().split()) f=list(map(int,input().split())) l=list(map(int,input().split())) ans=[[0]*m for i in range(n)] for i in range(n): t=list(map(int,input().split())) for j in range(m): print(min(l[i],f[j])*t[j],end=' ') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var h : OclAny := null; Sequence{n,m,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var f : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, m))) ; for i : Integer.subrange(0, n-1) do ( var t : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, m-1) do ( execute (Set{l[i+1], f[j+1]}->min() * t[j+1])->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,h=map(int,input().split()) m1=list(map(int,input().split())) n1=list(map(int,input().split())) l=[] for i in range(n): l1=list(map(int,input().split())) l.append(l1) for i in range(n): for j in range(m): if(l[i][j]==1): l[i][j]=min(n1[i],m1[j]) print(l[i][j],end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var h : OclAny := null; Sequence{n,m,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((l1) : l)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if (l[i+1][j+1] = 1) then ( l[i+1][j+1] := Set{n1[i+1], m1[j+1]}->min() ) else skip ; execute (l[i+1][j+1])->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,h=map(int,input().split()) a=list(map(int,input().split())) s=list(map(int,input().split())) d=[list(map(int,input().split()))for q in range(n)] ans=[[0]*m for q in range(n)] for q in range(n): for q1 in range(m): if d[q][q1]: ans[q][q1]=min(s[q],a[q1]) for q in ans : print(*q) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var h : OclAny := null; Sequence{n,m,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : Sequence := Integer.subrange(0, n-1)->select(q | true)->collect(q | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ans : Sequence := Integer.subrange(0, n-1)->select(q | true)->collect(q | (MatrixLib.elementwiseMult(Sequence{ 0 }, m))) ; for q : Integer.subrange(0, n-1) do ( for q1 : Integer.subrange(0, m-1) do ( if d[q+1][q1+1] then ( ans[q+1][q1+1] := Set{s[q+1], a[q1+1]}->min() ) else skip)) ; for q : ans do ( execute ((argument * (test (logical_test (comparison (expr (atom (name q))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def squareRoot(n): x=n ; y=1 ; while(x>y): x=(x+y)/2 ; y=n/x ; return x ; n=49 ; print("root of",n,"is",squareRoot(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 49; ; execute ("root of")->display();; operation squareRoot(n : OclAny) pre: true post: true activity: var x : OclAny := n; ; var y : int := 1; ; while ((x->compareTo(y)) > 0) do ( x := (x + y) / 2; ; y := n / x;) ; return x;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print((n+1)&-(n+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (MathLib.bitwiseAnd((n + 1), -(n + 1)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): r=a % b if r : return gcd(b,r) return b def lcm(a,b): if atoInteger() ; if not(n) then ( break ) else skip ; var bars : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var root_bar : Set := Set{}->union((Integer.subrange(1, n + 1-1))) ; for _tuple : bars do (var _indx : int := 1; var _anon : OclAny := _tuple->at(_indx); _indx := _indx + 1; var _anon : OclAny := _tuple->at(_indx); _indx := _indx + 1; var r : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if r then ( execute ((r) /: root_bar) ) else skip ; if b then ( execute ((b) /: root_bar) ) else skip) ; execute (min_weight(root_bar->last()))->display()); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var r : int := a mod b ; if r then ( return gcd(b, r) ) else skip ; return b; operation lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a->compareTo(b)) < 0 then ( Sequence{a,b} := Sequence{b,a} ) else skip ; return a * b div gcd(a, b); operation min_weight(m : OclAny) : OclAny pre: true post: true activity: var p : OclAny := null; var q : OclAny := null; Sequence{p,q,r,b} := bars[m - 1+1] ; var red : double := p * (if r then min_weight(r) else 1 endif) ; var blue : double := q * (if b then min_weight(b) else 1 endif) ; var equilibrium : OclAny := lcm(red, blue) ; return equilibrium div p + equilibrium div q; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minOperations(s,t,n): ct0=0 ct1=0 for i in range(n): if(s[i]==t[i]): continue if(s[i]=='0'): ct0+=1 else : ct1+=1 return max(ct0,ct1) if __name__=="__main__" : s="010" t="101" n=len(s) print(minOperations(s,t,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "010" ; t := "101" ; n := (s)->size() ; execute (minOperations(s, t, n))->display() ) else skip; operation minOperations(s : OclAny, t : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ct0 : int := 0 ; var ct1 : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (s[i+1] = t[i+1]) then ( continue ) else skip ; if (s[i+1] = '0') then ( ct0 := ct0 + 1 ) else ( ct1 := ct1 + 1 )) ; return Set{ct0, ct1}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd while True : try : n=int(input()) if not n : break lst=[[]] weight=[-1 for i in range(n+1)] def setWeight(n): p,q,r,b=lst[n] if weight[n]!=-1 : pass elif r==0 and b==0 : weight[n]=(p+q)//gcd(p,q) elif r==0 : setWeight(b) wb=weight[b] g=gcd(wb*q,p) lcm=wb*q*p//g weight[n]=lcm//q+lcm//p elif b==0 : setWeight(r) wr=weight[r] g=gcd(wr*p,q) lcm=wr*p*q//g weight[n]=lcm//p+lcm//q else : if weight[r]==-1 : setWeight(r) if weight[b]==-1 : setWeight(b) wr=weight[r] wb=weight[b] g=gcd(wr*p,wb*q) lcm=wr*p*wb*q//g weight[n]=lcm//p+lcm//q for i in range(n): lst.append(list(map(int,input().split()))) for i in range(0,n): if weight[i+1]==-1 : setWeight(i+1) print(max(weight)) except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( try ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(n) then ( break ) else skip ; var lst : Sequence := Sequence{ Sequence{} } ; var weight : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (-1)) ; skip ; for i : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : lst)) ; for i : Integer.subrange(0, n-1) do ( if weight[i + 1+1] = -1 then ( setWeight(i + 1) ) else skip) ; execute ((weight)->max())->display()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(x,y): while y>0 : x,y=y,x % y return x while True : N=int(input()) if not N : break a=[list(map(int,input().split()))for _ in[0]*N] root=(set(range(1,N+1))-set(n for bar in a for n in bar[2 :])).pop() def solve(ratio_r,ratio_l,left,right): d=gcd(ratio_r,ratio_l) ratio_r//=d ratio_l//=d w_left=solve(*a[left-1])if left else 0 w_right=solve(*a[right-1])if right else 0 if w_left==w_right==0 : w_left,w_right=ratio_l,ratio_r elif w_left==0 : w_right=(w_right*ratio_r)//gcd(w_right,ratio_r) w_left=ratio_l*(w_right//ratio_r) elif w_right==0 : w_left=(w_left*ratio_l)//gcd(w_left,ratio_l) w_right=ratio_r*(w_left//ratio_l) else : _r,_l=w_left*ratio_r,w_right*ratio_l d=gcd(_l,_r) w_right,w_left=w_right*(_r//d),w_left*(_l//d) return w_right+w_left print(solve(*a[root-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(N) then ( break ) else skip ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var root : OclAny := (Set{}->union((Integer.subrange(1, N + 1-1))) - Set{}->union(((argument (test (logical_test (comparison (expr (atom (name n)))))) (comp_for for (exprlist (expr (atom (name bar)))) in (logical_test (comparison (expr (atom (name a))))) (comp_iter (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name bar)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) :)) ]))))))))))))->last() ; (Set{}->union((Integer.subrange(1, N + 1-1))) - Set{}->union(((argument (test (logical_test (comparison (expr (atom (name n)))))) (comp_for for (exprlist (expr (atom (name bar)))) in (logical_test (comparison (expr (atom (name a))))) (comp_iter (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name bar)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) :)) ])))))))))))) := (Set{}->union((Integer.subrange(1, N + 1-1))) - Set{}->union(((argument (test (logical_test (comparison (expr (atom (name n)))))) (comp_for for (exprlist (expr (atom (name bar)))) in (logical_test (comparison (expr (atom (name a))))) (comp_iter (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name bar)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) :)) ]))))))))))))->front() ; skip ; execute (solve((argument * (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name root))) - (expr (atom (number (integer 1)))))))))) ])))))))))->display()); operation gcd(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: while y > 0 do ( Sequence{x,y} := Sequence{y,x mod y}) ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(x,y): if xexists( _x | result = _x ); attribute weight : int := 0; attribute leftratio : int := leftratio; attribute rightratio : int := rightratio; attribute left : int := left; attribute leftweight : int := 0; attribute right : int := right; attribute rightweight : int := 0; operation initialise(leftratio : int,rightratio : int,left : int,right : int) : Mobile pre: true post: true activity: self.weight := 0 ; self.leftratio := leftratio ; self.rightratio := rightratio ; self.left := left ; self.leftweight := 0 ; self.right := right ; self.rightweight := 0; return self; operation calc() : OclAny pre: true post: true activity: if self.weight /= 0 then ( return self.weight ) else skip ; if self.left = -1 then ( self.leftweight := 1 ) else ( self.leftweight := Mobile.calc(self.left) ) ; if self.right = -1 then ( self.rightweight := 1 ) else ( self.rightweight := Mobile.calc(self.right) ) ; var lmoment : double := self.leftratio * self.leftweight ; var rmoment : double := self.rightratio * self.rightweight ; var lcs : int := lmoment * rmoment div gcd(lmoment, rmoment) ; self.weight := (lcs div self.leftratio) + (lcs div self.rightratio) ; return self.weight; operation stdout() pre: true post: true activity: execute (self.left)->display(); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var barlist : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((Mobile.newMobile()).initialise())) ; for i : Integer.subrange(0, n-1) do ( var p : OclAny := null; var q : OclAny := null; var r : OclAny := null; var b : OclAny := null; Sequence{p,q,r,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; barlist[i+1].leftratio := p ; barlist[i+1].rightratio := q ; if r /= 0 then ( barlist[i+1].left := barlist[r - 1+1] ) else skip ; if b /= 0 then ( barlist[i+1].right := barlist[b - 1+1] ) else skip) ; var maxi : int := 0 ; for i : Integer.subrange(0, n-1) do ( maxi := Set{barlist[i+1].calc(), maxi}->max()) ; execute (maxi)->display()); operation gcd(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (x->compareTo(y)) < 0 then ( var tmp : OclAny := x ; x := y ; y := tmp ) else skip ; var ans : OclAny := y ; if x mod y /= 0 then ( ans := gcd(y, x mod y) ) else skip ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): from math import gcd def traversal(bar_id): if bar_id==0 : return 1 p,q,r,b=nodes[bar_id] r_w=traversal(r) b_w=traversal(b) cf=gcd(p*r_w,q*b_w) return r_w*b_w*(p+q)//cf from sys import stdin file_input=stdin while True : n=int(file_input.readline()) if n==0 : break root_id=n*(n+1)//2 nodes=[None] for i in range(1,n+1): p,q,r,b=map(int,file_input.readline().split()) g=gcd(p,q) nodes.append((p//g,q//g,r,b)) root_id-=(r+b) print(traversal(root_id)) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: skip ; skip ; skip ; var file_input : OclAny := stdin ; while true do ( var n : int := ("" + ((file_input.readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var root_id : int := n * (n + 1) div 2 ; var nodes : Sequence := Sequence{ null } ; for i : Integer.subrange(1, n + 1-1) do ( var p : OclAny := null; var q : OclAny := null; var r : OclAny := null; var b : OclAny := null; Sequence{p,q,r,b} := (file_input.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var g : OclAny := gcd(p, q) ; execute ((Sequence{p div g, q div g, r, b}) : nodes) ; root_id := root_id - (r + b)) ; execute (traversal(root_id))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) numOfPeople=list(map(int,input().split(' '))) counter=0 while n>1 : counter=counter+2*(numOfPeople[n-1]*((2*n)-2)) n=n-1 print(counter) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var numOfPeople : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var counter : int := 0 ; while n > 1 do ( counter := counter + 2 * (numOfPeople[n - 1+1] * ((2 * n) - 2)) ; n := n - 1) ; execute (counter)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout n=int(stdin.readline()) ary=list(map(int,stdin.readline().split())) ans=10**9 for x in range(1,n+1): cur=0 for f in range(1,n+1): cur=cur+2*ary[f-1]*(abs(x-f)+abs(f-1)+abs(x-1)) ans=min(ans,cur) stdout.write("{}".format(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + ((stdin.readLine())))->toInteger() ; var ary : Sequence := ((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : double := (10)->pow(9) ; for x : Integer.subrange(1, n + 1-1) do ( var cur : int := 0 ; for f : Integer.subrange(1, n + 1-1) do ( cur := cur + 2 * ary[f - 1+1] * ((x - f)->abs() + (f - 1)->abs() + (x - 1)->abs())) ; ans := Set{ans, cur}->min()) ; stdout.write(StringLib.interpolateStrings("{}", Sequence{ans})); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ar=list(map(int,input().strip().split(' '))) t=0 i=0 m=1000000000 while(itoInteger() ; var ar : Sequence := ((input()->trim().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var t : int := 0 ; var i : int := 0 ; var m : int := 1000000000 ; while ((i->compareTo(n)) < 0) do ( var c : int := 0 ; for j : Integer.subrange(0, n-1) do ( c := c + (i + (i - j)->abs() + j) * ar[j+1] * 2) ; if (c->compareTo(m)) < 0 then ( m := c ) else skip ; i := i + 1) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) ans=-1 for x in range(0,len(arr)): now=0 for j in range(len(arr)): one=abs(x-j)+abs(j-0)+abs(0-x) total=2*one*arr[j] now+=total if ans==-1 : ans=now ans=min(ans,now) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := -1 ; for x : Integer.subrange(0, (arr)->size()-1) do ( var now : int := 0 ; for j : Integer.subrange(0, (arr)->size()-1) do ( var one : double := (x - j)->abs() + (j - 0)->abs() + (0 - x)->abs() ; var total : double := 2 * one * arr[j+1] ; now := now + total) ; if ans = -1 then ( ans := now ) else skip ; ans := Set{ans, now}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input())+1 print(n &-n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() + 1 ; execute (MathLib.bitwiseAnd(n, -n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isdivisible7(num): n=len(num) if(n==0 and num[0]=='\n'): return 1 if(n % 3==1): num=str(num)+"00" n+=2 elif(n % 3==2): num=str(num)+"0" n+=1 GSum=0 p=1 for i in range(n-1,-1,-1): group=0 group+=ord(num[i])-ord('0') i-=1 group+=(ord(num[i])-ord('0'))*10 i-=1 group+=(ord(num[i])-ord('0'))*100 GSum=GSum+group*p p*=(-1) return(GSum % 7==0) if __name__=="__main__" : num="8955795758" if(isdivisible7(num)): print("Divisible by 7") else : print("Not Divisible by 7") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( num := "8955795758" ; if (isdivisible7(num)) then ( execute ("Divisible by 7")->display() ) else ( execute ("Not Divisible by 7")->display() ) ) else skip; operation isdivisible7(num : OclAny) : OclAny pre: true post: true activity: var n : int := (num)->size() ; if (n = 0 & num->first() = ' ') then ( return 1 ) else skip ; if (n mod 3 = 1) then ( num := ("" + ((num))) + "00" ; n := n + 2 ) else (if (n mod 3 = 2) then ( num := ("" + ((num))) + "0" ; n := n + 1 ) else skip) ; var GSum : int := 0 ; var p : int := 1 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( var group : int := 0 ; group := group + (num[i+1])->char2byte() - ('0')->char2byte() ; i := i - 1 ; group := group + ((num[i+1])->char2byte() - ('0')->char2byte()) * 10 ; i := i - 1 ; group := group + ((num[i+1])->char2byte() - ('0')->char2byte()) * 100 ; GSum := GSum + group * p ; p := p * (-1)) ; return (GSum mod 7 = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reverseBits(n): rev=0 while(n>0): rev=rev<<1 if(n & 1==1): rev=rev ^ 1 n=n>>1 return rev def isPalindrome(n): rev=reverseBits(n) return(n==rev) n=9 if(isPalindrome(n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 9 ; if (isPalindrome(n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation reverseBits(n : OclAny) : OclAny pre: true post: true activity: var rev : int := 0 ; while (n > 0) do ( rev := rev * (2->pow(1)) ; if (MathLib.bitwiseAnd(n, 1) = 1) then ( rev := MathLib.bitwiseXor(rev, 1) ) else skip ; n := n /(2->pow(1)) ; return rev); operation isPalindrome(n : OclAny) : OclAny pre: true post: true activity: rev := reverseBits(n) ; return (n = rev); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=map(int,raw_input().split()) n.sort() n.reverse() n=map(str,n) print(" ".join(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : Sequence := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; n := n->sort() ; n := n->reverse() ; n := (n)->collect( _x | (OclType["String"])->apply(_x) ) ; execute (StringLib.sumStringsWithSeparator((n), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Remainder(str,R): l=len(str) Rem=0 for i in range(l): Num=Rem*10+(ord(str[i])-ord('0')) Rem=Num % R return Rem if __name__=="__main__" : str="13589234356546756" R=13 print(Remainder(str,R)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( OclType["String"] := "13589234356546756" ; R := 13 ; execute (Remainder(OclType["String"], R))->display() ) else skip; operation Remainder(OclType["String"] : OclAny, R : OclAny) : OclAny pre: true post: true activity: var l : int := (OclType["String"])->size() ; var Rem : int := 0 ; for i : Integer.subrange(0, l-1) do ( var Num : int := Rem * 10 + ((("" + ([i+1])))->char2byte() - ('0')->char2byte()) ; Rem := Num mod R) ; return Rem; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(input()) if len(set(s))==len(s): print("yes") else : print("no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if (Set{}->union((s)))->size() = (s)->size() then ( execute ("yes")->display() ) else ( execute ("no")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() char=[chr(ord('a')+i)for i in range(26)] for c in char : if S.count(c)>1 : print('no') break else : print('yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var char : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | ((('a')->char2byte() + i)->byte2char())) ; (compound_stmt for (exprlist (expr (atom (name c)))) in (testlist (test (logical_test (comparison (expr (atom (name char))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name S)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))) > (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'no'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'yes'))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() l=len(S) ans=True for i in range(l): for j in range(i+1,l): if S[i]==S[j]: ans=False if ans==True : print('yes') else : print('no') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var l : int := (S)->size() ; var ans : boolean := true ; for i : Integer.subrange(0, l-1) do ( for j : Integer.subrange(i + 1, l-1) do ( if S[i+1] = S[j+1] then ( ans := false ) else skip)) ; if ans = true then ( execute ('yes')->display() ) else ( execute ('no')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=list(input()) S.sort() nd=0 i=0 while nd==0 and icharacters() ; S := S->sort() ; var nd : int := 0 ; var i : int := 0 ; while nd = 0 & (i->compareTo((S)->size() - 1)) < 0 do ( if S[i+1] = S[i + 1+1] then ( nd := 1 ) else skip ; i := i + 1) ; if nd = 1 then ( execute ("no")->display() ) else ( execute ("yes")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() print('yes' if len(s)==len(set(s))else 'no') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; execute (if (s)->size() = (Set{}->union((s)))->size() then 'yes' else 'no' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=3 def numberOfCells(mat): row=[[False for i in range(N)]for i in range(N)] col=[[False for i in range(N)]for i in range(N)] for i in range(N): for j in range(N-1,-1,-1): if(mat[i][j]==1): if j+1union(Sequence{1}->union(Sequence{ 1 }))}->union(Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{ 1 }))}->union(Sequence{ Sequence{0}->union(Sequence{1}->union(Sequence{ 1 })) })) ; execute (numberOfCells(mat))->display(); operation numberOfCells(mat : OclAny) : OclAny pre: true post: true activity: var row : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Integer.subrange(0, N-1)->select(i | true)->collect(i | (false)))) ; var col : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Integer.subrange(0, N-1)->select(i | true)->collect(i | (false)))) ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(-1 + 1, N - 1)->reverse() do ( if (mat[i+1][j+1] = 1) then ( if (j + 1->compareTo(N)) < 0 then ( row[i+1][j+1] := row[i+1][j + 1+1] ) else ( row[i+1][j+1] := true ) ) else ( row[i+1][j+1] := false ))) ; for j : Integer.subrange(0, N-1) do ( for i : Integer.subrange(-1 + 1, N - 1)->reverse() do ( if (mat[i+1][j+1] = 1) then ( if (i + 1->compareTo(N)) < 0 then ( col[i+1][j+1] := col[i + 1+1][j+1] ) else ( col[i+1][j+1] := true ) ) else ( col[i+1][j+1] := false ))) ; var cnt : int := 0 ; for i : Integer.subrange(0, N - 1-1) do ( for j : Integer.subrange(0, N - 1-1) do ( if (row[i+1][j+1] & col[i+1][j+1]) then ( cnt := cnt + 1 ) else skip)) ; for i : Integer.subrange(0, N-1) do ( if (col[i+1][N - 1+1]) then ( cnt := cnt + 1 ) else skip) ; for j : Integer.subrange(0, N - 1-1) do ( if (row[N - 1+1][j+1]) then ( cnt := cnt + 1 ) else skip) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input())+1 ; print(n &-~ ~ n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() + 1; execute (MathLib.bitwiseAnd(n, -MathLib.bitwiseNot(MathLib.bitwiseNot(n))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().strip() sys.setrecursionlimit(10**8) def solve(): n=int(input()) while n!=0 : w=tuple(map(int,input().split())) dp=[[0]*(n+1)for _ in range(n+1)] for i in range(n-1,-1,-1): for j in range(i+1,n): if(j-i+1)% 2==0 : if dp[i+1][j-1]==j-i-1 and abs(w[i]-w[j])<=1 : dp[i][j]=dp[i+1][j-1]+2 else : p=tuple(dp[i][k]+dp[k+1][j]for k in range(i,j+1)) dp[i][j]=max(p) else : dp[i][j]=max(dp[i][j-1],dp[i+1][j]) print(dp[0][n-1]) n=int(input()) if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine()->trim()) ; sys.setrecursionlimit((10)->pow(8)) ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while n /= 0 do ( var w : Sequence := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)))) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( for j : Integer.subrange(i + 1, n-1) do ( if (j - i + 1) mod 2 = 0 then ( if dp[i + 1+1][j - 1+1] = j - i - 1 & (w[i+1] - w[j+1])->abs() <= 1 then ( dp[i+1][j+1] := dp[i + 1+1][j - 1+1] + 2 ) else ( var p : Sequence := ((argument (test (logical_test (comparison (expr (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ]))) + (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name k))) + (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name k)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 1)))))))))) ))))))))) ; dp[i+1][j+1] := (p)->max() ) ) else ( dp[i+1][j+1] := Set{dp[i+1][j - 1+1], dp[i + 1+1][j+1]}->max() ))) ; execute (dp->first()[n - 1+1])->display() ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import lru_cache while True : N=int(input()) if N==0 : break W=list(map(int,input().split())) assert len(W)==N @ lru_cache(maxsize=None) def solve(l,r): assert l<=r if(r-l)% 2==1 : return False if r-l==2 : return abs(W[l]-W[l+1])<=1 if solve(l+1,r-1)and abs(W[l]-W[r-1])<=1 : return True for i in range(l+2,r,2): if solve(l,i)and solve(i,r): return True return False dp=[0]*(N+1) for i in range(1,N+1): ma=0 for j in range(i-1,-1,-1): ma=max(ma,dp[j]+solve(j,i)*(i-j)) dp[i]=ma print(dp[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var W : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; assert (W)->size() = N do "assertion failed" ; (compound_stmt (decorator @ (dotted_name (name lru_cache)) ( (arglist (argument (test (logical_test (comparison (expr (atom (name maxsize)))))) = (test (logical_test (comparison (expr (atom None))))))) )) (funcdef def (name solve) ( (typedargslist (def_parameters (def_parameter (named_parameter (name l))) , (def_parameter (named_parameter (name r))))) ) : (suite (stmt (simple_stmt (small_stmt assert (test (logical_test (comparison (comparison (expr (atom (name l)))) <= (comparison (expr (atom (name r)))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name r))) - (expr (atom (name l)))))))) ))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name False))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name r))) - (expr (atom (name l))))) == (comparison (expr (atom (number (integer 2)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name W)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name l)))))))) ]))) - (expr (atom (name W)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name l))) + (expr (atom (number (integer 1)))))))))) ]))))))))) ))))) <= (comparison (expr (atom (number (integer 1))))))))))))))) (stmt (compound_stmt if (test (logical_test (logical_test (comparison (expr (atom (name solve)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name l))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name r))) - (expr (atom (number (integer 1)))))))))) )))))) and (logical_test (comparison (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name W)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name l)))))))) ]))) - (expr (atom (name W)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name r))) - (expr (atom (number (integer 1)))))))))) ]))))))))) ))))) <= (comparison (expr (atom (number (integer 1))))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name True))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name l))) + (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (atom (name r))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (expr (atom (name solve)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l))))))) , (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))) and (logical_test (comparison (expr (atom (name solve)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (name r)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name True)))))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name False))))))))))))) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; for i : Integer.subrange(1, N + 1-1) do ( var ma : int := 0 ; for j : Integer.subrange(-1 + 1, i - 1)->reverse() do ( ma := Set{ma, dp[j+1] + solve(j, i) * (i - j)}->max()) ; dp[i+1] := ma) ; execute (dp->last())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,lst): dp=[[0]*n for _ in range(n+1)] for j in range(n-1): if abs(lst[j]-lst[j+1])<=1 : dp[2][j]=2 for i in range(3,n+1): for j in range(n-i+1): mx=0 if i % 2==0 : if abs(lst[j]-lst[j+i-1])<=1 : if dp[i-2][j+1]==i-2 : dp[i][j]=i continue mx=dp[i-2][j+1] for k in range(2,i,2): if mxtoInteger() ; if n = 0 then ( break ) else skip ; lst := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; solve(n, lst)); operation solve(n : OclAny, lst : OclAny) pre: true post: true activity: var dp : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, n))) ; for j : Integer.subrange(0, n - 1-1) do ( if (lst[j+1] - lst[j + 1+1])->abs() <= 1 then ( dp[2+1][j+1] := 2 ) else skip) ; for i : Integer.subrange(3, n + 1-1) do ( for j : Integer.subrange(0, n - i + 1-1) do ( var mx : int := 0 ; if i mod 2 = 0 then ( if (lst[j+1] - lst[j + i - 1+1])->abs() <= 1 then ( if dp[i - 2+1][j + 1+1] = i - 2 then ( dp[i+1][j+1] := i ; continue ) else skip ) else skip ; mx := dp[i - 2+1][j + 1+1] ; for k : Integer.subrange(2, i-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( if (mx->compareTo(dp[k+1][j+1] + dp[i - k+1][j + k+1])) < 0 then ( mx := dp[k+1][j+1] + dp[i - k+1][j + k+1] ; if mx = i then ( break ) else skip ) else skip) ) else ( for k : Integer.subrange(1, i-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( if (mx->compareTo(dp[k+1][j+1] + dp[i - k+1][j + k+1])) < 0 then ( mx := dp[k+1][j+1] + dp[i - k+1][j + k+1] ) else skip) ) ; dp[i+1][j+1] := mx)) ; execute (dp[n+1]->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): a=list(map(int,input().split())) a.sort(reverse=True) for x in range(len(a)): if x==len(a)-1 : print(a[x]) else : print(a[x],end=" ") if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; for x : Integer.subrange(0, (a)->size()-1) do ( if x = (a)->size() - 1 then ( execute (a[x+1])->display() ) else ( execute (a[x+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) while True : l1=list(map(int,input().split())) c=[[False]*n for i in range(n)] d=[0]*(n+1) for i in range(n-1): if abs(l1[i+1]-l1[i])<=1 : c[i][i+1]=True for i in range(3,n,2): for j in range(n-i): for k in range(j+1,j+i): if c[j][j+i]==False and c[j][k]and c[k+1][j+i]: c[j][j+i]=True break if c[j][j+i]==False and abs(l1[j]-l1[j+i])<=1 and c[j+1][j+i-1]: c[j][j+i]=True for i in range(n): for j in range(i): if c[j][i]: d[i]=max(d[i],d[j-1]+i-j+1) d[i]=max(d[i],d[i-1]) print(d[n-1]) n=int(input()) if n==0 : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while true do ( var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ false }, n))) ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(0, n - 1-1) do ( if (l1[i + 1+1] - l1[i+1])->abs() <= 1 then ( c[i+1][i + 1+1] := true ) else skip) ; for i : Integer.subrange(3, n-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( for j : Integer.subrange(0, n - i-1) do ( for k : Integer.subrange(j + 1, j + i-1) do ( if c[j+1][j + i+1] = false & c[j+1][k+1] & c[k + 1+1][j + i+1] then ( c[j+1][j + i+1] := true ; break ) else skip) ; if c[j+1][j + i+1] = false & (l1[j+1] - l1[j + i+1])->abs() <= 1 & c[j + 1+1][j + i - 1+1] then ( c[j+1][j + i+1] := true ) else skip)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, i-1) do ( if c[j+1][i+1] then ( d[i+1] := Set{d[i+1], d[j - 1+1] + i - j + 1}->max() ) else skip) ; d[i+1] := Set{d[i+1], d[i - 1+1]}->max()) ; execute (d[n - 1+1])->display() ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def func(): while True : N=int(input()) if N==0 : break W=[int(i)for i in input().split()] dp=[[0]*(N+1)for j in range(N+1)] for s in range(2,N+1): for l in range(N-s+1): r=l+s if(s-2)% 2==0 : if dp[l+1][r-1]==s-2 and abs(W[l]-W[r-1])<=1 : dp[l][r]=s continue for i in range(l,r+1): if dp[l][r]toInteger() ; if N = 0 then ( break ) else skip ; var W : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var dp : Sequence := Integer.subrange(0, N + 1-1)->select(j | true)->collect(j | (MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)))) ; for s : Integer.subrange(2, N + 1-1) do ( for l : Integer.subrange(0, N - s + 1-1) do ( var r : OclAny := l + s ; if (s - 2) mod 2 = 0 then ( if dp[l + 1+1][r - 1+1] = s - 2 & (W[l+1] - W[r - 1+1])->abs() <= 1 then ( dp[l+1][r+1] := s ; continue ) else skip ) else skip ; for i : Integer.subrange(l, r + 1-1) do ( if (dp[l+1][r+1]->compareTo(dp[l+1][i+1] + dp[i+1][r+1])) < 0 then ( dp[l+1][r+1] := dp[l+1][i+1] + dp[i+1][r+1] ) else skip))) ; execute (dp->first()[N+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=[] for i in range(n): s.append(input()) ans="" INF=1000 for c_i in range(ord('a'),ord('z')+1): small=INF c=chr(c_i) for i in range(n): cnt=s[i].count(c) small=min(small,cnt) ans+=c*small print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : s)) ; var ans : String := "" ; var INF : int := 1000 ; for c_i : Integer.subrange(('a')->char2byte(), ('z')->char2byte() + 1-1) do ( var small : int := INF ; var c : String := (c_i)->byte2char() ; for i : Integer.subrange(0, n-1) do ( var cnt : OclAny := s[i+1]->count(c) ; small := Set{small, cnt}->min()) ; ans := ans + StringLib.nCopies(c, small)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np n=int(input()) S=[str(input())for _ in range(0,n)] def Count_Alphabet(word): string=str(word) alphabet=str("abcdefghijklmnopqrstuvwxyz") count=np.zeros(len(alphabet)) for i in range(0,len(alphabet)): for j in range(0,len(string)): if alphabet[i]==string[j]: count[i]+=1 return count S_stat=np.ones((n,26)) for i in range(0,n): S_stat[i]=Count_Alphabet(S[i]) Min_sta=np.ones(26) for i in range(0,26): Min_sta[i]=min(S_stat[:,i]) ans=str() alphabet=str("abcdefghijklmnopqrstuvwxyz") for i in range(0,26): ans+=str(alphabet[i])*int(Min_sta[i]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine()))))) ; skip ; var S_stat : Sequence := MatrixLib.singleValueMatrix(Sequence{n, 26}, 1.0) ; for i : Integer.subrange(0, n-1) do ( S_stat[i+1] := Count_Alphabet(S[i+1])) ; var Min_sta : Sequence := MatrixLib.singleValueMatrix(26, 1.0) ; for i : Integer.subrange(0, 26-1) do ( Min_sta[i+1] := (S_stat->collect( _r | _r[i+1] ))->min()) ; var ans : String := ("" + (())) ; alphabet := ("" + (("abcdefghijklmnopqrstuvwxyz"))) ; for i : Integer.subrange(0, 26-1) do ( ans := ans + ("" + ((alphabet[i+1]))) * ("" + ((Min_sta[i+1])))->toInteger()) ; execute (ans)->display(); operation Count_Alphabet(word : OclAny) : OclAny pre: true post: true activity: var string : String := ("" + ((word))) ; var alphabet : String := ("" + (("abcdefghijklmnopqrstuvwxyz"))) ; var count : Sequence := MatrixLib.singleValueMatrix((alphabet)->size(), 0.0) ; for i : Integer.subrange(0, (alphabet)->size()-1) do ( for j : Integer.subrange(0, (string)->size()-1) do ( if alphabet[i+1] = string[j+1] then ( count[i+1] := count[i+1] + 1 ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict n=int(input()) S=[input()for i in range(n)] counter=[defaultdict(lambda : 0)for i in range(n)] for i in range(n): for c in S[i]: counter[i][c]+=1 all_counter=defaultdict(lambda : 0) for s in counter[0]: all_counter[s]+=counter[0][s] for i in range(n): for s in all_counter : all_counter[s]=min(counter[i][s],all_counter[s]) for s in sorted(all_counter,key=lambda x : x[0]): print(s*all_counter[s],end='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var counter : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (defaultdict(lambda $$ : OclAny in (0)))) ; for i : Integer.subrange(0, n-1) do ( for c : S[i+1] do ( counter[i+1][c+1] := counter[i+1][c+1] + 1)) ; var all_counter : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; for s : counter->first() do ( all_counter[s+1] := all_counter[s+1] + counter->first()[s+1]) ; for i : Integer.subrange(0, n-1) do ( for s : all_counter do ( all_counter[s+1] := Set{counter[i+1][s+1], all_counter[s+1]}->min())) ; for s : all_counter->sortedBy($x | (lambda x : OclAny in (x->first()))->apply($x)) do ( execute (s * all_counter[s+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) b=input() a={i : b.count(i)for i in b} for i in range(n-1): b=input() a={i : min(a[i],b.count(i))for i in b if i in a} ans="" for i in a.keys(): ans+=i*a[i] print(*sorted(ans),sep="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : String := (OclFile["System.in"]).readLine() ; var a : Map := b->characters()->select(i | true)->collect(i | Map{i |-> b->count(i)})->unionAll() ; for i : Integer.subrange(0, n - 1-1) do ( b := (OclFile["System.in"]).readLine() ; a := b->characters()->select(i | (a)->includes(i))->collect(i | Map{i |-> Set{a[i+1], b->count(i)}->min()})->unionAll()) ; var ans : String := "" ; for i : a.keys() do ( ans := ans + i * a[i+1]) ; execute ((argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) )))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=str(input()) my_str='' for c in s : if c=='0' or c=='1' : my_str+=c elif c=='B' and len(my_str)!=0 : my_str=my_str[: len(my_str)-1] print(my_str) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; var my_str : String := '' ; for c : s->characters() do ( if c = '0' or c = '1' then ( my_str := my_str + c ) else (if c = 'B' & (my_str)->size() /= 0 then ( my_str := my_str.subrange(1,(my_str)->size() - 1) ) else skip)) ; execute (my_str)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) SS=[input()for _ in range(N)] dict={} for S in SS : cnt={} for c in list(S): if c in cnt : cnt[c]+=1 else : cnt[c]=1 if len(dict)==0 : for c in cnt : dict[c]=cnt[c] else : for c in dict : if c in cnt : dict[c]=min(dict[c],cnt[c]) else : dict[c]=0 ans='' for i in range(26): c=chr(ord('a')+i) if c in dict : ans+=c*dict[c] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var SS : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var OclType["Map"] : OclAny := Set{} ; for S : SS do ( var cnt : OclAny := Set{} ; for c : (S) do ( if (cnt)->includes(c) then ( cnt[c+1] := cnt[c+1] + 1 ) else ( cnt[c+1] := 1 )) ; if (OclType["Map"])->size() = 0 then ( for c : cnt do ( (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name c)))))))) ]) := cnt[c+1]) ) else ( for c : OclType["Map"] do ( if (cnt)->includes(c) then ( (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name c)))))))) ]) := Set{(arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name c)))))))) ]), cnt[c+1]}->min() ) else ( (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name c)))))))) ]) := 0 )) )) ; var ans : String := '' ; for i : Integer.subrange(0, 26-1) do ( var c : String := (('a')->char2byte() + i)->byte2char() ; if (OclType["Map"])->includes(c) then ( ans := ans + StringLib.nCopies(c, (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name c)))))))) ])) ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,log def isPowerful(n): while(n % 2==0): power=0 while(n % 2==0): n/=2 power+=1 if(power==1): return False p=int(sqrt(n))+1 for factor in range(3,p,2): power=0 while(n % factor==0): n=n/factor power+=1 if(power==1): return False return(n==1) def isPower(a): if(a==1): return True p=int(sqrt(a))+1 for i in range(2,a,1): val=log(a)/log(i) if((val-int(val))<0.00000001): return True return False def isAchillesNumber(n): if(isPowerful(n)==True and isPower(n)==False): return True else : return False if __name__=='__main__' : n=72 if(isAchillesNumber(n)): print("YES") else : print("NO") n=36 if(isAchillesNumber(n)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( n := 72 ; if (isAchillesNumber(n)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ; n := 36 ; if (isAchillesNumber(n)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; operation isPowerful(n : OclAny) : OclAny pre: true post: true activity: while (n mod 2 = 0) do ( var power : int := 0 ; while (n mod 2 = 0) do ( n := n / 2 ; power := power + 1) ; if (power = 1) then ( return false ) else skip) ; var p : int := ("" + ((sqrt(n))))->toInteger() + 1 ; for factor : Integer.subrange(3, p-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( power := 0 ; while (n mod factor = 0) do ( n := n / factor ; power := power + 1) ; if (power = 1) then ( return false ) else skip) ; return (n = 1); operation isPower(a : OclAny) : OclAny pre: true post: true activity: if (a = 1) then ( return true ) else skip ; p := ("" + ((sqrt(a))))->toInteger() + 1 ; for i : Integer.subrange(2, a-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( var val : double := log(a) / log(i) ; if ((val - ("" + ((val)))->toInteger()) < 0.00000001) then ( return true ) else skip) ; return false; operation isAchillesNumber(n : OclAny) : OclAny pre: true post: true activity: if (isPowerful(n) = true & isPower(n) = false) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,collections infile=sys.stdin def find_square(S): qpos=[i for i,ch in enumerate(S)if ch=='?'] ns=len(S) nq=len(qpos) baseval=int(S.replace('?','0'),2) for i in xrange(1<toInteger() ; for i : xrange(T) do ( S := infile.readLine()->trim() ; var result : OclAny := find_square(S) ; execute (StringLib.format("Case #%d: %s",Sequence{i + 1, result}))->display()); operation find_square(S : OclAny) : OclAny pre: true post: true activity: var qpos : Sequence := Integer.subrange(1, (S)->size())->collect( _indx | Sequence{_indx-1, (S)->at(_indx)} )->select(_tuple | let i : OclAny = _tuple->at(1) in let ch : OclAny = _tuple->at(2) in ch = '?')->collect(_tuple | let i : OclAny = _tuple->at(1) in let ch : OclAny = _tuple->at(2) in (i)) ; var ns : int := (S)->size() ; var nq : int := (qpos)->size() ; var baseval : int := ("" + ((S.replace('?', '0'), 2)))->toInteger() ; for i : xrange(1 * (2->pow((qpos)->size()))) do ( var val : int := baseval ; for j : xrange(nq) do ( if (MathLib.bitwiseAnd(i, (1 * (2->pow(j))))) then ( var p : int := 1 * (2->pow((ns - qpos[j+1] - 1))) ; val := val + p ) else skip) ; var r : int := ("" + (((val)->pow(0.5))))->toInteger() ; if (r * r = val) then ( return bin(val).subrange(2+1) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def foo2(word,idx,n): word=word[:] for i in range(len(idx)): word[idx[i]]=n % 2 n//=2 res=0 for x in word : res=res*2+x t=int(res**0.5) if t*t==res : return ''.join(str(x)for x in word) def foo(ifile): word=list(ifile.readline().strip()) idx=[] n=0 for i in range(len(word)): if word[i]=='?' : idx.append(i) word[i]=None else : word[i]=int(word[i]) n=len(idx) if n==0 : return ''.join(str(x)for x in word) for i in range(2**n): t=foo2(word,idx,i) if t is not None : return t def main(ifile,ofile): n=int(ifile.readline()) for i in range(n): ofile.write("Case #%s: %s\n" %(i+1,foo(ifile))) ofile.flush() main(sys.stdin,sys.stdout) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; main(OclFile["System.in"], OclFile["System.out"]); operation foo2(word : OclAny, idx : OclAny, n : OclAny) : OclAny pre: true post: true activity: word := word ; for i : Integer.subrange(0, (idx)->size()-1) do ( word[idx[i+1]+1] := n mod 2 ; n := n div 2) ; var res : int := 0 ; for x : word do ( res := res * 2 + x) ; var t : int := ("" + (((res)->pow(0.5))))->toInteger() ; if t * t = res then ( return StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name word)))))))), '') ) else skip; operation foo(ifile : OclAny) : OclAny pre: true post: true activity: word := (ifile.readLine()->trim()) ; idx := Sequence{} ; n := 0 ; for i : Integer.subrange(0, (word)->size()-1) do ( if word[i+1] = '?' then ( execute ((i) : idx) ; word[i+1] := null ) else ( word[i+1] := ("" + ((word[i+1])))->toInteger() )) ; n := (idx)->size() ; if n = 0 then ( return StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name word)))))))), '') ) else skip ; for i : Integer.subrange(0, (2)->pow(n)-1) do ( t := foo2(word, idx, i) ; if not(t <>= null) then ( return t ) else skip); operation main(ifile : OclAny, ofile : OclAny) pre: true post: true activity: n := ("" + ((ifile.readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( ofile.write(StringLib.format("Case #%s: %s\n",Sequence{i + 1, foo(ifile)})) ; ofile.flush()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=1000000007 n=int(input()) x=sorted(list(map(int,input().split()))) s=sum(x) p=[] j=1 for i in range(n+1): p.append(j) j=(j*2)% mod d=0 for i in range(n): d=(d+(x[i]*p[i])% mod)% mod d=(d-(x[i]*p[n-i-1])% mod)% mod print(int(d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : int := 1000000007 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var s : OclAny := (x)->sum() ; var p : Sequence := Sequence{} ; var j : int := 1 ; for i : Integer.subrange(0, n + 1-1) do ( execute ((j) : p) ; j := (j * 2) mod mod) ; var d : int := 0 ; for i : Integer.subrange(0, n-1) do ( d := (d + (x[i+1] * p[i+1]) mod mod) mod mod ; d := (d - (x[i+1] * p[n - i - 1+1]) mod mod) mod mod) ; execute (("" + ((d)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sort(num): l=len(num) for i in range(0,l): for j in range(0,l-i-1): if num[j]collect( _x | (OclType["int"])->apply(_x) ) ; num := Sequence{} ; execute ((a) : num) ; execute ((b) : num) ; execute ((c) : num) ; execute ((d) : num) ; execute ((e) : num) ; sort(num); operation sort(num : OclAny) pre: true post: true activity: var l : int := (num)->size() ; for i : Integer.subrange(0, l-1) do ( for j : Integer.subrange(0, l - i - 1-1) do ( if (num[j+1]->compareTo(num[j + 1+1])) < 0 then ( var temp : OclAny := num[j+1] ; num[j+1] := num[j + 1+1] ; num[j + 1+1] := temp ) else skip)) ; execute (num->first())->display() ; for i : Integer.subrange(1, (num)->size() - 1-1) do ( execute ('')->display()) ; execute ('')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNumber(n,d): ans="" if(d!=10): ans+=str(d) for i in range(1,n): ans+='0' else : if(n==1): ans+="Impossible" else : ans+='1' for i in range(1,n): ans+='0' return ans if __name__=="__main__" : n=12 d=3 print(findNumber(n,d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 12 ; d := 3 ; execute (findNumber(n, d))->display() ) else skip; operation findNumber(n : OclAny, d : OclAny) : OclAny pre: true post: true activity: var ans : String := "" ; if (d /= 10) then ( ans := ans + ("" + ((d))) ; for i : Integer.subrange(1, n-1) do ( ans := ans + '0') ) else ( if (n = 1) then ( ans := ans + "Impossible" ) else ( ans := ans + '1' ; for i : Integer.subrange(1, n-1) do ( ans := ans + '0') ) ) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countRectangles(radius): rectangles=0 diameter=2*radius diameterSquare=diameter*diameter for a in range(1,2*radius): for b in range(1,2*radius): diagnalLengthSquare=(a*a+b*b) if(diagnalLengthSquare<=diameterSquare): rectangles+=1 return rectangles radius=2 totalRectangles=countRectangles(radius) print(totalRectangles,"rectangles can be","cut from a circle of Radius",radius) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; radius := 2 ; var totalRectangles : OclAny := countRectangles(radius) ; execute (totalRectangles)->display(); operation countRectangles(radius : OclAny) : OclAny pre: true post: true activity: var rectangles : int := 0 ; var diameter : double := 2 * radius ; var diameterSquare : double := diameter * diameter ; for a : Integer.subrange(1, 2 * radius-1) do ( for b : Integer.subrange(1, 2 * radius-1) do ( var diagnalLengthSquare : double := (a * a + b * b) ; if ((diagnalLengthSquare->compareTo(diameterSquare)) <= 0) then ( rectangles := rectangles + 1 ) else skip)) ; return rectangles; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def log_a_to_base_b(a,b): rslt=(1+log_a_to_base_b(a//b,b))if(a>(b-1))else 0 ; return rslt ; if __name__=="__main__" : a=3 ; b=2 ; print(log_a_to_base_b(a,b)); a=256 ; b=4 ; print(log_a_to_base_b(a,b)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := 3; ; b := 2; ; execute (log_a_to_base_b(a, b))->display(); ; a := 256; ; b := 4; ; execute (log_a_to_base_b(a, b))->display(); ) else skip; operation log_a_to_base_b(a : OclAny, b : OclAny) pre: true post: true activity: var rslt : int := if ((a->compareTo((b - 1))) > 0) then (1 + log_a_to_base_b(a div b, b)) else 0 endif; ; return rslt;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import operator while 1 : n=int(input()) if n==0 : break s=[list(map(int,input().split()))for i in range(n)] e=s[:] s.sort(key=operator.itemgetter(1)) e.sort(key=operator.itemgetter(2)) s_i=e_i=0 w=0 for i in range(n*2): if e_i=e[e_i][2]: w-=e[e_i][0] e_i+=1 else : w+=s[s_i][0] s_i+=1 if w>150 : print('NG') break if i==n*2-1 or s_i>=len(s): print('OK') break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var s : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var e : Sequence := s ; s := s->sort() ; e := e->sort() ; var s_i : OclAny := 0; var e_i : int := 0 ; var w : int := 0 ; for i : Integer.subrange(0, n * 2-1) do ( if (e_i->compareTo((e)->size())) < 0 & (s[s_i+1][1+1]->compareTo(e[e_i+1][2+1])) >= 0 then ( w := w - e[e_i+1]->first() ; e_i := e_i + 1 ) else ( w := w + s[s_i+1]->first() ; s_i := s_i + 1 ) ; if w > 150 then ( execute ('NG')->display() ; break ) else skip ; if i = n * 2 - 1 or (s_i->compareTo((s)->size())) >= 0 then ( execute ('OK')->display() ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() ans=[] for i in range(len(s)): if s[i]=='0' : ans.append(0) elif s[i]=='1' : ans.append(1) else : if ans!=[]: ans.pop() print(''.join(str(n)for n in ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = '0' then ( execute ((0) : ans) ) else (if s[i+1] = '1' then ( execute ((1) : ans) ) else ( if ans /= Sequence{} then ( ans := ans->front() ) else skip ) ) ) ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name ans)))))))), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy from test.support import _MemoryWatchdog BIG_NUM=2000000000 HUGE_NUM=99999999999999999 MOD=1000000007 EPS=0.000000001 sys.setrecursionlimit(100000) MAX=150 OUT=0 IN=1 class Info : def __init__(self,arg_weight,arg_TIME,arg_Type): self.weight=arg_weight self.TIME=arg_TIME self.Type=arg_Type def __lt__(self,another): if self.TIME!=another.TIME : return self.TIME0 and FLG==True : info=heappop(Q) if info.Type==IN : tmp_sum+=info.weight if tmp_sum>MAX : print("NG") FLG=False break else : tmp_sum-=info.weight if FLG==True : print("OK") ------------------------------------------------------------ OCL File: --------- class Info { static operation newInfo() : Info pre: true post: Info->exists( _x | result = _x ); attribute weight : OclAny := arg_weight; attribute TIME : OclAny := arg_TIME; attribute Type : OclAny := arg_Type; operation initialise(arg_weight : OclAny,arg_TIME : OclAny,arg_Type : OclAny) : Info pre: true post: true activity: self.weight := arg_weight ; self.TIME := arg_TIME ; self.Type := arg_Type; return self; operation __lt__(another : OclAny) : OclAny pre: true post: true activity: if self.TIME /= another.TIME then ( return (self.TIME->compareTo(another.TIME)) < 0 ) else ( return (self.Type->compareTo(another.Type)) < 0 ); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var HUGE_NUM : int := 99999999999999999 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; sys.setrecursionlimit(100000) ; var MAX : int := 150 ; var OUT : int := 0 ; var IN : int := 1 ; skip ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var Q : Sequence := Sequence{} ; for _anon : Integer.subrange(0, N-1) do ( var weight : OclAny := null; var left : OclAny := null; var right : OclAny := null; Sequence{weight,left,right} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; heappush(Q, (Info.newInfo()).initialise(weight, left, IN)) ; heappush(Q, (Info.newInfo()).initialise(weight, right, OUT))) ; var tmp_sum : int := 0 ; var FLG : boolean := true ; while (Q)->size() > 0 & FLG = true do ( var info : OclAny := heappop(Q) ; if info.Type = IN then ( tmp_sum := tmp_sum + info.weight ; if (tmp_sum->compareTo(MAX)) > 0 then ( execute ("NG")->display() ; FLG := false ; break ) else skip ) else ( tmp_sum := tmp_sum - info.weight )) ; if FLG = true then ( execute ("OK")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(n): events=[] for _ in range(n): m,a,b=map(int,input().split()) events.append([a,m]) events.append([b,-m]) weight=0 for t,m in sorted(events): weight+=m if weight>150 : return 'NG' return 'OK' def main(args): while True : n=int(input()) if n==0 : break ans=solve(n) print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(n : OclAny) : OclAny pre: true post: true activity: var events : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var m : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{m,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a}->union(Sequence{ m })) : events) ; execute ((Sequence{b}->union(Sequence{ -m })) : events)) ; var weight : int := 0 ; for _tuple : events->sort() do (var _indx : int := 1; var t : OclAny := _tuple->at(_indx); _indx := _indx + 1; var m : OclAny := _tuple->at(_indx); weight := weight + m ; if weight > 150 then ( return 'NG' ) else skip) ; return 'OK'; operation main(args : OclAny) pre: true post: true activity: while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var ans : OclAny := solve(n) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : num=int(input()) if num==0 : break L=[] start=set() for _ in range(num): w,a,b=[int(x)for x in input().split()] L.append([w,a,b]) start.add(a) f=0 for t in sorted(start): wt=0 for l in L : if t>=l[1]and t150 : f+=1 if f>0 : print("NG") else : print("OK") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if num = 0 then ( break ) else skip ; var L : Sequence := Sequence{} ; var start : Set := Set{}->union(()) ; for _anon : Integer.subrange(0, num-1) do ( var w : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{w,a,b} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((Sequence{w}->union(Sequence{a}->union(Sequence{ b }))) : L) ; execute ((a) : start)) ; var f : int := 0 ; for t : start->sort() do ( var wt : int := 0 ; for l : L do ( if (t->compareTo(l[1+1])) >= 0 & (t->compareTo(l[2+1])) < 0 then ( wt := wt + l->first() ) else skip) ; if wt > 150 then ( f := f + 1 ) else skip) ; if f > 0 then ( execute ("NG")->display() ) else ( execute ("OK")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break tbl=[] for i in range(n): m,a,b=map(int,input().split()) tbl.append((a,m)) tbl.append((b,-m)) tbl.sort() sum,t,s=0,-1,0 for i in range(len(tbl)): if t!=tbl[i][0]: if(sum+s)>150 : break sum+=s t,s=tbl[i][0],tbl[i][1] else : s+=tbl[i][1] print("OK" if sum+s<=150 else "NG") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var tbl : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var m : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{m,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a, m}) : tbl) ; execute ((Sequence{b, -m}) : tbl)) ; tbl := tbl->sort() ; var sum : OclAny := null; var t : OclAny := null; var s : OclAny := null; Sequence{sum,t,s} := Sequence{0,-1,0} ; for i : Integer.subrange(0, (tbl)->size()-1) do ( if t /= tbl[i+1]->first() then ( if (sum + s) > 150 then ( break ) else skip ; sum := sum + s ; var t : OclAny := null; var s : OclAny := null; Sequence{t,s} := Sequence{tbl[i+1]->first(),tbl[i+1][1+1]} ) else ( s := s + tbl[i+1][1+1] )) ; execute (if sum + s <= 150 then "OK" else "NG" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def read(): return list(map(int,input().split(' '))) def best(rank,tot): if rank==tot-1 : return 0 return tot//2+best((rank+1)//2,tot//2) def worst(rank,tot): if rank==0 : return 0 return tot//2+worst((rank-1)//2,tot//2) [T]=read() for i in range(1,T+1): n,P=read() ans1,ans2=0,2**n-1 L,R=0,2**n-1 while L=P : R=m-1 else : L=m ans1=L L,R=0,2**n-1 while Lpow(n) - 1} ; var L : OclAny := null; var R : OclAny := null; Sequence{L,R} := Sequence{0,(2)->pow(n) - 1} ; while (L->compareTo(R)) < 0 do ( var m : int := (L + R + 1) div 2 ; if (worst(m, (2)->pow(n))->compareTo(P)) >= 0 then ( var R : double := m - 1 ) else ( var L : int := m )) ; var ans1 : int := L ; Sequence{L,R} := Sequence{0,(2)->pow(n) - 1} ; while (L->compareTo(R)) < 0 do ( m := (L + R + 1) div 2 ; if (best(m, (2)->pow(n))->compareTo((2)->pow(n) - P)) < 0 then ( R := m - 1 ) else ( L := m )) ; var ans2 : int := L ; execute (StringLib.format('Case #%d: %d %d',Sequence{i, ans1, ans2}))->display()); operation read() : OclAny pre: true post: true activity: return ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )); operation best(rank : OclAny, tot : OclAny) : OclAny pre: true post: true activity: if rank = tot - 1 then ( return 0 ) else skip ; return tot div 2 + best((rank + 1) div 2, tot div 2); operation worst(rank : OclAny, tot : OclAny) : OclAny pre: true post: true activity: if rank = 0 then ( return 0 ) else skip ; return tot div 2 + worst((rank - 1) div 2, tot div 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os in_file=None out_file=None def run_main(main): name=sys.argv[0][:-3] in_file_name=name+".in" out_file_name=name+".out" if len(sys.argv)==2 : in_file_name=sys.argv[1] out_file_name=in_file_name[:-3]+".out" if len(sys.argv)==3 : if sys.argv[1]: in_file_name=sys.argv[1] if sys.argv[2]: out_file_name=sys.argv[2] global in_file global out_file if in_file_name=='-' : in_file=sys.stdin else : in_file=open(in_file_name,'r') if out_file_name=='-' : out_file=sys.stdout else : out_file=open(out_file_name,'w') main(in_file,out_file) out_file.close() in_file.close() def run_tests(do_testcase): def main(in_file,out_file): t=readinteger() for x in range(t): do_testcase(x+1) run_main(main) def readline(): return in_file.readline()[:-1] def writeline(s): out_file.write("%s\n" % s) def readinteger(): return int(readline()) def readintegers(): integers=readline().split() for i in range(len(integers)): integers[i]=int(integers[i]) return integers ------------------------------------------------------------ OCL File: --------- class FromPython { attribute in_file : OclAny; attribute out_file : OclAny; operation initialise() pre: true post: true activity: skip ; var in_file : OclAny := null ; var out_file : OclAny := null ; skip ; skip ; skip ; skip ; skip ; skip; operation run_main(main : OclAny) pre: true post: true activity: var name : OclAny := ((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))).subrange(1,-3) ; var in_file_name : int := name + ".in" ; var out_file_name : int := name + ".out" ; if ((trailer . (name argv)))->size() = 2 then ( in_file_name := (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) ; out_file_name := in_file_name.subrange(1,-3) + ".out" ) else skip ; if ((trailer . (name argv)))->size() = 3 then ( if (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) then ( in_file_name := (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) ) else skip ; if (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) then ( out_file_name := (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) ) else skip ) else skip ; skip ; skip ; if in_file_name = '-' then ( in_file := OclFile["System.in"] ) else ( in_file := OclFile.newOclFile_Write(OclFile.newOclFile(in_file_name)) ) ; if out_file_name = '-' then ( out_file := OclFile["System.out"] ) else ( out_file := OclFile.newOclFile_Write(OclFile.newOclFile(out_file_name)) ) ; main(in_file, out_file) ; out_file.closeFile() ; in_file.closeFile(); operation run_tests(do_testcase : OclAny) pre: true post: true activity: skip ; run_main(main); operation readline() : OclAny pre: true post: true activity: return in_file.readLine()->front(); operation writeline(s : OclAny) pre: true post: true activity: out_file.write(StringLib.format("%s\n",s)); operation readinteger() : OclAny pre: true post: true activity: return ("" + ((readline())))->toInteger(); operation readintegers() : OclAny pre: true post: true activity: var integers : OclAny := readline().split() ; for i : Integer.subrange(0, (integers)->size()-1) do ( integers[i+1] := ("" + ((integers[i+1])))->toInteger()) ; return integers; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import(absolute_import,division,print_function,unicode_literals) from sys import stdin gen=(int(s)for s in stdin.readline().split()) print(' '.join(str(i)for i in sorted(gen,reverse=True))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var gen : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name stdin)) (trailer . (name readline) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name gen))))))) , (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ))))))))), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import* from heapq import* import math def write(msg): stdout.write(msg) fo.write(msg) def writeln(msg): write(str(msg)+'\n') def readint(): return int(fi.readline()) def readints(): return[int(X)for X in fi.readline().split()] def readstr(): return fi.readline().rstrip() fni="%s-%s-%s.in" %(argv[1],argv[2],argv[3]) fno="%s-%s-%s.out" %(argv[1],argv[2],argv[3]) fi=open(fni,'r') fo=open(fno,'w') def ffail(start,step,num,prizes): if prizes>=num : return start+step*(num-1)+1 if prizes<=0 : return start if 2*prizes<=num : return start+step return ffail(start+step,step*2,num/2,prizes-num/2) def wwin(start,step,num,prizes): if prizes>=num : return start+step*(num-1) if prizes<=0 : return 0 return wwin(start,step*2,num/2,prizes) num_cases=readint() for case in range(1,1+num_cases): (N,P)=readints() g=ffail(0,1,2**N,P)-1 w=wwin(0,1,2**N,P) writeln("Case #%d: %d %d" %(case,g,w)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var fni : String := StringLib.format("%s-%s-%s.in",Sequence{argv[1+1], argv[2+1], argv[3+1]}) ; var fno : String := StringLib.format("%s-%s-%s.out",Sequence{argv[1+1], argv[2+1], argv[3+1]}) ; var fi : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(fni)) ; var fo : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(fno)) ; skip ; skip ; var num_cases : OclAny := readint() ; for case : Integer.subrange(1, 1 + num_cases-1) do ( ; var Sequence{N, P} : OclAny := readints() ; var g : double := ffail(0, 1, (2)->pow(N), P) - 1 ; var w : OclAny := wwin(0, 1, (2)->pow(N), P) ; writeln(StringLib.format("Case #%d: %d %d",Sequence{case, g, w}))); operation write(msg : OclAny) pre: true post: true activity: stdout.write(msg) ; fo.write(msg); operation writeln(msg : OclAny) pre: true post: true activity: write(("" + ((msg))) + ' '); operation readint() : OclAny pre: true post: true activity: return ("" + ((fi.readLine())))->toInteger(); operation readints() : OclAny pre: true post: true activity: return fi.readLine().split()->select(X | true)->collect(X | (("" + ((X)))->toInteger())); operation readstr() : OclAny pre: true post: true activity: return fi.readLine().rstrip(); operation ffail(start : OclAny, step : OclAny, num : OclAny, prizes : OclAny) : OclAny pre: true post: true activity: if (prizes->compareTo(num)) >= 0 then ( return start + step * (num - 1) + 1 ) else skip ; if prizes <= 0 then ( return start ) else skip ; if (2 * prizes->compareTo(num)) <= 0 then ( return start + step ) else skip ; return ffail(start + step, step * 2, num / 2, prizes - num / 2); operation wwin(start : OclAny, step : OclAny, num : OclAny, prizes : OclAny) : OclAny pre: true post: true activity: if (prizes->compareTo(num)) >= 0 then ( return start + step * (num - 1) ) else skip ; if prizes <= 0 then ( return 0 ) else skip ; return wwin(start, step * 2, num / 2, prizes); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_guaranteed(N,P): assert P>0 if N==0 : return 0 total=2**N if P==total : return total-1 if 2*P<=total : return 0 tmp=get_guaranteed(N-1,P-total//2) return 2*tmp+2 def get_possible(N,P): assert P>0 if N==0 : return 0 total=2**N if P==total : return total-1 if P==total//2 : return total-2 if 2*P<=total : tmp=get_possible(N-1,P) return 2*tmp else : return total-2 T=int(input()) for t in range(1,T+1): N,P=[int(x)for x in input().split()] print("Case #{}:{}{}".format(t,get_guaranteed(N,P),get_possible(N,P))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(1, T + 1-1) do ( Sequence{N,P} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (StringLib.interpolateStrings("Case #{}:{}{}", Sequence{t, get_guaranteed(N, P), get_possible(N, P)}))->display()); operation get_guaranteed(N : OclAny, P : OclAny) : OclAny pre: true post: true activity: assert P > 0 do "assertion failed" ; if N = 0 then ( return 0 ) else skip ; var total : double := (2)->pow(N) ; if P = total then ( return total - 1 ) else skip ; if (2 * P->compareTo(total)) <= 0 then ( return 0 ) else skip ; var tmp : OclAny := get_guaranteed(N - 1, P - total div 2) ; return 2 * tmp + 2; operation get_possible(N : OclAny, P : OclAny) : OclAny pre: true post: true activity: assert P > 0 do "assertion failed" ; if N = 0 then ( return 0 ) else skip ; total := (2)->pow(N) ; if P = total then ( return total - 1 ) else skip ; if P = total div 2 then ( return total - 2 ) else skip ; if (2 * P->compareTo(total)) <= 0 then ( tmp := get_possible(N - 1, P) ; return 2 * tmp ) else ( return total - 2 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import* inf=open('B-large.in') ouf=open('output.txt','w') input=lambda : inf.readline().strip() print=partial(print,file=ouf) def solve(): n,p=map(int,input().split()) y=max(min(2**q-2,2**n-1)for q in range(1,n+2)if 2**n-2**(n-q+1)trim()) ; var print : OclAny := partial(print, (argument (test (logical_test (comparison (expr (atom (name file)))))) = (test (logical_test (comparison (expr (atom (name ouf)))))))) ; skip ; var tests : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for z : Integer.subrange(0, tests-1) do ( execute (StringLib.interpolateStrings("Case #{}: ", Sequence{z + 1}))->display() ; solve()) ; ouf.closeFile(); operation solve() pre: true post: true activity: var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var y : OclAny := ((argument (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (number (integer 2)))) ** (expr (atom (name q)))) - (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (expr (expr (atom (number (integer 2)))) ** (expr (atom (name n)))) - (expr (atom (number (integer 1)))))))))) ))))))) (comp_for for (exprlist (expr (atom (name q)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 2)))))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (expr (expr (atom (number (integer 2)))) ** (expr (atom (name n)))) - (expr (expr (atom (number (integer 2)))) ** (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name n))) - (expr (atom (name q)))) + (expr (atom (number (integer 1))))))))) )))))) < (comparison (expr (atom (name p)))))))))))->max() ; var z : OclAny := ((argument (test (logical_test (comparison (expr (expr (expr (atom (number (integer 2)))) ** (expr (atom (name n)))) - (expr (expr (atom (number (integer 2)))) ** (expr (atom (name q)))))))) (comp_for for (exprlist (expr (atom (name q)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (expr (expr (atom (number (integer 2)))) ** (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (name q)))))))) )))) - (expr (atom (number (integer 1)))))) < (comparison (expr (atom (name p)))))))))))->max() ; execute (y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() ANSlist=[] for i in range(len(S)): if S[i]=='0' : ANSlist.append('0') elif S[i]=='1' : ANSlist.append('1') elif S[i]=='B' : if len(ANSlist)>=1 : del ANSlist[-1] ANS=''.join(ANSlist) print(ANS) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var ANSlist : Sequence := Sequence{} ; for i : Integer.subrange(0, (S)->size()-1) do ( if S[i+1] = '0' then ( execute (('0') : ANSlist) ) else (if S[i+1] = '1' then ( execute (('1') : ANSlist) ) else (if S[i+1] = 'B' then ( if (ANSlist)->size() >= 1 then ( execute (ANSlist->last())->isDeleted() ) else skip ) else skip ) ) ) ; var ANS : String := StringLib.sumStringsWithSeparator((ANSlist), '') ; execute (ANS)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getNumber(n,k): if(n % 2==0): pos=n//2 ; else : pos=(n//2)+1 ; if(k<=pos): return(k*2-1); else : return((k-pos)*2); if __name__=="__main__" : n=8 ; k=5 ; print(getNumber(n,k)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 8; k := 5; ; execute (getNumber(n, k))->display(); ) else skip; operation getNumber(n : OclAny, k : OclAny) pre: true post: true activity: if (n mod 2 = 0) then ( var pos : int := n div 2; ) else ( pos := (n div 2) + 1; ) ; if ((k->compareTo(pos)) <= 0) then ( return (k * 2 - 1); ) else ( return ((k - pos) * 2); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def isCubeFree(n): if n==1 : return False for i in range(2,int(n**(1/3)+1)): if(n %(i*i*i)==0): return False ; return True ; def printCubeFree(n): for i in range(2,n+1): if(isCubeFree(i)): print(i,end=" ") n=20 printCubeFree(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 20 ; printCubeFree(n); operation isCubeFree(n : OclAny) : OclAny pre: true post: true activity: if n = 1 then ( return false ) else skip ; for i : Integer.subrange(2, ("" + (((n)->pow((1 / 3)) + 1)))->toInteger()-1) do ( if (n mod (i * i * i) = 0) then ( return false; ) else skip) ; return true;; operation printCubeFree(n : OclAny) pre: true post: true activity: for i : Integer.subrange(2, n + 1-1) do ( if (isCubeFree(i)) then ( execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def makeAndCheckString(words,str): n=len(words) first=second=False for i in range(n): if words[i]==str : return True if str[0]==words[i][1]: first=True if str[1]==words[i][0]: second=True if first and second : return True return False str='ya' words=['ah','oy','to','ha'] if makeAndCheckString(words,str): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclType["String"] := 'ya' ; words := Sequence{'ah'}->union(Sequence{'oy'}->union(Sequence{'to'}->union(Sequence{ 'ha' }))) ; if makeAndCheckString(words, OclType["String"]) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); operation makeAndCheckString(words : OclAny, OclType["String"] : OclAny) : OclAny pre: true post: true activity: var n : int := (words)->size() ; var first : OclAny := false; var second : boolean := false ; for i : Integer.subrange(0, n-1) do ( if words[i+1] = OclType["String"] then ( return true ) else skip ; if ("" + (->first())) = words[i+1][1+1] then ( first := true ) else skip ; if ("" + ([1+1])) = words[i+1]->first() then ( second := true ) else skip ; if first & second then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minSum(n): sum=0 ; while(n>0): sum+=(n % 10); n//=10 ; if(sum==1): return 10 ; return sum ; if __name__=="__main__" : n=1884 ; print(minSum(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 1884; ; execute (minSum(n))->display(); ) else skip; operation minSum(n : OclAny) pre: true post: true activity: var sum : int := 0; ; while (n > 0) do ( sum := sum + (n mod 10); ; n := n div 10;) ; if (sum = 1) then ( return 10; ) else skip ; return sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,k=map(int,input().split()) a=list(map(int,input().split())) if(n==1): print("Yes") continue if(n==k): m=a[0] else : if(a[0]>=0): m=(a[0]-1)//(n-k+1)+1 else : m=(a[0]-1)//(n-k+1)+1 fl=1 for i in range(1,k): if(a[i]-a[i-1]toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (n = 1) then ( execute ("Yes")->display() ; continue ) else skip ; if (n = k) then ( var m : OclAny := a->first() ) else ( if (a->first() >= 0) then ( m := (a->first() - 1) div (n - k + 1) + 1 ) else ( m := (a->first() - 1) div (n - k + 1) + 1 ) ) ; var fl : int := 1 ; for i : Integer.subrange(1, k-1) do ( if ((a[i+1] - a[i - 1+1]->compareTo(m)) < 0) then ( fl := 0 ; break ) else skip ; m := a[i+1] - a[i - 1+1]) ; if (fl) then ( execute ("Yes")->display() ) else ( execute ("No")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n,k=map(int,input().split()) sum=list(map(int,input().split())) num=[0]*n abc=sorted(sum) abcd=sorted(sum,reverse=True) if k==1 : print("YES") continue x=k-1 y=n-1 while(x>0): num[y]=sum[x]-sum[x-1] x-=1 y-=1 checksum=sum[0] y+=1 div=y mustmin=int(num[y]) flag=0 while(y0 : print("NO") continue else : if mustmin*div>=checksum : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sum : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var num : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var abc : Sequence := sum->sort() ; var abcd : Sequence := sum->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; if k = 1 then ( execute ("YES")->display() ; continue ) else skip ; var x : double := k - 1 ; var y : double := n - 1 ; while (x > 0) do ( num[y+1] := [x+1]->sum() - [x - 1+1]->sum() ; x := x - 1 ; y := y - 1) ; var checksum : OclAny := ->first()->sum() ; y := y + 1 ; var div : OclAny := y ; var mustmin : int := ("" + ((num[y+1])))->toInteger() ; var flag : int := 0 ; while ((y->compareTo(n - 1)) < 0) do ( if num[y + 1+1] - num[y+1] < 0 then ( flag := flag + 1 ) else skip ; y := y + 1) ; if flag > 0 then ( execute ("NO")->display() ; continue ) else ( if (mustmin * div->compareTo(checksum)) >= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math t=int(input()) for t1 in range(t): tmp=input().split() n=int(tmp[0]) k=int(tmp[1]) s=[int(x)for x in input().split()] a=[s[0]/(n-k+1)] ans="Yes" for i in range(1,k): a.append(s[i]-s[i-1]) if a[-1]toInteger() ; for t1 : Integer.subrange(0, t-1) do ( var tmp : OclAny := input().split() ; var n : int := ("" + ((tmp->first())))->toInteger() ; var k : int := ("" + ((tmp[1+1])))->toInteger() ; var s : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a : Sequence := Sequence{ s->first() / (n - k + 1) } ; var ans : String := "Yes" ; for i : Integer.subrange(1, k-1) do ( execute ((s[i+1] - s[i - 1+1]) : a) ; if (a->last()->compareTo(a->front()->last())) < 0 then ( ans := "No" ; break ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(*sorted(list(map(int,input().split())))[: :-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))))))) ))) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ]))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) a=[*map(int,input().split())] dif=a[0]//(n-k+1)+(1 if a[0]%(n-k+1)else 0) dif=[dif]+[x-y for x,y in zip(a[1 :],a[:-1])] print(['NO','YES'][dif==sorted(dif)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dif : int := a->first() div (n - k + 1) + (if a->first() mod (n - k + 1) then 1 else 0 endif) ; dif := Sequence{ dif }->union(Integer.subrange(1, a->tail()->size())->collect( _indx | Sequence{a->tail()->at(_indx), a->front()->at(_indx)} )->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (x - y))) ; execute (Sequence{'NO'}->union(Sequence{ 'YES' })->select(dif = dif->sort()))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,sys,io,math from tokenize import Triple from array import array from math import* I=lambda :[*map(int,sys.stdin.readline().split())] IS=lambda : input() IN=lambda : int(input()) IF=lambda : float(input()) a,b,c,d=IS(),IS(),IS(),IS() a+=b[: :-1] x="X" for i in range(4): if a[i]==x : a=a[: i]+a[i+1 :] break c+=d[: :-1] for i in range(4): if c[i]==x : c=c[: i]+c[i+1 :] break f=False for i in range(4): if a==c : f=True c=c[1 :]+c[0] print("YES" if f else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var I : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var IS : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var IN : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var IF : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toReal()) ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := Sequence{IS->apply(),IS->apply(),IS->apply(),IS->apply()} ; a := a + b(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var x : String := "X" ; for i : Integer.subrange(0, 4-1) do ( if a[i+1] = x then ( var a : OclAny := a.subrange(1,i) + a.subrange(i + 1+1) ; break ) else skip) ; c := c + d(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; for i : Integer.subrange(0, 4-1) do ( if c[i+1] = x then ( var c : OclAny := c.subrange(1,i) + c.subrange(i + 1+1) ; break ) else skip) ; var f : boolean := false ; for i : Integer.subrange(0, 4-1) do ( if a = c then ( f := true ) else skip ; c := c->tail() + c->first()) ; execute (if f then "YES" else "NO" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from collections import deque for _ in range(int(input())): n=int(input()) w=deque(map(int,input().split())) d=[] for i in range(n-1): c=min(range(n-i),key=lambda x : w[x]) w.rotate(-c) w.popleft() if c : d.append([i+1,n,c]) print(len(d)) for i in d : print(' '.join(map(str,i))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : Sequence := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( var c : OclAny := Set{Integer.subrange(0, n - i-1), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ]))))))))}->min() ; w.rotate(-c) ; w := w->tail() ; if c then ( execute ((Sequence{i + 1}->union(Sequence{n}->union(Sequence{ c }))) : d) ) else skip) ; execute ((d)->size())->display() ; for i : d do ( execute (StringLib.sumStringsWithSeparator(((i)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a1=str(input()) a2=str(input()) b1=str(input()) b2=str(input()) a1=list(a1) a2=list(a2) a2.reverse() a=a1+a2 b1=list(b1) b2=list(b2) b2.reverse() b=b1+b2 a="".join(a) b="".join(b) a=a.replace("X","") b=b.replace("X","") b=b*2 c=b.count(a) if c>0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a1 : String := ("" + (((OclFile["System.in"]).readLine()))) ; var a2 : String := ("" + (((OclFile["System.in"]).readLine()))) ; var b1 : String := ("" + (((OclFile["System.in"]).readLine()))) ; var b2 : String := ("" + (((OclFile["System.in"]).readLine()))) ; a1 := (a1)->characters() ; a2 := (a2)->characters() ; a2 := a2->reverse() ; var a : String := a1 + a2 ; b1 := (b1)->characters() ; b2 := (b2)->characters() ; b2 := b2->reverse() ; var b : String := b1 + b2 ; a := StringLib.sumStringsWithSeparator((a), "") ; b := StringLib.sumStringsWithSeparator((b), "") ; a := a.replace("X", "") ; b := b.replace("X", "") ; b := StringLib.nCopies(b, 2) ; var c : int := b->count(a) ; if c > 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline s1=input()[:-1] s2=input()[:-1] s3=input()[:-1] s4=input()[:-1] s=(s1+s2[: :-1]).replace('X','') w=(s3+s4[: :-1]).replace('X','') for i in range(3): if s[0]!='A' : s=s[1 :]+s[0] else : break for i in range(3): if w[0]!='A' : w=w[1 :]+w[0] else : break print('YES' if s==w else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var s1 : OclAny := input()->front() ; var s2 : OclAny := input()->front() ; var s3 : OclAny := input()->front() ; var s4 : OclAny := input()->front() ; var s : String := (s1 + s2(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))).replace('X', '') ; var w : String := (s3 + s4(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))).replace('X', '') ; for i : Integer.subrange(0, 3-1) do ( if s->first() /= 'A' then ( s := s->tail() + s->first() ) else ( break )) ; for i : Integer.subrange(0, 3-1) do ( if w->first() /= 'A' then ( w := w->tail() + w->first() ) else ( break )) ; execute (if s = w then 'YES' else 'NO' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=[] b=[] for i in range(2): l+=list(map(str,input())) for i in range(2): b+=list(map(str,input())) for i in[l,b]: if i.index("X")<2 : in1=i.index("X") in2=(i.index("X")+2)% 4 i[in1],i[in2]=i[in2],i[in1] i.remove("X") if l[(l.index("A")+1)% 3]==b[(b.index("A")+1)% 3]: print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; for i : Integer.subrange(0, 2-1) do ( l := l + (((OclFile["System.in"]).readLine())->collect( _x | (OclType["String"])->apply(_x) ))) ; for i : Integer.subrange(0, 2-1) do ( b := b + (((OclFile["System.in"]).readLine())->collect( _x | (OclType["String"])->apply(_x) ))) ; for i : Sequence{l}->union(Sequence{ b }) do ( if i->indexOf("X") - 1 < 2 then ( var in1 : int := i->indexOf("X") - 1 ; var in2 : int := (i->indexOf("X") - 1 + 2) mod 4 ; var i[in1+1] : OclAny := null; var i[in2+1] : OclAny := null; Sequence{i[in1+1],i[in2+1]} := Sequence{i[in2+1],i[in1+1]} ) else skip ; execute (("X") /: i)) ; if l[(l->indexOf("A") - 1 + 1) mod 3+1] = b[(b->indexOf("A") - 1 + 1) mod 3+1] then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- B_0=str(input().strip('\n')) B_1=str(input().strip('\n')) B=list(B_0)+list(B_1[: :-1]) E_0=str(input().strip('\n')) E_1=str(input().strip('\n')) E=list(E_0)+list(E_1[: :-1]) B.remove("X") E.remove("X") def main(): for i in range(3): if B==E : return "YES" else : tmp=B.pop(0) B.append(tmp) return "NO" print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var B_0 : String := ("" + ((input()->trim()))) ; var B var B_0 : String := ("" + ((input()->trim()))) : String := ("" + ((input()->trim()))) ; var B : Sequence := (B_0)->characters()->union((B var B_0 : String := ("" + ((input()->trim())))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))) ; var E_0 : String := ("" + ((input()->trim()))) ; var E var B_0 : String := ("" + ((input()->trim()))) : String := ("" + ((input()->trim()))) ; var E : Sequence := (E_0)->characters()->union((E var B_0 : String := ("" + ((input()->trim())))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))) ; execute (("X") /: B) ; execute (("X") /: E) ; skip ; execute (main())->display(); operation main() : OclAny pre: true post: true activity: for i : Integer.subrange(0, 3-1) do ( if B = E then ( return "YES" ) else ( var tmp : OclAny := B->at(0`firstArg+1) ; B := B->excludingAt(0+1) ; execute ((tmp) : B) )) ; return "NO"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,k): if(n>=(k*(k+1))//2): return True return False if __name__=='__main__' : n=12 k=4 if(solve(n,k)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 12 ; k := 4 ; if (solve(n, k)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation solve(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if ((n->compareTo((k * (k + 1)) div 2)) >= 0) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n): if(n==1): print(-1); else : num=2 ; for i in range(n-1): num=(num*10)+3 ; print(num); if __name__=="__main__" : n=4 ; solve(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 4; ; solve(n); ) else skip; operation solve(n : OclAny) pre: true post: true activity: if (n = 1) then ( execute (-1)->display(); ) else ( var num : int := 2; ; for i : Integer.subrange(0, n - 1-1) do ( num := (num * 10) + 3;) ; execute (num)->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def largestNumber(n): s="" duplicate=n while(n>0): s=chr(n % 10+48)+s n=n//10 index=-1 for i in range(len(s)): if((ord(s[i])-ord('0'))% 2 & 1): index=i break if(index==-1): return duplicate num=0 for i in range(index): num=num*10+(ord(s[i])-ord('0')) num=num*10+(ord(s[index])-ord('0')-1) for i in range(index+1,len(s)): num=num*10+8 return num N=24578 print(largestNumber(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := 24578 ; execute (largestNumber(N))->display(); operation largestNumber(n : OclAny) : OclAny pre: true post: true activity: var s : String := "" ; var duplicate : OclAny := n ; while (n > 0) do ( s := (n mod 10 + 48)->byte2char() + s ; n := n div 10) ; var index : int := -1 ; for i : Integer.subrange(0, (s)->size()-1) do ( if (MathLib.bitwiseAnd(((s[i+1])->char2byte() - ('0')->char2byte()) mod 2, 1)) then ( index := i ; break ) else skip) ; if (index = -1) then ( return duplicate ) else skip ; var num : int := 0 ; for i : Integer.subrange(0, index-1) do ( num := num * 10 + ((s[i+1])->char2byte() - ('0')->char2byte())) ; num := num * 10 + ((s[index+1])->char2byte() - ('0')->char2byte() - 1) ; for i : Integer.subrange(index + 1, (s)->size()-1) do ( num := num * 10 + 8) ; return num; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def largestNumber(n): s="" duplicate=n while(n): s=chr(n % 10+48)+s n//=10 index=-1 for i in range(len(s)): if(((ord(s[i])-ord('0'))% 2 & 1)==0): index=i break if(index==-1): return duplicate num=0 for i in range(index): num=num*10+(ord(s[i])-ord('0')) num=num*10+(ord(s[index])-ord('0')-1) for i in range(index+1,len(s)): num=num*10+9 return num N=24578 print(largestNumber(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 24578 ; execute (largestNumber(N))->display(); operation largestNumber(n : OclAny) : OclAny pre: true post: true activity: var s : String := "" ; var duplicate : OclAny := n ; while (n) do ( s := (n mod 10 + 48)->byte2char() + s ; n := n div 10) ; var index : int := -1 ; for i : Integer.subrange(0, (s)->size()-1) do ( if ((MathLib.bitwiseAnd(((s[i+1])->char2byte() - ('0')->char2byte()) mod 2, 1)) = 0) then ( index := i ; break ) else skip) ; if (index = -1) then ( return duplicate ) else skip ; var num : int := 0 ; for i : Integer.subrange(0, index-1) do ( num := num * 10 + ((s[i+1])->char2byte() - ('0')->char2byte())) ; num := num * 10 + ((s[index+1])->char2byte() - ('0')->char2byte() - 1) ; for i : Integer.subrange(index + 1, (s)->size()-1) do ( num := num * 10 + 9) ; return num; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil,sqrt def FermatFactors(n): if(n<=0): return[n] if(n & 1)==0 : return[n/2,2] a=ceil(sqrt(n)) if(a*a==n): return[a,a] while(True): b1=a*a-n b=int(sqrt(b1)) if(b*b==b1): break else : a+=1 return[a-b,a+b] print(FermatFactors(6557)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; execute (FermatFactors(6557))->display(); operation FermatFactors(n : OclAny) : OclAny pre: true post: true activity: if (n <= 0) then ( return Sequence{ n } ) else skip ; if (MathLib.bitwiseAnd(n, 1)) = 0 then ( return Sequence{n / 2}->union(Sequence{ 2 }) ) else skip ; var a : OclAny := ceil(sqrt(n)) ; if (a * a = n) then ( return Sequence{a}->union(Sequence{ a }) ) else skip ; while (true) do ( var b1 : double := a * a - n ; var b : int := ("" + ((sqrt(b1))))->toInteger() ; if (b * b = b1) then ( break ) else ( a := a + 1 )) ; return Sequence{a - b}->union(Sequence{ a + b }); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def smallestNumber(n): num=0 s="" duplicate=n while(n): s=chr(n % 10+48)+s n//=10 index=-1 for i in range(len(s)): digit=ord(s[i])-ord('0') if((digit & 1)==0): index=i break if(index==-1): return duplicate for i in range(index): num=num*10+(ord(s[i])-ord('0')) num=num*10+(ord(s[index])-ord('0')+1) for i in range(index+1,len(s)): num=num*10+1 return num if __name__=="__main__" : N=2397 print(smallestNumber(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var N : int := 2397 ; execute (smallestNumber(N))->display() ) else skip; operation smallestNumber(n : OclAny) : OclAny pre: true post: true activity: var num : int := 0 ; var s : String := "" ; var duplicate : OclAny := n ; while (n) do ( s := (n mod 10 + 48)->byte2char() + s ; n := n div 10) ; var index : int := -1 ; for i : Integer.subrange(0, (s)->size()-1) do ( var digit : double := (s[i+1])->char2byte() - ('0')->char2byte() ; if ((MathLib.bitwiseAnd(digit, 1)) = 0) then ( index := i ; break ) else skip) ; if (index = -1) then ( return duplicate ) else skip ; for i : Integer.subrange(0, index-1) do ( num := num * 10 + ((s[i+1])->char2byte() - ('0')->char2byte())) ; num := num * 10 + ((s[index+1])->char2byte() - ('0')->char2byte() + 1) ; for i : Integer.subrange(index + 1, (s)->size()-1) do ( num := num * 10 + 1) ; return num; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sam=input() red=[] for i in sam : if i=="B" : if red : del red[-1] else : red.append(i) print(*red,sep="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sam : String := (OclFile["System.in"]).readLine() ; var red : Sequence := Sequence{} ; for i : sam->characters() do ( if i = "B" then ( if red then ( execute (red->last())->isDeleted() ) else skip ) else ( execute ((i) : red) )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name red))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count(n): x=(n//3)-1 ; if(n % 3>0): x+=1 ; return(4*x+4*n); if __name__=='__main__' : n=5 ; print(count(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 5; ; execute (count(n))->display(); ) else skip; operation count(n : OclAny) pre: true post: true activity: var x : double := (n div 3) - 1; ; if (n mod 3 > 0) then ( x := x + 1; ) else skip ; return (4 * x + 4 * n);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys if(len(sys.argv)<2): print("No file specified") sys.exit(1) infile=open(sys.argv[1]) outfile=open(sys.argv[1]+".out","w") num_cases=int(infile.readline().strip()) for case in range(1,num_cases+1): n,k,b,t=map(int,infile.readline().split()) positions=map(int,infile.readline().split()) speeds=map(int,infile.readline().split()) positions.reverse() speeds.reverse() swaps=0 chick_idx=0 found_completers=0 while chick_idx=(b-positions[chick_idx]): swaps+=chick_idx-found_completers found_completers+=1 chick_idx+=1 if found_completerssize() < 2) then ( execute ("No file specified")->display() ; sys.exit(1) ) else skip ; var infile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) ; var outfile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) + ".out")) ; var num_cases : int := ("" + ((infile.readLine()->trim())))->toInteger() ; for case : Integer.subrange(1, num_cases + 1-1) do ( var n : OclAny := null; var k : OclAny := null; var b : OclAny := null; var t : OclAny := null; Sequence{n,k,b,t} := (infile.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var positions : Sequence := (infile.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var speeds : Sequence := (infile.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; positions := positions->reverse() ; speeds := speeds->reverse() ; var swaps : int := 0 ; var chick_idx : int := 0 ; var found_completers : int := 0 ; while (chick_idx->compareTo(n)) < 0 & (found_completers->compareTo(k)) < 0 do ( if (speeds[chick_idx+1] * t->compareTo((b - positions[chick_idx+1]))) >= 0 then ( swaps := swaps + chick_idx - found_completers ; found_completers := found_completers + 1 ) else skip ; chick_idx := chick_idx + 1) ; if (found_completers->compareTo(k)) < 0 then ( var result : String := "IMPOSSIBLE" ) else ( result := StringLib.format("%d",swaps) ) ; outfile.write(StringLib.format("Case #%d: %s\n",Sequence{case, result})) ; if case mod 100 = 0 then ( execute (StringLib.format("Completed case %d",case))->display() ) else skip) ; outfile.closeFile() ; infile.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : inFile=open("B-large.in","r") outFile=open("practice.out","w") caseNum=int(inFile.readline()) for i in xrange(1,caseNum+1): rtv=0 N,K,B,T=tuple(map(int,inFile.readline().strip().split())) X=map(int,inFile.readline().strip().split()) V=map(int,inFile.readline().strip().split()) tc=[] for j in range(N): tmp_t=(B-X[j])/float(V[j]) tc.append((B-X[j])/float(V[j])) rtv=0 fg=0 lg=0 for j in range(N): h=N-j-1 if tc[h]>T : lg+=1 else : fg+=1 rtv+=lg if fg>=K : break if fgtoInteger() ; for i : xrange(1, caseNum + 1) do ( var rtv : int := 0 ; var N : OclAny := null; var K : OclAny := null; var B : OclAny := null; var T : OclAny := null; Sequence{N,K,B,T} := ((inFile.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var X : Sequence := (inFile.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var V : Sequence := (inFile.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var tc : Sequence := Sequence{} ; for j : Integer.subrange(0, N-1) do ( var tmp_t : double := (B - X[j+1]) / ("" + ((V[j+1])))->toReal() ; execute (((B - X[j+1]) / ("" + ((V[j+1])))->toReal()) : tc)) ; rtv := 0 ; var fg : int := 0 ; var lg : int := 0 ; for j : Integer.subrange(0, N-1) do ( var h : double := N - j - 1 ; if (tc[h+1]->compareTo(T)) > 0 then ( lg := lg + 1 ) else ( fg := fg + 1 ; rtv := rtv + lg ; if (fg->compareTo(K)) >= 0 then ( break ) else skip )) ; if (fg->compareTo(K)) < 0 then ( outFile.write(StringLib.format("Case #%d: IMPOSSIBLE\n",Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) ,)})) ) else ( outFile.write(StringLib.format("Case #%d: %d\n",Sequence{i, rtv})) )) ; outFile.closeFile() ; inFile.closeFile() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout C=int(stdin.readline()) for x in range(1,C+1): (N,K,B,T)=map(int,stdin.readline().split()) Xi=map(int,stdin.readline().split()) Vi=map(int,stdin.readline().split()) assert(len(Xi)==len(Vi)==N) i=0 S=0 while i=B : break if Xi[j]+Vi[j]*TtoInteger() ; for x : Integer.subrange(1, C + 1-1) do ( ; var Sequence{N, K, B, T} : Sequence := (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var Xi : Sequence := (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var Vi : Sequence := (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; assert ((Xi)->size() = (Vi)->size() & ((Vi)->size() == N)) do "assertion failed" ; var i : int := 0 ; var S : int := 0 ; while (i->compareTo(K)) < 0 do ( var k : double := N - i - 1 ; for j : Integer.subrange(-1 + 1, k)->reverse() do ( if (Xi[j+1] + Vi[j+1] * T->compareTo(B)) >= 0 then ( break ) else skip) ; if (Xi[j+1] + Vi[j+1] * T->compareTo(B)) < 0 then ( break ) else skip)) ; Sequence{Xi[k+1], Xi[j+1], Vi[k+1], Vi[j+1]} := Sequence{Xi[j+1], Xi[k+1], Vi[j+1], Vi[k+1]}; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline N,M=map(int,input().split()) u=[[]for i in range(N-1)] for i in range(M): s,t=map(int,input().split()) u[s-1].append(t-1) p=[0]*N p[0]=1 for x,y in enumerate(u): for z in y : p[z]+=p[x]/len(y) q=[0]*N q[N-1]=0 for x,y in list(enumerate(u))[: :-1]: q[x]=sum(q[z]for z in y)/len(y)+1 v=[0]*N for i in range(N-1): a=len(u[i]) if a>1 : b=max(q[c]for c in u[i]) v[i]=p[i]*(q[i]-(1+b))/(a-1) print(q[0]+min(v)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var u : Sequence := Integer.subrange(0, N - 1-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, M-1) do ( var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name u)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name s))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name t))) - (expr (atom (number (integer 1)))))))))) ))))) ; var p : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; p->first() := 1 ; for _tuple : Integer.subrange(1, (u)->size())->collect( _indx | Sequence{_indx-1, (u)->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); for z : y do ( p[z+1] := p[z+1] + p[x+1] / (y)->size())) ; var q : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; q[N - 1+1] := 0 ; for _tuple : OclType["Sequence"](Integer.subrange(1, (u)->size())->collect( _indx | Sequence{_indx-1, (u)->at(_indx)} ))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); q[x+1] := ((argument (test (logical_test (comparison (expr (atom (name q)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name z)))))))) ])))))) (comp_for for (exprlist (expr (atom (name z)))) in (logical_test (comparison (expr (atom (name y))))))))->sum() / (y)->size() + 1) ; var v : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for i : Integer.subrange(0, N - 1-1) do ( var a : int := (u[i+1])->size() ; if a > 1 then ( var b : OclAny := ((argument (test (logical_test (comparison (expr (atom (name q)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name c)))))))) ])))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name u)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))->max() ; v[i+1] := p[i+1] * (q[i+1] - (1 + b)) / (a - 1) ) else skip) ; execute (q->first() + (v)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math N,M=[int(x)for x in input().split()] edges=[[int(x)for x in input().split()]for _ in range(M)] forward_edges={n+1 :[]for n in range(N)} reverse_edges={n+1 :[]for n in range(N)} for e in edges : forward_edges[e[0]].append(e[1]) reverse_edges[e[1]].append(e[0]) estimated_distance={n+1 : None for n in range(N)} estimated_distance[N]=0 probability={n+1 : None for n in range(N)} probability[1]=1 def get_probability(n): if probability[n]is not None : return probability[n] prob=0 for m in reverse_edges[n]: prob+=get_probability(m)/len(forward_edges[m]) probability[n]=prob return prob def get_distance(n): if estimated_distance[n]is not None : return estimated_distance[n] total_distance=0 for m in forward_edges[n]: total_distance+=get_distance(m) estimated_distance[n]=1+total_distance/len(forward_edges[n]) return estimated_distance[n] before_distance=get_distance(1) max_decrease=0 for n in range(1,N): if len(forward_edges[n])==1 : continue distances=[get_distance(m)for m in forward_edges[n]] distance_diff=sum(distances)/len(distances)-(sum(distances)-max(distances))/(len(distances)-1) decrease=get_probability(n)*distance_diff max_decrease=max(max_decrease,decrease) print(before_distance-max_decrease) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var edges : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))) ; var forward_edges : Map := Integer.subrange(0, N-1)->select(n | true)->collect(n | Map{n + 1 |-> Sequence{}})->unionAll() ; var reverse_edges : Map := Integer.subrange(0, N-1)->select(n | true)->collect(n | Map{n + 1 |-> Sequence{}})->unionAll() ; for e : edges do ((expr (atom (name forward_edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))) ; (expr (atom (name reverse_edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))) ; var estimated_distance : Map := Integer.subrange(0, N-1)->select(n | true)->collect(n | Map{n + 1 |-> null})->unionAll() ; estimated_distance[N+1] := 0 ; var probability : Map := Integer.subrange(0, N-1)->select(n | true)->collect(n | Map{n + 1 |-> null})->unionAll() ; probability[1+1] := 1 ; skip ; skip ; var before_distance : OclAny := get_distance(1) ; var max_decrease : int := 0 ; for n : Integer.subrange(1, N-1) do ( if (forward_edges[n+1])->size() = 1 then ( continue ) else skip ; var distances : Sequence := forward_edges[n+1]->select(m | true)->collect(m | (get_distance(m))) ; var distance_diff : double := (distances)->sum() / (distances)->size() - ((distances)->sum() - (distances)->max()) / ((distances)->size() - 1) ; var decrease : double := get_probability(n) * distance_diff ; max_decrease := Set{max_decrease, decrease}->max()) ; execute (before_distance - max_decrease)->display(); operation get_probability(n : OclAny) : OclAny pre: true post: true activity: if not(probability[n+1] <>= null) then ( return probability[n+1] ) else skip ; var prob : int := 0 ; for m : reverse_edges[n+1] do ( prob := prob + get_probability(m) / (forward_edges[m+1])->size()) ; probability[n+1] := prob ; return prob; operation get_distance(n : OclAny) : OclAny pre: true post: true activity: if not(estimated_distance[n+1] <>= null) then ( return estimated_distance[n+1] ) else skip ; var total_distance : int := 0 ; for m : forward_edges[n+1] do ( total_distance := total_distance + get_distance(m)) ; estimated_distance[n+1] := 1 + total_distance / (forward_edges[n+1])->size() ; return estimated_distance[n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines n,m=map(int,readline().split()) M=map(int,read().split()) edges=zip(M,M) edges_from=[[]for _ in range(n)] edges_to=[[]for _ in range(n)] for _from,to in edges : edges_from[_from-1].append(to-1) E_dist_to_goal=[0]*n P_of_reaching=[0]*n P_of_reaching[0]=1 for v in range(n-2,-1,-1): routes=edges_from[v] for next_v in routes : E_dist_to_goal[v]+=E_dist_to_goal[next_v]+1 E_dist_to_goal[v]/=len(routes) for v in range(n-1): P_now=P_of_reaching[v] routes=edges_from[v] P_next=P_now/len(routes) for next_v in routes : P_of_reaching[next_v]+=P_next initial_ans=E_dist_to_goal[0] cut=0 for v in range(n-2): routes=edges_from[v] num_of_routes=len(routes) if num_of_routes==1 : continue not_cut_dist=E_dist_to_goal[v] longest_dist=max([E_dist_to_goal[next_v]+1 for next_v in routes]) after_cut_dist=(not_cut_dist-longest_dist/num_of_routes)*num_of_routes/(num_of_routes-1) delta=(not_cut_dist-after_cut_dist)*P_of_reaching[v] cut=max(cut,delta) ans=initial_ans-cut print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var M : Sequence := (read().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var edges : Sequence := Integer.subrange(1, M->size())->collect( _indx | Sequence{M->at(_indx), M->at(_indx)} ) ; var edges_from : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var edges_to : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _tuple : edges do (var _indx : int := 1; var _from : OclAny := _tuple->at(_indx); _indx := _indx + 1; var to : OclAny := _tuple->at(_indx); (expr (atom (name edges_from)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name _from))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name to))) - (expr (atom (number (integer 1)))))))))) ))))) ; var E_dist_to_goal : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var P_of_reaching : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; P_of_reaching->first() := 1 ; for v : Integer.subrange(-1 + 1, n - 2)->reverse() do ( var routes : OclAny := edges_from[v+1] ; for next_v : routes do ( E_dist_to_goal[v+1] := E_dist_to_goal[v+1] + E_dist_to_goal[next_v+1] + 1) ; E_dist_to_goal[v+1] := E_dist_to_goal[v+1] / (routes)->size()) ; for v : Integer.subrange(0, n - 1-1) do ( var P_now : OclAny := P_of_reaching[v+1] ; routes := edges_from[v+1] ; var P_next : double := P_now / (routes)->size() ; for next_v : routes do ( P_of_reaching[next_v+1] := P_of_reaching[next_v+1] + P_next)) ; var initial_ans : OclAny := E_dist_to_goal->first() ; var cut : int := 0 ; for v : Integer.subrange(0, n - 2-1) do ( routes := edges_from[v+1] ; var num_of_routes : int := (routes)->size() ; if num_of_routes = 1 then ( continue ) else skip ; var not_cut_dist : OclAny := E_dist_to_goal[v+1] ; var longest_dist : OclAny := (routes->select(next_v | true)->collect(next_v | (E_dist_to_goal[next_v+1] + 1)))->max() ; var after_cut_dist : double := (not_cut_dist - longest_dist / num_of_routes) * num_of_routes / (num_of_routes - 1) ; var delta : double := (not_cut_dist - after_cut_dist) * P_of_reaching[v+1] ; cut := Set{cut, delta}->max()) ; var ans : double := initial_ans - cut ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (n,m),*d=[list(map(int,s.split()))for s in open(0)] d.sort() for i in range(m): d[i]=[d[i][0]-1,d[i][1]-1] l=[0]*n for x in d : l[x[0]]+=1 p=[0]*n p[0]=1 for x in d : p[x[1]]+=p[x[0]]/l[x[0]] e=[0]*n index=d[-1][0] max_in_index=0 max_reduce_e=0 for x in d[: :-1]+[[-1,-1]]: if index!=x[0]: if l[index]>1 : max_reduce_e=max(max_reduce_e,p[index]*(e[index]/l[index]-(e[index]-max_in_index)/(l[index]-1))) e[index]/=l[index] index=x[0] max_in_index=0 if index==-1 : break max_in_index=max(max_in_index,e[x[1]]+1) e[x[0]]+=e[x[1]]+1 print(e[0]-max_reduce_e) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{n, m} : OclAny := null; var d : OclAny := null; Sequence{Sequence{n, m},d} := OclFile.newOclFile_Write(OclFile.newOclFile(0))->select(s | true)->collect(s | (((s.split())->collect( _x | (OclType["int"])->apply(_x) )))) ; d := d->sort() ; for i : Integer.subrange(0, m-1) do ( d[i+1] := Sequence{d[i+1]->first() - 1}->union(Sequence{ d[i+1][1+1] - 1 })) ; var l : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for x : d do ( l[x->first()+1] := l[x->first()+1] + 1) ; var p : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; p->first() := 1 ; for x : d do ( p[x[1+1]+1] := p[x[1+1]+1] + p[x->first()+1] / l[x->first()+1]) ; var e : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var index : OclAny := d->last()->first() ; var max_in_index : int := 0 ; var max_reduce_e : int := 0 ; for x : d(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->union(Sequence{ Sequence{-1}->union(Sequence{ -1 }) }) do ( if index /= x->first() then ( if l[index+1] > 1 then ( max_reduce_e := Set{max_reduce_e, p[index+1] * (e[index+1] / l[index+1] - (e[index+1] - max_in_index) / (l[index+1] - 1))}->max() ) else skip ; e[index+1] := e[index+1] / l[index+1] ; index := x->first() ; max_in_index := 0 ; if index = -1 then ( break ) else skip ) else skip ; max_in_index := Set{max_in_index, e[x[1+1]+1] + 1}->max() ; e[x->first()+1] := e[x->first()+1] + e[x[1+1]+1] + 1) ; execute (e->first() - max_reduce_e)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**7) inf=float('inf') def main(n,m,g,uv): eary=[inf]*m vary=[inf]*n vary[-1]=0 todo=[n-1] def dfs(v,x): if vary[v]1 and bary[v]: ary[i]=max(0,e-(e*k-eary[i])/(k-1)) ary[i]*=bary[v] return e0-max(0,max(ary)) n,m=map(int,input().split()) uv=[list(map(int,input().split()))for _ in range(m)] g=[[]for _ in range(n)] for i,(u,v)in enumerate(uv): u,v=u-1,v-1 g[u].append((i,v)) print(main(n,m,g,uv)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; skip ; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; uv := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; g := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _tuple : Integer.subrange(1, (uv)->size())->collect( _indx | Sequence{_indx-1, (uv)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{u, v} : OclAny := _tuple->at(_indx); var u : OclAny := null; Sequence{u,v} := Sequence{u - 1,v - 1} ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) , (test (logical_test (comparison (expr (atom (name v))))))) )))))))) ))))) ; execute (main(n, m, g, uv))->display(); operation main(n : OclAny, m : OclAny, g : OclAny, uv : OclAny) : OclAny pre: true post: true activity: var eary : Sequence := MatrixLib.elementwiseMult(Sequence{ Math_PINFINITY }, m) ; var vary : Sequence := MatrixLib.elementwiseMult(Sequence{ Math_PINFINITY }, n) ; vary->last() := 0 ; var todo : Sequence := Sequence{ n - 1 } ; skip ; var e0 : OclAny := dfs(0, -1) ; var ary : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, m) ; var bary : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; bary->first() := 1 ; for v : Integer.subrange(0, n-1) do ( var k : int := (g[v+1])->size() ; var e : OclAny := vary[v+1] ; for _tuple : g[v+1] do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var nv : OclAny := _tuple->at(_indx); bary[nv+1] := bary[nv+1] + 1 / k * bary[v+1] ; if k > 1 & bary[v+1] then ( ary[i+1] := Set{0, e - (e * k - eary[i+1]) / (k - 1)}->max() ; ary[i+1] := ary[i+1] * bary[v+1] ) else skip)) ; return e0 - Set{0, (ary)->max()}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- towr=[] res=[] while True : Str=input() if Str=="quit" : break elif Str=="pop" : res.append(towr.pop()) else : odr,clo=Str.split() towr.append(clo) for i in res : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var towr : Sequence := Sequence{} ; var res : Sequence := Sequence{} ; while true do ( var Str : String := (OclFile["System.in"]).readLine() ; if Str = "quit" then ( break ) else (if Str = "pop" then ( execute ((towr->last()) : res) ) else ( var odr : OclAny := null; var clo : OclAny := null; Sequence{odr,clo} := Str.split() ; execute ((clo) : towr) ) ) ) ; for i : res do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(str(input())) kekka=[] for i in range(len(s)): if s[0]=="B" : pass if s[i]=="B" : if not kekka==[]: kekka.pop() else : kekka.append(s[i]) print(''.join(kekka)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := (("" + (((OclFile["System.in"]).readLine()))))->characters() ; var kekka : Sequence := Sequence{} ; for i : Integer.subrange(0, (s)->size()-1) do ( if s->first() = "B" then ( skip ) else skip ; if s[i+1] = "B" then ( if not(kekka = Sequence{}) then ( kekka := kekka->front() ) else skip ) else ( execute ((s[i+1]) : kekka) )) ; execute (StringLib.sumStringsWithSeparator((kekka), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def longestPrefixSuffix(s): n=len(s) for res in range(n//2,0,-1): prefix=s[0 : res] suffix=s[n-res : n] if(prefix==suffix): return res return 0 s="blablabla" print(longestPrefixSuffix(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := "blablabla" ; execute (longestPrefixSuffix(s))->display(); operation longestPrefixSuffix(s : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; for res : Integer.subrange(0 + 1, n div 2)->reverse() do ( var prefix : OclAny := s.subrange(0+1, res) ; var suffix : OclAny := s.subrange(n - res+1, n) ; if (prefix = suffix) then ( return res ) else skip) ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : N=input() if not N : break a,b=-1,100000000 for j in range(N): i,h,w=map(int,raw_input().split()) h/=100.00 bmi=w/(h*h) if abs(bmi-22)collect( _x | (OclType["int"])->apply(_x) ) ; h := h / 100.00 ; var bmi : double := w / (h * h) ; if ((bmi - 22)->abs()->compareTo(b)) < 0 then ( var b : double := (bmi - 22)->abs() ; var a : OclAny := i ) else skip) ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def BMI(height,weight): return weight/(height/100)**2 STANDARD_VALUE=22 while True : input_count=int(input()) if input_count==0 : break input_data=[map(int,input().split(" "))for _ in range(input_count)] data=[(number,BMI(height,weight))for number,height,weight in input_data] data=[(number,abs(bmi-STANDARD_VALUE))for number,bmi in data] data.sort(key=lambda item :(item[1],item[0])) print(data[0][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var STANDARD_VALUE : int := 22 ; while true do ( var input_count : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if input_count = 0 then ( break ) else skip ; var input_data : Sequence := Integer.subrange(0, input_count-1)->select(_anon | true)->collect(_anon | ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ))) ; var data : Sequence := input_data->select(_tuple | true)->collect(_tuple | let number : OclAny = _tuple->at(1) in let height : OclAny = _tuple->at(2) in (Sequence{number, BMI(height, weight)})) ; data := data->select(_tuple | true)->collect(_tuple | let number : OclAny = _tuple->at(1) in let bmi : OclAny = _tuple->at(2) in (Sequence{number, (bmi - STANDARD_VALUE)->abs()})) ; data := data->sort() ; execute (data->first()->first())->display()); operation BMI(height : OclAny, weight : OclAny) : OclAny pre: true post: true activity: return weight / ((height / 100))->pow(2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy from test.support import _MemoryWatchdog BIG_NUM=2000000000 HUGE_NUM=99999999999999999 MOD=1000000007 EPS=0.000000001 sys.setrecursionlimit(100000) def gcd(x,y): x=abs(x) y=abs(y) if xexists( _x | result = _x ); attribute numerator : OclAny := arg_numerator; attribute denominator : OclAny := arg_denominator; operation initialise(arg_numerator : OclAny,arg_denominator : OclAny) : Info pre: true post: true activity: self.numerator := arg_numerator ; self.denominator := arg_denominator; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var HUGE_NUM : int := 99999999999999999 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; sys.setrecursionlimit(100000) ; skip ; skip ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var ans : int := -1 ; var info : Info := (Info.newInfo()).initialise(1000, 1) ; for i : Integer.subrange(0, N-1) do ( var ID : OclAny := null; var height : OclAny := null; var weight : OclAny := null; Sequence{ID,height,weight} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; height := height * height ; weight := weight * 10000 ; var common : OclAny := gcd(height, weight) ; height := height div common ; weight := weight div common ; var numerator : double := (22 * height - weight)->abs() ; var denominator : OclAny := height ; if (numerator * info.denominator->compareTo(info.numerator * denominator)) < 0 then ( ans := ID ; info.numerator := numerator ; info.denominator := denominator ) else skip) ; execute (StringLib.format("%d",(ans)))->display()); operation gcd(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: x := (x)->abs() ; y := (y)->abs() ; if (x->compareTo(y)) < 0 then ( Sequence{x,y} := Sequence{y,x} ) else skip ; if y = 0 then ( return x ) else ( return gcd(y, x mod y) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline from collections import namedtuple bmi=namedtuple('bmi',['d','p']) def calc_BMI(h,w): return w/((h/100)**2) def main(args): while True : n=int(input()) if n==0 : break scores=[] for _ in range(n): p,h,w=map(int,input().split()) scores.append(bmi(abs(calc_BMI(h,w)-22),p)) scores.sort() print(scores[0].p) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; var bmi : OclAny := namedtuple('bmi', Sequence{'d'}->union(Sequence{ 'p' })) ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation calc_BMI(h : OclAny, w : OclAny) : OclAny pre: true post: true activity: return w / (((h / 100))->pow(2)); operation main(args : OclAny) pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var scores : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var p : OclAny := null; Sequence{p,h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((bmi((calc_BMI(h, w) - 22)->abs(), p)) : scores)) ; scores := scores->sort() ; execute (scores->first().p)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- GOAL=22.0 EPS=1e-5 while True : n=int(input()) if n==0 : break id,vmin=0,1000000000.0 ; for i in range(n): p,h,w=list(map(int,input().split())) bmi=w/(h/100)**2 diff=abs(bmi-GOAL) if abs(diff-vmin)toReal() ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var id : OclAny := null; var vmin : OclAny := null; Sequence{id,vmin} := Sequence{0,1000000000.0}; ; for i : Integer.subrange(0, n-1) do ( var p : OclAny := null; var h : OclAny := null; var w : OclAny := null; Sequence{p,h,w} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var bmi : double := w / ((h / 100))->pow(2) ; var diff : double := (bmi - GOAL)->abs() ; if ((diff - vmin)->abs()->compareTo(EPS)) < 0 then ( if (p->compareTo(id)) < 0 then ( var id : OclAny := p ) else skip ) else (if (diff->compareTo(vmin)) < 0 then ( var vmin : OclAny := null; Sequence{id,vmin} := Sequence{p,diff} ) else skip)) ; execute (id)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cumm(x,y,cummx,cummy,cummx2,cummy2,n): for i in range(1,n+1): cummx[i]=cummx[i-1]+x[i] cummy[i]=cummy[i-1]+y[i] cummx2[i]=cummx2[i-1]+x[i]*x[i] cummy2[i]=cummy2[i-1]+y[i]*y[i] def calHammeredDistance(n,x,y): cummx=[0]*(n+1) cummy=[0]*(n+1) cummx2=[0]*(n+1) cummy2=[0]*(n+1) cumm(x,y,cummx,cummy,cummx2,cummy2,n) hdx,hdy=0,0 for i in range(1,n+1): hdx+=((i-1)*x[i]*x[i]+cummx2[i-1]-2*x[i]*cummx[i-1]) hdy+=((i-1)*y[i]*y[i]+cummy2[i-1]-2*y[i]*cummy[i-1]) total=hdx+hdy return total if __name__=="__main__" : n=3 x=[0,0,1,0] y=[1,0,0,0] print(calHammeredDistance(n,x,y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 3 ; x := Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 0 }))) ; y := Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))) ; execute (calHammeredDistance(n, x, y))->display() ) else skip; operation cumm(x : OclAny, y : OclAny, cummx : OclAny, cummy : OclAny, cummx2 : OclAny, cummy2 : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(1, n + 1-1) do ( cummx[i+1] := cummx[i - 1+1] + x[i+1] ; cummy[i+1] := cummy[i - 1+1] + y[i+1] ; cummx2[i+1] := cummx2[i - 1+1] + x[i+1] * x[i+1] ; cummy2[i+1] := cummy2[i - 1+1] + y[i+1] * y[i+1]); operation calHammeredDistance(n : OclAny, x : OclAny, y : OclAny) : OclAny pre: true post: true activity: cummx := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; cummy := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; cummx2 := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; cummy2 := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; cumm(x, y, cummx, cummy, cummx2, cummy2, n) ; var hdx : OclAny := null; var hdy : OclAny := null; Sequence{hdx,hdy} := Sequence{0,0} ; for i : Integer.subrange(1, n + 1-1) do ( hdx := hdx + ((i - 1) * x[i+1] * x[i+1] + cummx2[i - 1+1] - 2 * x[i+1] * cummx[i - 1+1]) ; hdy := hdy + ((i - 1) * y[i+1] * y[i+1] + cummy2[i - 1+1] - 2 * y[i+1] * cummy[i - 1+1])) ; var total : OclAny := hdx + hdy ; return total; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd as __gcd def isPossible(arr,n,p): gcd=0 ; for i in range(n): gcd=__gcd(gcd,arr[i]); if(p % gcd==0): return True ; return False ; if __name__=="__main__" : arr=[6,9]; n=len(arr); p=3 ; if(isPossible(arr,n,p)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{6}->union(Sequence{ 9 }); ; n := (arr)->size(); ; p := 3; ; if (isPossible(arr, n, p)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ) else skip; operation isPossible(arr : OclAny, n : OclAny, p : OclAny) pre: true post: true activity: var gcd : int := 0; ; for i : Integer.subrange(0, n-1) do ( gcd := __gcd(gcd, arr[i+1]);) ; if (p mod gcd = 0) then ( return true; ) else skip ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans=[0]*101 while True : try : ans[int(input())]+=1 except EOFError : break printqueue=[] maxi=max(ans) for i in range(1,101): if ans[i]==maxi : printqueue.append(i) for i in printqueue : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 101) ; while true do ( try ( ans[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1] := ans[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1] + 1) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))) ; var printqueue : Sequence := Sequence{} ; var maxi : OclAny := (ans)->max() ; for i : Integer.subrange(1, 101-1) do ( if ans[i+1] = maxi then ( execute ((i) : printqueue) ) else skip) ; for i : printqueue do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys data=[0]*101 for line in sys.stdin : try : n=int(line) data[n]+=1 except : break m=max(data) for i in range(len(data)): if data[i]==m : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var data : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 101) ; for line : OclFile["System.in"] do ( try ( var n : int := ("" + ((line)))->toInteger() ; data[n+1] := data[n+1] + 1) catch (_e : OclException) do ( break) ) ; var m : OclAny := (data)->max() ; for i : Integer.subrange(0, (data)->size()-1) do ( if data[i+1] = m then ( execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import random def lehmann(n,t): a=random.randint(2,n-1) e=(n-1)/2 while(t>0): result=((int)(a**e))% n if((result % n)==1 or(result % n)==(n-1)): a=random.randint(2,n-1) t-=1 else : return-1 return 1 n=13 t=10 if(n is 2): print("2 is Prime.") if(n % 2==0): print(n,"is Composite") else : flag=lehmann(n,t) if(flag is 1): print(n,"may be Prime.") else : print(n,"is Composite.") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 13 ; t := 10 ; if (n <>= 2) then ( execute ("2 is Prime.")->display() ) else skip ; if (n mod 2 = 0) then ( execute (n)->display() ) else ( var flag : OclAny := lehmann(n, t) ; if (flag <>= 1) then ( execute (n)->display() ) else ( execute (n)->display() ) ); operation lehmann(n : OclAny, t : OclAny) : OclAny pre: true post: true activity: var a : int := (2 + (OclRandom.defaultInstanceOclRandom()).nextInt(n - 1 - 2)) ; var e : double := (n - 1) / 2 ; while (t > 0) do ( var result : int := ((OclType["int"])((a)->pow(e))) mod n ; if ((result mod n) = 1 or (result mod n) = (n - 1)) then ( a := (2 + (OclRandom.defaultInstanceOclRandom()).nextInt(n - 1 - 2)) ; t := t - 1 ) else ( return -1 )) ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools while True : n,x=map(int,input().split(' ')) if(n==0)&(x==0): break ret=0 for v in itertools.combinations(list(range(1,n+1)),3): if sum(v)==x : ret+=1 print(ret) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; if MathLib.bitwiseAnd((n = 0), (x = 0)) then ( break ) else skip ; var ret : int := 0 ; for v : itertools.combinations((Integer.subrange(1, n + 1-1)), 3) do ( if (v)->sum() = x then ( ret := ret + 1 ) else skip) ; execute (ret)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function import sys stack=[] for line in sys.stdin : if line.startswith('quit'): break if line.startswith('push'): stack.append(line.strip()[-1]) if line.startswith('pop'): print(stack.pop()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var stack : Sequence := Sequence{} ; for line : OclFile["System.in"] do ( if line->hasPrefix('quit') then ( break ) else skip ; if line->hasPrefix('push') then ( execute ((line->trim()->last()) : stack) ) else skip ; if line->hasPrefix('pop') then ( execute (stack->last())->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from itertools import dropwhile a=[] for v in sys.stdin : a.append(int(v)) m=max([a.count(v)for v in set(a)]) try : next(dropwhile(lambda x : True,(print(v)for v in set(a)if a.count(v)==m))) except StopIteration : pass ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var a : Sequence := Sequence{} ; for v : OclFile["System.in"] do ( execute ((("" + ((v)))->toInteger()) : a)) ; var m : OclAny := (Set{}->union((a))->select(v | true)->collect(v | (a->count(v))))->max() ; try ( next(dropwhile(lambda x : OclAny in (true), Sequence{(testlist_comp (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) ))))))) (comp_for for (exprlist (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name a)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) ))))) == (comparison (expr (atom (name m))))))))))}))) (except_clause except (test (logical_test (comparison (expr (atom (name StopIteration)))))) : (suite (stmt (simple_stmt (small_stmt pass))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : alist=[] while True : try : a=int(input()) alist.append(a) except : break m=min(alist) M=max(alist) if m<1 : break clist=[0] saihin=[0] for i in range(m,M+1,1): c=alist.count(i) if c>clist[0]: del(clist[0]) clist.append(c) del(saihin[0]) if c==clist[0]: saihin.append(i) l=len(saihin) for i in range(l): if saihin==[]: break print(saihin[0]) del(saihin[0]) except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var alist : Sequence := Sequence{} ; while true do ( try ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((a) : alist)) catch (_e : OclException) do ( break) ) ; var m : OclAny := (alist)->min() ; var M : OclAny := (alist)->max() ; if m < 1 then ( break ) else skip ; var clist : Sequence := Sequence{ 0 } ; var saihin : Sequence := Sequence{ 0 } ; for i : Integer.subrange(m, M + 1-1)->select( $x | ($x - m) mod 1 = 0 ) do ( var c : int := alist->count(i) ; if (c->compareTo(clist->first())) > 0 then ( execute ((clist->first()))->isDeleted() ; execute ((c) : clist) ; execute ((saihin->first()))->isDeleted() ) else skip ; if c = clist->first() then ( execute ((i) : saihin) ) else skip) ; var l : int := (saihin)->size() ; for i : Integer.subrange(0, l-1) do ( if saihin = Sequence{} then ( break ) else skip ; execute (saihin->first())->display() ; execute ((saihin->first()))->isDeleted())) catch (_e : OclException) do ( break) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d={} try : while True : n=int(input()) if n in d : d[n]+=1 else : d[n]=1 except EOFError : pass a=[] m=max(d.values()) for key,value in d.items(): if value==m : a.append(key) a.sort() for i in a : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : OclAny := Set{} ; try ( while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (d)->includes(n) then ( d[n+1] := d[n+1] + 1 ) else ( d[n+1] := 1 ))) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt pass))))) ; var a : Sequence := Sequence{} ; var m : OclAny := (d.values())->max() ; for _tuple : d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); if value = m then ( execute ((key) : a) ) else skip) ; a := a->sort() ; for i : a do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- word=input().lower() list=[] sogl='' for i in word : list.append(i) for j in range(len(list)): if list[j]not in 'aoyeui' : sogl+=('.'+list[j]) print(sogl) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var word : OclAny := input()->toLowerCase() ; var OclType["Sequence"] : Sequence := Sequence{} ; var sogl : String := '' ; for i : word do ( execute ((i) : OclType["Sequence"])) ; for j : Integer.subrange(0, (OclType["Sequence"])->size()-1) do ( if ('aoyeui')->characters()->excludes([j+1]) then ( sogl := sogl + ('.'->union([j+1])) ) else skip) ; execute (sogl)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() t="" for i in s : if i not in "aeiouAEIOUYy" : t+="."+i.lower() print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var t : String := "" ; for i : s->characters() do ( if ("aeiouAEIOUYy")->characters()->excludes(i) then ( t := t + "." + i->toLowerCase() ) else skip) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() vows=['a','e','o','i','u','y'] s=s.lower() s="."+".".join([c for c in s if not vows.__contains__(c)]) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var vows : Sequence := Sequence{'a'}->union(Sequence{'e'}->union(Sequence{'o'}->union(Sequence{'i'}->union(Sequence{'u'}->union(Sequence{ 'y' }))))) ; s := s->toLowerCase() ; s := "." + StringLib.sumStringsWithSeparator((s->characters()->select(c | not(vows.__contains__(c)))->collect(c | (c))), ".") ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- txt=input() out="" for s in txt : if s.upper()in["A","O","Y","E","U","I"]: pass else : out=out+"."+s.lower() print(out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var txt : String := (OclFile["System.in"]).readLine() ; var out : String := "" ; for s : txt->characters() do ( if (Sequence{"A"}->union(Sequence{"O"}->union(Sequence{"Y"}->union(Sequence{"E"}->union(Sequence{"U"}->union(Sequence{ "I" }))))))->includes(s->toUpperCase()) then ( skip ) else ( out := out + "." + s->toLowerCase() )) ; execute (out)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- word=input().lower() list=[] sogl=[] for i in word : list.append(i) for j in range(len(list)): if list[j]not in 'aoyeui' : sogl.append('.') sogl.append(list[j]) print(''.join(sogl)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var word : OclAny := input()->toLowerCase() ; var OclType["Sequence"] : Sequence := Sequence{} ; var sogl : Sequence := Sequence{} ; for i : word do ( execute ((i) : OclType["Sequence"])) ; for j : Integer.subrange(0, (OclType["Sequence"])->size()-1) do ( if ('aoyeui')->characters()->excludes([j+1]) then ( execute (('.') : sogl) ; execute (([j+1]) : sogl) ) else skip) ; execute (StringLib.sumStringsWithSeparator((sogl), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- maxn=3e5+5 def solve(arr,n): f=[0]*(n+1) last=[0]*(n+1) ans=[-1]*(n+1) for i in range(1,n+1): x=arr[i] f[x]=max(f[x],i-last[x]) last[x]=i for x in range(1,n+1): f[x]=max(f[x],n-last[x]+1) i=f[x] while i<=n and ans[i]==-1 : ans[i]=x i+=1 print(*ans[1 :]) for _ in range(int(input())): n=int(input()) arr=list(map(int,input().split())) arr=[0]+arr solve(arr,n) num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var maxn : double := ("3e5")->toReal() + 5 ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; arr := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := Sequence{ 0 }->union(arr) ; solve(arr, n)) ; var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()); operation solve(arr : OclAny, n : OclAny) pre: true post: true activity: var f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var last : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (n + 1)) ; for i : Integer.subrange(1, n + 1-1) do ( var x : OclAny := arr[i+1] ; f[x+1] := Set{f[x+1], i - last[x+1]}->max() ; last[x+1] := i) ; for x : Integer.subrange(1, n + 1-1) do ( f[x+1] := Set{f[x+1], n - last[x+1] + 1}->max() ; var i : String := f[x+1] ; while i <= n & ans->at(i) = -1 do ( ans->at(i) := x ; i := i + 1)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,x): result=0 for i in range(1,n+1): for j in range(i,n+1): for k in range(j,n+1): if i==j or j==k or k==i : continue if i+j+k==x : result+=1 return result if __name__=="__main__" : while True : n,x=map(int,input().split()) if n==0 and x==0 : break print(solve(n,x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( while true do ( Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 & x = 0 then ( break ) else skip ; execute (solve(n, x))->display()) ) else skip; operation solve(n : OclAny, x : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(i, n + 1-1) do ( for k : Integer.subrange(j, n + 1-1) do ( if i = j or j = k or k = i then ( continue ) else skip ; if i + j + k = x then ( result := result + 1 ) else skip))) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def kAmazingNumbers(n,array): d={} for x in range(n): if array[x]in d : d[array[x]].append(x) else : d[array[x]]=[-1,x] for x in d : d[x].append(n) map={} for x in d : map[x]=0 for y in range(len(d[x])-1): map[x]=max(map[x],d[x][y+1]-d[x][y]) d={} for x in map : if map[x]in d : d[map[x]]=min(x,d[map[x]]) else : d[map[x]]=x ans=[] for x in range(1,n+1): if x not in d : if x==1 : ans.append(-1) else : ans.append(ans[x-2]) else : if x==1 or ans[x-2]==-1 : ans.append(d[x]) else : ans.append(min(d[x],ans[x-2])) return ans t=int(input()) for _ in range(t): n=int(input()) l=list(map(int,input().split())) ans=kAmazingNumbers(n,l) for x in ans : print(x,end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; ans := kAmazingNumbers(n, l) ; for x : ans do ( execute (x)->display()) ; execute (->display()); operation kAmazingNumbers(n : OclAny, array : OclAny) : OclAny pre: true post: true activity: var d : OclAny := Set{} ; for x : Integer.subrange(0, n-1) do ( if (d)->includes(array[x+1]) then ( (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name array)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) ) else ( d[array[x+1]+1] := Sequence{-1}->union(Sequence{ x }) )) ; for x : d do ((expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))) ; var map : OclAny := Set{} ; for x : d do ( ([x+1]`third)->collect( _x | ([x+1])->apply(_x) ) := 0 ; for y : Integer.subrange(0, (d[x+1])->size() - 1-1) do ( ([x+1]`third)->collect( _x | ([x+1])->apply(_x) ) := Set{([x+1]`third)->collect( _x | ([x+1])->apply(_x) ), d[x+1][y + 1+1] - d[x+1][y+1]}->max())) ; d := Set{} ; for x : map do ( if (d)->includes(([x+1]`third)->collect( _x | ([x+1])->apply(_x) )) then ( d->restrict(([x+1]`third)->collect( _x | ([x+1])->apply(_x) )) := Set{x, d->restrict(([x+1]`third)->collect( _x | ([x+1])->apply(_x) ))}->min() ) else ( d->restrict(([x+1]`third)->collect( _x | ([x+1])->apply(_x) )) := x )) ; var ans : Sequence := Sequence{} ; for x : Integer.subrange(1, n + 1-1) do ( if (d)->excludes(x) then ( if x = 1 then ( execute ((-1) : ans) ) else ( execute ((ans[x - 2+1]) : ans) ) ) else ( if x = 1 or ans[x - 2+1] = -1 then ( execute ((d[x+1]) : ans) ) else ( execute ((Set{d[x+1], ans[x - 2+1]}->min()) : ans) ) )) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- stack=[] while True : order=list(input().split()) if order[0]=='push' : stack.append(order[1]) elif order[0]=='pop' : print(stack.pop()) elif order[0]=='quit' : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var stack : Sequence := Sequence{} ; while true do ( var order : Sequence := (input().split()) ; if order->first() = 'push' then ( execute ((order[1+1]) : stack) ) else (if order->first() = 'pop' then ( execute (stack->last())->display() ) else (if order->first() = 'quit' then ( break ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().rstrip() def solve(): N=int(input()) A=list(map(int,input().split())) prev=[-1 for i in range(N)] M=[0 for i in range(N)] ans=[N+1 for i in range(N)] for i in range(N): M[A[i]-1]=max(M[A[i]-1],i-prev[A[i]-1]-1) prev[A[i]-1]=i for i in range(N): M[i]=max(M[i],N-prev[i]-1) for i in range(N): if M[i]!=N : ans[M[i]]=min(ans[M[i]],i+1) for i in range(1,N): ans[i]=min(ans[i],ans[i-1]) print(*[-1 if i==N+1 else i for i in ans]) T=int(input()) for i in range(T): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; skip ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, T-1) do ( solve()); operation solve() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var prev : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (-1)) ; var M : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; var ans : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (N + 1)) ; for i : Integer.subrange(0, N-1) do ( M[A[i+1] - 1+1] := Set{M[A[i+1] - 1+1], i - prev[A[i+1] - 1+1] - 1}->max() ; prev[A[i+1] - 1+1] := i) ; for i : Integer.subrange(0, N-1) do ( M[i+1] := Set{M[i+1], N - prev[i+1] - 1}->max()) ; for i : Integer.subrange(0, N-1) do ( if M[i+1] /= N then ( ans[M[i+1]+1] := Set{ans[M[i+1]+1], i + 1}->min() ) else skip) ; for i : Integer.subrange(1, N-1) do ( ans[i+1] := Set{ans[i+1], ans[i - 1+1]}->min()) ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom - (number (integer 1)))))) if (logical_test (comparison (comparison (expr (atom (name i)))) == (comparison (expr (expr (atom (name N))) + (expr (atom (number (integer 1)))))))) else (test (logical_test (comparison (expr (atom (name i))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name ans))))))) ])))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t=int(input()) ans=[] inf=pow(10,9)+1 for _ in range(t): n=int(input()) a=list(map(int,input().split())) x=[[-1]for _ in range(n+5)] for i in range(n): x[a[i]].append(i) ans0=[inf]*n for i in range(n,0,-1): xi=x[i] xi.append(n) if not len(xi)^ 2 : continue d=0 for j in range(len(xi)-1): d=max(d,xi[j+1]-xi[j]-1) ans0[d]=i for i in range(1,n): ans0[i]=min(ans0[i],ans0[i-1]) for i in range(n): if ans0[i]^ inf : break ans0[i]=-1 ans.append(" ".join(map(str,ans0))) sys.stdout.write("\n".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; var Math_PINFINITY : double := (10)->pow(9) + 1 ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : Sequence := Integer.subrange(0, n + 5-1)->select(_anon | true)->collect(_anon | (Sequence{ -1 })) ; for i : Integer.subrange(0, n-1) do ((expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var ans0 : Sequence := MatrixLib.elementwiseMult(Sequence{ Math_PINFINITY }, n) ; for i : Integer.subrange(0 + 1, n)->reverse() do ( var xi : OclAny := x[i+1] ; execute ((n) : xi) ; if not(MathLib.bitwiseXor((xi)->size(), 2)) then ( continue ) else skip ; var d : int := 0 ; for j : Integer.subrange(0, (xi)->size() - 1-1) do ( d := Set{d, xi[j + 1+1] - xi[j+1] - 1}->max()) ; ans0[d+1] := i) ; for i : Integer.subrange(1, n-1) do ( ans0[i+1] := Set{ans0[i+1], ans0[i - 1+1]}->min()) ; for i : Integer.subrange(0, n-1) do ( if MathLib.bitwiseXor(ans0[i+1], Math_PINFINITY) then ( break ) else skip ; ans0[i+1] := -1) ; execute ((StringLib.sumStringsWithSeparator(((ans0)->collect( _x | (OclType["String"])->apply(_x) )), " ")) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n=int(input()) a=list(map(int,input().split(' '))) l=[-1]*n u=[-1]*n k=[-1]*n for x in range(n): i=a[x]-1 l[i]=max(l[i],x-u[i]) u[i]=x m=n i=[x for x in range(n)if l[x]!=-1] for x in i : a=max(l[x],n-u[x]) if l[x]<=m and k[a-1]==-1 : for j in range(a-1,m): k[j]=x+1 m=a-1 print(*k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var l : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; var u : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; var k : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; for x : Integer.subrange(0, n-1) do ( var i : double := a[x+1] - 1 ; l[i+1] := Set{l[i+1], x - u[i+1]}->max() ; u[i+1] := x) ; var m : int := n ; i := Integer.subrange(0, n-1)->select(x | l[x+1] /= -1)->collect(x | (x)) ; for x : i do ( a := Set{l[x+1], n - u[x+1]}->max() ; if (l[x+1]->compareTo(m)) <= 0 & k[a - 1+1] = -1 then ( for j : Integer.subrange(a - 1, m-1) do ( k[j+1] := x + 1) ; m := a - 1 ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name k))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def counLastDigitK(low,high,k): count=0 for i in range(low,high+1): if(i % 10==k): count+=1 return count low=3 high=35 k=3 print(counLastDigitK(low,high,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; low := 3 ; high := 35 ; k := 3 ; execute (counLastDigitK(low, high, k))->display(); operation counLastDigitK(low : OclAny, high : OclAny, k : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(low, high + 1-1) do ( if (i mod 10 = k) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def counLastDigitK(low,high,k): count=(high-low)/10 if(high % 10>=k): count+=1 if(low % 10>k): count-=1 return int(count) low=3 high=35 k=3 print(counLastDigitK(low,high,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; low := 3 ; high := 35 ; k := 3 ; execute (counLastDigitK(low, high, k))->display(); operation counLastDigitK(low : OclAny, high : OclAny, k : OclAny) : OclAny pre: true post: true activity: var count : double := (high - low) / 10 ; if ((high mod 10->compareTo(k)) >= 0) then ( count := count + 1 ) else skip ; if ((low mod 10->compareTo(k)) > 0) then ( count := count - 1 ) else skip ; return ("" + ((count)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findCnt(arr,n,k): ret=0 ; i=0 ; while(i=arr[j-1]): j+=1 ; x=max(0,j-i-k); ret+=(x*(x+1))/2 ; i=j ; return ret ; if __name__=="__main__" : arr=[5,4,3,2,1]; n=len(arr); k=2 ; print(findCnt(arr,n,k)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{5}->union(Sequence{4}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 1 })))); ; n := (arr)->size(); ; k := 2; ; execute (findCnt(arr, n, k))->display(); ) else skip; operation findCnt(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var ret : int := 0; ; var i : int := 0; ; while ((i->compareTo(n)) < 0) do ( var j : int := i + 1; ; while ((j->compareTo(n)) < 0 & (arr[j+1]->compareTo(arr[j - 1+1])) >= 0) do ( j := j + 1;) ; var x : OclAny := Set{0, j - i - k}->max(); ; ret := ret + (x * (x + 1)) / 2; ; i := j;) ; return ret;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def smallestEven(n): if(n==1): return 0 return pow(10,n-1) n=4 print(smallestEven(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute (smallestEven(n))->display(); operation smallestEven(n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return 0 ) else skip ; return (10)->pow(n - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def smallestOdd(n): if(n==1): return 1 return pow(10,n-1)+1 n=4 print(smallestOdd(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute (smallestOdd(n))->display(); operation smallestOdd(n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return 1 ) else skip ; return (10)->pow(n - 1) + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=1 Answer=[] while c>0 : inp=input().split() n=int(inp[0]) x=int(inp[1]) c=n**2+x**2 if c==0 : break flg=0 for i in range(1,min(int(x/3),n-1)): for j in range(i+1,min(int(x/2),n)): for k in range(j+1,n+1): if i+j+k==x : flg+=1 Answer.append(flg) for l in range(0,len(Answer)): print(Answer[l]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : int := 1 ; var Answer : Sequence := Sequence{} ; while c > 0 do ( var inp : OclAny := input().split() ; var n : int := ("" + ((inp->first())))->toInteger() ; var x : int := ("" + ((inp[1+1])))->toInteger() ; c := (n)->pow(2) + (x)->pow(2) ; if c = 0 then ( break ) else skip ; var flg : int := 0 ; for i : Integer.subrange(1, Set{("" + ((x / 3)))->toInteger(), n - 1}->min()-1) do ( for j : Integer.subrange(i + 1, Set{("" + ((x / 2)))->toInteger(), n}->min()-1) do ( for k : Integer.subrange(j + 1, n + 1-1) do ( if i + j + k = x then ( flg := flg + 1 ) else skip))) ; execute ((flg) : Answer)) ; for l : Integer.subrange(0, (Answer)->size()-1) do ( execute (Answer[l+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumSquare(n): i=1 while i*i<=n : j=1 while(j*j<=n): if(i*i+j*j==n): print(i,"^2+",j,"^2") return True j=j+1 i=i+1 return False n=25 if(sumSquare(n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 25 ; if (sumSquare(n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation sumSquare(n : OclAny) : OclAny pre: true post: true activity: var i : int := 1 ; while (i * i->compareTo(n)) <= 0 do ( var j : int := 1 ; while ((j * j->compareTo(n)) <= 0) do ( if (i * i + j * j = n) then ( execute (i)->display() ; return true ) else skip ; j := j + 1) ; i := i + 1) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import chain alph="abcdefghijklmnopqrstuvwxyz" def solve1(s): cands=[s] for c in reversed(alph[:-1]): cands=chain.from_iterable([candidates(s,c)for s in cands]) cands=list(cands) cands.sort() print(len(cands)) if len(cands)>10 : for s in cands[: 5]: print(s) for s in cands[-5 :]: print(s) else : for s in cands : print(s) def next_char(c): return chr(ord(c)+1) def candidates(string,key): nex=next_char(key) flag=False for i,c in enumerate(string): if c==nex : flag=True break if c!=key : continue yield string[: i]+nex+string[i+1 :] if not flag : yield string while True : s=input() if s=="#" : break solve1(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var alph : String := "abcdefghijklmnopqrstuvwxyz" ; skip ; skip ; skip ; while true do ( s := (OclFile["System.in"]).readLine() ; if s = "#" then ( break ) else skip ; solve1(s)); operation solve1(s : OclAny) pre: true post: true activity: var cands : Sequence := Sequence{ s } ; for c : (alph->front())->reverse() do ( cands := chain.from_iterable(cands->select(s | true)->collect(s | (candidates(s, c))))) ; cands := (cands) ; cands := cands->sort() ; execute ((cands)->size())->display() ; if (cands)->size() > 10 then ( for s : cands.subrange(1,5) do ( execute (s)->display()) ; for s : cands.subrange(-5+1) do ( execute (s)->display()) ) else ( for s : cands do ( execute (s)->display()) ); operation next_char(c : OclAny) : OclAny pre: true post: true activity: return ((c)->char2byte() + 1)->byte2char(); operation candidates(string : OclAny, key : OclAny) pre: true post: true activity: var nex : OclAny := next_char(key) ; var flag : boolean := false ; for _tuple : Integer.subrange(1, (string)->size())->collect( _indx | Sequence{_indx-1, (string)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if c = nex then ( flag := true ; break ) else skip ; if c /= key then ( continue ) else skip ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return string.subrange(1,i) + nex + string.subrange(i + 1+1)) ; if not(flag) then ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return string ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stack=[] for operation in sys.stdin : if operation.startswith('quit'): break elif operation.startswith('push'): _,block=operation.rstrip().split() stack.append(block) elif operation.startswith('pop'): print(stack.pop()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stack : Sequence := Sequence{} ; for operation : OclFile["System.in"] do ( if operation->hasPrefix('quit') then ( break ) else (if operation->hasPrefix('push') then ( var _anon : OclAny := null; var block : OclAny := null; Sequence{_anon,block} := operation.rstrip().split() ; execute ((block) : stack) ) else (if operation->hasPrefix('pop') then ( execute (stack->last())->display() ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.readline()[:-1] while True : S=input() if S=="#" : break N=len(S) Sn=[ord(c)-97 for c in S] ans=[] ansappend=ans.append zip_=list(zip(range(N-1,-1,-1),Sn)) i=0 end=1<>j & 1 : n+=1 if tst[n]: tst[n]=0 ans_.append(n) else : i+=1<size() ; var Sn : Sequence := S->characters()->select(c | true)->collect(c | ((c)->char2byte() - 97)) ; var ans : Sequence := Sequence{} ; var ansappend : OclAny := ans.append ; var zip_ : Sequence := (Integer.subrange(1, Integer.subrange(-1 + 1, N - 1)->reverse()->size())->collect( _indx | Sequence{Integer.subrange(-1 + 1, N - 1)->reverse()->at(_indx), Sn->at(_indx)} )) ; var i : int := 0 ; var end : int := 1 * (2->pow(N)) ; var Tst : Sequence := Sequence{ 0 }->union(MatrixLib.elementwiseMult(Sequence{ 1 }, 25))->union(Sequence{ 0 }) ; while (i->compareTo(end)) < 0 do ( var tst : OclAny := Tst->copy() ; var ans_ : Sequence := Sequence{} ; (compound_stmt for (exprlist (expr (atom (name j))) , (expr (atom (name n)))) in (testlist (test (logical_test (comparison (expr (atom (name zip_))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (expr (expr (atom (name i))) >> (expr (atom (name j)))) & (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name n)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name tst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n)))))))) ])))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name tst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans_)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name j)))))))))))) (stmt (simple_stmt (small_stmt break)))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name tst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n)))))))) ])))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans_)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name j)))))))))))) (stmt (simple_stmt (small_stmt break)))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ansappend)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans_)))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))))) ; execute ((ans)->size())->display() ; if (ans)->size() <= 10 then ( for ans_ : ans do ( execute ((argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name chr)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (number (integer 97)))))))))) ))))))))) , (argument (test (logical_test (comparison (expr (atom (name ans_)))))))) )))))))))->display()) ) else ( for ans_ : ans.subrange(1,5) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name chr)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (number (integer 97)))))))))) ))))))))) , (argument (test (logical_test (comparison (expr (atom (name ans_)))))))) )))))))))->display()) ; for ans_ : ans.subrange(-5+1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name chr)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (number (integer 97)))))))))) ))))))))) , (argument (test (logical_test (comparison (expr (atom (name ans_)))))))) )))))))))->display()) )); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input(''))): n,m=map(int,input().split()) l=list(map(int,input().split())) k=sum(l)-m if k>0 : print(k) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine(''))))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k : double := (l)->sum() - m ; if k > 0 then ( execute (k)->display() ) else ( execute (0)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) for i in range(a): b,c=map(int,input().split()) d=list(map(int,input().split())) e=sum(d) if(etoInteger() ; for i : Integer.subrange(0, a-1) do ( var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var e : OclAny := (d)->sum() ; if ((e->compareTo(c)) < 0) then ( execute (0)->display() ) else ( execute (e - c)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for _ in range(n): a,b=map(int,input().split()) l=list(map(int,input().split())) s=sum(l)-b if(s<=0): print(0) else : print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : double := (l)->sum() - b ; if (s <= 0) then ( execute (0)->display() ) else ( execute (s)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while(t!=0): n,m=map(int,input().split()) l=[int(a)for a in input().split()] s=sum(l)-m if(s>0): print(s) else : print(0) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (t /= 0) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; var s : double := (l)->sum() - m ; if (s > 0) then ( execute (s)->display() ) else ( execute (0)->display() ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=map(int,input().split()) s=sum(list(map(int,input().split()))) print(s-m if s>m else 0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->sum() ; execute (if (s->compareTo(m)) > 0 then s - m else 0 endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,a=int(input()),sum(int(i)for i in input().split()) res=a-n if a>=n else 1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( )))))))))->sum()} ; var res : double := if (a->compareTo(n)) >= 0 then a - n else 1 endif ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=map(int,input().split()) while n!=0 or x!=0 : count=0 for i in range(1,n-1): for j in range(i+1,n): for k in range(j+1,n+1): if i+j+k==x : count+=1 print(count) n,x=map(int,input().split()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; while n /= 0 or x /= 0 do ( var count : int := 0 ; for i : Integer.subrange(1, n - 1-1) do ( for j : Integer.subrange(i + 1, n-1) do ( for k : Integer.subrange(j + 1, n + 1-1) do ( if i + j + k = x then ( count := count + 1 ) else skip))) ; execute (count)->display() ; var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) l1=list(map(int,input().split(" "))) a=0 for i in range(len(l1)): a+=l1[i] if a>=len(l1): print(abs(len(l1)-a)) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l1 : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var a : int := 0 ; for i : Integer.subrange(0, (l1)->size()-1) do ( a := a + l1[i+1]) ; if (a->compareTo((l1)->size())) >= 0 then ( execute (((l1)->size() - a)->abs())->display() ) else ( execute (1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) a=map(int,input().split()) p=sum(a) q=p/n if q==1.000000 : print(0) elif p<=0 or p<=n : print(1) else : print(p-n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : OclAny := (a)->sum() ; var q : double := p / n ; if q = 1.000000 then ( execute (0)->display() ) else (if p <= 0 or (p->compareTo(n)) <= 0 then ( execute (1)->display() ) else ( execute (p - n)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=[] s=[] for i in range(n): x=int(input()) s=list(map(int,input().split())) ans.append(s) for j in range(n): if sum(ans[j])/len(ans[j])==1 : print(0) else : if(sum(ans[j])-len(ans[j]))<=0 : print(1) else : print(sum(ans[j])-len(ans[j])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; var s : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; s := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((s) : ans)) ; for j : Integer.subrange(0, n-1) do ( if (ans[j+1])->sum() / (ans[j+1])->size() = 1 then ( execute (0)->display() ) else ( if ((ans[j+1])->sum() - (ans[j+1])->size()) <= 0 then ( execute (1)->display() ) else ( execute ((ans[j+1])->sum() - (ans[j+1])->size())->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- L=[] l=[] count=0 while True : a=raw_input() if a=="quit" : break elif a=="pop" : move=L[len(L)-1] l.append(move) L.pop(len(L)-1) count+=1 else : L.append(a) for i in xrange(len(l)): c=l[i] print(c[5]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var L : Sequence := Sequence{} ; var l : Sequence := Sequence{} ; var count : int := 0 ; while true do ( var a : OclAny := raw_input() ; if a = "quit" then ( break ) else (if a = "pop" then ( var move : OclAny := L[(L)->size() - 1+1] ; execute ((move) : l) ; L := L->excludingAt((L)->size() - 1+1) ; count := count + 1 ) else ( execute ((a) : L) ) ) ) ; for i : xrange((l)->size()) do ( var c : OclAny := l[i+1] ; execute (c[5+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for i in range(T): n=int(input()) arr=list(map(int,input().strip().split()))[: n] if sum(arr)>n : print(sum(arr)-n) elif sum(arr)/n==1 : print("0") else : print("1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, T-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : OclAny := OclType["Sequence"]((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ; if ((arr)->sum()->compareTo(n)) > 0 then ( execute ((arr)->sum() - n)->display() ) else (if (arr)->sum() / n = 1 then ( execute ("0")->display() ) else ( execute ("1")->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w=int(input()) if w % 2==0 and w>2 : print("YES") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if w mod 2 = 0 & w > 2 then ( execute ("YES")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if(n % 2==0 and n!=2): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n mod 2 = 0 & n /= 2) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- weight=int(input()) if weight>2 and weight % 2==0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var weight : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if weight > 2 & weight mod 2 = 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n!=2 and n % 2==0 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n /= 2 & n mod 2 = 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 2!=0 or n==2 : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 /= 0 or n = 2 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import itertools sys.setrecursionlimit(1000000000) from heapq import heapify,heappop,heappush,heappushpop import math import collections import copy while True : n,l=map(int,input().split()) cnt=0 if n==0 and l==0 : break for i in range(1,n+1): for j in range(i+1,n+1): for k in range(j+1,n+1): if(i!=j and j!=k and i!=k)and i+j+k==l : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit(1000000000) ; skip ; skip ; skip ; skip ; while true do ( var n : OclAny := null; var l : OclAny := null; Sequence{n,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cnt : int := 0 ; if n = 0 & l = 0 then ( break ) else skip ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(i + 1, n + 1-1) do ( for k : Integer.subrange(j + 1, n + 1-1) do ( if (i /= j & j /= k & i /= k) & i + j + k = l then ( cnt := cnt + 1 ) else skip))) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class ItemValue : def __init__(self,wt,val,ind): self.wt=wt self.val=val self.ind=ind self.cost=val//wt def __lt__(self,other): return self.cost=0 : capacity-=curWt totalValue+=curVal else : fraction=capacity/curWt totalValue+=curVal*fraction capacity=int(capacity-(curWt*fraction)) break return totalValue if __name__=="__main__" : wt=[10,40,20,30] val=[60,40,100,120] capacity=50 maxValue=FractionalKnapSack.getMaxValue(wt,val,capacity) print("Maximum value in Knapsack=",maxValue) ------------------------------------------------------------ OCL File: --------- class ItemValue { static operation newItemValue() : ItemValue pre: true post: ItemValue->exists( _x | result = _x ); attribute wt : OclAny := wt; attribute val : OclAny := val; attribute ind : OclAny := ind; attribute cost : int := val div wt; operation initialise(wt : OclAny,val : OclAny,ind : OclAny) : ItemValue pre: true post: true activity: self.wt := wt ; self.val := val ; self.ind := ind ; self.cost := val div wt; return self; operation __lt__(other : OclAny) : OclAny pre: true post: true activity: return (self.cost->compareTo(other.cost)) < 0; } class FractionalKnapSack { static operation newFractionalKnapSack() : FractionalKnapSack pre: true post: FractionalKnapSack->exists( _x | result = _x ); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( wt := Sequence{10}->union(Sequence{40}->union(Sequence{20}->union(Sequence{ 30 }))) ; val := Sequence{60}->union(Sequence{40}->union(Sequence{100}->union(Sequence{ 120 }))) ; capacity := 50 ; var maxValue : FractionalKnapSack := (FractionalKnapSack.newFractionalKnapSack()).initialise.getMaxValue(wt, val, capacity) ; execute ("Maximum value in Knapsack=")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=4 def calculateEnergy(mat,n): tot_energy=0 for i in range(n): for j in range(n): q=mat[i][j]//n i_des=q j_des=mat[i][j]-(n*q) tot_energy+=(abs(i_des-i)+abs(j_des-j)) return tot_energy mat=[[4,7,0,3],[8,5,6,1],[9,11,10,2],[15,13,14,12]] print("Total energy required=",calculateEnergy(mat,n),"units") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := 4 ; skip ; mat := Sequence{Sequence{4}->union(Sequence{7}->union(Sequence{0}->union(Sequence{ 3 })))}->union(Sequence{Sequence{8}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 1 })))}->union(Sequence{Sequence{9}->union(Sequence{11}->union(Sequence{10}->union(Sequence{ 2 })))}->union(Sequence{ Sequence{15}->union(Sequence{13}->union(Sequence{14}->union(Sequence{ 12 }))) }))) ; execute ("Total energy required=")->display(); operation calculateEnergy(mat : OclAny, n : OclAny) : OclAny pre: true post: true activity: var tot_energy : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( var q : int := mat[i+1][j+1] div n ; var i_des : int := q ; var j_des : double := mat[i+1][j+1] - (n * q) ; tot_energy := tot_energy + ((i_des - i)->abs() + (j_des - j)->abs()))) ; return tot_energy; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def overflow(H,r,h,N,R): tank_cap=3.14*r*r*H water_vol=3.14*r*r*h balls_vol=N*(4/3)*3.14*R*R*R vol=water_vol+balls_vol if vol>tank_cap : print("Overflow") else : print("Not in overflow state") H=10 r=5 h=5 N=2 R=2 overflow(H,r,h,N,R) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; H := 10 ; r := 5 ; h := 5 ; N := 2 ; R := 2 ; overflow(H, r, h, N, R); operation overflow(H : OclAny, r : OclAny, h : OclAny, N : OclAny, R : OclAny) pre: true post: true activity: var tank_cap : double := 3.14 * r * r * H ; var water_vol : double := 3.14 * r * r * h ; var balls_vol : double := N * (4 / 3) * 3.14 * R * R * R ; var vol : OclAny := water_vol + balls_vol ; if (vol->compareTo(tank_cap)) > 0 then ( execute ("Overflow")->display() ) else ( execute ("Not in overflow state")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) S=input() res=0 dp=[[0]*(N+1)for _ in range(N+1)] for i in reversed(range(N)): for j in reversed(range(i+1,N)): if S[i]==S[j]: dp[i][j]=max(dp[i][j],dp[i+1][j+1]+1) res=max(res,min(dp[i][j],j-i)) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : String := (OclFile["System.in"]).readLine() ; var res : int := 0 ; var dp : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)))) ; for i : (Integer.subrange(0, N-1))->reverse() do ( for j : (Integer.subrange(i + 1, N-1))->reverse() do ( if S[i+1] = S[j+1] then ( dp[i+1][j+1] := Set{dp[i+1][j+1], dp[i + 1+1][j + 1+1] + 1}->max() ) else skip ; res := Set{res, Set{dp[i+1][j+1], j - i}->min()}->max())) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def reverseWords(self,s): return ' '.join([word[: :-1]for word in s.split(' ')]) ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation reverseWords(s : OclAny) : OclAny pre: true post: true activity: return StringLib.sumStringsWithSeparator((s.split(' ')->select(word | true)->collect(word | (word(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))))), ' '); } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**7) debug=True debug=False def dprint(*objects): if debug==True : print(*objects) def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return sys.stdin.readline().strip() INF=10**18 MOD=10**9+7 def main(): N=II() S=SI() ans=-1 from collections import defaultdict posd=defaultdict(list) for i,c in enumerate(S): posd[c].append(i) for i in range(N): si=S[i] pos_list=posd[si] for pos in pos_list : if pos>=i : continue if pos>0 and S[pos-1]==S[i-1]: continue for j in range(N): if pos+j==i : break if i+j==N : break you=pos+j me=i+j if S[you]!=S[me]: break ans=max(ans,j) print(ans+1) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var debug : boolean := true ; debug := false ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var INF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; skip ; main(); operation dprint(objects : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name objects))) if debug = true then ( execute ((argument * (test (logical_test (comparison (expr (atom (name objects))))))))->display() ) else skip; operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation SI() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation main() pre: true post: true activity: var N : OclAny := II() ; var S : OclAny := SI() ; var ans : int := -1 ; skip ; var posd : OclAny := defaultdict(OclType["Sequence"]) ; for _tuple : Integer.subrange(1, (S)->size())->collect( _indx | Sequence{_indx-1, (S)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); (expr (atom (name posd)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name c)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; for i : Integer.subrange(0, N-1) do ( var si : OclAny := S[i+1] ; var pos_list : OclAny := posd[si+1] ; for pos : pos_list do ( if (pos->compareTo(i)) >= 0 then ( continue ) else skip ; if pos > 0 & S[pos - 1+1] = S[i - 1+1] then ( continue ) else skip ; for j : Integer.subrange(0, N-1) do ( if pos + j = i then ( break ) else skip ; if i + j = N then ( break ) else skip ; var you : OclAny := pos + j ; var me : OclAny := i + j ; if S[you+1] /= S[me+1] then ( break ) else skip ; ans := Set{ans, j}->max()))) ; execute (ans + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(x,N,S): candidate=set() for i in range(N-2*x+1): candidate.add(S[i : i+x]) if S[i+x : i+2*x]in candidate : return True return False def main(): n=int(input()) s=input().rstrip() l=0 r=n while lunion(()) ; for i : Integer.subrange(0, N - 2 * x + 1-1) do ( execute ((S.subrange(i+1, i + x)) : candidate) ; if (candidate)->includes(S.subrange(i + x+1, i + 2 * x)) then ( return true ) else skip) ; return false; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := input().rstrip() ; var l : int := 0 ; var r : int := n ; while (l->compareTo(r)) < 0 do ( var mid : int := (l + r + 1) div 2 ; if check(mid, n, s) then ( l := mid ) else ( r := mid - 1 )) ; execute ((l + r + 1) div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify import sys,bisect,math,itertools,pprint,fractions sys.setrecursionlimit(10**8) mod=10**9+7 INF=float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int,sys.stdin.readline().split())) n=inp() s=input() def z_algo(S): N=len(S) A=[0]*N i=1 ; j=0 A[0]=l=N while ikpow(8)) ; var mod : double := (10)->pow(9) + 7 ; var INF : double := ("" + (('inf')))->toReal() ; skip ; skip ; var n : OclAny := inp() ; var s : String := (OclFile["System.in"]).readLine() ; skip ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( var c : OclAny := z_algo(s.subrange(i+1)) ; for _tuple : Integer.subrange(1, (c)->size())->collect( _indx | Sequence{_indx-1, (c)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); var tmp : OclAny := Set{j, t}->min() ; res := Set{res, tmp}->max())) ; execute (res)->display(); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inpl() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation z_algo(S : OclAny) : OclAny pre: true post: true activity: var N : int := (S)->size() ; var A : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var i : int := 1; var j : int := 0 ; A->first() := N; var l : int := N ; while (i->compareTo(l)) < 0 do ( while (i + j->compareTo(l)) < 0 & S[j+1] = S[i + j+1] do ( j := j + 1) ; if not(j) then ( i := i + 1 ; continue ) else skip ; A[i+1] := j ; var k : int := 1 ; while (l - i->compareTo(k)) > 0 & (k < j - A[k+1]) do ( A[i + k+1] := A[k+1] ; k := k + 1) ; i := i + k; j := j - k) ; return A; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import random from collections import defaultdict from itertools import accumulate import sys input=sys.stdin.readline n=int(input()) s=input().rstrip() mod=(1<<61)-1 base=1000+random.randint(0,100) power=[1] for i in range(1,n): power.append((power[-1]*base)% mod) hvalue=[0] for i in range(n): hvalue.append((hvalue[-1]+(ord(s[i])*power[i]))% mod) def rollinghash(l,r): return((hvalue[r]-hvalue[l])*power[n-r])% mod def pun(i): dc=defaultdict(int) if i>n//2 : return False for j in range(n-i+1): x=rollinghash(j,i+j) if dc[x]: rg=dc[x] if rg<=j : return True else : dc[x]=i+j return False l=0 r=n//2+1 while l+1toInteger() ; var s : OclAny := input().rstrip() ; var mod : double := (1 * (2->pow(61))) - 1 ; var base : int := 1000 + (0 + (OclRandom.defaultInstanceOclRandom()).nextInt(100 - 0)) ; var power : Sequence := Sequence{ 1 } ; for i : Integer.subrange(1, n-1) do ( execute (((power->last() * base) mod mod) : power)) ; var hvalue : Sequence := Sequence{ 0 } ; for i : Integer.subrange(0, n-1) do ( execute (((hvalue->last() + ((s[i+1])->char2byte() * power[i+1])) mod mod) : hvalue)) ; skip ; skip ; l := 0 ; r := n div 2 + 1 ; while (l + 1->compareTo(r)) < 0 do ( var mi : int := (l + r) div 2 ; if pun(mi) then ( l := mi ) else ( r := mi )) ; execute (l)->display(); operation rollinghash(l : OclAny, r : OclAny) : OclAny pre: true post: true activity: return ((hvalue[r+1] - hvalue[l+1]) * power[n - r+1]) mod mod; operation pun(i : OclAny) : OclAny pre: true post: true activity: var dc : OclAny := defaultdict(OclType["int"]) ; if (i->compareTo(n div 2)) > 0 then ( return false ) else skip ; for j : Integer.subrange(0, n - i + 1-1) do ( var x : OclAny := rollinghash(j, i + j) ; if dc[x+1] then ( var rg : OclAny := dc[x+1] ; if (rg->compareTo(j)) <= 0 then ( return true ) else skip ) else ( dc[x+1] := i + j )) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def printArray(arr,Len): for i in range(Len): print(arr[i],end="") original_arr=[1,2,3,4,5] Len=len(original_arr) copied_arr=[0 for i in range(Len)] for i in range(Len): copied_arr[i]=original_arr[Len-i-1] print("Original array: ",end="") printArray(original_arr,Len) print("\nResultant array: ",end="") printArray(copied_arr,Len) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var original_arr : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ; Len := (original_arr)->size() ; var copied_arr : Sequence := Integer.subrange(0, Len-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, Len-1) do ( copied_arr[i+1] := original_arr[Len - i - 1+1]) ; execute ("Original array: ")->display() ; printArray(original_arr, Len) ; execute ("\nResultant array: ")->display() ; printArray(copied_arr, Len); operation printArray(arr : OclAny, Len : OclAny) pre: true post: true activity: for i : Integer.subrange(0, Len-1) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd as __gcd MAX=100 def recur(ind,cnt,last,a,n,k,dp): if(cnt==k): return 0 if(ind==n): return-10**9 if(dp[ind][cnt]!=-1): return dp[ind][cnt] ans=0 for i in range(ind,n): if(cnt % 2==0): ans=max(ans,recur(i+1,cnt+1,i,a,n,k,dp)) else : ans=max(ans,__gcd(a[last],a[i])+recur(i+1,cnt+1,0,a,n,k,dp)) dp[ind][cnt]=ans return ans a=[4,5,3,7,8,10,9,8] n=len(a) k=4 ; dp=[[-1 for i in range(MAX)]for i in range(n)] print(recur(0,0,0,a,n,k,dp)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MAX : int := 100 ; skip ; a := Sequence{4}->union(Sequence{5}->union(Sequence{3}->union(Sequence{7}->union(Sequence{8}->union(Sequence{10}->union(Sequence{9}->union(Sequence{ 8 }))))))) ; n := (a)->size() ; k := 4; ; dp := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (-1)))) ; execute (recur(0, 0, 0, a, n, k, dp))->display(); operation recur(ind : OclAny, cnt : OclAny, last : OclAny, a : OclAny, n : OclAny, k : OclAny, dp : OclAny) : OclAny pre: true post: true activity: if (cnt = k) then ( return 0 ) else skip ; if (ind = n) then ( return (-10)->pow(9) ) else skip ; if (dp[ind+1][cnt+1] /= -1) then ( return dp[ind+1][cnt+1] ) else skip ; var ans : int := 0 ; for i : Integer.subrange(ind, n-1) do ( if (cnt mod 2 = 0) then ( ans := Set{ans, recur(i + 1, cnt + 1, i, a, n, k, dp)}->max() ) else ( ans := Set{ans, __gcd(a[last+1], a[i+1]) + recur(i + 1, cnt + 1, 0, a, n, k, dp)}->max() )) ; dp[ind+1][cnt+1] := ans ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np ; import sys dp=np.zeros((1000,1000)); INT_MAX=sys.maxsize ; def isprime(num): if(num<=1): return False ; for i in range(2,int(num**(1/2))+1): if(num % i==0): return False ; return True ; def convert(s,i,j): temp=0 ; for k in range(i,j+1): temp=temp*10+(ord(s[k])-ord('0')); return temp ; def solve(s,i,j): num=convert(s,i,j); if(isprime(num)): return 0 ; if(i==j and isprime(num)): return 0 ; if(i==j and isprime(num)==False): return INT_MAX ; if(dp[i][j]): return dp[i][j]; ans=INT_MAX ; for k in range(i,j): left=solve(s,i,k); if(left==INT_MAX): continue ; right=solve(s,k+1,j); if(right==INT_MAX): continue ; ans=min(ans,1+left+right); dp[i][j]=ans ; return ans ; if __name__=="__main__" : s="2352" ; n=len(s); cuts=solve(s,0,n-1); if(cuts!=INT_MAX): print(cuts); else : print("Not Possible"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; ; skip ; var dp : Sequence := MatrixLib.singleValueMatrix(Sequence{1000, 1000}, 0.0); ; var INT_MAX : (trailer . (name maxsize)) := (trailer . (name maxsize)); ; skip ; skip ; skip ; if __name__ = "__main__" then ( s := "2352"; ; var n : int := (s)->size(); ; var cuts : OclAny := solve(s, 0, n - 1); ; if (cuts /= INT_MAX) then ( execute (cuts)->display(); ) else ( execute ("Not Possible")->display(); ) ) else skip; operation isprime(num : OclAny) pre: true post: true activity: if (num <= 1) then ( return false; ) else skip ; for i : Integer.subrange(2, ("" + (((num)->pow((1 / 2)))))->toInteger() + 1-1) do ( if (num mod i = 0) then ( return false; ) else skip) ; return true;; operation convert(s : OclAny, i : OclAny, j : OclAny) pre: true post: true activity: var temp : int := 0; ; for k : Integer.subrange(i, j + 1-1) do ( temp := temp * 10 + ((s[k+1])->char2byte() - ('0')->char2byte());) ; return temp;; operation solve(s : OclAny, i : OclAny, j : OclAny) pre: true post: true activity: num := convert(s, i, j); ; if (isprime(num)) then ( return 0; ) else skip ; if (i = j & isprime(num)) then ( return 0; ) else skip ; if (i = j & isprime(num) = false) then ( return INT_MAX; ) else skip ; if (dp[i+1][j+1]) then ( return dp[i+1][j+1]; ) else skip ; var ans : OclAny := INT_MAX; ; for k : Integer.subrange(i, j-1) do ( var left : OclAny := solve(s, i, k); ; if (left = INT_MAX) then ( continue; ) else skip ; var right : OclAny := solve(s, k + 1, j); ; if (right = INT_MAX) then ( continue; ) else skip ; ans := Set{ans, 1 + left + right}->min();) ; dp[i+1][j+1] := ans; ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def zzis(arr,n): Z=[[1 for i in range(2)]for i in range(n)] res=1 for i in range(1,n): for j in range(i): if(arr[j]arr[i]and Z[i][1]union(Sequence{22}->union(Sequence{9}->union(Sequence{33}->union(Sequence{49}->union(Sequence{50}->union(Sequence{31}->union(Sequence{ 60 }))))))) ; n := (arr)->size() ; execute ("Length of Longest Zig-Zag subsequence is")->display(); operation zzis(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var Z : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, 2-1)->select(i | true)->collect(i | (1)))) ; var res : int := 1 ; for i : Integer.subrange(1, n-1) do ( for j : Integer.subrange(0, i-1) do ( if ((arr[j+1]->compareTo(arr[i+1])) < 0 & (Z[i+1]->first()->compareTo(Z[j+1][1+1] + 1)) < 0) then ( Z[i+1]->first() := Z[j+1][1+1] + 1 ) else skip ; if ((arr[j+1]->compareTo(arr[i+1])) > 0 & (Z[i+1][1+1]->compareTo(Z[j+1]->first() + 1)) < 0) then ( Z[i+1][1+1] := Z[j+1]->first() + 1 ) else skip) ; if ((res->compareTo(Set{Z[i+1]->first(), Z[i+1][1+1]}->max())) < 0) then ( res := Set{Z[i+1]->first(), Z[i+1][1+1]}->max() ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- try : while True : s,w,h=map(float,input().split(",")) bmi=w/(h*h) if bmi>=25.0 : print(int(s)) except : pass ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: try ( while true do ( var s : OclAny := null; var w : OclAny := null; var h : OclAny := null; Sequence{s,w,h} := (input().split(","))->collect( _x | (OclType["double"])->apply(_x) ) ; var bmi : double := w / (h * h) ; if bmi >= 25.0 then ( execute (("" + ((s)))->toInteger())->display() ) else skip)) catch (_e : OclException) do ( skip) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys for l in sys.stdin.readlines(): data=l.split(",") x,y=float(data[1]),float(data[2]) if 25.0<=x/y**2 : print(data[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for l : (OclFile["System.in"]).readlines() do ( var data : OclAny := l.split(",") ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{("" + ((data[1+1])))->toReal(),("" + ((data[2+1])))->toReal()} ; if 25.0 <= x / (y)->pow(2) then ( execute (data->first())->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_input(): while True : try : yield ''.join(input()) except EOFError : break N=list(get_input()) for l in range(len(N)): S,W,H=N[l].split(",") s=int(S) w=float(W) h=float(H) BMI=w/h**2 if BMI>=25.0 : print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : Sequence := (OclIterator.newOclIterator_Function(lambda _i : int in self.get_input(_i))) ; for l : Integer.subrange(0, (N)->size()-1) do ( var S : OclAny := null; var W : OclAny := null; var H : OclAny := null; Sequence{S,W,H} := N[l+1].split(",") ; var s : int := ("" + ((S)))->toInteger() ; var w : double := ("" + ((W)))->toReal() ; var h : double := ("" + ((H)))->toReal() ; var BMI : double := w / (h)->pow(2) ; if BMI >= 25.0 then ( execute (s)->display() ) else skip); operation get_input(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; while true do ( try ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return StringLib.sumStringsWithSeparator(((OclFile["System.in"]).readLine()), '')) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=int(1e9+7) n=int(input()) arr=list(map(int,input().split())) arr.sort() l=1 ; r=0 for i in range(n): r=(r+l*arr[i])% MOD l=l*2 % MOD l=1 for i in range(n-1,-1,-1): r=(r-l*arr[i])% MOD l=l*2 % MOD print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : int := ("" + ((("1e9")->toReal() + 7)))->toInteger() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := arr->sort() ; var l : int := 1; var r : int := 0 ; for i : Integer.subrange(0, n-1) do ( r := (r + l * arr[i+1]) mod MOD ; l := l * 2 mod MOD) ; l := 1 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( r := (r - l * arr[i+1]) mod MOD ; l := l * 2 mod MOD) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=1000000007 def product(ar,n): result=1 for i in range(0,n): result=(result*ar[i])% MOD return result ar=[1,2,3,4,5] n=len(ar) print(product(ar,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : int := 1000000007 ; skip ; ar := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ; n := (ar)->size() ; execute (product(ar, n))->display(); operation product(ar : OclAny, n : OclAny) : OclAny pre: true post: true activity: var result : int := 1 ; for i : Integer.subrange(0, n-1) do ( result := (result * ar[i+1]) mod MOD) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bmi(s,w,h): if w/h**2>=25 : print(s) while(1): try : s,w,h=[i for i in input().split(",")] s=int(s) w=float(w) h=float(h) bmi(s,w,h) except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while (1) do ( try ( Sequence{s,w,h} := input().split(",")->select(i | true)->collect(i | (i)) ; s := ("" + ((s)))->toInteger() ; w := ("" + ((w)))->toReal() ; h := ("" + ((h)))->toReal() ; bmi(s, w, h)) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); operation bmi(s : OclAny, w : OclAny, h : OclAny) pre: true post: true activity: if w / (h)->pow(2) >= 25 then ( execute (s)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[] while 1 : try : n,w,h=map(float,input().split(',')) except : for i in a : print(i) break if w/h**2>=25 : a.append(int(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Sequence{} ; while 1 do ( try ( var n : OclAny := null; var w : OclAny := null; var h : OclAny := null; Sequence{n,w,h} := (input().split(','))->collect( _x | (OclType["double"])->apply(_x) )) catch (_e : OclException) do ( for i : a do ( execute (i)->display()) ; break) ; if w / (h)->pow(2) >= 25 then ( execute ((("" + ((n)))->toInteger()) : a) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=a-30 x=divmod(b,2) print(x[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : double := a - 30 ; var x : OclAny := Sequence{(b div 2), (b mod 2)} ; execute (x->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(float,input().split())) arr=sorted([x-int(x)for x in arr if x-int(x)!=0]) o=2*n-len(arr) arr_sum=sum(arr) res=int(2e9) for i in range(n+1): if i+o>=n : res=min(res,abs(i-arr_sum)) print("%.3f" % res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["double"])->apply(_x) )) ; arr := arr->select(x | x - ("" + ((x)))->toInteger() /= 0)->collect(x | (x - ("" + ((x)))->toInteger()))->sort() ; var o : double := 2 * n - (arr)->size() ; var arr_sum : OclAny := (arr)->sum() ; var res : int := ("" + ((("2e9")->toReal())))->toInteger() ; for i : Integer.subrange(0, n + 1-1) do ( if (i + o->compareTo(n)) >= 0 then ( res := Set{res, (i - arr_sum)->abs()}->min() ) else skip) ; execute (StringLib.format("%.3f",res))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fah(F): C=int((F-30)/2) return C f=int(input()) print(fah(f)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var f : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (fah(f))->display(); operation fah(F : OclAny) : OclAny pre: true post: true activity: var C : int := ("" + (((F - 30) / 2)))->toInteger() ; return C; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print((int(input())-30)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger() - 30) div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) print('{:.0f}'.format((a-30)/2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (StringLib.interpolateStrings('{:.0f}', Sequence{(a - 30) / 2}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def F(f): return(f-30)//2 a=int(input()) print(F(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (F(a))->display(); operation F(f : OclAny) : OclAny pre: true post: true activity: return (f - 30) div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- list_w=[] for x in range(10): x=int(input()) list_w.append(x) list_k=[] for y in range(10): y=int(input()) list_k.append(y) list_w.sort() list_k.sort() a=list_w[9]+list_w[8]+list_w[7] b=list_k[9]+list_k[8]+list_k[7] print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var list_w : Sequence := Sequence{} ; for x : Integer.subrange(0, 10-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((x) : list_w)) ; var list_k : Sequence := Sequence{} ; for y : Integer.subrange(0, 10-1) do ( var y : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((y) : list_k)) ; list_w := list_w->sort() ; list_k := list_k->sort() ; var a : OclAny := list_w[9+1] + list_w[8+1] + list_w[7+1] ; var b : OclAny := list_k[9+1] + list_k[8+1] + list_k[7+1] ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w1=int(input()) w2=int(input()) w3=int(input()) w4=int(input()) w5=int(input()) w6=int(input()) w7=int(input()) w8=int(input()) w9=int(input()) w10=int(input()) k1=int(input()) k2=int(input()) k3=int(input()) k4=int(input()) k5=int(input()) k6=int(input()) k7=int(input()) k8=int(input()) k9=int(input()) k10=int(input()) waseda=[w1,w2,w3,w4,w5,w6,w7,w8,w9,w10] keio=[k1,k2,k3,k4,k5,k6,k7,k8,k9,k10] waseda.sort() keio.sort() w=waseda[7]+waseda[8]+waseda[9] k=keio[7]+keio[8]+keio[9] print(w,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w2 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w3 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w4 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w5 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w6 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w7 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w8 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w9 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w10 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k2 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k3 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k4 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k5 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k6 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k7 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k8 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k9 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k10 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var waseda : Sequence := Sequence{w1}->union(Sequence{w2}->union(Sequence{w3}->union(Sequence{w4}->union(Sequence{w5}->union(Sequence{w6}->union(Sequence{w7}->union(Sequence{w8}->union(Sequence{w9}->union(Sequence{ w10 }))))))))) ; var keio : Sequence := Sequence{k1}->union(Sequence{k2}->union(Sequence{k3}->union(Sequence{k4}->union(Sequence{k5}->union(Sequence{k6}->union(Sequence{k7}->union(Sequence{k8}->union(Sequence{k9}->union(Sequence{ k10 }))))))))) ; waseda := waseda->sort() ; keio := keio->sort() ; var w : OclAny := waseda[7+1] + waseda[8+1] + waseda[9+1] ; var k : OclAny := keio[7+1] + keio[8+1] + keio[9+1] ; execute (w)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): W=sorted([int(input())for _ in range(10)],reverse=True) S=sorted([int(input())for _ in range(10)],reverse=True) print(W[0]+W[1]+W[2],S[0]+S[1]+S[2]) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var W : Sequence := Integer.subrange(0, 10-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var S : Sequence := Integer.subrange(0, 10-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; execute (W->first() + W[1+1] + W[2+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def product(ar,n): result=1 for i in range(0,n): result=result*ar[i] return result ar=[1,2,3,4,5] n=len(ar) print(product(ar,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; ar := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ; n := (ar)->size() ; execute (product(ar, n))->display(); operation product(ar : OclAny, n : OclAny) : OclAny pre: true post: true activity: var result : int := 1 ; for i : Integer.subrange(0, n-1) do ( result := result * ar[i+1]) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- W=[] K=[] i=0 while i<10 : s=int(input()) W.append(s) i+=1 W.sort() while 10<=i and i<20 : s=int(input()) K.append(s) i+=1 K.sort() sum1=0 sum2=0 for i in range(7,10): sum1+=W[i] for i in range(7,10): sum2+=K[i] print(f'{sum1}{sum2}') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var W : Sequence := Sequence{} ; var K : Sequence := Sequence{} ; var i : int := 0 ; while i < 10 do ( var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((s) : W) ; i := i + 1) ; W := W->sort() ; while 10 <= i & i < 20 do ( s := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((s) : K) ; i := i + 1) ; K := K->sort() ; var sum1 : int := 0 ; var sum2 : int := 0 ; for i : Integer.subrange(7, 10-1) do ( sum1 := sum1 + W[i+1]) ; for i : Integer.subrange(7, 10-1) do ( sum2 := sum2 + K[i+1]) ; execute (StringLib.formattedString('{sum1}{sum2}'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lst=[] for i in range(20): r=int(input()) lst.append(r) for i in range(10): for j in range(9,i,-1): if lst[j]toInteger() ; execute ((r) : lst)) ; for i : Integer.subrange(0, 10-1) do ( for j : Integer.subrange(i + 1, 9)->reverse() do ( if (lst[j+1]->compareTo(lst[j - 1+1])) < 0 then ( var lst[j+1] : OclAny := null; var lst[j - 1+1] : OclAny := null; Sequence{lst[j+1],lst[j - 1+1]} := Sequence{lst[j - 1+1],lst[j+1]} ) else skip)) ; for i : Integer.subrange(10, 20-1) do ( for j : Integer.subrange(i + 1, 19)->reverse() do ( if (lst[j+1]->compareTo(lst[j - 1+1])) < 0 then ( var lst[j+1] : OclAny := null; var lst[j - 1+1] : OclAny := null; Sequence{lst[j+1],lst[j - 1+1]} := Sequence{lst[j - 1+1],lst[j+1]} ) else skip)) ; var W : OclAny := lst[9+1] + lst[8+1] + lst[7+1] ; var K : OclAny := lst[19+1] + lst[18+1] + lst[17+1] ; execute (W)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) n=N A=list(map(float,input().strip().split(' '))) z=0 for i in range(len(A)): A[i]=round(A[i],3)-int(A[i]) if A[i]==0 : z+=1 ANS=sum(A) ans=10**10 for j in range(n-z,n+1): ans=min(ans,abs(ANS-j)) print("%.3f" % ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := N ; var A : Sequence := ((input()->trim().split(' '))->collect( _x | (OclType["double"])->apply(_x) )) ; var z : int := 0 ; for i : Integer.subrange(0, (A)->size()-1) do ( A[i+1] := MathLib.roundN(A[i+1], 3) - ("" + ((A[i+1])))->toInteger() ; if A[i+1] = 0 then ( z := z + 1 ) else skip) ; var ANS : OclAny := (A)->sum() ; var ans : double := (10)->pow(10) ; for j : Integer.subrange(n - z, n + 1-1) do ( ans := Set{ans, (ANS - j)->abs()}->min()) ; execute (StringLib.format("%.3f",ans))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) m=10**9+7 if a>b : print(0) else : r=1 for i in range(b-a+1,b+1): r*=i r %=m print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : double := (10)->pow(9) + 7 ; if (a->compareTo(b)) > 0 then ( execute (0)->display() ) else ( var r : int := 1 ; for i : Integer.subrange(b - a + 1, b + 1-1) do ( r := r * i ; r := r mod m) ; execute (r)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import collections import bisect import itertools import fractions import copy import decimal import queue sys.setrecursionlimit(10000001) INF=10**16 MOD=10**9+7 ni=lambda : int(sys.stdin.readline()) ns=lambda : map(int,sys.stdin.readline().split()) na=lambda : list(map(int,sys.stdin.readline().split())) def main(): n,k=ns() if n>k : print(0) exit() a=math.factorial(k) b=math.factorial(k-n) ans=a//b % MOD print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(10000001) ; var INF : double := (10)->pow(16) ; var MOD : double := (10)->pow(9) + 7 ; var ni : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var ns : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var na : Function := lambda $$ : OclAny in (((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ns->apply() ; if (n->compareTo(k)) > 0 then ( execute (0)->display() ; exit() ) else skip ; var a : long := MathLib.factorial(k) ; var b : long := MathLib.factorial(k - n) ; var ans : int := a div b mod MOD ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import factorial def solve(n,k): if n>k : return 0 return factorial(k)//factorial(k-n)%(10**9+7) def main(args): n,k=map(int,input().split()) ans=solve(n,k) print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (n->compareTo(k)) > 0 then ( return 0 ) else skip ; return factorial(k) div factorial(k - n) mod ((10)->pow(9) + 7); operation main(args : OclAny) pre: true post: true activity: Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : OclAny := solve(n, k) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Fermat : def __init__(self,size,mod): self.size=size self.mod=mod self.factorial=[1] self.inverse=[1] pre_f=1 for i in range(1,self.size+1): pre_f=(pre_f*i)% self.mod self.factorial.append(pre_f) self.inverse.append(pow(pre_f,self.mod-2,self.mod)) def comb(self,n,r): if nexists( _x | result = _x ); attribute size : OclAny := size; attribute mod : OclAny := mod; attribute factorial : Sequence := Sequence{ 1 }; attribute inverse : Sequence := Sequence{ 1 }; operation initialise(size : OclAny,mod : OclAny) : Fermat pre: true post: true activity: self.size := size ; self.mod := mod ; self.factorial := Sequence{ 1 } ; self.inverse := Sequence{ 1 } ; var pre_f : int := 1 ; for i : Integer.subrange(1, self.size + 1-1) do ( pre_f := (pre_f * i) mod self.mod ; (expr (atom (name self)) (trailer . (name factorial)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name pre_f)))))))) )))) ; (expr (atom (name self)) (trailer . (name inverse)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name pow)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name pre_f))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name self)) (trailer . (name mod))) - (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (atom (name self)) (trailer . (name mod)))))))) ))))))))) ))))); return self; operation comb(n : OclAny,r : OclAny) : OclAny pre: true post: true activity: if (n->compareTo(r)) < 0 then ( return 0 ) else ( return (self.factorial[n+1] * self.inverse[r+1] * self.inverse[n - r+1]) mod self.mod ); operation perm(n : OclAny,r : OclAny) : OclAny pre: true post: true activity: if (n->compareTo(r)) < 0 then ( return 0 ) else ( return (self.factorial[n+1] * self.inverse[n - r+1]) mod self.mod ); } class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var Fermat : Fermat := (Fermat.newFermat()).initialise(1000, (10)->pow(9) + 7) ; var k : OclAny := null; Sequence{n,k} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute ((Fermat.newFermat()).initialise.perm(k, n))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10000) memo=[1,1] def fact(a): if len(memo)>a : return memo[a] b=a*fact(a-1) memo.append(b) return b n,k=map(int,input().split()) if n>k : ans=0 else : ans=fact(k)//fact(k-n) print(ans % 1000000007) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(10000) ; var memo : Sequence := Sequence{1}->union(Sequence{ 1 }) ; skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (n->compareTo(k)) > 0 then ( var ans : int := 0 ) else ( ans := fact(k) div fact(k - n) ) ; execute (ans mod 1000000007)->display(); operation fact(a : OclAny) : OclAny pre: true post: true activity: if ((memo)->size()->compareTo(a)) > 0 then ( return memo[a+1] ) else skip ; var b : double := a * fact(a - 1) ; execute ((b) : memo) ; return b; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=int(input()) a=[] for i in range(4): x=int(input()) a.append(x) r1=0 r2=0 if a[0]% a[2]==0 : r1=a[0]//a[2] else : r1=a[0]//a[2]+1 if a[1]% a[3]==0 : r2=a[1]//a[3] else : r2=a[1]//a[3]+1 print(l-max(r1,r2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, 4-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((x) : a)) ; var r1 : int := 0 ; var r2 : int := 0 ; if a->first() mod a[2+1] = 0 then ( r1 := a->first() div a[2+1] ) else ( r1 := a->first() div a[2+1] + 1 ) ; if a[1+1] mod a[3+1] = 0 then ( r2 := a[1+1] div a[3+1] ) else ( r2 := a[1+1] div a[3+1] + 1 ) ; execute (l - Set{r1, r2}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- L,A,B,C,D=[int(input())for i in range(5)] a,b=(A-1)//C+1,(B-1)//D+1 if b>a : a=b print(L-a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var L : OclAny := null; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var D : OclAny := null; Sequence{L,A,B,C,D} := Integer.subrange(0, 5-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{(A - 1) div C + 1,(B - 1) div D + 1} ; if (b->compareTo(a)) > 0 then ( var a : OclAny := b ) else skip ; execute (L - a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin from math import ceil input=stdin.readline def main(args): L=int(input()) A=int(input()) B=int(input()) C=int(input()) D=int(input()) days_to_finish_A=ceil(A/C) days_to_finish_B=ceil(B/D) print(L-max(days_to_finish_A,days_to_finish_B)) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := stdin.readline ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation main(args : OclAny) pre: true post: true activity: var L : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var C : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var D : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var days_to_finish_A : OclAny := ceil(A / C) ; var days_to_finish_B : OclAny := ceil(B / D) ; execute (L - Set{days_to_finish_A, days_to_finish_B}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def totEdge(n): result=(n*(n-1))//2 return result if __name__=="__main__" : n=6 print(totEdge(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 6 ; execute (totEdge(n))->display() ) else skip; operation totEdge(n : OclAny) : OclAny pre: true post: true activity: var result : int := (n * (n - 1)) div 2 ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a=[int(input())for i in range(5)] b=sorted([math.ceil(a[1]/a[3]),math.ceil(a[2]/a[4])]) print(a[0]-b[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : Sequence := Integer.subrange(0, 5-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var b : Sequence := Sequence{(a[1+1] / a[3+1])->ceil()}->union(Sequence{ (a[2+1] / a[4+1])->ceil() })->sort() ; execute (a->first() - b->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input for _ in range(int(I())): n=int(I()) a=list(map(int,I().split())) res=[] for i in range(1,n): md=a.index(min(a)) if md : res.append([i,i+md,md]) a=a[: md]+a[md+1 :] print(len(res)) for i in res : print(*i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; for _anon : Integer.subrange(0, ("" + ((I())))->toInteger()-1) do ( var n : int := ("" + ((I())))->toInteger() ; var a : Sequence := ((I().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : Sequence := Sequence{} ; for i : Integer.subrange(1, n-1) do ( var md : int := a->indexOf((a)->min()) - 1 ; if md then ( execute ((Sequence{i}->union(Sequence{i + md}->union(Sequence{ md }))) : res) ) else skip ; a := a.subrange(1,md) + a.subrange(md + 1+1)) ; execute ((res)->size())->display() ; for i : res do ( execute ((argument * (test (logical_test (comparison (expr (atom (name i))))))))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math l=int(input()) a=int(input()) b=int(input()) c=int(input()) d=int(input()) j_day=a//c j_amr=a % c if(j_amr!=0): j_day=j_day+1 m_day=b//d m_amr=b % d if(m_amr!=0): m_day=m_day+1 if(j_day>=m_day): study_day=j_day else : study_day=m_day day=l-study_day print(day) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var j_day : int := a div c ; var j_amr : int := a mod c ; if (j_amr /= 0) then ( j_day := j_day + 1 ) else skip ; var m_day : int := b div d ; var m_amr : int := b mod d ; if (m_amr /= 0) then ( m_day := m_day + 1 ) else skip ; if ((j_day->compareTo(m_day)) >= 0) then ( var study_day : int := j_day ) else ( study_day := m_day ) ; var day : double := l - study_day ; execute (day)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) ans=1 for _ in range(n): ans*=k ans %=1000000007 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 1 ; for _anon : Integer.subrange(0, n-1) do ( ans := ans * k ; ans := ans mod 1000000007) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import lru_cache mod=1000000007 n,k=[int(i)for i in input().split(" ")] @ lru_cache() def power(m,n,mod): if n==0 : return 1 elif n==1 : return m elif n % 2==0 : return((power(m,n//2,mod)% mod)*(power(m,n//2,mod)% mod))% mod else : return(power(m,n-1,mod)*m)% mod print(power(k,n,mod)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var mod : int := 1000000007 ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; (compound_stmt (decorator @ (dotted_name (name lru_cache)) ( )) (funcdef def (name power) ( (typedargslist (def_parameters (def_parameter (named_parameter (name m))) , (def_parameter (named_parameter (name n))) , (def_parameter (named_parameter (name mod))))) ) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name n)))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name n)))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name m)))))))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (expr (atom (name n))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name power)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name m))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) // (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (atom (name mod)))))))) )))) % (expr (atom (name mod)))))))) ))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name power)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name m))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) // (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (atom (name mod)))))))) )))) % (expr (atom (name mod)))))))) )))))))) ))) % (expr (atom (name mod))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name power)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name m))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name mod)))))))) )))) * (expr (atom (name m)))))))) ))) % (expr (atom (name mod)))))))))))))))))) ; execute (power(k, n, mod))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.readline().strip() def list2d(a,b,c): return[[c]*b for i in range(a)] def list3d(a,b,c,d): return[[[d]*c for j in range(b)]for i in range(a)] def list4d(a,b,c,d,e): return[[[[e]*d for j in range(c)]for j in range(b)]for i in range(a)] def ceil(x,y=1): return int(-(-x//y)) def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(N=None): return list(MAP())if N is None else[INT()for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 EPS=10**-10 N,K=MAP() ans=K**N % MOD print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; var EPS : double := (10)->pow(-10) ; var K : OclAny := null; Sequence{N,K} := MAP() ; var ans : int := (K)->pow(N) mod MOD ; execute (ans)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation list2d(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, a-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ c }, b))); operation list3d(a : OclAny, b : OclAny, c : OclAny, d : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, a-1)->select(i | true)->collect(i | (Integer.subrange(0, b-1)->select(j | true)->collect(j | (MatrixLib.elementwiseMult(Sequence{ d }, c))))); operation list4d(a : OclAny, b : OclAny, c : OclAny, d : OclAny, e : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, a-1)->select(i | true)->collect(i | (Integer.subrange(0, b-1)->select(j | true)->collect(j | (Integer.subrange(0, c-1)->select(j | true)->collect(j | (MatrixLib.elementwiseMult(Sequence{ e }, d))))))); operation ceil(x : OclAny, y : int) : OclAny pre: true post: true activity: if y->oclIsUndefined() then y := 1 else skip; return ("" + ((-(-x div y))))->toInteger(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST(N : OclAny) : OclAny pre: true post: true activity: if N->oclIsUndefined() then N := null else skip; return if N <>= null then (MAP()) else Integer.subrange(0, N-1)->select(i | true)->collect(i | (INT())) endif; operation Yes() pre: true post: true activity: execute ('Yes')->display(); operation No() pre: true post: true activity: execute ('No')->display(); operation YES() pre: true post: true activity: execute ('YES')->display(); operation NO() pre: true post: true activity: execute ('NO')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect,collections,copy,heapq,itertools,math,string,sys input=lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF=float('inf') MOD=10**9+7 def I(): return int(input()) def F(): return float(input()) def SS(): 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 LSS(): return input().split() def resolve(): n,k=LI() ans=pow(k,n,MOD) print(ans) if __name__=='__main__' : resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; sys.setrecursionlimit((10)->pow(7)) ; var INF : double := ("" + (('inf')))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( resolve() ) else skip; operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation SS() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation LI() : OclAny pre: true post: true activity: return input->apply().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return input->apply().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return input->apply().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LSS() : OclAny pre: true post: true activity: return input->apply().split(); operation resolve() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := LI() ; var ans : double := (k)->pow(n) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def way1(ball,box): ans=pow(box,ball,MOD) return ans n,k=map(int,input().split()) MOD=10**9+7 print(way1(n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var MOD : double := (10)->pow(9) + 7 ; execute (way1(n, k))->display(); operation way1(ball : OclAny, box : OclAny) : OclAny pre: true post: true activity: var ans : double := (box)->pow(ball) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CountTheElements(arr,n,k): counter=0 for i in range(0,n,1): if(arr[i]% k==0): counter=counter+1 return counter if __name__=='__main__' : arr=[2,6,7,12,14,18]; n=len(arr) k=3 print(CountTheElements(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{2}->union(Sequence{6}->union(Sequence{7}->union(Sequence{12}->union(Sequence{14}->union(Sequence{ 18 }))))); ; n := (arr)->size() ; k := 3 ; execute (CountTheElements(arr, n, k))->display() ) else skip; operation CountTheElements(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var counter : int := 0 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (arr[i+1] mod k = 0) then ( counter := counter + 1 ) else skip) ; return counter; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,v=map(int,input().split()) if n<=v : cost=n-1 else : f=n-v cost=0 cost+=(1*v) if f>1 : for i in range(1,f): cost+=(i+1) print(cost) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var v : OclAny := null; Sequence{n,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (n->compareTo(v)) <= 0 then ( var cost : double := n - 1 ) else ( var f : double := n - v ; cost := 0 ; cost := cost + (1 * v) ; if f > 1 then ( for i : Integer.subrange(1, f-1) do ( cost := cost + (i + 1)) ) else skip ) ; execute (cost)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,v=map(int,input().split()) print((v+(n-v)*(n-v+1)//2,n)[v>n]-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var v : OclAny := null; Sequence{n,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Sequence{v + (n - v) * (n - v + 1) div 2, n}->select((v->compareTo(n)) > 0) - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) d=[10*[0]for _ in range(10)] ans=0 for i in range(1,n+1): s=str(i) if s[0]=="0" or s[-1]=="0" : continue d[int(s[0])][int(s[-1])]+=1 for i in range(1,10): for j in range(i,10): if i==j : ans+=d[i][j]*d[j][i] else : ans+=d[i][j]*d[j][i]*2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Sequence := Integer.subrange(0, 10-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 10))) ; var ans : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( var s : String := ("" + ((i))) ; if s->first() = "0" or s->last() = "0" then ( continue ) else skip ; d[("" + ((s->first())))->toInteger()+1][("" + ((s->last())))->toInteger()+1] := d[("" + ((s->first())))->toInteger()+1][("" + ((s->last())))->toInteger()+1] + 1) ; for i : Integer.subrange(1, 10-1) do ( for j : Integer.subrange(i, 10-1) do ( if i = j then ( ans := ans + d[i+1][j+1] * d[j+1][i+1] ) else ( ans := ans + d[i+1][j+1] * d[j+1][i+1] * 2 ))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import* import math def numline(f=int): return map(f,input().split()) n=int(input()) a=list(filter(lambda x : x!=0,numline(lambda s : int(s.split('.')[1])))) c0=min(2*n-len(a),len(a)) s=sum(a)-1000*min(n,len(a)) ans=abs(s) for i in range(c0): s+=1000 ans=min(ans,abs(s)) print('{}.{:0>3}'.format(ans//1000,ans % 1000)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((numline(lambda s : OclAny in (("" + ((s.split('.')[1+1])))->toInteger())))->select( _x | (lambda x : OclAny in (x /= 0))->apply(_x) = true )) ; var c0 : OclAny := Set{2 * n - (a)->size(), (a)->size()}->min() ; var s : double := (a)->sum() - 1000 * Set{n, (a)->size()}->min() ; var ans : double := (s)->abs() ; for i : Integer.subrange(0, c0-1) do ( s := s + 1000 ; ans := Set{ans, (s)->abs()}->min()) ; execute (StringLib.interpolateStrings('{}.{:0>3}', Sequence{ans div 1000, ans mod 1000}))->display(); operation numline(f : OclAny) : OclAny pre: true post: true activity: if f->oclIsUndefined() then f := OclType["int"] else skip; return (input().split())->collect( _x | (f)->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,v=list(map(int,input().split())) ans=0 if n-1>=v : ans+=v else : ans+=n-1 for i in range(2,(n-v)+1): ans+=i print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var v : OclAny := null; Sequence{n,v} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; if (n - 1->compareTo(v)) >= 0 then ( ans := ans + v ) else ( ans := ans + n - 1 ) ; for i : Integer.subrange(2, (n - v) + 1-1) do ( ans := ans + i) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,v=map(int,input().split()) cur_energi=0 cost=0 for i in range(1,n): if vcollect( _x | (OclType["int"])->apply(_x) ) ; var cur_energi : int := 0 ; var cost : int := 0 ; for i : Integer.subrange(1, n-1) do ( if (v->compareTo(n - i + 1)) < 0 then ( var Ac : double := (v - cur_energi) * i ; cost := cost + Ac ; cur_energi := cur_energi + Ac div i ) else ( var need_litrs : double := (n - i) - cur_energi ; Ac := need_litrs * i ; cost := cost + Ac ; cur_energi := cur_energi + Ac div i ) ; cur_energi := cur_energi - 1) ; execute (cost)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,v=map(int,input().split()) money=0 money=v gas=v if v>=n : print(n-1) else : for i in range(1,n+1): if n-i<=gas : if i!=1 : money+=i print(money) check=1 i=200 break if i==1 : continue money+=i if check!=1 : print(money) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var v : OclAny := null; Sequence{n,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var money : int := 0 ; money := v ; var gas : OclAny := v ; if (v->compareTo(n)) >= 0 then ( execute (n - 1)->display() ) else ( for i : Integer.subrange(1, n + 1-1) do ( if (n - i->compareTo(gas)) <= 0 then ( if i /= 1 then ( money := money + i ) else skip ; execute (money)->display() ; var check : int := 1 ; var i : int := 200 ; break ) else skip ; if i = 1 then ( continue ) else skip ; money := money + i) ; if check /= 1 then ( execute (money)->display() ) else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def exclude(a,n): count=0 for i in range(0,n): s=0 maximum=0 for j in range(i,min(n,i+60)): s+=a[j] maximum=max(a[j],maximum) if s % 2==0 and 2*maximum>s : count+=1 return count def countSubarrays(a,n): for i in range(0,n): a[i]=bin(a[i]).count('1') pre=[None]*n for i in range(0,n): pre[i]=a[i] if i!=0 : pre[i]+=pre[i-1] odd,even=0,0 for i in range(0,n): if pre[i]& 1 : odd+=1 even=n-odd even+=1 answer=((odd*(odd-1)//2)+(even*(even-1)//2)) print(answer) answer=answer-exclude(a,n) return answer if __name__=="__main__" : a=[6,7,14] n=len(a) print(countSubarrays(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( a := Sequence{6}->union(Sequence{7}->union(Sequence{ 14 })) ; n := (a)->size() ; execute (countSubarrays(a, n))->display() ) else skip; operation exclude(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( var s : int := 0 ; var maximum : int := 0 ; for j : Integer.subrange(i, Set{n, i + 60}->min()-1) do ( s := s + a[j+1] ; maximum := Set{a[j+1], maximum}->max() ; if s mod 2 = 0 & (2 * maximum->compareTo(s)) > 0 then ( count := count + 1 ) else skip)) ; return count; operation countSubarrays(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( a[i+1] := bin(a[i+1])->count('1')) ; var pre : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; for i : Integer.subrange(0, n-1) do ( pre[i+1] := a[i+1] ; if i /= 0 then ( pre[i+1] := pre[i+1] + pre[i - 1+1] ) else skip) ; var odd : OclAny := null; var even : OclAny := null; Sequence{odd,even} := Sequence{0,0} ; for i : Integer.subrange(0, n-1) do ( if MathLib.bitwiseAnd(pre[i+1], 1) then ( odd := odd + 1 ) else skip) ; var even : double := n - odd ; even := even + 1 ; var answer : int := ((odd * (odd - 1) div 2) + (even * (even - 1) div 2)) ; execute (answer)->display() ; answer := answer - exclude(a, n) ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lexicoSmallestPermuatation(arr,n): cnt=[0 for i in range(n+1)] for i in range(n): cnt[arr[i]]+=1 ele=1 replacement=0 vis=[0 for i in range(n+1)] for i in range(n): if(cnt[arr[i]]==1): continue while(cnt[ele]): ele+=1 if(ele>arr[i]and vis[arr[i]]==0): vis[arr[i]]=1 ; else : cnt[arr[i]]-=1 arr[i]=ele replacement+=1 ele+=1 print(replacement) for i in range(n): print(arr[i],end=" ") if __name__=='__main__' : arr=[2,3,4,3,2] sz=len(arr) lexicoSmallestPermuatation(arr,sz) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{3}->union(Sequence{ 2 })))) ; var sz : int := (arr)->size() ; lexicoSmallestPermuatation(arr, sz) ) else skip; operation lexicoSmallestPermuatation(arr : OclAny, n : OclAny) pre: true post: true activity: var cnt : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( cnt[arr[i+1]+1] := cnt[arr[i+1]+1] + 1) ; var ele : int := 1 ; var replacement : int := 0 ; var vis : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( if (cnt[arr[i+1]+1] = 1) then ( continue ) else skip ; while (cnt[ele+1]) do ( ele := ele + 1) ; if ((ele->compareTo(arr[i+1])) > 0 & vis[arr[i+1]+1] = 0) then ( vis[arr[i+1]+1] := 1; ) else ( cnt[arr[i+1]+1] := cnt[arr[i+1]+1] - 1 ; arr[i+1] := ele ; replacement := replacement + 1 ; ele := ele + 1 )) ; execute (replacement)->display() ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def preprocess(arr,n): temp=[None]*(2*n) for i in range(n): temp[i]=temp[i+n]=arr[i] return temp def leftRotate(arr,n,k,temp): start=k % n for i in range(start,start+n): print(temp[i],end="") print("") arr=[1,3,5,7,9] n=len(arr) temp=preprocess(arr,n) k=2 leftRotate(arr,n,k,temp) k=3 leftRotate(arr,n,k,temp) k=4 leftRotate(arr,n,k,temp) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{ 9 })))) ; n := (arr)->size() ; temp := preprocess(arr, n) ; k := 2 ; leftRotate(arr, n, k, temp) ; k := 3 ; leftRotate(arr, n, k, temp) ; k := 4 ; leftRotate(arr, n, k, temp); operation preprocess(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var temp : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (2 * n)) ; for i : Integer.subrange(0, n-1) do ( temp[i+1] := arr[i+1]; var temp[i + n+1] : OclAny := arr[i+1]) ; return temp; operation leftRotate(arr : OclAny, n : OclAny, k : OclAny, temp : OclAny) pre: true post: true activity: var start : int := k mod n ; for i : Integer.subrange(start, start + n-1) do ( execute (temp[i+1])->display()) ; execute ("")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : t-=1 n,k=map(int,input().split()) mas=[] a=[] b=[] a=list(map(int,input().split())) b=list(map(int,input().split())) for i in range(n): mas.append((a[i],b[i])) mas.sort() for i in range(n): if(k>=mas[i][0]): k+=mas[i][1] print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( t := t - 1 ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mas : Sequence := Sequence{} ; var a : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; b := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( execute ((Sequence{a[i+1], b[i+1]}) : mas)) ; mas := mas->sort() ; for i : Integer.subrange(0, n-1) do ( if ((k->compareTo(mas[i+1]->first())) >= 0) then ( k := k + mas[i+1][1+1] ) else skip) ; execute (k)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,k=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) d={} for i in range(n): if(a[i]in d): d[a[i]]+=b[i] else : d[a[i]]=b[i] for i in sorted(d.keys()): if(i>k): break else : k+=d[i] print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( if ((d)->includes(a[i+1])) then ( d[a[i+1]+1] := d[a[i+1]+1] + b[i+1] ) else ( d[a[i+1]+1] := b[i+1] )) ; for i : d.keys()->sort() do ( if ((i->compareTo(k)) > 0) then ( break ) else ( k := k + d[i+1] )) ; execute (k)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def inp(): return list(map(int,input().split())) def main(): n,k=inp() lst=[[0,1]for i in range(n)] tmp=inp() for i in range(n): lst[i][0]=tmp[i] tmp=inp() for i in range(n): lst[i][1]=tmp[i] lst.sort(key=lambda x : x[0]) for i in lst : if i[0]<=k : k+=i[1] print(k) if __name__=='__main__' : t=int(input()) for i in range(t): main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( main()) ) else skip; operation inp() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation main() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := inp() ; var lst : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{0}->union(Sequence{ 1 }))) ; var tmp : OclAny := inp() ; for i : Integer.subrange(0, n-1) do ( lst[i+1]->first() := tmp[i+1]) ; tmp := inp() ; for i : Integer.subrange(0, n-1) do ( lst[i+1][1+1] := tmp[i+1]) ; lst := lst->sort() ; for i : lst do ( if (i->first()->compareTo(k)) <= 0 then ( k := k + i[1+1] ) else skip) ; execute (k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n,k=map(int,input().split()) a=[int(i)for i in input().split()] b=[int(i)for i in input().split()] d=zip(a,b) d=sorted(d) for key,v in d : if key<=k : k=k+v else : break print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var b : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var d : Sequence := Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), b->at(_indx)} ) ; d := d->sort() ; for _tuple : d do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if (key->compareTo(k)) <= 0 then ( var k : OclAny := k + v ) else ( break )) ; execute (k)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=10000 sequence=[0]*(MAX+1); def vanEckSequence(): for i in range(MAX): for j in range(i-1,-1,-1): if(sequence[j]==sequence[i]): sequence[i+1]=i-j ; break ; def getCount(n): nthTerm=sequence[n-1]; count=0 ; for i in range(n): if(sequence[i]==nthTerm): count+=1 ; return count ; if __name__=="__main__" : vanEckSequence(); n=5 ; print(getCount(n)); n=11 ; print(getCount(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 10000 ; var sequence : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX + 1)); ; skip ; skip ; if __name__ = "__main__" then ( vanEckSequence(); ; n := 5; ; execute (getCount(n))->display(); ; n := 11; ; execute (getCount(n))->display(); ) else skip; operation vanEckSequence() pre: true post: true activity: for i : Integer.subrange(0, MAX-1) do ( for j : Integer.subrange(-1 + 1, i - 1)->reverse() do ( if (sequence[j+1] = sequence[i+1]) then ( sequence[i + 1+1] := i - j; ; break; ) else skip)); operation getCount(n : OclAny) pre: true post: true activity: var nthTerm : OclAny := sequence[n - 1+1]; ; var count : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (sequence[i+1] = nthTerm) then ( count := count + 1; ) else skip) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(float,input().split())) l=sorted([x-int(x)for x in l if x-int(x)!=0]) o=2*n-len(l) su=sum(l) ans=0xFFFFFFFFFFFFFFF for i in range(n+1): if i+o>=n : ans=min(ans,abs(i-su)) print("%.3f" % ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["double"])->apply(_x) )) ; l := l->select(x | x - ("" + ((x)))->toInteger() /= 0)->collect(x | (x - ("" + ((x)))->toInteger()))->sort() ; var o : double := 2 * n - (l)->size() ; var su : OclAny := (l)->sum() ; var ans : int := 0xFFFFFFFFFFFFFFF ; for i : Integer.subrange(0, n + 1-1) do ( if (i + o->compareTo(n)) >= 0 then ( ans := Set{ans, (i - su)->abs()}->min() ) else skip) ; execute (StringLib.format("%.3f",ans))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) count=0 for i in range(1,N+1): str_i=str(i) if int(str_i[-1])==0 : continue if len(str_i)==1 : count+=1 continue if len(str_i)==2 : if int(str_i[0])>int(str_i[-1]): count+=2 if int(str_i[0])==int(str_i[-1]): count+=3 continue if int(str_i[0])>int(str_i[-1]): count+=(10**(len(str_i)-2))*2 if int(str_i[0])==int(str_i[-1]): count+=(int(str_i[1 :-1]))*2+1 count+=2 for j in range(len(str_i)-2): count+=(10**j)*2 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := 0 ; for i : Integer.subrange(1, N + 1-1) do ( var str_i : String := ("" + ((i))) ; if ("" + ((str_i->last())))->toInteger() = 0 then ( continue ) else skip ; if (str_i)->size() = 1 then ( count := count + 1 ; continue ) else skip ; if (str_i)->size() = 2 then ( if (("" + ((str_i->first())))->toInteger()->compareTo(("" + ((str_i->last())))->toInteger())) > 0 then ( count := count + 2 ) else skip ; if ("" + ((str_i->first())))->toInteger() = ("" + ((str_i->last())))->toInteger() then ( count := count + 3 ) else skip ; continue ) else skip ; if (("" + ((str_i->first())))->toInteger()->compareTo(("" + ((str_i->last())))->toInteger())) > 0 then ( count := count + ((10)->pow(((str_i)->size() - 2))) * 2 ) else skip ; if ("" + ((str_i->first())))->toInteger() = ("" + ((str_i->last())))->toInteger() then ( count := count + (("" + ((str_i.subrange(1+1, -1))))->toInteger()) * 2 + 1 ; count := count + 2 ) else skip ; for j : Integer.subrange(0, (str_i)->size() - 2-1) do ( count := count + ((10)->pow(j)) * 2)) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) a,b=[[*map(int,input().split())]for i in range(2)] for i,j in sorted(zip(a,b)): if k-i<0 : break k+=j print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Integer.subrange(0, 2-1)->select(i | true)->collect(i | ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; for _tuple : Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), b->at(_indx)} )->sort() do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if k - i < 0 then ( break ) else skip ; k := k + j) ; execute (k)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def createSemiPrimeSieve(n): v=[0 for i in range(n+1)] for i in range(1,n+1): v[i]=i countDivision=[0 for i in range(n+1)] for i in range(n+1): countDivision[i]=2 for i in range(2,n+1,1): if(v[i]==i and countDivision[i]==2): for j in range(2*i,n+1,i): if(countDivision[j]>0): v[j]=int(v[j]/i) countDivision[j]-=1 res=[] for i in range(2,n+1,1): if(v[i]==1 and countDivision[i]==0): res.append(i) return res if __name__=='__main__' : n=16 semiPrime=createSemiPrimeSieve(n) for i in range(len(semiPrime)): print(semiPrime[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 16 ; var semiPrime : OclAny := createSemiPrimeSieve(n) ; for i : Integer.subrange(0, (semiPrime)->size()-1) do ( execute (semiPrime[i+1])->display()) ) else skip; operation createSemiPrimeSieve(n : OclAny) : OclAny pre: true post: true activity: var v : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(1, n + 1-1) do ( v[i+1] := i) ; var countDivision : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n + 1-1) do ( countDivision[i+1] := 2) ; for i : Integer.subrange(2, n + 1-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (v[i+1] = i & countDivision[i+1] = 2) then ( for j : Integer.subrange(2 * i, n + 1-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ( if (countDivision[j+1] > 0) then ( v[j+1] := ("" + ((v[j+1] / i)))->toInteger() ; countDivision[j+1] := countDivision[j+1] - 1 ) else skip) ) else skip) ; var res : Sequence := Sequence{} ; for i : Integer.subrange(2, n + 1-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (v[i+1] = 1 & countDivision[i+1] = 0) then ( execute ((i) : res) ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def editDistanceWith2Ops(X,Y): m=len(X) n=len(Y) L=[[0 for x in range(m+1)]for y in range(n+1)] for i in range(m+1): for j in range(n+1): if(i==0 or j==0): L[i][j]=0 elif(X[i-1]==Y[j-1]): L[i][j]=L[i-1][j-1]+1 else : L[i][j]=max(L[i-1][j],L[i][j-1]) lcs=L[m][n] return(m-lcs)+(n-lcs) if __name__=="__main__" : X="abc" Y="acd" print(editDistanceWith2Ops(X,Y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( X := "abc" ; Y := "acd" ; execute (editDistanceWith2Ops(X, Y))->display() ) else skip; operation editDistanceWith2Ops(X : OclAny, Y : OclAny) : OclAny pre: true post: true activity: var m : int := (X)->size() ; var n : int := (Y)->size() ; var L : Sequence := Integer.subrange(0, n + 1-1)->select(y | true)->collect(y | (Integer.subrange(0, m + 1-1)->select(x | true)->collect(x | (0)))) ; for i : Integer.subrange(0, m + 1-1) do ( for j : Integer.subrange(0, n + 1-1) do ( if (i = 0 or j = 0) then ( L[i+1][j+1] := 0 ) else (if (X[i - 1+1] = Y[j - 1+1]) then ( L[i+1][j+1] := L[i - 1+1][j - 1+1] + 1 ) else ( L[i+1][j+1] := Set{L[i - 1+1][j+1], L[i+1][j - 1+1]}->max() ) ) )) ; var lcs : OclAny := L[m+1][n+1] ; return (m - lcs) + (n - lcs); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution : def defangIPaddr(self,address : str)->str : return address.replace('.','[.]') ------------------------------------------------------------ OCL File: --------- class Solution { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation defangIPaddr(address : String) : String pre: true post: true activity: return address.replace('.', '[.]'); } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) max1=0 for i in range(n): x,y=map(int,input().split()) max1=max(max1,x+y) print(max1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var max1 : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; max1 := Set{max1, x + y}->max()) ; execute (max1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) points=sorted([tuple(map(int,input().split()))for i in range(n)],key=lambda p : p[0]+p[1]) print(sum(points[-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var points : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))->sortedBy($x | (lambda p : OclAny in (p->first() + p[1+1]))->apply($x)) ; execute ((points->last())->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(max(sum(map(int,input().split()))for _ in[0]*int(input()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (((argument (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=[] for i in range(int(input())): x.append(sum(map(int,input().split()))) print(max(x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : Sequence := Sequence{} ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum()) : x)) ; execute ((x)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) ans=0 for _ in range(n): x,y=map(int,input().split()) ans=max(ans,x+y) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; ans := Set{ans, x + y}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(float,input().split())) l=sorted([x-int(x)for x in l if x-int(x)!=0]) o=2*n-len(l) su=sum(l) ans=0xFFFFFFFFFFFFFFF for i in range(n+1): if i+o>=n : ans=min(ans,abs(i-su)) print("%.3f" % ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["double"])->apply(_x) )) ; l := l->select(x | x - ("" + ((x)))->toInteger() /= 0)->collect(x | (x - ("" + ((x)))->toInteger()))->sort() ; var o : double := 2 * n - (l)->size() ; var su : OclAny := (l)->sum() ; var ans : int := 0xFFFFFFFFFFFFFFF ; for i : Integer.subrange(0, n + 1-1) do ( if (i + o->compareTo(n)) >= 0 then ( ans := Set{ans, (i - su)->abs()}->min() ) else skip) ; execute (StringLib.format("%.3f",ans))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def countSegments(self,s): segment_count=0 for i in range(len(s)): if(i==0 or s[i-1]==' ')and s[i]!=' ' : segment_count+=1 return segment_count ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation countSegments(s : OclAny) : OclAny pre: true post: true activity: var segment_count : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if (i = 0 or s[i - 1+1] = ' ') & s[i+1] /= ' ' then ( segment_count := segment_count + 1 ) else skip) ; return segment_count; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin n=int(stdin.readline().rstrip()) li=[[0 for i in range(10)]for j in range(10)] for k in range(1,n+1): atama=int(str(k)[0]) ushiro=int(str(k)[-1]) li[atama][ushiro]+=1 point=0 for l in range(1,10): for m in range(1,10): point+=li[l][m]*li[m][l] print(point) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + ((stdin.readLine().rstrip())))->toInteger() ; var li : Sequence := Integer.subrange(0, 10-1)->select(j | true)->collect(j | (Integer.subrange(0, 10-1)->select(i | true)->collect(i | (0)))) ; for k : Integer.subrange(1, n + 1-1) do ( var atama : int := ("" + ((OclType["String"](k)->first())))->toInteger() ; var ushiro : int := ("" + ((OclType["String"](k)->last())))->toInteger() ; li[atama+1][ushiro+1] := li[atama+1][ushiro+1] + 1) ; var point : int := 0 ; for l : Integer.subrange(1, 10-1) do ( for m : Integer.subrange(1, 10-1) do ( point := point + li[l+1][m+1] * li[m+1][l+1])) ; execute (point)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) ans=0 for i in range(n-1): ans+=min(abs(a[i+1]-a[i])+abs(b[i+1]-b[i]),abs(b[i+1]-a[i])+abs(a[i+1]-b[i])) print(ans) for _ in range(int(input())): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve()); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( ans := ans + Set{(a[i + 1+1] - a[i+1])->abs() + (b[i + 1+1] - b[i+1])->abs(), (b[i + 1+1] - a[i+1])->abs() + (a[i + 1+1] - b[i+1])->abs()}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) total_sum=0 for i in range(n-1): if abs(a[i]-a[i+1])+abs(b[i]-b[i+1])toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var total_sum : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if ((a[i+1] - a[i + 1+1])->abs() + (b[i+1] - b[i + 1+1])->abs()->compareTo((a[i+1] - b[i + 1+1])->abs() + (b[i+1] - a[i + 1+1])->abs())) < 0 then ( total_sum := total_sum + (a[i+1] - a[i + 1+1])->abs() + (b[i+1] - b[i + 1+1])->abs() ) else ( total_sum := total_sum + (a[i+1] - b[i + 1+1])->abs() + (b[i+1] - a[i + 1+1])->abs() )) ; execute (total_sum)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solution(n,a,b): for i in range(n): if a[i]>b[i]: tmp=a[i] a[i]=b[i] b[i]=tmp summ=0 for i in range(n-1): summ+=abs(a[i]-a[i+1]) summ+=abs(b[i]-b[i+1]) return summ t=int(input()) while t : n=int(input()) a=[int(x)for x in input().strip().split(" ")] b=[int(x)for x in input().strip().split(" ")] print(solution(n,a,b)) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := input()->trim().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; b := input()->trim().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (solution(n, a, b))->display() ; t := t - 1); operation solution(n : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if (a[i+1]->compareTo(b[i+1])) > 0 then ( var tmp : OclAny := a[i+1] ; a[i+1] := b[i+1] ; b[i+1] := tmp ) else skip) ; var summ : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( summ := summ + (a[i+1] - a[i + 1+1])->abs() ; summ := summ + (b[i+1] - b[i + 1+1])->abs()) ; return summ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) l1=list(map(int,input().split())) for i in range(n-1): if abs(l[i]-l[i+1])+abs(l1[i]-l1[i+1])>abs(l[i]-l1[i+1])+abs(l1[i]-l[i+1]): l[i+1],l1[i+1]=l1[i+1],l[i+1] c=0 for i in range(1,n): c+=abs(l[i]-l[i-1]) for i in range(1,n): c+=abs(l1[i]-l1[i-1]) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n - 1-1) do ( if ((l[i+1] - l[i + 1+1])->abs() + (l1[i+1] - l1[i + 1+1])->abs()->compareTo((l[i+1] - l1[i + 1+1])->abs() + (l1[i+1] - l[i + 1+1])->abs())) > 0 then ( var l[i + 1+1] : OclAny := null; var l1[i + 1+1] : OclAny := null; Sequence{l[i + 1+1],l1[i + 1+1]} := Sequence{l1[i + 1+1],l[i + 1+1]} ) else skip) ; var c : int := 0 ; for i : Integer.subrange(1, n-1) do ( c := c + (l[i+1] - l[i - 1+1])->abs()) ; for i : Integer.subrange(1, n-1) do ( c := c + (l1[i+1] - l1[i - 1+1])->abs()) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=sorted((map(int,input().split()))) res=0 for i in range(1,n): if(a[i]<=a[i-1]): res=res+((a[i-1]-a[i])+1) a[i]=a[i]+(a[i-1]-a[i])+1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var res : int := 0 ; for i : Integer.subrange(1, n-1) do ( if ((a[i+1]->compareTo(a[i - 1+1])) <= 0) then ( res := res + ((a[i - 1+1] - a[i+1]) + 1) ; a[i+1] := a[i+1] + (a[i - 1+1] - a[i+1]) + 1 ) else skip) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ls=[int(a)for a in input().split()] ls.sort() ls1=[0]*2*n for i in range(n): ls1[ls[i]-1]+=1 sm=0 i=0 while i1 : idx=ls1.index(0) sm+=idx-i ls1[idx]+=1 ls1[i]-=1 i-=1 else : ls1[i]=1 i+=1 print(sm) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ls : Sequence := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; ls := ls->sort() ; var ls1 : Sequence := MatrixLib.elementwiseMult(MatrixLib.elementwiseMult(Sequence{ 0 }, 2), n) ; for i : Integer.subrange(0, n-1) do ( ls1[ls[i+1] - 1+1] := ls1[ls[i+1] - 1+1] + 1) ; var sm : int := 0 ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( if ls1[i+1] > 1 then ( var idx : int := ls1->indexOf(0) - 1 ; sm := sm + idx - i ; ls1[idx+1] := ls1[idx+1] + 1 ; ls1[i+1] := ls1[i+1] - 1 ; i := i - 1 ) else ( ls1[i+1] := 1 ) ; i := i + 1) ; execute (sm)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=sorted(list(map(int,input().split()))) count=0 counter=0 for i in range(1,n): if arr[i]<=arr[i-1]: count=arr[i-1]-arr[i]+1 arr[i]+=count counter+=count print(counter) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var count : int := 0 ; var counter : int := 0 ; for i : Integer.subrange(1, n-1) do ( if (arr[i+1]->compareTo(arr[i - 1+1])) <= 0 then ( count := arr[i - 1+1] - arr[i+1] + 1 ; arr[i+1] := arr[i+1] + count ; counter := counter + count ) else skip) ; execute (counter)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- number_of_icons=int(input()) soldiers=[int(i)for i in input().split()] soldiers.sort() result=0 for i in range(len(soldiers)): for j in range(i+1,len(soldiers)): if soldiers[i]==soldiers[j]: soldiers[j]+=1 result+=1 else : break print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var number_of_icons : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var soldiers : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; soldiers := soldiers->sort() ; var result : int := 0 ; for i : Integer.subrange(0, (soldiers)->size()-1) do ( for j : Integer.subrange(i + 1, (soldiers)->size()-1) do ( if soldiers[i+1] = soldiers[j+1] then ( soldiers[j+1] := soldiers[j+1] + 1 ; result := result + 1 ) else ( break ))) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def equivalentBase4(bin): if(bin=="00"): return 0 if(bin=="01"): return 1 if(bin=="10"): return 2 if(bin=="11"): return 3 def isDivisibleBy5(bin): l=len(bin) if((l % 2)==1): bin='0'+bin odd_sum=0 even_sum=0 isOddDigit=1 for i in range(0,len(bin),2): if(isOddDigit): odd_sum+=equivalentBase4(bin[i : i+2]) else : even_sum+=equivalentBase4(bin[i : i+2]) isOddDigit=isOddDigit ^ 1 if(abs(odd_sum-even_sum)% 5==0): return "Yes" else : return "No" if __name__=="__main__" : bin="10000101001" print(isDivisibleBy5(bin)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( bin := "10000101001" ; execute (isDivisibleBy5(bin))->display() ) else skip; operation equivalentBase4(bin : OclAny) : OclAny pre: true post: true activity: if (bin = "00") then ( return 0 ) else skip ; if (bin = "01") then ( return 1 ) else skip ; if (bin = "10") then ( return 2 ) else skip ; if (bin = "11") then ( return 3 ) else skip; operation isDivisibleBy5(bin : OclAny) : OclAny pre: true post: true activity: var l : int := (bin)->size() ; if ((l mod 2) = 1) then ( bin := '0' + bin ) else skip ; var odd_sum : int := 0 ; var even_sum : int := 0 ; var isOddDigit : int := 1 ; for i : Integer.subrange(0, (bin)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( if (isOddDigit) then ( odd_sum := odd_sum + equivalentBase4(bin.subrange(i+1, i + 2)) ) else ( even_sum := even_sum + equivalentBase4(bin.subrange(i+1, i + 2)) ) ; isOddDigit := MathLib.bitwiseXor(isOddDigit, 1)) ; if ((odd_sum - even_sum)->abs() mod 5 = 0) then ( return "Yes" ) else ( return "No" ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) temp=input().split(" ") num=list(map(int,temp)) num.sort() count=0 for x in range(1,len(num)): if num[x]<=num[x-1]: count+=abs(num[x]-num[x-1])+1 num[x]+=abs(num[x]-num[x-1])+1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var temp : OclAny := input().split(" ") ; var num : Sequence := ((temp)->collect( _x | (OclType["int"])->apply(_x) )) ; num := num->sort() ; var count : int := 0 ; for x : Integer.subrange(1, (num)->size()-1) do ( if (num[x+1]->compareTo(num[x - 1+1])) <= 0 then ( count := count + (num[x+1] - num[x - 1+1])->abs() + 1 ; num[x+1] := num[x+1] + (num[x+1] - num[x - 1+1])->abs() + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def factors(n): prime=dict() for i in range(2,mt.ceil(mt.sqrt(n+1))): while(n % i==0): if i in prime.keys(): prime[i]+=1 else : prime[i]=1 n=n//i if(n>2): if n in prime.keys(): prime[n]+=1 else : prime[n]=1 ans1=1 ans2=1 for it in prime : ans1*=2*prime[it]+1 ans2*=prime[it]+1 return ans1-ans2 n=5 print(factors(n)) n=8 print(factors(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 5 ; execute (factors(n))->display() ; n := 8 ; execute (factors(n))->display(); operation factors(n : OclAny) : OclAny pre: true post: true activity: var prime : Map := (arguments ( )) ; for i : Integer.subrange(2, mt.ceil(mt.sqrt(n + 1))-1) do ( while (n mod i = 0) do ( if (prime.keys())->includes(i) then ( prime[i+1] := prime[i+1] + 1 ) else ( prime[i+1] := 1 ) ; n := n div i)) ; if (n > 2) then ( if (prime.keys())->includes(n) then ( prime[n+1] := prime[n+1] + 1 ) else ( prime[n+1] := 1 ) ) else skip ; var ans1 : int := 1 ; var ans2 : int := 1 ; for it : prime->keys() do ( ans1 := ans1 * 2 * prime[it+1] + 1 ; ans2 := ans2 * prime[it+1] + 1) ; return ans1 - ans2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(N : int): l=len(str(N)) k={} for i in range(1,10): for j in range(1,10): k[str(i)+str(j)]=0 for x in range(1,N+1): s=str(x) if s[-1]!="0" : k[s[0]+s[-1]]+=1 k_new={} for i in range(1,10): k_new[str(i)+str(i)]=k[str(i)+str(i)]**2 for j in range(i+1,10): n=k[str(i)+str(j)]*k[str(j)+str(i)] k_new[str(i)+str(j)]=n*2 print(sum([t for t in k_new.values()])) return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() N=int(next(tokens)) solve(N) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(N : int) pre: true post: true activity: var l : int := (("" + ((N))))->size() ; var k : OclAny := Set{} ; for i : Integer.subrange(1, 10-1) do ( for j : Integer.subrange(1, 10-1) do ( k[("" + ((i))) + ("" + ((j)))+1] := 0)) ; for x : Integer.subrange(1, N + 1-1) do ( var s : String := ("" + ((x))) ; if s->last() /= "0" then ( k[s->first() + s->last()+1] := k[s->first() + s->last()+1] + 1 ) else skip) ; var k_new : OclAny := Set{} ; for i : Integer.subrange(1, 10-1) do ( k_new[("" + ((i))) + ("" + ((i)))+1] := (k[("" + ((i))) + ("" + ((i)))+1])->pow(2) ; for j : Integer.subrange(i + 1, 10-1) do ( var n : double := k[("" + ((i))) + ("" + ((j)))+1] * k[("" + ((j))) + ("" + ((i)))+1] ; k_new[("" + ((i))) + ("" + ((j)))+1] := n * 2)) ; execute ((k_new.values()->select(t | true)->collect(t | (t)))->sum())->display() ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var N : int := ("" + (((tokens).next())))->toInteger() ; solve(N); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,b,p=map(int,input().split()) x=0 y=n*p while n>1 : k=1 while k<=n : k*=2 k//=2 x+=b*k+k//2 n-=k//2 print(x,y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var b : OclAny := null; var p : OclAny := null; Sequence{n,b,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : int := 0 ; var y : double := n * p ; while n > 1 do ( var k : int := 1 ; while (k->compareTo(n)) <= 0 do ( k := k * 2) ; k := k div 2 ; x := x + b * k + k div 2 ; n := n - k div 2) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def getNumberOfMatches(participants): if participants==1 : return 0 competidors=int(math.sqrt(participants))**2 return competidors/2+getNumberOfMatches(competidors/2+participants-competidors) def main(): participants,bottles_per_match,towels_per_participant=[int(x)for x in input().split(" ")] matches=getNumberOfMatches(participants) print(f'{int(matches*(2*bottles_per_match+1))}{towels_per_participant*participants}') main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; main(); operation getNumberOfMatches(participants : OclAny) : OclAny pre: true post: true activity: if participants = 1 then ( return 0 ) else skip ; var competidors : double := (("" + (((participants)->sqrt())))->toInteger())->pow(2) ; return competidors / 2 + getNumberOfMatches(competidors / 2 + participants - competidors); operation main() pre: true post: true activity: var bottles_per_match : OclAny := null; var towels_per_participant : OclAny := null; Sequence{participants,bottles_per_match,towels_per_participant} := input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var matches : OclAny := getNumberOfMatches(participants) ; execute (StringLib.formattedString('{int(matches*(2*bottles_per_match+1))}{towels_per_participant*participants}'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,b,p=map(int,input().split()) bottles=0 towels=n*p while n!=1 : k=n//2 bottles+=k*(2*b+1) m=n-k*2 n=m+k print(bottles,towels) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var b : OclAny := null; var p : OclAny := null; Sequence{n,b,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var bottles : int := 0 ; var towels : double := n * p ; while n /= 1 do ( var k : int := n div 2 ; bottles := bottles + k * (2 * b + 1) ; var m : double := n - k * 2 ; var n : OclAny := m + k) ; execute (bottles)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,b,p=[int(x)for x in input().split()] bottlePerMatch=(2*b)+1 def calcBottle(part): if part==1 : return 0 elif part==2 : return bottlePerMatch else : k=int(math.log(part,2)) playersJogando=2**k matches=playersJogando/2 garrafa=matches*bottlePerMatch return garrafa+calcBottle((matches)+part-playersJogando) bottles=calcBottle(n) towels=p if n>1 : towels=n*p print("%d %d" %(bottles,towels)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var b : OclAny := null; var p : OclAny := null; Sequence{n,b,p} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var bottlePerMatch : double := (2 * b) + 1 ; skip ; var bottles : OclAny := calcBottle(n) ; var towels : OclAny := p ; if n > 1 then ( towels := n * p ) else skip ; execute (StringLib.format("%d %d",Sequence{bottles, towels}))->display(); operation calcBottle(part : OclAny) : OclAny pre: true post: true activity: if part = 1 then ( return 0 ) else (if part = 2 then ( return bottlePerMatch ) else ( var k : int := ("" + (((part, 2)->log())))->toInteger() ; var playersJogando : double := (2)->pow(k) ; var matches : double := playersJogando / 2 ; var garrafa : double := matches * bottlePerMatch ; return garrafa + calcBottle((matches) + part - playersJogando) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,b,p=map(int,input().split()) x=0 y=p*n while n>1 : q=n//2 w=n % 2 x=x+(q*2*b)+q n=q+w print(x,y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var b : OclAny := null; var p : OclAny := null; Sequence{n,b,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : int := 0 ; var y : double := p * n ; while n > 1 do ( var q : int := n div 2 ; var w : int := n mod 2 ; x := x + (q * 2 * b) + q ; var n : int := q + w) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=10 def isFactorion(n): fact=[0]*MAX fact[0]=1 for i in range(1,MAX): fact[i]=i*fact[i-1] org=n sum=0 while(n>0): d=n % 10 sum+=fact[d] n=n//10 if(sum==org): return True return False n=40585 if(isFactorion(n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 10 ; skip ; n := 40585 ; if (isFactorion(n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isFactorion(n : OclAny) : OclAny pre: true post: true activity: var fact : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX) ; fact->first() := 1 ; for i : Integer.subrange(1, MAX-1) do ( fact[i+1] := i * fact[i - 1+1]) ; var org : OclAny := n ; var sum : int := 0 ; while (n > 0) do ( var d : int := n mod 10 ; sum := sum + fact[d+1] ; n := n div 10) ; if (sum = org) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline write=sys.stdout.write def solve(): S=readline().strip() ans=0 d=0 ; cur=0 for c in S : if c=="R" : if d==cur : cur+=1 d=(d+1)% 4 if d==0 and cur==4 : ans+=1 cur=0 else : d=(d-1)% 4 if d==0 : cur=0 write("%d\n" % ans) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var write : OclAny := (OclFile["System.out"]).write ; skip ; solve(); operation solve() pre: true post: true activity: var S : OclAny := readline()->trim() ; var ans : int := 0 ; var d : int := 0; var cur : int := 0 ; for c : S do ( if c = "R" then ( if d = cur then ( cur := cur + 1 ) else skip ; d := (d + 1) mod 4 ; if d = 0 & cur = 4 then ( ans := ans + 1 ; cur := 0 ) else skip ) else ( d := (d - 1) mod 4 ; if d = 0 then ( cur := 0 ) else skip )) ; write(StringLib.format("%d\n",ans)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque score={} score[tuple(range(8))]=0 queue=deque() queue.append(tuple(range(8))) move=((1,4),(0,2,5),(1,3,6),(2,7),(0,5),(1,4,6),(2,5,7),(3,6)) while queue : puz=queue.popleft() pos=puz.index(0) for npos in move[pos]: npuz=list(puz) npuz[pos],npuz[npos]=npuz[npos],0 npuz=tuple(npuz) if npuz not in score : queue.append(npuz) score[npuz]=score[puz]+1 while True : try : puzzle=tuple(map(int,input().split())) print(score[puzzle]) except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var score : OclAny := Set{} ; score->restrict((Integer.subrange(0, 8-1))) := 0 ; var queue : Sequence := () ; execute (((Integer.subrange(0, 8-1))) : queue) ; var move : OclAny := Sequence{Sequence{1, 4}, Sequence{0, 2, 5}, Sequence{1, 3, 6}, Sequence{2, 7}, Sequence{0, 5}, Sequence{1, 4, 6}, Sequence{2, 5, 7}, Sequence{3, 6}} ; while queue do ( var puz : OclAny := queue->first() ; queue := queue->tail() ; var pos : int := puz->indexOf(0) - 1 ; for npos : move[pos+1] do ( var npuz : Sequence := (puz) ; var npuz[pos+1] : OclAny := null; var npuz[npos+1] : OclAny := null; Sequence{npuz[pos+1],npuz[npos+1]} := Sequence{npuz[npos+1],0} ; npuz := (npuz) ; if (score)->excludes(npuz) then ( execute ((npuz) : queue) ; score->restrict(npuz) := score[puz+1] + 1 ) else skip)) ; while true do ( try ( var puzzle : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (score->restrict(puzzle))->display()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() count=0 direction=0 for i in range(len(S)): if S[i]=='R' : direction+=1 else : direction-=1 if direction==4 : count+=1 direction=0 elif direction==-4 : direction=0 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var count : int := 0 ; var direction : int := 0 ; for i : Integer.subrange(0, (S)->size()-1) do ( if S[i+1] = 'R' then ( direction := direction + 1 ) else ( direction := direction - 1 ) ; if direction = 4 then ( count := count + 1 ; direction := 0 ) else (if direction = -4 then ( direction := 0 ) else skip)) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] def f(n): r=0 t=0 for c in n : if c=='R' : t+=1 if t==4 : r+=1 t=0 else : t-=1 if t==-4 : t=0 return r while 1 : n=S() if n==0 : break rr.append(f(n)) break return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : double := (10)->pow(9) + 7 ; var dd : Sequence := Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{ Sequence{0, -1} }))) ; var ddn : Sequence := Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{-1, 1}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{1, 1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{1, -1}}->union(Sequence{Sequence{0, -1}}->union(Sequence{ Sequence{-1, -1} }))))))) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; skip ; while 1 do ( n := S() ; if n = 0 then ( break ) else skip ; execute ((f(n)) : rr) ; break) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def winner(moves): data=dict() data['R']=0 data['P']=1 data['S']=2 if(moves[0]==moves[1]): return "Draw" if(((data[moves[0]]| 1<<(2))-(data[moves[1]]| 0<<(2)))% 3): return "A" return "B" def performQueries(arr,n): for i in range(n): print(winner(arr[i])) arr=["RS","SR","SP","PP"] n=len(arr) performQueries(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{"RS"}->union(Sequence{"SR"}->union(Sequence{"SP"}->union(Sequence{ "PP" }))) ; n := (arr)->size() ; performQueries(arr, n); operation winner(moves : OclAny) : OclAny pre: true post: true activity: var data : Map := (arguments ( )) ; data->at('R') := 0 ; data->at('P') := 1 ; data->at('S') := 2 ; if (moves->first() = moves[1+1]) then ( return "Draw" ) else skip ; if (((MathLib.bitwiseOr(data[moves->first()+1], 1 * (2->pow((2))))) - (MathLib.bitwiseOr(data[moves[1+1]+1], 0 * (2->pow((2)))))) mod 3) then ( return "A" ) else skip ; return "B"; operation performQueries(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (winner(arr[i+1]))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) count=0 d=1 mat=[[0]*10 for _ in range(10)] for a in range(1,n+1): if a>=10**d : d+=1 x=a//(10**(d-1)) y=a % 10 mat[x][y]+=1 for i in range(10): count+=mat[i][i]**2 for j in range(i+1,10): count+=mat[i][j]*mat[j][i]*2 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := 0 ; var d : int := 1 ; var mat : Sequence := Integer.subrange(0, 10-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 10))) ; for a : Integer.subrange(1, n + 1-1) do ( if (a->compareTo((10)->pow(d))) >= 0 then ( d := d + 1 ) else skip ; var x : int := a div ((10)->pow((d - 1))) ; var y : int := a mod 10 ; mat[x+1][y+1] := mat[x+1][y+1] + 1) ; for i : Integer.subrange(0, 10-1) do ( count := count + (mat[i+1][i+1])->pow(2) ; for j : Integer.subrange(i + 1, 10-1) do ( count := count + mat[i+1][j+1] * mat[j+1][i+1] * 2)) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def noOfTriples(arr,n): arr.sort() count=0 for i in range(n): if arr[i]==arr[2]: count+=1 if arr[0]==arr[2]: return(count-2)*(count-1)*(count)/6 elif arr[1]==arr[2]: return(count-1)*(count)/2 return count arr=[1,3,3,4] n=len(arr) print(noOfTriples(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{3}->union(Sequence{3}->union(Sequence{ 4 }))) ; n := (arr)->size() ; execute (noOfTriples(arr, n))->display(); operation noOfTriples(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] = arr[2+1] then ( count := count + 1 ) else skip) ; if arr->first() = arr[2+1] then ( return (count - 2) * (count - 1) * (count) / 6 ) else (if arr[1+1] = arr[2+1] then ( return (count - 1) * (count) / 2 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(1,t+1): if(i % 2==0): print("I love ",end="") else : print("I hate ",end="") if(i!=t): print("that ",end="") else : print("it ",end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(1, t + 1-1) do ( if (i mod 2 = 0) then ( execute ("I love ")->display() ) else ( execute ("I hate ")->display() ) ; if (i /= t) then ( execute ("that ")->display() ) else ( execute ("it ")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s='' for i in range(1,n+1): if(s): s+=' that ' if(i % 2): s+='I hate' else : s+='I love' if(i==n): s+=' it' print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := '' ; for i : Integer.subrange(1, n + 1-1) do ( if (s) then ( s := s + ' that ' ) else skip ; if (i mod 2) then ( s := s + 'I hate' ) else ( s := s + 'I love' ) ; if (i = n) then ( s := s + ' it' ) else skip) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a='I hate ' b='I love ' c='that ' d='it' if n==1 : print(a+d) else : e=a for i in range(1,n): if i % 2==1 : e=e+c+b elif i % 2==0 : e=e+c+a e=e+d print(e) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : String := 'I hate ' ; var b : String := 'I love ' ; var c : String := 'that ' ; var d : String := 'it' ; if n = 1 then ( execute (a + d)->display() ) else ( var e : String := a ; for i : Integer.subrange(1, n-1) do ( if i mod 2 = 1 then ( e := e + c + b ) else (if i mod 2 = 0 then ( e := e + c + a ) else skip)) ; e := e + d ; execute (e)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- layers=int(input()) words_in_sentence=[] for layer in range(layers): if layer % 2==0 : words_in_sentence.extend(['I','hate','that']) else : words_in_sentence.extend(['I','love','that']) words_in_sentence[-1]='it' print(' '.join(words_in_sentence)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var layers : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var words_in_sentence : Sequence := Sequence{} ; for layer : Integer.subrange(0, layers-1) do ( if layer mod 2 = 0 then ( words_in_sentence := words_in_sentence->union(Sequence{'I'}->union(Sequence{'hate'}->union(Sequence{ 'that' }))) ) else ( words_in_sentence := words_in_sentence->union(Sequence{'I'}->union(Sequence{'love'}->union(Sequence{ 'that' }))) )) ; words_in_sentence->last() := 'it' ; execute (StringLib.sumStringsWithSeparator((words_in_sentence), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(*(['I hate','I love']*50)[: int(input())],sep=' that ',end=' it') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom 'I hate'))))) , (test (logical_test (comparison (expr (atom 'I love')))))) ])) * (expr (atom (number (integer 50))))))))) )) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))) ]))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools import collections INF=10**9 def Z(): return int(input()) def ZZ(): return[int(_)for _ in input().split()] def main(): p=collections.defaultdict(int) q=collections.defaultdict(list) for i,v in enumerate(itertools.permutations(range(8))): p[v]=i q[i]=list(v) dist=[INF]*(40325) dist[0]=0 que=collections.deque() que.append(0) def change(i,j,l): d=dist[p[tuple(l)]] l[i],l[j]=l[j],l[i] if dist[p[tuple(l)]]==INF : dist[p[tuple(l)]]=d+1 que.append(p[tuple(l)]) l[i],l[j]=l[j],l[i] return while que : v=que.popleft() ll=q[v] i=ll.index(0) if i in{0,4}: change(i,i+1,ll) elif i in{3,7}: change(i-1,i,ll) else : change(i,i+1,ll) change(i-1,i,ll) change(i,(i+4)% 8,ll) while True : try : A=ZZ() print(dist[p[tuple(A)]]) except : break return if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var INF : double := (10)->pow(9) ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation Z() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation ZZ() : OclAny pre: true post: true activity: return input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())); operation main() pre: true post: true activity: var p : OclAny := .defaultdict(OclType["int"]) ; var q : OclAny := .defaultdict(OclType["Sequence"]) ; for _tuple : Integer.subrange(1, (itertools.permutations(Integer.subrange(0, 8-1)))->size())->collect( _indx | Sequence{_indx-1, (itertools.permutations(Integer.subrange(0, 8-1)))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); p[v+1] := i ; q[i+1] := (v)) ; var dist : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, (40325)) ; dist->first() := 0 ; var que : Sequence := () ; execute ((0) : que) ; skip ; while que do ( var v : OclAny := que->first() ; que := que->tail() ; var ll : OclAny := q[v+1] ; i := ll->indexOf(0) - 1 ; if (Set{0}->union(Set{ 4 }))->includes(i) then ( change(i, i + 1, ll) ) else (if (Set{3}->union(Set{ 7 }))->includes(i) then ( change(i - 1, i, ll) ) else ( change(i, i + 1, ll) ; change(i - 1, i, ll) ) ) ; change(i, (i + 4) mod 8, ll)) ; while true do ( try ( var A : OclAny := ZZ() ; execute (dist[p->restrict((A))+1])->display()) catch (_e : OclException) do ( break) ) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getMin(arr,n): minVal=min(arr); return minVal ; if __name__=="__main__" : arr=[5,3,1,6,9]; n=len(arr); print(getMin(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{5}->union(Sequence{3}->union(Sequence{1}->union(Sequence{6}->union(Sequence{ 9 })))); ; n := (arr)->size(); ; execute (getMin(arr, n))->display(); ) else skip; operation getMin(arr : OclAny, n : OclAny) pre: true post: true activity: var minVal : OclAny := (arr)->min(); ; return minVal;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findpair(l,r): c=0 for i in range(l,r+1): for j in range(i+1,r+1): if(j % i==0 and j!=i): print(i,",",j) c=1 break if(c==1): break if __name__=="__main__" : l=1 r=10 findpair(l,r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( l := 1 ; r := 10 ; findpair(l, r) ) else skip; operation findpair(l : OclAny, r : OclAny) pre: true post: true activity: var c : int := 0 ; for i : Integer.subrange(l, r + 1-1) do ( for j : Integer.subrange(i + 1, r + 1-1) do ( if (j mod i = 0 & j /= i) then ( execute (i)->display() ; c := 1 ; break ) else skip) ; if (c = 1) then ( break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,q=(map(int,input("").split())) s=input() t=input() positions='' for i in range(n-m+1): if s[i : i+m]==t : positions+="1" else : positions+="0" for i in range(q): l,r=map(int,input("").split()) if r-l+1>=m : print(positions[l-1 : r-m+1].count("1")) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var q : OclAny := null; Sequence{n,m,q} := ((input("").split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var positions : String := '' ; for i : Integer.subrange(0, n - m + 1-1) do ( if s.subrange(i+1, i + m) = t then ( positions := positions + "1" ) else ( positions := positions + "0" )) ; for i : Integer.subrange(0, q-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input("").split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (r - l + 1->compareTo(m)) >= 0 then ( execute (positions.subrange(l - 1+1, r - m + 1)->count("1"))->display() ) else ( execute (0)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout from bisect import bisect_left def main(): n,m,q=map(int,stdin.readline().split()) s=stdin.readline(); t=stdin.readline(); start=[]; end=[] for i in range(n-m+1): j=0 while jcollect( _x | (OclType["int"])->apply(_x) ) ; var s : String := stdin.readLine(); ; var t : String := stdin.readLine(); ; var start : Sequence := Sequence{}; var end : Sequence := Sequence{} ; for i : Integer.subrange(0, n - m + 1-1) do ( var j : int := 0 ; while (j->compareTo(m)) < 0 & s[i + j+1] = t[j+1] do ( j := j + 1) ; if j = m then ( execute ((i) : start) ; execute ((i + j - 1) : end) ) else skip) ; var len_start : int := (start)->size() ; var len_end : int := (end)->size() ; for _anon : Integer.subrange(0, q-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; l := l - 1; r := r - 1 ; if not(start) then ( stdout.write(StringLib.format("%d\n",(0))) ; continue ) else skip ; var x : OclAny := bisect_left(start, l) ; var y : OclAny := bisect_left(end, r) ; if x = len_end then ( stdout.write(StringLib.format("%d\n",(0))) ; continue ) else skip ; if y = len_end then ( stdout.write(StringLib.format("%d\n",Set{0, y - x}->max())) ; continue ) else skip ; if end[y+1] = r then ( stdout.write(StringLib.format("%d\n",Set{0, y - x + 1}->max())) ; continue ) else ( stdout.write(StringLib.format("%d\n",Set{0, y - x}->max())) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil t=int(input()) for _ in range(t): n,x=map(int,input().split()) a=list(map(int,input().split())) m=max(a) if x in a : print(1) else : print(max(2,ceil(x/m))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : OclAny := (a)->max() ; if (a)->includes(x) then ( execute (1)->display() ) else ( execute (Set{2, ceil(x / m)}->max())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) str1=input() str2=input() list1=[0 for i in range(99999)] for i in range(a-b+1): for j in range(b): index=0 if str1[i+j]!=str2[j]: index=1 break if index==1 : list1[i+1]=list1[i] else : list1[i+1]=list1[i]+1 for i in range(c): num1,num2=map(int,input().split()) if num2-num1collect( _x | (OclType["int"])->apply(_x) ) ; var str1 : String := (OclFile["System.in"]).readLine() ; var str2 : String := (OclFile["System.in"]).readLine() ; var list1 : Sequence := Integer.subrange(0, 99999-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, a - b + 1-1) do ( for j : Integer.subrange(0, b-1) do ( var index : int := 0 ; if str1[i + j+1] /= str2[j+1] then ( index := 1 ; break ) else skip) ; if index = 1 then ( list1[i + 1+1] := list1[i+1] ) else ( list1[i + 1+1] := list1[i+1] + 1 )) ; for i : Integer.subrange(0, c-1) do ( var num1 : OclAny := null; var num2 : OclAny := null; Sequence{num1,num2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (num2 - num1->compareTo(b - 1)) < 0 then ( execute (0)->display() ) else ( execute (list1[num2 - b + 1+1] - list1[num1 - 1+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d=lambda : map(int,input().split()) n,m,q=d() s,t=input(),input() a=[0,0] b=0 for i in range(n): b+=s[i : i+m]==t ; a+=[b] for f in[0]*q : l,r=d(); print(a[max(l,r-m+2)]-a[l]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var m : OclAny := null; var q : OclAny := null; Sequence{n,m,q} := d->apply() ; var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine()} ; var a : Sequence := Sequence{0}->union(Sequence{ 0 }) ; var b : int := 0 ; for i : Integer.subrange(0, n-1) do ( b := b + s.subrange(i+1, i + m) = t; a := a + Sequence{ b }) ; for f : MatrixLib.elementwiseMult(Sequence{ 0 }, q) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := d->apply(); execute (a[Set{l, r - m + 2}->max()+1] - a[l+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np from collections import defaultdict from itertools import chain,combinations def ext_gcd(a,b): if a==0 : return b,0,1 else : g,y,x=ext_gcd(b % a,a) return g,x-(b//a)*y,y def calc_div(n): sq=int(n**.5+10) x=np.arange(1,sq) x=x[n % x==0] x=np.concatenate((x,n//x)) return np.unique(x) def solve(n): if n==1 : return 1 factors=calc_div(2*n) res=2*n-1 for p in factors : q=(2*n)//p if p==1 or q==1 : continue a,x,y=ext_gcd(p,q) if a>1 : continue if x<0 : res=min(res,abs(p*x)) else : res=min(res,abs(q*y)) return res def main(): n=int(input()) res=solve(n) print(res) def test(): assert solve(11)==10 assert solve(20200920)==1100144 if __name__=="__main__" : test() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( test() ; main() ) else skip; operation ext_gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a = 0 then ( return b, 0, 1 ) else ( var g : OclAny := null; var y : OclAny := null; var x : OclAny := null; Sequence{g,y,x} := ext_gcd(b mod a, a) ; return g, x - (b div a) * y, y ); operation calc_div(n : OclAny) : OclAny pre: true post: true activity: var sq : int := ("" + (((n)->pow(.5) + 10)))->toInteger() ; var x : Sequence := MathLib.numericRange(1, sq, 1) ; x := x->select(n mod x = 0) ; x := ; return ; operation solve(n : OclAny) : OclAny pre: true post: true activity: if n = 1 then ( return 1 ) else skip ; var factors : OclAny := calc_div(2 * n) ; var res : double := 2 * n - 1 ; for p : factors do ( var q : int := (2 * n) div p ; if p = 1 or q = 1 then ( continue ) else skip ; var y : OclAny := null; Sequence{a,x,y} := ext_gcd(p, q) ; if a > 1 then ( continue ) else skip ; if MatrixLib.elementwiseLess(x,0) then ( res := Set{res, (MatrixLib.elementwiseMult(x, p))->abs()}->min() ) else ( res := Set{res, (q * y)->abs()}->min() )) ; return res; operation main() pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; res := solve(n) ; execute (res)->display(); operation test() pre: true post: true activity: assert solve(11) = 10 do "assertion failed" ; assert solve(20200920) = 1100144 do "assertion failed"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=1000000007 eps=10**-9 def main(): import sys input=sys.stdin.readline def PrimeDecomposition(N): ret={} n=int(N**0.5) for d in range(2,n+1): while N % d==0 : if d not in ret : ret[d]=1 else : ret[d]+=1 N//=d if N==1 : break if N!=1 : ret[N]=1 return ret def extgcd(a,b): if b : d,y,x=extgcd(b,a % b) y-=(a//b)*x return d,x,y else : return a,1,0 N=int(input()) if N==1 : print(1) exit() P=PrimeDecomposition(N) if 2 in P : P[2]+=1 else : P[2]=1 p_list=list(P.keys()) np=len(p_list) ans=2*N for i in range(2**np): p1=1 p2=1 for j in range(np): pp=p_list[j] if i>>j & 1 : p1*=pp**P[pp] else : p2*=pp**P[pp] _,s2,s1=extgcd(p2,p1) while s1>=0 or s2<=0 : s1-=p2 s2+=p1 while s2-p1>0 and s1+p2<0 : s2-=p1 s1+=p2 ans=min(ans,(-s1)*p1) print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : int := 1000000007 ; var eps : double := (10)->pow(-9) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 1 then ( execute (1)->display() ; exit() ) else skip ; var P : OclAny := PrimeDecomposition(N) ; if (P)->includes(2) then ( P[2+1] := P[2+1] + 1 ) else ( P[2+1] := 1 ) ; var p_list : Sequence := (P.keys()) ; var np : int := (p_list)->size() ; var ans : double := 2 * N ; for i : Integer.subrange(0, (2)->pow(np)-1) do ( var p1 : int := 1 ; var p2 : int := 1 ; for j : Integer.subrange(0, np-1) do ( var pp : OclAny := p_list[j+1] ; if MathLib.bitwiseAnd(i /(2->pow(j)), 1) then ( p1 := p1 * (pp)->pow(P[pp+1]) ) else ( p2 := p2 * (pp)->pow(P[pp+1]) )) ; var _anon : OclAny := null; var s2 : OclAny := null; var s1 : OclAny := null; Sequence{_anon,s2,s1} := extgcd(p2, p1) ; while s1 >= 0 or s2 <= 0 do ( s1 := s1 - p2 ; s2 := s2 + p1) ; while s2 - p1 > 0 & s1 + p2 < 0 do ( s2 := s2 - p1 ; s1 := s1 + p2) ; ans := Set{ans, (-s1) * p1}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import product def main(): n=int(input()) if n==1 : print(1) exit() if n % 2==0 : ans=2*n-1 n*=2 else : ans=n-1 factors=[] for p in range(2,n): if p*p>n : if n>1 : factors.append(n) break if n % p==0 : cnt=0 while n % p==0 : cnt+=1 n//=p factors.append(p**cnt) for tf in product([True,False],repeat=len(factors)): a,b=1,1 for i in range(len(factors)): if tf[i]: a*=factors[i] else : b*=factors[i] if a1 : l.append(a) a=b quo.append(0) quo[-1],b=divmod(l[-1],b) x,y=1,a//b flag=True while l : if flag : x+=y*quo.pop() b=l.pop() else : y+=x*quo.pop() a=l.pop() flag=not flag if ans>b*y : ans=b*y print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (1)->display() ; exit() ) else skip ; if n mod 2 = 0 then ( var ans : double := 2 * n - 1 ; n := n * 2 ) else ( ans := n - 1 ) ; var factors : Sequence := Sequence{} ; for p : Integer.subrange(2, n-1) do ( if (p * p->compareTo(n)) > 0 then ( if n > 1 then ( execute ((n) : factors) ) else skip ; break ) else skip ; if n mod p = 0 then ( var cnt : int := 0 ; while n mod p = 0 do ( cnt := cnt + 1 ; n := n div p) ; execute (((p)->pow(cnt)) : factors) ) else skip) ; for tf : product(Sequence{true}->union(Sequence{ false }), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name factors)))))))) ))))))))) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{1,1} ; for i : Integer.subrange(0, (factors)->size()-1) do ( if tf[i+1] then ( a := a * factors[i+1] ) else ( b := b * factors[i+1] )) ; if (a->compareTo(b)) < 0 or a = 1 or b = 1 then ( continue ) else skip ; var l : Sequence := Sequence{} ; var quo : Sequence := Sequence{} ; while a mod b > 1 do ( execute ((a) : l) ; var a : OclAny := b ; execute ((0) : quo) ; var quo->last() : OclAny := null; var b : OclAny := null; Sequence{quo->last(),b} := Sequence{(l->last() div b), (l->last() mod b)}) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{1,a div b} ; var flag : boolean := true ; while l do ( if flag then ( x := x + y * quo->last() ; var b : OclAny := l->last() ; l := l->front() ) else ( y := y + x * quo->last() ; a := l->last() ; l := l->front() ) ; flag := not(flag)) ; if (ans->compareTo(b * y)) > 0 then ( ans := b * y ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- results={"01234567" : 0} def main(): while True : try : tmp=input().replace('','') print(results[tmp]) except EOFError : break def swap(field,a,b): tmp=list(field) tmp[b],tmp[a]=tmp[a],tmp[b] return "".join(tmp) def convert_matrix_index(index): return index % 4,int(index/4) def convert_array_index(x,y): return x+y*4 def bfs(results): q=[["01234567",0]] while len(q)is not 0 : field,res=q.pop(0) x,y=convert_matrix_index(field.find('0')) for dx,dy in zip([0,0,-1,1],[1,-1,0,0]): nx=x+dx ny=y+dy if nx<0 or ny<0 or nx>=4 or ny>=2 : continue next_field=swap(field,convert_array_index(x,y),convert_array_index(nx,ny)) if next_field not in results : results[next_field]=res+1 q.append([next_field,res+1]) return results if __name__=='__main__' : results=bfs(results) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var results : Map := Map{ "01234567" |-> 0 } ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( results := bfs(results) ; main() ) else skip; operation main() pre: true post: true activity: while true do ( try ( var tmp : OclAny := input().replace('', '') ; execute (results[tmp+1])->display()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); operation swap(field : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: tmp := (field) ; var tmp[b+1] : OclAny := null; var tmp[a+1] : OclAny := null; Sequence{tmp[b+1],tmp[a+1]} := Sequence{tmp[a+1],tmp[b+1]} ; return StringLib.sumStringsWithSeparator((tmp), ""); operation convert_matrix_index(index : OclAny) : OclAny pre: true post: true activity: return index mod 4, ("" + ((index / 4)))->toInteger(); operation convert_array_index(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return x + y * 4; operation bfs(results : OclAny) : OclAny pre: true post: true activity: var q : Sequence := Sequence{ Sequence{"01234567"}->union(Sequence{ 0 }) } ; while not((q)->size() <>= 0) do ( var res : OclAny := null; Sequence{field,res} := q->at(0`firstArg+1) ; q := q->excludingAt(0+1) ; Sequence{x,y} := convert_matrix_index(field->indexOf('0') - 1) ; for _tuple : Integer.subrange(1, Sequence{0}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{ 1 })))->size())->collect( _indx | Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{ 1 })))->at(_indx), Sequence{1}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{ 0 })))->at(_indx)} ) do (var _indx : int := 1; var dx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dy : OclAny := _tuple->at(_indx); var nx : OclAny := x + dx ; var ny : OclAny := y + dy ; if nx < 0 or ny < 0 or nx >= 4 or ny >= 2 then ( continue ) else skip ; var next_field : OclAny := swap(field, convert_array_index(x, y), convert_array_index(nx, ny)) ; if (results)->excludes(next_field) then ( results[next_field+1] := res + 1 ; execute ((Sequence{next_field}->union(Sequence{ res + 1 })) : q) ) else skip)) ; return results; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) def crt(rs,ms): def _inv_gcd(a,b): if a==0 : return(b,0) s,t,m0,m1=b,a,0,1 while t : u=s//t s-=t*u m0-=m1*u tmp=s s=t t=tmp tmp=m0 m0=m1 m1=tmp if m0<0 : m0+=b//s return(s,m0) assert len(rs)==len(ms) n=len(rs) r0,m0=0,1 for i in range(n): assert 1<=ms[i] r1,m1=rs[i]% ms[i],ms[i] if m0toInteger() ; skip ; var divs : Set := Set{}->union(()) ; var m : int := 1 ; var NN : int := 2 * N ; while (m * m->compareTo(NN)) <= 0 do ( if NN mod m = 0 then ( execute ((m) : divs) ; execute ((NN div m) : divs) ) else skip ; m := m + 1) ; var ans : double := NN - 1 ; for x : divs do ( var y : int := NN div x ; if y = 1 then ( continue ) else skip ; var r : OclAny := null; Sequence{r,m} := crt(Sequence{0}->union(Sequence{ -1 }), Sequence{x}->union(Sequence{ y })) ; if r = m & (m == 0) then ( continue ) else skip ; ans := Set{ans, r}->min()) ; execute (ans)->display(); operation crt(rs : OclAny, ms : OclAny) : OclAny pre: true post: true activity: skip ; assert (rs)->size() = (ms)->size() do "assertion failed" ; var n : int := (rs)->size() ; var r0 : OclAny := null; Sequence{r0,m0} := Sequence{0,1} ; for i : Integer.subrange(0, n-1) do ( assert 1 <= ms[i+1] do "assertion failed" ; var r1 : OclAny := null; Sequence{r1,m1} := Sequence{rs[i+1] mod ms[i+1],ms[i+1]} ; if (m0->compareTo(m1)) < 0 then ( var r0 : OclAny := null; var r1 : OclAny := null; Sequence{r0,r1,m0,m1} := Sequence{r1,r0,m1,m0} ) else skip ; if m0 mod m1 = 0 then ( if r0 mod m1 /= r1 then ( return Sequence{0, 0} ) else skip ; continue ) else skip ; var g : OclAny := null; var im : OclAny := null; Sequence{g,im} := _inv_gcd(m0, m1) ; var u1 : int := m1 div g ; if (r1 - r0) mod g then ( return Sequence{0, 0} ) else skip ; var x : int := (r1 - r0) div g mod u1 * im mod u1 ; r0 := r0 + x * m0 ; m0 := m0 * u1 ; if r0 < 0 then ( r0 := r0 + m0 ) else skip) ; return Sequence{r0, m0}; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) def yakusu(n): a=[] for i in range(1,int(math.sqrt(2*n))+2): if(2*n % i==0): a.append(i) for i in range(len(a)): a.append(2*n//a[i]) return sorted(list(set(a))) def exgcd(a,b): if a==0 : return b,0,1 else : g,y,x=exgcd(b % a,a) return g,x-(b//a)*y,y def CRT(b1,m1,b2,m2): d,p,q=exgcd(m1,m2) if(b2-b1)% d!=0 : return 0,-1 m=m1*(m2//d) tmp=(b2-b1)//d*p %(m2//d) r=(b1+m1*tmp)% m return r,m x=yakusu(n) a=1e16 for i in range(len(x)): r,m=CRT(-1,2*n//x[i],0,x[i]) if(r>0): a=min(a,r) print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; skip ; skip ; var x : OclAny := yakusu(n) ; a := ("1e16")->toReal() ; for i : Integer.subrange(0, (x)->size()-1) do ( Sequence{r,m} := CRT(-1, 2 * n div x[i+1], 0, x[i+1]) ; if (r > 0) then ( a := Set{a, r}->min() ) else skip) ; execute (a)->display(); operation yakusu(n : OclAny) : OclAny pre: true post: true activity: var a : Sequence := Sequence{} ; for i : Integer.subrange(1, ("" + (((2 * n)->sqrt())))->toInteger() + 2-1) do ( if (2 * n mod i = 0) then ( execute ((i) : a) ) else skip) ; for i : Integer.subrange(0, (a)->size()-1) do ( execute ((2 * n div a[i+1]) : a)) ; return (Set{}->union((a)))->sort(); operation exgcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a = 0 then ( return b, 0, 1 ) else ( var g : OclAny := null; var y : OclAny := null; var x : OclAny := null; Sequence{g,y,x} := exgcd(b mod a, a) ; return g, x - (b div a) * y, y ); operation CRT(b1 : OclAny, m1 : OclAny, b2 : OclAny, m2 : OclAny) : OclAny pre: true post: true activity: var d : OclAny := null; var p : OclAny := null; var q : OclAny := null; Sequence{d,p,q} := exgcd(m1, m2) ; if (b2 - b1) mod d /= 0 then ( return 0, -1 ) else skip ; var m : double := m1 * (m2 div d) ; var tmp : int := (b2 - b1) div d * p mod (m2 div d) ; var r : int := (b1 + m1 * tmp) mod m ; return r, m; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthTerm(N): return((2*N+3)*(2*N+3)-2*N); n=4 print(nthTerm(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := 4 ; execute (nthTerm(n))->display(); operation nthTerm(N : OclAny) pre: true post: true activity: return ((2 * N + 3) * (2 * N + 3) - 2 * N);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def oddTriangularNumber(N): return(N*((2*N)-1)) if __name__=='__main__' : N=3 print(oddTriangularNumber(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( N := 3 ; execute (oddTriangularNumber(N))->display() ) else skip; operation oddTriangularNumber(N : OclAny) : OclAny pre: true post: true activity: return (N * ((2 * N) - 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def triplets(N): return((N+1)*(N+2))//2 ; N=50 ; print(triplets(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 50; ; execute (triplets(N))->display(); operation triplets(N : OclAny) pre: true post: true activity: return ((N + 1) * (N + 2)) div 2;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p=int(input()) for j in range(p): n,x=map(int,input().split()) s=set() num=0 for i in input().split(): s.add(int(i)) m=max(s) if x in s : print(1) else : if x % m==0 : num+=x//m else : if x//m<1 : k=1 else : k=x//m num+=k+1 print(num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, p-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Set := Set{}->union(()) ; var num : int := 0 ; for i : input().split() do ( execute ((("" + ((i)))->toInteger()) : s)) ; var m : OclAny := (s)->max() ; if (s)->includes(x) then ( execute (1)->display() ) else ( if x mod m = 0 then ( num := num + x div m ) else ( if x div m < 1 then ( var k : int := 1 ) else ( k := x div m ) ; num := num + k + 1 ) ; execute (num)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthTerm(N): nth=0 ; if(N % 2==1): nth=(N*N)+1 ; else : nth=(N*N)-1 ; return nth ; if __name__=="__main__" : N=5 ; print(nthTerm(N)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := 5; ; execute (nthTerm(N))->display(); ) else skip; operation nthTerm(N : OclAny) pre: true post: true activity: var nth : int := 0; ; if (N mod 2 = 1) then ( nth := (N * N) + 1; ) else ( nth := (N * N) - 1; ) ; return nth;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthTerm(N): nth=0 nth=(N*N*(N+1))//2 return nth N=5 print(nthTerm(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 5 ; execute (nthTerm(N))->display(); operation nthTerm(N : OclAny) : OclAny pre: true post: true activity: var nth : int := 0 ; nth := (N * N * (N + 1)) div 2 ; return nth; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(arr,n): modify=0 if(arr[0]>arr[1]): arr[0]=arr[1]//2 modify+=1 for i in range(1,n-1): if((arr[i-1]arr[i]and arr[i+1]>arr[i])): arr[i]=(arr[i-1]+arr[i+1])//2 if(arr[i]==arr[i-1]or arr[i]==arr[i+1]): return False modify+=1 if(arr[n-1]1): return False return True if __name__=="__main__" : arr=[2,4,8,6,9,12] n=len(arr) if(check(arr,n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{2}->union(Sequence{4}->union(Sequence{8}->union(Sequence{6}->union(Sequence{9}->union(Sequence{ 12 }))))) ; n := (arr)->size() ; if (check(arr, n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation check(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var modify : int := 0 ; if ((arr->first()->compareTo(arr[1+1])) > 0) then ( arr->first() := arr[1+1] div 2 ; modify := modify + 1 ) else skip ; for i : Integer.subrange(1, n - 1-1) do ( if (((arr[i - 1+1]->compareTo(arr[i+1])) < 0 & (arr[i + 1+1]->compareTo(arr[i+1])) < 0) or ((arr[i - 1+1]->compareTo(arr[i+1])) > 0 & (arr[i + 1+1]->compareTo(arr[i+1])) > 0)) then ( arr[i+1] := (arr[i - 1+1] + arr[i + 1+1]) div 2 ; if (arr[i+1] = arr[i - 1+1] or arr[i+1] = arr[i + 1+1]) then ( return false ) else skip ; modify := modify + 1 ) else skip) ; if ((arr[n - 1+1]->compareTo(arr[n - 2+1])) < 0) then ( modify := modify + 1 ) else skip ; if (modify > 1) then ( return false ) else skip ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() pr1="AB" pr2="BA" try : t=s.index(pr1) t1=s.rfind(pr2) t2=s.index(pr2) t3=s.rfind(pr1) if pr1 in s and pr2 in s and(abs(t-t1)>1 or abs(t2-t3)>1): print("YES") else : print("NO") except : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var pr1 : String := "AB" ; var pr2 : String := "BA" ; try ( var t : int := s->indexOf(pr1) - 1 ; var t1 : OclAny := s.rfind(pr2) ; var t2 : int := s->indexOf(pr2) - 1 ; var t3 : OclAny := s.rfind(pr1) ; if (s)->characters()->includes(pr1) & (s)->characters()->includes(pr2) & ((t - t1)->abs() > 1 or (t2 - t3)->abs() > 1) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )) catch (_e : OclException) do ( execute ("NO")->display()) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def swap(state,x,y): s=list(copy.deepcopy(state)) s[x],s[y]=s[y],s[x] return tuple(s) from collections import deque import copy MAGIC=37 move=((1,4),(0,2,5),(1,3,6),(2,7),(0,5),(1,4,6),(2,5,7),(3,6)) Q=deque() Q.append(((0,1,2,3,4,5,6,7),0)) hash={} hash[(0,1,2,3,4,5,6,7)]=0 while Q : state,x=Q.popleft() step=hash[state]+1 if step>MAGIC : continue for y in move[x]: nstate=swap(state,x,y) if nstate not in hash : nstep=100 else : nstep=hash[nstate] if stepfirst() ; Q := Q->tail() ; var step : int := hash[state+1] + 1 ; if (step->compareTo(MAGIC)) > 0 then ( continue ) else skip ; for y : move[x+1] do ( var nstate : OclAny := swap(state, x, y) ; if (hash)->excludes(nstate) then ( var nstep : int := 100 ) else ( nstep := hash[nstate+1] ) ; if (step->compareTo(nstep)) < 0 then ( execute ((Sequence{nstate, y}) : Q) ; hash[nstate+1] := step ) else skip)) ; while 1 do ( try ( state := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) catch (_e : OclException) do ( break) ; execute (hash[state+1])->display()); operation swap(state : OclAny, x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var s : Sequence := (copy.deepcopy(state)) ; var s[x+1] : OclAny := null; var s[y+1] : OclAny := null; Sequence{s[x+1],s[y+1]} := Sequence{s[y+1],s[x+1]} ; return (s); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def twoSubstrings(s): flag=False hasAB=False hasBA=False indexes=[] for i in range(len(s)-1): if s[i : i+2]=="AB" : hasAB=True indexes.append([i,i+2,1]) if s[i : i+2]=="BA" : hasBA=True indexes.append([i,i+2,2]) if not(hasAB and hasBA): return "NO" if len(indexes)<2 : return "NO" i=1 while idisplay() ) else skip; operation twoSubstrings(s : OclAny) : OclAny pre: true post: true activity: var flag : boolean := false ; var hasAB : boolean := false ; var hasBA : boolean := false ; var indexes : Sequence := Sequence{} ; for i : Integer.subrange(0, (s)->size() - 1-1) do ( if s.subrange(i+1, i + 2) = "AB" then ( hasAB := true ; execute ((Sequence{i}->union(Sequence{i + 2}->union(Sequence{ 1 }))) : indexes) ) else skip ; if s.subrange(i+1, i + 2) = "BA" then ( hasBA := true ; execute ((Sequence{i}->union(Sequence{i + 2}->union(Sequence{ 2 }))) : indexes) ) else skip) ; if not((hasAB & hasBA)) then ( return "NO" ) else skip ; if (indexes)->size() < 2 then ( return "NO" ) else skip ; var i : int := 1 ; while (i->compareTo((indexes)->size())) < 0 do ( for j : Integer.subrange(i, (indexes)->size()-1) do ( if indexes[j+1][2+1] /= indexes[i - 1+1][2+1] & indexes[j+1]->first() + 1 /= indexes[i - 1+1][1+1] then ( flag := true ; break ) else skip) ; i := i + 1) ; return if flag then "YES" else "NO" endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(s): ab=[] ba=[] for i in range(len(s)-1): if s[i]=="A" and s[i+1]=='B' : ab.append(i) elif s[i]=="B" and s[i+1]=='A' : ba.append(i) if len(ab)==0 or len(ba)==0 : return "NO" for i in range(len(ab)): for j in range(len(ba)): if abs(ab[i]-ba[j])>1 : return "YES" return "NO" for _ in range(1): print(solve(input())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, 1-1) do ( execute (solve((OclFile["System.in"]).readLine()))->display()); operation solve(s : OclAny) : OclAny pre: true post: true activity: var ab : Sequence := Sequence{} ; var ba : Sequence := Sequence{} ; for i : Integer.subrange(0, (s)->size() - 1-1) do ( if s[i+1] = "A" & s[i + 1+1] = 'B' then ( execute ((i) : ab) ) else (if s[i+1] = "B" & s[i + 1+1] = 'A' then ( execute ((i) : ba) ) else skip)) ; if (ab)->size() = 0 or (ba)->size() = 0 then ( return "NO" ) else skip ; for i : Integer.subrange(0, (ab)->size()-1) do ( for j : Integer.subrange(0, (ba)->size()-1) do ( if (ab[i+1] - ba[j+1])->abs() > 1 then ( return "YES" ) else skip)) ; return "NO"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() n=len(s) idx=0 res=False while idxsize() ; var idx : int := 0 ; var res : boolean := false ; while (idx->compareTo(n)) < 0 do ( if ('AB')->characters()->includes(s.subrange(idx+1, idx + 2)) then ( res := res or (s.subrange(idx + 2+1))->includes('BA') ) else (if ('BA')->characters()->includes(s.subrange(idx+1, idx + 2)) then ( res := res or (s.subrange(idx + 2+1))->includes('AB') ) else skip) ; idx := idx + 1) ; execute (if res then 'YES' else 'NO' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(s,k): count,length,pos=0,0,0 m=dict.fromkeys(s,0) for i in range(len(s)): m[s[i]]+=1 length+=1 if length>k : m[s[pos]]-=1 pos+=1 length-=1 if length==k and m[s[i]]==length : count+=1 print(count) if __name__=="__main__" : s="aaaabbbccdddd" k=4 solve(s,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "aaaabbbccdddd" ; k := 4 ; solve(s, k) ) else skip; operation solve(s : OclAny, k : OclAny) pre: true post: true activity: var count : OclAny := null; var length : OclAny := null; var pos : OclAny := null; Sequence{count,length,pos} := Sequence{0,0,0} ; var m : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))) ; for i : Integer.subrange(0, (s)->size()-1) do ( m[s[i+1]+1] := m[s[i+1]+1] + 1 ; length := length + 1 ; if (length->compareTo(k)) > 0 then ( m[s[pos+1]+1] := m[s[pos+1]+1] - 1 ; pos := pos + 1 ; length := length - 1 ) else skip ; if length = k & m[s[i+1]+1] = length then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxOperations(X,Y): if(X>Y): return-1 ; diff=Y-X ; if(diff==1): return-1 ; if(diff % 2==0): return(diff//2); return(1+((diff-3)//2)); if __name__=="__main__" : X=5 ; Y=16 ; print(maxOperations(X,Y)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( X := 5; Y := 16; ; execute (maxOperations(X, Y))->display(); ) else skip; operation maxOperations(X : OclAny, Y : OclAny) pre: true post: true activity: if ((X->compareTo(Y)) > 0) then ( return -1; ) else skip ; var diff : double := Y - X; ; if (diff = 1) then ( return -1; ) else skip ; if (diff mod 2 = 0) then ( return (diff div 2); ) else skip ; return (1 + ((diff - 3) div 2));; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ReplaceElements(arr,n): min_ele=arr[0] arr[0]=-1 for i in range(1,n): if(min_ele=arr[i]): temp=arr[i] arr[i]=min_ele min_ele=temp if __name__=="__main__" : arr=[4,5,2,1,7,6] n=len(arr) ReplaceElements(arr,n) for i in range(n): print(arr[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{4}->union(Sequence{5}->union(Sequence{2}->union(Sequence{1}->union(Sequence{7}->union(Sequence{ 6 }))))) ; n := (arr)->size() ; ReplaceElements(arr, n) ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()) ) else skip; operation ReplaceElements(arr : OclAny, n : OclAny) pre: true post: true activity: var min_ele : OclAny := arr->first() ; arr->first() := -1 ; for i : Integer.subrange(1, n-1) do ( if ((min_ele->compareTo(arr[i+1])) < 0) then ( arr[i+1] := min_ele ) else (if ((min_ele->compareTo(arr[i+1])) >= 0) then ( var temp : OclAny := arr[i+1] ; arr[i+1] := min_ele ; min_ele := temp ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) a=list(map(int,input().split())) mod=10**9+7 pw=[1 for i in range(n)] for i in range(1,n): pw[i]=pw[i-1]*2 % mod ans=0 a.sort() for i in range(1,n): ans+=((pw[i]-1)*(pw[n-i]-1)% mod)*(a[i]-a[i-1])% mod ans %=mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mod : double := (10)->pow(9) + 7 ; var pw : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (1)) ; for i : Integer.subrange(1, n-1) do ( pw[i+1] := pw[i - 1+1] * 2 mod mod) ; var ans : int := 0 ; a := a->sort() ; for i : Integer.subrange(1, n-1) do ( ans := ans + ((pw[i+1] - 1) * (pw[n - i+1] - 1) mod mod) * (a[i+1] - a[i - 1+1]) mod mod ; ans := ans mod mod) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n,x=map(int,input().split()) w=list(map(int,input().split())) a=max(w) if a>=x : for i in w : if i==x : print(1) break else : print(2) else : print((x+a-1)//a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := (w)->max() ; if (a->compareTo(x)) >= 0 then ( (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name w))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name i)))) == (comparison (expr (atom (name x))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ))))))))))))))) ) else ( execute ((x + a - 1) div a)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : t,p,r=map(int,input().split()) if t==0 and p==0 and r==0 : break logs=[input().split()for _ in range(r)] score=[[0,0,-i,[0]*p]for i in range(t)] c_n,pen,w_n=0,1,3 for tid,pid,time,msg in logs : tid,pid,time=int(tid)-1,int(pid)-1,int(time) if msg=='WRONG' : score[tid][w_n][pid]+=1 elif msg=='CORRECT' : score[tid][c_n]+=1 score[tid][pen]-=(score[tid][w_n][pid]*1200+time) score[tid][w_n][pid]=0 score=sorted(score,reverse=True) for c_n,pen,t,_ in score : print(abs(t)+1,c_n,abs(pen)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var t : OclAny := null; var p : OclAny := null; var r : OclAny := null; Sequence{t,p,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if t = 0 & p = 0 & r = 0 then ( break ) else skip ; var logs : Sequence := Integer.subrange(0, r-1)->select(_anon | true)->collect(_anon | (input().split())) ; var score : Sequence := Integer.subrange(0, t-1)->select(i | true)->collect(i | (Sequence{0}->union(Sequence{0}->union(Sequence{-i}->union(Sequence{ MatrixLib.elementwiseMult(Sequence{ 0 }, p) }))))) ; var c_n : OclAny := null; var pen : OclAny := null; var w_n : OclAny := null; Sequence{c_n,pen,w_n} := Sequence{0,1,3} ; for _tuple : logs do (var _indx : int := 1; var tid : OclAny := _tuple->at(_indx); _indx := _indx + 1; var pid : OclAny := _tuple->at(_indx); _indx := _indx + 1; var time : OclAny := _tuple->at(_indx); _indx := _indx + 1; var msg : OclAny := _tuple->at(_indx); var tid : OclAny := null; var pid : OclAny := null; var time : OclAny := null; Sequence{tid,pid,time} := Sequence{("" + ((tid)))->toInteger() - 1,("" + ((pid)))->toInteger() - 1,("" + ((time)))->toInteger()} ; if msg = 'WRONG' then ( score[tid+1][w_n+1][pid+1] := score[tid+1][w_n+1][pid+1] + 1 ) else (if msg = 'CORRECT' then ( score[tid+1][c_n+1] := score[tid+1][c_n+1] + 1 ; score[tid+1][pen+1] := score[tid+1][pen+1] - (score[tid+1][w_n+1][pid+1] * 1200 + time) ; score[tid+1][w_n+1][pid+1] := 0 ) else skip)) ; score := score->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; for _tuple : score do (var _indx : int := 1; var c_n : OclAny := _tuple->at(_indx); _indx := _indx + 1; var pen : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); _indx := _indx + 1; var _anon : OclAny := _tuple->at(_indx); execute ((t)->abs() + 1)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : T,P,R=map(int,input().split()) if T==0 and P==0 and R==0 : break submits=[] scores={} for i in range(1,T+1): scores[i]=[0,0] for i in range(R): tid,pid,time,message=map(str,input().split()) tid=int(tid) pid=int(pid) time=int(time) submits.append([tid,pid,time,message]) for i in range(len(submits)): if submits[i][3]=='CORRECT' : wa_cnt=0 for j in range(0,i): if submits[j][0]==submits[i][0]and submits[j][1]==submits[i][1]: wa_cnt+=1 scores[submits[i][0]][0]+=1 scores[submits[i][0]][1]+=(1200*wa_cnt+submits[i][2]) scores=sorted(scores.items(),key=lambda x :(x[1][0],-x[1][1],-x[0]),reverse=True) for score in scores : print(score[0],score[1][0],score[1][1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var T : OclAny := null; var P : OclAny := null; var R : OclAny := null; Sequence{T,P,R} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if T = 0 & P = 0 & R = 0 then ( break ) else skip ; var submits : Sequence := Sequence{} ; var scores : OclAny := Set{} ; for i : Integer.subrange(1, T + 1-1) do ( scores[i+1] := Sequence{0}->union(Sequence{ 0 })) ; for i : Integer.subrange(0, R-1) do ( var tid : OclAny := null; var pid : OclAny := null; var time : OclAny := null; var message : OclAny := null; Sequence{tid,pid,time,message} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; var tid : int := ("" + ((tid)))->toInteger() ; var pid : int := ("" + ((pid)))->toInteger() ; var time : int := ("" + ((time)))->toInteger() ; execute ((Sequence{tid}->union(Sequence{pid}->union(Sequence{time}->union(Sequence{ message })))) : submits)) ; for i : Integer.subrange(0, (submits)->size()-1) do ( if submits[i+1][3+1] = 'CORRECT' then ( var wa_cnt : int := 0 ; for j : Integer.subrange(0, i-1) do ( if submits[j+1]->first() = submits[i+1]->first() & submits[j+1][1+1] = submits[i+1][1+1] then ( wa_cnt := wa_cnt + 1 ) else skip) ; scores[submits[i+1]->first()+1]->first() := scores[submits[i+1]->first()+1]->first() + 1 ; scores[submits[i+1]->first()+1][1+1] := scores[submits[i+1]->first()+1][1+1] + (1200 * wa_cnt + submits[i+1][2+1]) ) else skip) ; scores := scores->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sortedBy($x | (lambda x : OclAny in (Sequence{x[1+1]->first(), -x[1+1][1+1], -x->first()}))->apply($x)) ; for score : scores do ( execute (score->first())->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque from itertools import permutations from itertools import combinations puz=[0,1,2,3,4,5,6,7] puzper=list(permutations(puz)) dic={} for i in range(40320): dic[puzper[i]]=-1 queue=deque([(0,1,2,3,4,5,6,7)]) dic[(0,1,2,3,4,5,6,7)]=0 while queue : a=queue.popleft() poszero=a.index(0) yy=(poszero)//4 xx=(poszero)% 4 dydx=[[1,0],[-1,0],[0,1],[0,-1]] for j,k in dydx : newy,newx=yy+j,xx+k if(0<=newy<2)and(0<=newx<4): newp=newy*4+newx lisa=list(a) lisa[poszero],lisa[newp]=lisa[newp],lisa[poszero] newper=tuple(lisa) if(dic[newper]==-1): dic[newper]=dic[a]+1 queue.append(newper) while True : try : inp=list(map(int,input().split())) print(dic[tuple(inp)]) except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var puz : Sequence := Sequence{0}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 7 }))))))) ; var puzper : Sequence := (permutations(puz)) ; var dic : OclAny := Set{} ; for i : Integer.subrange(0, 40320-1) do ( dic[puzper[i+1]+1] := -1) ; var queue : Sequence := (Sequence{ Sequence{0, 1, 2, 3, 4, 5, 6, 7} }) ; dic[Sequence{0, 1, 2, 3, 4, 5, 6, 7}+1] := 0 ; while queue do ( var a : OclAny := queue->first() ; queue := queue->tail() ; var poszero : int := a->indexOf(0) - 1 ; var yy : int := (poszero) div 4 ; var xx : int := (poszero) mod 4 ; var dydx : Sequence := Sequence{Sequence{1}->union(Sequence{ 0 })}->union(Sequence{Sequence{-1}->union(Sequence{ 0 })}->union(Sequence{Sequence{0}->union(Sequence{ 1 })}->union(Sequence{ Sequence{0}->union(Sequence{ -1 }) }))) ; for _tuple : dydx do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var k : OclAny := _tuple->at(_indx); var newy : OclAny := null; var newx : OclAny := null; Sequence{newy,newx} := Sequence{yy + j,xx + k} ; if (0 <= newy & (newy < 2)) & (0 <= newx & (newx < 4)) then ( var newp : double := newy * 4 + newx ; var lisa : Sequence := (a) ; var lisa[poszero+1] : OclAny := null; var lisa[newp+1] : OclAny := null; Sequence{lisa[poszero+1],lisa[newp+1]} := Sequence{lisa[newp+1],lisa[poszero+1]} ; var newper : Sequence := (lisa) ; if (dic->restrict(newper) = -1) then ( dic->restrict(newper) := dic[a+1] + 1 ; execute ((newper) : queue) ) else skip ) else skip)) ; while true do ( try ( var inp : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (dic->restrict((inp)))->display()) catch (_e : OclException) do ( break) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : T,P,R=map(int,input().split()) if not T and not P and not R : break d={str(i):{str(j):[False,0]for j in range(1,P+1)}for i in range(1,T+1)} for _ in range(R): tid,pid,time,m=input().split() if not d[tid][pid][0]: if m=="WRONG" : d[tid][pid][1]+=1 else : d[tid][pid][0]=True d[tid][pid][1]*=1200 d[tid][pid][1]+=int(time) l=[] for i in d.keys(): cd=[j for j in d[i].values()if j[0]] sc=sum([j[1]for j in cd]) l.extend([(int(i),len(cd),sc)]) p=sorted(l,key=lambda x :(-x[1],x[2],x[0])) for i in p : print(i[0],i[1],i[2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var T : OclAny := null; var P : OclAny := null; var R : OclAny := null; Sequence{T,P,R} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if not(T) & not(P) & not(R) then ( break ) else skip ; var d : Map := Integer.subrange(1, T + 1-1)->select(i | true)->collect(i | Map{("" + ((i))) |-> Integer.subrange(1, P + 1-1)->select(j | true)->collect(j | Map{("" + ((j))) |-> Sequence{false}->union(Sequence{ 0 })})->unionAll()})->unionAll() ; for _anon : Integer.subrange(0, R-1) do ( var tid : OclAny := null; var pid : OclAny := null; var time : OclAny := null; var m : OclAny := null; Sequence{tid,pid,time,m} := input().split() ; if not(d[tid+1][pid+1]->first()) then ( if m = "WRONG" then ( d[tid+1][pid+1][1+1] := d[tid+1][pid+1][1+1] + 1 ) else ( d[tid+1][pid+1]->first() := true ; d[tid+1][pid+1][1+1] := d[tid+1][pid+1][1+1] * 1200 ; d[tid+1][pid+1][1+1] := d[tid+1][pid+1][1+1] + ("" + ((time)))->toInteger() ) ) else skip) ; var l : Sequence := Sequence{} ; for i : d.keys() do ( var cd : Sequence := d[i+1].values()->select(j | j->first())->collect(j | (j)) ; var sc : OclAny := (cd->select(j | true)->collect(j | (j[1+1])))->sum() ; l := l->union(Sequence{ Sequence{("" + ((i)))->toInteger(), (cd)->size(), sc} })) ; var p : Sequence := l->sortedBy($x | (lambda x : OclAny in (Sequence{-x[1+1], x[2+1], x->first()}))->apply($x)) ; for i : p do ( execute (i->first())->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Score : def __init__(self,id,solve,penalty): self.id=id self.solve=solve self.penalty=penalty def __lt__(self,other): if(self.penalty==other.penalty)and(self.solve==other.solve): return self.idother.solve while True : t,p,r=map(int,input().split()) if(t,p,r)==(0,0,0): break tp=[[0]*p for i in range(t)] ts=[Score(i+1,0,0)for i in range(t)] for i in range(r): tid,pid,time,message=input().split() tid,pid,time=map(int,[tid,pid,time]) if message=='CORRECT' : ts[tid-1].solve+=1 ts[tid-1].penalty+=(tp[tid-1][pid-1]*1200+time) else : tp[tid-1][pid-1]+=1 ts=sorted(ts) for s in ts : print('{}{}{}'.format(s.id,s.solve,s.penalty)) ------------------------------------------------------------ OCL File: --------- class Score { static operation newScore() : Score pre: true post: Score->exists( _x | result = _x ); attribute id : OclAny := id; attribute solve : OclAny := solve; attribute penalty : OclAny := penalty; operation initialise(id : OclAny,solve : OclAny,penalty : OclAny) : Score pre: true post: true activity: self.id := id ; self.solve := solve ; self.penalty := penalty; return self; operation __lt__(other : OclAny) : OclAny pre: true post: true activity: if (self.penalty = other.penalty) & (self.solve = other.solve) then ( return (self.id->compareTo(other.id)) < 0 ) else (if (self.solve = other.solve) then ( return (self.penalty->compareTo(other.penalty)) < 0 ) else ( return (self.solve->compareTo(other.solve)) > 0 ) ) ; } class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var t : OclAny := null; var p : OclAny := null; var r : OclAny := null; Sequence{t,p,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if Sequence{t, p, r} = Sequence{0, 0, 0} then ( break ) else skip ; var tp : Sequence := Integer.subrange(0, t-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, p))) ; var ts : Sequence := Integer.subrange(0, t-1)->select(i | true)->collect(i | ((Score.newScore()).initialise(i + 1, 0, 0))) ; for i : Integer.subrange(0, r-1) do ( var tid : OclAny := null; var pid : OclAny := null; var time : OclAny := null; var message : OclAny := null; Sequence{tid,pid,time,message} := input().split() ; var tid : OclAny := null; var pid : OclAny := null; var time : OclAny := null; Sequence{tid,pid,time} := (Sequence{tid}->union(Sequence{pid}->union(Sequence{ time })))->collect( _x | (OclType["int"])->apply(_x) ) ; if message = 'CORRECT' then ( ts[tid - 1+1].solve := ts[tid - 1+1].solve + 1 ; ts[tid - 1+1].penalty := ts[tid - 1+1].penalty + (tp[tid - 1+1][pid - 1+1] * 1200 + time) ) else ( tp[tid - 1+1][pid - 1+1] := tp[tid - 1+1][pid - 1+1] + 1 )) ; ts := ts->sort() ; for s : ts do ( execute (StringLib.interpolateStrings('{}{}{}', Sequence{s.id, s.solve, s.penalty}))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : t,p,r=map(int,input().split()) if t==0 : break teamdata=[[0,0,i+1,set()]for i in range(t)] data=[] for i in range(r): b,c,a,d=input().split() b,c,a=map(int,(b,c,a)) if d=='CORRECT' : teamdata[b-1][0]+=1 teamdata[b-1][1]+=a teamdata[b-1][3].add(c) data.append([a,b,c,d]) for a,b,c,d in data : if d!='CORRECT' and(c in teamdata[b-1][3]): teamdata[b-1][1]+=1200 teamdata=sorted(teamdata,key=lambda x :(-x[0],x[1],x[2])) for i in range(t): print(teamdata[i][2],teamdata[i][0],teamdata[i][1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var t : OclAny := null; var p : OclAny := null; var r : OclAny := null; Sequence{t,p,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if t = 0 then ( break ) else skip ; var teamdata : Sequence := Integer.subrange(0, t-1)->select(i | true)->collect(i | (Sequence{0}->union(Sequence{0}->union(Sequence{i + 1}->union(Sequence{ Set{}->union(()) }))))) ; var data : Sequence := Sequence{} ; for i : Integer.subrange(0, r-1) do ( var b : OclAny := null; var c : OclAny := null; var a : OclAny := null; var d : OclAny := null; Sequence{b,c,a,d} := input().split() ; var b : OclAny := null; var c : OclAny := null; var a : OclAny := null; Sequence{b,c,a} := (Sequence{b, c, a})->collect( _x | (OclType["int"])->apply(_x) ) ; if d = 'CORRECT' then ( teamdata[b - 1+1]->first() := teamdata[b - 1+1]->first() + 1 ; teamdata[b - 1+1][1+1] := teamdata[b - 1+1][1+1] + a ; (expr (atom (name teamdata)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 3))))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))) ) else skip ; execute ((Sequence{a}->union(Sequence{b}->union(Sequence{c}->union(Sequence{ d })))) : data)) ; for _tuple : data do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); if d /= 'CORRECT' & ((teamdata[b - 1+1][3+1])->includes(c)) then ( teamdata[b - 1+1][1+1] := teamdata[b - 1+1][1+1] + 1200 ) else skip) ; teamdata := teamdata->sortedBy($x | (lambda x : OclAny in (Sequence{-x->first(), x[1+1], x[2+1]}))->apply($x)) ; for i : Integer.subrange(0, t-1) do ( execute (teamdata[i+1][2+1])->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def longestAr(n,arr): count=dict() for i in arr : count[i]=count.get(i,0)+1 kset=count.keys() maxm=0 for it in list(kset): a=it cur=0 cur1=0 cur2=0 if((a+1)in count): cur1=count[a+1] if((a-1)in count): cur2=count[a-1] cur=count[a]+max(cur1,cur2) if(cur>maxm): maxm=cur return maxm if __name__=='__main__' : n=8 arr=[2,2,3,5,5,6,6,6] maxLen=longestAr(n,arr) print(maxLen) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 8 ; arr := Sequence{2}->union(Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{5}->union(Sequence{6}->union(Sequence{6}->union(Sequence{ 6 }))))))) ; var maxLen : OclAny := longestAr(n, arr) ; execute (maxLen)->display() ) else skip; operation longestAr(n : OclAny, arr : OclAny) : OclAny pre: true post: true activity: var count : Map := (arguments ( )) ; for i : arr do ( count[i+1] := count.get(i, 0) + 1) ; var kset : OclAny := count.keys() ; var maxm : int := 0 ; for it : (kset) do ( var a : OclAny := it ; var cur : int := 0 ; var cur1 : int := 0 ; var cur2 : int := 0 ; if ((count)->includes((a + 1))) then ( cur1 := count[a + 1+1] ) else skip ; if ((count)->includes((a - 1))) then ( cur2 := count[a - 1+1] ) else skip ; cur := count[a+1] + Set{cur1, cur2}->max() ; if ((cur->compareTo(maxm)) > 0) then ( maxm := cur ) else skip) ; return maxm; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,input().split()) A=list(map(int,input().split())) S=sum(A) ans=0 for i in range(1,int(S**0.5)+1): if S % i!=0 : continue for j in range(2): d=i if j else S//i B=sorted(map(lambda a : a % d,A)) C=[0] for k in range(N): C.append(C[-1]+B[k]) for k in range(N+1): if((N-k)*d-(C[-1]-C[k])-C[k])% d==0 : if max(C[k],(N-k)*d-(C[-1]-C[k]))<=K : ans=max(ans,d) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var S : OclAny := (A)->sum() ; var ans : int := 0 ; for i : Integer.subrange(1, ("" + (((S)->pow(0.5))))->toInteger() + 1-1) do ( if S mod i /= 0 then ( continue ) else skip ; for j : Integer.subrange(0, 2-1) do ( var d : OclAny := if j then i else S div i endif ; var B : Sequence := (A)->collect( _x | (lambda a : OclAny in (a mod d))->apply(_x) )->sort() ; var C : Sequence := Sequence{ 0 } ; for k : Integer.subrange(0, N-1) do ( execute ((C->last() + B[k+1]) : C)) ; for k : Integer.subrange(0, N + 1-1) do ( if ((N - k) * d - (C->last() - C[k+1]) - C[k+1]) mod d = 0 then ( if (Set{C[k+1], (N - k) * d - (C->last() - C[k+1])}->max()->compareTo(K)) <= 0 then ( ans := Set{ans, d}->max() ) else skip ) else skip))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import os import sys if os.getenv("LOCAL"): sys.stdin=open("_in.txt","r") sys.setrecursionlimit(2147483647) INF=float("inf") IINF=10**18 MOD=10**9+7 def get_divisors(n): ret=[] for i in range(1,int(math.sqrt(n))+1): if n % i==0 : ret.append(i) if n//i!=i : ret.append(n//i) return ret def can_make(div): mods=[] for a in A : mods.append(a % div) mods.sort() left=0 right=len(mods)-1 k=K while left<=right and k>=0 : while left=0 and mods[right]% div==0 : right-=1 if right=m : mods[left]-=m mods[right]=0 right-=1 k-=m else : mods[right]+=mods[left] k-=mods[left] mods[left]=0 left+=1 return k>=0 N,K=list(map(int,sys.stdin.readline().split())) A=list(map(int,sys.stdin.readline().split())) divs=get_divisors(sum(A)) for div in sorted(divs,reverse=True): if can_make(div): print(div) exit() assert False ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if os.getenv("LOCAL") then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("_in.txt")) ) else skip ; sys.setrecursionlimit(2147483647) ; var INF : double := ("" + (("inf")))->toReal() ; var IINF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var A : Sequence := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var divs : OclAny := get_divisors((A)->sum()) ; for div : divs->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) do ( if can_make(div) then ( execute (div)->display() ; exit() ) else skip) ; assert false do "assertion failed"; operation get_divisors(n : OclAny) : OclAny pre: true post: true activity: var ret : Sequence := Sequence{} ; for i : Integer.subrange(1, ("" + (((n)->sqrt())))->toInteger() + 1-1) do ( if n mod i = 0 then ( execute ((i) : ret) ; if n div i /= i then ( execute ((n div i) : ret) ) else skip ) else skip) ; return ret; operation can_make(div : OclAny) : OclAny pre: true post: true activity: var mods : Sequence := Sequence{} ; for a : A do ( execute ((a mod div) : mods)) ; mods := mods->sort() ; var left : int := 0 ; var right : double := (mods)->size() - 1 ; var k : OclAny := K ; while (left->compareTo(right)) <= 0 & k >= 0 do ( while (left->compareTo((mods)->size())) < 0 & mods[left+1] mod div = 0 do ( left := left + 1) ; while right >= 0 & mods[right+1] mod div = 0 do ( right := right - 1) ; if (right->compareTo(left)) < 0 then ( return true ) else skip ; var m : double := div - mods[right+1] ; if (mods[left+1]->compareTo(m)) >= 0 then ( mods[left+1] := mods[left+1] - m ; mods[right+1] := 0 ; right := right - 1 ; k := k - m ) else ( mods[right+1] := mods[right+1] + mods[left+1] ; k := k - mods[left+1] ; mods[left+1] := 0 ; left := left + 1 )) ; return k >= 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np import sys def solve(A,K,div): for d in range(div.shape[0]-1,0,-1): res=div[d] B=np.sort(A % res) if B[B.shape[0]-1]==0 : return res i=0 j=B.shape[0]-1 cost=res-B[j] scost=0 while j-i>0 : for n in range(i,j): scost+=B[n] if scost>=cost : while scost>cost : j-=1 cost+=res-B[j] i=n+1 break else : i=j if K>=cost : return res return 1 def divisor(d,div): r=int(d**0.5-0.0000001)+1 ind=0 for i in range(1,r): if d % i==0 : div[ind]=i ind+=1 div[ind]=d//i ind+=1 if d % r==0 : div[ind]=r ind+=1 return ind line=sys.stdin.readline N,K=map(int,line().split()) A=np.fromstring(line(),dtype=np.int64,sep=' ') d=A.sum() div=np.empty(10**6,dtype=np.int64) num=divisor(d,div) div=np.sort(div[: num]) print(solve(A,K,div)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var line : OclAny := (OclFile["System.in"]).readline ; var N : OclAny := null; Sequence{N,K} := (line().split())->collect( _x | (OclType["int"])->apply(_x) ) ; A := ; d := A.sum() ; div := MatrixLib.singleValueMatrix((10)->pow(6), 0.0) ; var num : OclAny := divisor(d, div) ; div := ; execute (solve(A, K, div))->display(); operation solve(A : OclAny, K : OclAny, div : OclAny) : OclAny pre: true post: true activity: for d : Integer.subrange(0 + 1, div.shape->first() - 1)->reverse() do ( var res : OclAny := div[d+1] ; var B : (trailer . (name sort) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name A))) % (expr (atom (name res))))))))) ))) := ; if B[B.shape->first() - 1+1] = 0 then ( return res ) else skip ; var i : int := 0 ; var j : double := B.shape->first() - 1 ; var cost : double := res - B[j+1] ; var scost : int := 0 ; while j - i > 0 do ((compound_stmt for (exprlist (expr (atom (name n)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name scost)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name B)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n)))))))) ]))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name scost)))) >= (comparison (expr (atom (name cost))))))) : (suite (stmt (compound_stmt while (test (logical_test (comparison (comparison (expr (atom (name scost)))) > (comparison (expr (atom (name cost))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name j)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cost)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name res))) - (expr (atom (name B)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name j)))))))))))))))) ; if (K->compareTo(cost)) >= 0 then ( return res ) else skip) ; return 1; operation divisor(d : OclAny, div : OclAny) : OclAny pre: true post: true activity: var r : int := ("" + (((d)->pow(0.5) - 0.0000001)))->toInteger() + 1 ; var ind : int := 0 ; for i : Integer.subrange(1, r-1) do ( if d mod i = 0 then ( div[ind+1] := i ; ind := ind + 1 ; div[ind+1] := d div i ; ind := ind + 1 ) else skip) ; if d mod r = 0 then ( div[ind+1] := r ; ind := ind + 1 ) else skip ; return ind; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def divisors(n,sort=True,reverse=False): sqn=math.sqrt(n) sqn_int=int(sqn) div_list=[] if sqn==sqn_int : div_list.append(sqn_int) loop=range(1,sqn_int) else : loop=range(1,sqn_int+1) for i in loop : if n % i==0 : div_list.append(i) div_list.append(n//i) if sort : div_list.sort(reverse=reverse) return div_list inpl=lambda : list(map(int,input().split())) N,K=inpl() A=inpl() S=sum(A) div=divisors(S,reverse=True) for d in div : mods=[a % d for a in A] mods.sort() Sm=sum(mods) h=Sm//d minK=min(d*(h+1)-sum(mods[N-h-1 :]),sum(mods[: N-h])) if minK<=K : print(d) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var inpl : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := inpl->apply() ; var A : OclAny := inpl->apply() ; var S : OclAny := (A)->sum() ; var div : OclAny := divisors(S, (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; for d : div do ( var mods : Sequence := A->select(a | true)->collect(a | (a mod d)) ; mods := mods->sort() ; var Sm : OclAny := (mods)->sum() ; var h : int := Sm div d ; var minK : OclAny := Set{d * (h + 1) - (mods.subrange(N - h - 1+1))->sum(), (mods.subrange(1,N - h))->sum()}->min() ; if (minK->compareTo(K)) <= 0 then ( execute (d)->display() ; break ) else skip); operation divisors(n : OclAny, sort : OclAny, reverse : OclAny) : OclAny pre: true post: true activity: if sort->oclIsUndefined() then sort := true else skip; if reverse->oclIsUndefined() then reverse := false else skip; var sqn : double := (n)->sqrt() ; var sqn_int : int := ("" + ((sqn)))->toInteger() ; var div_list : Sequence := Sequence{} ; if sqn = sqn_int then ( execute ((sqn_int) : div_list) ; var loop : Sequence := Integer.subrange(1, sqn_int-1) ) else ( loop := Integer.subrange(1, sqn_int + 1-1) ) ; for i : loop do ( if n mod i = 0 then ( execute ((i) : div_list) ; execute ((n div i) : div_list) ) else skip) ; if sort then ( div_list := div_list->sort() ) else skip ; return div_list; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t=int(input()) ans=[] for _ in range(t): n,x=map(int,input().split()) a=list(map(int,input().split())) a.sort(reverse=True) s=set(a) if x in s : ans0=1 elif a[0]>x : ans0=2 else : ans0=x//a[0]+min(x % a[0],1) ans.append(ans0) sys.stdout.write("\n".join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var s : Set := Set{}->union((a)) ; if (s)->includes(x) then ( var ans0 : int := 1 ) else (if (a->first()->compareTo(x)) > 0 then ( ans0 := 2 ) else ( ans0 := x div a->first() + Set{x mod a->first(), 1}->min() ) ) ; execute ((ans0) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def yakusu(n): m=1 re=[] while m**2sr : r-=1 sr+=y-rs[r] if sr>k : break else : l+=1 sl+=rs[l] if sl>k : break print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var aa : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var yk : OclAny := yakusu((aa)->sum()) ; yk := yk->sort() ; for y : yk do ( var rs : Sequence := aa->select(a | a mod y)->collect(a | (a mod y)) ; if not(rs) then ( execute (y)->display() ; exit() ) else skip ; if (rs)->size() = 1 then ( continue ) else skip ; rs := rs->sort() ; var l : int := 0 ; var sl : OclAny := rs->first() ; var r : double := (rs)->size() - 1 ; var sr : double := y - rs[r+1] ; while 1 do ( if l + 1 = r then ( if sl = sr & (sl->compareTo(k)) <= 0 then ( execute (y)->display() ; exit() ) else ( break ) ) else skip ; if (sl->compareTo(sr)) > 0 then ( r := r - 1 ; sr := sr + y - rs[r+1] ; if (sr->compareTo(k)) > 0 then ( break ) else skip ) else ( l := l + 1 ; sl := sl + rs[l+1] ; if (sl->compareTo(k)) > 0 then ( break ) else skip ))) ; execute (1)->display(); operation yakusu(n : OclAny) : OclAny pre: true post: true activity: var m : int := 1 ; var re : Sequence := Sequence{} ; while ((m)->pow(2)->compareTo(n)) < 0 do ( var a : OclAny := null; var md : OclAny := null; Sequence{a,md} := Sequence{(n div m), (n mod m)} ; if md = 0 then ( execute ((m) : re) ; execute ((a) : re) ) else skip ; m := m + 1) ; if (m)->pow(2) = n then ( execute ((m) : re) ) else skip ; return re; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import permutations nums=list(map(int,input().split())) o=input().split() print(min(eval("min(((a{0}b){1}c){2}d,(a{0}b){2}(c{1}d))".format(*o))for a,b,c,d in permutations(nums))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var nums : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var o : OclAny := input().split() ; execute (((argument (test (logical_test (comparison (expr (atom (name eval)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "min(((a{0}b){1}c){2}d,(a{0}b){2}(c{1}d))") (trailer . (name format) (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom (name o)))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name a))) , (expr (atom (name b))) , (expr (atom (name c))) , (expr (atom (name d)))) in (logical_test (comparison (expr (atom (name permutations)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name nums)))))))) )))))))))->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math while True : x,y,s=map(int,input().split()) c=0 if x==0 and y==0 and s==0 : break else : for a in range(1,s): for b in range(1,s-a+1): if math.floor(a*(100+x)/100)+math.floor(b*(100+x)/100)==s : if math.floor(a*(100+y)/100)+math.floor(b*(100+y)/100)>c : c=math.floor(a*(100+y)/100)+math.floor(b*(100+y)/100) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var x : OclAny := null; var y : OclAny := null; var s : OclAny := null; Sequence{x,y,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : int := 0 ; if x = 0 & y = 0 & s = 0 then ( break ) else ( for a : Integer.subrange(1, s-1) do ( for b : Integer.subrange(1, s - a + 1-1) do ( if (a * (100 + x) / 100)->floor() + (b * (100 + x) / 100)->floor() = s then ( if ((a * (100 + y) / 100)->floor() + (b * (100 + y) / 100)->floor()->compareTo(c)) > 0 then ( c := (a * (100 + y) / 100)->floor() + (b * (100 + y) / 100)->floor() ) else skip ) else skip)) ; execute (c)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from inspect import currentframe def debug_print(s): return def debug_key(*args): names={id(v): k for k,v in currentframe().f_back.f_locals.items()} debug_print(','.join(names.get(id(arg),'???')+'='+repr(arg)for arg in args)) def solve(x,y,s): debug_print("\n-----solve-----") ans=0 for first in range(1,s//2+1): second=s-first first_nuki=(first+1)/(x+100)*100 second_nuki=(second+1)/(x+100)*100 if first_nuki.is_integer(): first_nuki-=1 else : first_nuki=int(first_nuki) if second_nuki.is_integer(): second_nuki-=1 else : second_nuki=int(second_nuki) if(int((first_nuki*(100+x))/100)+int((second_nuki*(100+x))/100))!=s : continue sum_y=int((first_nuki*(100+y))/100)+int((second_nuki*(100+y))/100) ans=max(ans,sum_y) print(ans) return if __name__=='__main__' : while True : x_input,y_input,s_input=map(int,input().split()) if x_input==y_input==s_input==0 : break solve(x_input,y_input,s_input) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( while true do ( var x_input : OclAny := null; var y_input : OclAny := null; var s_input : OclAny := null; Sequence{x_input,y_input,s_input} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x_input = y_input & (y_input == s_input) & (s_input == 0) then ( break ) else skip ; solve(x_input, y_input, s_input)) ) else skip; operation debug_print(s : OclAny) pre: true post: true activity: return; operation debug_key(args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) var names : Map := currentframe().f_back.f_locals->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->select(_tuple | true)->collect(_tuple | Map{?(v) |-> k})->unionAll() ; debug_print(StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (expr (expr (atom (name names)) (trailer . (name get) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name id)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arg)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom '???'))))))) )))) + (expr (atom '='))) + (expr (atom (name repr)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arg)))))))) )))))))) (comp_for for (exprlist (expr (atom (name arg)))) in (logical_test (comparison (expr (atom (name args)))))))), ',')); operation solve(x : OclAny, y : OclAny, s : OclAny) pre: true post: true activity: debug_print("\n-----solve-----") ; var ans : int := 0 ; for first : Integer.subrange(1, s div 2 + 1-1) do ( var second : double := s - first ; var first_nuki : double := (first + 1) / (x + 100) * 100 ; var second_nuki : double := (second + 1) / (x + 100) * 100 ; if first_nuki.is_integer() then ( first_nuki := first_nuki - 1 ) else ( first_nuki := ("" + ((first_nuki)))->toInteger() ) ; if second_nuki.is_integer() then ( second_nuki := second_nuki - 1 ) else ( second_nuki := ("" + ((second_nuki)))->toInteger() ) ; if (("" + (((first_nuki * (100 + x)) / 100)))->toInteger() + ("" + (((second_nuki * (100 + x)) / 100)))->toInteger()) /= s then ( continue ) else skip ; var sum_y : int := ("" + (((first_nuki * (100 + y)) / 100)))->toInteger() + ("" + (((second_nuki * (100 + y)) / 100)))->toInteger() ; ans := Set{ans, sum_y}->max()) ; execute (ans)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def tax(p,x): return p*(100+x)//100 def solve(X,Y,S): max_value=0 for a in range(1,S): for b in range(1,S): sum_value=tax(a,X)+tax(b,X) if sum_value==S : c=tax(a,Y)+tax(b,Y) if c>max_value : max_value=c if sum_value>S : break return max_value while True : X,Y,Z=map(int,input().split()) if X==0 : break print(solve(X,Y,Z)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( var Z : OclAny := null; Sequence{X,Y,Z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if X = 0 then ( break ) else skip ; execute (solve(X, Y, Z))->display()); operation tax(p : OclAny, x : OclAny) : OclAny pre: true post: true activity: return p * (100 + x) div 100; operation solve(X : OclAny, Y : OclAny, S : OclAny) : OclAny pre: true post: true activity: var max_value : int := 0 ; for a : Integer.subrange(1, S-1) do ( for b : Integer.subrange(1, S-1) do ( var sum_value : OclAny := tax(a, X) + tax(b, X) ; if sum_value = S then ( var c : OclAny := tax(a, Y) + tax(b, Y) ; if (c->compareTo(max_value)) > 0 then ( max_value := c ) else skip ; if (sum_value->compareTo(S)) > 0 then ( break ) else skip ) else skip)) ; return max_value; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil,floor while 1 : x,y,s=map(int,input().split()) if x==0 : break a=[] for i in range(1,s): p1=ceil(i/(1+x/100)-0.00001) if floor(p1*(1+x/100)+0.00001)!=i : continue p2=ceil((s-i)/(1+x/100)-0.00001) if floor(p2*(1+x/100)+0.00001)!=(s-i): continue a.append(floor(p1*(1+y/100)+0.00001)+floor(p2*(1+y/100)+0.00001)) print(max(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while 1 do ( var x : OclAny := null; var y : OclAny := null; var s : OclAny := null; Sequence{x,y,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x = 0 then ( break ) else skip ; var a : Sequence := Sequence{} ; for i : Integer.subrange(1, s-1) do ( var p1 : OclAny := ceil(i / (1 + x / 100) - 0.00001) ; if floor(p1 * (1 + x / 100) + 0.00001) /= i then ( continue ) else skip ; var p2 : OclAny := ceil((s - i) / (1 + x / 100) - 0.00001) ; if floor(p2 * (1 + x / 100) + 0.00001) /= (s - i) then ( continue ) else skip ; execute ((floor(p1 * (1 + y / 100) + 0.00001) + floor(p2 * (1 + y / 100) + 0.00001)) : a)) ; execute ((a)->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque import sys,heapq,bisect,math,itertools,string,queue,datetime sys.setrecursionlimit(10**8) INF=float('inf') mod=10**9+7 eps=10**-7 def inpl(): return list(map(int,input().split())) def inpl_str(): return list(input().split()) def calc(p,x): return p*(100+x)//100 while True : x,y,s=inpl() if x==0 and y==0 and s==0 : break else : ans=0 for a in range(1,s): ap=calc(a,x) for b in range(1,s): bp=calc(b,x) if ap+bp!=s : continue else : tmp=calc(a,y)+calc(b,y) ans=max(ans,tmp) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var eps : double := (10)->pow(-7) ; skip ; skip ; skip ; while true do ( var y : OclAny := null; var s : OclAny := null; Sequence{x,y,s} := inpl() ; if x = 0 & y = 0 & s = 0 then ( break ) else ( var ans : int := 0 ; for a : Integer.subrange(1, s-1) do ( var ap : OclAny := calc(a, x) ; for b : Integer.subrange(1, s-1) do ( var bp : OclAny := calc(b, x) ; if ap + bp /= s then ( continue ) else ( var tmp : OclAny := calc(a, y) + calc(b, y) ; ans := Set{ans, tmp}->max() ))) ; execute (ans)->display() )); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inpl_str() : OclAny pre: true post: true activity: return (input().split()); operation calc(p : OclAny, x : OclAny) : OclAny pre: true post: true activity: return p * (100 + x) div 100; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) if ab : print("a>b") else : print("a==b") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(b)) < 0 then ( execute ("adisplay() ) else (if (a->compareTo(b)) > 0 then ( execute ("a>b")->display() ) else ( execute ("a==b")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input().split() n=[int(i)for i in n] if(n[0]n[1]): print("a>b") if(n[0]==n[1]): print("a==b") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := input().split() ; n := n->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if ((n->first()->compareTo(n[1+1])) < 0) then ( execute ("adisplay() ) else skip ; if ((n->first()->compareTo(n[1+1])) > 0) then ( execute ("a>b")->display() ) else skip ; if (n->first() = n[1+1]) then ( execute ("a==b")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split(' ')) if a==b : print('a==b') if ab : print('a>b') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; if a = b then ( execute ('a==b')->display() ) else skip ; if (a->compareTo(b)) < 0 then ( execute ('adisplay() ) else skip ; if (a->compareTo(b)) > 0 then ( execute ('a>b')->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=raw_input().split(" ") a=int(a) b=int(b) if ab : print("a>b") else : print("a==b") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := raw_input().split(" ") ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; if (a->compareTo(b)) < 0 then ( execute ("adisplay() ) else (if (a->compareTo(b)) > 0 then ( execute ("a>b")->display() ) else ( execute ("a==b")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def smallestSubWithSum(arr,n,x): min_len=n+1 for start in range(0,n): curr_sum=arr[start] if(curr_sum>x): return 1 for end in range(start+1,n): curr_sum+=arr[end] if curr_sum>x and(end-start+1)union(Sequence{4}->union(Sequence{45}->union(Sequence{6}->union(Sequence{10}->union(Sequence{ 19 }))))) ; x := 51 ; var n1 : int := (arr1)->size() ; var res1 : OclAny := smallestSubWithSum(arr1, n1, x); ; if res1 = n1 + 1 then ( execute ("Not possible")->display() ) else ( execute (res1)->display() ) ; var arr2 : Sequence := Sequence{1}->union(Sequence{10}->union(Sequence{5}->union(Sequence{2}->union(Sequence{ 7 })))) ; var n2 : int := (arr2)->size() ; x := 9 ; var res2 : OclAny := smallestSubWithSum(arr2, n2, x); ; if res2 = n2 + 1 then ( execute ("Not possible")->display() ) else ( execute (res2)->display() ) ; var arr3 : Sequence := Sequence{1}->union(Sequence{11}->union(Sequence{100}->union(Sequence{1}->union(Sequence{0}->union(Sequence{200}->union(Sequence{3}->union(Sequence{2}->union(Sequence{1}->union(Sequence{ 250 }))))))))) ; var n3 : int := (arr3)->size() ; x := 280 ; var res3 : OclAny := smallestSubWithSum(arr3, n3, x) ; if res3 = n3 + 1 then ( execute ("Not possible")->display() ) else ( execute (res3)->display() ); operation smallestSubWithSum(arr : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: var min_len : OclAny := n + 1 ; for start : Integer.subrange(0, n-1) do ( var curr_sum : OclAny := arr[start+1] ; if ((curr_sum->compareTo(x)) > 0) then ( return 1 ) else skip ; for end : Integer.subrange(start + 1, n-1) do ( curr_sum := curr_sum + arr[end+1] ; if (curr_sum->compareTo(x)) > 0 & ((end - start + 1)->compareTo(min_len)) < 0 then ( min_len := (end - start + 1) ) else skip)) ; return min_len;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for j in range(int(input())): n=int(input()) a=list(map(int,input().split())) b=a.copy() b.sort() ans=[] var=0 for i in range(n): for k in range(n): if a[k]==b[i]and k==i : break elif a[k]==b[i]: ans.append([i+1,k+1,1]) for p in range(k,i,-1): temp=a[p] a[p]=a[p-1] a[p-1]=temp for j in range(len(ans)): if ans[j][0]toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : OclAny := a->copy() ; b := b->sort() ; var ans : Sequence := Sequence{} ; var var : int := 0 ; for i : Integer.subrange(0, n-1) do ( for k : Integer.subrange(0, n-1) do ( if a[k+1] = b[i+1] & k = i then ( break ) else (if a[k+1] = b[i+1] then ( execute ((Sequence{i + 1}->union(Sequence{k + 1}->union(Sequence{ 1 }))) : ans) ; for p : Integer.subrange(i + 1, k)->reverse() do ( var temp : OclAny := a[p+1] ; a[p+1] := a[p - 1+1] ; a[p - 1+1] := temp) ) else skip))) ; for j : Integer.subrange(0, (ans)->size()-1) do ( if (ans[j+1]->first()->compareTo(ans[j+1][1+1])) < 0 then ( var := var + 1 ) else skip) ; execute (var)->display() ; for j : Integer.subrange(0, (ans)->size()-1) do ( if (ans[j+1]->first()->compareTo(ans[j+1][1+1])) < 0 then ( ans[j+1][2+1] := ans[j+1][1+1] - ans[j+1]->first() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))))->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- integer=input() li=integer.split(" ") li[0]=int(li[0]) li[1]=int(li[1]) if li[0]>li[1]: print("a>b") elif li[0]first() := ("" + ((li->first())))->toInteger() ; li[1+1] := ("" + ((li[1+1])))->toInteger() ; if (li->first()->compareTo(li[1+1])) > 0 then ( execute ("a>b")->display() ) else (if (li->first()->compareTo(li[1+1])) < 0 then ( execute ("adisplay() ) else ( execute ("a==b")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): a,b=[int(j)for j in input().split(' ')] if not(a % b): print(a % b) else : print(b-a % b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split(' ')->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; if not((a mod b)) then ( execute (a mod b)->display() ) else ( execute (b - a mod b)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) while n>0 : a,b=map(int,input().split()) if a % b==0 : print(0) else : print((a//b+1)*b-a) n=n-1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while n > 0 do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a mod b = 0 then ( execute (0)->display() ) else ( execute ((a div b + 1) * b - a)->display() ) ; n := n - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def func(a,b): mi=(a % b) ma=(a-(a % b))+b if mi==0 : print(0) elif ama-a : print(ma-a) elif a-mitoInteger() ; var A : Sequence := Sequence{} ; var B : Sequence := Sequence{} ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( var k : OclAny := input().split() ; execute ((("" + ((k->first())))->toInteger()) : A) ; execute ((("" + ((k[1+1])))->toInteger()) : B) ; i := i + 1) ; i := 0 ; while (i->compareTo(n)) < 0 do ( func(A[i+1], B[i+1]) ; i := i + 1); operation func(a : OclAny, b : OclAny) pre: true post: true activity: var mi : int := (a mod b) ; var ma : double := (a - (a mod b)) + b ; if mi = 0 then ( execute (0)->display() ) else (if (a->compareTo(b)) < 0 then ( execute (b - a)->display() ) else (if (a - mi->compareTo(ma - a)) > 0 then ( execute (ma - a)->display() ) else (if (a - mi->compareTo(ma - a)) < 0 then ( execute (a - mi)->display() ) else skip ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): s=input() s=s.split() a=int(s[0]) b=int(s[1]) r=a % b x=b-r if(r==0): x=0 print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var s : String := (OclFile["System.in"]).readLine() ; s := s.split() ; var a : int := ("" + ((s->first())))->toInteger() ; var b : int := ("" + ((s[1+1])))->toInteger() ; var r : int := a mod b ; var x : double := b - r ; if (r = 0) then ( x := 0 ) else skip ; execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): a,b=list(map(int,input().split())) print(b-a % b if a % b!=0 else 0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (if a mod b /= 0 then b - a mod b else 0 endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pointIsOnLine(m,c,x,y): if(y==((m*x)+c)): return True ; return False ; m=3 ; c=2 ; x=1 ; y=5 ; if(pointIsOnLine(m,c,x,y)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; m := 3; c := 2; ; x := 1; y := 5; ; if (pointIsOnLine(m, c, x, y)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ); operation pointIsOnLine(m : OclAny, c : OclAny, x : OclAny, y : OclAny) pre: true post: true activity: if (y = ((m * x) + c)) then ( return true; ) else skip ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if((a % b)==0): return b return gcd(b,a % b) def firstFactorialDivisibleNumber(x): i=1 new_x=x for i in range(1,x): new_x/=gcd(i,new_x) if(new_x==1): break return i def main(): x=16 print(firstFactorialDivisibleNumber(x)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if ((a mod b) = 0) then ( return b ) else skip ; return gcd(b, a mod b); operation firstFactorialDivisibleNumber(x : OclAny) : OclAny pre: true post: true activity: var i : int := 1 ; var new_x : OclAny := x ; for i : Integer.subrange(1, x-1) do ( new_x := new_x / gcd(i, new_x) ; if (new_x = 1) then ( break ) else skip) ; return i; operation main() pre: true post: true activity: x := 16 ; execute (firstFactorialDivisibleNumber(x))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if((a % b)==0): return b return gcd(b,a % b) def firstFactorialDivisibleNumber(x): i=1 new_x=x for i in range(1,x): new_x/=gcd(i,new_x) if(new_x==1): break return i def countFactorialXNotY(x,y): return(firstFactorialDivisibleNumber(y)-firstFactorialDivisibleNumber(x)) x=15 y=25 print(countFactorialXNotY(x,y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; x := 15 ; y := 25 ; execute (countFactorialXNotY(x, y))->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if ((a mod b) = 0) then ( return b ) else skip ; return gcd(b, a mod b); operation firstFactorialDivisibleNumber(x : OclAny) : OclAny pre: true post: true activity: var i : int := 1 ; var new_x : OclAny := x ; for i : Integer.subrange(1, x-1) do ( new_x := new_x / gcd(i, new_x) ; if (new_x = 1) then ( break ) else skip) ; return i; operation countFactorialXNotY(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return (firstFactorialDivisibleNumber(y) - firstFactorialDivisibleNumber(x)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) sum=2*n*(2*n+1)//2 if(sum % 2==0): print("NO") return a=[] b=[] x=2*n y=2*n-1 cnt=1 while(cnt<=n): if(cnt % 2!=0): a.append(x) b.append(y) else : a.append(y) b.append(x) cnt+=1 x-=2 y-=2 print("YES") for item in a : print(item,end=" ") for item in b : print(item,end=" ") print() test=1 for t in range(0,test): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var test : int := 1 ; for t : Integer.subrange(0, test-1) do ( solve()); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sum : int := 2 * n * (2 * n + 1) div 2 ; if (sum mod 2 = 0) then ( execute ("NO")->display() ; return ) else skip ; var a : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; var x : int := 2 * n ; var y : double := 2 * n - 1 ; var cnt : int := 1 ; while ((cnt->compareTo(n)) <= 0) do ( if (cnt mod 2 /= 0) then ( execute ((x) : a) ; execute ((y) : b) ) else ( execute ((y) : a) ; execute ((x) : b) ) ; cnt := cnt + 1 ; x := x - 2 ; y := y - 2) ; execute ("YES")->display() ; for item : a do ( execute (item)->display()) ; for item : b do ( execute (item)->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=10000 sequence=[0]*(MAX+1); def vanEckSequence(): for i in range(MAX): for j in range(i-1,-1,-1): if(sequence[j]==sequence[i]): sequence[i+1]=i-j ; break ; def getCount(n): count=1 ; i=n-1 ; while(sequence[i+1]!=0): count+=1 ; i=i-sequence[i+1]; return count ; if __name__=="__main__" : vanEckSequence(); n=5 ; print(getCount(n)); n=11 ; print(getCount(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 10000 ; var sequence : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX + 1)); ; skip ; skip ; if __name__ = "__main__" then ( vanEckSequence(); ; n := 5; ; execute (getCount(n))->display(); ; n := 11; ; execute (getCount(n))->display(); ) else skip; operation vanEckSequence() pre: true post: true activity: for i : Integer.subrange(0, MAX-1) do ( for j : Integer.subrange(-1 + 1, i - 1)->reverse() do ( if (sequence[j+1] = sequence[i+1]) then ( sequence[i + 1+1] := i - j; ; break; ) else skip)); operation getCount(n : OclAny) pre: true post: true activity: var count : int := 1; ; var i : double := n - 1; ; while (sequence[i + 1+1] /= 0) do ( count := count + 1; ; i := i - sequence[i + 1+1];) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class SmallestNumber : def getSmallestNumber(self,num,op): self.ans=float('inf') self.op=op self.calculateSmallestNumer(num.copy(),0) return self.ans def calculateSmallestNumer(self,num,op_ind): if op_ind==len(self.op): self.ans=min(self.ans,num[0]) else : for i in range(len(num)): for j in range(i+1,len(num)): m1=num[i] m2=num[j] num_old=num.copy() num.remove(m1) num.remove(m2) if self.op[op_ind]=='+' : t=m1+m2 elif self.op[op_ind]=='*' : t=m1*m2 num.append(t) self.calculateSmallestNumer(num.copy(),op_ind+1) num=num_old if __name__=='__main__' : obj=SmallestNumber() a,b,c,d=list(map(int,input().strip().split())) op=input().strip().split() print(obj.getSmallestNumber([a,b,c,d],op)) ------------------------------------------------------------ OCL File: --------- class SmallestNumber { static operation newSmallestNumber() : SmallestNumber pre: true post: SmallestNumber->exists( _x | result = _x ); operation getSmallestNumber(num : OclAny,op : OclAny) : OclAny pre: true post: true activity: self.ans := ("" + (('inf')))->toReal() ; self.op := op ; self.calculateSmallestNumer(num->copy(), 0) ; return self.ans; operation calculateSmallestNumer(num : OclAny,op_ind : OclAny) pre: true post: true activity: if op_ind = (self.op)->size() then ( self.ans := Set{self.ans, num->first()}->min() ) else ( for i : Integer.subrange(0, (num)->size()-1) do ( for j : Integer.subrange(i + 1, (num)->size()-1) do ( var m1 : OclAny := num[i+1] ; var m2 : OclAny := num[j+1] ; var num_old : OclAny := num->copy() ; execute ((m1) /: num) ; execute ((m2) /: num) ; if self.op[op_ind+1] = '+' then ( var t : OclAny := m1 + m2 ) else (if self.op[op_ind+1] = '*' then ( t := m1 * m2 ) else skip) ; execute ((t) : num) ; self.calculateSmallestNumer(num->copy(), op_ind + 1) ; num := num_old)) ); } class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var obj : SmallestNumber := (SmallestNumber.newSmallestNumber()).initialise() ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; op := input()->trim().split() ; execute (obj.getSmallestNumber(Sequence{a}->union(Sequence{b}->union(Sequence{c}->union(Sequence{ d }))), op))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def smallestSubWithSum(arr,n,x): curr_sum=0 min_len=n+1 start=0 end=0 while(endx and startunion(Sequence{4}->union(Sequence{45}->union(Sequence{6}->union(Sequence{10}->union(Sequence{ 19 }))))) ; x := 51 ; var n1 : int := (arr1)->size() ; var res1 : OclAny := smallestSubWithSum(arr1, n1, x) ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Not possible"))))))) )))))) if (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name res1)))) == (comparison (expr (expr (atom (name n1))) + (expr (atom (number (integer 1)))))))))) ))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name res1)))))))) )))))))) ; var arr2 : Sequence := Sequence{1}->union(Sequence{10}->union(Sequence{5}->union(Sequence{2}->union(Sequence{ 7 })))) ; var n2 : int := (arr2)->size() ; x := 9 ; var res2 : OclAny := smallestSubWithSum(arr2, n2, x) ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Not possible"))))))) )))))) if (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name res2)))) == (comparison (expr (expr (atom (name n2))) + (expr (atom (number (integer 1)))))))))) ))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name res2)))))))) )))))))) ; var arr3 : Sequence := Sequence{1}->union(Sequence{11}->union(Sequence{100}->union(Sequence{1}->union(Sequence{0}->union(Sequence{200}->union(Sequence{3}->union(Sequence{2}->union(Sequence{1}->union(Sequence{ 250 }))))))))) ; var n3 : int := (arr3)->size() ; x := 280 ; var res3 : OclAny := smallestSubWithSum(arr3, n3, x) ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Not possible"))))))) )))))) if (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name res3)))) == (comparison (expr (expr (atom (name n3))) + (expr (atom (number (integer 1)))))))))) ))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name res3)))))))) )))))))); operation smallestSubWithSum(arr : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: var curr_sum : int := 0 ; var min_len : OclAny := n + 1 ; var start : int := 0 ; var end : int := 0 ; while ((end->compareTo(n)) < 0) do ( while ((curr_sum->compareTo(x)) <= 0 & (end->compareTo(n)) < 0) do ( curr_sum := curr_sum + arr[end+1] ; end := end + 1) ; while ((curr_sum->compareTo(x)) > 0 & (start->compareTo(n)) < 0) do ( if ((end - start->compareTo(min_len)) < 0) then ( min_len := end - start ) else skip ; curr_sum := curr_sum - arr[start+1] ; start := start + 1)) ; return min_len; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) di=[1,n,1,-n] if n % 2==0 : print("NO") else : print("YES") ans=[0 for i in range(2*n)]; it=0 for i in range(1,2*n+1): ans[it]=i it+=di[i % 4] for i in range(2*n): print(ans[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var di : Sequence := Sequence{1}->union(Sequence{n}->union(Sequence{1}->union(Sequence{ -n }))) ; if n mod 2 = 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; var ans : Sequence := Integer.subrange(0, 2 * n-1)->select(i | true)->collect(i | (0)); var it : int := 0 ; for i : Integer.subrange(1, 2 * n + 1-1) do ( ans[it+1] := i ; it := it + di[i mod 4+1]) ; for i : Integer.subrange(0, 2 * n-1) do ( execute (ans[i+1])->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=[0]*(2*n) if not n & 1 : print('NO') exit() rev=0 for i in range(n): a1,a2=2*i+1,2*i+2 if rev : ans[i],ans[i+n]=a2,a1 else : ans[i],ans[i+n]=a1,a2 rev=1-rev print('YES') print(' '.join([str(x)for x in ans])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * n)) ; if not(MathLib.bitwiseAnd(n, 1)) then ( execute ('NO')->display() ; exit() ) else skip ; var rev : int := 0 ; for i : Integer.subrange(0, n-1) do ( var a1 : OclAny := null; var a2 : OclAny := null; Sequence{a1,a2} := Sequence{2 * i + 1,2 * i + 2} ; if rev then ( var ans[i+1] : OclAny := null; var ans[i + n+1] : OclAny := null; Sequence{ans[i+1],ans[i + n+1]} := Sequence{a2,a1} ) else ( var ans[i+1] : OclAny := null; var ans[i + n+1] : OclAny := null; Sequence{ans[i+1],ans[i + n+1]} := Sequence{a1,a2} ) ; rev := 1 - rev) ; execute ('YES')->display() ; execute (StringLib.sumStringsWithSeparator((ans->select(x | true)->collect(x | (("" + ((x)))))), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=lambda : map(int,input().split()); n,d=i(); d-=sum(i()); print([d//5,-1][d<10*~-n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := i->apply(); d := d - (i->apply())->sum(); execute (Sequence{d div 5}->union(Sequence{ -1 })->select((d->compareTo(10 * MathLib.bitwiseNot(-n))) < 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=lambda : map(int,input().split()); n,d=i(); d-=sum(i()); print([d//5,-1][d<10*~-n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := i->apply(); d := d - (i->apply())->sum(); execute (Sequence{d div 5}->union(Sequence{ -1 })->select((d->compareTo(10 * MathLib.bitwiseNot(-n))) < 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=map(int,input().split()) T=list(map(int,input().split())) time=sum(T)+(n-1)*10 if time<=d : print((d-sum(T))//5) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var T : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var time : OclAny := (T)->sum() + (n - 1) * 10 ; if (time->compareTo(d)) <= 0 then ( execute ((d - (T)->sum()) div 5)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=list(map(int,input().split())) l=list(map(int,input().split())) s=sum(l) le=(10*(len(l)-1)) if s+le>y : print(-1) exit() left=y-(s+le) while left % 5!=0 : left-=1 print(int(le/5+left/5)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : OclAny := (l)->sum() ; var le : double := (10 * ((l)->size() - 1)) ; if (s + le->compareTo(y)) > 0 then ( execute (-1)->display() ; exit() ) else skip ; var left : double := y - (s + le) ; while left mod 5 /= 0 do ( left := left - 1) ; execute (("" + ((le / 5 + left / 5)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): n,t=map(int,input().split()) arr=list(map(int,input().split())) time=sum(arr)+(n-1)*10 if time>t : print(-1) return ; count=2*(n-1) left=t-time count+=left//5 print(count) def main(): t=1 for _ in range(t): solution() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; main(); operation solution() : OclAny pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var time : OclAny := (arr)->sum() + (n - 1) * 10 ; if (time->compareTo(t)) > 0 then ( execute (-1)->display() ; return; ) else skip ; var count : double := 2 * (n - 1) ; var left : double := t - time ; count := count + left div 5 ; execute (count)->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): S=input() ans=0 a,b='','' for s in S : a+=s if a!=b : ans+=1 b=a a='' print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{'',''} ; for s : S->characters() do ( a := a + s ; if a /= b then ( ans := ans + 1 ; var b : OclAny := a ; var a : String := '' ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input().strip() ans=[""] prev="" for i,s in enumerate(S): prev+=s if ans[-1]!=prev : ans.append(prev) prev="" else : if i==len(S)-1 : ans.append(prev) result=len(ans)-1 if ans[-1]==ans[-2]: result-=1 print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : OclAny := input()->trim() ; var ans : Sequence := Sequence{ "" } ; var prev : String := "" ; for _tuple : Integer.subrange(1, (S)->size())->collect( _indx | Sequence{_indx-1, (S)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); prev := prev + s ; if ans->last() /= prev then ( execute ((prev) : ans) ; prev := "" ) else ( if i = (S)->size() - 1 then ( execute ((prev) : ans) ) else skip )) ; var result : double := (ans)->size() - 1 ; if ans->last() = ans->front()->last() then ( result := result - 1 ) else skip ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rememberTheNumber(nums,i,operations,ans): if i>=3 : return for j in range(4): for k in range(j+1,4): if(nums[j]!=-1 and nums[k]!=-1): s=nums[j] nums[j]=-1 t=nums[k] if(operations[i]=='+'): nums[k]=s+t elif(operations[i]=='*'): nums[k]=s*t if(i==2 and nums[k]collect( _x | (OclType["int"])->apply(_x) )) ; operations := ((input().split())->collect( _x | (OclType["String"])->apply(_x) )) ; ans := Sequence{ 10000000000000000000000000 } ; rememberTheNumber(nums, 0, operations, ans) ; execute (ans->first())->display(); operation rememberTheNumber(nums : OclAny, i : OclAny, operations : OclAny, ans : OclAny) pre: true post: true activity: if i >= 3 then ( return ) else skip ; for j : Integer.subrange(0, 4-1) do ( for k : Integer.subrange(j + 1, 4-1) do ( if (nums[j+1] /= -1 & nums[k+1] /= -1) then ( var s : OclAny := nums[j+1] ; nums[j+1] := -1 ; var t : OclAny := nums[k+1] ; if (operations[i+1] = '+') then ( nums[k+1] := s + t ) else (if (operations[i+1] = '*') then ( nums[k+1] := s * t ) else skip) ; if (i = 2 & (nums[k+1]->compareTo(ans->first())) < 0) then ( ans->first() := nums[k+1] ) else skip ; rememberTheNumber(nums, i + 1, operations, ans) ; nums[j+1] := s ; nums[k+1] := t ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() n=len(S) A=[S[0]] B=[S[0 : 2]] i=0 j=0 while isize() ; var A : Sequence := Sequence{ S->first() } ; var B : Sequence := Sequence{ S.subrange(0+1, 2) } ; var i : int := 0 ; var j : int := 0 ; while (i->compareTo(n - 1)) < 0 do ( if A[j+1] /= S[i + 1+1] then ( execute ((S[i + 1+1]) : A) ; i := i + 1 ; j := j + 1 ) else ( execute ((S.subrange(i + 1+1, i + 3)) : A) ; i := i + 2 ; j := j + 1 )) ; i := 1 ; j := 0 ; while (i->compareTo(n - 1)) < 0 do ( if B[j+1] /= S[i + 1+1] then ( execute ((S[i + 1+1]) : B) ; i := i + 1 ; j := j + 1 ) else ( execute ((S.subrange(i + 1+1, i + 3)) : B) ; i := i + 2 ; j := j + 1 )) ; if A->last() = A->front()->last() then ( execute (A->last())->isDeleted() ) else skip ; if B->last() = B->front()->last() then ( execute (B->last())->isDeleted() ) else skip ; execute (Set{(A)->size(), (B)->size()}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minIndex(arr,n,pos): num=arr[pos] i=pos-1 while(i>=0): if(arr[i]!=num): break i-=1 return i+1 arr=[2,1,1,1,5,2] n=len(arr) pos=4 print(minIndex(arr,n,pos)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{5}->union(Sequence{ 2 }))))) ; n := (arr)->size() ; pos := 4 ; execute (minIndex(arr, n, pos))->display(); operation minIndex(arr : OclAny, n : OclAny, pos : OclAny) : OclAny pre: true post: true activity: var num : OclAny := arr[pos+1] ; var i : double := pos - 1 ; while (i >= 0) do ( if (arr[i+1] /= num) then ( break ) else skip ; i := i - 1) ; return i + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): S=input() if len(S)==1 : return 1 dp1=[0]*len(S) dp2=[0]*len(S) dp1[0]=1 dp2[1]=1 if S[0]!=S[1]: dp1[1]=2 for i,s in enumerate(S[1 :],1): if s!=S[i-1]: dp1[i]=max(dp1[i],dp1[i-1]+1) dp1[i]=max(dp1[i],dp2[i-1]+1) dp2[i]=dp1[i-2]+1 if S[i-1 : i+1]!=S[i-3 : i-1]: dp2[i]=max(dp2[i],dp2[i-2]+1) return max(dp1[-1],dp2[-1]) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (main())->display(); operation main() : OclAny pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; if (S)->size() = 1 then ( return 1 ) else skip ; var dp1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (S)->size()) ; var dp2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (S)->size()) ; dp1->first() := 1 ; dp2[1+1] := 1 ; if S->first() /= S[1+1] then ( dp1[1+1] := 2 ) else skip ; for _tuple : Integer.subrange(1, (S->tail(), 1)->size())->collect( _indx | Sequence{_indx-1, (S->tail(), 1)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); if s /= S[i - 1+1] then ( dp1[i+1] := Set{dp1[i+1], dp1[i - 1+1] + 1}->max() ) else skip ; dp1[i+1] := Set{dp1[i+1], dp2[i - 1+1] + 1}->max() ; dp2[i+1] := dp1[i - 2+1] + 1 ; if S.subrange(i - 1+1, i + 1) /= S.subrange(i - 3+1, i - 1) then ( dp2[i+1] := Set{dp2[i+1], dp2[i - 2+1] + 1}->max() ) else skip) ; return Set{dp1->last(), dp2->last()}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=str(input()) n=len(s) INF=10**18 dp=[[-INF]*3 for _ in range(n+1)] dp[0][0]=0 for i in range(n): for j in range(3): if dp[i][j]==-INF : continue for k in range(1,3): if j==k : if k==1 : if s[i-1]==s[i]: continue else : if s[i-2]==s[i]and s[i-1]==s[i]: continue if i+k<=n : dp[i+k][k]=max(dp[i+k][k],dp[i][j]+1) print(max(dp[n])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; var n : int := (s)->size() ; var INF : double := (10)->pow(18) ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ -INF }, 3))) ; dp->first()->first() := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, 3-1) do ( if dp[i+1][j+1] = -INF then ( continue ) else skip ; for k : Integer.subrange(1, 3-1) do ( if j = k then ( if k = 1 then ( if s[i - 1+1] = s[i+1] then ( continue ) else skip ) else ( if s[i - 2+1] = s[i+1] & s[i - 1+1] = s[i+1] then ( continue ) else skip ) ) else skip ; if (i + k->compareTo(n)) <= 0 then ( dp[i + k+1][k+1] := Set{dp[i + k+1][k+1], dp[i+1][j+1] + 1}->max() ) else skip))) ; execute ((dp[n+1])->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countWays(n,k): dp=[0]*(n+1) total=k mod=1000000007 dp[1]=k dp[2]=k*k for i in range(3,n+1): dp[i]=((k-1)*(dp[i-1]+dp[i-2]))% mod return dp[n] n=3 k=2 print(countWays(n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3 ; k := 2 ; execute (countWays(n, k))->display(); operation countWays(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var total : OclAny := k ; var mod : int := 1000000007 ; dp[1+1] := k ; dp[2+1] := k * k ; for i : Integer.subrange(3, n + 1-1) do ( dp[i+1] := ((k - 1) * (dp[i - 1+1] + dp[i - 2+1])) mod mod) ; return dp[n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s1,s2=input(),input() s='' counter=0 for c1,c2 in zip(s1,s2): if c1==c2 : s+=c1 else : s+=c2 if counter else c1 counter+=1 if counter else-1 print([s,'impossible'][counter!=0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s1 : OclAny := null; var s2 : OclAny := null; Sequence{s1,s2} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine()} ; var s : String := '' ; var counter : int := 0 ; for _tuple : Integer.subrange(1, s1->size())->collect( _indx | Sequence{s1->at(_indx), s2->at(_indx)} ) do (var _indx : int := 1; var c1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c2 : OclAny := _tuple->at(_indx); if c1 = c2 then ( s := s + c1 ) else ( s := s + if counter then c2 else c1 endif ; counter := counter + if counter then 1 else -1 endif )) ; execute (Sequence{s}->union(Sequence{ 'impossible' })->select(counter /= 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): s=input() t=input() p='' role='s' s_bias_score=0 t_bias_score=0 for i in range(len(s)): if s[i]!=t[i]: if role=='s' : p+=s[i] s_bias_score+=1 role='t' else : p+=t[i] t_bias_score+=1 role='s' else : p+=s[i] if s_bias_score==t_bias_score : print(p) else : print('impossible') if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var p : String := '' ; var role : String := 's' ; var s_bias_score : int := 0 ; var t_bias_score : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] /= t[i+1] then ( if role = 's' then ( p := p + s[i+1] ; s_bias_score := s_bias_score + 1 ; role := 't' ) else ( p := p + t[i+1] ; t_bias_score := t_bias_score + 1 ; role := 's' ) ) else ( p := p + s[i+1] )) ; if s_bias_score = t_bias_score then ( execute (p)->display() ) else ( execute ('impossible')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(input()) t=list(input()) p=[] k=0 n=len(s) for i in range(n): if s[i]==t[i]: p.append(t[i]) elif s[i]!=t[i]and k % 2==0 : p.append(s[i]) k=k+1 else : p.append(t[i]) k=k+1 if k % 2!=0 : print('impossible') else : print(*p,sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var t : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var p : Sequence := Sequence{} ; var k : int := 0 ; var n : int := (s)->size() ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = t[i+1] then ( execute ((t[i+1]) : p) ) else (if s[i+1] /= t[i+1] & k mod 2 = 0 then ( execute ((s[i+1]) : p) ; k := k + 1 ) else ( execute ((t[i+1]) : p) ; k := k + 1 ) ) ) ; if k mod 2 /= 0 then ( execute ('impossible')->display() ) else ( execute ((argument * (test (logical_test (comparison (expr (atom (name p))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A=input() B=input() ans=[] p=0 for i in range(len(A)): if A[i]==B[i]: ans.append(A[i]) else : if p==0 : ans.append(A[i]) p=1 elif p==1 : ans.append(B[i]) p=0 if p!=0 : print("impossible") exit() print("".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : String := (OclFile["System.in"]).readLine() ; var B : String := (OclFile["System.in"]).readLine() ; var ans : Sequence := Sequence{} ; var p : int := 0 ; for i : Integer.subrange(0, (A)->size()-1) do ( if A[i+1] = B[i+1] then ( execute ((A[i+1]) : ans) ) else ( if p = 0 then ( execute ((A[i+1]) : ans) ; p := 1 ) else (if p = 1 then ( execute ((B[i+1]) : ans) ; p := 0 ) else skip) )) ; if p /= 0 then ( execute ("impossible")->display() ; exit() ) else skip ; execute (StringLib.sumStringsWithSeparator((ans), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math s1=input() s2=input() diff=0 for i in range(len(s1)): if s1[i]!=s2[i]: diff+=1 if diff % 2==1 : print("impossible") else : i=j=0 while isize()-1) do ( if s1[i+1] /= s2[i+1] then ( diff := diff + 1 ) else skip) ; if diff mod 2 = 1 then ( execute ("impossible")->display() ) else ( var i : OclAny := 0; var j : int := 0 ; while (i->compareTo((s1)->size())) < 0 do ( execute (s1[i+1])->display() ; if s1[i+1] /= s2[i+1] then ( j := j + 1 ) else skip ; if j = diff div 2 then ( break ) else skip ; i := i + 1) ; execute (s2.subrange(i + 1+1))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_number(arr): global operations,nums if operations[0]=='+' : res1=nums[arr[0]]+nums[arr[1]] else : res1=nums[arr[0]]*nums[arr[1]] for i,op in enumerate(operations[1 :]): if op=='+' : res1=res1+nums[arr[i+2]] else : res1=res1*(nums[arr[i+2]]) if operations[0]=='+' : res2_1=nums[arr[0]]+nums[arr[1]] else : res2_1=nums[arr[0]]*nums[arr[1]] if operations[1]=='+' : res2_2=nums[arr[2]]+nums[arr[3]] else : res2_2=nums[arr[2]]*nums[arr[3]] if operations[2]=='+' : res2=res2_1+res2_2 else : res2=res2_1*res2_2 return min(res1,res2) def get_smallest_num(choices,curr_choice_cnt): global nums,min_num if curr_choice_cnt==4 : res=get_number(choices) if resselect(x | true)->collect(x | (("" + ((x)))->toInteger())) ; operations := input()->trim().split() ; min_num := 1000000000000 ; get_smallest_num(Sequence{}, 0) ; execute (min_num)->display() ) else skip; operation get_number(arr : OclAny) : OclAny pre: true post: true activity: skip; skip ; if operations->first() = '+' then ( var res1 : OclAny := nums[arr->first()+1] + nums[arr[1+1]+1] ) else ( res1 := nums[arr->first()+1] * nums[arr[1+1]+1] ) ; for _tuple : Integer.subrange(1, (operations->tail())->size())->collect( _indx | Sequence{_indx-1, (operations->tail())->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var op : OclAny := _tuple->at(_indx); if op = '+' then ( res1 := res1 + nums[arr[i + 2+1]+1] ) else ( res1 := res1 * (nums[arr[i + 2+1]+1]) )) ; if operations->first() = '+' then ( var res2 skip; skip : OclAny := nums[arr->first()+1] + nums[arr[1+1]+1] ) else ( res2 skip; skip := nums[arr->first()+1] * nums[arr[1+1]+1] ) ; if operations[1+1] = '+' then ( var res2:= nums[arr[2+1]+1] + nums[arr[3+1]+1] : OclAny := nums[arr[2+1]+1] + nums[arr[3+1]+1] ) else ( res2:= nums[arr[2+1]+1] * nums[arr[3+1]+1] := nums[arr[2+1]+1] * nums[arr[3+1]+1] ) ; if operations[2+1] = '+' then ( var res2 : OclAny := res2 skip; skip + res2_2 ) else ( res2 := res2 skip; skip * res2_2 ) ; return Set{res1, res2}->min(); operation get_smallest_num(choices : OclAny, curr_choice_cnt : OclAny) pre: true post: true activity: skip; skip ; if curr_choice_cnt = 4 then ( var res : OclAny := get_number(choices) ; if (res->compareTo(min_num)) < 0 then ( min_num := res ) else skip ; return ) else skip ; for idx : Integer.subrange(0, 4-1) do ( var new_arr : OclAny := choices->copy() ; if (new_arr)->excludes(idx) then ( execute ((idx) : new_arr) ; get_smallest_num(new_arr, curr_choice_cnt + 1) ) else skip) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getValueOfF(n): if(n==1): return 0 if(n==2): return 1 cnt=0 while(n % 2==0): cnt+=1 n/=2 return 2*cnt n=20 print(getValueOfF(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 20 ; execute (getValueOfF(n))->display(); operation getValueOfF(n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return 0 ) else skip ; if (n = 2) then ( return 1 ) else skip ; var cnt : int := 0 ; while (n mod 2 = 0) do ( cnt := cnt + 1 ; n := n / 2) ; return 2 * cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input exec(int(I())*"I();print(max(0,0,*map(len,I().split('A')[1:])));") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name I)) (trailer (arguments ( ))))))))) )))) * (expr (atom "I();print(max(0,0,*map(len,I().split('A')[1:])));"))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sortArray(a,n): ans=[] for i in range(n): if(a[i]>=0): ans.append(a[i]) ans=sorted(ans) j=0 for i in range(n): if(a[i]>=0): a[i]=ans[j] j+=1 for i in range(n): print(a[i],end=" ") arr=[2,-6,-3,8,4,1] n=len(arr) sortArray(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var arr : Sequence := Sequence{2}->union(Sequence{-6}->union(Sequence{-3}->union(Sequence{8}->union(Sequence{4}->union(Sequence{ 1 }))))) ; n := (arr)->size() ; sortArray(arr, n); operation sortArray(a : OclAny, n : OclAny) pre: true post: true activity: var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] >= 0) then ( execute ((a[i+1]) : ans) ) else skip) ; ans := ans->sort() ; var j : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] >= 0) then ( a[i+1] := ans[j+1] ; j := j + 1 ) else skip) ; for i : Integer.subrange(0, n-1) do ( execute (a[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): k=int(input()) s=input().lstrip('P').split('A') print(len(max(s))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := input().lstrip('P').split('A') ; execute (((s)->max())->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) s=input().split('A') try : m=max(s[1 :]) print(len(m)) except : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := input().split('A') ; try ( var m : OclAny := (s->tail())->max() ; execute ((m)->size())->display()) catch (_e : OclException) do ( execute (0)->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : t-=1 no_of_students=int(input()) students=input() for index,value in enumerate(students): if value=='A' : break count=0 max=0 for i in range(index+1,no_of_students): if students[i]=='A' : if count>max : max=count count=0 count=0 else : count+=1 if count>max : max=count print(max) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( t := t - 1 ; var no_of_students : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var students : String := (OclFile["System.in"]).readLine() ; for _tuple : Integer.subrange(1, (students)->size())->collect( _indx | Sequence{_indx-1, (students)->at(_indx)} ) do (var _indx : int := 1; var index : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); if value = 'A' then ( break ) else skip) ; var count : int := 0 ; var max : int := 0 ; for i : Integer.subrange(index + 1, no_of_students-1) do ( if students[i+1] = 'A' then ( if (count->compareTo(max)) > 0 then ( max := count ; count := 0 ) else skip ; count := 0 ) else ( count := count + 1 )) ; if (count->compareTo(max)) > 0 then ( max := count ) else skip ; execute (max)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): input() s=input().lstrip('P').split('A') print(len(max(s))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( input() ; var s : OclAny := input().lstrip('P').split('A') ; execute (((s)->max())->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools while True : N=int(input()) if not N : break D=[[]for _ in range(30)] for i in range(N): for x in map(int,input().split()[1 :]): D[x-1].append(i) C=[1<toInteger() ; if not(N) then ( break ) else skip ; var D : Sequence := Integer.subrange(0, 30-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, N-1) do ( for x : (input().split()->tail())->collect( _x | (OclType["int"])->apply(_x) ) do ((expr (atom (name D)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))) ; var C : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (1 * (2->pow(i)))) ; (compound_stmt for (exprlist (expr (atom (name d)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 30))))))))) )))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name i))) , (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name itertools)) (trailer . (name permutations) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name D)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name d)))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name C)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name C)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) | (expr (atom (name C)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name any)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (comparison (expr (atom (name x)))) == (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name N)))))))) ))) - (expr (atom (number (integer 1))))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name C)))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name d))) + (expr (atom (number (integer 1)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,meetables): mets=[set()for _ in range(n)] for d,meetable in enumerate(meetables[1 :]): today=meetable.copy() for i in meetable : today.update(mets[i]) mets[i]=today if len(today)==n : return d+1 return-1 while True : n=int(input()) if not n : break meetables=[set()for _ in range(31)] for i in range(n): for d in map(int,input().split()[1 :]): meetables[d].add(i) print(solve(n,meetables)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(n) then ( break ) else skip ; meetables := Integer.subrange(0, 31-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; for i : Integer.subrange(0, n-1) do ( for d : (input().split()->tail())->collect( _x | (OclType["int"])->apply(_x) ) do ((expr (atom (name meetables)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name d)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))) ; execute (solve(n, meetables))->display()); operation solve(n : OclAny, meetables : OclAny) : OclAny pre: true post: true activity: var mets : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; for _tuple : Integer.subrange(1, (meetables->tail())->size())->collect( _indx | Sequence{_indx-1, (meetables->tail())->at(_indx)} ) do (var _indx : int := 1; var d : OclAny := _tuple->at(_indx); _indx := _indx + 1; var meetable : OclAny := _tuple->at(_indx); var today : OclAny := meetable->copy() ; for i : meetable do ( execute ((mets[i+1]) <: today) ; mets[i+1] := today) ; if (today)->size() = n then ( return d + 1 ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if n==0 : break dic={} ok=[[False for i in range(30)]for i in range(n)] for i in range(n): dic[i]=[i] for m in list(map(int,input().split()))[1 :]: ok[i][m-1]=True f=False for i in range(30): tmp=[] for j in range(n): if ok[j][i]: tmp+=list(dic[j]) tmp=set(tmp) for j in range(n): if ok[j][i]: dic[j]=list(tmp) if len(dic[j])==n : print(i+1) f=True break if f : break if not f : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var dic : OclAny := Set{} ; var ok : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, 30-1)->select(i | true)->collect(i | (false)))) ; for i : Integer.subrange(0, n-1) do ( dic[i+1] := Sequence{ i } ; for m : OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->tail() do ( ok[i+1][m - 1+1] := true)) ; var f : boolean := false ; for i : Integer.subrange(0, 30-1) do ( var tmp : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( if ok[j+1][i+1] then ( tmp := tmp + (dic[j+1]) ) else skip) ; tmp := Set{}->union((tmp)) ; for j : Integer.subrange(0, n-1) do ( if ok[j+1][i+1] then ( dic[j+1] := (tmp) ; if (dic[j+1])->size() = n then ( execute (i + 1)->display() ; f := true ; break ) else skip ) else skip) ; if f then ( break ) else skip) ; if not(f) then ( execute (-1)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_number(arr): global operations,nums if operations[0]=='+' : res1=nums[arr[0]]+nums[arr[1]] else : res1=nums[arr[0]]*nums[arr[1]] for i,op in enumerate(operations[1 :]): if op=='+' : res1=res1+nums[arr[i+2]] else : res1=res1*(nums[arr[i+2]]) if operations[0]=='+' : res2_1=nums[arr[0]]+nums[arr[1]] else : res2_1=nums[arr[0]]*nums[arr[1]] if operations[1]=='+' : res2_2=nums[arr[2]]+nums[arr[3]] else : res2_2=nums[arr[2]]*nums[arr[3]] if operations[2]=='+' : res2=res2_1+res2_2 else : res2=res2_1*res2_2 return min(res1,res2) def get_smallest_num(choices,curr_choice_cnt): global nums,min_num if curr_choice_cnt==4 : res=get_number(choices) if resselect(x | true)->collect(x | (("" + ((x)))->toInteger())) ; operations := input()->trim().split() ; min_num := 1000000000000 ; get_smallest_num(Sequence{}, 0) ; execute (min_num)->display() ) else skip; operation get_number(arr : OclAny) : OclAny pre: true post: true activity: skip; skip ; if operations->first() = '+' then ( var res1 : OclAny := nums[arr->first()+1] + nums[arr[1+1]+1] ) else ( res1 := nums[arr->first()+1] * nums[arr[1+1]+1] ) ; for _tuple : Integer.subrange(1, (operations->tail())->size())->collect( _indx | Sequence{_indx-1, (operations->tail())->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var op : OclAny := _tuple->at(_indx); if op = '+' then ( res1 := res1 + nums[arr[i + 2+1]+1] ) else ( res1 := res1 * (nums[arr[i + 2+1]+1]) )) ; if operations->first() = '+' then ( var res2 skip; skip : OclAny := nums[arr->first()+1] + nums[arr[1+1]+1] ) else ( res2 skip; skip := nums[arr->first()+1] * nums[arr[1+1]+1] ) ; if operations[1+1] = '+' then ( var res2:= nums[arr[2+1]+1] + nums[arr[3+1]+1] : OclAny := nums[arr[2+1]+1] + nums[arr[3+1]+1] ) else ( res2:= nums[arr[2+1]+1] * nums[arr[3+1]+1] := nums[arr[2+1]+1] * nums[arr[3+1]+1] ) ; if operations[2+1] = '+' then ( var res2 : OclAny := res2 skip; skip + res2_2 ) else ( res2 := res2 skip; skip * res2_2 ) ; return Set{res1, res2}->min(); operation get_smallest_num(choices : OclAny, curr_choice_cnt : OclAny) pre: true post: true activity: skip; skip ; if curr_choice_cnt = 4 then ( var res : OclAny := get_number(choices) ; if (res->compareTo(min_num)) < 0 then ( min_num := res ) else skip ; return ) else skip ; for idx : Integer.subrange(0, 4-1) do ( var new_arr : OclAny := choices->copy() ; if (new_arr)->excludes(idx) then ( execute ((idx) : new_arr) ; get_smallest_num(new_arr, curr_choice_cnt + 1) ) else skip) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): from sys import stdin f_i=stdin ans=[] while True : n=int(f_i.readline()) if n==0 : break last_day=1 schedule=[set()for i in range(31)] for i in range(n): line=map(int,f_i.readline().split()) f=next(line) for day in line : schedule[day].add(i) if day>last_day : last_day=day groups=[set()for i in range(n)] for day in range(1,last_day+1): member1=schedule[day] member2=member1.copy() for person in member1 : member2 |=groups[person] if len(member2)==n : ans.append(day) break for person in member1 : groups[person]|=member2 else : ans.append(-1) print('\n'.join(map(str,ans))) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: skip ; var f_i : OclAny := stdin ; var ans : Sequence := Sequence{} ; while true do ( var n : int := ("" + ((f_i.readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var last_day : int := 1 ; var schedule : Sequence := Integer.subrange(0, 31-1)->select(i | true)->collect(i | (Set{}->union(()))) ; for i : Integer.subrange(0, n-1) do ( var line : Sequence := (f_i.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var f : OclAny := (line).next() ; for day : line do ((expr (atom (name schedule)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name day)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ; if (day->compareTo(last_day)) > 0 then ( last_day := day ) else skip)) ; var groups : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Set{}->union(()))) ; (compound_stmt for (exprlist (expr (atom (name day)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name last_day))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name member1)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name schedule)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name day)))))))) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name member2)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name member1)) (trailer . (name copy) (arguments ( ))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name person)))) in (testlist (test (logical_test (comparison (expr (atom (name member1))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name member2)))))))) (assign_part |= (testlist (test (logical_test (comparison (expr (atom (name groups)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name person)))))))) ])))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name member2)))))))) ))))) == (comparison (expr (atom (name n))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name day)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (compound_stmt for (exprlist (expr (atom (name person)))) in (testlist (test (logical_test (comparison (expr (atom (name member1))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name groups)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name person)))))))) ])))))))) (assign_part |= (testlist (test (logical_test (comparison (expr (atom (name member2))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))))))) ; execute (StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) while N : days=[[]for _ in range(31)] roles=[2**i for i in range(N)] for i in range(N): for j in list(map(int,input().split()))[1 :]: days[j].append(i) for i,day in enumerate(days): role=0 for d in day : role |=roles[d] for d in day : roles[d]=role if role==2**N-1 : print(i) break else : print(-1) N=int(input()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while N do ( var days : Sequence := Integer.subrange(0, 31-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var roles : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | ((2)->pow(i))) ; for i : Integer.subrange(0, N-1) do ( for j : OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->tail() do ((expr (atom (name days)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))) ; (compound_stmt for (exprlist (expr (atom (name i))) , (expr (atom (name day)))) in (testlist (test (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name days)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name role)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name d)))) in (testlist (test (logical_test (comparison (expr (atom (name day))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name role)))))))) (assign_part |= (testlist (test (logical_test (comparison (expr (atom (name roles)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name d)))))))) ])))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name d)))) in (testlist (test (logical_test (comparison (expr (atom (name day))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name roles)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name d)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name role))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name role)))) == (comparison (expr (expr (expr (atom (number (integer 2)))) ** (expr (atom (name N)))) - (expr (atom (number (integer 1))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ))))))))))))))) ; N := ("" + (((OclFile["System.in"]).readLine())))->toInteger()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) arr=list(map(int,input().split())) count=sum(x % 2 for x in arr) if count1 : if arr[i]% 2 : print(i+1,end=" ") k-=1 i+=1 print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name x))) % (expr (atom (number (integer 2)))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name arr))))))))->sum() ; if (count->compareTo(k)) < 0 or count mod 2 /= k mod 2 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; var i : int := 0 ; while k > 1 do ( if arr[i+1] mod 2 then ( execute (i + 1)->display() ; k := k - 1 ) else skip ; i := i + 1) ; execute (n)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthDigit(a,n,b): for i in range(1,n): a=a//b return a % b a=100 n=3 b=4 print(nthDigit(a,n,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 100 ; n := 3 ; b := 4 ; execute (nthDigit(a, n, b))->display(); operation nthDigit(a : OclAny, n : OclAny, b : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(1, n-1) do ( a := a div b) ; return a mod b; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) for _ in range(q): n,k=map(int,input().split()) a=list(map(int,input().strip().split())) l=[] for i in range(n): if a[i]% 2!=0 : l.append(i) m=len(l) if m % 2==k % 2 and k<=m : print("YES") if k>1 : for i in range(1,k-1): print(l[i],end=' ') print(l[k-1],end=' ') print(n) else : print(n) else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if a[i+1] mod 2 /= 0 then ( execute ((i) : l) ) else skip) ; var m : int := (l)->size() ; if m mod 2 = k mod 2 & (k->compareTo(m)) <= 0 then ( execute ("YES")->display() ; if k > 1 then ( for i : Integer.subrange(1, k - 1-1) do ( execute (l[i+1])->display()) ; execute (l[k - 1+1])->display() ; execute (n)->display() ) else ( execute (n)->display() ) ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n,k=map(int,input().split()) w=list(map(int,input().split())) d=set() ans='YES' if k==1 : if sum(w)% 2 : print("YES") print(n) else : print("NO") else : for i in range(n): if w[i]% 2 : d.add(i+1) k-=1 if k==1 : if sum(w[i+1 :])% 2 : d.add(n) else : ans="NO" break if ans=="NO" or k!=1 : print("NO") else : print(ans) print(' '.join(map(str,d))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : Set := Set{}->union(()) ; var ans : String := 'YES' ; if k = 1 then ( if (w)->sum() mod 2 then ( execute ("YES")->display() ; execute (n)->display() ) else ( execute ("NO")->display() ) ) else ( for i : Integer.subrange(0, n-1) do ( if w[i+1] mod 2 then ( execute ((i + 1) : d) ; k := k - 1 ) else skip ; if k = 1 then ( if (w.subrange(i + 1+1))->sum() mod 2 then ( execute ((n) : d) ) else ( ans := "NO" ) ; break ) else skip) ; if ans = "NO" or k /= 1 then ( execute ("NO")->display() ) else ( execute (ans)->display() ; execute (StringLib.sumStringsWithSeparator(((d)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout import sys def get_ints(): return map(int,sys.stdin.readline().strip().split()) t=int(input()) while t : t-=1 n,k=get_ints() a=list(map(int,input().split())) cntodd=0 for i in range(0,len(a)): if a[i]% 2==1 : cntodd+=1 if k>cntodd : print('NO') else : if(cntodd-k)% 2==1 : print('NO') else : print('YES') inds=[] ans=[] for i in range(0,len(a)): if a[i]% 2==1 : inds.append(int(i)) for i in range(cntodd-k,len(inds)-1): print(inds[i]+1,end=' ') print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( t := t - 1 ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := get_ints() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cntodd : int := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( if a[i+1] mod 2 = 1 then ( cntodd := cntodd + 1 ) else skip) ; if (k->compareTo(cntodd)) > 0 then ( execute ('NO')->display() ) else ( if (cntodd - k) mod 2 = 1 then ( execute ('NO')->display() ) else ( execute ('YES')->display() ; var inds : Sequence := Sequence{} ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, (a)->size()-1) do ( if a[i+1] mod 2 = 1 then ( execute ((("" + ((i)))->toInteger()) : inds) ) else skip) ; for i : Integer.subrange(cntodd - k, (inds)->size() - 1-1) do ( execute (inds[i+1] + 1)->display()) ; execute (n)->display() ) )); operation get_ints() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) for loop in range(q): n,k=map(int,input().split()) a=list(map(int,input().split())) res=[] for i,x in enumerate(a): if x % 2==1 : res.append(i+1) if len(res)toInteger() ; for loop : Integer.subrange(0, q-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); if x mod 2 = 1 then ( execute ((i + 1) : res) ) else skip) ; if ((res)->size()->compareTo(k)) < 0 or ((res)->size() - k) mod 2 /= 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name res)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (expr (atom (name k))) - (expr (atom (number (integer 1)))))))))) ]))))))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def EvenOddProduct(arr,n): even=1 odd=1 for i in range(0,n): if(i % 2==0): even*=arr[i] else : odd*=arr[i] print("Even Index Product : ",even) print("Odd Index Product : ",odd) arr=1,2,3,4,5,6 n=len(arr) EvenOddProduct(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := 1,2,3,4,5,6 ; n := (arr)->size() ; EvenOddProduct(arr, n); operation EvenOddProduct(arr : OclAny, n : OclAny) pre: true post: true activity: var even : int := 1 ; var odd : int := 1 ; for i : Integer.subrange(0, n-1) do ( if (i mod 2 = 0) then ( even := even * arr[i+1] ) else ( odd := odd * arr[i+1] )) ; execute ("Even Index Product : ")->display() ; execute ("Odd Index Product : ")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printArr(arr,n): for i in range(0,n): print(arr[i],end="") print("") def generateUtil(x,arr,curr_sum,curr_idx): if(curr_sum==x): printArr(arr,curr_idx) return num=1 while(num<=x-curr_sum and(curr_idx==0 or num<=arr[curr_idx-1])): arr[curr_idx]=num generateUtil(x,arr,curr_sum+num,curr_idx+1) num+=1 def generate(x): arr=[0]*x generateUtil(x,arr,0,0) x=5 generate(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; x := 5 ; generate(x); operation printArr(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()) ; execute ("")->display(); operation generateUtil(x : OclAny, arr : OclAny, curr_sum : OclAny, curr_idx : OclAny) pre: true post: true activity: if (curr_sum = x) then ( printArr(arr, curr_idx) ; return ) else skip ; var num : int := 1 ; while ((num->compareTo(x - curr_sum)) <= 0 & (curr_idx = 0 or (num->compareTo(arr[curr_idx - 1+1])) <= 0)) do ( arr[curr_idx+1] := num ; generateUtil(x, arr, curr_sum + num, curr_idx + 1) ; num := num + 1); operation generate(x : OclAny) pre: true post: true activity: arr := MatrixLib.elementwiseMult(Sequence{ 0 }, x) ; generateUtil(x, arr, 0, 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt MAX=1005 def SieveOfEratosthenes(primes): prime=[True for i in range(MAX)] for p in range(2,int(sqrt(MAX))+1,1): if(prime[p]==True): for i in range(p*2,MAX,p): prime[i]=False for p in range(2,MAX,1): if(prime[p]): primes.append(p) return primes def minimumSquareFreeDivisors(N): prime=[] primes=[] primes=SieveOfEratosthenes(prime) max_count=0 i=0 while(len(primes)and primes[i]*primes[i]<=N): if(N % primes[i]==0): tmp=0 while(N % primes[i]==0): tmp+=1 N/=primes[i] max_count=max(max_count,tmp) i+=1 if(max_count==0): max_count=1 return max_count if __name__=='__main__' : N=24 print("Minimum Number of Square Free Divisors is",minimumSquareFreeDivisors(N)) N=6 print("Minimum Number of Square Free Divisors is",minimumSquareFreeDivisors(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MAX : int := 1005 ; skip ; skip ; if __name__ = '__main__' then ( N := 24 ; execute ("Minimum Number of Square Free Divisors is")->display() ; N := 6 ; execute ("Minimum Number of Square Free Divisors is")->display() ) else skip; operation SieveOfEratosthenes(primes : OclAny) : OclAny pre: true post: true activity: var prime : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (true)) ; for p : Integer.subrange(2, ("" + ((sqrt(MAX))))->toInteger() + 1-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (prime[p+1] = true) then ( for i : Integer.subrange(p * 2, MAX-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip) ; for p : Integer.subrange(2, MAX-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (prime[p+1]) then ( execute ((p) : primes) ) else skip) ; return primes; operation minimumSquareFreeDivisors(N : OclAny) : OclAny pre: true post: true activity: prime := Sequence{} ; primes := Sequence{} ; primes := SieveOfEratosthenes(prime) ; var max_count : int := 0 ; var i : int := 0 ; while ((primes)->size() & (primes[i+1] * primes[i+1]->compareTo(N)) <= 0) do ( if (N mod primes[i+1] = 0) then ( var tmp : int := 0 ; while (N mod primes[i+1] = 0) do ( tmp := tmp + 1 ; N := N / primes[i+1]) ; max_count := Set{max_count, tmp}->max() ) else skip ; i := i + 1) ; if (max_count = 0) then ( max_count := 1 ) else skip ; return max_count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def countPair(a,n): maxm=a[0] for i in range(len(a)): if(a[i]>maxm): maxm=a[i] prime=[0 for i in range(maxm+1)] prime[0]=prime[1]=1 ; for i in range(2,int(sqrt(maxm))+1,1): if(prime[i]==0): for j in range(2*i,maxm+1,i): prime[j]=1 count=0 for i in range(n): for j in range(i+1,n,1): if(prime[a[i]]==0 or prime[a[j]]==0): count+=1 return count if __name__=='__main__' : arr=[2,3,5,4,7] n=5 print(countPair(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var arr : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{4}->union(Sequence{ 7 })))) ; n := 5 ; execute (countPair(arr, n))->display() ) else skip; operation countPair(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var maxm : OclAny := a->first() ; for i : Integer.subrange(0, (a)->size()-1) do ( if ((a[i+1]->compareTo(maxm)) > 0) then ( maxm := a[i+1] ) else skip) ; var prime : Sequence := Integer.subrange(0, maxm + 1-1)->select(i | true)->collect(i | (0)) ; prime->first() := 1; var prime[1+1] : int := 1; ; for i : Integer.subrange(2, ("" + ((sqrt(maxm))))->toInteger() + 1-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (prime[i+1] = 0) then ( for j : Integer.subrange(2 * i, maxm + 1-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ( prime[j+1] := 1) ) else skip) ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1)->select( $x | ($x - i + 1) mod 1 = 0 ) do ( if (prime[a[i+1]+1] = 0 or prime[a[j+1]+1] = 0) then ( count := count + 1 ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSetBits(n): count=0 while(n): n=n &(n-1) count=count+1 return count def findSum(n): sum=0 for i in range(1,n+1): if(countSetBits(i)==2): sum=sum+i return sum n=10 print(findSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 10 ; execute (findSum(n))->display(); operation countSetBits(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while (n) do ( n := MathLib.bitwiseAnd(n, (n - 1)) ; count := count + 1) ; return count; operation findSum(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( if (countSetBits(i) = 2) then ( sum := sum + i ) else skip) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math ; def Area(a,b): if(a<0 and b<0): return-1 ; h=math.sqrt(((pow(a,2)+pow(b,2))/(pow(a,2)*pow(b,2)))); A=0.70477*pow(h,2); return A ; a=5 ; b=4 ; print(round(Area(a,b),7)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; ; skip ; a := 5; ; b := 4; ; execute (MathLib.roundN(Area(a, b), 7))->display();; operation Area(a : OclAny, b : OclAny) pre: true post: true activity: if (a < 0 & b < 0) then ( return -1; ) else skip ; var h : double := ((((a)->pow(2) + (b)->pow(2)) / ((a)->pow(2) * (b)->pow(2))))->sqrt(); ; var A : double := 0.70477 * (h)->pow(2); ; return A;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution : def smallerNumbersThanCurrent(self,nums : List[int])->List[int]: count_list=[0]*101 for v in nums : count_list[v]+=1 for i in range(1,101): count_list[i]+=count_list[i-1] res=[] for v in nums : if v==0 : res.append(0) else : res.append(count_list[v-1]) return res ------------------------------------------------------------ OCL File: --------- class Solution { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation smallerNumbersThanCurrent(nums : List[OclType["int"]+1]) : OclAny pre: true post: true activity: var count_list : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 101) ; for v : nums do ( count_list[v+1] := count_list[v+1] + 1) ; for i : Integer.subrange(1, 101-1) do ( count_list[i+1] := count_list[i+1] + count_list[i - 1+1]) ; var res : Sequence := Sequence{} ; for v : nums do ( if v = 0 then ( execute ((0) : res) ) else ( execute ((count_list[v - 1+1]) : res) )) ; return res; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkArray(arr,n): zero=0 ; one=0 ; minusone=0 ; other=0 for i in range(0,n): if(arr[i]==0): zero+=1 elif(arr[i]==1): one+=1 elif(arr[i]==-1): minusone+=1 else : other+=1 if(other>1): return false elif(other!=0 and minusone!=0): return false elif(minusone>=1 and one==0): return false return True arr=[0,1,1,10] n=len(arr) if(checkArray(arr,n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 10 }))) ; n := (arr)->size() ; if (checkArray(arr, n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation checkArray(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var zero : int := 0; var one : int := 0; ; var minusone : int := 0; var other : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] = 0) then ( zero := zero + 1 ) else (if (arr[i+1] = 1) then ( one := one + 1 ) else (if (arr[i+1] = -1) then ( minusone := minusone + 1 ) else ( other := other + 1 ) ) ) ) ; if (other > 1) then ( return false ) else (if (other /= 0 & minusone /= 0) then ( return false ) else (if (minusone >= 1 & one = 0) then ( return false ) else skip ) ) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findsolution(n,x,y): if((y-n+1)*(y-n+1)+n-11): print(1); n-=1 ; n=5 ; x=15 ; y=15 ; findsolution(n,x,y); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5; ; x := 15; ; y := 15; ; findsolution(n, x, y);; operation findsolution(n : OclAny, x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (((y - n + 1) * (y - n + 1) + n - 1->compareTo(x)) < 0 or (y->compareTo(n)) < 0) then ( execute ("No solution")->display(); ; return; ) else skip ; execute (y - n + 1)->display(); ; while (n > 1) do ( execute (1)->display(); ; n := n - 1;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) if(n==0): print(1) elif(n==1): print(4) elif(n==2): print(8) elif(n==3): print(16) else : k=4+8*(int(math.sqrt(n*n/2))) p=int(math.sqrt(n*n/2)) if(p*p+(p+1)*(p+1)>n*n): k-=4 print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n = 0) then ( execute (1)->display() ) else (if (n = 1) then ( execute (4)->display() ) else (if (n = 2) then ( execute (8)->display() ) else (if (n = 3) then ( execute (16)->display() ) else ( var k : int := 4 + 8 * (("" + (((n * n / 2)->sqrt())))->toInteger()) ; var p : int := ("" + (((n * n / 2)->sqrt())))->toInteger() ; if ((p * p + (p + 1) * (p + 1)->compareTo(n * n)) > 0) then ( k := k - 4 ) else skip ; execute (k)->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,floor def calc(n): if n==0 : return 1 x=floor(sqrt(n**2/2)) y=floor(sqrt(n**2-x**2)) if x==y : return x*8 else : return x*8+4 n=int(input()) print(calc(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (calc(n))->display(); operation calc(n : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( return 1 ) else skip ; var x : OclAny := floor(sqrt((n)->pow(2) / 2)) ; var y : OclAny := floor(sqrt((n)->pow(2) - (x)->pow(2))) ; if x = y then ( return x * 8 ) else ( return x * 8 + 4 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a=int(input()) n=0 if a>0 : b=int(math.sqrt((a**2)/2)) if b**2+(b+1)**2<=a**2 : n=b*8+4 else : n=b*8 print(n) else : print('1') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := 0 ; if a > 0 then ( var b : int := ("" + (((((a)->pow(2)) / 2)->sqrt())))->toInteger() ; if ((b)->pow(2) + ((b + 1))->pow(2)->compareTo((a)->pow(2))) <= 0 then ( n := b * 8 + 4 ) else ( n := b * 8 ) ; execute (n)->display() ) else ( execute ('1')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(max(1,4*int(int(input())*2**0.5))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (Set{1, 4 * ("" + ((("" + (((OclFile["System.in"]).readLine())))->toInteger() * (2)->pow(0.5))))->toInteger()}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from time import sleep x=int(input()) a=int(input()) b=int(input()) ans=(x-a)% b sleep(a*0.001) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := (x - a) mod b ; sleep(a * 0.001) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(max(1,4*int(int(input())*2**0.5))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (Set{1, 4 * ("" + ((("" + (((OclFile["System.in"]).readLine())))->toInteger() * (2)->pow(0.5))))->toInteger()}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- map_=((1,4),(-1,2),(5,3),(4,1),(1,-1),(3,4)) while 1 : x=input() if x=='#' : break pt=0 for v in map(int,list(x)): pt=map_[pt][v] if pt==-1 : break print("Yes" if pt==3 else "No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var map_ : OclAny := Sequence{Sequence{1, 4}, Sequence{-1, 2}, Sequence{5, 3}, Sequence{4, 1}, Sequence{1, -1}, Sequence{3, 4}} ; while 1 do ( var x : String := (OclFile["System.in"]).readLine() ; if x = '#' then ( break ) else skip ; var pt : int := 0 ; for v : ((x)->characters())->collect( _x | (OclType["int"])->apply(_x) ) do ( pt := map_[pt+1][v+1] ; if pt = -1 then ( break ) else skip) ; execute (if pt = 3 then "Yes" else "No" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,datetime PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") routes={'A' :{'0' : 'X','1' : 'Y'},'X' :{'1' : 'Z'},'Y' :{'0' : 'X'},'Z' :{'0' : 'W','1' : 'B'},'W' :{'0' : 'B','1' : 'Y'},'B' :{'0' : 'Y','1' : 'X'}} def solve(inp): cur='A' k=0 while k Map{ '0' |-> 'X' }->union(Map{ '1' |-> 'Y' }) }->union(Map{ 'X' |-> Map{ '1' |-> 'Z' } }->union(Map{ 'Y' |-> Map{ '0' |-> 'X' } }->union(Map{ 'Z' |-> Map{ '0' |-> 'W' }->union(Map{ '1' |-> 'B' }) }->union(Map{ 'W' |-> Map{ '0' |-> 'B' }->union(Map{ '1' |-> 'Y' }) }->union(Map{ 'B' |-> Map{ '0' |-> 'Y' }->union(Map{ '1' |-> 'X' }) }))))) ; skip ; while true do ( inp := input()->trim() ; if inp = "#" then ( break ) else skip ; execute (solve(inp))->display()); operation solve(inp : OclAny) : OclAny pre: true post: true activity: var cur : String := 'A' ; var k : int := 0 ; while (k->compareTo((inp)->size())) < 0 do ( var route : OclAny := inp[k+1] ; if (routes->at(cur))->includes(route) then ( cur := routes->at(cur)[route+1] ) else ( return "No" ) ; k := k + 1) ; return if cur = 'B' then "Yes" else "No" endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : S=input() if S=="#" : break status="A" for i in range(len(S)): if status=="A" : if S[i]=="0" : status="X" else : status="Y" elif status=="B" : if S[i]=="0" : status="Y" else : status="X" elif status=="X" : if S[i]=="0" : status="NA" else : status="Z" elif status=="Y" : if S[i]=="0" : status="X" else : status="NA" elif status=="Z" : if S[i]=="0" : status="W" else : status="B" elif status=="W" : if S[i]=="0" : status="B" else : status="Y" else : status="NA" if status=="B" : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var S : String := (OclFile["System.in"]).readLine() ; if S = "#" then ( break ) else skip ; var status : String := "A" ; for i : Integer.subrange(0, (S)->size()-1) do ( if status = "A" then ( if S[i+1] = "0" then ( status := "X" ) else ( status := "Y" ) ) else (if status = "B" then ( if S[i+1] = "0" then ( status := "Y" ) else ( status := "X" ) ) else (if status = "X" then ( if S[i+1] = "0" then ( status := "NA" ) else ( status := "Z" ) ) else (if status = "Y" then ( if S[i+1] = "0" then ( status := "X" ) else ( status := "NA" ) ) else (if status = "Z" then ( if S[i+1] = "0" then ( status := "W" ) else ( status := "B" ) ) else (if status = "W" then ( if S[i+1] = "0" then ( status := "B" ) else ( status := "Y" ) ) else ( status := "NA" ) ) ) ) ) ) ) ; if status = "B" then ( execute ("Yes")->display() ) else ( execute ("No")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(s): path={'A' :{'0' : 'X','1' : 'Y'},'B' :{'0' : 'Y','1' : 'X'},'W' :{'0' : 'B','1' : 'Y'},'X' :{'0' : None,'1' : 'Z'},'Y' :{'0' : 'X','1' : None},'Z' :{'0' : 'W','1' : 'B'}} pos='A' for ch in s : pos=path[pos][ch] if pos is None : return 'No' return 'Yes' if pos=='B' else 'No' def main(args): while True : s=input() if s=='#' : break ans=solve(s) print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(s : OclAny) : OclAny pre: true post: true activity: var path : Map := Map{ 'A' |-> Map{ '0' |-> 'X' }->union(Map{ '1' |-> 'Y' }) }->union(Map{ 'B' |-> Map{ '0' |-> 'Y' }->union(Map{ '1' |-> 'X' }) }->union(Map{ 'W' |-> Map{ '0' |-> 'B' }->union(Map{ '1' |-> 'Y' }) }->union(Map{ 'X' |-> Map{ '0' |-> null }->union(Map{ '1' |-> 'Z' }) }->union(Map{ 'Y' |-> Map{ '0' |-> 'X' }->union(Map{ '1' |-> null }) }->union(Map{ 'Z' |-> Map{ '0' |-> 'W' }->union(Map{ '1' |-> 'B' }) }))))) ; var pos : String := 'A' ; for ch : s do ( pos := path->at(pos)[ch+1] ; if pos <>= null then ( return 'No' ) else skip) ; return if pos = 'B' then 'Yes' else 'No' endif; operation main(args : OclAny) pre: true post: true activity: while true do ( s := (OclFile["System.in"]).readLine() ; if s = '#' then ( break ) else skip ; var ans : OclAny := solve(s) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sameOccurrence(arr,n,x,y): countX=[0 for i in range(n)] countY=[0 for i in range(n)] m=dict() for i in range(n): if(arr[i]==x): if(i!=0): countX[i]=countX[i-1]+1 else : countX[i]=1 else : if(i!=0): countX[i]=countX[i-1] else : countX[i]=0 if(arr[i]==y): if(i!=0): countY[i]=countY[i-1]+1 else : countY[i]=1 else : if(i!=0): countY[i]=countY[i-1] else : countY[i]=0 m[countX[i]-countY[i]]=m.get(countX[i]-countY[i],0)+1 result=m[0] for j in m : result+=(m[j]*(m[j]-1))//2 return result arr=[1,2,2,3,4,1] n=len(arr) x,y=2,3 print(sameOccurrence(arr,n,x,y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 1 }))))) ; n := (arr)->size() ; Sequence{x,y} := Sequence{2,3} ; execute (sameOccurrence(arr, n, x, y))->display(); operation sameOccurrence(arr : OclAny, n : OclAny, x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var countX : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var countY : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var m : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] = x) then ( if (i /= 0) then ( countX[i+1] := countX[i - 1+1] + 1 ) else ( countX[i+1] := 1 ) ) else ( if (i /= 0) then ( countX[i+1] := countX[i - 1+1] ) else ( countX[i+1] := 0 ) ) ; if (arr[i+1] = y) then ( if (i /= 0) then ( countY[i+1] := countY[i - 1+1] + 1 ) else ( countY[i+1] := 1 ) ) else ( if (i /= 0) then ( countY[i+1] := countY[i - 1+1] ) else ( countY[i+1] := 0 ) ) ; m[countX[i+1] - countY[i+1]+1] := m.get(countX[i+1] - countY[i+1], 0) + 1) ; var result : OclAny := m->first() ; for j : m->keys() do ( result := result + (m[j+1] * (m[j+1] - 1)) div 2) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- edges=[[]for _ in range(7)] edges[0]=[2,3] edges[1]=[3,2] edges[2]=[6,4] edges[3]=[2,6] edges[4]=[5,1] edges[5]=[1,3] edges[6]=[6,6] while True : s=input() if s=="#" : break node=0 for c in s : node=edges[node][int(c)] if node==1 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var edges : Sequence := Integer.subrange(0, 7-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; edges->first() := Sequence{2}->union(Sequence{ 3 }) ; edges[1+1] := Sequence{3}->union(Sequence{ 2 }) ; edges[2+1] := Sequence{6}->union(Sequence{ 4 }) ; edges[3+1] := Sequence{2}->union(Sequence{ 6 }) ; edges[4+1] := Sequence{5}->union(Sequence{ 1 }) ; edges[5+1] := Sequence{1}->union(Sequence{ 3 }) ; edges[6+1] := Sequence{6}->union(Sequence{ 6 }) ; while true do ( var s : String := (OclFile["System.in"]).readLine() ; if s = "#" then ( break ) else skip ; var node : int := 0 ; for c : s->characters() do ( node := edges[node+1][("" + ((c)))->toInteger()+1]) ; if node = 1 then ( execute ("Yes")->display() ) else ( execute ("No")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=10**20 n=int(input()) top=[] bottom=[] for _ in range(n): a,b=map(int,input().split()) top.append(a) bottom.append(b) dp=[[INF]*(n+1)for _ in range(n+1)] for j in range(n): dp[0][j]=0 for i in range(1,n): for j in range(n-i): dp[i][j]=min(dp[k][j]+dp[i-k-1][j+k+1]+top[j]*bottom[j+k]*top[j+k+1]*bottom[j+i]for k in range(i)) print(dp[n-1][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INF : double := (10)->pow(20) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var top : Sequence := Sequence{} ; var bottom : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a) : top) ; execute ((b) : bottom)) ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ INF }, (n + 1)))) ; for j : Integer.subrange(0, n-1) do ( dp->first()[j+1] := 0) ; for i : Integer.subrange(1, n-1) do ( for j : Integer.subrange(0, n - i-1) do ( dp[i+1][j+1] := ((argument (test (logical_test (comparison (expr (expr (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))) + (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name i))) - (expr (atom (name k)))) - (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name j))) + (expr (atom (name k)))) + (expr (atom (number (integer 1)))))))))) ])))) + (expr (expr (expr (expr (atom (name top)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))) * (expr (atom (name bottom)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (name k))))))))) ])))) * (expr (atom (name top)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name j))) + (expr (atom (name k)))) + (expr (atom (number (integer 1)))))))))) ])))) * (expr (atom (name bottom)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (name i))))))))) ])))))))) (comp_for for (exprlist (expr (atom (name k)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))->min())) ; execute (dp[n - 1+1]->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) cards=[] for i in range(n): a,b=map(int,input().split()) cards.append((a,b)) memo=[[-1 for i in range(n+1)]for j in range(n+1)] def getans(l,r,cards): if(memo[l][r]==-1): if(l+1==r): memo[l][r]=0 else : ans=1<<32 for m in range(l+1,r): cost=cards[l][0]*cards[m-1][1]*cards[m][0]*cards[r-1][1]+getans(l,m,cards)+getans(m,r,cards) ans=min(ans,cost) memo[l][r]=ans return memo[l][r] print(getans(0,n,cards)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cards : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a, b}) : cards)) ; var memo : Sequence := Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (-1)))) ; skip ; execute (getans(0, n, cards))->display(); operation getans(l : OclAny, r : OclAny, cards : OclAny) : OclAny pre: true post: true activity: if (memo[l+1][r+1] = -1) then ( if (l + 1 = r) then ( memo[l+1][r+1] := 0 ) else ( var ans : int := 1 * (2->pow(32)) ; for m : Integer.subrange(l + 1, r-1) do ( var cost : double := cards[l+1]->first() * cards[m - 1+1][1+1] * cards[m+1]->first() * cards[r - 1+1][1+1] + getans(l, m, cards) + getans(m, r, cards) ; ans := Set{ans, cost}->min()) ; memo[l+1][r+1] := ans ) ) else skip ; return memo[l+1][r+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=0x7fffffff n=int(input()) c=[[INF for j in range(n)]for i in range(n)] a=[[0 for j in range(2)]for i in range(n)] for i in range(n): c[i][i]=0 for i in range(n): a[i][0],a[i][1]=list(map(int,input().split())) for l in range(1,n): for i in range(n-l): j=i+l for k in range(i,j): c[i][j]=min(c[i][j],c[i][k]+a[i][0]*a[k][1]*a[k+1][0]*a[j][1]+c[k+1][j]) print(c[0][n-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INF : int := 0x7fffffff ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, n-1)->select(j | true)->collect(j | (INF)))) ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, 2-1)->select(j | true)->collect(j | (0)))) ; for i : Integer.subrange(0, n-1) do ( c[i+1][i+1] := 0) ; for i : Integer.subrange(0, n-1) do ( var a[i+1]->first() : OclAny := null; var a[i+1][1+1] : OclAny := null; Sequence{a[i+1]->first(),a[i+1][1+1]} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; for l : Integer.subrange(1, n-1) do ( for i : Integer.subrange(0, n - l-1) do ( var j : OclAny := i + l ; for k : Integer.subrange(i, j-1) do ( c[i+1][j+1] := Set{c[i+1][j+1], c[i+1][k+1] + a[i+1]->first() * a[k+1][1+1] * a[k + 1+1]->first() * a[j+1][1+1] + c[k + 1+1][j+1]}->min()))) ; execute (c->first()[n - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=[int(input())for _ in range(3)] b=x[0]-x[1] a=int(b/x[2]) print(b-(x[2]*a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : Sequence := Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var b : double := x->first() - x[1+1] ; var a : int := ("" + ((b / x[2+1])))->toInteger() ; execute (b - (x[2+1] * a))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): s=input() station_list=[] for si in s[: : 3]: station_list.append(si) st_l=list(dict.fromkeys(station_list)) ans=[0]*51 ans[25]=station_list[0] for j in st_l[1 :]: place=s.index(j) now=s[place-3 : place+1] if now[1 : 3]=="->" : ans[ans.index(now[0])+1]=now[3] elif now[1 : 3]=="<-" : ans[ans.index(now[0])-1]=now[3] ans_l=list(dict.fromkeys(ans)) ans_l.remove(0) print(''.join(map(str,ans_l))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var station_list : Sequence := Sequence{} ; for si : s(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 3))))))))) do ( execute ((si) : station_list)) ; var st_l : Sequence := ((trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name station_list)))))))) ))))->keys()->asSequence() ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 51) ; ans[25+1] := station_list->first() ; for j : st_l->tail() do ( var place : int := s->indexOf(j) - 1 ; var now : OclAny := s.subrange(place - 3+1, place + 1) ; if now.subrange(1+1, 3) = "->" then ( ans[ans->indexOf(now->first()) - 1 + 1+1] := now[3+1] ) else (if now.subrange(1+1, 3) = "<-" then ( ans[ans->indexOf(now->first()) - 1 - 1+1] := now[3+1] ) else skip)) ; var ans_l : Sequence := ((trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))->keys()->asSequence() ; execute ((0) /: ans_l) ; execute (StringLib.sumStringsWithSeparator(((ans_l)->collect( _x | (OclType["String"])->apply(_x) )), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def proc(i): l=len(i) o=[i[0]] io=1 ii=1 while iitoInteger() ; for _anon : Integer.subrange(0, n-1) do ( l := (OclFile["System.in"]).readLine() ; var r : OclAny := proc(l) ; execute (r)->display()); operation proc(i : OclAny) : OclAny pre: true post: true activity: var l : int := (i)->size() ; var o : Sequence := Sequence{ i->first() } ; var io : int := 1 ; var ii : int := 1 ; while (ii->compareTo(l)) < 0 do ( if i.subrange(ii+1, ii + 2) = "<-" then ( io := io - 1 ) else ( io := io + 1 ) ; if (io = 0) then ( o := o.insertAt(io+1, i[ii + 2+1]) ; io := io + 1 ) else (if (io = (o)->size() + 1) then ( o := o.insertAt(io+1, i[ii + 2+1]) ) else ( if i[ii + 2+1] /= o[io - 1+1] then ( error untimeError.newuntimeError("error") ) else skip ) ) ; ii := ii + 3) ; var s : String := "" ; for c : o do ( s := s + c) ; return s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy from test.support import _MemoryWatchdog BIG_NUM=2000000000 HUGE_NUM=99999999999999999 MOD=1000000007 EPS=0.000000001 sys.setrecursionlimit(100000) SIZE=3001 MID=1500 N=int(input()) table=[None]*SIZE for _ in range(N): for i in range(SIZE): table[i]='@' input_str=input() table[MID]=input_str[0] loc=0 for i in range(1,len(input_str)-2,3): if input_str[i]=='-' : loc+=1 table[MID+loc]=input_str[i+2] else : loc-=1 table[MID+loc]=input_str[i+2] for i in range(SIZE): if table[i]=='@' : continue print("%s" %(table[i]),end="") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var HUGE_NUM : int := 99999999999999999 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; sys.setrecursionlimit(100000) ; var SIZE : int := 3001 ; var MID : int := 1500 ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var table : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, SIZE) ; for _anon : Integer.subrange(0, N-1) do ( for i : Integer.subrange(0, SIZE-1) do ( table[i+1] := '@') ; var input_str : String := (OclFile["System.in"]).readLine() ; table[MID+1] := input_str->first() ; var loc : int := 0 ; for i : Integer.subrange(1, (input_str)->size() - 2-1)->select( $x | ($x - 1) mod 3 = 0 ) do ( if input_str[i+1] = '-' then ( loc := loc + 1 ; table[MID + loc+1] := input_str[i + 2+1] ) else ( loc := loc - 1 ; table[MID + loc+1] := input_str[i + 2+1] )) ; for i : Integer.subrange(0, SIZE-1) do ( if table[i+1] = '@' then ( continue ) else skip ; execute (StringLib.format("%s",(table[i+1])))->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inputCount=int(input()) for _ in range(inputCount): inputContent=input() trainOrder=[item for item in inputContent if str.isalpha(item)] directOrder=[item for item in inputContent if item=="<" or item==">"] trainList=trainOrder[0] listIndex=1 trainLength=1 for train,direct in zip(trainOrder[1 :],directOrder): if listIndex==1 and direct=="<" : trainList=train+trainList trainLength+=1 elif listIndex==trainLength and direct==">" : trainList+=train listIndex+=1 trainLength+=1 elif direct=="<" : listIndex-=1 else : listIndex+=1 print(trainList) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inputCount : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, inputCount-1) do ( var inputContent : String := (OclFile["System.in"]).readLine() ; var trainOrder : Sequence := inputContent->characters()->select(item | ("" + (->matches("[a-zA-Z]*"))))->collect(item | (item)) ; var directOrder : Sequence := inputContent->characters()->select(item | item = "<" or item = ">")->collect(item | (item)) ; var trainList : OclAny := trainOrder->first() ; var listIndex : int := 1 ; var trainLength : int := 1 ; for _tuple : Integer.subrange(1, trainOrder->tail()->size())->collect( _indx | Sequence{trainOrder->tail()->at(_indx), directOrder->at(_indx)} ) do (var _indx : int := 1; var train : OclAny := _tuple->at(_indx); _indx := _indx + 1; var direct : OclAny := _tuple->at(_indx); if listIndex = 1 & direct = "<" then ( trainList := train + trainList ; trainLength := trainLength + 1 ) else (if listIndex = trainLength & direct = ">" then ( trainList := trainList + train ; listIndex := listIndex + 1 ; trainLength := trainLength + 1 ) else (if direct = "<" then ( listIndex := listIndex - 1 ) else ( listIndex := listIndex + 1 ) ) ) ) ; execute (trainList)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): s=input().replace("->",">").replace("<-","<") t,train,s=s[0],[s[0]],s[1 :] for i in range(0,len(s),2): if s[i]=='>' and not s[i+1]in train : idx=train.index(t)+1 train.insert(idx,s[i+1]) elif not s[i+1]in train : idx=train.index(t) train.insert(idx,s[i+1]) t=s[i+1] print(''.join(train)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : OclAny := input().replace("->", ">").replace("<-", "<") ; var t : OclAny := null; var train : OclAny := null; Sequence{t,train,s} := Sequence{s->first(),Sequence{ s->first() },s->tail()} ; for i : Integer.subrange(0, (s)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( if s[i+1] = '>' & not((train)->includes(s[i + 1+1])) then ( var idx : int := train->indexOf(t) - 1 + 1 ; train := train.insertAt(idx+1, s[i + 1+1]) ) else (if not((train)->includes(s[i + 1+1])) then ( idx := train->indexOf(t) - 1 ; train := train.insertAt(idx+1, s[i + 1+1]) ) else skip) ; var t : OclAny := s[i + 1+1]) ; execute (StringLib.sumStringsWithSeparator((train), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) num=0 for i in range(a,b+1,1): if c % i==0 : num+=1 print(num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var num : int := 0 ; for i : Integer.subrange(a, b + 1-1)->select( $x | ($x - a) mod 1 = 0 ) do ( if c mod i = 0 then ( num := num + 1 ) else skip) ; execute (num)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def maxPrimeFactors(n): num=n maxPrime=-1 ; while(n % 2==0): maxPrime=2 n=n/2 p=int(sqrt(n)+1) for i in range(3,p,2): while(n % i==0): maxPrime=i n=n/i if(n>2): maxPrime=n sum=maxPrime+num return sum if __name__=='__main__' : n=19 print(maxPrimeFactors(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( n := 19 ; execute (maxPrimeFactors(n))->display() ) else skip; operation maxPrimeFactors(n : OclAny) : OclAny pre: true post: true activity: var num : OclAny := n ; var maxPrime : int := -1; ; while (n mod 2 = 0) do ( maxPrime := 2 ; n := n / 2) ; var p : int := ("" + ((sqrt(n) + 1)))->toInteger() ; for i : Integer.subrange(3, p-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( while (n mod i = 0) do ( maxPrime := i ; n := n / i)) ; if (n > 2) then ( maxPrime := n ) else skip ; var sum : int := maxPrime + num ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- count=0 lst=[] a,b,c=(int(x)for x in input().split()) for i in range(1,c+1): if c % i==0 : lst.append(i) for l in lst : if l in range(a,b+1): count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var count : int := 0 ; var lst : Sequence := Sequence{} ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; for i : Integer.subrange(1, c + 1-1) do ( if c mod i = 0 then ( execute ((i) : lst) ) else skip) ; for l : lst do ( if (Integer.subrange(a, b + 1-1))->includes(l) then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- nums=list(map(int,input().split(" "))) counter=0 for i in range(nums[0],nums[1]+1): if nums[2]% i==0 : counter+=1 print(counter) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var nums : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var counter : int := 0 ; for i : Integer.subrange(nums->first(), nums[1+1] + 1-1) do ( if nums[2+1] mod i = 0 then ( counter := counter + 1 ) else skip) ; execute (counter)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) d=0 if a==b : while a!=b+1 : if c % a==0 : d+=1 a+=1 else : a+=1 elif b==c : while a!=b+2 : if c % a==0 : d+=1 a+=1 else : a+=1 else : while a!=b : if c % a==0 : d+=1 a+=1 else : a+=1 print(d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : int := 0 ; if a = b then ( while a /= b + 1 do ( if c mod a = 0 then ( d := d + 1 ; a := a + 1 ) else ( a := a + 1 )) ) else (if b = c then ( while a /= b + 2 do ( if c mod a = 0 then ( d := d + 1 ; a := a + 1 ) else ( a := a + 1 )) ) else ( while a /= b do ( if c mod a = 0 then ( d := d + 1 ; a := a + 1 ) else ( a := a + 1 )) ) ) ; execute (d)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- X,A,B=[int(input())for _ in range(3)] print((X-A)% B) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var X : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{X,A,B} := Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; execute ((X - A) mod B)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) ans=0 num=a while True : if c % num==0 : ans+=1 num+=1 if num>b : break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; var num : OclAny := a ; while true do ( if c mod num = 0 then ( ans := ans + 1 ) else skip ; num := num + 1 ; if (num->compareTo(b)) > 0 then ( break ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import Counter n=int(sys.stdin.readline().strip()) a=list(map(int,sys.stdin.readline().split())) c=Counter(a) print(n-max(c.values())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + ((sys.stdin.readLine()->trim())))->toInteger() ; var a : Sequence := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : OclAny := Counter(a) ; execute (n - (c.values())->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(i)for i in input().split()] a.sort() c=0 i=0 for j in range(n): if a[i]toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; a := a->sort() ; var c : int := 0 ; var i : int := 0 ; for j : Integer.subrange(0, n-1) do ( if (a[i+1]->compareTo(a[j+1])) < 0 then ( c := c + 1 ; i := i + 1 ) else skip ; j := j + 1) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from collections import Counter n=int(input()) w=Counter(map(int,input().split())) w=sorted(w.most_common()) c=0 x=w[0][1] for i in range(1,len(w)): y=min(x,w[i][1]) c+=y x+=w[i][1]-y print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : OclAny := Counter((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; w := w.most_common()->sort() ; var c : int := 0 ; var x : OclAny := w->first()[1+1] ; for i : Integer.subrange(1, (w)->size()-1) do ( var y : OclAny := Set{x, w[i+1][1+1]}->min() ; c := c + y ; x := x + w[i+1][1+1] - y) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(lambda x : int(x),input().split(" "))) arr_map={} for i in range(n): arr_map[arr[i]]=arr_map.get(arr[i],0)+1 max_count=0 for key in arr_map : max_count=max(max_count,arr_map[key]) print(n-max_count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split(" "))->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) )) ; var arr_map : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( arr_map[arr[i+1]+1] := arr_map.get(arr[i+1], 0) + 1) ; var max_count : int := 0 ; for key : arr_map do ( max_count := Set{max_count, arr_map[key+1]}->max()) ; execute (n - max_count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) sorted_l=sorted(l) j=0 for i in range(0,n): if sorted_l[i]>sorted_l[j]: j+=1 print(j) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sorted_l : Sequence := l->sort() ; var j : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (sorted_l[i+1]->compareTo(sorted_l[j+1])) > 0 then ( j := j + 1 ) else skip) ; execute (j)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq V,E,r=map(int,input().split()) G=[[]for i in range(V)] for i in range(E): s,t,d=map(int,input().split()) G[s].append([d,t]) INF=1000000007 mn=[INF]*V todo=[[0,r]] fin=[0]*V heapq.heapify(todo) while(todo!=[]): v=heapq.heappop(todo) if not fin[v[1]]: mn[v[1]]=v[0] fin[v[1]]=1 for i in G[v[1]]: if mn[v[1]]+i[0]collect( _x | (OclType["int"])->apply(_x) ) ; var G : Sequence := Integer.subrange(0, V-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, E-1) do ( var s : OclAny := null; var t : OclAny := null; var d : OclAny := null; Sequence{s,t,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name d)))))) , (test (logical_test (comparison (expr (atom (name t))))))) ]))))))) ))))) ; var INF : int := 1000000007 ; var mn : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, V) ; var todo : Sequence := Sequence{ Sequence{0}->union(Sequence{ r }) } ; var fin : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, V) ; heapq.heapify(todo) ; while (todo /= Sequence{}) do ( var v : OclAny := heapq.heappop(todo) ; if not(fin[v[1+1]+1]) then ( mn[v[1+1]+1] := v->first() ; fin[v[1+1]+1] := 1 ; for i : G[v[1+1]+1] do ( if (mn[v[1+1]+1] + i->first()->compareTo(mn[i[1+1]+1])) < 0 then ( heapq.heappush(todo, Sequence{mn[v[1+1]+1] + i->first()}->union(Sequence{ i[1+1] })) ) else skip) ) else skip) ; for i : Integer.subrange(0, V-1) do ( execute (if mn[i+1] /= INF then mn[i+1] else 'INF' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=int(input()),list(sorted(list(map(int,input().split())))) kk=1 ans=0 for i in range(len(x)): ans+=(x[i]-x[len(x)-i-1])*kk kk*=2 kk %=1000000007 ans %=1000000007 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort())} ; var kk : int := 1 ; var ans : int := 0 ; for i : Integer.subrange(0, (x)->size()-1) do ( ans := ans + (x[i+1] - x[(x)->size() - i - 1+1]) * kk ; kk := kk * 2 ; kk := kk mod 1000000007 ; ans := ans mod 1000000007) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : t=str(input()) if t=="-" : break m=int(input()) a=0 while atoInteger() ; var a : int := 0 ; while (a->compareTo(m)) < 0 do ( var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; t := t.subrange(b+1) + t.subrange(1,b) ; a := a + 1) ; execute (t)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict from heapq import heappush,heappop,heapify from sys import stdin def sp(G,R,V): d={} INF=float('inf') for i in range(V): d[i]=INF q=[(0,R)] d[R]=0 heapify(q) while q : (cost,v)=heappop(q) for(next,c)in G[v].items(): if d[next]>d[v]+c : d[next]=d[v]+c heappush(q,(d[next],next)) return d V,E,R=[int(x)for x in stdin.readline().split()] G=defaultdict(dict) for case in range(E): s,t,w=[int(x)for x in stdin.readline().split()] G[s][t]=w d=sp(G,R,V) for k in range(V): if d[k]==float('inf'): print("INF") else : print(d[k]) ------------------------------------------------------------ OCL File: --------- class FromPython { suite`nestedAttributeDefinitions operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var Sequence{cost, v} : OclAny := heappop(q); operation sp(G : OclAny, R : OclAny, V : OclAny) pre: true post: true activity: var d : OclAny := Set{} ; var INF : double := ("" + (('inf')))->toReal() ; for i : Integer.subrange(0, V-1) do ( d[i+1] := INF) ; var q : Sequence := Sequence{ Sequence{0, R} } ; d[R+1] := 0 ; heapify(q) ; while q do (suite); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print((int(input())-int(input()))% int(input())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger() - ("" + (((OclFile["System.in"]).readLine())))->toInteger()) mod ("" + (((OclFile["System.in"]).readLine())))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heapify,heappop,heappush def main(): vertex,edge,root=map(int,input().split()) max_val=10**10 graph=[[]for _ in range(vertex)] for _ in range(edge): s,t,d=map(int,input().split()) graph[s].append((t,d)) dist=[max_val for _ in range(vertex)] dist[root]=0 q=[] heapify(q) heappush(q,(0,root)) while q : now_d,now_v=heappop(q) for next_v,length in graph[now_v]: now_dist=dist[now_v]+length if dist[next_v]>now_dist : dist[next_v]=now_dist heappush(q,(dist[next_v],next_v)) for d in dist : print("INF" if d==max_val else d) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var vertex : OclAny := null; var edge : OclAny := null; var root : OclAny := null; Sequence{vertex,edge,root} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var max_val : double := (10)->pow(10) ; var graph : Sequence := Integer.subrange(0, vertex-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, edge-1) do ( var s : OclAny := null; var t : OclAny := null; var d : OclAny := null; Sequence{s,t,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name t)))))) , (test (logical_test (comparison (expr (atom (name d))))))) )))))))) ))))) ; var dist : Sequence := Integer.subrange(0, vertex-1)->select(_anon | true)->collect(_anon | (max_val)) ; dist[root+1] := 0 ; var q : Sequence := Sequence{} ; heapify(q) ; heappush(q, Sequence{0, root}) ; while q do ( var now_d : OclAny := null; var now_v : OclAny := null; Sequence{now_d,now_v} := heappop(q) ; for _tuple : graph[now_v+1] do (var _indx : int := 1; var next_v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var length : OclAny := _tuple->at(_indx); var now_dist : OclAny := dist[now_v+1] + length ; if (dist[next_v+1]->compareTo(now_dist)) > 0 then ( dist[next_v+1] := now_dist ; heappush(q, Sequence{dist[next_v+1], next_v}) ) else skip)) ; for d : dist do ( execute (if d = max_val then "INF" else d endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import defaultdict from queue import Queue def main(): input=sys.stdin.buffer.readline n,m,r=map(int,input().split()) graph=defaultdict(list) for _ in range(m): s,t,d=map(int,input().split()) graph[s].append((t,d)) que=Queue() que.put(r) dist=[-1]*n dist[r]=0 while not que.empty(): e=que.get() dist_now=dist[e] for nxt,cost in graph[e]: dist_nxt=dist[nxt] if dist_nxt==-1 or dist_nxt>dist_now+cost : dist[nxt]=dist_now+cost que.put(nxt) for d in dist : print(d if d!=-1 else "INF") if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var input : OclAny := sys.stdin.buffer.readline ; var n : OclAny := null; var m : OclAny := null; var r : OclAny := null; Sequence{n,m,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var graph : OclAny := defaultdict(OclType["Sequence"]) ; for _anon : Integer.subrange(0, m-1) do ( var s : OclAny := null; var t : OclAny := null; var d : OclAny := null; Sequence{s,t,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name t)))))) , (test (logical_test (comparison (expr (atom (name d))))))) )))))))) ))))) ; var que : OclAny := Queue() ; que.put(r) ; var dist : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; dist[r+1] := 0 ; while not(que.empty()) do ( var e : OclAny := que.get() ; var dist_now : OclAny := dist[e+1] ; for _tuple : graph[e+1] do (var _indx : int := 1; var nxt : OclAny := _tuple->at(_indx); _indx := _indx + 1; var cost : OclAny := _tuple->at(_indx); var dist_nxt : OclAny := dist[nxt+1] ; if dist_nxt = -1 or (dist_nxt->compareTo(dist_now + cost)) > 0 then ( dist[nxt+1] := dist_now + cost ; que.put(nxt) ) else skip)) ; for d : dist do ( execute (if d /= -1 then d else "INF" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import array import collections import heapq G_INF=2**31 class Dijkstra(object): def __init__(self,number_of_vertices,adjacency_list,costs,start): self.max_v=number_of_vertices self.adj=adjacency_list self.costs=costs self.start=start self.dist=None def initialize_dist(self): self.dist=collections.defaultdict(lambda : G_INF) self.dist[self.start]=0 def single_source_shortest_path(self): self.initialize_dist() pq=[(self.dist[v],v)for v in range(self.max_v)] heapq.heapify(pq) while pq : (_,v)=heapq.heappop(pq) for u in self.adj[v]: new_length=self.dist[v]+self.costs[(v,u)] if new_lengthexists( _x | result = _x ); attribute max_v : OclAny := number_of_vertices; attribute adj : OclAny := adjacency_list; attribute costs : OclAny := costs; attribute start : OclAny := start; attribute dist : OclAny := null; operation initialise(number_of_vertices : OclAny,adjacency_list : OclAny,costs : OclAny,start : OclAny) : pre: true post: true activity: self.max_v := number_of_vertices ; self.adj := adjacency_list ; self.costs := costs ; self.start := start ; self.dist := null; return self; operation initialize_dist() pre: true post: true activity: self.dist := .defaultdict(lambda $$ : OclAny in (G_INF)) ; self.dist[self.start+1] := 0; operation single_source_shortest_path() pre: true post: true activity: self.initialize_dist() ; var pq : Sequence := Integer.subrange(0, self.max_v-1)->select(v | true)->collect(v | (Sequence{self.dist[v+1], v})) ; heapq.heapify(pq) ; while pq do (suite); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var G_INF : double := (2)->pow(31) ; skip ; var Sequence{_anon, v} : OclAny := heapq.heappop(pq); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPossible(arr,p,n,m): sum=0 ; for i in range(p): sum+=arr[i]; if(sum==(n*m)): return True ; return False ; if __name__=='__main__' : n=3 ; m=4 ; arr=[6,3,2,1]; p=len(arr); if(isPossible(arr,p,n,m)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 3; ; m := 4; ; arr := Sequence{6}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 1 }))); ; p := (arr)->size(); ; if (isPossible(arr, p, n, m)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ) else skip; operation isPossible(arr : OclAny, p : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: var sum : int := 0; ; for i : Integer.subrange(0, p-1) do ( sum := sum + arr[i+1];) ; if (sum = (n * m)) then ( return true; ) else skip ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def largest(arr,n): return(max(arr)) arr=[10,324,45,90,9808] n=len(arr) Ans=largest(arr,n) print("Largest in given array is",Ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{10}->union(Sequence{324}->union(Sequence{45}->union(Sequence{90}->union(Sequence{ 9808 })))) ; n := (arr)->size() ; var Ans : OclAny := largest(arr, n) ; execute ("Largest in given array is")->display(); operation largest(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: return ((arr)->max()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- M=3 N=3 matrix=[[12,23,34],[45,56,67],[78,89,91]] def rotateMatrix(k): global M,N,matrix temp=[0]*M k=k % M for i in range(0,N): for t in range(0,M-k): temp[t]=matrix[i][t] for j in range(M-k,M): matrix[i][j-M+k]=matrix[i][j] for j in range(k,M): matrix[i][j]=temp[j-k] def displayMatrix(): global M,N,matrix for i in range(0,N): for j in range(0,M): print("{}".format(matrix[i][j]),end="") print() k=2 rotateMatrix(k) displayMatrix() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute M : OclAny; attribute N : OclAny; attribute matrix : OclAny; attribute M : OclAny; attribute N : OclAny; attribute matrix : OclAny; operation initialise() pre: true post: true activity: var M : int := 3 ; var N : int := 3 ; var matrix : Sequence := Sequence{Sequence{12}->union(Sequence{23}->union(Sequence{ 34 }))}->union(Sequence{Sequence{45}->union(Sequence{56}->union(Sequence{ 67 }))}->union(Sequence{ Sequence{78}->union(Sequence{89}->union(Sequence{ 91 })) })) ; skip ; skip ; k := 2 ; rotateMatrix(k) ; displayMatrix(); operation rotateMatrix(k : OclAny) pre: true post: true activity: skip; skip; skip ; var temp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, M) ; k := k mod M ; for i : Integer.subrange(0, N-1) do ( for t : Integer.subrange(0, M - k-1) do ( temp[t+1] := matrix[i+1][t+1]) ; for j : Integer.subrange(M - k, M-1) do ( matrix[i+1][j - M + k+1] := matrix[i+1][j+1]) ; for j : Integer.subrange(k, M-1) do ( matrix[i+1][j+1] := temp[j - k+1])); operation displayMatrix() pre: true post: true activity: skip; skip; skip ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, M-1) do ( execute (StringLib.interpolateStrings("{}", Sequence{matrix[i+1][j+1]}))->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- masks=[] for _ in range(int(input())): k,*b=map(int,input().split()) mask=0 for i in range(k): mask+=1<0)) def Set(i): global x global masks x |=masks[i] def clear(i): global x global masks x=(x | masks[i])^ masks[i] def flip(i): global x global masks x ^=masks[i] def all(i): global x global masks print(+(x & masks[i]==masks[i])) def any(i): global x global masks print(+(x & masks[i]>0)) def none(i): global x global masks print(+(x & masks[i]==0)) def count(i): global x global masks print(bin(x & masks[i]).count('1')) def val(i): global x global masks print(x & masks[i]) f=[test,Set,clear,flip,all,any,none,count,val].__getitem__ for _ in range(int(input())): op,*i=map(int,input().split()) f(op)(*i) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute x : OclAny; attribute x : OclAny; attribute masks : OclAny; attribute x : OclAny; attribute masks : OclAny; attribute x : OclAny; attribute masks : OclAny; attribute x : OclAny; attribute masks : OclAny; attribute x : OclAny; attribute masks : OclAny; attribute x : OclAny; attribute masks : OclAny; attribute x : OclAny; attribute masks : OclAny; attribute x : OclAny; attribute masks : OclAny; operation initialise() pre: true post: true activity: var masks : Sequence := Sequence{} ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var k : OclAny := null; var b : OclAny := null; Sequence{k,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mask : int := 0 ; for i : Integer.subrange(0, k-1) do ( mask := mask + 1 * (2->pow(b[i+1]))) ; execute ((mask) : masks)) ; var x : int := 0 ; var MASK : double := (1 * (2->pow(64))) - 1 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var f : OclAny := Sequence{test}->union(Sequence{Set}->union(Sequence{clear}->union(Sequence{flip}->union(Sequence{all}->union(Sequence{any}->union(Sequence{none}->union(Sequence{count}->union(Sequence{ val })))))))).__getitem__ ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var op : OclAny := null; var i : OclAny := null; Sequence{op,i} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name f)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name op)))))))) ))) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom (name i)))))))) ))))); operation test(i : OclAny) pre: true post: true activity: skip ; execute (((MathLib.bitwiseAnd(x, (1 * (2->pow(i))))) > 0))->display(); operation Set(i : OclAny) pre: true post: true activity: skip ; skip ; x := x or masks[i+1]; operation clear(i : OclAny) pre: true post: true activity: skip ; skip ; x := MathLib.bitwiseXor((MathLib.bitwiseOr(x, masks[i+1])), masks[i+1]); operation flip(i : OclAny) pre: true post: true activity: skip ; skip ; x := x xor masks[i+1]; operation all(i : OclAny) pre: true post: true activity: skip ; skip ; execute ((MathLib.bitwiseAnd(x, masks[i+1]) = masks[i+1]))->display(); operation any(i : OclAny) pre: true post: true activity: skip ; skip ; execute ((MathLib.bitwiseAnd(x, masks[i+1]) > 0))->display(); operation none(i : OclAny) pre: true post: true activity: skip ; skip ; execute ((MathLib.bitwiseAnd(x, masks[i+1]) = 0))->display(); operation count(i : OclAny) pre: true post: true activity: skip ; skip ; execute (bin(MathLib.bitwiseAnd(x, masks[i+1]))->count('1'))->display(); operation val(i : OclAny) pre: true post: true activity: skip ; skip ; execute (MathLib.bitwiseAnd(x, masks[i+1]))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=0 MASK=2**64-1 def x_test(i): return int((x &(1<0) def x_set(m): global x x |=M[m] def x_clear(m): global x x=(x | M[m])^ M[m] def x_flip(m): global x x ^=M[m] def x_all(m): return int(x & M[m]==M[m]) def x_any(m): return int(x & M[m]>0) def x_none(m): return int(x & M[m]==0) def x_count(m): return bin(x & M[m]).count("1") def x_val(m): return x & M[m] command=[x_test,x_set,x_clear,x_flip,x_all,x_any,x_none,x_count,x_val] M=[] N=int(input()) for i in range(N): k,*B=map(int,input().split()) M.append(sum(1<pow(64) - 1 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var command : Sequence := Sequence{x_test}->union(Sequence{x_set}->union(Sequence{x_clear}->union(Sequence{x_flip}->union(Sequence{x_all}->union(Sequence{x_any}->union(Sequence{x_none}->union(Sequence{x_count}->union(Sequence{ x_val })))))))) ; var M : Sequence := Sequence{} ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, N-1) do ( var k : OclAny := null; var B : OclAny := null; Sequence{k,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((((argument (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name b))))))) (comp_for for (exprlist (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name B))))))))->sum()) : M)) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, q-1) do ( var t : OclAny := null; var cmd : OclAny := null; Sequence{t,cmd} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : OclAny := command[t+1](cmd) ; if not(ans <>= null) then ( execute (ans)->display() ) else skip); operation x_test(i : OclAny) : OclAny pre: true post: true activity: return ("" + (((MathLib.bitwiseAnd(x, (1 * (2->pow(i))))) > 0)))->toInteger(); operation x_set(m : OclAny) pre: true post: true activity: skip ; x := x or M[m+1]; operation x_clear(m : OclAny) pre: true post: true activity: skip ; x := MathLib.bitwiseXor((MathLib.bitwiseOr(x, M[m+1])), M[m+1]); operation x_flip(m : OclAny) pre: true post: true activity: skip ; x := x xor M[m+1]; operation x_all(m : OclAny) : OclAny pre: true post: true activity: return ("" + ((MathLib.bitwiseAnd(x, M[m+1]) = M[m+1])))->toInteger(); operation x_any(m : OclAny) : OclAny pre: true post: true activity: return ("" + ((MathLib.bitwiseAnd(x, M[m+1]) > 0)))->toInteger(); operation x_none(m : OclAny) : OclAny pre: true post: true activity: return ("" + ((MathLib.bitwiseAnd(x, M[m+1]) = 0)))->toInteger(); operation x_count(m : OclAny) : OclAny pre: true post: true activity: return bin(MathLib.bitwiseAnd(x, M[m+1]))->count("1"); operation x_val(m : OclAny) : OclAny pre: true post: true activity: return MathLib.bitwiseAnd(x, M[m+1]); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) list_mask=[] for _ in range(n): k,*list_b=map(int,input().split()) mask=0 for i in range(k): mask+=2**list_b[i] list_mask.append(mask) q=int(input()) bit_flag=0 for _ in range(q): command,*list_num=input().split() m=int(list_num[0]) if command=="0" : i=m if bit_flag &(2**i): print(1) else : print(0) elif command=="1" : bit_flag=bit_flag | list_mask[m] elif command=="2" : bit_flag=bit_flag & ~ list_mask[m] elif command=="3" : bit_flag=bit_flag ^ list_mask[m] elif command=="4" : if(bit_flag & list_mask[m])==list_mask[m]: print(1) else : print(0) elif command=="5" : if bit_flag & list_mask[m]: print(1) else : print(0) elif command=="6" : if not bit_flag & list_mask[m]: print(1) else : print(0) elif command=="7" : print(bin(bit_flag & list_mask[m]).count("1")) elif command=="8" : print(bit_flag & list_mask[m]) else : raise ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var list_mask : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var k : OclAny := null; var list_b : OclAny := null; Sequence{k,list_b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mask : int := 0 ; for i : Integer.subrange(0, k-1) do ( mask := mask + (2)->pow(list_b[i+1])) ; execute ((mask) : list_mask)) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var bit_flag : int := 0 ; for _anon : Integer.subrange(0, q-1) do ( var command : OclAny := null; var list_num : OclAny := null; Sequence{command,list_num} := input().split() ; var m : int := ("" + ((list_num->first())))->toInteger() ; if command = "0" then ( var i : int := m ; if MathLib.bitwiseAnd(bit_flag, ((2)->pow(i))) then ( execute (1)->display() ) else ( execute (0)->display() ) ) else (if command = "1" then ( bit_flag := MathLib.bitwiseOr(bit_flag, list_mask[m+1]) ) else (if command = "2" then ( bit_flag := MathLib.bitwiseAnd(bit_flag, MathLib.bitwiseNot(list_mask[m+1])) ) else (if command = "3" then ( bit_flag := MathLib.bitwiseXor(bit_flag, list_mask[m+1]) ) else (if command = "4" then ( if (MathLib.bitwiseAnd(bit_flag, list_mask[m+1])) = list_mask[m+1] then ( execute (1)->display() ) else ( execute (0)->display() ) ) else (if command = "5" then ( if MathLib.bitwiseAnd(bit_flag, list_mask[m+1]) then ( execute (1)->display() ) else ( execute (0)->display() ) ) else (if command = "6" then ( if not(MathLib.bitwiseAnd(bit_flag, list_mask[m+1])) then ( execute (1)->display() ) else ( execute (0)->display() ) ) else (if command = "7" then ( execute (bin(MathLib.bitwiseAnd(bit_flag, list_mask[m+1]))->count("1"))->display() ) else (if command = "8" then ( execute (MathLib.bitwiseAnd(bit_flag, list_mask[m+1]))->display() ) else ( (small_stmt raise) ) ) ) ) ) ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- end=0 shuffled=[] while end==0 : phrase=input() if phrase=='-' : end+=1 else : shuffleTimes=int(input()) for i in range(shuffleTimes): shufflePosition=int(input()) phrase=phrase[shufflePosition :]+phrase[: shufflePosition] shuffled.append(phrase) for array in shuffled : print(array) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var end : int := 0 ; var shuffled : Sequence := Sequence{} ; while end = 0 do ( var phrase : String := (OclFile["System.in"]).readLine() ; if phrase = '-' then ( end := end + 1 ) else ( var shuffleTimes : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, shuffleTimes-1) do ( var shufflePosition : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; phrase := phrase.subrange(shufflePosition+1) + phrase.subrange(1,shufflePosition)) ; execute ((phrase) : shuffled) )) ; for array : shuffled do ( execute (array)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): x=int(input()) a=int(input()) b=int(input()) x-=a x=x-x//b*b print(x) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; x := x - a ; x := x - x div b * b ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) MASK=(1<<64)-1 mask=[] for i in range(q): retmask=0 ret=[i for i in map(int,input().split())] for i in range(1,ret[0]+1): retmask+=1<0 : print(1) else : print(0) elif query[0]==6 : if n & mask[query[1]]==0 : print(1) else : print(0) elif query[0]==7 : print(bin(n & mask[query[1]]).count("1")) elif query[0]==8 : print(mask[query[1]]& n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var MASK : double := (1 * (2->pow(64))) - 1 ; var mask : Sequence := Sequence{} ; for i : Integer.subrange(0, q-1) do ( var retmask : int := 0 ; var ret : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->select(i | true)->collect(i | (i)) ; for i : Integer.subrange(1, ret->first() + 1-1) do ( retmask := retmask + 1 * (2->pow(ret[i+1]))) ; execute ((retmask) : mask)) ; q := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := 0 ; for i : Integer.subrange(0, q-1) do ( var query : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->select(i | true)->collect(i | (i)) ; if query->first() = 0 then ( var temp : int := 1 * (2->pow(query[1+1])) ; if (MathLib.bitwiseAnd(n, temp)) = 0 then ( execute (0)->display() ) else ( execute (1)->display() ) ) else (if query->first() = 1 then ( n := (MathLib.bitwiseOr(n, mask[query[1+1]+1])) ) else (if query->first() = 2 then ( n := MathLib.bitwiseAnd(n, (MathLib.bitwiseAnd(MathLib.bitwiseNot(mask[query[1+1]+1]), MASK))) ) else (if query->first() = 3 then ( n := MathLib.bitwiseXor(n, mask[query[1+1]+1]) ) else (if query->first() = 4 then ( if MathLib.bitwiseAnd(n, mask[query[1+1]+1]) = mask[query[1+1]+1] then ( execute (1)->display() ) else ( execute (0)->display() ) ) else (if query->first() = 5 then ( if MathLib.bitwiseAnd(n, mask[query[1+1]+1]) > 0 then ( execute (1)->display() ) else ( execute (0)->display() ) ) else (if query->first() = 6 then ( if MathLib.bitwiseAnd(n, mask[query[1+1]+1]) = 0 then ( execute (1)->display() ) else ( execute (0)->display() ) ) else (if query->first() = 7 then ( execute (bin(MathLib.bitwiseAnd(n, mask[query[1+1]+1]))->count("1"))->display() ) else (if query->first() = 8 then ( execute (MathLib.bitwiseAnd(mask[query[1+1]+1], n))->display() ) else skip ) ) ) ) ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MASK=(1<<64)-1 x=0 def c_test(i): return+(x &(1<0) def c_set(m): global x x |=M[m] def c_clear(m): global x m=M[m] x=(x | m)^ m def c_flip(m): global x x ^=M[m] def c_all(m): m=M[m] return+(x & m==m) def c_any(m): m=M[m] return+(x & m>0) def c_none(m): m=M[m] return+(x & m==0) def c_count(m): m=M[m] return bin(x & m).count('1') def c_val(m): m=M[m] return x & m fmap=[c_test,c_set,c_clear,c_flip,c_all,c_any,c_none,c_count,c_val,] def query(Q): for q in range(Q): t,*cmd=map(int,input().split()) res=fmap[t](*cmd) if res is not None : yield res M=[] N=int(input()) for i in range(N): k,*B=map(int,input().split()) M.append(sum(1<pow(64))) - 1 ; var x : int := 0 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var fmap : Sequence := Sequence{c_test}->union(Sequence{c_set}->union(Sequence{c_clear}->union(Sequence{c_flip}->union(Sequence{c_all}->union(Sequence{c_any}->union(Sequence{c_none}->union(Sequence{c_count}->union(Sequence{ c_val })))))))) ; skip ; var M : Sequence := Sequence{} ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, N-1) do ( var k : OclAny := null; var B : OclAny := null; Sequence{k,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((((argument (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name b))))))) (comp_for for (exprlist (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name B))))))))->sum()) : M)) ; Q := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((argument * (test (logical_test (comparison (expr (atom (name query)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name Q)))))))) )))))))))->display(); operation c_test(i : OclAny) : OclAny pre: true post: true activity: return (MathLib.bitwiseAnd(x, (1 * (2->pow(i)))) > 0); operation c_set(m : OclAny) pre: true post: true activity: skip ; x := x or M[m+1]; operation c_clear(m : OclAny) pre: true post: true activity: skip ; m := M[m+1] ; x := MathLib.bitwiseXor((MathLib.bitwiseOr(x, m)), m); operation c_flip(m : OclAny) pre: true post: true activity: skip ; x := x xor M[m+1]; operation c_all(m : OclAny) : OclAny pre: true post: true activity: m := M[m+1] ; return (MathLib.bitwiseAnd(x, m) = m); operation c_any(m : OclAny) : OclAny pre: true post: true activity: m := M[m+1] ; return (MathLib.bitwiseAnd(x, m) > 0); operation c_none(m : OclAny) : OclAny pre: true post: true activity: m := M[m+1] ; return (MathLib.bitwiseAnd(x, m) = 0); operation c_count(m : OclAny) : OclAny pre: true post: true activity: m := M[m+1] ; return bin(MathLib.bitwiseAnd(x, m))->count('1'); operation c_val(m : OclAny) : OclAny pre: true post: true activity: m := M[m+1] ; return MathLib.bitwiseAnd(x, m); operation query(Q : OclAny) pre: true post: true activity: for q : Integer.subrange(0, Q-1) do ( var t : OclAny := null; var cmd : OclAny := null; Sequence{t,cmd} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var res : OclAny := fmap[t+1]((argument * (test (logical_test (comparison (expr (atom (name cmd)))))))) ; if not(res <>= null) then ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return res ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class new_Node : def __init__(self,data): self.data=data self.next=None def getIntesectionNode(head1,head2): current1=head1 current2=head2 if(not current1 or not current2): return-1 while(current1 and current2 and current1!=current2): current1=current1.next current2=current2.next if(current1==current2): return current1.data if(not current1): current1=head2 if(not current2): current2=head1 return current1.data head1=new_Node(10) head2=new_Node(3) newNode=new_Node(6) head2.next=newNode newNode=new_Node(9) head2.next.next=newNode newNode=new_Node(15) head1.next=newNode head2.next.next.next=newNode newNode=new_Node(30) head1.next.next=newNode head1.next.next.next=None print(getIntesectionNode(head1,head2)) ------------------------------------------------------------ OCL File: --------- class new_Node { static operation newnew_Node() : new_Node pre: true post: new_Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := null; operation initialise(data : OclAny) : new_Node pre: true post: true activity: self.data := data ; self.next := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; head1 := (new_Node.newnew_Node()).initialise(10) ; head2 := (new_Node.newnew_Node()).initialise(3) ; var newNode : new_Node := (new_Node.newnew_Node()).initialise(6) ; head2.next := newNode ; newNode := (new_Node.newnew_Node()).initialise(9) ; head2.next.next := newNode ; newNode := (new_Node.newnew_Node()).initialise(15) ; head1.next := newNode ; head2.next.next.next := newNode ; newNode := (new_Node.newnew_Node()).initialise(30) ; head1.next.next := newNode ; head1.next.next.next := null ; execute (getIntesectionNode(head1, head2))->display(); operation getIntesectionNode(head1 : OclAny, head2 : OclAny) : OclAny pre: true post: true activity: var current1 : OclAny := head1 ; var current2 : OclAny := head2 ; if (not(current1) or not(current2)) then ( return -1 ) else skip ; while (current1 & current2 & current1 /= current2) do ( current1 := current1.next ; current2 := current2.next ; if (current1 = current2) then ( return current1.data ) else skip ; if (not(current1)) then ( current1 := head2 ) else skip ; if (not(current2)) then ( current2 := head1 ) else skip) ; return current1.data; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gen(n,r): a=r[-1] a+=1 for i in range(1,n+1): r.append(a) a+=2 return r def conell(n): res=[] k=1 res.append(0) while 1 : res=gen(k,res) k+=1 j=len(res)-1 while j!=n and j+k>n : k-=1 if j>=n : break res.remove(res[0]) return res if __name__=="__main__" : n=10 print("The first %d terms are" % n) res=conell(n) for i in range(len(res)): print(res[i],end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 10 ; execute (StringLib.format("The first %d terms are",n))->display() ; res := conell(n) ; for i : Integer.subrange(0, (res)->size()-1) do ( execute (res[i+1])->display()) ; execute (->display() ) else skip; operation gen(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: var a : String := r->last() ; a := a + 1 ; for i : Integer.subrange(1, n + 1-1) do ( execute ((a) : r) ; a := a + 2) ; return r; operation conell(n : OclAny) : OclAny pre: true post: true activity: var res : Sequence := Sequence{} ; var k : int := 1 ; execute ((0) : res) ; while 1 do ( res := gen(k, res) ; k := k + 1 ; var j : double := (res)->size() - 1 ; while j /= n & (j + k->compareTo(n)) > 0 do ( k := k - 1) ; if (j->compareTo(n)) >= 0 then ( break ) else skip) ; execute ((res->first()) /: res) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=list(map(int,input().split())) B=list(map(int,input().split())) answer=0 for i in range(N): answer=max(answer,sum(A[: i+1]+B[i :])) print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var B : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var answer : int := 0 ; for i : Integer.subrange(0, N-1) do ( answer := Set{answer, (A.subrange(1,i + 1) + B.subrange(i+1))->sum()}->max()) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np if __name__=='__main__' : N=int(input()) A=[list(map(int,input().split()))for _ in range(2)] A=np.array(A) accum=np.zeros((2,N+1),np.int) for i in range(N): accum[0,i+1]=accum[0,i]+A[0,i] accum[1,i+1]=max(accum[0,i+1],accum[1,i])+A[1,i] print(accum[1,N]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := Integer.subrange(0, 2-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; A := (A) ; var accum : Sequence := MatrixLib.singleValueMatrix(Sequence{2, N + 1}, 0.0) ; for i : Integer.subrange(0, N-1) do ( accum->first()[i + 1+1] := accum->first()[i+1] + A->first()[i+1] ; accum[1+1][i + 1+1] := Set{accum->first()[i + 1+1], accum[1+1][i+1]}->max() + A[1+1][i+1]) ; execute (accum[1+1][N+1])->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin from itertools import accumulate N=int(stdin.readline().rstrip()) a=[[None]*N]*2 accum_a=[[None]*N]*2 data0=stdin.readline().split() data1=stdin.readline().split() a[0]=[int(data0[i])for i in range(N)] a[1]=[int(data1[i])for i in range(N-1,-1,-1)] accum_a[0]=list(accumulate(a[0])) accum_a[1]=list(accumulate(a[1])) accum_a[1]=accum_a[1][: :-1] vals_sum=[None]*N for i in range(N): vals_sum[i]=accum_a[0][i]+accum_a[1][i] print(max(vals_sum)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := ("" + ((stdin.readLine().rstrip())))->toInteger() ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ MatrixLib.elementwiseMult(Sequence{ null }, N) }, 2) ; var accum_a : Sequence := MatrixLib.elementwiseMult(Sequence{ MatrixLib.elementwiseMult(Sequence{ null }, N) }, 2) ; var data0 : OclAny := stdin.readLine().split() ; var data1 : OclAny := stdin.readLine().split() ; a->first() := Integer.subrange(0, N-1)->select(i | true)->collect(i | (("" + ((data0[i+1])))->toInteger())) ; a[1+1] := Integer.subrange(-1 + 1, N - 1)->reverse()->select(i | true)->collect(i | (("" + ((data1[i+1])))->toInteger())) ; accum_a->first() := (accumulate(a->first())) ; accum_a[1+1] := (accumulate(a[1+1])) ; accum_a[1+1] := accum_a[1+1](subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var vals_sum : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, N) ; for i : Integer.subrange(0, N-1) do ( vals_sum[i+1] := accum_a->first()[i+1] + accum_a[1+1][i+1]) ; execute ((vals_sum)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) grid=[list(int(s)for s in input().split())for _ in range(2)] max=0 for i in range(num): candies=sum(grid[0][: i+1]+grid[1][i :]) max=candies if maxtoInteger() ; var grid : Sequence := Integer.subrange(0, 2-1)->select(_anon | true)->collect(_anon | (((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))))) ; var max : int := 0 ; for i : Integer.subrange(0, num-1) do ( var candies : OclAny := (grid->first().subrange(1,i + 1) + grid[1+1].subrange(i+1))->sum() ; max := if (max->compareTo(candies)) < 0 then candies else max endif) ; execute (max)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) candy_map=[] candy_map.append(list(map(int,input().split()))) candy_map.append(list(map(int,input().split()))) dp=[[0]*n for _ in range(2)] dp[0][0]=candy_map[0][0] for i in range(1,n): dp[0][i]=dp[0][i-1]+candy_map[0][i] dp[1][0]=dp[0][0]+candy_map[1][0] for i in range(1,n): dp[1][i]=candy_map[1][i]+max(dp[0][i],dp[1][i-1]) print(dp[1][-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var candy_map : Sequence := Sequence{} ; execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : candy_map) ; execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : candy_map) ; var dp : Sequence := Integer.subrange(0, 2-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, n))) ; dp->first()->first() := candy_map->first()->first() ; for i : Integer.subrange(1, n-1) do ( dp->first()[i+1] := dp->first()[i - 1+1] + candy_map->first()[i+1]) ; dp[1+1]->first() := dp->first()->first() + candy_map[1+1]->first() ; for i : Integer.subrange(1, n-1) do ( dp[1+1][i+1] := candy_map[1+1][i+1] + Set{dp->first()[i+1], dp[1+1][i - 1+1]}->max()) ; execute (dp[1+1]->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) arr=[] for i in range(n): arr.append(input()) c=0 for i in range(len(arr[0])): cur=arr[0][i] for j in range(n): if arr[j][i]!=cur : return c c+=1 return c print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (solve())->display(); operation solve() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : arr)) ; var c : int := 0 ; for i : Integer.subrange(0, (arr->first())->size()-1) do ( var cur : OclAny := arr->first()[i+1] ; for j : Integer.subrange(0, n-1) do ( if arr[j+1][i+1] /= cur then ( return c ) else skip) ; c := c + 1) ; return c; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000 sequence=[0]*(MAX+1); def vanEckSequence(): for i in range(MAX): sequence[i]=0 ; for i in range(MAX): for j in range(i-1,-1,-1): if(sequence[j]==sequence[i]): sequence[i+1]=i-j ; break ; def getNthTerm(n): return sequence[n]; if __name__=="__main__" : vanEckSequence(); n=6 ; print(getNthTerm(n)); n=100 ; print(getNthTerm(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1000 ; var sequence : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX + 1)); ; skip ; skip ; if __name__ = "__main__" then ( vanEckSequence(); ; n := 6; ; execute (getNthTerm(n))->display(); ; n := 100; ; execute (getNthTerm(n))->display(); ) else skip; operation vanEckSequence() pre: true post: true activity: for i : Integer.subrange(0, MAX-1) do ( sequence[i+1] := 0;) ; for i : Integer.subrange(0, MAX-1) do ( for j : Integer.subrange(-1 + 1, i - 1)->reverse() do ( if (sequence[j+1] = sequence[i+1]) then ( sequence[i + 1+1] := i - j; ; break; ) else skip)); operation getNthTerm(n : OclAny) pre: true post: true activity: return sequence[n+1];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for j in range(int(input())): n=int(input()) a=list(map(int,input().split())) b=a.copy() b.sort() ans=[] var=0 for i in range(n): for k in range(n): if a[k]==b[i]and k==i : break elif a[k]==b[i]: ans.append([i+1,k+1,1]) for p in range(k,i,-1): temp=a[p] a[p]=a[p-1] a[p-1]=temp for j in range(len(ans)): if ans[j][0]toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : OclAny := a->copy() ; b := b->sort() ; var ans : Sequence := Sequence{} ; var var : int := 0 ; for i : Integer.subrange(0, n-1) do ( for k : Integer.subrange(0, n-1) do ( if a[k+1] = b[i+1] & k = i then ( break ) else (if a[k+1] = b[i+1] then ( execute ((Sequence{i + 1}->union(Sequence{k + 1}->union(Sequence{ 1 }))) : ans) ; for p : Integer.subrange(i + 1, k)->reverse() do ( var temp : OclAny := a[p+1] ; a[p+1] := a[p - 1+1] ; a[p - 1+1] := temp) ) else skip))) ; for j : Integer.subrange(0, (ans)->size()-1) do ( if (ans[j+1]->first()->compareTo(ans[j+1][1+1])) < 0 then ( var := var + 1 ) else skip) ; execute (var)->display() ; for j : Integer.subrange(0, (ans)->size()-1) do ( if (ans[j+1]->first()->compareTo(ans[j+1][1+1])) < 0 then ( ans[j+1][2+1] := ans[j+1][1+1] - ans[j+1]->first() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))))->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- D=[] H=[] d=input() while d!='-' : D.append(d+d) m=int(input()) h=0 for i in range(m): h+=int(input()) H.append(h) d=input() for i in range(len(D)): print(D[i][(H[i]%(len(D[i])//2)):((H[i]%(len(D[i])//2))+(len(D[i])//2))]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var D : Sequence := Sequence{} ; var H : Sequence := Sequence{} ; var d : String := (OclFile["System.in"]).readLine() ; while d /= '-' do ( execute ((d + d) : D) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var h : int := 0 ; for i : Integer.subrange(0, m-1) do ( h := h + ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; execute ((h) : H) ; d := (OclFile["System.in"]).readLine()) ; for i : Integer.subrange(0, (D)->size()-1) do ( execute (D[i+1].subrange((H[i+1] mod ((D[i+1])->size() div 2))+1, ((H[i+1] mod ((D[i+1])->size() div 2)) + ((D[i+1])->size() div 2))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) temp=[] for i in range(t): l=input() temp.append(l) t='' i=0 c=0 while(True): a=temp[0][i] for j in range(1,len(temp)): if a==temp[j][i]: continue else : c=1 break if c==1 : print(len(t)) break else : i+=1 t+=a ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var temp : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( var l : String := (OclFile["System.in"]).readLine() ; execute ((l) : temp)) ; t := '' ; var i : int := 0 ; var c : int := 0 ; while (true) do ( var a : OclAny := temp->first()[i+1] ; for j : Integer.subrange(1, (temp)->size()-1) do ( if a = temp[j+1][i+1] then ( continue ) else ( c := 1 ; break )) ; if c = 1 then ( execute ((t)->size())->display() ; break ) else ( i := i + 1 ; t := t + a )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=[] for _ in range(n): s.append(list(input())) s=list(map(set,zip(*s))) r=0 for i in range(len(s)): if len(s[i])==1 : r+=1 else : break print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((((OclFile["System.in"]).readLine())->characters()) : s)) ; s := ((Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name s)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name s)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name s)))))))`third->at(_indx)} ))->collect( _x | (OclType["Set"])->apply(_x) )) ; var r : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if (s[i+1])->size() = 1 then ( r := r + 1 ) else ( break )) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import* from math import* from decimal import* from collections import* import sys def _input(): return map(int,input().split()) def _list(): return list(map(int,input().split())) def _int(): return int(input()) def solves(): n=_int() a=[] for i in range(n): s=input() a.append(s) ans=0 for j in range(len(a[0])): t=a[0][j] for i in range(1,n): if a[i][j]==t : continue else : print(ans) return ans+=1 print(ans) t=1 for _ in range(0,t): solves() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; t := 1 ; for _anon : Integer.subrange(0, t-1) do ( solves()); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation _list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation _int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation solves() pre: true post: true activity: var n : OclAny := _int() ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; execute ((s) : a)) ; var ans : int := 0 ; for j : Integer.subrange(0, (a->first())->size()-1) do ( var t : OclAny := a->first()[j+1] ; for i : Integer.subrange(1, n-1) do ( if a[i+1][j+1] = t then ( continue ) else ( execute (ans)->display() ; return )) ; ans := ans + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def convert_in_list(string): list=[] for c in string : list.append(c) return list n=int(input()) last_prefix=convert_in_list(input()) for _ in range(n-1): phone=convert_in_list(input()) i=0 prefix=[] while itoInteger() ; var last_prefix : OclAny := convert_in_list((OclFile["System.in"]).readLine()) ; for _anon : Integer.subrange(0, n - 1-1) do ( var phone : OclAny := convert_in_list((OclFile["System.in"]).readLine()) ; var i : int := 0 ; var prefix : Sequence := Sequence{} ; while (i->compareTo((last_prefix)->size())) < 0 & phone[i+1] = last_prefix[i+1] do ( execute ((phone[i+1]) : prefix) ; i := i + 1) ; last_prefix := prefix) ; execute ((prefix)->size())->display(); operation convert_in_list(string : OclAny) : OclAny pre: true post: true activity: var OclType["Sequence"] : Sequence := Sequence{} ; for c : string do ( execute ((c) : OclType["Sequence"])) ; return OclType["Sequence"]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import random def selectRandom(x): res=0 ; count=0 ; count+=1 ; if(count==1): res=x ; else : i=random.randrange(count); if(i==count-1): res=x ; return res ; stream=[1,2,3,4]; n=len(stream); for i in range(n): print("Random number from first",(i+1),"numbers is",selectRandom(stream[i])); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var stream : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))); ; var n : int := (stream)->size(); ; for i : Integer.subrange(0, n-1) do ( execute ("Random number from first")->display();); operation selectRandom(x : OclAny) pre: true post: true activity: var res : int := 0; ; var count : int := 0; ; count := count + 1; ; if (count = 1) then ( res := x; ) else ( var i : int := (OclRandom.defaultInstanceOclRandom()).nextInt(count); ; if (i = count - 1) then ( res := x; ) else skip ) ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as ma def CountDigits(n): if(n==1): return 1 sum=0 for i in range(2,n+1): sum+=ma.log(i,10) sum*=n return ma.ceil(sum) if __name__=='__main__' : N=5 print(CountDigits(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var N : int := 5 ; execute (CountDigits(N))->display() ) else skip; operation CountDigits(n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return 1 ) else skip ; var sum : int := 0 ; for i : Integer.subrange(2, n + 1-1) do ( sum := sum + ma.log(i, 10)) ; sum := sum * n ; return ma.ceil(sum); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() a=[] t=0 for c in s : if len(a)>0 and a[-1]==c : t+=1 a.pop() else : a.append(c) print('Yes' if t % 2==1 else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var a : Sequence := Sequence{} ; var t : int := 0 ; for c : s->characters() do ( if (a)->size() > 0 & a->last() = c then ( t := t + 1 ; a := a->front() ) else ( execute ((c) : a) )) ; execute (if t mod 2 = 1 then 'Yes' else 'No' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque stack=deque() count=0 str=input() for c in str : if len(stack)==0 : stack.append(c) else : if c!=stack[len(stack)-1]: stack.append(c) else : stack.pop() count+=1 if count % 2!=0 and count!=0 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stack : Sequence := () ; var count : int := 0 ; var OclType["String"] : String := (OclFile["System.in"]).readLine() ; for c : OclType["String"]->characters() do ( if (stack)->size() = 0 then ( execute ((c) : stack) ) else ( if c /= stack[(stack)->size() - 1+1] then ( execute ((c) : stack) ) else ( stack := stack->front() ; count := count + 1 ) )) ; if count mod 2 /= 0 & count /= 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque line=list(input().strip()) switch : bool=False s=deque() for i in range(len(line)): if s and s[-1]==line[i]: switch=not switch s.pop() else : s.append(line[i]) print('Yes' if switch else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var line : Sequence := (input()->trim()) ; var switch : boolean := false ; var s : Sequence := () ; for i : Integer.subrange(0, (line)->size()-1) do ( if s & s->last() = line[i+1] then ( switch := not(switch) ; s := s->front() ) else ( execute ((line[i+1]) : s) )) ; execute (if switch then 'Yes' else 'No' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,k=list(map(int,input().split(' '))) elems=list(map(int,input().split(' '))) all_same=lambda arr : all([x==arr[0]for x in arr]) if all_same(elems): print(0) return if k==1 : print(-1) return if not all_same(elems[k-1 :]): print(-1) return target=elems[-1] to_delete=elems[0 : k-1] while to_delete and to_delete[-1]==target : to_delete.pop() print(len(to_delete)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var elems : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var all_same : Function := lambda arr : OclAny in ((arr->select(x | true)->collect(x | (x = arr->first())))->forAll( _x | _x = true )) ; if all_same->apply(elems) then ( execute (0)->display() ; return ) else skip ; if k = 1 then ( execute (-1)->display() ; return ) else skip ; if not(all_same->apply(elems.subrange(k - 1+1))) then ( execute (-1)->display() ; return ) else skip ; var target : OclAny := elems->last() ; var to_delete : OclAny := elems.subrange(0+1, k - 1) ; while to_delete & to_delete->last() = target do ( to_delete := to_delete->front()) ; execute ((to_delete)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() stk=[] cnt=0 for c in s : if stk and c==stk[-1]: stk.pop() cnt+=1 else : stk.append(c) print('Yes' if cnt & 1 else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var stk : Sequence := Sequence{} ; var cnt : int := 0 ; for c : s->characters() do ( if stk & c = stk->last() then ( stk := stk->front() ; cnt := cnt + 1 ) else ( execute ((c) : stk) )) ; execute (if MathLib.bitwiseAnd(cnt, 1) then 'Yes' else 'No' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=0 b=[[0 for col in range(250)]for row in range(10)] a="first" while True : a=list(input()) if a[0]=="-" : break m=int(input()) h=0 ans=[0]*250 for i in range(m): h=int(input()) for j in range(h,len(a)): ans[j-h]=a[j] for k in range(h): ans[len(a)-h+k]=a[k] for l in range(len(a)): a[l]=ans[l] for y in range(len(a)): b[x][y]=a[y] x+=1 for i in range(x): for j in range(200): if b[i][j]==0 : break print(b[i][j],end="") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 0 ; var b : Sequence := Integer.subrange(0, 10-1)->select(row | true)->collect(row | (Integer.subrange(0, 250-1)->select(col | true)->collect(col | (0)))) ; var a : String := "first" ; while true do ( a := ((OclFile["System.in"]).readLine())->characters() ; if a->first() = "-" then ( break ) else skip ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var h : int := 0 ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 250) ; for i : Integer.subrange(0, m-1) do ( h := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(h, (a)->size()-1) do ( ans[j - h+1] := a[j+1]) ; for k : Integer.subrange(0, h-1) do ( ans[(a)->size() - h + k+1] := a[k+1]) ; for l : Integer.subrange(0, (a)->size()-1) do ( a[l+1] := ans[l+1])) ; for y : Integer.subrange(0, (a)->size()-1) do ( b[x+1][y+1] := a[y+1]) ; x := x + 1) ; for i : Integer.subrange(0, x-1) do ( for j : Integer.subrange(0, 200-1) do ( if b[i+1][j+1] = 0 then ( break ) else skip ; execute (b[i+1][j+1])->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(input()) lis=['stop','!'] ans=0 for i in s : lis.append(i) if lis[-1]==lis[-2]: lis.pop(-1) lis.pop(-1) ans+=1 if ans % 2==0 : print('No') else : print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var lis : Sequence := Sequence{'stop'}->union(Sequence{ '!' }) ; var ans : int := 0 ; for i : s do ( execute ((i) : lis) ; if lis->last() = lis->front()->last() then ( lis := lis->excludingAt(-1+1) ; lis := lis->excludingAt(-1+1) ; ans := ans + 1 ) else skip) ; if ans mod 2 = 0 then ( execute ('No')->display() ) else ( execute ('Yes')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_CHAR=[26] def minChanges(str): n=len(str) if(n>MAX_CHAR[0]): return-1 dist_count=0 count=[0]*MAX_CHAR[0] for i in range(n): if(count[ord(str[i])-ord('a')]==0): dist_count+=1 count[(ord(str[i])-ord('a'))]+=1 return(n-dist_count) if __name__=='__main__' : str="aebaecedabbee" print(minChanges(str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_CHAR : Sequence := Sequence{ 26 } ; skip ; if __name__ = '__main__' then ( OclType["String"] := "aebaecedabbee" ; execute (minChanges(OclType["String"]))->display() ) else skip; operation minChanges(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var n : int := (OclType["String"])->size() ; if ((n->compareTo(MAX_CHAR->first())) > 0) then ( return -1 ) else skip ; var dist_count : int := 0 ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX_CHAR->first()) ; for i : Integer.subrange(0, n-1) do ( if (count[(("" + ([i+1])))->char2byte() - ('a')->char2byte()+1] = 0) then ( dist_count := dist_count + 1 ) else skip ; count[((("" + ([i+1])))->char2byte() - ('a')->char2byte())+1] := count[((("" + ([i+1])))->char2byte() - ('a')->char2byte())+1] + 1) ; return (n - dist_count); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maximumNum(curr_num,res): len1=len(curr_num); len2=len(res); if(len1==len2): i=0 ; while(curr_num[i]==res[i]): i+=1 ; if(curr_num[i]='0' and str[i]<='9'): curr_num+=str[i]; i+=1 ; if(i==n): break ; if(len(curr_num)>0): i-=1 ; res=maximumNum(curr_num,res); curr_num="" ; if(len(curr_num)==0 and len(res)==0): res+='0' ; return maximumNum(curr_num,res); str="100klh564abc365bg" ; print(extractMaximum(str)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; OclType["String"] := "100klh564abc365bg"; ; execute (extractMaximum(OclType["String"]))->display();; operation maximumNum(curr_num : OclAny, res : OclAny) pre: true post: true activity: var len1 : int := (curr_num)->size(); ; var len2 : int := (res)->size(); ; if (len1 = len2) then ( var i : int := 0; ; while (curr_num[i+1] = res[i+1]) do ( i := i + 1;) ; if ((curr_num[i+1]->compareTo(res[i+1])) < 0) then ( return res; ) else ( return curr_num; ) ) else skip ; return if ((len1->compareTo(len2)) < 0) then res else curr_num endif;; operation extractMaximum(OclType["String"] : OclAny) pre: true post: true activity: var n : int := (OclType["String"])->size(); ; curr_num := ""; ; res := ""; ; for i : Integer.subrange(0, n-1) do ( while ((i->compareTo(n)) < 0 & ("" + ([i+1])) = '0') do ( i := i + 1;) ; while ((i->compareTo(n)) < 0 & ("" + ([i+1])) >= '0' & ("" + ([i+1])) <= '9') do ( curr_num := curr_num + ("" + ([i+1])); ; i := i + 1;) ; if (i = n) then ( break; ) else skip ; if ((curr_num)->size() > 0) then ( i := i - 1; ) else skip ; res := maximumNum(curr_num, res); ; curr_num := "";) ; if ((curr_num)->size() = 0 & (res)->size() = 0) then ( res := res + '0'; ) else skip ; return maximumNum(curr_num, res);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=[int(i)for i in input().split()] if K==0 : print(N*N) else : count=0 for i in range(K+1,N+1): amari=N % i warikiriru=N-amari count+=warikiriru-int(warikiriru/i)-int(warikiriru/i)*(K-1) if amari>=K : count+=amari-(K-1) print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if K = 0 then ( execute (N * N)->display() ) else ( var count : int := 0 ; for i : Integer.subrange(K + 1, N + 1-1) do ( var amari : int := N mod i ; var warikiriru : double := N - amari ; count := count + warikiriru - ("" + ((warikiriru / i)))->toInteger() - ("" + ((warikiriru / i)))->toInteger() * (K - 1) ; if (amari->compareTo(K)) >= 0 then ( count := count + amari - (K - 1) ) else skip) ; execute (count)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(N : int,K : int): print(sum(N//b*(b-K)+max(0,N % b-max(0,K-1))for b in range(K+1,N+1))) def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() N=int(next(tokens)) K=int(next(tokens)) solve(N,K) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(N : int, K : int) pre: true post: true activity: execute (((argument (test (logical_test (comparison (expr (expr (expr (expr (atom (name N))) // (expr (atom (name b)))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (name K)))))))) )))) + (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (expr (expr (atom (name N))) % (expr (atom (name b)))) - (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name K))) - (expr (atom (number (integer 1)))))))))) )))))))))) )))))))) (comp_for for (exprlist (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name K))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name N))) + (expr (atom (number (integer 1)))))))))) )))))))))->sum())->display(); operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var N : int := ("" + (((tokens).next())))->toInteger() ; var K : int := ("" + (((tokens).next())))->toInteger() ; solve(N, K); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) ans=0 for b in range(k+1,n+1): q=n//b r=n % b ans+=q*(b-k) ans+=max(0,r-k+1) if k==0 : ans-=n print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; for b : Integer.subrange(k + 1, n + 1-1) do ( var q : int := n div b ; var r : int := n mod b ; ans := ans + q * (b - k) ; ans := ans + Set{0, r - k + 1}->max()) ; if k = 0 then ( ans := ans - n ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sr=lambda : sys.stdin.readline().rstrip() ir=lambda : int(sr()) lr=lambda : list(map(int,sr().split())) N,K=lr() total=N*N for b in range(1,N+1): if b<=K : total-=N else : total-=K*(N//b)+max(0,min(N % b,K-1)) answer=total print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var sr : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var ir : Function := lambda $$ : OclAny in (("" + ((sr->apply())))->toInteger()) ; var lr : Function := lambda $$ : OclAny in (((sr->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := lr->apply() ; var total : double := N * N ; for b : Integer.subrange(1, N + 1-1) do ( if (b->compareTo(K)) <= 0 then ( total := total - N ) else ( total := total - K * (N div b) + Set{0, Set{N mod b, K - 1}->min()}->max() )) ; var answer : OclAny := total ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()); print(sum(n//b*(b-k)+max(n % b-k+(k>0),0)for b in range(k+1,n+1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); execute (((argument (test (logical_test (comparison (expr (expr (expr (expr (atom (name n))) // (expr (atom (name b)))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (name k)))))))) )))) + (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (expr (atom (name n))) % (expr (atom (name b)))) - (expr (atom (name k)))) + (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name k)))) > (comparison (expr (atom (number (integer 0))))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))))))) (comp_for for (exprlist (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name k))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) )))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=input().split() z=-1 for i in range(n-1,-1,-1): if a[i]!=a[-1]: z=i break if k>z+1 : print(z+1) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := input().split() ; var z : int := -1 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if a[i+1] /= a->last() then ( z := i ; break ) else skip) ; if (k->compareTo(z + 1)) > 0 then ( execute (z + 1)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) rules=[map(int,input().split())for _ in range(k)] ans=[[0,1,1,1,1,1,1]for _ in range(n+1)] dic=[0,[0,1,0,0,1,0,0],[0,0,1,0,0,1,0],[0,0,0,1,0,0,1]] for[d,p]in rules : ans[d]=list(dic[p]) ans[1][4]=0 ans[1][5]=0 ans[1][6]=0 for d in range(2,n+1): ans[d][1]=ans[d][1]*(ans[d-1][2]+ans[d-1][3]+ans[d-1][5]+ans[d-1][6]) ans[d][2]=ans[d][2]*(ans[d-1][1]+ans[d-1][3]+ans[d-1][4]+ans[d-1][6]) ans[d][3]=ans[d][3]*(ans[d-1][1]+ans[d-1][2]+ans[d-1][4]+ans[d-1][5]) ans[d][4]=ans[d][4]*ans[d-1][1] ans[d][5]=ans[d][5]*ans[d-1][2] ans[d][6]=ans[d][6]*ans[d-1][3] print(sum(ans[n])% 10000) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var rules : Sequence := Integer.subrange(0, k-1)->select(_anon | true)->collect(_anon | ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ans : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })))))))) ; var dic : Sequence := Sequence{0}->union(Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 0 }))))))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 0 }))))))}->union(Sequence{ Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 1 })))))) }))) ; for Sequence{d}->union(Sequence{ p }) : rules do ( ans[d+1] := (dic[p+1])) ; ans[1+1][4+1] := 0 ; ans[1+1][5+1] := 0 ; ans[1+1][6+1] := 0 ; for d : Integer.subrange(2, n + 1-1) do ( ans[d+1][1+1] := ans[d+1][1+1] * (ans[d - 1+1][2+1] + ans[d - 1+1][3+1] + ans[d - 1+1][5+1] + ans[d - 1+1][6+1]) ; ans[d+1][2+1] := ans[d+1][2+1] * (ans[d - 1+1][1+1] + ans[d - 1+1][3+1] + ans[d - 1+1][4+1] + ans[d - 1+1][6+1]) ; ans[d+1][3+1] := ans[d+1][3+1] * (ans[d - 1+1][1+1] + ans[d - 1+1][2+1] + ans[d - 1+1][4+1] + ans[d - 1+1][5+1]) ; ans[d+1][4+1] := ans[d+1][4+1] * ans[d - 1+1][1+1] ; ans[d+1][5+1] := ans[d+1][5+1] * ans[d - 1+1][2+1] ; ans[d+1][6+1] := ans[d+1][6+1] * ans[d - 1+1][3+1]) ; execute ((ans[n+1])->sum() mod 10000)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys N,K=[int(x)for x in sys.stdin.readline().split(' ')] lines=sys.stdin.readlines() schedule=[0]*N for line in lines : strs=line.split(' ') schedule[int(strs[0])-1]=int(strs[1]) number=[0]*9 for i in range(9): l1=i//3 l2=i % 3 if(schedule[0]!=l2+1 and schedule[0]!=0): number[i]=0 elif(schedule[1]!=l1+1 and schedule[1]!=0): number[i]=0 else : number[i]=1 for s in schedule[2 :]: new_number=[0]*9 for i in range(9): l1=i//3 l2=i % 3 for j in range(3): new_number[i]+=number[l2*3+j]if((s==0 or s==l1+1)and not(l2==j and l1==j))else 0 for i in range(9): number[i]=new_number[i]% 10000 sum=0 for n in number : sum+=n print(sum % 10000) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := sys.stdin.readLine().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var lines : OclAny := (OclFile["System.in"]).readlines() ; var schedule : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for line : lines do ( var strs : OclAny := line.split(' ') ; schedule[("" + ((strs->first())))->toInteger() - 1+1] := ("" + ((strs[1+1])))->toInteger()) ; var number : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 9) ; for i : Integer.subrange(0, 9-1) do ( var l1 : int := i div 3 ; var l2 : int := i mod 3 ; if (schedule->first() /= l2 + 1 & schedule->first() /= 0) then ( number[i+1] := 0 ) else (if (schedule[1+1] /= l1 + 1 & schedule[1+1] /= 0) then ( number[i+1] := 0 ) else ( number[i+1] := 1 ) ) ) ; for s : schedule.subrange(2+1) do ( var new_number : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 9) ; for i : Integer.subrange(0, 9-1) do ( l1 := i div 3 ; l2 := i mod 3 ; for j : Integer.subrange(0, 3-1) do ( new_number[i+1] := new_number[i+1] + if ((s = 0 or s = l1 + 1) & not((l2 = j & l1 = j))) then number[l2 * 3 + j+1] else 0 endif)) ; for i : Integer.subrange(0, 9-1) do ( number[i+1] := new_number[i+1] mod 10000)) ; var sum : int := 0 ; for n : number do ( sum := sum + n) ; execute (sum mod 10000)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in iter(input,'-'): for _ in[0]*int(input()): n=int(input()) s=s[n :]+s[: n] print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclIterator.newOclIterator_Sequence(input, '-') do ( for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := s.subrange(n+1) + s.subrange(1,n)) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import Counter def solve(n,decided): status=Counter({(0,0,0): 1}) for d in range(1,n+1): u=Counter() pastas=range(1,4) if decided and decided[-1][0]==d : pastas=[decided.pop()[1]] for k,v in status.items(): _,d2,d3=k for p in pastas : if not d2==d3==p : u[(d2,d3,p)]+=v status=Counter({k : v % 10000 for k,v in u.items()}) return sum(status.values())% 10000 def main(args): n,k=map(int,input().split()) decided=sorted([list(map(int,input().split()))for _ in range(k)],reverse=True) ans=solve(n,decided) print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(n : OclAny, decided : OclAny) : OclAny pre: true post: true activity: var status : OclAny := Counter(Map{ Sequence{0, 0, 0} |-> 1 }) ; for d : Integer.subrange(1, n + 1-1) do ( var u : OclAny := Counter() ; var pastas : Sequence := Integer.subrange(1, 4-1) ; if decided & decided->last()->first() = d then ( pastas := Sequence{ decided->last()[1+1] } ) else skip ; for _tuple : status->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); var _anon : OclAny := null; var d2 : OclAny := null; var d3 : OclAny := null; Sequence{_anon,d2,d3} := k ; for p : pastas do ( if not(d2 = d3 & (d3 == p)) then ( u[Sequence{d2, d3, p}+1] := u[Sequence{d2, d3, p}+1] + v ) else skip)) ; status := Counter(u->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->select(_tuple | true)->collect(_tuple | Map{k |-> v mod 10000})->unionAll())) ; return (status.values())->sum() mod 10000; operation main(args : OclAny) pre: true post: true activity: var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; decided := Integer.subrange(0, k-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var ans : OclAny := solve(n, decided) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,input().split()) S=[-1]*N for _ in[0]*K : a,b=map(int,input().split()); S[a-1]=b-1 dp=[0]*9 st,nd=S[: 2] if st+1 : if nd+1 : dp[st*3+nd]=1 else : dp[st*3 : st*4]=[1]*3 elif nd+1 : dp[nd : : 3]=[1]*3 else : dp=[1]*9 for i in range(2,N): cur=S[i]; tmp=[0]*9 if cur+1 : for k in range(3): tmp[k*3+cur]=sum(dp[k : : 3])-dp[cur*4]*(k==cur) else : for cur in range(3): for k in range(3): tmp[k*3+cur]=sum(dp[k : : 3])-dp[cur*4]*(k==cur) dp=tmp[:] print(sum(dp)% 10000) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, N) ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, K) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); S[a - 1+1] := b - 1) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 9) ; var st : OclAny := null; var nd : OclAny := null; Sequence{st,nd} := S.subrange(1,2) ; if st + 1 then ( if nd + 1 then ( dp[st * 3 + nd+1] := 1 ) else ( dp.subrange(st * 3+1, st * 4) := MatrixLib.elementwiseMult(Sequence{ 1 }, 3) ) ) else (if nd + 1 then ( dp(subscript (test (logical_test (comparison (expr (atom (name nd)))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 3))))))))) := MatrixLib.elementwiseMult(Sequence{ 1 }, 3) ) else ( dp := MatrixLib.elementwiseMult(Sequence{ 1 }, 9) ) ) ; for i : Integer.subrange(2, N-1) do ( var cur : OclAny := S[i+1]; var tmp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 9) ; if cur + 1 then ( for k : Integer.subrange(0, 3-1) do ( tmp[k * 3 + cur+1] := (dp(subscript (test (logical_test (comparison (expr (atom (name k)))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 3))))))))))->sum() - dp[cur * 4+1] * (k = cur)) ) else ( for cur : Integer.subrange(0, 3-1) do ( for k : Integer.subrange(0, 3-1) do ( tmp[k * 3 + cur+1] := (dp(subscript (test (logical_test (comparison (expr (atom (name k)))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 3))))))))))->sum() - dp[cur * 4+1] * (k = cur))) ) ; dp := tmp) ; execute ((dp)->sum() mod 10000)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(dp,n,menue): if menue==0 : m1,m2=1,2 elif menue==1 : m1,m2=0,2 elif menue==2 : m1,m2=0,1 dp[n][menue][0]+=sum(dp[n-1][m1])+sum(dp[n-1][m2]) dp[n][menue][1]+=dp[n-1][menue][0] def run(): N,K=map(int,input().split()) dp=[[[0]*2 for _ in range(3)]for n in range(N)] k_li=[list(map(int,input().split()))for k in range(K)] k_li=sorted(k_li) k_i=0 ka,kb=k_li[0] if ka==1 : dp[0][kb-1][0]=1 k_i+=1 ka,kb=k_li[k_i] else : for k in range(3): dp[0][k][0]=1 for n in range(1,N): if(n+1)==ka : main(dp,n,kb-1) if k_ifirst() := dp[n+1][menue+1]->first() + (dp[n - 1+1][m1+1])->sum() + (dp[n - 1+1][m2+1])->sum() ; dp[n+1][menue+1][1+1] := dp[n+1][menue+1][1+1] + dp[n - 1+1][menue+1]->first(); operation run() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; dp := Integer.subrange(0, N-1)->select(n | true)->collect(n | (Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 2))))) ; var k_li : Sequence := Integer.subrange(0, K-1)->select(k | true)->collect(k | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; k_li := k_li->sort() ; var k_i : int := 0 ; var ka : OclAny := null; var kb : OclAny := null; Sequence{ka,kb} := k_li->first() ; if ka = 1 then ( dp->first()[kb - 1+1]->first() := 1 ; k_i := k_i + 1 ; var ka : OclAny := null; var kb : OclAny := null; Sequence{ka,kb} := k_li[k_i+1] ) else ( for k : Integer.subrange(0, 3-1) do ( dp->first()[k+1]->first() := 1) ) ; for n : Integer.subrange(1, N-1) do ( if (n + 1) = ka then ( main(dp, n, kb - 1) ; if (k_i->compareTo(K - 1)) < 0 then ( k_i := k_i + 1 ; var ka : OclAny := null; var kb : OclAny := null; Sequence{ka,kb} := k_li[k_i+1] ) else skip ) else ( for menue : Integer.subrange(0, 3-1) do ( main(dp, n, menue)) )) ; execute (((dp->last())->collect( _x | (sum)->apply(_x) ))->sum() mod 10000)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(s): tmp=ord('a') for i in s : if ord(i)>tmp : return "NO" elif ord(i)==tmp : tmp+=1 return "YES" s=input() print(solve(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := (OclFile["System.in"]).readLine() ; execute (solve(s))->display(); operation solve(s : OclAny) : OclAny pre: true post: true activity: var tmp : int := ('a')->char2byte() ; for i : s do ( if ((i)->char2byte()->compareTo(tmp)) > 0 then ( return "NO" ) else (if (i)->char2byte() = tmp then ( tmp := tmp + 1 ) else skip)) ; return "YES"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- obfuscation=list(input()) letters=list("abcdefghijklmnopqrstuvwxyz") if len(obfuscation)==1 : if obfuscation[0]=='a' : print("YES") else : print("NO") else : while len(obfuscation)>0 : if obfuscation[0]==letters[0]: while letters[0]in obfuscation : obfuscation.remove(letters[0]) letters.remove(letters[0]) else : print("NO") exit() print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var obfuscation : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var letters : Sequence := ("abcdefghijklmnopqrstuvwxyz")->characters() ; if (obfuscation)->size() = 1 then ( if obfuscation->first() = 'a' then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else ( while (obfuscation)->size() > 0 do ( if obfuscation->first() = letters->first() then ( while (obfuscation)->includes(letters->first()) do ( execute ((letters->first()) /: obfuscation)) ; execute ((letters->first()) /: letters) ) else ( execute ("NO")->display() ; exit() )) ; execute ("YES")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline s=input()[:-1] a=97 for i in s : if i>chr(a): print("NO") break elif i==chr(a): a+=1 else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var s : OclAny := input()->front() ; var a : int := 97 ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name s))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name i)))) > (comparison (expr (atom (name chr)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name i)))) == (comparison (expr (atom (name chr)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name a)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(s): alfabet="abcdefghijklmnopqrstuvwxyzЯ" for i in s : if i>alfabet[0]: return "NO" elif i==alfabet[0]: alfabet=alfabet[1 :] else : pass return "YES" s=input() print(f(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := (OclFile["System.in"]).readLine() ; execute (f(s))->display(); operation f(s : OclAny) : OclAny pre: true post: true activity: var alfabet : String := "abcdefghijklmnopqrstuvwxyz?" ; for i : s do ( if (i->compareTo(alfabet->first())) > 0 then ( return "NO" ) else (if i = alfabet->first() then ( alfabet := alfabet->tail() ) else ( skip ) ) ) ; return "YES"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) numbers=list(map(int,input().split())) target=None length=len(numbers) for i in range(k-1,length): if numbers[i]!=numbers[k-1]: print(-1) exit() else : target=numbers[k-1] index=0 if target!=None : for i in range(k-2,-1,-1): if numbers[i]!=target : index=i+1 break print(index) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var numbers : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var target : OclAny := null ; var length : int := (numbers)->size() ; for i : Integer.subrange(k - 1, length-1) do ( if numbers[i+1] /= numbers[k - 1+1] then ( execute (-1)->display() ; exit() ) else ( target := numbers[k - 1+1] )) ; var index : int := 0 ; if target /= null then ( for i : Integer.subrange(-1 + 1, k - 2)->reverse() do ( if numbers[i+1] /= target then ( index := i + 1 ; break ) else skip) ) else skip ; execute (index)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=ord('a')-1 for s in map(ord,input()): if s>c+1 : print('NO') exit() c=max(c,s) print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : double := ('a')->char2byte() - 1 ; for s : ((OclFile["System.in"]).readLine())->collect( _x | (ord)->apply(_x) ) do ( if (s->compareTo(c + 1)) > 0 then ( execute ('NO')->display() ; exit() ) else skip ; c := Set{c, s}->max()) ; execute ('YES')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools def solve(a,b): if a.count("1")*2>=len(a)and b.count("1")*2>=len(b): ch="1" other="0" else : ch="0" other="1" res=[] i=0 j=0 ilast=-1 jlast=-1 while i=n and nb1>=n or na1<=n and nb1<=n : res=solve(a,b) elif na1>=n and nc1>=n or na1<=n and nc1<=n : res=solve(a,c) elif nb1>=n and nc1>=n or nb1<=n and nc1<=n : res=solve(b,c) else : raise RuntimeError("unexpected") print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := (OclFile["System.in"]).readLine() ; b := (OclFile["System.in"]).readLine() ; var c : String := (OclFile["System.in"]).readLine() ; var na1 : int := a->count("1") ; var nb1 : int := b->count("1") ; var nc1 : int := c->count("1") ; res := null ; if (na1->compareTo(n)) >= 0 & (nb1->compareTo(n)) >= 0 or (na1->compareTo(n)) <= 0 & (nb1->compareTo(n)) <= 0 then ( res := solve(a, b) ) else (if (na1->compareTo(n)) >= 0 & (nc1->compareTo(n)) >= 0 or (na1->compareTo(n)) <= 0 & (nc1->compareTo(n)) <= 0 then ( res := solve(a, c) ) else (if (nb1->compareTo(n)) >= 0 & (nc1->compareTo(n)) >= 0 or (nb1->compareTo(n)) <= 0 & (nc1->compareTo(n)) <= 0 then ( res := solve(b, c) ) else ( error RuntimeError.newRuntimeError("unexpected") ) ) ) ; execute (res)->display()); operation solve(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a->count("1") * 2->compareTo((a)->size())) >= 0 & (b->count("1") * 2->compareTo((b)->size())) >= 0 then ( var ch : String := "1" ; var other : String := "0" ) else ( ch := "0" ; other := "1" ) ; var res : Sequence := Sequence{} ; var i : int := 0 ; var j : int := 0 ; var ilast : int := -1 ; var jlast : int := -1 ; while (i->compareTo((a)->size())) < 0 & (j->compareTo((b)->size())) < 0 do ( while (i->compareTo((a)->size())) < 0 & a[i+1] /= ch do ( i := i + 1) ; while (j->compareTo((b)->size())) < 0 & b[j+1] /= ch do ( j := j + 1) ; execute ((StringLib.nCopies(other, Set{i - ilast - 1, j - jlast - 1}->max())) : res) ; if i /= (a)->size() or j /= (b)->size() then ( execute ((ch) : res) ) else skip ; ilast := i ; jlast := j ; i := i + 1 ; j := j + 1) ; while (i->compareTo((a)->size())) < 0 do ( execute ((a[i+1]) : res) ; i := i + 1) ; while (j->compareTo((b)->size())) < 0 do ( execute ((b[j+1]) : res) ; j := j + 1) ; return StringLib.sumStringsWithSeparator((res), ''); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline t=int(input()) for _ in range(t): n=int(input()) s=[list(input().rstrip())for _ in range(3)] for l in range(2): x,y=str(l),str(l ^ 1) for i,j in[(0,1),(0,2),(1,2)]: a,b=s[i],s[j] a0,b0=a.count(x),b.count(x) a1,b1=2*n-a0,2*n-b0 m=max(a0,b0) if m+a1+b1<=3*n : c=[0]*(m+1) c0=0 for k in a : if k==x : c0+=1 else : c[c0]+=1 c0=0 for k in b : if k==x : c0+=1 else : c[c0]+=1 ans=[y*c[0]] for i in range(1,m+1): ans.append(x) ans.append(y*c[i]) ans.append("0"*(3*n-len("".join(ans)))) break print("".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | ((input().rstrip()))) ; for l : Integer.subrange(0, 2-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{("" + ((l))),("" + ((MathLib.bitwiseXor(l, 1))))} ; for _tuple : Sequence{Sequence{0, 1}}->union(Sequence{Sequence{0, 2}}->union(Sequence{ Sequence{1, 2} })) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{s[i+1],s[j+1]} ; var a0 : OclAny := null; var b0 : OclAny := null; Sequence{a0,b0} := Sequence{a->count(x),b->count(x)} ; var a1 : OclAny := null; var b1 : OclAny := null; Sequence{a1,b1} := Sequence{2 * n - a0,2 * n - b0} ; var m : OclAny := Set{a0, b0}->max() ; if (m + a1 + b1->compareTo(3 * n)) <= 0 then ( var c : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (m + 1)) ; var c0 : int := 0 ; for k : a do ( if k = x then ( c0 := c0 + 1 ) else ( c[c0+1] := c[c0+1] + 1 )) ; c0 := 0 ; for k : b do ( if k = x then ( c0 := c0 + 1 ) else ( c[c0+1] := c[c0+1] + 1 )) ; var ans : Sequence := Sequence{ y * c->first() } ; for i : Integer.subrange(1, m + 1-1) do ( execute ((x) : ans) ; execute ((y * c[i+1]) : ans)) ; execute ((StringLib.nCopies("0", (3 * n - (StringLib.sumStringsWithSeparator((ans), ""))->size()))) : ans) ; break ) else skip)) ; execute (StringLib.sumStringsWithSeparator((ans), ""))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(input()) t=0 n=len(s) acc_start=False acc_c1=False start_ind=0 c1_ind=0 while tcharacters() ; var t : int := 0 ; var n : int := (s)->size() ; var acc_start : boolean := false ; var acc_c1 : boolean := false ; var start_ind : int := 0 ; var c1_ind : int := 0 ; while (t->compareTo((s)->size())) < 0 & not((Sequence{acc_start}->union(Sequence{ acc_c1 }))->forAll( _x | _x = true )) do ( if not(acc_start) then ( if s[t+1] = '[' then ( acc_start := true ; start_ind := t ) else skip ) else (if not(acc_c1) then ( if s[t+1] = ':' then ( acc_c1 := true ; c1_ind := t ) else skip ) else skip) ; t := t + 1) ; t := 0 ; var acc_c2 : boolean := false ; var acc_end : boolean := false ; var c2_ind : int := 0 ; var end_ind : int := 0 ; while (t->compareTo((s)->size())) < 0 & not((Sequence{acc_end}->union(Sequence{ acc_c2 }))->forAll( _x | _x = true )) do ( if not(acc_end) then ( if s[MathLib.bitwiseNot(t)+1] = ']' then ( acc_end := true ; end_ind := n + MathLib.bitwiseNot(t) ) else skip ) else (if not(acc_c2) then ( if s[MathLib.bitwiseNot(t)+1] = ':' then ( acc_c2 := true ; c2_ind := n + MathLib.bitwiseNot(t) ) else skip ) else skip) ; t := t + 1) ; if (Sequence{acc_start}->union(Sequence{acc_c1}->union(Sequence{acc_c2}->union(Sequence{ acc_end }))))->forAll( _x | _x = true ) & (start_ind->compareTo(c1_ind)) < 0 & (c1_ind < c2_ind) & (c2_ind < end_ind) then ( execute (4 + s.subrange(c1_ind + 1+1, c2_ind)->count('|'))->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import collections n=int(input()) a=collections.Counter(list(map(int,sys.stdin.readline().split()))) q=[0,0] for v,k in a.items(): if k>=4 : q.append(v) if k>=2 : q.append(v) q.sort() print(q[-1]*q[-2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := .Counter(((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var q : Sequence := Sequence{0}->union(Sequence{ 0 }) ; for _tuple : a->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var k : OclAny := _tuple->at(_indx); if k >= 4 then ( execute ((v) : q) ) else skip ; if k >= 2 then ( execute ((v) : q) ) else skip) ; q := q->sort() ; execute (q->last() * q->front()->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n=int(input()) a=list(map(int,input().split())) cnt=Counter(a) cand=[] for k,v in cnt.items(): if 2<=v<4 : cand.append([k,2]) elif 4<=v : cand.append([k,2]) cand.append([k,2]) cand=sorted(cand,reverse=True) print(cand[0][0]*cand[1][0]if len(cand)>=2 else 0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : OclAny := Counter(a) ; var cand : Sequence := Sequence{} ; for _tuple : cnt->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if 2 <= v & (v < 4) then ( execute ((Sequence{k}->union(Sequence{ 2 })) : cand) ) else (if 4 <= v then ( execute ((Sequence{k}->union(Sequence{ 2 })) : cand) ; execute ((Sequence{k}->union(Sequence{ 2 })) : cand) ) else skip)) ; cand := cand->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; execute (if (cand)->size() >= 2 then cand->first()->first() * cand[1+1]->first() else 0 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=[int(i)for i in input().split()] A=sorted(A,reverse=True) l=0 r=0 t=10**9+7 for i in range(N): s=A[i] if s==t : if l==0 : l=s t=10**9+7 elif r==0 : r=s t=10**9+7 continue t=A[i] print(l*r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; A := A->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var l : int := 0 ; var r : int := 0 ; var t : double := (10)->pow(9) + 7 ; for i : Integer.subrange(0, N-1) do ( var s : OclAny := A[i+1] ; if s = t then ( if l = 0 then ( l := s ; t := (10)->pow(9) + 7 ) else (if r = 0 then ( r := s ; t := (10)->pow(9) + 7 ) else skip) ; continue ) else skip ; t := A[i+1]) ; execute (l * r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter def main(): n=int(input()) lst=list(map(int,input().rstrip().split())) cnt=sorted(Counter(lst).most_common(),reverse=True) ans=[] for i,j in cnt : if len(ans)>=2 : break if j>=4 : ans+=[i]+[i] elif j>=2 : ans+=[i] print(0 if ans==[]else ans[0]*ans[1]) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := ((input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : Sequence := Counter(lst).most_common()->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var ans : Sequence := Sequence{} ; for _tuple : cnt do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if (ans)->size() >= 2 then ( break ) else skip ; if j >= 4 then ( ans := ans + Sequence{ i }->union(Sequence{ i }) ) else (if j >= 2 then ( ans := ans + Sequence{ i } ) else skip)) ; execute (if ans = Sequence{} then 0 else ans->first() * ans[1+1] endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter N=int(input()) A=Counter(list(map(int,input().split()))) A=sorted(A.items(),reverse=True) ans=list() for key,value in A : if value>=4 : if len(ans)==0 : ans.append(key) ans.append(key) break else : ans.append(key) break elif value>=2 : if len(ans)==0 : ans.append(key) else : ans.append(key) break if len(ans)<=1 : print(0) else : print(ans[0]*ans[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : OclAny := Counter(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; A := A->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var ans : Sequence := () ; for _tuple : A do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); if value >= 4 then ( if (ans)->size() = 0 then ( execute ((key) : ans) ; execute ((key) : ans) ; break ) else ( execute ((key) : ans) ; break ) ) else (if value >= 2 then ( if (ans)->size() = 0 then ( execute ((key) : ans) ) else ( execute ((key) : ans) ; break ) ) else skip)) ; if (ans)->size() <= 1 then ( execute (0)->display() ) else ( execute (ans->first() * ans[1+1])->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from os.path import exists if exists("test.txt"): sys.stdin=open("test.txt","r") for _ in range(int(input())): n=int(input()) print(n+n//2*2+n//3*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if exists("test.txt") then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("test.txt")) ) else skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n + n div 2 * 2 + n div 3 * 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) seq=list(map(int,input().split())) prev=seq[-1] for i in range(n-2,-1,-1): if prev!=seq[i]: break prev=seq[i] else : print(0) exit() if k-1>i : print(i+1) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var seq : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var prev : OclAny := seq->last() ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (atom - (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name prev)))) != (comparison (expr (atom (name seq)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name prev)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name seq)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name exit)) (trailer (arguments ( ))))))))))))))) ; if (k - 1->compareTo(i)) > 0 then ( execute (i + 1)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for num in[*map(int,open(0))][1 :]: print((num//3+num//2)*2+num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for num : (OclFile.newOclFile_Write(OclFile.newOclFile(0)))->collect( _x | (OclType["int"])->apply(_x) )->tail() do ( execute ((num div 3 + num div 2) * 2 + num)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for n in[*map(int,open(0))][1 :]: print((n//3+n//2)*2+n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for n : (OclFile.newOclFile_Write(OclFile.newOclFile(0)))->collect( _x | (OclType["int"])->apply(_x) )->tail() do ( execute ((n div 3 + n div 2) * 2 + n)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import string from typing import Optional def mapped_read(cast): return map(cast,input().split()) def read_list(cast): return list(mapped_read(cast)) def lcm(a,b): return a//math.gcd(a,b)*b def solve(): n,=mapped_read(int) print(n+n//2*2+n//3*2) if __name__=="__main__" : n=1 n=int(input()) for _ in range(n): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( var n : int := 1 ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( solve()) ) else skip; operation mapped_read(cast : OclAny) : OclAny pre: true post: true activity: return (input().split())->collect( _x | (cast)->apply(_x) ); operation read_list(cast : OclAny) : OclAny pre: true post: true activity: return (mapped_read(cast)); operation lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a div (a)->gcd(b) * b; operation solve() pre: true post: true activity: (testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,)} := mapped_read(OclType["int"]) ; execute (n + n div 2 * 2 + n div 3 * 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) c=n+2*(n//2+n//3) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := n + 2 * (n div 2 + n div 3) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() t=s[: :-1] n=len(s) flag=0 lis=[] ind1,ind2,ind3,ind4=None,None,None,None for i in range(n): if s[i]=='[' : lis.append(i) ind1=i break if ind1==None : print(-1) exit() for i in range(ind1+1,n): if s[i]==':' : lis.append(i) ind2=i break if ind2==None : print(-1) exit() for i in reversed(range(ind2+1,n)): if s[i]==']' : lis.append(i) ind3=i break print() if ind3==None : print(-1) exit() for i in reversed(range(ind2+1,ind3)): if s[i]==':' : lis.append(i) ind4=i break if ind4==None : print(-1) exit() if len(lis)>=4 : if lis[0]size() ; var flag : int := 0 ; var lis : Sequence := Sequence{} ; var ind1 : OclAny := null; var ind2 : OclAny := null; var ind3 : OclAny := null; var ind4 : OclAny := null; Sequence{ind1,ind2,ind3,ind4} := Sequence{null,null,null,null} ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = '[' then ( execute ((i) : lis) ; var ind1 : OclAny := i ; break ) else skip) ; if ind1 = null then ( execute (-1)->display() ; exit() ) else skip ; for i : Integer.subrange(ind1 + 1, n-1) do ( if s[i+1] = ':' then ( execute ((i) : lis) ; var ind2 : OclAny := i ; break ) else skip) ; if ind2 = null then ( execute (-1)->display() ; exit() ) else skip ; for i : (Integer.subrange(ind2 + 1, n-1))->reverse() do ( if s[i+1] = ']' then ( execute ((i) : lis) ; var ind3 : OclAny := i ; break ) else skip ; execute (->display()) ; if ind3 = null then ( execute (-1)->display() ; exit() ) else skip ; for i : (Integer.subrange(ind2 + 1, ind3-1))->reverse() do ( if s[i+1] = ':' then ( execute ((i) : lis) ; var ind4 : OclAny := i ; break ) else skip) ; if ind4 = null then ( execute (-1)->display() ; exit() ) else skip ; if (lis)->size() >= 4 then ( if (lis->first()->compareTo(lis[1+1])) < 0 & (lis[1+1] < lis[3+1]) & (lis[3+1] < lis[2+1]) then ( execute (4 + s.subrange(lis[1+1]+1, lis[3+1] + 1)->count('|'))->display() ) else skip ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) ans=[] for i in range(2,n+1): c=1 for j in range(2,int(math.sqrt(i))+1): if i % j==0 : c=0 break if c : ans.append(i) ans2=[] for i in ans : ans2.append(i) tem=int(math.log(n,i)) for j in range(2,tem+1): ans2.append(i**j) print(len(ans2)) print(*ans2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(2, n + 1-1) do ( var c : int := 1 ; for j : Integer.subrange(2, ("" + (((i)->sqrt())))->toInteger() + 1-1) do ( if i mod j = 0 then ( c := 0 ; break ) else skip) ; if c then ( execute ((i) : ans) ) else skip) ; var ans2 : Sequence := Sequence{} ; for i : ans do ( execute ((i) : ans2) ; var tem : int := ("" + (((n, i)->log())))->toInteger() ; for j : Integer.subrange(2, tem + 1-1) do ( execute (((i)->pow(j)) : ans2))) ; execute ((ans2)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans2))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,s=int(input())+1,set() for i in range(2,n): for j in range(2,n): if not i % j : k=i while not k % j : k//=j if k==1 : s.add(i) break print(len(s),*s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger() + 1,Set{}->union(())} ; for i : Integer.subrange(2, n-1) do ( for j : Integer.subrange(2, n-1) do ( if not(i mod j) then ( var k : OclAny := i ; while not(k mod j) do ( k := k div j) ; if k = 1 then ( execute ((i) : s) ) else skip ; break ) else skip)) ; execute ((s)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) questions=[] for i in range(2,n+1): l=list(i % q for q in questions) if all(l): x=i while x<=n : questions.append(x) x*=i print(len(questions)) print(' '.join(str(q)for q in questions)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var questions : Sequence := Sequence{} ; for i : Integer.subrange(2, n + 1-1) do ( var l : Sequence := ((argument (test (logical_test (comparison (expr (expr (atom (name i))) % (expr (atom (name q))))))) (comp_for for (exprlist (expr (atom (name q)))) in (logical_test (comparison (expr (atom (name questions)))))))) ; if (l)->forAll( _x | _x = true ) then ( var x : OclAny := i ; while (x->compareTo(n)) <= 0 do ( execute ((x) : questions) ; x := x * i) ) else skip) ; execute ((questions)->size())->display() ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name q)))))))) ))))))) (comp_for for (exprlist (expr (atom (name q)))) in (logical_test (comparison (expr (atom (name questions)))))))), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math arr=[] def SieveOfEratosthenes(n): prime=[True for i in range(n+1)] p=2 while(p*p<=n): if(prime[p]==True): for i in range(p*2,n+1,p): prime[i]=False p+=1 prime[0]=False prime[1]=False for p in range(n+1): if prime[p]: arr.append(p) n=int(input()) SieveOfEratosthenes(n) final=[] for i in arr : x=int(math.log(n,i)) for j in range(1,x+1): final.append(pow(i,j)) print(len(final)) print(*final) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var arr : Sequence := Sequence{} ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; SieveOfEratosthenes(n) ; var final : Sequence := Sequence{} ; for i : arr do ( var x : int := ("" + (((n, i)->log())))->toInteger() ; for j : Integer.subrange(1, x + 1-1) do ( execute (((i)->pow(j)) : final))) ; execute ((final)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name final))))))))->display(); operation SieveOfEratosthenes(n : OclAny) pre: true post: true activity: var prime : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (true)) ; var p : int := 2 ; while ((p * p->compareTo(n)) <= 0) do ( if (prime[p+1] = true) then ( for i : Integer.subrange(p * 2, n + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip ; p := p + 1) ; prime->first() := false ; prime[1+1] := false ; for p : Integer.subrange(0, n + 1-1) do ( if prime[p+1] then ( execute ((p) : arr) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math seive=[1]*(1001) seive[0]=seive[1]=0 for i in range(2,int(math.sqrt(1001))): if seive[i]==1 : for j in range(i*i,1001,i): seive[j]=0 n=int(input()) l=[] for i in range(2,n+1): if seive[i]==1 : x=i while x<=n : if x not in l : l.append(x) x*=i print(len(l)) for i in l : print(i,end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var seive : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (1001)) ; seive->first() := 0; var seive[1+1] : int := 0 ; for i : Integer.subrange(2, ("" + (((1001)->sqrt())))->toInteger()-1) do ( if seive[i+1] = 1 then ( for j : Integer.subrange(i * i, 1001-1)->select( $x | ($x - i * i) mod i = 0 ) do ( seive[j+1] := 0) ) else skip) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; for i : Integer.subrange(2, n + 1-1) do ( if seive[i+1] = 1 then ( var x : OclAny := i ; while (x->compareTo(n)) <= 0 do ( if (l)->excludes(x) then ( execute ((x) : l) ) else skip ; x := x * i) ) else skip) ; execute ((l)->size())->display() ; for i : l do ( execute (i)->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) sequence=[int(i)for i in input().split()] flag=0 last=0 same=sequence[k-1] for i in range(k-1): if(same!=sequence[i]): last=i+1 for i in range(k-1,n): if sequence[i]!=same : flag=1 print(-1) break if flag==0 : print(last) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sequence : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var flag : int := 0 ; var last : int := 0 ; var same : OclAny := sequence[k - 1+1] ; for i : Integer.subrange(0, k - 1-1) do ( if (same /= sequence[i+1]) then ( last := i + 1 ) else skip) ; for i : Integer.subrange(k - 1, n-1) do ( if sequence[i+1] /= same then ( flag := 1 ; execute (-1)->display() ; break ) else skip) ; if flag = 0 then ( execute (last)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : w=int(input()) if w==-1 : break if w<=10 : mon=1150 elif 10toInteger() ; if w = -1 then ( break ) else skip ; if w <= 10 then ( var mon : int := 1150 ) else (if 10 < w & (w <= 20) then ( mon := 1150 + (w - 10) * 125 ) else (if 20 < w & (w <= 30) then ( mon := 1150 + 1250 + (w - 20) * 140 ) else ( mon := 1150 + 1250 + 1400 + (w - 30) * 160 ) ) ) ; execute (4280 - mon)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def water_charges(w): progressive_rate={(float('inf'),30): 160,(30,20): 140,(20,10): 125,(10,0): 0} charge=basic_charge=1150 for(upper,lower),rate in progressive_rate.items(): usage=min(w,upper)-lower if 0toInteger() ; if w = -1 then ( break ) else skip ; execute (last_water_charges - water_charges(w))->display()); operation water_charges(w : OclAny) : OclAny pre: true post: true activity: var progressive_rate : Map := Map{ Sequence{("" + (('inf')))->toReal(), 30} |-> 160 }->union(Map{ Sequence{30, 20} |-> 140 }->union(Map{ Sequence{20, 10} |-> 125 }->union(Map{ Sequence{10, 0} |-> 0 }))) ; var charge : OclAny := 1150; var basic_charge : int := 1150 ; for _tuple : progressive_rate->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var Sequence{upper, lower} : OclAny := _tuple->at(_indx); _indx := _indx + 1; var rate : OclAny := _tuple->at(_indx); var usage : double := Set{w, upper}->min() - lower ; if 0 < usage then ( charge := charge + usage * rate ) else skip) ; return charge; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import exit while(True): N=int(input()) if N<0 : exit() elif N<=10 : temp=1150 print(-(temp-4280)) elif 10toInteger() ; if N < 0 then ( exit() ) else (if N <= 10 then ( var temp : int := 1150 ; execute (-(temp - 4280))->display() ) else (if 10 < N & (N <= 20) then ( temp := (N - 10) * 125 + 1150 ; execute (-(temp - 4280))->display() ) else (if 20 < N & (N <= 30) then ( temp := (N - 20) * 140 + 10 * 125 + 1150 ; execute (-(temp - 4280))->display() ) else ( temp := (N - 30) * 160 + 1400 + 10 * 125 + 1150 ; execute (-(temp - 4280))->display() ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,fractions PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") def water_bill(n): if n<=10 : return 4280-1150 elif n<=20 : return 4280-(1150+(n-10)*125) elif n<=30 : return 4280-(1150+1250+(n-20)*140) else : return 4280-(1150+1250+1400+(n-30)*160) while True : n=int(input()) if n==-1 : break print(water_bill(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; skip ; while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = -1 then ( break ) else skip ; execute (water_bill(n))->display()); operation water_bill(n : OclAny) : OclAny pre: true post: true activity: if n <= 10 then ( return 4280 - 1150 ) else (if n <= 20 then ( return 4280 - (1150 + (n - 10) * 125) ) else (if n <= 30 then ( return 4280 - (1150 + 1250 + (n - 20) * 140) ) else ( return 4280 - (1150 + 1250 + 1400 + (n - 30) * 160) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if n==-1 : break w=1150 if n>30 : w+=(n-30)*160 n-=n-30 if n>20 : w+=(n-20)*140 n-=n-20 if n>10 : w+=(n-10)*125 print(4280-w) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = -1 then ( break ) else skip ; var w : int := 1150 ; if n > 30 then ( w := w + (n - 30) * 160 ; n := n - n - 30 ) else skip ; if n > 20 then ( w := w + (n - 20) * 140 ; n := n - n - 20 ) else skip ; if n > 10 then ( w := w + (n - 10) * 125 ) else skip ; execute (4280 - w)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() stack=[] output='' count=0 k=0 m=[] for i in range(0,len(a)): if a[i]=='[' : stack.append(i) if a[i]==']' : m.append(i) if len(stack)==0 or len(m)==0 : print(-1) elif m[-1]stack[0]: a1=stack[0] a2=m[-1] g=a[a1 : a2+1] t=[] f=[] for ele in range(0,len(g)): if g[ele]==':' : f.append(ele) if len(f)>=2 : count=0 a3=f[0] a4=f[-1] n=g[a3 : a4+1] for ele in n : if ele=='|' : count=count+1 print(count+2+2) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var stack : Sequence := Sequence{} ; var output : String := '' ; var count : int := 0 ; var k : int := 0 ; var m : Sequence := Sequence{} ; for i : Integer.subrange(0, (a)->size()-1) do ( if a[i+1] = '[' then ( execute ((i) : stack) ) else skip ; if a[i+1] = ']' then ( execute ((i) : m) ) else skip) ; if (stack)->size() = 0 or (m)->size() = 0 then ( execute (-1)->display() ) else (if (m->last()->compareTo(stack->first())) < 0 then ( execute (-1)->display() ) else (if (m->last()->compareTo(stack->first())) > 0 then ( var a1 : OclAny := stack->first() ; var a2 : OclAny := m->last() ; var g : OclAny := a.subrange(a1+1, a2 + 1) ; var t : Sequence := Sequence{} ; var f : Sequence := Sequence{} ; for ele : Integer.subrange(0, (g)->size()-1) do ( if g[ele+1] = ':' then ( execute ((ele) : f) ) else skip) ; if (f)->size() >= 2 then ( count := 0 ; var a3 : String := f->first() ; var a4 : String := f->last() ; var n : OclAny := g.subrange(a3+1, a4 + 1) ; for ele : n do ( if ele = '|' then ( count := count + 1 ) else skip) ; execute (count + 2 + 2)->display() ) else ( execute (-1)->display() ) ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countWays(n): count=0 i=1 while((i*i)display(); operation countWays(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var i : int := 1 ; while (((i * i)->compareTo(n)) < 0) do ( if (n mod i = 0) then ( count := count + 1 ) else skip ; i := i + 1) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=26 def targetstring(str1,str2): l1=len(str1) l2=len(str2) if(l1!=l2): return False map=[0]*MAX for i in range(l1): map[ord(str1[i])-ord('a')]+=1 for i in range(l2): map[ord(str2[i])-ord('a')]-=1 if(map[ord(str2[i])-ord('a')]<0): return False return True if __name__=="__main__" : str1="geeksforgeeks" str2="geegeeksksfor" if(targetstring(str1,str2)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 26 ; skip ; if __name__ = "__main__" then ( str1 := "geeksforgeeks" ; str2 := "geegeeksksfor" ; if (targetstring(str1, str2)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; operation targetstring(str1 : OclAny, str2 : OclAny) : OclAny pre: true post: true activity: var l1 : int := (str1)->size() ; var l2 : int := (str2)->size() ; if (l1 /= l2) then ( return false ) else skip ; var map : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX) ; for i : Integer.subrange(0, l1-1) do ( ([(str1[i+1])->char2byte() - ('a')->char2byte()+1]`third)->collect( _x | ([(str1[i+1])->char2byte() - ('a')->char2byte()+1])->apply(_x) ) := ([(str1[i+1])->char2byte() - ('a')->char2byte()+1]`third)->collect( _x | ([(str1[i+1])->char2byte() - ('a')->char2byte()+1])->apply(_x) ) + 1) ; for i : Integer.subrange(0, l2-1) do ( ([(str2[i+1])->char2byte() - ('a')->char2byte()+1]`third)->collect( _x | ([(str2[i+1])->char2byte() - ('a')->char2byte()+1])->apply(_x) ) := ([(str2[i+1])->char2byte() - ('a')->char2byte()+1]`third)->collect( _x | ([(str2[i+1])->char2byte() - ('a')->char2byte()+1])->apply(_x) ) - 1 ; if (([(str2[i+1])->char2byte() - ('a')->char2byte()+1]`third)->collect( _x | ([(str2[i+1])->char2byte() - ('a')->char2byte()+1])->apply(_x) ) < 0) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numberOfDiagonals(n): return n*(n-3)/2 def main(): n=5 print(n," sided convex polygon have ") print(numberOfDiagonals(n)," diagonals") if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation numberOfDiagonals(n : OclAny) : OclAny pre: true post: true activity: return n * (n - 3) / 2; operation main() pre: true post: true activity: n := 5 ; execute (n)->display() ; execute (numberOfDiagonals(n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calc_start(mid): cnt=-1 i=1 while 10**itoInteger() - 1 ; var left : OclAny := null; var right : OclAny := null; Sequence{left,right} := Sequence{1,(10)->pow(18)} ; while (left + 1->compareTo(right)) < 0 do ( mid := (left + right) div 2 ; var start : OclAny := calc_start(mid) ; if (start->compareTo(N)) <= 0 then ( var left : OclAny := mid ) else ( var right : OclAny := mid )) ; var ans : String := '' ; for i : Integer.subrange(left, left + 30-1) do ( var tmp : String := '' ; if i mod 3 = 0 then ( tmp := tmp + "Fizz" ) else skip ; if i mod 5 = 0 then ( tmp := tmp + "Buzz" ) else skip ; if not(tmp = "") then ( tmp := ("" + ((i))) ) else skip ; ans := ans + tmp) ; start := calc_start(left) ; execute (ans.subrange(N - start+1, N - start + 20))->display(); operation calc_start(mid : OclAny) : OclAny pre: true post: true activity: var cnt : int := -1 ; var i : int := 1 ; while ((10)->pow(i)->compareTo(mid)) < 0 do ( cnt := cnt + i * ((10)->pow(i) - (10)->pow((i - 1))) ; var fif : double := ((10)->pow(i) - 1) div 15 - ((10)->pow((i - 1)) - 1) div 15 ; var three : double := ((10)->pow(i) - 1) div 3 - ((10)->pow((i - 1)) - 1) div 3 ; var five : double := ((10)->pow(i) - 1) div 5 - ((10)->pow((i - 1)) - 1) div 5 ; cnt := cnt + (three + five) * 4 - (three + five - fif) * i ; i := i + 1) ; cnt := cnt + i * (mid - (10)->pow((i - 1))) ; fif := (mid - 1) div 15 - ((10)->pow((i - 1)) - 1) div 15 ; three := (mid - 1) div 3 - ((10)->pow((i - 1)) - 1) div 3 ; five := (mid - 1) div 5 - ((10)->pow((i - 1)) - 1) div 5 ; cnt := cnt + (three + five) * 4 - (three + five - fif) * i ; return cnt + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fun(n): return n &(n-1) n=7 print("The number after unsetting the rightmost set bit",fun(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 7 ; execute ("The number after unsetting the rightmost set bit")->display(); operation fun(n : OclAny) : OclAny pre: true post: true activity: return MathLib.bitwiseAnd(n, (n - 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fizzbuzz_length(n): f3=0 f5=0 f15=0 folen=0 keta=1 while True : ub=10**keta-1 lim=min(n,ub) folen+=keta*(lim-10**(keta-1)+1-(lim//3-f3)-(lim//5-f5)+(lim//15-f15)) f3=lim//3 f5=lim//5 f15=lim//15 if n<=ub : break keta+=1 return folen+4*(f3+f5) def fizzbuzz(i): if i % 15==0 : return "FizzBuzz" elif i % 3==0 : return "Fizz" elif i % 5==0 : return "Buzz" else : return str(i) s=int(input()) lb=0 ub=s while ub-lb>1 : m=(ub+lb)//2 if s<=fizzbuzz_length(m): ub=m else : lb=m ans="" for i in range(ub,ub+20): ans+=fizzbuzz(i) pos=s-fizzbuzz_length(ub-1)-1 print(ans[pos : pos+20]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lb : int := 0 ; ub := s ; while ub - lb > 1 do ( var m : int := (ub + lb) div 2 ; if (s->compareTo(fizzbuzz_length(m))) <= 0 then ( ub := m ) else ( lb := m )) ; var ans : String := "" ; for i : Integer.subrange(ub, ub + 20-1) do ( ans := ans + fizzbuzz(i)) ; var pos : double := s - fizzbuzz_length(ub - 1) - 1 ; execute (ans.subrange(pos+1, pos + 20))->display(); operation fizzbuzz_length(n : OclAny) : OclAny pre: true post: true activity: var f3 : int := 0 ; var f5 : int := 0 ; var f15 : int := 0 ; var folen : int := 0 ; var keta : int := 1 ; while true do ( var ub : double := (10)->pow(keta) - 1 ; var lim : OclAny := Set{n, ub}->min() ; folen := folen + keta * (lim - (10)->pow((keta - 1)) + 1 - (lim div 3 - f3) - (lim div 5 - f5) + (lim div 15 - f15)) ; f3 := lim div 3 ; f5 := lim div 5 ; f15 := lim div 15 ; if (n->compareTo(ub)) <= 0 then ( break ) else skip ; keta := keta + 1) ; return folen + 4 * (f3 + f5); operation fizzbuzz(i : OclAny) : OclAny pre: true post: true activity: if i mod 15 = 0 then ( return "FizzBuzz" ) else (if i mod 3 = 0 then ( return "Fizz" ) else (if i mod 5 = 0 then ( return "Buzz" ) else ( return ("" + ((i))) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(n): i=0 while(10**i<=n): i+=1 i-=1 return 8 if n % 15==0 else 4 if n % 3==0 or n % 5==0 else i def fizzbuzzlen(n): if n==0 : return 0 i=0 ans=0 while(10**i<=n): start=10**i end=min(10**(i+1)-1,n) numbase=(end-start+1) num3=end//3-(start-1)//3 num5=end//5-(start-1)//5 num15=end//15-(start-1)//15 numbase=numbase-num3-num5+num15 ans+=(i+1)*numbase+4*num3+4*num5 i+=1 return ans n=int(input()) l=0 r=10**18+1 while(l+1!=r): med=(l+r)//2 if(fizzbuzzlen(med)toInteger() ; var l : int := 0 ; var r : double := (10)->pow(18) + 1 ; while (l + 1 /= r) do ( var med : int := (l + r) div 2 ; if ((fizzbuzzlen(med)->compareTo(n)) < 0) then ( l := med ) else ( r := med )) ; var s : String := StringLib.sumStringsWithSeparator((Integer.subrange(l + 1, l + 21-1)->select(i | true)->collect(i | (if i = 0 then "0" else if i mod 15 = 0 then "FizzBuzz" else if i mod 5 = 0 then "Buzz" else if i mod 3 = 0 then "Fizz" else ("" + ((i))) endif endif endif endif))), "") ; execute (s.subrange(n - fizzbuzzlen(l) - 1+1, n - fizzbuzzlen(l) - 1 + 20))->display(); operation f(n : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; while (((10)->pow(i)->compareTo(n)) <= 0) do ( i := i + 1) ; i := i - 1 ; return if n mod 15 = 0 then 8 else if n mod 3 = 0 or n mod 5 = 0 then 4 else i endif endif; operation fizzbuzzlen(n : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( return 0 ) else skip ; i := 0 ; var ans : int := 0 ; while (((10)->pow(i)->compareTo(n)) <= 0) do ( var start : double := (10)->pow(i) ; var end : OclAny := Set{(10)->pow((i + 1)) - 1, n}->min() ; var numbase : double := (end - start + 1) ; var num3 : double := end div 3 - (start - 1) div 3 ; var num5 : double := end div 5 - (start - 1) div 5 ; var num15 : double := end div 15 - (start - 1) div 15 ; numbase := numbase - num3 - num5 + num15 ; ans := ans + (i + 1) * numbase + 4 * num3 + 4 * num5 ; i := i + 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(n): return(n*8+32)*6*10**(n-2)-5 i=2 count=0 s=int(input()) while 1 : if count+f(i)toInteger() ; while 1 do ( if (count + f(i)->compareTo(s)) < 0 then ( count := count + f(i) ) else ( break ) ; i := i + 1) ; var j : int := 0 ; var x : double := (10)->pow((i - 1)) - 9 ; var tmp : int := (s - count) div (i * 8 + 32) ; count := count - (if tmp /= 0 then 5 else 0 endif) ; count := count + tmp * (i * 8 + 32) ; x := x + tmp * 15 ; var fzbz : String := '' ; while ((fzbz)->size()->compareTo(s - count + 100)) <= 0 do ( fzbz := fzbz + (if x mod 15 = 0 then 'FizzBuzz' else if x mod 3 = 0 then 'Fizz' else if x mod 5 = 0 then 'Buzz' else ("" + ((x))) endif endif endif) ; x := x + 1) ; execute (fzbz.subrange(s - count - 1+1, s - count - 1 + 20))->display(); operation f(n : OclAny) : OclAny pre: true post: true activity: return (n * 8 + 32) * 6 * (10)->pow((n - 2)) - 5; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count_div(start,end,div): return(end-1)//div-(start-1)//div def calc_start(mid): cnt,i=0,1 while 10**itoInteger() - 1 ; var left : OclAny := null; var right : OclAny := null; Sequence{left,right} := Sequence{1,(10)->pow(18)} ; while (left + 1->compareTo(right)) < 0 do ( mid := (left + right) div 2 ; start := calc_start(mid) ; if (start->compareTo(N)) <= 0 then ( var left : OclAny := mid ) else ( var right : OclAny := mid )) ; var ans : String := '' ; for i : Integer.subrange(left, left + 9-1) do ( var tmp : String := '' ; if i mod 3 = 0 then ( tmp := tmp + "Fizz" ) else skip ; if i mod 5 = 0 then ( tmp := tmp + "Buzz" ) else skip ; if not(tmp = "") then ( tmp := ("" + ((i))) ) else skip ; ans := ans + tmp) ; start := calc_start(left) ; execute (ans.subrange(N - start+1, N - start + 20))->display(); operation count_div(start : OclAny, end : OclAny, div : OclAny) : OclAny pre: true post: true activity: return (end - 1) div div - (start - 1) div div; operation calc_start(mid : OclAny) : OclAny pre: true post: true activity: var cnt : OclAny := null; var i : OclAny := null; Sequence{cnt,i} := Sequence{0,1} ; while ((10)->pow(i)->compareTo(mid)) < 0 do ( var d : OclAny := null; var p : OclAny := null; Sequence{d,p} := Sequence{(10)->pow(i),(10)->pow((i - 1))} ; var fif : OclAny := null; var three : OclAny := null; var five : OclAny := null; Sequence{fif,three,five} := Sequence{count_div(p, d, 15),count_div(p, d, 3),count_div(p, d, 5)} ; cnt := cnt + i * (d - p) + (three + five) * 4 - (three + five - fif) * i ; i := i + 1) ; var d : double := (10)->pow((i - 1)) ; var fif : OclAny := null; var three : OclAny := null; var five : OclAny := null; Sequence{fif,three,five} := Sequence{count_div(d, mid, 15),count_div(d, mid, 3),count_div(d, mid, 5)} ; cnt := cnt + i * (mid - d) + (three + five) * 4 - (three + five - fif) * i ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- first=list(map(int,input().split())) a=list(map(int,input().split())) b=list(map(int,input().split())) nSoldiers=first[0] nVest=first[1] x=first[2] y=first[3] pair=0 result=[] curVest=0 curSoldier=0 while curSoldiercollect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var nSoldiers : OclAny := first->first() ; var nVest : OclAny := first[1+1] ; var x : OclAny := first[2+1] ; var y : OclAny := first[3+1] ; var pair : int := 0 ; var result : Sequence := Sequence{} ; var curVest : int := 0 ; var curSoldier : int := 0 ; while (curSoldier->compareTo(nSoldiers)) < 0 & (curVest->compareTo(nVest)) < 0 do ( if (a[curSoldier+1] - x->compareTo(b[curVest+1])) <= 0 & (b[curVest+1] <= a[curSoldier+1] + y) then ( execute ((("" + ((curSoldier + 1))) + " " + ("" + ((curVest + 1)))) : result) ; pair := pair + 1 ; curSoldier := curSoldier + 1 ; curVest := curVest + 1 ) else ( if (a[curSoldier+1]->compareTo(b[curVest+1])) < 0 then ( curSoldier := curSoldier + 1 ) else ( curVest := curVest + 1 ) )) ; execute (pair)->display() ; execute (StringLib.sumStringsWithSeparator((result), "\n"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,x,y=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) u=[] v=[] i,j,res=0,0,0 while ib[j]: j+=1 continue else : i+=1 continue print(res) for i in range(res): print(u[i],v[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,m,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var u : Sequence := Sequence{} ; var v : Sequence := Sequence{} ; var i : OclAny := null; var j : OclAny := null; var res : OclAny := null; Sequence{i,j,res} := Sequence{0,0,0} ; while (i->compareTo(n)) < 0 & (j->compareTo(m)) < 0 do ( if ((a[i+1] - x->compareTo(b[j+1])) <= 0 & (b[j+1]->compareTo(a[i+1] + y)) <= 0) then ( i := i + 1 ; j := j + 1 ; res := res + 1 ; execute ((i) : u) ; execute ((j) : v) ; continue ) else skip ; if (a[i+1] - x->compareTo(b[j+1])) > 0 then ( j := j + 1 ; continue ) else ( i := i + 1 ; continue )) ; execute (res)->display() ; for i : Integer.subrange(0, res-1) do ( execute (u[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): s=input() i=0 j=len(s)-1 while i=i and s[j]!=']' : j-=1 while j>=i and s[j]!=':' : j-=1 if i>=j : print(-1) else : print(s[i : j].count('|')+4) t=1 for i in range(t): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := 1 ; for i : Integer.subrange(0, t-1) do ( solve()); operation solve() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var i : int := 0 ; var j : double := (s)->size() - 1 ; while (i->compareTo((s)->size())) < 0 & s[i+1] /= '[' do ( i := i + 1) ; while (i->compareTo((s)->size())) < 0 & s[i+1] /= ':' do ( i := i + 1) ; while (j->compareTo(i)) >= 0 & s[j+1] /= ']' do ( j := j - 1) ; while (j->compareTo(i)) >= 0 & s[j+1] /= ':' do ( j := j - 1) ; if (i->compareTo(j)) >= 0 then ( execute (-1)->display() ) else ( execute (s.subrange(i+1, j)->count('|') + 4)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,x,y=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) v=[] i=0 for j in range(m): while icollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var v : Sequence := Sequence{} ; var i : int := 0 ; for j : Integer.subrange(0, m-1) do ( while (i->compareTo(n)) < 0 & (a[i+1] + y->compareTo(b[j+1])) < 0 do ( i := i + 1) ; if i = n then ( break ) else skip ; if (a[i+1] - x->compareTo(b[j+1])) <= 0 & (b[j+1] <= a[i+1] + y) then ( execute ((Sequence{i + 1, j + 1}) : v) ; i := i + 1 ) else skip) ; execute ((v)->size())->display() ; for vest : v do ( execute (vest->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,x,y=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) v=[] i=j=0 while ib[j]: j+=1 print(len(v)) for vest in v : print(vest[0],vest[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,m,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var v : Sequence := Sequence{} ; var i : OclAny := 0; var j : int := 0 ; while (i->compareTo(n)) < 0 & (j->compareTo(m)) < 0 do ( if (a[i+1] - x->compareTo(b[j+1])) <= 0 & (b[j+1] <= a[i+1] + y) then ( execute ((Sequence{i + 1, j + 1}) : v) ; i := i + 1 ; j := j + 1 ) else (if (a[i+1] + y->compareTo(b[j+1])) < 0 then ( i := i + 1 ) else (if (a[i+1] - x->compareTo(b[j+1])) > 0 then ( j := j + 1 ) else skip ) ) ) ; execute ((v)->size())->display() ; for vest : v do ( execute (vest->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- datain=True if datain : n,m,x,y=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) else : n,m,x,y=3,3,2,2 a=[1,5,9] b=[3,5,7] a.sort() b.sort() ia=0 ib=0 equi=[] while(iab[ib]): ib+=1 if(iacollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ) else ( var n : OclAny := null; var m : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,m,x,y} := Sequence{3,3,2,2} ; a := Sequence{1}->union(Sequence{5}->union(Sequence{ 9 })) ; b := Sequence{3}->union(Sequence{5}->union(Sequence{ 7 })) ) ; a := a->sort() ; b := b->sort() ; var ia : int := 0 ; var ib : int := 0 ; var equi : Sequence := Sequence{} ; while ((ia->compareTo(n)) < 0) & ((ib->compareTo(m)) < 0) do ( if ((a[ia+1] - x->compareTo(b[ib+1])) <= 0) & ((b[ib+1]->compareTo(a[ia+1] + y)) <= 0) then ( execute ((("" + ((ia + 1))) + ' ' + ("" + ((ib + 1)))) : equi) ; ia := ia + 1 ; ib := ib + 1 ) else ( if ((ia->compareTo(n)) < 0) & ((ib->compareTo(m)) < 0) & ((a[ia+1] - x->compareTo(b[ib+1])) > 0) then ( ib := ib + 1 ) else skip ; if ((ia->compareTo(n)) < 0) & ((ib->compareTo(m)) < 0) & ((a[ia+1] + y->compareTo(b[ib+1])) < 0) then ( ia := ia + 1 ) else skip )) ; execute ((equi)->size())->display() ; for sol : equi do ( execute (sol)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def LongestFibSubseq(A,n): S=set(A) maxLen=0 for i in range(0,n): for j in range(i+1,n): x=A[j] y=A[i]+A[j] length=2 while y in S : z=x+y x=y y=z length+=1 maxLen=max(maxLen,length) return maxLen if maxLen>=3 else 0 if __name__=="__main__" : A=[1,2,3,4,5,6,7,8] n=len(A) print(LongestFibSubseq(A,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( A := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 8 }))))))) ; n := (A)->size() ; execute (LongestFibSubseq(A, n))->display() ) else skip; operation LongestFibSubseq(A : OclAny, n : OclAny) : OclAny pre: true post: true activity: var S : Set := Set{}->union((A)) ; var maxLen : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( var x : OclAny := A[j+1] ; var y : OclAny := A[i+1] + A[j+1] ; var length : int := 2 ; while (S)->includes(y) do ( var z : OclAny := x + y ; x := y ; y := z ; length := length + 1 ; maxLen := Set{maxLen, length}->max()))) ; return if maxLen >= 3 then maxLen else 0 endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split(' ')) min_j,max_j,min_i,max_i=m,-1,n,-1 count=0 for i in range(n): s=input() for j in range(m): if s[j]=='B' : count+=1 min_j=min(min_j,j) max_j=max(max_j,j) min_i=min(min_i,i) max_i=max(max_i,i) num=max(max_j-min_j+1,max_i-min_i+1) if num>n or num>m : print(-1) elif count==0 : print(1) else : need=num*num-count print(need) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var min_j : OclAny := null; var max_j : OclAny := null; var min_i : OclAny := null; var max_i : OclAny := null; Sequence{min_j,max_j,min_i,max_i} := Sequence{m,-1,n,-1} ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; for j : Integer.subrange(0, m-1) do ( if s[j+1] = 'B' then ( count := count + 1 ; var min_j : OclAny := Set{min_j, j}->min() ; var max_j : OclAny := Set{max_j, j}->max() ; var min_i : OclAny := Set{min_i, i}->min() ; var max_i : OclAny := Set{max_i, i}->max() ) else skip)) ; var num : OclAny := Set{max_j - min_j + 1, max_i - min_i + 1}->max() ; if (num->compareTo(n)) > 0 or (num->compareTo(m)) > 0 then ( execute (-1)->display() ) else (if count = 0 then ( execute (1)->display() ) else ( var need : double := num * num - count ; execute (need)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=input().split() n,m=int(n),int(m) board=[] for i in range(n): row=input() board.append(row) locations_B=[] num_B=0 for i in range(n): for j in range(m): if board[i][j]=='B' : location=(j,i) locations_B.append(location) num_B+=1 if num_B==0 : print(1) quit() rows=[locations_B[i][0]for i in range(num_B)] columns=[locations_B[i][1]for i in range(num_B)] max_dimen=max(max(rows)-min(rows),max(columns)-min(columns))+1 if(max_dimen>n)or(max_dimen>m): print(-1) else : print(max_dimen**2-num_B) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split() ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{("" + ((n)))->toInteger(),("" + ((m)))->toInteger()} ; var board : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var row : String := (OclFile["System.in"]).readLine() ; execute ((row) : board)) ; var locations_B : Sequence := Sequence{} ; var num_B : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if board[i+1][j+1] = 'B' then ( var location : OclAny := Sequence{j, i} ; execute ((location) : locations_B) ; num_B := num_B + 1 ) else skip)) ; if num_B = 0 then ( execute (1)->display() ; quit() ) else skip ; var rows : Sequence := Integer.subrange(0, num_B-1)->select(i | true)->collect(i | (locations_B[i+1]->first())) ; var columns : Sequence := Integer.subrange(0, num_B-1)->select(i | true)->collect(i | (locations_B[i+1][1+1])) ; var max_dimen : OclAny := Set{(rows)->max() - (rows)->min(), (columns)->max() - (columns)->min()}->max() + 1 ; if ((max_dimen->compareTo(n)) > 0) or ((max_dimen->compareTo(m)) > 0) then ( execute (-1)->display() ) else ( execute ((max_dimen)->pow(2) - num_B)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=input().split() n,m=int(n),int(m) num_B=0 start_row=m-1 end_row=0 start_column=n-1 end_column=0 for i in range(n): row=input() for j in range(m): if row[j]=='B' : start_row=min(j,start_row) end_row=max(j,end_row) start_column=min(i,start_column) end_column=max(i,end_column) num_B+=1 if num_B==0 : print(1) quit() max_dimen=max(end_row-start_row,end_column-start_column)+1 if(max_dimen>n)or(max_dimen>m): print(-1) else : print(max_dimen**2-num_B) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split() ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{("" + ((n)))->toInteger(),("" + ((m)))->toInteger()} ; var num_B : int := 0 ; var start_row : double := m - 1 ; var end_row : int := 0 ; var start_column : double := n - 1 ; var end_column : int := 0 ; for i : Integer.subrange(0, n-1) do ( var row : String := (OclFile["System.in"]).readLine() ; for j : Integer.subrange(0, m-1) do ( if row[j+1] = 'B' then ( start_row := Set{j, start_row}->min() ; end_row := Set{j, end_row}->max() ; start_column := Set{i, start_column}->min() ; end_column := Set{i, end_column}->max() ; num_B := num_B + 1 ) else skip)) ; if num_B = 0 then ( execute (1)->display() ; quit() ) else skip ; var max_dimen : OclAny := Set{end_row - start_row, end_column - start_column}->max() + 1 ; if ((max_dimen->compareTo(n)) > 0) or ((max_dimen->compareTo(m)) > 0) then ( execute (-1)->display() ) else ( execute ((max_dimen)->pow(2) - num_B)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) sheet=[] for i in range(n): s=input() sheet.append(s) final=[] for i in range(len(sheet)): if 'B' in sheet[i]: temp=[] for j in range(len(sheet[i])): if sheet[i][j]=='B' : temp.append(j) x=len(temp) final.append([i,temp[0],temp[x-1],x]) if len(final)==0 : print("1") else : x=min(final,key=lambda process : process[0]) y=max(final,key=lambda process : process[0]) row=y[0]-x[0]+1 z=min(final,key=lambda process : process[1]) w=max(final,key=lambda process : process[2]) col=w[2]-z[1]+1 total=max(n,m) sqaure=max(row,col) if sqaure<=n and sqaure<=m : sum=0 for i in final : sum=sum+(sqaure-i[3]) if len(final)collect( _x | (OclType["int"])->apply(_x) ) ; var sheet : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; execute ((s) : sheet)) ; var final : Sequence := Sequence{} ; for i : Integer.subrange(0, (sheet)->size()-1) do ( if (sheet[i+1])->includes('B') then ( var temp : Sequence := Sequence{} ; for j : Integer.subrange(0, (sheet[i+1])->size()-1) do ( if sheet[i+1][j+1] = 'B' then ( execute ((j) : temp) ) else skip) ; var x : int := (temp)->size() ; execute ((Sequence{i}->union(Sequence{temp->first()}->union(Sequence{temp[x - 1+1]}->union(Sequence{ x })))) : final) ) else skip) ; if (final)->size() = 0 then ( execute ("1")->display() ) else ( x := Set{final, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name process)))) : (test (logical_test (comparison (expr (atom (name process)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))))}->min() ; var y : OclAny := Set{final, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name process)))) : (test (logical_test (comparison (expr (atom (name process)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))))}->max() ; var row : double := y->first() - x->first() + 1 ; var z : OclAny := Set{final, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name process)))) : (test (logical_test (comparison (expr (atom (name process)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))))}->min() ; var w : OclAny := Set{final, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name process)))) : (test (logical_test (comparison (expr (atom (name process)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ]))))))))}->max() ; var col : double := w[2+1] - z[1+1] + 1 ; var total : OclAny := Set{n, m}->max() ; var sqaure : OclAny := Set{row, col}->max() ; if (sqaure->compareTo(n)) <= 0 & (sqaure->compareTo(m)) <= 0 then ( var sum : int := 0 ; for i : final do ( sum := sum + (sqaure - i[3+1])) ; if ((final)->size()->compareTo(sqaure)) < 0 then ( sum := sum + ((sqaure - (final)->size()) * sqaure) ) else skip ; execute (sum)->display() ) else ( execute ("-1")->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def power(x,y,mod): res=1 while(y): if(y & 1): res=(res*x)% mod x=(x*x)% mod y=(y>>1) return(res % mod) def ncr(n,r,mod): res=1 for i in range(1,r+1): res=(res*(n-i+1))% mod inv=power(i,mod-2,mod) res=(res*inv)% mod return(res % mod) def NoOfChords(A): mod=10**9+7 ans=ncr(2*A,A,mod) inv=power(A+1,mod-2,mod) ans=(ans*inv)% mod return(ans % mod) N=2 print(NoOfChords(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var N : int := 2 ; execute (NoOfChords(N))->display(); operation power(x : OclAny, y : OclAny, mod : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; while (y) do ( if (MathLib.bitwiseAnd(y, 1)) then ( res := (res * x) mod mod ) else skip ; x := (x * x) mod mod ; y := (y /(2->pow(1)))) ; return (res mod mod); operation ncr(n : OclAny, r : OclAny, mod : OclAny) : OclAny pre: true post: true activity: res := 1 ; for i : Integer.subrange(1, r + 1-1) do ( res := (res * (n - i + 1)) mod mod ; var inv : OclAny := power(i, mod - 2, mod) ; res := (res * inv) mod mod) ; return (res mod mod); operation NoOfChords(A : OclAny) : OclAny pre: true post: true activity: mod := (10)->pow(9) + 7 ; var ans : OclAny := ncr(2 * A, A, mod) ; inv := power(A + 1, mod - 2, mod) ; ans := (ans * inv) mod mod ; return (ans mod mod); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reverseSting(text): index=-1 for i in range(len(text)-1,int(len(text)/2),-1): if text[i].isalpha(): temp=text[i] while True : index+=1 if text[index].isalpha(): text[i]=text[index] text[index]=temp break return text string="a!!!b.c.d,e'f,ghi" print("Input string: ",string) string=reverseSting(list(string)) print("Output string: ","".join(string)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var string : String := "a!!!b.c.d,e'f,ghi" ; execute ("Input string: ")->display() ; string := reverseSting((string)->characters()) ; execute ("Output string: ")->display(); operation reverseSting(text : OclAny) : OclAny pre: true post: true activity: var index : int := -1 ; for i : Integer.subrange(("" + (((text)->size() / 2)))->toInteger() + 1, (text)->size() - 1)->reverse() do ( if text[i+1]->matches("[a-zA-Z]*") then ( var temp : OclAny := text[i+1] ; while true do ( index := index + 1 ; if text[index+1]->matches("[a-zA-Z]*") then ( text[i+1] := text[index+1] ; text[index+1] := temp ; break ) else skip) ) else skip) ; return text; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countdigits(n,k): if n==0 : return 0 digit=n % 10 if digit==k : return 1+countdigits(n/10,k) return countdigits(n/10,k) if __name__=="__main__" : n=1000 ; k=0 ; print(countdigits(n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 1000; ; k := 0; ; execute (countdigits(n, k))->display() ) else skip; operation countdigits(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( return 0 ) else skip ; var digit : int := n mod 10 ; if digit = k then ( return 1 + countdigits(n / 10, k) ) else skip ; return countdigits(n / 10, k); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(s): c=4 flag_1=1 flag_2=1 flag_3=1 flag_4=1 for i in range(len(s)): if s[i]=='[' and flag_1 : flag_1=0 if s[i]==':' and not flag_1 : idx_1=i flag_2=0 break if flag_1 or flag_2 : return-1 for i in range(len(s)-1,idx_1,-1): if s[i]==']' and flag_3 : flag_3=0 if s[i]==':' and not flag_3 : idx_2=i flag_4=0 break if flag_3 or flag_4 : return-1 for i in range(idx_1,idx_2+1): if s[i]=='|' : c+=1 return c def main(): s=input() print(solve(s)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(s : OclAny) : OclAny pre: true post: true activity: var c : int := 4 ; var flag var c : int := 4 : int := 1 ; var flag:= 1 : int := 1 ; var flag_3 : int := 1 ; var flag_4 : int := 1 ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = '[' & flag var c : int := 4 then ( flag var c : int := 4 := 0 ) else skip ; if s[i+1] = ':' & not(flag if s[i+1] = '[' & flag var c : int := 4 then ( flag var c : int := 4 := 0 ) else skip) then ( var idx if s[i+1] = '[' & flag var c : int := 4 then ( flag var c : int := 4 := 0 ) else skip : OclAny := i ; flag:= 0 := 0 ; break ) else skip) ; if flag var c : int := 4 or flag return -1 then ( return -1 ) else skip ; for i : Integer.subrange(idx(s)->size() - 1, idx(s)->size() - 1, -1 + 1, (s)->size() - 1)->reverse() do ( if s[i+1] = ']' & flag_3 then ( flag_3 := 0 ) else skip ; if s[i+1] = ':' & not(flag_3) then ( var idx:= i : OclAny := i ; flag_4 := 0 ; break ) else skip) ; if flag_3 or flag_4 then ( return -1 ) else skip ; for i : Integer.subrange(idxidx(idx(idx var c : int := 4, idx1 + 1), idx1 + 1), idx1 + 1, idx1 + 1-1) do ( if s[i+1] = '|' then ( c := c + 1 ) else skip) ; return c; operation main() pre: true post: true activity: s := (OclFile["System.in"]).readLine() ; execute (solve(s))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=input().split() if a[-1]==b[0]and b[-1]==c[0]: print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := input().split() ; if a->last() = b->first() & b->last() = c->first() then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input().split() print('YES' if S[0][-1]==S[1][0]and S[1][-1]==S[2][0]else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : OclAny := input().split() ; execute (if S->first()->last() = S[1+1]->first() & S[1+1]->last() = S[2+1]->first() then 'YES' else 'NO' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairs(a,b,n,m): cnt=0 s=dict() for i in range(n): for j in range(m): sum=a[i]+b[j] if(sum not in s.keys()): cnt+=1 s[sum]=1 return cnt a=[12,2,7] n=len(a) b=[4,3,8] m=len(b) print(countPairs(a,b,n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{12}->union(Sequence{2}->union(Sequence{ 7 })) ; n := (a)->size() ; b := Sequence{4}->union(Sequence{3}->union(Sequence{ 8 })) ; m := (b)->size() ; execute (countPairs(a, b, n, m))->display(); operation countPairs(a : OclAny, b : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; var s : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( var sum : OclAny := a[i+1] + b[j+1] ; if ((s.keys())->excludes(sum)) then ( cnt := cnt + 1 ; s[sum+1] := 1 ) else skip)) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B,C=input().split() A=list(A) B=list(B) C=list(C) if A.pop()==B[0]and B.pop()==C[0]: print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{A,B,C} := input().split() ; var A : Sequence := (A) ; var B : Sequence := (B) ; var C : Sequence := (C) ; if A->last() = B->first() & B->last() = C->first() then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input().split() a=s[0] b=s[1] c=s[2] if a[len(a)-1]==b[0]and b[len(b)-1]==c[0]: print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := input().split() ; var a : OclAny := s->first() ; var b : OclAny := s[1+1] ; var c : OclAny := s[2+1] ; if a[(a)->size() - 1+1] = b->first() & b[(b)->size() - 1+1] = c->first() then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B,C=map(str,input().split()) print('YES' if A[-1]==B[0]and B[-1]==C[0]else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{A,B,C} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; execute (if A->last() = B->first() & B->last() = C->first() then 'YES' else 'NO' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(l): ans=0 nol=0 satu=0 neg=0 for e in l : if e==0 : nol+=1 continue if e>1 : satu+=1 ans+=e-1 continue elif e<0 : neg+=1 ans+=-1-e neg=neg % 2 if neg==1 : if nol>=1 : ans+=1+(nol-1) elif nol==0 : ans+=2 elif neg==0 : ans+=nol return ans input() l=list(map(int,input().split(" "))) print(solve(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; input() ; l := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; execute (solve(l))->display(); operation solve(l : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; var nol : int := 0 ; var satu : int := 0 ; var neg : int := 0 ; for e : l do ( if e = 0 then ( nol := nol + 1 ; continue ) else skip ; if e > 1 then ( satu := satu + 1 ; ans := ans + e - 1 ; continue ) else (if e < 0 then ( neg := neg + 1 ; ans := ans + -1 - e ) else skip)) ; neg := neg mod 2 ; if neg = 1 then ( if nol >= 1 then ( ans := ans + 1 + (nol - 1) ) else (if nol = 0 then ( ans := ans + 2 ) else skip) ) else (if neg = 0 then ( ans := ans + nol ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) s=input() a=[int(x)for x in s.split()] am=0 ans=0 soso0=0 product=1 for i in range(0,len(a)): if a[i]==-1 : am+=1 product*=a[i] elif a[i]<-1 : ans+=-a[i]-1 am+=1 product*=-1 elif a[i]==0 : soso0+=1 elif a[i]>1 : ans+=a[i]-1 if product==1 : ans+=soso0 print(ans) elif product==-1 : if soso0>0 : ans+=soso0 print(ans) else : ans+=2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var a : Sequence := s.split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var am : int := 0 ; var ans : int := 0 ; var soso0 : int := 0 ; var product : int := 1 ; for i : Integer.subrange(0, (a)->size()-1) do ( if a[i+1] = -1 then ( am := am + 1 ; product := product * a[i+1] ) else (if a[i+1] < -1 then ( ans := ans + -a[i+1] - 1 ; am := am + 1 ; product := product * -1 ) else (if a[i+1] = 0 then ( soso0 := soso0 + 1 ) else (if a[i+1] > 1 then ( ans := ans + a[i+1] - 1 ) else skip ) ) ) ) ; if product = 1 then ( ans := ans + soso0 ; execute (ans)->display() ) else (if product = -1 then ( if soso0 > 0 then ( ans := ans + soso0 ; execute (ans)->display() ) else ( ans := ans + 2 ; execute (ans)->display() ) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- count=input() nums=[int(x)for x in input().split()] hasZero=False cost=0 prod=1 for i in range(len(nums)-1,-1,-1): if nums[i]==0 : hasZero=True cost+=1 elif nums[i]<0 : cost+=abs(nums[i])-1 prod*=-1 else : cost+=nums[i]-1 if prod==-1 : if not hasZero : cost+=2 print(cost) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var count : String := (OclFile["System.in"]).readLine() ; var nums : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var hasZero : boolean := false ; var cost : int := 0 ; var prod : int := 1 ; for i : Integer.subrange(-1 + 1, (nums)->size() - 1)->reverse() do ( if nums[i+1] = 0 then ( hasZero := true ; cost := cost + 1 ) else (if nums[i+1] < 0 then ( cost := cost + (nums[i+1])->abs() - 1 ; prod := prod * -1 ) else ( cost := cost + nums[i+1] - 1 ) ) ) ; if prod = -1 then ( if not(hasZero) then ( cost := cost + 2 ) else skip ) else skip ; execute (cost)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) li=list(map(int,input().split())) ans=0 one=1 for i in range(n): if li[i]<0 : ans+=abs(li[i]-(-1)) one*=(-1) else : ans+=abs(li[i]-1) one*=1 if(one==-1)and(0 not in li): ans+=2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; var one : int := 1 ; for i : Integer.subrange(0, n-1) do ( if li[i+1] < 0 then ( ans := ans + (li[i+1] - (-1))->abs() ; one := one * (-1) ) else ( ans := ans + (li[i+1] - 1)->abs() ; one := one * 1 )) ; if (one = -1) & ((li)->excludes(0)) then ( ans := ans + 2 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) res=0 pc=0 oz=0 for a in arr : if a<0 : pc+=1 elif a==0 : oz+=1 continue res+=abs(abs(a)-1) if pc % 2!=0 and not oz : res+=2 elif pc % 2!=0 and oz : res+=(1*oz) else : res+=(1*oz) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : int := 0 ; var pc : int := 0 ; var oz : int := 0 ; for a : arr do ( if a < 0 then ( pc := pc + 1 ) else (if a = 0 then ( oz := oz + 1 ; continue ) else skip) ; res := res + ((a)->abs() - 1)->abs()) ; if pc mod 2 /= 0 & not(oz) then ( res := res + 2 ) else (if pc mod 2 /= 0 & oz then ( res := res + (1 * oz) ) else ( res := res + (1 * oz) ) ) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- __author__='Tianren Liu' import sys import numpy as np def solve(Choose,Target,p,dis): if len(dis)-1+Chooselen(p): return 0 ndis=np.zeros(len(dis)+1) ndis[: len(dis)]+=dis*(1-p[0]) ndis[1 :]+=dis*p[0] res=max(solve(Choose-1,Target,p[1 :],ndis),solve(Choose,Target,p[1 :],dis)) return res if __name__=="__main__" : T=int(sys.stdin.readline()) for t in range(T): N,K=map(int,sys.stdin.readline().split()) p=[float(f)for f in sys.stdin.readline().split()] print("Case #{}:{}".format(t+1,solve(K,K//2,p,np.array([1.])))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var __author__ : String := 'Tianren Liu' ; skip ; skip ; skip ; if __name__ = "__main__" then ( var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(0, T-1) do ( var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; p := sys.stdin.readLine().split()->select(f | true)->collect(f | (("" + ((f)))->toReal())) ; execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{t + 1, solve(K, K div 2, p, (Sequence{ 1. }))}))->display()) ) else skip; operation solve(Choose : OclAny, Target : OclAny, p : OclAny, dis : OclAny) : OclAny pre: true post: true activity: if ((dis)->size() - 1 + Choose->compareTo(Target)) < 0 then ( return 0. ) else skip ; if Choose = 0 then ( return dis[Target+1] ) else skip ; if (Choose->compareTo((p)->size())) > 0 then ( return 0 ) else skip ; var ndis : Sequence := MatrixLib.singleValueMatrix((dis)->size() + 1, 0.0) ; ndis.subrange(1,(dis)->size()) := ndis.subrange(1,(dis)->size()) + dis * (1 - p->first()) ; ndis->tail() := ndis->tail() + dis * p->first() ; var res : OclAny := Set{solve(Choose - 1, Target, p->tail(), ndis), solve(Choose, Target, p->tail(), dis)}->max() ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import collections import heapq import decimal input=sys.stdin.readline n=int(input()) mod=1000000007 p=[] p1=1 for i in range(n+1): p.append(p1) p1=(p1*2)% mod l=sorted([int(i)for i in input().split()]) s=0 for i in range(n): s=(s+(l[i]*p[i])% mod)% mod s=(s-(l[i]*p[n-i-1])% mod)% mod print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mod : int := 1000000007 ; var p : Sequence := Sequence{} ; var p1 : int := 1 ; for i : Integer.subrange(0, n + 1-1) do ( execute ((p1) : p) ; p1 := (p1 * 2) mod mod) ; var l : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))->sort() ; var s : int := 0 ; for i : Integer.subrange(0, n-1) do ( s := (s + (l[i+1] * p[i+1]) mod mod) mod mod ; s := (s - (l[i+1] * p[n - i - 1+1]) mod mod) mod mod) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def check(a,y): sum=0 for i in range(len(a)): x=math.sqrt(a[i]) if(math.floor(x)==math.ceil(x)): sum=sum+a[i] if(sum % y==0): return True else : return False a=[2,3,4,9,10] x=13 if check(a,x): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{9}->union(Sequence{ 10 })))) ; x := 13 ; if check(a, x) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation check(a : OclAny, y : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( var x : double := (a[i+1])->sqrt() ; if ((x)->floor() = (x)->ceil()) then ( sum := sum + a[i+1] ) else skip) ; if (sum mod y = 0) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cross(a,b): return a.real*b.imag-a.imag*b.real def intersection(p0,p1,p2,p3): a1=p3-p2 b1=p0-p2 b2=p1-p2 s1=cross(b1,a1) s2=cross(a1,b2) c1=p0+(p1-p0)*s1/(s1+s2) return c1 q=int(input()) for _ in[0]*q : x_y=map(int,input().split()) p0,p1,p2,p3=[x+y*1j for x,y in zip(*[x_y]*2)] c1=intersection(p0,p1,p2,p3) print('{:.10f}{:.10f}'.format(c1.real,c1.imag)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, q) do ( var x_y : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; Sequence{p0,p1,p2,p3} := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name x_y))))))) ])) * (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name x_y))))))) ])) * (expr (atom (number (integer 2)))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name x_y))))))) ])) * (expr (atom (number (integer 2)))))))))`third->at(_indx)} )->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (x + y * 1j)) ; c1 := intersection(p0, p1, p2, p3) ; execute (StringLib.interpolateStrings('{:.10f}{:.10f}', Sequence{c1.real, c1.imag}))->display()); operation cross(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a.real * b.imag - a.imag * b.real; operation intersection(p0 : OclAny, p1 : OclAny, p2 : OclAny, p3 : OclAny) : OclAny pre: true post: true activity: var a1 : double := p3 - p2 ; var b1 : double := p0 - p2 ; var b2 : double := p1 - p2 ; var s1 : OclAny := cross(b1, a1) ; var s2 : OclAny := cross(a1, b2) ; var c1 : OclAny := p0 + (p1 - p0) * s1 / (s1 + s2) ; return c1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=26 def canBeMapped(s1,l1,s2,l2): if(l1!=l2): return False freq1=[0 for i in range(MAX)] freq2=[0 for i in range(MAX)] for i in range(l1): freq1[ord(s1[i])-ord('a')]+=1 for i in range(l2): freq2[ord(s2[i])-ord('a')]+=1 for i in range(MAX): if(freq1[i]==0): continue found=False for j in range(MAX): if(freq1[i]==freq2[j]): freq2[j]=-1 found=True break if(found==False): return False return True if __name__=='__main__' : s1="axx" s2="cbc" l1=len(s1) l2=len(s2) if(canBeMapped(s1,l1,s2,l2)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 26 ; skip ; if __name__ = '__main__' then ( s1 := "axx" ; s2 := "cbc" ; l1 := (s1)->size() ; l2 := (s2)->size() ; if (canBeMapped(s1, l1, s2, l2)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation canBeMapped(s1 : OclAny, l1 : OclAny, s2 : OclAny, l2 : OclAny) : OclAny pre: true post: true activity: if (l1 /= l2) then ( return false ) else skip ; var freq1 : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)) ; var freq2 : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, l1-1) do ( freq1[(s1[i+1])->char2byte() - ('a')->char2byte()+1] := freq1[(s1[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; for i : Integer.subrange(0, l2-1) do ( freq2[(s2[i+1])->char2byte() - ('a')->char2byte()+1] := freq2[(s2[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; for i : Integer.subrange(0, MAX-1) do ( if (freq1[i+1] = 0) then ( continue ) else skip ; var found : boolean := false ; for j : Integer.subrange(0, MAX-1) do ( if (freq1[i+1] = freq2[j+1]) then ( freq2[j+1] := -1 ; found := true ; break ) else skip) ; if (found = false) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as ma def find(n,m,p,q): z=[] for i in range(p): z.append(q[i][1]) print(max(z)-min(z)) n,m,p=2,2,2 q=[(0,0),(0,1)] find(n,m,p,q) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{n,m,p} := Sequence{2,2,2} ; q := Sequence{Sequence{0, 0}}->union(Sequence{ Sequence{0, 1} }) ; find(n, m, p, q); operation find(n : OclAny, m : OclAny, p : OclAny, q : OclAny) pre: true post: true activity: var z : Sequence := Sequence{} ; for i : Integer.subrange(0, p-1) do ( execute ((q[i+1][1+1]) : z)) ; execute ((z)->max() - (z)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) sm=sum(list(map(int,input().split()))) print((n+sm)//(n+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sm : OclAny := (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->sum() ; execute ((n + sm) div (n + 1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- friends=input() friends=friends.split() friends_all=friends[0] friends_cakes=friends[1] person=int(friends_all)+1 cakes=input() cakes_amount=0 for a in cakes.split(): cakes_amount+=int(a) one_person=cakes_amount//person if cakes_amount % person!=0 : one_person+=1 else : pass print(one_person) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var friends : String := (OclFile["System.in"]).readLine() ; friends := friends.split() ; var friends_all : OclAny := friends->first() ; var friends_cakes : OclAny := friends[1+1] ; var person : int := ("" + ((friends_all)))->toInteger() + 1 ; var cakes : String := (OclFile["System.in"]).readLine() ; var cakes_amount : int := 0 ; for a : cakes.split() do ( cakes_amount := cakes_amount + ("" + ((a)))->toInteger()) ; var one_person : int := cakes_amount div person ; if cakes_amount mod person /= 0 then ( one_person := one_person + 1 ) else ( skip ) ; execute (one_person)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,c=list(map(int,input().split())) pli=list(map(int,input().split())) for i in range(c): p=sum(pli) mycake=p//(n+1) if p %(n+1)>0 : mycake+=1 print(mycake) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var pli : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, c-1) do ( var p : OclAny := (pli)->sum()) ; var mycake : int := p div (n + 1) ; if p mod (n + 1) > 0 then ( mycake := mycake + 1 ) else skip ; execute (mycake)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math N,C=list(map(int,input().split(' '))) cakes=list(map(int,input().split(' '))) num_cakes=sum(cakes) mycake=math.ceil(num_cakes/(N+1)) print(mycake) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var C : OclAny := null; Sequence{N,C} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var cakes : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var num_cakes : OclAny := (cakes)->sum() ; var mycake : double := (num_cakes / (N + 1))->ceil() ; execute (mycake)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,C=[int(i)for i in input().split()] p=[int(i)for i in input().split()] t=0 for i in range(len(p)): t+=p[i] if t %(N+1)==0 : ans=t//(N+1) else : ans=t//(N+1)+1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var C : OclAny := null; Sequence{N,C} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var p : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var t : int := 0 ; for i : Integer.subrange(0, (p)->size()-1) do ( t := t + p[i+1]) ; if t mod (N + 1) = 0 then ( var ans : int := t div (N + 1) ) else ( ans := t div (N + 1) + 1 ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import heapq import sys import math import itertools import bisect from io import BytesIO,IOBase import os def valid(i,j,n,m): if i=0 and j>=0 and ji : return "No" even.append(i) if i % 2==1 : if odd and odd[-1]>i : return "No" odd.append(i) return "Yes" if __name__=="__main__" : for i in range(inp()): print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( for i : Integer.subrange(0, inp()-1) do ( execute (solve())->display()) ) else skip; operation valid(i : OclAny, j : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: if (i->compareTo(n)) < 0 & i >= 0 & j >= 0 & (j->compareTo(m)) < 0 then ( return true ) else skip ; return false; operation sumn(i : OclAny, n : OclAny) : OclAny pre: true post: true activity: return (n - i) * (i + n) / 2; operation sqfun(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: return (-b + (b * b - 4 * a * c)->sqrt()) / 2 * a; operation getprime(num : OclAny) : OclAny pre: true post: true activity: if ((argument (test (logical_test (comparison (comparison (expr (expr (atom (name num))) % (expr (atom (name i))))) != (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name math)) (trailer . (name sqrt) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) ))))))))) )))) + (expr (atom (number (integer 1)))))))))) )))))))))->forAll( _x | _x = true ) then ( return true ) else skip; operation value() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation values() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inlsts() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inps() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation instr() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation stlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (i)); operation solve() : OclAny pre: true post: true activity: n := inp() ; var l : OclAny := inlsts() ; var odd : Sequence := Sequence{} ; var even : Sequence := Sequence{} ; for i : l do ( if i mod 2 = 0 then ( if even & (even->last()->compareTo(i)) > 0 then ( return "No" ) else skip ; execute ((i) : even) ) else skip ; if i mod 2 = 1 then ( if odd & (odd->last()->compareTo(i)) > 0 then ( return "No" ) else skip ; execute ((i) : odd) ) else skip) ; return "Yes"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import heapq import sys import math import itertools import bisect from io import BytesIO,IOBase import os def valid(i,j,n,m): if i=0 and j>=0 and ji : return "No" even.append(i) if i % 2==1 : if odd and odd[-1]>i : return "No" odd.append(i) return "Yes" if __name__=="__main__" : for i in range(inp()): print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( for i : Integer.subrange(0, inp()-1) do ( execute (solve())->display()) ) else skip; operation valid(i : OclAny, j : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: if (i->compareTo(n)) < 0 & i >= 0 & j >= 0 & (j->compareTo(m)) < 0 then ( return true ) else skip ; return false; operation sumn(i : OclAny, n : OclAny) : OclAny pre: true post: true activity: return (n - i) * (i + n) / 2; operation sqfun(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: return (-b + (b * b - 4 * a * c)->sqrt()) / 2 * a; operation getprime(num : OclAny) : OclAny pre: true post: true activity: if ((argument (test (logical_test (comparison (comparison (expr (expr (atom (name num))) % (expr (atom (name i))))) != (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name math)) (trailer . (name sqrt) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) ))))))))) )))) + (expr (atom (number (integer 1)))))))))) )))))))))->forAll( _x | _x = true ) then ( return true ) else skip; operation value() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation values() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inlsts() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inps() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation instr() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation stlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (i)); operation solve() : OclAny pre: true post: true activity: n := inp() ; var l : OclAny := values() ; var odd : Sequence := Sequence{} ; var even : Sequence := Sequence{} ; for i : l do ( if i mod 2 = 0 then ( if even & (even->last()->compareTo(i)) > 0 then ( return "No" ) else skip ; execute ((i) : even) ) else skip ; if i mod 2 = 1 then ( if odd & (odd->last()->compareTo(i)) > 0 then ( return "No" ) else skip ; execute ((i) : odd) ) else skip) ; return "Yes"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def nthElement(a,b,n): lcm=(a*b)/int(math.gcd(a,b)) l=1 r=min(a,b)*n while(l<=r): mid=(l+r)>>1 val=(int(mid/a)+int(mid/b)-int(mid/lcm)) if(val==n): return int(max(int(mid/a)*a,int(mid/b)*b)) if(valdisplay(); operation nthElement(a : OclAny, b : OclAny, n : OclAny) : OclAny pre: true post: true activity: var lcm : double := (a * b) / ("" + (((a)->gcd(b))))->toInteger() ; var l : int := 1 ; var r : double := Set{a, b}->min() * n ; while ((l->compareTo(r)) <= 0) do ( var mid : int := (l + r) /(2->pow(1)) ; var val : double := (("" + ((mid / a)))->toInteger() + ("" + ((mid / b)))->toInteger() - ("" + ((mid / lcm)))->toInteger()) ; if (val = n) then ( return ("" + ((Set{("" + ((mid / a)))->toInteger() * a, ("" + ((mid / b)))->toInteger() * b}->max())))->toInteger() ) else skip ; if ((val->compareTo(n)) < 0) then ( l := mid + 1 ) else ( r := mid - 1 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq n,q=map(int,input().split()) Q=[[]for i in range(n)] queries=list() for i in range(q): queries.append(list(map(int,input().split()))) for query in queries : if query[0]==0 : heapq.heappush(Q[query[1]],-query[2]) elif query[0]==1 : if Q[query[1]]: print(-Q[query[1]][0]) elif query[0]==2 : if Q[query[1]]: heapq.heappop(Q[query[1]]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var Q : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; var queries : Sequence := () ; for i : Integer.subrange(0, q-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : queries)) ; for query : queries do ( if query->first() = 0 then ( heapq.heappush(Q[query[1+1]+1], -query[2+1]) ) else (if query->first() = 1 then ( if Q[query[1+1]+1] then ( execute (-Q[query[1+1]+1]->first())->display() ) else skip ) else (if query->first() = 2 then ( if Q[query[1+1]+1] then ( heapq.heappop(Q[query[1+1]+1]) ) else skip ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- K,N=map(int,input().split()) if K % 2==0 : print(K//2,end=' ') for i in range(1,N): if i!=N-1 : print(K,end=' ') else : print(K) else : def superlist(L,n): if n % 2==1 : return[L//2+1]+superlist(L,n-1) else : Ax=[L//2+1 for i in range(n)] j=n-1 for i in range(n//2): Ax[j]-=1 if Ax[j]==0 : j-=1 else : for m in range(j+1,n): Ax[m]=L j=n-1 return Ax if K==1 : for i in range((N-1)//2+1): if i!=(N-1)//2 : print(1,end=' ') else : print(1) else : A=superlist(K,N) for _ in range(N): if _!=N-1 and A[_]!=0 : print(A[_],end=' ') elif _==N-1 and A[_]!=0 : print(A[_]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var K : OclAny := null; var N : OclAny := null; Sequence{K,N} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if K mod 2 = 0 then ( execute (K div 2)->display() ; for i : Integer.subrange(1, N-1) do ( if i /= N - 1 then ( execute (K)->display() ) else ( execute (K)->display() )) ) else ( skip ; if K = 1 then ( for i : Integer.subrange(0, (N - 1) div 2 + 1-1) do ( if i /= (N - 1) div 2 then ( execute (1)->display() ) else ( execute (1)->display() )) ) else ( var A : OclAny := superlist(K, N) ; for _anon : Integer.subrange(0, N-1) do ( if _anon /= N - 1 & A[_anon+1] /= 0 then ( execute (A[_anon+1])->display() ) else (if _anon = N - 1 & A[_anon+1] /= 0 then ( execute (A[_anon+1])->display() ) else skip)) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import starmap def cross(a,b): return a.real*b.imag-a.imag*b.real q=int(input()) while q : q-=1 p0,p1,p2,p3=starmap(complex,zip(*[map(int,input().split())]*2)) d1,d2=abs(cross(p3-p2,p0-p2)),abs(cross(p3-p2,p1-p2)) c=p0+(p1-p0)*d1/(d1+d2) print(c.real,c.imag) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while q do ( q := q - 1 ; var p0 : OclAny := null; var p1 : OclAny := null; var p2 : OclAny := null; var p3 : OclAny := null; Sequence{p0,p1,p2,p3} := starmap(complex, Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))`third->at(_indx)} )) ; var d1 : OclAny := null; var d2 : OclAny := null; Sequence{d1,d2} := Sequence{(cross(p3 - p2, p0 - p2))->abs(),(cross(p3 - p2, p1 - p2))->abs()} ; var c : OclAny := p0 + (p1 - p0) * d1 / (d1 + d2) ; execute (c.real)->display()); operation cross(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a.real * b.imag - a.imag * b.real; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def main(K,N): ans=[] if K % 2==0 : for i in range(N): if i==0 : ans.append(K//2) else : ans.append(K) elif K==1 : n2=math.ceil(N/2) for i in range(n2): ans.append(1) else : K2=math.ceil(K/2) ans=[K2]*N n=N//2 for i in range(n): if ans[-1]==1 : ans.pop() else : ans[-1]-=1 while len(ans)collect( _x | (OclType["int"])->apply(_x) ) ; execute (main(K, N))->display(); operation main(K : OclAny, N : OclAny) : OclAny pre: true post: true activity: var ans : Sequence := Sequence{} ; if K mod 2 = 0 then ( for i : Integer.subrange(0, N-1) do ( if i = 0 then ( execute ((K div 2) : ans) ) else ( execute ((K) : ans) )) ) else (if K = 1 then ( var n2 : double := (N / 2)->ceil() ; for i : Integer.subrange(0, n2-1) do ( execute ((1) : ans)) ) else ( var K2 : double := (K / 2)->ceil() ; ans := MatrixLib.elementwiseMult(Sequence{ K2 }, N) ; var n : int := N div 2 ; for i : Integer.subrange(0, n-1) do ( if ans->last() = 1 then ( ans := ans->front() ) else ( ans->last() := ans->last() - 1 ; while ((ans)->size()->compareTo(N)) < 0 do ( execute ((K) : ans)) )) ) ) ; return StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(k,n): if k & 1==0 : return[k//2]+[k]*(n-1) ans=[k//2+1]*n l=n for i in range((n-2)//2+1): if ans[-1]==1 : ans.pop() l-=1 else : ans[-1]-=1 if lcollect( _x | (OclType["int"])->apply(_x) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name solve)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name k))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->display(); operation solve(k : OclAny, n : OclAny) : OclAny pre: true post: true activity: if MathLib.bitwiseAnd(k, 1) = 0 then ( return Sequence{ k div 2 }->union(MatrixLib.elementwiseMult(Sequence{ k }, (n - 1))) ) else skip ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ k div 2 + 1 }, n) ; var l : OclAny := n ; for i : Integer.subrange(0, (n - 2) div 2 + 1-1) do ( if ans->last() = 1 then ( ans := ans->front() ; l := l - 1 ) else ( ans->last() := ans->last() - 1 ; if (l->compareTo(n)) < 0 then ( ans := ans + MatrixLib.elementwiseMult(Sequence{ k }, (n - l)) ; l := n ) else skip )) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline INF=10**9+7 def calc(n,k): if k==1 : return n if n>20 : return INF return min(INF,(pow(k,n)-1)//(k-1)) K,N=map(int,readline().split()) if K % 2==0 : ans=[K//2]+[K]*(N-1) print(*ans) else : ans=[] cnt=0 half=True for l in range(N,0,-1): clk=calc(l,K) if half : c=1+K//2 if l % 2==0 : cnt+=1 if clk//2==cnt : ans.append(c) break if clk//2=clk : cnt-=clk c-=1 if cnt==clk-1 : ans.append(c) break else : c=K while cnt>=clk : cnt-=clk c-=1 if cnt==clk-1 : ans.append(c) break ans.append(c) print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var INF : double := (10)->pow(9) + 7 ; skip ; var K : OclAny := null; var N : OclAny := null; Sequence{K,N} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if K mod 2 = 0 then ( var ans : Sequence := Sequence{ K div 2 }->union(MatrixLib.elementwiseMult(Sequence{ K }, (N - 1))) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ) else ( ans := Sequence{} ; var cnt : int := 0 ; var half : boolean := true ; for l : Integer.subrange(0 + 1, N)->reverse() do ( var clk : OclAny := calc(l, K) ; if half then ( var c : int := 1 + K div 2 ; if l mod 2 = 0 then ( cnt := cnt + 1 ) else skip ; if clk div 2 = cnt then ( execute ((c) : ans) ; break ) else skip ; if (clk div 2->compareTo(cnt)) < 0 then ( c := c - 1 ; half := false ; cnt := cnt - clk div 2 + 1 ; while (cnt->compareTo(clk)) >= 0 do ( cnt := cnt - clk ; c := c - 1) ; if cnt = clk - 1 then ( execute ((c) : ans) ; break ) else skip ) else skip ) else ( c := K ; while (cnt->compareTo(clk)) >= 0 do ( cnt := cnt - clk ; c := c - 1) ; if cnt = clk - 1 then ( execute ((c) : ans) ; break ) else skip ) ; execute ((c) : ans)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ); operation calc(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if k = 1 then ( return n ) else skip ; if n > 20 then ( return INF ) else skip ; return Set{INF, ((k)->pow(n) - 1) div (k - 1)}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline K,N=map(int,input().split()) if K % 2==0 : L=K//2 R=L+1 arr=[L]+[K]*(N-1) else : arr=[(K+1)//2]*N x=N//2 for i in range(x): arr[-1]-=1 if arr[-1]==0 : arr.pop() continue L=len(arr) if Lcollect( _x | (OclType["int"])->apply(_x) ) ; if K mod 2 = 0 then ( var L : int := K div 2 ; var R : int := L + 1 ; var arr : Sequence := Sequence{ L }->union(MatrixLib.elementwiseMult(Sequence{ K }, (N - 1))) ) else ( arr := MatrixLib.elementwiseMult(Sequence{ (K + 1) div 2 }, N) ; var x : int := N div 2 ; for i : Integer.subrange(0, x-1) do ( arr->last() := arr->last() - 1 ; if arr->last() = 0 then ( arr := arr->front() ; continue ) else skip ; L := (arr)->size() ; if (L->compareTo(N)) < 0 then ( arr := arr + MatrixLib.elementwiseMult(Sequence{ K }, (N - L)) ) else skip) ) ; var answer : String := StringLib.sumStringsWithSeparator(((arr)->collect( _x | (OclType["String"])->apply(_x) )), ' ') ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,m,x,y,a,b=map(int,input().split()) gcd=math.gcd(a,b) a//=gcd b//=gcd max_ratio=min(n//a,m//b) a*=max_ratio b*=max_ratio x1=max(0,min(x-(a+1)//2,n-a)) y1=max(0,min(y-(b+1)//2,m-b)) print(x1,y1,x1+a,y1+b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; var x : OclAny := null; var y : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,m,x,y,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var gcd : long := (a)->gcd(b) ; a := a div gcd ; b := b div gcd ; var max_ratio : OclAny := Set{n div a, m div b}->min() ; a := a * max_ratio ; b := b * max_ratio ; var x1 : OclAny := Set{0, Set{x - (a + 1) div 2, n - a}->min()}->max() ; var y1 : OclAny := Set{0, Set{y - (b + 1) div 2, m - b}->min()}->max() ; execute (x1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import gcd n,m,x,y,a,b=map(int,input().split()) k=gcd(a,b) a//=k b//=k times=min(n//a,m//b) a*=times b*=times x1=x-(a+1)//2 y1=y-(b+1)//2 if x1<0 : x1=0 if y1<0 : y1=0 if x1+a>n : x1-=(x1+a-n) if y1+b>m : y1-=(y1+b-m) print(x1,y1,x1+a,y1+b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; var x : OclAny := null; var y : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,m,x,y,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : OclAny := gcd(a, b) ; a := a div k ; b := b div k ; var times : OclAny := Set{n div a, m div b}->min() ; a := a * times ; b := b * times ; var x1 : double := x - (a + 1) div 2 ; var y1 : double := y - (b + 1) div 2 ; if x1 < 0 then ( x1 := 0 ) else skip ; if y1 < 0 then ( y1 := 0 ) else skip ; if (x1 + a->compareTo(n)) > 0 then ( x1 := x1 - (x1 + a - n) ) else skip ; if (y1 + b->compareTo(m)) > 0 then ( y1 := y1 - (y1 + b - m) ) else skip ; execute (x1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import gcd n,m,x,y,a,b=map(int,input().split()) g=gcd(a,b) a,b=a//g,b//g k=min(n//a,m//b) a,b=k*a,k*b x1,x2=x-(a-a//2),x+a//2 y1,y2=y-(b-b//2),y+b//2 d=max(0,0-x1) x1,x2=x1+d,x2+d d=max(0,x2-n) x1,x2=x1-d,x2-d d=max(0,0-y1) y1,y2=y1+d,y2+d d=max(0,y2-m) y1,y2=y1-d,y2-d print(" ".join(map(str,[x1,y1,x2,y2]))); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; var x : OclAny := null; var y : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,m,x,y,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var g : OclAny := gcd(a, b) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{a div g,b div g} ; var k : OclAny := Set{n div a, m div b}->min() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{k * a,k * b} ; var x1 : OclAny := null; var x2 : OclAny := null; Sequence{x1,x2} := Sequence{x - (a - a div 2),x + a div 2} ; var y1 : OclAny := null; var y2 : OclAny := null; Sequence{y1,y2} := Sequence{y - (b - b div 2),y + b div 2} ; var d : OclAny := Set{0, 0 - x1}->max() ; var x1 : OclAny := null; var x2 : OclAny := null; Sequence{x1,x2} := Sequence{x1 + d,x2 + d} ; d := Set{0, x2 - n}->max() ; var x1 : OclAny := null; var x2 : OclAny := null; Sequence{x1,x2} := Sequence{x1 - d,x2 - d} ; d := Set{0, 0 - y1}->max() ; var y1 : OclAny := null; var y2 : OclAny := null; Sequence{y1,y2} := Sequence{y1 + d,y2 + d} ; d := Set{0, y2 - m}->max() ; var y1 : OclAny := null; var y2 : OclAny := null; Sequence{y1,y2} := Sequence{y1 - d,y2 - d} ; execute (StringLib.sumStringsWithSeparator(((Sequence{x1}->union(Sequence{y1}->union(Sequence{x2}->union(Sequence{ y2 }))))->collect( _x | (OclType["String"])->apply(_x) )), " "))->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import gcd n,m,x,y,a,b=map(int,input().split()) r=gcd(a,b) a,b=a//r,b//r r=min(n//a,m//b) a,b=a*r,b*r cx,cy=(a+1)//2,(b+1)//2 dx,dy=min(n-a,max(cx,x)-cx),min(m-b,max(cy,y)-cy) print(dx,dy,a+dx,b+dy) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; var x : OclAny := null; var y : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,m,x,y,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var r : OclAny := gcd(a, b) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{a div r,b div r} ; r := Set{n div a, m div b}->min() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{a * r,b * r} ; var cx : OclAny := null; var cy : OclAny := null; Sequence{cx,cy} := Sequence{(a + 1) div 2,(b + 1) div 2} ; var dx : OclAny := null; var dy : OclAny := null; Sequence{dx,dy} := Sequence{Set{n - a, Set{cx, x}->max() - cx}->min(),Set{m - b, Set{cy, y}->max() - cy}->min()} ; execute (dx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lps(str): n=len(str) L=[[0 for x in range(n)]for x in range(n)] for i in range(n): L[i][i]=1 for cl in range(2,n+1): for i in range(n-cl+1): j=i+cl-1 if str[i]==str[j]and cl==2 : L[i][j]=2 elif str[i]==str[j]: L[i][j]=L[i+1][j-1]+2 else : L[i][j]=max(L[i][j-1],L[i+1][j]); return L[0][n-1] seq="GEEKS FOR GEEKS" n=len(seq) print("The length of the LPS is "+str(lps(seq))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var seq : String := "GEEKS FOR GEEKS" ; n := (seq)->size() ; execute ("The length of the LPS is " + ("" + ((lps(seq)))))->display(); operation lps(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var n : int := (OclType["String"])->size() ; var L : Sequence := Integer.subrange(0, n-1)->select(x | true)->collect(x | (Integer.subrange(0, n-1)->select(x | true)->collect(x | (0)))) ; for i : Integer.subrange(0, n-1) do ( L[i+1][i+1] := 1) ; for cl : Integer.subrange(2, n + 1-1) do ( for i : Integer.subrange(0, n - cl + 1-1) do ( var j : double := i + cl - 1 ; if ("" + ([i+1])) = ("" + ([j+1])) & cl = 2 then ( L[i+1][j+1] := 2 ) else (if ("" + ([i+1])) = ("" + ([j+1])) then ( L[i+1][j+1] := L[i + 1+1][j - 1+1] + 2 ) else ( L[i+1][j+1] := Set{L[i+1][j - 1+1], L[i + 1+1][j+1]}->max(); ) ) )) ; return L->first()[n - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import gcd n,m,x,y,a,b=map(int,input().split()) r=gcd(a,b) a,b=a//r,b//r r=min(n//a,m//b) a,b=a*r,b*r cx,cy=(a+1)//2,(b+1)//2 dx,dy=min(n-a,max(cx,x)-cx),min(m-b,max(cy,y)-cy) print(dx,dy,a+dx,b+dy) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; var x : OclAny := null; var y : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,m,x,y,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var r : OclAny := gcd(a, b) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{a div r,b div r} ; r := Set{n div a, m div b}->min() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{a * r,b * r} ; var cx : OclAny := null; var cy : OclAny := null; Sequence{cx,cy} := Sequence{(a + 1) div 2,(b + 1) div 2} ; var dx : OclAny := null; var dy : OclAny := null; Sequence{dx,dy} := Sequence{Set{n - a, Set{cx, x}->max() - cx}->min(),Set{m - b, Set{cy, y}->max() - cy}->min()} ; execute (dx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countOccurrances(n,d): count=0 while(n>0): if(n % 10==d): count=count+1 n=n//10 return count d=2 n=214215421 print(countOccurrances(n,d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; d := 2 ; n := 214215421 ; execute (countOccurrances(n, d))->display(); operation countOccurrances(n : OclAny, d : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while (n > 0) do ( if (n mod 10 = d) then ( count := count + 1 ) else skip ; n := n div 10) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys class Segment(object): __slots__=('source','target') def __init__(self,source,target): self.source=complex(source) self.target=complex(target) def cross(a,b): return a.real*b.imag-a.imag*b.real def dot(a,b): return a.real*b.real+a.imag*b.imag def get_cross_point(s1,s2): base_vector=s2.target-s2.source d1=abs(cross(base_vector,s1.source-s2.source)) d2=abs(cross(base_vector,s1.target-s2.source)) t=d1/(d1+d2) cross_point=s1.source+(s1.target-s1.source)*t print('{real:.10f}{imag:.10f}'.format(real=cross_point.real,imag=cross_point.imag)) return None def solve(_lines): for line in _lines : line=tuple(map(int,line)) p0,p1,p2,p3=(x+y*1j for x,y in zip(line[: : 2],line[1 : : 2])) s1,s2=Segment(p0,p1),Segment(p2,p3) get_cross_point(s1,s2) return None if __name__=='__main__' : _input=sys.stdin.readlines() l_num=int(_input[0]) lines=map(lambda x : x.split(),_input[1 :]) solve(lines) ------------------------------------------------------------ OCL File: --------- class Segment extends object { static operation newSegment() : Segment pre: true post: Segment->exists( _x | result = _x ); static attribute __slots__ : OclAny := Sequence{'source', 'target'}; attribute source : OclAny := complex(source); attribute target : OclAny := complex(target); operation initialise(source : OclAny,target : OclAny) : pre: true post: true activity: self.source := complex(source) ; self.target := complex(target); return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var _input : OclAny := (OclFile["System.in"]).readlines() ; var l_num : int := ("" + ((_input->first())))->toInteger() ; var lines : Sequence := (_input->tail())->collect( _x | (lambda x : OclAny in (x.split()))->apply(_x) ) ; solve(lines) ) else skip; operation cross(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a.real * b.imag - a.imag * b.real; operation dot(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a.real * b.real + a.imag * b.imag; operation get_cross_point(s1 : OclAny, s2 : OclAny) : OclAny pre: true post: true activity: var base_vector : double := s2.target - s2.source ; var d1 : double := (cross(base_vector, s1.source - s2.source))->abs() ; var d2 : double := (cross(base_vector, s1.target - s2.source))->abs() ; var t : double := d1 / (d1 + d2) ; var cross_point : OclAny := s1.source + (s1.target - s1.source) * t ; execute (StringLib.interpolateStrings('{real:.10f}{imag:.10f}', Sequence{(argument (test (logical_test (comparison (expr (atom (name real)))))) = (test (logical_test (comparison (expr (atom (name cross_point)) (trailer . (name real))))))), (argument (test (logical_test (comparison (expr (atom (name imag)))))) = (test (logical_test (comparison (expr (atom (name cross_point)) (trailer . (name imag)))))))}))->display() ; return null; operation solve(_lines : OclAny) : OclAny pre: true post: true activity: for line : _lines do ( var line : Sequence := ((line)->collect( _x | (OclType["int"])->apply(_x) )) ; var p0 : OclAny := null; var p1 : OclAny := null; var p2 : OclAny := null; var p3 : OclAny := null; Sequence{p0,p1,p2,p3} := Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (expr (atom (name y))) * (expr (atom (number 1j)))))))) (comp_for for (exprlist (expr (atom (name x))) , (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name line)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name line)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) ])))))))) ))))))))} ; Sequence{s1,s2} := Sequence{(Segment.newSegment()).initialise(p0, p1),(Segment.newSegment()).initialise(p2, p3)} ; get_cross_point(s1, s2)) ; return null; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,q=map(int,input().split()) s=input() s=list(s) str_=0 ans=set() for i in range(n-2): if s[i]+s[i+1]+s[i+2]=='abc' : str_+=1 s=['0']+['0']+s+['0']+['0'] for i in range(q): pos,c=map(str,input().split()) pos=int(pos) pos+=1 if s[pos]+s[pos+1]+s[pos+2]=='abc' or s[pos-1]+s[pos]+s[pos+1]=='abc' or s[pos-2]+s[pos-1]+s[pos]=='abc' : if s[pos]!=c : s[pos]=c if s[pos]+s[pos+1]+s[pos+2]=='abc' or s[pos-1]+s[pos]+s[pos+1]=='abc' or s[pos-2]+s[pos-1]+s[pos]=='abc' : pass else : str_-=1 else : s[pos]=c if s[pos]+s[pos+1]+s[pos+2]=='abc' or s[pos-1]+s[pos]+s[pos+1]=='abc' or s[pos-2]+s[pos-1]+s[pos]=='abc' : str_+=1 print(str_) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; s := (s)->characters() ; var str_ : int := 0 ; var ans : Set := Set{}->union(()) ; for i : Integer.subrange(0, n - 2-1) do ( if s[i+1] + s[i + 1+1] + s[i + 2+1] = 'abc' then ( str_ := str_ + 1 ) else skip) ; s := Sequence{ '0' }->union(Sequence{ '0' })->union(s)->union(Sequence{ '0' })->union(Sequence{ '0' }) ; for i : Integer.subrange(0, q-1) do ( var pos : OclAny := null; var c : OclAny := null; Sequence{pos,c} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; var pos : int := ("" + ((pos)))->toInteger() ; pos := pos + 1 ; if s[pos+1] + s[pos + 1+1] + s[pos + 2+1] = 'abc' or s[pos - 1+1] + s[pos+1] + s[pos + 1+1] = 'abc' or s[pos - 2+1] + s[pos - 1+1] + s[pos+1] = 'abc' then ( if s[pos+1] /= c then ( s[pos+1] := c ; if s[pos+1] + s[pos + 1+1] + s[pos + 2+1] = 'abc' or s[pos - 1+1] + s[pos+1] + s[pos + 1+1] = 'abc' or s[pos - 2+1] + s[pos - 1+1] + s[pos+1] = 'abc' then ( skip ) else ( str_ := str_ - 1 ) ) else skip ) else ( s[pos+1] := c ; if s[pos+1] + s[pos + 1+1] + s[pos + 2+1] = 'abc' or s[pos - 1+1] + s[pos+1] + s[pos + 1+1] = 'abc' or s[pos - 2+1] + s[pos - 1+1] + s[pos+1] = 'abc' then ( str_ := str_ + 1 ) else skip ) ; execute (str_)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check_a(l,i): if i>=len(l)-2 : return False else : if l[i+1]=='b' and l[i+2]=='c' : return True return False def check_b(l,i): if i==0 or i==len(l)-1 : return False else : if l[i-1]=='a' and l[i+1]=='c' : return True return False def check_c(l,i): if i<2 : return False else : if l[i-1]=='b' and l[i-2]=='a' : return True return False def fun(l,idx): if l[idx]=='a' : return check_a(l,idx) elif l[idx]=='b' : return check_b(l,idx) else : return check_c(l,idx) n,q=map(int,input().split()) s=input().rstrip() l=[x for x in s] count=i=0 while icollect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := input().rstrip() ; l := s->select(x | true)->collect(x | (x)) ; var count : OclAny := 0; i := 0 ; while (i->compareTo(n - 2)) < 0 do ( if l[i+1] = 'a' & l[i + 1+1] = 'b' & l[i + 2+1] = 'c' then ( count := count + 1 ; i := i + 3 ) else ( i := i + 1 )) ; for z : Integer.subrange(0, q-1) do ( var c : OclAny := null; Sequence{idx,c} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; idx := ("" + ((idx)))->toInteger() - 1 ; if c = l[idx+1] then ( execute (count)->display() ) else ( var ans : OclAny := fun(l, idx) ; if ans then ( count := count - 1 ) else skip ; l[idx+1] := c ; var ans2 : OclAny := fun(l, idx) ; if ans2 then ( count := count + 1 ) else skip ; execute (count)->display() )); operation check_a(l : OclAny, i : OclAny) : OclAny pre: true post: true activity: if (i->compareTo((l)->size() - 2)) >= 0 then ( return false ) else ( if l[i + 1+1] = 'b' & l[i + 2+1] = 'c' then ( return true ) else skip ; return false ); operation check_b(l : OclAny, i : OclAny) : OclAny pre: true post: true activity: if i = 0 or i = (l)->size() - 1 then ( return false ) else ( if l[i - 1+1] = 'a' & l[i + 1+1] = 'c' then ( return true ) else skip ; return false ); operation check_c(l : OclAny, i : OclAny) : OclAny pre: true post: true activity: if i < 2 then ( return false ) else ( if l[i - 1+1] = 'b' & l[i - 2+1] = 'a' then ( return true ) else skip ; return false ); operation fun(l : OclAny, idx : OclAny) : OclAny pre: true post: true activity: if l[idx+1] = 'a' then ( return check_a(l, idx) ) else (if l[idx+1] = 'b' then ( return check_b(l, idx) ) else ( return check_c(l, idx) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n,m=map(int,input().split('')) a=list(input()) num=0 for i in range(n-2): if(''.join(a[i : i+3])=='abc'): num+=1 for i in range(m): index,ch=input().split('') index=int(index)-1 for j in range(max(0,index-2),index+1): if(''.join(a[j : j+3])=='abc'): num-=1 a[index]=ch for j in range(max(0,index-2),index+1): if(''.join(a[j : j+3])=='abc'): num+=1 print(num) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split(''))->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var num : int := 0 ; for i : Integer.subrange(0, n - 2-1) do ( if (StringLib.sumStringsWithSeparator((a.subrange(i+1, i + 3)), '') = 'abc') then ( num := num + 1 ) else skip) ; for i : Integer.subrange(0, m-1) do ( var index : OclAny := null; var ch : OclAny := null; Sequence{index,ch} := input().split('') ; var index : double := ("" + ((index)))->toInteger() - 1 ; for j : Integer.subrange(Set{0, index - 2}->max(), index + 1-1) do ( if (StringLib.sumStringsWithSeparator((a.subrange(j+1, j + 3)), '') = 'abc') then ( num := num - 1 ) else skip) ; a[index+1] := ch ; for j : Integer.subrange(Set{0, index - 2}->max(), index + 1-1) do ( if (StringLib.sumStringsWithSeparator((a.subrange(j+1, j + 3)), '') = 'abc') then ( num := num + 1 ) else skip) ; execute (num)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,q=map(int,input().split()) s=input() ans=s.count("abc") l=list(s) for j in range(q): i,c=map(str,input().split()) ind=int(i)-1 if l[ind : ind+3]==["a",'b','c']: ans-=1 elif l[ind-1 : ind+2]==["a",'b','c']: ans-=1 elif l[ind-2 : ind+1]==["a",'b','c']: ans-=1 l[int(i)-1]=c if l[ind : ind+3]==["a",'b','c']: ans+=1 elif l[ind-1 : ind+2]==["a",'b','c']: ans+=1 elif l[ind-2 : ind+1]==["a",'b','c']: ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var ans : int := s->count("abc") ; var l : Sequence := (s)->characters() ; for j : Integer.subrange(0, q-1) do ( var i : OclAny := null; var c : OclAny := null; Sequence{i,c} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; var ind : double := ("" + ((i)))->toInteger() - 1 ; if l.subrange(ind+1, ind + 3) = Sequence{"a"}->union(Sequence{'b'}->union(Sequence{ 'c' })) then ( ans := ans - 1 ) else (if l.subrange(ind - 1+1, ind + 2) = Sequence{"a"}->union(Sequence{'b'}->union(Sequence{ 'c' })) then ( ans := ans - 1 ) else (if l.subrange(ind - 2+1, ind + 1) = Sequence{"a"}->union(Sequence{'b'}->union(Sequence{ 'c' })) then ( ans := ans - 1 ) else skip ) ) ; l[("" + ((i)))->toInteger() - 1+1] := c ; if l.subrange(ind+1, ind + 3) = Sequence{"a"}->union(Sequence{'b'}->union(Sequence{ 'c' })) then ( ans := ans + 1 ) else (if l.subrange(ind - 1+1, ind + 2) = Sequence{"a"}->union(Sequence{'b'}->union(Sequence{ 'c' })) then ( ans := ans + 1 ) else (if l.subrange(ind - 2+1, ind + 1) = Sequence{"a"}->union(Sequence{'b'}->union(Sequence{ 'c' })) then ( ans := ans + 1 ) else skip ) ) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) re=[] for i in range(a): n,k=input().split() n=int(n) k=int(k) arr1=[int(arr1)for arr1 in input().split()] arr2=[int(arr2)for arr2 in input().split()] arr1.sort() r1=0 newarr=[] if(k==0): re.append(sum(arr1)) else : while len(newarr)0): m1=max(arr1) m2=max(arr2) if(m1>=m2): newarr.append(arr1.pop(arr1.index(m1))) else : newarr.append(arr2.pop(arr2.index(m2))) k=k-1 else : newarr=newarr+arr1[len(arr1)-1 : len(arr1)-1-(n-len(newarr)):-1] re.append(sum(newarr)) for i in re : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var re : Sequence := Sequence{} ; for i : Integer.subrange(0, a-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var k : int := ("" + ((k)))->toInteger() ; var arr1 : Sequence := input().split()->select(arr1 | true)->collect(arr1 | (("" + ((arr1)))->toInteger())) ; var arr2 : Sequence := input().split()->select(arr2 | true)->collect(arr2 | (("" + ((arr2)))->toInteger())) ; arr1 := arr1->sort() ; var r1 : int := 0 ; var newarr : Sequence := Sequence{} ; if (k = 0) then ( execute (((arr1)->sum()) : re) ) else ( while ((newarr)->size()->compareTo(n)) < 0 do ( if (k > 0) then ( var m1 : OclAny := (arr1)->max() ; var m2 : OclAny := (arr2)->max() ; if ((m1->compareTo(m2)) >= 0) then ( execute ((arr1->at((expr (atom (name arr1)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name m1)))))))) ))))+1)) : newarr) ) else ( execute ((arr2->at((expr (atom (name arr2)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name m2)))))))) ))))+1)) : newarr) ; k := k - 1 ) ) else ( newarr := newarr->union(arr1(subscript (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr1)))))))) )))) - (expr (atom (number (integer 1)))))))) : (test (logical_test (comparison (expr (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr1)))))))) )))) - (expr (atom (number (integer 1))))) - (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name newarr)))))))) ))))))))) ))))))) (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) )) ; execute (((newarr)->sum()) : re) )) ; for i : re do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,k=map(int,input().split()) l1=list(map(int,input().split())) l2=list(map(int,input().split())) l1.sort() l2.sort() for j in range(n): if(k==0): break if(l1[j]toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l1 := l1->sort() ; l2 := l2->sort() ; for j : Integer.subrange(0, n-1) do ( if (k = 0) then ( break ) else skip ; if ((l1[j+1]->compareTo(l2[n - j - 1+1])) < 0) then ( var l1[j+1] : OclAny := null; var l2[n - j - 1+1] : OclAny := null; Sequence{l1[j+1],l2[n - j - 1+1]} := Sequence{l2[n - j - 1+1],l1[j+1]} ; var k : double := k - 1 ) else skip) ; var m : int := 0 ; for z : Integer.subrange(0, n-1) do ( m := m + l1[z+1]) ; execute (m)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input())*3 arr=[] for _ in range(t): arr.append(list(map(int,input().split()))) def maximum(T): maxi=T[0] for i in range(1,len(T)): if maxiT[i]: mini=T[i] return mini def Somme(T): S=0 for i in range(len(T)): S+=T[i] return S for i in range(0,t-2,3): n,k=arr[i][0],arr[i][1] i+=1 a=arr[i] i+=1 b=arr[i] for _ in range(k): max=maximum(b) min=minimum(a) if mintoInteger() * 3 ; var arr : Sequence := Sequence{} ; for _anon : Integer.subrange(0, t-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : arr)) ; skip ; skip ; skip ; for i : Integer.subrange(0, t - 2-1)->select( $x | ($x - 0) mod 3 = 0 ) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := Sequence{arr[i+1]->first(),arr[i+1][1+1]} ; i := i + 1 ; var a : OclAny := arr[i+1] ; i := i + 1 ; var b : OclAny := arr[i+1] ; for _anon : Integer.subrange(0, k-1) do ( var max : OclAny := maximum(b) ; var min : OclAny := minimum(a) ; if (min->compareTo(max)) < 0 then ( var l : int := b->indexOf(max) - 1 ; var j : int := a->indexOf(min) - 1 ; var Aux : OclAny := b[l+1] ; b[l+1] := a[j+1] ; a[j+1] := Aux ) else skip) ; execute (Somme(a))->display()); operation maximum(T : OclAny) : OclAny pre: true post: true activity: var maxi : OclAny := T->first() ; for i : Integer.subrange(1, (T)->size()-1) do ( if (maxi->compareTo(T[i+1])) < 0 then ( maxi := T[i+1] ) else skip) ; return maxi; operation minimum(T : OclAny) : OclAny pre: true post: true activity: var mini : OclAny := T->first() ; for i : Integer.subrange(1, (T)->size()-1) do ( if (mini->compareTo(T[i+1])) > 0 then ( mini := T[i+1] ) else skip) ; return mini; operation Somme(T : OclAny) : OclAny pre: true post: true activity: var S : int := 0 ; for i : Integer.subrange(0, (T)->size()-1) do ( S := S + T[i+1]) ; return S; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import defaultdict from heapq import heappop,heappush n=int(sys.stdin.readline().split()[0]) A=defaultdict(list) ans=[] for query in sys.stdin : if query[0]=='0' : t,x=query[2 :].split() heappush(A[t],-int(x)) elif query[0]=='1' : if A[query[2 :-1]]: ans.append(f'{-A[query[2:-1]][0]}'+'\n') else : if A[query[2 :-1]]: heappop(A[query[2 :-1]]) sys.stdout.writelines(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var n : int := ("" + ((sys.stdin.readLine().split()->first())))->toInteger() ; var A : OclAny := defaultdict(OclType["Sequence"]) ; var ans : Sequence := Sequence{} ; for query : OclFile["System.in"] do ( if query->first() = '0' then ( var t : OclAny := null; var x : OclAny := null; Sequence{t,x} := query.subrange(2+1).split() ; heappush(A[t+1], -("" + ((x)))->toInteger()) ) else (if query->first() = '1' then ( if A[query.subrange(2+1, -1)+1] then ( execute ((StringLib.formattedString('{-A[query[2:-1]][0]}') + ' ') : ans) ) else skip ) else ( if A[query.subrange(2+1, -1)+1] then ( heappop(A[query.subrange(2+1, -1)+1]) ) else skip ) ) ) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name writelines) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : n,k=map(int,input().split()) arr1=[int(x)for x in input().split()] arr2=[int(y)for y in input().split()] arr1.sort() arr2.sort(reverse=True) for i in range(k): for j in range(n): if(arr2[j]>arr1[j]): arr1[j],arr2[j]=arr2[j],arr1[j] break t-=1 sum=0 for i in range(n): sum+=arr1[i] print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr1 : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var arr2 : Sequence := input().split()->select(y | true)->collect(y | (("" + ((y)))->toInteger())) ; arr1 := arr1->sort() ; arr2 := arr2->sort() ; for i : Integer.subrange(0, k-1) do ( for j : Integer.subrange(0, n-1) do ( if ((arr2[j+1]->compareTo(arr1[j+1])) > 0) then ( var arr1[j+1] : OclAny := null; var arr2[j+1] : OclAny := null; Sequence{arr1[j+1],arr2[j+1]} := Sequence{arr2[j+1],arr1[j+1]} ; break ) else skip)) ; t := t - 1 ; var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + arr1[i+1]) ; execute (sum)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for tc in range(T): n,k=map(int,input().split()) a=sorted(list(map(int,input().split()))) b=sorted(list(map(int,input().split())),reverse=True) i=0 j=0 while k and i-1 : if a[i]toInteger() ; for tc : Integer.subrange(0, T-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var i : int := 0 ; var j : int := 0 ; while k & (i->compareTo(n)) < 0 & j > -1 do ( if (a[i+1]->compareTo(b[j+1])) < 0 then ( var a[i+1] : OclAny := null; var b[j+1] : OclAny := null; Sequence{a[i+1],b[j+1]} := Sequence{b[j+1],a[i+1]} ; k := k - 1 ; i := i + 1 ; j := j + 1 ) else (if a[i+1] = b[j+1] then ( i := i + 1 ) else ( break ) ) ) ; execute ((a)->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,k=map(int,input().split()) if k>=n//2 : print(n*(n-1)//2) else : x=n-k*2 print(n*(n-1)//2-x*(x-1)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (k->compareTo(n div 2)) >= 0 then ( execute (n * (n - 1) div 2)->display() ) else ( var x : double := n - k * 2 ; execute (n * (n - 1) div 2 - x * (x - 1) div 2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def intersection_ll(s0,s1,t0,t1): x0,y0=s0 x1,y1=s1 X0,X1=t0 X1,Y1=t1 p=(x1-x0)*(y0-Y0)-(y1-y0)*(x0-X0) q=(x1-x0)*(Y1-Y0)-(y1-y0)*(X1-X0) return(X0+p*(X1-X0)/float(q),Y0+p*(Y1-Y0)/float(q)) n=int(input()) for i in range(n): x0,y0,x1,y1,X0,Y0,X1,Y1=map(int,input().split()) print("%.08f %.08f" % intersection_ll((x0,y0),(x1,y1),(X0,Y0),(X1,Y1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var x0 : OclAny := null; var y0 : OclAny := null; var x1 : OclAny := null; var y1 : OclAny := null; var X0 : OclAny := null; var Y0 : OclAny := null; var X1 : OclAny := null; var Y1 : OclAny := null; Sequence{x0,y0,x1,y1,X0,Y0,X1,Y1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (StringLib.format("%.08f %.08f",intersection_ll(Sequence{x0, y0}, Sequence{x1, y1}, Sequence{X0, Y0}, Sequence{X1, Y1})))->display()); operation intersection_ll(s0 : OclAny, s1 : OclAny, t0 : OclAny, t1 : OclAny) : OclAny pre: true post: true activity: var x0 : OclAny := null; var y0 : OclAny := null; Sequence{x0,y0} := s0 ; var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := s1 ; var X0 : OclAny := null; var X1 : OclAny := null; Sequence{X0,X1} := t0 ; var X1 : OclAny := null; var Y1 : OclAny := null; Sequence{X1,Y1} := t1 ; var p : double := (x1 - x0) * (y0 - Y0) - (y1 - y0) * (x0 - X0) ; var q : double := (x1 - x0) * (Y1 - Y0) - (y1 - y0) * (X1 - X0) ; return Sequence{X0 + p * (X1 - X0) / ("" + ((q)))->toReal(), Y0 + p * (Y1 - Y0) / ("" + ((q)))->toReal()}; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) c=max(n-2*k,0) s=n*(n-1)/2-c*(c-1)/2 print(int(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : OclAny := Set{n - 2 * k, 0}->max() ; var s : double := n * (n - 1) / 2 - c * (c - 1) / 2 ; execute (("" + ((s)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countOp(arr,n,k): operations=0 ; for i in range(1,n): if(abs(arr[i]-arr[i-1])>k): absDiff=abs(arr[i]-arr[i-1]); currOp=absDiff-k ; if(arr[i]union(Sequence{2}->union(Sequence{5}->union(Sequence{ 9 }))); ; n := (arr)->size(); ; k := 2; ; execute (countOp(arr, n, k))->display(); ) else skip; operation countOp(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var operations : int := 0; ; for i : Integer.subrange(1, n-1) do ( if (((arr[i+1] - arr[i - 1+1])->abs()->compareTo(k)) > 0) then ( var absDiff : double := (arr[i+1] - arr[i - 1+1])->abs(); ; var currOp : double := absDiff - k; ; if ((arr[i+1]->compareTo(arr[i - 1+1])) < 0) then ( arr[i+1] := arr[i+1] + currOp; ) else ( arr[i+1] := arr[i+1] - currOp; ) ; operations := operations + currOp; ) else skip) ; return operations;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys INT_MAX=sys.maxsize ; INT_MIN=-(sys.maxsize-1); def countOfSubarrays(arr,n): count=0 ; v=[0]*(n+1); for i in range(n): v[arr[i]]=i ; maximum=INT_MIN ; minimum=INT_MAX ; for i in range(1,n+1): maximum=max(maximum,v[i]); minimum=min(minimum,v[i]); if(maximum-minimumunion(Sequence{1}->union(Sequence{3}->union(Sequence{2}->union(Sequence{5}->union(Sequence{ 6 }))))); ; n := (arr)->size(); ; execute (countOfSubarrays(arr, n))->display(); ) else skip; operation countOfSubarrays(arr : OclAny, n : OclAny) pre: true post: true activity: var count : int := 0; ; var v : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); ; for i : Integer.subrange(0, n-1) do ( v[arr[i+1]+1] := i;) ; var maximum : OclAny := INT_MIN; ; var minimum : OclAny := INT_MAX; ; for i : Integer.subrange(1, n + 1-1) do ( maximum := Set{maximum, v[i+1]}->max(); ; minimum := Set{minimum, v[i+1]}->min(); ; if ((maximum - minimum->compareTo(i)) < 0) then ( count := count + 1; ) else skip) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) L=[0] R=[0] for i in range(n): l,r=map(int,input().split()) L.append(l) R.append(r) L.sort(reverse=True) R.sort() ans=0 tmp=0 for i in range(n): if L[i]-R[i]>0 : ans+=2*(L[i]-R[i]) else : print(ans) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var L : Sequence := Sequence{ 0 } ; var R : Sequence := Sequence{ 0 } ; for i : Integer.subrange(0, n-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((l) : L) ; execute ((r) : R)) ; L := L->sort() ; R := R->sort() ; var ans : int := 0 ; var tmp : int := 0 ; for i : Integer.subrange(0, n-1) do ( if L[i+1] - R[i+1] > 0 then ( ans := ans + 2 * (L[i+1] - R[i+1]) ) else ( execute (ans)->display() ; break )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) LRs=[] for i in range(N): L,R=map(int,input().split()) LRs+=[(L,R,i)] Ls=sorted(LRs) Rs=sorted(LRs,key=lambda x : x[1]) done=[False]*N iL=N-1 iR=0 ans1=0 xNow=0 while True : while iR=0 and done[Ls[iL][2]]: iL-=1 if iL<0 : break xNext=Ls[iL][0] if xNext=0 and done[Ls[iL][2]]: iL-=1 if iL<0 : break xNext=Ls[iL][0] if xNexttoInteger() ; var LRs : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var L : OclAny := null; var R : OclAny := null; Sequence{L,R} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; LRs := LRs + Sequence{ Sequence{L, R, i} }) ; var Ls : Sequence := LRs->sort() ; var Rs : Sequence := LRs->sortedBy($x | (lambda x : OclAny in (x[1+1]))->apply($x)) ; var done : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, N) ; var iL : double := N - 1 ; var iR : int := 0 ; var ans1 : int := 0 ; var xNow : int := 0 ; while true do ( while (iR->compareTo(N)) < 0 & done[Rs[iR+1][2+1]+1] do ( iR := iR + 1) ; if iR = N then ( break ) else skip ; var xNext : OclAny := Rs[iR+1][1+1] ; if (xNow->compareTo(xNext)) < 0 then ( break ) else skip ; ans1 := ans1 + xNow - xNext ; xNow := xNext ; done[Rs[iR+1][2+1]+1] := true ; while iL >= 0 & done[Ls[iL+1][2+1]+1] do ( iL := iL - 1) ; if iL < 0 then ( break ) else skip ; xNext := Ls[iL+1]->first() ; if (xNext->compareTo(xNow)) < 0 then ( break ) else skip ; ans1 := ans1 + xNext - xNow ; xNow := xNext ; done[Ls[iL+1][2+1]+1] := true) ; ans1 := ans1 + (xNow)->abs() ; done := MatrixLib.elementwiseMult(Sequence{ false }, N) ; iL := N - 1 ; iR := 0 ; var ans2 : int := 0 ; xNow := 0 ; while true do ( while iL >= 0 & done[Ls[iL+1][2+1]+1] do ( iL := iL - 1) ; if iL < 0 then ( break ) else skip ; xNext := Ls[iL+1]->first() ; if (xNext->compareTo(xNow)) < 0 then ( break ) else skip ; ans2 := ans2 + xNext - xNow ; xNow := xNext ; done[Ls[iL+1][2+1]+1] := true ; while (iR->compareTo(N)) < 0 & done[Rs[iR+1][2+1]+1] do ( iR := iR + 1) ; if iR = N then ( break ) else skip ; xNext := Rs[iR+1][1+1] ; if (xNow->compareTo(xNext)) < 0 then ( break ) else skip ; ans2 := ans2 + xNow - xNext ; xNow := xNext ; done[Rs[iR+1][2+1]+1] := true) ; ans2 := ans2 + (xNow)->abs() ; execute (Set{ans1, ans2}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) intervals=tuple(tuple(map(int,input().split()))for _ in range(N)) L=sorted((l for l,r in intervals)) R=sorted((r for l,r in intervals),reverse=True) def helper(L,R,turn): x=0 cost=0 T=[L,None,R] while True : y=T[turn+1].pop() if turn*(y-x)<0 : cost+=abs(x-y) x=y else : break turn*=-1 cost+=abs(x) return cost print(max(helper(L.copy(),R.copy(),t)for t in(-1,1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var intervals : Sequence := ((argument (test (logical_test (comparison (expr (atom (name tuple)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) ))))))))) ; var L : Sequence := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name l)))))) (comp_for for (exprlist (expr (atom (name l))) , (expr (atom (name r)))) in (logical_test (comparison (expr (atom (name intervals)))))))}->sort() ; var R : Sequence := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name r)))))) (comp_for for (exprlist (expr (atom (name l))) , (expr (atom (name r)))) in (logical_test (comparison (expr (atom (name intervals)))))))}->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; skip ; execute (((argument (test (logical_test (comparison (expr (atom (name helper)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)) (trailer . (name copy) (arguments ( )))))))) , (argument (test (logical_test (comparison (expr (atom (name R)) (trailer . (name copy) (arguments ( )))))))) , (argument (test (logical_test (comparison (expr (atom (name t)))))))) ))))))) (comp_for for (exprlist (expr (atom (name t)))) in (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom - (number (integer 1))))))) , (test (logical_test (comparison (expr (atom (number (integer 1)))))))) ))))))))->max())->display(); operation helper(L : OclAny, R : OclAny, turn : OclAny) : OclAny pre: true post: true activity: var x : int := 0 ; var cost : int := 0 ; var T : Sequence := Sequence{L}->union(Sequence{null}->union(Sequence{ R })) ; while true do ( var y : OclAny := T[turn + 1+1]->last() ; if turn * (y - x) < 0 then ( cost := cost + (x - y)->abs() ; x := y ) else ( break ) ; turn := turn * -1) ; cost := cost + (x)->abs() ; return cost; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heappush,heappop readline=open(0).readline writelines=open(1,'w').writelines N,Q=map(int,readline().split()) ans=[] A=[[]for i in range(N)] def push(t,x): heappush(A[t],-x) def get_max(t): A[t]and ans.append("%d\n" %-A[t][0]) def delete_max(t): A[t]and heappop(A[t]) C=[push,get_max,delete_max].__getitem__ for i in range(Q): t,*a=map(int,readline().split()) C(t)(*a) writelines(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := open(0).readline ; var writelines : OclAny := open(1, 'w').writelines ; var N : OclAny := null; var Q : OclAny := null; Sequence{N,Q} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := Sequence{} ; var A : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{})) ; skip ; skip ; skip ; var C : OclAny := Sequence{push}->union(Sequence{get_max}->union(Sequence{ delete_max })).__getitem__ ; for i : Integer.subrange(0, Q-1) do ( var a : OclAny := null; Sequence{t,a} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name C)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) ))) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; writelines(ans); operation push(t : OclAny, x : OclAny) pre: true post: true activity: heappush(A[t+1], -x); operation get_max(t : OclAny) pre: true post: true activity: (logical_test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ]))))) and (logical_test (comparison (expr (atom (name ans)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom "%d\n")) % (expr - (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))))) ))))))); operation delete_max(t : OclAny) pre: true post: true activity: (logical_test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ]))))) and (logical_test (comparison (expr (atom (name heappop)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])))))))) ))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,*LR=map(int,open(0).read().split()) L,R=LR[: : 2],LR[1 : : 2] L.sort(reverse=True) R.sort() ans=0 cur=0 for l,r in zip(L,R): ans=max(ans,cur+l,cur-r,cur+l-r) cur+=l-r print(2*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var LR : OclAny := null; Sequence{N,LR} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var L : OclAny := null; var R : OclAny := null; Sequence{L,R} := Sequence{LR(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))),LR(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))} ; L := L->sort() ; R := R->sort() ; var ans : int := 0 ; var cur : int := 0 ; for _tuple : Integer.subrange(1, L->size())->collect( _indx | Sequence{L->at(_indx), R->at(_indx)} ) do (var _indx : int := 1; var l : OclAny := _tuple->at(_indx); _indx := _indx + 1; var r : OclAny := _tuple->at(_indx); ans := Set{ans, cur + l, cur - r, cur + l - r}->max() ; cur := cur + l - r) ; execute (2 * ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin def li(): return map(int,stdin.readline().split()) def li_(): return map(lambda x : int(x)-1,stdin.readline().split()) def lf(): return map(float,stdin.readline().split()) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) n=ni() left=[] right=[] for _ in range(n): l,r=li() left.append(l) right.append(r) left.sort(reverse=True) right.sort(reverse=False) ans_l=0 last=0 for i in range(n): if left[i]-last<0 : ans_l+=abs(last) break else : ans_l+=(left[i]-last) last=left[i] if last-right[i]<0 : ans_l+=abs(last) break else : ans_l+=(last-right[i]) last=right[i] ans_r=0 last=0 for i in range(n): if last-right[i]<0 : ans_r+=abs(last) break else : ans_r+=(last-right[i]) last=right[i] if left[i]-last<0 : ans_r+=abs(last) break else : ans_r+=(left[i]-last) last=left[i] print(max(ans_l,ans_r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stdin : OclFile := OclFile["System.in"] ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := ni() ; var left : Sequence := Sequence{} ; var right : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := li() ; execute ((l) : left) ; execute ((r) : right)) ; left := left->sort() ; right := right->sort() ; var ans_l : int := 0 ; var last : int := 0 ; for i : Integer.subrange(0, n-1) do ( if left[i+1] - last < 0 then ( ans_l := ans_l + (last)->abs() ; break ) else ( ans_l := ans_l + (left[i+1] - last) ; last := left[i+1] ) ; if last - right[i+1] < 0 then ( ans_l := ans_l + (last)->abs() ; break ) else ( ans_l := ans_l + (last - right[i+1]) ; last := right[i+1] )) ; var ans_r : int := 0 ; last := 0 ; for i : Integer.subrange(0, n-1) do ( if last - right[i+1] < 0 then ( ans_r := ans_r + (last)->abs() ; break ) else ( ans_r := ans_r + (last - right[i+1]) ; last := right[i+1] ) ; if left[i+1] - last < 0 then ( ans_r := ans_r + (last)->abs() ; break ) else ( ans_r := ans_r + (left[i+1] - last) ; last := left[i+1] )) ; execute (Set{ans_l, ans_r}->max())->display(); operation li() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation li_() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ); operation lf() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ); operation ls() : OclAny pre: true post: true activity: return stdin.readLine().split(); operation ns() : OclAny pre: true post: true activity: return stdin.readLine().rstrip(); operation lc() : OclAny pre: true post: true activity: return (ns()); operation ni() : OclAny pre: true post: true activity: return ("" + ((stdin.readLine())))->toInteger(); operation nf() : OclAny pre: true post: true activity: return ("" + ((stdin.readLine())))->toReal(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def display(n): for i in range(n): for j in range((n//2)+1): if((j==0 or j==n//2)and i!=0 or i==0 and j!=0 and j!=n//2 or i==n//2): print("*",end="") else : print("",end="") print() display(7) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; display(7); operation display(n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, (n div 2) + 1-1) do ( if ((j = 0 or j = n div 2) & i /= 0 or i = 0 & j /= 0 & j /= n div 2 or i = n div 2) then ( execute ("*")->display() ) else ( execute ("")->display() )) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) temp=[int(x)for x in input().split()] l=[] f=[False]*n for i in range(1,n,1): l.append([temp[i],i]) l.sort(reverse=True) l.insert(0,[temp[0],0]) i=0 j=1 result=[] f[0]=True while(i0 : while(cap!=0 and jtoInteger() ; var temp : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var l : Sequence := Sequence{} ; var f : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ; for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( execute ((Sequence{temp[i+1]}->union(Sequence{ i })) : l)) ; l := l->sort() ; l := l.insertAt(0+1, Sequence{temp->first()}->union(Sequence{ 0 })) ; var i : int := 0 ; var j : int := 1 ; var result : Sequence := Sequence{} ; f->first() := true ; while ((i->compareTo(n)) < 0 & (j->compareTo(n)) < 0) do ( var cap : OclAny := l[i+1]->first() ; var per : OclAny := l[i+1][1+1] ; if f[per+1] & cap > 0 then ( while (cap /= 0 & (j->compareTo(n)) < 0) do ( execute ((Sequence{per}->union(Sequence{ l[j+1][1+1] })) : result) ; f[l[j+1][1+1]+1] := true ; cap := cap - 1 ; j := j + 1) ) else ( break ) ; i := i + 1) ; if j = n then ( var le : int := (result)->size() ; execute (le)->display() ; for i : Integer.subrange(0, le-1) do ( execute (result[i+1]->first() + 1)->display()) ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") n=int(input()) for k in range(n): x1,y1,x2,y2,x3,y3,x4,y4=[int(_)for _ in input().split()] x=((x1*y2-y1*x2)*(x3-x4)-(x1-x2)*(x3*y4-y3*x4))/((x1-x2)*(y3-y4)-(y1-y2)*(x3-x4)) y=((x1*y2-y1*x2)*(y3-y4)-(y1-y2)*(x3*y4-y3*x4))/((x1-x2)*(y3-y4)-(y1-y2)*(x3-x4)) print("%.10f %.10f" %(x,y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for k : Integer.subrange(0, n-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; var x3 : OclAny := null; var y3 : OclAny := null; var x4 : OclAny := null; var y4 : OclAny := null; Sequence{x1,y1,x2,y2,x3,y3,x4,y4} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var x : double := ((x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4)) / ((x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4)) ; var y : double := ((x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4)) / ((x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4)) ; execute (StringLib.format("%.10f %.10f",Sequence{x, y}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) vals=list(map(int,input().split())) vals=[(i,vals[i])for i in range(n)] vals=[vals[0]]+sorted(vals[1 :],key=lambda x : x[1],reverse=True) most_left_idx=0 count=0 output='' for i in range(n): if(most_left_idx>=i): for j in range(1,vals[i][1]+1): if(most_left_idx+j=n-1): print(count) print(output) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var vals : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; vals := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{i, vals[i+1]})) ; vals := Sequence{ vals->first() }->union(vals->tail()->sortedBy($x | (lambda x : OclAny in (x[1+1]))->apply($x))) ; var most_left_idx : int := 0 ; var count : int := 0 ; var output : String := '' ; for i : Integer.subrange(0, n-1) do ( if ((most_left_idx->compareTo(i)) >= 0) then ( for j : Integer.subrange(1, vals[i+1][1+1] + 1-1) do ( if ((most_left_idx + j->compareTo(n)) < 0) then ( count := count + 1 ; output := output + StringLib.interpolateStrings('{}{} ', Sequence{vals[i+1]->first() + 1, vals[most_left_idx + j+1]->first() + 1}) ) else skip) ; most_left_idx := most_left_idx + vals[i+1][1+1] ) else skip) ; if ((most_left_idx->compareTo(n - 1)) >= 0) then ( execute (count)->display() ; execute (output)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=[int(x)for x in input().split()] if arr[0]==0 or sum(arr)toInteger() ; var arr : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if arr->first() = 0 or ((arr)->sum()->compareTo(n - 1)) < 0 then ( execute (-1)->display() ; exit() ) else skip ; var lis : Sequence := Sequence{} ; var z : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] /= 0 then ( execute ((Sequence{arr[i+1]}->union(Sequence{ i + 1 })) : lis) ) else ( execute ((Sequence{arr[i+1]}->union(Sequence{ i + 1 })) : z) )) ; for t : z do ( execute ((t) : lis)) ; var item : OclAny := lis->first()->first() ; var i : int := 0 ; var j : int := 1 ; var count : int := 0 ; execute (n - 1)->display() ; while (count /= n - 1) do ( execute (lis[i+1][1+1])->display() ; j := j + 1 ; count := count + 1 ; lis[i+1]->first() := lis[i+1]->first() - 1 ; if lis[i+1]->first() = 0 then ( i := i + 1 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMinimumDeletion(l,r,dp,s): if l>r : return 0 if l==r : return 1 if dp[l][r]!=-1 : return dp[l][r] res=1+findMinimumDeletion(l+1,r,dp,s) for i in range(l+1,r+1): if s[l]==s[i]: res=min(res,findMinimumDeletion(l+1,i-1,dp,s)+findMinimumDeletion(i,r,dp,s)) dp[l][r]=res return res if __name__=="__main__" : s="abcddcba" n=len(s) N=10 dp=[[-1 for i in range(N)]for j in range(N)] print(findMinimumDeletion(0,n-1,dp,s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "abcddcba" ; var n : int := (s)->size() ; var N : int := 10 ; dp := Integer.subrange(0, N-1)->select(j | true)->collect(j | (Integer.subrange(0, N-1)->select(i | true)->collect(i | (-1)))) ; execute (findMinimumDeletion(0, n - 1, dp, s))->display() ) else skip; operation findMinimumDeletion(l : OclAny, r : OclAny, dp : OclAny, s : OclAny) : OclAny pre: true post: true activity: if (l->compareTo(r)) > 0 then ( return 0 ) else skip ; if l = r then ( return 1 ) else skip ; if dp[l+1][r+1] /= -1 then ( return dp[l+1][r+1] ) else skip ; var res : int := 1 + findMinimumDeletion(l + 1, r, dp, s) ; for i : Integer.subrange(l + 1, r + 1-1) do ( if s[l+1] = s[i+1] then ( res := Set{res, findMinimumDeletion(l + 1, i - 1, dp, s) + findMinimumDeletion(i, r, dp, s)}->min() ) else skip) ; dp[l+1][r+1] := res ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) boats=[set(list(map(int,input().split()))[1 :])for _ in range(k)] r=int(input()) out=set() for _ in range(r): p,q=map(int,input().split()) for boat in boats : if p in boat and q in boat : out.add(p) out.add(q) break print(len(out)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var boats : Sequence := Integer.subrange(0, k-1)->select(_anon | true)->collect(_anon | (Set{}->union((OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->tail())))) ; var r : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var out : Set := Set{}->union(()) ; for _anon : Integer.subrange(0, r-1) do ( var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for boat : boats do ( if (boat)->includes(p) & (boat)->includes(q) then ( execute ((p) : out) ; execute ((q) : out) ; break ) else skip)) ; execute ((out)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) r=[0]*(n+1) for i in range(k): for x in list(map(int,input().split()))[1 :]: r[x]=i a=[0]*(n+1) for _ in range(int(input())): p,q=map(int,input().split()) if r[p]==r[q]: a[q]=a[p]=1 print(sum(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var r : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(0, k-1) do ( for x : OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->tail() do ( r[x+1] := i)) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if r[p+1] = r[q+1] then ( a[q+1] := 1; var a[p+1] : int := 1 ) else skip) ; execute ((a)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class MaxHeapInt(object): def __init__(self,val): self.val=val def __lt__(self,other): return self.val>other.val def __eq__(self,other): return self.val==other.val def __str__(self): return str(self.val) def resolve(): import heapq n,Q=[int(i)for i in input().split()] ans=[[]for _ in range(n)] for _ in range(Q): q=[int(i)for i in input().split()] if q[0]==0 : heapq.heappush(ans[q[1]],MaxHeapInt(q[2])) elif q[0]==1 : if len(ans[q[1]])>0 : print(ans[q[1]][0].val) else : if len(ans[q[1]])>0 : heapq.heappop(ans[q[1]]) resolve() ------------------------------------------------------------ OCL File: --------- class MaxHeapInt extends object { static operation newMaxHeapInt() : MaxHeapInt pre: true post: MaxHeapInt->exists( _x | result = _x ); attribute val : OclAny := val; operation initialise(val : OclAny) : pre: true post: true activity: self.val := val; return self; operation __lt__(other : OclAny) : OclAny pre: true post: true activity: return (self.val->compareTo(other.val)) > 0; operation __eq__(other : OclAny) : OclAny pre: true post: true activity: return self.val = other.val; operation __str__() : OclAny pre: true post: true activity: return ("" + ((self.val))); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; resolve(); operation resolve() pre: true post: true activity: skip ; var n : OclAny := null; var Q : OclAny := null; Sequence{n,Q} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, Q-1) do ( var q : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if q->first() = 0 then ( heapq.heappush(ans[q[1+1]+1], (MaxHeapInt.newMaxHeapInt()).initialise(q[2+1])) ) else (if q->first() = 1 then ( if (ans[q[1+1]+1])->size() > 0 then ( execute (ans[q[1+1]+1]->first().val)->display() ) else skip ) else ( if (ans[q[1+1]+1])->size() > 0 then ( heapq.heappop(ans[q[1+1]+1]) ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) r=[0]*(n+1) for i in range(k): for x in list(map(int,input().split()))[1 :]: r[x]=i a=[0]*(n+1) for _ in[0]*int(input()): p,q=map(int,input().split()) if r[p]==r[q]: a[q]=a[p]=1 print(sum(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var r : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(0, k-1) do ( for x : OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->tail() do ( r[x+1] := i)) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if r[p+1] = r[q+1] then ( a[q+1] := 1; var a[p+1] : int := 1 ) else skip) ; execute ((a)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) rabbit=[0]*n anger=[0]*n for i in range(k): m,*b=map(int,input().split()) for j in b : rabbit[j-1]=i+1 k=int(input()) for i in range(k): a,b=map(int,input().split()) if rabbit[a-1]==rabbit[b-1]: anger[a-1],anger[b-1]=1,1 print(sum(anger)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var rabbit : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var anger : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, k-1) do ( var m : OclAny := null; var b : OclAny := null; Sequence{m,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for j : b do ( rabbit[j - 1+1] := i + 1)) ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, k-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if rabbit[a - 1+1] = rabbit[b - 1+1] then ( var anger[a - 1+1] : OclAny := null; var anger[b - 1+1] : OclAny := null; Sequence{anger[a - 1+1],anger[b - 1+1]} := Sequence{1,1} ) else skip) ; execute ((anger)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(input()) mod=1000000007 c=[1]+[0]*3 for i in s : if i=='A' : c[1]=(c[1]+c[0])% mod elif i=='B' : c[2]=(c[2]+c[1])% mod elif i=='C' : c[3]=(c[3]+c[2])% mod else : c[3]=(c[3]*3+c[2])% mod c[2]=(c[2]*3+c[1])% mod c[1]=(c[1]*3+c[0])% mod c[0]=c[0]*3 % mod print(c[3]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var mod : int := 1000000007 ; var c : Sequence := Sequence{ 1 }->union(MatrixLib.elementwiseMult(Sequence{ 0 }, 3)) ; for i : s do ( if i = 'A' then ( c[1+1] := (c[1+1] + c->first()) mod mod ) else (if i = 'B' then ( c[2+1] := (c[2+1] + c[1+1]) mod mod ) else (if i = 'C' then ( c[3+1] := (c[3+1] + c[2+1]) mod mod ) else ( c[3+1] := (c[3+1] * 3 + c[2+1]) mod mod ; c[2+1] := (c[2+1] * 3 + c[1+1]) mod mod ; c[1+1] := (c[1+1] * 3 + c->first()) mod mod ; c->first() := c->first() * 3 mod mod ) ) ) ) ; execute (c[3+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=10**9+7 def main(): S=input() N=len(S) pre_hatena=S[: 1].count("?") a=S[: 1].count("A") post_hatena=S[2 :].count("?") c=S[2 :].count("C") ans=0 for i in range(1,N-1): if S[i]=="?" or S[i]=="B" : pre_pow=pow(3,pre_hatena-1,MOD) pre=((pre_pow*3)% MOD)*a+pre_pow*pre_hatena post_pow=pow(3,post_hatena-1,MOD) post=((post_pow*3)% MOD)*c+post_pow*post_hatena ans+=pre*post ans %=MOD if S[i]=="?" : pre_hatena+=1 if S[i]=="A" : a+=1 if S[i+1]=="?" : post_hatena-=1 if S[i+1]=="C" : c-=1 print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : double := (10)->pow(9) + 7 ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var N : int := (S)->size() ; var pre_hatena : OclAny := S.subrange(1,1)->count("?") ; var a : OclAny := S.subrange(1,1)->count("A") ; var post_hatena : OclAny := S.subrange(2+1)->count("?") ; var c : OclAny := S.subrange(2+1)->count("C") ; var ans : int := 0 ; for i : Integer.subrange(1, N - 1-1) do ( if S[i+1] = "?" or S[i+1] = "B" then ( var pre_pow : double := (3)->pow(pre_hatena - 1) ; var pre : double := ((pre_pow * 3) mod MOD) * a + pre_pow * pre_hatena ; var post_pow : double := (3)->pow(post_hatena - 1) ; var post : double := ((post_pow * 3) mod MOD) * c + post_pow * post_hatena ; ans := ans + pre * post ; ans := ans mod MOD ) else skip ; if S[i+1] = "?" then ( pre_hatena := pre_hatena + 1 ) else skip ; if S[i+1] = "A" then ( a := a + 1 ) else skip ; if S[i + 1+1] = "?" then ( post_hatena := post_hatena - 1 ) else skip ; if S[i + 1+1] = "C" then ( c := c - 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**7) limit=100000 mod=10**9+7 lpow=[False]*(limit+1) lpow[0]=1 def pow(n,p): if p<0 : return 0 if lpow[p]: return lpow[p] else : if p % 2==0 : ret=(pow(n,p//2)**2)% mod else : ret=((pow(n,p//2)**2)*n)% mod lpow[p]=ret return ret def main(): s=input() res=0 ca=0 cc=s.count("C") cw=0 aw=s.count("?") for c in s : if c=="A" : ca+=1 elif c=="C" : cc-=1 elif c=="B" : res+=ca*cc*pow(3,aw)+ca*(aw-cw)*pow(3,aw-1)+cw*cc*pow(3,aw-1)+cw*(aw-cw)*pow(3,aw-2) res %=mod elif c=="?" : res+=ca*cc*pow(3,aw-1)+ca*(aw-cw-1)*pow(3,aw-2)+cw*cc*pow(3,aw-2)+cw*(aw-cw-1)*pow(3,aw-3) res %=mod cw+=1 print(res) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var limit : int := 100000 ; var mod : double := (10)->pow(9) + 7 ; var lpow : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (limit + 1)) ; lpow->first() := 1 ; skip ; skip ; main(); operation pow(n : OclAny, p : OclAny) : OclAny pre: true post: true activity: if p < 0 then ( return 0 ) else skip ; if lpow[p+1] then ( return lpow[p+1] ) else ( if p mod 2 = 0 then ( var ret : int := (((n)->pow(p div 2))->pow(2)) mod mod ) else ( ret := ((((n)->pow(p div 2))->pow(2)) * n) mod mod ) ; lpow[p+1] := ret ; return ret ); operation main() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var res : int := 0 ; var ca : int := 0 ; var cc : int := s->count("C") ; var cw : int := 0 ; var aw : int := s->count("?") ; for c : s->characters() do ( if c = "A" then ( ca := ca + 1 ) else (if c = "C" then ( cc := cc - 1 ) else (if c = "B" then ( res := res + ca * cc * (3)->pow(aw) + ca * (aw - cw) * (3)->pow(aw - 1) + cw * cc * (3)->pow(aw - 1) + cw * (aw - cw) * (3)->pow(aw - 2) ; res := res mod mod ) else (if c = "?" then ( res := res + ca * cc * (3)->pow(aw - 1) + ca * (aw - cw - 1) * (3)->pow(aw - 2) + cw * cc * (3)->pow(aw - 2) + cw * (aw - cw - 1) * (3)->pow(aw - 3) ; res := res mod mod ; cw := cw + 1 ) else skip ) ) ) ) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countFreq(arr,n): visited=[False for i in range(n)] for i in range(n): if(visited[i]==True): continue count=1 for j in range(i+1,n,1): if(arr[i]==arr[j]): visited[j]=True count+=1 print(arr[i],count) if __name__=='__main__' : arr=[10,20,20,10,10,20,5,20] n=len(arr) countFreq(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{10}->union(Sequence{20}->union(Sequence{20}->union(Sequence{10}->union(Sequence{10}->union(Sequence{20}->union(Sequence{5}->union(Sequence{ 20 }))))))) ; n := (arr)->size() ; countFreq(arr, n) ) else skip; operation countFreq(arr : OclAny, n : OclAny) pre: true post: true activity: var visited : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (false)) ; for i : Integer.subrange(0, n-1) do ( if (visited[i+1] = true) then ( continue ) else skip ; var count : int := 1 ; for j : Integer.subrange(i + 1, n-1)->select( $x | ($x - i + 1) mod 1 = 0 ) do ( if (arr[i+1] = arr[j+1]) then ( visited[j+1] := true ; count := count + 1 ) else skip) ; execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): S=input() ans2=dp_simple(S) print(ans2) def dp_simple(S): n=len(S) MOD=10**9+7 dp=[[0]*(3+1)for _ in range(n+1)] dp[0][0]=1 for i in range(n): for j in range(3+1): m=1 if S[i]=="?" : m=3 dp[i+1][j]+=dp[i][j]*m dp[i+1][j]%=MOD if j<3 and(S[i]=="?" or S[i]=="ABC"[j]): dp[i+1][j+1]+=dp[i][j] dp[i+1][j+1]%=MOD ans=dp[n][3] return ans if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var ans2 : OclAny := dp_simple(S) ; execute (ans2)->display(); operation dp_simple(S : OclAny) : OclAny pre: true post: true activity: var n : int := (S)->size() ; var MOD : double := (10)->pow(9) + 7 ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (3 + 1)))) ; dp->first()->first() := 1 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, 3 + 1-1) do ( var m : int := 1 ; if S[i+1] = "?" then ( m := 3 ) else skip ; dp[i + 1+1][j+1] := dp[i + 1+1][j+1] + dp[i+1][j+1] * m ; dp[i + 1+1][j+1] := dp[i + 1+1][j+1] mod MOD ; if j < 3 & (S[i+1] = "?" or S[i+1] = "ABC"[j+1]) then ( dp[i + 1+1][j + 1+1] := dp[i + 1+1][j + 1+1] + dp[i+1][j+1] ; dp[i + 1+1][j + 1+1] := dp[i + 1+1][j + 1+1] mod MOD ) else skip)) ; var ans : OclAny := dp[n+1][3+1] ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- data=input() MOD=10**9+7 SLen=len(data) targets="ABC" array=[[0 for i in range(SLen+1)]for _ in range(4)] array[0][0]=1 for i in range(SLen): for j in range(4): if data[i]=='?' : if j<3 : array[j+1][i+1]=(array[j+1][i+1]+array[j][i])% MOD array[j][i+1]=(array[j][i+1]+array[j][i]*3)% MOD else : if j<3 and data[i]==targets[j]: array[j+1][i+1]=(array[j+1][i+1]+array[j][i])% MOD array[j][i+1]=(array[j][i+1]+array[j][i])% MOD print(array[3][SLen]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var data : String := (OclFile["System.in"]).readLine() ; var MOD : double := (10)->pow(9) + 7 ; var SLen : int := (data)->size() ; var targets : String := "ABC" ; var array : Sequence := Integer.subrange(0, 4-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, SLen + 1-1)->select(i | true)->collect(i | (0)))) ; array->first()->first() := 1 ; for i : Integer.subrange(0, SLen-1) do ( for j : Integer.subrange(0, 4-1) do ( if data[i+1] = '?' then ( if j < 3 then ( array[j + 1+1][i + 1+1] := (array[j + 1+1][i + 1+1] + array[j+1][i+1]) mod MOD ) else skip ; array[j+1][i + 1+1] := (array[j+1][i + 1+1] + array[j+1][i+1] * 3) mod MOD ) else ( if j < 3 & data[i+1] = targets[j+1] then ( array[j + 1+1][i + 1+1] := (array[j + 1+1][i + 1+1] + array[j+1][i+1]) mod MOD ) else skip ; array[j+1][i + 1+1] := (array[j+1][i + 1+1] + array[j+1][i+1]) mod MOD ))) ; execute (array[3+1][SLen+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def uniqueRows(s,m,n): i,j,count=0,0,0 for i in range(n): for j in range(i): if(s[i]==s[j]): count+=1 break if(count>=1): print("No") else : print("Yes") m=3 n=3 s=[[1,0,1],[0,0,0],[1,0,0]] uniqueRows(s,m,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; m := 3 ; n := 3 ; s := Sequence{Sequence{1}->union(Sequence{0}->union(Sequence{ 1 }))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{ Sequence{1}->union(Sequence{0}->union(Sequence{ 0 })) })) ; uniqueRows(s, m, n); operation uniqueRows(s : OclAny, m : OclAny, n : OclAny) pre: true post: true activity: var i : OclAny := null; var j : OclAny := null; var count : OclAny := null; Sequence{i,j,count} := Sequence{0,0,0} ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, i-1) do ( if (s[i+1] = s[j+1]) then ( count := count + 1 ; break ) else skip)) ; if (count >= 1) then ( execute ("No")->display() ) else ( execute ("Yes")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def PositionRightmostSetbit(n): position=1 m=1 while(not(n & m)): m=m<<1 position+=1 return position n=16 print(PositionRightmostSetbit(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 16 ; execute (PositionRightmostSetbit(n))->display(); operation PositionRightmostSetbit(n : OclAny) : OclAny pre: true post: true activity: var position : int := 1 ; var m : int := 1 ; while (not((MathLib.bitwiseAnd(n, m)))) do ( m := m * (2->pow(1)) ; position := position + 1) ; return position; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq def insert(t,x): global Qlist heapq.heappush(Qlist[t],-x) def getMax(t): global Qlist if Qlist[t]: num=Qlist[t][0] print(-num) def deleteMax(t): global Qlist if Qlist[t]: heapq.heappop(Qlist[t]) Qlist=[] n,q=map(int,input().split()) for i in range(n): Qi=[] heapq.heapify(Qi) Qlist.append(Qi) for i in range(q): queryi=list(map(int,input().split())) if queryi[0]==0 : insert(queryi[1],queryi[2]) elif queryi[0]==1 : getMax(queryi[1]) else : deleteMax(queryi[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute Qlist : OclAny; attribute Qlist : OclAny; attribute Qlist : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; Qlist := Sequence{} ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, n-1) do ( var Qi : Sequence := Sequence{} ; heapq.heapify(Qi) ; execute ((Qi) : Qlist)) ; for i : Integer.subrange(0, q-1) do ( var queryi : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if queryi->first() = 0 then ( insert(queryi[1+1], queryi[2+1]) ) else (if queryi->first() = 1 then ( getMax(queryi[1+1]) ) else ( deleteMax(queryi[1+1]) ) ) ); operation insert(t : OclAny, x : OclAny) pre: true post: true activity: skip ; heapq.heappush(Qlist[t+1], -x); operation getMax(t : OclAny) pre: true post: true activity: skip ; if Qlist[t+1] then ( var num : OclAny := Qlist[t+1]->first() ; execute (-num)->display() ) else skip; operation deleteMax(t : OclAny) pre: true post: true activity: skip ; if Qlist[t+1] then ( heapq.heappop(Qlist[t+1]) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMajority(arr,size): m={} for i in range(size): if arr[i]in m : m[arr[i]]+=1 else : m[arr[i]]=1 count=0 for key in m : if m[key]>size/2 : count=1 print("Majority found :-",key) break if(count==0): print("No Majority element") arr=[2,2,2,2,5,5,2,3,3] n=len(arr) findMajority(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{5}->union(Sequence{5}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 3 })))))))) ; var n : int := (arr)->size() ; findMajority(arr, n); operation findMajority(arr : OclAny, size : OclAny) pre: true post: true activity: var m : OclAny := Set{} ; for i : Integer.subrange(0, size-1) do ( if (m)->includes(arr[i+1]) then ( m[arr[i+1]+1] := m[arr[i+1]+1] + 1 ) else ( m[arr[i+1]+1] := 1 )) ; var count : int := 0 ; for key : m do ( if (m[key+1]->compareTo(size / 2)) > 0 then ( count := 1 ; execute ("Majority found :-")->display() ; break ) else skip) ; if (count = 0) then ( execute ("No Majority element")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rectanglearea(r): if r<0 : return-1 a=r*r return a if __name__=="__main__" : r=5 print(rectanglearea(r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( r := 5 ; execute (rectanglearea(r))->display() ) else skip; operation rectanglearea(r : OclAny) : OclAny pre: true post: true activity: if r < 0 then ( return -1 ) else skip ; var a : double := r * r ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ellipsearea(r): if(r<0): return-1 ; a=(3.14*r*r)/4 ; return a ; if __name__=="__main__" : r=5 ; print(ellipsearea(r)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( r := 5; ; execute (ellipsearea(r))->display(); ) else skip; operation ellipsearea(r : OclAny) pre: true post: true activity: if (r < 0) then ( return -1; ) else skip ; var a : double := (3.14 * r * r) / 4; ; return a;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) arr=list(map(int,input().split())) arr.sort(reverse=True) res=0 s=0 for i in range(12): if s>=k : break else : s+=arr[i] res+=1 if stoInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := arr->sort() ; var res : int := 0 ; var s : int := 0 ; for i : Integer.subrange(0, 12-1) do ( if (s->compareTo(k)) >= 0 then ( break ) else ( s := s + arr[i+1] ; res := res + 1 )) ; if (s->compareTo(k)) < 0 then ( execute (-1)->display() ) else ( execute (res)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=list(map(int,input().split())) b.sort(reverse=True) x=0 i=0 while i=a : print(i) else : print("-1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; b := b->sort() ; var x : int := 0 ; var i : int := 0 ; while (i->compareTo((b)->size())) < 0 & (x->compareTo(a)) < 0 do ( x := x + b[i+1] ; i := i + 1) ; if (x->compareTo(a)) >= 0 then ( execute (i)->display() ) else ( execute ("-1")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) a=list(map(int,input().split())) result=[] if sum(a)toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var result : Sequence := Sequence{} ; if ((a)->sum()->compareTo(k)) < 0 then ( execute (-1)->display() ; exit() ) else skip ; while ((result)->sum()->compareTo(k)) < 0 do ( execute (((a)->max()) : result) ; a := a->excludingAt(a->indexOf((a)->max()) - 1+1)) ; execute ((result)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: n,k,b,s=map(int,s.split()); s-=k*b ; x=s//n ; r=s % n ; print(*n*k-n>=s>=0 and[k*b+x]+r*[x+1]+(n-r-1)*[x]or[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var n : OclAny := null; var k : OclAny := null; var b : OclAny := null; var s : OclAny := null; Sequence{n,k,b,s} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ); s := s - k * b; var x : int := s div n; var r : int := s mod n; execute ((argument * (test (logical_test (logical_test (logical_test (comparison (comparison (comparison (expr (expr (expr (atom (name n))) * (expr (atom (name k)))) - (expr (atom (name n))))) >= (comparison (expr (atom (name s))))) >= (comparison (expr (atom (number (integer 0))))))) and (logical_test (comparison (expr (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name k))) * (expr (atom (name b)))) + (expr (atom (name x)))))))) ])) + (expr (expr (atom (name r))) * (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (number (integer 1))))))))) ])))) + (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name n))) - (expr (atom (name r)))) - (expr (atom (number (integer 1))))))))) ))) * (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name x))))))) ]))))))) or (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom - (number (integer 1)))))))) ]))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) a=list(input().split()) for i in range(len(a)): a[i]=int(a[i]) a.sort(reverse=True) sum=0 count=0 for i in a : sum+=i count+=1 if sum>=k : break if k==0 : print(0) elif sumtoInteger() ; var a : Sequence := (input().split()) ; for i : Integer.subrange(0, (a)->size()-1) do ( a[i+1] := ("" + ((a[i+1])))->toInteger()) ; a := a->sort() ; var sum : int := 0 ; var count : int := 0 ; for i : a do ( sum := sum + i ; count := count + 1 ; if (sum->compareTo(k)) >= 0 then ( break ) else skip) ; if k = 0 then ( execute (0)->display() ) else (if (sum->compareTo(k)) < 0 then ( execute (-1)->display() ) else ( execute (count)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def mergeSort(arr,n): temp_arr=[0]*n return _mergeSort(arr,temp_arr,0,n-1) def _mergeSort(arr,temp_arr,left,right): inv_count=0 if leftunion(Sequence{20}->union(Sequence{6}->union(Sequence{4}->union(Sequence{ 5 })))) ; n := (arr)->size() ; var result : OclAny := mergeSort(arr, n) ; execute ("Number of inversions are")->display(); operation mergeSort(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var temp_arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; return _mergeSort(arr, temp_arr, 0, n - 1); operation _mergeSort(arr : OclAny, temp_arr : OclAny, left : OclAny, right : OclAny) : OclAny pre: true post: true activity: var inv_count : int := 0 ; if (left->compareTo(right)) < 0 then ( var mid : int := (left + right) div 2 ; inv_count := inv_count + _mergeSort(arr, temp_arr, left, mid) ; inv_count := inv_count + _mergeSort(arr, temp_arr, mid + 1, right) ; inv_count := inv_count + merge(arr, temp_arr, left, mid, right) ) else skip ; return inv_count; operation merge(arr : OclAny, temp_arr : OclAny, left : OclAny, mid : OclAny, right : OclAny) : OclAny pre: true post: true activity: var i : OclAny := left ; var j : int := mid + 1 ; var k : OclAny := left ; inv_count := 0 ; while (i->compareTo(mid)) <= 0 & (j->compareTo(right)) <= 0 do ( if (arr[i+1]->compareTo(arr[j+1])) <= 0 then ( temp_arr[k+1] := arr[i+1] ; k := k + 1 ; i := i + 1 ) else ( temp_arr[k+1] := arr[j+1] ; inv_count := inv_count + (mid - i + 1) ; k := k + 1 ; j := j + 1 )) ; while (i->compareTo(mid)) <= 0 do ( temp_arr[k+1] := arr[i+1] ; k := k + 1 ; i := i + 1) ; while (j->compareTo(right)) <= 0 do ( temp_arr[k+1] := arr[j+1] ; k := k + 1 ; j := j + 1) ; for loop_var : Integer.subrange(left, right + 1-1) do ( arr[loop_var+1] := temp_arr[loop_var+1]) ; return inv_count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) for i in range(x): A=input().split() y=int(A[0]) z=int(A[1]) if y>=z : print("01"*(z)+'0'*(y-z)) else : print("01"*(y)+'1'*(z-y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, x-1) do ( var A : OclAny := input().split() ; var y : int := ("" + ((A->first())))->toInteger() ; var z : int := ("" + ((A[1+1])))->toInteger() ; if (y->compareTo(z)) >= 0 then ( execute (StringLib.nCopies("01", (z)) + StringLib.nCopies('0', (y - z)))->display() ) else ( execute (StringLib.nCopies("01", (y)) + StringLib.nCopies('1', (z - y)))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculate_min_sum(a,n): a.sort() min_sum=0 for i in range(1,n,2): min_sum+=abs(a[i]-a[i-1]) return min_sum def calculate_max_sum(a,n): a.sort() max_sum=0 for i in range(n//2): max_sum+=abs(a[n-1-i]-a[i]) return max_sum if __name__=="__main__" : a=[10,-10,20,-40] n=len(a) print("The minimum sum of pairs is",calculate_min_sum(a,n)) print("The maximum sum of pairs is",calculate_max_sum(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( a := Sequence{10}->union(Sequence{-10}->union(Sequence{20}->union(Sequence{ -40 }))) ; n := (a)->size() ; execute ("The minimum sum of pairs is")->display() ; execute ("The maximum sum of pairs is")->display() ) else skip; operation calculate_min_sum(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: a := a->sort() ; var min_sum : int := 0 ; for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( min_sum := min_sum + (a[i+1] - a[i - 1+1])->abs()) ; return min_sum; operation calculate_max_sum(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: a := a->sort() ; var max_sum : int := 0 ; for i : Integer.subrange(0, n div 2-1) do ( max_sum := max_sum + (a[n - 1 - i+1] - a[i+1])->abs()) ; return max_sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys tokens=''.join(sys.stdin.readlines()).split()[: :-1] def next(): return tokens.pop() def nextInt(): return int(next()) def nextFloat(): return float(next()) def getIntArray(n): return[nextInt()for _ in range(n)] def getFloatArray(n): return[nextFloat()for _ in range(n)] def getStringArray(n): return[next()for _ in range(n)] testcase=True def solve(testcase=1): a,b=nextInt(),nextInt() ans=["10"*min(a,b)] for i in range(min(a,b),a): ans.append('0') for i in range(min(a,b),b): ans.append('1') print(''.join(ans)) pass if testcase is None : testcaseCount=1 while tokens : solve(testcaseCount) testcaseCount+=1 else : testcaseCount=nextInt()if testcase else 1 for tc in range(testcaseCount): solve(tc+1) assert not tokens ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var tokens : OclAny := ''.join((OclFile["System.in"]).readlines()).split()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; skip ; skip ; skip ; skip ; skip ; skip ; var testcase : boolean := true ; skip ; if testcase <>= null then ( var testcaseCount : int := 1 ; while tokens do ( solve(testcaseCount) ; testcaseCount := testcaseCount + 1) ) else ( testcaseCount := if testcase then nextInt() else 1 endif ; for tc : Integer.subrange(0, testcaseCount-1) do ( solve(tc + 1)) ; assert not(tokens) do "assertion failed" ); operation next() : OclAny pre: true post: true activity: return tokens->last(); operation nextInt() : OclAny pre: true post: true activity: return ("" + ((().next())))->toInteger(); operation nextFloat() : OclAny pre: true post: true activity: return ("" + ((().next())))->toReal(); operation getIntArray(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (nextInt())); operation getFloatArray(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (nextFloat())); operation getStringArray(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (().next())); operation solve(testcase : int) pre: true post: true activity: if testcase->oclIsUndefined() then testcase := 1 else skip; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{nextInt(),nextInt()} ; var ans : Sequence := Sequence{ StringLib.nCopies("10", Set{a, b}->min()) } ; for i : Integer.subrange(Set{a, b}->min(), a-1) do ( execute (('0') : ans)) ; for i : Integer.subrange(Set{a, b}->min(), b-1) do ( execute (('1') : ans)) ; execute (StringLib.sumStringsWithSeparator((ans), ''))->display() ; skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): a,b=map(int,input().split('')) s='' while a>0 and b>0 : s+='10' a-=1 b-=1 if a>0 : s+='0'*a else : if b>0 : s+='1'*b print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split(''))->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := '' ; while a > 0 & b > 0 do ( s := s + '10' ; a := a - 1 ; b := b - 1) ; if a > 0 then ( s := s + StringLib.nCopies('0', a) ) else ( if b > 0 then ( s := s + StringLib.nCopies('1', b) ) else skip ) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): a,b=map(int,input().split()) ans="" for j in range(min(a,b)): ans+="01" if a>b : ans+="0"*(a-b) else : ans+="1"*(b-a) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : String := "" ; for j : Integer.subrange(0, Set{a, b}->min()-1) do ( ans := ans + "01") ; if (a->compareTo(b)) > 0 then ( ans := ans + StringLib.nCopies("0", (a - b)) ) else ( ans := ans + StringLib.nCopies("1", (b - a)) ) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a,b=list(map(int,input().split())) if a>=b : print("01"*b+"0"*(a-b)) else : print("10"*a+"1"*(b-a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (a->compareTo(b)) >= 0 then ( execute (StringLib.nCopies("01", b) + StringLib.nCopies("0", (a - b)))->display() ) else ( execute (StringLib.nCopies("10", a) + StringLib.nCopies("1", (b - a)))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def squareDigitSum(num): summ=0 num=int(num) squareNum=num*num while squareNum>0 : summ=summ+(squareNum % 10) squareNum=squareNum//10 return summ if __name__=="__main__" : N="1111" print(squareDigitSum(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var N : String := "1111" ; execute (squareDigitSum(N))->display() ) else skip; operation squareDigitSum(num : OclAny) : OclAny pre: true post: true activity: var summ : int := 0 ; num := ("" + ((num)))->toInteger() ; var squareNum : double := num * num ; while squareNum > 0 do ( summ := summ + (squareNum mod 10) ; squareNum := squareNum div 10) ; return summ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def quadrant(s): l=len(s) if('+' in s): i=s.index('+') else : i=s.index('-') real=s[0 : i] imaginary=s[i+1 : l-1] x=int(real) y=int(imaginary) if(x>0 and y>0): print("Quadrant 1") elif(x<0 and y>0): print("Quadrant 2") elif(x<0 and y<0): print("Quadrant 3") elif(x>0 and y<0): print("Quadrant 4") elif(x==0 and y>0): print("Lies on positive","Imaginary axis") elif(x==0 and y<0): print("Lies on negative","Imaginary axis") elif(y==0 and x<0): print("Lies on negative","X-axis") elif(y==0 and x>0): print("Lies on positive","X-axis") else : print("Lies on the Origin") if __name__=='__main__' : s="5+3i" quadrant(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( s := "5+3i" ; quadrant(s) ) else skip; operation quadrant(s : OclAny) pre: true post: true activity: var l : int := (s)->size() ; if ((s)->includes('+')) then ( var i : int := s->indexOf('+') - 1 ) else ( i := s->indexOf('-') - 1 ) ; var real : OclAny := s.subrange(0+1, i) ; var imaginary : OclAny := s.subrange(i + 1+1, l - 1) ; var x : int := ("" + ((real)))->toInteger() ; var y : int := ("" + ((imaginary)))->toInteger() ; if (x > 0 & y > 0) then ( execute ("Quadrant 1")->display() ) else (if (x < 0 & y > 0) then ( execute ("Quadrant 2")->display() ) else (if (x < 0 & y < 0) then ( execute ("Quadrant 3")->display() ) else (if (x > 0 & y < 0) then ( execute ("Quadrant 4")->display() ) else (if (x = 0 & y > 0) then ( execute ("Lies on positive")->display() ) else (if (x = 0 & y < 0) then ( execute ("Lies on negative")->display() ) else (if (y = 0 & x < 0) then ( execute ("Lies on negative")->display() ) else (if (y = 0 & x > 0) then ( execute ("Lies on positive")->display() ) else ( execute ("Lies on the Origin")->display() ) ) ) ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(Arr,n,M,K): flag=0 for i in range(n): if(Arr[i]==0): flag=1 if(K % 2!=0 and flag==0): return "No" else : return "Yes" ; if __name__=='__main__' : Arr=[1,1,2,4,7,8] M=5 ; K=6 ; n=len(Arr); print(check(Arr,n,M,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( Arr := Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{7}->union(Sequence{ 8 }))))) ; M := 5; ; K := 6; ; n := (Arr)->size(); ; execute (check(Arr, n, M, K))->display() ) else skip; operation check(Arr : OclAny, n : OclAny, M : OclAny, K : OclAny) : OclAny pre: true post: true activity: var flag : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (Arr[i+1] = 0) then ( flag := 1 ) else skip) ; if (K mod 2 /= 0 & flag = 0) then ( return "No" ) else ( return "Yes"; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: n,k,b,s=map(int,s.split()); s-=k*b ; x=s//n ; r=s % n ; print(*n*k-n>=s>=0 and[k*b+x]+r*[x+1]+(n-r-1)*[x]or[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var n : OclAny := null; var k : OclAny := null; var b : OclAny := null; var s : OclAny := null; Sequence{n,k,b,s} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ); s := s - k * b; var x : int := s div n; var r : int := s mod n; execute ((argument * (test (logical_test (logical_test (logical_test (comparison (comparison (comparison (expr (expr (expr (atom (name n))) * (expr (atom (name k)))) - (expr (atom (name n))))) >= (comparison (expr (atom (name s))))) >= (comparison (expr (atom (number (integer 0))))))) and (logical_test (comparison (expr (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name k))) * (expr (atom (name b)))) + (expr (atom (name x)))))))) ])) + (expr (expr (atom (name r))) * (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (number (integer 1))))))))) ])))) + (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name n))) - (expr (atom (name r)))) - (expr (atom (number (integer 1))))))))) ))) * (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name x))))))) ]))))))) or (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom - (number (integer 1)))))))) ]))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import log t=int(input()) for i in range(t): total=0 a,b=input().split() a,b=int(a),int(b) if(b==1): b+=1 total+=1 b0=b loga=log(a) while True : if loga//log(b)==loga//log(b+1): max=b break else : b+=1 total+=max-b0 while a!=0 : a//=b total+=1 print(total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var total : int := 0 ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{("" + ((a)))->toInteger(),("" + ((b)))->toInteger()} ; if (b = 1) then ( b := b + 1 ; total := total + 1 ) else skip ; var b0 : OclAny := b ; var loga : OclAny := log(a) ; while true do ( if loga div log(b) = loga div log(b + 1) then ( var max : OclAny := b ; break ) else ( b := b + 1 )) ; total := total + max - b0 ; while a /= 0 do ( a := a div b ; total := total + 1) ; execute (total)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def verif(a,b): c=0 if b>a : return 1 while a>0 : a=a//b c+=1 return c t=int(input()) for _ in range(t): a,b=map(int,input().split()) count=0 if b==1 : b+=1 count+=1 while verif(a,b)>verif(a,b+1): count+=1 b+=1 print(verif(a,b)+count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var count : int := 0 ; if b = 1 then ( b := b + 1 ; count := count + 1 ) else skip ; while (verif(a, b)->compareTo(verif(a, b + 1))) > 0 do ( count := count + 1 ; b := b + 1) ; execute (verif(a, b) + count)->display()); operation verif(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var c : int := 0 ; if (b->compareTo(a)) > 0 then ( return 1 ) else skip ; while a > 0 do ( a := a div b ; c := c + 1) ; return c; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) A=[int(x)for x in input().split()] m=int(input()) B=[int(x)for x in input().split()] ans=0 for i in range(min(len(A),len(B))): if A[i]B[i]: break else : if len(A)toInteger() ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : int := 0 ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name B)))))))) ))))))))) ))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) < (comparison (expr (atom (name B)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (stmt (simple_stmt (small_stmt break)))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) > (comparison (expr (atom (name B)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt break)))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)))))))) ))))) < (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name B)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))))))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_OPS=30 for _ in range(int(input())): a,b=[int(x)for x in input().split()] if b>a : print(1) continue min_ops=(a-b)+2 for i in range(0 if b>1 else 1,MAX_OPS+1): current_b=b+i current_ops=i current_a=a while current_a>0 : current_a=current_a//current_b current_ops+=1 min_ops=min(min_ops,current_ops) print(min_ops) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_OPS : int := 30 ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if (b->compareTo(a)) > 0 then ( execute (1)->display() ; continue ) else skip ; var min_ops : double := (a - b) + 2 ; for i : Integer.subrange(if b > 1 then 0 else 1 endif, MAX_OPS + 1-1) do ( var current_b : OclAny := b + i ; var current_ops : OclAny := i ; var current_a : OclAny := a ; while current_a > 0 do ( current_a := current_a div current_b ; current_ops := current_ops + 1) ; min_ops := Set{min_ops, current_ops}->min()) ; execute (min_ops)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math if __name__=='__main__' : t=int(input()) for _ in range(t): a,b=map(int,input().split()) operacoes=math.inf for i in range(50): if b+i<=1 : continue aux=i c=a while c!=0 : c=math.floor(c//(b+i)) aux+=1 if operacoes>aux : operacoes=aux print(operacoes) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var operacoes : OclAny := ; for i : Integer.subrange(0, 50-1) do ( if b + i <= 1 then ( continue ) else skip ; var aux : OclAny := i ; var c : OclAny := a ; while c /= 0 do ( c := (c div (b + i))->floor() ; aux := aux + 1) ; if (operacoes->compareTo(aux)) > 0 then ( operacoes := aux ) else skip) ; execute (operacoes)->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math tests=int(input()) for i in range(tests): a,b=map(int,input().split()) operations=0 while a!=0 : operations+=1 if b==1 : b+=1 continue exp1=math.log(a,b) exp2=math.log(a,b+1)+1 if exp1toInteger() ; for i : Integer.subrange(0, tests-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var operations : int := 0 ; while a /= 0 do ( operations := operations + 1 ; if b = 1 then ( b := b + 1 ; continue ) else skip ; var exp1 : double := (a, b)->log() ; var exp2 : double := (a, b + 1)->log() + 1 ; if (exp1->compareTo(exp2)) < 0 then ( var a : int := a div b ) else ( b := b + 1 )) ; execute (operations)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def isPrime(n): if(n<=1): return False if(n<=3): return True if(n % 2==0 or n % 3==0): return False for i in range(5,int(sqrt(n))+1,6): if(n % i==0 or n %(i+2)==0): return False return True def isFactorialPrime(n): if(not isPrime(n)): return False fact=1 i=1 while(fact<=n+1): fact=fact*i if(n+1==fact or n-1==fact): return True i+=1 return False if __name__=="__main__" : n=23 if(isFactorialPrime(n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( n := 23 ; if (isFactorialPrime(n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isPrime(n : OclAny) : OclAny pre: true post: true activity: if (n <= 1) then ( return false ) else skip ; if (n <= 3) then ( return true ) else skip ; if (n mod 2 = 0 or n mod 3 = 0) then ( return false ) else skip ; for i : Integer.subrange(5, ("" + ((sqrt(n))))->toInteger() + 1-1)->select( $x | ($x - 5) mod 6 = 0 ) do ( if (n mod i = 0 or n mod (i + 2) = 0) then ( return false ) else skip) ; return true; operation isFactorialPrime(n : OclAny) : OclAny pre: true post: true activity: if (not(isPrime(n))) then ( return false ) else skip ; var fact : int := 1 ; var i : int := 1 ; while ((fact->compareTo(n + 1)) <= 0) do ( fact := fact * i ; if (n + 1 = fact or n - 1 = fact) then ( return true ) else skip ; i := i + 1) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def isPrime(n): if(n<=1): return False if(n<=3): return True if(n % 2==0 and n % 3==0): return False for i in range(5,int(sqrt(n))+1,6): if(n % i==0 and n %(i+2)==0): return False return True def isDivisible(n): if(isPrime(n+1)): return False return True if __name__=='__main__' : n=6 if(isDivisible(n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( n := 6 ; if (isDivisible(n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isPrime(n : OclAny) : OclAny pre: true post: true activity: if (n <= 1) then ( return false ) else skip ; if (n <= 3) then ( return true ) else skip ; if (n mod 2 = 0 & n mod 3 = 0) then ( return false ) else skip ; for i : Integer.subrange(5, ("" + ((sqrt(n))))->toInteger() + 1-1)->select( $x | ($x - 5) mod 6 = 0 ) do ( if (n mod i = 0 & n mod (i + 2) = 0) then ( return false ) else skip) ; return true; operation isDivisible(n : OclAny) : OclAny pre: true post: true activity: if (isPrime(n + 1)) then ( return false ) else skip ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNumber(arr,n): arr=sorted(arr) Max=arr[n-1] table=[10**9 for i in range((2*Max)+1)] table[0]=0 ans=-1 for i in range(1,2*Max+1): for j in range(n): if(arr[j]<=i): res=table[i-arr[j]] if(res!=10**9 and res+1arr[n-1]and table[i]==10**9): ans=i break return ans arr=[6,7,15] n=len(arr) print(findNumber(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{6}->union(Sequence{7}->union(Sequence{ 15 })) ; n := (arr)->size() ; execute (findNumber(arr, n))->display(); operation findNumber(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var Max : OclAny := arr[n - 1+1] ; var table : Sequence := Integer.subrange(0, (2 * Max) + 1-1)->select(i | true)->collect(i | ((10)->pow(9))) ; table->first() := 0 ; var ans : int := -1 ; for i : Integer.subrange(1, 2 * Max + 1-1) do ( for j : Integer.subrange(0, n-1) do ( if ((arr[j+1]->compareTo(i)) <= 0) then ( var res : OclAny := table[i - arr[j+1]+1] ; if (res /= (10)->pow(9) & (res + 1->compareTo(table[i+1])) < 0) then ( table[i+1] := res + 1 ) else skip ) else skip) ; if ((i->compareTo(arr[n - 1+1])) > 0 & table[i+1] = (10)->pow(9)) then ( ans := i ; break ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxEvenLenSum(arr,n): if(n<2): return 0 dp=[0 for i in range(n)] dp[n-1]=0 dp[n-2]=arr[n-2]+arr[n-1] for i in range(n-3,-1,-1): dp[i]=arr[i]+arr[i+1] if(dp[i+2]>0): dp[i]+=dp[i+2] maxSum=max(dp) return maxSum arr=[8,9,-8,9,10] n=len(arr) print(maxEvenLenSum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{8}->union(Sequence{9}->union(Sequence{-8}->union(Sequence{9}->union(Sequence{ 10 })))) ; n := (arr)->size() ; execute (maxEvenLenSum(arr, n))->display(); operation maxEvenLenSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n < 2) then ( return 0 ) else skip ; var dp : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; dp[n - 1+1] := 0 ; dp[n - 2+1] := arr[n - 2+1] + arr[n - 1+1] ; for i : Integer.subrange(-1 + 1, n - 3)->reverse() do ( dp[i+1] := arr[i+1] + arr[i + 1+1] ; if (dp[i + 2+1] > 0) then ( dp[i+1] := dp[i+1] + dp[i + 2+1] ) else skip) ; var maxSum : OclAny := (dp)->max() ; return maxSum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=30 def solve(X,Y,l,r,k,dp): if k==0 : return 0 if l<0 or r<0 : return 1000000000 if dp[l][r][k]!=-1 : return dp[l][r][k] cost=((ord(X[l])-ord('a'))^(ord(Y[r])-ord('a'))) dp[l][r][k]=min([cost+solve(X,Y,l-1,r-1,k-1,dp),solve(X,Y,l-1,r,k,dp),solve(X,Y,l,r-1,k,dp)]) return dp[l][r][k] if __name__=="__main__" : X="abble" Y="pie" n=len(X) m=len(Y) k=2 dp=[[[-1]*N for __ in range(N)]for ___ in range(N)] ans=solve(X,Y,n-1,m-1,k,dp) print(-1 if ans==1000000000 else ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 30 ; skip ; if __name__ = "__main__" then ( X := "abble" ; Y := "pie" ; var n : int := (X)->size() ; var m : int := (Y)->size() ; k := 2 ; dp := Integer.subrange(0, N-1)->select(___ | true)->collect(___ | (Integer.subrange(0, N-1)->select(__ | true)->collect(__ | (MatrixLib.elementwiseMult(Sequence{ -1 }, N))))) ; var ans : OclAny := solve(X, Y, n - 1, m - 1, k, dp) ; execute (if ans = 1000000000 then -1 else ans endif)->display() ) else skip; operation solve(X : OclAny, Y : OclAny, l : OclAny, r : OclAny, k : OclAny, dp : OclAny) : OclAny pre: true post: true activity: if k = 0 then ( return 0 ) else skip ; if l < 0 or r < 0 then ( return 1000000000 ) else skip ; if dp[l+1][r+1][k+1] /= -1 then ( return dp[l+1][r+1][k+1] ) else skip ; var cost : int := (MathLib.bitwiseXor(((X[l+1])->char2byte() - ('a')->char2byte()), ((Y[r+1])->char2byte() - ('a')->char2byte()))) ; dp[l+1][r+1][k+1] := (Sequence{cost + solve(X, Y, l - 1, r - 1, k - 1, dp)}->union(Sequence{solve(X, Y, l - 1, r, k, dp)}->union(Sequence{ solve(X, Y, l, r - 1, k, dp) })))->min() ; return dp[l+1][r+1][k+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k,b,s=list(map(int,input().split())) if(s//k(k*b+n*k-n)): print(-1) else : a=[] a.append(min(k*b+k-1,s)) t=a[0] for i in range(1,n): if a[i-1]==0 : break elif(((s-t)//k)>=1): a.append(k-1) t+=k-1 else : a.append(s-t) t+=s-t for i in range(len(a)): print(str(a[i])+" ",end='') if len(a)toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; var b : OclAny := null; var s : OclAny := null; Sequence{n,k,b,s} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if ((s div k->compareTo(b)) < 0) then ( execute (-1)->display() ) else (if ((s->compareTo((k * b + n * k - n))) > 0) then ( execute (-1)->display() ) else ( var a : Sequence := Sequence{} ; execute ((Set{k * b + k - 1, s}->min()) : a) ; var t : OclAny := a->first() ; for i : Integer.subrange(1, n-1) do ( if a[i - 1+1] = 0 then ( break ) else (if (((s - t) div k) >= 1) then ( execute ((k - 1) : a) ; t := t + k - 1 ) else ( execute ((s - t) : a) ; t := t + s - t ) ) ) ; for i : Integer.subrange(0, (a)->size()-1) do ( execute (("" + ((a[i+1]))) + " ")->display()) ; if ((a)->size()->compareTo(n)) < 0 then ( for i : Integer.subrange(0, n - (a)->size()-1) do ( execute ("0 ")->display()) ) else skip ; execute (->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): while b!=0 : a,b=b,a % b return a n=int(input()) a=[int(i)for i in input().split()] cnt_ones=0 for x in a : if x==1 : cnt_ones+=1 if cnt_ones>0 : print(n-cnt_ones) else : min_len=n+1 for i in range(n): p=a[i] for j in range(i+1,n): p=gcd(p,a[j]) if p==1 : min_len=min(min_len,j-i) break if min_len==n+1 : print(-1) else : print(min_len+n-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var cnt_ones : int := 0 ; for x : a do ( if x = 1 then ( cnt_ones := cnt_ones + 1 ) else skip) ; if cnt_ones > 0 then ( execute (n - cnt_ones)->display() ) else ( var min_len : int := n + 1 ; for i : Integer.subrange(0, n-1) do ( var p : OclAny := a[i+1] ; for j : Integer.subrange(i + 1, n-1) do ( p := gcd(p, a[j+1]) ; if p = 1 then ( min_len := Set{min_len, j - i}->min() ; break ) else skip)) ; if min_len = n + 1 then ( execute (-1)->display() ) else ( execute (min_len + n - 1)->display() ) ); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: while b /= 0 do ( Sequence{a,b} := Sequence{b,a mod b}) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() l1=list(map(int,input().split())) n=input() l2=list(map(int,input().split())) if l1collect( _x | (OclType["int"])->apply(_x) )) ; n := (OclFile["System.in"]).readLine() ; var l2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if MatrixLib.matrixLess(l1,l2) then ( execute (1)->display() ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math input=sys.stdin.readline def gcd(x,y): if y==0 : return x return gcd(y,x % y) def solve(n,arr): count=0 for num in arr : if num==1 : count+=1 if count>0 : return n-count dp={} length=float("inf") for i in range(n): dp[(i,i)]=arr[i] for j in range(i+1,n): dp[(i,j)]=math.gcd(dp[(i,j-1)],arr[j]) if dp[(i,j)]==1 : length=min(length,j-i+1) return length-1+n-1 if lengthtoInteger() ; arr := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (solve(n, arr))->display(); operation gcd(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if y = 0 then ( return x ) else skip ; return gcd(y, x mod y); operation solve(n : OclAny, arr : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for num : arr do ( if num = 1 then ( count := count + 1 ) else skip) ; if count > 0 then ( return n - count ) else skip ; var dp : OclAny := Set{} ; var length : double := ("" + (("inf")))->toReal() ; for i : Integer.subrange(0, n-1) do ( dp[Sequence{i, i}+1] := arr[i+1] ; for j : Integer.subrange(i + 1, n-1) do ( dp[Sequence{i, j}+1] := (dp[Sequence{i, j - 1}+1])->gcd(arr[j+1]) ; if dp[Sequence{i, j}+1] = 1 then ( length := Set{length, j - i + 1}->min() ) else skip)) ; return if (length->compareTo(("" + (("inf")))->toReal())) < 0 then length - 1 + n - 1 else -1 endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) a=list(map(int,input().split())) ans,cnt=n,a.count(1) for i in range(n): m=a[i] for j in range(i+1,n): m=math.gcd(m,a[j]) if m==1 : ans=min(ans,j-i-1) if cnt>0 : print(n-cnt) elif ans==n : print(-1) else : print(n+ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : OclAny := null; var cnt : OclAny := null; Sequence{ans,cnt} := Sequence{n,a->count(1)} ; for i : Integer.subrange(0, n-1) do ( var m : OclAny := a[i+1] ; for j : Integer.subrange(i + 1, n-1) do ( m := (m)->gcd(a[j+1]) ; if m = 1 then ( var ans : OclAny := Set{ans, j - i - 1}->min() ) else skip)) ; if cnt > 0 then ( execute (n - cnt)->display() ) else (if ans = n then ( execute (-1)->display() ) else ( execute (n + ans)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): while b!=0 : a,b=b,a % b return a n=int(input()) a=[int(i)for i in input().split()] cnt_ones=0 for x in a : if x==1 : cnt_ones+=1 if cnt_ones>0 : print(n-cnt_ones) else : min_len=n+1 for i in range(n): p=a[i] for j in range(i+1,n): p=gcd(p,a[j]) if p==1 : min_len=min(min_len,j-i) break if min_len==n+1 : print(-1) else : print(min_len+n-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var cnt_ones : int := 0 ; for x : a do ( if x = 1 then ( cnt_ones := cnt_ones + 1 ) else skip) ; if cnt_ones > 0 then ( execute (n - cnt_ones)->display() ) else ( var min_len : int := n + 1 ; for i : Integer.subrange(0, n-1) do ( var p : OclAny := a[i+1] ; for j : Integer.subrange(i + 1, n-1) do ( p := gcd(p, a[j+1]) ; if p = 1 then ( min_len := Set{min_len, j - i}->min() ; break ) else skip)) ; if min_len = n + 1 then ( execute (-1)->display() ) else ( execute (min_len + n - 1)->display() ) ); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: while b /= 0 do ( Sequence{a,b} := Sequence{b,a mod b}) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) for i,v in enumerate(arr): if i==0 : arr[i]=v-1 else : if v-arr[i-1]>0 : arr[i]=v-1 elif v-arr[i-1]<0 : print("No") break else : print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (compound_stmt for (exprlist (expr (atom (name i))) , (expr (atom (name v)))) in (testlist (test (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name i)))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1))))))))))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name v))) - (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))))) > (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1))))))))))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (expr (atom (name v))) - (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))))) < (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "No"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Yes"))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np import sys n=int(input()) h=np.array(list(map(int,input().split()))) ans="No" h[0]-=1 for i in range(1,n-1): dif_1=h[i]-h[i+1] dif_2=h[i]-h[i-1] if dif_1>1 : print(ans) sys.exit() elif dif_1==1 or dif_2>0 : h[i]-=1 max_h=0 for i in range(1,n): max_h=max(max_h,h[i-1]) dif=h[i]-max_h if dif<0 : print(ans) sys.exit() ans="Yes" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var h : Sequence := (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ans : String := "No" ; h->first() := h->first() - 1 ; for i : Integer.subrange(1, n - 1-1) do ( var dif skip : double := h[i+1] - h[i + 1+1] ; var dif:= h[i+1] - h[i - 1+1] : double := h[i+1] - h[i - 1+1] ; if dif var dif skip : double := h[i+1] - h[i + 1+1] > 1 then ( execute (ans)->display() ; sys.exit() ) else (if dif var dif skip : double := h[i+1] - h[i + 1+1] = 1 or dif0 > 0 then ( h[i+1] := h[i+1] - 1 ) else skip)) ; var max_h : int := 0 ; for i : Integer.subrange(1, n-1) do ( max_h := Set{max_h, h[i - 1+1]}->max() ; var dif : double := h[i+1] - max_h ; if dif < 0 then ( execute (ans)->display() ; sys.exit() ) else skip) ; ans := "Yes" ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lst=[int(i)for i in input().split()] if len(set(lst))==1 : print('Yes') exit() lst_c=sorted(lst) for i in range(n): if lst[i]-lst_c[i]>=2 : print('No') exit() print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if (Set{}->union((lst)))->size() = 1 then ( execute ('Yes')->display() ; exit() ) else skip ; var lst_c : Sequence := lst->sort() ; for i : Integer.subrange(0, n-1) do ( if lst[i+1] - lst_c[i+1] >= 2 then ( execute ('No')->display() ; exit() ) else skip) ; execute ('Yes')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n,*h=map(int,sys.stdin.read().split()) def main(): ans='Yes' for i in range(n-1,0,-1): if h[i-1]>h[i]: h[i-1]-=1 if h[i-1]>h[i]: ans='No' ; break print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var h : OclAny := null; Sequence{n,h} := (sys.stdin.readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var ans : String := 'Yes' ; for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( if (h[i - 1+1]->compareTo(h[i+1])) > 0 then ( h[i - 1+1] := h[i - 1+1] - 1 ) else skip ; if (h[i - 1+1]->compareTo(h[i+1])) > 0 then ( ans := 'No'; break ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys A=int(input()) H=list(map(int,input().split())) if A==1 : print('Yes') sys.exit() if H[0]==H[1]+1 : H[0]-=1 elif H[0]>=H[1]+2 : print('No') sys.exit() for i in range(1,A-1): if H[i]==H[i+1]+1 and H[i]==H[i-1]: print('No') sys.exit() elif H[i]==H[i+1]+1 and H[i]>H[i-1]: H[i]-=1 elif H[i]==H[i+1]and H[i]>H[i-1]: H[i]-=1 elif H[i]>=H[i+1]+2 : print('No') sys.exit() print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var H : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if A = 1 then ( execute ('Yes')->display() ; sys.exit() ) else skip ; if H->first() = H[1+1] + 1 then ( H->first() := H->first() - 1 ) else (if (H->first()->compareTo(H[1+1] + 2)) >= 0 then ( execute ('No')->display() ; sys.exit() ) else skip) ; for i : Integer.subrange(1, A - 1-1) do ( if H[i+1] = H[i + 1+1] + 1 & H[i+1] = H[i - 1+1] then ( execute ('No')->display() ; sys.exit() ) else (if H[i+1] = H[i + 1+1] + 1 & (H[i+1]->compareTo(H[i - 1+1])) > 0 then ( H[i+1] := H[i+1] - 1 ) else (if H[i+1] = H[i + 1+1] & (H[i+1]->compareTo(H[i - 1+1])) > 0 then ( H[i+1] := H[i+1] - 1 ) else (if (H[i+1]->compareTo(H[i + 1+1] + 2)) >= 0 then ( execute ('No')->display() ; sys.exit() ) else skip ) ) ) ) ; execute ('Yes')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def missingNumber(a,n): mp=dict(); for i in range(n): if(a[i]>0): if a[i]not in mp.keys(): mp[a[i]]=0 mp[a[i]]+=1 index=1 ; while(1): if(index not in mp.keys()): return index ; index+=1 ; if __name__=="__main__" : a=[1,1,1,0,-1,-2]; size=len(a); print("Smallest positive missing number is : ",missingNumber(a,size)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{ -2 }))))); ; var size : int := (a)->size(); ; execute ("Smallest positive missing number is : ")->display(); ) else skip; operation missingNumber(a : OclAny, n : OclAny) pre: true post: true activity: var mp : Map := (arguments ( )); ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] > 0) then ( if (mp.keys())->excludes(a[i+1]) then ( mp[a[i+1]+1] := 0 ) else skip ; mp[a[i+1]+1] := mp[a[i+1]+1] + 1 ) else skip) ; var index : int := 1; ; while (1) do ( if ((mp.keys())->excludes(index)) then ( return index; ) else skip ; index := index + 1;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: n,k,b,s=map(int,s.split()); s-=k*b ; x=s//n ; r=s % n ; print(*n*k-n>=s>=0 and[k*b+x]+r*[x+1]+(n-r-1)*[x]or[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var n : OclAny := null; var k : OclAny := null; var b : OclAny := null; var s : OclAny := null; Sequence{n,k,b,s} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ); s := s - k * b; var x : int := s div n; var r : int := s mod n; execute ((argument * (test (logical_test (logical_test (logical_test (comparison (comparison (comparison (expr (expr (expr (atom (name n))) * (expr (atom (name k)))) - (expr (atom (name n))))) >= (comparison (expr (atom (name s))))) >= (comparison (expr (atom (number (integer 0))))))) and (logical_test (comparison (expr (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name k))) * (expr (atom (name b)))) + (expr (atom (name x)))))))) ])) + (expr (expr (atom (name r))) * (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (number (integer 1))))))))) ])))) + (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name n))) - (expr (atom (name r)))) - (expr (atom (number (integer 1))))))))) ))) * (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name x))))))) ]))))))) or (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom - (number (integer 1)))))))) ]))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import UserList class LexicalOrderedList(UserList): def __eq__(self,other): len_a=len(self) len_b=len(other) if len_a!=len_b : return False i=0 while self.data[i]==other.data[i]: i+=1 return i==len_a def __gt__(self,other): len_a=len(self) len_b=len(other) i=0 while(iother.data[i] def __ge__(self,other): return self==other or self>other def run(): n=int(input()) a=LexicalOrderedList() for c in input().split(): a.append(int(c)) assert len(a)==n m=int(input()) b=LexicalOrderedList() for c in input().split(): b.append(int(c)) assert len(b)==m if b>a : print(1) else : print(0) if __name__=='__main__' : run() ------------------------------------------------------------ OCL File: --------- class LexicalOrderedList extends UserList { static operation newLexicalOrderedList() : LexicalOrderedList pre: true post: LexicalOrderedList->exists( _x | result = _x ); operation __eq__(other : OclAny) : OclAny pre: true post: true activity: var len_a : int := (self)->size() ; var len_b : int := (other)->size() ; if len_a /= len_b then ( return false ) else skip ; var i : int := 0 ; while self.data[i+1] = other.data[i+1] do ( i := i + 1) ; return i = len_a; operation __gt__(other : OclAny) : OclAny pre: true post: true activity: len_a := (self)->size() ; len_b := (other)->size() ; i := 0 ; while ((i->compareTo(len_a)) < 0 & (i->compareTo(len_b)) < 0 & self.data[i+1] = other.data[i+1]) do ( i := i + 1) ; if i = len_a & i = len_b then ( return false ) else (if i = len_a & (i->compareTo(len_b)) < 0 then ( return false ) else (if (i->compareTo(len_a)) < 0 & i = len_b then ( return true ) else ( return (self.data[i+1]->compareTo(other.data[i+1])) > 0 ) ) ) ; operation __ge__(other : OclAny) : OclAny pre: true post: true activity: return self = other or (self->compareTo(other)) > 0; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( run() ) else skip; operation run() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : LexicalOrderedList := (LexicalOrderedList.newLexicalOrderedList()).initialise() ; for c : input().split() do ( execute ((("" + ((c)))->toInteger()) : a)) ; assert (a)->size() = n do "assertion failed" ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : LexicalOrderedList := (LexicalOrderedList.newLexicalOrderedList()).initialise() ; for c : input().split() do ( execute ((("" + ((c)))->toInteger()) : b)) ; assert (b)->size() = m do "assertion failed" ; if (b->compareTo(a)) > 0 then ( execute (1)->display() ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def flip(c): return '1' if(c=='0')else '0' def printOneAndTwosComplement(bin): n=len(bin) ones="" twos="" for i in range(n): ones+=flip(bin[i]) ones=list(ones.strip("")) twos=list(ones) for i in range(n-1,-1,-1): if(ones[i]=='1'): twos[i]='0' else : twos[i]='1' break i-=1 if(i==-1): twos.insert(0,'1') print("1's complement: ",*ones,sep="") print("2's complement: ",*twos,sep="") if __name__=='__main__' : bin="1100" printOneAndTwosComplement(bin.strip("")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( bin := "1100" ; printOneAndTwosComplement(bin->trim()) ) else skip; operation flip(c : OclAny) : OclAny pre: true post: true activity: return if (c = '0') then '1' else '0' endif; operation printOneAndTwosComplement(bin : OclAny) pre: true post: true activity: var n : int := (bin)->size() ; var ones : String := "" ; var twos : String := "" ; for i : Integer.subrange(0, n-1) do ( ones := ones + flip(bin[i+1])) ; ones := (ones->trim())->characters() ; twos := (ones)->characters() ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (ones[i+1] = '1') then ( twos[i+1] := '0' ) else ( twos[i+1] := '1' ; break )) ; i := i - 1 ; if (i = -1) then ( twos := twos.insertAt(0+1, '1') ) else skip ; execute ("1's complement: ")->display() ; execute ("2's complement: ")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairs(arr1,arr2,m,n,x): count=0 us=set() for i in range(m): us.add(arr1[i]) for j in range(n): if x-arr2[j]in us : count+=1 return count arr1=[1,3,5,7] arr2=[2,3,5,8] m=len(arr1) n=len(arr2) x=10 print("Count=",countPairs(arr1,arr2,m,n,x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr1 := Sequence{1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 7 }))) ; arr2 := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 8 }))) ; m := (arr1)->size() ; n := (arr2)->size() ; x := 10 ; execute ("Count=")->display(); operation countPairs(arr1 : OclAny, arr2 : OclAny, m : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var us : Set := Set{}->union(()) ; for i : Integer.subrange(0, m-1) do ( execute ((arr1[i+1]) : us)) ; for j : Integer.subrange(0, n-1) do ( if (us)->includes(x - arr2[j+1]) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=int(input()) l_c=list() for _ in range(f): l_c.append(list(map(int,input().split()))) n=0 for i in range(f): s_i=set() for j in range(f): if i==j : pass elif l_c[i][0]==l_c[j][0]: if l_c[i][1]>l_c[j][1]: s_i.add("D") elif l_c[i][1]l_c[j][0]: s_i.add("L") elif l_c[i][0]toInteger() ; var l_c : Sequence := () ; for _anon : Integer.subrange(0, f-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : l_c)) ; var n : int := 0 ; for i : Integer.subrange(0, f-1) do ( var s_i : Set := Set{}->union(()) ; for j : Integer.subrange(0, f-1) do ( if i = j then ( skip ) else (if l_c[i+1]->first() = l_c[j+1]->first() then ( if (l_c[i+1][1+1]->compareTo(l_c[j+1][1+1])) > 0 then ( execute (("D") : s_i) ) else (if (l_c[i+1][1+1]->compareTo(l_c[j+1][1+1])) < 0 then ( execute (("U") : s_i) ) else skip) ) else (if l_c[i+1][1+1] = l_c[j+1][1+1] then ( if (l_c[i+1]->first()->compareTo(l_c[j+1]->first())) > 0 then ( execute (("L") : s_i) ) else (if (l_c[i+1]->first()->compareTo(l_c[j+1]->first())) < 0 then ( execute (("R") : s_i) ) else skip) ) else skip ) ) ) ; if (s_i)->size() = 4 then ( n := n + 1 ) else skip) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=[] for i in range(n): a=[int(x)for x in input().split()] arr.append(a) cnt=0 for i in range(n): x=arr[i][0] y=arr[i][1] temp=[0]*4 for j in range(n): if arr[j][1]==y and arr[j][0]>x : temp[1]=1 for j in range(n): if arr[j][1]==y and arr[j][0]y and arr[j][0]==x : temp[2]=1 for j in range(n): if arr[j][1]toInteger() ; var arr : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((a) : arr)) ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := arr[i+1]->first() ; var y : OclAny := arr[i+1][1+1] ; var temp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 4) ; for j : Integer.subrange(0, n-1) do ( if arr[j+1][1+1] = y & (arr[j+1]->first()->compareTo(x)) > 0 then ( temp[1+1] := 1 ) else skip) ; for j : Integer.subrange(0, n-1) do ( if arr[j+1][1+1] = y & (arr[j+1]->first()->compareTo(x)) < 0 then ( temp->first() := 1 ) else skip) ; for j : Integer.subrange(0, n-1) do ( if (arr[j+1][1+1]->compareTo(y)) > 0 & arr[j+1]->first() = x then ( temp[2+1] := 1 ) else skip) ; for j : Integer.subrange(0, n-1) do ( if (arr[j+1][1+1]->compareTo(y)) < 0 & arr[j+1]->first() = x then ( temp[3+1] := 1 ) else skip) ; var sm : int := 0 ; for i : temp do ( sm := sm + i) ; if sm = 4 then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) liste=[] sayac=0 for i in range(a): v=list(map(int,input().split())) liste.append(v) for b in range(a): ust=0 sag=0 sol=0 alt=0 for n in range(a): if liste[n][0]==liste[b][0]and liste[n][1]>liste[b][1]: ust=ust+1 if liste[n][0]==liste[b][0]and liste[n][1]liste[b][0]and liste[n][1]==liste[b][1]: sag=sag+1 if sag>0 and sol>0 and ust>0 and alt>0 : sayac=sayac+1 print(sayac) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var liste : Sequence := Sequence{} ; var sayac : int := 0 ; for i : Integer.subrange(0, a-1) do ( var v : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((v) : liste)) ; for b : Integer.subrange(0, a-1) do ( var ust : int := 0 ; var sag : int := 0 ; var sol : int := 0 ; var alt : int := 0 ; for n : Integer.subrange(0, a-1) do ( if liste[n+1]->first() = liste[b+1]->first() & (liste[n+1][1+1]->compareTo(liste[b+1][1+1])) > 0 then ( ust := ust + 1 ) else skip ; if liste[n+1]->first() = liste[b+1]->first() & (liste[n+1][1+1]->compareTo(liste[b+1][1+1])) < 0 then ( alt := alt + 1 ) else skip ; if (liste[n+1]->first()->compareTo(liste[b+1]->first())) < 0 & liste[n+1][1+1] = liste[b+1][1+1] then ( sol := sol + 1 ) else skip ; if (liste[n+1]->first()->compareTo(liste[b+1]->first())) > 0 & liste[n+1][1+1] = liste[b+1][1+1] then ( sag := sag + 1 ) else skip) ; if sag > 0 & sol > 0 & ust > 0 & alt > 0 then ( sayac := sayac + 1 ) else skip) ; execute (sayac)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): n=int(input()) points=[] ys=defaultdict(list) xs=defaultdict(list) for _ in range(n): a,b=map(int,input().split()) points.append((a,b)) ys[a].append(b) xs[b].append(a) res=0 for x,y in points : nbrs=0 for b in ys[x]: if b>y : nbrs |=1<<0 elif bx : nbrs |=1<<2 elif atoInteger() ; var points : Sequence := Sequence{} ; var ys : OclAny := defaultdict(OclType["Sequence"]) ; var xs : OclAny := defaultdict(OclType["Sequence"]) ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a, b}) : points) ; (expr (atom (name ys)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name xs)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var res : int := 0 ; for _tuple : points do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); var nbrs : int := 0 ; for b : ys[x+1] do ( if (b->compareTo(y)) > 0 then ( nbrs := nbrs or 1 * (2->pow(0)) ) else (if (b->compareTo(y)) < 0 then ( nbrs := nbrs or 1 * (2->pow(1)) ) else skip)) ; for a : xs[y+1] do ( if (a->compareTo(x)) > 0 then ( nbrs := nbrs or 1 * (2->pow(2)) ) else (if (a->compareTo(x)) < 0 then ( nbrs := nbrs or 1 * (2->pow(3)) ) else skip)) ; res := res + nbrs = 15) ; return (res)->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r=lambda : list(map(int,input().split())) l=list(r()for _ in range(int(input()))) cm=lambda a,b :(a>b)-(a4 for x,y in l) print(p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var l : Sequence := ((argument (test (logical_test (comparison (expr (atom (name r)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))) ))))))))) ; var cm : Function := lambda a : OclAny, b : OclAny in (((a->compareTo(b)) > 0) - ((a->compareTo(b)) < 0)) ; var p : OclAny := ((argument (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom { (dictorsetmaker (testlist_comp (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name cm)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) , (test (logical_test (comparison (expr (atom (name cm)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b))))))) , (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))))))) )))))) (comp_for for (exprlist (expr (atom (name a))) , (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name l))))) (comp_iter if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom (name a)))) == (comparison (expr (atom (name x)))))) or (logical_test (comparison (comparison (expr (atom (name b)))) == (comparison (expr (atom (name y))))))))) )))))))))) }))))))) ))))) > (comparison (expr (atom (number (integer 4)))))))) (comp_for for (exprlist (expr (atom (name x))) , (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name l))))))))->sum() ; execute (p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binaryToDecimal(n): num=n dec_value=0 base=1 l=len(num) for i in range(l-1,-1,-1): if(num[i]=='1'): dec_value+=base base=base*2 return dec_value def numberSequence(n): if(n==1): return 1 s="" for i in range(1,n): s+='1' s+='0' for i in range(1,n+1): s+='1' num=binaryToDecimal(s) return num if __name__=="__main__" : n=4 print(numberSequence(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 4 ; execute (numberSequence(n))->display() ) else skip; operation binaryToDecimal(n : OclAny) : OclAny pre: true post: true activity: var num : OclAny := n ; var dec_value : int := 0 ; var base : int := 1 ; var l : int := (num)->size() ; for i : Integer.subrange(-1 + 1, l - 1)->reverse() do ( if (num[i+1] = '1') then ( dec_value := dec_value + base ) else skip ; base := base * 2) ; return dec_value; operation numberSequence(n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return 1 ) else skip ; var s : String := "" ; for i : Integer.subrange(1, n-1) do ( s := s + '1') ; s := s + '0' ; for i : Integer.subrange(1, n + 1-1) do ( s := s + '1') ; num := binaryToDecimal(s) ; return num; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def constructString(n): s="" for i in range(n): s+="10" return s def binaryToDecimal(n): num=n dec_value=0 base=1 Len=len(num) for i in range(Len-1,-1,-1): if(num[i]=='1'): dec_value+=base base=base*2 return dec_value def findNumber(n): s=constructString(n-1) num=binaryToDecimal(s) return num n=4 print(findNumber(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 4 ; execute (findNumber(n))->display(); operation constructString(n : OclAny) : OclAny pre: true post: true activity: var s : String := "" ; for i : Integer.subrange(0, n-1) do ( s := s + "10") ; return s; operation binaryToDecimal(n : OclAny) : OclAny pre: true post: true activity: var num : OclAny := n ; var dec_value : int := 0 ; var base : int := 1 ; var Len : int := (num)->size() ; for i : Integer.subrange(-1 + 1, Len - 1)->reverse() do ( if (num[i+1] = '1') then ( dec_value := dec_value + base ) else skip ; base := base * 2) ; return dec_value; operation findNumber(n : OclAny) : OclAny pre: true post: true activity: s := constructString(n - 1) ; num := binaryToDecimal(s) ; return num; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def main(): test_cases=range(int(input())) for test_case in test_cases : a,b=sorted([int(u)for u in input().split(" ")]) total_games=a+b odd_bool=True if total_games % 2==0 : odd_bool=False x=total_games//2 y=math.ceil(total_games/2) dif_min=abs(y-b) dif_max=min(y,b)+min(x,a) if odd_bool : x=[str(i)for i in range(dif_min,dif_max+1)] print(len(x)) print(" ".join(x)) else : x=[str(i)for i in range(dif_min,dif_max+1,2)] print(len(x)) print(" ".join(x)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var test_cases : Sequence := Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) ; for test_case : test_cases do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split(" ")->select(u | true)->collect(u | (("" + ((u)))->toInteger()))->sort() ; var total_games : OclAny := a + b ; var odd_bool : boolean := true ; if total_games mod 2 = 0 then ( odd_bool := false ) else skip ; var x : int := total_games div 2 ; var y : double := (total_games / 2)->ceil() ; var dif_min : double := (y - b)->abs() ; var dif_max : OclAny := Set{y, b}->min() + Set{x, a}->min() ; if odd_bool then ( x := Integer.subrange(dif_min, dif_max + 1-1)->select(i | true)->collect(i | (("" + ((i))))) ; execute ((x)->size())->display() ; execute (StringLib.sumStringsWithSeparator((x), " "))->display() ) else ( x := Integer.subrange(dif_min, dif_max + 1-1)->select( $x | ($x - dif_min) mod 2 = 0 )->select(i | true)->collect(i | (("" + ((i))))) ; execute ((x)->size())->display() ; execute (StringLib.sumStringsWithSeparator((x), " "))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find3Numbers(arr,n): small=+2147483647 large=+2147483647 for i in range(n): if(arr[i]<=small): small=arr[i] elif(arr[i]<=large): large=arr[i] else : break if(i==n): print("No such triplet found") return for j in range(i+1): if(arr[j]union(Sequence{7}->union(Sequence{4}->union(Sequence{ 8 }))) ; n := (arr)->size() ; find3Numbers(arr, n); operation find3Numbers(arr : OclAny, n : OclAny) pre: true post: true activity: var small : int := 2147483647 ; var large : int := 2147483647 ; for i : Integer.subrange(0, n-1) do ( if ((arr[i+1]->compareTo(small)) <= 0) then ( small := arr[i+1] ) else (if ((arr[i+1]->compareTo(large)) <= 0) then ( large := arr[i+1] ) else ( break ) ) ) ; if (i = n) then ( execute ("No such triplet found")->display() ; return ) else skip ; for j : Integer.subrange(0, i + 1-1) do ( if ((arr[j+1]->compareTo(large)) < 0) then ( small := arr[j+1] ; break ) else skip) ; execute (small)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import calendar y=int(input()) is_run=calendar.isleap(y) week=calendar.weekday(y,1,1) while True : y=y+1 if calendar.isleap(y)==is_run and calendar.weekday(y,1,1)==week : print(y) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var y : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var is_run : OclAny := calendar.isleap(y) ; var week : OclAny := calendar.weekday(y, 1, 1) ; while true do ( y := y + 1 ; if calendar.isleap(y) = is_run & calendar.weekday(y, 1, 1) = week then ( execute (y)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy BIG_NUM=2000000000 HUGE_NUM=99999999999999999 MOD=1000000007 EPS=0.000000001 sys.setrecursionlimit(100000) len_A=int(input()) A=list(map(int,input().split())) len_B=int(input()) B=list(map(int,input().split())) B_Bigger=False for i in range(min(len_A,len_B)): if A[i]!=B[i]: B_Bigger=B[i]>A[i] break if i==len_A-1 and i!=len_B-1 : B_Bigger=True if B_Bigger==True : print("1") else : print("0") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var HUGE_NUM : int := 99999999999999999 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; sys.setrecursionlimit(100000) ; var len_A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var len_B : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var B_Bigger : boolean := false ; for i : Integer.subrange(0, Set{len_A, len_B}->min()-1) do ( if A[i+1] /= B[i+1] then ( B_Bigger := (B[i+1]->compareTo(A[i+1])) > 0 ; break ) else skip ; if i = len_A - 1 & i /= len_B - 1 then ( B_Bigger := true ) else skip) ; if B_Bigger = true then ( execute ("1")->display() ) else ( execute ("0")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMaximum(arr,low,high): max=arr[low] i=low for i in range(high+1): if arr[i]>max : max=arr[i] return max arr=[1,30,40,50,60,70,23,20] n=len(arr) print("The maximum element is %d" % findMaximum(arr,0,n-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{30}->union(Sequence{40}->union(Sequence{50}->union(Sequence{60}->union(Sequence{70}->union(Sequence{23}->union(Sequence{ 20 }))))))) ; var n : int := (arr)->size() ; execute (StringLib.format("The maximum element is %d",findMaximum(arr, 0, n - 1)))->display(); operation findMaximum(arr : OclAny, low : OclAny, high : OclAny) : OclAny pre: true post: true activity: var max : OclAny := arr[low+1] ; var i : OclAny := low ; for i : Integer.subrange(0, high + 1-1) do ( if (arr[i+1]->compareTo(max)) > 0 then ( max := arr[i+1] ) else skip) ; return max; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CalculatePairs(a,n): cnt_zero=0 cnt_one=0 for i in range(0,n): if(a[i]% 2==0): cnt_zero+=1 else : cnt_one+=1 total_XOR_pairs=cnt_zero*cnt_one total_AND_pairs=(cnt_one)*(cnt_one-1)/2 total_OR_pairs=cnt_zero*cnt_one+(cnt_one)*(cnt_one-1)/2 print("cntXOR=",int(total_XOR_pairs)) print("cntAND=",int(total_AND_pairs)) print("cntOR=",int(total_OR_pairs)) if __name__=='__main__' : a=[1,3,4,2] n=len(a) CalculatePairs(a,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := Sequence{1}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 2 }))) ; n := (a)->size() ; CalculatePairs(a, n) ) else skip; operation CalculatePairs(a : OclAny, n : OclAny) pre: true post: true activity: var cnt_zero : int := 0 ; var cnt_one : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] mod 2 = 0) then ( cnt_zero := cnt_zero + 1 ) else ( cnt_one := cnt_one + 1 )) ; var total_XOR_pairs : int := cnt_zero * cnt_one ; var total_AND_pairs : double := (cnt_one) * (cnt_one - 1) / 2 ; var total_OR_pairs : int := cnt_zero * cnt_one + (cnt_one) * (cnt_one - 1) / 2 ; execute ("cntXOR=")->display() ; execute ("cntAND=")->display() ; execute ("cntOR=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=map(int,input().split()) d=abs(n-m)//2 s=n+m if s % 2==0 : ar=[i for i in range(d,s-d+1,2)] print(len(ar)) print(*ar) else : ar=[i for i in range(d,s-d+1)] print(len(ar)) print(*ar) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : int := (n - m)->abs() div 2 ; var s : OclAny := n + m ; if s mod 2 = 0 then ( var ar : Sequence := Integer.subrange(d, s - d + 1-1)->select( $x | ($x - d) mod 2 = 0 )->select(i | true)->collect(i | (i)) ; execute ((ar)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ar))))))))->display() ) else ( ar := Integer.subrange(d, s - d + 1-1)->select(i | true)->collect(i | (i)) ; execute ((ar)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ar))))))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): a,b=map(int,input().split()) arr=[] if(a+b)% 2==0 : ans=max(a,b)-(a+b)/2 for i in range(min(a,b)+1): arr.append(int(ans)) ans+=2 else : ans=max(a,b)-int((a+b)/2) for i in range(min(a,b)+1): arr.append(int(ans)) ans+=2 ans=max(a,b)-(int((a+b)/2)+1) for i in range(min(a,b)+1): arr.append(int(ans)) ans+=2 arr.sort() print(len(arr)) print(*arr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := Sequence{} ; if (a + b) mod 2 = 0 then ( var ans : double := Set{a, b}->max() - (a + b) / 2 ; for i : Integer.subrange(0, Set{a, b}->min() + 1-1) do ( execute ((("" + ((ans)))->toInteger()) : arr) ; ans := ans + 2) ) else ( ans := Set{a, b}->max() - ("" + (((a + b) / 2)))->toInteger() ; for i : Integer.subrange(0, Set{a, b}->min() + 1-1) do ( execute ((("" + ((ans)))->toInteger()) : arr) ; ans := ans + 2) ; ans := Set{a, b}->max() - (("" + (((a + b) / 2)))->toInteger() + 1) ; for i : Integer.subrange(0, Set{a, b}->min() + 1-1) do ( execute ((("" + ((ans)))->toInteger()) : arr) ; ans := ans + 2) ) ; arr := arr->sort() ; execute ((arr)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name arr))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def flipAndInvertImage(self,A): for row in A : for i in xrange((len(row)+1)/2): row[i],row[~ i]=row[~ i]^ 1,row[i]^ 1 return A ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation flipAndInvertImage(A : OclAny) : OclAny pre: true post: true activity: for row : A do ( for i : xrange(((row)->size() + 1) / 2) do ( var row[i+1] : OclAny := null; var row[MathLib.bitwiseNot(i)+1] : OclAny := null; Sequence{row[i+1],row[MathLib.bitwiseNot(i)+1]} := Sequence{MathLib.bitwiseXor(row[MathLib.bitwiseNot(i)+1], 1),MathLib.bitwiseXor(row[i+1], 1)})) ; return A; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countConsecutive(s): count=-1 for i in range(len(s)-1): if(i<=len(s)): if(s[i]is s[i+1]): i+=1 else : count+=1 return count if __name__=='__main__' : str="44522255" print(countConsecutive(str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var OclType["String"] : String := "44522255" ; execute (countConsecutive(OclType["String"]))->display() ) else skip; operation countConsecutive(s : OclAny) : OclAny pre: true post: true activity: var count : int := -1 ; for i : Integer.subrange(0, (s)->size() - 1-1) do ( if ((i->compareTo((s)->size())) <= 0) then ( if (s[i+1] <>= s[i + 1+1]) then ( i := i + 1 ) else ( count := count + 1 ) ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findKHCF(x,y,k): small=min(x,y) count=1 for i in range(2,small+1): if(x % i==0 and y % i==0): count=count+1 if(count==k): return i return-1 x=4 y=24 k=3 print(findKHCF(x,y,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := 4 ; y := 24 ; k := 3 ; execute (findKHCF(x, y, k))->display(); operation findKHCF(x : OclAny, y : OclAny, k : OclAny) : OclAny pre: true post: true activity: var small : OclAny := Set{x, y}->min() ; var count : int := 1 ; for i : Integer.subrange(2, small + 1-1) do ( if (x mod i = 0 & y mod i = 0) then ( count := count + 1 ) else skip ; if (count = k) then ( return i ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def largestPower(n,p): x=0 while n : n/=p x+=n return x n=10 ; p=3 print("The largest power of %d that divides %d! is %d\n" %(p,n,largestPower(n,p))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 10; p := 3 ; execute (StringLib.format("The largest power of %d that divides %d! is %d\n",Sequence{p, n, largestPower(n, p)}))->display(); operation largestPower(n : OclAny, p : OclAny) : OclAny pre: true post: true activity: var x : int := 0 ; while n do ( n := n / p ; x := x + n) ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def largestPower(n,p): x=0 while n : n/=p x+=n return x n=10 ; p=3 print("The largest power of %d that divides %d! is %d\n" %(p,n,largestPower(n,p))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 10; p := 3 ; execute (StringLib.format("The largest power of %d that divides %d! is %d\n",Sequence{p, n, largestPower(n, p)}))->display(); operation largestPower(n : OclAny, p : OclAny) : OclAny pre: true post: true activity: var x : int := 0 ; while n do ( n := n / p ; x := x + n) ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def soinnsuubunnkai(n): dic=defaultdict(int) i=2 while i*i<=n : while n % i==0 : dic[i]+=1 n//=i i+=1 if n!=1 : dic[n]+=1 return list(dic.values()) def saiki(values,score,ind,end): if ind==end : return score return saiki(values,score*values[ind],ind+1,end)*2+saiki(values,score,ind+1,end) while True : n=int(input()) if n==0 : break values=soinnsuubunnkai(n) print((saiki(values,1,0,len(values))+1)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; values := soinnsuubunnkai(n) ; execute ((saiki(values, 1, 0, (values)->size()) + 1) div 2)->display()); operation soinnsuubunnkai(n : OclAny) : OclAny pre: true post: true activity: var dic : OclAny := defaultdict(OclType["int"]) ; var i : int := 2 ; while (i * i->compareTo(n)) <= 0 do ( while n mod i = 0 do ( dic[i+1] := dic[i+1] + 1 ; n := n div i) ; i := i + 1) ; if n /= 1 then ( dic[n+1] := dic[n+1] + 1 ) else skip ; return (dic.values()); operation saiki(values : OclAny, score : OclAny, ind : OclAny, end : OclAny) : OclAny pre: true post: true activity: if ind = end then ( return score ) else skip ; return saiki(values, score * values[ind+1], ind + 1, end) * 2 + saiki(values, score, ind + 1, end); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import zip_longest if __name__=='__main__' : int(input()) A=list(map(int,input().split())) int(input()) B=list(map(int,input().split())) win=0 for a,b in zip_longest(A,B,fillvalue=-1): if ab : win=0 break print(win) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( OclType["int"]((OclFile["System.in"]).readLine()) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; OclType["int"]((OclFile["System.in"]).readLine()) ; var B : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var win : int := 0 ; for _tuple : zip_longest(A, B, (argument (test (logical_test (comparison (expr (atom (name fillvalue)))))) = (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if (a->compareTo(b)) < 0 then ( win := 1 ; break ) else (if (a->compareTo(b)) > 0 then ( win := 0 ; break ) else skip)) ; execute (win)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countEle(s,a,N): mp={} for i in range(0,N): num=a[i] if num in mp : print("0",end=" ") else : cnt=0 while s[-1]!=num : mp[s.pop()]=True cnt+=1 s.pop() cnt+=1 print(cnt,end=" ") if __name__=="__main__" : N=5 s=[] s.append(1) s.append(2) s.append(3) s.append(4) s.append(6) a=[6,3,4,1,2] countEle(s,a,N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := 5 ; s := Sequence{} ; execute ((1) : s) ; execute ((2) : s) ; execute ((3) : s) ; execute ((4) : s) ; execute ((6) : s) ; a := Sequence{6}->union(Sequence{3}->union(Sequence{4}->union(Sequence{1}->union(Sequence{ 2 })))) ; countEle(s, a, N) ) else skip; operation countEle(s : OclAny, a : OclAny, N : OclAny) pre: true post: true activity: var mp : OclAny := Set{} ; for i : Integer.subrange(0, N-1) do ( var num : OclAny := a[i+1] ; if (mp)->includes(num) then ( execute ("0")->display() ) else ( var cnt : int := 0 ; while s->last() /= num do ( mp[s->last()+1] := true ; cnt := cnt + 1) ; s := s->front() ; cnt := cnt + 1 ; execute (cnt)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def minCostJumpsDP(A,k): size=len(A) x=[sys.maxsize]*(size) x[0]=0 for i in range(size): j=i+1 while junion(Sequence{26}->union(Sequence{37}->union(Sequence{35}->union(Sequence{33}->union(Sequence{35}->union(Sequence{ 56 })))))) ; execute (minCostJumpsDP(input_, 3))->display() ) else skip; operation minCostJumpsDP(A : OclAny, k : OclAny) : OclAny pre: true post: true activity: var size : int := (A)->size() ; var x : Sequence := MatrixLib.elementwiseMult(Sequence{ (trailer . (name maxsize)) }, (size)) ; x->first() := 0 ; for i : Integer.subrange(0, size-1) do ( var j : OclAny := i + 1 ; while (j->compareTo(i + k + 1)) < 0 & (j->compareTo(size)) < 0 do ( x[j+1] := Set{x[j+1], x[i+1] + (A[i+1] - A[j+1])->abs()}->min() ; j := j + 1)) ; return x[size - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkForSorting(arr,n): for i in range(0,n-1): if(arr[i]>arr[i+1]): if(arr[i]-arr[i+1]==1): arr[i],arr[i+1]=arr[i+1],arr[i] else : return False return True arr=[1,0,3,2] n=len(arr) if(checkForSorting(arr,n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{0}->union(Sequence{3}->union(Sequence{ 2 }))) ; n := (arr)->size() ; if (checkForSorting(arr, n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation checkForSorting(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n - 1-1) do ( if ((arr[i+1]->compareTo(arr[i + 1+1])) > 0) then ( if (arr[i+1] - arr[i + 1+1] = 1) then ( var arr[i+1] : OclAny := null; var arr[i + 1+1] : OclAny := null; Sequence{arr[i+1],arr[i + 1+1]} := Sequence{arr[i + 1+1],arr[i+1]} ) else ( return false ) ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find_prob(N,P): dp=[0]*(n+1) dp[0]=1 dp[1]=0 dp[2]=P dp[3]=1-P for i in range(4,N+1): dp[i]=(P)*dp[i-2]+(1-P)*dp[i-3] return dp[N] n=5 p=0.2 print(round(find_prob(n,p),2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := 5 ; var p : double := 0.2 ; execute (MathLib.roundN(find_prob(n, p), 2))->display(); operation find_prob(N : OclAny, P : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; dp->first() := 1 ; dp[1+1] := 0 ; dp[2+1] := P ; dp[3+1] := 1 - P ; for i : Integer.subrange(4, N + 1-1) do ( dp[i+1] := (P) * dp[i - 2+1] + (1 - P) * dp[i - 3+1]) ; return dp[N+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,s=map(int,input().split()) x=abs(b)+abs(a) if scollect( _x | (OclType["int"])->apply(_x) ) ; var x : double := (b)->abs() + (a)->abs() ; if (s->compareTo(x)) < 0 then ( execute ("NO")->display() ) else (if s = x then ( execute ("YES")->display() ) else ( if (s - x) mod 2 = 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,s=map(int,input().split()) if(((s-(abs(a)+abs(b)))% 2)==0)and(s>=abs(a)+abs(b)): print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var s : OclAny := null; Sequence{a,b,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (((s - ((a)->abs() + (b)->abs())) mod 2) = 0) & ((s->compareTo((a)->abs() + (b)->abs())) >= 0) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(a,b,s): if scollect( _x | (OclType["int"])->apply(_x) ) ; var ans : OclAny := solve((a)->abs(), (b)->abs(), s) ; execute (ans)->display() ) else skip; operation solve(a : OclAny, b : OclAny, s : OclAny) : OclAny pre: true post: true activity: if (s->compareTo(a + b)) < 0 then ( return "No" ) else skip ; var x : double := s - a - b ; if x mod 2 then ( return "No" ) else skip ; return "Yes"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,s=map(int,input().split()) x=s-abs(a)-abs(b) if x>=0 and x % 2==0 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var s : OclAny := null; Sequence{a,b,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : double := s - (a)->abs() - (b)->abs() ; if x >= 0 & x mod 2 = 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,steps=map(int,input().split()) if stepscollect( _x | (OclType["int"])->apply(_x) ) ; if (steps->compareTo((a)->abs() + (b)->abs())) < 0 then ( execute ('No')->display() ) else ( if (steps - ((a)->abs() + (b)->abs())) mod 2 = 0 then ( execute ('Yes')->display() ) else ( execute ('No')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isSubSeqDivisible(str): n=len(str) dp=[[0 for i in range(10)]for i in range(n+1)] arr=[0 for i in range(n+1)] for i in range(1,n+1): arr[i]=int(str[i-1]); for i in range(1,n+1): dp[i][arr[i]% 8]=1 ; for j in range(8): if(dp[i-1][j]>dp[i][(j*10+arr[i])% 8]): dp[i][(j*10+arr[i])% 8]=dp[i-1][j] if(dp[i-1][j]>dp[i][j]): dp[i][j]=dp[i-1][j] for i in range(1,n+1): if(dp[i][0]==1): return True return False str="3144" if(isSubSeqDivisible(str)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclType["String"] := "3144" ; if (isSubSeqDivisible(OclType["String"])) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isSubSeqDivisible(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var n : int := (OclType["String"])->size() ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, 10-1)->select(i | true)->collect(i | (0)))) ; var arr : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(1, n + 1-1) do ( arr[i+1] := ("" + ((("" + ([i - 1+1])))))->toInteger();) ; for i : Integer.subrange(1, n + 1-1) do ( dp[i+1][arr[i+1] mod 8+1] := 1; ; for j : Integer.subrange(0, 8-1) do ( if ((dp[i - 1+1][j+1]->compareTo(dp[i+1][(j * 10 + arr[i+1]) mod 8+1])) > 0) then ( dp[i+1][(j * 10 + arr[i+1]) mod 8+1] := dp[i - 1+1][j+1] ) else skip ; if ((dp[i - 1+1][j+1]->compareTo(dp[i+1][j+1])) > 0) then ( dp[i+1][j+1] := dp[i - 1+1][j+1] ) else skip)) ; for i : Integer.subrange(1, n + 1-1) do ( if (dp[i+1]->first() = 1) then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printConsecutive(last,first): print(first,end="") first+=1 for x in range(first,last+1): print("+",x,end="") def findConsecutive(N): for last in range(1,N): for first in range(0,last): if 2*N==(last-first)*(last+first+1): print(N,"=",end="") printConsecutive(last,first+1) return print("-1") n=12 findConsecutive(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := 12 ; findConsecutive(n); operation printConsecutive(last : OclAny, first : OclAny) pre: true post: true activity: execute (first)->display() ; first := first + 1 ; for x : Integer.subrange(first, last + 1-1) do ( execute ("+")->display()); operation findConsecutive(N : OclAny) pre: true post: true activity: for last : Integer.subrange(1, N-1) do ( for first : Integer.subrange(0, last-1) do ( if 2 * N = (last - first) * (last + first + 1) then ( execute (N)->display() ; printConsecutive(last, first + 1) ; return ) else skip)) ; execute ("-1")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def StrictlyPositiveXor(A,N): allxor=0 ; checkallzero=True ; for i in range(N): allxor ^=A[i]; if(A[i]>0): checkallzero=False ; if(allxor!=0): return N ; if(checkallzero): return-1 ; l=N ; r=-1 ; for i in range(N): if(A[i]>0): l=i+1 ; break ; for i in range(N-1,-1,-1): if(A[i]>0): r=i+1 ; break ; return max(N-l,r-1); if __name__=="__main__" : A=[1,0,0,1]; N=len(A); print(StrictlyPositiveXor(A,N)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( A := Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 1 }))); ; N := (A)->size(); ; execute (StrictlyPositiveXor(A, N))->display(); ) else skip; operation StrictlyPositiveXor(A : OclAny, N : OclAny) pre: true post: true activity: var allxor : int := 0; ; var checkallzero : boolean := true; ; for i : Integer.subrange(0, N-1) do ( allxor := allxor xor A[i+1]; ; if (A[i+1] > 0) then ( checkallzero := false; ) else skip) ; if (allxor /= 0) then ( return N; ) else skip ; if (checkallzero) then ( return -1; ) else skip ; var l : OclAny := N; var r : int := -1; ; for i : Integer.subrange(0, N-1) do ( if (A[i+1] > 0) then ( l := i + 1; ; break; ) else skip) ; for i : Integer.subrange(-1 + 1, N - 1)->reverse() do ( if (A[i+1] > 0) then ( r := i + 1; ; break; ) else skip) ; return Set{N - l, r - 1}->max();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=[] w=9 b=9 w1=[] b1=[] s1=[] for i in range(8): s=input().strip() s1.append(s) for j in range(8): if "W"==s[j]and j not in b1 : w=min(w,i) if "B"==s[j]: b1.append(j) s1=s1[: :-1] for i in range(8): s=s1[i] for j in range(8): if "B"==s[j]and j not in w1 : b=min(b,i) if "W"==s[j]: w1.append(j) if w<=b : print("A") else : print("B") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := Sequence{} ; var w : int := 9 ; var b : int := 9 ; var w1 : Sequence := Sequence{} ; var b1 : Sequence := Sequence{} ; var s1 : Sequence := Sequence{} ; for i : Integer.subrange(0, 8-1) do ( s := input()->trim() ; execute ((s) : s1) ; for j : Integer.subrange(0, 8-1) do ( if "W" = s[j+1] & (b1)->excludes(j) then ( w := Set{w, i}->min() ) else skip ; if "B" = s[j+1] then ( execute ((j) : b1) ) else skip)) ; s1 := s1(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; for i : Integer.subrange(0, 8-1) do ( s := s1[i+1] ; for j : Integer.subrange(0, 8-1) do ( if "B" = s[j+1] & (w1)->excludes(j) then ( b := Set{b, i}->min() ) else skip ; if "W" = s[j+1] then ( execute ((j) : w1) ) else skip)) ; if (w->compareTo(b)) <= 0 then ( execute ("A")->display() ) else ( execute ("B")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ww,bb=[],[] min_b,min_w,board=7,7,[] rowsi=[0,1,2,3,4,5,6,7] for row in rowsi : ll=input() if 'B' in ll : col=-1 for _ in rowsi[: ll.count('B')]: col=ll.index('B',col+1) bb.append([row,col,None,7-row]) if 'W' in ll : col=-1 for _ in rowsi[: ll.count('W')]: col=ll.index('W',col+1) unobstructed=True for ur in rowsi[: row]: if board[ur][col]!='.' : unobstructed=False break if unobstructed and rowto_win : min_b=bb[bi][3] print('A' if min_w<=min_b else 'B') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ww : OclAny := null; var bb : OclAny := null; Sequence{ww,bb} := Sequence{Sequence{},Sequence{}} ; var min_b : OclAny := null; var min_w : OclAny := null; var board : OclAny := null; Sequence{min_b,min_w,board} := Sequence{7,7,Sequence{}} ; var rowsi : Sequence := Sequence{0}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 7 }))))))) ; for row : rowsi do ( var ll : String := (OclFile["System.in"]).readLine() ; if (ll)->characters()->includes('B') then ( var col : int := -1 ; for _anon : rowsi.subrange(1,ll->count('B')) do ( col := ll->indexOf('B', col + 1) - 1 ; execute ((Sequence{row}->union(Sequence{col}->union(Sequence{null}->union(Sequence{ 7 - row })))) : bb)) ) else skip ; if (ll)->characters()->includes('W') then ( col := -1 ; for _anon : rowsi.subrange(1,ll->count('W')) do ( col := ll->indexOf('W', col + 1) - 1 ; var unobstructed : boolean := true ; for ur : rowsi.subrange(1,row) do ( if board[ur+1][col+1] /= '.' then ( unobstructed := false ; break ) else skip) ; if unobstructed & (row->compareTo(min_w)) < 0 then ( var min_w : OclAny := row ) else skip ; execute ((Sequence{row}->union(Sequence{col}->union(Sequence{unobstructed}->union(Sequence{ row })))) : ww)) ) else skip ; execute ((ll) : board)) ; for bi : Integer.subrange(0, (bb)->size()-1) do ( var row : OclAny := null; var _anon : OclAny := null; var to_win : OclAny := null; Sequence{row,col,_anon,to_win} := bb[bi+1] ; unobstructed := true ; for r : rowsi.subrange(row + 1+1) do ( if board[r+1][col+1] /= '.' then ( bb[bi+1][2+1] := false ; unobstructed := false ; break ) else skip) ; if unobstructed then ( bb[bi+1][2+1] := true ; if (min_b->compareTo(to_win)) > 0 then ( var min_b : OclAny := bb[bi+1][3+1] ) else skip ) else skip) ; execute (if (min_w->compareTo(min_b)) <= 0 then 'A' else 'B' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n=int(input()) nums=[int(i)for i in input().split()] c=Counter(nums) if sum(nums)==0 : print('Yes') elif len(c)==2 : for k,v in c.items(): if k==0 : if v!=n//3 : print('No') break else : if v!=n//3*2 : print('No') break else : print('Yes') elif len(c)==3 : t=0 for k,v in c.items(): if v!=n//3 : print('No') break t ^=k else : if t : print('No') else : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nums : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var c : OclAny := Counter(nums) ; if (nums)->sum() = 0 then ( execute ('Yes')->display() ) else (if (c)->size() = 2 then ( (compound_stmt for (exprlist (expr (atom (name k))) , (expr (atom (name v)))) in (testlist (test (logical_test (comparison (expr (atom (name c)) (trailer . (name items) (arguments ( )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name k)))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name v)))) != (comparison (expr (expr (atom (name n))) // (expr (atom (number (integer 3))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'No'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name v)))) != (comparison (expr (expr (expr (atom (name n))) // (expr (atom (number (integer 3))))) * (expr (atom (number (integer 2))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'No'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'Yes'))))))) ))))))))))))))) ) else (if (c)->size() = 3 then ( var t : int := 0 ; (compound_stmt for (exprlist (expr (atom (name k))) , (expr (atom (name v)))) in (testlist (test (logical_test (comparison (expr (atom (name c)) (trailer . (name items) (arguments ( )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name v)))) != (comparison (expr (expr (atom (name n))) // (expr (atom (number (integer 3))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'No'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name t)))))))) (assign_part ^= (testlist (test (logical_test (comparison (expr (atom (name k)))))))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name t)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'No'))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'Yes'))))))) ))))))))))))))))))) ) else ( execute ('No')->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline g=[input()[:-1]for _ in range(8)] a,b=9,9 for i in range(8): for j in range(8): if g[i][j]=='W' : k=i while k : if g[k][j]=='B' : break k-=1 if k==0 and g[0][j]!='B' : a=i break if a!=9 : break for i in range(7,-1,-1): for j in range(8): if g[i][j]=='B' : k=i while k<7 : if g[k][j]=='W' : break k+=1 if k==7 and g[7][j]!='W' : b=7-i break if b!=9 : break if a<=b : print('A') else : print('B') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var g : Sequence := Integer.subrange(0, 8-1)->select(_anon | true)->collect(_anon | (input()->front())) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{9,9} ; for i : Integer.subrange(0, 8-1) do ( for j : Integer.subrange(0, 8-1) do ( if g[i+1][j+1] = 'W' then ( var k : OclAny := i ; while k do ( if g[k+1][j+1] = 'B' then ( break ) else skip ; k := k - 1) ; if k = 0 & g->first()[j+1] /= 'B' then ( var a : OclAny := i ; break ) else skip ) else skip) ; if a /= 9 then ( break ) else skip) ; for i : Integer.subrange(-1 + 1, 7)->reverse() do ( for j : Integer.subrange(0, 8-1) do ( if g[i+1][j+1] = 'B' then ( k := i ; while k < 7 do ( if g[k+1][j+1] = 'W' then ( break ) else skip ; k := k + 1) ; if k = 7 & g[7+1][j+1] /= 'W' then ( var b : double := 7 - i ; break ) else skip ) else skip) ; if b /= 9 then ( break ) else skip) ; if (a->compareTo(b)) <= 0 then ( execute ('A')->display() ) else ( execute ('B')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- g,v=[input()for i in range(8)],[8,8] for i in range(8): for j in range(8): if g[i][j]=='W' and all(g[k][j]=='.' for k in range(i)): v[0]=min(v[0],i) elif g[i][j]=='B' and all(g[k][j]=='.' for k in range(i+1,8)): v[1]=min(v[1],7-i) print('A' if v[0]<=v[1]else 'B') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var g : OclAny := null; var v : OclAny := null; Sequence{g,v} := Sequence{Integer.subrange(0, 8-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())),Sequence{8}->union(Sequence{ 8 })} ; for i : Integer.subrange(0, 8-1) do ( for j : Integer.subrange(0, 8-1) do ( if g[i+1][j+1] = 'W' & ((argument (test (logical_test (comparison (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) == (comparison (expr (atom '.')))))) (comp_for for (exprlist (expr (atom (name k)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))->forAll( _x | _x = true ) then ( v->first() := Set{v->first(), i}->min() ) else (if g[i+1][j+1] = 'B' & ((argument (test (logical_test (comparison (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) == (comparison (expr (atom '.')))))) (comp_for for (exprlist (expr (atom (name k)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 8))))))))) )))))))))->forAll( _x | _x = true ) then ( v[1+1] := Set{v[1+1], 7 - i}->min() ) else skip))) ; execute (if (v->first()->compareTo(v[1+1])) <= 0 then 'A' else 'B' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pr(i,u): global total print(team[i][0]) total,affi[u]=total+1,affi[u]+1 while True : n=int(input()) if n==0 : break team=[] for i in range(n): id,u,a,p=map(int,input().split()) team.append((id,u,a,p)) team.sort(key=lambda x :(-x[2],x[3],x[0])) total,affi=0,[0]*1002 for i in range(n): u=team[i][1] if total<10 and affi[u]<3 : pr(i,u) elif total<20 and affi[u]<2 : pr(i,u) elif total<26 and affi[u]<1 : pr(i,u) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute total : OclAny; operation initialise() pre: true post: true activity: skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var team : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var id : OclAny := null; var a : OclAny := null; var p : OclAny := null; Sequence{id,u,a,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{id, u, a, p}) : team)) ; team := team->sort() ; var affi : OclAny := null; Sequence{total,affi} := Sequence{0,MatrixLib.elementwiseMult(Sequence{ 0 }, 1002)} ; for i : Integer.subrange(0, n-1) do ( u := team[i+1][1+1] ; if total < 10 & affi[u+1] < 3 then ( pr(i, u) ) else (if total < 20 & affi[u+1] < 2 then ( pr(i, u) ) else (if total < 26 & affi[u+1] < 1 then ( pr(i, u) ) else skip ) ) )); operation pr(i : OclAny, u : OclAny) pre: true post: true activity: skip ; execute (team[i+1]->first())->display() ; var affi[u+1] : OclAny := null; Sequence{total,affi[u+1]} := Sequence{total + 1,affi[u+1] + 1}; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin from operator import itemgetter while 1 : n=int(stdin.readline().rstrip()) if n==0 : break teams=[] Selected_team_id=[] cnt_selected_teams=0 dic_shozoku_and_cntSelected={} for i in range(n): *t,=map(int,stdin.readline().split()) teams.append(t) if not dic_shozoku_and_cntSelected.__contains__(t[1]): dic_shozoku_and_cntSelected[t[1]]=0 sorted_teams1=sorted(teams,key=itemgetter(3,0)) sorted_teams=sorted(sorted_teams1,key=itemgetter(2),reverse=True) for t in sorted_teams : cnt_same_shozoku=dic_shozoku_and_cntSelected[t[1]] if cnt_selected_teams<10 : if cnt_same_shozoku<3 : Selected_team_id.append(t[0]) dic_shozoku_and_cntSelected[t[1]]+=1 cnt_selected_teams+=1 elif cnt_selected_teams<20 : if cnt_same_shozoku<2 : Selected_team_id.append(t[0]) dic_shozoku_and_cntSelected[t[1]]+=1 cnt_selected_teams+=1 elif cnt_selected_teams<26 : if cnt_same_shozoku<1 : Selected_team_id.append(t[0]) dic_shozoku_and_cntSelected[t[1]]+=1 cnt_selected_teams+=1 print("\n".join(map(str,Selected_team_id))) ------------------------------------------------------------ OCL File: --------- class FromPython { suite`nestedAttributeDefinitions operation initialise() pre: true post: true activity: skip ; skip ; while 1 do ( var n : int := ("" + ((stdin.readLine().rstrip())))->toInteger() ; if n = 0 then ( break ) else skip ; var teams : Sequence := Sequence{} ; var Selected_team_id : Sequence := Sequence{} ; var cnt_selected_teams : int := 0 ; var dic_shozoku_and_cntSelected : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do (suite)) ; (testlist_star_expr (star_expr * (expr (atom (name t)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name t)))) ,)} := (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sort_cmp(x,y): if x[2]==y[2]: return x[3]x[2] def solve(n): teams=[] for i in range(n): teams.append(list(map(int,raw_input().split()))) teams=sorted(teams,key=lambda x :-1e12*x[2]+x[3]*1e6+x[0]) A=[] B=[] threshold=3 for team in teams : if len(A)==10 : threshold=2 elif len(A)==20 : threshold=1 if B.count(team[1])toInteger() ; if n = 0 then ( break ) else skip ; solve(n)); operation sort_cmp(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if x[2+1] = y[2+1] then ( return (x[3+1]->compareTo(y[3+1])) < 0 ) else ( return (x[2+1]->compareTo(x[2+1])) > 0 ); operation solve(n : OclAny) pre: true post: true activity: var teams : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((((raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : teams)) ; teams := teams->sortedBy($x | (lambda x : OclAny in (-("1e12")->toReal() * x[2+1] + x[3+1] * ("1e6")->toReal() + x->first()))->apply($x)) ; var A : Sequence := Sequence{} ; var B : Sequence := Sequence{} ; var threshold : int := 3 ; for team : teams do ( if (A)->size() = 10 then ( threshold := 2 ) else (if (A)->size() = 20 then ( threshold := 1 ) else skip) ; if (B->count(team[1+1])->compareTo(threshold)) < 0 then ( execute ((team->first()) : A) ; execute ((team[1+1]) : B) ) else skip ; if (A)->size() = 26 then ( break ) else skip) ; for a : A do ( execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict while True : n=int(input()) if n==0 : break teams=[] for _ in range(n): i,u,a,p=map(int,input().split()) teams.append((-a,p,i,u)) teams.sort() u_counter=defaultdict(int) all_counter=0 selected=[] for _,_,i,u in teams : if all_counter<10 and u_counter[u]<3 or all_counter<20 and u_counter[u]<2 or all_counter<26 and u_counter[u]<1 : u_counter[u]+=1 all_counter+=1 selected.append(i) [print(s)for s in selected] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var teams : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var i : OclAny := null; var u : OclAny := null; var a : OclAny := null; var p : OclAny := null; Sequence{i,u,a,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{-a, p, i, u}) : teams)) ; teams := teams->sort() ; var u_counter : OclAny := defaultdict(OclType["int"]) ; var all_counter : int := 0 ; var selected : Sequence := Sequence{} ; for _tuple : teams do (var _indx : int := 1; var _anon : OclAny := _tuple->at(_indx); _indx := _indx + 1; var _anon : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var u : OclAny := _tuple->at(_indx); if all_counter < 10 & u_counter[u+1] < 3 or all_counter < 20 & u_counter[u+1] < 2 or all_counter < 26 & u_counter[u+1] < 1 then ( u_counter[u+1] := u_counter[u+1] + 1 ; all_counter := all_counter + 1 ; execute ((i) : selected) ) else skip)) ; ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) a=list(map(int,input().split())) odd=0 m2=0 m4=0 for n in a : if n % 2==1 : odd+=1 elif n % 4!=0 : m2+=1 else : m4+=1 if m4>=odd or(m2==0 and m4>=odd-1): print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var odd : int := 0 ; var m2 : int := 0 ; var m4 : int := 0 ; for n : a do ( if n mod 2 = 1 then ( odd := odd + 1 ) else (if n mod 4 /= 0 then ( m2 := m2 + 1 ) else ( m4 := m4 + 1 ) ) ) ; if (m4->compareTo(odd)) >= 0 or (m2 = 0 & (m4->compareTo(odd - 1)) >= 0) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : in_tmp=input() if(in_tmp=="0"): break list_team=[] for i in range(int(in_tmp)): list_team.append(list(map(int,input().split()))) list_sorted=sorted(list_team,key=lambda x :(-x[2],x[3],x[0])) cnt_passed=0 dict_passed={} for item in list_sorted : if(item[1]not in dict_passed.keys()): dict_passed[item[1]]=0 if(cnt_passed<10): if(dict_passed[item[1]]<3): print(item[0]) dict_passed[item[1]]+=1 cnt_passed+=1 elif(cnt_passed<20): if(dict_passed[item[1]]<2): print(item[0]) dict_passed[item[1]]+=1 cnt_passed+=1 elif(cnt_passed<26): if(dict_passed[item[1]]<1): print(item[0]) dict_passed[item[1]]+=1 cnt_passed+=1 else : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var in_tmp : String := (OclFile["System.in"]).readLine() ; if (in_tmp = "0") then ( break ) else skip ; var list_team : Sequence := Sequence{} ; for i : Integer.subrange(0, ("" + ((in_tmp)))->toInteger()-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : list_team)) ; var list_sorted : Sequence := list_team->sortedBy($x | (lambda x : OclAny in (Sequence{-x[2+1], x[3+1], x->first()}))->apply($x)) ; var cnt_passed : int := 0 ; var dict_passed : OclAny := Set{} ; for item : list_sorted do ( if ((dict_passed.keys())->excludes(item[1+1])) then ( dict_passed[item[1+1]+1] := 0 ) else skip ; if (cnt_passed < 10) then ( if (dict_passed[item[1+1]+1] < 3) then ( execute (item->first())->display() ; dict_passed[item[1+1]+1] := dict_passed[item[1+1]+1] + 1 ; cnt_passed := cnt_passed + 1 ) else skip ) else (if (cnt_passed < 20) then ( if (dict_passed[item[1+1]+1] < 2) then ( execute (item->first())->display() ; dict_passed[item[1+1]+1] := dict_passed[item[1+1]+1] + 1 ; cnt_passed := cnt_passed + 1 ) else skip ) else (if (cnt_passed < 26) then ( if (dict_passed[item[1+1]+1] < 1) then ( execute (item->first())->display() ; dict_passed[item[1+1]+1] := dict_passed[item[1+1]+1] + 1 ; cnt_passed := cnt_passed + 1 ) else skip ) else ( break ) ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPalindrome(n): divisor=1 while(n/divisor>=10): divisor*=10 while(n!=0): leading=n//divisor trailing=n % 10 if(leading!=trailing): return False n=(n % divisor)//10 divisor=divisor/100 return True if(isPalindrome(1001)): print('Yes,it is palindrome') else : print('No,not palindrome') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if (isPalindrome(1001)) then ( execute ('Yes,it is palindrome')->display() ) else ( execute ('No,not palindrome')->display() ); operation isPalindrome(n : OclAny) : OclAny pre: true post: true activity: var divisor : int := 1 ; while (n / divisor >= 10) do ( divisor := divisor * 10) ; while (n /= 0) do ( var leading : int := n div divisor ; var trailing : int := n mod 10 ; if (leading /= trailing) then ( return false ) else skip ; n := (n mod divisor) div 10 ; divisor := divisor / 100) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=26 mod=3001 def CntSubstr(s,l): hash=0 ; for i in range(l): hash=(hash*x+(ord(s[i])-97))% mod ; pow_l=1 ; for i in range(l-1): pow_l=(pow_l*x)% mod ; result=set(); result.add(hash); for i in range(l,len(s)): hash=((hash-pow_l*(ord(s[i-l])-97)+2*mod)*x+(ord(s[i])-97))% mod ; result.add(hash); print(len(result)); if __name__=="__main__" : s="abcba" ; l=2 ; CntSubstr(s,l); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 26 ; var mod : int := 3001 ; skip ; if __name__ = "__main__" then ( s := "abcba"; ; l := 2; ; CntSubstr(s, l); ) else skip; operation CntSubstr(s : OclAny, l : OclAny) pre: true post: true activity: var hash : int := 0; ; for i : Integer.subrange(0, l-1) do ( hash := (hash * x + ((s[i+1])->char2byte() - 97)) mod mod;) ; var pow_l : int := 1; ; for i : Integer.subrange(0, l - 1-1) do ( pow_l := (pow_l * x) mod mod;) ; var result : Set := Set{}->union(()); ; execute ((hash) : result); ; for i : Integer.subrange(l, (s)->size()-1) do ( hash := ((hash - pow_l * ((s[i - l+1])->char2byte() - 97) + 2 * mod) * x + ((s[i+1])->char2byte() - 97)) mod mod; ; execute ((hash) : result);) ; execute ((result)->size())->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() length=len(s) ans=0 for i in range(length//2): if(s[i],s[-(i+1)])not in(("i","i"),("w","w"),("(",")"),(")","(")): ans+=1 if length % 2 and s[length//2]in("(",")"): ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var length : int := (s)->size() ; var ans : int := 0 ; for i : Integer.subrange(0, length div 2-1) do ( if (Sequence{Sequence{"i", "i"}, Sequence{"w", "w"}, Sequence{"(", ")"}, Sequence{")", "("}})->excludes(Sequence{s[i+1], s->reverse()->at(-(-(i + 1)))}) then ( ans := ans + 1 ) else skip) ; if length mod 2 & (Sequence{"(", ")"})->includes(s[length div 2+1]) then ( ans := ans + 1 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=list(map(int,input().split())) hats=A[:] import copy from collections import defaultdict d=defaultdict(lambda : 0) for h in hats : d[h]+=1 def f(): if len(d)==3 : xor=0 for key in d : xor ^=key if xor==0 : lsit_d=list(d.keys()) if d[lsit_d[0]]==d[lsit_d[1]]and d[lsit_d[0]]==d[lsit_d[2]]: return 'Yes' else : return 'No' else : return 'No' if len(d)==1 : lsit_d=list(d.keys()) if lsit_d[0]==0 : return 'Yes' if len(d)==2 : if d[0]*2==N-d[0]: return 'Yes' return 'No' print(f()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var hats : Sequence := A ; skip ; skip ; var d : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; for h : hats do ( d[h+1] := d[h+1] + 1) ; skip ; execute (f())->display(); operation f() : OclAny pre: true post: true activity: if (d)->size() = 3 then ( var xor : int := 0 ; for key : d do ( xor := xor xor key) ; if xor = 0 then ( var lsit_d : Sequence := (d.keys()) ; if d[lsit_d->first()+1] = d[lsit_d[1+1]+1] & d[lsit_d->first()+1] = d[lsit_d[2+1]+1] then ( return 'Yes' ) else ( return 'No' ) ) else ( return 'No' ) ) else skip ; if (d)->size() = 1 then ( lsit_d := (d.keys()) ; if lsit_d->first() = 0 then ( return 'Yes' ) else skip ) else skip ; if (d)->size() = 2 then ( if d->first() * 2 = N - d->first() then ( return 'Yes' ) else skip ) else skip ; return 'No'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- flip={'i' : 'i','w' : 'w','(' : ')',')' : '('} s=input() result=0 for i in range((len(s)+1)//2): result+=(flip[s[i]]!=s[len(s)-i-1]) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var flip : Map := Map{ 'i' |-> 'i' }->union(Map{ 'w' |-> 'w' }->union(Map{ '(' |-> ')' }->union(Map{ ')' |-> '(' }))) ; var s : String := (OclFile["System.in"]).readLine() ; var result : int := 0 ; for i : Integer.subrange(0, ((s)->size() + 1) div 2-1) do ( result := result + (flip[s[i+1]+1] /= s[(s)->size() - i - 1+1])) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s,c=input(),0 for i in range(len(s)//2): if s[i]=="i" or s[i]=="w" : if s[i]!=s[-i-1]: c+=1 elif s[i]=="(" : if s[-i-1]!=")" : c+=1 elif s[-i-1]!="(" : c+=1 if len(s)% 2 : if s[len(s)//2]==")" or s[len(s)//2]=="(" : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := null; var c : OclAny := null; Sequence{s,c} := Sequence{(OclFile["System.in"]).readLine(),0} ; for i : Integer.subrange(0, (s)->size() div 2-1) do ( if s[i+1] = "i" or s[i+1] = "w" then ( if s[i+1] /= s->reverse()->at(-(-i - 1)) then ( c := c + 1 ) else skip ) else (if s[i+1] = "(" then ( if s->reverse()->at(-(-i - 1)) /= ")" then ( c := c + 1 ) else skip ) else (if s->reverse()->at(-(-i - 1)) /= "(" then ( c := c + 1 ) else skip ) ) ) ; if (s)->size() mod 2 then ( if s[(s)->size() div 2+1] = ")" or s[(s)->size() div 2+1] = "(" then ( c := c + 1 ) else skip ) else skip ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() ans=0 ls=len(s) if ls % 2==1 : if s[ls//2]=="i" or s[ls//2]=="w" : pass else : ans+=1 for i in range(ls//2): if s[i]=="i" : if s[ls-i-1]!="i" : ans+=1 elif s[i]=="w" : if s[ls-i-1]!="w" : ans+=1 elif s[i]=="(" : if s[ls-i-1]!=")" : ans+=1 elif s[i]==")" : if s[ls-i-1]!="(" : ans+=1 else : for i in range(ls//2): if s[i]=="i" : if s[ls-i-1]!="i" : ans+=1 elif s[i]=="w" : if s[ls-i-1]!="w" : ans+=1 elif s[i]=="(" : if s[ls-i-1]!=")" : ans+=1 elif s[i]==")" : if s[ls-i-1]!="(" : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; var ls : int := (s)->size() ; if ls mod 2 = 1 then ( if s[ls div 2+1] = "i" or s[ls div 2+1] = "w" then ( skip ) else ( ans := ans + 1 ) ; for i : Integer.subrange(0, ls div 2-1) do ( if s[i+1] = "i" then ( if s[ls - i - 1+1] /= "i" then ( ans := ans + 1 ) else skip ) else (if s[i+1] = "w" then ( if s[ls - i - 1+1] /= "w" then ( ans := ans + 1 ) else skip ) else (if s[i+1] = "(" then ( if s[ls - i - 1+1] /= ")" then ( ans := ans + 1 ) else skip ) else (if s[i+1] = ")" then ( if s[ls - i - 1+1] /= "(" then ( ans := ans + 1 ) else skip ) else skip ) ) ) ) ) else ( for i : Integer.subrange(0, ls div 2-1) do ( if s[i+1] = "i" then ( if s[ls - i - 1+1] /= "i" then ( ans := ans + 1 ) else skip ) else (if s[i+1] = "w" then ( if s[ls - i - 1+1] /= "w" then ( ans := ans + 1 ) else skip ) else (if s[i+1] = "(" then ( if s[ls - i - 1+1] /= ")" then ( ans := ans + 1 ) else skip ) else (if s[i+1] = ")" then ( if s[ls - i - 1+1] /= "(" then ( ans := ans + 1 ) else skip ) else skip ) ) ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- arr=list(map(int,input().split())) counter=0 time=29 while arr[0]>0 or arr[1]>0 or arr[2]>0 : index=counter % 3 if arr[index]>1 : arr[index]-=2 elif arr[index]==1 : arr[index]-=1 counter+=1 time+=1 print(time) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var counter : int := 0 ; var time : int := 29 ; while arr->first() > 0 or arr[1+1] > 0 or arr[2+1] > 0 do ( var index : int := counter mod 3 ; if arr[index+1] > 1 then ( arr[index+1] := arr[index+1] - 2 ) else (if arr[index+1] = 1 then ( arr[index+1] := arr[index+1] - 1 ) else skip) ; counter := counter + 1 ; time := time + 1) ; execute (time)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=[int(x)for x in input().split()] t=29 ; j=0 while(l!=[0,0,0]): i=j % 3 if l[i]>1 : l[i]-=2 elif l[i]==1 : l[i]-=1 t+=1 j+=1 print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var t : int := 29; var j : int := 0 ; while (l /= Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))) do ( var i : int := j mod 3 ; if l[i+1] > 1 then ( l[i+1] := l[i+1] - 2 ) else (if l[i+1] = 1 then ( l[i+1] := l[i+1] - 1 ) else skip) ; t := t + 1 ; j := j + 1) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,*a=map(int,open(0).read().split()) s=[i % 4 for i in a] f,t=s.count(0),s.count(2) print("YNeos"[n-f-t+(t>0)>f+1 : : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := a->select(i | true)->collect(i | (i mod 4)) ; var f : OclAny := null; var t : OclAny := null; Sequence{f,t} := Sequence{s->count(0),s->count(2)} ; execute ("YNeos"(subscript (test (logical_test (comparison (comparison (expr (expr (expr (expr (atom (name n))) - (expr (atom (name f)))) - (expr (atom (name t)))) + (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name t)))) > (comparison (expr (atom (number (integer 0))))))))) ))))) > (comparison (expr (expr (atom (name f))) + (expr (atom (number (integer 1))))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- colors=list(map(int,input().split())) time=29 while any(colors): i=0 while i<3 and any(colors): colors[i]=max(0,colors[i]-2) time+=1 i+=1 print(time) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var colors : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var time : int := 29 ; while (colors)->exists( _x | _x = true ) do ( var i : int := 0 ; while i < 3 & (colors)->exists( _x | _x = true ) do ( colors[i+1] := Set{0, colors[i+1] - 2}->max() ; time := time + 1 ; i := i + 1)) ; execute (time)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- colors=list(map(int,input().split())) time=29 i=0 while any(colors): colors[i % 3]=max(0,colors[i % 3]-2) i+=1 print(time+i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var colors : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var time : int := 29 ; var i : int := 0 ; while (colors)->exists( _x | _x = true ) do ( colors[i mod 3+1] := Set{0, colors[i mod 3+1] - 2}->max() ; i := i + 1) ; execute (time + i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r,g,b=map(int,input().split()) r=r % 2+r//2 g=g % 2+g//2 b=b % 2+b//2 if max(r,g,b)==r==g==b : print(29+g*3) elif max(r,g,b)==r==g : print(28+g*3) elif max(r,g,b)==r==b : print(29+b*3) elif max(r,g,b)==g==b : print(29+b*3) elif max(r,g,b)==r : print(27+r*3) elif max(r,g,b)==g : print(28+g*3) elif max(r,g,b)==b : print(29+b*3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : OclAny := null; var g : OclAny := null; var b : OclAny := null; Sequence{r,g,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var r : int := r mod 2 + r div 2 ; var g : int := g mod 2 + g div 2 ; var b : int := b mod 2 + b div 2 ; if Set{r, g, b}->max() = r & (r == g) & (g == b) then ( execute (29 + g * 3)->display() ) else (if Set{r, g, b}->max() = r & (r == g) then ( execute (28 + g * 3)->display() ) else (if Set{r, g, b}->max() = r & (r == b) then ( execute (29 + b * 3)->display() ) else (if Set{r, g, b}->max() = g & (g == b) then ( execute (29 + b * 3)->display() ) else (if Set{r, g, b}->max() = r then ( execute (27 + r * 3)->display() ) else (if Set{r, g, b}->max() = g then ( execute (28 + g * 3)->display() ) else (if Set{r, g, b}->max() = b then ( execute (29 + b * 3)->display() ) else skip ) ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numOfSubseq(arr,n): i,inc_count,dec_count=0,0,0 ; max=[0]*n ; min=[0]*n ; k1=0 ; k2=0 ; if(arr[0]arr[i-1]and arr[i]>arr[i+1]): max[k2]=i ; k2+=1 ; if(arr[n-1]union(Sequence{8}->union(Sequence{11}->union(Sequence{13}->union(Sequence{10}->union(Sequence{15}->union(Sequence{14}->union(Sequence{16}->union(Sequence{ 20 })))))))); ; n := (arr)->size(); ; numOfSubseq(arr, n); ) else skip; operation numOfSubseq(arr : OclAny, n : OclAny) pre: true post: true activity: var i : OclAny := null; var inc_count : OclAny := null; var dec_count : OclAny := null; Sequence{i,inc_count,dec_count} := Sequence{0,0,0}; ; var max : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; var min : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; var k1 : int := 0; ; var k2 : int := 0; ; if ((arr->first()->compareTo(arr[1+1])) < 0) then ( Set{(arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k1)))))))) ])}->min() := 0; ; k1 := k1 + 1; ) else ( Set{(arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k2)))))))) ])}->max() := 0; ; k2 := k2 + 1; ) ; for i : Integer.subrange(1, n - 1-1) do ( if ((arr[i+1]->compareTo(arr[i - 1+1])) < 0 & (arr[i+1]->compareTo(arr[i + 1+1])) < 0) then ( Set{(arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k1)))))))) ])}->min() := i; ; k1 := k1 + 1; ) else skip ; if ((arr[i+1]->compareTo(arr[i - 1+1])) > 0 & (arr[i+1]->compareTo(arr[i + 1+1])) > 0) then ( Set{(arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k2)))))))) ])}->max() := i; ; k2 := k2 + 1; ) else skip) ; if ((arr[n - 1+1]->compareTo(arr[n - 2+1])) < 0) then ( Set{(arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k1)))))))) ])}->min() := n - 1; ; k1 := k1 + 1; ) else ( Set{(arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k2)))))))) ])}->max() := n - 1; ; k2 := k2 + 1; ) ; if (Set{(arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])}->min() = 0) then ( var inc_count : int := k2; ; var dec_count : double := k1 - 1; ) else ( inc_count := k2 - 1; ; dec_count := k1; ) ; execute ("Increasing Subsequence Count: ")->display(); ; execute ("Decreasing Subsequence Count: ")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,gcd def smallestDivisor(x): if(x % 2==0): return 2 ; for i in range(3,int(sqrt(x))+1,2): if(x % i==0): return i ; return x def smallestInteger(arr,n): __gcd=0 ; for i in range(n): __gcd=gcd(__gcd,arr[i]); return smallestDivisor(__gcd); if __name__=="__main__" : arr=[2,4,8]; n=len(arr); print(smallestInteger(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{2}->union(Sequence{4}->union(Sequence{ 8 })); ; n := (arr)->size(); ; execute (smallestInteger(arr, n))->display(); ) else skip; operation smallestDivisor(x : OclAny) : OclAny pre: true post: true activity: if (x mod 2 = 0) then ( return 2; ) else skip ; for i : Integer.subrange(3, ("" + ((sqrt(x))))->toInteger() + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if (x mod i = 0) then ( return i; ) else skip) ; return x; operation smallestInteger(arr : OclAny, n : OclAny) pre: true post: true activity: var __gcd : int := 0; ; for i : Integer.subrange(0, n-1) do ( __gcd := gcd(__gcd, arr[i+1]);) ; return smallestDivisor(__gcd);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections N=int(input()) A=[int(x)for x in input().split()] AA=sorted(A) c=collections.Counter(A) third=N//3 ans="No" if all(a==0 for a in A): ans="Yes" elif len(c)==2 and N % 3==0 : if all(a==0 for a in AA[: third]): ans="Yes" elif len(c)==3 and N % 3==0 : if A.count(AA[0])==third and A.count(AA[third])==third and A.count(AA[2*third])==third : if AA[0]^ AA[third]==AA[2*third]and AA[third]^ AA[2*third]==AA[0]and AA[2*third]^ AA[0]==AA[third]: ans="Yes" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var AA : Sequence := A->sort() ; var c : OclAny := .Counter(A) ; var third : int := N div 3 ; var ans : String := "No" ; if ((argument (test (logical_test (comparison (comparison (expr (atom (name a)))) == (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name A))))))))->forAll( _x | _x = true ) then ( ans := "Yes" ) else (if (c)->size() = 2 & N mod 3 = 0 then ( if ((argument (test (logical_test (comparison (comparison (expr (atom (name a)))) == (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name AA)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name third)))))))) ]))))))))->forAll( _x | _x = true ) then ( ans := "Yes" ) else skip ) else (if (c)->size() = 3 & N mod 3 = 0 then ( if A->count(AA->first()) = third & A->count(AA[third+1]) = third & A->count(AA[2 * third+1]) = third then ( if MathLib.bitwiseXor(AA->first(), AA[third+1]) = AA[2 * third+1] & MathLib.bitwiseXor(AA[third+1], AA[2 * third+1]) = AA->first() & MathLib.bitwiseXor(AA[2 * third+1], AA->first()) = AA[third+1] then ( ans := "Yes" ) else skip ) else skip ) else skip ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin inp=stdin.readline n,m,k=map(int,inp().split()) table=[] for i in range(n): table.append(list(map(int,inp().split()))) row_status=[i for i in range(n)] col_status=[i for i in range(m)] ans=[] while k : k-=1 op,x,y=inp().split() x=int(x)-1 y=int(y)-1 if op=="r" : row_status[x],row_status[y]=row_status[y],row_status[x] elif op=="c" : col_status[x],col_status[y]=col_status[y],col_status[x] else : ans.append(str(table[row_status[x]][col_status[y]])) print("\n".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var inp : OclAny := stdin.readline ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (inp().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var table : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((((inp().split())->collect( _x | (OclType["int"])->apply(_x) ))) : table)) ; var row_status : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)) ; var col_status : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (i)) ; var ans : Sequence := Sequence{} ; while k do ( k := k - 1 ; var op : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{op,x,y} := inp().split() ; var x : double := ("" + ((x)))->toInteger() - 1 ; var y : double := ("" + ((y)))->toInteger() - 1 ; if op = "r" then ( var row_status[x+1] : OclAny := null; var row_status[y+1] : OclAny := null; Sequence{row_status[x+1],row_status[y+1]} := Sequence{row_status[y+1],row_status[x+1]} ) else (if op = "c" then ( var col_status[x+1] : OclAny := null; var col_status[y+1] : OclAny := null; Sequence{col_status[x+1],col_status[y+1]} := Sequence{col_status[y+1],col_status[x+1]} ) else ( execute ((("" + ((table[row_status[x+1]+1][col_status[y+1]+1])))) : ans) ) ) ) ; execute (StringLib.sumStringsWithSeparator((ans), "\n"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) t=[input().split()for i in range(n)] c={str(i): i-1 for i in range(m+1)} r={str(i): i-1 for i in range(n+1)} ans=[] for i in range(k): s,x,y=input().split() if s=='c' : c[x],c[y]=c[y],c[x] elif s=='r' : r[x],r[y]=r[y],r[x] else : ans.append(t[r[x]][c[y]]) print('\n'.join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (input().split())) ; var c : Map := Integer.subrange(0, m + 1-1)->select(i | true)->collect(i | Map{("" + ((i))) |-> i - 1})->unionAll() ; var r : Map := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | Map{("" + ((i))) |-> i - 1})->unionAll() ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, k-1) do ( var s : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{s,x,y} := input().split() ; if s = 'c' then ( var c[x+1] : OclAny := null; var c[y+1] : OclAny := null; Sequence{c[x+1],c[y+1]} := Sequence{c[y+1],c[x+1]} ) else (if s = 'r' then ( var r[x+1] : OclAny := null; var r[y+1] : OclAny := null; Sequence{r[x+1],r[y+1]} := Sequence{r[y+1],r[x+1]} ) else ( execute ((t[r[x+1]+1][c[y+1]+1]) : ans) ) ) ) ; execute (StringLib.sumStringsWithSeparator((ans), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout n,m,k=map(int,stdin.readline().split()) t=[stdin.readline().split()for i in range(n)] c={str(i): i-1 for i in range(m+1)} r={str(i): i-1 for i in range(n+1)} ans=[] for i in range(k): s,x,y=input().split() if s=='c' : c[x],c[y]=c[y],c[x] elif s=='r' : r[x],r[y]=r[y],r[x] else : ans.append(t[r[x]][c[y]]) stdout.write('\n'.join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (stdin.readLine().split())) ; var c : Map := Integer.subrange(0, m + 1-1)->select(i | true)->collect(i | Map{("" + ((i))) |-> i - 1})->unionAll() ; var r : Map := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | Map{("" + ((i))) |-> i - 1})->unionAll() ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, k-1) do ( var s : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{s,x,y} := input().split() ; if s = 'c' then ( var c[x+1] : OclAny := null; var c[y+1] : OclAny := null; Sequence{c[x+1],c[y+1]} := Sequence{c[y+1],c[x+1]} ) else (if s = 'r' then ( var r[x+1] : OclAny := null; var r[y+1] : OclAny := null; Sequence{r[x+1],r[y+1]} := Sequence{r[y+1],r[x+1]} ) else ( execute ((t[r[x+1]+1][c[y+1]+1]) : ans) ) ) ) ; stdout.write(StringLib.sumStringsWithSeparator((ans), ' ')); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout n,m,k=map(int,stdin.readline().split()) g=[stdin.readline().split()for i in range(n)] r=[i for i in range(n+1)] c=[i for i in range(m+1)] ans=[] for i in range(k): t,x,y=stdin.readline().split() x,y=int(x),int(y) if t=='c' : c[x],c[y]=c[y],c[x] elif t=='r' : r[x],r[y]=r[y],r[x] else : ans.append(g[r[x]-1][c[y]-1]) stdout.write('\n'.join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var g : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (stdin.readLine().split())) ; var r : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (i)) ; var c : Sequence := Integer.subrange(0, m + 1-1)->select(i | true)->collect(i | (i)) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, k-1) do ( var t : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{t,x,y} := stdin.readLine().split() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{("" + ((x)))->toInteger(),("" + ((y)))->toInteger()} ; if t = 'c' then ( var c[x+1] : OclAny := null; var c[y+1] : OclAny := null; Sequence{c[x+1],c[y+1]} := Sequence{c[y+1],c[x+1]} ) else (if t = 'r' then ( var r[x+1] : OclAny := null; var r[y+1] : OclAny := null; Sequence{r[x+1],r[y+1]} := Sequence{r[y+1],r[x+1]} ) else ( execute ((g[r[x+1] - 1+1][c[y+1] - 1+1]) : ans) ) ) ) ; stdout.write(StringLib.sumStringsWithSeparator((ans), ' ')); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys N=int(input()) alist=list(map(int,input().split())) s1=[] s2=[] s4=[] for a in alist : if a % 2==1 : s1.append(a) elif a % 4==0 : s4.append(a) else : s2.append(a) answer_list=[] last=4 for i in range(N): if last==4 : if s1 : answer_list.append(s1.pop()) last=1 elif s2 : answer_list.append(s2.pop()) last=2 else : answer_list.append(s4.pop()) last=4 elif last==2 : if s2 : answer_list.append(s2.pop()) last=2 elif s4 : answer_list.append(s4.pop()) last=4 else : print("No") sys.exit(0) elif last==1 : if s4 : answer_list.append(s4.pop()) last=4 else : print("No") sys.exit(0) print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var alist : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s1 : Sequence := Sequence{} ; var s2 : Sequence := Sequence{} ; var s4 : Sequence := Sequence{} ; for a : alist do ( if a mod 2 = 1 then ( execute ((a) : s1) ) else (if a mod 4 = 0 then ( execute ((a) : s4) ) else ( execute ((a) : s2) ) ) ) ; var answer_list : Sequence := Sequence{} ; var last : int := 4 ; for i : Integer.subrange(0, N-1) do ( if last = 4 then ( if s1 then ( execute ((s1->last()) : answer_list) ; last := 1 ) else (if s2 then ( execute ((s2->last()) : answer_list) ; last := 2 ) else ( execute ((s4->last()) : answer_list) ; last := 4 ) ) ) else (if last = 2 then ( if s2 then ( execute ((s2->last()) : answer_list) ; last := 2 ) else (if s4 then ( execute ((s4->last()) : answer_list) ; last := 4 ) else ( execute ("No")->display() ; sys.exit(0) ) ) ) else (if last = 1 then ( if s4 then ( execute ((s4->last()) : answer_list) ; last := 4 ) else ( execute ("No")->display() ; sys.exit(0) ) ) else skip ) ) ) ; execute ("Yes")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- X=list(map(int,input().split())) Row,Column={str(i): i-1 for i in range(1,X[0]+1)},{str(i): i-1 for i in range(1,X[1]+1)} Ans=[] Cosmic=[input().split()for i in range(X[0])] for _ in range(X[-1]): Temp=input().split() if Temp[0]=="c" : Column[Temp[1]],Column[Temp[2]]=Column[Temp[2]],Column[Temp[1]] elif Temp[0]=="r" : Row[Temp[1]],Row[Temp[2]]=Row[Temp[2]],Row[Temp[1]] else : Ans.append(Cosmic[Row[Temp[1]]][Column[Temp[2]]]) print('\n'.join(Ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var X : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var Row : OclAny := null; var Column : OclAny := null; Sequence{Row,Column} := Sequence{Integer.subrange(1, X->first() + 1-1)->select(i | true)->collect(i | Map{("" + ((i))) |-> i - 1})->unionAll(),Integer.subrange(1, X[1+1] + 1-1)->select(i | true)->collect(i | Map{("" + ((i))) |-> i - 1})->unionAll()} ; var Ans : Sequence := Sequence{} ; var Cosmic : Sequence := Integer.subrange(0, X->first()-1)->select(i | true)->collect(i | (input().split())) ; for _anon : Integer.subrange(0, X->last()-1) do ( var Temp : OclAny := input().split() ; if Temp->first() = "c" then ( var Column[Temp[1+1]+1] : OclAny := null; var Column[Temp[2+1]+1] : OclAny := null; Sequence{Column[Temp[1+1]+1],Column[Temp[2+1]+1]} := Sequence{Column[Temp[2+1]+1],Column[Temp[1+1]+1]} ) else (if Temp->first() = "r" then ( var Row[Temp[1+1]+1] : OclAny := null; var Row[Temp[2+1]+1] : OclAny := null; Sequence{Row[Temp[1+1]+1],Row[Temp[2+1]+1]} := Sequence{Row[Temp[2+1]+1],Row[Temp[1+1]+1]} ) else ( execute ((Cosmic[Row[Temp[1+1]+1]+1][Column[Temp[2+1]+1]+1]) : Ans) ) ) ) ; execute (StringLib.sumStringsWithSeparator((Ans), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPrime(a,lower,upper): n=0 for i in range(lower-1,upper): n=n+a[i] if(n<=1): return False for i in range(2,n): if(n % i==0): return False return True a=[1,2,3,5,5,4,7,8,9] lower=3 upper=6 if(isPrime(a,lower,upper)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{5}->union(Sequence{4}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 9 })))))))) ; lower := 3 ; upper := 6 ; if (isPrime(a, lower, upper)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isPrime(a : OclAny, lower : OclAny, upper : OclAny) : OclAny pre: true post: true activity: var n : int := 0 ; for i : Integer.subrange(lower - 1, upper-1) do ( n := n + a[i+1]) ; if (n <= 1) then ( return false ) else skip ; for i : Integer.subrange(2, n-1) do ( if (n mod i = 0) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def checkSemiprime(num): cnt=0 for i in range(2,int(math.sqrt(num))+1): while num % i==0 : num/=i cnt+=1 if cnt>=2 : break if(num>1): cnt+=1 return cnt==2 def semiprime(n): if checkSemiprime(n)==True : print("True") else : print("False") n=6 semiprime(n) n=8 semiprime(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 6 ; semiprime(n) ; n := 8 ; semiprime(n);; operation checkSemiprime(num : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; for i : Integer.subrange(2, ("" + (((num)->sqrt())))->toInteger() + 1-1) do ( while num mod i = 0 do ( num := num / i ; cnt := cnt + 1) ; if cnt >= 2 then ( break ) else skip) ; if (num > 1) then ( cnt := cnt + 1 ) else skip ; return cnt = 2; operation semiprime(n : OclAny) pre: true post: true activity: if checkSemiprime(n) = true then ( execute ("True")->display() ) else ( execute ("False")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans=1 def gcd(a,b): if b==0 : return a else : return gcd(b,a % b) def solve(): global ans n=int(input()) for i in range(0,50): for j in range(0,50): for k in range(0,50): a=n-i b=n-j c=n-k if gcd(a,b)==1 and gcd(b,c)==1 and gcd(a,c)==1 : if a*b*c>ans : ans=a*b*c if __name__=='__main__' : solve() print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute ans : OclAny; operation initialise() pre: true post: true activity: var ans : int := 1 ; skip ; skip ; if __name__ = '__main__' then ( solve() ; execute (ans)->display() ) else skip; operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if b = 0 then ( return a ) else ( return gcd(b, a mod b) ); operation solve() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, 50-1) do ( for j : Integer.subrange(0, 50-1) do ( for k : Integer.subrange(0, 50-1) do ( a := n - i ; b := n - j ; var c : double := n - k ; if gcd(a, b) = 1 & gcd(b, c) = 1 & gcd(a, c) = 1 then ( if (a * b * c->compareTo(ans)) > 0 then ( ans := a * b * c ) else skip ) else skip))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import threading,sys def main(): def gcd(a,b): if b==0 : return a else : return gcd(b,a % b) n=int(input()) if n<3 : print(n) exit() if n % 2 : print(n*(n-1)*(n-2)) elif gcd(n,n-3)==1 : print(n*(n-1)*(n-3)) else : print((n-1)*(n-2)*(n-3)) if __name__=='__main__' : sys.setrecursionlimit(1<<30) threading.stack_size(1<<27) main_thread=threading.Thread(target=main) main_thread.start() main_thread.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( sys.setrecursionlimit(1 * (2->pow(30))) ; threading.stack_size(1 * (2->pow(27))) ; var main_thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ; main_thread.start() ; main_thread.join() ) else skip; operation main() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n < 3 then ( execute (n)->display() ; exit() ) else skip ; if n mod 2 then ( execute (n * (n - 1) * (n - 2))->display() ) else (if gcd(n, n - 3) = 1 then ( execute (n * (n - 1) * (n - 3))->display() ) else ( execute ((n - 1) * (n - 2) * (n - 3))->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if atoInteger() ; if n <= 2 then ( execute (n)->display() ) else (if n = 3 then ( execute (6)->display() ) else ( if n mod 2 = 1 then ( execute (n * (n - 1) * (n - 2))->display() ) else ( var ans : double := (n - 3) * (n - 2) * (n - 1) ; var t : OclAny := Set{n - 50, 1}->max() ; for i : Integer.subrange(t, n-1) do ( for j : Integer.subrange(i + 1, n + 1-1) do ( for k : Integer.subrange(j + 1, n + 1-1) do ( var x : int := (i * j) div gcd(i, j) ; x := (x * k) div gcd(x, k) ; ans := Set{ans, x}->max()))) ; execute (ans)->display() ) ) ) ; operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a->compareTo(b)) < 0 then ( Sequence{a,b} := Sequence{b,a} ) else skip ; if b = 0 then ( return a ) else skip ; return gcd(b, a mod b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import deque from collections import Counter readline=sys.stdin.readline N=int(readline()) A=list(map(int,readline().split())) x=A[0] y,z=x,x for a in A : if a!=x : y=a break for a in A : if a!=x and a!=y : z=a break if N % 3==0 : cx,cy,cz=A.count(x),A.count(y),A.count(z) if x!=y and x!=z : if cx+cy+cz==N : if cx==cy and cx==cz and((x ^ z==y)or(x ^ y==z)): print('Yes') else : print('No') else : print('No') elif x!=y : x,y=max(x,y),min(x,y) cx,cy=A.count(x),A.count(y) if cy*2==cx and y==0 : print('Yes') else : print('No') elif x==y : if x==0 : print('Yes') else : print('No') else : if x==y : if x==0 : print('Yes') else : print('No') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var N : int := ("" + ((readline())))->toInteger() ; var A : Sequence := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := A->first() ; var y : OclAny := null; var z : OclAny := null; Sequence{y,z} := Sequence{x,x} ; for a : A do ( if a /= x then ( var y : OclAny := a ; break ) else skip) ; for a : A do ( if a /= x & a /= y then ( var z : OclAny := a ; break ) else skip) ; if N mod 3 = 0 then ( var cx : OclAny := null; var cy : OclAny := null; var cz : OclAny := null; Sequence{cx,cy,cz} := Sequence{A->count(x),A->count(y),A->count(z)} ; if x /= y & x /= z then ( if cx + cy + cz = N then ( if cx = cy & cx = cz & ((MathLib.bitwiseXor(x, z) = y) or (MathLib.bitwiseXor(x, y) = z)) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ) ) else ( execute ('No')->display() ) ) else (if x /= y then ( Sequence{x,y} := Sequence{Set{x, y}->max(),Set{x, y}->min()} ; var cx : OclAny := null; var cy : OclAny := null; Sequence{cx,cy} := Sequence{A->count(x),A->count(y)} ; if cy * 2 = cx & y = 0 then ( execute ('Yes')->display() ) else ( execute ('No')->display() ) ) else (if x = y then ( if x = 0 then ( execute ('Yes')->display() ) else ( execute ('No')->display() ) ) else skip ) ) ) else ( if x = y then ( if x = 0 then ( execute ('Yes')->display() ) else ( execute ('No')->display() ) ) else ( execute ('No')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==1 : print(1) elif n==2 : print(2) elif n==3 : print(1*2*3) elif n==4 : print(12) elif n % 2 : print((n-2)*(n-1)*n) else : if n % 2==0 and n % 3==0 : print((n-1)*(n-2)*(n-3)) else : print(n*(n-1)*(n-3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (1)->display() ) else (if n = 2 then ( execute (2)->display() ) else (if n = 3 then ( execute (1 * 2 * 3)->display() ) else (if n = 4 then ( execute (12)->display() ) else (if n mod 2 then ( execute ((n - 2) * (n - 1) * n)->display() ) else ( if n mod 2 = 0 & n mod 3 = 0 then ( execute ((n - 1) * (n - 2) * (n - 3))->display() ) else ( execute (n * (n - 1) * (n - 3))->display() ) ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) if x>2 : if x % 2==1 : print(x*(x-1)*(x-2)) elif x % 3==0 : print((x-1)*(x-2)*(x-3)) else : print((x)*(x-1)*(x-3)) elif x==2 : print(2) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if x > 2 then ( if x mod 2 = 1 then ( execute (x * (x - 1) * (x - 2))->display() ) else (if x mod 3 = 0 then ( execute ((x - 1) * (x - 2) * (x - 3))->display() ) else ( execute ((x) * (x - 1) * (x - 3))->display() ) ) ) else (if x = 2 then ( execute (2)->display() ) else ( execute (1)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def gcd(a,b): while b!=0 : a,b=b,a % b return a input=sys.stdin.readlines() tc=int(input[0]) for cs in range(tc): ls=input[cs+1].split(' ') n=int(ls[0]) t=[int(x)for x in ls[1 :]] t.sort() g=t[1]-t[0] for i in range(2,len(t)): g=gcd(g,t[i]-t[i-1]) print("Case #%s: %s" %(str(cs+1),str((-t[0])% g))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readlines() ; var tc : int := ("" + (((OclFile["System.in"]).readLine->first())))->toInteger() ; for cs : Integer.subrange(0, tc-1) do ( var ls : OclAny := input[cs + 1+1].split(' ') ; var n : int := ("" + ((ls->first())))->toInteger() ; var t : Sequence := ls->tail()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; t := t->sort() ; var g : double := t[1+1] - t->first() ; for i : Integer.subrange(2, (t)->size()-1) do ( g := gcd(g, t[i+1] - t[i - 1+1])) ; execute (StringLib.format("Case #%s: %s",Sequence{("" + ((cs + 1))), ("" + (((-t->first()) mod g)))}))->display()); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: while b /= 0 do ( Sequence{a,b} := Sequence{b,a mod b}) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal def s(): return input() def i(): return int(input()) def S(): return input().split() def I(): return map(int,input().split()) def L(): return list(map(int,input().split())) def l(): return list(map(int,input().split())) def lcm(a,b): return a*b//math.gcd(a,b) sys.setrecursionlimit(10**9) INF=10**9 mod=10**9+7 N=i() a=l() num1=0 num2=0 num3=0 for i in range(N): if a[i]% 4==0 : num3+=1 elif a[i]% 2==0 : num2+=1 else : num1+=1 if num3+1pow(9)) ; var INF : double := (10)->pow(9) ; var mod : double := (10)->pow(9) + 7 ; var N : OclAny := i() ; a := l() ; var num1 : int := 0 ; var num2 : int := 0 ; var num3 : int := 0 ; for i : Integer.subrange(0, N-1) do ( if a[i+1] mod 4 = 0 then ( num3 := num3 + 1 ) else (if a[i+1] mod 2 = 0 then ( num2 := num2 + 1 ) else ( num1 := num1 + 1 ) ) ) ; if (num3 + 1->compareTo(num1)) < 0 then ( execute ('No')->display() ) else (if num3 + 1 = num1 & num2 /= 0 then ( execute ('No')->display() ) else ( execute ('Yes')->display() ) ) ; operation s() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation i() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation S() : OclAny pre: true post: true activity: return input().split(); operation I() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation L() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation l() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a * b div (a)->gcd(b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAXN=1005 def GCD(a,b): while(b>0): c=a % b a=b b=c return a fi=open('warning.in','r') T=int(fi.readline()) for iT in range(T): s=fi.readline() s2=s.split() N=int(s2[0]) data=[] for i in range(N): data.append(int(s2[i+1])) a=[] ac=0 for i in range(N): j=i+1 ; while(j0): S=T-S res='Case #'+str(iT+1)+': '+str(S) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAXN : int := 1005 ; skip ; var fi : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('warning.in')) ; var T : int := ("" + ((fi.readLine())))->toInteger() ; for iT : Integer.subrange(0, T-1) do ( var s : String := fi.readLine() ; var s2 : OclAny := s.split() ; var N : int := ("" + ((s2->first())))->toInteger() ; var data : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute ((("" + ((s2[i + 1+1])))->toInteger()) : data)) ; a := Sequence{} ; var ac : int := 0 ; for i : Integer.subrange(0, N-1) do ( var j : OclAny := i + 1; ; while ((j->compareTo(N)) < 0) do ( execute (((data[i+1] - data[j+1])->abs()) : a) ; ac := ac + 1 ; j := j + 1)) ; for i : Integer.subrange(0, ac - 1-1) do ( a[i + 1+1] := GCD(a[i+1], a[i + 1+1])) ; T := a[ac - 1+1] ; var S : int := data->first() mod T ; if (S > 0) then ( S := T - S ) else skip ; var res : String := 'Case #' + ("" + ((iT + 1))) + ': ' + ("" + ((S))) ; execute (res)->display()); operation GCD(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: while (b > 0) do ( var c : int := a mod b ; a := b ; b := c) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=map(int,input().split()) print(max(a*b,c*d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{a * b, c * d}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys INF=float('inf') MOD=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return input() a,b,c,d=LI() print(max(a*b,c*d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var INF : double := ("" + (('inf')))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := LI() ; execute (Set{a * b, c * d}->max())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation SI() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=map(int,input().split()) square1=a*b square2=c*d ans=0 if square1collect( _x | (OclType["int"])->apply(_x) ) ; var square1 : double := a * b ; var square2 : double := c * d ; var ans : int := 0 ; if (square1->compareTo(square2)) < 0 then ( ans := square2 ) else ( ans := square1 ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): a,b,c,d=map(int,input().split()) print(max(a*b,c*d)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{a * b, c * d}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=(int(i)for i in input().split()) print(max(a*b,c*d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; execute (Set{a * b, c * d}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lst=list(map(int,input().rstrip().split())) n=lst[0] m=lst[1] if m<=n : fp=n//2 if fp//m!=0 : sp=(fp % m) if sp!=0 : sp=m-(fp % m) if(fp+sp)*2collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := lst->first() ; var m : OclAny := lst[1+1] ; if (m->compareTo(n)) <= 0 then ( var fp : int := n div 2 ; if fp div m /= 0 then ( var sp : int := (fp mod m) ; if sp /= 0 then ( sp := m - (fp mod m) ) else skip ; if ((fp + sp) * 2->compareTo(n)) < 0 then ( sp := sp + m ) else skip ) else ( sp := m - fp ) ; execute (fp + sp)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) a.sort() data=[] lst=[a[0]] num=1 for i in range(1,n): if a[i]==a[i-1]: num+=1 else : data.append(num) lst.append(a[i]) num=1 data.append(num) if len(data)==3 and data[0]==data[1]==data[2]: if lst[0]^ lst[1]==lst[2]: print("Yes") else : print("No") else : if len(data)==1 and lst[0]==0 : print("Yes") elif len(data)==2 and data[0]*2==data[1]: print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var data : Sequence := Sequence{} ; var lst : Sequence := Sequence{ a->first() } ; var num : int := 1 ; for i : Integer.subrange(1, n-1) do ( if a[i+1] = a[i - 1+1] then ( num := num + 1 ) else ( execute ((num) : data) ; execute ((a[i+1]) : lst) ; num := 1 )) ; execute ((num) : data) ; if (data)->size() = 3 & data->first() = data[1+1] & (data[1+1] == data[2+1]) then ( if MathLib.bitwiseXor(lst->first(), lst[1+1]) = lst[2+1] then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else ( if (data)->size() = 1 & lst->first() = 0 then ( execute ("Yes")->display() ) else (if (data)->size() = 2 & data->first() * 2 = data[1+1] then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=input().split() n=int(n) m=int(m) if n>=m : a=n/2 if a % m==0 : print(int(a)) else : b=a+(m-(a % m)) print(int(b)) else : print("-1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var m : int := ("" + ((m)))->toInteger() ; if (n->compareTo(m)) >= 0 then ( var a : double := n / 2 ; if a mod m = 0 then ( execute (("" + ((a)))->toInteger())->display() ) else ( var b : OclAny := a + (m - (a mod m)) ; execute (("" + ((b)))->toInteger())->display() ) ) else ( execute ("-1")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=n-n//2 print([a+(-a)% m,-1][ncollect( _x | (OclType["int"])->apply(_x) ) ; var a : double := n - n div 2 ; execute (Sequence{a + (-a) mod m}->union(Sequence{ -1 })->select((n->compareTo(m)) < 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(N,aa): n_m2=0 n_m4=0 n_m2_notm4=0 for a in aa : is_m2=a % 2==0 is_m4=a % 4==0 n_m2+=int(is_m2) n_m4+=int(is_m4) n_m2_notm4+=int(is_m2 and not is_m4) if n_m2==N : return "Yes" elif n_m2_notm4==0 and n_m4>=N//2 : return "Yes" else : rest=N-n_m2_notm4+1 if n_m4>=rest//2 : return "Yes" else : return "No" if __name__=='__main__' : N=int(input()) aa=map(int,input().split()) print(main(N,aa)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; aa := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (main(N, aa))->display() ) else skip; operation main(N : OclAny, aa : OclAny) : OclAny pre: true post: true activity: var n_m2 : int := 0 ; var n_m4 : int := 0 ; var n_m2_notm4 : int := 0 ; for a : aa do ( var is_m2 : boolean := a mod 2 = 0 ; var is_m4 : boolean := a mod 4 = 0 ; n_m2 := n_m2 + ("" + ((is_m2)))->toInteger() ; n_m4 := n_m4 + ("" + ((is_m4)))->toInteger() ; n_m2_notm4 := n_m2_notm4 + ("" + ((is_m2 & not(is_m4))))->toInteger()) ; if n_m2 = N then ( return "Yes" ) else (if n_m2_notm4 = 0 & (n_m4->compareTo(N div 2)) >= 0 then ( return "Yes" ) else ( var rest : double := N - n_m2_notm4 + 1 ; if (n_m4->compareTo(rest div 2)) >= 0 then ( return "Yes" ) else ( return "No" ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) if ncollect( _x | (OclType["int"])->apply(_x) ) ; if (n->compareTo(m)) < 0 then ( execute (-1)->display() ) else (if n = m then ( execute (m)->display() ) else ( if n mod 2 = 0 then ( if (n / 2) mod m = 0 then ( execute (("" + ((n / 2)))->toInteger())->display() ) else ( var num : int := ("" + ((n / 2)))->toInteger() + 1 ; while num mod m /= 0 do ( num := num + 1) ; execute (num)->display() ) ) else ( num := ("" + ((n / 2)))->toInteger() + 1 ; while num mod m /= 0 do ( num := num + 1) ; execute (num)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(input,m): if m>input : return-1 a,b=0,0 if input % 2==0 : b=0 a=input//2 else : b=1 a=input//2 for i in range(a,-1,-1): s=i*2+b if(i+b)% m==0 and s==input : return i+b b+=2 inputt,m=map(int,input().split()) print(check(inputt,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var inputt : OclAny := null; Sequence{inputt,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (check(inputt, m))->display(); operation check(input : OclAny, m : OclAny) : OclAny pre: true post: true activity: if (m->compareTo(input)) > 0 then ( return -1 ) else skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{0,0} ; if input mod 2 = 0 then ( var b : int := 0 ; var a : int := input div 2 ) else ( b := 1 ; a := input div 2 ) ; for i : Integer.subrange(-1 + 1, a)->reverse() do ( var s : double := i * 2 + b ; if (i + b) mod m = 0 & s = input then ( return i + b ) else skip ; b := b + 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def remainder(st): ln=len(st) rem=0 for i in range(0,ln): num=rem*10+(int)(st[i]) rem=num % 11 return rem st="3435346456547566345436457867978" print(remainder(st)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; st := "3435346456547566345436457867978" ; execute (remainder(st))->display(); operation remainder(st : OclAny) : OclAny pre: true post: true activity: var ln : int := (st)->size() ; var rem : int := 0 ; for i : Integer.subrange(0, ln-1) do ( var num : int := rem * 10 + (OclType["int"])(st[i+1]) ; rem := num mod 11) ; return rem; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) A=[int(i)for i in input().split()] A.sort() ans=0.0 for i in range(1,n): cd=int(A[i])-int(A[i-1]) if i==n-1 : ab=int(A[n-3])+int(A[n-4]) elif i==n-2 : ab=int(A[n-1])+int(A[n-4]) else : ab=int(A[n-1])+int(A[n-2]) ans=max(ans,ab/cd) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; A := A->sort() ; var ans : double := 0.0 ; for i : Integer.subrange(1, n-1) do ( var cd : double := ("" + ((A[i+1])))->toInteger() - ("" + ((A[i - 1+1])))->toInteger() ; if i = n - 1 then ( var ab : int := ("" + ((A[n - 3+1])))->toInteger() + ("" + ((A[n - 4+1])))->toInteger() ) else (if i = n - 2 then ( ab := ("" + ((A[n - 1+1])))->toInteger() + ("" + ((A[n - 4+1])))->toInteger() ) else ( ab := ("" + ((A[n - 1+1])))->toInteger() + ("" + ((A[n - 2+1])))->toInteger() ) ) ; ans := Set{ans, ab / cd}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=sorted(map(int,input().split())) b=[(a[i+1]-a[i],i)for i in range(n-1)] b.sort(key=lambda x : x[0]) if b[0][1]toInteger() ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var b : Sequence := Integer.subrange(0, n - 1-1)->select(i | true)->collect(i | (Sequence{a[i + 1+1] - a[i+1], i})) ; b := b->sort() ; if (b->first()[1+1]->compareTo(n - 2)) < 0 then ( execute ((a->last() + a->front()->last()) / b->first()->first())->display() ) else (if b->first()[1+1] = n - 3 then ( if b[1+1][1+1] = n - 2 then ( execute (Set{(a->last() + a->front()->last()) / b[2+1]->first(), (a->last() + a->reverse()->at(-(-4))) / b->first()->first(), (a->reverse()->at(-(-3)) + a->reverse()->at(-(-4))) / b[1+1]->first()}->max())->display() ) else ( execute (Set{(a->last() + a->front()->last()) / b[1+1]->first(), (a->last() + a->reverse()->at(-(-4))) / b->first()->first()}->max())->display() ) ) else ( if b[1+1][1+1] = n - 3 then ( execute (Set{(a->last() + a->front()->last()) / b[2+1]->first(), (a->last() + a->reverse()->at(-(-4))) / b[1+1]->first(), (a->reverse()->at(-(-3)) + a->reverse()->at(-(-4))) / b->first()->first()}->max())->display() ) else ( execute (Set{(a->last() + a->front()->last()) / b[1+1]->first(), (a->reverse()->at(-(-3)) + a->reverse()->at(-(-4))) / b->first()->first()}->max())->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy n=int(input()) data=list(map(int,input().split())) data.sort() data1=copy.copy(data) A=data1.pop() B=data1.pop() n_1=n-2 min=100000000 for i in range(n_1-1): if data1[i+1]-data1[i]toInteger() ; var data : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; data := data->sort() ; var data1 : OclAny := copy->copy() ; var A : OclAny := data1->last() ; data1 := data1->front() ; var B : OclAny := data1->last() ; data1 := data1->front() ; var n skip : double := n - 2 ; var min : int := 100000000 ; for i : Integer.subrange(0, nn(n(n skip - 1) - 1) - 1 - 1-1) do ( if (data1[i + 1+1] - data1[i+1]->compareTo(min)) < 0 then ( min := data1[i + 1+1] - data1[i+1] ; var C : OclAny := data1[i + 1+1] ; var D : OclAny := data1[i+1] ) else skip) ; var ans skip : double := (A + B) / (C - D) ; var data2 : OclAny := copy->copy() ; min := 100000000 ; for i : Integer.subrange(0, n - 1-1) do ( if (data2[i + 1+1] - data2[i+1]->compareTo(min)) < 0 then ( min := data2[i + 1+1] - data2[i+1] ; C := data2[i + 1+1] ; D := data2[i+1] ) else skip) ; execute ((C) /: data2) ; execute ((D) /: data2) ; A := data2->last() ; data2 := data2->front() ; B := data2->last() ; data2 := data2->front() ; var ans:= (A + B) / (C - D) : double := (A + B) / (C - D) ; execute (Set{ans(ans(ansSet{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ansSet{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ansSet{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ansSet{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ansSet{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ansSet{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ansSet{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ans skip, ans_2), ans_2), ans_2}->max()), ans_2), ans_2), ans_2}->max()), ans_2), ans_2), ans_2}->max(), ans_2), ans_2), ans_2}->max())->display(), ans_2), ans_2), ans_2}->max()), ans_2), ans_2), ans_2}->max()), ans_2), ans_2), ans_2}->max(), ans_2), ans_2), ans_2}->max())->display(), ans_2), ans_2), ans_2}->max()), ans_2), ans_2), ans_2}->max()), ans_2), ans_2), ans_2}->max(), ans_2), ans_2), ans_2}->max())->display(), ans_2), ans_2), ans_2}->max()), ans_2), ans_2), ans_2}->max()), ans_2), ans_2), ans_2}->max(), ans_2), ans_2), ans_2}->max())->display(), ans_2), ans_2), ans_2}->max()), ans_2), ans_2), ans_2}->max()), ans_2), ans_2), ans_2}->max(), ans_2), ans_2), ans_2}->max())->display(), ans_2), ans_2), ans_2}->max()), ans_2), ans_2), ans_2}->max()), ans_2), ans_2), ans_2}->max(), ans_2), ans_2), ans_2}->max())->display(), ans_2), ans_2), ans_2}->max()), ans_2), ans_2), ans_2}->max()), ans_2), ans_2), ans_2}->max(), ans_2), ans_2), ans_2}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) *A,=map(int,input().split()) A.sort(reverse=1) ans=0 for i in range(n): for j in range(i+1,n): p=q=0 while p in[i,j]: p+=1 while q in[i,j,p]: q+=1 ans=max(ans,(A[p]+A[q])/(A[i]-A[j])) print("%.6f" % ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (testlist_star_expr (star_expr * (expr (atom (name A)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name A)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; A := A->sort() ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( var p : OclAny := 0; var q : int := 0 ; while (Sequence{i}->union(Sequence{ j }))->includes(p) do ( p := p + 1) ; while (Sequence{i}->union(Sequence{j}->union(Sequence{ p })))->includes(q) do ( q := q + 1) ; ans := Set{ans, (A[p+1] + A[q+1]) / (A[i+1] - A[j+1])}->max())) ; execute (StringLib.format("%.6f",ans))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) a=[int(i)for i in input().split()] a.sort() a.reverse() ans=(a[2]+a[3])/(a[0]-a[1]) ans=max(ans,(a[1]+a[3])/(a[0]-a[2])) for j in range(3,N): ans=max(ans,(a[1]+a[2])/(a[0]-a[j])) ans=max(ans,(a[0]+a[3])/(a[1]-a[2])) for j in range(3,N): ans=max(ans,(a[0]+a[2])/(a[1]-a[j])) for i in range(2,N): for j in range(i+1,N): ans=max(ans,(a[0]+a[1])/(a[i]-a[j])) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; a := a->sort() ; a := a->reverse() ; var ans : double := (a[2+1] + a[3+1]) / (a->first() - a[1+1]) ; ans := Set{ans, (a[1+1] + a[3+1]) / (a->first() - a[2+1])}->max() ; for j : Integer.subrange(3, N-1) do ( ans := Set{ans, (a[1+1] + a[2+1]) / (a->first() - a[j+1])}->max()) ; ans := Set{ans, (a->first() + a[3+1]) / (a[1+1] - a[2+1])}->max() ; for j : Integer.subrange(3, N-1) do ( ans := Set{ans, (a->first() + a[2+1]) / (a[1+1] - a[j+1])}->max()) ; for i : Integer.subrange(2, N-1) do ( for j : Integer.subrange(i + 1, N-1) do ( ans := Set{ans, (a->first() + a[1+1]) / (a[i+1] - a[j+1])}->max())) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) for i in range(x+1): if(i**2+i)//2>=x : print(i) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, x + 1-1) do ( if (((i)->pow(2) + i) div 2->compareTo(x)) >= 0 then ( execute (i)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isAnagram(s1,s2): s1=list(s1); s2=list(s2); s1=s1.sort(); s2=s2.sort(); if(s1==s2): return 1 ; return 0 ; def CountSteps(s1,s2,size): s1=list(s1); s2=list(s2); i=0 ; j=0 ; result=0 ; while(isize(); ; if (isAnagram(s1, s2)) then ( execute (CountSteps(s1, s2, size))->display(); ) else ( execute (-1)->display(); ) ) else skip; operation isAnagram(s1 : OclAny, s2 : OclAny) pre: true post: true activity: s1 := (s1); ; s2 := (s2); ; s1 := s1->sort(); ; s2 := s2->sort(); ; if (s1 = s2) then ( return 1; ) else skip ; return 0;; operation CountSteps(s1 : OclAny, s2 : OclAny, size : OclAny) pre: true post: true activity: s1 := (s1); ; s2 := (s2); ; var i : int := 0; ; var j : int := 0; ; var result : int := 0; ; while ((i->compareTo(size)) < 0) do ( j := i; ; while (s1[j+1] /= s2[i+1]) do ( j := j + 1;) ; while ((i->compareTo(j)) < 0) do ( var temp : OclAny := s1[j+1]; ; s1[j+1] := s1[j - 1+1]; ; s1[j - 1+1] := temp; ; j := j - 1; ; result := result + 1;) ; i := i + 1;) ; return result;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPalindrome(s): for i in range(len(s)): if(s[i]!=s[len(s)-i-1]): return False return true def ans(s): s2=s for i in range(len(s)): s2=s2[len(s2)-1]+s2 s2=s2[0 : len(s2)-1] if(s!=s2 and isPalindrome(s2)): return True return False def solve(s): if(len(s)<=3): return-1 cnt=[0 for i in range(26)] for i in range(len(s)): cnt[ord(s[i])-ord('a')]+=1 max=cnt[0] for i in range(len(cnt)): if cnt[i]>max : max=cnt[i] if(max>=len(s)-1): return-1 else : if ans(s)==True : return 1 else : return 2 if __name__=='__main__' : s="nolon" print(solve(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( s := "nolon" ; execute (solve(s))->display() ) else skip; operation isPalindrome(s : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, (s)->size()-1) do ( if (s[i+1] /= s[(s)->size() - i - 1+1]) then ( return false ) else skip) ; return true; operation ans(s : OclAny) : OclAny pre: true post: true activity: var s2 : OclAny := s ; for i : Integer.subrange(0, (s)->size()-1) do ( s2 := s2[(s2)->size() - 1+1] + s2 ; s2 := s2.subrange(0+1, (s2)->size() - 1) ; if (s /= s2 & isPalindrome(s2)) then ( return true ) else skip) ; return false; operation solve(s : OclAny) : OclAny pre: true post: true activity: if ((s)->size() <= 3) then ( return -1 ) else skip ; var cnt : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, (s)->size()-1) do ( cnt[(s[i+1])->char2byte() - ('a')->char2byte()+1] := cnt[(s[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; var max : OclAny := cnt->first() ; for i : Integer.subrange(0, (cnt)->size()-1) do ( if (cnt[i+1]->compareTo(max)) > 0 then ( max := cnt[i+1] ) else skip) ; if ((max->compareTo((s)->size() - 1)) >= 0) then ( return -1 ) else ( if ans(s) = true then ( return 1 ) else ( return 2 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPossible(arr,n,C,mid): magnet=1 currPosition=arr[0] for i in range(1,n): if(arr[i]-currPosition>=mid): magnet+=1 currPosition=arr[i] if(magnet==C): return True return False def binarySearch(n,C,arr): arr.sort(reverse=False) lo=0 hi=arr[n-1] ans=0 while(lo<=hi): mid=int((lo+hi)/2) if(isPossible(arr,n,C,mid)==False): hi=mid-1 else : ans=max(ans,mid) lo=mid+1 return ans if __name__=='__main__' : C=4 arr=[1,2,5,8,10,18] n=len(arr) print(binarySearch(n,C,arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( C := 4 ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{5}->union(Sequence{8}->union(Sequence{10}->union(Sequence{ 18 }))))) ; n := (arr)->size() ; execute (binarySearch(n, C, arr))->display() ) else skip; operation isPossible(arr : OclAny, n : OclAny, C : OclAny, mid : OclAny) : OclAny pre: true post: true activity: var magnet : int := 1 ; var currPosition : OclAny := arr->first() ; for i : Integer.subrange(1, n-1) do ( if ((arr[i+1] - currPosition->compareTo(mid)) >= 0) then ( magnet := magnet + 1 ; currPosition := arr[i+1] ; if (magnet = C) then ( return true ) else skip ) else skip) ; return false; operation binarySearch(n : OclAny, C : OclAny, arr : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var lo : int := 0 ; var hi : OclAny := arr[n - 1+1] ; var ans : int := 0 ; while ((lo->compareTo(hi)) <= 0) do ( mid := ("" + (((lo + hi) / 2)))->toInteger() ; if (isPossible(arr, n, C, mid) = false) then ( hi := mid - 1 ) else ( ans := Set{ans, mid}->max() ; lo := mid + 1 )) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findParity(x): y=x ^(x>>1); y=y ^(y>>2); y=y ^(y>>4); y=y ^(y>>8); y=y ^(y>>16); if(y & 1): return 1 ; return 0 ; if(findParity(9)==0): print("Even Parity"); else : print("Odd Parity\n"); if(findParity(13)==0): print("Even Parity"); else : print("Odd Parity"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if (findParity(9) = 0) then ( execute ("Even Parity")->display(); ) else ( execute ("Odd Parity\n")->display(); ) ; if (findParity(13) = 0) then ( execute ("Even Parity")->display(); ) else ( execute ("Odd Parity")->display(); ); operation findParity(x : OclAny) pre: true post: true activity: var y : int := MathLib.bitwiseXor(x, (x /(2->pow(1)))); ; y := MathLib.bitwiseXor(y, (y /(2->pow(2)))); ; y := MathLib.bitwiseXor(y, (y /(2->pow(4)))); ; y := MathLib.bitwiseXor(y, (y /(2->pow(8)))); ; y := MathLib.bitwiseXor(y, (y /(2->pow(16)))); ; if (MathLib.bitwiseAnd(y, 1)) then ( return 1; ) else skip ; return 0;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t1=int(input()) t2=int(input()) if not t1toInteger() ; var t2 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not((t1->compareTo(t2)) < 0) then ( Sequence{t1,t2} := Sequence{t2,t1} ) else skip ; if t2 - t1 <= 180 then ( execute ((t2 + t1) / 2)->display() ) else ( execute (((t2 + t1 + 360) mod 720) / 2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 def LI(): return list(map(int,input().split())) def LF(): return list(map(float,input().split())) def LS(): return input().split() def I(): return int(input()) def F(): return float(input()) def S(): return input() def main(): a=I() b=I() if a>b : a,b=b,a if b-a>a+360-b : a+=360 return(a+b)/2.0 % 360 print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LF() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["double"])->apply(_x) )); operation LS() : OclAny pre: true post: true activity: return input().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation main() : OclAny pre: true post: true activity: var a : OclAny := I() ; var b : OclAny := I() ; if (a->compareTo(b)) > 0 then ( Sequence{a,b} := Sequence{b,a} ) else skip ; if (b - a->compareTo(a + 360 - b)) > 0 then ( a := a + 360 ) else skip ; return (a + b) / 2.0 mod 360; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=int(input()),int(input()) print((a+b+360*(abs(a-b)>180))/2 % 360) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),("" + (((OclFile["System.in"]).readLine())))->toInteger()} ; execute ((a + b + 360 * ((a - b)->abs() > 180)) / 2 mod 360)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=float(input()) b=float(input()) if a>b : a,b=b,a ansa=(a+b)/2 ta=abs(a-ansa) if ansa<0 : ansa+=360.0 ansb=(a+b-360)/2 tb=abs(a-ansb) if ansb<0 : ansb+=360.0 if tatoReal() ; var b : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; if (a->compareTo(b)) > 0 then ( Sequence{a,b} := Sequence{b,a} ) else skip ; var ansa : double := (a + b) / 2 ; var ta : double := (a - ansa)->abs() ; if ansa < 0 then ( ansa := ansa + 360.0 ) else skip ; var ansb : double := (a + b - 360) / 2 ; var tb : double := (a - ansb)->abs() ; if ansb < 0 then ( ansb := ansb + 360.0 ) else skip ; if (ta->compareTo(tb)) < 0 then ( execute (ansa)->display() ) else ( execute (ansb)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t1=int(input()) t2=int(input()) x=(t2-t1)/2 a=x for i in range(-2,3): t=x+i*180 if abs(a)>abs(t): a=t ans=t1+a while ans<0 : ans+=360 while ans>360 : ans-=360 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t2 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : double := (t2 - t1) / 2 ; var a : OclAny := x ; for i : Integer.subrange(-2, 3-1) do ( var t : OclAny := x + i * 180 ; if ((a)->abs()->compareTo((t)->abs())) > 0 then ( a := t ) else skip) ; var ans : int := t1 + a ; while ans < 0 do ( ans := ans + 360) ; while ans > 360 do ( ans := ans - 360) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution : def maxArea(self,height : List[int])->int : left,right=0,len(height)-1 result=0 while leftheight[right]: right-=1 else : left+=1 return result ------------------------------------------------------------ OCL File: --------- class Solution { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation maxArea(height : List[OclType["int"]+1]) : int pre: true post: true activity: var left : OclAny := null; var right : OclAny := null; Sequence{left,right} := Sequence{0,(height)->size() - 1} ; var result : int := 0 ; while (left->compareTo(right)) < 0 do ( result := Set{Set{height[left+1], height[right+1]}->min() * (right - left), result}->max() ; if (height[left+1]->compareTo(height[right+1])) > 0 then ( right := right - 1 ) else ( left := left + 1 )) ; return result; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxProd(arr,n,k): product=1 ; s=dict.fromkeys(arr,0); arr.sort(); for i in range(n): if(s[arr[i]]==0): product=product*arr[i]; s[arr[i]]=s[arr[i]]+1 ; j=n-1 ; while(j>=0 and k>0): if((k>(s[arr[j]]-1))and((s[arr[j]]-1)>0)): product*=pow(arr[j],s[arr[j]]-1); k=k-s[arr[j]]+1 ; s[arr[j]]=0 ; if(k<=(s[arr[j]]-1)and((s[arr[j]]-1)>0)): product*=pow(arr[j],k); break ; j-=1 return product ; if __name__=="__main__" : arr=[5,6,7,8,2,5,6,8]; n=len(arr); k=2 ; print(maxProd(arr,n,k)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{2}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 8 }))))))); ; n := (arr)->size(); ; k := 2; ; execute (maxProd(arr, n, k))->display(); ) else skip; operation maxProd(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var product : int := 1; ; var s : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))); ; arr := arr->sort(); ; for i : Integer.subrange(0, n-1) do ( if (s[arr[i+1]+1] = 0) then ( product := product * arr[i+1]; ) else skip ; s[arr[i+1]+1] := s[arr[i+1]+1] + 1;) ; var j : double := n - 1; ; while (j >= 0 & k > 0) do ( if (((k->compareTo((s[arr[j+1]+1] - 1))) > 0) & ((s[arr[j+1]+1] - 1) > 0)) then ( product := product * (arr[j+1])->pow(s[arr[j+1]+1] - 1); ; k := k - s[arr[j+1]+1] + 1; ; s[arr[j+1]+1] := 0; ) else skip ; if ((k->compareTo((s[arr[j+1]+1] - 1))) <= 0 & ((s[arr[j+1]+1] - 1) > 0)) then ( product := product * (arr[j+1])->pow(k); ; break; ) else skip ; j := j - 1) ; return product;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def examC(): X=I() cur=int(0) i=1 while(X>cur): cur+=i i+=1 print(i-1) import sys import copy from collections import Counter,defaultdict,deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def S(): return sys.stdin.readline().strip() mod=10**9+7 inf=float('inf') examC() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; examC(); operation examC() pre: true post: true activity: var X : OclAny := I() ; var cur : int := ("" + ((0)))->toInteger() ; var i : int := 1 ; while ((X->compareTo(cur)) > 0) do ( cur := cur + i ; i := i + 1) ; execute (i - 1)->display(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation S() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count_numbers(k,n): dp=[[0 for i in range(2)]for i in range(n+1)] dp[1][0]=0 dp[1][1]=k-1 for i in range(2,n+1): dp[i][0]=dp[i-1][1] dp[i][1]=(dp[i-1][0]+dp[i-1][1])*(k-1) return dp[n][0]+dp[n][1] k=10 n=3 print(count_numbers(k,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; k := 10 ; n := 3 ; execute (count_numbers(k, n))->display(); operation count_numbers(k : OclAny, n : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, 2-1)->select(i | true)->collect(i | (0)))) ; dp[1+1]->first() := 0 ; dp[1+1][1+1] := k - 1 ; for i : Integer.subrange(2, n + 1-1) do ( dp[i+1]->first() := dp[i - 1+1][1+1] ; dp[i+1][1+1] := (dp[i - 1+1]->first() + dp[i - 1+1][1+1]) * (k - 1)) ; return dp[n+1]->first() + dp[n+1][1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findLargest(n,v): flag=0 sum=0 for i in range(n): if(v[i]==0): flag=1 sum+=v[i] if(flag==0): print("Not possible") else : v.sort(reverse=True) if(v[0]==0): print("0") return 0 else : flag=0 y=sum % 3 if(y!=0): i=n-1 while(i>=0): if(v[i]% 3==y): v.remove(v[i]) flag=1 break i-=1 if(flag==0): y=3-y cnt=0 i=n-1 while(i>=0): if(v[i]% 3==y): v.remove(v[i]) cnt+=1 if(cnt>=2): break i-=1 if(v[0]==0): print("0") else : for i in(v): print(i,end="") if __name__=='__main__' : n=11 v=[3,9,9,6,4,3,6,4,9,6,0] findLargest(n,v) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 11 ; v := Sequence{3}->union(Sequence{9}->union(Sequence{9}->union(Sequence{6}->union(Sequence{4}->union(Sequence{3}->union(Sequence{6}->union(Sequence{4}->union(Sequence{9}->union(Sequence{6}->union(Sequence{ 0 })))))))))) ; findLargest(n, v) ) else skip; operation findLargest(n : OclAny, v : OclAny) : OclAny pre: true post: true activity: var flag : int := 0 ; var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (v[i+1] = 0) then ( flag := 1 ) else skip ; sum := sum + v[i+1]) ; if (flag = 0) then ( execute ("Not possible")->display() ) else ( v := v->sort() ; if (v->first() = 0) then ( execute ("0")->display() ; return 0 ) else ( flag := 0 ; var y : int := sum mod 3 ; if (y /= 0) then ( var i : double := n - 1 ; while (i >= 0) do ( if (v[i+1] mod 3 = y) then ( execute ((v[i+1]) /: v) ; flag := 1 ; break ) else skip ; i := i - 1) ; if (flag = 0) then ( y := 3 - y ; var cnt : int := 0 ; i := n - 1 ; while (i >= 0) do ( if (v[i+1] mod 3 = y) then ( execute ((v[i+1]) /: v) ; cnt := cnt + 1 ; if (cnt >= 2) then ( break ) else skip ) else skip ; i := i - 1) ) else skip ) else skip ; if (v->first() = 0) then ( execute ("0")->display() ) else ( for i : (v) do ( execute (i)->display()) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countways(n): if(n==1): return 0 ; elif(n % 2==0): return 1+countways(n/2); else : return 1+min(countways(n-1),countways(n+1)); n=15 ; print(countways(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 15; ; execute (countways(n))->display();; operation countways(n : OclAny) pre: true post: true activity: if (n = 1) then ( return 0; ) else (if (n mod 2 = 0) then ( return 1 + countways(n / 2); ) else ( return 1 + Set{countways(n - 1), countways(n + 1)}->min(); ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if name=='__main__' : for first in range(1,6): for second in range(1,6): print(5*first+second-5) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if name = '__main__' then ( for first : Integer.subrange(1, 6-1) do ( for second : Integer.subrange(1, 6-1) do ( execute (5 * first + second - 5)->display())) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,m=map(int,input().split()) height=[] for _ in range(n): lst=list(map(int,input().split())) k=lst[0] ss=lst[1 : : 2] hs=lst[2 : : 2] v_acc=0 h_acc=0 index=0 s,h=ss[0],hs[0] save=[] for i in range(m+1): if icollect( _x | (OclType["int"])->apply(_x) ) ; var height : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k : OclAny := lst->first() ; var ss : OclAny := lst(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ; var hs : OclAny := lst(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ; var v_acc : int := 0 ; var h_acc : int := 0 ; var index : int := 0 ; var s : OclAny := null; var h : OclAny := null; Sequence{s,h} := Sequence{ss->first(),hs->first()} ; var save : Sequence := Sequence{} ; for i : Integer.subrange(0, m + 1-1) do ( if (i->compareTo(v_acc + s * h)) < 0 then ( execute ((h_acc + (i - v_acc) / s) : save) ) else ( v_acc := i ; h_acc := h_acc + h ; index := index + 1 ; execute ((h_acc) : save) ; if index = k then ( break ) else skip ; var s : OclAny := null; var h : OclAny := null; Sequence{s,h} := Sequence{ss[index+1],hs[index+1]} )) ; execute ((save) : height)) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (m + 1)) ; for i : Integer.subrange(0, n-1) do ( var hi : OclAny := height[i+1] ; for j : Integer.subrange(-1 + 1, m)->reverse() do ( dp[j+1] := (Integer.subrange(0, Set{(hi)->size(), j + 1}->min()-1)->select(v | true)->collect(v | (dp[j - v+1] + hi[v+1])))->max())) ; execute (dp->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if a==0 : return b return gcd(int(b)% int(a),a) def g(a,b): return a*b//(gcd(a,b)) n=list(map(int,input().split())) if n[0]% 2==0 and n[0]% 5>0 : n*=2 elif n[0]% 5==0 and n[0]% 2>0 : n*=5 c=10**n[1] print(g(c,n[0])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n->first() mod 2 = 0 & n->first() mod 5 > 0 then ( n := n * 2 ) else (if n->first() mod 5 = 0 & n->first() mod 2 > 0 then ( n := n * 5 ) else skip) ; var c : double := (10)->pow(n[1+1]) ; execute (g(c, n->first()))->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a = 0 then ( return b ) else skip ; return gcd(("" + ((b)))->toInteger() mod ("" + ((a)))->toInteger(), a); operation g(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a * b div (gcd(a, b)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) def gcd(a,b): if a==0 or b==0 : return max(a,b) else : if a>b : a=a % b else : b=b % a return gcd(a,b) print(n*int('1'+('0'*k))//gcd(n,int('1'+('0'*k)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; execute (n * ("" + (('1' + (StringLib.nCopies('0', k)))))->toInteger() div gcd(n, ("" + (('1' + (StringLib.nCopies('0', k)))))->toInteger()))->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a = 0 or b = 0 then ( return Set{a, b}->max() ) else ( if (a->compareTo(b)) > 0 then ( a := a mod b ) else ( b := b mod a ) ; return gcd(a, b) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) def nod(a,b): if a==0 : return b return nod(b % a,a) def nok(a,b): return a*b//nod(a,b) print(nok(a,int("1"+"0"*b))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; skip ; execute (nok(a, ("" + (("1" + StringLib.nCopies("0", b))))->toInteger()))->display(); operation nod(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a = 0 then ( return b ) else skip ; return nod(b mod a, a); operation nok(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a * b div nod(a, b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) def f(a,b): if a==0 : return b return f(b % a,a) def fg(a,b): return a*b//f(a,b) y=1 print(fg(a,int('1'+'0'*b))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; skip ; var y : int := 1 ; execute (fg(a, ("" + (('1' + StringLib.nCopies('0', b))))->toInteger()))->display(); operation f(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a = 0 then ( return b ) else skip ; return f(b mod a, a); operation fg(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a * b div f(a, b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if a==0 : return b return gcd(int(b)% int(a),a) def g(a,b): return a*b//(gcd(a,b)) n=list(map(int,input().split())) if n[0]% 2==0 and n[0]% 5>0 : n*=2 elif n[0]% 5==0 and n[0]% 2>0 : n*=5 c=10**n[1] print(g(c,n[0])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n->first() mod 2 = 0 & n->first() mod 5 > 0 then ( n := n * 2 ) else (if n->first() mod 5 = 0 & n->first() mod 2 > 0 then ( n := n * 5 ) else skip) ; var c : double := (10)->pow(n[1+1]) ; execute (g(c, n->first()))->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a = 0 then ( return b ) else skip ; return gcd(("" + ((b)))->toInteger() mod ("" + ((a)))->toInteger(), a); operation g(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a * b div (gcd(a, b)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,q=map(int,input().split()) a=[int(x)for x in input().split()] a.sort(reverse=True) b=[0] for i in a : b.append(i+b[-1]) for _ in range(q): x,y=map(int,input().split()) print(b[x]-b[x-y]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; a := a->sort() ; var b : Sequence := Sequence{ 0 } ; for i : a do ( execute ((i + b->last()) : b)) ; for _anon : Integer.subrange(0, q-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (b[x+1] - b[x - y+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def leapyear(y): return y % 400==0 or(y % 4==0 and y % 100!=0) a=int(input()) t=int(leapyear(a)) s=int(leapyear(a+1)) d=s+1 y=a+1 while(d % 7!=0 or s!=t): y+=1 s=int(leapyear(y)) d+=s+1 print(y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : int := ("" + ((leapyear(a))))->toInteger() ; var s : int := ("" + ((leapyear(a + 1))))->toInteger() ; var d : int := s + 1 ; y := a + 1 ; while (d mod 7 /= 0 or s /= t) do ( y := y + 1 ; s := ("" + ((leapyear(y))))->toInteger() ; d := d + s + 1) ; execute (y)->display(); operation leapyear(y : OclAny) : OclAny pre: true post: true activity: return y mod 400 = 0 or (y mod 4 = 0 & y mod 100 /= 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minCost(n,arr,cost): Sum,totalCost=0,0 for i in range(0,n-1): Sum+=arr[i] totalCost+=cost*Sum arr[n-1]+=Sum totalCost+=(2*cost*arr[n-1]) return totalCost if __name__=="__main__" : arr=[1,2,4,5] n=len(arr) cost=1 print(minCost(n,arr,cost)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 5 }))) ; n := (arr)->size() ; cost := 1 ; execute (minCost(n, arr, cost))->display() ) else skip; operation minCost(n : OclAny, arr : OclAny, cost : OclAny) : OclAny pre: true post: true activity: var Sum : OclAny := null; var totalCost : OclAny := null; Sequence{Sum,totalCost} := Sequence{0,0} ; for i : Integer.subrange(0, n - 1-1) do ( Sum := Sum + arr[i+1]) ; totalCost := totalCost + cost * Sum ; arr[n - 1+1] := arr[n - 1+1] + Sum ; totalCost := totalCost + (2 * cost * arr[n - 1+1]) ; return totalCost; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def test(n): n=math.ceil((-1+math.sqrt(1+8*n))/2) return n n=int(input()) print(test(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (test(n))->display(); operation test(n : OclAny) : OclAny pre: true post: true activity: n := ((-1 + (1 + 8 * n)->sqrt()) / 2)->ceil() ; return n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,q=map(int,input().split()) n_string=list(map(int,input().split())) n_string.sort(reverse=True) ps=[0] for j in n_string : ps.append(ps[-1]+j) for i in range(q): x,y=map(int,input().split()) s=ps[x]-ps[x-y] print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n_string : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; n_string := n_string->sort() ; var ps : Sequence := Sequence{ 0 } ; for j : n_string do ( execute ((ps->last() + j) : ps)) ; for i : Integer.subrange(0, q-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : double := ps[x+1] - ps[x - y+1] ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) l=list(map(int,input().split())) l.sort() ps=[0] for i in l : ps.append(ps[-1]+i) for i in range(m): a,b=map(int,input().split()) print(ps[n-a+b]-ps[n-a]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := l->sort() ; var ps : Sequence := Sequence{ 0 } ; for i : l do ( execute ((ps->last() + i) : ps)) ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (ps[n - a + b+1] - ps[n - a+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def prefixSum(massive): output=[0] for _ in massive : output.append(output[-1]+_) return output n,q=map(int,input().split()) p=sorted(list(map(int,input().split())),reverse=True) prefSump=prefixSum(p) for i in range(q): x,y=map(int,input().split()) print(prefSump[x]-prefSump[x-y]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var prefSump : OclAny := prefixSum(p) ; for i : Integer.subrange(0, q-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (prefSump[x+1] - prefSump[x - y+1])->display()); operation prefixSum(massive : OclAny) : OclAny pre: true post: true activity: var output : Sequence := Sequence{ 0 } ; for _anon : massive do ( execute ((output->last() + _anon) : output)) ; return output; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pr(m): o=[0] for i in m : o.append(o[-1]+i) return o n,q=map(int,input().split()) p=list(map(int,input().split())) p=sorted(p)[: :-1] pe=pr(p) for i in range(q): x,y=map(int,input().split()) print(pe[x]-pe[x-y]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; p := sorted(p)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var pe : OclAny := pr(p) ; for i : Integer.subrange(0, q-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (pe[x+1] - pe[x - y+1])->display()); operation pr(m : OclAny) : OclAny pre: true post: true activity: var o : Sequence := Sequence{ 0 } ; for i : m do ( execute ((o->last() + i) : o)) ; return o; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binaryRightAngleTriangle(n): for row in range(0,n): for col in range(0,row+1): if(((row+col)% 2)==0): print("0",end="") else : print("1",end="") print("\t",end="") print("") n=4 binaryRightAngleTriangle(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; binaryRightAngleTriangle(n); operation binaryRightAngleTriangle(n : OclAny) pre: true post: true activity: for row : Integer.subrange(0, n-1) do ( for col : Integer.subrange(0, row + 1-1) do ( if (((row + col) mod 2) = 0) then ( execute ("0")->display() ) else ( execute ("1")->display() ) ; execute ("\t")->display()) ; execute ("")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s1=set() while n!=0 : for x in input().split(' '): s1.add(int(x)) n=n-1 for _ in range(1,3002): if not _ in s1 : print(_) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s1 : Set := Set{}->union(()) ; while n /= 0 do ( for x : input().split(' ') do ( execute ((("" + ((x)))->toInteger()) : s1) ; n := n - 1)) ; for _anon : Integer.subrange(1, 3002-1) do ( if not((s1)->includes(_anon)) then ( execute (_anon)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=[False for _ in range(3002)] a=map(int,input().split()) for i in a : arr[i]=True for i in range(1,3002): if arr[i]==False : print(i) exit() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Integer.subrange(0, 3002-1)->select(_anon | true)->collect(_anon | (false)) ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : a do ( arr[i+1] := true) ; for i : Integer.subrange(1, 3002-1) do ( if arr[i+1] = false then ( execute (i)->display() ; exit() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() inp=[int(i)for i in input().split()] for i in range(1,max(inp)+2): if i not in inp : print(i) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var inp : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; for i : Integer.subrange(1, (inp)->max() + 2-1) do ( if (inp)->excludes(i) then ( execute (i)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) arr=list(map(int,input().split())) ans=-1 arr.sort() for i in range(1,arr[-1],1): if i==arr[i-1]: continue else : ans=i break if ans==-1 : print(arr[-1]+1) else : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := -1 ; arr := arr->sort() ; for i : Integer.subrange(1, arr->last()-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if i = arr[i - 1+1] then ( continue ) else ( ans := i ; break )) ; if ans = -1 then ( execute (arr->last() + 1)->display() ) else ( execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def solve(c,a,n): CCA,CCC,CAN=0,0,0 CAN=min(c,a,n) c-=CAN a-=CAN if a>0 and c>0 : CCA=min(a,c//2) c-=(CCA*2) if c>2 : CCC=c//3 return CAN+CCA+CCC def main(args): Q=int(input()) for _ in range(Q): c,a,n=map(int,input().split()) ans=solve(c,a,n) print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(c : OclAny, a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var CCA : OclAny := null; var CCC : OclAny := null; var CAN : OclAny := null; Sequence{CCA,CCC,CAN} := Sequence{0,0,0} ; var CAN : OclAny := Set{c, a, n}->min() ; c := c - CAN ; a := a - CAN ; if a > 0 & c > 0 then ( var CCA : OclAny := Set{a, c div 2}->min() ; c := c - (CCA * 2) ) else skip ; if c > 2 then ( var CCC : int := c div 3 ) else skip ; return CAN + CCA + CCC; operation main(args : OclAny) pre: true post: true activity: var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, Q-1) do ( Sequence{c,a,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : OclAny := solve(c, a, n) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- len1=int(input()) list1=list(map(int,input().rstrip().split())) list1.sort() i=1 j=0 len1=len(list1) while(jtoInteger() ; var list1 : Sequence := ((input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; list1 := list1->sort() ; var i : int := 1 ; var j : int := 0 ; len1 := (list1)->size() ; while ((j->compareTo(len1)) < 0) do ( if (list1[j+1] = i) then ( i := i + 1 ; j := j + 1 ) else ( break )) ; execute (i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def freqPairs(arr,n): max=arr[0] for i in range(len(arr)): if arr[i]>max : max=arr[i] freq=[0 for i in range(max+1)] count=0 for i in range(n): freq[arr[i]]+=1 for i in range(n): for j in range(2*arr[i],max+1,arr[i]): if(freq[j]>=1): count+=freq[j] if(freq[arr[i]]>1): count+=freq[arr[i]]-1 freq[arr[i]]-=1 return count if __name__=='__main__' : arr=[3,2,4,2,6] n=len(arr) print(freqPairs(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{3}->union(Sequence{2}->union(Sequence{4}->union(Sequence{2}->union(Sequence{ 6 })))) ; n := (arr)->size() ; execute (freqPairs(arr, n))->display() ) else skip; operation freqPairs(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var max : OclAny := arr->first() ; for i : Integer.subrange(0, (arr)->size()-1) do ( if (arr[i+1]->compareTo(max)) > 0 then ( max := arr[i+1] ) else skip) ; var freq : Sequence := Integer.subrange(0, max + 1-1)->select(i | true)->collect(i | (0)) ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( freq[arr[i+1]+1] := freq[arr[i+1]+1] + 1) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(2 * arr[i+1], max + 1-1)->select( $x | ($x - 2 * arr[i+1]) mod arr[i+1] = 0 ) do ( if (freq[j+1] >= 1) then ( count := count + freq[j+1] ) else skip) ; if (freq[arr[i+1]+1] > 1) then ( count := count + freq[arr[i+1]+1] - 1 ; freq[arr[i+1]+1] := freq[arr[i+1]+1] - 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,array,re,functools input=lambda : sys.stdin.readline() @ functools.lru_cache(maxsize=10000) def Main(): x=int(input()) lb=-1 ub=123456789 while ub-lb>1 : mid=(ub+lb)//2 s=mid*(mid+1)//2 if s>=x : ub=mid else : lb=mid print(ub) if __name__=='__main__' : Main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; (compound_stmt (decorator @ (dotted_name (dotted_name (name functools)) . (name lru_cache)) ( (arglist (argument (test (logical_test (comparison (expr (atom (name maxsize)))))) = (test (logical_test (comparison (expr (atom (number (integer 10000))))))))) )) (funcdef def (name Main) ( ) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name lb)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ub)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 123456789))))))))))))) (stmt (compound_stmt while (test (logical_test (comparison (comparison (expr (expr (atom (name ub))) - (expr (atom (name lb))))) > (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name mid)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name ub))) + (expr (atom (name lb)))))))) ))) // (expr (atom (number (integer 2)))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (name mid))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name mid))) + (expr (atom (number (integer 1))))))))) )))) // (expr (atom (number (integer 2)))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name s)))) >= (comparison (expr (atom (name x))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ub)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name mid))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name lb)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name mid))))))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ub)))))))) ))))))))))))))) ; if __name__ = '__main__' then ( Main() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=2 M=2 def Matrix(a): ch='1' ; for i in range(N): for j in range(M): if(a[i][j]=='.'): a[i][j]=ch ; if(ch=='1'): ch=='0' else : ch='1' print(a[i][j],end=" "); print() if(i % 2==0): ch='0' ; else : ch='1' ; if __name__=="__main__" : a=[['.','_'],['_','.'],] Matrix(a); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 2 ; var M : int := 2 ; skip ; if __name__ = "__main__" then ( a := Sequence{Sequence{'.'}->union(Sequence{ '_' })}->union(Sequence{ Sequence{'_'}->union(Sequence{ '.' }) }) ; Matrix(a); ) else skip; operation Matrix(a : OclAny) pre: true post: true activity: var ch : String := '1'; ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, M-1) do ( if (a[i+1][j+1] = '.') then ( a[i+1][j+1] := ch; ) else skip ; if (ch = '1') then ( (comparison (comparison (expr (atom (name ch)))) == (comparison (expr (atom '0')))) ) else ( ch := '1' ) ; execute (a[i+1][j+1])->display();) ; execute (->display() ; if (i mod 2 = 0) then ( ch := '0'; ) else ( ch := '1'; )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : a0,L=map(int,input().split()) if a0==0 and L==0 : break s=("{:0"+str(L)+"d}").format(a0) hist=[a0] for i in range(1,21): large="".join(sorted(s,reverse=True)) small="".join(sorted(s)) ai=int(large)-int(small) if ai in hist : j=hist.index(ai) print(j,int(ai),i-j) break else : hist.append(ai) s=("{:0"+str(L)+"d}").format(ai) else : raise AttributeError ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var a0 : OclAny := null; var L : OclAny := null; Sequence{a0,L} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a0 = 0 & L = 0 then ( break ) else skip ; var s : String := StringLib.interpolateStrings(("{:0" + ("" + ((L))) + "d}"), Sequence{a0}) ; var hist : Sequence := Sequence{ a0 } ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 21))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name large)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom "") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s))))))) , (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ))))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name small)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom "") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ai)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name large)))))))) )))) - (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name small)))))))) )))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name ai)))) in (comparison (expr (atom (name hist))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name j)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name hist)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ai)))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j))))))) , (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ai)))))))) )))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (name j))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name hist)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ai)))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom "{:0")) + (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)))))))) ))))) + (expr (atom "d}"))))))) )) (trailer . (name format) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ai)))))))) )))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt raise (test (logical_test (comparison (expr (atom (name AttributeError))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] def f(i,n): t=[c for c in str(i)] if len(t)pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; skip ; while true do ( var l : OclAny := null; Sequence{n,l} := LI() ; if n = 0 & l = 0 then ( break ) else skip ; var d : OclAny := Set{} ; d[n+1] := 0 ; i := 1 ; while true do ( n := f(n, l) ; if (d)->includes(n) then ( execute ((StringLib.interpolateStrings('{}{}{}', Sequence{d[n+1], n, i - d[n+1]})) : rr) ; break ) else skip ; d[n+1] := i ; i := i + 1)) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def is_unique2(seq): seen=[] unique_list=[x for x in seq if x not in seen and not seen.append(x)] return len(seq)==len(unique_list) while True : iCount=0 n=input().split() if int(n[1])==0 : break num=n.pop(0) m=int(n[0]) numStr=list(num) while len(numStr)toInteger() = 0 then ( break ) else skip ; var num : OclAny := n->at(0`firstArg+1) ; n := n->excludingAt(0+1) ; var m : int := ("" + ((n->first())))->toInteger() ; var numStr : Sequence := (num) ; while ((numStr)->size()->compareTo(m)) < 0 do ( numStr := numStr.insertAt(0+1, "0")) ; var numSub : Sequence := Integer.subrange(0, m-1)->select(l | true)->collect(l | (("" + ((numStr[l+1])))->toInteger())) ; var num0 : String := StringLib.sumStringsWithSeparator((numSub->select(k | true)->collect(k | (("" + ((k)))))), "") ; var count : Sequence := Sequence{} ; execute ((num0) : count) ; var answer : String := "False" ; while answer do ( numSub := numSub->sort() ; var Min : String := StringLib.sumStringsWithSeparator((numSub->select(j | true)->collect(j | (("" + ((j)))))), "") ; numSub := numSub->reverse() ; var Max : String := StringLib.sumStringsWithSeparator((numSub->select(i | true)->collect(i | (("" + ((i)))))), "") ; var num1 : double := ("" + ((Max)))->toInteger() - ("" + ((Min)))->toInteger() ; num1 := ("" + ((num1))) ; var xxx : Sequence := (num1) ; while ((xxx)->size()->compareTo(m)) < 0 do ( xxx := xxx.insertAt(0+1, "0")) ; numSub := Integer.subrange(0, m-1)->select(g | true)->collect(g | (("" + ((xxx[g+1])))->toInteger())) ; var xxxx : String := StringLib.sumStringsWithSeparator((xxx->select(h | true)->collect(h | (("" + ((h)))))), "") ; execute ((("" + ((xxxx)))) : count) ; answer := is_unique2(count) ; iCount := iCount + 1) ; execute (count->indexOf(count->last()) - 1)->display() ; execute (("" + ((count->last())))->toInteger())->display() ; execute (("" + ((iCount - count->indexOf(count->last()) - 1))))->display()); operation is_unique2(seq : OclAny) : OclAny pre: true post: true activity: var seen : Sequence := Sequence{} ; var unique_list : Sequence := seq->select(x | (seen)->excludes(x) & not(seen.append(x)))->collect(x | (x)) ; return (seq)->size() = (unique_list)->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools as it def caln(an): maxa=int(an) mina=int(an) con=it.permutations(an) for x in con : temp=int(''.join(x)) if temp>maxa : maxa=temp elif mina>temp : mina=temp return str(maxa-mina) while 1 : a=[] a0,n=list(input().split()) if a0==n=='0' : break if len(a0)size()->compareTo(("" + ((n)))->toInteger())) < 0 then ( var a0 : String := StringLib.sumStringsWithSeparator((Integer.subrange(0, ("" + ((n)))->toInteger() - (a0)->size()-1)->select(_anon | true)->collect(_anon | ('0'))), '') + a0 ) else skip ; execute ((a0) : a) ; var count : int := 0 ; an := a0 ; while 1 do ( count := count + 1 ; an := caln(an) ; if ((an)->size()->compareTo(("" + ((n)))->toInteger())) < 0 then ( an := StringLib.sumStringsWithSeparator((Integer.subrange(0, ("" + ((n)))->toInteger() - (an)->size()-1)->select(_anon | true)->collect(_anon | ('0'))), '') + an ) else skip ; if (a)->includes(an) then ( execute (StringLib.interpolateStrings("{}{}{}", Sequence{a->indexOf(an) - 1, ("" + ((an)))->toInteger(), count - a->indexOf(an) - 1}))->display() ; break ) else skip ; execute ((an) : a))); operation caln(an : OclAny) : OclAny pre: true post: true activity: var maxa : int := ("" + ((an)))->toInteger() ; var mina : int := ("" + ((an)))->toInteger() ; var con : OclAny := it.permutations(an) ; for x : con do ( var temp : int := ("" + ((StringLib.sumStringsWithSeparator((x), ''))))->toInteger() ; if (temp->compareTo(maxa)) > 0 then ( maxa := temp ) else (if (mina->compareTo(temp)) > 0 then ( mina := temp ) else skip)) ; return ("" + ((maxa - mina))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def M(x,L): l=list(str(x)) while(len(l)!=L): l.append("0") res="" l.sort() for i in range(len(l)): res+=l[len(l)-1-i] return int(res) def m(x,L): l=list(str(x)) while(len(l)!=L): l.append("0") res="" l.sort() for i in range(len(l)): res+=l[i] return int(res) def solve(a,L): checked=[-1 for i in range(1000000)] for i in range(30): if(checked[a]!=-1): print(checked[a],a,i-checked[a]) return checked[a]=i a=M(a,L)-m(a,L) while(True): a,L=map(int,input().split()) if(a==0 and L==0): break solve(a,L) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; while (true) do ( Sequence{a,L} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a = 0 & L = 0) then ( break ) else skip ; solve(a, L)); operation M(x : OclAny, L : OclAny) : OclAny pre: true post: true activity: var l : Sequence := (("" + ((x))))->characters() ; while ((l)->size() /= L) do ( execute (("0") : l)) ; var res : String := "" ; l := l->sort() ; for i : Integer.subrange(0, (l)->size()-1) do ( res := res + l[(l)->size() - 1 - i+1]) ; return ("" + ((res)))->toInteger(); operation m(x : OclAny, L : OclAny) : OclAny pre: true post: true activity: l := (("" + ((x))))->characters() ; while ((l)->size() /= L) do ( execute (("0") : l)) ; res := "" ; l := l->sort() ; for i : Integer.subrange(0, (l)->size()-1) do ( res := res + l[i+1]) ; return ("" + ((res)))->toInteger(); operation solve(a : OclAny, L : OclAny) pre: true post: true activity: var checked : Sequence := Integer.subrange(0, 1000000-1)->select(i | true)->collect(i | (-1)) ; for i : Integer.subrange(0, 30-1) do ( if (checked[a+1] /= -1) then ( execute (checked[a+1])->display() ; return ) else skip ; checked[a+1] := i ; a := M(a, L) - m(a, L)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : n,m=map(int,input().split()) except EOFError : break costs=[] vocals=[] dances=[] looks=[] for _ in range(n): input() c,v,d,l=map(int,input().split()) costs.append(c) vocals.append(v) dances.append(d) looks.append(l) def max_param(params): dp=[0]*(m+1) for i in range(n): c=costs[i] p=params[i] for j in range(m-c+1): dp[j+c]=max(dp[j+c],dp[j]+p) return dp[-1] print(max(max_param(vocals),max_param(dances),max_param(looks))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))) ; var costs : Sequence := Sequence{} ; var vocals : Sequence := Sequence{} ; var dances : Sequence := Sequence{} ; var looks : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( input() ; var c : OclAny := null; var v : OclAny := null; var d : OclAny := null; var l : OclAny := null; Sequence{c,v,d,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((c) : costs) ; execute ((v) : vocals) ; execute ((d) : dances) ; execute ((l) : looks)) ; skip ; execute (Set{max_param(vocals), max_param(dances), max_param(looks)}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") N=int(input()) for __ in range(N): c,a,n=[int(_)for _ in input().split()] ans=0 while min(a,c,n)>0 : ans+=1 c-=1 a-=1 n-=1 while c>1 and a>0 : ans+=1 c-=2 a-=1 ans+=c//3 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for __ : Integer.subrange(0, N-1) do ( var c : OclAny := null; var a : OclAny := null; var n : OclAny := null; Sequence{c,a,n} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var ans : int := 0 ; while Set{a, c, n}->min() > 0 do ( ans := ans + 1 ; c := c - 1 ; a := a - 1 ; n := n - 1) ; while c > 1 & a > 0 do ( ans := ans + 1 ; c := c - 2 ; a := a - 1) ; ans := ans + c div 3 ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def swap(a,b,c,d): a=a+b b=a-b a=a-b b=b+c c=b-c b=b-c c=c+d d=c-d c=c-d print("values after swapping are : ") print("a=",a) print("b=",b) print("c=",c) print("d=",d) a=1 b=2 c=3 d=4 print("values after swapping are : ") print("a=",a) print("b=",b) print("c=",c) print("d=",d) print("") swap(a,b,c,d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 1 ; b := 2 ; c := 3 ; d := 4 ; execute ("values after swapping are : ")->display() ; execute ("a=")->display() ; execute ("b=")->display() ; execute ("c=")->display() ; execute ("d=")->display() ; execute ("")->display() ; swap(a, b, c, d); operation swap(a : OclAny, b : OclAny, c : OclAny, d : OclAny) pre: true post: true activity: a := a + b ; b := a - b ; a := a - b ; b := b + c ; c := b - c ; b := b - c ; c := c + d ; d := c - d ; c := c - d ; execute ("values after swapping are : ")->display() ; execute ("a=")->display() ; execute ("b=")->display() ; execute ("c=")->display() ; execute ("d=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def setmiddlebits(n): n |=n>>1 ; n |=n>>2 ; n |=n>>4 ; n |=n>>8 ; n |=n>>16 ; return(n>>1)^ 1 def togglemiddlebits(n): if(n==1): return 1 return n ^ setmiddlebits(n) n=9 print(togglemiddlebits(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 9 ; execute (togglemiddlebits(n))->display(); operation setmiddlebits(n : OclAny) : OclAny pre: true post: true activity: n := n or n /(2->pow(1)); ; n := n or n /(2->pow(2)); ; n := n or n /(2->pow(4)); ; n := n or n /(2->pow(8)); ; n := n or n /(2->pow(16)); ; return MathLib.bitwiseXor((n /(2->pow(1))), 1); operation togglemiddlebits(n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return 1 ) else skip ; return MathLib.bitwiseXor(n, setmiddlebits(n)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t1,t2,r1,r2=map(int,input().split()) if r1!=-1 and r2!=-1 : if r1>r2 : print("Alice") elif r1t2 : print("Bob") else : print("Draw") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t1 : OclAny := null; var t2 : OclAny := null; var r1 : OclAny := null; var r2 : OclAny := null; Sequence{t1,t2,r1,r2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if r1 /= -1 & r2 /= -1 then ( if (r1->compareTo(r2)) > 0 then ( execute ("Alice")->display() ) else (if (r1->compareTo(r2)) < 0 then ( execute ("Bob")->display() ) else ( execute ("Draw")->display() ) ) ) else ( if (t1->compareTo(t2)) < 0 then ( execute ("Alice")->display() ) else (if (t1->compareTo(t2)) > 0 then ( execute ("Bob")->display() ) else ( execute ("Draw")->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) r=(-1+(1+8*x)**0.5)/2 if r.is_integer(): print(int(r)) else : print(int(r)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r : double := (-1 + ((1 + 8 * x))->pow(0.5)) / 2 ; if r.is_integer() then ( execute (("" + ((r)))->toInteger())->display() ) else ( execute (("" + ((r)))->toInteger() + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from heapq import heappush,heappop import sys import math import bisect import random def LI(): return[int(x)for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return[list(x)for x in sys.stdin.readline().split()] def S(): res=list(sys.stdin.readline()) if res[-1]=="\n" : return res[:-1] return res def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] sys.setrecursionlimit(1000000) mod=1000000007 def solve(): T1,T2,R1,R2=LI() if(R1==-1 or R2==-1): if(T1R2): print("Alice") elif(R2>R1): print("Bob") else : print("Draw") return if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1000000) ; var mod : int := 1000000007 ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | ((x))); operation S() : OclAny pre: true post: true activity: var res : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if res->last() = "\n" then ( return res->front() ) else skip ; return res; operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation solve() pre: true post: true activity: var T1 : OclAny := null; var T2 : OclAny := null; var R1 : OclAny := null; var R2 : OclAny := null; Sequence{T1,T2,R1,R2} := LI() ; if (R1 = -1 or R2 = -1) then ( if ((T1->compareTo(T2)) < 0) then ( execute ("Alice")->display() ) else (if ((T2->compareTo(T1)) < 0) then ( execute ("Bob")->display() ) else ( execute ("Draw")->display() ) ) ) else ( if ((R1->compareTo(R2)) > 0) then ( execute ("Alice")->display() ) else (if ((R2->compareTo(R1)) > 0) then ( execute ("Bob")->display() ) else ( execute ("Draw")->display() ) ) ) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=map(int,input().split()) def A_win(): print("Alice") def B_win(): print("Bob") def Draw(): print("Draw") if c==-1 or d==-1 : if ab : B_win() else : Draw() elif c>d : A_win() elif ccollect( _x | (OclType["int"])->apply(_x) ) ; skip ; skip ; skip ; if c = -1 or d = -1 then ( if (a->compareTo(b)) < 0 then ( A_win() ) else (if (a->compareTo(b)) > 0 then ( B_win() ) else ( Draw() ) ) ) else (if (c->compareTo(d)) > 0 then ( A_win() ) else (if (c->compareTo(d)) < 0 then ( B_win() ) else (if c = d then ( Draw() ) else skip ) ) ) ; operation A_win() pre: true post: true activity: execute ("Alice")->display(); operation B_win() pre: true post: true activity: execute ("Bob")->display(); operation Draw() pre: true post: true activity: execute ("Draw")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t1,t2,r1,r2=[int(s)for s in input().split()] if r1==-1 or r2==-1 : if t1t2 : print('Bob') else : print('Draw') else : if r1>r2 : print('Alice') elif r1select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; if r1 = -1 or r2 = -1 then ( if (t1->compareTo(t2)) < 0 then ( execute ('Alice')->display() ) else (if (t1->compareTo(t2)) > 0 then ( execute ('Bob')->display() ) else ( execute ('Draw')->display() ) ) ) else ( if (r1->compareTo(r2)) > 0 then ( execute ('Alice')->display() ) else (if (r1->compareTo(r2)) < 0 then ( execute ('Bob')->display() ) else ( execute ('Draw')->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t1,t2,r1,r2=map(int,input().split()) if r1==-1 or r2==-1 : if t1t2 : print('Bob') else : print('Draw') elif r1>r2 : print('Alice') elif r1collect( _x | (OclType["int"])->apply(_x) ) ; if r1 = -1 or r2 = -1 then ( if (t1->compareTo(t2)) < 0 then ( execute ('Alice')->display() ) else (if (t1->compareTo(t2)) > 0 then ( execute ('Bob')->display() ) else ( execute ('Draw')->display() ) ) ) else (if (r1->compareTo(r2)) > 0 then ( execute ('Alice')->display() ) else (if (r1->compareTo(r2)) < 0 then ( execute ('Bob')->display() ) else ( execute ('Draw')->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def _log(x,base): return(int)(math.log(x)/math.log(base)) def recursiveLogStar(n,b): if(n>1.0): return 1.0+recursiveLogStar(_log(n,b),b) else : return 0 if __name__=='__main__' : n=100 base=5 print("Log*(",n,")=",recursiveLogStar(n,base)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( n := 100 ; base := 5 ; execute ("Log*(")->display() ) else skip; operation _log(x : OclAny, base : OclAny) : OclAny pre: true post: true activity: return (OclType["int"])((x)->log() / (base)->log()); operation recursiveLogStar(n : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (n > 1.0) then ( return 1.0 + recursiveLogStar(_log(n, b), b) ) else ( return 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countInRangeUtil(pos,cnt,tight,num): if pos==len(num): if cnt<=K : return 1 return 0 if dp[pos][cnt][tight]!=-1 : return dp[pos][cnt][tight] ans=0 limit=9 if tight else num[pos] for dig in range(limit+1): currCnt=cnt if dig!=0 : currCnt+=1 currTight=tight if digdisplay() ; L := 9995 ; R := 10005 ; K := 2 ; execute (countInRange(R) - countInRange(L - 1))->display() ) else skip; operation countInRangeUtil(pos : OclAny, cnt : OclAny, tight : OclAny, num : OclAny) : OclAny pre: true post: true activity: if pos = (num)->size() then ( if (cnt->compareTo(K)) <= 0 then ( return 1 ) else skip ; return 0 ) else skip ; if dp[pos+1][cnt+1][tight+1] /= -1 then ( return dp[pos+1][cnt+1][tight+1] ) else skip ; var ans : int := 0 ; var limit : int := if tight then 9 else num[pos+1] endif ; for dig : Integer.subrange(0, limit + 1-1) do ( var currCnt : OclAny := cnt ; if dig /= 0 then ( currCnt := currCnt + 1 ) else skip ; var currTight : OclAny := tight ; if (dig->compareTo(num[pos+1])) < 0 then ( currTight := 1 ) else skip ; ans := ans + countInRangeUtil(pos + 1, currCnt, currTight, num)) ; dp[pos+1][cnt+1][tight+1] := ans ; return dp[pos+1][cnt+1][tight+1]; operation countInRange(x : OclAny) : OclAny pre: true post: true activity: skip; skip; skip ; num := Sequence{} ; while x do ( execute ((x mod 10) : num) ; x := x div 10) ; num := num->reverse() ; dp := Integer.subrange(0, M-1)->select(j | true)->collect(j | (Integer.subrange(0, M-1)->select(i | true)->collect(i | (Sequence{-1}->union(Sequence{ -1 }))))) ; return countInRangeUtil(0, 0, 0, num); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) ans="YES" if abs(a-b)>1 or a+b==0 : ans="NO" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : String := "YES" ; if (a - b)->abs() > 1 or a + b = 0 then ( ans := "NO" ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class newNode : def __init__(self,data): self.data=data self.left=None self.right=None def isBSTUtil(root,prev): if(root): if(not isBSTUtil(root.left,prev)): return False if(root.data<=prev): return False prev=root.data return isBSTUtil(root.right,prev) return True def isBST(root): prev=-(2**32) return isBSTUtil(root,prev) root=newNode(5) root.left=newNode(2) root.right=newNode(15) root.left.left=newNode(1) root.left.right=newNode(4) if(isBST(root)): print("Is BST") else : print("Not a BST") ------------------------------------------------------------ OCL File: --------- class newNode { static operation newnewNode() : newNode pre: true post: newNode->exists( _x | result = _x ); attribute data : OclAny := data; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(data : OclAny) : newNode pre: true post: true activity: self.data := data ; self.left := null ; self.right := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; root := (newNode.newnewNode()).initialise(5) ; root.left := (newNode.newnewNode()).initialise(2) ; root.right := (newNode.newnewNode()).initialise(15) ; root.left.left := (newNode.newnewNode()).initialise(1) ; root.left.right := (newNode.newnewNode()).initialise(4) ; if (isBST(root)) then ( execute ("Is BST")->display() ) else ( execute ("Not a BST")->display() ); operation isBSTUtil(root : OclAny, prev : OclAny) : OclAny pre: true post: true activity: if (root) then ( if (not(isBSTUtil(root.left, prev))) then ( return false ) else skip ; if ((root.data->compareTo(prev)) <= 0) then ( return false ) else skip ; prev := root.data ; return isBSTUtil(root.right, prev) ) else skip ; return true; operation isBST(root : OclAny) : OclAny pre: true post: true activity: prev := -((2)->pow(32)) ; return isBSTUtil(root, prev); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math class Node : def __init__(self,data): self.data=data self.left=None self.right=None def isBSTUtil(root,prev): if(root!=None): if(isBSTUtil(root.left,prev)==True): return False if(prev!=None and root.data<=prev.data): return False prev=root return isBSTUtil(root.right,prev) return True def isBST(root): prev=None return isBSTUtil(root,prev) if __name__=='__main__' : root=Node(3) root.left=Node(2) root.right=Node(5) root.right.left=Node(1) root.right.right=Node(4) if(isBST(root)==None): print("Is BST") else : print("Not a BST") ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.left := null ; self.right := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( root := (Node.newNode()).initialise(3) ; root.left := (Node.newNode()).initialise(2) ; root.right := (Node.newNode()).initialise(5) ; root.right.left := (Node.newNode()).initialise(1) ; root.right.right := (Node.newNode()).initialise(4) ; if (isBST(root) = null) then ( execute ("Is BST")->display() ) else ( execute ("Not a BST")->display() ) ) else skip; operation isBSTUtil(root : OclAny, prev : OclAny) : OclAny pre: true post: true activity: if (root /= null) then ( if (isBSTUtil(root.left, prev) = true) then ( return false ) else skip ; if (prev /= null & (root.data->compareTo(prev.data)) <= 0) then ( return false ) else skip ; prev := root ; return isBSTUtil(root.right, prev) ) else skip ; return true; operation isBST(root : OclAny) : OclAny pre: true post: true activity: prev := null ; return isBSTUtil(root, prev); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def product(a,n): ans=1 val=pow(2,n-1) for i in range(n): ans*=pow(a[i],val) return ans n=2 a=[3,7] print(product(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 2 ; a := Sequence{3}->union(Sequence{ 7 }) ; execute (product(a, n))->display(); operation product(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := 1 ; var val : double := (2)->pow(n - 1) ; for i : Integer.subrange(0, n-1) do ( ans := ans * (a[i+1])->pow(val)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def toBinary(n): if(n>=1 or n<=0): return "ERROR" ; frac=0.5 ; answer="." ; while(n>0): if(len(answer)>=32): return "ERROR" ; if(n>=frac): answer+="1" ; n=n-frac ; else : answer+="0" ; frac=(frac/2); return answer ; n=0.625 ; result=toBinary(n); print("(0",result,")in base 2"); m=0.72 ; result=toBinary(m); print("(",result,")"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 0.625; ; var result : OclAny := toBinary(n); ; execute ("(0")->display(); ; var m : double := 0.72; ; result := toBinary(m); ; execute ("(")->display();; operation toBinary(n : OclAny) pre: true post: true activity: if (n >= 1 or n <= 0) then ( return "ERROR"; ) else skip ; var frac : double := 0.5; ; var answer : String := "."; ; while (n > 0) do ( if ((answer)->size() >= 32) then ( return "ERROR"; ) else skip ; if ((n->compareTo(frac)) >= 0) then ( answer := answer + "1"; ; n := n - frac; ) else ( answer := answer + "0"; ) ; frac := (frac / 2);) ; return answer;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def makeOdd(n): if(n % 2!=0): return 1 ; resul=1 ; while(n % 2==0): n=n/2 ; resul=resul*2 ; return resul ; n=36 ; print(makeOdd(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 36; ; execute (makeOdd(n))->display();; operation makeOdd(n : OclAny) pre: true post: true activity: if (n mod 2 /= 0) then ( return 1; ) else skip ; var resul : int := 1; ; while (n mod 2 = 0) do ( n := n / 2; ; resul := resul * 2;) ; return resul;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def toBinary(n): if(n>=1 or n<=0): return "ERROR" answer="" frac=0.5 answer=answer+"." while(n>0): if(len(answer)>=32): return "ERROR" b=n*2 if(b>=1): answer=answer+"1" n=b-1 else : answer=answer+"0" n=b return answer if __name__=='__main__' : n=0.625 result=toBinary(n) print("(0",result,")in base 2") m=0.72 result=toBinary(m) print("(",result,")") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 0.625 ; var result : OclAny := toBinary(n) ; execute ("(0")->display() ; var m : double := 0.72 ; result := toBinary(m) ; execute ("(")->display() ) else skip; operation toBinary(n : OclAny) : OclAny pre: true post: true activity: if (n >= 1 or n <= 0) then ( return "ERROR" ) else skip ; var answer : String := "" ; var frac : double := 0.5 ; answer := answer + "." ; while (n > 0) do ( if ((answer)->size() >= 32) then ( return "ERROR" ) else skip ; var b : double := n * 2 ; if (b >= 1) then ( answer := answer + "1" ; n := b - 1 ) else ( answer := answer + "0" ; n := b )) ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input()+'#' l,b,c=-1,'',[] for i,x in enumerate(zip(a,a[1 :])): if x[0]!=x[1]: b+=x[0] c+=[i-l] l=i y=len(b) print([c[y//2]+1,0][y % 2==0 or c[y//2]<2 or b!=b[: :-1]or any(c[y//2-i]+c[y//2+i]<3 for i in range(1,y//2+1))]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() + '#' ; var l : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{l,b,c} := Sequence{-1,'',Sequence{}} ; for _tuple : Integer.subrange(1, (Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), a->tail()->at(_indx)} ))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), a->tail()->at(_indx)} ))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); if x->first() /= x[1+1] then ( b := b + x->first() ; c := c + Sequence{ i - l } ; var l : OclAny := i ) else skip) ; var y : int := (b)->size() ; execute (Sequence{c[y div 2+1] + 1}->union(Sequence{ 0 })->select(y mod 2 = 0 or c[y div 2+1] < 2 or b /= b(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) or ((argument (test (logical_test (comparison (comparison (expr (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name y))) // (expr (atom (number (integer 2))))) - (expr (atom (name i))))))))) ]))) + (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name y))) // (expr (atom (number (integer 2))))) + (expr (atom (name i))))))))) ]))))) < (comparison (expr (atom (number (integer 3)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (expr (atom (name y))) // (expr (atom (number (integer 2))))) + (expr (atom (number (integer 1)))))))))) )))))))))->exists( _x | _x = true )))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input()+'#' l,b,c=-1,'',[] for i,x in enumerate(zip(a,a[1 :])): if x[0]!=x[1]: b+=x[0] c+=[i-l] l=i y=len(b) print([c[y//2]+1,0][y % 2==0 or c[y//2]<2 or b!=b[: :-1]or any(c[y//2-i]+c[y//2+i]<3 for i in range(1,y//2+1))]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() + '#' ; var l : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{l,b,c} := Sequence{-1,'',Sequence{}} ; for _tuple : Integer.subrange(1, (Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), a->tail()->at(_indx)} ))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), a->tail()->at(_indx)} ))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); if x->first() /= x[1+1] then ( b := b + x->first() ; c := c + Sequence{ i - l } ; var l : OclAny := i ) else skip) ; var y : int := (b)->size() ; execute (Sequence{c[y div 2+1] + 1}->union(Sequence{ 0 })->select(y mod 2 = 0 or c[y div 2+1] < 2 or b /= b(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) or ((argument (test (logical_test (comparison (comparison (expr (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name y))) // (expr (atom (number (integer 2))))) - (expr (atom (name i))))))))) ]))) + (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name y))) // (expr (atom (number (integer 2))))) + (expr (atom (name i))))))))) ]))))) < (comparison (expr (atom (number (integer 3)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (expr (atom (name y))) // (expr (atom (number (integer 2))))) + (expr (atom (number (integer 1)))))))))) )))))))))->exists( _x | _x = true )))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input()+'#' l,b,c=-1,'',[] for i,x in enumerate(zip(a,a[1 :])): if x[0]!=x[1]: b+=x[0] c+=[i-l] l=i y=len(b) print([c[y//2]+1,0][y % 2==0 or c[y//2]<2 or b!=b[: :-1]or any(c[y//2-i]+c[y//2+i]<3 for i in range(1,y//2+1))]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() + '#' ; var l : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{l,b,c} := Sequence{-1,'',Sequence{}} ; for _tuple : Integer.subrange(1, (Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), a->tail()->at(_indx)} ))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), a->tail()->at(_indx)} ))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); if x->first() /= x[1+1] then ( b := b + x->first() ; c := c + Sequence{ i - l } ; var l : OclAny := i ) else skip) ; var y : int := (b)->size() ; execute (Sequence{c[y div 2+1] + 1}->union(Sequence{ 0 })->select(y mod 2 = 0 or c[y div 2+1] < 2 or b /= b(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) or ((argument (test (logical_test (comparison (comparison (expr (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name y))) // (expr (atom (number (integer 2))))) - (expr (atom (name i))))))))) ]))) + (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name y))) // (expr (atom (number (integer 2))))) + (expr (atom (name i))))))))) ]))))) < (comparison (expr (atom (number (integer 3)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (expr (atom (name y))) // (expr (atom (number (integer 2))))) + (expr (atom (number (integer 1)))))))))) )))))))))->exists( _x | _x = true )))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def idx(row): color_length=[] i=0 while i0 : lenght=p-l if lenght==1 : if r[l][1]>1 : print(r[l][1]+1) return else : print(0) return if lenght==2 : print(0) return if lenght>2 : if r[l][0]!=r[p-1][0]or r[l][1]+r[p-1][1]<3 : print(0) return else : l+=1 p-=1 data=input() balls=idx(data) is_empty(balls,0,len(balls)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var data : String := (OclFile["System.in"]).readLine() ; var balls : OclAny := idx(data) ; is_empty(balls, 0, (balls)->size()); operation idx(row : OclAny) : OclAny pre: true post: true activity: var color_length : Sequence := Sequence{} ; var i : int := 0 ; while (i->compareTo((row)->size())) < 0 do ( var color : OclAny := null; var length : OclAny := null; Sequence{color,length} := Sequence{row[i+1],1} ; while (i->compareTo((row)->size() - 1)) < 0 do ( if row[i + 1+1] = color then ( length := length + 1 ; i := i + 1 ) else ( break )) ; execute ((Sequence{color, length}) : color_length) ; i := i + 1) ; return color_length; operation is_empty(r : OclAny, l : OclAny, p : OclAny) pre: true post: true activity: while p - l > 0 do ( var lenght : double := p - l ; if lenght = 1 then ( if r[l+1][1+1] > 1 then ( execute (r[l+1][1+1] + 1)->display() ; return ) else ( execute (0)->display() ; return ) ) else skip ; if lenght = 2 then ( execute (0)->display() ; return ) else skip ; if lenght > 2 then ( if r[l+1]->first() /= r[p - 1+1]->first() or r[l+1][1+1] + r[p - 1+1][1+1] < 3 then ( execute (0)->display() ; return ) else ( l := l + 1 ; p := p - 1 ) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): res=0 c,a,n=list(map(int,input().split())) res=min(n,a,c) c-=res a-=res if c>=2 and a>=1 : cca=min(c//2,a) c-=cca*2 res+=cca if c>=3 : res+=c//3 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var res : int := 0 ; var c : OclAny := null; var a : OclAny := null; var n : OclAny := null; Sequence{c,a,n} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; res := Set{n, a, c}->min() ; c := c - res ; a := a - res ; if c >= 2 & a >= 1 then ( var cca : OclAny := Set{c div 2, a}->min() ; c := c - cca * 2 ; res := res + cca ) else skip ; if c >= 3 then ( res := res + c div 3 ) else skip ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def idx(row): color_length=[] i=0 while i0 : lenght=p-l if lenght==1 : if r[l][1]>1 : return r[l][1]+1 else : return 0 if lenght==2 : return 0 if lenght>2 : if r[l][0]!=r[p-1][0]or r[l][1]+r[p-1][1]<3 : return 0 else : l+=1 p-=1 data=input() balls=idx(data) print(is_empty(balls,0,len(balls))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var data : String := (OclFile["System.in"]).readLine() ; var balls : OclAny := idx(data) ; execute (is_empty(balls, 0, (balls)->size()))->display(); operation idx(row : OclAny) : OclAny pre: true post: true activity: var color_length : Sequence := Sequence{} ; var i : int := 0 ; while (i->compareTo((row)->size())) < 0 do ( var color : OclAny := null; var length : OclAny := null; Sequence{color,length} := Sequence{row[i+1],1} ; while (i->compareTo((row)->size() - 1)) < 0 do ( if row[i + 1+1] = color then ( length := length + 1 ; i := i + 1 ) else ( break )) ; execute ((Sequence{color, length}) : color_length) ; i := i + 1) ; return color_length; operation is_empty(r : OclAny, l : OclAny, p : OclAny) : OclAny pre: true post: true activity: while p - l > 0 do ( var lenght : double := p - l ; if lenght = 1 then ( if r[l+1][1+1] > 1 then ( return r[l+1][1+1] + 1 ) else ( return 0 ) ) else skip ; if lenght = 2 then ( return 0 ) else skip ; if lenght > 2 then ( if r[l+1]->first() /= r[p - 1+1]->first() or r[l+1][1+1] + r[p - 1+1][1+1] < 3 then ( return 0 ) else ( l := l + 1 ; p := p - 1 ) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(x,y): if y==0 : return x else : return gcd(y,x % y) def main(): l,r=tuple(map(int,input().split(' '))) print(gcd(l,r)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation gcd(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if y = 0 then ( return x ) else ( return gcd(y, x mod y) ); operation main() pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; execute (gcd(l, r))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=map(int,input().split()) b=min((x,y)) a=max((x,y))% b if a==0 : print(b) else : for i in range(1,a+1): if a % i==0 and b %(a/i)==0 : print(int(a/i)) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : OclAny := (Sequence{x, y})->min() ; var a : int := (Sequence{x, y})->max() mod b ; if a = 0 then ( execute (b)->display() ) else ( for i : Integer.subrange(1, a + 1-1) do ( if a mod i = 0 & b mod (a / i) = 0 then ( execute (("" + ((a / i)))->toInteger())->display() ; break ) else skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- li=list(map(int,input().split())) li.sort(reverse=True) while li[0]% li[1]!=0 : temp=li[1] li[1]=li[0]% li[1] li[0]=temp print(li[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var li : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; li := li->sort() ; while li->first() mod li[1+1] /= 0 do ( var temp : OclAny := li[1+1] ; li[1+1] := li->first() mod li[1+1] ; li->first() := temp) ; execute (li[1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a,b=map(int,input().split()) print(math.gcd(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a)->gcd(b))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def Prime(arr,n): max_val=max(arr) prime=[True for i in range(max_val+1)] prime[0]=False prime[1]=False for p in range(2,mt.ceil(mt.sqrt(max_val))): if(prime[p]==True): for i in range(2*p,max_val+1,p): prime[i]=False minimum=10**9 maximum=-10**9 for i in range(n): if(prime[arr[i]]==True): minimum=min(minimum,arr[i]) maximum=max(maximum,arr[i]) print("Minimum : ",minimum) print("Maximum : ",maximum) arr=[1,2,3,4,5,6,7] n=len(arr) Prime(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 7 })))))) ; n := (arr)->size() ; Prime(arr, n); operation Prime(arr : OclAny, n : OclAny) pre: true post: true activity: var max_val : OclAny := (arr)->max() ; var prime : Sequence := Integer.subrange(0, max_val + 1-1)->select(i | true)->collect(i | (true)) ; prime->first() := false ; prime[1+1] := false ; for p : Integer.subrange(2, mt.ceil(mt.sqrt(max_val))-1) do ( if (prime[p+1] = true) then ( for i : Integer.subrange(2 * p, max_val + 1-1)->select( $x | ($x - 2 * p) mod p = 0 ) do ( prime[i+1] := false) ) else skip) ; var minimum : double := (10)->pow(9) ; var maximum : double := (-10)->pow(9) ; for i : Integer.subrange(0, n-1) do ( if (prime[arr[i+1]+1] = true) then ( minimum := Set{minimum, arr[i+1]}->min() ; maximum := Set{maximum, arr[i+1]}->max() ) else skip) ; execute ("Minimum : ")->display() ; execute ("Maximum : ")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(x,y): if x0 : tmp=x % y x=y y=tmp return x def test(): x,y=map(int,input().split()) result=gcd(x,y) print(result) if __name__=='__main__' : test() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( test() ) else skip; operation gcd(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (x->compareTo(y)) < 0 then ( var tmp : OclAny := x ; x := y ; y := tmp ) else skip ; while y > 0 do ( tmp := x mod y ; x := y ; y := tmp) ; return x; operation test() pre: true post: true activity: Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var result : OclAny := gcd(x, y) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w=map(int,input().split()) c=[list(map(int,input().split()))for _ in range(10)] a=[list(map(int,input().split()))for _ in range(h)] INF=10**10 dist=[[c[i][j]for j in range(10)]for i in range(10)] for k in range(10): for i in range(10): for j in range(10): dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]) ans=0 for i in range(h): for j in range(w): if a[i][j]!=-1 : ans+=dist[a[i][j]][1] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : Sequence := Integer.subrange(0, 10-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var a : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var INF : double := (10)->pow(10) ; var dist : Sequence := Integer.subrange(0, 10-1)->select(i | true)->collect(i | (Integer.subrange(0, 10-1)->select(j | true)->collect(j | (c[i+1][j+1])))) ; for k : Integer.subrange(0, 10-1) do ( for i : Integer.subrange(0, 10-1) do ( for j : Integer.subrange(0, 10-1) do ( dist[i+1][j+1] := Set{dist[i+1][j+1], dist[i+1][k+1] + dist[k+1][j+1]}->min()))) ; var ans : int := 0 ; for i : Integer.subrange(0, h-1) do ( for j : Integer.subrange(0, w-1) do ( if a[i+1][j+1] /= -1 then ( ans := ans + dist[a[i+1][j+1]+1][1+1] ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def warshall_floyd(V): for k in range(V): for i in range(V): for j in range(V): d[i][j]=min(d[i][j],d[i][k]+d[k][j]) from collections import Counter INF=float('inf') H,W=map(int,input().split()) d=[[int(i)for i in input().split()]for _ in range(10)] a=[] for _ in range(H): a.extend([int(i)for i in input().split()if i!='-1']) dic=Counter(a) warshall_floyd(10) ans=0 for key,val in dic.items(): ans+=d[key][1]*val print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var INF : double := ("" + (('inf')))->toReal() ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := Integer.subrange(0, 10-1)->select(_anon | true)->collect(_anon | (input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())))) ; var a : Sequence := Sequence{} ; for _anon : Integer.subrange(0, H-1) do ( a := a->union(input().split()->select(i | i /= '-1')->collect(i | (("" + ((i)))->toInteger())))) ; var dic : OclAny := Counter(a) ; warshall_floyd(10) ; var ans : int := 0 ; for _tuple : dic->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var val : OclAny := _tuple->at(_indx); ans := ans + d[key+1][1+1] * val) ; execute (ans)->display(); operation warshall_floyd(V : OclAny) pre: true post: true activity: for k : Integer.subrange(0, V-1) do ( for i : Integer.subrange(0, V-1) do ( for j : Integer.subrange(0, V-1) do ( d[i+1][j+1] := Set{d[i+1][j+1], d[i+1][k+1] + d[k+1][j+1]}->min()))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq def dijkstra_heap(s,C): d=[float("inf")]*10 used=[False]*10 d[s]=0 used[s]=True edgelist=[] for i,w in enumerate(C[s]): heapq.heappush(edgelist,[w,i]) while len(edgelist): minedge=heapq.heappop(edgelist) v=minedge[1] if used[v]: continue d[v]=minedge[0] used[v]=True for i,w in enumerate(C[v]): if not used[i]: heapq.heappush(edgelist,[d[v]+w,i]) return d H,W=map(int,input().split()) C=[[]for _ in range(10)] for i in range(10): c=list(map(int,input().split())) for j in range(10): C[j].append(c[j]) d=dijkstra_heap(1,C) ans=0 for i in range(H): A=list(map(int,input().split())) for a in A : if a>=0 : ans+=d[a] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; C := Integer.subrange(0, 10-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, 10-1) do ( var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, 10-1) do ((expr (atom (name C)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) )))))) ; d := dijkstra_heap(1, C) ; var ans : int := 0 ; for i : Integer.subrange(0, H-1) do ( var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for a : A do ( if a >= 0 then ( ans := ans + d[a+1] ) else skip)) ; execute (ans)->display(); operation dijkstra_heap(s : OclAny, C : OclAny) : OclAny pre: true post: true activity: var d : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (("inf")))->toReal() }, 10) ; var used : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, 10) ; d[s+1] := 0 ; used[s+1] := true ; var edgelist : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (C[s+1])->size())->collect( _indx | Sequence{_indx-1, (C[s+1])->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var w : OclAny := _tuple->at(_indx); heapq.heappush(edgelist, Sequence{w}->union(Sequence{ i }))) ; while (edgelist)->size() do ( var minedge : OclAny := heapq.heappop(edgelist) ; var v : OclAny := minedge[1+1] ; if used[v+1] then ( continue ) else skip ; d[v+1] := minedge->first() ; used[v+1] := true ; for _tuple : Integer.subrange(1, (C[v+1])->size())->collect( _indx | Sequence{_indx-1, (C[v+1])->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var w : OclAny := _tuple->at(_indx); if not(used[i+1]) then ( heapq.heappush(edgelist, Sequence{d[v+1] + w}->union(Sequence{ i })) ) else skip)) ; return d; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- Q=int(input()) for i in range(Q): c,a,n=map(int,input().split()) teams=0 mini=min(c,a,n) teams+=mini c-=mini a-=mini n-=mini mini=min(int(c/2),a) teams+=mini c-=mini*2 a-=mini mini=int(c/3) teams+=mini print(teams) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, Q-1) do ( var c : OclAny := null; var a : OclAny := null; var n : OclAny := null; Sequence{c,a,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var teams : int := 0 ; var mini : OclAny := Set{c, a, n}->min() ; teams := teams + mini ; c := c - mini ; a := a - mini ; n := n - mini ; mini := Set{("" + ((c / 2)))->toInteger(), a}->min() ; teams := teams + mini ; c := c - mini * 2 ; a := a - mini ; mini := ("" + ((c / 3)))->toInteger() ; teams := teams + mini ; execute (teams)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq INF=10**9 def solve(): H,W=map(int,input().split()) graph=[list(map(int,input().split()))for _ in range(10)] search_table=[[i!=1 and i!=j for i in range(10)]for j in range(10)] min_distance_n_to_1=[INF]*10 min_distance_n_to_1[1]=0 queue=[(min_distance_n_to_1[v],v)for v in range(10)] heapq.heapify(queue) while queue : _,dom=heapq.heappop(queue) for i in range(10): if min_distance_n_to_1[i]>min_distance_n_to_1[dom]+graph[i][dom]: min_distance_n_to_1[i]=min_distance_n_to_1[dom]+graph[i][dom] heapq.heappush(queue,(min_distance_n_to_1[i],i)) ret=sum(sum(min_distance_n_to_1[int(Aij)]if int(Aij)!=-1 else 0 for Aij in input().split())for _ in range(H)) print(ret) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var INF : double := (10)->pow(9) ; skip ; solve(); operation solve() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var graph : Sequence := Integer.subrange(0, 10-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var search_table : Sequence := Integer.subrange(0, 10-1)->select(j | true)->collect(j | (Integer.subrange(0, 10-1)->select(i | true)->collect(i | (i /= 1 & i /= j)))) ; var min_distance_n_to var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, 10) ; min_distance_n_to var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )[1+1] := 0 ; var queue : Sequence := Integer.subrange(0, 10-1)->select(v | true)->collect(v | (Sequence{min_distance_n_to(testlist_comp (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name min_distance_n_to var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])))))) , (test (logical_test (comparison (expr (atom (name v))))))) )))))) (comp_for for (exprlist (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 10))))))))) ))))))))[v+1], v})) ; heapq.heapify(queue) ; while queue do ( var _anon : OclAny := null; var dom : OclAny := null; Sequence{_anon,dom} := heapq.heappop(queue) ; for i : Integer.subrange(0, 10-1) do ( if (min_distance_n_to var _anon : OclAny := null; var dom : OclAny := null; Sequence{_anon,dom} := heapq.heappop(queue)[i+1]->compareTo(min_distance_n_to var _anon : OclAny := null; var dom : OclAny := null; Sequence{_anon,dom} := heapq.heappop(queue)[dom+1] + graph[i+1][dom+1])) > 0 then ( min_distance_n_to var _anon : OclAny := null; var dom : OclAny := null; Sequence{_anon,dom} := heapq.heappop(queue)[i+1] := min_distance_n_to var _anon : OclAny := null; var dom : OclAny := null; Sequence{_anon,dom} := heapq.heappop(queue)[dom+1] + graph[i+1][dom+1] ; heapq.heappush(queue, Sequence{min_distance_n_toqueue[i+1], i}) ) else skip)) ; var ret : OclAny := ((argument (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name min_distance_n_to var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name Aij)))))))) ))))))))) ]))))) if (logical_test (comparison (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name Aij)))))))) ))))) != (comparison (expr (atom - (number (integer 1))))))) else (test (logical_test (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name Aij)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name H)))))))) )))))))))->sum() ; execute (ret)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline H,W=map(int,readline().split()) C=[None]*10 for i in range(10): C[i]=list(map(int,readline().split())) for k in range(10): for i in range(10): for j in range(10): C[i][j]=min(C[i][j],C[i][k]+C[k][j]) from collections import defaultdict wall=defaultdict(int) for i in range(H): for w in list(map(int,readline().split())): wall[w]+=1 ans=0 for key,value in wall.items(): if key==-1 : continue ans+=value*C[key][1] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var C : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, 10) ; for i : Integer.subrange(0, 10-1) do ( C[i+1] := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; for k : Integer.subrange(0, 10-1) do ( for i : Integer.subrange(0, 10-1) do ( for j : Integer.subrange(0, 10-1) do ( C[i+1][j+1] := Set{C[i+1][j+1], C[i+1][k+1] + C[k+1][j+1]}->min()))) ; skip ; var wall : OclAny := defaultdict(OclType["int"]) ; for i : Integer.subrange(0, H-1) do ( for w : ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) do ( wall[w+1] := wall[w+1] + 1)) ; var ans : int := 0 ; for _tuple : wall->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); if key = -1 then ( continue ) else skip ; ans := ans + value * C[key+1][1+1]) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) S=0 s_list=[] input_list=list(map(int,input().split())) allS=sum(input_list) for n in input_list[:-1]: S+=n s_list.append(abs(allS-2*S)) print(min(s_list)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : int := 0 ; var s_list : Sequence := Sequence{} ; var input_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var allS : OclAny := (input_list)->sum() ; for n : input_list->front() do ( S := S + n ; execute (((allS - 2 * S)->abs()) : s_list)) ; execute ((s_list)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from numpy import*; n,*a=map(int,open(0).read().split()); print(min(abs(cumsum(a[: :-1])[: :-1]-cumsum([0]+a[:-1]))[1 :])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ); execute ((abs(cumsum(a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) - cumsum(Sequence{ 0 }->union(a->front())))->tail())->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def read_int_list(): return list(map(int,input().split())) def read_int(): return int(input()) def read_str_list(): return input().split() def read_str(): return input() def solve(): n=read_int() a=read_int_list() res=2*10**10 x=0 y=sum(a) for i in range(n-1): x+=a[i] y-=a[i] d=abs(x-y) if res>d : res=d return res def main(): res=solve() print(res) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation read_int_list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation read_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation read_str_list() : OclAny pre: true post: true activity: return input().split(); operation read_str() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation solve() : OclAny pre: true post: true activity: var n : OclAny := read_int() ; var a : OclAny := read_int_list() ; var res : double := 2 * (10)->pow(10) ; var x : int := 0 ; var y : OclAny := (a)->sum() ; for i : Integer.subrange(0, n - 1-1) do ( x := x + a[i+1] ; y := y - a[i+1] ; var d : double := (x - y)->abs() ; if (res->compareTo(d)) > 0 then ( res := d ) else skip) ; return res; operation main() pre: true post: true activity: res := solve() ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def inpl(): return[int(i)for i in input().split()] import numpy as np ans=float('inf') N=int(input()) a=np.cumsum(np.array(inpl())) suma=a[-1] a=np.delete(a,-1) for i in a : ans=min(ans,abs(suma-2*i)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var ans : double := ("" + (('inf')))->toReal() ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : (trailer . (name cumsum) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name np)) (trailer . (name array) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name inpl)) (trailer (arguments ( ))))))))) ))))))))) ))) := ; var suma : OclAny := a->last() ; a := ; for i : a do ( ans := Set{ans, (suma - 2 * i)->abs()}->min()) ; execute (ans)->display(); operation inpl() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) w=list(map(int,input().split())) c=max(w) for i in range(n): s=w[i] for j in range(i+1,n): s ^=w[j] if s>c : c=s print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : OclAny := (w)->max() ; for i : Integer.subrange(0, n-1) do ( var s : OclAny := w[i+1] ; for j : Integer.subrange(i + 1, n-1) do ( s := s xor w[j+1] ; if (s->compareTo(c)) > 0 then ( c := s ) else skip)) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(input()) a=[] b=input().split(" ") for i in range(n): a.append(int(b[i])) for i in range(1,n): a[i]+=a[i-1] mn=abs(a[n-1]-2*a[0]) for i in range(1,n-1): mn=min(mn,abs(a[n-1]-2*a[i])) print(mn) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; var b : OclAny := input().split(" ") ; for i : Integer.subrange(0, n-1) do ( execute ((("" + ((b[i+1])))->toInteger()) : a)) ; for i : Integer.subrange(1, n-1) do ( a[i+1] := a[i+1] + a[i - 1+1]) ; var mn : double := (a[n - 1+1] - 2 * a->first())->abs() ; for i : Integer.subrange(1, n - 1-1) do ( mn := Set{mn, (a[n - 1+1] - 2 * a[i+1])->abs()}->min()) ; execute (mn)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSum(N,L,R): if(L>R): return 0 ; if(N==1): return R-L+1 ; if(N>1): return(N-2)*(R-L)+1 ; return 0 ; if __name__=='__main__' : N,L,R=4,4,6 ; print(countSum(N,L,R)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( Sequence{N,L,R} := Sequence{4,4,6}; ; execute (countSum(N, L, R))->display(); ) else skip; operation countSum(N : OclAny, L : OclAny, R : OclAny) pre: true post: true activity: if ((L->compareTo(R)) > 0) then ( return 0; ) else skip ; if (N = 1) then ( return R - L + 1; ) else skip ; if (N > 1) then ( return (N - 2) * (R - L) + 1; ) else skip ; return 0;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxCircularSum(arr,n,k): if(nans): ans=sum ; start=(i-k+1)% n ; end=i % n ; print("max circular sum=",ans); print("start index=",start,"\nend index=",end); if __name__=="__main__" : arr=[18,4,3,4,5,6,7,8,2,10]; n=len(arr); k=3 ; maxCircularSum(arr,n,k); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{18}->union(Sequence{4}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{2}->union(Sequence{ 10 }))))))))); ; n := (arr)->size(); ; k := 3; ; maxCircularSum(arr, n, k); ) else skip; operation maxCircularSum(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if ((n->compareTo(k)) < 0) then ( execute ("Invalid")->display(); ; return; ) else skip ; var sum : int := 0; var start : int := 0; var end : double := k - 1; ; for i : Integer.subrange(0, k-1) do ( sum := sum + arr[i+1];) ; var ans : int := sum; ; for i : Integer.subrange(k, n + k-1) do ( sum := sum + arr[i mod n+1] - arr[(i - k) mod n+1]; ; if ((sum->compareTo(ans)) > 0) then ( ans := sum; ; start := (i - k + 1) mod n; ; end := i mod n; ) else skip) ; execute ("max circular sum=")->display(); ; execute ("start index=")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): c,a,n=map(int,input().split()) cnt=0 while True : if c<1 or a<1 or n<1 : break c-=1 a-=1 n-=1 cnt+=1 while True : if c<2 or a<1 : break c-=2 a-=1 cnt+=1 while True : if c<3 : break c-=3 cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var c : OclAny := null; var a : OclAny := null; var n : OclAny := null; Sequence{c,a,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cnt : int := 0 ; while true do ( if c < 1 or a < 1 or n < 1 then ( break ) else skip ; c := c - 1 ; a := a - 1 ; n := n - 1 ; cnt := cnt + 1) ; while true do ( if c < 2 or a < 1 then ( break ) else skip ; c := c - 2 ; a := a - 1 ; cnt := cnt + 1) ; while true do ( if c < 3 then ( break ) else skip ; c := c - 3 ; cnt := cnt + 1) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(s): for i in range(0,len(s)): if(s[i]==s[i+1]): return True return False s="xzyyz" if(check(s)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := "xzyyz" ; if (check(s)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); operation check(s : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, (s)->size()-1) do ( if (s[i+1] = s[i + 1+1]) then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt MAX=10000 prefix=[0 for i in range(MAX+1)] def buildPrefix(): prime=[True for i in range(MAX+1)] for p in range(2,int(sqrt(MAX))+1,1): if(prime[p]==True): for i in range(p*2,MAX+1,p): prime[i]=False prefix[0]=0 prefix[1]=0 for p in range(2,MAX+1,1): prefix[p]=prefix[p-1] if(prime[p]): prefix[p]+=p def sumPrimeRange(L,R): buildPrefix() return prefix[R]-prefix[L-1] if __name__=='__main__' : L=10 R=20 print(sumPrimeRange(L,R)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MAX : int := 10000 ; var prefix : Sequence := Integer.subrange(0, MAX + 1-1)->select(i | true)->collect(i | (0)) ; skip ; skip ; if __name__ = '__main__' then ( L := 10 ; R := 20 ; execute (sumPrimeRange(L, R))->display() ) else skip; operation buildPrefix() pre: true post: true activity: var prime : Sequence := Integer.subrange(0, MAX + 1-1)->select(i | true)->collect(i | (true)) ; for p : Integer.subrange(2, ("" + ((sqrt(MAX))))->toInteger() + 1-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (prime[p+1] = true) then ( for i : Integer.subrange(p * 2, MAX + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip) ; prefix->first() := 0 ; prefix[1+1] := 0 ; for p : Integer.subrange(2, MAX + 1-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( prefix[p+1] := prefix[p - 1+1] ; if (prime[p+1]) then ( prefix[p+1] := prefix[p+1] + p ) else skip); operation sumPrimeRange(L : OclAny, R : OclAny) : OclAny pre: true post: true activity: buildPrefix() ; return prefix[R+1] - prefix[L - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumofproduct(n): ans=0 for x in range(1,n+1): y=int(n/x) ans+=(y*x) return ans n=10 print(sumofproduct(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 10 ; execute (sumofproduct(n))->display(); operation sumofproduct(n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for x : Integer.subrange(1, n + 1-1) do ( var y : int := ("" + ((n / x)))->toInteger() ; ans := ans + (y * x)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def firstDigit(n): fact=1 for i in range(2,n+1): fact=fact*i while(fact % 10==0): fact=int(fact/10) while(fact>=10): fact=int(fact/10) return math.floor(fact) n=5 print(firstDigit(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 5 ; execute (firstDigit(n))->display(); operation firstDigit(n : OclAny) : OclAny pre: true post: true activity: var fact : int := 1 ; for i : Integer.subrange(2, n + 1-1) do ( fact := fact * i ; while (fact mod 10 = 0) do ( fact := ("" + ((fact / 10)))->toInteger())) ; while (fact >= 10) do ( fact := ("" + ((fact / 10)))->toInteger()) ; return (fact)->floor(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) a=list(map(int,input().split())) a.sort(reverse=True) ans=a[n//2] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var ans : OclAny := a[n div 2+1] ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ls=input().split() ls=[int(num)for num in ls] ls.sort() if n % 2==0 : print(ls[n//2-1]) else : print(ls[(n+1)//2-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ls : OclAny := input().split() ; ls := ls->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; ls := ls->sort() ; if n mod 2 = 0 then ( execute (ls[n div 2 - 1+1])->display() ) else ( execute (ls[(n + 1) div 2 - 1+1])->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) while True : if len(l)==1 : break del l[l.index(max(l))] if len(l)==1 : break del l[l.index(min(l))] print(*l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; while true do ( if (l)->size() = 1 then ( break ) else skip ; execute (l[l->indexOf((l)->max()) - 1+1])->isDeleted() ; if (l)->size() = 1 then ( break ) else skip ; execute (l[l->indexOf((l)->min()) - 1+1])->isDeleted()) ; execute ((argument * (test (logical_test (comparison (expr (atom (name l))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[int(i)for i in input().split()] y=0 for i in range(n): t=0 for j in range(i,n): t ^=l[j] y=max(y,t) print(y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var y : int := 0 ; for i : Integer.subrange(0, n-1) do ( var t : int := 0 ; for j : Integer.subrange(i, n-1) do ( t := t xor l[j+1] ; y := Set{y, t}->max())) ; execute (y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a=int(input()),sorted(int(i)for i in input().split()) res=a[(len(a)-1)//2] print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),(argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))->sort()} ; var res : OclAny := a[((a)->size() - 1) div 2+1] ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) a.sort(reverse=True) print(a[n//2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; execute (a[n div 2+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break m=int(input()) s=input() ar=[0]*m ans=0 if m>=3 : for i in range(2,m): if s[i-2 : i+1]=="IOI" : ar[i]=ar[i-2]+1 if ar[i]>=n : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var ar : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; var ans : int := 0 ; if m >= 3 then ( for i : Integer.subrange(2, m-1) do ( if s.subrange(i - 2+1, i + 1) = "IOI" then ( ar[i+1] := ar[i - 2+1] + 1 ; if (ar[i+1]->compareTo(n)) >= 0 then ( ans := ans + 1 ) else skip ) else skip) ) else skip ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if not n : break puyos=[] pre=int(input()) cnt=1 for _ in range(n-1): p=int(input()) if pre!=p : puyos.append((pre,cnt)) pre=p cnt=0 cnt+=1 puyos.append((pre,cnt)) lp=len(puyos) min_puyo=n for i,puyo in enumerate(puyos): color,num=puyo if num==2 : continue tn,j=n,1 while True : if i-j<0 or i+j>=lp : break tp_c,tp_n=puyos[i-j] up_c,up_n=puyos[i+j] if tp_c!=up_c : break first_adjust=0 if j==1 : if num==1 : first_adjust=1 else : first_adjust=-1 tn-=4 dp=tp_n+up_n+first_adjust if dp<4 : break tn-=dp j+=1 if min_puyo>tn : min_puyo=tn print(min_puyo) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(n) then ( break ) else skip ; var puyos : Sequence := Sequence{} ; var pre : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cnt : int := 1 ; for _anon : Integer.subrange(0, n - 1-1) do ( var p : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if pre /= p then ( execute ((Sequence{pre, cnt}) : puyos) ; pre := p ; cnt := 0 ) else skip ; cnt := cnt + 1) ; execute ((Sequence{pre, cnt}) : puyos) ; var lp : int := (puyos)->size() ; var min_puyo : int := n ; for _tuple : Integer.subrange(1, (puyos)->size())->collect( _indx | Sequence{_indx-1, (puyos)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var puyo : OclAny := _tuple->at(_indx); var color : OclAny := null; var num : OclAny := null; Sequence{color,num} := puyo ; if num = 2 then ( continue ) else skip ; var tn : OclAny := null; var j : OclAny := null; Sequence{tn,j} := Sequence{n,1} ; while true do ( if i - j < 0 or (i + j->compareTo(lp)) >= 0 then ( break ) else skip ; var tp_c : OclAny := null; var tp_n : OclAny := null; Sequence{tp_c,tp_n} := puyos[i - j+1] ; var up_c : OclAny := null; var up_n : OclAny := null; Sequence{up_c,up_n} := puyos[i + j+1] ; if tp_c /= up_c then ( break ) else skip ; var first_adjust : int := 0 ; if j = 1 then ( if num = 1 then ( first_adjust := 1 ) else ( first_adjust := -1 ; tn := tn - 4 ) ) else skip ; var dp : OclAny := tp_n + up_n + first_adjust ; if dp < 4 then ( break ) else skip ; tn := tn - dp ; j := j + 1) ; if (min_puyo->compareTo(tn)) > 0 then ( min_puyo := tn ) else skip) ; execute (min_puyo)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=100000 while True : n=int(input()) if not n : break lst=[int(input())for _ in range(n)] def check(x): c1=c2=lst[x] l=r=x b=0 for i in range(r,n): if lst[i]!=c2 : r=i-1 break else : r=n-1 for i in range(l,-1,-1): if lst[i]!=c1 : l=i+1 break else : l=0 if r-l-b<3 : return n else : b=r-l while l>0 and rtoInteger() ; if not(n) then ( break ) else skip ; var lst : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; skip ; var ans : int := INF ; for i : Integer.subrange(0, n-1) do ( lst[i+1] := (lst[i+1] + 1) mod 3 + 1 ; ans := Set{ans, check(i)}->min() ; lst[i+1] := (lst[i+1] + 1) mod 3 + 1 ; ans := Set{ans, check(i)}->min() ; lst[i+1] := (lst[i+1] + 1) mod 3 + 1) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): INF=100000 while True : n=int(input()) if not n : break lst=[int(input())for _ in range(n)] def check(x): c=lst[x] l=r=x b=0 for i in range(r,n): if lst[i]!=c : r=i-1 break else : r=n-1 for i in range(l,-1,-1): if lst[i]!=c : l=i+1 break else : l=0 if r-l-b<3 : return n else : b=r-l while l>0 and rtoInteger() ; if not(n) then ( break ) else skip ; var lst : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; skip ; var ans : int := INF ; for i : Integer.subrange(0, n-1) do ( lst[i+1] := (lst[i+1]) mod 3 + 1 ; ans := Set{ans, check(i)}->min() ; lst[i+1] := (lst[i+1]) mod 3 + 1 ; ans := Set{ans, check(i)}->min() ; lst[i+1] := (lst[i+1]) mod 3 + 1) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def doChain(ar,si,ei): p,c=0,[] for i in range(si,ei): if ar[i]==p : c.append(i) if i==len(ar)-1 and len(c)>=4 : del ar[min(c): max(c)+1] return True,max(0,si-3),min(ei+5,len(ar)) else : if len(c)>=4 : del ar[min(c): max(c)+1] return True,max(0,si-3),min(ei+5,len(ar)) p=ar[i] c=[i] return False,0,len(ar) while True : N=int(input()) if N==0 : break A=[int(input())for _ in range(N)] minvalue=N for j in range(len(A)-1): B=A[:] if B[j+1]!=B[j]: B[j+1]=B[j] result=True si,ei=max(0,j-3),min(j+5,len(A)) while result==True : result,si,ei=doChain(B,si,ei) if len(B)toInteger() ; if N = 0 then ( break ) else skip ; var A : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var minvalue : int := N ; for j : Integer.subrange(0, (A)->size() - 1-1) do ( var B : Sequence := A ; if B[j + 1+1] /= B[j+1] then ( B[j + 1+1] := B[j+1] ; var result : boolean := true ; Sequence{si,ei} := Sequence{Set{0, j - 3}->max(),Set{j + 5, (A)->size()}->min()} ; while result = true do ( Sequence{result,si,ei} := doChain(B, si, ei) ; if ((B)->size()->compareTo(minvalue)) < 0 then ( minvalue := (B)->size() ) else skip) ) else skip) ; execute (minvalue)->display()); operation doChain(ar : OclAny, si : OclAny, ei : OclAny) : OclAny pre: true post: true activity: var p : OclAny := null; var c : OclAny := null; Sequence{p,c} := Sequence{0,Sequence{}} ; for i : Integer.subrange(si, ei-1) do ( if ar[i+1] = p then ( execute ((i) : c) ; if i = (ar)->size() - 1 & (c)->size() >= 4 then ( execute (ar.subrange((c)->min()+1, (c)->max() + 1))->isDeleted() ; return true, Set{0, si - 3}->max(), Set{ei + 5, (ar)->size()}->min() ) else skip ) else ( if (c)->size() >= 4 then ( execute (ar.subrange((c)->min()+1, (c)->max() + 1))->isDeleted() ; return true, Set{0, si - 3}->max(), Set{ei + 5, (ar)->size()}->min() ) else skip ; var p : OclAny := ar[i+1] ; var c : Sequence := Sequence{ i } )) ; return false, 0, (ar)->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def erase(array,i,N): if array[i-1]==array[i]: up=i-1 down=i elif array[i]==array[i+1]: up=i down=i+1 else : return N-2 while True : if array[up]==-1 or array[down]==-1 or not array[up]==array[down]: return up+N-down-1 save_up=up save_down=down c=array[up] while array[up]==c : up-=1 while array[down]==c : down+=1 if save_up-up+down-save_down<4 : return save_up+N-save_down-1 def main(): while True : N=int(input()) if N==0 : return a=[-1] for i in range(N): a.append(int(input())) a.append(-1) min_erased=N for i in range(1,N+1): save=a[i] a[i]=save % 3+1 min_erased=min(min_erased,erase(a,i,N+2)) a[i]=(save+1)% 3+1 min_erased=min(min_erased,erase(a,i,N+2)) a[i]=save print(min_erased) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation erase(array : OclAny, i : OclAny, N : OclAny) : OclAny pre: true post: true activity: if array[i - 1+1] = array[i+1] then ( var up : double := i - 1 ; var down : OclAny := i ) else (if array[i+1] = array[i + 1+1] then ( up := i ; down := i + 1 ) else ( return N - 2 ) ) ; while true do ( if array[up+1] = -1 or array[down+1] = -1 or not(array[up+1] = array[down+1]) then ( return up + N - down - 1 ) else skip ; var save_up : OclAny := up ; var save_down : OclAny := down ; var c : OclAny := array[up+1] ; while array[up+1] = c do ( up := up - 1) ; while array[down+1] = c do ( down := down + 1) ; if save_up - up + down - save_down < 4 then ( return save_up + N - save_down - 1 ) else skip); operation main() pre: true post: true activity: while true do ( N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( return ) else skip ; var a : Sequence := Sequence{ -1 } ; for i : Integer.subrange(0, N-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : a)) ; execute ((-1) : a) ; var min_erased : OclAny := N ; for i : Integer.subrange(1, N + 1-1) do ( var save : OclAny := a[i+1] ; a[i+1] := save mod 3 + 1 ; min_erased := Set{min_erased, erase(a, i, N + 2)}->min() ; a[i+1] := (save + 1) mod 3 + 1 ; min_erased := Set{min_erased, erase(a, i, N + 2)}->min() ; a[i+1] := save) ; execute (min_erased)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printmaxSubseq(arr,n): for i in range(n-1): if(arr[i]union(Sequence{8}->union(Sequence{11}->union(Sequence{13}->union(Sequence{10}->union(Sequence{15}->union(Sequence{14}->union(Sequence{16}->union(Sequence{20}->union(Sequence{ 5 }))))))))); ; n := (arr)->size(); ; printmaxSubseq(arr, n); ) else skip; operation printmaxSubseq(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n - 1-1) do ( if ((arr[i+1]->compareTo(arr[i + 1+1])) < 0) then ( execute (arr[i+1])->display(); ) else ( execute (arr[i+1])->display(); )) ; execute (arr[n - 1+1])->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict d=defaultdict(lambda : "no such property") check,*yaml=list(open(0)) before=[] beforei=[] ka=defaultdict(lambda :-1) bv=-1 for y in yaml : y=y.split(":") vacant=y[0].count("") if bv>=vacant : for num,b in enumerate(beforei): if b==vacant : break before=before[: num] beforei=beforei[: num] bv=vacant before.append(y[0].strip("")) beforei.append(bv) x=y[1][1 :-1] d[tuple(before)]="object" if x=="" else "string \""+x+" \ "" ans=tuple(check.strip("\n").split(".")[1 :]) print(d[ans]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var d : OclAny := defaultdict(lambda $$ : OclAny in ("no such property")) ; var check : OclAny := null; var yaml : OclAny := null; Sequence{check,yaml} := (OclFile.newOclFile_Write(OclFile.newOclFile(0))) ; var before : Sequence := Sequence{} ; var beforei : Sequence := Sequence{} ; var ka : OclAny := defaultdict(lambda $$ : OclAny in (-1)) ; var bv : int := -1 ; for y : yaml do ( var y : OclAny := y.split(":") ; var vacant : OclAny := y->first()->count("") ; if (bv->compareTo(vacant)) >= 0 then ( for _tuple : Integer.subrange(1, (beforei)->size())->collect( _indx | Sequence{_indx-1, (beforei)->at(_indx)} ) do (var _indx : int := 1; var num : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if b = vacant then ( break ) else skip) ; before := before.subrange(1,num) ; beforei := beforei.subrange(1,num) ) else skip ; bv := vacant ; execute ((y->first()->trim()) : before) ; execute ((bv) : beforei) ; var x : OclAny := y[1+1].subrange(1+1, -1) ; d->restrict((before)) := if x = "" then "object" else "string \"" + x + " \ " endif) ;\n var ans : Sequence := (check->trim().split(".")->tail()) ;\n execute (d->restrict(ans))->display();\n\n\n}\n ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re gkey=input() yaml={} opening_key=[''] opening_ind=[-1] space_prog=re.compile(r'*') key_prog=re.compile(r'[a-z\d]+') while True : try : line=input() except EOFError : break indent=len(space_prog.match(line).group()) while opening_ind[-1]>=indent : opening_ind.pop() opening_key.pop() key=key_prog.search(line).group() if not line.endswith(':'): yaml['.'.join(opening_key+[key])]=('string "{}"'.format(line[line.index(':')+2 :])) continue opening_key.append(key) opening_ind.append(indent) yaml['.'.join(opening_key)]='object' print(yaml.get(gkey,'no such property')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var gkey : String := (OclFile["System.in"]).readLine() ; var yaml : OclAny := Set{} ; var opening_key : Sequence := Sequence{ '' } ; var opening_ind : Sequence := Sequence{ -1 } ; var space_prog : OclRegex := OclRegex.compile(StringLib.rawString('*')) ; var key_prog : OclRegex := OclRegex.compile(StringLib.rawString('[a-z\d]+')) ; while true do ( try ( var line : String := (OclFile["System.in"]).readLine()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))) ; var indent : int := (space_prog.match(line).group())->size() ; while (opening_ind->last()->compareTo(indent)) >= 0 do ( opening_ind := opening_ind->front() ; opening_key := opening_key->front()) ; var key : OclAny := key_prog.search(line).group() ; if not(line->hasSuffix(':')) then ( yaml[StringLib.sumStringsWithSeparator((opening_key->union(Sequence{ key })), '.')+1] := (StringLib.interpolateStrings('string "{}"', Sequence{line.subrange(line->indexOf(':') - 1 + 2+1)})) ; continue ) else skip ; execute ((key) : opening_key) ; execute ((indent) : opening_ind) ; yaml[StringLib.sumStringsWithSeparator((opening_key), '.')+1] := 'object') ; execute (yaml.get(gkey, 'no such property'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) res=0 for i in range(n): x=0 for j in range(i,n): x=(x ^ a[j]) res=max(res,x) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x : int := 0 ; for j : Integer.subrange(i, n-1) do ( x := (MathLib.bitwiseXor(x, a[j+1])) ; res := Set{res, x}->max())) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,o=(int(x)for x in input().split()) def gcdOfFactorial(n,o): return math.factorial(min(n,o)) print(gcdOfFactorial(n,o)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var o : OclAny := null; Sequence{n,o} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; skip ; execute (gcdOfFactorial(n, o))->display(); operation gcdOfFactorial(n : OclAny, o : OclAny) : OclAny pre: true post: true activity: return MathLib.factorial(Set{n, o}->min()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import re def solve(n,s): ans=0 p='(I(?:OI){'+str(n)+',})' for f in re.findall(p,s): repeat=len(f)//2 if repeat>=n : ans+=(repeat-n+1) return ans def main(args): while True : n=int(input()) if n==0 : break _=input() s=input() ans=solve(n,s) print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(n : OclAny, s : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; var p : String := '(I(?:OI){' + ("" + ((n))) + ',})' ; for f : (s)->allMatches(p) do ( var repeat : int := (f)->size() div 2 ; if (repeat->compareTo(n)) >= 0 then ( ans := ans + (repeat - n + 1) ) else skip) ; return ans; operation main(args : OclAny) pre: true post: true activity: while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var _anon : String := (OclFile["System.in"]).readLine() ; s := (OclFile["System.in"]).readLine() ; ans := solve(n, s) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fact(n): if n<=1 : return 1 return fact(n-1)*n a,b=(int(x)for x in input().split()) print(fact(min(a,b))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; execute (fact(Set{a, b}->min()))->display(); operation fact(n : OclAny) : OclAny pre: true post: true activity: if n <= 1 then ( return 1 ) else skip ; return fact(n - 1) * n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fmin(m,n): d=min(m,n) factorial=1 for i in range(1,d+1): factorial=factorial*i print(factorial) m,n=[int(items)for items in input().split(" ")] fmin(m,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{m,n} := input().split(" ")->select(items | true)->collect(items | (("" + ((items)))->toInteger())) ; fmin(m, n); operation fmin(m : OclAny, n : OclAny) pre: true post: true activity: var d : OclAny := Set{m, n}->min() ; var factorial : int := 1 ; for i : Integer.subrange(1, d + 1-1) do ( factorial := factorial * i) ; execute (factorial)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minfact(x,y): z=min(x,y) fact=1 for i in range(1,z+1): fact*=i print(fact) x,y=[int(item)for item in input().split(' ')] minfact(x,y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{x,y} := input().split(' ')->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; minfact(x, y); operation minfact(x : OclAny, y : OclAny) pre: true post: true activity: var z : OclAny := Set{x, y}->min() ; var fact : int := 1 ; for i : Integer.subrange(1, z + 1-1) do ( fact := fact * i) ; execute (fact)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fact(s): if s<=1 : return 1 return fact(s-1)*s p,q=(int(y)for y in input().split()) print(fact(min(p,q))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) ))))))) (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; execute (fact(Set{p, q}->min()))->display(); operation fact(s : OclAny) : OclAny pre: true post: true activity: if s <= 1 then ( return 1 ) else skip ; return fact(s - 1) * s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=list(input()) n=len(a) res=0 for i in range(1,n): if a[i]!=a[i-1]: res+=1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var n : int := (a)->size() ; var res : int := 0 ; for i : Integer.subrange(1, n-1) do ( if a[i+1] /= a[i - 1+1] then ( res := res + 1 ) else skip) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys s=sys.stdin.readline() w=len([i for i in s.split('B')if i!='' and i!='\n']) b=len([i for i in s.split('W')if i!='' and i!='\n']) print(w+b-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : String := (OclFile["System.in"]).readLine() ; var w : int := (s.split('B')->select(i | i /= '' & i /= ' ')->collect(i | (i)))->size() ; var b : int := (s.split('W')->select(i | i /= '' & i /= ' ')->collect(i | (i)))->size() ; execute (w + b - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print((lambda s : s.count('WB')+s.count('BW'))(input())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((lambda s : OclAny in (s->count('WB') + s->count('BW')))((OclFile["System.in"]).readLine()))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- line=input() s=len(line) last=line[0] count=0 for letter in line : if letter!=last : last=letter count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var line : String := (OclFile["System.in"]).readLine() ; var s : int := (line)->size() ; var last : OclAny := line->first() ; var count : int := 0 ; for letter : line->characters() do ( if letter /= last then ( last := letter ; count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- uniq=[] for c in input(): if not uniq : uniq+=c elif uniq[-1]!=c : uniq+=c print(len(uniq)-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var uniq : Sequence := Sequence{} ; for c : (OclFile["System.in"]).readLine() do ( if not(uniq) then ( uniq := uniq + c ) else (if uniq->last() /= c then ( uniq := uniq + c ) else skip)) ; execute ((uniq)->size() - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) def yihuohe(a): he=a[0] for i in range(1,len(a)): he ^=a[i] return he a=input().strip().split(" ") for i in range(len(a)): a[i]=int(a[i]) max_=0 for i in range(len(a)): for j in range(i,len(a)): max_=max(max_,yihuohe(a[i : j+1])) print(max_) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; a := input()->trim().split(" ") ; for i : Integer.subrange(0, (a)->size()-1) do ( a[i+1] := ("" + ((a[i+1])))->toInteger()) ; var max_ : int := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( for j : Integer.subrange(i, (a)->size()-1) do ( max_ := Set{max_, yihuohe(a.subrange(i+1, j + 1))}->max())) ; execute (max_)->display(); operation yihuohe(a : OclAny) : OclAny pre: true post: true activity: var he : OclAny := a->first() ; for i : Integer.subrange(1, (a)->size()-1) do ( he := he xor a[i+1]) ; return he; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline while True : n=int(input()) if n==0 : break m=int(input()) s=input().strip() ans=cnt=i=0 while i0 : if s[i]=='O' : cnt-=1 if cnt>=n : ans+=cnt-n+1 cnt=0 i+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := input()->trim() ; ans := ans(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cnt)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; while (i->compareTo(m)) < 0 do ( if (i + 1->compareTo(m)) < 0 & s.subrange(i+1, i + 2) = 'IO' then ( cnt := cnt + 1 ; i := i + 1 ) else (if cnt > 0 then ( if s[i+1] = 'O' then ( cnt := cnt - 1 ) else skip ; if (cnt->compareTo(n)) >= 0 then ( ans := ans + cnt - n + 1 ) else skip ; var cnt : int := 0 ) else skip) ; i := i + 1) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countBits(a): count=0 while(a): if(a & 1): count+=1 a=a>>1 return count def insertionSort(arr,aux,n): for i in range(1,n,1): key1=aux[i] key2=arr[i] j=i-1 while(j>=0 and aux[j]union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))))) ; n := (arr)->size() ; sortBySetBitCount(arr, n) ; printArr(arr, n) ) else skip; operation countBits(a : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while (a) do ( if (MathLib.bitwiseAnd(a, 1)) then ( count := count + 1 ) else skip ; a := a /(2->pow(1))) ; return count; operation insertionSort(arr : OclAny, aux : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( var key1 : OclAny := aux[i+1] ; var key2 : OclAny := arr[i+1] ; var j : double := i - 1 ; while (j >= 0 & (aux[j+1]->compareTo(key1)) < 0) do ( aux[j + 1+1] := aux[j+1] ; arr[j + 1+1] := arr[j+1] ; j := j - 1) ; aux[j + 1+1] := key1 ; arr[j + 1+1] := key2); operation sortBySetBitCount(arr : OclAny, n : OclAny) pre: true post: true activity: aux := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( aux[i+1] := countBits(arr[i+1])) ; insertionSort(arr, aux, n); operation printArr(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def modInverse(a,m): g=gcd(a,m) if(g!=1): print("Inverse doesn't exist") else : print("Modular multiplicative inverse is ",power(a,m-2,m)) def power(x,y,m): if(y==0): return 1 p=power(x,y//2,m)% m p=(p*p)% m if(y % 2==0): return p else : return((x*p)% m) def gcd(a,b): if(a==0): return b return gcd(b % a,a) a=3 ; m=11 modInverse(a,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; a := 3; m := 11 ; modInverse(a, m); operation modInverse(a : OclAny, m : OclAny) pre: true post: true activity: var g : OclAny := gcd(a, m) ; if (g /= 1) then ( execute ("Inverse doesn't exist")->display() ) else ( execute ("Modular multiplicative inverse is ")->display() ); operation power(x : OclAny, y : OclAny, m : OclAny) : OclAny pre: true post: true activity: if (y = 0) then ( return 1 ) else skip ; var p : int := power(x, y div 2, m) mod m ; p := (p * p) mod m ; if (y mod 2 = 0) then ( return p ) else ( return ((x * p) mod m) ); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0) then ( return b ) else skip ; return gcd(b mod a, a); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minimumMoves(n,a,s,t): x=s for i in range(1,n+1): if x==t : return i-1 x=a[x] return-1 if __name__=="__main__" : s,t=2,1 a=[-1,2,3,4,1] n=len(a) print(minimumMoves(n,a,s,t)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{s,t} := Sequence{2,1} ; a := Sequence{-1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 1 })))) ; n := (a)->size() ; execute (minimumMoves(n, a, s, t))->display() ) else skip; operation minimumMoves(n : OclAny, a : OclAny, s : OclAny, t : OclAny) : OclAny pre: true post: true activity: var x : OclAny := s ; for i : Integer.subrange(1, n + 1-1) do ( if x = t then ( return i - 1 ) else skip ; x := a[x+1]) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countOddRotations(n): odd_count=0 ; even_count=0 while n!=0 : digit=n % 10 if digit % 2==0 : odd_count+=1 else : even_count+=1 n=n//10 print("Odd=",odd_count) print("Even=",even_count) n=1234 countOddRotations(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 1234 ; countOddRotations(n); operation countOddRotations(n : OclAny) pre: true post: true activity: var odd_count : int := 0; var even_count : int := 0 ; while n /= 0 do ( var digit : int := n mod 10 ; if digit mod 2 = 0 then ( odd_count := odd_count + 1 ) else ( even_count := even_count + 1 ) ; n := n div 10) ; execute ("Odd=")->display() ; execute ("Even=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fact(n): f=1 while n>=1 : f=f*n n=n-1 return f def findSmallerInRight(st,low,high): countRight=0 i=low+1 while i<=high : if st[i]display(); operation fact(n : OclAny) : OclAny pre: true post: true activity: var f : int := 1 ; while n >= 1 do ( f := f * n ; n := n - 1) ; return f; operation findSmallerInRight(st : OclAny, low : OclAny, high : OclAny) : OclAny pre: true post: true activity: var countRight : int := 0 ; var i : OclAny := low + 1 ; while (i->compareTo(high)) <= 0 do ( if (st[i+1]->compareTo(st[low+1])) < 0 then ( countRight := countRight + 1 ) else skip ; i := i + 1) ; return countRight; operation findRank(st : OclAny) : OclAny pre: true post: true activity: var ln : int := (st)->size() ; var mul : OclAny := fact(ln) ; var rank : int := 1 ; i := 0 ; while (i->compareTo(ln)) < 0 do ( mul := mul / (ln - i) ; countRight := findSmallerInRight(st, i, ln - 1) ; rank := rank + countRight * mul ; i := i + 1) ; return rank; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s="ABCdcba" u=[0]*26 n=len(s) for i in range(n): if(s[i].isupper()): u[ord(s[i])-65]+=1 else : u[ord(s[i])-97]-=1 fl=True po=0 ne=0 for i in range(26): if(u[i]>0): po+=u[i] if(u[i]<0): ne+=u[i] if(po==0 and ne==0): print("YES") elif(po==1 and ne==0): print("YES") elif(po==0 and ne==-1): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := "ABCdcba" ; var u : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; var n : int := (s)->size() ; for i : Integer.subrange(0, n-1) do ( if (s[i+1]->matches("[A-Z ]*")) then ( u[(s[i+1])->char2byte() - 65+1] := u[(s[i+1])->char2byte() - 65+1] + 1 ) else ( u[(s[i+1])->char2byte() - 97+1] := u[(s[i+1])->char2byte() - 97+1] - 1 )) ; var fl : boolean := true ; var po : int := 0 ; var ne : int := 0 ; for i : Integer.subrange(0, 26-1) do ( if (u[i+1] > 0) then ( po := po + u[i+1] ) else skip ; if (u[i+1] < 0) then ( ne := ne + u[i+1] ) else skip) ; if (po = 0 & ne = 0) then ( execute ("YES")->display() ) else (if (po = 1 & ne = 0) then ( execute ("YES")->display() ) else (if (po = 0 & ne = -1) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np ; dp=np.ones((15,2))*-1 ; def convertToString(num): return str(num); def calculate(pos,tight,D,sz,num): if(pos==len(num)): return 1 ; if(dp[pos][tight]!=-1): return dp[pos][tight]; val=0 ; if(tight==0): for i in range(sz): if(D[i]<(ord(num[pos])-ord('0'))): val+=calculate(pos+1,1,D,sz,num); elif(D[i]==ord(num[pos])-ord('0')): val+=calculate(pos+1,tight,D,sz,num); else : for i in range(sz): val+=calculate(pos+1,tight,D,sz,num); dp[pos][tight]=val ; return dp[pos][tight]; def countNumbers(D,N,sz): num=convertToString(N); length=len(num); ans=calculate(0,0,D,sz,num); for i in range(1,length): ans+=calculate(i,1,D,sz,num); return ans ; if __name__=="__main__" : sz=3 ; D=[1,4,9]; N=10 ; print(countNumbers(D,N,sz)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; ; var dp : Sequence := MatrixLib.elementwiseMult(MatrixLib.singleValueMatrix(Sequence{15, 2}, 1.0), -1); ; skip ; skip ; skip ; if __name__ = "__main__" then ( sz := 3; ; D := Sequence{1}->union(Sequence{4}->union(Sequence{ 9 })); ; N := 10; ; execute (countNumbers(D, N, sz))->display(); ) else skip; operation convertToString(num : OclAny) pre: true post: true activity: return ("" + ((num)));; operation calculate(pos : OclAny, tight : OclAny, D : OclAny, sz : OclAny, num : OclAny) pre: true post: true activity: if (pos = (num)->size()) then ( return 1; ) else skip ; if (dp[pos+1][tight+1] /= -1) then ( return dp[pos+1][tight+1]; ) else skip ; var val : int := 0; ; if (tight = 0) then ( for i : Integer.subrange(0, sz-1) do ( if ((D[i+1]->compareTo(((num[pos+1])->char2byte() - ('0')->char2byte()))) < 0) then ( val := val + calculate(pos + 1, 1, D, sz, num); ) else (if (D[i+1] = (num[pos+1])->char2byte() - ('0')->char2byte()) then ( val := val + calculate(pos + 1, tight, D, sz, num); ) else skip)) ) else ( for i : Integer.subrange(0, sz-1) do ( val := val + calculate(pos + 1, tight, D, sz, num);) ) ; dp[pos+1][tight+1] := val; ; return dp[pos+1][tight+1];; operation countNumbers(D : OclAny, N : OclAny, sz : OclAny) pre: true post: true activity: num := convertToString(N); ; var length : int := (num)->size(); ; var ans : OclAny := calculate(0, 0, D, sz, num); ; for i : Integer.subrange(1, length-1) do ( ans := ans + calculate(i, 1, D, sz, num);) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node(object): __slots__='data','next' def __init__(self,data=None,next=None): self.data=data self.next=next def __repr__(self): return repr(self.data) class LinkedList(object): def __init__(self): self.head=None def __repr__(self): nodes=[] curr=self.head while curr : nodes.append(repr(curr)) curr=curr.next return '['+','.join(nodes)+']' def prepend(self,data): self.head=Node(data=data,next=self.head) def reverse(self,k=1): if self.head is None : return curr=self.head prev=None new_stack=[] while curr is not None : val=0 while curr is not None and valexists( _x | result = _x ); static attribute __slots__ : String := 'data','next'; attribute data : OclAny := data; attribute next : OclAny := next; operation initialise(data : OclAny,next : OclAny) : pre: true post: true activity: self.data := data ; self.next := next; return self; operation __repr__() : OclAny pre: true post: true activity: return ("" + ((self.data))); } class LinkedList extends object { static operation newLinkedList() : LinkedList pre: true post: LinkedList->exists( _x | result = _x ); attribute head : OclAny := null; operation initialise() : pre: true post: true activity: self.head := null; return self; operation __repr__() : OclAny pre: true post: true activity: var nodes : Sequence := Sequence{} ; var curr : OclAny := self.head ; while curr do ( execute ((("" + ((curr)))) : nodes) ; curr := curr.next) ; return '[' + StringLib.sumStringsWithSeparator((nodes), ',') + ']'; operation prepend(data : OclAny) pre: true post: true activity: self.head := (Node.newNode()).initialise((argument (test (logical_test (comparison (expr (atom (name data)))))) = (test (logical_test (comparison (expr (atom (name data))))))), (argument (test (logical_test (comparison (expr (atom (name next)))))) = (test (logical_test (comparison (expr (atom (name self)) (trailer . (name head)))))))); operation reverse(k : int) : OclAny pre: true post: true activity: if self.head <>= null then ( return ) else skip ; curr := self.head ; var prev : OclAny := null ; var new_stack : Sequence := Sequence{} ; while not(curr <>= null) do ( var val : int := 0 ; while not(curr <>= null) & (val->compareTo(k)) < 0 do ( execute ((curr.data) : new_stack) ; curr := curr.next ; val := val + 1) ; while new_stack do ( if prev <>= null then ( prev := (Node.newNode()).initialise(new_stack->last()) ; self.head := prev ) else ( prev.next := (Node.newNode()).initialise(new_stack->last()) ; prev := prev.next ))) ; prev.next := null ; return self.head; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var llist : LinkedList := (LinkedList.newLinkedList()).initialise() ; llist.prepend(9) ; llist.prepend(8) ; llist.prepend(7) ; llist.prepend(6) ; llist.prepend(5) ; llist.prepend(4) ; llist.prepend(3) ; llist.prepend(2) ; llist.prepend(1) ; execute ("Given linked list")->display() ; execute (llist)->display() ; llist.head := llist->reverse() ; execute ("Reversed Linked list")->display() ; execute (llist)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) mat=[] for i in range(n): v,w,t,d,s=map(str,input().split()) mat.append([int(v),int(w),t,int(d),s]) mat.sort() for i in range(n): print(' '.join(str(m)for m in mat[i])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mat : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var v : OclAny := null; var w : OclAny := null; var t : OclAny := null; var d : OclAny := null; var s : OclAny := null; Sequence{v,w,t,d,s} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; execute ((Sequence{("" + ((v)))->toInteger()}->union(Sequence{("" + ((w)))->toInteger()}->union(Sequence{t}->union(Sequence{("" + ((d)))->toInteger()}->union(Sequence{ s }))))) : mat)) ; mat := mat->sort() ; for i : Integer.subrange(0, n-1) do ( execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name m)))))))) ))))))) (comp_for for (exprlist (expr (atom (name m)))) in (logical_test (comparison (expr (atom (name mat)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Items : def __init__(self,v,w,t,d,s): self.value=v self.weight=w self.type=t self.date=d self.name=s def __lt__(self,other): if self.valueexists( _x | result = _x ); attribute value : OclAny := v; attribute weight : OclAny := w; attribute type : OclAny := t; attribute date : OclAny := d; attribute name : OclAny := s; operation initialise(v : OclAny,w : OclAny,t : OclAny,d : OclAny,s : OclAny) : Items pre: true post: true activity: self.value := v ; self.weight := w ; self.type := t ; self.date := d ; self.name := s; return self; operation __lt__(other : OclAny) : OclAny pre: true post: true activity: if (self.value->compareTo(other.value)) < 0 then ( return true ) else (if self.value = other.value then ( if (self.weight->compareTo(other.weight)) < 0 then ( return true ) else (if self.weight = other.weight then ( if (self.type->compareTo(other.type)) < 0 then ( return true ) else (if self.type = other.type then ( if (self.date->compareTo(other.date)) < 0 then ( return true ) else (if self.date = other.date then ( if (self.name->compareTo(other.name)) < 0 then ( return true ) else ( return false ) ) else ( return false ) ) ) else ( return false ) ) ) else ( return false ) ) ) else ( return false ) ) ; operation __str__() : OclAny pre: true post: true activity: return StringLib.interpolateStrings("{}{}{}{}{}", Sequence{self.value, self.weight, self.type, self.date, self.name}); } class FromPython { operation initialise() pre: true post: true activity: skip ; var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var L : Sequence := Sequence{} ; for _anon : Integer.subrange(0, num-1) do ( Sequence{v,w,t,d,s} := input().split() ; execute (((Items.newItems()).initialise(("" + ((v)))->toInteger(), ("" + ((w)))->toInteger(), t, ("" + ((d)))->toInteger(), s)) : L)) ; L := L->sort() ; for i : L do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def leapyear(n): if(n % 400==0 or(n % 4==0 and n % 100!=0)): return "y" else : return "n" n=int(input()) d="f" if(n % 400==0 or(n % 4==0 and n % 100!=0)): ans="ly" else : ans="nly" while(True): if(n % 400==0 or(n % 4==0 and n % 100!=0)): if(d=="m"): d="w" n+=1 elif(d=="t"): d="th" n+=1 elif(d=="w"): d="f" n+=1 elif(d=="th"): d="sa" n+=1 elif(d=="f"): d="s" n+=1 elif(d=="sa"): d="m" n+=1 elif(d=="s"): d="t" n+=1 else : if(d=="m"): d="t" n+=1 elif(d=="t"): d="w" n+=1 elif(d=="w"): d="th" n+=1 elif(d=="th"): d="f" n+=1 elif(d=="f"): d="sa" n+=1 elif(d=="sa"): d="s" n+=1 elif(d=="s"): d="m" n+=1 if(d=="f" and ans=="ly" and leapyear(n)=="y"): break elif(d=="f" and ans=="nly" and leapyear(n)=="n"): break print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : String := "f" ; if (n mod 400 = 0 or (n mod 4 = 0 & n mod 100 /= 0)) then ( var ans : String := "ly" ) else ( ans := "nly" ) ; while (true) do ( if (n mod 400 = 0 or (n mod 4 = 0 & n mod 100 /= 0)) then ( if (d = "m") then ( d := "w" ; n := n + 1 ) else (if (d = "t") then ( d := "th" ; n := n + 1 ) else (if (d = "w") then ( d := "f" ; n := n + 1 ) else (if (d = "th") then ( d := "sa" ; n := n + 1 ) else (if (d = "f") then ( d := "s" ; n := n + 1 ) else (if (d = "sa") then ( d := "m" ; n := n + 1 ) else (if (d = "s") then ( d := "t" ; n := n + 1 ) else skip ) ) ) ) ) ) ) else ( if (d = "m") then ( d := "t" ; n := n + 1 ) else (if (d = "t") then ( d := "w" ; n := n + 1 ) else (if (d = "w") then ( d := "th" ; n := n + 1 ) else (if (d = "th") then ( d := "f" ; n := n + 1 ) else (if (d = "f") then ( d := "sa" ; n := n + 1 ) else (if (d = "sa") then ( d := "s" ; n := n + 1 ) else (if (d = "s") then ( d := "m" ; n := n + 1 ) else skip ) ) ) ) ) ) ) ; if (d = "f" & ans = "ly" & leapyear(n) = "y") then ( break ) else (if (d = "f" & ans = "nly" & leapyear(n) = "n") then ( break ) else skip)) ; execute (n)->display(); operation leapyear(n : OclAny) : OclAny pre: true post: true activity: if (n mod 400 = 0 or (n mod 4 = 0 & n mod 100 /= 0)) then ( return "y" ) else ( return "n" ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): while True : n=int(input()) if n==0 : break m=int(input()) s=input() pn="IOI"+("OI"*(n-1)) limit=len(pn) searchflag=False nextI=False tmp=[] start=0 i=0 ans=0 while i=limit : tmp.append(searching) searchflag=not searchflag else : if s[i]=="I" : start=i nextI=False searchflag=True i+=1 for i in range(len(tmp)): ans+=len(tmp[i])//2-n+1 print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var pn : String := "IOI" + (StringLib.nCopies("OI", (n - 1))) ; var limit : int := (pn)->size() ; var searchflag : boolean := false ; var nextI : boolean := false ; var tmp : Sequence := Sequence{} ; var start : int := 0 ; var i : int := 0 ; var ans : int := 0 ; while (i->compareTo(m)) < 0 do ( if searchflag then ( if not(nextI) & s[i+1] = "O" then ( nextI := not(nextI) ) else (if nextI & s[i+1] = "I" then ( nextI := not(nextI) ) else ( if s[i - 1+1] = "I" then ( var searching : OclAny := s.subrange(start+1, i) ) else ( searching := s.subrange(start+1, i - 1) ) ; i := i - 1 ; if ((searching)->size()->compareTo(limit)) >= 0 then ( execute ((searching) : tmp) ) else skip ; searchflag := not(searchflag) ) ) ) else ( if s[i+1] = "I" then ( start := i ; nextI := false ; searchflag := true ) else skip ) ; i := i + 1) ; for i : Integer.subrange(0, (tmp)->size()-1) do ( ans := ans + (tmp[i+1])->size() div 2 - n + 1) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().strip().split())) mx=c=0 for i in range(n): if mxtoInteger() ; var a : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mx : OclAny := 0; var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (mx->compareTo(a[i+1])) < 0 then ( mx := a[i+1] ) else skip ; c := a[i+1] ; for j : Integer.subrange(i + 1, n-1) do ( c := c xor a[j+1] ; if (mx->compareTo(c)) < 0 then ( mx := c ) else skip) ; if (mx->compareTo(c)) < 0 then ( mx := c ) else skip) ; execute (mx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for item in sorted([[int(a[0]),int(a[1]),a[2],int(a[3]),a[4]]for a in[input().split()for _ in[0]*int(input())]]): print(*item) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for item : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger())->select(_anon | true)->collect(_anon | (input().split()))->select(a | true)->collect(a | (Sequence{("" + ((a->first())))->toInteger()}->union(Sequence{("" + ((a[1+1])))->toInteger()}->union(Sequence{a[2+1]}->union(Sequence{("" + ((a[3+1])))->toInteger()}->union(Sequence{ a[4+1] }))))))->sort() do ( execute ((argument * (test (logical_test (comparison (expr (atom (name item))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- readline=open(0).readline N=int(readline()) P=[readline().split()for i in range(N)] P=[(int(v),int(w),t,int(d),s)for v,w,t,d,s in P] P.sort() open(1,'w').writelines(["%d %d %s %d %s\n" % e for e in P]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var readline : OclAny := open(0).readline ; var N : int := ("" + ((readline())))->toInteger() ; var P : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (readline().split())) ; P := P->select(_tuple | true)->collect(_tuple | let v : OclAny = _tuple->at(1) in let w : OclAny = _tuple->at(2) in (Sequence{("" + ((v)))->toInteger(), ("" + ((w)))->toInteger(), t, ("" + ((d)))->toInteger(), s})) ; P := P->sort() ; (expr (atom (name open)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom 'w'))))))) ))) (trailer . (name writelines) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom "%d %d %s %d %s\n")) % (expr (atom (name e))))))) (comp_for for (exprlist (expr (atom (name e)))) in (logical_test (comparison (expr (atom (name P))))))) ]))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heapify,heappop def sort(xs): heapify(xs) return[heappop(xs)for _ in range(len(xs))] def run(): n=int(input()) elements=[] for _ in range(n): v,w,t,d,s=input().split() elements.append((int(v),int(w),t,int(d),s)) for e in sort(elements): print("{}{}{}{}{}".format(*e)) if __name__=='__main__' : run() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( run() ) else skip; operation sort(xs : OclAny) : OclAny pre: true post: true activity: heapify(xs) ; return Integer.subrange(0, (xs)->size()-1)->select(_anon | true)->collect(_anon | (heappop(xs))); operation run() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var elements : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var v : OclAny := null; var w : OclAny := null; var t : OclAny := null; var d : OclAny := null; var s : OclAny := null; Sequence{v,w,t,d,s} := input().split() ; execute ((Sequence{("" + ((v)))->toInteger(), ("" + ((w)))->toInteger(), t, ("" + ((d)))->toInteger(), s}) : elements)) ; for e : sort(elements) do ( execute (StringLib.interpolateStrings("{}{}{}{}{}", Sequence{(argument * (test (logical_test (comparison (expr (atom (name e)))))))}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkIfPossibleRec(x,a,b,isPossible,n): if x>n : return if isPossible[x]: return isPossible[x]=True checkIfPossibleRec(x+a,a,b,isPossible,n) checkIfPossibleRec(x+b,a,b,isPossible,n) def checkPossible(n,a,b): isPossible=[False]*(n+1) checkIfPossibleRec(0,a,b,isPossible,n) return isPossible[n] if __name__=="__main__" : a,b,n=3,7,8 if checkPossible(a,b,n): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( Sequence{a,b,n} := Sequence{3,7,8} ; if checkPossible(a, b, n) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation checkIfPossibleRec(x : OclAny, a : OclAny, b : OclAny, isPossible : OclAny, n : OclAny) pre: true post: true activity: if (x->compareTo(n)) > 0 then ( return ) else skip ; if isPossible[x+1] then ( return ) else skip ; isPossible[x+1] := true ; checkIfPossibleRec(x + a, a, b, isPossible, n) ; checkIfPossibleRec(x + b, a, b, isPossible, n); operation checkPossible(n : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: isPossible := MatrixLib.elementwiseMult(Sequence{ false }, (n + 1)) ; checkIfPossibleRec(0, a, b, isPossible, n) ; return isPossible[n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def printSubsequences(arr,n): opsize=math.pow(2,n) for counter in range(1,(int)(opsize)): for j in range(0,n): if(counter &(1<union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))) ; n := (arr)->size() ; execute ("All Non-empty Subsequences")->display() ; printSubsequences(arr, n); operation printSubsequences(arr : OclAny, n : OclAny) pre: true post: true activity: var opsize : double := (2)->pow(n) ; for counter : Integer.subrange(1, (OclType["int"])(opsize)-1) do ( for j : Integer.subrange(0, n-1) do ( if (MathLib.bitwiseAnd(counter, (1 * (2->pow(j))))) then ( execute (arr[j+1])->display() ) else skip) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) c=int(input()) d=int(input()) e=int(input()) k=int(input()) if e-a<=k : print("Yay!") else : print(":(") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var e : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (e - a->compareTo(k)) <= 0 then ( execute ("Yay!")->display() ) else ( execute (":(")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections as c ip=lambda : map(int,input().split()) A=int(input()) B=int(input()) C=int(input()) D=int(input()) E=int(input()) k=int(input()) for i in[A,B,C,D,E]: for j in[A,B,C,D,E]: if abs(i-j)>k : print(':(') exit() print('Yay!') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var ip : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var C : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var D : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var E : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Sequence{A}->union(Sequence{B}->union(Sequence{C}->union(Sequence{D}->union(Sequence{ E })))) do ( for j : Sequence{A}->union(Sequence{B}->union(Sequence{C}->union(Sequence{D}->union(Sequence{ E })))) do ( if ((i - j)->abs()->compareTo(k)) > 0 then ( execute (':(')->display() ; exit() ) else skip)) ; execute ('Yay!')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): import sys input=sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter,deque from itertools import combinations,permutations,accumulate,groupby,product from bisect import bisect_left,bisect_right from heapq import heapify,heappop,heappush from math import floor,ceil a=[int(input())for _ in range(5)] k=int(input()) if a[-1]-a[0]>k : print(':(') else : print('Yay!') if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit((10)->pow(7)) ; skip ; skip ; skip ; skip ; skip ; var a : Sequence := Integer.subrange(0, 5-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (a->last() - a->first()->compareTo(k)) > 0 then ( execute (':(')->display() ) else ( execute ('Yay!')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- antennas=[0]*5 for i in range(5): antennas[i]=int(input()) k=int(input()) for i in range(len(antennas)): for j in range(i+1,len(antennas)): if antennas[j]-antennas[i]>k : print(":(") exit(0) print('Yay!') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var antennas : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 5) ; for i : Integer.subrange(0, 5-1) do ( antennas[i+1] := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, (antennas)->size()-1) do ( for j : Integer.subrange(i + 1, (antennas)->size()-1) do ( if (antennas[j+1] - antennas[i+1]->compareTo(k)) > 0 then ( execute (":(")->display() ; exit(0) ) else skip)) ; execute ('Yay!')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if n==0 : break a='I'+'OI'*n b,s=int(input()),input() print(sum(1 for i in range(b-len(a))if s[i : i+len(a)]==a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var a : String := 'I' + StringLib.nCopies('OI', n) ; var b : OclAny := null; var s : OclAny := null; Sequence{b,s} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),(OclFile["System.in"]).readLine()} ; execute (((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))) : (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))))))))) ])))) == (comparison (expr (atom (name a)))))))))))->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=[int(input())for _ in range(5)] k=int(input()) if max(l)-min(l)<=k : print('Yay!') else : print(':(') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := Integer.subrange(0, 5-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if ((l)->max() - (l)->min()->compareTo(k)) <= 0 then ( execute ('Yay!')->display() ) else ( execute (':(')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printTwoDivisibleParts(num,f,s): N=len(num); prefixReminder=[0]*(N+1); suffixReminder=[0]*(N+1); for i in range(1,N): suffixReminder[i]=(suffixReminder[i-1]*10+(ord(num[i-1])-48))% f ; base=1 ; for i in range(N-1,-1,-1): prefixReminder[i]=(prefixReminder[i+1]+(ord(num[i])-48)*base)% s ; base=(base*10)% s ; for i in range(N): if(prefixReminder[i]==0 and suffixReminder[i]==0 and num[i]!='0'): print(num[0 : i],num[i : N]); return 0 ; print("Not Possible"); if __name__=='__main__' : num="246904096" ; f=12345 ; s=1024 ; printTwoDivisibleParts(num,f,s); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( num := "246904096"; ; f := 12345; ; s := 1024; ; printTwoDivisibleParts(num, f, s); ) else skip; operation printTwoDivisibleParts(num : OclAny, f : OclAny, s : OclAny) pre: true post: true activity: var N : int := (num)->size(); ; var prefixReminder : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)); ; var suffixReminder : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)); ; for i : Integer.subrange(1, N-1) do ( suffixReminder[i+1] := (suffixReminder[i - 1+1] * 10 + ((num[i - 1+1])->char2byte() - 48)) mod f;) ; var base : int := 1; ; for i : Integer.subrange(-1 + 1, N - 1)->reverse() do ( prefixReminder[i+1] := (prefixReminder[i + 1+1] + ((num[i+1])->char2byte() - 48) * base) mod s; ; base := (base * 10) mod s;) ; for i : Integer.subrange(0, N-1) do ( if (prefixReminder[i+1] = 0 & suffixReminder[i+1] = 0 & num[i+1] /= '0') then ( execute (num.subrange(0+1, i))->display(); ; return 0; ) else skip) ; execute ("Not Possible")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=10000 arr=[] sprime=[False]*(MAX) def computeSemiPrime(): for i in range(2,MAX): cnt,num,j=0,i,2 while cnt<2 and j*j<=num : while num % j==0 : num/=j cnt+=1 j+=1 if num>1 : cnt+=1 if cnt==2 : sprime[i]=True arr.append(i) def checkSemiPrime(n): i=0 while arr[i]<=n//2 : if sprime[n-arr[i]]==True : return True i+=1 return False if __name__=="__main__" : computeSemiPrime() n=30 if checkSemiPrime(n)==True : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 10000 ; var arr : Sequence := Sequence{} ; var sprime : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (MAX)) ; skip ; skip ; if __name__ = "__main__" then ( computeSemiPrime() ; n := 30 ; if checkSemiPrime(n) = true then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; operation computeSemiPrime() pre: true post: true activity: for i : Integer.subrange(2, MAX-1) do ( var cnt : OclAny := null; var num : OclAny := null; var j : OclAny := null; Sequence{cnt,num,j} := Sequence{0,i,2} ; while cnt < 2 & (j * j->compareTo(num)) <= 0 do ( while num mod j = 0 do ( num := num / j ; cnt := cnt + 1) ; j := j + 1) ; if num > 1 then ( cnt := cnt + 1 ) else skip ; if cnt = 2 then ( sprime[i+1] := true ; execute ((i) : arr) ) else skip); operation checkSemiPrime(n : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; while (arr[i+1]->compareTo(n div 2)) <= 0 do ( if sprime[n - arr[i+1]+1] = true then ( return true ) else skip ; i := i + 1) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) t,=R() while t : t-=1 ; n,=R(); a,b=zip(*(R()for _ in[0]*n)); s=0 for x,y,z,w in zip(a,b,(0,*b),R()): p=s+x-z+w ; s=p+max(y-x+1>>1,y-p) print(p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := R->apply() ; while t do ( t := t - 1;(testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,)} := R->apply(); var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name R)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr (atom (name n)))))))) )))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name R)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr (atom (name n)))))))) )))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name R)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr (atom (name n)))))))) )))))))`third->at(_indx)} ); var s : int := 0 ; for _tuple : Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), b->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); _indx := _indx + 1; var z : OclAny := _tuple->at(_indx); _indx := _indx + 1; var w : OclAny := _tuple->at(_indx); var p : double := s + x - z + w; s := p + Set{y - x + 1 /(2->pow(1)), y - p}->max()) ; execute (p)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) t,=R() while t : t-=1 ; n,=R(); a,b=zip(*(R()for _ in[0]*n)); s=0 for x,y,z,w in zip(a,b,(0,*b),R()): p=s+x-z+w ; s=p+max(y-x+1>>1,y-p) print(p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := R->apply() ; while t do ( t := t - 1;(testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,)} := R->apply(); var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name R)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr (atom (name n)))))))) )))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name R)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr (atom (name n)))))))) )))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name R)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr (atom (name n)))))))) )))))))`third->at(_indx)} ); var s : int := 0 ; for _tuple : Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), b->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); _indx := _indx + 1; var z : OclAny := _tuple->at(_indx); _indx := _indx + 1; var w : OclAny := _tuple->at(_indx); var p : double := s + x - z + w; s := p + Set{y - x + 1 /(2->pow(1)), y - p}->max()) ; execute (p)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) for _ in range(q): n=int(input()) t=0 s=0 a=[0] b=[0] for _ in range(n): x,y=list(map(int,input().split())) a.append(x) b.append(y) p=list(map(int,input().split())) for i in range(1,n): t+=a[i]-b[i-1]+p[i-1] t+=max(b[i]-t,(b[i]-a[i]+1)//2) t+=a[n]-b[n-1]+p[n-1] print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : int := 0 ; var s : int := 0 ; var a : Sequence := Sequence{ 0 } ; var b : Sequence := Sequence{ 0 } ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((x) : a) ; execute ((y) : b)) ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(1, n-1) do ( t := t + a[i+1] - b[i - 1+1] + p[i - 1+1] ; t := t + Set{b[i+1] - t, (b[i+1] - a[i+1] + 1) div 2}->max()) ; t := t + a[n+1] - b[n - 1+1] + p[n - 1+1] ; execute (t)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) ans=[] for i in range(t): a=[0] b=[0] n=int(input()) for j in range(n): ai,bi=map(int,input().split()) a.append(ai) b.append(bi) time=0 tm=[0] tm+=[int(x)for x in input().split()] diff=0 for k in range(1,n+1): time+=a[k]-b[k-1]+tm[k] if k!=n : time+=(b[k]-a[k]+1)//2 if timetoInteger() ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( var a : Sequence := Sequence{ 0 } ; var b : Sequence := Sequence{ 0 } ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, n-1) do ( var ai : OclAny := null; var bi : OclAny := null; Sequence{ai,bi} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((ai) : a) ; execute ((bi) : b)) ; var time : int := 0 ; var tm : Sequence := Sequence{ 0 } ; tm := tm + input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var diff : int := 0 ; for k : Integer.subrange(1, n + 1-1) do ( time := time + a[k+1] - b[k - 1+1] + tm[k+1] ; if k /= n then ( time := time + (b[k+1] - a[k+1] + 1) div 2 ; if (time->compareTo(b[k+1])) < 0 then ( time := time + b[k+1] - time ) else skip ) else ( continue )) ; execute ((time) : ans)) ; for _anon : Integer.subrange(0, (ans)->size()-1) do ( execute (ans[_anon+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=[0] b=[0] for __ in range(n): ai,bi=map(int,input().split()) a.append(ai) b.append(bi) tm=[0] tm+=[int(x)for x in input().split()] dep=[0]*(n+1) arr=[0]*(n+1) for i in range(1,n+1): arr[i]=dep[i-1]+(a[i]-b[i-1])+tm[i] dep[i]=max(b[i],arr[i]+((b[i]-a[i]+1)//2)) print(arr[n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{ 0 } ; var b : Sequence := Sequence{ 0 } ; for __ : Integer.subrange(0, n-1) do ( var ai : OclAny := null; var bi : OclAny := null; Sequence{ai,bi} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((ai) : a) ; execute ((bi) : b)) ; var tm : Sequence := Sequence{ 0 } ; tm := tm + input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var dep : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(1, n + 1-1) do ( arr[i+1] := dep[i - 1+1] + (a[i+1] - b[i - 1+1]) + tm[i+1] ; dep[i+1] := Set{b[i+1], arr[i+1] + ((b[i+1] - a[i+1] + 1) div 2)}->max()) ; execute (arr[n+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys s=sys.stdin.read().lower() table={"a" : 0,"b" : 0,"c" : 0,"d" : 0,"e" : 0,"f" : 0,"g" : 0,"h" : 0,"i" : 0,"j" : 0,"k" : 0,"l" : 0,"m" : 0,"n" : 0,"o" : 0,"p" : 0,"q" : 0,"r" : 0,"s" : 0,"t" : 0,"u" : 0,"v" : 0,"w" : 0,"x" : 0,"y" : 0,"z" : 0,} for i in list(s): if i in table : table[i]+=1 else : continue for i in table : print('{}:{}'.format(i,table[i])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : OclAny := sys.stdin.readAll()->toLowerCase() ; var table : Map := Map{ "a" |-> 0 }->union(Map{ "b" |-> 0 }->union(Map{ "c" |-> 0 }->union(Map{ "d" |-> 0 }->union(Map{ "e" |-> 0 }->union(Map{ "f" |-> 0 }->union(Map{ "g" |-> 0 }->union(Map{ "h" |-> 0 }->union(Map{ "i" |-> 0 }->union(Map{ "j" |-> 0 }->union(Map{ "k" |-> 0 }->union(Map{ "l" |-> 0 }->union(Map{ "m" |-> 0 }->union(Map{ "n" |-> 0 }->union(Map{ "o" |-> 0 }->union(Map{ "p" |-> 0 }->union(Map{ "q" |-> 0 }->union(Map{ "r" |-> 0 }->union(Map{ "s" |-> 0 }->union(Map{ "t" |-> 0 }->union(Map{ "u" |-> 0 }->union(Map{ "v" |-> 0 }->union(Map{ "w" |-> 0 }->union(Map{ "x" |-> 0 }->union(Map{ "y" |-> 0 }->union((dictorsetmaker (test (logical_test (comparison (expr (atom "z"))))) : (test (logical_test (comparison (expr (atom (number (integer 0))))))) ,)))))))))))))))))))))))))) ; for i : (s) do ( if (table)->includes(i) then ( table[i+1] := table[i+1] + 1 ) else ( continue )) ; for i : table->keys() do ( execute (StringLib.interpolateStrings('{}:{}', Sequence{i, table[i+1]}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- char_list="abcdefghijklmnopqrstuvwxyz" char_count={} for c in char_list : char_count[c]=0 s="" while True : try : s+=input().lower() except EOFError : break for c in s : if c in char_count : char_count[c]+=1 for char,count in char_count.items(): print("{}:{:d}".format(char,count)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var char_list : String := "abcdefghijklmnopqrstuvwxyz" ; var char_count : OclAny := Set{} ; for c : char_list->characters() do ( char_count[c+1] := 0) ; var s : String := "" ; while true do ( try ( s := s + input()->toLowerCase()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))) ; for c : s->characters() do ( if (char_count)->includes(c) then ( char_count[c+1] := char_count[c+1] + 1 ) else skip) ; for _tuple : char_count->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var char : OclAny := _tuple->at(_indx); _indx := _indx + 1; var count : OclAny := _tuple->at(_indx); execute (StringLib.interpolateStrings("{}:{:d}", Sequence{char, count}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=input() length=len(n) minval=10000 for i in range(length-1): n1=n[i] for j in range(i+1,length): n2=n[j] if int(n1+n2)% 25==0 : val=length-i-2 if valtoInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : String := (OclFile["System.in"]).readLine() ; var length : int := (n)->size() ; var minval : int := 10000 ; for i : Integer.subrange(0, length - 1-1) do ( var n1 : OclAny := n[i+1] ; for j : Integer.subrange(i + 1, length-1) do ( var n2 : OclAny := n[j+1] ; if ("" + ((n1 + n2)))->toInteger() mod 25 = 0 then ( var val : double := length - i - 2 ; if (val->compareTo(minval)) < 0 then ( minval := val ) else skip ) else skip)) ; execute (minval)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- b=[0 for i in range(28)] d={"a" : 1,"b" : 2,"c" : 3,"d" : 4,"e" : 5,"f" : 6,"g" : 7,"h" : 8,"i" : 9,"j" : 10,"k" : 11,"l" : 12,"m" : 13,"n" : 14,"o" : 15,"p" : 16,"q" : 17,"r" : 18,"s" : 19,"t" : 20,"u" : 21,"v" : 22,"w" : 23,"x" : 24,"y" : 25,"z" : 26} while(True): try : a=input() except : break if a=="" : break a=str.lower(a) a=list(a) for i in a : if i in d : b[d[i]-1]=b[d[i]-1]+1 for key in d : print(key,b[d[key]-1],sep=" : ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var b : Sequence := Integer.subrange(0, 28-1)->select(i | true)->collect(i | (0)) ; var d : Map := Map{ "a" |-> 1 }->union(Map{ "b" |-> 2 }->union(Map{ "c" |-> 3 }->union(Map{ "d" |-> 4 }->union(Map{ "e" |-> 5 }->union(Map{ "f" |-> 6 }->union(Map{ "g" |-> 7 }->union(Map{ "h" |-> 8 }->union(Map{ "i" |-> 9 }->union(Map{ "j" |-> 10 }->union(Map{ "k" |-> 11 }->union(Map{ "l" |-> 12 }->union(Map{ "m" |-> 13 }->union(Map{ "n" |-> 14 }->union(Map{ "o" |-> 15 }->union(Map{ "p" |-> 16 }->union(Map{ "q" |-> 17 }->union(Map{ "r" |-> 18 }->union(Map{ "s" |-> 19 }->union(Map{ "t" |-> 20 }->union(Map{ "u" |-> 21 }->union(Map{ "v" |-> 22 }->union(Map{ "w" |-> 23 }->union(Map{ "x" |-> 24 }->union(Map{ "y" |-> 25 }->union(Map{ "z" |-> 26 }))))))))))))))))))))))))) ; while (true) do ( try ( var a : String := (OclFile["System.in"]).readLine()) catch (_e : OclException) do ( break) ; if a = "" then ( break ) else skip ; a := ("" + (->toLowerCase())) ; a := (a)->characters() ; for i : a->characters() do ( if (d)->includes(i) then ( b[d[i+1] - 1+1] := b[d[i+1] - 1+1] + 1 ) else skip)) ; for key : d->keys() do ( execute (key)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys cnt={} for line in sys.stdin : for l in line : if l.isalpha(): c=l.lower() cnt[c]=cnt.get(c,0)+1 for i in range(26): c=chr(ord('a')+i) print(c," : ",cnt.get(c,0),sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var cnt : OclAny := Set{} ; for line : OclFile["System.in"] do ( for l : line do ( if l->matches("[a-zA-Z]*") then ( var c : String := l->toLowerCase() ; cnt->at(c) := cnt.get(c, 0) + 1 ) else skip)) ; for i : Integer.subrange(0, 26-1) do ( c := (('a')->char2byte() + i)->byte2char() ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def existsTriplet(a,b,c,x,l1,l2,l3): if(l2<=l1 and l2<=l3): l1,l2=l2,l1 a,b=b,a elif(l3<=l1 and l3<=l2): l1,l3=l3,l1 a,c=c,a for i in range(l1): j=0 k=l3-1 while(j=0): if(a[i]+b[j]+c[k]==x): return True if(a[i]+b[j]+c[k]union(Sequence{7}->union(Sequence{8}->union(Sequence{10}->union(Sequence{ 15 })))) ; b := Sequence{1}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 8 }))) ; c := Sequence{4}->union(Sequence{5}->union(Sequence{ 5 })) ; l1 := (a)->size() ; l2 := (b)->size() ; l3 := (c)->size() ; x := 14 ; if (existsTriplet(a, b, c, x, l1, l2, l3)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation existsTriplet(a : OclAny, b : OclAny, c : OclAny, x : OclAny, l1 : OclAny, l2 : OclAny, l3 : OclAny) : OclAny pre: true post: true activity: if ((l2->compareTo(l1)) <= 0 & (l2->compareTo(l3)) <= 0) then ( Sequence{l1,l2} := Sequence{l2,l1} ; Sequence{a,b} := Sequence{b,a} ) else (if ((l3->compareTo(l1)) <= 0 & (l3->compareTo(l2)) <= 0) then ( Sequence{l1,l3} := Sequence{l3,l1} ; Sequence{a,c} := Sequence{c,a} ) else skip) ; for i : Integer.subrange(0, l1-1) do ( var j : int := 0 ; var k : double := l3 - 1 ; while ((j->compareTo(l2)) < 0 & k >= 0) do ( if (a[i+1] + b[j+1] + c[k+1] = x) then ( return true ) else skip ; if ((a[i+1] + b[j+1] + c[k+1]->compareTo(x)) < 0) then ( j := j + 1 ) else ( k := k - 1 ))) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSetBits(n): count=0 while n : count+=1 n &=(n-1) return count def FlippedCount(a,b): return countSetBits(a ^ b) a=10 b=20 print(FlippedCount(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 10 ; b := 20 ; execute (FlippedCount(a, b))->display(); operation countSetBits(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while n do ( count := count + 1 ; n := n & (n - 1)) ; return count; operation FlippedCount(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return countSetBits(MathLib.bitwiseXor(a, b)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w="" try : for _ in range(5): w+=input().lower() except EOFError : pass ch=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"] for chkspell in ch : print("{}:{}".format(chkspell,w.count(chkspell))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : String := "" ; try ( for _anon : Integer.subrange(0, 5-1) do ( w := w + input()->toLowerCase())) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt pass))))) ; var ch : Sequence := Sequence{"a"}->union(Sequence{"b"}->union(Sequence{"c"}->union(Sequence{"d"}->union(Sequence{"e"}->union(Sequence{"f"}->union(Sequence{"g"}->union(Sequence{"h"}->union(Sequence{"i"}->union(Sequence{"j"}->union(Sequence{"k"}->union(Sequence{"l"}->union(Sequence{"m"}->union(Sequence{"n"}->union(Sequence{"o"}->union(Sequence{"p"}->union(Sequence{"q"}->union(Sequence{"r"}->union(Sequence{"s"}->union(Sequence{"t"}->union(Sequence{"u"}->union(Sequence{"v"}->union(Sequence{"w"}->union(Sequence{"x"}->union(Sequence{"y"}->union(Sequence{ "z" }))))))))))))))))))))))))) ; for chkspell : ch do ( execute (StringLib.interpolateStrings("{}:{}", Sequence{chkspell, w->count(chkspell)}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=map(int,input().split()) a=[tuple(map(int,input().split()))for _ in range(n)] print(max([a[i][1]/a[i][0]for i in range(n)])*t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; execute ((Integer.subrange(0, n-1)->select(i | true)->collect(i | (a[i+1][1+1] / a[i+1]->first())))->max() * t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,t=[int(i)for i in input().split()] r=0.0 for l in range(N): x,h=[float(i)for i in input().split()] r=max(r,h/x) print(float(t)*r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var t : OclAny := null; Sequence{N,t} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var r : double := 0.0 ; for l : Integer.subrange(0, N-1) do ( var x : OclAny := null; var h : OclAny := null; Sequence{x,h} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toReal())) ; r := Set{r, h / x}->max()) ; execute (("" + ((t)))->toReal() * r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=map(int,input().split()) lsx=[] lsh=[] for i in range(n): x,h=map(int,input().split()) lsx.append(x) lsh.append(h) tam=0 for j in range(n): if lsh[j]/lsx[j]>tam : tam=lsh[j]/lsx[j] print(t*tam) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lsx : Sequence := Sequence{} ; var lsh : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var h : OclAny := null; Sequence{x,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((x) : lsx) ; execute ((h) : lsh)) ; var tam : int := 0 ; for j : Integer.subrange(0, n-1) do ( if (lsh[j+1] / lsx[j+1]->compareTo(tam)) > 0 then ( tam := lsh[j+1] / lsx[j+1] ) else skip) ; execute (t * tam)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,t=[int(e)for e in input().split()] ts=[[int(e)for e in input().split()]for _ in range(N)] result=0 for x,h in ts : r=h*t/x result=max(result,r) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var t : OclAny := null; Sequence{N,t} := input().split()->select(e | true)->collect(e | (("" + ((e)))->toInteger())) ; var ts : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (input().split()->select(e | true)->collect(e | (("" + ((e)))->toInteger())))) ; var result : int := 0 ; for _tuple : ts do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var h : OclAny := _tuple->at(_indx); var r : double := h * t / x ; result := Set{result, r}->max()) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,t=map(int,input().split()) angle=0 for _ in range(n): x,h=map(int,input().split()) tmp=math.atan2(h,x) if tmp>angle : angle=tmp y=math.tan(angle)*t print(y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var angle : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var h : OclAny := null; Sequence{x,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var tmp : OclAny := ; if (tmp->compareTo(angle)) > 0 then ( angle := tmp ) else skip) ; var y : double := (angle)->tan() * t ; execute (y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : t-=1 s=input() stack=[] chuc05=["5","0"] check0050=0 check2575=0 pos5=0 pos0=0 pos27=0 pos05=0 chuc27=["2","7"] for i in range(0,len(s)): j=len(s)-1-i if s[j]=='0' and check0050==0 : pos0=j check0050=1 continue if check0050==1 and s[j]in chuc05 : if jtoInteger() ; while t > 0 do ( t := t - 1 ; var s : String := (OclFile["System.in"]).readLine() ; var stack : Sequence := Sequence{} ; var chuc05 : Sequence := Sequence{"5"}->union(Sequence{ "0" }) ; var check0050 : int := 0 ; var check2575 : int := 0 ; var pos5 : int := 0 ; var pos0 : int := 0 ; var pos27 : int := 0 ; var pos05 : int := 0 ; var chuc27 : Sequence := Sequence{"2"}->union(Sequence{ "7" }) ; for i : Integer.subrange(0, (s)->size()-1) do ( var j : double := (s)->size() - 1 - i ; if s[j+1] = '0' & check0050 = 0 then ( pos0 := j ; check0050 := 1 ; continue ) else skip ; if check0050 = 1 & (chuc05)->includes(s[j+1]) then ( if (j->compareTo(pos0)) < 0 then ( pos05 := j ; check0050 := 2 ) else skip ; continue ) else skip ; if s[j+1] = '5' & check2575 = 0 then ( pos0 := j ; check2575 := 1 ; continue ) else skip ; if check2575 = 1 & (chuc27)->includes(s[j+1]) then ( if (j->compareTo(pos0)) < 0 then ( pos27 := j ; check2575 := 2 ; continue ) else skip ) else skip) ; var ans1 : double := (s)->size() - pos05 - 2 ; var ans2 : double := (s)->size() - pos27 - 2 ; execute (Set{ans1, ans2}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=map(int,input().split()) arr=list(map(int,input().split())) def f(arr): original=set(arr) narr=list(map(lambda i : i & x,arr)) if len(arr)>len(original): print(0) else : mapping={} for i in range(n): mapping[arr[i]]=i for i in range(n): if arr[i]& x in original and i!=mapping[arr[i]& x]: print(1) return if len(narr)>len(set(narr)): print(2) else : print(-1) f(arr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; f(arr); operation f(arr : OclAny) pre: true post: true activity: var original : Set := Set{}->union((arr)) ; var narr : Sequence := ((arr)->collect( _x | (lambda i : OclAny in (MathLib.bitwiseAnd(i, x)))->apply(_x) )) ; if ((arr)->size()->compareTo((original)->size())) > 0 then ( execute (0)->display() ) else ( var mapping : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( mapping[arr[i+1]+1] := i) ; for i : Integer.subrange(0, n-1) do ( if (original)->includes(MathLib.bitwiseAnd(arr[i+1], x)) & i /= mapping[MathLib.bitwiseAnd(arr[i+1], x)+1] then ( execute (1)->display() ; return ) else skip) ; if ((narr)->size()->compareTo((Set{}->union((narr)))->size())) > 0 then ( execute (2)->display() ) else ( execute (-1)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def process(k,x): p=k & x if p==k : return False,k else : return True,p def main(): n,x=map(int,input().split()) a=list(map(int,input().split())) if n<2 : print(-1) return b=[] for num in a : b.append((num,1)) p=num & x if p==num : continue else : b.append((p,0)) b=sorted(b,key=lambda t :(t[0],-t[1])) last_p=b[0][0] current_op=2-b[0][1] min_op=10 for i in b[1 :]: if i[0]==last_p : current_op-=i[1] min_op=min(min_op,current_op) if min_op==0 : break else : last_p=i[0] current_op=2-i[1] if min_op==10 : print(-1) else : print(min_op) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation process(k : OclAny, x : OclAny) : OclAny pre: true post: true activity: var p : int := MathLib.bitwiseAnd(k, x) ; if p = k then ( return false, k ) else ( return true, p ); operation main() pre: true post: true activity: var n : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n < 2 then ( execute (-1)->display() ; return ) else skip ; var b : Sequence := Sequence{} ; for num : a do ( execute ((Sequence{num, 1}) : b) ; p := MathLib.bitwiseAnd(num, x) ; if p = num then ( continue ) else ( execute ((Sequence{p, 0}) : b) )) ; b := b->sortedBy($x | (lambda t : OclAny in (Sequence{t->first(), -t[1+1]}))->apply($x)) ; var last_p : OclAny := b->first()->first() ; var current_op : double := 2 - b->first()[1+1] ; var min_op : int := 10 ; for i : b->tail() do ( if i->first() = last_p then ( current_op := current_op - i[1+1] ; min_op := Set{min_op, current_op}->min() ; if min_op = 0 then ( break ) else skip ) else ( last_p := i->first() ; current_op := 2 - i[1+1] )) ; if min_op = 10 then ( execute (-1)->display() ) else ( execute (min_op)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def process(k,x): p=k & x if p==k : return False,k else : return True,p def main(): n,x=map(int,input().split()) a=list(map(int,input().split())) if n<2 : print(-1) return b=[] for num in a : b.append((num,1)) p=num & x if p==num : continue else : b.append((p,0)) b=sorted(b,key=lambda t :(t[0],-t[1])) last_p=b[0][0] current_op=2-b[0][1] min_op=10 for i in b[1 :]: if i[0]==last_p : current_op-=i[1] min_op=min(min_op,current_op) if min_op==0 : break else : last_p=i[0] current_op=2-i[1] if min_op==10 : print(-1) else : print(min_op) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation process(k : OclAny, x : OclAny) : OclAny pre: true post: true activity: var p : int := MathLib.bitwiseAnd(k, x) ; if p = k then ( return false, k ) else ( return true, p ); operation main() pre: true post: true activity: var n : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n < 2 then ( execute (-1)->display() ; return ) else skip ; var b : Sequence := Sequence{} ; for num : a do ( execute ((Sequence{num, 1}) : b) ; p := MathLib.bitwiseAnd(num, x) ; if p = num then ( continue ) else ( execute ((Sequence{p, 0}) : b) )) ; b := b->sortedBy($x | (lambda t : OclAny in (Sequence{t->first(), -t[1+1]}))->apply($x)) ; var last_p : OclAny := b->first()->first() ; var current_op : double := 2 - b->first()[1+1] ; var min_op : int := 10 ; for i : b->tail() do ( if i->first() = last_p then ( current_op := current_op - i[1+1] ; min_op := Set{min_op, current_op}->min() ; if min_op = 0 then ( break ) else skip ) else ( last_p := i->first() ; current_op := 2 - i[1+1] )) ; if min_op = 10 then ( execute (-1)->display() ) else ( execute (min_op)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,x=map(int,input().split()) w=list(map(int,input().split())) a=set(w) if len(a)collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Set := Set{}->union((w)) ; if ((a)->size()->compareTo(n)) < 0 then ( execute (0)->display() ) else ( var d : Sequence := w->select(i | MathLib.bitwiseAnd(i, x) /= i)->collect(i | (MathLib.bitwiseAnd(i, x))) ; var b : Set := Set{}->union((d)) ; if MathLib.bitwiseAnd(b, a) then ( execute (1)->display() ) else ( if ((b)->size()->compareTo((d)->size())) < 0 then ( execute (2)->display() ) else ( execute (-1)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[0]+list(map(int,input().split())) l=1 ans=1 for i in range(n): if a[i+1]<=a[i]*2 : ans+=1 l=max(l,ans) else : ans=1 print(l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var l : int := 1 ; var ans : int := 1 ; for i : Integer.subrange(0, n-1) do ( if (a[i + 1+1]->compareTo(a[i+1] * 2)) <= 0 then ( ans := ans + 1 ; l := Set{l, ans}->max() ) else ( ans := 1 )) ; execute (l)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=[int(x)for x in input().split()] a=[int(x)for x in input().split()] s,t=set(),set() ans=3 for i in a : if i in s : ans=min(ans,0) elif i in t : ans=min(ans,1) elif i & x in s : ans=min(ans,1) elif i & x in t : ans=min(ans,2) s.add(i) t.add(i & x) print(ans if ans<3 else-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := Sequence{Set{}->union(()),Set{}->union(())} ; var ans : int := 3 ; for i : a do ( if (s)->includes(i) then ( ans := Set{ans, 0}->min() ) else (if (t)->includes(i) then ( ans := Set{ans, 1}->min() ) else (if (s)->includes(MathLib.bitwiseAnd(i, x)) then ( ans := Set{ans, 1}->min() ) else (if (t)->includes(MathLib.bitwiseAnd(i, x)) then ( ans := Set{ans, 2}->min() ) else skip ) ) ) ; execute ((i) : s) ; execute ((MathLib.bitwiseAnd(i, x)) : t)) ; execute (if ans < 3 then ans else -1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count(n,x): cnt=0 for i in range(1,n+1): if i<=x : if x//i<=n and x % i==0 : cnt+=1 return cnt n=8 x=24 print(count(n,x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 8 ; x := 24 ; execute (count(n, x))->display(); operation count(n : OclAny, x : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( if (i->compareTo(x)) <= 0 then ( if (x div i->compareTo(n)) <= 0 & x mod i = 0 then ( cnt := cnt + 1 ) else skip ) else skip) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMaximumNum(st,n,k): for i in range(n): if(k<1): break if(st[i]!='9'): st=st[0 : i]+'9'+st[i+1 :] k-=1 return st st="569431" n=len(st) k=3 print(findMaximumNum(st,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; st := "569431" ; n := (st)->size() ; k := 3 ; execute (findMaximumNum(st, n, k))->display(); operation findMaximumNum(st : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if (k < 1) then ( break ) else skip ; if (st[i+1] /= '9') then ( st := st.subrange(0+1, i) + '9' + st.subrange(i + 1+1) ; k := k - 1 ) else skip) ; return st; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: n=int(s); k=0--n//4 ; print('9'*(n-k)+'8'*k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var n : int := ("" + ((s)))->toInteger(); var k : double := 0 - -n div 4; execute (StringLib.nCopies('9', (n - k)) + StringLib.nCopies('8', k))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil for i in range(int(input())): n=int(input()) print("9"*(n-ceil((n)/4))+"8"*(ceil((n)/4))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (StringLib.nCopies("9", (n - ceil((n) / 4))) + StringLib.nCopies("8", (ceil((n) / 4))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def _input(): return map(int,input().split()) a,b=_input() if abs(a-b)>1 or(a==0 and b==0): print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := _input() ; if (a - b)->abs() > 1 or (a = 0 & b = 0) then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(0,int(input())): n=int(input()) f=-(-n//4) o=n-f print("9"*o+"8"*f) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var f : int := -(-n div 4) ; var o : double := n - f ; execute (StringLib.nCopies("9", o) + StringLib.nCopies("8", f))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math t=int(input()) r=[] for i in range(t): n=int(input()) b=math.ceil(n/4) a=['9']*(n-b) c=['8']*b a=a+c ac="".join(a) r.append(ac) for i in range(len(r)): print(r[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : double := (n / 4)->ceil() ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ '9' }, (n - b)) ; var c : Sequence := MatrixLib.elementwiseMult(Sequence{ '8' }, b) ; a := a->union(c) ; var ac : String := StringLib.sumStringsWithSeparator((a), "") ; execute ((ac) : r)) ; for i : Integer.subrange(0, (r)->size()-1) do ( execute (r[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for _ in[0]*int(input()): n=int(input()) times=int(math.ceil(n/4)) print((n-times)*'9'+times*'8') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var times : int := ("" + (((n / 4)->ceil())))->toInteger() ; execute ((n - times) * '9' + times * '8')->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math result=["x",-math.inf] for x in range(int(input())): l=[int(x)if x.isnumeric()else x for x in input().split()] target=(sum(l[3 :])+100*l[1]-50*l[2]) if result[1]union(Sequence{ - }) ; for x : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var l : Sequence := input().split()->select(x | true)->collect(x | (if x->matches("[0-9]*") then ("" + ((x)))->toInteger() else x endif)) ; var target : double := ((l.subrange(3+1))->sum() + 100 * l[1+1] - 50 * l[2+1]) ; if (result[1+1]->compareTo(target)) < 0 then ( result := Sequence{l->first()}->union(Sequence{ target }) ) else skip) ; execute (result->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- participants=int(input()) participants_points={} for i in range(participants): participant_infor=input().split() nickname=participant_infor[0] successful_hacks=int(participant_infor[1]) unsuccessful_hacks=int(participant_infor[2]) points_problem_A=int(participant_infor[3]) points_problem_B=int(participant_infor[4]) points_problem_C=int(participant_infor[5]) points_problem_D=int(participant_infor[6]) points_problem_E=int(participant_infor[7]) participants_points[nickname]=(successful_hacks*100-50*unsuccessful_hacks+points_problem_A+points_problem_B+points_problem_C+points_problem_D+points_problem_E) for nickname,points in participants_points.items(): if points==max(participants_points.values()): print(nickname) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var participants : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var participants_points : OclAny := Set{} ; for i : Integer.subrange(0, participants-1) do ( var participant_infor : OclAny := input().split() ; var nickname : OclAny := participant_infor->first() ; var successful_hacks : int := ("" + ((participant_infor[1+1])))->toInteger() ; var unsuccessful_hacks : int := ("" + ((participant_infor[2+1])))->toInteger() ; var points_problem_A : int := ("" + ((participant_infor[3+1])))->toInteger() ; var points_problem_B : int := ("" + ((participant_infor[4+1])))->toInteger() ; var points_problem_C : int := ("" + ((participant_infor[5+1])))->toInteger() ; var points_problem_D : int := ("" + ((participant_infor[6+1])))->toInteger() ; var points_problem_E : int := ("" + ((participant_infor[7+1])))->toInteger() ; participants_points[nickname+1] := (successful_hacks * 100 - 50 * unsuccessful_hacks + points_problem_A + points_problem_B + points_problem_C + points_problem_D + points_problem_E)) ; for _tuple : participants_points->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var nickname : OclAny := _tuple->at(_indx); _indx := _indx + 1; var points : OclAny := _tuple->at(_indx); if points = (participants_points.values())->max() then ( execute (nickname)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) ans=1 l=[] for i in range(0,n-1): if a[i]*2>=a[i+1]: ans=ans+1 else : l.append(ans) ans=1 l.append(ans) print(max(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 1 ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( if (a[i+1] * 2->compareTo(a[i + 1+1])) >= 0 then ( ans := ans + 1 ) else ( execute ((ans) : l) ; ans := 1 )) ; execute ((ans) : l) ; execute ((l)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() a=[] for s in[*open(0)][1 :]: s=s.split() a+=[[s[0],*map(int,s[1 :])]] print(max(a,key=lambda x : x[1]*100-x[2]*50+sum(x[3 :]))[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var a : Sequence := Sequence{} ; for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var s : OclAny := s.split() ; a := a + Sequence{ Sequence{s->first()}->union((s->tail())->collect( _x | (OclType["int"])->apply(_x) )) }) ; execute (max(a, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (expr (expr (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) * (expr (atom (number (integer 100))))) - (expr (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ]))) * (expr (atom (number (integer 50)))))) + (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 3))))))) :)) ])))))))) )))))))))))->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=False for a in range(int(input())): name,*pts=input().split() amn=0 for j in range(7): pts[j]=int(pts[j]) if j==0 : pts[j]*=100 if j==1 : pts[j]*=-50 amn+=pts[j] if not t : best=amn best_name=name t=True else : if amn>best : best_name=name best=amn print(best_name) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : boolean := false ; for a : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var name : OclAny := null; var pts : OclAny := null; Sequence{name,pts} := input().split() ; var amn : int := 0 ; for j : Integer.subrange(0, 7-1) do ( pts[j+1] := ("" + ((pts[j+1])))->toInteger() ; if j = 0 then ( pts[j+1] := pts[j+1] * 100 ) else skip ; if j = 1 then ( pts[j+1] := pts[j+1] * -50 ) else skip ; amn := amn + pts[j+1]) ; if not(t) then ( var best : int := amn ; var best_name : int := name ; t := true ) else ( if (amn->compareTo(best)) > 0 then ( best_name := name ; best := amn ) else skip )) ; execute (best_name)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) d={} for i in range(n): l=[str(x)for x in input().split()] points=(int(l[1])*100)-(int(l[2])*50)+int(l[3])+int(l[4])+int(l[5])+int(l[6])+int(l[7]) d[l[0]]=points m=max(d.values()) for i in d : if d[i]==m : print(i) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var l : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x))))) ; var points : double := (("" + ((l[1+1])))->toInteger() * 100) - (("" + ((l[2+1])))->toInteger() * 50) + ("" + ((l[3+1])))->toInteger() + ("" + ((l[4+1])))->toInteger() + ("" + ((l[5+1])))->toInteger() + ("" + ((l[6+1])))->toInteger() + ("" + ((l[7+1])))->toInteger() ; d[l->first()+1] := points) ; var m : OclAny := (d.values())->max() ; for i : d do ( if d[i+1] = m then ( execute (i)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) b=86400 list=[int(num)for num in input().split()] j=0 ; k=0 while(j=m): print(j+1) break else : j+=1 continue ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : int := 86400 ; var OclType["Sequence"] : Sequence := input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var j : int := 0; var k : int := 0 ; while ((j->compareTo(n)) < 0) do ( var c : double := b - [j+1] ; k := k + c ; if ((k->compareTo(m)) >= 0) then ( execute (j + 1)->display() ; break ) else ( j := j + 1 ; continue )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) for i in range(N): num=list(input()) a=num.copy() b=num.copy() ans_1=0 ans_2=0 try : while a[-1]!='0' : a.pop(-1) ans_1+=1 while a[-2]!='0' and a[-2]!='5' : a.pop(-2) ans_1+=1 except : pass try : while b[-1]!='5' : b.pop(-1) ans_2+=1 while b[-2]!='2' and b[-2]!='7' : b.pop(-2) ans_2+=1 except : pass print(min(ans_1,ans_2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, N-1) do ( var num : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var a : OclAny := num->copy() ; var b : OclAny := num->copy() ; var ans var num : Sequence := ((OclFile["System.in"]).readLine())->characters() : int := 0 ; var ans:= 0 : int := 0 ; try ( while a->last() /= '0' do ( a := a->excludingAt(-1+1) ; ans a := a->excludingAt(-1+1) := ans a := a->excludingAt(-1+1) + 1) ; while a->front()->last() /= '0' & a->front()->last() /= '5' do ( a := a->excludingAt(-2+1) ; ans a := a->excludingAt(-2+1) := ans a := a->excludingAt(-2+1) + 1)) catch (_e : OclException) do ( skip) ; try ( while b->last() /= '5' do ( b := b->excludingAt(-1+1) ; ans + 1 := ans + 1 + 1) ; while b->front()->last() /= '2' & b->front()->last() /= '7' do ( b := b->excludingAt(-2+1) ; ans + 1 := ans + 1 + 1)) catch (_e : OclException) do ( skip) ; execute (Set{ans(ans(ansSet{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ansSet{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ansSet{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ansSet{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ansSet{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ansSet{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ansSet{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ans var num : Sequence := ((OclFile["System.in"]).readLine())->characters(), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min(), ans_2), ans_2), ans_2}->min())->display(), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min(), ans_2), ans_2), ans_2}->min())->display(), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min(), ans_2), ans_2), ans_2}->min())->display(), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min(), ans_2), ans_2), ans_2}->min())->display(), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min(), ans_2), ans_2), ans_2}->min())->display(), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min(), ans_2), ans_2), ans_2}->min())->display(), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min(), ans_2), ans_2), ans_2}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import* from decimal import* def _input(): return map(int,input().split()) def _list(): return list(map(int,input().split())) def solves(): n,m=_input() lst=_list() ans=0 ; for i in range(n): lst[i]=86400-lst[i] m-=lst[i] if(m<=0): print(i+1) exit() print(-1) t=1 for _ in range(0,t): solves() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solves()); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation _list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation solves() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := _input() ; var lst : OclAny := _list() ; var ans : int := 0; ; for i : Integer.subrange(0, n-1) do ( lst[i+1] := 86400 - lst[i+1] ; m := m - lst[i+1] ; if (m <= 0) then ( execute (i + 1)->display() ; exit() ) else skip) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) l=[int(i)for i in input().split()] count=0 for i in range(len(l)): count+=(86400-l[i]) if count>=m : print(i+1) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var count : int := 0 ; for i : Integer.subrange(0, (l)->size()-1) do ( count := count + (86400 - l[i+1]) ; if (count->compareTo(m)) >= 0 then ( execute (i + 1)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- days,bookt=map(int,input().split()) time=list(map(int,input().split())) for x in range(days): lft=86400-time[x] if lft>=bookt : print(x+1) break bookt-=lft ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var days : OclAny := null; var bookt : OclAny := null; Sequence{days,bookt} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var time : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for x : Integer.subrange(0, days-1) do ( var lft : double := 86400 - time[x+1] ; if (lft->compareTo(bookt)) >= 0 then ( execute (x + 1)->display() ; break ) else skip ; bookt := bookt - lft); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=map(int,input().split()) l=list(map(int,input().split())) k=list(map(lambda x : 86400-x,l)) c=0 m=0 for i in range(n): c+=k[i] if c>=t : m=i+1 break print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k : Sequence := ((l)->collect( _x | (lambda x : OclAny in (86400 - x))->apply(_x) )) ; var c : int := 0 ; var m : int := 0 ; for i : Integer.subrange(0, n-1) do ( c := c + k[i+1] ; if (c->compareTo(t)) >= 0 then ( m := i + 1 ; break ) else skip) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np import sys C_MAX=30 max_arr_len=10 dp=np.zeros((max_arr_len,C_MAX+1)); v=np.zeros((max_arr_len,C_MAX+1)); INT_MIN=-(sys.maxsize)+1 def findMax(i,r,w,n): if(r<0): return INT_MIN ; if(i==n): return 0 ; if(v[i][r]): return dp[i][r]; v[i][r]=1 ; dp[i][r]=max(w[i]+findMax(i+1,r-w[i],w,n),findMax(i+1,r,w,n)); return dp[i][r]; def preCompute(w,n): for i in range(C_MAX,-1,-1): findMax(0,i,w,n); def ansQuery(w): return dp[0][w]; if __name__=="__main__" : w=[3,8,9]; n=len(w) preCompute(w,n); queries=[11,10,4]; q=len(queries) for i in range(q): print(ansQuery(queries[i])); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var C_MAX : int := 30 ; var max_arr_len : int := 10 ; var dp : Sequence := MatrixLib.singleValueMatrix(Sequence{max_arr_len, C_MAX + 1}, 0.0); ; var v : Sequence := MatrixLib.singleValueMatrix(Sequence{max_arr_len, C_MAX + 1}, 0.0); ; var INT_MIN : (trailer . (name maxsize)) := -((trailer . (name maxsize))) + 1 ; skip ; skip ; skip ; if __name__ = "__main__" then ( w := Sequence{3}->union(Sequence{8}->union(Sequence{ 9 })); ; n := (w)->size() ; preCompute(w, n); ; var queries : Sequence := Sequence{11}->union(Sequence{10}->union(Sequence{ 4 })); ; var q : int := (queries)->size() ; for i : Integer.subrange(0, q-1) do ( execute (ansQuery(queries[i+1]))->display();) ) else skip; operation findMax(i : OclAny, r : OclAny, w : OclAny, n : OclAny) pre: true post: true activity: if (r < 0) then ( return INT_MIN; ) else skip ; if (i = n) then ( return 0; ) else skip ; if (v[i+1][r+1]) then ( return dp[i+1][r+1]; ) else skip ; v[i+1][r+1] := 1; ; dp[i+1][r+1] := Set{w[i+1] + findMax(i + 1, r - w[i+1], w, n), findMax(i + 1, r, w, n)}->max(); ; return dp[i+1][r+1];; operation preCompute(w : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(-1 + 1, C_MAX)->reverse() do ( findMax(0, i, w, n);); operation ansQuery(w : OclAny) pre: true post: true activity: return dp->first()[w+1];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def do(n,p): t=(n//50)% 475 for i in range(25): t=(t*96+42)% 475 if(26+t==p): return True return False p,x,y=map(int,input().split()) for i in range(500): for j in range(500): if(x+100*i-50*j>=y and do(x+100*i-50*j,p)): print(i) exit() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : OclAny := null; var y : OclAny := null; Sequence{p,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, 500-1) do ( for j : Integer.subrange(0, 500-1) do ( if ((x + 100 * i - 50 * j->compareTo(y)) >= 0 & do(x + 100 * i - 50 * j, p)) then ( execute (i)->display() ; exit() ) else skip)); operation do(n : OclAny, p : OclAny) : OclAny pre: true post: true activity: var t : int := (n div 50) mod 475 ; for i : Integer.subrange(0, 25-1) do ( t := (t * 96 + 42) mod 475 ; if (26 + t = p) then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) ans=1 ; l=[] for i in range(0,n-1): if a[i]*2>=a[i+1]: ans+=1 else : l.append(ans) ans=1 l.append(ans) print(max(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 1; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( if (a[i+1] * 2->compareTo(a[i + 1+1])) >= 0 then ( ans := ans + 1 ) else ( execute ((ans) : l) ; ans := 1 )) ; execute ((ans) : l) ; execute ((l)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p,x,y=map(int,input().split()) def shirtpicking(s,test): i=(s//50)% 475 res=[] for t in range(25): i=(i*96+42)% 475 res.append(i+26) if test in res : return True else : return False if x>=y : for x1 in range((x-y)//50+1): if shirtpicking(x-x1*50,p): print(0) exit() ans=0 s=x ints=0 while ans==0 : s+=50 ints+=1 if shirtpicking(s,p): print((ints+1)//2) exit() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{p,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; if (x->compareTo(y)) >= 0 then ( for x1 : Integer.subrange(0, (x - y) div 50 + 1-1) do ( if shirtpicking(x - x1 * 50, p) then ( execute (0)->display() ; exit() ) else skip) ) else skip ; var ans : int := 0 ; s := x ; var ints : int := 0 ; while ans = 0 do ( s := s + 50 ; ints := ints + 1 ; if shirtpicking(s, p) then ( execute ((ints + 1) div 2)->display() ; exit() ) else skip); operation shirtpicking(s : OclAny, test : OclAny) : OclAny pre: true post: true activity: var i : int := (s div 50) mod 475 ; var res : Sequence := Sequence{} ; for t : Integer.subrange(0, 25-1) do ( i := (i * 96 + 42) mod 475 ; execute ((i + 26) : res)) ; if (res)->includes(test) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=99**9 p,x,y=map(int,input().split()) kat_x=x//50 kat_y=y//50 kat_high=999999990 if y>x : t=-1 res=-1 for i in range(kat_y,kat_high): if res>0 : break t+=1 k=i % 475 for _ in range(25): k=(k*96+42)% 475 if k+26==p : res=t break print((res-kat_x+1)//2) else : t=-1 res=INF if x % 50pow(9) ; var p : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{p,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var kat_x : int := x div 50 ; var kat_y : int := y div 50 ; var kat_high : int := 999999990 ; if (y->compareTo(x)) > 0 then ( var t : int := -1 ; var res : int := -1 ; for i : Integer.subrange(kat_y, kat_high-1) do ( if res > 0 then ( break ) else skip ; t := t + 1 ; var k : int := i mod 475 ; for _anon : Integer.subrange(0, 25-1) do ( k := (k * 96 + 42) mod 475 ; if k + 26 = p then ( res := t ; break ) else skip)) ; execute ((res - kat_x + 1) div 2)->display() ) else ( t := -1 ; res := INF ; if (x mod 50->compareTo(y mod 50)) < 0 then ( kat_y := kat_y + 1 ) else skip ; for i : Integer.subrange(kat_y - 1 + 1, kat_x)->reverse() do ( if res /= INF then ( break ) else skip ; t := t + 1 ; k := i mod 475 ; for _anon : Integer.subrange(0, 25-1) do ( k := (k * 96 + 42) mod 475 ; if k + 26 = p then ( res := t ; execute (0)->display() ; break ) else skip)) ; t := -1 ; if res = INF then ( var pp : boolean := true ; for i : Integer.subrange(kat_x, kat_high-1) do ( if pp = false then ( break ) else skip ; t := t + 1 ; k := i mod 475 ; for _anon : Integer.subrange(0, 25-1) do ( k := (k * 96 + 42) mod 475 ; if k + 26 = p then ( res := Set{res, t}->min() ; pp := false ; break ) else skip)) ; execute ((res + 1) div 2)->display() ) else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p,x,y=map(int,input().split()) def check(s): i=(s//50)% 475 for t in range(25): i=(i*96+42)% 475 if 26+i==p : return True return False for up in range(500): for down in range(500): if x+100*up-50*down>=y and check(x+100*up-50*down): print(up) exit() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{p,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; for up : Integer.subrange(0, 500-1) do ( for down : Integer.subrange(0, 500-1) do ( if (x + 100 * up - 50 * down->compareTo(y)) >= 0 & check(x + 100 * up - 50 * down) then ( execute (up)->display() ; exit() ) else skip)); operation check(s : OclAny) : OclAny pre: true post: true activity: var i : int := (s div 50) mod 475 ; for t : Integer.subrange(0, 25-1) do ( i := (i * 96 + 42) mod 475 ; if 26 + i = p then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=input() length=len(n) minval=10000 for i in range(length-1): n1=n[i] for j in range(i+1,length): n2=n[j] if int(n1+n2)% 25==0 : val=length-i-2 if valtoInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : String := (OclFile["System.in"]).readLine() ; var length : int := (n)->size() ; var minval : int := 10000 ; for i : Integer.subrange(0, length - 1-1) do ( var n1 : OclAny := n[i+1] ; for j : Integer.subrange(i + 1, length-1) do ( var n2 : OclAny := n[j+1] ; if ("" + ((n1 + n2)))->toInteger() mod 25 = 0 then ( var val : double := length - i - 2 ; if (val->compareTo(minval)) < 0 then ( minval := val ) else skip ) else skip)) ; execute (minval)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys MOD=1000000007 def inp(): return sys.stdin.readline().strip() def ii(): return int(inp()) def iis(): return[int(i)for i in inp().split()] p,x,y=iis() def checker(s): i=(s//50)% 475 for _ in range(25): i=(i*96+42)% 475 if 26+i==p : return True return False def solve(): cnt=0 for successful in range(200): for unsuccessful in range(400): new_x=x+100*successful-50*unsuccessful if new_x>=y and checker(new_x): return cnt cnt+=1 print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MOD : int := 1000000007 ; skip ; skip ; skip ; var p : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{p,x,y} := iis() ; skip ; skip ; execute (solve())->display(); operation inp() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation ii() : OclAny pre: true post: true activity: return ("" + ((inp())))->toInteger(); operation iis() : OclAny pre: true post: true activity: return inp().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation checker(s : OclAny) : OclAny pre: true post: true activity: var i : int := (s div 50) mod 475 ; for _anon : Integer.subrange(0, 25-1) do ( i := (i * 96 + 42) mod 475 ; if 26 + i = p then ( return true ) else skip) ; return false; operation solve() : OclAny pre: true post: true activity: var cnt : int := 0 ; for successful : Integer.subrange(0, 200-1) do ( for unsuccessful : Integer.subrange(0, 400-1) do ( var new_x : double := x + 100 * successful - 50 * unsuccessful ; if (new_x->compareTo(y)) >= 0 & checker(new_x) then ( return cnt ) else skip) ; cnt := cnt + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) case=list(map(int,input().split())) for x in range(n): if case[x]<0 : case[x]*=-1 for x in range(n): if x % 2==0 : case[x]*=-1 else : continue case=list(map(str,case)) print(" ".join(case)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var case : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for x : Integer.subrange(0, n-1) do ( if case[x+1] < 0 then ( case[x+1] := case[x+1] * -1 ) else skip) ; for x : Integer.subrange(0, n-1) do ( if x mod 2 = 0 then ( case[x+1] := case[x+1] * -1 ) else ( continue )) ; case := ((case)->collect( _x | (OclType["String"])->apply(_x) )) ; execute (StringLib.sumStringsWithSeparator((case), " "))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in[0]*int(input()): n=int(input()) *a,=map(int,input().split()) for i in range(n): print(abs(a[i])*(-1)**(i % 2),end=' ') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; (testlist_star_expr (star_expr * (expr (atom (name a)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name a)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def _input(): return map(int,input().split()) for _ in range(int(input())): n=int(input()) lst=list(_input()) i=0 while i0 : print(-lst[i],end=' ') else : print(lst[i],end=' ') else : if lst[i]<0 : print(-lst[i],end=' ') else : print(lst[i],end=' ') i+=1 print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := (_input()) ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( if i mod 2 = 0 then ( if lst[i+1] > 0 then ( execute (-lst[i+1])->display() ) else ( execute (lst[i+1])->display() ) ) else ( if lst[i+1] < 0 then ( execute (-lst[i+1])->display() ) else ( execute (lst[i+1])->display() ) ) ; i := i + 1) ; execute (->display()); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Solve(): for t in range(int(input())): n=int(input()) b=list(map(int,input().split())) for i in range(n-1): if i % 2==0 : if b[i]<0 : b[i]=-b[i] if b[i+1]>0 : b[i+1]=-b[i+1] else : if b[i]>0 : b[i]=-b[i] if b[i+1]<0 : b[i+1]=-b[i+1] print(*b) if __name__=="__main__" : Solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Solve() ) else skip; operation Solve() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n - 1-1) do ( if i mod 2 = 0 then ( if b[i+1] < 0 then ( b[i+1] := -b[i+1] ) else skip ; if b[i + 1+1] > 0 then ( b[i + 1+1] := -b[i + 1+1] ) else skip ) else ( if b[i+1] > 0 then ( b[i+1] := -b[i+1] ) else skip ; if b[i + 1+1] < 0 then ( b[i + 1+1] := -b[i + 1+1] ) else skip )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name b))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) a=list(map(int,input().split())) for j in range(n): if j % 2==0 and a[j]<0 : a[j]=-a[j] elif j % 2==1 and a[j]>0 : a[j]=-a[j] print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, n-1) do ( if j mod 2 = 0 & a[j+1] < 0 then ( a[j+1] := -a[j+1] ) else (if j mod 2 = 1 & a[j+1] > 0 then ( a[j+1] := -a[j+1] ) else skip)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- homa,k=map(int,input().split()) type_k=tuple(map(int,input().split())) if min(type_k)>homa or not homa : print(1,0) elif homa in type_k : print(type_k.index(homa)+1,1) elif 1 in type_k : print(type_k.index(1)+1,homa) else : slv=dict() max_2=min(type_k) for_ind=type_k.index(max_2)+1 for i,v in enumerate(type_k): if v>homa : continue elif v>homa//2 : if v>max_2 : max_2=v for_ind=i+1 else : slv[v]=i+1 slv[max_2]=for_ind amn,ost=divmod(homa,max_2) num=max_2 for j in slv.keys(): if not ost : break t1,t2=divmod(homa,j) if t2collect( _x | (OclType["int"])->apply(_x) ) ; var type_k : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if ((type_k)->min()->compareTo(homa)) > 0 or not(homa) then ( execute (1)->display() ) else (if (type_k)->includes(homa) then ( execute (type_k->indexOf(homa) - 1 + 1)->display() ) else (if (type_k)->includes(1) then ( execute (type_k->indexOf(1) - 1 + 1)->display() ) else ( var slv : Map := (arguments ( )) ; var max:= (type_k)->min() : OclAny := (type_k)->min() ; var for_ind : int := type_k->indexOf(max1) - 1 + 1 ; for _tuple : Integer.subrange(1, (type_k)->size())->collect( _indx | Sequence{_indx-1, (type_k)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if (v->compareTo(homa)) > 0 then ( continue ) else (if (v->compareTo(homa div 2)) > 0 then ( if (v->compareTo(max max:= v := v ; for_ind := i + 1)) > 0 then ( max:= v := v ; for_ind := i + 1 ) else skip ) else ( slv[v+1] := i + 1 ) ) ) ; slv[max:= for_ind+1] := for_ind ; var amn : OclAny := null; var ost : OclAny := null; Sequence{amn,ost} := Sequence{(homa div max_2), (homa mod max_2)} ; var num : OclAny := max_2 ; for j : slv.keys() do ( if not(ost) then ( break ) else skip ; var t1 : OclAny := null; var t2 : OclAny := null; Sequence{t1,t2} := Sequence{(homa div j), (homa mod j)} ; if (t2->compareTo(ost)) < 0 then ( var amn : OclAny := null; var ost : OclAny := null; Sequence{amn,ost,num} := Sequence{t1,t2,j} ) else skip) ; execute (slv[num+1])->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) A=list(map(int,input().split())) a=1 s=1 for i in range(0,n-1): if A[i]*2>=A[i+1]: a+=1 s=max(s,a) else : a=1 print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : int := 1 ; var s : int := 1 ; for i : Integer.subrange(0, n - 1-1) do ( if (A[i+1] * 2->compareTo(A[i + 1+1])) >= 0 then ( a := a + 1 ; s := Set{s, a}->max() ) else ( a := 1 )) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (number_of_hamsters,type_of_boxes)=map(int,input().split(' ')) boxes_capacity=list(map(int,input().split(' '))) box_index=0 quantity=0 surpluses=[] if number_of_hamsters==0 : print(1,0) else : for i in range(type_of_boxes): surpluses.append(number_of_hamsters % boxes_capacity[i]) if surpluses.count(0)>0 : print(surpluses.index(0)+1,number_of_hamsters//boxes_capacity[surpluses.index(0)]) else : min_index=surpluses.index(min(surpluses)) print(min_index+1,(number_of_hamsters-surpluses[min_index])//boxes_capacity[min_index]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{number_of_hamsters, type_of_boxes} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var boxes_capacity : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var box_index : int := 0 ; var quantity : int := 0 ; var surpluses : Sequence := Sequence{} ; if number_of_hamsters = 0 then ( execute (1)->display() ) else ( for i : Integer.subrange(0, type_of_boxes-1) do ( execute ((number_of_hamsters mod boxes_capacity[i+1]) : surpluses)) ; if surpluses->count(0) > 0 then ( execute (surpluses->indexOf(0) - 1 + 1)->display() ) else ( var min_index : int := surpluses->indexOf((surpluses)->min()) - 1 ; execute (min_index + 1)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() rd=lambda : map(int,input().split()) n,k=rd() p,q=min(enumerate(rd()),key=lambda x : n % x[1]) print(p+1,n//q) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var rd : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := rd->apply() ; var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := Set{Integer.subrange(1, (rd->apply())->size())->collect( _indx | Sequence{_indx-1, (rd->apply())->at(_indx)} ), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (expr (atom (name n))) % (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))))}->min() ; execute (p + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class newNode : def __init__(self,data): self.data=data ; self.left=None ; self.right=None ; def insert(root,data): if(root==None): return newNode(data); else : if(dataroot.data): root.right=insert(root.right,data); return root ; def inOrder(root): if(root==None): return ; else : inOrder(root.left); print(root.data,end=" "); inOrder(root.right); if __name__=="__main__" : arr=[1,2,3,2,5,4,4]; n=len(arr); root=None ; for i in range(n): root=insert(root,arr[i]); inOrder(root); ------------------------------------------------------------ OCL File: --------- class newNode { static operation newnewNode() : newNode pre: true post: newNode->exists( _x | result = _x ); operation initialise(data : OclAny) : newNode pre: true post: true activity: self.data := data; ; self.left := null; ; self.right := null;; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( var arr : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{2}->union(Sequence{5}->union(Sequence{4}->union(Sequence{ 4 })))))); ; var n : int := (arr)->size(); ; root := null; ; for i : Integer.subrange(0, n-1) do ( root := insert(root, arr[i+1]);) ; inOrder(root); ) else skip; operation insert(root : OclAny, data : OclAny) pre: true post: true activity: if (root = null) then ( return (newNode.newnewNode()).initialise(data); ) else ( if ((data->compareTo(root.data)) < 0) then ( root.left := insert(root.left, data); ) else skip ; if ((data->compareTo(root.data)) > 0) then ( root.right := insert(root.right, data); ) else skip ; return root; ); operation inOrder(root : OclAny) : OclAny pre: true post: true activity: if (root = null) then ( return; ) else ( inOrder(root.left); ; execute (root.data)->display(); ; inOrder(root.right); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=list(map(int,input().split(" "))) boxes=list(map(int,input().split(" "))) boxnum=1 minbox=N//boxes[0] hamleft=N % boxes[0] for i in range(len(boxes)): if(N % boxes[i]collect( _x | (OclType["int"])->apply(_x) )) ; var boxes : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var boxnum : int := 1 ; var minbox : int := N div boxes->first() ; var hamleft : int := N mod boxes->first() ; for i : Integer.subrange(0, (boxes)->size()-1) do ( if ((N mod boxes[i+1]->compareTo(hamleft)) < 0) then ( boxnum := i + 1 ; minbox := N div boxes[i+1] ; hamleft := N mod boxes[i+1] ) else skip) ; execute (("" + ((boxnum))) + " " + ("" + ((minbox))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n,k=map(int,input().split()) kinds=list(map(int,input().split())) maxHamsters=-sys.maxsize index=0 movingBoxes=0 for i in range(len(kinds)): boxes=n//kinds[i] movingHamsters=boxes*kinds[i] if movingHamsters>maxHamsters : maxHamsters=movingHamsters movingBoxes=boxes index=i+1 print(index,movingBoxes) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var kinds : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var maxHamsters : (trailer . (name maxsize)) := -(trailer . (name maxsize)) ; var index : int := 0 ; var movingBoxes : int := 0 ; for i : Integer.subrange(0, (kinds)->size()-1) do ( var boxes : int := n div kinds[i+1] ; var movingHamsters : double := boxes * kinds[i+1] ; if (movingHamsters->compareTo(maxHamsters)) > 0 then ( maxHamsters := movingHamsters ; movingBoxes := boxes ; index := i + 1 ) else skip) ; execute (index)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def leftRotate(arr,d,n): d=d % n g_c_d=gcd(d,n) for i in range(g_c_d): temp=arr[i] j=i while 1 : k=j+d if k>=n : k=k-n if k==i : break arr[j]=arr[k] j=k arr[j]=temp def printArray(arr,size): for i in range(size): print("% d" % arr[i],end=" ") def gcd(a,b): if b==0 : return a ; else : return gcd(b,a % b) arr=[1,2,3,4,5,6,7] n=len(arr) d=2 leftRotate(arr,d,n) printArray(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 7 })))))) ; n := (arr)->size() ; d := 2 ; leftRotate(arr, d, n) ; printArray(arr, n); operation leftRotate(arr : OclAny, d : OclAny, n : OclAny) pre: true post: true activity: d := d mod n ; var g_c_d : OclAny := gcd(d, n) ; for i : Integer.subrange(0, g_c_d-1) do ( var temp : OclAny := arr[i+1] ; var j : OclAny := i ; while 1 do ( var k : OclAny := j + d ; if (k->compareTo(n)) >= 0 then ( k := k - n ) else skip ; if k = i then ( break ) else skip ; arr[j+1] := arr[k+1] ; j := k) ; arr[j+1] := temp); operation printArray(arr : OclAny, size : OclAny) pre: true post: true activity: for i : Integer.subrange(0, size-1) do ( execute (StringLib.format("% d",arr[i+1]))->display()); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if b = 0 then ( return a; ) else ( return gcd(b, a mod b) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) a=list(map(int,input().split())) l=100 cnt=[0]*(l+1) ans=0 for i in a : cnt[i]+=1 ans+=i s=ans for i in range(1,l+1): for j in range(i,l+1,i): if not cnt[j]: continue u=j//i-j for k in range(1,l+1): if not cnt[k]: continue v=i*k-k ans=min(ans,s+u+v) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : int := 100 ; var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (l + 1)) ; var ans : int := 0 ; for i : a do ( cnt[i+1] := cnt[i+1] + 1 ; ans := ans + i) ; var s : int := ans ; for i : Integer.subrange(1, l + 1-1) do ( for j : Integer.subrange(i, l + 1-1)->select( $x | ($x - i) mod i = 0 ) do ( if not(cnt[j+1]) then ( continue ) else skip ; var u : double := j div i - j ; for k : Integer.subrange(1, l + 1-1) do ( if not(cnt[k+1]) then ( continue ) else skip ; var v : double := i * k - k ; ans := Set{ans, s + u + v}->min()))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def prime(num): b=num for i in range(2,num): if i*i>num : break if b % i==0 : return False return True def factors(num): L=[] for i in range(1,int(num**0.5)+1): if num % i==0 : L.append(i) if i*i!=num : L.append(num//i) return L for i in range(1): n=int(input()) M=list(map(int,input().split())) min1=min(M) diff=0 for i in M : for j in factors(i): if((min1+i)-(min1*j+i//j))>diff : diff=((min1+i)-((min1*j)+(i//j))) print(sum(M)-diff) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; for i : Integer.subrange(0, 1-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var M : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var min1 : OclAny := (M)->min() ; var diff : int := 0 ; for i : M do ( for j : factors(i) do ( if (((min1 + i) - (min1 * j + i div j))->compareTo(diff)) > 0 then ( diff := ((min1 + i) - ((min1 * j) + (i div j))) ) else skip)) ; execute ((M)->sum() - diff)->display()); operation prime(num : OclAny) : OclAny pre: true post: true activity: var b : OclAny := num ; for i : Integer.subrange(2, num-1) do ( if (i * i->compareTo(num)) > 0 then ( break ) else skip ; if b mod i = 0 then ( return false ) else skip) ; return true; operation factors(num : OclAny) : OclAny pre: true post: true activity: var L : Sequence := Sequence{} ; for i : Integer.subrange(1, ("" + (((num)->pow(0.5))))->toInteger() + 1-1) do ( if num mod i = 0 then ( execute ((i) : L) ; if i * i /= num then ( execute ((num div i) : L) ) else skip ) else skip) ; return L; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=sorted(list(map(int,input().split())),reverse=1) x=a[-1] s=sum(a) yy=0 for y in a : zz=0 for i in range(2,y+1): if y % i==0 : zz=min(-x+x*i-y+(y//i),zz) if zz<0 : yy=min(yy,zz) print(s+yy) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ; var x : OclAny := a->last() ; var s : OclAny := (a)->sum() ; var yy : int := 0 ; for y : a do ( var zz : int := 0 ; for i : Integer.subrange(2, y + 1-1) do ( if y mod i = 0 then ( zz := Set{-x + x * i - y + (y div i), zz}->min() ) else skip) ; if zz < 0 then ( yy := Set{yy, zz}->min() ) else skip) ; execute (s + yy)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys n=int(input()) a=sorted(list(map(int,input().split()))) factors=[] for i,item in enumerate(a): element_factors=[] for j in range(2,math.ceil(math.sqrt(item))+1): if item % j==0 : element_factors.append(j) element_factors.append(item//j) factors.append(list(set(element_factors))) best=sum(a) original_sum=sum(a) for i,factor in enumerate(factors): for item in factor : current=int(original_sum) current-=a[i]-a[i]//item current+=a[0]*item-a[0] best=min(best,current) print(best) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var factors : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var item : OclAny := _tuple->at(_indx); var element_factors : Sequence := Sequence{} ; for j : Integer.subrange(2, ((item)->sqrt())->ceil() + 1-1) do ( if item mod j = 0 then ( execute ((j) : element_factors) ; execute ((item div j) : element_factors) ) else skip) ; execute (((Set{}->union((element_factors)))) : factors)) ; var best : OclAny := (a)->sum() ; var original_sum : OclAny := (a)->sum() ; for _tuple : Integer.subrange(1, (factors)->size())->collect( _indx | Sequence{_indx-1, (factors)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var factor : OclAny := _tuple->at(_indx); for item : factor do ( var current : int := ("" + ((original_sum)))->toInteger() ; current := current - a[i+1] - a[i+1] div item ; current := current + a->first() * item - a->first() ; best := Set{best, current}->min())) ; execute (best)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() a=[*map(int,input().split())] m=min(a) print(sum(a)-max(y+m-y//x-m*x for y in a for x in range(1,y+1)if y % x==0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : OclAny := (a)->min() ; execute ((a)->sum() - ((argument (test (logical_test (comparison (expr (expr (expr (expr (atom (name y))) + (expr (atom (name m)))) - (expr (expr (atom (name y))) // (expr (atom (name x))))) - (expr (expr (atom (name m))) * (expr (atom (name x)))))))) (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name a))))) (comp_iter (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name y))) + (expr (atom (number (integer 1)))))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (expr (atom (name y))) % (expr (atom (name x))))) == (comparison (expr (atom (number (integer 0))))))))))))))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=list(map(int,input().split())) if n==1 : print(1) else : a=1 u=1 for i in range(1,n): if p[i]<=2*p[i-1]: u+=1 a=max(a,u) else : u=1 print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = 1 then ( execute (1)->display() ) else ( var a : int := 1 ; var u : int := 1 ; for i : Integer.subrange(1, n-1) do ( if (p[i+1]->compareTo(2 * p[i - 1+1])) <= 0 then ( u := u + 1 ; a := Set{a, u}->max() ) else ( u := 1 )) ; execute (a)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minimizeDiff(arr,n,k): max_element=max(arr) min_element=min(arr) if((max_element-min_element)<=k): return(max_element-min_element) avg=(max_element+min_element)//2 for i in range(n): if(arr[i]>avg): arr[i]-=k else : arr[i]+=k max_element=max(arr) min_element=min(arr) return(max_element-min_element); if __name__=="__main__" : arr=[3,16,12,9,20] n=5 k=3 print("Max height difference=",minimizeDiff(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{3}->union(Sequence{16}->union(Sequence{12}->union(Sequence{9}->union(Sequence{ 20 })))) ; n := 5 ; k := 3 ; execute ("Max height difference=")->display() ) else skip; operation minimizeDiff(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var max_element : OclAny := (arr)->max() ; var min_element : OclAny := (arr)->min() ; if (((max_element - min_element)->compareTo(k)) <= 0) then ( return (max_element - min_element) ) else skip ; var avg : int := (max_element + min_element) div 2 ; for i : Integer.subrange(0, n-1) do ( if ((arr[i+1]->compareTo(avg)) > 0) then ( arr[i+1] := arr[i+1] - k ) else ( arr[i+1] := arr[i+1] + k )) ; max_element := (arr)->max() ; min_element := (arr)->min() ; return (max_element - min_element);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_CHAR=26 def removeChars(str,k): hash=[0]*(MAX_CHAR) n=len(str) for i in range(n): hash[ord(str[i])-ord('a')]+=1 res="" for i in range(n): if(hash[ord(str[i])-ord('a')]>=k): res+=str[i] return res if __name__=="__main__" : str="geeksforgeeks" k=2 print(removeChars(str,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_CHAR : int := 26 ; skip ; if __name__ = "__main__" then ( OclType["String"] := "geeksforgeeks" ; k := 2 ; execute (removeChars(OclType["String"], k))->display() ) else skip; operation removeChars(OclType["String"] : OclAny, k : OclAny) : OclAny pre: true post: true activity: var hash : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX_CHAR)) ; var n : int := (OclType["String"])->size() ; for i : Integer.subrange(0, n-1) do ( hash[(("" + ([i+1])))->char2byte() - ('a')->char2byte()+1] := hash[(("" + ([i+1])))->char2byte() - ('a')->char2byte()+1] + 1) ; var res : String := "" ; for i : Integer.subrange(0, n-1) do ( if ((hash[(("" + ([i+1])))->char2byte() - ('a')->char2byte()+1]->compareTo(k)) >= 0) then ( res := res + ("" + ([i+1])) ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import collections import heapq input=sys.stdin.readline n=int(input()) l=[int(i)for i in input().split()] m=int(input()) s=0 d={} for i in range(m): a,b,c=(int(i)for i in input().split()) if(b in d): d[b]=min(d[b],c) else : d[b]=c c1=0 for i in range(1,n+1): if(i not in d): c1+=1 if(c1>1): print(-1) else : for i in d : s+=d[i] print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : int := 0 ; var d : OclAny := Set{} ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; if ((d)->includes(b)) then ( d[b+1] := Set{d[b+1], c}->min() ) else ( d[b+1] := c )) ; var c1 : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( if ((d)->excludes(i)) then ( c1 := c1 + 1 ) else skip) ; if (c1 > 1) then ( execute (-1)->display() ) else ( for i : d do ( s := s + d[i+1]) ; execute (s)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) q=list(map(int,input().split())) m=int(input()) A=[0]*m for i in range(m): entry=list(map(int,input().split())) for j in range(len(entry)): entry[j]-=1 A[i]=entry e=[0]*n for i in range(n): e[i]=[] h=10**6+2 l=[h]*n for i in range(m): e[A[i][1]].append(A[i][0]) l[A[i][1]]=min(l[A[i][1]],A[i][2]+1) count=0 for i in e : if len(i)==0 : count+=1 if(count>1): print(-1) else : print(sum([i for i in l if itoInteger() ; var q : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; for i : Integer.subrange(0, m-1) do ( var entry : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, (entry)->size()-1) do ( entry[j+1] := entry[j+1] - 1) ; A[i+1] := entry) ; var e : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( e[i+1] := Sequence{}) ; var h : double := (10)->pow(6) + 2 ; var l : Sequence := MatrixLib.elementwiseMult(Sequence{ h }, n) ; for i : Integer.subrange(0, m-1) do ((expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))) ; l[A[i+1][1+1]+1] := Set{l[A[i+1][1+1]+1], A[i+1][2+1] + 1}->min()) ; var count : int := 0 ; for i : e do ( if (i)->size() = 0 then ( count := count + 1 ) else skip) ; if (count > 1) then ( execute (-1)->display() ) else ( execute ((l->select(i | (i->compareTo(h)) < 0)->collect(i | (i)))->sum())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) qualifications=list(map(int,input().split())) apps=[] limit=(10**6)+1 result=[limit for i in range(n)] m=int(input()) for i in range(m): a,b,c=map(int,input().split()) result[b-1]=min(result[b-1],c) count=0 for i in result : if i==limit : count+=1 if count>1 : print(-1) else : out=0 for i in result : if i!=limit : out+=i print(out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var qualifications : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var apps : Sequence := Sequence{} ; var limit : double := ((10)->pow(6)) + 1 ; var result : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (limit)) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; result[b - 1+1] := Set{result[b - 1+1], c}->min()) ; var count : int := 0 ; for i : result do ( if i = limit then ( count := count + 1 ) else skip) ; if count > 1 then ( execute (-1)->display() ) else ( var out : int := 0 ; for i : result do ( if i /= limit then ( out := out + i ) else skip) ; execute (out)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s=input() return(list(s[: len(s)-1])) def invr(): return(map(int,input().split())) from typing import List def minCostCreateHierarchy(n : int,edges)->int : edges.sort(key=lambda x : x[2]) has_boss=[False for _ in range(n+1)] res=0 for u,v,d in edges : if not has_boss[v]: res+=d has_boss[v]=True return res def task4(n : int,qualifications : List[int],statements : List[List[int]])->int : subordinates=set(statement[1]for statement in statements) if len(subordinates)!=n-1 : return-1 return minCostCreateHierarchy(n,statements) n=inp() qualifications=inlt() statements=[] m=inp() for i in range(m): statements.append(inlt()) print(task4(n,qualifications,statements)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := inp() ; var qualifications : OclAny := inlt() ; var statements : Sequence := Sequence{} ; var m : OclAny := inp() ; for i : Integer.subrange(0, m-1) do ( execute ((inlt()) : statements)) ; execute (task4(n, qualifications, statements))->display(); operation inp() : OclAny pre: true post: true activity: return (("" + (((OclFile["System.in"]).readLine())))->toInteger()); operation inlt() : OclAny pre: true post: true activity: return (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))); operation insr() : OclAny pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; return ((s.subrange(1,(s)->size() - 1))); operation invr() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation minCostCreateHierarchy(n : int, edges : OclAny) : int pre: true post: true activity: edges := edges->sort() ; var has_boss : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (false)) ; var res : int := 0 ; for _tuple : edges do (var _indx : int := 1; var u : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); if not(has_boss[v+1]) then ( res := res + d ; has_boss[v+1] := true ) else skip) ; return res; operation task4(n : int, qualifications : List[OclType["int"]+1], statements : List[List[OclType["int"]+1]+1]) : int pre: true post: true activity: var subordinates : Set := Set{}->union(((argument (test (logical_test (comparison (expr (atom (name statement)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))) (comp_for for (exprlist (expr (atom (name statement)))) in (logical_test (comparison (expr (atom (name statements))))))))) ; if (subordinates)->size() /= n - 1 then ( return -1 ) else skip ; return minCostCreateHierarchy(n, statements); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=list(map(int,input().split())) xs=list(sorted(x)) b1=xs[n//2-1] b2=xs[n//2] for xi in x : if xi<=b1 : print(b2) else : print(b1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var xs : Sequence := (x->sort()) ; var b1 : OclAny := xs[n div 2 - 1+1] ; var b2 : OclAny := xs[n div 2+1] ; for xi : x do ( if (xi->compareTo(b1)) <= 0 then ( execute (b2)->display() ) else ( execute (b1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**15 mod=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): n=I() a=LI() s=sorted(a) r=[] if n % 2==0 : b=s[n//2-1] c=s[n//2] for t in a : if t<=b : r.append(c) else : r.append(b) else : b=s[n//2] c=s[n//2-1] for t in a : if t>=b : r.append(c) else : r.append(b) return '\n'.join(map(str,r)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(15) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var n : OclAny := I() ; var a : OclAny := LI() ; s := a->sort() ; var r : Sequence := Sequence{} ; if n mod 2 = 0 then ( var b : OclAny := s[n div 2 - 1+1] ; var c : OclAny := s[n div 2+1] ; for t : a do ( if (t->compareTo(b)) <= 0 then ( execute ((c) : r) ) else ( execute ((b) : r) )) ) else ( b := s[n div 2+1] ; c := s[n div 2 - 1+1] ; for t : a do ( if (t->compareTo(b)) >= 0 then ( execute ((c) : r) ) else ( execute ((b) : r) )) ) ; return StringLib.sumStringsWithSeparator(((r)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) X=[int(_)for _ in input().split()] xs=sorted(X) m1=xs[N//2-1] m2=xs[N//2] for i in range(N): if X[i]<=m1 : print(m2) else : print(m1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var X : Sequence := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var xs : Sequence := X->sort() ; var m1 : OclAny := xs[N div 2 - 1+1] ; var m2 : OclAny := xs[N div 2+1] ; for i : Integer.subrange(0, N-1) do ( if (X[i+1]->compareTo(m1)) <= 0 then ( execute (m2)->display() ) else ( execute (m1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=list(map(int,input().split())) y=[] for i in range(n): y.append([x[i],i]) y.sort() ans=[-1 for i in range(n)] for i in range(n//2): ans[y[i][1]]=y[n//2][0] for i in range(n//2,n): ans[y[i][1]]=y[n//2-1][0] for i in range(n): print(ans[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var y : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((Sequence{x[i+1]}->union(Sequence{ i })) : y)) ; y := y->sort() ; var ans : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (-1)) ; for i : Integer.subrange(0, n div 2-1) do ( ans[y[i+1][1+1]+1] := y[n div 2+1]->first()) ; for i : Integer.subrange(n div 2, n-1) do ( ans[y[i+1][1+1]+1] := y[n div 2 - 1+1]->first()) ; for i : Integer.subrange(0, n-1) do ( execute (ans[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) X=list(map(int,input().split())) D={} for i in range(N): D[i]=X[i] X=sorted(X) ans=[X[N//2-1],X[N//2]] A={} cnt=0 for i,v in sorted(D.items(),key=lambda x : x[1]): if cnttoInteger() ; var X : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var D : OclAny := Set{} ; for i : Integer.subrange(0, N-1) do ( D[i+1] := X[i+1]) ; X := X->sort() ; var ans : Sequence := Sequence{X[N div 2 - 1+1]}->union(Sequence{ X[N div 2+1] }) ; var A : OclAny := Set{} ; var cnt : int := 0 ; for _tuple : D->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sortedBy($x | (lambda x : OclAny in (x[1+1]))->apply($x)) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if (cnt->compareTo(N div 2)) < 0 then ( A[i+1] := ans[1+1] ) else ( A[i+1] := ans->first() ) ; cnt := cnt + 1) ; for _tuple : A->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sortedBy($x | (lambda x : OclAny in (x->first()))->apply($x)) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); execute (v)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minsteps(n,m): if(m>n): return-1 else : return((n+1)//2+m-1)//m*m ; n=17 m=4 ans=minsteps(n,m) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 17 ; m := 4 ; var ans : OclAny := minsteps(n, m) ; execute (ans)->display(); operation minsteps(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: if ((m->compareTo(n)) > 0) then ( return -1 ) else ( return ((n + 1) div 2 + m - 1) div m * m; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def LCSubStr(X,Y,m,n): LCSuff=[[0 for k in range(n+1)]for l in range(m+1)] result=0 for i in range(m+1): for j in range(n+1): if(i==0 or j==0): LCSuff[i][j]=0 elif(X[i-1]==Y[j-1]): LCSuff[i][j]=LCSuff[i-1][j-1]+1 result=max(result,LCSuff[i][j]) else : LCSuff[i][j]=0 return result X='OldSite:GeeksforGeeks.org' Y='NewSite:GeeksQuiz.com' m=len(X) n=len(Y) print('Length of Longest Common Substring is',LCSubStr(X,Y,m,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; X := 'OldSite:GeeksforGeeks.org' ; Y := 'NewSite:GeeksQuiz.com' ; m := (X)->size() ; n := (Y)->size() ; execute ('Length of Longest Common Substring is')->display(); operation LCSubStr(X : OclAny, Y : OclAny, m : OclAny, n : OclAny) : OclAny pre: true post: true activity: var LCSuff : Sequence := Integer.subrange(0, m + 1-1)->select(l | true)->collect(l | (Integer.subrange(0, n + 1-1)->select(k | true)->collect(k | (0)))) ; var result : int := 0 ; for i : Integer.subrange(0, m + 1-1) do ( for j : Integer.subrange(0, n + 1-1) do ( if (i = 0 or j = 0) then ( LCSuff[i+1][j+1] := 0 ) else (if (X[i - 1+1] = Y[j - 1+1]) then ( LCSuff[i+1][j+1] := LCSuff[i - 1+1][j - 1+1] + 1 ; result := Set{result, LCSuff[i+1][j+1]}->max() ) else ( LCSuff[i+1][j+1] := 0 ) ) )) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printSmall(arr,n,k): for i in range(k,n): max_var=arr[k-1] pos=k-1 for j in range(k-2,-1,-1): if(arr[j]>max_var): max_var=arr[j] pos=j if(max_var>arr[i]): j=pos while(junion(Sequence{5}->union(Sequence{8}->union(Sequence{9}->union(Sequence{6}->union(Sequence{7}->union(Sequence{3}->union(Sequence{4}->union(Sequence{2}->union(Sequence{ 0 }))))))))) ; n := (arr)->size() ; k := 5 ; printSmall(arr, n, k); operation printSmall(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: for i : Integer.subrange(k, n-1) do ( var max_var : OclAny := arr[k - 1+1] ; var pos : double := k - 1 ; for j : Integer.subrange(-1 + 1, k - 2)->reverse() do ( if ((arr[j+1]->compareTo(max_var)) > 0) then ( max_var := arr[j+1] ; pos := j ) else skip) ; if ((max_var->compareTo(arr[i+1])) > 0) then ( var j : OclAny := pos ; while ((j->compareTo(k - 1)) < 0) do ( arr[j+1] := arr[j + 1+1] ; j := j + 1) ; arr[k - 1+1] := arr[i+1] ) else skip) ; for i : Integer.subrange(0, k-1) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() ans=0 for i in range(1,len(a)): df=a[: i] sm=a[i :] if sm[0]=="0" : continue df=int(df) sm=int(sm) if(df+sm)% 2==0 and sm>=df and(sm-df)% 2==0 : ans+=1 if int(a)% 2==0 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; for i : Integer.subrange(1, (a)->size()-1) do ( var df : OclAny := a.subrange(1,i) ; var sm : OclAny := a.subrange(i+1) ; if sm->first() = "0" then ( continue ) else skip ; df := ("" + ((df)))->toInteger() ; sm := ("" + ((sm)))->toInteger() ; if (df + sm) mod 2 = 0 & (sm->compareTo(df)) >= 0 & (sm - df) mod 2 = 0 then ( ans := ans + 1 ) else skip) ; if ("" + ((a)))->toInteger() mod 2 = 0 then ( ans := ans + 1 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=list(input()) for i in range(len(a)): a[i]=int(a[i]) ans=0 for i in range(len(a)): if a[i]==0 : continue c=0 for j in range(i): c*=10 c+=a[j] d=0 for j in range(i,len(a)): d*=10 d+=a[j] if(c+d)% 2!=0 : continue x=(c+d)//2 y=d-x if x>=0 and y>=0 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := ((OclFile["System.in"]).readLine())->characters() ; for i : Integer.subrange(0, (a)->size()-1) do ( a[i+1] := ("" + ((a[i+1])))->toInteger()) ; var ans : int := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( if a[i+1] = 0 then ( continue ) else skip ; var c : int := 0 ; for j : Integer.subrange(0, i-1) do ( c := c * 10 ; c := c + a[j+1]) ; var d : int := 0 ; for j : Integer.subrange(i, (a)->size()-1) do ( d := d * 10 ; d := d + a[j+1]) ; if (c + d) mod 2 /= 0 then ( continue ) else skip ; var x : int := (c + d) div 2 ; var y : double := d - x ; if x >= 0 & y >= 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) a=list(map(int,input().split())) my_list_left=list() my_list_right=list() my_list_left.append(1) my_list_right.append(1) max_=1 for i in range(1,len(a)): if a[i-1]<=a[i]: max_+=1 else : max_=1 my_list_left.append(max_) max_=1 i=len(a)-1 while(i>0): if a[i-1]>=a[i]: max_+=1 else : max_=1 my_list_right.insert(0,max_) i-=1 max_=0 for i in range(0,len(a)): max_=max(max_,my_list_left[i]+my_list_right[i]-1) print(max_) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var my_list_left : Sequence := () ; var my_list_right : Sequence := () ; execute ((1) : my_list_left) ; execute ((1) : my_list_right) ; var max_ : int := 1 ; for i : Integer.subrange(1, (a)->size()-1) do ( if (a[i - 1+1]->compareTo(a[i+1])) <= 0 then ( max_ := max_ + 1 ) else ( max_ := 1 ) ; execute ((max_) : my_list_left)) ; max_ := 1 ; var i : double := (a)->size() - 1 ; while (i > 0) do ( if (a[i - 1+1]->compareTo(a[i+1])) >= 0 then ( max_ := max_ + 1 ) else ( max_ := 1 ) ; my_list_right := my_list_right.insertAt(0+1, max_) ; i := i - 1) ; max_ := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( max_ := Set{max_, my_list_left[i+1] + my_list_right[i+1] - 1}->max()) ; execute (max_)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sections=int(input()) heights=list(map(int,input().split())) maximum=0 tempMax=0 for i in range(sections): valueRight=0 valueLeft=0 left=True right=True temp=0 while left==True and i-temp!=0 : if heights[i-temp-1]<=heights[i-temp]: temp+=1 valueLeft+=1 else : left=False temp=0 while right==True and i+temp+1maximum): maximum=tempMax print(maximum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sections : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var heights : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var maximum : int := 0 ; var tempMax : int := 0 ; for i : Integer.subrange(0, sections-1) do ( var valueRight : int := 0 ; var valueLeft : int := 0 ; var left : boolean := true ; var right : boolean := true ; var temp : int := 0 ; while left = true & i - temp /= 0 do ( if (heights[i - temp - 1+1]->compareTo(heights[i - temp+1])) <= 0 then ( temp := temp + 1 ; valueLeft := valueLeft + 1 ) else ( left := false )) ; temp := 0 ; while right = true & (i + temp + 1->compareTo(sections)) < 0 do ( if (heights[i + temp + 1+1]->compareTo(heights[i + temp+1])) <= 0 then ( temp := temp + 1 ; valueRight := valueRight + 1 ) else ( right := false )) ; tempMax := (valueRight + valueLeft + 1) ; if ((tempMax->compareTo(maximum)) > 0) then ( maximum := tempMax ) else skip) ; execute (maximum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==1 : input() print(1) exit() building=list(map(int,input().split())) m=0 i=0 while i-1 and building[j]<=building[j+1]: count,j=count+1,j-1 j=i+1 while jtoInteger() ; if n = 1 then ( input() ; execute (1)->display() ; exit() ) else skip ; var building : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := 0 ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( var count : int := 1 ; var j : double := i - 1 ; while j > -1 & (building[j+1]->compareTo(building[j + 1+1])) <= 0 do ( Sequence{count,j} := Sequence{count + 1,j - 1}) ; j := i + 1 ; while (j->compareTo(n)) < 0 & (building[j+1]->compareTo(building[j - 1+1])) <= 0 do ( Sequence{count,j} := Sequence{count + 1,j + 1}) ; m := Set{m, count}->max() ; i := i + 1) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lm(): return map(int,input().split()) def xd(): return int(input()) def ll(): return list(map(int,input().split())) N=xd() a=ll() i=0 maxcount=0 for j in range(len(a)): i=j count=1 peak=False while ia[i+1]): if(peak==False): peak=True if(peak==True): count+=1 else : break i+=1 if(count>maxcount): maxcount=count print(maxcount) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var N : OclAny := xd() ; var a : OclAny := ll() ; var i : int := 0 ; var maxcount : int := 0 ; for j : Integer.subrange(0, (a)->size()-1) do ( i := j ; var count : int := 1 ; var peak : boolean := false ; while (i->compareTo((a)->size() - 1)) < 0 do ( if ((a[i+1]->compareTo(a[i + 1+1])) < 0) then ( if (peak = true) then ( break ) else skip ; count := count + 1 ) else (if (a[i+1] = a[i + 1+1]) then ( count := count + 1 ) else (if ((a[i+1]->compareTo(a[i + 1+1])) > 0) then ( if (peak = false) then ( peak := true ) else skip ; if (peak = true) then ( count := count + 1 ) else ( break ) ) else skip ) ) ; i := i + 1) ; if ((count->compareTo(maxcount)) > 0) then ( maxcount := count ) else skip) ; execute (maxcount)->display(); operation lm() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation xd() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation ll() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) heights=list(map(int,input().split())) max_count=1 i=0 while i=heights[moving_i]: count+=1 moving_i+=1 if moving_i==n-1 : break temp_max=moving_i if moving_i!=n-1 : while heights[moving_i+1]<=heights[moving_i]: count+=1 moving_i+=1 if moving_i==n-1 : break max_count=max(max_count,count) i=temp_max+1 print(max_count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var heights : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var max_count : int := 1 ; var i : int := 0 ; while (i->compareTo(n - 1)) < 0 do ( var count : int := 1 ; var temp_max : int := 0 ; var moving_i : int := i ; while (heights[moving_i + 1+1]->compareTo(heights[moving_i+1])) >= 0 do ( count := count + 1 ; moving_i := moving_i + 1 ; if moving_i = n - 1 then ( break ) else skip) ; temp_max := moving_i ; if moving_i /= n - 1 then ( while (heights[moving_i + 1+1]->compareTo(heights[moving_i+1])) <= 0 do ( count := count + 1 ; moving_i := moving_i + 1 ; if moving_i = n - 1 then ( break ) else skip) ) else skip ; max_count := Set{max_count, count}->max() ; i := temp_max + 1) ; execute (max_count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=10**9+7 n,m,k=map(int,input().split()) s=n*m factorial=[1] for i in range(1,s+1): factorial.append(factorial[i-1]*i % mod) inverse=[0]*(s+1) inverse[-1]=pow(factorial[-1],mod-2,mod) for i in range(s-1,-1,-1): inverse[i]=inverse[i+1]*(i+1)% mod def comb(n,r): if npow(9) + 7 ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : double := n * m ; var factorial : Sequence := Sequence{ 1 } ; for i : Integer.subrange(1, s + 1-1) do ( execute ((factorial[i - 1+1] * i mod mod) : factorial)) ; var inverse : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (s + 1)) ; inverse->last() := (factorial->last())->pow(mod - 2) ; for i : Integer.subrange(-1 + 1, s - 1)->reverse() do ( inverse[i+1] := inverse[i + 1+1] * (i + 1) mod mod) ; skip ; var c : OclAny := comb(n * m - 2, k - 2) ; var ans : int := 0 ; for i : Integer.subrange(1, n-1) do ( ans := ans + i * (n - i) * ((m)->pow(2)) * c ; ans := ans mod mod) ; for i : Integer.subrange(1, m-1) do ( ans := ans + i * (m - i) * ((n)->pow(2)) * c ; ans := ans mod mod) ; execute (ans)->display(); operation comb(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: if (n->compareTo(r)) < 0 then ( return 0 ) else skip ; return factorial[n+1] * inverse[r+1] * inverse[n - r+1] mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def comb(n,r,p): if(r<0)or(npow(9) + 7 ; var N : double := (10)->pow(6) ; var fact : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var factinv : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var inv : Sequence := Sequence{0}->union(Sequence{ 1 }) ; for i : Integer.subrange(2, N + 1-1) do ( execute (((fact->last() * i) mod p) : fact) ; execute (((-inv[p mod i+1] * (p div i)) mod p) : inv) ; execute (((factinv->last() * inv->last()) mod p) : factinv)) ; var M : OclAny := null; var K : OclAny := null; Sequence{N,M,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var MOD : double := (10)->pow(9) + 7 ; var sumx : int := 0 ; var sumy : int := 0 ; for d : Integer.subrange(1, N-1) do ( var cnt : double := (N - d) * (M)->pow(2) ; cnt := cnt mod MOD ; cnt := cnt * comb(N * M - 2, K - 2, MOD) ; sumx := sumx + d * cnt ; sumx := sumx mod MOD) ; for d : Integer.subrange(1, M-1) do ( cnt := (M - d) * (N)->pow(2) ; cnt := cnt mod MOD ; cnt := cnt * comb(N * M - 2, K - 2, MOD) ; sumy := sumy + d * cnt ; sumy := sumy mod MOD) ; execute ((sumx + sumy) mod MOD)->display(); operation comb(n : OclAny, r : OclAny, p : OclAny) : OclAny pre: true post: true activity: if (r < 0) or ((n->compareTo(r)) < 0) then ( return 0 ) else skip ; r := Set{r, n - r}->min() ; return fact[n+1] * factinv[r+1] * factinv[n - r+1] mod p; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import calendar y=int(input()) is_run=calendar.isleap(y) week=calendar.weekday(y,1,1) while True : y=y+1 if calendar.isleap(y)==is_run and calendar.weekday(y,1,1)==week : print(y) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var y : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var is_run : OclAny := calendar.isleap(y) ; var week : OclAny := calendar.weekday(y, 1, 1) ; while true do ( y := y + 1 ; if calendar.isleap(y) = is_run & calendar.weekday(y, 1, 1) = week then ( execute (y)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() cnt1=0 cnt2=0 for i in range(len(s)): if i % 2==0 : if s[i]=='0' : cnt1+=1 else : cnt2+=1 else : if s[i]=='0' : cnt2+=1 else : cnt1+=1 print(min(cnt1,cnt2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var cnt1 : int := 0 ; var cnt2 : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if i mod 2 = 0 then ( if s[i+1] = '0' then ( cnt1 := cnt1 + 1 ) else ( cnt2 := cnt2 + 1 ) ) else ( if s[i+1] = '0' then ( cnt2 := cnt2 + 1 ) else ( cnt1 := cnt1 + 1 ) )) ; execute (Set{cnt1, cnt2}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): s=input() print("NO" if s.count("N")==1 else "YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; execute (if s->count("N") = 1 then "NO" else "YES" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque import sys,heapq,bisect,math,itertools,string,queue,datetime sys.setrecursionlimit(10**8) INF=float('inf') mod=10**9+7 eps=10**-7 def inpl(): return list(map(int,input().split())) def inpl_str(): return list(input().split()) H,W,K=inpl() MAX=H*W+5 fac=[1]*(MAX+1) for i in range(1,MAX+1): fac[i]=(fac[i-1]*i)% mod gyakugen=[1]*(MAX+1) gyakugen[MAX]=pow(fac[MAX],mod-2,mod) for i in range(MAX,0,-1): gyakugen[i-1]=(gyakugen[i]*i)% mod def Comb(n,k): return(fac[n]*gyakugen[k]*gyakugen[n-k])% mod ans=0 ruiseki=[0] tmp=0 for i in range(1,max(H,W)+5): tmp+=i ruiseki.append(tmp) for y in range(H): ans+=(ruiseki[y]+ruiseki[H-y-1])*W*W for x in range(W): ans+=(ruiseki[x]+ruiseki[W-x-1])*H*H ans//=2 ans*=Comb(H*W-2,K-2) print(ans % mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var eps : double := (10)->pow(-7) ; skip ; skip ; var H : OclAny := null; var W : OclAny := null; var K : OclAny := null; Sequence{H,W,K} := inpl() ; var MAX : double := H * W + 5 ; var fac : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (MAX + 1)) ; for i : Integer.subrange(1, MAX + 1-1) do ( fac[i+1] := (fac[i - 1+1] * i) mod mod) ; var gyakugen : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (MAX + 1)) ; gyakugen[MAX+1] := (fac[MAX+1])->pow(mod - 2) ; for i : Integer.subrange(0 + 1, MAX)->reverse() do ( gyakugen[i - 1+1] := (gyakugen[i+1] * i) mod mod) ; skip ; var ans : int := 0 ; var ruiseki : Sequence := Sequence{ 0 } ; var tmp : int := 0 ; for i : Integer.subrange(1, Set{H, W}->max() + 5-1) do ( tmp := tmp + i ; execute ((tmp) : ruiseki)) ; for y : Integer.subrange(0, H-1) do ( ans := ans + (ruiseki[y+1] + ruiseki[H - y - 1+1]) * W * W) ; for x : Integer.subrange(0, W-1) do ( ans := ans + (ruiseki[x+1] + ruiseki[W - x - 1+1]) * H * H) ; ans := ans div 2 ; ans := ans * Comb(H * W - 2, K - 2) ; execute (ans mod mod)->display(); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inpl_str() : OclAny pre: true post: true activity: return (input().split()); operation Comb(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: return (fac[n+1] * gyakugen[k+1] * gyakugen[n - k+1]) mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=10**9+7 inv_2=pow(2,mod-2,mod) N,M,K=map(int,input().split()) def make_fact(n): fact=[1]*(n+1) for i in range(1,n+1): fact[i]=fact[i-1]*i % mod return fact def make_fact_inv(n): fact_inv=[1]*(n+1) fact_inv[n]=pow(fact[n],mod-2,mod) for i in range(n,0,-1): fact_inv[i-1]=fact_inv[i]*i % mod return fact_inv def comb(n,k): return fact[n]*fact_inv[k]*fact_inv[n-k]% mod fact=make_fact(N*M) fact_inv=make_fact_inv(N*M) Sum=[0]*(max(N,M)+1) for i in range(1,len(Sum)): Sum[i]=(Sum[i-1]+i)% mod ans=0 for x in range(1,N+1): for y in range(1,M+1): ans+=(Sum[x-1]+Sum[N-x])*M+(Sum[y-1]+Sum[M-y])*N ans %=mod print(ans*comb(N*M-2,K-2)*inv_2 % mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : double := (10)->pow(9) + 7 ; var inv:= (2)->pow(mod - 2) : double := (2)->pow(mod - 2) ; var N : OclAny := null; var M : OclAny := null; var K : OclAny := null; Sequence{N,M,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; skip ; skip ; fact := make_fact(N * M) ; fact_inv := make_fact_inv(N * M) ; var Sum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (Set{N, M}->max() + 1)) ; for i : Integer.subrange(1, (Sum)->size()-1) do ( Sum[i+1] := (Sum[i - 1+1] + i) mod mod) ; var ans : int := 0 ; for x : Integer.subrange(1, N + 1-1) do ( for y : Integer.subrange(1, M + 1-1) do ( ans := ans + (Sum[x - 1+1] + Sum[N - x+1]) * M + (Sum[y - 1+1] + Sum[M - y+1]) * N ; ans := ans mod mod)) ; execute (ans * comb(N * M - 2, K - 2) * invmod mod mod)->display(); operation make_fact(n : OclAny) : OclAny pre: true post: true activity: var fact : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ; for i : Integer.subrange(1, n + 1-1) do ( fact[i+1] := fact[i - 1+1] * i mod mod) ; return fact; operation make_fact_inv(n : OclAny) : OclAny pre: true post: true activity: var fact_inv : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ; fact_inv[n+1] := (fact[n+1])->pow(mod - 2) ; for i : Integer.subrange(0 + 1, n)->reverse() do ( fact_inv[i - 1+1] := fact_inv[i+1] * i mod mod) ; return fact_inv; operation comb(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: return fact[n+1] * fact_inv[k+1] * fact_inv[n - k+1] mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- LAW=10**9+7 N,M,K=map(int,input().split(" ")) def calc_rev(n,law): if n==1 : return 1 pre_r=law pre_x=0 pre_y=1 cur_r=n cur_x=1 cur_y=0 while True : d=pre_r//cur_r r=pre_r % cur_r nxt_r=r nxt_x=pre_x-d*cur_x nxt_y=pre_y-d*cur_y if nxt_r==1 : ret=nxt_x while ret<0 : ret+=law ; return ret ; elif nxt_r==0 : return None pre_r=cur_r ; pre_x=cur_x ; pre_y=cur_y ; cur_r=nxt_r ; cur_x=nxt_x ; cur_y=nxt_y ; def calc_dsum(n,m): dx=0 for i in range(1,n): dx+=i*(n-i) dy=0 for i in range(1,m): dy+=i*(m-i) dx*=m*m dy*=n*n return dx+dy def calc_csum(n,k): csum=1 for i in range(k): csum=(csum*(n-i))% LAW for i in range(1,k+1): csum=(csum*calc_rev(i,LAW))% LAW csum=(csum*k*(k-1))% LAW csum=(csum*calc_rev(n*(n-1),LAW))% LAW return csum def c(n,m,k): return(calc_csum(n*m,k)*calc_dsum(n,m))% LAW print(c(N,M,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var LAW : double := (10)->pow(9) + 7 ; var N : OclAny := null; var M : OclAny := null; var K : OclAny := null; Sequence{N,M,K} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; skip ; skip ; skip ; execute (c(N, M, K))->display(); operation calc_rev(n : OclAny, law : OclAny) : OclAny pre: true post: true activity: if n = 1 then ( return 1 ) else skip ; var pre_r : OclAny := law ; var pre_x : int := 0 ; var pre_y : int := 1 ; var cur_r : OclAny := n ; var cur_x : int := 1 ; var cur_y : int := 0 ; while true do ( var d : int := pre_r div cur_r ; var r : int := pre_r mod cur_r ; var nxt_r : int := r ; var nxt_x : double := pre_x - d * cur_x ; var nxt_y : double := pre_y - d * cur_y ; if nxt_r = 1 then ( var ret : OclAny := nxt_x ; while ret < 0 do ( ret := ret + law;) ; return ret; ) else (if nxt_r = 0 then ( return null ) else skip) ; pre_r := cur_r; ; pre_x := cur_x; ; pre_y := cur_y; ; cur_r := nxt_r; ; cur_x := nxt_x; ; cur_y := nxt_y;); operation calc_dsum(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var dx : int := 0 ; for i : Integer.subrange(1, n-1) do ( dx := dx + i * (n - i)) ; var dy : int := 0 ; for i : Integer.subrange(1, m-1) do ( dy := dy + i * (m - i)) ; dx := dx * m * m ; dy := dy * n * n ; return dx + dy; operation calc_csum(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var csum : int := 1 ; for i : Integer.subrange(0, k-1) do ( csum := (csum * (n - i)) mod LAW) ; for i : Integer.subrange(1, k + 1-1) do ( csum := (csum * calc_rev(i, LAW)) mod LAW) ; csum := (csum * k * (k - 1)) mod LAW ; csum := (csum * calc_rev(n * (n - 1), LAW)) mod LAW ; return csum; operation c(n : OclAny, m : OclAny, k : OclAny) : OclAny pre: true post: true activity: return (calc_csum(n * m, k) * calc_dsum(n, m)) mod LAW; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) if n-2<0 : x=1 else : x=n-2 if m-2<0 : y=1 else : y=m-2 print(x*y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n - 2 < 0 then ( var x : int := 1 ) else ( x := n - 2 ) ; if m - 2 < 0 then ( var y : int := 1 ) else ( y := m - 2 ) ; execute (x * y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(N,M): if N*M==1 : return 1 elif min(N,M)==1 : return max(N,M)-2 else : return(N-2)*(M-2) N,M=map(int,input().split()) print(solve(N,M)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (solve(N, M))->display(); operation solve(N : OclAny, M : OclAny) : OclAny pre: true post: true activity: if N * M = 1 then ( return 1 ) else (if Set{N, M}->min() = 1 then ( return Set{N, M}->max() - 2 ) else ( return (N - 2) * (M - 2) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy import sys import math tmp=input().split() n,m=list(map(lambda a : int(a),tmp)) if(n==1)and(m==1): print(1) elif(n>=2)and(m>=2): print((n-2)*(m-2)) else : print(max(n,m)-2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var tmp : OclAny := input().split() ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((tmp)->collect( _x | (lambda a : OclAny in (("" + ((a)))->toInteger()))->apply(_x) )) ; if (n = 1) & (m = 1) then ( execute (1)->display() ) else (if (n >= 2) & (m >= 2) then ( execute ((n - 2) * (m - 2))->display() ) else ( execute (Set{n, m}->max() - 2)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) fc=(N==1 and M==1) fs=(N>=3 and M==1) fu=(M>=3 and N==1) fi=(M>=3 and N>=3) ans=(1 if fc else 0)+(N-2 if fs else 0)+(M-2 if fu else 0)+((M-2)*(N-2)if fi else 0) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var fc : boolean := (N = 1 & M = 1) ; var fs : boolean := (N >= 3 & M = 1) ; var fu : boolean := (M >= 3 & N = 1) ; var fi : boolean := (M >= 3 & N >= 3) ; var ans : int := (if fc then 1 else 0 endif) + (if fs then N - 2 else 0 endif) + (if fu then M - 2 else 0 endif) + (if fi then (M - 2) * (N - 2) else 0 endif) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=sorted(list(map(int,input().split()))) if N==1 and M==1 : print(1) elif N==1 and M>1 : print(M-2) else : print((N-2)*(M-2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; if N = 1 & M = 1 then ( execute (1)->display() ) else (if N = 1 & M > 1 then ( execute (M - 2)->display() ) else ( execute ((N - 2) * (M - 2))->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) tbl=[] for i in range(n): a,b=map(int,input().split()) tbl.append([b,a]) tbl.sort() ans=saw=0 seen=[0]*101 for i in range(1,32): for j in range(n): if itoInteger() ; var tbl : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{b}->union(Sequence{ a })) : tbl)) ; tbl := tbl->sort() ; var ans : OclAny := 0; var saw : int := 0 ; var seen : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 101) ; for i : Integer.subrange(1, 32-1) do ( for j : Integer.subrange(0, n-1) do ( if (i->compareTo(tbl[j+1][1+1])) < 0 or (tbl[j+1]->first()->compareTo(i)) < 0 then ( continue ) else skip ; if seen[j+1] then ( continue ) else skip ; ans := ans + 100; seen[j+1] := 1; saw := saw + 1 ; break;)) ; execute (ans + (31 - saw) * 50)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections s=list(input()) even=collections.Counter(s[0 : : 2]) odd=collections.Counter(s[1 : : 2]) print(min(len(s)-(even["0"]+odd["1"]),len(s)-(even["1"]+odd["0"]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var even : OclAny := .Counter(s(subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) ; var odd : OclAny := .Counter(s(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) ; execute (Set{(s)->size() - (even->at("0") + odd->at("1")), (s)->size() - (even->at("1") + odd->at("0"))}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) As=[] Bs=[] movies=[[]for x in range(31)] for n in range(N): a,b=map(int,input().split()) a-=1 b-=1 As.append(a) Bs.append(b) for day in range(a,b+1): movies[day].append(n) picked=[False]*N ans=0 for day in range(31): unseen_movies=[m for m in movies[day]if not picked[m]] if len(unseen_movies)==0 : ans+=50 else : lastday=1000 should_see=-1 for m in unseen_movies : if Bs[m]toInteger() ; var As : Sequence := Sequence{} ; var Bs : Sequence := Sequence{} ; var movies : Sequence := Integer.subrange(0, 31-1)->select(x | true)->collect(x | (Sequence{})) ; for n : Integer.subrange(0, N-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := a - 1 ; b := b - 1 ; execute ((a) : As) ; execute ((b) : Bs) ; for day : Integer.subrange(a, b + 1-1) do ((expr (atom (name movies)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name day)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))) ; var picked : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, N) ; var ans : int := 0 ; for day : Integer.subrange(0, 31-1) do ( var unseen_movies : Sequence := movies[day+1]->select(m | not(picked[m+1]))->collect(m | (m)) ; if (unseen_movies)->size() = 0 then ( ans := ans + 50 ) else ( var lastday : int := 1000 ; var should_see : int := -1 ; for m : unseen_movies do ( if (Bs[m+1]->compareTo(lastday)) < 0 then ( lastday := Bs[m+1] ; should_see := m ) else skip) ; picked[should_see+1] := true ; ans := ans + 100 )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): s=input() new=s[0] for i in range(1,len(s)): if s[i-1]=='E' and s[i]=='E' : continue new+=s[i] if new in['EN','NE','ENE']: print('NO') else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var new : OclAny := s->first() ; for i : Integer.subrange(1, (s)->size()-1) do ( if s[i - 1+1] = 'E' & s[i+1] = 'E' then ( continue ) else skip ; new := new + s[i+1]) ; if (Sequence{'EN'}->union(Sequence{'NE'}->union(Sequence{ 'ENE' })))->includes(new) then ( execute ('NO')->display() ) else ( execute ('YES')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import heapq INF=float('inf') MOD=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return input() n=II() M=[LI()for _ in range(n)] for a in zip(*M): start=set(a) break M.sort() ans=0 index=0 hq=[] for i in range(31): if i+1 in start : while i+1 in start and M[index][0]==i+1 : heapq.heappush(hq,M[index][1]) index+=1 if index>=n : break while hq and hq[0]toReal() ; var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := II() ; var M : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI())) ; for a : Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name M)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name M)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name M)))))))`third->at(_indx)} ) do ( var start : Set := Set{}->union((a)) ; break) ; M := M->sort() ; var ans : int := 0 ; var index : int := 0 ; var hq : Sequence := Sequence{} ; for i : Integer.subrange(0, 31-1) do ( if (start)->includes(i + 1) then ( while (start)->includes(i + 1) & M[index+1]->first() = i + 1 do ( heapq.heappush(hq, M[index+1][1+1]) ; index := index + 1 ; if (index->compareTo(n)) >= 0 then ( break ) else skip) ) else skip ; while hq & (hq->first()->compareTo(i + 1)) < 0 do ( if hq then ( var tmp : OclAny := heapq.heappop(hq) ) else ( break )) ; if hq then ( ans := ans + 100 ; tmp := heapq.heappop(hq) ) else ( ans := ans + 50 )) ; execute (ans)->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation SI() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def getPosOfRightmostSetBit(n): return int(math.log2(n &-n)+1) def setRightmostUnsetBit(n): if(n==0): return 1 if((n &(n+1))==0): return n pos=getPosOfRightmostSetBit(~ n) return((1<<(pos-1))| n) n=21 print(setRightmostUnsetBit(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 21 ; execute (setRightmostUnsetBit(n))->display(); operation getPosOfRightmostSetBit(n : OclAny) : OclAny pre: true post: true activity: return ("" + (( + 1)))->toInteger(); operation setRightmostUnsetBit(n : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return 1 ) else skip ; if ((MathLib.bitwiseAnd(n, (n + 1))) = 0) then ( return n ) else skip ; var pos : OclAny := getPosOfRightmostSetBit(MathLib.bitwiseNot(n)) ; return (MathLib.bitwiseOr((1 * (2->pow((pos - 1)))), n)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def modularEquation(a,b): if(ab): count=count+1 if(i>b): count=count+1 if(y*y==n and y>b): count=count-1 print(count) a=21 b=5 modularEquation(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 21 ; b := 5 ; modularEquation(a, b); operation modularEquation(a : OclAny, b : OclAny) pre: true post: true activity: if ((a->compareTo(b)) < 0) then ( execute ("No solution possible ")->display() ; return ) else skip ; if (a = b) then ( execute ("Infinite Solution possible ")->display() ; return ) else skip ; var count : int := 0 ; var n : double := a - b ; var y : OclAny := (OclType["int"])((a - b)->sqrt()) ; for i : Integer.subrange(1, y + 1-1) do ( if (n mod i = 0) then ( if ((n / i->compareTo(b)) > 0) then ( count := count + 1 ) else skip ; if ((i->compareTo(b)) > 0) then ( count := count + 1 ) else skip ) else skip) ; if (y * y = n & (y->compareTo(b)) > 0) then ( count := count - 1 ) else skip ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSplTripletsSum(a,b,c,p,q,r): summ=0 for i in range(p): for j in range(q): for k in range(r): if(a[i]<=b[j]and c[k]<=b[j]): summ+=(a[i]+b[j])*(b[j]+c[k]) return summ A=[1,4,5] B=[2,3] C=[2,1,3] p=len(A) q=len(B) r=len(C) print("Sum of values of all special triplets=",findSplTripletsSum(A,B,C,p,q,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var A : Sequence := Sequence{1}->union(Sequence{4}->union(Sequence{ 5 })) ; var B : Sequence := Sequence{2}->union(Sequence{ 3 }) ; var C : Sequence := Sequence{2}->union(Sequence{1}->union(Sequence{ 3 })) ; p := (A)->size() ; q := (B)->size() ; r := (C)->size() ; execute ("Sum of values of all special triplets=")->display(); operation findSplTripletsSum(a : OclAny, b : OclAny, c : OclAny, p : OclAny, q : OclAny, r : OclAny) : OclAny pre: true post: true activity: var summ : int := 0 ; for i : Integer.subrange(0, p-1) do ( for j : Integer.subrange(0, q-1) do ( for k : Integer.subrange(0, r-1) do ( if ((a[i+1]->compareTo(b[j+1])) <= 0 & (c[k+1]->compareTo(b[j+1])) <= 0) then ( summ := summ + (a[i+1] + b[j+1]) * (b[j+1] + c[k+1]) ) else skip))) ; return summ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): st=input() ch=input() k=True s=0 for x in st : if((x==ch)and(s % 2==0)): print("YES") k=False break s=s+1 if k : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var st : String := (OclFile["System.in"]).readLine() ; var ch : String := (OclFile["System.in"]).readLine() ; var k : boolean := true ; var s : int := 0 ; for x : st->characters() do ( if ((x = ch) & (s mod 2 = 0)) then ( execute ("YES")->display() ; k := false ; break ) else skip ; s := s + 1) ; if k then ( execute ("NO")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): s=input() a=input() for i in range(0,len(s),2): if(len(s)% 2!=0)and(a in s)and(s[i]==a): print('yes') break else : print('no') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var a : String := (OclFile["System.in"]).readLine() ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))) % (expr (atom (number (integer 2)))))) != (comparison (expr (atom (number (integer 0))))))))) ))))) and (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name a)))) in (comparison (expr (atom (name s)))))))) )))))) and (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (name a)))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'yes'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'no'))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(n,c): if c not in n : return False indices=[i for i,x in enumerate(n)if x==c] return any((len(n)-i-1)% 2==0 for i in indices) t=int(input()) for _ in range(t): n=input() c=input() if f(n,c): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( n := (OclFile["System.in"]).readLine() ; c := (OclFile["System.in"]).readLine() ; if f(n, c) then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); operation f(n : OclAny, c : OclAny) : OclAny pre: true post: true activity: if (n)->excludes(c) then ( return false ) else skip ; var indices : Sequence := Integer.subrange(1, (n)->size())->collect( _indx | Sequence{_indx-1, (n)->at(_indx)} )->select(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in x = c)->collect(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in (i)) ; return ((argument (test (logical_test (comparison (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))) - (expr (atom (name i)))) - (expr (atom (number (integer 1))))))))) ))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name indices))))))))->exists( _x | _x = true ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(n,c): if c not in n : return False indices=[(len(n)-i-1)% 2==0 for i,x in enumerate(n)if x==c] return any(indices) t=int(input()) for _ in range(t): n=input() c=input() if f(n,c): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( n := (OclFile["System.in"]).readLine() ; c := (OclFile["System.in"]).readLine() ; if f(n, c) then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); operation f(n : OclAny, c : OclAny) : OclAny pre: true post: true activity: if (n)->excludes(c) then ( return false ) else skip ; var indices : Sequence := Integer.subrange(1, (n)->size())->collect( _indx | Sequence{_indx-1, (n)->at(_indx)} )->select(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in x = c)->collect(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in (((n)->size() - i - 1) mod 2 = 0)) ; return (indices)->exists( _x | _x = true ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,Counter from itertools import product,groupby,count,permutations,combinations from math import pi,sqrt from collections import deque from bisect import bisect,bisect_left,bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF=float("inf") YES,Yes,yes,NO,No,no="YES","Yes","yes","NO","No","no" dy4,dx4=[0,1,0,-1],[1,0,-1,0] dy8,dx8=[0,-1,0,1,1,-1,-1,1],[1,0,-1,0,1,1,-1,-1] def inside(y,x,H,W): return 0<=ytoReal() ; var YES : OclAny := null; var Yes : OclAny := null; var yes : OclAny := null; var NO : OclAny := null; var No : OclAny := null; var no : OclAny := null; Sequence{YES,Yes,yes,NO,No,no} := Sequence{"YES","Yes","yes","NO","No","no"} ; var dy4 : OclAny := null; var dx4 : OclAny := null; Sequence{dy4,dx4} := Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ -1 }))),Sequence{1}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{ 0 })))} ; var dy8 : OclAny := null; var dx8 : OclAny := null; Sequence{dy8,dx8} := Sequence{Sequence{0}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{-1}->union(Sequence{-1}->union(Sequence{ 1 }))))))),Sequence{1}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{-1}->union(Sequence{ -1 })))))))} ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation inside(y : OclAny, x : OclAny, H : OclAny, W : OclAny) : OclAny pre: true post: true activity: return 0 <= y & (y < H) & 0 <= x & (x < W); operation ceil(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a + b - 1) div b; operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if b = 0 then ( return a ) else skip ; return gcd(b, a mod b); operation lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var g : OclAny := gcd(a, b) ; return a / g * b; operation solve(S : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, (S)->size()-1) do ( if ("" + ((S[i+1])))->toInteger() = n then ( skip ) else ( ans := ans + 1 ) ; n := 1 - n) ; return ans; operation main() pre: true post: true activity: S := (OclFile["System.in"]).readLine() ; execute (Set{solve(S, 0), solve(S, 1)}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re for _ in range(int(input())): s=input() c=input() p=re.compile('(\\w\\w)*{}(\\w\\w)*'.format(c)) if p.match(s): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var c : String := (OclFile["System.in"]).readLine() ; var p : OclRegex := OclRegex.compile(StringLib.interpolateStrings('(\\w\\w)*{}(\\w\\w)*', Sequence{c})) ; if p.match(s) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPalindrome(n): if n % 11==0 : return True return False if __name__=="__main__" : n=123321 if isPalindrome(n): print("Palindrome") else : print("Not Palindrome") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 123321 ; if isPalindrome(n) then ( execute ("Palindrome")->display() ) else ( execute ("Not Palindrome")->display() ) ) else skip; operation isPalindrome(n : OclAny) : OclAny pre: true post: true activity: if n mod 11 = 0 then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=eval(input()) for i in range(t): s=input() if s[-1]=="E" : c=s.count("N") if c==1 : print("no") else : print("yes") else : c=s.count("N") if c==1 : print("no") else : print("yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, t-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if s->last() = "E" then ( var c : int := s->count("N") ; if c = 1 then ( execute ("no")->display() ) else ( execute ("yes")->display() ) ) else ( c := s->count("N") ; if c = 1 then ( execute ("no")->display() ) else ( execute ("yes")->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import bisect read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines n,m=map(int,readline().split()) if n==m : print("Draw") elif n==1 or m==1 : if n==1 : print("Alice") else : print("Bob") else : if n>m : print("Alice") else : print("Bob") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = m then ( execute ("Draw")->display() ) else (if n = 1 or m = 1 then ( if n = 1 then ( execute ("Alice")->display() ) else ( execute ("Bob")->display() ) ) else ( if (n->compareTo(m)) > 0 then ( execute ("Alice")->display() ) else ( execute ("Bob")->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=((11+int(s))% 13 for s in input().split()) print('Alice' if a>b else 'Bob' if acompareTo(b)) > 0 then 'Alice' else if (a->compareTo(b)) < 0 then 'Bob' else 'Draw' endif endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def one_card_poker(A : int,B : int)->str : if A==B : return 'Draw' if A==1 : return 'Alice' if B==1 : return 'Bob' if A>B : return 'Alice' return 'Bob' if __name__=="__main__" : A,B=map(int,input().split()) ans=one_card_poker(A,B) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : OclAny := one_card_poker(A, B) ; execute (ans)->display() ) else skip; operation one_card_poker(A : int, B : int) : String pre: true post: true activity: if A = B then ( return 'Draw' ) else skip ; if A = 1 then ( return 'Alice' ) else skip ; if B = 1 then ( return 'Bob' ) else skip ; if (A->compareTo(B)) > 0 then ( return 'Alice' ) else skip ; return 'Bob'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def debug(x,table): for name,val in table.items(): if x is val : print('DEBUG:{}->{}'.format(name,val),file=sys.stderr) return None def solve(): A,B=map(int,input().split()) if A==B : ans='Draw' else : if A==1 : ans='Alice' elif B==1 : ans='Bob' elif A>B : ans='Alice' else : ans='Bob' print(ans) if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation debug(x : OclAny, table : OclAny) : OclAny pre: true post: true activity: for _tuple : table->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var name : OclAny := _tuple->at(_indx); _indx := _indx + 1; var val : OclAny := _tuple->at(_indx); if x <>= val then ( execute (StringLib.interpolateStrings('DEBUG:{}->{}', Sequence{name, val}))->display() ; return null ) else skip); operation solve() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if A = B then ( var ans : String := 'Draw' ) else ( if A = 1 then ( ans := 'Alice' ) else (if B = 1 then ( ans := 'Bob' ) else (if (A->compareTo(B)) > 0 then ( ans := 'Alice' ) else ( ans := 'Bob' ) ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) h=[0,14]+list(range(2,14)) if a==b : print("Draw") else : print("Alice" if h[a]>h[b]else "Bob") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h : Sequence := Sequence{0}->union(Sequence{ 14 })->union((Integer.subrange(2, 14-1))) ; if a = b then ( execute ("Draw")->display() ) else ( execute (if (h[a+1]->compareTo(h[b+1])) > 0 then "Alice" else "Bob" endif)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minSwaps(arr,n): noOfOnes=0 for i in range(n): if(arr[i]==1): noOfOnes=noOfOnes+1 x=noOfOnes maxOnes=-2147483648 preCompute={} if(arr[0]==1): preCompute[0]=1 for i in range(1,n): if(arr[i]==1): preCompute[i]=preCompute[i-1]+1 else : preCompute[i]=preCompute[i-1] for i in range(x-1,n): if(i==(x-1)): noOfOnes=preCompute[i] else : noOfOnes=preCompute[i]-preCompute[i-x] if(maxOnesunion(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 1 })))) ; n := (a)->size() ; execute (minSwaps(a, n))->display(); operation minSwaps(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var noOfOnes : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] = 1) then ( noOfOnes := noOfOnes + 1 ) else skip) ; var x : int := noOfOnes ; var maxOnes : int := -2147483648 ; var preCompute : OclAny := Set{} ; if (arr->first() = 1) then ( preCompute->first() := 1 ) else skip ; for i : Integer.subrange(1, n-1) do ( if (arr[i+1] = 1) then ( preCompute[i+1] := preCompute[i - 1+1] + 1 ) else ( preCompute[i+1] := preCompute[i - 1+1] )) ; for i : Integer.subrange(x - 1, n-1) do ( if (i = (x - 1)) then ( noOfOnes := preCompute[i+1] ) else ( noOfOnes := preCompute[i+1] - preCompute[i - x+1] ) ; if ((maxOnes->compareTo(noOfOnes)) < 0) then ( maxOnes := noOfOnes ) else skip) ; var noOfZeroes : double := x - maxOnes ; return noOfZeroes; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def findArea(a): area=(sqrt(5*(5+2*(sqrt(5))))*a*a)/4 return area a=5 print("Area of Pentagon: ",findArea(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 5 ; execute ("Area of Pentagon: ")->display(); operation findArea(a : OclAny) : OclAny pre: true post: true activity: var area : double := (sqrt(5 * (5 + 2 * (sqrt(5)))) * a * a) / 4 ; return area; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin S=stdin.readline().rstrip() N=len(S) s0='' s1='' c0=0 c1=0 for itr in range(0,N): if itr % 2==0 : s0+="0" s1+="1" else : s0+="1" s1+="0" for itr in range(0,N): if S[itr]!=s0[itr]: c0+=1 if S[itr]!=s1[itr]: c1+=1 if c0>=c1 : print(c1) else : print(c0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var S : OclAny := stdin.readLine().rstrip() ; var N : int := (S)->size() ; var s0 : String := '' ; var s1 : String := '' ; var c0 : int := 0 ; var c1 : int := 0 ; for itr : Integer.subrange(0, N-1) do ( if itr mod 2 = 0 then ( s0 := s0 + "0" ; s1 := s1 + "1" ) else ( s0 := s0 + "1" ; s1 := s1 + "0" )) ; for itr : Integer.subrange(0, N-1) do ( if S[itr+1] /= s0[itr+1] then ( c0 := c0 + 1 ) else skip ; if S[itr+1] /= s1[itr+1] then ( c1 := c1 + 1 ) else skip) ; if (c0->compareTo(c1)) >= 0 then ( execute (c1)->display() ) else ( execute (c0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def countOrderedPairs(N): count_pairs=0 p=int(sqrt(N-1))+1 q=int(sqrt(N))+2 for i in range(1,p,1): for j in range(i,q,1): count_pairs+=1 count_pairs*=2 count_pairs-=int(sqrt(N-1)) return count_pairs if __name__=='__main__' : N=5 print(countOrderedPairs(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( N := 5 ; execute (countOrderedPairs(N))->display() ) else skip; operation countOrderedPairs(N : OclAny) : OclAny pre: true post: true activity: var count_pairs : int := 0 ; var p : int := ("" + ((sqrt(N - 1))))->toInteger() + 1 ; var q : int := ("" + ((sqrt(N))))->toInteger() + 2 ; for i : Integer.subrange(1, p-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( for j : Integer.subrange(i, q-1)->select( $x | ($x - i) mod 1 = 0 ) do ( count_pairs := count_pairs + 1)) ; count_pairs := count_pairs * 2 ; count_pairs := count_pairs - ("" + ((sqrt(N - 1))))->toInteger() ; return count_pairs; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt MAX=1000 def NthPrime(n): count=0 for i in range(2,MAX+1): check=0 for j in range(2,int(sqrt(i))+1): if i % j==0 : check=1 break if check==0 : count+=1 if count==n : return i break def NthFib(n): f=[0]*(n+2) f[0],f[1]=0,1 for i in range(2,n+1): f[i]=f[i-1]+f[i-2] return f[n] def findNthTerm(n): if n % 2==0 : n//=2 n=NthPrime(n) print(n) else : n=(n//2)+1 n=NthFib(n-1) print(n) if __name__=="__main__" : X=5 findNthTerm(X) X=10 findNthTerm(X) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MAX : int := 1000 ; skip ; skip ; skip ; if __name__ = "__main__" then ( var X : int := 5 ; findNthTerm(X) ; X := 10 ; findNthTerm(X) ) else skip; operation NthPrime(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(2, MAX + 1-1) do ( var check : int := 0 ; for j : Integer.subrange(2, ("" + ((sqrt(i))))->toInteger() + 1-1) do ( if i mod j = 0 then ( check := 1 ; break ) else skip) ; if check = 0 then ( count := count + 1 ) else skip ; if count = n then ( return i ; break ) else skip); operation NthFib(n : OclAny) : OclAny pre: true post: true activity: var f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 2)) ; var f->first() : OclAny := null; var f[1+1] : OclAny := null; Sequence{f->first(),f[1+1]} := Sequence{0,1} ; for i : Integer.subrange(2, n + 1-1) do ( f[i+1] := f[i - 1+1] + f[i - 2+1]) ; return f[n+1]; operation findNthTerm(n : OclAny) pre: true post: true activity: if n mod 2 = 0 then ( n := n div 2 ; n := NthPrime(n) ; execute (n)->display() ) else ( n := (n div 2) + 1 ; n := NthFib(n - 1) ; execute (n)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=list(input()) i=len(S)-1 while i>=4 : if S[i-4 : i+1]==['d','r','e','a','m']or S[i-4 : i+1]==['e','r','a','s','e']: i-=5 elif i-5>=0 and S[i-5 : i+1]==["e","r","a","s","e","r"]: i-=6 elif i-6>=0 and S[i-6 : i+1]==["d","r","e","a","m","e","r"]: i-=7 else : break if i==-1 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var i : double := (S)->size() - 1 ; while i >= 4 do ( if S.subrange(i - 4+1, i + 1) = Sequence{'d'}->union(Sequence{'r'}->union(Sequence{'e'}->union(Sequence{'a'}->union(Sequence{ 'm' })))) or S.subrange(i - 4+1, i + 1) = Sequence{'e'}->union(Sequence{'r'}->union(Sequence{'a'}->union(Sequence{'s'}->union(Sequence{ 'e' })))) then ( i := i - 5 ) else (if i - 5 >= 0 & S.subrange(i - 5+1, i + 1) = Sequence{"e"}->union(Sequence{"r"}->union(Sequence{"a"}->union(Sequence{"s"}->union(Sequence{"e"}->union(Sequence{ "r" }))))) then ( i := i - 6 ) else (if i - 6 >= 0 & S.subrange(i - 6+1, i + 1) = Sequence{"d"}->union(Sequence{"r"}->union(Sequence{"e"}->union(Sequence{"a"}->union(Sequence{"m"}->union(Sequence{"e"}->union(Sequence{ "r" })))))) then ( i := i - 7 ) else ( break ) ) ) ) ; if i = -1 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import Fraction T=int(input()) for test in range(1,T+1): people=[] G=int(input()) for g in range(G): di,hi,mi=[int(x)for x in input().split()] for h in range(hi): people.append((di,mi+h)) assert len(people)<=2 d0,m0=people[0] d1,m1=people[1] t0=Fraction((360-d0)*m0,360) t1=Fraction((360-d1)*m1,360) t=max(t0,t1) prejde0=t*360/m0 prejde1=t*360/m1 if(prejde0>=720-d0)or(prejde1>=720-d1): print('Case #{}:{}'.format(test,1)) else : print('Case #{}:{}'.format(test,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for test : Integer.subrange(1, T + 1-1) do ( var people : Sequence := Sequence{} ; var G : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for g : Integer.subrange(0, G-1) do ( var di : OclAny := null; var hi : OclAny := null; var mi : OclAny := null; Sequence{di,hi,mi} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for h : Integer.subrange(0, hi-1) do ( execute ((Sequence{di, mi + h}) : people))) ; assert (people)->size() <= 2 do "assertion failed" ; var d0 : OclAny := null; var m0 : OclAny := null; Sequence{d0,m0} := people->first() ; var d1 : OclAny := null; var m1 : OclAny := null; Sequence{d1,m1} := people[1+1] ; var t0 : OclAny := Fraction((360 - d0) * m0, 360) ; var t1 : OclAny := Fraction((360 - d1) * m1, 360) ; var t : OclAny := Set{t0, t1}->max() ; var prejde0 : double := t * 360 / m0 ; var prejde1 : double := t * 360 / m1 ; if ((prejde0->compareTo(720 - d0)) >= 0) or ((prejde1->compareTo(720 - d1)) >= 0) then ( execute (StringLib.interpolateStrings('Case #{}:{}', Sequence{test, 1}))->display() ) else ( execute (StringLib.interpolateStrings('Case #{}:{}', Sequence{test, 0}))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): print("YES" if input().count("N")!=1 else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (if input()->count("N") /= 1 then "YES" else "NO" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() S=S[: :-1] count=0 while(countcompareTo((S)->size())) < 0) do ( if ((S)->size() - count) < 5 then ( execute ('NO')->display() ; exit() ) else (if S[count+1] = 'e' & S[count + 1+1] = 's' & S[count + 2+1] = 'a' & S[count + 3+1] = 'r' & S[count + 4+1] = 'e' then ( count := count + 5 ) else (if S[count+1] = 'm' & S[count + 1+1] = 'a' & S[count + 2+1] = 'e' & S[count + 3+1] = 'r' & S[count + 4+1] = 'd' then ( count := count + 5 ) else (if ((S)->size() - count) = 5 then ( execute ('NO')->display() ; exit() ) else (if S[count+1] = 'r' & S[count + 1+1] = 'e' & S[count + 2+1] = 's' & S[count + 3+1] = 'a' & S[count + 4+1] = 'r' & S[count + 5+1] = 'e' then ( count := count + 6 ) else (if ((S)->size() - count) = 6 then ( execute ('NO')->display() ; exit() ) else (if S[count+1] = 'r' & S[count + 1+1] = 'e' & S[count + 2+1] = 'm' & S[count + 3+1] = 'a' & S[count + 4+1] = 'e' & S[count + 5+1] = 'r' & S[count + 6+1] = 'd' then ( count := count + 7 ) else ( execute ('NO')->display() ; exit() ) ) ) ) ) ) ) ) ; execute ('YES')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re s=input() s=re.sub('eraser?','1',s) s=re.sub('dream(er)?','1',s) print('YES' if len(s)==s.count('1')else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : String := (OclFile["System.in"]).readLine() ; s := (s).replaceAllMatches('eraser?', '1') ; s := (s).replaceAllMatches('dream(er)?', '1') ; execute (if (s)->size() = s->count('1') then 'YES' else 'NO' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys INF=float("inf") sys.setrecursionlimit(10**5) def yes(): print("YES") def no(): print("NO") template=["dream","dreamer","erase","eraser"] def dfs(s,i): if i==len(s): return True for t in template : if s[i :].startswith(t): if dfs(s,i+len(t)): return True return False def solve(S : str): if dfs(S,0): yes() else : no() return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() S=next(tokens) solve(S) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var INF : double := ("" + (("inf")))->toReal() ; sys.setrecursionlimit((10)->pow(5)) ; skip ; skip ; var template : Sequence := Sequence{"dream"}->union(Sequence{"dreamer"}->union(Sequence{"erase"}->union(Sequence{ "eraser" }))) ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation yes() pre: true post: true activity: execute ("YES")->display(); operation no() pre: true post: true activity: execute ("NO")->display(); operation dfs(s : OclAny, i : OclAny) : OclAny pre: true post: true activity: if i = (s)->size() then ( return true ) else skip ; for t : template do ( if s.subrange(i+1)->hasPrefix(t) then ( if dfs(s, i + (t)->size()) then ( return true ) else skip ) else skip) ; return false; operation solve(S : String) pre: true post: true activity: if dfs(S, 0) then ( yes() ) else ( no() ) ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var S : OclAny := (tokens).next() ; solve(S); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(input()) c=0 while len(s)>0 : p="1" q="1" r="1" if len(s)<5 : break if len(s)<=7 : if len(s)==5 : if s==list("dream")or s==list("erase"): c=1 break elif len(s)==6 : if s==list("eraser"): c=1 break elif len(s)==7 : if s==list("dreamer"): c=1 break else : p=s[len(s)-5 : len(s)] q=s[len(s)-6 : len(s)] r=s[len(s)-7 : len(s)] if p==list("dream")or p==list("erase"): del s[len(s)-5 : len(s)] elif q==list("eraser"): del s[len(s)-6 : len(s)] elif r==list("dreamer"): del s[len(s)-7 : len(s)] else : break print("YES" if c==1 else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var c : int := 0 ; while (s)->size() > 0 do ( var p : String := "1" ; var q : String := "1" ; var r : String := "1" ; if (s)->size() < 5 then ( break ) else skip ; if (s)->size() <= 7 then ( if (s)->size() = 5 then ( if s = ("dream")->characters() or s = ("erase")->characters() then ( c := 1 ; break ) else skip ) else (if (s)->size() = 6 then ( if s = ("eraser")->characters() then ( c := 1 ; break ) else skip ) else (if (s)->size() = 7 then ( if s = ("dreamer")->characters() then ( c := 1 ; break ) else skip ) else skip ) ) ) else ( p := s.subrange((s)->size() - 5+1, (s)->size()) ; q := s.subrange((s)->size() - 6+1, (s)->size()) ; r := s.subrange((s)->size() - 7+1, (s)->size()) ; if p = ("dream")->characters() or p = ("erase")->characters() then ( execute (s.subrange((s)->size() - 5+1, (s)->size()))->isDeleted() ) else (if q = ("eraser")->characters() then ( execute (s.subrange((s)->size() - 6+1, (s)->size()))->isDeleted() ) else (if r = ("dreamer")->characters() then ( execute (s.subrange((s)->size() - 7+1, (s)->size()))->isDeleted() ) else ( break ) ) ) )) ; execute (if c = 1 then "YES" else "NO" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def lastKDigits(a,n,k): num=(int)(math.pow(10,k)) mul=a[0]% num for i in range(1,n): a[i]=a[i]% num mul=(a[i]*mul)% num return mul a=[22,31,44,27,37,43] k=2 n=len(a) print(lastKDigits(a,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := Sequence{22}->union(Sequence{31}->union(Sequence{44}->union(Sequence{27}->union(Sequence{37}->union(Sequence{ 43 }))))) ; k := 2 ; n := (a)->size() ; execute (lastKDigits(a, n, k))->display(); operation lastKDigits(a : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var num : OclAny := (OclType["int"])((10)->pow(k)) ; var mul : int := a->first() mod num ; for i : Integer.subrange(1, n-1) do ( a[i+1] := a[i+1] mod num ; mul := (a[i+1] * mul) mod num) ; return mul; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=list(str(input())) i=0 counter=0 while icharacters() ; var i : int := 0 ; var counter : int := 0 ; while (i->compareTo((x)->size() - 1)) < 0 do ( if (x[i+1] = x[i + 1+1]) then ( if x[i + 1+1] = "0" then ( x[i + 1+1] := "1" ) else ( x[i + 1+1] := "0" ) ; counter := counter + 1 ) else skip ; i := i + 1) ; execute (counter)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def minimumChar(S1,S2): n,m=len(S1),len(S2) ans=sys.maxsize for i in range(m-n+1): minRemovedChar=0 for j in range(n): if(S1[j]!=S2[i+j]): minRemovedChar+=1 ans=min(minRemovedChar,ans) return ans if __name__=='__main__' : S1="abc" S2="paxzk" print(minimumChar(S1,S2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( S1 := "abc" ; S2 := "paxzk" ; execute (minimumChar(S1, S2))->display() ) else skip; operation minimumChar(S1 : OclAny, S2 : OclAny) : OclAny pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{(S1)->size(),(S2)->size()} ; var ans : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; for i : Integer.subrange(0, m - n + 1-1) do ( var minRemovedChar : int := 0 ; for j : Integer.subrange(0, n-1) do ( if (S1[j+1] /= S2[i + j+1]) then ( minRemovedChar := minRemovedChar + 1 ) else skip) ; ans := Set{minRemovedChar, ans}->min()) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) max_=-int('1'+'0'*1000) for i in range(n): f,t=map(int,input().split()) if t>k : tmp=f-(t-k) else : tmp=f if max_collect( _x | (OclType["int"])->apply(_x) ) ; var max_ : int := -("" + (('1' + StringLib.nCopies('0', 1000))))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var f : OclAny := null; var t : OclAny := null; Sequence{f,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (t->compareTo(k)) > 0 then ( var tmp : double := f - (t - k) ) else ( tmp := f ) ; if (max_->compareTo(tmp)) < 0 then ( max_ := tmp ) else skip) ; execute (max_)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) max_joy : int=-10**10 for i in range(n): f,t=map(int,input().split()) joy=f if t<=k else f-t+k if joy>max_joy : max_joy=joy print(max_joy) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var max_joy : int := (-10)->pow(10) ; for i : Integer.subrange(0, n-1) do ( var f : OclAny := null; var t : OclAny := null; Sequence{f,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var joy : OclAny := if (t->compareTo(k)) <= 0 then f else f - t + k endif ; if (joy->compareTo(max_joy)) > 0 then ( max_joy := joy ) else skip) ; execute (max_joy)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def print(*args,end='\n',sep=' ')->None : sys.stdout.write(sep.join(map(str,args))+end) def Solve(): n,k=list(map(int,input().split())) ans=-10**20 for i in range(n): f,t=list(map(int,input().split())) if t>k : ans=max(f-(t-k),ans) else : ans=max(f,ans) print(ans) if __name__=="__main__" : Solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; if __name__ = "__main__" then ( Solve() ) else skip; (funcdef def name print ( (typedargslist (args * (named_parameter (name args))) , (def_parameters (def_parameter (named_parameter (name end)) = (test (logical_test (comparison (expr (atom ' ')))))) , (def_parameter (named_parameter (name sep)) = (test (logical_test (comparison (expr (atom ' ')))))))) ) -> (test (logical_test (comparison (expr (atom None))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name sep)) (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name args)))))))) ))))))))) )))) + (expr (atom (name end))))))))) )))))))))))))) operation Solve() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : double := (-10)->pow(20) ; for i : Integer.subrange(0, n-1) do ( var f : OclAny := null; var t : OclAny := null; Sequence{f,t} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (t->compareTo(k)) > 0 then ( ans := Set{f - (t - k), ans}->max() ) else ( ans := Set{f, ans}->max() )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) maxx=-10**18 for i in range(n): line=list(map(int,input().split())) if line[1]<=k : maxx=max(line[0],maxx) else : maxx=max((line[0]-(line[1]-k),maxx)) print(maxx) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var maxx : double := (-10)->pow(18) ; for i : Integer.subrange(0, n-1) do ( var line : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (line[1+1]->compareTo(k)) <= 0 then ( maxx := Set{line->first(), maxx}->max() ) else ( maxx := (Sequence{line->first() - (line[1+1] - k), maxx})->max() )) ; execute (maxx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class DSU : def __init__(self,n): self.parent=list(range(n)) def find(self,v): u=v while self.parent[u]!=u : u=self.parent[u] while self.parent[v]!=v : x=self.parent[v] self.parent[v]=u v=x return u def union(self,v,u): u=self.find(u) v=self.find(v) self.parent[v]=u return u def check_corr(s): n=len(s) dsu=DSU(n) for idx in range(n): if s[idx]=='E' : dsu.union(idx,(idx+1)% n) for idx in range(n): if s[idx]=='N' : a=dsu.find(idx) b=dsu.find((idx+1)% n) if a==b : return "NO" return "YES" t=int(input()) for _ in range(t): s=input() print(check_corr(s)) ------------------------------------------------------------ OCL File: --------- class DSU { static operation newDSU() : DSU pre: true post: DSU->exists( _x | result = _x ); attribute parent : Sequence := (Integer.subrange(0, n-1)); operation initialise(n : OclAny) : DSU pre: true post: true activity: self.parent := (Integer.subrange(0, n-1)); return self; operation find(v : OclAny) : OclAny pre: true post: true activity: var u : OclAny := v ; while self.parent[u+1] /= u do ( u := self.parent[u+1]) ; while self.parent[v+1] /= v do ( var x : OclAny := self.parent[v+1] ; self.parent[v+1] := u ; v := x) ; return u; operation union(v : OclAny,u : OclAny) : OclAny pre: true post: true activity: u := self->indexOf(u) - 1 ; v := self->indexOf(v) - 1 ; self.parent[v+1] := u ; return u; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( s := (OclFile["System.in"]).readLine() ; execute (check_corr(s))->display()); operation check_corr(s : OclAny) : OclAny pre: true post: true activity: n := (s)->size() ; var dsu : DSU := (DSU.newDSU()).initialise(n) ; for idx : Integer.subrange(0, n-1) do ( if s[idx+1] = 'E' then ( dsu.union(idx, (idx + 1) mod n) ) else skip) ; for idx : Integer.subrange(0, n-1) do ( if s[idx+1] = 'N' then ( var a : int := dsu->indexOf(idx) - 1 ; var b : int := dsu->indexOf((idx + 1) mod n) - 1 ; if a = b then ( return "NO" ) else skip ) else skip) ; return "YES"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s,q=map(int,input().split()) l_p=-1e10 for _ in range(s): f,t=map(int,input().split()) l_p=max(f-max(0,t-q),l_p) print(l_p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := null; var q : OclAny := null; Sequence{s,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l_p : double := -("1e10")->toReal() ; for _anon : Integer.subrange(0, s-1) do ( var f : OclAny := null; var t : OclAny := null; Sequence{f,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; l_p := Set{f - Set{0, t - q}->max(), l_p}->max()) ; execute (l_p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print("ai1"+"3"*(int(input())//100+3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ("ai1" + StringLib.nCopies("3", (("" + (((OclFile["System.in"]).readLine())))->toInteger() div 100 + 3)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) n=x/100 def f(n): if n==0 : return 'ai1333' else : a=f(n-1) b=a+'3' return b print(f(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : double := x / 100 ; skip ; execute (f(n))->display(); operation f(n : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( return 'ai1333' ) else ( var a : String := f(n - 1) ; var b : String := a + '3' ; return b ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math x=int(input()) x=math.floor(x/100) print('ai1333'+'3'*x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; x := (x / 100)->floor() ; execute ('ai1333' + StringLib.nCopies('3', x))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute_lps(s): n=len(s) lps=[0 for i in range(n)] Len=0 lps[0]=0 i=1 while(isize() ; var lps : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var Len : int := 0 ; lps->first() := 0 ; var i : int := 1 ; while ((i->compareTo(n)) < 0) do ( if (s[i+1] = s[Len+1]) then ( Len := Len + 1 ; lps[i+1] := Len ; i := i + 1 ) else ( if (Len /= 0) then ( Len := lps[Len - 1+1] ) else ( lps[i+1] := 0 ; i := i + 1 ) )) ; return lps; operation Longestsubstring(s : OclAny) pre: true post: true activity: lps := compute_lps(s) ; n := (s)->size() ; if (lps[n - 1+1] = 0) then ( execute (-1)->display() ; exit() ) else skip ; for i : Integer.subrange(0, n - 1-1) do ( if (lps[i+1] = lps[n - 1+1]) then ( execute (s.subrange(0+1, lps[i+1]))->display() ; exit() ) else skip) ; if (lps[lps[n - 1+1] - 1+1] = 0) then ( execute (-1)->display() ) else ( execute (s.subrange(0+1, lps[lps[n - 1+1] - 1+1]))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) ans=x//100 AI="ai1333" for i in range(0,ans): AI=AI+"3" print(AI) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := x div 100 ; var AI : String := "ai1333" ; for i : Integer.subrange(0, ans-1) do ( AI := AI + "3") ; execute (AI)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) print("ai1333{}".format("3"*(x//100))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (StringLib.interpolateStrings("ai1333{}", Sequence{StringLib.nCopies("3", (x div 100))}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=100005 def createHash(hash,maxElement): prev=0 curr=1 hash.add(prev) hash.add(curr) while(curr<=maxElement): temp=curr+prev hash.add(temp) prev=curr curr=temp def longestFibonacciSubsequence(arr,n): hash=set() createHash(hash,max(arr)) answer=0 for i in range(n): if(arr[i]in hash): answer+=1 return answer if __name__=='__main__' : arr=[3,4,11,2,9,21] n=len(arr) print(longestFibonacciSubsequence(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 100005 ; skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{3}->union(Sequence{4}->union(Sequence{11}->union(Sequence{2}->union(Sequence{9}->union(Sequence{ 21 }))))) ; n := (arr)->size() ; execute (longestFibonacciSubsequence(arr, n))->display() ) else skip; operation createHash(hash : OclAny, maxElement : OclAny) pre: true post: true activity: var prev : int := 0 ; var curr : int := 1 ; execute ((prev) : hash) ; execute ((curr) : hash) ; while ((curr->compareTo(maxElement)) <= 0) do ( var temp : int := curr + prev ; execute ((temp) : hash) ; prev := curr ; curr := temp); operation longestFibonacciSubsequence(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: hash := Set{}->union(()) ; createHash(hash, (arr)->max()) ; var answer : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ((hash)->includes(arr[i+1])) then ( answer := answer + 1 ) else skip) ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findPrime(MAX): pm=[True]*(MAX+1) pm[0],pm[1]=False,False for i in range(2,MAX+1): if pm[i]==True : for j in range(2*i,MAX+1,i): pm[j]=False prime=[] for i in range(0,MAX+1): if pm[i]==True : prime.append(i) return prime def findSmallest(arr,n): MAX=max(arr) prime=findPrime(MAX) s=set() for i in range(0,n): s.add(arr[i]) ans=-1 for i in range(0,len(prime)): if prime[i]not in s : ans=prime[i] break return ans if __name__=="__main__" : arr=[3,0,1,2,7] n=len(arr) if(findSmallest(arr,n)==-1): print("No prime number missing") else : print(findSmallest(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{3}->union(Sequence{0}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 7 })))) ; n := (arr)->size() ; if (findSmallest(arr, n) = -1) then ( execute ("No prime number missing")->display() ) else ( execute (findSmallest(arr, n))->display() ) ) else skip; operation findPrime(MAX : OclAny) : OclAny pre: true post: true activity: var pm : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (MAX + 1)) ; var pm->first() : OclAny := null; var pm[1+1] : OclAny := null; Sequence{pm->first(),pm[1+1]} := Sequence{false,false} ; for i : Integer.subrange(2, MAX + 1-1) do ( if pm[i+1] = true then ( for j : Integer.subrange(2 * i, MAX + 1-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ( pm[j+1] := false) ) else skip) ; var prime : Sequence := Sequence{} ; for i : Integer.subrange(0, MAX + 1-1) do ( if pm[i+1] = true then ( execute ((i) : prime) ) else skip) ; return prime; operation findSmallest(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: MAX := (arr)->max() ; prime := findPrime(MAX) ; var s : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( execute ((arr[i+1]) : s)) ; var ans : int := -1 ; for i : Integer.subrange(0, (prime)->size()-1) do ( if (s)->excludes(prime[i+1]) then ( ans := prime[i+1] ; break ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W,h,w=map(int,input().split()) a=[[0]*W for i in range(H)] INF=10**9 for i in range(H): for j in range(W): if i % h==h-1 and j % w==w-1 : a[i][j]=-INF elif i % h==0 and j % w==0 : a[i][j]=INF-1 if sum([sum(line)for line in a])>0 : print("Yes") for i in range(H): print(*a[i]) else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; var h : OclAny := null; var w : OclAny := null; Sequence{H,W,h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, H-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, W))) ; var INF : double := (10)->pow(9) ; for i : Integer.subrange(0, H-1) do ( for j : Integer.subrange(0, W-1) do ( if i mod h = h - 1 & j mod w = w - 1 then ( a[i+1][j+1] := -INF ) else (if i mod h = 0 & j mod w = 0 then ( a[i+1][j+1] := INF - 1 ) else skip))) ; if (a->select(line | true)->collect(line | ((line)->sum())))->sum() > 0 then ( execute ("Yes")->display() ; for i : Integer.subrange(0, H-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))->display()) ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def main(): H,W,h,w=map(int,input().split()) if H*W-(H//h)*(W//w)*w*h==0 : print("No") else : if W % w!=0 : ans=[0 for _ in range(W)] co=[0 for _ in range(W+1)] for i in range(1,w): co[i]=(W-i)//w+1 for i in range(w,W+1): co[i]=co[i-w]-1 for i in range(W): ans[i]=co[i+1]-co[i] print("Yes") for i in range(H): print(*ans) else : ans=[0 for _ in range(H)] co=[0 for _ in range(H+1)] for i in range(1,h): co[i]=(H-i)//h+1 for i in range(h,H+1): co[i]=co[i-h]-1 for i in range(H): ans[i]=co[i+1]-co[i] print("Yes") for i in range(H): print(*list(ans[i]for _ in range(W))) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; var h : OclAny := null; var w : OclAny := null; Sequence{H,W,h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if H * W - (H div h) * (W div w) * w * h = 0 then ( execute ("No")->display() ) else ( if W mod w /= 0 then ( var ans : Sequence := Integer.subrange(0, W-1)->select(_anon | true)->collect(_anon | (0)) ; var co : Sequence := Integer.subrange(0, W + 1-1)->select(_anon | true)->collect(_anon | (0)) ; for i : Integer.subrange(1, w-1) do ( co[i+1] := (W - i) div w + 1) ; for i : Integer.subrange(w, W + 1-1) do ( co[i+1] := co[i - w+1] - 1) ; for i : Integer.subrange(0, W-1) do ( ans[i+1] := co[i + 1+1] - co[i+1]) ; execute ("Yes")->display() ; for i : Integer.subrange(0, H-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()) ) else ( ans := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (0)) ; co := Integer.subrange(0, H + 1-1)->select(_anon | true)->collect(_anon | (0)) ; for i : Integer.subrange(1, h-1) do ( co[i+1] := (H - i) div h + 1) ; for i : Integer.subrange(h, H + 1-1) do ( co[i+1] := co[i - h+1] - 1) ; for i : Integer.subrange(0, H-1) do ( ans[i+1] := co[i + 1+1] - co[i+1]) ; execute ("Yes")->display() ; for i : Integer.subrange(0, H-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name W)))))))) ))))))))) )))))))))->display()) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) if(b-a)>=10 : print(0) else : res=1 for i in range(a+1,b+1): res=(res*(i % 10))% 10 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (b - a) >= 10 then ( execute (0)->display() ) else ( var res : int := 1 ; for i : Integer.subrange(a + 1, b + 1-1) do ( res := (res * (i mod 10)) mod 10) ; execute (res)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import sys import numpy as np if os.getenv("LOCAL"): sys.stdin=open("_in.txt","r") sys.setrecursionlimit(2147483647) INF=float("inf") IINF=10**18 MOD=10**9+7 H,W,A,B=list(map(int,sys.stdin.readline().split())) if H % A==0 and W % B==0 : print('No') exit() def cumsum(S,s): ret=np.zeros(S+1,dtype=int) n=0 for i in range(0,len(ret),s): ret[i]=n n-=1 for a in range(1,s): n=1e7 for i in range(a,len(ret),s): ret[i]=n n-=1 return ret print('Yes') if H % A!=0 : col=np.diff(cumsum(H,A)) ans=np.tile(col,W).reshape(W,H).T else : col=np.diff(cumsum(W,B)) ans=np.tile(col,H).reshape(H,W) print('\n'.join(map(lambda r : ' '.join(r),ans.astype(str)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if os.getenv("LOCAL") then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("_in.txt")) ) else skip ; sys.setrecursionlimit(2147483647) ; var INF : double := ("" + (("inf")))->toReal() ; var IINF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; var H : OclAny := null; var W : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{H,W,A,B} := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if H mod A = 0 & W mod B = 0 then ( execute ('No')->display() ; exit() ) else skip ; skip ; execute ('Yes')->display() ; if H mod A /= 0 then ( var col : (trailer . (name diff) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name cumsum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name H))))))) , (argument (test (logical_test (comparison (expr (atom (name A)))))))) ))))))))) ))) := ; var ans : OclAny := np.tile(col, W).reshape(W, H).T ) else ( col := ; ans := np.tile(col, H).reshape(H, W) ) ; execute (StringLib.sumStringsWithSeparator(((ans.astype(OclType["String"]))->collect( _x | (lambda r : OclAny in (StringLib.sumStringsWithSeparator((r), ' ')))->apply(_x) )), ' '))->display(); operation cumsum(S : OclAny, s : OclAny) : OclAny pre: true post: true activity: var ret : Sequence := MatrixLib.singleValueMatrix(S + 1, 0.0) ; var n : int := 0 ; for i : Integer.subrange(0, (ret)->size()-1)->select( $x | ($x - 0) mod s = 0 ) do ( ret[i+1] := n ; n := n - 1) ; for a : Integer.subrange(1, s-1) do ( n := ("1e7")->toReal() ; for i : Integer.subrange(a, (ret)->size()-1)->select( $x | ($x - a) mod s = 0 ) do ( ret[i+1] := n ; n := n - 1)) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W,h,w=map(int,input().split()) def solve(H,W,h,w): if(W % w==0 and H % h==0): return False,[] if(W % w==0): return True,solve_vertical(H,W,h,w) return True,solve_horizontal(H,W,h,w) def solve_horizontal(H,W,h,w): return[solve_horizontal_core(W,w)]*H def solve_horizontal_core(W,w): m,r=divmod(W,w) row=[0]*W row[0]=m+1 row[w-1]=-m-2 for i in range(w,W): row[i]=row[i-w] return row def solve_vertical(H,W,h,w): col=solve_horizontal_core(H,h) m=[] for c in col : m.append([c]*W) return m yesno,mat=solve(H,W,h,w) if yesno : print('Yes') for row in mat : print(*row) else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; var h : OclAny := null; var w : OclAny := null; Sequence{H,W,h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; skip ; skip ; skip ; var yesno : OclAny := null; var mat : OclAny := null; Sequence{yesno,mat} := solve(H, W, h, w) ; if yesno then ( execute ('Yes')->display() ; for row : mat do ( execute ((argument * (test (logical_test (comparison (expr (atom (name row))))))))->display()) ) else ( execute ('No')->display() ); operation solve(H : OclAny, W : OclAny, h : OclAny, w : OclAny) : OclAny pre: true post: true activity: if (W mod w = 0 & H mod h = 0) then ( return false, Sequence{} ) else skip ; if (W mod w = 0) then ( return true, solve_vertical(H, W, h, w) ) else skip ; return true, solve_horizontal(H, W, h, w); operation solve_horizontal(H : OclAny, W : OclAny, h : OclAny, w : OclAny) : OclAny pre: true post: true activity: return MatrixLib.elementwiseMult(Sequence{ solve_horizontal_core(W, w) }, H); operation solve_horizontal_core(W : OclAny, w : OclAny) : OclAny pre: true post: true activity: var m : OclAny := null; var r : OclAny := null; Sequence{m,r} := Sequence{(W div w), (W mod w)} ; var row : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, W) ; row->first() := m + 1 ; row[w - 1+1] := -m - 2 ; for i : Integer.subrange(w, W-1) do ( row[i+1] := row[i - w+1]) ; return row; operation solve_vertical(H : OclAny, W : OclAny, h : OclAny, w : OclAny) : OclAny pre: true post: true activity: var col : OclAny := solve_horizontal_core(H, h) ; var m : Sequence := Sequence{} ; for c : col do ( execute ((MatrixLib.elementwiseMult(Sequence{ c }, W)) : m)) ; return m; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W,h,w=[int(x)for x in input().split('')] if W % w!=0 : r=W % w n=int(W/w) n=n+1 print('Yes') for i in range(H): for k in range(W): if(k+1)% w==0 : print(-n*(w-1)-1,end='') else : print(n,end='') if k==W-1 : print() else : print(end='') elif H % h!=0 : r=H % h n=int(H/h) n=n+1 print('Yes') store=0 for i in range(H): if(i+1)% h==0 : store=-n*(h-1)-1 else : store=n for k in range(W): if k==W-1 : print(store) else : print(store,end='') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; var h : OclAny := null; var w : OclAny := null; Sequence{H,W,h,w} := input().split('')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if W mod w /= 0 then ( var r : int := W mod w ; var n : int := ("" + ((W / w)))->toInteger() ; n := n + 1 ; execute ('Yes')->display() ; for i : Integer.subrange(0, H-1) do ( for k : Integer.subrange(0, W-1) do ( if (k + 1) mod w = 0 then ( execute (-n * (w - 1) - 1)->display() ) else ( execute (n)->display() ) ; if k = W - 1 then ( execute (->display() ) else ( execute ((argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom '')))))))->display() ))) ) else (if H mod h /= 0 then ( r := H mod h ; n := ("" + ((H / h)))->toInteger() ; n := n + 1 ; execute ('Yes')->display() ; var store : int := 0 ; for i : Integer.subrange(0, H-1) do ( if (i + 1) mod h = 0 then ( store := -n * (h - 1) - 1 ) else ( store := n ) ; for k : Integer.subrange(0, W-1) do ( if k = W - 1 then ( execute (store)->display() ) else ( execute (store)->display() ))) ) else ( execute ('No')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (a,b)=map(int,input().split(' ')) if abs(a-b)>1 or a==b==0 : print('NO') else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{a, b} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; if (a - b)->abs() > 1 or a = b & (b == 0) then ( execute ('NO')->display() ) else ( execute ('YES')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import combinations proplems,mini,maxi,dif=map(int,input().split()); levels=list(map(int,input().split())); summ=0 arr=[combinations(levels,i)for i in range(2,proplems+1)] for i in arr : x=list(i) for j in x : z=0 ; big=0 ; smal=10**6+1 smal=min(smal,min(j)) big=max(big,max(j)) z+=sum(j) if mini<=z<=maxi and big-smal>=dif : summ+=1 print(summ) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var proplems : OclAny := null; var mini : OclAny := null; var maxi : OclAny := null; var dif : OclAny := null; Sequence{proplems,mini,maxi,dif} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var levels : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); var summ : int := 0 ; var arr : Sequence := Integer.subrange(2, proplems + 1-1)->select(i | true)->collect(i | (combinations(levels, i))) ; for i : arr do ( var x : Sequence := (i) ; for j : x do ( var z : int := 0; var big : int := 0; var smal : double := (10)->pow(6) + 1 ; smal := Set{smal, (j)->min()}->min() ; big := Set{big, (j)->max()}->max() ; z := z + (j)->sum() ; if (mini->compareTo(z)) <= 0 & (z <= maxi) & (big - smal->compareTo(dif)) >= 0 then ( summ := summ + 1 ) else skip)) ; execute (summ)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,l,r,x=map(int,input().split()) difficulty=list(map(int,input().split())) total=0 mask=0 while mask<(1<hard : hard=difficulty[i] if difficulty[i]=x and turns>1 : total+=1 mask+=1 print(total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; var r : OclAny := null; var x : OclAny := null; Sequence{n,l,r,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var difficulty : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var total : int := 0 ; var mask : int := 0 ; while (mask->compareTo((1 * (2->pow(n))))) < 0 do ( var summ : int := 0 ; var turns : int := 0 ; var easy : int := 0 ; var hard : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (MathLib.bitwiseAnd(mask, 1 * (2->pow(i)))) then ( summ := summ + difficulty[i+1] ; turns := turns + 1 ; if (difficulty[i+1]->compareTo(hard)) > 0 then ( hard := difficulty[i+1] ) else skip ; if (difficulty[i+1]->compareTo(easy)) < 0 then ( easy := difficulty[i+1] ) else (if difficulty[i+1] /= easy or difficulty[i+1] /= hard then ( if not(hard) then ( hard := difficulty[i+1] ) else skip ; if not(easy) then ( easy := difficulty[i+1] ) else skip ) else skip) ) else skip) ; if (l->compareTo(summ)) <= 0 & (summ <= r) & (hard - easy->compareTo(x)) >= 0 & turns > 1 then ( total := total + 1 ) else skip ; mask := mask + 1) ; execute (total)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().rstrip("\n") read_int=lambda : int(input()) read_ints=lambda : list(map(int,input().split())) read_str=lambda : input().strip() read_strs=lambda : read_str().split(' ') def solve(): n,l,r,x=read_ints() a=read_ints() cnt=0 def dfs(p,s,mx,mn): nonlocal cnt if p>=n : if mx-mn>=x and l<=s<=r : cnt+=1 return dfs(p+1,s+a[p],max(mx,a[p]),min(mn,a[p])) dfs(p+1,s,mx,mn) dfs(0,0,0,float("inf")) print(cnt) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute cnt : OclAny; operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip("\n")) ; var read_int : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var read_ints : Function := lambda $$ : OclAny in (((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var read_str : Function := lambda $$ : OclAny in (input->apply()->trim()) ; var read_strs : Function := lambda $$ : OclAny in (read_str->apply().split(' ')) ; skip ; solve(); operation solve() pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; var r : OclAny := null; var x : OclAny := null; Sequence{n,l,r,x} := read_ints->apply() ; var a : OclAny := read_ints->apply() ; var cnt : int := 0 ; skip ; dfs(0, 0, 0, ("" + (("inf")))->toReal()) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().rstrip("\n") read_int=lambda : int(input()) read_ints=lambda : list(map(int,input().split())) read_str=lambda : input().strip() read_strs=lambda : read_str().split(' ') def solve2(): n,l,r,x=read_ints() a=read_ints() cnt=0 for mask in range(0,1<=x : cnt+=1 print(cnt) solve2() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip("\n")) ; var read_int : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var read_ints : Function := lambda $$ : OclAny in (((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var read_str : Function := lambda $$ : OclAny in (input->apply()->trim()) ; var read_strs : Function := lambda $$ : OclAny in (read_str->apply().split(' ')) ; skip ; solve2(); operation solve2() pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; var r : OclAny := null; var x : OclAny := null; Sequence{n,l,r,x} := read_ints->apply() ; var a : OclAny := read_ints->apply() ; var cnt : int := 0 ; for mask : Integer.subrange(0, 1 * (2->pow(n))-1) do ( var s : OclAny := null; var mx : OclAny := null; var mn : OclAny := null; Sequence{s,mx,mn} := Sequence{0,0,("" + (('inf')))->toReal()} ; for bit : Integer.subrange(0, n-1) do ( if MathLib.bitwiseAnd(mask, (1 * (2->pow(bit)))) then ( s := s + a[bit+1] ; var mx : OclAny := Set{mx, a[bit+1]}->max() ; var mn : OclAny := Set{mn, a[bit+1]}->min() ) else skip) ; if (l->compareTo(s)) <= 0 & (s <= r) & (mx - mn->compareTo(x)) >= 0 then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().rstrip("\n") read_int=lambda : int(input()) read_ints=lambda : list(map(int,input().split())) read_str=lambda : input().strip() read_strs=lambda : read_str().split(' ') def solve(): n,l,r,x=read_ints() a=read_ints() cnt=0 def dfs(p,s,mx,mn): nonlocal cnt if p>=n : if mx-mn>=x and l<=s<=r : cnt+=1 return dfs(p+1,s+a[p],max(mx,a[p]),min(mn,a[p])) dfs(p+1,s,mx,mn) dfs(0,0,0,float("inf")) print(cnt) def solve2(): n,l,r,x=read_ints() a=read_ints() cnt=0 for mask in range(0,1<=x : cnt+=1 print(cnt) solve2() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute cnt : OclAny; operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip("\n")) ; var read_int : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var read_ints : Function := lambda $$ : OclAny in (((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var read_str : Function := lambda $$ : OclAny in (input->apply()->trim()) ; var read_strs : Function := lambda $$ : OclAny in (read_str->apply().split(' ')) ; skip ; skip ; solve2(); operation solve() pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; var r : OclAny := null; var x : OclAny := null; Sequence{n,l,r,x} := read_ints->apply() ; var a : OclAny := read_ints->apply() ; var cnt : int := 0 ; skip ; dfs(0, 0, 0, ("" + (("inf")))->toReal()) ; execute (cnt)->display(); operation solve2() pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; var r : OclAny := null; var x : OclAny := null; Sequence{n,l,r,x} := read_ints->apply() ; a := read_ints->apply() ; cnt := 0 ; for mask : Integer.subrange(0, 1 * (2->pow(n))-1) do ( Sequence{s,mx,mn} := Sequence{0,0,("" + (('inf')))->toReal()} ; for bit : Integer.subrange(0, n-1) do ( if MathLib.bitwiseAnd(mask, (1 * (2->pow(bit)))) then ( s := s + a[bit+1] ; mx := Set{mx, a[bit+1]}->max() ; mn := Set{mn, a[bit+1]}->min() ) else skip) ; if (l->compareTo(s)) <= 0 & (s <= r) & (mx - mn->compareTo(x)) >= 0 then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n,m,x,y=list(map(int,input().split())) arr=[] for i in range(n): arr.extend(list(map(str,input().split('*')))) cost=0 for ele in arr : l=len(ele) if l>0 : if y<=x*2 : if l % 2==0 : cost+=(l//2)*y elif l==1 : cost+=x else : cost+=x l-=1 cost+=(l//2)*y else : cost+=l*x return cost for t in range(0,int(input())): print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (solve())->display()); operation solve() : OclAny pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,m,x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var arr : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( arr := arr->union(((input().split('*'))->collect( _x | (OclType["String"])->apply(_x) )))) ; var cost : int := 0 ; for ele : arr do ( var l : int := (ele)->size() ; if l > 0 then ( if (y->compareTo(x * 2)) <= 0 then ( if l mod 2 = 0 then ( cost := cost + (l div 2) * y ) else (if l = 1 then ( cost := cost + x ) else ( cost := cost + x ; l := l - 1 ; cost := cost + (l div 2) * y ) ) ) else ( cost := cost + l * x ) ) else skip) ; return cost; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,m,x,y=list(map(int,input().split())) cost=0 for _ in range(n): row=input() if 2*xtoInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,m,x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cost : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var row : String := (OclFile["System.in"]).readLine() ; if (2 * x->compareTo(y)) < 0 or m = 1 then ( for tile : row->characters() do ( if tile = '.' then ( cost := cost + x ) else skip) ) else ( var i : int := 0 ; while (i->compareTo(m)) < 0 do ( if row[i+1] = '.' then ( if (i + 1->compareTo(m)) < 0 & row[i + 1+1] = '.' then ( cost := cost + y ; i := i + 1 ) else ( cost := cost + x ) ) else skip ; i := i + 1) )) ; execute (cost)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,n1=[int(i)for i in input().split()] if n1-n>=10 : print("0") else : if(n1 % 10>n % 10): pro=1 for i in range((n % 10)+1,(n1 % 10)+1): pro*=i print(pro % 10) elif n==n1 : print("1") else : print("0") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var n1 : OclAny := null; Sequence{n,n1} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if n1 - n >= 10 then ( execute ("0")->display() ) else ( if ((n1 mod 10->compareTo(n mod 10)) > 0) then ( var pro : int := 1 ; for i : Integer.subrange((n mod 10) + 1, (n1 mod 10) + 1-1) do ( pro := pro * i) ; execute (pro mod 10)->display() ) else (if n = n1 then ( execute ("1")->display() ) else ( execute ("0")->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input exec(int(I())*"n,m,x,y=map(int,I().split());print(sum(l//2*min(2*x,y)+l%2*x for _ in[0]*n for l in map(len,I().split('*'))));") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name I)) (trailer (arguments ( ))))))))) )))) * (expr (atom "n,m,x,y=map(int,I().split());print(sum(l//2*min(2*x,y)+l%2*x for _ in[0]*n for l in map(len,I().split('*'))));"))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n,m,x,y=map(int,input().split()) a=[input()for i in range(n)] s=0 for i in a : if i.count('..')==0 : s+=i.count('.')*x else : if x<=y//2 : s+=i.count('.')*x else : p=i.replace('..','--') s+=p.count('--')*y+p.count('.')*x print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,m,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var s : int := 0 ; for i : a do ( if i->count('..') = 0 then ( s := s + i->count('.') * x ) else ( if (x->compareTo(y div 2)) <= 0 then ( s := s + i->count('.') * x ) else ( var p : String := i.replace('..', '--') ; s := s + p->count('--') * y + p->count('.') * x ) )) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countOccurrences(x,d): count=0 ; while(x): if(x % 10==d): count+=1 ; x=int(x/10); return count ; def maxOccurring(x): if(x<0): x=-x ; result=0 ; max_count=1 ; for d in range(10): count=countOccurrences(x,d); if(count>=max_count): max_count=count ; result=d ; return result ; x=1223355 ; print("Max occurring digit is",maxOccurring(x)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; x := 1223355; ; execute ("Max occurring digit is")->display();; operation countOccurrences(x : OclAny, d : OclAny) pre: true post: true activity: var count : int := 0; ; while (x) do ( if (x mod 10 = d) then ( count := count + 1; ) else skip ; x := ("" + ((x / 10)))->toInteger();) ; return count;; operation maxOccurring(x : OclAny) pre: true post: true activity: if (x < 0) then ( x := -x; ) else skip ; var result : int := 0; ; var max_count : int := 1; ; for d : Integer.subrange(0, 10-1) do ( count := countOccurrences(x, d); ; if ((count->compareTo(max_count)) >= 0) then ( max_count := count; ; result := d; ) else skip) ; return result;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n,m,x,y=map(int,input().split()) a=[input()for i in range(n)] s=0 for i in a : if i.count('..')==0 or x<=y//2 : s+=i.count('.')*x else : p=i.replace('..','--') s+=p.count('--')*y+p.count('.')*x print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,m,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var s : int := 0 ; for i : a do ( if i->count('..') = 0 or (x->compareTo(y div 2)) <= 0 then ( s := s + i->count('.') * x ) else ( var p : String := i.replace('..', '--') ; s := s + p->count('--') * y + p->count('.') * x )) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline def Interactive(*query): print(*query) sys.stdout.flush() return input() N=int(readline()) if N//2 % 2 : print("!",-1) else : left=0 right=N//2-1 al,bl=int(Interactive("?",left+1)),int(Interactive("?",left+N//2+1)) ar,br=int(Interactive("?",right+1)),int(Interactive("?",right+N//2+1)) if al==bl : print("!",left+1) exit() if ar==br : print("!",right+1) exit() while lefttoInteger() ; if N div 2 mod 2 then ( execute ("!")->display() ) else ( var left : int := 0 ; var right : double := N div 2 - 1 ; var al : OclAny := null; var bl : OclAny := null; Sequence{al,bl} := Sequence{("" + ((Interactive("?", left + 1))))->toInteger(),("" + ((Interactive("?", left + N div 2 + 1))))->toInteger()} ; var ar : OclAny := null; var br : OclAny := null; Sequence{ar,br} := Sequence{("" + ((Interactive("?", right + 1))))->toInteger(),("" + ((Interactive("?", right + N div 2 + 1))))->toInteger()} ; if al = bl then ( execute ("!")->display() ; exit() ) else skip ; if ar = br then ( execute ("!")->display() ; exit() ) else skip ; while (left->compareTo(right)) < 0 do ( var mid : int := (left + right) div 2 ; var am : OclAny := null; var bm : OclAny := null; Sequence{am,bm} := Sequence{("" + ((Interactive("?", mid + 1))))->toInteger(),("" + ((Interactive("?", mid + N div 2 + 1))))->toInteger()} ; if am = bm then ( execute ("!")->display() ; exit() ) else skip ; if ((al->compareTo(bl)) < 0) = ((am->compareTo(bm)) < 0) then ( left := mid ) else ( right := mid )) ); operation Interactive(query : OclAny : Sequence(OclAny)) : OclAny pre: true post: true activity: (args * (named_parameter (name query))) execute ((argument * (test (logical_test (comparison (expr (atom (name query))))))))->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))) ; return (OclFile["System.in"]).readLine(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def ask(x): print('? %d' % x) sys.stdout.flush() x=int(input()) return x n=int(input()) t=n//2 if t & 1 : print('!-1') sys.stdout.flush() sys.exit() l=1 r=n while l>1 if ask(mid)>=ask((mid+t-1)% n+1): r=mid else : l=mid+1 print('! %d' % l) sys.stdout.flush() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : int := n div 2 ; if MathLib.bitwiseAnd(t, 1) then ( execute ('!-1')->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))) ; sys.exit() ) else skip ; var l : int := 1 ; var r : int := n ; while (l->compareTo(r)) < 0 do ( var mid : int := (l + r) /(2->pow(1)) ; if (ask(mid)->compareTo(ask((mid + t - 1) mod n + 1))) >= 0 then ( r := mid ) else ( l := mid + 1 )) ; execute (StringLib.format('! %d',l))->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))); operation ask(x : OclAny) : OclAny pre: true post: true activity: execute (StringLib.format('? %d',x))->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))) ; x := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def check(i,n): a=i b=i+n//2 print(f'?{a}') sys.stdout.flush() a1=int(input()) print(f'?{b}') sys.stdout.flush() b1=int(input()) return[a1,b1] def process(n): if n % 4==2 : print('!-1') sys.stdout.flush() sys.exit() else : a1,b1=check(1,n) if a1==b1 : print('! 1') sys.stdout.flush() sys.exit() if a1>b1 : pos=1 neg=1+n//2 else : pos=1+n//2 neg=1 while True : m1=(pos+neg)//2 a1,b1=check(m1,n) if a1==b1 : print(f'!{m1}') sys.stdout.flush() sys.exit() elif a1>b1 : pos=m1 else : neg=m1 n=int(input()) process(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; process(n); operation check(i : OclAny, n : OclAny) : OclAny pre: true post: true activity: var a : OclAny := i ; var b : OclAny := i + n div 2 ; execute (StringLib.formattedString('?{a}'))->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))) ; var a1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (StringLib.formattedString('?{b}'))->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))) ; var b1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; return Sequence{a1}->union(Sequence{ b1 }); operation process(n : OclAny) pre: true post: true activity: if n mod 4 = 2 then ( execute ('!-1')->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))) ; sys.exit() ) else ( Sequence{a1,b1} := check(1, n) ; if a1 = b1 then ( execute ('! 1')->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))) ; sys.exit() ) else skip ; if (a1->compareTo(b1)) > 0 then ( var pos : int := 1 ; var neg : int := 1 + n div 2 ) else ( pos := 1 + n div 2 ; neg := 1 ) ; while true do ( var m1 : int := (pos + neg) div 2 ; Sequence{a1,b1} := check(m1, n) ; if a1 = b1 then ( execute (StringLib.formattedString('!{m1}'))->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))) ; sys.exit() ) else (if (a1->compareTo(b1)) > 0 then ( pos := m1 ) else ( neg := m1 ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def ask(x): print('? %d' % x) sys.stdout.flush() x=int(input()) return x n=int(input()) t=n//2 if t & 1 : print('!-1') sys.stdout.flush() sys.exit() l=1 r=n while l>1 if ask(mid)>=ask((mid+t-1)% n+1): r=mid else : l=mid+1 print('! %d' % l) sys.stdout.flush() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : int := n div 2 ; if MathLib.bitwiseAnd(t, 1) then ( execute ('!-1')->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))) ; sys.exit() ) else skip ; var l : int := 1 ; var r : int := n ; while (l->compareTo(r)) < 0 do ( var mid : int := (l + r) /(2->pow(1)) ; if (ask(mid)->compareTo(ask((mid + t - 1) mod n + 1))) >= 0 then ( r := mid ) else ( l := mid + 1 )) ; execute (StringLib.format('! %d',l))->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))); operation ask(x : OclAny) : OclAny pre: true post: true activity: execute (StringLib.format('? %d',x))->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))) ; x := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def a(x): print('? %d' % x) sys.stdout.flush() x=int(input()) return x n=int(input()) t=n//2 if t & 1 : print('!-1') sys.stdout.flush() sys.exit() l=1 r=n while l>1 if a(m)>=a((m+t-1)% n+1): r=m else : l=m+1 print('! %d' % l) sys.stdout.flush() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : int := n div 2 ; if MathLib.bitwiseAnd(t, 1) then ( execute ('!-1')->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))) ; sys.exit() ) else skip ; var l : int := 1 ; var r : int := n ; while (l->compareTo(r)) < 0 do ( var m : int := (l + r) /(2->pow(1)) ; if (a(m)->compareTo(a((m + t - 1) mod n + 1))) >= 0 then ( r := m ) else ( l := m + 1 )) ; execute (StringLib.format('! %d',l))->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))); operation a(x : OclAny) : OclAny pre: true post: true activity: execute (StringLib.format('? %d',x))->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))) ; x := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): ans=max(range(1,1001),key=count_solutions) return str(ans) def count_solutions(p): result=0 for a in range(1,p+1): for b in range(a,(p-a)//2+1): c=p-a-b if a*a+b*b==c*c : result+=1 return result if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : OclAny := Set{Integer.subrange(1, 1001-1), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name count_solutions)))))))}->max() ; return ("" + ((ans))); operation count_solutions(p : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; for a : Integer.subrange(1, p + 1-1) do ( for b : Integer.subrange(a, (p - a) div 2 + 1-1) do ( var c : double := p - a - b ; if a * a + b * b = c * c then ( result := result + 1 ) else skip)) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) def f(n): L=[1] c=1 while 6**c<=n : L.append(6**c) c+=1 c=1 while 9**c<=n : L.append(9**c) c+=1 return L dp=[0 for i in range(N+1)] dp[1]=1 for i in range(N): L=f(i+1) temp=dp[i+1-L[0]] for j in range(len(L)): if temp>dp[i+1-L[j]]: temp=dp[i+1-L[j]] dp[i+1]=temp+1 print(dp[N]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; var dp : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (0)) ; dp[1+1] := 1 ; for i : Integer.subrange(0, N-1) do ( L := f(i + 1) ; var temp : OclAny := dp[i + 1 - L->first()+1] ; for j : Integer.subrange(0, (L)->size()-1) do ( if (temp->compareTo(dp[i + 1 - L[j+1]+1])) > 0 then ( temp := dp[i + 1 - L[j+1]+1] ) else skip) ; dp[i + 1+1] := temp + 1) ; execute (dp[N+1])->display(); operation f(n : OclAny) : OclAny pre: true post: true activity: var L : Sequence := Sequence{ 1 } ; var c : int := 1 ; while ((6)->pow(c)->compareTo(n)) <= 0 do ( execute (((6)->pow(c)) : L) ; c := c + 1) ; c := 1 ; while ((9)->pow(c)->compareTo(n)) <= 0 do ( execute (((9)->pow(c)) : L) ; c := c + 1) ; return L; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math tc=1 for i in range(tc): a,b=map(int,input().split()) if(b-a>=10): print(0) else : val=1 while b>a : val*=b % 10 val %=10 b-=1 print(val) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var tc : int := 1 ; for i : Integer.subrange(0, tc-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (b - a >= 10) then ( execute (0)->display() ) else ( var val : int := 1 ; while (b->compareTo(a)) > 0 do ( val := val * b mod 10 ; val := val mod 10 ; b := b - 1) ; execute (val)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys s2nn=lambda s :[int(c)for c in s.split(' ')] ss2nn=lambda ss :[int(s)for s in ss] ss2nnn=lambda ss :[s2nn(s)for s in ss] i2s=lambda : sys.stdin.readline().rstrip() i2n=lambda : int(i2s()) i2nn=lambda : s2nn(i2s()) ii2ss=lambda n :[sys.stdin.readline().rstrip()for _ in range(n)] ii2nn=lambda n : ss2nn(ii2ss(n)) ii2nnn=lambda n : ss2nnn(ii2ss(n)) def main(): N=i2n() coins=[1] d=6 while d<=N : coins.append(d) d*=6 d=9 while d<=N : coins.append(d) d*=9 dp=[0]*(N+1) for i in range(1,N+1): n=100000 for c in coins : if i-c<0 : continue t=dp[i-c]+1 if tselect(c | true)->collect(c | (("" + ((c)))->toInteger()))) ; var ss2nn : Function := lambda ss : OclAny in (ss->select(s | true)->collect(s | (("" + ((s)))->toInteger()))) ; var ss2nnn : Function := lambda ss : OclAny in (ss->select(s | true)->collect(s | (s2nn->apply(s)))) ; var i2s : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var i2n : Function := lambda $$ : OclAny in (("" + ((i2s->apply())))->toInteger()) ; var i2nn : Function := lambda $$ : OclAny in (s2nn->apply(i2s->apply())) ; var ii2ss : Function := lambda n : OclAny in (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (sys.stdin.readLine().rstrip()))) ; var ii2nn : Function := lambda n : OclAny in (ss2nn->apply(ii2ss->apply(n))) ; var ii2nnn : Function := lambda n : OclAny in (ss2nnn->apply(ii2ss->apply(n))) ; skip ; main(); operation main() pre: true post: true activity: var N : OclAny := i2n->apply() ; var coins : Sequence := Sequence{ 1 } ; var d : int := 6 ; while (d->compareTo(N)) <= 0 do ( execute ((d) : coins) ; d := d * 6) ; d := 9 ; while (d->compareTo(N)) <= 0 do ( execute ((d) : coins) ; d := d * 9) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; for i : Integer.subrange(1, N + 1-1) do ( var n : int := 100000 ; for c : coins do ( if i - c < 0 then ( continue ) else skip ; var t : OclAny := dp[i - c+1] + 1 ; if (t->compareTo(n)) < 0 then ( n := t ) else skip) ; dp[i+1] := n) ; execute (dp[N+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printLogestIncSubArr(arr,n): m=1 l=1 maxIndex=0 for i in range(1,n): if(arr[i]>arr[i-1]): l=l+1 else : if(munion(Sequence{6}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{1}->union(Sequence{ 2 })))))))) ; n := (arr)->size() ; printLogestIncSubArr(arr, n); operation printLogestIncSubArr(arr : OclAny, n : OclAny) pre: true post: true activity: var m : int := 1 ; var l : int := 1 ; var maxIndex : int := 0 ; for i : Integer.subrange(1, n-1) do ( if ((arr[i+1]->compareTo(arr[i - 1+1])) > 0) then ( l := l + 1 ) else ( if ((m->compareTo(l)) < 0) then ( m := l ; maxIndex := i - m ) else skip ; l := 1 )) ; if ((m->compareTo(l)) < 0) then ( m := l ; maxIndex := n - m ) else skip ; for i : Integer.subrange(maxIndex, (m + maxIndex)-1) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(N : int): from itertools import takewhile,count dp=list(range(N+1)) for n in(6,9): for m in takewhile(lambda x : x<=N,(n**e for e in count(1))): for i in range(m,N+1): dp[i]=min(dp[i],dp[i-m]+1) return dp[N] def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() N=int(next(tokens)) print(solve(N)) def test(): import doctest doctest.testmod() if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(N : int) : OclAny pre: true post: true activity: skip ; var dp : Sequence := (Integer.subrange(0, N + 1-1)) ; for n : Sequence{6, 9} do ( for m : takewhile(lambda x : OclAny in ((x->compareTo(N)) <= 0), Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom (name n))) ** (expr (atom (name e))))))) (comp_for for (exprlist (expr (atom (name e)))) in (logical_test (comparison (expr (atom (name count)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ))))))))}) do ( for i : Integer.subrange(m, N + 1-1) do ( dp[i+1] := Set{dp[i+1], dp[i - m+1] + 1}->min()))) ; return dp[N+1]; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var N : int := ("" + (((tokens).next())))->toInteger() ; execute (solve(N))->display(); operation test() pre: true post: true activity: skip ; doctest.testmod(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=n for i in range(n+1): cnt,p6,p9=0,i,n-i while p6>0 : cnt+=p6 % 6 p6//=6 while p9>0 : cnt+=p9 % 9 p9//=9 if cnttoInteger() ; var ans : int := n ; for i : Integer.subrange(0, n + 1-1) do ( var cnt : OclAny := null; var p6 : OclAny := null; var p9 : OclAny := null; Sequence{cnt,p6,p9} := Sequence{0,i,n - i} ; while p6 > 0 do ( cnt := cnt + p6 mod 6 ; p6 := p6 div 6) ; while p9 > 0 do ( cnt := cnt + p9 mod 9 ; p9 := p9 div 9) ; if (cnt->compareTo(ans)) < 0 then ( ans := cnt ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- max_n=100000 I=lambda : list(map(int,input().split())) s=[] for i in range(1,7): s.append(9**i) s.append(6**i) n,=I() a=[0]*100009 for i in range(1,100007): a[i]=a[i-1]+1 for j in s : if i-j>=0 : a[i]=min(a[i-j]+1,a[i]) print(a[n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var max_n : int := 100000 ; var I : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var s : Sequence := Sequence{} ; for i : Integer.subrange(1, 7-1) do ( execute (((9)->pow(i)) : s) ; execute (((6)->pow(i)) : s)) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,)} := I->apply() ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100009) ; for i : Integer.subrange(1, 100007-1) do ( a[i+1] := a[i - 1+1] + 1 ; for j : s do ( if i - j >= 0 then ( a[i+1] := Set{a[i - j+1] + 1, a[i+1]}->min() ) else skip)) ; execute (a[n+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solveEquation(equation): n=len(equation) sign=1 coeff=0 total=0 i=0 for j in range(0,n): if(equation[j]=='+' or equation[j]=='-'): if(j>i): total=(total+sign*int(equation[i : j])) i=j elif(equation[j]=='x'): if((i==j)or equation[j-1]=='+'): coeff+=sign elif(equation[j-1]=='-'): coeff=coeff-sign else : coeff=(coeff+sign*int(equation[i : j])) i=j+1 elif(equation[j]=='='): if(j>i): total=(total+sign*int(equation[i : j])) sign=-1 i=j+1 if(idisplay(); operation solveEquation(equation : OclAny) : OclAny pre: true post: true activity: var n : int := (equation)->size() ; var sign : int := 1 ; var coeff : int := 0 ; var total : int := 0 ; var i : int := 0 ; for j : Integer.subrange(0, n-1) do ( if (equation[j+1] = '+' or equation[j+1] = '-') then ( if ((j->compareTo(i)) > 0) then ( total := (total + sign * ("" + ((equation.subrange(i+1, j))))->toInteger()) ) else skip ; i := j ) else (if (equation[j+1] = 'x') then ( if ((i = j) or equation[j - 1+1] = '+') then ( coeff := coeff + sign ) else (if (equation[j - 1+1] = '-') then ( coeff := coeff - sign ) else ( coeff := (coeff + sign * ("" + ((equation.subrange(i+1, j))))->toInteger()) ) ) ; i := j + 1 ) else (if (equation[j+1] = '=') then ( if ((j->compareTo(i)) > 0) then ( total := (total + sign * ("" + ((equation.subrange(i+1, j))))->toInteger()) ) else skip ; sign := -1 ; i := j + 1 ) else skip ) ) ) ; if ((i->compareTo(n)) < 0) then ( total := (total + sign * ("" + ((equation.subrange(i+1, (equation)->size()))))->toInteger()) ) else skip ; if (coeff = 0 & total = 0) then ( return "Infinite solutions" ) else skip ; if (coeff = 0 & total) then ( return "No solution" ) else skip ; var ans : double := -total / coeff ; return ("" + ((ans)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- digits=input() uppercaseList=[str(i)for i in range(65,90+1)] lowercaseList=[str(i)for i in range(97,122+1)] if digits in uppercaseList : print('1') elif digits in lowercaseList : print('2') else : print('0') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var digits : String := (OclFile["System.in"]).readLine() ; var uppercaseList : Sequence := Integer.subrange(65, 90 + 1-1)->select(i | true)->collect(i | (("" + ((i))))) ; var lowercaseList : Sequence := Integer.subrange(97, 122 + 1-1)->select(i | true)->collect(i | (("" + ((i))))) ; if (uppercaseList)->includes(digits) then ( execute ('1')->display() ) else (if (lowercaseList)->includes(digits) then ( execute ('2')->display() ) else ( execute ('0')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=int(input()) print(1 if 65<=i<=90 else 2 if 97<=i<=122 else 0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (if 65 <= i & (i <= 90) then 1 else if 97 <= i & (i <= 122) then 2 else 0 endif endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n<65 or(n>90 and n<97)or n>122 : print(0) elif n<=90 : print(1) else : print(2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n < 65 or (n > 90 & n < 97) or n > 122 then ( execute (0)->display() ) else (if n <= 90 then ( execute (1)->display() ) else ( execute (2)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=int(input()) if i>=65 and i<=90 : print("1") elif i>=97 and i<=122 : print("2") else : print("0") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if i >= 65 & i <= 90 then ( execute ("1")->display() ) else (if i >= 97 & i <= 122 then ( execute ("2")->display() ) else ( execute ("0")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) ans=0 if a>=65 and a<=90 : ans=1 elif a>=97 and a<=122 : ans=2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; if a >= 65 & a <= 90 then ( ans := 1 ) else (if a >= 97 & a <= 122 then ( ans := 2 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys def _input(): return map(int,input().split()) a,b=_input() if b-a>=5 : print(0) else : res=1 for i in range(a+1,b+1): res*=(i % 10) print(res % 10) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := _input() ; if b - a >= 5 then ( execute (0)->display() ) else ( var res : int := 1 ; for i : Integer.subrange(a + 1, b + 1-1) do ( res := res * (i mod 10)) ; execute (res mod 10)->display() ); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) for i in range(a,0,-1): if a % i==0 : print(i,end=' ') a=i ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0 + 1, a)->reverse() do ( if a mod i = 0 then ( execute (i)->display() ; a := i ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=list(map(int,input().split())) print(1,end=" ") ptr=n-1 v=[0]*n for i in range(n): v[p[i]-1]=1 while(ptr>=0 and v[ptr]==1): ptr-=1 print(i+1-(n-1-ptr)+1,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (1)->display() ; var ptr : double := n - 1 ; var v : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( v[p[i+1] - 1+1] := 1 ; while (ptr >= 0 & v[ptr+1] = 1) do ( ptr := ptr - 1) ; execute (i + 1 - (n - 1 - ptr) + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict R=lambda : map(int,input().split()) n=int(input()) ans=[-1]*(n+1) sms=[1]*(n+1) vst=[0]*(n+1) def getAns(cur): rcur=cur while ans[rcur]!=-1 : rcur=ans[rcur] res=rcur rcur=cur while ans[rcur]!=-1 : ans[rcur]=res rcur=ans[rcur] return res def join(n1,n2): try : u,v=getAns(n1),getAns(n2) if u>v : u,v=v,u sms[v]+=sms[u] ans[u]=v except : print('Oh no: '+str(n1)+' '+str(n2)) res=[1] for num in R(): diff=1 left=0 if num>1 and vst[num-1]: left=sms[getAns(num-1)] join(num-1,num) if numcollect( _x | (OclType["int"])->apply(_x) )) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (n + 1)) ; var sms : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ; var vst : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; skip ; skip ; res := Sequence{ 1 } ; for num : R->apply() do ( var diff : int := 1 ; var left : int := 0 ; if num > 1 & vst[num - 1+1] then ( left := sms[getAns(num - 1)+1] ; join(num - 1, num) ) else skip ; if (num->compareTo(n)) < 0 & vst[num + 1+1] then ( join(num, num + 1) ) else skip ; if getAns(num) = n then ( diff := diff - left - 1 ) else skip ; vst[num+1] := 1 ; execute ((res->last() + diff) : res)) ; execute (StringLib.sumStringsWithSeparator(((res)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); operation getAns(cur : OclAny) : OclAny pre: true post: true activity: var rcur : OclAny := cur ; while ans[rcur+1] /= -1 do ( rcur := ans[rcur+1]) ; var res : OclAny := rcur ; rcur := cur ; while ans[rcur+1] /= -1 do ( ans[rcur+1] := res ; rcur := ans[rcur+1]) ; return res; operation join(n1 : OclAny, n2 : OclAny) pre: true post: true activity: try ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := Sequence{getAns(n1),getAns(n2)} ; if (u->compareTo(v)) > 0 then ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := Sequence{v,u} ) else skip ; sms[v+1] := sms[v+1] + sms[u+1] ; ans[u+1] := v) catch (_e : OclException) do ( execute ('Oh no: ' + ("" + ((n1))) + ' ' + ("" + ((n2))))->display()) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys import queue import itertools from heapq import heappop,heappush import random def solve(): n=int(input()) q=list(map(int,input().split())) d=[0 for i in range(n+1)] d[-1]=1 ans=1 left=n print(1,end=" ") for i in range(n): k=q[i]-1 d[k]=1 if k==left-1 : for j in range(left-1,-1,-1): if d[j]==1 : left-=1 ans-=1 else : break ans+=1 print(ans,end=" ") if __name__=='__main__' : multi_test=0 if multi_test : t=int(sys.stdin.readline()) for _ in range(t): solve() else : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var multi_test : int := 0 ; if multi_test then ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( solve()) ) else ( solve() ) ) else skip; operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var q : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; d->last() := 1 ; var ans : int := 1 ; var left : int := n ; execute (1)->display() ; for i : Integer.subrange(0, n-1) do ( var k : double := q[i+1] - 1 ; d[k+1] := 1 ; if k = left - 1 then ( for j : Integer.subrange(-1 + 1, left - 1)->reverse() do ( if d[j+1] = 1 then ( left := left - 1 ; ans := ans - 1 ) else ( break )) ) else skip ; ans := ans + 1 ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from bisect import bisect_right as br from collections import deque from itertools import combinations as cb def int_arr(): return list(map(int,sys.stdin.readline().strip().split())) def str_arr(): return list(map(str,sys.stdin.readline().strip().split())) def input(): return sys.stdin.readline().strip() n=int(input()) arr=int_arr() s=set() x=n+1 sm=0 print(1,end=' ') for i in range(n): sm+=1 s.add(arr[i]) while x-1 in s : x-=1 sm-=1 print(sm+1,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : OclAny := int_arr() ; var s : Set := Set{}->union(()) ; var x : int := n + 1 ; var sm : int := 0 ; execute (1)->display() ; for i : Integer.subrange(0, n-1) do ( sm := sm + 1 ; execute ((arr[i+1]) : s) ; while (s)->includes(x - 1) do ( x := x - 1 ; sm := sm - 1) ; execute (sm + 1)->display()); operation int_arr() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation str_arr() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["String"])->apply(_x) )); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) print(1,end=" ") ptr=n-1 v=[0]*n for i in range(n): v[l[i]-1]=1 while(ptr>=0 and v[ptr]==1): ptr-=1 print(i+1-(n-1-ptr)+1,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (1)->display() ; var ptr : double := n - 1 ; var v : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( v[l[i+1] - 1+1] := 1 ; while (ptr >= 0 & v[ptr+1] = 1) do ( ptr := ptr - 1) ; execute (i + 1 - (n - 1 - ptr) + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() acgt='ACGT' length=0 max_length=0 for i in range(len(s)): if s[i]in acgt : for j in range(len(s)-i): if s[i+j]in acgt : length+=1 else : break max_length=max(max_length,length) length=0 print(max_length) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var acgt : String := 'ACGT' ; var length : int := 0 ; var max_length : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if (acgt)->characters()->includes(s[i+1]) then ( for j : Integer.subrange(0, (s)->size() - i-1) do ( if (acgt)->characters()->includes(s[i + j+1]) then ( length := length + 1 ) else ( break )) ; max_length := Set{max_length, length}->max() ; length := 0 ) else skip) ; execute (max_length)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() def che(s): for c in s : if c=='A' or c=='C' or c=='G' or c=='T' : pass else : return 0 return 1 mx="" for i in range(0,len(s)+1): for j in range(0,len(s)+1): com=s[i : j] if len(com)==0 : continue if len(mx)size() + 1-1) do ( for j : Integer.subrange(0, (s)->size() + 1-1) do ( var com : OclAny := s.subrange(i+1, j) ; if (com)->size() = 0 then ( continue ) else skip ; if ((mx)->size()->compareTo((com)->size())) < 0 & che(com) then ( mx := com ) else skip)) ; execute ((mx)->size())->display(); operation che(s : OclAny) : OclAny pre: true post: true activity: for c : s->characters() do ( if c = 'A' or c = 'C' or c = 'G' or c = 'T' then ( skip ) else ( return 0 )) ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() S_list=list(S) S_ex=''.join((['1' if(k=='A' or k=='C' or k=='G' or k=='T')else '0' for k in S_list])) S_ans=[len(k)for k in S_ex.split('0')] print(max(S_ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var S_list : Sequence := (S)->characters() ; var S_ex : String := StringLib.sumStringsWithSeparator(((S_list->select(k | true)->collect(k | (if (k = 'A' or k = 'C' or k = 'G' or k = 'T') then '1' else '0' endif)))), '') ; var S_ans : Sequence := S_ex.split('0')->select(k | true)->collect(k | ((k)->size())) ; execute ((S_ans)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- str=input() ans=0 temp=0 for i in range(len(str)): if str[i]in 'ACGT' : temp+=1 else : if anssize()-1) do ( if ('ACGT')->characters()->includes(("" + ([i+1]))) then ( temp := temp + 1 ) else ( if (ans->compareTo(temp)) < 0 then ( ans := temp ) else skip ; temp := 0 )) ; if (ans->compareTo(temp)) < 0 then ( ans := temp ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=str(input()) lists=[] result=[] max=0 for i in range(len(S)): for j in range(len(S)): result.append(S[i : len(S)-j]) for i in range(len(result)): cnt=0 for j in range(len(result[i])): m=list(result[i]) if m[j]=="A" or m[j]=="C" or m[j]=="G" or m[j]=="T" : cnt+=1 if cnt==len(result[i]): lists.append(result[i]) if maxsize()-1) do ( for j : Integer.subrange(0, (S)->size()-1) do ( execute ((S.subrange(i+1, (S)->size() - j)) : result))) ; for i : Integer.subrange(0, (result)->size()-1) do ( var cnt : int := 0 ; for j : Integer.subrange(0, (result[i+1])->size()-1) do ( var m : Sequence := (result[i+1]) ; if m[j+1] = "A" or m[j+1] = "C" or m[j+1] = "G" or m[j+1] = "T" then ( cnt := cnt + 1 ) else skip) ; if cnt = (result[i+1])->size() then ( execute ((result[i+1]) : lists) ; if (max->compareTo((result[i+1])->size())) < 0 then ( max := (result[i+1])->size() ) else skip ) else skip) ; execute (max)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) base=[0]*3 out=0 point=0 inning=0 while True : event=input() if event=="HIT" : if base[2]==1 : point+=1 base[2]=base[1] base[1]=base[0] base[0]=1 elif event=="HOMERUN" : point+=sum(base)+1 base=[0]*3 elif event=="OUT" : out+=1 if out==3 : print(point) inning+=1 if inning==N : break base=[0]*3 out=0 point=0 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var base : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 3) ; var out : int := 0 ; var point : int := 0 ; var inning : int := 0 ; while true do ( var event : String := (OclFile["System.in"]).readLine() ; if event = "HIT" then ( if base[2+1] = 1 then ( point := point + 1 ) else skip ; base[2+1] := base[1+1] ; base[1+1] := base->first() ; base->first() := 1 ) else (if event = "HOMERUN" then ( point := point + (base)->sum() + 1 ; base := MatrixLib.elementwiseMult(Sequence{ 0 }, 3) ) else (if event = "OUT" then ( out := out + 1 ; if out = 3 then ( execute (point)->display() ; inning := inning + 1 ; if inning = N then ( break ) else skip ; base := MatrixLib.elementwiseMult(Sequence{ 0 }, 3) ; out := 0 ; point := 0 ) else skip ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): n=int(input()) print(n,end=" ") while n>1 : for i in range(2,n+1): if n % i==0 : print(n//i,end=" ") n//=i break def main(): t=1 for _ in range(t): solution() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; main(); operation solution() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n)->display() ; while n > 1 do ( for i : Integer.subrange(2, n + 1-1) do ( if n mod i = 0 then ( execute (n div i)->display() ; n := n div i ; break ) else skip)); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) if b-a>=5 : print(0) elif b-a==4 : m=str((a+1)*(a+2)*(a+3)*b) m1=m[-1] print(int(m1)) elif b-a==3 : c=str((a+1)*(a+2)*b) c1=c[-1] print(int(c1)) elif b-a==2 : d=str((a+1)*b) d1=d[-1] print(int(d1)) elif b-a==1 : e=str(b) e1=e[-1] print(e1) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if b - a >= 5 then ( execute (0)->display() ) else (if b - a = 4 then ( var m : String := ("" + (((a + 1) * (a + 2) * (a + 3) * b))) ; var m1 : OclAny := m->last() ; execute (("" + ((m1)))->toInteger())->display() ) else (if b - a = 3 then ( var c : String := ("" + (((a + 1) * (a + 2) * b))) ; var c1 : OclAny := c->last() ; execute (("" + ((c1)))->toInteger())->display() ) else (if b - a = 2 then ( var d : String := ("" + (((a + 1) * b))) ; var d1 : OclAny := d->last() ; execute (("" + ((d1)))->toInteger())->display() ) else (if b - a = 1 then ( var e : String := ("" + ((b))) ; var e1 : OclAny := e->last() ; execute (e1)->display() ) else ( execute (1)->display() ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque N=int(input()) INF=10**9 A=[int(input())for _ in range(N)]+[0]*6 B=[INF]*(N+6) B[0]=0 Q=deque([[0,0]]) while Q : x,y=Q.popleft() if x>=N-1 : print(y) break if B[x]toInteger() ; var INF : double := (10)->pow(9) ; var A : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))->union(MatrixLib.elementwiseMult(Sequence{ 0 }, 6)) ; var B : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, (N + 6)) ; B->first() := 0 ; var Q : Sequence := (Sequence{ Sequence{0}->union(Sequence{ 0 }) }) ; while Q do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Q->first() ; Q := Q->tail() ; if (x->compareTo(N - 1)) >= 0 then ( execute (y)->display() ; break ) else skip ; if (B[x+1]->compareTo(y)) < 0 then ( continue ) else skip ; if A[x+1] = 0 then ( for i : Integer.subrange(1, 7-1) do ( if (y + 1->compareTo(B[x + i+1])) < 0 then ( B[x + i+1] := y + 1 ; execute ((Sequence{x + i}->union(Sequence{ y + 1 })) : Q) ) else skip) ) else ( if (y->compareTo(B[x + A[x+1]+1])) < 0 then ( B[x + A[x+1]+1] := y ; Q := Q->prepend(Sequence{x + A[x+1]}->union(Sequence{ y })) ) else skip )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heappop,heappush import sys sys.setrecursionlimit(1000000) INF=10**20 def bfs(x): if visited[x]==2 : return None if visited[x]==1 : return edges[x] if plst[x]==0 : edges[x]=x visited[x]=1 return x visited[x]=2 ret=bfs(x+plst[x]) if ret!=None : edges[x]=ret visited[x]=1 return ret def search(): cost=[INF]*n cost[0]=0 que=[] heappush(que,(0,0)) while que : score,pos=heappop(que) for dice in range(1,7): new_pos=pos+dice if new_pos>=n-1 : print(score+1) return if edges[new_pos]==None : continue new_pos=edges[new_pos] if new_pos>=n-1 : print(score+1) return if cost[new_pos]>score+1 : cost[new_pos]=score+1 heappush(que,(score+1,new_pos)) else : print("Miss!!") n=int(input()) plst=[int(input())for _ in range(n)] edges=[None for _ in range(n)] visited=[0]*n for i in range(n): bfs(i) search() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit(1000000) ; var INF : double := (10)->pow(20) ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var plst : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var edges : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (null)) ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( bfs(i)) ; search(); operation bfs(x : OclAny) : OclAny pre: true post: true activity: if visited[x+1] = 2 then ( return null ) else skip ; if visited[x+1] = 1 then ( return edges[x+1] ) else skip ; if plst[x+1] = 0 then ( edges[x+1] := x ; visited[x+1] := 1 ; return x ) else skip ; visited[x+1] := 2 ; var ret : OclAny := bfs(x + plst[x+1]) ; if ret /= null then ( edges[x+1] := ret ; visited[x+1] := 1 ) else skip ; return ret; operation search() pre: true post: true activity: var cost : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, n) ; cost->first() := 0 ; var que : Sequence := Sequence{} ; heappush(que, Sequence{0, 0}) ; (compound_stmt while (test (logical_test (comparison (expr (atom (name que)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name score)))))) , (test (logical_test (comparison (expr (atom (name pos))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name heappop)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name que)))))))) ))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name dice)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 7))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name new_pos)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name pos))) + (expr (atom (name dice))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name new_pos)))) >= (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name score))) + (expr (atom (number (integer 1)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt return)))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name new_pos)))))))) ])))) == (comparison (expr (atom None)))))) : (suite (stmt (simple_stmt (small_stmt continue)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name new_pos)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name new_pos)))))))) ])))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name new_pos)))) >= (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name score))) + (expr (atom (number (integer 1)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt return)))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name cost)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name new_pos)))))))) ])))) > (comparison (expr (expr (atom (name score))) + (expr (atom (number (integer 1))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cost)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name new_pos)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name score))) + (expr (atom (number (integer 1)))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name heappush)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name que))))))) , (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name score))) + (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (atom (name new_pos))))))) )))))))) ))))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Miss!!"))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B,C,D=tuple(map(int,input().split())) if A+BC+D : print("Left") else : print("Balanced") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var D : OclAny := null; Sequence{A,B,C,D} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (A + B->compareTo(C + D)) < 0 then ( execute ("Right")->display() ) else (if (A + B->compareTo(C + D)) > 0 then ( execute ("Left")->display() ) else ( execute ("Balanced")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=map(int,input().split()) left=a+b right=c+d ans=None if left==right : ans='Balanced' elif left>right : ans='Left' elif leftcollect( _x | (OclType["int"])->apply(_x) ) ; var left : OclAny := a + b ; var right : OclAny := c + d ; var ans : OclAny := null ; if left = right then ( ans := 'Balanced' ) else (if (left->compareTo(right)) > 0 then ( ans := 'Left' ) else (if (left->compareTo(right)) < 0 then ( ans := 'Right' ) else skip ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B,C,D=map(int,input().split()) l=A+B r=C+D if l>r : print('Left') elif l==r : print('Balanced') else : print('Right') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var D : OclAny := null; Sequence{A,B,C,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : OclAny := A + B ; var r : OclAny := C + D ; if (l->compareTo(r)) > 0 then ( execute ('Left')->display() ) else (if l = r then ( execute ('Balanced')->display() ) else ( execute ('Right')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d=list(map(int,input().split())) if sum(d[: 2])collect( _x | (OclType["int"])->apply(_x) )) ; if ((d.subrange(1,2))->sum()->compareTo((d.subrange(2+1))->sum())) < 0 then ( execute ("Right")->display() ) else (if (d.subrange(1,2))->sum() = (d.subrange(2+1))->sum() then ( execute ("Balanced")->display() ) else ( execute ("Left")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B,C,D=map(int,input().split()) print("Left" if(A+B)>(C+D)else "Balanced" if(A+B)==(C+D)else "Right") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var D : OclAny := null; Sequence{A,B,C,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if ((A + B)->compareTo((C + D))) > 0 then "Left" else if (A + B) = (C + D) then "Balanced" else "Right" endif endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=[0]*N B=[0]*N C=[0]*N lineA=list(map(int,input().split())) lineB=list(map(int,input().split())) lineC=list(map(int,input().split())) for i in range(1,lineA[0]+1): A[lineA[i]-1]=1 for i in range(1,lineB[0]+1): B[lineB[i]-1]=1 for i in range(1,lineC[0]+1): C[lineC[i]-1]=1 ans=0 for i in range(N): if(((not A[i])and C[i])or(B[i]and C[i])): ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var B : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var C : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var lineA : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lineB : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lineC : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(1, lineA->first() + 1-1) do ( A[lineA[i+1] - 1+1] := 1) ; for i : Integer.subrange(1, lineB->first() + 1-1) do ( B[lineB[i+1] - 1+1] := 1) ; for i : Integer.subrange(1, lineC->first() + 1-1) do ( C[lineC[i+1] - 1+1] := 1) ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( if (((not(A[i+1])) & C[i+1]) or (B[i+1] & C[i+1])) then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : N=int(input()) all_list={i for i in range(1,N+1)} A_list=list(map(int,input().split())) B_list=list(map(int,input().split())) C_list=list(map(int,input().split())) A_number=A_list[0] A_identity=set(A_list[1 :]) B_number=B_list[0] B_identity=set(B_list[1 :]) C_number=C_list[0] C_identity=set(C_list[1 :]) not_A_identity=all_list-A_identity cond1=not_A_identity & C_identity cond2=B_identity & C_identity suspected=cond1 | cond2 print(len(suspected)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var all_list : Set := Integer.subrange(1, N + 1-1)->select(i | true)->collect(i | i)->asSet() ; var A_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var B_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var C_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var A_number : OclAny := A_list->first() ; var A_identity : Set := Set{}->union((A_list->tail())) ; var B_number : OclAny := B_list->first() ; var B_identity : Set := Set{}->union((B_list->tail())) ; var C_number : OclAny := C_list->first() ; var C_identity : Set := Set{}->union((C_list->tail())) ; var not_A_identity : double := all_list - A_identity ; var cond1 : int := MathLib.bitwiseAnd(not_A_identity, C_identity) ; var cond2 : int := MathLib.bitwiseAnd(B_identity, C_identity) ; var suspected : int := MathLib.bitwiseOr(cond1, cond2) ; execute ((suspected)->size())->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- para=int(input()) i=2 print(para,end=' ') while para>1 : if para % i==0 : para=para/i print(int(para),end=' ') else : i=i+1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var para : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 2 ; execute (para)->display() ; while para > 1 do ( if para mod i = 0 then ( para := para / i ; execute (("" + ((para)))->toInteger())->display() ) else ( i := i + 1 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() a=[int(num)for num in s.split()] s=input() b=[int(num)for num in s.split()] s=input() c=[int(num)for num in s.split()] isa=[] isb=[] isc=[] for i in range(n+1): isa.append(False) isb.append(False) isc.append(False) for i in range(1,a[0]+1): isa[a[i]]=True for i in range(1,b[0]+1): isb[b[i]]=True for i in range(1,c[0]+1): isc[c[i]]=True C=c[0] CA=0 ABC=0 for i in range(1,n+1): if isc[i]& isa[i]: CA+=1 if isa[i]& isb[i]& isc[i]: ABC+=1 print(C-CA+ABC) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var a : Sequence := s.split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; s := (OclFile["System.in"]).readLine() ; var b : Sequence := s.split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; s := (OclFile["System.in"]).readLine() ; var c : Sequence := s.split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var isa : Sequence := Sequence{} ; var isb : Sequence := Sequence{} ; var isc : Sequence := Sequence{} ; for i : Integer.subrange(0, n + 1-1) do ( execute ((false) : isa) ; execute ((false) : isb) ; execute ((false) : isc)) ; for i : Integer.subrange(1, a->first() + 1-1) do ( isa[a[i+1]+1] := true) ; for i : Integer.subrange(1, b->first() + 1-1) do ( isb[b[i+1]+1] := true) ; for i : Integer.subrange(1, c->first() + 1-1) do ( isc[c[i+1]+1] := true) ; var C : OclAny := c->first() ; var CA : int := 0 ; var ABC : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( if MathLib.bitwiseAnd(isc[i+1], isa[i+1]) then ( CA := CA + 1 ) else skip ; if MathLib.bitwiseAnd(MathLib.bitwiseAnd(isa[i+1], isb[i+1]), isc[i+1]) then ( ABC := ABC + 1 ) else skip) ; execute (C - CA + ABC)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): print(''.join(['W' if(i+j)% 2==0 else 'B' for j in range(n)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( execute (StringLib.sumStringsWithSeparator((Integer.subrange(0, n-1)->select(j | true)->collect(j | (if (i + j) mod 2 = 0 then 'W' else 'B' endif))), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A,B,C=list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split())) D=set(A[1 :]+B[1 :]+C[1 :]) ans=0 for e in D : if(e not in A[1 :]and e in C[1 :])or(e in B[1 :]and e in C[1 :]): ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{A,B,C} := Sequence{((input().split())->collect( _x | (OclType["int"])->apply(_x) )),((input().split())->collect( _x | (OclType["int"])->apply(_x) )),((input().split())->collect( _x | (OclType["int"])->apply(_x) ))} ; var D : Set := Set{}->union((A->tail() + B->tail() + C->tail())) ; var ans : int := 0 ; for e : D do ( if ((A->tail())->excludes(e) & (C->tail())->includes(e)) or ((B->tail())->includes(e) & (C->tail())->includes(e)) then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) U=set([i+1 for i in range(N)]) A=set([int(x)for x in input().split()[1 :]]) B=set([int(x)for x in input().split()[1 :]]) C=set([int(x)for x in input().split()[1 :]]) result=((U-A)& C)|(B & C) print(len(result)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var U : Set := Set{}->union((Integer.subrange(0, N-1)->select(i | true)->collect(i | (i + 1)))) ; var A : Set := Set{}->union((input().split()->tail()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))) ; var B : Set := Set{}->union((input().split()->tail()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))) ; var C : Set := Set{}->union((input().split()->tail()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))) ; var result : int := MathLib.bitwiseOr((MathLib.bitwiseAnd((U - A), C)), (MathLib.bitwiseAnd(B, C))) ; execute ((result)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k,a,b=map(int,input().split()) def numbers(a,b,k): x=b//k-a//k if a % k==0 : x+=1 return x if a==0 and b==0 : print(1) if a>0 and b>0 : print(numbers(a,b,k)) elif a==0 and b>0 : print(numbers(a+1,b,k)+1) elif a<0 and b==0 : print(numbers(1,-a,k)+1) elif a<0 and b>0 : print(numbers(1,b,k)+numbers(1,-a,k)+1) elif a<0 and b<0 : print(numbers(-b,-a,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{k,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; if a = 0 & b = 0 then ( execute (1)->display() ) else skip ; if a > 0 & b > 0 then ( execute (numbers(a, b, k))->display() ) else (if a = 0 & b > 0 then ( execute (numbers(a + 1, b, k) + 1)->display() ) else (if a < 0 & b = 0 then ( execute (numbers(1, -a, k) + 1)->display() ) else (if a < 0 & b > 0 then ( execute (numbers(1, b, k) + numbers(1, -a, k) + 1)->display() ) else (if a < 0 & b < 0 then ( execute (numbers(-b, -a, k))->display() ) else skip ) ) ) ) ; operation numbers(a : OclAny, b : OclAny, k : OclAny) : OclAny pre: true post: true activity: var x : double := b div k - a div k ; if a mod k = 0 then ( x := x + 1 ) else skip ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k,a,b=map(int,input().split()) print(b//k-(a-1)//k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{k,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (b div k - (a - 1) div k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k,a,b=list(map(int,input().split())) pa,qa=a//k,a % k pb,qb=b//k,b % k print((pb-pa)+(1 if qa==0 else 0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{k,a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var pa : OclAny := null; var qa : OclAny := null; Sequence{pa,qa} := Sequence{a div k,a mod k} ; var pb : OclAny := null; var qb : OclAny := null; Sequence{pb,qb} := Sequence{b div k,b mod k} ; execute ((pb - pa) + (if qa = 0 then 1 else 0 endif))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k,a,b=map(int,input().split()) ans=0 r=a % k if r==0 : start_ind=a else : start_ind=a+k-r ans=(b-start_ind)//k print(ans+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{k,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; var r : int := a mod k ; if r = 0 then ( var start_ind : OclAny := a ) else ( start_ind := a + k - r ) ; ans := (b - start_ind) div k ; execute (ans + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k,a,b=[int(c)for c in input().split()] print(b//k-(a-1)//k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{k,a,b} := input().split()->select(c | true)->collect(c | (("" + ((c)))->toInteger())) ; execute (b div k - (a - 1) div k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minimumDeletions(a,n): if(n<=2): return 0 count=0 for i in range(n-2): if((a[i]a[i+1]and a[i+1]>a[i+2])): count+=1 return count a=[5,2,3,6,1] n=len(a) print(minimumDeletions(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{5}->union(Sequence{2}->union(Sequence{3}->union(Sequence{6}->union(Sequence{ 1 })))) ; n := (a)->size() ; execute (minimumDeletions(a, n))->display(); operation minimumDeletions(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n <= 2) then ( return 0 ) else skip ; var count : int := 0 ; for i : Integer.subrange(0, n - 2-1) do ( if (((a[i+1]->compareTo(a[i + 1+1])) < 0 & (a[i + 1+1]->compareTo(a[i + 2+1])) < 0) or ((a[i+1]->compareTo(a[i + 1+1])) > 0 & (a[i + 1+1]->compareTo(a[i + 2+1])) > 0)) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n,0,-1): if n % i==0 : n=i ; print(i,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0 + 1, n)->reverse() do ( if n mod i = 0 then ( n := i; execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def square(n): return n*n ; def sum(n): if(n==0): return 0 ; if(n % 2==1): return(square(int((n+1)/2))+sum(int(n/2))); else : return(square(int(n/2))+sum(int(n/2))); def oddDivSum(a,b): return sum(b)-sum(a-1); a,b=3,9 ; print(oddDivSum(a,b)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; Sequence{a,b} := Sequence{3,9}; ; execute (oddDivSum(a, b))->display();; operation square(n : OclAny) pre: true post: true activity: return n * n;; operation sum(n : OclAny) pre: true post: true activity: if (n = 0) then ( return 0; ) else skip ; if (n mod 2 = 1) then ( return (square(("" + (((n + 1) / 2)))->toInteger()) + (("" + ((n / 2)))->toInteger())->sum()); ) else ( return (square(("" + ((n / 2)))->toInteger()) + (("" + ((n / 2)))->toInteger())->sum()); ); operation oddDivSum(a : OclAny, b : OclAny) pre: true post: true activity: return (b)->sum() - (a - 1)->sum();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- exec(int(input())*'input();print(*sorted(input().split(),key=int)[::-1]);') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) )))) * (expr (atom 'input();print(*sorted(input().split(),key=int)[::-1]);'))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(1,n+1): if(i % 2==0): for j in range(1,n+1): if j % 2==0 : print("W",end="") if j % 2==1 : print("B",end="") print("") if(i % 2==1): for j in range(1,n+1): if j % 2==1 : print("W",end="") if j % 2==0 : print("B",end="") print("") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(1, n + 1-1) do ( if (i mod 2 = 0) then ( for j : Integer.subrange(1, n + 1-1) do ( if j mod 2 = 0 then ( execute ("W")->display() ) else skip ; if j mod 2 = 1 then ( execute ("B")->display() ) else skip) ; execute ("")->display() ) else skip ; if (i mod 2 = 1) then ( for j : Integer.subrange(1, n + 1-1) do ( if j mod 2 = 1 then ( execute ("W")->display() ) else skip ; if j mod 2 = 0 then ( execute ("B")->display() ) else skip) ; execute ("")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import sqrt,ceil,floor,gcd from collections import Counter input=lambda : sys.stdin.readline() def int_arr(): return list(map(int,input().split())) def str_arr(): return list(map(str,input().split())) def get_str(): return map(str,input().split()) def get_int(): return map(int,input().split()) def get_flo(): return map(float,input().split()) def lcm(a,b): return(a*b)//gcd(a,b) mod=1000000007 def solve(): pass for _ in range(int(input())): n=int(input()) arr=int_arr() arr.sort(reverse=True) print(*arr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : int := 1000000007 ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : OclAny := int_arr() ; arr := arr->sort() ; execute ((argument * (test (logical_test (comparison (expr (atom (name arr))))))))->display()); operation int_arr() : OclAny pre: true post: true activity: return ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )); operation str_arr() : OclAny pre: true post: true activity: return ((input->apply().split())->collect( _x | (OclType["String"])->apply(_x) )); operation get_str() : OclAny pre: true post: true activity: return (input->apply().split())->collect( _x | (OclType["String"])->apply(_x) ); operation get_int() : OclAny pre: true post: true activity: return (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ); operation get_flo() : OclAny pre: true post: true activity: return (input->apply().split())->collect( _x | (OclType["double"])->apply(_x) ); operation lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a * b) div gcd(a, b); operation solve() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) a.sort(reverse=True) print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for tt in range(t): n=int(input()) arr=list(map(int,input().split())) arr=sorted(arr,reverse=True) for i in arr : print(i,end=' ') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for tt : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := arr->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; for i : arr do ( execute (i)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt MAX=1000000 prime=[0]*(MAX+1); def updatePrimes(): for i in range(2,MAX+1): prime[i]=1 ; prime[0]=prime[1]=0 ; for i in range(2,int(sqrt(MAX)+1)): if(prime[i]==1): for j in range(i*i,MAX,i): prime[j]=0 ; for i in range(1,MAX): prime[i]+=prime[i-1]; def getDifference(l,r): total=r-l+1 ; primes=prime[r]-prime[l-1]; composites=total-primes ; return(abs(primes-composites)); if __name__=="__main__" : queries=[[1,10],[5,30]]; q=len(queries); updatePrimes(); for i in range(q): print(getDifference(queries[i][0],queries[i][1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MAX : int := 1000000 ; var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX + 1)); ; skip ; skip ; if __name__ = "__main__" then ( var queries : Sequence := Sequence{Sequence{1}->union(Sequence{ 10 })}->union(Sequence{ Sequence{5}->union(Sequence{ 30 }) }); ; var q : int := (queries)->size(); ; updatePrimes(); ; for i : Integer.subrange(0, q-1) do ( execute (getDifference(queries[i+1]->first(), queries[i+1][1+1]))->display()) ) else skip; operation updatePrimes() pre: true post: true activity: for i : Integer.subrange(2, MAX + 1-1) do ( prime[i+1] := 1;) ; prime->first() := 0; var prime[1+1] : int := 0; ; for i : Integer.subrange(2, ("" + ((sqrt(MAX) + 1)))->toInteger()-1) do ( if (prime[i+1] = 1) then ( for j : Integer.subrange(i * i, MAX-1)->select( $x | ($x - i * i) mod i = 0 ) do ( prime[j+1] := 0;) ) else skip) ; for i : Integer.subrange(1, MAX-1) do ( prime[i+1] := prime[i+1] + prime[i - 1+1];); operation getDifference(l : OclAny, r : OclAny) pre: true post: true activity: var total : double := r - l + 1; ; var primes : double := prime[r+1] - prime[l - 1+1]; ; var composites : double := total - primes; ; return ((primes - composites)->abs());; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import log10 def generateNumbers(m): numbers=[] for y in range(1,10): k_max=((10**(m-2)*(10*y+1))//(10**(m-1)+y)) for k in range(1,k_max+1): x=((y*(10**(m-1)-k))//(10*k-1)) if((y*(10**(m-1)-k))%(10*k-1)==0): numbers.append(10*x+y) for n in sorted(numbers): print(n) m=3 generateNumbers(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; m := 3 ; generateNumbers(m); operation generateNumbers(m : OclAny) pre: true post: true activity: var numbers : Sequence := Sequence{} ; for y : Integer.subrange(1, 10-1) do ( var k_max : int := (((10)->pow((m - 2)) * (10 * y + 1)) div ((10)->pow((m - 1)) + y)) ; for k : Integer.subrange(1, k_max + 1-1) do ( var x : int := ((y * ((10)->pow((m - 1)) - k)) div (10 * k - 1)) ; if ((y * ((10)->pow((m - 1)) - k)) mod (10 * k - 1) = 0) then ( execute ((10 * x + y) : numbers) ) else skip)) ; for n : numbers->sort() do ( execute (n)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r=int(input()) for i in range(r): h,s=map(int,input().split()) if s<=h : print(s) else : ans=s//h rem=s % h sol=ans*ans*(h-rem)+(ans+1)*(ans+1)*rem print(sol) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, r-1) do ( var h : OclAny := null; var s : OclAny := null; Sequence{h,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (s->compareTo(h)) <= 0 then ( execute (s)->display() ) else ( var ans : int := s div h ; var rem : int := s mod h ; var sol : double := ans * ans * (h - rem) + (ans + 1) * (ans + 1) * rem ; execute (sol)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) for _ in range(q): c,sum=map(int,input().split()) type1=sum//c type2=(sum+c-1)//c if c==1 or sum==1 : print(sum**2) else : print(type2**2*(sum % c)+(type1**2*((sum-type2*(sum % c))//type1)if type1!=0 else type1**2*((sum-type2*(sum % c))))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( var c : OclAny := null; var sum : OclAny := null; Sequence{c,sum} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var type1 : int := sum div c ; var type2 : int := (sum + c - 1) div c ; if c = 1 or sum = 1 then ( execute ((sum)->pow(2))->display() ) else ( execute ((type2)->pow(2) * (sum mod c) + (if type1 /= 0 then (type1)->pow(2) * ((sum - type2 * (sum mod c)) div type1) else (type1)->pow(2) * ((sum - type2 * (sum mod c))) endif))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n,0,-1): if n % i==0 : print(i,end=" ") n=i ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0 + 1, n)->reverse() do ( if n mod i = 0 then ( execute (i)->display() ; n := i ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() for _ in[*open(0)][1 :]: c,s=map(int,_.split()) print((s//c)**2*c+(s % c)*(2*(s//c)+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; for _anon : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var c : OclAny := null; var s : OclAny := null; Sequence{c,s} := (_anon.split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (((s div c))->pow(2) * c + (s mod c) * (2 * (s div c) + 1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline inp=lambda : list(map(int,input().split())) from math import ceil def answer(): ans=0 for i in range(n): x,y=take[i] q=(y//x) ans=(y % x)*(q+1)*(q+1)+(x-(y % x))*q*q print(ans) for T in range(1): n=int(input()) take=[] for i in range(n): x,y=inp() take.append([x,y]) answer() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; var inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; skip ; skip ; for T : Integer.subrange(0, 1-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var take : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := inp->apply() ; execute ((Sequence{x}->union(Sequence{ y })) : take)) ; answer()); operation answer() pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := take[i+1] ; var q : int := (y div x) ; ans := (y mod x) * (q + 1) * (q + 1) + (x - (y mod x)) * q * q ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt from collections import defaultdict,deque from bisect import bisect_left as b_l from bisect import bisect_right as b_r import sys mod=10**9+7 for i in range(int(input())): c,s=map(int,input().split()) print(((s//c)+1)**2*(s % c)+(s//c)**2*(c-s % c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var c : OclAny := null; var s : OclAny := null; Sequence{c,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((((s div c) + 1))->pow(2) * (s mod c) + ((s div c))->pow(2) * (c - s mod c))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): if i % 2==0 : print("WB"*(n//2)+"W"*(n % 2)) else : print("BW"*(n//2)+"B"*(n % 2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( if i mod 2 = 0 then ( execute (StringLib.nCopies("WB", (n div 2)) + StringLib.nCopies("W", (n mod 2)))->display() ) else ( execute (StringLib.nCopies("BW", (n div 2)) + StringLib.nCopies("B", (n mod 2)))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- prnt=0 l_s=input() l_i=input() for i in l_i : if i==l_s[prnt]: prnt+=1 if prnt==len(l_s): break print(prnt+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var prnt : int := 0 ; var l_s : String := (OclFile["System.in"]).readLine() ; var l_i : String := (OclFile["System.in"]).readLine() ; for i : l_i->characters() do ( if i = l_s[prnt+1] then ( prnt := prnt + 1 ; if prnt = (l_s)->size() then ( break ) else skip ) else skip) ; execute (prnt + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() s2=input() i=0 ste=1 for c in s2 : if c==s[i]: i=i+1 ste=ste+1 print(ste) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var s2 : String := (OclFile["System.in"]).readLine() ; var i : int := 0 ; var ste : int := 1 ; for c : s2->characters() do ( if c = s[i+1] then ( i := i + 1 ; ste := ste + 1 ) else skip) ; execute (ste)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() t=input() sum=0 j=0 for i in range(len(t)): j=j if s[i-j]==t[i]: sum+=1 else : j+=1 print(sum+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var sum : int := 0 ; var j : int := 0 ; for i : Integer.subrange(0, (t)->size()-1) do ( j := j ; if s[i - j+1] = t[i+1] then ( sum := sum + 1 ) else ( j := j + 1 )) ; execute (sum + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input().strip() l=input().strip() less=0 for i in range(len(l)): if s[less]==l[i]: less+=1 print(less+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := input()->trim() ; var l : OclAny := input()->trim() ; var less : int := 0 ; for i : Integer.subrange(0, (l)->size()-1) do ( if s[less+1] = l[i+1] then ( less := less + 1 ) else skip) ; execute (less + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,p=input(),input(),0 for i in range(len(b)): if b[i]==a[p]: p+=1 print(p+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var p : OclAny := null; Sequence{a,b,p} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine(),0} ; for i : Integer.subrange(0, (b)->size()-1) do ( if b[i+1] = a[p+1] then ( p := p + 1 ) else skip) ; execute (p + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def inc(c): return chr(ord(c)+1) n,p=map(int,input().split('')) s=list(input()) p+=97 i=n-1 s[i]=inc(s[i]) while-1=p : s[i]='a' i-=1 s[i]=inc(s[i]) elif i>0 and s[i]==s[i-1]or i>1 and s[i]==s[i-2]: s[i]=inc(s[i]) else : i+=1 else : print(''.join(s)if i>-1 else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := (input().split(''))->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; p := p + 97 ; var i : double := n - 1 ; s[i+1] := inc(s[i+1]) ; (compound_stmt while (test (logical_test (comparison (comparison (comparison (expr (atom - (number (integer 1))))) < (comparison (expr (atom (name i))))) < (comparison (expr (atom (name n))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name ord)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))) >= (comparison (expr (atom (name p))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom 'a'))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name inc)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))))))))))))) (elif_clause elif (test (logical_test (logical_test (logical_test (comparison (comparison (expr (atom (name i)))) > (comparison (expr (atom (number (integer 0))))))) and (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))))))) or (logical_test (logical_test (comparison (comparison (expr (atom (name i)))) > (comparison (expr (atom (number (integer 1))))))) and (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 2)))))))))) ]))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name inc)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))))) if (logical_test (comparison (comparison (expr (atom (name i)))) > (comparison (expr (atom - (number (integer 1))))))) else (test (logical_test (comparison (expr (atom "NO")))))))) ))))))))))))))); operation inc(c : OclAny) : OclAny pre: true post: true activity: return ((c)->char2byte() + 1)->byte2char(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,m=map(int,input().split()) w=list(map(int,input().split())) for _ in range(m): l,r,x=map(int,input().split()) d=0 for i in range(l-1,r): if w[x-1]>w[i]: d+=1 if d==x-l : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for _anon : Integer.subrange(0, m-1) do ( var l : OclAny := null; var r : OclAny := null; var x : OclAny := null; Sequence{l,r,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : int := 0 ; for i : Integer.subrange(l - 1, r-1) do ( if (w[x - 1+1]->compareTo(w[i+1])) > 0 then ( d := d + 1 ) else skip) ; if d = x - l then ( execute ('Yes')->display() ) else ( execute ('No')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,p=map(int,input().split()) s=list(map(ord,input())) index=n-1 s[n-1]+=1 p+=97 while(index>=0 and index=p): s[index]=97 index-=1 s[index]+=1 elif(index!=0 and s[index]==s[index-1]): s[index]+=1 elif(index>1 and s[index]==s[index-2]): s[index]+=1 else : index+=1 if(index<0): print("NO") else : for i in s : print(chr(i),end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := (((OclFile["System.in"]).readLine())->collect( _x | (ord)->apply(_x) )) ; var index : double := n - 1 ; s[n - 1+1] := s[n - 1+1] + 1 ; p := p + 97 ; while (index >= 0 & (index->compareTo(n)) < 0) do ( if ((s[index+1]->compareTo(p)) >= 0) then ( s[index+1] := 97 ; index := index - 1 ; s[index+1] := s[index+1] + 1 ) else (if (index /= 0 & s[index+1] = s[index - 1+1]) then ( s[index+1] := s[index+1] + 1 ) else (if (index > 1 & s[index+1] = s[index - 2+1]) then ( s[index+1] := s[index+1] + 1 ) else ( index := index + 1 ) ) ) ) ; if (index < 0) then ( execute ("NO")->display() ) else ( for i : s do ( execute ((i)->byte2char())->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,p=list(map(int,input().split())) s=list(input()) s[n-1]=chr(ord(s[n-1])+1) i=n-1 while i>=0 and i=ord('a')+p : s[i]='a' i-=1 s[i]=chr(ord(s[i])+1) elif i>0 and s[i]==s[i-1]or i>1 and s[i]==s[i-2]: s[i]=chr(ord(s[i])+1) else : i+=1 print("NO" if i<0 else "".join(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; s[n - 1+1] := ((s[n - 1+1])->char2byte() + 1)->byte2char() ; var i : double := n - 1 ; while i >= 0 & (i->compareTo(n)) < 0 do ( if ((s[i+1])->char2byte()->compareTo(('a')->char2byte() + p)) >= 0 then ( s[i+1] := 'a' ; i := i - 1 ; s[i+1] := ((s[i+1])->char2byte() + 1)->byte2char() ) else (if i > 0 & s[i+1] = s[i - 1+1] or i > 1 & s[i+1] = s[i - 2+1] then ( s[i+1] := ((s[i+1])->char2byte() + 1)->byte2char() ) else ( i := i + 1 ) ) ) ; execute (if i < 0 then "NO" else StringLib.sumStringsWithSeparator((s), "") endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,p=map(int,input().split()) s=list(input()) oa=ord('a') for i in range(n-1,-1,-1): k=ord(s[i])-oa ban="" if i-1>=0 : ban+=s[i-1] if i-2>=0 : ban+=s[i-2] for pi in range(k+1,p): c=chr(oa+pi) if c not in ban : s[i]=c for j in range(i+1,n): bs="" if j-1>=0 : bs+=s[j-1] if j-2>=0 : bs+=s[j-2] for fi in range(p): nc=chr(oa+fi) if nc not in bs : s[j]=nc break print("".join(s)) exit(0) print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var oa : int := ('a')->char2byte() ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( var k : double := (s[i+1])->char2byte() - oa ; var ban : String := "" ; if i - 1 >= 0 then ( ban := ban + s[i - 1+1] ) else skip ; if i - 2 >= 0 then ( ban := ban + s[i - 2+1] ) else skip ; for pi : Integer.subrange(k + 1, p-1) do ( var c : String := (oa + pi)->byte2char() ; if (ban)->characters()->excludes(c) then ( s[i+1] := c ; for j : Integer.subrange(i + 1, n-1) do ( var bs : String := "" ; if j - 1 >= 0 then ( bs := bs + s[j - 1+1] ) else skip ; if j - 2 >= 0 then ( bs := bs + s[j - 2+1] ) else skip ; for fi : Integer.subrange(0, p-1) do ( var nc : String := (oa + fi)->byte2char() ; if (bs)->characters()->excludes(nc) then ( s[j+1] := nc ; break ) else skip)) ; execute (StringLib.sumStringsWithSeparator((s), ""))->display() ; exit(0) ) else skip)) ; execute ("NO")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def prMultiples(N): for i in range(1,N+1): for j in range(1,i+1): print((i*j),end=" ") print() if __name__=='__main__' : N=5 prMultiples(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( N := 5 ; prMultiples(N) ) else skip; operation prMultiples(N : OclAny) pre: true post: true activity: for i : Integer.subrange(1, N + 1-1) do ( for j : Integer.subrange(1, i + 1-1) do ( execute ((i * j))->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import heapq def debug(*args): print(*args,file=sys.stderr) fin=sys.stdin T=int(fin.readline()) for case in range(1,T+1): N=int(fin.readline()) heap=[] hikers=0 for i in range(N): d,h,m=map(int,fin.readline().split()) for p in range(m,m+h): t=p*(360-d)/360.0 heapq.heappush(heap,(t,1,p)) hikers+=1 current=hikers least=current while current<=hikers*2 : token=heapq.heappop(heap) t,d,p=token current-=d least=min(current,least) heapq.heappush(heap,(t+p,-1,p)) result=least debug("Case %d" % case) print("Case #%d: %s" %(case,result)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var fin : OclFile := OclFile["System.in"] ; var T : int := ("" + ((fin.readLine())))->toInteger() ; for case : Integer.subrange(1, T + 1-1) do ( var N : int := ("" + ((fin.readLine())))->toInteger() ; var heap : Sequence := Sequence{} ; var hikers : int := 0 ; for i : Integer.subrange(0, N-1) do ( var d : OclAny := null; var h : OclAny := null; var m : OclAny := null; Sequence{d,h,m} := (fin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for p : Integer.subrange(m, m + h-1) do ( var t : double := p * (360 - d) / 360.0 ; heapq.heappush(heap, Sequence{t, 1, p}) ; hikers := hikers + 1)) ; var current : int := hikers ; var least : int := current ; while (current->compareTo(hikers * 2)) <= 0 do ( var token : OclAny := heapq.heappop(heap) ; var d : OclAny := null; var p : OclAny := null; Sequence{t,d,p} := token ; current := current - d ; least := Set{current, least}->min() ; heapq.heappush(heap, Sequence{t + p, -1, p})) ; var result : int := least ; debug(StringLib.format("Case %d",case)) ; execute (StringLib.format("Case #%d: %s",Sequence{case, result}))->display()); operation debug(args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) execute ((argument * (test (logical_test (comparison (expr (atom (name args))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) for i in range(n): if i % 2 : print(('WB'*n)[: n]) else : print(('BW'*n)[: n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( if i mod 2 then ( execute ((StringLib.nCopies('WB', n)).subrange(1,n))->display() ) else ( execute ((StringLib.nCopies('BW', n)).subrange(1,n))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def trace(n,m): A=[[0 for x in range(m)]for y in range(n)]; B=[[0 for x in range(m)]for y in range(n)]; C=[[0 for x in range(m)]for y in range(n)]; cnt=1 ; for i in range(n): for j in range(m): A[i][j]=cnt ; cnt+=1 ; cnt=1 ; for i in range(n): for j in range(m): B[j][i]=cnt ; cnt+=1 ; for i in range(n): for j in range(m): C[i][j]=A[i][j]+B[i][j]; sum=0 ; for i in range(n): for j in range(m): if(i==j): sum+=C[i][j]; return sum ; N=3 ; M=3 ; print(trace(N,M)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 3; ; var M : int := 3; ; execute (trace(N, M))->display();; operation trace(n : OclAny, m : OclAny) pre: true post: true activity: var A : Sequence := Integer.subrange(0, n-1)->select(y | true)->collect(y | (Integer.subrange(0, m-1)->select(x | true)->collect(x | (0)))); ; var B : Sequence := Integer.subrange(0, n-1)->select(y | true)->collect(y | (Integer.subrange(0, m-1)->select(x | true)->collect(x | (0)))); ; var C : Sequence := Integer.subrange(0, n-1)->select(y | true)->collect(y | (Integer.subrange(0, m-1)->select(x | true)->collect(x | (0)))); ; var cnt : int := 1; ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( A[i+1][j+1] := cnt; ; cnt := cnt + 1;)) ; cnt := 1; ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( B[j+1][i+1] := cnt; ; cnt := cnt + 1;)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( C[i+1][j+1] := A[i+1][j+1] + B[i+1][j+1];)) ; var sum : int := 0; ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if (i = j) then ( sum := sum + C[i+1][j+1]; ) else skip)) ; return sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) p=[int(x)for x in input().split()] s=input() l=sorted([[s[i],p[i],i]for i in range(n)]) q=[-1 for i in range(n)] for i in range(n): q[l[i][2]]=i+1 print(*q) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var s : String := (OclFile["System.in"]).readLine() ; var l : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{s[i+1]}->union(Sequence{p[i+1]}->union(Sequence{ i }))))->sort() ; var q : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (-1)) ; for i : Integer.subrange(0, n-1) do ( q[l[i+1][2+1]+1] := i + 1) ; execute ((argument * (test (logical_test (comparison (expr (atom (name q))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cnt(res_arr,count): for index in range(1,count+1): weight=res_arr[index]['weight'] add_less=res_arr[index]['add_less'] positive={} negative={} sz=len(weight) ls=[0]*sz for i in range(sz): if add_less[i]==1 : positive[i]=weight[i] else : negative[i]=weight[i] positive=dict(sorted(positive.items(),key=lambda item : item[1],reverse=True)) negative=dict(sorted(negative.items(),key=lambda item : item[1],reverse=True)) count_el=sz for p in positive.keys(): positive[p]=count_el count_el-=1 for p in negative.keys(): negative[p]=count_el count_el-=1 res=[] for i in range(sz): if i in positive : res.append(positive[i]) else : res.append(negative[i]) for i in res : print(i,end=' ') print() def pars(): n=int(input()) res_arr={} count_el=n cur_index=1 while n>0 : cnt=int(input()) st=input() weight=list(map(int,st.split(' '))) st=input() add_less=list(map(int,list(st))) res_arr[cur_index]={'weight' : weight,'add_less' : add_less} cur_index+=1 n-=1 return res_arr,count_el if __name__=="__main__" : res_arr,count=pars() cnt(res_arr,count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( Sequence{res_arr,count} := pars() ; cnt(res_arr, count) ) else skip; operation cnt(res_arr : OclAny, count : OclAny) pre: true post: true activity: for index : Integer.subrange(1, count + 1-1) do ( var weight : OclAny := res_arr[index+1]->at('weight') ; var add_less : OclAny := res_arr[index+1]->at('add_less') ; var positive : OclAny := Set{} ; var negative : OclAny := Set{} ; var sz : int := (weight)->size() ; var ls : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, sz) ; for i : Integer.subrange(0, sz-1) do ( if add_less[i+1] = 1 then ( positive[i+1] := weight[i+1] ) else ( negative[i+1] := weight[i+1] )) ; positive := ((expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name positive)) (trailer . (name items) (arguments ( )))))))) , (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name item)))) : (test (logical_test (comparison (expr (atom (name item)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) , (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ))))) ; negative := ((expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name negative)) (trailer . (name items) (arguments ( )))))))) , (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name item)))) : (test (logical_test (comparison (expr (atom (name item)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) , (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ))))) ; var count_el : int := sz ; for p : positive.keys() do ( positive[p+1] := count_el ; count_el := count_el - 1) ; for p : negative.keys() do ( negative[p+1] := count_el ; count_el := count_el - 1) ; var res : Sequence := Sequence{} ; for i : Integer.subrange(0, sz-1) do ( if (positive)->includes(i) then ( execute ((positive[i+1]) : res) ) else ( execute ((negative[i+1]) : res) )) ; for i : res do ( execute (i)->display()) ; execute (->display()); operation pars() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; res_arr := Set{} ; count_el := n ; var cur_index : int := 1 ; while n > 0 do ( var cnt : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var st : String := (OclFile["System.in"]).readLine() ; weight := ((st.split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; st := (OclFile["System.in"]).readLine() ; add_less := (((st)->characters())->collect( _x | (OclType["int"])->apply(_x) )) ; res_arr[cur_index+1] := Map{ 'weight' |-> weight }->union(Map{ 'add_less' |-> add_less }) ; cur_index := cur_index + 1 ; n := n - 1) ; return res_arr, count_el; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) p=list(map(int,input().split())) s=input() zero=s.count("0") l=[] all=[] for j in range(n): all.append(j+1) for j in range(n): if(s[j]=="0" and p[j]<=zero)or(s[j]=="1" and p[j]>zero): l.append(p[j]) all[p[j]-1]=0 elif s[j]=="0" : l.append(-1) else : l.append(-2) zeroes=all[: zero] ones=all[zero :] zeroes.sort(reverse=True) ones.sort(reverse=True) z=0 o=0 for j in range(n): if l[j]==-1 : l[j]=zeroes[z] z+=1 elif l[j]==-2 : l[j]=ones[o] o+=1 print(*l,sep=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : String := (OclFile["System.in"]).readLine() ; var zero : int := s->count("0") ; var l : Sequence := Sequence{} ; var all : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( execute ((j + 1) : all)) ; for j : Integer.subrange(0, n-1) do ( if (s[j+1] = "0" & (p[j+1]->compareTo(zero)) <= 0) or (s[j+1] = "1" & (p[j+1]->compareTo(zero)) > 0) then ( execute ((p[j+1]) : l) ; [p[j+1] - 1+1]->forAll( _x | _x = true ) := 0 ) else (if s[j+1] = "0" then ( execute ((-1) : l) ) else ( execute ((-2) : l) ) ) ) ; var zeroes : boolean := .subrange(1,zero)->forAll( _x | _x = true ) ; var ones : boolean := .subrange(zero+1)->forAll( _x | _x = true ) ; zeroes := zeroes->sort() ; ones := ones->sort() ; var z : int := 0 ; var o : int := 0 ; for j : Integer.subrange(0, n-1) do ( if l[j+1] = -1 then ( l[j+1] := zeroes[z+1] ; z := z + 1 ) else (if l[j+1] = -2 then ( l[j+1] := ones[o+1] ; o := o + 1 ) else skip)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name l))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def solve(): n,m=map(int,input().split()) a=list(map(int,input().split())) for i in range(m): l,r,x=map(int,input().split()) count=0 page=a[x-1] for j in range(l-1,r): if a[j]collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, m-1) do ( var l : OclAny := null; var r : OclAny := null; var x : OclAny := null; Sequence{l,r,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var count : int := 0 ; var page : OclAny := a[x - 1+1] ; for j : Integer.subrange(l - 1, r-1) do ( if (a[j+1]->compareTo(page)) < 0 then ( count := count + 1 ) else skip) ; if count = x - l then ( execute ('Yes')->display() ) else ( execute ('No')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) p=[int(x)for x in input().split()] s=input() l=sorted([[s[i],p[i],i]for i in range(n)]) q=[-1 for i in range(n)] for i in range(n): q[l[i][2]]=i+1 print(*q) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var s : String := (OclFile["System.in"]).readLine() ; var l : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{s[i+1]}->union(Sequence{p[i+1]}->union(Sequence{ i }))))->sort() ; var q : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (-1)) ; for i : Integer.subrange(0, n-1) do ( q[l[i+1][2+1]+1] := i + 1) ; execute ((argument * (test (logical_test (comparison (expr (atom (name q))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input exec(int(I())*"n,a,b=map(int,I().split());s=x,*_=I();print(a*n+b*(n,s.count(x+'01'[x<'1'])+1)[b<0]);") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name I)) (trailer (arguments ( ))))))))) )))) * (expr (atom "n,a,b=map(int,I().split());s=x,*_=I();print(a*n+b*(n,s.count(x+'01'[x<'1'])+1)[b<0]);"))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,a,b=map(int,input().split()) l=input() initial=a*n if(b>=0): initial+=n*b else : ans=[] ans.append(l[0]) curr=l[0] for i in range(1,n): if l[i]==curr : continue else : ans.append(l[i]) curr=l[i] x=len(ans) if(x==1): initial+=b else : if(x % 2==0): initial+=(b*(x//2+1)) else : initial+=(b*((x-1)//2+1)) print(initial) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : String := (OclFile["System.in"]).readLine() ; var initial : double := a * n ; if (b >= 0) then ( initial := initial + n * b ) else ( var ans : Sequence := Sequence{} ; execute ((l->first()) : ans) ; var curr : OclAny := l->first() ; for i : Integer.subrange(1, n-1) do ( if l[i+1] = curr then ( continue ) else ( execute ((l[i+1]) : ans) ; curr := l[i+1] )) ; var x : int := (ans)->size() ; if (x = 1) then ( initial := initial + b ) else ( if (x mod 2 = 0) then ( initial := initial + (b * (x div 2 + 1)) ) else ( initial := initial + (b * ((x - 1) div 2 + 1)) ) ) ) ; execute (initial)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,a,b=list(map(int,input().split())) s=input() if b>=0 : print((a*n)+n*b) elif b<0 : t=0 ans=1 prev=s[0] for i in range(1,n): if s[i]!=prev : if t==0 : ans+=1 t=1 else : t=0 prev=s[i] print((a*n)+b*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : String := (OclFile["System.in"]).readLine() ; if b >= 0 then ( execute ((a * n) + n * b)->display() ) else (if b < 0 then ( var t : int := 0 ; var ans : int := 1 ; var prev : OclAny := s->first() ; for i : Integer.subrange(1, n-1) do ( if s[i+1] /= prev then ( if t = 0 then ( ans := ans + 1 ; t := 1 ) else ( t := 0 ) ; prev := s[i+1] ) else skip) ; execute ((a * n) + b * ans)->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def slove(): n,a,b=[int(x)for x in input().split(' ')] s=input() dem=1 for i in range(1,len(s)): if s[i]!=s[i-1]: dem+=1 res=a*len(s)+(dem//2+1)*b res1=a*len(s)+b*len(s) print(max(res,res1)) t=int(input()) while t>0 : slove() t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( slove() ; t := t - 1); operation slove() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var s : String := (OclFile["System.in"]).readLine() ; var dem : int := 1 ; for i : Integer.subrange(1, (s)->size()-1) do ( if s[i+1] /= s[i - 1+1] then ( dem := dem + 1 ) else skip) ; var res : double := a * (s)->size() + (dem div 2 + 1) * b ; var res1 : double := a * (s)->size() + b * (s)->size() ; execute (Set{res, res1}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for _ in range(int(input())): n,a,b=map(int,input().split()) s=input() if b>=0 : print((a*n)+(b*n)) else : change=int(0) c=s[0] for i in range(n): if s[i]!=c : change=change+1 c=s[i] z=int(math.ceil(change/2.0)+1) print((a*n)+(b*z)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; if b >= 0 then ( execute ((a * n) + (b * n))->display() ) else ( var change : int := ("" + ((0)))->toInteger() ; var c : OclAny := s->first() ; for i : Integer.subrange(0, n-1) do ( if s[i+1] /= c then ( change := change + 1 ) else skip ; c := s[i+1]) ; var z : int := ("" + (((change / 2.0)->ceil() + 1)))->toInteger() ; execute ((a * n) + (b * z))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) w='W' b='B' for i in range(n): for j in range(n): if i % 2==j % 2 : print(w,end="") else : print(b,end="") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : String := 'W' ; var b : String := 'B' ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if i mod 2 = j mod 2 then ( execute (w)->display() ) else ( execute (b)->display() )) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def networkDelayTime(self,times,N,K): graph=collections.defaultdict(list) for u,v,w in times : graph[u].append((v,w)) dist={node : float('inf')for node in xrange(1,N+1)} seen=[False]*(N+1) dist[K]=0 while True : cand_node=-1 cand_dist=float('inf') for i in xrange(1,N+1): if not seen[i]and dist[i]exists( _x | result = _x ); operation networkDelayTime(times : OclAny,N : OclAny,K : OclAny) : OclAny pre: true post: true activity: var graph : OclAny := .defaultdict(OclType["Sequence"]) ; for _tuple : times do (var _indx : int := 1; var u : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var w : OclAny := _tuple->at(_indx); (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name v)))))) , (test (logical_test (comparison (expr (atom (name w))))))) )))))))) ))))) ; var dist : Map := xrange(1, N + 1)->select(node | true)->collect(node | Map{node |-> ("" + (('inf')))->toReal()})->unionAll() ; var seen : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (N + 1)) ; dist[K+1] := 0 ; while true do ( var cand_node : int := -1 ; var cand_dist : double := ("" + (('inf')))->toReal() ; for i : xrange(1, N + 1) do ( if not(seen[i+1]) & (dist[i+1]->compareTo(cand_dist)) < 0 then ( cand_dist := dist[i+1] ; cand_node := i ) else skip) ; if cand_node < 0 then ( break ) else skip ; seen[cand_node+1] := true ; for _tuple : graph[cand_node+1] do (var _indx : int := 1; var nei : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); dist[nei+1] := Set{dist[nei+1], dist[cand_node+1] + d}->min())) ; var ans : OclAny := (dist.values())->max() ; return if (ans->compareTo(("" + (('inf')))->toReal())) < 0 then ans else -1 endif; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math LENGTH=18 MAX_COUNT=3 BASE=10 def compute(): ans=partition_and_count(LENGTH,MAX_COUNT,[]) ans=divide_exactly(ans*(BASE-1),BASE) return str(ans) def partition_and_count(sum,max,terms): if len(terms)==BASE : return count_ways(terms)if(sum==0)else 0 else : result=0 for i in reversed(range(min(max,sum)+1)): terms.append(i) result+=partition_and_count(sum-i,i,terms) terms.pop() return result def count_ways(freqs): histogram=[0]*(MAX_COUNT+1) for x in freqs : histogram[x]+=1 ways=math.factorial(BASE) for x in histogram : ways//=math.factorial(x) ways*=math.factorial(LENGTH) for x in freqs : ways//=math.factorial(x) return ways def divide_exactly(x,y): if x % y!=0 : raise ValueError("Not divisible") return x//y if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var LENGTH : int := 18 ; var MAX_COUNT : int := 3 ; var BASE : int := 10 ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : OclAny := partition_and_count(LENGTH, MAX_COUNT, Sequence{}) ; ans := divide_exactly(ans * (BASE - 1), BASE) ; return ("" + ((ans))); operation partition_and_count(sum : OclAny, max : OclAny, terms : OclAny) : OclAny pre: true post: true activity: if (terms)->size() = BASE then ( return if (sum = 0) then count_ways(terms) else 0 endif ) else ( var result : int := 0 ; for i : (Integer.subrange(0, Set{max, sum}->min() + 1-1))->reverse() do ( execute ((i) : terms) ; result := result + partition_and_count(sum - i, i, terms) ; terms := terms->front()) ; return result ); operation count_ways(freqs : OclAny) : OclAny pre: true post: true activity: var histogram : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX_COUNT + 1)) ; for x : freqs do ( histogram[x+1] := histogram[x+1] + 1) ; var ways : long := MathLib.factorial(BASE) ; for x : histogram do ( ways := ways div MathLib.factorial(x)) ; ways := ways * MathLib.factorial(LENGTH) ; for x : freqs do ( ways := ways div MathLib.factorial(x)) ; return ways; operation divide_exactly(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if x mod y /= 0 then ( error IncorrectElementException.newIncorrectElementException("Not divisible") ) else skip ; return x div y; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sortWithSetbits(arr,n,k): v1=[] v2=[] for i in range(0,n,1): if(bin(arr[i]).count('1')==k): v1.append(i) v2.append(arr[i]) v2.sort(reverse=False) for i in range(0,len(v1),1): arr[v1[i]]=v2[i] for i in range(0,n,1): print(arr[i],end=" ") if __name__=='__main__' : arr=[14,255,1,7,13] n=len(arr) k=3 sortWithSetbits(arr,n,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{14}->union(Sequence{255}->union(Sequence{1}->union(Sequence{7}->union(Sequence{ 13 })))) ; n := (arr)->size() ; k := 3 ; sortWithSetbits(arr, n, k) ) else skip; operation sortWithSetbits(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var v1 : Sequence := Sequence{} ; var v2 : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (bin(arr[i+1])->count('1') = k) then ( execute ((i) : v1) ; execute ((arr[i+1]) : v2) ) else skip) ; v2 := v2->sort() ; for i : Integer.subrange(0, (v1)->size()-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( arr[v1[i+1]+1] := v2[i+1]) ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) p=[0]+list(map(int,input().split())) for _ in range(m): l,r,x=map(int,input().split()) c=0 for i in range(l,r+1): if(p[i]collect( _x | (OclType["int"])->apply(_x) ) ; var p : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; for _anon : Integer.subrange(0, m-1) do ( var l : OclAny := null; var r : OclAny := null; var x : OclAny := null; Sequence{l,r,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : int := 0 ; for i : Integer.subrange(l, r + 1-1) do ( if ((p[i+1]->compareTo(p[x+1])) < 0) then ( c := c + 1 ) else skip) ; if (l + c = x) then ( execute ('Yes')->display() ) else ( execute ('No')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def canConvert(a,b): while(b>a): if(b % 10==1): b//=10 ; continue ; if(b % 2==0): b/=2 ; continue ; return false ; if(b==a): return True ; return False ; if __name__=="__main__" : A=2 ; B=82 ; if(canConvert(A,B)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var A : int := 2; var B : int := 82; ; if (canConvert(A, B)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ) else skip; operation canConvert(a : OclAny, b : OclAny) pre: true post: true activity: while ((b->compareTo(a)) > 0) do ( if (b mod 10 = 1) then ( b := b div 10; ; continue; ) else skip ; if (b mod 2 = 0) then ( b := b / 2; ; continue; ) else skip ; return false;) ; if (b = a) then ( return true; ) else skip ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def missingNumber(arr1,arr2,n): mnum=0 for i in range(n): mnum=mnum ^ arr1[i] for i in range(n-1): mnum=mnum ^ arr2[i] return mnum arr1=[4,8,1,3,7] arr2=[7,4,3,1] n=len(arr1) print("Missing number=",missingNumber(arr1,arr2,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr1 := Sequence{4}->union(Sequence{8}->union(Sequence{1}->union(Sequence{3}->union(Sequence{ 7 })))) ; arr2 := Sequence{7}->union(Sequence{4}->union(Sequence{3}->union(Sequence{ 1 }))) ; n := (arr1)->size() ; execute ("Missing number=")->display(); operation missingNumber(arr1 : OclAny, arr2 : OclAny, n : OclAny) : OclAny pre: true post: true activity: var mnum : int := 0 ; for i : Integer.subrange(0, n-1) do ( mnum := MathLib.bitwiseXor(mnum, arr1[i+1])) ; for i : Integer.subrange(0, n - 1-1) do ( mnum := MathLib.bitwiseXor(mnum, arr2[i+1])) ; return mnum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import tan def InscribedCircleArea(n,a): if(a<0 and n<0): return-1 r=a/(2*tan((180/n)*3.14159/180)); Area=3.14*r*r return Area if __name__=='__main__' : a=4 n=6 print('{0:.6}'.format(InscribedCircleArea(n,a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( a := 4 ; n := 6 ; execute (StringLib.interpolateStrings('{0:.6}', Sequence{InscribedCircleArea(n, a)}))->display() ) else skip; operation InscribedCircleArea(n : OclAny, a : OclAny) : OclAny pre: true post: true activity: if (a < 0 & n < 0) then ( return -1 ) else skip ; var r : double := a / (2 * tan((180 / n) * 3.14159 / 180)); ; var Area : double := 3.14 * r * r ; return Area; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def print(*args,end='\n',sep=' ')->None : sys.stdout.write(sep.join(map(str,args))+end) MOD=10**9+7 def Solve(): n=int(input()) print((3**(3*n)-7**n)% MOD) if __name__=="__main__" : Solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var MOD : double := (10)->pow(9) + 7 ; skip ; if __name__ = "__main__" then ( Solve() ) else skip; (funcdef def name print ( (typedargslist (args * (named_parameter (name args))) , (def_parameters (def_parameter (named_parameter (name end)) = (test (logical_test (comparison (expr (atom ' ')))))) , (def_parameter (named_parameter (name sep)) = (test (logical_test (comparison (expr (atom ' ')))))))) ) -> (test (logical_test (comparison (expr (atom None))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name sep)) (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name args)))))))) ))))))))) )))) + (expr (atom (name end))))))))) )))))))))))))) operation Solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (((3)->pow((3 * n)) - (7)->pow(n)) mod MOD)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print((pow(3,n*3)-pow(7,n))%(pow(10,9)+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (((3)->pow(n * 3) - (7)->pow(n)) mod ((10)->pow(9) + 7))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()); print((3**(3*n)-(7**n))% 1000000007) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); execute (((3)->pow((3 * n)) - ((7)->pow(n))) mod 1000000007)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def small(a,x): if x<10 : return(a**x)%(10**9+7) if x % 2==0 : return(small(a,x//2)*small(a,x//2))%(10**9+7) else : return(a*small(a,x//2)*small(a,x//2))%(10**9+7) def rec(a,b,x): if x<10 : return(a**x-b**x)%(10**9+7) if x % 2==0 : return rec(a,b,x//2)*(small(a,x//2)+small(b,x//2))%(10**9+7) else : return(small(a,x)%(10**9+7)-small(b,x)%(10**9+7))%(10**9+7) n=int(input()) print(rec(27,7,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (rec(27, 7, n))->display(); operation small(a : OclAny, x : OclAny) : OclAny pre: true post: true activity: if x < 10 then ( return ((a)->pow(x)) mod ((10)->pow(9) + 7) ) else skip ; if x mod 2 = 0 then ( return (small(a, x div 2) * small(a, x div 2)) mod ((10)->pow(9) + 7) ) else ( return (a * small(a, x div 2) * small(a, x div 2)) mod ((10)->pow(9) + 7) ); operation rec(a : OclAny, b : OclAny, x : OclAny) : OclAny pre: true post: true activity: if x < 10 then ( return ((a)->pow(x) - (b)->pow(x)) mod ((10)->pow(9) + 7) ) else skip ; if x mod 2 = 0 then ( return rec(a, b, x div 2) * (small(a, x div 2) + small(b, x div 2)) mod ((10)->pow(9) + 7) ) else ( return (small(a, x) mod ((10)->pow(9) + 7) - small(b, x) mod ((10)->pow(9) + 7)) mod ((10)->pow(9) + 7) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) ans=n+1 for i in range(1,n+1): if i*i>n : break ans=min(ans,i+n//i+min(n % i,1)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := n + 1 ; for i : Integer.subrange(1, n + 1-1) do ( if (i * i->compareTo(n)) > 0 then ( break ) else skip ; ans := Set{ans, i + n div i + Set{n mod i, 1}->min()}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- number=int(input()) print((3**(3*number)-(7**number))%(10**9+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var number : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (((3)->pow((3 * number)) - ((7)->pow(number))) mod ((10)->pow(9) + 7))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def MSBPosition(N): msb_p=-1 while(N): N=N>>1 msb_p+=1 return msb_p def findBitwiseOR(L,R): res=0 msb_p1=MSBPosition(L) msb_p2=MSBPosition(R) while(msb_p1==msb_p2): res_val=(1<display() ) else skip; operation MSBPosition(N : OclAny) : OclAny pre: true post: true activity: var msb_p : int := -1 ; while (N) do ( N := N /(2->pow(1)) ; msb_p := msb_p + 1) ; return msb_p; operation findBitwiseOR(L : OclAny, R : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; var msb_p1 : OclAny := MSBPosition(L) ; var msb_p2 : OclAny := MSBPosition(R) ; while (msb_p1 = msb_p2) do ( var res_val : int := (1 * (2->pow(msb_p1))) ; res := res + res_val ; L := L - res_val ; R := R - res_val ; msb_p1 := MSBPosition(L) ; msb_p2 := MSBPosition(R)) ; msb_p1 := Set{msb_p1, msb_p2}->max() ; for i : Integer.subrange(-1 + 1, msb_p1)->reverse() do ( res_val := (1 * (2->pow(i))) ; res := res + res_val) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) if a==b-1 or a==b+1 or(a==b and a!=0 and b!=0): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = b - 1 or a = b + 1 or (a = b & a /= 0 & b /= 0) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def oddNumSum(n): j=0 sm=0 for i in range(1,n+1): j=(2*i-1) sm=sm+(j*j*j*j) return sm n=6 ; print(oddNumSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 6; ; execute (oddNumSum(n))->display(); operation oddNumSum(n : OclAny) : OclAny pre: true post: true activity: var j : int := 0 ; var sm : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( j := (2 * i - 1) ; sm := sm + (j * j * j * j)) ; return sm; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def evenPowerSum(n): sum=0 ; for i in range(1,n+1): j=2*i ; sum=sum+(j*j*j*j); return sum ; n=5 ; print(evenPowerSum(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5; ; execute (evenPowerSum(n))->display();; operation evenPowerSum(n : OclAny) pre: true post: true activity: var sum : int := 0; ; for i : Integer.subrange(1, n + 1-1) do ( var j : double := 2 * i; ; sum := sum + (j * j * j * j);) ; return sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def summation(n): sum=0 j=1 for i in range(1,n+1): sum=sum+j j=(j*10)+1 return sum n=5 print(summation(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; execute (summation(n))->display(); operation summation(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; var j : int := 1 ; for i : Integer.subrange(1, n + 1-1) do ( sum := sum + j ; j := (j * 10) + 1) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) vv=list(map(int,input().split())) f={} b={} fcnt=0 bcnt=0 for v in vv : if fcnt==bcnt : if v in f : f[v]+=1 else : f[v]=1 fcnt+=1 else : if v in b : b[v]+=1 else : b[v]=1 bcnt+=1 ff=sorted(list(map(lambda x : tuple(reversed(x)),f.items())),reverse=True) bb=sorted(list(map(lambda x : tuple(reversed(x)),b.items())),reverse=True) if ff[0][1]!=bb[0][1]: print(n-ff[0][0]-bb[0][0]) else : ans=1145141919 if len(bb)==1 : ans=min(ans,n-ff[0][0]) else : ans=min(ans,n-ff[0][0]-bb[1][0]) if len(ff)==1 : ans=min(ans,n-bb[0][0]) else : ans=min(ans,n-bb[0][0]-ff[1][0]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var vv : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var f : OclAny := Set{} ; var b : OclAny := Set{} ; var fcnt : int := 0 ; var bcnt : int := 0 ; for v : vv do ( if fcnt = bcnt then ( if (f)->includes(v) then ( f[v+1] := f[v+1] + 1 ) else ( f[v+1] := 1 ) ; fcnt := fcnt + 1 ) else ( if (b)->includes(v) then ( b[v+1] := b[v+1] + 1 ) else ( b[v+1] := 1 ) ; bcnt := bcnt + 1 )) ; var ff : Sequence := ((f->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}))->collect( _x | (lambda x : OclAny in (((x)->reverse())))->apply(_x) ))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var bb : Sequence := ((b->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}))->collect( _x | (lambda x : OclAny in (((x)->reverse())))->apply(_x) ))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; if ff->first()[1+1] /= bb->first()[1+1] then ( execute (n - ff->first()->first() - bb->first()->first())->display() ) else ( var ans : int := 1145141919 ; if (bb)->size() = 1 then ( ans := Set{ans, n - ff->first()->first()}->min() ) else ( ans := Set{ans, n - ff->first()->first() - bb[1+1]->first()}->min() ) ; if (ff)->size() = 1 then ( ans := Set{ans, n - bb->first()->first()}->min() ) else ( ans := Set{ans, n - bb->first()->first() - ff[1+1]->first()}->min() ) ; execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import* n,*v=map(int,open(0).read().split()) a=Counter(v[: : 2]).most_common() b=Counter(v[1 : : 2]).most_common() if a[0][0]==b[0][0]: if len(a)>1 and len(b)>1 : print(min(n-a[0][1]-b[1][1],n-a[1][1]-b[0][1])) elif len(a)>1 : print(n-a[1][1]-b[0][1]) elif len(b)>1 : print(n-a[0][1]-b[1][1]) else : print(n//2) else : print(n-a[0][1]-b[0][1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var v : OclAny := null; Sequence{n,v} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := Counter(v(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))).most_common() ; var b : OclAny := Counter(v(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))).most_common() ; if a->first()->first() = b->first()->first() then ( if (a)->size() > 1 & (b)->size() > 1 then ( execute (Set{n - a->first()[1+1] - b[1+1][1+1], n - a[1+1][1+1] - b->first()[1+1]}->min())->display() ) else (if (a)->size() > 1 then ( execute (n - a[1+1][1+1] - b->first()[1+1])->display() ) else (if (b)->size() > 1 then ( execute (n - a->first()[1+1] - b[1+1][1+1])->display() ) else ( execute (n div 2)->display() ) ) ) ) else ( execute (n - a->first()[1+1] - b->first()[1+1])->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import socket from collections import Counter if socket.gethostname()in['N551J','F551C']: sys.stdin=open('c1.in') def read_int_list(): return list(map(int,input().split())) def read_int(): return int(input()) def read_str_list(): return input().split() def read_str(): return input() def solve(): n=read_int() a=read_int_list() c=[Counter(a[k : : 2])for k in range(2)] a,b=[c[k].most_common(1)[0]for k in range(2)] if a[0]!=b[0]: return n-a[1]-b[1] if a[1]==n//2 and b[1]==n//2 : return n//2 res=n if a[1]union(Sequence{ 'F551C' }))->includes(socket.gethostname()) then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('c1.in')) ) else skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation read_int_list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation read_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation read_str_list() : OclAny pre: true post: true activity: return input().split(); operation read_str() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation solve() : OclAny pre: true post: true activity: var n : OclAny := read_int() ; var a : OclAny := read_int_list() ; var c : Sequence := Integer.subrange(0, 2-1)->select(k | true)->collect(k | (Counter(a(subscript (test (logical_test (comparison (expr (atom (name k)))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))))) ; var b : OclAny := null; Sequence{a,b} := Integer.subrange(0, 2-1)->select(k | true)->collect(k | (c[k+1].most_common(1)->first())) ; if a->first() /= b->first() then ( return n - a[1+1] - b[1+1] ) else skip ; if a[1+1] = n div 2 & b[1+1] = n div 2 then ( return n div 2 ) else skip ; var res : OclAny := n ; if (a[1+1]->compareTo(n div 2)) < 0 then ( var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := c->first().most_common(2) ; res := Set{res, n - q[1+1] - b[1+1]}->min() ) else skip ; if (b[1+1]->compareTo(n div 2)) < 0 then ( var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := c[1+1].most_common(2) ; res := Set{res, n - a[1+1] - q[1+1]}->min() ) else skip ; return res; operation main() pre: true post: true activity: res := solve() ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N=int(input()) A=[int(i)for i in input().split()] A_odd=A[1 : : 2] A_even=A[0 : : 2] dict_odd={-1 : 0} dict_even={-1 : 0} for i in A_odd : if i not in dict_odd : dict_odd[i]=1 else : dict_odd[i]+=1 for i in A_even : if i not in dict_even : dict_even[i]=1 else : dict_even[i]+=1 dict_odd=sorted(dict_odd.items(),key=lambda x : x[1],reverse=True) dict_even=sorted(dict_even.items(),key=lambda x : x[1],reverse=True) if dict_even[0][0]!=dict_odd[0][0]: max_odd=dict_odd[0][1] max_even=dict_even[0][1] print(N-max_even-max_odd) else : if dict_odd[0][1]>dict_even[0][1]: max_odd=dict_odd[0][1] max_even=dict_even[1][1] print(N-max_even-max_odd) elif dict_even[0][1]>dict_odd[0][1]: max_odd=dict_odd[1][1] max_even=dict_even[0][1] print(N-max_even-max_odd) else : max_odd=max(dict_even[1][1],dict_odd[1][1]) print(N-dict_even[0][1]-max_odd) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var A_odd : OclAny := A(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ; var A_even : OclAny := A(subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ; var dict_odd : Map := Map{ -1 |-> 0 } ; var dict_even : Map := Map{ -1 |-> 0 } ; for i : A_odd do ( if (dict_odd)->excludes(i) then ( dict_odd[i+1] := 1 ) else ( dict_odd[i+1] := dict_odd[i+1] + 1 )) ; for i : A_even do ( if (dict_even)->excludes(i) then ( dict_even[i+1] := 1 ) else ( dict_even[i+1] := dict_even[i+1] + 1 )) ; dict_odd := dict_odd->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sortedBy($x | (lambda x : OclAny in (x[1+1]))->apply($x)) ; dict_even := dict_even->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sortedBy($x | (lambda x : OclAny in (x[1+1]))->apply($x)) ; if dict_even->first()->first() /= dict_odd->first()->first() then ( var max_odd : OclAny := dict_odd->first()[1+1] ; var max_even : OclAny := dict_even->first()[1+1] ; execute (N - max_even - max_odd)->display() ) else ( if (dict_odd->first()[1+1]->compareTo(dict_even->first()[1+1])) > 0 then ( max_odd := dict_odd->first()[1+1] ; max_even := dict_even[1+1][1+1] ; execute (N - max_even - max_odd)->display() ) else (if (dict_even->first()[1+1]->compareTo(dict_odd->first()[1+1])) > 0 then ( max_odd := dict_odd[1+1][1+1] ; max_even := dict_even->first()[1+1] ; execute (N - max_even - max_odd)->display() ) else ( max_odd := Set{dict_even[1+1][1+1], dict_odd[1+1][1+1]}->max() ; execute (N - dict_even->first()[1+1] - max_odd)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections n=int(input()) all_list_str=input() all_list=list(map(int,all_list_str.split())) odd_list=[all_list[i]for i in range(1,n,2)] even_list=[all_list[i]for i in range(0,n-1,2)] c=collections.Counter(odd_list) c_odd_list=c.most_common() c=collections.Counter(even_list) c_even_list=c.most_common() if(c_odd_list[0][0]!=c_even_list[0][0]): odd_target=c_odd_list[0][0] even_target=c_even_list[0][0] elif(c_odd_list[0][1]>c_even_list[0][1]): odd_target=c_odd_list[0][0] even_target=c_even_list[1][0] elif(c_odd_list[0][1]c_even_list[1][1]): odd_target=c_odd_list[1][0] even_target=c_even_list[0][0] else : odd_target=c_odd_list[0][0] even_target=c_even_list[1][0] print(str(len(odd_list)-odd_list.count(odd_target)+len(even_list)-even_list.count(even_target))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var all_list_str : String := (OclFile["System.in"]).readLine() ; var all_list : Sequence := ((all_list_str.split())->collect( _x | (OclType["int"])->apply(_x) )) ; var odd_list : Sequence := Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 2 = 0 )->select(i | true)->collect(i | (all_list[i+1])) ; var even_list : Sequence := Integer.subrange(0, n - 1-1)->select( $x | ($x - 0) mod 2 = 0 )->select(i | true)->collect(i | (all_list[i+1])) ; var c : OclAny := .Counter(odd_list) ; var c_odd_list : OclAny := c.most_common() ; c := .Counter(even_list) ; var c_even_list : OclAny := c.most_common() ; if (c_odd_list->first()->first() /= c_even_list->first()->first()) then ( var odd_target : OclAny := c_odd_list->first()->first() ; var even_target : OclAny := c_even_list->first()->first() ) else (if ((c_odd_list->first()[1+1]->compareTo(c_even_list->first()[1+1])) > 0) then ( odd_target := c_odd_list->first()->first() ; even_target := c_even_list[1+1]->first() ) else (if ((c_odd_list->first()[1+1]->compareTo(c_even_list->first()[1+1])) < 0) then ( odd_target := c_odd_list[1+1]->first() ; even_target := c_even_list->first()->first() ) else ( if ((c_odd_list)->size() = 1 & (c_even_list)->size() = 1) then ( odd_target := c_odd_list->first()->first() ; even_target := odd_target + 1 ) else (if ((c_odd_list)->size() = 1) then ( odd_target := c_odd_list->first()->first() ; even_target := c_even_list[1+1]->first() ) else (if ((c_even_list)->size() = 1) then ( odd_target := c_odd_list[1+1]->first() ; even_target := c_even_list->first()->first() ) else (if ((c_odd_list[1+1][1+1]->compareTo(c_even_list[1+1][1+1])) > 0) then ( odd_target := c_odd_list[1+1]->first() ; even_target := c_even_list->first()->first() ) else ( odd_target := c_odd_list->first()->first() ; even_target := c_even_list[1+1]->first() ) ) ) ) ) ) ) ; execute (("" + (((odd_list)->size() - odd_list->count(odd_target) + (even_list)->size() - even_list->count(even_target)))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) x=int(n**0.5) if n==x**2 : print(2*x) elif n-x<=x**2 : print(2*x+1) else : print(2*x+2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := ("" + (((n)->pow(0.5))))->toInteger() ; if n = (x)->pow(2) then ( execute (2 * x)->display() ) else (if (n - x->compareTo((x)->pow(2))) <= 0 then ( execute (2 * x + 1)->display() ) else ( execute (2 * x + 2)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,next=None,prev=None,data=None): self.next=next self.prev=prev self.data=data def push(head,new_data): new_node=Node(data=new_data) new_node.next=head new_node.prev=None if head is not None : head.prev=new_node head=new_node return head def size(head): node=head sz=0 while(node is not None): sz+=1 node=node.next return sz def printList(head): node=head print("Given linked list") while(node is not None): print(node.data,end=" "), last=node node=node.next def rotate(start,N): if N==0 : return current=start count=1 while countexists( _x | result = _x ); attribute next : OclAny := next; attribute prev : OclAny := prev; attribute data : OclAny := data; operation initialise(next : OclAny,prev : OclAny,data : OclAny) : Node pre: true post: true activity: self.next := next ; self.prev := prev ; self.data := data; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( head := null ; head := push(head, 'e') ; head := push(head, 'd') ; head := push(head, 'c') ; head := push(head, 'b') ; head := push(head, 'a') ; printList(head) ; execute ("\n")->display() ; N := 2 ; sz := size(head) ; N := N mod sz; ; N := sz - N; ; head := rotate(head, N) ; printList(head) ) else skip; operation push(head : OclAny, new_data : OclAny) : OclAny pre: true post: true activity: var new_node : Node := (Node.newNode()).initialise((argument (test (logical_test (comparison (expr (atom (name data)))))) = (test (logical_test (comparison (expr (atom (name new_data)))))))) ; new_node.next := head ; new_node.prev := null ; if not(head <>= null) then ( head.prev := new_node ) else skip ; head := new_node ; return head; operation size(head : OclAny) : OclAny pre: true post: true activity: var node : OclAny := head ; var sz : int := 0 ; while (not(node <>= null)) do ( sz := sz + 1 ; node := node.next) ; return sz; operation printList(head : OclAny) pre: true post: true activity: node := head ; execute ("Given linked list")->display() ; while (not(node <>= null)) do ((testlist_star_expr (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name node)) (trailer . (name data))))))) , (argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom " "))))))) ))))))) ,) ; var last : OclAny := node ; node := node.next); operation rotate(start : OclAny, N : OclAny) : OclAny pre: true post: true activity: if N = 0 then ( return ) else skip ; var current : OclAny := start ; var count : int := 1 ; while (count->compareTo(N)) < 0 & current /= null do ( current := current.next ; count := count + 1) ; if current = null then ( return ) else skip ; var NthNode : OclAny := current ; while current.next /= null do ( current := current.next) ; current.next := start ; start.prev := current ; start := NthNode.next ; start.prev := null ; NthNode.next := null ; return start; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Max_Sum(a,n): b=[0 for i in range(n)] S=0 res=0 for i in range(n): b[i]=res res+=a[i] S+=a[i] res=max(res,-S) ans=S ans=max(ans,res) g=0 for i in range(n-1,-1,-1): g-=a[i] ans=max(ans,g+b[i]) return ans a=[-6,10,-3,10,-2] n=len(a) print("Maximum sum is:",Max_Sum(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{-6}->union(Sequence{10}->union(Sequence{-3}->union(Sequence{10}->union(Sequence{ -2 })))) ; n := (a)->size() ; execute ("Maximum sum is:")->display(); operation Max_Sum(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var b : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var S : int := 0 ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( b[i+1] := res ; res := res + a[i+1] ; S := S + a[i+1] ; res := Set{res, -S}->max()) ; var ans : int := S ; ans := Set{ans, res}->max() ; var g : int := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( g := g - a[i+1] ; ans := Set{ans, g + b[i+1]}->max()) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sum(x,n): total=1.0 multi=x for i in range(1,n+1): total=total+multi/i multi=multi*x return total x=2 n=5 print(round(sum(x,n),2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := 2 ; n := 5 ; execute (MathLib.roundN((x, n)->sum(), 2))->display(); operation sum(x : OclAny, n : OclAny) : OclAny pre: true post: true activity: var total : double := 1.0 ; var multi : OclAny := x ; for i : Integer.subrange(1, n + 1-1) do ( total := total + multi / i ; multi := multi * x) ; return total; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd,sqrt def sumAP(n,d): n=int(n/d) return(n)*(1+n)*d/2 def sumMultiples(A,B,n): n-=1 common=int((A*B)/gcd(A,B)) return(sumAP(n,A)+sumAP(n,B)-sumAP(n,common)) if __name__=='__main__' : n=100 A=5 B=10 print("Sum=",int(sumMultiples(A,B,n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( n := 100 ; A := 5 ; B := 10 ; execute ("Sum=")->display() ) else skip; operation sumAP(n : OclAny, d : OclAny) : OclAny pre: true post: true activity: n := ("" + ((n / d)))->toInteger() ; return (n) * (1 + n) * d / 2; operation sumMultiples(A : OclAny, B : OclAny, n : OclAny) : OclAny pre: true post: true activity: n := n - 1 ; var common : int := ("" + (((A * B) / gcd(A, B))))->toInteger() ; return (sumAP(n, A) + sumAP(n, B) - sumAP(n, common)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=1000 bhisop_board=[[0 for i in range(n)]for j in range(n)] t=int(input()) for i in range(t): x,y=map(int,input().split()) bhisop_board[x-1][y-1]=1 total_attacks=0 for i in range(1,n): curr_diag_bhisops_count=0 for j in range(i+1): if bhisop_board[i-j][j]==1 : curr_diag_bhisops_count+=1 total_attacks+=curr_diag_bhisops_count*(curr_diag_bhisops_count-1)//2 for j in range(1,n): curr_diag_bhisops_count=0 for i in range(n-j): if bhisop_board[n-1-i][j+i]==1 : curr_diag_bhisops_count+=1 total_attacks+=curr_diag_bhisops_count*(curr_diag_bhisops_count-1)//2 for i in range(n-1,0,-1): curr_diag_bhisops_count=0 for j in range(n-i): if bhisop_board[i+j][j]==1 : curr_diag_bhisops_count+=1 total_attacks+=curr_diag_bhisops_count*(curr_diag_bhisops_count-1)//2 for j in range(n): curr_diag_bhisops_count=0 for i in range(n-j): if bhisop_board[i][j+i]==1 : curr_diag_bhisops_count+=1 total_attacks+=curr_diag_bhisops_count*(curr_diag_bhisops_count-1)//2 print(total_attacks) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := 1000 ; var bhisop_board : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)))) ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; bhisop_board[x - 1+1][y - 1+1] := 1) ; var total_attacks : int := 0 ; for i : Integer.subrange(1, n-1) do ( var curr_diag_bhisops_count : int := 0 ; for j : Integer.subrange(0, i + 1-1) do ( if bhisop_board[i - j+1][j+1] = 1 then ( curr_diag_bhisops_count := curr_diag_bhisops_count + 1 ) else skip) ; total_attacks := total_attacks + curr_diag_bhisops_count * (curr_diag_bhisops_count - 1) div 2) ; for j : Integer.subrange(1, n-1) do ( curr_diag_bhisops_count := 0 ; for i : Integer.subrange(0, n - j-1) do ( if bhisop_board[n - 1 - i+1][j + i+1] = 1 then ( curr_diag_bhisops_count := curr_diag_bhisops_count + 1 ) else skip) ; total_attacks := total_attacks + curr_diag_bhisops_count * (curr_diag_bhisops_count - 1) div 2) ; for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( curr_diag_bhisops_count := 0 ; for j : Integer.subrange(0, n - i-1) do ( if bhisop_board[i + j+1][j+1] = 1 then ( curr_diag_bhisops_count := curr_diag_bhisops_count + 1 ) else skip) ; total_attacks := total_attacks + curr_diag_bhisops_count * (curr_diag_bhisops_count - 1) div 2) ; for j : Integer.subrange(0, n-1) do ( curr_diag_bhisops_count := 0 ; for i : Integer.subrange(0, n - j-1) do ( if bhisop_board[i+1][j + i+1] = 1 then ( curr_diag_bhisops_count := curr_diag_bhisops_count + 1 ) else skip) ; total_attacks := total_attacks + curr_diag_bhisops_count * (curr_diag_bhisops_count - 1) div 2) ; execute (total_attacks)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[[*map(int,input().split())]for i in range(n)] d1={} d2={} for i in a : wk1=i[0]+i[1] wk2=i[0]-i[1] if not wk1 in d1 : d1[wk1]=0 d1[wk1]+=1 if not wk2 in d2 : d2[wk2]=0 d2[wk2]+=1 ans=0 for i in d1 : ans+=(d1[i]-1)*d1[i]//2 for i in d2 : ans+=(d2[i]-1)*d2[i]//2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var d1 : OclAny := Set{} ; var d2 : OclAny := Set{} ; for i : a do ( var wk1 : OclAny := i->first() + i[1+1] ; var wk2 : double := i->first() - i[1+1] ; if not((d1)->includes(wk1)) then ( d1[wk1+1] := 0 ) else skip ; d1[wk1+1] := d1[wk1+1] + 1 ; if not((d2)->includes(wk2)) then ( d2[wk2+1] := 0 ) else skip ; d2[wk2+1] := d2[wk2+1] + 1) ; var ans : int := 0 ; for i : d1 do ( ans := ans + (d1[i+1] - 1) * d1[i+1] div 2) ; for i : d2 do ( ans := ans + (d2[i+1] - 1) * d2[i+1] div 2) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- L1=[0]*2000 L2=[0]*2000 S=0 for i in range(int(input())): x,y=map(int,input().split()) L1[x+y-1]+=1 L2[1000+x-y]+=1 S+=L1[x+y-1]+L2[1000+x-y]-2 print(S) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var L1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 2000) ; var L2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 2000) ; var S : int := 0 ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; L1[x + y - 1+1] := L1[x + y - 1+1] + 1 ; L2[1000 + x - y+1] := L2[1000 + x - y+1] + 1 ; S := S + L1[x + y - 1+1] + L2[1000 + x - y+1] - 2) ; execute (S)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict pairs=0 a=defaultdict(lambda : 0) b=defaultdict(lambda : 0) for _ in[0]*int(input()): x,y=map(int,input().split()) a[x-y]+=1 ; b[x+y]+=1 for i in a.values(): pairs+=i*(i-1)//2 for i in b.values(): pairs+=i*(i-1)//2 print(pairs) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var pairs : int := 0 ; var a : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; var b : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a[x - y+1] := a[x - y+1] + 1; b[x + y+1] := b[x + y+1] + 1) ; for i : a.values() do ( pairs := pairs + i * (i - 1) div 2) ; for i : b.values() do ( pairs := pairs + i * (i - 1) div 2) ; execute (pairs)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) m1=[0 for _ in range(2007)] m2=[0 for _ in range(2007)] m3=[0 for _ in range(2007)] res=0 for _ in range(n): x,y=map(int,input().split()) res+=m1[x+y]+(m2[x-y]if x>=y else m3[y-x]); m1[x+y]+=1 if x>=y : m2[x-y]+=1 else : m3[y-x]+=1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m1 : Sequence := Integer.subrange(0, 2007-1)->select(_anon | true)->collect(_anon | (0)) ; var m2 : Sequence := Integer.subrange(0, 2007-1)->select(_anon | true)->collect(_anon | (0)) ; var m3 : Sequence := Integer.subrange(0, 2007-1)->select(_anon | true)->collect(_anon | (0)) ; var res : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; res := res + m1[x + y+1] + (if (x->compareTo(y)) >= 0 then m2[x - y+1] else m3[y - x+1] endif); ; m1[x + y+1] := m1[x + y+1] + 1 ; if (x->compareTo(y)) >= 0 then ( m2[x - y+1] := m2[x - y+1] + 1 ) else ( m3[y - x+1] := m3[y - x+1] + 1 )) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- X,A,B=map(int,input().split()) if A>=B : print('delicious') elif X>=B-A : print('safe') else : print('dangerous') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var X : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{X,A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (A->compareTo(B)) >= 0 then ( execute ('delicious')->display() ) else (if (X->compareTo(B - A)) >= 0 then ( execute ('safe')->display() ) else ( execute ('dangerous')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,radians,log2 from itertools import accumulate,permutations,combinations,product,groupby from operator import itemgetter,mul from copy import deepcopy from string import ascii_lowercase,ascii_uppercase,digits from bisect import bisect,bisect_left from fractions import gcd from heapq import heappush,heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) def ZIP(n): return zip(*(MAP()for _ in range(n))) sys.setrecursionlimit(10**9) INF=float('inf') mod=10**9+7 X,A,B=MAP() if B<=A : print("delicious") elif B<=A+X : print("safe") else : print("dangerous") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var X : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{X,A,B} := MAP() ; if (B->compareTo(A)) <= 0 then ( execute ("delicious")->display() ) else (if (B->compareTo(A + X)) <= 0 then ( execute ("safe")->display() ) else ( execute ("dangerous")->display() ) ) ; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ZIP(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))`third->at(_indx)} ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(n): i=2 while True : x=(i//2)*((i//2)+(i & 1)) if x>=n : return i i+=1 n=int(input()) print(check(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (check(n))->display(); operation check(n : OclAny) : OclAny pre: true post: true activity: var i : int := 2 ; while true do ( var x : int := (i div 2) * ((i div 2) + (MathLib.bitwiseAnd(i, 1))) ; if (x->compareTo(n)) >= 0 then ( return i ) else skip ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : for _ in range(int(input())): x,y=sorted(list(map(int,input().split())),reverse=True) i,j=0,0 turn=False commands=0 while True : if i==x and j==y : break if turn : if i==x : pass if itoInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,0} ; var turn : boolean := false ; var commands : int := 0 ; while true do ( if i = x & j = y then ( break ) else skip ; if turn then ( if i = x then ( skip ) else skip ; if (i->compareTo(x)) < 0 then ( i := i + 1 ) else ( i := i - 1 ) ; commands := commands + 1 ) else ( if j = y then ( skip ) else (if (j->compareTo(y)) < 0 then ( j := j + 1 ) else ( j := j - 1 ) ) ; commands := commands + 1 ) ; turn := not(turn)) ; execute (if x = y then commands else commands - 1 endif)->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INT=lambda : int(input()) INTM=lambda : map(int,input().split()) STRM=lambda : map(str,input().split()) STR=lambda : str(input()) LIST=lambda : list(map(int,input().split())) LISTS=lambda : list(map(str,input().split())) def do(): x,a,b=INTM() if a>=b : print('delicious') elif x+a>=b : print('safe') else : print('dangerous') if __name__=='__main__' : do() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INT : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var INTM : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var STRM : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["String"])->apply(_x) )) ; var STR : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))) ; var LIST : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var LISTS : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["String"])->apply(_x) ))) ; skip ; if __name__ = '__main__' then ( do() ) else skip; operation do() pre: true post: true activity: var x : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{x,a,b} := INTM->apply() ; if (a->compareTo(b)) >= 0 then ( execute ('delicious')->display() ) else (if (x + a->compareTo(b)) >= 0 then ( execute ('safe')->display() ) else ( execute ('dangerous')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,a,b=[int(x)for x in input().split()] if a+x=b : print("delicious") else : print("safe") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{x,a,b} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if (a + x->compareTo(b)) < 0 then ( execute ("dangerous")->display() ) else (if (a->compareTo(b)) >= 0 then ( execute ("delicious")->display() ) else ( execute ("safe")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- X,A,B=map(int,input().split()) delicious=True dangerous=True if B>A : delicious=False if B>A+X : dangerous=False if delicious : print('delicious') elif dangerous : print('safe') else : print("dangerous") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var X : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{X,A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var delicious : boolean := true ; var dangerous : boolean := true ; if (B->compareTo(A)) > 0 then ( delicious := false ) else skip ; if (B->compareTo(A + X)) > 0 then ( dangerous := false ) else skip ; if delicious then ( execute ('delicious')->display() ) else (if dangerous then ( execute ('safe')->display() ) else ( execute ("dangerous")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(s,p,q): global nx global ny for i in range(0,len(s)): if s[i]=='x' : nx+=1 else : ny+=1 if nx*ny!=p+q : return 1 else : return 0 def smallestPermutation(s,p,q): if check(s,p,q)==1 : return "Impossible" s=sorted(s) a,b,i=nx*ny,0,0 if a==p and b==q : return ''.join(s) while True : for i in range(0,len(s)-1): if s[i]=='x' and s[i+1]=='y' : break for j in range(i,len(s)-1): if s[j]=='x' and s[j+1]=='y' : s[j],s[j+1]=s[j+1],s[j] a-=1 b+=1 if a==p and b==q : return ''.join(s) if __name__=="__main__" : nx,ny=0,0 s="yxxyx" p,q=3,3 print(smallestPermutation(s,p,q)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute nx : OclAny; attribute ny : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( Sequence{nx,ny} := Sequence{0,0} ; s := "yxxyx" ; Sequence{p,q} := Sequence{3,3} ; execute (smallestPermutation(s, p, q))->display() ) else skip; operation check(s : OclAny, p : OclAny, q : OclAny) : OclAny pre: true post: true activity: skip ; skip ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = 'x' then ( nx := nx + 1 ) else ( ny := ny + 1 )) ; if nx * ny /= p + q then ( return 1 ) else ( return 0 ); operation smallestPermutation(s : OclAny, p : OclAny, q : OclAny) : OclAny pre: true post: true activity: if check(s, p, q) = 1 then ( return "Impossible" ) else skip ; s := s->sort() ; var a : OclAny := null; var b : OclAny := null; var i : OclAny := null; Sequence{a,b,i} := Sequence{nx * ny,0,0} ; if a = p & b = q then ( return StringLib.sumStringsWithSeparator((s), '') ) else skip ; while true do ( for i : Integer.subrange(0, (s)->size() - 1-1) do ( if s[i+1] = 'x' & s[i + 1+1] = 'y' then ( break ) else skip) ; for j : Integer.subrange(i, (s)->size() - 1-1) do ( if s[j+1] = 'x' & s[j + 1+1] = 'y' then ( var s[j+1] : OclAny := null; var s[j + 1+1] : OclAny := null; Sequence{s[j+1],s[j + 1+1]} := Sequence{s[j + 1+1],s[j+1]} ; a := a - 1 ; b := b + 1 ; if a = p & b = q then ( return StringLib.sumStringsWithSeparator((s), '') ) else skip ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) if n==1 : print(0); continue l.sort() c=0 x=l[0] for i in l[1 : :]: c+=(i-1)//(2*x-1) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = 1 then ( execute (0)->display(); continue ) else skip ; l := l->sort() ; var c : int := 0 ; var x : OclAny := l->first() ; for i : l(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop :)) do ( c := c + (i - 1) div (2 * x - 1)) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) arr=list(map(int,input().split())) m=min(arr) if m==1 : ans=0 for e in arr : if e!=m : ans+=e-1 print(ans) continue m=2*m-1 ans=0 for e in arr : if e % m==0 : ans+=e//m ans-=1 else : ans+=e//m print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : OclAny := (arr)->min() ; if m = 1 then ( var ans : int := 0 ; for e : arr do ( if e /= m then ( ans := ans + e - 1 ) else skip) ; execute (ans)->display() ; continue ) else skip ; m := 2 * m - 1 ; ans := 0 ; for e : arr do ( if e mod m = 0 then ( ans := ans + e div m ; ans := ans - 1 ) else ( ans := ans + e div m )) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) sets=[] for _ in range(t): input() sets.append(list(map(int,input().split()))) for peels in sets : n=0 sp=min(peels) for peel in peels : if peel>=2*sp : d=peel/(2*sp-1) if int(d)==d : d=int(d)-1 else : d=int(d) n+=d print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sets : Sequence := Sequence{} ; for _anon : Integer.subrange(0, t-1) do ( input() ; execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : sets)) ; for peels : sets do ( var n : int := 0 ; var sp : OclAny := (peels)->min() ; for peel : peels do ( if (peel->compareTo(2 * sp)) >= 0 then ( var d : double := peel / (2 * sp - 1) ; if ("" + ((d)))->toInteger() = d then ( d := ("" + ((d)))->toInteger() - 1 ) else ( d := ("" + ((d)))->toInteger() ) ; n := n + d ) else skip) ; execute (n)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) arr=list(map(int,input().split())) minimum=min(arr) maximum=2*minimum-1 steps=0 for j in range(n): if arr[j]>=maximum : steps+=arr[j]//maximum if arr[j]% maximum!=0 : steps+=1 steps-=1 print(steps) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var minimum : OclAny := (arr)->min() ; var maximum : double := 2 * minimum - 1 ; var steps : int := 0 ; for j : Integer.subrange(0, n-1) do ( if (arr[j+1]->compareTo(maximum)) >= 0 then ( steps := steps + arr[j+1] div maximum ; if arr[j+1] mod maximum /= 0 then ( steps := steps + 1 ) else skip ; steps := steps - 1 ) else skip) ; execute (steps)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) arr=list(map(int,input().split())) ans=0 smallest=arr[0] for i in range(1,len(arr)): curr=arr[i] if curr<2*smallest : pass else : temp=2*smallest-1 ans+=(curr//temp) if curr % temp==0 : ans-=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; var smallest : OclAny := arr->first() ; for i : Integer.subrange(1, (arr)->size()-1) do ( var curr : OclAny := arr[i+1] ; if (curr->compareTo(2 * smallest)) < 0 then ( skip ) else ( var temp : double := 2 * smallest - 1 ; ans := ans + (curr div temp) ; if curr mod temp = 0 then ( ans := ans - 1 ) else skip )) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break solvers=set() for i in range(1,int(n**(1/2))+2): if n % i==0 : solvers.add(i) solvers.add(n//i) score=sum(solvers)-n if ntoInteger() ; if n = 0 then ( break ) else skip ; var solvers : Set := Set{}->union(()) ; for i : Integer.subrange(1, ("" + (((n)->pow((1 / 2)))))->toInteger() + 2-1) do ( if n mod i = 0 then ( execute ((i) : solvers) ; execute ((n div i) : solvers) ) else skip) ; var score : double := (solvers)->sum() - n ; if (n->compareTo(score)) < 0 then ( execute ("abundant number")->display() ) else (if n = score then ( execute ("perfect number")->display() ) else ( execute ("deficient number")->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import division,print_function from sys import stdin,exit def main(readline=stdin.readline): for _ in range(int(readline())): first=second=third=out=point=0 while out<3 : event=readline()[1] if event=='I' : point+=third third=second second=first first=1 elif event=='U' : out+=1 else : point+=first+second+third+1 first=second=third=0 print(point) exit() if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main(readline : OclAny) pre: true post: true activity: if readline->oclIsUndefined() then readline := stdin.readline else skip; for _anon : Integer.subrange(0, ("" + ((readline())))->toInteger()-1) do ( first := first(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name second)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name third)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name out)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name point)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; while out < 3 do ( var event : OclAny := readline()[1+1] ; if event = 'I' then ( point := point + third ; var third : OclAny := second ; var second : OclAny := first ; var first : int := 1 ) else (if event = 'U' then ( out := out + 1 ) else ( point := point + first + second + third + 1 ; first := first(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name second)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name third)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ) ) ) ; execute (point)->display()) ; exit(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x,y=list(map(int,input().split(' '))) print(max(x,y)*2-1)if x!=y else print(x*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x))))))) , (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))) * (expr (atom (number (integer 2))))) - (expr (atom (number (integer 1)))))))))) )))))) if (logical_test (comparison (comparison (expr (atom (name x)))) != (comparison (expr (atom (name y)))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) * (expr (atom (number (integer 2)))))))))) ))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) sum0=math.inf for i in range(1,math.ceil(math.sqrt(n))+1): if(i+math.ceil(n/i))toInteger() ; var sum0 : OclAny := ; for i : Integer.subrange(1, ((n)->sqrt())->ceil() + 1-1) do ( if ((i + (n / i)->ceil())->compareTo(sum0)) < 0 then ( sum0 := i + (n / i)->ceil() ; var out : Sequence := Sequence{i}->union(Sequence{ (n / i)->ceil() }) ) else skip) ; execute ((out)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys p="perfect number" d="deficient number" a="abundant number" number_list=[] while True : N=int(input()) if N==0 : break else : number_list.append(N) maximum=int(max(number_list)**0.5) prime_table=[i for i in range(maximum+1)] prime_table[1]=0 for i in range(2,int(maximum**0.5)): if prime_table[i]==i : k=2 while k*i<=maximum : prime_table[k*i]==0 k+=1 for N in number_list : N_origin=N devide_list=[] for i in prime_table : if i!=0 : count=0 while N % i==0 : count+=1 N=N/i devide_list.append([i,count]) if N!=1 : devide_list.append([N,1]) S=1 for i in devide_list : S*=(i[0]**(i[1]+1)-1)/(i[0]-1) S-=N_origin if N_origin==S : print(p) elif N_origin>S : print(d) else : print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var p : String := "perfect number" ; var d : String := "deficient number" ; var a : String := "abundant number" ; var number_list : Sequence := Sequence{} ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else ( execute ((N) : number_list) )) ; var maximum : int := ("" + ((((number_list)->max())->pow(0.5))))->toInteger() ; var prime_table : Sequence := Integer.subrange(0, maximum + 1-1)->select(i | true)->collect(i | (i)) ; prime_table[1+1] := 0 ; for i : Integer.subrange(2, ("" + (((maximum)->pow(0.5))))->toInteger()-1) do ( if prime_table[i+1] = i then ( var k : int := 2 ; while (k * i->compareTo(maximum)) <= 0 do ((comparison (comparison (expr (atom (name prime_table)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name k))) * (expr (atom (name i))))))))) ])))) == (comparison (expr (atom (number (integer 0)))))) ; k := k + 1) ) else skip) ; for N : number_list do ( var N_origin : int := N ; var devide_list : Sequence := Sequence{} ; for i : prime_table do ( if i /= 0 then ( var count : int := 0 ; while N mod i = 0 do ( count := count + 1 ; N := N / i) ; execute ((Sequence{i}->union(Sequence{ count })) : devide_list) ) else skip) ; if N /= 1 then ( execute ((Sequence{N}->union(Sequence{ 1 })) : devide_list) ) else skip ; var S : int := 1 ; for i : devide_list do ( S := S * ((i->first())->pow((i[1+1] + 1)) - 1) / (i->first() - 1)) ; S := S - N_origin ; if N_origin = S then ( execute (p)->display() ) else (if (N_origin->compareTo(S)) > 0 then ( execute (d)->display() ) else ( execute (a)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(p): ans=1 if p<=5 : return 0 for n in range(2,int(p**0.5)+1): if p % n==0 : if n!=p//n : ans+=n+p//n else : ans+=n return ans while 1 : n=int(input()) if n==0 : break m=f(n) if n==m : print('perfect number') else : print('deficient number' if n>m else 'abundant number') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var m : String := f(n) ; if n = m then ( execute ('perfect number')->display() ) else ( execute (if n > m then 'deficient number' else 'abundant number' endif)->display() )); operation f(p : OclAny) : OclAny pre: true post: true activity: var ans : int := 1 ; if p <= 5 then ( return 0 ) else skip ; for n : Integer.subrange(2, ("" + (((p)->pow(0.5))))->toInteger() + 1-1) do ( if p mod n = 0 then ( if n /= p div n then ( ans := ans + n + p div n ) else ( ans := ans + n ) ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math while True : N=int(input()) if N==0 : break elif N==1 : print("deficient number") else : sum=1 for i in range(2,int(math.sqrt(N))+1): if N % i==0 and i**2!=N : sum+=N/i+i elif i**2==N : sum+=i if sum==N : print("perfect number") elif sum>N : print("abundant number") else : print("deficient number") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else (if N = 1 then ( execute ("deficient number")->display() ) else ( var sum : int := 1 ; for i : Integer.subrange(2, ("" + (((N)->sqrt())))->toInteger() + 1-1) do ( if N mod i = 0 & (i)->pow(2) /= N then ( sum := sum + N / i + i ) else (if (i)->pow(2) = N then ( sum := sum + i ) else skip)) ; if sum = N then ( execute ("perfect number")->display() ) else (if (sum->compareTo(N)) > 0 then ( execute ("abundant number")->display() ) else ( execute ("deficient number")->display() ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def make_division(n : int): divisors=[] for i in range(1,int(n**0.5)+1): if n % i==0 : divisors.append(i) if i!=n//i : divisors.append(n//i) divisors.sort() divisors.pop(-1) return sum(divisors) if __name__=='__main__' : while True : n=int(input()) if n==0 : break m=make_division(n) if n==m : print("perfect number") elif n>m : print("deficient number") else : print("abundant number") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var m : OclAny := make_division(n) ; if n = m then ( execute ("perfect number")->display() ) else (if (n->compareTo(m)) > 0 then ( execute ("deficient number")->display() ) else ( execute ("abundant number")->display() ) ) ) ) else skip; operation make_division(n : int) : OclAny pre: true post: true activity: var divisors : Sequence := Sequence{} ; for i : Integer.subrange(1, ("" + (((n)->pow(0.5))))->toInteger() + 1-1) do ( if n mod i = 0 then ( execute ((i) : divisors) ; if i /= n div i then ( execute ((n div i) : divisors) ) else skip ) else skip) ; divisors := divisors->sort() ; divisors := divisors->excludingAt(-1+1) ; return (divisors)->sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) count=0 j=n-1 for i in range(n-1,-1,-1): j=min(j,i) last_kill_pos=max(0,i-a[i]) if j>last_kill_pos : count+=(j-last_kill_pos) j=last_kill_pos print(n-count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : int := 0 ; var j : double := n - 1 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( j := Set{j, i}->min() ; var last_kill_pos : OclAny := Set{0, i - a[i+1]}->max() ; if (j->compareTo(last_kill_pos)) > 0 then ( count := count + (j - last_kill_pos) ; j := last_kill_pos ) else skip) ; execute (n - count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lst=list(map(int,input().split())) safe=n-1 alive=0 for i in range(n-1,-1,-1): if(i==safe): alive+=1 safe-=1 safe=min(safe,i-lst[i]-1) print(alive) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var safe : double := n - 1 ; var alive : int := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (i = safe) then ( alive := alive + 1 ; safe := safe - 1 ) else skip ; safe := Set{safe, i - lst[i+1] - 1}->min()) ; execute (alive)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lst=list(map(int,input().split())) safe=n-1 alive=0 for i in range(n-1,-1,-1): if(i==safe): alive+=1 safe-=1 safe=min(safe,i-lst[i]-1) print(alive) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var safe : double := n - 1 ; var alive : int := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (i = safe) then ( alive := alive + 1 ; safe := safe - 1 ) else skip ; safe := Set{safe, i - lst[i+1] - 1}->min()) ; execute (alive)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lst=list(map(int,input().split())) safe=n-1 alive=0 for i in range(n-1,-1,-1): if(i==safe): alive+=1 safe-=1 safe=min(safe,i-lst[i]-1) print(alive) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var safe : double := n - 1 ; var alive : int := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (i = safe) then ( alive := alive + 1 ; safe := safe - 1 ) else skip ; safe := Set{safe, i - lst[i+1] - 1}->min()) ; execute (alive)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) killed=0 last_killed=n for i in range(n-1,-1,-1): cur_kill=max(0,i-l[i]) if cur_kill>=last_killed : continue if itoInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var killed : int := 0 ; var last_killed : int := n ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( var cur_kill : OclAny := Set{0, i - l[i+1]}->max() ; if (cur_kill->compareTo(last_killed)) >= 0 then ( continue ) else skip ; if (i->compareTo(last_killed)) < 0 then ( killed := killed + i - cur_kill ) else ( killed := killed + last_killed - cur_kill ) ; if cur_kill = 0 then ( break ) else skip ; last_killed := Set{last_killed, cur_kill}->min()) ; execute (n - killed)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x,y=list(map(int,input().split())) print(2*max(x,y)-(x!=y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (2 * Set{x, y}->max() - (x /= y))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Divison(a,n): maxi=-10**9 mini=10**9 for i in a : maxi=max(i,maxi) mini=min(i,mini) return maxi//mini a=[3,7,9,3,11] n=len(a) print(Divison(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{3}->union(Sequence{7}->union(Sequence{9}->union(Sequence{3}->union(Sequence{ 11 })))) ; n := (a)->size() ; execute (Divison(a, n))->display(); operation Divison(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var maxi : double := (-10)->pow(9) ; var mini : double := (10)->pow(9) ; for i : a do ( maxi := Set{i, maxi}->max() ; mini := Set{i, mini}->min()) ; return maxi div mini; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys from collections import deque,OrderedDict,defaultdict import heapq from collections import Counter def inp(): return sys.stdin.readline().rstrip() def mpp(): return map(int,inp().split()) def lis(): return list(mpp()) def yn(n): if n : return "YES" else : return "NO" def fn(b,g,n): ans=0 for i in range(b+1): if 0<=n-i<=g : ans+=1 return ans def main(): b=int(inp()) g=int(inp()) n=int(inp()) print(fn(b,g,n)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation inp() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation mpp() : OclAny pre: true post: true activity: return (inp().split())->collect( _x | (OclType["int"])->apply(_x) ); operation lis() : OclAny pre: true post: true activity: return (mpp()); operation yn(n : OclAny) : OclAny pre: true post: true activity: if n then ( return "YES" ) else ( return "NO" ); operation fn(b : OclAny, g : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, b + 1-1) do ( if 0 <= n - i & (n - i <= g) then ( ans := ans + 1 ) else skip) ; return ans; operation main() pre: true post: true activity: b := ("" + ((inp())))->toInteger() ; g := ("" + ((inp())))->toInteger() ; n := ("" + ((inp())))->toInteger() ; execute (fn(b, g, n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def to_upper(string): for i in range(len(string)): if('a'<=string[i]<='z'): string=(string[0 : i]+chr(ord(string[i])-ord('a')+ord('A'))+string[i+1 :]) return string ; if __name__=='__main__' : str="geeksforgeeks" ; print(to_upper(str)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var OclType["String"] : String := "geeksforgeeks"; ; execute (to_upper(OclType["String"]))->display(); ) else skip; operation to_upper(string : OclAny) pre: true post: true activity: for i : Integer.subrange(0, (string)->size()-1) do ( if ('a' <= string[i+1] & (string[i+1] <= 'z')) then ( string := (string.subrange(0+1, i) + ((string[i+1])->char2byte() - ('a')->char2byte() + ('A')->char2byte())->byte2char() + string.subrange(i + 1+1)) ) else skip) ; return string;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- fin=open("b.in","r") n=int(fin.readline()) fout=open("b.out","w") for i in xrange(1,n+1): p,k,l=map(int,fin.readline().split()) freqs=map(int,fin.readline().split()) if p*k>fout,"Case #%d: Impossible" % i else : freqs.sort(lambda a,b : b-a) total=0 for j in xrange(1,p+1): total+=sum(freqs[: k])*j freqs=freqs[k :] if len(freqs)==0 : break print>>fout,"Case #%d: %d" %(i,total) fout.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var fin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("b.in")) ; var n : int := ("" + ((fin.readLine())))->toInteger() ; var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("b.out")) ; for i : xrange(1, n + 1) do ( var p : OclAny := null; var k : OclAny := null; var l : OclAny := null; Sequence{p,k,l} := (fin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var freqs : Sequence := (fin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (p * k->compareTo(l)) < 0 then ( print /(2->pow(fout)) ; (expr (expr (atom "Case #%d: Impossible")) % (expr (atom (name i)))) ) else ( freqs := freqs->sort() ; var total : int := 0 ; for j : xrange(1, p + 1) do ( total := total + (freqs.subrange(1,k))->sum() * j ; freqs := freqs.subrange(k+1) ; if (freqs)->size() = 0 then ( break ) else skip) ; print /(2->pow(fout)) ; (expr (expr (atom "Case #%d: %d")) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) , (test (logical_test (comparison (expr (atom (name total))))))) )))) )) ; fout.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): n,t=map(int,input().split()) a=list(map(int,input().split())) id=0 for i in range(n): if a[i]>a[id]: id=i t-=a[i] if t<0 : break if t>=0 : id=-1 print(id+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var id : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1]->compareTo(a[id+1])) > 0 then ( id := i ) else skip ; t := t - a[i+1] ; if t < 0 then ( break ) else skip) ; if t >= 0 then ( id := -1 ) else skip ; execute (id + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n,s=map(int,input().split()) w=list(map(int,input().split())) t=-1 d,d1=0,0 for i in range(n): if w[i]>d : d=w[i] d1=i+1 if s-w[i]>=0 : s-=w[i] else : t=i break if t==-1 or dtoInteger()-1) do ( var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : int := -1 ; var d : OclAny := null; var d1 : OclAny := null; Sequence{d,d1} := Sequence{0,0} ; for i : Integer.subrange(0, n-1) do ( if (w[i+1]->compareTo(d)) > 0 then ( var d : OclAny := w[i+1] ; var d1 : OclAny := i + 1 ) else skip ; if s - w[i+1] >= 0 then ( s := s - w[i+1] ) else ( t := i ; break )) ; if t = -1 or (d->compareTo(w[t+1])) < 0 then ( execute (0)->display() ) else ( execute (d1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): n,t=map(int,input().split()) a=list(map(int,input().split())) id=0 for i in range(n): if a[i]>a[id]: id=i t-=a[i] if t<0 : break if t>=0 : id=-1 print(id+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var id : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1]->compareTo(a[id+1])) > 0 then ( id := i ) else skip ; t := t - a[i+1] ; if t < 0 then ( break ) else skip) ; if t >= 0 then ( id := -1 ) else skip ; execute (id + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n,s=map(int,input().split()) k=s a=[x for x in list(map(int,input().split()))] ans=[] for j in range(n): if s>=0 : ans.append(a[j]) s=s-a[j] ans.sort() aa=max(ans) if s<0 : print(a.index(aa)+1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : OclAny := s ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->select(x | true)->collect(x | (x)) ; var ans : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( if s >= 0 then ( execute ((a[j+1]) : ans) ; var s : double := s - a[j+1] ) else skip) ; ans := ans->sort() ; var aa : OclAny := (ans)->max() ; if s < 0 then ( execute (a->indexOf(aa) - 1 + 1)->display() ) else ( execute (0)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n,s=map(int,input().split()) k=s a=[x for x in list(map(int,input().split()))] ans=[] for j in range(n): if s>=0 : ans.append(a[j]) s=s-a[j] aa=max(ans) if s<0 : print(a.index(aa)+1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : OclAny := s ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->select(x | true)->collect(x | (x)) ; var ans : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( if s >= 0 then ( execute ((a[j+1]) : ans) ; var s : double := s - a[j+1] ) else skip) ; var aa : OclAny := (ans)->max() ; if s < 0 then ( execute (a->indexOf(aa) - 1 + 1)->display() ) else ( execute (0)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findOddPair(A,N): count=0 for i in range(0,N): if(A[i]% 2==0): count+=1 return count*(N-count) if __name__=='__main__' : a=[5,4,7,2,1] n=len(a) print(findOddPair(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var a : Sequence := Sequence{5}->union(Sequence{4}->union(Sequence{7}->union(Sequence{2}->union(Sequence{ 1 })))) ; var n : int := (a)->size() ; execute (findOddPair(a, n))->display() ) else skip; operation findOddPair(A : OclAny, N : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, N-1) do ( if (A[i+1] mod 2 = 0) then ( count := count + 1 ) else skip) ; return count * (N - count); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): x,y=map(int,input().split()) if x==y : print(x+y) else : p=max(x,y) print(2*p-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x = y then ( execute (x + y)->display() ) else ( var p : OclAny := Set{x, y}->max() ; execute (2 * p - 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def LongestSubarray(arr,n,k): count=1 max_lenght=1 prev_mod=arr[0]% k for i in range(1,n): curr_mod=arr[i]% k if curr_mod==prev_mod : count+=1 else : max_lenght=max(max_lenght,count) count=1 prev_mod=curr_mod return max_lenght arr=[4,9,7,18,29,11] n=len(arr) k=11 print(LongestSubarray(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{4}->union(Sequence{9}->union(Sequence{7}->union(Sequence{18}->union(Sequence{29}->union(Sequence{ 11 }))))) ; n := (arr)->size() ; k := 11 ; execute (LongestSubarray(arr, n, k))->display(); operation LongestSubarray(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var count : int := 1 ; var max_lenght : int := 1 ; var prev_mod : int := arr->first() mod k ; for i : Integer.subrange(1, n-1) do ( var curr_mod : int := arr[i+1] mod k ; if curr_mod = prev_mod then ( count := count + 1 ) else ( max_lenght := Set{max_lenght, count}->max() ; count := 1 ; prev_mod := curr_mod )) ; return max_lenght; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxTeams(N1,N2): count=0 while(N1>0 and N2>0 and N1+N2>=3): if(N1>N2): N1-=2 N2-=1 else : N1-=1 N2-=2 count=count+1 return count N1=4 N2=5 print(maxTeams(N1,N2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N1 := 4 ; N2 := 5 ; execute (maxTeams(N1, N2))->display(); operation maxTeams(N1 : OclAny, N2 : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while (N1 > 0 & N2 > 0 & N1 + N2 >= 3) do ( if ((N1->compareTo(N2)) > 0) then ( N1 := N1 - 2 ; N2 := N2 - 1 ) else ( N1 := N1 - 1 ; N2 := N2 - 2 ) ; count := count + 1) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=list(int(input())for i in range(3)) print((min(a+b-c,a,b,c)+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 3))))))))) ))))))))) ; execute ((Set{a + b - c, a, b, c}->min() + 1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print((n*800)-(n//15)*200) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((n * 800) - (n div 15) * 200)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) if N<15 : print(800*N) else : a=N/15 a=int(a) print(800*N-a*200) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N < 15 then ( execute (800 * N)->display() ) else ( var a : double := N / 15 ; a := ("" + ((a)))->toInteger() ; execute (800 * N - a * 200)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) x=N*800 y=(N//15)*200 print(x-y if N>=15 else x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := N * 800 ; var y : int := (N div 15) * 200 ; execute (if N >= 15 then x - y else x endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) omake=N//15 print(800*N-200*omake) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var omake : int := N div 15 ; execute (800 * N - 200 * omake)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()); print(n*800-n//15*200) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); execute (n * 800 - n div 15 * 200)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def numberOfDistinct(n): ans=0 for i in range(1,int(math.sqrt(n))+1): if(n % i==0): ans+=1 if((n//i)!=i): ans+=1 return ans if __name__=="__main__" : n=3 print(numberOfDistinct(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 3 ; execute (numberOfDistinct(n))->display() ) else skip; operation numberOfDistinct(n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(1, ("" + (((n)->sqrt())))->toInteger() + 1-1) do ( if (n mod i = 0) then ( ans := ans + 1 ; if ((n div i) /= i) then ( ans := ans + 1 ) else skip ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input().split() b=int(a[0])+int(a[1])+int(a[2]) print(b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := input().split() ; var b : int := ("" + ((a->first())))->toInteger() + ("" + ((a[1+1])))->toInteger() + ("" + ((a[2+1])))->toInteger() ; execute (b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for _ in range(n): a,b=map(int,input().split()) if(a==b): print(2*a) else : c=abs(b-a) g=2*c c=min(a,b) g+=2*c-1 print(g) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a = b) then ( execute (2 * a)->display() ) else ( var c : double := (b - a)->abs() ; var g : double := 2 * c ; c := Set{a, b}->min() ; g := g + 2 * c - 1 ; execute (g)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p,m,c=(int(x)for x in input().split()) print(p+m+c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : OclAny := null; var m : OclAny := null; var c : OclAny := null; Sequence{p,m,c} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; execute (p + m + c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,f,b=map(int,input().split()) print(m+f+b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var f : OclAny := null; var b : OclAny := null; Sequence{m,f,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (m + f + b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) print(a+b+c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (a + b + c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) g=int(input()) n=int(input()) print(min(t+g-n,n,t,g)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var g : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (Set{t + g - n, n, t, g}->min() + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- P,M,C=map(int,input().split()) print(P+M+C) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var P : OclAny := null; var M : OclAny := null; var C : OclAny := null; Sequence{P,M,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (P + M + C)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=n factors=set() q=2 while n>1 and q*q<=n : if n % q==0 : factors.add(q) n//=q else : q+=1 if n>1 : factors.add(n) for p in factors : m*=p-1 m//=p print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := n ; var factors : Set := Set{}->union(()) ; var q : int := 2 ; while n > 1 & (q * q->compareTo(n)) <= 0 do ( if n mod q = 0 then ( execute ((q) : factors) ; n := n div q ) else ( q := q + 1 )) ; if n > 1 then ( execute ((n) : factors) ) else skip ; for p : factors do ( m := m * p - 1 ; m := m div p) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import itertools def sieve(n): is_prime=[True]*(n+1) prime_list=[] is_prime[0]=is_prime[1]=False prime_list.append(2) for i in range(3,n+1,2): if is_prime[i]: prime_list.append(i) for j in range(i*i,n+1,i): is_prime[j]=False return prime_list primes=sieve(40000) def factoriaztion(n): ret=[] for prime in primes : while n % prime==0 : ret.append(prime) n/=prime if n==1 : break if n>1 : ret.append(n) return ret if __name__=='__main__' : n=sys.stdin.readline() n=int(n) factors=factoriaztion(n) factors=itertools.groupby(factors) ans=1 for k,v in factors : l=len(list(v)) ans=ans*(k**l-k**(l-1)) sys.stdout.write(str(ans)+'\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var primes : OclAny := sieve(40000) ; skip ; if __name__ = '__main__' then ( n := (OclFile["System.in"]).readLine() ; n := ("" + ((n)))->toInteger() ; var factors : OclAny := factoriaztion(n) ; factors := itertools.groupby(factors) ; var ans : int := 1 ; for _tuple : factors do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); var l : int := ((v))->size() ; ans := ans * ((k)->pow(l) - (k)->pow((l - 1)))) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) )))) + (expr (atom ' ')))))))) )))) ) else skip; operation sieve(n : OclAny) : OclAny pre: true post: true activity: var is_prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (n + 1)) ; var prime_list : Sequence := Sequence{} ; is_prime->first() := false; var is_prime[1+1] : boolean := false ; execute ((2) : prime_list) ; for i : Integer.subrange(3, n + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if is_prime[i+1] then ( execute ((i) : prime_list) ) else skip ; for j : Integer.subrange(i * i, n + 1-1)->select( $x | ($x - i * i) mod i = 0 ) do ( is_prime[j+1] := false)) ; return prime_list; operation factoriaztion(n : OclAny) : OclAny pre: true post: true activity: var ret : Sequence := Sequence{} ; for prime : primes do ( while n mod prime = 0 do ( execute ((prime) : ret) ; n := n / prime) ; if n = 1 then ( break ) else skip) ; if n > 1 then ( execute ((n) : ret) ) else skip ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict from itertools import combinations from functools import reduce n=int(input()) r=int(n**(1/2))+2 dic=defaultdict(int) temp=n for i in range(2,r): if temptoInteger() ; var r : int := ("" + (((n)->pow((1 / 2)))))->toInteger() + 2 ; var dic : OclAny := defaultdict(OclType["int"]) ; var temp : int := n ; for i : Integer.subrange(2, r-1) do ( if (temp->compareTo(i)) < 0 then ( break ) else skip ; while temp mod i = 0 do ( temp := temp div i ; dic[i+1] := dic[i+1] + 1)) ; if temp /= 1 then ( dic[temp+1] := dic[temp+1] + 1 ) else skip ; var ans : int := n ; var keys : Sequence := (dic.keys()) ; var length : int := (keys)->size() ; for i : Integer.subrange(1, length + 1-1) do ( for t : combinations(keys, i) do ( ans := ans + n div reduce(lambda x : OclAny, y : OclAny in (x * y), t) * ((-1))->pow(i))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,collections as cl,bisect as bs sys.setrecursionlimit(100000) Max=sys.maxsize def l(): return list(map(int,input().split())) def m(): return map(int,input().split()) def onem(): return int(input()) def s(x): a=[] aa=x[0] su=1 for i in range(len(x)-1): if aa==x[i+1]: a.append([aa,su]) aa=x[i+1] su=1 else : su+=1 a.append([aa,su]) return a def jo(x): return " ".join(map(str,x)) def max2(x): return max(map(max,x)) def prime_decomposition(n): i=2 table=[] while i*i<=n : while n % i==0 : n/=i table.append(i) i+=1 if n>1 : table.append(int(n)) return table n=onem() nn=prime_decomposition(n) l=cl.Counter(nn) kkk=1 for i,j in l.items(): kkk*=(i-1)*(i**(j-1)) print(kkk) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(100000) ; var Max : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; n := onem() ; var nn : OclAny := prime_decomposition(n) ; var l : OclAny := cl.Counter(nn) ; var kkk : int := 1 ; for _tuple : l->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); kkk := kkk * (i - 1) * ((i)->pow((j - 1)))) ; execute (kkk)->display(); operation l() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation m() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation onem() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation s(x : OclAny) : OclAny pre: true post: true activity: var a : Sequence := Sequence{} ; var aa : OclAny := x->first() ; var su : int := 1 ; for i : Integer.subrange(0, (x)->size() - 1-1) do ( if aa = x[i + 1+1] then ( execute ((Sequence{aa}->union(Sequence{ su })) : a) ; aa := x[i + 1+1] ; su := 1 ) else ( su := su + 1 )) ; execute ((Sequence{aa}->union(Sequence{ su })) : a) ; return a; operation jo(x : OclAny) : OclAny pre: true post: true activity: return StringLib.sumStringsWithSeparator(((x)->collect( _x | (OclType["String"])->apply(_x) )), " "); operation max2(x : OclAny) : OclAny pre: true post: true activity: return ((x)->collect( _x | (max)->apply(_x) ))->max(); operation prime_decomposition(n : OclAny) : OclAny pre: true post: true activity: var i : int := 2 ; var table : Sequence := Sequence{} ; while (i * i->compareTo(n)) <= 0 do ( while n mod i = 0 do ( n := n / i ; execute ((i) : table)) ; i := i + 1) ; if n > 1 then ( execute ((("" + ((n)))->toInteger()) : table) ) else skip ; return table; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=lambda x : p*(x-1)//x p=n=int(input()) d=2 while d*d<=n : if n % d==0 : p=f(d) while n % d==0 : n//=d d+=1 if n>1 : p=f(n) print(p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : Function := lambda x : OclAny in (p * (x - 1) div x) ; var p : OclAny := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : int := 2 ; while (d * d->compareTo(n)) <= 0 do ( if n mod d = 0 then ( p := f->apply(d) ; while n mod d = 0 do ( n := n div d) ) else skip ; d := d + 1) ; if n > 1 then ( p := f->apply(n) ) else skip ; execute (p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reverse(str1,x): n=(len(str1)-x)//2 for i in range(n): print(str1[i],end="") for i in range(n+x-1,n-1,-1): print(str1[i],end="") for i in range(n+x,len(str1)): print(str1[i],end="") str1="geeksforgeeks" x=3 reverse(str1,x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; str1 := "geeksforgeeks" ; x := 3 ; reverse(str1, x); operation reverse(str1 : OclAny, x : OclAny) pre: true post: true activity: var n : int := ((str1)->size() - x) div 2 ; for i : Integer.subrange(0, n-1) do ( execute (str1[i+1])->display()) ; for i : Integer.subrange(n - 1 + 1, n + x - 1)->reverse() do ( execute (str1[i+1])->display()) ; for i : Integer.subrange(n + x, (str1)->size()-1) do ( execute (str1[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CompareAlphanumeric(str1,str2): i=0 j=0 len1=len(str1) len2=len(str2) while(i<=len1 and j<=len2): while(i='a' and str1[i]<='z')or(str1[i]>='A' and str1[i]<='Z')or(str1[i]>='0' and str1[i]<='9'))==False)): i+=1 while(j='a' and str2[j]<='z')or(str2[j]>='A' and str2[j]<='Z')or(str2[j]>='0' and str2[j]<='9'))==False)): j+=1 if(i==len1 and j==len2): return True elif(str1[i]!=str2[j]): return False else : i+=1 j+=1 return False def CompareAlphanumericUtil(str1,str2): res=CompareAlphanumeric(str1,str2) if(res==True): print("Equal") else : print("Unequal") if __name__=='__main__' : str1="Ram,Shyam" str2=" Ram-Shyam." CompareAlphanumericUtil(str1,str2) str1="abc123" str2="123abc" CompareAlphanumericUtil(str1,str2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( str1 := "Ram,Shyam" ; str2 := " Ram-Shyam." ; CompareAlphanumericUtil(str1, str2) ; str1 := "abc123" ; str2 := "123abc" ; CompareAlphanumericUtil(str1, str2) ) else skip; operation CompareAlphanumeric(str1 : OclAny, str2 : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; var j : int := 0 ; var len1 : int := (str1)->size() ; var len2 : int := (str2)->size() ; while ((i->compareTo(len1)) <= 0 & (j->compareTo(len2)) <= 0) do ( while ((i->compareTo(len1)) < 0 & (((str1[i+1] >= 'a' & str1[i+1] <= 'z') or (str1[i+1] >= 'A' & str1[i+1] <= 'Z') or (str1[i+1] >= '0' & str1[i+1] <= '9')) = false)) do ( i := i + 1) ; while ((j->compareTo(len2)) < 0 & (((str2[j+1] >= 'a' & str2[j+1] <= 'z') or (str2[j+1] >= 'A' & str2[j+1] <= 'Z') or (str2[j+1] >= '0' & str2[j+1] <= '9')) = false)) do ( j := j + 1) ; if (i = len1 & j = len2) then ( return true ) else (if (str1[i+1] /= str2[j+1]) then ( return false ) else ( i := i + 1 ; j := j + 1 ) ) ) ; return false; operation CompareAlphanumericUtil(str1 : OclAny, str2 : OclAny) pre: true post: true activity: var res : OclAny := CompareAlphanumeric(str1, str2) ; if (res = true) then ( execute ("Equal")->display() ) else ( execute ("Unequal")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break y=float(input()) ans=0 for i in range(n): b,r,t=map(int,input().split()) if t==1 : m=1+y*(r/100) else : m=(1+(r/100))**y if anstoInteger() ; if n = 0 then ( break ) else skip ; var y : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var b : OclAny := null; var r : OclAny := null; var t : OclAny := null; Sequence{b,r,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if t = 1 then ( var m : int := 1 + y * (r / 100) ) else ( m := ((1 + (r / 100)))->pow(y) ) ; if (ans->compareTo(m)) < 0 then ( ans := m ; var a : OclAny := b ) else skip) ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,bisect PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") def get_interest1(y,rate): return 100+y*rate def get_interest2(y,rate): return 100*(1+rate/100)**y while True : n=int(input()) if n==0 : break y=int(input()) high=0 for _ in range(n): no,rate,btype=[int(__)for __ in input().split()] if btype==1 : interest=get_interest1(y,rate) else : interest=get_interest2(y,rate) if interest>high : high=interest best=no print(best) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; skip ; skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; y := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var high : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var no : OclAny := null; var btype : OclAny := null; Sequence{no,rate,btype} := input().split()->select(__ | true)->collect(__ | (("" + ((__)))->toInteger())) ; if btype = 1 then ( var interest : OclAny := get_interest1(y, rate) ) else ( interest := get_interest2(y, rate) ) ; if (interest->compareTo(high)) > 0 then ( high := interest ; var best : OclAny := no ) else skip) ; execute (best)->display()); operation get_interest1(y : OclAny, rate : OclAny) : OclAny pre: true post: true activity: return 100 + y * rate; operation get_interest2(y : OclAny, rate : OclAny) : OclAny pre: true post: true activity: return 100 * ((1 + rate / 100))->pow(y); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(y,banks): return sorted([(1+r*y/100,b)if t==1 else((1+r/100)**y,b)for b,r,t in banks])[-1][-1] def main(args): while True : n=int(input()) if n==0 : break y=int(input()) banks=[(int(i)for i in input().split())for _ in range(n)] ans=solve(y,banks) print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(y : OclAny, banks : OclAny) : OclAny pre: true post: true activity: return sorted(banks->select(_tuple | true)->collect(_tuple | let b : OclAny = _tuple->at(1) in let r : OclAny = _tuple->at(2) in (if t = 1 then Sequence{1 + r * y / 100, b} else Sequence{((1 + r / 100))->pow(y), b} endif)))->last()->last(); operation main(args : OclAny) pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; y := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; banks := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))})) ; var ans : OclAny := solve(y, banks) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- b=int(input()) g=int(input()) n=int(input()) val=0 b=min(b,n) g=min(g,n) while(b+g)//n>0 : if b : b-=1 else : g-=1 val+=1 print(val) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var g : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var val : int := 0 ; b := Set{b, n}->min() ; g := Set{g, n}->min() ; while (b + g) div n > 0 do ( if b then ( b := b - 1 ) else ( g := g - 1 ) ; val := val + 1) ; execute (val)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def simple_interest(r,y): return(100+r*y)/100 def compound_interest(r,y): return((100+r)/100)**y import sys import operator f=sys.stdin get_ganri={1 : simple_interest,2 : compound_interest} while True : n=int(f.readline()) if n==0 : break y=int(f.readline()) brt=[list(map(int,f.readline().split()))for _ in range(n)] b_ganri=[(b,get_ganri[t](r,y))for b,r,t in brt] print(max(b_ganri,key=operator.itemgetter(1))[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var f : OclFile := OclFile["System.in"] ; var get_ganri : Map := Map{ 1 |-> simple_interest }->union(Map{ 2 |-> compound_interest }) ; while true do ( var n : int := ("" + ((f.readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; y := ("" + ((f.readLine())))->toInteger() ; var brt : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var b_ganri : Sequence := brt->select(_tuple | true)->collect(_tuple | let b : OclAny = _tuple->at(1) in let r : OclAny = _tuple->at(2) in (Sequence{b, get_ganri[t+1](r, y)})) ; execute (max(b_ganri, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name operator)) (trailer . (name itemgetter) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))))))->first())->display()); operation simple_interest(r : OclAny, y : OclAny) : OclAny pre: true post: true activity: return (100 + r * y) / 100; operation compound_interest(r : OclAny, y : OclAny) : OclAny pre: true post: true activity: return (((100 + r) / 100))->pow(y); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if n==0 : break y=int(input()) b=[tuple(map(int,input().split()))for _ in range(n)] p=[((1+b[i][1]/100*y)if b[i][2]==1 else((1+b[i][1]/100)**y))for i in range(n)] print(b[p.index(max(p))][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var y : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var p : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((if b[i+1][2+1] = 1 then (1 + b[i+1][1+1] / 100 * y) else (((1 + b[i+1][1+1] / 100))->pow(y)) endif))) ; execute (b[p->indexOf((p)->max()) - 1+1]->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,A=list(map(int,input().split())) x=list(map(int,input().split())) for i in range(N): x[i]-=A L=[[0 for i in range(10002)]for j in range(N)] for i in range(N): L[i][5001+x[i]]=1 for i in range(N-1): for j in range(10002): if L[i][j]!=0 : L[i+1][j]+=L[i][j] L[i+1][j+x[i+1]]+=L[i][j] print(L[N-1][5001]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; Sequence{N,A} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, N-1) do ( x[i+1] := x[i+1] - A) ; var L : Sequence := Integer.subrange(0, N-1)->select(j | true)->collect(j | (Integer.subrange(0, 10002-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, N-1) do ( L[i+1][5001 + x[i+1]+1] := 1) ; for i : Integer.subrange(0, N - 1-1) do ( for j : Integer.subrange(0, 10002-1) do ( if L[i+1][j+1] /= 0 then ( L[i + 1+1][j+1] := L[i + 1+1][j+1] + L[i+1][j+1] ; L[i + 1+1][j + x[i + 1+1]+1] := L[i + 1+1][j + x[i + 1+1]+1] + L[i+1][j+1] ) else skip)) ; execute (L[N - 1+1][5001+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda : sys.stdin.readline().rstrip() from collections import defaultdict from copy import copy def resolve(): n,a=map(int,input().split()) X=list(map(lambda x : int(x)-a,input().split())) dp=defaultdict(int) dp[0]=1 for x in X : ndp=copy(dp) for key,val in dp.items(): ndp[key+x]+=val dp=ndp print(dp[0]-1) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(2147483647) ; var INF : double := ("" + (("inf")))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; skip ; skip ; skip ; resolve(); operation resolve() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var X : Sequence := ((input->apply().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - a))->apply(_x) )) ; var dp : OclAny := defaultdict(OclType["int"]) ; dp->first() := 1 ; for x : X do ( var ndp : OclAny := copy(dp) ; for _tuple : dp->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var val : OclAny := _tuple->at(_indx); ndp[key + x+1] := ndp[key + x+1] + val) ; dp := ndp) ; execute (dp->first() - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import copy import heapq import sys import itertools import math import queue input=sys.stdin.readline sys.setrecursionlimit(1000000) mod=998244353 def read_values(): return map(int,input().split()) def read_index(): return map(lambda x : int(x)-1,input().split()) def read_list(): return list(read_values()) def read_lists(N): return[read_list()for n in range(N)] def init_dp1(init,N): return[init for _ in range(N)] def init_dp2(init,N,M): return[[init for _ in range(M)]for _ in range(N)] def main(): N,X=read_values() A=read_list() dp=[[[0 for _ in range(N*X+1)]for _ in range(N+1)]for _ in range(N+1)] dp[0][0][0]=1 for i,a in enumerate(A): for j in range(N+1): for k in range(N*X): if k+a<=N*X and jcollect( _x | (OclType["int"])->apply(_x) ); operation read_index() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ); operation read_list() : OclAny pre: true post: true activity: return (read_values()); operation read_lists(N : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, N-1)->select(n | true)->collect(n | (read_list())); operation init_dp1(init : OclAny, N : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (init)); operation init_dp2(init : OclAny, N : OclAny, M : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (init)))); operation main() pre: true post: true activity: var X : OclAny := null; Sequence{N,X} := read_values() ; var A : OclAny := read_list() ; var dp : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, N * X + 1-1)->select(_anon | true)->collect(_anon | (0)))))) ; dp->first()->first()->first() := 1 ; for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); for j : Integer.subrange(0, N + 1-1) do ( for k : Integer.subrange(0, N * X-1) do ( if (k + a->compareTo(N * X)) <= 0 & (j->compareTo(N)) < 0 then ( dp[i + 1+1][j + 1+1][k + a+1] := dp[i + 1+1][j + 1+1][k + a+1] + dp[i+1][j+1][k+1] ) else skip ; dp[i + 1+1][j+1][k+1] := dp[i + 1+1][j+1][k+1] + dp[i+1][j+1][k+1]))) ; var res : int := 0 ; for i : Integer.subrange(1, N + 1-1) do ( res := res + dp[N+1][i+1][i * X+1]) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lps(str): n=len(str) L=[[0 for x in range(n)]for y in range(n)] for i in range(n): L[i][i]=1 for cl in range(2,n+1): for i in range(n-cl+1): j=i+cl-1 if(str[i]==str[j]and cl==2): L[i][j]=2 elif(str[i]==str[j]): L[i][j]=L[i+1][j-1]+2 else : L[i][j]=max(L[i][j-1],L[i+1][j]) return L[0][n-1] def minimumNumberOfDeletions(str): n=len(str) l=lps(str) return(n-l) if __name__=="__main__" : str="geeksforgeeks" print("Minimum number of deletions=",minimumNumberOfDeletions(str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( OclType["String"] := "geeksforgeeks" ; execute ("Minimum number of deletions=")->display() ) else skip; operation lps(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var n : int := (OclType["String"])->size() ; var L : Sequence := Integer.subrange(0, n-1)->select(y | true)->collect(y | (Integer.subrange(0, n-1)->select(x | true)->collect(x | (0)))) ; for i : Integer.subrange(0, n-1) do ( L[i+1][i+1] := 1) ; for cl : Integer.subrange(2, n + 1-1) do ( for i : Integer.subrange(0, n - cl + 1-1) do ( var j : double := i + cl - 1 ; if (("" + ([i+1])) = ("" + ([j+1])) & cl = 2) then ( L[i+1][j+1] := 2 ) else (if (("" + ([i+1])) = ("" + ([j+1]))) then ( L[i+1][j+1] := L[i + 1+1][j - 1+1] + 2 ) else ( L[i+1][j+1] := Set{L[i+1][j - 1+1], L[i + 1+1][j+1]}->max() ) ) )) ; return L->first()[n - 1+1]; operation minimumNumberOfDeletions(OclType["String"] : OclAny) : OclAny pre: true post: true activity: n := (OclType["String"])->size() ; var l : OclAny := lps(OclType["String"]) ; return (n - l); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def makelist2(n,m): return[[0 for k in range(m)]for i in range(n)] n,a=map(int,input().split()) x=list(map(int,input().split())) X=max(x) X=max(X,a) b=[] for i in range(n): b.append(x[i]-a) dp=makelist2(n+1,2*n*X+1) dp[0][n*X]=1 for j in range(n+1): for t in range(2*n*X+1): if j>=1 and(t-b[j-1]<0 or t-b[j-1]>2*n*X): dp[j][t]=dp[j-1][t] elif j>=1 : dp[j][t]=dp[j-1][t]+dp[j-1][t-b[j-1]] print(dp[n][n*X]-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; Sequence{n,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var X : OclAny := (x)->max() ; X := Set{X, a}->max() ; var b : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((x[i+1] - a) : b)) ; var dp : OclAny := makelist2(n + 1, 2 * n * X + 1) ; dp->first()[n * X+1] := 1 ; for j : Integer.subrange(0, n + 1-1) do ( for t : Integer.subrange(0, 2 * n * X + 1-1) do ( if j >= 1 & (t - b[j - 1+1] < 0 or (t - b[j - 1+1]->compareTo(2 * n * X)) > 0) then ( dp[j+1][t+1] := dp[j - 1+1][t+1] ) else (if j >= 1 then ( dp[j+1][t+1] := dp[j - 1+1][t+1] + dp[j - 1+1][t - b[j - 1+1]+1] ) else skip))) ; execute (dp[n+1][n * X+1] - 1)->display(); operation makelist2(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, m-1)->select(k | true)->collect(k | (0)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from collections import defaultdict sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod=10**9+7 def I(): return int(input()) def LI(): return list(map(int,input().split())) def LIR(row,col): if row<=0 : return[[]for _ in range(col)] elif col==1 : return[I()for _ in range(row)] else : read_all=[LI()for _ in range(row)] return map(list,zip(*read_all)) N,A=LI() x=LI() dp=[[[0]*(50*N+1)for _ in range(N+1)]for _ in range(N)] dp[0][0][0]=1 dp[0][1][x[0]]=1 for i in range(1,N): for j in range(N+1): for k in range(50*N+1): dp[i][j][k]=dp[i-1][j][k] if k-x[i]>=0 : dp[i][j][k]+=dp[i-1][j-1][k-x[i]] ans=0 for j in range(1,N+1): ans+=dp[N-1][j][A*j] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; var N : OclAny := null; var A : OclAny := null; Sequence{N,A} := LI() ; var x : OclAny := LI() ; var dp : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (50 * N + 1)))))) ; dp->first()->first()->first() := 1 ; dp->first()[1+1][x->first()+1] := 1 ; for i : Integer.subrange(1, N-1) do ( for j : Integer.subrange(0, N + 1-1) do ( for k : Integer.subrange(0, 50 * N + 1-1) do ( dp[i+1][j+1][k+1] := dp[i - 1+1][j+1][k+1] ; if k - x[i+1] >= 0 then ( dp[i+1][j+1][k+1] := dp[i+1][j+1][k+1] + dp[i - 1+1][j - 1+1][k - x[i+1]+1] ) else skip))) ; var ans : int := 0 ; for j : Integer.subrange(1, N + 1-1) do ( ans := ans + dp[N - 1+1][j+1][A * j+1]) ; execute (ans)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LIR(row : OclAny, col : OclAny) : OclAny pre: true post: true activity: if row <= 0 then ( return Integer.subrange(0, col-1)->select(_anon | true)->collect(_anon | (Sequence{})) ) else (if col = 1 then ( return Integer.subrange(0, row-1)->select(_anon | true)->collect(_anon | (I())) ) else ( var read_all : Sequence := Integer.subrange(0, row-1)->select(_anon | true)->collect(_anon | (LI())) ; return (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name read_all)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name read_all)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name read_all)))))))`third->at(_indx)} ))->collect( _x | (OclType["Sequence"])->apply(_x) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100001 ; p=[]; def sieve(): isPrime=[0]*(MAX+1); for i in range(2,MAX+1): if(isPrime[i]==0): p.append(i); j=2 ; while(i*j<=MAX): isPrime[i*j]=1 ; j+=1 ; def phi(n): res=n ; i=0 ; while(p[i]*p[i]<=n): if(n % p[i]==0): res-=int(res/p[i]); while(n % p[i]==0): n=int(n/p[i]); i+=1 ; if(n>1): res-=int(res/n); return res ; sieve(); print(phi(11)); print(phi(21)); print(phi(31)); print(phi(41)); print(phi(51)); print(phi(61)); print(phi(91)); print(phi(101)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 100001; ; var p : Sequence := Sequence{}; ; skip ; skip ; sieve(); ; execute (phi(11))->display(); ; execute (phi(21))->display(); ; execute (phi(31))->display(); ; execute (phi(41))->display(); ; execute (phi(51))->display(); ; execute (phi(61))->display(); ; execute (phi(91))->display(); ; execute (phi(101))->display();; operation sieve() pre: true post: true activity: var isPrime : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX + 1)); ; for i : Integer.subrange(2, MAX + 1-1) do ( if (isPrime[i+1] = 0) then ( execute ((i) : p); ; var j : int := 2; ; while ((i * j->compareTo(MAX)) <= 0) do ( isPrime[i * j+1] := 1; ; j := j + 1;) ) else skip); operation phi(n : OclAny) pre: true post: true activity: var res : OclAny := n; ; var i : int := 0; ; while ((p[i+1] * p[i+1]->compareTo(n)) <= 0) do ( if (n mod p[i+1] = 0) then ( res := res - ("" + ((res / p[i+1])))->toInteger(); ; while (n mod p[i+1] = 0) do ( n := ("" + ((n / p[i+1])))->toInteger();) ) else skip ; i := i + 1;) ; if (n > 1) then ( res := res - ("" + ((res / n)))->toInteger(); ) else skip ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPossible(v,string): char_list=list(string) char_list.sort() for i in range(len(v)-1): for j in range(len(v)): temp=v[i]+v[j]; temp_list=list(temp) temp_list.sort() if(temp_list==char_list): return True ; return False ; if __name__=="__main__" : string="amazon" ; v=["fds","oxq","zoa","epw","amn"]; if(isPossible(v,string)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( string := "amazon"; ; v := Sequence{"fds"}->union(Sequence{"oxq"}->union(Sequence{"zoa"}->union(Sequence{"epw"}->union(Sequence{ "amn" })))); ; if (isPossible(v, string)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ) else skip; operation isPossible(v : OclAny, string : OclAny) pre: true post: true activity: var char_list : Sequence := (string)->characters() ; char_list := char_list->sort() ; for i : Integer.subrange(0, (v)->size() - 1-1) do ( for j : Integer.subrange(0, (v)->size()-1) do ( var temp : OclAny := v[i+1] + v[j+1]; ; var temp_list : Sequence := (temp) ; temp_list := temp_list->sort() ; if (temp_list = char_list) then ( return true; ) else skip)) ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def __gcd(a,b): if(a==0 or b==0): return 0 if(a==b): return a if(a>b): return __gcd(a-b,b) return __gcd(a,b-a) def coprime(a,b): if(__gcd(a,b)==1): print("Co-Prime") else : print("Not Co-Prime") a=5 ; b=6 coprime(a,b) a=8 ; b=16 coprime(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 5; b := 6 ; coprime(a, b) ; a := 8; b := 16 ; coprime(a, b); operation __gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0 or b = 0) then ( return 0 ) else skip ; if (a = b) then ( return a ) else skip ; if ((a->compareTo(b)) > 0) then ( return __gcd(a - b, b) ) else skip ; return __gcd(a, b - a); operation coprime(a : OclAny, b : OclAny) pre: true post: true activity: if (__gcd(a, b) = 1) then ( execute ("Co-Prime")->display() ) else ( execute ("Not Co-Prime")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys infile=None outfile=None def readline(): x=infile.readline() if len(x)>0 and x[-1]=='\n' : return x[:-1] else : return x def readint(): return int(readline()) def readfloat(): return float(readline()) def readints(): return[int(x)for x in readline().split()] def readfloats(): return[float(x)for x in readline().split()] def writeline(x): outfile.write(x+'\n') def writecase(casenum,answer): outfile.write('Case #{:d}:{}\n'.format(casenum,answer)) def run(main): global infile,outfile args=sys.argv infile=sys.stdin outfile=sys.stdout if len(args)==2 : if args[1]!='-' : infile=open(args[1],'r') if args[1].endswith('.in'): outfile=open(args[1][:-3]+'.out','w') elif len(args)==3 : if args[1]!='-' : infile=open(args[1],'r') if args[2]!='-' : outfile=open(args[2],'w') elif len(args)>3 : print("Expected 0,1,or 2 arguments,not{}".format(len(args)-1)) print(args) return t=readint() for casenum in range(1,t+1): main(casenum) if infile is not sys.stdin : infile.close() if outfile is not sys.stdout : outfile.close() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute infile : OclAny; attribute outfile : OclAny; operation initialise() pre: true post: true activity: skip ; var infile : OclAny := null ; var outfile : OclAny := null ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip; operation readline() : OclAny pre: true post: true activity: var x : String := infile.readLine() ; if (x)->size() > 0 & x->last() = ' ' then ( return x->front() ) else ( return x ); operation readint() : OclAny pre: true post: true activity: return ("" + ((readline())))->toInteger(); operation readfloat() : OclAny pre: true post: true activity: return ("" + ((readline())))->toReal(); operation readints() : OclAny pre: true post: true activity: return readline().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation readfloats() : OclAny pre: true post: true activity: return readline().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation writeline(x : OclAny) pre: true post: true activity: outfile.write(x + ' '); operation writecase(casenum : OclAny, answer : OclAny) pre: true post: true activity: outfile.write(StringLib.interpolateStrings('Case #{:d}:{} ', Sequence{casenum, answer})); operation run(main : OclAny) pre: true post: true activity: skip; skip ; var args : (trailer . (name argv)) := (trailer . (name argv)) ; infile := OclFile["System.in"] ; outfile := OclFile["System.out"] ; if (args)->size() = 2 then ( if args[1+1] /= '-' then ( infile := OclFile.newOclFile_Write(OclFile.newOclFile(args[1+1])) ; if args[1+1]->hasSuffix('.in') then ( outfile := OclFile.newOclFile_Write(OclFile.newOclFile(args[1+1].subrange(1,-3) + '.out')) ) else skip ) else skip ) else (if (args)->size() = 3 then ( if args[1+1] /= '-' then ( infile := OclFile.newOclFile_Write(OclFile.newOclFile(args[1+1])) ) else skip ; if args[2+1] /= '-' then ( outfile := OclFile.newOclFile_Write(OclFile.newOclFile(args[2+1])) ) else skip ) else (if (args)->size() > 3 then ( execute (StringLib.interpolateStrings("Expected 0,1,or 2 arguments,not{}", Sequence{(args)->size() - 1}))->display() ; execute (args)->display() ; return ) else skip ) ) ; var t : OclAny := readint() ; for casenum : Integer.subrange(1, t + 1-1) do ( main(casenum)) ; if not(infile <>= OclFile["System.in"]) then ( infile.closeFile() ) else skip ; if not(outfile <>= OclFile["System.out"]) then ( outfile.closeFile() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- b=int(input()) g=int(input()) n=int(input()) print(min(g,n)-(n-min(b,n))+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var g : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (Set{g, n}->min() - (n - Set{b, n}->min()) + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) A=[list(map(int,input().split()))for _ in range(N)] ans=0 for i in range(1,M+1): cnt=0 for a in A : if(i in a[1 :]): cnt+=1 if(cnt==N): ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ans : int := 0 ; for i : Integer.subrange(1, M + 1-1) do ( var cnt : int := 0 ; for a : A do ( if ((a->tail())->includes(i)) then ( cnt := cnt + 1 ) else skip) ; if (cnt = N) then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import reduce def main(): N,M=[int(x)for x in input().split()] A=[[int(x)for x in input().split()[1 :]]for _ in range(N)] print(len(reduce(lambda a,b : a & b,map(lambda a : set(a),A)))) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var A : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (input().split()->tail()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))) ; execute ((reduce(lambda a : OclAny, b : OclAny in (MathLib.bitwiseAnd(a, b)), (A)->collect( _x | (lambda a : OclAny in (Set{}->union((a))))->apply(_x) )))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) food=[0 for i in range(m)] for i in range(n): line=[int(t)for t in input().split()] k=line[0] a=line[1 :] for item in a : food[item-1]+=1 cnt=0 for item in food : if item==n : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var food : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( var line : Sequence := input().split()->select(t | true)->collect(t | (("" + ((t)))->toInteger())) ; var k : OclAny := line->first() ; var a : OclAny := line->tail() ; for item : a do ( food[item - 1+1] := food[item - 1+1] + 1)) ; var cnt : int := 0 ; for item : food do ( if item = n then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bit_check(n): if((n &(n-1))==0): return True return False if __name__=='__main__' : n=14 if(bit_check(n)): print('1') else : print('0') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 14 ; if (bit_check(n)) then ( execute ('1')->display() ) else ( execute ('0')->display() ) ) else skip; operation bit_check(n : OclAny) : OclAny pre: true post: true activity: if ((MathLib.bitwiseAnd(n, (n - 1))) = 0) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np N,M=map(int,input().split()) search=np.zeros(M+1) for i in range(N): K=list(map(int,input().split())) for j in range(1,K[0]+1): search[K[j]]+=1 place=np.where(search==N) print(len(place[0])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var search : Sequence := MatrixLib.singleValueMatrix(M + 1, 0.0) ; for i : Integer.subrange(0, N-1) do ( var K : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(1, K->first() + 1-1) do ( search[K[j+1]+1] := search[K[j+1]+1] + 1)) ; var place : (trailer . (name where) (arguments ( (arglist (argument (test (logical_test (comparison (comparison (expr (atom (name search)))) == (comparison (expr (atom (name N))))))))) ))) := ; execute ((place->first())->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections a,b=map(int,input().split()) c=[list(map(int,input().split()))for i in range(a)] result=[] for i in range(a): n=c[i][1 :] result+=n ans=collections.Counter(result) ans1,ans2=zip(*ans.most_common()) ans2=list(ans2) print(ans2.count(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : Sequence := Integer.subrange(0, a-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var result : Sequence := Sequence{} ; for i : Integer.subrange(0, a-1) do ( var n : OclAny := c[i+1]->tail() ; result := result + n) ; var ans : OclAny := .Counter(result) ; var ans1 : OclAny := null; var ans2 : OclAny := null; Sequence{ans1,ans2} := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name ans)) (trailer . (name most_common) (arguments ( ))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name ans)) (trailer . (name most_common) (arguments ( ))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name ans)) (trailer . (name most_common) (arguments ( ))))))))`third->at(_indx)} ) ; var ans2 : Sequence := (ans2) ; execute (ans2->count(a))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate from collections import defaultdict N,T=map(int,input().split()) A=[int(x)for x in input().split()] B=[x for x in accumulate(A[: :-1],max)][: :-1] c=defaultdict(int) for i in range(N-1): c[B[i]-A[i]]+=1 print(c[max(c)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := null; var T : OclAny := null; Sequence{N,T} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var B : OclAny := accumulate(A(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))), max)->select(x | true)->collect(x | (x))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var c : OclAny := defaultdict(OclType["int"]) ; for i : Integer.subrange(0, N - 1-1) do ( c[B[i+1] - A[i+1]+1] := c[B[i+1] - A[i+1]+1] + 1) ; execute (c[(c)->max()+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from itertools import accumulate read=sys.stdin.read N,T,*A=map(int,read().split()) a_maximum=list(reversed(list(accumulate(A[: :-1],max))[:-1])) a=[j-i for i,j in zip(A,a_maximum)] minimum=max(a) print(a.count(minimum)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var read : OclAny := (OclFile["System.in"]).read ; var N : OclAny := null; var T : OclAny := null; var A : OclAny := null; Sequence{N,T,A} := (read().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a_maximum : Sequence := ((OclType["Sequence"](accumulate(A(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))), max))->front())->reverse()) ; var a : Sequence := Integer.subrange(1, A->size())->collect( _indx | Sequence{A->at(_indx), a_maximum->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let j : OclAny = _tuple->at(2) in (j - i)) ; var minimum : OclAny := (a)->max() ; execute (a->count(minimum))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): from collections import Counter n,t=map(int,input().split()) a=list(map(int,input().split())) minmum_numbers=[a[0]for _ in range(n)] diff=[0 for _ in range(n)] for i in range(1,n): minmum_numbers[i]=min(minmum_numbers[i-1],a[i]) diff[i]=a[i]-minmum_numbers[i] print(sorted(Counter(diff).items(),key=lambda x : x[0],reverse=True)[0][1]) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: skip ; var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var minmum_numbers : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (a->first())) ; var diff : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)) ; for i : Integer.subrange(1, n-1) do ( minmum_numbers[i+1] := Set{minmum_numbers[i - 1+1], a[i+1]}->min() ; diff[i+1] := a[i+1] - minmum_numbers[i+1]) ; execute (sorted(Counter(diff)->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))), (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True))))))))->first()[1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def read_int(): return int(input().strip()) def read_ints(): return list(map(int,input().strip().split(' '))) def solve(): N,T=read_ints() A=read_ints() MAX_OF_REST=[] MAX=-math.inf for i in range(N-1,-1,-1): MAX=max(MAX,A[i]) MAX_OF_REST.append(MAX) MAX_OF_REST.reverse() max_profit=0 max_count=0 for i in range(N-1): profit=MAX_OF_REST[i+1]-A[i] if profit>max_profit : max_profit=profit max_count=1 elif profit==max_profit : max_count+=1 return max_count if __name__=='__main__' : print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( execute (solve())->display() ) else skip; operation read_int() : OclAny pre: true post: true activity: return ("" + ((input()->trim())))->toInteger(); operation read_ints() : OclAny pre: true post: true activity: return ((input()->trim().split(' '))->collect( _x | (OclType["int"])->apply(_x) )); operation solve() : OclAny pre: true post: true activity: var N : OclAny := null; var T : OclAny := null; Sequence{N,T} := read_ints() ; var A : OclAny := read_ints() ; var MAX_OF_REST : Sequence := Sequence{} ; var MAX : OclAny := - ; for i : Integer.subrange(-1 + 1, N - 1)->reverse() do ( MAX := Set{MAX, A[i+1]}->max() ; execute ((MAX) : MAX_OF_REST)) ; MAX_OF_REST := MAX_OF_REST->reverse() ; var max_profit : int := 0 ; var max_count : int := 0 ; for i : Integer.subrange(0, N - 1-1) do ( var profit : double := MAX_OF_REST[i + 1+1] - A[i+1] ; if (profit->compareTo(max_profit)) > 0 then ( max_profit := profit ; max_count := 1 ) else (if profit = max_profit then ( max_count := max_count + 1 ) else skip)) ; return max_count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,T=list(map(int,input().split())) A=list(map(int,input().split())) max_diff=0 count=0 minv=A[0] for i in range(1,len(A)): if max_diff<(A[i]-minv): max_diff=A[i]-minv count=1 elif max_diff==(A[i]-minv): count+=1 if minv>A[i]: minv=A[i] print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var T : OclAny := null; Sequence{N,T} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var max_diff : int := 0 ; var count : int := 0 ; var minv : OclAny := A->first() ; for i : Integer.subrange(1, (A)->size()-1) do ( if (max_diff->compareTo((A[i+1] - minv))) < 0 then ( max_diff := A[i+1] - minv ; count := 1 ) else (if max_diff = (A[i+1] - minv) then ( count := count + 1 ) else skip) ; if (minv->compareTo(A[i+1])) > 0 then ( minv := A[i+1] ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def _input(): return map(int,input().split()) n=int(input()) a=int(input()) b=int(input()) if n % a==0 or n % b==0 : print("YES") print(str(n//a)+' 0' if n % a==0 else '0 '+str(n//b)) else : c1=1 ; c2=0 n-=a ; k=n//b check=False while k>0 : if(n-k*b)% a==0 : check=True ; break k-=1 c2=k c1+=(n-k*b)//a if check==False : print("NO") else : print("YES") print(c1,c2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod a = 0 or n mod b = 0 then ( execute ("YES")->display() ; execute (if n mod a = 0 then ("" + ((n div a))) + ' 0' else '0 ' + ("" + ((n div b))) endif)->display() ) else ( var c1 : int := 1; var c2 : int := 0 ; n := n - a; var k : int := n div b ; var check : boolean := false ; while k > 0 do ( if (n - k * b) mod a = 0 then ( check := true; break ) else skip ; k := k - 1) ; c2 := k ; c1 := c1 + (n - k * b) div a ; if check = false then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; execute (c1)->display() ) ); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- akhi=int(input()) if(akhi==2): print(akhi) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var akhi : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (akhi = 2) then ( execute (akhi)->display() ) else ( execute (1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(1 if n!=2 else 2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (if n /= 2 then 1 else 2 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=[int(i)for i in input().split()][: :-1] minprice=[a[0]] for i in range(1,n): minprice.append(min(minprice[i-1],a[i])) c=0 for i in range(n): c+=a[i]>minprice[i] print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var minprice : Sequence := Sequence{ a->first() } ; for i : Integer.subrange(1, n-1) do ( execute ((Set{minprice[i - 1+1], a[i+1]}->min()) : minprice)) ; var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( c := c + (a[i+1]->compareTo(minprice[i+1])) > 0) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==2 : print(n) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 2 then ( execute (n)->display() ) else ( execute (1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print((input()=='2')+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (((OclFile["System.in"]).readLine() = '2') + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- v=int(input()) res=1 if v!=2 else 2 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var v : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : int := if v /= 2 then 1 else 2 endif ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : a,b=input().split() if b=='X' : break if '_' in a : ans=a.split('_') else : ans=[] j=0 for i in range(1,len(a)): if a[i].isupper(): ans.append(a[j : i]) j=i ans.append(a[j :]) if b=='D' : ans='_'.join(map(str.lower,ans)) else : ans=''.join(map(str.capitalize,ans)) if b=='L' : ans=ans[0].lower()+ans[1 :] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; if b = 'X' then ( break ) else skip ; if (a)->includes('_') then ( var ans : OclAny := a.split('_') ) else ( ans := Sequence{} ; var j : int := 0 ; for i : Integer.subrange(1, (a)->size()-1) do ( if a[i+1]->matches("[A-Z ]*") then ( execute ((a.subrange(j+1, i)) : ans) ; j := i ) else skip) ; execute ((a.subrange(j+1)) : ans) ) ; if b = 'D' then ( ans := StringLib.sumStringsWithSeparator(((ans)->collect( _x | (("" + (.lower)))->apply(_x) )), '_') ) else ( ans := StringLib.sumStringsWithSeparator(((ans)->collect( _x | (("" + (.capitalize)))->apply(_x) )), '') ; if b = 'L' then ( ans := ans->first()->toLowerCase() + ans->tail() ) else skip ) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- large=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ") small=list("abcdefghijklmnopqrstuvwxyz") while 1 : word,alpha=input().split() if alpha=="X" : break word=list(word) ans="" if alpha=="L" : first=word.pop(0) if first in large : ans+=small[large.index(first)] else : ans+=first while word!=[]: w=word.pop(0) if w=="_" : target=word.pop(0) if target in small : ans+=large[small.index(target)] else : ans+=target else : ans+=w elif alpha=="U" : first=word.pop(0) if first in small : ans+=large[small.index(first)] else : ans+=first while word!=[]: w=word.pop(0) if w=="_" : target=word.pop(0) if target in small : ans+=large[small.index(target)] else : ans+=target else : ans+=w elif alpha=="D" : first=word.pop(0) if first in large : ans+=small[large.index(first)] else : ans+=first while word!=[]: w=word.pop(0) if w in large : ans+="_"+small[large.index(w)] else : ans+=w print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var large : Sequence := ("ABCDEFGHIJKLMNOPQRSTUVWXYZ")->characters() ; var small : Sequence := ("abcdefghijklmnopqrstuvwxyz")->characters() ; while 1 do ( var word : OclAny := null; var alpha : OclAny := null; Sequence{word,alpha} := input().split() ; if alpha = "X" then ( break ) else skip ; var word : Sequence := (word) ; var ans : String := "" ; if alpha = "L" then ( var first : OclAny := word->at(0`firstArg+1) ; word := word->excludingAt(0+1) ; if (large)->includes(first) then ( ans := ans + small[large->indexOf(first) - 1+1] ) else ( ans := ans + first ) ; while word /= Sequence{} do ( var w : OclAny := word->at(0`firstArg+1) ; word := word->excludingAt(0+1) ; if w = "_" then ( var target : OclAny := word->at(0`firstArg+1) ; word := word->excludingAt(0+1) ; if (small)->includes(target) then ( ans := ans + large[small->indexOf(target) - 1+1] ) else ( ans := ans + target ) ) else ( ans := ans + w )) ) else (if alpha = "U" then ( first := word->at(0`firstArg+1) ; word := word->excludingAt(0+1) ; if (small)->includes(first) then ( ans := ans + large[small->indexOf(first) - 1+1] ) else ( ans := ans + first ) ; while word /= Sequence{} do ( w := word->at(0`firstArg+1) ; word := word->excludingAt(0+1) ; if w = "_" then ( target := word->at(0`firstArg+1) ; word := word->excludingAt(0+1) ; if (small)->includes(target) then ( ans := ans + large[small->indexOf(target) - 1+1] ) else ( ans := ans + target ) ) else ( ans := ans + w )) ) else (if alpha = "D" then ( first := word->at(0`firstArg+1) ; word := word->excludingAt(0+1) ; if (large)->includes(first) then ( ans := ans + small[large->indexOf(first) - 1+1] ) else ( ans := ans + first ) ; while word /= Sequence{} do ( w := word->at(0`firstArg+1) ; word := word->excludingAt(0+1) ; if (large)->includes(w) then ( ans := ans + "_" + small[large->indexOf(w) - 1+1] ) else ( ans := ans + w )) ) else skip ) ) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re while True : n,t=map(str,input().split()) if t=='X' : break if '_' in n : if t=='D' : print(n) else : m=n.title() l=re.sub('_','',m) if t=='U' : print(l) elif t=='L' : p=l[0].lower()+l[1 :] print(p) else : q=n[0].upper()+n[1 :] r=re.findall('[A-Z][a-z]*',q) if t=='D' : s='_'.join(r) print(s.lower()) elif t=='U' : print("".join(r)) elif t=='L' : u="".join(r) v=u[0].lower()+u[1 :] print(v) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; if t = 'X' then ( break ) else skip ; if (n)->includes('_') then ( if t = 'D' then ( execute (n)->display() ) else ( var m : String := StringLib.toTitleCase(n) ; var l : String := (m).replaceAllMatches('_', '') ; if t = 'U' then ( execute (l)->display() ) else (if t = 'L' then ( var p : OclAny := l->first()->toLowerCase() + l->tail() ; execute (p)->display() ) else skip) ) ) else ( var q : OclAny := n->first()->toUpperCase() + n->tail() ; var r : Sequence(String) := (q)->allMatches('[A-Z][a-z]*') ; if t = 'D' then ( var s : String := StringLib.sumStringsWithSeparator((r), '_') ; execute (s->toLowerCase())->display() ) else (if t = 'U' then ( execute (StringLib.sumStringsWithSeparator((r), ""))->display() ) else (if t = 'L' then ( var u : String := StringLib.sumStringsWithSeparator((r), "") ; var v : OclAny := u->first()->toLowerCase() + u->tail() ; execute (v)->display() ) else skip ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : words,type_=input().split() if type_=="L" : if "_" in words : words=words.split("_") words=words[0]+"".join([w[0].upper()+w[1 :]for w in words[1 :]]) else : words=words[0].lower()+words[1 :] elif type_=="U" : if "_" in words : words=words.split("_") words="".join([w[0].upper()+w[1 :]for w in words]) else : words=words[0].upper()+words[1 :] elif type_=="D" : indices=[i for i,w in enumerate(words)if w.isupper()]+[len(words)] if words[0].islower(): indices.insert(0,0) words="_".join([words[indices[i]].lower()+words[indices[i]+1 : indices[i+1]]for i in range(len(indices)-1)]) else : break print(words) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var words : OclAny := null; var type_ : OclAny := null; Sequence{words,type_} := input().split() ; if type_ = "L" then ( if (words)->includes("_") then ( var words : OclAny := words.split("_") ; words := words->first() + StringLib.sumStringsWithSeparator((words->tail()->select(w | true)->collect(w | (w->first()->toUpperCase() + w->tail()))), "") ) else ( words := words->first()->toLowerCase() + words->tail() ) ) else (if type_ = "U" then ( if (words)->includes("_") then ( words := words.split("_") ; words := StringLib.sumStringsWithSeparator((words->select(w | true)->collect(w | (w->first()->toUpperCase() + w->tail()))), "") ) else ( words := words->first()->toUpperCase() + words->tail() ) ) else (if type_ = "D" then ( var indices : Sequence := Integer.subrange(1, (words)->size())->collect( _indx | Sequence{_indx-1, (words)->at(_indx)} )->select(_tuple | let i : OclAny = _tuple->at(1) in let w : OclAny = _tuple->at(2) in w->matches("[A-Z ]*"))->collect(_tuple | let i : OclAny = _tuple->at(1) in let w : OclAny = _tuple->at(2) in (i))->union(Sequence{ (words)->size() }) ; if words->first()->matches("[a-z ]*") then ( indices := indices.insertAt(0+1, 0) ) else skip ; words := StringLib.sumStringsWithSeparator((Integer.subrange(0, (indices)->size() - 1-1)->select(i | true)->collect(i | (words[indices[i+1]+1]->toLowerCase() + words.subrange(indices[i+1] + 1+1, indices[i + 1+1])))), "_") ) else ( break ) ) ) ; execute (words)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : name,type=map(str,input().split()) if type=="X" : break else : N=list(name) if "_" in N : if type=="U" or type=="L" : cnt=0 for i in range(len(N)): if i==0 and type=="U" : N[i]=N[i].upper() elif N[i]=="_" : cnt+=1 elif cnt==1 : N[i]=N[i].upper() cnt=0 N=[i for i in N if i!="_"] elif type=="U" : N[0]=N[0].upper() elif type=="L" : N[0]=N[0].lower() else : s=0 for i in range(len(N)): if i==0 : N[s]=N[s].lower() s+=1 elif N[s].isupper(): N[s]=N[s].lower() N.insert(s,"_") s+=2 else : s+=1 for i in range(len(N)): if i==len(N)-1 : print(N[i]) else : print(N[i],end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var name : OclAny := null; var type : OclAny := null; Sequence{name,type} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; if type = "X" then ( break ) else ( var N : Sequence := (name) ; if (N)->includes("_") then ( if type = "U" or type = "L" then ( var cnt : int := 0 ; for i : Integer.subrange(0, (N)->size()-1) do ( if i = 0 & type = "U" then ( N[i+1] := N[i+1]->toUpperCase() ) else (if N[i+1] = "_" then ( cnt := cnt + 1 ) else (if cnt = 1 then ( N[i+1] := N[i+1]->toUpperCase() ; cnt := 0 ) else skip ) ) ) ; N := N->select(i | i /= "_")->collect(i | (i)) ) else skip ) else (if type = "U" then ( N->first() := N->first()->toUpperCase() ) else (if type = "L" then ( N->first() := N->first()->toLowerCase() ) else ( var s : int := 0 ; for i : Integer.subrange(0, (N)->size()-1) do ( if i = 0 then ( N[s+1] := N[s+1]->toLowerCase() ; s := s + 1 ) else (if N[s+1]->matches("[A-Z ]*") then ( N[s+1] := N[s+1]->toLowerCase() ; N := N.insertAt(s+1, "_") ; s := s + 2 ) else ( s := s + 1 ) ) ) ) ) ) ; for i : Integer.subrange(0, (N)->size()-1) do ( if i = (N)->size() - 1 then ( execute (N[i+1])->display() ) else ( execute (N[i+1])->display() )) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b,i,arr=int(input()),int(input()),int(input()),0,[] while i*a<=n : arr.append(a*i); i+=1 for j in range(len(arr)): if(n-arr[j])% b==0 : print("YES"); print(j,(n-arr[j])//b); break else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; var i : OclAny := null; var arr : OclAny := null; Sequence{n,a,b,i,arr} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),("" + (((OclFile["System.in"]).readLine())))->toInteger(),("" + (((OclFile["System.in"]).readLine())))->toInteger(),0,Sequence{}} ; while (i * a->compareTo(n)) <= 0 do ( execute ((a * i) : arr); i := i + 1) ; (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr)))))))) ))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) ))) % (expr (atom (name b))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))))))) ; (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j))))))) , (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) ))) // (expr (atom (name b))))))))) )))))))))) ; (small_stmt break)))))) (else_clause else : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lengthOfLastWord(a): l=0 x=a.strip() for i in range(len(x)): if x[i]==" " : l=0 else : l+=1 return l if __name__=="__main__" : inp="Geeks For Geeks " print("The length of last word is",lengthOfLastWord(inp)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var inp : String := "Geeks For Geeks " ; execute ("The length of last word is")->display() ) else skip; operation lengthOfLastWord(a : OclAny) : OclAny pre: true post: true activity: var l : int := 0 ; var x : String := a->trim() ; for i : Integer.subrange(0, (x)->size()-1) do ( if x[i+1] = " " then ( l := 0 ) else ( l := l + 1 )) ; return l; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=[int(i)for i in input().split()] if a==0 and b==0 : print('NO') else : if abs(a-b)==0 or abs(a-b)==1 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if a = 0 & b = 0 then ( execute ('NO')->display() ) else ( if (a - b)->abs() = 0 or (a - b)->abs() = 1 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minSwaps(arr,n): numberOfOnes=0 for i in range(0,n): if(arr[i]==1): numberOfOnes=numberOfOnes+1 x=numberOfOnes count_ones=0 maxOnes=0 for i in range(0,x): if(arr[i]==1): count_ones=count_ones+1 maxOnes=count_ones for i in range(1,(n-x+1)): if(arr[i-1]==1): count_ones=count_ones-1 if(arr[i+x-1]==1): count_ones=count_ones+1 if(maxOnesunion(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 1 })))))))) ; n := 9 ; execute (minSwaps(a, n))->display(); operation minSwaps(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var numberOfOnes : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] = 1) then ( numberOfOnes := numberOfOnes + 1 ) else skip) ; var x : int := numberOfOnes ; var count_ones : int := 0 ; var maxOnes : int := 0 ; for i : Integer.subrange(0, x-1) do ( if (arr[i+1] = 1) then ( count_ones := count_ones + 1 ) else skip) ; maxOnes := count_ones ; for i : Integer.subrange(1, (n - x + 1)-1) do ( if (arr[i - 1+1] = 1) then ( count_ones := count_ones - 1 ) else skip ; if (arr[i + x - 1+1] = 1) then ( count_ones := count_ones + 1 ) else skip ; if ((maxOnes->compareTo(count_ones)) < 0) then ( maxOnes := count_ones ) else skip) ; var numberOfZeroes : double := x - maxOnes ; return numberOfZeroes; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def countX(n): count=0 for i in range(n+1): if n-i==(n ^ i): count+=1 return count if __name__=='__main__' : n=5 answer=countX(n) print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( n := 5 ; var answer : OclAny := countX(n) ; execute (answer)->display() ) else skip; operation countX(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( if n - i = (MathLib.bitwiseXor(n, i)) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lower(matrix,row,col): for i in range(0,row): for j in range(0,col): if(ij): print("0",end=" "); else : print(matrix[i][j],end=" "); print(" "); matrix=[[1,2,3],[4,5,6],[7,8,9]]; row=3 ; col=3 ; print("Lower triangular matrix: "); lower(matrix,row,col); print("Upper triangular matrix: "); upper(matrix,row,col); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; matrix := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))}->union(Sequence{ Sequence{7}->union(Sequence{8}->union(Sequence{ 9 })) })); ; row := 3; ; col := 3; ; execute ("Lower triangular matrix: ")->display(); ; lower(matrix, row, col); ; execute ("Upper triangular matrix: ")->display(); ; upper(matrix, row, col);; operation lower(matrix : OclAny, row : OclAny, col : OclAny) pre: true post: true activity: for i : Integer.subrange(0, row-1) do ( for j : Integer.subrange(0, col-1) do ( if ((i->compareTo(j)) < 0) then ( execute ("0")->display(); ) else ( execute (matrix[i+1][j+1])->display(); )) ; execute (" ")->display();); operation upper(matrix : OclAny, row : OclAny, col : OclAny) pre: true post: true activity: for i : Integer.subrange(0, row-1) do ( for j : Integer.subrange(0, col-1) do ( if ((i->compareTo(j)) > 0) then ( execute ("0")->display(); ) else ( execute (matrix[i+1][j+1])->display(); )) ; execute (" ")->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def difference(M,N): return M+N if __name__=='__main__' : M=999999999 N=1000000000 print(difference(M,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( M := 999999999 ; N := 1000000000 ; execute (difference(M, N))->display() ) else skip; operation difference(M : OclAny, N : OclAny) : OclAny pre: true post: true activity: return M + N; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input()[: :-1] new='' mx='a' for i in range(len(s)): if s[i]==mx : new+=s[i] elif s[i]>mx : new+=s[i] mx=s[i] print(new[: :-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := input()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var new : String := '' ; var mx : String := 'a' ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = mx then ( new := new + s[i+1] ) else (if s[i+1] > mx then ( new := new + s[i+1] ; mx := s[i+1] ) else skip)) ; execute (new(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() realsus=[] for i in range(len(n)): realsus.append((n[i],i)) realsus.sort(key=lambda x : 100-ord(x[0])) curmax=-1 ans=[] for i in realsus : if i[1]>curmax : curmax=i[1] ans.append(i[0]) print("".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var realsus : Sequence := Sequence{} ; for i : Integer.subrange(0, (n)->size()-1) do ( execute ((Sequence{n[i+1], i}) : realsus)) ; realsus := realsus->sort() ; var curmax : int := -1 ; var ans : Sequence := Sequence{} ; for i : realsus do ( if (i[1+1]->compareTo(curmax)) > 0 then ( curmax := i[1+1] ; execute ((i->first()) : ans) ) else skip) ; execute (StringLib.sumStringsWithSeparator((ans), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=m='' for x in input()[: :-1]: if x>=m : a+=x m=max(m,x) print(a[: :-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := ''; var m : String := '' ; for x : input()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if (x->compareTo(m)) >= 0 then ( a := a + x ) else skip ; m := Set{m, x}->max()) ; execute (a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=[i for i in input()] a=[0]*26 for i in range(len(s)): a[ord(s[i])-97]=i a=a[: :-1] for i in range(1,len(a)): a[i]=max(a[i],a[i-1]) print('z'*s.count('z'),end='') for j in range(1,26): letter=chr(122-j) for i in range(a[j-1],a[j]+1): if s[i]==letter : print(letter,end='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := (OclFile["System.in"]).readLine()->select(i | true)->collect(i | (i)) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for i : Integer.subrange(0, (s)->size()-1) do ( a[(s[i+1])->char2byte() - 97+1] := i) ; a := a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; for i : Integer.subrange(1, (a)->size()-1) do ( a[i+1] := Set{a[i+1], a[i - 1+1]}->max()) ; execute (StringLib.nCopies('z', s->count('z')))->display() ; for j : Integer.subrange(1, 26-1) do ( var letter : String := (122 - j)->byte2char() ; for i : Integer.subrange(a[j - 1+1], a[j+1] + 1-1) do ( if s[i+1] = letter then ( execute (letter)->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k='' s=input() while s!='' : ans=sorted(s)[sorted(s).index(max(s)):] s=s[: :-1][: s[: :-1].index(max(s))] for i in ans : k=k+i s=s[: :-1] print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : String := '' ; var s : String := (OclFile["System.in"]).readLine() ; while s /= '' do ( var ans : OclAny := sorted(s).subrange(sorted(s)->indexOf((s)->max()) - 1+1) ; s := s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))).subrange(1,s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->indexOf((s)->max()) - 1) ; for i : ans do ( k := k + i) ; s := s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ; execute (k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) a=int(input()) b=int(input()) c,d,h=0,0,0 if a>b : a,b=b,a h=1 while n>0 : if n % a!=0 : n-=b d+=1 else : c+=n//a n=0 if n<0 : print("NO") else : print("YES") if h==1 : c,d=d,c print(c,d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : OclAny := null; var d : OclAny := null; var h : OclAny := null; Sequence{c,d,h} := Sequence{0,0,0} ; if (a->compareTo(b)) > 0 then ( Sequence{a,b} := Sequence{b,a} ; var h : int := 1 ) else skip ; while n > 0 do ( if n mod a /= 0 then ( n := n - b ; d := d + 1 ) else ( c := c + n div a ; n := 0 )) ; if n < 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; if h = 1 then ( var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := Sequence{d,c} ) else skip ; execute (c)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a=int(input()) b=[int(i)for i in input().split()][: :-1] cnt=0 min=b[0] for i in range(1,a): if b[i]>min : cnt+=1 elif b[i]toInteger()-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : OclAny := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var cnt : int := 0 ; var min : OclAny := b->first() ; for i : Integer.subrange(1, a-1) do ( if (b[i+1]->compareTo(min)) > 0 then ( cnt := cnt + 1 ) else (if (b[i+1]->compareTo(min)) < 0 then ( min := b[i+1] ) else skip)) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import random n=int(input()) a=[list(input())for _ in range(n)] e=[0 for _ in range(n)] kachi=[0 for _ in range(n)] hikiwake=[0 for _ in range(n)] for i in range(n): for j in range(n): if a[i][j]=='o' : e[i]+=3/n kachi[i]+=1 elif a[i][j]=='-' : e[i]+=1/n hikiwake[i]+=1 me=-1 idx=-1 for i in range(n): if metoInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((OclFile["System.in"]).readLine())->characters())) ; var e : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)) ; var kachi : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)) ; var hikiwake : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if a[i+1][j+1] = 'o' then ( e[i+1] := e[i+1] + 3 / n ; kachi[i+1] := kachi[i+1] + 1 ) else (if a[i+1][j+1] = '-' then ( e[i+1] := e[i+1] + 1 / n ; hikiwake[i+1] := hikiwake[i+1] + 1 ) else skip))) ; var me : int := -1 ; var idx : int := -1 ; for i : Integer.subrange(0, n-1) do ( if (me->compareTo(e[i+1])) < 0 then ( me := e[i+1] ; idx := i ) else skip) ; var ls : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if a[i+1][idx+1] = 'o' then ( execute ((i + 1) : ls) ) else skip) ; if (ls)->size() = 0 then ( execute ((idx + 1) : ls) ) else skip ; for i : Integer.subrange(0, 1000-1) do ( execute (ls[i mod (ls)->size()+1])->display() ; var s : String := (OclFile["System.in"]).readLine()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minimumMoves(a,n): operations=0 a.sort(reverse=False) for i in range(0,n,1): operations=operations+abs(a[i]-(i+1)) return operations if __name__=='__main__' : arr=[5,3,2] n=len(arr) print(minimumMoves(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var arr : Sequence := Sequence{5}->union(Sequence{3}->union(Sequence{ 2 })) ; n := (arr)->size() ; execute (minimumMoves(arr, n))->display() ) else skip; operation minimumMoves(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var operations : int := 0 ; a := a->sort() ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( operations := operations + (a[i+1] - (i + 1))->abs()) ; return operations; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def solve(): n=int(input()) s=input() ans=[] last=n-1 for i in range(n): if s[i]=='1' : while last>i : if s[last]=='0' : ans.append(i+1) ans.append(last+1) last-=1 break last-=1 return sorted(ans) for i in range(int(input())): ans=solve() if len(ans)==0 : print(0) else : print(1) print(len(ans),*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( ans := solve() ; if (ans)->size() = 0 then ( execute (0)->display() ) else ( execute (1)->display() ; execute ((ans)->size())->display() )); operation solve() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var ans : Sequence := Sequence{} ; var last : double := n - 1 ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = '1' then ( while (last->compareTo(i)) > 0 do ( if s[last+1] = '0' then ( execute ((i + 1) : ans) ; execute ((last + 1) : ans) ; last := last - 1 ; break ) else skip ; last := last - 1) ) else skip) ; return ans->sort(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) for j in range(int(input())): n=int(input()) s=list(input()) ss=sorted(s) if s==ss : print(0) else : print(1) l=[] for i in range(n): if(s[i]!=ss[i]): l.append(str(i+1)) print(len(l),end=' ') print(' '.join(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var ss : Sequence := s->sort() ; if s = ss then ( execute (0)->display() ) else ( execute (1)->display() ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if (s[i+1] /= ss[i+1]) then ( execute ((("" + ((i + 1)))) : l) ) else skip) ; execute ((l)->size())->display() ; execute (StringLib.sumStringsWithSeparator((l), ' '))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) s=input() cnt0=s.count('0') cnt1=n-cnt0 swap=[] for i in range(cnt0): if s[i]!='0' : swap.append(i+1) for i in range(cnt0,cnt0+cnt1): if s[i]!='1' : swap.append(i+1) if len(swap)==0 : print(0) else : print(1) print(len(swap),*swap) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var cnt0 : int := s->count('0') ; var cnt1 : double := n - cnt0 ; var swap : Sequence := Sequence{} ; for i : Integer.subrange(0, cnt0-1) do ( if s[i+1] /= '0' then ( execute ((i + 1) : swap) ) else skip) ; for i : Integer.subrange(cnt0, cnt0 + cnt1-1) do ( if s[i+1] /= '1' then ( execute ((i + 1) : swap) ) else skip) ; if (swap)->size() = 0 then ( execute (0)->display() ) else ( execute (1)->display() ; execute ((swap)->size())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) outp='' for i in range(n): breakFlag=False outK=0 lstJ=[] lstK=[] strLen=int(input()) myStr=list(str(input())) for j in range(strLen-1): if not(breakFlag): if myStr[j]=='1' : for k in range(strLen-1,j-1,-1): if myStr[k]=='0' : outK+=2 lstJ.append(j) lstK.append(k) myStr[j]='0' myStr[k]='1' break if(k==j-1): breakFlag=True else : break if outK==0 : print(0) else : print(1) print(outK,end=' ') for i in lstJ : print(i+1,end=' ') lstK.reverse() for i in lstK : print(i+1,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var outp : String := '' ; for i : Integer.subrange(0, n-1) do ( var breakFlag : boolean := false ; var outK : int := 0 ; var lstJ : Sequence := Sequence{} ; var lstK : Sequence := Sequence{} ; var strLen : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var myStr : Sequence := (("" + (((OclFile["System.in"]).readLine()))))->characters() ; for j : Integer.subrange(0, strLen - 1-1) do ( if not((breakFlag)) then ( if myStr[j+1] = '1' then ( for k : Integer.subrange(j - 1 + 1, strLen - 1)->reverse() do ( if myStr[k+1] = '0' then ( outK := outK + 2 ; execute ((j) : lstJ) ; execute ((k) : lstK) ; myStr[j+1] := '0' ; myStr[k+1] := '1' ; break ) else skip ; if (k = j - 1) then ( breakFlag := true ) else skip) ) else skip ) else ( break )) ; if outK = 0 then ( execute (0)->display() ) else ( execute (1)->display() ; execute (outK)->display() ; for i : lstJ do ( execute (i + 1)->display()) ; lstK := lstK->reverse() ; for i : lstK do ( execute (i + 1)->display()) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) s=input() ans=[] last=n-1 for i in range(n): if s[i]=='1' : while last>i : if s[last]=='0' : ans.append(i+1) ans.append(last+1) last-=1 break last-=1 return sorted(ans) for i in range(int(input())): ans=solve() if len(ans)==0 : print(0) else : print(1) print(len(ans),*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( ans := solve() ; if (ans)->size() = 0 then ( execute (0)->display() ) else ( execute (1)->display() ; execute ((ans)->size())->display() )); operation solve() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var ans : Sequence := Sequence{} ; var last : double := n - 1 ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = '1' then ( while (last->compareTo(i)) > 0 do ( if s[last+1] = '0' then ( execute ((i + 1) : ans) ; execute ((last + 1) : ans) ; last := last - 1 ; break ) else skip ; last := last - 1) ) else skip) ; return ans->sort(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def areCharactersUnique(s): checker=0 for i in range(len(s)): val=ord(s[i])-ord('a') if(checker &(1<0 : return False checker |=(1<display() ) else ( execute ("No")->display() ); operation areCharactersUnique(s : OclAny) : OclAny pre: true post: true activity: var checker : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( var val : double := (s[i+1])->char2byte() - ('a')->char2byte() ; if (MathLib.bitwiseAnd(checker, (1 * (2->pow(val))))) > 0 then ( return false ) else skip ; checker := checker or (1 * (2->pow(val)))) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(a,n): for i in range(n): if(a[i]): return True return False if __name__=='__main__' : a=[0,1,0,1] n=len(a) if(check(a,n)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 1 }))) ; n := (a)->size() ; if (check(a, n)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; operation check(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if (a[i+1]) then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(a,n): if n % 2==1 : return False for i in range(n//2): if a[i]!=a[i+(n//2)]: return False return True if __name__=="__main__" : a=[1,4,1,4] n=len(a) if check(a,n): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{1}->union(Sequence{4}->union(Sequence{1}->union(Sequence{ 4 }))) ; n := (a)->size() ; if check(a, n) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; operation check(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: if n mod 2 = 1 then ( return false ) else skip ; for i : Integer.subrange(0, n div 2-1) do ( if a[i+1] /= a[i + (n div 2)+1] then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b=map(int,input().split()) i=0 while True : if a<=0 or b<=0 : break if a>b : i+=a//b a-=a//b*b else : i+=b//a b-=b//a*a print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var i : int := 0 ; while true do ( if a <= 0 or b <= 0 then ( break ) else skip ; if (a->compareTo(b)) > 0 then ( i := i + a div b ; a := a - a div b * b ) else ( i := i + b div a ; b := b - b div a * a )) ; execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import product for _ in range(int(input())): input(); arr=list(map(int,input().split(' '))); arr.reverse(); num=arr[0]; ans=0 for i in arr : num=min(i,num); ans+=(i>num) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( input(); var arr : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )); arr := arr->reverse(); var num : OclAny := arr->first(); var ans : int := 0 ; for i : arr do ( num := Set{i, num}->min(); ans := ans + ((i->compareTo(num)) > 0)) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin n=int(stdin.readline()) a=int(stdin.readline()) b=int(stdin.readline()) for x in range(n+1): rem=n-a*x if rem>=0 and rem % b==0 : y=rem//b print("YES") print(x,y) sys.exit() print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + ((stdin.readLine())))->toInteger() ; var a : int := ("" + ((stdin.readLine())))->toInteger() ; var b : int := ("" + ((stdin.readLine())))->toInteger() ; for x : Integer.subrange(0, n + 1-1) do ( var rem : double := n - a * x ; if rem >= 0 & rem mod b = 0 then ( var y : int := rem div b ; execute ("YES")->display() ; execute (x)->display() ; sys.exit() ) else skip) ; execute ("NO")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def stringLen(str): m=dict() m[0]=-1 count_0=0 count_1=0 res=0 for i in range(len(str)): if str[i]=='0' : count_0+=1 else : count_1+=1 if m.get(count_1-count_0): res=max(res,i-m[count_1-count_0]) else : m[count_1-count_0]=i return res str="101001000" print("Length of longest balanced" " sub string=",stringLen(str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclType["String"] := "101001000" ; execute ((atom "Length of longest balanced" " sub string="))->display(); operation stringLen(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var m : Map := (arguments ( )) ; m->first() := -1 ; var count_0 : int := 0 ; var count var m : Map := (arguments ( )) : int := 0 ; var res : int := 0 ; for i : Integer.subrange(0, (OclType["String"])->size()-1) do ( if ("" + ([i+1])) = '0' then ( count_0 := count_0 + 1 ) else ( count var m : Map := (arguments ( )) := count var m : Map := (arguments ( )) + 1 ) ; if m.get(count if ("" + ([i+1])) = '0' then ( count_0 := count_0 + 1 ) else ( count var m : Map := (arguments ( )) := count var m : Map := (arguments ( )) + 1 ) - count_0) then ( res := Set{res, i - m[countres - count_0+1]}->max() ) else ( m[count if ("" + ([i+1])) = '0' then ( count_0 := count_0 + 1 ) else ( count var m : Map := (arguments ( )) := count var m : Map := (arguments ( )) + 1 ) - count_0+1] := i )) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k,n=input(),int(input()) l=list(map(int,input().split())) print(sum([i*(l[ord(k[i-1])-97])if i<=len(k)else max(l)*i for i in range(1,len(k)+n+1)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : OclAny := null; var n : OclAny := null; Sequence{k,n} := Sequence{(OclFile["System.in"]).readLine(),("" + (((OclFile["System.in"]).readLine())))->toInteger()} ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((Integer.subrange(1, (k)->size() + n + 1-1)->select(i | true)->collect(i | (if (i->compareTo((k)->size())) <= 0 then i * (l[(k[i - 1+1])->char2byte() - 97+1]) else (l)->max() * i endif)))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() k=int(input()) d=list(map(int,input().split())) ans=0 for i in range(len(s)): ans+=(i+1)*d[ord(s[i])-ord('a')] maxi=max(d) for i in range(k): ans+=(i+len(s)+1)*maxi print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( ans := ans + (i + 1) * d[(s[i+1])->char2byte() - ('a')->char2byte()+1]) ; var maxi : OclAny := (d)->max() ; for i : Integer.subrange(0, k-1) do ( ans := ans + (i + (s)->size() + 1) * maxi) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): s=input() k=int(input()) abc=list(map(int,input().split())) sum1=0 for i in range(len(s)): sum1+=abc[ord(s[i])-97]*(i+1) sum2=0 for i in range(k): sum2+=len(s)+i+1 print(sum1+sum2*max(abc)) for _ in range(1): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, 1-1) do ( solve()); operation solve() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var abc : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sum1 : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( sum1 := sum1 + abc[(s[i+1])->char2byte() - 97+1] * (i + 1)) ; var sum2 : int := 0 ; for i : Integer.subrange(0, k-1) do ( sum2 := sum2 + (s)->size() + i + 1) ; execute (sum1 + sum2 * (abc)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- alpha=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] x=input() l=" ".join(x) t=l.split() n=int(input()) k=[int(i)for i in input().split()] L=[] for i in range(len(t)): s=alpha.index(t[i]) L.append(s) c=0 for x in range(len(L)): c+=(x+1)*(k[L[x]]) p=0 for z in range(1,n+1): p+=(len(t)+z)*(max(k)) print(p+c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var alpha : Sequence := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{'c'}->union(Sequence{'d'}->union(Sequence{'e'}->union(Sequence{'f'}->union(Sequence{'g'}->union(Sequence{'h'}->union(Sequence{'i'}->union(Sequence{'j'}->union(Sequence{'k'}->union(Sequence{'l'}->union(Sequence{'m'}->union(Sequence{'n'}->union(Sequence{'o'}->union(Sequence{'p'}->union(Sequence{'q'}->union(Sequence{'r'}->union(Sequence{'s'}->union(Sequence{'t'}->union(Sequence{'u'}->union(Sequence{'v'}->union(Sequence{'w'}->union(Sequence{'x'}->union(Sequence{'y'}->union(Sequence{ 'z' }))))))))))))))))))))))))) ; var x : String := (OclFile["System.in"]).readLine() ; var l : String := StringLib.sumStringsWithSeparator((x), " ") ; var t : OclAny := l.split() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var L : Sequence := Sequence{} ; for i : Integer.subrange(0, (t)->size()-1) do ( var s : int := alpha->indexOf(t[i+1]) - 1 ; execute ((s) : L)) ; var c : int := 0 ; for x : Integer.subrange(0, (L)->size()-1) do ( c := c + (x + 1) * (k[L->at(x)+1])) ; var p : int := 0 ; for z : Integer.subrange(1, n + 1-1) do ( p := p + ((t)->size() + z) * ((k)->max())) ; execute (p + c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() k=int(input()) w=list(map(int,input().split())) maxW=w[0] maxS="a" for j in range(1,26): if maxWtoInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var maxW : OclAny := w->first() ; var maxS : String := "a" ; for j : Integer.subrange(1, 26-1) do ( if (maxW->compareTo(w[j+1])) < 0 then ( maxW := w[j+1] ; maxS := (97 + j)->byte2char() ) else skip) ; s := s + StringLib.nCopies(maxS, k) ; var res : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( res := res + (i + 1) * w[(s[i+1])->char2byte() - ("a")->char2byte()+1]) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() res=[] for d in reversed(n): d=int(d) s=("-O" if d>=5 else "O-")+"|"+"O"*(d % 5)+"-"+"O"*(4-d % 5) res.append(s) res="\n".join(res) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var res : Sequence := Sequence{} ; for d : (n)->reverse() do ( var d : int := ("" + ((d)))->toInteger() ; var s : String := (if d >= 5 then "-O" else "O-" endif) + "|" + StringLib.nCopies("O", (d mod 5)) + "-" + StringLib.nCopies("O", (4 - d mod 5)) ; execute ((s) : res)) ; res := StringLib.sumStringsWithSeparator((res), "\n") ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if(n==0): print('O-|-OOOO') while(n!=0): r=n % 10 n=int(n/10) if(r==1): print('O-|O-OOO') elif(r==2): print('O-|OO-OO') elif(r==3): print('O-|OOO-O') elif(r==4): print('O-|OOOO-') elif(r==5): print('-O|-OOOO') elif(r==6): print('-O|O-OOO') elif(r==7): print('-O|OO-OO') elif(r==8): print('-O|OOO-O') elif(r==9): print('-O|OOOO-') else : print('O-|-OOOO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n = 0) then ( execute ('O-|-OOOO')->display() ) else skip ; while (n /= 0) do ( var r : int := n mod 10 ; n := ("" + ((n / 10)))->toInteger() ; if (r = 1) then ( execute ('O-|O-OOO')->display() ) else (if (r = 2) then ( execute ('O-|OO-OO')->display() ) else (if (r = 3) then ( execute ('O-|OOO-O')->display() ) else (if (r = 4) then ( execute ('O-|OOOO-')->display() ) else (if (r = 5) then ( execute ('-O|-OOOO')->display() ) else (if (r = 6) then ( execute ('-O|O-OOO')->display() ) else (if (r = 7) then ( execute ('-O|OO-OO')->display() ) else (if (r = 8) then ( execute ('-O|OOO-O')->display() ) else (if (r = 9) then ( execute ('-O|OOOO-')->display() ) else ( execute ('O-|-OOOO')->display() ) ) ) ) ) ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() for digit in n[: :-1]: digit_int=int(digit) soroban="" if digit_int<5 : soroban+="O-|" else : soroban+="-O|" if digit_int % 5==0 : soroban+="-OOOO" elif digit_int % 5==1 : soroban+="O-OOO" elif digit_int % 5==2 : soroban+="OO-OO" elif digit_int % 5==3 : soroban+="OOO-O" else : soroban+="OOOO-" print(soroban) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; for digit : n(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( var digit_int : int := ("" + ((digit)))->toInteger() ; var soroban : String := "" ; if digit_int < 5 then ( soroban := soroban + "O-|" ) else ( soroban := soroban + "-O|" ) ; if digit_int mod 5 = 0 then ( soroban := soroban + "-OOOO" ) else (if digit_int mod 5 = 1 then ( soroban := soroban + "O-OOO" ) else (if digit_int mod 5 = 2 then ( soroban := soroban + "OO-OO" ) else (if digit_int mod 5 = 3 then ( soroban := soroban + "OOO-O" ) else ( soroban := soroban + "OOOO-" ) ) ) ) ; execute (soroban)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while(t>0): n=int(input()) li=[int(x)for x in input().split()] m=li[-1] c=0 for i in range(len(li)-2,-1,-1): if(li[i]>m): c=c+1 m=min(m,li[i]) print(c) t=t-1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (t > 0) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var m : OclAny := li->last() ; var c : int := 0 ; for i : Integer.subrange(-1 + 1, (li)->size() - 2)->reverse() do ( if ((li[i+1]->compareTo(m)) > 0) then ( c := c + 1 ) else skip ; m := Set{m, li[i+1]}->min()) ; execute (c)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import heapq import sys import math import itertools import bisect from io import BytesIO,IOBase import os def valid(i,j,n,m): if i=0 and j>=0 and j=5 : s+='-O|' s+='O'*(tmp-5)+'-' s+='O'*(5-(tmp-5)-1) else : s+='O-|' s+='O'*(tmp)+'-' s+='O'*(5-(tmp)-1) print(s) if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation valid(i : OclAny, j : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: if (i->compareTo(n)) < 0 & i >= 0 & j >= 0 & (j->compareTo(m)) < 0 then ( return true ) else skip ; return false; operation sumn(i : OclAny, n : OclAny) : OclAny pre: true post: true activity: return (n - i) * (i + n) / 2; operation sqfun(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: return (-b + (b * b - 4 * a * c)->sqrt()) / 2 * a; operation getprime(num : OclAny) : OclAny pre: true post: true activity: if ((argument (test (logical_test (comparison (comparison (expr (expr (atom (name num))) % (expr (atom (name i))))) != (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name math)) (trailer . (name sqrt) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) ))))))))) )))) + (expr (atom (number (integer 1)))))))))) )))))))))->forAll( _x | _x = true ) then ( return true ) else skip; operation value() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation values() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inlsts() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inps() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation instr() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation stlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (i)); operation solve() pre: true post: true activity: n := inp() ; for i : OclType["String"](n)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( var tmp : int := ("" + ((i)))->toInteger() ; var s : String := '' ; if tmp >= 5 then ( s := s + '-O|' ; s := s + StringLib.nCopies('O', (tmp - 5)) + '-' ; s := s + StringLib.nCopies('O', (5 - (tmp - 5) - 1)) ) else ( s := s + 'O-|' ; s := s + StringLib.nCopies('O', (tmp)) + '-' ; s := s + StringLib.nCopies('O', (5 - (tmp) - 1)) ) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def gcd(a,b): if b==0 : return 1,0,a x,y,d=gcd(b,a % b) return y,x-y*(a//b),d def solve(): c=int(input()) a=int(input()) b=int(input()) coef_a,coef_b,d=gcd(a,b) if c % d : print("NO") return coef_a*=c//d coef_b*=c//d if coef_a<0 : k=(-coef_a*d+b-1)//b coef_a+=k*b//d coef_b-=k*a//d if coef_b<0 : k=(-coef_b*d+a-1)//a coef_b+=k*a//d coef_a-=k*b//d if min(coef_a,coef_b)<0 : print("NO") else : print(f"YES\n{coef_a}{coef_b}") if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if b = 0 then ( return 1, 0, a ) else skip ; var x : OclAny := null; var y : OclAny := null; var d : OclAny := null; Sequence{x,y,d} := gcd(b, a mod b) ; return y, x - y * (a div b), d; operation solve() pre: true post: true activity: var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; b := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var coef_a : OclAny := null; var coef_b : OclAny := null; var d : OclAny := null; Sequence{coef_a,coef_b,d} := gcd(a, b) ; if c mod d then ( execute ("NO")->display() ; return ) else skip ; coef_a := coef_a * c div d ; coef_b := coef_b * c div d ; if coef_a < 0 then ( var k : int := (-coef_a * d + b - 1) div b ; coef_a := coef_a + k * b div d ; coef_b := coef_b - k * a div d ) else skip ; if coef_b < 0 then ( k := (-coef_b * d + a - 1) div a ; coef_b := coef_b + k * a div d ; coef_a := coef_a - k * b div d ) else skip ; if Set{coef_a, coef_b}->min() < 0 then ( execute ("NO")->display() ) else ( execute (StringLib.formattedString("YES\n{coef_a}{coef_b}"))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import heapq import sys import math import itertools import bisect from io import BytesIO,IOBase import os def valid(i,j,n,m): if i=0 and j>=0 and j=5 : s+='-O|' s+='O'*(tmp-5)+'-' s+='O'*(5-(tmp-5)-1) else : s+='O-|' s+='O'*(tmp)+'-' s+='O'*(5-(tmp)-1) print(s) if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation valid(i : OclAny, j : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: if (i->compareTo(n)) < 0 & i >= 0 & j >= 0 & (j->compareTo(m)) < 0 then ( return true ) else skip ; return false; operation sumn(i : OclAny, n : OclAny) : OclAny pre: true post: true activity: return (n - i) * (i + n) / 2; operation sqfun(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: return (-b + (b * b - 4 * a * c)->sqrt()) / 2 * a; operation getprime(num : OclAny) : OclAny pre: true post: true activity: if ((argument (test (logical_test (comparison (comparison (expr (expr (atom (name num))) % (expr (atom (name i))))) != (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name math)) (trailer . (name sqrt) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) ))))))))) )))) + (expr (atom (number (integer 1)))))))))) )))))))))->forAll( _x | _x = true ) then ( return true ) else skip; operation value() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation values() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inlsts() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inps() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation instr() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation stlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (i)); operation solve() pre: true post: true activity: n := inp() ; for i : OclType["String"](n)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( var tmp : int := ("" + ((i)))->toInteger() ; var s : String := '' ; if tmp >= 5 then ( s := s + '-O|' ; s := s + StringLib.nCopies('O', (tmp - 5)) + '-' ; s := s + StringLib.nCopies('O', (5 - (tmp - 5) - 1)) ) else ( s := s + 'O-|' ; s := s + StringLib.nCopies('O', (tmp)) + '-' ; s := s + StringLib.nCopies('O', (5 - (tmp) - 1)) ) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minimumRemoval(n,a): c=dict.fromkeys(a,0); for i in range(n): c[a[i]]+=1 ; ans=0 ; for i in range(n): ok=False ; for j in range(31): x=(1<1 or(c[x]==1 and x!=a[i]))): ok=True ; break ; if(not ok): ans+=1 ; return ans ; if __name__=="__main__" : a=[4,7,1,5,4,9]; n=len(a); print(minimumRemoval(n,a)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{4}->union(Sequence{7}->union(Sequence{1}->union(Sequence{5}->union(Sequence{4}->union(Sequence{ 9 }))))); ; n := (a)->size(); ; execute (minimumRemoval(n, a))->display(); ) else skip; operation minimumRemoval(n : OclAny, a : OclAny) pre: true post: true activity: var c : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))); ; for i : Integer.subrange(0, n-1) do ( c[a[i+1]+1] := c[a[i+1]+1] + 1;) ; var ans : int := 0; ; for i : Integer.subrange(0, n-1) do ( var ok : boolean := false; ; for j : Integer.subrange(0, 31-1) do ( var x : double := (1 * (2->pow(j))) - a[i+1]; ; if ((c)->includes(x) & (c[x+1] > 1 or (c[x+1] = 1 & x /= a[i+1]))) then ( ok := true; ; break; ) else skip) ; if (not(ok)) then ( ans := ans + 1; ) else skip) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=10 y=5 x=x ^ y ; y=x ^ y ; x=x ^ y ; print("After Swapping: x=",x," y=",y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 10 ; var y : int := 5 ; x := MathLib.bitwiseXor(x, y); ; y := MathLib.bitwiseXor(x, y); ; x := MathLib.bitwiseXor(x, y); ; execute ("After Swapping: x=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findExtraCharcter(strA,strB): res=0 for i in range(0,len(strA)): res=res ^(ord)(strA[i]) for i in range(0,len(strB)): res=res ^(ord)(strB[i]) return((chr)(res)); strA="abcd" strB="cbdad" print(findExtraCharcter(strA,strB)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; strA := "abcd" ; strB := "cbdad" ; execute (findExtraCharcter(strA, strB))->display(); operation findExtraCharcter(strA : OclAny, strB : OclAny) pre: true post: true activity: var res : int := 0 ; for i : Integer.subrange(0, (strA)->size()-1) do ( res := MathLib.bitwiseXor(res, (ord)(strA[i+1]))) ; for i : Integer.subrange(0, (strB)->size()-1) do ( res := MathLib.bitwiseXor(res, (ord)(strB[i+1]))) ; return ((chr)(res));; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if not n : break a=[list(map(int,input().split()))for _ in range(n)] s=max(min(a[i])for i in range(n)) c=[max(a[i][j]for i in range(n))for j in range(n)] for j in range(n): if c[j]==s : print(s) break else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(n) then ( break ) else skip ; var a : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var s : OclAny := ((argument (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->max() ; var c : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (((argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->max())) ; (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) == (comparison (expr (atom (name s))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def get_min_value_in_row(data): if(len(data)<1): return 0 min=0 for i in range(0,len(data)): if(data[i]max): max=data[i][Min] for i in range(index,len(data)): if(data[i][Min]>max): max=data[i][Min] return True if max==data[index][Min]else False def print_both(data): for i in range(0,len(data)): indexmin=get_min_value_in_row(data[i]) if(is_max(indexmin,i,data)==True): print(data[i][indexmin]) return print(0) l=[] for i in sys.stdin : l.append(i) i=0 while(icompareTo((l)->size())) < 0) do ( if ((l[i+1])->size() = 2) then ( var Matrix : Sequence := Sequence{} ; for j : Integer.subrange(i + 1, ("" + ((l[i+1])))->toInteger() + i + 1-1) do ( var temp : Sequence := Sequence{ l[j+1].split() } ; for k : Integer.subrange(0, (temp->first())->size()-1) do ( temp->first()[k+1] := ("" + ((temp->first()[k+1])))->toInteger()) ; execute ((temp->first()) : Matrix)) ; i := i + ("" + ((l[i+1])))->toInteger() + 1 ; print_both(Matrix) ) else ( i := i + 1 )); operation get_min_value_in_row(data : OclAny) : OclAny pre: true post: true activity: if ((data)->size() < 1) then ( return 0 ) else skip ; var min : int := 0 ; for i : Integer.subrange(0, (data)->size()-1) do ( if ((data[i+1]->compareTo(data[min+1])) < 0) then ( min := i ) else skip) ; return min; operation is_max(Min : OclAny, index : OclAny, data : OclAny) : OclAny pre: true post: true activity: var max : OclAny := data[index+1][Min+1] ; for i : Integer.subrange(-1 + 1, index)->reverse() do ( if ((data[i+1][Min+1]->compareTo(max)) > 0) then ( max := data[i+1][Min+1] ) else skip) ; for i : Integer.subrange(index, (data)->size()-1) do ( if ((data[i+1][Min+1]->compareTo(max)) > 0) then ( max := data[i+1][Min+1] ) else skip) ; return if max = data[index+1][Min+1] then true else false endif; operation print_both(data : OclAny) pre: true post: true activity: for i : Integer.subrange(0, (data)->size()-1) do ( var indexmin : OclAny := get_min_value_in_row(data[i+1]) ; if (is_max(indexmin, i, data) = true) then ( execute (data[i+1][indexmin+1])->display() ; return ) else skip) ; execute (0)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : N=int(input()) if N==0 : break S=[list(map(int,input().split()))for i in range(N)] B={max(S[i][j]for i in range(N))for j in range(N)}&{min(S[i][j]for j in range(N))for i in range(N)} if B : e,=B print(e) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var S : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var B : int := MathLib.bitwiseAnd(Integer.subrange(0, N-1)->select(j | true)->collect(j | ((argument (test (logical_test (comparison (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))))->max())->asSet(), Integer.subrange(0, N-1)->select(i | true)->collect(i | ((argument (test (logical_test (comparison (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))))->min())->asSet()) ; if B then ( (testlist_star_expr (test (logical_test (comparison (expr (atom (name e)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name e)))))) ,)} := B ; execute (e)->display() ) else ( execute (0)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys while True : n=int(sys.stdin.readline().rstrip()) if n==0 : break ; students=[] for i in range(n): students.append(list(map(int,sys.stdin.readline().rstrip().split(' ')))) s_list=[[min(row)==s for s in row]for row in students] t_list=[[max(col)==s for s in col]for col in zip(*students)] ret=[0] for i,data in enumerate(zip(s_list,zip(*t_list))): for j,d in enumerate(zip(*data)): if all(d): ret.append(students[i][j]) print(max(ret)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : int := ("" + ((sys.stdin.readLine().rstrip())))->toInteger() ; if n = 0 then ( break; ) else skip ; var students : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((((sys.stdin.readLine().rstrip().split(' '))->collect( _x | (OclType["int"])->apply(_x) ))) : students)) ; var s_list : Sequence := students->select(row | true)->collect(row | (row->select(s | true)->collect(s | ((row)->min() = s)))) ; var t_list : Sequence := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name students)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name students)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name students)))))))`third->at(_indx)} )->select(col | true)->collect(col | (col->select(s | true)->collect(s | ((col)->max() = s)))) ; var ret : Sequence := Sequence{ 0 } ; for _tuple : Integer.subrange(1, (Integer.subrange(1, s_list->size())->collect( _indx | Sequence{s_list->at(_indx), Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name t_list)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name t_list)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name t_list)))))))`third->at(_indx)} )->at(_indx)} ))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(1, s_list->size())->collect( _indx | Sequence{s_list->at(_indx), Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name t_list)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name t_list)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name t_list)))))))`third->at(_indx)} )->at(_indx)} ))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var data : OclAny := _tuple->at(_indx); for _tuple : Integer.subrange(1, (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name data)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name data)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name data)))))))`third->at(_indx)} ))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name data)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name data)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name data)))))))`third->at(_indx)} ))->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); if (d)->forAll( _x | _x = true ) then ( execute ((students[i+1][j+1]) : ret) ) else skip)) ; execute ((ret)->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bad_price(): t=int(input()) for i in range(t): n=int(input()) a=list(map(int,input().split())) minimum=a[n-1] counter=0 for s in range(n-2,-1,-1): if a[s]>minimum : counter+=1 minimum=min([a[s],minimum]) print(counter) bad_price() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; bad_price(); operation bad_price() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var minimum : OclAny := a[n - 1+1] ; var counter : int := 0 ; for s : Integer.subrange(-1 + 1, n - 2)->reverse() do ( if (a[s+1]->compareTo(minimum)) > 0 then ( counter := counter + 1 ) else skip ; minimum := (Sequence{a[s+1]}->union(Sequence{ minimum }))->min()) ; execute (counter)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline while True : n=int(input()) if n==0 : break a=[list(map(int,input().split()))for r in range(n)] b=[[0 for c in range(n)]for r in range(n)] for r in range(n): mi=min(a[r]) for c in range(n): if a[r][c]==mi : b[r][c]|=1 for c in range(n): ma=max([a[r][c]for r in range(n)]) for r in range(n): if a[r][c]==ma : b[r][c]|=2 ans=0 for r in range(n): for c in range(n): if b[r][c]==3 : ans=a[r][c] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var a : Sequence := Integer.subrange(0, n-1)->select(r | true)->collect(r | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var b : Sequence := Integer.subrange(0, n-1)->select(r | true)->collect(r | (Integer.subrange(0, n-1)->select(c | true)->collect(c | (0)))) ; for r : Integer.subrange(0, n-1) do ( var mi : OclAny := (a[r+1])->min() ; for c : Integer.subrange(0, n-1) do ( if a[r+1][c+1] = mi then ( b[r+1][c+1] := b[r+1][c+1] or 1 ) else skip)) ; for c : Integer.subrange(0, n-1) do ( var ma : OclAny := (Integer.subrange(0, n-1)->select(r | true)->collect(r | (a[r+1][c+1])))->max() ; for r : Integer.subrange(0, n-1) do ( if a[r+1][c+1] = ma then ( b[r+1][c+1] := b[r+1][c+1] or 2 ) else skip)) ; var ans : int := 0 ; for r : Integer.subrange(0, n-1) do ( for c : Integer.subrange(0, n-1) do ( if b[r+1][c+1] = 3 then ( ans := a[r+1][c+1] ) else skip)) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countCoins(n): c=0 if(n<10): return n if(n>9 and n<25): c=n//10+n % 10 return c if(n>24): c=n//25 if(n % 25<10): c=c+n % 25 return c if(n % 25>9): c=(c+(n % 25)//10+(n % 25)% 10) return c n=14 print(countCoins(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 14 ; execute (countCoins(n))->display(); operation countCoins(n : OclAny) : OclAny pre: true post: true activity: var c : int := 0 ; if (n < 10) then ( return n ) else skip ; if (n > 9 & n < 25) then ( c := n div 10 + n mod 10 ; return c ) else skip ; if (n > 24) then ( c := n div 25 ; if (n mod 25 < 10) then ( c := c + n mod 25 ; return c ) else skip ; if (n mod 25 > 9) then ( c := (c + (n mod 25) div 10 + (n mod 25) mod 10) ; return c ) else skip ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys def _input(): return map(int,input().split()) n=int(input()) lst=list(_input()) m=min(lst); l=[] for i in range(n): if lst[i]==m : l.append(i) res=sys.maxsize for i in range(1,len(l)): res=min(res,l[i]-l[i-1]) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := (_input()) ; var m : OclAny := (lst)->min(); var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if lst[i+1] = m then ( execute ((i) : l) ) else skip) ; var res : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; for i : Integer.subrange(1, (l)->size()-1) do ( res := Set{res, l[i+1] - l[i - 1+1]}->min()) ; execute (res)->display(); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict n=int(input()) u,v=defaultdict(int),defaultdict(int) for i in range(n): a,b=map(int,input().split()) u[a]+=1 if b!=a : v[b]+=1 k=(n-1)//2 s=any(v[b]>k for b in v) t=[u[a]for a in u if u[a]+v[a]>k] if t : print(max(0,k+1-max(t))) else : print(k+1 if s else-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := Sequence{defaultdict(OclType["int"]),defaultdict(OclType["int"])} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; u[a+1] := u[a+1] + 1 ; if b /= a then ( v[b+1] := v[b+1] + 1 ) else skip) ; var k : int := (n - 1) div 2 ; var s : boolean := ((argument (test (logical_test (comparison (comparison (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])))) > (comparison (expr (atom (name k))))))) (comp_for for (exprlist (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name v))))))))->exists( _x | _x = true ) ; var t : Sequence := u->select(a | (u[a+1] + v[a+1]->compareTo(k)) > 0)->collect(a | (u[a+1])) ; if t then ( execute (Set{0, k + 1 - (t)->max()}->max())->display() ) else ( execute (if s then k + 1 else -1 endif)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()); q=(n+1)//2 ; m=q*2 ; f=1 d=dict() for i in range(n): x,y=map(int,input().split()) if x not in d : d[x]=[0,0] d[x][0]+=1 if x!=y : if y not in d : d[y]=[0,0] d[y][1]+=1 if d[x][0]>=q or d[y][0]>=q : print(0); f=0 break if sum(d[x])>=q : m=min(m,q-d[x][0]) if sum(d[y])>=q : m=min(m,q-d[y][0]) if f : print(['%d' % m,'-1'][m==q*2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var q : int := (n + 1) div 2; var m : int := q * 2; var f : int := 1 ; var d : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (d)->excludes(x) then ( d[x+1] := Sequence{0}->union(Sequence{ 0 }) ) else skip ; d[x+1]->first() := d[x+1]->first() + 1 ; if x /= y then ( if (d)->excludes(y) then ( d[y+1] := Sequence{0}->union(Sequence{ 0 }) ) else skip ; d[y+1][1+1] := d[y+1][1+1] + 1 ) else skip ; if (d[x+1]->first()->compareTo(q)) >= 0 or (d[y+1]->first()->compareTo(q)) >= 0 then ( execute (0)->display(); f := 0 ; break ) else skip ; if ((d[x+1])->sum()->compareTo(q)) >= 0 then ( m := Set{m, q - d[x+1]->first()}->min() ) else skip ; if ((d[y+1])->sum()->compareTo(q)) >= 0 then ( m := Set{m, q - d[y+1]->first()}->min() ) else skip) ; if f then ( execute (Sequence{StringLib.format('%d',m)}->union(Sequence{ '-1' })->select(m = q * 2))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict from math import ceil d=defaultdict(list) n=int(input()) for i in range(n): a,b=map(int,input().split()) if a==b : if a in d : d[a][0]+=1 else : d[a]=[1,0] else : if a in d : d[a][0]+=1 else : d[a]=[1,0] if b in d : d[b][1]+=1 else : d[b]=[0,1] m=ceil(n/2) mini=1e6 for i in d : a=d[i][0] b=d[i][1] if a+b>=m : if a>=m : mini=min(0,mini) else : mini=min(m-a,mini) if mini==1e6 : print(-1) else : print(mini) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var d : OclAny := defaultdict(OclType["Sequence"]) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = b then ( if (d)->includes(a) then ( d[a+1]->first() := d[a+1]->first() + 1 ) else ( d[a+1] := Sequence{1}->union(Sequence{ 0 }) ) ) else ( if (d)->includes(a) then ( d[a+1]->first() := d[a+1]->first() + 1 ) else ( d[a+1] := Sequence{1}->union(Sequence{ 0 }) ) ; if (d)->includes(b) then ( d[b+1][1+1] := d[b+1][1+1] + 1 ) else ( d[b+1] := Sequence{0}->union(Sequence{ 1 }) ) )) ; var m : OclAny := ceil(n / 2) ; var mini : double := ("1e6")->toReal() ; for i : d do ( var a : OclAny := d[i+1]->first() ; var b : OclAny := d[i+1][1+1] ; if (a + b->compareTo(m)) >= 0 then ( if (a->compareTo(m)) >= 0 then ( mini := Set{0, mini}->min() ) else ( mini := Set{m - a, mini}->min() ) ) else skip) ; if mini = ("1e6")->toReal() then ( execute (-1)->display() ) else ( execute (mini)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil n=int(input()) front=[] back=[] dfront={} dback={} for i in range(n): a,b=map(int,input().split()) front.append(a) back.append(b) for i in range(n): if front[i]==back[i]: if front[i]in dfront : dfront[front[i]]+=1 else : dfront[front[i]]=1 else : if front[i]in dfront : dfront[front[i]]+=1 else : dfront[front[i]]=1 if back[i]in dback : dback[back[i]]+=1 else : dback[back[i]]=1 m=10**10 f=0 for i in dfront : if dfront[i]>=ceil(n/2): f=1 break else : temp=ceil(n/2)-dfront[i] if i in dback : if dback[i]>=temp : m=min(m,temp) if f==1 : print(0) else : g=1 for i in dback : if i not in dfront and dback[i]>=ceil(n/2): g=0 m=min(m,ceil(n/2)) if m==10**10 : print(-1) else : print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var front : Sequence := Sequence{} ; var back : Sequence := Sequence{} ; var dfront : OclAny := Set{} ; var dback : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a) : front) ; execute ((b) : back)) ; for i : Integer.subrange(0, n-1) do ( if front[i+1] = back[i+1] then ( if (dfront)->includes(front[i+1]) then ( dfront[front[i+1]+1] := dfront[front[i+1]+1] + 1 ) else ( dfront[front[i+1]+1] := 1 ) ) else ( if (dfront)->includes(front[i+1]) then ( dfront[front[i+1]+1] := dfront[front[i+1]+1] + 1 ) else ( dfront[front[i+1]+1] := 1 ) ; if (dback)->includes(back[i+1]) then ( dback[back[i+1]+1] := dback[back[i+1]+1] + 1 ) else ( dback[back[i+1]+1] := 1 ) )) ; var m : double := (10)->pow(10) ; var f : int := 0 ; for i : dfront do ( if (dfront[i+1]->compareTo(ceil(n / 2))) >= 0 then ( f := 1 ; break ) else ( var temp : double := ceil(n / 2) - dfront[i+1] ; if (dback)->includes(i) then ( if (dback[i+1]->compareTo(temp)) >= 0 then ( m := Set{m, temp}->min() ) else skip ) else skip )) ; if f = 1 then ( execute (0)->display() ) else ( var g : int := 1 ; for i : dback do ( if (dfront)->excludes(i) & (dback[i+1]->compareTo(ceil(n / 2))) >= 0 then ( g := 0 ; m := Set{m, ceil(n / 2)}->min() ) else skip) ; if m = (10)->pow(10) then ( execute (-1)->display() ) else ( execute (m)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def allOddDigits(n): while(n): if((n % 10)% 2==0): return False n=int(n/10) return True def largestNumber(n): if(n % 2==0): n-=1 i=n while(1): if(allOddDigits(i)): return i i-=2 if __name__=='__main__' : N=23 print(largestNumber(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var N : int := 23 ; execute (largestNumber(N))->display() ) else skip; operation allOddDigits(n : OclAny) : OclAny pre: true post: true activity: while (n) do ( if ((n mod 10) mod 2 = 0) then ( return false ) else skip ; n := ("" + ((n / 10)))->toInteger()) ; return true; operation largestNumber(n : OclAny) : OclAny pre: true post: true activity: if (n mod 2 = 0) then ( n := n - 1 ) else skip ; var i : OclAny := n ; while (1) do ( if (allOddDigits(i)) then ( return i ) else skip ; i := i - 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().rstrip() T=int(input()) for _ in range(T): N,K=map(int,input().split()) X=[] for _ in range(N): x,y=map(int,input().split()) X.append((x,y)) for i,(x,y)in enumerate(X): for j,(x2,y2)in enumerate(X): if abs(x-x2)+abs(y-y2)>K : break else : print(1) break else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, T-1) do ( var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var X : Sequence := Sequence{} ; for _anon : Integer.subrange(0, N-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{x, y}) : X)) ; (compound_stmt for (exprlist (expr (atom (name i))) , (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name x)))))) , (test (logical_test (comparison (expr (atom (name y))))))) )))) in (testlist (test (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name X)))))))) )))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name j))) , (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name x2)))))) , (test (logical_test (comparison (expr (atom (name y2))))))) )))) in (testlist (test (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name X)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (name x2))))))))) )))) + (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (name y2))))))))) )))))) > (comparison (expr (atom (name K))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n,k=map(int,input().split()) w=[list(map(int,input().split()))for _ in range(n)] for i in range(n): if all(i==j or abs(w[i][0]-w[j][0])+abs(w[i][1]-w[j][1])<=k for j in range(n)): print(1) break else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name all)) (trailer (arguments ( (arglist (argument (test (logical_test (logical_test (comparison (comparison (expr (atom (name i)))) == (comparison (expr (atom (name j)))))) or (logical_test (comparison (comparison (expr (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) - (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))))) )))) + (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) - (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))))) )))))) <= (comparison (expr (atom (name k)))))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): LIMIT=10**8-1 ans=0 primes=eulerlib.list_primes(LIMIT//2) sqrt=eulerlib.sqrt(LIMIT) for(i,p)in enumerate(primes): if p>sqrt : break end=binary_search(primes,LIMIT//p) ans+=(end+1 if end>=0 else-end-1)-i return str(ans) def binary_search(lst,x): start=0 end=len(lst) while startlst[mid]: start=mid+1 elif x==lst[mid]: return mid else : raise AssertionError() return-start-1 if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LIMIT : double := (10)->pow(8) - 1 ; var ans : int := 0 ; var primes : OclAny := eulerlib.list_primes(LIMIT div 2) ; var sqrt : double := eulerlib.sqrt(LIMIT) ; for Sequence{i, p} : Integer.subrange(1, (primes)->size())->collect( _indx | Sequence{_indx-1, (primes)->at(_indx)} ) do ( if (p->compareTo(sqrt)) > 0 then ( break ) else skip ; var end : OclAny := binary_search(primes, LIMIT div p) ; ans := ans + (if end >= 0 then end + 1 else -end - 1 endif) - i) ; return ("" + ((ans))); operation binary_search(lst : OclAny, x : OclAny) : OclAny pre: true post: true activity: var start : int := 0 ; end := (lst)->size() ; while (start->compareTo(end)) < 0 do ( var mid : int := (start + end) div 2 ; if (x->compareTo(lst[mid+1])) < 0 then ( end := mid ) else (if (x->compareTo(lst[mid+1])) > 0 then ( start := mid + 1 ) else (if x = lst[mid+1] then ( return mid ) else ( error AssertionException.newAssertionException() ) ) ) ) ; return -start - 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for j in range(t): n,k=map(int,input().split()) a=[] r=-1 for i in range(n): x,y=map(int,input().split()) a.append([x,y]) for[x,y]in a : d=0 for[x1,y1]in a : if(abs(x1-x)+abs(y1-y))>k : d=-1 if d==0 : r=1 break print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{} ; var r : int := -1 ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{x}->union(Sequence{ y })) : a)) ; for Sequence{x}->union(Sequence{ y }) : a do ( var d : int := 0 ; for Sequence{x1}->union(Sequence{ y1 }) : a do ( if (((x1 - x)->abs() + (y1 - y)->abs())->compareTo(k)) > 0 then ( d := -1 ) else skip) ; if d = 0 then ( r := 1 ; break ) else skip) ; execute (r)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): r=input().split() n=int(r[0]) k=int(r[1]) x,y=[],[] for i in range(n): p=input().split() x.append(int(p[0])) y.append(int(p[1])) for i in range(len(x)): d=0 for j in range(len(x)): if i!=j and(abs(x[j]-x[i])+abs(y[j]-y[i])<=k): d+=1 if d==n-1 : break if d==n-1 : break if d==n-1 : print(1) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var r : OclAny := input().split() ; var n : int := ("" + ((r->first())))->toInteger() ; var k : int := ("" + ((r[1+1])))->toInteger() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{Sequence{},Sequence{}} ; for i : Integer.subrange(0, n-1) do ( var p : OclAny := input().split() ; execute ((("" + ((p->first())))->toInteger()) : x) ; execute ((("" + ((p[1+1])))->toInteger()) : y)) ; for i : Integer.subrange(0, (x)->size()-1) do ( var d : int := 0 ; for j : Integer.subrange(0, (x)->size()-1) do ( if i /= j & (((x[j+1] - x[i+1])->abs() + (y[j+1] - y[i+1])->abs()->compareTo(k)) <= 0) then ( d := d + 1 ) else skip ; if d = n - 1 then ( break ) else skip) ; if d = n - 1 then ( break ) else skip) ; if d = n - 1 then ( execute (1)->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) R=lambda :[*map(int,input().split())] exec(R()[0]*'n,k=R();a=[R()for _ in[0]*n];print(int(min(max(abs(x-u)+abs(y-v)for x,y in a)for u,v in a)<=k)or-1);') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (expr (expr (atom (name R)) (trailer (arguments ( ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) * (expr (atom 'n,k=R();a=[R()for _ in[0]*n];print(int(min(max(abs(x-u)+abs(y-v)for x,y in a)for u,v in a)<=k)or-1);'))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) A=list(map(int,input().split())) B=[] x=n f=0 m=min(A) for i in range(len(A)): if(A[i]==m): if(f==0): j=i f=1 else : x=min(x,i-j) j=i print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var B : Sequence := Sequence{} ; var x : int := n ; var f : int := 0 ; var m : OclAny := (A)->min() ; for i : Integer.subrange(0, (A)->size()-1) do ( if (A[i+1] = m) then ( if (f = 0) then ( var j : OclAny := i ; f := 1 ) else ( x := Set{x, i - j}->min() ; j := i ) ) else skip) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=[] res=0 for _ in range(n): temp=list(map(int,input().split())) a.append(temp) for i in range(n): for j in range(0,2*m,2): if a[i][j]==1 or a[i][j+1]==1 : res+=1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{} ; var res : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var temp : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((temp) : a)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, 2 * m-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( if a[i+1][j+1] = 1 or a[i+1][j + 1+1] = 1 then ( res := res + 1 ) else skip)) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=list(map(int,input().split())) cnt=0 for i in range(n): lst=list(map(int,input().split())) for j in range(0,2*m,2): if lst[j]==1 or lst[j+1]==1 : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, 2 * m-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( if lst[j+1] = 1 or lst[j + 1+1] = 1 then ( cnt := cnt + 1 ) else skip)) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) c=0 for i in range(n): a=list(map(int,input().split())) for j in range(0,len(a),2): l=a[j : j+2] if 1 in l : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, (a)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( var l : OclAny := a.subrange(j+1, j + 2) ; if (l)->includes(1) then ( c := c + 1 ) else skip)) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=(int(i)for i in input().split()) res=0 for _ in range(n): floor=[int(i)for i in input().split()] flats=[floor[2*i : 2*i+2]for i in range(m)] res+=sum(1 for f,s in flats if f+s>0) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var res : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var floor : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var flats : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (floor.subrange(2 * i+1, 2 * i + 2))) ; res := res + ((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name f))) , (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name flats))))) (comp_iter if (test (logical_test (comparison (comparison (expr (expr (atom (name f))) + (expr (atom (name s))))) > (comparison (expr (atom (number (integer 0))))))))))))->sum()) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) ans=0 for i in range(n): arr=list(map(int,input().split())) for j in range(k): if arr[j*2]or arr[j*2+1]: ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, k-1) do ( if arr[j * 2+1] or arr[j * 2 + 1+1] then ( ans := ans + 1 ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n,s=map(int,input().split()) if n==0 : break r=[0]*101 for _ in[0]*n : r[int(input())]+=1 a=0 for i in range(101): if i*2>s : a+=(r[i]**2-r[i])//2 a+=r[i]*sum(r[j]for j in range(max(i+1,s+1-i),101)) print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var r : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 101) ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, n) do ( r[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1] := r[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1] + 1) ; var a : int := 0 ; for i : Integer.subrange(0, 101-1) do ( if (i * 2->compareTo(s)) > 0 then ( a := a + ((r[i+1])->pow(2) - r[i+1]) div 2 ) else skip ; a := a + r[i+1] * ((argument (test (logical_test (comparison (expr (atom (name r)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (expr (atom (name s))) + (expr (atom (number (integer 1))))) - (expr (atom (name i))))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 101))))))))) )))))))))->sum()) ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- M=20 dp=[] d,K=None,None def count(pos,cnt,tight,nonz,num : list): if pos==len(num): if cnt==K : return 1 return 0 if dp[pos][cnt][tight][nonz]!=-1 : return dp[pos][cnt][tight][nonz] ans=0 limit=9 if tight else num[pos] for dig in range(limit+1): currCnt=cnt if dig==d : if d!=0 or not d and nonz : currCnt+=1 currTight=tight if digdisplay() ) else skip; operation count(pos : OclAny, cnt : OclAny, tight : OclAny, nonz : OclAny, num : Sequence(OclAny)) : OclAny pre: true post: true activity: if pos = (num)->size() then ( if cnt = K then ( return 1 ) else skip ; return 0 ) else skip ; if dp[pos+1][cnt+1][tight+1][nonz+1] /= -1 then ( return dp[pos+1][cnt+1][tight+1][nonz+1] ) else skip ; var ans : int := 0 ; var limit : int := if tight then 9 else num[pos+1] endif ; for dig : Integer.subrange(0, limit + 1-1) do ( var currCnt : OclAny := cnt ; if dig = d then ( if d /= 0 or not(d) & nonz then ( currCnt := currCnt + 1 ) else skip ) else skip ; var currTight : OclAny := tight ; if (dig->compareTo(num[pos+1])) < 0 then ( currTight := 1 ) else skip ; ans := ans + count(pos + 1, currCnt, currTight, (nonz or dig /= 0), num)) ; dp[pos+1][cnt+1][tight+1][nonz+1] := ans ; return dp[pos+1][cnt+1][tight+1][nonz+1]; operation solve(x : OclAny) : OclAny pre: true post: true activity: skip; skip; skip ; var num : Sequence := Sequence{} ; while x do ( execute ((x mod 10) : num) ; x := x div 10) ; num := num->reverse() ; dp := Integer.subrange(0, M-1)->select(k | true)->collect(k | (Integer.subrange(0, M-1)->select(j | true)->collect(j | (Integer.subrange(0, 2-1)->select(i | true)->collect(i | (Sequence{-1}->union(Sequence{ -1 }))))))) ; return count(0, 0, 0, 0, num); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate while True : n,s=map(int,input().split()) if n==0 : break lst=[0]*102 for _ in range(n): lst[int(input())]+=1 acc_lst=list(reversed(list(accumulate(reversed(lst))))) ans=0 for i in range(1,101): if s+1-i>i : ans+=lst[i]*acc_lst[s+1-i] else : ans+=lst[i]*(lst[i]-1)//2 ans+=lst[i]*acc_lst[i+1] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var lst : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 102) ; for _anon : Integer.subrange(0, n-1) do ( lst[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1] := lst[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1] + 1) ; var acc_lst : Sequence := (((accumulate((lst)->reverse())))->reverse()) ; var ans : int := 0 ; for i : Integer.subrange(1, 101-1) do ( if (s + 1 - i->compareTo(i)) > 0 then ( ans := ans + lst[i+1] * acc_lst[s + 1 - i+1] ) else ( ans := ans + lst[i+1] * (lst[i+1] - 1) div 2 ; ans := ans + lst[i+1] * acc_lst[i + 1+1] )) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from collections import Counter,deque from sys import stdout import time from math import factorial,log,gcd import sys from decimal import Decimal from heapq import* def S(): return sys.stdin.readline().split() def I(): return[int(i)for i in sys.stdin.readline().split()] def II(): return int(sys.stdin.readline()) def IS(): return sys.stdin.readline().replace('\n','') def pair(n): return(n-1)*n//2 def main(): n=II() s=IS() letters=set(s) ans=0 for w in letters : for i in range(n): if s[i]!=w : left=i+1 break for i in range(n-1,-1,-1): if s[i]!=w : right=n-i break ans=(ans+left*right-1)% mod print(ans+1) if __name__=='__main__' : mod=998244353 main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var mod : int := 998244353 ; main() ) else skip; operation S() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation IS() : OclAny pre: true post: true activity: return sys.stdin.readLine().replace(' ', ''); operation pair(n : OclAny) : OclAny pre: true post: true activity: return (n - 1) * n div 2; operation main() pre: true post: true activity: n := II() ; var s : OclAny := IS() ; var letters : Set := Set{}->union((s)) ; var ans : int := 0 ; for w : letters do ( for i : Integer.subrange(0, n-1) do ( if s[i+1] /= w then ( var left : OclAny := i + 1 ; break ) else skip) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if s[i+1] /= w then ( var right : double := n - i ; break ) else skip) ; ans := (ans + left * right - 1) mod mod) ; execute (ans + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin as sin def aint(): return int(input()) def amap(): return map(int,sin.readline().split()) def alist(): return list(map(int,sin.readline().split())) def astr(): return input() n=aint() s=input() i=0 j=n-1 ans=0 while i=0 and s[j]==s[-1]: j-=1 if s[0]==s[-1]: if i>j : ans=n*(n+1)//2 else : ans=(n-j)*(i+1) else : ans=i+n-j print(ans % 998244353) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var n : OclAny := aint() ; var s : String := (OclFile["System.in"]).readLine() ; var i : int := 0 ; var j : double := n - 1 ; var ans : int := 0 ; while (i->compareTo(n)) < 0 & s[i+1] = s->first() do ( i := i + 1) ; while j >= 0 & s[j+1] = s->last() do ( j := j - 1) ; if s->first() = s->last() then ( if (i->compareTo(j)) > 0 then ( ans := n * (n + 1) div 2 ) else ( ans := (n - j) * (i + 1) ) ) else ( ans := i + n - j ) ; execute (ans mod 998244353)->display(); operation aint() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation amap() : OclAny pre: true post: true activity: return (sin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation alist() : OclAny pre: true post: true activity: return ((sin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation astr() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() cleft=0 cright=0 for i in range(n): if s[i]==s[0]: cleft+=1 else : break for i in range(n-1,-1,-1): if s[i]==s[-1]: cright+=1 else : break if s[0]==s[-1]: result=(cleft+1)*(cright+1) print(result % 998244353) else : result=cleft+cright+1 print(result % 998244353) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var cleft : int := 0 ; var cright : int := 0 ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = s->first() then ( cleft := cleft + 1 ) else ( break )) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if s[i+1] = s->last() then ( cright := cright + 1 ) else ( break )) ; if s->first() = s->last() then ( var result : int := (cleft + 1) * (cright + 1) ; execute (result mod 998244353)->display() ) else ( result := cleft + cright + 1 ; execute (result mod 998244353)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) min_arr=min(arr) mins=[] for i in range(len(arr)): if arr[i]==min_arr : mins.append(i) mm=[] for i in range(len(mins)-1): mm.append(mins[i+1]-mins[i]) print(min(mm)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var min_arr : OclAny := (arr)->min() ; var mins : Sequence := Sequence{} ; for i : Integer.subrange(0, (arr)->size()-1) do ( if arr[i+1] = min_arr then ( execute ((i) : mins) ) else skip) ; var mm : Sequence := Sequence{} ; for i : Integer.subrange(0, (mins)->size() - 1-1) do ( execute ((mins[i + 1+1] - mins[i+1]) : mm)) ; execute ((mm)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=input() c1,c2=0,0 i=0 while p[i]==p[0]and i=0 : c2+=1 i-=1 if c1==n : print(((n*(n-1))//2)% 998244353) elif p[0]==p[n-1]: print(((c1+1)*(c2+1))% 998244353) else : print((c1+c2+1)% 998244353) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : String := (OclFile["System.in"]).readLine() ; var c1 : OclAny := null; var c2 : OclAny := null; Sequence{c1,c2} := Sequence{0,0} ; var i : int := 0 ; while p[i+1] = p->first() & (i->compareTo(n)) < 0 do ( c1 := c1 + 1 ; i := i + 1) ; i := n - 1 ; while p[i+1] = p[n - 1+1] & i >= 0 do ( c2 := c2 + 1 ; i := i - 1) ; if c1 = n then ( execute (((n * (n - 1)) div 2) mod 998244353)->display() ) else (if p->first() = p[n - 1+1] then ( execute (((c1 + 1) * (c2 + 1)) mod 998244353)->display() ) else ( execute ((c1 + c2 + 1) mod 998244353)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() a1=1 for i in range(1,n): if s[i]==s[0]: a1+=1 else : break b=1 for i in range(n-2,-1,-1): if s[i]==s[-1]: b+=1 else : break res=a1+b+1 if s[0]==s[-1]: res+=a1*b print(res % 998244353) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var a1 : int := 1 ; for i : Integer.subrange(1, n-1) do ( if s[i+1] = s->first() then ( a1 := a1 + 1 ) else ( break )) ; var b : int := 1 ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( if s[i+1] = s->last() then ( b := b + 1 ) else ( break )) ; var res : int := a1 + b + 1 ; if s->first() = s->last() then ( res := res + a1 * b ) else skip ; execute (res mod 998244353)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000 def numofArray(n,m): dp=[[0 for i in range(MAX)]for j in range(MAX)] di=[[]for i in range(MAX)] mu=[[]for i in range(MAX)] for i in range(1,m+1): for j in range(2*i,m+1,i): di[j].append(i) mu[i].append(j) di[i].append(i) for i in range(1,m+1): dp[1][i]=1 for i in range(2,n+1): for j in range(1,m+1): dp[i][j]=0 for x in di[j]: dp[i][j]+=dp[i-1][x] for x in mu[j]: dp[i][j]+=dp[i-1][x] ans=0 for i in range(1,m+1): ans+=dp[n][i] di[i].clear() mu[i].clear() return ans if __name__=="__main__" : n=m=3 print(numofArray(n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1000 ; skip ; if __name__ = "__main__" then ( n := 3; m := 3 ; execute (numofArray(n, m))->display() ) else skip; operation numofArray(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, MAX-1)->select(j | true)->collect(j | (Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)))) ; var di : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (Sequence{})) ; var mu : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(1, m + 1-1) do ( for j : Integer.subrange(2 * i, m + 1-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ((expr (atom (name di)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ; (expr (atom (name mu)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) ))))) ; (expr (atom (name di)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; for i : Integer.subrange(1, m + 1-1) do ( dp[1+1][i+1] := 1) ; for i : Integer.subrange(2, n + 1-1) do ( for j : Integer.subrange(1, m + 1-1) do ( dp[i+1][j+1] := 0 ; for x : di[j+1] do ( dp[i+1][j+1] := dp[i+1][j+1] + dp[i - 1+1][x+1]) ; for x : mu[j+1] do ( dp[i+1][j+1] := dp[i+1][j+1] + dp[i - 1+1][x+1]))) ; var ans : int := 0 ; for i : Integer.subrange(1, m + 1-1) do ( ans := ans + dp[n+1][i+1] ; (expr (atom (name di)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name clear) (arguments ( )))) ; (expr (atom (name mu)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name clear) (arguments ( ))))) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def longest(a,n,k): freq=[0]*n start=0 end=0 now=0 l=0 for i in range(n): freq[a[i]]+=1 if(freq[a[i]]==1): now+=1 while(now>k): freq[a[l]]-=1 if(freq[a[l]]==0): now-=1 l+=1 if(i-l+1>=end-start+1): end=i start=l for i in range(start,end+1): print(a[i],end=" ") if __name__=="__main__" : a=[6,5,1,2,3,2,1,4,5] n=len(a) k=3 longest(a,n,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{6}->union(Sequence{5}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{2}->union(Sequence{1}->union(Sequence{4}->union(Sequence{ 5 })))))))) ; n := (a)->size() ; k := 3 ; longest(a, n, k) ) else skip; operation longest(a : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var start : int := 0 ; var end : int := 0 ; var now : int := 0 ; var l : int := 0 ; for i : Integer.subrange(0, n-1) do ( freq[a[i+1]+1] := freq[a[i+1]+1] + 1 ; if (freq[a[i+1]+1] = 1) then ( now := now + 1 ) else skip ; while ((now->compareTo(k)) > 0) do ( freq[a[l+1]+1] := freq[a[l+1]+1] - 1 ; if (freq[a[l+1]+1] = 0) then ( now := now - 1 ) else skip ; l := l + 1) ; if ((i - l + 1->compareTo(end - start + 1)) >= 0) then ( end := i ; start := l ) else skip) ; for i : Integer.subrange(start, end + 1-1) do ( execute (a[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) ans=0 for i in range(n): if b[i]==a[ans]: ans+=1 print(n-ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if b[i+1] = a[ans+1] then ( ans := ans + 1 ) else skip) ; execute (n - ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ip=input() st="" if len(ip)!=1 : if ip[0]=="9" : st="9" ip=ip[1 :] for i in ip : if int(i)>4 : n=9-int(i) st+=str(n) else : st+=i else : st=ip print(int(st)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ip : String := (OclFile["System.in"]).readLine() ; var st : String := "" ; if (ip)->size() /= 1 then ( if ip->first() = "9" then ( st := "9" ; ip := ip->tail() ) else skip ; for i : ip->characters() do ( if ("" + ((i)))->toInteger() > 4 then ( var n : double := 9 - ("" + ((i)))->toInteger() ; st := st + ("" + ((n))) ) else ( st := st + i )) ) else ( st := ip ) ; execute (("" + ((st)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a1=list(map(int,input().split())) a2=list(map(int,input().split())) vis,j=set(),n-1 res=j for i in range(n-1,-1,-1): if a2[i]in vis : continue if a2[i]==a1[j]: j-=1 continue while a2[i]!=a1[j]: vis.add(a1[j]) j-=1 j-=1 res=j+1 print(n-res-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var vis : OclAny := null; var j : OclAny := null; Sequence{vis,j} := Sequence{Set{}->union(()),n - 1} ; var res : OclAny := j ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (vis)->includes(a2[i+1]) then ( continue ) else skip ; if a2[i+1] = a1[j+1] then ( j := j - 1 ; continue ) else skip ; while a2[i+1] /= a1[j+1] do ( execute ((a1[j+1]) : vis) ; j := j - 1) ; j := j - 1 ; res := j + 1) ; execute (n - res - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from math import* import bisect as bs n=int(input()) a=[int(x)for x in input().split()] b=[int(x)for x in input().split()] d={} for i in range(n): d[b[i]]=i c=0 ans=0 u=[0 for i in range(n)] for i in range(n): u[i]=d[a[i]] for i in range(1,n): if u[i]toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var b : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var d : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( d[b[i+1]+1] := i) ; var c : int := 0 ; var ans : int := 0 ; var u : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( u[i+1] := d[a[i+1]+1]) ; for i : Integer.subrange(1, n-1) do ( if (u[i+1]->compareTo(u[i - 1+1])) < 0 then ( ans := n - i ; break ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) i=j=0 for j in range(n): if b[j]==a[i]: i=i+1 print(n-i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var i : OclAny := 0; var j : int := 0 ; for j : Integer.subrange(0, n-1) do ( if b[j+1] = a[i+1] then ( i := i + 1 ) else skip) ; execute (n - i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() perm_target=list(map(int,input().split())) perm_given=list(map(int,input().split())) cursor=0 move=0 for val in perm_given : if val==perm_target[cursor]: cursor+=1 else : move+=1 print(move) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var perm_target : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var perm_given : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cursor : int := 0 ; var move : int := 0 ; for val : perm_given do ( if val = perm_target[cursor+1] then ( cursor := cursor + 1 ) else ( move := move + 1 )) ; execute (move)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : if input()=='0' : break a=sorted(list(map(int,input().split())))[: :-1] b=sorted(list(map(int,input().split())))[: :-1] p=0 ; c=0 ; for i,x in enumerate(a): if i/2collect( _x | (OclType["int"])->apply(_x) )))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var b : OclAny := sorted(((input().split())->collect( _x | (OclType["int"])->apply(_x) )))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var p : int := 0; var c : int := 0; ; (compound_stmt for (exprlist (expr (atom (name i))) , (expr (atom (name x)))) in (testlist (test (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name i))) / (expr (atom (number (integer 2)))))) < (comparison (expr (atom (name c))))))) : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))) ; (small_stmt break))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name x)))) <= (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name p)))))))) ]))))))) : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name p)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (else_clause else : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))))) (else_clause else : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NA'))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) line=[int(i)for i in input().split()] index=[] minimum=min(line) for i in range(len(line)): if line[i]==minimum : if len(index)==0 : index.append([i,0]) else : index.append([i,i-index[-1][0]]) index.sort(key=lambda x : x[1]) print(index[1][1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var line : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var index : Sequence := Sequence{} ; var minimum : OclAny := (line)->min() ; for i : Integer.subrange(0, (line)->size()-1) do ( if line[i+1] = minimum then ( if (index)->size() = 0 then ( execute ((Sequence{i}->union(Sequence{ 0 })) : index) ) else ( execute ((Sequence{i}->union(Sequence{ i - index->last()->first() })) : index) ) ) else skip) ; index := index->sort() ; execute (index[1+1][1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break a=list(map(int,input().split())) b=list(map(int,input().split())) a.sort(reverse=True) b.sort(reverse=True) ans,i=n,-1 for k in range(0,n,2): i+=1 if a[k]>b[i]: ans=k+1 break print("NA" if ans==n else ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; b := b->sort() ; var ans : OclAny := null; var i : OclAny := null; Sequence{ans,i} := Sequence{n,-1} ; for k : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( i := i + 1 ; if (a[k+1]->compareTo(b[i+1])) > 0 then ( var ans : OclAny := k + 1 ; break ) else skip) ; execute (if ans = n then "NA" else ans endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def counting_sort(nmax,la): f=[0]*(nmax+1) nmax=0 for a in la : f[a]+=1 if a>nmax : nmax=a k,i=len(la),nmax la=[] while k : if f[i]: la+=[i]*f[i] k-=f[i] i-=1 return la while True : n=int(input()) if n==0 : break a=list(map(int,input().split())) b=list(map(int,input().split())) a=counting_sort(100000,a) b=counting_sort(100000,b) ans,i=n,-1 for k in range(0,n,2): i+=1 if a[k]>b[i]: ans=k+1 break print("NA" if ans==n else ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := counting_sort(100000, a) ; b := counting_sort(100000, b) ; var ans : OclAny := null; var i : OclAny := null; Sequence{ans,i} := Sequence{n,-1} ; for k : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( i := i + 1 ; if (a[k+1]->compareTo(b[i+1])) > 0 then ( var ans : OclAny := k + 1 ; break ) else skip) ; execute (if ans = n then "NA" else ans endif)->display()); operation counting_sort(nmax : OclAny, la : OclAny) : OclAny pre: true post: true activity: var f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (nmax + 1)) ; nmax := 0 ; for a : la do ( f[a+1] := f[a+1] + 1 ; if (a->compareTo(nmax)) > 0 then ( nmax := a ) else skip) ; var k : OclAny := null; var i : OclAny := null; Sequence{k,i} := Sequence{(la)->size(),nmax} ; la := Sequence{} ; while k do ( if f[i+1] then ( la := la + MatrixLib.elementwiseMult(Sequence{ i }, f[i+1]) ; k := k - f[i+1] ) else skip ; i := i - 1) ; return la; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy from test.support import _MemoryWatchdog BIG_NUM=2000000000 HUGE_NUM=99999999999999999 MOD=1000000007 EPS=0.000000001 sys.setrecursionlimit(100000) while True : N=int(input()) if N==0 : break me=list(map(int,input().split())) enemy=list(map(int,input().split())) me.sort(reverse=True) enemy.sort(reverse=True) num_win=0 ans=BIG_NUM k=0 for i in range(N-1): if me[i]>enemy[k]: num_win+=1 if num_win>(i+1)//2 : ans=i+1 break else : k+=1 if ans==BIG_NUM : print("NA") else : print("%d" %(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var HUGE_NUM : int := 99999999999999999 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; sys.setrecursionlimit(100000) ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var me : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var enemy : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; me := me->sort() ; enemy := enemy->sort() ; var num_win : int := 0 ; var ans : int := BIG_NUM ; var k : int := 0 ; for i : Integer.subrange(0, N - 1-1) do ( if (me[i+1]->compareTo(enemy[k+1])) > 0 then ( num_win := num_win + 1 ; if (num_win->compareTo((i + 1) div 2)) > 0 then ( ans := i + 1 ; break ) else skip ) else ( k := k + 1 )) ; if ans = BIG_NUM then ( execute ("NA")->display() ) else ( execute (StringLib.format("%d",(ans)))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque while True : n=int(input()) if n==0 : break q1=deque(sorted(map(int,input().split()))) q2=deque(sorted(map(int,input().split()))) cnt=0 for k in range(1,n): top1=q1.pop() top2=q2.pop() if top1>top2 : cnt+=1 q2.append(top2) q2.popleft() if cnt*2>k : print(k) break else : print("NA") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var q1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort()) ; var q2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort()) ; var cnt : int := 0 ; (compound_stmt for (exprlist (expr (atom (name k)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name top1)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name q1)) (trailer . (name pop) (arguments ( ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name top2)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name q2)) (trailer . (name pop) (arguments ( ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name top1)))) > (comparison (expr (atom (name top2))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cnt)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name q2)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name top2)))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name q2)) (trailer . (name popleft) (arguments ( )))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name cnt))) * (expr (atom (number (integer 2)))))) > (comparison (expr (atom (name k))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name k)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NA"))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter,defaultdict,deque import sys,threading input=sys.stdin.readline def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s=input() return(list(s[: len(s)])) def invr(): return(map(int,input().split())) x=inp() s=list(str(x)) for i,ch in enumerate(s): if ch>'4' : s[i]=str(ord('9')-ord(ch)) if s[0]=='0' : s[0]='9' print(''.join(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; var x : OclAny := inp() ; s := (("" + ((x))))->characters() ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var ch : OclAny := _tuple->at(_indx); if ch > '4' then ( s[i+1] := ("" + ((('9')->char2byte() - (ch)->char2byte()))) ) else skip) ; if s->first() = '0' then ( s->first() := '9' ) else skip ; execute (StringLib.sumStringsWithSeparator((s), ''))->display(); operation inp() : OclAny pre: true post: true activity: return (("" + (((OclFile["System.in"]).readLine())))->toInteger()); operation inlt() : OclAny pre: true post: true activity: return (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))); operation insr() : OclAny pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; return ((s.subrange(1,(s)->size()))); operation invr() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Add(x,y): while(y!=0): carry=x & y x=x ^ y y=carry<<1 return x print(Add(15,32)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (Add(15, 32))->display(); operation Add(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: while (y /= 0) do ( var carry : int := MathLib.bitwiseAnd(x, y) ; x := MathLib.bitwiseXor(x, y) ; y := carry * (2->pow(1))) ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(num): if num=="" : return False if num[0]=="0" : return num=="0" return 0<=int(num)<=255 s=input() ans=0 for i in range(1,4): for j in range(1,4): for k in range(1,4): n1=s[: i] n2=s[i : i+j] n3=s[i+j : i+j+k] n4=s[i+j+k :] if check(n1)and check(n2)and check(n3)and check(n4): ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; for i : Integer.subrange(1, 4-1) do ( for j : Integer.subrange(1, 4-1) do ( for k : Integer.subrange(1, 4-1) do ( var n1 : OclAny := s.subrange(1,i) ; var n2 : OclAny := s.subrange(i+1, i + j) ; var n3 : OclAny := s.subrange(i + j+1, i + j + k) ; var n4 : OclAny := s.subrange(i + j + k+1) ; if check(n1) & check(n2) & check(n3) & check(n4) then ( ans := ans + 1 ) else skip))) ; execute (ans)->display(); operation check(num : OclAny) : OclAny pre: true post: true activity: if num = "" then ( return false ) else skip ; if num->first() = "0" then ( return num = "0" ) else skip ; return 0 <= ("" + ((num)))->toInteger() & (("" + ((num)))->toInteger() <= 255); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools S=input() ans=0 for ptn in itertools.combinations(range(1,len(S)),3): ai,bi,ci=ptn a=S[: ai] b=S[ai : bi] c=S[bi : ci] d=S[ci :] if a[0]=='0' and a!='0' : continue if b[0]=='0' and b!='0' : continue if c[0]=='0' and c!='0' : continue if d[0]=='0' and d!='0' : continue if not 0<=int(a)<=255 : continue if not 0<=int(b)<=255 : continue if not 0<=int(c)<=255 : continue if not 0<=int(d)<=255 : continue ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var S : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; for ptn : itertools.combinations(Integer.subrange(1, (S)->size()-1), 3) do ( var ai : OclAny := null; var bi : OclAny := null; var ci : OclAny := null; Sequence{ai,bi,ci} := ptn ; var a : OclAny := S.subrange(1,ai) ; var b : OclAny := S.subrange(ai+1, bi) ; var c : OclAny := S.subrange(bi+1, ci) ; var d : OclAny := S.subrange(ci+1) ; if a->first() = '0' & a /= '0' then ( continue ) else skip ; if b->first() = '0' & b /= '0' then ( continue ) else skip ; if c->first() = '0' & c /= '0' then ( continue ) else skip ; if d->first() = '0' & d /= '0' then ( continue ) else skip ; if not(0 <= ("" + ((a)))->toInteger() & (("" + ((a)))->toInteger() <= 255)) then ( continue ) else skip ; if not(0 <= ("" + ((b)))->toInteger() & (("" + ((b)))->toInteger() <= 255)) then ( continue ) else skip ; if not(0 <= ("" + ((c)))->toInteger() & (("" + ((c)))->toInteger() <= 255)) then ( continue ) else skip ; if not(0 <= ("" + ((d)))->toInteger() & (("" + ((d)))->toInteger() <= 255)) then ( continue ) else skip ; ans := ans + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for _ in range(int(input())): n=int(input()) arr=list(map(int,input().split())) ans=0 for i in range(n): for j in range(i+1,n): if math.gcd(arr[i],2*arr[j])>1 or math.gcd(2*arr[i],arr[j])>1 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if (arr[i+1])->gcd(2 * arr[j+1]) > 1 or (2 * arr[i+1])->gcd(arr[j+1]) > 1 then ( ans := ans + 1 ) else skip)) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) o,e=[],[] cnt=0 for i in l : if i % 2==0 : e.append(i) else : o.append(i) if len(o)==0 : print(len(e)*(len(e)-1)//2) else : for i in range(len(o)): for j in range(i+1,len(o)): if(math.gcd(o[i],o[j])>1): cnt=cnt+1 for i in range(n-1,n-len(e)-1,-1): cnt=cnt+i print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var o : OclAny := null; var e : OclAny := null; Sequence{o,e} := Sequence{Sequence{},Sequence{}} ; var cnt : int := 0 ; for i : l do ( if i mod 2 = 0 then ( execute ((i) : e) ) else ( execute ((i) : o) )) ; if (o)->size() = 0 then ( execute ((e)->size() * ((e)->size() - 1) div 2)->display() ) else ( for i : Integer.subrange(0, (o)->size()-1) do ( for j : Integer.subrange(i + 1, (o)->size()-1) do ( if ((o[i+1])->gcd(o[j+1]) > 1) then ( cnt := cnt + 1 ) else skip)) ; for i : Integer.subrange(n - (e)->size() - 1 + 1, n - 1)->reverse() do ( cnt := cnt + i) ; execute (cnt)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math t=int(input()) while t : t-=1 n=int(input()) c=0 l=list(map(int,input().split())) for i in range(n): for j in range(i+1,n): if math.gcd(l[i],2*l[j])>1 or math.gcd(l[i]*2,l[j])>1 : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( t := t - 1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := 0 ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if (l[i+1])->gcd(2 * l[j+1]) > 1 or (l[i+1] * 2)->gcd(l[j+1]) > 1 then ( c := c + 1 ) else skip)) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout,stderr import heapq def solve(N,hikers): N=len(hikers) D=[h[0]for h in hikers] M=[h[1]for h in hikers] intersects=[((360-D[i])*M[i],M[i],i)for i in range(N)] heapq.heapify(intersects) best=N current=best seen=set() while current<=2*N : (m,M,i)=heapq.heappop(intersects) if i not in seen : current-=1 best=min(best,current) seen.add(i) else : current+=1 heapq.heappush(intersects,(m+M*360,M,i)) return best def main(): T=int(input()) for case in range(1,T+1): N=int(input()) hikers=[] for i in range(N): D,H,M=map(int,input().split()) for j in range(H): hikers.append((D,M+j)) answer=solve(N,hikers) print("Case #%d: %s" %(case,answer)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { suite`nestedAttributeDefinitions operation initialise() pre: true post: true activity: skip ; skip ; skip ; var Sequence{m, M, i} : OclAny := heapq.heappop(intersects); operation solve(N : OclAny, hikers : OclAny) pre: true post: true activity: N := (hikers)->size() ; var D : Sequence := hikers->select(h | true)->collect(h | (h->first())) ; var M : Sequence := hikers->select(h | true)->collect(h | (h[1+1])) ; var intersects : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{(360 - D[i+1]) * M[i+1], M[i+1], i})) ; heapq.heapify(intersects) ; var best : OclAny := N ; var current : OclAny := best ; var seen : Set := Set{}->union(()) ; while (current->compareTo(2 * N)) <= 0 do (suite); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- size_array=int(input()) array=list(map(int,input().split(' '))) minimums=min(array) minimums_indexes=[] for i in range(size_array): if array[i]==minimums : minimums_indexes.append(i) minimums_distances=[] for i in range(1,len(minimums_indexes)): minimums_distances.append(minimums_indexes[i]-minimums_indexes[i-1]) print(min(minimums_distances)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var size_array : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var array : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var minimums : OclAny := (array)->min() ; var minimums_indexes : Sequence := Sequence{} ; for i : Integer.subrange(0, size_array-1) do ( if array[i+1] = minimums then ( execute ((i) : minimums_indexes) ) else skip) ; var minimums_distances : Sequence := Sequence{} ; for i : Integer.subrange(1, (minimums_indexes)->size()-1) do ( execute ((minimums_indexes[i+1] - minimums_indexes[i - 1+1]) : minimums_distances)) ; execute ((minimums_distances)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) a=[] b=[] for i in range(0,n): if l[i]% 2==0 : a.append(l[i]) else : b.append(l[i]) a=a+b c=0 for i in range(n): for j in range(i+1,n): if math.gcd(a[i],2*a[j])>1 : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if l[i+1] mod 2 = 0 then ( execute ((l[i+1]) : a) ) else ( execute ((l[i+1]) : b) )) ; a := a->union(b) ; var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if (a[i+1])->gcd(2 * a[j+1]) > 1 then ( c := c + 1 ) else skip)) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfLastDig(n,m): sum=0 ; k=n//m ; arr=[0]*10 ; for i in range(10): arr[i]=m*(i+1)% 10 ; sum+=arr[i]; rem=k % 10 ; ans=(k//10)*sum ; for i in range(rem): ans+=arr[i]; return ans ; if __name__=="__main__" : n=100 ; m=3 ; print(sumOfLastDig(n,m)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 100; m := 3; ; execute (sumOfLastDig(n, m))->display(); ) else skip; operation sumOfLastDig(n : OclAny, m : OclAny) pre: true post: true activity: var sum : int := 0; ; var k : int := n div m; ; var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10); ; for i : Integer.subrange(0, 10-1) do ( arr[i+1] := m * (i + 1) mod 10; ; sum := sum + arr[i+1];) ; var rem : int := k mod 10; ; var ans : int := (k div 10) * sum; ; for i : Integer.subrange(0, rem-1) do ( ans := ans + arr[i+1];) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() enk=int(x) yreq=9 for d in range(len(x)): if(d==0 and x[d]=='9'): pass else : yreq=int(x[: d]+str(9-int(x[d]))+x[d+1 :]) if(d==0 and x[d]=='9'): pass elif yreqtoInteger() ; var yreq : int := 9 ; for d : Integer.subrange(0, (x)->size()-1) do ( if (d = 0 & x[d+1] = '9') then ( skip ) else ( yreq := ("" + ((x.subrange(1,d) + ("" + ((9 - ("" + ((x[d+1])))->toInteger()))) + x.subrange(d + 1+1))))->toInteger() ) ; if (d = 0 & x[d+1] = '9') then ( skip ) else (if (yreq->compareTo(enk)) < 0 then ( x := x.subrange(1,d) + (("" + ((9 - ("" + ((x[d+1])))->toInteger())))) + x.subrange(d + 1+1) ; enk := yreq ) else skip)) ; execute (enk)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : n=int(input()) k=list((input()).split()) k=[int(i)for i in k] print(k.index(max(k))+1) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : Sequence := (((OclFile["System.in"]).readLine()).split()) ; k := k->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute (k->indexOf((k)->max()) - 1 + 1)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : for _ in range(int(input())): n=int(input()) arr=list(map(int,input().split())) x=0 for i in range(1,n): if arr[i]>=arr[x]: x=i print(x+1) except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : int := 0 ; for i : Integer.subrange(1, n-1) do ( if (arr[i+1]->compareTo(arr[x+1])) >= 0 then ( x := i ) else skip) ; execute (x + 1)->display())) catch (_e : OclException) do ( break) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from random import* def check(lista2): for i in range(0,len(lista2)): if lista2[i]!=0 : k=i break ; for i in range(0,len(lista2)): if i!=k : if lista2[i]!=0 : return 99 return k t=int(input()) for j in range(0,t): n=int(input()) lista=list(map(int,input().split())) while True : if check(lista)!=99 : index=check(lista) break ; x=randint(0,n-1) while(lista[x]==0): x=randint(0,n-1) y=randint(0,n-1) while(y==x or lista[y]==0): y=randint(0,n-1) s=min((lista[x],lista[y])) lista[x]-=s lista[y]-=s print(index+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lista : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; while true do ( if check(lista) /= 99 then ( var index : OclAny := check(lista) ; break; ) else skip ; var x : OclAny := randint(0, n - 1) ; while (lista[x+1] = 0) do ( x := randint(0, n - 1)) ; var y : OclAny := randint(0, n - 1) ; while (y = x or lista[y+1] = 0) do ( y := randint(0, n - 1)) ; var s : OclAny := (Sequence{lista[x+1], lista[y+1]})->min() ; lista[x+1] := lista[x+1] - s ; lista[y+1] := lista[y+1] - s) ; execute (index + 1)->display()); operation check(lista2 : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, (lista2)->size()-1) do ( if lista2[i+1] /= 0 then ( var k : OclAny := i ; break; ) else skip) ; for i : Integer.subrange(0, (lista2)->size()-1) do ( if i /= k then ( if lista2[i+1] /= 0 then ( return 99 ) else skip ) else skip) ; return k; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from os.path import exists if exists("test.txt"): sys.stdin=open("test.txt","r") for _ in range(int(input())): n=int(input()) a=(list(map(int,input().split()))) mx=max(a) for i in range(len(a)): if mx==a[i]: print(i+1); break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if exists("test.txt") then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("test.txt")) ) else skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var mx : OclAny := (a)->max() ; for i : Integer.subrange(0, (a)->size()-1) do ( if mx = a[i+1] then ( execute (i + 1)->display(); break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) ball=input().split() a=len(ball)-1 while a>=0 : ball[a]=int(ball[a]) a-=1 if n==1 : print(1) else : i=1 max_balls=max(ball) while i<=len(ball): if ball[i-1]==max_balls : print(i) break i+=1 t=int(input()) while t>0 : solve() t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( solve() ; t := t - 1); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ball : OclAny := input().split() ; var a : double := (ball)->size() - 1 ; while a >= 0 do ( ball[a+1] := ("" + ((ball[a+1])))->toInteger() ; a := a - 1) ; if n = 1 then ( execute (1)->display() ) else ( var i : int := 1 ; var max_balls : OclAny := (ball)->max() ; while (i->compareTo((ball)->size())) <= 0 do ( if ball[i - 1+1] = max_balls then ( execute (i)->display() ; break ) else skip ; i := i + 1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printPattern(s,n): print(''.join(s)) i,j=0,n-1 while i1 : s[i],s[j]='*','*' print(''.join(s)) i+=1 j-=1 if __name__=="__main__" : s="geeks" n=len(s) printPattern(list(s),n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "geeks" ; n := (s)->size() ; printPattern((s), n) ) else skip; operation printPattern(s : OclAny, n : OclAny) pre: true post: true activity: execute (StringLib.sumStringsWithSeparator((s), ''))->display() ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,n - 1} ; while (i->compareTo(j)) < 0 do ( var s[i+1] : OclAny := null; var s[j+1] : OclAny := null; Sequence{s[i+1],s[j+1]} := Sequence{s[j+1],s[i+1]} ; i := i + 1 ; j := j - 1) ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,n - 1} ; while j - i > 1 do ( var s[i+1] : OclAny := null; var s[j+1] : OclAny := null; Sequence{s[i+1],s[j+1]} := Sequence{'*','*'} ; execute (StringLib.sumStringsWithSeparator((s), ''))->display() ; i := i + 1 ; j := j - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tc=int(input().strip()) for t in range(tc): b,n=tuple(int(x)for x in input().strip().split()) m=list(int(x)for x in input().strip().split()) l,r=-1,n*min(m) lv=0 while l+1trim())))->toInteger() ; for t : Integer.subrange(0, tc-1) do ( var b : OclAny := null; var n : OclAny := null; Sequence{b,n} := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name strip) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ; var m : Sequence := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name strip) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{-1,n * (m)->min()} ; var lv : int := 0 ; while (l + 1->compareTo(r)) < 0 do ( var c : int := (l + r) div 2 ; var v : OclAny := ((argument (test (logical_test (comparison (expr (expr (expr (atom (name c))) // (expr (atom (name a)))) + (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name m))))))))->sum() ; if (v->compareTo(n)) < 0 then ( var l : int := c ; lv := v ) else ( var r : int := c )) ; var idx : double := n - lv - 1 ; var ans : OclAny := OclType["Sequence"]((argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (expr (atom (name r))) % (expr (atom (name m)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))) == (comparison (expr (atom (number (integer 0))))))))))))[idx+1] ; execute (StringLib.format("Case #%d: %d",Sequence{t + 1, ans}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cal(m,t): return sum([(t+x-1)//x for x in m]) def gao(): (b,n)=list(map(int,input().split())) m=list(map(int,input().split())) l=0 r=min(m)*n ans=r while l<=r : mid=(l+r)//2 s=cal(m,mid) if s>=n : ans=mid r=mid-1 else : l=mid+1 ans=ans-1 cnt=n-cal(m,ans) for i in range(len(m)): if ans % m[i]==0 : cnt-=1 if cnt==0 : return i+1 return-1 t=int(input()) for cas in range(t): print('Case #%d:' %(cas+1),end=' ') print(gao()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; t := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for cas : Integer.subrange(0, t-1) do ( execute (StringLib.format('Case #%d:',(cas + 1)))->display() ; execute (gao())->display()); operation cal(m : OclAny, t : OclAny) : OclAny pre: true post: true activity: return (m->select(x | true)->collect(x | ((t + x - 1) div x)))->sum(); operation gao() pre: true post: true activity: ; var Sequence{b, n} : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; m := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : int := 0 ; var r : double := (m)->min() * n ; var ans : OclAny := r ; while (l->compareTo(r)) <= 0 do ( var mid : int := (l + r) div 2 ; var s : OclAny := cal(m, mid) ; if (s->compareTo(n)) >= 0 then ( ans := mid ; r := mid - 1 ) else ( l := mid + 1 )) ; ans := ans - 1 ; var cnt : double := n - cal(m, ans) ; for i : Integer.subrange(0, (m)->size()-1) do ( if ans mod m[i+1] = 0 then ( cnt := cnt - 1 ; if cnt = 0 then ( return i + 1 ) else skip ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- counter=0 result=0 x=list(map(int,input().split())) prison=list(map(int,input().split())) for i in range(x[0]): if(prison[i]<=x[1]): counter+=1 else : counter=0 if(counter>=x[2]): result+=1 print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var counter : int := 0 ; var result : int := 0 ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var prison : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, x->first()-1) do ( if ((prison[i+1]->compareTo(x[1+1])) <= 0) then ( counter := counter + 1 ) else ( counter := 0 ) ; if ((counter->compareTo(x[2+1])) >= 0) then ( result := result + 1 ) else skip) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.stdin=open('a.in','r') sys.stdout=open('a.out','w') def getline(): return[int(c)for c in input().split()] def can(t,b,B,N): ans=0 flag=True count=sum([(t+(c-1))//c for c in b]) free=sum([1 for c in b if t % c==0]) if count+free>=N : flag=True tmp=0 for j in range(B): if t % b[j]==0 : tmp+=1 if tmp==N-count : return[j+1,True] return[0,True] else : return[0,False] def solve(): [B,N]=getline() b=getline() l=0 r=10000000000000000 [ans,flag]=can(l,b,B,N) if flag : return ans while l+1union(Sequence{ flag }) := can(l, b, B, N); operation getline() : OclAny pre: true post: true activity: return input().split()->select(c | true)->collect(c | (("" + ((c)))->toInteger())); operation can(t : OclAny, b : OclAny, B : OclAny, N : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; var flag : boolean := true ; var count : OclAny := (b->select(c | true)->collect(c | ((t + (c - 1)) div c)))->sum() ; var free : OclAny := (b->select(c | t mod c = 0)->collect(c | (1)))->sum() ; if (count + free->compareTo(N)) >= 0 then ( flag := true ; var tmp : int := 0 ; for j : Integer.subrange(0, B-1) do ( if t mod b[j+1] = 0 then ( tmp := tmp + 1 ) else skip ; if tmp = N - count then ( return Sequence{j + 1}->union(Sequence{ true }) ) else skip) ; return Sequence{0}->union(Sequence{ true }) ) else ( return Sequence{0}->union(Sequence{ false }) ); operation solve() pre: true post: true activity: ; Sequence{B}->union(Sequence{ N }) := getline() ; b := getline() ; var l : int := 0 ; var r : int := 10000000000000000; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from typing import List,Tuple from collections import defaultdict,deque,namedtuple from heapq import heappush as push,heappop as pop import sys INF=(int)(1e9+7) sys.setrecursionlimit(INF) def solve(n): res=0 power=0 while n : digit=n % 10 n=n//10 if n!=0 and digit>=5 : res+=((9-digit)*(10**power)) else : if digit==9 or digit<5 : res+=(digit*(10**power)) else : res+=((9-digit)*(10**power)) power+=1 return res if __name__=="__main__" : n=int(input()) print(solve(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var INF : OclAny := (OclType["int"])(("1e9")->toReal() + 7) ; sys.setrecursionlimit(INF) ; skip ; if __name__ = "__main__" then ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (solve(n))->display() ) else skip; operation solve(n : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; var power : int := 0 ; while n do ( var digit : int := n mod 10 ; n := n div 10 ; if n /= 0 & digit >= 5 then ( res := res + ((9 - digit) * ((10)->pow(power))) ) else ( if digit = 9 or digit < 5 then ( res := res + (digit * ((10)->pow(power))) ) else ( res := res + ((9 - digit) * ((10)->pow(power))) ) ) ; power := power + 1) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil from fractions import Fraction from heapq import heapify,heappop,heappushpop T=int(input()) for case in range(1,T+1): B,N=[int(i)for i in input().split()] m=[int(i)for i in input().split()] tmin=max(N-B,0)/sum(Fraction(1,i)for i in m) N-=sum(ceil(tmin/m[b])for b in range(B)) h=[(ceil(tmin/m[b])*m[b],b)for b in range(B)] heapify(h) t,b=heappop(h) for i in range(N-1): t,b=heappushpop(h,(t+m[b],b)) print("Case #{}:{}".format(case,b+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for case : Integer.subrange(1, T + 1-1) do ( var B : OclAny := null; var N : OclAny := null; Sequence{B,N} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var m : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var tmin : double := Set{N - B, 0}->max() / ((argument (test (logical_test (comparison (expr (atom (name Fraction)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name m))))))))->sum() ; N := N - ((argument (test (logical_test (comparison (expr (atom (name ceil)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name tmin))) / (expr (atom (name m)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ]))))))))) ))))))) (comp_for for (exprlist (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name B)))))))) )))))))))->sum() ; var h : Sequence := Integer.subrange(0, B-1)->select(b | true)->collect(b | (Sequence{ceil(tmin / m[b+1]) * m[b+1], b})) ; heapify(h) ; var t : OclAny := null; var b : OclAny := null; Sequence{t,b} := heappop(h) ; for i : Integer.subrange(0, N - 1-1) do ( var t : OclAny := null; var b : OclAny := null; Sequence{t,b} := heappushpop(h, Sequence{t + m[b+1], b})) ; execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{case, b + 1}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq def ReadIn(): t=int(input()) for c in range(1,t+1): m,n=[int(x)for x in input().split()] a=[int(x)for x in input().split()] yield c,n,a def OK(n,a,guess): return sum([guess//x+1 for x in a])>=n def Solve(n,a): if n<=len(a): return n lower=0 upper=max(a)*n while lowerat(_indx); _indx := _indx + 1; var n : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); execute (StringLib.format('Case #%d: %d',Sequence{c, Solve(n, a)}))->display()) ) else skip; operation ReadIn(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for c : Integer.subrange(1, t + 1-1) do ( var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return c, n, a); operation OK(n : OclAny, a : OclAny, guess : OclAny) : OclAny pre: true post: true activity: return ((a->select(x | true)->collect(x | (guess div x + 1)))->sum()->compareTo(n)) >= 0; operation Solve(n : OclAny, a : OclAny) : OclAny pre: true post: true activity: if (n->compareTo((a)->size())) <= 0 then ( return n ) else skip ; var lower : int := 0 ; var upper : double := (a)->max() * n ; while (lower->compareTo(upper)) < 0 do ( guess := (lower + upper + 1) div 2 ; if OK(n, a, guess) then ( upper := guess - 1 ) else ( lower := guess )) ; guess := lower ; var heap : Sequence := Sequence{} ; var remain : OclAny := n ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); var num : int := guess div x + 1 ; remain := remain - num ; heapq.heappush(heap, Sequence{num * x - guess, i})) ; var ret : OclAny := heap->first()[1+1] ; for r : Integer.subrange(0, remain-1) do ( var i : OclAny := null; Sequence{t,i} := heapq.heappop(heap) ; heapq.heappush(heap, Sequence{t + a[i+1], i}) ; ret := i) ; return ret + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from heapq import heappush,heappop from itertools import permutations,accumulate import sys import math import bisect def LI(): return[int(x)for x in sys.stdin.buffer.readline().split()] def I(): return int(sys.stdin.buffer.readline()) def LS(): return[list(x)for x in sys.stdin.readline().split()] def S(): res=list(sys.stdin.readline()) if res[-1]=="\n" : return res[:-1] return res def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] sys.setrecursionlimit(1000000) mod=1000000007 def solve(): n=I() a=LI() c=defaultdict(lambda : 0) for i in a : c[i]+=1 a=[[i,2-(j & 1)]for(i,j)in c.items()] a.sort() s=0 c=0 for i in range(len(a)): if a[i][1]==2 : c+=1 s+=a[i][1] s-=c if c & 1 : s-=1 print(s) return if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1000000) ; var mod : int := 1000000007 ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation LI() : OclAny pre: true post: true activity: return sys.stdin.buffer.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation I() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.buffer.readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | ((x))); operation S() : OclAny pre: true post: true activity: var res : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if res->last() = "\n" then ( return res->front() ) else skip ; return res; operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation solve() pre: true post: true activity: n := I() ; var a : OclAny := LI() ; var c : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; for i : a do ( c[i+1] := c[i+1] + 1) ; a := c->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->select(Sequence{i, j} | true)->collect(Sequence{i, j} | (Sequence{i}->union(Sequence{ 2 - (MathLib.bitwiseAnd(j, 1)) }))) ; a := a->sort() ; var s : int := 0 ; c := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( if a[i+1][1+1] = 2 then ( c := c + 1 ) else skip ; s := s + a[i+1][1+1]) ; s := s - c ; if MathLib.bitwiseAnd(c, 1) then ( s := s - 1 ) else skip ; execute (s)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- si=lambda : input() ni=lambda : int(input()) nm=lambda : map(int,input().split()) nl=lambda : list(map(int,input().split())) from collections import defaultdict as dd n=int(input()) a=nl() a.sort() d=dd(int) for aa in a : d[aa]+=1 counter=0 for k,v in d.items(): if v % 2==0 : counter+=v-1 if counter % 2==0 : print(len(d)) else : print(len(d)-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var si : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var ni : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var nm : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var nl : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := nl->apply() ; a := a->sort() ; var d : OclAny := dd(OclType["int"]) ; for aa : a do ( d[aa+1] := d[aa+1] + 1) ; var counter : int := 0 ; for _tuple : d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if v mod 2 = 0 then ( counter := counter + v - 1 ) else skip) ; if counter mod 2 = 0 then ( execute ((d)->size())->display() ) else ( execute ((d)->size() - 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calc(n): ret=n while ret>=3 : ret=ret % 3+ret//3 return ret n=int(input()) arr=list(map(int,input().split())) cnt=[0]*(10**5+1) for i in range(n): cnt[arr[i]]+=1 cnt1=0 cnt2=0 for i in range(10**5+1): tmp=calc(cnt[i]) if tmp==1 : cnt1+=1 elif tmp==2 : cnt2+=1 if cnt2 % 2==0 : print(cnt1+cnt2) else : print(cnt1+cnt2-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((10)->pow(5) + 1)) ; for i : Integer.subrange(0, n-1) do ( cnt[arr[i+1]+1] := cnt[arr[i+1]+1] + 1) ; var cnt1 : int := 0 ; var cnt2 : int := 0 ; for i : Integer.subrange(0, (10)->pow(5) + 1-1) do ( var tmp : OclAny := calc(cnt[i+1]) ; if tmp = 1 then ( cnt1 := cnt1 + 1 ) else (if tmp = 2 then ( cnt2 := cnt2 + 1 ) else skip)) ; if cnt2 mod 2 = 0 then ( execute (cnt1 + cnt2)->display() ) else ( execute (cnt1 + cnt2 - 1)->display() ); operation calc(n : OclAny) : OclAny pre: true post: true activity: var ret : OclAny := n ; while ret >= 3 do ( ret := ret mod 3 + ret div 3) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=input().split() already=[False]*(10**5+1) dup_count=0 for a in A : a=int(a) if not already[a]: already[a]=True else : dup_count+=1 if dup_count % 2==0 : print(N-dup_count) else : print(N-dup_count-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : OclAny := input().split() ; var already : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, ((10)->pow(5) + 1)) ; var dup_count : int := 0 ; for a : A do ( var a : int := ("" + ((a)))->toInteger() ; if not(already[a+1]) then ( already[a+1] := true ) else ( dup_count := dup_count + 1 )) ; if dup_count mod 2 = 0 then ( execute (N - dup_count)->display() ) else ( execute (N - dup_count - 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n,*a=map(int,open(0).read().split()) c=Counter(a) b=0 for i in c.values(): b+=i-1 if b % 2!=0 : b+=1 print(n-b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : OclAny := Counter(a) ; var b : int := 0 ; for i : c.values() do ( b := b + i - 1) ; if b mod 2 /= 0 then ( b := b + 1 ) else skip ; execute (n - b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,val): self.data=val ; self.left=None ; self.right=None ; def spiralOrder(root): d=[]; d.append(root); direct=0 ; while(len(d)!=0): size=len(d); while(size): size-=1 ; if(direct==0): temp=d.pop(); if(temp.right): d.insert(0,temp.right); if(temp.left): d.insert(0,temp.left); print(temp.data,end=" "); else : temp=d[0]; d.pop(0); if(temp.left): d.append(temp.left); if(temp.right): d.append(temp.right); print(temp.data,end=" "); print() direct=1-direct ; if __name__=="__main__" : root=Node(10); root.left=Node(20); root.right=Node(30); root.left.left=Node(40); root.left.right=Node(60); spiralOrder(root); ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); operation initialise(val : OclAny) : Node pre: true post: true activity: self.data := val; ; self.left := null; ; self.right := null;; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( root := (Node.newNode()).initialise(10); ; root.left := (Node.newNode()).initialise(20); ; root.right := (Node.newNode()).initialise(30); ; root.left.left := (Node.newNode()).initialise(40); ; root.left.right := (Node.newNode()).initialise(60); ; spiralOrder(root); ) else skip; operation spiralOrder(root : OclAny) pre: true post: true activity: var d : Sequence := Sequence{}; ; execute ((root) : d); ; var direct : int := 0; ; while ((d)->size() /= 0) do ( var size : int := (d)->size(); ; while (size) do ( size := size - 1; ; if (direct = 0) then ( var temp : OclAny := d->last() ; d := d->front(); ; if (temp.right) then ( d := d.insertAt(0+1, temp.right); ) else skip ; if (temp.left) then ( d := d.insertAt(0+1, temp.left); ) else skip ; execute (temp.data)->display(); ) else ( temp := d->first(); ; d := d->excludingAt(0+1); ; if (temp.left) then ( execute ((temp.left) : d); ) else skip ; if (temp.right) then ( execute ((temp.right) : d); ) else skip ; execute (temp.data)->display(); )) ; execute (->display() ; direct := 1 - direct;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import array from collections import deque def groupify(length,adj_list): group=array.array('l',(-1 for _ in range(length))) g_id=0 dq=deque() for idx in range(length): if group[idx]==-1 : group[idx]=g_id dq.append(idx) while len(dq): v=dq.popleft() for t in adj_list[v]: if group[t]==-1 : group[t]=g_id dq.append(t) g_id+=1 return group n,m=map(int,input().split()) adj_list=[set()for _ in range(n)] for _ in range(m): i,j=map(int,input().split()) adj_list[i].add(j) adj_list[j].add(i) group=groupify(n,adj_list) q=int(input()) for _ in range(q): s,t=map(int,input().split()) if group[s]==group[t]: print('yes') else : print('no') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; adj_list := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; for _anon : Integer.subrange(0, m-1) do ( var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name adj_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) ; (expr (atom (name adj_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; group := groupify(n, adj_list) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if group[s+1] = group[t+1] then ( execute ('yes')->display() ) else ( execute ('no')->display() )); operation groupify(length : OclAny, adj_list : OclAny) : OclAny pre: true post: true activity: var group : OclAny := array.array('l', Sequence{(testlist_comp (test (logical_test (comparison (expr (atom - (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name length)))))))) ))))))))}) ; var g_id : int := 0 ; var dq : Sequence := () ; for idx : Integer.subrange(0, length-1) do ( if group[idx+1] = -1 then ( group[idx+1] := g_id ; execute ((idx) : dq) ; while (dq)->size() do ( var v : OclAny := dq->first() ; dq := dq->tail() ; for t : adj_list[v+1] do ( if group[t+1] = -1 then ( group[t+1] := g_id ; execute ((t) : dq) ) else skip)) ; g_id := g_id + 1 ) else skip) ; return group; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- counter=0 result=0 x=list(map(int,input().split())) prison=list(map(int,input().split())) for i in range(x[0]): if(prison[i]<=x[1]): counter+=1 else : counter=0 if(counter>=x[2]): result+=1 print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var counter : int := 0 ; var result : int := 0 ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var prison : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, x->first()-1) do ( if ((prison[i+1]->compareTo(x[1+1])) <= 0) then ( counter := counter + 1 ) else ( counter := 0 ) ; if ((counter->compareTo(x[2+1])) >= 0) then ( result := result + 1 ) else skip) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def __gcd(a,b): if(a==0 or b==0): return 0 ; if(a==b): return a ; if(a>b): return __gcd(a-b,b); return __gcd(a,b-a); def NumberOfSquares(x,y): s=__gcd(x,y); ans=(x*y)/(s*s); return int(ans); m=385 ; n=60 ; print(NumberOfSquares(m,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var m : int := 385; ; var n : int := 60; ; execute (NumberOfSquares(m, n))->display();; operation __gcd(a : OclAny, b : OclAny) pre: true post: true activity: if (a = 0 or b = 0) then ( return 0; ) else skip ; if (a = b) then ( return a; ) else skip ; if ((a->compareTo(b)) > 0) then ( return __gcd(a - b, b); ) else skip ; return __gcd(a, b - a);; operation NumberOfSquares(x : OclAny, y : OclAny) pre: true post: true activity: var s : OclAny := __gcd(x, y); ; var ans : double := (x * y) / (s * s); ; return ("" + ((ans)))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(200000) def dfs(v): global node_chk global B global connect global value node_chk[v]=1 connect[v]=value for x in B[v]: if(node_chk[x]==0): dfs(x) n,m=map(int,input().split()) B=[[]for i in range(n)] node_chk=[0 for i in range(n)] connect=[0 for i in range(n)] value=0 for i in range(m): A=list(map(int,input().split())) B[A[0]].append(A[1]) B[A[1]].append(A[0]) for i in range(n): if(node_chk[i]==1): continue dfs(i) value+=1 q=int(input()) for i in range(q): start,target=map(int,input().split()) if(connect[start]==connect[target]): print("yes") else : print("no") ------------------------------------------------------------ OCL File: --------- class FromPython { attribute node_chk : OclAny; attribute B : OclAny; attribute connect : OclAny; attribute value : OclAny; operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(200000) ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; B := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; node_chk := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; connect := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; value := 0 ; for i : Integer.subrange(0, m-1) do ( var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (expr (atom (name B)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))) ; (expr (atom (name B)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))) ; for i : Integer.subrange(0, n-1) do ( if (node_chk[i+1] = 1) then ( continue ) else skip ; dfs(i) ; value := value + 1) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( var start : OclAny := null; var target : OclAny := null; Sequence{start,target} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (connect[start+1] = connect[target+1]) then ( execute ("yes")->display() ) else ( execute ("no")->display() )); operation dfs(v : OclAny) pre: true post: true activity: skip ; skip ; skip ; skip ; node_chk[v+1] := 1 ; connect[v+1] := value ; for x : B[v+1] do ( if (node_chk[x+1] = 0) then ( dfs(x) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict import sys sys.setrecursionlimit(1<<25) G=defaultdict(lambda :[]) N,M=map(int,input().split()) color={key : None for key in range(N)} for _ in range(M): s,t=map(int,input().split()) G[s].append(t) G[t].append(s) def dfs(node : int,co : int): if color[node]is not None : return color[node]=co for n in G[node]: dfs(n,co) return c=1 for node in G.keys(): dfs(node,c) c+=1 Q=int(input()) for _ in range(Q): s,t=map(int,input().split()) if(color[s]is not None)and(color[t]is not None)and(color[s]==color[t]): print('yes') else : print('no') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit(1 * (2->pow(25))) ; var G : OclAny := defaultdict(lambda $$ : OclAny in (Sequence{})) ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var color : Map := Integer.subrange(0, N-1)->select(key | true)->collect(key | Map{key |-> null})->unionAll() ; for _anon : Integer.subrange(0, M-1) do ( var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) )))) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))) ; skip ; var c : int := 1 ; for node : G.keys() do ( dfs(node, c) ; c := c + 1) ; var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, Q-1) do ( var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (not(color[s+1] <>= null)) & (not(color[t+1] <>= null)) & (color[s+1] = color[t+1]) then ( execute ('yes')->display() ) else ( execute ('no')->display() )); operation dfs(node : int, co : int) pre: true post: true activity: if not(color[node+1] <>= null) then ( return ) else skip ; color[node+1] := co ; for n : G[node+1] do ( dfs(n, co)) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class UnionSet : def __init__(self,num_node : int)->None : self.size=[1]*num_node self.id=[i for i in range(num_node+1)] def get_root(self,i : int)->int : while i!=self.id[i]: self.id[i]=self.id[self.id[i]] i=self.id[i] return i def is_connected(self,node1 : int,node2 : int)->bool : return self.get_root(node1)==self.get_root(node2) def unite(self,node1 : int,node2 : int)->None : i,j=self.get_root(node1),self.get_root(node2) if i==j : return if self.size[i]exists( _x | result = _x ); operation __init__(num_node : int) : OclAny pre: true post: true activity: self.size := MatrixLib.elementwiseMult(Sequence{ 1 }, num_node) ; self.id := Integer.subrange(0, num_node + 1-1)->select(i | true)->collect(i | (i)); operation get_root(i : int) : int pre: true post: true activity: while i /= self.id[i+1] do ( self.id[i+1] := self.id[self.id[i+1]+1] ; var i : OclAny := self.id[i+1]) ; return i; operation is_connected(node1 : int,node2 : int) : boolean pre: true post: true activity: return self.get_root(node1) = self.get_root(node2); operation unite(node1 : int,node2 : int) : OclAny pre: true post: true activity: var j : OclAny := null; Sequence{i,j} := Sequence{self.get_root(node1),self.get_root(node2)} ; if i = j then ( return ) else skip ; if (self.size[i+1]->compareTo(self.size[j+1])) < 0 then ( self.id[i+1] := j ; self.size[j+1] := self.size[j+1] + self.size[i+1] ) else ( self.id[j+1] := i ; self.size[i+1] := self.size[i+1] + self.size[j+1] ); } class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var num_users : OclAny := null; var num_relations : OclAny := null; Sequence{num_users,num_relations} := (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ) ; var union_set : UnionSet := (UnionSet.newUnionSet()).initialise(num_users) ; for _anon : Integer.subrange(0, num_relations-1) do ( var user1 : OclAny := null; var user2 : OclAny := null; Sequence{user1,user2} := (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ) ; union_set.unite(user1, user2)) ; var num_questions : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, num_questions-1) do ( var user1 : OclAny := null; var user2 : OclAny := null; Sequence{user1,user2} := (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ) ; if union_set.is_connected(user1, user2) then ( execute ("yes")->display() ) else ( execute ("no")->display() )) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(200000) input_lines=[[int(i)for i in line.split()]for line in sys.stdin.read().splitlines()] [user_num,rel_num]=input_lines[0] rel_list=input_lines[1 : rel_num+1] ques_num=input_lines[rel_num+1][0] ques_list=input_lines[rel_num+2 :] color_list=[-1]*user_num adja_list=[set()for i in range(user_num)] def dfs(id,color): if color_list[id]==-1 : color_list[id]=color for a_id in adja_list[id]: dfs(a_id,color) for rel in rel_list : adja_list[rel[0]].add(rel[1]) adja_list[rel[1]].add(rel[0]) color=0 for id in range(user_num): dfs(id,color) color+=1 for ques in ques_list : if color_list[ques[0]]==color_list[ques[1]]: print('yes') else : print('no') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(200000) ; var input_lines : Sequence := sys.stdin.readAll().splitlines()->select(line | true)->collect(line | (line.split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())))) ; Sequence{user_num}->union(Sequence{ rel_num }) := input_lines->first() ; var rel_list : OclAny := input_lines.subrange(1+1, rel_num + 1) ; var ques_num : OclAny := input_lines[rel_num + 1+1]->first() ; var ques_list : OclAny := input_lines.subrange(rel_num + 2+1) ; var color_list : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, user_num) ; var adja_list : Sequence := Integer.subrange(0, user_num-1)->select(i | true)->collect(i | (Set{}->union(()))) ; skip ; for rel : rel_list do ((expr (atom (name adja_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name rel)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name rel)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))) ; (expr (atom (name adja_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name rel)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name rel)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))) ; color := 0 ; for id : Integer.subrange(0, user_num-1) do ( dfs(id, color) ; color := color + 1) ; for ques : ques_list do ( if color_list[ques->first()+1] = color_list[ques[1+1]+1] then ( execute ('yes')->display() ) else ( execute ('no')->display() )); operation dfs(id : OclAny, color : OclAny) pre: true post: true activity: if color_list[id+1] = -1 then ( color_list[id+1] := color ; for a_id : adja_list[id+1] do ( dfs(a_id, color)) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- testCount=int(raw_input()) for testIndex in range(testCount): ans="Case #"+str(testIndex+1)+": " n=int(raw_input()) a=[] for i in range(n): a1,a2=[int(x)for x in raw_input().split(" ")] a+=[(a1,a2,2)] a.sort(key=lambda x : x[1]*10000+x[0]) star=0 count=0 for i in range(n): need=a[i][1]-star while need>0 : flag=True for j in range(n-1,i-1,-1): if a[j][2]==2 and star>=a[j][0]: a[j]=(a[j][0],a[j][1],1) need-=1 star+=1 count+=1 flag=False break if flag : break if need>0 : ans+="Too Bad" break star+=a[i][2] count+=1 if star==n*2 : ans+=str(count) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var testCount : int := ("" + ((raw_input())))->toInteger() ; for testIndex : Integer.subrange(0, testCount-1) do ( var ans : String := "Case #" + ("" + ((testIndex + 1))) + ": " ; var n : int := ("" + ((raw_input())))->toInteger() ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a1 : OclAny := null; var a2 : OclAny := null; Sequence{a1,a2} := raw_input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; a := a + Sequence{ Sequence{a1, a2, 2} }) ; a := a->sort() ; var star : int := 0 ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( var need : double := a[i+1][1+1] - star ; while need > 0 do ( var flag : boolean := true ; for j : Integer.subrange(i - 1 + 1, n - 1)->reverse() do ( if a[j+1][2+1] = 2 & (star->compareTo(a[j+1]->first())) >= 0 then ( a[j+1] := Sequence{a[j+1]->first(), a[j+1][1+1], 1} ; need := need - 1 ; star := star + 1 ; count := count + 1 ; flag := false ; break ) else skip) ; if flag then ( break ) else skip) ; if need > 0 then ( ans := ans + "Too Bad" ; break ) else skip ; star := star + a[i+1][2+1] ; count := count + 1) ; if star = n * 2 then ( ans := ans + ("" + ((count))) ) else skip ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def work(A,B,NL): res=0 pts=0 S=[0]*NL R2=0 while True : cont=True while cont : cont=False for k in range(NL): if S[k]<2 and B[k]<=pts : cont=True pts+=(2-S[k]) S[k]=2 res+=1 R2+=1 if R2==NL : return res cont=False Sel=[k for k in range(NL)if S[k]==0 and A[k]<=pts] if len(Sel)==0 : return 'Too Bad' k=max(Sel,key=lambda i : B[i]) pts+=1 res+=1 S[k]=1 T=int(raw_input()) for k in range(1,T+1): NL=int(raw_input()) A=[0]*NL B=[0]*NL for i in range(NL): A[i],B[i]=map(int,raw_input().split()) print('Case #{}:{}'.format(k,work(A,B,NL))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var T : int := ("" + ((raw_input())))->toInteger() ; for k : Integer.subrange(1, T + 1-1) do ( NL := ("" + ((raw_input())))->toInteger() ; A := MatrixLib.elementwiseMult(Sequence{ 0 }, NL) ; B := MatrixLib.elementwiseMult(Sequence{ 0 }, NL) ; for i : Integer.subrange(0, NL-1) do ( var A[i+1] : OclAny := null; var B[i+1] : OclAny := null; Sequence{A[i+1],B[i+1]} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (StringLib.interpolateStrings('Case #{}:{}', Sequence{k, work(A, B, NL)}))->display()); operation work(A : OclAny, B : OclAny, NL : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; var pts : int := 0 ; var S : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, NL) ; var R2 : int := 0 ; while true do ( var cont : boolean := true ; while cont do ( cont := false ; for k : Integer.subrange(0, NL-1) do ( if S[k+1] < 2 & (B[k+1]->compareTo(pts)) <= 0 then ( cont := true ; pts := pts + (2 - S[k+1]) ; S[k+1] := 2 ; res := res + 1 ; R2 := R2 + 1 ; if R2 = NL then ( return res ) else skip ) else skip)) ; cont := false ; var Sel : Sequence := Integer.subrange(0, NL-1)->select(k | S[k+1] = 0 & (A[k+1]->compareTo(pts)) <= 0)->collect(k | (k)) ; if (Sel)->size() = 0 then ( return 'Too Bad' ) else skip ; var k : OclAny := Set{Sel, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name i)))) : (test (logical_test (comparison (expr (atom (name B)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))}->max() ; pts := pts + 1 ; res := res + 1 ; S[k+1] := 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import argv infile=open(argv[1]) cases=int(infile.readline()) for i in range(cases): n=int(infile.readline()) needed=[] for j in range(n): needed.append(list(map(int,infile.readline().split()))) games=0 stars=0 earned=[0 for j in range(n)] toobad=False games=0 while stars<2*n : level=None earn=0 mostneeded=-1 spam=True for j in range(n): if stars>=needed[j][1]and earned[j]==0 : level=j earn=2 break elif stars>=needed[j][1]and earned[j]==1 : level=j earn=1 spam=False elif spam and stars>=needed[j][0]and earned[j]==0 and needed[j][1]>mostneeded : level=j earn=1 mostneeded=needed[j][1] if earn==2 : earned[level]=2 stars+=2 elif earn==1 : earned[level]+=1 stars+=1 else : toobad=True break games+=1 if toobad : print('Case #{}: Too Bad'.format(i+1)) else : print('Case #{}:{}'.format(i+1,games)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var infile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(argv[1+1])) ; var cases : int := ("" + ((infile.readLine())))->toInteger() ; for i : Integer.subrange(0, cases-1) do ( var n : int := ("" + ((infile.readLine())))->toInteger() ; var needed : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( execute ((((infile.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) : needed)) ; var games : int := 0 ; var stars : int := 0 ; var earned : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (0)) ; var toobad : boolean := false ; games := 0 ; while (stars->compareTo(2 * n)) < 0 do ( var level : OclAny := null ; var earn : int := 0 ; var mostneeded : int := -1 ; var spam : boolean := true ; for j : Integer.subrange(0, n-1) do ( if (stars->compareTo(needed[j+1][1+1])) >= 0 & earned[j+1] = 0 then ( level := j ; earn := 2 ; break ) else (if (stars->compareTo(needed[j+1][1+1])) >= 0 & earned[j+1] = 1 then ( level := j ; earn := 1 ; spam := false ) else (if spam & (stars->compareTo(needed[j+1]->first())) >= 0 & earned[j+1] = 0 & (needed[j+1][1+1]->compareTo(mostneeded)) > 0 then ( level := j ; earn := 1 ; mostneeded := needed[j+1][1+1] ) else skip ) ) ) ; if earn = 2 then ( earned[level+1] := 2 ; stars := stars + 2 ) else (if earn = 1 then ( earned[level+1] := earned[level+1] + 1 ; stars := stars + 1 ) else ( toobad := true ; break ) ) ; games := games + 1) ; if toobad then ( execute (StringLib.interpolateStrings('Case #{}: Too Bad', Sequence{i + 1}))->display() ) else ( execute (StringLib.interpolateStrings('Case #{}:{}', Sequence{i + 1, games}))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from Queue import PriorityQueue with open('B-large.in','r')as fin : with open('output.txt','w')as fout : numcases=int(fin.readline()) for i in range(1,numcases+1): line=[int(j)for j in fin.readline().split()] numlevels=line[0] doables=[] levels=PriorityQueue() for j in range(numlevels): line=[int(k)for k in fin.readline().split()] levels.put((line[0],line[1])) stars=0 played=0 while True : while not levels.empty(): nextlevel=levels.get() if nextlevel[0]<=stars : if nextlevel[1]==None : played+=1 stars+=1 else : doables.append(nextlevel[1]) else : levels.put(nextlevel) break doables.sort() if len(doables)==0 : if not levels.empty(): played=-1 break else : lowlevel=doables[0] played+=1 if lowlevel<=stars : stars+=2 doables=doables[1 :] else : stars+=1 levels.put((doables[-1],None)) del doables[-1] fout.write("Case #") fout.write(str(i)) fout.write(": ") if(played>=0): fout.write(str(played)) else : fout.write("Too Bad") fout.write('\n') print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; try (var fin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('B-large.in')); try (var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('output.txt')); var numcases : int := ("" + ((fin.readLine())))->toInteger() ; for i : Integer.subrange(1, numcases + 1-1) do ( var line : Sequence := fin.readLine().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; var numlevels : OclAny := line->first() ; var doables : Sequence := Sequence{} ; var levels : OclAny := PriorityQueue() ; for j : Integer.subrange(0, numlevels-1) do ( line := fin.readLine().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger())) ; levels.put(Sequence{line->first(), line[1+1]})) ; var stars : int := 0 ; var played : int := 0 ; while true do ( while not(levels.empty()) do ( var nextlevel : OclAny := levels.get() ; if (nextlevel->first()->compareTo(stars)) <= 0 then ( if nextlevel[1+1] = null then ( played := played + 1 ; stars := stars + 1 ) else ( execute ((nextlevel[1+1]) : doables) ) ) else ( levels.put(nextlevel) ; break )) ; doables := doables->sort() ; if (doables)->size() = 0 then ( if not(levels.empty()) then ( played := -1 ) else skip ; break ) else ( var lowlevel : OclAny := doables->first() ; played := played + 1 ; if (lowlevel->compareTo(stars)) <= 0 then ( stars := stars + 2 ; doables := doables->tail() ) else ( stars := stars + 1 ; levels.put(Sequence{doables->last(), null}) ; execute (doables->last())->isDeleted() ) )) ; fout.write("Case #") ; fout.write(("" + ((i)))) ; fout.write(": ") ; if (played >= 0) then ( fout.write(("" + ((played)))) ) else ( fout.write("Too Bad") ) ; fout.write(' ') ; execute (i)->display())) catch (_e : OclException) do skip) catch (_e : OclException) do skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def input(): with open('b.in')as file : tests_count=int(file.readline().strip()) for i in xrange(tests_count): levels_count=int(file.readline().strip()) levels_requirements=[] for j in xrange(levels_count): levels_requirements.append(tuple(int(n)for n in file.readline().strip().split())) yield levels_requirements def output(answers): with open('b.out','w')as file : for i,answer in enumerate(answers): file.write('Case #%s: %s\n' %(i+1,answer)) def choose_level(levels_requirements,levels_solved,stars_earned): for i in xrange(len(levels_requirements)): result=levels_solved[i] if result<2 : if levels_requirements[i][1]<=stars_earned : levels_solved[i]=2 return 2-result candidate_i=-1 maximum_2_stars=-1 for i in xrange(len(levels_requirements)): result=levels_solved[i] if result==0 : if levels_requirements[i][0]<=stars_earned : if levels_requirements[i][1]>maximum_2_stars : maximum_2_stars=levels_requirements[i][1] candidate_i=i if candidate_i==-1 : return 0 levels_solved[candidate_i]=1 return 1 def solve(levels_requirements): levels_solved=[0]*len(levels_requirements) stars_earned=0 games_played=0 while True : if all(l==2 for l in levels_solved): return games_played new_stars=choose_level(levels_requirements,levels_solved,stars_earned) if not new_stars : return 'Too Bad' else : stars_earned+=new_stars games_played+=1 def main(): answers=(solve(levels_requirements)for levels_requirements in input()) output(answers) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation input(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; try (var file : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('b.in')); var tests_count : int := ("" + ((file.readLine()->trim())))->toInteger() ; for i : xrange(tests_count) do ( var levels_count : int := ("" + ((file.readLine()->trim())))->toInteger() ; var levels_requirements : Sequence := Sequence{} ; for j : xrange(levels_count) do ( execute ((((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name file)) (trailer . (name readline) (arguments ( ))) (trailer . (name strip) (arguments ( ))) (trailer . (name split) (arguments ( )))))))))) : levels_requirements)) ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return levels_requirements)) catch (_e : OclException) do skip; operation output(answers : OclAny) pre: true post: true activity: try (var file : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('b.out')); for _tuple : Integer.subrange(1, (answers)->size())->collect( _indx | Sequence{_indx-1, (answers)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var answer : OclAny := _tuple->at(_indx); file.write(StringLib.format('Case #%s: %s ',Sequence{i + 1, answer})))) catch (_e : OclException) do skip; operation choose_level(levels_requirements : OclAny, levels_solved : OclAny, stars_earned : OclAny) : OclAny pre: true post: true activity: for i : xrange((levels_requirements)->size()) do ( var result : OclAny := levels_solved[i+1] ; if result < 2 then ( if (levels_requirements[i+1][1+1]->compareTo(stars_earned)) <= 0 then ( levels_solved[i+1] := 2 ; return 2 - result ) else skip ) else skip) ; var candidate_i : int := -1 ; var maximum:= -1_stars : int := -1 ; for i : xrange((levels_requirements)->size()) do ( result := levels_solved[i+1] ; if result = 0 then ( if (levels_requirements[i+1]->first()->compareTo(stars_earned)) <= 0 then ( if (levels_requirements[i+1][1+1]->compareTo(maximum maximum:= levels_requirements[i+1][1+1]_stars := levels_requirements[i+1][1+1] ; candidate_i := i_stars)) > 0 then ( maximum:= levels_requirements[i+1][1+1]_stars := levels_requirements[i+1][1+1] ; candidate_i := i ) else skip ) else skip ) else skip) ; if candidate_i = -1 then ( return 0 ) else skip ; levels_solved[candidate_i+1] := 1 ; return 1; operation solve(levels_requirements : OclAny) : OclAny pre: true post: true activity: levels_solved := MatrixLib.elementwiseMult(Sequence{ 0 }, (levels_requirements)->size()) ; stars_earned := 0 ; var games_played : int := 0 ; while true do ( if ((argument (test (logical_test (comparison (comparison (expr (atom (name l)))) == (comparison (expr (atom (number (integer 2)))))))) (comp_for for (exprlist (expr (atom (name l)))) in (logical_test (comparison (expr (atom (name levels_solved))))))))->forAll( _x | _x = true ) then ( return games_played ) else skip ; var new_stars : OclAny := choose_level(levels_requirements, levels_solved, stars_earned) ; if not(new_stars) then ( return 'Too Bad' ) else ( stars_earned := stars_earned + new_stars ; games_played := games_played + 1 )); operation main() pre: true post: true activity: answers := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name solve)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name levels_requirements)))))))) ))))))) (comp_for for (exprlist (expr (atom (name levels_requirements)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))} ; output(answers); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y,tx,ty=map(int,input().split()) tx,ty=tx-x,ty-y s=ty*'U'+tx*'R'+ty*'D'+tx*'L' s1='L'+'U'*(ty+1)+'R'*(tx+1)+'D'+'R'+(ty+1)*'D'+'L'*(tx+1)+'U' print(s+s1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; var tx : OclAny := null; var ty : OclAny := null; Sequence{x,y,tx,ty} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var tx : OclAny := null; var ty : OclAny := null; Sequence{tx,ty} := Sequence{tx - x,ty - y} ; var s : double := ty * 'U' + tx * 'R' + ty * 'D' + tx * 'L' ; var s1 : String := 'L' + StringLib.nCopies('U', (ty + 1)) + StringLib.nCopies('R', (tx + 1)) + 'D' + 'R' + (ty + 1) * 'D' + StringLib.nCopies('L', (tx + 1)) + 'U' ; execute (s + s1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- SCORE=[] n=int(input()) for i in range(n): BASE=[False]*3 OUTcount=0 preSCORE=0 while OUTcount<3 : spam=input() if 'HIT' in spam : if BASE[2]==True : preSCORE+=1 BASE[2]=BASE[1] BASE[1]=BASE[0] BASE[0]=True elif 'OUT' in spam : OUTcount+=1 elif 'HOMERUN' in spam : preSCORE+=sum(x for x in BASE)+1 BASE=[False]*3 SCORE.append(preSCORE) for i in SCORE : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var SCORE : Sequence := Sequence{} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var BASE : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, 3) ; var OUTcount : int := 0 ; var preSCORE : int := 0 ; while OUTcount < 3 do ( var spam : String := (OclFile["System.in"]).readLine() ; if (spam)->characters()->includes('HIT') then ( if BASE[2+1] = true then ( preSCORE := preSCORE + 1 ) else skip ; BASE[2+1] := BASE[1+1] ; BASE[1+1] := BASE->first() ; BASE->first() := true ) else (if (spam)->characters()->includes('OUT') then ( OUTcount := OUTcount + 1 ) else (if (spam)->characters()->includes('HOMERUN') then ( preSCORE := preSCORE + ((argument (test (logical_test (comparison (expr (atom (name x)))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name BASE))))))))->sum() + 1 ; BASE := MatrixLib.elementwiseMult(Sequence{ false }, 3) ) else skip ) ) ) ; execute ((preSCORE) : SCORE)) ; for i : SCORE do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from typing import List,Tuple from collections import defaultdict,deque,namedtuple from heapq import heappush as push,heappop as pop import sys INF=(int)(1e9+7) sys.setrecursionlimit(INF) def solve(n): res=0 power=1 while n : digit=n % 10 n=n//10 if n!=0 and digit>=5 : res+=((9-digit)*(power)) else : if digit==9 or digit<5 : res+=(digit*(power)) else : res+=((9-digit)*(power)) power*=10 return res if __name__=="__main__" : n=int(input()) print(solve(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var INF : OclAny := (OclType["int"])(("1e9")->toReal() + 7) ; sys.setrecursionlimit(INF) ; skip ; if __name__ = "__main__" then ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (solve(n))->display() ) else skip; operation solve(n : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; var power : int := 1 ; while n do ( var digit : int := n mod 10 ; n := n div 10 ; if n /= 0 & digit >= 5 then ( res := res + ((9 - digit) * (power)) ) else ( if digit = 9 or digit < 5 then ( res := res + (digit * (power)) ) else ( res := res + ((9 - digit) * (power)) ) ) ; power := power * 10) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t,c=map(int,input().split()); x=0 ; z=0 for i in map(int,input().split()): if i<=t : x+=1 else : x=0 if x>=c : z+=1 print(z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; var c : OclAny := null; Sequence{n,t,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var x : int := 0; var z : int := 0 ; for i : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( if (i->compareTo(t)) <= 0 then ( x := x + 1 ) else ( x := 0 ) ; if (x->compareTo(c)) >= 0 then ( z := z + 1 ) else skip) ; execute (z)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from collections import defaultdict sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod=10**9+7 def I(): return int(input()) def II(): return map(int,input().split()) def III(): return list(map(int,input().split())) def Line(N): read_all=[tuple(map(int,input().split()))for _ in range(N)] return map(list,zip(*read_all)) sx,sy,tx,ty=II() move=['U']*(ty-sy)+['R']*(tx-sx)+['D']*(ty-sy)+['L']*(tx-sx) move2=['L']+['U']*(ty-sy+1)+['R']*(tx-sx+1)+['D']+['R']+['D']*(ty-sy+1)+['L']*(tx-sx+1)+['U'] ans=move+move2 print(*ans,sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; var sx : OclAny := null; var sy : OclAny := null; var tx : OclAny := null; var ty : OclAny := null; Sequence{sx,sy,tx,ty} := II() ; var move : Sequence := MatrixLib.elementwiseMult(Sequence{ 'U' }, (ty - sy))->union(MatrixLib.elementwiseMult(Sequence{ 'R' }, (tx - sx)))->union(MatrixLib.elementwiseMult(Sequence{ 'D' }, (ty - sy)))->union(MatrixLib.elementwiseMult(Sequence{ 'L' }, (tx - sx))) ; var move2 : Sequence := Sequence{ 'L' }->union(MatrixLib.elementwiseMult(Sequence{ 'U' }, (ty - sy + 1)))->union(MatrixLib.elementwiseMult(Sequence{ 'R' }, (tx - sx + 1)))->union(Sequence{ 'D' })->union(Sequence{ 'R' })->union(MatrixLib.elementwiseMult(Sequence{ 'D' }, (ty - sy + 1)))->union(MatrixLib.elementwiseMult(Sequence{ 'L' }, (tx - sx + 1)))->union(Sequence{ 'U' }) ; var ans : Sequence := move->union(move2) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation II() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation III() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation Line(N : OclAny) : OclAny pre: true post: true activity: var read_all : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; return (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name read_all)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name read_all)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name read_all)))))))`third->at(_indx)} ))->collect( _x | (OclType["Sequence"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=map(int,input().split()) x=c-a y=d-b s="" for i in range(y): s+="U" for i in range(x): s+="R" for i in range(y): s+="D" for i in range(x+1): s+="L" for i in range(y+1): s+="U" for i in range(x+1): s+="R" s+="DR" for i in range(y+1): s+="D" for i in range(x+1): s+="L" s+="U" print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : double := c - a ; var y : double := d - b ; var s : String := "" ; for i : Integer.subrange(0, y-1) do ( s := s + "U") ; for i : Integer.subrange(0, x-1) do ( s := s + "R") ; for i : Integer.subrange(0, y-1) do ( s := s + "D") ; for i : Integer.subrange(0, x + 1-1) do ( s := s + "L") ; for i : Integer.subrange(0, y + 1-1) do ( s := s + "U") ; for i : Integer.subrange(0, x + 1-1) do ( s := s + "R") ; s := s + "DR" ; for i : Integer.subrange(0, y + 1-1) do ( s := s + "D") ; for i : Integer.subrange(0, x + 1-1) do ( s := s + "L") ; s := s + "U" ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): sx,sy,tx,ty=map(int,input().split()) print(''.join(['U'*(ty-sy),'R'*(tx-sx),'D'*(ty-sy),'L'*(tx-sx+1),'U'*(ty-sy+1),'R'*(tx-sx+1),'D','R','D'*(ty-sy+1),'L'*(tx-sx+1),]))DEDENT if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; operation main() pre: true post: true activity: var sx : OclAny := null; var sy : OclAny := null; var tx : OclAny := null; var ty : OclAny := null; Sequence{sx,sy,tx,ty} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (StringLib.sumStringsWithSeparator((Sequence{StringLib.nCopies('U', (ty - sy))}->union(Sequence{StringLib.nCopies('R', (tx - sx))}->union(Sequence{StringLib.nCopies('D', (ty - sy))}->union(Sequence{StringLib.nCopies('L', (tx - sx + 1))}->union(Sequence{StringLib.nCopies('U', (ty - sy + 1))}->union(Sequence{StringLib.nCopies('R', (tx - sx + 1))}->union(Sequence{'D'}->union(Sequence{'R'}->union(Sequence{StringLib.nCopies('D', (ty - sy + 1))}->union(Sequence{ StringLib.nCopies('L', (tx - sx + 1)) })))))))))), ''))->display() ; testlist_star_expr`updateFormDEDENT ; if __name__ = "__main__" then ( main() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sx,sy,tx,ty=map(int,input().split()) ans="" ans+="U"*(ty-sy) ans+="R"*(tx-sx) ans+="D"*(ty-sy) ans+="L"*(tx-sx) ans+="L" ans+="U"*(ty-sy+1) ans+="R"*(tx-sx+1) ans+="D" ans+="R" ans+="D"*(ty-sy+1) ans+="L"*(tx-sx+1) ans+="U" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sx : OclAny := null; var sy : OclAny := null; var tx : OclAny := null; var ty : OclAny := null; Sequence{sx,sy,tx,ty} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : String := "" ; ans := ans + StringLib.nCopies("U", (ty - sy)) ; ans := ans + StringLib.nCopies("R", (tx - sx)) ; ans := ans + StringLib.nCopies("D", (ty - sy)) ; ans := ans + StringLib.nCopies("L", (tx - sx)) ; ans := ans + "L" ; ans := ans + StringLib.nCopies("U", (ty - sy + 1)) ; ans := ans + StringLib.nCopies("R", (tx - sx + 1)) ; ans := ans + "D" ; ans := ans + "R" ; ans := ans + StringLib.nCopies("D", (ty - sy + 1)) ; ans := ans + StringLib.nCopies("L", (tx - sx + 1)) ; ans := ans + "U" ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib,fractions,itertools def compute(): LIMIT=10**8 ans=0 isprime=eulerlib.list_primality(LIMIT-1) for x in range(1,LIMIT//4+1): for y in itertools.count(1): a=x*y*y-1 if a>=LIMIT : break if not isprime[a]: continue for z in itertools.count(y+1): if fractions.gcd(y,z)!=1 : continue c=x*z*z-1 if c>=LIMIT : break if isprime[c]: b=x*y*z-1 if isprime[b]: ans+=a+b+c return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LIMIT : double := (10)->pow(8) ; var ans : int := 0 ; var isprime : OclAny := eulerlib.list_primality(LIMIT - 1) ; for x : Integer.subrange(1, LIMIT div 4 + 1-1) do ( for y : itertools->count(1) do ( var a : double := x * y * y - 1 ; if (a->compareTo(LIMIT)) >= 0 then ( break ) else skip ; if not(isprime[a+1]) then ( continue ) else skip ; for z : itertools->count(y + 1) do ( if fractions.gcd(y, z) /= 1 then ( continue ) else skip ; var c : double := x * z * z - 1 ; if (c->compareTo(LIMIT)) >= 0 then ( break ) else skip ; if isprime[c+1] then ( var b : double := x * y * z - 1 ; if isprime[b+1] then ( ans := ans + a + b + c ) else skip ) else skip))) ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def maxSubArraySum(a,size): max_so_far=-(sys.maxsize-1) max_ending_here=0 for i in range(size): max_ending_here=max_ending_here+a[i] if(max_so_farunion(Sequence{32}->union(Sequence{-24}->union(Sequence{0}->union(Sequence{27}->union(Sequence{-10}->union(Sequence{0}->union(Sequence{ -19 }))))))) ; n := (a)->size() ; execute (maxSum(a, n))->display() ) else skip; operation maxSubArraySum(a : OclAny, size : OclAny) : OclAny pre: true post: true activity: var max_so_far : double := -((trailer . (name maxsize)) - 1) ; var max_ending_here : int := 0 ; for i : Integer.subrange(0, size-1) do ( max_ending_here := max_ending_here + a[i+1] ; if ((max_so_far->compareTo(max_ending_here)) < 0) then ( max_so_far := max_ending_here ) else skip ; if (max_ending_here < 0) then ( max_ending_here := 0 ) else skip) ; return max_so_far; operation maxSum(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var S : int := 0; ; var S1 : OclAny := maxSubArraySum(a, n) ; for i : Integer.subrange(0, n-1) do ( S := S + a[i+1]) ; return (2 * S1 - S); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cmp(a,b): return(a>b)-(aunion(Sequence{4}->union(Sequence{2}->union(Sequence{10}->union(Sequence{7}->union(Sequence{8}->union(Sequence{8}->union(Sequence{1}->union(Sequence{ 9 })))))))) ; execute (maxSubarraySize(arr))->display(); operation cmp(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return ((a->compareTo(b)) > 0) - ((a->compareTo(b)) < 0); operation maxSubarraySize(arr : OclAny) : OclAny pre: true post: true activity: var N : int := (arr)->size() ; var ans : int := 1 ; var anchor : int := 0 ; for i : Integer.subrange(1, N-1) do ( var c : OclAny := cmp(arr[i - 1+1], arr[i+1]) ; if c = 0 then ( anchor := i ) else (if i = N - 1 or c * cmp(arr[i+1], arr[i + 1+1]) /= -1 then ( ans := Set{ans, i - anchor + 1}->max() ; anchor := i ) else skip)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPossible(a,n): cur=a[0]; cur-=1 ; for i in range(1,n): nxt=a[i]; if(nxt>cur): nxt-=1 ; elif(nxtunion(Sequence{2}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })))); ; n := (a)->size(); ; if (isPossible(a, n)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ) else skip; operation isPossible(a : OclAny, n : OclAny) pre: true post: true activity: var cur : OclAny := a->first(); ; cur := cur - 1; ; for i : Integer.subrange(1, n-1) do ( var nxt : OclAny := a[i+1]; ; if ((nxt->compareTo(cur)) > 0) then ( nxt := nxt - 1; ) else (if ((nxt->compareTo(cur)) < 0) then ( return false; ) else skip) ; cur := nxt;) ; return true;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import reduce a=int(input()) if a<=4 : print(4) elif a>4 and a<=8 : print(8) elif a<10 : print(13) else : while True : b=(reduce(lambda x,y : int(x)+int(y),str(a))) if b % 4==0 : break a+=1 print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if a <= 4 then ( execute (4)->display() ) else (if a > 4 & a <= 8 then ( execute (8)->display() ) else (if a < 10 then ( execute (13)->display() ) else ( while true do ( var b : OclAny := (reduce(lambda x : OclAny, y : OclAny in (("" + ((x)))->toInteger() + ("" + ((y)))->toInteger()), ("" + ((a))))) ; if b mod 4 = 0 then ( break ) else skip ; a := a + 1) ; execute (a)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) L=list(map(int,input().split())) mini=L[0] n=1 if N>1 : for i in range(N-1): if mini>L[i+1]: n=n+1 mini=L[i+1] print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var L : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mini : OclAny := L->first() ; var n : int := 1 ; if N > 1 then ( for i : Integer.subrange(0, N - 1-1) do ( if (mini->compareTo(L[i + 1+1])) > 0 then ( n := n + 1 ; mini := L[i + 1+1] ) else skip) ) else skip ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=0 for i in range(n,n*10): s=str(i) s=sum([int(j)for j in s]) if(s % 4==0): print(i) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : int := 0 ; for i : Integer.subrange(n, n * 10-1) do ( s := ("" + ((i))) ; s := (s->select(j | true)->collect(j | (("" + ((j)))->toInteger())))->sum() ; if (s mod 4 = 0) then ( execute (i)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,b,a=map(int,input().split()); x=0 ; z=0 ans=0 l=list(map(int,input().split())) l2=[] for i in range(n): if l[i]<=b : x+=1 else : x=0 if(x>=a): ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var b : OclAny := null; var a : OclAny := null; Sequence{n,b,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var x : int := 0; var z : int := 0 ; var ans : int := 0 ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l2 : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if (l[i+1]->compareTo(b)) <= 0 then ( x := x + 1 ) else ( x := 0 ) ; if ((x->compareTo(a)) >= 0) then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) while(1): t=str(a) p=0 for i in t : p+=int(i) if p % 4==0 : break a+=1 print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (1) do ( var t : String := ("" + ((a))) ; var p : int := 0 ; for i : t->characters() do ( p := p + ("" + ((i)))->toInteger()) ; if p mod 4 = 0 then ( break ) else skip ; a := a + 1) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) sum1=-1 while(sum1 % 4!=0): sum1=0 for i in str(n): sum1+=int(i) if(sum1 % 4!=0): n+=1 print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sum1 : int := -1 ; while (sum1 mod 4 /= 0) do ( sum1 := 0 ; for i : ("" + ((n))) do ( sum1 := sum1 + ("" + ((i)))->toInteger()) ; if (sum1 mod 4 /= 0) then ( n := n + 1 ) else skip) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isdg(n): s=0 while n>0 : s+=n % 10 n//=10 return s % 4==0 a=int(input()) while not isdg(a): a+=1 print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while not(isdg(a)) do ( a := a + 1) ; execute (a)->display(); operation isdg(n : OclAny) : OclAny pre: true post: true activity: var s : int := 0 ; while n > 0 do ( s := s + n mod 10 ; n := n div 10) ; return s mod 4 = 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) list2=[] list2=map(int,input().split()) ch=0 bi=0 ba=0 list1=[] if 1<=a<=20 : for i in list2 : list1.append(i) while True : if len(list1)==0 : break else : ch+=int(list1[0]) list1.pop(0) if len(list1)==0 : break else : bi+=int(list1[0]) list1.pop(0) if len(list1)==0 : break else : ba+=int(list1[0]) list1.pop(0) if bi>=ba and bi>=ch : print("biceps") elif ba>=bi and ba>=ch : print("back") elif ch>=ba and ch>bi : print("chest") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var list2 : Sequence := Sequence{} ; list2 := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ch : int := 0 ; var bi : int := 0 ; var ba : int := 0 ; var list1 : Sequence := Sequence{} ; if 1 <= a & (a <= 20) then ( for i : list2 do ( execute ((i) : list1)) ; while true do ( if (list1)->size() = 0 then ( break ) else ( ch := ch + ("" + ((list1->first())))->toInteger() ; list1 := list1->excludingAt(0+1) ; if (list1)->size() = 0 then ( break ) else ( bi := bi + ("" + ((list1->first())))->toInteger() ; list1 := list1->excludingAt(0+1) ; if (list1)->size() = 0 then ( break ) else ( ba := ba + ("" + ((list1->first())))->toInteger() ; list1 := list1->excludingAt(0+1) ) ) )) ; if (bi->compareTo(ba)) >= 0 & (bi->compareTo(ch)) >= 0 then ( execute ("biceps")->display() ) else (if (ba->compareTo(bi)) >= 0 & (ba->compareTo(ch)) >= 0 then ( execute ("back")->display() ) else (if (ch->compareTo(ba)) >= 0 & (ch->compareTo(bi)) > 0 then ( execute ("chest")->display() ) else skip ) ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : n=int(input()) exercises=list(map(int,input().split())) types_of_exercises=[0,0,0] i=0 type=0 while itoInteger() ; var exercises : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var types_of_exercises : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) ; var i : int := 0 ; var type : int := 0 ; while (i->compareTo(n)) < 0 do ( if type = 3 then ( type := 0 ) else skip ; types_of_exercises[type+1] := types_of_exercises[type+1] + exercises[i+1] ; i := i + 1 ; type := type + 1) ; type := types_of_exercises->indexOf((types_of_exercises)->max()) - 1 ; if type = 0 then ( execute ("chest")->display() ) else (if type = 1 then ( execute ("biceps")->display() ) else ( execute ("back")->display() ) ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- exercises=int(input()) array=list(map(int,input().split())) counter=1 chest=0 biceps=0 back=0 for i in array : if counter==4 : counter=1 if counter==1 : chest+=i elif counter==2 : biceps+=i elif counter==3 : back+=i counter+=1 if chest>biceps and chest>back : print("chest") elif biceps>chest and biceps>back : print("biceps") elif back>chest and back>biceps : print("back") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var exercises : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var array : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var counter : int := 1 ; var chest : int := 0 ; var biceps : int := 0 ; var back : int := 0 ; for i : array do ( if counter = 4 then ( counter := 1 ) else skip ; if counter = 1 then ( chest := chest + i ) else (if counter = 2 then ( biceps := biceps + i ) else (if counter = 3 then ( back := back + i ) else skip ) ) ; counter := counter + 1) ; if (chest->compareTo(biceps)) > 0 & (chest->compareTo(back)) > 0 then ( execute ("chest")->display() ) else (if (biceps->compareTo(chest)) > 0 & (biceps->compareTo(back)) > 0 then ( execute ("biceps")->display() ) else (if (back->compareTo(chest)) > 0 & (back->compareTo(biceps)) > 0 then ( execute ("back")->display() ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lenz=int(input()) arr=input() arr=arr.split(" ") arr=[int(x)for x in arr] train={'chest' : 0,'biceps' : 0,'back' : 0} j=1 for i in range(lenz): if j==1 : if "chest" in train : train['chest']+=arr[i] else : train['chest']=0 train['chest']+=arr[i] j=2 elif j==2 : if 'biceps' in train : train['biceps']+=arr[i] else : train['biceps']=0 train['biceps']+=arr[i] j=3 else : if 'back' in train : train['back']+=arr[i] else : train['back']=0 train['back']+=arr[i] j=1 maxx=max(train['chest'],train['biceps'],train['back']) if maxx==train['chest']: print("chest") elif maxx==train['biceps']: print("biceps") else : print("back") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lenz : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : String := (OclFile["System.in"]).readLine() ; arr := arr.split(" ") ; arr := arr->characters()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var train : Map := Map{ 'chest' |-> 0 }->union(Map{ 'biceps' |-> 0 }->union(Map{ 'back' |-> 0 })) ; var j : int := 1 ; for i : Integer.subrange(0, lenz-1) do ( if j = 1 then ( if (train)->includes("chest") then ( train->at('chest') := train->at('chest') + arr[i+1] ) else ( train->at('chest') := 0 ; train->at('chest') := train->at('chest') + arr[i+1] ) ; j := 2 ) else (if j = 2 then ( if (train)->includes('biceps') then ( train->at('biceps') := train->at('biceps') + arr[i+1] ) else ( train->at('biceps') := 0 ; train->at('biceps') := train->at('biceps') + arr[i+1] ) ; j := 3 ) else ( if (train)->includes('back') then ( train->at('back') := train->at('back') + arr[i+1] ) else ( train->at('back') := 0 ; train->at('back') := train->at('back') + arr[i+1] ) ; j := 1 ) ) ) ; var maxx : OclAny := Set{train->at('chest'), train->at('biceps'), train->at('back')}->max() ; if maxx = train->at('chest') then ( execute ("chest")->display() ) else (if maxx = train->at('biceps') then ( execute ("biceps")->display() ) else ( execute ("back")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) *x,=map(int,input().split()) a=sum(x[: : 3]); b=sum(x[1 : : 3]); c=sum(x[2 : : 3]) y=[a,b,c] if max(y)==a : print('chest') elif max(y)==b : print('biceps') elif max(y)==c : print('back') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (testlist_star_expr (star_expr * (expr (atom (name x)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name x)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := (x(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 3))))))))))->sum(); var b : OclAny := (x(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 3))))))))))->sum(); var c : OclAny := (x(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 3))))))))))->sum() ; var y : Sequence := Sequence{a}->union(Sequence{b}->union(Sequence{ c })) ; if (y)->max() = a then ( execute ('chest')->display() ) else (if (y)->max() = b then ( execute ('biceps')->display() ) else (if (y)->max() = c then ( execute ('back')->display() ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def smaller(a,b): if a>b : return b else : return a N=int(input()) P=list(map(int,input().split())) res=0 S=[P[0]] for i in range(1,N): S.append(smaller(S[i-1],P[i])) for i in range(N): if P[i]==S[i]: res+=1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var P : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : int := 0 ; var S : Sequence := Sequence{ P->first() } ; for i : Integer.subrange(1, N-1) do ( execute ((smaller(S[i - 1+1], P[i+1])) : S)) ; for i : Integer.subrange(0, N-1) do ( if P[i+1] = S[i+1] then ( res := res + 1 ) else skip) ; execute (res)->display(); operation smaller(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a->compareTo(b)) > 0 then ( return b ) else ( return a ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy BIG_NUM=2000000000 HUGE_NUM=99999999999999999 MOD=1000000007 EPS=0.000000001 sys.setrecursionlimit(100000) tmp_str=input() print(tmp_str[: :-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var HUGE_NUM : int := 99999999999999999 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; sys.setrecursionlimit(100000) ; var tmp_str : String := (OclFile["System.in"]).readLine() ; execute (tmp_str(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): s=list(input()) for x in range(len(s)-1,-1,-1): print(s[x],end="") print() if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; for x : Integer.subrange(-1 + 1, (s)->size() - 1)->reverse() do ( execute (s[x+1])->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Solve(): n,t,c=list(map(int,input().split())) a=list(map(int,input().split())) s="".join(list(map(lambda x : "1" if x<=t else "0",a))).split("0") ans=0 for i in s : if len(i)>=c : ans+=len(i)-(c-1) print(ans) if __name__=="__main__" : Solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Solve() ) else skip; operation Solve() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; var c : OclAny := null; Sequence{n,t,c} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : OclAny := "".join(((a)->collect( _x | (lambda x : OclAny in (if (x->compareTo(t)) <= 0 then "1" else "0" endif))->apply(_x) ))).split("0") ; var ans : int := 0 ; for i : s do ( if ((i)->size()->compareTo(c)) >= 0 then ( ans := ans + (i)->size() - (c - 1) ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(''.join(reversed(input()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (StringLib.sumStringsWithSeparator((((OclFile["System.in"]).readLine())->reverse()), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(): s=sys.stdin.readline().strip() rev_s=s[: :-1] print(rev_s) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var s : OclAny := sys.stdin.readLine()->trim() ; var rev_s : OclAny := s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; execute (rev_s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() cnt=-1 for i in range(len(S)): if i==len(S)-1 : print(S[0]) else : print(S[cnt],sep="",end="") cnt-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var cnt : int := -1 ; for i : Integer.subrange(0, (S)->size()-1) do ( if i = (S)->size() - 1 then ( execute (S->first())->display() ) else ( execute (S[cnt+1])->display() ; cnt := cnt - 1 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMajority(arr,n): maxCount=0 ; index=-1 for i in range(n): count=0 for j in range(n): if(arr[i]==arr[j]): count+=1 if(count>maxCount): maxCount=count index=i if(maxCount>n//2): print(arr[index]) else : print("No Majority Element") if __name__=="__main__" : arr=[1,1,2,1,3,5,1] n=len(arr) findMajority(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 1 })))))) ; n := (arr)->size() ; findMajority(arr, n) ) else skip; operation findMajority(arr : OclAny, n : OclAny) pre: true post: true activity: var maxCount : int := 0; ; var index : int := -1 ; for i : Integer.subrange(0, n-1) do ( var count : int := 0 ; for j : Integer.subrange(0, n-1) do ( if (arr[i+1] = arr[j+1]) then ( count := count + 1 ) else skip) ; if ((count->compareTo(maxCount)) > 0) then ( maxCount := count ; index := i ) else skip) ; if ((maxCount->compareTo(n div 2)) > 0) then ( execute (arr[index+1])->display() ) else ( execute ("No Majority Element")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countTrees(n): BT=[0]*(n+1) BT[0]=BT[1]=1 for i in range(2,n+1): for j in range(i): BT[i]+=BT[j]*BT[i-j-1] return BT[n] if __name__=='__main__' : n=5 print("Total Possible Binary Trees are : ",countTrees(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 5 ; execute ("Total Possible Binary Trees are : ")->display() ) else skip; operation countTrees(n : OclAny) : OclAny pre: true post: true activity: var BT : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; BT->first() := 1; var BT[1+1] : int := 1 ; for i : Integer.subrange(2, n + 1-1) do ( for j : Integer.subrange(0, i-1) do ( BT[i+1] := BT[i+1] + BT[j+1] * BT[i - j - 1+1])) ; return BT[n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculateEvenSum(n): if n<=0 : return 0 fibo=[0]*(2*n+1) fibo[0],fibo[1]=0,1 sum=0 for i in range(2,2*n+1): fibo[i]=fibo[i-1]+fibo[i-2] if i % 2==0 : sum+=fibo[i] return sum if __name__=="__main__" : n=8 print("Even indexed Fibonacci Sum upto",n,"terms:",calculateEvenSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 8 ; execute ("Even indexed Fibonacci Sum upto")->display() ) else skip; operation calculateEvenSum(n : OclAny) : OclAny pre: true post: true activity: if n <= 0 then ( return 0 ) else skip ; var fibo : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * n + 1)) ; var fibo->first() : OclAny := null; var fibo[1+1] : OclAny := null; Sequence{fibo->first(),fibo[1+1]} := Sequence{0,1} ; var sum : int := 0 ; for i : Integer.subrange(2, 2 * n + 1-1) do ( fibo[i+1] := fibo[i - 1+1] + fibo[i - 2+1] ; if i mod 2 = 0 then ( sum := sum + fibo[i+1] ) else skip) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=sum(int(input())for _ in[0]*4) print(t//60) print(t % 60) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr (atom (number (integer 4))))))))))->sum() ; execute (t div 60)->display() ; execute (t mod 60)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np N=int(input()) n=[int(x)for x in input().split()] n=np.array(n) a=1 pos=0 for i in range(1,N): if n[pos]>n[i]: a+=1 pos=i print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; n := (n) ; var a : int := 1 ; var pos : int := 0 ; for i : Integer.subrange(1, N-1) do ( if (n[pos+1]->compareTo(n[i+1])) > 0 then ( a := a + 1 ; pos := i ) else skip) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys a=int(sys.stdin.readline()) b=int(sys.stdin.readline()) c=int(sys.stdin.readline()) d=int(sys.stdin.readline()) sum_4=a+b+c+d minutes=int(sum_4/60) seconds=sum_4 % 60 print(minutes) print(seconds) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sum_4 : int := a + b + c + d ; var minutes : int := ("" + ((sum_4 / 60)))->toInteger() ; var seconds : int := sum_4 mod 60 ; execute (minutes)->display() ; execute (seconds)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in divmod(sum([int(input())for _ in range(4)]),60): print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Sequence{((Integer.subrange(0, 4-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())))->sum() div 60), ((Integer.subrange(0, 4-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())))->sum() mod 60)} do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def my_range(): for i in range(4): a=int(input()) yield a ss=sum(my_range()) x=int(ss/60) y=int(ss % 60) print(x) print(y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var ss : OclAny := (OclIterator.newOclIterator_Function(lambda _i : int in self.my_range(_i)))->sum() ; var x : int := ("" + ((ss / 60)))->toInteger() ; var y : int := ("" + ((ss mod 60)))->toInteger() ; execute (x)->display() ; execute (y)->display(); operation my_range(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; for i : Integer.subrange(0, 4-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return a); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=map(int,input().split()) l=list(map(int,input().split())) ans=0 c=0 for i in l : if i==1 : if a!=0 : a-=i ; ans+=1 elif b!=0 : ans+=i ; b-=1 ; c+=1 elif c!=0 : ans+=i ; c-=1 else : if b!=0 : ans+=i ; b-=1 print(sum(l)-ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; var c : int := 0 ; for i : l do ( if i = 1 then ( if a /= 0 then ( a := a - i; ans := ans + 1 ) else (if b /= 0 then ( ans := ans + i; b := b - 1; c := c + 1 ) else (if c /= 0 then ( ans := ans + i; c := c - 1 ) else skip ) ) ) else ( if b /= 0 then ( ans := ans + i; b := b - 1 ) else skip )) ; execute ((l)->sum() - ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): sum=0 for _ in range(4): sum+=int(input()) x=sum//60 y=sum % 60 print(x) print(y) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var sum : int := 0 ; for _anon : Integer.subrange(0, 4-1) do ( sum := sum + ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var x : int := sum div 60 ; var y : int := sum mod 60 ; execute (x)->display() ; execute (y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s=input() return(list(s[: len(s)-1])) def invr(): return(map(int,input().split())) [n,k]=inlt() a=inlt() seen={} for i in range(n): seen[a[i]]=i+1 if len(seen)==k : break if len(seen)==k : print(min(seen.values()),max(seen.values())) else : print(-1,-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; Sequence{n}->union(Sequence{ k }) := inlt() ; var a : OclAny := inlt() ; var seen : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( seen[a[i+1]+1] := i + 1 ; if (seen)->size() = k then ( break ) else skip) ; if (seen)->size() = k then ( execute ((seen.values())->min())->display() ) else ( execute (-1)->display() ); operation inp() : OclAny pre: true post: true activity: return (("" + (((OclFile["System.in"]).readLine())))->toInteger()); operation inlt() : OclAny pre: true post: true activity: return (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))); operation insr() : OclAny pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; return ((s.subrange(1,(s)->size() - 1))); operation invr() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin from collections import defaultdict n,k=[int(x)for x in stdin.readline().split()] a=[int(x)for x in stdin.readline().split()] unique=defaultdict(int) l=0 ans_l=ans_r=-2 for r in range(n): unique[a[r]]+=1 while len(unique)==k and lselect(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a : Sequence := stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var unique : OclAny := defaultdict(OclType["int"]) ; var l : int := 0 ; var ans_l : OclAny := -2; var ans_r : int := -2 ; for r : Integer.subrange(0, n-1) do ( unique[a[r+1]+1] := unique[a[r+1]+1] + 1 ; while (unique)->size() = k & (l->compareTo(r)) < 0 do ( Sequence{ans_l,ans_r} := Sequence{l,r} ; unique[a[l+1]+1] := unique[a[l+1]+1] - 1 ; if unique[a[l+1]+1] <= 0 then ( execute (unique[a[l+1]+1])->isDeleted() ) else skip ; l := l + 1)) ; if k = 1 then ( execute ("1 1")->display() ) else ( execute (StringLib.formattedString('{ans_l+1}{ans_r+1}'))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=list(map(int,input().split())) b={} for i in range(n): b[a[i]]=i+1 if len(b)==k : break if len(b)==k : print(min(b.values()),max(b.values())) else : print(-1,-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( b[a[i+1]+1] := i + 1 ; if (b)->size() = k then ( break ) else skip) ; if (b)->size() = k then ( execute ((b.values())->min())->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): n,k=map(int,input().split()) arr=list(map(int,input().split())) if k==1 : print(1,1) return ; x,y=float("-inf"),float("inf") uniq=0 win=defaultdict(int) left=0 for i in range(len(arr)): uniq+=win[arr[i]]==0 win[arr[i]]+=1 while uniq>=k : if((i-left+1)<(y-x+1)): x,y=left,i win[arr[left]]-=1 uniq-=win[arr[left]]==0 left+=1 if[x,y]!=[float("-inf"),float("inf")]: print(x+1,y+1) return ; print(-1,-1) def main(): t=1 for _ in range(t): solution() import sys import threading sys.setrecursionlimit(1<<30) threading.stack_size(1<<27) thread=threading.Thread(target=main) thread.start(); thread.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1 * (2->pow(30))) ; threading.stack_size(1 * (2->pow(27))) ; var thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ; thread.start(); thread.join(); operation solution() : OclAny pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if k = 1 then ( execute (1)->display() ; return; ) else skip ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{("" + (("-inf")))->toReal(),("" + (("inf")))->toReal()} ; var uniq : int := 0 ; var win : OclAny := defaultdict(OclType["int"]) ; var left : int := 0 ; for i : Integer.subrange(0, (arr)->size()-1) do ( uniq := uniq + win[arr[i+1]+1] = 0 ; win[arr[i+1]+1] := win[arr[i+1]+1] + 1 ; while (uniq->compareTo(k)) >= 0 do ( if (((i - left + 1)->compareTo((y - x + 1))) < 0) then ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{left,i} ) else skip ; win[arr[left+1]+1] := win[arr[left+1]+1] - 1 ; uniq := uniq - win[arr[left+1]+1] = 0 ; left := left + 1)) ; if Sequence{x}->union(Sequence{ y }) /= Sequence{("" + (("-inf")))->toReal()}->union(Sequence{ ("" + (("inf")))->toReal() }) then ( execute (x + 1)->display() ; return; ) else skip ; execute (-1)->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().strip().split()) a=list(map(int,input().strip().split()))[: n] cnt=[0 for _ in range(100001)] numDiff=0 for i in range(n): cnt[a[i]]+=1 if cnt[a[i]]==1 : numDiff+=1 if numDiff==k : for l in range(i+1): cnt[a[l]]-=1 if cnt[a[l]]==0 : print(l+1,i+1) exit(0) print(-1,-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := OclType["Sequence"]((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ; var cnt : Sequence := Integer.subrange(0, 100001-1)->select(_anon | true)->collect(_anon | (0)) ; var numDiff : int := 0 ; for i : Integer.subrange(0, n-1) do ( cnt[a[i+1]+1] := cnt[a[i+1]+1] + 1 ; if cnt[a[i+1]+1] = 1 then ( numDiff := numDiff + 1 ) else skip ; if numDiff = k then ( for l : Integer.subrange(0, i + 1-1) do ( cnt[a[l+1]+1] := cnt[a[l+1]+1] - 1 ; if cnt[a[l+1]+1] = 0 then ( execute (l + 1)->display() ; exit(0) ) else skip) ) else skip) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(*args : str)->str : n=int(args[0]) P=list(map(int,args[1].split())) count=0 small=P[0] for i in range(n): if P[i]<=small : count+=1 small=min(small,P[i]) return str(count) if __name__=="__main__" : print(solve(*(open(0).read().splitlines()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (solve((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name open)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))) (trailer . (name read) (arguments ( ))) (trailer . (name splitlines) (arguments ( )))))))) )))))))))->display() ) else skip; operation solve(args : String : Sequence(OclAny)) : String pre: true post: true activity: (args * (named_parameter (name args) : (test (logical_test (comparison (expr (atom (name str)))))))) var n : int := ("" + ((args->first())))->toInteger() ; var P : Sequence := ((args[1+1].split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : int := 0 ; var small : OclAny := P->first() ; for i : Integer.subrange(0, n-1) do ( if (P[i+1]->compareTo(small)) <= 0 then ( count := count + 1 ) else skip ; small := Set{small, P[i+1]}->min()) ; return ("" + ((count))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np N=int(input()) A=[np.array(list(map(int,input().split())))for i in range(N)] ans=sum([sum(A[i])for i in range(N)]) ans//=2 for i in range(N): A[i][i]=10**10 def main(ans): for i in range(N): for j in range(i+1,N): Min=min(A[i]+A[j]) if MintoInteger() ; var A : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))) ; var ans : OclAny := (Integer.subrange(0, N-1)->select(i | true)->collect(i | ((A[i+1])->sum())))->sum() ; ans := ans div 2 ; for i : Integer.subrange(0, N-1) do ( A[i+1][i+1] := (10)->pow(10)) ; skip ; execute (main(ans))->display(); operation main(ans : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(i + 1, N-1) do ( var Min : OclAny := (A[i+1] + A[j+1])->min() ; if (Min->compareTo(A[i+1][j+1])) < 0 then ( return -1 ) else skip ; if Min = A[i+1][j+1] then ( ans := ans - A[i+1][j+1] ) else skip)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def I(): return int(input()) def MI(): return map(int,input().split()) def LI(): return list(map(int,input().split())) def main(): mod=10**9+7 inf=10*20 N=I() A=[[]for _ in range(N)] A2=[[1]*N for _ in range(N)] ans=0 for i in range(N): A[i]=LI() ans+=sum(A[i]) def warshall_floyd(d): for k in range(N): for i in range(N): if k==i : continue for j in range(N): if j==i or j==k : continue dd=d[i][k]+d[k][j] if dd==d[i][j]: A2[i][j]=0 elif ddtoInteger(); operation MI() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation main() pre: true post: true activity: var mod : double := (10)->pow(9) + 7 ; var Math_PINFINITY : int := 10 * 20 ; var N : OclAny := I() ; var A : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var A2 : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 1 }, N))) ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( A[i+1] := LI() ; ans := ans + (A[i+1])->sum()) ; skip ; if warshall_floyd(A) = -1 then ( ans := -2 ) else ( ans := 0 ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( ans := ans + A[i+1][j+1] * A2[i+1][j+1])) ) ; execute (ans div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np import sys def read_data(): try : LOCAL_FLAG import codecs import os lines=[] file_path=os.path.join(os.path.dirname(__file__),'data.dat') with codecs.open(file_path,'r','utf-8')as f : n_lines=int(f.readline()) for i in range(n_lines): lines.append(f.readline().rstrip("\n")) except NameError : lines=[] n_lines=int(input()) for i in range(n_lines): lines.append(input()) return lines raw_data=read_data() tarray=[] for each in raw_data : tarray.append(each.split()) A=np.array(tarray,dtype='int64') N=A.shape[0] def Restoring_Road_Network(): import scipy.sparse.csgraph as graph MAX=[10000000000]*N d=np.diag(MAX) C=A.copy() C+=d total_dis=0 n_path=0 for i in range(N-1): for j in range(i+1,N): dis_two_node=np.min(C[i]+C[j]) if dis_two_node>C[i,j]: total_dis+=C[i,j] elif dis_two_nodefirst() ; skip ; Restoring_Road_Network(); operation read_data() : OclAny pre: true post: true activity: try ( ; skip ; skip ; var lines : Sequence := Sequence{} ; var file_path : OclAny := os.path.join(os.path.dirname(__file__), 'data.dat') ; try (var f : OclAny := codecs.open(file_path, 'r', 'utf-8'); var n_lines : int := ("" + ((f.readLine())))->toInteger() ; for i : Integer.subrange(0, n_lines-1) do ( execute ((f.readLine().rstrip("\n")) : lines))) catch (_e : OclException) do skip) (except_clause except (test (logical_test (comparison (expr (atom (name NameError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name lines)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom [ ]))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name n_lines)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n_lines)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name lines)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))))))))))) ; return lines; operation Restoring_Road_Network() pre: true post: true activity: skip ; var MAX : Sequence := MatrixLib.elementwiseMult(Sequence{ 10000000000 }, N) ; var d : (trailer . (name diag) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name MAX)))))))) ))) := ; var C : OclAny := A->copy() ; C := C + d ; var total_dis : int := 0 ; var n_path : int := 0 ; for i : Integer.subrange(0, N - 1-1) do ( for j : Integer.subrange(i + 1, N-1) do ( var dis_two_node : (trailer . (name min) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name C)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name C)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))))) ))) := ; if (dis_two_node->compareTo(C[i+1][j+1])) > 0 then ( total_dis := total_dis + C[i+1][j+1] ) else (if (dis_two_node->compareTo(C[i+1][j+1])) < 0 then ( execute (-1)->display() ; exit() ) else skip))) ; execute (total_dis)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools import sys sys.setrecursionlimit(10000) INF=float('inf') N=int(sys.stdin.readline()) A=[list(map(int,sys.stdin.readline().split()))for _ in range(N)] def solve(): useless=[[0]*N for _ in range(N)] for st,en in itertools.combinations(range(N),r=2): for via in range(N): if via in[st,en]: continue if A[st][via]+A[via][en]toReal() ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; skip ; execute (solve())->display(); operation solve() : OclAny pre: true post: true activity: var useless : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, N))) ; for _tuple : itertools.combinations(Integer.subrange(0, N-1), (argument (test (logical_test (comparison (expr (atom (name r)))))) = (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do (var _indx : int := 1; var st : OclAny := _tuple->at(_indx); _indx := _indx + 1; var en : OclAny := _tuple->at(_indx); for via : Integer.subrange(0, N-1) do ( if (Sequence{st}->union(Sequence{ en }))->includes(via) then ( continue ) else skip ; if (A[st+1][via+1] + A[via+1][en+1]->compareTo(A[st+1][en+1])) < 0 then ( return -1 ) else skip ; if A[st+1][via+1] + A[via+1][en+1] = A[st+1][en+1] then ( useless[st+1][en+1] := true ; useless[en+1][st+1] := true ) else skip)) ; return (itertools.product(Integer.subrange(0, N-1), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->select(_tuple | let s : OclAny = _tuple->at(1) in let e : OclAny = _tuple->at(2) in not(useless[s+1][e+1]))->collect(_tuple | let s : OclAny = _tuple->at(1) in let e : OclAny = _tuple->at(2) in (A[s+1][e+1])))->sum() div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=input().split(" ") n=int(n) a=int(a) b=int(b) aux=0 denies=0 for x in input().split(" "): x=int(x) if(x==1): if(a>0): a-=1 elif(b>0): b-=1 aux+=1 elif(aux>0): aux-=1 else : denies+=1 else : if(b>0): b-=1 else : denies+=x print(denies) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := input().split(" ") ; var n : int := ("" + ((n)))->toInteger() ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; var aux : int := 0 ; var denies : int := 0 ; for x : input().split(" ") do ( var x : int := ("" + ((x)))->toInteger() ; if (x = 1) then ( if (a > 0) then ( a := a - 1 ) else (if (b > 0) then ( b := b - 1 ; aux := aux + 1 ) else (if (aux > 0) then ( aux := aux - 1 ) else ( denies := denies + 1 ) ) ) ) else ( if (b > 0) then ( b := b - 1 ) else ( denies := denies + x ) )) ; execute (denies)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy def Warshall_Floyd(edges,N): for k in range(N): for i in range(N): for j in range(N): edges[i][j]=min(edges[i][j],edges[i][k]+edges[k][j]) return edges n=int(input()) arr=[list(map(int,input().split()))for _ in range(n)] g=[[float('inf')]*n for _ in range(n)] for i in range(n): for j in range(n): g[i][j]=arr[i][j] d=Warshall_Floyd(copy.deepcopy(g),n) ans=0 for a in range(n): for b in range(n): if a>=b : continue w=g[a][b] if d[a][b]toInteger() ; var arr : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var g : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ ("" + (('inf')))->toReal() }, n))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( g[i+1][j+1] := arr[i+1][j+1])) ; var d : OclAny := Warshall_Floyd(copy.deepcopy(g), n) ; var ans : int := 0 ; (compound_stmt for (exprlist (expr (atom (name a)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name b)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name a)))) >= (comparison (expr (atom (name b))))))) : (suite (stmt (simple_stmt (small_stmt continue)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name w)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])))) < (comparison (expr (atom (name w))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name exit)) (trailer (arguments ( ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name tmp)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (number (integer 10)))) ** (expr (atom (number (integer 10)))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name k)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name k)))) == (comparison (expr (atom (name a)))))) or (logical_test (comparison (comparison (expr (atom (name k)))) == (comparison (expr (atom (name b)))))))) : (suite (stmt (simple_stmt (small_stmt continue)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name tmp)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name tmp))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ]))) + (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ]))))))))) )))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name w)))) == (comparison (expr (atom (name tmp))))))) : (suite (stmt (simple_stmt (small_stmt continue)))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name w))))))))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))))))))); operation Warshall_Floyd(edges : OclAny, N : OclAny) : OclAny pre: true post: true activity: for k : Integer.subrange(0, N-1) do ( for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( edges[i+1][j+1] := Set{edges[i+1][j+1], edges[i+1][k+1] + edges[k+1][j+1]}->min()))) ; return edges; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Check_is_possible(l,r,k): count=0 ; for i in range(l,r+1): if(i % k==0): count+=1 ; return(count>1); l=4 ; r=12 ; k=5 ; if(Check_is_possible(l,r,k)): print("YES"); else : print("NO"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; l := 4; ; r := 12; ; k := 5; ; if (Check_is_possible(l, r, k)) then ( execute ("YES")->display(); ) else ( execute ("NO")->display(); ); operation Check_is_possible(l : OclAny, r : OclAny, k : OclAny) pre: true post: true activity: var count : int := 0; ; for i : Integer.subrange(l, r + 1-1) do ( if (i mod k = 0) then ( count := count + 1; ) else skip) ; return (count > 1);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) n_O=0 n_E=0 for i in range(1,n+1): if(2*i)% k==0 : if(2*i//k)% 2==0 : n_E+=1 else : n_O+=1 print(n_E**3+n_O**3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n_O : int := 0 ; var n_E : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( if (2 * i) mod k = 0 then ( if (2 * i div k) mod 2 = 0 then ( n_E := n_E + 1 ) else ( n_O := n_O + 1 ) ) else skip) ; execute ((n_E)->pow(3) + (n_O)->pow(3))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import ceil def input(): return sys.stdin.readline().strip() def main(): N,K=map(int,input().split()) if K % 2!=0 : val1=(N//K)*(N//K-1)*(N//K-2) val2=(N//K)*(N//K-1)*3 val3=N//K print(val1+val2+val3) else : val1=(N//K)*(N//K-1)*(N//K-2) val2=(N//K)*(N//K-1)*3 val3=N//K N-=K//2 val4=(N//K+1)*(N//K)*(N//K-1) val5=(N//K+1)*(N//K)*3 val6=N//K+1 print(val1+val2+val3+val4+val5+val6) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation main() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if K mod 2 /= 0 then ( var val1 : double := (N div K) * (N div K - 1) * (N div K - 2) ; var val2 : double := (N div K) * (N div K - 1) * 3 ; var val3 : int := N div K ; execute (val1 + val2 + val3)->display() ) else ( val1 := (N div K) * (N div K - 1) * (N div K - 2) ; val2 := (N div K) * (N div K - 1) * 3 ; val3 := N div K ; N := N - K div 2 ; var val4 : double := (N div K + 1) * (N div K) * (N div K - 1) ; var val5 : int := (N div K + 1) * (N div K) * 3 ; var val6 : int := N div K + 1 ; execute (val1 + val2 + val3 + val4 + val5 + val6)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,input().split()) count=N//K count2=0 if K % 2==0 : K2=K//2 count2=(N//K2)-count ans=count*count*count ans+=count2*count2*count2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var count : int := N div K ; var count2 : int := 0 ; if K mod 2 = 0 then ( var K2 : int := K div 2 ; count2 := (N div K2) - count ) else skip ; var ans : int := count * count * count ; ans := ans + count2 * count2 * count2 ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- now_min=1<<20 n=int(input()) ans=0 for p in map(int,input().split()): if ppow(20)) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; for p : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( if (p->compareTo(now_min)) < 0 then ( ans := ans + 1 ; now_min := p ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math N,K=map(int,input().split()) count=0 for i in range(1,N+1): if K % 2==0 : a=i*K/2 if a>=N+1 : break maxn=int((N+a)//K) minn=math.ceil((a+1)/K) maxln=int((N-a)//K) minln=max(math.ceil((1-a)/K),1-i) count+=(maxn-minn+1)*(maxln-minln+1) else : a=i*K if a>=N+1 : break maxn=int((N+a)//K) minn=math.ceil((a+1)/K) maxln=int((N-a)//K) minln=max(math.ceil((1-a)/K),1-i) count+=(maxn-minn+1)*(maxln-minln+1) print(int(count)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var count : int := 0 ; for i : Integer.subrange(1, N + 1-1) do ( if K mod 2 = 0 then ( var a : double := i * K / 2 ; if (a->compareTo(N + 1)) >= 0 then ( break ) else skip ; var maxn : int := ("" + (((N + a) div K)))->toInteger() ; var minn : double := ((a + 1) / K)->ceil() ; var maxln : int := ("" + (((N - a) div K)))->toInteger() ; var minln : OclAny := Set{((1 - a) / K)->ceil(), 1 - i}->max() ; count := count + (maxn - minn + 1) * (maxln - minln + 1) ) else ( a := i * K ; if (a->compareTo(N + 1)) >= 0 then ( break ) else skip ; maxn := ("" + (((N + a) div K)))->toInteger() ; minn := ((a + 1) / K)->ceil() ; maxln := ("" + (((N - a) div K)))->toInteger() ; minln := Set{((1 - a) / K)->ceil(), 1 - i}->max() ; count := count + (maxn - minn + 1) * (maxln - minln + 1) )) ; execute (("" + ((count)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(N : int,K : int): a=N//K if K % 2==0 : if N % K>=K//2 : b=a+1 else : b=a print(a**3+b**3) else : print(a**3) return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() N=int(next(tokens)) K=int(next(tokens)) solve(N,K) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(N : int, K : int) pre: true post: true activity: var a : int := N div K ; if K mod 2 = 0 then ( if (N mod K->compareTo(K div 2)) >= 0 then ( var b : int := a + 1 ) else ( b := a ) ; execute ((a)->pow(3) + (b)->pow(3))->display() ) else ( execute ((a)->pow(3))->display() ) ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var N : int := ("" + (((tokens).next())))->toInteger() ; var K : int := ("" + (((tokens).next())))->toInteger() ; solve(N, K); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A=int(input()) print(2*A-1,2) print(1,2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (2 * A - 1)->display() ; execute (1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) if(a==1): print(3,1) print(3) else : print(2*(a-1),2) print(1,2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (a = 1) then ( execute (3)->display() ; execute (3)->display() ) else ( execute (2 * (a - 1))->display() ; execute (1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solver : def main(self): n=int(input().strip()) print('{}2\n1 2'.format((n-1)*2+1)) Solver().main() ------------------------------------------------------------ OCL File: --------- class Solver { static operation newSolver() : Solver pre: true post: Solver->exists( _x | result = _x ); operation main() pre: true post: true activity: var n : int := ("" + ((input()->trim())))->toInteger() ; execute (StringLib.interpolateStrings('{}2 1 2', Sequence{(n - 1) * 2 + 1}))->display(); } class FromPython { operation initialise() pre: true post: true activity: skip ; (expr (atom (name Solver)) (trailer (arguments ( ))) (trailer . (name main) (arguments ( )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=map(int,input().strip().split()) c=0 l=list(map(int,input().strip().split())) co=0 for i in range(n): if l[i]==2 : if b<=0 : co+=2 else : b-=1 if l[i]==1 : if a>0 : a-=1 elif b>0 : b-=1 c+=1 elif c>0 : c-=1 else : co+=1 print(co) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : int := 0 ; var l : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var co : int := 0 ; for i : Integer.subrange(0, n-1) do ( if l[i+1] = 2 then ( if b <= 0 then ( co := co + 2 ) else ( b := b - 1 ) ) else skip ; if l[i+1] = 1 then ( if a > 0 then ( a := a - 1 ) else (if b > 0 then ( b := b - 1 ; c := c + 1 ) else (if c > 0 then ( c := c - 1 ) else ( co := co + 1 ) ) ) ) else skip) ; execute (co)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): count=int(input()) print('{}2'.format(count*2-1)) print('1 2') main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var count : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (StringLib.interpolateStrings('{}2', Sequence{count * 2 - 1}))->display() ; execute ('1 2')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(n*2-1,2) print(1,2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n * 2 - 1)->display() ; execute (1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def circlearea(R): if(R<0): return-1 ; a=(3.14*R*R)/4 ; return a ; if __name__=="__main__" : R=2 ; print(circlearea(R)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( R := 2; ; execute (circlearea(R))->display(); ) else skip; operation circlearea(R : OclAny) pre: true post: true activity: if (R < 0) then ( return -1; ) else skip ; var a : double := (3.14 * R * R) / 4; ; return a;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): ans=x=y=tx=ty=0 while True : dx,dy=map(int,input().split()) if(dx | dy)==0 : break x+=dx ; y+=dy d=x*x+y*y if d>ans : ans,tx,ty=d,x,y elif d==ans and txtoInteger()-1) do ( ans := ans(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name y)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name tx)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ty)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; while true do ( var dx : OclAny := null; var dy : OclAny := null; Sequence{dx,dy} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (MathLib.bitwiseOr(dx, dy)) = 0 then ( break ) else skip ; x := x + dx; y := y + dy ; var d : double := x * x + y * y ; if (d->compareTo(ans)) > 0 then ( var ans : OclAny := null; var tx : OclAny := null; var ty : OclAny := null; Sequence{ans,tx,ty} := Sequence{d,x,y} ) else (if d = ans & (tx->compareTo(x)) < 0 then ( var tx : OclAny := null; var ty : OclAny := null; Sequence{tx,ty} := Sequence{x,y} ) else skip)) ; execute (tx)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) c=0 for i in range(2): c+=max(a,b) if a>=b : a-=1 else : b-=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : int := 0 ; for i : Integer.subrange(0, 2-1) do ( c := c + Set{a, b}->max() ; if (a->compareTo(b)) >= 0 then ( a := a - 1 ) else ( b := b - 1 )) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): m=dx=dy=0 while 1 : x,y=map(int,input().split()) if x==y==0 : break dx+=x dy+=y l=dx*dx+dy*dy if(m==l and mxtoInteger()-1) do ( m := m(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dx)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dy)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; while 1 do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x = y & (y == 0) then ( break ) else skip ; dx := dx + x ; dy := dy + y ; var l : double := dx * dx + dy * dy ; if (m = l & (mx->compareTo(dx)) < 0) or (m->compareTo(l)) < 0 then ( var m : OclAny := null; var mx : OclAny := null; var my : OclAny := null; Sequence{m,mx,my} := Sequence{l,dx,dy} ) else skip) ; execute (mx)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : TC=int(input()) for _ in range(TC): maxDist=0 treasureX=0 treasureY=0 posX=0 posY=0 while True : x,y=[int(x)for x in list(filter(lambda x : x!='',input().strip().split(' ')))] if x==0 and y==0 : break posX+=x posY+=y dist=posX*posX+posY*posY if dist>maxDist or(dist==maxDist and posX>treasureX): maxDist=dist treasureX=posX treasureY=posY print(treasureX,treasureY) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var TC : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, TC-1) do ( var maxDist : int := 0 ; var treasureX : int := 0 ; var treasureY : int := 0 ; var posX : int := 0 ; var posY : int := 0 ; while true do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input()->trim().split(' '))->select( _x | (lambda x : OclAny in (x /= ''))->apply(_x) = true ))->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if x = 0 & y = 0 then ( break ) else skip ; posX := posX + x ; posY := posY + y ; var dist : int := posX * posX + posY * posY ; if (dist->compareTo(maxDist)) > 0 or (dist = maxDist & (posX->compareTo(treasureX)) > 0) then ( maxDist := dist ; treasureX := posX ; treasureY := posY ) else skip) ; execute (treasureX)->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline MOD=1000000007 MOD2=998244353 ii=lambda : int(input().strip('\n')) si=lambda : input().strip('\n') dgl=lambda : list(map(int,input().strip('\n'))) f=lambda : map(int,input().strip('\n').split()) il=lambda : list(map(int,input().strip('\n').split())) ls=lambda : list(input().strip('\n')) lsi=lambda :[int(i)for i in ls()] let='abcdefghijklmnopqrstuvwxyz' for _ in range(1): n=ii() edges=[il()for i in range(n-1)] clr=[0]+il() deg=[0]*(n+1) tot=0 for i in edges : if clr[i[0]]!=clr[i[1]]: deg[i[0]]+=1 deg[i[1]]+=1 tot+=1 for i in range(1,n+1): if deg[i]==tot : exit(print('YES\n'+str(i))) print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var MOD : int := 1000000007 ; var MOD2 : int := 998244353 ; var ii : Function := lambda $$ : OclAny in (("" + ((input()->trim())))->toInteger()) ; var si : Function := lambda $$ : OclAny in (input()->trim()) ; var dgl : Function := lambda $$ : OclAny in (((input()->trim())->collect( _x | (OclType["int"])->apply(_x) ))) ; var f : Function := lambda $$ : OclAny in ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var il : Function := lambda $$ : OclAny in (((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ls : Function := lambda $$ : OclAny in ((input()->trim())) ; var lsi : Function := lambda $$ : OclAny in (ls->apply()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))) ; var let : String := 'abcdefghijklmnopqrstuvwxyz' ; for _anon : Integer.subrange(0, 1-1) do ( var n : OclAny := ii->apply() ; var edges : Sequence := Integer.subrange(0, n - 1-1)->select(i | true)->collect(i | (il->apply())) ; var clr : Sequence := Sequence{ 0 }->union(il->apply()) ; var deg : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var tot : int := 0 ; for i : edges do ( if clr[i->first()+1] /= clr[i[1+1]+1] then ( deg[i->first()+1] := deg[i->first()+1] + 1 ; deg[i[1+1]+1] := deg[i[1+1]+1] + 1 ; tot := tot + 1 ) else skip) ; for i : Integer.subrange(1, n + 1-1) do ( if deg[i+1] = tot then ( exit(('YES ' + ("" + ((i))))->display()) ) else skip) ; execute ('NO')->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=[] brr=[] for i in range(n-1): u,v=list(map(int,input().split())) arr.append(u) brr.append(v) color=list(map(int,input().split())) ans=[] for i in range(n-1): if color[arr[i]-1]!=color[brr[i]-1]: if ans==[]: ans+=[arr[i],brr[i]] else : if arr[i]in ans and brr[i]in ans : print("NO") exit() elif arr[i]in ans : ans=[arr[i]] elif brr[i]in ans : ans=[brr[i]] else : print("NO") exit() print("YES") if len(ans)==0 : ans.append(1) print(ans[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Sequence{} ; var brr : Sequence := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((u) : arr) ; execute ((v) : brr)) ; var color : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( if color[arr[i+1] - 1+1] /= color[brr[i+1] - 1+1] then ( if ans = Sequence{} then ( ans := ans + Sequence{arr[i+1]}->union(Sequence{ brr[i+1] }) ) else ( if (ans)->includes(arr[i+1]) & (ans)->includes(brr[i+1]) then ( execute ("NO")->display() ; exit() ) else (if (ans)->includes(arr[i+1]) then ( ans := Sequence{ arr[i+1] } ) else (if (ans)->includes(brr[i+1]) then ( ans := Sequence{ brr[i+1] } ) else ( execute ("NO")->display() ; exit() ) ) ) ) ) else skip) ; execute ("YES")->display() ; if (ans)->size() = 0 then ( execute ((1) : ans) ) else skip ; execute (ans->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import sys def read_ints(): return[int(x)for x in sys.stdin.readline().strip().split()] def main(): N=read_ints()[0] edges=[] vx_to_neighbor_colors=collections.defaultdict(set) for _ in range(N-1): u,v=read_ints() u-=1 v-=1 edges.append((u,v)) colors=read_ints() vx_to_cnt=collections.Counter() e_cnt=0 for e in edges : if colors[e[0]]==colors[e[1]]: continue vx_to_cnt[e[0]]+=1 vx_to_cnt[e[1]]+=1 e_cnt+=1 if e_cnt==0 : return 1 if e_cnt==1 : return 1+list(vx_to_cnt.keys())[0] root=None for vx,cnt in vx_to_cnt.items(): if cnt==e_cnt : if root is not None : return None root=1+vx elif cnt!=1 : return None return root if __name__=='__main__' : root=main() if root is not None : print(f'YES\n{root}') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( root := main() ; if not(root <>= null) then ( execute (StringLib.formattedString('YES {root}'))->display() ) else ( execute ('NO')->display() ) ) else skip; operation read_ints() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation main() : OclAny pre: true post: true activity: var N : OclAny := read_ints()->first() ; var edges : Sequence := Sequence{} ; var vx_to_neighbor_colors : OclAny := .defaultdict(OclType["Set"]) ; for _anon : Integer.subrange(0, N - 1-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := read_ints() ; u := u - 1 ; v := v - 1 ; execute ((Sequence{u, v}) : edges)) ; var colors : OclAny := read_ints() ; var vx_to_cnt : OclAny := .Counter() ; var e_cnt : int := 0 ; for e : edges do ( if colors[e->first()+1] = colors[e[1+1]+1] then ( continue ) else skip ; vx_to_cnt[e->first()+1] := vx_to_cnt[e->first()+1] + 1 ; vx_to_cnt[e[1+1]+1] := vx_to_cnt[e[1+1]+1] + 1 ; e_cnt := e_cnt + 1) ; if e_cnt = 0 then ( return 1 ) else skip ; if e_cnt = 1 then ( return 1 + OclType["Sequence"](vx_to_cnt.keys())->first() ) else skip ; var root : OclAny := null ; for _tuple : vx_to_cnt->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var vx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var cnt : OclAny := _tuple->at(_indx); if cnt = e_cnt then ( if not(root <>= null) then ( return null ) else skip ; root := 1 + vx ) else (if cnt /= 1 then ( return null ) else skip)) ; return root; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) edges=list(list(map(int,input().split()))for _ in range(n-1)) colors=list(map(int,input().split())) edge_cnt=0 pnt_cnt={0 : 0} for a,b in edges : a-=1 ; b-=1 if colors[a]!=colors[b]: edge_cnt+=1 pnt_cnt[a]=pnt_cnt.get(a,0)+1 pnt_cnt[b]=pnt_cnt.get(b,0)+1 for k,v in pnt_cnt.items(): if v==edge_cnt : print("YES") print(k+1) break else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var edges : Sequence := ((argument (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) ))))))))) ; var colors : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var edge_cnt : int := 0 ; var pnt_cnt : Map := Map{ 0 |-> 0 } ; for _tuple : edges do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); a := a - 1; b := b - 1 ; if colors[a+1] /= colors[b+1] then ( edge_cnt := edge_cnt + 1 ; pnt_cnt[a+1] := pnt_cnt.get(a, 0) + 1 ; pnt_cnt[b+1] := pnt_cnt.get(b, 0) + 1 ) else skip) ; (compound_stmt for (exprlist (expr (atom (name k))) , (expr (atom (name v)))) in (testlist (test (logical_test (comparison (expr (atom (name pnt_cnt)) (trailer . (name items) (arguments ( )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name v)))) == (comparison (expr (atom (name edge_cnt))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name k))) + (expr (atom (number (integer 1)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,a,b=map(int,input().split()) w=input()[:-1].split() c=0 d=0 for i in range(n): if w[i]=='1' : if a>0 : a-=1 elif b>0 : b-=1 d+=1 elif d>0 : d-=1 else : c+=1 else : if b>0 : b-=1 else : c+=2 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : OclAny := input()->front().split() ; var c : int := 0 ; var d : int := 0 ; for i : Integer.subrange(0, n-1) do ( if w[i+1] = '1' then ( if a > 0 then ( a := a - 1 ) else (if b > 0 then ( b := b - 1 ; d := d + 1 ) else (if d > 0 then ( d := d - 1 ) else ( c := c + 1 ) ) ) ) else ( if b > 0 then ( b := b - 1 ) else ( c := c + 2 ) )) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): SIZE=1001 ans=1 ans+=sum(4*i*i-6*(i-1)for i in range(3,SIZE+1,2)) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var SIZE : int := 1001 ; var ans : int := 1 ; ans := ans + ((argument (test (logical_test (comparison (expr (expr (expr (expr (atom (number (integer 4)))) * (expr (atom (name i)))) * (expr (atom (name i)))) - (expr (expr (atom (number (integer 6)))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1))))))))) )))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 3)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name SIZE))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))))))))->sum() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import inf n=int(input()) ans=0 for _ in range(n): x1,y1,x2,y2=[int(i)for i in input().split(' ')] ans+=(abs(x2-x1)+1)*(abs(y2-y1)+1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := input().split(' ')->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; ans := ans + ((x2 - x1)->abs() + 1) * ((y2 - y1)->abs() + 1)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- z=[]; s=0 for i in ' '*int(input()): a,b,c,d=list(map(int,input().split())) s+=(c-a+1)*(d-b+1) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var z : Sequence := Sequence{}; var s : int := 0 ; for i : StringLib.nCopies(' ', ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; s := s + (c - a + 1) * (d - b + 1)) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A=list(map(int,input().split())) print(max(A[0]+A[1],A[0]+A[0]-1,A[1]+A[1]-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (Set{A->first() + A[1+1], A->first() + A->first() - 1, A[1+1] + A[1+1] - 1}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- table=[[0 for i in range(100)]for i in range(100)] n=int(input()) summi=0 for i in range(n): x1,y1,x2,y2=map(int,input().split()) for j in range(x1-1,x2,1): for k in range(y1-1,y2,1): table[j][k]+=1 for i in range(100): for j in range(100): summi+=table[i][j] print(summi) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var table : Sequence := Integer.subrange(0, 100-1)->select(i | true)->collect(i | (Integer.subrange(0, 100-1)->select(i | true)->collect(i | (0)))) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var summi : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for j : Integer.subrange(x1 - 1, x2-1)->select( $x | ($x - x1 - 1) mod 1 = 0 ) do ( for k : Integer.subrange(y1 - 1, y2-1)->select( $x | ($x - y1 - 1) mod 1 = 0 ) do ( table[j+1][k+1] := table[j+1][k+1] + 1))) ; for i : Integer.subrange(0, 100-1) do ( for j : Integer.subrange(0, 100-1) do ( summi := summi + table[i+1][j+1])) ; execute (summi)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- table=[[0 for i in range(100)]for i in range(100)] n=int(input()) summi=0 for i in range(n): x1,y1,x2,y2=map(int,input().split()) summi+=(x2-x1+1)*(y2-y1+1) print(summi) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var table : Sequence := Integer.subrange(0, 100-1)->select(i | true)->collect(i | (Integer.subrange(0, 100-1)->select(i | true)->collect(i | (0)))) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var summi : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; summi := summi + (x2 - x1 + 1) * (y2 - y1 + 1)) ; execute (summi)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) n=int(input()) k=0 for i in range(n): x1,y1,x2,y2=map(int,input().split()) k+=(x2-x1+1)*(y2-y1+1) print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; k := k + (x2 - x1 + 1) * (y2 - y1 + 1)) ; execute (k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def arrange(arr,n,x): for i in range(1,n): diff=abs(arr[i]-x) j=i-1 if(abs(arr[j]-x)>diff): temp=arr[i] while(abs(arr[j]-x)>diff and j>=0): arr[j+1]=arr[j] j-=1 arr[j+1]=temp def print_1(arr,n): for i in range(n): print(arr[i],end=" ") if __name__=="__main__" : arr=[10,5,3,9,2] n=len(arr) x=7 arrange(arr,n,x) print_1(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{10}->union(Sequence{5}->union(Sequence{3}->union(Sequence{9}->union(Sequence{ 2 })))) ; n := (arr)->size() ; x := 7 ; arrange(arr, n, x) ; printprintprintprintprintprintprint arr := Sequence{10}->union(Sequence{5}->union(Sequence{3}->union(Sequence{9}->union(Sequence{ 2 }))))(arr, n)(arr, n)(arr, n)(arr, n)(arr, n)(arr, n)(arr, n) ) else skip; operation arrange(arr : OclAny, n : OclAny, x : OclAny) pre: true post: true activity: for i : Integer.subrange(1, n-1) do ( var diff : double := (arr[i+1] - x)->abs() ; var j : double := i - 1 ; if (((arr[j+1] - x)->abs()->compareTo(diff)) > 0) then ( var temp : OclAny := arr[i+1] ; while (((arr[j+1] - x)->abs()->compareTo(diff)) > 0 & j >= 0) do ( arr[j + 1+1] := arr[j+1] ; j := j - 1) ; arr[j + 1+1] := temp ) else skip); operation print skip(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=101 dp=[[-1 for i in range(2)]for i in range(MAX)] def CountWays(n,flag): if(dp[n][flag]!=-1): return dp[n][flag] if(n==0): return 1 sum=0 if(flag==0 and n>1): sum=(sum+CountWays(n-1,0)+CountWays(n-2,1)) else : sum=sum+CountWays(n-1,0) dp[n][flag]=sum return dp[n][flag] if __name__=='__main__' : n=5 print(CountWays(n,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 101 ; var dp : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (Integer.subrange(0, 2-1)->select(i | true)->collect(i | (-1)))) ; skip ; if __name__ = '__main__' then ( n := 5 ; execute (CountWays(n, 0))->display() ) else skip; operation CountWays(n : OclAny, flag : OclAny) : OclAny pre: true post: true activity: if (dp[n+1][flag+1] /= -1) then ( return dp[n+1][flag+1] ) else skip ; if (n = 0) then ( return 1 ) else skip ; var sum : int := 0 ; if (flag = 0 & n > 1) then ( sum := (sum + CountWays(n - 1, 0) + CountWays(n - 2, 1)) ) else ( sum := sum + CountWays(n - 1, 0) ) ; dp[n+1][flag+1] := sum ; return dp[n+1][flag+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) As=[A-i for i,A in enumerate(map(int,input().split()),1)] As.sort() b=As[N//2] print(sum([abs(A-b)for A in As])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var As : Sequence := Integer.subrange(1, ((input().split())->collect( _x | (OclType["int"])->apply(_x) ), 1)->size())->collect( _indx | Sequence{_indx-1, ((input().split())->collect( _x | (OclType["int"])->apply(_x) ), 1)->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let A : OclAny = _tuple->at(2) in (A - i)) ; As := As->sort() ; var b : OclAny := As[N div 2+1] ; execute ((As->select(A | true)->collect(A | ((A - b)->abs())))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) a=[int(i)for i in input().split()] B=[a[i]-i-1 for i in range(len(a))] B.sort() ans=0 for i,aa in enumerate(a): ans+=abs(aa-(i+1)-B[len(B)//2]) print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var B : Sequence := Integer.subrange(0, (a)->size()-1)->select(i | true)->collect(i | (a[i+1] - i - 1)) ; B := B->sort() ; var ans : int := 0 ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var aa : OclAny := _tuple->at(_indx); ans := ans + (aa - (i + 1) - B[(B)->size() div 2+1])->abs()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import Fraction import math with open("C-small-1-attempt0.in")as infile : with open("C.out","w")as outfile : ncases=int(next(infile)) for case in range(1,ncases+1): nlines=int(next(infile)) hikers=[] for L in range(nlines): D,H,M=map(int,next(infile).split()) for i in range(H): hikers.append((D,M+i)) hikers.sort() time1=(Fraction(hikers[0][1])*(360-hikers[0][0]))/360 laps2=time1*1/Fraction(hikers[1][1])+Fraction(hikers[1][0])/360 time2=(Fraction(hikers[1][1])*(360-hikers[1][0]))/360 laps1=time2*1/Fraction(hikers[0][1])+Fraction(hikers[0][0])/360 if laps2<=1 : sol1=1 else : sol1=int(laps2-1) if laps1<=1 : sol2=1 else : sol2=int(laps1-1) print("Case #{}:{}".format(case,min(sol1,sol2)),file=outfile) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; try (var infile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("C-small-1-attempt0.in")); try (var outfile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("C.out")); var ncases : int := ("" + (((infile).next())))->toInteger() ; for case : Integer.subrange(1, ncases + 1-1) do ( var nlines : int := ("" + (((infile).next())))->toInteger() ; var hikers : Sequence := Sequence{} ; for L : Integer.subrange(0, nlines-1) do ( var D : OclAny := null; var H : OclAny := null; var M : OclAny := null; Sequence{D,H,M} := (next(infile).split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, H-1) do ( execute ((Sequence{D, M + i}) : hikers))) ; hikers := hikers->sort() ; var time1 : double := (Fraction(hikers->first()[1+1]) * (360 - hikers->first()->first())) / 360 ; var laps2 : double := time1 * 1 / Fraction(hikers[1+1][1+1]) + Fraction(hikers[1+1]->first()) / 360 ; var time2 : double := (Fraction(hikers[1+1][1+1]) * (360 - hikers[1+1]->first())) / 360 ; var laps1 : double := time2 * 1 / Fraction(hikers->first()[1+1]) + Fraction(hikers->first()->first()) / 360 ; if laps2 <= 1 then ( var sol1 : int := 1 ) else ( sol1 := ("" + ((laps2 - 1)))->toInteger() ) ; if laps1 <= 1 then ( var sol2 : int := 1 ) else ( sol2 := ("" + ((laps1 - 1)))->toInteger() ) ; execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{case, Set{sol1, sol2}->min()}))->display())) catch (_e : OclException) do skip) catch (_e : OclException) do skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=map(int,input().split(' ')) t=[int(i)for i in input().split(' ')] deny,extra=0,0 for i in range(n): if t[i]==1 : if a!=0 : a-=1 elif b!=0 : b-=1 extra+=1 elif extra!=0 : extra-=1 else : deny+=1 else : if b!=0 : b-=1 else : deny+=2 print(deny) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var t : Sequence := input().split(' ')->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var deny : OclAny := null; var extra : OclAny := null; Sequence{deny,extra} := Sequence{0,0} ; for i : Integer.subrange(0, n-1) do ( if t[i+1] = 1 then ( if a /= 0 then ( a := a - 1 ) else (if b /= 0 then ( b := b - 1 ; extra := extra + 1 ) else (if extra /= 0 then ( extra := extra - 1 ) else ( deny := deny + 1 ) ) ) ) else ( if b /= 0 then ( b := b - 1 ) else ( deny := deny + 2 ) )) ; execute (deny)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np def f(n,b,c): return np.sum(np.abs(c-b)) def solve(n,a): c=np.asarray([(a[i]-i-1)for i in range(n)],dtype=int) b=np.median(c) return int(f(n,b,c)) assert solve(5,[2,2,3,5,5])==2 assert solve(9,[1,2,3,4,5,6,7,8,9])==0 assert solve(6,[6,5,4,3,2,1])==18 assert solve(7,[1,1,1,1,2,3,4])==6 n=int(input()) a=list(map(int,input().split())) print(solve(n,a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; assert solve(5, Sequence{2}->union(Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 5 }))))) = 2 do "assertion failed" ; assert solve(9, Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 9 }))))))))) = 0 do "assertion failed" ; assert solve(6, Sequence{6}->union(Sequence{5}->union(Sequence{4}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 1 })))))) = 18 do "assertion failed" ; assert solve(7, Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))))))) = 6 do "assertion failed" ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (solve(n, a))->display(); operation f(n : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: return MatrixLib.sumMatrix(); operation solve(n : OclAny, a : OclAny) : OclAny pre: true post: true activity: c := ; b := ; return ("" + ((f(n, b, c))))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): ab=list(map(int,input().split())) ans=0 for _ in range(2): button=max(ab) indx=ab.index(button) ans+=button ab[indx]-=1 print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var ab : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for _anon : Integer.subrange(0, 2-1) do ( var button : OclAny := (ab)->max() ; var indx : int := ab->indexOf(button) - 1 ; ans := ans + button ; ab[indx+1] := ab[indx+1] - 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,*a=map(int,open(0).read().split()) a=sorted([a[i]-i for i in range(n)]) print(sum([abs(i-a[n//2])for i in a])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (a[i+1] - i))->sort() ; execute ((a->select(i | true)->collect(i | ((i - a[n div 2+1])->abs())))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) b=[int(a-(i+1))for i,a in enumerate(list(map(int,input().split())))] if n==1 : print(0) exit(0) bm=b[:] bm.sort() mid_1=bm[n//2] mid_2=bm[(n//2)+1] ans_1,ans_2=0,0 if n % 2==1 : for bb in b : ans_1+=abs(bb-mid_1) print(ans_1) else : for bb in b : ans_1+=abs(bb-mid_1) ans_2+=abs(bb-mid_2) print(min(ans_1,ans_2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := Integer.subrange(1, (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->size())->collect( _indx | Sequence{_indx-1, (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let a : OclAny = _tuple->at(2) in (("" + ((a - (i + 1))))->toInteger())) ; if n = 1 then ( execute (0)->display() ; exit(0) ) else skip ; var bm : Sequence := b ; bm := bm->sort() ; var mid var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() : OclAny := bm[n div 2+1] ; var mid:= bm[(n div 2) + 1+1] : OclAny := bm[(n div 2) + 1+1] ; var ansans var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(),ans:= 0,0 : OclAny := null; var ans:= 0,0 : OclAny := null; Sequence{ans var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(),ans:= 0,0} := Sequence{0,0} ; if n mod 2 = 1 then ( for bb : b do ( ans var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() := ans var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() + (bb - mid var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger())->abs()) ; execute (ansans(ans(ans(ansans(ans(ans(ansans(ans(ans(ansans(ans(ans(ansans(ans(ans(ansans(ans(ans(ansans(ans(ans for bb : b do ( ans var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() := ans var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() + (bb - mid var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger())->abs()))))->display())))->display())))->display())))->display())))->display())))->display())))->display() ) else ( for bb : b do ( ans var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() := ans var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() + (bb - mid var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger())->abs() ; ans + (bb - mid_2)->abs() := ans + (bb - mid_2)->abs() + (bb - mid_2)->abs()) ; execute (Set{ans(ans(ansSet{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ansSet{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ansSet{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ansSet{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ansSet{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ansSet{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ansSet{ans(ans(ans(Set{ans(ans(ans(Set{ans(ans(ans for bb : b do ( ans var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() := ans var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() + (bb - mid var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger())->abs() ; ans + (bb - mid_2)->abs() := ans + (bb - mid_2)->abs() + (bb - mid_2)->abs()), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min(), ans_2), ans_2), ans_2}->min())->display(), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min(), ans_2), ans_2), ans_2}->min())->display(), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min(), ans_2), ans_2), ans_2}->min())->display(), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min(), ans_2), ans_2), ans_2}->min())->display(), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min(), ans_2), ans_2), ans_2}->min())->display(), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min(), ans_2), ans_2), ans_2}->min())->display(), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min()), ans_2), ans_2), ans_2}->min(), ans_2), ans_2), ans_2}->min())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def A(m,n,s="% s"): print(s %("A(% d,% d)" %(m,n))) if m==0 : return n+1 if n==0 : return A(m-1,1,s) n2=A(m,n-1,s %("A(% d,%% s)" %(m-1))) return A(m-1,n2,s) print(A(1,2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (A(1, 2))->display(); operation A(m : OclAny, n : OclAny, s : String) : OclAny pre: true post: true activity: if s->oclIsUndefined() then s := "% s" else skip; execute (StringLib.format(s,(StringLib.format("A(% d,% d)",Sequence{m, n}))))->display() ; if m = 0 then ( return n + 1 ) else skip ; if n = 0 then ( return A(m - 1, 1, s) ) else skip ; var n2 : OclAny := A(m, n - 1, StringLib.format(s,(StringLib.format("A(% d,%% s)",(m - 1))))) ; return A(m - 1, n2, s); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def NumberOfRectangles(n,m): if(n % 2==0): return(n/2)*m elif(m % 2==0): return(m//2)*n return(n*m-1)//2 if __name__=="__main__" : n=3 m=3 print(NumberOfRectangles(n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 3 ; m := 3 ; execute (NumberOfRectangles(n, m))->display() ) else skip; operation NumberOfRectangles(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: if (n mod 2 = 0) then ( return (n / 2) * m ) else (if (m mod 2 = 0) then ( return (m div 2) * n ) else skip) ; return (n * m - 1) div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cen_octagonalnum(n): return(4*n*n-4*n+1) if __name__=='__main__' : n=6 print(n,"th Centered","octagonal number: ",cen_octagonalnum(n)) n=11 print(n,"th Centered","octagonal number: ",cen_octagonalnum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 6 ; execute (n)->display() ; n := 11 ; execute (n)->display() ) else skip; operation cen_octagonalnum(n : OclAny) : OclAny pre: true post: true activity: return (4 * n * n - 4 * n + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) a=x//11 if x % 11==0 : print(a*2) exit() if a*11<=x<=a*11+6 : print(x//11*2+1) else : print(x//11*2+2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := x div 11 ; if x mod 11 = 0 then ( execute (a * 2)->display() ; exit() ) else skip ; if (a * 11->compareTo(x)) <= 0 & (x <= a * 11 + 6) then ( execute (x div 11 * 2 + 1)->display() ) else ( execute (x div 11 * 2 + 2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) input=sys.stdin.readline from math import floor,ceil,sqrt,factorial,log from heapq import heappop,heappush,heappushpop from collections import Counter,defaultdict,deque from itertools import accumulate,permutations,combinations,product,combinations_with_replacement from bisect import bisect_left,bisect_right from copy import deepcopy inf=float('inf') mod=10**9+7 def pprint(*A): for a in A : print(*a,sep='\n') def INT_(n): return int(n)-1 def MI(): return map(int,input().split()) def MF(): return map(float,input().split()) def MI_(): return map(INT_,input().split()) def LI(): return list(MI()) def LI_(): return[int(x)-1 for x in input().split()] def LF(): return list(MF()) def LIN(n : int): return[I()for _ in range(n)] def LLIN(n : int): return[LI()for _ in range(n)] def LLIN_(n : int): return[LI_()for _ in range(n)] def LLI(): return[list(map(int,l.split()))for l in input()] def I(): return int(input()) def F(): return float(input()) def ST(): return input().replace('\n','') def main(): X=I() ans=X//11*2 if X % 11==0 : pass elif(X-X//11*11)<=6 : ans+=1 else : ans+=2 print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; skip ; skip ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation pprint(A : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name A))) for a : A do ( execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display()); operation INT_(n : OclAny) : OclAny pre: true post: true activity: return ("" + ((n)))->toInteger() - 1; operation MI() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation MF() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["double"])->apply(_x) ); operation MI_() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (INT_)->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return (MI()); operation LI_() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return (MF()); operation LIN(n : int) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (I())); operation LLIN(n : int) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI())); operation LLIN_(n : int) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI_())); operation LLI() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine()->select(l | true)->collect(l | (((l.split())->collect( _x | (OclType["int"])->apply(_x) )))); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation ST() : OclAny pre: true post: true activity: return input().replace(' ', ''); operation main() pre: true post: true activity: var X : OclAny := I() ; var ans : int := X div 11 * 2 ; if X mod 11 = 0 then ( skip ) else (if (X - X div 11 * 11) <= 6 then ( ans := ans + 1 ) else ( ans := ans + 2 ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil x=int(input()) print(x//11*2+ceil((x % 11)/6)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (x div 11 * 2 + ceil((x mod 11) / 6))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(): x=input() x=int(x) ans=0 ans+=(x//11)*2 x=x % 11 if x==0 : print(ans) exit() ans+=x//6 x=x % 6 if x==0 : print(ans) else : ans+=1 print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var x : String := (OclFile["System.in"]).readLine() ; x := ("" + ((x)))->toInteger() ; var ans : int := 0 ; ans := ans + (x div 11) * 2 ; x := StringLib.format(x,11) ; if x = 0 then ( execute (ans)->display() ; exit() ) else skip ; ans := ans + x div 6 ; x := StringLib.format(x,6) ; if x = 0 then ( execute (ans)->display() ) else ( ans := ans + 1 ; execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=list(map(int,input().split())) k=2 l=[] if n>2 : for i in range(2,n): if x[i-1]+x[i-2]==x[i]: l.append("1") else : l.append("0") b="".join(l) b.strip() k=b.split("0") c=[] for j in k : c.append(len(j)) if n>2 : print(max(c)+2) else : print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k : int := 2 ; var l : Sequence := Sequence{} ; if n > 2 then ( for i : Integer.subrange(2, n-1) do ( if x[i - 1+1] + x[i - 2+1] = x[i+1] then ( execute (("1") : l) ) else ( execute (("0") : l) )) ) else skip ; var b : String := StringLib.sumStringsWithSeparator((l), "") ; b->trim() ; k := b.split("0") ; var c : Sequence := Sequence{} ; for j : k do ( execute (((j)->size()) : c)) ; if n > 2 then ( execute ((c)->max() + 2)->display() ) else ( execute (n)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lst=sorted(list(map(int,input().split()))) if lst[1]-lst[0]>=1 : print(lst[1]*2-1) else : print(2*lst[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; if lst[1+1] - lst->first() >= 1 then ( execute (lst[1+1] * 2 - 1)->display() ) else ( execute (2 * lst[1+1])->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=n//11*2 tmp=ans*11/2 while tmptoInteger() ; var ans : int := n div 11 * 2 ; var tmp : double := ans * 11 / 2 ; while (tmp->compareTo(n)) < 0 do ( tmp := tmp + 6 ; ans := ans + 1 ; if (tmp->compareTo(n)) < 0 then ( tmp := tmp + 5 ; ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=set(map(int,input().split())) m=int(input()) b=set(map(int,input().split())) s_union=a.union(b) print(*sorted(s_union),sep="\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var s_union : OclAny := a.union(b) ; execute ((argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s_union)))))))) )))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) a=set([int(a)for a in input().split()]) m=int(input()) b=set([int(a)for a in input().split()]) c=a.union(b) sorted_c=sorted(c) for i in sorted_c : print(i) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Set := Set{}->union((input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())))) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Set := Set{}->union((input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())))) ; var c : OclAny := a.union(b) ; var sorted_c : Sequence := c->sort() ; for i : sorted_c do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) a_li=list(map(int,input().split())) b=int(input()) b_li=list(map(int,input().split())) answer=sorted(set(a_li+b_li)) ans=[print(i)for i in answer] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a_li : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b_li : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var answer : Sequence := Set{}->union((a_li->union(b_li)))->sort() ; var ans : Sequence := answer->select(i | true)->collect(i | ((i)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- setA=set() while True : try : a=input() s=set(map(int,input().split())) setA=setA.union(s) except EOFError : break for elem in sorted(setA): print(elem) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var setA : Set := Set{}->union(()) ; while true do ( try ( var a : String := (OclFile["System.in"]).readLine() ; var s : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; setA := setA.union(s)) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))) ; for elem : setA->sort() do ( execute (elem)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def union(n,m,a,b): i,j=0,0 while ib[j]: yield b[j] j+=1 else : yield a[i] i+=1 j+=1 while icompareTo(n)) < 0 & (j->compareTo(m)) < 0 do ( if (a[i+1]->compareTo(b[j+1])) < 0 then ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return a[i+1] ; i := i + 1 ) else (if (a[i+1]->compareTo(b[j+1])) > 0 then ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return b[j+1] ; j := j + 1 ) else ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return a[i+1] ; i := i + 1 ; j := j + 1 ) ) ) ; while (i->compareTo(n)) < 0 do ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return a[i+1] ; i := i + 1) ; while (j->compareTo(m)) < 0 do ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return b[j+1] ; j := j + 1); operation run() pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; m := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; b := input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; for v : union(n, m, a, b) do ( execute (v)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : N=0 times=[] try : N=int(input()) times=list(map(int,input().split())) except : break times.sort(reverse=True) ans=0 for i in range(len(times)): ans+=(i+1)*times[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var N : int := 0 ; var times : Sequence := Sequence{} ; try ( N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; times := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) catch (_e : OclException) do ( break) ; times := times->sort() ; var ans : int := 0 ; for i : Integer.subrange(0, (times)->size()-1) do ( ans := ans + (i + 1) * times[i+1]) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for j in range(100): n=int(input()) a=list(map(int,input().split())) a.sort() now=0 ans=0 for i in range(n): now+=a[i] ans+=now print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for j : Integer.subrange(0, 100-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var now : int := 0 ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( now := now + a[i+1] ; ans := ans + now) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import fileinput tokens=[] for line in fileinput.input(): tokens.append(list(map(int,line.strip().split()))) for i in range(len(tokens)): if i % 2==0 : continue else : S=0 token_s=sorted(tokens[i]) for i,name in enumerate(token_s): S+=name*(len(token_s)-i) print(S) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var tokens : Sequence := Sequence{} ; for line : fileinput.input() do ( execute ((((line->trim().split())->collect( _x | (OclType["int"])->apply(_x) ))) : tokens)) ; for i : Integer.subrange(0, (tokens)->size()-1) do ( if i mod 2 = 0 then ( continue ) else ( var S : int := 0 ; var token_s : Sequence := tokens[i+1]->sort() ; for _tuple : Integer.subrange(1, (token_s)->size())->collect( _indx | Sequence{_indx-1, (token_s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var name : OclAny := _tuple->at(_indx); S := S + name * ((token_s)->size() - i)) ; execute (S)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def sumItUp(List): result=[] for i in range(0,len(List)): result.append(sum(List[0 : i+1])) return sum(result) List=[] for i in sys.stdin : List.append(i) for i in range(1,len(List),2): List[i]=List[i].split() for j in range(0,len(List[i])): List[i][j]=int(List[i][j]) List[i]=sorted(List[i]) print(sumItUp(List[i])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; List := Sequence{} ; for i : OclFile["System.in"] do ( execute ((i) : List)) ; for i : Integer.subrange(1, (List)->size()-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( List[i+1] := List[i+1].split() ; for j : Integer.subrange(0, (List[i+1])->size()-1) do ( List[i+1][j+1] := ("" + ((List[i+1][j+1])))->toInteger()) ; List[i+1] := List[i+1]->sort() ; execute (sumItUp(List[i+1]))->display()); operation sumItUp(List : OclAny) : OclAny pre: true post: true activity: var result : Sequence := Sequence{} ; for i : Integer.subrange(0, (List)->size()-1) do ( execute (((List.subrange(0+1, i + 1))->sum()) : result)) ; return (result)->sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- var1=int(input()) for m in range(0,var1): OutCount=0 BaseCount=0 PointCount=0 for i in range(0,100): try : str1=input() if str1=='HIT' : BaseCount=BaseCount+1 if BaseCount==4 : PointCount=PointCount+1 BaseCount=3 elif str1=='HOMERUN' : PointCount=PointCount+BaseCount+1 BaseCount=0 elif str1=='OUT' : OutCount=OutCount+1 if OutCount==3 : print(PointCount) break except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var var1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for m : Integer.subrange(0, var1-1) do ( var OutCount : int := 0 ; var BaseCount : int := 0 ; var PointCount : int := 0 ; for i : Integer.subrange(0, 100-1) do ( try ( var str1 : String := (OclFile["System.in"]).readLine() ; if str1 = 'HIT' then ( BaseCount := BaseCount + 1 ; if BaseCount = 4 then ( PointCount := PointCount + 1 ; BaseCount := 3 ) else skip ) else (if str1 = 'HOMERUN' then ( PointCount := PointCount + BaseCount + 1 ; BaseCount := 0 ) else (if str1 = 'OUT' then ( OutCount := OutCount + 1 ; if OutCount = 3 then ( execute (PointCount)->display() ; break ) else skip ) else skip ) ) ) catch (_e : OclException) do ( break) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isAlphabaticOrder(s): n=len(s) c=[s[i]for i in range(len(s))] c.sort(reverse=False) for i in range(n): if(c[i]!=s[i]): return False return True if __name__=='__main__' : s="aabbbcc" if(isAlphabaticOrder(s)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( s := "aabbbcc" ; if (isAlphabaticOrder(s)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isAlphabaticOrder(s : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; var c : Sequence := Integer.subrange(0, (s)->size()-1)->select(i | true)->collect(i | (s[i+1])) ; c := c->sort() ; for i : Integer.subrange(0, n-1) do ( if (c[i+1] /= s[i+1]) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) l=list(map(int,input().split())) if n<=2 : print(n) return i=2 ans=0 while itoInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n <= 2 then ( execute (n)->display() ; return ) else skip ; var i : int := 2 ; var ans : int := 0 ; while (i->compareTo(n)) < 0 do ( var count : int := 2 ; while (i->compareTo(n)) < 0 & l[i+1] = l[i - 1+1] + l[i - 2+1] do ( i := i + 1 ; count := count + 1) ; ans := Set{ans, count}->max() ; i := i + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : num=int(input()) except : break times=list(map(int,input().split())) times.sort() ans=sum([(num-index)*time for index,time in enumerate(times)]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) catch (_e : OclException) do ( break) ; var times : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; times := times->sort() ; var ans : OclAny := (Integer.subrange(1, (times)->size())->collect( _indx | Sequence{_indx-1, (times)->at(_indx)} )->select(_tuple | true)->collect(_tuple | let index : OclAny = _tuple->at(1) in let time : OclAny = _tuple->at(2) in ((num - index) * time)))->sum() ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mat=[input()for _ in range(3)] print(mat[0][0],mat[1][1],mat[2][2],sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mat : Sequence := Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; execute (mat->first()->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=input() d=input() e=input() ans=c[0]+d[1]+e[2] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : String := (OclFile["System.in"]).readLine() ; var d : String := (OclFile["System.in"]).readLine() ; var e : String := (OclFile["System.in"]).readLine() ; var ans : OclAny := c->first() + d[1+1] + e[2+1] ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s='' for i in range(3): s+=input()[i] print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := '' ; for i : Integer.subrange(0, 3-1) do ( s := s + input()[i+1]) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input(); b=input(); c=input(); print(a[0]+b[1]+c[2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine(); var b : String := (OclFile["System.in"]).readLine(); var c : String := (OclFile["System.in"]).readLine(); execute (a->first() + b[1+1] + c[2+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : s=[list(input())for i in range(3)] print(s[0][0]+s[1][1]+s[2][2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var s : Sequence := Integer.subrange(0, 3-1)->select(i | true)->collect(i | (((OclFile["System.in"]).readLine())->characters())) ; execute (s->first()->first() + s[1+1][1+1] + s[2+1][2+1])->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline while True : n,h=map(int,input().split()) if n==0 : break ans=[] for i in range(h): c,a,b=input().split() a,b=int(a)-1,int(b)-1 if c=="xy" : ans+=[a+b*n+z*n**2 for z in range(n)] elif c=="xz" : ans+=[a+y*n+b*n**2 for y in range(n)] else : ans+=[x+a*n+b*n**2 for x in range(n)] print(n**3-len(set(ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; while true do ( var n : OclAny := null; var h : OclAny := null; Sequence{n,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, h-1) do ( var c : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{c,a,b} := input().split() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{("" + ((a)))->toInteger() - 1,("" + ((b)))->toInteger() - 1} ; if c = "xy" then ( ans := ans + Integer.subrange(0, n-1)->select(z | true)->collect(z | (a + b * n + z * (n)->pow(2))) ) else (if c = "xz" then ( ans := ans + Integer.subrange(0, n-1)->select(y | true)->collect(y | (a + y * n + b * (n)->pow(2))) ) else ( ans := ans + Integer.subrange(0, n-1)->select(x | true)->collect(x | (x + a * n + b * (n)->pow(2))) ) ) ) ; execute ((n)->pow(3) - (Set{}->union((ans)))->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): while True : n,h=map(int,input().split()) if n==0 : break s=set() for _ in[0]*h : t,*a=input().split() i,j=map(lambda x : int(x)-1,a) k=1 if t=="xy" : j*=n k=n**2 elif t=="xz" : j*=n**2 k=n else : i*=n j*=(n**2) s.update(range(i+j,i+j+k*n,k)) print(n**3-len(s)) if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( solve() ) else skip; operation solve() pre: true post: true activity: while true do ( var n : OclAny := null; var h : OclAny := null; Sequence{n,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var s : Set := Set{}->union(()) ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, h) do ( var t : OclAny := null; var a : OclAny := null; Sequence{t,a} := input().split() ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := (a)->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ) ; var k : int := 1 ; if t = "xy" then ( j := j * n ; k := (n)->pow(2) ) else (if t = "xz" then ( j := j * (n)->pow(2) ; k := n ) else ( i := i * n ; j := j * ((n)->pow(2)) ) ) ; execute ((Integer.subrange(i + j, i + j + k * n-1)->select( $x | ($x - i + j) mod k = 0 )) <: s)) ; execute ((n)->pow(3) - (s)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : N,H=map(int,input().split()) if N==H==0 : break s=set() for i in range(H): c,a,b=input().split(); a=int(a)-1 ; b=int(b)-1 if c=="xy" : s.update((a,b,i)for i in range(N)) if c=="xz" : s.update((a,i,b)for i in range(N)) if c=="yz" : s.update((i,a,b)for i in range(N)) print(N**3-len(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var N : OclAny := null; var H : OclAny := null; Sequence{N,H} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if N = H & (H == 0) then ( break ) else skip ; var s : Set := Set{}->union(()) ; for i : Integer.subrange(0, H-1) do ( var c : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{c,a,b} := input().split(); var a : double := ("" + ((a)))->toInteger() - 1; var b : double := ("" + ((b)))->toInteger() - 1 ; if c = "xy" then ( execute (((argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name b)))))) , (test (logical_test (comparison (expr (atom (name i))))))) )))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) ))))))))) <: s) ) else skip ; if c = "xz" then ( execute (((argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name i)))))) , (test (logical_test (comparison (expr (atom (name b))))))) )))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) ))))))))) <: s) ) else skip ; if c = "yz" then ( execute (((argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) , (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name b))))))) )))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) ))))))))) <: s) ) else skip) ; execute ((N)->pow(3) - (s)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B=map(int,input().split()) pattern1=A+A-1 pattern2=A+B pattern3=B+B-1 print(max(pattern1,pattern2,pattern3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var pattern1 : double := A + A - 1 ; var pattern2 : OclAny := A + B ; var pattern3 : double := B + B - 1 ; execute (Set{pattern1, pattern2, pattern3}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline while True : n,h=map(int,input().split()) if n==0 : break ans=[] for i in range(h): s=input() c=s[: 2] a,b=s[3 :].split() a,b=int(a)-1,int(b)-1 if c=="xy" : k=a+(b<<9) ans+=[k+(z<<18)for z in range(n)] elif c=="xz" : k=a+(b<<18) ans+=[k+(y<<9)for y in range(n)] else : k=(a<<9)+(b<<18) ans+=[k+x for x in range(n)] print(n**3-len(set(ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; while true do ( var n : OclAny := null; var h : OclAny := null; Sequence{n,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, h-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var c : OclAny := s.subrange(1,2) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := s.subrange(3+1).split() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{("" + ((a)))->toInteger() - 1,("" + ((b)))->toInteger() - 1} ; if c = "xy" then ( var k : OclAny := a + (b * (2->pow(9))) ; ans := ans + Integer.subrange(0, n-1)->select(z | true)->collect(z | (k + (z * (2->pow(18))))) ) else (if c = "xz" then ( k := a + (b * (2->pow(18))) ; ans := ans + Integer.subrange(0, n-1)->select(y | true)->collect(y | (k + (y * (2->pow(9))))) ) else ( k := (a * (2->pow(9))) + (b * (2->pow(18))) ; ans := ans + Integer.subrange(0, n-1)->select(x | true)->collect(x | (k + x)) ) ) ) ; execute ((n)->pow(3) - (Set{}->union((ans)))->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(x)for x in input().split()] if n<3 : print(n) exit() l=0 r=2 maxVal=2 while l<=r and rtoInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if n < 3 then ( execute (n)->display() ; exit() ) else skip ; var l : int := 0 ; var r : int := 2 ; var maxVal : int := 2 ; while (l->compareTo(r)) <= 0 & (r->compareTo(n)) < 0 do ( if a[r+1] = (a[r - 1+1] + a[r - 2+1]) then ( while (r->compareTo(n)) < 0 & a[r+1] = a[r - 1+1] + a[r - 2+1] do ( maxVal := Set{r - l + 1, maxVal}->max() ; r := r + 1) ; l := r - 2 ) else skip ; l := l + 1 ; r := r + 1) ; execute (maxVal)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,h=map(int,input().split()) if n==0 : break hit=set() for _ in range(h): c,a,b=input().split() if c=="xy" : add={(int(a),int(b),z)for z in range(1,n+1)} elif c=="xz" : add={(int(a),y,int(b))for y in range(1,n+1)} elif c=="yz" : add={(x,int(a),int(b))for x in range(1,n+1)} hit=hit | add print(n**3-len(hit)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var h : OclAny := null; Sequence{n,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var hit : Set := Set{}->union(()) ; for _anon : Integer.subrange(0, h-1) do ( var c : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{c,a,b} := input().split() ; if c = "xy" then ( var add : Set := Integer.subrange(1, n + 1-1)->select(z | true)->collect(z | Sequence{("" + ((a)))->toInteger(), ("" + ((b)))->toInteger(), z})->asSet() ) else (if c = "xz" then ( add := Integer.subrange(1, n + 1-1)->select(y | true)->collect(y | Sequence{("" + ((a)))->toInteger(), y, ("" + ((b)))->toInteger()})->asSet() ) else (if c = "yz" then ( add := Integer.subrange(1, n + 1-1)->select(x | true)->collect(x | Sequence{x, ("" + ((a)))->toInteger(), ("" + ((b)))->toInteger()})->asSet() ) else skip ) ) ; hit := MathLib.bitwiseOr(hit, add)) ; execute ((n)->pow(3) - (hit)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib,fractions,itertools def compute(): TARGET=fractions.Fraction(1,10) numprimes=0 for n in itertools.count(1,2): for i in range(4): if eulerlib.is_prime(n*n-i*(n-1)): numprimes+=1 if n>1 and fractions.Fraction(numprimes,n*2-1)display() ) else skip; operation compute() : OclAny pre: true post: true activity: var TARGET : OclAny := fractions.Fraction(1, 10) ; var numprimes : int := 0 ; for n : itertools->count(1, 2) do ( for i : Integer.subrange(0, 4-1) do ( if eulerlib.is_prime(n * n - i * (n - 1)) then ( numprimes := numprimes + 1 ) else skip) ; if n > 1 & (fractions.Fraction(numprimes, n * 2 - 1)->compareTo(TARGET)) < 0 then ( return ("" + ((n))) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math N,M=input().split() N=int(N) M=int(M) if abs(N-M)>1 : print(0) elif N==M : res=math.factorial(N)*math.factorial(M)*2 print(res % int(1e9+7)) else : res=math.factorial(N)*math.factorial(M) print(res % int(1e9+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := input().split() ; var N : int := ("" + ((N)))->toInteger() ; var M : int := ("" + ((M)))->toInteger() ; if (N - M)->abs() > 1 then ( execute (0)->display() ) else (if N = M then ( var res : double := MathLib.factorial(N) * MathLib.factorial(M) * 2 ; execute (res mod ("" + ((("1e9")->toReal() + 7)))->toInteger())->display() ) else ( res := MathLib.factorial(N) * MathLib.factorial(M) ; execute (res mod ("" + ((("1e9")->toReal() + 7)))->toInteger())->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- buf=input().split() N=int(buf[0]) M=int(buf[1]) thres=10**9+7 if abs(N-M)==1 : N=min(N,M) retVal=1 for i in range(1,N+1): retVal*=(i**2) if retVal>=thres : retVal=retVal % thres retVal*=(N+1) if retVal>=thres : retVal=retVal % thres print(retVal) elif N==M : retVal=2 for i in range(1,N+1): retVal*=(i**2) if retVal>=thres : retVal=retVal % thres print(retVal) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var buf : OclAny := input().split() ; var N : int := ("" + ((buf->first())))->toInteger() ; var M : int := ("" + ((buf[1+1])))->toInteger() ; var thres : double := (10)->pow(9) + 7 ; if (N - M)->abs() = 1 then ( N := Set{N, M}->min() ; var retVal : int := 1 ; for i : Integer.subrange(1, N + 1-1) do ( retVal := retVal * ((i)->pow(2)) ; if (retVal->compareTo(thres)) >= 0 then ( retVal := retVal mod thres ) else skip) ; retVal := retVal * (N + 1) ; if (retVal->compareTo(thres)) >= 0 then ( retVal := retVal mod thres ) else skip ; execute (retVal)->display() ) else (if N = M then ( retVal := 2 ; for i : Integer.subrange(1, N + 1-1) do ( retVal := retVal * ((i)->pow(2)) ; if (retVal->compareTo(thres)) >= 0 then ( retVal := retVal mod thres ) else skip) ; execute (retVal)->display() ) else ( execute (0)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=list(map(int,input().split())) MOD=10**9+7 MAX=max(n,m)+2 fact=[0]*(MAX) fact[0]=1 for i in range(1,MAX): fact[i]=(fact[i-1]*i)% MOD if abs(n-m)>1 : ans=0 else : if n==m : ans=fact[n]*fact[m]*2 % MOD else : ans=fact[n]*fact[m]% MOD print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var MOD : double := (10)->pow(9) + 7 ; var MAX : OclAny := Set{n, m}->max() + 2 ; var fact : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX)) ; fact->first() := 1 ; for i : Integer.subrange(1, MAX-1) do ( fact[i+1] := (fact[i - 1+1] * i) mod MOD) ; if (n - m)->abs() > 1 then ( var ans : int := 0 ) else ( if n = m then ( ans := fact[n+1] * fact[m+1] * 2 mod MOD ) else ( ans := fact[n+1] * fact[m+1] mod MOD ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,m=map(int,input().split()) mod=10**9+7 if abs(n-m)>1 : print(0) else : ans=1 for i in range(1,n+1): ans=ans*i % mod for j in range(1,m+1): ans=ans*j % mod if abs(n-m)==0 : print(2*ans % mod) else : print(ans % mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mod : double := (10)->pow(9) + 7 ; if (n - m)->abs() > 1 then ( execute (0)->display() ) else ( var ans : int := 1 ; for i : Integer.subrange(1, n + 1-1) do ( ans := ans * i mod mod) ; for j : Integer.subrange(1, m + 1-1) do ( ans := ans * j mod mod) ; if (n - m)->abs() = 0 then ( execute (2 * ans mod mod)->display() ) else ( execute (ans mod mod)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np n,m=map(int,input().split()) if abs(n-m)>1 : print(0) quit() mod=10**9+7 def cumprod(L,mod=mod): A=np.arange(L,dtype=np.int64) A[0]=1 Lsq=int(L**.5+1) A=np.resize(A,Lsq**2).reshape(Lsq,Lsq) for n in range(1,Lsq): A[:,n]*=A[:,n-1] A[:,n]%=mod for n in range(1,Lsq): A[n]*=A[n-1,-1] A[n]%=mod return A.ravel()[: L] fact=cumprod(2*10**6+10,mod) res=fact[n]*fact[m] if n==m : res*=2 print(res % mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (n - m)->abs() > 1 then ( execute (0)->display() ; quit() ) else skip ; var mod : double := (10)->pow(9) + 7 ; skip ; var fact : OclAny := cumprod(2 * (10)->pow(6) + 10, mod) ; var res : double := fact[n+1] * fact[m+1] ; if n = m then ( res := res * 2 ) else skip ; execute (res mod mod)->display(); operation cumprod(L : OclAny, mod : OclAny) : OclAny pre: true post: true activity: if mod->oclIsUndefined() then mod := mod else skip; var A : Sequence := MathLib.numericRange(L, (argument (test (logical_test (comparison (expr (atom (name dtype)))))) = (test (logical_test (comparison (expr (atom (name np)) (trailer . (name int64))))))), 1) ; A->first() := 1 ; var Lsq : int := ("" + (((L)->pow(.5) + 1)))->toInteger() ; A := np.resize(A, (Lsq)->pow(2)).reshape(Lsq, Lsq) ; for n : Integer.subrange(1, Lsq-1) do ( A->collect( _r | _r[n+1] ) := A->collect( _r | _r[n+1] ) * A->collect( _r | _r[n - 1+1] ) ; A->collect( _r | _r[n+1] ) := A->collect( _r | _r[n+1] ) mod mod) ; for n : Integer.subrange(1, Lsq-1) do ( A[n+1] := A[n+1] * A[n - 1+1]->last() ; A[n+1] := A[n+1] mod mod) ; return A.ravel().subrange(1,L); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- K=int(input()) N=50 a=K//N b=K % N l=a-b+N*2 m=a-b+N-1 L=[l for _ in range(b)] M=[m for _ in range(N-b)] print(N) print(" ".join(map(str,L+M))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var N : int := 50 ; var a : int := K div N ; var b : int := K mod N ; var l : double := a - b + N * 2 ; var m : double := a - b + N - 1 ; var L : Sequence := Integer.subrange(0, b-1)->select(_anon | true)->collect(_anon | (l)) ; var M : Sequence := Integer.subrange(0, N - b-1)->select(_anon | true)->collect(_anon | (m)) ; execute (N)->display() ; execute (StringLib.sumStringsWithSeparator(((L->union(M))->collect( _x | (OclType["String"])->apply(_x) )), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): s=input() v=[ord(i)for i in s] m=min(v) a=chr(m) v.remove(m) b=[chr(i)for i in v] b=''.join(b) print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var v : Sequence := s->characters()->select(i | true)->collect(i | ((i)->char2byte())) ; var m : OclAny := (v)->min() ; var a : String := (m)->byte2char() ; execute ((m) /: v) ; var b : Sequence := v->select(i | true)->collect(i | ((i)->byte2char())) ; b := StringLib.sumStringsWithSeparator((b), '') ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from datetime import date from math import factorial import functools from heapq import* from collections import deque import collections import math from collections import defaultdict,Counter import sys sys.setrecursionlimit(10**7) MOD=10**9+7 inf=float("inf") def main(): k=int(input()) if k==0 : print(3) print("2 2 2") exit() elif k==1 : print(3) print("1 0 3") exit() a=min(k,50) b=k % a ans=[i+k//a for i in range(a)] for i in range(b): ans.sort() for j in range(1,a): ans[j]-=1 ans[0]+=a print(a) print(*ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; var MOD : double := (10)->pow(9) + 7 ; var Math_PINFINITY : double := ("" + (("inf")))->toReal() ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if k = 0 then ( execute (3)->display() ; execute ("2 2 2")->display() ; exit() ) else (if k = 1 then ( execute (3)->display() ; execute ("1 0 3")->display() ; exit() ) else skip) ; var a : OclAny := Set{k, 50}->min() ; var b : int := k mod a ; var ans : Sequence := Integer.subrange(0, a-1)->select(i | true)->collect(i | (i + k div a)) ; for i : Integer.subrange(0, b-1) do ( ans := ans->sort() ; for j : Integer.subrange(1, a-1) do ( ans[j+1] := ans[j+1] - 1) ; ans->first() := ans->first() + a) ; execute (a)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) if k<=100*1000 : if k % 2 : print(2) print(k//2,2+k//2) else : print(2) print(1+k//2,1+k//2) else : mn=k//50 md=k % 50 print(50) ok=49+mn for i in range(50): if itoInteger() ; if (k->compareTo(100 * 1000)) <= 0 then ( if k mod 2 then ( execute (2)->display() ; execute (k div 2)->display() ) else ( execute (2)->display() ; execute (1 + k div 2)->display() ) ) else ( var mn : int := k div 50 ; var md : int := k mod 50 ; execute (50)->display() ; var ok : int := 49 + mn ; for i : Integer.subrange(0, 50-1) do ( if (i->compareTo(md)) < 0 then ( execute (ok + 50 - (md - 1))->display() ) else ( execute (ok - md)->display() )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): n=int(input()) arr=list(map(int,input().split())) if n<=2 : return print(n) res=2 left=0 for i in range(2,len(arr)): if arr[i]!=arr[i-1]+arr[i-2]: left=i-1 continue res=max(res,i-left+1) print(res) def main(): t=1 for _ in range(t): solution() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; main(); operation solution() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n <= 2 then ( return (n)->display() ) else skip ; var res : int := 2 ; var left : int := 0 ; for i : Integer.subrange(2, (arr)->size()-1) do ( if arr[i+1] /= arr[i - 1+1] + arr[i - 2+1] then ( left := i - 1 ; continue ) else skip ; res := Set{res, i - left + 1}->max()) ; execute (res)->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getlist(): return list(map(int,input().split())) K=int(input()) N=50 a=K//50 b=K % 50 ans=[] for i in range(b): ans.append(N+N+a-b) for i in range(N-b): ans.append(N-1+a-b) print(N) ans=list(map(str,ans)) print(" ".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var N : int := 50 ; var a : int := K div 50 ; var b : int := K mod 50 ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, b-1) do ( execute ((N + N + a - b) : ans)) ; for i : Integer.subrange(0, N - b-1) do ( execute ((N - 1 + a - b) : ans)) ; execute (N)->display() ; ans := ((ans)->collect( _x | (OclType["String"])->apply(_x) )) ; execute (StringLib.sumStringsWithSeparator((ans), " "))->display(); operation getlist() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): k=int(input()) if k==0 : print(4) print(3,3,3,3) return if k==1 : print(3) print(1,0,3) return if k<=50 : print(k) print(' '.join([str(k)]*k)) return print(50) res=[50+k//50-k % 50-1]*50 for i in range(k % 50): res[i]+=51 print(' '.join([str(i)for i in res])) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if k = 0 then ( execute (4)->display() ; execute (3)->display() ; return ) else skip ; if k = 1 then ( execute (3)->display() ; execute (1)->display() ; return ) else skip ; if k <= 50 then ( execute (k)->display() ; execute (StringLib.sumStringsWithSeparator((MatrixLib.elementwiseMult(Sequence{ ("" + ((k))) }, k)), ' '))->display() ; return ) else skip ; execute (50)->display() ; var res : Sequence := MatrixLib.elementwiseMult(Sequence{ 50 + k div 50 - k mod 50 - 1 }, 50) ; for i : Integer.subrange(0, k mod 50-1) do ( res[i+1] := res[i+1] + 51) ; execute (StringLib.sumStringsWithSeparator((res->select(i | true)->collect(i | (("" + ((i)))))), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def invertBits(n): x=int(math.log(n,2)) m=1<display(); operation invertBits(n : OclAny) : OclAny pre: true post: true activity: var x : int := ("" + (((n, 2)->log())))->toInteger() ; var m : int := 1 * (2->pow(x)) ; m := MathLib.bitwiseOr(m, m - 1) ; n := MathLib.bitwiseXor(n, m) ; return n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def largestCoprime(N): if N==6 : return 1 elif N % 4==0 : return N//2-1 elif N % 2==0 : return N//2-2 else : return(N-1)//2 if __name__=="__main__" : n=50 print(largestCoprime(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var n : int := 50 ; execute (largestCoprime(n))->display() ) else skip; operation largestCoprime(N : OclAny) : OclAny pre: true post: true activity: if N = 6 then ( return 1 ) else (if N mod 4 = 0 then ( return N div 2 - 1 ) else (if N mod 2 = 0 then ( return N div 2 - 2 ) else ( return (N - 1) div 2 ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def matrix_multiplication(M,N): R=[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]] for i in range(0,4): for j in range(0,4): for k in range(0,4): R[i][j]+=M[i][k]*N[k][j] for i in range(0,4): for j in range(0,4): print(R[i][j],end="") print("\n",end="") M=[[1,1,1,1],[2,2,2,2],[3,3,3,3],[4,4,4,4]] N=[[1,1,1,1],[2,2,2,2],[3,3,3,3],[4,4,4,4]] matrix_multiplication(M,N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; M := Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })))}->union(Sequence{Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 2 })))}->union(Sequence{Sequence{3}->union(Sequence{3}->union(Sequence{3}->union(Sequence{ 3 })))}->union(Sequence{ Sequence{4}->union(Sequence{4}->union(Sequence{4}->union(Sequence{ 4 }))) }))) ; N := Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })))}->union(Sequence{Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 2 })))}->union(Sequence{Sequence{3}->union(Sequence{3}->union(Sequence{3}->union(Sequence{ 3 })))}->union(Sequence{ Sequence{4}->union(Sequence{4}->union(Sequence{4}->union(Sequence{ 4 }))) }))) ; matrix_multiplication(M, N); operation matrix_multiplication(M : OclAny, N : OclAny) pre: true post: true activity: var R : Sequence := Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))}->union(Sequence{ Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))) }))) ; for i : Integer.subrange(0, 4-1) do ( for j : Integer.subrange(0, 4-1) do ( for k : Integer.subrange(0, 4-1) do ( R[i+1][j+1] := R[i+1][j+1] + M[i+1][k+1] * N[k+1][j+1]))) ; for i : Integer.subrange(0, 4-1) do ( for j : Integer.subrange(0, 4-1) do ( execute (R[i+1][j+1])->display()) ; execute ("\n")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=[] for i in range(n): s.append(input()) print(len(set(s))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : s)) ; execute ((Set{}->union((s)))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): import sys N=int(sys.stdin.readline()) presents=set() for _ in range(N): presents.add(sys.stdin.readline().rstrip()) print(len(presents)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var presents : Set := Set{}->union(()) ; for _anon : Integer.subrange(0, N-1) do ( execute ((sys.stdin.readLine().rstrip()) : presents)) ; execute ((presents)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for k in range(t): s=input() p=0 i=0 while(itoInteger() ; for k : Integer.subrange(0, t-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var p : int := 0 ; var i : int := 0 ; while ((i->compareTo((s)->size())) < 0) do ( if ((s[i+1]->compareTo(s[p+1])) < 0) then ( p := i ) else skip ; i := i + 1) ; execute (s[p+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) t=[] for i in range(677): t.append([]) x=n for i in range(n): a=input() if(len(a)<4): if(a in t[0]): x-=1 else : t[0].append(a) else : p=ord(a[0])*26+ord(a[1])-2618 if(a[2 :]in t[p]): x-=1 else : t[p].append(a[2 :]) print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : Sequence := Sequence{} ; for i : Integer.subrange(0, 677-1) do ( execute ((Sequence{}) : t)) ; var x : int := n ; for i : Integer.subrange(0, n-1) do ( var a : String := (OclFile["System.in"]).readLine() ; if ((a)->size() < 4) then ( if ((t->first())->includes(a)) then ( x := x - 1 ) else ( (expr (atom (name t)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))) ) ) else ( var p : double := (a->first())->char2byte() * 26 + (a[1+1])->char2byte() - 2618 ; if ((t[p+1])->includes(a.subrange(2+1))) then ( x := x - 1 ) else ( (expr (atom (name t)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name p)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) :)) ])))))))) )))) ) )) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(len(set(input()for _ in range(n)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((Set{}->union(((argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from decimal import* from itertools import permutations,combinations,combinations_with_replacement,product import math N=int(input()) l=[] for i in range(N): l.append(input()) l=sorted(l) last='' counter=0 for i in range(N): if(l[i]!=last): counter+=1 last=l[i] print(counter) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute (((OclFile["System.in"]).readLine()) : l)) ; l := l->sort() ; var last : String := '' ; var counter : int := 0 ; for i : Integer.subrange(0, N-1) do ( if (l[i+1] /= last) then ( counter := counter + 1 ) else skip ; last := l[i+1]) ; execute (counter)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lst=list(map(int,input().split())) cnt=2 z=2 if n==1 or n==2 : print(n) else : for i in range(2,n): if lst[i]==(lst[i-1]+lst[i-2]): cnt+=1 if cnt>z : z=cnt else : cnt=2 print(z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : int := 2 ; var z : int := 2 ; if n = 1 or n = 2 then ( execute (n)->display() ) else ( for i : Integer.subrange(2, n-1) do ( if lst[i+1] = (lst[i - 1+1] + lst[i - 2+1]) then ( cnt := cnt + 1 ; if (cnt->compareTo(z)) > 0 then ( z := cnt ) else skip ) else ( cnt := 2 )) ; execute (z)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split(' ')) c,d=map(int,input().split(' ')) if(c>=b-1 and c<(b+1)*2+1)or(d>=a-1 and d<(a+1)*2+1): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; if ((c->compareTo(b - 1)) >= 0 & (c->compareTo((b + 1) * 2 + 1)) < 0) or ((d->compareTo(a - 1)) >= 0 & (d->compareTo((a + 1) * 2 + 1)) < 0) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- al,ar=map(int,input().split()) bl,br=map(int,input().split()) if al-1<=br<=2*al+2 or ar-1<=bl<=2*ar+2 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var al : OclAny := null; var ar : OclAny := null; Sequence{al,ar} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var bl : OclAny := null; var br : OclAny := null; Sequence{bl,br} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (al - 1->compareTo(br)) <= 0 & (br <= 2 * al + 2) or (ar - 1->compareTo(bl)) <= 0 & (bl <= 2 * ar + 2) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- g=[int(x)for x in input().split()] b=[int(x)for x in input().split()] b.reverse() flag=False for i in range(0,2): if(g[i]>b[i]): diff=g[i]-b[i] if(diff>1): continue else : flag=True break else : temp=max(g[i],b[i])//min(g[i],b[i]) if(temp>4): continue elif(temp<=4 and min(g[i],b[i])==1): flag=True break elif(temp<3): flag=True break if(flag): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var g : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var b : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; b := b->reverse() ; var flag : boolean := false ; for i : Integer.subrange(0, 2-1) do ( if ((g[i+1]->compareTo(b[i+1])) > 0) then ( var diff : double := g[i+1] - b[i+1] ; if (diff > 1) then ( continue ) else ( flag := true ; break ) ) else ( var temp : int := Set{g[i+1], b[i+1]}->max() div Set{g[i+1], b[i+1]}->min() ; if (temp > 4) then ( continue ) else (if (temp <= 4 & Set{g[i+1], b[i+1]}->min() = 1) then ( flag := true ; break ) else (if (temp < 3) then ( flag := true ; break ) else skip ) ) )) ; if (flag) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import collections import copy import enum import functools import heapq import itertools import math import random import re import sys import time import string from typing import List sys.setrecursionlimit(3001) input=sys.stdin.readline a,b=map(int,map(int,input().split())) c,d=map(int,input().split()) if a-1<=d<=2*(a+1): print("YES") exit() if b-1<=c<=2*(b+1): print("YES") exit() print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(3001) ; var input : OclAny := (OclFile["System.in"]).readline ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->collect( _x | (OclType["int"])->apply(_x) ) ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a - 1->compareTo(d)) <= 0 & (d <= 2 * (a + 1)) then ( execute ("YES")->display() ; exit() ) else skip ; if (b - 1->compareTo(c)) <= 0 & (c <= 2 * (b + 1)) then ( execute ("YES")->display() ; exit() ) else skip ; execute ("NO")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(a,b): if a>=b+2 : return False if b>2*(a+1): return False return True a,b=map(int,input().split()) c,d=map(int,input().split()) if check(a,d)or check(b,c): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if check(a, d) or check(b, c) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); operation check(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a->compareTo(b + 2)) >= 0 then ( return false ) else skip ; if (b->compareTo(2 * (a + 1))) > 0 then ( return false ) else skip ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math M=256 def entropy_if_smallest(ctr,bound): ret=0 for v in ctr : if v==0 : continue ret-=(v/N)*math.log2(v/N) if ret>=bound : return None return ret def solve(src): ans_h=float('inf') ans=None for s in range(16): for a in range(16): for c in range(16): ctr=[0]*M r=s for i in src : r=(a*r+c)% M o=(i+r)% M ctr[o]+=1 h=entropy_if_smallest(ctr,ans_h) if h is not None : ans=(s,a,c) ans_h=h if ans_h==0 : return ans return ans while True : N=int(input()) if N==0 : break src=list(map(int,input().split())) print(' '.join(map(str,solve(src)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var M : int := 256 ; skip ; skip ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; src := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (StringLib.sumStringsWithSeparator(((solve(src))->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()); operation entropy_if_smallest(ctr : OclAny, bound : OclAny) : OclAny pre: true post: true activity: var ret : int := 0 ; for v : ctr do ( if v = 0 then ( continue ) else skip ; ret := ret - (v / N) * ; if (ret->compareTo(bound)) >= 0 then ( return null ) else skip) ; return ret; operation solve(src : OclAny) : OclAny pre: true post: true activity: var ans_h : double := ("" + (('inf')))->toReal() ; var ans : OclAny := null ; for s : Integer.subrange(0, 16-1) do ( for a : Integer.subrange(0, 16-1) do ( for c : Integer.subrange(0, 16-1) do ( ctr := MatrixLib.elementwiseMult(Sequence{ 0 }, M) ; var r : OclAny := s ; for i : src do ( r := (a * r + c) mod M ; var o : int := (i + r) mod M ; ctr[o+1] := ctr[o+1] + 1) ; var h : OclAny := entropy_if_smallest(ctr, ans_h) ; if not(h <>= null) then ( ans := Sequence{s, a, c} ; ans_h := h ; if ans_h = 0 then ( return ans ) else skip ) else skip))) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): s=input() v=s.find(min(s)) print(min(s),s[: v]+s[v+1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var v : int := s->indexOf((s)->min()) - 1 ; execute ((s)->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] while True : n=I() if n==0 : break ii=LI() m=inf r='-1' for s in range(16): for a in range(16): for c in range(16): t=s f=[0]*256 for i in ii : t=(a*t+c)% 256 f[(t+i)% 256]+=1 h=0 for i in range(256): if f[i]==0 : continue h-=f[i]/n*math.log(f[i]/n) if m>h+eps : m=h r='{}{}{}'.format(s,a,c) rr.append(r) return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var n : OclAny := I() ; if n = 0 then ( break ) else skip ; var ii : OclAny := LI() ; var m : double := Math_PINFINITY ; var r : String := '-1' ; for s : Integer.subrange(0, 16-1) do ( for a : Integer.subrange(0, 16-1) do ( for c : Integer.subrange(0, 16-1) do ( var t : OclAny := s ; var f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 256) ; for i : ii do ( t := (a * t + c) mod 256 ; f[(t + i) mod 256+1] := f[(t + i) mod 256+1] + 1) ; var h : int := 0 ; for i : Integer.subrange(0, 256-1) do ( if f[i+1] = 0 then ( continue ) else skip ; h := h - f[i+1] / n * (f[i+1] / n)->log()) ; if (m->compareTo(h + eps)) > 0 then ( m := h ; r := StringLib.interpolateStrings('{}{}{}', Sequence{s, a, c}) ) else skip))) ; execute ((r) : rr)) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math M=256 R=[[[[None]*(M+2)for i in range(16)]for j in range(16)]for k in range(16)] for s in range(16): for a in range(16): for c in range(16): R[s][a][c][0]=s for i in range(M+1): R[s][a][c][i+1]=(a*R[s][a][c][i]+c)% M while True : n=int(input()) if n==0 : break v=list(map(int,input().split())) hmin=1e9 smin=0 amin=0 cmin=0 for s in range(16): for a in range(16): for c in range(16): cnt=[0]*(M+1) for i in range(n): cnt[(v[i]+R[s][a][c][i+1])% M]+=1 h=0 for x in cnt : if x>0 : h-=math.log2(float(x)/n)*x if hselect(k | true)->collect(k | (Integer.subrange(0, 16-1)->select(j | true)->collect(j | (Integer.subrange(0, 16-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ null }, (M + 2)))))))) ; for s : Integer.subrange(0, 16-1) do ( for a : Integer.subrange(0, 16-1) do ( for c : Integer.subrange(0, 16-1) do ( R[s+1][a+1][c+1]->first() := s ; for i : Integer.subrange(0, M + 1-1) do ( R[s+1][a+1][c+1][i + 1+1] := (a * R[s+1][a+1][c+1][i+1] + c) mod M)))) ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var v : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var hmin : double := ("1e9")->toReal() ; var smin : int := 0 ; var amin : int := 0 ; var cmin : int := 0 ; for s : Integer.subrange(0, 16-1) do ( for a : Integer.subrange(0, 16-1) do ( for c : Integer.subrange(0, 16-1) do ( var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (M + 1)) ; for i : Integer.subrange(0, n-1) do ( cnt[(v[i+1] + R[s+1][a+1][c+1][i + 1+1]) mod M+1] := cnt[(v[i+1] + R[s+1][a+1][c+1][i + 1+1]) mod M+1] + 1) ; var h : int := 0 ; for x : cnt do ( if x > 0 then ( h := h - * x ) else skip) ; if (h->compareTo(hmin)) < 0 then ( Sequence{smin,amin,cmin,hmin} := Sequence{s,a,c,h} ) else skip))) ; execute (smin)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def dist(p1,p2): return math.sqrt((p1[0]-p2[0])**2+(p1[1]-p2[1])**2) def cross(p1,p2): return p1[0]*p2[1]-p1[1]*p2[0] def parse_point(line): tokens=line.split() return int(tokens[0]),int(tokens[1]) n=int(input()) pt=[parse_point(input())for _ in range(n)] res=1e100 pr1,pr2=None,None for i in range(len(pt)): pr1=pt[i-2] pr2=pt[i-1] cur=pt[i] p1=(pr1[0]-pr2[0],pr1[1]-pr2[1]) p2=(cur[0]-pr2[0],cur[1]-pr2[1]) c=dist(pr1,cur) if abs(cross(p1,p2)/2)/ctoInteger() ; var pt : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (parse_point((OclFile["System.in"]).readLine()))) ; var res : double := ("1e100")->toReal() ; var pr1 : OclAny := null; var pr2 : OclAny := null; Sequence{pr1,pr2} := Sequence{null,null} ; for i : Integer.subrange(0, (pt)->size()-1) do ( var pr1 : OclAny := pt[i - 2+1] ; var pr2 : OclAny := pt[i - 1+1] ; var cur : OclAny := pt[i+1] ; p1 := Sequence{pr1->first() - pr2->first(), pr1[1+1] - pr2[1+1]} ; p2 := Sequence{cur->first() - pr2->first(), cur[1+1] - pr2[1+1]} ; var c : OclAny := dist(pr1, cur) ; if ((cross(p1, p2) / 2)->abs() / c->compareTo(res)) < 0 then ( res := (cross(p1, p2) / 2)->abs() / c ) else skip) ; execute (res)->display(); operation dist(p1 : OclAny, p2 : OclAny) : OclAny pre: true post: true activity: return (((p1->first() - p2->first()))->pow(2) + ((p1[1+1] - p2[1+1]))->pow(2))->sqrt(); operation cross(p1 : OclAny, p2 : OclAny) : OclAny pre: true post: true activity: return p1->first() * p2[1+1] - p1[1+1] * p2->first(); operation parse_point(line : OclAny) : OclAny pre: true post: true activity: var tokens : OclAny := line.split() ; return ("" + ((tokens->first())))->toInteger(), ("" + ((tokens[1+1])))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import inf def vect(x,y): return abs(sum([x[i]*(y[(i+1)% 3]-y[(i+2)% 3])for i in range(3)])) def l(x,y): return((x[0]-x[2])**2+(y[0]-y[2])**2)**0.5 def h(x,y): return vect(x,y)/l(x,y) n=int(input()) x=[] y=[] for i in range(n): a,b=[int(x)for x in input().split()] x.append(a) y.append(b) x+=x[: 2] y+=y[: 2] dmin=inf for i in range(n): d=h(x[i : i+3],y[i : i+3])/2 if dmin>d : dmin=d print(dmin) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; x := Sequence{} ; y := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((a) : x) ; execute ((b) : y)) ; x := x + x.subrange(1,2) ; y := y + y.subrange(1,2) ; var dmin : double := Math_PINFINITY ; for i : Integer.subrange(0, n-1) do ( var d : double := h(x.subrange(i+1, i + 3), y.subrange(i+1, i + 3)) / 2 ; if (dmin->compareTo(d)) > 0 then ( dmin := d ) else skip) ; execute (dmin)->display(); operation vect(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return ((Integer.subrange(0, 3-1)->select(i | true)->collect(i | (x[i+1] * (y[(i + 1) mod 3+1] - y[(i + 2) mod 3+1]))))->sum())->abs(); operation l(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return ((((x->first() - x[2+1]))->pow(2) + ((y->first() - y[2+1]))->pow(2)))->pow(0.5); operation h(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return vect(x, y) / l(x, y); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) print(n//2*6) for i in range(0,n,2): print(2,i+1,i+2) print(1,i+1,i+2) print(1,i+1,i+2) print(2,i+1,i+2) print(1,i+1,i+2) print(1,i+1,i+2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (n div 2 * 6)->display() ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( execute (2)->display() ; execute (1)->display() ; execute (1)->display() ; execute (2)->display() ; execute (1)->display() ; execute (1)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math data=sys.stdin.read().split() data_ptr=0 def data_next(): global data_ptr,data data_ptr+=1 return data[data_ptr-1] N=int(data_next()) arr=list(zip(map(int,data[1 : : 2]),map(int,data[2 : : 2]))) def cross(x1,y1,x2,y2): return x1*y2-x2*y1 def dist(x,y): return math.sqrt(x*x+y*y) ans=4000000000.0 for i in range(N): x1,y1=arr[i-1] x2,y2=arr[i] x1-=arr[i-2][0] x2-=arr[i-2][0] y1-=arr[i-2][1] y2-=arr[i-2][1] ans=min(ans,abs(cross(x1,y1,x2,y2)/dist(x2,y2)/2)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute data_ptr : OclAny; attribute data : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; var data : OclAny := sys.stdin.readAll().split() ; var data_ptr : int := 0 ; skip ; var N : int := ("" + ((data_next())))->toInteger() ; var arr : Sequence := (Integer.subrange(1, (data(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->collect( _x | (OclType["int"])->apply(_x) )->size())->collect( _indx | Sequence{(data(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->collect( _x | (OclType["int"])->apply(_x) )->at(_indx), (data(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->collect( _x | (OclType["int"])->apply(_x) )->at(_indx)} )) ; skip ; skip ; var ans : double := 4000000000.0 ; for i : Integer.subrange(0, N-1) do ( Sequence{x1,y1} := arr[i - 1+1] ; Sequence{x2,y2} := arr[i+1] ; x1 := x1 - arr[i - 2+1]->first() ; x2 := x2 - arr[i - 2+1]->first() ; y1 := y1 - arr[i - 2+1][1+1] ; y2 := y2 - arr[i - 2+1][1+1] ; ans := Set{ans, (cross(x1, y1, x2, y2) / dist(x2, y2) / 2)->abs()}->min()) ; execute (ans)->display(); operation data_next() : OclAny pre: true post: true activity: skip; skip ; data_ptr := data_ptr + 1 ; return data[data_ptr - 1+1]; operation cross(x1 : OclAny, y1 : OclAny, x2 : OclAny, y2 : OclAny) : OclAny pre: true post: true activity: return x1 * y2 - x2 * y1; operation dist(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return (x * x + y * y)->sqrt(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,hypot def dist(a,b,c): return abs((c[1]-a[1])*b[0]-(c[0]-a[0])*b[1]+c[0]*a[1]-c[1]*a[0])/hypot(c[0]-a[0],c[1]-a[1])/2 n=int(input()) liste=[list(map(int,input().split(" ")))for _ in range(n)] d=-1 for i in range(n): if i==n-1 : a,b,c=liste[n-2],liste[n-1],liste[0] else : a,b,c=liste[i-1],liste[i],liste[i+1] if d!=-1 : d=min(d,dist(a,b,c)) else : d=dist(a,b,c) print(d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var liste : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )))) ; var d : int := -1 ; for i : Integer.subrange(0, n-1) do ( if i = n - 1 then ( Sequence{a,b,c} := Sequence{liste[n - 2+1],liste[n - 1+1],liste->first()} ) else ( Sequence{a,b,c} := Sequence{liste[i - 1+1],liste[i+1],liste[i + 1+1]} ) ; if d /= -1 then ( d := Set{d, dist(a, b, c)}->min() ) else ( d := dist(a, b, c) )) ; execute (d)->display(); operation dist(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: return ((c[1+1] - a[1+1]) * b->first() - (c->first() - a->first()) * b[1+1] + c->first() * a[1+1] - c[1+1] * a->first())->abs() / hypot(c->first() - a->first(), c[1+1] - a[1+1]) / 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* n=int(input()) r=[list(map(int,input().split()))for _ in range(n)] ans=10**20 for i in range(n): x0,y0=r[(i+n-1)% n] x1,y1=r[(i+1)% n] x,y=r[i] ans=min(ans,abs((y1-y0)*x-(x1-x0)*y-(x0*y1-x1*y0))/sqrt((x1-x0)**2+(y1-y0)**2)) print(ans/2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ans : double := (10)->pow(20) ; for i : Integer.subrange(0, n-1) do ( var x0 : OclAny := null; var y0 : OclAny := null; Sequence{x0,y0} := r[(i + n - 1) mod n+1] ; var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := r[(i + 1) mod n+1] ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := r[i+1] ; ans := Set{ans, ((y1 - y0) * x - (x1 - x0) * y - (x0 * y1 - x1 * y0))->abs() / sqrt(((x1 - x0))->pow(2) + ((y1 - y0))->pow(2))}->min()) ; execute (ans / 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minimumOperations(arr,n): brr=[0,0,0,0] for i in range(n): brr[arr[i]% 4]+=1 ; if((brr[1]+2*brr[2]+3*brr[3])% 4==0): min_opr=min(brr[3],brr[1]) brr[3]-=min_opr brr[1]-=min_opr min_opr+=brr[2]//2 brr[2]%=2 if(brr[2]): min_opr+=2 brr[2]=0 if(brr[3]): brr[3]-=2 if(brr[1]): brr[1]-=2 if(brr[1]): min_opr+=(brr[1]//4)*3 if(brr[3]): min_opr+=(brr[3]//4)*3 return min_opr return-1 arr=[1,2,3,1,2,3,8] n=len(arr) print(minimumOperations(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 8 })))))) ; n := (arr)->size() ; execute (minimumOperations(arr, n))->display(); operation minimumOperations(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var brr : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))) ; for i : Integer.subrange(0, n-1) do ( brr[arr[i+1] mod 4+1] := brr[arr[i+1] mod 4+1] + 1;) ; if ((brr[1+1] + 2 * brr[2+1] + 3 * brr[3+1]) mod 4 = 0) then ( var min_opr : OclAny := Set{brr[3+1], brr[1+1]}->min() ; brr[3+1] := brr[3+1] - min_opr ; brr[1+1] := brr[1+1] - min_opr ; min_opr := min_opr + brr[2+1] div 2 ; brr[2+1] := brr[2+1] mod 2 ; if (brr[2+1]) then ( min_opr := min_opr + 2 ; brr[2+1] := 0 ; if (brr[3+1]) then ( brr[3+1] := brr[3+1] - 2 ) else skip ; if (brr[1+1]) then ( brr[1+1] := brr[1+1] - 2 ) else skip ) else skip ; if (brr[1+1]) then ( min_opr := min_opr + (brr[1+1] div 4) * 3 ) else skip ; if (brr[3+1]) then ( min_opr := min_opr + (brr[3+1] div 4) * 3 ) else skip ; return min_opr ) else skip ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) box=list(map(int,input().split())) q=int(input()) for _ in range(q): b,m,e=map(int,input().split()) _box=list(box) for k in range(e-b): _box[b+(k+(e-m))%(e-b)]=box[b+k] box=_box print(*box) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var box : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( var b : OclAny := null; var m : OclAny := null; var e : OclAny := null; Sequence{b,m,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var _box : Sequence := (box) ; for k : Integer.subrange(0, e - b-1) do ( _box[b + (k + (e - m)) mod (e - b)+1] := box[b + k+1]) ; box := _box) ; execute ((argument * (test (logical_test (comparison (expr (atom (name box))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): s=input() w=sorted(s)[0] i=s.index(w) print(w,s[0 : i]+s[i+1 : :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var w : OclAny := sorted(s)->first() ; var i : int := s->indexOf(w) - 1 ; execute (w)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : num_a=int(input()) a=list(map(lambda x : int(x),input().split())) num_query=int(input()) for _ in range(num_query): begin,margin,end=map(lambda x : int(x),input().split()) diff=end-margin modulo=end-begin a_sliced=a[begin : end] a_sliced=[a_sliced[(idx+len(a_sliced)-diff)% modulo]for idx in range(len(a_sliced))] a[begin : end]=a_sliced print(" ".join([str(elem)for elem in a])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var num_a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) )) ; var num_query : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, num_query-1) do ( var begin : OclAny := null; var margin : OclAny := null; var end : OclAny := null; Sequence{begin,margin,end} := (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ) ; var diff : double := end - margin ; var modulo : double := end - begin ; var a_sliced : OclAny := a.subrange(begin+1, end) ; a_sliced := Integer.subrange(0, (a_sliced)->size()-1)->select(idx | true)->collect(idx | (a_sliced[(idx + (a_sliced)->size() - diff) mod modulo+1])) ; a.subrange(begin+1, end) := a_sliced) ; execute (StringLib.sumStringsWithSeparator((a->select(elem | true)->collect(elem | (("" + ((elem)))))), " "))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def resolve(): from collections import deque N=int(input()) A=[int(i)for i in input().split()] Q=int(input()) ans=[i for i in range(N)] for _ in range(Q): b,m,e=[int(i)for i in input().split()] tmp=deque(ans[b : e]) tmp.rotate(e-m) for i in range(b,e): ans[i]=tmp[i-b] prt=[0]*N for i in range(N): prt[i]=A[ans[i]] print(*prt) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; resolve(); operation resolve() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (i)) ; for _anon : Integer.subrange(0, Q-1) do ( var b : OclAny := null; var m : OclAny := null; var e : OclAny := null; Sequence{b,m,e} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var tmp : Sequence := (ans.subrange(b+1, e)) ; tmp.rotate(e - m) ; for i : Integer.subrange(b, e-1) do ( ans[i+1] := tmp[i - b+1])) ; var prt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for i : Integer.subrange(0, N-1) do ( prt[i+1] := A[ans[i+1]+1]) ; execute ((argument * (test (logical_test (comparison (expr (atom (name prt))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque import sys input=sys.stdin.readline def main(): n1=int(input()) l1=list(map(int,input().split())) l2=[] for i in range(int(input())): (b,m,e)=map(int,input().split()) for k in range(b): l2.append(l1[k]) for k in range(m,e): l2.append(l1[k]) for k in range(b,m): l2.append(l1[k]) for k in range(e,len(l1)): l2.append(l1[k]) l1=l2 l2=[] print(" ".join(map(str,l1))) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { suite`nestedAttributeDefinitions operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var Sequence{b, m, e} : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation main(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; var n1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l2 : Sequence := Sequence{} ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (suite); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def partial_rotate(origin,begin,middle,end): list1=origin[: begin] list2=origin[begin : end] list3=origin[end :] list2_sub1=list2[middle-begin :] list2_sub2=list2[: middle-begin] return list1+list2_sub1+list2_sub2+list3 if __name__=='__main__' : N=int(input()) A=list(map(int,input().split())) Q=int(input()) for i in range(Q): b,m,e=map(int,input().split()) A=partial_rotate(A,b,m,e) print(' '.join(map(str,A))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, Q-1) do ( var b : OclAny := null; var m : OclAny := null; var e : OclAny := null; Sequence{b,m,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; A := partial_rotate(A, b, m, e)) ; execute (StringLib.sumStringsWithSeparator(((A)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ) else skip; operation partial_rotate(origin : OclAny, begin : OclAny, middle : OclAny, end : OclAny) : OclAny pre: true post: true activity: var list1 : OclAny := origin.subrange(1,begin) ; var list2 : OclAny := origin.subrange(begin+1, end) ; var list3 : OclAny := origin.subrange(end+1) ; var list2_sub1 : OclAny := list2.subrange(middle - begin+1) ; var list2_sub2 : OclAny := list2.subrange(1,middle - begin) ; return list1 + list2_sub1 + list2_sub2 + list3; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() a=int(s[0 : 2]) b=int(s[2 : 4]) if(a>0 and a<13)and(b>0 and b<13): print("AMBIGUOUS") elif a>0 and a<13 : print("MMYY") elif b>0 and b<13 : print("YYMM") else : print("NA") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var a : int := ("" + ((s.subrange(0+1, 2))))->toInteger() ; var b : int := ("" + ((s.subrange(2+1, 4))))->toInteger() ; if (a > 0 & a < 13) & (b > 0 & b < 13) then ( execute ("AMBIGUOUS")->display() ) else (if a > 0 & a < 13 then ( execute ("MMYY")->display() ) else (if b > 0 & b < 13 then ( execute ("YYMM")->display() ) else ( execute ("NA")->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n=int(input()) w=list(map(int,input().split())) d=[1,2,2,1,2,2] print(6*n//2) for i in range(n//2): for j in range(6): print(d[j],i*2+1,i*2+2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 2 }))))) ; execute (6 * n div 2)->display() ; for i : Integer.subrange(0, n div 2-1) do ( for j : Integer.subrange(0, 6-1) do ( execute (d[j+1])->display()))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(S : int): a=S//100 b=S % 100 if a<1 or a>12 : if b<1 or b>12 : print('NA') else : print('YYMM') else : if b<1 or b>12 : print('MMYY') else : print('AMBIGUOUS') return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() S=int(next(tokens)) solve(S) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(S : int) pre: true post: true activity: var a : int := S div 100 ; var b : int := S mod 100 ; if a < 1 or a > 12 then ( if b < 1 or b > 12 then ( execute ('NA')->display() ) else ( execute ('YYMM')->display() ) ) else ( if b < 1 or b > 12 then ( execute ('MMYY')->display() ) else ( execute ('AMBIGUOUS')->display() ) ) ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var S : int := ("" + (((tokens).next())))->toInteger() ; solve(S); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() b=int(s[: 2]) a=int(s[2 :]) def yorm(i): flag='none' if 0toInteger() ; var a : int := ("" + ((s.subrange(2+1))))->toInteger() ; skip ; var bf : OclAny := yorm(b) ; var af : OclAny := yorm(a) ; var ans : OclAny := bf + af ; if (ans)->size() /= 4 then ( ans := 'NA' ) else skip ; if ans = 'MMMM' then ( ans := 'AMBIGUOUS' ) else skip ; if ans = 'YYYY' then ( ans := 'NA' ) else skip ; execute (ans)->display(); operation yorm(i : OclAny) : OclAny pre: true post: true activity: var flag : String := 'none' ; if 0 < i & (i <= 12) then ( flag := 'MM' ) else (if i < 100 then ( flag := 'YY' ) else skip) ; return flag; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys S=input() if int(S[2 :])in range(1,13): if int(S[: 2])in range(1,13): print('AMBIGUOUS') sys.exit() else : print('YYMM') sys.exit() elif int(S[: 2])in range(1,13): print('MMYY') sys.exit() else : print('NA') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var S : String := (OclFile["System.in"]).readLine() ; if (Integer.subrange(1, 13-1))->includes(("" + ((S.subrange(2+1))))->toInteger()) then ( if (Integer.subrange(1, 13-1))->includes(("" + ((S.subrange(1,2))))->toInteger()) then ( execute ('AMBIGUOUS')->display() ; sys.exit() ) else ( execute ('YYMM')->display() ; sys.exit() ) ) else (if (Integer.subrange(1, 13-1))->includes(("" + ((S.subrange(1,2))))->toInteger()) then ( execute ('MMYY')->display() ; sys.exit() ) else ( execute ('NA')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=int(a[: 2]) c=int(a[2 :]) if b>12 and c>12 : print("NA") elif b>12 or b==0 : if c<1 : print("NA") else : print("YYMM") elif c>12 or c==0 : if b<1 : print("NA") else : print("MMYY") else : print("AMBIGUOUS") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : int := ("" + ((a.subrange(1,2))))->toInteger() ; var c : int := ("" + ((a.subrange(2+1))))->toInteger() ; if b > 12 & c > 12 then ( execute ("NA")->display() ) else (if b > 12 or b = 0 then ( if c < 1 then ( execute ("NA")->display() ) else ( execute ("YYMM")->display() ) ) else (if c > 12 or c = 0 then ( if b < 1 then ( execute ("NA")->display() ) else ( execute ("MMYY")->display() ) ) else ( execute ("AMBIGUOUS")->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): s=input() k=sorted(s) print(k[0],end='') l=list(s) l.remove(k[0]) p=''.join(l) print(p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var k : Sequence := s->sort() ; execute (k->first())->display() ; var l : Sequence := (s)->characters() ; execute ((k->first()) /: l) ; var p : String := StringLib.sumStringsWithSeparator((l), '') ; execute (p)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checksum(n): if n==0 : print("-1 0 1") return 0 inc=0 if n>0 : inc=1 else : inc=-1 for i in range(0,n-1,inc): if i+i+1+i+2==n : print(i," ",i+1," ",i+2) return 0 print("-1") n=6 checksum(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 6 ; checksum(n); operation checksum(n : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( execute ("-1 0 1")->display() ; return 0 ) else skip ; var inc : int := 0 ; if n > 0 then ( inc := 1 ) else ( inc := -1 ) ; for i : Integer.subrange(0, n - 1-1)->select( $x | ($x - 0) mod inc = 0 ) do ( if i + i + 1 + i + 2 = n then ( execute (i)->display() ; return 0 ) else skip) ; execute ("-1")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checksum(n): if n==0 : print("-2-1 0 1 2") return 0 inc=0 if n>0 : inc=1 else : inc=-1 for i in range(0,n-3,inc): if i+i+1+i+2+i+3+i+4==n : print(i," ",i+1," ",i+2," ",i+3," ",i+4) return 0 print("-1") n=15 checksum(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 15 ; checksum(n); operation checksum(n : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( execute ("-2-1 0 1 2")->display() ; return 0 ) else skip ; var inc : int := 0 ; if n > 0 then ( inc := 1 ) else ( inc := -1 ) ; for i : Integer.subrange(0, n - 3-1)->select( $x | ($x - 0) mod inc = 0 ) do ( if i + i + 1 + i + 2 + i + 3 + i + 4 = n then ( execute (i)->display() ; return 0 ) else skip) ; execute ("-1")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in[0]*int(input()): input(); a=[*map(int,input().split())]; b=[y for x,y,z in zip([0]+a,a,a[1 :]+[0])if 0>x | ztoInteger()) do ( input(); var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var b : boolean := Integer.subrange(1, Sequence{ 0 }->union(a)->size())->collect( _indx | Sequence{Sequence{ 0 }->union(a)->at(_indx), a->at(_indx)} )->select(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in 0 > MathLib.bitwiseOr(x, z) & (MathLib.bitwiseOr(x, z) < y))->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (y)) or Sequence{ 0 }; var l : OclAny := (b)->min(); var m : OclAny := (Sequence{ ((b)->max() - l + 1) div 2 }->union(Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), a->tail()->at(_indx)} )->select(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in MathLib.bitwiseAnd(MathLib.bitwiseNot(x), MathLib.bitwiseNot(y)))->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in ((x - y)->abs()))))->max(); execute (m)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math t=int(input()) for i in range(0,t): n=int(input()) l=input().split() m=[] b=[] for j in range(0,n-1): x=int(l[j]) y=int(l[j+1]) if x!=-1 and y!=-1 : m.append(abs(x-y)) if x==-1 and y!=-1 : b.append(y) if x!=-1 and y==-1 : b.append(x) b.sort() m.sort() mx=0 mn=0 if len(m)!=0 : mx=m[len(m)-1] mk=0 if len(b)!=0 : mk=math.ceil((b[len(b)-1]-b[0])/2) if mx>mk : mn=math.ceil((b[len(b)-1]+b[0])/2) else : mn=math.ceil((b[len(b)-1]+b[0])/2) mx=mn-b[0] print(mx,mn) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : OclAny := input().split() ; var m : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; for j : Integer.subrange(0, n - 1-1) do ( var x : int := ("" + ((l[j+1])))->toInteger() ; var y : int := ("" + ((l[j + 1+1])))->toInteger() ; if x /= -1 & y /= -1 then ( execute (((x - y)->abs()) : m) ) else skip ; if x = -1 & y /= -1 then ( execute ((y) : b) ) else skip ; if x /= -1 & y = -1 then ( execute ((x) : b) ) else skip) ; b := b->sort() ; m := m->sort() ; var mx : int := 0 ; var mn : int := 0 ; if (m)->size() /= 0 then ( mx := m[(m)->size() - 1+1] ) else skip ; var mk : int := 0 ; if (b)->size() /= 0 then ( mk := ((b[(b)->size() - 1+1] - b->first()) / 2)->ceil() ; if (mx->compareTo(mk)) > 0 then ( mn := ((b[(b)->size() - 1+1] + b->first()) / 2)->ceil() ) else ( mn := ((b[(b)->size() - 1+1] + b->first()) / 2)->ceil() ; mx := mn - b->first() ) ) else skip ; execute (mx)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def motaracksBirthday(n,array): c=0 l=[] for x in range(n): if array[x]!=-1 : if x==0 and array[x+1]==-1 : l.append(array[x]) elif x==n-1 and array[n-2]==-1 : l.append(array[x]) else : if x>0 and xtoInteger() ; for _anon : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; l := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : OclAny := motaracksBirthday(n, l) ; execute (ans->first())->display()); operation motaracksBirthday(n : OclAny, array : OclAny) : OclAny pre: true post: true activity: var c : int := 0 ; var l : Sequence := Sequence{} ; for x : Integer.subrange(0, n-1) do ( if array[x+1] /= -1 then ( if x = 0 & array[x + 1+1] = -1 then ( execute ((array[x+1]) : l) ) else (if x = n - 1 & array[n - 2+1] = -1 then ( execute ((array[x+1]) : l) ) else ( if x > 0 & (x->compareTo(n - 1)) < 0 & (array[x - 1+1] = -1 or array[x + 1+1] = -1) then ( execute ((array[x+1]) : l) ) else skip ) ) ) else skip) ; c := (l)->size() ; if c = 0 then ( var mean : int := 0 ) else ( mean := ((l)->min() + (l)->max()) div 2 ) ; var md : int := 0 ; for x : Integer.subrange(0, n-1) do ( if array[x+1] = -1 then ( array[x+1] := mean ) else skip) ; for x : Integer.subrange(1, n-1) do ( var d : double := (array[x+1] - array[x - 1+1])->abs() ; md := Set{d, md}->max()) ; return md, mean; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) res=0 a=list(map(int,input().split())) mina=float('inf') maxa=0 res=0 for i in range(n): if a[i]==-1 : if i>0 and a[i-1]!=-1 : mina=min(mina,a[i-1]) maxa=max(maxa,a[i-1]) if i0 : ans=max(ans,abs(a[i]-a[i-1])) print('{}{}'.format(ans,res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : int := 0 ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mina : double := ("" + (('inf')))->toReal() ; var maxa : int := 0 ; res := 0 ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = -1 then ( if i > 0 & a[i - 1+1] /= -1 then ( mina := Set{mina, a[i - 1+1]}->min() ; maxa := Set{maxa, a[i - 1+1]}->max() ) else skip ; if (i->compareTo(n - 1)) < 0 & a[i + 1+1] /= -1 then ( mina := Set{mina, a[i + 1+1]}->min() ; maxa := Set{maxa, a[i + 1+1]}->max() ) else skip ) else skip) ; if mina = ("" + (('inf')))->toReal() then ( execute (StringLib.interpolateStrings('{}{}', Sequence{0, 1}))->display() ) else ( res := (maxa + mina) div 2 ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = -1 then ( a[i+1] := res ) else skip ; if i > 0 then ( ans := Set{ans, (a[i+1] - a[i - 1+1])->abs()}->max() ) else skip) ; execute (StringLib.interpolateStrings('{}{}', Sequence{ans, res}))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input for _ in range(int(I())): n,__=int(I()),I() print(3*n) for i in range(1,n+1,2): print(1,i,i+1) print(2,i,i+1) print(1,i,i+1) print(1,i,i+1) print(2,i,i+1) print(1,i,i+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; for _anon : Integer.subrange(0, ("" + ((I())))->toInteger()-1) do ( var n : OclAny := null; var __ : OclAny := null; Sequence{n,__} := Sequence{("" + ((I())))->toInteger(),I()} ; execute (3 * n)->display() ; for i : Integer.subrange(1, n + 1-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( execute (1)->display() ; execute (2)->display() ; execute (1)->display() ; execute (1)->display() ; execute (2)->display() ; execute (1)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t=int(input()) ans=[] inf=pow(10,9)+1 for _ in range(t): n=int(input()) a=[0]+list(map(int,input().split()))+[0] ma,mi=-inf,inf for i in range(1,n+1): if not a[i]==-1 and min(a[i-1],a[i+1])==-1 : ma=max(ma,a[i]) mi=min(mi,a[i]) m0=0 for i in range(1,n): if min(a[i],a[i+1])>-1 : m0=max(m0,abs(a[i]-a[i+1])) m,k=0,0 if mi<=ma : m=max((ma-mi+1)//2,m0) k=mi+(ma-mi+1)//2 ans.append(" ".join(map(str,(m,k)))) sys.stdout.write("\n".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; var Math_PINFINITY : double := (10)->pow(9) + 1 ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->union(Sequence{ 0 }) ; var ma : OclAny := null; var mi : OclAny := null; Sequence{ma,mi} := Sequence{-Math_PINFINITY,Math_PINFINITY} ; for i : Integer.subrange(1, n + 1-1) do ( if not(a[i+1] = -1) & Set{a[i - 1+1], a[i + 1+1]}->min() = -1 then ( var ma : OclAny := Set{ma, a[i+1]}->max() ; var mi : OclAny := Set{mi, a[i+1]}->min() ) else skip) ; var m0 : int := 0 ; for i : Integer.subrange(1, n-1) do ( if Set{a[i+1], a[i + 1+1]}->min() > -1 then ( m0 := Set{m0, (a[i+1] - a[i + 1+1])->abs()}->max() ) else skip) ; var m : OclAny := null; var k : OclAny := null; Sequence{m,k} := Sequence{0,0} ; if (mi->compareTo(ma)) <= 0 then ( var m : OclAny := Set{(ma - mi + 1) div 2, m0}->max() ; var k : OclAny := mi + (ma - mi + 1) div 2 ) else skip ; execute ((StringLib.sumStringsWithSeparator(((Sequence{m, k})->collect( _x | (OclType["String"])->apply(_x) )), " ")) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,l=map(int,input().split()) i=0 tim=0 res=[] a=list(map(int,input().split())) while il : i+=1 ; for i in range(m): s=input() if s=='0' : res.append(str(tim)) continue w,p,d=map(int,s.split()) p-=1 ; if a[p]>l : continue a[p]+=d ; if a[p]<=l : continue if p>0 and a[p-1]>l and pl : tim-=1 ; elif(p>0 and a[p-1]>l)or(pl): continue else : tim+=1 ; for i in res : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var l : OclAny := null; Sequence{n,m,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var i : int := 0 ; var tim : int := 0 ; var res : Sequence := Sequence{} ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; while (i->compareTo(n)) < 0 do ( while (i->compareTo(n)) < 0 & (a[i+1]->compareTo(l)) <= 0 do ( i := i + 1;) ; if i = n then ( break ) else skip ; tim := tim + 1; ; while (i->compareTo(n)) < 0 & (a[i+1]->compareTo(l)) > 0 do ( i := i + 1;)) ; for i : Integer.subrange(0, m-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if s = '0' then ( execute ((("" + ((tim)))) : res) ; continue ) else skip ; var w : OclAny := null; var p : OclAny := null; var d : OclAny := null; Sequence{w,p,d} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ) ; p := p - 1; ; if (a[p+1]->compareTo(l)) > 0 then ( continue ) else skip ; a[p+1] := a[p+1] + d; ; if (a[p+1]->compareTo(l)) <= 0 then ( continue ) else skip ; if p > 0 & (a[p - 1+1]->compareTo(l)) > 0 & (p->compareTo(n - 1)) < 0 & (a[p + 1+1]->compareTo(l)) > 0 then ( tim := tim - 1; ) else (if (p > 0 & (a[p - 1+1]->compareTo(l)) > 0) or ((p->compareTo(n - 1)) < 0 & (a[p + 1+1]->compareTo(l)) > 0) then ( continue ) else ( tim := tim + 1; ) ) ) ; for i : res do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout input,print=stdin.readline,stdout.write def main(input=input,print=print,map=map,int=int,range=range,set=set,str=str,list=list): n,m,l=map(int,input().split()) a=[-1]+list(map(int,input().split()))+[-1] f,x=False,0 for q in range(n+2): if a[q]>l : if not f : f=True x+=1 else : f=False answer=[] for _ in range(m): s=list(map(int,input().split())) if s[0]==0 : answer.append(str(x)) else : w=s[1] if a[w]+s[2]>l and l>=a[w]: if a[w-1]>l and a[w+1]>l : x-=1 elif not(a[w-1]>l or a[w+1]>l): x+=1 a[w]+=s[2] print('\n'.join(answer)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := null; var print : OclAny := null; Sequence{input,print} := Sequence{stdin.readline,stdout.write}(stmt (compound_stmt (funcdef def (name main) ( (typedargslist (def_parameters (def_parameter (named_parameter (name input)) = (test (logical_test (comparison (expr (atom (name input)))))))) ,) ))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print))))))) (assign_part = (testlist_star_expr (test (logical_test (comparison (expr (atom print))))) , (test (logical_test (comparison (expr (atom (name map))))))) = (testlist_star_expr (test (logical_test (comparison (expr (atom (name map)))))) , (test (logical_test (comparison (expr (atom (name int))))))) = (testlist_star_expr (test (logical_test (comparison (expr (atom (name int)))))) , (test (logical_test (comparison (expr (atom (name range))))))) = (testlist_star_expr (test (logical_test (comparison (expr (atom (name range)))))) , (test (logical_test (comparison (expr (atom (name set))))))) = (testlist_star_expr (test (logical_test (comparison (expr (atom (name set)))))) , (test (logical_test (comparison (expr (atom (name str))))))) = (testlist_star_expr (test (logical_test (comparison (expr (atom (name str)))))) , (test (logical_test (comparison (expr (atom (name list))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name list))))))))))) :)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPeak(arr,n,num,i,j): if(i>=0 and arr[i]>num): return False if(jnum): return False return True def isTrough(arr,n,num,i,j): if(i>=0 and arr[i]union(Sequence{10}->union(Sequence{5}->union(Sequence{7}->union(Sequence{4}->union(Sequence{3}->union(Sequence{ 5 })))))) ; n := (arr)->size() ; printPeaksTroughs(arr, n); operation isPeak(arr : OclAny, n : OclAny, num : OclAny, i : OclAny, j : OclAny) : OclAny pre: true post: true activity: if (i >= 0 & (arr[i+1]->compareTo(num)) > 0) then ( return false ) else skip ; if ((j->compareTo(n)) < 0 & (arr[j+1]->compareTo(num)) > 0) then ( return false ) else skip ; return true; operation isTrough(arr : OclAny, n : OclAny, num : OclAny, i : OclAny, j : OclAny) : OclAny pre: true post: true activity: if (i >= 0 & (arr[i+1]->compareTo(num)) < 0) then ( return false ) else skip ; if ((j->compareTo(n)) < 0 & (arr[j+1]->compareTo(num)) < 0) then ( return false ) else skip ; return true; operation printPeaksTroughs(arr : OclAny, n : OclAny) pre: true post: true activity: execute ("Peaks : ")->display() ; for i : Integer.subrange(0, n-1) do ( if (isPeak(arr, n, arr[i+1], i - 1, i + 1)) then ( execute (arr[i+1])->display() ) else skip) ; execute (->display() ; execute ("Troughs : ")->display() ; for i : Integer.subrange(0, n-1) do ( if (isTrough(arr, n, arr[i+1], i - 1, i + 1)) then ( execute (arr[i+1])->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout input,print=stdin.readline,stdout.write def main(input=input,print=print,map=map,int=int,range=range,set=set,str=str,list=list): n,m,l=map(int,input().split()) a=[-1]+list(map(int,input().split()))+[-1] f,x=False,0 for q in range(n+2): if a[q]>l : if not f : f=True x+=1 else : f=False answer=[] for _ in range(m): s=list(map(int,input().split())) if s[0]==0 : answer.append(str(x)) else : w=s[1] if a[w]+s[2]>l and l>=a[w]: if a[w-1]>l and a[w+1]>l : x-=1 elif a[w-1]<=l and a[w+1]<=l : x+=1 a[w]+=s[2] print('\n'.join(answer)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := null; var print : OclAny := null; Sequence{input,print} := Sequence{stdin.readline,stdout.write}(stmt (compound_stmt (funcdef def (name main) ( (typedargslist (def_parameters (def_parameter (named_parameter (name input)) = (test (logical_test (comparison (expr (atom (name input)))))))) ,) ))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print))))))) (assign_part = (testlist_star_expr (test (logical_test (comparison (expr (atom print))))) , (test (logical_test (comparison (expr (atom (name map))))))) = (testlist_star_expr (test (logical_test (comparison (expr (atom (name map)))))) , (test (logical_test (comparison (expr (atom (name int))))))) = (testlist_star_expr (test (logical_test (comparison (expr (atom (name int)))))) , (test (logical_test (comparison (expr (atom (name range))))))) = (testlist_star_expr (test (logical_test (comparison (expr (atom (name range)))))) , (test (logical_test (comparison (expr (atom (name set))))))) = (testlist_star_expr (test (logical_test (comparison (expr (atom (name set)))))) , (test (logical_test (comparison (expr (atom (name str))))))) = (testlist_star_expr (test (logical_test (comparison (expr (atom (name str)))))) , (test (logical_test (comparison (expr (atom (name list))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name list))))))))))) :)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout input,print=stdin.readline,stdout.write def main(input=input,print=print,map=map,int=int,range=range,set=set,str=str,list=list): n,m,l=map(int,input().split()) a=[-1]+list(map(int,input().split()))+[-1] f,x=False,0 for q in range(n+2): if a[q]>l : if not f : f=True x+=1 else : f=False answer=[] for _ in range(m): s=list(map(int,input().split())) if s[0]==0 : answer.append(str(x)) else : w=s[1] if a[w]+s[2]>l>=a[w]: if a[w-1]>l and a[w+1]>l : x-=1 elif a[w-1]<=l and a[w+1]<=l : x+=1 a[w]+=s[2] print('\n'.join(answer)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := null; var print : OclAny := null; Sequence{input,print} := Sequence{stdin.readline,stdout.write}(stmt (compound_stmt (funcdef def (name main) ( (typedargslist (def_parameters (def_parameter (named_parameter (name input)) = (test (logical_test (comparison (expr (atom (name input)))))))) ,) ))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print))))))) (assign_part = (testlist_star_expr (test (logical_test (comparison (expr (atom print))))) , (test (logical_test (comparison (expr (atom (name map))))))) = (testlist_star_expr (test (logical_test (comparison (expr (atom (name map)))))) , (test (logical_test (comparison (expr (atom (name int))))))) = (testlist_star_expr (test (logical_test (comparison (expr (atom (name int)))))) , (test (logical_test (comparison (expr (atom (name range))))))) = (testlist_star_expr (test (logical_test (comparison (expr (atom (name range)))))) , (test (logical_test (comparison (expr (atom (name set))))))) = (testlist_star_expr (test (logical_test (comparison (expr (atom (name set)))))) , (test (logical_test (comparison (expr (atom (name str))))))) = (testlist_star_expr (test (logical_test (comparison (expr (atom (name str)))))) , (test (logical_test (comparison (expr (atom (name list))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name list))))))))))) :)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,l=map(int,input().split()) i=0 tim=0 res=[] a=list(map(int,input().split())) while il : i+=1 ; for i in range(m): s=input() if s=='0' : res.append(str(tim)) continue w,p,d=map(int,s.split()) p-=1 ; if a[p]>l : continue a[p]+=d ; if a[p]<=l : continue if p>0 and a[p-1]>l and pl : tim-=1 ; elif(p>0 and a[p-1]>l)or(pl): continue else : tim+=1 ; for i in res : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var l : OclAny := null; Sequence{n,m,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var i : int := 0 ; var tim : int := 0 ; var res : Sequence := Sequence{} ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; while (i->compareTo(n)) < 0 do ( while (i->compareTo(n)) < 0 & (a[i+1]->compareTo(l)) <= 0 do ( i := i + 1;) ; if i = n then ( break ) else skip ; tim := tim + 1; ; while (i->compareTo(n)) < 0 & (a[i+1]->compareTo(l)) > 0 do ( i := i + 1;)) ; for i : Integer.subrange(0, m-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if s = '0' then ( execute ((("" + ((tim)))) : res) ; continue ) else skip ; var w : OclAny := null; var p : OclAny := null; var d : OclAny := null; Sequence{w,p,d} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ) ; p := p - 1; ; if (a[p+1]->compareTo(l)) > 0 then ( continue ) else skip ; a[p+1] := a[p+1] + d; ; if (a[p+1]->compareTo(l)) <= 0 then ( continue ) else skip ; if p > 0 & (a[p - 1+1]->compareTo(l)) > 0 & (p->compareTo(n - 1)) < 0 & (a[p + 1+1]->compareTo(l)) > 0 then ( tim := tim - 1; ) else (if (p > 0 & (a[p - 1+1]->compareTo(l)) > 0) or ((p->compareTo(n - 1)) < 0 & (a[p + 1+1]->compareTo(l)) > 0) then ( continue ) else ( tim := tim + 1; ) ) ) ; for i : res do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNums(n): if(n<=11): if(n==8): print("4 4",end=" ") if(n==10): print("4 6",end=" ") else : print("-1",end=" ") if(n % 2==0): print("4 ",(n-4),end=" ") else : print("9 ",n-9,end=" ") n=13 findNums(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 13 ; findNums(n); operation findNums(n : OclAny) pre: true post: true activity: if (n <= 11) then ( if (n = 8) then ( execute ("4 4")->display() ) else skip ; if (n = 10) then ( execute ("4 6")->display() ) else ( execute ("-1")->display() ) ) else skip ; if (n mod 2 = 0) then ( execute ("4 ")->display() ) else ( execute ("9 ")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) result=0 for i in range(n): if b[i]<2 or b[i]>2*a[i]: result-=1 else : result+=math.floor(b[i]/2)*math.ceil(b[i]/2) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var result : int := 0 ; for i : Integer.subrange(0, n-1) do ( if b[i+1] < 2 or (b[i+1]->compareTo(2 * a[i+1])) > 0 then ( result := result - 1 ) else ( result := result + (b[i+1] / 2)->floor() * (b[i+1] / 2)->ceil() )) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() print(sum(-1 if(b>2*a or b==1)else((b//2)*((b+1)//2))for a,b in zip(map(int,input().split()),map(int,input().split())))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; execute (((argument (test (logical_test (comparison (expr (atom - (number (integer 1)))))) if (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom (name b)))) > (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name a))))))) or (logical_test (comparison (comparison (expr (atom (name b)))) == (comparison (expr (atom (number (integer 1)))))))))) ))))) else (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name b))) // (expr (atom (number (integer 2))))))))) ))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name b))) + (expr (atom (number (integer 1))))))))) ))) // (expr (atom (number (integer 2))))))))) )))))))) ))))))) (comp_for for (exprlist (expr (atom (name a))) , (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) )))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(x)for x in input().split()] b=[int(x)for x in input().split()] joy=0 for i in range(n): if(b[i]>2*a[i]or b[i]==1): joy=joy-1 else : joy=joy+((b[i]//2)*((b[i]+1)//2)) print(joy) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var b : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var joy : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ((b[i+1]->compareTo(2 * a[i+1])) > 0 or b[i+1] = 1) then ( joy := joy - 1 ) else ( joy := joy + ((b[i+1] div 2) * ((b[i+1] + 1) div 2)) )) ; execute (joy)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) input() print(n*3) for i in range(0,n,2): print(1,i+1,i+2) print(2,i+1,i+2) print(1,i+1,i+2) print(1,i+1,i+2) print(2,i+1,i+2) print(1,i+1,i+2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; input() ; execute (n * 3)->display() ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( execute (1)->display() ; execute (2)->display() ; execute (1)->display() ; execute (1)->display() ; execute (2)->display() ; execute (1)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) joy=0 for i in range(n): temp2=(b[i]+1)//2 if(a[i]>=temp2 and b[i]!=1): temp1=b[i]//2 joy+=(temp1*temp2) elif(a[i]*2toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var joy : int := 0 ; for i : Integer.subrange(0, n-1) do ( var temp2 : int := (b[i+1] + 1) div 2 ; if ((a[i+1]->compareTo(temp2)) >= 0 & b[i+1] /= 1) then ( var temp1 : int := b[i+1] div 2 ; joy := joy + (temp1 * temp2) ) else (if ((a[i+1] * 2->compareTo(b[i+1])) < 0 or b[i+1] = 1) then ( joy := joy - 1 ) else ( temp1 := a[i+1] ; temp2 := a[i+1] ; joy := joy + (temp1 * temp2) ) ) ) ; execute (joy)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) joy=0 for i in range(n): temp2=(b[i]+1)//2 if(a[i]>=temp2 and b[i]!=1): temp1=b[i]//2 joy+=(temp1*temp2) elif(a[i]*2toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var joy : int := 0 ; for i : Integer.subrange(0, n-1) do ( var temp2 : int := (b[i+1] + 1) div 2 ; if ((a[i+1]->compareTo(temp2)) >= 0 & b[i+1] /= 1) then ( var temp1 : int := b[i+1] div 2 ; joy := joy + (temp1 * temp2) ) else (if ((a[i+1] * 2->compareTo(b[i+1])) < 0 or b[i+1] = 1) then ( joy := joy - 1 ) else ( temp1 := a[i+1] ; temp2 := a[i+1] ; joy := joy + (temp1 * temp2) ) ) ) ; execute (joy)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def index(i): return 1+(i>>31)-(-i>>31) def check(n): s="negative","zero","positive" val=index(n) print(n,"is",s[val]) check(30) check(-20) check(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; check(30) ; check(-20) ; check(0); operation index(i : OclAny) : OclAny pre: true post: true activity: return 1 + (i /(2->pow(31))) - (-i /(2->pow(31))); operation check(n : OclAny) pre: true post: true activity: var s : String := "negative","zero","positive" ; var val : OclAny := index(n) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def radius(n,d): print("The side of each square is ",d/((n-1)*(2**(1/2)))); d=42 ; n=4 ; radius(n,d); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; d := 42; n := 4; ; radius(n, d);; operation radius(n : OclAny, d : OclAny) pre: true post: true activity: execute ("The side of each square is ")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Get_Minimum(q): minimum=0 sum=0 for i in range(n-1): sum+=q[i] if sumn : okay=False if len(set(p))!=n : okay=False if okay : return p else : return-1 if __name__=="__main__" : q=[-2,1] n=len(q)+1 print(Find_Permutation(q)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( q := Sequence{-2}->union(Sequence{ 1 }) ; var n : int := (q)->size() + 1 ; execute (Find_Permutation(q))->display() ) else skip; operation Get_Minimum(q : OclAny) : OclAny pre: true post: true activity: var minimum : int := 0 ; var sum : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( sum := sum + q[i+1] ; if (sum->compareTo(minimum)) < 0 then ( minimum := sum ) else skip) ; return minimum; operation Find_Permutation(q : OclAny) : OclAny pre: true post: true activity: var p : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var min_value : OclAny := Get_Minimum(q) ; p->first() := 1 - min_value ; for i : Integer.subrange(0, n - 1-1) do ( p[i + 1+1] := p[i+1] + q[i+1]) ; var okay : boolean := true ; for i : Integer.subrange(0, n-1) do ( if p[i+1] < 1 or (p[i+1]->compareTo(n)) > 0 then ( okay := false ) else skip) ; if (Set{}->union((p)))->size() /= n then ( okay := false ) else skip ; if okay then ( return p ) else ( return -1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def marathon(n,b): sum=0 ll=b.split(' ') l=[int(i)for i in ll] maxx=max(l) for i in l : sum=sum+int(i) m=max(math.ceil(sum/(n-1)),maxx) return m n=int(input()) b=input() print(marathon(n,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; b := (OclFile["System.in"]).readLine() ; execute (marathon(n, b))->display(); operation marathon(n : OclAny, b : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; var ll : OclAny := b.split(' ') ; var l : Sequence := ll->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var maxx : OclAny := (l)->max() ; for i : l do ( sum := sum + ("" + ((i)))->toInteger()) ; var m : OclAny := Set{(sum / (n - 1))->ceil(), maxx}->max() ; return m; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) a=[int(x)for x in input().split()] ans1=math.ceil(sum(a)/(n-1)) ans2=max(a) print(max(ans1,ans2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans1 : double := ((a)->sum() / (n - 1))->ceil() ; var ans2 : OclAny := (a)->max() ; execute (Set{ans1, ans2}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil a=int(input()) *b,=map(int,input().split()) print(max(ceil(sum(b)/(a-1)),max(b))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (testlist_star_expr (star_expr * (expr (atom (name b)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name b)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{ceil((b)->sum() / (a - 1)), (b)->max()}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) l=list(map(int,input().split())) print(max(max(l),math.ceil(sum(l)/(n-1)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (Set{(l)->max(), ((l)->sum() / (n - 1))->ceil()}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) aa=input() aaa=aa.split(' ') a=[int(i)for i in aaa] m=max(a) ss=list(a) s=0 for i in ss : s=s+i ans=int(max(math.ceil(s*1.0/(n-1)),m)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var aa : String := (OclFile["System.in"]).readLine() ; var aaa : OclAny := aa.split(' ') ; var a : Sequence := aaa->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var m : OclAny := (a)->max() ; var ss : Sequence := (a) ; var s : int := 0 ; for i : ss do ( s := s + i) ; var ans : int := ("" + ((Set{(s * 1.0 / (n - 1))->ceil(), m}->max())))->toInteger() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K,Q=map(int,input().split()) L=[0 for i in range(N)] for _ in range(Q): L[int(input())-1]+=1 for l in L : if K-Q+l>0 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; var Q : OclAny := null; Sequence{N,K,Q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var L : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; for _anon : Integer.subrange(0, Q-1) do ( L[("" + (((OclFile["System.in"]).readLine())))->toInteger() - 1+1] := L[("" + (((OclFile["System.in"]).readLine())))->toInteger() - 1+1] + 1) ; for l : L do ( if K - Q + l > 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printAsMaximalPrimeSum(n): if(n % 2==1): print("3 ",end="") n-=3 while(n>0): print("2 ",end="") n-=2 n=5 printAsMaximalPrimeSum(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; printAsMaximalPrimeSum(n); operation printAsMaximalPrimeSum(n : OclAny) pre: true post: true activity: if (n mod 2 = 1) then ( execute ("3 ")->display() ; n := n - 3 ) else skip ; while (n > 0) do ( execute ("2 ")->display() ; n := n - 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,a): print((n//2)*6) for i in range(0,n,2): for j in range(2): print(1,i+1,i+2) print(2,i+1,i+2) print(1,i+1,i+2) for t in range(int(input())): n=int(input()) a=list(map(int,input().split())) solve(n,a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; solve(n, a)); operation solve(n : OclAny, a : OclAny) pre: true post: true activity: execute ((n div 2) * 6)->display() ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( for j : Integer.subrange(0, 2-1) do ( execute (1)->display() ; execute (2)->display() ; execute (1)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def frequency(a,x): count=0 for i in a : if i==x : count+=1 return count a=[0,5,5,5,4] x=5 print(frequency(a,x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{0}->union(Sequence{5}->union(Sequence{5}->union(Sequence{5}->union(Sequence{ 4 })))) ; x := 5 ; execute (frequency(a, x))->display(); operation frequency(a : OclAny, x : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : a do ( if i = x then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter def solve(string): n,k,q,*a=map(int,string.split()) a=Counter(a) return "\n".join(["Yes" if a.get(i+1,0)>q-k else "No" for i in range(n)]) if __name__=='__main__' : n,m,q=map(int,input().split()) print(solve('{}{}{}\n'.format(n,m,q)+'\n'.join([input()for _ in range(q)]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var n : OclAny := null; var m : OclAny := null; var q : OclAny := null; Sequence{n,m,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (solve(StringLib.interpolateStrings('{}{}{} ', Sequence{n, m, q}) + StringLib.sumStringsWithSeparator((Integer.subrange(0, q-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine()))), ' ')))->display() ) else skip; operation solve(string : OclAny) : OclAny pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var q : OclAny := null; var a : OclAny := null; Sequence{n,k,q,a} := (string.split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := Counter(a) ; return StringLib.sumStringsWithSeparator((Integer.subrange(0, n-1)->select(i | true)->collect(i | (if (a.get(i + 1, 0)->compareTo(q - k)) > 0 then "Yes" else "No" endif))), "\n"); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K,Q=[int(x)for x in input().split()] hiku=[Q for _ in range(N)] for i in range(Q): Ai=int(input()) hiku[Ai-1]-=1 for x in hiku : x=K-x if x>0 : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; var Q : OclAny := null; Sequence{N,K,Q} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var hiku : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Q)) ; for i : Integer.subrange(0, Q-1) do ( var Ai : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; hiku[Ai - 1+1] := hiku[Ai - 1+1] - 1) ; for x : hiku do ( var x : double := K - x ; if x > 0 then ( execute ('Yes')->display() ) else ( execute ('No')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections n,k,q=map(int,input().split()) a=[int(input())for _ in range(q)] num_ans=collections.Counter(a) for i in range(1,n+1): if i in num_ans : minus_point=q-num_ans[i] else : minus_point=q if k-minus_point>0 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; var q : OclAny := null; Sequence{n,k,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, q-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var num_ans : OclAny := .Counter(a) ; for i : Integer.subrange(1, n + 1-1) do ( if (num_ans)->includes(i) then ( var minus_point : double := q - num_ans[i+1] ) else ( minus_point := q ) ; if k - minus_point > 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline N,K,Q=map(int,input().split()) A=[int(input())for _ in range(Q)] cnt=[0]*N for x in A : cnt[x-1]+=1 for x in cnt : print('Yes' if K-Q+x>0 else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var N : OclAny := null; var K : OclAny := null; var Q : OclAny := null; Sequence{N,K,Q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := Integer.subrange(0, Q-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for x : A do ( cnt[x - 1+1] := cnt[x - 1+1] + 1) ; for x : cnt do ( execute (if K - Q + x > 0 then 'Yes' else 'No' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def __gcd(a,b): if(a==0 or b==0): return 0 ; if(a==b): return a ; if(a>b): return __gcd(a-b,b); return __gcd(a,b-a); def find_Gcd(crr,n): result=crr[0]; for i in range(1,n): result=__gcd(crr[i],result); return result ; def profitRatio(amountArr,timeTrr,n): i=0 ; crr=[0]*n ; for i in range(n): crr[i]=amountArr[i]*timeTrr[i]; Share=find_Gcd(crr,n); for i in range(n-1): print(int(crr[i]/Share),end=" : "); print(int(crr[i+1]/Share)); amountArr=[5000,6000,1000]; timeTrr=[6,6,12]; n=len(amountArr); profitRatio(amountArr,timeTrr,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; amountArr := Sequence{5000}->union(Sequence{6000}->union(Sequence{ 1000 })); ; timeTrr := Sequence{6}->union(Sequence{6}->union(Sequence{ 12 })); ; n := (amountArr)->size(); ; profitRatio(amountArr, timeTrr, n);; operation __gcd(a : OclAny, b : OclAny) pre: true post: true activity: if (a = 0 or b = 0) then ( return 0; ) else skip ; if (a = b) then ( return a; ) else skip ; if ((a->compareTo(b)) > 0) then ( return __gcd(a - b, b); ) else skip ; return __gcd(a, b - a);; operation find_Gcd(crr : OclAny, n : OclAny) pre: true post: true activity: var result : OclAny := crr->first(); ; for i : Integer.subrange(1, n-1) do ( result := __gcd(crr[i+1], result);) ; return result;; operation profitRatio(amountArr : OclAny, timeTrr : OclAny, n : OclAny) pre: true post: true activity: var i : int := 0; ; crr := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; for i : Integer.subrange(0, n-1) do ( crr[i+1] := amountArr[i+1] * timeTrr[i+1];) ; var Share : OclAny := find_Gcd(crr, n); ; for i : Integer.subrange(0, n - 1-1) do ( execute (("" + ((crr[i+1] / Share)))->toInteger())->display();) ; execute (("" + ((crr[i + 1+1] / Share)))->toInteger())->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ts,tf,t=[int(x)for x in input().split()] n=int(input()) if n==0 : print(ts) quit() visitors_arrive=[int(x)for x in input().split()] vasya_arrive=0 wait=1e12 for arrive in visitors_arrive : if arrive<=tf-t : if ts-arriveselect(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( execute (ts)->display() ; quit() ) else skip ; var visitors_arrive : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var vasya_arrive : int := 0 ; var wait : double := ("1e12")->toReal() ; for arrive : visitors_arrive do ( if (arrive->compareTo(tf - t)) <= 0 then ( if (ts - arrive->compareTo(wait)) < 0 then ( wait := ts - arrive ; vasya_arrive := Set{ts, arrive - 1}->min() ) else skip ; var ts : OclAny := Set{arrive, ts}->max() + t ) else skip) ; if (ts->compareTo(tf - t)) <= 0 then ( vasya_arrive := ts ) else skip ; execute (vasya_arrive)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): s=[int(x)for x in input().split()] ts,tf,t=s[0],s[1],s[2] n=int(input()) if n==0 : return ts v=[int(x)for x in input().split()] v0=v[0] if v0>ts : return ts ans,ansv=1e15,1e15 now=ts for i in range(len(v)): if max(0,now-v[i]+1)select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ts : OclAny := null; var tf : OclAny := null; var t : OclAny := null; Sequence{ts,tf,t} := Sequence{s->first(),s[1+1],s[2+1]} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( return ts ) else skip ; var v : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var v0 : OclAny := v->first() ; if (v0->compareTo(ts)) > 0 then ( return ts ) else skip ; var ans : OclAny := null; var ansv : OclAny := null; Sequence{ans,ansv} := Sequence{("1e15")->toReal(),("1e15")->toReal()} ; var now : OclAny := ts ; for i : Integer.subrange(0, (v)->size()-1) do ( if (Set{0, now - v[i+1] + 1}->max()->compareTo(ansv)) < 0 & (v[i+1] - 1 + t->compareTo(tf)) <= 0 then ( var ansv : OclAny := Set{0, now - v[i+1] + 1}->max() ; var ans : double := v[i+1] - 1 ) else skip ; now := Set{now, v[i+1]}->max() + t) ; if (now + t->compareTo(tf)) <= 0 then ( return now ) else ( return ans ); operation main() pre: true post: true activity: var output : OclAny := solve() ; execute (output)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- abertura,fechamento,tempoAtendimento=[int(t)for t in input().split()] pessoas=int(input()) if(pessoas==0): print(abertura) exit() pessoasChegada=[int(t)for t in input().split()] resposta=espera=int(1e18) for pessoa in pessoasChegada : if(pessoa<=fechamento-tempoAtendimento): if(pessoa>0 and abertura-pessoa+1select(t | true)->collect(t | (("" + ((t)))->toInteger())) ; var pessoas : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (pessoas = 0) then ( execute (abertura)->display() ; exit() ) else skip ; var pessoasChegada : Sequence := input().split()->select(t | true)->collect(t | (("" + ((t)))->toInteger())) ; var resposta : OclAny := ("" + ((("1e18")->toReal())))->toInteger(); var espera : int := ("" + ((("1e18")->toReal())))->toInteger() ; for pessoa : pessoasChegada do ( if ((pessoa->compareTo(fechamento - tempoAtendimento)) <= 0) then ( if (pessoa > 0 & (abertura - pessoa + 1->compareTo(espera)) < 0) then ( espera := abertura - pessoa + 1 ; resposta := Set{abertura, pessoa - 1}->min() ) else skip ; var abertura : OclAny := Set{abertura, pessoa}->max() + tempoAtendimento ) else skip) ; if ((abertura->compareTo(fechamento - tempoAtendimento)) <= 0) then ( execute (abertura)->display() ) else ( execute (resposta)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ts,tf,t=[int(x)for x in input().split()] n=int(input()) if n==0 : print(ts) quit() visitors_arrive=[int(x)for x in input().split()] vasya_arrive=0 wait=1e12 for arrive in visitors_arrive : if arrive<=tf-t : if ts-arrive+1select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( execute (ts)->display() ; quit() ) else skip ; var visitors_arrive : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var vasya_arrive : int := 0 ; var wait : double := ("1e12")->toReal() ; for arrive : visitors_arrive do ( if (arrive->compareTo(tf - t)) <= 0 then ( if (ts - arrive + 1->compareTo(wait)) < 0 then ( wait := ts - arrive + 1 ; vasya_arrive := Set{ts, arrive - 1}->min() ) else skip ; var ts : OclAny := Set{arrive, ts}->max() + t ) else skip) ; if (ts->compareTo(tf - t)) <= 0 then ( vasya_arrive := ts ) else skip ; execute (vasya_arrive)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ts,tf,t=[int(x)for x in input().split()] n=int(input()) if n==0 : print(ts) quit() visitors_arrive=[int(x)for x in input().split()] vasya_arrive=0 wait=1e12 for arrive in visitors_arrive : if arrive<=tf-t : if ts-arriveselect(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( execute (ts)->display() ; quit() ) else skip ; var visitors_arrive : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var vasya_arrive : int := 0 ; var wait : double := ("1e12")->toReal() ; for arrive : visitors_arrive do ( if (arrive->compareTo(tf - t)) <= 0 then ( if (ts - arrive->compareTo(wait)) < 0 then ( wait := ts - arrive ; vasya_arrive := Set{ts, arrive - 1}->min() ) else skip ; var ts : OclAny := Set{arrive, ts}->max() + t ) else skip) ; if (ts->compareTo(tf - t)) <= 0 then ( vasya_arrive := ts ) else skip ; execute (vasya_arrive)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- event=[] inning=int(input()) NONE=0b000 FIRST=0b001 SECOND=0b010 THIRD=0b100 runner=NONE currentInning=0 score=0 outCount=0 inningScore=[] while currentInningtoInteger() ; var NONE : int := 0b000 ; var FIRST : int := 0b001 ; var SECOND : int := 0b010 ; var THIRD : int := 0b100 ; var runner : int := NONE ; var currentInning : int := 0 ; var score : int := 0 ; var outCount : int := 0 ; var inningScore : Sequence := Sequence{} ; while (currentInning->compareTo(inning)) < 0 do ( var data : String := (OclFile["System.in"]).readLine() ; if data = "HIT" then ( if (MathLib.bitwiseAnd(runner, THIRD)) = THIRD then ( score := score + 1 ; runner := runner & MathLib.bitwiseNot(THIRD) ) else skip ; runner := runner * (2->pow(1)) ; runner := runner or FIRST ) else (if data = "OUT" then ( outCount := outCount + 1 ) else (if data = "HOMERUN" then ( if (MathLib.bitwiseAnd(runner, THIRD)) = THIRD then ( score := score + 1 ) else skip ; if (MathLib.bitwiseAnd(runner, SECOND)) = SECOND then ( score := score + 1 ) else skip ; if (MathLib.bitwiseAnd(runner, FIRST)) = FIRST then ( score := score + 1 ) else skip ; score := score + 1 ; runner := NONE ) else skip ) ) ; if outCount = 3 then ( execute ((score) : inningScore) ; currentInning := currentInning + 1 ; outCount := 0 ; score := 0 ; runner := NONE ) else skip) ; for i : Integer.subrange(0, inning-1) do ( execute (inningScore[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isNumBalanced(N): st=str(N) isBalanced=True freq=[0]*10 n=len(st) for i in range(0,n): freq[int(st[i])]+=1 for i in range(0,9): if freq[i]!=freq[i+1]: isBalanced=False if isBalanced : return True else : return False if __name__=="__main__" : N=1234567890 flag=isNumBalanced(N) if flag : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := 1234567890 ; var flag : OclAny := isNumBalanced(N) ; if flag then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; operation isNumBalanced(N : OclAny) : OclAny pre: true post: true activity: var st : String := ("" + ((N))) ; var isBalanced : boolean := true ; var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; var n : int := (st)->size() ; for i : Integer.subrange(0, n-1) do ( freq[("" + ((st[i+1])))->toInteger()+1] := freq[("" + ((st[i+1])))->toInteger()+1] + 1) ; for i : Integer.subrange(0, 9-1) do ( if freq[i+1] /= freq[i + 1+1] then ( isBalanced := false ) else skip) ; if isBalanced then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMinimal(a,n): a.sort() sum=0 for i in range(n//2): sum+=((a[i]+a[n-i-1])*(a[i]+a[n-i-1])) return sum if __name__=="__main__" : a=[8,5,2,3] n=len(a) print(findMinimal(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{8}->union(Sequence{5}->union(Sequence{2}->union(Sequence{ 3 }))) ; n := (a)->size() ; execute (findMinimal(a, n))->display() ) else skip; operation findMinimal(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: a := a->sort() ; var sum : int := 0 ; for i : Integer.subrange(0, n div 2-1) do ( sum := sum + ((a[i+1] + a[n - i - 1+1]) * (a[i+1] + a[n - i - 1+1]))) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) L=sorted(list(map(int,input().split()))) ans=0 for i in range(n): ans+=L[2*i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var L : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( ans := ans + L[2 * i+1]) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def getInt(): return int(input()) def getIntList(): return[int(x)for x in input().split()] def zeros(n): return[0]*n def zeros2(n,m): return[zeros(m)for i in range(n)] class Debug(): def __init__(self): self.debug=True def off(self): self.debug=False def dmp(self,x,cmt=''): if self.debug : if cmt!='' : w=cmt+': '+str(x) else : w=str(x) print(w) return x def prob(): d=Debug() d.off() N=getInt() d.dmp((N),'N') L=getIntList() d.dmp((L),'L') L.sort() count=0 for i in range(N): count+=min(L[i*2],L[i*2+1]) return count ans=prob() print(ans) ------------------------------------------------------------ OCL File: --------- class Debug { static operation newDebug() : Debug pre: true post: Debug->exists( _x | result = _x ); attribute debug : boolean := true; operation initialise() : pre: true post: true activity: self.debug := true; return self; operation off() pre: true post: true activity: self.debug := false; operation dmp(x : OclAny,cmt : String) : OclAny pre: true post: true activity: if self.debug then ( if cmt /= '' then ( var w : String := cmt + ': ' + ("" + ((x))) ) else ( w := ("" + ((x))) ) ; execute (w)->display() ) else skip ; return x; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var ans : OclAny := prob() ; execute (ans)->display(); operation getInt() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation getIntList() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation zeros(n : OclAny) : OclAny pre: true post: true activity: return MatrixLib.elementwiseMult(Sequence{ 0 }, n); operation zeros2(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (zeros(m))); operation prob() : OclAny pre: true post: true activity: var d : Debug := (Debug.newDebug()).initialise() ; d.off() ; var N : OclAny := getInt() ; d.dmp((N), 'N') ; var L : OclAny := getIntList() ; d.dmp((L), 'L') ; L := L->sort() ; var count : int := 0 ; for i : Integer.subrange(0, N-1) do ( count := count + Set{L[i * 2+1], L[i * 2 + 1+1]}->min()) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=[int(v)for v in input().split()] L=[int(v)for v in input().split()] L.sort() L_even=L[0 : : 2] goukei=sum(L_even) print(str(goukei)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : Sequence := input().split()->select(v | true)->collect(v | (("" + ((v)))->toInteger())) ; var L : Sequence := input().split()->select(v | true)->collect(v | (("" + ((v)))->toInteger())) ; L := L->sort() ; var L_even : OclAny := L(subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ; var goukei : OclAny := (L_even)->sum() ; execute (("" + ((goukei))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**9) input=sys.stdin.readline N=int(input()) A=list(map(int,input().split())) A=sorted(A) print(sum(A[0 : : 2])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(9)) ; var input : OclAny := (OclFile["System.in"]).readline ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; A := A->sort() ; execute ((A(subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin point=0 n=int(stdin.readline().rstrip()) li=list(map(int,stdin.readline().rstrip().split())) li.sort() for i in range(n): point+=min(li[2*i],li[2*i+1]) print(point) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var point : int := 0 ; var n : int := ("" + ((stdin.readLine().rstrip())))->toInteger() ; var li : Sequence := ((stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; li := li->sort() ; for i : Integer.subrange(0, n-1) do ( point := point + Set{li[2 * i+1], li[2 * i + 1+1]}->min()) ; execute (point)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] while True : n,m,k=LI() if n==0 : break r=[[0]*(n*m+1)for _ in range(n+1)] r[0][0]=1 for i in range(n): for j in range(i,n*m): if r[i][j]==0 : break for kk in range(1,m+1): r[i+1][j+kk]+=r[i][j]/m t=0 for kk in range(n*m+1): c=max(kk-k,1) t+=c*r[n][kk] rr.append('{:0.9f}'.format(t)) return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := LI() ; if n = 0 then ( break ) else skip ; var r : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (n * m + 1)))) ; r->first()->first() := 1 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i, n * m-1) do ( if r[i+1][j+1] = 0 then ( break ) else skip ; for kk : Integer.subrange(1, m + 1-1) do ( r[i + 1+1][j + kk+1] := r[i + 1+1][j + kk+1] + r[i+1][j+1] / m))) ; var t : int := 0 ; for kk : Integer.subrange(0, n * m + 1-1) do ( var c : OclAny := Set{kk - k, 1}->max() ; t := t + c * r[n+1][kk+1]) ; execute ((StringLib.interpolateStrings('{:0.9f}', Sequence{t})) : rr)) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np def waysToArrange(N,K,k): C=np.zeros((N+1,N+1)) for i in range(N+1): for j in range(i+1): if(j==0 or j==i): C[i][j]=1 else : C[i][j]=(C[i-1][j-1]+C[i-1][j]) dp=np.zeros((K+1)) count=0 dp[0]=1 for i in range(K): dp[i+1]=(dp[i]*C[count+k[i]-1][k[i]-1]) count+=k[i] return dp[K] if __name__=="__main__" : N=4 k=[2,2] K=len(k) print(int(waysToArrange(N,K,k))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( N := 4 ; k := Sequence{2}->union(Sequence{ 2 }) ; K := (k)->size() ; execute (("" + ((waysToArrange(N, K, k))))->toInteger())->display() ) else skip; operation waysToArrange(N : OclAny, K : OclAny, k : OclAny) : OclAny pre: true post: true activity: var C : Sequence := MatrixLib.singleValueMatrix(Sequence{N + 1, N + 1}, 0.0) ; for i : Integer.subrange(0, N + 1-1) do ( for j : Integer.subrange(0, i + 1-1) do ( if (j = 0 or j = i) then ( C[i+1][j+1] := 1 ) else ( C[i+1][j+1] := (C[i - 1+1][j - 1+1] + C[i - 1+1][j+1]) ))) ; var dp : Sequence := MatrixLib.singleValueMatrix((K + 1), 0.0) ; var count : int := 0 ; dp->first() := 1 ; for i : Integer.subrange(0, K-1) do ( dp[i + 1+1] := (dp[i+1] * C[count + k[i+1] - 1+1][k[i+1] - 1+1]) ; count := count + k[i+1]) ; return dp[K+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def power(n,r): count=0 ; i=r while((n/i)>=1): count+=n/i i=i*r return int(count) n=6 ; r=3 print(power(n,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 6; r := 3 ; execute (power(n, r))->display(); operation power(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: var count : int := 0; var i : OclAny := r ; while ((n / i) >= 1) do ( count := count + n / i ; i := i * r) ; return ("" + ((count)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) while T : s=input().split(' ') n,k=int(s[0]),int(s[1]) a=input().split(' ') for i in range(n): a[i]=int(a[i]) res=0 if k==1 : res=(n-1)//2 else : for i in range(1,n-1): if a[i]>a[i-1]+a[i+1]: res+=1 print(res) T-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while T do ( var s : OclAny := input().split(' ') ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := Sequence{("" + ((s->first())))->toInteger(),("" + ((s[1+1])))->toInteger()} ; var a : OclAny := input().split(' ') ; for i : Integer.subrange(0, n-1) do ( a[i+1] := ("" + ((a[i+1])))->toInteger()) ; var res : int := 0 ; if k = 1 then ( res := (n - 1) div 2 ) else ( for i : Integer.subrange(1, n - 1-1) do ( if (a[i+1]->compareTo(a[i - 1+1] + a[i + 1+1])) > 0 then ( res := res + 1 ) else skip) ) ; execute (res)->display() ; T := T - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printMax(arr,n,k): max=0 for i in range(n-k+1): max=arr[i] for j in range(1,k): if arr[i+j]>max : max=arr[i+j] print(str(max)+"",end="") if __name__=="__main__" : arr=[1,2,3,4,5,6,7,8,9,10] n=len(arr) k=3 printMax(arr,n,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{ 10 }))))))))) ; n := (arr)->size() ; k := 3 ; printMax(arr, n, k) ) else skip; operation printMax(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var max : int := 0 ; for i : Integer.subrange(0, n - k + 1-1) do ( max := arr[i+1] ; for j : Integer.subrange(1, k-1) do ( if (arr[i + j+1]->compareTo(max)) > 0 then ( max := arr[i + j+1] ) else skip) ; execute (("" + ((max))) + "")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import floor for _ in range(int(input())): n,k=map(int,input().split()) mass=list(map(int,input().split())) s=0 if k==1 : print(floor((n-1)/2)) else : for i in range(1,n-1): if mass[i]>mass[i-1]+mass[i+1]: s+=1 print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mass : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : int := 0 ; if k = 1 then ( execute (floor((n - 1) / 2))->display() ) else ( for i : Integer.subrange(1, n - 1-1) do ( if (mass[i+1]->compareTo(mass[i - 1+1] + mass[i + 1+1])) > 0 then ( s := s + 1 ) else skip) ; execute (s)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def sol(n,k,s): a=sorted(map(len,s.strip('L').split('W'))) m=len(a)+k while a and a[0]<=k : k-=a.pop(0) return(2*min(n,m-1)-len(a)or 1)-1 def main(): f=sys.stdin t=int(f.readline()) for _ in range(t): n,k=map(int,f.readline().split()) s=f.readline().strip() print(sol(n,k,s)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation sol(n : OclAny, k : OclAny, s : OclAny) : OclAny pre: true post: true activity: var a : Sequence := (s->trim().split('W'))->collect( _x | (len)->apply(_x) )->sort() ; var m : int := (a)->size() + k ; while a & (a->first()->compareTo(k)) <= 0 do ( k := k - a->at(0`firstArg+1) ; a := a->excludingAt(0+1)) ; return (2 * Set{n, m - 1}->min() - (a)->size() or 1) - 1; operation main() pre: true post: true activity: var f : OclFile := OclFile["System.in"] ; var t : int := ("" + ((f.readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( Sequence{n,k} := (f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; s := f.readLine()->trim() ; execute (sol(n, k, s))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) a=list(map(int,input().split())) if k==1 : print((n-1)//2) else : print(sum(a[i-1]+a[i+1]toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if k = 1 then ( execute ((n - 1) div 2)->display() ) else ( execute (((argument (test (logical_test (comparison (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))) + (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))))) < (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) )))))))))->sum())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): a=input().split() n=int(a[0]) k=int(a[1]) a=input().split() b=0 while b1 : while ba[b-1]+a[b+1]: c+=1 b+=1 print(c) else : if n % 2==0 : print((n//2)-1) else : print(n//2) t=int(input()) while t>0 : solve() t=t-1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( solve() ; t := t - 1); operation solve() pre: true post: true activity: var a : OclAny := input().split() ; var n : int := ("" + ((a->first())))->toInteger() ; var k : int := ("" + ((a[1+1])))->toInteger() ; a := input().split() ; var b : int := 0 ; while (b->compareTo(n)) < 0 do ( a[b+1] := ("" + ((a[b+1])))->toInteger() ; b := b + 1) ; b := 1 ; var c : int := 0 ; if k > 1 then ( while (b->compareTo((a)->size() - 1)) < 0 do ( if (a[b+1]->compareTo(a[b - 1+1] + a[b + 1+1])) > 0 then ( c := c + 1 ) else skip ; b := b + 1) ; execute (c)->display() ) else ( if n mod 2 = 0 then ( execute ((n div 2) - 1)->display() ) else ( execute (n div 2)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r,c=map(int,input().split()) a=[] for i in range(r): a.append(list(map(int,input().split()))) a[i].append(sum(a[i])) for i in range(r): print(" ".join(list(map(str,a[i])))) csum=[] for j in range(c+1): su=0 for i in range(r): su+=a[i][j] csum.append(su) print(" ".join(list(map(str,csum)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, r-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : a) ; (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))))))) ))))) ; for i : Integer.subrange(0, r-1) do ( execute (StringLib.sumStringsWithSeparator((((a[i+1])->collect( _x | (OclType["String"])->apply(_x) ))), " "))->display()) ; var csum : Sequence := Sequence{} ; for j : Integer.subrange(0, c + 1-1) do ( var su : int := 0 ; for i : Integer.subrange(0, r-1) do ( su := su + a[i+1][j+1]) ; execute ((su) : csum)) ; execute (StringLib.sumStringsWithSeparator((((csum)->collect( _x | (OclType["String"])->apply(_x) ))), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def shownum(list): stri=str() for s in list : stri+=str(s)+" " print(stri[:-1]) r,c=map(int,input().split()) csum=[list()for x in range(c)] rlist=[list()for x in range(r+1)] for i in range(r): sum=0 rlist[i]=list(map(int,input().split())) for j in range(c): csum[j].append(rlist[i][j]) for j in rlist[i]: sum+=j rlist[i].append(sum) for s in csum : sum=0 for l in s : sum+=l rlist[r].append(sum) sum=0 for i in rlist[r]: sum+=i rlist[r].append(sum) for i in range(r+1): shownum(rlist[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var csum : Sequence := Integer.subrange(0, c-1)->select(x | true)->collect(x | (())) ; var rlist : Sequence := Integer.subrange(0, r + 1-1)->select(x | true)->collect(x | (())) ; for i : Integer.subrange(0, r-1) do ( var sum : int := 0 ; rlist[i+1] := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, c-1) do ((expr (atom (name csum)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name rlist)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) ))))) ; for j : rlist[i+1] do ( sum := sum + j) ; (expr (atom (name rlist)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sum)))))))) ))))) ; for s : csum do ( sum := 0 ; for l : s do ( sum := sum + l) ; (expr (atom (name rlist)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sum)))))))) ))))) ; sum := 0 ; for i : rlist[r+1] do ( sum := sum + i) ; (expr (atom (name rlist)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sum)))))))) )))) ; for i : Integer.subrange(0, r + 1-1) do ( shownum(rlist[i+1])); operation shownum(list : OclAny) pre: true post: true activity: var stri : String := ("" + (())) ; for s : OclType["Sequence"] do ( stri := stri + ("" + ((s))) + " ") ; execute (stri->front())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin r,c=[int(x)for x in stdin.readline().rstrip().split()] table=[[int(x)for x in stdin.readline().rstrip().split()]for _ in range(r)] for row in range(r): table[row]+=[sum(table[row])] print(*table[row]) col_sum=[sum(x)for x in zip(*table)] print(*col_sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := stdin.readLine().rstrip().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var table : Sequence := Integer.subrange(0, r-1)->select(_anon | true)->collect(_anon | (stdin.readLine().rstrip().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))) ; for row : Integer.subrange(0, r-1) do ( table[row+1] := table[row+1] + Sequence{ (table[row+1])->sum() } ; execute ((argument * (test (logical_test (comparison (expr (atom (name table)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name row)))))))) ]))))))))->display()) ; var col_sum : Sequence := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name table)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name table)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name table)))))))`third->at(_indx)} )->select(x | true)->collect(x | ((x)->sum())) ; execute ((argument * (test (logical_test (comparison (expr (atom (name col_sum))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r,c=[int(x)for x in input().split()] s_row=[0 for x in range(c+1)] for i in range(r): row=[int(x)for x in input().split()] row.append(sum(row)) print(" ".join([str(x)for x in row])) s_row=[x+y for x,y in zip(s_row,row)] print(" ".join([str(x)for x in s_row])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var s_row : Sequence := Integer.subrange(0, c + 1-1)->select(x | true)->collect(x | (0)) ; for i : Integer.subrange(0, r-1) do ( var row : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (((row)->sum()) : row) ; execute (StringLib.sumStringsWithSeparator((row->select(x | true)->collect(x | (("" + ((x)))))), " "))->display() ; s_row := Integer.subrange(1, s_row->size())->collect( _indx | Sequence{s_row->at(_indx), row->at(_indx)} )->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (x + y))) ; execute (StringLib.sumStringsWithSeparator((s_row->select(x | true)->collect(x | (("" + ((x)))))), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r,c=map(int,input().split()) hyou=[] tate_sum=[0]*(c+1) for i in range(r): line=list(map(int,input().split())) line.append(sum(line)) tate_sum=[tate_sum[j]+line[j]for j in range(len(line))] hyou.append(" ".join(map(str,line))) hyou.append(" ".join(map(str,tate_sum))) print("\n".join(hyou)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var hyou : Sequence := Sequence{} ; var tate_sum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (c + 1)) ; for i : Integer.subrange(0, r-1) do ( var line : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (((line)->sum()) : line) ; tate_sum := Integer.subrange(0, (line)->size()-1)->select(j | true)->collect(j | (tate_sum[j+1] + line[j+1])) ; execute ((StringLib.sumStringsWithSeparator(((line)->collect( _x | (OclType["String"])->apply(_x) )), " ")) : hyou)) ; execute ((StringLib.sumStringsWithSeparator(((tate_sum)->collect( _x | (OclType["String"])->apply(_x) )), " ")) : hyou) ; execute (StringLib.sumStringsWithSeparator((hyou), "\n"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np right=3 ; left=6 ; dp=np.ones((left,right)) dp=-1*dp def findSubarraySum(ind,flips,n,a,k): if(flips>k): return-1e9 ; if(ind==n): return 0 ; if(dp[ind][flips]!=-1): return dp[ind][flips]; ans=0 ; ans=max(0,a[ind]+findSubarraySum(ind+1,flips,n,a,k)); ans=max(ans,-a[ind]+findSubarraySum(ind+1,flips+1,n,a,k)); dp[ind][flips]=ans ; return dp[ind][flips]; def findMaxSubarraySum(a,n,k): ans=-1e9 ; for i in range(n): ans=max(ans,findSubarraySum(i,0,n,a,k)); return ans ; if __name__=="__main__" : a=[-1,-2,-100,-10]; n=len(a); k=1 ; print(findMaxSubarraySum(a,n,k)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var right : int := 3; ; var left : int := 6; ; var dp : Sequence := MatrixLib.singleValueMatrix(Sequence{left, right}, 1.0) ; dp := MatrixLib.elementwiseMult(dp, -1) ; skip ; skip ; if __name__ = "__main__" then ( a := Sequence{-1}->union(Sequence{-2}->union(Sequence{-100}->union(Sequence{ -10 }))); ; n := (a)->size(); ; k := 1; ; execute (findMaxSubarraySum(a, n, k))->display(); ) else skip; operation findSubarraySum(ind : OclAny, flips : OclAny, n : OclAny, a : OclAny, k : OclAny) pre: true post: true activity: if ((flips->compareTo(k)) > 0) then ( return -("1e9")->toReal(); ) else skip ; if (ind = n) then ( return 0; ) else skip ; if (dp[ind+1][flips+1] /= -1) then ( return dp[ind+1][flips+1]; ) else skip ; var ans : int := 0; ; ans := Set{0, a[ind+1] + findSubarraySum(ind + 1, flips, n, a, k)}->max(); ; ans := Set{ans, -a[ind+1] + findSubarraySum(ind + 1, flips + 1, n, a, k)}->max(); ; dp[ind+1][flips+1] := ans; ; return dp[ind+1][flips+1];; operation findMaxSubarraySum(a : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: ans := -("1e9")->toReal(); ; for i : Integer.subrange(0, n-1) do ( ans := Set{ans, findSubarraySum(i, 0, n, a, k)}->max();) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def isPrime(n): if(n<=1): return False if(n<=3): return True if(n % 2==0 or n % 3==0): return False k=int(sqrt(n))+1 for i in range(5,k,6): if(n % i==0 or n %(i+2)==0): return False return True def isThreeDisctFactors(n): sq=int(sqrt(n)) if(1*sq*sq!=n): return False if(isPrime(sq)): return True else : return False if __name__=='__main__' : num=9 if(isThreeDisctFactors(num)): print("Yes") else : print("No") num=15 if(isThreeDisctFactors(num)): print("Yes") else : print("No") num=12397923568441 if(isThreeDisctFactors(num)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( var num : int := 9 ; if (isThreeDisctFactors(num)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ; num := 15 ; if (isThreeDisctFactors(num)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ; num := 12397923568441 ; if (isThreeDisctFactors(num)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isPrime(n : OclAny) : OclAny pre: true post: true activity: if (n <= 1) then ( return false ) else skip ; if (n <= 3) then ( return true ) else skip ; if (n mod 2 = 0 or n mod 3 = 0) then ( return false ) else skip ; var k : int := ("" + ((sqrt(n))))->toInteger() + 1 ; for i : Integer.subrange(5, k-1)->select( $x | ($x - 5) mod 6 = 0 ) do ( if (n mod i = 0 or n mod (i + 2) = 0) then ( return false ) else skip) ; return true; operation isThreeDisctFactors(n : OclAny) : OclAny pre: true post: true activity: var sq : int := ("" + ((sqrt(n))))->toInteger() ; if (1 * sq * sq /= n) then ( return false ) else skip ; if (isPrime(sq)) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maximumFixedPoints(a,n): pos=[None]*n count,swapped=0,0 for i in range(0,n): pos[a[i]]=i for i in range(0,n): if a[i]==i : count+=1 elif swapped==0 and pos[i]==a[i]: count+=2 swapped=1 if swapped==0 and countunion(Sequence{1}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 2 })))) ; n := (a)->size() ; execute (maximumFixedPoints(a, n))->display() ) else skip; operation maximumFixedPoints(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var pos : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; var count : OclAny := null; var swapped : OclAny := null; Sequence{count,swapped} := Sequence{0,0} ; for i : Integer.subrange(0, n-1) do ( pos[a[i+1]+1] := i) ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = i then ( count := count + 1 ) else (if swapped = 0 & pos[i+1] = a[i+1] then ( count := count + 2 ; var swapped : int := 1 ) else skip)) ; if swapped = 0 & (count->compareTo(n - 1)) < 0 then ( count := count + 1 ) else skip ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- coin=[10,50,100,500,500000] first=True while True : bill=int(input()) if bill==0 : break ; if not first : print() else : first=False posses=list(map(int,input().split())) Sumcoin=sum(coin[i]*posses[i]for i in range(4)) change=Sumcoin-bill ChangeCoin=[change % coin[i+1]//coin[i]for i in range(4)] hand=[posses[i]-ChangeCoin[i]for i in range(4)] for i in range(4): if posses[i]>ChangeCoin[i]: print(coin[i],hand[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var coin : Sequence := Sequence{10}->union(Sequence{50}->union(Sequence{100}->union(Sequence{500}->union(Sequence{ 500000 })))) ; var first : boolean := true ; while true do ( var bill : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if bill = 0 then ( break; ) else skip ; if not(first) then ( execute (->display() ) else ( first := false ) ; var posses : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var Sumcoin : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name coin)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) * (expr (atom (name posses)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 4))))))))) )))))))))->sum() ; var change : double := Sumcoin - bill ; var ChangeCoin : Sequence := Integer.subrange(0, 4-1)->select(i | true)->collect(i | (change mod coin[i + 1+1] div coin[i+1])) ; var hand : Sequence := Integer.subrange(0, 4-1)->select(i | true)->collect(i | (posses[i+1] - ChangeCoin[i+1])) ; for i : Integer.subrange(0, 4-1) do ( if (posses[i+1]->compareTo(ChangeCoin[i+1])) > 0 then ( execute (coin[i+1])->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input for _ in[0]*int(I()): n,k=map(int,I().split()); a=sorted(map(len,I().strip('L').split('W'))); m=len(a)+k while a and a[0]<=k : k-=a.pop(0) print((2*min(n,m-1)-len(a)or 1)-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + ((I())))->toInteger()) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (I().split())->collect( _x | (OclType["int"])->apply(_x) ); var a : Sequence := (I()->trim().split('W'))->collect( _x | (len)->apply(_x) )->sort(); var m : int := (a)->size() + k ; while a & (a->first()->compareTo(k)) <= 0 do ( k := k - a->at(0`firstArg+1) ; a := a->excludingAt(0+1)) ; execute ((2 * Set{n, m - 1}->min() - (a)->size() or 1) - 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def back_oturigation(fee,coin_values,coin_nums): oturi=coin_values[0]*coin_nums[0]+coin_values[1]*coin_nums[1]+coin_values[2]*coin_nums[2]+coin_values[3]*coin_nums[3]-fee use_coins=[0]*len(coin_values) no_use_coins=[0]*len(coin_values) for i in range(len(coin_values)-1,-1,-1): no_use_coins[i]=int(oturi/coin_values[i]) oturi=oturi-(coin_values[i]*no_use_coins[i]) for i in range(0,len(use_coins),1): use_coins[i]=coin_nums[i]-no_use_coins[i] if use_coins[i]>0 : print(str(coin_values[i])+''+str(use_coins[i])) if __name__=="__main__" : first=True while(True): total_fee=int(input('')) if total_fee==0 : break if first : first=False else : print('') coins=input('') coins=coins.split('') coins=[int(coin)for coin in coins] coin_values=[10,50,100,500] back_oturigation(total_fee,coin_values,coins) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var first : boolean := true ; while (true) do ( var total_fee : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; if total_fee = 0 then ( break ) else skip ; if first then ( first := false ) else ( execute ('')->display() ) ; var coins : String := (OclFile["System.in"]).readLine('') ; coins := coins.split('') ; coins := coins->characters()->select(coin | true)->collect(coin | (("" + ((coin)))->toInteger())) ; coin_values := Sequence{10}->union(Sequence{50}->union(Sequence{100}->union(Sequence{ 500 }))) ; back_oturigation(total_fee, coin_values, coins)) ) else skip; operation back_oturigation(fee : OclAny, coin_values : OclAny, coin_nums : OclAny) pre: true post: true activity: var oturi : double := coin_values->first() * coin_nums->first() + coin_values[1+1] * coin_nums[1+1] + coin_values[2+1] * coin_nums[2+1] + coin_values[3+1] * coin_nums[3+1] - fee ; var use_coins : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (coin_values)->size()) ; var no_use_coins : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (coin_values)->size()) ; for i : Integer.subrange(-1 + 1, (coin_values)->size() - 1)->reverse() do ( no_use_coins[i+1] := ("" + ((oturi / coin_values[i+1])))->toInteger() ; oturi := oturi - (coin_values[i+1] * no_use_coins[i+1])) ; for i : Integer.subrange(0, (use_coins)->size()-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( use_coins[i+1] := coin_nums[i+1] - no_use_coins[i+1] ; if use_coins[i+1] > 0 then ( execute (("" + ((coin_values[i+1]))) + '' + ("" + ((use_coins[i+1]))))->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- coins=[10,50,100,500] flg=0 while 1 : subtotal=int(input()) if subtotal==0 : break if flg==1 : print() s_purse=list(map(int,input().split())) ans=[0,0,0,0] for id in range(len(coins)): if id==0 : continue payable=0 for i in range(len(coins)-id): payable+=coins[i]*s_purse[i] while 1 : if payableunion(Sequence{50}->union(Sequence{100}->union(Sequence{ 500 }))) ; var flg : int := 0 ; while 1 do ( var subtotal : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if subtotal = 0 then ( break ) else skip ; if flg = 1 then ( execute (->display() ) else skip ; var s_purse : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))) ; for id : Integer.subrange(0, (coins)->size()-1) do ( if id = 0 then ( continue ) else skip ; var payable : int := 0 ; for i : Integer.subrange(0, (coins)->size() - id-1) do ( payable := payable + coins[i+1] * s_purse[i+1]) ; while 1 do ( if (payable->compareTo(subtotal)) < 0 then ( ans->reverse()->at(-(-id)) := ans->reverse()->at(-(-id)) + 1 ; s_purse->reverse()->at(-(-id)) := s_purse->reverse()->at(-(-id)) - 1 ; subtotal := subtotal - coins->reverse()->at(-(-id)) ) else ( break ))) ; if 0 < subtotal then ( ans->first() := ans->first() + subtotal div 10 ; s_purse->first() := s_purse->first() - subtotal div 10 ; subtotal := subtotal - coins->first() * ans->first() ) else skip ; var charge : int := -subtotal ; var cha_coins : Sequence := Sequence{charge div 10}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))) ; var hitsuyou : Sequence := Sequence{5}->union(Sequence{2}->union(Sequence{ 5 })) ; for i : Integer.subrange(0, (coins)->size() - 1-1) do ( if (hitsuyou[i+1]->compareTo(cha_coins[i+1])) <= 0 then ( cha_coins[i + 1+1] := cha_coins[i+1] div hitsuyou[i+1] ; cha_coins[i+1] := cha_coins[i+1] mod hitsuyou[i+1] ) else skip ; if (hitsuyou[i+1]->compareTo(cha_coins[i+1] + s_purse[i+1])) <= 0 then ( ans[i+1] := ans[i+1] + (cha_coins[i+1] + s_purse[i+1]) div hitsuyou[i+1] * hitsuyou[i+1] - cha_coins[i+1] ; cha_coins[i + 1+1] := cha_coins[i + 1+1] + (cha_coins[i+1] + s_purse[i+1]) div hitsuyou[i+1] ) else skip) ; for i : Integer.subrange(0, (coins)->size()-1) do ( if ans[i+1] then ( execute (coins[i+1])->display() ) else skip) ; flg := 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=10**15 MOD=10**9+7 money=(10,50,100,500) def solve(N): coins=list(map(int,input().split())) tot=sum(coins[i]*money[i]for i in range(4)) ans=[0]*4 tot-=N for i in range(3,-1,-1): X=tot//money[i] tot %=money[i] ans[i]=max(coins[i]-X,0) for i in range(4): if ans[i]==0 : continue print(money[i],ans[i]) def main(): i=0 while True : N=int(input()) if N==0 : break if i>0 : print('') i+=1 solve(N) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INF : double := (10)->pow(15) ; var MOD : double := (10)->pow(9) + 7 ; var money : OclAny := Sequence{10, 50, 100, 500} ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(N : OclAny) pre: true post: true activity: var coins : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var tot : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name coins)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) * (expr (atom (name money)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 4))))))))) )))))))))->sum() ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 4) ; tot := tot - N ; for i : Integer.subrange(-1 + 1, 3)->reverse() do ( var X : int := tot div money[i+1] ; tot := tot mod money[i+1] ; ans[i+1] := Set{coins[i+1] - X, 0}->max()) ; for i : Integer.subrange(0, 4-1) do ( if ans[i+1] = 0 then ( continue ) else skip ; execute (money[i+1])->display()); operation main() pre: true post: true activity: var i : int := 0 ; while true do ( N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; if i > 0 then ( execute ('')->display() ) else skip ; i := i + 1 ; solve(N)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- count=0 coins=[10,50,100,500] while 1 : price=int(input()) if price==0 : break if count!=0 : print('') wallet=list(map(int,input().split(' '))) cash=wallet[0]*10+wallet[1]*50+wallet[2]*100+wallet[3]*500 charge=cash-price chargecoins=((charge % 50)//10,(charge % 100)//50,(charge % 500)//100,charge//500) for i in range(4): if wallet[i]>chargecoins[i]: print('{}{}'.format(coins[i],wallet[i]-chargecoins[i])) count+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var count : int := 0 ; var coins : Sequence := Sequence{10}->union(Sequence{50}->union(Sequence{100}->union(Sequence{ 500 }))) ; while 1 do ( var price : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if price = 0 then ( break ) else skip ; if count /= 0 then ( execute ('')->display() ) else skip ; var wallet : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var cash : double := wallet->first() * 10 + wallet[1+1] * 50 + wallet[2+1] * 100 + wallet[3+1] * 500 ; var charge : double := cash - price ; var chargecoins : OclAny := Sequence{(charge mod 50) div 10, (charge mod 100) div 50, (charge mod 500) div 100, charge div 500} ; for i : Integer.subrange(0, 4-1) do ( if (wallet[i+1]->compareTo(chargecoins[i+1])) > 0 then ( execute (StringLib.interpolateStrings('{}{}', Sequence{coins[i+1], wallet[i+1] - chargecoins[i+1]}))->display() ) else skip) ; count := count + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B=map(int,input().split()) print((A-1)*(B-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((A - 1) * (B - 1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=[int(i)for i in input().split()] ans=a*b-(a+b-1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : double := a * b - (a + b - 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- listA=list(map(int,input().split())) print(listA[0]*listA[1]-(listA[0]+listA[1]-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var listA : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (listA->first() * listA[1+1] - (listA->first() + listA[1+1] - 1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): numer=1 denom=0 for i in reversed(range(100)): numer,denom=e_contfrac_term(i)*numer+denom,numer ans=sum(int(c)for c in str(numer)) return str(ans) def e_contfrac_term(i): if i==0 : return 2 elif i % 3==2 : return i//3*2+2 else : return 1 if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var numer : int := 1 ; var denom : int := 0 ; for i : (Integer.subrange(0, 100-1))->reverse() do ( Sequence{numer,denom} := Sequence{e_contfrac_term(i) * numer + denom,numer}) ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name numer)))))))) )))))))))->sum() ; return ("" + ((ans))); operation e_contfrac_term(i : OclAny) : OclAny pre: true post: true activity: if i = 0 then ( return 2 ) else (if i mod 3 = 2 then ( return i div 3 * 2 + 2 ) else ( return 1 ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()); print(a*b-a-b+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); execute (a * b - a - b + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) ans=(a-1)*(b-1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : double := (a - 1) * (b - 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,k=map(int,input().split()) s=input() c=1 f=s.find("*") while ftoInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var c : int := 1 ; var f : int := s->indexOf("*") - 1 ; while (f->compareTo(s.rfind("*"))) < 0 do ( f := s.rfind("*", f, f + k + 1) ; c := c + 1) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input for _ in[0]*int(s()): n,k=map(int,s().split()); a=sorted(map(len,s().strip('L').split('W'))); m=len(a)+k while a and a[0]<=k : k-=a.pop(0) print((2*min(n,m-1)-len(a)or 1)-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := input ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + ((s())))->toInteger()) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (s().split())->collect( _x | (OclType["int"])->apply(_x) ); var a : Sequence := (s()->trim().split('W'))->collect( _x | (len)->apply(_x) )->sort(); var m : int := (a)->size() + k ; while a & (a->first()->compareTo(k)) <= 0 do ( k := k - a->at(0`firstArg+1) ; a := a->excludingAt(0+1)) ; execute ((2 * Set{n, m - 1}->min() - (a)->size() or 1) - 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) s=input() count=0 gap=0 last=0 lastl=-1 for i in range(n): if count==0 and s[i]=="*" : count=1 last=i lastl=i gap=0 continue if s[i]=="*" : last=i gap+=1 else : gap+=1 if gap==k and count>=1 : if lastl==last : break count+=1 gap=i-last lastl=last if lastl!=last : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var count : int := 0 ; var gap : int := 0 ; var last : int := 0 ; var lastl : int := -1 ; for i : Integer.subrange(0, n-1) do ( if count = 0 & s[i+1] = "*" then ( count := 1 ; last := i ; lastl := i ; gap := 0 ; continue ) else skip ; if s[i+1] = "*" then ( last := i ; gap := gap + 1 ) else ( gap := gap + 1 ) ; if gap = k & count >= 1 then ( if lastl = last then ( break ) else skip ; count := count + 1 ; gap := i - last ; lastl := last ) else skip) ; if lastl /= last then ( count := count + 1 ) else skip ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from itertools import combinations iput=sys.stdin.readline for _ in range(int(input())): n,k=map(int,input().split()) s=list(input()) if s.count('*')==1 : print(1) else : ans=2 q=n-s[: :-1].index('*') s=s[s.index('*'): q] val=[] count=1 for i in range(1,len(s)): if s[i]=='*' : val.append(count) count=1 else : count+=1 count=0 for i in val : count+=i if count>k : ans+=1 count=i print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var iput : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if s->count('*') = 1 then ( execute (1)->display() ) else ( var ans : int := 2 ; var q : double := n - s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->indexOf('*') - 1 ; s := s.subrange(s->indexOf('*') - 1+1, q) ; var val : Sequence := Sequence{} ; var count : int := 1 ; for i : Integer.subrange(1, (s)->size()-1) do ( if s[i+1] = '*' then ( execute ((count) : val) ; count := 1 ) else ( count := count + 1 )) ; count := 0 ; for i : val do ( count := count + i ; if (count->compareTo(k)) > 0 then ( ans := ans + 1 ; count := i ) else skip) ; execute (ans)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import deque input=lambda : sys.stdin.readline().rstrip("\n") for _ in range(int(input())): n,k=map(int,input().split()) a=input() l=a.find("*") r=a.rfind("*") sum=1 if r==l : print(sum) else : sum+=1 while r-l>k : l=a[: l+1+k].rfind("*") sum+=1 print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip("\n")) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : String := (OclFile["System.in"]).readLine() ; var l : int := a->indexOf("*") - 1 ; var r : OclAny := a.rfind("*") ; var sum : int := 1 ; if r = l then ( execute (sum)->display() ) else ( sum := sum + 1 ; while (r - l->compareTo(k)) > 0 do ( l := a.subrange(1,l + 1 + k).rfind("*") ; sum := sum + 1) ; execute (sum)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Convert(radian): pi=3.14159 degree=radian*(180/pi) return degree radian=5 print("degree=",(Convert(radian))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; radian := 5 ; execute ("degree=")->display(); operation Convert(radian : OclAny) : OclAny pre: true post: true activity: var pi : double := 3.14159 ; var degree : double := radian * (180 / pi) ; return degree; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def isPower(x,y): res1=math.log(y)//math.log(x); res2=math.log(y)/math.log(x); return 1 if(res1==res2)else 0 ; if __name__=='__main__' : print(isPower(27,729)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( execute (isPower(27, 729))->display(); ) else skip; operation isPower(x : OclAny, y : OclAny) pre: true post: true activity: var res1 : int := (y)->log() div (x)->log(); ; var res2 : double := (y)->log() / (x)->log(); ; return if (res1 = res2) then 1 else 0 endif;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=list(map(int,input().split())) distress=0 for _ in range(n): ch,d=input().split() d=int(d) if ch=='+' : x+=d continue if xcollect( _x | (OclType["int"])->apply(_x) )) ; var distress : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var ch : OclAny := null; var d : OclAny := null; Sequence{ch,d} := input().split() ; var d : int := ("" + ((d)))->toInteger() ; if ch = '+' then ( x := x + d ; continue ) else skip ; if (x->compareTo(d)) < 0 then ( distress := distress + 1 ) else ( x := x - d )) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): line=input() line=line.split(' ') n=int(line[0]) t=int(line[1]) line=input() line=line.split(' ') total=0 for i in range(1,n): total+=min(t,int(line[i])-int(line[i-1])) print(total+t) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var line : String := (OclFile["System.in"]).readLine() ; line := line.split(' ') ; var n : int := ("" + ((line->first())))->toInteger() ; var t : int := ("" + ((line[1+1])))->toInteger() ; line := (OclFile["System.in"]).readLine() ; line := line.split(' ') ; var total : int := 0 ; for i : Integer.subrange(1, n-1) do ( total := total + Set{t, ("" + ((line[i+1])))->toInteger() - ("" + ((line[i - 1+1])))->toInteger()}->min()) ; execute (total + t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=input().split() n=int(n) x=int(x) z3lan=0 for i in range(n): a,nm=input().split() nm=int(nm) if a=='+' : x+=nm else : if x>=nm : x-=nm else : z3lan+=1 print(x,z3lan) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var x : int := ("" + ((x)))->toInteger() ; var z3lan : int := 0 ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var nm : OclAny := null; Sequence{a,nm} := input().split() ; var nm : int := ("" + ((nm)))->toInteger() ; if a = '+' then ( x := x + nm ) else ( if (x->compareTo(nm)) >= 0 then ( x := x - nm ) else ( z3lan := z3lan + 1 ) )) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=map(int,input().split()); ctr=0 for i in range(n): sy,inp=input().split() inp=int(inp) if sy=='+' : x+=inp else : if inp>x : ctr+=1 else : x-=inp print(x,end=" ") print(ctr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var ctr : int := 0 ; for i : Integer.subrange(0, n-1) do ( var sy : OclAny := null; var inp : OclAny := null; Sequence{sy,inp} := input().split() ; var inp : int := ("" + ((inp)))->toInteger() ; if sy = '+' then ( x := x + inp ) else ( if (inp->compareTo(x)) > 0 then ( ctr := ctr + 1 ) else ( x := x - inp ) )) ; execute (x)->display() ; execute (ctr)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- o,p=map(int,input().split()) left=0 for i in range(o): c,cur=input().split() cur=int(cur) if c=="+" : p+=cur elif p>=cur : p-=cur else : left+=1 print(p,left) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var o : OclAny := null; var p : OclAny := null; Sequence{o,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var left : int := 0 ; for i : Integer.subrange(0, o-1) do ( var c : OclAny := null; var cur : OclAny := null; Sequence{c,cur} := input().split() ; var cur : int := ("" + ((cur)))->toInteger() ; if c = "+" then ( p := p + cur ) else (if (p->compareTo(cur)) >= 0 then ( p := p - cur ) else ( left := left + 1 ) ) ) ; execute (p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=map(int,input().split()) distress=0 for i in range(n): s,a=input().split() a=int(a) if(s=="+"): x+=a elif(s=="-" and x-a>=0): x-=a else : distress+=1 print(x,distress) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var distress : int := 0 ; for i : Integer.subrange(0, n-1) do ( var s : OclAny := null; var a : OclAny := null; Sequence{s,a} := input().split() ; var a : int := ("" + ((a)))->toInteger() ; if (s = "+") then ( x := x + a ) else (if (s = "-" & x - a >= 0) then ( x := x - a ) else ( distress := distress + 1 ) ) ) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) arr=[0]; for i in range(t): n,sm=map(int,input().split()) count=0 ; count1=0 ; count2=-2 a=input() arr.clear() for j in range(n): if a[j]=='W' : count+=1 ; count1+=1 if count2+1==j : count1+=1 if count!=1 and count2+1!=j : arr.append(j-count2-1) count2=j sm=min(sm,n-count) arr=sorted(arr) if count==0 : print(max(0,2*sm-1)) else : sz=len(arr) for k in range(sz): if sm>=arr[k]: count1+=2*arr[k]+1 ; sm-=arr[k] else : count1+=2*sm sm=0 print(count1+2*sm) arr.clear() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Sequence{ 0 }; ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var sm : OclAny := null; Sequence{n,sm} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var count : int := 0; var count1 : int := 0; var count2 : int := -2 ; var a : String := (OclFile["System.in"]).readLine() ; execute (arr /<: arr) ; for j : Integer.subrange(0, n-1) do ( if a[j+1] = 'W' then ( count := count + 1; count1 := count1 + 1 ; if count2 + 1 = j then ( count1 := count1 + 1 ) else skip ; if count /= 1 & count2 + 1 /= j then ( execute ((j - count2 - 1) : arr) ) else skip ; count2 := j ) else skip) ; var sm : OclAny := Set{sm, n - count}->min() ; arr := arr->sort() ; if count = 0 then ( execute (Set{0, 2 * sm - 1}->max())->display() ) else ( var sz : int := (arr)->size() ; for k : Integer.subrange(0, sz-1) do ( if (sm->compareTo(arr[k+1])) >= 0 then ( count1 := count1 + 2 * arr[k+1] + 1; sm := sm - arr[k+1] ) else ( count1 := count1 + 2 * sm ; sm := 0 )) ; execute (count1 + 2 * sm)->display() ; execute (arr /<: arr) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) prev=list(map(int,input().split())) max_disA=-1 max_disB=-1 min_timeA=10**9 min_timeB=10**9 for _ in range(n-1): curr=list(map(int,input().split())) if prev[1]!=curr[1]and prev[2]==curr[2]: dis=math.sqrt((prev[3]-curr[3])**2+(prev[4]-curr[4])**2) if max_disAcurr[0]-prev[0]: max_disA=dis min_timeA=curr[0]-prev[0] elif dis==max_disB and prev[2]==0 and min_timeB>curr[0]-prev[0]: max_disB=dis min_timeB=curr[0]-prev[0] prev=curr if max_disA==-1 : print(-1,-1) else : print(max_disA,min_timeA/60) if max_disB==-1 : print(-1,-1) else : print(max_disB,min_timeB/60) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var prev : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var max_disA : int := -1 ; var max_disB : int := -1 ; var min_timeA : double := (10)->pow(9) ; var min_timeB : double := (10)->pow(9) ; for _anon : Integer.subrange(0, n - 1-1) do ( var curr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if prev[1+1] /= curr[1+1] & prev[2+1] = curr[2+1] then ( var dis : double := (((prev[3+1] - curr[3+1]))->pow(2) + ((prev[4+1] - curr[4+1]))->pow(2))->sqrt() ; if (max_disA->compareTo(dis)) < 0 & prev[2+1] = 0 then ( max_disA := dis ; min_timeA := curr->first() - prev->first() ) else (if (max_disB->compareTo(dis)) < 0 & prev[2+1] = 1 then ( max_disB := dis ; min_timeB := curr->first() - prev->first() ) else (if dis = max_disA & prev[2+1] = 0 & (min_timeA->compareTo(curr->first() - prev->first())) > 0 then ( max_disA := dis ; min_timeA := curr->first() - prev->first() ) else (if dis = max_disB & prev[2+1] = 0 & (min_timeB->compareTo(curr->first() - prev->first())) > 0 then ( max_disB := dis ; min_timeB := curr->first() - prev->first() ) else skip ) ) ) ) else skip ; prev := curr) ; if max_disA = -1 then ( execute (-1)->display() ) else ( execute (max_disA)->display() ) ; if max_disB = -1 then ( execute (-1)->display() ) else ( execute (max_disB)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) prev=list(map(int,input().split())) max_disA=-1 max_disB=-1 min_timeA=10**9 min_timeB=10**9 for _ in range(n-1): curr=list(map(int,input().split())) if prev[1]!=curr[1]and prev[2]==curr[2]: dis=math.sqrt((prev[3]-curr[3])**2+(prev[4]-curr[4])**2) if max_disAcurr[0]-prev[0]: max_disA=dis min_timeA=curr[0]-prev[0] elif dis==max_disB and prev[2]==1 and min_timeB>curr[0]-prev[0]: max_disB=dis min_timeB=curr[0]-prev[0] prev=curr if max_disA==-1 : print(-1,-1) else : print(max_disA,min_timeA/60) if max_disB==-1 : print(-1,-1) else : print(max_disB,min_timeB/60) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var prev : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var max_disA : int := -1 ; var max_disB : int := -1 ; var min_timeA : double := (10)->pow(9) ; var min_timeB : double := (10)->pow(9) ; for _anon : Integer.subrange(0, n - 1-1) do ( var curr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if prev[1+1] /= curr[1+1] & prev[2+1] = curr[2+1] then ( var dis : double := (((prev[3+1] - curr[3+1]))->pow(2) + ((prev[4+1] - curr[4+1]))->pow(2))->sqrt() ; if (max_disA->compareTo(dis)) < 0 & prev[2+1] = 0 then ( max_disA := dis ; min_timeA := curr->first() - prev->first() ) else (if (max_disB->compareTo(dis)) < 0 & prev[2+1] = 1 then ( max_disB := dis ; min_timeB := curr->first() - prev->first() ) else (if dis = max_disA & prev[2+1] = 0 & (min_timeA->compareTo(curr->first() - prev->first())) > 0 then ( max_disA := dis ; min_timeA := curr->first() - prev->first() ) else (if dis = max_disB & prev[2+1] = 1 & (min_timeB->compareTo(curr->first() - prev->first())) > 0 then ( max_disB := dis ; min_timeB := curr->first() - prev->first() ) else skip ) ) ) ) else skip ; prev := curr) ; if max_disA = -1 then ( execute (-1)->display() ) else ( execute (max_disA)->display() ) ; if max_disB = -1 then ( execute (-1)->display() ) else ( execute (max_disB)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) last=[-1]*5 At=-1 Al=-1 Bt=-1 Bl=-1 for _ in range(n): l=list(map(int,input().split())) if last[2]!=l[2]or last[1]==-1 or last[1]==l[1]: last=l elif last[1]!=l[1]: len=math.sqrt((last[3]-l[3])**2+(last[4]-l[4])**2) tim=l[0]-last[0] if l[2]==0 : if Al<=len : Al=len At=tim elif l[2]==1 : if Bl<=len : Bl=len Bt=tim last=l if Al!=-1 : print("{0:.10f}".format(round(Al,10)),end=" ") print("{0:.10f}".format(At/60)) else : print("-1-1") if Bl!=-1 : print("{0:.10f}".format(round(Bl,10)),end=" ") print("{0:.10f}".format(Bt/60)) else : print("-1-1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var last : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, 5) ; var At : int := -1 ; var Al : int := -1 ; var Bt : int := -1 ; var Bl : int := -1 ; for _anon : Integer.subrange(0, n-1) do ( var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if last[2+1] /= l[2+1] or last[1+1] = -1 or last[1+1] = l[1+1] then ( last := l ) else (if last[1+1] /= l[1+1] then ( var len : double := (((last[3+1] - l[3+1]))->pow(2) + ((last[4+1] - l[4+1]))->pow(2))->sqrt() ; var tim : double := l->first() - last->first() ; if l[2+1] = 0 then ( if (Al->compareTo(len)) <= 0 then ( Al := len ; At := tim ) else skip ) else (if l[2+1] = 1 then ( if (Bl->compareTo(len)) <= 0 then ( Bl := len ; Bt := tim ) else skip ) else skip) ) else skip) ; last := l) ; if Al /= -1 then ( execute (StringLib.interpolateStrings("{0:.10f}", Sequence{MathLib.roundN(Al, 10)}))->display() ; execute (StringLib.interpolateStrings("{0:.10f}", Sequence{At / 60}))->display() ) else ( execute ("-1-1")->display() ) ; if Bl /= -1 then ( execute (StringLib.interpolateStrings("{0:.10f}", Sequence{MathLib.roundN(Bl, 10)}))->display() ; execute (StringLib.interpolateStrings("{0:.10f}", Sequence{Bt / 60}))->display() ) else ( execute ("-1-1")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def encode(s,k): newS="" for i in range(len(s)): val=ord(s[i]) dup=k if val+k>122 : k-=(122-val) k=k % 26 newS+=chr(96+k) else : newS+=chr(val+k) k=dup print(newS) str="abc" k=28 encode(str,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var OclType["String"] : String := "abc" ; k := 28 ; encode(OclType["String"], k); operation encode(s : OclAny, k : OclAny) pre: true post: true activity: var newS : String := "" ; for i : Integer.subrange(0, (s)->size()-1) do ( var val : int := (s[i+1])->char2byte() ; var dup : OclAny := k ; if val + k > 122 then ( k := k - (122 - val) ; k := k mod 26 ; newS := newS + (96 + k)->byte2char() ) else ( newS := newS + (val + k)->byte2char() ) ; k := dup) ; execute (newS)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPossible(x,y,k): minMoves=abs(x)+abs(y) if(k>=minMoves and(k-minMoves)% 2==0): return True return False x=5 y=8 k=20 if(isPossible(x,y,k)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := 5 ; y := 8 ; k := 20 ; if (isPossible(x, y, k)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isPossible(x : OclAny, y : OclAny, k : OclAny) : OclAny pre: true post: true activity: var minMoves : double := (x)->abs() + (y)->abs() ; if ((k->compareTo(minMoves)) >= 0 & (k - minMoves) mod 2 = 0) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,T=map(int,input().split()); t=[int(x)for x in input().split()]; end=0 ; ans=0 ; for i in range(N): if end>t[i]: ans+=t[i]+T-end ; else : ans+=T ; end=t[i]+T ; print(ans); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var T : OclAny := null; Sequence{N,T} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); ; var t : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); ; var end : int := 0; ; var ans : int := 0; ; for i : Integer.subrange(0, N-1) do ( if (end->compareTo(t[i+1])) > 0 then ( ans := ans + t[i+1] + T - end; ) else ( ans := ans + T; ) ; end := t[i+1] + T;) ; execute (ans)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fill0X(m,n): i,k,l=0,0,0 r=m c=n a=[[None]*n for i in range(m)] x='X' while kdisplay() ; fill0X(5, 6) ; execute ("Output for m=4,n=4")->display() ; fill0X(4, 4) ; execute ("Output for m=3,n=4")->display() ; fill0X(3, 4) ) else skip; operation fill0X(m : OclAny, n : OclAny) pre: true post: true activity: var i : OclAny := null; var k : OclAny := null; var l : OclAny := null; Sequence{i,k,l} := Sequence{0,0,0} ; var r : OclAny := m ; var c : OclAny := n ; var a : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ null }, n))) ; var x : String := 'X' ; while (k->compareTo(m)) < 0 & (l->compareTo(n)) < 0 do ( for i : Integer.subrange(l, n-1) do ( a[k+1][i+1] := x) ; k := k + 1 ; for i : Integer.subrange(k, m-1) do ( a[i+1][n - 1+1] := x) ; n := n - 1 ; if (k->compareTo(m)) < 0 then ( for i : Integer.subrange(l - 1 + 1, n - 1)->reverse() do ( a[m - 1+1][i+1] := x) ; m := m - 1 ) else skip ; if (l->compareTo(n)) < 0 then ( for i : Integer.subrange(k - 1 + 1, m - 1)->reverse() do ( a[i+1][l+1] := x) ; l := l + 1 ) else skip ; x := if x = '0' then 'X' else '0' endif) ; for i : Integer.subrange(0, r-1) do ( for j : Integer.subrange(0, c-1) do ( execute (a[i+1][j+1])->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) if n % 7==0 : print(n) else : ans=-1 for j in range(10): if(n-n % 10+j)% 7==0 : ans=n-n % 10+j print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 7 = 0 then ( execute (n)->display() ) else ( var ans : int := -1 ; for j : Integer.subrange(0, 10-1) do ( if (n - n mod 10 + j) mod 7 = 0 then ( ans := n - n mod 10 + j ) else skip) ; execute (ans)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): s=input() n=int(s) if n % 7==0 : print(n) else : for i in range(1,10): n=int(str(i)+s[1 :]) if n % 7==0 : print(n) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var n : int := ("" + ((s)))->toInteger() ; if n mod 7 = 0 then ( execute (n)->display() ) else ( for i : Integer.subrange(1, 10-1) do ( n := ("" + ((("" + ((i))) + s->tail())))->toInteger() ; if n mod 7 = 0 then ( execute (n)->display() ; break ) else skip) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): def check(s): for i in range(len(s)-1,-1,-1): for j in range(0,10): k=s[i] s[i]=str(j) if int(''.join(s))% 7==0 : return int(''.join(s)) s[i]=k n=int(input()) if n % 7==0 : print(n) else : s=list(str(n)) print(check(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 7 = 0 then ( execute (n)->display() ) else ( s := (("" + ((n))))->characters() ; execute (check(s))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input("")) for i in range(t): n=int(input("")) k=n % 7 if(n % 10-k<0): n=n+7-k else : n=n-k print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine(""))))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine(""))))->toInteger() ; var k : int := n mod 7 ; if (n mod 10 - k < 0) then ( n := n + 7 - k ) else ( n := n - k ) ; execute (n)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() p=input() judge=0 for i in range(0,len(s)): s_double=s+s if p in s_double : judge+=1 if judge!=0 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var p : String := (OclFile["System.in"]).readLine() ; var judge : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( var s_double : String := s + s ; if (s_double)->characters()->includes(p) then ( judge := judge + 1 ) else skip) ; if judge /= 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=input() if int(n)% 7==0 : print(n) else : n=n[:-1] for j in range(10): if int(n+str(j))% 7==0 : print(n+str(j)) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : String := (OclFile["System.in"]).readLine() ; if ("" + ((n)))->toInteger() mod 7 = 0 then ( execute (n)->display() ) else ( n := n->front() ; for j : Integer.subrange(0, 10-1) do ( if ("" + ((n + ("" + ((j))))))->toInteger() mod 7 = 0 then ( execute (n + ("" + ((j))))->display() ; break ) else skip) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq import sys from collections import defaultdict def dijkstra(graph,size,start): d=[float('inf')]*size d[start]=0 q=[(0,start)] while len(q): du,u=heapq.heappop(q) for length,v in graph[u]: if d[v]>du+length : d[v]=du+length heapq.heappush(q,(d[v],v)) return d f=sys.stdin while True : n,m=map(int,f.readline().split()) if n==0 : break abct=[map(int,f.readline().split())for _ in range(n)] d=[defaultdict(list),defaultdict(list)] for ai,bi,ci,ti in abct : ai-=1 bi-=1 d[0][ai].append((ci,bi)) d[0][bi].append((ci,ai)) d[1][ai].append((ti,bi)) d[1][bi].append((ti,ai)) dist={} for i in range(int(f.readline())): p,q,r=map(int,f.readline().split()) p-=1 q-=1 try : print(dist[(q,r)][p]) except KeyError : try : print(dist[(p,r)][q]) except : dist[(p,r)]=dijkstra(d[r],m,p) print(dist[(p,r)][q]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var f : OclFile := OclFile["System.in"] ; while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var abct : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; d := Sequence{defaultdict(OclType["Sequence"])}->union(Sequence{ defaultdict(OclType["Sequence"]) }) ; for _tuple : abct do (var _indx : int := 1; var ai : OclAny := _tuple->at(_indx); _indx := _indx + 1; var bi : OclAny := _tuple->at(_indx); _indx := _indx + 1; var ci : OclAny := _tuple->at(_indx); _indx := _indx + 1; var ti : OclAny := _tuple->at(_indx); ai := ai - 1 ; bi := bi - 1 ; (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ai)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name ci)))))) , (test (logical_test (comparison (expr (atom (name bi))))))) )))))))) )))) ; (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name bi)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name ci)))))) , (test (logical_test (comparison (expr (atom (name ai))))))) )))))))) )))) ; (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ai)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name ti)))))) , (test (logical_test (comparison (expr (atom (name bi))))))) )))))))) )))) ; (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name bi)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name ti)))))) , (test (logical_test (comparison (expr (atom (name ai))))))) )))))))) ))))) ; var dist : OclAny := Set{} ; for i : Integer.subrange(0, ("" + ((f.readLine())))->toInteger()-1) do ( var p : OclAny := null; var r : OclAny := null; Sequence{p,q,r} := (f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; p := p - 1 ; q := q - 1 ; try ( execute (dist[Sequence{q, r}+1][p+1])->display()) (except_clause except (test (logical_test (comparison (expr (atom (name KeyError)))))) : (suite (stmt (compound_stmt try : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name dist)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name p)))))) , (test (logical_test (comparison (expr (atom (name r))))))) )))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name q)))))))) ])))))))) ))))))))))))) (except_clause except : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dist)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name p)))))) , (test (logical_test (comparison (expr (atom (name r))))))) )))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dijkstra)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name m))))))) , (argument (test (logical_test (comparison (expr (atom (name p)))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name dist)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name p)))))) , (test (logical_test (comparison (expr (atom (name r))))))) )))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name q)))))))) ])))))))) )))))))))))))))))))); operation dijkstra(graph : OclAny, size : OclAny, start : OclAny) : OclAny pre: true post: true activity: var d : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (('inf')))->toReal() }, size) ; d[start+1] := 0 ; var q : Sequence := Sequence{ Sequence{0, start} } ; while (q)->size() do ( var du : OclAny := null; var u : OclAny := null; Sequence{du,u} := heapq.heappop(q) ; for _tuple : graph[u+1] do (var _indx : int := 1; var length : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if (d[v+1]->compareTo(du + length)) > 0 then ( d[v+1] := du + length ; heapq.heappush(q, Sequence{d[v+1], v}) ) else skip)) ; return d; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def warshall_floyd(v_count : int,matrix : list)->list : for i in range(v_count): for j,c2 in enumerate(row[i]for row in matrix): for k,(c1,c3)in enumerate(zip(matrix[j],matrix[i])): if c1>c2+c3 : matrix[j][k]=c2+c3 return matrix while True : e_count,v_count=map(int,input().split()) if not e_count : break inf=float("inf") edges_cost,edges_time=[[inf]*v_count for _ in[0]*v_count],[[inf]*v_count for _ in[0]*v_count] for _ in[0]*e_count : a,b,cost,time=map(int,input().split()) a,b=a-1,b-1 edges_cost[a][b]=cost edges_cost[b][a]=cost edges_time[a][b]=time edges_time[b][a]=time warshall_floyd(v_count,edges_cost) warshall_floyd(v_count,edges_time) for _ in[0]*int(input()): p,q,r=map(int,input().split()) print((edges_time if r else edges_cost)[p-1][q-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var e_count : OclAny := null; var v_count : OclAny := null; Sequence{e_count,v_count} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if not(e_count) then ( break ) else skip ; var Math_PINFINITY : double := ("" + (("inf")))->toReal() ; var edges_cost : OclAny := null; var edges_time : OclAny := null; Sequence{edges_cost,edges_time} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, v_count)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ Math_PINFINITY }, v_count))),MatrixLib.elementwiseMult(Sequence{ 0 }, v_count)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ Math_PINFINITY }, v_count)))} ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, e_count) do ( var a : OclAny := null; var b : OclAny := null; var cost : OclAny := null; var time : OclAny := null; Sequence{a,b,cost,time} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{a - 1,b - 1} ; edges_cost[a+1][b+1] := cost ; edges_cost[b+1][a+1] := cost ; edges_time[a+1][b+1] := time ; edges_time[b+1][a+1] := time) ; warshall_floyd(v_count, edges_cost) ; warshall_floyd(v_count, edges_time) ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var p : OclAny := null; var q : OclAny := null; var r : OclAny := null; Sequence{p,q,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((if r then edges_time else edges_cost endif)[p - 1+1][q - 1+1])->display())); operation warshall_floyd(v_count : int, matrix : Sequence(OclAny)) : Sequence pre: true post: true activity: for i : Integer.subrange(0, v_count-1) do ( for _tuple : Integer.subrange(1, ((argument (test (logical_test (comparison (expr (atom (name row)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))) (comp_for for (exprlist (expr (atom (name row)))) in (logical_test (comparison (expr (atom (name matrix))))))))->size())->collect( _indx | Sequence{_indx-1, ((argument (test (logical_test (comparison (expr (atom (name row)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))) (comp_for for (exprlist (expr (atom (name row)))) in (logical_test (comparison (expr (atom (name matrix))))))))->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c2 : OclAny := _tuple->at(_indx); for _tuple : Integer.subrange(1, (Integer.subrange(1, matrix[j+1]->size())->collect( _indx | Sequence{matrix[j+1]->at(_indx), matrix[i+1]->at(_indx)} ))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(1, matrix[j+1]->size())->collect( _indx | Sequence{matrix[j+1]->at(_indx), matrix[i+1]->at(_indx)} ))->at(_indx)} ) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{c1, c3} : OclAny := _tuple->at(_indx); if (c1->compareTo(c2 + c3)) > 0 then ( matrix[j+1][k+1] := c2 + c3 ) else skip))) ; return matrix; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heappush,heappop import sys readline=sys.stdin.readline write=sys.stdout.write def solve(): M,N=map(int,readline().split()) if M==N==0 : return False G=[[]for i in range(N)] INF=10**18 def solve(s,t,u): dist=[INF]*N dist[s]=0 que=[(0,s)] while que : cost,v=heappop(que) if dist[v]collect( _x | (OclType["int"])->apply(_x) ) ; if M = N & (N == 0) then ( return false ) else skip ; var G : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{})) ; var INF : double := (10)->pow(18) ; skip ; for i : Integer.subrange(0, M-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c,t} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ); a := a - 1; b := b - 1 ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name b)))))) , (test (logical_test (comparison (expr (atom (name c)))))) , (test (logical_test (comparison (expr (atom (name t))))))) )))))))) )))) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name c)))))) , (test (logical_test (comparison (expr (atom (name t))))))) )))))))) ))))) ; var K : int := ("" + ((readline())))->toInteger() ; for i : Integer.subrange(0, K-1) do ( var p : OclAny := null; var q : OclAny := null; var r : OclAny := null; Sequence{p,q,r} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; write(StringLib.format("%d\n",solve(p - 1, q - 1, r + 1)))) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,tmax=map(int,input().split()) t=list(map(int,input().split())) ans=0 for i in range(n-1): if t[i+1]-t[i]collect( _x | (OclType["int"])->apply(_x) ) ; var t : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if (t[i + 1+1] - t[i+1]->compareTo(tmax)) < 0 then ( ans := ans + t[i + 1+1] - t[i+1] ) else ( ans := ans + tmax )) ; ans := ans + tmax ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heappush,heappop def Dijkstra(graph,start,goal): que=[(0,start)] visited=[False]*len(graph) while True : path_len,v=heappop(que) visited[v]=True if v==goal : print(path_len) break for w,edge_len in graph[v].items(): if not visited[w]: heappush(que,(path_len+edge_len,w)) while(True): dicco={} dicti={} n,m=map(int,input().split()) if n==0 and m==0 : break for i in range(m): dicco[i]={} dicti[i]={} for _ in range(n): a,b,c,t=map(int,input().split()) dicco[a-1][b-1]=c dicco[b-1][a-1]=c dicti[a-1][b-1]=t dicti[b-1][a-1]=t k=int(input()) for _ in range(k): p,q,r=map(int,input().split()) if not r : Dijkstra(dicco,p-1,q-1) else : Dijkstra(dicti,p-1,q-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while (true) do ( var dicco : OclAny := Set{} ; var dicti : OclAny := Set{} ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 & m = 0 then ( break ) else skip ; for i : Integer.subrange(0, m-1) do ( dicco[i+1] := Set{} ; dicti[i+1] := Set{}) ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var t : OclAny := null; Sequence{a,b,c,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; dicco[a - 1+1][b - 1+1] := c ; dicco[b - 1+1][a - 1+1] := c ; dicti[a - 1+1][b - 1+1] := t ; dicti[b - 1+1][a - 1+1] := t) ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, k-1) do ( var p : OclAny := null; var q : OclAny := null; var r : OclAny := null; Sequence{p,q,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if not(r) then ( Dijkstra(dicco, p - 1, q - 1) ) else ( Dijkstra(dicti, p - 1, q - 1) ))); operation Dijkstra(graph : OclAny, start : OclAny, goal : OclAny) pre: true post: true activity: var que : Sequence := Sequence{ Sequence{0, start} } ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (graph)->size()) ; while true do ( var path_len : OclAny := null; var v : OclAny := null; Sequence{path_len,v} := heappop(que) ; visited[v+1] := true ; if v = goal then ( execute (path_len)->display() ; break ) else skip ; for _tuple : graph[v+1]->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var w : OclAny := _tuple->at(_indx); _indx := _indx + 1; var edge_len : OclAny := _tuple->at(_indx); if not(visited[w+1]) then ( heappush(que, Sequence{path_len + edge_len, w}) ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heappop as hpop from heapq import heappush as hpush def main(): while True : n,m=map(int,input().split()) if not n : break cost_edges=[[]for _ in range(m)] time_edges=[[]for _ in range(m)] for _ in range(n): a,b,c,t=map(int,input().split()) cost_edges[a-1].append((c,b-1)) cost_edges[b-1].append((c,a-1)) time_edges[a-1].append((t,b-1)) time_edges[b-1].append((t,a-1)) k=int(input()) for _ in range(k): start,goal,r=map(int,input().split()) start-=1 goal-=1 if r : edges=time_edges else : edges=cost_edges que=[(0,start)] visited=[False for _ in range(m)] while que : score,station=hpop(que) visited[station]=True if station==goal : print(score) break for c,to_station in edges[station]: if not visited[to_station]: hpush(que,(score+c,to_station)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; main(); operation main() pre: true post: true activity: while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if not(n) then ( break ) else skip ; var cost_edges : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var time_edges : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var t : OclAny := null; Sequence{a,b,c,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name cost_edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name c)))))) , (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1))))))))) )))))))) )))) ; (expr (atom (name cost_edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name c)))))) , (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1))))))))) )))))))) )))) ; (expr (atom (name time_edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name t)))))) , (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1))))))))) )))))))) )))) ; (expr (atom (name time_edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name t)))))) , (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1))))))))) )))))))) ))))) ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, k-1) do ( var start : OclAny := null; var goal : OclAny := null; var r : OclAny := null; Sequence{start,goal,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; start := start - 1 ; goal := goal - 1 ; if r then ( var edges : Sequence := time_edges ) else ( edges := cost_edges ) ; var que : Sequence := Sequence{ Sequence{0, start} } ; var visited : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (false)) ; while que do ( var score : OclAny := null; var station : OclAny := null; Sequence{score,station} := hpop(que) ; visited[station+1] := true ; if station = goal then ( execute (score)->display() ; break ) else skip ; for _tuple : edges[station+1] do (var _indx : int := 1; var c : OclAny := _tuple->at(_indx); _indx := _indx + 1; var to_station : OclAny := _tuple->at(_indx); if not(visited[to_station+1]) then ( hpush(que, Sequence{score + c, to_station}) ) else skip)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printSequence(v,n,s,k): if(s==0): for i in range(0,len(v)): print("{}".format(v[i]),end="") print("") return ; for i in range(0,k): v.append(n+i) printSequence(v,n+i,s-1,k) v.pop() for i in range(1,k): v.append(n-i) printSequence(v,n-i,s-1,k) v.pop() def wrapper(n,s,k): v=[] v.append(n) printSequence(v,n,s-1,k) n=5 ; s=3 ; k=2 ; wrapper(n,s,k); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 5; s := 3; k := 2; ; wrapper(n, s, k);; operation printSequence(v : OclAny, n : OclAny, s : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (s = 0) then ( for i : Integer.subrange(0, (v)->size()-1) do ( execute (StringLib.interpolateStrings("{}", Sequence{v[i+1]}))->display()) ; execute ("")->display() ; return; ) else skip ; for i : Integer.subrange(0, k-1) do ( execute ((n + i) : v) ; printSequence(v, n + i, s - 1, k) ; v := v->front()) ; for i : Integer.subrange(1, k-1) do ( execute ((n - i) : v) ; printSequence(v, n - i, s - 1, k) ; v := v->front()); operation wrapper(n : OclAny, s : OclAny, k : OclAny) pre: true post: true activity: v := Sequence{} ; execute ((n) : v) ; printSequence(v, n, s - 1, k); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cassini(n): return-1 if(n & 1)else 1 n=5 print(cassini(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; execute (cassini(n))->display(); operation cassini(n : OclAny) : OclAny pre: true post: true activity: return if (MathLib.bitwiseAnd(n, 1)) then -1 else 1 endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binarySearchCount(arr,n,key): left=0 right=n-1 count=0 while(left<=right): mid=int((right+left)/2) if(arr[mid]<=key): count=mid+1 left=mid+1 else : right=mid-1 return count arr=[1,2,4,11,11,16] key=11 n=len(arr) print(binarySearchCount(arr,n,key)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{11}->union(Sequence{11}->union(Sequence{ 16 }))))) ; key := 11 ; n := (arr)->size() ; execute (binarySearchCount(arr, n, key))->display(); operation binarySearchCount(arr : OclAny, n : OclAny, key : OclAny) : OclAny pre: true post: true activity: var left : int := 0 ; var right : double := n - 1 ; var count : int := 0 ; while ((left->compareTo(right)) <= 0) do ( var mid : int := ("" + (((right + left) / 2)))->toInteger() ; if ((arr[mid+1]->compareTo(key)) <= 0) then ( count := mid + 1 ; left := mid + 1 ) else ( right := mid - 1 )) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) e=10**9+7 print(1 if n==0 else(pow(2,n-1,e)+pow(2,n*2-1,e))% e) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var e : double := (10)->pow(9) + 7 ; execute (if n = 0 then 1 else ((2)->pow(n - 1) + (2)->pow(n * 2 - 1)) mod e endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print((lambda x,y : 'Yes' if y in x else 'No')(input()*2,input())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((lambda x : OclAny, y : OclAny in (if (x)->includes(y) then 'Yes' else 'No' endif))((OclFile["System.in"]).readLine() * 2, (OclFile["System.in"]).readLine()))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n : k=pow(2,n-1,1000000007) print((k*(2*k+1))% 1000000007) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n then ( var k : double := (2)->pow(n - 1) ; execute ((k * (2 * k + 1)) mod 1000000007)->display() ) else ( execute (1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) res=pow(2,n,1000000007) print((res+1)*res//2 % 1000000007) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : double := (2)->pow(n) ; execute ((res + 1) * res div 2 mod 1000000007)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=1000000007 n=int(input()) print(1 if not n else((pow(2,n-1,MOD)*(1+pow(2,n,MOD)))% MOD)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : int := 1000000007 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (if not(n) then 1 else (((2)->pow(n - 1) * (1 + (2)->pow(n))) mod MOD) endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np n,t=map(int,input().split()) a=list(map(int,input().split())) result=0 for i,v in enumerate(a[1 :],1): result+=min(a[i-1]+t,v)-a[i-1] print(result+t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var result : int := 0 ; for _tuple : Integer.subrange(1, (a->tail(), 1)->size())->collect( _indx | Sequence{_indx-1, (a->tail(), 1)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); result := result + Set{a[i - 1+1] + t, v}->min() - a[i - 1+1]) ; execute (result + t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=1000000007 ; n=int(input()); if(n==0): print(1); else : print(((2*pow(4,n-1,MOD))+pow(2,n-1,MOD))% MOD); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : int := 1000000007; ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); ; if (n = 0) then ( execute (1)->display(); ) else ( execute (((2 * (4)->pow(n - 1)) + (2)->pow(n - 1)) mod MOD)->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p,k=map(int,input().split()) ans=[] while p!=0 : ans.append(p % k) p-=ans[-1] p//=(-k) print(len(ans)) print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : OclAny := null; var k : OclAny := null; Sequence{p,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := Sequence{} ; while p /= 0 do ( execute ((p mod k) : ans) ; p := p - ans->last() ; p := p div (-k)) ; execute ((ans)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p,k=input().split() p,k=int(p),int(k) s=k-1 ls=[0] while s

toInteger(),("" + ((k)))->toInteger()} ; var s : double := k - 1 ; var ls : Sequence := Sequence{ 0 } ; while (s->compareTo(p)) < 0 do ( execute ((0) : ls) ; execute ((0) : ls) ; s := s * k * k + k - 1) ; var n : int := (ls)->size() ; for i : Integer.subrange(0, n-1) do ( if (MathLib.bitwiseAnd(i, 1)) = 0 then ( ls[i+1] := k - 1 ) else skip) ; var res : double := s - p ; for i : Integer.subrange(0, n-1) do ( var t : int := res mod k ; if MathLib.bitwiseAnd(i, 1) then ( ls[i+1] := ls[i+1] + t ) else ( ls[i+1] := ls[i+1] - t ) ; res := res div k) ; execute (n)->display() ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name ls)))))))), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p,k=map(int,input().split()) ans=[] while p : ans.append(p % k) p//=k p*=-1 print(len(ans)) print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : OclAny := null; var k : OclAny := null; Sequence{p,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := Sequence{} ; while p do ( execute ((p mod k) : ans) ; p := p div k ; p := p * -1) ; execute ((ans)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def converttobase(n,b): if(-1<=b<=1): return "INVALID INPUT" elif(b>1): L=[] while(n!=0): L.append(n % b) n=n//b return L[: :-1] else : L=[] while(n!=0): if(n % b<0): x=-b+n % b L.append(x) n=1+n//b else : L.append(n % b) n=n//b return L L=list(map(int,input().split())) M=converttobase(L[0],-1*L[1]) print(len(M)) print(*M) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; L := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var M : OclAny := converttobase(L->first(), -1 * L[1+1]) ; execute ((M)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name M))))))))->display(); operation converttobase(n : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (-1 <= b & (b <= 1)) then ( return "INVALID INPUT" ) else (if (b > 1) then ( var L : Sequence := Sequence{} ; while (n /= 0) do ( execute ((n mod b) : L) ; n := n div b) ; return L(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ) else ( L := Sequence{} ; while (n /= 0) do ( if (n mod b < 0) then ( var x : OclAny := -b + n mod b ; execute ((x) : L) ; n := 1 + n div b ) else ( execute ((n mod b) : L) ; n := n div b )) ; return L ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p,k=map(int,input().split()) ans=[] cnt=0 while(p): if(cnt % 2==0): ans.append(p % k) p-=p % k else : if(p % k!=0): ans.append((k-p % k)) p+=k-p % k else : ans.append(0) p//=k cnt+=1 print(len(ans)) for k in range(len(ans)): print(ans[k],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : OclAny := null; var k : OclAny := null; Sequence{p,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := Sequence{} ; var cnt : int := 0 ; while (p) do ( if (cnt mod 2 = 0) then ( execute ((p mod k) : ans) ; p := p - p mod k ) else ( if (p mod k /= 0) then ( execute (((k - p mod k)) : ans) ; p := p + k - p mod k ) else ( execute ((0) : ans) ) ) ; p := p div k ; cnt := cnt + 1) ; execute ((ans)->size())->display() ; for k : Integer.subrange(0, (ans)->size()-1) do ( execute (ans[k+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) points=[list(map(int,input().split()))for _ in range(n)] points=[[p[0]-points[0][0],p[1]-points[0][1]]for p in points[1 :]] print(sum([(points[i][0]*points[i+1][1]-points[i+1][0]*points[i][1])/2 for i in range(len(points)-1)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var points : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; points := points->tail()->select(p | true)->collect(p | (Sequence{p->first() - points->first()->first()}->union(Sequence{ p[1+1] - points->first()[1+1] }))) ; execute ((Integer.subrange(0, (points)->size() - 1-1)->select(i | true)->collect(i | ((points[i+1]->first() * points[i + 1+1][1+1] - points[i + 1+1]->first() * points[i+1][1+1]) / 2)))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() p=input() sl=[i for i in s] pl=[i for i in p] lenp=len(p) pp=pl[-1] el=[i for i,x in enumerate(sl)if x==pp] check=0 for i in el : pcheck=-1 while True : if sl[i]==pl[pcheck]: i-=1 pcheck-=1 else : break if pcheck+lenp<=0 : check+=1 break if check==1 : break if check==0 : print("No") else : print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var p : String := (OclFile["System.in"]).readLine() ; var sl : Sequence := s->characters()->select(i | true)->collect(i | (i)) ; var pl : Sequence := p->characters()->select(i | true)->collect(i | (i)) ; var lenp : int := (p)->size() ; var pp : OclAny := pl->last() ; var el : Sequence := Integer.subrange(1, (sl)->size())->collect( _indx | Sequence{_indx-1, (sl)->at(_indx)} )->select(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in x = pp)->collect(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in (i)) ; var check : int := 0 ; for i : el do ( var pcheck : int := -1 ; while true do ( if sl[i+1] = pl[pcheck+1] then ( i := i - 1 ; pcheck := pcheck - 1 ) else ( break ) ; if pcheck + lenp <= 0 then ( check := check + 1 ; break ) else skip) ; if check = 1 then ( break ) else skip) ; if check = 0 then ( execute ("No")->display() ) else ( execute ("Yes")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from typing import List,Tuple if __name__=="__main__" : n=int(input()) coordinates : List[Tuple[int,int]]=[] for _ in range(n): x,y=map(lambda x : int(x),input().split()) coordinates.append((x,y)) ans=0.0 for i in range(n): x1,y1=coordinates[i][0],coordinates[i][1] x2,y2=coordinates[(i+1)% n][0],coordinates[(i+1)% n][1] ans+=(x1*y2-x2*y1) print(f"{ans/2.0:.1f}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var coordinates : OclAny := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ) ; execute ((Sequence{x, y}) : coordinates)) ; var ans : double := 0.0 ; for i : Integer.subrange(0, n-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := Sequence{coordinates[i+1]->first(),coordinates[i+1][1+1]} ; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x2,y2} := Sequence{coordinates[(i + 1) mod n+1]->first(),coordinates[(i + 1) mod n+1][1+1]} ; ans := ans + (x1 * y2 - x2 * y1)) ; execute (StringLib.formattedString("{ans/2.0:.1f}"))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- EPS=1e-4 def OuterProduct(one,two): tmp=one.conjugate()*two return tmp.imag def Area(dots): res=0 for i in range(len(dots)-1): res+=OuterProduct(dots[i],dots[i+1]) res+=OuterProduct(dots[-1],dots[0]) return res/2 n=int(input()) dots=[] for _ in range(n): x,y=map(int,input().split()) dots.append(complex(x,y)) print(Area(dots)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var EPS : double := ("1e-4")->toReal() ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; dots := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((complex(x, y)) : dots)) ; execute (Area(dots))->display(); operation OuterProduct(one : OclAny, two : OclAny) : OclAny pre: true post: true activity: var tmp : double := one.conjugate() * two ; return tmp.imag; operation Area(dots : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; for i : Integer.subrange(0, (dots)->size() - 1-1) do ( res := res + OuterProduct(dots[i+1], dots[i + 1+1])) ; res := res + OuterProduct(dots->last(), dots->first()) ; return res / 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,T=map(int,input().split()) arrT=list(map(int,input().split())) start=arrT[0] end=0 ans=0 for i in range(N): if i==N-1 : if arrT[i-1]+T>=arrT[i]: end=arrT[i] num=end-start+T ans+=num else : ans+=T elif arrT[i]+T>=arrT[i+1]: end=arrT[i] continue else : end=arrT[i] num=end-start+T ans+=num start=arrT[i+1] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var T : OclAny := null; Sequence{N,T} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arrT : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var start : OclAny := arrT->first() ; var end : int := 0 ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( if i = N - 1 then ( if (arrT[i - 1+1] + T->compareTo(arrT[i+1])) >= 0 then ( end := arrT[i+1] ; var num : double := end - start + T ; ans := ans + num ) else ( ans := ans + T ) ) else (if (arrT[i+1] + T->compareTo(arrT[i + 1+1])) >= 0 then ( end := arrT[i+1] ; continue ) else ( end := arrT[i+1] ; num := end - start + T ; ans := ans + num ; start := arrT[i + 1+1] ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() p1=complex(*list(map(float,input().split()))) p2=complex(*list(map(float,input().split()))) ans=0 def area(p,q,r): return((p-r).conjugate()*(q-r)).imag/2 try : while True : p3=complex(*list(map(float,input().split()))) ans+=area(p1,p2,p3) p2=p3 except EOFError : print(abs(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var p1 : OclAny := complex((argument * (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name float))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))))))) ; var p2 : OclAny := complex((argument * (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name float))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))))))) ; var ans : int := 0 ; skip ; try ( while true do ( var p3 : OclAny := complex((argument * (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name float))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))))))) ; ans := ans + area(p1, p2, p3) ; p2 := p3)) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) )))))))))) ))); operation area(p : OclAny, q : OclAny, r : OclAny) : OclAny pre: true post: true activity: return ((p - r).conjugate() * (q - r)).imag / 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import cmath def norm(c): a=abs(c) return a*a def dot_product(a,b): return(a.conjugate()*b).real def cross_product(a,b): return(a.conjugate()*b).imag def projection(p,b): return b*dot_product(p,b)/norm(b) P=[] N=int(input().strip()) for _ in range(N): x,y=map(float,input().strip().split()) P.append(complex(x,y)) total=0.0 for i in range(1,N-1): a,b,c=P[0],P[i],P[i+1] total+=cross_product(b-a,c-a) print("%.1f" %(abs(total)/2.0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var P : Sequence := Sequence{} ; var N : int := ("" + ((input()->trim())))->toInteger() ; for _anon : Integer.subrange(0, N-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input()->trim().split())->collect( _x | (OclType["double"])->apply(_x) ) ; execute ((complex(x, y)) : P)) ; var total : double := 0.0 ; for i : Integer.subrange(1, N - 1-1) do ( Sequence{a,b,c} := Sequence{P->first(),P[i+1],P[i + 1+1]} ; total := total + cross_product(b - a, c - a)) ; execute (StringLib.format("%.1f",((total)->abs() / 2.0)))->display(); operation norm(c : OclAny) : OclAny pre: true post: true activity: var a : double := (c)->abs() ; return a * a; operation dot_product(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a.conjugate() * b).real; operation cross_product(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a.conjugate() * b).imag; operation projection(p : OclAny, b : OclAny) : OclAny pre: true post: true activity: return b * dot_product(p, b) / norm(b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for _ in range(n): st,di=map(int,input().split()) em=0 if(st>=di and st<2*di)or(di>=st and di<2*st): em=(st//3)+(di//3) if((st % 3)+(di % 3))>2 : em+=1 elif st>=2*di or di>=2*st : if st>di : em=di elif di>st : em=st print(em) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var st : OclAny := null; var di : OclAny := null; Sequence{st,di} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var em : int := 0 ; if ((st->compareTo(di)) >= 0 & (st->compareTo(2 * di)) < 0) or ((di->compareTo(st)) >= 0 & (di->compareTo(2 * st)) < 0) then ( em := (st div 3) + (di div 3) ; if ((st mod 3) + (di mod 3)) > 2 then ( em := em + 1 ) else skip ) else (if (st->compareTo(2 * di)) >= 0 or (di->compareTo(2 * st)) >= 0 then ( if (st->compareTo(di)) > 0 then ( em := di ) else (if (di->compareTo(st)) > 0 then ( em := st ) else skip) ) else skip) ; execute (em)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) i=1 while True : if i>t : break a,b=input().split() a=int(a) b=int(b) k=(a+b)//3 if k>a : print(a) elif k>b : print(b) else : print(k) i=i+1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 1 ; while true do ( if (i->compareTo(t)) > 0 then ( break ) else skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; var k : int := (a + b) div 3 ; if (k->compareTo(a)) > 0 then ( execute (a)->display() ) else (if (k->compareTo(b)) > 0 then ( execute (b)->display() ) else ( execute (k)->display() ) ) ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def earn(s,d): if(s and d)==0 : return 0 item1=min(s,d) item2=max(s,d) if item2>=2*item1 : return item1 return int((item1+item2)/3) for _ in range(int(input())): s,d=tuple(map(int,input().split())) print(earn(s,d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( Sequence{s,d} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (earn(s, d))->display()); operation earn(s : OclAny, d : OclAny) : OclAny pre: true post: true activity: if (s & d) = 0 then ( return 0 ) else skip ; var item1 : OclAny := Set{s, d}->min() ; var item2 : OclAny := Set{s, d}->max() ; if (item2->compareTo(2 * item1)) >= 0 then ( return item1 ) else skip ; return ("" + (((item1 + item2) / 3)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a,b=map(int,input().split()) ans=0 if(atoInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; if ((a->compareTo(b)) < 0) then ( var a : OclAny := a + b ; var b : double := a - b ; a := a - b ) else skip ; if ((b * 2->compareTo(a)) <= 0) then ( execute (b)->display() ) else ( execute ((a + b) div 3)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): l,r=map(int,input().split()) print(min(l,r,(l+r)//3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{l, r, (l + r) div 3}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isVowel(c): return(c=='A' or c=='E' or c=='I' or c=='O' or c=='U' or c=='a' or c=='e' or c=='i' or c=='o' or c=='u'); def pigLatin(s): length=len(s); index=-1 ; for i in range(length): if(isVowel(s[i])): index=i ; break ; if(index==-1): return "-1" ; return s[index :]+s[0 : index]+"ay" ; str=pigLatin("graphic"); if(str=="-1"): print("No vowels found.Pig Latin not possible"); else : print(str); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var OclType["String"] : OclAny := pigLatin("graphic"); ; if (OclType["String"] = "-1") then ( execute ("No vowels found.Pig Latin not possible")->display(); ) else ( execute (OclType["String"])->display(); ); operation isVowel(c : OclAny) pre: true post: true activity: return (c = 'A' or c = 'E' or c = 'I' or c = 'O' or c = 'U' or c = 'a' or c = 'e' or c = 'i' or c = 'o' or c = 'u');; operation pigLatin(s : OclAny) pre: true post: true activity: var length : int := (s)->size(); ; var index : int := -1; ; for i : Integer.subrange(0, length-1) do ( if (isVowel(s[i+1])) then ( index := i; ; break; ) else skip) ; if (index = -1) then ( return "-1"; ) else skip ; return s.subrange(index+1) + s.subrange(0+1, index) + "ay";; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin s=stdin.readline().rstrip() p=stdin.readline().rstrip() ss=s*2 if p in ss : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : OclAny := stdin.readLine().rstrip() ; var p : OclAny := stdin.readLine().rstrip() ; var ss : double := s * 2 ; if (ss)->includes(p) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNumbers(arr,n): num=[0 for i in range(n)] b_minus_a=arr[n-1]-arr[1] num[1]=(arr[0]+b_minus_a)//2 num[0]=arr[0]-num[1] for i in range(1,(n-2)+1): num[i+1]=arr[i]-num[0] print("Numbers are: ",end="") for i in range(n): print(num[i],end=",") arr=[13,10,14,9,17,21,16,18,13,17] n=5 findNumbers(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{13}->union(Sequence{10}->union(Sequence{14}->union(Sequence{9}->union(Sequence{17}->union(Sequence{21}->union(Sequence{16}->union(Sequence{18}->union(Sequence{13}->union(Sequence{ 17 }))))))))) ; n := 5 ; findNumbers(arr, n); operation findNumbers(arr : OclAny, n : OclAny) pre: true post: true activity: var num : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var b_minus_a : double := arr[n - 1+1] - arr[1+1] ; num[1+1] := (arr->first() + b_minus_a) div 2 ; num->first() := arr->first() - num[1+1] ; for i : Integer.subrange(1, (n - 2) + 1-1) do ( num[i + 1+1] := arr[i+1] - num->first()) ; execute ("Numbers are: ")->display() ; for i : Integer.subrange(0, n-1) do ( execute (num[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import gcd import math def LCM(x,y,z): ans=int((x*y)/(gcd(x,y))) return int((z*ans)/(gcd(ans,z))) def findDivisible(n,x,y,z): lcm=LCM(x,y,z) ndigitnumber=math.pow(10,n-1) reminder=ndigitnumber % lcm if reminder==0 : return ndigitnumber ndigitnumber+=lcm-reminder if ndigitnumberdisplay() ) else ( execute ("Not possible")->display() ); operation LCM(x : OclAny, y : OclAny, z : OclAny) : OclAny pre: true post: true activity: var ans : int := ("" + (((x * y) / (gcd(x, y)))))->toInteger() ; return ("" + (((z * ans) / (gcd(ans, z)))))->toInteger(); operation findDivisible(n : OclAny, x : OclAny, y : OclAny, z : OclAny) : OclAny pre: true post: true activity: var lcm : OclAny := LCM(x, y, z) ; var ndigitnumber : double := (10)->pow(n - 1) ; var reminder : int := ndigitnumber mod lcm ; if reminder = 0 then ( return ndigitnumber ) else skip ; ndigitnumber := ndigitnumber + lcm - reminder ; if (ndigitnumber->compareTo((10)->pow(n))) < 0 then ( return ("" + ((ndigitnumber)))->toInteger() ) else ( return 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def parser(l,r): if all(S[i].isdigit()for i in range(l,r+1)): return int(S[l : r+1])//2+1 ret=[] cnt=0 start=0 for i in range(l,r+1): if S[i]=='[' : cnt+=1 if cnt==1 : start=i elif S[i]==']' : if cnt==1 : ret.append(parser(start+1,i-1)) cnt-=1 ret.sort() return sum(ret[: len(ret)//2+1]) N=int(input()) for _ in range(N): S=input() print(parser(0,len(S)-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, N-1) do ( var S : String := (OclFile["System.in"]).readLine() ; execute (parser(0, (S)->size() - 1))->display()); operation parser(l : OclAny, r : OclAny) : OclAny pre: true post: true activity: if ((argument (test (logical_test (comparison (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name isdigit) (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name r))) + (expr (atom (number (integer 1)))))))))) )))))))))->forAll( _x | _x = true ) then ( return ("" + ((S.subrange(l+1, r + 1))))->toInteger() div 2 + 1 ) else skip ; var ret : Sequence := Sequence{} ; var cnt : int := 0 ; var start : int := 0 ; for i : Integer.subrange(l, r + 1-1) do ( if S[i+1] = '[' then ( cnt := cnt + 1 ; if cnt = 1 then ( start := i ) else skip ) else (if S[i+1] = ']' then ( if cnt = 1 then ( execute ((parser(start + 1, i - 1)) : ret) ) else skip ; cnt := cnt - 1 ) else skip)) ; ret := ret->sort() ; return (ret.subrange(1,(ret)->size() div 2 + 1))->sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def f(x): res=[] flag=False tank=[] for i in range(len(x)): if x[i]==0 and x[i+1]>0 : flag=True elif x[i]==0 : res.append(0) elif x[i]>0 : tank.append(x[i]) elif x[i]==-1 and flag : tank.sort() res.append(sum(tank[: len(tank)//2+1])) flag=False tank=[] else : res.append(-1) return res testnum=int(input()) for testcase in range(testnum): ss=list(input()) s=[] tmp,p=0,0 for i in range(len(ss)-2,-1,-1): if ss[i]=="]" : s.append(-1) elif ss[i]=="[" : s.append(0) else : tmp+=int(ss[i])*pow(10,p) p+=1 if ss[i-1]=="[" : s.append(tmp//2+1) tmp,p=0,0 s=s[: :-1] while len(s)>1 : s=f(s) print(s[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var testnum : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for testcase : Integer.subrange(0, testnum-1) do ( var ss : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var s : Sequence := Sequence{} ; var tmp : OclAny := null; var p : OclAny := null; Sequence{tmp,p} := Sequence{0,0} ; for i : Integer.subrange(-1 + 1, (ss)->size() - 2)->reverse() do ( if ss[i+1] = "]" then ( execute ((-1) : s) ) else (if ss[i+1] = "[" then ( execute ((0) : s) ) else ( tmp := tmp + ("" + ((ss[i+1])))->toInteger() * (10)->pow(p) ; p := p + 1 ; if ss[i - 1+1] = "[" then ( execute ((tmp div 2 + 1) : s) ; var tmp : OclAny := null; var p : OclAny := null; Sequence{tmp,p} := Sequence{0,0} ) else skip ) ) ) ; s := s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; while (s)->size() > 1 do ( s := f(s)) ; execute (s->first())->display()); operation f(x : OclAny) : OclAny pre: true post: true activity: var res : Sequence := Sequence{} ; var flag : boolean := false ; var tank : Sequence := Sequence{} ; for i : Integer.subrange(0, (x)->size()-1) do ( if x[i+1] = 0 & x[i + 1+1] > 0 then ( flag := true ) else (if x[i+1] = 0 then ( execute ((0) : res) ) else (if x[i+1] > 0 then ( execute ((x[i+1]) : tank) ) else (if x[i+1] = -1 & flag then ( tank := tank->sort() ; execute (((tank.subrange(1,(tank)->size() div 2 + 1))->sum()) : res) ; flag := false ; tank := Sequence{} ) else ( execute ((-1) : res) ) ) ) ) ) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 dd=[(0,-1),(1,0),(0,1),(-1,0)] ddn=[(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)] def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] n=I() ni=0 def f(a): if len(a)==1 : return a[0]//2+1 cs=sorted([f(c)for c in a]) return sum(cs[: len(cs)//2+1]) while nipow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; var dd : Sequence := Sequence{Sequence{0, -1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{ Sequence{-1, 0} }))) ; var ddn : Sequence := Sequence{Sequence{0, -1}}->union(Sequence{Sequence{1, -1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{1, 1}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{-1, -1}}->union(Sequence{Sequence{-1, 0}}->union(Sequence{ Sequence{-1, 1} }))))))) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; var n : OclAny := I() ; var ni : int := 0 ; skip ; while (ni->compareTo(n)) < 0 do ( ni := ni + 1 ; s := S() ; a := s.replace('][', '],[') ; execute ((f(a)) : rr)) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re n=int(input()) for _ in range(n): dataset=input() stage=1 while(re.match('\[[0-9]+\]',dataset)is None): iterator=re.finditer('\[([0-9]+\]\[)+[0-9]+\]',dataset) minimum_votes=[] for i,match in enumerate(iterator): areas=list(map(int,match.group()[1 :-1].split(']['))) minimum_areas=sorted(areas)[: len(areas)//2+1] if stage==1 : minimum_voters=[m//2+1 for m in minimum_areas] minimum_vote=sum(minimum_voters) else : minimum_vote=sum(minimum_areas) minimum_votes.append(str(minimum_vote)) dataset=dataset.replace(match.group(),str(-i-1),1) for i,minimum_vote in enumerate(minimum_votes): dataset=dataset.replace(str(-i-1),minimum_vote,1) stage+=1 print(dataset[1 :-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var dataset : String := (OclFile["System.in"]).readLine() ; var stage : int := 1 ; while ((dataset)->firstMatch("^" + '\[[0-9]+\]' + ".*") <>= null) do ( var iterator : OclIterator := OclIterator.newOclIterator_Sequence((dataset)->allMatches('\[([0-9]+\]\[)+[0-9]+\]')) ; var minimum_votes : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (iterator)->size())->collect( _indx | Sequence{_indx-1, (iterator)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var match : OclAny := _tuple->at(_indx); var areas : Sequence := ((match.group().subrange(1+1, -1).split(']['))->collect( _x | (OclType["int"])->apply(_x) )) ; var minimum_areas : OclAny := sorted(areas).subrange(1,(areas)->size() div 2 + 1) ; if stage = 1 then ( var minimum_voters : Sequence := minimum_areas->select(m | true)->collect(m | (m div 2 + 1)) ; var minimum_vote : OclAny := (minimum_voters)->sum() ) else ( minimum_vote := (minimum_areas)->sum() ) ; execute ((("" + ((minimum_vote)))) : minimum_votes) ; dataset := dataset.replace(match.group(), ("" + ((-i - 1))), 1)) ; for _tuple : Integer.subrange(1, (minimum_votes)->size())->collect( _indx | Sequence{_indx-1, (minimum_votes)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var minimum_vote : OclAny := _tuple->at(_indx); dataset := dataset.replace(("" + ((-i - 1))), minimum_vote, 1)) ; stage := stage + 1) ; execute (dataset.subrange(1+1, -1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline class Node(): def __init__(self): self.is_leaf=False self.val=-1 self.childs=[] self.child_num=0 self.parent=None def win(self): if self.is_leaf : return self.val//2+1 tmp=[] for c in self.childs : tmp.append(c.win()) tmp=sorted(tmp) ret=0 for i in range(self.child_num//2+1): ret+=tmp[i] return ret def main(): n=int(input()) questions=[input().strip()for i in range(n)] for q in questions : root=Node() now=root i=0 while iexists( _x | result = _x ); attribute is_leaf : boolean := false; attribute val : int := -1; attribute childs : Sequence := Sequence{}; attribute child_num : int := 0; attribute parent : OclAny := null; operation initialise() : pre: true post: true activity: self.is_leaf := false ; self.val := -1 ; self.childs := Sequence{} ; self.child_num := 0 ; self.parent := null; return self; operation win() : OclAny pre: true post: true activity: if self.is_leaf then ( return self.val div 2 + 1 ) else skip ; var tmp : Sequence := Sequence{} ; for c : self.childs do ( execute ((c.win()) : tmp)) ; tmp := tmp->sort() ; var ret : int := 0 ; for i : Integer.subrange(0, self.child_num div 2 + 1-1) do ( ret := ret + tmp[i+1]) ; return ret; } class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var questions : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (input()->trim())) ; for q : questions do ( var root : Node := (Node.newNode()).initialise() ; var now : OclAny := root ; var i : int := 0 ; while (i->compareTo((q)->size())) < 0 do ( if q[i+1] = "[" then ( tmp := (Node.newNode()).initialise() ; tmp.parent := now ; (expr (atom (name now)) (trailer . (name childs)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name tmp)))))))) )))) ; now.child_num := now.child_num + 1 ; now := tmp ; i := i + 1 ) else (if q[i+1] = "]" then ( now := now.parent ; i := i + 1 ) else ( var j : int := i ; while ("0123456789")->characters()->includes(q[j + 1+1]) do ( j := j + 1) ; now.is_leaf := true ; now.val := ("" + ((q.subrange(i+1, j + 1))))->toInteger() ; i := j + 1 ) ) ) ; execute (root.win())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=6 ; n=4 ; def compareRow(a1,a2): for i in range(n): if(a1[i]a2[i]): return-1 ; return 0 ; def binaryCheck(ar,arr): l=0 ; r=m-1 ; while(l<=r): mid=(l+r)//2 ; temp=compareRow(ar[mid],arr); if(temp==0): return mid+1 ; elif(temp==1): l=mid+1 ; else : r=mid-1 ; return-1 ; if __name__=="__main__" : mat=[[0,0,1,0],[10,9,22,23],[40,40,40,40],[43,44,55,68],[81,73,100,132],[100,75,125,133]]; row=[10,9,22,23]; print(binaryCheck(mat,row)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : int := 6; ; var n : int := 4; ; skip ; skip ; if __name__ = "__main__" then ( var mat : Sequence := Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 0 })))}->union(Sequence{Sequence{10}->union(Sequence{9}->union(Sequence{22}->union(Sequence{ 23 })))}->union(Sequence{Sequence{40}->union(Sequence{40}->union(Sequence{40}->union(Sequence{ 40 })))}->union(Sequence{Sequence{43}->union(Sequence{44}->union(Sequence{55}->union(Sequence{ 68 })))}->union(Sequence{Sequence{81}->union(Sequence{73}->union(Sequence{100}->union(Sequence{ 132 })))}->union(Sequence{ Sequence{100}->union(Sequence{75}->union(Sequence{125}->union(Sequence{ 133 }))) }))))); ; var row : Sequence := Sequence{10}->union(Sequence{9}->union(Sequence{22}->union(Sequence{ 23 }))); ; execute (binaryCheck(mat, row))->display(); ) else skip; operation compareRow(a1 : OclAny, a2 : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if ((a1[i+1]->compareTo(a2[i+1])) < 0) then ( return 1; ) else (if ((a1[i+1]->compareTo(a2[i+1])) > 0) then ( return -1; ) else skip)) ; return 0;; operation binaryCheck(ar : OclAny, arr : OclAny) pre: true post: true activity: var l : int := 0; var r : double := m - 1; ; while ((l->compareTo(r)) <= 0) do ( var mid : int := (l + r) div 2; ; var temp : OclAny := compareRow(ar[mid+1], arr); ; if (temp = 0) then ( return mid + 1; ) else (if (temp = 1) then ( l := mid + 1; ) else ( r := mid - 1; ) ) ) ; return -1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def area(x1,y1,z1,x2,y2,z2): area=math.sqrt((y1*z2-y2*z1)**2+(x1*z2-x2*z1)**2+(x1*y2-x2*y1)**2) area=area/2 return area def main(): x1=-2 y1=0 z1=-5 x2=1 y2=-2 z2=-1 a=area(x1,y1,z1,x2,y2,z2) print("Area=",a) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation area(x1 : OclAny, y1 : OclAny, z1 : OclAny, x2 : OclAny, y2 : OclAny, z2 : OclAny) : OclAny pre: true post: true activity: var area : double := (((y1 * z2 - y2 * z1))->pow(2) + ((x1 * z2 - x2 * z1))->pow(2) + ((x1 * y2 - x2 * y1))->pow(2))->sqrt() ; area := area / 2 ; return area; operation main() pre: true post: true activity: x1 := -2 ; y1 := 0 ; z1 := -5 ; x2 := 1 ; y2 := -2 ; z2 := -1 ; var a : OclAny := area(x1, y1, z1, x2, y2, z2) ; execute ("Area=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt if __name__=='__main__' : n=7 i,j=0,0 while(i=n-1): print("*",end="") else : print(end="") j+=1 for k in range(3): for l in range(n-1+i): if(l<=2 or(l<=n-1+i and l>=n-4+i)): print("*",end="") else : print(end="") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var n : int := 7 ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,0} ; while ((i->compareTo(n)) < 0) do ( if (j = n + i) then ( var j : int := -1 ; i := i + 1 ; execute (->display() ) else (if (((i + j)->compareTo(n - 1)) >= 0) then ( execute ("*")->display() ) else ( execute ((argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom "")))))))->display() ) ) ; j := j + 1) ; for k : Integer.subrange(0, 3-1) do ( for l : Integer.subrange(0, n - 1 + i-1) do ( if (l <= 2 or ((l->compareTo(n - 1 + i)) <= 0 & (l->compareTo(n - 4 + i)) >= 0)) then ( execute ("*")->display() ) else ( execute ((argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom "")))))))->display() )) ; execute (->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt MAX=100000 prime=[True for i in range(MAX+1)] def sieve(): k=int(sqrt(MAX)) for p in range(2,k,1): if(prime[p]==True): for i in range(p*2,MAX,p): prime[i]=False def divCount(n): total=1 for p in range(2,n+1,1): if(prime[p]): count=0 if(n % p==0): while(n % p==0): n=n/p count+=1 total=total*(count+1) return total def findNumber(n): if(n==1): return 3 i=2 count=0 second=1 first=1 while(count<=n): if(i % 2==0): first=divCount(i+1) count=first*second else : second=divCount(int((i+1)/2)) count=first*second i+=1 return i*(i-1)/2 if __name__=='__main__' : n=4 sieve() print(int(findNumber(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MAX : int := 100000 ; var prime : Sequence := Integer.subrange(0, MAX + 1-1)->select(i | true)->collect(i | (true)) ; skip ; skip ; skip ; if __name__ = '__main__' then ( n := 4 ; sieve() ; execute (("" + ((findNumber(n))))->toInteger())->display() ) else skip; operation sieve() pre: true post: true activity: var k : int := ("" + ((sqrt(MAX))))->toInteger() ; for p : Integer.subrange(2, k-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (prime[p+1] = true) then ( for i : Integer.subrange(p * 2, MAX-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip); operation divCount(n : OclAny) : OclAny pre: true post: true activity: var total : int := 1 ; for p : Integer.subrange(2, n + 1-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (prime[p+1]) then ( var count : int := 0 ; if (n mod p = 0) then ( while (n mod p = 0) do ( n := n / p ; count := count + 1) ; total := total * (count + 1) ) else skip ) else skip) ; return total; operation findNumber(n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return 3 ) else skip ; var i : int := 2 ; count := 0 ; var second : int := 1 ; var first : int := 1 ; while ((count->compareTo(n)) <= 0) do ( if (i mod 2 = 0) then ( first := divCount(i + 1) ; count := first * second ) else ( second := divCount(("" + (((i + 1) / 2)))->toInteger()) ; count := first * second ) ; i := i + 1) ; return i * (i - 1) / 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from multiprocessing import Pool from pprint import pprint import sys def calcprob(p): prob={} k=len(p) assert k % 2==0 for j in range(k//2+1): prob[(0,j)]=0 prob[(0,0)]=1 i=0 for pp in p : i+=1 for j in range(k//2+1): res=prob[(i-1,j)]*(1-pp) if j>0 : res=res+prob[(i-1,j-1)]*pp prob[(i,j)]=res return prob[(i,k//2)] def solve_test(data): n,k,p=data p=sorted(p) ans=-1 for i in range(k+1): left=i right=k-i pp=p[: i]+p[n-right :] assert len(pp)==k prob=calcprob(pp) if prob>ans : ans=prob sys.stderr.write('.') return ans tests=int(input()) data=[] for test in range(tests): sys.stderr.write(str(test)) n,k=map(int,input().split()) p=list(map(float,input().split())) data.append((n,k,p)) with Pool(6)as p : res=p.map(solve_test,data) for test in range(tests): print("Case #%d: %0.8f" %(test+1,res[test])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var tests : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; data := Sequence{} ; for test : Integer.subrange(0, tests-1) do ((expr (atom (name sys)) (trailer . (name stderr)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name test)))))))) ))))))))) )))) ; var n : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; p := ((input().split())->collect( _x | (OclType["double"])->apply(_x) )) ; execute ((Sequence{n, k, p}) : data)) ; try (var p : OclAny := Pool(6); res := p.map(solve_test, data)) catch (_e : OclException) do skip ; for test : Integer.subrange(0, tests-1) do ( execute (StringLib.format("Case #%d: %0.8f",Sequence{test + 1, res[test+1]}))->display()); operation calcprob(p : OclAny) : OclAny pre: true post: true activity: var prob : OclAny := Set{} ; var k : int := (p)->size() ; assert k mod 2 = 0 do "assertion failed" ; for j : Integer.subrange(0, k div 2 + 1-1) do ( prob[Sequence{0, j}+1] := 0) ; prob[Sequence{0, 0}+1] := 1 ; var i : int := 0 ; for pp : p do ( i := i + 1 ; for j : Integer.subrange(0, k div 2 + 1-1) do ( var res : double := prob[Sequence{i - 1, j}+1] * (1 - pp) ; if j > 0 then ( res := res + prob[Sequence{i - 1, j - 1}+1] * pp ) else skip ; prob[Sequence{i, j}+1] := res)) ; return prob[Sequence{i, k div 2}+1]; operation solve_test(data : OclAny) : OclAny pre: true post: true activity: var n : OclAny := null; Sequence{n,k,p} := data ; p := p->sort() ; var ans : int := -1 ; for i : Integer.subrange(0, k + 1-1) do ( var left : int := i ; var right : double := k - i ; var pp : OclAny := p.subrange(1,i) + p.subrange(n - right+1) ; assert (pp)->size() = k do "assertion failed" ; prob := calcprob(pp) ; if (prob->compareTo(ans)) > 0 then ( ans := prob ) else skip) ; (expr (atom (name sys)) (trailer . (name stderr)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '.'))))))) )))) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lista=list() r=1 a=list(map(int,input().split())) for e in a : lista+=[r]*e r+=1 m=int(input()) m_int=list(map(int,input().split())) for e in m_int : print(lista[e-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lista : Sequence := () ; var r : int := 1 ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for e : a do ( lista := lista + MatrixLib.elementwiseMult(Sequence{ r }, e) ; r := r + 1) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m_int : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for e : m_int do ( execute (lista[e - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import string import sys input=lambda : sys.stdin.buffer.readline().decode().strip() print=sys.stdout.write s=input() for i in range(len(s)-25): substring=s[i : i+26] if all(substring.count(char)==1 for char in substring if char!="?"): setsub=set(substring) if setsub==set(string.ascii_uppercase): ans=s.replace("?","A") break setsub.remove("?") for char in set(string.ascii_uppercase)-setsub : substring=substring.replace("?",char,1) s=s[0 : i]+substring+s[i+26 :] ans=s.replace("?","A") break else : ans="-1" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.buffer.readLine().decode()->trim()) ; var print : OclAny := (OclFile["System.out"]).write ; var s : String := (OclFile["System.in"]).readLine() ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))) - (expr (atom (number (integer 25)))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name substring)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))) : (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 26)))))))))) ])))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name all)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (comparison (expr (atom (name substring)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name char)))))))) ))))) == (comparison (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name char)))) in (logical_test (comparison (expr (atom (name substring))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name char)))) != (comparison (expr (atom "?")))))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name setsub)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name substring)))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name setsub)))) == (comparison (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name string)) (trailer . (name ascii_uppercase)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)) (trailer . (name replace) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "?")))))) , (argument (test (logical_test (comparison (expr (atom "A"))))))) ))))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name setsub)) (trailer . (name remove) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "?"))))))) )))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name char)))) in (testlist (test (logical_test (comparison (expr (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name string)) (trailer . (name ascii_uppercase)))))))) )))) - (expr (atom (name setsub)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name substring)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name substring)) (trailer . (name replace) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "?")))))) , (argument (test (logical_test (comparison (expr (atom (name char))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))) : (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name substring)))) + (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 26)))))))) :)) ]))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)) (trailer . (name replace) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "?")))))) , (argument (test (logical_test (comparison (expr (atom "A"))))))) ))))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom "-1")))))))))))))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd,sqrt prime=[True]*100001 def SieveOfEratosthenes(): prime[0]=False prime[1]=False for p in range(2,int(sqrt(100001))+1): if prime[p]==True : for i in range(p**2,100001,p): prime[i]=False def common_prime(a,b): __gcd=gcd(a,b) for i in range(2,__gcd+1): if prime[i]and __gcd % i==0 : print(i,end=" ") if __name__=="__main__" : SieveOfEratosthenes() a,b=6,12 common_prime(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, 100001) ; skip ; skip ; if __name__ = "__main__" then ( SieveOfEratosthenes() ; Sequence{a,b} := Sequence{6,12} ; common_prime(a, b) ) else skip; operation SieveOfEratosthenes() pre: true post: true activity: prime->first() := false ; prime[1+1] := false ; for p : Integer.subrange(2, ("" + ((sqrt(100001))))->toInteger() + 1-1) do ( if prime[p+1] = true then ( for i : Integer.subrange((p)->pow(2), 100001-1)->select( $x | ($x - (p)->pow(2)) mod p = 0 ) do ( prime[i+1] := false) ) else skip); operation common_prime(a : OclAny, b : OclAny) pre: true post: true activity: var __gcd : OclAny := gcd(a, b) ; for i : Integer.subrange(2, __gcd + 1-1) do ( if prime[i+1] & __gcd mod i = 0 then ( execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printCollatz(n): while n!=1 : print(n,end=' ') if n & 1 : n=3*n+1 else : n=n//2 print(n) printCollatz(6) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; printCollatz(6); operation printCollatz(n : OclAny) pre: true post: true activity: while n /= 1 do ( execute (n)->display() ; if MathLib.bitwiseAnd(n, 1) then ( n := 3 * n + 1 ) else ( n := n div 2 )) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys BIG_NUM=2000000000 MOD=1000000007 EPS=0.000000001 S=str(input()) P=str(input()) is_ok=False for i in range(len(S)): FLG=True for k in range(len(P)): if S[(i+k)%(len(S))]!=P[k]: FLG=False break if FLG==True : is_ok=True break if is_ok==True : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var BIG_NUM : int := 2000000000 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; var S : String := ("" + (((OclFile["System.in"]).readLine()))) ; var P : String := ("" + (((OclFile["System.in"]).readLine()))) ; var is_ok : boolean := false ; for i : Integer.subrange(0, (S)->size()-1) do ( var FLG : boolean := true ; for k : Integer.subrange(0, (P)->size()-1) do ( if S[(i + k) mod ((S)->size())+1] /= P[k+1] then ( FLG := false ; break ) else skip) ; if FLG = true then ( is_ok := true ; break ) else skip) ; if is_ok = true then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find_Square_369(num): if(num[0]=='3'): a='1' b='0' c='8' d='9' elif(num[0]=='6'): a='4' b='3' c='5' d='6' else : a='9' b='8' c='0' d='1' result="" size=len(num) for i in range(1,size): result+=a result+=b for i in range(1,size): result+=c result+=d return result num_3="3333" num_6="6666" num_9="9999" result="" result=find_Square_369(num_3) print("Square of "+num_3+" is : "+result); result=find_Square_369(num_6) print("Square of "+num_6+" is : "+result); result=find_Square_369(num_9) print("Square of "+num_9+" is : "+result); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var num_3 : String := "3333" ; var num_6 : String := "6666" ; var num_9 : String := "9999" ; result := "" ; result := find_Square_369(num_3) ; execute ("Square of " + num_3 + " is : " + result)->display(); ; result := find_Square_369(num_6) ; execute ("Square of " + num_6 + " is : " + result)->display(); ; result := find_Square_369(num_9) ; execute ("Square of " + num_9 + " is : " + result)->display();; operation find_Square if (num->first() = '3') then ( var a : String := '1' ; var b : String := '0' ; var c : String := '8' ; var d : String := '9' ) else (if (num->first() = '6') then ( a := '4' ; b := '3' ; c := '5' ; d := '6' ) else ( a := '9' ; b := '8' ; c := '0' ; d := '1' ) ) ; var result : String := "" ; var size : int := (num)->size() ; for i : Integer.subrange(1, size-1) do ( result := result + a) ; result := result + b ; for i : Integer.subrange(1, size-1) do ( result := result + c) ; result := result + d ; return result69(num : OclAny) : OclAny pre: true post: true activity: if (num->first() = '3') then ( var a : String := '1' ; var b : String := '0' ; var c : String := '8' ; var d : String := '9' ) else (if (num->first() = '6') then ( a := '4' ; b := '3' ; c := '5' ; d := '6' ) else ( a := '9' ; b := '8' ; c := '0' ; d := '1' ) ) ; var result : String := "" ; var size : int := (num)->size() ; for i : Integer.subrange(1, size-1) do ( result := result + a) ; result := result + b ; for i : Integer.subrange(1, size-1) do ( result := result + c) ; result := result + d ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=0 for i in range(n): l,r=map(int,input().split()) ans+=r-l+1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; ans := ans + r - l + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(sum(1-eval(input().replace(" ","-"))for _ in range(int(input())))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (((argument (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) - (expr (atom (name eval)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name replace) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " ")))))) , (argument (test (logical_test (comparison (expr (atom "-"))))))) ))))))))) )))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))) )))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) e=[[int(i)for i in input().split()]for i in range(n)] result=0 for i in e : result+=i[1]-i[0] print(result+n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var e : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())))) ; var result : int := 0 ; for i : e do ( result := result + i[1+1] - i->first()) ; execute (result + n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[tuple(map(int,input().split()))for i in range(n)] cnt=0 for i in l : cnt+=(i[1]-i[0]+1) print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var cnt : int := 0 ; for i : l do ( cnt := cnt + (i[1+1] - i->first() + 1)) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lr=[] for _ in range(n): a=[int(x)for x in input().split()] lr.append(a) ans=0 for x in lr : ans+=x[1]-x[0]+1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lr : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((a) : lr)) ; var ans : int := 0 ; for x : lr do ( ans := ans + x[1+1] - x->first() + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: n,k=map(int,s.split()); v=bin(k-1)[2 :] if k>1 : v+='0' if len(v)>n : print(-1); continue v=v.rjust(n,'0'); a=[]; t=[] for i in range(n): t+=str(i+1), if v[i]<'1' : a+=t[: :-1]; t=[] print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ); var v : OclAny := bin(k - 1).subrange(2+1) ; if k > 1 then ( v := v + '0' ) else skip ; if ((v)->size()->compareTo(n)) > 0 then ( execute (-1)->display(); continue ) else skip ; v := StringLib.padLeftWithInto(v, '0', n); var a : Sequence := Sequence{}; var t : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( t := t + (testlist (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ))))))) ,) ; if v[i+1] < '1' then ( a := a + t(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); t := Sequence{} ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,sys ; input=sys.stdin.readline ; S=lambda : input().rstrip(); I=lambda : int(S()); M=lambda : map(int,S().split()); L=lambda : list(M()); mod1=1000000007 ; mod2=998244353 for _ in range(I()): n,k=M() if k>2**(n-1): print(-1); continue if n==1 : print(1); continue s=bin(2**(n-1)-k)[2 :]; s=(n-1-len(s))*'0'+s res=[]; cur=[1]; j=2 for i in s : if i=='1' : res+=cur[: :-1] cur=[j]; j+=1 else : cur.append(j); j+=1 res+=cur[: :-1]; print(*res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; var input : OclAny := (OclFile["System.in"]).readline; var S : Function := lambda $$ : OclAny in (input().rstrip()); var I : Function := lambda $$ : OclAny in (("" + ((S->apply())))->toInteger()); var M : Function := lambda $$ : OclAny in ((S->apply().split())->collect( _x | (OclType["int"])->apply(_x) )); var L : Function := lambda $$ : OclAny in ((M->apply())); var mod1 : int := 1000000007; var mod2 : int := 998244353 ; for _anon : Integer.subrange(0, I->apply()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := M->apply() ; if (k->compareTo((2)->pow((n - 1)))) > 0 then ( execute (-1)->display(); continue ) else skip ; if n = 1 then ( execute (1)->display(); continue ) else skip ; var s : OclAny := bin((2)->pow((n - 1)) - k).subrange(2+1); s := (n - 1 - (s)->size()) * '0' + s ; var res : Sequence := Sequence{}; var cur : Sequence := Sequence{ 1 }; var j : int := 2 ; for i : s do ( if i = '1' then ( res := res + cur(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; cur := Sequence{ j }; j := j + 1 ) else ( execute ((j) : cur); j := j + 1 )) ; res := res + cur(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from operator import itemgetter m_inf=float("-inf") n=int(input()) phrase=[0]*(394) for s,l,p in(map(int,input().split())for _ in[0]*n): for i,_p in enumerate(phrase[s : l+1],start=s): phrase[i]=_p if _p>p else p dp=[0]+[m_inf]*393 for length,p in filter(itemgetter(1),enumerate(phrase)): for from_p,to_p,to in zip(dp,dp[length :],range(length,395)): dp[to]=to_p if to_p>=from_p+p else from_p+p result=[dp[int(input())]for _ in[0]*int(input())] print(*(result if m_inf not in result else[-1]),sep="\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var m_inf : double := ("" + (("-inf")))->toReal() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var phrase : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (394)) ; for _tuple : Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr (atom (name n))))))))} do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var l : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p : OclAny := _tuple->at(_indx); for _tuple : Integer.subrange(1, (phrase.subrange(s+1, l + 1), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (name s))))))))->size())->collect( _indx | Sequence{_indx-1, (phrase.subrange(s+1, l + 1), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (name s))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var _p : OclAny := _tuple->at(_indx); phrase[i+1] := if (_p->compareTo(p)) > 0 then _p else p endif)) ; var dp : Sequence := Sequence{ 0 }->union(MatrixLib.elementwiseMult(Sequence{ m_inf }, 393)) ; for _tuple : (Integer.subrange(1, (phrase)->size())->collect( _indx | Sequence{_indx-1, (phrase)->at(_indx)} ))->select( _x | (itemgetter(1))->apply(_x) = true ) do (var _indx : int := 1; var length : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p : OclAny := _tuple->at(_indx); for _tuple : Integer.subrange(1, dp->size())->collect( _indx | Sequence{dp->at(_indx), dp.subrange(length+1)->at(_indx)} ) do (var _indx : int := 1; var from_p : OclAny := _tuple->at(_indx); _indx := _indx + 1; var to_p : OclAny := _tuple->at(_indx); _indx := _indx + 1; var to : OclAny := _tuple->at(_indx); dp[to+1] := if (to_p->compareTo(from_p + p)) >= 0 then to_p else from_p + p endif)) ; var result : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger())->select(_anon | true)->collect(_anon | (dp[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1])) ; execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name result))))) if (logical_test (comparison (comparison (expr (atom (name m_inf)))) not in (comparison (expr (atom (name result)))))) else (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom - (number (integer 1)))))))) ]))))))) ))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=1 h=[0]*126 for i in range(n): v=int(input()) if v<=125 : h[v]+=1 ans+=v s=0 for i in range(1,126): s+=h[i-1] if n>s+4*i : ans-=n-(s+4*i) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 1 ; var h : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 126) ; for i : Integer.subrange(0, n-1) do ( var v : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if v <= 125 then ( h[v+1] := h[v+1] + 1 ) else skip ; ans := ans + v) ; var s : int := 0 ; for i : Integer.subrange(1, 126-1) do ( s := s + h[i - 1+1] ; if (n->compareTo(s + 4 * i)) > 0 then ( ans := ans - n - (s + 4 * i) ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : n=int(input()) hl=[] for i in range(n): hl.append(int(input())) i=0 d=0 ans=1 hl=sorted(hl,reverse=True) for i,h in enumerate(hl): a=h-d if a<0 : a=0 ans+=a if i % 4==3 : d+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var hl : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : hl)) ; var i : int := 0 ; var d : int := 0 ; var ans : int := 1 ; hl := hl->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; for _tuple : Integer.subrange(1, (hl)->size())->collect( _indx | Sequence{_indx-1, (hl)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var h : OclAny := _tuple->at(_indx); var a : double := h - d ; if a < 0 then ( a := 0 ) else skip ; ans := ans + a ; if i mod 4 = 3 then ( d := d + 1 ) else skip) ; execute (ans)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import* from bisect import* from math import* from collections import* from heapq import* from random import* import sys sys.setrecursionlimit(10**6) int1=lambda x : int(x)-1 p2D=lambda x : print(*x,sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int,sys.stdin.readline().split()) def MI1(): return map(int1,sys.stdin.readline().split()) def MF(): return map(float,sys.stdin.readline().split()) def LI(): return list(map(int,sys.stdin.readline().split())) def LI1(): return list(map(int1,sys.stdin.readline().split())) def LF(): return list(map(float,sys.stdin.readline().split())) def LLI(rows_number): return[LI()for _ in range(rows_number)] dij=[(1,0),(0,1),(-1,0),(0,-1)] def main(): n=II() tt=[] aa=[] for _ in range(n): t,a=MI() tt.append(t) aa.append(log10(10-a)-1) cm=[0] for a in aa : cm.append(cm[-1]+a) q=II() for _ in range(q): l,r=MI() li=bisect_left(tt,l) ri=bisect_left(tt,r) print(pow(10,cm[ri]-cm[li]+9)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(6)) ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; var p2D : Function := lambda x : OclAny in (((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var dij : Sequence := Sequence{Sequence{1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{-1, 0}}->union(Sequence{ Sequence{0, -1} }))) ; skip ; main(); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation MI1() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (int1)->apply(_x) ); operation MF() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LI1() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (int1)->apply(_x) )); operation LF() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) )); operation LLI(rows_number : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows_number-1)->select(_anon | true)->collect(_anon | (LI())); operation main() pre: true post: true activity: var n : OclAny := II() ; var tt : Sequence := Sequence{} ; var aa : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var t : OclAny := null; var a : OclAny := null; Sequence{t,a} := MI() ; execute ((t) : tt) ; execute ((log10(10 - a) - 1) : aa)) ; var cm : Sequence := Sequence{ 0 } ; for a : aa do ( execute ((cm->last() + a) : cm)) ; var q : OclAny := II() ; for _anon : Integer.subrange(0, q-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := MI() ; var li : OclAny := bisect_left(tt, l) ; var ri : OclAny := bisect_left(tt, r) ; execute ((10)->pow(cm[ri+1] - cm[li+1] + 9))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=sorted([int(input())for _ in[0]*int(input())]) c=b=0 for i in range(len(a)-1,-1,-1): if a[i]toInteger())->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))->sort() ; var c : OclAny := 0; var b : int := 0 ; for i : Integer.subrange(-1 + 1, (a)->size() - 1)->reverse() do ( if (a[i+1]->compareTo(c div 4)) < 0 then ( continue ) else ( b := b + a[i+1] - c div 4 ) ; c := c + 1) ; execute (b + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=sorted([int(input())for _ in[0]*int(input())]) c=b=0 for i in range(len(a)-1,-1,-1): if a[i]>=c//4 : b+=a[i]-c//4 c+=1 print(b+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger())->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))->sort() ; var c : OclAny := 0; var b : int := 0 ; for i : Integer.subrange(-1 + 1, (a)->size() - 1)->reverse() do ( if (a[i+1]->compareTo(c div 4)) >= 0 then ( b := b + a[i+1] - c div 4 ) else skip ; c := c + 1) ; execute (b + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) h_lst=sorted([int(input())for _ in range(n)]) def solve(): ans=1 cnt=0 while h_lst : for _ in range(4): if h_lst : add=h_lst.pop()-cnt if add<=0 : return ans ans+=add else : return ans cnt+=1 return ans print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var h_lst : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))->sort() ; skip ; execute (solve())->display(); operation solve() : OclAny pre: true post: true activity: var ans : int := 1 ; var cnt : int := 0 ; while h_lst do ( for _anon : Integer.subrange(0, 4-1) do ( if h_lst then ( var add : double := h_lst->last() - cnt ; if add <= 0 then ( return ans ) else skip ; ans := ans + add ) else ( return ans )) ; cnt := cnt + 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printPath(res,nThNode,kThNode): if kThNode>nThNode : return res.append(kThNode) for i in range(0,len(res)): print(res[i],end=" ") print() printPath(res[:],nThNode,kThNode*2) printPath(res[:],nThNode,kThNode*2+1) def printPathToCoverAllNodeUtil(nThNode): res=[] printPath(res,nThNode,1) if __name__=="__main__" : nThNode=7 printPathToCoverAllNodeUtil(nThNode) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( nThNode := 7 ; printPathToCoverAllNodeUtil(nThNode) ) else skip; operation printPath(res : OclAny, nThNode : OclAny, kThNode : OclAny) pre: true post: true activity: if (kThNode->compareTo(nThNode)) > 0 then ( return ) else skip ; execute ((kThNode) : res) ; for i : Integer.subrange(0, (res)->size()-1) do ( execute (res[i+1])->display()) ; execute (->display() ; printPath(res, nThNode, kThNode * 2) ; printPath(res, nThNode, kThNode * 2 + 1); operation printPathToCoverAllNodeUtil(nThNode : OclAny) pre: true post: true activity: res := Sequence{} ; printPath(res, nThNode, 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printFactorialNums(n): fact=1 x=2 while fact<=n : print(fact,end=" ") fact=fact*x x+=1 n=100 printFactorialNums(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 100 ; printFactorialNums(n); operation printFactorialNums(n : OclAny) pre: true post: true activity: var fact : int := 1 ; var x : int := 2 ; while (fact->compareTo(n)) <= 0 do ( execute (fact)->display() ; fact := fact * x ; x := x + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPair(arr,n,k): cnt=0 ; for i in range(n): arr[i]=(arr[i]+k)% k ; hash=[0]*k ; for i in range(n): hash[arr[i]]+=1 ; for i in range(k): cnt+=(hash[i]*(hash[i]-1))/2 ; print(int(cnt)); if __name__=='__main__' : arr=[1,2,3,4]; k=2 ; n=len(arr); countPair(arr,n,k); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))); ; k := 2; ; n := (arr)->size(); ; countPair(arr, n, k); ) else skip; operation countPair(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var cnt : int := 0; ; for i : Integer.subrange(0, n-1) do ( arr[i+1] := (arr[i+1] + k) mod k;) ; var hash : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, k); ; for i : Integer.subrange(0, n-1) do ( hash[arr[i+1]+1] := hash[arr[i+1]+1] + 1;) ; for i : Integer.subrange(0, k-1) do ( cnt := cnt + (hash[i+1] * (hash[i+1] - 1)) / 2;) ; execute (("" + ((cnt)))->toInteger())->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys INT_MIN=-sys.maxsize-1 def maxSum(arr,n,k): max_sum=INT_MIN for i in range(n-k+1): current_sum=0 for j in range(k): current_sum=current_sum+arr[i+j] max_sum=max(current_sum,max_sum) return max_sum arr=[1,4,2,10,2,3,1,0,20] k=4 n=len(arr) print(maxSum(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var INT_MIN : double := -(trailer . (name maxsize)) - 1 ; skip ; arr := Sequence{1}->union(Sequence{4}->union(Sequence{2}->union(Sequence{10}->union(Sequence{2}->union(Sequence{3}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 20 })))))))) ; k := 4 ; n := (arr)->size() ; execute (maxSum(arr, n, k))->display(); operation maxSum(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var max_sum : OclAny := INT_MIN ; for i : Integer.subrange(0, n - k + 1-1) do ( var current_sum : int := 0 ; for j : Integer.subrange(0, k-1) do ( current_sum := current_sum + arr[i + j+1]) ; max_sum := Set{current_sum, max_sum}->max()) ; return max_sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=1000000007 eps=10**-9 def main(): import sys from collections import deque input=sys.stdin.buffer.readline N,M=map(int,input().split()) adj=[[]for _ in range(N+1)] for _ in range(M): a,b=map(int,input().split()) adj[a].append(b) adj[b].append(a) seen=[0]*(N+1) single=0 bipartite=0 not_bipartite=0 for v0 in range(1,N+1): if seen[v0]!=0 : continue flg=1 que=deque() que.append(v0) seen[v0]=1 cnt=0 while que : v=que.popleft() cnt+=1 for u in adj[v]: if seen[u]==0 : seen[u]=-seen[v] que.append(u) else : if seen[u]==seen[v]: flg=0 if cnt==1 : single+=1 else : if flg : bipartite+=1 else : not_bipartite+=1 ans=N**2-(N-single)**2 ans+=(bipartite+not_bipartite)**2 ans+=bipartite**2 print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : int := 1000000007 ; var eps : double := (10)->pow(-9) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: skip ; skip ; var input : OclAny := sys.stdin.buffer.readline ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var adj : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, M-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var seen : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; var single : int := 0 ; var bipartite : int := 0 ; var not_bipartite : int := 0 ; for v0 : Integer.subrange(1, N + 1-1) do ( if seen[v0+1] /= 0 then ( continue ) else skip ; var flg : int := 1 ; var que : Sequence := () ; execute ((v0) : que) ; seen[v0+1] := 1 ; var cnt : int := 0 ; while que do ( var v : OclAny := que->first() ; que := que->tail() ; cnt := cnt + 1 ; for u : adj[v+1] do ( if seen[u+1] = 0 then ( seen[u+1] := -seen[v+1] ; execute ((u) : que) ) else ( if seen[u+1] = seen[v+1] then ( flg := 0 ) else skip ))) ; if cnt = 1 then ( single := single + 1 ) else ( if flg then ( bipartite := bipartite + 1 ) else ( not_bipartite := not_bipartite + 1 ) )) ; var ans : double := (N)->pow(2) - ((N - single))->pow(2) ; ans := ans + ((bipartite + not_bipartite))->pow(2) ; ans := ans + (bipartite)->pow(2) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def makePalindrome(str1): i=0 j=len(str1)-1 str1=list(str1) while(i<=j): if(str1[i]=='*' and str1[j]=='*'): str1[i]='a' str1[j]='a' elif(str1[j]=='*'): str1[j]=str1[i] elif(str1[i]=='*'): str1[i]=str1[j] elif(str1[i]!=str1[j]): str1=''.join(str1) return "-1" i+=1 j-=1 str1=''.join(str1) return str1 if __name__=='__main__' : str1="na*an" print(makePalindrome(str1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( str1 := "na*an" ; execute (makePalindrome(str1))->display() ) else skip; operation makePalindrome(str1 : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; var j : double := (str1)->size() - 1 ; str1 := (str1) ; while ((i->compareTo(j)) <= 0) do ( if (str1[i+1] = '*' & str1[j+1] = '*') then ( str1[i+1] := 'a' ; str1[j+1] := 'a' ) else (if (str1[j+1] = '*') then ( str1[j+1] := str1[i+1] ) else (if (str1[i+1] = '*') then ( str1[i+1] := str1[j+1] ) else (if (str1[i+1] /= str1[j+1]) then ( str1 := StringLib.sumStringsWithSeparator((str1), '') ; return "-1" ) else skip ) ) ) ; i := i + 1 ; j := j - 1) ; str1 := StringLib.sumStringsWithSeparator((str1), '') ; return str1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: t=m=0 for x in s.split(): t+=int(x); m=min(m,t) print(-m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var t : OclAny := 0; var m : int := 0 ; for x : s.split() do ( t := t + ("" + ((x)))->toInteger(); m := Set{m, t}->min()) ; execute (-m)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for p in range(int(input())): n=int(input()) a=list(map(int,input().split())) for i in range(1,n): a[i]+=a[i-1] print(abs(min(a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for p : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(1, n-1) do ( a[i+1] := a[i+1] + a[i - 1+1]) ; execute (((a)->min())->abs())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import log10 from bisect import bisect_left n=int(input()) l=[[0,0]]+[list(map(int,input().split()))for _ in range(n)] for i in range(1,n+1): l[i][1]=log10(1-l[i][1]/10) for i in range(n): l[i+1][1]+=l[i][1] q=int(input()) for _ in range(q): a,b=map(int,input().split()) i=bisect_left(l,[a,0])-1 j=bisect_left(l,[b,0])-1 p=l[j][1]-l[i][1]+9 print(10**p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{ Sequence{0}->union(Sequence{ 0 }) }->union(Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))) ; for i : Integer.subrange(1, n + 1-1) do ( l[i+1][1+1] := log10(1 - l[i+1][1+1] / 10)) ; for i : Integer.subrange(0, n-1) do ( l[i + 1+1][1+1] := l[i + 1+1][1+1] + l[i+1][1+1]) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var i : double := bisect_left(l, Sequence{a}->union(Sequence{ 0 })) - 1 ; var j : double := bisect_left(l, Sequence{b}->union(Sequence{ 0 })) - 1 ; var p : double := l[j+1][1+1] - l[i+1][1+1] + 9 ; execute ((10)->pow(p))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def _input(): return map(int,input().split()) def f(): n=int(input()) lst=list(_input()) i=0 while i0 : lst[i+1]+=lst[i] i+=1 print(lst[-1]) for _ in range(int(input())): f() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( f()); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation f() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := (_input()) ; var i : int := 0 ; while (i->compareTo(n - 1)) < 0 do ( if lst[i+1] > 0 then ( lst[i + 1+1] := lst[i + 1+1] + lst[i+1] ) else skip ; i := i + 1) ; execute (lst->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) l=list(map(int,input().strip().split())) a=0 for i in l : if(i<0 and a!=0): q=abs(i) if(a>=q): a-=q else : a=0 elif(i<0): continue else : a+=i print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : int := 0 ; for i : l do ( if (i < 0 & a /= 0) then ( var q : double := (i)->abs() ; if ((a->compareTo(q)) >= 0) then ( a := a - q ) else ( a := 0 ) ) else (if (i < 0) then ( continue ) else ( a := a + i ) ) ) ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(0,int(input())): input() v=list(map(int,input().split())) p=0 t=0 for x in v : if x<0 : w=p+x p=max(0,p+x) if w<0 : t+=w else : p+=x print(abs(t)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( input() ; var v : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var p : int := 0 ; var t : int := 0 ; for x : v do ( if x < 0 then ( var w : int := p + x ; p := Set{0, p + x}->max() ; if w < 0 then ( t := t + w ) else skip ) else ( p := p + x )) ; execute ((t)->abs())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,A,B=map(int,input().split()) if(B-A)% 2 : print(min(A-1,N-B)+(B+1-A)//2) else : print((B-A)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{N,A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (B - A) mod 2 then ( execute (Set{A - 1, N - B}->min() + (B + 1 - A) div 2)->display() ) else ( execute ((B - A) div 2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input_lines=input().split() N=int(input_lines[0]) A=int(input_lines[1]) B=int(input_lines[2]) ans=0 if(B-A)% 2==0 : print(int((B-A)//2)) else : print(min(A-1,N-B)+1+int((B-A-1)//2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var input_lines : OclAny := input().split() ; var N : int := ("" + ((input_lines->first())))->toInteger() ; var A : int := ("" + ((input_lines[1+1])))->toInteger() ; var B : int := ("" + ((input_lines[2+1])))->toInteger() ; var ans : int := 0 ; if (B - A) mod 2 = 0 then ( execute (("" + (((B - A) div 2)))->toInteger())->display() ) else ( execute (Set{A - 1, N - B}->min() + 1 + ("" + (((B - A - 1) div 2)))->toInteger())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n,a,b=map(int,input().split()) if(b-a)% 2==0 : print((b-a)//2) sys.exit() k=(a+b-1)//2 print(min(k,n-k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (b - a) mod 2 = 0 then ( execute ((b - a) div 2)->display() ; sys.exit() ) else skip ; var k : int := (a + b - 1) div 2 ; execute (Set{k, n - k}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict max_phrases=defaultdict(int) n=int(input()) for _ in range(n): s,l,p=map(int,input().split()) for length in range(s,l+1): max_phrases[length]=max(max_phrases[length],p) m=int(input()) melodies=[int(input())for _ in range(m)] max_length=max(melodies) dp=[-1]*(max_length+max(max_phrases)) dp[0]=0 for i in range(max_length): c=dp[i] if c==-1 : continue for length,p in max_phrases.items(): dp[i+length]=max(dp[i+length],c+p) results=[None]*m for i,melody in enumerate(melodies): result=dp[melody] if result==-1 : print(-1) break results[i]=result else : print('\n'.join(map(str,results))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var max_phrases : OclAny := defaultdict(OclType["int"]) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var s : OclAny := null; var l : OclAny := null; var p : OclAny := null; Sequence{s,l,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for length : Integer.subrange(s, l + 1-1) do ( max_phrases[length+1] := Set{max_phrases[length+1], p}->max())) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var melodies : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var max_length : OclAny := (melodies)->max() ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (max_length + (max_phrases)->max())) ; dp->first() := 0 ; for i : Integer.subrange(0, max_length-1) do ( var c : OclAny := dp[i+1] ; if c = -1 then ( continue ) else skip ; for _tuple : max_phrases->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var length : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p : OclAny := _tuple->at(_indx); dp[i + length+1] := Set{dp[i + length+1], c + p}->max())) ; var results : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, m) ; (compound_stmt for (exprlist (expr (atom (name i))) , (expr (atom (name melody)))) in (testlist (test (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name melodies)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name result)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name melody)))))))) ])))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name result)))) == (comparison (expr (atom - (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name results)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name result))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ' ') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name results)))))))) ))))))))) ))))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def p_a(): n,a,b=map(int,input().split()) if(b-a)& 1==0 : print((b-a)//2) exit() print((b-a-1)//2+min(a-1,n-b)+1) p_a() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; p_a(); operation p_a() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if MathLib.bitwiseAnd((b - a), 1) = 0 then ( execute ((b - a) div 2)->display() ; exit() ) else skip ; execute ((b - a - 1) div 2 + Set{a - 1, n - b}->min() + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=list(map(int,input().split())) s=0 if(a-b)% 2==0 : s=abs(a-b)//2 else : s=min((a+b-1)//2,(2*n-a-b+1)//2) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : int := 0 ; if (a - b) mod 2 = 0 then ( s := (a - b)->abs() div 2 ) else ( s := Set{(a + b - 1) div 2, (2 * n - a - b + 1) div 2}->min() ) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left def main(): A,B,q=map(int,input().split()) INF=10**18 s=[-INF]+[int(input())for _ in range(A)]+[INF] t=[-INF]+[int(input())for _ in range(B)]+[INF] for _ in range(q): x=int(input()) sind=bisect_left(s,x) tind=bisect_left(t,x) res=INF for S in[s[sind-1],s[sind]]: for T in[t[tind-1],t[tind]]: d1=abs(x-S)+abs(S-T) d2=abs(x-T)+abs(T-S) res=min([res,d1,d2]) print(res) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var q : OclAny := null; Sequence{A,B,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var INF : double := (10)->pow(18) ; var s : Sequence := Sequence{ -INF }->union(Integer.subrange(0, A-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())))->union(Sequence{ INF }) ; var t : Sequence := Sequence{ -INF }->union(Integer.subrange(0, B-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())))->union(Sequence{ INF }) ; for _anon : Integer.subrange(0, q-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sind : OclAny := bisect_left(s, x) ; var tind : OclAny := bisect_left(t, x) ; var res : OclAny := INF ; for S : Sequence{s[sind - 1+1]}->union(Sequence{ s[sind+1] }) do ( for T : Sequence{t[tind - 1+1]}->union(Sequence{ t[tind+1] }) do ( var d1 : double := (x - S)->abs() + (S - T)->abs() ; var d2 : double := (x - T)->abs() + (T - S)->abs() ; res := (Sequence{res}->union(Sequence{d1}->union(Sequence{ d2 })))->min())) ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import numpy as np hint=list(map(int,input().split())) s=[int(input())for i in range(sum(hint))] def search_min_pos(arr,target): index=bisect.bisect_left(arr,target) if 0==index : dist=arr[index] else : dist=arr[index-1 : index+1] if not isinstance(dist,list): dist=[dist] return dist a_arr=s[: hint[0]] b_arr=s[hint[0]:-hint[2]] sum=0 for t in s[-hint[2]:]: a_pos=search_min_pos(a_arr,t) b_pos=search_min_pos(b_arr,t) min_dist=10**11 for a in a_pos : b_against_a=search_min_pos(b_arr,a) for ba in b_against_a : min_dist=min([min_dist,abs(t-a)+abs(ba-a)]) for b in b_pos : a_against_b=search_min_pos(a_arr,b) for ab in a_against_b : min_dist=min([min_dist,abs(t-b)+abs(ab-b)]) print(min_dist) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var hint : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Sequence := Integer.subrange(0, (hint)->sum()-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; skip ; var a_arr : OclAny := s.subrange(1,hint->first()) ; var b_arr : OclAny := s.subrange(hint->first()+1, -hint[2+1]) ; var sum : int := 0 ; for t : s.subrange(-hint[2+1]+1) do ( var a_pos : OclAny := search_min_pos(a_arr, t) ; var b_pos : OclAny := search_min_pos(b_arr, t) ; var min_dist : double := (10)->pow(11) ; for a : a_pos do ( var b_against_a : OclAny := search_min_pos(b_arr, a) ; for ba : b_against_a do ( min_dist := (Sequence{min_dist}->union(Sequence{ (t - a)->abs() + (ba - a)->abs() }))->min())) ; for b : b_pos do ( var a_against_b : OclAny := search_min_pos(a_arr, b) ; for ab : a_against_b do ( min_dist := (Sequence{min_dist}->union(Sequence{ (t - b)->abs() + (ab - b)->abs() }))->min())) ; execute (min_dist)->display()); operation search_min_pos(arr : OclAny, target : OclAny) : OclAny pre: true post: true activity: var index : OclAny := bisect.bisect_left(arr, target) ; if 0 = index then ( var dist : OclAny := arr[index+1] ) else ( dist := arr.subrange(index - 1+1, index + 1) ) ; if not((OclType["Sequence"]).isInstance(dist)) then ( dist := Sequence{ dist } ) else skip ; return dist; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getMinCost(arr,n): min_ele=min(arr) return min_ele*(n-1) arr=[4,2,5] n=len(arr) print(getMinCost(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{4}->union(Sequence{2}->union(Sequence{ 5 })) ; n := (arr)->size() ; execute (getMinCost(arr, n))->display(); operation getMinCost(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var min_ele : OclAny := (arr)->min() ; return min_ele * (n - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import bisect input=sys.stdin.buffer.readline sys.setrecursionlimit(10**7) bl=bisect.bisect_left A,B,Q=map(int,input().split()) inf=10**18 S=[-inf]+[int(input())for _ in range(A)]+[inf] T=[-inf]+[int(input())for _ in range(B)]+[inf] def path(x): sl=S[bl(S,x)-1] sr=S[bl(S,x)] tl=T[bl(T,x)-1] tr=T[bl(T,x)] res=10**18 res=min(res,abs(x-sl)+abs(sl-tl)) res=min(res,abs(x-sl)+abs(sl-tr)) res=min(res,abs(x-sr)+abs(sr-tr)) res=min(res,abs(x-sr)+abs(sr-tl)) res=min(res,abs(x-tr)+abs(tr-sl)) res=min(res,abs(x-tr)+abs(tr-sr)) res=min(res,abs(x-tl)+abs(tl-sl)) res=min(res,abs(x-tl)+abs(tl-sr)) return res X=[int(input())for _ in range(Q)] for x in X : print(path(x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := sys.stdin.buffer.readline ; sys.setrecursionlimit((10)->pow(7)) ; var bl : OclAny := bisect.bisect_left ; var A : OclAny := null; var B : OclAny := null; var Q : OclAny := null; Sequence{A,B,Q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var Math_PINFINITY : double := (10)->pow(18) ; var S : Sequence := Sequence{ -Math_PINFINITY }->union(Integer.subrange(0, A-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())))->union(Sequence{ Math_PINFINITY }) ; var T : Sequence := Sequence{ -Math_PINFINITY }->union(Integer.subrange(0, B-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())))->union(Sequence{ Math_PINFINITY }) ; skip ; var X : Sequence := Integer.subrange(0, Q-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; for x : X do ( execute (path(x))->display()); operation path(x : OclAny) : OclAny pre: true post: true activity: var sl : OclAny := S[bl(S, x) - 1+1] ; var sr : OclAny := S[bl(S, x)+1] ; var tl : OclAny := T[bl(T, x) - 1+1] ; var tr : OclAny := T[bl(T, x)+1] ; var res : double := (10)->pow(18) ; res := Set{res, (x - sl)->abs() + (sl - tl)->abs()}->min() ; res := Set{res, (x - sl)->abs() + (sl - tr)->abs()}->min() ; res := Set{res, (x - sr)->abs() + (sr - tr)->abs()}->min() ; res := Set{res, (x - sr)->abs() + (sr - tl)->abs()}->min() ; res := Set{res, (x - tr)->abs() + (tr - sl)->abs()}->min() ; res := Set{res, (x - tr)->abs() + (tr - sr)->abs()}->min() ; res := Set{res, (x - tl)->abs() + (tl - sl)->abs()}->min() ; res := Set{res, (x - tl)->abs() + (tl - sr)->abs()}->min() ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left def solve(string): a,b,q,*stx=map(int,string.split()) s=[-10**10]+stx[: a]+[2*10**10] t=[-10**10]+stx[a : a+b]+[2*10**10] ans=[] i_s=0 i_t=0 for _x in stx[-q :]: i_s,i_t=bisect_left(s,_x),bisect_left(t,_x) ls,rs=_x-s[i_s-1],s[i_s]-_x lt,rt=_x-t[i_t-1],t[i_t]-_x r_max=max(rs,rt) l_max=max(ls,lt) ans.append(str(min(r_max,l_max,rt+ls+(rt if rtcollect( _x | (OclType["int"])->apply(_x) ) ; execute (solve(StringLib.interpolateStrings('{}{}{} ', Sequence{n, m, l}) + StringLib.sumStringsWithSeparator((Integer.subrange(0, n + m + l-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine()))), ' ')))->display() ) else skip; operation solve(string : OclAny) : OclAny pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var q : OclAny := null; var stx : OclAny := null; Sequence{a,b,q,stx} := (string.split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := Sequence{ (-10)->pow(10) }->union(stx.subrange(1,a))->union(Sequence{ 2 * (10)->pow(10) }) ; var t : Sequence := Sequence{ (-10)->pow(10) }->union(stx.subrange(a+1, a + b))->union(Sequence{ 2 * (10)->pow(10) }) ; var ans : Sequence := Sequence{} ; var i_s : int := 0 ; var i_t : int := 0 ; for _x : stx.subrange(-q+1) do ( Sequence{i_s,i_t} := Sequence{bisect_left(s, _x),bisect_left(t, _x)} ; var ls : OclAny := null; var rs : OclAny := null; Sequence{ls,rs} := Sequence{_x - s[i_s - 1+1],s[i_s+1] - _x} ; var lt : OclAny := null; var rt : OclAny := null; Sequence{lt,rt} := Sequence{_x - t[i_t - 1+1],t[i_t+1] - _x} ; var r_max : OclAny := Set{rs, rt}->max() ; var l_max : OclAny := Set{ls, lt}->max() ; execute ((("" + ((Set{r_max, l_max, rt + ls + (if (rt->compareTo(ls)) < 0 then rt else ls endif), rs + lt + (if (rs->compareTo(lt)) < 0 then rs else lt endif)}->min())))) : ans)) ; return StringLib.sumStringsWithSeparator((ans), "\n"); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import sys input=sys.stdin.readline def main(): A,B,Q=map(int,input().split()) s=list(int(input())for _ in range(A)) t=list(int(input())for _ in range(B)) sort_s=sorted(s) sort_t=sorted(t) for _ in range(Q): x=int(input()) s_near=bisect.bisect_left(sort_s,x) t_near=bisect.bisect_left(sort_t,x) s_candidate=[] t_candidate=[] if s_near==0 : s_candidate.append(sort_s[s_near]) elif s_near==A : s_candidate.append(sort_s[s_near-1]) else : s_candidate.append(sort_s[s_near]) s_candidate.append(sort_s[s_near-1]) if t_near==0 : t_candidate.append(sort_t[t_near]) elif t_near==B : t_candidate.append(sort_t[t_near-1]) else : t_candidate.append(sort_t[t_near]) t_candidate.append(sort_t[t_near-1]) ans=float('inf') for i in s_candidate : for j in t_candidate : tmp=abs(x-i)+abs(i-j) ans=min(ans,tmp) for k in t_candidate : for l in s_candidate : tmp=abs(x-k)+abs(k-l) ans=min(ans,tmp) print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; main(); operation main() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var Q : OclAny := null; Sequence{A,B,Q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)))))))) ))))))))) ; var t : Sequence := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name B)))))))) ))))))))) ; var sort_s : Sequence := s->sort() ; var sort_t : Sequence := t->sort() ; for _anon : Integer.subrange(0, Q-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s_near : OclAny := bisect.bisect_left(sort_s, x) ; var t_near : OclAny := bisect.bisect_left(sort_t, x) ; var s_candidate : Sequence := Sequence{} ; var t_candidate : Sequence := Sequence{} ; if s_near = 0 then ( execute ((sort_s[s_near+1]) : s_candidate) ) else (if s_near = A then ( execute ((sort_s[s_near - 1+1]) : s_candidate) ) else ( execute ((sort_s[s_near+1]) : s_candidate) ; execute ((sort_s[s_near - 1+1]) : s_candidate) ) ) ; if t_near = 0 then ( execute ((sort_t[t_near+1]) : t_candidate) ) else (if t_near = B then ( execute ((sort_t[t_near - 1+1]) : t_candidate) ) else ( execute ((sort_t[t_near+1]) : t_candidate) ; execute ((sort_t[t_near - 1+1]) : t_candidate) ) ) ; var ans : double := ("" + (('inf')))->toReal() ; for i : s_candidate do ( for j : t_candidate do ( var tmp : double := (x - i)->abs() + (i - j)->abs() ; ans := Set{ans, tmp}->min())) ; for k : t_candidate do ( for l : s_candidate do ( tmp := (x - k)->abs() + (k - l)->abs() ; ans := Set{ans, tmp}->min())) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMinSwaps(arr,n): noOfZeroes=[0]*n count=0 noOfZeroes[n-1]=1-arr[n-1] for i in range(n-2,-1,-1): noOfZeroes[i]=noOfZeroes[i+1] if(arr[i]==0): noOfZeroes[i]=noOfZeroes[i]+1 for i in range(0,n): if(arr[i]==1): count=count+noOfZeroes[i] return count arr=[0,0,1,0,1,0,1,1] n=len(arr) print(findMinSwaps(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 1 }))))))) ; n := (arr)->size() ; execute (findMinSwaps(arr, n))->display(); operation findMinSwaps(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var noOfZeroes : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var count : int := 0 ; noOfZeroes[n - 1+1] := 1 - arr[n - 1+1] ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( noOfZeroes[i+1] := noOfZeroes[i + 1+1] ; if (arr[i+1] = 0) then ( noOfZeroes[i+1] := noOfZeroes[i+1] + 1 ) else skip) ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] = 1) then ( count := count + noOfZeroes[i+1] ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=10**9+7 def sum(a,d,n): return n*(2*a+(n-1)*d)//2 def main(): n,m=map(int,input().split()) s=0 if n==1 : s=m+1 else : s=sum(m+1,-n+1,1+m//(n-1)) s*=2 s-=(m+1) print(s % MOD) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation sum(a : OclAny, d : OclAny, n : OclAny) : OclAny pre: true post: true activity: return n * (2 * a + (n - 1) * d) div 2; operation main() pre: true post: true activity: var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : int := 0 ; if n = 1 then ( s := m + 1 ) else ( s := (m + 1, -n + 1, 1 + m div (n - 1))->sum() ; s := s * 2 ; s := s - (m + 1) ) ; execute (s mod MOD)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=10**18 N=393 n=int(input()) phrss=[list(map(int,input().split()))for _ in range(n)] m=int(input()) mldys=[int(input())for _ in range(m)] max_mldy=max(mldys) mp=[-INF]*(N+1) for phrase in phrss : shortest,longest,point=phrase for length in range(shortest,longest+1): mp[length]=max(point,mp[length]) dp=[-INF]*(N+1) dp[0]=0 for i in range(N+1): for j in range(1,i+1): dp[i]=max(dp[i-j]+mp[j],dp[i]) ans=[] for melody in mldys : ans.append(dp[melody]) can=True for ai in ans : if ai<0 : can=False if can : for ai in ans : print(ai) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INF : double := (10)->pow(18) ; var N : int := 393 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var phrss : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mldys : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var max_mldy : OclAny := (mldys)->max() ; var mp : Sequence := MatrixLib.elementwiseMult(Sequence{ -INF }, (N + 1)) ; for phrase : phrss do ( var shortest : OclAny := null; var longest : OclAny := null; var point : OclAny := null; Sequence{shortest,longest,point} := phrase ; for length : Integer.subrange(shortest, longest + 1-1) do ( mp[length+1] := Set{point, mp[length+1]}->max())) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ -INF }, (N + 1)) ; dp->first() := 0 ; for i : Integer.subrange(0, N + 1-1) do ( for j : Integer.subrange(1, i + 1-1) do ( dp[i+1] := Set{dp[i - j+1] + mp[j+1], dp[i+1]}->max())) ; var ans : Sequence := Sequence{} ; for melody : mldys do ( execute ((dp[melody+1]) : ans)) ; var can : boolean := true ; for ai : ans do ( if ai < 0 then ( can := false ) else skip) ; if can then ( for ai : ans do ( execute (ai)->display()) ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- asd=raw_input() asdd=asd.split() n=int(asdd[0]) m=int(asdd[1]) if n==1 : print(m+1)% 1000000007 exit(0) x=(m+1)/(n-1) print(2*((m+1)*x-x*(n-1)*(x+1)/2)+m+1)% 1000000007 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var asd : OclAny := raw_input() ; var asdd : OclAny := asd.split() ; var n : int := ("" + ((asdd->first())))->toInteger() ; var m : int := ("" + ((asdd[1+1])))->toInteger() ; if n = 1 then ( (expr (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name m))) + (expr (atom (number (integer 1)))))))))) )))) % (expr (atom (number (integer 1000000007))))) ; exit(0) ) else skip ; var x : double := (m + 1) / (n - 1) ; (expr (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (expr (atom (number (integer 2)))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name m))) + (expr (atom (number (integer 1))))))))) ))) * (expr (atom (name x)))) - (expr (expr (expr (expr (atom (name x))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1))))))))) )))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (number (integer 1))))))))) )))) / (expr (atom (number (integer 2)))))))))) )))) + (expr (atom (name m)))) + (expr (atom (number (integer 1)))))))))) )))) % (expr (atom (number (integer 1000000007))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) mod1,mod2=10**9+7,998244353 mod=mod1 ans=(m+1)% mod if n!=1 : a=m//(n-1) ans=((m+1)*(a+1)+(m+1)*a-(n-1)*a*(a+1))% mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mod1 : OclAny := null; var mod2 : OclAny := null; Sequence{mod1,mod2} := Sequence{(10)->pow(9) + 7,998244353} ; var mod : OclAny := mod1 ; var ans : int := (m + 1) mod mod ; if n /= 1 then ( var a : int := m div (n - 1) ; ans := ((m + 1) * (a + 1) + (m + 1) * a - (n - 1) * a * (a + 1)) mod mod ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r=1000000007 n,m=input().split() n=int(n) m=int(m) if n==1 : output=(m+1)% r print(output) else : l=(m+1)//(n-1)+1 a=(m+1)-((m+1)//(n-1))*(n-1) e=m+1 output=((a+e)*l)//2 output=2*output-(m+1) output=output % r print(output) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : int := 1000000007 ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var m : int := ("" + ((m)))->toInteger() ; if n = 1 then ( var output : int := (m + 1) mod r ; execute (output)->display() ) else ( var l : int := (m + 1) div (n - 1) + 1 ; var a : double := (m + 1) - ((m + 1) div (n - 1)) * (n - 1) ; var e : int := m + 1 ; output := ((a + e) * l) div 2 ; output := 2 * output - (m + 1) ; output := output mod r ; execute (output)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) MOD=10**9+7 if n==1 : print((m+1)% MOD) else : k=m//(n-1) res=m+1+2*(m*k-k*(k+1)*(n-1)//2+k) print(res % MOD) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var MOD : double := (10)->pow(9) + 7 ; if n = 1 then ( execute ((m + 1) mod MOD)->display() ) else ( var k : int := m div (n - 1) ; var res : OclAny := m + 1 + 2 * (m * k - k * (k + 1) * (n - 1) div 2 + k) ; execute (res mod MOD)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printSeries(N): ith_term=0 ; for i in range(1,N+1): ith_term=0 ; if(i % 2==0): ith_term=2*i*i+1 ; else : ith_term=2*i*i-1 ; print(ith_term,end=","); if __name__=='__main__' : N=7 ; printSeries(N); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( N := 7; ; printSeries(N); ) else skip; operation printSeries(N : OclAny) pre: true post: true activity: var ith_term : int := 0; ; for i : Integer.subrange(1, N + 1-1) do ( ith_term := 0; ; if (i mod 2 = 0) then ( ith_term := 2 * i * i + 1; ) else ( ith_term := 2 * i * i - 1; ) ; execute (ith_term)->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSum(arr,n): result=0 count_odd=0 count_even=0 for i in range(1,n+1): if(arr[i-1]% 2==0): count_even=count_even+count_even+1 count_odd=count_odd+count_odd else : temp=count_even count_even=count_even+count_odd count_odd=count_odd+temp+1 return(count_even,count_odd) arr=[1,2,2,3]; n=len(arr) count_even,count_odd=countSum(arr,n); print("EvenSum=",count_even," OddSum=",count_odd) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 3 }))); ; n := (arr)->size() ; Sequence{count_even,count_odd} := countSum(arr, n); ; execute ("EvenSum=")->display(); operation countSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; var count_odd : int := 0 ; var count_even : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( if (arr[i - 1+1] mod 2 = 0) then ( count_even := count_even + count_even + 1 ; count_odd := count_odd + count_odd ) else ( var temp : int := count_even ; count_even := count_even + count_odd ; count_odd := count_odd + temp + 1 )) ; return Sequence{count_even, count_odd}; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cntSubArrays(arr,n,k): res=0 ; i=0 ; while(i=arr[j-1]): j+=1 ; res+=max(j-i-k+1,0); i=j ; return res ; if __name__=="__main__" : arr=[1,2,3,2,5]; n=len(arr); k=2 ; print(cntSubArrays(arr,n,k)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 5 })))); ; n := (arr)->size(); ; k := 2; ; execute (cntSubArrays(arr, n, k))->display(); ) else skip; operation cntSubArrays(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var res : int := 0; ; var i : int := 0; ; while ((i->compareTo(n)) < 0) do ( var j : int := i + 1; ; while ((j->compareTo(n)) < 0 & (arr[j+1]->compareTo(arr[j - 1+1])) >= 0) do ( j := j + 1;) ; res := res + Set{j - i - k + 1, 0}->max(); ; i := j;) ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def digitsNum(N): if(N==0): print("0",end="") if(N % 9!=0): print(N % 9,end="") for i in range(1,int(N/9)+1): print("9",end="") for i in range(1,N+1): print("0",end="") print() N=5 print("The number is : ",end="") digitsNum(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; N := 5 ; execute ("The number is : ")->display() ; digitsNum(N); operation digitsNum(N : OclAny) pre: true post: true activity: if (N = 0) then ( execute ("0")->display() ) else skip ; if (N mod 9 /= 0) then ( execute (N mod 9)->display() ) else skip ; for i : Integer.subrange(1, ("" + ((N / 9)))->toInteger() + 1-1) do ( execute ("9")->display()) ; for i : Integer.subrange(1, N + 1-1) do ( execute ("0")->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution : def maximum69Number(self,num : int)->int : return(str(num).replace('6','9',1)) ------------------------------------------------------------ OCL File: --------- class Solution { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation maximum69Number(num : int) : int pre: true post: true activity: return (OclType["String"](num).replace('6', '9', 1)); } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l1=sorted(list(map(int,input().split()))) m=int(input()) l2=sorted(list(map(int,input().split()))) print(l1[-1],l2[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; execute (l1->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,radians from heapq import heappop,heappush,heapify,heappushpop from itertools import permutations,combinations,product,accumulate from operator import itemgetter,mul from copy import deepcopy from string import ascii_lowercase,ascii_uppercase,digits def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) sys.setrecursionlimit(10**9) INF=float('inf') MOD=10**9+7 n=INT() slp=[LIST()for _ in range(n)] m=INT() w=[INT()for _ in range(m)] dp=[0]*394 v=[0]*394 for s,l,p in slp : for x in range(s,l+1): v[x]=max(v[x],p) for i in range(394): for j in range(i+1): dp[i]=max(dp[i],dp[i-j]+v[j]) ans=[] for i in w : if dp[i]==0 : print(-1) break else : ans.append(dp[i]) else : print(*ans,sep="\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; var n : OclAny := INT() ; var slp : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LIST())) ; var m : OclAny := INT() ; var w : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (INT())) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 394) ; var v : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 394) ; for _tuple : slp do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var l : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p : OclAny := _tuple->at(_indx); for x : Integer.subrange(s, l + 1-1) do ( v[x+1] := Set{v[x+1], p}->max())) ; for i : Integer.subrange(0, 394-1) do ( for j : Integer.subrange(0, i + 1-1) do ( dp[i+1] := Set{dp[i+1], dp[i - j+1] + v[j+1]}->max())) ; var ans : Sequence := Sequence{} ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name w))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom (name ans))))))) , (argument (test (logical_test (comparison (expr (atom (name sep)))))) = (test (logical_test (comparison (expr (atom "\n"))))))) ))))))))))))))); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l1=list(map(int,input().split()))[: n] m=int(input()) l2=list(map(int,input().split()))[: m] l3=l1+l2 l4=[] for i in range(len(l1)): for j in range(len(l2)): k=l1[i]+l2[j] if k not in l3 : l4.append(l1[i]) l4.append(l2[j]) print(l4[0],end=' ') print(l4[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l1 : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l2 : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,m) ; var l3 : OclAny := l1 + l2 ; var l4 : Sequence := Sequence{} ; for i : Integer.subrange(0, (l1)->size()-1) do ( for j : Integer.subrange(0, (l2)->size()-1) do ( var k : OclAny := l1[i+1] + l2[j+1] ; if (l3)->excludes(k) then ( execute ((l1[i+1]) : l4) ; execute ((l2[j+1]) : l4) ) else skip)) ; execute (l4->first())->display() ; execute (l4[1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(*(max(map(int,input()and input().split()))for _ in '00')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( )))))) and (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( )))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom '00')))))) ))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a_matrix=input().split() a_matrix=[int(num)for num in a_matrix] m=int(input()) b_matrix=input().split() b_matrix=[int(num)for num in b_matrix] print(f"{max(a_matrix)}{max(b_matrix)}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a_matrix : OclAny := input().split() ; a_matrix := a_matrix->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b_matrix : OclAny := input().split() ; b_matrix := b_matrix->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; execute (StringLib.formattedString("{max(a_matrix)}{max(b_matrix)}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) m=int(input()) b=list(map(int,input().split())) a=sorted(a) b=sorted(b) print(a[-1],b[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; b := b->sort() ; execute (a->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,k=map(int,input().split()) s=list(input().rstrip()) s.sort() ans=0 la=0 for i in s : if la+1collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := (input().rstrip()) ; s := s->sort() ; var ans : int := 0 ; var la : int := 0 ; for i : s do ( if (la + 1->compareTo(i)) < 0 then ( la := i ; ans := ans + i - 96 ; k := k - 1 ) else skip ; if not(k) then ( break ) else skip) ; if k then ( ans := -1 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) w=p=0 for c in map(ord,sorted((input()))): if c-p>1 : w+=c-96 ; p=c ; k-=1 if k==0 : break print((w,-1)[k>0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : OclAny := 0; var p : int := 0 ; for c : (((OclFile["System.in"]).readLine())->sort())->collect( _x | (ord)->apply(_x) ) do ( if c - p > 1 then ( w := w + c - 96; p := c; k := k - 1 ) else skip ; if k = 0 then ( break ) else skip) ; execute (Sequence{w, -1}->select(k > 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : l,r=0,int(input()) if r==0 : break a=[int(input())for _ in range(r)] r-=1 ; c=0 k=int(input()) while l<=r : c+=1 m=(l+r)//2 if a[m]==k : break if a[m]toInteger()} ; if r = 0 then ( break ) else skip ; var a : Sequence := Integer.subrange(0, r-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; r := r - 1; var c : int := 0 ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (l->compareTo(r)) <= 0 do ( c := c + 1 ; var m : int := (l + r) div 2 ; if a[m+1] = k then ( break ) else skip ; if (a[m+1]->compareTo(k)) < 0 then ( var l : int := m + 1 ) else ( var r : double := m - 1 )) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def algo(chaine,num): trier=sorted(chaine) liste=[ord(a)-96 for a in trier] somme=sum(liste) if(num>len(liste)): return-1 c=1 n=liste[0] for k in range(len(liste)-1): if(n+1first())))->toInteger() ; var k : int := ("" + ((a[1+1])))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var news : Sequence := Sequence{} ; var ans : OclAny := algo(s, k) ; execute (ans)->display(); operation algo(chaine : OclAny, num : OclAny) : OclAny pre: true post: true activity: var trier : Sequence := chaine->sort() ; var liste : Sequence := trier->select(a | true)->collect(a | ((a)->char2byte() - 96)) ; var somme : OclAny := (liste)->sum() ; if ((num->compareTo((liste)->size())) > 0) then ( return -1 ) else skip ; var c : int := 1 ; var n : OclAny := liste->first() ; for k : Integer.subrange(0, (liste)->size() - 1-1) do ( if ((n + 1->compareTo(liste[k + 1+1])) < 0) then ( c := c + 1 ; n := liste[k+1] ) else skip) ; if ((c->compareTo(num)) < 0) then ( return -1 ) else skip ; var arr : Sequence := Sequence{} ; var count : int := -1 ; for i : Integer.subrange(0, (liste)->size()-1) do ( if (arr)->includes(liste[i+1]) then ( continue ) else skip ; if liste[i+1] = count + 1 then ( continue ) else skip ; execute ((liste[i+1]) : arr) ; count := liste[i+1] ; if (arr)->size() = num then ( break ) else skip) ; if (arr)->size() /= num then ( return -1 ) else skip ; return (arr)->sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) w=p=0 for c in map(ord,sorted((input()))): if c-p>1 : w+=c-96 ; p=c ; k-=1 if k==0 : break print((w,-1)[k>0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : OclAny := 0; var p : int := 0 ; for c : (((OclFile["System.in"]).readLine())->sort())->collect( _x | (ord)->apply(_x) ) do ( if c - p > 1 then ( w := w + c - 96; p := c; k := k - 1 ) else skip ; if k = 0 then ( break ) else skip) ; execute (Sequence{w, -1}->select(k > 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys I=lambda :[*map(int,sys.stdin.readline().split())] IS=lambda : input() IN=lambda : int(input()) IF=lambda : float(input()) n,k,=map(int,input().split()) s=IS() d=[False]*26 for i in s : d[ord(i)-ord('a')]=True w=0 l=0 i=0 while i<26 and lcollect( _x | (OclType["int"])->apply(_x) )) ; var IS : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var IN : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var IF : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toReal()) ; var n : OclAny := null; (declareIfNecessary (test (logical_test (comparison (expr (atom (name k)))))) ,) Sequence{n,(testlist_star_expr (test (logical_test (comparison (expr (atom (name k)))))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := IS->apply() ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, 26) ; for i : s do ( d[(i)->char2byte() - ('a')->char2byte()+1] := true) ; var w : int := 0 ; var l : int := 0 ; var i : int := 0 ; while i < 26 & (l->compareTo(k)) < 0 do ( if d[i+1] then ( w := w + i + 1 ; l := l + 1 ; i := i + 2 ) else ( i := i + 1 )) ; execute (if l = k then w else -1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) s=[] l=[] p=[] for _ in range(N): temp_s,temp_l,temp_p=map(int,input().split()) s.append(temp_s) l.append(temp_l) p.append(temp_p) M=int(input()) w=[int(input())for _ in range(M)] max_M=max(w) dp=[[-1 for _ in range(max_M+1)]for _ in range(N+1)] for i in range(N): for j in range(s[i],min(l[i]+1,max_M+1)): dp[i+1][j]=p[i] for i in range(N): for j in range(max_M+1): if j=s[i]: if dp[i+1][j-s[i]]==-1 : dp[i+1][j]=max(dp[i+1][j],dp[i][j]) else : dp[i+1][j]=max(dp[i+1][j],dp[i][j],dp[i+1][j-s[i]]+p[i]) ans=[] for i in range(M): ans.append(dp[N][w[i]]) if ans.count(-1)>=1 : print(-1) else : for a in ans : print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := Sequence{} ; var l : Sequence := Sequence{} ; var p : Sequence := Sequence{} ; for _anon : Integer.subrange(0, N-1) do ( var temp_s : OclAny := null; var temp_l : OclAny := null; var temp_p : OclAny := null; Sequence{temp_s,temp_l,temp_p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((temp_s) : s) ; execute ((temp_l) : l) ; execute ((temp_p) : p)) ; var M : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var max_M : OclAny := (w)->max() ; var dp : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, max_M + 1-1)->select(_anon | true)->collect(_anon | (-1)))) ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(s[i+1], Set{l[i+1] + 1, max_M + 1}->min()-1) do ( dp[i + 1+1][j+1] := p[i+1])) ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, max_M + 1-1) do ( if (j->compareTo(s[i+1])) < 0 then ( dp[i + 1+1][j+1] := Set{dp[i + 1+1][j+1], dp[i+1][j+1]}->max() ) else (if (j->compareTo(s[i+1])) >= 0 then ( if dp[i + 1+1][j - s[i+1]+1] = -1 then ( dp[i + 1+1][j+1] := Set{dp[i + 1+1][j+1], dp[i+1][j+1]}->max() ) else ( dp[i + 1+1][j+1] := Set{dp[i + 1+1][j+1], dp[i+1][j+1], dp[i + 1+1][j - s[i+1]+1] + p[i+1]}->max() ) ) else skip))) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, M-1) do ( execute ((dp[N+1][w[i+1]+1]) : ans)) ; if ans->count(-1) >= 1 then ( execute (-1)->display() ) else ( for a : ans do ( execute (a)->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- EPS=1e-7 while True : d=float(input()) if d==0 : break px,py,vx,vy=map(float,input().split()) ans=d+1 dp=(px*px+py*py)**0.5 dv=(vx*vx+vy*vy)**0.5 x=(px*vx+py*vy)/(dp*dv) if abs(x+1)<=EPS : ans=dp elif abs(1-x)<=EPS : ans=2-dp print(ans if abs(ans-d)<=EPS or ans<=d else "impossible") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var EPS : double := ("1e-7")->toReal() ; while true do ( var d : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; if d = 0 then ( break ) else skip ; var px : OclAny := null; var py : OclAny := null; var vx : OclAny := null; var vy : OclAny := null; Sequence{px,py,vx,vy} := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; var ans : OclAny := d + 1 ; var dp : double := ((px * px + py * py))->pow(0.5) ; var dv : double := ((vx * vx + vy * vy))->pow(0.5) ; var x : double := (px * vx + py * vy) / (dp * dv) ; if ((x + 1)->abs()->compareTo(EPS)) <= 0 then ( ans := dp ) else (if ((1 - x)->abs()->compareTo(EPS)) <= 0 then ( ans := 2 - dp ) else skip) ; execute (if ((ans - d)->abs()->compareTo(EPS)) <= 0 or (ans->compareTo(d)) <= 0 then ans else "impossible" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin def solve(): file_input=stdin while True : D=float(file_input.readline()) if D==0 : break px,py,vx,vy=map(float,file_input.readline().split()) if px*vy-py*vx==0 : OP=(px**2+py**2)**0.5 if px*vx+py*vy<0 : if OP<=D : print(OP) else : print('impossible') else : d=2-OP if d<=D : print(d) else : print('impossible') else : print('impossible') solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; solve(); operation solve() pre: true post: true activity: var file_input : OclAny := stdin ; while true do ( var D : double := ("" + ((file_input.readLine())))->toReal() ; if D = 0 then ( break ) else skip ; var px : OclAny := null; var py : OclAny := null; var vx : OclAny := null; var vy : OclAny := null; Sequence{px,py,vx,vy} := (file_input.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ) ; if px * vy - py * vx = 0 then ( var OP : double := (((px)->pow(2) + (py)->pow(2)))->pow(0.5) ; if px * vx + py * vy < 0 then ( if (OP->compareTo(D)) <= 0 then ( execute (OP)->display() ) else ( execute ('impossible')->display() ) ) else ( var d : double := 2 - OP ; if (d->compareTo(D)) <= 0 then ( execute (d)->display() ) else ( execute ('impossible')->display() ) ) ) else ( execute ('impossible')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def exponentMod(A,B,C): if(A==0): return 0 if(B==0): return 1 y=0 if(B % 2==0): y=exponentMod(A,B/2,C) y=(y*y)% C else : y=A % C y=(y*exponentMod(A,B-1,C)% C)% C return((y+C)% C) A=2 B=5 C=13 print("Power is",exponentMod(A,B,C)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; A := 2 ; B := 5 ; C := 13 ; execute ("Power is")->display(); operation exponentMod(A : OclAny, B : OclAny, C : OclAny) : OclAny pre: true post: true activity: if (A = 0) then ( return 0 ) else skip ; if (B = 0) then ( return 1 ) else skip ; var y : int := 0 ; if (B mod 2 = 0) then ( y := exponentMod(A, B / 2, C) ; y := (y * y) mod C ) else ( y := A mod C ; y := (y * exponentMod(A, B - 1, C) mod C) mod C ) ; return ((y + C) mod C); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import defaultdict as dd input=sys.stdin.readline N=int(input()) a=list(map(int,input().split())) d=dd(int) l=dd(lambda : N+1) for i in range(N): d[a[i]]+=1 l[a[i]]=min(l[a[i]],i+1) ks=sorted(d.keys(),reverse=True) res=[0]*(N+1) for i in range(len(ks)-1): t=ks[i]-ks[i+1] k=ks[i] res[l[k]]+=d[k]*t d[ks[i+1]]+=d[k] l[ks[i+1]]=min(l[ks[i+1]],l[k]) res[1]+=d[ks[-1]]*ks[-1] for r in res[1 :]: print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := dd(OclType["int"]) ; var l : OclAny := dd(lambda $$ : OclAny in (N + 1)) ; for i : Integer.subrange(0, N-1) do ( d[a[i+1]+1] := d[a[i+1]+1] + 1 ; l[a[i+1]+1] := Set{l[a[i+1]+1], i + 1}->min()) ; var ks : Sequence := d.keys()->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var res : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; for i : Integer.subrange(0, (ks)->size() - 1-1) do ( var t : double := ks[i+1] - ks[i + 1+1] ; var k : OclAny := ks[i+1] ; res[l[k+1]+1] := res[l[k+1]+1] + d[k+1] * t ; d[ks[i + 1+1]+1] := d[ks[i + 1+1]+1] + d[k+1] ; l[ks[i + 1+1]+1] := Set{l[ks[i + 1+1]+1], l[k+1]}->min()) ; res[1+1] := res[1+1] + d[ks->last()+1] * ks->last() ; for r : res->tail() do ( execute (r)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(raw_input()) a=[[int(k),i+1]for i,k in enumerate(raw_input().split())] a.sort(reverse=True) z=[l[1]for l in a] s=[0]*n a.append([0,0]) min_a_i=float('inf') for i,p in enumerate(a[:-1]): min_a_i=min(min_a_i,a[i][1]) if not p[0]==a[i+1][0]: q=p[0]-a[i+1][0] s[min_a_i-1]+=(i+1)*q for t in s : print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + ((raw_input())))->toInteger() ; var a : Sequence := Integer.subrange(1, (raw_input().split())->size())->collect( _indx | Sequence{_indx-1, (raw_input().split())->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let k : OclAny = _tuple->at(2) in (Sequence{("" + ((k)))->toInteger()}->union(Sequence{ i + 1 }))) ; a := a->sort() ; var z : Sequence := a->select(l | true)->collect(l | (l[1+1])) ; var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; execute ((Sequence{0}->union(Sequence{ 0 })) : a) ; var min_a_i : double := ("" + (('inf')))->toReal() ; for _tuple : Integer.subrange(1, (a->front())->size())->collect( _indx | Sequence{_indx-1, (a->front())->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p : OclAny := _tuple->at(_indx); min_a_i := Set{min_a_i, a[i+1][1+1]}->min() ; if not(p->first() = a[i + 1+1]->first()) then ( var q : double := p->first() - a[i + 1+1]->first() ; s[min_a_i - 1+1] := s[min_a_i - 1+1] + (i + 1) * q ) else skip) ; for t : s do ( execute (t)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) int1=lambda x : int(x)-1 p2D=lambda x : print(*x,sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int,sys.stdin.readline().split()) def LI(): return list(map(int,sys.stdin.readline().split())) def LLI(rows_number): return[LI()for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] def main(): n=II() aa=LI() bot=[] mx=0 for i,a in enumerate(aa): if a>mx : bot.append((mx,i)) mx=a aa.sort() ans=[0]*n j=n s=0 fin=0 for mx,i in bot[: :-1]: while j>0 and aa[j-1]>mx : j-=1 s+=aa[j] ans[i]=s-(n-j)*mx-fin fin+=ans[i] print(*ans,sep="\n") main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; var p2D : Function := lambda x : OclAny in (((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ; skip ; skip ; skip ; skip ; skip ; skip ; main(); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LLI(rows_number : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows_number-1)->select(_anon | true)->collect(_anon | (LI())); operation SI() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation main() pre: true post: true activity: var n : OclAny := II() ; var aa : OclAny := LI() ; var bot : Sequence := Sequence{} ; var mx : int := 0 ; for _tuple : Integer.subrange(1, (aa)->size())->collect( _indx | Sequence{_indx-1, (aa)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); if (a->compareTo(mx)) > 0 then ( execute ((Sequence{mx, i}) : bot) ; mx := a ) else skip) ; aa := aa->sort() ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var j : OclAny := n ; var s : int := 0 ; var fin : int := 0 ; for _tuple : bot(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do (var _indx : int := 1; var mx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); while j > 0 & (aa[j - 1+1]->compareTo(mx)) > 0 do ( j := j - 1 ; s := s + aa[j+1]) ; ans[i+1] := s - (n - j) * mx - fin ; fin := fin + ans[i+1]) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lis=list(map(int,input().split())) key=lis[0] num=[0] li=[key] for i in range(1,n): if lis[i]>key : key=lis[i] num.append(i) li.append(key) m=len(li) nu=[li[0]]+[li[i+1]-li[i]for i in range(m-1)] he=[0]*m cou=[0]*m from bisect import bisect_left for k in lis : sen=bisect_left(li,k) cou[sen]+=k-li[sen] he[sen]+=1 key=0 for i in reversed(range(m)): key+=he[i] he[i]=key for i in range(m): cou[i]+=he[i]*nu[i] ans=[0]*n for i,c in zip(num,cou): ans[i]=c for r in ans : print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lis : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var key : OclAny := lis->first() ; var num : Sequence := Sequence{ 0 } ; var li : Sequence := Sequence{ key } ; for i : Integer.subrange(1, n-1) do ( if (lis[i+1]->compareTo(key)) > 0 then ( key := lis[i+1] ; execute ((i) : num) ; execute ((key) : li) ) else skip) ; var m : int := (li)->size() ; var nu : Sequence := Sequence{ li->first() }->union(Integer.subrange(0, m - 1-1)->select(i | true)->collect(i | (li[i + 1+1] - li[i+1]))) ; var he : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; var cou : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; skip ; for k : lis do ( var sen : OclAny := bisect_left(li, k) ; cou[sen+1] := cou[sen+1] + k - li[sen+1] ; he[sen+1] := he[sen+1] + 1) ; key := 0 ; for i : (Integer.subrange(0, m-1))->reverse() do ( key := key + he[i+1] ; he[i+1] := key) ; for i : Integer.subrange(0, m-1) do ( cou[i+1] := cou[i+1] + he[i+1] * nu[i+1]) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for _tuple : Integer.subrange(1, num->size())->collect( _indx | Sequence{num->at(_indx), cou->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); ans[i+1] := c) ; for r : ans do ( execute (r)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def search(data,key): cnt=0 left,right=-1,len(data) while right-left>1 : mid=(left+right)//2 cnt+=1 if data[mid]==key : break elif data[mid]>key : right=mid else : left=mid return cnt def solve(): N=int(input()) if N==0 : return-1 data=[int(input())for i in range(N)] k=int(input()) return search(data,k) while True : ans=solve() if ans==-1 : break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( var ans : OclAny := solve() ; if ans = -1 then ( break ) else skip ; execute (ans)->display()); operation search(data : OclAny, key : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; var left : OclAny := null; var right : OclAny := null; Sequence{left,right} := Sequence{-1,(data)->size()} ; while right - left > 1 do ( var mid : int := (left + right) div 2 ; cnt := cnt + 1 ; if data[mid+1] = key then ( break ) else (if (data[mid+1]->compareTo(key)) > 0 then ( var right : int := mid ) else ( var left : int := mid ) ) ) ; return cnt; operation solve() : OclAny pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( return -1 ) else skip ; data := Integer.subrange(0, N-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; return search(data, k); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N,*A=map(int,open(0).read().split()) L,C={},{} for i,a in enumerate(A): if a in C : C[a]+=1 else : C[a]=1 L[a]=i Z=[0]*N B=sorted(C,reverse=True) l=N-1 cnt=0 for b,c in zip(B,B[1 :]+[0]): l=min(l,L[b]) cnt+=C[b] Z[l]+=(b-c)*cnt print(*Z,sep="\n") if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; Sequence{N,A} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var L : OclAny := null; var C : OclAny := null; Sequence{L,C} := Sequence{Set{},Set{}} ; for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); if (C)->includes(a) then ( C[a+1] := C[a+1] + 1 ) else ( C[a+1] := 1 ; L[a+1] := i )) ; var Z : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var B : Sequence := C->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var l : double := N - 1 ; var cnt : int := 0 ; for _tuple : Integer.subrange(1, B->size())->collect( _indx | Sequence{B->at(_indx), B->tail()->union(Sequence{ 0 })->at(_indx)} ) do (var _indx : int := 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); l := Set{l, L[b+1]}->min() ; cnt := cnt + C[b+1] ; Z[l+1] := Z[l+1] + (b - c) * cnt) ; execute ((argument * (test (logical_test (comparison (expr (atom (name Z))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): n=int(input()) arr=[] for _ in range(n): a,b=map(int,input().split()) arr.append((a,b)) home_freq=Counter([x for x,_ in arr]) for val in arr : away_home=home_freq[val[1]] print(n-1+away_home,n-1-away_home) def main(): t=1 for _ in range(t): solution() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; main(); operation solution() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a, b}) : arr)) ; var home_freq : OclAny := Counter(arr->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let _anon : OclAny = _tuple->at(2) in (x))) ; for val : arr do ( var away_home : OclAny := home_freq[val[1+1]+1] ; execute (n - 1 + away_home)->display()); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import deque input=sys.stdin.buffer.readline N=int(input()) adj=[[]for _ in range(N+1)] for _ in range(N-1): a,b=map(int,input().split()) adj[a].append(b) adj[b].append(a) que=deque() que.append(1) seen=[0]*(N+1) seen[1]=1 par=[0]*(N+1) child_num=[0]*(N+1) while que : v=que.popleft() for u in adj[v]: if seen[u]==0 : seen[u]=1 par[u]=v child_num[v]+=1 que.append(u) seq=deque() for i in range(1,N+1): if child_num[i]==0 : seq.append(i) while seq : c=seq.pop() seen[c]=0 if seen[par[c]]==0 : print('First') exit() seen[par[c]]=0 child_num[par[par[c]]]-=1 if child_num[par[par[c]]]==0 : seq.append(par[par[c]]) print('Second') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := sys.stdin.buffer.readline ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var adj : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, N - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var que : Sequence := () ; execute ((1) : que) ; var seen : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; seen[1+1] := 1 ; var par : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; var child_num : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; while que do ( var v : OclAny := que->first() ; que := que->tail() ; for u : adj[v+1] do ( if seen[u+1] = 0 then ( seen[u+1] := 1 ; par[u+1] := v ; child_num[v+1] := child_num[v+1] + 1 ; execute ((u) : que) ) else skip)) ; var seq : Sequence := () ; for i : Integer.subrange(1, N + 1-1) do ( if child_num[i+1] = 0 then ( execute ((i) : seq) ) else skip) ; while seq do ( var c : OclAny := seq->last() ; seq := seq->front() ; seen[c+1] := 0 ; if seen[par[c+1]+1] = 0 then ( execute ('First')->display() ; exit() ) else skip ; seen[par[c+1]+1] := 0 ; child_num[par[par[c+1]+1]+1] := child_num[par[par[c+1]+1]+1] - 1 ; if child_num[par[par[c+1]+1]+1] = 0 then ( execute ((par[par[c+1]+1]) : seq) ) else skip) ; execute ('Second')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) teams=[] result=[[n-1,0]for i in range(n)] colors={} for i in range(n): x,y=[int(i)for i in input().split()] colors[x]=colors.get(x,0)+1 teams.append([x,y]) for i in range(n): x_away,y_away=teams[i] value=colors.get(y_away)if colors.get(y_away)is not None else 0 result[i][0]+=value result[i][1]+=n-1-value for i in result : print(*i) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var teams : Sequence := Sequence{} ; var result : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{n - 1}->union(Sequence{ 0 }))) ; var colors : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; colors[x+1] := colors.get(x, 0) + 1 ; execute ((Sequence{x}->union(Sequence{ y })) : teams)) ; for i : Integer.subrange(0, n-1) do ( var x_away : OclAny := null; var y_away : OclAny := null; Sequence{x_away,y_away} := teams[i+1] ; var value : OclAny := if not(colors.get(y_away) <>= null) then colors.get(y_away) else 0 endif ; result[i+1]->first() := result[i+1]->first() + value ; result[i+1][1+1] := result[i+1][1+1] + n - 1 - value) ; for i : result do ( execute ((argument * (test (logical_test (comparison (expr (atom (name i))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) teams=[] result=[[n-1,0]for i in range(n)] colors={} for i in range(n): x,y=[int(i)for i in input().split()] colors[x]=colors.get(x,0)+1 teams.append([x,y]) for i in range(n): x_away,y_away=teams[i] value=colors.get(y_away)if colors.get(y_away)is not None else 0 result[i][0]+=value result[i][1]+=n-1-value for i in result : print(*i) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var teams : Sequence := Sequence{} ; var result : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{n - 1}->union(Sequence{ 0 }))) ; var colors : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; colors[x+1] := colors.get(x, 0) + 1 ; execute ((Sequence{x}->union(Sequence{ y })) : teams)) ; for i : Integer.subrange(0, n-1) do ( var x_away : OclAny := null; var y_away : OclAny := null; Sequence{x_away,y_away} := teams[i+1] ; var value : OclAny := if not(colors.get(y_away) <>= null) then colors.get(y_away) else 0 endif ; result[i+1]->first() := result[i+1]->first() + value ; result[i+1][1+1] := result[i+1][1+1] + n - 1 - value) ; for i : result do ( execute ((argument * (test (logical_test (comparison (expr (atom (name i))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[0 for i in range(n)] x=[0 for i in range(100001)] for i in range(n): s,a[i]=map(int,input().split()) x[s]+=1 for i in range(n): print(n-1+x[a[i]],n-1-x[a[i]]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var x : Sequence := Integer.subrange(0, 100001-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( var s : OclAny := null; var a[i+1] : OclAny := null; Sequence{s,a[i+1]} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; x[s+1] := x[s+1] + 1) ; for i : Integer.subrange(0, n-1) do ( execute (n - 1 + x[a[i+1]+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=[0]*n q=[0]*100001 for i in range(n): x,y=map(int,input().split()) p[i]=y q[x]+=1 for i in range(n): k=q[p[i]] p[i]=str(n-1+k)+' '+str(n-1-k) print('\n'.join(p)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var q : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100001) ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; p[i+1] := y ; q[x+1] := q[x+1] + 1) ; for i : Integer.subrange(0, n-1) do ( var k : OclAny := q[p[i+1]+1] ; p[i+1] := ("" + ((n - 1 + k))) + ' ' + ("" + ((n - 1 - k)))) ; execute (StringLib.sumStringsWithSeparator((p), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from string import ascii_lowercase from bisect import bisect def solve(s): pos=[[]for _ in range(26)] offset=ord('a') for i,c in enumerate(s): c=ord(c)-offset pos[c].append(i) for l in pos : l.append(len(s)) all_char_sequence_start_pos=[] pos_i=[len(l)-1 for l in pos] while all(pi>=0 for pi in pos_i): i=min(l[pi]for pi,l in zip(pos_i,pos)) all_char_sequence_start_pos.append(i) for j in range(26): while pos_i[j]>=0 and pos[j][pos_i[j]]>=i : pos_i[j]-=1 all_char_sequence_start_pos.reverse() ans=[] curr=-1 for i in all_char_sequence_start_pos : for c in range(26): cj=bisect(pos[c],curr) j=pos[c][cj] if j>=i : ans.append(c) curr=j break return ''.join(chr(c+offset)for c in ans) print(solve(input().strip())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; execute (solve(input()->trim()))->display(); operation solve(s : OclAny) : OclAny pre: true post: true activity: var pos : Sequence := Integer.subrange(0, 26-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var offset : int := ('a')->char2byte() ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); var c : double := (c)->char2byte() - offset ; (expr (atom (name pos)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name c)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; for l : pos do ( execute (((s)->size()) : l)) ; var all_char_sequence_start_pos : Sequence := Sequence{} ; var pos_i : Sequence := pos->select(l | true)->collect(l | ((l)->size() - 1)) ; while ((argument (test (logical_test (comparison (comparison (expr (atom (name pi)))) >= (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name pi)))) in (logical_test (comparison (expr (atom (name pos_i))))))))->forAll( _x | _x = true ) do ( var i : OclAny := ((argument (test (logical_test (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name pi)))))))) ])))))) (comp_for for (exprlist (expr (atom (name pi))) , (expr (atom (name l)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name pos_i))))))) , (argument (test (logical_test (comparison (expr (atom (name pos)))))))) )))))))))->min() ; execute ((i) : all_char_sequence_start_pos) ; for j : Integer.subrange(0, 26-1) do ( while pos_i[j+1] >= 0 & (pos[j+1][pos_i[j+1]+1]->compareTo(i)) >= 0 do ( pos_i[j+1] := pos_i[j+1] - 1))) ; all_char_sequence_start_pos := all_char_sequence_start_pos->reverse() ; var ans : Sequence := Sequence{} ; var curr : int := -1 ; for i : all_char_sequence_start_pos do ( for c : Integer.subrange(0, 26-1) do ( var cj : OclAny := bisect(pos[c+1], curr) ; var j : OclAny := pos[c+1][cj+1] ; if (j->compareTo(i)) >= 0 then ( execute ((c) : ans) ; curr := j ; break ) else skip)) ; return StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name chr)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name c))) + (expr (atom (name offset))))))))) ))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name ans)))))))), ''); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 gosa=1.0/10**10 mod=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def main(): a=S() l=len(a) t={} for c in string.ascii_lowercase : t[c]=l b=[(1,0,0)for _ in range(l)] b.append((1,'a',l)) b.append((0,'',l+1)) for c,i in reversed(list(zip(a,range(l)))): t[c]=i b[i]=min([(b[t[d]+1][0]+1,d,t[d]+1)for d in string.ascii_lowercase]) r='' i=0 while ipow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var gosa : double := 1.0 / (10)->pow(10) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation main() : OclAny pre: true post: true activity: var a : OclAny := S() ; var l : int := (a)->size() ; var t : OclAny := Set{} ; for c : string.ascii_lowercase do ( t[c+1] := l) ; var b : Sequence := Integer.subrange(0, l-1)->select(_anon | true)->collect(_anon | (Sequence{1, 0, 0})) ; execute ((Sequence{1, 'a', l}) : b) ; execute ((Sequence{0, '', l + 1}) : b) ; for _tuple : ((Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), Integer.subrange(0, l-1)->at(_indx)} )))->reverse() do (var _indx : int := 1; var c : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); t[c+1] := i ; b[i+1] := (string.ascii_lowercase->select(d | true)->collect(d | (Sequence{b[t[d+1] + 1+1]->first() + 1, d, t[d+1] + 1})))->min()) ; var r : String := '' ; var i : int := 0 ; while (i->compareTo(l)) < 0 do ( r := r + b[i+1][1+1] ; i := b[i+1][2+1]) ; return r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline A=input().rstrip() dp=[chr(c)for c in range(ord('a'),ord('z')+1)] for c in A[: :-1]: s=min(dp,key=lambda x : len(x)) dp[ord(c)-ord('a')]=c+s print(min(dp,key=lambda x : len(x))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var A : OclAny := input().rstrip() ; var dp : Sequence := Integer.subrange(('a')->char2byte(), ('z')->char2byte() + 1-1)->select(c | true)->collect(c | ((c)->byte2char())) ; for c : A(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( var s : OclAny := Set{dp, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))))))))}->min() ; dp[(c)->char2byte() - ('a')->char2byte()+1] := c + s) ; execute (Set{dp, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))))))))}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left CHARACTERs='abcdefghijklmnopqrstuvwxyz' As=input() lenA=len(As) posChars=dict([(ch,[lenA])for ch in CHARACTERs]) dp=[0]*lenA+[1,0] for i in reversed(range(lenA)): posChars[As[i]].append(i) dp[i]=min([dp[posChars[ch][-1]+1]for ch in CHARACTERs])+1 for ch in CHARACTERs : posChars[ch]=posChars[ch][: :-1] ans=[] i=0 for k in reversed(range(dp[0])): for ch in CHARACTERs : pos=posChars[ch][bisect_left(posChars[ch],i)] if dp[pos+1]==k : ans.append(ch) i=pos+1 break print(''.join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var CHARACTERs : String := 'abcdefghijklmnopqrstuvwxyz' ; var As : String := (OclFile["System.in"]).readLine() ; var lenA : int := (As)->size() ; var posChars : Map := ((atom [ (testlist_comp (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name ch)))))) , (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name lenA))))))) ])))))) )))))) (comp_for for (exprlist (expr (atom (name ch)))) in (logical_test (comparison (expr (atom (name CHARACTERs))))))) ])) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, lenA)->union(Sequence{1}->union(Sequence{ 0 })) ; for i : (Integer.subrange(0, lenA-1))->reverse() do ((expr (atom (name posChars)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name As)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ; dp[i+1] := (CHARACTERs->characters()->select(ch | true)->collect(ch | (dp[posChars[ch+1]->last() + 1+1])))->min() + 1) ; for ch : CHARACTERs->characters() do ( posChars[ch+1] := posChars[ch+1](subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ; var ans : Sequence := Sequence{} ; var i : int := 0 ; for k : (Integer.subrange(0, dp->first()-1))->reverse() do ( for ch : CHARACTERs->characters() do ( var pos : OclAny := posChars[ch+1][bisect_left(posChars[ch+1], i)+1] ; if dp[pos + 1+1] = k then ( execute ((ch) : ans) ; i := pos + 1 ; break ) else skip)) ; execute (StringLib.sumStringsWithSeparator((ans), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,bisect PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") def search(n,A,s): cnt=0 left,right=0,n-1 while left<=right : mid=(left+right)//2 cnt+=1 if A[mid]==s : return cnt elif A[mid]>s : right=mid-1 else : left=mid+1 return cnt while True : n=int(input()) if n==0 : break A=[int(input())for _ in range(n)] s=int(input()) print(search(n,A,s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; skip ; while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; A := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; s := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (search(n, A, s))->display()); operation search(n : OclAny, A : OclAny, s : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; var left : OclAny := null; var right : OclAny := null; Sequence{left,right} := Sequence{0,n - 1} ; while (left->compareTo(right)) <= 0 do ( var mid : int := (left + right) div 2 ; cnt := cnt + 1 ; if A[mid+1] = s then ( return cnt ) else (if (A[mid+1]->compareTo(s)) > 0 then ( var right : double := mid - 1 ) else ( var left : int := mid + 1 ) ) ) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): import sys input=sys.stdin.readline s=input() alpha="abcdefghijklmnopqrstuvwxyz" l=len(s) alpha2={j : i for i,j in enumerate(alpha)} memo=[[0]*26 for _ in range(l,-1,-1)] for i in range(26): memo[l][i]=l+1 for i in range(l-1,-1,-1): for x,y in alpha2.items(): if s[i]==x : memo[i][y]=i+1 else : memo[i][y]=memo[i+1][y] search=[1]*(l+2) search[l+1]=0 for i in range(l-1,-1,-1): m=max([memo[i][j]for j in range(26)]) if m!=l+1 : search[i]=search[m]+1 n,seq=0,0 ans_len=search[0] ans="" temp=0 for i in range(ans_len): for j in range(26): n=memo[temp][j] seq=search[n]+i if seq+1==ans_len : ans+=alpha[j] temp=memo[temp][j] break print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var s : String := (OclFile["System.in"]).readLine() ; var alpha : String := "abcdefghijklmnopqrstuvwxyz" ; var l : int := (s)->size() ; var alpha2 : Map := Integer.subrange(1, (alpha)->size())->collect( _indx | Sequence{_indx-1, (alpha)->at(_indx)} )->select(_tuple | true)->collect(_tuple | Map{j |-> i})->unionAll() ; var memo : Sequence := Integer.subrange(-1 + 1, l)->reverse()->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 26))) ; for i : Integer.subrange(0, 26-1) do ( memo[l+1][i+1] := l + 1) ; for i : Integer.subrange(-1 + 1, l - 1)->reverse() do ( for _tuple : alpha2->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if s[i+1] = x then ( memo[i+1][y+1] := i + 1 ) else ( memo[i+1][y+1] := memo[i + 1+1][y+1] ))) ; var search : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (l + 2)) ; search[l + 1+1] := 0 ; for i : Integer.subrange(-1 + 1, l - 1)->reverse() do ( var m : OclAny := (Integer.subrange(0, 26-1)->select(j | true)->collect(j | (memo[i+1][j+1])))->max() ; if m /= l + 1 then ( search[i+1] := search[m+1] + 1 ) else skip) ; var n : OclAny := null; var seq : OclAny := null; Sequence{n,seq} := Sequence{0,0} ; var ans_len : OclAny := search->first() ; var ans : String := "" ; var temp : int := 0 ; for i : Integer.subrange(0, ans_len-1) do ( for j : Integer.subrange(0, 26-1) do ( var n : OclAny := memo[temp+1][j+1] ; var seq : OclAny := search[n+1] + i ; if seq + 1 = ans_len then ( ans := ans + alpha[j+1] ; temp := memo[temp+1][j+1] ; break ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def main(): n=I() d=collections.defaultdict(set) kk=None for _ in range(n-1): a,b=LI() kk=[a,b] d[a].add(b) d[b].add(a) tt=True gf=collections.defaultdict(bool) while tt : tt=False for k,v in list(d.items()): if len(v)==1 : vt=list(v)[0] if len(d[vt])==1 : continue for vv in d[vt]: if vv==k : continue if vt in d[vv]: d[vv].remove(vt) d[vt]=set([k]) tt=True elif len(v)==0 : return 'First' return 'Second' print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation main() : OclAny pre: true post: true activity: var n : OclAny := I() ; var d : OclAny := .defaultdict(OclType["Set"]) ; var kk : OclAny := null ; for _anon : Integer.subrange(0, n - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := LI() ; kk := Sequence{a}->union(Sequence{ b }) ; (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var tt : boolean := true ; var gf : OclAny := .defaultdict(OclType["boolean"]) ; while tt do ( tt := false ; for _tuple : (d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if (v)->size() = 1 then ( var vt : OclAny := OclType["Sequence"](v)->first() ; if (d[vt+1])->size() = 1 then ( continue ) else skip ; for vv : d[vt+1] do ( if vv = k then ( continue ) else skip ; if (d[vv+1])->includes(vt) then ( (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name vv)))))))) ])) (trailer . (name remove) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name vt)))))))) )))) ) else skip) ; d[vt+1] := Set{}->union((Sequence{ k })) ; tt := true ) else (if (v)->size() = 0 then ( return 'First' ) else skip))) ; return 'Second'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=3 C=5 def maxArea(mat): hist=[[0 for i in range(C+1)]for i in range(R+1)] for i in range(0,C,1): hist[0][i]=mat[0][i] for j in range(1,R,1): if((mat[j][i]==0)): hist[j][i]=0 else : hist[j][i]=hist[j-1][i]+1 for i in range(0,R,1): count=[0 for i in range(R+1)] for j in range(0,C,1): count[hist[i][j]]+=1 col_no=0 j=R while(j>=0): if(count[j]>0): for k in range(0,count[j],1): hist[i][col_no]=j col_no+=1 j-=1 max_area=0 for i in range(0,R,1): for j in range(0,C,1): curr_area=(j+1)*hist[i][j] if(curr_area>max_area): max_area=curr_area return max_area if __name__=='__main__' : mat=[[0,1,0,1,0],[0,1,0,1,1],[1,1,0,1,0]] print("Area of the largest rectangle is",maxArea(mat)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : int := 3 ; var C : int := 5 ; skip ; if __name__ = '__main__' then ( mat := Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 0 }))))}->union(Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 1 }))))}->union(Sequence{ Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 0 })))) })) ; execute ("Area of the largest rectangle is")->display() ) else skip; operation maxArea(mat : OclAny) : OclAny pre: true post: true activity: var hist : Sequence := Integer.subrange(0, R + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, C + 1-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, C-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( hist->first()[i+1] := mat->first()[i+1] ; for j : Integer.subrange(1, R-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if ((mat[j+1][i+1] = 0)) then ( hist[j+1][i+1] := 0 ) else ( hist[j+1][i+1] := hist[j - 1+1][i+1] + 1 ))) ; for i : Integer.subrange(0, R-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( var count : Sequence := Integer.subrange(0, R + 1-1)->select(i | true)->collect(i | (0)) ; for j : Integer.subrange(0, C-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( count[hist[i+1][j+1]+1] := count[hist[i+1][j+1]+1] + 1) ; var col_no : int := 0 ; var j : int := R ; while (j >= 0) do ( if (count[j+1] > 0) then ( for k : Integer.subrange(0, count[j+1]-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( hist[i+1][col_no+1] := j ; col_no := col_no + 1) ) else skip ; j := j - 1)) ; var max_area : int := 0 ; for i : Integer.subrange(0, R-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( for j : Integer.subrange(0, C-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( var curr_area : double := (j + 1) * hist[i+1][j+1] ; if ((curr_area->compareTo(max_area)) > 0) then ( max_area := curr_area ) else skip)) ; return max_area; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numb=int(input()) lst=[] i=0 while itoInteger() ; var lst : Sequence := Sequence{} ; var i : int := 0 ; while (i->compareTo(numb)) < 0 do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : lst) ; i := i + 1) ; var bin_lst : Sequence := Sequence{} ; skip ; genbin(numb) ; var ind : boolean := true ; for i : Integer.subrange(0, (bin_lst)->size()-1) do ( numb := 0 ; for j : Integer.subrange(0, (bin_lst[i+1])->size()-1) do ( if bin_lst[i+1][j+1] = '1' then ( numb := numb + lst[j+1] ) else ( numb := numb - lst[j+1] )) ; if numb mod 360 = 0 then ( ind := false ; execute ("YES")->display() ; break ) else skip) ; if ind then ( execute ("NO")->display() ) else skip; operation genbin(n : OclAny, bs : String) pre: true post: true activity: if bs->oclIsUndefined() then bs := '' else skip; if n - 1 then ( genbin(n - 1, bs + '0') ; genbin(n - 1, bs + '1') ) else ( execute (('1' + bs) : bin_lst) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[0 for i in range(n)] for i in range(n): l[i]=int(input()) dp=[[False for i in range(360)]for j in range(n+1)] for i in range(n+1): for j in range(360): if i==0 and j==0 : dp[i][j]=True continue if i!=0 : dp[i][j]=dp[i-1][(j+l[i-1])% 360]| dp[i-1][(j-l[i-1])% 360] if dp[n][0]: print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( l[i+1] := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, 360-1)->select(i | true)->collect(i | (false)))) ; for i : Integer.subrange(0, n + 1-1) do ( for j : Integer.subrange(0, 360-1) do ( if i = 0 & j = 0 then ( dp[i+1][j+1] := true ; continue ) else skip ; if i /= 0 then ( dp[i+1][j+1] := MathLib.bitwiseOr(dp[i - 1+1][(j + l[i - 1+1]) mod 360+1], dp[i - 1+1][(j - l[i - 1+1]) mod 360+1]) ) else skip)) ; if dp[n+1]->first() then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(start,rest): if rest : return check(start+rest[0],rest[1 :])or check(start-rest[0],rest[1 :]) else : return not(start % 360) n=int(input()) a=[] start=int(input()) for i in range(1,n): a.append(int(input())) print("YES" if check(start,a)else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; start := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(1, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : a)) ; execute (if check(start, a) then "YES" else "NO" endif)->display(); operation check(start : OclAny, rest : OclAny) : OclAny pre: true post: true activity: if rest then ( return check(start + rest->first(), rest->tail()) or check(start - rest->first(), rest->tail()) ) else ( return not((start mod 360)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- arr=[] flag=False t=int(input()) for _ in range(t): n=int(input()) arr.append(n) for num in range(0,1<toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((n) : arr)) ; for num : Integer.subrange(0, 1 * (2->pow(t))-1) do ( var add : int := 0 ; var sub : int := 0 ; for bit : Integer.subrange(0, t-1) do ( if MathLib.bitwiseAnd(num, (1 * (2->pow(bit)))) then ( add := add + arr[bit+1] ) else ( sub := sub - arr[bit+1] )) ; var final : int := add + sub ; if final mod 360 = 0 then ( flag := true ; break ) else skip) ; if flag = true then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cfB(n,arr): flag=0 for num in range((1<toInteger() ; arr := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : arr)) ; cfB(n, arr); operation cfB(n : OclAny, arr : OclAny) pre: true post: true activity: var flag : int := 0 ; for num : Integer.subrange(0, (1 * (2->pow(n)))-1) do ( var sum : int := 0 ; for bits : Integer.subrange(0, n-1) do ( if MathLib.bitwiseAnd(num, (1 * (2->pow(bits)))) then ( sum := sum + arr[bits+1] ) else ( sum := sum - arr[bits+1] )) ; if not((sum mod 360)) then ( flag := 1 ; break ) else skip) ; if flag then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import inf from collections import* import math,os,sys,heapq,bisect,random from functools import lru_cache from itertools import* def inp(): return sys.stdin.readline().rstrip("\n") def out(var): sys.stdout.write(str(var)) def inpu(): return int(inp()) def lis(): return list(map(int,inp().split())) def stringlis(): return list(map(str,inp().split())) def sep(): return map(int,inp().split()) def strsep(): return map(str,inp().split()) def fsep(): return map(float,inp().split()) M,M1=1000000007,998244353 def main(): how_much_noob_I_am=1 for __ in range(how_much_noob_I_am): n=inpu() arr=lis() s=set() p=set() for i in range(n): q=set() for j in p : q.add(j | arr[i]) q.add(arr[i]) p=q for k in p : s.add(k) print(len(s)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var M : OclAny := null; var M1 : OclAny := null; Sequence{M,M1} := Sequence{1000000007,998244353} ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation inp() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip("\n"); operation out(var : OclAny) pre: true post: true activity: (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name var)))))))) ))))))))) )))); operation inpu() : OclAny pre: true post: true activity: return ("" + ((inp())))->toInteger(); operation lis() : OclAny pre: true post: true activity: return ((inp().split())->collect( _x | (OclType["int"])->apply(_x) )); operation stringlis() : OclAny pre: true post: true activity: return ((inp().split())->collect( _x | (OclType["String"])->apply(_x) )); operation sep() : OclAny pre: true post: true activity: return (inp().split())->collect( _x | (OclType["int"])->apply(_x) ); operation strsep() : OclAny pre: true post: true activity: return (inp().split())->collect( _x | (OclType["String"])->apply(_x) ); operation fsep() : OclAny pre: true post: true activity: return (inp().split())->collect( _x | (OclType["double"])->apply(_x) ); operation main() pre: true post: true activity: var how_much_noob_I_am : int := 1 ; for __ : Integer.subrange(0, how_much_noob_I_am-1) do ( var n : OclAny := inpu() ; var arr : OclAny := lis() ; var s : Set := Set{}->union(()) ; var p : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( var q : Set := Set{}->union(()) ; for j : p do ( execute ((MathLib.bitwiseOr(j, arr[i+1])) : q)) ; execute ((arr[i+1]) : q) ; p := q ; for k : p do ( execute ((k) : s))) ; execute ((s)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from functools import lru_cache,cmp_to_key from heapq import merge,heapify,heappop,heappush from collections import defaultdict as dd,deque,Counter as C from itertools import combinations as comb,permutations as perm from bisect import bisect_left as bl,bisect_right as br,bisect,insort from time import perf_counter from fractions import Fraction import copy from copy import deepcopy import time starttime=time.time() mod=int(pow(10,9)+7) mod2=998244353 def data(): return sys.stdin.readline().strip() def out(*var,end="\n"): sys.stdout.write(' '.join(map(str,var))+end) def L(): return list(sp()) def sl(): return list(ssp()) def sp(): return map(int,data().split()) def ssp(): return map(str,data().split()) def l1d(n,val=0): return[val for i in range(n)] def l2d(n,m,val=0): return[l1d(n,val)for j in range(m)] try : sys.stdin=open("input.txt","r") sys.stdout=open("../output.txt","w") except : pass def pmat(A): for ele in A : print(*ele,end="\n") n=int(input()) a=list(map(int,input().split())) s=set() t=set() for aa in a : s={aa | j for j in s} s.add(aa) t.update(s) print(len(t)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var starttime : OclAny := time.time() ; var mod : int := ("" + (((10)->pow(9) + 7)))->toInteger() ; var mod2 : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; try ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile("../output.txt"))) catch (_e : OclException) do ( skip) ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Set := Set{}->union(()) ; var t : Set := Set{}->union(()) ; for aa : a do ( s := s->select(j | true)->collect(j | MathLib.bitwiseOr(aa, j))->asSet() ; execute ((aa) : s) ; execute ((s) <: t)) ; execute ((t)->size())->display(); operation data() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation out(var : OclAny : Sequence(OclAny), end : String) pre: true post: true activity: (args * (named_parameter (name var))) if end->oclIsUndefined() then end := "\n" else skip; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ' ') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name var)))))))) ))))))))) )))) + (expr (atom (name end))))))))) )))); operation L() : OclAny pre: true post: true activity: return (sp()); operation sl() : OclAny pre: true post: true activity: return (ssp()); operation sp() : OclAny pre: true post: true activity: return (data().split())->collect( _x | (OclType["int"])->apply(_x) ); operation ssp() : OclAny pre: true post: true activity: return (data().split())->collect( _x | (OclType["String"])->apply(_x) ); operation l1d(n : OclAny, val : int) : OclAny pre: true post: true activity: if val->oclIsUndefined() then val := 0 else skip; return Integer.subrange(0, n-1)->select(i | true)->collect(i | (val)); operation l2d(n : OclAny, m : OclAny, val : int) : OclAny pre: true post: true activity: if val->oclIsUndefined() then val := 0 else skip; return Integer.subrange(0, m-1)->select(j | true)->collect(j | (l1d(n, val))); operation pmat(A : OclAny) pre: true post: true activity: for ele : A do ( execute ((argument * (test (logical_test (comparison (expr (atom (name ele))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import bisect import heapq from bisect import bisect_right from sys import stdin,stdout def get_ints_in_variables(): return map(int,sys.stdin.readline().strip().split()) def get_int(): return int(sys.stdin.readline()) def get_ints_in_list(): return list(map(int,sys.stdin.readline().strip().split())) def get_list_of_list(n): return[list(map(int,sys.stdin.readline().strip().split()))for _ in range(n)] def get_string(): return sys.stdin.readline().strip() def myceil(x,y): return(x+y-1)//y def Solution(): n=get_int() arr=get_ints_in_list() pre=[-1 for _ in range(20)] pos=[-1 for _ in range(20)] ain=[False for _ in range((1<<20)+1)] cnt=0 for i in range(n): for j in range(20-1,-1,-1): if arr[i]&(1<trim().split())->collect( _x | (OclType["int"])->apply(_x) ); operation get_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation get_ints_in_list() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation get_list_of_list(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )))); operation get_string() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation myceil(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return (x + y - 1) div y; operation Solution() pre: true post: true activity: n := get_int() ; var arr : OclAny := get_ints_in_list() ; var pre : Sequence := Integer.subrange(0, 20-1)->select(_anon | true)->collect(_anon | (-1)) ; var pos : Sequence := Integer.subrange(0, 20-1)->select(_anon | true)->collect(_anon | (-1)) ; var ain : Sequence := Integer.subrange(0, (1 * (2->pow(20))) + 1-1)->select(_anon | true)->collect(_anon | (false)) ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(-1 + 1, 20 - 1)->reverse() do ( if MathLib.bitwiseAnd(arr[i+1], (1 * (2->pow(j)))) then ( pre[j+1] := i ) else skip) ; var val : OclAny := arr[i+1] ; if not(ain[val+1]) then ( cnt := cnt + 1 ) else skip ; ain[val+1] := true ; for j : Integer.subrange(0, 20-1) do ( pos[j+1] := pre[j+1]) ; pos := pos->sort() ; for j : Integer.subrange(-1 + 1, 20 - 1)->reverse() do ( if pos[j+1] /= -1 then ( val := val or arr[pos[j+1]+1] ) else skip ; if not(ain[val+1]) then ( cnt := cnt + 1 ) else skip ; ain[val+1] := true)) ; execute (cnt)->display(); operation main() pre: true post: true activity: Solution(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def b_search(data,k): count=0 l=0 r=len(data)-1 while r>=l : count+=1 mid=(l+r)//2 if data[mid]==k : break if data[mid]>k : r=mid-1 else : l=mid+1 return count def main(args): while True : n=int(input()) if n==0 : break data=[int(input())for _ in range(n)] k=int(input()) result=b_search(data,k) print(result) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation b_search(data : OclAny, k : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var l : int := 0 ; var r : double := (data)->size() - 1 ; while (r->compareTo(l)) >= 0 do ( count := count + 1 ; var mid : int := (l + r) div 2 ; if data[mid+1] = k then ( break ) else skip ; if (data[mid+1]->compareTo(k)) > 0 then ( r := mid - 1 ) else ( l := mid + 1 )) ; return count; operation main(args : OclAny) pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; data := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; k := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var result : OclAny := b_search(data, k) ; execute (result)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) ab=[list(map(int,input().split()))for _ in[0]*(n-1)] g=[set()for _ in[0]*n] [g[a-1].add(b-1)for a,b in ab] [g[b-1].add(a-1)for a,b in ab] only=[] sign=[False]*n for i in range(n): if len(g[i])==1 : only.append(i) while only : i=only.pop() if not g[i]: print("Second") return j=g[i].pop() g[j].remove(i) if sign[i]and not g[j]: print("First") return if not sign[i]and sign[j]: print("First") return if not sign[j]and not sign[i]: sign[j]=True if len(g[j])==1 : only.append(j) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; ; ; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ab : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n - 1))->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var g : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n)->select(_anon | true)->collect(_anon | (Set{}->union(()))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from sys import stdin,stdout def get_ints_in_variables(): return map(int,sys.stdin.readline().strip().split()) def get_int(): return int(input()) def get_ints_in_list(): return list(map(int,sys.stdin.readline().strip().split())) def get_list_of_list(n): return[list(map(int,sys.stdin.readline().strip().split()))for _ in range(n)] def get_string(): return sys.stdin.readline().strip() def main(): n=int(input()) arr=get_ints_in_list() pre=[-1 for _ in range(20)] pos=[-1 for _ in range(20)] ain=[False for _ in range((1<<20)+1)] res=0 for i in range(0,n): for j in range(20-1,-1,-1): if arr[i]&(1<trim().split())->collect( _x | (OclType["int"])->apply(_x) ); operation get_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation get_ints_in_list() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation get_list_of_list(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )))); operation get_string() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation main() pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : OclAny := get_ints_in_list() ; var pre : Sequence := Integer.subrange(0, 20-1)->select(_anon | true)->collect(_anon | (-1)) ; var pos : Sequence := Integer.subrange(0, 20-1)->select(_anon | true)->collect(_anon | (-1)) ; var ain : Sequence := Integer.subrange(0, (1 * (2->pow(20))) + 1-1)->select(_anon | true)->collect(_anon | (false)) ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(-1 + 1, 20 - 1)->reverse() do ( if MathLib.bitwiseAnd(arr[i+1], (1 * (2->pow(j)))) then ( pre[j+1] := i ) else skip) ; var val : OclAny := arr[i+1] ; if not(ain[val+1]) then ( res := res + 1 ) else skip ; ain[val+1] := true ; for j : Integer.subrange(0, 20-1) do ( pos[j+1] := pre[j+1]) ; pos := pos->sort() ; for j : Integer.subrange(-1 + 1, 20 - 1)->reverse() do ( if pos[j+1] /= -1 then ( val := MathLib.bitwiseOr(val, arr[pos[j+1]+1]) ) else skip ; if not(ain[val+1]) then ( res := res + 1 ) else skip ; ain[val+1] := true)) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(x)for x in input().split()] ans=set() cur_ans=set() for i in a : cur_ans={i | j for j in cur_ans} cur_ans.add(i) ans.update(cur_ans) print(len(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : Set := Set{}->union(()) ; var cur_ans : Set := Set{}->union(()) ; for i : a do ( cur_ans := cur_ans->select(j | true)->collect(j | MathLib.bitwiseOr(i, j))->asSet() ; execute ((i) : cur_ans) ; execute ((cur_ans) <: ans)) ; execute ((ans)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys n,q=map(int,input().split()) row1=set() row2=set() diagonalCount=0 upDownCount=0 for _ in range(q): r,c=map(int,input().split()) if c in row1 and r==1 : if c in row2 : upDownCount-=1 if c+1 in row2 : diagonalCount-=1 if c-1 in row2 : diagonalCount-=1 row1.remove(c) elif c in row2 and r==2 : if c in row1 : upDownCount-=1 if c+1 in row1 : diagonalCount-=1 if c-1 in row1 : diagonalCount-=1 row2.remove(c) else : if r==1 : row1.add(c) if c in row2 : upDownCount+=1 if c+1 in row2 : diagonalCount+=1 if c-1 in row2 : diagonalCount+=1 else : row2.add(c) if c in row1 : upDownCount+=1 if c+1 in row1 : diagonalCount+=1 if c-1 in row1 : diagonalCount+=1 print("YES" if diagonalCount==0 and upDownCount==0 else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var row1 : Set := Set{}->union(()) ; var row2 : Set := Set{}->union(()) ; var diagonalCount : int := 0 ; var upDownCount : int := 0 ; for _anon : Integer.subrange(0, q-1) do ( var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (row1)->includes(c) & r = 1 then ( if (row2)->includes(c) then ( upDownCount := upDownCount - 1 ) else skip ; if (row2)->includes(c + 1) then ( diagonalCount := diagonalCount - 1 ) else skip ; if (row2)->includes(c - 1) then ( diagonalCount := diagonalCount - 1 ) else skip ; execute ((c) /: row1) ) else (if (row2)->includes(c) & r = 2 then ( if (row1)->includes(c) then ( upDownCount := upDownCount - 1 ) else skip ; if (row1)->includes(c + 1) then ( diagonalCount := diagonalCount - 1 ) else skip ; if (row1)->includes(c - 1) then ( diagonalCount := diagonalCount - 1 ) else skip ; execute ((c) /: row2) ) else ( if r = 1 then ( execute ((c) : row1) ; if (row2)->includes(c) then ( upDownCount := upDownCount + 1 ) else skip ; if (row2)->includes(c + 1) then ( diagonalCount := diagonalCount + 1 ) else skip ; if (row2)->includes(c - 1) then ( diagonalCount := diagonalCount + 1 ) else skip ) else ( execute ((c) : row2) ; if (row1)->includes(c) then ( upDownCount := upDownCount + 1 ) else skip ; if (row1)->includes(c + 1) then ( diagonalCount := diagonalCount + 1 ) else skip ; if (row1)->includes(c - 1) then ( diagonalCount := diagonalCount + 1 ) else skip ) ) ) ; execute (if diagonalCount = 0 & upDownCount = 0 then "YES" else "NO" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,q=(int(x)for x in input().split()) board=[[0]*n for _ in range(2)] vs,ds=0,0 for _ in range(q): r,c=(int(x)for x in input().split()) if board[r-1][c-1]: if c-2>=0 and board[2-r][c-2]: ds-=1 if c=0 and board[2-r][c-2]: ds+=1 if cselect(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, n))) ; var vs : OclAny := null; var ds : OclAny := null; Sequence{vs,ds} := Sequence{0,0} ; for _anon : Integer.subrange(0, q-1) do ( var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; if board[r - 1+1][c - 1+1] then ( if c - 2 >= 0 & board[2 - r+1][c - 2+1] then ( ds := ds - 1 ) else skip ; if (c->compareTo(n)) < 0 & board[2 - r+1][c+1] then ( ds := ds - 1 ) else skip ; if board[2 - r+1][c - 1+1] then ( vs := vs - 1 ) else skip ) else ( if c - 2 >= 0 & board[2 - r+1][c - 2+1] then ( ds := ds + 1 ) else skip ; if (c->compareTo(n)) < 0 & board[2 - r+1][c+1] then ( ds := ds + 1 ) else skip ; if board[2 - r+1][c - 1+1] then ( vs := vs + 1 ) else skip ) ; board[r - 1+1][c - 1+1] := (1 - board[r - 1+1][c - 1+1])->abs() ; execute (if vs = 0 & ds = 0 then 'Yes' else 'No' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,q=map(int,input().split(' ')) map=[[0],[0]*(n+2),[0]*(n+2)] p=0 for _ in range(q): x,y=input().split(' ') x=int(x) y=int(y) if x==2 : t=1 else : t=2 if map[x][y]==0 : map[x][y]=-1 for i in range(-1,2): if map[t][y+i]!=0 : p+=1 else : map[x][y]=0 for i1 in range(-1,2): if map[t][y+i1]==-1 : p-=1 print("yes")if p==0 else print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var map : Sequence := Sequence{Sequence{ 0 }}->union(Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 2))}->union(Sequence{ MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 2)) })) ; var p : int := 0 ; for _anon : Integer.subrange(0, q-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := input().split(' ') ; var x : int := ("" + ((x)))->toInteger() ; var y : int := ("" + ((y)))->toInteger() ; if x = 2 then ( var t : int := 1 ) else ( t := 2 ) ; if map[x+1][y+1] = 0 then ( map[x+1][y+1] := -1 ; for i : Integer.subrange(-1, 2-1) do ( if map[t+1][y + i+1] /= 0 then ( p := p + 1 ) else skip) ) else ( map[x+1][y+1] := 0 ; for i1 : Integer.subrange(-1, 2-1) do ( if map[t+1][y + i1+1] = -1 then ( p := p - 1 ) else skip) ) ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "yes"))))))) )))))) if (logical_test (comparison (comparison (expr (atom (name p)))) == (comparison (expr (atom (number (integer 0))))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "No"))))))) ))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,l,r=map(int,input().split()) if n==0 and l==0 and r==0 : break else : a=[0 for i in range(n)] for i in range(n): aa=int(input()) a[i]=aa cnt=0 for x in range(l,r+1): flag=False for i in range(n): if x % a[i]==0 : flag=True break if(i+1)% 2==1 and flag==True : cnt+=1 elif flag==False : if n % 2==0 : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{n,l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 & l = 0 & r = 0 then ( break ) else ( var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( var aa : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a[i+1] := aa) ; var cnt : int := 0 ; for x : Integer.subrange(l, r + 1-1) do ( var flag : boolean := false ; for i : Integer.subrange(0, n-1) do ( if x mod a[i+1] = 0 then ( flag := true ; break ) else skip) ; if (i + 1) mod 2 = 1 & flag = true then ( cnt := cnt + 1 ) else (if flag = false then ( if n mod 2 = 0 then ( cnt := cnt + 1 ) else skip ) else skip)) ) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,l,r,A): res=0 for x in range(l,r+1): for i in range(n): if(not x % A[i]): res+=0 if(i & 1)else 1 break else : res+=0 if(n & 1)else 1 return res def main(): ans=[] while True : n,l,r=map(int,input().split()) if(not n)and(not l)and(not r): break A=[int(input())for i in range(n)] ans.append(solve(n,l,r,A)) for i in ans : print(i) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation solve(n : OclAny, l : OclAny, r : OclAny, A : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; for x : Integer.subrange(l, r + 1-1) do ((compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test not (logical_test (comparison (expr (expr (atom (name x))) % (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name res)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))) if (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) & (expr (atom (number (integer 1))))))))) ))))) else (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name res)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))) if (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name n))) & (expr (atom (number (integer 1))))))))) ))))) else (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))))) ; return res; operation main() pre: true post: true activity: var ans : Sequence := Sequence{} ; while true do ( Sequence{n,l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (not(n)) & (not(l)) & (not(r)) then ( break ) else skip ; A := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; execute ((solve(n, l, r, A)) : ans)) ; for i : ans do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,l,r=map(int,input().split()) ans=0 if n==0 and l==0 and r==0 : break A=[] for i in range(n): a=int(input()) A.append(a) for x in range(r-l+1): x+=l for i in range(len(A)): flag=True if x % A[i]==0 : if i % 2==0 : ans+=1 flag=False break if flag and len(A)% 2==0 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{n,l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; if n = 0 & l = 0 & r = 0 then ( break ) else skip ; var A : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((a) : A)) ; for x : Integer.subrange(0, r - l + 1-1) do ( x := x + l ; for i : Integer.subrange(0, (A)->size()-1) do ( var flag : boolean := true ; if x mod A[i+1] = 0 then ( if i mod 2 = 0 then ( ans := ans + 1 ) else skip ; flag := false ; break ) else skip) ; if flag & (A)->size() mod 2 = 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math while 1 : n,l,r=map(int,input().split()) if(n,l,r)==(0,0,0): break aa=[int(input())for _ in range(n)] koho=set([i for i in range(l,r+1)]) baisu=set() uru=set() for i,a in enumerate(aa): start=math.ceil(l/a)*a for k in range(start,r+1,a): baisu.add(k) if not i % 2 : uru |=koho & baisu koho-=baisu if not n % 2 : uru |=koho print(len(uru)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while 1 do ( var n : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{n,l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if Sequence{n, l, r} = Sequence{0, 0, 0} then ( break ) else skip ; var aa : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var koho : Set := Set{}->union((Integer.subrange(l, r + 1-1)->select(i | true)->collect(i | (i)))) ; var baisu : Set := Set{}->union(()) ; var uru : Set := Set{}->union(()) ; for _tuple : Integer.subrange(1, (aa)->size())->collect( _indx | Sequence{_indx-1, (aa)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); var start : double := (l / a)->ceil() * a ; for k : Integer.subrange(start, r + 1-1)->select( $x | ($x - start) mod a = 0 ) do ( execute ((k) : baisu)) ; if not(i mod 2) then ( uru := uru or MathLib.bitwiseAnd(koho, baisu) ) else skip ; koho := koho - baisu) ; if not(n mod 2) then ( uru := uru or koho ) else skip ; execute ((uru)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for i in range(50): n,l,r=map(int,input().split()) if n==0 and l==0 and r==0 : break else : a=[] for ii in range(n): a.append(int(input())) ans=0 for k in range(l,r+1): for s in range(math.ceil(n/2)): if k % a[2*s]==0 : ans+=1 break elif 2*s+1==n : break elif k % a[2*s+1]==0 : break elif s==math.ceil(n/2)-1 and n % 2==0 : ans+=1 break else : continue print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, 50-1) do ( var n : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{n,l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 & l = 0 & r = 0 then ( break ) else ( var a : Sequence := Sequence{} ; for ii : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : a)) ; var ans : int := 0 ; for k : Integer.subrange(l, r + 1-1) do ( for s : Integer.subrange(0, (n / 2)->ceil()-1) do ( if k mod a[2 * s+1] = 0 then ( ans := ans + 1 ; break ) else (if 2 * s + 1 = n then ( break ) else (if k mod a[2 * s + 1+1] = 0 then ( break ) else (if s = (n / 2)->ceil() - 1 & n mod 2 = 0 then ( ans := ans + 1 ; break ) else ( continue ) ) ) ) )) ; execute (ans)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import string,sys input=lambda : sys.stdin.buffer.readline().decode().strip() print=sys.stdout.write s=input() for i in range(len(s)-25): substring=s[i : i+26] if all(substring.count(char)==1 for char in substring if char!="?"): setsub=set(substring) for char in set(string.ascii_uppercase)-setsub : substring=substring.replace("?",char,1) s=s[0 : i]+substring+s[i+26 :] ans=s.replace("?","A") break else : ans="-1" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.buffer.readLine().decode()->trim()) ; var print : OclAny := (OclFile["System.out"]).write ; var s : String := (OclFile["System.in"]).readLine() ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))) - (expr (atom (number (integer 25)))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name substring)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))) : (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 26)))))))))) ])))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name all)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (comparison (expr (atom (name substring)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name char)))))))) ))))) == (comparison (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name char)))) in (logical_test (comparison (expr (atom (name substring))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name char)))) != (comparison (expr (atom "?")))))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name setsub)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name substring)))))))) ))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name char)))) in (testlist (test (logical_test (comparison (expr (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name string)) (trailer . (name ascii_uppercase)))))))) )))) - (expr (atom (name setsub)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name substring)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name substring)) (trailer . (name replace) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "?")))))) , (argument (test (logical_test (comparison (expr (atom (name char))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))) : (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name substring)))) + (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 26)))))))) :)) ]))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)) (trailer . (name replace) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "?")))))) , (argument (test (logical_test (comparison (expr (atom "A"))))))) ))))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom "-1")))))))))))))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline sys.setrecursionlimit(10**7) N=int(input()) edge=[[]for i in range(N)] for i in range(N-1): a,b=map(int,input().split()) edge[a-1].append(b-1) edge[b-1].append(a-1) ans=[0 for i in range(N)] subtreesize=[0 for i in range(N)] def dfs(v,pv): if edge[v]==[pv]: subtreesize[v]=1 ans[v]+=((N-1)% 2==1) return subtreesize[v] a=0 size=1 for nv in edge[v]: if nv==pv : continue else : size+=dfs(nv,v) a+=(subtreesize[nv]% 2==1) rest=N-size a+=(rest % 2==1) ans[v]=a subtreesize[v]=size return size dfs(0,-1) check=[1]*N if check==ans : print("Second") else : print("First") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit((10)->pow(7)) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var edge : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, N - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ))))) ; var ans : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; var subtreesize : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; skip ; dfs(0, -1) ; var check : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, N) ; if check = ans then ( execute ("Second")->display() ) else ( execute ("First")->display() ); operation dfs(v : OclAny, pv : OclAny) : OclAny pre: true post: true activity: if edge[v+1] = Sequence{ pv } then ( subtreesize[v+1] := 1 ; ans[v+1] := ans[v+1] + ((N - 1) mod 2 = 1) ; return subtreesize[v+1] ) else skip ; var a : int := 0 ; var size : int := 1 ; for nv : edge[v+1] do ( if nv = pv then ( continue ) else ( size := size + dfs(nv, v) ; a := a + (subtreesize[nv+1] mod 2 = 1) )) ; var rest : double := N - size ; a := a + (rest mod 2 = 1) ; ans[v+1] := a ; subtreesize[v+1] := size ; return size; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline write=sys.stdout.write def solve(): N=int(input()) if N==0 : return False A=[int(readline())for i in range(N)] k=int(readline()) ans=0 left=0 ; right=N-1 while left<=right : mid=(left+right)>>1 v=A[mid] ans+=1 if v==k : break if vtoInteger() ; if N = 0 then ( return false ) else skip ; var A : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (("" + ((readline())))->toInteger())) ; var k : int := ("" + ((readline())))->toInteger() ; var ans : int := 0 ; var left : int := 0; var right : double := N - 1 ; while (left->compareTo(right)) <= 0 do ( var mid : int := (left + right) /(2->pow(1)) ; var v : OclAny := A[mid+1] ; ans := ans + 1 ; if v = k then ( break ) else skip ; if (v->compareTo(k)) < 0 then ( left := mid + 1 ) else ( right := mid - 1 )) ; write(StringLib.format("%d\n",ans)) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() l=input() ll=l.split() le=len(ll) for j in range(0,le): ll[j]=int(ll[j]) ll.sort() s='' for i in range(0,le): s+=str(ll[i])+' ' print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var l : String := (OclFile["System.in"]).readLine() ; var ll : OclAny := l.split() ; var le : int := (ll)->size() ; for j : Integer.subrange(0, le-1) do ( ll[j+1] := ("" + ((ll[j+1])))->toInteger()) ; ll := ll->sort() ; var s : String := '' ; for i : Integer.subrange(0, le-1) do ( s := s + ("" + ((ll[i+1]))) + ' ') ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A=int(input()) B=list(map(int,input().split())) print(*sorted(B)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name B)))))))) )))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- nav=int(input()) pa=[int(i)for i in input().split()] pa=sorted(pa) for i in pa : print(i,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var nav : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var pa : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; pa := pa->sort() ; for i : pa do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().strip().split())) print(' '.join(map(str,sorted(a)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (StringLib.sumStringsWithSeparator(((a->sort())->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- nwer1=int(input()) awer1=[int(iwer1)for iwer1 in input().split()] awer1.sort() print(*awer1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var nwer1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var awer1 : Sequence := input().split()->select(iwer1 | true)->collect(iwer1 | (("" + ((iwer1)))->toInteger())) ; awer1 := awer1->sort() ; execute ((argument * (test (logical_test (comparison (expr (atom (name awer1))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printArr(arr,n): for i in range(n): print(arr[i],end=" "); def sortArr(arr,n,k): prev=-1 ; for i in range(n): if(arr[i]% k==0): if(prev!=-1): temp=arr[prev+1 : i]; temp.sort(); arr=arr[: prev+1]+temp+arr[i :]; prev=i ; printArr(arr,n); if __name__=="__main__" : arr=[2,1,13,3,7,8,21,13,12]; n=len(arr); k=2 ; sortArr(arr,n,k); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{2}->union(Sequence{1}->union(Sequence{13}->union(Sequence{3}->union(Sequence{7}->union(Sequence{8}->union(Sequence{21}->union(Sequence{13}->union(Sequence{ 12 })))))))); ; n := (arr)->size(); ; k := 2; ; sortArr(arr, n, k); ) else skip; operation printArr(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display();); operation sortArr(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var prev : int := -1; ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] mod k = 0) then ( if (prev /= -1) then ( var temp : OclAny := arr.subrange(prev + 1+1, i); ; temp := temp->sort(); ; arr := arr.subrange(1,prev + 1) + temp + arr.subrange(i+1); ) else skip ; prev := i; ) else skip) ; printArr(arr, n);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) time=list(map(int,input().split(" "))) if time.count(min(time))>=2 : print("Still Rozdil") else : print(time.index(min(time))+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var time : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; if time->count((time)->min()) >= 2 then ( execute ("Still Rozdil")->display() ) else ( execute (time->indexOf((time)->min()) - 1 + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) m=min(l) if l.count(m)>1 : print("Still Rozdil") else : print((l.index(m)+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : OclAny := (l)->min() ; if l->count(m) > 1 then ( execute ("Still Rozdil")->display() ) else ( execute ((l->indexOf(m) - 1 + 1))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) l=list(map(int,input().split())) k=min(l) if l.count(k)==1 : for i in range(t): if l[i]==k : print(i+1) else : print("Still Rozdil") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k : OclAny := (l)->min() ; if l->count(k) = 1 then ( for i : Integer.subrange(0, t-1) do ( if l[i+1] = k then ( execute (i + 1)->display() ) else skip) ) else ( execute ("Still Rozdil")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(100000) def dfs(v,p): result=sum(dfs(c,v)for c in edges[v]if c!=p) if result>=2 : print('First') exit() return not result n=int(input()) if n % 2 : print('First') exit() edges=[set()for _ in range(n)] for _ in range(n-1): a,b=map(int,input().split()) a-=1 b-=1 edges[a].add(b) edges[b].add(a) print('First' if dfs(0,None)else 'Second') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(100000) ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 then ( execute ('First')->display() ; exit() ) else skip ; var edges : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; for _anon : Integer.subrange(0, n - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := a - 1 ; b := b - 1 ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; execute (if dfs(0, null) then 'First' else 'Second' endif)->display(); operation dfs(v : OclAny, p : OclAny) : OclAny pre: true post: true activity: var result : OclAny := ((argument (test (logical_test (comparison (expr (atom (name dfs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c))))))) , (argument (test (logical_test (comparison (expr (atom (name v)))))))) ))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ]))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name c)))) != (comparison (expr (atom (name p)))))))))))->sum() ; if result >= 2 then ( execute ('First')->display() ; exit() ) else skip ; return not(result); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) mini=arr[0] ind=[mini,0] for i in range(1,n): if arr[i]1 : print("Still Rozdil") else : print(ind[1]+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mini : OclAny := arr->first() ; var ind : Sequence := Sequence{mini}->union(Sequence{ 0 }) ; for i : Integer.subrange(1, n-1) do ( if (arr[i+1]->compareTo(mini)) < 0 then ( mini := arr[i+1] ; ind->first() := mini ; ind[1+1] := i ) else skip) ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] = mini then ( count := count + 1 ) else skip) ; if count > 1 then ( execute ("Still Rozdil")->display() ) else ( execute (ind[1+1] + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printPattern(n): if(n==0 or n<0): print(n,end=",") return print(n,end=",") printPattern(n-5) print(n,end=",") n=16 printPattern(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 16 ; printPattern(n); operation printPattern(n : OclAny) pre: true post: true activity: if (n = 0 or n < 0) then ( execute (n)->display() ; return ) else skip ; execute (n)->display() ; printPattern(n - 5) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def kthOdd(arr,n,k): for i in range(n): if(arr[i]% 2==1): k-=1 ; if(k==0): return arr[i]; return-1 ; arr=[1,2,3,4,5]; n=len(arr); k=2 ; print(kthOdd(arr,n,k)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))); ; n := (arr)->size(); ; k := 2; ; execute (kthOdd(arr, n, k))->display();; operation kthOdd(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if (arr[i+1] mod 2 = 1) then ( k := k - 1; ) else skip ; if (k = 0) then ( return arr[i+1]; ) else skip) ; return -1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _=input() distances=[int(x)for x in input().split()] ville=min(distances) compte=distances.count(ville) if compte<2 : print(distances.index(ville)+1) else : print("Still Rozdil") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _anon : String := (OclFile["System.in"]).readLine() ; var distances : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ville : OclAny := (distances)->min() ; var compte : int := distances->count(ville) ; if compte < 2 then ( execute (distances->indexOf(ville) - 1 + 1)->display() ) else ( execute ("Still Rozdil")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def section(x1,x2,y1,y2,z1,z2,m,n): x=((m*x2)+(n*x1))/(m+n) y=((m*y2)+(n*y1))/(m+n) z=((m*z2)+(n*z1))/(m+n) print("(",x,",",y,",",z,")") if __name__=='__main__' : x1=2 x2=4 y1=-1 y2=3 z1=4 z2=2 m=2 n=3 section(x1,x2,y1,y2,z1,z2,m,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( x1 := 2 ; x2 := 4 ; y1 := -1 ; y2 := 3 ; z1 := 4 ; z2 := 2 ; m := 2 ; n := 3 ; section(x1, x2, y1, y2, z1, z2, m, n) ) else skip; operation section(x1 : OclAny, x2 : OclAny, y1 : OclAny, y2 : OclAny, z1 : OclAny, z2 : OclAny, m : OclAny, n : OclAny) pre: true post: true activity: var x : double := ((m * x2) + (n * x1)) / (m + n) ; var y : double := ((m * y2) + (n * y1)) / (m + n) ; var z : double := ((m * z2) + (n * z1)) / (m + n) ; execute ("(")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def PrintBothArrays(a,n): v1,v2=[],[]; mpp=dict.fromkeys(a,0); for i in range(n): mpp[a[i]]+=1 ; if(mpp[a[i]]==1): v1.append(a[i]); elif(mpp[a[i]]==2): v2.append(a[i]); else : print("Not possible"); return ; v1.sort(); print("Strictly increasing array is:"); for it in v1 : print(it,end=" "); v2.sort(reverse=True); print("\nStrictly decreasing array is:"); for it in v2 : print(it,end=" ") if __name__=="__main__" : a=[7,2,7,3,3,1,4]; n=len(a); PrintBothArrays(a,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{7}->union(Sequence{2}->union(Sequence{7}->union(Sequence{3}->union(Sequence{3}->union(Sequence{1}->union(Sequence{ 4 })))))); ; n := (a)->size(); ; PrintBothArrays(a, n); ) else skip; operation PrintBothArrays(a : OclAny, n : OclAny) pre: true post: true activity: var v1 : OclAny := null; var v2 : OclAny := null; Sequence{v1,v2} := Sequence{Sequence{},Sequence{}}; ; var mpp : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))); ; for i : Integer.subrange(0, n-1) do ( mpp[a[i+1]+1] := mpp[a[i+1]+1] + 1; ; if (mpp[a[i+1]+1] = 1) then ( execute ((a[i+1]) : v1); ) else (if (mpp[a[i+1]+1] = 2) then ( execute ((a[i+1]) : v2); ) else ( execute ("Not possible")->display(); ; return; ) ) ) ; v1 := v1->sort(); ; execute ("Strictly increasing array is:")->display(); ; for it : v1 do ( execute (it)->display();) ; v2 := v2->sort(); ; execute ("\nStrictly decreasing array is:")->display(); ; for it : v2 do ( execute (it)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def proc(n,k): if n==1 : return[1]if k==0 else[-1] if n//2>k : return[-1] num_of_pairs=n//2 k-=(num_of_pairs-1) ans=[k,2*k] base=2*k+1 for i in range(n-2): ans.append(base) base+=1 return ans def validate(n,k,ans): point=0 for i in range(0,n,2): point+=math.gcd(ans[i],ans[i+1]) assert point==k and len(set(ans))==n n,k=map(int,input().split()) ans=proc(n,k) print(' '.join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; ans := proc(n, k) ; execute (StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); operation proc(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if n = 1 then ( return if k = 0 then Sequence{ 1 } else Sequence{ -1 } endif ) else skip ; if (n div 2->compareTo(k)) > 0 then ( return Sequence{ -1 } ) else skip ; var num_of_pairs : int := n div 2 ; k := k - (num_of_pairs - 1) ; var ans : Sequence := Sequence{k}->union(Sequence{ 2 * k }) ; var base : double := 2 * k + 1 ; for i : Integer.subrange(0, n - 2-1) do ( execute ((base) : ans) ; base := base + 1) ; return ans; operation validate(n : OclAny, k : OclAny, ans : OclAny) pre: true post: true activity: var point : int := 0 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( point := point + (ans[i+1])->gcd(ans[i + 1+1])) ; assert point = k & (Set{}->union((ans)))->size() = n do "assertion failed"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=list(map(int,input().split())) p=n//2 if n==1 : if k==0 : print(1) else : print(-1) else : if p>k : print(-1) else : if p==k : for i in range(1,n+1): print(i,end=' ') else : x=k-(p-1) print(x,x*2,end=' ') mass=[] count=n-2 for i in range(2,10000000,2): if count>1 : if i!=x and i!=x*2 and i-1!=x and i-1!=x*2 : count-=2 mass.append(i) mass.append(i-1) elif count==1 : if i!=x and i!=x*2 : count-=1 mass.append(i) else : break print(*mass) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var p : int := n div 2 ; if n = 1 then ( if k = 0 then ( execute (1)->display() ) else ( execute (-1)->display() ) ) else ( if (p->compareTo(k)) > 0 then ( execute (-1)->display() ) else ( if p = k then ( for i : Integer.subrange(1, n + 1-1) do ( execute (i)->display()) ) else ( var x : double := k - (p - 1) ; execute (x)->display() ; var mass : Sequence := Sequence{} ; var count : double := n - 2 ; for i : Integer.subrange(2, 10000000-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( if count > 1 then ( if i /= x & i /= x * 2 & i - 1 /= x & i - 1 /= x * 2 then ( count := count - 2 ; execute ((i) : mass) ; execute ((i - 1) : mass) ) else skip ) else (if count = 1 then ( if i /= x & i /= x * 2 then ( count := count - 1 ; execute ((i) : mass) ) else skip ) else ( break ) ) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name mass))))))))->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkdigit(n,k): while(n): rem=n % 10 if(rem==k): return 1 n=n/10 return 0 def findNthNumber(n,k): i=k+1 count=1 while(countdisplay(); operation checkdigit(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: while (n) do ( var rem : int := n mod 10 ; if (rem = k) then ( return 1 ) else skip ; n := n / 10) ; return 0; operation findNthNumber(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var i : OclAny := k + 1 ; var count : int := 1 ; while ((count->compareTo(n)) < 0) do ( if (checkdigit(i, k) or (i mod k = 0)) then ( count := count + 1 ) else skip ; if (count = n) then ( return i ) else skip ; i := i + 1) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) sodd=0 seven=0 for i in range(n): if i % 2==0 : sodd+=a[i] else : seven+=a[i] res=[] if sodd<=seven : for i in range(n): if i % 2==0 : res.append(1) else : res.append(a[i]) else : for i in range(n): if i % 2==0 : res.append(a[i]) else : res.append(1) print(*res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sodd : int := 0 ; var seven : int := 0 ; for i : Integer.subrange(0, n-1) do ( if i mod 2 = 0 then ( sodd := sodd + a[i+1] ) else ( seven := seven + a[i+1] )) ; var res : Sequence := Sequence{} ; if (sodd->compareTo(seven)) <= 0 then ( for i : Integer.subrange(0, n-1) do ( if i mod 2 = 0 then ( execute ((1) : res) ) else ( execute ((a[i+1]) : res) )) ) else ( for i : Integer.subrange(0, n-1) do ( if i mod 2 = 0 then ( execute ((a[i+1]) : res) ) else ( execute ((1) : res) )) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,m=list(map(int,input().split(" "))) arr=[] for i in range(n): temp=[] for i in input(): temp.append(int(i)) arr.append(temp) res="YES" for i in range(n): for j in range(m): try : count=arr[i+1][j]+arr[i][j+1]+arr[i+1][j+1]+arr[i][j] if count==3 : res="NO" except : pass print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var arr : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var temp : Sequence := Sequence{} ; for i : (OclFile["System.in"]).readLine() do ( execute ((("" + ((i)))->toInteger()) : temp)) ; execute ((temp) : arr)) ; var res : String := "YES" ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( try ( var count : OclAny := arr[i + 1+1][j+1] + arr[i+1][j + 1+1] + arr[i + 1+1][j + 1+1] + arr[i+1][j+1] ; if count = 3 then ( res := "NO" ) else skip) catch (_e : OclException) do ( skip) )) ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def read_line(): return[int(x)for x in input().split()] def read_int(): return int(input()) def solve(): n=read_int() a=read_line() sum1,sum2=0,0 for i in range(n): if(i & 1)==1 : sum1+=a[i]-1 else : sum2+=a[i]-1 if sum1*2>sum(a): for i in range(n): if(i & 1)==0 : print(1,end=' ') else : print(a[i],end=' ') else : for i in range(n): if(i & 1)==1 : print(1,end=' ') else : print(a[i],end=' ') print() t=read_int() while t>0 : solve() t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var t : OclAny := read_int() ; while t > 0 do ( solve() ; t := t - 1); operation read_line() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation read_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation solve() pre: true post: true activity: var n : OclAny := read_int() ; var a : OclAny := read_line() ; var sum1 : OclAny := null; var sum2 : OclAny := null; Sequence{sum1,sum2} := Sequence{0,0} ; for i : Integer.subrange(0, n-1) do ( if (MathLib.bitwiseAnd(i, 1)) = 1 then ( sum1 := sum1 + a[i+1] - 1 ) else ( sum2 := sum2 + a[i+1] - 1 )) ; if (sum1 * 2->compareTo((a)->sum())) > 0 then ( for i : Integer.subrange(0, n-1) do ( if (MathLib.bitwiseAnd(i, 1)) = 0 then ( execute (1)->display() ) else ( execute (a[i+1])->display() )) ) else ( for i : Integer.subrange(0, n-1) do ( if (MathLib.bitwiseAnd(i, 1)) = 1 then ( execute (1)->display() ) else ( execute (a[i+1])->display() )) ) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): n=int(input()) a=list(map(int,input().split())) s=sum(a) cur=[0,0] for i in range(n): cur[i % 2]+=a[i]-1 for j in range(2): if 2*cur[j]>s : continue for i in range(n): if i % 2==j : a[i]=1 break print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : OclAny := (a)->sum() ; var cur : Sequence := Sequence{0}->union(Sequence{ 0 }) ; for i : Integer.subrange(0, n-1) do ( cur[i mod 2+1] := cur[i mod 2+1] + a[i+1] - 1) ; for j : Integer.subrange(0, 2-1) do ( if (2 * cur[j+1]->compareTo(s)) > 0 then ( continue ) else skip ; for i : Integer.subrange(0, n-1) do ( if i mod 2 = j then ( a[i+1] := 1 ) else skip) ; break) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import random import math from collections import defaultdict import itertools from sys import stdin,stdout import sys import operator from decimal import Decimal p2D=lambda x : print(*x,sep="\n") def II(): return int(sys.stdin.buffer.readline()) def MI(): return map(int,sys.stdin.buffer.readline().split()) def LI(): return list(map(int,sys.stdin.buffer.readline().split())) def LLI(rows_number): return[LI()for _ in range(rows_number)] def BI(): return sys.stdin.buffer.readline().rstrip() def SI(): return sys.stdin.buffer.readline().rstrip().decode() def li(): return[int(i)for i in input().split()] def lli(rows): return[li()for _ in range(rows)] def si(): return input() def ii(): return int(input()) def ins(): return input().split() def main(): for _ in range(ii()): n=ii() a=li() s1=sum(a[: : 2]) s2=sum(a[1 : : 2]) ans='' i=0 if s1>s2 : while idisplay()) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation II() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.buffer.readLine())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LLI(rows_number : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows_number-1)->select(_anon | true)->collect(_anon | (LI())); operation BI() : OclAny pre: true post: true activity: return sys.stdin.buffer.readLine().rstrip(); operation SI() : OclAny pre: true post: true activity: return sys.stdin.buffer.readLine().rstrip().decode(); operation li() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation lli(rows : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows-1)->select(_anon | true)->collect(_anon | (li())); operation si() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation ii() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation ins() : OclAny pre: true post: true activity: return input().split(); operation main() pre: true post: true activity: for _anon : Integer.subrange(0, ii()-1) do ( var n : OclAny := ii() ; var a : OclAny := li() ; var s1 : OclAny := (a(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->sum() ; var s2 : OclAny := (a(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->sum() ; var ans : String := '' ; var i : int := 0 ; if (s1->compareTo(s2)) > 0 then ( while (i->compareTo(n)) < 0 do ( if i mod 2 = 0 then ( ans := ans + ("" + ((a[i+1]))) + ' ' ; i := i + 1 ) else ( ans := ans + '1 ' ; i := i + 1 )) ) else ( while (i->compareTo(n)) < 0 do ( if i mod 2 = 1 then ( ans := ans + ("" + ((a[i+1]))) + ' ' ; i := i + 1 ) else ( ans := ans + '1 ' ; i := i + 1 )) ) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=[i for i in input().split()] al=list(a) bl=list(b) s=al[0] c=bl[0] for i in al[1 :]: if iselect(i | true)->collect(i | (i)) ; var al : Sequence := (a) ; var bl : Sequence := (b) ; var s : OclAny := al->first() ; var c : OclAny := bl->first() ; for i : al->tail() do ( if (i->compareTo(c)) < 0 then ( s := s + i ) else ( break )) ; s := s + c ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(string): n,*a=map(int,string.split()) l,c,r=1,2,3 sll,slr,srl,srr=sum(a[: l]),sum(a[l : c]),sum(a[c : r]),sum(a[r :]) ans=max(sll,slr,srl,srr)-min(sll,slr,srl,srr) while cunion(Sequence{ (OclFile["System.in"]).readLine() })), ' ')))->display() ) else skip; operation solve(string : OclAny) : OclAny pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := (string.split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : OclAny := null; var c : OclAny := null; var r : OclAny := null; Sequence{l,c,r} := Sequence{1,2,3} ; var sll : OclAny := null; var slr : OclAny := null; var srl : OclAny := null; var srr : OclAny := null; Sequence{sll,slr,srl,srr} := Sequence{(a.subrange(1,l))->sum(),(a.subrange(l+1, c))->sum(),(a.subrange(c+1, r))->sum(),(a.subrange(r+1))->sum()} ; var ans : double := Set{sll, slr, srl, srr}->max() - Set{sll, slr, srl, srr}->min() ; while (c->compareTo(n - 1)) < 0 do ( var d : double := (sll - slr)->abs() ; var dn : double := (sll + 2 * a[l+1] - slr)->abs() ; while (dn->compareTo(d)) < 0 do ( var sll : OclAny := null; var slr : OclAny := null; Sequence{sll,slr} := Sequence{sll + a[l+1],slr - a[l+1]} ; l := l + 1 ; d := (sll - slr)->abs() ; dn := (sll + 2 * a[l+1] - slr)->abs()) ; d := (srl - srr)->abs() ; dn := (srl + 2 * a[r+1] - srr)->abs() ; while (dn->compareTo(d)) < 0 do ( var srl : OclAny := null; var srr : OclAny := null; Sequence{srl,srr} := Sequence{srl + a[r+1],srr - a[r+1]} ; r := r + 1 ; d := (srl - srr)->abs() ; dn := (srl + 2 * a[r+1] - srr)->abs()) ; ans := Set{ans, Set{sll, slr, srl, srr}->max() - Set{sll, slr, srl, srr}->min()}->min() ; slr := slr + a[c+1] ; srl := srl - a[c+1] ; c := c + 1) ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) A=list(map(int,input().split())) S=[0] cnt=0 for i in range(n): cnt+=A[i] S.append(cnt) ans=S[n] d1=1 d3=2 for d2 in range(2,n-1): L=S[d2] R=S[n]-S[d2] for i in range(d1,d2): if S[i]>=L/2 : break if abs(S[i]-L/2)>=abs(S[i-1]-L/2): d1=i-1 else : d1=i for i in range(d3,n): if S[i]-S[d2]>=R/2 : break if abs(S[i]-S[d2]-R/2)>=abs(S[i-1]-S[d2]-R/2): d3=i-1 else : d3=i s=[S[d1],S[d2]-S[d1],S[d3]-S[d2],S[n]-S[d3]] ans=min(max(s)-min(s),ans) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var S : Sequence := Sequence{ 0 } ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( cnt := cnt + A[i+1] ; execute ((cnt) : S)) ; var ans : OclAny := S[n+1] ; var d1 : int := 1 ; var d3 : int := 2 ; for d2 : Integer.subrange(2, n - 1-1) do ( var L : OclAny := S[d2+1] ; var R : double := S[n+1] - S[d2+1] ; for i : Integer.subrange(d1, d2-1) do ( if (S[i+1]->compareTo(L / 2)) >= 0 then ( break ) else skip) ; if ((S[i+1] - L / 2)->abs()->compareTo((S[i - 1+1] - L / 2)->abs())) >= 0 then ( d1 := i - 1 ) else ( d1 := i ) ; for i : Integer.subrange(d3, n-1) do ( if (S[i+1] - S[d2+1]->compareTo(R / 2)) >= 0 then ( break ) else skip) ; if ((S[i+1] - S[d2+1] - R / 2)->abs()->compareTo((S[i - 1+1] - S[d2+1] - R / 2)->abs())) >= 0 then ( d3 := i - 1 ) else ( d3 := i ) ; var s : Sequence := Sequence{S[d1+1]}->union(Sequence{S[d2+1] - S[d1+1]}->union(Sequence{S[d3+1] - S[d2+1]}->union(Sequence{ S[n+1] - S[d3+1] }))) ; ans := Set{(s)->max() - (s)->min(), ans}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,radians from heapq import heappop,heappush,heapify,heappushpop from itertools import permutations,combinations,product,accumulate from operator import itemgetter,mul from copy import deepcopy from string import ascii_lowercase,ascii_uppercase,digits def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) sys.setrecursionlimit(10**9) INF=float('inf') MOD=10**9+7 N=INT() A=LIST() B=list(accumulate(A)) l,c,r=0,1,2 P=sum(A[: l]) Q=sum(A[l : c]) R=sum(A[c : r]) S=sum(A[r :]) ans=INF for c in range(1,N-1): while True : if abs(P-Q)pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; var N : OclAny := INT() ; var A : OclAny := LIST() ; var B : Sequence := (accumulate(A)) ; var l : OclAny := null; var c : OclAny := null; var r : OclAny := null; Sequence{l,c,r} := Sequence{0,1,2} ; var P : OclAny := (A.subrange(1,l))->sum() ; var Q : OclAny := (A.subrange(l+1, c))->sum() ; var R : OclAny := (A.subrange(c+1, r))->sum() ; var S : OclAny := (A.subrange(r+1))->sum() ; var ans : OclAny := INF ; for c : Integer.subrange(1, N - 1-1) do ( while true do ( if ((P - Q)->abs()->compareTo(((P + A[l+1]) - (Q - A[l+1]))->abs())) < 0 then ( break ) else skip ; if l = c - 1 then ( break ) else skip ; P := P + A[l+1] ; Q := Q - A[l+1] ; l := l + 1) ; while true do ( if ((R - S)->abs()->compareTo(((R + A[r+1]) - (S - A[r+1]))->abs())) < 0 then ( break ) else skip ; if r = N - 1 then ( break ) else skip ; R := R + A[r+1] ; S := S - A[r+1] ; r := r + 1) ; ans := Set{Set{P, Q, R, S}->max() - Set{P, Q, R, S}->min(), ans}->min() ; Q := Q + A[c+1] ; R := R - A[c+1]) ; execute (ans)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(i)for i in input().split()] for i in range(1,n): a[i]+=a[i-1] l,r,ans=1,3,float("inf") for i in range(2,n-1): num,num2=abs(2*a[l-1]-a[i-1]),abs(2*a[r-1]-a[i-1]-a[n-1]) while num>abs(2*a[l]-a[i-1])and labs(2*a[r]-a[i-1]-a[-1])and rtoInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; for i : Integer.subrange(1, n-1) do ( a[i+1] := a[i+1] + a[i - 1+1]) ; var l : OclAny := null; var r : OclAny := null; var ans : OclAny := null; Sequence{l,r,ans} := Sequence{1,3,("" + (("inf")))->toReal()} ; for i : Integer.subrange(2, n - 1-1) do ( var num : OclAny := null; var num2 : OclAny := null; Sequence{num,num2} := Sequence{(2 * a[l - 1+1] - a[i - 1+1])->abs(),(2 * a[r - 1+1] - a[i - 1+1] - a[n - 1+1])->abs()} ; while (num->compareTo((2 * a[l+1] - a[i - 1+1])->abs())) > 0 & (l->compareTo(i - 1)) < 0 do ( var l : OclAny := null; var num : OclAny := null; Sequence{l,num} := Sequence{l + 1,(2 * a[l+1] - a[i - 1+1])->abs()}) ; while (num2->compareTo((2 * a[r+1] - a[i - 1+1] - a->last())->abs())) > 0 & (r->compareTo(n - 1)) < 0 do ( var r : OclAny := null; var num2 : OclAny := null; Sequence{r,num2} := Sequence{r + 1,(2 * a[r+1] - a[i - 1+1] - a->last())->abs()}) ; var ans : OclAny := Set{ans, Set{a[l - 1+1], a[i - 1+1] - a[l - 1+1], a[r - 1+1] - a[i - 1+1], a->last() - a[r - 1+1]}->max() - Set{a[l - 1+1], a[i - 1+1] - a[l - 1+1], a[r - 1+1] - a[i - 1+1], a->last() - a[r - 1+1]}->min()}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import itertools INF=float("inf") def solve(N : int,A : "List[int]"): wa=list(itertools.accumulate(A)) m=INF atama1,atama2=0,2 for i in range(1,N-2): s0,s1=wa[atama1],wa[i]-wa[atama1] for j in range(atama1+1,i): t0,t1=wa[j],wa[i]-wa[j] if t0>=t1 : if abs(s1-s0)>=abs(t1-t0): s0,s1=t0,t1 atama1+=1 break s0,s1=t0,t1 atama1+=1 s2,s3=wa[atama2]-wa[i],wa[N-1]-wa[atama2] for j in range(atama2+1,N): t2,t3=wa[j]-wa[i],wa[N-1]-wa[j] if t2>=t3 : if abs(s3-s2)>=abs(t3-t2): s2,s3=t2,t3 atama2+=1 break s2,s3=t2,t3 atama2+=1 s=[s0,s1,s2,s3] s.sort() m=min(s[3]-s[0],m) print(m) return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() N=int(next(tokens)) A=[int(next(tokens))for _ in range(N)] solve(N,A) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var INF : double := ("" + (("inf")))->toReal() ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(N : int, A : "List[int]") pre: true post: true activity: var wa : Sequence := (itertools.accumulate(A)) ; var m : OclAny := INF ; var atama1 : OclAny := null; var atama2 : OclAny := null; Sequence{atama1,atama2} := Sequence{0,2} ; for i : Integer.subrange(1, N - 2-1) do ( var s0 : OclAny := null; var s1 : OclAny := null; Sequence{s0,s1} := Sequence{wa[atama1+1],wa[i+1] - wa[atama1+1]} ; for j : Integer.subrange(atama1 + 1, i-1) do ( var t0 : OclAny := null; var t1 : OclAny := null; Sequence{t0,t1} := Sequence{wa[j+1],wa[i+1] - wa[j+1]} ; if (t0->compareTo(t1)) >= 0 then ( if ((s1 - s0)->abs()->compareTo((t1 - t0)->abs())) >= 0 then ( var s0 : OclAny := null; var s1 : OclAny := null; Sequence{s0,s1} := Sequence{t0,t1} ; atama1 := atama1 + 1 ) else skip ; break ) else skip ; var s0 : OclAny := null; var s1 : OclAny := null; Sequence{s0,s1} := Sequence{t0,t1} ; atama1 := atama1 + 1) ; var s2 : OclAny := null; var s3 : OclAny := null; Sequence{s2,s3} := Sequence{wa[atama2+1] - wa[i+1],wa[N - 1+1] - wa[atama2+1]} ; for j : Integer.subrange(atama2 + 1, N-1) do ( var t2 : OclAny := null; var t3 : OclAny := null; Sequence{t2,t3} := Sequence{wa[j+1] - wa[i+1],wa[N - 1+1] - wa[j+1]} ; if (t2->compareTo(t3)) >= 0 then ( if ((s3 - s2)->abs()->compareTo((t3 - t2)->abs())) >= 0 then ( var s2 : OclAny := null; var s3 : OclAny := null; Sequence{s2,s3} := Sequence{t2,t3} ; atama2 := atama2 + 1 ) else skip ; break ) else skip ; var s2 : OclAny := null; var s3 : OclAny := null; Sequence{s2,s3} := Sequence{t2,t3} ; atama2 := atama2 + 1) ; var s : Sequence := Sequence{s0}->union(Sequence{s1}->union(Sequence{s2}->union(Sequence{ s3 }))) ; s := s->sort() ; m := Set{s[3+1] - s->first(), m}->min()) ; execute (m)->display() ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var N : int := ("" + (((tokens).next())))->toInteger() ; var A : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((tokens).next())))->toInteger())) ; solve(N, A); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkForElement(array,n): s=set() sum=0 for i in range(n): sum+=array[i] s.add(array[i]) f=int(sum/2) if(sum % 2==0 and f in s): return True else : return False if __name__=='__main__' : array=[1,2,3] n=len(array) if(checkForElement(array,n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( array := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; n := (array)->size() ; if (checkForElement(array, n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation checkForElement(array : OclAny, n : OclAny) : OclAny pre: true post: true activity: var s : Set := Set{}->union(()) ; var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + array[i+1] ; execute ((array[i+1]) : s)) ; var f : int := ("" + ((sum / 2)))->toInteger() ; if (sum mod 2 = 0 & (s)->includes(f)) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import queue n,m=map(int,input().split()) vis,ci,cb,cc=[0]*(n+1),0,0,0 g=[[]for i in range(n+1)] def dfs(x): stk,flag=queue.LifoQueue(),True stk.put((x,1)) while not stk.empty(): u,col=stk.get() if vis[u]: flag &=(vis[u]==col) continue vis[u]=col for i in g[u]: stk.put((i,3-col)) return flag for i in range(m): u,v=map(int,input().split()) g[u]+=[v] g[v]+=[u] for i in range(1,n+1): if vis[i]==0 : if len(g[i])==0 : ci+=1 else : if dfs(i): cb+=1 else : cc+=1 print(ci*ci+2*ci*(n-ci)+cc*cc+2*cb*cc+2*cb*cb) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var vis : OclAny := null; var ci : OclAny := null; var cb : OclAny := null; var cc : OclAny := null; Sequence{vis,ci,cb,cc} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)),0,0,0} ; var g : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Sequence{})) ; skip ; for i : Integer.subrange(0, m-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; g[u+1] := g[u+1] + Sequence{ v } ; g[v+1] := g[v+1] + Sequence{ u }) ; for i : Integer.subrange(1, n + 1-1) do ( if vis[i+1] = 0 then ( if (g[i+1])->size() = 0 then ( ci := ci + 1 ) else ( if dfs(i) then ( cb := cb + 1 ) else ( cc := cc + 1 ) ) ) else skip) ; execute (ci * ci + 2 * ci * (n - ci) + cc * cc + 2 * cb * cc + 2 * cb * cb)->display(); operation dfs(x : OclAny) : OclAny pre: true post: true activity: var stk : OclAny := null; var flag : OclAny := null; Sequence{stk,flag} := Sequence{queue.LifoQueue(),true} ; stk.put(Sequence{x, 1}) ; while not(stk.empty()) do ( var u : OclAny := null; var col : OclAny := null; Sequence{u,col} := stk.get() ; if vis[u+1] then ( flag := flag & (vis[u+1] = col) ; continue ) else skip ; vis[u+1] := col ; for i : g[u+1] do ( stk.put(Sequence{i, 3 - col}))) ; return flag; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def minGCD(arr,n): minGCD=0 ; for i in range(n): minGCD=gcd(minGCD,arr[i]); return minGCD ; def minLCM(arr,n): minLCM=arr[0]; for i in range(1,n): minLCM=min(minLCM,arr[i]); return minLCM ; if __name__=="__main__" : arr=[2,66,14,521]; n=len(arr); print("LCM=",minLCM(arr,n),",GCD=",minGCD(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{2}->union(Sequence{66}->union(Sequence{14}->union(Sequence{ 521 }))); ; n := (arr)->size(); ; execute ("LCM=")->display(); ) else skip; operation minGCD(arr : OclAny, n : OclAny) pre: true post: true activity: var minGCD : int := 0; ; for i : Integer.subrange(0, n-1) do ( minGCD := gcd(minGCD, arr[i+1]);) ; return minGCD;; operation minLCM(arr : OclAny, n : OclAny) pre: true post: true activity: var minLCM : OclAny := arr->first(); ; for i : Integer.subrange(1, n-1) do ( minLCM := Set{minLCM, arr[i+1]}->min();) ; return minLCM;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) a=0 b=1 ch=0 fib=[0,1] if(x==0): print("0 0 0") elif(x==1): print("1 0 0") else : while(btoInteger() ; var a : int := 0 ; var b : int := 1 ; var ch : int := 0 ; var fib : Sequence := Sequence{0}->union(Sequence{ 1 }) ; if (x = 0) then ( execute ("0 0 0")->display() ) else (if (x = 1) then ( execute ("1 0 0")->display() ) else ( while ((b->compareTo(x)) < 0) do ( var y : int := a + b ; execute ((a + b) : fib) ; a := b ; b := y) ; execute ((x) /: fib) ; for i : fib do ( for j : fib do ( for k : fib do ( if (i + j + k = x) then ( execute (i)->display() ; ch := 1 ; break ) else skip) ; if (ch = 1) then ( break ) else skip) ; if (ch = 1) then ( break ) else skip) ; if (ch = 0) then ( execute ("IMPOSSIBLE")->display() ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(0,0,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (0)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(input(),0,0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((OclFile["System.in"]).readLine())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- name=input().split() for i in range(1,len(name[0])): if name[0][i]>=name[1][0]: name[0]=name[0][: i] break print(name[0]+name[1][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var name : OclAny := input().split() ; for i : Integer.subrange(1, (name->first())->size()-1) do ( if (name->first()[i+1]->compareTo(name[1+1]->first())) >= 0 then ( name->first() := name->first().subrange(1,i) ; break ) else skip) ; execute (name->first() + name[1+1]->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import lru_cache ; array=set() n=int(input()) @ lru_cache(maxsize=None) def fib(n): if n<=1 : array.add(n) return n ans=fib(n-1)+fib(n-2) array.add(ans) return ans fib(50) def solve(target): for firstNum in array : for secondNum in array : if(target-(firstNum+secondNum))in array : return(firstNum,secondNum,(target-(firstNum+secondNum))) return(-1,-1,-1) firstNum,secondNum,thirdNum=solve(n) if firstNum==-1 : print("I'm too stupid to solve this problem") else : print(firstNum,secondNum,thirdNum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; ; var array : Set := Set{}->union(()) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (compound_stmt (decorator @ (dotted_name (name lru_cache)) ( (arglist (argument (test (logical_test (comparison (expr (atom (name maxsize)))))) = (test (logical_test (comparison (expr (atom None))))))) )) (funcdef def (name fib) ( (typedargslist (def_parameters (def_parameter (named_parameter (name n))))) ) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name n)))) <= (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name array)) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name n))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name fib)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) )))) + (expr (atom (name fib)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 2)))))))))) )))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name array)) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) )))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name ans))))))))))))) ; fib(50) ; skip ; var firstNum : OclAny := null; var secondNum : OclAny := null; var thirdNum : OclAny := null; Sequence{firstNum,secondNum,thirdNum} := solve(n) ; if firstNum = -1 then ( execute ("I'm too stupid to solve this problem")->display() ) else ( execute (firstNum)->display() ); operation solve(target : OclAny) : OclAny pre: true post: true activity: for firstNum : array do ( for secondNum : array do ( if (array)->includes((target - (firstNum + secondNum))) then ( return Sequence{firstNum, secondNum, (target - (firstNum + secondNum))} ) else skip)) ; return Sequence{-1, -1, -1}; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMaximumDiff(a,n): ind1=0 for i in range(n-1,-1,-1): if(a[0]!=a[i]): ind1=i break ind2=0 for i in range(n-1): if(a[n-1]!=a[i]): ind2=(n-1-i) break return max(ind1,ind2) a=[1,2,3,2,3] n=len(a) print(findMaximumDiff(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 3 })))) ; n := (a)->size() ; execute (findMaximumDiff(a, n))->display(); operation findMaximumDiff(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ind1 : int := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (a->first() /= a[i+1]) then ( ind1 := i ; break ) else skip) ; var ind2 : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if (a[n - 1+1] /= a[i+1]) then ( ind2 := (n - 1 - i) ; break ) else skip) ; return Set{ind1, ind2}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ispalindrome(x): ans,temp=0,x while temp>0 : ans=10*ans+temp % 10 temp=temp//10 return ans==x def SuperPalindromes(L,R): L,R=int(L),int(R) LIMIT=100000 ans=0 for i in range(LIMIT): s=str(i) p=s+s[-2 : :-1] p_sq=int(p)**2 if p_sq>R : break if p_sq>=L and ispalindrome(p_sq): ans=ans+1 for i in range(LIMIT): s=str(i) p=s+s[: :-1] p_sq=int(p)**2 if p_sq>R : break if p_sq>=L and ispalindrome(p_sq): ans=ans+1 return ans L="4" R="1000" print(SuperPalindromes(L,R)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; L := "4" ; R := "1000" ; execute (SuperPalindromes(L, R))->display(); operation ispalindrome(x : OclAny) : OclAny pre: true post: true activity: var ans : OclAny := null; var temp : OclAny := null; Sequence{ans,temp} := Sequence{0,x} ; while temp > 0 do ( var ans : double := 10 * ans + temp mod 10 ; var temp : int := temp div 10) ; return ans = x; operation SuperPalindromes(L : OclAny, R : OclAny) : OclAny pre: true post: true activity: Sequence{L,R} := Sequence{("" + ((L)))->toInteger(),("" + ((R)))->toInteger()} ; var LIMIT : int := 100000 ; ans := 0 ; for i : Integer.subrange(0, LIMIT-1) do ( var s : String := ("" + ((i))) ; var p : String := s + s(subscript (test (logical_test (comparison (expr (atom - (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var p_sq : double := (("" + ((p)))->toInteger())->pow(2) ; if (p_sq->compareTo(R)) > 0 then ( break ) else skip ; if (p_sq->compareTo(L)) >= 0 & ispalindrome(p_sq) then ( ans := ans + 1 ) else skip) ; for i : Integer.subrange(0, LIMIT-1) do ( s := ("" + ((i))) ; p := s + s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; p_sq := (("" + ((p)))->toInteger())->pow(2) ; if (p_sq->compareTo(R)) > 0 then ( break ) else skip ; if (p_sq->compareTo(L)) >= 0 & ispalindrome(p_sq) then ( ans := ans + 1 ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def removeRecur(n): prev_digit=n % 10 pow=10 res=prev_digit while(n): curr_digit=n % 10 if(curr_digit!=prev_digit): res+=curr_digit*pow prev_digit=curr_digit pow*=10 n=int(n/10) return res if __name__=='__main__' : n=12224 print(removeRecur(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 12224 ; execute (removeRecur(n))->display() ) else skip; operation removeRecur(n : OclAny) : OclAny pre: true post: true activity: var prev_digit : int := n mod 10 ; var pow : int := 10 ; var res : int := prev_digit ; while (n) do ( var curr_digit : int := n mod 10 ; if (curr_digit /= prev_digit) then ( res := res + curr_digit * pow ; prev_digit := curr_digit ; pow := pow * 10 ) else skip ; n := ("" + ((n / 10)))->toInteger()) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNextNumber(n): h=[0 for i in range(10)] i=0 msb=n rem=0 next_num=-1 count=0 while(msb>9): rem=msb % 10 h[rem]=1 msb//=10 count+=1 h[msb]=1 count+=1 for i in range(msb+1,10,1): if(h[i]==0): next_num=i break if(next_num==-1): for i in range(1,msb,1): if(h[i]==0): next_num=i count+=1 break if(next_num>0): for i in range(0,10,1): if(h[i]==0): msb=i break for i in range(1,count,1): next_num=((next_num*10)+msb) if(next_num>n): print(next_num) else : print("Not Possible") else : print("Not Possible") if __name__=='__main__' : n=2019 findNextNumber(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 2019 ; findNextNumber(n) ) else skip; operation findNextNumber(n : OclAny) pre: true post: true activity: var h : Sequence := Integer.subrange(0, 10-1)->select(i | true)->collect(i | (0)) ; var i : int := 0 ; var msb : OclAny := n ; var rem : int := 0 ; var next_num : int := -1 ; var count : int := 0 ; while (msb > 9) do ( rem := msb mod 10 ; h[rem+1] := 1 ; msb := msb div 10 ; count := count + 1) ; h[msb+1] := 1 ; count := count + 1 ; for i : Integer.subrange(msb + 1, 10-1)->select( $x | ($x - msb + 1) mod 1 = 0 ) do ( if (h[i+1] = 0) then ( next_num := i ; break ) else skip) ; if (next_num = -1) then ( for i : Integer.subrange(1, msb-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if (h[i+1] = 0) then ( next_num := i ; count := count + 1 ; break ) else skip) ) else skip ; if (next_num > 0) then ( for i : Integer.subrange(0, 10-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (h[i+1] = 0) then ( msb := i ; break ) else skip) ; for i : Integer.subrange(1, count-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( next_num := ((next_num * 10) + msb)) ; if ((next_num->compareTo(n)) > 0) then ( execute (next_num)->display() ) else ( execute ("Not Possible")->display() ) ) else ( execute ("Not Possible")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for tt in range(t): n,m=map(int,input().split()) a=[] for i in range(n): a.append([int(j)for j in input()]) s=0 x=0 for i in range(1,n): for j in range(1,m): s=a[i][j]+a[i-1][j-1]+a[i-1][j]+a[i][j-1] if s==3 : x=1 break if x==1 : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for tt : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()->select(j | true)->collect(j | (("" + ((j)))->toInteger()))) : a)) ; var s : int := 0 ; var x : int := 0 ; for i : Integer.subrange(1, n-1) do ( for j : Integer.subrange(1, m-1) do ( s := a[i+1][j+1] + a[i - 1+1][j - 1+1] + a[i - 1+1][j+1] + a[i+1][j - 1+1] ; if s = 3 then ( x := 1 ; break ) else skip)) ; if x = 1 then ( execute ("NO")->display() ) else ( execute ("YES")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairs(s1,n1,s2,n2): freq1=[0]*26 ; freq2=[0]*26 ; count=0 ; for i in range(n1): freq1[ord(s1[i])-ord('a')]+=1 ; for i in range(n2): freq2[ord(s2[i])-ord('a')]+=1 ; for i in range(26): count+=min(freq1[i],freq2[i]); return count ; if __name__=="__main__" : s1="geeksforgeeks" ; s2="platformforgeeks" ; n1=len(s1); n2=len(s2); print(countPairs(s1,n1,s2,n2)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s1 := "geeksforgeeks"; ; s2 := "platformforgeeks"; ; n1 := (s1)->size(); ; n2 := (s2)->size(); ; execute (countPairs(s1, n1, s2, n2))->display(); ) else skip; operation countPairs(s1 : OclAny, n1 : OclAny, s2 : OclAny, n2 : OclAny) pre: true post: true activity: var freq1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26); ; var freq2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26); ; var count : int := 0; ; for i : Integer.subrange(0, n1-1) do ( freq1[(s1[i+1])->char2byte() - ('a')->char2byte()+1] := freq1[(s1[i+1])->char2byte() - ('a')->char2byte()+1] + 1;) ; for i : Integer.subrange(0, n2-1) do ( freq2[(s2[i+1])->char2byte() - ('a')->char2byte()+1] := freq2[(s2[i+1])->char2byte() - ('a')->char2byte()+1] + 1;) ; for i : Integer.subrange(0, 26-1) do ( count := count + Set{freq1[i+1], freq2[i+1]}->min();) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) a=list(map(int,input().split())) L=[0 for i in range(8)] s=0 for i in range(N): if a[i]<3200 : L[a[i]//400]=L[a[i]//400]+1 else : s=s+1 n=0 for i in range(8): if L[i]>0 : n=n+1 nmin=n nmax=n+s if nmin==0 : nmin=1 print(str(nmin)+" "+str(nmax)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var L : Sequence := Integer.subrange(0, 8-1)->select(i | true)->collect(i | (0)) ; var s : int := 0 ; for i : Integer.subrange(0, N-1) do ( if a[i+1] < 3200 then ( L[a[i+1] div 400+1] := L[a[i+1] div 400+1] + 1 ) else ( s := s + 1 )) ; var n : int := 0 ; for i : Integer.subrange(0, 8-1) do ( if L[i+1] > 0 then ( n := n + 1 ) else skip) ; var nmin : int := n ; var nmax : int := n + s ; if nmin = 0 then ( nmin := 1 ) else skip ; execute (("" + ((nmin))) + " " + ("" + ((nmax))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def f(r): from bisect import bisect R=[400,800,1200,1600,2000,2400,2800,3200] return bisect(R,r) def solve(N : int,a : "List[int]"): from collections import Counter b=tuple(map(f,a)) c=Counter(b) return max(1,len(c)-(1 if c[8]else 0)),len(c)+(c[8]-1 if c[8]else 0) def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() N=int(next(tokens)) a=[int(next(tokens))for _ in range(N)] print(*solve(N,a)) def test(): import doctest doctest.testmod() if __name__=='__main__' : test() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( test() ; main() ) else skip; operation f(r : OclAny) : OclAny pre: true post: true activity: skip ; var R : Sequence := Sequence{400}->union(Sequence{800}->union(Sequence{1200}->union(Sequence{1600}->union(Sequence{2000}->union(Sequence{2400}->union(Sequence{2800}->union(Sequence{ 3200 }))))))) ; return bisect(R, r); operation solve(N : int, a : "List[int]") : OclAny pre: true post: true activity: skip ; var b : Sequence := ((a)->collect( _x | (f)->apply(_x) )) ; var c : OclAny := Counter(b) ; return Set{1, (c)->size() - (if c[8+1] then 1 else 0 endif)}->max(), (c)->size() + (if c[8+1] then c[8+1] - 1 else 0 endif); operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var N : int := ("" + (((tokens).next())))->toInteger() ; var a : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((tokens).next())))->toInteger())) ; execute ((argument * (test (logical_test (comparison (expr (atom (name solve)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N))))))) , (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))))))))->display(); operation test() pre: true post: true activity: skip ; doctest.testmod(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections as c input(); a=c.Counter(i//400 for i in[*map(int,input().split())]) b,c=len(set([i for i,j in a.items()if i<8])),sum([j for i,j in a.items()if i>=8]) print([b,1][b==0],b+c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; input(); var a : OclAny := c.Counter((argument (test (logical_test (comparison (expr (expr (atom (name i))) // (expr (atom (number (integer 400)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom [ (testlist_comp (star_expr * (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))) ]))))))) ; var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := Sequence{(Set{}->union((a->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->select(_tuple | let i : OclAny = _tuple->at(1) in let j : OclAny = _tuple->at(2) in i < 8)->collect(_tuple | let i : OclAny = _tuple->at(1) in let j : OclAny = _tuple->at(2) in (i)))))->size(),(a->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->select(_tuple | let i : OclAny = _tuple->at(1) in let j : OclAny = _tuple->at(2) in i >= 8)->collect(_tuple | let i : OclAny = _tuple->at(1) in let j : OclAny = _tuple->at(2) in (j)))->sum()} ; execute (Sequence{b}->union(Sequence{ 1 })->select(b = 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np import sys from collections import deque from collections import defaultdict import heapq import collections import itertools import bisect from scipy.special import comb import copy sys.setrecursionlimit(10**6) def zz(): return list(map(int,sys.stdin.readline().split())) def z(): return int(sys.stdin.readline()) def S(): return sys.stdin.readline()[:-1] def C(line): return[sys.stdin.readline()for _ in range(line)] def is_prime(n): if n==1 : return False for i in range(2,int(n**0.5)+1): if n % i==0 : return False return True N=z() A=zz() lis=list(range(-1,3200,400)) ok=0 set_=[] for i in range(N): if(A[i]>=3200): ok+=1 else : idx=bisect.bisect_left(lis,A[i]) set_.append(idx) set_=set(set_) min_=max(len(set_),1) max_=len(set_)+ok print(min_,max_) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(6)) ; skip ; skip ; skip ; skip ; skip ; var N : OclAny := z() ; var A : OclAny := zz() ; var lis : Sequence := (Integer.subrange(-1, 3200-1)->select( $x | ($x - -1) mod 400 = 0 )) ; var ok : int := 0 ; var set_ : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( if (A[i+1] >= 3200) then ( ok := ok + 1 ) else ( var idx : OclAny := bisect.bisect_left(lis, A[i+1]) ; execute ((idx) : set_) )) ; set_ := Set{}->union((set_)) ; var min_ : OclAny := Set{(set_)->size(), 1}->max() ; var max_ : int := (set_)->size() + ok ; execute (min_)->display(); operation zz() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation z() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation S() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation C(line : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, line-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())); operation is_prime(n : OclAny) : OclAny pre: true post: true activity: if n = 1 then ( return false ) else skip ; for i : Integer.subrange(2, ("" + (((n)->pow(0.5))))->toInteger() + 1-1) do ( if n mod i = 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f,s=input().split() l=f[0] for c in f[1 :]: if c>=s[0]: break l+=c print(l+s[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : OclAny := null; var s : OclAny := null; Sequence{f,s} := input().split() ; var l : String := f->first() ; for c : f->tail() do ( if (c->compareTo(s->first())) >= 0 then ( break ) else skip ; l := l + c) ; execute (l + s->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=list(map(int,input().split())) c=0 d=0 e=0 f=0 g=0 h=0 i=0 j=0 k=0 x=0 for z in range(a): if b[z]<=399 : c=c+1 if 400<=b[z]<799 : d=d+1 if 800<=b[z]<=1199 : e=e+1 if 1200<=b[z]<=1599 : f=f+1 if 1600<=b[z]<=1999 : g=g+1 if 2000<=b[z]<=2399 : h=h+1 if 2400<=b[z]<=2799 : i=i+1 if 2800<=b[z]<=3199 : j=j+1 if b[z]>=3200 : k=k+1 if c!=0 : x=x+1 if d!=0 : x=x+1 if e!=0 : x=x+1 if f!=0 : x=x+1 if g!=0 : x=x+1 if h!=0 : x=x+1 if i!=0 : x=x+1 if j!=0 : x=x+1 if k+x>a : print(x,a) elif(c+d+e+f+g+h+i+j)==0 and k!=0 : print(1,k) else : print(x,k+x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; var d : int := 0 ; var e : int := 0 ; var f : int := 0 ; var g : int := 0 ; var h : int := 0 ; var i : int := 0 ; var j : int := 0 ; var k : int := 0 ; var x : int := 0 ; for z : Integer.subrange(0, a-1) do ( if b[z+1] <= 399 then ( c := c + 1 ) else skip ; if 400 <= b[z+1] & (b[z+1] < 799) then ( d := d + 1 ) else skip ; if 800 <= b[z+1] & (b[z+1] <= 1199) then ( e := e + 1 ) else skip ; if 1200 <= b[z+1] & (b[z+1] <= 1599) then ( f := f + 1 ) else skip ; if 1600 <= b[z+1] & (b[z+1] <= 1999) then ( g := g + 1 ) else skip ; if 2000 <= b[z+1] & (b[z+1] <= 2399) then ( h := h + 1 ) else skip ; if 2400 <= b[z+1] & (b[z+1] <= 2799) then ( i := i + 1 ) else skip ; if 2800 <= b[z+1] & (b[z+1] <= 3199) then ( j := j + 1 ) else skip ; if b[z+1] >= 3200 then ( k := k + 1 ) else skip) ; if c /= 0 then ( x := x + 1 ) else skip ; if d /= 0 then ( x := x + 1 ) else skip ; if e /= 0 then ( x := x + 1 ) else skip ; if f /= 0 then ( x := x + 1 ) else skip ; if g /= 0 then ( x := x + 1 ) else skip ; if h /= 0 then ( x := x + 1 ) else skip ; if i /= 0 then ( x := x + 1 ) else skip ; if j /= 0 then ( x := x + 1 ) else skip ; if (k + x->compareTo(a)) > 0 then ( execute (x)->display() ) else (if (c + d + e + f + g + h + i + j) = 0 & k /= 0 then ( execute (1)->display() ) else ( execute (x)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPlusPossible(arr,n): mp=dict() for i in range(n): mp[arr[i]]=mp.get(arr[i],0)+1 foundModOne=False for x in mp : element=x frequency=mp[x] if(frequency % 4==0): continue if(frequency % 4==1): if(foundModOne==True): return False foundModOne=True else : return False return True arr=[1,1,1,1,2,2,2,3,2] n=len(arr) if(isPlusPossible(arr,n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 2 })))))))) ; n := (arr)->size() ; if (isPlusPossible(arr, n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isPlusPossible(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var mp : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( mp[arr[i+1]+1] := mp.get(arr[i+1], 0) + 1) ; var foundModOne : boolean := false ; for x : mp->keys() do ( var element : OclAny := x ; var frequency : OclAny := mp[x+1] ; if (frequency mod 4 = 0) then ( continue ) else skip ; if (frequency mod 4 = 1) then ( if (foundModOne = true) then ( return false ) else skip ; foundModOne := true ) else ( return false )) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def largestSquareFactor(num): answer=1 for i in range(2,int(math.sqrt(num))): cnt=0 j=i while(num % j==0): cnt+=1 j*=i if(cnt & 1): cnt-=1 answer*=pow(i,cnt) else : answer*=pow(i,cnt) return answer if __name__=="__main__" : N=420 print(largestSquareFactor(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var N : int := 420 ; execute (largestSquareFactor(N))->display() ) else skip; operation largestSquareFactor(num : OclAny) : OclAny pre: true post: true activity: var answer : int := 1 ; for i : Integer.subrange(2, ("" + (((num)->sqrt())))->toInteger()-1) do ( var cnt : int := 0 ; var j : OclAny := i ; while (num mod j = 0) do ( cnt := cnt + 1 ; j := j * i) ; if (MathLib.bitwiseAnd(cnt, 1)) then ( cnt := cnt - 1 ; answer := answer * (i)->pow(cnt) ) else ( answer := answer * (i)->pow(cnt) )) ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=map(int,input().split()) l=list(map(int,input().split())) for i in range(len(l)): print(str((l[i]*a)% b//a),end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, (l)->size()-1) do ( execute (("" + (((l[i+1] * a) mod b div a))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import factorial input=sys.stdin.readline def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s=input() return(s[: len(s)-1]) def invr(): return(map(int,input().split())) def insr2(): s=input() return(s.split(" ")) q=inp() for _ in range(q): def solve(): n,m=inlt() arr=[] for _ in range(n): s=insr() arr.append([int(a)for a in s]) if n==1 or m==1 : print('YES') return for i in range(n-1): for j in range(m-1): if arr[i][j]+arr[i+1][j]+arr[i][j+1]+arr[i+1][j+1]==3 : print('NO') return print('YES') return solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; skip ; var q : OclAny := inp() ; for _anon : Integer.subrange(0, q-1) do ( skip ; solve()); operation inp() : OclAny pre: true post: true activity: return (("" + (((OclFile["System.in"]).readLine())))->toInteger()); operation inlt() : OclAny pre: true post: true activity: return (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))); operation insr() : OclAny pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; return (s.subrange(1,(s)->size() - 1)); operation invr() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation insr2() : OclAny pre: true post: true activity: s := (OclFile["System.in"]).readLine() ; return (s.split(" ")); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=map(int,input().split()) arr=list(map(int,input().split())) for v in arr : ans=0 if a==0 else(v*a)% b//a print(ans,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for v : arr do ( var ans : int := if a = 0 then 0 else (v * a) mod b div a endif ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.readline write=sys.stdout.write n,a,b=map(int,read().split()) arr=list(map(int,read().split())) for x in arr : mx=x*a//b mn=(mx*b+a-1)//a write(str(x-mn)+' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := (OclFile["System.in"]).readline ; var write : OclAny := (OclFile["System.out"]).write ; var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (read().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((read().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for x : arr do ( var mx : int := x * a div b ; var mn : int := (mx * b + a - 1) div a ; write(("" + ((x - mn))) + ' ')); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=map(int,input().split()); tokens=list(map(int,input().split())) for i in tokens : dollars=i*a//b if dollars>0 : print(str(int(i %(dollars*b/a))),end=" ") else : print(str(i),end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var tokens : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : tokens do ( var dollars : int := i * a div b ; if dollars > 0 then ( execute (("" + ((("" + ((i mod (dollars * b / a))))->toInteger()))))->display() ) else ( execute (("" + ((i))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=map(int,input().split()); tokens=list(map(int,input().split())) for i in tokens : dollars=i*a//b if dollars>0 : print(str(int(i %(dollars*b/a))),end=" ") else : print(str(i),end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var tokens : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : tokens do ( var dollars : int := i * a div b ; if dollars > 0 then ( execute (("" + ((("" + ((i mod (dollars * b / a))))->toInteger()))))->display() ) else ( execute (("" + ((i))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_CHAR=256 def isPresent(s,q): freq=[0]*MAX_CHAR for i in range(0,len(s)): freq[ord(s[i])]+=1 for i in range(0,len(q)): freq[ord(q[i])]-=1 if(freq[ord(q[i])]<0): return False return True s="abctd" q="cat" if(isPresent(s,q)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_CHAR : int := 256 ; skip ; s := "abctd" ; q := "cat" ; if (isPresent(s, q)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isPresent(s : OclAny, q : OclAny) : OclAny pre: true post: true activity: var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX_CHAR) ; for i : Integer.subrange(0, (s)->size()-1) do ( freq[(s[i+1])->char2byte()+1] := freq[(s[i+1])->char2byte()+1] + 1) ; for i : Integer.subrange(0, (q)->size()-1) do ( freq[(q[i+1])->char2byte()+1] := freq[(q[i+1])->char2byte()+1] - 1 ; if (freq[(q[i+1])->char2byte()+1] < 0) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printMatrix(n,k): for i in range(n): for j in range(n): if(i==j): print(k,end=" "); else : print("0",end=" "); print(); if __name__=="__main__" : n=3 ; k=7 ; printMatrix(n,k); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 3; k := 7; ; printMatrix(n, k); ) else skip; operation printMatrix(n : OclAny, k : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if (i = j) then ( execute (k)->display(); ) else ( execute ("0")->display(); )) ; execute (->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(str,input().split()) first=a[0] last=b[0] ans=first for i in range(1,len(a)): if(a[i]collect( _x | (OclType["String"])->apply(_x) ) ; var first : OclAny := a->first() ; var last : OclAny := b->first() ; var ans : OclAny := first ; for i : Integer.subrange(1, (a)->size()-1) do ( if ((a[i+1]->compareTo(last)) < 0) then ( ans := ans + a[i+1] ) else ( break )) ; ans := ans + last ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) home=input() flights=[] while num>0 : s,t=input().split("->") flights.append(s) flights.append(t) num-=1 count=0 for flight in flights : if flight==home : count+=1 if count % 2==0 : print("home") else : print("contest") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var home : String := (OclFile["System.in"]).readLine() ; var flights : Sequence := Sequence{} ; while num > 0 do ( var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := input().split("->") ; execute ((s) : flights) ; execute ((t) : flights) ; num := num - 1) ; var count : int := 0 ; for flight : flights do ( if flight = home then ( count := count + 1 ) else skip) ; if count mod 2 = 0 then ( execute ("home")->display() ) else ( execute ("contest")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=(int(input())) s=input() a="" for i in range(n): a=input() if n % 2==0 : print("home") else : print("contest") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var s : String := (OclFile["System.in"]).readLine() ; var a : String := "" ; for i : Integer.subrange(0, n-1) do ( a := (OclFile["System.in"]).readLine()) ; if n mod 2 = 0 then ( execute ("home")->display() ) else ( execute ("contest")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=(int(input())) s=input() a="" for i in range(n): a=input() if n % 2==0 : print("home") else : print("contest") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var s : String := (OclFile["System.in"]).readLine() ; var a : String := "" ; for i : Integer.subrange(0, n-1) do ( a := (OclFile["System.in"]).readLine()) ; if n mod 2 = 0 then ( execute ("home")->display() ) else ( execute ("contest")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): n,m=map(int,input().split()) g=[] for i in range(n): g.append(input()) ans="YES" if(n==1==m): print(ans); continue for x,y in zip(g,g[1 :]): for a,b,c,d in zip(x,x[1 :],y,y[1 :]): if(int(a)+int(b)+int(c)+int(d)==3): ans="NO" ; break if(ans=="NO"): break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var g : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : g)) ; var ans : String := "YES" ; if (n = 1 & (1 == m)) then ( execute (ans)->display(); continue ) else skip ; for _tuple : Integer.subrange(1, g->size())->collect( _indx | Sequence{g->at(_indx), g->tail()->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); for _tuple : Integer.subrange(1, x->size())->collect( _indx | Sequence{x->at(_indx), x->tail()->at(_indx)} ) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); if (("" + ((a)))->toInteger() + ("" + ((b)))->toInteger() + ("" + ((c)))->toInteger() + ("" + ((d)))->toInteger() = 3) then ( ans := "NO"; break ) else skip) ; if (ans = "NO") then ( break ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=(int(input())) s=input() a="" for i in range(n): a=input() if n % 2==0 : print("home") else : print("contest") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var s : String := (OclFile["System.in"]).readLine() ; var a : String := "" ; for i : Integer.subrange(0, n-1) do ( a := (OclFile["System.in"]).readLine()) ; if n mod 2 = 0 then ( execute ("home")->display() ) else ( execute ("contest")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print('hcoomnet e s t'[int(input())% 2 : : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ('hcoomnet e s t'(subscript (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) )))) % (expr (atom (number (integer 2)))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def search(searchspace,s,e,key): ans=-1 while s<=e : mid=(s+e)//2 if searchspace[mid]-key>=0 : ans=mid e=mid-1 else : s=mid+1 return ans def longestSubarray(a,n): SuffixSum=[0 for i in range(n+1)] for i in range(n-1,-1,-1): SuffixSum[i]=SuffixSum[i+1]+a[i] ans=0 searchspace=[0 for i in range(n)] index=[0 for i in range(n)] j=0 for i in range(n): if j==0 or(SuffixSum[i]>searchspace[j-1]): searchspace[j]=SuffixSum[i] index[j]=i j+=1 idx=search(searchspace,0,j-1,SuffixSum[i+1]) if idx!=-1 : ans=max(ans,i-index[idx]+1) return ans a=[-1,4,-2,-5,6,-8] n=len(a) print(longestSubarray(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; a := Sequence{-1}->union(Sequence{4}->union(Sequence{-2}->union(Sequence{-5}->union(Sequence{6}->union(Sequence{ -8 }))))) ; n := (a)->size() ; execute (longestSubarray(a, n))->display(); operation search(searchspace : OclAny, s : OclAny, e : OclAny, key : OclAny) : OclAny pre: true post: true activity: var ans : int := -1 ; while (s->compareTo(e)) <= 0 do ( var mid : int := (s + e) div 2 ; if searchspace[mid+1] - key >= 0 then ( ans := mid ; e := mid - 1 ) else ( s := mid + 1 )) ; return ans; operation longestSubarray(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var SuffixSum : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( SuffixSum[i+1] := SuffixSum[i + 1+1] + a[i+1]) ; ans := 0 ; searchspace := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var index : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var j : int := 0 ; for i : Integer.subrange(0, n-1) do ( if j = 0 or ((SuffixSum[i+1]->compareTo(searchspace[j - 1+1])) > 0) then ( searchspace[j+1] := SuffixSum[i+1] ; index[j+1] := i ; j := j + 1 ) else skip ; var idx : OclAny := search(searchspace, 0, j - 1, SuffixSum[i + 1+1]) ; if idx /= -1 then ( ans := Set{ans, i - index[idx+1] + 1}->max() ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import Fraction while True : s=input() if s=="#" : break s="".join([c for c in s if c=='n' or c=='w']) x=0 if s[-1]=='n' else 90 for i in range(len(s)-1): if s[-2-i]=='n' : x-=Fraction(45,1<characters()->select(c | c = 'n' or c = 'w')->collect(c | (c))), "") ; var x : int := if s->last() = 'n' then 0 else 90 endif ; for i : Integer.subrange(0, (s)->size() - 1-1) do ( if s->reverse()->at(-(-2 - i)) = 'n' then ( x := x - Fraction(45, 1 * (2->pow(i))) ) else ( x := x + Fraction(45, 1 * (2->pow(i))) )) ; execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : direction=''.join(reversed(input())) if direction=='#' : break count=0 ans=0 while direction!='' : if direction[0]=='h' : if count==0 : ans=0 else : ans=ans*2-90 direction=direction[len('north'):] else : if count==0 : ans=90 else : ans=ans*2+90 direction=direction[len('west'):] count+=1 while ans % 2==0 and count>1 : ans//=2 count-=1 if count<=1 : print(ans) else : print(str(ans)+'/'+str(2**(count-1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var direction : String := StringLib.sumStringsWithSeparator((((OclFile["System.in"]).readLine())->reverse()), '') ; if direction = '#' then ( break ) else skip ; var count : int := 0 ; var ans : int := 0 ; while direction /= '' do ( if direction->first() = 'h' then ( if count = 0 then ( ans := 0 ) else ( ans := ans * 2 - 90 ) ; direction := direction.subrange(('north')->size()+1) ) else ( if count = 0 then ( ans := 90 ) else ( ans := ans * 2 + 90 ) ; direction := direction.subrange(('west')->size()+1) ) ; count := count + 1) ; while ans mod 2 = 0 & count > 1 do ( ans := ans div 2 ; count := count - 1) ; if count <= 1 then ( execute (ans)->display() ) else ( execute (("" + ((ans))) + '/' + ("" + (((2)->pow((count - 1))))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import Fraction def rec(s): if s[0]=='n' : if len(s)>5 : t=rec(s[5 :]) return[(t[0]-45)*2,t[1]+1] else : return[0,0] else : if len(s)>4 : t=rec(s[4 :]) return[(t[0]+45)*2,t[1]+1] else : return[90,0] while True : s=input() if s=="#" : break [n,d]=rec(s) d=2**d ans=Fraction(n,d) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( s := (OclFile["System.in"]).readLine() ; if s = "#" then ( break ) else skip) ; Sequence{n}->union(Sequence{ d }) := rec(s); operation rec(s : OclAny) : OclAny pre: true post: true activity: if s->first() = 'n' then ( if (s)->size() > 5 then ( var t : OclAny := rec(s.subrange(5+1)) ; return Sequence{(t->first() - 45) * 2}->union(Sequence{ t[1+1] + 1 }) ) else ( return Sequence{0}->union(Sequence{ 0 }) ) ) else ( if (s)->size() > 4 then ( t := rec(s.subrange(4+1)) ; return Sequence{(t->first() + 45) * 2}->union(Sequence{ t[1+1] + 1 }) ) else ( return Sequence{90}->union(Sequence{ 0 }) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import Fraction def calc(s): n=ans=0 while len(s)>=4 : if s[-4]=='w' : s=s[:-4] if n==0 : ans=Fraction(90,1) else : ans+=Fraction(90,2**n) else : s=s[:-5] if n==0 : ans=Fraction(0,1) else : ans-=Fraction(90,2**n) n+=1 return ans while True : S=input() if S=='#' : break print(calc(S)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( var S : String := (OclFile["System.in"]).readLine() ; if S = '#' then ( break ) else skip ; execute (calc(S))->display()); operation calc(s : OclAny) : OclAny pre: true post: true activity: var n : OclAny := 0; var ans : int := 0 ; while (s)->size() >= 4 do ( if s->reverse()->at(-(-4)) = 'w' then ( s := s.subrange(1,-4) ; if n = 0 then ( ans := Fraction(90, 1) ) else ( ans := ans + Fraction(90, (2)->pow(n)) ) ) else ( s := s.subrange(1,-5) ; if n = 0 then ( ans := Fraction(0, 1) ) else ( ans := ans - Fraction(90, (2)->pow(n)) ) ) ; n := n + 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) f,s=input().split() l=f[0] for c in f[1 :]: if c>=s[0]: break l+=c print(l+s[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var f : OclAny := null; var s : OclAny := null; Sequence{f,s} := input().split() ; var l : String := f->first() ; for c : f->tail() do ( if (c->compareTo(s->first())) >= 0 then ( break ) else skip ; l := l + c) ; execute (l + s->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import* while True : s=input()[: :-1] if s=='#' : break if s[0]=='h' : angle=Fraction(0) cnt=5 else : angle=Fraction(90) cnt=4 i=1 while cntfirst() = 'h' then ( var angle : OclAny := Fraction(0) ; var cnt : int := 5 ) else ( angle := Fraction(90) ; cnt := 4 ) ; var i : int := 1 ; while (cnt->compareTo((s)->size())) < 0 do ( if s[cnt+1] = 'h' then ( angle := angle - Fraction(90 / (2)->pow(i)) ; cnt := cnt + 5 ) else ( angle := angle + Fraction(90 / (2)->pow(i)) ; cnt := cnt + 4 ) ; i := i + 1) ; execute (angle)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def prov(x): for i in range(2,x): if x % i==0 : return True return False t=int(input()) for _ in range(t): n=int(input()) *mas,=map(int,input().split()) ind=[] for i in range(len(mas)): ind+=[i+1] s=sum(mas) if prov(s)==True : print(len(mas)) print(*ind) else : indez=0 for i in range(len(mas)): if prov(s-mas[i])==True : indez=i+1 break print(len(mas)-1) del ind[indez-1] print(*ind) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; (testlist_star_expr (star_expr * (expr (atom (name mas)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name mas)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation prov(x : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(2, x-1) do ( if x mod i = 0 then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for _ in range(T): n,m=map(int,input().split()) grid=[None]*n for i in range(n): grid[i]=input() visited=[[False]*m for i in range(n)] ans=True for i in range(n): for j in range(m): if grid[i][j]=='0' or visited[i][j]: continue else : up=i down=i left=j right=j while up>=0 and grid[up][j]=='1' : up-=1 up+=1 while down=0 and grid[i][left]=='1' : left-=1 left+=1 while righttoInteger() ; for _anon : Integer.subrange(0, T-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var grid : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; for i : Integer.subrange(0, n-1) do ( grid[i+1] := (OclFile["System.in"]).readLine()) ; var visited : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ false }, m))) ; var ans : boolean := true ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if grid[i+1][j+1] = '0' or visited[i+1][j+1] then ( continue ) else ( var up : OclAny := i ; var down : OclAny := i ; var left : OclAny := j ; var right : OclAny := j ; while up >= 0 & grid[up+1][j+1] = '1' do ( up := up - 1) ; up := up + 1 ; while (down->compareTo(n)) < 0 & grid[down+1][j+1] = '1' do ( down := down + 1) ; down := down - 1 ; while left >= 0 & grid[i+1][left+1] = '1' do ( left := left - 1) ; left := left + 1 ; while (right->compareTo(m)) < 0 & grid[i+1][right+1] = '1' do ( right := right + 1) ; right := right - 1 ; for a : Integer.subrange(up, down + 1-1) do ( for b : Integer.subrange(left, right + 1-1) do ( if grid[a+1][b+1] = '1' & not(visited[a+1][b+1]) then ( visited[a+1][b+1] := true ) else ( ans := false ))) ; if not(ans) then ( break ) else skip )) ; if not(ans) then ( break ) else skip) ; if not(ans) then ( execute ('NO')->display() ) else ( execute ('YES')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): d=int(input()) num=input().split() num=[int(i)for i in num] k=-1 m=-1 s=sum(num) for j in range(2,s): if s % j==0 : k=0 break for j in range(len(num)): if num[j]% 2==1 : m=j if k==0 : print(len(num)) for i in range(len(num)): print(i+1,end=" ") else : print(len(num)-1) for i in range(len(num)): if i!=m : print(i+1,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var num : OclAny := input().split() ; num := num->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var k : int := -1 ; var m : int := -1 ; var s : OclAny := (num)->sum() ; for j : Integer.subrange(2, s-1) do ( if s mod j = 0 then ( k := 0 ; break ) else skip) ; for j : Integer.subrange(0, (num)->size()-1) do ( if num[j+1] mod 2 = 1 then ( m := j ) else skip) ; if k = 0 then ( execute ((num)->size())->display() ; for i : Integer.subrange(0, (num)->size()-1) do ( execute (i + 1)->display()) ) else ( execute ((num)->size() - 1)->display() ; for i : Integer.subrange(0, (num)->size()-1) do ( if i /= m then ( execute (i + 1)->display() ) else skip) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: a=*map(int,s.split()),; s=sum(a);*r,=range(1,len(a)+1) if all(s % i for i in range(2,s)): del r[[x & 1 for x in a].index(1)] print(len(r),*r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var a : OclAny := (testlist_star_expr (star_expr * (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name s)) (trailer . (name split) (arguments ( ))))))))) ))))) ,); var s : OclAny := (a)->sum();(testlist_star_expr (star_expr * (expr (atom (name r)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name r)))) ,)} := Integer.subrange(1, (a)->size() + 1-1) ; if ((argument (test (logical_test (comparison (expr (expr (atom (name s))) % (expr (atom (name i))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))))))))->forAll( _x | _x = true ) then ( execute (r[a->select(x | true)->collect(x | (MathLib.bitwiseAnd(x, 1)))->indexOf(1) - 1+1])->isDeleted() ) else skip ; execute ((r)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for j in range(t): n=int(input()) a=list(map(int,input().split())) dx=-1 b=-1 sum=0 k=0 for i in range(n): sum=sum+a[i] if(a[i]% 2==1): b=a[i] dx=i for i in range(2,sum): if sum % i==0 : k=1 break if(k==1): print(n) else : print(n-1) for i in range(n): if(k==0)and(i==dx): continue else : print(i+1,end='') print('') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dx : int := -1 ; var b : int := -1 ; var sum : int := 0 ; var k : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + a[i+1] ; if (a[i+1] mod 2 = 1) then ( b := a[i+1] ; dx := i ) else skip) ; for i : Integer.subrange(2, sum-1) do ( if sum mod i = 0 then ( k := 1 ; break ) else skip) ; if (k = 1) then ( execute (n)->display() ) else ( execute (n - 1)->display() ) ; for i : Integer.subrange(0, n-1) do ( if (k = 0) & (i = dx) then ( continue ) else ( execute (i + 1)->display() )) ; execute ('')->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def is_composite(n): return any(n==i*(n//i)for i in range(2,n//2)) t=int(input()) for _ in range(t): n,a=int(input()),[int(i)for i in input().split()] s,res=sum(a),set(i+1 for i in range(n)) if not is_composite(s): res.remove(next(i+1 for i,a_i in enumerate(a)if a_i & 1==1)) print(len(res)),print(*res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var a : OclAny := null; Sequence{n,a} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))} ; var s : OclAny := null; var res : OclAny := null; Sequence{s,res} := Sequence{(a)->sum(),Set{}->union(((argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))))} ; if not(is_composite(s)) then ( execute ((((argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name a_i)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (expr (atom (name a_i))) & (expr (atom (number (integer 1)))))) == (comparison (expr (atom (number (integer 1)))))))))))).next()) /: res) ) else skip ; ((res)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display()); operation is_composite(n : OclAny) : OclAny pre: true post: true activity: return ((argument (test (logical_test (comparison (comparison (expr (atom (name n)))) == (comparison (expr (expr (atom (name i))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name n))) // (expr (atom (name i)))))))) )))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) // (expr (atom (number (integer 2)))))))))) )))))))))->exists( _x | _x = true ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def counDivisors(X): count=0 for i in range(1,X+1): if(X % i==0): count+=1 return count def countDivisorsMult(arr,n): mul=1 for i in range(n): mul*=arr[i] return counDivisors(mul) arr=[2,4,6] n=len(arr) print(countDivisorsMult(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{2}->union(Sequence{4}->union(Sequence{ 6 })) ; n := (arr)->size() ; execute (countDivisorsMult(arr, n))->display(); operation counDivisors(X : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(1, X + 1-1) do ( if (X mod i = 0) then ( count := count + 1 ) else skip) ; return count; operation countDivisorsMult(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var mul : int := 1 ; for i : Integer.subrange(0, n-1) do ( mul := mul * arr[i+1]) ; return counDivisors(mul); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printRepeating(arr,n): for i in range(0,n): index=arr[i]% n arr[index]+=n for i in range(0,n): if(arr[i]/n)>1 : print(i,end=" ") arr=[1,6,3,1,3,6,6] arr_size=len(arr) print("The repeating elements are:") printRepeating(arr,arr_size) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{6}->union(Sequence{3}->union(Sequence{1}->union(Sequence{3}->union(Sequence{6}->union(Sequence{ 6 })))))) ; var arr_size : int := (arr)->size() ; execute ("The repeating elements are:")->display() ; printRepeating(arr, arr_size); operation printRepeating(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( var index : int := arr[i+1] mod n ; arr[index+1] := arr[index+1] + n) ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] / n) > 1 then ( execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(a==0): return b else : return gcd(b % a,a) def solve(n,m,x,y,a,b): g=int(gcd(a,b)) a/=g b/=g k=int(min(n/a,m/b)) x1=int(x-(k*a-k*a/2)) x2=int(x+k*a/2) y1=int(y-(k*b-k*b/2)) y2=int(y+k*b/2) if(int(x1)<0): x2-=x1 x1=0 if(int(x2)>n): x1-=x2-n x2=n if(int(y1)<0): y2-=y1 y1=0 if(int(y2)>m): y1-=y2-m y2=m print(x1,"",y1,"",x2,"",y2,sep="") n=70 m=10 x=20 y=5 a=5 b=3 solve(n,m,x,y,a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 70 ; m := 10 ; x := 20 ; y := 5 ; a := 5 ; b := 3 ; solve(n, m, x, y, a, b); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0) then ( return b ) else ( return gcd(b mod a, a) ); operation solve(n : OclAny, m : OclAny, x : OclAny, y : OclAny, a : OclAny, b : OclAny) pre: true post: true activity: var g : int := ("" + ((gcd(a, b))))->toInteger() ; a := a / g ; b := b / g ; var k : int := ("" + ((Set{n / a, m / b}->min())))->toInteger() ; var x1 : int := ("" + ((x - (k * a - k * a / 2))))->toInteger() ; var x2 : int := ("" + ((x + k * a / 2)))->toInteger() ; var y1 : int := ("" + ((y - (k * b - k * b / 2))))->toInteger() ; var y2 : int := ("" + ((y + k * b / 2)))->toInteger() ; if (("" + ((x1)))->toInteger() < 0) then ( x2 := x2 - x1 ; x1 := 0 ) else skip ; if ((("" + ((x2)))->toInteger()->compareTo(n)) > 0) then ( x1 := x1 - x2 - n ; x2 := n ) else skip ; if (("" + ((y1)))->toInteger() < 0) then ( y2 := y2 - y1 ; y1 := 0 ) else skip ; if ((("" + ((y2)))->toInteger()->compareTo(m)) > 0) then ( y1 := y1 - y2 - m ; y2 := m ) else skip ; execute (x1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left tbl=[i**3 for i in range(1111)] while True : z=int(input()) if z==0 : break ma=0 for x in range(z-1,0,-1): y=bisect_left(tbl,tbl[z]-tbl[x])-1 if tbl[y]>tbl[x]: break ma=max(ma,tbl[x]+tbl[y]) print(tbl[z]-ma) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var tbl : Sequence := Integer.subrange(0, 1111-1)->select(i | true)->collect(i | ((i)->pow(3))) ; while true do ( var z : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if z = 0 then ( break ) else skip ; var ma : int := 0 ; for x : Integer.subrange(0 + 1, z - 1)->reverse() do ( var y : double := bisect_left(tbl, tbl[z+1] - tbl[x+1]) - 1 ; if (tbl[y+1]->compareTo(tbl[x+1])) > 0 then ( break ) else skip ; ma := Set{ma, tbl[x+1] + tbl[y+1]}->max()) ; execute (tbl[z+1] - ma)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=input() res=max(int(i)for i in n) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : String := (OclFile["System.in"]).readLine() ; var res : OclAny := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name n))))))))->max() ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=1/3 while 1 : z=int(input()) if z==0 : break m=0 zz=z*z*z for x in range(1,int(z/pow(2,a))+1): xx=x*x*x y=int(pow(zz-xx,a)) yy=y*y*y m=max(m,yy+xx) print(zz-m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : double := 1 / 3 ; while 1 do ( var z : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if z = 0 then ( break ) else skip ; var m : int := 0 ; var zz : int := z * z * z ; for x : Integer.subrange(1, ("" + ((z / (2)->pow(a))))->toInteger() + 1-1) do ( var xx : double := x * x * x ; var y : int := ("" + (((zz - xx)->pow(a))))->toInteger() ; var yy : int := y * y * y ; m := Set{m, yy + xx}->max()) ; execute (zz - m)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) pw_list=[len(input())for _ in range(n)] pw=len(input()) p=sorted(pw_list) head=p.index(pw) tail=n-list(reversed(p)).index(pw)-1 worst_case=head+((head)//k)*5+1 best_case=tail+(tail//k)*5+1 print(worst_case,best_case) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var pw_list : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((OclFile["System.in"]).readLine())->size())) ; var pw : int := ((OclFile["System.in"]).readLine())->size() ; var p : Sequence := pw_list->sort() ; var head : int := p->indexOf(pw) - 1 ; var tail : double := n - OclType["Sequence"]((p)->reverse())->indexOf(pw) - 1 - 1 ; var worst_case : int := head + ((head) div k) * 5 + 1 ; var best_case : OclAny := tail + (tail div k) * 5 + 1 ; execute (worst_case)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=1/3 while 1 : z=int(input()) if z==0 : break m,zz=0,z*z*z for x in range(1,int(z/pow(2,a))+1): xx=x*x*x y=int(pow(zz-xx,a)) yy=y*y*y m=max(m,yy+xx) print(zz-m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : double := 1 / 3 ; while 1 do ( var z : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if z = 0 then ( break ) else skip ; var m : OclAny := null; var zz : OclAny := null; Sequence{m,zz} := Sequence{0,z * z * z} ; for x : Integer.subrange(1, ("" + ((z / (2)->pow(a))))->toInteger() + 1-1) do ( var xx : double := x * x * x ; var y : int := ("" + (((zz - xx)->pow(a))))->toInteger() ; var yy : int := y * y * y ; var m : OclAny := Set{m, yy + xx}->max()) ; execute (zz - m)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : z=int(input())**3 if z==0 : break m,x=0,0 while 1 : x+=1 xx=x**3 y=int((z-xx)**(1/3)) if ytoInteger())->pow(3) ; if z = 0 then ( break ) else skip ; var m : OclAny := null; var x : OclAny := null; Sequence{m,x} := Sequence{0,0} ; while 1 do ( x := x + 1 ; var xx : double := (x)->pow(3) ; var y : int := ("" + ((((z - xx))->pow((1 / 3)))))->toInteger() ; if (y->compareTo(x)) < 0 then ( break ) else skip ; var m : OclAny := Set{m, (y)->pow(3) + xx}->max()) ; execute (z - m)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) def counter(l): d={} for i in l : if i not in d : d[i]=1 else : d[i]+=1 l2=[d[i]for i in l] return l2 n,=R() for i in range(n): length,=R() l=list(R()) q,=R() ql=[] for j in range(q): ql.append([j]+list(R())) ql.sort(key=lambda x : x[2]) breaker=False Max=ql[-1][-1] c=0 q3=[] l2=l.copy() for k in ql : if k[-1]<=Max : while ccollect( _x | (OclType["int"])->apply(_x) )) ; skip ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,)} := R->apply() ; for i : Integer.subrange(0, n-1) do ((testlist_star_expr (test (logical_test (comparison (expr (atom (name length)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name length)))))) ,)} := R->apply() ; l := (R->apply())->characters() ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name q)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name q)))))) ,)} := R->apply() ; var ql : Sequence := Sequence{} ; for j : Integer.subrange(0, q-1) do ( execute ((Sequence{ j }->union((R->apply())->characters())) : ql)) ; ql := ql->sort() ; var breaker : boolean := false ; var Max : OclAny := ql->last()->last() ; var c : int := 0 ; var q3 : Sequence := Sequence{} ; l2 := l->copy() ; for k : ql do ( if (k->last()->compareTo(Max)) <= 0 then ( while (c->compareTo(k->last())) < 0 do ( l2 := counter(l) ; if l2 = l then ( breaker := true ) else skip ; l := l2->copy() ; c := c + 1 ; if breaker then ( Max := c ; break ) else skip) ) else skip ; execute ((Sequence{l2[k[1+1] - 1+1]}->union(Sequence{ k->first() })) : q3)) ; q3 := q3->sort() ; for e : q3 do ( execute (e->first())->display())); operation counter(l : OclAny) : OclAny pre: true post: true activity: var d : OclAny := Set{} ; for i : l do ( if (d)->excludes(i) then ( d[i+1] := 1 ) else ( d[i+1] := d[i+1] + 1 )) ; var l2 : Sequence := l->select(i | true)->collect(i | (d[i+1])) ; return l2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter for _ in range(int(input())): n=int(input()) w=list(map(int,input().split())) c=int(n**0.5)+2 W=[w] for i in range(c): s=Counter(w) w=[s[i]for i in w] W.append(w) for i in range(int(input())): x,k=map(int,input().split()) k=min(k,c) print(W[k][x-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := ("" + (((n)->pow(0.5))))->toInteger() + 2 ; var W : Sequence := Sequence{ w } ; for i : Integer.subrange(0, c-1) do ( var s : OclAny := Counter(w) ; w := w->select(i | true)->collect(i | (s[i+1])) ; execute ((w) : W)) ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var k : OclAny := null; Sequence{x,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : OclAny := Set{k, c}->min() ; execute (W[k+1][x - 1+1])->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from typing import Counter for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) l=[a] for i in range(15): X=Counter(a) a=[X[i]for i in a] l.append(a) q=int(input()) for i in range(q): x,k=list(map(int,input().split())) print(l[min(15,k)][x-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : Sequence := Sequence{ a } ; for i : Integer.subrange(0, 15-1) do ( var X : OclAny := Counter(a) ; a := a->select(i | true)->collect(i | (X[i+1])) ; execute ((a) : l)) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( var x : OclAny := null; var k : OclAny := null; Sequence{x,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (l[Set{15, k}->min()+1][x - 1+1])->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from typing import Counter from math import log for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) l=[a] ceil=int(log(n,2))+1 for i in range(ceil): X=Counter(a) a=[X[i]for i in a] l.append(a) q=int(input()) for i in range(q): x,k=list(map(int,input().split())) print(l[min(ceil,k)][x-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : Sequence := Sequence{ a } ; var ceil : int := ("" + ((log(n, 2))))->toInteger() + 1 ; for i : Integer.subrange(0, ceil-1) do ( var X : OclAny := Counter(a) ; a := a->select(i | true)->collect(i | (X[i+1])) ; execute ((a) : l)) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( var x : OclAny := null; var k : OclAny := null; Sequence{x,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (l[Set{ceil, k}->min()+1][x - 1+1])->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,a): dp=[a] count=[0]*n for ai in a : count[ai-1]+=1 equal=False while not equal : new=[] new_count=[0]*n for i in range(n): new.append(count[a[i]-1]) new_count[new[i]-1]+=1 equal=True for i in range(n): equal=equal and(new[i]==dp[-1][i]) dp.append(new) count=new_count.copy() a=new.copy() return dp for t in range(int(input())): n=int(input()) a=list(map(int,input().split())) q=int(input()) dp=solve(n,a) for qi in range(q): x,k=map(int,input().split()) if ktoInteger()-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; dp := solve(n, a) ; for qi : Integer.subrange(0, q-1) do ( var x : OclAny := null; var k : OclAny := null; Sequence{x,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (k->compareTo((dp)->size())) < 0 then ( execute (dp[k+1][x - 1+1])->display() ) else ( execute (dp->last()[x - 1+1])->display() ))); operation solve(n : OclAny, a : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Sequence{ a } ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for ai : a do ( count[ai - 1+1] := count[ai - 1+1] + 1) ; var equal : boolean := false ; while not(equal) do ( var new : Sequence := Sequence{} ; var new_count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( execute ((count[a[i+1] - 1+1]) : new) ; new_count[new[i+1] - 1+1] := new_count[new[i+1] - 1+1] + 1) ; equal := true ; for i : Integer.subrange(0, n-1) do ( equal := equal & (new[i+1] = dp->last()[i+1])) ; execute ((new) : dp) ; count := new_count->copy() ; a := new->copy()) ; return dp; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find(a,b,k,n1,n2): s=set() for i in range(n2): s.add(b[i]) missing=0 for i in range(n1): if a[i]not in s : missing+=1 if missing==k : return a[i] return-1 a=[0,2,4,6,8,10,12,14,15] b=[4,10,6,8,12] n1=len(a) n2=len(b) k=3 print(find(a,b,k,n1,n2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{0}->union(Sequence{2}->union(Sequence{4}->union(Sequence{6}->union(Sequence{8}->union(Sequence{10}->union(Sequence{12}->union(Sequence{14}->union(Sequence{ 15 })))))))) ; b := Sequence{4}->union(Sequence{10}->union(Sequence{6}->union(Sequence{8}->union(Sequence{ 12 })))) ; n1 := (a)->size() ; n2 := (b)->size() ; k := 3 ; execute (find(a, b, k, n1, n2))->display(); operation find(a : OclAny, b : OclAny, k : OclAny, n1 : OclAny, n2 : OclAny) : OclAny pre: true post: true activity: var s : Set := Set{}->union(()) ; for i : Integer.subrange(0, n2-1) do ( execute ((b[i+1]) : s)) ; var missing : int := 0 ; for i : Integer.subrange(0, n1-1) do ( if (s)->excludes(a[i+1]) then ( missing := missing + 1 ) else skip ; if missing = k then ( return a[i+1] ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Dice(): top=1 n=2 e=4 w=3 s=5 dice=[1,2,3,4,5,6] top_front_right=[[-1,3,5,2,4,-1],[4,-1,1,6,-1,3],[2,6,-1,-1,1,5],[5,1,-1,-1,6,2],[3,-1,6,1,-1,4],[-1,4,2,5,3,-1]] def __init__(self,num): self.dice=num def roll(self,direction): if(direction=="N"): self.top,self.n,self.s=self.n,7-self.top,self.top elif(direction=="E"): self.top,self.e,self.w=self.e,7-self.top,self.top elif(direction=="W"): self.top,self.e,self.w=self.w,self.top,7-self.top elif(direction=="S"): self.top,self.n,self.s=self.s,self.top,7-self.top d=list(map(int,input().split())) dice=Dice(d) n=int(input()) for i in range(n): top,front=map(int,input().split()) print(d[dice.top_front_right[d.index(top)][d.index(front)]-1]) ------------------------------------------------------------ OCL File: --------- class Dice { static operation newDice() : Dice pre: true post: Dice->exists( _x | result = _x ); static attribute top : int := 1; static attribute n : int := 2; static attribute e : int := 4; static attribute w : int := 3; static attribute s : int := 5; static attribute dice : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))))); static attribute top_front_right : Sequence := Sequence{Sequence{-1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ -1 })))))}->union(Sequence{Sequence{4}->union(Sequence{-1}->union(Sequence{1}->union(Sequence{6}->union(Sequence{-1}->union(Sequence{ 3 })))))}->union(Sequence{Sequence{2}->union(Sequence{6}->union(Sequence{-1}->union(Sequence{-1}->union(Sequence{1}->union(Sequence{ 5 })))))}->union(Sequence{Sequence{5}->union(Sequence{1}->union(Sequence{-1}->union(Sequence{-1}->union(Sequence{6}->union(Sequence{ 2 })))))}->union(Sequence{Sequence{3}->union(Sequence{-1}->union(Sequence{6}->union(Sequence{1}->union(Sequence{-1}->union(Sequence{ 4 })))))}->union(Sequence{ Sequence{-1}->union(Sequence{4}->union(Sequence{2}->union(Sequence{5}->union(Sequence{3}->union(Sequence{ -1 }))))) }))))); attribute dice : OclAny := num; operation initialise(num : OclAny) : pre: true post: true activity: self.dice := num; return self; operation roll(direction : OclAny) pre: true post: true activity: if (direction = "N") then ( var self.top : OclAny := null; var self.n : OclAny := null; var self.s : OclAny := null; Sequence{self.top,self.n,self.s} := Sequence{self.n,7 - self.top,self.top} ) else (if (direction = "E") then ( var self.top : OclAny := null; var self.e : OclAny := null; var self.w : OclAny := null; Sequence{self.top,self.e,self.w} := Sequence{self.e,7 - self.top,self.top} ) else (if (direction = "W") then ( var self.top : OclAny := null; var self.e : OclAny := null; var self.w : OclAny := null; Sequence{self.top,self.e,self.w} := Sequence{self.w,self.top,7 - self.top} ) else (if (direction = "S") then ( var self.top : OclAny := null; var self.n : OclAny := null; var self.s : OclAny := null; Sequence{self.top,self.n,self.s} := Sequence{self.s,self.top,7 - self.top} ) else skip ) ) ) ; } class FromPython { operation initialise() pre: true post: true activity: skip ; var d : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; dice := (Dice.newDice()).initialise(d) ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var front : OclAny := null; Sequence{top,front} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (d[dice.top_front_right[d->indexOf(top) - 1+1][d->indexOf(front) - 1+1] - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): min_count=-1 num=str(input()) for j in range(len(num)): val=ord(num[j])-ord('0') if(val>min_count): min_count=val print(min_count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var min_count : int := -1 ; var num : String := ("" + (((OclFile["System.in"]).readLine()))) ; for j : Integer.subrange(0, (num)->size()-1) do ( var val : double := (num[j+1])->char2byte() - ('0')->char2byte() ; if ((val->compareTo(min_count)) > 0) then ( min_count := val ) else skip) ; execute (min_count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input n,k=map(int,I().split()) a=sorted(len(I())for _ in '0'*n) p=len(I()) t=a.index(p) a,b=t,t+a.count(p) print(1+a+a//k*5,b+(b-1)//k*5) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (I().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name I)) (trailer (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (expr (atom '0')) * (expr (atom (name n))))))))->sort() ; var p : int := (I())->size() ; var t : int := a->indexOf(p) - 1 ; var b : OclAny := null; Sequence{a,b} := Sequence{t,t + a->count(p)} ; execute (1->union(a) + a div k * 5)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inp=[i for i in input().split()] n=int(input()) array=[[i for i in input().split()]for i in range(n)] for i2 in range(n): fuck="" for i in range(1,33): if(i<=20 and i % 5==0)or i==22 or i==27 or i==28 : s="N" else : s="E" if s=="E" : a=[] a.append(inp[3]) a.append(inp[1]) a.append(inp[0]) a.append(inp[5]) a.append(inp[4]) a.append(inp[2]) inp=a if inp[0]==array[i2][0]and inp[1]==array[i2][1]and inp[2]!=fuck : print(inp[2]) fuck=inp[2] elif s=="N" : a=[] a.append(inp[1]) a.append(inp[5]) a.append(inp[2]) a.append(inp[3]) a.append(inp[0]) a.append(inp[4]) inp=a if inp[0]==array[i2][0]and inp[1]==array[i2][1]and inp[2]!=fuck : print(inp[2]) fuck=inp[2] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inp : Sequence := input().split()->select(i | true)->collect(i | (i)) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var array : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (input().split()->select(i | true)->collect(i | (i)))) ; for i2 : Integer.subrange(0, n-1) do ( var fuck : String := "" ; for i : Integer.subrange(1, 33-1) do ( if (i <= 20 & i mod 5 = 0) or i = 22 or i = 27 or i = 28 then ( var s : String := "N" ) else ( s := "E" ) ; if s = "E" then ( var a : Sequence := Sequence{} ; execute ((inp[3+1]) : a) ; execute ((inp[1+1]) : a) ; execute ((inp->first()) : a) ; execute ((inp[5+1]) : a) ; execute ((inp[4+1]) : a) ; execute ((inp[2+1]) : a) ; inp := a ; if inp->first() = array[i2+1]->first() & inp[1+1] = array[i2+1][1+1] & inp[2+1] /= fuck then ( execute (inp[2+1])->display() ; fuck := inp[2+1] ) else skip ) else (if s = "N" then ( a := Sequence{} ; execute ((inp[1+1]) : a) ; execute ((inp[5+1]) : a) ; execute ((inp[2+1]) : a) ; execute ((inp[3+1]) : a) ; execute ((inp->first()) : a) ; execute ((inp[4+1]) : a) ; inp := a ; if inp->first() = array[i2+1]->first() & inp[1+1] = array[i2+1][1+1] & inp[2+1] /= fuck then ( execute (inp[2+1])->display() ; fuck := inp[2+1] ) else skip ) else skip))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys face=sys.stdin.readline().split() right=[[None for front in range(6)]for top in range(6)] right[0][1]=right[1][5]=right[5][4]=right[4][0]=3-1 right[1][0]=right[5][1]=right[4][5]=right[0][4]=4-1 right[0][2]=right[2][5]=right[5][3]=right[3][0]=5-1 right[2][0]=right[5][2]=right[3][5]=right[0][3]=2-1 right[3][1]=right[1][2]=right[2][4]=right[4][3]=1-1 right[1][3]=right[2][1]=right[4][2]=right[3][4]=6-1 q=int(sys.stdin.readline()) for i in range(q): top,front=sys.stdin.readline().split() r_index=right[face.index(top)][face.index(front)] print(face[r_index]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var face : OclAny := sys.stdin.readLine().split() ; var right : Sequence := Integer.subrange(0, 6-1)->select(top | true)->collect(top | (Integer.subrange(0, 6-1)->select(front | true)->collect(front | (null)))) ; right->first()[1+1] := right->first()[1+1](assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name right)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 5))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name right)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 5))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 4))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name right)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 4))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (number (integer 3)))) - (expr (atom (number (integer 1))))))))))) ; right[1+1]->first() := right[1+1]->first()(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name right)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 5))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name right)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 4))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 5))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name right)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 4))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (number (integer 4)))) - (expr (atom (number (integer 1))))))))))) ; right->first()[2+1] := right->first()[2+1](assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name right)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 5))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name right)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 5))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 3))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name right)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 3))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (number (integer 5)))) - (expr (atom (number (integer 1))))))))))) ; right[2+1]->first() := right[2+1]->first()(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name right)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 5))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name right)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 3))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 5))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name right)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 3))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) - (expr (atom (number (integer 1))))))))))) ; right[3+1][1+1] := right[3+1][1+1](assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name right)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name right)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 4))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name right)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 4))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 3))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) - (expr (atom (number (integer 1))))))))))) ; right[1+1][3+1] := right[1+1][3+1](assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name right)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name right)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 4))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name right)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 3))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 4))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (number (integer 6)))) - (expr (atom (number (integer 1))))))))))) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( var top : OclAny := null; var front : OclAny := null; Sequence{top,front} := sys.stdin.readLine().split() ; var r_index : OclAny := right[face->indexOf(top) - 1+1][face->indexOf(front) - 1+1] ; execute (face[r_index+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Dice : def __init__(self,top=1,front=2,left=4,right=3,back=5,bottom=6): self.d={"TOP" : top,"FRONT" : front,"LEFT" : left,"RIGHT" : right,"BACK" : back,"BOTTOM" : bottom} def roll_x(self): self._roll("TOP","FRONT","BOTTOM","BACK") def roll_y(self): self._roll("FRONT","LEFT","BACK","RIGHT") def roll_z(self): self._roll("TOP","LEFT","BOTTOM","RIGHT") def _roll(self,a,b,c,d): self.d[a],self.d[b],self.d[c],self.d[d]=self.d[b],self.d[c],self.d[d],self.d[a] def all_rolls(self): ret=[] for i in range(6): if i % 2 : self.roll_x() else : self.roll_y() for j in range(4): self.roll_z() t=self.d.copy() ret.append(t) return ret d=list(map(int,input().split())) dd=Dice(d[0],d[1],d[3],d[2],d[4],d[5]) l=dd.all_rolls() q=int(input()) for i in range(q): t,f=list(map(int,input().split())) for ele in l : if ele["TOP"]==t and ele["FRONT"]==f : print(ele["RIGHT"]) break ------------------------------------------------------------ OCL File: --------- class Dice { static operation newDice() : Dice pre: true post: Dice->exists( _x | result = _x ); attribute d : Map := Map{ "TOP" |-> top }->union(Map{ "FRONT" |-> front }->union(Map{ "LEFT" |-> left }->union(Map{ "RIGHT" |-> right }->union(Map{ "BACK" |-> back }->union(Map{ "BOTTOM" |-> bottom }))))); operation initialise(top : int,front : int,left : int,right : int,back : int,bottom : int) : Dice pre: true post: true activity: self.d := Map{ "TOP" |-> top }->union(Map{ "FRONT" |-> front }->union(Map{ "LEFT" |-> left }->union(Map{ "RIGHT" |-> right }->union(Map{ "BACK" |-> back }->union(Map{ "BOTTOM" |-> bottom }))))); return self; operation roll_x() pre: true post: true activity: self._roll("TOP", "FRONT", "BOTTOM", "BACK"); operation roll_y() pre: true post: true activity: self._roll("FRONT", "LEFT", "BACK", "RIGHT"); operation roll_z() pre: true post: true activity: self._roll("TOP", "LEFT", "BOTTOM", "RIGHT"); operation _roll(a : OclAny,b : OclAny,c : OclAny,d : OclAny) pre: true post: true activity: var self.d[a+1] : OclAny := null; var self.d[b+1] : OclAny := null; var self.d[c+1] : OclAny := null; var self.d[d+1] : OclAny := null; Sequence{self.d[a+1],self.d[b+1],self.d[c+1],self.d[d+1]} := Sequence{self.d[b+1],self.d[c+1],self.d[d+1],self.d[a+1]}; operation all_rolls() : OclAny pre: true post: true activity: var ret : Sequence := Sequence{} ; for i : Integer.subrange(0, 6-1) do ( if i mod 2 then ( self.roll_x() ) else ( self.roll_y() ) ; for j : Integer.subrange(0, 4-1) do ( self.roll_z() ; var t : OclAny := self.d->copy() ; execute ((t) : ret))) ; return ret; } class FromPython { operation initialise() pre: true post: true activity: skip ; d := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dd : Dice := (Dice.newDice()).initialise(d->first(), d[1+1], d[3+1], d[2+1], d[4+1], d[5+1]) ; var l : OclAny := dd.all_rolls() ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( var f : OclAny := null; Sequence{t,f} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for ele : l do ( if ele->at("TOP") = t & ele->at("FRONT") = f then ( execute (ele->at("RIGHT"))->display() ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rotate(arr,i): if i=='W' : arr=[arr[k-1]for k in[3,2,6,1,5,4]] if i=='E' : arr=[arr[k-1]for k in[4,2,1,6,5,3]] if i=='N' : arr=[arr[k-1]for k in[2,6,3,4,1,5]] if i=='S' : arr=[arr[k-1]for k in[5,1,3,4,6,2]] return arr arr=input().split() deck=[] for i in 'W'*4 : arr=rotate(arr,i) for k in 'NNNN' : arr=rotate(arr,k) deck.append(arr) arr=rotate(arr,'N') arr=rotate(arr,'W') for k in 'NNNN' : arr=rotate(arr,k) deck.append(arr) arr=rotate(arr,'W') arr=rotate(arr,'W') for k in 'NNNN' : arr=rotate(arr,k) deck.append(arr) n=int(input()) for i in range(n): query=input().split() for v in deck : if v[0]==query[0]and v[1]==query[1]: print(v[2]) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := input().split() ; var deck : Sequence := Sequence{} ; for i : StringLib.nCopies('W', 4) do ( arr := rotate(arr, i) ; for k : 'NNNN'->characters() do ( arr := rotate(arr, k) ; execute ((arr) : deck))) ; arr := rotate(arr, 'N') ; arr := rotate(arr, 'W') ; for k : 'NNNN'->characters() do ( arr := rotate(arr, k) ; execute ((arr) : deck)) ; arr := rotate(arr, 'W') ; arr := rotate(arr, 'W') ; for k : 'NNNN'->characters() do ( arr := rotate(arr, k) ; execute ((arr) : deck)) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var query : OclAny := input().split() ; for v : deck do ( if v->first() = query->first() & v[1+1] = query[1+1] then ( execute (v[2+1])->display() ; break ) else skip)); operation rotate(arr : OclAny, i : OclAny) : OclAny pre: true post: true activity: if i = 'W' then ( arr := Sequence{3}->union(Sequence{2}->union(Sequence{6}->union(Sequence{1}->union(Sequence{5}->union(Sequence{ 4 })))))->select(k | true)->collect(k | (arr[k - 1+1])) ) else skip ; if i = 'E' then ( arr := Sequence{4}->union(Sequence{2}->union(Sequence{1}->union(Sequence{6}->union(Sequence{5}->union(Sequence{ 3 })))))->select(k | true)->collect(k | (arr[k - 1+1])) ) else skip ; if i = 'N' then ( arr := Sequence{2}->union(Sequence{6}->union(Sequence{3}->union(Sequence{4}->union(Sequence{1}->union(Sequence{ 5 })))))->select(k | true)->collect(k | (arr[k - 1+1])) ) else skip ; if i = 'S' then ( arr := Sequence{5}->union(Sequence{1}->union(Sequence{3}->union(Sequence{4}->union(Sequence{6}->union(Sequence{ 2 })))))->select(k | true)->collect(k | (arr[k - 1+1])) ) else skip ; return arr; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=['']*100 a[11],a[12],a[13],a[14],a[15]='a','b','c','d','e' a[21],a[22],a[23],a[24],a[25]='f','g','h','i','j' a[31],a[32],a[33],a[34],a[35]='k','l','m','n','o' a[41],a[42],a[43],a[44],a[45]='p','q','r','s','t' a[51],a[52],a[53],a[54],a[55]='u','v','w','x','y' a[61],a[62],a[63],a[64],a[65]='z','.','?','!','' while True : try : buf=list(input()) except : break f=True ans='' for i in range(0,len(buf),2): if i+1>=len(buf): f=False break if buf[i].isdigit()and buf[i+1].isdigit(): k=int(buf[i]+buf[i+1]) if a[k]!='' : ans+=a[k] else : f=False break print(ans if f else "NA") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := MatrixLib.elementwiseMult(Sequence{ '' }, 100) ; var a[11+1] : OclAny := null; var a[12+1] : OclAny := null; var a[13+1] : OclAny := null; var a[14+1] : OclAny := null; var a[15+1] : OclAny := null; Sequence{a[11+1],a[12+1],a[13+1],a[14+1],a[15+1]} := Sequence{'a','b','c','d','e'} ; var a[21+1] : OclAny := null; var a[22+1] : OclAny := null; var a[23+1] : OclAny := null; var a[24+1] : OclAny := null; var a[25+1] : OclAny := null; Sequence{a[21+1],a[22+1],a[23+1],a[24+1],a[25+1]} := Sequence{'f','g','h','i','j'} ; var a[31+1] : OclAny := null; var a[32+1] : OclAny := null; var a[33+1] : OclAny := null; var a[34+1] : OclAny := null; var a[35+1] : OclAny := null; Sequence{a[31+1],a[32+1],a[33+1],a[34+1],a[35+1]} := Sequence{'k','l','m','n','o'} ; var a[41+1] : OclAny := null; var a[42+1] : OclAny := null; var a[43+1] : OclAny := null; var a[44+1] : OclAny := null; var a[45+1] : OclAny := null; Sequence{a[41+1],a[42+1],a[43+1],a[44+1],a[45+1]} := Sequence{'p','q','r','s','t'} ; var a[51+1] : OclAny := null; var a[52+1] : OclAny := null; var a[53+1] : OclAny := null; var a[54+1] : OclAny := null; var a[55+1] : OclAny := null; Sequence{a[51+1],a[52+1],a[53+1],a[54+1],a[55+1]} := Sequence{'u','v','w','x','y'} ; var a[61+1] : OclAny := null; var a[62+1] : OclAny := null; var a[63+1] : OclAny := null; var a[64+1] : OclAny := null; var a[65+1] : OclAny := null; Sequence{a[61+1],a[62+1],a[63+1],a[64+1],a[65+1]} := Sequence{'z','.','?','!',''} ; while true do ( try ( var buf : Sequence := ((OclFile["System.in"]).readLine())->characters()) catch (_e : OclException) do ( break) ; var f : boolean := true ; var ans : String := '' ; for i : Integer.subrange(0, (buf)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( if (i + 1->compareTo((buf)->size())) >= 0 then ( f := false ; break ) else skip ; if buf[i+1]->matches("[0-9]*") & buf[i + 1+1]->matches("[0-9]*") then ( var k : int := ("" + ((buf[i+1] + buf[i + 1+1])))->toInteger() ; if a[k+1] /= '' then ( ans := ans + a[k+1] ) else ( f := false ; break ) ) else skip) ; execute (if f then ans else "NA" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys convert={"1" :{"1" : "a","2" : "b","3" : "c","4" : "d","5" : "e"},"2" :{"1" : "f","2" : "g","3" : "h","4" : "i","5" : "j"},"3" :{"1" : "k","2" : "l","3" : "m","4" : "n","5" : "o"},"4" :{"1" : "p","2" : "q","3" : "r","4" : "s","5" : "t"},"5" :{"1" : "u","2" : "v","3" : "w","4" : "x","5" : "y"},"6" :{"1" : "z","2" : ".","3" : "?","4" : "!","5" : ""},} for line in sys.stdin : line=line[:-1] if len(line)% 2!=0 : print("NA") continue message="" line=iter(line) for first,second in zip(*[line,line]): if "1"<=first<="6" and "1"<=second<="5" : message+=convert.get(first).get(second) else : print("NA") break else : print(message) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var convert : Map := Map{ "1" |-> Map{ "1" |-> "a" }->union(Map{ "2" |-> "b" }->union(Map{ "3" |-> "c" }->union(Map{ "4" |-> "d" }->union(Map{ "5" |-> "e" })))) }->union(Map{ "2" |-> Map{ "1" |-> "f" }->union(Map{ "2" |-> "g" }->union(Map{ "3" |-> "h" }->union(Map{ "4" |-> "i" }->union(Map{ "5" |-> "j" })))) }->union(Map{ "3" |-> Map{ "1" |-> "k" }->union(Map{ "2" |-> "l" }->union(Map{ "3" |-> "m" }->union(Map{ "4" |-> "n" }->union(Map{ "5" |-> "o" })))) }->union(Map{ "4" |-> Map{ "1" |-> "p" }->union(Map{ "2" |-> "q" }->union(Map{ "3" |-> "r" }->union(Map{ "4" |-> "s" }->union(Map{ "5" |-> "t" })))) }->union(Map{ "5" |-> Map{ "1" |-> "u" }->union(Map{ "2" |-> "v" }->union(Map{ "3" |-> "w" }->union(Map{ "4" |-> "x" }->union(Map{ "5" |-> "y" })))) }->union((dictorsetmaker (test (logical_test (comparison (expr (atom "6"))))) : (test (logical_test (comparison (expr (atom { (dictorsetmaker (test (logical_test (comparison (expr (atom "1"))))) : (test (logical_test (comparison (expr (atom "z"))))) , (test (logical_test (comparison (expr (atom "2"))))) : (test (logical_test (comparison (expr (atom "."))))) , (test (logical_test (comparison (expr (atom "3"))))) : (test (logical_test (comparison (expr (atom "?"))))) , (test (logical_test (comparison (expr (atom "4"))))) : (test (logical_test (comparison (expr (atom "!"))))) , (test (logical_test (comparison (expr (atom "5"))))) : (test (logical_test (comparison (expr (atom "")))))) }))))) ,)))))) ; for line : OclFile["System.in"] do ( var line : OclAny := line->front() ; if (line)->size() mod 2 /= 0 then ( execute ("NA")->display() ; continue ) else skip ; var message : String := "" ; line := OclIterator.newOclIterator_Sequence(line) ; (compound_stmt for (exprlist (expr (atom (name first))) , (expr (atom (name second)))) in (testlist (test (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name line)))))) , (test (logical_test (comparison (expr (atom (name line))))))) ]))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (comparison (expr (atom "1"))) <= (comparison (expr (atom (name first))))) <= (comparison (expr (atom "6"))))) and (logical_test (comparison (comparison (comparison (expr (atom "1"))) <= (comparison (expr (atom (name second))))) <= (comparison (expr (atom "5"))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name message)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name convert)) (trailer . (name get) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name first)))))))) ))) (trailer . (name get) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name second)))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NA"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name message)))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def message(numbers): numbers=str(numbers) message="" while(len(numbers)>0): num=numbers[: 2] if len(num)==1 : return "NA" if int(num[0])>6 or int(num[0])<=0 : return "NA" if int(num[1])>5 or int(num[1])<=0 : return "NA" code=(int(num[0])-1)*5+int(num[1]) if code>30 : return "NA" if code==27 : message+="." elif code==28 : message+="?" elif code==29 : message+="!" elif code==30 : message+=" " else : message+=chr(code-1+ord('a')) numbers=numbers[2 : :] return message while True : try : n=input() print(message(n)) except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( try ( var n : String := (OclFile["System.in"]).readLine() ; execute (message(n))->display()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); operation message(numbers : OclAny) : OclAny pre: true post: true activity: numbers := ("" + ((numbers))) ; var message : String := "" ; while ((numbers)->size() > 0) do ( var num : OclAny := numbers.subrange(1,2) ; if (num)->size() = 1 then ( return "NA" ) else skip ; if ("" + ((num->first())))->toInteger() > 6 or ("" + ((num->first())))->toInteger() <= 0 then ( return "NA" ) else skip ; if ("" + ((num[1+1])))->toInteger() > 5 or ("" + ((num[1+1])))->toInteger() <= 0 then ( return "NA" ) else skip ; var code : double := (("" + ((num->first())))->toInteger() - 1) * 5 + ("" + ((num[1+1])))->toInteger() ; if code > 30 then ( return "NA" ) else skip ; if code = 27 then ( message := message + "." ) else (if code = 28 then ( message := message + "?" ) else (if code = 29 then ( message := message + "!" ) else (if code = 30 then ( message := message + " " ) else ( message := message + (code - 1 + ('a')->char2byte())->byte2char() ) ) ) ) ; numbers := numbers(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop :))) ; return message; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def decode(code): result='' while code : try : c=code[: 2] result+=Code_table[c] code=code[2 :] except : return 'NA' return result Code_table={'11' : 'a','21' : 'f','31' : 'k','41' : 'p','51' : 'u','61' : 'z','12' : 'b','22' : 'g','32' : 'l','42' : 'q','52' : 'v','62' : '.','13' : 'c','23' : 'h','33' : 'm','43' : 'r','53' : 'w','63' : '?','14' : 'd','24' : 'i','34' : 'n','44' : 's','54' : 'x','64' : '!','15' : 'e','25' : 'j','35' : 'o','45' : 't','55' : 'y','65' : ' ',} def main(args): for line in sys.stdin : result=decode(line.strip()) print(result) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var Code_table : Map := Map{ '11' |-> 'a' }->union(Map{ '21' |-> 'f' }->union(Map{ '31' |-> 'k' }->union(Map{ '41' |-> 'p' }->union(Map{ '51' |-> 'u' }->union(Map{ '61' |-> 'z' }->union(Map{ '12' |-> 'b' }->union(Map{ '22' |-> 'g' }->union(Map{ '32' |-> 'l' }->union(Map{ '42' |-> 'q' }->union(Map{ '52' |-> 'v' }->union(Map{ '62' |-> '.' }->union(Map{ '13' |-> 'c' }->union(Map{ '23' |-> 'h' }->union(Map{ '33' |-> 'm' }->union(Map{ '43' |-> 'r' }->union(Map{ '53' |-> 'w' }->union(Map{ '63' |-> '?' }->union(Map{ '14' |-> 'd' }->union(Map{ '24' |-> 'i' }->union(Map{ '34' |-> 'n' }->union(Map{ '44' |-> 's' }->union(Map{ '54' |-> 'x' }->union(Map{ '64' |-> '!' }->union(Map{ '15' |-> 'e' }->union(Map{ '25' |-> 'j' }->union(Map{ '35' |-> 'o' }->union(Map{ '45' |-> 't' }->union(Map{ '55' |-> 'y' }->union((dictorsetmaker (test (logical_test (comparison (expr (atom '65'))))) : (test (logical_test (comparison (expr (atom ' '))))) ,)))))))))))))))))))))))))))))) ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation decode(code : OclAny) : OclAny pre: true post: true activity: var result : String := '' ; while code do ( try ( var c : OclAny := code.subrange(1,2) ; result := result + Code_table[c+1] ; code := code.subrange(2+1)) catch (_e : OclException) do ( return 'NA') ) ; return result; operation main(args : OclAny) pre: true post: true activity: for line : OclFile["System.in"] do ( result := decode(line->trim()) ; execute (result)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- L=[] L.append(list("abcde")) L.append(list("fghij")) L.append(list("klmno")) L.append(list("pqrst")) L.append(list("uvwxy")) L.append(list("z.?! ")) while True : try : tmp=input() l=[int(x)-1 for x in list(tmp)] except : break if len(l)% 2>0 : print("NA") continue ferr=0 M=[] for i,j in zip(l[0 : : 2],l[1 : : 2]): if i not in range(len(L))or j not in range(len(L[0])): ferr+=1 else : M.append(L[i][j]) if ferr>0 : print("NA") else : print("".join(M)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var L : Sequence := Sequence{} ; execute ((("abcde")->characters()) : L) ; execute ((("fghij")->characters()) : L) ; execute ((("klmno")->characters()) : L) ; execute ((("pqrst")->characters()) : L) ; execute ((("uvwxy")->characters()) : L) ; execute ((("z.?! ")->characters()) : L) ; while true do ( try ( var tmp : String := (OclFile["System.in"]).readLine() ; var l : Sequence := (tmp)->characters()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1))) catch (_e : OclException) do ( break) ; if (l)->size() mod 2 > 0 then ( execute ("NA")->display() ; continue ) else skip ; var ferr : int := 0 ; var M : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, l(subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{l(subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->at(_indx), l(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if (Integer.subrange(0, (L)->size()-1))->excludes(i) or (Integer.subrange(0, (L->first())->size()-1))->excludes(j) then ( ferr := ferr + 1 ) else ( execute ((L[i+1][j+1]) : M) )) ; if ferr > 0 then ( execute ("NA")->display() ) else ( execute (StringLib.sumStringsWithSeparator((M), ""))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=int(input()) MOD=10**9 x=(-s)% MOD y=(s+x)//MOD print(0,0,10**9,1,x,y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var MOD : double := (10)->pow(9) ; var x : int := (-s) mod MOD ; var y : int := (s + x) div MOD ; execute (0)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() for i in range(len(s)-25): substring=s[i : i+26] if all(substring.count(char)==1 for char in substring if char!="?"): setsub=set(substring) for char in set("MNBVCXZLKJHGFDSAQPWOEIRUYT")-setsub : substring=substring.replace("?",char,1) s=s[0 : i]+substring+s[i+26 :] ans=s.replace("?","A") break else : ans="-1" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))) - (expr (atom (number (integer 25)))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name substring)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))) : (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 26)))))))))) ])))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name all)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (comparison (expr (atom (name substring)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name char)))))))) ))))) == (comparison (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name char)))) in (logical_test (comparison (expr (atom (name substring))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name char)))) != (comparison (expr (atom "?")))))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name setsub)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name substring)))))))) ))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name char)))) in (testlist (test (logical_test (comparison (expr (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "MNBVCXZLKJHGFDSAQPWOEIRUYT"))))))) )))) - (expr (atom (name setsub)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name substring)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name substring)) (trailer . (name replace) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "?")))))) , (argument (test (logical_test (comparison (expr (atom (name char))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))) : (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name substring)))) + (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 26)))))))) :)) ]))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)) (trailer . (name replace) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "?")))))) , (argument (test (logical_test (comparison (expr (atom "A"))))))) ))))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom "-1")))))))))))))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,k=list(map(int,input().split())) arr=[input()for _ in range(n)] correct_length=len(input()) less_length_passwords,same_length_passwords=0,0 for element in arr : check_length=len(element) if check_length==correct_length : same_length_passwords+=1 elif check_lengthcollect( _x | (OclType["int"])->apply(_x) )) ; var arr : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var correct_length : int := ((OclFile["System.in"]).readLine())->size() ; var less_length_passwords : OclAny := null; var same_length_passwords : OclAny := null; Sequence{less_length_passwords,same_length_passwords} := Sequence{0,0} ; for element : arr do ( var check_length : int := (element)->size() ; if check_length = correct_length then ( same_length_passwords := same_length_passwords + 1 ) else (if (check_length->compareTo(correct_length)) < 0 then ( less_length_passwords := less_length_passwords + 1 ) else skip)) ; var min_time : int := (less_length_passwords div k) * 5 + less_length_passwords + 1 ; var max_time : int := (((less_length_passwords + same_length_passwords - 1) div k) * 5 + less_length_passwords + same_length_passwords) ; execute (min_time)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): num=input() li=list(map(int,num)) print(max(li)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var num : String := (OclFile["System.in"]).readLine() ; var li : Sequence := ((num)->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((li)->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque,Counter from heapq import heappush,heappop,heapify from itertools import permutations,accumulate,combinations,combinations_with_replacement from math import sqrt,ceil,floor,factorial from bisect import bisect_left,bisect_right,insort_left,insort_right from copy import deepcopy from operator import itemgetter from functools import reduce,lru_cache from fractions import gcd import sys def input(): return sys.stdin.readline().rstrip() def I(): return int(input()) def Is(): return(int(x)for x in input().split()) def LI(): return list(Is()) def TI(): return tuple(Is()) def IR(n): return[I()for _ in range(n)] def LIR(n): return[LI()for _ in range(n)] def TIR(n): return[TI()for _ in range(n)] def S(): return input() def Ss(): return input().split() def LS(): return list(S()) def SR(n): return[S()for _ in range(n)] def SsR(n): return[Ss()for _ in range(n)] def LSR(n): return[LS()for _ in range(n)] sys.setrecursionlimit(10**6) MOD=10**9+7 INF=10**18 s=I() a=s//10**9 b=s % 10**9 if a+1>10**9 : print(0,0,10**9,0,0,10**9) else : print(0,0,10**9,10**9-b,1,a+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(6)) ; var MOD : double := (10)->pow(9) + 7 ; var INF : double := (10)->pow(18) ; var s : OclAny := I() ; var a : int := s div (10)->pow(9) ; var b : int := s mod (10)->pow(9) ; if (a + 1->compareTo((10)->pow(9))) > 0 then ( execute (0)->display() ) else ( execute (0)->display() ); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation Is() : OclAny pre: true post: true activity: return Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))}; operation LI() : OclAny pre: true post: true activity: return (Is()); operation TI() : OclAny pre: true post: true activity: return (Is()); operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI())); operation TIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (TI())); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation Ss() : OclAny pre: true post: true activity: return input().split(); operation LS() : OclAny pre: true post: true activity: return (S()); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (S())); operation SsR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Ss())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LS())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np n=int(input()) a1=0 a2=0 b1=0 b2=0 temp=np.round(np.sqrt(float(n))) temp=int(temp) if n==temp*temp : a1=temp b2=temp a2=0 b1=0 else : a1=temp+1 b2=temp+1 over=a1*b2 diff=over-n if diff>1e9 : a1=temp over=a1*b2 diff=over-n if diff>1e9 : b2=temp over=a1*b2 diff=over-n a2=1 b1=int(diff) print("0 0 "+str(a1)+" "+str(a2)+" "+str(b1)+" "+str(b2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a1 : int := 0 ; var a2 : int := 0 ; var b1 : int := 0 ; var b2 : int := 0 ; var temp : Sequence := MatrixLib.elementwiseApply(MatrixLib.elementwiseApply(("" + ((n)))->toReal(), lambda x : double in (x->sqrt())), lambda x : double in (x->round())) ; temp := ("" + ((temp)))->toInteger() ; if n = MatrixLib.dotProduct(temp,temp) then ( a1 := temp ; b2 := temp ; a2 := 0 ; b1 := 0 ) else ( a1 := MatrixLib.elementwiseAdd(temp, 1) ; b2 := MatrixLib.elementwiseAdd(temp, 1) ; var over : int := a1 * b2 ; var diff : double := over - n ; if diff > ("1e9")->toReal() then ( a1 := temp ; over := a1 * b2 ; diff := over - n ) else skip ; if diff > ("1e9")->toReal() then ( b2 := temp ; over := a1 * b2 ; diff := over - n ) else skip ; a2 := 1 ; b1 := ("" + ((diff)))->toInteger() ) ; execute ("0 0 " + ("" + ((a1))) + " " + ("" + ((a2))) + " " + ("" + ((b1))) + " " + ("" + ((b2))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys S=int(input()) a=math.sqrt(S) b=math.ceil(a) diff=-(S-b**2) diffs=[] if diff==0 : print(0,0,int(b),0,0,int(b)) sys.exit() for i in range(1,math.ceil(math.sqrt(b))+1): if diff % i!=0 : continue else : diffs.append([i,int(diff/i)]) if len(diffs)>2 : if diffs[-2][1]==diffs[-1][0]: print(0,0,int(b),int(diffs[-1][0]),int(diffs[-1][1]),int(b)) sys.exit() print(0,0,int(b),int(diffs[-1][0]),int(diffs[-1][1]),int(b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var S : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : double := (S)->sqrt() ; var b : double := (a)->ceil() ; var diff : double := -(S - (b)->pow(2)) ; var diffs : Sequence := Sequence{} ; if diff = 0 then ( execute (0)->display() ; sys.exit() ) else skip ; for i : Integer.subrange(1, ((b)->sqrt())->ceil() + 1-1) do ( if diff mod i /= 0 then ( continue ) else ( execute ((Sequence{i}->union(Sequence{ ("" + ((diff / i)))->toInteger() })) : diffs) ) ; if (diffs)->size() > 2 then ( if diffs->front()->last()[1+1] = diffs->last()->first() then ( execute (0)->display() ; sys.exit() ) else skip ) else skip) ; execute (0)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter,deque from collections import defaultdict from itertools import combinations,permutations,accumulate,groupby,product from bisect import bisect_left,bisect_right from heapq import heapify,heappop,heappush from math import floor,ceil,pi,factorial from operator import itemgetter def I(): return int(input()) def MI(): return map(int,input().split()) def LI(): return list(map(int,input().split())) def LI2(): return[int(input())for i in range(n)] def SI(): return input().rstrip() def printns(x): print('\n'.join(x)) def printni(x): print('\n'.join(list(map(str,x)))) inf=10**17 mod=10**9+7 s=I() if s==10**18 : print(0,0,0,10**9,10**9,0) else : print(0,0,10**9,1,10**9-s %(10**9),1+s//(10**9)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit((10)->pow(7)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var Math_PINFINITY : double := (10)->pow(17) ; var mod : double := (10)->pow(9) + 7 ; var s : OclAny := I() ; if s = (10)->pow(18) then ( execute (0)->display() ) else ( execute (0)->display() ); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LI2() : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())); operation SI() : OclAny pre: true post: true activity: return input().rstrip(); operation printns(x : OclAny) pre: true post: true activity: execute (StringLib.sumStringsWithSeparator((x), ' '))->display(); operation printni(x : OclAny) pre: true post: true activity: execute (StringLib.sumStringsWithSeparator((((x)->collect( _x | (OclType["String"])->apply(_x) ))), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxPerimeter(arr): maxi=0 n=len(arr) arr.sort(reverse=True) for i in range(0,n-2): if arr[i]<(arr[i+1]+arr[i+2]): maxi=max(maxi,arr[i]+arr[i+1]+arr[i+2]) break if(maxi==0): return "Triangle formation is not possible" else : return "Maximum Perimeter is: "+str(maxi) def main(): arr1=[6,1,6,5,8,4] a=maxPerimeter(arr1) print(a) arr2=[2,20,7,55,1,33,12,4] a=maxPerimeter(arr2) print(a) arr3=[33,6,20,1,8,12,5,55,4,9] a=maxPerimeter(arr3) print(a) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation maxPerimeter(arr : OclAny) : OclAny pre: true post: true activity: var maxi : int := 0 ; var n : int := (arr)->size() ; arr := arr->sort() ; for i : Integer.subrange(0, n - 2-1) do ( if (arr[i+1]->compareTo((arr[i + 1+1] + arr[i + 2+1]))) < 0 then ( maxi := Set{maxi, arr[i+1] + arr[i + 1+1] + arr[i + 2+1]}->max() ; break ) else skip) ; if (maxi = 0) then ( return "Triangle formation is not possible" ) else ( return "Maximum Perimeter is: " + ("" + ((maxi))) ); operation main() pre: true post: true activity: var arr1 : Sequence := Sequence{6}->union(Sequence{1}->union(Sequence{6}->union(Sequence{5}->union(Sequence{8}->union(Sequence{ 4 }))))) ; var a : OclAny := maxPerimeter(arr1) ; execute (a)->display() ; var arr2 : Sequence := Sequence{2}->union(Sequence{20}->union(Sequence{7}->union(Sequence{55}->union(Sequence{1}->union(Sequence{33}->union(Sequence{12}->union(Sequence{ 4 }))))))) ; a := maxPerimeter(arr2) ; execute (a)->display() ; var arr3 : Sequence := Sequence{33}->union(Sequence{6}->union(Sequence{20}->union(Sequence{1}->union(Sequence{8}->union(Sequence{12}->union(Sequence{5}->union(Sequence{55}->union(Sequence{4}->union(Sequence{ 9 }))))))))) ; a := maxPerimeter(arr3) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def area_fun(side): area=side*side return area side=4 area=area_fun(side) print(area) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; side := 4 ; area := area_fun(side) ; execute (area)->display(); operation area_fun(side : OclAny) : OclAny pre: true post: true activity: var area : double := side * side ; return area; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def li(): return list(map(int,input().split())) def gi(n): return[list(map(int,input().split()))for _ in range(n)] s=input() t=input() print(s.count(t)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; execute (s->count(t))->display(); operation li() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation gi(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s1=input() s2=input() n=len(s1) m=len(s2) i=0 number=0 while isize() ; var m : int := (s2)->size() ; var i : int := 0 ; var number : int := 0 ; while (i->compareTo(n)) < 0 do ( if s1.subrange(i+1, i + m) = s2 then ( number := number + 1 ; i := i + m ) else ( i := i + 1 )) ; execute (number)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() t=input() res=0 lt=len(t) x=0 while 1 : x=s.find(t,x) if x==-1 : break res+=1 x+=lt print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var res : int := 0 ; var lt : int := (t)->size() ; var x : int := 0 ; while 1 do ( x := s->indexOf(t, x) - 1 ; if x = -1 then ( break ) else skip ; res := res + 1 ; x := x + lt) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) arr=[0]*(n) for i in range(n): arr[i]=input() job=input() arr=sorted(arr,key=len) i=0 while icollect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n)) ; for i : Integer.subrange(0, n-1) do ( arr[i+1] := (OclFile["System.in"]).readLine()) ; var job : String := (OclFile["System.in"]).readLine() ; arr := arr->sortedBy($x | (len)->apply($x)) ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( if (job)->size() = (arr[i+1])->size() then ( var c : int := i ; break ) else skip ; i := i + 1) ; while (i->compareTo(n)) < 0 do ( if ((job)->size()->compareTo((arr[i+1])->size())) < 0 then ( break ) else skip ; i := i + 1) ; execute (((c) div m) * 5 + c + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- string=input() sub=input() l1=len(string) l2=len(sub) counter=0 for i in range(l1-l2+1): match=1 for j in range(l2): if sub[j]!=string[i+j]: match=0 break if match : string=string[: i+j]+'#'+string[i+j+1 :] counter+=1 print(counter) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var string : String := (OclFile["System.in"]).readLine() ; var sub : String := (OclFile["System.in"]).readLine() ; var l1 : int := (string)->size() ; var l2 : int := (sub)->size() ; var counter : int := 0 ; for i : Integer.subrange(0, l1 - l2 + 1-1) do ( var match : int := 1 ; for j : Integer.subrange(0, l2-1) do ( if sub[j+1] /= string[i + j+1] then ( match := 0 ; break ) else skip) ; if match then ( string := string.subrange(1,i + j) + '#' + string.subrange(i + j + 1+1) ; counter := counter + 1 ) else skip) ; execute (counter)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): print(max(list(map(int,input().strip())))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute ((((input()->trim())->collect( _x | (OclType["int"])->apply(_x) )))->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ai=input() phone=input() print(ai.count(phone)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ai : String := (OclFile["System.in"]).readLine() ; var phone : String := (OclFile["System.in"]).readLine() ; execute (ai->count(phone))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class UnionFind(): def __init__(self,n): self.parent=list(range(n)) self.rank=[0]*n def find(self,x): if self.parent[x]==x : return x else : self.parent[x]=self.find(self.parent[x]) return self.parent[x] def unite(self,x,y): x,y=self.find(x),self.find(y) if x==y : return if self.rank[x]exists( _x | result = _x ); attribute parent : Sequence := (Integer.subrange(0, n-1)); attribute rank : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); operation initialise(n : OclAny) : pre: true post: true activity: self.parent := (Integer.subrange(0, n-1)) ; self.rank := MatrixLib.elementwiseMult(Sequence{ 0 }, n); return self; operation find(x : OclAny) : OclAny pre: true post: true activity: if self.parent[x+1] = x then ( return x ) else ( self.parent[x+1] := self->indexOf(self.parent[x+1]) - 1 ; return self.parent[x+1] ); operation unite(x : OclAny,y : OclAny) pre: true post: true activity: Sequence{x,y} := Sequence{self->indexOf(x) - 1,self->indexOf(y) - 1} ; if x = y then ( return ) else skip ; if (self.rank[x+1]->compareTo(self.rank[y+1])) < 0 then ( self.parent[x+1] := y ) else ( self.parent[y+1] := x ; if self.rank[x+1] = self.rank[y+1] then ( self.rank[x+1] := self.rank[x+1] + 1 ) else skip ); operation same(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: return self->indexOf(x) - 1 = self->indexOf(y) - 1; } class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var m : OclAny := null; Sequence{n,m} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; if not(n) then ( break ) else skip ; var result : int := 0 ; var bridges : Sequence := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name tuple)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name m)))))))) ))))))))}->sortedBy($x | (lambda x : OclAny in (x[2+1]))->apply($x)) ; var tree : UnionFind := (UnionFind.newUnionFind()).initialise(n) ; for _tuple : bridges do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var cost : OclAny := _tuple->at(_indx); if not(tree.same(a, b)) then ( result := result + cost ; tree.unite(a, b) ) else skip) ; execute (result)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline write=sys.stdout.write def solve(): N,M=map(int,readline().split()) if N==0 : return False *p,=range(N) def root(x): if x==p[x]: return x p[x]=y=root(p[x]) return y def unite(x,y): px=root(x); py=root(y) if px==py : return 0 if pxcollect( _x | (OclType["int"])->apply(_x) ) ; if N = 0 then ( return false ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline class Unionfind : def __init__(self,n): self.par=[-1]*n self.rank=[1]*n def root(self,x): r=x while not self.par[r]<0 : r=self.par[r] t=x while t!=r : tmp=t t=self.par[t] self.par[tmp]=r return r def unite(self,x,y): rx=self.root(x) ry=self.root(y) if rx==ry : return if self.rank[rx]<=self.rank[ry]: self.par[ry]+=self.par[rx] self.par[rx]=ry if self.rank[rx]==self.rank[ry]: self.rank[ry]+=1 else : self.par[rx]+=self.par[ry] self.par[ry]=rx def is_same(self,x,y): return self.root(x)==self.root(y) def count(self,x): return-self.par[self.root(x)] while True : n,m=map(int,input().split()) if n==0 and m==0 : exit() edges=[tuple(map(int,input().split()))for _ in range(m)] edges.sort(key=lambda t : t[2]) uf=Unionfind(n) ans=0 for a,b,c in edges : if not uf.is_same(a,b): uf.unite(a,b) ans+=c print(ans) ------------------------------------------------------------ OCL File: --------- class Unionfind { static operation newUnionfind() : Unionfind pre: true post: Unionfind->exists( _x | result = _x ); attribute par : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n); attribute rank : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, n); operation initialise(n : OclAny) : Unionfind pre: true post: true activity: self.par := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; self.rank := MatrixLib.elementwiseMult(Sequence{ 1 }, n); return self; operation root(x : OclAny) : OclAny pre: true post: true activity: var r : OclAny := x ; while not(self.par[r+1] < 0) do ( r := self.par[r+1]) ; var t : OclAny := x ; while t /= r do ( var tmp : OclAny := t ; t := self.par[t+1] ; self.par[tmp+1] := r) ; return r; operation unite(x : OclAny,y : OclAny) pre: true post: true activity: var rx : OclAny := self.root(x) ; var ry : OclAny := self.root(y) ; if rx = ry then ( return ) else skip ; if (self.rank[rx+1]->compareTo(self.rank[ry+1])) <= 0 then ( self.par[ry+1] := self.par[ry+1] + self.par[rx+1] ; self.par[rx+1] := ry ; if self.rank[rx+1] = self.rank[ry+1] then ( self.rank[ry+1] := self.rank[ry+1] + 1 ) else skip ) else ( self.par[rx+1] := self.par[rx+1] + self.par[ry+1] ; self.par[ry+1] := rx ); operation is_same(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: return self.root(x) = self.root(y); operation count(x : OclAny) : OclAny pre: true post: true activity: return -self.par[self.root(x)+1]; } class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; while true do ( var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 & m = 0 then ( exit() ) else skip ; var edges : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; edges := edges->sort() ; var uf : Unionfind := (Unionfind.newUnionfind()).initialise(n) ; var ans : int := 0 ; for _tuple : edges do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if not(uf.is_same(a, b)) then ( uf.unite(a, b) ; ans := ans + c ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=105 id,size=[0]*MAX,[0]*MAX def init(n): for i in range(n): id[i],size[i]=i,1 def root(i): while i!=id[i]: id[i]=id[id[i]] i=id[i] return i def connected(p,q): return root(p)==root(q) def unite(p,q): i,j=root(p),root(q) if i==j : return if size[i]collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; edge := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var s : OclAny := null; var t : OclAny := null; var w : OclAny := null; Sequence{s,t,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{s, t, w}) : edge)) ; execute (kruskal(n, edge))->display()); operation init(n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( var ?[i+1] : OclAny := null; var size[i+1] : OclAny := null; Sequence{?[i+1],size[i+1]} := Sequence{i,1}); operation root(i : OclAny) : OclAny pre: true post: true activity: while i /= ?[i+1] do ( ?[i+1] := ?[?[i+1]+1] ; i := ?[i+1]) ; return i; operation connected(p : OclAny, q : OclAny) : OclAny pre: true post: true activity: return root(p) = root(q); operation unite(p : OclAny, q : OclAny) pre: true post: true activity: var j : OclAny := null; Sequence{i,j} := Sequence{root(p),root(q)} ; if i = j then ( return ) else skip ; if (size[i+1]->compareTo(size[j+1])) < 0 then ( ?[i+1] := j ; size[j+1] := size[j+1] + size[i+1] ) else ( ?[j+1] := i ; size[i+1] := size[i+1] + size[j+1] ); operation kruskal(V : OclAny, edge : OclAny) pre: true post: true activity: var ee : Sequence := edge->sortedBy($x | (lambda x : OclAny in ((x[2+1])))->apply($x)) ; init(V) ; var ans : int := 0 ; for e : ee do ( if not(connected(e->first(), e[1+1])) then ( unite(e->first(), e[1+1]) ; ans := ans + e[2+1] ) else skip) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heappush,heappop def get_par(x,par_lst): if x==par_lst[x]: return x p=get_par(par_lst[x],par_lst) par_lst[x]=p return p while True : n,m=map(int,input().split()) if n==0 : break que=[] for _ in range(m): a,b,c=map(int,input().split()) heappush(que,(c,a,b)) par_lst=[i for i in range(n)] ans=0 while que : c,a,b=heappop(que) pa,pb=get_par(a,par_lst),get_par(b,par_lst) if pa!=pb : par_lst[pa]=pb ans+=c print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var que : Sequence := Sequence{} ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; heappush(que, Sequence{c, a, b})) ; par_lst := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)) ; var ans : int := 0 ; while que do ( var c : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{c,a,b} := heappop(que) ; var pa : OclAny := null; var pb : OclAny := null; Sequence{pa,pb} := Sequence{get_par(a, par_lst),get_par(b, par_lst)} ; if pa /= pb then ( par_lst[pa+1] := pb ; ans := ans + c ) else skip) ; execute (ans)->display()); operation get_par(x : OclAny, par_lst : OclAny) : OclAny pre: true post: true activity: if x = par_lst[x+1] then ( return x ) else skip ; var p : OclAny := get_par(par_lst[x+1], par_lst) ; par_lst[x+1] := p ; return p; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def BF(p,n,s): inf=float("inf") d=[inf for i in range(n)] d[s-1]=0 for i in range(n+1): for e in p : if e[0]!=inf and d[e[1]-1]>d[e[0]-1]+e[2]: d[e[1]-1]=d[e[0]-1]+e[2] if i==n-1 : t=d[-1] if i==n and t!=d[-1]: return[0,'inf'] return list(map(lambda x :-x,d)) n,m=map(int,input().split()) a=[list(map(int,input().split()))for i in range(m)] a=[[x,y,-z]for x,y,z in a] print(BF(a,n,1)[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; a := a->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (Sequence{x}->union(Sequence{y}->union(Sequence{ -z })))) ; execute (BF(a, n, 1)->last())->display(); operation BF(p : OclAny, n : OclAny, s : OclAny) : OclAny pre: true post: true activity: var Math_PINFINITY : double := ("" + (("inf")))->toReal() ; var d : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Math_PINFINITY)) ; d[s - 1+1] := 0 ; for i : Integer.subrange(0, n + 1-1) do ( for e : p do ( if e->first() /= Math_PINFINITY & (d[e[1+1] - 1+1]->compareTo(d[e->first() - 1+1] + e[2+1])) > 0 then ( d[e[1+1] - 1+1] := d[e->first() - 1+1] + e[2+1] ) else skip) ; if i = n - 1 then ( var t : OclAny := d->last() ) else skip ; if i = n & t /= d->last() then ( return Sequence{0}->union(Sequence{ 'inf' }) ) else skip) ; return ((d)->collect( _x | (lambda x : OclAny in (-x))->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**9) import numpy as np from heapq import heappush,heappop N,M,=map(int,input().split()) graph=[[]for _ in range(N+1)] for _ in range(M): a,b,c=map(int,input().split()) graph[a].append((b,-c)) def dijkstra(start,co): INF=10**15 dist=[INF]*(N+1) dist[start]=0 que=[(0,start,co)] while que : score,place,count=heappop(que) if score>dist[place]or count>2000 : continue for next_node,weight in graph[place]: score2=score+weight if next_node==N and count>1000 : print('inf') exit() if dist[next_node]>score2 and count<2000 : dist[next_node]=score2 heappush(que,(score2,next_node,count+1)) return dist d1=np.array(dijkstra(1,0)) print(-d1[N]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(9)) ; skip ; skip ; var N : OclAny := null; (declareIfNecessary (test (logical_test (comparison (expr (atom (name M)))))) ,) Sequence{N,(testlist_star_expr (test (logical_test (comparison (expr (atom (name M)))))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var graph : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, M-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name b)))))) , (test (logical_test (comparison (expr - (expr (atom (name c)))))))) )))))))) ))))) ; skip ; var d1 : Sequence := (dijkstra(1, 0)) ; execute (-d1[N+1])->display(); operation dijkstra(start : OclAny, co : OclAny) : OclAny pre: true post: true activity: var INF : double := (10)->pow(15) ; var dist : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, (N + 1)) ; dist[start+1] := 0 ; var que : Sequence := Sequence{ Sequence{0, start, co} } ; while que do ( var score : OclAny := null; var place : OclAny := null; var count : OclAny := null; Sequence{score,place,count} := heappop(que) ; if (score->compareTo(dist[place+1])) > 0 or count > 2000 then ( continue ) else skip ; for _tuple : graph[place+1] do (var _indx : int := 1; var next_node : OclAny := _tuple->at(_indx); _indx := _indx + 1; var weight : OclAny := _tuple->at(_indx); var score2 : OclAny := score + weight ; if next_node = N & count > 1000 then ( execute ('inf')->display() ; exit() ) else skip ; if (dist[next_node+1]->compareTo(score2)) > 0 & count < 2000 then ( dist[next_node+1] := score2 ; heappush(que, Sequence{score2, next_node, count + 1}) ) else skip)) ; return dist; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) p=[len(input())for _ in range(n)] password=len(input()) p=sorted(p) first=p.index(password) last=n-list(reversed(p)).index(password)-1 mn=first+((first//k)*5)+1 mx=last+((last//k)*5)+1 print(mn,mx) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((OclFile["System.in"]).readLine())->size())) ; var password : int := ((OclFile["System.in"]).readLine())->size() ; p := p->sort() ; var first : int := p->indexOf(password) - 1 ; var last : double := n - OclType["Sequence"]((p)->reverse())->indexOf(password) - 1 - 1 ; var mn : int := first + ((first div k) * 5) + 1 ; var mx : OclAny := last + ((last div k) * 5) + 1 ; execute (mn)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from scipy.sparse.csgraph import connected_components,bellman_ford,NegativeCycleError from scipy.sparse import csr_matrix N,M=map(int,input().split()) frm,to,length=[],[],[] for _ in range(M): a,b,c=map(int,input().split()) frm.append(a-1) to.append(b-1) length.append(-c) connect_check=csr_matrix(([1]*(M+1),(frm+[N-1],to+[0])),shape=(N,N)) _,labels=connected_components(connect_check,connection='strong') label_num=labels[0] frm_c,to_c,length_c=[],[],[] for i in range(M): if labels[frm[i]]==labels[to[i]]==label_num : frm_c.append(frm[i]) to_c.append(to[i]) length_c.append(length[i]) matr=csr_matrix((length_c,(frm_c,to_c)),shape=(N,N)) try : ans=-int(bellman_ford(matr,indices=0)[N-1]) print(ans) except NegativeCycleError : print('inf') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var frm : OclAny := null; var to : OclAny := null; var length : OclAny := null; Sequence{frm,to,length} := Sequence{Sequence{},Sequence{},Sequence{}} ; for _anon : Integer.subrange(0, M-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a - 1) : frm) ; execute ((b - 1) : to) ; execute ((-c) : length)) ; var connect_check : OclAny := csr_matrix(Sequence{MatrixLib.elementwiseMult(Sequence{ 1 }, (M + 1)), Sequence{frm->union(Sequence{ N - 1 }), to->union(Sequence{ 0 })}}, (argument (test (logical_test (comparison (expr (atom (name shape)))))) = (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name N)))))) , (test (logical_test (comparison (expr (atom (name N))))))) )))))))) ; var _anon : OclAny := null; var labels : OclAny := null; Sequence{_anon,labels} := connected_components(connect_check, (argument (test (logical_test (comparison (expr (atom (name connection)))))) = (test (logical_test (comparison (expr (atom 'strong'))))))) ; var label_num : OclAny := labels->first() ; var frm_c : OclAny := null; var to_c : OclAny := null; var length_c : OclAny := null; Sequence{frm_c,to_c,length_c} := Sequence{Sequence{},Sequence{},Sequence{}} ; for i : Integer.subrange(0, M-1) do ( if labels[frm[i+1]+1] = labels[to[i+1]+1] & (labels[to[i+1]+1] == label_num) then ( execute ((frm[i+1]) : frm_c) ; execute ((to[i+1]) : to_c) ; execute ((length[i+1]) : length_c) ) else skip) ; var matr : OclAny := csr_matrix(Sequence{length_c, Sequence{frm_c, to_c}}, (argument (test (logical_test (comparison (expr (atom (name shape)))))) = (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name N)))))) , (test (logical_test (comparison (expr (atom (name N))))))) )))))))) ; try ( var ans : int := -("" + ((bellman_ford(matr, (argument (test (logical_test (comparison (expr (atom (name indices)))))) = (test (logical_test (comparison (expr (atom (number (integer 0)))))))))[N - 1+1])))->toInteger() ; execute (ans)->display()) (except_clause except (test (logical_test (comparison (expr (atom (name NegativeCycleError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'inf'))))))) )))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate import math from collections import deque from collections import defaultdict from itertools import permutations import heapq import bisect from collections import Counter from itertools import* from bisect import bisect_left,bisect_right from copy import deepcopy inf=float('inf') from functools import reduce n,m=map(int,input().split()) edge=[] for i in range(m): a,b,c=map(int,input().split()) edge.append([a-1,b-1,-c]) dist=[inf]*n dist[0]=0 for i in range(1,n): for j in range(m): if dist[edge[j][1]]>dist[edge[j][0]]+edge[j][2]: dist[edge[j][1]]=dist[edge[j][0]]+edge[j][2] ans=dist[n-1] for j in range(m): if dist[edge[j][1]]>dist[edge[j][0]]+edge[j][2]: dist[edge[j][1]]=dist[edge[j][0]]+edge[j][2] if dist[n-1]toReal() ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var edge : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a - 1}->union(Sequence{b - 1}->union(Sequence{ -c }))) : edge)) ; var dist : Sequence := MatrixLib.elementwiseMult(Sequence{ Math_PINFINITY }, n) ; dist->first() := 0 ; for i : Integer.subrange(1, n-1) do ( for j : Integer.subrange(0, m-1) do ( if (dist[edge[j+1][1+1]+1]->compareTo(dist[edge[j+1]->first()+1] + edge[j+1][2+1])) > 0 then ( dist[edge[j+1][1+1]+1] := dist[edge[j+1]->first()+1] + edge[j+1][2+1] ) else skip)) ; var ans : OclAny := dist[n - 1+1] ; for j : Integer.subrange(0, m-1) do ( if (dist[edge[j+1][1+1]+1]->compareTo(dist[edge[j+1]->first()+1] + edge[j+1][2+1])) > 0 then ( dist[edge[j+1][1+1]+1] := dist[edge[j+1]->first()+1] + edge[j+1][2+1] ) else skip) ; if (dist[n - 1+1]->compareTo(ans)) < 0 then ( execute ("inf")->display() ) else ( execute (-ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=lambda : map(int,input().split()) n,k=I() a=*I(), m=len({*a}) x=0--max(a.count(x)for x in{*a})//k print(m*x*k-n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := I->apply() ; var a : OclAny := (testlist_star_expr (star_expr * (expr (atom (name I)) (trailer (arguments ( ))))) ,) ; var m : int := (Set{ a })->size() ; var x : double := 0 - -((argument (test (logical_test (comparison (expr (atom (name a)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom { (dictorsetmaker (testlist_comp (star_expr * (expr (atom (name a)))))) })))))))->max() div k ; execute (m * x * k - n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) m=str(n) highest=set() for j in range(len(m)): highest.add(int(m[j])) print(max(highest)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : String := ("" + ((n))) ; var highest : Set := Set{}->union(()) ; for j : Integer.subrange(0, (m)->size()-1) do ( execute ((("" + ((m[j+1])))->toInteger()) : highest)) ; execute ((highest)->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys inf=1<<60 def solve(): N,M=map(int,input().split()) edges=[None]*M for i in range(M): a,b,c=map(int,sys.stdin.readline().split()) a,b=a-1,b-1 edges[i]=(a,b,-c) ans=BellmanFord(N,M,edges) if ans is None : print('inf') else : print(-ans) def BellmanFord(N,M,edges): d=[inf]*N d[0]=0 for i in range(N-1): for(u,v,c)in edges : if d[u]+cpow(60)) ; skip ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var edges : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, M) ; for i : Integer.subrange(0, M-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{a - 1,b - 1} ; edges[i+1] := Sequence{a, b, -c}) ; var ans : OclAny := BellmanFord(N, M, edges) ; if ans <>= null then ( execute ('inf')->display() ) else ( execute (-ans)->display() ); operation BellmanFord(N : OclAny, M : OclAny, edges : OclAny) : OclAny pre: true post: true activity: var d : Sequence := MatrixLib.elementwiseMult(Sequence{ Math_PINFINITY }, N) ; d->first() := 0 ; for i : Integer.subrange(0, N - 1-1) do ( for Sequence{u, v, c} : edges do ( if (d[u+1] + c->compareTo(d[v+1])) < 0 then ( d[v+1] := d[u+1] + c ) else skip)) ; for Sequence{u, v, c} : edges do ( if (d[u+1] + c->compareTo(d[v+1])) < 0 then ( if v = N - 1 then ( return null ) else skip ; d[v+1] := d[u+1] + c ) else skip) ; return d[N - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def MinSteps(SourceX,SourceY,DestX,DestY): print(max(abs(SourceX-DestX),abs(SourceY-DestY))) while((SourceX!=DestX)or(SourceY!=DestY)): if(SourceXDestX): print('D',end="") SourceX-=1 if(SourceY>DestY): print('L') SourceY-=1 if(SourceYabs(), (SourceY - DestY)->abs()}->max())->display() ; while ((SourceX /= DestX) or (SourceY /= DestY)) do ( if ((SourceX->compareTo(DestX)) < 0) then ( execute ('U')->display() ; SourceX := SourceX + 1 ) else skip ; if ((SourceX->compareTo(DestX)) > 0) then ( execute ('D')->display() ; SourceX := SourceX - 1 ) else skip ; if ((SourceY->compareTo(DestY)) > 0) then ( execute ('L')->display() ; SourceY := SourceY - 1 ) else skip ; if ((SourceY->compareTo(DestY)) < 0) then ( execute ('R')->display() ; SourceY := SourceY + 1 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,m,k=map(int,input().split()) d1=[[]for _ in range(n)] d2=[[]for _ in range(n)] d3=[[]for _ in range(n)] for i in range(n): s=input()[:-1] for _ in range(m): a,b,c=map(int,input().split()) d1[i].append(a) d2[i].append(b) d3[i].append(c) p=0 for i in range(n): for j in range(n): if i==j : continue d=[d2[j][x]-d1[i][x]for x in range(m)] d=sorted(zip(d,d3[i]),reverse=True) q=k ii=0 p1=0 while q : q1=min(q,d[ii][1]) q-=q1 p1+=d[ii][0]*q1 ii+=1 if ii==m or d[ii][0]<0 : break p=max(p,p1) print(p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d1 : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var d2 : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var d3 : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, n-1) do ( var s : OclAny := input()->front() ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name d1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))) ; (expr (atom (name d2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name d3)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))))) ; var p : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if i = j then ( continue ) else skip ; var d : Sequence := Integer.subrange(0, m-1)->select(x | true)->collect(x | (d2[j+1][x+1] - d1[i+1][x+1])) ; d := Integer.subrange(1, d->size())->collect( _indx | Sequence{d->at(_indx), d3[i+1]->at(_indx)} )->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var q : OclAny := k ; var ii : int := 0 ; var p1 : int := 0 ; while q do ( var q1 : OclAny := Set{q, d[ii+1][1+1]}->min() ; q := q - q1 ; p1 := p1 + d[ii+1]->first() * q1 ; ii := ii + 1 ; if ii = m or d[ii+1]->first() < 0 then ( break ) else skip) ; p := Set{p, p1}->max())) ; execute (p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=input().split(" ") n=int(n) m=int(m) k=int(k) mex=0 class Obj : def __init__(self,index,costs,sells,lims): self.i=index self.costs=costs self.sells=sells self.limits=lims l=[Obj(i,[],[],[])for i in range(n)] for i in range(n): planet=input() for j in range(m): a,b,c=tuple(map(int,input().split(" "))) l[i].costs.append(a) l[i].sells.append(b) l[i].limits.append(c) for i in range(n): for j in range(n): l1=l[i].costs l2=l[j].sells ll=[] for pro in range(m): ll.append([l2[pro]-l1[pro],pro]) ll.sort(key=lambda x : x[0]) quant=0 pr=-1 c=0 while quant-len(ll)-1 : if quant+l[i].limits[ll[pr][1]]<=k and ll[pr][0]>0 : quant+=l[i].limits[ll[pr][1]] c+=l[i].limits[ll[pr][1]]*ll[pr][0] elif ll[pr][0]>0 : c+=(k-quant)*ll[pr][0] quant=k else : break pr-=1 mex=max(c,mex) print(mex) ------------------------------------------------------------ OCL File: --------- class Obj { static operation newObj() : Obj pre: true post: Obj->exists( _x | result = _x ); attribute i : OclAny := index; attribute costs : OclAny := costs; attribute sells : OclAny := sells; attribute limits : OclAny := lims; operation initialise(index : OclAny,costs : OclAny,sells : OclAny,lims : OclAny) : Obj pre: true post: true activity: self.i := index ; self.costs := costs ; self.sells := sells ; self.limits := lims; return self; } class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := input().split(" ") ; var n : int := ("" + ((n)))->toInteger() ; var m : int := ("" + ((m)))->toInteger() ; var k : int := ("" + ((k)))->toInteger() ; var mex : int := 0 ; skip ; var l : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((Obj.newObj()).initialise(i, Sequence{}, Sequence{}, Sequence{}))) ; for i : Integer.subrange(0, n-1) do ( var planet : String := (OclFile["System.in"]).readLine() ; for j : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name costs)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))) ; (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name sells)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name limits)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( var l1 : OclAny := l[i+1].costs ; var l2 : OclAny := l[j+1].sells ; var ll : Sequence := Sequence{} ; for pro : Integer.subrange(0, m-1) do ( execute ((Sequence{l2[pro+1] - l1[pro+1]}->union(Sequence{ pro })) : ll)) ; ll := ll->sort() ; var quant : int := 0 ; var pr : int := -1 ; var c : int := 0 ; while (quant->compareTo(k)) < 0 & (pr->compareTo(-(ll)->size() - 1)) > 0 do ( if (quant + l[i+1].limits[ll[pr+1][1+1]+1]->compareTo(k)) <= 0 & ll[pr+1]->first() > 0 then ( quant := quant + l[i+1].limits[ll[pr+1][1+1]+1] ; c := c + l[i+1].limits[ll[pr+1][1+1]+1] * ll[pr+1]->first() ) else (if ll[pr+1]->first() > 0 then ( c := c + (k - quant) * ll[pr+1]->first() ; quant := k ) else ( break ) ) ; pr := pr - 1) ; mex := Set{c, mex}->max())) ; execute (mex)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) a,b,c=[],[],[] a=[] for i in range(n): input() a.append([]) b.append([]) c.append([]) for j in range(m): x,y,z=map(int,input().split()) a[i].append(x) b[i].append(y) c[i].append(z) ans=0 for i in range(n): for j in range(n): if i==j : continue d=[] for p in range(m): kol=c[i][p] s=b[j][p]-a[i][p] while s>=0 and kol!=0 : d.append(s) kol-=1 d.sort() d=d[: :-1] d=d[: k] ans=max(0,ans,sum(d)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{Sequence{},Sequence{},Sequence{}} ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( input() ; execute ((Sequence{}) : a) ; execute ((Sequence{}) : b) ; execute ((Sequence{}) : c) ; for j : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) ; (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))) ; (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name z)))))))) )))))) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if i = j then ( continue ) else skip ; var d : Sequence := Sequence{} ; for p : Integer.subrange(0, m-1) do ( var kol : OclAny := c[i+1][p+1] ; var s : double := b[j+1][p+1] - a[i+1][p+1] ; while s >= 0 & kol /= 0 do ( execute ((s) : d) ; kol := kol - 1)) ; d := d->sort() ; d := d(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; d := d.subrange(1,k) ; ans := Set{0, ans, (d)->sum()}->max())) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import string import copy def main_function(): n,m,k=[int(i)for i in input().split(" ")] collector=[[]for i in range(n)] profit=0 for i in range(n): input() for j in range(m): a_b_c=[int(r)for r in input().split(" ")] collector[i].append(a_b_c) for bought in range(len(collector)): for sold in range(len(collector)): main_list=[] for item in range(m): bought_price=collector[bought][item][0] amount=collector[bought][item][2] sold_price=collector[sold][item][1] price_difference=sold_price-bought_price if price_difference>0 : main_list.append((price_difference,amount)) main_list.sort(key=lambda x : x[0],reverse=True) limit=k local_profit=0 for i in main_list : price_difference=i[0] quantity=i[1] if limit>quantity : local_profit+=quantity*price_difference limit-=quantity else : local_profit+=limit*price_difference break if local_profit>profit : profit=local_profit print(profit) if __name__=='__main__' : main_function() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main_function() ) else skip; operation main_function() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var collector : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; var profit : int := 0 ; for i : Integer.subrange(0, n-1) do ( input() ; for j : Integer.subrange(0, m-1) do ( var a_b_c : Sequence := input().split(" ")->select(r | true)->collect(r | (("" + ((r)))->toInteger())) ; (expr (atom (name collector)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a_b_c)))))))) )))))) ; for bought : Integer.subrange(0, (collector)->size()-1) do ( for sold : Integer.subrange(0, (collector)->size()-1) do ( var main_list : Sequence := Sequence{} ; for item : Integer.subrange(0, m-1) do ( var bought_price : OclAny := collector[bought+1][item+1]->first() ; var amount : OclAny := collector[bought+1][item+1][2+1] ; var sold_price : OclAny := collector[sold+1][item+1][1+1] ; var price_difference : double := sold_price - bought_price ; if price_difference > 0 then ( execute ((Sequence{price_difference, amount}) : main_list) ) else skip) ; main_list := main_list->sort() ; var limit : OclAny := k ; var local_profit : int := 0 ; for i : main_list do ( price_difference := i->first() ; var quantity : OclAny := i[1+1] ; if (limit->compareTo(quantity)) > 0 then ( local_profit := local_profit + quantity * price_difference ; limit := limit - quantity ) else ( local_profit := local_profit + limit * price_difference ; break )) ; if (local_profit->compareTo(profit)) > 0 then ( profit := local_profit ) else skip)) ; execute (profit)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input().replace(";","").replace("-","").replace("_","").lower() p=input().replace(";","").replace("-","").replace("_","").lower() c=input().replace(";","").replace("-","").replace("_","").lower() z=[n+p+c,n+c+p,c+n+p,c+p+n,p+c+n,p+n+c] for i in range(int(input())): q=input().replace(";","").replace("-","").replace("_","").lower() if q in z : print("ACC") else : print("WA") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := input().replace(";", "").replace("-", "").replace("_", "")->toLowerCase() ; var p : OclAny := input().replace(";", "").replace("-", "").replace("_", "")->toLowerCase() ; var c : OclAny := input().replace(";", "").replace("-", "").replace("_", "")->toLowerCase() ; var z : Sequence := Sequence{n + p + c}->union(Sequence{n + c + p}->union(Sequence{c + n + p}->union(Sequence{c + p + n}->union(Sequence{p + c + n}->union(Sequence{ p + n + c }))))) ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var q : OclAny := input().replace(";", "").replace("-", "").replace("_", "")->toLowerCase() ; if (z)->includes(q) then ( execute ("ACC")->display() ) else ( execute ("WA")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def toLowerCase(self,str): res=[] gap=ord('a')-ord('A') for c in str : if ord(c)>=ord('A')and ord(c)<=ord('Z'): res.append(chr(ord(c)+gap)) else : res.append(c) return ''.join(res) ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation toLowerCase(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var res : Sequence := Sequence{} ; var gap : double := ('a')->char2byte() - ('A')->char2byte() ; for c : OclType["String"] do ( if ((c)->char2byte()->compareTo(('A')->char2byte())) >= 0 & ((c)->char2byte()->compareTo(('Z')->char2byte())) <= 0 then ( execute ((((c)->char2byte() + gap)->byte2char()) : res) ) else ( execute ((c) : res) )) ; return StringLib.sumStringsWithSeparator((res), ''); } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N,A,B,C,D=map(int,input().split()) diff=B-A for i in range(N-1): if-D*i+C*(N-1-i)<=diff<=-C*i+D*(N-1-i): print("YES") return print("NO") if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var D : OclAny := null; Sequence{N,A,B,C,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var diff : double := B - A ; for i : Integer.subrange(0, N - 1-1) do ( if (-D * i + C * (N - 1 - i)->compareTo(diff)) <= 0 & (diff <= -C * i + D * (N - 1 - i)) then ( execute ("YES")->display() ; return ) else skip) ; execute ("NO")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque,Counter from heapq import heappush,heappop,heapify import math from bisect import bisect_left import random from itertools import permutations,accumulate,combinations import sys import string INF=float('inf') def LI(): return list(map(int,sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return sys.stdin.readline().strip() def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] def SRL(n): return[list(S())for i in range(n)] mod=998244353 n,a,b,c,d=LI() for add_cnt in range(n): subtract_cnt=n-1-add_cnt min_val=add_cnt*c-subtract_cnt*d max_val=add_cnt*d-subtract_cnt*c if min_val<=b-a<=max_val : print('YES') break else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var INF : double := ("" + (('inf')))->toReal() ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : int := 998244353 ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{n,a,b,c,d} := LI() ; (compound_stmt for (exprlist (expr (atom (name add_cnt)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name subtract_cnt)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (name n))) - (expr (atom (number (integer 1))))) - (expr (atom (name add_cnt))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name min_val)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (name add_cnt))) * (expr (atom (name c)))) - (expr (expr (atom (name subtract_cnt))) * (expr (atom (name d)))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name max_val)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (name add_cnt))) * (expr (atom (name d)))) - (expr (expr (atom (name subtract_cnt))) * (expr (atom (name c)))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (comparison (expr (atom (name min_val)))) <= (comparison (expr (expr (atom (name b))) - (expr (atom (name a)))))) <= (comparison (expr (atom (name max_val))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) ))))))))))))))); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation S() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation SRL(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | ((S()))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.readline().strip() def list2d(a,b,c): return[[c]*b for i in range(a)] def list3d(a,b,c,d): return[[[d]*c for j in range(b)]for i in range(a)] def list4d(a,b,c,d,e): return[[[[e]*d for j in range(c)]for j in range(b)]for i in range(a)] def ceil(x,y=1): return int(-(-x//y)) def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(N=None): return list(MAP())if N is None else[INT()for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 N,A,B,C,D=MAP() B-=A l=D-C+1 b=C*2-1 mx=D l+=(D-C)*(N-2) b=max(b-(D-C)*(N-2),0) mx*=N-1 B+=mx mod=l+b if B<0 or B>mx*2 : NO() exit() if B % modpow(9)) ; var INF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var D : OclAny := null; Sequence{N,A,B,C,D} := MAP() ; B := B - A ; var l : double := D - C + 1 ; b := C * 2 - 1 ; var mx : OclAny := D ; l := l + (D - C) * (N - 2) ; b := Set{b - (D - C) * (N - 2), 0}->max() ; mx := mx * N - 1 ; B := B + mx ; var mod : OclAny := l + b ; if B < 0 or (B->compareTo(mx * 2)) > 0 then ( NO() ; exit() ) else skip ; if (B mod mod->compareTo(l)) < 0 then ( YES() ) else ( NO() ); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation list2d(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, a-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ c }, b))); operation list3d(a : OclAny, b : OclAny, c : OclAny, d : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, a-1)->select(i | true)->collect(i | (Integer.subrange(0, b-1)->select(j | true)->collect(j | (MatrixLib.elementwiseMult(Sequence{ d }, c))))); operation list4d(a : OclAny, b : OclAny, c : OclAny, d : OclAny, e : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, a-1)->select(i | true)->collect(i | (Integer.subrange(0, b-1)->select(j | true)->collect(j | (Integer.subrange(0, c-1)->select(j | true)->collect(j | (MatrixLib.elementwiseMult(Sequence{ e }, d))))))); operation ceil(x : OclAny, y : int) : OclAny pre: true post: true activity: if y->oclIsUndefined() then y := 1 else skip; return ("" + ((-(-x div y))))->toInteger(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST(N : OclAny) : OclAny pre: true post: true activity: if N->oclIsUndefined() then N := null else skip; return if N <>= null then (MAP()) else Integer.subrange(0, N-1)->select(i | true)->collect(i | (INT())) endif; operation Yes() pre: true post: true activity: execute ('Yes')->display(); operation No() pre: true post: true activity: execute ('No')->display(); operation YES() pre: true post: true activity: execute ('YES')->display(); operation NO() pre: true post: true activity: execute ('NO')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil n=int(input()) debt=100000 for i in range(0,n): debt=debt*1.05 debt=int(ceil(debt/1000.0)*1000.0) print(debt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var debt : int := 100000 ; for i : Integer.subrange(0, n-1) do ( debt := debt * 1.05 ; debt := ("" + ((ceil(debt / 1000.0) * 1000.0)))->toInteger()) ; execute (debt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,A,B,C,D=list(map(int,input().split())) def nibun(func,min_,max_): left=min_ right=max_ while not(left==right): mid=(left+right)//2 tmp=func(mid) if tmp : right=mid else : left=mid+1 return left X=abs(A-B) def calc(n): m=N-n-1 min_val=-D*n+C*m max_val=-C*n+D*m return min_val,max_val def check(n): return calc(n)[0]<=X n=(nibun(check,0,N)) print("YES" if calc(n)[0]<=abs(A-B)and calc(n)[1]>=abs(A-B)else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var D : OclAny := null; Sequence{N,A,B,C,D} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; var X : double := (A - B)->abs() ; skip ; skip ; n := (nibun(check, 0, N)) ; execute (if (calc(n)->first()->compareTo((A - B)->abs())) <= 0 & (calc(n)[1+1]->compareTo((A - B)->abs())) >= 0 then "YES" else "NO" endif)->display(); operation nibun(func : OclAny, min_ : OclAny, max_ : OclAny) : OclAny pre: true post: true activity: var left : OclAny := min_ ; var right : OclAny := max_ ; while not((left = right)) do ( var mid : int := (left + right) div 2 ; var tmp : OclAny := func(mid) ; if tmp then ( right := mid ) else ( left := mid + 1 )) ; return left; operation calc(n : OclAny) : OclAny pre: true post: true activity: var m : double := N - n - 1 ; var min_val : double := -D * n + C * m ; var max_val : double := -C * n + D * m ; return min_val, max_val; operation check(n : OclAny) : OclAny pre: true post: true activity: return (calc(n)->first()->compareTo(X)) <= 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def between(l,c,r): return l<=c and c<=r N,A,B,C,D=[int(i)for i in input().split()] ul=[A+D*i for i in range(N)] dl=[A+C*i for i in range(N)] ur=[B+D*i for i in range(N)][: :-1] dr=[B+C*i for i in range(N)][: :-1] res=False for i in range(N): if between(dl[i],ur[i],ul[i])or between(dl[i],dr[i],ul[i]): res=True print("YES" if res else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var D : OclAny := null; Sequence{N,A,B,C,D} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ul : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (A + D * i)) ; var dl : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (A + C * i)) ; var ur : OclAny := Integer.subrange(0, N-1)->select(i | true)->collect(i | (B + D * i))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var dr : OclAny := Integer.subrange(0, N-1)->select(i | true)->collect(i | (B + C * i))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var res : boolean := false ; for i : Integer.subrange(0, N-1) do ( if between(dl[i+1], ur[i+1], ul[i+1]) or between(dl[i+1], dr[i+1], ul[i+1]) then ( res := true ) else skip) ; execute (if res then "YES" else "NO" endif)->display(); operation between(l : OclAny, c : OclAny, r : OclAny) : OclAny pre: true post: true activity: return (l->compareTo(c)) <= 0 & (c->compareTo(r)) <= 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=map(int,input().split()) for _ in range(int(input())): x,y=map(int,input().split()) if y<=x+d and y>=x-d and x>=d-y and x<=2*n-d-y : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (y->compareTo(x + d)) <= 0 & (y->compareTo(x - d)) >= 0 & (x->compareTo(d - y)) >= 0 & (x->compareTo(2 * n - d - y)) <= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=map(int,input().split()) for _ in range(int(input())): x,y=map(int,input().split()) print("YES" if d<=x+y<=2*n-d and abs(x-y)<=d else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if (d->compareTo(x + y)) <= 0 & (x + y <= 2 * n - d) & ((x - y)->abs()->compareTo(d)) <= 0 then "YES" else "NO" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=list(map(int,input().split())) m=int(input()) count=0 for m in range(m): x,y=list(map(int,input().split())) if(x+y>=d)and(x+y<=(2*n-d))and(y-x<=d)and(x-y<=d): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := 0 ; for m : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if ((x + y->compareTo(d)) >= 0) & ((x + y->compareTo((2 * n - d))) <= 0) & ((y - x->compareTo(d)) <= 0) & ((x - y->compareTo(d)) <= 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def check_bipartite(s,links,visited): q=[(s,0)] is_bipartite=True count=0 while q : v,color=q.pop() if visited[v]!=-1 : if visited[v]!=color : is_bipartite=False continue visited[v]=color count+=1 new_color=color ^ 1 for u in links[v]: if visited[u]!=-1 : if visited[u]!=new_color : is_bipartite=False continue q.append((u,new_color)) return is_bipartite,count n,m=map(int,sys.stdin.buffer.readline().split()) links=[set()for _ in range(n)] mp=map(int,sys.stdin.buffer.read().split()) for u,v in zip(mp,mp): u-=1 v-=1 links[u].add(v) links[v].add(u) visited=[-1]*n count_bipartite=0 count_non_bipartite=0 count_isolated=0 ans=0 for v in range(n): if visited[v]!=-1 : continue is_bipartite,count=check_bipartite(v,links,visited) if count==1 : count_isolated+=1 elif is_bipartite : count_bipartite+=1 else : count_non_bipartite+=1 ans=count_isolated*(n*2-count_isolated) ans+=count_non_bipartite*(count_non_bipartite+count_bipartite*2) ans+=count_bipartite**2*2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; links := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; var mp : Sequence := (sys.stdin.buffer.readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for _tuple : Integer.subrange(1, mp->size())->collect( _indx | Sequence{mp->at(_indx), mp->at(_indx)} ) do (var _indx : int := 1; var u : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); u := u - 1 ; v := v - 1 ; (expr (atom (name links)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) ; (expr (atom (name links)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)))))))) ))))) ; visited := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; var count_bipartite : int := 0 ; var count_non_bipartite : int := 0 ; var count_isolated : int := 0 ; var ans : int := 0 ; for v : Integer.subrange(0, n-1) do ( if visited[v+1] /= -1 then ( continue ) else skip ; Sequence{is_bipartite,count} := check_bipartite(v, links, visited) ; if count = 1 then ( count_isolated := count_isolated + 1 ) else (if is_bipartite then ( count_bipartite := count_bipartite + 1 ) else ( count_non_bipartite := count_non_bipartite + 1 ) ) ) ; ans := count_isolated * (n * 2 - count_isolated) ; ans := ans + count_non_bipartite * (count_non_bipartite + count_bipartite * 2) ; ans := ans + (count_bipartite)->pow(2) * 2 ; execute (ans)->display(); operation check_bipartite(s : OclAny, links : OclAny, visited : OclAny) : OclAny pre: true post: true activity: var q : Sequence := Sequence{ Sequence{s, 0} } ; var is_bipartite : boolean := true ; var count : int := 0 ; while q do ( var v : OclAny := null; var color : OclAny := null; Sequence{v,color} := q->last() ; q := q->front() ; if visited[v+1] /= -1 then ( if visited[v+1] /= color then ( is_bipartite := false ) else skip ; continue ) else skip ; visited[v+1] := color ; count := count + 1 ; var new_color : int := MathLib.bitwiseXor(color, 1) ; for u : links[v+1] do ( if visited[u+1] /= -1 then ( if visited[u+1] /= new_color then ( is_bipartite := false ) else skip ; continue ) else skip ; execute ((Sequence{u, new_color}) : q))) ; return is_bipartite, count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=map(int,input().split()) for _ in range(int(input())): x,y=map(int,input().split()) print("YES" if abs(x-y)<=d<=x+y<=2*n-d else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if ((x - y)->abs()->compareTo(d)) <= 0 & (d <= x + y) & (x + y <= 2 * n - d) then "YES" else "NO" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=map(int,input().split()) m=int(input()) for i in range(m): x,y=map(int,input().split()) if-d<=x-y<=d<=x+y<=2*n-d : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (-d->compareTo(x - y)) <= 0 & (x - y <= d) & (d <= x + y) & (x + y <= 2 * n - d) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countDigit(n): if n==0 : return 0 return 1+countDigit(n//10) n=345289467 print("Number of digits : % d" %(countDigit(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 345289467 ; execute (StringLib.format("Number of digits : % d",(countDigit(n))))->display(); operation countDigit(n : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( return 0 ) else skip ; return 1 + countDigit(n div 10); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countDigit(n): count=0 while n!=0 : n//=10 count+=1 return count n=345289467 print("Number of digits : % d" %(countDigit(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 345289467 ; execute (StringLib.format("Number of digits : % d",(countDigit(n))))->display(); operation countDigit(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while n /= 0 do ( n := n div 10 ; count := count + 1) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def countDigit(n): return math.floor(math.log(n,10)+1) n=345289467 print("Number of digits : % d" %(countDigit(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 345289467 ; execute (StringLib.format("Number of digits : % d",(countDigit(n))))->display(); operation countDigit(n : OclAny) : OclAny pre: true post: true activity: return ((n, 10)->log() + 1)->floor(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import itertools x=100 for _ in itertools.repeat(None,int(input())): x=math.ceil(x*1.05) print(x*1000) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var x : int := 100 ; for _anon : itertools.repeat(null, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( x := (x * 1.05)->ceil()) ; execute (x * 1000)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sort_list(list1,list2): zipped_pairs=zip(list2,list1) z=[x for _,x in sorted(zipped_pairs)] return z n=int(input()) l=list(map(int,input().split())) l1=list(map(int,input().split())) l=sort_list(l,l1) l.reverse() l1.sort(reverse=True) f=set() nextq=dict() ans=0 def nex(i): if nextq[i]in f : nextq[i]=nex(nextq[i]) return nextq[i] for i in range(n): if l[i]in f : d=nex(l[i]) ans+=(d-l[i])*l1[i] f.add(d) nextq.update({d : d+1}) else : f.add(l[i]) nextq.update({l[i]: l[i]+1}) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := sort_list(l, l1) ; l := l->reverse() ; l1 := l1->sort() ; var f : Set := Set{}->union(()) ; var nextq : Map := (arguments ( )) ; var ans : int := 0 ; skip ; for i : Integer.subrange(0, n-1) do ( if (f)->includes(l[i+1]) then ( var d : OclAny := nex(l[i+1]) ; ans := ans + (d - l[i+1]) * l1[i+1] ; execute ((d) : f) ; execute ((Map{ d |-> d + 1 }) <: nextq) ) else ( execute ((l[i+1]) : f) ; execute ((Map{ l[i+1] |-> l[i+1] + 1 }) <: nextq) )) ; execute (ans)->display(); operation sort_list(list1 : OclAny, list2 : OclAny) : OclAny pre: true post: true activity: var zipped_pairs : Sequence := Integer.subrange(1, list2->size())->collect( _indx | Sequence{list2->at(_indx), list1->at(_indx)} ) ; var z : Sequence := zipped_pairs->sort()->select(_tuple | true)->collect(_tuple | let _anon : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in (x)) ; return z; operation nex(i : OclAny) : OclAny pre: true post: true activity: if (f)->includes(nextq[i+1]) then ( nextq[i+1] := nex(nextq[i+1]) ) else skip ; return nextq[i+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(i)for i in input().split(' ')] t=[int(i)for i in input().split(' ')] import collections from heapq import heapify,heappop,heappush l=collections.defaultdict(list) at=[[a[i],t[i]]for i in range(n)] at.sort(key=lambda x : x[0]) for aa,tt in at : l[aa].append(tt) res=0 q=sorted(l.keys())[: :-1] tmp=[] heapify(tmp) sums=0 while q : i=q.pop() if len(l[i])==1 and not tmp : continue else : for ll in l[i]: heappush(tmp,-ll) sums+=ll idx=i while tmp and((q and idx+1!=q[-1])or not q): p=-heappop(tmp) res+=sums-p sums-=p idx+=1 if tmp : p=-heappop(tmp) res+=sums-p sums-=p if not q : q.append(idx+1) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split(' ')->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var t : Sequence := input().split(' ')->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; skip ; skip ; var l : OclAny := .defaultdict(OclType["Sequence"]) ; var at : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{a[i+1]}->union(Sequence{ t[i+1] }))) ; at := at->sort() ; for _tuple : at do (var _indx : int := 1; var aa : OclAny := _tuple->at(_indx); _indx := _indx + 1; var tt : OclAny := _tuple->at(_indx); (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name aa)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name tt)))))))) ))))) ; var res : int := 0 ; var q : OclAny := sorted(l.keys())(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var tmp : Sequence := Sequence{} ; heapify(tmp) ; var sums : int := 0 ; while q do ( var i : OclAny := q->last() ; q := q->front() ; if (l[i+1])->size() = 1 & not(tmp) then ( continue ) else ( for ll : l[i+1] do ( heappush(tmp, -ll) ; sums := sums + ll) ; var idx : OclAny := i ; while tmp & ((q & idx + 1 /= q->last()) or not(q)) do ( var p : OclAny := -heappop(tmp) ; res := res + sums - p ; sums := sums - p ; idx := idx + 1) ; if tmp then ( p := -heappop(tmp) ; res := res + sums - p ; sums := sums - p ; if not(q) then ( execute ((idx + 1) : q) ) else skip ) else skip )) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline out=sys.stdout from heapq import* from collections import defaultdict n=int(input()) d=defaultdict(list) a=list(map(int,input().split())) t=list(map(int,input().split())) ans=0 for i in range(n): heappush(d[a[i]],t[i]) key_heap=list(d.keys()) heapify(key_heap) s=0 m_heap=[] while len(key_heap)>0 : k=heappop(key_heap) s+=sum(d[k]) while len(d[k])>0 : y=heappop(d[k]) heappush(m_heap,-y) t=heappop(m_heap) s+=t ans+=s if s!=0 and k+1 not in d.keys(): heappush(key_heap,k+1) del d[k] out.write(str(ans)+'\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var out : OclFile := OclFile["System.out"] ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : OclAny := defaultdict(OclType["Sequence"]) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( heappush(d[a[i+1]+1], t[i+1])) ; var key_heap : Sequence := (d.keys()) ; heapify(key_heap) ; var s : int := 0 ; var m_heap : Sequence := Sequence{} ; while (key_heap)->size() > 0 do ( var k : OclAny := heappop(key_heap) ; s := s + (d[k+1])->sum() ; while (d[k+1])->size() > 0 do ( var y : OclAny := heappop(d[k+1]) ; heappush(m_heap, -y)) ; t := heappop(m_heap) ; s := s + t ; ans := ans + s ; if s /= 0 & (d.keys())->excludes(k + 1) then ( heappush(key_heap, k + 1) ) else skip ; execute (d[k+1])->isDeleted()) ; out.write(("" + ((ans))) + ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline out=sys.stdout from heapq import* from collections import defaultdict n=int(input()) d=defaultdict(list) a=list(map(int,input().split())) t=list(map(int,input().split())) ans=0 for i in range(n): heappush(d[a[i]],t[i]) key_heap=list(d.keys()) heapify(key_heap) s=0 m_heap=[] while len(key_heap)>0 : k=heappop(key_heap) s+=sum(d[k]) while len(d[k])>0 : y=heappop(d[k]) heappush(m_heap,-y) t=heappop(m_heap) s+=t ans+=s if s!=0 and k+1 not in d.keys(): heappush(key_heap,k+1) del d[k] out.write(str(ans)+'\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var out : OclFile := OclFile["System.out"] ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : OclAny := defaultdict(OclType["Sequence"]) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( heappush(d[a[i+1]+1], t[i+1])) ; var key_heap : Sequence := (d.keys()) ; heapify(key_heap) ; var s : int := 0 ; var m_heap : Sequence := Sequence{} ; while (key_heap)->size() > 0 do ( var k : OclAny := heappop(key_heap) ; s := s + (d[k+1])->sum() ; while (d[k+1])->size() > 0 do ( var y : OclAny := heappop(d[k+1]) ; heappush(m_heap, -y)) ; t := heappop(m_heap) ; s := s + t ; ans := ans + s ; if s /= 0 & (d.keys())->excludes(k + 1) then ( heappush(key_heap, k + 1) ) else skip ; execute (d[k+1])->isDeleted()) ; out.write(("" + ((ans))) + ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def xoa(s): return ''.join([x for x in s.lower()if x not in '-_;']) a=xoa(input()) b=xoa(input()) c=xoa(input()) tohop=[a+b+c,a+c+b,b+a+c,b+c+a,c+a+b,c+b+a] for _ in range(int(input())): print('ACC' if xoa(input())in tohop else 'WA') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := xoa((OclFile["System.in"]).readLine()) ; var b : OclAny := xoa((OclFile["System.in"]).readLine()) ; var c : OclAny := xoa((OclFile["System.in"]).readLine()) ; var tohop : Sequence := Sequence{a + b + c}->union(Sequence{a + c + b}->union(Sequence{b + a + c}->union(Sequence{b + c + a}->union(Sequence{c + a + b}->union(Sequence{ c + b + a }))))) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (if (tohop)->includes(xoa((OclFile["System.in"]).readLine())) then 'ACC' else 'WA' endif)->display()); operation xoa(s : OclAny) : OclAny pre: true post: true activity: return StringLib.sumStringsWithSeparator((s->toLowerCase()->select(x | ('-_;')->characters()->excludes(x))->collect(x | (x))), ''); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq n=int(input()) a=[[]for _ in range(n)] j=0 for i in input().strip().split(' '): a[j].append(int(i)) j+=1 j=0 for i in input().strip().split(' '): a[j].append(int(i)) j+=1 a.sort() q=[] total=0 count=0 last=a[0][0] heapq.heappush(q,-a[0][1]) count+=a[0][1] for i in a[1 :]: if i[0]==last : heapq.heappush(q,-i[1]) count+=i[1] else : while q and lasttoInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var j : int := 0 ; for i : input()->trim().split(' ') do ((expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))) )))) ; j := j + 1) ; j := 0 ; for i : input()->trim().split(' ') do ((expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))) )))) ; j := j + 1) ; a := a->sort() ; var q : Sequence := Sequence{} ; var total : int := 0 ; var count : int := 0 ; var last : OclAny := a->first()->first() ; heapq.heappush(q, -a->first()[1+1]) ; count := count + a->first()[1+1] ; for i : a->tail() do ( if i->first() = last then ( heapq.heappush(q, -i[1+1]) ; count := count + i[1+1] ) else ( while q & (last->compareTo(i->first())) < 0 do ( count := count + heapq.heappop(q) ; total := total + Set{count, 0}->max() ; if count < 0 then ( count := 0 ) else skip ; last := last + 1) ; last := i->first() ; heapq.heappush(q, -i[1+1]) ; count := count + i[1+1] )) ; while q do ( count := count + heapq.heappop(q) ; total := total + Set{count, 0}->max() ; if count < 0 then ( count := 0 ) else skip) ; execute (total)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_N=44 _memo=[None for _ in range(MAX_N+1)] _memo[0]=_memo[1]=1 def fibonacci(n): if _memo[n]is not None : return _memo[n] else : _memo[n]=fibonacci(n-1)+fibonacci(n-2) return _memo[n] if __name__=='__main__' : n=int(input()) print(fibonacci(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_N : int := 44 ; var _memo : Sequence := Integer.subrange(0, MAX_N + 1-1)->select(_anon | true)->collect(_anon | (null)) ; _memo->first() := 1; var _memo[1+1] : int := 1 ; skip ; if __name__ = '__main__' then ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (fibonacci(n))->display() ) else skip; operation fibonacci(n : OclAny) : OclAny pre: true post: true activity: if not(_memo[n+1] <>= null) then ( return _memo[n+1] ) else ( _memo[n+1] := fibonacci(n - 1) + fibonacci(n - 2) ; return _memo[n+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def inpl(): return list(map(int,input().split())) def f(n): if n<2 : return 1 ret=[0]*(n+1) ret[0]=1 ret[1]=1 for i in range(2,n+1): ret[i]=ret[i-2]+ret[i-1] return ret[n] print(f(int(input()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; execute (f(("" + (((OclFile["System.in"]).readLine())))->toInteger()))->display(); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation f(n : OclAny) : OclAny pre: true post: true activity: if n < 2 then ( return 1 ) else skip ; var ret : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; ret->first() := 1 ; ret[1+1] := 1 ; for i : Integer.subrange(2, n + 1-1) do ( ret[i+1] := ret[i - 2+1] + ret[i - 1+1]) ; return ret[n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) dict={0 : 1,1 : 1} def fib(n): if n in dict.keys(): return dict[n] else : dict[n]=fib(n-1)+fib(n-2) return dict[n] print(fib(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var OclType["Map"] : Map := Map{ 0 |-> 1 }->union(Map{ 1 |-> 1 }) ; skip ; execute (fib(n))->display(); operation fib(n : OclAny) : OclAny pre: true post: true activity: if ((trailer . (name keys) (arguments ( ))))->includes(n) then ( return (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n)))))))) ]) ) else ( (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n)))))))) ]) := fib(n - 1) + fib(n - 2) ; return (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n)))))))) ]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class fibonacci : def __init__(self): self.result : List[int]=[-1]*1000 return def calc(self,n): if(n==0 or n==1): self.result[n]=1 return 1 if(self.result[n]!=-1): return self.result[n] self.result[n-1]=self.calc(n-1) self.result[n-2]=self.calc(n-2) return self.result[n-1]+self.result[n-2] n=int(input()) print(fibonacci().calc(n)) ------------------------------------------------------------ OCL File: --------- class fibonacci { static operation newfibonacci() : fibonacci pre: true post: fibonacci->exists( _x | result = _x ); attribute result : OclAny : OclAny := MatrixLib.elementwiseMult(Sequence{ -1 }, 1000); operation initialise() : fibonacci pre: true post: true activity: var self.result : OclAny := MatrixLib.elementwiseMult(Sequence{ -1 }, 1000) ; return; return self; operation calc(n : OclAny) : OclAny pre: true post: true activity: if (n = 0 or n = 1) then ( self.result[n+1] := 1 ; return 1 ) else skip ; if (self.result[n+1] /= -1) then ( return self.result[n+1] ) else skip ; self.result[n - 1+1] := self.calc(n - 1) ; self.result[n - 2+1] := self.calc(n - 2) ; return self.result[n - 1+1] + self.result[n - 2+1]; } class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (fibonacci().calc(n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**7) input=sys.stdin.readline f_inf=float('inf') mod=10**9+7 def resolve(): n=int(input()) fib=[0]*(n+1) fib[0],fib[1]=1,1 for i in range(2,n+1): fib[i]=fib[i-1]+fib[i-2] print(fib[-1]) if __name__=='__main__' : resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var input : OclAny := (OclFile["System.in"]).readline ; var f_inf : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; skip ; if __name__ = '__main__' then ( resolve() ) else skip; operation resolve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var fib : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var fib->first() : OclAny := null; var fib[1+1] : OclAny := null; Sequence{fib->first(),fib[1+1]} := Sequence{1,1} ; for i : Integer.subrange(2, n + 1-1) do ( fib[i+1] := fib[i - 1+1] + fib[i - 2+1]) ; execute (fib->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=100000 ; n=int(input()) while n>0 : n-=1 m=m+(m*5)//100 m=((m-1)//1000+1)*1000 print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : int := 100000; ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while n > 0 do ( n := n - 1 ; m := m + (m * 5) div 100 ; m := ((m - 1) div 1000 + 1) * 1000) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minDiff(n,x,A): mn=A[0] mx=A[0] for i in range(0,n): mn=min(mn,A[i]) mx=max(mx,A[i]) return max(0,mx-mn-2*x) n=3 x=3 A=[1,3,6] print(minDiff(n,x,A)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3 ; x := 3 ; A := Sequence{1}->union(Sequence{3}->union(Sequence{ 6 })) ; execute (minDiff(n, x, A))->display(); operation minDiff(n : OclAny, x : OclAny, A : OclAny) : OclAny pre: true post: true activity: var mn : OclAny := A->first() ; var mx : OclAny := A->first() ; for i : Integer.subrange(0, n-1) do ( mn := Set{mn, A[i+1]}->min() ; mx := Set{mx, A[i+1]}->max()) ; return Set{0, mx - mn - 2 * x}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNthNum(N): bit_L=1 ; last_num=0 ; while(bit_L*(bit_L+1)/2compareTo(N)) < 0) do ( last_num := last_num + bit_L; ; bit_L := bit_L + 1;) ; var bit_R : double := N - last_num - 1; ; execute ((1 * (2->pow(bit_L))) + (1 * (2->pow(bit_R))))->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=10000000019 x=0 def mod(x): return(x % m+m)% m def pow(x,a): ret=1 while a : if(a & 1): ret=mod(x*ret) x=mod(x*x) a>>=1 return ret for _ in range(int(input())): o,y=map(int,input().split()) if o==1 : x=(x+y)% m elif o==2 : x=(x-y)% m elif o==3 : x=mod(x*y) else : x=mod(x*pow(y,m-2)) print(x if x<(1<<31)else x-m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : int := 10000000019 ; var x : int := 0 ; skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var o : OclAny := null; var y : OclAny := null; Sequence{o,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if o = 1 then ( x := (x + y) mod m ) else (if o = 2 then ( x := (x - y) mod m ) else (if o = 3 then ( x := mod(x * y) ) else ( x := mod(x * (y)->pow(m - 2)) ) ) ) ) ; execute (if (x->compareTo((1 * (2->pow(31))))) < 0 then x else x - m endif)->display(); operation mod(x : OclAny) : OclAny pre: true post: true activity: return (x mod m + m) mod m; operation pow(x : OclAny, a : OclAny) : OclAny pre: true post: true activity: var ret : int := 1 ; while a do ( if (MathLib.bitwiseAnd(a, 1)) then ( ret := mod(x * ret) ) else skip ; x := mod(x * x) ; a := a div (2->pow(1))) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=["_",";","-"] s1=input().upper() s2=input().upper() s3=input().upper() t=int(input()) s11="".join(i for i in s1 if i not in l) s22="".join(i for i in s2 if i not in l) s33="".join(i for i in s3 if i not in l) a1=s11+s22+s33 a2=s11+s33+s22 a3=s22+s11+s33 a4=s22+s33+s11 a5=s33+s11+s22 a6=s33+s22+s11 for i in range(0,t): I=input().upper() i1="".join(i for i in I if i not in l) if i1==a1 or i1==a2 or i1==a3 or i1==a4 or i1==a5 or i1==a6 : print("ACC") else : print("WA") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := Sequence{"_"}->union(Sequence{";"}->union(Sequence{ "-" })) ; var s1 : OclAny := input()->toUpperCase() ; var s2 : OclAny := input()->toUpperCase() ; var s3 : OclAny := input()->toUpperCase() ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s11 : String := StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name s1))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name i)))) not in (comparison (expr (atom (name l))))))))))), "") ; var s22 : String := StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name s2))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name i)))) not in (comparison (expr (atom (name l))))))))))), "") ; var s33 : String := StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name s3))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name i)))) not in (comparison (expr (atom (name l))))))))))), "") ; var a1 : String := s11 + s22 + s33 ; var a2 : String := s11 + s33 + s22 ; var a3 : String := s22 + s11 + s33 ; var a4 : String := s22 + s33 + s11 ; var a5 : String := s33 + s11 + s22 ; var a6 : String := s33 + s22 + s11 ; for i : Integer.subrange(0, t-1) do ( var I : OclAny := input()->toUpperCase() ; var i1 : String := StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name I))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name i)))) not in (comparison (expr (atom (name l))))))))))), "") ; if i1 = a1 or i1 = a2 or i1 = a3 or i1 = a4 or i1 = a5 or i1 = a6 then ( execute ("ACC")->display() ) else ( execute ("WA")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def checkPerfectcube(n): cube_root=n**(1./3.) if round(cube_root)**3==n : return True else : return False def largestPerfectcubeNumber(a,n): maxi=-1 for i in range(0,n,1): if(checkPerfectcube(a[i])): maxi=max(a[i],maxi) return maxi ; if __name__=='__main__' : a=[16,64,25,2,3,10] n=len(a) print(largestPerfectcubeNumber(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( a := Sequence{16}->union(Sequence{64}->union(Sequence{25}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 10 }))))) ; n := (a)->size() ; execute (largestPerfectcubeNumber(a, n))->display() ) else skip; operation checkPerfectcube(n : OclAny) : OclAny pre: true post: true activity: var cube_root : double := (n)->pow((1. / 3.)) ; if ((cube_root)->round())->pow(3) = n then ( return true ) else ( return false ); operation largestPerfectcubeNumber(a : OclAny, n : OclAny) pre: true post: true activity: var maxi : int := -1 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (checkPerfectcube(a[i+1])) then ( maxi := Set{a[i+1], maxi}->max() ) else skip) ; return maxi;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import exit,stdin N,M=[int(_)for _ in stdin.readline().rstrip().split()] s1=set() sn=set() for _ in range(M): a,b=[int(_)for _ in stdin.readline().rstrip().split()] if a==1 : s1.add(b) elif b==N : sn.add(a) for x in s1 : if x in sn : print("POSSIBLE") exit(0) print("IMPOSSIBLE") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := stdin.readLine().rstrip().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var s1 : Set := Set{}->union(()) ; var sn : Set := Set{}->union(()) ; for _anon : Integer.subrange(0, M-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := stdin.readLine().rstrip().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; if a = 1 then ( execute ((b) : s1) ) else (if b = N then ( execute ((a) : sn) ) else skip)) ; for x : s1 do ( if (sn)->includes(x) then ( execute ("POSSIBLE")->display() ; exit(0) ) else skip) ; execute ("IMPOSSIBLE")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) AB={} ans='IMPOSSIBLE' for i in range(m): a,b=map(int,input().split()) if a==1 : if b in AB : if AB[b]==n : ans='POSSIBLE' break else : AB[b]=1 if b==n : if a in AB : if AB[a]==1 : ans='POSSIBLE' break else : AB[a]=n print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var AB : OclAny := Set{} ; var ans : String := 'IMPOSSIBLE' ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 1 then ( if (AB)->includes(b) then ( if AB[b+1] = n then ( ans := 'POSSIBLE' ; break ) else skip ) else ( AB[b+1] := 1 ) ) else skip ; if b = n then ( if (AB)->includes(a) then ( if AB[a+1] = 1 then ( ans := 'POSSIBLE' ; break ) else skip ) else ( AB[a+1] := n ) ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 from collections import deque N,M=map(int,input().split()) cost=[[]for _ in range(N)] visited=[False]*N for i in range(M): a,b=map(int,input().split()) a-=1 b-=1 cost[a].append(b) def bfs(node,dist): d=deque() d.append((node,dist)) while d : (node,dist)=d.popleft() if visited[node]!=False : continue visited[node]=dist for i in cost[node]: d.append((i,dist+1)) return visited[N-1] if bfs(0,0)==2 : print('POSSIBLE') else : print('IMPOSSIBLE') ------------------------------------------------------------ OCL File: --------- class FromPython { suite`nestedAttributeDefinitions operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit(2147483647) ; var INF : double := ("" + (("inf")))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cost : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, N) ; for i : Integer.subrange(0, M-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := a - 1 ; b := b - 1 ; (expr (atom (name cost)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) ))))) ; skip ; var Sequence{node, dist} : OclAny := d->first() ; d := d->tail(); operation bfs(node : OclAny, dist : OclAny) pre: true post: true activity: var d : Sequence := () ; execute ((Sequence{node, dist}) : d) ; while d do (suite); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(1<<25) read=sys.stdin.readline ra=range enu=enumerate def mina(*argv,sub=1): return list(map(lambda x : x-sub,argv)) def a_int(): return int(read()) def ints(): return list(map(int,read().split())) from collections import defaultdict N,M=ints() graph=defaultdict(lambda :[]) for _ in ra(M): a,b=mina(*ints()) graph[a].append(b) graph[b].append(a) def dfs(now,fr,d): if d==2 : return now==N-1 res=False for to in graph[now]: if fr==to : continue res=res or dfs(to,now,d+1) return res print('POSSIBLE' if dfs(0,-1,0)else 'IMPOSSIBLE') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(1 * (2->pow(25))) ; var read : OclAny := (OclFile["System.in"]).readline ; var ra : OclAny := range ; var enu : OclAny := enumerate ; skip ; skip ; skip ; skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := ints() ; var graph : OclAny := defaultdict(lambda $$ : OclAny in (Sequence{})) ; for _anon : ra(M) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := mina((argument * (test (logical_test (comparison (expr (atom (name ints)) (trailer (arguments ( ))))))))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; skip ; execute (if dfs(0, -1, 0) then 'POSSIBLE' else 'IMPOSSIBLE' endif)->display(); operation mina(argv : OclAny : Sequence(OclAny), sub : int) : OclAny pre: true post: true activity: (args * (named_parameter (name argv))) if sub->oclIsUndefined() then sub := 1 else skip; return ((argv)->collect( _x | (lambda x : OclAny in (x - sub))->apply(_x) )); operation a_int() : OclAny pre: true post: true activity: return ("" + ((read())))->toInteger(); operation ints() : OclAny pre: true post: true activity: return ((read().split())->collect( _x | (OclType["int"])->apply(_x) )); operation dfs(now : OclAny, fr : OclAny, d : OclAny) : OclAny pre: true post: true activity: if d = 2 then ( return now = N - 1 ) else skip ; var res : boolean := false ; for to : graph[now+1] do ( if fr = to then ( continue ) else skip ; res := res or dfs(to, now, d + 1)) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=lambda : map(int,input().split()) n,m=f() c=[[]for _ in range(n+1)] for _ in range(m): a,b=f() c[a]+=[b] c[b]+=[a] print("IMPOSSIBLE" if all(n not in c[i]for i in c[1])else "POSSIBLE") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := f->apply() ; var c : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := f->apply() ; c[a+1] := c[a+1] + Sequence{ b } ; c[b+1] := c[b+1] + Sequence{ a }) ; execute (if ((argument (test (logical_test (comparison (comparison (expr (atom (name n)))) not in (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))))->forAll( _x | _x = true ) then "IMPOSSIBLE" else "POSSIBLE" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=1000000 def MinimumCost(cost,n,W): val=list() wt=list() size=0 for i in range(n): if(cost[i]!=-1): val.append(cost[i]) wt.append(i+1) size+=1 n=size min_cost=[[0 for i in range(W+1)]for j in range(n+1)] for i in range(W+1): min_cost[0][i]=INF for i in range(1,n+1): min_cost[i][0]=0 for i in range(1,n+1): for j in range(1,W+1): if(wt[i-1]>j): min_cost[i][j]=min_cost[i-1][j] else : min_cost[i][j]=min(min_cost[i-1][j],min_cost[i][j-wt[i-1]]+val[i-1]) if(min_cost[n][W]==INF): return-1 else : return min_cost[n][W] cost=[1,2,3,4,5] W=5 n=len(cost) print(MinimumCost(cost,n,W)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INF : int := 1000000 ; skip ; cost := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ; W := 5 ; n := (cost)->size() ; execute (MinimumCost(cost, n, W))->display(); operation MinimumCost(cost : OclAny, n : OclAny, W : OclAny) : OclAny pre: true post: true activity: var val : Sequence := () ; var wt : Sequence := () ; var size : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (cost[i+1] /= -1) then ( execute ((cost[i+1]) : val) ; execute ((i + 1) : wt) ; size := size + 1 ) else skip) ; n := size ; var min_cost : Sequence := Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, W + 1-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, W + 1-1) do ( min_cost->first()[i+1] := INF) ; for i : Integer.subrange(1, n + 1-1) do ( min_cost[i+1]->first() := 0) ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, W + 1-1) do ( if ((wt[i - 1+1]->compareTo(j)) > 0) then ( min_cost[i+1][j+1] := min_cost[i - 1+1][j+1] ) else ( min_cost[i+1][j+1] := Set{min_cost[i - 1+1][j+1], min_cost[i+1][j - wt[i - 1+1]+1] + val[i - 1+1]}->min() ))) ; if (min_cost[n+1][W+1] = INF) then ( return -1 ) else ( return min_cost[n+1][W+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : n=int(input()) y=100000 y2=y/1000 for i in range(0,n): y4=y2*1.05 y3=float(int(y2*1.05)) if y4-y3>0 : y4+=1 y2=int(y4) print(y2*1000) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var y : int := 100000 ; var y2 : double := y / 1000 ; for i : Integer.subrange(0, n-1) do ( var y4 : double := y2 * 1.05 ; var y3 : double := ("" + ((("" + ((y2 * 1.05)))->toInteger())))->toReal() ; if y4 - y3 > 0 then ( y4 := y4 + 1 ) else skip ; y2 := ("" + ((y4)))->toInteger()) ; execute (y2 * 1000)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def findRoots(a,b,c): if a==0 : print("Invalid") return-1 d=b*b-4*a*c sqrt_val=math.sqrt(abs(d)) if d>0 : print("Roots are real and different ") print((-b+sqrt_val)/(2*a)) print((-b-sqrt_val)/(2*a)) elif d==0 : print("Roots are real and same") print(-b/(2*a)) else : print("Roots are complex") print(-b/(2*a),"+i",sqrt_val) print(-b/(2*a),"-i",sqrt_val) a=1 b=-7 c=12 findRoots(a,b,c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 1 ; b := -7 ; c := 12 ; findRoots(a, b, c); operation findRoots(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: if a = 0 then ( execute ("Invalid")->display() ; return -1 ) else skip ; var d : double := b * b - 4 * a * c ; var sqrt_val : double := ((d)->abs())->sqrt() ; if d > 0 then ( execute ("Roots are real and different ")->display() ; execute ((-b + sqrt_val) / (2 * a))->display() ; execute ((-b - sqrt_val) / (2 * a))->display() ) else (if d = 0 then ( execute ("Roots are real and same")->display() ; execute (-b / (2 * a))->display() ) else ( execute ("Roots are complex")->display() ; execute (-b / (2 * a))->display() ; execute (-b / (2 * a))->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys with open(sys.argv[1])as f : lines=f.readlines() T=int(lines[0],10) for tt,l in enumerate(lines[1 :]): pancakes=l.strip() done=False flips=0 while 1 : index=pancakes.rfind("-") if index==-1 : break flips+=1 new_cakes="" for i in xrange(index+1): if pancakes[i]=="+" : new_cakes+="-" elif pancakes[i]=="-" : new_cakes+="+" else : raise Exception("wtf") pancakes=new_cakes+pancakes[index+1 :] print("Case #%d:" %(tt+1)),flips ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; try (var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))); var lines : String := f.readlines()) catch (_e : OclException) do skip ; var T : int := ("" + ((lines->first(), 10)))->toInteger() ; for _tuple : Integer.subrange(1, (lines->tail())->size())->collect( _indx | Sequence{_indx-1, (lines->tail())->at(_indx)} ) do (var _indx : int := 1; var tt : OclAny := _tuple->at(_indx); _indx := _indx + 1; var l : OclAny := _tuple->at(_indx); var pancakes : String := l->trim() ; var done : boolean := false ; var flips : int := 0 ; while 1 do ( var index : OclAny := pancakes.rfind("-") ; if index = -1 then ( break ) else skip ; flips := flips + 1 ; var new_cakes : String := "" ; for i : xrange(index + 1) do ( if pancakes[i+1] = "+" then ( new_cakes := new_cakes + "-" ) else (if pancakes[i+1] = "-" then ( new_cakes := new_cakes + "+" ) else ( error ProgramException.newProgramException("wtf") ) ) ) ; pancakes := new_cakes + pancakes.subrange(index + 1+1)) ; (StringLib.format("Case #%d:",(tt + 1)))->display() ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import heapq import sys import math import itertools import bisect from io import BytesIO,IOBase import os def valid(i,j,n,m): if i=0 and j>=0 and jcompareTo(n)) < 0 & i >= 0 & j >= 0 & (j->compareTo(m)) < 0 then ( return true ) else skip ; return false; operation sumn(i : OclAny, n : OclAny) : OclAny pre: true post: true activity: return (n - i) * (i + n) / 2; operation sqfun(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: return (-b + (b * b - 4 * a * c)->sqrt()) / 2 * a; operation value() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation values() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inlsts() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inps() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation instr() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation stlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (i)); operation f(s : OclAny) : OclAny pre: true post: true activity: var r : String := '' ; for i : s do ( if (Sequence{'-'}->union(Sequence{';'}->union(Sequence{ '_' })))->excludes(i) then ( r := r + i->toLowerCase() ) else skip) ; return r; operation solve() pre: true post: true activity: var l : Sequence := Sequence{} ; for i : Integer.subrange(0, 3-1) do ( execute ((f((OclFile["System.in"]).readLine())) : l)) ; var t : OclAny := itertools.permutations(l, (l)->size()) ; l := Sequence{} ; for i : t do ( execute ((StringLib.sumStringsWithSeparator((i), "")) : l)) ; for i : Integer.subrange(0, inp()-1) do ( if (l)->includes(f(instr())) then ( execute ('ACC')->display() ) else ( execute ('WA')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=open('C:\\Users\\djspence\\Downloads\\B-large.in','r') tries=int(f.readline()) for i in range(0,tries): pans=f.readline().strip() flips=0 for j in range(1,len(pans)): if pans[j]!=pans[j-1]: flips+=1 if pans[len(pans)-1]=="-" : flips+=1 print("Case #"+str(i+1)+": "+str(flips)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('C:\\Users\\djspence\\Downloads\\B-large.in')) ; var tries : int := ("" + ((f.readLine())))->toInteger() ; for i : Integer.subrange(0, tries-1) do ( var pans : OclAny := f.readLine()->trim() ; var flips : int := 0 ; for j : Integer.subrange(1, (pans)->size()-1) do ( if pans[j+1] /= pans[j - 1+1] then ( flips := flips + 1 ) else skip) ; if pans[(pans)->size() - 1+1] = "-" then ( flips := flips + 1 ) else skip ; execute ("Case #" + ("" + ((i + 1))) + ": " + ("" + ((flips))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,inspect problemName='pancakes' runOnRealData=True def solution(string): current='+' flips=0 for c in string[: :-1]: if c!=current : flips+=1 current=c return flips currentDir=os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) inputString='B-large.in' outputString=problemName+('_example_output' if not runOnRealData else '_output') inFile=os.path.join(currentDir,'inputfiles',inputString) outFile=os.path.join(currentDir,'outputfiles','%s.txt' % outputString) if os.path.exists(outFile): os.remove(outFile) with open(inFile,'r')as inputfile : numberOfCases=int(inputfile.readline()) for case in xrange(1,numberOfCases+1): string=inputfile.readline().strip() result=solution(string) with open(outFile,'a')as f : f.write('Case #%d: %d\n' %(case,result)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var problemName : String := 'pancakes' ; var runOnRealData : boolean := true ; skip ; var currentDir : OclAny := os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) ; var inputString : String := 'B-large.in' ; var outputString : String := problemName + (if not(runOnRealData) then '_example_output' else '_output' endif) ; var inFile : OclAny := os.path.join(currentDir, 'inputfiles', inputString) ; var outFile : OclAny := os.path.join(currentDir, 'outputfiles', StringLib.format('%s.txt',outputString)) ; if os.path.exists(outFile) then ( execute ((outFile) /: os) ) else skip ; try (var inputfile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(inFile)); var numberOfCases : int := ("" + ((inputfile.readLine())))->toInteger() ; for case : xrange(1, numberOfCases + 1) do ( string := inputfile.readLine()->trim() ; var result : OclAny := solution(string) ; try (var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(outFile)); f.write(StringLib.format('Case #%d: %d ',Sequence{case, result}))) catch (_e : OclException) do skip)) catch (_e : OclException) do skip; operation solution(string : OclAny) : OclAny pre: true post: true activity: var current : String := '+' ; var flips : int := 0 ; for c : string(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if c /= current then ( flips := flips + 1 ; current := c ) else skip) ; return flips; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import itertools import numpy as np import devtools def read_case(f): return read_letters(f) def solve_small(case): S=case S.append('+') return sum(S[i]!=S[i+1]for i in range(len(S)-1)) def solve_large(case): return solve_small(case) def write_case(f,i,res): f.write('Case #%d: ' % i) f.write('%s' % res) f.write('\n') def read_word(f): return next(f).strip() def read_int(f,b=10): return int(read_word(f),b) def read_letters(f): return list(read_word(f)) def read_digits(f,b=10): return[int(x,b)for x in read_letters(f)] def read_words(f,d=' '): return read_word(f).split(d) def read_ints(f,b=10,d=' '): return[int(x,b)for x in read_words(f,d)] def read_floats(f,d=' '): return[float(x)for x in read_words(f,d)] def read_arr(f,R,reader=read_ints,*args,**kwargs): return[reader(f,*args,**kwargs)for i in range(R)] def solve(solver,fn,out_fn=None): in_fn=fn+'.in' if out_fn is None : out_fn=fn+'.out' with open(in_fn,'r')as fi : with open(out_fn,'w')as fo : T=read_int(fi) for i in range(T): case=read_case(fi) res=solver(case) write_case(fo,i,res) from run import* ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip; operation read_case(f : OclAny) : OclAny pre: true post: true activity: return read_letters(f); operation solve_small(case : OclAny) : OclAny pre: true post: true activity: var S : OclAny := case ; execute (('+') : S) ; return ((argument (test (logical_test (comparison (comparison (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) != (comparison (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name S)))))))) )))) - (expr (atom (number (integer 1)))))))))) )))))))))->sum(); operation solve_large(case : OclAny) : OclAny pre: true post: true activity: return solve_small(case); operation write_case(f : OclAny, i : OclAny, res : OclAny) pre: true post: true activity: f.write(StringLib.format('Case #%d: ',i)) ; f.write(StringLib.format('%s',res)) ; f.write(' '); operation read_word(f : OclAny) : OclAny pre: true post: true activity: return next(f)->trim(); operation read_int(f : OclAny, b : int) : OclAny pre: true post: true activity: if b->oclIsUndefined() then b := 10 else skip; return ("" + ((read_word(f), b)))->toInteger(); operation read_letters(f : OclAny) : OclAny pre: true post: true activity: return (read_word(f)); operation read_digits(f : OclAny, b : int) : OclAny pre: true post: true activity: if b->oclIsUndefined() then b := 10 else skip; return read_letters(f)->select(x | true)->collect(x | (("" + ((x, b)))->toInteger())); operation read_words(f : OclAny, d : String) : OclAny pre: true post: true activity: if d->oclIsUndefined() then d := ' ' else skip; return read_word(f).split(d); operation read_ints(f : OclAny, b : int, d : String) : OclAny pre: true post: true activity: if b->oclIsUndefined() then b := 10 else skip; if d->oclIsUndefined() then d := ' ' else skip; return read_words(f, d)->select(x | true)->collect(x | (("" + ((x, b)))->toInteger())); operation read_floats(f : OclAny, d : String) : OclAny pre: true post: true activity: if d->oclIsUndefined() then d := ' ' else skip; return read_words(f, d)->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation read_arr(f : OclAny, R : OclAny, reader : OclAny, args : OclAny : Sequence(OclAny), kwargs : OclAny : Map(String, OclAny)) : OclAny pre: true post: true activity: if reader->oclIsUndefined() then reader := read_ints else skip; (args * (named_parameter (name args)))(kwargs ** (named_parameter (name kwargs))) return Integer.subrange(0, R-1)->select(i | true)->collect(i | (reader(f, (argument * (test (logical_test (comparison (expr (atom (name args))))))), (argument ** (test (logical_test (comparison (expr (atom (name kwargs)))))))))); operation solve(solver : OclAny, fn : OclAny, out_fn : OclAny) pre: true post: true activity: if out_fn->oclIsUndefined() then out_fn := null else skip; var in_fn : OclAny := fn + '.in' ; if out_fn <>= null then ( out_fn := fn + '.out' ) else skip ; try (var fi : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(in_fn)); try (var fo : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(out_fn)); var T : OclAny := read_int(fi) ; for i : Integer.subrange(0, T-1) do ( case := read_case(fi) ; res := solver(case) ; write_case(fo, i, res))) catch (_e : OclException) do skip) catch (_e : OclException) do skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- TEST='large' IN='B-{}.in'.format(TEST) OUT='B-{}.out'.format(TEST) def run(stack): n=len(stack) stack+='+' cnt=0 for i in range(n): if stack[i]!=stack[i+1]: cnt+=1 return cnt def main(): with open(IN)as fin,open(OUT,'w')as fout : t=int(fin.readline().strip()) for i in range(t): stack=fin.readline().strip() res=run(stack) print('Case #{}:{}'.format(i+1,res),file=fout) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var TEST : String := 'large' ; var IN : String := StringLib.interpolateStrings('B-{}.in', Sequence{TEST}) ; var OUT : String := StringLib.interpolateStrings('B-{}.out', Sequence{TEST}) ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation run(stack : OclAny) : OclAny pre: true post: true activity: var n : int := (stack)->size() ; stack := stack + '+' ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( if stack[i+1] /= stack[i + 1+1] then ( cnt := cnt + 1 ) else skip) ; return cnt; operation main() pre: true post: true activity: try (var fin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(IN)); var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(OUT)); var t : int := ("" + ((fin.readLine()->trim())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( stack := fin.readLine()->trim() ; var res : OclAny := run(stack) ; execute (StringLib.interpolateStrings('Case #{}:{}', Sequence{i + 1, res}))->display())) catch (_e : OclException) do skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printCombination(n): print("1 ",end=""); if((n-2)% 3==0): print("2",n-3,end=""); else : print("1",(n-2),end=""); if __name__=='__main__' : n=233 ; printCombination(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 233; ; printCombination(n); ) else skip; operation printCombination(n : OclAny) pre: true post: true activity: execute ("1 ")->display(); ; if ((n - 2) mod 3 = 0) then ( execute ("2")->display(); ) else ( execute ("1")->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkUnimodal(arr,n): i=1 while(iarr[i-1]): i+=1 while(iunion(Sequence{5}->union(Sequence{5}->union(Sequence{5}->union(Sequence{4}->union(Sequence{ 2 }))))) ; n := (arr)->size() ; if (checkUnimodal(arr, n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation checkUnimodal(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var i : int := 1 ; while ((i->compareTo(n)) < 0 & (arr[i+1]->compareTo(arr[i - 1+1])) > 0) do ( i := i + 1) ; while ((i->compareTo(n)) < 0 & arr[i+1] = arr[i - 1+1]) do ( i := i + 1) ; while ((i->compareTo(n)) < 0 & (arr[i+1]->compareTo(arr[i - 1+1])) < 0) do ( i := i + 1) ; return (i = n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=float("Inf") ary=list(map(int,input().split())) total=sum(ary) a=0 for i in range(n-1): a+=ary[i] total-=ary[i] ans=min(ans,abs(a-total)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : double := ("" + (("Inf")))->toReal() ; var ary : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var total : OclAny := (ary)->sum() ; var a : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( a := a + ary[i+1] ; total := total - ary[i+1] ; ans := Set{ans, (a - total)->abs()}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(N,a): suma=0 SUM=sum(a) MIN=10**15 for i in a[:(N-1)]: suma+=i MIN=min(MIN,abs(2*suma-SUM)) return abs(MIN) if __name__=="__main__" : N=int(input()) a=list(map(int,input().split())) print(solve(N,a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (solve(N, a))->display() ) else skip; operation solve(N : OclAny, a : OclAny) : OclAny pre: true post: true activity: var suma : int := 0 ; var SUM : OclAny := (a)->sum() ; var MIN : double := (10)->pow(15) ; for i : a.subrange(1,(N - 1)) do ( suma := suma + i ; MIN := Set{MIN, (2 * suma - SUM)->abs()}->min()) ; return (MIN)->abs(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=100000 while n>0 : a*=1.05 if a % 1000!=0 : a=int(a+1000-(a % 1000)) n-=1 print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := 100000 ; while n > 0 do ( a := a * 1.05 ; if a mod 1000 /= 0 then ( a := ("" + ((a + 1000 - (a mod 1000))))->toInteger() ) else skip ; n := n - 1) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np N=int(input()) a=list(map(int,input().split())) tmp=a[0] S=sum(a) ans=np.abs(S-2*tmp) for i in range(1,N-1): tmp+=a[i] ans=min(ans,np.abs(S-2*tmp)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var tmp : OclAny := a->first() ; var S : OclAny := (a)->sum() ; var ans : (trailer . (name abs) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name S))) - (expr (expr (atom (number (integer 2)))) * (expr (atom (name tmp)))))))))) ))) := ; for i : Integer.subrange(1, N - 1-1) do ( tmp := tmp + a[i+1] ; ans := Set{ans, }->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input().replace(";","").replace("-","").replace("_","").lower() p=input().replace(";","").replace("-","").replace("_","").lower() c=input().replace(";","").replace("-","").replace("_","").lower() z=[n+p+c,n+c+p,c+n+p,c+p+n,p+c+n,p+n+c] for i in range(int(input())): q=input().replace(";","").replace("-","").replace("_","").lower() if q in z : print("ACC") else : print("WA") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := input().replace(";", "").replace("-", "").replace("_", "")->toLowerCase() ; var p : OclAny := input().replace(";", "").replace("-", "").replace("_", "")->toLowerCase() ; var c : OclAny := input().replace(";", "").replace("-", "").replace("_", "")->toLowerCase() ; var z : Sequence := Sequence{n + p + c}->union(Sequence{n + c + p}->union(Sequence{c + n + p}->union(Sequence{c + p + n}->union(Sequence{p + c + n}->union(Sequence{ p + n + c }))))) ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var q : OclAny := input().replace(";", "").replace("-", "").replace("_", "")->toLowerCase() ; if (z)->includes(q) then ( execute ("ACC")->display() ) else ( execute ("WA")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=[int(x)for x in input().split()] B=[0]*N x=sum(A) y=0 ret=abs(sum(A)-A[0]-A[0]) for i,a in enumerate(A[:-1]): y+=a x-=a ret=min(ret,abs(x-y)) print(ret) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var B : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var x : OclAny := (A)->sum() ; var y : int := 0 ; var ret : double := ((A)->sum() - A->first() - A->first())->abs() ; for _tuple : Integer.subrange(1, (A->front())->size())->collect( _indx | Sequence{_indx-1, (A->front())->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); y := y + a ; x := x - a ; ret := Set{ret, (x - y)->abs()}->min()) ; execute (ret)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(x)for x in input().split()] sm=sum(a)//2 mn=10**10 ar=a[0] su=a[-1] for i in range(1,len(a)-1): if abs(sm-ar)2 : ar=sum(a[0 : mn_i]) su=sum(a[mn_i : :]) print(abs(ar-su)) else : print(abs(ar-su)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var sm : int := (a)->sum() div 2 ; var mn : double := (10)->pow(10) ; var ar : OclAny := a->first() ; var su : OclAny := a->last() ; for i : Integer.subrange(1, (a)->size() - 1-1) do ( if ((sm - ar)->abs()->compareTo(mn)) < 0 then ( mn := (sm - ar)->abs() ; var mn_i : OclAny := i ) else skip ; ar := ar + a[i+1]) ; if (a)->size() > 2 then ( ar := (a.subrange(0+1, mn_i))->sum() ; su := (a(subscript (test (logical_test (comparison (expr (atom (name mn_i)))))) : (sliceop :)))->sum() ; execute ((ar - su)->abs())->display() ) else ( execute ((ar - su)->abs())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) s=set() for i in range(N): s.add(tuple(sorted(map(int,input().split())))) print(N-len(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Set := Set{}->union(()) ; for i : Integer.subrange(0, N-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort())) : s)) ; execute (N - (s)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) points=[] tmp=(list(map(int,input().split()))) tmp.sort() points.append(tmp) for i in range(n-1): new=list(map(int,input().split())) new.sort() flag=True for arr in points : if(arr[0]==new[0]and arr[1]==new[1]and arr[2]==new[2]): flag=False if(flag): points.append(new) print(n-len(points)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var points : Sequence := Sequence{} ; var tmp : Sequence := (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; tmp := tmp->sort() ; execute ((tmp) : points) ; for i : Integer.subrange(0, n - 1-1) do ( var new : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; new := new->sort() ; var flag : boolean := true ; for arr : points do ( if (arr->first() = new->first() & arr[1+1] = new[1+1] & arr[2+1] = new[2+1]) then ( flag := false ) else skip) ; if (flag) then ( execute ((new) : points) ) else skip) ; execute (n - (points)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter import string import re c=Counter() N=int(re.split('\s',raw_input())[0]) for i in range(N): l=sorted([int(i)for i in re.split('\s',raw_input())[0 : 3]]) c[frozenset(l)]+=1 print(len(list(c.elements()))-len(list(c))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var c : OclAny := Counter() ; var N : int := ("" + ((re.split('\s', raw_input())->first())))->toInteger() ; for i : Integer.subrange(0, N-1) do ( var l : Sequence := re.split('\s', raw_input()).subrange(0+1, 3)->select(i | true)->collect(i | (("" + ((i)))->toInteger()))->sort() ; c[Set{}+1] := c[Set{}+1] + 1) ; execute (((c.elements()))->size() - ((c))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def unique(seq): seen=[] return[x for x in seq if x not in seen and not seen.append(x)] n=int(input()) point=[] for _ in range(n): p=list(map(int,input().split())) p.sort() point.append(p) point_uni=unique(point) ans=len(point)-len(point_uni) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var point : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; p := p->sort() ; execute ((p) : point)) ; var point_uni : OclAny := unique(point) ; var ans : double := (point)->size() - (point_uni)->size() ; execute (ans)->display(); operation unique(seq : OclAny) : OclAny pre: true post: true activity: var seen : Sequence := Sequence{} ; return seq->select(x | (seen)->excludes(x) & not(seen.append(x)))->collect(x | (x)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=[] for i in range(n): p.append([int(num)for num in input().split()]) flag=[] for i in range(n): flag.append(False) count=0 for i in range(n): p[i].sort() for i in range(n): if flag[i]: continue flag[i]=True for j in range(i+1,n): if flag[j]: continue if(p[i][0]==p[j][0])&(p[i][1]==p[j][1])&(p[i][2]==p[j][2]): flag[j]=True count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger()))) : p)) ; var flag : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((false) : flag)) ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ((expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name sort) (arguments ( ))))) ; for i : Integer.subrange(0, n-1) do ( if flag[i+1] then ( continue ) else skip ; flag[i+1] := true ; for j : Integer.subrange(i + 1, n-1) do ( if flag[j+1] then ( continue ) else skip ; if MathLib.bitwiseAnd(MathLib.bitwiseAnd((p[i+1]->first() = p[j+1]->first()), (p[i+1][1+1] = p[j+1][1+1])), (p[i+1][2+1] = p[j+1][2+1])) then ( flag[j+1] := true ; count := count + 1 ) else skip)) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout,setrecursionlimit from math import gcd,floor,sqrt,log from collections import defaultdict as dd from bisect import bisect_left as bl,bisect_right as br inp=lambda : int(input()) strng=lambda : input().strip() jn=lambda x,l : x.join(map(str,l)) strl=lambda : list(input().strip()) mul=lambda : map(int,input().strip().split()) mulf=lambda : map(float,input().strip().split()) seq=lambda : list(map(int,input().strip().split())) ceil=lambda x : int(x)if(x==int(x))else int(x)+1 ceildiv=lambda x,d : x//d if(x % d==0)else x//d+1 flush=lambda : stdout.flush() stdstr=lambda : stdin.readline() stdint=lambda : int(stdin.readline()) stdpr=lambda x : stdout.write(str(x)) mod=1000000007 for t in range(inp()): n,m=mul() counter=[0]*m for _ in range((2*n)-1): inn=stdstr() for i in range(m): counter[i]^=ord(inn[i]) for c in counter : stdpr(chr(c)) stdpr("\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var strng : Function := lambda $$ : OclAny in (input()->trim()) ; var jn : Function := lambda x : OclAny, l : OclAny in (StringLib.sumStringsWithSeparator(((l)->collect( _x | (OclType["String"])->apply(_x) )), x)) ; var strl : Function := lambda $$ : OclAny in ((input()->trim())) ; var mul : Function := lambda $$ : OclAny in ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mulf : Function := lambda $$ : OclAny in ((input()->trim().split())->collect( _x | (OclType["double"])->apply(_x) )) ; var seq : Function := lambda $$ : OclAny in (((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ceil : Function := lambda x : OclAny in (if (x = ("" + ((x)))->toInteger()) then ("" + ((x)))->toInteger() else ("" + ((x)))->toInteger() + 1 endif) ; var ceildiv : Function := lambda x : OclAny, d : OclAny in (if (x mod d = 0) then x div d else x div d + 1 endif) ; var flush : Function := lambda $$ : OclAny in (stdout.flush()) ; var stdstr : Function := lambda $$ : OclAny in (stdin.readLine()) ; var stdint : Function := lambda $$ : OclAny in (("" + ((stdin.readLine())))->toInteger()) ; var stdpr : Function := lambda x : OclAny in (stdout.write(("" + ((x))))) ; var mod : int := 1000000007 ; for t : Integer.subrange(0, inp->apply()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := mul->apply() ; var counter : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; for _anon : Integer.subrange(0, (2 * n) - 1-1) do ( var inn : OclAny := stdstr->apply() ; for i : Integer.subrange(0, m-1) do ( counter[i+1] := counter[i+1] xor (inn[i+1])->char2byte())) ; for c : counter do ( stdpr((c)->byte2char())) ; stdpr("\n")); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout def get_ints(): return map(int,stdin.readline().split()) def PRINT(s): stdout.write(s+'\n') for t in range(int(stdin.readline())): n,m=get_ints() SUM=[0]*m for i in range(n): s=stdin.readline()[:-1] for j in range(m): SUM[j]+=ord(s[j]) for i in range(n-1): s=stdin.readline()[:-1] for j in range(m): SUM[j]-=ord(s[j]) PRINT(''.join([chr(i)for i in SUM])) stdout.flush() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; for t : Integer.subrange(0, ("" + ((stdin.readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := get_ints() ; var SUM : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; for i : Integer.subrange(0, n-1) do ( s := stdin.readLine()->front() ; for j : Integer.subrange(0, m-1) do ( SUM[j+1] := SUM[j+1] + (s[j+1])->char2byte())) ; for i : Integer.subrange(0, n - 1-1) do ( s := stdin.readLine()->front() ; for j : Integer.subrange(0, m-1) do ( SUM[j+1] := SUM[j+1] - (s[j+1])->char2byte())) ; PRINT(StringLib.sumStringsWithSeparator((SUM->select(i | true)->collect(i | ((i)->byte2char()))), '')) ; stdout.flush()); operation get_ints() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation PRINT(s : OclAny) pre: true post: true activity: stdout.write(s + ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import* q,*n=map(int,open(0)) can=[] for i in range(1,10**5+1): p=[] for j in range(1,int(i**.5)+1): if i % j<1 : p+=[j,i//j] *p,e=sorted(p) for j in range(len(p)-1): p[j+1]*=p[j] if p[-1]>=e*2 : can+=i, for i in n : print(bisect(can,i)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var q : OclAny := null; var n : OclAny := null; Sequence{q,n} := (OclFile.newOclFile_Write(OclFile.newOclFile(0)))->collect( _x | (OclType["int"])->apply(_x) ) ; var can : Sequence := Sequence{} ; for i : Integer.subrange(1, (10)->pow(5) + 1-1) do ( var p : Sequence := Sequence{} ; for j : Integer.subrange(1, ("" + (((i)->pow(.5))))->toInteger() + 1-1) do ( if i mod j < 1 then ( p := p + Sequence{j}->union(Sequence{ i div j }) ) else skip)) ; var p : OclAny := null; var e : OclAny := null; Sequence{p,e} := p->sort(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for case in range(1,T+1): N,L=(int(i)for i in input().split()) a=sorted(int(i,2)for i in input().split()) b=sorted(int(i,2)for i in input().split()) ans=L+1 for i in b : if sorted(a[0]^ i ^ j for j in a)==b : ans=min(ans,bin(a[0]^ i).count('1')) if ans==L+1 : ans='NOT POSSIBLE' print("Case #{}:{}".format(case,ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for case : Integer.subrange(1, T + 1-1) do ( var N : OclAny := null; var L : OclAny := null; Sequence{N,L} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var a : Sequence := (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))->sort() ; var b : Sequence := (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))->sort() ; var ans : OclAny := L + 1 ; for i : b do ( if (argument (test (logical_test (comparison (expr (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) ^ (expr (atom (name i)))) ^ (expr (atom (name j))))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name a)))))))->sort() = b then ( ans := Set{ans, bin(MathLib.bitwiseXor(a->first(), i))->count('1')}->min() ) else skip) ; if ans = L + 1 then ( ans := 'NOT POSSIBLE' ) else skip ; execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{case, ans}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout def get_ints(): return map(int,stdin.readline().split()) def PRINT(s): stdout.write(s+'\n') for t in range(int(stdin.readline())): n,m=get_ints() SUM=[0]*m for i in range(n): s=stdin.readline()[:-1] for j in range(m): SUM[j]^=ord(s[j]) for i in range(n-1): s=stdin.readline()[:-1] for j in range(m): SUM[j]^=ord(s[j]) PRINT(''.join([chr(i)for i in SUM])) stdout.flush() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; for t : Integer.subrange(0, ("" + ((stdin.readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := get_ints() ; var SUM : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; for i : Integer.subrange(0, n-1) do ( s := stdin.readLine()->front() ; for j : Integer.subrange(0, m-1) do ( SUM[j+1] := SUM[j+1] xor (s[j+1])->char2byte())) ; for i : Integer.subrange(0, n - 1-1) do ( s := stdin.readLine()->front() ; for j : Integer.subrange(0, m-1) do ( SUM[j+1] := SUM[j+1] xor (s[j+1])->char2byte())) ; PRINT(StringLib.sumStringsWithSeparator((SUM->select(i | true)->collect(i | ((i)->byte2char()))), '')) ; stdout.flush()); operation get_ints() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation PRINT(s : OclAny) pre: true post: true activity: stdout.write(s + ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout inp=lambda : int(input()) strng=lambda : input().strip() jn=lambda x,l : x.join(map(str,l)) strl=lambda : list(input().strip()) mul=lambda : map(int,input().strip().split()) mulf=lambda : map(float,input().strip().split()) seq=lambda : list(map(int,input().strip().split())) ceil=lambda x : int(x)if(x==int(x))else int(x)+1 ceildiv=lambda x,d : x//d if(x % d==0)else x//d+1 flush=lambda : stdout.flush() stdstr=lambda : stdin.readline() stdint=lambda : int(stdin.readline()) stdpr=lambda x : stdout.write(str(x)) mod=1000000007 for t in range(inp()): n,m=mul() counter=[0]*m for _ in range((2*n)-1): inn=stdstr() for i in range(m): counter[i]^=ord(inn[i]) for c in counter : stdpr(chr(c)) stdpr("\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var strng : Function := lambda $$ : OclAny in (input()->trim()) ; var jn : Function := lambda x : OclAny, l : OclAny in (StringLib.sumStringsWithSeparator(((l)->collect( _x | (OclType["String"])->apply(_x) )), x)) ; var strl : Function := lambda $$ : OclAny in ((input()->trim())) ; var mul : Function := lambda $$ : OclAny in ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mulf : Function := lambda $$ : OclAny in ((input()->trim().split())->collect( _x | (OclType["double"])->apply(_x) )) ; var seq : Function := lambda $$ : OclAny in (((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ceil : Function := lambda x : OclAny in (if (x = ("" + ((x)))->toInteger()) then ("" + ((x)))->toInteger() else ("" + ((x)))->toInteger() + 1 endif) ; var ceildiv : Function := lambda x : OclAny, d : OclAny in (if (x mod d = 0) then x div d else x div d + 1 endif) ; var flush : Function := lambda $$ : OclAny in (stdout.flush()) ; var stdstr : Function := lambda $$ : OclAny in (stdin.readLine()) ; var stdint : Function := lambda $$ : OclAny in (("" + ((stdin.readLine())))->toInteger()) ; var stdpr : Function := lambda x : OclAny in (stdout.write(("" + ((x))))) ; var mod : int := 1000000007 ; for t : Integer.subrange(0, inp->apply()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := mul->apply() ; var counter : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; for _anon : Integer.subrange(0, (2 * n) - 1-1) do ( var inn : OclAny := stdstr->apply() ; for i : Integer.subrange(0, m-1) do ( counter[i+1] := counter[i+1] xor (inn[i+1])->char2byte())) ; for c : counter do ( stdpr((c)->byte2char())) ; stdpr("\n")); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSquares(m,n): if(ndisplay() ) else skip; operation countSquares(m : OclAny, n : OclAny) : OclAny pre: true post: true activity: if ((n->compareTo(m)) < 0) then ( var temp : OclAny := m ; m := n ; n := temp ) else skip ; return ((m * (m + 1) * (2 * m + 1) / 6 + (n - m) * m * (m + 1) / 2)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def logicOfSequence(N): if(N % 2==0): N=N*N else : N=N*N*N return N N=6 print(logicOfSequence(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 6 ; execute (logicOfSequence(N))->display(); operation logicOfSequence(N : OclAny) : OclAny pre: true post: true activity: if (N mod 2 = 0) then ( N := N * N ) else ( N := N * N * N ) ; return N; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import floor def check_char(st,ch): l=len(st) for i in range(l): if(st[i]==ch): return True return False def find_avg(st): sm=0 l=len(st) for i in range(l): ch=st[i] sm=sm+ord(ch) avg=int(floor(sm/l)) return(chr(avg)) if __name__=='__main__' : st="ag23sdfa" ch=find_avg(st) print(ch) if(check_char(st,ch)==True): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( st := "ag23sdfa" ; ch := find_avg(st) ; execute (ch)->display() ; if (check_char(st, ch) = true) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation check_char(st : OclAny, ch : OclAny) : OclAny pre: true post: true activity: var l : int := (st)->size() ; for i : Integer.subrange(0, l-1) do ( if (st[i+1] = ch) then ( return true ) else skip) ; return false; operation find_avg(st : OclAny) : OclAny pre: true post: true activity: var sm : int := 0 ; l := (st)->size() ; for i : Integer.subrange(0, l-1) do ( ch := st[i+1] ; sm := sm + (ch)->char2byte()) ; var avg : int := ("" + ((floor(sm / l))))->toInteger() ; return ((avg)->byte2char()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil,sqrt MAX=100000 divisors=[0]*MAX def generateDivisors(n): for i in range(1,ceil(sqrt(n))+1): if(n % i==0): if(n//i==i): divisors[i]+=1 else : divisors[i]+=1 divisors[n//i]+=1 def findMaxMultiples(arr,n): ans=0 for i in range(n): ans=max(divisors[arr[i]],ans) generateDivisors(arr[i]) return ans arr=[8,1,28,4,2,6,7] n=len(arr) print(findMaxMultiples(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MAX : int := 100000 ; var divisors : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX) ; skip ; skip ; arr := Sequence{8}->union(Sequence{1}->union(Sequence{28}->union(Sequence{4}->union(Sequence{2}->union(Sequence{6}->union(Sequence{ 7 })))))) ; n := (arr)->size() ; execute (findMaxMultiples(arr, n))->display(); operation generateDivisors(n : OclAny) pre: true post: true activity: for i : Integer.subrange(1, ceil(sqrt(n)) + 1-1) do ( if (n mod i = 0) then ( if (n div i = i) then ( divisors[i+1] := divisors[i+1] + 1 ) else ( divisors[i+1] := divisors[i+1] + 1 ; divisors[n div i+1] := divisors[n div i+1] + 1 ) ) else skip); operation findMaxMultiples(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( ans := Set{divisors[arr[i+1]+1], ans}->max() ; generateDivisors(arr[i+1])) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def maxProfit(n,a,b,x,y): res=x*(n//a); res+=y*(n//b); res-=min(x,y)*(n//((a*b)//gcd(a,b))); return res ; if __name__=="__main__" : n=6 ; a=6 ; b=2 ; x=8 ; y=2 ; print(maxProfit(n,a,b,x,y)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 6; a := 6; b := 2; x := 8; y := 2; ; execute (maxProfit(n, a, b, x, y))->display(); ) else skip; operation maxProfit(n : OclAny, a : OclAny, b : OclAny, x : OclAny, y : OclAny) pre: true post: true activity: var res : double := x * (n div a); ; res := res + y * (n div b); ; res := res - Set{x, y}->min() * (n div ((a * b) div gcd(a, b))); ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Diffs(a,k): out,inc,dec=[],[0]*len(a),[0]*len(a) inc_sum,dec_sum=0,0 for i in range(0,len(a)): j=i-1 while(j>=0 and j>i-k and a[j+1]>a[j]): inc[j]+=1 inc_sum+=1 j-=1 j=i-1 while(j>=0 and j>i-k and a[j+1]=k-1 : if i>=k : inc_sum-=inc[i-k] dec_sum-=dec[i-k] out.append(inc_sum-dec_sum) return out if __name__=="__main__" : out=Diffs([10,20,30,15,15],3) for n in out : print(n,end=",") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var out : OclAny := Diffs(Sequence{10}->union(Sequence{20}->union(Sequence{30}->union(Sequence{15}->union(Sequence{ 15 })))), 3) ; for n : out do ( execute (n)->display()) ) else skip; operation Diffs(a : OclAny, k : OclAny) : OclAny pre: true post: true activity: var out : OclAny := null; var inc : OclAny := null; var dec : OclAny := null; Sequence{out,inc,dec} := Sequence{Sequence{},MatrixLib.elementwiseMult(Sequence{ 0 }, (a)->size()),MatrixLib.elementwiseMult(Sequence{ 0 }, (a)->size())} ; var inc_sum : OclAny := null; var dec_sum : OclAny := null; Sequence{inc_sum,dec_sum} := Sequence{0,0} ; for i : Integer.subrange(0, (a)->size()-1) do ( var j : double := i - 1 ; while (j >= 0 & (j->compareTo(i - k)) > 0 & (a[j + 1+1]->compareTo(a[j+1])) > 0) do ( inc[j+1] := inc[j+1] + 1 ; inc_sum := inc_sum + 1 ; j := j - 1) ; j := i - 1 ; while (j >= 0 & (j->compareTo(i - k)) > 0 & (a[j + 1+1]->compareTo(a[j+1])) < 0) do ( dec[j+1] := dec[j+1] + 1 ; dec_sum := dec_sum + 1 ; j := j - 1) ; if (i->compareTo(k - 1)) >= 0 then ( if (i->compareTo(k)) >= 0 then ( inc_sum := inc_sum - inc[i - k+1] ; dec_sum := dec_sum - dec[i - k+1] ) else skip ; execute ((inc_sum - dec_sum) : out) ) else skip) ; return out; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=list(map(int,input().split())) A=[int(input())for _ in range(M)] MOD=1000000007 if M==0 : B=[] B.append(N+1) elif M==1 : B=[] B.append(A[0]) B.append(N-A[0]) else : B=[A[0]] for i in range(M-1): B.append(A[i+1]-A[i]-1) B.append(N-A[M-1]) ans=1 if 0 in B : ans=0 else : F=[1,1] for n in B : while len(F)collect( _x | (OclType["int"])->apply(_x) )) ; var A : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var MOD : int := 1000000007 ; if M = 0 then ( var B : Sequence := Sequence{} ; execute ((N + 1) : B) ) else (if M = 1 then ( B := Sequence{} ; execute ((A->first()) : B) ; execute ((N - A->first()) : B) ) else ( B := Sequence{ A->first() } ; for i : Integer.subrange(0, M - 1-1) do ( execute ((A[i + 1+1] - A[i+1] - 1) : B)) ; execute ((N - A[M - 1+1]) : B) ) ) ; var ans : int := 1 ; if (B)->includes(0) then ( ans := 0 ) else ( var F : Sequence := Sequence{1}->union(Sequence{ 1 }) ; for n : B do ( while ((F)->size()->compareTo(n)) < 0 do ( execute ((F->last() + F->front()->last()) : F)) ; var now : OclAny := F[n - 1+1] ; ans := ans * now mod MOD) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) mod=10**9+7 dp=[0]*(N+1) dp[0]=1 for i in range(1,M+1): a=int(input()) dp[a]=-1 for i in range(0,N-1): if dp[i]==-1 : continue if dp[i+1]!=-1 : dp[i+1]+=dp[i]% mod dp[i+1]%=mod if dp[i+2]!=-1 : dp[i+2]+=dp[i]% mod dp[i+2]%=mod if dp[-2]!=-1 : dp[-1]+=dp[-2]% mod dp[-1]%=mod print(dp[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mod : double := (10)->pow(9) + 7 ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; dp->first() := 1 ; for i : Integer.subrange(1, M + 1-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; dp[a+1] := -1) ; for i : Integer.subrange(0, N - 1-1) do ( if dp[i+1] = -1 then ( continue ) else skip ; if dp[i + 1+1] /= -1 then ( dp[i + 1+1] := dp[i + 1+1] + dp[i+1] mod mod ; dp[i + 1+1] := dp[i + 1+1] mod mod ) else skip ; if dp[i + 2+1] /= -1 then ( dp[i + 2+1] := dp[i + 2+1] + dp[i+1] mod mod ; dp[i + 2+1] := dp[i + 2+1] mod mod ) else skip) ; if dp->front()->last() /= -1 then ( dp->last() := dp->last() + dp->front()->last() mod mod ; dp->last() := dp->last() mod mod ) else skip ; execute (dp->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input(); a=set([chr(i+65)for i in range(26)]); ans=0 if len(s)<26 : print(-1) else : ind=0 for x in range(len(s)-26+1): k=s[x : 26+x]; b=set(k) if k.count('?')==0 and len(b)==26 or len(b)-1+k.count('?')==26 : a-=b ; ans=1 ; ind=x ; break if ans==0 : print(-1) else : b=list(a); k='' for i in range(ind): if s[i]=='?' : k+='A' else : k+=s[i] for i in range(ind,ind+26): if s[i]=='?' : k+=b[0]; b.remove(b[0]) else : k+=s[i] for i in range(ind+26,len(s)): if s[i]=='?' : k+='A' else : k+=s[i] print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine(); var a : Set := Set{}->union((Integer.subrange(0, 26-1)->select(i | true)->collect(i | ((i + 65)->byte2char())))); var ans : int := 0 ; if (s)->size() < 26 then ( execute (-1)->display() ) else ( var ind : int := 0 ; for x : Integer.subrange(0, (s)->size() - 26 + 1-1) do ( var k : OclAny := s.subrange(x+1, 26 + x); var b : Set := Set{}->union((k)) ; if k->count('?') = 0 & (b)->size() = 26 or (b)->size() - 1 + k->count('?') = 26 then ( a := a - b; ans := 1; ind := x; break ) else skip) ; if ans = 0 then ( execute (-1)->display() ) else ( b := (a); k := '' ; for i : Integer.subrange(0, ind-1) do ( if s[i+1] = '?' then ( k := k + 'A' ) else ( k := k + s[i+1] )) ; for i : Integer.subrange(ind, ind + 26-1) do ( if s[i+1] = '?' then ( k := k + b->first(); execute ((b->first()) /: b) ) else ( k := k + s[i+1] )) ; for i : Integer.subrange(ind + 26, (s)->size()-1) do ( if s[i+1] = '?' then ( k := k + 'A' ) else ( k := k + s[i+1] )) ; execute (k)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- fin=open('A-large.in','r') fout=open('out.txt','w') t=int(fin.readline()) for casecount in range(1,t+1): n,l=map(int,fin.readline().split()) outlet=[list(x)for x in fin.readline().split()] device=[list(x)for x in fin.readline().split()] device.sort() smallest=41 for func in range(0,n): switch=[] for i in range(0,l): if outlet[0][i]!=device[func][i]: switch.append(i) output=[] for x in outlet : x1=x.copy() for y in switch : if x1[y]=='0' : x1[y]='1' else : x1[y]='0' output.append(x1) output.sort() if smallest>len(switch)and output==device : smallest=len(switch) fout.write('Case #%d: ' % casecount) if smallest==41 : fout.write('NOT POSSIBLE\n') else : fout.write('%d\n' % smallest) fin.close() fout.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var fin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('A-large.in')) ; var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('out.txt')) ; var t : int := ("" + ((fin.readLine())))->toInteger() ; for casecount : Integer.subrange(1, t + 1-1) do ( var n : OclAny := null; var l : OclAny := null; Sequence{n,l} := (fin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var outlet : Sequence := fin.readLine().split()->select(x | true)->collect(x | ((x))) ; var device : Sequence := fin.readLine().split()->select(x | true)->collect(x | ((x))) ; device := device->sort() ; var smallest : int := 41 ; for func : Integer.subrange(0, n-1) do ( var switch : Sequence := Sequence{} ; for i : Integer.subrange(0, l-1) do ( if outlet->first()[i+1] /= device[func+1][i+1] then ( execute ((i) : switch) ) else skip) ; var output : Sequence := Sequence{} ; for x : outlet do ( var x1 : OclAny := x->copy() ; for y : switch do ( if x1[y+1] = '0' then ( x1[y+1] := '1' ) else ( x1[y+1] := '0' )) ; execute ((x1) : output)) ; output := output->sort() ; if (smallest->compareTo((switch)->size())) > 0 & output = device then ( smallest := (switch)->size() ) else skip) ; fout.write(StringLib.format('Case #%d: ',casecount)) ; if smallest = 41 then ( fout.write('NOT POSSIBLE ') ) else ( fout.write(StringLib.format('%d ',smallest)) )) ; fin.closeFile() ; fout.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def eratosthenes(N): from collections import deque work=[True]*(N+1) work[0]=False work[1]=False ret=[] for i in range(N+1): if work[i]: ret.append(i) for j in range(2*i,N+1,i): work[j]=False return ret from itertools import accumulate def main(): ANS=[1]*100001 ANS[0]=0 ANS[1]=0 Primes=eratosthenes(100000) for p in Primes : ANS[p]=0 if p**2<=100000 : ANS[p**2]=0 if p**3<=100000 : ANS[p**3]=0 for p in Primes : for q in Primes : if p*q<=100000 : ANS[p*q]=0 else : break accANS=list(accumulate(ANS)) Q=int(input()) for _ in range(Q): print(accANS[int(input())]) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation eratosthenes(N : OclAny) : OclAny pre: true post: true activity: skip ; var work : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (N + 1)) ; work->first() := false ; work[1+1] := false ; var ret : Sequence := Sequence{} ; for i : Integer.subrange(0, N + 1-1) do ( if work[i+1] then ( execute ((i) : ret) ; for j : Integer.subrange(2 * i, N + 1-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ( work[j+1] := false) ) else skip) ; return ret; operation main() pre: true post: true activity: var ANS : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, 100001) ; ANS->first() := 0 ; ANS[1+1] := 0 ; var Primes : OclAny := eratosthenes(100000) ; for p : Primes do ( ANS[p+1] := 0 ; if (p)->pow(2) <= 100000 then ( ANS[(p)->pow(2)+1] := 0 ) else skip ; if (p)->pow(3) <= 100000 then ( ANS[(p)->pow(3)+1] := 0 ) else skip) ; for p : Primes do ( for q : Primes do ( if p * q <= 100000 then ( ANS[p * q+1] := 0 ) else ( break ))) ; var accANS : Sequence := (accumulate(ANS)) ; var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, Q-1) do ( execute (accANS[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Fib(n): a,b=0,1 if n==1 : return a elif n==2 : return b else : for i in range(n-2): a,b=b,a+b return b N,M=map(int,input().split()) if M==0 : P=Fib(N+2) print(P % 1000000007) else : S=[] for _ in range(M): S.append(int(input())) S.append(-1) S.append(N+1) S.sort() P=1 for i in range(M+1): P*=Fib(S[i+1]-S[i]) print(P % 1000000007) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if M = 0 then ( var P : OclAny := Fib(N + 2) ; execute (P mod 1000000007)->display() ) else ( var S : Sequence := Sequence{} ; for _anon : Integer.subrange(0, M-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : S)) ; execute ((-1) : S) ; execute ((N + 1) : S) ; S := S->sort() ; P := 1 ; for i : Integer.subrange(0, M + 1-1) do ( P := P * Fib(S[i + 1+1] - S[i+1])) ; execute (P mod 1000000007)->display() ); operation Fib(n : OclAny) : OclAny pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{0,1} ; if n = 1 then ( return a ) else (if n = 2 then ( return b ) else ( for i : Integer.subrange(0, n - 2-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a + b}) ; return b ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(N,M,A): MOD=10**9+7 A=set(A) if N==1 : return 1 if 1 not in A else 0 dp=[0]*(N+1) dp[0]=1 dp[1]=1 if 1 not in A else 0 for i in range(2,N+1): if i in A : dp[i]=0 else : dp[i]=(dp[i-2]+dp[i-1])% MOD return dp[-1] def main(args): N,M=map(int,input().split()) A=[int(input())for _ in range(M)] ans=solve(N,M,A) print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(N : OclAny, M : OclAny, A : OclAny) : OclAny pre: true post: true activity: var MOD : double := (10)->pow(9) + 7 ; A := Set{}->union((A)) ; if N = 1 then ( return if (A)->excludes(1) then 1 else 0 endif ) else skip ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; dp->first() := 1 ; dp[1+1] := if (A)->excludes(1) then 1 else 0 endif ; for i : Integer.subrange(2, N + 1-1) do ( if (A)->includes(i) then ( dp[i+1] := 0 ) else ( dp[i+1] := (dp[i - 2+1] + dp[i - 1+1]) mod MOD )) ; return dp->last(); operation main(args : OclAny) pre: true post: true activity: Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; A := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var ans : OclAny := solve(N, M, A) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=list(map(int,input().split())) L=set(int(input())for _ in range(m)) dp=[0]*(n+1) mod=10**9+7 dp[0]=1 for i in range(n): if i+1 not in L : dp[i+1]+=dp[i] dp[i+1]%=mod if i+2 not in L and i+2collect( _x | (OclType["int"])->apply(_x) )) ; var L : Set := Set{}->union(((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name m)))))))) )))))))))) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var mod : double := (10)->pow(9) + 7 ; dp->first() := 1 ; for i : Integer.subrange(0, n-1) do ( if (L)->excludes(i + 1) then ( dp[i + 1+1] := dp[i + 1+1] + dp[i+1] ; dp[i + 1+1] := dp[i + 1+1] mod mod ) else skip ; if (L)->excludes(i + 2) & (i + 2->compareTo(n + 1)) < 0 then ( dp[i + 2+1] := dp[i + 2+1] + dp[i+1] ; dp[i + 2+1] := dp[i + 2+1] mod mod ) else skip) ; execute (dp[n+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): n,c=map(int,input().split()) arr=list(map(int,input().split())) mx=0 for i in range(1,n): mx=max(mx,arr[i-1]-arr[i]) if mx-c<=0 : print(0) return print(mx-c) def main(): t=1 for _ in range(t): solution() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; main(); operation solution() pre: true post: true activity: var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mx : int := 0 ; for i : Integer.subrange(1, n-1) do ( mx := Set{mx, arr[i - 1+1] - arr[i+1]}->max()) ; if mx - c <= 0 then ( execute (0)->display() ; return ) else skip ; execute (mx - c)->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (n,c)=map(int,input().split(' ')) prices=list(map(int,input().split(' '))) revenue=0 for i in range(n-1): if prices[i]-prices[i+1]>=revenue : revenue=prices[i]-prices[i+1] profit=revenue-c if profit<0 : print(0) else : print(profit) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{n, c} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var prices : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var revenue : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if (prices[i+1] - prices[i + 1+1]->compareTo(revenue)) >= 0 then ( revenue := prices[i+1] - prices[i + 1+1] ) else skip) ; var profit : double := revenue - c ; if profit < 0 then ( execute (0)->display() ) else ( execute (profit)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=list(map(int,input().split())) l=list(map(int,input().split())) po1=0 po2=1 su=0 while po2su : su=z po1+=1 po2+=1 su=su-y if su<0 : print(0) exit() print(su) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var po1 : int := 0 ; var po2 : int := 1 ; var su : int := 0 ; while (po2->compareTo(x)) < 0 do ( var z : double := l[po1+1] - l[po2+1] ; if (z->compareTo(su)) > 0 then ( su := z ) else skip ; po1 := po1 + 1 ; po2 := po2 + 1) ; su := su - y ; if su < 0 then ( execute (0)->display() ; exit() ) else skip ; execute (su)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=list(map(int,input().split())) r=list(map(int,input().split())) po1=0 po2=1 su=0 while po2su : su=z po1+=1 po2+=1 su=su-y if su<0 : print(0) exit() print(su) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var r : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var po1 : int := 0 ; var po2 : int := 1 ; var su : int := 0 ; while (po2->compareTo(x)) < 0 do ( var z : double := r[po1+1] - r[po2+1] ; if (z->compareTo(su)) > 0 then ( su := z ) else skip ; po1 := po1 + 1 ; po2 := po2 + 1) ; su := su - y ; if su < 0 then ( execute (0)->display() ; exit() ) else skip ; execute (su)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=list(map(int,input().split())) r=list(map(int,input().split())) po1=0 po2=1 su=0 while po2su : su=z po1+=1 po2+=1 su=su-y if su<0 : print(0) exit() print(su) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var r : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var po1 : int := 0 ; var po2 : int := 1 ; var su : int := 0 ; while (po2->compareTo(x)) < 0 do ( var z : double := r[po1+1] - r[po2+1] ; if (z->compareTo(su)) > 0 then ( su := z ) else skip ; po1 := po1 + 1 ; po2 := po2 + 1) ; su := su - y ; if su < 0 then ( execute (0)->display() ; exit() ) else skip ; execute (su)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) print('{:.0f}'.format(math.floor(n/3))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (StringLib.interpolateStrings('{:.0f}', Sequence{(n / 3)->floor()}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys fin=open(sys.argv[1],"r") fout=open("p1.out","w") T=int(fin.readline()) def conv(s): return int(s,2) for i in range(T): N,L=map(int,fin.readline().split()) ans=L+1 device=sorted(map(conv,fin.readline().split())) outlet=map(conv,fin.readline().split()) for j in range(len(outlet)): bits=device[0]^ outlet[j] def flip(t): return t ^ bits new_out=sorted(map(flip,outlet)) if new_out==device : ans=min(ans,bin(bits).count("1")) fout.write("Case #"+str(i+1)+": ") if ans==L+1 : fout.write("NOT POSSIBLE\n") else : fout.write(str(ans)+"\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var fin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) ; var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("p1.out")) ; var T : int := ("" + ((fin.readLine())))->toInteger() ; skip ; for i : Integer.subrange(0, T-1) do ( var N : OclAny := null; var L : OclAny := null; Sequence{N,L} := (fin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : OclAny := L + 1 ; var device : Sequence := (fin.readLine().split())->collect( _x | (conv)->apply(_x) )->sort() ; var outlet : Sequence := (fin.readLine().split())->collect( _x | (conv)->apply(_x) ) ; for j : Integer.subrange(0, (outlet)->size()-1) do ( var bits : int := MathLib.bitwiseXor(device->first(), outlet[j+1]) ; skip ; var new_out : Sequence := (outlet)->collect( _x | (flip)->apply(_x) )->sort() ; if new_out = device then ( ans := Set{ans, bin(bits)->count("1")}->min() ) else skip) ; fout.write("Case #" + ("" + ((i + 1))) + ": ") ; if ans = L + 1 then ( fout.write("NOT POSSIBLE\n") ) else ( fout.write(("" + ((ans))) + "\n") )); operation conv(s : OclAny) : OclAny pre: true post: true activity: return ("" + ((s, 2)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(1<<25) read=sys.stdin.readline ra=range enu=enumerate def read_ints(): return list(map(int,read().split())) def read_a_int(): return int(read()) def read_tuple(H): ret=[] for _ in range(H): ret.append(tuple(map(int,read().split()))) return ret def read_col(H): ret=[] for _ in range(H): ret.append(list(map(int,read().split()))) return tuple(map(list,zip(*ret))) def read_matrix(H): ret=[] for _ in range(H): ret.append(list(map(int,read().split()))) return ret MOD=10**9+7 INF=2**31 from collections import defaultdict,Counter,deque from operator import itemgetter from itertools import product,permutations,combinations from bisect import bisect_left,bisect_right N=read_a_int() print(N//3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(1 * (2->pow(25))) ; var read : OclAny := (OclFile["System.in"]).readline ; var ra : OclAny := range ; var enu : OclAny := enumerate ; skip ; skip ; skip ; skip ; skip ; var MOD : double := (10)->pow(9) + 7 ; var INF : double := (2)->pow(31) ; skip ; skip ; skip ; skip ; var N : OclAny := read_a_int() ; execute (N div 3)->display(); operation read_ints() : OclAny pre: true post: true activity: return ((read().split())->collect( _x | (OclType["int"])->apply(_x) )); operation read_a_int() : OclAny pre: true post: true activity: return ("" + ((read())))->toInteger(); operation read_tuple(H : OclAny) : OclAny pre: true post: true activity: var ret : Sequence := Sequence{} ; for _anon : Integer.subrange(0, H-1) do ( execute ((((read().split())->collect( _x | (OclType["int"])->apply(_x) ))) : ret)) ; return ret; operation read_col(H : OclAny) : OclAny pre: true post: true activity: ret := Sequence{} ; for _anon : Integer.subrange(0, H-1) do ( execute ((((read().split())->collect( _x | (OclType["int"])->apply(_x) ))) : ret)) ; return ((Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name ret)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name ret)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name ret)))))))`third->at(_indx)} ))->collect( _x | (OclType["Sequence"])->apply(_x) )); operation read_matrix(H : OclAny) : OclAny pre: true post: true activity: ret := Sequence{} ; for _anon : Integer.subrange(0, H-1) do ( execute ((((read().split())->collect( _x | (OclType["int"])->apply(_x) ))) : ret)) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def get_sieve_of_eratosthenes(n): if not isinstance(n,int): raise TypeError('n is int type.') if n<2 : raise ValueError('n is more than 2') prime=[] limit=math.sqrt(n) data=[i+1 for i in range(1,n)] while True : p=data[0] if limit<=p : return prime+data prime.append(p) data=[e for e in data if e % p!=0] n=int(input()) ma=int(math.sqrt(10**5)) lis=get_sieve_of_eratosthenes(ma) l_b=[False]*(10**5+1) for item1 in lis : for item2 in lis : if item210**5 : break i=0 while(item1*item2*(3+i)<=10**5): l_b[item1*item2*(3+i)]=True i+=1 for item in lis : if item**3<10**5 : l_b[item**3]=False l_count=[0]*(10**5+1) for i in range(1,10**5+1): if l_b[i]: l_count[i]=l_count[i-1]+1 else : l_count[i]=l_count[i-1] for _ in range(n): num=int(input()) print(l_count[num]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ma : int := ("" + ((((10)->pow(5))->sqrt())))->toInteger() ; var lis : OclAny := get_sieve_of_eratosthenes(ma) ; var l_b : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, ((10)->pow(5) + 1)) ; for item1 : lis do ( for item2 : lis do ( if (item2->compareTo(item1)) < 0 then ( continue ) else skip ; if (item1 * item2 * 3->compareTo((10)->pow(5))) > 0 then ( break ) else skip ; var i : int := 0 ; while ((item1 * item2 * (3 + i)->compareTo((10)->pow(5))) <= 0) do ( l_b[item1 * item2 * (3 + i)+1] := true ; i := i + 1))) ; for item : lis do ( if ((item)->pow(3)->compareTo((10)->pow(5))) < 0 then ( l_b[(item)->pow(3)+1] := false ) else skip) ; var l_count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((10)->pow(5) + 1)) ; for i : Integer.subrange(1, (10)->pow(5) + 1-1) do ( if l_b[i+1] then ( l_count[i+1] := l_count[i - 1+1] + 1 ) else ( l_count[i+1] := l_count[i - 1+1] )) ; for _anon : Integer.subrange(0, n-1) do ( var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (l_count[num+1])->display()); operation get_sieve_of_eratosthenes(n : OclAny) : OclAny pre: true post: true activity: if not((OclType["int"]).isInstance(n)) then ( error CastingException.newCastingException('n is int type.') ) else skip ; if n < 2 then ( error IncorrectElementException.newIncorrectElementException('n is more than 2') ) else skip ; var prime : Sequence := Sequence{} ; var limit : double := (n)->sqrt() ; var data : Sequence := Integer.subrange(1, n-1)->select(i | true)->collect(i | (i + 1)) ; while true do ( var p : OclAny := data->first() ; if (limit->compareTo(p)) <= 0 then ( return prime->union(data) ) else skip ; execute ((p) : prime) ; data := data->select(e | e mod p /= 0)->collect(e | (e))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(int(input())//3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (("" + (((OclFile["System.in"]).readLine())))->toInteger() div 3)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=n//3 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := n div 3 ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) print(int(N/3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (("" + ((N / 3)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) ans="APPROVED" for i in range(n): if a[i]% 2==0 : if a[i]% 3==0 or a[i]% 5==0 : continue else : ans="DENIED" break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : String := "APPROVED" ; for i : Integer.subrange(0, n-1) do ( if a[i+1] mod 2 = 0 then ( if a[i+1] mod 3 = 0 or a[i+1] mod 5 = 0 then ( continue ) else ( ans := "DENIED" ; break ) ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() a_list=list(map(int,input().split())) for a in a_list : if a % 2==0 : if a % 3==0 or a % 5==0 : pass else : print('DENIED') exit() print('APPROVED') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var a_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for a : a_list do ( if a mod 2 = 0 then ( if a mod 3 = 0 or a mod 5 = 0 then ( skip ) else ( execute ('DENIED')->display() ; exit() ) ) else skip) ; execute ('APPROVED')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np n=int(input()) a=np.array([int(x)for x in input().split()]) aa=a[a % 2==0] aaa=aa[(aa % 3==0)|(aa % 5==0)] if len(aa)==len(aaa): print("APPROVED") else : print("DENIED") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) ; var aa : OclAny := a->select(a mod 2 = 0) ; var aaa : OclAny := aa[MathLib.bitwiseOr((aa mod 3 = 0), (aa mod 5 = 0))+1] ; if (aa)->size() = (aaa)->size() then ( execute ("APPROVED")->display() ) else ( execute ("DENIED")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,*a=map(int,open(0).read().split()) a=[i for i in a if i % 2==0 and i % 3!=0 and i % 5!=0] print(["APPROVED","DENIED"][len(a)>0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := a->select(i | i mod 2 = 0 & i mod 3 /= 0 & i mod 5 /= 0)->collect(i | (i)) ; execute (Sequence{"APPROVED"}->union(Sequence{ "DENIED" })->select((a)->size() > 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) cnt=0 for i in range(n): if l[i]% 2==0 : if l[i]% 3==0 : cnt+=1 elif l[i]% 5==0 : cnt+=1 else : print("DENIED") quit() print("APPROVED") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( if l[i+1] mod 2 = 0 then ( if l[i+1] mod 3 = 0 then ( cnt := cnt + 1 ) else (if l[i+1] mod 5 = 0 then ( cnt := cnt + 1 ) else ( execute ("DENIED")->display() ; quit() ) ) ) else skip) ; execute ("APPROVED")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reader(f): f=open(f) for line in f : yield line.strip() f.close() def write(f,lst): for i in xrange(len(lst)): lst[i]="Case #%s: %s" %(i+1,lst[i]) f=open(f,'w') f.write('\n'.join(lst)) f.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip; operation reader(f : OclAny) pre: true post: true activity: f := OclFile.newOclFile_Write(OclFile.newOclFile(f)) ; for line : f do ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return line->trim()) ; f.closeFile(); operation write(f : OclAny, lst : OclAny) pre: true post: true activity: for i : xrange((lst)->size()) do ( lst[i+1] := StringLib.format("Case #%s: %s",Sequence{i + 1, lst[i+1]})) ; f := OclFile.newOclFile_Write(OclFile.newOclFile(f)) ; f.write(StringLib.sumStringsWithSeparator((lst), ' ')) ; f.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def totalOperations(st,length): d={} for i in range(length): if st[i]in d : d[st[i]]+=1 else : d[st[i]]=1 valueSet=set() for key in d.keys(): valueSet.add(d[key]) return len(valueSet) st="geeksforgeeks" l=len(st) print(totalOperations(st,l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; st := "geeksforgeeks" ; var l : int := (st)->size() ; execute (totalOperations(st, l))->display(); operation totalOperations(st : OclAny, length : OclAny) : OclAny pre: true post: true activity: var d : OclAny := Set{} ; for i : Integer.subrange(0, length-1) do ( if (d)->includes(st[i+1]) then ( d[st[i+1]+1] := d[st[i+1]+1] + 1 ) else ( d[st[i+1]+1] := 1 )) ; var valueSet : Set := Set{}->union(()) ; for key : d.keys() do ( execute ((d[key+1]) : valueSet)) ; return (valueSet)->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count(s,k): n=len(s) d,count=0,0 for i in range(k): d+=ord(s[i]) if(d % k==0): count+=1 for i in range(k,n): prev=ord(s[i-k]) d-=prev d+=ord(s[i]) if(d % k==0): count+=1 return count s="bcgabc" k=3 ans=count(s,k) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := "bcgabc" ; k := 3 ; var ans : OclAny := count(s, k) ; execute (ans)->display(); operation count(s : OclAny, k : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; var d : OclAny := null; var count : OclAny := null; Sequence{d,count} := Sequence{0,0} ; for i : Integer.subrange(0, k-1) do ( d := d + (s[i+1])->char2byte() ; if (d mod k = 0) then ( count := count + 1 ; for i : Integer.subrange(k, n-1) do ( var prev : int := (s[i - k+1])->char2byte() ; d := d - prev ; d := d + (s[i+1])->char2byte() ; if (d mod k = 0) then ( count := count + 1 ; return count ) else skip) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math N=10**5+5 lst=[0]*(N) for i in range(10,N-3): count=0 for j in range(1,int(math.sqrt(i))+1): if i % j==0 : count+=1 if count>=3 : lst[i]=lst[i-1]+1 if lst[i]==0 : lst[i]=lst[i-1] Q=int(input()) for _ in range(Q): print(lst[int(input())]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : double := (10)->pow(5) + 5 ; var lst : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N)) ; for i : Integer.subrange(10, N - 3-1) do ( var count : int := 0 ; for j : Integer.subrange(1, ("" + (((i)->sqrt())))->toInteger() + 1-1) do ( if i mod j = 0 then ( count := count + 1 ) else skip ; if count >= 3 then ( lst[i+1] := lst[i - 1+1] + 1 ) else skip) ; if lst[i+1] = 0 then ( lst[i+1] := lst[i - 1+1] ) else skip) ; var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, Q-1) do ( execute (lst[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Xor_Sum(arr,n): sum=0 index,left_xor=0,0 right_xor=0 for i in range(n): left_xor=left_xor ^ arr[i] right_xor=0 for j in range(i+1,n): right_xor=right_xor ^ arr[j] if(left_xor+right_xor>sum): sum=left_xor+right_xor index=i return index+1 arr=[1,4,6,3,8,13,34,2,21,10] n=len(arr) print(Xor_Sum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{4}->union(Sequence{6}->union(Sequence{3}->union(Sequence{8}->union(Sequence{13}->union(Sequence{34}->union(Sequence{2}->union(Sequence{21}->union(Sequence{ 10 }))))))))) ; n := (arr)->size() ; execute (Xor_Sum(arr, n))->display(); operation Xor_Sum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; var index : OclAny := null; var left_xor : OclAny := null; Sequence{index,left_xor} := Sequence{0,0} ; var right_xor : int := 0 ; for i : Integer.subrange(0, n-1) do ( var left_xor : int := MathLib.bitwiseXor(left_xor, arr[i+1]) ; right_xor := 0 ; for j : Integer.subrange(i + 1, n-1) do ( right_xor := MathLib.bitwiseXor(right_xor, arr[j+1])) ; if ((left_xor + right_xor->compareTo(sum)) > 0) then ( sum := left_xor + right_xor ; var index : OclAny := i ) else skip) ; return index + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getMaxMedian(arr,n,k): size=n+k arr.sort(reverse=False) if(size % 2==0): median=(arr[int(size/2)-1]+arr[int(size/2)])/2 return median median=arr[int(size/2)] return median if __name__=='__main__' : arr=[3,2,3,4,2] n=len(arr) k=2 print(getMaxMedian(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{3}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 2 })))) ; n := (arr)->size() ; k := 2 ; execute (getMaxMedian(arr, n, k))->display() ) else skip; operation getMaxMedian(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var size : OclAny := n + k ; arr := arr->sort() ; if (size mod 2 = 0) then ( var median : double := (arr[("" + ((size / 2)))->toInteger() - 1+1] + arr[("" + ((size / 2)))->toInteger()+1]) / 2 ; return median ) else skip ; median := arr[("" + ((size / 2)))->toInteger()+1] ; return median; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=input() if b.count("A")>b.count("D"): print("Anton") elif b.count("A")toInteger() ; var b : String := (OclFile["System.in"]).readLine() ; if (b->count("A")->compareTo(b->count("D"))) > 0 then ( execute ("Anton")->display() ) else (if (b->count("A")->compareTo(b->count("D"))) < 0 then ( execute ("Danik")->display() ) else ( execute ("Friendship")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) s=input() acount=0 dcount=0 for c in s : if c=='A' : acount+=1 else : dcount+=1 if acount>dcount : print("Anton") elif acounttoInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var acount : int := 0 ; var dcount : int := 0 ; for c : s->characters() do ( if c = 'A' then ( acount := acount + 1 ) else ( dcount := dcount + 1 )) ; if (acount->compareTo(dcount)) > 0 then ( execute ("Anton")->display() ) else (if (acount->compareTo(dcount)) < 0 then ( execute ("Danik")->display() ) else ( execute ("Friendship")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=int(input()) Y=input()[: s] count2=0 counts=0 for j in Y : if j=="A" : count2=count2+1 if j=="D" : counts=counts+1 if(count2>counts): print("Anton") elif(counts>count2): print("Danik") else : print("Friendship") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var Y : OclAny := input().subrange(1,s) ; var count2 : int := 0 ; var counts : int := 0 ; for j : Y do ( if j = "A" then ( count2 := count2 + 1 ) else skip ; if j = "D" then ( counts := counts + 1 ) else skip) ; if ((count2->compareTo(counts)) > 0) then ( execute ("Anton")->display() ) else (if ((counts->compareTo(count2)) > 0) then ( execute ("Danik")->display() ) else ( execute ("Friendship")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=input() x,y=b.count('A'),b.count('D') if x>y : print("Anton") elif xtoInteger() ; var b : String := (OclFile["System.in"]).readLine() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{b->count('A'),b->count('D')} ; if (x->compareTo(y)) > 0 then ( execute ("Anton")->display() ) else (if (x->compareTo(y)) < 0 then ( execute ("Danik")->display() ) else ( execute ("Friendship")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=input() x,y=b.count('A'),b.count('D') if x>y : print("Anton") elif xtoInteger() ; var b : String := (OclFile["System.in"]).readLine() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{b->count('A'),b->count('D')} ; if (x->compareTo(y)) > 0 then ( execute ("Anton")->display() ) else (if (x->compareTo(y)) < 0 then ( execute ("Danik")->display() ) else ( execute ("Friendship")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def flips(a,b): result='' for i in range(len(a)): result+='0' if a[i]==b[i]else '1' return result def flop(a,b): result='' for i in range(len(a)): result+=a[i]if b[i]=='0' else '1' if a[i]=='0' else '0' return result for t in range(int(input())): N,L=map(int,input().split()) start=input().split() goal=input().split() minimum=1000 first=start[0] for g in goal : flip=flips(g,first) popcount=flip.count('1') if popcounttoInteger()-1) do ( var N : OclAny := null; var L : OclAny := null; Sequence{N,L} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var start : OclAny := input().split() ; var goal : OclAny := input().split() ; var minimum : int := 1000 ; var first : OclAny := start->first() ; for g : goal do ( var flip : OclAny := flips(g, first) ; var popcount : int := flip->count('1') ; if (popcount->compareTo(minimum)) < 0 then ( var outlets : Set := Set{}->union((start)) ; var devices : Set := Set{}->union(((goal)->collect( _x | (lambda a : OclAny in (flop(a, flip)))->apply(_x) ))) ; if outlets = devices then ( minimum := popcount ) else skip ) else skip) ; result := 0 ; execute (StringLib.interpolateStrings('Case #{}:{}', Sequence{t + 1, if minimum /= 1000 then minimum else 'NOT POSSIBLE' endif}))->display()); operation flips(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var result : String := '' ; for i : Integer.subrange(0, (a)->size()-1) do ( result := result + if a[i+1] = b[i+1] then '0' else '1' endif) ; return result; operation flop(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: result := '' ; for i : Integer.subrange(0, (a)->size()-1) do ( result := result + if b[i+1] = '0' then a[i+1] else if a[i+1] = '0' then '1' else '0' endif endif) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,c=map(int,input().split()) p=list(map(int,input().split())) t=list(map(int,input().split())) score=0 sum=0 for i in range(n): sum+=t[i] score+=max(0,(p[i]-(sum*c))) summ=0 scoree=0 for i in range(n-1,-1,-1): summ+=t[i] scoree+=max(0,(p[i]-(summ*c))) if(scoree>score): print("Radewoosh") elif(score==scoree): print("Tie") else : print("Limak") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var score : int := 0 ; var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + t[i+1] ; score := score + Set{0, (p[i+1] - (sum * c))}->max()) ; var summ : int := 0 ; var scoree : int := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( summ := summ + t[i+1] ; scoree := scoree + Set{0, (p[i+1] - (summ * c))}->max()) ; if ((scoree->compareTo(score)) > 0) then ( execute ("Radewoosh")->display() ) else (if (score = scoree) then ( execute ("Tie")->display() ) else ( execute ("Limak")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,c=map(int,input().split()) p=list(map(int,input().split())) t=list(map(int,input().split())) Tl=0 Tr=0 Sl=0 Sr=0 for i in range(n): Tl+=t[i] Tr+=t[-i-1] Sl+=max(0,p[i]-(c*Tl)) Sr+=max(0,p[-i-1]-(c*Tr)) if Sl>Sr : print("Limak") elif Sr>Sl : print("Radewoosh") else : print("Tie") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var Tl : int := 0 ; var Tr : int := 0 ; var Sl : int := 0 ; var Sr : int := 0 ; for i : Integer.subrange(0, n-1) do ( Tl := Tl + t[i+1] ; Tr := Tr + t->reverse()->at(-(-i - 1)) ; Sl := Sl + Set{0, p[i+1] - (c * Tl)}->max() ; Sr := Sr + Set{0, p->reverse()->at(-(-i - 1)) - (c * Tr)}->max()) ; if (Sl->compareTo(Sr)) > 0 then ( execute ("Limak")->display() ) else (if (Sr->compareTo(Sl)) > 0 then ( execute ("Radewoosh")->display() ) else ( execute ("Tie")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=lambda : map(int,input().split()) n,c=i(); p=[*i()]; t=[*i()]; s,a,b=0,0,0 for k in range(n): a+=t[k]; b+=t[n-1-k] s+=max(0,p[k]-a*c)-max(0,p[n-k-1]-b*c) print([['Tie','Radewoosh'][s<0],'Limak'][s>0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := i->apply(); var p : Sequence := i->apply(); var t : Sequence := i->apply(); var s : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{s,a,b} := Sequence{0,0,0} ; for k : Integer.subrange(0, n-1) do ( a := a + t[k+1]; b := b + t[n - 1 - k+1] ; s := s + Set{0, p[k+1] - a * c}->max() - Set{0, p[n - k - 1+1] - b * c}->max()) ; execute (Sequence{Sequence{'Tie'}->union(Sequence{ 'Radewoosh' })->select(s < 0)}->union(Sequence{ 'Limak' })->select(s > 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=lambda : map(int,input().split()) n,k=I() a=*I(), m=len({*a}) x=0--max(a.count(x)for x in{*a})//k print(m*x*k-n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := I->apply() ; var a : OclAny := (testlist_star_expr (star_expr * (expr (atom (name I)) (trailer (arguments ( ))))) ,) ; var m : int := (Set{ a })->size() ; var x : double := 0 - -((argument (test (logical_test (comparison (expr (atom (name a)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom { (dictorsetmaker (testlist_comp (star_expr * (expr (atom (name a)))))) })))))))->max() div k ; execute (m * x * k - n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import product,accumulate from math import gcd from bisect import bisect import sys from sys import setrecursionlimit setrecursionlimit(10**9) input=sys.stdin.readline def inpl(): return list(map(int,input().split())) def primes(N): sieve=[1]*(N+1) sieve[: 2]=[0,0] P=[] for i in range(2,N+1): if sieve[i]: P.append(i) for j in range(2*i,N+1,i): sieve[j]=0 return P C=[1]*(10**5+1) C[0]=0 C[1]=0 P=primes(10**5) for p in P : C[p]=0 for p in P : if p**3>100000 : break C[p**3]=0 for i in range(len(P)): for j in range(i,bisect(P,10**5//P[i])): C[P[i]*P[j]]=0 S=list(accumulate(C)) for _ in range(int(input())): print(S[int(input())]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; setrecursionlimit((10)->pow(9)) ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; var C : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, ((10)->pow(5) + 1)) ; C->first() := 0 ; C[1+1] := 0 ; P := primes((10)->pow(5)) ; for p : P do ( C[p+1] := 0) ; for p : P do ( if (p)->pow(3) > 100000 then ( break ) else skip ; C[(p)->pow(3)+1] := 0) ; for i : Integer.subrange(0, (P)->size()-1) do ( for j : Integer.subrange(i, bisect(P, (10)->pow(5) div P[i+1])-1) do ( C[P[i+1] * P[j+1]+1] := 0)) ; var S : Sequence := (accumulate(C)) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (S[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1])->display()); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation primes(N : OclAny) : OclAny pre: true post: true activity: var sieve : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (N + 1)) ; sieve.subrange(1,2) := Sequence{0}->union(Sequence{ 0 }) ; var P : Sequence := Sequence{} ; for i : Integer.subrange(2, N + 1-1) do ( if sieve[i+1] then ( execute ((i) : P) ; for j : Integer.subrange(2 * i, N + 1-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ( sieve[j+1] := 0) ) else skip) ; return P; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,c=list(map(int,input().split())) p=list(map(int,input().split())) t=list(map(int,input().split())) limak=0 radewoosh=0 totalL=0 totalR=0 sum1=0 sum2=0 for i in range(n): totalL+=t[i] sum1+=max(0,p[i]-c*totalL) for i in range(n-1,-1,-1): totalR+=t[i] sum2+=max(0,p[i]-c*totalR) if sum1collect( _x | (OclType["int"])->apply(_x) )) ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var limak : int := 0 ; var radewoosh : int := 0 ; var totalL : int := 0 ; var totalR : int := 0 ; var sum1 : int := 0 ; var sum2 : int := 0 ; for i : Integer.subrange(0, n-1) do ( totalL := totalL + t[i+1] ; sum1 := sum1 + Set{0, p[i+1] - c * totalL}->max()) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( totalR := totalR + t[i+1] ; sum2 := sum2 + Set{0, p[i+1] - c * totalR}->max()) ; if (sum1->compareTo(sum2)) < 0 then ( execute ('Radewoosh')->display() ) else (if (sum2->compareTo(sum1)) < 0 then ( execute ('Limak')->display() ) else ( execute ('Tie')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=lambda : map(int,input().split()) n,c=i(); p=[*i()]; t=[*i()]; s,a,b=0,0,0 for k in range(n): a+=t[k]; b+=t[n-1-k] s+=max(0,p[k]-a*c)-max(0,p[n-k-1]-b*c) print([['Tie','Radewoosh'][s<0],'Limak'][s>0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := i->apply(); var p : Sequence := i->apply(); var t : Sequence := i->apply(); var s : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{s,a,b} := Sequence{0,0,0} ; for k : Integer.subrange(0, n-1) do ( a := a + t[k+1]; b := b + t[n - 1 - k+1] ; s := s + Set{0, p[k+1] - a * c}->max() - Set{0, p[n - k - 1+1] - b * c}->max()) ; execute (Sequence{Sequence{'Tie'}->union(Sequence{ 'Radewoosh' })->select(s < 0)}->union(Sequence{ 'Limak' })->select(s > 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=11 ; def isMultipleof5(n): s=str(n); l=len(s); if(s[l-1]=='5' or s[l-1]=='0'): return True ; return False ; n=19 ; if(isMultipleof5(n)==True): print(n,"is multiple of 5"); else : print(n,"is not a multiple of 5"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 11; ; skip ; n := 19; ; if (isMultipleof5(n) = true) then ( execute (n)->display(); ) else ( execute (n)->display(); ); operation isMultipleof5(n : OclAny) pre: true post: true activity: var s : String := ("" + ((n))); ; var l : int := (s)->size(); ; if (s[l - 1+1] = '5' or s[l - 1+1] = '0') then ( return true; ) else skip ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- items={} recipes={} def reset(): items.clear() recipes.clear() def algorithm(): while True : reset() for _ in range(int(input())): item,price=input().split() items[item]=int(price) if len(items)==0 : break for _ in range(int(input())): recipe=input().split() recipes[recipe[0]]=recipe[2 :] for _ in range(len(recipes)): for k,v in recipes.items(): total=0 for i in range(len(v)): total+=items[v[i]] items[k]=items[k]if items[k]toInteger()-1) do ( var item : OclAny := null; var price : OclAny := null; Sequence{item,price} := input().split() ; items[item+1] := ("" + ((price)))->toInteger()) ; if (items)->size() = 0 then ( break ) else skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var recipe : OclAny := input().split() ; recipes[recipe->first()+1] := recipe.subrange(2+1)) ; for _anon : Integer.subrange(0, (recipes)->size()-1) do ( for _tuple : recipes->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); var total : int := 0 ; for i : Integer.subrange(0, (v)->size()-1) do ( total := total + items[v[i+1]+1]) ; items[k+1] := if (items[k+1]->compareTo(total)) < 0 then items[k+1] else total endif)) ; execute (items[(OclFile["System.in"]).readLine()+1])->display()); operation main() pre: true post: true activity: algorithm(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy def findrecipe(rec,ite,obj): try : mat=rec[obj] rec2=copy.copy(rec) del rec2[obj] price=min(ite[obj],sum([findrecipe(rec2,ite,m)for m in mat])) return price except : return ite[obj] while(True): try : item={} n=int(input()) for _ in range(n): s,p=input().split() p=int(p) item[s]=p recipe={} m=int(input()) for _ in range(m): o,k,qs=input().split(" ",2) recipe[o]=qs.split() t=input() print(findrecipe(recipe,item,t)) except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while (true) do ( try ( var item : OclAny := Set{} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var s : OclAny := null; var p : OclAny := null; Sequence{s,p} := input().split() ; var p : int := ("" + ((p)))->toInteger() ; item[s+1] := p) ; var recipe : OclAny := Set{} ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, m-1) do ( var o : OclAny := null; var k : OclAny := null; var qs : OclAny := null; Sequence{o,k,qs} := input().split(" ", 2) ; recipe[o+1] := qs.split()) ; var t : String := (OclFile["System.in"]).readLine() ; execute (findrecipe(recipe, item, t))->display()) catch (_e : OclException) do ( break) ); operation findrecipe(rec : OclAny, ite : OclAny, obj : OclAny) : OclAny pre: true post: true activity: try ( var mat : OclAny := rec[obj+1] ; var rec2 : OclAny := copy->copy() ; execute (rec2[obj+1])->isDeleted() ; var price : OclAny := Set{ite[obj+1], (mat->select(m | true)->collect(m | (findrecipe(rec2, ite, m))))->sum()}->min() ; return price) catch (_e : OclException) do ( return ite[obj+1]) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def maxAreaOfIsland(self,grid): ans=0 for i in range(len(grid)): for j in range(len(grid[0])): if grid[i][j]==1 : grid[i][j]=0 ans=max(self.dfs(grid,i,j),ans) return ans def dfs(self,grid,i,j): stack=[(i,j)] area=0 while stack : r,c=stack.pop(-1) area+=1 for nr,nc in((r-1,c),(r+1,c),(r,c-1),(r,c+1)): if(0<=nrexists( _x | result = _x ); operation maxAreaOfIsland(grid : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, (grid)->size()-1) do ( for j : Integer.subrange(0, (grid->first())->size()-1) do ( if grid[i+1][j+1] = 1 then ( grid[i+1][j+1] := 0 ; ans := Set{self.dfs(grid, i, j), ans}->max() ) else skip)) ; return ans; operation dfs(grid : OclAny,i : OclAny,j : OclAny) : OclAny pre: true post: true activity: var stack : Sequence := Sequence{ Sequence{i, j} } ; var area : int := 0 ; while stack do ( var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := stack->at((atom - (number (integer 1)))+1) ; stack := stack->excludingAt(-1+1) ; area := area + 1 ; for _tuple : Sequence{Sequence{r - 1, c}, Sequence{r + 1, c}, Sequence{r, c - 1}, Sequence{r, c + 1}} do (var _indx : int := 1; var nr : OclAny := _tuple->at(_indx); _indx := _indx + 1; var nc : OclAny := _tuple->at(_indx); if (0 <= nr & (nr < (grid)->size()) & 0 <= nc & (nc < (grid->first())->size()) & grid[nr+1][nc+1]) then ( execute ((Sequence{nr, nc}) : stack) ; grid[nr+1][nc+1] := 0 ) else skip)) ; return area; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Data : def __init__(self,n,p): self.name=str(n) self.price=int(p) self.recipe=[] def minCost(self): if self.recipe==[]: return self.price else : return min(self.price,sum(list(map(lambda x : Data.minCost(index[x]),self.recipe)))) def str(self): return "{}:{}:{}".format(self.name,self.price,self.recipe) i_str=input() n=int(i_str) index={} while n!=0 : for i in range(n): i_str=input() name,price=i_str.split() index[name]=Data(name,price) i_str=input() m=int(i_str) for i in range(m): i_str=input() data=i_str.split() index[data[0]].recipe=data[2 :] q=input() print(index[q].minCost()) i_str=input() n=int(i_str) index={} ------------------------------------------------------------ OCL File: --------- class Data { static operation newData() : Data pre: true post: Data->exists( _x | result = _x ); attribute name : String := ("" + ((n))); attribute price : int := ("" + ((p)))->toInteger(); attribute recipe : Sequence := Sequence{}; operation initialise(n : OclAny,p : OclAny) : Data pre: true post: true activity: self.name := ("" + ((n))) ; self.price := ("" + ((p)))->toInteger() ; self.recipe := Sequence{}; return self; operation minCost() : OclAny pre: true post: true activity: if self.recipe = Sequence{} then ( return self.price ) else ( return Set{self.price, (((self.recipe)->collect( _x | (lambda x : OclAny in (Data.minCost(index[x+1])))->apply(_x) )))->sum()}->min() ); operation OclType["String"]() : OclAny pre: true post: true activity: return StringLib.interpolateStrings("{}:{}:{}", Sequence{self.name, self.price, self.recipe}); } class FromPython { operation initialise() pre: true post: true activity: skip ; var i_str : String := (OclFile["System.in"]).readLine() ; n := ("" + ((i_str)))->toInteger() ; var index : OclAny := Set{} ; while n /= 0 do ( for i : Integer.subrange(0, n-1) do ( i_str := (OclFile["System.in"]).readLine() ; var name : OclAny := null; var price : OclAny := null; Sequence{name,price} := i_str.split() ; index[name+1] := (Data.newData()).initialise(name, price)) ; i_str := (OclFile["System.in"]).readLine() ; var m : int := ("" + ((i_str)))->toInteger() ; for i : Integer.subrange(0, m-1) do ( i_str := (OclFile["System.in"]).readLine() ; var data : OclAny := i_str.split() ; index[data->first()+1].recipe := data.subrange(2+1)) ; var q : String := (OclFile["System.in"]).readLine() ; execute (index->at(q).minCost())->display() ; i_str := (OclFile["System.in"]).readLine() ; n := ("" + ((i_str)))->toInteger() ; index := Set{}); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=0x7fffffff def calc(t): ans=INF if len(mono[t][1])>0 : ans=0 for i in mono[t][1]: ans+=calc(i) return min(ans,mono[t][0]) while True : n=int(input()) if n==0 : break mono={} for i in range(n): s,p=input().split() mono[s]=(int(p),[]) m=int(input()) for i in range(m): a=input().split() s,p=a[0],INF if s in mono : p=mono[s][0] mono[s]=(p,a[2 :]) print(calc(input())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INF : int := 0x7fffffff ; skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var mono : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var s : OclAny := null; var p : OclAny := null; Sequence{s,p} := input().split() ; mono[s+1] := Sequence{("" + ((p)))->toInteger(), Sequence{}}) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := input().split() ; var s : OclAny := null; var p : OclAny := null; Sequence{s,p} := Sequence{a->first(),INF} ; if (mono)->includes(s) then ( var p : OclAny := mono[s+1]->first() ) else skip ; mono[s+1] := Sequence{p, a.subrange(2+1)}) ; execute (calc((OclFile["System.in"]).readLine()))->display()); operation calc(t : OclAny) : OclAny pre: true post: true activity: var ans : int := INF ; if (mono[t+1][1+1])->size() > 0 then ( ans := 0 ; for i : mono[t+1][1+1] do ( ans := ans + calc(i)) ) else skip ; return Set{ans, mono[t+1]->first()}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def price(target,item,recipe): ret=[] if target in recipe : ret.append(sum(price(r,item,recipe)for r in recipe[target])) if target in item : ret.append(item[target]) if len(ret)==0 : return 0 return min(ret) import sys f=sys.stdin while True : n=int(f.readline()) if n==0 : break item=[f.readline().split()for _ in range(n)] item={name : int(price)for name,price in item} recipe=[f.readline().strip().split()for _ in range(int(f.readline()))] recipe={r[0]: r[2 :]for r in recipe} print(price(f.readline().strip(),item,recipe)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var f : OclFile := OclFile["System.in"] ; while true do ( var n : int := ("" + ((f.readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; item := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (f.readLine().split())) ; item := item->select(_tuple | true)->collect(_tuple | Map{name |-> ("" + ((price)))->toInteger()})->unionAll() ; recipe := Integer.subrange(0, ("" + ((f.readLine())))->toInteger()-1)->select(_anon | true)->collect(_anon | (f.readLine()->trim().split())) ; recipe := recipe->select(r | true)->collect(r | Map{r->first() |-> r.subrange(2+1)})->unionAll() ; execute (price(f.readLine()->trim(), item, recipe))->display()); operation price(target : OclAny, item : OclAny, recipe : OclAny) : OclAny pre: true post: true activity: var ret : Sequence := Sequence{} ; if (recipe)->includes(target) then ( execute ((((argument (test (logical_test (comparison (expr (atom (name price)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name r))))))) , (argument (test (logical_test (comparison (expr (atom (name item))))))) , (argument (test (logical_test (comparison (expr (atom (name recipe)))))))) ))))))) (comp_for for (exprlist (expr (atom (name r)))) in (logical_test (comparison (expr (atom (name recipe)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name target)))))))) ]))))))))->sum()) : ret) ) else skip ; if (item)->includes(target) then ( execute ((item[target+1]) : ret) ) else skip ; if (ret)->size() = 0 then ( return 0 ) else skip ; return (ret)->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() l=s.split('@') if l[0]=='@' : print("No solution") else : n=len(l) f=1 for i in range(1,n-1): if len(l[i])<2 : f=0 break l[i]=l[i][0]+','+l[i][1 :] if n>1 and f and l[0]and l[n-1]: print('@'.join(l)) else : print("No solution") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var l : OclAny := s.split('@') ; if l->first() = '@' then ( execute ("No solution")->display() ) else ( var n : int := (l)->size() ; var f : int := 1 ; for i : Integer.subrange(1, n - 1-1) do ( if (l[i+1])->size() < 2 then ( f := 0 ; break ) else skip ; l[i+1] := l[i+1]->first() + ',' + l[i+1]->tail()) ; if n > 1 & f & l->first() & l[n - 1+1] then ( execute (StringLib.sumStringsWithSeparator((l), '@'))->display() ) else ( execute ("No solution")->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input().split('@'); n=len(s)-1 for i in range(1,n): if len(s[i])<2 : print('No solution'); exit() else : s[i]=s[i][0]+','+s[i][1 :] if n>0 and s and s[0]and s[n]: print('@'.join(s)) else : print('No solution') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := input().split('@'); var n : double := (s)->size() - 1 ; for i : Integer.subrange(1, n-1) do ( if (s[i+1])->size() < 2 then ( execute ('No solution')->display(); exit() ) else ( s[i+1] := s[i+1]->first() + ',' + s[i+1]->tail() )) ; if n > 0 & s & s->first() & s[n+1] then ( execute (StringLib.sumStringsWithSeparator((s), '@'))->display() ) else ( execute ('No solution')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n): n_2=n//2 ; den="1" ; while(n_2): den+='0' ; n_2-=1 print(str(1)+"/"+str(den)) if __name__=="__main__" : N=5 ; solve(N); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var N : int := 5; ; solve(N); ) else skip; operation solve(n : OclAny) pre: true post: true activity: var n:= n div 2 : int := n div 2; ; var den : String := "1"; ; while (n den := den + '0'; ; n - 1 := n - 1 - 1) do ( den := den + '0'; ; n - 1 := n - 1 - 1) ; execute (("" + ((1))) + "/" + ("" + ((den))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline s=list(input().rstrip()) n=len(s) x=[-2] for i in range(n): if s[i]=="@" : x.append(i) x.append(n+1) ans=[] for i in range(len(x)-1): if x[i+1]-x[i]<3 : ans=["No solution"] break if len(x)==2 : ans=["No solution"] if not len(ans): l=0 for i in range(len(x)-2): r=min(n,x[i+2]-1) ans.append("".join(s[l : r])) l=r sys.stdout.write(",".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var s : Sequence := (input().rstrip()) ; var n : int := (s)->size() ; var x : Sequence := Sequence{ -2 } ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = "@" then ( execute ((i) : x) ) else skip) ; execute ((n + 1) : x) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, (x)->size() - 1-1) do ( if x[i + 1+1] - x[i+1] < 3 then ( ans := Sequence{ "No solution" } ; break ) else skip) ; if (x)->size() = 2 then ( ans := Sequence{ "No solution" } ) else skip ; if not((ans)->size()) then ( var l : int := 0 ; for i : Integer.subrange(0, (x)->size() - 2-1) do ( var r : OclAny := Set{n, x[i + 2+1] - 1}->min() ; execute ((StringLib.sumStringsWithSeparator((s.subrange(l+1, r)), "")) : ans) ; l := r) ) else skip ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ",") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(s): n=len(s) if s[0]=='@' or s[-1]=='@' or n<=2 or '@@' in s : print('No solution') return lis=[] i=0 t='' while(isize() ; if s->first() = '@' or s->last() = '@' or n <= 2 or (s)->includes('@@') then ( execute ('No solution')->display() ; return ) else skip ; var lis : Sequence := Sequence{} ; var i : int := 0 ; var t : String := '' ; while ((i->compareTo(n)) < 0) do ( if s[i+1] /= '@' then ( t := t + s[i+1] ; i := i + 1 ) else ( t := t + '@' + s[i + 1+1] ; if t->first() = '@' then ( execute ('No solution')->display() ; return ) else skip ; execute ((t) : lis) ; t := '' ; i := i + 2 )) ; if lis then ( lis->last() := lis->last() + t ) else ( execute ('No solution')->display() ; return ) ; execute (StringLib.sumStringsWithSeparator((lis), ','))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() A=[] while S : if S.count("@")==0 : print("No solution") exit() if S.count("@")==1 : A.append(S) break else : x=S.index("@") if x+1count("@") = 0 then ( execute ("No solution")->display() ; exit() ) else skip ; if S->count("@") = 1 then ( execute ((S) : A) ; break ) else ( var x : int := S->indexOf("@") - 1 ; if (x + 1->compareTo((S)->size())) < 0 then ( execute ((S.subrange(1,x + 2)) : A) ; S := S.subrange(x + 2+1) ) else ( execute (("@") : A) ; break ) )) ; for a : A do ( if a->first() = "@" or a->last() = "@" then ( execute ("No solution")->display() ; exit() ) else skip) ; for i : Integer.subrange(0, (A)->size()-1) do ( execute (A[i+1])->display() ; if i /= (A)->size() - 1 then ( execute (",")->display() ) else ( execute (->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def countPairs(arr,n): mp=dict() for i in range(n): if arr[i]in mp.keys(): mp[arr[i]]+=1 else : mp[arr[i]]=1 ans=0 for it in mp : count=mp[it] ans+=(count*(count-1))//2 return ans arr=[1,1,2] n=len(arr) print(countPairs(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{1}->union(Sequence{1}->union(Sequence{ 2 })) ; n := (arr)->size() ; execute (countPairs(arr, n))->display(); operation countPairs(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var mp : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( if (mp.keys())->includes(arr[i+1]) then ( mp[arr[i+1]+1] := mp[arr[i+1]+1] + 1 ) else ( mp[arr[i+1]+1] := 1 )) ; var ans : int := 0 ; for it : mp->keys() do ( var count : OclAny := mp[it+1] ; ans := ans + (count * (count - 1)) div 2) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000,10**9)) write=lambda x : sys.stdout.write(x+"\n") n,m=list(map(int,input().split())) from collections import defaultdict ns=defaultdict(set) for i in range(m): a,b=map(int,input().split()) a-=1 b-=1 ns[a].add(b) ns[b].add(a) cs=[None]*n def is_bip(u): q=[start] cs[start]=1 v1=1 v0=0 bip=True while q : u=q.pop() c=cs[u] cc=int(not c) for v in ns[u]: if cs[v]is None : cs[v]=cc if cc==0 : v0+=1 else : v1+=1 q.append(v) elif cs[v]==c : bip=False if bip : return True,v0,v1 else : return False,v0+v1,0 types=[] vals=[] ans=0 n0=0 n1=0 n2=0 nv=0 for start in range(n): if cs[start]is not None : continue res,v0,v1=is_bip(start) if v0+v1==1 : n0+=1 elif res : nv+=(v0+v1) n1+=1 else : nv+=(v0+v1) n2+=1 ans+=n0*nv*2 ans+=n0**2 ans+=(n1+n2)**2+n1**2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; sys.setrecursionlimit(Set{1000, (10)->pow(9)}->max()) ; var write : Function := lambda x : OclAny in ((OclFile["System.out"]).write(x + "\n")) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; var ns : OclAny := defaultdict(OclType["Set"]) ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := a - 1 ; b := b - 1 ; (expr (atom (name ns)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name ns)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var cs : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; skip ; var types : Sequence := Sequence{} ; var vals : Sequence := Sequence{} ; var ans : int := 0 ; var n0 : int := 0 ; var n1 : int := 0 ; var n2 : int := 0 ; var nv : int := 0 ; for start : Integer.subrange(0, n-1) do ( if not(cs[start+1] <>= null) then ( continue ) else skip ; var res : OclAny := null; Sequence{res,v0,v1} := is_bip(start) ; if v0 + v1 = 1 then ( n0 := n0 + 1 ) else (if res then ( nv := nv + (v0 + v1) ; n1 := n1 + 1 ) else ( nv := nv + (v0 + v1) ; n2 := n2 + 1 ) ) ) ; ans := ans + n0 * nv * 2 ; ans := ans + (n0)->pow(2) ; ans := ans + ((n1 + n2))->pow(2) + (n1)->pow(2) ; execute (ans)->display(); operation is_bip(u : OclAny) : OclAny pre: true post: true activity: var q : Sequence := Sequence{ start } ; cs[start+1] := 1 ; var v1 : int := 1 ; var v0 : int := 0 ; var bip : boolean := true ; while q do ( u := q->last() ; q := q->front() ; var c : OclAny := cs[u+1] ; var cc : int := ("" + ((not(c))))->toInteger() ; for v : ns[u+1] do ( if cs[v+1] <>= null then ( cs[v+1] := cc ; if cc = 0 then ( v0 := v0 + 1 ) else ( v1 := v1 + 1 ) ; execute ((v) : q) ) else (if cs[v+1] = c then ( bip := false ) else skip))) ; if bip then ( return true, v0, v1 ) else ( return false, v0 + v1, 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math k=int(input()) def find_sol(n): result=1 a=0 b=0 if n % 10==0 : result*=(n//10)**10 a=10 b=0 else : x=math.floor(n/10) y=math.ceil(n/10) b=n-10*x a=10*y-n result*=(x**a)*(y**b) return(result,a,b) guess=int(10*k**0.1) while find_sol(guess)[0]toInteger() ; skip ; var guess : int := ("" + ((10 * (k)->pow(0.1))))->toInteger() ; while (find_sol(guess)->first()->compareTo(k)) < 0 do ( guess := guess + 1) ; Sequence{a,b} := find_sol(guess)->tail() ; x := (guess / 10)->floor() ; y := (guess / 10)->ceil() ; var word : String := 'codeforces' ; var ans : String := '' ; for i : Integer.subrange(0, a-1) do ( ans := ans + word[i+1] * x) ; for j : Integer.subrange(a, a + b-1) do ( ans := ans + word[j+1] * y) ; execute (ans)->display(); operation find_sol(n : OclAny) : OclAny pre: true post: true activity: var result : int := 1 ; var a : int := 0 ; var b : int := 0 ; if n mod 10 = 0 then ( result := result * ((n div 10))->pow(10) ; a := 10 ; b := 0 ) else ( var x : double := (n / 10)->floor() ; var y : double := (n / 10)->ceil() ; b := n - 10 * x ; a := 10 * y - n ; result := result * ((x)->pow(a)) * ((y)->pow(b)) ) ; return Sequence{result, a, b}; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) s='codeforces' s=list(s) cur=1 for i in range(len(s)): left=1 right=41 best=None while left<=right : mid=(left+right)//2 temp=cur*(mid**(len(s)-i)) if temp=k : best=mid right=mid-1 cur*=best if best : s[i]=s[i]*best print(''.join(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := 'codeforces' ; s := (s)->characters() ; var cur : int := 1 ; for i : Integer.subrange(0, (s)->size()-1) do ( var left : int := 1 ; var right : int := 41 ; var best : OclAny := null ; while (left->compareTo(right)) <= 0 do ( var mid : int := (left + right) div 2 ; var temp : double := cur * ((mid)->pow(((s)->size() - i))) ; if (temp->compareTo(k)) < 0 then ( left := mid + 1 ) else skip ; if (temp->compareTo(k)) >= 0 then ( best := mid ; right := mid - 1 ) else skip) ; cur := cur * best ; if best then ( s[i+1] := s[i+1] * best ) else skip) ; execute (StringLib.sumStringsWithSeparator((s), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def search(p,n): t=1 while t**ptoInteger() ; var s : String := 'codeforces' ; for i : Integer.subrange(0, 10-1) do ( t := search(10 - i, n) ; execute (s[i+1] * t)->display() ; n := (n + t - 1) div t); operation search(p : OclAny, n : OclAny) : OclAny pre: true post: true activity: var t : int := 1 ; while ((t)->pow(p)->compareTo(n)) < 0 do ( t := t + 1) ; return t; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout def next_line(): return stdin.readline().rstrip() def next_int(): return int(next_line()) def out(text): stdout.write(str(text)+'\n') def main(): k=next_int() out(solve(k)) def solve(k): word=list('codeforces') n=len(word) ways=1 count=[1]*n i=0 while ways=n : i=0 result=[] for i in range(n): for j in range(count[i]): result.append(word[i]) return ''.join(result) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; main(); operation next_line() : OclAny pre: true post: true activity: return stdin.readLine().rstrip(); operation next_int() : OclAny pre: true post: true activity: return ("" + ((next_line())))->toInteger(); operation out(text : OclAny) pre: true post: true activity: stdout.write(("" + ((text))) + ' '); operation main() pre: true post: true activity: var k : OclAny := next_int() ; out(solve(k)); operation solve(k : OclAny) : OclAny pre: true post: true activity: var word : Sequence := ('codeforces')->characters() ; var n : int := (word)->size() ; var ways : int := 1 ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, n) ; var i : int := 0 ; while (ways->compareTo(k)) < 0 do ( ways := ways / count[i+1] ; count[i+1] := count[i+1] + 1 ; ways := ways * count[i+1] ; i := i + 1 ; if (i->compareTo(n)) >= 0 then ( i := 0 ) else skip) ; var result : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, count[i+1]-1) do ( execute ((word[i+1]) : result))) ; return StringLib.sumStringsWithSeparator((result), ''); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,pow sz=100005 isPrime=[True for i in range(sz+1)] def sieve(): isPrime[0]=isPrime[1]=False for i in range(2,int(sqrt(sz))+1,1): if(isPrime[i]): for j in range(i*i,sz,i): isPrime[j]=False def findPrimesD(d): left=int(pow(10,d-1)) right=int(pow(10,d)-1) for i in range(left,right+1,1): if(isPrime[i]): print(i,end=" ") if __name__=='__main__' : sieve() d=1 findPrimesD(d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var sz : int := 100005 ; var isPrime : Sequence := Integer.subrange(0, sz + 1-1)->select(i | true)->collect(i | (true)) ; skip ; skip ; if __name__ = '__main__' then ( sieve() ; d := 1 ; findPrimesD(d) ) else skip; operation sieve() pre: true post: true activity: isPrime->first() := false; var isPrime[1+1] : boolean := false ; for i : Integer.subrange(2, ("" + ((sqrt(sz))))->toInteger() + 1-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (isPrime[i+1]) then ( for j : Integer.subrange(i * i, sz-1)->select( $x | ($x - i * i) mod i = 0 ) do ( isPrime[j+1] := false) ) else skip); operation findPrimesD(d : OclAny) pre: true post: true activity: var left : int := ("" + (((10)->pow(d - 1))))->toInteger() ; var right : int := ("" + (((10)->pow(d) - 1)))->toInteger() ; for i : Integer.subrange(left, right + 1-1)->select( $x | ($x - left) mod 1 = 0 ) do ( if (isPrime[i+1]) then ( execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def decToOctal(n): octalNum=[0]*100 ; i=0 ; while(n!=0): octalNum[i]=n % 8 ; n=int(n/8); i+=1 ; for j in range(i-1,-1,-1): print(octalNum[j],end=""); n=33 ; decToOctal(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 33; ; decToOctal(n);; operation decToOctal(n : OclAny) pre: true post: true activity: var octalNum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100); ; var i : int := 0; ; while (n /= 0) do ( octalNum[i+1] := n mod 8; ; n := ("" + ((n / 8)))->toInteger(); ; i := i + 1;) ; for j : Integer.subrange(-1 + 1, i - 1)->reverse() do ( execute (octalNum[j+1])->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tc=int(input().strip()) for t in range(tc): n=int(input().strip()) v=list(int(x)for x in input().strip().split()) a=sum(max(0,v[i]-v[i+1])for i in range(n-1)) b=max(max(0,v[i]-v[i+1])for i in range(n-1)) c=sum(min(b,v[i])for i in range(n-1)) print("Case #%d: %d %d" %(t+1,a,c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var tc : int := ("" + ((input()->trim())))->toInteger() ; for t : Integer.subrange(0, tc-1) do ( var n : int := ("" + ((input()->trim())))->toInteger() ; var v : Sequence := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name strip) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ; var a : OclAny := ((argument (test (logical_test (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) )))))))))->sum() ; var b : OclAny := ((argument (test (logical_test (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) )))))))))->max() ; var c : OclAny := ((argument (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b))))))) , (argument (test (logical_test (comparison (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) )))))))))->sum() ; execute (StringLib.format("Case #%d: %d %d",Sequence{t + 1, a, c}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printPermutation(n,k): if(k>=n or(n % 2==0 and k==0)): print(-1); return ; per=[0]*(n+1); for i in range(1,n+1): per[i]=i ; cnt=n-1 ; i=2 ; while(ik): t=per[i]; per[i]=per[i+1]; per[i+1]=t ; cnt-=2 ; elif(cnt-1==k): t=per[1]; per[1]=per[i]; per[i]=t ; cnt-=1 ; else : break ; i+=2 ; for i in range(1,n+1): print(per[i],end=" "); n=4 ; k=3 ; printPermutation(n,k); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4; ; k := 3; ; printPermutation(n, k);; operation printPermutation(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if ((k->compareTo(n)) >= 0 or (n mod 2 = 0 & k = 0)) then ( execute (-1)->display(); ; return; ) else skip ; var per : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); ; for i : Integer.subrange(1, n + 1-1) do ( per[i+1] := i;) ; var cnt : double := n - 1; ; var i : int := 2; ; while ((i->compareTo(n)) < 0) do ( if ((cnt - 1->compareTo(k)) > 0) then ( var t : OclAny := per[i+1]; ; per[i+1] := per[i + 1+1]; ; per[i + 1+1] := t; ; cnt := cnt - 2; ) else (if (cnt - 1 = k) then ( t := per[1+1]; ; per[1+1] := per[i+1]; ; per[i+1] := t; ; cnt := cnt - 1; ) else ( break; ) ) ; i := i + 2;) ; for i : Integer.subrange(1, n + 1-1) do ( execute (per[i+1])->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkSolution(a,b,c): if((b*b)-(4*a*c))>0 : print("2 solutions") elif((b*b)-(4*a*c))==0 : print("1 solution") else : print("No solutions") if __name__=="__main__" : a,b,c=2,5,2 checkSolution(a,b,c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{a,b,c} := Sequence{2,5,2} ; checkSolution(a, b, c) ) else skip; operation checkSolution(a : OclAny, b : OclAny, c : OclAny) pre: true post: true activity: if ((b * b) - (4 * a * c)) > 0 then ( execute ("2 solutions")->display() ) else (if ((b * b) - (4 * a * c)) = 0 then ( execute ("1 solution")->display() ) else ( execute ("No solutions")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sdin=sys.stdin.readline n=int(sdin()) a=list(map(int,sdin().split())) b=list(map(int,sdin().split())) ans=0 for k in range(29): a_nex=[[],[]] b_nex=[[],[]] for ai in a : a_nex[(ai &(1<>k].append(ai) for bj in b : b_nex[(bj &(1<>k].append(bj) a=[] b=[] for i in range(2): a=a+a_nex[i] b=b+b_nex[i] mask=pow(2,k+1)-1 a_mask=[ai & mask for ai in a] b_mask=[bj & mask for bj in b] base=pow(2,k) itr=[n]*4 count=0 for ai in a_mask : border=[base-ai,2*base-ai,3*base-ai,4*base-ai] for i in range(4): while 0toInteger() ; var a : Sequence := ((sdin().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((sdin().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for k : Integer.subrange(0, 29-1) do ( var a_nex : Sequence := Sequence{Sequence{}}->union(Sequence{ Sequence{} }) ; var b_nex : Sequence := Sequence{Sequence{}}->union(Sequence{ Sequence{} }) ; for ai : a do ((expr (atom (name a_nex)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name ai))) & (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name k)))))))) )))))))) ))) >> (expr (atom (name k))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ai)))))))) ))))) ; for bj : b do ((expr (atom (name b_nex)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name bj))) & (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name k)))))))) )))))))) ))) >> (expr (atom (name k))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name bj)))))))) ))))) ; a := Sequence{} ; b := Sequence{} ; for i : Integer.subrange(0, 2-1) do ( a := a->union(a_nex[i+1]) ; b := b->union(b_nex[i+1])) ; var mask : double := (2)->pow(k + 1) - 1 ; var a_mask : Sequence := a->select(ai | true)->collect(ai | (MathLib.bitwiseAnd(ai, mask))) ; var b_mask : Sequence := b->select(bj | true)->collect(bj | (MathLib.bitwiseAnd(bj, mask))) ; var base : double := (2)->pow(k) ; var itr : Sequence := MatrixLib.elementwiseMult(Sequence{ n }, 4) ; var count : int := 0 ; for ai : a_mask do ( var border : Sequence := Sequence{base - ai}->union(Sequence{2 * base - ai}->union(Sequence{3 * base - ai}->union(Sequence{ 4 * base - ai }))) ; for i : Integer.subrange(0, 4-1) do ( while 0 < itr[i+1] & (border[i+1]->compareTo(b_mask[itr[i+1] - 1+1])) <= 0 do ( itr[i+1] := itr[i+1] - 1)) ; count := count + ((itr[1+1] - itr->first()) + (itr[3+1] - itr[2+1]))) ; if MathLib.bitwiseAnd(count, 1) then ( ans := ans + base ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sum(x,y,n): sum1=((x**2)*(x**(2*n)-1))//(x**2-1) sum2=(x*y*(x**n*y**n-1))//(x*y-1) return(sum1+sum2) if __name__=='__main__' : x=2 y=2 n=2 print(sum(x,y,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( x := 2 ; y := 2 ; n := 2 ; execute ((x, y, n)->sum())->display() ) else skip; operation sum(x : OclAny, y : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sum1 : int := (((x)->pow(2)) * ((x)->pow((2 * n)) - 1)) div ((x)->pow(2) - 1) ; var sum2 : int := (x * y * ((x)->pow(n) * (y)->pow(n) - 1)) div (x * y - 1) ; return (sum1 + sum2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin import numpy as np d_in=lambda : int(stdin.readline()) ds_in=lambda : list(map(int,stdin.readline().split())) ORDER=28 def np_search(b_list_,a_list_,pow2,N_): c1=np.searchsorted(a_list_,pow2-b_list_) c2=np.searchsorted(a_list_,2*pow2-b_list_) c3=np.searchsorted(a_list_,3*pow2-b_list_) return N_**2-c3.sum()+c2.sum()-c1.sum() N=d_in() a_list=ds_in() b_list=ds_in() np_a=np.array(a_list) np_b=np.array(b_list) a_order_list=np.zeros((ORDER,N),dtype=int) b_order_list=np.zeros((ORDER,N),dtype=int) for i in range(1,ORDER+1): a_order_list[i-1,:]=np_a % 2**i b_order_list[i-1,:]=np_b % 2**i a_order_list.sort(axis=1) ans='' for i in range(ORDER): count=np_search(b_list_=b_order_list[i],a_list_=a_order_list[i],pow2=2**i,N_=N) if count % 2==1 : ans+='1' else : ans+='0' count=np_search(b_list_=b_order_list[-1],a_list_=a_order_list[-1],pow2=2**ORDER,N_=N) if count % 2==1 : ans+='1' else : ans+='0' print(int(ans[: :-1],2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var d_in : Function := lambda $$ : OclAny in (("" + ((stdin.readLine())))->toInteger()) ; var ds_in : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ORDER : int := 28 ; skip ; var N : OclAny := d_in->apply() ; var a_list : OclAny := ds_in->apply() ; var b_list : OclAny := ds_in->apply() ; var np_a : Sequence := (a_list) ; var np_b : Sequence := (b_list) ; var a_order_list : Sequence := MatrixLib.singleValueMatrix(Sequence{ORDER, N}, 0.0) ; var b_order_list : Sequence := MatrixLib.singleValueMatrix(Sequence{ORDER, N}, 0.0) ; for i : Integer.subrange(1, ORDER + 1-1) do ( a_order_list[i - 1+1] := np_a mod (2)->pow(i) ; b_order_list[i - 1+1] := np_b mod (2)->pow(i)) ; a_order_list := a_order_list->sort() ; var ans : String := '' ; for i : Integer.subrange(0, ORDER-1) do ( var count : OclAny := np_search((argument (test (logical_test (comparison (expr (atom (name b_list_)))))) = (test (logical_test (comparison (expr (atom (name b_order_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))), (argument (test (logical_test (comparison (expr (atom (name a_list_)))))) = (test (logical_test (comparison (expr (atom (name a_order_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))), (argument (test (logical_test (comparison (expr (atom (name pow2)))))) = (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) ** (expr (atom (name i)))))))), (argument (test (logical_test (comparison (expr (atom (name N_)))))) = (test (logical_test (comparison (expr (atom (name N)))))))) ; if count mod 2 = 1 then ( ans := ans + '1' ) else ( ans := ans + '0' )) ; count := np_search((argument (test (logical_test (comparison (expr (atom (name b_list_)))))) = (test (logical_test (comparison (expr (atom (name b_order_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))))))), (argument (test (logical_test (comparison (expr (atom (name a_list_)))))) = (test (logical_test (comparison (expr (atom (name a_order_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))))))), (argument (test (logical_test (comparison (expr (atom (name pow2)))))) = (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) ** (expr (atom (name ORDER)))))))), (argument (test (logical_test (comparison (expr (atom (name N_)))))) = (test (logical_test (comparison (expr (atom (name N)))))))) ; if count mod 2 = 1 then ( ans := ans + '1' ) else ( ans := ans + '0' ) ; execute (("" + ((ans(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))), 2)))->toInteger())->display(); operation np_search(b_list_ : OclAny, a_list_ : OclAny, pow2 : OclAny, N_ : OclAny) : OclAny pre: true post: true activity: var c1 : (trailer . (name searchsorted) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a_list_))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name pow2))) - (expr (atom (name b_list_))))))))) ))) := ; var c2 : (trailer . (name searchsorted) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a_list_))))))) , (argument (test (logical_test (comparison (expr (expr (expr (atom (number (integer 2)))) * (expr (atom (name pow2)))) - (expr (atom (name b_list_))))))))) ))) := ; var c3 : (trailer . (name searchsorted) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a_list_))))))) , (argument (test (logical_test (comparison (expr (expr (expr (atom (number (integer 3)))) * (expr (atom (name pow2)))) - (expr (atom (name b_list_))))))))) ))) := ; return (N_)->pow(2) - c3.sum() + c2.sum() - c1.sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(i)for i in input().split(" ")] b=[int(i)for i in input().split(" ")] p=1 x=0 for k in range(0,29): b_m=sorted([i %(p*2)for i in b]) a_m=sorted([i %(p*2)for i in a],reverse=True) s=0 l1=0 r1=0 l2=0 r2=0 for a_mi in a_m : while l1toInteger() ; var a : Sequence := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var b : Sequence := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var p : int := 1 ; var x : int := 0 ; for k : Integer.subrange(0, 29-1) do ( var b_m : Sequence := b->select(i | true)->collect(i | (i mod (p * 2)))->sort() ; var a_m : Sequence := a->select(i | true)->collect(i | (i mod (p * 2)))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var s : int := 0 ; var l1 : int := 0 ; var r1 : int := 0 ; var l2 : int := 0 ; var r2 : int := 0 ; for a_mi : a_m do ( while (l1->compareTo(n)) < 0 & (a_mi + b_m[l1+1]->compareTo(p)) < 0 do ( l1 := l1 + 1) ; while (r1->compareTo(n)) < 0 & (a_mi + b_m[r1+1]->compareTo(2 * p)) < 0 do ( r1 := r1 + 1) ; while (l2->compareTo(n)) < 0 & (a_mi + b_m[l2+1]->compareTo(3 * p)) < 0 do ( l2 := l2 + 1) ; while (r2->compareTo(n)) < 0 & (a_mi + b_m[r2+1]->compareTo(4 * p)) < 0 do ( r2 := r2 + 1) ; s := s + r2 - l2 + r1 - l1) ; if s mod 2 = 1 then ( x := x + p ) else skip ; p := p * 2) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import numpy as np bl=np.searchsorted N=int(input()) a=np.int32(input().split()) b=np.int32(input().split()) b.sort() q=max(a+[b[-1]]) if q==0 : print(0),sys.exit() p=math.ceil(math.log(q,2))+1 ans=0 for i in range(p,-1,-1): T=2**i ai=a %(2*T) bi=b %(2*T) bi.sort() tmp=0 left1=bl(bi,T-ai) right1=bl(bi,2*T-ai) left2=bl(bi,3*T-ai) right2=bl(bi,4*T-ai) if np.sum(-left1+right1-left2+right2)% 2 : ans+=T print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var bl : (trailer . (name searchsorted)) := ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : (trailer . (name int32) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))) := ; var b : (trailer . (name int32) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))) := ; b := b->sort() ; var q : OclAny := (a->union(Sequence{ b->last() }))->max() ; if q = 0 then ( (0)->display() ; sys.exit() ) else skip ; var p : double := ((q, 2)->log())->ceil() + 1 ; var ans : int := 0 ; for i : Integer.subrange(-1 + 1, p)->reverse() do ( var T : double := (2)->pow(i) ; var ai : int := a mod (2 * T) ; var bi : int := b mod (2 * T) ; bi := bi->sort() ; var tmp : int := 0 ; var left1 : OclAny := bl(bi, T - ai) ; var right1 : OclAny := bl(bi, 2 * T - ai) ; var left2 : OclAny := bl(bi, 3 * T - ai) ; var right2 : OclAny := bl(bi, 4 * T - ai) ; if MatrixLib.sumMatrix(-left1 + right1 - left2 + right2) mod 2 then ( ans := ans + T ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np bisect_left=np.searchsorted input() a=np.array(input().split(),'int32') b=np.array(input().split(),'int32') ans=0 for k in range(28,-1,-1): low=pow(2,k) high=pow(2,k+1) a %=high b %=high b.sort() y=np.hstack((b-high,b)) left=bisect_left(y,low-a) right=bisect_left(y,high-a) if np.sum(right-left)% 2 : ans+=low print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var bisect_left : (trailer . (name searchsorted)) := ; input() ; var a : Sequence := (input().split(), 'int32') ; var b : Sequence := (input().split(), 'int32') ; var ans : int := 0 ; for k : Integer.subrange(-1 + 1, 28)->reverse() do ( var low : double := (2)->pow(k) ; var high : double := (2)->pow(k + 1) ; a := a mod high ; b := b mod high ; b := b->sort() ; var y : (trailer . (name hstack) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (name high))))))) , (test (logical_test (comparison (expr (atom (name b))))))) )))))))) ))) := ; var left : OclAny := bisect_left(y, low - a) ; var right : OclAny := bisect_left(y, high - a) ; if MatrixLib.sumMatrix(right - left) mod 2 then ( ans := ans + low ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def vowelOrConsonant(x): if(x=='a' or x=='e' or x=='i' or x=='o' or x=='u'): print("Vowel") else : print("Consonant") vowelOrConsonant('c') vowelOrConsonant('e') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; vowelOrConsonant('c') ; vowelOrConsonant('e'); operation vowelOrConsonant(x : OclAny) pre: true post: true activity: if (x = 'a' or x = 'e' or x = 'i' or x = 'o' or x = 'u') then ( execute ("Vowel")->display() ) else ( execute ("Consonant")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printGroups(n): x=1 y=n*n for i in range(1,n+1): for j in range(1,n//2+1): print("{",x,",",y,"}",end=" ") x+=1 y-=1 print() if __name__=="__main__" : n=4 printGroups(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 4 ; printGroups(n) ) else skip; operation printGroups(n : OclAny) pre: true post: true activity: var x : int := 1 ; var y : double := n * n ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, n div 2 + 1-1) do ( execute ("{")->display() ; x := x + 1 ; y := y - 1) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findRealAndImag(s): l=len(s) i=0 if(s.find('+')!=-1): i=s.find('+') else : i=s.find('-'); real=s[: i] imaginary=s[i+1 : l-1] print("Real part:",real) print("Imaginary part:",imaginary) s="3+4i" ; findRealAndImag(s); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := "3+4i"; ; findRealAndImag(s);; operation findRealAndImag(s : OclAny) pre: true post: true activity: var l : int := (s)->size() ; var i : int := 0 ; if (s->indexOf('+') - 1 /= -1) then ( i := s->indexOf('+') - 1 ) else ( i := s->indexOf('-') - 1; ) ; var real : OclAny := s.subrange(1,i) ; var imaginary : OclAny := s.subrange(i + 1+1, l - 1) ; execute ("Real part:")->display() ; execute ("Imaginary part:")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.stdin=open('a.in','r') sys.stdout=open('a.out','w') def getline(): return[int(c)for c in input().split()] def solve(): [n]=getline() a=getline() ans1=0 ans2=0 k=0 for i in range(0,n-1,1): if a[i]>a[i+1]: ans1+=a[i]-a[i+1] k=max(k,a[i]-a[i+1]) for i in range(0,n-1,1): ans2+=min(a[i],k) return "%d %d" %(ans1,ans2) for T in range(int(input())): sys.stderr.write(str(T)) print('Case #%d: %s' %(T+1,solve())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('a.in')) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile('a.out')) ; skip ; skip ; for T : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ((expr (atom (name sys)) (trailer . (name stderr)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name T)))))))) ))))))))) )))) ; execute (StringLib.format('Case #%d: %s',Sequence{T + 1, solve()}))->display()); operation getline() : OclAny pre: true post: true activity: return input().split()->select(c | true)->collect(c | (("" + ((c)))->toInteger())); operation solve() pre: true post: true activity: ; Sequence{ n } := getline() ; var a : OclAny := getline() ; var ans1 : int := 0 ; var ans2 : int := 0 ; var k : int := 0 ; for i : Integer.subrange(0, n - 1-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (a[i+1]->compareTo(a[i + 1+1])) > 0 then ( ans1 := ans1 + a[i+1] - a[i + 1+1] ; k := Set{k, a[i+1] - a[i + 1+1]}->max() ) else skip) ; for i : Integer.subrange(0, n - 1-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( ans2 := ans2 + Set{a[i+1], k}->min()) ; return StringLib.format("%d %d",Sequence{ans1, ans2}); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inp=input() arr=[int(i)for i in input().split(' ')] firstMAX=max(arr) arr2=[0] maxes=[] result=0 for i in range(len(arr)): if(len(arr)-1!=i and i!=0): if(arr[i]==arr[i+1]and arr[i]==firstMAX): result+=1 else : if((arr[i]==arr[i-1]and arr[i]==firstMAX)or arr[i]==firstMAX): result+=1 else : maxes.append(result) result=0 else : if(arr[i]==firstMAX): result+=1 if(len(arr)-1==i): maxes.append(result) result=0 else : maxes.append(result) result=0 print(max(maxes)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inp : String := (OclFile["System.in"]).readLine() ; var arr : Sequence := input().split(' ')->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var firstMAX : OclAny := (arr)->max() ; var arr2 : Sequence := Sequence{ 0 } ; var maxes : Sequence := Sequence{} ; var result : int := 0 ; for i : Integer.subrange(0, (arr)->size()-1) do ( if ((arr)->size() - 1 /= i & i /= 0) then ( if (arr[i+1] = arr[i + 1+1] & arr[i+1] = firstMAX) then ( result := result + 1 ) else ( if ((arr[i+1] = arr[i - 1+1] & arr[i+1] = firstMAX) or arr[i+1] = firstMAX) then ( result := result + 1 ) else ( execute ((result) : maxes) ; result := 0 ) ) ) else ( if (arr[i+1] = firstMAX) then ( result := result + 1 ; if ((arr)->size() - 1 = i) then ( execute ((result) : maxes) ; result := 0 ) else skip ) else ( execute ((result) : maxes) ; result := 0 ) )) ; execute ((maxes)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split(' '))) lst=sorted(a) bigger=lst[-1] indices=[] for i,x in enumerate(a): if x==bigger : indices.append(i) count=1 answer=1 for i in range(len(indices)-1): if indices[i]==indices[i+1]-1 : count+=1 answer=max(answer,count) else : count=1 print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var lst : Sequence := a->sort() ; var bigger : OclAny := lst->last() ; var indices : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); if x = bigger then ( execute ((i) : indices) ) else skip) ; var count : int := 1 ; var answer : int := 1 ; for i : Integer.subrange(0, (indices)->size() - 1-1) do ( if indices[i+1] = indices[i + 1+1] - 1 then ( count := count + 1 ; answer := Set{answer, count}->max() ) else ( count := 1 )) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSum(n): n-=1 sum=0 sum+=(n*(n+1))/2 sum+=(n*(n+1)*(2*n+1))/6 return int(sum) n=3 print(findSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3 ; execute (findSum(n))->display(); operation findSum(n : OclAny) : OclAny pre: true post: true activity: n := n - 1 ; var sum : int := 0 ; sum := sum + (n * (n + 1)) / 2 ; sum := sum + (n * (n + 1) * (2 * n + 1)) / 6 ; return ("" + ((sum)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) a=list(map(int,input().split())) mx=max(a) max_len=0 now_len=0 for i in range(n): if a[i]==mx : now_len+=1 max_len=max(max_len,now_len) else : now_len=0 print(max_len) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mx : OclAny := (a)->max() ; var max_len : int := 0 ; var now_len : int := 0 ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = mx then ( now_len := now_len + 1 ; max_len := Set{max_len, now_len}->max() ) else ( now_len := 0 )) ; execute (max_len)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[*map(int,input().split())] mx=max(a) ans=1 i=0 while itoInteger() ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mx : OclAny := (a)->max() ; var ans : int := 1 ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( var count : int := 0 ; while (i->compareTo(n)) < 0 & a[i+1] = mx do ( count := count + 1 ; i := i + 1) ; i := i + 1 ; ans := Set{ans, count}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) l=list(map(int,input().split())) x,ct,max_ct=0,0,0 for i in range(0,n): if(xtoInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := null; var ct : OclAny := null; var max_ct : OclAny := null; Sequence{x,ct,max_ct} := Sequence{0,0,0} ; for i : Integer.subrange(0, n-1) do ( if ((x->compareTo(l[i+1])) < 0) then ( var x : OclAny := l[i+1] ) else skip) ; for i : Integer.subrange(0, n-1) do ( if (l[i+1] = x) then ( ct := ct + 1 ) else ( var max_ct : OclAny := Set{ct, max_ct}->max() ; var ct : int := 0 )) ; max_ct := Set{ct, max_ct}->max() ; execute (max_ct)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) table1='' table2='' for i in range(2*N): if icollect( _x | (OclType["int"])->apply(_x) ) ; var table1 : String := '' ; var table2 : String := '' ; for i : Integer.subrange(0, 2 * N-1) do ( if (i->compareTo(N)) < 0 then ( table1 := table1 + (OclFile["System.in"]).readLine() ) else ( table2 := table2 + (OclFile["System.in"]).readLine() )) ; var count : int := 0 ; for _tuple : Integer.subrange(1, table1->size())->collect( _indx | Sequence{table1->at(_indx), table2->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if i /= j then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=[list(list(input()))for i in range(n)] b=[list(list(input()))for i in range(n)] cout=0 for i in range(n): for j in range(m): if a[i][j]!=b[i][j]: cout+=1 print(cout) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((((OclFile["System.in"]).readLine())->characters()))) ; var b : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((((OclFile["System.in"]).readLine())->characters()))) ; var cout : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if a[i+1][j+1] /= b[i+1][j+1] then ( cout := cout + 1 ) else skip)) ; execute (cout)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from heapq import heappush,heappop import sys import math import bisect import random def LI(): return[int(x)for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return[list(x)for x in sys.stdin.readline().split()] def S(): res=list(sys.stdin.readline()) if res[-1]=="\n" : return res[:-1] return res def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] sys.setrecursionlimit(1000000) mod=1000000007 def solve(): N,M=LI() A=SR(N) B=SR(N) ans=0 for i in range(N): for j in range(M): if A[i][j]!=B[i][j]: ans+=1 print(ans) return if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1000000) ; var mod : int := 1000000007 ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | ((x))); operation S() : OclAny pre: true post: true activity: var res : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if res->last() = "\n" then ( return res->front() ) else skip ; return res; operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation solve() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := LI() ; var A : OclAny := SR(N) ; var B : OclAny := SR(N) ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, M-1) do ( if A[i+1][j+1] /= B[i+1][j+1] then ( ans := ans + 1 ) else skip)) ; execute (ans)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) A=[input()for _ in range(N)] B=[input()for _ in range(N)] ans=0 for a,b in zip(A,B): for aa,bb in zip(a,b): if aa!=bb : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var B : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var ans : int := 0 ; for _tuple : Integer.subrange(1, A->size())->collect( _indx | Sequence{A->at(_indx), B->at(_indx)} ) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); for _tuple : Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), b->at(_indx)} ) do (var _indx : int := 1; var aa : OclAny := _tuple->at(_indx); _indx := _indx + 1; var bb : OclAny := _tuple->at(_indx); if aa /= bb then ( ans := ans + 1 ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r=0 for _ in[0]*int(input()): s,d=map(int,input().split()) r=[(r-s+d)//d*d+s,s][rtoInteger()) do ( var s : OclAny := null; var d : OclAny := null; Sequence{s,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; r := Sequence{(r - s + d) div d * d + s}->union(Sequence{ s })->select((r->compareTo(s)) < 0)) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for tc in range(int(input())): n=int(input()) m=list(map(int,input().split())) x,y,t,r=0,0,0,0 for d in m : if dtoInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := null; var y : OclAny := null; var t : OclAny := null; var r : OclAny := null; Sequence{x,y,t,r} := Sequence{0,0,0,0} ; for d : m do ( if (d->compareTo(t)) < 0 then ( x := x + t - d ; var r : OclAny := Set{r, t - d}->max() ) else skip ; var t : OclAny := d) ; for d : m->front() do ( y := y + Set{r, d}->min()) ; execute (StringLib.format("Case #%d: %d %d",Sequence{tc + 1, x, y}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=lambda : map(int,input().split()) n,=x() cnt=0 ; c=0 for i in range(n): a,b=x() j=c+1 ; cnt2=0 while True : if(j in range(a,10**20,b)): cnt+=(j-c); c=j ; break j+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,)} := x->apply() ; var cnt : int := 0; var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := x->apply() ; var j : int := c + 1; var cnt2 : int := 0 ; while true do ( if ((Integer.subrange(a, (10)->pow(20)-1)->select( $x | ($x - a) mod b = 0 ))->includes(j)) then ( cnt := cnt + (j - c); c := j; break ) else skip ; j := j + 1)) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getSum(n): sum=0 while(n!=0): sum=sum+int(n % 10) n=int(n/10) return sum n=687 print(getSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 687 ; execute (getSum(n))->display(); operation getSum(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; while (n /= 0) do ( sum := sum + ("" + ((n mod 10)))->toInteger() ; n := ("" + ((n / 10)))->toInteger()) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- total=0 for _ in range(int(input())): s,d=map(int,input().split()) if totaltoInteger()-1) do ( var s : OclAny := null; var d : OclAny := null; Sequence{s,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (total->compareTo(s)) < 0 then ( total := s ) else (if (s->compareTo(total)) <= 0 then ( var i : int := 1 ; while ((s + d * i)->compareTo(total)) <= 0 do ( i := i + 1) ; total := (s + d * i) ) else skip)) ; execute (total)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=0 for i in range(n): s,d=map(int,input().split()) if s>x : x=s else : x=x-(x-s)% d+d print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := 0 ; for i : Integer.subrange(0, n-1) do ( var s : OclAny := null; var d : OclAny := null; Sequence{s,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (s->compareTo(x)) > 0 then ( x := s ) else ( x := x - (x - s) mod d + d )) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- number_of_doctors=int(input()) appointments=[0] for i in range(number_of_doctors): (s,d)=map(int,input().split(' ')) while True : if s not in appointments and s>appointments[-1]: appointments.append(s) break else : s=(d-(appointments[-1]-s)% d)+appointments[-1] print(max(appointments)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var number_of_doctors : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var appointments : Sequence := Sequence{ 0 } ; for i : Integer.subrange(0, number_of_doctors-1) do ( ; var Sequence{s, d} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; while true do ( if (appointments)->excludes(s) & (s->compareTo(appointments->last())) > 0 then ( execute ((s) : appointments) ; break ) else ( var s : double := (d - (appointments->last() - s) mod d) + appointments->last() ))) ; execute ((appointments)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findX(A,B): j=0 x=0 while(A or B): if((A & 1)and(B & 1)): x+=(1<>=1 B>>=1 j+=1 return x if __name__=='__main__' : A=2 B=3 X=findX(A,B) print("X=",X,",Sum=",(A ^ X)+(B ^ X)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( A := 2 ; B := 3 ; var X : OclAny := findX(A, B) ; execute ("X=")->display() ) else skip; operation findX(A : OclAny, B : OclAny) : OclAny pre: true post: true activity: var j : int := 0 ; var x : int := 0 ; while (A or B) do ( if ((MathLib.bitwiseAnd(A, 1)) & (MathLib.bitwiseAnd(B, 1))) then ( x := x + (1 * (2->pow(j))) ) else skip ; A := A div (2->pow(1)) ; B := B div (2->pow(1)) ; j := j + 1) ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def splitStrings(st,dl): word="" num=0 st+=dl l=len(st) substr_list=[] for i in range(l): if(st[i]!=dl): word+=st[i] else : if(len(word)!=0): substr_list.append(word) word="" return substr_list if __name__=='__main__' : str="geeks;for;geeks" dl=';' res=splitStrings(str,dl) for x in range(len(res)): print(res[x]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var OclType["String"] : String := "geeks;for;geeks" ; dl := ';' ; var res : OclAny := splitStrings(OclType["String"], dl) ; for x : Integer.subrange(0, (res)->size()-1) do ( execute (res[x+1])->display()) ) else skip; operation splitStrings(st : OclAny, dl : OclAny) : OclAny pre: true post: true activity: var word : String := "" ; var num : int := 0 ; st := st + dl ; var l : int := (st)->size() ; var substr_list : Sequence := Sequence{} ; for i : Integer.subrange(0, l-1) do ( if (st[i+1] /= dl) then ( word := word + st[i+1] ) else ( if ((word)->size() /= 0) then ( execute ((word) : substr_list) ) else skip ; word := "" )) ; return substr_list; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def floorSqrt(x): if(x==0 or x==1): return x start=1 end=x while(start<=end): mid=(start+end)//2 if(mid*mid==x): return mid if(mid*middisplay(); operation floorSqrt(x : OclAny) : OclAny pre: true post: true activity: if (x = 0 or x = 1) then ( return x ) else skip ; var start : int := 1 ; var end : OclAny := x ; while ((start->compareTo(end)) <= 0) do ( var mid : int := (start + end) div 2 ; if (mid * mid = x) then ( return mid ) else skip ; if ((mid * mid->compareTo(x)) < 0) then ( start := mid + 1 ; var ans : int := mid ) else ( end := mid - 1 )) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import fractions import heapq import collections import re import array import bisect from collections import Counter,defaultdict class BIT(object): def __init__(self,size): self.size=size self.l=[0]*(size+1) def sum(self,i): r=0 while i>0 : r+=self.l[i] i-=i &-i return r def add(self,i,x): while i<=self.size : self.l[i]+=x i+=i &-i max_a=1000000 def solve(a): bit=BIT(max_a) ans=0 for i,x in enumerate(a): ans+=i-bit.sum(x) bit.add(x,1) return ans def main(): while True : N=int(input()) if N==0 : return a=[] for i in range(N): a.append(int(input())) print(solve(a)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class BIT extends object { static operation newBIT() : BIT pre: true post: BIT->exists( _x | result = _x ); attribute size : OclAny := size; attribute l : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (size + 1)); operation initialise(size : OclAny) : pre: true post: true activity: self.size := size ; self.l := MatrixLib.elementwiseMult(Sequence{ 0 }, (size + 1)); return self; operation sum(i : OclAny) : OclAny pre: true post: true activity: var r : int := 0 ; while i > 0 do ( r := r + self.l[i+1] ; i := i - MathLib.bitwiseAnd(i, -i)) ; return r; operation add(i : OclAny,x : OclAny) pre: true post: true activity: while (i->compareTo(self.size)) <= 0 do ( self.l[i+1] := self.l[i+1] + x ; i := i + MathLib.bitwiseAnd(i, -i)); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var max_a : int := 1000000 ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation solve(a : OclAny) : OclAny pre: true post: true activity: var bit : BIT := (BIT.newBIT()).initialise(max_a) ; var ans : int := 0 ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); ans := ans + i - bit.sum(x) ; execute ((x, 1) : bit)) ; return ans; operation main() pre: true post: true activity: while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( return ) else skip ; a := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : a)) ; execute (solve(a))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,bisect PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") def bubble_sort(N,A): cnt=0 last=N-1 while last>0 : for k in range(last): if A[k]>A[k+1]: A[k],A[k+1]=A[k+1],A[k] cnt+=1 last-=1 return cnt while True : N=int(input()) if N==0 : break A=[int(input())for _ in range(N)] print(bubble_sort(N,A)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; skip ; while true do ( N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; A := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; execute (bubble_sort(N, A))->display()); operation bubble_sort(N : OclAny, A : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; var last : double := N - 1 ; while last > 0 do ( for k : Integer.subrange(0, last-1) do ( if (A[k+1]->compareTo(A[k + 1+1])) > 0 then ( var A[k+1] : OclAny := null; var A[k + 1+1] : OclAny := null; Sequence{A[k+1],A[k + 1+1]} := Sequence{A[k + 1+1],A[k+1]} ; cnt := cnt + 1 ) else skip) ; last := last - 1) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : N,M,C=input(),[],0 if not N : break for i in range(N): M.append(input()) for p in range(N)[: :-1]: for i in range(p): if M[i]>M[i+1]: M[i],M[i+1]=M[i+1],M[i] C+=1 print(C) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var N : OclAny := null; var M : OclAny := null; var C : OclAny := null; Sequence{N,M,C} := Sequence{(OclFile["System.in"]).readLine(),Sequence{},0} ; if not(N) then ( break ) else skip ; for i : Integer.subrange(0, N-1) do ( execute (((OclFile["System.in"]).readLine()) : M)) ; for p : range(N)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( for i : Integer.subrange(0, p-1) do ( if (M[i+1]->compareTo(M[i + 1+1])) > 0 then ( var M[i+1] : OclAny := null; var M[i + 1+1] : OclAny := null; Sequence{M[i+1],M[i + 1+1]} := Sequence{M[i + 1+1],M[i+1]} ; C := C + 1 ) else skip)) ; execute (C)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gao1(l): ans=0 for i in range(1,len(l)): if l[i]toInteger() ; for cas : Integer.subrange(0, t-1) do ( execute (StringLib.format('Case #%d:',(cas + 1)))->display() ; var n : String := (OclFile["System.in"]).readLine() ; l := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (gao1(l))->display()); operation gao1(l : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(1, (l)->size()-1) do ( if (l[i+1]->compareTo(l[i - 1+1])) < 0 then ( ans := ans + l[i - 1+1] - l[i+1] ) else skip) ; return ans; operation gao2(l : OclAny) : OclAny pre: true post: true activity: var rate : int := 0 ; for i : Integer.subrange(1, (l)->size()-1) do ( rate := Set{rate, l[i - 1+1] - l[i+1]}->max()) ; ans := 0 ; for i : Integer.subrange(1, (l)->size()-1) do ( ans := ans + Set{l[i - 1+1], rate}->min()) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getSum(n): sum=0 while(n>0): sum+=int(n % 10) n=int(n/10) return sum n=687 print(getSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 687 ; execute (getSum(n))->display(); operation getSum(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; while (n > 0) do ( sum := sum + ("" + ((n mod 10)))->toInteger() ; n := ("" + ((n / 10)))->toInteger()) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bubble_sort(item_list): length=len(item_list) count=0 for lp in range(length): for lp2 in range(length-lp-1): if item_list[lp2]>item_list[lp2+1]: tmp=item_list[lp2] item_list[lp2]=item_list[lp2+1] item_list[lp2+1]=tmp count+=1 return count while True : input_count=int(input()) if input_count==0 : break data=[int(input())for _ in range(input_count)] result=bubble_sort(data) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var input_count : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if input_count = 0 then ( break ) else skip ; var data : Sequence := Integer.subrange(0, input_count-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var result : OclAny := bubble_sort(data) ; execute (result)->display()); operation bubble_sort(item_list : OclAny) : OclAny pre: true post: true activity: var length : int := (item_list)->size() ; var count : int := 0 ; for lp : Integer.subrange(0, length-1) do ( for lp2 : Integer.subrange(0, length - lp - 1-1) do ( if (item_list[lp2+1]->compareTo(item_list[lp2 + 1+1])) > 0 then ( var tmp : OclAny := item_list[lp2+1] ; item_list[lp2+1] := item_list[lp2 + 1+1] ; item_list[lp2 + 1+1] := tmp ; count := count + 1 ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if n==0 : break c=0 a=[int(input())for _ in range(n)] for i in range(n): for j in range(n-1,0,-1): if a[j]toInteger() ; if n = 0 then ( break ) else skip ; var c : int := 0 ; var a : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0 + 1, n - 1)->reverse() do ( if (a[j+1]->compareTo(a[j - 1+1])) < 0 then ( var Sequence{a[j+1], a[j - 1+1]} : OclAny := null; Sequence{c,Sequence{a[j+1], a[j - 1+1]}} := Sequence{c + 1,Sequence{a[j - 1+1], a[j+1]}} ) else skip)) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) print(a % b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (a mod b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from decimal import* a,b=input().rstrip().split(' ') getcontext().prec=len(a) ans=Decimal(a)% Decimal(b) ans=ans.quantize(Decimal('1.'),rounding=ROUND_DOWN) if ans==0 : print(0) else : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().rstrip().split(' ') ; getcontext().prec := (a)->size() ; var ans : int := Decimal(a) mod Decimal(b) ; ans := ans.quantize(Decimal('1.'), (argument (test (logical_test (comparison (expr (atom (name rounding)))))) = (test (logical_test (comparison (expr (atom (name ROUND_DOWN)))))))) ; if ans = 0 then ( execute (0)->display() ) else ( execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(eval(input().replace(' ','%'))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (input().replace(' ', '%'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() a,b=x.split() a=int(a) b=int(b) print(a % b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := (OclFile["System.in"]).readLine() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := x.split() ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; execute (a mod b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): A,B=map(int,input().split()) print(A % B) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (A mod B)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B=map(int,input().split()) print(A+B) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (A + B)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from decimal import* a,b=input().rstrip().split(' ') getcontext().prec=1000000 print(Decimal(a)+Decimal(b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().rstrip().split(' ') ; getcontext().prec := 1000000 ; execute (Decimal(a) + Decimal(b))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(eval(input().replace(" ","+"))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (input().replace(" ", "+"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def __gcd(a,b): if(a==0 or b==0): return 0 if(a==b): return a if(a>b): return __gcd(a-b,b) return __gcd(a,b-a) def findValue(x,y,z): g=__gcd(y,z) return(x*g)/__gcd(x,g) x=30 y=40 z=400 print("%d" % findValue(x,y,z)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; x := 30 ; y := 40 ; z := 400 ; execute (StringLib.format("%d",findValue(x, y, z)))->display(); operation __gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0 or b = 0) then ( return 0 ) else skip ; if (a = b) then ( return a ) else skip ; if ((a->compareTo(b)) > 0) then ( return __gcd(a - b, b) ) else skip ; return __gcd(a, b - a); operation findValue(x : OclAny, y : OclAny, z : OclAny) : OclAny pre: true post: true activity: var g : OclAny := __gcd(y, z) ; return (x * g) / __gcd(x, g); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math class Node : def __init__(self,data): self.data=data self.next=None def push(head_ref,new_data): new_node=Node(new_data) new_node.data=new_data new_node.next=head_ref head_ref=new_node return head_ref def isPrime(n): if(n<=1): return False if(n<=3): return True if(n % 2==0 or n % 3==0): return False for i in range(5,n+1,6): if(i*iexists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.next := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( head := null ; head := push(head, 17) ; head := push(head, 7) ; head := push(head, 6) ; head := push(head, 16) ; head := push(head, 15) ; execute ("Original List: ")->display() ; printList(head) ; head := deleteNonPrimeNodes(head) ; execute ("\nModified List: ")->display() ; printList(head) ) else skip; operation push(head_ref : OclAny, new_data : OclAny) : OclAny pre: true post: true activity: var new_node : Node := (Node.newNode()).initialise(new_data) ; new_node.data := new_data ; new_node.next := head_ref ; head_ref := new_node ; return head_ref; operation isPrime(n : OclAny) : OclAny pre: true post: true activity: if (n <= 1) then ( return false ) else skip ; if (n <= 3) then ( return true ) else skip ; if (n mod 2 = 0 or n mod 3 = 0) then ( return false ) else skip ; for i : Integer.subrange(5, n + 1-1)->select( $x | ($x - 5) mod 6 = 0 ) do ( if ((i * i->compareTo(n + 2)) < 0 & (n mod i = 0 or n mod (i + 2) = 0)) then ( return false ) else skip) ; return true; operation deleteNonPrimeNodes(head_ref : OclAny) : OclAny pre: true post: true activity: var ptr : OclAny := head_ref ; while (ptr /= null & isPrime(ptr.data) /= true) do ( var temp : OclAny := ptr ; ptr := ptr.next) ; head_ref := ptr ; if (ptr = null) then ( return null ) else skip ; var curr : OclAny := ptr.next ; while (curr /= null) do ( if (isPrime(curr.data) /= true) then ( ptr.next := curr.next ; curr := ptr.next ) else ( ptr := curr ; curr := curr.next ) ; return head_ref); operation printList(head : OclAny) pre: true post: true activity: while (head /= null) do ( execute (head.data)->display() ; head := head.next); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tests=int(input()) for t in range(tests): n=int(input()) a=list(map(int,input().split())) first=0 for i in range(n-1): if a[i+1]toInteger() ; for t : Integer.subrange(0, tests-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var first : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if (a[i + 1+1]->compareTo(a[i+1])) < 0 then ( first := first + a[i+1] - a[i + 1+1] ) else skip) ; var maxdiff : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( maxdiff := Set{maxdiff, a[i+1] - a[i + 1+1]}->max()) ; var current : OclAny := null; var second : OclAny := null; Sequence{current,second} := Sequence{a->first(),0} ; for i : Integer.subrange(1, (a)->size()-1) do ( var now : OclAny := Set{current, maxdiff}->min() ; second := second + now ; var current : OclAny := a[i+1]) ; execute (StringLib.interpolateStrings('Case #{}:{}{}', Sequence{t + 1, first, second}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import sys def main(): a,b=map(int,input().split()) print(a+b) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (a + b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,bisect,math A,B=map(int,sys.stdin.readline().split()) print(A+B) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (A + B)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=1000001 ; fourDiv=[False]*(N+1); def fourDistinctFactors(): primeAll=[True]*(N+1); p=2 ; while(p*p<=N): if(primeAll[p]==True): i=p*2 ; while(i<=N): primeAll[i]=False ; i+=p ; p+=1 ; prime=[]; for p in range(2,N+1): if(primeAll[p]): prime.append(p); for i in range(len(prime)): p=prime[i]; if(1*p*p*p<=N): fourDiv[p*p*p]=True ; for j in range(i+1,len(prime)): q=prime[j]; if(1*p*q>N): break ; fourDiv[p*q]=True ; fourDistinctFactors(); num=10 ; if(fourDiv[num]): print("Yes"); else : print("No"); num=12 ; if(fourDiv[num]): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 1000001; ; var fourDiv : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (N + 1)); ; skip ; fourDistinctFactors(); ; var num : int := 10; ; if (fourDiv[num+1]) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ; num := 12; ; if (fourDiv[num+1]) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ); operation fourDistinctFactors() pre: true post: true activity: var primeAll : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (N + 1)); ; var p : int := 2; ; while ((p * p->compareTo(N)) <= 0) do ( if (primeAll[p+1] = true) then ( var i : int := p * 2; ; while ((i->compareTo(N)) <= 0) do ( primeAll[i+1] := false; ; i := i + p;) ) else skip ; p := p + 1;) ; var prime : Sequence := Sequence{}; ; for p : Integer.subrange(2, N + 1-1) do ( if (primeAll[p+1]) then ( execute ((p) : prime); ) else skip) ; for i : Integer.subrange(0, (prime)->size()-1) do ( p := prime[i+1]; ; if ((1 * p * p * p->compareTo(N)) <= 0) then ( fourDiv[p * p * p+1] := true; ) else skip ; for j : Integer.subrange(i + 1, (prime)->size()-1) do ( var q : OclAny := prime[j+1]; ; if ((1 * p * q->compareTo(N)) > 0) then ( break; ) else skip ; fourDiv[p * q+1] := true;)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict from heapq import nlargest def maxSize(adj,node,parent): children=adj[node]-{parent} if len(children)==1 : return 1 return sum(nlargest(2,(maxSize(adj,child,node)for child in children)))+1 for t in range(int(input())): N=int(input()) adj=defaultdict(set) for _ in range(N-1): a,b=map(int,input().split()) adj[a].add(b) adj[b].add(a) result=N-max(maxSize(adj,root,None)for root in range(1,N+1)) assert 0<=result<=N print('Case #{}:{}'.format(t+1,result)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; adj := defaultdict(OclType["Set"]) ; for _anon : Integer.subrange(0, N - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var result : double := N - ((argument (test (logical_test (comparison (expr (atom (name maxSize)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name adj))))))) , (argument (test (logical_test (comparison (expr (atom (name root))))))) , (argument (test (logical_test (comparison (expr (atom None))))))) ))))))) (comp_for for (exprlist (expr (atom (name root)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name N))) + (expr (atom (number (integer 1)))))))))) )))))))))->max() ; assert 0 <= result & (result <= N) do "assertion failed" ; execute (StringLib.interpolateStrings('Case #{}:{}', Sequence{t + 1, result}))->display()); operation maxSize(adj : OclAny, node : OclAny, parent : OclAny) : OclAny pre: true post: true activity: var children : double := adj[node+1] - Set{ parent } ; if (children)->size() = 1 then ( return 1 ) else skip ; return (nlargest(2, Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name maxSize)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name adj))))))) , (argument (test (logical_test (comparison (expr (atom (name child))))))) , (argument (test (logical_test (comparison (expr (atom (name node)))))))) ))))))) (comp_for for (exprlist (expr (atom (name child)))) in (logical_test (comparison (expr (atom (name children)))))))}))->sum() + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def search(tree,root,parent): children=tree[root].copy() if parent!=0 : del children[children.index(parent)] if len(children)<=1 : return 1 firstlarge=0 secondlarge=0 for child in children : result=search(tree,child,root) if result>firstlarge : secondlarge=firstlarge firstlarge=result elif result>secondlarge : secondlarge=result return firstlarge+secondlarge+1 fin=open('B-large.in','r') fout=open('out.txt','w') t=int(fin.readline()) for casecount in range(1,t+1): n=int(fin.readline()) tree=[[]for x in range(0,n+1)] for i in range(0,n-1): xi,yi=map(int,fin.readline().split()) tree[xi].append(yi) tree[yi].append(xi) result=0 for i in range(1,n+1): temp=search(tree,i,0) if temp>result : result=temp fout.write('Case #%d: %d\n' %(casecount,n-result)) fin.close() fout.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var fin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('B-large.in')) ; var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('out.txt')) ; var t : int := ("" + ((fin.readLine())))->toInteger() ; for casecount : Integer.subrange(1, t + 1-1) do ( var n : int := ("" + ((fin.readLine())))->toInteger() ; tree := Integer.subrange(0, n + 1-1)->select(x | true)->collect(x | (Sequence{})) ; for i : Integer.subrange(0, n - 1-1) do ( var xi : OclAny := null; var yi : OclAny := null; Sequence{xi,yi} := (fin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name tree)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name xi)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name yi)))))))) )))) ; (expr (atom (name tree)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name yi)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name xi)))))))) ))))) ; result := 0 ; for i : Integer.subrange(1, n + 1-1) do ( var temp : OclAny := search(tree, i, 0) ; if (temp->compareTo(result)) > 0 then ( result := temp ) else skip) ; fout.write(StringLib.format('Case #%d: %d ',Sequence{casecount, n - result}))) ; fin.closeFile() ; fout.closeFile(); operation search(tree : OclAny, root : OclAny, parent : OclAny) : OclAny pre: true post: true activity: var children : OclAny := tree[root+1]->copy() ; if parent /= 0 then ( execute (children[children->indexOf(parent) - 1+1])->isDeleted() ) else skip ; if (children)->size() <= 1 then ( return 1 ) else skip ; var firstlarge : int := 0 ; var secondlarge : int := 0 ; for child : children do ( var result : OclAny := search(tree, child, root) ; if (result->compareTo(firstlarge)) > 0 then ( secondlarge := firstlarge ; firstlarge := result ) else (if (result->compareTo(secondlarge)) > 0 then ( secondlarge := result ) else skip)) ; return firstlarge + secondlarge + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque T=int(input()) for case in range(1,T+1): N=int(input()) edges=[tuple(int(i)-1 for i in input().split())for i in range(N-1)] neigh=[[]for i in range(N)] for i,j in edges : neigh[i].append(j) neigh[j].append(i) ans=N for root in range(N): parent=[None for i in range(N)] children=[[]for i in range(N)] queue=deque([root]) order=[root] while queue : cur=queue.popleft() for i in neigh[cur]: if parent[i]==None and i!=root : parent[i]=cur children[cur].append(i) queue.append(i) order.append(i) order=list(reversed(order)) size=[None for i in range(N)] cost=[None for i in range(N)] for i in order : c=children[i] d=len(c) size[i]=sum(size[j]for j in c)+1 if d==0 : cost[i]=0 elif d==1 : cost[i]=size[c[0]] elif d==2 : cost[i]=cost[c[0]]+cost[c[1]] else : cost[i]=size[i]-1-sum(sorted(size[j]-cost[j]for j in c)[-2 :]) ans=min(ans,cost[root]) print("Case #{}:{}".format(case,ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for case : Integer.subrange(1, T + 1-1) do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var edges : Sequence := Integer.subrange(0, N - 1-1)->select(i | true)->collect(i | (((argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) - (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))))) ; var neigh : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{})) ; for _tuple : edges do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); (expr (atom (name neigh)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) ; (expr (atom (name neigh)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var ans : int := N ; for root : Integer.subrange(0, N-1) do ( var parent : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (null)) ; var children : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{})) ; var queue : Sequence := (Sequence{ root }) ; var order : Sequence := Sequence{ root } ; while queue do ( var cur : OclAny := queue->first() ; queue := queue->tail() ; for i : neigh[cur+1] do ( if parent[i+1] = null & i /= root then ( parent[i+1] := cur ; (expr (atom (name children)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name cur)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ; execute ((i) : queue) ; execute ((i) : order) ) else skip)) ; order := ((order)->reverse()) ; var size : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (null)) ; var cost : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (null)) ; for i : order do ( var c : OclAny := children[i+1] ; var d : int := (c)->size() ; size[i+1] := ((argument (test (logical_test (comparison (expr (atom (name size)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name c))))))))->sum() + 1 ; if d = 0 then ( cost[i+1] := 0 ) else (if d = 1 then ( cost[i+1] := size[c->first()+1] ) else (if d = 2 then ( cost[i+1] := cost[c->first()+1] + cost[c[1+1]+1] ) else ( cost[i+1] := size[i+1] - 1 - (sorted((argument (test (logical_test (comparison (expr (expr (atom (name size)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))) - (expr (atom (name cost)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name c)))))))).subrange(-2+1))->sum() ) ) ) ) ; ans := Set{ans, cost[root+1]}->min()) ; execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{case, ans}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10000) parents=[] edgecopy=[] def DP(node): childsizes=[] aScores=[] for child in edges[node]: if child==parents[node]: continue parents[child]=node ; size,score=DP(child) childsizes.append(size) aScores.append(size-score) totalsize=sum(childsizes)+1 if len(childsizes)<2 : return(totalsize,totalsize-1) else : aScores.sort() return(totalsize,totalsize-1-aScores[-1]-aScores[-2]) T=int(input()) for case in range(1,T+1): N=int(input()) edges=[[]for i in range(N)] for e in range(N-1): x,y=(int(x)for x in input().split()) edges[x-1].append(y-1) edges[y-1].append(x-1) ans=N for root in range(N): edgecopy[:]=[edges[x][:]for x in range(N)] parents[:]=[-1]*N parents[root]=root (size,score)=DP(root) ans=min(ans,score) print("Case #",case,": ",ans,sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(10000) ; var parents : Sequence := Sequence{} ; var edgecopy : Sequence := Sequence{} ; skip ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for case : Integer.subrange(1, T + 1-1) do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var edges : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{})) ; for e : Integer.subrange(0, N - 1-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ))))) ; var ans : int := N ; for root : Integer.subrange(0, N-1) do ( edgecopy := Integer.subrange(0, N-1)->select(x | true)->collect(x | (edges[x+1])) ; parents := MatrixLib.elementwiseMult(Sequence{ -1 }, N) ; parents[root+1] := root)) ; var Sequence{size, score} : OclAny := DP(root); operation DP(node : OclAny) : OclAny pre: true post: true activity: var childsizes : Sequence := Sequence{} ; var aScores : Sequence := Sequence{} ; for child : edges[node+1] do ( if child = parents[node+1] then ( continue ) else skip ; parents[child+1] := node; ; var size : OclAny := null; var score : OclAny := null; Sequence{size,score} := DP(child) ; execute ((size) : childsizes) ; execute ((size - score) : aScores)) ; var totalsize : OclAny := (childsizes)->sum() + 1 ; if (childsizes)->size() < 2 then ( return Sequence{totalsize, totalsize - 1} ) else ( aScores := aScores->sort() ; return Sequence{totalsize, totalsize - 1 - aScores->last() - aScores->front()->last()} ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def rl(t): return[t(_)for _ in input().split()] def solve(n,edges): e=[[]for i in range(n)] for a,b in edges : e[a-1].append(b-1) e[b-1].append(a-1) def f(i,p): childs=[j for j in e[i]if j!=p] if len(childs)<2 : res=1 else : d=[f(j,i)for j in childs] d.sort(reverse=True) res=d[0]+d[1]+1 return res ds=[f(root,-1)for root in range(n)] return n-max(ds) def main(): T,*_=rl(int) for C in range(1,T+1): n,*_=rl(int) edges=[] for i in range(n-1): a,b=rl(int) edges.append((a,b)) answer=solve(n,edges) print('Case #%d:' % C,answer) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation rl(t : OclAny) : OclAny pre: true post: true activity: return input().split()->select(_anon | true)->collect(_anon | (t(_anon))); operation solve(n : OclAny, edges : OclAny) : OclAny pre: true post: true activity: var e : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for _tuple : edges do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); (expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ))))) ; skip ; var ds : Sequence := Integer.subrange(0, n-1)->select(root | true)->collect(root | (f(root, -1))) ; return n - (ds)->max(); operation main() pre: true post: true activity: var T : OclAny := null; var _anon : OclAny := null; Sequence{T,_anon} := rl(OclType["int"]) ; for C : Integer.subrange(1, T + 1-1) do ( var _anon : OclAny := null; Sequence{n,_anon} := rl(OclType["int"]) ; edges := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := rl(OclType["int"]) ; execute ((Sequence{a, b}) : edges)) ; var answer : OclAny := solve(n, edges) ; execute (StringLib.format('Case #%d:',C))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printArr(arr,n): for i in range(n): print(arr[i],end=" ") def replaceMax(arr,n): max_element=max(arr) min_element=min(arr) ranges=max_element-min_element coeffOfRange=ranges/(max_element+min_element) for i in range(n): if(arr[i]==max_element): arr[i]=coeffOfRange break printArr(arr,n) if __name__=="__main__" : arr=[15,16,10,9,6,7,17] n=len(arr) replaceMax(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{15}->union(Sequence{16}->union(Sequence{10}->union(Sequence{9}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 17 })))))) ; n := (arr)->size() ; replaceMax(arr, n) ) else skip; operation printArr(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); operation replaceMax(arr : OclAny, n : OclAny) pre: true post: true activity: var max_element : OclAny := (arr)->max() ; var min_element : OclAny := (arr)->min() ; var ranges : double := max_element - min_element ; var coeffOfRange : double := ranges / (max_element + min_element) ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] = max_element) then ( arr[i+1] := coeffOfRange ; break ) else skip) ; printArr(arr, n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M,L=map(int,input().split()) tbl=[[]for i in range(45)] for i in range(M): d,a,k,t=map(int,input().split()) tbl[d*N+a-1].append((k,t)) dp=[[0 for i in range(45)]for j in range(45)] for da in range(5*N): for i in range(L+1): if icollect( _x | (OclType["int"])->apply(_x) ) ; var tbl : Sequence := Integer.subrange(0, 45-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, M-1) do ( var d : OclAny := null; var a : OclAny := null; var k : OclAny := null; var t : OclAny := null; Sequence{d,a,k,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name tbl)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (expr (atom (name d))) * (expr (atom (name N)))) + (expr (atom (name a)))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name k)))))) , (test (logical_test (comparison (expr (atom (name t))))))) )))))))) ))))) ; var dp : Sequence := Integer.subrange(0, 45-1)->select(j | true)->collect(j | (Integer.subrange(0, 45-1)->select(i | true)->collect(i | (0)))) ; for da : Integer.subrange(0, 5 * N-1) do ( for i : Integer.subrange(0, L + 1-1) do ( if (i->compareTo(L)) < 0 then ( for _tuple : tbl[da+1] do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); dp[da + k+1][i + 1+1] := Set{dp[da + k+1][i + 1+1], dp[da+1][i+1] + t}->max()) ) else skip ; dp[da + 1+1][i+1] := Set{dp[da + 1+1][i+1], dp[da+1][i+1]}->max())) ; execute (dp[5 * N+1][L+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) a.sort() for i in range(n): print(a[i],a[n+i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; for i : Integer.subrange(0, n-1) do ( execute (a[i+1])->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def MinSum(a,n): gcd=a[0] for i in range(1,n): gcd=math.gcd(a[i],gcd) return n*gcd if __name__=="__main__" : a=[20,14,6,8,15] n=len(a) print(MinSum(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( a := Sequence{20}->union(Sequence{14}->union(Sequence{6}->union(Sequence{8}->union(Sequence{ 15 })))) ; n := (a)->size() ; execute (MinSum(a, n))->display() ) else skip; operation MinSum(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var gcd : OclAny := a->first() ; for i : Integer.subrange(1, n-1) do ( gcd := (a[i+1])->gcd(gcd)) ; return n * gcd; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) a.sort() for i in range(n): print(a[i],a[n+i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; for i : Integer.subrange(0, n-1) do ( execute (a[i+1])->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=sorted(map(int,input().split())) ans=[str(a[i])+" "+str(a[n+i])for i in range(n)] print(" ".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var ans : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + ((a[i+1]))) + " " + ("" + ((a[n + i+1]))))) ; execute (StringLib.sumStringsWithSeparator((ans), " "))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) a.sort() for i in range(n*2): print(a[n*(i % 2)+i//2],end=' ') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; for i : Integer.subrange(0, n * 2-1) do ( execute (a[n * (i mod 2) + i div 2+1])->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=sorted(map(int,input().split())) res=[] for i in range(n): res.append(a[i]) res.append(a[2*n-1-i]) print(*res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var res : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((a[i+1]) : res) ; execute ((a[2 * n - 1 - i+1]) : res)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() nStrSum=0 for i in range(len(n)): nStrSum+=int(n[i]) print("Yes" if int(n)% nStrSum==0 else "No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var nStrSum : int := 0 ; for i : Integer.subrange(0, (n)->size()-1) do ( nStrSum := nStrSum + ("" + ((n[i+1])))->toInteger()) ; execute (if ("" + ((n)))->toInteger() mod nStrSum = 0 then "Yes" else "No" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def answer(n : int)->str : temp=n sum_of_digits=0 while 0toInteger() ; execute (answer(n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) wals=list(str(N)) wals=[int(s)for s in wals] wa=sum(wals) if N % wa==0 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var wals : Sequence := (("" + ((N))))->characters() ; wals := wals->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; var wa : OclAny := (wals)->sum() ; if N mod wa = 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=input() n=int(num) div=[int(i)for i in list(num)] if n % sum(div): print("No") else : print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : String := (OclFile["System.in"]).readLine() ; var n : int := ("" + ((num)))->toInteger() ; var div : Sequence := (num)->characters()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if n mod (div)->sum() then ( execute ("No")->display() ) else ( execute ("Yes")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import product n,m,l=map(int,input().split()) subjects=[[]for _ in range(5)] for _ in range(m): d,a,k,t=map(int,input().split()) subjects[d].append((a,a+k-1,t)) for i in range(5): subjects[i].sort(key=lambda x : x[1]) def calcDp(i): dp=[[0]*(n+1)for _ in range(n+1)] sub=subjects[i] for init,end,value in sub : for y in range(n): new_score=dp[y][init-1]+value for x in range(end,n+1): dp[y+1][x]=max(dp[y+1][x],new_score) ret=[] for i in range(n+1): ret.append(max(dp[i])) return ret lst=[calcDp(i)for i in range(5)] ans=0 for t in product(range(n+1),repeat=5): if sum(t)>l : continue score=0 for i,v in enumerate(t): score+=lst[i][v] ans=max(score,ans) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; var l : OclAny := null; Sequence{n,m,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var subjects : Sequence := Integer.subrange(0, 5-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, m-1) do ( var d : OclAny := null; var a : OclAny := null; var k : OclAny := null; var t : OclAny := null; Sequence{d,a,k,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name subjects)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name d)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (expr (expr (atom (name a))) + (expr (atom (name k)))) - (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (atom (name t))))))) )))))))) ))))) ; for i : Integer.subrange(0, 5-1) do ((expr (atom (name subjects)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name sort) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))))) ))))) ; skip ; var lst : Sequence := Integer.subrange(0, 5-1)->select(i | true)->collect(i | (calcDp(i))) ; var ans : int := 0 ; for t : product(Integer.subrange(0, n + 1-1), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (number (integer 5))))))))) do ( if ((t)->sum()->compareTo(l)) > 0 then ( continue ) else skip ; var score : int := 0 ; for _tuple : Integer.subrange(1, (t)->size())->collect( _indx | Sequence{_indx-1, (t)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); score := score + lst[i+1][v+1]) ; ans := Set{score, ans}->max()) ; execute (ans)->display(); operation calcDp(i : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)))) ; var sub : OclAny := subjects[i+1] ; for _tuple : sub do (var _indx : int := 1; var init : OclAny := _tuple->at(_indx); _indx := _indx + 1; var end : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); for y : Integer.subrange(0, n-1) do ( var new_score : OclAny := dp[y+1][init - 1+1] + value ; for x : Integer.subrange(end, n + 1-1) do ( dp[y + 1+1][x+1] := Set{dp[y + 1+1][x+1], new_score}->max()))) ; var ret : Sequence := Sequence{} ; for i : Integer.subrange(0, n + 1-1) do ( execute (((dp[i+1])->max()) : ret)) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input(); print('Yes' if int(n)% sum(int(n[i])for i in range(len(n)))==0 else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine(); execute (if ("" + ((n)))->toInteger() mod ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))) )))))))))->sum() = 0 then 'Yes' else 'No' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() if n[0]==n[-1]: print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; if n->first() = n->last() then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def mergeIntervals(arr): arr.sort(key=lambda x : x[0]) m=[] s=-10000 max=-100000 for i in range(len(arr)): a=arr[i] if a[0]>max : if i!=0 : m.append([s,max]) max=a[1] s=a[0] else : if a[1]>=max : max=a[1] if max!=-100000 and[s,max]not in m : m.append([s,max]) print("The Merged Intervals are :",end=" ") for i in range(len(m)): print(m[i],end=" ") arr=[[6,8],[1,9],[2,4],[4,7]] mergeIntervals(arr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{Sequence{6}->union(Sequence{ 8 })}->union(Sequence{Sequence{1}->union(Sequence{ 9 })}->union(Sequence{Sequence{2}->union(Sequence{ 4 })}->union(Sequence{ Sequence{4}->union(Sequence{ 7 }) }))) ; mergeIntervals(arr); operation mergeIntervals(arr : OclAny) pre: true post: true activity: arr := arr->sort() ; var m : Sequence := Sequence{} ; var s : int := -10000 ; var max : int := -100000 ; for i : Integer.subrange(0, (arr)->size()-1) do ( var a : OclAny := arr[i+1] ; if (a->first()->compareTo(max)) > 0 then ( if i /= 0 then ( execute ((Sequence{s}->union(Sequence{ max })) : m) ) else skip ; max := a[1+1] ; s := a->first() ) else ( if (a[1+1]->compareTo(max)) >= 0 then ( max := a[1+1] ) else skip )) ; if max /= -100000 & (m)->excludes(Sequence{s}->union(Sequence{ max })) then ( execute ((Sequence{s}->union(Sequence{ max })) : m) ) else skip ; execute ("The Merged Intervals are :")->display() ; for i : Integer.subrange(0, (m)->size()-1) do ( execute (m[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=list(input()) print('Yes' if n==list(reversed(n))else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : Sequence := ((OclFile["System.in"]).readLine())->characters() ; execute (if n = ((n)->reverse()) then 'Yes' else 'No' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=str(input()) ans="Yes" for i in range(len(N)//2): if N[i]!=N[len(N)-i-1]: ans="No" break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : String := ("" + (((OclFile["System.in"]).readLine()))) ; var ans : String := "Yes" ; for i : Integer.subrange(0, (N)->size() div 2-1) do ( if N[i+1] /= N[(N)->size() - i - 1+1] then ( ans := "No" ; break ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() print('Yes' if n==n[: :-1]else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; execute (if n = n(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then 'Yes' else 'No' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=input() if N=="".join(N[: :-1]): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : String := (OclFile["System.in"]).readLine() ; if N = StringLib.sumStringsWithSeparator((N(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))), "") then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printCount(a,n,m,z,l): for i in range(n): mp=dict() for j in range(m): mp[a[i][j]]=1 count=0 for j in range(l): if z[j]in mp.keys(): count+=1 print("row",i+1,"=",count) a=[[8,27,39,589,23],[23,34,589,12,45],[939,32,27,12,78],[23,349,48,21,32]] arr=[589,39,27] n=len(a) m=5 l=len(arr) printCount(a,n,m,arr,l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{Sequence{8}->union(Sequence{27}->union(Sequence{39}->union(Sequence{589}->union(Sequence{ 23 }))))}->union(Sequence{Sequence{23}->union(Sequence{34}->union(Sequence{589}->union(Sequence{12}->union(Sequence{ 45 }))))}->union(Sequence{Sequence{939}->union(Sequence{32}->union(Sequence{27}->union(Sequence{12}->union(Sequence{ 78 }))))}->union(Sequence{ Sequence{23}->union(Sequence{349}->union(Sequence{48}->union(Sequence{21}->union(Sequence{ 32 })))) }))) ; var arr : Sequence := Sequence{589}->union(Sequence{39}->union(Sequence{ 27 })) ; n := (a)->size() ; m := 5 ; l := (arr)->size() ; printCount(a, n, m, arr, l); operation printCount(a : OclAny, n : OclAny, m : OclAny, z : OclAny, l : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( var mp : Map := (arguments ( )) ; for j : Integer.subrange(0, m-1) do ( mp[a[i+1][j+1]+1] := 1) ; var count : int := 0 ; for j : Integer.subrange(0, l-1) do ( if (mp.keys())->includes(z[j+1]) then ( count := count + 1 ) else skip) ; execute ("row")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R,C,N=map(int,input().split()) edge=[] def F(x,y): if x==0 : return y if y==C : return C+x if x==R : return R+C*2-y if y==0 : return 2*R+2*C-x return-1 for i in range(1,N+1): x1,y1,x2,y2=map(int,input().split()) d1=F(x1,y1) d2=F(x2,y2) if d1<0 : continue if d2<0 : continue edge.append((d1,i)) edge.append((d2,i)) edge.sort() stack=[] used=[False]*(N+1) ans="YES" for _,x in edge : if not used[x]: used[x]=True stack.append(x) else : y=stack.pop() if x!=y : ans="NO" break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : OclAny := null; var C : OclAny := null; var N : OclAny := null; Sequence{R,C,N} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var edge : Sequence := Sequence{} ; skip ; for i : Integer.subrange(1, N + 1-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d1 : OclAny := F(x1, y1) ; var d2 : OclAny := F(x2, y2) ; if d1 < 0 then ( continue ) else skip ; if d2 < 0 then ( continue ) else skip ; execute ((Sequence{d1, i}) : edge) ; execute ((Sequence{d2, i}) : edge)) ; edge := edge->sort() ; var stack : Sequence := Sequence{} ; var used : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (N + 1)) ; var ans : String := "YES" ; for _tuple : edge do (var _indx : int := 1; var _anon : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); if not(used[x+1]) then ( used[x+1] := true ; execute ((x) : stack) ) else ( y := stack->last() ; stack := stack->front() ; if x /= y then ( ans := "NO" ; break ) else skip )) ; execute (ans)->display(); operation F(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if x = 0 then ( return y ) else skip ; if y = C then ( return C + x ) else skip ; if x = R then ( return R + C * 2 - y ) else skip ; if y = 0 then ( return 2 * R + 2 * C - x ) else skip ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import defaultdict def read_int_list(): return list(map(int,input().split())) def read_int(): return int(input()) def read_str_list(): return input().split() def read_str(): return input() def pos(X,Y): if Y==0 : return X if X==r : return r+Y if Y==c : return r+c+r-X if X==0 : return r+c+r+c-Y r,c,n,=read_int_list() x=[0,0] y=[0,0] a=[] for i in range(n): x[0],y[0],x[1],y[1]=read_int_list() if(x[0]in[0,r]or y[0]in[0,c])and(x[1]in[0,r]or y[1]in[0,c]): for k in range(2): a.append((pos(x[k],y[k]),i)) m=len(a)//2 a.sort() res='YES' started=set() s=[] for p,i in a : if i not in started : started.add(i) s.append(i) else : if s[-1]!=i : res='NO' break s.pop() print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var r : OclAny := null; var c : OclAny := null; (declareIfNecessary (test (logical_test (comparison (expr (atom (name n)))))) ,) Sequence{r,c,(testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,)} := read_int_list() ; var x : Sequence := Sequence{0}->union(Sequence{ 0 }) ; var y : Sequence := Sequence{0}->union(Sequence{ 0 }) ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x->first() : OclAny := null; var y->first() : OclAny := null; var x[1+1] : OclAny := null; var y[1+1] : OclAny := null; Sequence{x->first(),y->first(),x[1+1],y[1+1]} := read_int_list() ; if ((Sequence{0}->union(Sequence{ r }))->includes(x->first()) or (Sequence{0}->union(Sequence{ c }))->includes(y->first())) & ((Sequence{0}->union(Sequence{ r }))->includes(x[1+1]) or (Sequence{0}->union(Sequence{ c }))->includes(y[1+1])) then ( for k : Integer.subrange(0, 2-1) do ( execute ((Sequence{pos(x[k+1], y[k+1]), i}) : a)) ) else skip) ; var m : int := (a)->size() div 2 ; a := a->sort() ; var res : String := 'YES' ; var started : Set := Set{}->union(()) ; var s : Sequence := Sequence{} ; for _tuple : a do (var _indx : int := 1; var p : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); if (started)->excludes(i) then ( execute ((i) : started) ; execute ((i) : s) ) else ( if s->last() /= i then ( res := 'NO' ; break ) else skip ; s := s->front() )) ; execute (res)->display(); operation read_int_list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation read_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation read_str_list() : OclAny pre: true post: true activity: return input().split(); operation read_str() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pos(X : OclAny, Y : OclAny) : OclAny pre: true post: true activity: if Y = 0 then ( return X ) else skip ; if X = r then ( return r + Y ) else skip ; if Y = c then ( return r + c + r - X ) else skip ; if X = 0 then ( return r + c + r + c - Y ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input()+'T' x,y=[int(i)for i in input().split()] dire=True xi=[] yi=[] ctr=0 for i in range(len(s)): if s[i]=='F' : ctr+=1 continue if dire : xi.append(ctr) else : yi.append(ctr) ctr=0 dire=not dire ans='Yes' X=(sum(xi)-x)//2 x0=xi.pop(0) Hx={0 : True} for i in xi : for j in Hx.copy().keys(): Hx[j+i]=True Y=(sum(yi)-y)//2 Hy={0 : True} for i in yi : for j in Hy.copy().keys(): Hy[j+i]=True if(x0+sum(xi)-x)% 2!=0 or(sum(yi)-y)% 2!=0 : ans='No' if not Hx.get(X,False)or not Hy.get(Y,False): ans='No' print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() + 'T' ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var dire : boolean := true ; var xi : Sequence := Sequence{} ; var yi : Sequence := Sequence{} ; var ctr : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = 'F' then ( ctr := ctr + 1 ; continue ) else skip ; if dire then ( execute ((ctr) : xi) ) else ( execute ((ctr) : yi) ) ; ctr := 0 ; dire := not(dire)) ; var ans : String := 'Yes' ; var X : int := ((xi)->sum() - x) div 2 ; var x0 : OclAny := xi->at(0`firstArg+1) ; xi := xi->excludingAt(0+1) ; var Hx : Map := Map{ 0 |-> true } ; for i : xi do ( for j : Hx->copy().keys() do ( Hx[j + i+1] := true)) ; var Y : int := ((yi)->sum() - y) div 2 ; var Hy : Map := Map{ 0 |-> true } ; for i : yi do ( for j : Hy->copy().keys() do ( Hy[j + i+1] := true)) ; if (x0 + (xi)->sum() - x) mod 2 /= 0 or ((yi)->sum() - y) mod 2 /= 0 then ( ans := 'No' ) else skip ; if not(Hx.get(X, false)) or not(Hy.get(Y, false)) then ( ans := 'No' ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import exit,setrecursionlimit,stderr from functools import reduce from itertools import* from collections import* from bisect import* def read(): return int(input()) def reads(): return[int(x)for x in input().split()] R,C,N=reads() def edge(x,y): return x==0 or x==R or y==0 or y==C def flat(x,y): assert edge(x,y) if y==0 : return x elif x==R : return R+y elif y==C : return R+C+(R-x) else : assert x==0 return 2*R+C+(C-y) ps=[] for i in range(N): x1,y1,x2,y2=reads() if edge(x1,y1)and edge(x2,y2): ps.append((flat(x1,y1),i)) ps.append((flat(x2,y2),i)) ps.sort() stack=[] for _,i in ps : if len(stack)>0 and stack[-1]==i : stack.pop() else : stack.append(i) print("YES" if len(stack)==0 else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var R : OclAny := null; var C : OclAny := null; var N : OclAny := null; Sequence{R,C,N} := reads() ; skip ; skip ; var ps : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := reads() ; if edge(x1, y1) & edge(x2, y2) then ( execute ((Sequence{flat(x1, y1), i}) : ps) ; execute ((Sequence{flat(x2, y2), i}) : ps) ) else skip) ; ps := ps->sort() ; var stack : Sequence := Sequence{} ; for _tuple : ps do (var _indx : int := 1; var _anon : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); if (stack)->size() > 0 & stack->last() = i then ( stack := stack->front() ) else ( execute ((i) : stack) )) ; execute (if (stack)->size() = 0 then "YES" else "NO" endif)->display(); operation read() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation reads() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation edge(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return x = 0 or x = R or y = 0 or y = C; operation flat(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: assert edge(x, y) do "assertion failed" ; if y = 0 then ( return x ) else (if x = R then ( return R + y ) else (if y = C then ( return R + C + (R - x) ) else ( assert x = 0 do "assertion failed" ; return 2 * R + C + (C - y) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def add(bound,r,c,x,y,i): if x==0 : bound.append((0,y,i)) elif y==c : bound.append((1,x,i)) elif x==r : bound.append((2,c-y,i)) else : bound.append((3,r-x,i)) def solve(bound): if not bound : return True bound.sort() st=[0]*len(bound) p=-1 for _,_,i in bound : if 0<=p and st[p]==i : p-=1 else : p+=1 st[p]=i return p==-1 def main(): r,c,n=input().split() r=int(r) c=int(c) n=int(n) bound=[] for i in range(n): x1,y1,x2,y2=input().split() x1=int(x1) y1=int(y1) x2=int(x2) y2=int(y2) if(x1 % r==0 or y1 % c==0)and(x2 % r==0 or y2 % c==0): add(bound,r,c,x1,y1,i) add(bound,r,c,x2,y2,i) print('YES' if solve(bound)else 'NO') if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation add(bound : OclAny, r : OclAny, c : OclAny, x : OclAny, y : OclAny, i : OclAny) pre: true post: true activity: if x = 0 then ( execute ((Sequence{0, y, i}) : bound) ) else (if y = c then ( execute ((Sequence{1, x, i}) : bound) ) else (if x = r then ( execute ((Sequence{2, c - y, i}) : bound) ) else ( execute ((Sequence{3, r - x, i}) : bound) ) ) ) ; operation solve(bound : OclAny) : OclAny pre: true post: true activity: if not(bound) then ( return true ) else skip ; bound := bound->sort() ; var st : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (bound)->size()) ; var p : int := -1 ; for _tuple : bound do (var _indx : int := 1; var _anon : OclAny := _tuple->at(_indx); _indx := _indx + 1; var _anon : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); if 0 <= p & st[p+1] = i then ( p := p - 1 ) else ( p := p + 1 ; st[p+1] := i )) ; return p = -1; operation main() pre: true post: true activity: var n : OclAny := null; Sequence{r,c,n} := input().split() ; r := ("" + ((r)))->toInteger() ; c := ("" + ((c)))->toInteger() ; var n : int := ("" + ((n)))->toInteger() ; bound := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := input().split() ; var x1 : int := ("" + ((x1)))->toInteger() ; var y1 : int := ("" + ((y1)))->toInteger() ; var x2 : int := ("" + ((x2)))->toInteger() ; var y2 : int := ("" + ((y2)))->toInteger() ; if (x1 mod r = 0 or y1 mod c = 0) & (x2 mod r = 0 or y2 mod c = 0) then ( add(bound, r, c, x1, y1, i) ; add(bound, r, c, x2, y2, i) ) else skip) ; execute (if solve(bound) then 'YES' else 'NO' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import phase r,c,n=map(int,input().split()) l=list() for i in range(n): w,x,y,z=map(int,input().split()) if(w in(0,r)or x in(0,c))and(y in(0,r)or z in(0,c)): l.append((i,w-r/2+(x-c/2)*1j)) l.append((i,y-r/2+(z-c/2)*1j)) l.sort(key=lambda t : phase(t[1])) p=list() for x,c in l : if p==[]or p[-1]!=x : p.append(x) else : p.pop() ans=["NO","YES"] print(ans[p==[]]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var r : OclAny := null; var c : OclAny := null; var n : OclAny := null; Sequence{r,c,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := () ; for i : Integer.subrange(0, n-1) do ( var w : OclAny := null; var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{w,x,y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if ((Sequence{0, r})->includes(w) or (Sequence{0, c})->includes(x)) & ((Sequence{0, r})->includes(y) or (Sequence{0, c})->includes(z)) then ( execute ((Sequence{i, w - r / 2 + (x - c / 2) * 1j}) : l) ; execute ((Sequence{i, y - r / 2 + (z - c / 2) * 1j}) : l) ) else skip) ; l := l->sort() ; var p : Sequence := () ; for _tuple : l do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if p = Sequence{} or p->last() /= x then ( execute ((x) : p) ) else ( p := p->front() )) ; var ans : Sequence := Sequence{"NO"}->union(Sequence{ "YES" }) ; execute (ans->select(p = Sequence{}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=5 fac1=1 for i in range(2,n): fac1=fac1*i fac2=fac1*n totalWays=fac1*fac2 print(totalWays) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := 5 ; var fac1 : int := 1 ; for i : Integer.subrange(2, n-1) do ( fac1 := fac1 * i) ; var fac2 : int := fac1 * n ; var totalWays : int := fac1 * fac2 ; execute (totalWays)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) print((b+a-1)//a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((b + a - 1) div a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=input().split() A=int(l[0]) B=int(l[1]) kimawasi=B//A if B % A>0 : kimawasi=kimawasi+1 print(kimawasi) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := input().split() ; var A : int := ("" + ((l->first())))->toInteger() ; var B : int := ("" + ((l[1+1])))->toInteger() ; var kimawasi : int := B div A ; if B mod A > 0 then ( kimawasi := kimawasi + 1 ) else skip ; execute (kimawasi)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) if a>=b : print(1) else : if b % a==0 : print(b//a) else : print(b//a+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(b)) >= 0 then ( execute (1)->display() ) else ( if b mod a = 0 then ( execute (b div a)->display() ) else ( execute (b div a + 1)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B=[int(i)for i in input().split()] ans=0 if B % A==0 : ans=B//A else : ans=B//A+1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : int := 0 ; if B mod A = 0 then ( ans := B div A ) else ( ans := B div A + 1 ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a,b=map(int,input().split()) print(math.ceil(b/a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((b / a)->ceil())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import heapq import sys import math import itertools import bisect from io import BytesIO,IOBase import os def valid(i,j,n,m): if i=0 and j>=0 and jcompareTo(n)) < 0 & i >= 0 & j >= 0 & (j->compareTo(m)) < 0 then ( return true ) else skip ; return false; operation sumn(i : OclAny, n : OclAny) : OclAny pre: true post: true activity: return (n - i) * (i + n) / 2; operation sqfun(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: return (-b + (b * b - 4 * a * c)->sqrt()) / 2 * a; operation getprime(num : OclAny) : OclAny pre: true post: true activity: if ((argument (test (logical_test (comparison (comparison (expr (expr (atom (name num))) % (expr (atom (name i))))) != (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name math)) (trailer . (name sqrt) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) ))))))))) )))) + (expr (atom (number (integer 1)))))))))) )))))))))->forAll( _x | _x = true ) then ( return true ) else skip; operation value() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation values() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inlsts() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inps() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation instr() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation stlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (i)); operation solve() pre: true post: true activity: var k : OclAny := null; Sequence{n,k} := values() ; var lst : OclAny := inlsts() ; var tmpsum : OclAny := (lst.subrange(1,k))->sum() ; var ind : int := 0 ; var minsum : OclAny := tmpsum ; for i : Integer.subrange(k, n-1) do ( tmpsum := tmpsum + lst[i+1] ; tmpsum := tmpsum - lst[i - k+1] ; if (tmpsum->compareTo(minsum)) < 0 then ( minsum := tmpsum ; ind := i - k + 1 ) else skip) ; execute (ind + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): s=input() xa,ya=map(int,input().split()) xset=set([0]) yset=set([0]) if "T" not in s : print("Yes" if len(s)==xa and ya==0 else "No") return fcnt=0 tcnt=0 for c in s : if "T"==c : if fcnt>0 : if tcnt % 2==0 : if tcnt==0 : xset=set([x+fcnt for x in xset]) else : xset=set([x+fcnt for x in xset])| set([x-fcnt for x in xset]) else : yset=set([y+fcnt for y in yset])| set([y-fcnt for y in yset]) fcnt=0 tcnt+=1 if "F"==c : fcnt+=1 if fcnt>0 : if tcnt % 2==0 : if tcnt==0 : xset=set([x+fcnt for x in xset]) else : xset=set([x+fcnt for x in xset])| set([x-fcnt for x in xset]) else : yset=set([y+fcnt for y in yset])| set([y-fcnt for y in yset]) print("Yes" if(xa in xset)and(ya in yset)else "No") if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( solve() ) else skip; operation solve() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var xa : OclAny := null; var ya : OclAny := null; Sequence{xa,ya} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var xset : Set := Set{}->union((Sequence{ 0 })) ; var yset : Set := Set{}->union((Sequence{ 0 })) ; if (s)->characters()->excludes("T") then ( execute (if (s)->size() = xa & ya = 0 then "Yes" else "No" endif)->display() ; return ) else skip ; var fcnt : int := 0 ; var tcnt : int := 0 ; for c : s->characters() do ( if "T" = c then ( if fcnt > 0 then ( if tcnt mod 2 = 0 then ( if tcnt = 0 then ( xset := Set{}->union((xset->select(x | true)->collect(x | (x + fcnt)))) ) else ( xset := MathLib.bitwiseOr(Set{}->union((xset->select(x | true)->collect(x | (x + fcnt)))), Set{}->union((xset->select(x | true)->collect(x | (x - fcnt))))) ) ) else ( yset := MathLib.bitwiseOr(Set{}->union((yset->select(y | true)->collect(y | (y + fcnt)))), Set{}->union((yset->select(y | true)->collect(y | (y - fcnt))))) ) ) else skip ; fcnt := 0 ; tcnt := tcnt + 1 ) else skip ; if "F" = c then ( fcnt := fcnt + 1 ) else skip) ; if fcnt > 0 then ( if tcnt mod 2 = 0 then ( if tcnt = 0 then ( xset := Set{}->union((xset->select(x | true)->collect(x | (x + fcnt)))) ) else ( xset := MathLib.bitwiseOr(Set{}->union((xset->select(x | true)->collect(x | (x + fcnt)))), Set{}->union((xset->select(x | true)->collect(x | (x - fcnt))))) ) ) else ( yset := MathLib.bitwiseOr(Set{}->union((yset->select(y | true)->collect(y | (y + fcnt)))), Set{}->union((yset->select(y | true)->collect(y | (y - fcnt))))) ) ) else skip ; execute (if ((xset)->includes(xa)) & ((yset)->includes(ya)) then "Yes" else "No" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- items,hole=[int(x)for x in input().split()] planks=[int(x)for x in input().split()] holder=float('inf') ans=float('inf') if items!=hole : hol=sum([planks[1+x]for x in range(hole)]) for i in range(items-hole+1): new_hold=min(holder,hol) if new_hold=items : break hol=hol-planks[i]+planks[i+hole] else : ans=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var items : OclAny := null; var hole : OclAny := null; Sequence{items,hole} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var planks : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var holder : double := ("" + (('inf')))->toReal() ; var ans : double := ("" + (('inf')))->toReal() ; if items /= hole then ( var hol : OclAny := (Integer.subrange(0, hole-1)->select(x | true)->collect(x | (planks[1 + x+1])))->sum() ; for i : Integer.subrange(0, items - hole + 1-1) do ( var new_hold : OclAny := Set{holder, hol}->min() ; if (new_hold->compareTo(holder)) < 0 then ( holder := new_hold ; ans := i + 1 ) else skip ; if (i + hole->compareTo(items)) >= 0 then ( break ) else skip ; hol := hol - planks[i+1] + planks[i + hole+1]) ) else ( ans := 1 ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin n,k=map(int,input().split()) heights=[int(x)for x in stdin.readline().split()] prefsum=[0]*(n+1) for i in range(1,n+1): prefsum[i]=prefsum[i-1]+heights[i-1] ans=0 minHeight=1e8 for i in range(k,n+1): if prefsum[i]-prefsum[i-k]collect( _x | (OclType["int"])->apply(_x) ) ; var heights : Sequence := stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var prefsum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(1, n + 1-1) do ( prefsum[i+1] := prefsum[i - 1+1] + heights[i - 1+1]) ; var ans : int := 0 ; var minHeight : double := ("1e8")->toReal() ; for i : Integer.subrange(k, n + 1-1) do ( if (prefsum[i+1] - prefsum[i - k+1]->compareTo(minHeight)) < 0 then ( minHeight := prefsum[i+1] - prefsum[i - k+1] ; ans := i - k + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=list(map(int,input().split())) hig=[int(i)for i in input().split()] cum=[hig[0]] for i in range(1,n): cum.append(hig[i]+cum[i-1]) ind=[cum[k-1]] for i in range(1,n): if i==n-k+1 : break ind.append(cum[i+k-1]-cum[i-1]) print(ind.index(min(ind))+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var hig : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var cum : Sequence := Sequence{ hig->first() } ; for i : Integer.subrange(1, n-1) do ( execute ((hig[i+1] + cum[i - 1+1]) : cum)) ; var ind : Sequence := Sequence{ cum[k - 1+1] } ; for i : Integer.subrange(1, n-1) do ( if i = n - k + 1 then ( break ) else skip ; execute ((cum[i + k - 1+1] - cum[i - 1+1]) : ind)) ; execute (ind->indexOf((ind)->min()) - 1 + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from xmlrpc.client import MAXINT a,b=map(int,input().split()) l=[0] ind=0 p=list(map(int,input().split())) l.extend(p) for i in range(1,a+1): l[i]=l[i]+l[i-1] s=MAXINT for h in range(a-b+1): if(l[h+b]-l[h]collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := Sequence{ 0 } ; var ind : int := 0 ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := l->union(p) ; for i : Integer.subrange(1, a + 1-1) do ( l[i+1] := l[i+1] + l[i - 1+1]) ; var s : OclAny := MAXINT ; for h : Integer.subrange(0, a - b + 1-1) do ( if ((l[h + b+1] - l[h+1]->compareTo(s)) < 0) then ( s := l[h + b+1] - l[h+1] ; ind := h + 1 ) else skip) ; execute (ind)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=lambda : map(int,input().split()) n,k=I() a=*I(), m=len({*a}) x=0--max(a.count(x)for x in{*a})//k print(m*x*k-n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := I->apply() ; var a : OclAny := (testlist_star_expr (star_expr * (expr (atom (name I)) (trailer (arguments ( ))))) ,) ; var m : int := (Set{ a })->size() ; var x : double := 0 - -((argument (test (logical_test (comparison (expr (atom (name a)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom { (dictorsetmaker (testlist_comp (star_expr * (expr (atom (name a)))))) })))))))->max() div k ; execute (m * x * k - n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def longest_substring(s,k): n=len(s) if(k>1): s+=s n*=2 ans=0 i=0 while(idisplay(); operation longest_substring(s : OclAny, k : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; if (k > 1) then ( s := s + s ; n := n * 2 ) else skip ; var ans : int := 0 ; var i : int := 0 ; while ((i->compareTo(n)) < 0) do ( var x : int := 0 ; while ((i->compareTo(n)) < 0 & s[i+1] = '0') do ( Sequence{x,i} := Sequence{x + 1,i + 1}) ; ans := Set{ans, x}->max() ; i := i + 1) ; if (k = 1 or ans /= n) then ( return ans ) else ( return (ans div 2) * k ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[] b=[] for i in range(3): a.append(int(input())) a.sort() for j in range(3,5): b.append(int(input())) b.sort() print(a[0]+b[0]-50) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; for i : Integer.subrange(0, 3-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : a) ; a := a->sort()) ; for j : Integer.subrange(3, 5-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : b) ; b := b->sort()) ; execute (a->first() + b->first() - 50)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def main(args): pastas=[int(input())for _ in range(3)] drinks=[int(input())for _ in range(2)] total=min(pastas)+min(drinks)-50 print(total) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation main(args : OclAny) pre: true post: true activity: var pastas : Sequence := Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var drinks : Sequence := Integer.subrange(0, 2-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var total : double := (pastas)->min() + (drinks)->min() - 50 ; execute (total)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math p1=int(input()) p2=int(input()) p3=int(input()) j1=int(input()) j2=int(input()) p_min=min(p1,p2,p3) J_min=min(j1,j2) min_sum=p_min+J_min-50 print(min_sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var p1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p2 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p3 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var j1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var j2 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p_min : OclAny := Set{p1, p2, p3}->min() ; var J_min : OclAny := Set{j1, j2}->min() ; var min_sum : double := p_min + J_min - 50 ; execute (min_sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- pasta=[] juice=[] for i in range(3): a=int(input()) pasta.append(a) for j in range(2): a=int(input()) juice.append(a) pasta.sort() juice.sort() print(pasta[0]+juice[0]-50) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var pasta : Sequence := Sequence{} ; var juice : Sequence := Sequence{} ; for i : Integer.subrange(0, 3-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((a) : pasta)) ; for j : Integer.subrange(0, 2-1) do ( a := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((a) : juice)) ; pasta := pasta->sort() ; juice := juice->sort() ; execute (pasta->first() + juice->first() - 50)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(s,x,y): def update(move): ncx=set() cx=cxy[is_x] for x in cx : ncx.add(x+move) ncx.add(x-move) cxy[is_x]=ncx spl=map(len,s.split('T')) is_x=1 cxy=[{next(spl)},{0}] for l in spl : update(l) is_x ^=1 return x in cxy[0]and y in cxy[1] s=input() x,y=map(int,input().split()) print('Yes' if solve(s,x,y)else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := (OclFile["System.in"]).readLine() ; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if solve(s, x, y) then 'Yes' else 'No' endif)->display(); operation solve(s : OclAny, x : OclAny, y : OclAny) : OclAny pre: true post: true activity: skip ; var spl : Sequence := (s.split('T'))->collect( _x | (len)->apply(_x) ) ; var is_x : int := 1 ; var cxy : Sequence := Sequence{Set{ (spl).next() }}->union(Sequence{ Set{ 0 } }) ; for l : spl do ( update(l) ; is_x := is_x xor 1) ; return (cxy->first())->includes(x) & (cxy[1+1])->includes(y); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): a=int(input()) b=int(input()) c=int(input()) d=int(input()) e=int(input()) ans=-50 if a<=b : if a<=c : ans+=a else : ans+=c else : if b<=c : ans+=b else : ans+=c if d<=e : ans+=d else : ans+=e print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var e : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := -50 ; if (a->compareTo(b)) <= 0 then ( if (a->compareTo(c)) <= 0 then ( ans := ans + a ) else ( ans := ans + c ) ) else ( if (b->compareTo(c)) <= 0 then ( ans := ans + b ) else ( ans := ans + c ) ) ; if (d->compareTo(e)) <= 0 then ( ans := ans + d ) else ( ans := ans + e ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.stdin=open("data.txt") sys.stdout=open("out.txt","w") input=sys.stdin.readline for case in range(int(input())): k,c,s=map(int,input().split()) if c*stoInteger()-1) do ( var k : OclAny := null; var c : OclAny := null; var s : OclAny := null; Sequence{k,c,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (c * s->compareTo(k)) < 0 then ( execute (StringLib.format("Case #%s: IMPOSSIBLE",(case + 1)))->display() ) else ( var check : Sequence := Sequence{} ; var num : int := 0 ; var carry : int := 0 ; for i : Integer.subrange(0, k-1) do ( num := num * k ; num := num + i ; carry := carry + 1 ; if carry = c then ( execute ((num + 1) : check) ; carry := 0 ; num := 0 ) else skip) ; if carry then ( execute ((num + 1) : check) ) else skip ; execute (StringLib.format("Case #%s: %s",Sequence{case + 1, StringLib.sumStringsWithSeparator(((check)->collect( _x | (OclType["String"])->apply(_x) )), " ")}))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- filename="D-large" fin=open(filename+".in","r") fout=open(filename+".out","w") casenum=int(fin.readline()) for ite in range(casenum): in_list=fin.readline().split() K=int(in_list[0]) C=int(in_list[1]) S=int(in_list[2]) Smin=(K-1)//C+1 if S<(K-1)//C+1 : return_str="IMPOSSIBLE" else : return_str='' for jte in range(Smin-1): next_num=0 for kte in range(C): next_num*=K next_num+=kte+C*jte return_str+=str(next_num+1)+' ' next_num=0 for kte in range(K-C,K): next_num*=K if kte>=0 : next_num+=kte return_str+=str(next_num+1) fout.write("Case #{0}:{1}\n".format(ite+1,return_str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var filename : String := "D-large" ; var fin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(filename + ".in")) ; var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(filename + ".out")) ; var casenum : int := ("" + ((fin.readLine())))->toInteger() ; for ite : Integer.subrange(0, casenum-1) do ( var in_list : OclAny := fin.readLine().split() ; var K : int := ("" + ((in_list->first())))->toInteger() ; var C : int := ("" + ((in_list[1+1])))->toInteger() ; var S : int := ("" + ((in_list[2+1])))->toInteger() ; var Smin : int := (K - 1) div C + 1 ; if (S->compareTo((K - 1) div C + 1)) < 0 then ( var return_str : String := "IMPOSSIBLE" ) else ( return_str := '' ; for jte : Integer.subrange(0, Smin - 1-1) do ( var next_num : int := 0 ; for kte : Integer.subrange(0, C-1) do ( next_num := next_num * K ; next_num := next_num + kte + C * jte) ; return_str := return_str + ("" + ((next_num + 1))) + ' ') ; next_num := 0 ; for kte : Integer.subrange(K - C, K-1) do ( next_num := next_num * K ; if kte >= 0 then ( next_num := next_num + kte ) else skip) ; return_str := return_str + ("" + ((next_num + 1))) ) ; fout.write(StringLib.interpolateStrings("Case #{0}:{1}\n", Sequence{ite + 1, return_str}))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,inspect problemName='fractiles' runOnRealData=True def solution(K,C,S): necessaryTiles=(K+C-1)/C if StoInteger() ; for case : xrange(1, numberOfCases + 1) do (suite)) catch (_e : OclException) do skip ; Sequence{K}->union(Sequence{C}->union(Sequence{ S })) := (inputfile.readLine().split(' '))->collect( _x | (OclType["int"])->apply(_x) ); operation solution(K : OclAny, C : OclAny, S : OclAny) : OclAny pre: true post: true activity: var necessaryTiles : double := (K + C - 1) / C ; if (S->compareTo(necessaryTiles)) < 0 then ( return Sequence{ 'IMPOSSIBLE' } ) else skip ; var result : Sequence := Sequence{} ; var k : int := 0 ; var level : int := 0 ; var tile : int := 0 ; while ((result)->size()->compareTo(necessaryTiles)) < 0 do ( tile := (tile * K) + Set{k, K - 1}->min() ; level := level + 1 ; k := k + 1 ; if level = C then ( execute ((tile + 1) : result) ; level := 0 ; tile := 0 ) else skip) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys def findsol(K,C,S): if C*S=K): x=K-1 flag=1 tmp.append(x) tmp2=0 for jj in tmp : tmp2=K*tmp2+jj a.append(tmp2+1) if(flag==1): break return a def convertnums(s): a=[] ii=0 for jj in range(len(s)): if s[jj]==' ' : if(iitoInteger() ; for ii : Integer.subrange(1, T + 1-1) do ( tmp := fidi.readLine() ; tmp := convertnums(tmp) ; K := ("" + ((tmp->first())))->toInteger() ; C := ("" + ((tmp[1+1])))->toInteger() ; S := ("" + ((tmp[2+1])))->toInteger() ; a := findsol(K, C, S) ; if (a->first() = 'I') then ( fido.write('Case #' + ("" + ((ii))) + ': '->union(a) + ' ') ; execute ('Case #' + ("" + ((ii))) + ': '->union(a))->display() ) else ( fido.write('Case #' + ("" + ((ii))) + ': ') ; for jj : a do ( fido.write(("" + ((jj))) + ' ')) ; fido.write(' ') ; execute ('Case #' + ("" + ((ii))) + ': ')->display() )) ; fidi.closeFile() ; fido.closeFile(); operation findsol(K : OclAny, C : OclAny, S : OclAny) : OclAny pre: true post: true activity: if (C * S->compareTo(K)) < 0 then ( return 'IMPOSSIBLE' ) else skip ; var a : Sequence := Sequence{} ; var flag : int := 0 ; for ii : Integer.subrange(0, S-1) do ( var tmp : Sequence := Sequence{} ; for jj : Integer.subrange(0, C-1) do ( var x : double := ii * C + jj ; if ((x->compareTo(K)) >= 0) then ( x := K - 1 ; flag := 1 ) else skip ; execute ((x) : tmp)) ; var tmp2 : int := 0 ; for jj : tmp do ( tmp2 := K * tmp2 + jj) ; execute ((tmp2 + 1) : a) ; if (flag = 1) then ( break ) else skip) ; return a; operation convertnums(s : OclAny) : OclAny pre: true post: true activity: a := Sequence{} ; var ii : int := 0 ; for jj : Integer.subrange(0, (s)->size()-1) do ( if s[jj+1] = ' ' then ( if ((ii->compareTo(jj)) < 0) then ( execute ((("" + ((s.subrange(ii+1, jj))))->toReal()) : a) ; ii := jj + 1 ) else skip ) else skip) ; execute ((("" + ((s.subrange(ii+1, jj))))->toReal()) : a) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math def prework(argv): return "nothing" def base_conv(i_list,from_base): s=0 for i in reversed(i_list): s*=from_base s+=i return s def once(): [k,c,s]=[int(x)for x in input().split()] if s=k : break l.append(ic+j) printerr(l) ans_list.append(base_conv(l,k)) return " ".join(str(x+1)for x in ans_list) def printerr(*v): print(*v,file=sys.stderr) def main(): TT=int(input()) for tt in range(1,TT+1): printerr("coping Case %d.." %(tt)) ans=once() print("Case #%d: %s" %(tt,(ans))) if __name__=='__main__' : msg=prework(sys.argv) print("prework down with",msg,file=sys.stderr) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var msg : OclAny := prework((trailer . (name argv))) ; execute ("prework down with")->display() ; main() ) else skip; operation prework(argv : OclAny) : OclAny pre: true post: true activity: return "nothing"; operation base_conv(i_list : OclAny, from_base : OclAny) : OclAny pre: true post: true activity: var s : int := 0 ; for i : (i_list)->reverse() do ( s := s * from_base ; s := s + i) ; return s; operation once() pre: true post: true activity: ; Sequence{k}->union(Sequence{c}->union(Sequence{ s })) := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if (s->compareTo((k / c)->ceil())) < 0 then ( return "IMPOSSIBLE" ) else skip ; var ans_list : Sequence := () ; for ic : Integer.subrange(0, k-1)->select( $x | ($x - 0) mod c = 0 ) do ( var l : Sequence := () ; for j : Integer.subrange(0, c-1) do ( if (ic + j->compareTo(k)) >= 0 then ( break ) else skip ; execute ((ic + j) : l)) ; printerr(l) ; execute ((base_conv(l, k)) : ans_list)) ; return StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (number (integer 1)))))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name ans_list)))))))), " "); operation printerr(v : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name v))) execute ((argument * (test (logical_test (comparison (expr (atom (name v))))))))->display(); operation main() pre: true post: true activity: var TT : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for tt : Integer.subrange(1, TT + 1-1) do ( printerr(StringLib.format("coping Case %d..",(tt))) ; var ans : OclAny := once() ; execute (StringLib.format("Case #%d: %s",Sequence{tt, (ans)}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def answer(arr,ranges,reversals,index): i=reversals-1 while(i>=0): left=ranges[i][0] right=ranges[i][1] if(left<=index and right>=index): index=right+left-index i-=1 return arr[index] if __name__=='__main__' : arr=[10,20,30,40,50] reversals=2 ranges=[[1,4],[0,2]] index=1 print(answer(arr,ranges,reversals,index)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{10}->union(Sequence{20}->union(Sequence{30}->union(Sequence{40}->union(Sequence{ 50 })))) ; reversals := 2 ; ranges := Sequence{Sequence{1}->union(Sequence{ 4 })}->union(Sequence{ Sequence{0}->union(Sequence{ 2 }) }) ; index := 1 ; execute (answer(arr, ranges, reversals, index))->display() ) else skip; operation answer(arr : OclAny, ranges : OclAny, reversals : OclAny, index : OclAny) : OclAny pre: true post: true activity: var i : double := reversals - 1 ; while (i >= 0) do ( var left : OclAny := ranges[i+1]->first() ; var right : OclAny := ranges[i+1][1+1] ; if ((left->compareTo(index)) <= 0 & (right->compareTo(index)) >= 0) then ( index := right + left - index ) else skip ; i := i - 1) ; return arr[index+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import reduce def M(x,y): if x=='T' and y=='T' : return 'T' elif x=='T' and y=='F' : return 'F' elif x=='F' and y=='T' : return 'T' else : return 'T' _=input() P=input().split() print(reduce(M,P)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var _anon : String := (OclFile["System.in"]).readLine() ; var P : OclAny := input().split() ; execute (reduce(M, P))->display(); operation M(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if x = 'T' & y = 'T' then ( return 'T' ) else (if x = 'T' & y = 'F' then ( return 'F' ) else (if x = 'F' & y = 'T' then ( return 'T' ) else ( return 'T' ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict from heapq import heappush,heappop import sys import math import bisect import random def LI(): return list(map(int,sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return list(map(list,sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l=[None for i in range(n)] for i in range(n): l[i]=I() return l def LIR(n): l=[None for i in range(n)] for i in range(n): l[i]=LI() return l def SR(n): l=[None for i in range(n)] for i in range(n): l[i]=S() return l def LSR(n): l=[None for i in range(n)] for i in range(n): l[i]=SR() return l mod=1000000007 def m(x,y): if x==y : return "T" if x=="F" : return "T" return "F" n=I() p=input().split() ans=p[0] for i in range(1,n): ans=m(ans,p[i]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : int := 1000000007 ; skip ; n := I() ; var p : OclAny := input().split() ; var ans : OclAny := p->first() ; for i : Integer.subrange(1, n-1) do ( ans := m(ans, p[i+1])) ; execute (ans)->display(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["Sequence"])->apply(_x) )); operation S() : OclAny pre: true post: true activity: return OclType["Sequence"]((OclFile["System.in"]).readLine())->front(); operation IR(n : OclAny) : OclAny pre: true post: true activity: var l : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; for i : Integer.subrange(0, n-1) do ( l[i+1] := I()) ; return l; operation LIR(n : OclAny) : OclAny pre: true post: true activity: l := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; for i : Integer.subrange(0, n-1) do ( l[i+1] := LI()) ; return l; operation SR(n : OclAny) : OclAny pre: true post: true activity: l := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; for i : Integer.subrange(0, n-1) do ( l[i+1] := S()) ; return l; operation LSR(n : OclAny) : OclAny pre: true post: true activity: l := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; for i : Integer.subrange(0, n-1) do ( l[i+1] := SR()) ; return l; operation m(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if x = y then ( return "T" ) else skip ; if x = "F" then ( return "T" ) else skip ; return "F"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) tf=list(map(str,input().split())) tf_r=tf[: :-1] while n!=1 : if tf_r[-1]=="T" and tf_r[-2]=="F" : del tf_r[-2 :] tf_r.append("F") n-=1 else : del tf_r[-2 :] tf_r.append("T") n-=1 print(tf_r[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var tf : Sequence := ((input().split())->collect( _x | (OclType["String"])->apply(_x) )) ; var tf_r : OclAny := tf(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; while n /= 1 do ( if tf_r->last() = "T" & tf_r->front()->last() = "F" then ( execute (tf_r.subrange(-2+1))->isDeleted() ; execute (("F") : tf_r) ; n := n - 1 ) else ( execute (tf_r.subrange(-2+1))->isDeleted() ; execute (("T") : tf_r) ; n := n - 1 )) ; execute (tf_r->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def checkIfSortRotated(arr,n): minEle=sys.maxsize maxEle=-sys.maxsize-1 minIndex=-1 for i in range(n): if arr[i]union(Sequence{4}->union(Sequence{5}->union(Sequence{1}->union(Sequence{ 2 })))) ; n := (arr)->size() ; checkIfSortRotated(arr, n); operation checkIfSortRotated(arr : OclAny, n : OclAny) pre: true post: true activity: var minEle : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; var maxEle : double := -(trailer . (name maxsize)) - 1 ; var minIndex : int := -1 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1]->compareTo(minEle)) < 0 then ( minEle := arr[i+1] ; minIndex := i ) else skip) ; var flag1 : int := 1 ; for i : Integer.subrange(1, minIndex-1) do ( if (arr[i+1]->compareTo(arr[i - 1+1])) < 0 then ( flag1 := 0 ; break ) else skip) ; var flag2 : int := 2 ; for i : Integer.subrange(minIndex + 1, n-1) do ( if (arr[i+1]->compareTo(arr[i - 1+1])) < 0 then ( flag2 := 0 ; break ) else skip) ; if (flag1 & flag2 & (arr[n - 1+1]->compareTo(arr[minIndex - 1+1])) < 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) P=input().split() if P[0]=="T" and P[1]=="F" : out="F" else : out="T" for i in range(N-2): if out=="T" and P[i+2]=="F" : out="F" else : out="T" print(out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var P : OclAny := input().split() ; if P->first() = "T" & P[1+1] = "F" then ( var out : String := "F" ) else ( out := "T" ) ; for i : Integer.subrange(0, N - 2-1) do ( if out = "T" & P[i + 2+1] = "F" then ( out := "F" ) else ( out := "T" )) ; execute (out)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def M(i,j): return "F" if i=="T" and j=="F" else "T" n=int(input()) p=input().split() ret=p[0] for i in range(1,n): ret=M(ret,p[i]) print(ret) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : OclAny := input().split() ; var ret : OclAny := p->first() ; for i : Integer.subrange(1, n-1) do ( ret := M(ret, p[i+1])) ; execute (ret)->display(); operation M(i : OclAny, j : OclAny) : OclAny pre: true post: true activity: return if i = "T" & j = "F" then "F" else "T" endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,F=[int(i)for i in input().split()] itemsets=[] for l in range(N): items=input().split() M=int(items.pop(0)) items.sort() for i in range(len(items)): for j in range(i+1,len(items)): itemsets.append(items[i]+""+items[j]) itemsets.sort() cnt=1 ans=[] if F>1 : ans.append("") for i in range(1,len(itemsets)): if itemsets[i]==itemsets[i-1]: cnt=cnt+1 if cnt>=F and itemsets[i]!=ans[-1]: ans.append(itemsets[i]) else : cnt=1 ans.pop(0) else : ans=itemsets print(len(ans)) for i in range(len(ans)): print(ans[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var F : OclAny := null; Sequence{N,F} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var itemsets : Sequence := Sequence{} ; for l : Integer.subrange(0, N-1) do ( var items : OclAny := input().split() ; var M : int := ("" + ((items->at(0`firstArg+1))))->toInteger() ; items := items->sort() ; for i : Integer.subrange(0, (items)->size()-1) do ( for j : Integer.subrange(i + 1, (items)->size()-1) do ( execute ((items[i+1] + "" + items[j+1]) : itemsets)))) ; itemsets := itemsets->sort() ; var cnt : int := 1 ; var ans : Sequence := Sequence{} ; if F > 1 then ( execute (("") : ans) ; for i : Integer.subrange(1, (itemsets)->size()-1) do ( if itemsets[i+1] = itemsets[i - 1+1] then ( cnt := cnt + 1 ; if (cnt->compareTo(F)) >= 0 & itemsets[i+1] /= ans->last() then ( execute ((itemsets[i+1]) : ans) ) else skip ) else ( cnt := 1 )) ; ans := ans->excludingAt(0+1) ) else ( ans := itemsets ) ; execute ((ans)->size())->display() ; for i : Integer.subrange(0, (ans)->size()-1) do ( execute (ans[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import combinations N,F=map(int,input().split()) goods=[sorted(g)for _ in range(N)for g in list(combinations(list(map(str,input().split()))[1 :],2))] sets=set((g[0],g[1])for g in goods) s=[(s[0],s[1])for s in sets if goods.count([s[0],s[1]])>=F] n=[sum(1 for s in sets if goods.count([s[0],s[1]])>=F)] for a in n : print(a) else : if n[0]!=0 : for t in sorted(sorted(s,key=lambda x : x[1])): print(*t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var F : OclAny := null; Sequence{N,F} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var goods : Sequence := Integer.subrange(0, N-1)->select(_anon; g : (combinations(OclType["Sequence"]((input().split())->collect( _x | (OclType["String"])->apply(_x) ))->tail(), 2)) | true)->collect(_anon; g : (combinations(OclType["Sequence"]((input().split())->collect( _x | (OclType["String"])->apply(_x) ))->tail(), 2)) | (g->sort())) ; var sets : Set := Set{}->union(((argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))) , (test (logical_test (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))) )))))) (comp_for for (exprlist (expr (atom (name g)))) in (logical_test (comparison (expr (atom (name goods))))))))) ; var s : Sequence := sets->select(s | (goods->count(Sequence{s->first()}->union(Sequence{ s[1+1] }))->compareTo(F)) >= 0)->collect(s | (Sequence{s->first(), s[1+1]})) ; var n : Sequence := Sequence{ ((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name sets))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name goods)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))) , (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))) ]))))))) ))))) >= (comparison (expr (atom (name F)))))))))))->sum() } ; (compound_stmt for (exprlist (expr (atom (name a)))) in (testlist (test (logical_test (comparison (expr (atom (name n))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))))))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name n)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) != (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name t)))) in (testlist (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s))))))) , (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))))) ))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom (name t)))))))) ))))))))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys l=input().split() f=int(l[1]) t={} for l in sys.stdin : e=l.split() m=int(e.pop(0)) s=sorted(e) for i in range(m): for j in range(i+1,m): k=(s[i],s[j]) if k in t : t[k]+=1 else : t[k]=1 f=list(sorted(filter(lambda x : t[x]>=f,t))) print(len(f)) for e in f : print("{0:s}{1:s}".format(e[0],e[1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var l : OclAny := input().split() ; var f : int := ("" + ((l[1+1])))->toInteger() ; var t : OclAny := Set{} ; for l : OclFile["System.in"] do ( var e : OclAny := l.split() ; var m : int := ("" + ((e->at(0`firstArg+1))))->toInteger() ; var s : Sequence := e->sort() ; for i : Integer.subrange(0, m-1) do ( for j : Integer.subrange(i + 1, m-1) do ( var k : OclAny := Sequence{s[i+1], s[j+1]} ; if (t)->includes(k) then ( t[k+1] := t[k+1] + 1 ) else ( t[k+1] := 1 )))) ; f := ((t)->select( _x | (lambda x : OclAny in ((t[x+1]->compareTo(f)) >= 0))->apply(_x) = true )->sort()) ; execute ((f)->size())->display() ; for e : f do ( execute (StringLib.interpolateStrings("{0:s}{1:s}", Sequence{e->first(), e[1+1]}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def combinations(l): sl=sorted(l) r=range(len(sl)-1) for i in r : for j in range(i+1,len(sl)): yield(sl[i],sl[j]) m,n=[int(s)for s in input().split()] d={} for i in range(m): l=input().split()[1 :] for e in combinations(l): if e in d : d[e]+=1 else : d[e]=1 sl=sorted([e[0][0]+" "+e[0][1]for e in d.items()if e[1]>=n]) print(len(sl)) for i in sl : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; var d : OclAny := Set{} ; for i : Integer.subrange(0, m-1) do ( l := input().split()->tail() ; for e : combinations(l) do ( if (d)->includes(e) then ( d[e+1] := d[e+1] + 1 ) else ( d[e+1] := 1 ))) ; sl := d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->select(e | (e[1+1]->compareTo(n)) >= 0)->collect(e | (e->first()->first() + " " + e->first()[1+1]))->sort() ; execute ((sl)->size())->display() ; for i : sl do ( execute (i)->display()); operation combinations(l : OclAny) pre: true post: true activity: var sl : Sequence := l->sort() ; var r : Sequence := Integer.subrange(0, (sl)->size() - 1-1) ; for i : r do ( for j : Integer.subrange(i + 1, (sl)->size()-1) do ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return Sequence{sl[i+1], sl[j+1]})); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,f=map(int,input().split()) pair={} for i in range(n): m,*items=input().split() m=int(m) for p in range(m): for q in range(p): key=tuple(sorted([items[p],items[q]])) pair[key]=pair.get(key,0)+1 ans=sorted(key for key in pair if pair[key]>=f) print(len(ans)) if ans : for a,b in ans : print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var f : OclAny := null; Sequence{n,f} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var pair : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var m : OclAny := null; var items : OclAny := null; Sequence{m,items} := input().split() ; var m : int := ("" + ((m)))->toInteger() ; for p : Integer.subrange(0, m-1) do ( for q : Integer.subrange(0, p-1) do ( var key : Sequence := (Sequence{items[p+1]}->union(Sequence{ items[q+1] })->sort()) ; pair->restrict(key) := pair.get(key, 0) + 1))) ; var ans : Sequence := (argument (test (logical_test (comparison (expr (atom (name key)))))) (comp_for for (exprlist (expr (atom (name key)))) in (logical_test (comparison (expr (atom (name pair))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name pair)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name key)))))))) ])))) >= (comparison (expr (atom (name f))))))))))->sort() ; execute ((ans)->size())->display() ; if ans then ( for _tuple : ans do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); execute (a)->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairs(arr,n): map=dict() for i in range(n): map[arr[i]-i]=map.get(arr[i]-i,0)+1 res=0 for x in map : cnt=map[x] res+=((cnt*(cnt-1))//2) return res arr=[1,5,6,7,9] n=len(arr) print(countPairs(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 9 })))) ; n := (arr)->size() ; execute (countPairs(arr, n))->display(); operation countPairs(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var map : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( ([arr[i+1] - i+1]`third)->collect( _x | ([arr[i+1] - i+1])->apply(_x) ) := MatrixLib.elementwiseAdd(((trailer . (name get) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name i)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))))->collect( _x | ((trailer . (name get) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name i)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))))->apply(_x) ), 1)) ; var res : int := 0 ; for x : map->keys() do ( var cnt : Sequence := ([x+1]`third)->collect( _x | ([x+1])->apply(_x) ) ; res := res + ((MatrixLib.elementwiseMult(cnt, (cnt - 1))) div 2)) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lst=input().split() n,m=int(lst[0]),int(lst[1]) a=[] b=[] for i in range(n): lst=list(map(int,input().split())) a.append(lst) lst=[0 for j in range(m)] b.append(lst) res=[] for i in range(n-1): for j in range(m-1): if a[i][j]==a[i][j+1]==a[i+1][j]==a[i+1][j+1]==1 : res.append([i+1,j+1]) b[i][j]=1 b[i][j+1]=1 b[i+1][j]=1 b[i+1][j+1]=1 k=len(res) for i in range(n): for j in range(m): if a[i][j]!=b[i][j]: k=-1 break if k==-1 : break print(k) if k!=-1 : for lst in res : print(lst[0],lst[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lst : OclAny := input().split() ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{("" + ((lst->first())))->toInteger(),("" + ((lst[1+1])))->toInteger()} ; var a : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( lst := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((lst) : a) ; lst := Integer.subrange(0, m-1)->select(j | true)->collect(j | (0)) ; execute ((lst) : b)) ; var res : Sequence := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(0, m - 1-1) do ( if a[i+1][j+1] = a[i+1][j + 1+1] & (a[i+1][j + 1+1] == a[i + 1+1][j+1]) & (a[i + 1+1][j+1] == a[i + 1+1][j + 1+1]) & (a[i + 1+1][j + 1+1] == 1) then ( execute ((Sequence{i + 1}->union(Sequence{ j + 1 })) : res) ; b[i+1][j+1] := 1 ; b[i+1][j + 1+1] := 1 ; b[i + 1+1][j+1] := 1 ; b[i + 1+1][j + 1+1] := 1 ) else skip)) ; var k : int := (res)->size() ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if a[i+1][j+1] /= b[i+1][j+1] then ( k := -1 ; break ) else skip) ; if k = -1 then ( break ) else skip) ; execute (k)->display() ; if k /= -1 then ( for lst : res do ( execute (lst->first())->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,m=map(int,input().split()) g=[input()[:-1].split()for _ in range(n)] s=set() c=0 for i in range(n): for j in range(m): if g[i][j]=='1' : if icollect( _x | (OclType["int"])->apply(_x) ) ; var g : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (input()->front().split())) ; var s : Set := Set{}->union(()) ; var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if g[i+1][j+1] = '1' then ( if (i->compareTo(n - 1)) < 0 & (j->compareTo(m - 1)) < 0 & g[i + 1+1][j+1] = g[i+1][j + 1+1] & (g[i+1][j + 1+1] == g[i + 1+1][j + 1+1]) & (g[i + 1+1][j + 1+1] == '1') then ( execute ((Sequence{i + 1, j + 1}) : s) ) else (if (i->compareTo(n - 1)) < 0 & 0 < j & g[i + 1+1][j+1] = g[i + 1+1][j - 1+1] & (g[i + 1+1][j - 1+1] == g[i+1][j - 1+1]) & (g[i+1][j - 1+1] == '1') then ( execute ((Sequence{i + 1, j}) : s) ) else (if 0 < i & 0 < j & g[i - 1+1][j+1] = g[i - 1+1][j - 1+1] & (g[i - 1+1][j - 1+1] == g[i+1][j - 1+1]) & (g[i+1][j - 1+1] == '1') then ( execute ((Sequence{i, j}) : s) ) else (if 0 < i & (j->compareTo(m - 1)) < 0 & g[i - 1+1][j+1] = g[i - 1+1][j + 1+1] & (g[i - 1+1][j + 1+1] == g[i+1][j + 1+1]) & (g[i+1][j + 1+1] == '1') then ( execute ((Sequence{i, j + 1}) : s) ) else ( c := -1 ; break ) ) ) ) ) else skip) ; if c = -1 then ( break ) else skip) ; if c = -1 then ( execute (c)->display() ) else ( execute ((s)->size())->display() ; for i : s do ( execute ((argument * (test (logical_test (comparison (expr (atom (name i))))))))->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline N,M=map(int,input().split()) UV=[[int(x)for x in row.split()]for row in sys.stdin.readlines()] graph=[[]for _ in range(N+1)] for u,v in UV : graph[u].append(v) graph[v].append(u) color=[None]*(N+1) def calc_comp_data(v): c=0 q=[v] color[v]=0 is_bipartite=True size=1 while q : qq=[] c ^=1 for x in q : for y in graph[x]: if color[y]is None : color[y]=c qq.append(y) size+=1 elif color[y]==c : continue else : is_bipartite=False q=qq return size,is_bipartite size=[] is_bipartite=[] for v in range(1,N+1): if color[v]is not None : continue x,y=calc_comp_data(v) size.append(x) is_bipartite.append(y) size,is_bipartite n_point=sum(1 if s==1 else 0 for s in size) n_component=len(size) n_bipartitle=sum(1 if s>=2 and bl else 0 for s,bl in zip(size,is_bipartite)) answer=0 for s,bl in zip(size,is_bipartite): if s==1 : answer+=N elif not bl : answer+=(n_component-n_point)+s*n_point else : answer+=(n_component-n_point)+n_bipartitle+s*n_point print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var UV : Sequence := (OclFile["System.in"]).readlines()->select(row | true)->collect(row | (row.split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))) ; var graph : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _tuple : UV do (var _indx : int := 1; var u : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)))))))) ))))) ; var color : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (N + 1)) ; skip ; size := Sequence{} ; is_bipartite := Sequence{} ; for v : Integer.subrange(1, N + 1-1) do ( if not(color[v+1] <>= null) then ( continue ) else skip ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := calc_comp_data(v) ; execute ((x) : size) ; execute ((y) : is_bipartite)) ; size ; ; var n_point : OclAny := ((argument (test (logical_test (comparison (expr (atom (number (integer 1)))))) if (logical_test (comparison (comparison (expr (atom (name s)))) == (comparison (expr (atom (number (integer 1))))))) else (test (logical_test (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name size))))))))->sum() ; var n_component : int := (size)->size() ; var n_bipartitle : OclAny := ((argument (test (logical_test (comparison (expr (atom (number (integer 1)))))) if (logical_test (logical_test (comparison (comparison (expr (atom (name s)))) >= (comparison (expr (atom (number (integer 2))))))) and (logical_test (comparison (expr (atom (name bl)))))) else (test (logical_test (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name s))) , (expr (atom (name bl)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name size))))))) , (argument (test (logical_test (comparison (expr (atom (name is_bipartite)))))))) )))))))))->sum() ; var answer : int := 0 ; for _tuple : Integer.subrange(1, size->size())->collect( _indx | Sequence{size->at(_indx), is_bipartite->at(_indx)} ) do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var bl : OclAny := _tuple->at(_indx); if s = 1 then ( answer := answer + N ) else (if not(bl) then ( answer := answer + (n_component - n_point) + s * n_point ) else ( answer := answer + (n_component - n_point) + n_bipartitle + s * n_point ) ) ) ; execute (answer)->display(); operation calc_comp_data(v : OclAny) : OclAny pre: true post: true activity: var c : int := 0 ; var q : Sequence := Sequence{ v } ; color[v+1] := 0 ; var is_bipartite : boolean := true ; var size : int := 1 ; while q do ( var qq : Sequence := Sequence{} ; c := c xor 1 ; for x : q do ( for y : graph[x+1] do ( if color[y+1] <>= null then ( color[y+1] := c ; execute ((y) : qq) ; size := size + 1 ) else (if color[y+1] = c then ( continue ) else ( is_bipartite := false ) ) )) ; q := qq) ; return size, is_bipartite; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) num=[] ans=[] for i in range(n): x=list(map(int,input().split())) num.append(x) for i in range(n-1): for j in range(m-1): if(num[i][j]*num[i+1][j]*num[i][j+1]*num[i+1][j+1]!=0): num[i][j]=num[i+1][j]=num[i][j+1]=num[i+1][j+1]=2 a=[i+1,j+1] ans.append(a) f=1 for i in range(n): for j in range(m): if(num[i][j]==1): f=0 break if(f==0): print(-1) else : print(len(ans)) for i in range(len(ans)): print(ans[i][0],ans[i][1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var num : Sequence := Sequence{} ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((x) : num)) ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(0, m - 1-1) do ( if (num[i+1][j+1] * num[i + 1+1][j+1] * num[i+1][j + 1+1] * num[i + 1+1][j + 1+1] /= 0) then ( num[i+1][j+1] := num[i+1][j+1](assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name num)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name num)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 1)))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name num)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 1)))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) ; var a : Sequence := Sequence{i + 1}->union(Sequence{ j + 1 }) ; execute ((a) : ans) ) else skip)) ; var f : int := 1 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if (num[i+1][j+1] = 1) then ( f := 0 ; break ) else skip)) ; if (f = 0) then ( execute (-1)->display() ) else ( execute ((ans)->size())->display() ; for i : Integer.subrange(0, (ans)->size()-1) do ( execute (ans[i+1]->first())->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline inp=lambda : list(map(int,input().split())) def check(x,y): if(x+1>=n or y+1>=m): return False count=a[x][y]+a[x+1][y]+a[x][y+1]+a[x+1][y+1] if(count==4): return True return False def answer(): ans=[] b=[[0 for i in range(m)]for j in range(n)] for i in range(n): for j in range(m): if(check(i,j)): b[i][j]=1 b[i+1][j]=1 b[i][j+1]=1 b[i+1][j+1]=1 ans.append([i+1,j+1]) if(b[i][j]==0 and a[i][j]==1): if(not check(i,j)): print(-1) return print(len(ans)) for x in ans : print(*x) for T in range(1): n,m=inp() a=[inp()for i in range(n)] answer() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; var inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; skip ; skip ; for T : Integer.subrange(0, 1-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := inp->apply() ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (inp->apply())) ; answer()); operation check(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if ((x + 1->compareTo(n)) >= 0 or (y + 1->compareTo(m)) >= 0) then ( return false ) else skip ; var count : OclAny := a[x+1][y+1] + a[x + 1+1][y+1] + a[x+1][y + 1+1] + a[x + 1+1][y + 1+1] ; if (count = 4) then ( return true ) else skip ; return false; operation answer() pre: true post: true activity: var ans : Sequence := Sequence{} ; var b : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (Integer.subrange(0, m-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if (check(i, j)) then ( b[i+1][j+1] := 1 ; b[i + 1+1][j+1] := 1 ; b[i+1][j + 1+1] := 1 ; b[i + 1+1][j + 1+1] := 1 ; execute ((Sequence{i + 1}->union(Sequence{ j + 1 })) : ans) ) else skip ; if (b[i+1][j+1] = 0 & a[i+1][j+1] = 1) then ( if (not(check(i, j))) then ( execute (-1)->display() ; return ) else skip ) else skip)) ; execute ((ans)->size())->display() ; for x : ans do ( execute ((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=[[]for i in range(n)] for i in range(n): a[i]=list(map(int,input().split())) ans=[] for i in range(n-1): for j in range(m-1): if(a[i][j]*a[i][j+1]*a[i+1][j]*a[i+1][j+1]>0): a[i][j]=2 a[i+1][j]=2 a[i][j+1]=2 a[i+1][j+1]=2 ans.append([i,j]) cnt1=0 for i in range(n): for j in range(m): if(a[i][j]==1): cnt1+=1 if(cnt1!=0): print(-1) else : print(len(ans)) for x in ans : print(x[0]+1,x[1]+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, n-1) do ( a[i+1] := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(0, m - 1-1) do ( if (a[i+1][j+1] * a[i+1][j + 1+1] * a[i + 1+1][j+1] * a[i + 1+1][j + 1+1] > 0) then ( a[i+1][j+1] := 2 ; a[i + 1+1][j+1] := 2 ; a[i+1][j + 1+1] := 2 ; a[i + 1+1][j + 1+1] := 2 ; execute ((Sequence{i}->union(Sequence{ j })) : ans) ) else skip)) ; var cnt1 : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if (a[i+1][j+1] = 1) then ( cnt1 := cnt1 + 1 ) else skip)) ; if (cnt1 /= 0) then ( execute (-1)->display() ) else ( execute ((ans)->size())->display() ; for x : ans do ( execute (x->first() + 1)->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def countPrimes(self,n): isPrime=[True]*n for i in xrange(2,n): if i*i>=n : break if not isPrime[i]: continue for j in xrange(i*i,n,i): isPrime[j]=False count=0 for i in xrange(2,n): if isPrime[i]: count+=1 return count ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation countPrimes(n : OclAny) : OclAny pre: true post: true activity: var isPrime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, n) ; for i : xrange(2, n) do ( if (i * i->compareTo(n)) >= 0 then ( break ) else skip ; if not(isPrime[i+1]) then ( continue ) else skip ; for j : xrange(i * i, n, i) do ( isPrime[j+1] := false)) ; var count : int := 0 ; for i : xrange(2, n) do ( if isPrime[i+1] then ( count := count + 1 ) else skip) ; return count; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import deque def bfs(source,target,parent): queue=deque() queue.appendleft(source) visited=[False]*v_num visited[source]=True while queue : current=queue.popleft() for adj,cp in adj_table[current].items(): if cp and not visited[adj]: queue.append(adj) visited[adj]=True parent[adj]=current return True if visited[target]else False def graph_FordFulkerson(source,sink): parent=[-1]*v_num max_flow=0 while bfs(source,sink,parent): path_flow=float('inf') bk_1=sink while bk_1!=source : parent_bk_1=parent[bk_1] assert parent_bk_1!=-1 path_flow=min(path_flow,adj_table[parent_bk_1][bk_1]) bk_1=parent[bk_1] max_flow+=path_flow bk_2=sink while bk_2!=source : parent_bk_2=parent[bk_2] assert parent_bk_2!=-1 adj_table[bk_2].setdefault(parent_bk_2,0) adj_table[parent_bk_2][bk_2]-=path_flow adj_table[bk_2][parent_bk_2]+=path_flow bk_2=parent[bk_2] return max_flow if __name__=='__main__' : _input=sys.stdin.readlines() v_num,e_num=map(int,_input[0].split()) edges=map(lambda x : x.split(),_input[1 :]) adj_table=tuple(dict()for _ in range(v_num)) for edge in edges : s,t,c=map(int,edge) adj_table[s][t]=c print(graph_FordFulkerson(source=0,sink=v_num-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var _input : OclAny := (OclFile["System.in"]).readlines() ; var v_num : OclAny := null; var e_num : OclAny := null; Sequence{v_num,e_num} := (_input->first().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var edges : Sequence := (_input->tail())->collect( _x | (lambda x : OclAny in (x.split()))->apply(_x) ) ; var adj_table : Sequence := ((argument (test (logical_test (comparison (expr (atom (name dict)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v_num)))))))) ))))))))) ; for edge : edges do ( var s : OclAny := null; var t : OclAny := null; var c : OclAny := null; Sequence{s,t,c} := (edge)->collect( _x | (OclType["int"])->apply(_x) ) ; adj_table[s+1][t+1] := c) ; execute (graph_FordFulkerson((argument (test (logical_test (comparison (expr (atom (name source)))))) = (test (logical_test (comparison (expr (atom (number (integer 0)))))))), (argument (test (logical_test (comparison (expr (atom (name sink)))))) = (test (logical_test (comparison (expr (expr (atom (name v_num))) - (expr (atom (number (integer 1)))))))))))->display() ) else skip; operation bfs(source : OclAny, target : OclAny, parent : OclAny) : OclAny pre: true post: true activity: var queue : Sequence := () ; queue := queue->prepend(source) ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, v_num) ; visited[source+1] := true ; while queue do ( var current : OclAny := queue->first() ; queue := queue->tail() ; for _tuple : adj_table[current+1]->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var adj : OclAny := _tuple->at(_indx); _indx := _indx + 1; var cp : OclAny := _tuple->at(_indx); if cp & not(visited[adj+1]) then ( execute ((adj) : queue) ; visited[adj+1] := true ; parent[adj+1] := current ) else skip)) ; return if visited[target+1] then true else false endif; operation graph_FordFulkerson(source : OclAny, sink : OclAny) : OclAny pre: true post: true activity: parent := MatrixLib.elementwiseMult(Sequence{ -1 }, v_num) ; var max_flow : int := 0 ; while bfs(source, sink, parent) do ( var path_flow : double := ("" + (('inf')))->toReal() ; var bk var path_flow : double := ("" + (('inf')))->toReal() : OclAny := sink ; while bk var path_flow : double := ("" + (('inf')))->toReal() /= source do ( var parent_bk var path_flow : double := ("" + (('inf')))->toReal() : OclAny := parent[bk var path_flow : double := ("" + (('inf')))->toReal()+1] ; assert parent_bk var parent_bk var path_flow : double := ("" + (('inf')))->toReal() : OclAny := parent[bk var path_flow : double := ("" + (('inf')))->toReal()+1] /= -1 do "assertion failed" ; path_flow := Set{path_flow, adj_table[parent_bkpath_flow+1][bkpath_flow+1]}->min() ; bk var parent_bk var path_flow : double := ("" + (('inf')))->toReal() : OclAny := parent[bk var path_flow : double := ("" + (('inf')))->toReal()+1] := parent[bk var parent_bk var path_flow : double := ("" + (('inf')))->toReal() : OclAny := parent[bk var path_flow : double := ("" + (('inf')))->toReal()+1]+1]) ; max_flow := max_flow + path_flow ; var bk:= sink : OclAny := sink ; while bksource /= source do ( var parent_bk:= parent[bk_2+1] : OclAny := parent[bk_2+1] ; assert parent_bk-1 /= -1 do "assertion failed" ; (expr (atom (name adj_table)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name bk_2)))))))) ])) (trailer . (name setdefault) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name parent_bk_2))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))) ; adj_table[parent_bk - path_flow+1][bk - path_flow+1] := adj_table[parent_bk - path_flow+1][bk - path_flow+1] - path_flow ; adj_table[bk + path_flow+1][parent_bk + path_flow+1] := adj_table[bk + path_flow+1][parent_bk + path_flow+1] + path_flow ; bk:= parent[bk_2+1] := parent[bk_2+1])) ; return max_flow; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,collections sys.setrecursionlimit(10000) INF=float("inf") V,E=map(int,sys.stdin.readline().split()) uvc=tuple(tuple(map(int,sys.stdin.readline().rstrip().split()))for _ in range(E)) G={i :{}for i in range(V)} mG={i :{}for i in range(V)} for u,v,c in uvc : G[u][v]=c G[v][u]=0 mG[u][v]=0 mG[v][u]=0 def dfs(current,flow): if current==V-1 : return flow visited.add(current) if not G[current]: return 0 for nex,nex_c in G[current].items(): if not nex in visited and nex_c!=0 : f=dfs(nex,min(flow,nex_c)) if f!=0 : mG[current][nex]=mG[current][nex]+f G[current][nex]=G[current][nex]-f G[nex][current]=G[nex][current]+f return f return 0 visited=set() while dfs(0,INF)!=0 : visited=set() pass print(sum(mG[0].values())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(10000) ; var INF : double := ("" + (("inf")))->toReal() ; var V : OclAny := null; var E : OclAny := null; Sequence{V,E} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var uvc : Sequence := ((argument (test (logical_test (comparison (expr (atom (name tuple)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin)) (trailer . (name readline) (arguments ( ))) (trailer . (name rstrip) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name E)))))))) ))))))))) ; var G : Map := Integer.subrange(0, V-1)->select(i | true)->collect(i | Map{i |-> Set{}})->unionAll() ; var mG : Map := Integer.subrange(0, V-1)->select(i | true)->collect(i | Map{i |-> Set{}})->unionAll() ; for _tuple : uvc do (var _indx : int := 1; var u : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); G[u+1][v+1] := c ; G[v+1][u+1] := 0 ; mG[u+1][v+1] := 0 ; mG[v+1][u+1] := 0) ; skip ; var visited : Set := Set{}->union(()) ; while dfs(0, INF) /= 0 do ( visited := Set{}->union(()) ; skip) ; execute ((mG->first().values())->sum())->display(); operation dfs(current : OclAny, flow : OclAny) : OclAny pre: true post: true activity: if current = V - 1 then ( return flow ) else skip ; execute ((current) : visited) ; if not(G[current+1]) then ( return 0 ) else skip ; for _tuple : G[current+1]->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var nex : OclAny := _tuple->at(_indx); _indx := _indx + 1; var nex_c : OclAny := _tuple->at(_indx); if not((visited)->includes(nex)) & nex_c /= 0 then ( var f : OclAny := dfs(nex, Set{flow, nex_c}->min()) ; if f /= 0 then ( mG[current+1][nex+1] := mG[current+1][nex+1] + f ; G[current+1][nex+1] := G[current+1][nex+1] - f ; G[nex+1][current+1] := G[nex+1][current+1] + f ; return f ) else skip ) else skip) ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def dfs(node,sink,f,used,Edge): if node==sink : return f used[node]=True for i,e in enumerate(Edge[node]): nextnode,nextcap,edgeIndex=e if not used[nextnode]and nextcap>0 : d=dfs(nextnode,sink,min(f,nextcap),used,Edge) if d>0 : Edge[node][i][1]-=d Edge[nextnode][edgeIndex][1]+=d return d return 0 def MF(): input=sys.stdin.readline V,E=map(int,input().split()) Edge=[[]for _ in range(V)] edgeSize=[0]*V for _ in range(E): frm,t,cap=map(int,input().split()) Edge[frm].append([t,cap,edgeSize[t]]) Edge[t].append([frm,0,edgeSize[frm]]) edgeSize[t]+=1 edgeSize[frm]+=1 maxFlow=0 while True : visited=[False for _ in range(V)] f=dfs(0,V-1,1000000000,visited,Edge) if f==0 : break maxFlow+=f print(maxFlow) return 0 if __name__=="__main__" : MF() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( MF() ) else skip; operation dfs(node : OclAny, sink : OclAny, f : OclAny, used : OclAny, Edge : OclAny) : OclAny pre: true post: true activity: if node = sink then ( return f ) else skip ; used[node+1] := true ; for _tuple : Integer.subrange(1, (Edge[node+1])->size())->collect( _indx | Sequence{_indx-1, (Edge[node+1])->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var e : OclAny := _tuple->at(_indx); var nextnode : OclAny := null; var nextcap : OclAny := null; var edgeIndex : OclAny := null; Sequence{nextnode,nextcap,edgeIndex} := e ; if not(used[nextnode+1]) & nextcap > 0 then ( var d : OclAny := dfs(nextnode, sink, Set{f, nextcap}->min(), used, Edge) ; if d > 0 then ( Edge[node+1][i+1][1+1] := Edge[node+1][i+1][1+1] - d ; Edge[nextnode+1][edgeIndex+1][1+1] := Edge[nextnode+1][edgeIndex+1][1+1] + d ; return d ) else skip ) else skip) ; return 0; operation MF() : OclAny pre: true post: true activity: var input : OclAny := (OclFile["System.in"]).readline ; var V : OclAny := null; var E : OclAny := null; Sequence{V,E} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; Edge := Integer.subrange(0, V-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var edgeSize : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, V) ; for _anon : Integer.subrange(0, E-1) do ( var frm : OclAny := null; var t : OclAny := null; var cap : OclAny := null; Sequence{frm,t,cap} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name Edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name frm)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name t)))))) , (test (logical_test (comparison (expr (atom (name cap)))))) , (test (logical_test (comparison (expr (atom (name edgeSize)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ]))))))) ]))))))) )))) ; (expr (atom (name Edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name frm)))))) , (test (logical_test (comparison (expr (atom (number (integer 0))))))) , (test (logical_test (comparison (expr (atom (name edgeSize)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name frm)))))))) ]))))))) ]))))))) )))) ; edgeSize[t+1] := edgeSize[t+1] + 1 ; edgeSize[frm+1] := edgeSize[frm+1] + 1) ; var maxFlow : int := 0 ; while true do ( var visited : Sequence := Integer.subrange(0, V-1)->select(_anon | true)->collect(_anon | (false)) ; f := dfs(0, V - 1, 1000000000, visited, Edge) ; if f = 0 then ( break ) else skip ; maxFlow := maxFlow + f) ; execute (maxFlow)->display() ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class edge : def __init__(self,to,cap,rev): self.to,self.cap,self.rev=to,cap,rev def makeG(n): return[[]for _ in xrange(n)] def add(G,fr,to,cap): G[fr].append(edge(to,cap,len(G[to]))) G[to].append(edge(fr,0,len(G[fr])-1)) def dfs(G,v,t,f,used): if v==t : return f used[v]=True for i in xrange(len(G[v])): e=G[v][i] if not used[e.to]and e.cap>0 : d=dfs(G,e.to,t,min(f,e.cap),used) if d>0 : e.cap-=d G[e.to][e.rev].cap+=d return d return 0 def max_flow(G,n,s,t): flow=0 while True : used=[False]*n f=dfs(G,s,t,float("inf"),used) if f==0 : return flow flow+=f V,E=map(int,raw_input().split()) G=makeG(V) for i in xrange(E): u,v,c=map(int,raw_input().split()) add(G,u,v,c) s=0 t=V-1 print(max_flow(G,V,s,t)) ------------------------------------------------------------ OCL File: --------- class edge { static operation newedge() : edge pre: true post: edge->exists( _x | result = _x ); attribute (testlist_star_expr (test (logical_test (comparison (expr (atom (name self)) (trailer . (name to)))))) , (test (logical_test (comparison (expr (atom (name self)) (trailer . (name cap)))))) , (test (logical_test (comparison (expr (atom (name self)) (trailer . (name rev))))))) : OclAny := to,cap,rev; operation initialise(to : OclAny,cap : OclAny,rev : OclAny) : edge pre: true post: true activity: var self.to : OclAny := null; var self.cap : OclAny := null; var self.rev : OclAny := null; Sequence{self.to,self.cap,self.rev} := Sequence{to,cap,rev}; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var V : OclAny := null; var E : OclAny := null; Sequence{V,E} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; G := makeG(V) ; for i : xrange(E) do ( var u : OclAny := null; var c : OclAny := null; Sequence{u,v,c} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; add(G, u, v, c)) ; s := 0 ; t := V - 1 ; execute (max_flow(G, V, s, t))->display(); operation makeG(n : OclAny) : OclAny pre: true post: true activity: return xrange(n)->select(_anon | true)->collect(_anon | (Sequence{})); operation add(G : OclAny, fr : OclAny, to : OclAny, cap : OclAny) pre: true post: true activity: (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name fr)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name edge)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name to))))))) , (argument (test (logical_test (comparison (expr (atom (name cap))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name to)))))))) ])))))))) ))))))))) ))))))))) )))) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name to)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name edge)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name fr))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name fr)))))))) ])))))))) )))) - (expr (atom (number (integer 1)))))))))) ))))))))) )))); operation dfs(G : OclAny, v : OclAny, t : OclAny, f : OclAny, used : OclAny) : OclAny pre: true post: true activity: if v = t then ( return f ) else skip ; used[v+1] := true ; for i : xrange((G[v+1])->size()) do ( var e : OclAny := G[v+1][i+1] ; if not(used[e.to+1]) & e.cap > 0 then ( var d : OclAny := dfs(G, e.to, t, Set{f, e.cap}->min(), used) ; if d > 0 then ( e.cap := e.cap - d ; G[e.to+1][e.rev+1].cap := G[e.to+1][e.rev+1].cap + d ; return d ) else skip ) else skip) ; return 0; operation max_flow(G : OclAny, n : OclAny, s : OclAny, t : OclAny) : OclAny pre: true post: true activity: var flow : int := 0 ; while true do ( used := MatrixLib.elementwiseMult(Sequence{ false }, n) ; f := dfs(G, s, t, ("" + (("inf")))->toReal(), used) ; if f = 0 then ( return flow ) else skip ; flow := flow + f); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def summation(n): return int((pow(10,n+1)-10-(9*n))/81); print(summation(5)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; execute (summation(5))->display();; operation summation(n : OclAny) pre: true post: true activity: return ("" + ((((10)->pow(n + 1) - 10 - (9 * n)) / 81)))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque import sys sys.setrecursionlimit(200000) n,e=map(int,input().split()) g=[[]for i in range(n)] for i in range(e): a,b,c=map(int,input().split()) g[a].append([b,c,len(g[b])]) g[b].append([a,0,len(g[a])-1]) def bfs(s,t): global level que=deque([s]) level[s]=0 while que : v=que.popleft() lv=level[v]+1 for y,cap,rev in g[v]: if cap and level[y]is None : level[y]=lv que.append(y) return level[t]if level[t]else 0 def dfs(x,t,f): if x==t : return f for j in range(it[x],len(g[x])): it[x]=j y,cap,rev=g[x][j] if cap and level[x]collect( _x | (OclType["int"])->apply(_x) ) ; var g : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, e-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name b)))))) , (test (logical_test (comparison (expr (atom (name c)))))) , (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])))))))) )))))))) ]))))))) )))) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (number (integer 0))))))) , (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])))))))) )))) - (expr (atom (number (integer 1))))))))) ]))))))) ))))) ; skip ; skip ; var flow : int := 0 ; f := ("" + (("inf")))->toReal(); var INF : double := ("" + (("inf")))->toReal() ; level := MatrixLib.elementwiseMult(Sequence{ null }, n) ; while bfs(0, n - 1) do ( var it : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; f := INF ; while f do ( f := dfs(0, n - 1, INF) ; flow := flow + f) ; level := MatrixLib.elementwiseMult(Sequence{ null }, n)) ; execute (flow)->display(); operation bfs(s : OclAny, t : OclAny) : OclAny pre: true post: true activity: skip ; var que : Sequence := (Sequence{ s }) ; level[s+1] := 0 ; while que do ( var v : OclAny := que->first() ; que := que->tail() ; var lv : OclAny := level[v+1] + 1 ; for _tuple : g[v+1] do (var _indx : int := 1; var y : OclAny := _tuple->at(_indx); _indx := _indx + 1; var cap : OclAny := _tuple->at(_indx); _indx := _indx + 1; var rev : OclAny := _tuple->at(_indx); if cap & level[y+1] <>= null then ( level[y+1] := lv ; execute ((y) : que) ) else skip)) ; return if level[t+1] then level[t+1] else 0 endif; operation dfs(x : OclAny, t : OclAny, f : OclAny) : OclAny pre: true post: true activity: if x = t then ( return f ) else skip ; for j : Integer.subrange(it[x+1], (g[x+1])->size()-1) do ( it[x+1] := j ; var y : OclAny := null; var cap : OclAny := null; var rev : OclAny := null; Sequence{y,cap,rev} := g[x+1][j+1] ; if cap & (level[x+1]->compareTo(level[y+1])) < 0 then ( var d : OclAny := dfs(y, t, Set{f, cap}->min()) ; if d then ( g[x+1][j+1][1+1] := g[x+1][j+1][1+1] - d ; g[y+1][rev+1][1+1] := g[y+1][rev+1][1+1] + d ; return d ) else skip ) else skip) ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() X,Y=list(map(int,input().split())) def judge(l,m): s=sum(l) t=s-m if m>0 else s+m if t<0 or t % 2==1 : return False t//=2 n=len(l) w=[[False]*(t+1)for _ in range(n+1)] w[0][0]=True for i in range(1,n+1): for j in range(t+1): if w[i-1][j]: w[i][j]=True if j+l[i-1]<=t : w[i][j+l[i-1]]=True return w[-1][-1] def main(): n=len(S) d=0 for s in S : if s=="F" : d+=1 else : break dx,dy=[],[] side=True i=d while icollect( _x | (OclType["int"])->apply(_x) )) ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation judge(l : OclAny, m : OclAny) : OclAny pre: true post: true activity: var s : OclAny := (l)->sum() ; var t : double := if m > 0 then s - m else s + m endif ; if t < 0 or t mod 2 = 1 then ( return false ) else skip ; t := t div 2 ; var n : int := (l)->size() ; var w : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ false }, (t + 1)))) ; w->first()->first() := true ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(0, t + 1-1) do ( if w[i - 1+1][j+1] then ( w[i+1][j+1] := true ; if (j + l[i - 1+1]->compareTo(t)) <= 0 then ( w[i+1][j + l[i - 1+1]+1] := true ) else skip ) else skip)) ; return w->last()->last(); operation main() pre: true post: true activity: n := (S)->size() ; var d : int := 0 ; for s : S->characters() do ( if s = "F" then ( d := d + 1 ) else ( break )) ; var dx : OclAny := null; var dy : OclAny := null; Sequence{dx,dy} := Sequence{Sequence{},Sequence{}} ; var side : boolean := true ; var i : int := d ; while (i->compareTo(n)) < 0 do ( while (i->compareTo(n)) < 0 & S[i+1] = "T" do ( side := not(side) ; i := i + 1) ; var c : int := 0 ; while (i->compareTo(n)) < 0 & S[i+1] = "F" do ( c := c + 1 ; i := i + 1) ; if side then ( execute ((c) : dx) ) else ( execute ((c) : dy) )) ; var b1 : OclAny := judge(dx, X - d) ; var b2 : OclAny := judge(dy, Y) ; var ans : String := if b1 & b2 then "Yes" else "No" endif ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMinSwaps(s,k): ans=0 ; c_one=0 ; c_zero=0 ; for i in range(len(s)-1,-1,-1): if(s[i]=='1'): c_one+=1 ; if(s[i]=='0'): c_zero+=1 ; ans+=c_one ; if(c_zero==k): break ; if(c_zerodisplay(); ) else skip; operation findMinSwaps(s : OclAny, k : OclAny) pre: true post: true activity: var ans : int := 0; ; var c_one : int := 0; var c_zero : int := 0; ; for i : Integer.subrange(-1 + 1, (s)->size() - 1)->reverse() do ( if (s[i+1] = '1') then ( c_one := c_one + 1; ) else skip ; if (s[i+1] = '0') then ( c_zero := c_zero + 1; ; ans := ans + c_one; ) else skip ; if (c_zero = k) then ( break; ) else skip) ; if ((c_zero->compareTo(k)) < 0) then ( return -1; ) else skip ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(): n,d=map(int,input().split()) costs=[int(x)for x in input().split()] m=int(input()) res=0 costs.sort() for i in range(len(costs)): res+=costs[i] m-=1 if m==0 : break print(res-m*d) f() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; f(); operation f() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var costs : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : int := 0 ; costs := costs->sort() ; for i : Integer.subrange(0, (costs)->size()-1) do ( res := res + costs[i+1] ; m := m - 1 ; if m = 0 then ( break ) else skip) ; execute (res - m * d)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=lambda : map(int,input().split()) n,d=I() a=sorted(I())+[-d]*99 print(sum(a[: next(I())])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := I->apply() ; var a : Sequence := I->apply()->sort()->union(MatrixLib.elementwiseMult(Sequence{ -d }, 99)) ; execute ((a.subrange(1,(I->apply()).next()))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) n,d=map(int,input().split()) a=sorted(map(int,input().split())) m=int(input()) print(sum(a[: min(n,m)])-d*max(0,m-n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((a.subrange(1,Set{n, m}->min()))->sum() - d * Set{0, m - n}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=map(int,input().split()) sps=list(map(int,input().split())) gost=int(input()) total=sum(sps) diff=n-gost if diff>0 : sps.sort() print(sum(sps[: gost])) elif diff<0 : d*=diff print(total+d) else : print(total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sps : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var gost : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var total : OclAny := (sps)->sum() ; var diff : double := n - gost ; if diff > 0 then ( sps := sps->sort() ; execute ((sps.subrange(1,gost))->sum())->display() ) else (if diff < 0 then ( d := d * diff ; execute (total + d)->display() ) else ( execute (total)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=list(map(int,input().split())) lst=list(map(int,input().split())) m=int(input()) lst.sort() ans=0 if m<=len(lst): ans=sum(lst[: m]) else : ans=sum(lst) ans-=(d*(m-len(lst))) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; lst := lst->sort() ; var ans : int := 0 ; if (m->compareTo((lst)->size())) <= 0 then ( ans := (lst.subrange(1,m))->sum() ) else ( ans := (lst)->sum() ; ans := ans - (d * (m - (lst)->size())) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,W=map(int,input().split()) wv=[] for i in range(n): wv.append(list(map(int,input().split()))) num=wv[0][0] dp=[[-float("inf")for i in range(3*(n-1)+1)]for j in range(n+1)] dp[0][0]=0 for i in range(n): w,v=wv[i][0],wv[i][1] w-=num for j in range(n-1,-1,-1): for k in range(3*(n-1)+1-w): dp[j+1][k+w]=max(dp[j+1][k+w],dp[j][k]+v) ans=0 for i in range(3*(n-1)+1): for j in range(n+1): if j*num+i<=W : ans=max(ans,dp[j][i]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var W : OclAny := null; Sequence{n,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var wv : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : wv)) ; var num : OclAny := wv->first()->first() ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, 3 * (n - 1) + 1-1)->select(i | true)->collect(i | (-("" + (("inf")))->toReal())))) ; dp->first()->first() := 0 ; for i : Integer.subrange(0, n-1) do ( var w : OclAny := null; var v : OclAny := null; Sequence{w,v} := Sequence{wv[i+1]->first(),wv[i+1][1+1]} ; w := w - num ; for j : Integer.subrange(-1 + 1, n - 1)->reverse() do ( for k : Integer.subrange(0, 3 * (n - 1) + 1 - w-1) do ( dp[j + 1+1][k + w+1] := Set{dp[j + 1+1][k + w+1], dp[j+1][k+1] + v}->max()))) ; var ans : int := 0 ; for i : Integer.subrange(0, 3 * (n - 1) + 1-1) do ( for j : Integer.subrange(0, n + 1-1) do ( if (j * num + i->compareTo(W)) <= 0 then ( ans := Set{ans, dp[j+1][i+1]}->max() ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from itertools import accumulate read=sys.stdin.read readline=sys.stdin.readline readlines=sys.stdin.readlines sys.setrecursionlimit(10**9) INF=1<<60 MOD=1000000007 def main(): N,W,*wv=map(int,read().split()) w0=wv[0] weight=[[]for _ in range(4)] for w,v in zip(*[iter(wv)]*2): weight[w-w0].append(v) for i in range(4): weight[i].sort(reverse=True) csum=[[0]for _ in range(4)] for i in range(4): csum[i].extend(accumulate(weight[i])) def dfs(w,v,idx): if idx==4 : return v ans=0 for i in range(len(csum[idx])): if w+(w0+idx)*i>W : break ans=max(ans,dfs(w+(w0+idx)*i,v+csum[idx][i],idx+1)) return ans print(dfs(0,0,0)) return if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var read : OclAny := (OclFile["System.in"]).read ; var readline : OclAny := (OclFile["System.in"]).readline ; var readlines : OclAny := (OclFile["System.in"]).readlines ; sys.setrecursionlimit((10)->pow(9)) ; var INF : int := 1 * (2->pow(60)) ; var MOD : int := 1000000007 ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var W : OclAny := null; var wv : OclAny := null; Sequence{N,W,wv} := (read().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w0 : OclAny := wv->first() ; var weight : Sequence := Integer.subrange(0, 4-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _tuple : Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name wv)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name wv)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name wv)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))`third->at(_indx)} ) do (var _indx : int := 1; var w : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); (expr (atom (name weight)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name w))) - (expr (atom (name w0))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) ))))) ; for i : Integer.subrange(0, 4-1) do ((expr (atom (name weight)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name sort) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ))))) ; var csum : Sequence := Integer.subrange(0, 4-1)->select(_anon | true)->collect(_anon | (Sequence{ 0 })) ; for i : Integer.subrange(0, 4-1) do ((expr (atom (name csum)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name extend) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name accumulate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name weight)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))))))) ))))) ; skip ; execute (dfs(0, 0, 0))->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda : sys.stdin.readline().rstrip() from collections import defaultdict def resolve(): n,W=map(int,input().split()) WV=[tuple(map(int,input().split()))for _ in range(n)] weight=set() for i in range(n+1): for j in range(3*i+1): if(WV[0][0]*i+j>W): continue weight.add(WV[0][0]*i+j) weight=sorted(weight) dp=defaultdict(int) for i in range(n): ndp=defaultdict(int) w,v=WV[i] for key in weight : ndp[key]=max(ndp[key],dp[key]) if(key+w<=W): ndp[key+w]=max(ndp[key+w],dp[key]+v) dp=ndp ans=0 for key in weight : ans=max(ans,dp[key]) print(ans) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(2147483647) ; var INF : double := ("" + (("inf")))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; skip ; skip ; resolve(); operation resolve() pre: true post: true activity: var n : OclAny := null; var W : OclAny := null; Sequence{n,W} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var WV : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var weight : Set := Set{}->union(()) ; for i : Integer.subrange(0, n + 1-1) do ( for j : Integer.subrange(0, 3 * i + 1-1) do ( if ((WV->first()->first() * i + j->compareTo(W)) > 0) then ( continue ) else skip ; execute ((WV->first()->first() * i + j) : weight))) ; weight := weight->sort() ; var dp : OclAny := defaultdict(OclType["int"]) ; for i : Integer.subrange(0, n-1) do ( var ndp : OclAny := defaultdict(OclType["int"]) ; var w : OclAny := null; var v : OclAny := null; Sequence{w,v} := WV[i+1] ; for key : weight do ( ndp[key+1] := Set{ndp[key+1], dp[key+1]}->max() ; if ((key + w->compareTo(W)) <= 0) then ( ndp[key + w+1] := Set{ndp[key + w+1], dp[key+1] + v}->max() ) else skip) ; dp := ndp) ; var ans : int := 0 ; for key : weight do ( ans := Set{ans, dp[key+1]}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNumbers(n,b): even=0 ; odd=0 ; if(b % 2==0): even=pow(b,n)-2 ; odd=pow(b,n)-1 ; else : even=pow(b,n)-1 ; odd=pow(b,n)-2 ; print("Even Number=",int(even)); print("Odd Number=",int(odd)); if __name__=='__main__' : N=2 ; B=5 ; findNumbers(N,B); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var N : int := 2; ; var B : int := 5; ; findNumbers(N, B); ) else skip; operation findNumbers(n : OclAny, b : OclAny) pre: true post: true activity: var even : int := 0; ; var odd : int := 0; ; if (b mod 2 = 0) then ( even := (b)->pow(n) - 2; ; odd := (b)->pow(n) - 1; ) else ( even := (b)->pow(n) - 1; ; odd := (b)->pow(n) - 2; ) ; execute ("Even Number=")->display(); ; execute ("Odd Number=")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,collections sys.setrecursionlimit(10**7) def Is(): return[int(x)for x in sys.stdin.readline().split()] def S(): return input() s=S() gx,gy=Is() l=s.split("T") for i in range(len(l)): l[i]=len(l[i]) xlis,ylis=l[: : 2],l[1 : : 2] sx=xlis.pop(0)if len(xlis)>0 else 0 sy=0 xlis.sort(reverse=True) ylis.sort(reverse=True) def calc(start,goal,lis): p=start for e in lis : if ppow(7)) ; skip ; skip ; var s : OclAny := S() ; var gx : OclAny := null; var gy : OclAny := null; Sequence{gx,gy} := Is() ; var l : OclAny := s.split("T") ; for i : Integer.subrange(0, (l)->size()-1) do ( l[i+1] := (l[i+1])->size()) ; var xlis : OclAny := null; var ylis : OclAny := null; Sequence{xlis,ylis} := Sequence{l(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))),l(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))} ; var sx : OclAny := if (xlis)->size() > 0 then xlis->at(0`firstArg+1) else 0 endif ; var sy : int := 0 ; xlis := xlis->sort() ; ylis := ylis->sort() ; skip ; if calc(sx, gx, xlis) & calc(sy, gy, ylis) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation Is() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation calc(start : OclAny, goal : OclAny, lis : OclAny) : OclAny pre: true post: true activity: var p : OclAny := start ; for e : lis do ( if (p->compareTo(goal)) < 0 then ( p := p + e ) else ( p := p - e )) ; return p = goal; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,W=map(int,input().split()) WV=[[int(x)for x in input().split()]for _ in range(N)] w1=WV[0][0] V=[[],[],[],[]] Vcum=[[0],[0],[0],[0]] for w,v in WV : V[w-w1].append(v) for i in range(4): s=0 V[i].sort(reverse=True) for x in V[i]: s+=x Vcum[i].append(s) answer=0 for a in range(len(V[0])+1): for b in range(len(V[1])+1): for c in range(len(V[2])+1): w=w1*a+(w1+1)*b+(w1+2)*c if w>W : break d=min((W-w)//(w1+3),len(V[3])) x=Vcum[0][a]+Vcum[1][b]+Vcum[2][c]+Vcum[3][d] answer=max(answer,x) print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var W : OclAny := null; Sequence{N,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var WV : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))) ; var w1 : OclAny := WV->first()->first() ; var V : Sequence := Sequence{Sequence{}}->union(Sequence{Sequence{}}->union(Sequence{Sequence{}}->union(Sequence{ Sequence{} }))) ; var Vcum : Sequence := Sequence{Sequence{ 0 }}->union(Sequence{Sequence{ 0 }}->union(Sequence{Sequence{ 0 }}->union(Sequence{ Sequence{ 0 } }))) ; for _tuple : WV do (var _indx : int := 1; var w : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); (expr (atom (name V)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name w))) - (expr (atom (name w1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) ))))) ; for i : Integer.subrange(0, 4-1) do ( var s : int := 0 ; (expr (atom (name V)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name sort) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) )))) ; for x : V[i+1] do ( s := s + x ; (expr (atom (name Vcum)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))))) ; var answer : int := 0 ; for a : Integer.subrange(0, (V->first())->size() + 1-1) do ( for b : Integer.subrange(0, (V[1+1])->size() + 1-1) do ( for c : Integer.subrange(0, (V[2+1])->size() + 1-1) do ( var w : double := w1 * a + (w1 + 1) * b + (w1 + 2) * c ; if (w->compareTo(W)) > 0 then ( break ) else skip ; var d : OclAny := Set{(W - w) div (w1 + 3), (V[3+1])->size()}->min() ; var x : OclAny := Vcum->first()[a+1] + Vcum[1+1][b+1] + Vcum[2+1][c+1] + Vcum[3+1][d+1] ; answer := Set{answer, x}->max()))) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,W=map(int,input().split()) w1,w2,w3,w4=[],[],[],[] w,v=map(int,input().split()) w1.append(v) for _ in range(n-1): a,b=map(int,input().split()) if a==w : w1.append(b) if a==w+1 : w2.append(b) if a==w+2 : w3.append(b) if a==w+3 : w4.append(b) for w_ in[w1,w2,w3,w4]: w_.sort(reverse=True) ans=0 for i in range(0,len(w1)+1): for j in range(0,len(w2)+1): for k in range(0,len(w3)+1): res=W-(i*w+j*(w+1)+k*(w+2)) if res<0 : continue tmp=sum(w1[: i])+sum(w2[: j])+sum(w3[: k])+sum(w4[: res//(w+3)]) ans=max(tmp,ans) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var W : OclAny := null; Sequence{n,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w1 : OclAny := null; var w2 : OclAny := null; var w3 : OclAny := null; var w4 : OclAny := null; Sequence{w1,w2,w3,w4} := Sequence{Sequence{},Sequence{},Sequence{},Sequence{}} ; var w : OclAny := null; var v : OclAny := null; Sequence{w,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((v) : w1) ; for _anon : Integer.subrange(0, n - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = w then ( execute ((b) : w1) ) else skip ; if a = w + 1 then ( execute ((b) : w2) ) else skip ; if a = w + 2 then ( execute ((b) : w3) ) else skip ; if a = w + 3 then ( execute ((b) : w4) ) else skip) ; for w_ : Sequence{w1}->union(Sequence{w2}->union(Sequence{w3}->union(Sequence{ w4 }))) do ( w_ := w_->sort()) ; var ans : int := 0 ; for i : Integer.subrange(0, (w1)->size() + 1-1) do ( for j : Integer.subrange(0, (w2)->size() + 1-1) do ( for k : Integer.subrange(0, (w3)->size() + 1-1) do ( var res : double := W - (i * w + j * (w + 1) + k * (w + 2)) ; if res < 0 then ( continue ) else skip ; var tmp : OclAny := (w1.subrange(1,i))->sum() + (w2.subrange(1,j))->sum() + (w3.subrange(1,k))->sum() + (w4.subrange(1,res div (w + 3)))->sum() ; ans := Set{tmp, ans}->max()))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculateSum(arr,n): if(n==0): return 0 s=arr[0] value=int(s) sum=value for i in range(2,n,2): s=arr[i] value=int(s) operation=arr[i-1][0] if(operation=='+'): sum+=value else : sum-=value return sum arr=["3","+","4","-","7","+","13"] n=len(arr) print(calculateSum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{"3"}->union(Sequence{"+"}->union(Sequence{"4"}->union(Sequence{"-"}->union(Sequence{"7"}->union(Sequence{"+"}->union(Sequence{ "13" })))))) ; n := (arr)->size() ; execute (calculateSum(arr, n))->display(); operation calculateSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return 0 ) else skip ; var s : OclAny := arr->first() ; var value : int := ("" + ((s)))->toInteger() ; var sum : int := value ; for i : Integer.subrange(2, n-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( s := arr[i+1] ; value := ("" + ((s)))->toInteger() ; var operation : OclAny := arr[i - 1+1]->first() ; if (operation = '+') then ( sum := sum + value ) else ( sum := sum - value )) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isFascinating(num): freq=[0]*10 val=(str(num)+str(num*2)+str(num*3)) for i in range(len(val)): digit=int(val[i]) if freq[digit]>0 : return False else : freq[digit]+=1 for i in range(1,10): if freq[i]==0 : return False return True if __name__=="__main__" : num=192 if num<100 : print("No") else : ans=isFascinating(num) if ans : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( num := 192 ; if num < 100 then ( execute ("No")->display() ) else ( var ans : OclAny := isFascinating(num) ; if ans then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) ) else skip; operation isFascinating(num : OclAny) : OclAny pre: true post: true activity: var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; var val : String := (("" + ((num))) + ("" + ((num * 2))) + ("" + ((num * 3)))) ; for i : Integer.subrange(0, (val)->size()-1) do ( var digit : int := ("" + ((val[i+1])))->toInteger() ; if freq[digit+1] > 0 then ( return false ) else ( freq[digit+1] := freq[digit+1] + 1 )) ; for i : Integer.subrange(1, 10-1) do ( if freq[i+1] = 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import os for s in sys.stdin : n=int(s) if n==0 : break costs=[] for a in range(0,26): for b in range(0,17): for c in range(0,11): if a*200+b*300+c*500==n : cost=0 a_bulk_num=a//5 a_price_down_num=a_bulk_num*5 a_normal_price_num=a-a_price_down_num cost+=380*0.8*a_price_down_num+380*a_normal_price_num b_bulk_num=b//4 b_price_down_num=b_bulk_num*4 b_normal_price_num=b-b_price_down_num cost+=550*0.85*b_price_down_num+550*b_normal_price_num c_bulk_num=c//3 c_price_down_num=c_bulk_num*3 c_normal_price_num=c-c_price_down_num cost+=850*0.88*c_price_down_num+850*c_normal_price_num costs.append(cost) print(int(min(costs))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for s : OclFile["System.in"] do ( var n : int := ("" + ((s)))->toInteger() ; if n = 0 then ( break ) else skip ; var costs : Sequence := Sequence{} ; for a : Integer.subrange(0, 26-1) do ( for b : Integer.subrange(0, 17-1) do ( for c : Integer.subrange(0, 11-1) do ( if a * 200 + b * 300 + c * 500 = n then ( var cost : int := 0 ; var a_bulk_num : int := a div 5 ; var a_price_down_num : int := a_bulk_num * 5 ; var a_normal_price_num : double := a - a_price_down_num ; cost := cost + 380 * 0.8 * a_price_down_num + 380 * a_normal_price_num ; var b_bulk_num : int := b div 4 ; var b_price_down_num : int := b_bulk_num * 4 ; var b_normal_price_num : double := b - b_price_down_num ; cost := cost + 550 * 0.85 * b_price_down_num + 550 * b_normal_price_num ; var c_bulk_num : int := c div 3 ; var c_price_down_num : int := c_bulk_num * 3 ; var c_normal_price_num : double := c - c_price_down_num ; cost := cost + 850 * 0.88 * c_price_down_num + 850 * c_normal_price_num ; execute ((cost) : costs) ) else skip))) ; execute (("" + (((costs)->min())))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- Soba=[[2,380],[3,550],[5,850],[10,1520],[12,1870],[15,2244]] while True : g=int(input()) if g==0 : break g_g=int(g/100) DP=[[10000 for j in range(g_g+1)]for i in range(7)] for i in range(7): DP[i][0]=0 for i in range(7): for j in range(g_g+1): if j-Soba[i-1][0]+1>=0 : DP[i][j]=min(DP[i-1][j],DP[i][j-Soba[i-1][0]]+Soba[i-1][1]) else : DP[i][j]=DP[i-1][j] print(DP[6][g_g]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Soba : Sequence := Sequence{Sequence{2}->union(Sequence{ 380 })}->union(Sequence{Sequence{3}->union(Sequence{ 550 })}->union(Sequence{Sequence{5}->union(Sequence{ 850 })}->union(Sequence{Sequence{10}->union(Sequence{ 1520 })}->union(Sequence{Sequence{12}->union(Sequence{ 1870 })}->union(Sequence{ Sequence{15}->union(Sequence{ 2244 }) }))))) ; while true do ( var g : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if g = 0 then ( break ) else skip ; var g_g : int := ("" + ((g / 100)))->toInteger() ; var DP : Sequence := Integer.subrange(0, 7-1)->select(i | true)->collect(i | (Integer.subrange(0, g_g + 1-1)->select(j | true)->collect(j | (10000)))) ; for i : Integer.subrange(0, 7-1) do ( DP[i+1]->first() := 0) ; for i : Integer.subrange(0, 7-1) do ( for j : Integer.subrange(0, g_g + 1-1) do ( if j - Soba[i - 1+1]->first() + 1 >= 0 then ( DP[i+1][j+1] := Set{DP[i - 1+1][j+1], DP[i+1][j - Soba[i - 1+1]->first()+1] + Soba[i - 1+1][1+1]}->min() ) else ( DP[i+1][j+1] := DP[i - 1+1][j+1] ))) ; execute (DP[6+1][g_g+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : try : inp=int(input()) if inp==0 : break m_list=[] for i in range(4): for j in range(5): for k in range(6): for l in range(3): for m in range(4): for n in range(5): if i*1500+j*1200+k*1000+l*500+m*300+n*200==inp : m_list.append(i*2244+j*1870+k*1520+l*850+m*550+n*380) print(min(m_list)) except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( try ( var inp : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if inp = 0 then ( break ) else skip ; var m_list : Sequence := Sequence{} ; for i : Integer.subrange(0, 4-1) do ( for j : Integer.subrange(0, 5-1) do ( for k : Integer.subrange(0, 6-1) do ( for l : Integer.subrange(0, 3-1) do ( for m : Integer.subrange(0, 4-1) do ( for n : Integer.subrange(0, 5-1) do ( if i * 1500 + j * 1200 + k * 1000 + l * 500 + m * 300 + n * 200 = inp then ( execute ((i * 2244 + j * 1870 + k * 1520 + l * 850 + m * 550 + n * 380) : m_list) ) else skip)))))) ; execute ((m_list)->min())->display()) catch (_e : OclException) do ( break) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def price(pack,unit_price,units,off): return pack//units*units*unit_price*(1.-off)+pack % units*unit_price def solve(): while True : w=int(sys.stdin.readline()) if w==0 : return min=max([380*25,550*17,850*10]) for a in range(0,w//200+1): need=w-a*200 for b in range(0,need//300+1): if((need-b*300)% 500!=0): continue c=(need-b*300)//500 p=price(a,380,5,0.2)+price(b,550,4,0.15)+price(c,850,3,0.12) if ptoInteger() ; if w = 0 then ( return ) else skip ; var min : OclAny := (Sequence{380 * 25}->union(Sequence{550 * 17}->union(Sequence{ 850 * 10 })))->max() ; for a : Integer.subrange(0, w div 200 + 1-1) do ( var need : double := w - a * 200 ; for b : Integer.subrange(0, need div 300 + 1-1) do ( if ((need - b * 300) mod 500 /= 0) then ( continue ) else skip ; var c : int := (need - b * 300) div 500 ; var p : OclAny := price(a, 380, 5, 0.2) + price(b, 550, 4, 0.15) + price(c, 850, 3, 0.12) ; if (p->compareTo(min)) < 0 then ( min := p ) else skip)) ; execute (StringLib.interpolateStrings("{:.0f}", Sequence{min}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import division,print_function from sys import stdin,exit def main(readline=stdin.readline): price_table=(0,0,380,550,760,850,1100,1230,1400,1610,1520,1950,1870,2070,2250,2244,2620,2624,2794,3004,3040,3344,3390,3590,3740,3764,4120,4114,4314,4494,4488,4864,4868,5038,5248,5284,5588,5634,5834,5984,6008,6364,6358,6558,6738,6732,7108,7112,7282,7492,7528) while 1 : weight=int(readline()) if not weight : exit() print(price_table[weight//100]) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main(readline : OclAny) pre: true post: true activity: if readline->oclIsUndefined() then readline := stdin.readline else skip; var price_table : OclAny := Sequence{0, 0, 380, 550, 760, 850, 1100, 1230, 1400, 1610, 1520, 1950, 1870, 2070, 2250, 2244, 2620, 2624, 2794, 3004, 3040, 3344, 3390, 3590, 3740, 3764, 4120, 4114, 4314, 4494, 4488, 4864, 4868, 5038, 5248, 5284, 5588, 5634, 5834, 5984, 6008, 6364, 6358, 6558, 6738, 6732, 7108, 7112, 7282, 7492, 7528} ; while 1 do ( var weight : int := ("" + ((readline())))->toInteger() ; if not(weight) then ( exit() ) else skip ; execute (price_table[weight div 100+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def plot(x,y): print(f'{x:.8f}{y:.8f}') def Koch(n,x1,y1,x2,y2): if n==0 : plot(x1,y1) return sx=(2*x1+x2)/3 sy=(2*y1+y2)/3 tx=(x1+2*x2)/3 ty=(y1+2*y2)/3 ux=(tx-sx)*(1/2)-(ty-sy)*(math.sqrt(3)/2)+sx uy=(tx-sx)*(math.sqrt(3)/2)+(ty-sy)*(1/2)+sy Koch(n-1,x1,y1,sx,sy) Koch(n-1,sx,sy,ux,uy) Koch(n-1,ux,uy,tx,ty) Koch(n-1,tx,ty,x2,y2) n=int(input()) Koch(n,0,0,100,0) plot(100,0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; Koch(n, 0, 0, 100, 0) ; plot(100, 0); operation plot(x : OclAny, y : OclAny) pre: true post: true activity: execute (StringLib.formattedString('{x:.8f}{y:.8f}'))->display(); operation Koch(n : OclAny, x1 : OclAny, y1 : OclAny, x2 : OclAny, y2 : OclAny) pre: true post: true activity: if n = 0 then ( plot(x1, y1) ; return ) else skip ; var sx : double := (2 * x1 + x2) / 3 ; var sy : double := (2 * y1 + y2) / 3 ; var tx : double := (x1 + 2 * x2) / 3 ; var ty : double := (y1 + 2 * y2) / 3 ; var ux : double := (tx - sx) * (1 / 2) - (ty - sy) * ((3)->sqrt() / 2) + sx ; var uy : double := (tx - sx) * ((3)->sqrt() / 2) + (ty - sy) * (1 / 2) + sy ; Koch(n - 1, x1, y1, sx, sy) ; Koch(n - 1, sx, sy, ux, uy) ; Koch(n - 1, ux, uy, tx, ty) ; Koch(n - 1, tx, ty, x2, y2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def foot(a,b,c,d,x1,y1,z1): k=(-a*x1-b*y1-c*z1-d)/(a*a+b*b+c*c); x2=a*k+x1 ; y2=b*k+y1 ; z2=c*k+z1 ; print("x2=",round(x2,1)) print("y2=",round(y2,1)) print("z2=",round(z2,1)) if __name__=="__main__" : a=1 b=-2 c=0 d=0 x1=-1 y1=3 z1=4 foot(a,b,c,d,x1,y1,z1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := 1 ; b := -2 ; c := 0 ; d := 0 ; x1 := -1 ; y1 := 3 ; z1 := 4 ; foot(a, b, c, d, x1, y1, z1) ) else skip; operation foot(a : OclAny, b : OclAny, c : OclAny, d : OclAny, x1 : OclAny, y1 : OclAny, z1 : OclAny) pre: true post: true activity: var k : double := (-a * x1 - b * y1 - c * z1 - d) / (a * a + b * b + c * c); ; var x2 : double := a * k + x1; ; var y2 : double := b * k + y1; ; var z2 : double := c * k + z1; ; execute ("x2=")->display() ; execute ("y2=")->display() ; execute ("z2=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=list(map(int,input().split())) b=[["W",1]for _ in range(n)] b[0]=["R",1] for i in range(m): x,y=list(map(int,input().split())) b[x-1][1]-=1 if b[x-1][0]=="R" : b[y-1]=["R",b[y-1][1]+1] if b[x-1][1]==0 : b[x-1][0]="W" else : b[y-1][1]+=1 cnt=0 for i in range(n): if b[i][0]=="R" : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{"W"}->union(Sequence{ 1 }))) ; b->first() := Sequence{"R"}->union(Sequence{ 1 }) ; for i : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; b[x - 1+1][1+1] := b[x - 1+1][1+1] - 1 ; if b[x - 1+1]->first() = "R" then ( b[y - 1+1] := Sequence{"R"}->union(Sequence{ b[y - 1+1][1+1] + 1 }) ; if b[x - 1+1][1+1] = 0 then ( b[x - 1+1]->first() := "W" ) else skip ) else ( b[y - 1+1][1+1] := b[y - 1+1][1+1] + 1 )) ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( if b[i+1]->first() = "R" then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findPermutation(n): res=[] en,on=2,1 if(n % 2==0): for i in range(n): if(i % 2==0): res.append(en) en+=2 else : res.append(on) on+=2 else : for i in range(n-2): if(i % 2==0): res.append(en) en+=2 else : res.append(on) on+=2 res.append(n) res.append(n-2) for i in range(n): print(res[i],end=" ") print() if __name__=="__main__" : n=9 ; findPermutation(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 9; ; findPermutation(n) ) else skip; operation findPermutation(n : OclAny) pre: true post: true activity: var res : Sequence := Sequence{} ; var en : OclAny := null; var on : OclAny := null; Sequence{en,on} := Sequence{2,1} ; if (n mod 2 = 0) then ( for i : Integer.subrange(0, n-1) do ( if (i mod 2 = 0) then ( execute ((en) : res) ; en := en + 2 ) else ( execute ((on) : res) ; on := on + 2 )) ) else ( for i : Integer.subrange(0, n - 2-1) do ( if (i mod 2 = 0) then ( execute ((en) : res) ; en := en + 2 ) else ( execute ((on) : res) ; on := on + 2 )) ; execute ((n) : res) ; execute ((n - 2) : res) ) ; for i : Integer.subrange(0, n-1) do ( execute (res[i+1])->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(): global d p=[d[0]] for i in range(len(d)-1): a,b=d[i],d[i+1] r=(b-a)/3 p+=[a+r,a+r+r*(1+3**.5*1j)/2,b-r,b] d=p d=[0j,100+0j] for _ in[0]*int(input()): f() for e in d : print(e.real,e.imag) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute d : OclAny; operation initialise() pre: true post: true activity: skip ; d := Sequence{0j}->union(Sequence{ 100 + 0j }) ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( f()) ; for e : d do ( execute (e.real)->display()); operation f() pre: true post: true activity: skip ; var p : Sequence := Sequence{ d->first() } ; for i : Integer.subrange(0, (d)->size() - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{d[i+1],d[i + 1+1]} ; var r : double := (b - a) / 3 ; p := p + Sequence{a + r}->union(Sequence{a + r + r * (1 + (3)->pow(.5) * 1j) / 2}->union(Sequence{b - r}->union(Sequence{ b })))) ; d := p; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def rot60_on_complex_plane(start : complex,end : complex)->complex : v=end-start arg=1/2+complex(0,(math.sqrt(3)/2)) return v*arg+start def print_real_coordinate(z : complex)->None : x=z.real y=z.imag print(f"{x:.8f}{y:.8f}") def create_koch_points(p1 : complex,p2 : complex,n : int)->None : if n==0 : return s=(p2-p1)*(1/3)+p1 t=(p2-p1)*(2/3)+p1 u=rot60_on_complex_plane(s,t) create_koch_points(p1,s,n-1) print_real_coordinate(s) create_koch_points(s,u,n-1) print_real_coordinate(u) create_koch_points(u,t,n-1) print_real_coordinate(t) create_koch_points(t,p2,n-1) if __name__=="__main__" : n=int(input()) start_point=(0+0j) end_point=(100+0j) print_real_coordinate(start_point) create_koch_points(start_point,end_point,n) print_real_coordinate(end_point) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var start_point : int := (0 + 0j) ; var end_point : int := (100 + 0j) ; print_real_coordinate(start_point) ; create_koch_points(start_point, end_point, n) ; print_real_coordinate(end_point) ) else skip; operation rot60_on_complex_plane(start : complex, end : complex) : OclAny pre: true post: true activity: var v : double := end - start ; var arg : double := 1 / 2 + complex(0, ((3)->sqrt() / 2)) ; return v * arg + start; operation print_real_coordinate(z : complex) : OclAny pre: true post: true activity: var x : OclAny := z.real ; var y : OclAny := z.imag ; execute (StringLib.formattedString("{x:.8f}{y:.8f}"))->display(); operation create_koch_points(p1 : complex, p2 : complex, n : int) : OclAny pre: true post: true activity: if n = 0 then ( return ) else skip ; var s : double := (p2 - p1) * (1 / 3) + p1 ; var t : double := (p2 - p1) * (2 / 3) + p1 ; var u : OclAny := rot60_on_complex_plane(s, t) ; create_koch_points(p1, s, n - 1) ; print_real_coordinate(s) ; create_koch_points(s, u, n - 1) ; print_real_coordinate(u) ; create_koch_points(u, t, n - 1) ; print_real_coordinate(t) ; create_koch_points(t, p2, n - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def divide_segment(left,right): delta_x_quarter=(right[0]-left[0])/3.0 delta_y_quarter=(right[1]-left[1])/3.0 delta_x_quarter_rotated=(delta_x_quarter-math.sqrt(3)*delta_y_quarter)/2.0 delta_y_quarter_rotated=(math.sqrt(3)*delta_x_quarter+delta_y_quarter)/2.0 s=[left[0]+delta_x_quarter,left[1]+delta_y_quarter] t=[left[0]+delta_x_quarter*2.0,left[1]+delta_y_quarter*2.0] u=[s[0]+delta_x_quarter_rotated,s[1]+delta_y_quarter_rotated] return s,t,u def make_coch_curve(depth,left,right): print("{0:2.8f}{1:2.8f}".format(left[0],left[1])) if depth==0 : print("{0:2.8f}{1:2.8f}".format(right[0],right[1])) else : make_coch_curve_recursively(depth-1,left,right) def make_coch_curve_recursively(depth,left,right): s,t,u=divide_segment(left,right) if depth==0 : print("{0:2.8f}{1:2.8f}".format(s[0],s[1])) print("{0:2.8f}{1:2.8f}".format(u[0],u[1])) print("{0:2.8f}{1:2.8f}".format(t[0],t[1])) print("{0:2.8f}{1:2.8f}".format(right[0],right[1])) else : make_coch_curve_recursively(depth-1,left,s) make_coch_curve_recursively(depth-1,s,u) make_coch_curve_recursively(depth-1,u,t) make_coch_curve_recursively(depth-1,t,right) def main(): depth=int(input().strip()) make_coch_curve(depth,left=[0.0,0.0],right=[100.0,0.0]) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation divide_segment(left : OclAny, right : OclAny) : OclAny pre: true post: true activity: var delta_x_quarter : double := (right->first() - left->first()) / 3.0 ; var delta_y_quarter : double := (right[1+1] - left[1+1]) / 3.0 ; var delta_x_quarter_rotated : double := (delta_x_quarter - (3)->sqrt() * delta_y_quarter) / 2.0 ; var delta_y_quarter_rotated : double := ((3)->sqrt() * delta_x_quarter + delta_y_quarter) / 2.0 ; var s : Sequence := Sequence{left->first() + delta_x_quarter}->union(Sequence{ left[1+1] + delta_y_quarter }) ; var t : Sequence := Sequence{left->first() + delta_x_quarter * 2.0}->union(Sequence{ left[1+1] + delta_y_quarter * 2.0 }) ; var u : Sequence := Sequence{s->first() + delta_x_quarter_rotated}->union(Sequence{ s[1+1] + delta_y_quarter_rotated }) ; return s, t, u; operation make_coch_curve(depth : OclAny, left : OclAny, right : OclAny) pre: true post: true activity: execute (StringLib.interpolateStrings("{0:2.8f}{1:2.8f}", Sequence{left->first(), left[1+1]}))->display() ; if depth = 0 then ( execute (StringLib.interpolateStrings("{0:2.8f}{1:2.8f}", Sequence{right->first(), right[1+1]}))->display() ) else ( make_coch_curve_recursively(depth - 1, left, right) ); operation make_coch_curve_recursively(depth : OclAny, left : OclAny, right : OclAny) pre: true post: true activity: Sequence{s,t,u} := divide_segment(left, right) ; if depth = 0 then ( execute (StringLib.interpolateStrings("{0:2.8f}{1:2.8f}", Sequence{s->first(), s[1+1]}))->display() ; execute (StringLib.interpolateStrings("{0:2.8f}{1:2.8f}", Sequence{u->first(), u[1+1]}))->display() ; execute (StringLib.interpolateStrings("{0:2.8f}{1:2.8f}", Sequence{t->first(), t[1+1]}))->display() ; execute (StringLib.interpolateStrings("{0:2.8f}{1:2.8f}", Sequence{right->first(), right[1+1]}))->display() ) else ( make_coch_curve_recursively(depth - 1, left, s) ; make_coch_curve_recursively(depth - 1, s, u) ; make_coch_curve_recursively(depth - 1, u, t) ; make_coch_curve_recursively(depth - 1, t, right) ); operation main() pre: true post: true activity: depth := ("" + ((input()->trim())))->toInteger() ; make_coch_curve(depth, (argument (test (logical_test (comparison (expr (atom (name left)))))) = (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number 0.0)))))) , (test (logical_test (comparison (expr (atom (number 0.0))))))) ])))))), (argument (test (logical_test (comparison (expr (atom (name right)))))) = (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number 100.0)))))) , (test (logical_test (comparison (expr (atom (number 0.0))))))) ]))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) from math import sin,cos,pi th=pi/3 def koch(d,p1,p2): if d==0 : return s=[0,0] t=[0,0] u=[0,0] s[0]=(2*p1[0]+p2[0])/3 s[1]=(2*p1[1]+p2[1])/3 t[0]=(2*p2[0]+p1[0])/3 t[1]=(2*p2[1]+p1[1])/3 u[0]=(t[0]-s[0])*cos(th)-(t[1]-s[1])*sin(th)+s[0] u[1]=(t[0]-s[0])*sin(th)+(t[1]-s[1])*cos(th)+s[1] koch(d-1,p1,s) print(*s) koch(d-1,s,u) print(*u) koch(d-1,u,t) print(*t) koch(d-1,t,p2) p_start=[0.0,0.0] p_end=[100.0,0.0] print(*p_start) koch(N,p_start,p_end) print(*p_end) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; var th : double := pi / 3 ; skip ; var p_start : Sequence := Sequence{0.0}->union(Sequence{ 0.0 }) ; var p_end : Sequence := Sequence{100.0}->union(Sequence{ 0.0 }) ; execute ((argument * (test (logical_test (comparison (expr (atom (name p_start))))))))->display() ; koch(N, p_start, p_end) ; execute ((argument * (test (logical_test (comparison (expr (atom (name p_end))))))))->display(); operation koch(d : OclAny, p1 : OclAny, p2 : OclAny) pre: true post: true activity: if d = 0 then ( return ) else skip ; var s : Sequence := Sequence{0}->union(Sequence{ 0 }) ; var t : Sequence := Sequence{0}->union(Sequence{ 0 }) ; var u : Sequence := Sequence{0}->union(Sequence{ 0 }) ; s->first() := (2 * p1->first() + p2->first()) / 3 ; s[1+1] := (2 * p1[1+1] + p2[1+1]) / 3 ; t->first() := (2 * p2->first() + p1->first()) / 3 ; t[1+1] := (2 * p2[1+1] + p1[1+1]) / 3 ; u->first() := (t->first() - s->first()) * cos(th) - (t[1+1] - s[1+1]) * sin(th) + s->first() ; u[1+1] := (t->first() - s->first()) * sin(th) + (t[1+1] - s[1+1]) * cos(th) + s[1+1] ; koch(d - 1, p1, s) ; execute ((argument * (test (logical_test (comparison (expr (atom (name s))))))))->display() ; koch(d - 1, s, u) ; execute ((argument * (test (logical_test (comparison (expr (atom (name u))))))))->display() ; koch(d - 1, u, t) ; execute ((argument * (test (logical_test (comparison (expr (atom (name t))))))))->display() ; koch(d - 1, t, p2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def composite_factors(n): count=0 ; a=[0]*(n+1); for i in range(1,n+1): if(n % i==0): a[i]=i ; for i in range(2,n+1): j=2 ; p=1 ; while(jdisplay(); ) else skip; operation composite_factors(n : OclAny) pre: true post: true activity: var count : int := 0; ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); ; for i : Integer.subrange(1, n + 1-1) do ( if (n mod i = 0) then ( a[i+1] := i; ) else skip) ; for i : Integer.subrange(2, n + 1-1) do ( var j : int := 2; ; var p : int := 1; ; while ((j->compareTo(a[i+1])) < 0) do ( if (a[i+1] mod j = 0) then ( p := 0; ; break; ) else skip ; j := j + 1;) ; if (p = 0 & a[i+1] /= 0) then ( count := count + 1; ) else skip) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def findSubarraySum(arr,n,Sum): prevSum=defaultdict(lambda : 0) res=0 currsum=0 for i in range(0,n): currsum+=arr[i] if currsum==Sum : res+=1 if(currsum-Sum)in prevSum : res+=prevSum[currsum-Sum] prevSum[currsum]+=1 return res if __name__=="__main__" : arr=[10,2,-2,-20,10] Sum=-10 n=len(arr) print(findSubarraySum(arr,n,Sum)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{10}->union(Sequence{2}->union(Sequence{-2}->union(Sequence{-20}->union(Sequence{ 10 })))) ; Sum := -10 ; n := (arr)->size() ; execute (findSubarraySum(arr, n, Sum))->display() ) else skip; operation findSubarraySum(arr : OclAny, n : OclAny, Sum : OclAny) : OclAny pre: true post: true activity: var prevSum : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; var res : int := 0 ; var currsum : int := 0 ; for i : Integer.subrange(0, n-1) do ( currsum := currsum + arr[i+1] ; if currsum = Sum then ( res := res + 1 ) else skip ; if (prevSum)->includes((currsum - Sum)) then ( res := res + prevSum[currsum - Sum+1] ) else skip ; prevSum[currsum+1] := prevSum[currsum+1] + 1) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): lamps=list(map(int,input().split(' '))) lamps.sort(reverse=True) if lamps[0]<=lamps[1]+lamps[2]+1 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var lamps : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; lamps := lamps->sort() ; if (lamps->first()->compareTo(lamps[1+1] + lamps[2+1] + 1)) <= 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): a=sorted(list(map(int,input().split()))) print('Yes' if a[2]<=a[0]+a[1]+1 else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; execute (if (a[2+1]->compareTo(a->first() + a[1+1] + 1)) <= 0 then 'Yes' else 'No' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): l=list(map(int,input().split(" "))) maximum=max(l) minimum=min(l) if(maximum-(sum(l)-maximum))<2 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var l : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var maximum : OclAny := (l)->max() ; var minimum : OclAny := (l)->min() ; if (maximum - ((l)->sum() - maximum)) < 2 then ( execute ("Yes")->display() ) else ( execute ("No")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(i)for i in input().split()] x=[0 for i in range(m)] y=[0 for i in range(m)] ans=[0 for i in range(n)] count=[1 for i in range(n)] ans[0]=1 for i in range(m): x[i],y[i]=[int(i)for i in input().split()] for i in range(m): count[x[i]-1]-=1 count[y[i]-1]+=1 if ans[x[i]-1]==1 : ans[y[i]-1]=1 if count[x[i]-1]==0 : ans[x[i]-1]=0 print(sum(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var x : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (0)) ; var y : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (0)) ; var ans : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var count : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (1)) ; ans->first() := 1 ; for i : Integer.subrange(0, m-1) do ( var x[i+1] : OclAny := null; var y[i+1] : OclAny := null; Sequence{x[i+1],y[i+1]} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))) ; for i : Integer.subrange(0, m-1) do ( count[x[i+1] - 1+1] := count[x[i+1] - 1+1] - 1 ; count[y[i+1] - 1+1] := count[y[i+1] - 1+1] + 1 ; if ans[x[i+1] - 1+1] = 1 then ( ans[y[i+1] - 1+1] := 1 ) else skip ; if count[x[i+1] - 1+1] = 0 then ( ans[x[i+1] - 1+1] := 0 ) else skip) ; execute ((ans)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): a=sorted(list(map(int,input().split()))) print('Yes' if a[2]<=a[0]+a[1]+1 else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; execute (if (a[2+1]->compareTo(a->first() + a[1+1] + 1)) <= 0 then 'Yes' else 'No' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def SUM(x,n): total=1 for i in range(1,n+1): total=total+((x**i)/i) return total x=2 n=5 s=SUM(x,n) print(round(s,2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := 2 ; n := 5 ; var s : OclAny := SUM(x, n) ; execute (MathLib.roundN(s, 2))->display(); operation SUM(x : OclAny, n : OclAny) : OclAny pre: true post: true activity: var total : int := 1 ; for i : Integer.subrange(1, n + 1-1) do ( total := total + (((x)->pow(i)) / i)) ; return total; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for j in range(t): sp=list(map(int,input().split())) sp.sort() if sp[2]-(sp[1]+sp[0])<=1 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, t-1) do ( var sp : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; sp := sp->sort() ; if sp[2+1] - (sp[1+1] + sp->first()) <= 1 then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : n=eval(input()) is_prime=[True for _ in range(n+1)] is_prime[1]=False for i in range(2,int((n+1)/2)): if is_prime[i]: for j in range(i*2,n+1,i): is_prime[j]=False is_prime_rev=list(is_prime) is_prime_rev.reverse() count=0 for i in range(1,n+1): count=count+(1 if is_prime[i]and is_prime_rev[i-1]else 0) print(count) except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var n : OclAny := (OclFile["System.in"]).readLine() ; var is_prime : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (true)) ; is_prime[1+1] := false ; for i : Integer.subrange(2, ("" + (((n + 1) / 2)))->toInteger()-1) do ( if is_prime[i+1] then ( for j : Integer.subrange(i * 2, n + 1-1)->select( $x | ($x - i * 2) mod i = 0 ) do ( is_prime[j+1] := false) ) else skip) ; var is_prime_rev : Sequence := (is_prime) ; is_prime_rev := is_prime_rev->reverse() ; var count : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( count := count + (if is_prime[i+1] & is_prime_rev[i - 1+1] then 1 else 0 endif)) ; execute (count)->display()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math M=10001 size=(M-1)//2 l=[1]*size b=int(math.sqrt(M)+1) for i in range(3,b,2): index=(i-3)//2 if l[index]: l[index+i : : i]=[0]*len(l[index+i : : i]) m=[] for i in range(size): if l[i]: m.append(i) s="" p=[0,0,0,1] for i in sys.stdin : n=int(i) if n<=3 : print(p[n]) elif n % 2==0 : if l[(n-3)//2]: print(2) else : print(0) else : ct=0 n2=(n-5)//2 for j in m : if j>n2 : break if l[n2-j]: ct+=1 print(ct) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var M : int := 10001 ; var size : int := (M - 1) div 2 ; var l : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, size) ; var b : int := ("" + (((M)->sqrt() + 1)))->toInteger() ; for i : Integer.subrange(3, b-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( var index : int := (i - 3) div 2 ; if l[index+1] then ( l(subscript (test (logical_test (comparison (expr (expr (atom (name index))) + (expr (atom (name i))))))) : (sliceop : (test (logical_test (comparison (expr (atom (name i)))))))) := MatrixLib.elementwiseMult(Sequence{ 0 }, (l(subscript (test (logical_test (comparison (expr (expr (atom (name index))) + (expr (atom (name i))))))) : (sliceop : (test (logical_test (comparison (expr (atom (name i)))))))))->size()) ) else skip) ; var m : Sequence := Sequence{} ; for i : Integer.subrange(0, size-1) do ( if l[i+1] then ( execute ((i) : m) ) else skip) ; var s : String := "" ; var p : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 1 }))) ; for i : OclFile["System.in"] do ( var n : int := ("" + ((i)))->toInteger() ; if n <= 3 then ( execute (p[n+1])->display() ) else (if n mod 2 = 0 then ( if l[(n - 3) div 2+1] then ( execute (2)->display() ) else ( execute (0)->display() ) ) else ( var ct : int := 0 ; var n2 : int := (n - 5) div 2 ; for j : m do ( if (j->compareTo(n2)) > 0 then ( break ) else skip ; if l[n2 - j+1] then ( ct := ct + 1 ) else skip) ; execute (ct)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def is_prime(x): if((x % 2==0 and x>2)or x<2): return 0 elif(x<=5): return 1 a=3 while(a*a<=x): if(x % a==0): return 0 a+=2 return 1 l=[] for i in sys.stdin : l.append(int(i)) for data in l : count=0 data1=[i for i in range(1,data+1)] data2=[i for i in range(data,0,-1)] for i in range(0,data): count+=1 if(is_prime(data1[i])==1 and is_prime(data2[i])==1)else 0 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var l : Sequence := Sequence{} ; for i : OclFile["System.in"] do ( execute ((("" + ((i)))->toInteger()) : l)) ; for data : l do ( var count : int := 0 ; var data1 : Sequence := Integer.subrange(1, data + 1-1)->select(i | true)->collect(i | (i)) ; var data2 : Sequence := Integer.subrange(0 + 1, data)->reverse()->select(i | true)->collect(i | (i)) ; for i : Integer.subrange(0, data-1) do ( count := count + if (is_prime(data1[i+1]) = 1 & is_prime(data2[i+1]) = 1) then 1 else 0 endif) ; execute (count)->display()); operation is_prime(x : OclAny) : OclAny pre: true post: true activity: if ((x mod 2 = 0 & x > 2) or x < 2) then ( return 0 ) else (if (x <= 5) then ( return 1 ) else skip) ; var a : int := 3 ; while ((a * a->compareTo(x)) <= 0) do ( if (x mod a = 0) then ( return 0 ) else skip ; a := a + 2) ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as math def prime_checker(limit): n=0 prime_index=[] for k in range(2,limit+1): factor=0 if k % 2==0 and k!=2 : continue for divisor in range(2,math.floor(math.sqrt(k))+1): if k % divisor==0 : factor+=1 if factor==0 : prime_index.append(k) return prime_index def prime_checker2(limit): n=0 prime_index=[] for k in range(9754,limit+1): factor=0 if k % 2==0 and k!=2 : continue for divisor in range(2,math.floor(math.sqrt(k))+1): if k % divisor==0 : factor+=1 if factor==0 : prime_index.append(k) return prime_index all_primes=prime_checker(10000) while True : try : limit=int(input()) if limit==1 : print(0) else : li=list(range(1,limit+1,1)) li_r=list(reversed(li)) index_r=[] match_primes=[i for i in all_primes if i<=limit] index=match_primes index_r=[limit+1-j for j in match_primes] print(len(list(set(index)& set(index_r)))) except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var all_primes : OclAny := prime_checker(10000) ; while true do ( try ( limit := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if limit = 1 then ( execute (0)->display() ) else ( var li : Sequence := (Integer.subrange(1, limit + 1-1)->select( $x | ($x - 1) mod 1 = 0 )) ; var li_r : Sequence := ((li)->reverse()) ; var index_r : Sequence := Sequence{} ; var match_primes : Sequence := all_primes->select(i | (i->compareTo(limit)) <= 0)->collect(i | (i)) ; var index : Sequence := match_primes ; index_r := match_primes->select(j | true)->collect(j | (limit + 1 - j)) ; execute (((MathLib.bitwiseAnd(Set{}->union((index)), Set{}->union((index_r)))))->size())->display() )) catch (_e : OclException) do ( break) ); operation prime_checker(limit : OclAny) : OclAny pre: true post: true activity: var n : int := 0 ; var prime_index : Sequence := Sequence{} ; for k : Integer.subrange(2, limit + 1-1) do ( var factor : int := 0 ; if k mod 2 = 0 & k /= 2 then ( continue ) else skip ; for divisor : Integer.subrange(2, ((k)->sqrt())->floor() + 1-1) do ( if k mod divisor = 0 then ( factor := factor + 1 ) else skip) ; if factor = 0 then ( execute ((k) : prime_index) ) else skip) ; return prime_index; operation prime_checker2(limit : OclAny) : OclAny pre: true post: true activity: n := 0 ; prime_index := Sequence{} ; for k : Integer.subrange(9754, limit + 1-1) do ( factor := 0 ; if k mod 2 = 0 & k /= 2 then ( continue ) else skip ; for divisor : Integer.subrange(2, ((k)->sqrt())->floor() + 1-1) do ( if k mod divisor = 0 then ( factor := factor + 1 ) else skip) ; if factor = 0 then ( execute ((k) : prime_index) ) else skip) ; return prime_index; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import fileinput ps=set() for i in range(3,10001,2): for p in ps : if p>100 : continue if i % p==0 : break else : ps.add(i) i+=2 ps.add(2) for line in fileinput.input(): n=int(line) print(sum(i in ps and(n+1-i)in ps for i in range(2,n+1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var ps : Set := Set{}->union(()) ; for i : Integer.subrange(3, 10001-1)->select( $x | ($x - 3) mod 2 = 0 ) do ((compound_stmt for (exprlist (expr (atom (name p)))) in (testlist (test (logical_test (comparison (expr (atom (name ps))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name p)))) > (comparison (expr (atom (number (integer 100)))))))) : (suite (stmt (simple_stmt (small_stmt continue)))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name i))) % (expr (atom (name p))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ps)) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))))))))) ; i := i + 2) ; execute ((2) : ps) ; for line : fileinput.input() do ( var n : int := ("" + ((line)))->toInteger() ; execute (((argument (test (logical_test (logical_test (comparison (comparison (expr (atom (name i)))) in (comparison (expr (atom (name ps)))))) and (logical_test (comparison (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name n))) + (expr (atom (number (integer 1))))) - (expr (atom (name i)))))))) )))) in (comparison (expr (atom (name ps)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) )))))))))->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if not n : break poles=[tuple(map(int,input().split()))for _ in range(n)] poles_set=set(poles) max_square=0 for i in range(n): x1,y1=poles[i] for j in range(i,n): x2,y2=poles[j] dx,dy=x2-x1,y2-y1 if((x2+dy,y2-dx)in poles_set and(x1+dy,y1-dx)in poles_set)or((x2-dy,y2+dx)in poles_set and(x1-dy,y1+dx)in poles_set): edge=dx**2+dy**2 if max_squaretoInteger() ; if not(n) then ( break ) else skip ; var poles : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var poles_set : Set := Set{}->union((poles)) ; var max_square : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := poles[i+1] ; for j : Integer.subrange(i, n-1) do ( var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x2,y2} := poles[j+1] ; var dx : OclAny := null; var dy : OclAny := null; Sequence{dx,dy} := Sequence{x2 - x1,y2 - y1} ; if ((poles_set)->includes(Sequence{x2 + dy, y2 - dx}) & (poles_set)->includes(Sequence{x1 + dy, y1 - dx})) or ((poles_set)->includes(Sequence{x2 - dy, y2 + dx}) & (poles_set)->includes(Sequence{x1 - dy, y1 + dx})) then ( var edge : double := (dx)->pow(2) + (dy)->pow(2) ; if (max_square->compareTo(edge)) < 0 then ( max_square := edge ) else skip ) else skip)) ; execute (max_square)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): while True : n=int(input()) if not n : break ps=[] dic={} for i in range(n): x,y=map(int,input().split()) dic[(x,y)]=1 ; ps.append((x,y)) ans=0 for i in range(n): for j in range(n): p1=ps[i] p2=ps[j] p1x=p1[0] p1y=p1[1] p2x=p2[0] p2y=p2[1] vx=p2x-p1x vy=p2y-p1y if(p1x+vy,p1y-vx)in dic and(p2x+vy,p2y-vx)in dic : ans=max(ans,vx**2+vy**2) print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(n) then ( break ) else skip ; var ps : Sequence := Sequence{} ; var dic : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; dic[Sequence{x, y}+1] := 1; ; execute ((Sequence{x, y}) : ps)) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( var p1 : OclAny := ps[i+1] ; var p2 : OclAny := ps[j+1] ; var p1x : OclAny := p1->first() ; var p1y : OclAny := p1[1+1] ; var p2x : OclAny := p2->first() ; var p2y : OclAny := p2[1+1] ; var vx : double := p2x - p1x ; var vy : double := p2y - p1y ; if (dic)->includes(Sequence{p1x + vy, p1y - vx}) & (dic)->includes(Sequence{p2x + vy, p2y - vx}) then ( ans := Set{ans, (vx)->pow(2) + (vy)->pow(2)}->max() ) else skip)) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,radians from itertools import accumulate,permutations,combinations,product from operator import itemgetter,mul from copy import deepcopy from string import ascii_lowercase,ascii_uppercase,digits from bisect import bisect,bisect_left from fractions import gcd from heapq import heappush,heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) def ZIP(n): return zip(*(MAP()for _ in range(n))) sys.setrecursionlimit(10**9) INF=float('inf') mod=10**9+7 N,M=MAP() balls=[[1,0]for _ in range(N)] balls[0]=[0,1] for _ in range(M): x,y=MAP() w_x,r_x=balls[x-1] w_y,r_y=balls[y-1] if w_x>=1 and r_x>=1 : balls[x-1][0]-=1 balls[y-1][1]+=1 elif w_x==0 : balls[x-1][1]-=1 balls[y-1][1]+=1 else : balls[x-1][0]-=1 balls[y-1][0]+=1 ans=0 for i in range(N): if balls[i][1]: ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := MAP() ; var balls : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Sequence{1}->union(Sequence{ 0 }))) ; balls->first() := Sequence{0}->union(Sequence{ 1 }) ; for _anon : Integer.subrange(0, M-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := MAP() ; var w_x : OclAny := null; var r_x : OclAny := null; Sequence{w_x,r_x} := balls[x - 1+1] ; var w_y : OclAny := null; var r_y : OclAny := null; Sequence{w_y,r_y} := balls[y - 1+1] ; if w_x >= 1 & r_x >= 1 then ( balls[x - 1+1]->first() := balls[x - 1+1]->first() - 1 ; balls[y - 1+1][1+1] := balls[y - 1+1][1+1] + 1 ) else (if w_x = 0 then ( balls[x - 1+1][1+1] := balls[x - 1+1][1+1] - 1 ; balls[y - 1+1][1+1] := balls[y - 1+1][1+1] + 1 ) else ( balls[x - 1+1]->first() := balls[x - 1+1]->first() - 1 ; balls[y - 1+1]->first() := balls[y - 1+1]->first() + 1 ) ) ) ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( if balls[i+1][1+1] then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ZIP(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))`third->at(_indx)} ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): while True : n=int(input()) if not n : break ps=[list(map(int,input().split()))for i in range(n)] dic=set() for t in ps : dic.add((t[0],t[1])) ans=0 for i in range(n): p1=ps[i] p1x=p1[0] p1y=p1[1] for j in range(n): p2=ps[j] p2x=p2[0] p2y=p2[1] vx=p2x-p1x vy=p2y-p1y if(p1x+vy,p1y-vx)in dic and(p2x+vy,p2y-vx)in dic : ans=max(ans,vx**2+vy**2) print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(n) then ( break ) else skip ; var ps : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var dic : Set := Set{}->union(()) ; for t : ps do ( execute ((Sequence{t->first(), t[1+1]}) : dic)) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var p1 : OclAny := ps[i+1] ; var p1x : OclAny := p1->first() ; var p1y : OclAny := p1[1+1] ; for j : Integer.subrange(0, n-1) do ( var p2 : OclAny := ps[j+1] ; var p2x : OclAny := p2->first() ; var p2y : OclAny := p2[1+1] ; var vx : double := p2x - p1x ; var vy : double := p2y - p1y ; if (dic)->includes(Sequence{p1x + vy, p1y - vx}) & (dic)->includes(Sequence{p2x + vy, p2y - vx}) then ( ans := Set{ans, (vx)->pow(2) + (vy)->pow(2)}->max() ) else skip)) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): while True : n=int(input()) if not n : break ps=[] dic={} for i in range(n): x,y=map(int,input().split()) dic[(x,y)]=1 ; ps.append((x,y)) ans=0 for i in range(n): for j in range(n): p1=ps[i] p2=ps[j] vx=p2[0]-p1[0] vy=p2[1]-p1[1] if(p1[0]+vy,p1[1]-vx)in dic and(p2[0]+vy,p2[1]-vx)in dic : ans=max(ans,vx**2+vy**2) print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(n) then ( break ) else skip ; var ps : Sequence := Sequence{} ; var dic : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; dic[Sequence{x, y}+1] := 1; ; execute ((Sequence{x, y}) : ps)) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( var p1 : OclAny := ps[i+1] ; var p2 : OclAny := ps[j+1] ; var vx : double := p2->first() - p1->first() ; var vy : double := p2[1+1] - p1[1+1] ; if (dic)->includes(Sequence{p1->first() + vy, p1[1+1] - vx}) & (dic)->includes(Sequence{p2->first() + vy, p2[1+1] - vx}) then ( ans := Set{ans, (vx)->pow(2) + (vy)->pow(2)}->max() ) else skip)) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pattern(n): k=1 for i in range(1,n+1): p=k for j in range(1,i+1): print(p,end="") p=p-(n+j-i) print("") k=k+1+n-i n=5 pattern(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; pattern(n); operation pattern(n : OclAny) pre: true post: true activity: var k : int := 1 ; for i : Integer.subrange(1, n + 1-1) do ( var p : int := k ; for j : Integer.subrange(1, i + 1-1) do ( execute (p)->display() ; p := p - (n + j - i)) ; execute ("")->display() ; k := k + 1 + n - i); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): while True : n=int(input()) if not n : break ps=[list(map(int,input().split()))for i in range(n)] dic=set() for t in ps : dic.add((t[0],t[1])) ans=0 for i in range(n): for j in range(n): p1=ps[i] p2=ps[j] p1x=p1[0] p1y=p1[1] p2x=p2[0] p2y=p2[1] vx=p2x-p1x vy=p2y-p1y if(p1x+vy,p1y-vx)in dic and(p2x+vy,p2y-vx)in dic : ans=max(ans,vx**2+vy**2) print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(n) then ( break ) else skip ; var ps : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var dic : Set := Set{}->union(()) ; for t : ps do ( execute ((Sequence{t->first(), t[1+1]}) : dic)) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( var p1 : OclAny := ps[i+1] ; var p2 : OclAny := ps[j+1] ; var p1x : OclAny := p1->first() ; var p1y : OclAny := p1[1+1] ; var p2x : OclAny := p2->first() ; var p2y : OclAny := p2[1+1] ; var vx : double := p2x - p1x ; var vy : double := p2y - p1y ; if (dic)->includes(Sequence{p1x + vy, p1y - vx}) & (dic)->includes(Sequence{p2x + vy, p2y - vx}) then ( ans := Set{ans, (vx)->pow(2) + (vy)->pow(2)}->max() ) else skip)) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_ITERATIONS=20 ; def isLychrel(number): for i in range(MAX_ITERATIONS): number=number+reverse(number); if(isPalindrome(number)): return "false" ; return "true" ; def isPalindrome(number): return number==reverse(number); def reverse(number): reverse=0 ; while(number>0): remainder=number % 10 ; reverse=(reverse*10)+remainder ; number=int(number/10); return reverse ; number=295 ; print(number," is lychrel? ",isLychrel(number)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_ITERATIONS : int := 20; ; skip ; skip ; skip ; number := 295; ; execute (number)->display();; operation isLychrel(number : OclAny) pre: true post: true activity: for i : Integer.subrange(0, MAX_ITERATIONS-1) do ( number := number + reverse(number); ; if (isPalindrome(number)) then ( return "false"; ) else skip) ; return "true";; operation isPalindrome(number : OclAny) pre: true post: true activity: return number = reverse(number);; operation reverse(number : OclAny) pre: true post: true activity: var reverse : int := 0; ; while (number > 0) do ( var remainder : int := number mod 10; ; reverse := (reverse * 10) + remainder; ; number := ("" + ((number / 10)))->toInteger();) ; return reverse;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minCost(graph,n): cost1,cost2=0,0 ; start=[False]*(n+1); end=[False]*(n+1); for i in range(n): a=graph[i][0]; b=graph[i][1]; c=graph[i][2]; if(start[a]or end[b]): cost2+=c ; start[b]=True ; end[a]=True ; else : cost1+=c ; start[a]=True ; end[b]=True ; return min(cost1,cost2); if __name__=='__main__' : n=5 ; graph=[[1,2,7],[5,1,8],[5,4,5],[3,4,1],[3,2,10]]; ans=minCost(graph,n); print(ans); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 5; ; graph := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 7 }))}->union(Sequence{Sequence{5}->union(Sequence{1}->union(Sequence{ 8 }))}->union(Sequence{Sequence{5}->union(Sequence{4}->union(Sequence{ 5 }))}->union(Sequence{Sequence{3}->union(Sequence{4}->union(Sequence{ 1 }))}->union(Sequence{ Sequence{3}->union(Sequence{2}->union(Sequence{ 10 })) })))); ; var ans : OclAny := minCost(graph, n); ; execute (ans)->display(); ) else skip; operation minCost(graph : OclAny, n : OclAny) pre: true post: true activity: var cost1 : OclAny := null; var cost2 : OclAny := null; Sequence{cost1,cost2} := Sequence{0,0}; ; var start : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (n + 1)); ; var end : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (n + 1)); ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := graph[i+1]->first(); ; var b : OclAny := graph[i+1][1+1]; ; var c : OclAny := graph[i+1][2+1]; ; if (start[a+1] or end[b+1]) then ( cost2 := cost2 + c; ; start[b+1] := true; ; end[a+1] := true; ) else ( cost1 := cost1 + c; ; start[a+1] := true; ; end[b+1] := true; )) ; return Set{cost1, cost2}->min();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- infile=open('airport_walk.in') outfile=open('airport_walk.out','w') T=int(infile.readline().strip()) for t in xrange(T): X,S,R,runtime,N=[int(s)for s in infile.readline().strip().split()] run_bonus=R-S speeds,lengths=[],[] walkways=[] for i in xrange(N): B,E,w=[int(s)for s in infile.readline().strip().split()] walkways.append((w+S,E-B)) sum_lens=sum(w[1]for w in walkways) walkways.append((S,X-sum_lens)) walkways=sorted(walkways,key=lambda w : w[0]) answer=0.0 for speed,distance in walkways : cur_runtime=min(distance/float(speed+run_bonus),float(runtime)) runtime-=cur_runtime answer+=cur_runtime+((distance-(speed+run_bonus)*cur_runtime)/float(speed)) outfile.write('Case #%d: %.9f\n' %(t+1,answer)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var infile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('airport_walk.in')) ; var outfile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('airport_walk.out')) ; var T : int := ("" + ((infile.readLine()->trim())))->toInteger() ; for t : xrange(T) do ( var X : OclAny := null; var S : OclAny := null; var R : OclAny := null; var runtime : OclAny := null; var N : OclAny := null; Sequence{X,S,R,runtime,N} := infile.readLine()->trim().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; var run_bonus : double := R - S ; var speeds : OclAny := null; var lengths : OclAny := null; Sequence{speeds,lengths} := Sequence{Sequence{},Sequence{}} ; var walkways : Sequence := Sequence{} ; for i : xrange(N) do ( var B : OclAny := null; var E : OclAny := null; var w : OclAny := null; Sequence{B,E,w} := infile.readLine()->trim().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; execute ((Sequence{w + S, E - B}) : walkways)) ; var sum_lens : OclAny := ((argument (test (logical_test (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))) (comp_for for (exprlist (expr (atom (name w)))) in (logical_test (comparison (expr (atom (name walkways))))))))->sum() ; execute ((Sequence{S, X - sum_lens}) : walkways) ; walkways := walkways->sortedBy($x | (lambda w : OclAny in (w->first()))->apply($x)) ; var answer : double := 0.0 ; for _tuple : walkways do (var _indx : int := 1; var speed : OclAny := _tuple->at(_indx); _indx := _indx + 1; var distance : OclAny := _tuple->at(_indx); var cur_runtime : OclAny := Set{distance / ("" + ((speed + run_bonus)))->toReal(), ("" + ((runtime)))->toReal()}->min() ; runtime := runtime - cur_runtime ; answer := answer + cur_runtime + ((distance - (speed + run_bonus) * cur_runtime) / ("" + ((speed)))->toReal())) ; outfile.write(StringLib.format('Case #%d: %.9f ',Sequence{t + 1, answer}))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- with open('input.in','r')as fin : with open('output.txt','w')as fout : numcases=int(fin.readline()) for casenum in range(1,numcases+1): info=[int(i)for i in fin.readline().split()] length=info[0] walksp=float(info[1]) runsp=float(info[2]) runt=float(info[3]) walkways=[] for walkway in range(info[4]): w=[int(i)for i in fin.readline().split()] walkways.append((w[2],(w[1]-w[0]))) walkways.sort() lengths=sum([x[1]for x in walkways]) time=0.0 nowalklen=length-lengths print(nowalklen) if(runttoInteger() ; for casenum : Integer.subrange(1, numcases + 1-1) do ( var info : Sequence := fin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var length : OclAny := info->first() ; var walksp : double := ("" + ((info[1+1])))->toReal() ; var runsp : double := ("" + ((info[2+1])))->toReal() ; var runt : double := ("" + ((info[3+1])))->toReal() ; var walkways : Sequence := Sequence{} ; for walkway : Integer.subrange(0, info[4+1]-1) do ( var w : Sequence := fin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute ((Sequence{w[2+1], (w[1+1] - w->first())}) : walkways)) ; walkways := walkways->sort() ; var lengths : OclAny := (walkways->select(x | true)->collect(x | (x[1+1])))->sum() ; var time : double := 0.0 ; var nowalklen : double := length - lengths ; execute (nowalklen)->display() ; if ((runt->compareTo(nowalklen / runsp)) < 0) then ( time := runt + (nowalklen - (runsp * runt)) / walksp ; runt := 0 ) else ( runt := runt - nowalklen / runsp ; time := time + nowalklen / runsp ) ; execute (time)->display() ; for i : walkways do ( if ((runt->compareTo(i[1+1] / (i->first() + runsp))) < 0) then ( time := time + runt + (i[1+1] - ((i->first() + runsp) * runt)) / (i->first() + walksp) ; runt := 0 ) else ( time := time + i[1+1] / (i->first() + runsp) ; runt := runt - i[1+1] / (i->first() + runsp) )) ; fout.write("Case #" + ("" + ((casenum))) + ": " + ("" + ((time))) + ' '))) catch (_e : OclException) do skip) catch (_e : OclException) do skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import division def memoized(func): mem={} def wrapped(*args): if args not in mem : mem[args]=func(*args) return mem[args] return wrapped TASK="A" print("Calculation...") with open(TASK+".in")as infile : with open(TASK+".out",mode="wt")as outfile : cases=int(infile.readline()) for ncase in range(cases): X,W,R,t,N=(int(s)for s in infile.readline().split()) parts=[] for i in xrange(N): B,E,s=(int(s)for s in infile.readline().split()) X-=E-B parts.append((s,E-B)) parts.append((0,X)) parts.sort() T=0 for s,L in parts : if t>0 : Tr=min(L/(s+R),t) T+=Tr t-=Tr L-=(s+R)*Tr if t==0 : T+=L/(s+W) outfile.write("Case #{nc}:{data}\n".format(nc=ncase+1,data=T)) print("Calculation done.") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var TASK : String := "A" ; execute ("Calculation...")->display() ; try (var infile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(TASK + ".in")); try (var outfile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(TASK + ".out")); var cases : int := ("" + ((infile.readLine())))->toInteger() ; for ncase : Integer.subrange(0, cases-1) do ( var X : OclAny := null; var W : OclAny := null; var R : OclAny := null; var t : OclAny := null; var N : OclAny := null; Sequence{X,W,R,t,N} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name infile)) (trailer . (name readline) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var parts : Sequence := Sequence{} ; for i : xrange(N) do ( var B : OclAny := null; var E : OclAny := null; var s : OclAny := null; Sequence{B,E,s} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name infile)) (trailer . (name readline) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; X := X - E - B ; execute ((Sequence{s, E - B}) : parts)) ; execute ((Sequence{0, X}) : parts) ; parts := parts->sort() ; var T : int := 0 ; for _tuple : parts do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var L : OclAny := _tuple->at(_indx); if t > 0 then ( var Tr : OclAny := Set{L / (s + R), t}->min() ; T := T + Tr ; t := t - Tr ; L := L - (s + R) * Tr ) else skip ; if t = 0 then ( T := T + L / (s + W) ) else skip) ; outfile.write(StringLib.interpolateStrings("Case #{nc}:{data}\n", Sequence{(argument (test (logical_test (comparison (expr (atom (name nc)))))) = (test (logical_test (comparison (expr (expr (atom (name ncase))) + (expr (atom (number (integer 1))))))))), (argument (test (logical_test (comparison (expr (atom (name data)))))) = (test (logical_test (comparison (expr (atom (name T)))))))})))) catch (_e : OclException) do skip) catch (_e : OclException) do skip ; execute ("Calculation done.")->display(); operation memoized(func : OclAny) : OclAny pre: true post: true activity: var mem : OclAny := Set{} ; skip ; return wrapped; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,collections infile=sys.stdin def get_time(segments,S,R,running_time): segments=collections.deque(sorted(segments,key=lambda s : s[1])) t=0 while segments : sdist,sspeed=segments.popleft() if running_time>0 : rt=sdist/(sspeed+R) if rt<=running_time : running_time-=rt t+=rt else : remaining=sdist-(running_time*(R+sspeed)) t+=running_time+(remaining/(S+sspeed)) running_time=0 else : t+=(sdist/(S+sspeed)) return t T=int(infile.readline()) for i in xrange(T): X,S,R,t,N=map(int,infile.readline().split()) segments=[] wdist=0 for j in xrange(N): B,E,w=map(float,infile.readline().split()) segments.append((E-B,w)) wdist+=E-B segments.append((X-wdist,0)) result=get_time(segments,float(S),float(R),float(t)) print("Case #%d: %f" %(i+1,result)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var infile : OclFile := OclFile["System.in"] ; skip ; var T : int := ("" + ((infile.readLine())))->toInteger() ; for i : xrange(T) do ( var X : OclAny := null; var N : OclAny := null; Sequence{X,S,R,t,N} := (infile.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; segments := Sequence{} ; var wdist : int := 0 ; for j : xrange(N) do ( var B : OclAny := null; var E : OclAny := null; var w : OclAny := null; Sequence{B,E,w} := (infile.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ) ; execute ((Sequence{E - B, w}) : segments) ; wdist := wdist + E - B) ; execute ((Sequence{X - wdist, 0}) : segments) ; var result : OclAny := get_time(segments, ("" + ((S)))->toReal(), ("" + ((R)))->toReal(), ("" + ((t)))->toReal()) ; execute (StringLib.format("Case #%d: %f",Sequence{i + 1, result}))->display()); operation get_time(segments : OclAny, S : OclAny, R : OclAny, running_time : OclAny) : OclAny pre: true post: true activity: segments := (segments->sortedBy($x | (lambda s : OclAny in (s[1+1]))->apply($x))) ; var t : int := 0 ; while segments do ( var sdist : OclAny := null; var sspeed : OclAny := null; Sequence{sdist,sspeed} := segments->first() ; segments := segments->tail() ; if running_time > 0 then ( var rt : double := sdist / (sspeed + R) ; if (rt->compareTo(running_time)) <= 0 then ( running_time := running_time - rt ; t := t + rt ) else ( var remaining : double := sdist - (running_time * (R + sspeed)) ; t := t + running_time + (remaining / (S + sspeed)) ; running_time := 0 ) ) else ( t := t + (sdist / (S + sspeed)) )) ; return t; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) x,y=zip(*(map(int,input().split())for _ in range(M))) c=[1 for _ in range(N+1)] r=[False for _ in range(N+1)] r[1]=True for a,b in zip(x,y): c[b]+=1 r[b]|=r[a] c[a]-=1 r[a]&=c[a]>=1 ans=sum(r) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name M)))))))) )))))))) )))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name M)))))))) )))))))) )))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name M)))))))) )))))))) )))))))`third->at(_indx)} ) ; var c : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (1)) ; var r : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (false)) ; r[1+1] := true ; for _tuple : Integer.subrange(1, x->size())->collect( _indx | Sequence{x->at(_indx), y->at(_indx)} ) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); c[b+1] := c[b+1] + 1 ; r[b+1] := r[b+1] or r[a+1] ; c[a+1] := c[a+1] - 1 ; r[a+1] := r[a+1] & c[a+1] >= 1) ; var ans : OclAny := (r)->sum() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) for num in range(1,N+1): X,S,R,T,n=map(int,input().split()) L={} W={} L[0]=X W[0]=0 for i in range(1,n+1): b,e,w=map(int,input().split()) L[i]=(e-b) W[i]=w L[0]-=(e-b) Idx=list(range(n+1)) Idx=sorted(Idx,key=W.get) Answer=0 for i in Idx : if T==0 : Answer+=L[i]/(W[i]+S) elif(W[i]+R)*T>=L[i]: Answer+=L[i]/(W[i]+R) T-=L[i]/(W[i]+R) else : Answer+=T+(L[i]-T*(W[i]+R))/(W[i]+S) T=0 print("Case #",num,": ",Answer,sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for num : Integer.subrange(1, N + 1-1) do ( var X : OclAny := null; var S : OclAny := null; var R : OclAny := null; var T : OclAny := null; var n : OclAny := null; Sequence{X,S,R,T,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var L : OclAny := Set{} ; var W : OclAny := Set{} ; L->first() := X ; W->first() := 0 ; for i : Integer.subrange(1, n + 1-1) do ( var b : OclAny := null; var e : OclAny := null; var w : OclAny := null; Sequence{b,e,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; L[i+1] := (e - b) ; W[i+1] := w ; L->first() := L->first() - (e - b)) ; var Idx : Sequence := (Integer.subrange(0, n + 1-1)) ; Idx := Idx->sortedBy($x | (W.get)->apply($x)) ; var Answer : int := 0 ; for i : Idx do ( if T = 0 then ( Answer := Answer + L[i+1] / (W[i+1] + S) ) else (if ((W[i+1] + R) * T->compareTo(L[i+1])) >= 0 then ( Answer := Answer + L[i+1] / (W[i+1] + R) ; T := T - L[i+1] / (W[i+1] + R) ) else ( Answer := Answer + T + (L[i+1] - T * (W[i+1] + R)) / (W[i+1] + S) ; var T : int := 0 ) ) ) ; execute ("Case #")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def StarPattern(height): for i in range(height): for j in range(height-1,i,-1): print("*",end="") printChar=False for j in range(((i*2)+1)): if(printChar): print("*",end="") else : print(i+1,end="") printChar=not printChar for j in range(height-1,i,-1): print("*",end="") print() height=7 StarPattern(height) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; height := 7 ; StarPattern(height); operation StarPattern(height : OclAny) pre: true post: true activity: for i : Integer.subrange(0, height-1) do ( for j : Integer.subrange(i + 1, height - 1)->reverse() do ( execute ("*")->display()) ; var printChar : boolean := false ; for j : Integer.subrange(0, ((i * 2) + 1)-1) do ( if (printChar) then ( execute ("*")->display() ) else ( execute (i + 1)->display() ) ; printChar := not(printChar)) ; for j : Integer.subrange(i + 1, height - 1)->reverse() do ( execute ("*")->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPresent(arr,low,high,value): while(low<=high): mid=(low+high)//2 if(arr[mid]==value): return True elif(arr[mid]>value): high=mid-1 else : low=mid+1 return False def countPairs(arr1,arr2,m,n,x): count=0 for i in range(m): value=x-arr1[i] if(isPresent(arr2,0,n-1,value)): count+=1 return count if __name__=="__main__" : arr1=[1,3,5,7] arr2=[2,3,5,8] m=len(arr1) n=len(arr2) x=10 print("Count=",countPairs(arr1,arr2,m,n,x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr1 := Sequence{1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 7 }))) ; arr2 := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 8 }))) ; m := (arr1)->size() ; n := (arr2)->size() ; x := 10 ; execute ("Count=")->display() ) else skip; operation isPresent(arr : OclAny, low : OclAny, high : OclAny, value : OclAny) : OclAny pre: true post: true activity: while ((low->compareTo(high)) <= 0) do ( var mid : int := (low + high) div 2 ; if (arr[mid+1] = value) then ( return true ) else (if ((arr[mid+1]->compareTo(value)) > 0) then ( high := mid - 1 ) else ( low := mid + 1 ) ) ) ; return false; operation countPairs(arr1 : OclAny, arr2 : OclAny, m : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, m-1) do ( value := x - arr1[i+1] ; if (isPresent(arr2, 0, n - 1, value)) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l1=list(map(int,input().split())) l2=list(map(int,input().split())) spp=0 spn=0 spn=max(l2[0]-l1[0],0)+max(l2[1]-l1[1],0)+max(l2[2]-l1[2],0) spp=int(max((l1[0]-l2[0])/2,0))+int(max((l1[1]-l2[1])/2,0))+int(max((l1[2]-l2[2])/2,0)) if spp>=spn : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var spp : int := 0 ; var spn : int := 0 ; spn := Set{l2->first() - l1->first(), 0}->max() + Set{l2[1+1] - l1[1+1], 0}->max() + Set{l2[2+1] - l1[2+1], 0}->max() ; spp := ("" + ((Set{(l1->first() - l2->first()) / 2, 0}->max())))->toInteger() + ("" + ((Set{(l1[1+1] - l2[1+1]) / 2, 0}->max())))->toInteger() + ("" + ((Set{(l1[2+1] - l2[2+1]) / 2, 0}->max())))->toInteger() ; if (spp->compareTo(spn)) >= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- M=3 ; N=2 ; def getIndex(n,shuffle): for i in range(3): if(shuffle[i][0]==n): n=shuffle[i][1]; elif(shuffle[i][1]==n): n=shuffle[i][0]; print(n); if __name__=="__main__" : n=3 ; shuffle=[[3,1],[2,1],[1,2]]; getIndex(n,shuffle); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var M : int := 3; var N : int := 2; ; skip ; if __name__ = "__main__" then ( n := 3; ; shuffle := Sequence{Sequence{3}->union(Sequence{ 1 })}->union(Sequence{Sequence{2}->union(Sequence{ 1 })}->union(Sequence{ Sequence{1}->union(Sequence{ 2 }) })); ; getIndex(n, shuffle); ) else skip; operation getIndex(n : OclAny, shuffle : OclAny) pre: true post: true activity: for i : Integer.subrange(0, 3-1) do ( if (shuffle[i+1]->first() = n) then ( n := shuffle[i+1][1+1]; ) else (if (shuffle[i+1][1+1] = n) then ( n := shuffle[i+1]->first(); ) else skip)) ; execute (n)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000,10**9)) write=lambda x : sys.stdout.write(x+"\n") s=input() K=int(input()) n=len(s) dp=[[[0]*(K+1)for _ in range(n+2-i)]for i in range(n+1)] for i in range(n): for j in range(K+1): dp[i][1][j]=1 for l in range(2,n+1): for i in range(n-l+1): for k in range(K+1): if s[i]==s[i+l-1]: dp[i][l][k]=dp[i+1][l-2][k]+2 else : dp[i][l][k]=max(dp[i+1][l-1][k],dp[i][l-1][k]) if k>=1 : dp[i][l][k]=max(dp[i][l][k],dp[i+1][l-2][k-1]+2) ans=max(dp[0][i][j]for i in range(n+2)for j in range(K+1)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; sys.setrecursionlimit(Set{1000, (10)->pow(9)}->max()) ; var write : Function := lambda x : OclAny in ((OclFile["System.out"]).write(x + "\n")) ; var s : String := (OclFile["System.in"]).readLine() ; var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := (s)->size() ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, n + 2 - i-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (K + 1)))))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, K + 1-1) do ( dp[i+1][1+1][j+1] := 1)) ; for l : Integer.subrange(2, n + 1-1) do ( for i : Integer.subrange(0, n - l + 1-1) do ( for k : Integer.subrange(0, K + 1-1) do ( if s[i+1] = s[i + l - 1+1] then ( dp[i+1][l+1][k+1] := dp[i + 1+1][l - 2+1][k+1] + 2 ) else ( dp[i+1][l+1][k+1] := Set{dp[i + 1+1][l - 1+1][k+1], dp[i+1][l - 1+1][k+1]}->max() ; if k >= 1 then ( dp[i+1][l+1][k+1] := Set{dp[i+1][l+1][k+1], dp[i + 1+1][l - 2+1][k - 1+1] + 2}->max() ) else skip )))) ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 2)))))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name K))) + (expr (atom (number (integer 1)))))))))) )))))))))))->max() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines import numpy as np S=np.frombuffer(readline().rstrip(),'S1') N=len(S) K=int(readline()) dp=[None]*(N+1) dp[0]=None dp[1]=np.zeros((N,K+10),np.int32); dp[1][:,0]=1 if N>=2 : dp[2]=np.zeros((N-1,K+10),np.int32) dp[2][:,0]=1+(S[:-1]==S[1 :]) dp[2][:,1]=2 for n in range(3,N+1): arr=np.zeros((N-n+1,K+10),np.int32) np.maximum(arr,dp[n-1][:-1],out=arr) np.maximum(arr,dp[n-1][1 :],out=arr) match=(S[:-n+1]==S[n-1 :]) np.maximum(arr,match[:,None]*(dp[n-2][1 :-1]+2),out=arr) np.maximum(arr[:,1 :],dp[n-2][1 :-1,:-1]+2,out=arr[:,1 :]) dp[n]=arr answer=dp[-1][0][: K+1].max() print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; skip ; var S : (trailer . (name frombuffer) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name readline)) (trailer (arguments ( ))) (trailer . (name rstrip) (arguments ( )))))))) , (argument (test (logical_test (comparison (expr (atom 'S1'))))))) ))) := ; var N : int := (S)->size() ; var K : int := ("" + ((readline())))->toInteger() ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (N + 1)) ; dp->first() := null ; dp[1+1] := MatrixLib.singleValueMatrix(Sequence{N, K + 10}, 0.0); dp[1+1]->collect( _r | _r->first() ) := 1 ; if N >= 2 then ( dp[2+1] := MatrixLib.singleValueMatrix(Sequence{N - 1, K + 10}, 0.0) ; dp[2+1]->collect( _r | _r->first() ) := 1 + (S->front() = S->tail()) ; dp[2+1]->collect( _r | _r[1+1] ) := 2 ) else skip ; for n : Integer.subrange(3, N + 1-1) do ( var arr : Sequence := MatrixLib.singleValueMatrix(Sequence{N - n + 1, K + 10}, 0.0) ; np.maximum(arr, dp[n - 1+1]->front(), (argument (test (logical_test (comparison (expr (atom (name out)))))) = (test (logical_test (comparison (expr (atom (name arr)))))))) ; np.maximum(arr, dp[n - 1+1]->tail(), (argument (test (logical_test (comparison (expr (atom (name out)))))) = (test (logical_test (comparison (expr (atom (name arr)))))))) ; var match : boolean := (S.subrange(1,-n + 1) = S.subrange(n - 1+1)) ; np.maximum(arr, MatrixLib.elementwiseMult(match->collect( _r | _r[null+1] ), (dp[n - 2+1].subrange(1+1, -1) + 2)), (argument (test (logical_test (comparison (expr (atom (name out)))))) = (test (logical_test (comparison (expr (atom (name arr)))))))) ; np.maximum(arr->collect( _r | _r->tail() ), dp[n - 2+1].subrange(1+1, -1)->front() + 2, (argument (test (logical_test (comparison (expr (atom (name out)))))) = (test (logical_test (comparison (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript :) , (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))))))) ; dp[n+1] := arr) ; var answer : OclAny := dp->last()->first().subrange(1,K + 1)->max() ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_ind(l,r): mod=3 return OFFSET*(l % mod)+r s=input() n=len(s) k=int(input()) dp=[[0]*((n+1)*3)for i in range(k+1)] OFFSET=n+1 for i in range(n): dp[0][get_ind(i,i+1)]=1 for length in range(2,n+1): for l in range(n+1): for ki in range(k+1): r=l+length if r>n : break if s[l]==s[r-1]: dp[ki][get_ind(l,r)]=max(2+dp[ki][get_ind(l+1,r-1)],dp[ki][get_ind(l,r)]) else : dp[ki][get_ind(l,r)]=max(dp[ki][get_ind(l+1,r)],dp[ki][get_ind(l,r-1)],dp[ki][get_ind(l,r)]) if ki-1>=0 : dp[ki][get_ind(l,r)]=max(dp[ki-1][get_ind(l+1,r-1)]+2,dp[ki][get_ind(l,r)]) ans=0 for i in range(k+1): for j in range(3*(n+1)): ans=max(ans,dp[i][j]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : String := (OclFile["System.in"]).readLine() ; var n : int := (s)->size() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var dp : Sequence := Integer.subrange(0, k + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, ((n + 1) * 3)))) ; var OFFSET : int := n + 1 ; for i : Integer.subrange(0, n-1) do ( dp->first()[get_ind(i, i + 1)+1] := 1) ; for length : Integer.subrange(2, n + 1-1) do ( for l : Integer.subrange(0, n + 1-1) do ( for ki : Integer.subrange(0, k + 1-1) do ( r := l + length ; if (r->compareTo(n)) > 0 then ( break ) else skip ; if s[l+1] = s[r - 1+1] then ( dp[ki+1][get_ind(l, r)+1] := Set{2 + dp[ki+1][get_ind(l + 1, r - 1)+1], dp[ki+1][get_ind(l, r)+1]}->max() ) else ( dp[ki+1][get_ind(l, r)+1] := Set{dp[ki+1][get_ind(l + 1, r)+1], dp[ki+1][get_ind(l, r - 1)+1], dp[ki+1][get_ind(l, r)+1]}->max() ; if ki - 1 >= 0 then ( dp[ki+1][get_ind(l, r)+1] := Set{dp[ki - 1+1][get_ind(l + 1, r - 1)+1] + 2, dp[ki+1][get_ind(l, r)+1]}->max() ) else skip )))) ; var ans : int := 0 ; for i : Integer.subrange(0, k + 1-1) do ( for j : Integer.subrange(0, 3 * (n + 1)-1) do ( ans := Set{ans, dp[i+1][j+1]}->max())) ; execute (ans)->display(); operation get_ind(l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var mod : int := 3 ; return OFFSET * (l mod mod) + r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(s,k): n=len(s) if k>=n//2 : return n dpp=[[1]*(k+1),[0]*(k+1)] for r in range(1,n): dpc=[[0]*(k+1)for _ in range(r+2)] dpc[r]=[1]*(k+1) for l in range(r-1,-1,-1): dpl,dpl1=dpc[l],dpp[l+1] if s[l]==s[r]: dpc[l]=[c+2 for c in dpl1] else : dppl,dpcl1=dpp[l],dpc[l+1] dpl[0]=max(dppl[0],dpcl1[0]) for p in range(1,k+1): dpl[p]=max(dppl[p],dpcl1[p],dpl1[p-1]+2) dpp=dpc return dpp[0][k] print(solve(input(),int(input()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (solve((OclFile["System.in"]).readLine(), ("" + (((OclFile["System.in"]).readLine())))->toInteger()))->display(); operation solve(s : OclAny, k : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; if (k->compareTo(n div 2)) >= 0 then ( return n ) else skip ; var dpp : Sequence := Sequence{MatrixLib.elementwiseMult(Sequence{ 1 }, (k + 1))}->union(Sequence{ MatrixLib.elementwiseMult(Sequence{ 0 }, (k + 1)) }) ; for r : Integer.subrange(1, n-1) do ( var dpc : Sequence := Integer.subrange(0, r + 2-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (k + 1)))) ; dpc[r+1] := MatrixLib.elementwiseMult(Sequence{ 1 }, (k + 1)) ; for l : Integer.subrange(-1 + 1, r - 1)->reverse() do ( var dpl : OclAny := null; var dpl1 : OclAny := null; Sequence{dpl,dpl1} := Sequence{dpc[l+1],dpp[l + 1+1]} ; if s[l+1] = s[r+1] then ( dpc[l+1] := dpl1->select(c | true)->collect(c | (c + 2)) ) else ( var dppl : OclAny := null; var dpcl1 : OclAny := null; Sequence{dppl,dpcl1} := Sequence{dpp[l+1],dpc[l + 1+1]} ; dpl->first() := Set{dppl->first(), dpcl1->first()}->max() ; for p : Integer.subrange(1, k + 1-1) do ( dpl[p+1] := Set{dppl[p+1], dpcl1[p+1], dpl1[p - 1+1] + 2}->max()) )) ; dpp := dpc) ; return dpp->first()[k+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() K=int(input()) N=len(S) if K*2>=N-1 : print(N) exit() dp=[[[0 for _ in range(K+1)]for _ in range(N)]for _ in range(N)] for i in range(N): for k in range(K+1): dp[i][i][k]=1 for _j in range(1,N): for i in range(N): j=i+_j if jtoInteger() ; var N : int := (S)->size() ; if (K * 2->compareTo(N - 1)) >= 0 then ( execute (N)->display() ; exit() ) else skip ; var dp : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, K + 1-1)->select(_anon | true)->collect(_anon | (0)))))) ; for i : Integer.subrange(0, N-1) do ( for k : Integer.subrange(0, K + 1-1) do ( dp[i+1][i+1][k+1] := 1)) ; for _j : Integer.subrange(1, N-1) do ( for i : Integer.subrange(0, N-1) do ( var j : OclAny := i + _j ; if (j->compareTo(N)) < 0 then ( for k : Integer.subrange(0, K + 1-1) do ( dp[i+1][j+1][k+1] := Set{dp[i+1][j+1][k+1], dp[i + 1+1][j+1][k+1], dp[i+1][j - 1+1][k+1]}->max() ; if _j = 1 then ( if S[i+1] = S[j+1] then ( dp[i+1][j+1][k+1] := 2 ) else ( if (k + 1->compareTo(K)) <= 0 then ( dp[i+1][j+1][k + 1+1] := 2 ) else skip ) ) else ( if S[i+1] = S[j+1] then ( dp[i+1][j+1][k+1] := Set{dp[i+1][j+1][k+1], dp[i + 1+1][j - 1+1][k+1] + 2}->max() ) else ( if (k + 1->compareTo(K)) <= 0 then ( dp[i+1][j+1][k + 1+1] := Set{dp[i+1][j+1][k+1], dp[i + 1+1][j - 1+1][k+1] + 2}->max() ) else skip ) )) ) else skip)) ; execute ((dp->first()[N - 1+1])->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split(' ')) X=[] for i in range(M): X.append(list(map(int,input().split(' ')))) num_b=[1 for i in range(N+1)] num_b[0]=0 psb=[0]*(N+1) psb[1]=1 for i in range(M): num_b[X[i][0]]-=1 num_b[X[i][1]]+=1 if psb[X[i][0]]==1 : psb[X[i][1]]=1 if num_b[X[i][0]]==0 : psb[X[i][0]]=0 print(psb.count(1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var X : Sequence := Sequence{} ; for i : Integer.subrange(0, M-1) do ( execute ((((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ))) : X)) ; var num_b : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (1)) ; num_b->first() := 0 ; var psb : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; psb[1+1] := 1 ; for i : Integer.subrange(0, M-1) do ( num_b[X[i+1]->first()+1] := num_b[X[i+1]->first()+1] - 1 ; num_b[X[i+1][1+1]+1] := num_b[X[i+1][1+1]+1] + 1 ; if psb[X[i+1]->first()+1] = 1 then ( psb[X[i+1][1+1]+1] := 1 ) else skip ; if num_b[X[i+1]->first()+1] = 0 then ( psb[X[i+1]->first()+1] := 0 ) else skip) ; execute (psb->count(1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- maximum=1000 def lcs(X,Y,m,n,dp): if(m==0 or n==0): return 0 if(dp[m-1][n-1]!=-1): return dp[m-1][n-1] if(X[m-1]==Y[n-1]): dp[m-1][n-1]=1+lcs(X,Y,m-1,n-1,dp) return dp[m-1][n-1] else : dp[m-1][n-1]=max(lcs(X,Y,m,n-1,dp),lcs(X,Y,m-1,n,dp)) return dp[m-1][n-1] X="AGGTAB" Y="GXTXAYB" m=len(X) n=len(Y) dp=[[-1 for i in range(maximum)]for i in range(m)] print("Length of LCS:",lcs(X,Y,m,n,dp)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var maximum : int := 1000 ; skip ; X := "AGGTAB" ; Y := "GXTXAYB" ; m := (X)->size() ; n := (Y)->size() ; dp := Integer.subrange(0, m-1)->select(i | true)->collect(i | (Integer.subrange(0, maximum-1)->select(i | true)->collect(i | (-1)))) ; execute ("Length of LCS:")->display(); operation lcs(X : OclAny, Y : OclAny, m : OclAny, n : OclAny, dp : OclAny) : OclAny pre: true post: true activity: if (m = 0 or n = 0) then ( return 0 ) else skip ; if (dp[m - 1+1][n - 1+1] /= -1) then ( return dp[m - 1+1][n - 1+1] ) else skip ; if (X[m - 1+1] = Y[n - 1+1]) then ( dp[m - 1+1][n - 1+1] := 1 + lcs(X, Y, m - 1, n - 1, dp) ; return dp[m - 1+1][n - 1+1] ) else ( dp[m - 1+1][n - 1+1] := Set{lcs(X, Y, m, n - 1, dp), lcs(X, Y, m - 1, n, dp)}->max() ; return dp[m - 1+1][n - 1+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=20 fact=[0]*N ; def pre(): fact[0]=1 ; for i in range(1,N): fact[i]=i*fact[i-1]; def CountPermutation(a,n): ways=1 ; a.sort(); size=1 ; for i in range(1,n): if(a[i]==a[i-1]): size+=1 ; else : ways*=fact[size]; size=1 ; ways*=fact[size]; return ways ; if __name__=="__main__" : a=[1,2,4,4,2,4]; n=len(a); pre(); print(CountPermutation(a,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 20 ; var fact : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N); ; skip ; skip ; if __name__ = "__main__" then ( a := Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{4}->union(Sequence{2}->union(Sequence{ 4 }))))); ; n := (a)->size(); ; pre(); ; execute (CountPermutation(a, n))->display(); ) else skip; operation pre() pre: true post: true activity: fact->first() := 1; ; for i : Integer.subrange(1, N-1) do ( fact[i+1] := i * fact[i - 1+1];); operation CountPermutation(a : OclAny, n : OclAny) pre: true post: true activity: var ways : int := 1; ; a := a->sort(); ; var size : int := 1; ; for i : Integer.subrange(1, n-1) do ( if (a[i+1] = a[i - 1+1]) then ( size := size + 1; ) else ( ways := ways * fact[size+1]; ; size := 1; )) ; ways := ways * fact[size+1]; ; return ways;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000000 def breakSum(n): dp=[0]*(n+1) dp[0]=0 dp[1]=1 for i in range(2,n+1): dp[i]=max(dp[int(i/2)]+dp[int(i/3)]+dp[int(i/4)],i); return dp[n] n=24 print(breakSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1000000 ; skip ; n := 24 ; execute (breakSum(n))->display(); operation breakSum(n : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; dp->first() := 0 ; dp[1+1] := 1 ; for i : Integer.subrange(2, n + 1-1) do ( dp[i+1] := Set{dp[("" + ((i / 2)))->toInteger()+1] + dp[("" + ((i / 3)))->toInteger()+1] + dp[("" + ((i / 4)))->toInteger()+1], i}->max();) ; return dp[n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairs(arr,n): countZero=0 ; countTwo=0 ; for i in range(n): if(arr[i]==0): countZero+=1 ; elif(arr[i]==2): countTwo+=1 ; pair0=(countZero*(countZero-1))//2 ; pair2=(countTwo*(countTwo-1))//2 ; return pair0+pair2 ; if __name__=="__main__" : arr=[2,0,3,2,0]; n=len(arr); print(countPairs(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{2}->union(Sequence{0}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 0 })))); ; n := (arr)->size(); ; execute (countPairs(arr, n))->display(); ) else skip; operation countPairs(arr : OclAny, n : OclAny) pre: true post: true activity: var countZero : int := 0; ; var countTwo : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] = 0) then ( countZero := countZero + 1; ) else (if (arr[i+1] = 2) then ( countTwo := countTwo + 1; ) else skip)) ; var pair0 : int := (countZero * (countZero - 1)) div 2; ; var pair2 : int := (countTwo * (countTwo - 1)) div 2; ; return pair0 + pair2;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- v=[h-t for h,t in zip(map(int,input().split()),map(int,input().split()))] print('Yes' if sum([n if n<0 else n//2 for n in v])>=0 else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var v : Sequence := Integer.subrange(1, (input().split())->collect( _x | (OclType["int"])->apply(_x) )->size())->collect( _indx | Sequence{(input().split())->collect( _x | (OclType["int"])->apply(_x) )->at(_indx), (input().split())->collect( _x | (OclType["int"])->apply(_x) )->at(_indx)} )->select(_tuple | true)->collect(_tuple | let h : OclAny = _tuple->at(1) in let t : OclAny = _tuple->at(2) in (h - t)) ; execute (if (v->select(n | true)->collect(n | (if n < 0 then n else n div 2 endif)))->sum() >= 0 then 'Yes' else 'No' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w=map(int,input().split()) cloud=[[i for i in input()]for i in range(h)] flag=0 cnt=0 for i in range(h): for j in range(w): if j==w-1 and flag==0 and cloud[i][j]=='.' : print(-1,end='') elif j==w-1 and cloud[i][j]=='c' : print(0,end='') flag=1 cnt=0 elif j==w-1 and cloud[i][j]=='.' : cnt+=1 print(cnt,end='') elif flag==0 and cloud[i][j]=='.' : print(-1,end=' ') elif cloud[i][j]=='c' : print(0,end=' ') flag=1 cnt=0 else : cnt+=1 print(cnt,end=' ') print() cnt=0 flag=0 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cloud : Sequence := Integer.subrange(0, h-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine()->select(i | true)->collect(i | (i)))) ; var flag : int := 0 ; var cnt : int := 0 ; for i : Integer.subrange(0, h-1) do ( for j : Integer.subrange(0, w-1) do ( if j = w - 1 & flag = 0 & cloud[i+1][j+1] = '.' then ( execute (-1)->display() ) else (if j = w - 1 & cloud[i+1][j+1] = 'c' then ( execute (0)->display() ; flag := 1 ; cnt := 0 ) else (if j = w - 1 & cloud[i+1][j+1] = '.' then ( cnt := cnt + 1 ; execute (cnt)->display() ) else (if flag = 0 & cloud[i+1][j+1] = '.' then ( execute (-1)->display() ) else (if cloud[i+1][j+1] = 'c' then ( execute (0)->display() ; flag := 1 ; cnt := 0 ) else ( cnt := cnt + 1 ; execute (cnt)->display() ) ) ) ) ) ) ; execute (->display() ; cnt := 0 ; flag := 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline h,w=map(int,input().split()) ans=[[0 for c in range(w)]for r in range(h)] arr=[input().strip()for r in range(h)] for r in range(h): p=-1 for c in range(w): if arr[r][c]=='c' : p=c ans[r][c]=-1 if p<0 else c-p for r in range(h): print(*ans[r]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := Integer.subrange(0, h-1)->select(r | true)->collect(r | (Integer.subrange(0, w-1)->select(c | true)->collect(c | (0)))) ; var arr : Sequence := Integer.subrange(0, h-1)->select(r | true)->collect(r | (input()->trim())) ; for r : Integer.subrange(0, h-1) do ( var p : int := -1 ; for c : Integer.subrange(0, w-1) do ( if arr[r+1][c+1] = 'c' then ( p := c ) else skip ; ans[r+1][c+1] := if p < 0 then -1 else c - p endif)) ; for r : Integer.subrange(0, h-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ]))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W=list(map(int,input().split(' '))) sections=[list(input())for i in range(H)] crowds=[[-1 for w in range(W)]for h in range(H)] for h in range(H): c=-1 for w in range(W): if c>=0 : c+=1 if sections[h][w]=='c' : c=0 crowds[h][w]=c for row in crowds : print(' '.join(list(map(str,row)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var sections : Sequence := Integer.subrange(0, H-1)->select(i | true)->collect(i | (((OclFile["System.in"]).readLine())->characters())) ; var crowds : Sequence := Integer.subrange(0, H-1)->select(h | true)->collect(h | (Integer.subrange(0, W-1)->select(w | true)->collect(w | (-1)))) ; for h : Integer.subrange(0, H-1) do ( var c : int := -1 ; for w : Integer.subrange(0, W-1) do ( if c >= 0 then ( c := c + 1 ) else skip ; if sections[h+1][w+1] = 'c' then ( c := 0 ) else skip ; crowds[h+1][w+1] := c)) ; for row : crowds do ( execute (StringLib.sumStringsWithSeparator((((row)->collect( _x | (OclType["String"])->apply(_x) ))), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W=[int(i)for i in input().split(" ")] city=[] for i in range(H): C=input() row=[] timer=-1000 for c in C : if c=="c" : timer=0 row.append(timer) else : timer+=1 row.append(timer) city.append(row) for i in range(H): for j in range(W): if city[i][j]<0 : city[i][j]="-1" else : city[i][j]=str(city[i][j]) for c in city : print(" ".join(c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var city : Sequence := Sequence{} ; for i : Integer.subrange(0, H-1) do ( var C : String := (OclFile["System.in"]).readLine() ; var row : Sequence := Sequence{} ; var timer : int := -1000 ; for c : C->characters() do ( if c = "c" then ( timer := 0 ; execute ((timer) : row) ) else ( timer := timer + 1 ; execute ((timer) : row) )) ; execute ((row) : city)) ; for i : Integer.subrange(0, H-1) do ( for j : Integer.subrange(0, W-1) do ( if city[i+1][j+1] < 0 then ( city[i+1][j+1] := "-1" ) else ( city[i+1][j+1] := ("" + ((city[i+1][j+1]))) ))) ; for c : city do ( execute (StringLib.sumStringsWithSeparator((c), " "))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w=map(int,input().split()) ans=[[0]*w for i in range(h)] c_m=[] for i in range(h): c_lis=input() c_m.append(list(c_lis)) for j in range(h): for k in range(w): if ans[j][k]==0 and c_m[j][k]=='.' : ans[j][k]=-1 elif c_m[j][k]=='c' : for l in range(w-k): ans[j][k+l]=l for m in range(h): cha=str(ans[m][0]) for n in range(w-1): cha=cha+" "+str(ans[m][n+1]) print(cha) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := Integer.subrange(0, h-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, w))) ; var c_m : Sequence := Sequence{} ; for i : Integer.subrange(0, h-1) do ( var c_lis : String := (OclFile["System.in"]).readLine() ; execute (((c_lis)->characters()) : c_m)) ; for j : Integer.subrange(0, h-1) do ( for k : Integer.subrange(0, w-1) do ( if ans[j+1][k+1] = 0 & c_m[j+1][k+1] = '.' then ( ans[j+1][k+1] := -1 ) else (if c_m[j+1][k+1] = 'c' then ( for l : Integer.subrange(0, w - k-1) do ( ans[j+1][k + l+1] := l) ) else skip))) ; for m : Integer.subrange(0, h-1) do ( var cha : String := ("" + ((ans[m+1]->first()))) ; for n : Integer.subrange(0, w - 1-1) do ( cha := cha + " " + ("" + ((ans[m+1][n + 1+1])))) ; execute (cha)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W=map(int,input().split()) s=[] for k in range(H): s.append(input()) B=[] for k in range(H): for l in range(W): if s[k][l]=="B" : B.append([k,l]) ans=0 for e in B : for f in B : ans=max(ans,abs(e[0]-f[0])+abs(e[1]-f[1])) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := Sequence{} ; for k : Integer.subrange(0, H-1) do ( execute (((OclFile["System.in"]).readLine()) : s)) ; var B : Sequence := Sequence{} ; for k : Integer.subrange(0, H-1) do ( for l : Integer.subrange(0, W-1) do ( if s[k+1][l+1] = "B" then ( execute ((Sequence{k}->union(Sequence{ l })) : B) ) else skip)) ; var ans : int := 0 ; for e : B do ( for f : B do ( ans := Set{ans, (e->first() - f->first())->abs() + (e[1+1] - f[1+1])->abs()}->max())) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) count=0 count1=0 arr=sorted(list(map(int,input().split()))) for i in range(n): if arr[i]==arr[2]: count+=1 if i<3 : count1+=1 print(int(int(math.factorial(count))/(int(math.factorial(count1))*int(math.factorial(count-count1))))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := 0 ; var count1 : int := 0 ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] = arr[2+1] then ( count := count + 1 ; if i < 3 then ( count1 := count1 + 1 ) else skip ) else skip) ; execute (("" + ((("" + ((MathLib.factorial(count))))->toInteger() / (("" + ((MathLib.factorial(count1))))->toInteger() * ("" + ((MathLib.factorial(count - count1))))->toInteger()))))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(arr): def choose(a,b): ans=1 A=max(b,a-b) B=min(b,a-b) for i in range(A+1,a+1): ans*=i for j in range(2,B+1): ans//=j return ans dic={} unique=[] for i in arr : if i not in dic : dic[i]=1 unique.append(i) else : dic[i]+=1 cnt,ans=3,1 for i in sorted(unique): cur=min(dic[i],cnt) cnt-=cur ans*=choose(dic[i],cur) if cnt==0 : break return ans n=int(input()) print(solve([int(i)for i in input().split()])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (solve(input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))))->display(); operation solve(arr : OclAny) : OclAny pre: true post: true activity: skip ; var dic : OclAny := Set{} ; var unique : Sequence := Sequence{} ; for i : arr do ( if (dic)->excludes(i) then ( dic[i+1] := 1 ; execute ((i) : unique) ) else ( dic[i+1] := dic[i+1] + 1 )) ; var cnt : OclAny := null; Sequence{cnt,ans} := Sequence{3,1} ; for i : unique->sort() do ( var cur : OclAny := Set{dic[i+1], cnt}->min() ; cnt := cnt - cur ; ans := ans * choose(dic[i+1], cur) ; if cnt = 0 then ( break ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) massiv_a=list(map(int,input().split())) massiv_a=sorted(massiv_a) x,y,z=massiv_a[0],massiv_a[1],massiv_a[2] if(xtoInteger() ; var massiv_a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; massiv_a := massiv_a->sort() ; var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := Sequence{massiv_a->first(),massiv_a[1+1],massiv_a[2+1]} ; if ((x->compareTo(y)) < 0 & (y < z)) then ( execute (massiv_a->count(z))->display() ) else skip ; if (((x->compareTo(y)) < 0) & (y = z)) then ( var sum_element : int := massiv_a->count(z) ; execute ((sum_element * (sum_element - 1)) div 2)->display() ) else skip ; if ((x = y) & ((y->compareTo(z)) < 0)) then ( execute (massiv_a->count(z))->display() ) else skip ; if ((x = y) & (y = z)) then ( sum_element := massiv_a->count(z) ; execute ((sum_element * (sum_element - 1) * (sum_element - 2)) div 6)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n=int(input()) a=sorted(map(int,input().split())) q=Counter(a) if a[0]==a[1]==a[2]: o=q[a[0]] print(o*(o-1)*(o-2)//6) elif a[0]==a[1]: o=q[a[0]] print((o*(o-1)//2)*q[a[2]]) elif a[1]==a[2]: o=q[a[1]] print((o*(o-1)//2)*q[a[0]]) else : print(q[a[0]]*q[a[1]]*q[a[2]]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var q : OclAny := Counter(a) ; if a->first() = a[1+1] & (a[1+1] == a[2+1]) then ( var o : OclAny := q[a->first()+1] ; execute (o * (o - 1) * (o - 2) div 6)->display() ) else (if a->first() = a[1+1] then ( o := q[a->first()+1] ; execute ((o * (o - 1) div 2) * q[a[2+1]+1])->display() ) else (if a[1+1] = a[2+1] then ( o := q[a[1+1]+1] ; execute ((o * (o - 1) div 2) * q[a->first()+1])->display() ) else ( execute (q[a->first()+1] * q[a[1+1]+1] * q[a[2+1]+1])->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- W=int(input()) w3=[] while W>0 : w3.append(W % 3) W=W//3 w3.append(0) for i in range(len(w3)-1): if w3[i]>1 : w3[i]=w3[i]-3 w3[i+1]=w3[i+1]+1 w3.reverse() if w3[0]==1 : print("+",end="") elif w3[0]==-1 : print("-",end="") for i in range(1,len(w3)): if w3[i]==1 : print("+",end="") elif w3[i]==0 : print("0",end="") elif w3[i]==-1 : print("-",end="") print("") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var W : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w3 : Sequence := Sequence{} ; while W > 0 do ( execute ((W mod 3) : w3) ; W := W div 3) ; execute ((0) : w3) ; for i : Integer.subrange(0, (w3)->size() - 1-1) do ( if w3[i+1] > 1 then ( w3[i+1] := w3[i+1] - 3 ; w3[i + 1+1] := w3[i + 1+1] + 1 ) else skip) ; w3 := w3->reverse() ; if w3->first() = 1 then ( execute ("+")->display() ) else (if w3->first() = -1 then ( execute ("-")->display() ) else skip) ; for i : Integer.subrange(1, (w3)->size()-1) do ( if w3[i+1] = 1 then ( execute ("+")->display() ) else (if w3[i+1] = 0 then ( execute ("0")->display() ) else (if w3[i+1] = -1 then ( execute ("-")->display() ) else skip ) ) ) ; execute ("")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) l=list(map(int,input().split())) d={} ans=0 for i in l : if i in d.keys(): d[i]+=1 else : d[i]=1 x=max(d.values()) if x % m==0 : None else : x=(int(x/m)+1)*m for i in d.values(): ans+=x-i print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := Set{} ; var ans : int := 0 ; for i : l do ( if (d.keys())->includes(i) then ( d[i+1] := d[i+1] + 1 ) else ( d[i+1] := 1 )) ; var x : OclAny := (d.values())->max() ; if x mod m = 0 then ( ) else ( x := (("" + ((x / m)))->toInteger() + 1) * m ) ; for i : d.values() do ( ans := ans + x - i) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline a,b,c=map(int,input().split()) x,y,z=map(int,input().split()) a1=a-x b1=b-y c1=c-z x=0 y=0 for i in[a1,b1,c1]: if i>0 : x+=i//2 else : y-=i if x>=y : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a1 : double := a - x ; var b1 : double := b - y ; var c1 : double := c - z ; var x : int := 0 ; var y : int := 0 ; for i : Sequence{a1}->union(Sequence{b1}->union(Sequence{ c1 })) do ( if i > 0 then ( x := x + i div 2 ) else ( y := y - i )) ; if (x->compareTo(y)) >= 0 then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") N=int(input()) ans="" while N>0 : if N % 3==2 : ans+='-' N+=1 elif N % 3==1 : ans+='+' else : ans+='0' N//=3 print(ans[: :-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : String := "" ; while N > 0 do ( if N mod 3 = 2 then ( ans := ans + '-' ; N := N + 1 ) else (if N mod 3 = 1 then ( ans := ans + '+' ) else ( ans := ans + '0' ) ) ; N := N div 3) ; execute (ans(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import product,starmap,dropwhile from math import log n=int(input()) m=int(log(n,3))+2 for a in product([-1,0,1],repeat=m): if n==sum(starmap(lambda t,x : 3**t*x,zip(reversed(range(m)),a))): print("".join(map(lambda x : "-0+"[x+1],dropwhile(lambda x : x==0,a)))) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := ("" + ((log(n, 3))))->toInteger() + 2 ; for a : product(Sequence{-1}->union(Sequence{0}->union(Sequence{ 1 })), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (name m)))))))) do ( if n = (starmap(lambda t : OclAny, x : OclAny in ((3)->pow(t) * x), Integer.subrange(1, (Integer.subrange(0, m-1))->reverse()->size())->collect( _indx | Sequence{(Integer.subrange(0, m-1))->reverse()->at(_indx), a->at(_indx)} )))->sum() then ( execute (StringLib.sumStringsWithSeparator(((dropwhile(lambda x : OclAny in (x = 0), a))->collect( _x | (lambda x : OclAny in ("-0+"[x + 1+1]))->apply(_x) )), ""))->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy BIG_NUM=2000000000 HUGE_NUM=99999999999999999 MOD=1000000007 EPS=0.000000001 sys.setrecursionlimit(3**12) SIZE=15 POW=[1]*SIZE for i in range(1,SIZE): POW[i]=POW[i-1]*3 W=int(input()) max_digit=None for i in range(SIZE): if(POW[i]-1)//2>=W : max_digit=i break ans=[None]*(max_digit+1) work=[None]*(max_digit+1) def recursive(digit,tmp_sum): global ans,work,W,max_digit if digit==-1 : if tmp_sum==W : for i in range(max_digit,-1,-1): ans[i]=work[i] return work[digit]='0' recursive(digit-1,tmp_sum) work[digit]='+' recursive(digit-1,tmp_sum+POW[digit]) if tmp_sum>0 : work[digit]='-' recursive(digit-1,tmp_sum-POW[digit]) recursive(max_digit,0) is_First=True for i in range(max_digit,-1,-1): if ans[i]=='0' : if is_First : continue else : print("0",end="") elif ans[i]=='+' : is_First=False print("+",end="") else : is_First=False print("-",end="") print() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute ans : OclAny; attribute work : OclAny; attribute W : OclAny; attribute max_digit : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var HUGE_NUM : int := 99999999999999999 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; sys.setrecursionlimit((3)->pow(12)) ; var SIZE : int := 15 ; var POW : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, SIZE) ; for i : Integer.subrange(1, SIZE-1) do ( POW[i+1] := POW[i - 1+1] * 3) ; var W : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var max_digit : OclAny := null ; for i : Integer.subrange(0, SIZE-1) do ( if ((POW[i+1] - 1) div 2->compareTo(W)) >= 0 then ( max_digit := i ; break ) else skip) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (max_digit + 1)) ; var work : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (max_digit + 1)) ; skip ; recursive(max_digit, 0) ; var is_First : boolean := true ; for i : Integer.subrange(-1 + 1, max_digit)->reverse() do ( if ans[i+1] = '0' then ( if is_First then ( continue ) else ( execute ("0")->display() ) ) else (if ans[i+1] = '+' then ( is_First := false ; execute ("+")->display() ) else ( is_First := false ; execute ("-")->display() ) ) ) ; execute (->display(); operation recursive(digit : OclAny, tmp_sum : OclAny) pre: true post: true activity: skip; skip; skip; skip ; if digit = -1 then ( if tmp_sum = W then ( for i : Integer.subrange(-1 + 1, max_digit)->reverse() do ( ans[i+1] := work[i+1]) ) else skip ; return ) else skip ; work[digit+1] := '0' ; recursive(digit - 1, tmp_sum) ; work[digit+1] := '+' ; recursive(digit - 1, tmp_sum + POW[digit+1]) ; if tmp_sum > 0 then ( work[digit+1] := '-' ; recursive(digit - 1, tmp_sum - POW[digit+1]) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from operator import itemgetter from fractions import gcd from math import ceil,floor from copy import deepcopy from itertools import accumulate from collections import Counter import math from functools import reduce sys.setrecursionlimit(200000) input=sys.stdin.readline def ii(): return int(input()) def mi(): return map(int,input().rstrip().split()) def lmi(): return list(map(int,input().rstrip().split())) def li(): return list(input().rstrip()) def debug(*args,sep=" ",end="\n"): print("debug:",*args,file=sys.stderr,sep=sep,end=end)if not __debug__ else None H,W=mi() S=[li()for i in range(H)] ans=[] for i in range(H): for j in range(W): if S[i][j]=="B" : ans.append((i,j)) ans.sort(key=lambda x : x[0]+x[1]) debug(ans[-1]) debug(ans[0]) tmp=abs(ans[-1][0]-ans[0][0])+abs(ans[-1][1]-ans[0][1]) ans.sort(key=lambda x : x[0]+(W-x[1])) debug(ans[-1]) debug(ans[0]) tmp2=abs(ans[-1][0]-ans[0][0])+abs(ans[-1][1]-ans[0][1]) print(max(tmp,tmp2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(200000) ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; skip ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := mi() ; var S : Sequence := Integer.subrange(0, H-1)->select(i | true)->collect(i | (li())) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, H-1) do ( for j : Integer.subrange(0, W-1) do ( if S[i+1][j+1] = "B" then ( execute ((Sequence{i, j}) : ans) ) else skip)) ; ans := ans->sort() ; debug(ans->last()) ; debug(ans->first()) ; var tmp : double := (ans->last()->first() - ans->first()->first())->abs() + (ans->last()[1+1] - ans->first()[1+1])->abs() ; ans := ans->sort() ; debug(ans->last()) ; debug(ans->first()) ; var tmp2 : double := (ans->last()->first() - ans->first()->first())->abs() + (ans->last()[1+1] - ans->first()[1+1])->abs() ; execute (Set{tmp, tmp2}->max())->display(); operation ii() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation mi() : OclAny pre: true post: true activity: return (input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ); operation lmi() : OclAny pre: true post: true activity: return ((input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )); operation li() : OclAny pre: true post: true activity: return (input().rstrip()); operation debug(args : OclAny : Sequence(OclAny), sep : String, end : String) pre: true post: true activity: (args * (named_parameter (name args))) if sep->oclIsUndefined() then sep := " " else skip; if end->oclIsUndefined() then end := "\n" else skip; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "debug:")))))) , (argument * (test (logical_test (comparison (expr (atom (name args))))))) , (argument (test (logical_test (comparison (expr (atom (name file)))))) = (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stderr))))))) , (argument (test (logical_test (comparison (expr (atom (name sep)))))) = (test (logical_test (comparison (expr (atom (name sep))))))) , (argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom (name end)))))))) )))))) if (logical_test not (logical_test (comparison (expr (atom (name __debug__)))))) else (test (logical_test (comparison (expr (atom None)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import product def calc(x): c=0 ; y=1 while 1 : if abs(x-y)<=(y-1)//2 : R=[0]*(c+1) R[c]=1 if xy : r=calc(x-y) for i in range(len(r)): R[i]=r[i] return R y*=3 c+=1 print(*map({-1 : '-',0 : '0',1 : '+'}.__getitem__,reversed(calc(int(input())))),sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; execute ((argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom { (dictorsetmaker (test (logical_test (comparison (expr (atom - (number (integer 1))))))) : (test (logical_test (comparison (expr (atom '-'))))) , (test (logical_test (comparison (expr (atom (number (integer 0))))))) : (test (logical_test (comparison (expr (atom '0'))))) , (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (test (logical_test (comparison (expr (atom '+')))))) }) (trailer . (name __getitem__))))))) , (argument (test (logical_test (comparison (expr (atom (name reversed)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name calc)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))) ))))))))) ))))))))) )))))))))->display(); operation calc(x : OclAny) : OclAny pre: true post: true activity: var c : int := 0; var y : int := 1 ; while 1 do ( if ((x - y)->abs()->compareTo((y - 1) div 2)) <= 0 then ( var R : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (c + 1)) ; R[c+1] := 1 ; if (x->compareTo(y)) < 0 then ( var r : OclAny := calc(y - x) ; for i : Integer.subrange(0, (r)->size()-1) do ( R[i+1] := -r[i+1]) ) else (if (x->compareTo(y)) > 0 then ( r := calc(x - y) ; for i : Integer.subrange(0, (r)->size()-1) do ( R[i+1] := r[i+1]) ) else skip) ; return R ) else skip ; y := y * 3 ; c := c + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,X,T=map(int,input().split()) k=N//X if N % X : k+=1 print(k*T) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var X : OclAny := null; var T : OclAny := null; Sequence{N,X,T} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : int := N div X ; if N mod X then ( k := k + 1 ) else skip ; execute (k * T)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,x,t=map(int,input().split()) ichiplate=math.ceil(n/x) print(ichiplate*t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var x : OclAny := null; var t : OclAny := null; Sequence{n,x,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ichiplate : double := (n / x)->ceil() ; execute (ichiplate * t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input().split(" ") N=int(a[0]) X=int(a[1]) T=int(a[2]) b=N//X if N % X!=0 : b+=1 print(b*T) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := input().split(" ") ; var N : int := ("" + ((a->first())))->toInteger() ; var X : int := ("" + ((a[1+1])))->toInteger() ; var T : int := ("" + ((a[2+1])))->toInteger() ; var b : int := N div X ; if N mod X /= 0 then ( b := b + 1 ) else skip ; execute (b * T)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : N,X,T=map(int,input().split()) print(((N+(X-1))//X)*T) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var N : OclAny := null; var X : OclAny := null; var T : OclAny := null; Sequence{N,X,T} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (((N + (X - 1)) div X) * T)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x,t=map(int,input().split()) nn=n//x amari=n % x if amari==0 : print(nn*t) else : print(nn*t+t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; var t : OclAny := null; Sequence{n,x,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var nn : int := n div x ; var amari : int := n mod x ; if amari = 0 then ( execute (nn * t)->display() ) else ( execute (nn * t + t)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b=map(int,input().split()) c=a+b+min(a,b)-2 if c==1 : c=0 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : double := a + b + Set{a, b}->min() - 2 ; if c = 1 then ( c := 0 ) else skip ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=list(map(int,input().split())) y=list(map(int,input().split())) e=0 for i in range(3): if a[i]-y[i]>=0 : e+=(a[i]-y[i])//2 else : e+=a[i]-y[i] print("YES" if e>=0 else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var y : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var e : int := 0 ; for i : Integer.subrange(0, 3-1) do ( if a[i+1] - y[i+1] >= 0 then ( e := e + (a[i+1] - y[i+1]) div 2 ) else ( e := e + a[i+1] - y[i+1] )) ; execute (if e >= 0 then "YES" else "NO" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def splitup(n,m): if m==n==1 : return 0 check=((m*n)% 2==0) if m>n : n,m=m,n if check : megan1=m-1+n-1 stanley1=(m-1)+1 else : megan1=(m//2)*2+(n-1) stanley1=(m//2)*2+1 res=megan1+stanley1 return res j=int(input("")) for i in range(j): n,m=[int(x)for x in input("").split()] print(splitup(n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var j : int := ("" + (((OclFile["System.in"]).readLine(""))))->toInteger() ; for i : Integer.subrange(0, j-1) do ( Sequence{n,m} := input("").split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (splitup(n, m))->display()); operation splitup(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: if m = n & (n == 1) then ( return 0 ) else skip ; var check : boolean := ((m * n) mod 2 = 0) ; if (m->compareTo(n)) > 0 then ( Sequence{n,m} := Sequence{m,n} ) else skip ; if check then ( var megan1 : double := m - 1 + n - 1 ; var stanley1 : double := (m - 1) + 1 ) else ( megan1 := (m div 2) * 2 + (n - 1) ; stanley1 := (m div 2) * 2 + 1 ) ; var res : OclAny := megan1 + stanley1 ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for lowbu in[*open(0)][1 :]: nuu,meh=sorted(map(int,lowbu.split())); print(2*nuu+meh-3+(meh>1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for lowbu : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var nuu : OclAny := null; var meh : OclAny := null; Sequence{nuu,meh} := (lowbu.split())->collect( _x | (OclType["int"])->apply(_x) )->sort(); execute (2 * nuu + meh - 3 + (meh > 1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W=map(int,input().split()) MAP=[list(input())for i in range(H)] BLIST=[] for i in range(H): for j in range(W): if MAP[i][j]=="B" : BLIST.append([i,j]) BLIST.sort(key=lambda x : x[0]+x[1]) ANS=abs(BLIST[0][0]-BLIST[-1][0])+abs(BLIST[0][1]-BLIST[-1][1]) BLIST.sort(key=lambda x : x[0]-x[1]) ANS=max(ANS,abs(BLIST[0][0]-BLIST[-1][0])+abs(BLIST[0][1]-BLIST[-1][1])) print(ANS) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var MAP : Sequence := Integer.subrange(0, H-1)->select(i | true)->collect(i | (((OclFile["System.in"]).readLine())->characters())) ; var BLIST : Sequence := Sequence{} ; for i : Integer.subrange(0, H-1) do ( for j : Integer.subrange(0, W-1) do ( if MAP[i+1][j+1] = "B" then ( execute ((Sequence{i}->union(Sequence{ j })) : BLIST) ) else skip)) ; BLIST := BLIST->sort() ; var ANS : double := (BLIST->first()->first() - BLIST->last()->first())->abs() + (BLIST->first()[1+1] - BLIST->last()[1+1])->abs() ; BLIST := BLIST->sort() ; ANS := Set{ANS, (BLIST->first()->first() - BLIST->last()->first())->abs() + (BLIST->first()[1+1] - BLIST->last()[1+1])->abs()}->max() ; execute (ANS)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): li=list(map(int,input().split())) n=li[0] m=li[1] if m==n==1 : res=0 elif n==1 or m==1 : res=max(m,n)-min(m,n)+1 else : res=max(m,n)-1+(min(m,n)-1)*2+1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var li : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := li->first() ; var m : OclAny := li[1+1] ; if m = n & (n == 1) then ( var res : int := 0 ) else (if n = 1 or m = 1 then ( res := Set{m, n}->max() - Set{m, n}->min() + 1 ) else ( res := Set{m, n}->max() - 1 + (Set{m, n}->min() - 1) * 2 + 1 ) ) ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(0,t): lista=list(map(int,input().split())) n=lista[0] m=lista[1] if n==1 and m==1 : print(0) continue if n>=m : print(n+2*m-2) else : print(m+2*n-2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var lista : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := lista->first() ; var m : OclAny := lista[1+1] ; if n = 1 & m = 1 then ( execute (0)->display() ; continue ) else skip ; if (n->compareTo(m)) >= 0 then ( execute (n + 2 * m - 2)->display() ) else ( execute (m + 2 * n - 2)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if(n % 4==0 or n % 4==3): print(0) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n mod 4 = 0 or n mod 4 = 3) then ( execute (0)->display() ) else ( execute (1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) if math.ceil(n/2.0)% 2==0 : print("0") else : print("1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n / 2.0)->ceil() mod 2 = 0 then ( execute ("0")->display() ) else ( execute ("1")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) if(a % 4==3 or a % 4==0): print(0) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (a mod 4 = 3 or a mod 4 = 0) then ( execute (0)->display() ) else ( execute (1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 4==1 or n % 4==2 : print(1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 4 = 1 or n mod 4 = 2 then ( execute (1)->display() ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 4==1 or n % 4==2 : print(1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 4 = 1 or n mod 4 = 2 then ( execute (1)->display() ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def andOperator(a,b): while(adisplay(); operation andOperator(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: while ((a->compareTo(b)) < 0) do ( b := b - (MathLib.bitwiseAnd(b, -b))) ; return b; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def OR(a,n): ans=a[0] for i in range(1,n): ans |=a[i] return ans if __name__=='__main__' : a=[1,4,6] n=len(a) print(OR(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := Sequence{1}->union(Sequence{4}->union(Sequence{ 6 })) ; n := (a)->size() ; execute (OR(a, n))->display() ) else skip; operation OR(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : OclAny := a->first() ; for i : Integer.subrange(1, n-1) do ( ans := ans or a[i+1]) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checking(s): c=0 n=len(s) i=n-1 while(i>=0): if(s[i]=='0'): c+=1 if(c>=6 and s[i]=='1'): return True i-=1 return False if __name__=='__main__' : s="100010001" if(checking(s)): print("Possible") else : print("Not possible") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( s := "100010001" ; if (checking(s)) then ( execute ("Possible")->display() ) else ( execute ("Not possible")->display() ) ) else skip; operation checking(s : OclAny) : OclAny pre: true post: true activity: var c : int := 0 ; var n : int := (s)->size() ; var i : double := n - 1 ; while (i >= 0) do ( if (s[i+1] = '0') then ( c := c + 1 ) else skip ; if (c >= 6 & s[i+1] = '1') then ( return true ) else skip ; i := i - 1) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ss(a,b): a=min(a,b) return a*(a+1)//2+(b-a)*a def solve(a,b,p): lft=p-1 rt=a-p b-=a x=0 y=b while x!=y : tmp=(x+y+1)//2 if ss(lft,tmp-1)+ss(rt,tmp-1)+tmp>b : y=tmp-1 else : x=tmp return x+1 a,b,p=map(int,input().split()) print(solve(a,b,p)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{a,b,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (solve(a, b, p))->display(); operation ss(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: a := Set{a, b}->min() ; return a * (a + 1) div 2 + (b - a) * a; operation solve(a : OclAny, b : OclAny, p : OclAny) : OclAny pre: true post: true activity: var lft : double := p - 1 ; var rt : double := a - p ; b := b - a ; var x : int := 0 ; var y : OclAny := b ; while x /= y do ( var tmp : int := (x + y + 1) div 2 ; if (ss(lft, tmp - 1) + ss(rt, tmp - 1) + tmp->compareTo(b)) > 0 then ( y := tmp - 1 ) else ( x := tmp )) ; return x + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n,k=map(int,input().split()) if k==1 : print(n) sys.exit(0) ans=1 while anscollect( _x | (OclType["int"])->apply(_x) ) ; if k = 1 then ( execute (n)->display() ; sys.exit(0) ) else skip ; var ans : int := 1 ; while (ans->compareTo(n)) < 0 do ( ans := ans * 2 + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) if k==1 : print(n) exit() mx=1 while mx*2<=n : mx<<=1 print(mx*2-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if k = 1 then ( execute (n)->display() ; exit() ) else skip ; var mx : int := 1 ; while (mx * 2->compareTo(n)) <= 0 do ( mx := mx * (2->pow(1))) ; execute (mx * 2 - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) if k==1 : print(n) else : ans=1 while ans<=n : ans*=2 print(ans-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if k = 1 then ( execute (n)->display() ) else ( var ans : int := 1 ; while (ans->compareTo(n)) <= 0 do ( ans := ans * 2) ; execute (ans - 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n,k=map(int,input().split()) if k==1 : print(n) sys.exit(0) ans=1 while anscollect( _x | (OclType["int"])->apply(_x) ) ; if k = 1 then ( execute (n)->display() ; sys.exit(0) ) else skip ; var ans : int := 1 ; while (ans->compareTo(n)) < 0 do ( ans := ans * 2 + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n,k=map(int,input().split()) if k==1 : print(n) sys.exit(0) ans=1 while anscollect( _x | (OclType["int"])->apply(_x) ) ; if k = 1 then ( execute (n)->display() ; sys.exit(0) ) else skip ; var ans : int := 1 ; while (ans->compareTo(n)) < 0 do ( ans := ans * 2 + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pairs(n): c=[[0 for i in range(10)]for i in range(10)] tmp=1 for i in range(1,n+1): if(i>=tmp*10): tmp*=10 c[i//tmp][i % 10]+=1 ans=0 for i in range(1,10): for j in range(1,10): ans+=c[i][j]*c[j][i] return ans if __name__=='__main__' : n=25 print(pairs(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 25 ; execute (pairs(n))->display() ) else skip; operation pairs(n : OclAny) : OclAny pre: true post: true activity: var c : Sequence := Integer.subrange(0, 10-1)->select(i | true)->collect(i | (Integer.subrange(0, 10-1)->select(i | true)->collect(i | (0)))) ; var tmp : int := 1 ; for i : Integer.subrange(1, n + 1-1) do ( if ((i->compareTo(tmp * 10)) >= 0) then ( tmp := tmp * 10 ) else skip ; c[i div tmp+1][i mod 10+1] := c[i div tmp+1][i mod 10+1] + 1) ; var ans : int := 0 ; for i : Integer.subrange(1, 10-1) do ( for j : Integer.subrange(1, 10-1) do ( ans := ans + c[i+1][j+1] * c[j+1][i+1])) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): ans=get_expected_singles((1,))-2 return f"{ans:.6f}" @ eulerlib.memoize def get_expected_singles(state): result=0.0 if len(state)>0 : for i in range(len(state)): tempstate=list(state) sheet=state[i] del tempstate[i] for j in range(sheet+1,6): tempstate.append(j) tempstate.sort() result+=get_expected_singles(tuple(tempstate)) result/=len(state) if len(state)==1 : result+=1.0 return result if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; (compound_stmt (decorator @ (dotted_name (dotted_name (name eulerlib)) . (name memoize))) (funcdef def (name get_expected_singles) ( (typedargslist (def_parameters (def_parameter (named_parameter (name state))))) ) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name result)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number 0.0)))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name state)))))))) ))))) > (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name state)))))))) ))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name tempstate)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name state)))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sheet)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name state)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))))))) (stmt (simple_stmt (small_stmt del (exprlist (expr (atom (name tempstate)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) (stmt (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name sheet))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 6))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name tempstate)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) ))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name tempstate)) (trailer . (name sort) (arguments ( )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name result)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name get_expected_singles)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name tuple)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name tempstate)))))))) ))))))))) ))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name result)))))))) (assign_part /= (testlist (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name state)))))))) )))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name state)))))))) ))))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name result)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number 1.0))))))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name result))))))))))))) ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : double := get_expected_singles(Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1))))))) ,)}) - 2 ; return StringLib.formattedString("{ans:.6f}"); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numberOfPainters(arr,n,maxLen): total=0 numPainters=1 for i in arr : total+=i if(total>maxLen): total=i numPainters+=1 return numPainters def partition(arr,n,k): lo=max(arr) hi=sum(arr) while(lounion(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 9 })))))))) ; n := (arr)->size() ; k := 3 ; execute (("" + ((partition(arr, n, k))))->toInteger())->display(); operation numberOfPainters(arr : OclAny, n : OclAny, maxLen : OclAny) : OclAny pre: true post: true activity: var total : int := 0 ; var numPainters : int := 1 ; for i : arr do ( total := total + i ; if ((total->compareTo(maxLen)) > 0) then ( total := i ; numPainters := numPainters + 1 ) else skip) ; return numPainters; operation partition(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var lo : OclAny := (arr)->max() ; var hi : OclAny := (arr)->sum() ; while ((lo->compareTo(hi)) < 0) do ( var mid : OclAny := lo + (hi - lo) / 2 ; var requiredPainters : OclAny := numberOfPainters(arr, n, mid) ; if ((requiredPainters->compareTo(k)) <= 0) then ( hi := mid ) else ( lo := mid + 1 )) ; return lo; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkForElement(array,n): sum=0 for i in range(n): sum+=array[i] if(sum % 2): return False sum//=2 start=0 end=n-1 while(start<=end): mid=start+(end-start)//2 if(array[mid]==sum): return True elif(array[mid]>sum): end=mid-1 ; else : start=mid+1 return False if __name__=="__main__" : array=[1,2,3] n=len(array) if(checkForElement(array,n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( array := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; n := (array)->size() ; if (checkForElement(array, n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation checkForElement(array : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + array[i+1]) ; if (sum mod 2) then ( return false ) else skip ; sum := sum div 2 ; var start : int := 0 ; var end : double := n - 1 ; while ((start->compareTo(end)) <= 0) do ( var mid : int := start + (end - start) div 2 ; if (array[mid+1] = sum) then ( return true ) else (if ((array[mid+1]->compareTo(sum)) > 0) then ( end := mid - 1; ) else ( start := mid + 1 ) ) ) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def countDistinct(arr,k,n): mp=defaultdict(lambda : 0) dist_count=0 for i in range(k): if mp[arr[i]]==0 : dist_count+=1 mp[arr[i]]+=1 print(dist_count) for i in range(k,n): if mp[arr[i-k]]==1 : dist_count-=1 mp[arr[i-k]]-=1 if mp[arr[i]]==0 : dist_count+=1 mp[arr[i]]+=1 print(dist_count) arr=[1,2,1,3,4,2,3] n=len(arr) k=4 countDistinct(arr,k,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{3}->union(Sequence{4}->union(Sequence{2}->union(Sequence{ 3 })))))) ; n := (arr)->size() ; k := 4 ; countDistinct(arr, k, n); operation countDistinct(arr : OclAny, k : OclAny, n : OclAny) pre: true post: true activity: var mp : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; var dist_count : int := 0 ; for i : Integer.subrange(0, k-1) do ( if mp[arr[i+1]+1] = 0 then ( dist_count := dist_count + 1 ) else skip ; mp[arr[i+1]+1] := mp[arr[i+1]+1] + 1) ; execute (dist_count)->display() ; for i : Integer.subrange(k, n-1) do ( if mp[arr[i - k+1]+1] = 1 then ( dist_count := dist_count - 1 ) else skip ; mp[arr[i - k+1]+1] := mp[arr[i - k+1]+1] - 1 ; if mp[arr[i+1]+1] = 0 then ( dist_count := dist_count + 1 ) else skip ; mp[arr[i+1]+1] := mp[arr[i+1]+1] + 1 ; execute (dist_count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def inpl(): return list(map(int,input().split())) H,W=inpl() ans=0 C=[input()for _ in range(H)] for i in range(2): L=[0]*H R=[0]*H Lk=[] Rk=[] for h in range(H): L[h]=C[h].find("B") R[h]=C[h].rfind("B") if L[h]>=0 : Lk.append(h) if R[h]>=0 : Rk.append(h) for lh in Lk : for rh in Rk : ans=max(ans,abs(L[lh]-R[rh])+abs(lh-rh)) if i==0 : C=["".join(c)for c in zip(*C)] H,W=W,H print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := inpl() ; var ans : int := 0 ; var C : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; for i : Integer.subrange(0, 2-1) do ( var L : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, H) ; var R : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, H) ; var Lk : Sequence := Sequence{} ; var Rk : Sequence := Sequence{} ; for h : Integer.subrange(0, H-1) do ( L[h+1] := C[h+1]->indexOf("B") - 1 ; R[h+1] := C[h+1].rfind("B") ; if L[h+1] >= 0 then ( execute ((h) : Lk) ) else skip ; if R[h+1] >= 0 then ( execute ((h) : Rk) ) else skip) ; for lh : Lk do ( for rh : Rk do ( ans := Set{ans, (L[lh+1] - R[rh+1])->abs() + (lh - rh)->abs()}->max())) ; if i = 0 then ( C := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name C)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name C)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name C)))))))`third->at(_indx)} )->select(c | true)->collect(c | (StringLib.sumStringsWithSeparator((c), ""))) ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := Sequence{W,H} ) else skip) ; execute (ans)->display(); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) if(a>=0 and a<=100)and(b>=0 and b<=100)and(c>=0 and c<=100): if acollect( _x | (OclType["int"])->apply(_x) ) ; if (a >= 0 & a <= 100) & (b >= 0 & b <= 100) & (c >= 0 & c <= 100) then ( if (a->compareTo(b)) < 0 & (b < c) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def main(args): a,b,c=map(int,input().split()) if acollect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(b)) < 0 & (b < c) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- number=input() number_list=number.split(' ') a=0 b=0 c=0 for i in number_list : a=number_list[0] b=number_list[1] c=number_list[2] if int(a)first() ; b := number_list[1+1] ; c := number_list[2+1]) ; if (("" + ((a)))->toInteger()->compareTo(("" + ((b)))->toInteger())) < 0 & (("" + ((b)))->toInteger()->compareTo(("" + ((c)))->toInteger())) < 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=list(map(int,input().split())) a=l[0] b=l[1] c=l[2] if acollect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := l->first() ; var b : OclAny := l[1+1] ; var c : OclAny := l[2+1] ; if (a->compareTo(b)) < 0 & (b < c) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=(int(x)for x in input().split()) if acompareTo(b)) < 0 & (b < c) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import sqrt from collections import defaultdict from math import* import sys from typing import Counter input=sys.stdin.readline n=list(map(int,input().split()))[0] s=list(map(str,input().split()))[0] p=set() arr=[] for i in range(n): a,b=list(map(int,input().split())) arr.append([a,b]) p.add(a) l=[0]*124 bulb=0 for i,j in arr : m,n=i,j light=1 if s[bulb]=='1' else 0 bulb+=1 for k in range(len(l)): if n : l[k]+=light n-=1 if not n : m=i light=0 if light==1 else 1 elif m : m-=1 l[k]+=light if not m : n=i light=0 if light==1 else 1 print(max(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->first() ; var s : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["String"])->apply(_x) ))->first() ; var p : Set := Set{}->union(()) ; var arr : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((Sequence{a}->union(Sequence{ b })) : arr) ; execute ((a) : p)) ; var l : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 124) ; var bulb : int := 0 ; for _tuple : arr do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); var m : OclAny := null; Sequence{m,n} := Sequence{i,j} ; var light : int := if s[bulb+1] = '1' then 1 else 0 endif ; bulb := bulb + 1 ; for k : Integer.subrange(0, (l)->size()-1) do ( if n then ( l[k+1] := l[k+1] + light ; n := n - 1 ; if not(n) then ( var m : OclAny := i ; light := if light = 1 then 0 else 1 endif ) else skip ) else (if m then ( m := m - 1 ; l[k+1] := l[k+1] + light ; if not(m) then ( n := i ; light := if light = 1 then 0 else 1 endif ) else skip ) else skip))) ; execute ((l)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate n,t=map(int,input().split()) a=[0]*(t+1) for l,r in(map(int,input().split())for _ in range(n)): a[l]+=1 a[r]-=1 print(max(accumulate(a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (t + 1)) ; for _tuple : Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))} do (var _indx : int := 1; var l : OclAny := _tuple->at(_indx); _indx := _indx + 1; var r : OclAny := _tuple->at(_indx); a[l+1] := a[l+1] + 1 ; a[r+1] := a[r+1] - 1) ; execute ((accumulate(a))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(events): ans,customer=0,0 for _,e in events : customer+=e ans=max(ans,customer) return ans def main(args): N,T=map(int,input().split()) events=[] for _ in range(N): l,r=map(int,input().split()) events.append((l,1)) events.append((r,-1)) ans=solve(sorted(events)) print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(events : OclAny) : OclAny pre: true post: true activity: var ans : OclAny := null; var customer : OclAny := null; Sequence{ans,customer} := Sequence{0,0} ; for _tuple : events do (var _indx : int := 1; var _anon : OclAny := _tuple->at(_indx); _indx := _indx + 1; var e : OclAny := _tuple->at(_indx); customer := customer + e ; var ans : OclAny := Set{ans, customer}->max()) ; return ans; operation main(args : OclAny) pre: true post: true activity: var N : OclAny := null; var T : OclAny := null; Sequence{N,T} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; events := Sequence{} ; for _anon : Integer.subrange(0, N-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{l, 1}) : events) ; execute ((Sequence{r, -1}) : events)) ; ans := solve(events->sort()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop BIG_NUM=2000000000 HUGE_NUM=9999999999999999 MOD=1000000007 EPS=0.000000001 N,T=map(int,input().split()) table=[0]*(T+1) for loop in range(N): left,right=map(int,input().split()) table[left]+=1 table[right]-=1 ans=table[0] for i in range(1,T+1): table[i]+=table[i-1] ans=max(ans,table[i]) print("%d" %(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var HUGE_NUM : int := 9999999999999999 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; var N : OclAny := null; var T : OclAny := null; Sequence{N,T} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var table : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (T + 1)) ; for loop : Integer.subrange(0, N-1) do ( var left : OclAny := null; var right : OclAny := null; Sequence{left,right} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; table[left+1] := table[left+1] + 1 ; table[right+1] := table[right+1] - 1) ; var ans : OclAny := table->first() ; for i : Integer.subrange(1, T + 1-1) do ( table[i+1] := table[i+1] + table[i - 1+1] ; ans := Set{ans, table[i+1]}->max()) ; execute (StringLib.format("%d",(ans)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline N,T=map(int,input().split()) imos=[0 for _ in range(T+1)] for _ in range(N): l,r=map(int,input().split()) imos[l]+=1 imos[r]-=1 for i in range(T): imos[i+1]+=imos[i] print(max(imos)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var N : OclAny := null; var T : OclAny := null; Sequence{N,T} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var imos : Sequence := Integer.subrange(0, T + 1-1)->select(_anon | true)->collect(_anon | (0)) ; for _anon : Integer.subrange(0, N-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; imos[l+1] := imos[l+1] + 1 ; imos[r+1] := imos[r+1] - 1) ; for i : Integer.subrange(0, T-1) do ( imos[i + 1+1] := imos[i + 1+1] + imos[i+1]) ; execute ((imos)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=[] for i in range(2): c.append(input()) if c[0][0]==c[1][2]and c[0][1]==c[1][1]and c[0][2]==c[1][0]: print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : Sequence := Sequence{} ; for i : Integer.subrange(0, 2-1) do ( execute (((OclFile["System.in"]).readLine()) : c)) ; if c->first()->first() = c[1+1][2+1] & c->first()[1+1] = c[1+1][1+1] & c->first()[2+1] = c[1+1]->first() then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W=map(int,input().split()) builds=[] for h in range(H): l=str(input()) for w in range(W): if l[w]=="B" : builds.append([h,w]) ans=0 for i,hw1 in enumerate(builds): for hw2 in builds[i+1 :]: ans=max(ans,abs(hw1[0]-hw2[0])+abs(hw1[1]-hw2[1])) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var builds : Sequence := Sequence{} ; for h : Integer.subrange(0, H-1) do ( var l : String := ("" + (((OclFile["System.in"]).readLine()))) ; for w : Integer.subrange(0, W-1) do ( if l[w+1] = "B" then ( execute ((Sequence{h}->union(Sequence{ w })) : builds) ) else skip)) ; var ans : int := 0 ; for _tuple : Integer.subrange(1, (builds)->size())->collect( _indx | Sequence{_indx-1, (builds)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var hw1 : OclAny := _tuple->at(_indx); for hw2 : builds.subrange(i + 1+1) do ( ans := Set{ans, (hw1->first() - hw2->first())->abs() + (hw1[1+1] - hw2[1+1])->abs()}->max())) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): ans=sum(i for i in range(1000000)if is_decimal_binary_palindrome(i)) return str(ans) def is_decimal_binary_palindrome(n): s=str(n) if s!=s[: :-1]: return False t=bin(n)[2 :] return t==t[: :-1] if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1000000))))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (atom (name is_decimal_binary_palindrome)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))))->sum() ; return ("" + ((ans))); operation is_decimal_binary_palindrome(n : OclAny) : OclAny pre: true post: true activity: var s : String := ("" + ((n))) ; if s /= s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( return false ) else skip ; var t : OclAny := bin(n).subrange(2+1) ; return t = t(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : N,T=map(lambda x : int(x),input().split()) table=[0]*(T+1) for idx in range(N): l,r=map(lambda x : int(x),input().split()) table[l]+=1 table[r]-=1 ans=table[0] for idx in range(1,T+1): table[idx]+=table[idx-1] ans=max(ans,table[idx]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var N : OclAny := null; var T : OclAny := null; Sequence{N,T} := (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ) ; var table : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (T + 1)) ; for idx : Integer.subrange(0, N-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ) ; table[l+1] := table[l+1] + 1 ; table[r+1] := table[r+1] - 1) ; var ans : OclAny := table->first() ; for idx : Integer.subrange(1, T + 1-1) do ( table[idx+1] := table[idx+1] + table[idx - 1+1] ; ans := Set{ans, table[idx+1]}->max()) ; execute (ans)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) x=["purple","green","blue","orange","red","yellow"] y=["Power","Time","Space","Soul","Reality","Mind"] s=set([input().rstrip()for _ in range(n)]) ans=[] for i,j in zip(x,y): if not i in s : ans.append(j) m=len(ans) print(m) sys.stdout.write("\n".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := Sequence{"purple"}->union(Sequence{"green"}->union(Sequence{"blue"}->union(Sequence{"orange"}->union(Sequence{"red"}->union(Sequence{ "yellow" }))))) ; var y : Sequence := Sequence{"Power"}->union(Sequence{"Time"}->union(Sequence{"Space"}->union(Sequence{"Soul"}->union(Sequence{"Reality"}->union(Sequence{ "Mind" }))))) ; var s : Set := Set{}->union((Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (input().rstrip())))) ; var ans : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, x->size())->collect( _indx | Sequence{x->at(_indx), y->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if not((s)->includes(i)) then ( execute ((j) : ans) ) else skip) ; var m : int := (ans)->size() ; execute (m)->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l1=['purple','green','blue','orange','red','yellow'] l2=['Power','Time','Space','Soul','Reality','Mind'] print(6-n) for j in range(n): a=l1.index(input()) l1[a]='no' for k in range(0,len(l1)): if l1[k]!='no' : print(l2[k]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l1 : Sequence := Sequence{'purple'}->union(Sequence{'green'}->union(Sequence{'blue'}->union(Sequence{'orange'}->union(Sequence{'red'}->union(Sequence{ 'yellow' }))))) ; var l2 : Sequence := Sequence{'Power'}->union(Sequence{'Time'}->union(Sequence{'Space'}->union(Sequence{'Soul'}->union(Sequence{'Reality'}->union(Sequence{ 'Mind' }))))) ; execute (6 - n)->display() ; for j : Integer.subrange(0, n-1) do ( var a : int := l1->indexOf((OclFile["System.in"]).readLine()) - 1 ; l1[a+1] := 'no') ; for k : Integer.subrange(0, (l1)->size()-1) do ( if l1[k+1] /= 'no' then ( execute (l2[k+1])->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) l=[] for i in range(t): s=input() l.append(s) l1=[] if 'red' not in l : l1.append('Reality') if 'purple' not in l : l1.append('Power') if 'blue' not in l : l1.append('Space') if 'green' not in l : l1.append('Time') if 'orange' not in l : l1.append('Soul') if 'yellow' not in l : l1.append('Mind') print(len(l1)) for i in l1 : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( var s : String := (OclFile["System.in"]).readLine() ; execute ((s) : l)) ; var l1 : Sequence := Sequence{} ; if (l)->excludes('red') then ( execute (('Reality') : l1) ) else skip ; if (l)->excludes('purple') then ( execute (('Power') : l1) ) else skip ; if (l)->excludes('blue') then ( execute (('Space') : l1) ) else skip ; if (l)->excludes('green') then ( execute (('Time') : l1) ) else skip ; if (l)->excludes('orange') then ( execute (('Soul') : l1) ) else skip ; if (l)->excludes('yellow') then ( execute (('Mind') : l1) ) else skip ; execute ((l1)->size())->display() ; for i : l1 do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- stones={'purple' : 'Power','green' : 'Time','blue' : 'Space','orange' : 'Soul','red' : 'Reality','yellow' : 'Mind'} m=int(input()) while m>0 : m-=1 del stones[input()] print(len(stones)) for key,value in stones.items(): print(value) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var stones : Map := Map{ 'purple' |-> 'Power' }->union(Map{ 'green' |-> 'Time' }->union(Map{ 'blue' |-> 'Space' }->union(Map{ 'orange' |-> 'Soul' }->union(Map{ 'red' |-> 'Reality' }->union(Map{ 'yellow' |-> 'Mind' }))))) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while m > 0 do ( m := m - 1 ; execute (stones[(OclFile["System.in"]).readLine()+1])->isDeleted()) ; execute ((stones)->size())->display() ; for _tuple : stones->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); execute (value)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d={'purple' : 'Power','green' : 'Time','blue' : 'Space','orange' : 'Soul','red' : 'Reality','yellow' : 'Mind'} l=[] k=[] m=d.keys() for _ in range(int(input())): l.append(input('')) for i in m : if i not in l : k.append(d[i]) print(len(k)) print('\n'.join(k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : Map := Map{ 'purple' |-> 'Power' }->union(Map{ 'green' |-> 'Time' }->union(Map{ 'blue' |-> 'Space' }->union(Map{ 'orange' |-> 'Soul' }->union(Map{ 'red' |-> 'Reality' }->union(Map{ 'yellow' |-> 'Mind' }))))) ; var l : Sequence := Sequence{} ; var k : Sequence := Sequence{} ; var m : OclAny := d.keys() ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (((OclFile["System.in"]).readLine('')) : l)) ; for i : m do ( if (l)->excludes(i) then ( execute ((d[i+1]) : k) ) else skip) ; execute ((k)->size())->display() ; execute (StringLib.sumStringsWithSeparator((k), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CountSpecialPalindrome(str): n=len(str); result=0 ; sameChar=[0]*n ; i=0 ; while(i0 and j<(n-1)and(str[j-1]==str[j+1]and str[j]!=str[j-1])): result+=(sameChar[j-1]if(sameChar[j-1]display();; operation CountSpecialPalindrome(OclType["String"] : OclAny) pre: true post: true activity: var n : int := (OclType["String"])->size(); ; var result : int := 0; ; var sameChar : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; var i : int := 0; ; while ((i->compareTo(n)) < 0) do ( var sameCharCount : int := 1; ; var j : int := i + 1; ; while ((j->compareTo(n)) < 0) do ( if (("" + ([i+1])) /= ("" + ([j+1]))) then ( break; ) else skip ; sameCharCount := sameCharCount + 1; ; j := j + 1;) ; result := result + ("" + ((sameCharCount * (sameCharCount + 1) / 2)))->toInteger(); ; sameChar[i+1] := sameCharCount; ; i := j;) ; for j : Integer.subrange(1, n-1) do ( if (("" + ([j+1])) = ("" + ([j - 1+1]))) then ( sameChar[j+1] := sameChar[j - 1+1]; ) else skip ; if (j > 0 & (j->compareTo((n - 1))) < 0 & (("" + ([j - 1+1])) = ("" + ([j + 1+1])) & ("" + ([j+1])) /= ("" + ([j - 1+1])))) then ( result := result + (if ((sameChar[j - 1+1]->compareTo(sameChar[j + 1+1])) < 0) then sameChar[j - 1+1] else sameChar[j + 1+1] endif); ) else skip) ; return result - n;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isAMultipleOf4(n): if((n & 3)==0): return "Yes" return "No" if __name__=="__main__" : n=16 print(isAMultipleOf4(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 16 ; execute (isAMultipleOf4(n))->display() ) else skip; operation isAMultipleOf4(n : OclAny) : OclAny pre: true post: true activity: if ((MathLib.bitwiseAnd(n, 3)) = 0) then ( return "Yes" ) else skip ; return "No"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minOperations(n,m,k,matrix): arr=[0]*(n*m) mod=matrix[0][0]% k for i in range(0,n): for j in range(0,m): arr[i*m+j]=matrix[i][j] if matrix[i][j]% k!=mod : return-1 arr.sort() median=arr[(n*m)//2] minOperations=0 for i in range(0,n*m): minOperations+=abs(arr[i]-median)//k if(n*m)% 2==0 : median2=arr[(n*m)//2] minOperations2=0 for i in range(0,n*m): minOperations2+=abs(arr[i]-median2)//k minOperations=min(minOperations,minOperations2) return minOperations if __name__=="__main__" : matrix=[[2,4,6],[8,10,12],[14,16,18],[20,22,24]] n=len(matrix) m=len(matrix[0]) k=2 print(minOperations(n,m,k,matrix)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( matrix := Sequence{Sequence{2}->union(Sequence{4}->union(Sequence{ 6 }))}->union(Sequence{Sequence{8}->union(Sequence{10}->union(Sequence{ 12 }))}->union(Sequence{Sequence{14}->union(Sequence{16}->union(Sequence{ 18 }))}->union(Sequence{ Sequence{20}->union(Sequence{22}->union(Sequence{ 24 })) }))) ; n := (matrix)->size() ; m := (matrix->first())->size() ; k := 2 ; execute (minOperations(n, m, k, matrix))->display() ) else skip; operation minOperations(n : OclAny, m : OclAny, k : OclAny, matrix : OclAny) : OclAny pre: true post: true activity: var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n * m)) ; var mod : int := matrix->first()->first() mod k ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( arr[i * m + j+1] := matrix[i+1][j+1] ; if matrix[i+1][j+1] mod k /= mod then ( return -1 ) else skip)) ; arr := arr->sort() ; var median : OclAny := arr[(n * m) div 2+1] ; var minOperations : int := 0 ; for i : Integer.subrange(0, n * m-1) do ( minOperations := minOperations + (arr[i+1] - median)->abs() div k) ; if (n * m) mod 2 = 0 then ( var median2 : OclAny := arr[(n * m) div 2+1] ; var minOperations2 : int := 0 ; for i : Integer.subrange(0, n * m-1) do ( minOperations2 := minOperations2 + (arr[i+1] - median2)->abs() div k) ; minOperations := Set{minOperations, minOperations2}->min() ) else skip ; return minOperations; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minReplacement(string): if len(string)>26 : print("IMPOSSIBLE") else : Hash=[0]*26 for i in range(0,len(string)): Hash[ord(string[i])-ord('a')]+=1 count=0 for i in range(0,len(string)): if Hash[ord(string[i])-ord('a')]>1 : for j in range(0,26): if Hash[j]==0 : Hash[ord(string[i])-ord('a')]-=1 string[i]=chr(j+ord('a')) Hash[j]+=1 break print(''.join(string)) if __name__=="__main__" : string="xxxxyyyy" minReplacement(list(string)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( string := "xxxxyyyy" ; minReplacement((string)->characters()) ) else skip; operation minReplacement(string : OclAny) pre: true post: true activity: if (string)->size() > 26 then ( execute ("IMPOSSIBLE")->display() ) else ( var Hash : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for i : Integer.subrange(0, (string)->size()-1) do ( Hash[(string[i+1])->char2byte() - ('a')->char2byte()+1] := Hash[(string[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; var count : int := 0 ; for i : Integer.subrange(0, (string)->size()-1) do ( if Hash[(string[i+1])->char2byte() - ('a')->char2byte()+1] > 1 then ( for j : Integer.subrange(0, 26-1) do ( if Hash[j+1] = 0 then ( Hash[(string[i+1])->char2byte() - ('a')->char2byte()+1] := Hash[(string[i+1])->char2byte() - ('a')->char2byte()+1] - 1 ; string[i+1] := (j + ('a')->char2byte())->byte2char() ; Hash[j+1] := Hash[j+1] + 1 ; break ) else skip) ) else skip) ; execute (StringLib.sumStringsWithSeparator((string), ''))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) h=int(input()) S=(a+b)*h/2 print(int(S)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var h : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : double := (a + b) * h / 2 ; execute (("" + ((S)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def partition(A,p,r): q=p for i in range(p,r): if A[i][1]<=A[r][1]: A[q],A[i]=A[i],A[q] q+=1 A[q],A[r]=A[r],A[q] return q def quicksort(A,left,right): if leftA[i][2]: return "Not stable" return "Stable" n=int(input()) data=[] for i in range(n): mark,num=map(str,input().split()) data+=[[mark,int(num),i]] quicksort(data,0,len(data)-1) print(check_stable(data)) for line in data : print(line[0],line[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var data : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var mark : OclAny := null; var num : OclAny := null; Sequence{mark,num} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; data := data + Sequence{ Sequence{mark}->union(Sequence{("" + ((num)))->toInteger()}->union(Sequence{ i })) }) ; quicksort(data, 0, (data)->size() - 1) ; execute (check_stable(data))->display() ; for line : data do ( execute (line->first())->display()); operation partition(A : OclAny, p : OclAny, r : OclAny) : OclAny pre: true post: true activity: var q : OclAny := p ; for i : Integer.subrange(p, r-1) do ( if (A[i+1][1+1]->compareTo(A[r+1][1+1])) <= 0 then ( var A[q+1] : OclAny := null; var A[i+1] : OclAny := null; Sequence{A[q+1],A[i+1]} := Sequence{A[i+1],A[q+1]} ; q := q + 1 ) else skip) ; var A[q+1] : OclAny := null; var A[r+1] : OclAny := null; Sequence{A[q+1],A[r+1]} := Sequence{A[r+1],A[q+1]} ; return q; operation quicksort(A : OclAny, left : OclAny, right : OclAny) pre: true post: true activity: if (left->compareTo(right)) < 0 then ( q := partition(A, left, right) ; quicksort(A, left, q - 1) ; quicksort(A, q + 1, right) ) else skip; operation check_stable(A : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(1, (A)->size()-1) do ( if A[i - 1+1][1+1] = A[i+1][1+1] then ( if (A[i - 1+1][2+1]->compareTo(A[i+1][2+1])) > 0 then ( return "Not stable" ) else skip ) else skip) ; return "Stable"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y,h=int(input()),int(input()),int(input()) print(int((x+y)*h/2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; var h : OclAny := null; Sequence{x,y,h} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),("" + (((OclFile["System.in"]).readLine())))->toInteger(),("" + (((OclFile["System.in"]).readLine())))->toInteger()} ; execute (("" + (((x + y) * h / 2)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[int(input())for _ in range(3)] print((a[0]+a[1])*a[2]//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; execute ((a->first() + a[1+1]) * a[2+1] div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- top,bottom,height=[int(input())for i in range(3)] result=(top+bottom)*height//2 print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var top : OclAny := null; var bottom : OclAny := null; var height : OclAny := null; Sequence{top,bottom,height} := Integer.subrange(0, 3-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var result : int := (top + bottom) * height div 2 ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print((int(input())+int(input()))*int(input())//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger() + ("" + (((OclFile["System.in"]).readLine())))->toInteger()) * ("" + (((OclFile["System.in"]).readLine())))->toInteger() div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=list(map(int,input().split())) print(K*((K-1)**(N-1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (K * (((K - 1))->pow((N - 1))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def rs(): return sys.stdin.readline().rstrip() def ri(): return int(rs()) def rs_(): return[_ for _ in rs().split()] def ri_(): return[int(_)for _ in rs().split()] n,k=ri_() print(k*((k-1)**(n-1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ri_() ; execute (k * (((k - 1))->pow((n - 1))))->display(); operation rs() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation ri() : OclAny pre: true post: true activity: return ("" + ((rs())))->toInteger(); operation rs_() : OclAny pre: true post: true activity: return rs().split()->select(_anon | true)->collect(_anon | (_anon)); operation ri_() : OclAny pre: true post: true activity: return rs().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,input().split()) ans=1 for i in range(N): if i==0 : ans*=K else : ans*=(K-1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 1 ; for i : Integer.subrange(0, N-1) do ( if i = 0 then ( ans := ans * K ) else ( ans := ans * (K - 1) )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,input().split()) r=K for i in range(1,N): r*=K-1 print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var r : OclAny := K ; for i : Integer.subrange(1, N-1) do ( r := r * K - 1) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def longestSubseq(s): n=len(s) pre_count_0=[0 for i in range(n+2)] pre_count_1=[0 for i in range(n+1)] post_count_0=[0 for i in range(n+2)] pre_count_0[0]=0 post_count_0[n+1]=0 pre_count_1[0]=0 for j in range(1,n+1): pre_count_0[j]=pre_count_0[j-1] pre_count_1[j]=pre_count_1[j-1] post_count_0[n-j+1]=post_count_0[n-j+2] if(s[j-1]=='0'): pre_count_0[j]+=1 else : pre_count_1[j]+=1 if(s[n-j]=='0'): post_count_0[n-j+1]+=1 if(pre_count_0[n]==n or pre_count_0[n]==0): return n ans=0 for i in range(1,n+1): for j in range(i,n+1,1): ans=max(pre_count_0[i-1]+pre_count_1[j]-pre_count_1[i-1]+post_count_0[j+1],ans) return ans if __name__=='__main__' : s="000011100000" print(longestSubseq(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( s := "000011100000" ; execute (longestSubseq(s))->display() ) else skip; operation longestSubseq(s : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; var pre_count_0 : Sequence := Integer.subrange(0, n + 2-1)->select(i | true)->collect(i | (0)) ; var pre_count var n : int := (s)->size() : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; var post_count_0 : Sequence := Integer.subrange(0, n + 2-1)->select(i | true)->collect(i | (0)) ; pre_count_0->first() := 0 ; post_count_0[n + 1+1] := 0 ; pre_count var n : int := (s)->size()->first() := 0 ; for j : Integer.subrange(1, n + 1-1) do ( pre_count_0[j+1] := pre_count_0[j - 1+1] ; pre_count pre_count_0[j+1] := pre_count_0[j - 1+1][j+1] := pre_count pre_count_0[j+1] := pre_count_0[j - 1+1][j - 1+1] ; post_count_0[n - j + 1+1] := post_count_0[n - j + 2+1] ; if (s[j - 1+1] = '0') then ( pre_count_0[j+1] := pre_count_0[j+1] + 1 ) else ( pre_count pre_count_0[j+1] := pre_count_0[j - 1+1][j+1] := pre_count pre_count_0[j+1] := pre_count_0[j - 1+1][j+1] + 1 ) ; if (s[n - j+1] = '0') then ( post_count_0[n - j + 1+1] := post_count_0[n - j + 1+1] + 1 ) else skip) ; if (pre_count_0[n+1] = n or pre_count_0[n+1] = 0) then ( return n ) else skip ; var ans : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(i, n + 1-1)->select( $x | ($x - i) mod 1 = 0 ) do ( ans := Set{pre_count_0[i - 1+1] + pre_count(pre_count_0[i - 1+1] + pre_count(pre_count_0[i - 1+1] + pre_count var n : int := (s)->size()[j+1] - pre_count var n : int := (s)->size()[i - 1+1] + post_count_0[j + 1+1], ans)[j+1] - pre_count(pre_count_0[i - 1+1] + pre_count var n : int := (s)->size()[j+1] - pre_count var n : int := (s)->size()[i - 1+1] + post_count_0[j + 1+1], ans)[i - 1+1] + post_count_0[j + 1+1], ans)[j+1] - pre_count(pre_count_0[i - 1+1] + pre_count(pre_count_0[i - 1+1] + pre_count var n : int := (s)->size()[j+1] - pre_count var n : int := (s)->size()[i - 1+1] + post_count_0[j + 1+1], ans)[j+1] - pre_count(pre_count_0[i - 1+1] + pre_count var n : int := (s)->size()[j+1] - pre_count var n : int := (s)->size()[i - 1+1] + post_count_0[j + 1+1], ans)[i - 1+1] + post_count_0[j + 1+1], ans)[i - 1+1] + post_count_0[j + 1+1], ans}->max())) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import Counter n,k=map(int,input().split()) print(k*((k-1)**(n-1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (k * (((k - 1))->pow((n - 1))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ispower(n): if(n<125): return(n==1 or n==5 or n==25) if(n % 125!=0): return 0 else : return ispower(n//125) def number(s,i,j): ans=0 for x in range(i,j): ans=ans*2+(ord(s[x])-ord('0')) return ans def minCuts(s,n): dp=[n+1 for i in range(n+1)] dp[0]=0 ; for i in range(1,n+1): if(s[i-1]=='0'): continue for j in range(i): if(s[j]=='0'): continue num=number(s,j,i) if(not ispower(num)): continue dp[i]=min(dp[i],dp[j]+1) if dp[n]size() ; execute (minCuts(s, n))->display() ) else skip; operation ispower(n : OclAny) : OclAny pre: true post: true activity: if (n < 125) then ( return (n = 1 or n = 5 or n = 25) ) else skip ; if (n mod 125 /= 0) then ( return 0 ) else ( return ispower(n div 125) ); operation number(s : OclAny, i : OclAny, j : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for x : Integer.subrange(i, j-1) do ( ans := ans * 2 + ((s[x+1])->char2byte() - ('0')->char2byte())) ; return ans; operation minCuts(s : OclAny, n : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (n + 1)) ; dp->first() := 0; ; for i : Integer.subrange(1, n + 1-1) do ( if (s[i - 1+1] = '0') then ( continue ) else skip ; for j : Integer.subrange(0, i-1) do ( if (s[j+1] = '0') then ( continue ) else skip ; var num : OclAny := number(s, j, i) ; if (not(ispower(num))) then ( continue ) else skip ; dp[i+1] := Set{dp[i+1], dp[j+1] + 1}->min())) ; if (dp[n+1]->compareTo(n + 1)) < 0 then ( return dp[n+1] ) else ( return -1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy def partition(A,p,r): x=int(A[r].split()[1]) i=p-1 tmp=0 for j in range(p,r): if int(A[j].split()[1])<=x : i=i+1 tmp=A[i] A[i]=A[j] A[j]=tmp tmp=A[i+1] A[i+1]=A[r] A[r]=tmp return i+1 def quickSort(A,p,r): if p0 and aft<0)or(bef<0 and aft>0): return 'Not stable' return 'Stable' if __name__=="__main__" : n=int(input()) A=[] for _ in range(n): A.append(input()) bef_A=copy.deepcopy(A) aft_A=quickSort(A,0,n-1) print(checkStable(bef_A,aft_A)) for data in aft_A : print(data) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; A := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : A)) ; var bef_A : OclAny := copy.deepcopy(A) ; var aft_A : OclAny := quickSort(A, 0, n - 1) ; execute (checkStable(bef_A, aft_A))->display() ; for data : aft_A do ( execute (data)->display()) ) else skip; operation partition(A : OclAny, p : OclAny, r : OclAny) : OclAny pre: true post: true activity: var x : int := ("" + ((A[r+1].split()[1+1])))->toInteger() ; var i : double := p - 1 ; var tmp : int := 0 ; for j : Integer.subrange(p, r-1) do ( if (("" + ((A[j+1].split()[1+1])))->toInteger()->compareTo(x)) <= 0 then ( i := i + 1 ; tmp := A[i+1] ; A[i+1] := A[j+1] ; A[j+1] := tmp ) else skip) ; tmp := A[i + 1+1] ; A[i + 1+1] := A[r+1] ; A[r+1] := tmp ; return i + 1; operation quickSort(A : OclAny, p : OclAny, r : OclAny) : OclAny pre: true post: true activity: if (p->compareTo(r)) < 0 then ( var q : OclAny := partition(A, p, r) ; quickSort(A, p, q - 1) ; quickSort(A, q + 1, r) ) else skip ; return (A); operation checkStable(before_list : OclAny, sorted_list : OclAny) : OclAny pre: true post: true activity: for val : sorted_list do ( var same_list : Sequence := sorted_list->select(i | (("" + ((val.split()[1+1])))->toInteger() = ("" + ((i.split()[1+1])))->toInteger()) & val /= i)->collect(i | (i)) ; if (same_list)->size() = 0 then ( continue ) else skip ; for data : same_list do ( var bef : double := before_list->indexOf(val) - 1 - before_list->indexOf(data) - 1 ; var aft : double := sorted_list->indexOf(val) - 1 - sorted_list->indexOf(data) - 1 ; if (bef > 0 & aft < 0) or (bef < 0 & aft > 0) then ( return 'Not stable' ) else skip)) ; return 'Stable'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(b==0): return a return(gcd(b,a % b)) def findSmallest(a,b): lcm=(a*b)/gcd(a,b) print("x=",lcm/a,"\ny=",lcm/b) a=25 b=35 findSmallest(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 25 ; b := 35 ; findSmallest(a, b); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (b = 0) then ( return a ) else skip ; return (gcd(b, a mod b)); operation findSmallest(a : OclAny, b : OclAny) pre: true post: true activity: var lcm : double := (a * b) / gcd(a, b) ; execute ("x=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() uzun1=len(a) for i in range(0,uzun1): if(a[i]=="r"): print(i+1) for i in range(0,uzun1): if(a[uzun1-i-1]=="l"): print(uzun1-i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var uzun1 : int := (a)->size() ; for i : Integer.subrange(0, uzun1-1) do ( if (a[i+1] = "r") then ( execute (i + 1)->display() ) else skip) ; for i : Integer.subrange(0, uzun1-1) do ( if (a[uzun1 - i - 1+1] = "l") then ( execute (uzun1 - i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import sys import math from collections import deque,defaultdict import bisect import heapq input=sys.stdin.readline def multiple(): a=map(int,input().split()) return a def array(): a=input().split() return a def intarray(): a=list(map(int,input().split())) return a def intinput(): n=int(input()) return n def strinput(): s=input().strip() return s def isPrime(n): val=int(math.sqrt(n))+1 for i in range(2,val): if n % i==0 : return False return True def solution(): MOD=1000000007 s=strinput() a=[1] b=[] count=2 for x in range(len(s)-1): i=s[x] if i=='l' : a.append(count) else : val=a[-1] a.pop() a.append(count) b.append(val) count+=1 for i in b : print(i) for i in reversed(range(len(a))): print(a[i]) return t=1 for _ in range(t): solution() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); operation multiple() : OclAny pre: true post: true activity: var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; return a; operation array() : OclAny pre: true post: true activity: a := input().split() ; return a; operation intarray() : OclAny pre: true post: true activity: a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; return a; operation intinput() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; return n; operation strinput() : OclAny pre: true post: true activity: var s : OclAny := input()->trim() ; return s; operation isPrime(n : OclAny) : OclAny pre: true post: true activity: var val : int := ("" + (((n)->sqrt())))->toInteger() + 1 ; for i : Integer.subrange(2, val-1) do ( if n mod i = 0 then ( return false ) else skip) ; return true; operation solution() pre: true post: true activity: var MOD : int := 1000000007 ; s := strinput() ; a := Sequence{ 1 } ; var b : Sequence := Sequence{} ; var count : int := 2 ; for x : Integer.subrange(0, (s)->size() - 1-1) do ( var i : OclAny := s[x+1] ; if i = 'l' then ( execute ((count) : a) ) else ( val := a->last() ; a := a->front() ; execute ((count) : a) ; execute ((val) : b) ) ; count := count + 1) ; for i : b do ( execute (i)->display()) ; for i : (Integer.subrange(0, (a)->size()-1))->reverse() do ( execute (a[i+1])->display()) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline s=input()[:-1] l=[] r=[] for i in range(len(s)): if s[i]=='l' : r+=[i+1] else : l+=[i+1] x=l+r[: :-1] for i in x : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var s : OclAny := input()->front() ; var l : Sequence := Sequence{} ; var r : Sequence := Sequence{} ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = 'l' then ( r := r + Sequence{ i + 1 } ) else ( l := l + Sequence{ i + 1 } )) ; var x : Sequence := l->union(r(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ; for i : x do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() l=list(s) ans=[] for i in range(len(l)): if l[i]=='r' : print(i+1) for i in range(len(l)-1,-1,-1): if l[i]=='l' : print(i+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var l : Sequence := (s)->characters() ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, (l)->size()-1) do ( if l[i+1] = 'r' then ( execute (i + 1)->display() ) else skip) ; for i : Integer.subrange(-1 + 1, (l)->size() - 1)->reverse() do ( if l[i+1] = 'l' then ( execute (i + 1)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def games(c,a): k=0 for i in c : if a==[]: return k if i<=a[0]: a.pop(0) k+=1 return k nm=input() a=[int(i)for i in input().split()] b=[int(i)for i in input().split()] print(games(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var nm : String := (OclFile["System.in"]).readLine() ; a := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var b : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute (games(a, b))->display(); operation games(c : OclAny, a : OclAny) : OclAny pre: true post: true activity: var k : int := 0 ; for i : c do ( if a = Sequence{} then ( return k ) else skip ; if (i->compareTo(a->first())) <= 0 then ( a := a->excludingAt(0+1) ; k := k + 1 ) else skip) ; return k; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=lambda : map(int,input().split()) n,m=i() a,b=i(),[*i()] k=0 for x in a : k=k+(x<=b[k]) if k==m : break print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := i->apply() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{i->apply(),i->apply()} ; var k : int := 0 ; for x : a do ( k := k + ((x->compareTo(b[k+1])) <= 0) ; if k = m then ( break ) else skip) ; execute (k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sieveOfEratosthenes(N,s): prime=[False]*(N+1) for i in range(2,N+1,2): s[i]=2 for i in range(3,N+1,2): if(prime[i]==False): s[i]=i for j in range(i,int(N/i)+1,2): if(prime[i*j]==False): prime[i*j]=True s[i*j]=i def generatePrimeFactors(N): s=[0]*(N+1) sieveOfEratosthenes(N,s) print("Factor Power") curr=s[N] cnt=1 while(N>1): N//=s[N] if(curr==s[N]): cnt+=1 continue print(str(curr)+"\t"+str(cnt)) curr=s[N] cnt=1 N=360 generatePrimeFactors(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; N := 360 ; generatePrimeFactors(N); operation sieveOfEratosthenes(N : OclAny, s : OclAny) pre: true post: true activity: var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (N + 1)) ; for i : Integer.subrange(2, N + 1-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( s[i+1] := 2) ; for i : Integer.subrange(3, N + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if (prime[i+1] = false) then ( s[i+1] := i ; for j : Integer.subrange(i, ("" + ((N / i)))->toInteger() + 1-1)->select( $x | ($x - i) mod 2 = 0 ) do ( if (prime[i * j+1] = false) then ( prime[i * j+1] := true ; s[i * j+1] := i ) else skip) ) else skip); operation generatePrimeFactors(N : OclAny) pre: true post: true activity: s := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; sieveOfEratosthenes(N, s) ; execute ("Factor Power")->display() ; var curr : OclAny := s[N+1] ; var cnt : int := 1 ; while (N > 1) do ( N := N div s[N+1] ; if (curr = s[N+1]) then ( cnt := cnt + 1 ; continue ) else skip ; execute (("" + ((curr))) + "\t" + ("" + ((cnt))))->display() ; curr := s[N+1] ; cnt := 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r=lambda : map(int,input().split()) r() c,a=r(),[*r()]+[0] i=0 for x in c : i+=x<=a[i] print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; r() ; var c : OclAny := null; var a : OclAny := null; Sequence{c,a} := Sequence{r->apply(),r->apply()->union(Sequence{ 0 })} ; var i : int := 0 ; for x : c do ( i := i + (x->compareTo(a[i+1])) <= 0) ; execute (i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) R() c,a=R(),[*R()]+[0] i=0 for x in c : i+=x<=a[i] print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; R() ; var c : OclAny := null; var a : OclAny := null; Sequence{c,a} := Sequence{R->apply(),R->apply()->union(Sequence{ 0 })} ; var i : int := 0 ; for x : c do ( i := i + (x->compareTo(a[i+1])) <= 0) ; execute (i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import os import random import re import sys from math import gcd from math import sqrt n,m=list(map(int,input().split())) c=list(map(int,input().split())) a=list(map(int,input().split())) ans=0 for i in range(n): if(ans=c[i]): ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ((ans->compareTo(m)) < 0) & ((a[ans+1]->compareTo(c[i+1])) >= 0) then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Quicksort : def quicksort(self,a,p,r): if pexists( _x | result = _x ); operation quicksort(a : OclAny,p : OclAny,r : OclAny) : OclAny pre: true post: true activity: if (p->compareTo(r)) < 0 then ( var q : OclAny := self.partion(a, p, r) ; self.quicksort(a, p, q - 1) ; self.quicksort(a, q + 1, r) ) else skip ; return (a); operation partion(a : OclAny,p : OclAny,r : OclAny) : OclAny pre: true post: true activity: var x : OclAny := a[r+1][1+1] ; var i : double := p - 1 ; for j : Integer.subrange(p, r-1) do ( if (a[j+1][1+1]->compareTo(x)) <= 0 then ( i := i + 1 ; var a[i+1] : OclAny := null; var a[j+1] : OclAny := null; Sequence{a[i+1],a[j+1]} := Sequence{a[j+1],a[i+1]} ) else skip) ; var a[i + 1+1] : OclAny := null; var a[r+1] : OclAny := null; Sequence{a[i + 1+1],a[r+1]} := Sequence{a[r+1],a[i + 1+1]} ; return (i + 1); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( n := ("" + ((input().rstrip())))->toInteger() ; var cards : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var tmp : OclAny := input().rstrip().split(" ") ; tmp[1+1] := ("" + ((tmp[1+1])))->toInteger() ; execute ((tmp) : cards)) ; a := cards ; var b : Sequence := cards ; x := (Quicksort.newQuicksort()).initialise() ; a := x.quicksort(a, 0, n - 1) ; b := b->sortedBy($x | (lambda i : OclAny in (i[1+1]))->apply($x)) ; if a = b then ( execute ("Stable")->display() ) else ( execute ("Not stable")->display() ) ; for i : a do ( i[1+1] := ("" + ((i[1+1]))) ; execute (StringLib.sumStringsWithSeparator((i), " "))->display()) ) else skip; operation bubbleSort(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var flag : int := 1 ; while flag = 1 do ( flag := 0 ; for j : Integer.subrange(0 + 1, n - 1)->reverse() do ( if (a[j+1][1+1]->compareTo(a[j - 1+1][1+1])) < 0 then ( var a[j+1] : OclAny := null; var a[j - 1+1] : OclAny := null; Sequence{a[j+1],a[j - 1+1]} := Sequence{a[j - 1+1],a[j+1]} ; flag := 1 ) else skip)) ; return (a); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def productAtKthLevel(tree,k): level=-1 product=1 n=len(tree) for i in range(0,n): if(tree[i]=='('): level+=1 elif(tree[i]==')'): level-=1 else : if(level==k): product*=(int(tree[i])-int('0')) return product tree="(0(5(6()())(4()(9()())))(7(1()())(3()())))" k=2 print(productAtKthLevel(tree,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; tree := "(0(5(6()())(4()(9()())))(7(1()())(3()())))" ; k := 2 ; execute (productAtKthLevel(tree, k))->display(); operation productAtKthLevel(tree : OclAny, k : OclAny) : OclAny pre: true post: true activity: var level : int := -1 ; var product : int := 1 ; var n : int := (tree)->size() ; for i : Integer.subrange(0, n-1) do ( if (tree[i+1] = '(') then ( level := level + 1 ) else (if (tree[i+1] = ')') then ( level := level - 1 ) else ( if (level = k) then ( product := product * (("" + ((tree[i+1])))->toInteger() - ("" + (('0')))->toInteger()) ) else skip ) ) ) ; return product; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def factorial(n): if(n==0): return 1 ; return n*factorial(n-1); def countNum(n): if(n>10): return 0 ; return(9*factorial(9)//factorial(10-n)); if __name__=="__main__" : n=3 ; print(countNum(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 3; ; execute (countNum(n))->display(); ) else skip; operation factorial(n : OclAny) pre: true post: true activity: if (n = 0) then ( return 1; ) else skip ; return n * factorial(n - 1);; operation countNum(n : OclAny) pre: true post: true activity: if (n > 10) then ( return 0; ) else skip ; return (9 * factorial(9) div factorial(10 - n));; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections n=int(input()) array=[int(x)for x in input().split()] _dict=collections.Counter(array) res=0 for i,j in _dict.items(): if i!=j : if i>j : res+=j else : res+=abs(i-j) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var array : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var _dict : OclAny := .Counter(array) ; var res : int := 0 ; for _tuple : _dict->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if i /= j then ( if (i->compareTo(j)) > 0 then ( res := res + j ) else ( res := res + (i - j)->abs() ) ) else skip) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def c_good_sequence(N,A): from collections import Counter count=Counter(A) ans=0 for k,v in count.items(): if k==1 : if v==1 : continue else : ans+=v-k elif k!=v : ans+=v % k return ans N=int(input()) A=[int(_)for _ in input().split()] print(c_good_sequence(N,A)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; A := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; execute (c_good_sequence(N, A))->display(); operation c_good_sequence(N : OclAny, A : OclAny) : OclAny pre: true post: true activity: skip ; var count : OclAny := Counter(A) ; var ans : int := 0 ; for _tuple : count->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if k = 1 then ( if v = 1 then ( continue ) else ( ans := ans + v - k ) ) else (if k /= v then ( ans := ans + v mod k ) else skip)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) dict={} for i in range(n): if dict.get(a[i])==None : dict[a[i]]=1 else : dict[a[i]]+=1 cnt=0 for keys,vals in dict.items(): if keys>vals : cnt+=vals elif keystoInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var OclType["Map"] : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( if (trailer . (name get) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))) = null then ( (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ]) := 1 ) else ( (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ]) := (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ]) + 1 )) ; var cnt : int := 0 ; for _tuple : (trailer . (name items) (arguments ( ))) do (var _indx : int := 1; var keys : OclAny := _tuple->at(_indx); _indx := _indx + 1; var vals : OclAny := _tuple->at(_indx); if (keys->compareTo(vals)) > 0 then ( cnt := cnt + vals ) else (if (keys->compareTo(vals)) < 0 then ( cnt := cnt + vals - keys ) else skip)) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=[int(i)for i in input().split()] from collections import Counter ans=0 for k,v in Counter(A).items(): if v!=k and k>v : ans+=v elif v!=k and ktoInteger() ; var A : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; skip ; var ans : int := 0 ; for _tuple : Counter(A)->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if v /= k & (k->compareTo(v)) > 0 then ( ans := ans + v ) else (if v /= k & (k->compareTo(v)) < 0 then ( ans := ans + v - k ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def longestSubarray(a,n): hash=[[0 for i in range(10)]for j in range(n)] for i in range(n): num=a[i] while(num): hash[i][num % 10]=1 num=int(num/10) longest=-sys.maxsize-1 count=0 for i in range(n-1): for j in range(10): if(hash[i][j]and hash[i+1][j]): count+=1 break if(j==10): longest=max(longest,count+1) count=0 longest=max(longest,count+1) return longest if __name__=='__main__' : a=[11,22,33,44,54,56,63] n=len(a) print(longestSubarray(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( a := Sequence{11}->union(Sequence{22}->union(Sequence{33}->union(Sequence{44}->union(Sequence{54}->union(Sequence{56}->union(Sequence{ 63 })))))) ; n := (a)->size() ; execute (longestSubarray(a, n))->display() ) else skip; operation longestSubarray(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var hash : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (Integer.subrange(0, 10-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, n-1) do ( var num : OclAny := a[i+1] ; while (num) do ( hash[i+1][num mod 10+1] := 1 ; num := ("" + ((num / 10)))->toInteger())) ; var longest : double := -(trailer . (name maxsize)) - 1 ; var count : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(0, 10-1) do ( if (hash[i+1][j+1] & hash[i + 1+1][j+1]) then ( count := count + 1 ; break ) else skip) ; if (j = 10) then ( longest := Set{longest, count + 1}->max() ; count := 0 ) else skip) ; longest := Set{longest, count + 1}->max() ; return longest; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections dic=collections.defaultdict(int) n=int(input()) a=[int(i)for i in input().split()] for i in range(n): dic[a[i]]+=1 ans=0 for key in dic.keys(): if dic[key]>=key : ans+=(dic[key]-key) else : ans+=dic[key] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var dic : OclAny := .defaultdict(OclType["int"]) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; for i : Integer.subrange(0, n-1) do ( dic[a[i+1]+1] := dic[a[i+1]+1] + 1) ; var ans : int := 0 ; for key : dic.keys() do ( if (dic[key+1]->compareTo(key)) >= 0 then ( ans := ans + (dic[key+1] - key) ) else ( ans := ans + dic[key+1] )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for _ in range(n): s=list(input()) mins="".join(sorted(s,reverse=False)) maxs="".join(sorted(s,reverse=True)) print(int(maxs)-int(mins)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var mins : String := StringLib.sumStringsWithSeparator((s->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name False))))))))), "") ; var maxs : String := StringLib.sumStringsWithSeparator((s->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True))))))))), "") ; execute (("" + ((maxs)))->toInteger() - ("" + ((mins)))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline write=sys.stdout.write def solve(): N=readline().strip() res=int("".join(sorted(N,reverse=1)))-int("".join(sorted(N))) write("%d\n" % res) T=int(readline()) for i in range(T): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var write : OclAny := (OclFile["System.out"]).write ; skip ; var T : int := ("" + ((readline())))->toInteger() ; for i : Integer.subrange(0, T-1) do ( solve()); operation solve() pre: true post: true activity: var N : OclAny := readline()->trim() ; var res : double := ("" + ((StringLib.sumStringsWithSeparator((N->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))), ""))))->toInteger() - ("" + ((StringLib.sumStringsWithSeparator((N->sort()), ""))))->toInteger() ; write(StringLib.format("%d\n",res)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys f=sys.stdin n=int(f.readline()) for i in range(n): line=f.readline().strip() print(int(''.join(sorted(line)[: :-1]))-int(''.join(sorted(line)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var f : OclFile := OclFile["System.in"] ; var n : int := ("" + ((f.readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var line : OclAny := f.readLine()->trim() ; execute (("" + ((StringLib.sumStringsWithSeparator((sorted(line)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))), ''))))->toInteger() - ("" + ((StringLib.sumStringsWithSeparator((line->sort()), ''))))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) int1=lambda x : int(x)-1 p2D=lambda x : print(*x,sep="\n") def QuickSort(aa,p,r): def Partition(aa,p,r): x=aa[r][0] i=p-1 for j in range(p,r): if aa[j][0]<=x : i+=1 aa[i],aa[j]=aa[j],aa[i] aa[i+1],aa[r]=aa[r],aa[i+1] return i+1 if pctoi[c1]: stable=False break print("Stable")if stable else print("Not stable") for c in cc : print(c[1],c[0]) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; var p2D : Function := lambda x : OclAny in (((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ; skip ; skip ; main(); operation QuickSort(aa : OclAny, p : OclAny, r : OclAny) pre: true post: true activity: skip ; if (p->compareTo(r)) < 0 then ( var q : OclAny := Partition(aa, p, r) ; QuickSort(aa, p, q - 1) ; QuickSort(aa, q + 1, r) ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cc : Sequence := Sequence{} ; var ctoi : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var m : OclAny := null; var a : OclAny := null; Sequence{m,a} := input().split() ; var c : OclAny := Sequence{("" + ((a)))->toInteger(), m} ; ctoi[c+1] := i ; execute ((c) : cc)) ; QuickSort(cc, 0, n - 1) ; var stable : boolean := true ; for _tuple : Integer.subrange(1, cc->size())->collect( _indx | Sequence{cc->at(_indx), cc->tail()->at(_indx)} ) do (var _indx : int := 1; var c0 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c1 : OclAny := _tuple->at(_indx); if c0->first() = c1->first() & (ctoi[c0+1]->compareTo(ctoi[c1+1])) > 0 then ( stable := false ; break ) else skip) ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Stable"))))))) )))))) if (logical_test (comparison (expr (atom (name stable))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Not stable"))))))) )))))))) ; for c : cc do ( execute (c[1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): num=list(map(int,list(input()))) min_num=''.join(list(map(str,sorted(num)))) max_num=''.join(list(map(str,sorted(num,reverse=True)))) print(int(max_num)-int(min_num)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var num : Sequence := ((((OclFile["System.in"]).readLine())->characters())->collect( _x | (OclType["int"])->apply(_x) )) ; var min_num : String := StringLib.sumStringsWithSeparator((((num->sort())->collect( _x | (OclType["String"])->apply(_x) ))), '') ; var max_num : String := StringLib.sumStringsWithSeparator((((num->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))))->collect( _x | (OclType["String"])->apply(_x) ))), '') ; execute (("" + ((max_num)))->toInteger() - ("" + ((min_num)))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): Max_num="" Min_num="" n=str(input()) Lis=list(map(str,n)) Min_num_lis=sorted(Lis) Max_num_lis=sorted(Lis)[: :-1] for j in range(8): Max_num=Max_num+Max_num_lis[j] Min_num=Min_num+Min_num_lis[j] sa=int(Max_num)-int(Min_num) print(sa) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var Max_num : String := "" ; var Min_num : String := "" ; n := ("" + (((OclFile["System.in"]).readLine()))) ; var Lis : Sequence := ((n)->collect( _x | (OclType["String"])->apply(_x) )) ; var Min_num_lis : Sequence := Lis->sort() ; var Max_num_lis : OclAny := sorted(Lis)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; for j : Integer.subrange(0, 8-1) do ( Max_num := Max_num + Max_num_lis[j+1] ; Min_num := Min_num + Min_num_lis[j+1]) ; var sa : double := ("" + ((Max_num)))->toInteger() - ("" + ((Min_num)))->toInteger() ; execute (sa)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) num=list(map(int,input().split())) oddsum,evensum,preeven,preodd=0,0,0,0 ans=0 for i in range(n): if(i % 2==1): evensum+=num[i] else : oddsum+=num[i] for i in range(n): if(i % 2==1): evensum-=num[i] else : oddsum-=num[i] if(oddsum+preeven==evensum+preodd): ans+=1 if(i % 2==1): preeven+=num[i] else : preodd+=num[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var num : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var oddsum : OclAny := null; var evensum : OclAny := null; var preeven : OclAny := null; var preodd : OclAny := null; Sequence{oddsum,evensum,preeven,preodd} := Sequence{0,0,0,0} ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (i mod 2 = 1) then ( evensum := evensum + num[i+1] ) else ( oddsum := oddsum + num[i+1] )) ; for i : Integer.subrange(0, n-1) do ( if (i mod 2 = 1) then ( evensum := evensum - num[i+1] ) else ( oddsum := oddsum - num[i+1] ) ; if (oddsum + preeven = evensum + preodd) then ( ans := ans + 1 ) else skip ; if (i mod 2 = 1) then ( preeven := preeven + num[i+1] ) else ( preodd := preodd + num[i+1] )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) s=sum(l) esum,osum=0,0 for i in range(len(l)): if(i % 2==0): esum+=l[i] else : osum+=l[i] ans=0 a,b=0,0 for i in range(len(l)): if(i % 2==0): esum=s-osum-l[i] else : osum=s-esum-l[i] if(esum==osum): ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : OclAny := (l)->sum() ; var esum : OclAny := null; var osum : OclAny := null; Sequence{esum,osum} := Sequence{0,0} ; for i : Integer.subrange(0, (l)->size()-1) do ( if (i mod 2 = 0) then ( esum := esum + l[i+1] ) else ( osum := osum + l[i+1] )) ; var ans : int := 0 ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{0,0} ; for i : Integer.subrange(0, (l)->size()-1) do ( if (i mod 2 = 0) then ( var esum : double := s - osum - l[i+1] ) else ( var osum : double := s - esum - l[i+1] ) ; if (esum = osum) then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) asd=list(map(int,input().split())) k=0 sum1,sum2=0,0 for i in range(n): if(i+2)% 2==0 : sum1=sum1+asd[i] else : sum2=sum2+asd[i] a=0 for i in range(n): if(i+2)% 2==0 : sum1=sum1-asd[i] else : sum2=sum2-asd[i] if(i+1)% 2==0 : sum2=sum2+a else : sum1=sum1+a if sum1==sum2 : k+=1 a=asd[i] print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var asd : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k : int := 0 ; var sum1 : OclAny := null; var sum2 : OclAny := null; Sequence{sum1,sum2} := Sequence{0,0} ; for i : Integer.subrange(0, n-1) do ( if (i + 2) mod 2 = 0 then ( var sum1 : OclAny := sum1 + asd[i+1] ) else ( var sum2 : OclAny := sum2 + asd[i+1] )) ; var a : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (i + 2) mod 2 = 0 then ( sum1 := sum1 - asd[i+1] ) else ( sum2 := sum2 - asd[i+1] ) ; if (i + 1) mod 2 = 0 then ( sum2 := sum2 + a ) else ( sum1 := sum1 + a ) ; if sum1 = sum2 then ( k := k + 1 ) else skip ; a := asd[i+1]) ; execute (k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): a,b,c=map(int,input().split()) print((a+b+c)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a + b + c) div 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) w=list(map(int,input().split())) s=sum(w) b=sum(w[i]for i in range(n)if i % 2) a=s-b c=0 for i in range(n): if i % 2==0 : if i!=0 : a+=w[i-1] a-=w[i] else : b-=w[i] b+=w[i-1] if a==b : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : OclAny := (w)->sum() ; var b : OclAny := ((argument (test (logical_test (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (expr (atom (name i))) % (expr (atom (number (integer 2))))))))))))->sum() ; var a : double := s - b ; var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( if i mod 2 = 0 then ( if i /= 0 then ( a := a + w[i - 1+1] ) else skip ; a := a - w[i+1] ) else ( b := b - w[i+1] ; b := b + w[i - 1+1] ) ; if a = b then ( c := c + 1 ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def getPerfectSquares(n): perfectSquares=[] current=1 i=1 while(current<=n): perfectSquares.append(current) i+=1 current=i**2 return perfectSquares def countTriplets(n): perfectSquares=getPerfectSquares(n**2) count=0 for a in range(1,n+1): aSquare=a**2 for i in range(len(perfectSquares)): cSquare=perfectSquares[i] bSquare=abs(cSquare-aSquare) b=math.sqrt(bSquare) b=int(b) c=math.sqrt(cSquare) c=int(c) if(c=a)and(b<=c)and(aSquare+bSquare==cSquare)): count+=1 return count if __name__=="__main__" : n=10 print(countTriplets(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( n := 10 ; execute (countTriplets(n))->display() ) else skip; operation getPerfectSquares(n : OclAny) : OclAny pre: true post: true activity: var perfectSquares : Sequence := Sequence{} ; var current : int := 1 ; var i : int := 1 ; while ((current->compareTo(n)) <= 0) do ( execute ((current) : perfectSquares) ; i := i + 1 ; current := (i)->pow(2)) ; return perfectSquares; operation countTriplets(n : OclAny) : OclAny pre: true post: true activity: perfectSquares := getPerfectSquares((n)->pow(2)) ; var count : int := 0 ; for a : Integer.subrange(1, n + 1-1) do ( var aSquare : double := (a)->pow(2) ; for i : Integer.subrange(0, (perfectSquares)->size()-1) do ( var cSquare : OclAny := perfectSquares[i+1] ; var bSquare : double := (cSquare - aSquare)->abs() ; var b : double := (bSquare)->sqrt() ; b := ("" + ((b)))->toInteger() ; var c : double := (cSquare)->sqrt() ; c := ("" + ((c)))->toInteger() ; if ((c->compareTo(a)) < 0 or ((perfectSquares)->excludes(bSquare))) then ( continue ) else skip ; if (((b->compareTo(a)) >= 0) & ((b->compareTo(c)) <= 0) & (aSquare + bSquare = cSquare)) then ( count := count + 1 ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(t,_t): h,m=[int(_t[i : i+2])-int(t[i : i+2])for i in[0,3]] return 60*h+m n,t=map(int,input().split()) prv=input().split() a=[] for _ in[0]*(n-1): now=input().split() d=f(prv[2],now[0]) if d>=t : a.append(now[1]+' '+str(d)) prv=now print(len(a)) for x in a : print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var prv : OclAny := input().split() ; var a : Sequence := Sequence{} ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, (n - 1)) do ( var now : OclAny := input().split() ; var d : String := f(prv[2+1], now->first()) ; if d >= t then ( execute ((now[1+1] + ' ' + ("" + ((d)))) : a) ) else skip ; prv := now) ; execute ((a)->size())->display() ; for x : a do ( execute (x)->display()); operation f(t : OclAny, _t : OclAny) : OclAny pre: true post: true activity: var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := Sequence{0}->union(Sequence{ 3 })->select(i | true)->collect(i | (("" + ((_t.subrange(i+1, i + 2))))->toInteger() - ("" + ((t.subrange(i+1, i + 2))))->toInteger())) ; return 60 * h + m; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(t,_t): h,m=[int(_t[i : i+2])-int(t[i : i+2])for i in[0,3]] return 60*h+m n,t=map(int,input().split()) prv=input().split() a=[] for _ in[0]*(n-1): now=input().split() d=f(prv[2],now[0]) if d>=t : a+=[[now[1],d]] prv=now print(len(a)) for x in a : print(*x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var prv : OclAny := input().split() ; var a : Sequence := Sequence{} ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, (n - 1)) do ( var now : OclAny := input().split() ; var d : String := f(prv[2+1], now->first()) ; if d >= t then ( a := a + Sequence{ Sequence{now[1+1]}->union(Sequence{ d }) } ) else skip ; prv := now) ; execute ((a)->size())->display() ; for x : a do ( execute ((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()); operation f(t : OclAny, _t : OclAny) : OclAny pre: true post: true activity: var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := Sequence{0}->union(Sequence{ 3 })->select(i | true)->collect(i | (("" + ((_t.subrange(i+1, i + 2))))->toInteger() - ("" + ((t.subrange(i+1, i + 2))))->toInteger())) ; return 60 * h + m; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,T=map(int,input().split()) a,b,s,name1=input().split() def func(s): a=s[: 2] b=s[3 :] return int(a)*60+int(b) s=func(s) l=[] for i in range(N-1): t,name1,s2,name2=input().split() t=func(t) s2=func(s2) if t-s>=T : l.append([name1,t-s]) s=s2 print(len(l)) for i,j in l : print(i,j) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var T : OclAny := null; Sequence{N,T} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; var s : OclAny := null; var name1 : OclAny := null; Sequence{a,b,s,name1} := input().split() ; skip ; s := func(s) ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, N - 1-1) do ( var t : OclAny := null; var name1 : OclAny := null; var s2 : OclAny := null; var name2 : OclAny := null; Sequence{t,name1,s2,name2} := input().split() ; var t : OclAny := func(t) ; var s2 : OclAny := func(s2) ; if (t - s->compareTo(T)) >= 0 then ( execute ((Sequence{name1}->union(Sequence{ t - s })) : l) ) else skip ; s := s2) ; execute ((l)->size())->display() ; for _tuple : l do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); execute (i)->display()); operation func(s : OclAny) : OclAny pre: true post: true activity: var a : OclAny := s.subrange(1,2) ; var b : OclAny := s.subrange(3+1) ; return ("" + ((a)))->toInteger() * 60 + ("" + ((b)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def make_card(i,card): suit,value=card.split() return(int(value),i,card) def partition_stable(a,p,r): x,i=a[r],p-1 for j in range(p,r): if a[j]<=x : i+=1 a[i],a[j]=a[j],a[i] i+=1 a[i],a[r]=a[r],a[i] return i def partition_not_stable(a,p,r): x,i=a[r][0],p-1 for j in range(p,r): if a[j][0]<=x : i+=1 a[i],a[j]=a[j],a[i] i+=1 a[i],a[r]=a[r],a[i] return i def quick_sort(a,p,r,func): if ptoInteger() ; a := ((argument (test (logical_test (comparison (expr (atom (name make_card)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))) ; var b : Sequence := a ; quick_sort(a, 0, n - 1, partition_not_stable) ; quick_sort(b, 0, n - 1, partition_stable) ; execute ((if a = b then 'S' else 'Not s' endif) + 'table')->display() ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name card)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))) (comp_for for (exprlist (expr (atom (name card)))) in (logical_test (comparison (expr (atom (name a)))))))), ' '))->display(); operation make_card(i : OclAny, card : OclAny) : OclAny pre: true post: true activity: var suit : OclAny := null; var value : OclAny := null; Sequence{suit,value} := card.split() ; return Sequence{("" + ((value)))->toInteger(), i, card}; operation partition_stable(a : OclAny, p : OclAny, r : OclAny) : OclAny pre: true post: true activity: var x : OclAny := null; Sequence{x,i} := Sequence{a[r+1],p - 1} ; for j : Integer.subrange(p, r-1) do ( if (a[j+1]->compareTo(x)) <= 0 then ( i := i + 1 ; var a[i+1] : OclAny := null; var a[j+1] : OclAny := null; Sequence{a[i+1],a[j+1]} := Sequence{a[j+1],a[i+1]} ) else skip) ; i := i + 1 ; var a[i+1] : OclAny := null; var a[r+1] : OclAny := null; Sequence{a[i+1],a[r+1]} := Sequence{a[r+1],a[i+1]} ; return i; operation partition_not_stable(a : OclAny, p : OclAny, r : OclAny) : OclAny pre: true post: true activity: var x : OclAny := null; Sequence{x,i} := Sequence{a[r+1]->first(),p - 1} ; for j : Integer.subrange(p, r-1) do ( if (a[j+1]->first()->compareTo(x)) <= 0 then ( i := i + 1 ; var a[i+1] : OclAny := null; var a[j+1] : OclAny := null; Sequence{a[i+1],a[j+1]} := Sequence{a[j+1],a[i+1]} ) else skip) ; i := i + 1 ; var a[i+1] : OclAny := null; var a[r+1] : OclAny := null; Sequence{a[i+1],a[r+1]} := Sequence{a[r+1],a[i+1]} ; return i; operation quick_sort(a : OclAny, p : OclAny, r : OclAny, func : OclAny) pre: true post: true activity: if (p->compareTo(r)) < 0 then ( var q : OclAny := func(a, p, r) ; quick_sort(a, p, q - 1, func) ; quick_sort(a, q + 1, r, func) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,t=map(int,input().split()) star=[list(map(str,input().split()))for i in range(n)] ans=[] for i in range(n-1): a=list(map(int,star[i][2].split(":"))) b=list(map(int,star[i+1][0].split(":"))) ai=a[0]*60+a[1] bi=b[0]*60+b[1] x=bi-ai if x>=t : ans.append((star[i][3],x)) print(len(ans)) for a,b in ans : print(a,b) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var star : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["String"])->apply(_x) )))) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( var a : Sequence := ((star[i+1][2+1].split(":"))->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((star[i + 1+1]->first().split(":"))->collect( _x | (OclType["int"])->apply(_x) )) ; var ai : double := a->first() * 60 + a[1+1] ; var bi : double := b->first() * 60 + b[1+1] ; var x : double := bi - ai ; if (x->compareTo(t)) >= 0 then ( execute ((Sequence{star[i+1][3+1], x}) : ans) ) else skip) ; execute ((ans)->size())->display() ; for _tuple : ans do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=map(int,input().split()) def f(i,j): return 60*j[0]+j[1]-60*i[0]-i[1] res=[] tmp=input().split() name,bef=tmp[3],list(map(int,tmp[2].split(":"))) for i in range(n-1): tmp=input().split() aft=list(map(int,tmp[0].split(":"))) tim=f(bef,aft) if tim>=t : res.append([name,str(tim)]) name,bef=tmp[3],list(map(int,tmp[2].split(":"))) print(len(res)) if len(res)!=0 : print("\n".join([" ".join(x)for x in res])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; var res : Sequence := Sequence{} ; var tmp : OclAny := input().split() ; var name : OclAny := null; var bef : OclAny := null; Sequence{name,bef} := Sequence{tmp[3+1],((tmp[2+1].split(":"))->collect( _x | (OclType["int"])->apply(_x) ))} ; for i : Integer.subrange(0, n - 1-1) do ( tmp := input().split() ; var aft : Sequence := ((tmp->first().split(":"))->collect( _x | (OclType["int"])->apply(_x) )) ; var tim : String := f(bef, aft) ; if tim >= t then ( execute ((Sequence{name}->union(Sequence{ ("" + ((tim))) })) : res) ) else skip ; var name : OclAny := null; var bef : OclAny := null; Sequence{name,bef} := Sequence{tmp[3+1],((tmp[2+1].split(":"))->collect( _x | (OclType["int"])->apply(_x) ))}) ; execute ((res)->size())->display() ; if (res)->size() /= 0 then ( execute (StringLib.sumStringsWithSeparator((res->select(x | true)->collect(x | (StringLib.sumStringsWithSeparator((x), " ")))), "\n"))->display() ) else skip; operation f(i : OclAny, j : OclAny) : OclAny pre: true post: true activity: return 60 * j->first() + j[1+1] - 60 * i->first() - i[1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def minimumCuts(a,n): a.sort() gcd=a[1]-a[0] s=gcd for i in range(2,n): gcd=math.gcd(gcd,a[i]-a[i-1]) s+=a[i]-a[i-1] if(360-s>0): gcd=math.gcd(gcd,360-s) return(360//gcd)-n if __name__=="__main__" : arr=[30,60,180] n=len(arr) print(minimumCuts(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var arr : Sequence := Sequence{30}->union(Sequence{60}->union(Sequence{ 180 })) ; n := (arr)->size() ; execute (minimumCuts(arr, n))->display() ) else skip; operation minimumCuts(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: a := a->sort() ; var gcd : double := a[1+1] - a->first() ; var s : OclAny := gcd ; for i : Integer.subrange(2, n-1) do ( gcd := (gcd)->gcd(a[i+1] - a[i - 1+1]) ; s := s + a[i+1] - a[i - 1+1]) ; if (360 - s > 0) then ( gcd := (gcd)->gcd(360 - s) ) else skip ; return (360 div gcd) - n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isVowel(ch): if(ch=='a' or ch=='e' or ch=='i' or ch=='o' or ch=='u'): return True return False def lcs(X,Y,m,n): L=[[0 for i in range(n+1)]for j in range(m+1)] i,j=0,0 for i in range(m+1): for j in range(n+1): if(i==0 or j==0): L[i][j]=0 elif((X[i-1]==Y[j-1])and isVowel(X[i-1])): L[i][j]=L[i-1][j-1]+1 else : L[i][j]=max(L[i-1][j],L[i][j-1]) return L[m][n] X="aieef" Y="klaief" m=len(X) n=len(Y) print("Length of LCS=",lcs(X,Y,m,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; X := "aieef" ; Y := "klaief" ; m := (X)->size() ; n := (Y)->size() ; execute ("Length of LCS=")->display(); operation isVowel(ch : OclAny) : OclAny pre: true post: true activity: if (ch = 'a' or ch = 'e' or ch = 'i' or ch = 'o' or ch = 'u') then ( return true ) else skip ; return false; operation lcs(X : OclAny, Y : OclAny, m : OclAny, n : OclAny) : OclAny pre: true post: true activity: var L : Sequence := Integer.subrange(0, m + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)))) ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,0} ; for i : Integer.subrange(0, m + 1-1) do ( for j : Integer.subrange(0, n + 1-1) do ( if (i = 0 or j = 0) then ( L[i+1][j+1] := 0 ) else (if ((X[i - 1+1] = Y[j - 1+1]) & isVowel(X[i - 1+1])) then ( L[i+1][j+1] := L[i - 1+1][j - 1+1] + 1 ) else ( L[i+1][j+1] := Set{L[i - 1+1][j+1], L[i+1][j - 1+1]}->max() ) ) )) ; return L[m+1][n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin tt=int(stdin.readline()) ANS=[] for loop in range(tt): abc=list(map(int,stdin.readline().split())) ans=sum(abc)//2 ANS.append(ans) print("\n".join(map(str,ANS))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var tt : int := ("" + ((stdin.readLine())))->toInteger() ; var ANS : Sequence := Sequence{} ; for loop : Integer.subrange(0, tt-1) do ( var abc : Sequence := ((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := (abc)->sum() div 2 ; execute ((ans) : ANS)) ; execute (StringLib.sumStringsWithSeparator(((ANS)->collect( _x | (OclType["String"])->apply(_x) )), "\n"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): k,p=map(int,input().split()) k %=p print(p if k==0 else k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var k : OclAny := null; var p : OclAny := null; Sequence{k,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; k := k mod p ; execute (if k = 0 then p else k endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) V=[0 for i in range(N)] for i in range(N): k,p=map(int,input().split()) if p>=k : c=k else : while True : b=k-p if b<=p : c=b break else : k=b V[i-1]=c for i in range(N): print(V[i-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var V : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, N-1) do ( var k : OclAny := null; var p : OclAny := null; Sequence{k,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (p->compareTo(k)) >= 0 then ( var c : OclAny := k ) else ( while true do ( var b : double := k - p ; if (b->compareTo(p)) <= 0 then ( c := b ; break ) else ( var k : OclAny := b )) ) ; V[i - 1+1] := c) ; for i : Integer.subrange(0, N-1) do ( execute (V[i - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys f=sys.stdin n=int(f.readline()) for k,p in(map(int,line.split())for line in f): print(k % p if k % p else p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var f : OclFile := OclFile["System.in"] ; var n : int := ("" + ((f.readLine())))->toInteger() ; for _tuple : Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name line)) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name line)))) in (logical_test (comparison (expr (atom (name f)))))))} do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p : OclAny := _tuple->at(_indx); execute (if k mod p then k mod p else p endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) K=[] P=[] while len(K)toInteger() ; var K : Sequence := Sequence{} ; var P : Sequence := Sequence{} ; while ((K)->size()->compareTo(n)) < 0 do ( var k : OclAny := null; var p : OclAny := null; Sequence{k,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((k) : K) ; execute ((p) : P)) ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := K[i+1] ; var b : OclAny := P[i+1] ; if a mod b /= 0 then ( execute (a mod b)->display() ) else ( execute (b)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) for l in range(N): K,P=[int(i)for i in input().split()] ans=K % P if ans==0 : ans=P print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for l : Integer.subrange(0, N-1) do ( var K : OclAny := null; var P : OclAny := null; Sequence{K,P} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : int := K mod P ; if ans = 0 then ( ans := P ) else skip ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n,q=map(int,input().split()) s=[0]*-~ n w=m=0 for e in sys.stdin : a,v=map(int,e.split()) s[a]+=v if v<0 and a==w : m=max(s); w=s.index(m) elif s[a]>m : w,m=a,s[a] elif s[a]==m : w=min(w,a) print(w,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, -MathLib.bitwiseNot(n)) ; var w : OclAny := 0; var m : int := 0 ; for e : OclFile["System.in"] do ( var a : OclAny := null; var v : OclAny := null; Sequence{a,v} := (e.split())->collect( _x | (OclType["int"])->apply(_x) ) ; s[a+1] := s[a+1] + v ; if v < 0 & a = w then ( m := (s)->max(); w := s->indexOf(m) - 1 ) else (if (s[a+1]->compareTo(m)) > 0 then ( Sequence{w,m} := Sequence{a,s[a+1]} ) else (if s[a+1] = m then ( w := Set{w, a}->min() ) else skip ) ) ; execute (w)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) l=list(map(int,input().split())) ras=set(l) number=dict() for j in l : if j not in number : number[j]=1 else : number[j]+=1 minbl=0 for q,w in number.items(): minbl=max(minbl,(w+k-1)//k) print(minbl*len(ras)*k-n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ras : Set := Set{}->union((l)) ; var number : Map := (arguments ( )) ; for j : l do ( if (number)->excludes(j) then ( number[j+1] := 1 ) else ( number[j+1] := number[j+1] + 1 )) ; var minbl : int := 0 ; for _tuple : number->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var q : OclAny := _tuple->at(_indx); _indx := _indx + 1; var w : OclAny := _tuple->at(_indx); minbl := Set{minbl, (w + k - 1) div k}->max()) ; execute (minbl * (ras)->size() * k - n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) for i in range(num): n=int(input()) if n % 2050!=0 : print(-1) else : lenz=0 compare=0 dec=n while comparetoInteger() ; for i : Integer.subrange(0, num-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2050 /= 0 then ( execute (-1)->display() ) else ( var lenz : int := 0 ; var compare : int := 0 ; var dec : int := n ; while (compare->compareTo(n)) < 0 do ( var val : int := (("" + ((dec))))->size() ; for k : Integer.subrange(-1 + 1, val - 4)->reverse() do ( if (2050 * ((10)->pow(k))->compareTo(dec)) <= 0 then ( compare := compare + 2050 * ((10)->pow(k)) ; dec := dec - 2050 * ((10)->pow(k)) ; break ) else skip) ; lenz := lenz + 1) ; execute (lenz)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class SegmentTree : def __init__(self,n): n_=1 while n_<=n : n_*=2 self.n=n_ self.data=[(0,-n_-1)]*(2*n_) def add(self,k,a): idx=k+(self.n-1) data=self.data data[idx]=(data[idx][0]+a,-k) while idx : idx=(idx-1)/2 data[idx]=max(data[2*idx+1],data[2*idx+2]) def get(self): return self.data[0] inputs=lambda : map(int,raw_input().split()) n,q=inputs() st=SegmentTree(n) for t in xrange(q): a,v=inputs() st.add(a,v) p,q=st.get() print-q,p ------------------------------------------------------------ OCL File: --------- class SegmentTree { static operation newSegmentTree() : SegmentTree pre: true post: SegmentTree->exists( _x | result = _x ); attribute n : int := n_; attribute data : Sequence := MatrixLib.elementwiseMult(Sequence{ Sequence{0, -n_ - 1} }, (2 * n_)); operation initialise(n : OclAny) : SegmentTree pre: true post: true activity: var n_ : int := 1 ; while (n_->compareTo(n)) <= 0 do ( n_ := n_ * 2) ; self.n := n_ ; self.data := MatrixLib.elementwiseMult(Sequence{ Sequence{0, -n_ - 1} }, (2 * n_)); return self; operation add(k : OclAny,a : OclAny) pre: true post: true activity: var idx : OclAny := k + (self.n - 1) ; var data : OclAny := self.data ; data[idx+1] := Sequence{data[idx+1]->first() + a, -k} ; while idx do ( idx := (idx - 1) / 2 ; data[idx+1] := Set{data[2 * idx + 1+1], data[2 * idx + 2+1]}->max()); operation get() : OclAny pre: true post: true activity: return self.data->first(); } class FromPython { operation initialise() pre: true post: true activity: skip ; var inputs : Function := lambda $$ : OclAny in ((raw_input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : OclAny := null; Sequence{n,q} := inputs->apply() ; var st : SegmentTree := (SegmentTree.newSegmentTree()).initialise(n) ; for t : xrange(q) do ( var v : OclAny := null; Sequence{a,v} := inputs->apply() ; execute ((a, v) : st) ; var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := st.get() ; print - q ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import division,print_function from sys import stdin,exit def main(readline=stdin.readline): n,q=(int(s)for s in readline().split()) base=[0]*n midway=[0]*(n//100+1) last=[0]*(n//10000+1) for _ in range(q): a,v=(int(s)for s in readline().split()) a-=1 base[a]+=v b=a-a % 100 index=b value=base[b] end=b+100 if b+100oclIsUndefined() then readline := stdin.readline else skip; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name readline)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var base : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var midway : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n div 100 + 1)) ; var last : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n div 10000 + 1)) ; for _anon : Integer.subrange(0, q-1) do ( var a : OclAny := null; var v : OclAny := null; Sequence{a,v} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name readline)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; a := a - 1 ; base[a+1] := base[a+1] + v ; var b : double := a - a mod 100 ; var index : OclAny := b ; var value : OclAny := base[b+1] ; var end : OclAny := if (b + 100->compareTo(n)) < 0 then b + 100 else n endif ; for i : Integer.subrange(b, end-1) do ( if (value->compareTo(base[i+1])) < 0 then ( value := base[i+1] ; index := i ) else skip) ; midway[b div 100+1] := index ; var c : double := a - a mod 10000 ; var cc : int := c div 100 ; index := c ; value := base[c+1] ; for i : midway.subrange(cc+1, cc + 100) do ( if (value->compareTo(base[i+1])) < 0 then ( value := base[i+1] ; index := i ) else skip) ; last[c div 10000+1] := index ; index := last->first() ; value := base[index+1] ; for i : last do ( if (value->compareTo(base[i+1])) < 0 then ( value := base[i+1] ; index := i ) else skip) ; execute (index + 1)->display()) ; exit(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) for loop in range(q): a,b,c=map(int,input().split()) print((a+b+c)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for loop : Integer.subrange(0, q-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a + b + c) div 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq MAX=1000000 SFT=20 Q=[] tbl=[[0 for j in range(2)]for i in range(MAX+2)] n,q=list(map(int,input().split())) for i in range(q): id,v=list(map(int,input().split())) tbl[id][0]+=v tbl[id][1]+=1 heapq.heappush(Q,((-tbl[id][0]<select(i | true)->collect(i | (Integer.subrange(0, 2-1)->select(j | true)->collect(j | (0)))) ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, q-1) do ( var id : OclAny := null; var v : OclAny := null; Sequence{id,v} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; tbl[id+1]->first() := tbl[id+1]->first() + v ; tbl[id+1][1+1] := tbl[id+1][1+1] + 1 ; heapq.heappush(Q, Sequence{MathLib.bitwiseOr((-tbl[id+1]->first() * (2->pow(SFT))), id), id, tbl[id+1][1+1]}) ; while 1 do ( var f : OclAny := null; var id : OclAny := null; var c : OclAny := null; Sequence{f,id,c} := Q->first() ; if tbl[id+1][1+1] = c then ( execute (id)->display() ; break ) else skip ; heapq.heappop(Q))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=10**20 def main(): n,q=map(int,input().split()) size=1 while size0 : ind=(ind-1)//2 ca1,cv1=seg_tree[ind*2+1] ca2,cv2=seg_tree[ind*2+2] if cv1>=cv2 : if seg_tree[ind]==(ca1,cv1): break seg_tree[ind]=(ca1,cv1) else : if seg_tree[ind]==(ca2,cv2): break seg_tree[ind]=(ca2,cv2) for i in range(q): a,v=map(int,input().split()) update(a-1,v) print(seg_tree[0][0],seg_tree[0][1]) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INF : double := (10)->pow(20) ; skip ; main(); operation main() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var size : int := 1 ; while (size->compareTo(n)) < 0 do ( size := size * 2) ; size := size * 2 - 1 ; var seg_tree : Sequence := Integer.subrange(0, size-1)->select(_anon | true)->collect(_anon | (Sequence{INF, 0})) ; skip ; for i : Integer.subrange(0, q-1) do ( Sequence{a,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; update(a - 1, v) ; execute (seg_tree->first()->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def avg_of_even_num(n): sum=0 for i in range(1,n+1): sum=sum+2*i return sum/n n=9 print(avg_of_even_num(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 9 ; execute (avg_of_even_num(n))->display(); operation avg_of_even_num(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( sum := sum + 2 * i) ; return sum / n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfDigits(x): sum=0 ; while(x>0): sum+=(x % 10); x=int(x/10); return sum ; def compute(n): answer=[]; pos=0 ; for i in range(101): valueOnLeft=(abs(n-i)+sumOfDigits(abs(n-i))); valueOnRight=(n+i)+sumOfDigits(n+i); if(valueOnRight==n): answer.append(n+i); if(valueOnLeft==n): answer.append(abs(n-i)); if(len(answer)==0): print(-1); else : for i in range(len(answer)): print("X=",answer[i]); N=100000001 ; compute(N); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := 100000001; ; compute(N);; operation sumOfDigits(x : OclAny) pre: true post: true activity: var sum : int := 0; ; while (x > 0) do ( sum := sum + (x mod 10); ; x := ("" + ((x / 10)))->toInteger();) ; return sum;; operation compute(n : OclAny) pre: true post: true activity: var answer : Sequence := Sequence{}; ; var pos : int := 0; ; for i : Integer.subrange(0, 101-1) do ( var valueOnLeft : double := ((n - i)->abs() + sumOfDigits((n - i)->abs())); ; var valueOnRight : OclAny := (n + i) + sumOfDigits(n + i); ; if (valueOnRight = n) then ( execute ((n + i) : answer); ) else skip ; if (valueOnLeft = n) then ( execute (((n - i)->abs()) : answer); ) else skip) ; if ((answer)->size() = 0) then ( execute (-1)->display(); ) else ( for i : Integer.subrange(0, (answer)->size()-1) do ( execute ("X=")->display();) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) arr=list(map(int,input().split())) print(n-arr.count(min(arr))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (n - arr->count((arr)->min()))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): input() inputList=list(map(int,input().split(" "))) inputList=[item for item in inputList if item!=min(inputList)] print(len(inputList)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( input() ; var inputList : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; inputList := inputList->select(item | item /= (inputList)->min())->collect(item | (item)) ; execute ((inputList)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) print(n-a.count(min(a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (n - a->count((a)->min()))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): heroes=int(input()) strength=list(map(int,input().split())) counter=0 temp=min(strength) for i in strength : if i>temp : counter+=1 print(counter) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var heroes : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var strength : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var counter : int := 0 ; var temp : OclAny := (strength)->min() ; for i : strength do ( if (i->compareTo(temp)) > 0 then ( counter := counter + 1 ) else skip) ; execute (counter)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) x=int(n/2050) s=str(x) sum=0 l=[] if(n % 2050!=0)or n<2050 : print(-1) else : for j in s : l.append(j) for j in range(len(l)): sum+=int(l[j]) print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := ("" + ((n / 2050)))->toInteger() ; var s : String := ("" + ((x))) ; var sum : int := 0 ; var l : Sequence := Sequence{} ; if (n mod 2050 /= 0) or n < 2050 then ( execute (-1)->display() ) else ( for j : s->characters() do ( execute ((j) : l)) ; for j : Integer.subrange(0, (l)->size()-1) do ( sum := sum + ("" + ((l[j+1])))->toInteger()) ; execute (sum)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) li=list(map(int,input().split())) li.sort() tmp=li[0] res=0 for i in li : if i>tmp : res+=1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; li := li->sort() ; var tmp : OclAny := li->first() ; var res : int := 0 ; for i : li do ( if (i->compareTo(tmp)) > 0 then ( res := res + 1 ) else skip) ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in[*open(0)][1 :]: print(sum(map(int,i.split()))//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( execute (((i.split())->collect( _x | (OclType["int"])->apply(_x) ))->sum() div 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(): n=input() l1=set(input().split(' ')) print(len(l1)) return 0 row=int(input()) for r in range(row): f() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var row : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for r : Integer.subrange(0, row-1) do ( f()); operation f() : OclAny pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var l1 : Set := Set{}->union((input().split(' '))) ; execute ((l1)->size())->display() ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): length=int(input()) m=[int(num)for num in input().split()] print(len(set(m))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var length : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : Sequence := input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; execute ((Set{}->union((m)))->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) print(len(set(input().split()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((Set{}->union((input().split())))->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=map(int,input().split()) print(len(set(a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Set{}->union((a)))->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=input() t=int(t) for i in range(t): n=input() Set=input() Set=Set.split() Set=list(dict.fromkeys(Set)) print(len(Set)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : String := (OclFile["System.in"]).readLine() ; t := ("" + ((t)))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : String := (OclFile["System.in"]).readLine() ; var Set : String := (OclFile["System.in"]).readLine() ; Set := Set.split() ; Set := ((trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name Set)))))))) ))))->keys()->asSequence() ; execute ((Set)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) q=int(input()) k=[] for i in range(q): k1=int(input()) k.append([k1,i]) a.sort() k.sort() lwb=[n]*q upb=[n]*q i1=0 i2=0 j1=0 j2=0 while i1a[j1]: j1+=1 except : pass try : while k[i1][0]>=a[j2]: j2+=1 except : pass lwb[k[i1][1]]=j1 i1+=1 upb[k[i2][1]]=j2 i2+=1 for i in range(q): print(lwb[i],upb[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : Sequence := Sequence{} ; for i : Integer.subrange(0, q-1) do ( var k1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((Sequence{k1}->union(Sequence{ i })) : k)) ; a := a->sort() ; k := k->sort() ; var lwb : Sequence := MatrixLib.elementwiseMult(Sequence{ n }, q) ; var upb : Sequence := MatrixLib.elementwiseMult(Sequence{ n }, q) ; var i1 : int := 0 ; var i2 : int := 0 ; var j1 : int := 0 ; var j2 : int := 0 ; while (i1->compareTo(q)) < 0 & (i2->compareTo(q)) < 0 & (j1->compareTo(n)) < 0 & (j2->compareTo(n)) < 0 do ( try ( while (k[i1+1]->first()->compareTo(a[j1+1])) > 0 do ( j1 := j1 + 1)) catch (_e : OclException) do ( skip) ; try ( while (k[i1+1]->first()->compareTo(a[j2+1])) >= 0 do ( j2 := j2 + 1)) catch (_e : OclException) do ( skip) ; lwb[k[i1+1][1+1]+1] := j1 ; i1 := i1 + 1 ; upb[k[i2+1][1+1]+1] := j2 ; i2 := i2 + 1) ; for i : Integer.subrange(0, q-1) do ( execute (lwb[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect input(); A=list(map(int,input().split())) for _ in[0]*int(input()): k=int(input()) print(bisect.bisect_left(A,k),bisect.bisect_right(A,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; input(); var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (bisect.bisect_left(A, k))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binaryUpper(n,a): ok=-1 ng=len(a) while abs(ok-ng)>1 : mid=(ok+ng)//2 if a[mid]<=n : ok=mid else : ng=mid return ng def binaryLower(n,a): ok=len(a) ng=-1 while abs(ok-ng)>1 : mid=(ok+ng)//2 if a[mid]>=n : ok=mid else : ng=mid return ok def resolve(): import sys input=sys.stdin.readline n=int(input()) a=[int(i)for i in input().split()] q=int(input()) for _ in range(q): k=int(input()) print(binaryLower(k,a),binaryUpper(k,a)) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; resolve(); operation binaryUpper(n : OclAny, a : OclAny) : OclAny pre: true post: true activity: var ok : int := -1 ; var ng : int := (a)->size() ; while (ok - ng)->abs() > 1 do ( var mid : int := (ok + ng) div 2 ; if (a[mid+1]->compareTo(n)) <= 0 then ( ok := mid ) else ( ng := mid )) ; return ng; operation binaryLower(n : OclAny, a : OclAny) : OclAny pre: true post: true activity: ok := (a)->size() ; ng := -1 ; while (ok - ng)->abs() > 1 do ( mid := (ok + ng) div 2 ; if (a[mid+1]->compareTo(n)) >= 0 then ( ok := mid ) else ( ng := mid )) ; return ok; operation resolve() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (binaryLower(k, a))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect f=open(0) readline=f.readline N=int(readline()) *A,=map(int,readline().split()) ans=[] def query(Q): for k in map(int,f.read().split()): idx=bisect(A,k-1) if idxtoInteger() ; (testlist_star_expr (star_expr * (expr (atom (name A)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name A)))) ,)} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := Sequence{} ; skip ; (expr (atom (name open)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom 'w'))))))) ))) (trailer . (name writelines) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name query)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name readline)) (trailer (arguments ( ))))))))) ))))))))) ))))))))) ))))))))) )))); operation query(Q : OclAny) pre: true post: true activity: for k : (f.readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( var idx : OclAny := bisect(A, k - 1) ; if (idx->compareTo(N)) < 0 & A[idx+1] = k then ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return StringLib.format("%d %d\n",Sequence{idx, bisect(A, k)}) ) else ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return StringLib.format("%d %d\n",Sequence{idx, idx}) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) print(-1 if n % 2050 else sum(map(int,str(n//2050)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (if n mod 2050 then -1 else ((("" + ((n div 2050))))->collect( _x | (OclType["int"])->apply(_x) ))->sum() endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) def one_sided(slots,x): if slots>=x-1 : result=(slots-x+1)+(x-1)*x//2 return result else : result=slots*(2*x-slots-1)//2 return result def pillows_used(x): left_slot=k-1 right_slot=n-k res=x+one_sided(left_slot,x)+one_sided(right_slot,x)<=m return res left=1 right=m mid=(left+right)//2 while left!=right : if pillows_used(mid): left=mid+1 else : right=mid mid=(left+right)//2 if(n==1): print(mid) else : print(mid-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; skip ; var left : int := 1 ; var right : OclAny := m ; var mid : int := (left + right) div 2 ; while left /= right do ( if pillows_used(mid) then ( left := mid + 1 ) else ( right := mid ) ; mid := (left + right) div 2) ; if (n = 1) then ( execute (mid)->display() ) else ( execute (mid - 1)->display() ); operation one_sided(slots : OclAny, x : OclAny) : OclAny pre: true post: true activity: if (slots->compareTo(x - 1)) >= 0 then ( var result : double := (slots - x + 1) + (x - 1) * x div 2 ; return result ) else ( result := slots * (2 * x - slots - 1) div 2 ; return result ); operation pillows_used(x : OclAny) : OclAny pre: true post: true activity: var left_slot : double := k - 1 ; var right_slot : double := n - k ; var res : boolean := (x + one_sided(left_slot, x) + one_sided(right_slot, x)->compareTo(m)) <= 0 ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from bisect import bisect_left from bisect import bisect_right input() arr=list(map(int,input().split())) nq=int(input()) lines=sys.stdin.readlines() ans=[None]*nq for i in range(nq): q=int(lines[i]) ans[i]='{}{}'.format((bisect_left(arr,q)),bisect_right(arr,q)) print('\n'.join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; input() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var nq : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lines : OclAny := (OclFile["System.in"]).readlines() ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, nq) ; for i : Integer.subrange(0, nq-1) do ( var q : int := ("" + ((lines[i+1])))->toInteger() ; ans[i+1] := StringLib.interpolateStrings('{}{}', Sequence{(bisect_left(arr, q)), bisect_right(arr, q)})) ; execute (StringLib.sumStringsWithSeparator((ans), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countFreq(a,n): hm={} for i in range(0,n): hm[a[i]]=hm.get(a[i],0)+1 st=set() for x in hm : st.add((x,hm[x])) cumul=0 for x in sorted(st): cumul+=x[1] print(x[0],cumul) if __name__=="__main__" : a=[1,3,2,4,2,1] n=len(a) countFreq(a,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{1}->union(Sequence{3}->union(Sequence{2}->union(Sequence{4}->union(Sequence{2}->union(Sequence{ 1 }))))) ; n := (a)->size() ; countFreq(a, n) ) else skip; operation countFreq(a : OclAny, n : OclAny) pre: true post: true activity: var hm : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( hm[a[i+1]+1] := hm.get(a[i+1], 0) + 1) ; var st : Set := Set{}->union(()) ; for x : hm do ( execute ((Sequence{x, hm[x+1]}) : st)) ; var cumul : int := 0 ; for x : st->sort() do ( cumul := cumul + x[1+1] ; execute (x->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) h=list(map(int,input().split())) step=[] for i in range(n-1): if h[i]toInteger() ; var h : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var step : Sequence := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( if (h[i+1]->compareTo(h[i + 1+1])) < 0 then ( execute ((0) : step) ) else ( execute ((1) : step) )) ; var a : Sequence := Integer.subrange(1, (step)->size())->collect( _indx | Sequence{_indx-1, (step)->at(_indx)} )->select(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in x = 0)->collect(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in (i)) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, (a)->size()-1) do ( if i = 0 then ( var d : OclAny := a->first() ; execute ((d) : ans) ) else ( var b : double := a[i+1] - a[i - 1+1] ; execute ((b) : ans) )) ; if not(a) then ( execute (n - 1)->display() ) else ( execute (((n - 1) - a->last()) : ans) ; execute ((ans)->max() - 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import groupby _=input() H=tuple(map(int,input().split())) a=[h1>=h2 for h1,h2 in zip(H,H[1 :])] print(max((sum(g)for k,g in groupby(a)if k),default=0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var _anon : String := (OclFile["System.in"]).readLine() ; var H : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := Integer.subrange(1, H->size())->collect( _indx | Sequence{H->at(_indx), H->tail()->at(_indx)} )->select(_tuple | true)->collect(_tuple | let h1 : OclAny = _tuple->at(1) in let h2 : OclAny = _tuple->at(2) in ((h1->compareTo(h2)) >= 0)) ; execute (Set{Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name g)))))))) ))))))) (comp_for for (exprlist (expr (atom (name k))) , (expr (atom (name g)))) in (logical_test (comparison (expr (atom (name groupby)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (atom (name k)))))))))}, (argument (test (logical_test (comparison (expr (atom (name default)))))) = (test (logical_test (comparison (expr (atom (number (integer 0))))))))}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): input() H=[int(i)for i in input().split()] ans=0 prev=float('inf') cnt=-1 for cur in H : if prev>=cur : cnt+=1 else : if ansselect(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : int := 0 ; var prev : double := ("" + (('inf')))->toReal() ; var cnt : int := -1 ; for cur : H do ( if (prev->compareTo(cur)) >= 0 then ( cnt := cnt + 1 ) else ( if (ans->compareTo(cnt)) < 0 then ( ans := cnt ) else skip ; cnt := 0 ) ; prev := cur) ; if (ans->compareTo(cnt)) < 0 then ( ans := cnt ) else skip ; execute (ans)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np N=int(input()) H=np.array([int(i)for i in input().split(' ')]) length=0 max_length=0 for i in range(N-1): if H[i+1]-H[i]<=0 : length+=1 else : length=0 if max_lengthtoInteger() ; var H : Sequence := (input().split(' ')->select(i | true)->collect(i | (("" + ((i)))->toInteger()))) ; var length : int := 0 ; var max_length : int := 0 ; for i : Integer.subrange(0, N - 1-1) do ( if H[i + 1+1] - H[i+1] <= 0 then ( length := length + 1 ) else ( length := 0 ; if (max_length->compareTo(length)) < 0 then ( max_length := length ) else skip ) ; if (max_length->compareTo(length)) < 0 then ( max_length := length ) else skip) ; execute (max_length)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) h_list=list(map(int,input().split())) i=0 cnt=0 record=0 while i=h_list[i+1]: cnt+=1 else : cnt=0 if cnt>record : record=cnt i+=1 print(record) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var h_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var i : int := 0 ; var cnt : int := 0 ; var record : int := 0 ; while (i->compareTo(n - 1)) < 0 do ( if (h_list[i+1]->compareTo(h_list[i + 1+1])) >= 0 then ( cnt := cnt + 1 ) else ( cnt := 0 ) ; if (cnt->compareTo(record)) > 0 then ( record := cnt ) else skip ; i := i + 1) ; execute (record)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkBit(pattern,arr,n): count=0 for i in range(0,n): if((pattern & arr[i])==pattern): count=count+1 return count def maxAND(arr,n): res=0 for bit in range(31,-1,-1): count=checkBit(res |(1<=2): res=res |(1<display() ) else ( execute ("No")->display() ) ) else skip; operation arePermutation(str1 : OclAny, str2 : OclAny) : OclAny pre: true post: true activity: var n1 : int := (str1)->size() ; var n2 : int := (str2)->size() ; if (n1 /= n2) then ( return false ) else skip ; var a : Sequence := str1->sort() ; str1 := StringLib.sumStringsWithSeparator((a), " ") ; var b : Sequence := str2->sort() ; str2 := StringLib.sumStringsWithSeparator((b), " ") ; for i : Integer.subrange(0, n1-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (str1[i+1] /= str2[i+1]) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break f=list(input().split()) is_on=False left_up=False right_up=False ans=0 for i in range(n): if f[i]=="lu" : left_up=True elif f[i]=="ld" : left_up=False elif f[i]=="ru" : right_up=True else : right_up=False if left_up and right_up and not is_on : is_on=True ans+=1 elif not left_up and not right_up and is_on : is_on=False ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var f : Sequence := (input().split()) ; var is_on : boolean := false ; var left_up : boolean := false ; var right_up : boolean := false ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if f[i+1] = "lu" then ( left_up := true ) else (if f[i+1] = "ld" then ( left_up := false ) else (if f[i+1] = "ru" then ( right_up := true ) else ( right_up := false ) ) ) ; if left_up & right_up & not(is_on) then ( is_on := true ; ans := ans + 1 ) else (if not(left_up) & not(right_up) & is_on then ( is_on := false ; ans := ans + 1 ) else skip)) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a,b=map(int,input().split()) count=0 while a!=0 and b!=0 : m=min(a,b) b=max(a,b) a=m count+=b//a b=b % a print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var count : int := 0 ; while a /= 0 & b /= 0 do ( var m : OclAny := Set{a, b}->min() ; var b : OclAny := Set{a, b}->max() ; var a : OclAny := m ; count := count + b div a ; b := b mod a) ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): print(sum(map(int,input().split()))//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum() div 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for _ in range(n): x=int(input()) if(x % 2050!=0): print(-1) else : c=0 x=x//2050 while(x!=0): c+=x % 10 x=x//10 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (x mod 2050 /= 0) then ( execute (-1)->display() ) else ( var c : int := 0 ; x := x div 2050 ; while (x /= 0) do ( c := c + x mod 10 ; x := x div 10) ; execute (c)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if n==0 : break step=list(input().split()) pos=0 lu,ru,ld,rd=[0]*4 cnt=0 for s in step : if pos==0 : if s=="lu" : lu=1 elif s=="ru" : ru=1 elif s=="ld" : lu=0 elif s=="rd" : ru=0 if lu==1 and ru==1 : cnt+=1 pos=1 lu,ru=0,0 elif pos==1 : if s=="ld" : ld=1 elif s=="rd" : rd=1 elif s=="lu" : ld=0 elif s=="ru" : rd=0 if ld==1 and rd==1 : cnt+=1 pos=0 ld,rd=0,0 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var step : Sequence := (input().split()) ; var pos : int := 0 ; var lu : OclAny := null; var ru : OclAny := null; var ld : OclAny := null; var rd : OclAny := null; Sequence{lu,ru,ld,rd} := MatrixLib.elementwiseMult(Sequence{ 0 }, 4) ; var cnt : int := 0 ; for s : step do ( if pos = 0 then ( if s = "lu" then ( var lu : int := 1 ) else (if s = "ru" then ( var ru : int := 1 ) else (if s = "ld" then ( lu := 0 ) else (if s = "rd" then ( ru := 0 ) else skip ) ) ) ; if lu = 1 & ru = 1 then ( cnt := cnt + 1 ; pos := 1 ; Sequence{lu,ru} := Sequence{0,0} ) else skip ) else (if pos = 1 then ( if s = "ld" then ( var ld : int := 1 ) else (if s = "rd" then ( var rd : int := 1 ) else (if s = "lu" then ( ld := 0 ) else (if s = "ru" then ( rd := 0 ) else skip ) ) ) ; if ld = 1 & rd = 1 then ( cnt := cnt + 1 ; pos := 0 ; Sequence{ld,rd} := Sequence{0,0} ) else skip ) else skip)) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ansli=[] while 1 : n=input() if n=="0" : break a=input().split() up=0 down=1 lu=0 ru=0 ld=0 rd=0 count=0 for i in a : if i=="ru" : ru=1 rd=0 elif i=="lu" : lu=1 ld=0 elif i=="rd" : rd=1 ru=0 elif i=="ld" : ld=1 lu=0 if ru==1 and lu==1 and down==1 : count+=1 down=0 up=1 elif rd==1 and ld==1 and up==1 : count+=1 down=1 up=0 ansli.append(count) for i in ansli : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ansli : Sequence := Sequence{} ; while 1 do ( var n : String := (OclFile["System.in"]).readLine() ; if n = "0" then ( break ) else skip ; var a : OclAny := input().split() ; var up : int := 0 ; var down : int := 1 ; var lu : int := 0 ; var ru : int := 0 ; var ld : int := 0 ; var rd : int := 0 ; var count : int := 0 ; for i : a do ( if i = "ru" then ( ru := 1 ; rd := 0 ) else (if i = "lu" then ( lu := 1 ; ld := 0 ) else (if i = "rd" then ( rd := 1 ; ru := 0 ) else (if i = "ld" then ( ld := 1 ; lu := 0 ) else skip ) ) ) ; if ru = 1 & lu = 1 & down = 1 then ( count := count + 1 ; down := 0 ; up := 1 ) else (if rd = 1 & ld = 1 & up = 1 then ( count := count + 1 ; down := 1 ; up := 0 ) else skip)) ; execute ((count) : ansli)) ; for i : ansli do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math while True : answer=0 count=int(input()) if count==0 : break orders=input().split(' ') for i in range(int(math.floor(count/2))): s=orders[2*i : 2*i+2] if not(s[0][0]==s[1][0])and(s[0][1]==s[1][1]): answer+=1 print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var answer : int := 0 ; var count : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if count = 0 then ( break ) else skip ; var orders : OclAny := input().split(' ') ; for i : Integer.subrange(0, ("" + (((count / 2)->floor())))->toInteger()-1) do ( var s : OclAny := orders.subrange(2 * i+1, 2 * i + 2) ; if not((s->first()->first() = s[1+1]->first())) & (s->first()[1+1] = s[1+1][1+1]) then ( answer := answer + 1 ) else skip) ; execute (answer)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): while True : n=int(input()) if n==0 : exit() f=[s for s in input().split()] pm='d' cnt=0 for m in f : if m[1]==pm : cnt+=1 pm=m[1] print(cnt) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( exit() ) else skip ; var f : Sequence := input().split()->select(s | true)->collect(s | (s)) ; var pm : String := 'd' ; var cnt : int := 0 ; for m : f do ( if m[1+1] = pm then ( cnt := cnt + 1 ) else skip ; pm := m[1+1]) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,w=map(int,input().split()) arr=list(map(int,input().split())) arr.sort() maxi=w/(3*n) if arr[-n]arr[0]: maxi=arr[0] print(3*n*maxi) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var w : OclAny := null; Sequence{n,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := arr->sort() ; var maxi : double := w / (3 * n) ; if (arr->reverse()->at(-(-n))->compareTo(maxi * 2)) < 0 then ( maxi := arr->reverse()->at(-(-n)) / 2 ) else skip ; if (maxi->compareTo(arr->first())) > 0 then ( maxi := arr->first() ) else skip ; execute (3 * n * maxi)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,w=map(int,input().split()) a=list(map(int,input().split())) a=sorted(a) m_g,m_b=a[0],a[n] if m_b/2<=m_g and(m_b/2)*n+m_b*n<=w : print((m_b/2)*n+m_b*n) elif m_g*2<=m_b and m_g*n+m_g*2*n<=w : print(m_g*n+m_g*2*n) else : x=w/(3*n) print(3*x*n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var w : OclAny := null; Sequence{n,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var m_g : OclAny := null; var m_b : OclAny := null; Sequence{m_g,m_b} := Sequence{a->first(),a[n+1]} ; if (m_b / 2->compareTo(m_g)) <= 0 & ((m_b / 2) * n + m_b * n->compareTo(w)) <= 0 then ( execute ((m_b / 2) * n + m_b * n)->display() ) else (if (m_g * 2->compareTo(m_b)) <= 0 & (m_g * n + m_g * 2 * n->compareTo(w)) <= 0 then ( execute (m_g * n + m_g * 2 * n)->display() ) else ( var x : double := w / (3 * n) ; execute (3 * x * n)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : n,w=list(map(int,input().split())) arr=list(map(int,input().split())) sorted_arr=sorted(arr) boys=sorted_arr[n :] girls=sorted_arr[: n] total=0 a=girls[0] b=boys[0] m=min(a,b/2) ans=min(3*m*n,w) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var n : OclAny := null; var w : OclAny := null; Sequence{n,w} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sorted_arr : Sequence := arr->sort() ; var boys : OclAny := sorted_arr.subrange(n+1) ; var girls : OclAny := sorted_arr.subrange(1,n) ; var total : int := 0 ; var a : OclAny := girls->first() ; var b : OclAny := boys->first() ; var m : OclAny := Set{a, b / 2}->min() ; var ans : OclAny := Set{3 * m * n, w}->min() ; execute (ans)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- params=list(map(int,input().split(" "))) n=params[0] w=params[1] volumn=sorted(list(map(int,input().split(" ")))) temp=0 if volumn[0]*2w : print(w) else : print(temp) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var params : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := params->first() ; var w : OclAny := params[1+1] ; var volumn : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var temp : int := 0 ; if (volumn->first() * 2->compareTo(volumn[n+1])) < 0 then ( temp := volumn->first() * 3.0 * n ) else ( temp := volumn[n+1] / 2.0 * 3 * n ) ; if (temp->compareTo(w)) > 0 then ( execute (w)->display() ) else ( execute (temp)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inp_1=input() inp_2=input() inp_1=inp_1.split(' ') n=int(inp_1[0]) w=int(inp_1[1]) inp_2=inp_2.split(' ') cup_cap=list() for i in range(2*n): cup_cap.append(int(inp_2[i])) cup_cap.sort() amount=0 if cup_cap[0]>=cup_cap[n]/2 : amount_girl=cup_cap[n]/2 else : amount_girl=cup_cap[0] amount_boy=amount_girl*2 amount_total=amount_boy+amount_girl if amount_total*n<=w : print(amount_total*n) else : print(w) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inp_1 : String := (OclFile["System.in"]).readLine() ; var inp:= (OclFile["System.in"]).readLine() : String := (OclFile["System.in"]).readLine() ; inp var inp_1 : String := (OclFile["System.in"]).readLine() := inp var inp_1 : String := (OclFile["System.in"]).readLine().split(' ') ; var n : int := ("" + ((inp var inp_1 : String := (OclFile["System.in"]).readLine()->first())))->toInteger() ; var w : int := ("" + ((inp var inp_1 : String := (OclFile["System.in"]).readLine()[1+1])))->toInteger() ; inp:= inp_2.split(' ') := inp_2.split(' ') ; var cup_cap : Sequence := () ; for i : Integer.subrange(0, 2 * n-1) do ( execute ((("" + ((inp.append(("" + ((inp_2[i+1])))->toInteger())[i+1])))->toInteger()) : cup_cap)) ; cup_cap := cup_cap->sort() ; var amount : int := 0 ; if (cup_cap->first()->compareTo(cup_cap[n+1] / 2)) >= 0 then ( var amount_girl : double := cup_cap[n+1] / 2 ) else ( amount_girl := cup_cap->first() ) ; var amount_boy : double := amount_girl * 2 ; var amount_total : OclAny := amount_boy + amount_girl ; if (amount_total * n->compareTo(w)) <= 0 then ( execute (amount_total * n)->display() ) else ( execute (w)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Divisors(x): c=0 v=[] while(x % 2==0): c+=1 x/=2 v.append(c) c=0 while(x % 3==0): c+=1 x/=3 v.append(c) c=0 while(x % 7==0): c+=1 x/=7 v.append(c) v.append(x) return v def MinOperations(a,b): va=Divisors(a) vb=Divisors(b) if(va[3]!=vb[3]): return-1 minOperations=abs(va[0]-vb[0])+abs(va[1]-vb[1])+abs(va[2]-vb[2]) return minOperations if __name__=='__main__' : a=14 b=28 print(MinOperations(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( a := 14 ; b := 28 ; execute (MinOperations(a, b))->display() ) else skip; operation Divisors(x : OclAny) : OclAny pre: true post: true activity: var c : int := 0 ; var v : Sequence := Sequence{} ; while (x mod 2 = 0) do ( c := c + 1 ; x := x / 2) ; execute ((c) : v) ; c := 0 ; while (x mod 3 = 0) do ( c := c + 1 ; x := x / 3) ; execute ((c) : v) ; c := 0 ; while (x mod 7 = 0) do ( c := c + 1 ; x := x / 7) ; execute ((c) : v) ; execute ((x) : v) ; return v; operation MinOperations(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var va : OclAny := Divisors(a) ; var vb : OclAny := Divisors(b) ; if (va[3+1] /= vb[3+1]) then ( return -1 ) else skip ; var minOperations : double := (va->first() - vb->first())->abs() + (va[1+1] - vb[1+1])->abs() + (va[2+1] - vb[2+1])->abs() ; return minOperations; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): b,p,f=map(int,input().split()) h,c=map(int,input().split()) b=b//2 if b<1 : print(0) else : m=max(h,c) if m==h : q=min(b,p) q*=m b-=p if b>0 : x=min(b,f) x*=c else : x=0 else : q=min(b,f) q*=m b-=f if b>0 : x=min(b,p) x*=h else : x=0 print(q+x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var b : OclAny := null; var p : OclAny := null; var f : OclAny := null; Sequence{b,p,f} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h : OclAny := null; var c : OclAny := null; Sequence{h,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : int := b div 2 ; if b < 1 then ( execute (0)->display() ) else ( var m : OclAny := Set{h, c}->max() ; if m = h then ( var q : OclAny := Set{b, p}->min() ; q := q * m ; b := b - p ; if b > 0 then ( var x : OclAny := Set{b, f}->min() ; x := x * c ) else ( x := 0 ) ) else ( q := Set{b, f}->min() ; q := q * m ; b := b - f ; if b > 0 then ( x := Set{b, p}->min() ; x := x * h ) else ( x := 0 ) ) ; execute (q + x)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) u=0 if n % 2050!=0 : print(-1) else : while n>=2050 : x=2050 while x<=n : x*=10 x//=10 u+=1 n-=x print(u) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var u : int := 0 ; if n mod 2050 /= 0 then ( execute (-1)->display() ) else ( while n >= 2050 do ( var x : int := 2050 ; while (x->compareTo(n)) <= 0 do ( x := x * 10) ; x := x div 10 ; u := u + 1 ; n := n - x) ; execute (u)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from audioop import reverse from cmath import* from math import* from decimal import* from collections import* import sys def _input(): return map(int,input().split()) def _list(): return list(map(int,input().split())) def _int(): return int(input()) def solves(): a,b,c=_input() c1,c2=_input() if c1toInteger() ; for _anon : Integer.subrange(0, t-1) do ( solves()); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation _list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation _int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation solves() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := _input() ; var c1 : OclAny := null; var c2 : OclAny := null; Sequence{c1,c2} := _input() ; if (c1->compareTo(c2)) < 0 then ( var c1 : OclAny := null; var c2 : OclAny := null; Sequence{c1,c2} := Sequence{c2,c1} ; var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := Sequence{c,b} ) else skip ; var cur : int := 0 ; cur := Set{a div 2, b}->min() ; a := a - cur * 2 ; var cur1 : OclAny := Set{a div 2, c}->min() ; a := a - cur1 * 2 ; c := c - cur1 ; execute (c1 * cur + c2 * cur1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) hcount,ccount=0,0 for i in range(0,t): arr1=[int(x)for x in input().split()] arr2=[int(x)for x in input().split()] b,p,f=arr1[0],arr1[1],arr1[2] h,c=arr2[0],arr2[1] if h>=c : if b==1 : hcount,ccount=0,0 if pf : ccount=f else : ccount=b//2-p elif p>=b//2 : hcount=b//2 else : if b==1 : hcount,ccount=0,0 if fp : hcount=p else : hcount=b//2-f elif f>=b//2 : ccount=b//2 print(hcount*h+ccount*c) hcount,ccount=0,0 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var hcount : OclAny := null; var ccount : OclAny := null; Sequence{hcount,ccount} := Sequence{0,0} ; for i : Integer.subrange(0, t-1) do ( var arr1 : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var arr2 : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var b : OclAny := null; var p : OclAny := null; var f : OclAny := null; Sequence{b,p,f} := Sequence{arr1->first(),arr1[1+1],arr1[2+1]} ; var h : OclAny := null; var c : OclAny := null; Sequence{h,c} := Sequence{arr2->first(),arr2[1+1]} ; if (h->compareTo(c)) >= 0 then ( if b = 1 then ( var hcount : OclAny := null; var ccount : OclAny := null; Sequence{hcount,ccount} := Sequence{0,0} ) else skip ; if (p->compareTo(b div 2)) < 0 then ( var hcount : OclAny := p ; if (b div 2 - p->compareTo(f)) > 0 then ( var ccount : OclAny := f ) else ( ccount := b div 2 - p ) ) else (if (p->compareTo(b div 2)) >= 0 then ( hcount := b div 2 ) else skip) ) else ( if b = 1 then ( Sequence{hcount,ccount} := Sequence{0,0} ) else skip ; if (f->compareTo(b div 2)) < 0 then ( ccount := f ; if (b div 2 - f->compareTo(p)) > 0 then ( hcount := p ) else ( hcount := b div 2 - f ) ) else (if (f->compareTo(b div 2)) >= 0 then ( ccount := b div 2 ) else skip) ) ; execute (hcount * h + ccount * c)->display() ; Sequence{hcount,ccount} := Sequence{0,0}); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) n,=R() for _ in[0]*n : b,*a=R();(h,p),(c,f)=sorted(zip(R(),a)); m=min(b//2,f); print(m*c+min(p,b//2-m)*h) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,)} := R->apply() ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, n) do ( var b : OclAny := null; var a : OclAny := null; Sequence{b,a} := R->apply(); var Sequence{h, p} : OclAny := null; var Sequence{c, f} : OclAny := null; Sequence{Sequence{h, p},Sequence{c, f}} := Integer.subrange(1, R->apply()->size())->collect( _indx | Sequence{R->apply()->at(_indx), a->at(_indx)} )->sort(); var m : OclAny := Set{b div 2, f}->min(); execute (m * c + Set{p, b div 2 - m}->min() * h)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) for _ in range(a): b,p,f=map(int,input().split()) h,c=map(int,input().split()) if(b>1): if(h>c): k=0 sum=0 while(b>1 and p>0): k+=1 b-=2 p-=1 sum+=k*h k=0 while(b>1 and f>0): k+=1 b-=2 f-=1 sum+=k*c print(sum) else : k=0 sum=0 while(b>1 and f>0): k+=1 b-=2 f-=1 sum+=k*c k=0 while(b>1 and p>0): k+=1 b-=2 p-=1 sum+=k*h print(sum) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, a-1) do ( var b : OclAny := null; var p : OclAny := null; var f : OclAny := null; Sequence{b,p,f} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h : OclAny := null; var c : OclAny := null; Sequence{h,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (b > 1) then ( if ((h->compareTo(c)) > 0) then ( var k : int := 0 ; var sum : int := 0 ; while (b > 1 & p > 0) do ( k := k + 1 ; b := b - 2 ; p := p - 1) ; sum := sum + k * h ; k := 0 ; while (b > 1 & f > 0) do ( k := k + 1 ; b := b - 2 ; f := f - 1) ; sum := sum + k * c ; execute (sum)->display() ) else ( k := 0 ; sum := 0 ; while (b > 1 & f > 0) do ( k := k + 1 ; b := b - 2 ; f := f - 1) ; sum := sum + k * c ; k := 0 ; while (b > 1 & p > 0) do ( k := k + 1 ; b := b - 2 ; p := p - 1) ; sum := sum + k * h ; execute (sum)->display() ) ) else ( execute (0)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy x=['Front','Right','Back','Left'] y=['Top','Front','Bottom','Back'] z=['Top','Left','Bottom','Right'] def turn(dice,direction): turned_dice=copy.deepcopy(dice) if direction=='Right' : for i in range(4): turned_dice[x[i]]=dice[x[(i+1)% 4]] if direction=='Left' : for i in range(4): turned_dice[x[i]]=dice[x[(i-1)% 4]] if direction=='North' : for i in range(4): turned_dice[y[i]]=dice[y[(i+1)% 4]] if direction=='South' : for i in range(4): turned_dice[y[i]]=dice[y[(i-1)% 4]] if direction=='East' : for i in range(4): turned_dice[z[i]]=dice[z[(i+1)% 4]] if direction=='West' : for i in range(4): turned_dice[z[i]]=dice[z[(i-1)% 4]] return turned_dice if __name__=='__main__' : while True : n=int(input()) if n==0 : break dice={'Top' : 1,'Front' : 2,'Right' : 3,'Left' : 4,'Back' : 5,'Bottom' : 6} ret=1 for i in range(n): dice=turn(dice,input()) ret+=dice['Top'] print(ret) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : Sequence := Sequence{'Front'}->union(Sequence{'Right'}->union(Sequence{'Back'}->union(Sequence{ 'Left' }))) ; var y : Sequence := Sequence{'Top'}->union(Sequence{'Front'}->union(Sequence{'Bottom'}->union(Sequence{ 'Back' }))) ; var z : Sequence := Sequence{'Top'}->union(Sequence{'Left'}->union(Sequence{'Bottom'}->union(Sequence{ 'Right' }))) ; skip ; if __name__ = '__main__' then ( while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; dice := Map{ 'Top' |-> 1 }->union(Map{ 'Front' |-> 2 }->union(Map{ 'Right' |-> 3 }->union(Map{ 'Left' |-> 4 }->union(Map{ 'Back' |-> 5 }->union(Map{ 'Bottom' |-> 6 }))))) ; var ret : int := 1 ; for i : Integer.subrange(0, n-1) do ( dice := turn(dice, (OclFile["System.in"]).readLine()) ; ret := ret + dice->at('Top')) ; execute (ret)->display()) ) else skip; operation turn(dice : OclAny, direction : OclAny) : OclAny pre: true post: true activity: var turned_dice : OclAny := copy.deepcopy(dice) ; if direction = 'Right' then ( for i : Integer.subrange(0, 4-1) do ( turned_dice[x[i+1]+1] := dice[x[(i + 1) mod 4+1]+1]) ) else skip ; if direction = 'Left' then ( for i : Integer.subrange(0, 4-1) do ( turned_dice[x[i+1]+1] := dice[x[(i - 1) mod 4+1]+1]) ) else skip ; if direction = 'North' then ( for i : Integer.subrange(0, 4-1) do ( turned_dice[y[i+1]+1] := dice[y[(i + 1) mod 4+1]+1]) ) else skip ; if direction = 'South' then ( for i : Integer.subrange(0, 4-1) do ( turned_dice[y[i+1]+1] := dice[y[(i - 1) mod 4+1]+1]) ) else skip ; if direction = 'East' then ( for i : Integer.subrange(0, 4-1) do ( turned_dice[z[i+1]+1] := dice[z[(i + 1) mod 4+1]+1]) ) else skip ; if direction = 'West' then ( for i : Integer.subrange(0, 4-1) do ( turned_dice[z[i+1]+1] := dice[z[(i - 1) mod 4+1]+1]) ) else skip ; return turned_dice; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Dice : def __init__(self): self.omote=1 self.sita=2 self.migi=3 self.ue=5 self.hidari=4 self.ura=6 def North(self): self.omote,self.ue,self.ura,self.sita=self.sita,self.omote,self.ue,self.ura def East(self): self.omote,self.hidari,self.ura,self.migi=self.hidari,self.ura,self.migi,self.omote def West(self): self.omote,self.migi,self.ura,self.hidari=self.migi,self.ura,self.hidari,self.omote def South(self): self.omote,self.ue,self.ura,self.sita=self.ue,self.ura,self.sita,self.omote def Right(self): self.sita,self.migi,self.ue,self.hidari=self.migi,self.ue,self.hidari,self.sita def Left(self): self.sita,self.hidari,self.ue,self.migi=self.hidari,self.ue,self.migi,self.sita n=int(input()) while(n!=0): sum=1 dice=Dice() dice_def={"North" : dice.North,"East" : dice.East,"South" : dice.South,"West" : dice.West,"Right" : dice.Right,"Left" : dice.Left} for i in range(n): dice_def[input().strip()]() sum+=dice.omote print(sum) n=int(input()) ------------------------------------------------------------ OCL File: --------- class Dice { static operation newDice() : Dice pre: true post: Dice->exists( _x | result = _x ); attribute omote : int := 1; attribute sita : int := 2; attribute migi : int := 3; attribute ue : int := 5; attribute hidari : int := 4; attribute ura : int := 6; operation initialise() : Dice pre: true post: true activity: self.omote := 1 ; self.sita := 2 ; self.migi := 3 ; self.ue := 5 ; self.hidari := 4 ; self.ura := 6; return self; operation North() pre: true post: true activity: var self.omote : OclAny := null; var self.ue : OclAny := null; var self.ura : OclAny := null; var self.sita : OclAny := null; Sequence{self.omote,self.ue,self.ura,self.sita} := Sequence{self.sita,self.omote,self.ue,self.ura}; operation East() pre: true post: true activity: var self.omote : OclAny := null; var self.hidari : OclAny := null; var self.ura : OclAny := null; var self.migi : OclAny := null; Sequence{self.omote,self.hidari,self.ura,self.migi} := Sequence{self.hidari,self.ura,self.migi,self.omote}; operation West() pre: true post: true activity: var self.omote : OclAny := null; var self.migi : OclAny := null; var self.ura : OclAny := null; var self.hidari : OclAny := null; Sequence{self.omote,self.migi,self.ura,self.hidari} := Sequence{self.migi,self.ura,self.hidari,self.omote}; operation South() pre: true post: true activity: var self.omote : OclAny := null; var self.ue : OclAny := null; var self.ura : OclAny := null; var self.sita : OclAny := null; Sequence{self.omote,self.ue,self.ura,self.sita} := Sequence{self.ue,self.ura,self.sita,self.omote}; operation Right() pre: true post: true activity: var self.sita : OclAny := null; var self.migi : OclAny := null; var self.ue : OclAny := null; var self.hidari : OclAny := null; Sequence{self.sita,self.migi,self.ue,self.hidari} := Sequence{self.migi,self.ue,self.hidari,self.sita}; operation Left() pre: true post: true activity: var self.sita : OclAny := null; var self.hidari : OclAny := null; var self.ue : OclAny := null; var self.migi : OclAny := null; Sequence{self.sita,self.hidari,self.ue,self.migi} := Sequence{self.hidari,self.ue,self.migi,self.sita}; } class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (n /= 0) do ( var sum : int := 1 ; var dice : Dice := (Dice.newDice()).initialise() ; var dice_def : Map := Map{ "North" |-> dice.North }->union(Map{ "East" |-> dice.East }->union(Map{ "South" |-> dice.South }->union(Map{ "West" |-> dice.West }->union(Map{ "Right" |-> dice.Right }->union(Map{ "Left" |-> dice.Left }))))) ; for i : Integer.subrange(0, n-1) do ((expr (atom (name dice_def)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name strip) (arguments ( ))))))))) ])) (trailer (arguments ( )))) ; sum := sum + dice.omote) ; execute (sum)->display() ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys e=sys.stdin.readline p={'N' :(1,5,2,3,0,4),'E' :(3,1,0,5,4,2),'W' :(2,1,5,0,4,3),'S' :(4,0,2,3,5,1),'R' :(0,2,4,1,3,5),'L' :(0,3,1,4,2,5)} for n in iter(e,'0\n'): a=1 ; s=[1,2,3,4,5,6] for _ in[0]*int(n): s=[s[i]for i in p[e()[0]]] a+=s[0] print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var e : OclAny := (OclFile["System.in"]).readline ; var p : Map := Map{ 'N' |-> Sequence{1, 5, 2, 3, 0, 4} }->union(Map{ 'E' |-> Sequence{3, 1, 0, 5, 4, 2} }->union(Map{ 'W' |-> Sequence{2, 1, 5, 0, 4, 3} }->union(Map{ 'S' |-> Sequence{4, 0, 2, 3, 5, 1} }->union(Map{ 'R' |-> Sequence{0, 2, 4, 1, 3, 5} }->union(Map{ 'L' |-> Sequence{0, 3, 1, 4, 2, 5} }))))) ; for n : OclIterator.newOclIterator_Sequence(e, '0 ') do ( var a : int := 1; var s : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))))) ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + ((n)))->toInteger()) do ( s := p[e()->first()+1]->select(i | true)->collect(i | (s[i+1])) ; a := a + s->first()) ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys f=sys.stdin def North(d): d=[d[1]]+[7-d[0]]+[d[2]] return d def East(d): d=[7-d[2]]+[d[1]]+[d[0]] return d def South(d): d=[7-d[1]]+[d[0]]+[d[2]] return d def West(d): d=[d[2]]+[d[1]]+[7-d[0]] return d def Right(d): d=[d[0]]+[d[2]]+[7-d[1]] return d def Left(d): d=[d[0]]+[7-d[2]]+[d[1]] return d while True : n=int(f.readline()) if n==0 : break dice=[1,2,3] result=1 for _ in range(n): direction=f.readline().rstrip() if direction=='North' : dice=North(dice) if direction=='East' : dice=East(dice) if direction=='South' : dice=South(dice) if direction=='West' : dice=West(dice) if direction=='Right' : dice=Right(dice) if direction=='Left' : dice=Left(dice) result+=dice[0] print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var f : OclFile := OclFile["System.in"] ; skip ; skip ; skip ; skip ; skip ; skip ; while true do ( var n : int := ("" + ((f.readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var dice : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; var result : int := 1 ; for _anon : Integer.subrange(0, n-1) do ( var direction : OclAny := f.readLine().rstrip() ; if direction = 'North' then ( dice := North(dice) ) else skip ; if direction = 'East' then ( dice := East(dice) ) else skip ; if direction = 'South' then ( dice := South(dice) ) else skip ; if direction = 'West' then ( dice := West(dice) ) else skip ; if direction = 'Right' then ( dice := Right(dice) ) else skip ; if direction = 'Left' then ( dice := Left(dice) ) else skip ; result := result + dice->first()) ; execute (result)->display()); operation North(d : OclAny) : OclAny pre: true post: true activity: d := Sequence{ d[1+1] }->union(Sequence{ 7 - d->first() })->union(Sequence{ d[2+1] }) ; return d; operation East(d : OclAny) : OclAny pre: true post: true activity: d := Sequence{ 7 - d[2+1] }->union(Sequence{ d[1+1] })->union(Sequence{ d->first() }) ; return d; operation South(d : OclAny) : OclAny pre: true post: true activity: d := Sequence{ 7 - d[1+1] }->union(Sequence{ d->first() })->union(Sequence{ d[2+1] }) ; return d; operation West(d : OclAny) : OclAny pre: true post: true activity: d := Sequence{ d[2+1] }->union(Sequence{ d[1+1] })->union(Sequence{ 7 - d->first() }) ; return d; operation Right(d : OclAny) : OclAny pre: true post: true activity: d := Sequence{ d->first() }->union(Sequence{ d[2+1] })->union(Sequence{ 7 - d[1+1] }) ; return d; operation Left(d : OclAny) : OclAny pre: true post: true activity: d := Sequence{ d->first() }->union(Sequence{ 7 - d[2+1] })->union(Sequence{ d[1+1] }) ; return d; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=1000001 c=0 n=0 m=0 a=0 b=0 def dfs(a,b,v,vis): global c vis[a]=1 c+=1 for i in v[a]: if(vis[i]==0 and i!=b): dfs(i,b,v,vis) def Calculate(v): global c vis=[0 for i in range(n+1)] c=0 dfs(a,b,v,vis) ans1=n-c-1 vis=[0 for i in range(len(vis))] c=0 dfs(b,a,v,vis) ans2=n-c-1 print(ans1*ans2) if __name__=='__main__' : n=7 m=7 a=3 b=5 edges=[[1,2],[2,3],[3,4],[4,5],[5,6],[6,7],[7,5]] v=[[]for i in range(n+1)] for i in range(m): v[edges[i][0]].append(edges[i][1]) v[edges[i][1]].append(edges[i][0]) Calculate(v) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute c : OclAny; attribute c : OclAny; operation initialise() pre: true post: true activity: var N : int := 1000001 ; var c : int := 0 ; var n : int := 0 ; var m : int := 0 ; var a : int := 0 ; var b : int := 0 ; skip ; skip ; if __name__ = '__main__' then ( n := 7 ; m := 7 ; a := 3 ; b := 5 ; var edges : Sequence := Sequence{Sequence{1}->union(Sequence{ 2 })}->union(Sequence{Sequence{2}->union(Sequence{ 3 })}->union(Sequence{Sequence{3}->union(Sequence{ 4 })}->union(Sequence{Sequence{4}->union(Sequence{ 5 })}->union(Sequence{Sequence{5}->union(Sequence{ 6 })}->union(Sequence{Sequence{6}->union(Sequence{ 7 })}->union(Sequence{ Sequence{7}->union(Sequence{ 5 }) })))))) ; v := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, m-1) do ((expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))) ; (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))) ; Calculate(v) ) else skip; operation dfs(a : OclAny, b : OclAny, v : OclAny, vis : OclAny) pre: true post: true activity: skip ; vis[a+1] := 1 ; c := c + 1 ; for i : v[a+1] do ( if (vis[i+1] = 0 & i /= b) then ( dfs(i, b, v, vis) ) else skip); operation Calculate(v : OclAny) pre: true post: true activity: skip ; vis := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; c := 0 ; dfs(a, b, v, vis) ; var ans1 : double := n - c - 1 ; vis := Integer.subrange(0, (vis)->size()-1)->select(i | true)->collect(i | (0)) ; c := 0 ; dfs(b, a, v, vis) ; var ans2 : double := n - c - 1 ; execute (ans1 * ans2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class diceClass : def __init__(self,valuelist): self.valuelist=valuelist self.t=valuelist[0] self.s=valuelist[1] self.e=valuelist[2] self.w=valuelist[3] self.n=valuelist[4] self.b=valuelist[5] def print(self): print('t={0},s={1},e={2},w={3},n={4},b={5}'.format(self.t,self.s,self.e,self.w,self.n,self.b)) def throw(self,direction): if direction=='North' : self.t,self.s,self.b,self.n=self.s,self.b,self.n,self.t elif direction=='South' : self.t,self.s,self.b,self.n=self.n,self.t,self.s,self.b elif direction=='West' : self.t,self.e,self.b,self.w=self.e,self.b,self.w,self.t elif direction=='East' : self.t,self.e,self.b,self.w=self.w,self.t,self.e,self.b elif direction=='Right' : self.s,self.e,self.w,self.n=self.e,self.n,self.s,self.w elif direction=='Left' : self.s,self.e,self.w,self.n=self.w,self.s,self.n,self.e while True : n=int(input()) if n==0 : break A=[1,2,3,4,5,6] dice=diceClass(A) tsum=dice.t for i in range(n): s=input().strip() dice.throw(s) tsum=tsum+dice.t print(tsum) ------------------------------------------------------------ OCL File: --------- class diceClass { static operation newdiceClass() : diceClass pre: true post: diceClass->exists( _x | result = _x ); attribute valuelist : OclAny := valuelist; attribute t : OclAny := valuelist->first(); attribute s : OclAny := valuelist[1+1]; attribute e : OclAny := valuelist[2+1]; attribute w : OclAny := valuelist[3+1]; attribute n : OclAny := valuelist[4+1]; attribute b : OclAny := valuelist[5+1]; operation initialise(valuelist : OclAny) : diceClass pre: true post: true activity: self.valuelist := valuelist ; self.t := valuelist->first() ; self.s := valuelist[1+1] ; self.e := valuelist[2+1] ; self.w := valuelist[3+1] ; self.n := valuelist[4+1] ; self.b := valuelist[5+1]; return self; (funcdef def name print ( (typedargslist (def_parameters (def_parameter (named_parameter (name self))))) ) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 't={0},s={1},e={2},w={3},n={4},b={5}') (trailer . (name format) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name self)) (trailer . (name t))))))) , (argument (test (logical_test (comparison (expr (atom (name self)) (trailer . (name s))))))) , (argument (test (logical_test (comparison (expr (atom (name self)) (trailer . (name e))))))) , (argument (test (logical_test (comparison (expr (atom (name self)) (trailer . (name w))))))) , (argument (test (logical_test (comparison (expr (atom (name self)) (trailer . (name n))))))) , (argument (test (logical_test (comparison (expr (atom (name self)) (trailer . (name b)))))))) ))))))))) )))))))))))))) operation throw(direction : OclAny) pre: true post: true activity: if direction = 'North' then ( var self.t : OclAny := null; var self.s : OclAny := null; var self.b : OclAny := null; var self.n : OclAny := null; Sequence{self.t,self.s,self.b,self.n} := Sequence{self.s,self.b,self.n,self.t} ) else (if direction = 'South' then ( var self.t : OclAny := null; var self.s : OclAny := null; var self.b : OclAny := null; var self.n : OclAny := null; Sequence{self.t,self.s,self.b,self.n} := Sequence{self.n,self.t,self.s,self.b} ) else (if direction = 'West' then ( var self.t : OclAny := null; var self.e : OclAny := null; var self.b : OclAny := null; var self.w : OclAny := null; Sequence{self.t,self.e,self.b,self.w} := Sequence{self.e,self.b,self.w,self.t} ) else (if direction = 'East' then ( var self.t : OclAny := null; var self.e : OclAny := null; var self.b : OclAny := null; var self.w : OclAny := null; Sequence{self.t,self.e,self.b,self.w} := Sequence{self.w,self.t,self.e,self.b} ) else (if direction = 'Right' then ( var self.s : OclAny := null; var self.e : OclAny := null; var self.w : OclAny := null; var self.n : OclAny := null; Sequence{self.s,self.e,self.w,self.n} := Sequence{self.e,self.n,self.s,self.w} ) else (if direction = 'Left' then ( var self.s : OclAny := null; var self.e : OclAny := null; var self.w : OclAny := null; var self.n : OclAny := null; Sequence{self.s,self.e,self.w,self.n} := Sequence{self.w,self.s,self.n,self.e} ) else skip ) ) ) ) ) ; } class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var A : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))))) ; var dice : diceClass := (diceClass.newdiceClass()).initialise(A) ; var tsum : OclAny := dice.t ; for i : Integer.subrange(0, n-1) do ( var s : OclAny := input()->trim() ; dice.throw(s) ; tsum := tsum + dice.t) ; execute (tsum)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPerfectSquare(n): i=1 while(i*i<=n): if((n % i==0)and(n/i==i)): return True i=i+1 return False if __name__=="__main__" : n=36 if(isPerfectSquare(n)): print("Yes,it is a perfect square.") else : print("No,it is not a perfect square.") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 36 ; if (isPerfectSquare(n)) then ( execute ("Yes,it is a perfect square.")->display() ) else ( execute ("No,it is not a perfect square.")->display() ) ) else skip; operation isPerfectSquare(n : OclAny) : OclAny pre: true post: true activity: var i : int := 1 ; while ((i * i->compareTo(n)) <= 0) do ( if ((n mod i = 0) & (n / i = i)) then ( return true ) else skip ; i := i + 1) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) if(n % 2==1): print(7,end='') n-=3 while(n>0): print(1,end='') n-=2 print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n mod 2 = 1) then ( execute (7)->display() ; n := n - 3 ) else skip ; while (n > 0) do ( execute (1)->display() ; n := n - 2) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import io,os input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def main(t): n=int(input()) arr=list(map(int,input().split())) if n==1 : print(0) return num1=arr[n-1]-min(arr[: n-1]) num2=max(arr[1 :])-arr[0] num3=max([arr[i]-arr[i+1]for i in range(n-1)]) print(max(num1,num2,num3)) T=int(input()) t=1 while t<=T : main(t) t+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; skip ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; t := 1 ; while (t->compareTo(T)) <= 0 do ( main(t) ; t := t + 1); operation main(t : OclAny) pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = 1 then ( execute (0)->display() ; return ) else skip ; var num1 : double := arr[n - 1+1] - (arr.subrange(1,n - 1))->min() ; var num2 : double := (arr->tail())->max() - arr->first() ; var num3 : OclAny := (Integer.subrange(0, n - 1-1)->select(i | true)->collect(i | (arr[i+1] - arr[i + 1+1])))->max() ; execute (Set{num1, num2, num3}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: a=*map(int,s.split()),; print(max(max(a)-a[0],a[-1]-min(a),*(y-x for x,y in zip(a,a[-1 :]+a)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var a : OclAny := (testlist_star_expr (star_expr * (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name s)) (trailer . (name split) (arguments ( ))))))))) ))))) ,); execute (Set{(a)->max() - a->first(), a->last() - (a)->min(), (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (name x))))))) (comp_for for (exprlist (expr (atom (name x))) , (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))) :)) ]))) + (expr (atom (name a))))))))) )))))))) )))))))}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) arr=list(map(int,input().split()))[: n] res=max(arr[-1]-min(arr),max(arr)-arr[0]) for i in range(n): res=max(res,arr[i-1]-arr[i]) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ; var res : OclAny := Set{arr->last() - (arr)->min(), (arr)->max() - arr->first()}->max() ; for i : Integer.subrange(0, n-1) do ( res := Set{res, arr[i - 1+1] - arr[i+1]}->max()) ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from os.path import exists if exists("test.txt"): sys.stdin=open("test.txt","r") for _ in range(int(input())): n=int(input()) a=(list(map(int,input().split()))) if n==1 : print(0) continue x=max(a[1 :])-a[0] y=a[n-1]-min(a[: n-1]) z=(max(a[i]-a[i+1]for i in range(n-1))) print(max(x,y,z)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if exists("test.txt") then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("test.txt")) ) else skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; if n = 1 then ( execute (0)->display() ; continue ) else skip ; var x : double := (a->tail())->max() - a->first() ; var y : double := a[n - 1+1] - (a.subrange(1,n - 1))->min() ; var z : OclAny := (((argument (test (logical_test (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) )))))))))->max()) ; execute (Set{x, y, z}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): n=int(input()) lst=[int(i)for i in input().split()] if(len(lst)==1): print(0) else : A=max(lst[1 :])-lst[0] B=lst[-1]-min(lst[:-1]) C=max(lst[i]-lst[(i+1)% n]for i in range(n)) print(max(A,B,C)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if ((lst)->size() = 1) then ( execute (0)->display() ) else ( var A : double := (lst->tail())->max() - lst->first() ; var B : double := lst->last() - (lst->front())->min() ; var C : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) ))) % (expr (atom (name n))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->max() ; execute (Set{A, B, C}->max())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p=1.0 f=1.0 def e(x,n): global p,f if(n==0): return 1 r=e(x,n-1) p=p*x f=f*n return(r+p/f) x=4 n=15 print(e(x,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute p : OclAny; attribute f : OclAny; operation initialise() pre: true post: true activity: var p : double := 1.0 ; var f : double := 1.0 ; skip ; x := 4 ; n := 15 ; execute (e(x, n))->display(); operation e(x : OclAny, n : OclAny) : OclAny pre: true post: true activity: skip; skip ; if (n = 0) then ( return 1 ) else skip ; var r : OclAny := e(x, n - 1) ; p := p * x ; f := f * n ; return (r + p / f); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) nums=list(map(int,input().split())) print("YES" if len(set(nums))==len(nums)else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nums : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (if (Set{}->union((nums)))->size() = (nums)->size() then "YES" else "NO" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def l(n): return len(str(n)) def el(n): return int(str(n)[1 :]) def first(n): return int(str(n)[0]) def maxima(n): if l(n)==1 : return n elif first(n)==1 : return max(9**(l(n)-1),first(n)*maxima(el(n))) else : return max((first(n)-1)*9**(l(n)-1),first(n)*maxima(el(n))) n=int(input()) print(maxima(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (maxima(n))->display(); operation l(n : OclAny) : OclAny pre: true post: true activity: return (("" + ((n))))->size(); operation el(n : OclAny) : OclAny pre: true post: true activity: return ("" + ((OclType["String"](n)->tail())))->toInteger(); operation first(n : OclAny) : OclAny pre: true post: true activity: return ("" + ((OclType["String"](n)->first())))->toInteger(); operation maxima(n : OclAny) : OclAny pre: true post: true activity: if l(n) = 1 then ( return n ) else (if first(n) = 1 then ( return Set{(9)->pow((l(n) - 1)), first(n) * maxima(el(n))}->max() ) else ( return Set{(first(n) - 1) * (9)->pow((l(n) - 1)), first(n) * maxima(el(n))}->max() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy import random import bisect import fractions import math import sys import collections mod=10**9+7 sys.setrecursionlimit(mod) d=collections.deque() def LI(): return list(map(int,sys.stdin.readline().split())) N=int(input()) A=LI() ans=1 c=collections.Counter(A) for key in c.keys(): if c[key]>1 : ans=0 break if ans : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; sys.setrecursionlimit(mod) ; var d : Sequence := () ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : OclAny := LI() ; var ans : int := 1 ; var c : OclAny := .Counter(A) ; for key : c.keys() do ( if c[key+1] > 1 then ( ans := 0 ; break ) else skip) ; if ans then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify import sys,bisect,math,itertools,pprint,fractions sys.setrecursionlimit(10**8) mod=10**9+7 INF=float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int,sys.stdin.readline().split())) n=inp() a=inpl() print('YES' if len(a)==len(set(a))else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; var mod : double := (10)->pow(9) + 7 ; var INF : double := ("" + (('inf')))->toReal() ; skip ; skip ; var n : OclAny := inp() ; var a : OclAny := inpl() ; execute (if (a)->size() = (Set{}->union((a)))->size() then 'YES' else 'NO' endif)->display(); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inpl() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solv(A): A=sorted(A) a0=A[0] for a in A[1 :]: if a0==a : return "NO" a0=a return "YES" if __name__=="__main__" : N=int(input()) A=map(int,input().split()) ans=solv(A) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; A := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : OclAny := solv(A) ; execute (ans)->display() ) else skip; operation solv(A : OclAny) : OclAny pre: true post: true activity: A := A->sort() ; var a0 : OclAny := A->first() ; for a : A->tail() do ( if a0 = a then ( return "NO" ) else skip ; a0 := a) ; return "YES"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import os import random import re import sys from math import gcd from math import sqrt from collections import Counter for _ in range(int(input())): n=int(input()) if n % 2==0 : print('1'*(n//2)) else : print('7'+'1'*((n-3)//2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( execute (StringLib.nCopies('1', (n div 2)))->display() ) else ( execute ('7' + StringLib.nCopies('1', ((n - 3) div 2)))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- kazu1=int(input()) kazu2=list(map(int,input().split())) def has_duplicates(seq): return len(seq)==len(set(seq)) if has_duplicates(kazu2): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var kazu1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var kazu2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; if has_duplicates(kazu2) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); operation has_duplicates(seq : OclAny) : OclAny pre: true post: true activity: return (seq)->size() = (Set{}->union((seq)))->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def successiveChange(arr,N): result=0 ; var1=arr[0]; var2=arr[1]; result=float(var1+var2+(float(var1*var2)/100)); for i in range(2,N): result=(result+arr[i]+(float(result*arr[i])/100)); return result ; arr=[10,20,30,10]; N=len(arr); result=successiveChange(arr,N); print("Percentage change is=%.2f" %(result),"%"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{10}->union(Sequence{20}->union(Sequence{30}->union(Sequence{ 10 }))); ; N := (arr)->size(); ; result := successiveChange(arr, N); ; execute (StringLib.format("Percentage change is=%.2f",(result)))->display();; operation successiveChange(arr : OclAny, N : OclAny) pre: true post: true activity: var result : int := 0; ; var var1 : OclAny := arr->first(); ; var var2 : OclAny := arr[1+1]; ; result := ("" + ((var1 + var2 + (("" + ((var1 * var2)))->toReal() / 100))))->toReal(); ; for i : Integer.subrange(2, N-1) do ( result := (result + arr[i+1] + (("" + ((result * arr[i+1])))->toReal() / 100));) ; return result;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkPalindrome(s): for i in range(len(s)): if(s[i]!=s[len(s)-i-1]): return False return True def CheckOdd(s): n=len(s) for i in range(n): x="" for j in range(i,n): x+=s[j] if(len(x)% 2==0 and checkPalindrome(x)==True): return False return True s="geeksforgeeks" if(CheckOdd(s)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; s := "geeksforgeeks" ; if (CheckOdd(s)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); operation checkPalindrome(s : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, (s)->size()-1) do ( if (s[i+1] /= s[(s)->size() - i - 1+1]) then ( return false ) else skip) ; return true; operation CheckOdd(s : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; for i : Integer.subrange(0, n-1) do ( var x : String := "" ; for j : Integer.subrange(i, n-1) do ( x := x + s[j+1] ; if ((x)->size() mod 2 = 0 & checkPalindrome(x) = true) then ( return false ) else skip)) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairs(a,n): mn=+2147483647 mx=-2147483648 for i in range(n): mn=min(mn,a[i]) mx=max(mx,a[i]) c1=0 c2=0 for i in range(n): if(a[i]==mn): c1+=1 if(a[i]==mx): c2+=1 if(mn==mx): return n*(n-1)//2 else : return c1*c2 a=[3,2,1,1,3] n=len(a) print(countPairs(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{3}->union(Sequence{2}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 3 })))) ; n := (a)->size() ; execute (countPairs(a, n))->display(); operation countPairs(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var mn : int := 2147483647 ; var mx : int := -2147483648 ; for i : Integer.subrange(0, n-1) do ( mn := Set{mn, a[i+1]}->min() ; mx := Set{mx, a[i+1]}->max()) ; var c1 : int := 0 ; var c2 : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] = mn) then ( c1 := c1 + 1 ) else skip ; if (a[i+1] = mx) then ( c2 := c2 + 1 ) else skip) ; if (mn = mx) then ( return n * (n - 1) div 2 ) else ( return c1 * c2 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def distinctCount(arr,n): count=n ; i=0 ; j=n-1 ; sum=0 ; while(iunion(Sequence{-1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 1 })))); ; n := (arr)->size(); ; execute ("Count of absolute distinct values : ")->display();; operation distinctCount(arr : OclAny, n : OclAny) pre: true post: true activity: var count : OclAny := n; ; var i : int := 0; var j : double := n - 1; var sum : int := 0; ; while ((i->compareTo(j)) < 0) do ( while (i /= j & arr[i+1] = arr[i + 1+1]) do ( count := count - 1; ; i := i + 1;) ; while (i /= j & arr[j+1] = arr[j - 1+1]) do ( count := count - 1; ; j := j - 1;) ; if (i = j) then ( break; ) else skip ; sum := arr[i+1] + arr[j+1]; ; if (sum = 0) then ( count := count - 1; ; i := i + 1; ; j := j - 1; ) else (if (sum < 0) then ( i := i + 1; ) else ( j := j - 1; ) ) ) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ii=lambda : int(input()) mi=lambda : map(int,input().split()) li=lambda : list(map(int,input().split())) INF=float('inf') v,e=mi() dp=[[float('inf')for i in range(v)]for j in range(v)] path=[[]for i in range(v)] for i in range(e): s,t,d=mi() path[s].append((t,d)) dp[s][t]=d for i in range(v): dp[i][i]=0 for k in range(v): for i in range(v): for j in range(v): dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]) for i in range(v): if dp[i][i]<0 : print('NEGATIVE CYCLE') break else : for i in range(v): for j in range(v): c=dp[i][j] if c==INF : c='INF' if j!=v-1 : print(c,end=" ") else : print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ii : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var mi : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var li : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var INF : double := ("" + (('inf')))->toReal() ; var v : OclAny := null; var e : OclAny := null; Sequence{v,e} := mi->apply() ; var dp : Sequence := Integer.subrange(0, v-1)->select(j | true)->collect(j | (Integer.subrange(0, v-1)->select(i | true)->collect(i | (("" + (('inf')))->toReal())))) ; var path : Sequence := Integer.subrange(0, v-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, e-1) do ( var s : OclAny := null; var t : OclAny := null; var d : OclAny := null; Sequence{s,t,d} := mi->apply() ; (expr (atom (name path)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name t)))))) , (test (logical_test (comparison (expr (atom (name d))))))) )))))))) )))) ; dp[s+1][t+1] := d) ; for i : Integer.subrange(0, v-1) do ( dp[i+1][i+1] := 0) ; for k : Integer.subrange(0, v-1) do ( for i : Integer.subrange(0, v-1) do ( for j : Integer.subrange(0, v-1) do ( dp[i+1][j+1] := Set{dp[i+1][j+1], dp[i+1][k+1] + dp[k+1][j+1]}->min()))) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) < (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NEGATIVE CYCLE'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name c)))) == (comparison (expr (atom (name INF))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom 'INF')))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name j)))) != (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c))))))) , (argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom " "))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))))))))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=input()[:-1] x=len(n) if x==1 : print(n) else : c=int(n[0]) if c==1 : print(9**(x-1)) else : z=1 for i in range(x): z*=int(n[i]) for i in range(x): if int(n[i])==0 : continue d=int(n[i])-1 for j in range(i): d*=int(n[j]) d*=9**(x-i-1) z=max(z,d) print(z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := input()->front() ; var x : int := (n)->size() ; if x = 1 then ( execute (n)->display() ) else ( var c : int := ("" + ((n->first())))->toInteger() ; if c = 1 then ( execute ((9)->pow((x - 1)))->display() ) else ( var z : int := 1 ; for i : Integer.subrange(0, x-1) do ( z := z * ("" + ((n[i+1])))->toInteger()) ; for i : Integer.subrange(0, x-1) do ( if ("" + ((n[i+1])))->toInteger() = 0 then ( continue ) else skip ; var d : double := ("" + ((n[i+1])))->toInteger() - 1 ; for j : Integer.subrange(0, i-1) do ( d := d * ("" + ((n[j+1])))->toInteger()) ; d := d * (9)->pow((x - i - 1)) ; z := Set{z, d}->max()) ; execute (z)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict INF=999999999999999999999 def bellman_ford(G,n): d={} for i in range(n): d[i]={} for j in range(n): if i in G and j in G[i]: d[i][j]=G[i][j] else : d[i][j]=INF d[i][i]=0 for k in range(n): for i in range(n): for j in range(n): if d[i][k]==INF or d[k][j]==INF : continue if d[i][j]>d[i][k]+d[k][j]: d[i][j]=d[i][k]+d[k][j] return d G={} n,m=[int(v)for v in input().strip().split(' ')] for i in range(n): G[i]={} for _ in range(m): s,t,c=[int(v)for v in input().strip().split(' ')] G[s][t]=c d=bellman_ford(G,n) for i in range(n): if d[i][i]<0 : print("NEGATIVE CYCLE") exit() for i in range(n): print(" ".join([str(d[i][j])if d[i][j]!=INF else "INF" for j in range(n)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var INF : double := 999999999999999999999 ; skip ; G := Set{} ; var m : OclAny := null; Sequence{n,m} := input()->trim().split(' ')->select(v | true)->collect(v | (("" + ((v)))->toInteger())) ; for i : Integer.subrange(0, n-1) do ( G[i+1] := Set{}) ; for _anon : Integer.subrange(0, m-1) do ( var s : OclAny := null; var t : OclAny := null; var c : OclAny := null; Sequence{s,t,c} := input()->trim().split(' ')->select(v | true)->collect(v | (("" + ((v)))->toInteger())) ; G[s+1][t+1] := c) ; d := bellman_ford(G, n) ; for i : Integer.subrange(0, n-1) do ( if d[i+1][i+1] < 0 then ( execute ("NEGATIVE CYCLE")->display() ; exit() ) else skip) ; for i : Integer.subrange(0, n-1) do ( execute (StringLib.sumStringsWithSeparator((Integer.subrange(0, n-1)->select(j | true)->collect(j | (if d[i+1][j+1] /= INF then ("" + ((d[i+1][j+1]))) else "INF" endif))), " "))->display()); operation bellman_ford(G : OclAny, n : OclAny) : OclAny pre: true post: true activity: var d : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( d[i+1] := Set{} ; for j : Integer.subrange(0, n-1) do ( if (G)->includes(i) & (G[i+1])->includes(j) then ( d[i+1][j+1] := G[i+1][j+1] ) else ( d[i+1][j+1] := INF )) ; d[i+1][i+1] := 0) ; for k : Integer.subrange(0, n-1) do ( for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if d[i+1][k+1] = INF or d[k+1][j+1] = INF then ( continue ) else skip ; if (d[i+1][j+1]->compareTo(d[i+1][k+1] + d[k+1][j+1])) > 0 then ( d[i+1][j+1] := d[i+1][k+1] + d[k+1][j+1] ) else skip))) ; return d; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin from math import isinf def generate_adj_table(v_table,_init_adj_table): for each in v_table : start,end,weight=map(int,each) _init_adj_table[start][end]=weight return _init_adj_table def floyd(_adj_table): for k in v_range : for i in v_range : for j in v_range : _adj_table[i][j]=min(_adj_table[i][j],_adj_table[i][k]+_adj_table[k][j]) return _adj_table def solve(_after_table): negative=False for m in v_range : if _after_table[m][m]<0 : negative=True if negative : print('NEGATIVE CYCLE') return None else : for each in _after_table : print(' '.join(('INF' if isinf(ele)else str(ele)for ele in each))) return _after_table if __name__=='__main__' : _input=stdin.readlines() vertices,edges=map(int,_input[0].split()) info_list=map(lambda x : x.split(),_input[1 :]) v_range=range(vertices) init_adj_table=tuple([float('inf')]*vertices for _ in v_range) for n in v_range : init_adj_table[n][n]=0 adj_table=generate_adj_table(info_list,init_adj_table) after_table=floyd(adj_table) solve(after_table) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var _input : OclAny := stdin.readlines() ; var vertices : OclAny := null; var edges : OclAny := null; Sequence{vertices,edges} := (_input->first().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var info_list : Sequence := (_input->tail())->collect( _x | (lambda x : OclAny in (x.split()))->apply(_x) ) ; var v_range : Sequence := Integer.subrange(0, vertices-1) ; var init_adj_table : Sequence := ((argument (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name float)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'inf'))))))) )))))))) ])) * (expr (atom (name vertices))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name v_range)))))))) ; for n : v_range do ( init_adj_table[n+1][n+1] := 0) ; var adj_table : OclAny := generate_adj_table(info_list, init_adj_table) ; var after_table : OclAny := floyd(adj_table) ; solve(after_table) ) else skip; operation generate_adj_table(v_table : OclAny, _init_adj_table : OclAny) : OclAny pre: true post: true activity: for each : v_table do ( var start : OclAny := null; var end : OclAny := null; var weight : OclAny := null; Sequence{start,end,weight} := (each)->collect( _x | (OclType["int"])->apply(_x) ) ; _init_adj_table[start+1][end+1] := weight) ; return _init_adj_table; operation floyd(_adj_table : OclAny) : OclAny pre: true post: true activity: for k : v_range do ( for i : v_range do ( for j : v_range do ( _adj_table[i+1][j+1] := Set{_adj_table[i+1][j+1], _adj_table[i+1][k+1] + _adj_table[k+1][j+1]}->min()))) ; return _adj_table; operation solve(_after_table : OclAny) : OclAny pre: true post: true activity: var negative : boolean := false ; for m : v_range do ( if _after_table[m+1][m+1] < 0 then ( negative := true ) else skip) ; if negative then ( execute ('NEGATIVE CYCLE')->display() ; return null ) else ( for each : _after_table do ( execute (StringLib.sumStringsWithSeparator((Sequence{(testlist_comp (test (logical_test (comparison (expr (atom 'INF')))) if (logical_test (comparison (expr (atom (name isinf)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ele)))))))) )))))) else (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ele)))))))) )))))))) (comp_for for (exprlist (expr (atom (name ele)))) in (logical_test (comparison (expr (atom (name each)))))))}), ' '))->display()) ) ; return _after_table; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=2000000000 def read_adj_mat(): nv,ne=[int(x)for x in input().split()] A=[[0 if fr==to else INF for fr in range(nv)]for to in range(nv)] for _ in range(ne): s,t,d=[int(x)for x in input().split()] A[s][t]=d return A def get_shortest_paths(D): n=len(D) for to in range(n): for fr in range(n): here=D[fr][to] if here==INF : continue for to2 in range(n): here2=D[to][to2] if here2==INF : continue D[fr][to2]=min(D[fr][to2],here+here2) def print_result(D): for fr in range(len(D)): for to in range(len(D)): if to!=0 : print("",end="") if D[fr][to]==INF : print("INF",end="") else : print(D[fr][to],end="") print() def main(): D=read_adj_mat() get_shortest_paths(D) for d in[D[x][x]for x in range(len(D))]: if d<0 : print("NEGATIVE CYCLE") break else : print_result(D) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INF : int := 2000000000 ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation read_adj_mat() : OclAny pre: true post: true activity: var nv : OclAny := null; var ne : OclAny := null; Sequence{nv,ne} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var A : Sequence := Integer.subrange(0, nv-1)->select(to | true)->collect(to | (Integer.subrange(0, nv-1)->select(fr | true)->collect(fr | (if fr = to then 0 else INF endif)))) ; for _anon : Integer.subrange(0, ne-1) do ( var s : OclAny := null; var t : OclAny := null; var d : OclAny := null; Sequence{s,t,d} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; A[s+1][t+1] := d) ; return A; operation get_shortest_paths(D : OclAny) pre: true post: true activity: var n : int := (D)->size() ; for to : Integer.subrange(0, n-1) do ( for fr : Integer.subrange(0, n-1) do ( var here : OclAny := D[fr+1][to+1] ; if here = INF then ( continue ) else skip ; for to2 : Integer.subrange(0, n-1) do ( var here2 : OclAny := D[to+1][to2+1] ; if here2 = INF then ( continue ) else skip ; D[fr+1][to2+1] := Set{D[fr+1][to2+1], here + here2}->min()))); operation print_result(D : OclAny) pre: true post: true activity: for fr : Integer.subrange(0, (D)->size()-1) do ( for to : Integer.subrange(0, (D)->size()-1) do ( if to /= 0 then ( execute ("")->display() ) else skip ; if D[fr+1][to+1] = INF then ( execute ("INF")->display() ) else ( execute (D[fr+1][to+1])->display() )) ; execute (->display()); operation main() pre: true post: true activity: D := read_adj_mat() ; get_shortest_paths(D) ; (compound_stmt for (exprlist (expr (atom (name d)))) in (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name D)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name D)))))))) ))))))))) )))))))) ])))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name d)))) < (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NEGATIVE CYCLE"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name print_result)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name D)))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def warshall_floyd(v_num,dist_lst): negative_cycle_flag=False for k in range(v_num): for i in range(v_num): for j in range(v_num): if dist_lst[i][k]!=INF and dist_lst[k][j]!=INF : if dist_lst[i][j]>dist_lst[i][k]+dist_lst[k][j]: dist_lst[i][j]=dist_lst[i][k]+dist_lst[k][j] for v in range(v_num): if dist_lst[v][v]<0 : negative_cycle_flag=True if negative_cycle_flag : print("NEGATIVE CYCLE") else : for lst in dist_lst : put="" for i in lst : if i==INF : put+="INF"+" " else : put+=str(i)+" " print(put.rstrip()) v_num,e_num=map(int,input().split()) INF=10**20 dist_lst=[[INF]*v_num for _ in range(v_num)] for _ in range(e_num): s,t,dist=map(int,input().split()) dist_lst[s][t]=dist for v in range(v_num): dist_lst[v][v]=0 warshall_floyd(v_num,dist_lst) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var e_num : OclAny := null; Sequence{v_num,e_num} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var INF : double := (10)->pow(20) ; dist_lst := Integer.subrange(0, v_num-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ INF }, v_num))) ; for _anon : Integer.subrange(0, e_num-1) do ( var s : OclAny := null; var t : OclAny := null; var dist : OclAny := null; Sequence{s,t,dist} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; dist_lst[s+1][t+1] := dist) ; for v : Integer.subrange(0, v_num-1) do ( dist_lst[v+1][v+1] := 0) ; warshall_floyd(v_num, dist_lst); operation warshall_floyd(v_num : OclAny, dist_lst : OclAny) pre: true post: true activity: var negative_cycle_flag : boolean := false ; for k : Integer.subrange(0, v_num-1) do ( for i : Integer.subrange(0, v_num-1) do ( for j : Integer.subrange(0, v_num-1) do ( if dist_lst[i+1][k+1] /= INF & dist_lst[k+1][j+1] /= INF then ( if (dist_lst[i+1][j+1]->compareTo(dist_lst[i+1][k+1] + dist_lst[k+1][j+1])) > 0 then ( dist_lst[i+1][j+1] := dist_lst[i+1][k+1] + dist_lst[k+1][j+1] ) else skip ) else skip))) ; for v : Integer.subrange(0, v_num-1) do ( if dist_lst[v+1][v+1] < 0 then ( negative_cycle_flag := true ) else skip) ; if negative_cycle_flag then ( execute ("NEGATIVE CYCLE")->display() ) else ( for lst : dist_lst do ( var put : String := "" ; for i : lst do ( if i = INF then ( put := put + "INF" + " " ) else ( put := put + ("" + ((i))) + " " )) ; execute (StringLib.rightTrim(put))->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) if n % 2==1 : print(7,end='') n-=3 x=int(n/2) for i in range(x): print(1,end='') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 1 then ( execute (7)->display() ; n := n - 3 ) else skip ; var x : int := ("" + ((n / 2)))->toInteger() ; for i : Integer.subrange(0, x-1) do ( execute (1)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minRange(arr,n,k): l=0 r=n for i in range(n): s=[] for j in range(i,n): s.append(arr[j]) if(len(s)==k): if((j-i)<(r-l)): r=j l=i break if(j==n): break if(l==0 and r==n): print("Invalid k") else : print(l,r) if __name__=="__main__" : arr=[1,2,3,4,5] n=len(arr) k=3 minRange(arr,n,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ; n := (arr)->size() ; k := 3 ; minRange(arr, n, k) ) else skip; operation minRange(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var l : int := 0 ; var r : OclAny := n ; for i : Integer.subrange(0, n-1) do ( var s : Sequence := Sequence{} ; for j : Integer.subrange(i, n-1) do ( execute ((arr[j+1]) : s) ; if ((s)->size() = k) then ( if (((j - i)->compareTo((r - l))) < 0) then ( r := j ; l := i ) else skip ; break ) else skip) ; if (j = n) then ( break ) else skip) ; if (l = 0 & r = n) then ( execute ("Invalid k")->display() ) else ( execute (l)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculate(bit_cnt): res=1 ; while(bit_cnt>0): bit_cnt-=1 ; res=res*3 ; return res ; def unset_bit_count(n): count=0 ; while(n>0): if((n & 1)==0): count+=1 ; n=n>>1 ; return count ; if __name__=='__main__' : n=2 ; count=unset_bit_count(n); ans=calculate(count); print(ans); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( n := 2; ; count := unset_bit_count(n); ; var ans : OclAny := calculate(count); ; execute (ans)->display(); ) else skip; operation calculate(bit_cnt : OclAny) pre: true post: true activity: var res : int := 1; ; while (bit_cnt > 0) do ( bit_cnt := bit_cnt - 1; ; res := res * 3;) ; return res;; operation unset_bit_count(n : OclAny) pre: true post: true activity: var count : int := 0; ; while (n > 0) do ( if ((MathLib.bitwiseAnd(n, 1)) = 0) then ( count := count + 1; ) else skip ; n := n /(2->pow(1));) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSubarray(arr,n,k): count=0 for i in range(0,n): sum=0 ; for j in range(i,n): if(sum+arr[j]union(Sequence{11}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 15 })))) ; k := 10 ; var size : int := (array)->size() ; count := countSubarray(array, size, k); ; execute (count)->display(); operation countSubarray(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( var sum : int := 0; ; for j : Integer.subrange(i, n-1) do ( if ((sum + arr[j+1]->compareTo(k)) < 0) then ( sum := arr[j+1] + sum ; count := count + 1 ) else ( break ))) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a,b=map(int,input().split()) diff=a-b if diff<0 : print(0) elif diff==0 : print("infinity") else : cnt=0 for i in range(1,1+int(math.sqrt(diff))): if diff % i==0 and i>b : cnt+=1 if diff % i==0 and diff//i>b and i*i!=diff : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var diff : double := a - b ; if diff < 0 then ( execute (0)->display() ) else (if diff = 0 then ( execute ("infinity")->display() ) else ( var cnt : int := 0 ; for i : Integer.subrange(1, 1 + ("" + (((diff)->sqrt())))->toInteger()-1) do ( if diff mod i = 0 & (i->compareTo(b)) > 0 then ( cnt := cnt + 1 ) else skip ; if diff mod i = 0 & (diff div i->compareTo(b)) > 0 & i * i /= diff then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import random from bisect import bisect_left as lb from bisect import bisect_right as rb from collections import deque from queue import PriorityQueue as pq from math import gcd input_=lambda : sys.stdin.readline().strip("\n") ii=lambda : int(input_()) il=lambda : list(map(int,input_().split())) ilf=lambda : list(map(float,input_().split())) lii=lambda : list(map(int,list(ip()))) ip=lambda : input_() fi=lambda : float(input_()) ap=lambda ab,bc,cd : ab[bc].append(cd) li=lambda : list(input_()) pr=lambda x : print(x) prinT=lambda x : print(x) f=lambda : sys.stdout.flush() inv=lambda x : pow(x,mod-2,mod) dx=[0,0,1,-1] dy=[1,-1,0,0] mod=10**9+7 mod1=998244353 a,b=il() if(a==b): print("infinity") elif(b>a): print(0) else : x=a-b p=1 ans=0 while(p*p<=x): if(x % p==0): t=x//p t1=p if(t==t1): if(t>b): ans+=1 else : if(t>b): ans+=1 if(t1>b): ans+=1 p+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var input_ : Function := lambda $$ : OclAny in (sys.stdin.readLine()->trim()) ; var ii : Function := lambda $$ : OclAny in (("" + ((input_->apply())))->toInteger()) ; var il : Function := lambda $$ : OclAny in (((input_->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ilf : Function := lambda $$ : OclAny in (((input_->apply().split())->collect( _x | (OclType["double"])->apply(_x) ))) ; var lii : Function := lambda $$ : OclAny in ((((ip()))->collect( _x | (OclType["int"])->apply(_x) ))) ; var ip : Function := lambda $$ : OclAny in (input_->apply()) ; var fi : Function := lambda $$ : OclAny in (("" + ((input_->apply())))->toReal()) ; var ap : Function := lambda ab : OclAny, bc : OclAny, cd : OclAny in (ab[bc+1].append(cd)) ; var li : Function := lambda $$ : OclAny in ((input_->apply())) ; var pr : Function := lambda x : OclAny in ((x)->display()) ; var prinT : Function := lambda x : OclAny in ((x)->display()) ; var f : Function := lambda $$ : OclAny in ((OclFile["System.out"]).flush()) ; var inv : Function := lambda x : OclAny in ((x)->pow(mod - 2)) ; var dx : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ -1 }))) ; var dy : Sequence := Sequence{1}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{ 0 }))) ; var mod : double := (10)->pow(9) + 7 ; var mod1 : int := 998244353 ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := il->apply() ; if (a = b) then ( execute ("infinity")->display() ) else (if ((b->compareTo(a)) > 0) then ( execute (0)->display() ) else ( var x : double := a - b ; var p : int := 1 ; var ans : int := 0 ; while ((p * p->compareTo(x)) <= 0) do ( if (x mod p = 0) then ( var t : int := x div p ; var t1 : int := p ; if (t = t1) then ( if ((t->compareTo(b)) > 0) then ( ans := ans + 1 ) else skip ) else ( if ((t->compareTo(b)) > 0) then ( ans := ans + 1 ) else skip ; if ((t1->compareTo(b)) > 0) then ( ans := ans + 1 ) else skip ) ) else skip ; p := p + 1) ; execute (ans)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) k=0 c=0 while(n>0): p=1 l=map(int,list(str(n))) for i in l : p*=i k=max(k,p) n=n-n %(10**(c+1))-1 c+=1 print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := 0 ; var c : int := 0 ; while (n > 0) do ( var p : int := 1 ; var l : Sequence := ((("" + ((n))))->characters())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : l do ( p := p * i) ; k := Set{k, p}->max() ; n := n - n mod ((10)->pow((c + 1))) - 1 ; c := c + 1) ; execute (k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys def get_array(): return list(map(int,sys.stdin.readline().strip().split())) def get_ints(): return map(int,sys.stdin.readline().strip().split()) def input(): return sys.stdin.readline().strip() MOD=10**9+7 def main(): (a,b)=get_ints() if a==b : print("infinity") elif b>a : print(0) else : n=(a-b) cnt=0 for i in range(1,int(math.sqrt(n))+1): if n % i==0 : if i>b : cnt+=1 if n//i!=i and(n//i)>b : cnt+=1 print(cnt) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var MOD : double := (10)->pow(9) + 7 ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation get_array() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation get_ints() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation main() pre: true post: true activity: ; var Sequence{a, b} : OclAny := get_ints() ; if a = b then ( execute ("infinity")->display() ) else (if (b->compareTo(a)) > 0 then ( execute (0)->display() ) else ( var n : double := (a - b) ; var cnt : int := 0 ; for i : Integer.subrange(1, ("" + (((n)->sqrt())))->toInteger() + 1-1) do ( if n mod i = 0 then ( if (i->compareTo(b)) > 0 then ( cnt := cnt + 1 ) else skip ; if n div i /= i & ((n div i)->compareTo(b)) > 0 then ( cnt := cnt + 1 ) else skip ) else skip) ; execute (cnt)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt import sys def conta_divisores(num,lim): if num==1 : return 0 divs=0 for c in range(1,int(sqrt(num))+1,1): if num % c==0 : if c>lim : divs+=1 if num/c>lim and num/c!=c : divs+=1 return divs for l in sys.stdin : a,b=[int(n)for n in l.split()] if a==b : print("infinity") continue if b>a : print(0) continue if a==1 and b==0 : print(1) continue print(conta_divisores(a-b,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; for l : OclFile["System.in"] do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := l.split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; if a = b then ( execute ("infinity")->display() ; continue ) else skip ; if (b->compareTo(a)) > 0 then ( execute (0)->display() ; continue ) else skip ; if a = 1 & b = 0 then ( execute (1)->display() ; continue ) else skip ; execute (conta_divisores(a - b, b))->display()); operation conta_divisores(num : OclAny, lim : OclAny) : OclAny pre: true post: true activity: if num = 1 then ( return 0 ) else skip ; var divs : int := 0 ; for c : Integer.subrange(1, ("" + ((sqrt(num))))->toInteger() + 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if num mod c = 0 then ( if (c->compareTo(lim)) > 0 then ( divs := divs + 1 ) else skip ; if (num / c->compareTo(lim)) > 0 & num / c /= c then ( divs := divs + 1 ) else skip ) else skip) ; return divs; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,*L=map(int,open(0).read().split()) memo=[set()for i in range(N)] ans=sum(L) def dfs(i,mi,ma): global ans if i==N : ans=min(ans,ma-mi) return key=(mi,ma) if ma-mi>=ans or key in memo[i]: return memo[i].add(key) s=0 for j in range(i,N-(i==0)): s+=L[j] dfs(j+1,min(mi,s),max(ma,s)) dfs(0,10**18,-10**18) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute ans : OclAny; operation initialise() pre: true post: true activity: var N : OclAny := null; var L : OclAny := null; Sequence{N,L} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var memo : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Set{}->union(()))) ; var ans : OclAny := (L)->sum() ; skip ; dfs(0, (10)->pow(18), (-10)->pow(18)) ; execute (ans)->display(); operation dfs(i : OclAny, mi : OclAny, ma : OclAny) pre: true post: true activity: skip ; if i = N then ( ans := Set{ans, ma - mi}->min() ; return ) else skip ; var key : OclAny := Sequence{mi, ma} ; if (ma - mi->compareTo(ans)) >= 0 or (memo[i+1])->includes(key) then ( return ) else skip ; (expr (atom (name memo)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name key)))))))) )))) ; var s : int := 0 ; for j : Integer.subrange(i, N - (i = 0)-1) do ( s := s + L[j+1] ; dfs(j + 1, Set{mi, s}->min(), Set{ma, s}->max())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import sys def main(): N=read_int() A=[read_int()for _ in range(N)] print(solve(N,A)) def solve(N,A): lens=set() for i in range(N): s=A[i] lens.add(s) for j in range(i+1,N): s+=A[j] lens.add(s) lens=list(lens) lens.sort() best=lens[-1] lens.pop() M=len(lens) for li in range(M): lmin=lens[li] for lj in range(li,M): lmax=lens[lj] if lmax-lmin>=best : break D=set() D.add(0) for a in A : ND=set() for d in D : if d+a<=lmax : ND.add(d+a) if lmin<=d<=lmax and a<=lmax : ND.add(a) D=ND if any([lmin<=d<=lmax for d in D]): best=lmax-lmin break return best DEBUG='DEBUG' in os.environ def inp(): return sys.stdin.readline().rstrip() def read_int(): return int(inp()) def read_ints(): return[int(e)for e in inp().split()] def dprint(*value,sep=' ',end='\n'): if DEBUG : print(*value,sep=sep,end=end) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var DEBUG : boolean := (os.environ)->includes('DEBUG') ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := read_int() ; var A : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (read_int())) ; execute (solve(N, A))->display(); operation solve(N : OclAny, A : OclAny) : OclAny pre: true post: true activity: var lens : Set := Set{}->union(()) ; for i : Integer.subrange(0, N-1) do ( var s : OclAny := A[i+1] ; execute ((s) : lens) ; for j : Integer.subrange(i + 1, N-1) do ( s := s + A[j+1] ; execute ((s) : lens))) ; lens := (lens) ; lens := lens->sort() ; var best : OclAny := lens->last() ; lens := lens->front() ; var M : int := (lens)->size() ; for li : Integer.subrange(0, M-1) do ( var lmin : OclAny := lens[li+1] ; for lj : Integer.subrange(li, M-1) do ( var lmax : OclAny := lens[lj+1] ; if (lmax - lmin->compareTo(best)) >= 0 then ( break ) else skip ; var D : Set := Set{}->union(()) ; execute ((0) : D) ; for a : A do ( var ND : Set := Set{}->union(()) ; for d : D do ( if (d + a->compareTo(lmax)) <= 0 then ( execute ((d + a) : ND) ) else skip ; if (lmin->compareTo(d)) <= 0 & (d <= lmax) & (a->compareTo(lmax)) <= 0 then ( execute ((a) : ND) ) else skip) ; D := ND) ; if (D->select(d | true)->collect(d | ((lmin->compareTo(d)) <= 0 & (d <= lmax))))->exists( _x | _x = true ) then ( best := lmax - lmin ; break ) else skip)) ; return best; operation inp() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation read_int() : OclAny pre: true post: true activity: return ("" + ((inp())))->toInteger(); operation read_ints() : OclAny pre: true post: true activity: return inp().split()->select(e | true)->collect(e | (("" + ((e)))->toInteger())); operation dprint(value : OclAny : Sequence(OclAny), sep : String, end : String) pre: true post: true activity: (args * (named_parameter (name value))) if sep->oclIsUndefined() then sep := ' ' else skip; if end->oclIsUndefined() then end := ' ' else skip; if DEBUG then ( execute ((argument * (test (logical_test (comparison (expr (atom (name value))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(low,n,ls): dp=[10**20 for i in range(n+1)] dp[0]=low for i in range(n): length=0 for j in range(i,-1,-1): length+=ls[j] if i+1==n and j==0 : continue if length>=low : high=max(length,dp[j]) dp[i+1]=min(dp[i+1],high) return dp[n]-low def main(): n=int(input()) ls=[int(input())for i in range(n)] ans=10**20 for i in range(n): length=0 for j in range(i,n): length+=ls[j] ans=min(ans,solve(length,n,ls)) print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation solve(low : OclAny, n : OclAny, ls : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | ((10)->pow(20))) ; dp->first() := low ; for i : Integer.subrange(0, n-1) do ( var length : int := 0 ; for j : Integer.subrange(-1 + 1, i)->reverse() do ( length := length + ls[j+1] ; if i + 1 = n & j = 0 then ( continue ) else skip ; if (length->compareTo(low)) >= 0 then ( var high : OclAny := Set{length, dp[j+1]}->max() ; dp[i + 1+1] := Set{dp[i + 1+1], high}->min() ) else skip)) ; return dp[n+1] - low; operation main() pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; ls := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var ans : double := (10)->pow(20) ; for i : Integer.subrange(0, n-1) do ( length := 0 ; for j : Integer.subrange(i, n-1) do ( length := length + ls[j+1] ; ans := Set{ans, solve(length, n, ls)}->min())) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- exec(int(input())*'n=int(input());print("17"[n%2]+(n//2-1)*"1");') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) )))) * (expr (atom 'n=int(input());print("17"[n%2]+(n//2-1)*"1");'))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getMinVal(p,q): if q % p==0 : return p return-1 p=24 ; q=48 print(getMinVal(p,q)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; p := 24; q := 48 ; execute (getMinVal(p, q))->display(); operation getMinVal(p : OclAny, q : OclAny) : OclAny pre: true post: true activity: if q mod p = 0 then ( return p ) else skip ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isEvenOrOdd(L,R): oddCount=(R-L)/2 if(R % 2==1 or L % 2==1): oddCount=oddCount+1 if(oddCount % 2==0): return "Even" else : return "Odd" L=5 R=15 print(isEvenOrOdd(L,R)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; L := 5 ; R := 15 ; execute (isEvenOrOdd(L, R))->display();; operation isEvenOrOdd(L : OclAny, R : OclAny) : OclAny pre: true post: true activity: var oddCount : double := (R - L) / 2 ; if (R mod 2 = 1 or L mod 2 = 1) then ( oddCount := oddCount + 1 ) else skip ; if (oddCount mod 2 = 0) then ( return "Even" ) else ( return "Odd" ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,Ma,Mb=map(int,input().split()) dp=[[10**18 for _ in range(401)]for _ in range(401)] dp[0][0]=0 for i in range(N): a,b,c=map(int,input().split()) for ca in range(i*10,-1,-1): for cb in range(i*10,-1,-1): dp[ca+a][cb+b]=min(dp[ca+a][cb+b],dp[ca][cb]+c) ans=10**18 for ca in range(401): for cb in range(401): if not ca*Mb==cb*Ma or ca==0 : continue if ans>dp[ca][cb]: ans=dp[ca][cb] if ans==10**18 : print(-1) else : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var Ma : OclAny := null; var Mb : OclAny := null; Sequence{N,Ma,Mb} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dp : Sequence := Integer.subrange(0, 401-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, 401-1)->select(_anon | true)->collect(_anon | ((10)->pow(18))))) ; dp->first()->first() := 0 ; for i : Integer.subrange(0, N-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for ca : Integer.subrange(-1 + 1, i * 10)->reverse() do ( for cb : Integer.subrange(-1 + 1, i * 10)->reverse() do ( dp[ca + a+1][cb + b+1] := Set{dp[ca + a+1][cb + b+1], dp[ca+1][cb+1] + c}->min()))) ; var ans : double := (10)->pow(18) ; for ca : Integer.subrange(0, 401-1) do ( for cb : Integer.subrange(0, 401-1) do ( if not(ca * Mb = cb * Ma) or ca = 0 then ( continue ) else skip ; if (ans->compareTo(dp[ca+1][cb+1])) > 0 then ( ans := dp[ca+1][cb+1] ) else skip)) ; if ans = (10)->pow(18) then ( execute (-1)->display() ) else ( execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda : sys.stdin.readline().rstrip() from itertools import product from copy import deepcopy def resolve(): n,ma,mb=map(int,input().split()) ABC=[tuple(map(int,input().split()))for _ in range(n)] M=400 dp=[[INF]*(M+1)for _ in range(M+1)] dp[0][0]=0 for a,b,c in ABC : for x,y in product(range(M,-1,-1),repeat=2): if(x+a<=M and y+b<=M): dp[x+a][y+b]=min(dp[x+a][y+b],dp[x][y]+c) ans=INF for x,y in product(range(1,M+1),repeat=2): if(x*mb==y*ma): ans=min(ans,dp[x][y]) if(ans==INF): ans=-1 print(ans) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(2147483647) ; var INF : double := ("" + (("inf")))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; skip ; skip ; skip ; resolve(); operation resolve() pre: true post: true activity: var n : OclAny := null; var ma : OclAny := null; var mb : OclAny := null; Sequence{n,ma,mb} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ABC : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var M : int := 400 ; var dp : Sequence := Integer.subrange(0, M + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ INF }, (M + 1)))) ; dp->first()->first() := 0 ; for _tuple : ABC do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); for _tuple : product(Integer.subrange(-1 + 1, M)->reverse(), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if ((x + a->compareTo(M)) <= 0 & (y + b->compareTo(M)) <= 0) then ( dp[x + a+1][y + b+1] := Set{dp[x + a+1][y + b+1], dp[x+1][y+1] + c}->min() ) else skip)) ; var ans : OclAny := INF ; for _tuple : product(Integer.subrange(1, M + 1-1), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if (x * mb = y * ma) then ( ans := Set{ans, dp[x+1][y+1]}->min() ) else skip) ; if (ans = INF) then ( ans := -1 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) def funk(n): k=str(n) if len(k)==1 : return n s=funk(n//10) l=funk(n//10-1) return max(9,s*(n % 10),l*9) print(funk(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; execute (funk(n))->display(); operation funk(n : OclAny) : OclAny pre: true post: true activity: var k : String := ("" + ((n))) ; if (k)->size() = 1 then ( return n ) else skip ; var s : OclAny := funk(n div 10) ; var l : OclAny := funk(n div 10 - 1) ; return Set{9, s * (n mod 10), l * 9}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict from bisect import bisect_right INF=float('inf') N,Ma,Mb=map(int,input().split()) a,b,c=[None]*N,[None]*N,[None]*N for i in range(N): a[i],b[i],c[i]=map(int,input().split()) hN=N//2 dic1=defaultdict(lambda : INF) for i in range(1<>j)& 1 : _a+=a[j] _b+=b[j] _c+=c[j] if _c>j)& 1 : _a+=a[hN+j] _b+=b[hN+j] _c+=c[hN+j] if _ctoReal() ; var N : OclAny := null; var Ma : OclAny := null; var Mb : OclAny := null; Sequence{N,Ma,Mb} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{MatrixLib.elementwiseMult(Sequence{ null }, N),MatrixLib.elementwiseMult(Sequence{ null }, N),MatrixLib.elementwiseMult(Sequence{ null }, N)} ; for i : Integer.subrange(0, N-1) do ( var a[i+1] : OclAny := null; var b[i+1] : OclAny := null; var c[i+1] : OclAny := null; Sequence{a[i+1],b[i+1],c[i+1]} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var hN : int := N div 2 ; var dic1 : OclAny := defaultdict(lambda $$ : OclAny in (INF)) ; for i : Integer.subrange(0, 1 * (2->pow(hN))-1) do ( var _a : OclAny := null; var _b : OclAny := null; var _c : OclAny := null; Sequence{_a,_b,_c} := Sequence{0,0,0} ; for j : Integer.subrange(0, hN-1) do ( if MathLib.bitwiseAnd((i /(2->pow(j))), 1) then ( _a := _a + a[j+1] ; _b := _b + b[j+1] ; _c := _c + c[j+1] ) else skip) ; if (_c->compareTo(dic1[Sequence{_a, _b}+1])) < 0 then ( dic1[Sequence{_a, _b}+1] := _c ) else skip) ; var dic2 : OclAny := defaultdict(lambda $$ : OclAny in (INF)) ; for i : Integer.subrange(0, 1 * (2->pow((N - hN)))-1) do ( var _a : OclAny := null; var _b : OclAny := null; var _c : OclAny := null; Sequence{_a,_b,_c} := Sequence{0,0,0} ; for j : Integer.subrange(0, N - hN-1) do ( if MathLib.bitwiseAnd((i /(2->pow(j))), 1) then ( _a := _a + a[hN + j+1] ; _b := _b + b[hN + j+1] ; _c := _c + c[hN + j+1] ) else skip) ; if (_c->compareTo(dic2[Sequence{_a, _b}+1])) < 0 then ( dic2[Sequence{_a, _b}+1] := _c ) else skip) ; var ans : OclAny := INF ; for k : dic1 do ( var _a : OclAny := null; var _b : OclAny := null; Sequence{_a,_b} := k ; var v : OclAny := dic1[k+1] ; for i : Integer.subrange(1, N + 1-1) do ( ans := Set{ans, v + dic2[Sequence{Ma * i - _a, Mb * i - _b}+1]}->min())) ; ans := if (ans->compareTo(INF)) < 0 then ans else -1 endif ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import Fraction import sys input=sys.stdin.readline INF=float('inf') N,A,B=list(map(int,input().split())) data=[list(map(int,input().split()))for _ in range(N)] P=[] M=[] Z=[] for a,b,c in data : if Fraction(a,b)==Fraction(A,B): Z.append(c) elif Fraction(a,b)>Fraction(A,B): P.append((a*2520-b*2520*A//B,c)) else : M.append((-a*2520+b*2520*A//B,c)) dpP=[INF for i in range(1000000)] dpP[0]=0 for v,c in P : for i in range(1000000)[: :-1]: if i>=v : dpP[i]=min(dpP[i],dpP[i-v]+c) dpM=[INF for i in range(1000000)] dpM[0]=0 for v,c in M : for i in range(1000000)[: :-1]: if i>=v : dpM[i]=min(dpM[i],dpM[i-v]+c) ans=INF if Z : ans=min(Z) for i in range(1,1000000): ans=min(ans,dpP[i]+dpM[i]) if ans==INF : print(-1) else : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var INF : double := ("" + (('inf')))->toReal() ; var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{N,A,B} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var data : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var P : Sequence := Sequence{} ; var M : Sequence := Sequence{} ; var Z : Sequence := Sequence{} ; for _tuple : data do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if Fraction(a, b) = Fraction(A, B) then ( execute ((c) : Z) ) else (if (Fraction(a, b)->compareTo(Fraction(A, B))) > 0 then ( execute ((Sequence{a * 2520 - b * 2520 * A div B, c}) : P) ) else ( execute ((Sequence{-a * 2520 + b * 2520 * A div B, c}) : M) ) ) ) ; var dpP : Sequence := Integer.subrange(0, 1000000-1)->select(i | true)->collect(i | (INF)) ; dpP->first() := 0 ; for _tuple : P do (var _indx : int := 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); for i : range(1000000)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if (i->compareTo(v)) >= 0 then ( dpP[i+1] := Set{dpP[i+1], dpP[i - v+1] + c}->min() ) else skip)) ; var dpM : Sequence := Integer.subrange(0, 1000000-1)->select(i | true)->collect(i | (INF)) ; dpM->first() := 0 ; for _tuple : M do (var _indx : int := 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); for i : range(1000000)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if (i->compareTo(v)) >= 0 then ( dpM[i+1] := Set{dpM[i+1], dpM[i - v+1] + c}->min() ) else skip)) ; var ans : OclAny := INF ; if Z then ( ans := (Z)->min() ) else skip ; for i : Integer.subrange(1, 1000000-1) do ( ans := Set{ans, dpP[i+1] + dpM[i+1]}->min()) ; if ans = INF then ( execute (-1)->display() ) else ( execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,ma,mb,*L=map(int,open(0).read().split()) M=1<<30 dp=[[M]*420 for _ in range(420)] dp[0][0]=0 ua=ub=15 for a,b,c in zip(*[iter(L)]*3): for i in range(ua,-1,-1): for j in range(ub,-1,-1): t=dp[i][j]+c if dp[i+a][j+b]>t : dp[i+a][j+b]=t if ua_mb : ans=min(ans,dp[_ma][_mb]) _ma+=ma _mb+=mb print(ans if anscollect( _x | (OclType["int"])->apply(_x) ) ; var M : int := 1 * (2->pow(30)) ; var dp : Sequence := Integer.subrange(0, 420-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ M }, 420))) ; dp->first()->first() := 0 ; var ua : OclAny := 15; var ub : int := 15 ; for _tuple : Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)))))))) )))))))) ])) * (expr (atom (number (integer 3)))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)))))))) )))))))) ])) * (expr (atom (number (integer 3)))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)))))))) )))))))) ])) * (expr (atom (number (integer 3)))))))))`third->at(_indx)} ) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); for i : Integer.subrange(-1 + 1, ua)->reverse() do ( for j : Integer.subrange(-1 + 1, ub)->reverse() do ( var t : OclAny := dp[i+1][j+1] + c ; if (dp[i + a+1][j + b+1]->compareTo(t)) > 0 then ( dp[i + a+1][j + b+1] := t ; if (ua->compareTo(i + a)) < 0 then ( ua := i + a ) else skip ; if (ub->compareTo(j + b)) < 0 then ( ub := j + b ) else skip ) else skip))) ; var ans : int := M ; var _ma : OclAny := null; var _mb : OclAny := null; Sequence{_ma,_mb} := Sequence{ma,mb} ; while _ma < 410 & (410 > _mb) do ( ans := Set{ans, dp[_ma+1][_mb+1]}->min() ; _ma := _ma + ma ; _mb := _mb + mb) ; execute (if (ans->compareTo(M)) < 0 then ans else -1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if a==0 or b==0 : return 0 if a==b : return a if a>b : return gcd(a-b,b) return gcd(a,b-a) def cpFact(x,y): while gcd(x,y)!=1 : x=x/gcd(x,y) return int(x) x=15 y=3 print(cpFact(x,y)) x=14 y=28 print(cpFact(x,y)) x=7 y=3 print(cpFact(x,y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; x := 15 ; y := 3 ; execute (cpFact(x, y))->display() ; x := 14 ; y := 28 ; execute (cpFact(x, y))->display() ; x := 7 ; y := 3 ; execute (cpFact(x, y))->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a = 0 or b = 0 then ( return 0 ) else skip ; if a = b then ( return a ) else skip ; if (a->compareTo(b)) > 0 then ( return gcd(a - b, b) ) else skip ; return gcd(a, b - a); operation cpFact(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: while gcd(x, y) /= 1 do ( x := x / gcd(x, y)) ; return ("" + ((x)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,m=map(int,input().split()) M=1000000009 c=1 x=(2**m-1)% M for i in range(n): c=c*x % M x-=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var M : int := 1000000009 ; var c : int := 1 ; var x : int := ((2)->pow(m) - 1) mod M ; for i : Integer.subrange(0, n-1) do ( c := c * x mod M ; x := x - 1) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) ans=1 ; mod=1000000009 ; gh=pow(2,b,mod) for i in range(1,1+a): ans=pow(ans*(gh-i),1,mod) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 1; var mod : int := 1000000009; var gh : double := (2)->pow(b) ; for i : Integer.subrange(1, 1 + a-1) do ( ans := (ans * (gh - i))->pow(1)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) def out(case): seg2=0 seg2=int(case/2) mod=case % 2 if mod==0 : for i in range(seg2): print("1",end="") else : print("7",end="") for i in range(seg2-1): print("1",end="") print("") for i in range(n): case=int(input()) if case==3 : print("7") elif case==2 : print("1") else : out(case) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; for i : Integer.subrange(0, n-1) do ( case := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if case = 3 then ( execute ("7")->display() ) else (if case = 2 then ( execute ("1")->display() ) else ( out(case) ) ) ); operation out(case : OclAny) pre: true post: true activity: var seg2 : int := 0 ; seg2 := ("" + ((case / 2)))->toInteger() ; var mod : int := case mod 2 ; if mod = 0 then ( for i : Integer.subrange(0, seg2-1) do ( execute ("1")->display()) ) else ( execute ("7")->display() ; for i : Integer.subrange(0, seg2 - 1-1) do ( execute ("1")->display()) ) ; execute ("")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) mod=10**9+9 s,ans=pow(2,m,mod)-1,1 for i in range(n): ans=ans*(s-i)% mod ; print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mod : double := (10)->pow(9) + 9 ; var s : OclAny := null; var ans : OclAny := null; Sequence{s,ans} := Sequence{(2)->pow(m) - 1,1} ; for i : Integer.subrange(0, n-1) do ( var ans : int := ans * (s - i) mod mod;) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) MOD=10**9+9 out=1 curr=pow(2,m,MOD)-1 for i in range(n): out*=curr curr-=1 out %=MOD print(out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var MOD : double := (10)->pow(9) + 9 ; var out : int := 1 ; var curr : double := (2)->pow(m) - 1 ; for i : Integer.subrange(0, n-1) do ( out := out * curr ; curr := curr - 1 ; out := out mod MOD) ; execute (out)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) mod=10**9+9 s,ans=pow(2,m,mod)-1,1 for i in range(n): ans=ans*(s-i)% mod ; print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mod : double := (10)->pow(9) + 9 ; var s : OclAny := null; var ans : OclAny := null; Sequence{s,ans} := Sequence{(2)->pow(m) - 1,1} ; for i : Integer.subrange(0, n-1) do ( var ans : int := ans * (s - i) mod mod;) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) l=len(str(n)) pow9=[1] for _ in range(l): pow9.append(9*pow9[-1]) ans=pow9[l-1] x=list(str(n)) y=[int(i)for i in x] now=1 for i in range(l): if y[i]-1>0 : now*=y[i]-1 ans=max(ans,now*pow9[l-i-1]) now//=y[i]-1 now*=y[i] if not now : break ans=max(ans,now) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : int := (("" + ((n))))->size() ; var pow9 : Sequence := Sequence{ 1 } ; for _anon : Integer.subrange(0, l-1) do ( execute ((9 * pow9->last()) : pow9)) ; var ans : OclAny := pow9[l - 1+1] ; var x : Sequence := (("" + ((n))))->characters() ; var y : Sequence := x->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var now : int := 1 ; for i : Integer.subrange(0, l-1) do ( if y[i+1] - 1 > 0 then ( now := now * y[i+1] - 1 ; ans := Set{ans, now * pow9[l - i - 1+1]}->max() ; now := now div y[i+1] - 1 ) else skip ; now := now * y[i+1] ; if not(now) then ( break ) else skip) ; ans := Set{ans, now}->max() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=list(input().split()) a=int(a) b=int(b) print((a*a//4)*(b*b//4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split()) ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; execute ((a * a div 4) * (b * b div 4))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from sys import stdin,stdout def get_ints_in_variables(): return map(int,sys.stdin.readline().strip().split()) def get_int(): return int(input()) def get_ints_in_list(): return list(map(int,sys.stdin.readline().strip().split())) def get_list_of_list(n): return[list(map(int,sys.stdin.readline().strip().split()))for _ in range(n)] def get_string(): return sys.stdin.readline().strip() def main(): w,h=get_ints_in_variables() wd=0 hd=0 i=2 while i<=w : wd+=(w-i+1) i+=2 i=2 while i<=h : hd+=(h-i+1) i+=2 res=wd*hd print(res) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation get_ints_in_variables() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ); operation get_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation get_ints_in_list() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation get_list_of_list(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )))); operation get_string() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation main() pre: true post: true activity: var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := get_ints_in_variables() ; var wd : int := 0 ; var hd : int := 0 ; var i : int := 2 ; while (i->compareTo(w)) <= 0 do ( wd := wd + (w - i + 1) ; i := i + 2) ; i := 2 ; while (i->compareTo(h)) <= 0 do ( hd := hd + (h - i + 1) ; i := i + 2) ; var res : int := wd * hd ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w,h=map(int,input().split()) ans1=0 ans2=0 for i in range(2,w+1,2): ans1=ans1+(w-i+1) for j in range(2,h+1,2): ans2=ans2+(h-j+1) print(ans1*ans2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans1 : int := 0 ; var ans2 : int := 0 ; for i : Integer.subrange(2, w + 1-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( ans1 := ans1 + (w - i + 1)) ; for j : Integer.subrange(2, h + 1-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( ans2 := ans2 + (h - j + 1)) ; execute (ans1 * ans2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input().split() (w,h)=(int(i)for i in s) if(w==1 or h==1): print(0) else : ans1=0 ans2=0 for i in range(2,w+1,2): ans1+=(w-i+1) for i in range(2,h+1,2): ans2+=(h-i+1) print(ans1*ans2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := input().split() ; var Sequence{w, h} : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name s)))))))} ; if (w = 1 or h = 1) then ( execute (0)->display() ) else ( var ans1 : int := 0 ; var ans2 : int := 0 ; for i : Integer.subrange(2, w + 1-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( ans1 := ans1 + (w - i + 1)) ; for i : Integer.subrange(2, h + 1-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( ans2 := ans2 + (h - i + 1)) ; execute (ans1 * ans2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input().split() (w,h)=(int(i)for i in s) if(w==1 or h==1): print(0) else : ans1=0 ans2=0 for i in range(2,w+1,2): ans1+=(w-i+1) for i in range(2,h+1,2): ans2+=(h-i+1) print(ans1*ans2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := input().split() ; var Sequence{w, h} : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name s)))))))} ; if (w = 1 or h = 1) then ( execute (0)->display() ) else ( var ans1 : int := 0 ; var ans2 : int := 0 ; for i : Integer.subrange(2, w + 1-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( ans1 := ans1 + (w - i + 1)) ; for i : Integer.subrange(2, h + 1-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( ans2 := ans2 + (h - i + 1)) ; execute (ans1 * ans2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math PI=3.14159265 def area_inscribed(a): return(a*a*(PI/12)) def perm_inscribed(a): return(PI*(a/math.sqrt(3))) a=6.0 print("Area of inscribed circle is :% f" % area_inscribed(a)) print("\nPerimeter of inscribed circle is :% f" % perm_inscribed(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PI : double := 3.14159265 ; skip ; skip ; a := 6.0 ; execute (StringLib.format("Area of inscribed circle is :% f",area_inscribed(a)))->display() ; execute (StringLib.format("\nPerimeter of inscribed circle is :% f",perm_inscribed(a)))->display(); operation area_inscribed(a : OclAny) : OclAny pre: true post: true activity: return (a * a * (PI / 12)); operation perm_inscribed(a : OclAny) : OclAny pre: true post: true activity: return (PI * (a / (3)->sqrt())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,next=None,prev=None,data=None): self.next=next self.prev=prev self.data=data def push(head,new_data): new_node=Node(data=new_data) new_node.next=head new_node.prev=None if head is not None : head.prev=new_node head=new_node return head def printList(head): node=head print("Given linked list") while(node is not None): print(node.data,end=" "), last=node node=node.next def rotate(start,N): if N==0 : return current=start count=1 while countexists( _x | result = _x ); attribute next : OclAny := next; attribute prev : OclAny := prev; attribute data : OclAny := data; operation initialise(next : OclAny,prev : OclAny,data : OclAny) : Node pre: true post: true activity: self.next := next ; self.prev := prev ; self.data := data; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( head := null ; head := push(head, 'e') ; head := push(head, 'd') ; head := push(head, 'c') ; head := push(head, 'b') ; head := push(head, 'a') ; printList(head) ; execute ("\n")->display() ; N := 2 ; head := rotate(head, N) ; printList(head) ) else skip; operation push(head : OclAny, new_data : OclAny) : OclAny pre: true post: true activity: var new_node : Node := (Node.newNode()).initialise((argument (test (logical_test (comparison (expr (atom (name data)))))) = (test (logical_test (comparison (expr (atom (name new_data)))))))) ; new_node.next := head ; new_node.prev := null ; if not(head <>= null) then ( head.prev := new_node ) else skip ; head := new_node ; return head; operation printList(head : OclAny) pre: true post: true activity: var node : OclAny := head ; execute ("Given linked list")->display() ; while (not(node <>= null)) do ((testlist_star_expr (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name node)) (trailer . (name data))))))) , (argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom " "))))))) ))))))) ,) ; var last : OclAny := node ; node := node.next); operation rotate(start : OclAny, N : OclAny) : OclAny pre: true post: true activity: if N = 0 then ( return ) else skip ; var current : OclAny := start ; var count : int := 1 ; while (count->compareTo(N)) < 0 & current /= null do ( current := current.next ; count := count + 1) ; if current = null then ( return ) else skip ; var NthNode : OclAny := current ; while current.next /= null do ( current := current.next) ; current.next := start ; start.prev := current ; start := NthNode.next ; start.prev := null ; NthNode.next := null ; return start; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printPrevGreater(arr,n): s=set() for i in range(0,n): it=[x for x in s if x>=arr[i]] if len(it)==0 : print("-1",end=" ") else : print(min(it),end=" ") s.add(arr[i]) if __name__=="__main__" : arr=[10,5,11,10,20,12] n=len(arr) printPrevGreater(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{10}->union(Sequence{5}->union(Sequence{11}->union(Sequence{10}->union(Sequence{20}->union(Sequence{ 12 }))))) ; n := (arr)->size() ; printPrevGreater(arr, n) ) else skip; operation printPrevGreater(arr : OclAny, n : OclAny) pre: true post: true activity: var s : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( var it : Sequence := s->select(x | (x->compareTo(arr[i+1])) >= 0)->collect(x | (x)) ; if (it)->size() = 0 then ( execute ("-1")->display() ) else ( execute ((it)->min())->display() ) ; execute ((arr[i+1]) : s)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getSum(n,d): if(ndisplay() ) else skip; operation getSum(n : OclAny, d : OclAny) : OclAny pre: true post: true activity: if ((n->compareTo(d)) < 0) then ( return 0 ) else skip ; while (n mod 10 /= d) do ( n := n - 1) ; var k : int := n div 10 ; return ((k + 1) * d + (k * 10 + 10 * k * k) div 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdout questions=[2,3,4,5,7,9,11,13,17,19,23,25,29,31,37,41,43,47,49] counter=0 for q in questions : print(q) stdout.flush() if input()=="yes" : counter+=1 if counter>1 : break if counter<2 : print("prime") else : print("composite") stdout.flush() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var questions : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{7}->union(Sequence{9}->union(Sequence{11}->union(Sequence{13}->union(Sequence{17}->union(Sequence{19}->union(Sequence{23}->union(Sequence{25}->union(Sequence{29}->union(Sequence{31}->union(Sequence{37}->union(Sequence{41}->union(Sequence{43}->union(Sequence{47}->union(Sequence{ 49 })))))))))))))))))) ; var counter : int := 0 ; for q : questions do ( execute (q)->display() ; stdout.flush() ; if (OclFile["System.in"]).readLine() = "yes" then ( counter := counter + 1 ; if counter > 1 then ( break ) else skip ) else skip) ; if counter < 2 then ( execute ("prime")->display() ) else ( execute ("composite")->display() ) ; stdout.flush(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) x=a h=0 s=0 while x>0 : x-=1 h+=1 s+=1 while s//b!=0 : h+=1 s=s-b+1 print(h) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := a ; var h : int := 0 ; var s : int := 0 ; while x > 0 do ( x := x - 1 ; h := h + 1 ; s := s + 1) ; while s div b /= 0 do ( h := h + 1 ; s := s - b + 1) ; execute (h)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- temp=[] ans=0 for i in range(2,50): if ans>=2 : break flag=True for j in temp : if i % j==0 : flag=False break if flag : temp.append(i) rr=i+0 while ans<2 : print(rr) if input()=="yes" : ans+=1 rr*=rr if rr>50 : break else : break if ans>=2 : print("composite") else : print("prime") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var temp : Sequence := Sequence{} ; var ans : int := 0 ; for i : Integer.subrange(2, 50-1) do ( if ans >= 2 then ( break ) else skip ; var flag : boolean := true ; for j : temp do ( if i mod j = 0 then ( flag := false ; break ) else skip) ; if flag then ( execute ((i) : temp) ; var rr : OclAny := i + 0 ; while ans < 2 do ( execute (rr)->display() ; if (OclFile["System.in"]).readLine() = "yes" then ( ans := ans + 1 ; rr := rr * rr ; if rr > 50 then ( break ) else skip ) else ( break )) ) else skip) ; if ans >= 2 then ( execute ("composite")->display() ) else ( execute ("prime")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- temp=[] ans=0 for i in range(2,50): if ans>=2 : break flag=True for j in temp : if i % j==0 : flag=False break if flag : temp.append(i) rr=i+0 while ans<2 : print(rr) if input()=="yes" : ans+=1 rr*=rr if rr>50 : break else : break if ans>=2 : print("composite") else : print("prime") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var temp : Sequence := Sequence{} ; var ans : int := 0 ; for i : Integer.subrange(2, 50-1) do ( if ans >= 2 then ( break ) else skip ; var flag : boolean := true ; for j : temp do ( if i mod j = 0 then ( flag := false ; break ) else skip) ; if flag then ( execute ((i) : temp) ; var rr : OclAny := i + 0 ; while ans < 2 do ( execute (rr)->display() ; if (OclFile["System.in"]).readLine() = "yes" then ( ans := ans + 1 ; rr := rr * rr ; if rr > 50 then ( break ) else skip ) else ( break )) ) else skip) ; if ans >= 2 then ( execute ("composite")->display() ) else ( execute ("prime")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- temp=[] ans=0 for i in range(2,50): if ans>=2 : break flag=True for j in temp : if i % j==0 : flag=False break if flag : temp.append(i) rr=i+0 while ans<2 : print(rr) if input()=="yes" : ans+=1 rr*=rr if rr>50 : break else : break if ans>=2 : print("composite") else : print("prime") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var temp : Sequence := Sequence{} ; var ans : int := 0 ; for i : Integer.subrange(2, 50-1) do ( if ans >= 2 then ( break ) else skip ; var flag : boolean := true ; for j : temp do ( if i mod j = 0 then ( flag := false ; break ) else skip) ; if flag then ( execute ((i) : temp) ; var rr : OclAny := i + 0 ; while ans < 2 do ( execute (rr)->display() ; if (OclFile["System.in"]).readLine() = "yes" then ( ans := ans + 1 ; rr := rr * rr ; if rr > 50 then ( break ) else skip ) else ( break )) ) else skip) ; if ans >= 2 then ( execute ("composite")->display() ) else ( execute ("prime")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdout p=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47] p2=[4,9,25,49] ans=0 for i in p : if ans>=2 : break print(i) stdout.flush() n=input()=='yes' ans+=1 if n else 0 for i in p2 : if ans>=2 : break print(i) stdout.flush() n=input()=='yes' ans+=1 if n else 0 print('prime' if ans<2 else 'composite') stdout.flush() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var p : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{11}->union(Sequence{13}->union(Sequence{17}->union(Sequence{19}->union(Sequence{23}->union(Sequence{29}->union(Sequence{31}->union(Sequence{37}->union(Sequence{41}->union(Sequence{43}->union(Sequence{ 47 })))))))))))))) ; var p2 : Sequence := Sequence{4}->union(Sequence{9}->union(Sequence{25}->union(Sequence{ 49 }))) ; var ans : int := 0 ; for i : p do ( if ans >= 2 then ( break ) else skip ; execute (i)->display() ; stdout.flush() ; var n : boolean := (OclFile["System.in"]).readLine() = 'yes' ; ans := ans + if n then 1 else 0 endif) ; for i : p2 do ( if ans >= 2 then ( break ) else skip ; execute (i)->display() ; stdout.flush() ; n := (OclFile["System.in"]).readLine() = 'yes' ; ans := ans + if n then 1 else 0 endif) ; execute (if ans < 2 then 'prime' else 'composite' endif)->display() ; stdout.flush(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() if n % 2==0 : p="" for i in range(0,n,2): p=p+(s[i : i+2]+"-") print(p[: len(p)-1]) else : p="" for i in range(0,n-3,2): p=p+(s[i : i+2]+"-") print(p+s[len(s)-3 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; if n mod 2 = 0 then ( var p : String := "" ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( p := p + (s.subrange(i+1, i + 2) + "-")) ; execute (p.subrange(1,(p)->size() - 1))->display() ) else ( p := "" ; for i : Integer.subrange(0, n - 3-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( p := p + (s.subrange(i+1, i + 2) + "-")) ; execute (p + s.subrange((s)->size() - 3+1))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=input() a=int(0) if n % 2==0 : for i in range(n): if i % 2==0 and i!=0 : m=''.join((m[:(i+a)],'-',m[(a+i):])) a+=1 elif n>3 : m=''.join(((m[:-3]),'-',m[-3 :])) for i in range(n-3): if i % 2==0 and i!=0 : m=''.join((m[:(i+a)],'-',m[(a+i):])) a+=1 print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : String := (OclFile["System.in"]).readLine() ; var a : int := ("" + ((0)))->toInteger() ; if n mod 2 = 0 then ( for i : Integer.subrange(0, n-1) do ( if i mod 2 = 0 & i /= 0 then ( m := StringLib.sumStringsWithSeparator((Sequence{m.subrange(1,(i + a)), '-', m.subrange((a + i)+1)}), '') ; a := a + 1 ) else skip) ) else (if n > 3 then ( m := StringLib.sumStringsWithSeparator((Sequence{(m.subrange(1,-3)), '-', m.subrange(-3+1)}), '') ; for i : Integer.subrange(0, n - 3-1) do ( if i mod 2 = 0 & i /= 0 then ( m := StringLib.sumStringsWithSeparator((Sequence{m.subrange(1,(i + a)), '-', m.subrange((a + i)+1)}), '') ; a := a + 1 ) else skip) ) else skip) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=input() x='' if n % 2==0 : for i in range(0,n,2): x+=(a[i]+a[i+1]+'-') else : for i in range(0,n-3,2): x+=(a[i]+a[i+1]+'-') x+=(a[n-3 : :]+'-') print(x[:-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : String := (OclFile["System.in"]).readLine() ; var x : String := '' ; if n mod 2 = 0 then ( for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( x := x + (a[i+1] + a[i + 1+1] + '-')) ) else ( for i : Integer.subrange(0, n - 3-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( x := x + (a[i+1] + a[i + 1+1] + '-')) ; x := x + (a(subscript (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 3)))))))) : (sliceop :)) + '-') ) ; execute (x->front())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) tel=input() tt=[]; ii=-2 for i in range(0,(n//2)*2,2): if itoInteger() ; var tel : String := (OclFile["System.in"]).readLine() ; var tt : Sequence := Sequence{}; var ii : int := -2 ; for i : Integer.subrange(0, (n div 2) * 2-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( if (i->compareTo(n - 3)) < 0 then ( ii := i ; execute ((tel.subrange(i+1, i + 2)) : tt) ) else skip) ; execute ((tel.subrange(ii + 2+1)) : tt) ; execute (StringLib.sumStringsWithSeparator((tt), "-"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) a=input() if n % 2==0 : print(a[0]+a[1],end="") i=2 else : print(a[0]+a[1]+a[2],end="") i=3 while itoInteger() ; var a : String := (OclFile["System.in"]).readLine() ; if n mod 2 = 0 then ( execute (a->first() + a[1+1])->display() ; var i : int := 2 ) else ( execute (a->first() + a[1+1] + a[2+1])->display() ; i := 3 ) ; while (i->compareTo(n)) < 0 do ( execute ("-" + a[i+1] + a[i + 1+1])->display() ; i := i + 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- code=""" #include using namespace std; #define dump(...)cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<int(a);) #define rep(i,n)repi(i,0,n) #define per(i,n)peri(i,0,n) #define all(c)begin(c),end(c) #define mp make_pair #define mt make_tuple typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; typedef pairpii; typedef vectorvi; typedef vectorvvi; typedef vectorvl; typedef vectorvvl; typedef vectorvd; typedef vectorvvd; typedef vectorvs; template ostream& operator<<(ostream& os,const pair& p){ return os<<'('< void print_tuple(ostream&,const Tuple&){} template void print_tuple(ostream& os,const Tuple& t){ print_tuple(os,t); os<<(sizeof...(Cdr)?",":"")<(t); } template ostream& operator<<(ostream& os,const tuple& t){ print_tuple(os<<'(',t); return os<<')'; } template basic_ostream& operator<<(basic_ostream& os,const C& c){ os<<'['; for(auto i=begin(c);i!=end(c);++i) os<<(i==begin(c)?"":" ")<<*i; return os<<']'; } constexpr int INF=1e9; constexpr int MOD=1e9+7; constexpr double EPS=1e-9; int dfs(const vvi& g,int u) { int res=1<>n>>m && n|m;){ arraycs; vvi g(n); rep(i,n){ cin>>cs[i]; int k; cin>>k; rep(j,k){ int r; cin>>r; g[i].push_back(r); } } arraybs; rep(i,n)bs[i]=dfs(g,i); static arraysums; sums.fill(0); rep(i,n)sums[1<>j&1)*bs[j]; if(sums[b]>=m)res=min(res,__builtin_popcount(b)); } cout<\r\nusing namespace std;\r\n\r\n#define dump(...)cout<<" # "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<int(a);)\r\n#define rep(i,n)repi(i,0,n)\r\n#define per(i,n)peri(i,0,n)\r\n#define all(c)begin(c),end(c)\r\n#define mp make_pair\r\n#define mt make_tuple\r\n\r\ntypedef unsigned int uint;\r\ntypedef long long ll;\r\ntypedef unsigned long long ull;\r\ntypedef pairpii;\r\ntypedef vectorvi;\r\ntypedef vectorvvi;\r\ntypedef vectorvl;\r\ntypedef vectorvvl;\r\ntypedef vectorvd;\r\ntypedef vectorvvd;\r\ntypedef vectorvs;\r\n\r\ntemplate\r\nostream& operator<<(ostream& os,const pair& p){\r\n\treturn os<<'('<\r\nvoid print_tuple(ostream&,const Tuple&){}\r\ntemplate\r\nvoid print_tuple(ostream& os,const Tuple& t){\r\n\tprint_tuple(os,t);\r\n\tos<<(sizeof...(Cdr)?" , ":" ")<(t);\r\n}\r\ntemplate\r\nostream& operator<<(ostream& os,const tuple& t){\r\n\tprint_tuple(os<<'(',t);\r\n\treturn os<<')';\r\n}\r\n\r\ntemplate\r\nbasic_ostream& operator<<(basic_ostream& os,const C& c){\r\n\tos<<'[';\r\n\tfor(auto i=begin(c);i!=end(c);++i)\r\n\t\tos<<(i==begin(c)?" ":" ")<<*i;\r\n\treturn os<<']';\r\n}\r\n\r\nconstexpr int INF=1e9;\r\nconstexpr int MOD=1e9+7;\r\nconstexpr double EPS=1e-9;\r\n\r\nint dfs(const vvi& g,int u)\r\n{\r\n\tint res=1<>n>>m && n|m;){\r\n\t\tarraycs;\r\n\t\tvvi g(n);\r\n\t\trep(i,n){\r\n\t\t\tcin>>cs[i];\r\n\t\t\tint k; cin>>k;\r\n\t\t\trep(j,k){\r\n\t\t\t\tint r; cin>>r;\r\n\t\t\t\tg[i].push_back(r);\r\n}\r\n}\r\n\r\n\t\tarraybs;\r\n\t\trep(i,n)bs[i]=dfs(g,i);\r\n\r\n\t\tstatic arraysums; sums.fill(0);\r\n\r\n\t\trep(i,n)sums[1<>j&1)*bs[j];\r\n\t\t\tif(sums[b]>=m)res=min(res,__builtin_popcount(b));\r\n}\r\n\t\tcout<collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{s1->first(),s1[1+1]} ; var res : int := 0 ; var unu : int := 0 ; while (true) do ( res := res + a ; unu := unu + a ; var a : int := ("" + ((unu / b)))->toInteger() ; unu := unu mod b ; if (a = 0) then ( break ) else skip) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections N=int(input()) A=list(map(int,input().split())) cnt=collections.Counter(A) Q=int(input()) tot=sum(A) for _ in range(Q): B,C=list(map(int,input().split())) if B in cnt : tot+=(C-B)*cnt[B] cnt[C]+=cnt[B] cnt[B]=0 print(tot) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : OclAny := .Counter(A) ; var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var tot : OclAny := (A)->sum() ; for _anon : Integer.subrange(0, Q-1) do ( var B : OclAny := null; var C : OclAny := null; Sequence{B,C} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (cnt)->includes(B) then ( tot := tot + (C - B) * cnt[B+1] ; cnt[C+1] := cnt[C+1] + cnt[B+1] ; cnt[B+1] := 0 ) else skip ; execute (tot)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np import math import scipy as sp import queue import collections MOD=10**9+7 INF=10**9 def main(kwargs): n=kwargs["n"] A=kwargs["A"] q=kwargs["q"] B=kwargs["B"] C=kwargs["C"] cnt=dict(collections.Counter(A)) res=[sum(A)] for i in range(q): if B[i]in cnt.keys(): res.append(res[-1]+(C[i]-B[i])*cnt[B[i]]) if C[i]in cnt.keys(): cnt[C[i]]+=cnt[B[i]] else : cnt[C[i]]=cnt[B[i]] cnt[B[i]]=0 else : res.append(res[-1]) res="\n".join([str(i)for i in res[1 :]]) return res if __name__=="__main__" : kwargs={} cin=input().split() kwargs["n"]=[int(i)for i in cin][0] cin=input().split() kwargs["A"]=[int(i)for i in cin] cin=input().split() kwargs["q"]=[int(i)for i in cin][0] kwargs["B"]=[] kwargs["C"]=[] for i in range(kwargs["q"]): cin=input().split() b,c=[int(i)for i in cin] kwargs["B"].append(b) kwargs["C"].append(c) cout=main(kwargs) print(cout) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var MOD : double := (10)->pow(9) + 7 ; var INF : double := (10)->pow(9) ; skip ; if __name__ = "__main__" then ( kwargs := Set{} ; var cin : OclAny := input().split() ; kwargs->at("n") := cin->select(i | true)->collect(i | (("" + ((i)))->toInteger()))->first() ; cin := input().split() ; kwargs->at("A") := cin->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; cin := input().split() ; kwargs->at("q") := cin->select(i | true)->collect(i | (("" + ((i)))->toInteger()))->first() ; kwargs->at("B") := Sequence{} ; kwargs->at("C") := Sequence{} ; for i : Integer.subrange(0, kwargs->at("q")-1) do ( cin := input().split() ; var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := cin->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; (expr (atom (name kwargs)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom "B"))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name kwargs)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom "C"))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))) ; var cout : OclAny := main(kwargs) ; execute (cout)->display() ) else skip; operation main(kwargs : OclAny) : OclAny pre: true post: true activity: var n : OclAny := kwargs->at("n") ; var A : OclAny := kwargs->at("A") ; var q : OclAny := kwargs->at("q") ; var B : OclAny := kwargs->at("B") ; var C : OclAny := kwargs->at("C") ; var cnt : Map := ((expr (atom (name collections)) (trailer . (name Counter) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)))))))) ))))) ; var res : Sequence := Sequence{ (A)->sum() } ; for i : Integer.subrange(0, q-1) do ( if (cnt.keys())->includes(B[i+1]) then ( execute ((res->last() + (C[i+1] - B[i+1]) * cnt[B[i+1]+1]) : res) ; if (cnt.keys())->includes(C[i+1]) then ( cnt[C[i+1]+1] := cnt[C[i+1]+1] + cnt[B[i+1]+1] ) else ( cnt[C[i+1]+1] := cnt[B[i+1]+1] ) ; cnt[B[i+1]+1] := 0 ) else ( execute ((res->last()) : res) )) ; res := StringLib.sumStringsWithSeparator((res->tail()->select(i | true)->collect(i | (("" + ((i)))))), "\n") ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) r=range a=list(map(int,input().split())) q=int(input()) d={} s=0 for i in r(n): cu=a[i] if d.get(cu,None): d[cu]+=1 else : d[cu]=1 s+=cu for _ in r(q): bi,ci=map(int,input().split()) diff=ci-bi if d.get(ci,None): d[ci]+=d.get(bi,0) else : d[ci]=d.get(bi,0) s+=diff*d.get(bi,0) print(s) if d.get(bi,None): d[bi]=0 if __name__=='__main__' : t=1 for _ in range(t): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solve()) ) else skip; operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r : OclAny := range ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : OclAny := Set{} ; var s : int := 0 ; for i : r(n) do ( var cu : OclAny := a[i+1] ; if d.get(cu, null) then ( d[cu+1] := d[cu+1] + 1 ) else ( d[cu+1] := 1 ) ; s := s + cu) ; for _anon : r(q) do ( var bi : OclAny := null; var ci : OclAny := null; Sequence{bi,ci} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var diff : double := ci - bi ; if d.get(ci, null) then ( d[ci+1] := d[ci+1] + d.get(bi, 0) ) else ( d[ci+1] := d.get(bi, 0) ) ; s := s + diff * d.get(bi, 0) ; execute (s)->display() ; if d.get(bi, null) then ( d[bi+1] := 0 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) q=int(input()) s=[list(map(int,input().split()))for i in range(q)] ans=sum(a) from collections import Counter cnt=Counter(a) for i,j in s : if j in cnt : cnt[j]+=cnt[i] else : cnt[j]=cnt[i] ans=ans-i*cnt[i]+cnt[i]*j if i in cnt : cnt.pop(i) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := Integer.subrange(0, q-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ans : OclAny := (a)->sum() ; skip ; var cnt : OclAny := Counter(a) ; for _tuple : s do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if (cnt)->includes(j) then ( cnt[j+1] := cnt[j+1] + cnt[i+1] ) else ( cnt[j+1] := cnt[i+1] ) ; ans := ans - i * cnt[i+1] + cnt[i+1] * j ; if (cnt)->includes(i) then ( cnt := cnt->excludingAt(i+1) ) else skip ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections n=int(input()) a=[int(i)for i in input().split()] q=int(input()) bc=[] for i in range(q): bc.append(list(map(int,input().split()))) c=collections.Counter(a) ans=sum(a) for i in range(q): add=bc[i][1]-bc[i][0] cnt=c[bc[i][0]] ans+=cnt*add c[bc[i][1]]+=c[bc[i][0]] c[bc[i][0]]=0 ; print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var bc : Sequence := Sequence{} ; for i : Integer.subrange(0, q-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : bc)) ; var c : OclAny := .Counter(a) ; var ans : OclAny := (a)->sum() ; for i : Integer.subrange(0, q-1) do ( var add : double := bc[i+1][1+1] - bc[i+1]->first() ; var cnt : OclAny := c[bc[i+1]->first()+1] ; ans := ans + cnt * add ; c[bc[i+1][1+1]+1] := c[bc[i+1][1+1]+1] + c[bc[i+1]->first()+1] ; c[bc[i+1]->first()+1] := 0; ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=(int)(input()) for i in range(t): w=input().split() n=(int)(w[0]) a=(int)(w[1]) b=(int)(w[2]) if a==1 : if(n-1)% b==0 : print("Yes") else : print("No") else : t=1 flag=0 while t<=n : if t % b==n % b : flag=1 break t=t*a if flag==1 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := (OclType["int"])((OclFile["System.in"]).readLine()) ; for i : Integer.subrange(0, t-1) do ( var w : OclAny := input().split() ; var n : OclAny := (OclType["int"])(w->first()) ; var a : OclAny := (OclType["int"])(w[1+1]) ; var b : OclAny := (OclType["int"])(w[2+1]) ; if a = 1 then ( if (n - 1) mod b = 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else ( t := 1 ; var flag : int := 0 ; while (t->compareTo(n)) <= 0 do ( if t mod b = n mod b then ( flag := 1 ; break ) else skip ; t := t * a) ; if flag = 1 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def in_set(n,a,b): if n==1 or n % b==1 or b==1 : return True x=1 while x<=n and a>1 : if x % b==n % b : return True x*=a return False q=int(input()) for i in range(q): n,a,b=map(int,input().split()) print('Yes' if in_set(n,a,b)else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if in_set(n, a, b) then 'Yes' else 'No' endif)->display()); operation in_set(n : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if n = 1 or n mod b = 1 or b = 1 then ( return true ) else skip ; var x : int := 1 ; while (x->compareTo(n)) <= 0 & a > 1 do ( if x mod b = n mod b then ( return true ) else skip ; x := x * a) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def in_set(n,a,b): if a==1 : return n % b==1 or b==1 x=1 while x<=n : if x % b==n % b : return True x*=a return False q=int(input()) for i in range(q): n,a,b=map(int,input().split()) print('Yes' if in_set(n,a,b)else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if in_set(n, a, b) then 'Yes' else 'No' endif)->display()); operation in_set(n : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a = 1 then ( return n mod b = 1 or b = 1 ) else skip ; var x : int := 1 ; while (x->compareTo(n)) <= 0 do ( if x mod b = n mod b then ( return true ) else skip ; x := x * a) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout def next_line(): return stdin.readline().rstrip() def next_int(): return int(next_line()) def out(text): stdout.write(str(text)+'\n') def main(): amount=next_int() for i in range(amount): n,a,b=map(lambda x : int(x),next_line().split()) out(solve(n,a,b)) def solve(n,a,b): if n==1 or b==1 : return 'Yes' if a==1 : return 'Yes' if(n-1)% b==0 else 'No' num=1 rem=n % b while num<=n : if rem==num % b : return 'Yes' num*=a return 'No' main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; main(); operation next_line() : OclAny pre: true post: true activity: return stdin.readLine().rstrip(); operation next_int() : OclAny pre: true post: true activity: return ("" + ((next_line())))->toInteger(); operation out(text : OclAny) pre: true post: true activity: stdout.write(("" + ((text))) + ' '); operation main() pre: true post: true activity: var amount : OclAny := next_int() ; for i : Integer.subrange(0, amount-1) do ( var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (next_line().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ) ; out(solve(n, a, b))); operation solve(n : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if n = 1 or b = 1 then ( return 'Yes' ) else skip ; if a = 1 then ( return if (n - 1) mod b = 0 then 'Yes' else 'No' endif ) else skip ; var num : int := 1 ; var rem : int := n mod b ; while (num->compareTo(n)) <= 0 do ( if rem = num mod b then ( return 'Yes' ) else skip ; num := num * a) ; return 'No'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=(int)(input()) for i in range(t): w=input().split() n=(int)(w[0]) a=(int)(w[1]) b=(int)(w[2]) if a==1 : if(n-1)% b==0 : print("Yes") else : print("No") else : t=1 flag=0 while t<=n : if t % b==n % b : flag=1 break t=t*a if flag==1 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := (OclType["int"])((OclFile["System.in"]).readLine()) ; for i : Integer.subrange(0, t-1) do ( var w : OclAny := input().split() ; var n : OclAny := (OclType["int"])(w->first()) ; var a : OclAny := (OclType["int"])(w[1+1]) ; var b : OclAny := (OclType["int"])(w[2+1]) ; if a = 1 then ( if (n - 1) mod b = 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else ( t := 1 ; var flag : int := 0 ; while (t->compareTo(n)) <= 0 do ( if t mod b = n mod b then ( flag := 1 ; break ) else skip ; t := t * a) ; if flag = 1 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print("YNEOS"[input()!=input()[: :-1]: : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ("YNEOS"(subscript (test (logical_test (comparison (comparison (expr (atom (name input)) (trailer (arguments ( ))))) != (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ]))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) f=lambda k,s :(2*s-k+1)*k-s if kcollect( _x | (OclType["int"])->apply(_x) ) ; var f : Function := lambda k : OclAny, s : OclAny in (if (k->compareTo(s)) < 0 then (2 * s - k + 1) * k - s else (s - 2) * s + 2 * k endif) ; var s : OclAny := null; var m : OclAny := null; Sequence{s,m} := Sequence{m div n + 1,2 * m + 1} ; while (f->apply(k, s) + f->apply(n - k + 1, s)->compareTo(m)) < 0 do ( s := s + 1) ; execute (s - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- code=""" #include #include #include #include using namespace std; #define dump(...)cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<int(a);) #define rep(i,n)repi(i,0,n) #define per(i,n)peri(i,0,n) #define all(c)begin(c),end(c) #define mp make_pair #define mt make_tuple typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; typedef pairpii; typedef vectorvi; typedef vectorvvi; typedef vectorvl; typedef vectorvvl; typedef vectorvd; typedef vectorvvd; typedef vectorvs; constexpr int INF=1e9; constexpr int MOD=1e9+7; constexpr double EPS=1e-9; int dfs(const vvi& g,int u) { int res=1<>n>>m && n|m;){ arraycs; vvi g(n); rep(i,n){ cin>>cs[i]; int k; cin>>k; rep(j,k){ int r; cin>>r; g[i].push_back(r); } } arraybs; rep(i,n)bs[i]=dfs(g,i); static arraysums; sums.fill(0); rep(i,n)sums[1<>j&1)*bs[j]; if(sums[b]>=m)res=min(res,__builtin_popcount(b)); } cout<\r\n#include\r\n#include\r\n#include\r\nusing namespace std;\r\n\r\n#define dump(...)cout<<" # "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<int(a);)\r\n#define rep(i,n)repi(i,0,n)\r\n#define per(i,n)peri(i,0,n)\r\n#define all(c)begin(c),end(c)\r\n#define mp make_pair\r\n#define mt make_tuple\r\n\r\ntypedef unsigned int uint;\r\ntypedef long long ll;\r\ntypedef unsigned long long ull;\r\ntypedef pairpii;\r\ntypedef vectorvi;\r\ntypedef vectorvvi;\r\ntypedef vectorvl;\r\ntypedef vectorvvl;\r\ntypedef vectorvd;\r\ntypedef vectorvvd;\r\ntypedef vectorvs;\r\n\r\nconstexpr int INF=1e9;\r\nconstexpr int MOD=1e9+7;\r\nconstexpr double EPS=1e-9;\r\n\r\nint dfs(const vvi& g,int u)\r\n{\r\n\tint res=1<>n>>m && n|m;){\r\n\t\tarraycs;\r\n\t\tvvi g(n);\r\n\t\trep(i,n){\r\n\t\t\tcin>>cs[i];\r\n\t\t\tint k; cin>>k;\r\n\t\t\trep(j,k){\r\n\t\t\t\tint r; cin>>r;\r\n\t\t\t\tg[i].push_back(r);\r\n}\r\n}\r\n\r\n\t\tarraybs;\r\n\t\trep(i,n)bs[i]=dfs(g,i);\r\n\r\n\t\tstatic arraysums; sums.fill(0);\r\n\r\n\t\trep(i,n)sums[1<>j&1)*bs[j];\r\n\t\t\tif(sums[b]>=m)res=min(res,__builtin_popcount(b));\r\n}\r\n\t\tcout<select(i | true)->collect(i | (Integer.subrange(0, 1003-1)->select(_anon | true)->collect(_anon | (0)))) ; skip ; skip ; preComputeCoeff() ; N := 3 ; execute (computeStringCount(N))->display(); operation preComputeCoeff() pre: true post: true activity: for i : Integer.subrange(0, Max-1) do ( for j : Integer.subrange(0, i + 1-1) do ( if (j = 0 or j = i) then ( nCr[i+1][j+1] := 1 ) else ( nCr[i+1][j+1] := (nCr[i - 1+1][j - 1+1] + nCr[i - 1+1][j+1]) mod mod ))); operation computeStringCount(N : OclAny) : OclAny pre: true post: true activity: var n : int := N div 2 ; var ans : int := 0 ; for i : Integer.subrange(2, n + 1-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( ans := (ans + ((nCr[n+1][i+1] * nCr[n+1][i div 2+1]) mod mod)) mod mod) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- arr=[0]*32 def balTernary(ter): carry,base,i=0,10,31 while ter>0 : rem=(ter % base)+carry if rem==0 : arr[i]=0 carry,i=0,i-1 elif rem==1 : arr[i]=1 carry,i=0,i-1 elif rem==2 : arr[i]=-1 carry,i=1,i-1 elif rem==3 : arr[i]=0 carry,i=1,i-1 ter=ter//base if carry==1 : arr[i]=1 def ternary(number): ans,rem,base=0,1,1 while number>0 : rem=number % 3 ans=ans+rem*base number//=3 base=base*10 return ans if __name__=="__main__" : number=3056 ter=ternary(number) balTernary(ter) i=0 while arr[i]==0 : i+=1 for j in range(i,32): if arr[j]==-1 : print('Z',end="") else : print(arr[j],end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 32) ; skip ; skip ; if __name__ = "__main__" then ( number := 3056 ; ter := ternary(number) ; balTernary(ter) ; var i : int := 0 ; while arr[i+1] = 0 do ( i := i + 1) ; for j : Integer.subrange(i, 32-1) do ( if arr[j+1] = -1 then ( execute ('Z')->display() ) else ( execute (arr[j+1])->display() )) ) else skip; operation balTernary(ter : OclAny) pre: true post: true activity: var carry : OclAny := null; var base : OclAny := null; var i : OclAny := null; Sequence{carry,base,i} := Sequence{0,10,31} ; while ter > 0 do ( var rem : int := (ter mod base) + carry ; if rem = 0 then ( arr[i+1] := 0 ; var carry : OclAny := null; var i : OclAny := null; Sequence{carry,i} := Sequence{0,i - 1} ) else (if rem = 1 then ( arr[i+1] := 1 ; var carry : OclAny := null; var i : OclAny := null; Sequence{carry,i} := Sequence{0,i - 1} ) else (if rem = 2 then ( arr[i+1] := -1 ; var carry : OclAny := null; var i : OclAny := null; Sequence{carry,i} := Sequence{1,i - 1} ) else (if rem = 3 then ( arr[i+1] := 0 ; var carry : OclAny := null; var i : OclAny := null; Sequence{carry,i} := Sequence{1,i - 1} ) else skip ) ) ) ; ter := ter div base) ; if carry = 1 then ( arr[i+1] := 1 ) else skip; operation ternary(number : OclAny) : OclAny pre: true post: true activity: var ans : OclAny := null; var base : OclAny := null; Sequence{ans,rem,base} := Sequence{0,1,1} ; while number > 0 do ( rem := number mod 3 ; var ans : OclAny := ans + rem * base ; number := number div 3 ; var base : double := base * 10) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() t=input() t="".join(reversed(t)) if s==t : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; t := StringLib.sumStringsWithSeparator(((t)->reverse()), "") ; if s = t then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() t=input() if s[: :-1]==t : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; if s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) = t then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- st1=input() st2=input() if st1==st2[: :-1]: print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var st1 : String := (OclFile["System.in"]).readLine() ; var st2 : String := (OclFile["System.in"]).readLine() ; if st1 = st2(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() y=input() if x==y[: :-1]: print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := (OclFile["System.in"]).readLine() ; var y : String := (OclFile["System.in"]).readLine() ; if x = y(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s1=input() s2=input() if s1[: :-1]==s2 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s1 : String := (OclFile["System.in"]).readLine() ; var s2 : String := (OclFile["System.in"]).readLine() ; if s1(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) = s2 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : str="A computer science portal for geeks" for i in range(0,len(str),1): if(str[i]==' '): str=str.replace(str[i],'-') print(str) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var OclType["String"] : String := "A computer science portal for geeks" ; for i : Integer.subrange(0, (OclType["String"])->size()-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (("" + ([i+1])) = ' ') then ( OclType["String"] := ("" + (.replace(("" + ([i+1])), '-'))) ) else skip) ; execute (OclType["String"])->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxCount(A,N,K): maximum=0 start=0 end=0 j=0 A.sort() for i in range(0,N): while(junion(Sequence{26}->union(Sequence{17}->union(Sequence{12}->union(Sequence{15}->union(Sequence{ 2 }))))) ; N := (A)->size() ; K := 5 ; execute (maxCount(A, N, K))->display(); operation maxCount(A : OclAny, N : OclAny, K : OclAny) : OclAny pre: true post: true activity: var maximum : int := 0 ; var start : int := 0 ; var end : int := 0 ; var j : int := 0 ; A := A->sort() ; for i : Integer.subrange(0, N-1) do ( while ((j->compareTo(N)) < 0 & (A[j+1]->compareTo(A[i+1] + K)) <= 0) do ( j := j + 1) ; if (maximum->compareTo((j - i))) < 0 then ( maximum := (j - i) ; start := i; ; end := j; ) else skip) ; return maximum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=[int(x)for x in input().split()] time=0 c=0 while a>0 : time+=a c+=a a=(c/b)//1 c-=((c/b)//1)*b print(str(int(time))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var time : int := 0 ; var c : int := 0 ; while a > 0 do ( time := time + a ; c := c + a ; var a : int := (c / b) div 1 ; c := c - ((c / b) div 1) * b) ; execute (("" + ((("" + ((time)))->toInteger()))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input e=enumerate for _ in[0]*int(I()): n=int(I()); r=[[*I()]for _ in[0]*n];(i,j),(k,l)=[(i,j)for i,s in e(r)for j,x in e(s)if '.'>x]; k=(k+(k==i))% n ; l=(l+(l==j))% n ; r[k][l]=r[i][l]=r[k][j]='*' for s in r : print(*s,sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; var e : OclAny := enumerate ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + ((I())))->toInteger()) do ( var n : int := ("" + ((I())))->toInteger(); var r : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n)->select(_anon | true)->collect(_anon | (I())); var Sequence{i, j} : OclAny := null; var Sequence{k, l} : OclAny := null; Sequence{Sequence{i, j},Sequence{k, l}} := e(r)->select(_tuple | let i : OclAny = _tuple->at(1) in let s : OclAny = _tuple->at(2) in true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let s : OclAny = _tuple->at(2) in (Sequence{i, j})); var k : int := (k + (k = i)) mod n; var l : int := (l + (l = j)) mod n; r[k+1][l+1] := r[k+1][l+1](assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name r)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name l)))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name r)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom '*')))))))) ; for s : r do ( execute ((argument * (test (logical_test (comparison (expr (atom (name s))))))))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=3 M=3 def check(a,b): for i in range(1,N,1): for j in range(1,M,1): if(a[i][j]!=b[i][j]): a[i][j]^=1 a[0][0]^=1 a[0][j]^=1 a[i][0]^=1 for i in range(N): for j in range(M): if(a[i][j]!=b[i][j]): return False return True if __name__=='__main__' : a=[[0,1,0],[0,1,0],[1,0,0]] b=[[1,0,0],[1,0,0],[1,0,0]] if(check(a,b)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 3 ; var M : int := 3 ; skip ; if __name__ = '__main__' then ( a := Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{ 0 }))}->union(Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{ 0 }))}->union(Sequence{ Sequence{1}->union(Sequence{0}->union(Sequence{ 0 })) })) ; b := Sequence{Sequence{1}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{Sequence{1}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{ Sequence{1}->union(Sequence{0}->union(Sequence{ 0 })) })) ; if (check(a, b)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation check(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(1, N-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( for j : Integer.subrange(1, M-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if (a[i+1][j+1] /= b[i+1][j+1]) then ( a[i+1][j+1] := a[i+1][j+1] xor 1 ; a->first()->first() := a->first()->first() xor 1 ; a->first()[j+1] := a->first()[j+1] xor 1 ; a[i+1]->first() := a[i+1]->first() xor 1 ) else skip)) ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, M-1) do ( if (a[i+1][j+1] /= b[i+1][j+1]) then ( return false ) else skip)) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for x in range(int(input())): n=int(input()); l=[]; m=[] for i in range(n): s=input(); sb=[] for e in s : sb.append(e) l.append(sb) for j in range(n): if s[j]=='*' : m.append([i,j]) x1,x2,y1,y2=m[0][0],m[1][0],m[0][1],m[1][1] if x1!=x2 and y1!=y2 : l[x1][y2]='*' ; l[x2][y1]='*' elif x1==x2 : sp=(abs(y1-y2)+x1)% n l[sp][y1]='*' ; l[sp][y2]='*' else : sp=(abs(x1-x2)+y1)% n l[x1][sp]='*' ; l[x2][sp]='*' for ll in l : print(''.join(ll)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for x : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var l : Sequence := Sequence{}; var m : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine(); var sb : Sequence := Sequence{} ; for e : s->characters() do ( execute ((e) : sb)) ; execute ((sb) : l) ; for j : Integer.subrange(0, n-1) do ( if s[j+1] = '*' then ( execute ((Sequence{i}->union(Sequence{ j })) : m) ) else skip)) ; var x1 : OclAny := null; var x2 : OclAny := null; var y1 : OclAny := null; var y2 : OclAny := null; Sequence{x1,x2,y1,y2} := Sequence{m->first()->first(),m[1+1]->first(),m->first()[1+1],m[1+1][1+1]} ; if x1 /= x2 & y1 /= y2 then ( l[x1+1][y2+1] := '*'; l[x2+1][y1+1] := '*' ) else (if x1 = x2 then ( var sp : int := ((y1 - y2)->abs() + x1) mod n ; l[sp+1][y1+1] := '*'; l[sp+1][y2+1] := '*' ) else ( sp := ((x1 - x2)->abs() + y1) mod n ; l[x1+1][sp+1] := '*'; l[x2+1][sp+1] := '*' ) ) ; for ll : l do ( execute (StringLib.sumStringsWithSeparator((ll), ''))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : n=int(input()) li=[] for i in range(n): a=list(input()) li.append(a) new=[] for i in range(n): for j in range(n): if li[i][j]=="*" : new.append([i,j]) a=new[0][0] b=new[0][1] c=new[1][0] d=new[1][1] if a==c : if atoInteger() ; while t do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : Sequence := ((OclFile["System.in"]).readLine())->characters() ; execute ((a) : li)) ; var new : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if li[i+1][j+1] = "*" then ( execute ((Sequence{i}->union(Sequence{ j })) : new) ) else skip)) ; a := new->first()->first() ; var b : OclAny := new->first()[1+1] ; var c : OclAny := new[1+1]->first() ; var d : OclAny := new[1+1][1+1] ; if a = c then ( if (a->compareTo(n - 1)) < 0 then ( li->restrict(MatrixLib.elementwiseAdd(a, 1))[b+1] := "*" ; li[c + 1+1][d+1] := "*" ) else ( li[a - 1+1][b+1] := "*" ; li[c - 1+1][d+1] := "*" ) ) else (if b = d then ( if (b->compareTo(n - 1)) < 0 then ( li->restrict(a)[b + 1+1] := "*" ; li[c+1][d + 1+1] := "*" ) else ( li->restrict(a)[b - 1+1] := "*" ; li[c+1][d - 1+1] := "*" ) ) else ( li->restrict(a)[d+1] := "*" ; li[c+1][b+1] := "*" ) ) ; for i : li do ( for j : i do ( execute (j)->display()) ; execute ("")->display()) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def maxSubArraySum(a,size): max_so_far=-(sys.maxsize-1); max_ending_here=0 ; for i in range(size): max_ending_here=max_ending_here+a[i]; if(max_so_farunion(Sequence{-2}->union(Sequence{ 3 })); ; n := (a)->size(); ; K := 2; ; execute (minimizedSum(a, n, K))->display(); ) else skip; operation maxSubArraySum(a : OclAny, size : OclAny) pre: true post: true activity: var max_so_far : double := -((trailer . (name maxsize)) - 1); ; var max_ending_here : int := 0; ; for i : Integer.subrange(0, size-1) do ( max_ending_here := max_ending_here + a[i+1]; ; if ((max_so_far->compareTo(max_ending_here)) < 0) then ( max_so_far := max_ending_here; ) else skip ; if (max_ending_here < 0) then ( max_ending_here := 0; ) else skip) ; return max_so_far;; operation minimizedSum(a : OclAny, n : OclAny, K : OclAny) pre: true post: true activity: var sum : OclAny := maxSubArraySum(a, n); ; var totalSum : int := 0; ; for i : Integer.subrange(0, n-1) do ( totalSum := totalSum + a[i+1];) ; if (sum < 0) then ( return totalSum; ) else skip ; totalSum := totalSum - sum + sum / K; ; return totalSum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): while b : a,b=b,a % b return a def f(n,m): if m==1 : return 0 x=1 for i in range(m): x=(x*n)% m if x==1 : return i+1 while 1 : a,b=map(int,input().split()) if a==0 : break c=gcd(a,b) a//=c ; b//=c cnt=0 ; d=gcd(b,10) while d!=1 : b//=d cnt+=1 d=gcd(b,10) print(cnt,f(10,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while 1 do ( Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 0 then ( break ) else skip ; var c : OclAny := gcd(a, b) ; a := a div c; b := b div c ; var cnt : int := 0; var d : OclAny := gcd(b, 10) ; while d /= 1 do ( b := b div d ; cnt := cnt + 1 ; d := gcd(b, 10)) ; execute (cnt)->display()); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: while b do ( Sequence{a,b} := Sequence{b,a mod b}) ; return a; operation f(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: if m = 1 then ( return 0 ) else skip ; var x : int := 1 ; for i : Integer.subrange(0, m-1) do ( x := (x * n) mod m ; if x = 1 then ( return i + 1 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def noOfMoves(arr,n): cnt=0 maxCnt=0 for i in range(n): if(arr[i]==1): cnt+=1 else : if(cnt!=0): maxCnt=max(maxCnt,cnt) cnt=0 print(maxCnt) if __name__=='__main__' : arr=[0,1,1,1,1,0,0,1,1,0,0,1] N=len(arr) noOfMoves(arr,N) arr1=[1,0,1,0,1,0,1,0] N=len(arr1) noOfMoves(arr1,N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 1 }))))))))))) ; var N : int := (arr)->size() ; noOfMoves(arr, N) ; var arr1 : Sequence := Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 0 }))))))) ; N := (arr1)->size() ; noOfMoves(arr1, N) ) else skip; operation noOfMoves(arr : OclAny, n : OclAny) pre: true post: true activity: var cnt : int := 0 ; var maxCnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] = 1) then ( cnt := cnt + 1 ) else ( if (cnt /= 0) then ( maxCnt := Set{maxCnt, cnt}->max() ; cnt := 0 ) else skip )) ; execute (maxCnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minChanges(str,n): count,zeros,ones=0,0,0 if(ord(str[0])!=ord('1')): count+=1 ones+=1 for i in range(1,n): if(ord(str[i])==ord('0')): zeros+=1 else : ones+=1 if(zeros>ones): zeros-=1 ones+=1 count+=1 return count if __name__=='__main__' : str="0000" n=len(str) print(minChanges(str,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( OclType["String"] := "0000" ; n := (OclType["String"])->size() ; execute (minChanges(OclType["String"], n))->display() ) else skip; operation minChanges(OclType["String"] : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count : OclAny := null; var zeros : OclAny := null; var ones : OclAny := null; Sequence{count,zeros,ones} := Sequence{0,0,0} ; if ((("" + (->first())))->char2byte() /= ('1')->char2byte()) then ( count := count + 1 ; ones := ones + 1 ) else skip ; for i : Integer.subrange(1, n-1) do ( if ((("" + ([i+1])))->char2byte() = ('0')->char2byte()) then ( zeros := zeros + 1 ) else ( ones := ones + 1 ) ; if ((zeros->compareTo(ones)) > 0) then ( zeros := zeros - 1 ; ones := ones + 1 ; count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) cnt=0 ans='' st=list() for x in a : while cnttoInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : int := 0 ; var ans : String := '' ; var st : Sequence := () ; for x : a do ( while (cnt->compareTo(x)) < 0 do ( ans := ans + '(' ; cnt := cnt + 1 ; execute ((cnt) : st)) ; if st->last() = x then ( st := st->front() ; ans := ans + ')' ) else ( ans := ':(' ; break )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque import sys sys.setrecursionlimit(10**7) N=int(input()) P=list(map(int,input().split())) Q=[-1]*N for i,p in enumerate(P): Q[p-1]=i S='' a=1 def rec(l,r): global S,a if l==r : return while l=r : print(':(') exit() a+=1 S+='(' rec(l,ai) S+=')' l=ai+1 rec(0,N) print(S) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute S : OclAny; attribute a : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var P : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var Q : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, N) ; for _tuple : Integer.subrange(1, (P)->size())->collect( _indx | Sequence{_indx-1, (P)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p : OclAny := _tuple->at(_indx); Q[p - 1+1] := i) ; var S : String := '' ; var a : int := 1 ; skip ; rec(0, N) ; execute (S)->display(); operation rec(l : OclAny, r : OclAny) pre: true post: true activity: skip; skip ; if l = r then ( return ) else skip ; while (l->compareTo(r)) < 0 do ( var ai : OclAny := Q[a - 1+1] ; if (ai->compareTo(r)) >= 0 then ( execute (':(')->display() ; exit() ) else skip ; a := a + 1 ; S := S + '(' ; rec(l, ai) ; S := S + ')' ; l := ai + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re candeleIntere,b=map(int,input().split()) s=0 restoSciolte=0 while candeleIntere>0 or restoSciolte>=b : candeleIntere+=restoSciolte//b restoSciolte %=b s+=candeleIntere restoSciolte+=candeleIntere % b candeleIntere//=b print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var candeleIntere : OclAny := null; var b : OclAny := null; Sequence{candeleIntere,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : int := 0 ; var restoSciolte : int := 0 ; while candeleIntere > 0 or (restoSciolte->compareTo(b)) >= 0 do ( candeleIntere := candeleIntere + restoSciolte div b ; restoSciolte := restoSciolte mod b ; s := s + candeleIntere ; restoSciolte := restoSciolte + candeleIntere mod b ; candeleIntere := candeleIntere div b) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(a==0 or b==0): return 0 if(a==b): return a if(a>b): return gcd(a-b,b) return gcd(a,b-a) def squarearea(l,b): if(l<0 or b<0): return-1 n=(l*b)/gcd(l,b) return n*n if __name__=='__main__' : l=6 b=4 print(int(squarearea(l,b))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( l := 6 ; b := 4 ; execute (("" + ((squarearea(l, b))))->toInteger())->display() ) else skip; operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0 or b = 0) then ( return 0 ) else skip ; if (a = b) then ( return a ) else skip ; if ((a->compareTo(b)) > 0) then ( return gcd(a - b, b) ) else skip ; return gcd(a, b - a); operation squarearea(l : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (l < 0 or b < 0) then ( return -1 ) else skip ; var n : double := (l * b) / gcd(l, b) ; return n * n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def totalSubSets(n,l,r): MOD=1000000007 ; zero=(math.floor(r/3)-math.ceil(l/3)+1); one=(math.floor((r-1)/3)-math.ceil((l-1)/3)+1); two=(math.floor((r-2)/3)-math.ceil((l-2)/3)+1); dp=[[0 for x in range(3)]for y in range(n)] dp[0][0]=zero ; dp[0][1]=one ; dp[0][2]=two ; for i in range(1,n): dp[i][0]=((dp[i-1][0]*zero)+(dp[i-1][1]*two)+(dp[i-1][2]*one))% MOD ; dp[i][1]=((dp[i-1][0]*one)+(dp[i-1][1]*zero)+(dp[i-1][2]*two))% MOD ; dp[i][2]=((dp[i-1][0]*two)+(dp[i-1][1]*one)+(dp[i-1][2]*zero))% MOD ; return dp[n-1][0]; n=5 ; l=10 ; r=100 ; print(totalSubSets(n,l,r)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 5; ; l := 10; ; r := 100; ; execute (totalSubSets(n, l, r))->display();; operation totalSubSets(n : OclAny, l : OclAny, r : OclAny) pre: true post: true activity: var MOD : int := 1000000007; ; var zero : double := ((r / 3)->floor() - (l / 3)->ceil() + 1); ; var one : double := (((r - 1) / 3)->floor() - ((l - 1) / 3)->ceil() + 1); ; var two : double := (((r - 2) / 3)->floor() - ((l - 2) / 3)->ceil() + 1); ; var dp : Sequence := Integer.subrange(0, n-1)->select(y | true)->collect(y | (Integer.subrange(0, 3-1)->select(x | true)->collect(x | (0)))) ; dp->first()->first() := zero; ; dp->first()[1+1] := one; ; dp->first()[2+1] := two; ; for i : Integer.subrange(1, n-1) do ( dp[i+1]->first() := ((dp[i - 1+1]->first() * zero) + (dp[i - 1+1][1+1] * two) + (dp[i - 1+1][2+1] * one)) mod MOD; ; dp[i+1][1+1] := ((dp[i - 1+1]->first() * one) + (dp[i - 1+1][1+1] * zero) + (dp[i - 1+1][2+1] * two)) mod MOD; ; dp[i+1][2+1] := ((dp[i - 1+1]->first() * two) + (dp[i - 1+1][1+1] * one) + (dp[i - 1+1][2+1] * zero)) mod MOD;) ; return dp[n - 1+1]->first();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getMinimumOps(ar,k): n=len(ar) dp=[[0 for i in range(k+1)]for i in range(n)] dp[0][1]=0 for i in range(1,n): maxGroups=min(k,i+1) for j in range(1,maxGroups+1): dp[i][j]=10**9 if(j==1): freq1=dict() freqOfMode=0 for it in range(0,i+1): freq1[ar[it]]=freq1.get(ar[it],0)+1 newElementFreq=freq1[ar[it]] if(newElementFreq>freqOfMode): freqOfMode=newElementFreq dp[i][1]=(i+1)-freqOfMode else : freq=dict() freqOfMode=0 for it in range(i,j-2,-1): freq[ar[it]]=freq.get(ar[it],0)+1 newElementFreq=freq[ar[it]] if(newElementFreq>freqOfMode): freqOfMode=newElementFreq elementsToChange=i-it+1 elementsToChange-=freqOfMode dp[i][j]=min(dp[it-1][j-1]+elementsToChange,dp[i][j]) return dp[n-1][k] k=3 ar=[3,1,3,3,2,1,8,5] print(getMinimumOps(ar,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; k := 3 ; ar := Sequence{3}->union(Sequence{1}->union(Sequence{3}->union(Sequence{3}->union(Sequence{2}->union(Sequence{1}->union(Sequence{8}->union(Sequence{ 5 }))))))) ; execute (getMinimumOps(ar, k))->display(); operation getMinimumOps(ar : OclAny, k : OclAny) : OclAny pre: true post: true activity: var n : int := (ar)->size() ; var dp : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, k + 1-1)->select(i | true)->collect(i | (0)))) ; dp->first()[1+1] := 0 ; for i : Integer.subrange(1, n-1) do ( var maxGroups : OclAny := Set{k, i + 1}->min() ; for j : Integer.subrange(1, maxGroups + 1-1) do ( dp[i+1][j+1] := (10)->pow(9) ; if (j = 1) then ( var freq1 : Map := (arguments ( )) ; var freqOfMode : int := 0 ; for it : Integer.subrange(0, i + 1-1) do ( freq1[ar[it+1]+1] := freq1.get(ar[it+1], 0) + 1 ; var newElementFreq : OclAny := freq1[ar[it+1]+1] ; if ((newElementFreq->compareTo(freqOfMode)) > 0) then ( freqOfMode := newElementFreq ) else skip) ; dp[i+1][1+1] := (i + 1) - freqOfMode ) else ( var freq : Map := (arguments ( )) ; freqOfMode := 0 ; for it : Integer.subrange(j - 2 + 1, i)->reverse() do ( freq[ar[it+1]+1] := freq.get(ar[it+1], 0) + 1 ; newElementFreq := freq[ar[it+1]+1] ; if ((newElementFreq->compareTo(freqOfMode)) > 0) then ( freqOfMode := newElementFreq ) else skip ; var elementsToChange : double := i - it + 1 ; elementsToChange := elementsToChange - freqOfMode ; dp[i+1][j+1] := Set{dp[it - 1+1][j - 1+1] + elementsToChange, dp[i+1][j+1]}->min()) ))) ; return dp[n - 1+1][k+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def findDimen(H,A): if H*H<4*A : print("Not Possible") return apb=sqrt(H*H+4*A) asb=sqrt(H*H-4*A) print("P=","%.2f" %((apb-asb)/2.0)) print("B=","%.2f" %((apb+asb)/2.0)) H=5 A=6 findDimen(H,A) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; H := 5 ; A := 6 ; findDimen(H, A); operation findDimen(H : OclAny, A : OclAny) pre: true post: true activity: if (H * H->compareTo(4 * A)) < 0 then ( execute ("Not Possible")->display() ; return ) else skip ; var apb : OclAny := sqrt(H * H + 4 * A) ; var asb : OclAny := sqrt(H * H - 4 * A) ; execute ("P=")->display() ; execute ("B=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rangesum(n,l,r): arr=[0]*n ; c=1 ; i=0 ; while(c<=n): arr[i]=c ; i+=1 ; c+=2 ; c=2 ; while(c<=n): arr[i]=c ; i+=1 ; c+=2 ; sum=0 ; for i in range(l-1,r,1): sum+=arr[i]; return sum ; if __name__=='__main__' : n=12 ; l,r=1,11 ; print(rangesum(n,l,r)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 12; ; Sequence{l,r} := Sequence{1,11}; ; execute (rangesum(n, l, r))->display(); ) else skip; operation rangesum(n : OclAny, l : OclAny, r : OclAny) pre: true post: true activity: var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; var c : int := 1; var i : int := 0; ; while ((c->compareTo(n)) <= 0) do ( arr[i+1] := c; ; i := i + 1; ; c := c + 2;) ; c := 2; ; while ((c->compareTo(n)) <= 0) do ( arr[i+1] := c; ; i := i + 1; ; c := c + 2;) ; var sum : int := 0; ; for i : Integer.subrange(l - 1, r-1)->select( $x | ($x - l - 1) mod 1 = 0 ) do ( sum := sum + arr[i+1];) ; return sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- toch,dlin=map(int,input().split()) otrez=[0]*(dlin+1) for i in range(toch): nach,konec=map(int,input().split()) for j in range(nach,konec+1): otrez[j]=1 pust=otrez.count(0)-1 print(pust) if pust!=0 : for i in range(1,dlin+1): if otrez[i]!=1 : print(i,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var toch : OclAny := null; var dlin : OclAny := null; Sequence{toch,dlin} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var otrez : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (dlin + 1)) ; for i : Integer.subrange(0, toch-1) do ( var nach : OclAny := null; var konec : OclAny := null; Sequence{nach,konec} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for j : Integer.subrange(nach, konec + 1-1) do ( otrez[j+1] := 1)) ; var pust : double := otrez->count(0) - 1 ; execute (pust)->display() ; if pust /= 0 then ( for i : Integer.subrange(1, dlin + 1-1) do ( if otrez[i+1] /= 1 then ( execute (i)->display() ) else skip) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=[] for i in range(1,m+1): a.append(i) for a1 in range(n): x,y=map(int,input().split()) for a2 in range(x,y+1): if a2 in a : a.remove(a2) print(len(a)) for i in a : print(i,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{} ; for i : Integer.subrange(1, m + 1-1) do ( execute ((i) : a)) ; for a1 : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for a2 : Integer.subrange(x, y + 1-1) do ( if (a)->includes(a2) then ( execute ((a2) /: a) ) else skip)) ; execute ((a)->size())->display() ; for i : a do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) seg=[list(map(int,input().split()))for i in range(n)] def bad(x): for i in range(n): if(seg[i][0]<=x and x<=seg[i][1]): return False return True ans=list(filter(bad,[i for i in range(1,m+1)])) print(len(ans)) print(' '.join([str(x)for x in ans])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var seg : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; skip ; var ans : Sequence := ((Integer.subrange(1, m + 1-1)->select(i | true)->collect(i | (i)))->select( _x | (bad)->apply(_x) = true )) ; execute ((ans)->size())->display() ; execute (StringLib.sumStringsWithSeparator((ans->select(x | true)->collect(x | (("" + ((x)))))), ' '))->display(); operation bad(x : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if ((seg[i+1]->first()->compareTo(x)) <= 0 & (x->compareTo(seg[i+1][1+1])) <= 0) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=list(map(int,input().split())) l=[] for i in range(n): a,b=list(map(int,input().split())) w=[x for x in range(a,b+1)] l=l+w k=[x for x in range(1,m+1)] ch="" s=0 for i in range(len(k)): if(k[i]not in l): ch=ch+str(k[i])+" " s=s+1 print(s) print(ch) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var w : Sequence := Integer.subrange(a, b + 1-1)->select(x | true)->collect(x | (x)) ; l := l->union(w)) ; var k : Sequence := Integer.subrange(1, m + 1-1)->select(x | true)->collect(x | (x)) ; var ch : String := "" ; var s : int := 0 ; for i : Integer.subrange(0, (k)->size()-1) do ( if ((l)->excludes(k[i+1])) then ( ch := ch + ("" + ((k[i+1]))) + " " ; s := s + 1 ) else skip) ; execute (s)->display() ; execute (ch)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) exist=[] for i in range(n): x,y=map(int,input().split()) for j in range(x,y+1): if j not in exist : exist.append(j) print(m-len(exist)) for i in range(1,m+1): if i not in exist : print(i,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var exist : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for j : Integer.subrange(x, y + 1-1) do ( if (exist)->excludes(j) then ( execute ((j) : exist) ) else skip)) ; execute (m - (exist)->size())->display() ; for i : Integer.subrange(1, m + 1-1) do ( if (exist)->excludes(i) then ( execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(map(int,input().split())) a,b=s[0],s[1] k=a while a//b>0 : k=k+a//b a=(a//b)+(a % b) print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{s->first(),s[1+1]} ; var k : OclAny := a ; while a div b > 0 do ( k := k + a div b ; var a : int := (a div b) + (a mod b)) ; execute (k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input().split(' ') n=int(s[0]) m1=int(s[1])-1 m=m1 l=[] s="" def f(str1): i1=m+1 i2=m while i1!=0 and i1!=1 : if str1[i2]!=str1[m-i2]: return False else : i2-=1 i1-=2 return True for i in range(n): obj=input() if f(obj): s=obj else : l.append(obj) while len(l)!=0 : for obj1 in l : l.remove(obj1) s1=obj1[0] for obj2 in l : m=m1 s2=obj2[m] if s1==s2 : r=obj1+obj2 m=len(r)-1 if f(r): s=obj1+s+obj2 l.remove(obj2) print(len(s)) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := input().split(' ') ; var n : int := ("" + ((s->first())))->toInteger() ; var m1 : double := ("" + ((s[1+1])))->toInteger() - 1 ; var m : OclAny := m1 ; var l : Sequence := Sequence{} ; s := "" ; skip ; for i : Integer.subrange(0, n-1) do ( var obj : String := (OclFile["System.in"]).readLine() ; if f(obj) then ( s := obj ) else ( execute ((obj) : l) )) ; while (l)->size() /= 0 do ( for obj1 : l do ( execute ((obj1) /: l) ; var s1 : OclAny := obj1->first() ; for obj2 : l do ( m := m1 ; var s2 : OclAny := obj2[m+1] ; if s1 = s2 then ( var r : OclAny := obj1 + obj2 ; m := (r)->size() - 1 ; if f(r) then ( s := obj1 + s + obj2 ; execute ((obj2) /: l) ) else skip ) else skip))) ; execute ((s)->size())->display() ; execute (s)->display(); operation f(str1 : OclAny) : OclAny pre: true post: true activity: var i1 : OclAny := m + 1 ; var i2 : OclAny := m ; while i1 /= 0 & i1 /= 1 do ( if str1[i2+1] /= str1[m - i2+1] then ( return false ) else ( i2 := i2 - 1 ; i1 := i1 - 2 )) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,s=map(int,input().split()); l=[] for i in range(n): l.append(input()) s1="" ; f=0 ; st="" d=dict() for i in l : d[i]=0 for i in l : s3=i[: :-1] if s3==i : st=i elif d[i]==0 : if s3 in d and d[s3]==0 : d[s3]=1 ; d[i]=2 ; s1+=i ans=s1+st+s1[: :-1] le=len(ans) print(le); print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : l)) ; var s1 : String := ""; var f : int := 0; var st : String := "" ; var d : Map := (arguments ( )) ; for i : l do ( d[i+1] := 0) ; for i : l do ( var s3 : OclAny := i(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; if s3 = i then ( st := i ) else (if d[i+1] = 0 then ( if (d)->includes(s3) & d[s3+1] = 0 then ( d[s3+1] := 1; d[i+1] := 2; s1 := s1 + i ) else skip ) else skip)) ; var ans : String := s1 + st + s1(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var le : int := (ans)->size() ; execute (le)->display(); execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) setagem=set() ans='' aux='' for i in range(N): s=input() reverso=s[: :-1] if(s==reverso): aux=reverso elif reverso in setagem : ans+=reverso setagem.add(s) ans=ans[: :-1]+aux+ans print(len(ans)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var setagem : Set := Set{}->union(()) ; var ans : String := '' ; var aux : String := '' ; for i : Integer.subrange(0, N-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var reverso : OclAny := s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; if (s = reverso) then ( aux := reverso ) else (if (setagem)->includes(reverso) then ( ans := ans + reverso ) else skip) ; execute ((s) : setagem)) ; ans := ans(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) + aux + ans ; execute ((ans)->size())->display() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CntcontSubs(a,n): c=0 d=0 sum=1 for i in range(n): if(a[i]% 2!=0 or a[i]% 4==0): d+=1 sum=a[i] for j in range(i+1,n): sum=sum*a[j] if(sum % 2!=0 or sum % 4==0): c+=1 sum=1 return c+d if __name__=='__main__' : arr=[5,4,2,9,8] n=len(arr) print(CntcontSubs(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var arr : Sequence := Sequence{5}->union(Sequence{4}->union(Sequence{2}->union(Sequence{9}->union(Sequence{ 8 })))) ; n := (arr)->size() ; execute (CntcontSubs(arr, n))->display() ) else skip; operation CntcontSubs(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var c : int := 0 ; var d : int := 0 ; var sum : int := 1 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] mod 2 /= 0 or a[i+1] mod 4 = 0) then ( d := d + 1 ) else skip ; sum := a[i+1] ; for j : Integer.subrange(i + 1, n-1) do ( sum := sum * a[j+1] ; if (sum mod 2 /= 0 or sum mod 4 = 0) then ( c := c + 1 ) else skip) ; sum := 1) ; return c + d; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def PROBLEM(): n,m=map(int,input().split()) T=[] for _ in range(n): T.append(input()) S='' i=0 Nb=1 while T!=[]: P=RecherchePosPali(T,n,T[i]) if P!=-1 : S=T[i]+S+T[P] T.remove(T[P]) T.remove(T[i]) n-=2 elif Nb and S[: len(S)//2]+T[i]+S[len(S)//2 :]==(S[: len(S)//2]+T[i]+S[len(S)//2 :])[: :-1]: S=S[: len(S)//2]+T[i]+S[len(S)//2 :] T.remove(T[i]) n-=1 Nb=0 else : T.remove(T[i]) n-=1 print(len(S)) print(S) def RecherchePosPali(T,n,S): P=-1 i=1 while P==-1 and icollect( _x | (OclType["int"])->apply(_x) ) ; var T : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : T)) ; var S : String := '' ; var i : int := 0 ; var Nb : int := 1 ; while T /= Sequence{} do ( var P : OclAny := RecherchePosPali(T, n, T[i+1]) ; if P /= -1 then ( S := T[i+1] + S + T[P+1] ; execute ((T[P+1]) /: T) ; execute ((T[i+1]) /: T) ; n := n - 2 ) else (if Nb & S.subrange(1,(S)->size() div 2) + T[i+1] + S.subrange((S)->size() div 2+1) = (S.subrange(1,(S)->size() div 2) + T[i+1] + S.subrange((S)->size() div 2+1))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( S := S.subrange(1,(S)->size() div 2) + T[i+1] + S.subrange((S)->size() div 2+1) ; execute ((T[i+1]) /: T) ; n := n - 1 ; Nb := 0 ) else ( execute ((T[i+1]) /: T) ; n := n - 1 ) ) ) ; execute ((S)->size())->display() ; execute (S)->display(); operation RecherchePosPali(T : OclAny, n : OclAny, S : OclAny) : OclAny pre: true post: true activity: P := -1 ; i := 1 ; while P = -1 & (i->compareTo(n)) < 0 do ( if S = T[i+1](subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( P := i ) else ( i := i + 1 )) ; return P; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input().split(' ') n=int(s[0]) m1=int(s[1])-1 m=m1 l=[] s="" def f(str1): i1=m+1 i2=m while i1!=0 and i1!=1 : if str1[i2]!=str1[m-i2]: return False else : i2-=1 i1-=2 return True for i in range(n): obj=input() if f(obj): s=obj else : l.append(obj) while len(l)!=0 : for obj1 in l : l.remove(obj1) s1=obj1[0] for obj2 in l : m=m1 s2=obj2[m] if s1==s2 : r=obj1+obj2 m=len(r)-1 if f(r): s=obj1+s+obj2 l.remove(obj2) print(len(s)) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := input().split(' ') ; var n : int := ("" + ((s->first())))->toInteger() ; var m1 : double := ("" + ((s[1+1])))->toInteger() - 1 ; var m : OclAny := m1 ; var l : Sequence := Sequence{} ; s := "" ; skip ; for i : Integer.subrange(0, n-1) do ( var obj : String := (OclFile["System.in"]).readLine() ; if f(obj) then ( s := obj ) else ( execute ((obj) : l) )) ; while (l)->size() /= 0 do ( for obj1 : l do ( execute ((obj1) /: l) ; var s1 : OclAny := obj1->first() ; for obj2 : l do ( m := m1 ; var s2 : OclAny := obj2[m+1] ; if s1 = s2 then ( var r : OclAny := obj1 + obj2 ; m := (r)->size() - 1 ; if f(r) then ( s := obj1 + s + obj2 ; execute ((obj2) /: l) ) else skip ) else skip))) ; execute ((s)->size())->display() ; execute (s)->display(); operation f(str1 : OclAny) : OclAny pre: true post: true activity: var i1 : OclAny := m + 1 ; var i2 : OclAny := m ; while i1 /= 0 & i1 /= 1 do ( if str1[i2+1] /= str1[m - i2+1] then ( return false ) else ( i2 := i2 - 1 ; i1 := i1 - 2 )) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(a,b,c): return a*b<100*c m,rd,rr,cd,cr=map(int,input().split()) ex=cd*100//rd if(f(ex,rd,cd)): ex+=1 ey=cr*100//rr if(f(ey,rr,cr)): ey+=1 print(m-ex-ey if m-ex-ey>=0 else-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var m : OclAny := null; var rd : OclAny := null; var rr : OclAny := null; var cd : OclAny := null; var cr : OclAny := null; Sequence{m,rd,rr,cd,cr} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ex : int := cd * 100 div rd ; if (f(ex, rd, cd)) then ( ex := ex + 1 ) else skip ; var ey : int := cr * 100 div rr ; if (f(ey, rr, cr)) then ( ey := ey + 1 ) else skip ; execute (if m - ex - ey >= 0 then m - ex - ey else -1 endif)->display(); operation f(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: return (a * b->compareTo(100 * c)) < 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getMin(arr,n): return min(arr) def getMax(arr,n): return max(arr) if __name__=='__main__' : arr=[12,1234,45,67,1] n=len(arr) print("Minimum element of array: ",getMin(arr,n)) print("Maximum element of array: ",getMax(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{12}->union(Sequence{1234}->union(Sequence{45}->union(Sequence{67}->union(Sequence{ 1 })))) ; n := (arr)->size() ; execute ("Minimum element of array: ")->display() ; execute ("Maximum element of array: ")->display() ) else skip; operation getMin(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: return (arr)->min(); operation getMax(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: return (arr)->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() Kco=a.count('K') Uco=a.count('U') Pco=a.count('P') Cco=a.count('C') print(min(Kco,Uco,Pco,Cco)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var Kco : int := a->count('K') ; var Uco : int := a->count('U') ; var Pco : int := a->count('P') ; var Cco : int := a->count('C') ; execute (Set{Kco, Uco, Pco, Cco}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x='KUPC' y=[0]*4 z=input() for i in range(len(z)): if z[i]in x : y[x.index(z[i])]+=1 else : continue print(min(y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := 'KUPC' ; var y : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 4) ; var z : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, (z)->size()-1) do ( if (x)->characters()->includes(z[i+1]) then ( y[x->indexOf(z[i+1]) - 1+1] := y[x->indexOf(z[i+1]) - 1+1] + 1 ) else ( continue )) ; execute ((y)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def getSum(n): sm=0 while(n!=0): sm=sm+n % 10 n=n//10 return sm def largestDigitSumdivisior(n): res=0 for i in range(1,(int)(math.sqrt(n))+1): if(n % i==0): res=max(res,getSum(i)) res=max(res,getSum(n//i)) return res n=14 print(largestDigitSumdivisior(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 14 ; execute (largestDigitSumdivisior(n))->display(); operation getSum(n : OclAny) : OclAny pre: true post: true activity: var sm : int := 0 ; while (n /= 0) do ( sm := sm + n mod 10 ; n := n div 10) ; return sm; operation largestDigitSumdivisior(n : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; for i : Integer.subrange(1, (OclType["int"])((n)->sqrt()) + 1-1) do ( if (n mod i = 0) then ( res := Set{res, getSum(i)}->max() ; res := Set{res, getSum(n div i)}->max() ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=str(input()) k=(s.count('K')) u=(s.count('U')) p=(s.count('P')) c=(s.count('C')) x=min(k,u,p,c) print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; var k : int := (s->count('K')) ; var u : int := (s->count('U')) ; var p : int := (s->count('P')) ; var c : int := (s->count('C')) ; var x : OclAny := Set{k, u, p, c}->min() ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() a=list(a) l=0 m=0 n=0 o=0 for i in range(len(a)): if a[i]=="K" : l+=1 if a[i]=="U" : m+=1 if a[i]=="P" : n+=1 if a[i]=="C" : o+=1 min=l zero=0 if min>m : zero=m m=min min=zero zero=0 if min>n : zero=n n=min min=zero zero=0 if min>o : zero=o o=min min=zero print(min) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; a := (a)->characters() ; var l : int := 0 ; var m : int := 0 ; var n : int := 0 ; var o : int := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( if a[i+1] = "K" then ( l := l + 1 ) else skip ; if a[i+1] = "U" then ( m := m + 1 ) else skip ; if a[i+1] = "P" then ( n := n + 1 ) else skip ; if a[i+1] = "C" then ( o := o + 1 ) else skip) ; var min : int := l ; var zero : int := 0 ; if (min->compareTo(m)) > 0 then ( zero := m ; m := min ; min := zero ) else skip ; zero := 0 ; if (min->compareTo(n)) > 0 then ( zero := n ; n := min ; min := zero ) else skip ; zero := 0 ; if (min->compareTo(o)) > 0 then ( zero := o ; o := min ; min := zero ) else skip ; execute (min)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() lis=[] a=x.count('K') lis.append(a) b=x.count('U') lis.append(b) c=x.count('P') lis.append(c) d=x.count('C') lis.append(d) print(min(lis)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := (OclFile["System.in"]).readLine() ; var lis : Sequence := Sequence{} ; var a : int := x->count('K') ; execute ((a) : lis) ; var b : int := x->count('U') ; execute ((b) : lis) ; var c : int := x->count('P') ; execute ((c) : lis) ; var d : int := x->count('C') ; execute ((d) : lis) ; execute ((lis)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def findTriplets(arr,n,Sum): for i in range(n-1): s=dict() for j in range(i+1,n): x=Sum-(arr[i]+arr[j]) if x in s.keys(): print(x,arr[i],arr[j]) else : s[arr[j]]=1 arr=[0,-1,2,-3,1] Sum=-2 n=len(arr) findTriplets(arr,n,Sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{0}->union(Sequence{-1}->union(Sequence{2}->union(Sequence{-3}->union(Sequence{ 1 })))) ; Sum := -2 ; n := (arr)->size() ; findTriplets(arr, n, Sum); operation findTriplets(arr : OclAny, n : OclAny, Sum : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n - 1-1) do ( var s : Map := (arguments ( )) ; for j : Integer.subrange(i + 1, n-1) do ( var x : double := Sum - (arr[i+1] + arr[j+1]) ; if (s.keys())->includes(x) then ( execute (x)->display() ) else ( s[arr[j+1]+1] := 1 ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(s): for i in range(len(s)): if s[0]!=s[i]: return 1 return 0 s=input() a=s while a!="" : if a[0]!=a[-1]: print(len(s)) exit() else : a=a[1 : len(a)-1 :] if f(s)==1 : print(len(s)-1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := (OclFile["System.in"]).readLine() ; var a : OclAny := s ; while a /= "" do ( if a->first() /= a->last() then ( execute ((s)->size())->display() ; exit() ) else ( a := a(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))) - (expr (atom (number (integer 1)))))))) (sliceop :)) )) ; if f(s) = 1 then ( execute ((s)->size() - 1)->display() ) else ( execute (0)->display() ); operation f(s : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, (s)->size()-1) do ( if s->first() /= s[i+1] then ( return 1 ) else skip) ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) pros=sorted([list(map(int,input().split()))for _ in range(m)]) index=0 covered=0 right=0 ans=0 while True : a,b=pros[index] if a>covered+1 : if covered==right : print("Impossible") break covered=right ans+=1 continue else : right=max(right,b) index+=1 if covered==n : print(ans) break if index==m : covered=right ans+=1 print(ans if covered==n else "Impossible") break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var pros : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))->sort() ; var index : int := 0 ; var covered : int := 0 ; var right : int := 0 ; var ans : int := 0 ; while true do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := pros[index+1] ; if (a->compareTo(covered + 1)) > 0 then ( if covered = right then ( execute ("Impossible")->display() ; break ) else skip ; covered := right ; ans := ans + 1 ; continue ) else ( right := Set{right, b}->max() ; index := index + 1 ) ; if covered = n then ( execute (ans)->display() ; break ) else skip ; if index = m then ( covered := right ; ans := ans + 1 ; execute (if covered = n then ans else "Impossible" endif)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getPairs(a): n=len(a) count=(n*(n-1))//2 return count a=[2,4,3,1] print(getPairs(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{2}->union(Sequence{4}->union(Sequence{3}->union(Sequence{ 1 }))) ; execute (getPairs(a))->display(); operation getPairs(a : OclAny) : OclAny pre: true post: true activity: var n : int := (a)->size() ; var count : int := (n * (n - 1)) div 2 ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left n=int(input()) A=tuple(map(int,input().split())) q=int(input()) for _ in range(q): k=int(input()) print(bisect_left(A,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (bisect_left(A, k))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def LowerBound(d,l): max=len(l)-1 min=0 mid=max//2 while True : if(l[mid]>d): max=mid elif(l[mid]==d): while l[mid]==d and mid>=0 : mid-=1 return mid+1 else : min=mid mid=(max+min)//2 if(mid==max or mid==min): if(l[mid]==d or l[max]==d): while l[mid]==d and mid>=0 : mid-=1 return mid+1 if(l[max]d): return min return max def main(): nl=int(input()) l=list(map(int,input().split())) for i in range(int(input())): n=int(input()) result=LowerBound(n,l) print(result) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation LowerBound(d : OclAny, l : OclAny) : OclAny pre: true post: true activity: var max : double := (l)->size() - 1 ; var min : int := 0 ; var mid : int := max div 2 ; while true do ( if ((l[mid+1]->compareTo(d)) > 0) then ( max := mid ) else (if (l[mid+1] = d) then ( while l[mid+1] = d & mid >= 0 do ( mid := mid - 1) ; return mid + 1 ) else ( min := mid ) ) ; mid := (max + min) div 2 ; if (mid = max or mid = min) then ( if (l[mid+1] = d or l[max+1] = d) then ( while l[mid+1] = d & mid >= 0 do ( mid := mid - 1) ; return mid + 1 ) else skip ; if ((l[max+1]->compareTo(d)) < 0) then ( return (l)->size() ) else skip ; if ((l[mid+1]->compareTo(d)) > 0) then ( return min ) else skip ; return max ) else skip); operation main() pre: true post: true activity: var nl : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; l := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var result : OclAny := LowerBound(n, l) ; execute (result)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binarySearch(n,a): ok=len(a) ng=-1 while abs(ok-ng)>1 : mid=(ok+ng)//2 if a[mid]>=n : ok=mid else : ng=mid return ok def resolve(): import sys input=sys.stdin.readline n=int(input()) a=[int(i)for i in input().split()] q=int(input()) for _ in range(q): k=int(input()) print(binarySearch(k,a)) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; resolve(); operation binarySearch(n : OclAny, a : OclAny) : OclAny pre: true post: true activity: var ok : int := (a)->size() ; var ng : int := -1 ; while (ok - ng)->abs() > 1 do ( var mid : int := (ok + ng) div 2 ; if (a[mid+1]->compareTo(n)) >= 0 then ( ok := mid ) else ( ng := mid )) ; return ok; operation resolve() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (binarySearch(k, a))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rel(w): global ans if w==set(): return print(str(len(w))+'\n'+' '.join(map(str,w))) res=list(map(int,input().split())) for i in range(n): if i+1 not in w : ans[i]=min(ans[i],res[i]) n=int(input()) ans=[10**10]*n a=[(1,n)] for i in range(10): b=[n+1] for l,r in a : b+=[l,(l+r)//2+1] b.sort() m=len(b) w=set() for j in range(0,m-1,2): w |={x for x in range(b[j],b[j+1])} rel(w) rel(w ^{i for i in range(1,n+1)}) a=[(b[j],b[j+1]-1)for j in range(m-1)] print('-1\n'+' '.join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute ans : OclAny; operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; ans := MatrixLib.elementwiseMult(Sequence{ (10)->pow(10) }, n) ; var a : Sequence := Sequence{ Sequence{1, n} } ; for i : Integer.subrange(0, 10-1) do ( var b : Sequence := Sequence{ n + 1 } ; for _tuple : a do (var _indx : int := 1; var l : OclAny := _tuple->at(_indx); _indx := _indx + 1; var r : OclAny := _tuple->at(_indx); b := b + Sequence{l}->union(Sequence{ (l + r) div 2 + 1 })) ; b := b->sort() ; var m : int := (b)->size() ; w := Set{}->union(()) ; for j : Integer.subrange(0, m - 1-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( w := w or Integer.subrange(b[j+1], b[j + 1+1]-1)->select(x | true)->collect(x | x)->asSet()) ; rel(w) ; rel(MathLib.bitwiseXor(w, Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | i)->asSet())) ; a := Integer.subrange(0, m - 1-1)->select(j | true)->collect(j | (Sequence{b[j+1], b[j + 1+1] - 1}))) ; execute ('-1 ' + StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); operation rel(w : OclAny) pre: true post: true activity: skip ; if w = Set{}->union(()) then ( return ) else skip ; execute (("" + (((w)->size()))) + ' ' + StringLib.sumStringsWithSeparator(((w)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ; var res : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( if (w)->excludes(i + 1) then ( ans[i+1] := Set{ans[i+1], res[i+1]}->min() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect def main(): n=int(input()) li=[int(a)for a in input().split()] q=int(input()) for _ in range(q): k=int(input()) i=bisect.bisect_left(li,k) print(i) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li : Sequence := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : OclAny := bisect.bisect_left(li, k) ; execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect readline=open(0).readline N=int(readline()) *A,=map(int,readline().split()) open(1,'w').writelines(["%d\n" % bisect(A,int(readline())-1)for q in range(int(readline()))]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := open(0).readline ; var N : int := ("" + ((readline())))->toInteger() ; (testlist_star_expr (star_expr * (expr (atom (name A)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name A)))) ,)} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name open)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom 'w'))))))) ))) (trailer . (name writelines) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom "%d\n")) % (expr (atom (name bisect)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name readline)) (trailer (arguments ( ))))))))) )))) - (expr (atom (number (integer 1)))))))))) )))))))) (comp_for for (exprlist (expr (atom (name q)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name readline)) (trailer (arguments ( ))))))))) ))))))))) )))))))) ]))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printPalindrome(left,mid,right): for x in left : print(x,end="") print(mid,end="") right=right[: :-1] for x in right : print(x,end="") print('\n',end="") def findPalindrome(S,N,M): d=set() for i in range(M): d.add(S[i]) left=[] right=[] mid="" for i in range(N): t=S[i] t=t[: :-1] if(t==S[i]): mid=t elif(t in d): left.append(S[i]) right.append(t) d.remove(S[i]) d.remove(t) printPalindrome(left,mid,right) if __name__=='__main__' : S=["tab","one","bat"] M=3 N=len(S) findPalindrome(S,N,M) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( S := Sequence{"tab"}->union(Sequence{"one"}->union(Sequence{ "bat" })) ; M := 3 ; N := (S)->size() ; findPalindrome(S, N, M) ) else skip; operation printPalindrome(left : OclAny, mid : OclAny, right : OclAny) pre: true post: true activity: for x : left do ( execute (x)->display()) ; execute (mid)->display() ; right := right(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; for x : right do ( execute (x)->display()) ; execute (' ')->display(); operation findPalindrome(S : OclAny, N : OclAny, M : OclAny) pre: true post: true activity: var d : Set := Set{}->union(()) ; for i : Integer.subrange(0, M-1) do ( execute ((S[i+1]) : d)) ; left := Sequence{} ; right := Sequence{} ; mid := "" ; for i : Integer.subrange(0, N-1) do ( var t : OclAny := S[i+1] ; t := t(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; if (t = S[i+1]) then ( mid := t ) else (if ((d)->includes(t)) then ( execute ((S[i+1]) : left) ; execute ((t) : right) ; execute ((S[i+1]) /: d) ; execute ((t) /: d) ) else skip)) ; printPalindrome(left, mid, right); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def findlargestAfterDel(arr,m,dell,n): mp=dict() for i in range(n): if dell[i]in mp.keys(): mp[dell[i]]+=1 else : mp[dell[i]]=1 largestElement=-10**9 for i in range(m): if(arr[i]in mp.keys()): mp[arr[i]]-=1 if(mp[arr[i]]==0): mp.pop(arr[i]) else : largestElement=max(largestElement,arr[i]) return largestElement array=[5,12,33,4,56,12,20] m=len(array) dell=[12,33,56,5] n=len(dell) print(findlargestAfterDel(array,m,dell,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var array : Sequence := Sequence{5}->union(Sequence{12}->union(Sequence{33}->union(Sequence{4}->union(Sequence{56}->union(Sequence{12}->union(Sequence{ 20 })))))) ; m := (array)->size() ; dell := Sequence{12}->union(Sequence{33}->union(Sequence{56}->union(Sequence{ 5 }))) ; n := (dell)->size() ; execute (findlargestAfterDel(array, m, dell, n))->display(); operation findlargestAfterDel(arr : OclAny, m : OclAny, dell : OclAny, n : OclAny) : OclAny pre: true post: true activity: var mp : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( if (mp.keys())->includes(dell[i+1]) then ( mp[dell[i+1]+1] := mp[dell[i+1]+1] + 1 ) else ( mp[dell[i+1]+1] := 1 )) ; var largestElement : double := (-10)->pow(9) ; for i : Integer.subrange(0, m-1) do ( if ((mp.keys())->includes(arr[i+1])) then ( mp[arr[i+1]+1] := mp[arr[i+1]+1] - 1 ; if (mp[arr[i+1]+1] = 0) then ( mp := mp->excludingAt(arr[i+1]+1) ) else skip ) else ( largestElement := Set{largestElement, arr[i+1]}->max() )) ; return largestElement; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): x0=3 y0=1 x=x0 y=y0 while True : sqrt=eulerlib.sqrt(y**2*8+1) if sqrt % 2==1 : blue=(sqrt+1)//2+y if blue+y>10**12 : return str(blue) nextx=x*x0+y*y0*8 nexty=x*y0+y*x0 x=nextx y=nexty if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var x0 : int := 3 ; var y0 : int := 1 ; var x : int := x0 ; var y : int := y0 ; while true do ( var sqrt : double := eulerlib.sqrt((y)->pow(2) * 8 + 1) ; if sqrt mod 2 = 1 then ( var blue : int := (sqrt + 1) div 2 + y ; if (blue + y->compareTo((10)->pow(12))) > 0 then ( return ("" + ((blue))) ) else skip ) else skip ; var nextx : int := x * x0 + y * y0 * 8 ; var nexty : int := x * y0 + y * x0 ; x := nextx ; y := nexty); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() res=[*set(x)] def isPalindrome(s): return s==s[: :-1] if len(res)==1 : print("0") elif isPalindrome(x): print(len(x)-1) elif len(res)==1 : print("0") else : print(len(x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := (OclFile["System.in"]).readLine() ; var res : Sequence := Set{}->union((x)) ; skip ; if (res)->size() = 1 then ( execute ("0")->display() ) else (if isPalindrome(x) then ( execute ((x)->size() - 1)->display() ) else (if (res)->size() = 1 then ( execute ("0")->display() ) else ( execute ((x)->size())->display() ) ) ) ; operation isPalindrome(s : OclAny) : OclAny pre: true post: true activity: return s = s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- varun=int(input()) for n in range(varun): print(3*varun+n,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var varun : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for n : Integer.subrange(0, varun-1) do ( execute (3 * varun + n)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(*range(n,n+n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((argument * (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (name n))))))))) )))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) base=n first=int(n/math.pow(10,int(math.log10(n)))) base*=10 base//=first print(*range(base,base+n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var base : int := n ; var first : int := ("" + ((n / (10)->pow(("" + (((n)->log10())))->toInteger()))))->toInteger() ; base := base * 10 ; base := base div first ; execute ((argument * (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name base))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name base))) + (expr (atom (name n))))))))) )))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=10000000 for i in range(n,0,-1): print(x-i,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := 10000000 ; for i : Integer.subrange(0 + 1, n)->reverse() do ( execute (x - i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdout n=int(input()) ans=[10**10]*n th=1 while thtoInteger() ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ (10)->pow(10) }, n) ; var th : int := 1 ; while (th->compareTo(n)) < 0 do ( var ask : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((i mod (2 * th)->compareTo(th)) < 0)) ; for _anon : Integer.subrange(0, 2-1) do ( var inds : Sequence := Integer.subrange(1, (ask)->size())->collect( _indx | Sequence{_indx-1, (ask)->at(_indx)} )->select(_tuple | let key : OclAny = _tuple->at(1) in let value : OclAny = _tuple->at(2) in value)->collect(_tuple | let key : OclAny = _tuple->at(1) in let value : OclAny = _tuple->at(2) in (key)) ; execute ((inds)->size())->display() ; execute (StringLib.sumStringsWithSeparator((inds->select(i | true)->collect(i | (("" + ((i + 1)))))), ' '))->display() ; stdout.flush() ; var reply : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; ans := Integer.subrange(0, n-1)->select(i | true)->collect(i | (if ask[i+1] then ans[i+1] else Set{ans[i+1], reply[i+1]}->min() endif)) ; ask := ask->select(v | true)->collect(v | (not(v)))) ; th := th * 2) ; execute (-1)->display() ; execute (StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ; stdout.flush(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) for i in range(a): print(3*a+i,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, a-1) do ( execute (3 * a + i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPowerOfTwo(x): return x and(not(x &(x-1))) def differAtOneBitPos(a,b): return isPowerOfTwo(a ^ b) a=13 b=9 if(differAtOneBitPos(a,b)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 13 ; b := 9 ; if (differAtOneBitPos(a, b)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isPowerOfTwo(x : OclAny) : OclAny pre: true post: true activity: return x & (not((MathLib.bitwiseAnd(x, (x - 1))))); operation differAtOneBitPos(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return isPowerOfTwo(MathLib.bitwiseXor(a, b)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): a=int(input()) n=input() if a % 2==1 : has_odd=False x=0 while x0 : solve() t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( solve() ; t := t - 1); operation solve() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : String := (OclFile["System.in"]).readLine() ; if a mod 2 = 1 then ( var has_odd : boolean := false ; var x : int := 0 ; while (x->compareTo(a)) < 0 do ( if ("" + ((n[x+1])))->toInteger() mod 2 = 1 then ( has_odd := true ; break ) else skip ; x := x + 2) ; if has_odd then ( execute (1)->display() ) else ( execute (2)->display() ) ) else ( var even : boolean := false ; x := 1 ; while (x->compareTo(a)) < 0 do ( if ("" + ((n[x+1])))->toInteger() mod 2 = 0 then ( even := true ; break ) else ( x := x + 2 )) ; if even then ( execute (2)->display() ) else ( execute (1)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): m=int(input()) n=input() r="" b="" if(m==1 and int(n)% 2==0): print(2) elif(m==1 and int(n)% 2!=0): print(1) else : for i in range(m): if(i % 2==0): r=r+n[i] else : b=b+n[i] if(m % 2==0): for i in b : if int(i)% 2==0 : print(2) break else : print(1) else : for i in r : if int(i)% 2!=0 : print(1) break else : print(2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : String := (OclFile["System.in"]).readLine() ; var r : String := "" ; var b : String := "" ; if (m = 1 & ("" + ((n)))->toInteger() mod 2 = 0) then ( execute (2)->display() ) else (if (m = 1 & ("" + ((n)))->toInteger() mod 2 /= 0) then ( execute (1)->display() ) else ( for i : Integer.subrange(0, m-1) do ( if (i mod 2 = 0) then ( r := r + n[i+1] ) else ( b := b + n[i+1] )) ; if (m mod 2 = 0) then ( (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name b))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ))))))))))))))) ) else ( (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name r))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) % (expr (atom (number (integer 2)))))) != (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ))))))))))))))) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): ln=int(input()) num=list(input()) re,ro,bo,be=0,0,0,0 for h in range(ln): if(h % 2==0): if(int(num[h])% 2==0): re+=1 else : ro+=1 else : if(int(num[h])% 2==0): be+=1 else : bo+=1 if(ln % 2==0): if(be!=0): print('2') else : print('1') else : if(ro!=0): print('1') else : print('2') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var ln : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var num : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var re : OclAny := null; var ro : OclAny := null; var bo : OclAny := null; var be : OclAny := null; Sequence{re,ro,bo,be} := Sequence{0,0,0,0} ; for h : Integer.subrange(0, ln-1) do ( if (h mod 2 = 0) then ( if (("" + ((num[h+1])))->toInteger() mod 2 = 0) then ( re := re + 1 ) else ( ro := ro + 1 ) ) else ( if (("" + ((num[h+1])))->toInteger() mod 2 = 0) then ( be := be + 1 ) else ( bo := bo + 1 ) )) ; if (ln mod 2 = 0) then ( if (be /= 0) then ( execute ('2')->display() ) else ( execute ('1')->display() ) ) else ( if (ro /= 0) then ( execute ('1')->display() ) else ( execute ('2')->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(0,n): m=int(input()) a=input() odd=[] even=[] for j in range(0,m): if j % 2==0 : odd.append(int(a[j])) else : even.append(int(a[j])) if m % 2==0 : bl=False for o in range(0,len(even)): if even[o]% 2==0 : bl=True break if bl : print("2") else : print("1") else : bl=False for o in range(0,len(odd)): if odd[o]% 2==1 : bl=True break if bl : print("1") else : print("2") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : String := (OclFile["System.in"]).readLine() ; var odd : Sequence := Sequence{} ; var even : Sequence := Sequence{} ; for j : Integer.subrange(0, m-1) do ( if j mod 2 = 0 then ( execute ((("" + ((a[j+1])))->toInteger()) : odd) ) else ( execute ((("" + ((a[j+1])))->toInteger()) : even) )) ; if m mod 2 = 0 then ( var bl : boolean := false ; for o : Integer.subrange(0, (even)->size()-1) do ( if even[o+1] mod 2 = 0 then ( bl := true ; break ) else skip) ; if bl then ( execute ("2")->display() ) else ( execute ("1")->display() ) ) else ( bl := false ; for o : Integer.subrange(0, (odd)->size()-1) do ( if odd[o+1] mod 2 = 1 then ( bl := true ; break ) else skip) ; if bl then ( execute ("1")->display() ) else ( execute ("2")->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() print((len(a)-(a==a[: :-1]))*(len(set(a))!=1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; execute (((a)->size() - (a = a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))) * ((Set{}->union((a)))->size() /= 1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: f=len(s)% 2 ; print('2112'[f+2*any(f ^ int(i)& 1 for i in s[f : : 2])]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var f : int := (s)->size() mod 2; execute ('2112'[f + 2 * ((argument (test (logical_test (comparison (expr (expr (atom (name f))) ^ (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) & (expr (atom (number (integer 1))))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name f)))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) ]))))))))->exists( _x | _x = true )+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=5,7,10 if(a<=b and a<=c): print(a,"is the smallest") elif(b<=a and b<=c): print(b,"is the smallest") else : print(c,"is the smallest") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{5,7,10} ; if ((a->compareTo(b)) <= 0 & (a->compareTo(c)) <= 0) then ( execute (a)->display() ) else (if ((b->compareTo(a)) <= 0 & (b->compareTo(c)) <= 0) then ( execute (b)->display() ) else ( execute (c)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def countNumbers(N): return int(math.sqrt(N))-1 if __name__=="__main__" : N=36 print(countNumbers(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( N := 36 ; execute (countNumbers(N))->display() ) else skip; operation countNumbers(N : OclAny) : OclAny pre: true post: true activity: return ("" + (((N)->sqrt())))->toInteger() - 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdout def g(k,p): print(str(k)+'\n'+' '.join(map(str,p))) stdout.flush() n=int(input()) s=[9e9]*n def f(q): global s p=[k+1 for k,v in enumerate(q)if v] g(len(p),p) s=[i if j else min(i,int(k))for i,j,k in zip(s,q,input().split())] return[not v for v in q] k=1 while ktoInteger() ; var s : Sequence := MatrixLib.elementwiseMult(Sequence{ ("9e9")->toReal() }, n) ; skip ; k := 1 ; while (k->compareTo(n)) < 0 do ( f(f(Integer.subrange(0, n-1)->select(i | true)->collect(i | (not((MathLib.bitwiseAnd(i, k))))))) ; k := k * 2) ; g(-1, s); operation g(k : OclAny, p : OclAny) pre: true post: true activity: execute (("" + ((k))) + ' ' + StringLib.sumStringsWithSeparator(((p)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ; stdout.flush(); operation f(q : OclAny) : OclAny pre: true post: true activity: skip ; p := Integer.subrange(1, (q)->size())->collect( _indx | Sequence{_indx-1, (q)->at(_indx)} )->select(_tuple | let k : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in v)->collect(_tuple | let k : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in (k + 1)) ; g((p)->size(), p) ; s := Integer.subrange(1, s->size())->collect( _indx | Sequence{s->at(_indx), q->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let j : OclAny = _tuple->at(2) in (if j then i else Set{i, ("" + ((k)))->toInteger()}->min() endif)) ; return q->select(v | true)->collect(v | (not(v))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def gethighest(t): n,k=t//3,t % 3 if n==0 : return min(1,k),k elif n==10 : return 10,10 elif n==9 : return n+(k!=0),10 else : return n+(k!=0),n+1+(k==2) def work(s): s=list(map(int,s.split())) N=s[0] S=s[1] p=s[2] T=s[3 :] assert(len(T)==N) BH=0 OH=0 BL=0 for t in T : nh,sh=gethighest(t) if nh>=p : BH+=1 elif sh>=p : OH+=1 else : BL+=1 return(BH+min(OH,S)) if __name__=='__main__' : T=int(sys.stdin.readline().strip()) for i in range(T): s=work(sys.stdin.readline().rstrip()) print('Case #{}:{}'.format(i+1,s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( T := ("" + ((sys.stdin.readLine()->trim())))->toInteger() ; for i : Integer.subrange(0, T-1) do ( s := work(sys.stdin.readLine().rstrip()) ; execute (StringLib.interpolateStrings('Case #{}:{}', Sequence{i + 1, s}))->display()) ) else skip; operation gethighest(t : OclAny) : OclAny pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := Sequence{t div 3,t mod 3} ; if n = 0 then ( return Set{1, k}->min(), k ) else (if n = 10 then ( return 10, 10 ) else (if n = 9 then ( return n + (k /= 0), 10 ) else ( return n + (k /= 0), n + 1 + (k = 2) ) ) ) ; operation work(s : OclAny) : OclAny pre: true post: true activity: s := ((s.split())->collect( _x | (OclType["int"])->apply(_x) )) ; var N : OclAny := s->first() ; var S : OclAny := s[1+1] ; var p : OclAny := s[2+1] ; var T : OclAny := s.subrange(3+1) ; assert ((T)->size() = N) do "assertion failed" ; var BH : int := 0 ; var OH : int := 0 ; var BL : int := 0 ; for t : T do ( var nh : OclAny := null; var sh : OclAny := null; Sequence{nh,sh} := gethighest(t) ; if (nh->compareTo(p)) >= 0 then ( BH := BH + 1 ) else (if (sh->compareTo(p)) >= 0 then ( OH := OH + 1 ) else ( BL := BL + 1 ) ) ) ; return (BH + Set{OH, S}->min()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=open('B-large.in','r') g=open('resultBlarge.txt','w') T=int(f.next().strip()) for i in xrange(1,1+T): s=map(int,f.next().strip().split()) N=s[0] S=s[1] p=s[2] scores=s[3 :] if p>=2 : solid_score=3*p-2 surprise_score=3*p-4 elif p==1 : solid_score=1 surprise_score=1 elif p==0 : solid_score=0 surprise_score=0 solid=sum(sc>=solid_score for sc in scores) surprise=sum(sc>=surprise_score for sc in scores)-solid res=solid+min(surprise,S) g.write('Case #'+str(i)+': '+str(res)+'\n') g.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('B-large.in')) ; var g : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('resultBlarge.txt')) ; var T : int := ("" + ((f.next()->trim())))->toInteger() ; for i : xrange(1, 1 + T) do ( var s : Sequence := (f.next()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var N : OclAny := s->first() ; var S : OclAny := s[1+1] ; var p : OclAny := s[2+1] ; var scores : OclAny := s.subrange(3+1) ; if p >= 2 then ( var solid_score : double := 3 * p - 2 ; var surprise_score : double := 3 * p - 4 ) else (if p = 1 then ( solid_score := 1 ; surprise_score := 1 ) else (if p = 0 then ( solid_score := 0 ; surprise_score := 0 ) else skip ) ) ; var solid : OclAny := ((argument (test (logical_test (comparison (comparison (expr (atom (name sc)))) >= (comparison (expr (atom (name solid_score))))))) (comp_for for (exprlist (expr (atom (name sc)))) in (logical_test (comparison (expr (atom (name scores))))))))->sum() ; var surprise : double := ((argument (test (logical_test (comparison (comparison (expr (atom (name sc)))) >= (comparison (expr (atom (name surprise_score))))))) (comp_for for (exprlist (expr (atom (name sc)))) in (logical_test (comparison (expr (atom (name scores))))))))->sum() - solid ; var res : OclAny := solid + Set{surprise, S}->min() ; g.write('Case #' + ("" + ((i))) + ': ' + ("" + ((res))) + ' ')) ; g.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- with open('B-large.in','r')as fin : with open('output.txt','w')as fout : numcases=int(fin.readline()) for i in range(1,numcases+1): line=[int(j)for j in fin.readline().split()] surprising=line[1] minscore=line[2] oknum=0 needsSurprising=0 for j in line[3 :]: d=j/3 m=j % 3 if m==0 : if d>=minscore : oknum+=1 elif d>=minscore-1 and d>0 : needsSurprising+=1 elif m==1 : if d>=minscore-1 : oknum+=1 elif m==2 : if d>=minscore-1 : oknum+=1 elif d>=minscore-2 : needsSurprising+=1 fout.write("Case #") fout.write(str(i)) fout.write(": ") fout.write(str(oknum+min(surprising,needsSurprising))) fout.write('\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: try (var fin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('B-large.in')); try (var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('output.txt')); var numcases : int := ("" + ((fin.readLine())))->toInteger() ; for i : Integer.subrange(1, numcases + 1-1) do ( var line : Sequence := fin.readLine().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; var surprising : OclAny := line[1+1] ; var minscore : OclAny := line[2+1] ; var oknum : int := 0 ; var needsSurprising : int := 0 ; for j : line.subrange(3+1) do ( var d : double := j / 3 ; var m : int := j mod 3 ; if m = 0 then ( if (d->compareTo(minscore)) >= 0 then ( oknum := oknum + 1 ) else (if (d->compareTo(minscore - 1)) >= 0 & d > 0 then ( needsSurprising := needsSurprising + 1 ) else skip) ) else (if m = 1 then ( if (d->compareTo(minscore - 1)) >= 0 then ( oknum := oknum + 1 ) else skip ) else (if m = 2 then ( if (d->compareTo(minscore - 1)) >= 0 then ( oknum := oknum + 1 ) else (if (d->compareTo(minscore - 2)) >= 0 then ( needsSurprising := needsSurprising + 1 ) else skip) ) else skip ) ) ) ; fout.write("Case #") ; fout.write(("" + ((i)))) ; fout.write(": ") ; fout.write(("" + ((oknum + Set{surprising, needsSurprising}->min())))) ; fout.write(' '))) catch (_e : OclException) do skip) catch (_e : OclException) do skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def ints(): for line in sys.stdin : for word in line.split(): yield int(word) return get_int=ints() T=next(get_int) for t in range(T): N=next(get_int) S=next(get_int) p=next(get_int) total=0 for i in range(N): val=next(get_int) if val>3*p-3 : total=total+1 elif val>3*p-5 and S>0 and val>0 : total=total+1 S=S-1 print("Case #",t+1,": ",total,sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var get_int : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.ints(_i)) ; var T : OclAny := (get_int).next() ; for t : Integer.subrange(0, T-1) do ( var N : OclAny := (get_int).next() ; var S : OclAny := (get_int).next() ; var p : OclAny := (get_int).next() ; var total : int := 0 ; for i : Integer.subrange(0, N-1) do ( var val : OclAny := (get_int).next() ; if (val->compareTo(3 * p - 3)) > 0 then ( total := total + 1 ) else (if (val->compareTo(3 * p - 5)) > 0 & S > 0 & val > 0 then ( total := total + 1 ; S := S - 1 ) else skip)) ; execute ("Case #")->display()); operation ints(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; for line : OclFile["System.in"] do ( for word : line.split() do ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return ("" + ((word)))->toInteger())) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(st): n=len(st) oddDigSum=0 evenDigSum=0 for i in range(0,n): if(i % 2==0): oddDigSum=oddDigSum+((int)(st[i])) else : evenDigSum=evenDigSum+((int)(st[i])) return((oddDigSum-evenDigSum)% 11==0) st="76945" if(check(st)): print("Yes") else : print("No ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; st := "76945" ; if (check(st)) then ( execute ("Yes")->display() ) else ( execute ("No ")->display() ); operation check(st : OclAny) : OclAny pre: true post: true activity: var n : int := (st)->size() ; var oddDigSum : int := 0 ; var evenDigSum : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (i mod 2 = 0) then ( oddDigSum := oddDigSum + ((OclType["int"])(st[i+1])) ) else ( evenDigSum := evenDigSum + ((OclType["int"])(st[i+1])) )) ; return ((oddDigSum - evenDigSum) mod 11 = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) t=0 for i in range(n): t+=a[i] t=t//n cnt=0 for i in range(n): if a[i]>t : a[i+1]+=abs(a[i]-t) cnt+=(abs(a[i]-t)) elif a[i]toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : int := 0 ; for i : Integer.subrange(0, n-1) do ( t := t + a[i+1]) ; t := t div n ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1]->compareTo(t)) > 0 then ( a[i + 1+1] := a[i + 1+1] + (a[i+1] - t)->abs() ; cnt := cnt + ((a[i+1] - t)->abs()) ) else (if (a[i+1]->compareTo(t)) < 0 then ( a[i + 1+1] := a[i + 1+1] - (a[i+1] - t)->abs() ; cnt := cnt + ((a[i+1] - t)->abs()) ) else skip)) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(x)for x in input().split()] s=sum(a)//n lft=0 ans=0 for i in range(n): ans+=abs(lft) lft+=a[i]-s print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var s : int := (a)->sum() div n ; var lft : int := 0 ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( ans := ans + (lft)->abs() ; lft := lft + a[i+1] - s) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() reverse="" for i in range(len(n)-1,-1,-1): reverse+=n[i] all_repeated=1 for i in range(len(n)-1): if n[i]==n[i+1]: all_repeated+=1 if all_repeated==len(n): print(0) elif(n==reverse): print(len(n)-1) else : print(len(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var reverse : String := "" ; for i : Integer.subrange(-1 + 1, (n)->size() - 1)->reverse() do ( reverse := reverse + n[i+1]) ; var all_repeated : int := 1 ; for i : Integer.subrange(0, (n)->size() - 1-1) do ( if n[i+1] = n[i + 1+1] then ( all_repeated := all_repeated + 1 ) else skip) ; if all_repeated = (n)->size() then ( execute (0)->display() ) else (if (n = reverse) then ( execute ((n)->size() - 1)->display() ) else ( execute ((n)->size())->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) sum=0 for x in a : sum+=x t=sum//n ans=0 for i in range(n-1): if a[i]toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sum : int := 0 ; for x : a do ( sum := sum + x) ; var t : int := sum div n ; var ans : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if (a[i+1]->compareTo(t)) < 0 then ( ans := ans + (t - a[i+1]) ; a[i + 1+1] := a[i + 1+1] - (t - a[i+1]) ) else ( ans := ans + (a[i+1] - t) ; a[i + 1+1] := a[i + 1+1] + (a[i+1] - t) )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate from bisect import bisect_left n=int(input()) l=list(map(int,input().split())) s=sum(l) q=s//n extras=[] extraind=[] lackee=[] for i,e in enumerate(l): if e>q : extras.append(e-q) extraind.append(i) elif etoInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : OclAny := (l)->sum() ; var q : int := s div n ; var extras : Sequence := Sequence{} ; var extraind : Sequence := Sequence{} ; var lackee : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (l)->size())->collect( _indx | Sequence{_indx-1, (l)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var e : OclAny := _tuple->at(_indx); if (e->compareTo(q)) > 0 then ( execute ((e - q) : extras) ; execute ((i) : extraind) ) else (if (e->compareTo(q)) < 0 then ( execute ((Sequence{i, q - e}) : lackee) ) else skip)) ; var c : int := 0 ; var i : int := 0 ; for _tuple : lackee do (var _indx : int := 1; var indx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var e : OclAny := _tuple->at(_indx); s := 0 ; while (s->compareTo(e)) < 0 do ( var nextra : OclAny := Set{0, extras[i+1] - (e - s)}->max() ; s := s + extras[i+1] - nextra ; c := c + (extras[i+1] - nextra) * (indx - extraind[i+1])->abs() ; extras[i+1] := nextra ; if extras[i+1] = 0 then ( i := i + 1 ) else skip)) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdout n=int(input()) ans=[10**10]*n th=1 while thtoInteger() ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ (10)->pow(10) }, n) ; var th : int := 1 ; while (th->compareTo(n)) < 0 do ( var ask : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((i mod (2 * th)->compareTo(th)) < 0)) ; for _anon : Integer.subrange(0, 2-1) do ( var inds : Sequence := Integer.subrange(1, (ask)->size())->collect( _indx | Sequence{_indx-1, (ask)->at(_indx)} )->select(_tuple | let key : OclAny = _tuple->at(1) in let value : OclAny = _tuple->at(2) in value)->collect(_tuple | let key : OclAny = _tuple->at(1) in let value : OclAny = _tuple->at(2) in (key)) ; execute ((inds)->size())->display() ; execute (StringLib.sumStringsWithSeparator((inds->select(i | true)->collect(i | (("" + ((i + 1)))))), ' '))->display() ; stdout.flush() ; var reply : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; ans := Integer.subrange(0, n-1)->select(i | true)->collect(i | (if ask[i+1] then ans[i+1] else Set{ans[i+1], reply[i+1]}->min() endif)) ; ask := ask->select(v | true)->collect(v | (not(v)))) ; th := th * 2) ; execute (-1)->display() ; execute (StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ; stdout.flush(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) t=0 for i in range(n): t+=a[i] t=t//n cnt=0 for i in range(n): if a[i]>t : a[i+1]+=abs(a[i]-t) cnt+=(abs(a[i]-t)) elif a[i]toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : int := 0 ; for i : Integer.subrange(0, n-1) do ( t := t + a[i+1]) ; t := t div n ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1]->compareTo(t)) > 0 then ( a[i + 1+1] := a[i + 1+1] + (a[i+1] - t)->abs() ; cnt := cnt + ((a[i+1] - t)->abs()) ) else (if (a[i+1]->compareTo(t)) < 0 then ( a[i + 1+1] := a[i + 1+1] - (a[i+1] - t)->abs() ; cnt := cnt + ((a[i+1] - t)->abs()) ) else skip)) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) w=[int(k)for k in input().split()] x,y=0,0 last=[0,0] if w[0]>0 : x+=1 last[0]+=1 else : y+=1 last[1]+=1 for j in range(1,n): if w[j]>0 : last[0]+=1 x+=last[0] y+=last[1] else : y+=1 x+=last[1] y+=last[0] last=[last[1],last[0]+1] print(y,x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger())) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{0,0} ; var last : Sequence := Sequence{0}->union(Sequence{ 0 }) ; if w->first() > 0 then ( x := x + 1 ; last->first() := last->first() + 1 ) else ( y := y + 1 ; last[1+1] := last[1+1] + 1 ) ; for j : Integer.subrange(1, n-1) do ( if w[j+1] > 0 then ( last->first() := last->first() + 1 ; x := x + last->first() ; y := y + last[1+1] ) else ( y := y + 1 ; x := x + last[1+1] ; y := y + last->first() ; last := Sequence{last[1+1]}->union(Sequence{ last->first() + 1 }) )) ; execute (y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) dp=[[0 for i in range(2)]for j in range(n)] dp[0][0]=dp[0][1]=1 if a[0]<0 : dp[0][0]=0 else : dp[0][1]=0 for i in range(1,n): if a[i]>=0 : dp[i][0]=dp[i-1][0]+1 dp[i][1]=dp[i-1][1] else : dp[i][0]=dp[i-1][1] dp[i][1]=dp[i-1][0]+1 po=0 ne=0 for i in range(0,n): po+=dp[i][0] ne+=dp[i][1] print(ne,po) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dp : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (Integer.subrange(0, 2-1)->select(i | true)->collect(i | (0)))) ; dp->first()->first() := 1; var dp->first()[1+1] : int := 1 ; if a->first() < 0 then ( dp->first()->first() := 0 ) else ( dp->first()[1+1] := 0 ) ; for i : Integer.subrange(1, n-1) do ( if a[i+1] >= 0 then ( dp[i+1]->first() := dp[i - 1+1]->first() + 1 ; dp[i+1][1+1] := dp[i - 1+1][1+1] ) else ( dp[i+1]->first() := dp[i - 1+1][1+1] ; dp[i+1][1+1] := dp[i - 1+1]->first() + 1 )) ; var po : int := 0 ; var ne : int := 0 ; for i : Integer.subrange(0, n-1) do ( po := po + dp[i+1]->first() ; ne := ne + dp[i+1][1+1]) ; execute (ne)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) nums=list(map(int,input().split())) neg=[0] for num in nums : neg.append(neg[-1]) if num<0 : neg[-1]+=1 e=o=0 tot_pos=tot_neg=0 for val in neg : if val % 2 : tot_pos+=o tot_neg+=e o+=1 else : tot_pos+=e tot_neg+=o e+=1 print(tot_neg,tot_pos) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nums : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var neg : Sequence := Sequence{ 0 } ; for num : nums do ( execute ((neg->last()) : neg) ; if num < 0 then ( neg->last() := neg->last() + 1 ) else skip) ; var e : OclAny := 0; var o : int := 0 ; var tot_pos : OclAny := 0; var tot_neg : int := 0 ; for val : neg do ( if val mod 2 then ( tot_pos := tot_pos + o ; tot_neg := tot_neg + e ; o := o + 1 ) else ( tot_pos := tot_pos + e ; tot_neg := tot_neg + o ; e := e + 1 )) ; execute (tot_neg)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def canBeSumofConsec(n): return((n &(n-1))and n) n=15 if(canBeSumofConsec(n)): print("true") else : print("false") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 15 ; if (canBeSumofConsec(n)) then ( execute ("true")->display() ) else ( execute ("false")->display() ); operation canBeSumofConsec(n : OclAny) : OclAny pre: true post: true activity: return ((MathLib.bitwiseAnd(n, (n - 1))) & n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for ti in range(1,int(input())+1): n,p,q,r,s=[int(x)for x in input().split()] dev=[(i*p+q)% r+s for i in range(n)] tot=sum(dev) i=0 j=n-1 ltot=0 mtot=tot rtot=0 best=0 while ltotrtot : if ltot+dev[i]toInteger() + 1-1) do ( var n : OclAny := null; var p : OclAny := null; var q : OclAny := null; var r : OclAny := null; var s : OclAny := null; Sequence{n,p,q,r,s} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var dev : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((i * p + q) mod r + s)) ; var tot : OclAny := (dev)->sum() ; var i : int := 0 ; var j : double := n - 1 ; var ltot : int := 0 ; var mtot : OclAny := tot ; var rtot : int := 0 ; var best : int := 0 ; while (ltot->compareTo(mtot)) < 0 & (mtot > rtot) do ( if (ltot + dev[i+1]->compareTo(rtot + dev[j+1])) < 0 then ( ltot := ltot + dev[i+1] ; mtot := mtot - dev[i+1] ; i := i + 1 ; best := Set{best, tot - Set{ltot, mtot, rtot}->max()}->max() ) else ( rtot := rtot + dev[j+1] ; mtot := mtot - dev[j+1] ; j := j - 1 ; best := Set{best, tot - Set{ltot, mtot, rtot}->max()}->max() )) ; execute ('Case #' + ("" + ((ti))) + ':')->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys t=int(sys.stdin.readline()) def solve(n,p,q,r,s): l=[(i*p+q)% r+s for i in range(n)] vsota=sum(l) cum=[0] for x in l : cum.append(cum[-1]+x) best=0.0 for b in range(n-1,-1,-1): rem=vsota-(cum[n]-cum[b]) al=0 ar=b while al+1right : ar=amid else : al=amid s=[cum[al],cum[b]-cum[al],cum[n]-cum[b]] s.sort() p=(s[0]+s[1])/vsota best=max(best,p) s=[cum[ar],cum[b]-cum[ar],cum[n]-cum[b]] s.sort() p=(s[0]+s[1])/vsota best=max(best,p) return best for test_case in range(1,t+1): n,p,q,r,s=map(int,sys.stdin.readline().strip().split()) print("Case #{0}:{1}".format(test_case,solve(n,p,q,r,s))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; for test_case : Integer.subrange(1, t + 1-1) do ( Sequence{n,p,q,r,s} := (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (StringLib.interpolateStrings("Case #{0}:{1}", Sequence{test_case, solve(n, p, q, r, s)}))->display()); operation solve(n : OclAny, p : OclAny, q : OclAny, r : OclAny, s : OclAny) : OclAny pre: true post: true activity: var l : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((i * p + q) mod r + s)) ; var vsota : OclAny := (l)->sum() ; var cum : Sequence := Sequence{ 0 } ; for x : l do ( execute ((cum->last() + x) : cum)) ; var best : double := 0.0 ; for b : Integer.subrange(-1 + 1, n - 1)->reverse() do ( var rem : double := vsota - (cum[n+1] - cum[b+1]) ; var al : int := 0 ; var ar : OclAny := b ; while (al + 1->compareTo(ar)) < 0 do ( var amid : int := (al + ar) div 2 ; var left : OclAny := cum[amid+1] ; var right : double := cum[b+1] - cum[amid+1] ; if (left->compareTo(right)) > 0 then ( ar := amid ) else ( al := amid )) ; s := Sequence{cum[al+1]}->union(Sequence{cum[b+1] - cum[al+1]}->union(Sequence{ cum[n+1] - cum[b+1] })) ; s := s->sort() ; p := (s->first() + s[1+1]) / vsota ; best := Set{best, p}->max() ; s := Sequence{cum[ar+1]}->union(Sequence{cum[b+1] - cum[ar+1]}->union(Sequence{ cum[n+1] - cum[b+1] })) ; s := s->sort() ; p := (s->first() + s[1+1]) / vsota ; best := Set{best, p}->max()) ; return best; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_trials=int(input()) def in_range(a,b,S): return S[b+1]-S[a] def compute(): N,p,q,r,s=map(int,input().split()) S=[0]*(N+1) S[0]=0 for i in range(0,N): S[i+1]=(p*i+q)% r+s+S[i] a_lo=0 a_hi=N-1 min_solveig_score=S[N]+1 while a_lo<=a_hi : a_try=(a_lo+a_hi)//2 lo_range=S[a_try] b_lo=a_try b_hi=N-1 min_max_mid_hi=S[N]+1 while b_lo<=b_hi : b_try=(b_lo+b_hi)//2 mid_range=S[b_try+1]-S[a_try] hi_range=S[N]-S[b_try+1] min_max_mid_hi=min(min_max_mid_hi,max(mid_range,hi_range)) if mid_range>hi_range : b_hi=b_try-1 elif mid_rangemin_max_mid_hi : a_hi=a_try-1 elif lo_rangetoInteger() ; skip ; skip ; for i : Integer.subrange(0, num_trials-1) do ( execute ("Case #" + ("" + ((i + 1))) + ": " + ("" + ((compute()))))->display()); operation in_range(a : OclAny, b : OclAny, S : OclAny) : OclAny pre: true post: true activity: return S[b + 1+1] - S[a+1]; operation compute() : OclAny pre: true post: true activity: var N : OclAny := null; var p : OclAny := null; var q : OclAny := null; var r : OclAny := null; var s : OclAny := null; Sequence{N,p,q,r,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; S := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; S->first() := 0 ; for i : Integer.subrange(0, N-1) do ( S[i + 1+1] := (p * i + q) mod r + s + S[i+1]) ; var a_lo : int := 0 ; var a_hi : double := N - 1 ; var min_solveig_score : OclAny := S[N+1] + 1 ; while (a_lo->compareTo(a_hi)) <= 0 do ( var a_try : int := (a_lo + a_hi) div 2 ; var lo_range : OclAny := S[a_try+1] ; var b_lo : int := a_try ; var b_hi : double := N - 1 ; var min_max_mid_hi : OclAny := S[N+1] + 1 ; while (b_lo->compareTo(b_hi)) <= 0 do ( var b_try : int := (b_lo + b_hi) div 2 ; var mid_range : double := S[b_try + 1+1] - S[a_try+1] ; var hi_range : double := S[N+1] - S[b_try + 1+1] ; min_max_mid_hi := Set{min_max_mid_hi, Set{mid_range, hi_range}->max()}->min() ; if (mid_range->compareTo(hi_range)) > 0 then ( b_hi := b_try - 1 ) else (if (mid_range->compareTo(hi_range)) < 0 then ( b_lo := b_try + 1 ) else ( break ) ) ) ; min_solveig_score := Set{min_solveig_score, Set{lo_range, min_max_mid_hi}->max()}->min() ; if (lo_range->compareTo(min_max_mid_hi)) > 0 then ( a_hi := a_try - 1 ) else (if (lo_range->compareTo(min_max_mid_hi)) < 0 then ( a_lo := a_try + 1 ) else ( break ) ) ) ; return (StringLib.format("%1.10f",(1 - min_solveig_score / S[N+1]))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Diamond(rows): n=0 for i in range(1,rows+1): for j in range(1,(rows-i)+1): print(end="") while n!=(2*i-1): print("*",end="") n=n+1 n=0 print() k=1 n=1 for i in range(1,rows): for j in range(1,k+1): print(end="") k=k+1 while n<=(2*(rows-i)-1): print("*",end="") n=n+1 n=1 print() rows=5 Diamond(rows) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; rows := 5 ; Diamond(rows); operation Diamond(rows : OclAny) pre: true post: true activity: var n : int := 0 ; for i : Integer.subrange(1, rows + 1-1) do ( for j : Integer.subrange(1, (rows - i) + 1-1) do ( execute ((argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom "")))))))->display()) ; while n /= (2 * i - 1) do ( execute ("*")->display() ; n := n + 1) ; n := 0 ; execute (->display()) ; var k : int := 1 ; n := 1 ; for i : Integer.subrange(1, rows-1) do ( for j : Integer.subrange(1, k + 1-1) do ( execute ((argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom "")))))))->display()) ; k := k + 1 ; while (n->compareTo((2 * (rows - i) - 1))) <= 0 do ( execute ("*")->display() ; n := n + 1) ; n := 1 ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=str(input()) max_length=0 for x in range(0,len(s)-1): for y in range(x+1,len(s)): m=s[x : y+1] n=m[: :-1] if m!=n : if len(m)>max_length : max_length=len(m) print(max_length) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; var max_length : int := 0 ; for x : Integer.subrange(0, (s)->size() - 1-1) do ( for y : Integer.subrange(x + 1, (s)->size()-1) do ( var m : OclAny := s.subrange(x+1, y + 1) ; var n : OclAny := m(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; if m /= n then ( if ((m)->size()->compareTo(max_length)) > 0 then ( max_length := (m)->size() ) else skip ) else skip)) ; execute (max_length)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l,r=[int(x)for x in input().split()] curr=r s=0 while curr : s+=1 curr//=10 first=10**s second=first//2 ans=-1 for i in[l,r,first,second]: if i>=l and i<=r : curr=i rev='' for k in str(curr): rev+=str(9-int(k)) ans=max(ans,int(rev)*curr) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var curr : OclAny := r ; var s : int := 0 ; while curr do ( s := s + 1 ; curr := curr div 10) ; var first : double := (10)->pow(s) ; var second : int := first div 2 ; var ans : int := -1 ; for i : Sequence{l}->union(Sequence{r}->union(Sequence{first}->union(Sequence{ second }))) do ( if (i->compareTo(l)) >= 0 & (i->compareTo(r)) <= 0 then ( curr := i ; var rev : String := '' ; for k : ("" + ((curr))) do ( rev := rev + ("" + ((9 - ("" + ((k)))->toInteger())))) ; ans := Set{ans, ("" + ((rev)))->toInteger() * curr}->max() ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lst=input().split() dicts={} max=0 for i in lst : if i in dicts : dicts[i]+=1 else : dicts[i]=1 if dicts[i]>max : max=dicts[i] if max==3 : print(0) elif max==2 : print(1) else : max=0 for i in range(2): for j in range(i+1,3): if lst[i][1]==lst[j][1]and abs(ord(lst[i][0])-ord(lst[j][0]))<3 : max+=1 if max==0 : print(2) elif max>0 and max<3 : print(1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lst : OclAny := input().split() ; var dicts : OclAny := Set{} ; var max : int := 0 ; for i : lst do ( if (dicts)->includes(i) then ( dicts[i+1] := dicts[i+1] + 1 ) else ( dicts[i+1] := 1 ) ; if (dicts[i+1]->compareTo(max)) > 0 then ( max := dicts[i+1] ) else skip) ; if max = 3 then ( execute (0)->display() ) else (if max = 2 then ( execute (1)->display() ) else ( max := 0 ; for i : Integer.subrange(0, 2-1) do ( for j : Integer.subrange(i + 1, 3-1) do ( if lst[i+1][1+1] = lst[j+1][1+1] & ((lst[i+1]->first())->char2byte() - (lst[j+1]->first())->char2byte())->abs() < 3 then ( max := max + 1 ) else skip)) ; if max = 0 then ( execute (2)->display() ) else (if max > 0 & max < 3 then ( execute (1)->display() ) else ( execute (0)->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline w=input()[:-1].split() w.sort() c=1 if w[0]==w[1]==w[2]or(int(w[0][0])==int(w[1][0])-1==int(w[2][0])-2 and w[0][1]==w[1][1]==w[2][1]): print(0) elif w[0]==w[1]or w[1]==w[2]or w[0]==w[2]or(w[0][1]==w[1][1]and int(w[1][0])-int(w[0][0])<=2)or(w[2][1]==w[1][1]and int(w[2][0])-int(w[1][0])<=2)or(w[2][1]==w[0][1]and int(w[2][0])-int(w[0][0])<=2): print(1) else : print(2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var w : OclAny := input()->front().split() ; w := w->sort() ; var c : int := 1 ; if w->first() = w[1+1] & (w[1+1] == w[2+1]) or (("" + ((w->first()->first())))->toInteger() = ("" + ((w[1+1]->first())))->toInteger() - 1 & (("" + ((w[1+1]->first())))->toInteger() - 1 == ("" + ((w[2+1]->first())))->toInteger() - 2) & w->first()[1+1] = w[1+1][1+1] & (w[1+1][1+1] == w[2+1][1+1])) then ( execute (0)->display() ) else (if w->first() = w[1+1] or w[1+1] = w[2+1] or w->first() = w[2+1] or (w->first()[1+1] = w[1+1][1+1] & ("" + ((w[1+1]->first())))->toInteger() - ("" + ((w->first()->first())))->toInteger() <= 2) or (w[2+1][1+1] = w[1+1][1+1] & ("" + ((w[2+1]->first())))->toInteger() - ("" + ((w[1+1]->first())))->toInteger() <= 2) or (w[2+1][1+1] = w->first()[1+1] & ("" + ((w[2+1]->first())))->toInteger() - ("" + ((w->first()->first())))->toInteger() <= 2) then ( execute (1)->display() ) else ( execute (2)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline s=list(input().rstrip().split()) d=dict() for i in range(1,10): d[str(i)+"m"]=i d[str(i)+"p"]=i+20 d[str(i)+"s"]=i+40 x=[0]*80 for i in s : x[d[i]]+=1 ans=3-max(x) for i in range(78): s=0 for j in range(3): s+=min(x[i+j],1) ans=min(ans,3-s) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var s : Sequence := (input().rstrip().split()) ; var d : Map := (arguments ( )) ; for i : Integer.subrange(1, 10-1) do ( d[("" + ((i))) + "m"+1] := i ; d[("" + ((i))) + "p"+1] := i + 20 ; d[("" + ((i))) + "s"+1] := i + 40) ; var x : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 80) ; for i : s do ( x[d[i+1]+1] := x[d[i+1]+1] + 1) ; var ans : double := 3 - (x)->max() ; for i : Integer.subrange(0, 78-1) do ( s := 0 ; for j : Integer.subrange(0, 3-1) do ( s := s + Set{x[i + j+1], 1}->min()) ; ans := Set{ans, 3 - s}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (a,b)=input().rstrip().split(' ') a=int(a) b=int(b) if ab : print("a>b") else : print("a==b") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{a, b} : OclAny := input().rstrip().split(' ') ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; if (a->compareTo(b)) < 0 then ( execute ("adisplay() ) else (if (a->compareTo(b)) > 0 then ( execute ("a>b")->display() ) else ( execute ("a==b")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(arg): arg=str(arg) numbers=[int(x)for x in arg.split(" ")] a,b=numbers[0],numbers[1] if a>b : return "a>b" elif adisplay() ) else skip; operation main(arg : OclAny) : OclAny pre: true post: true activity: arg := ("" + ((arg))) ; var numbers : Sequence := arg.split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{numbers->first(),numbers[1+1]} ; if (a->compareTo(b)) > 0 then ( return "a>b" ) else (if (a->compareTo(b)) < 0 then ( return "ab : print("a>b") elif acollect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(b)) > 0 then ( execute ("a>b")->display() ) else (if (a->compareTo(b)) < 0 then ( execute ("adisplay() ) else ( execute ("a==b")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): a,b=map(int,input().split()) if a>b : print('a>b') elif acollect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(b)) > 0 then ( execute ('a>b')->display() ) else (if (a->compareTo(b)) < 0 then ( execute ('adisplay() ) else (if a = b then ( execute ('a==b')->display() ) else ( execute ('error')->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) def small(a,b): return ab def equal(a,b): return a==b if small(a,b): print("ab") elif equal(a,b): print("a==b") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; skip ; skip ; if small(a, b) then ( execute ("adisplay() ) else (if big(a, b) then ( execute ("a>b")->display() ) else (if equal(a, b) then ( execute ("a==b")->display() ) else skip ) ) ; operation small(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a->compareTo(b)) < 0; operation big(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a->compareTo(b)) > 0; operation equal(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a = b; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys Even=True for s in sys.stdin : if Even : Even=False a=list(map(int,s.split())) else : Even=True b=list(map(int,s.split())) hit=sum(a[i]==b[i]for i in range(4)) blow=sum(b[i]in a for i in range(4))-hit print(hit,blow) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var Even : boolean := true ; for s : OclFile["System.in"] do ( if Even then ( Even := false ; var a : Sequence := ((s.split())->collect( _x | (OclType["int"])->apply(_x) )) ) else ( Even := true ; var b : Sequence := ((s.split())->collect( _x | (OclType["int"])->apply(_x) )) ; var hit : OclAny := ((argument (test (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 4))))))))) )))))))))->sum() ; var blow : double := ((argument (test (logical_test (comparison (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) in (comparison (expr (atom (name a))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 4))))))))) )))))))))->sum() - hit ; execute (hit)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : A=map(int,input().split()) ls_A=list(A) B=map(int,input().split()) ls_B=list(B) h=0 b=0 for i in range(len(ls_A)): if ls_A[i]==ls_B[i]: h+=1 if ls_A[0]==ls_B[1]: b+=1 if ls_A[0]==ls_B[2]: b+=1 if ls_A[0]==ls_B[3]: b+=1 if ls_A[1]==ls_B[0]: b+=1 if ls_A[1]==ls_B[2]: b+=1 if ls_A[1]==ls_B[3]: b+=1 if ls_A[2]==ls_B[0]: b+=1 if ls_A[2]==ls_B[1]: b+=1 if ls_A[2]==ls_B[3]: b+=1 if ls_A[3]==ls_B[0]: b+=1 if ls_A[3]==ls_B[1]: b+=1 if ls_A[3]==ls_B[2]: b+=1 print(h,b) except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var A : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ls_A : Sequence := (A) ; var B : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ls_B : Sequence := (B) ; var h : int := 0 ; var b : int := 0 ; for i : Integer.subrange(0, (ls_A)->size()-1) do ( if ls_A[i+1] = ls_B[i+1] then ( h := h + 1 ) else skip) ; if ls_A->first() = ls_B[1+1] then ( b := b + 1 ) else skip ; if ls_A->first() = ls_B[2+1] then ( b := b + 1 ) else skip ; if ls_A->first() = ls_B[3+1] then ( b := b + 1 ) else skip ; if ls_A[1+1] = ls_B->first() then ( b := b + 1 ) else skip ; if ls_A[1+1] = ls_B[2+1] then ( b := b + 1 ) else skip ; if ls_A[1+1] = ls_B[3+1] then ( b := b + 1 ) else skip ; if ls_A[2+1] = ls_B->first() then ( b := b + 1 ) else skip ; if ls_A[2+1] = ls_B[1+1] then ( b := b + 1 ) else skip ; if ls_A[2+1] = ls_B[3+1] then ( b := b + 1 ) else skip ; if ls_A[3+1] = ls_B->first() then ( b := b + 1 ) else skip ; if ls_A[3+1] = ls_B[1+1] then ( b := b + 1 ) else skip ; if ls_A[3+1] = ls_B[2+1] then ( b := b + 1 ) else skip ; execute (h)->display()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- in1=input() in2=input() if((in1[0]==in2[2])and(in1[1]==in2[1])and(in1[2]==in2[0])): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var in1 : String := (OclFile["System.in"]).readLine() ; var in2 : String := (OclFile["System.in"]).readLine() ; if ((in1->first() = in2[2+1]) & (in1[1+1] = in2[1+1]) & (in1[2+1] = in2->first())) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ref(n): return int(''.join([str(9-int(x))for x in str(n)])) l,r=map(int,input().split()) ans=0 ans=max(ans,ref(l)*l) ans=max(ans,ref(r)*r) cur=5 for i in range(20): if(l<=cur<=r): ans=max(ans,ref(cur)*cur) cur*=10 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; ans := Set{ans, ref(l) * l}->max() ; ans := Set{ans, ref(r) * r}->max() ; var cur : int := 5 ; for i : Integer.subrange(0, 20-1) do ( if ((l->compareTo(cur)) <= 0 & (cur <= r)) then ( ans := Set{ans, ref(cur) * cur}->max() ) else skip ; cur := cur * 10) ; execute (ans)->display(); operation ref(n : OclAny) : OclAny pre: true post: true activity: return ("" + ((StringLib.sumStringsWithSeparator((("" + ((n)))->select(x | true)->collect(x | (("" + ((9 - ("" + ((x)))->toInteger())))))), ''))))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): x,y=map(int,input().split()) a=1 if y/x!=y//x or x>y : b=0 a=0 else : b=y//x print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : int := 1 ; if y / x /= y div x or (x->compareTo(y)) > 0 then ( var b : int := 0 ; a := 0 ) else ( b := y div x ) ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : H=0 ; B=0 ; a=list(map(int,input().split())) b=list(map(int,input().split())) except : break if a[0]==b[0]: H+=1 if a[1]==b[1]: H+=1 if a[2]==b[2]: H+=1 if a[3]==b[3]: H+=1 if a[0]==b[1]or a[0]==b[2]or a[0]==b[3]: B+=1 if a[1]==b[0]or a[1]==b[2]or a[1]==b[3]: B+=1 if a[2]==b[0]or a[2]==b[1]or a[2]==b[3]: B+=1 if a[3]==b[0]or a[3]==b[1]or a[3]==b[2]: B+=1 print(H,B) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var H : int := 0; var B : int := 0; ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) catch (_e : OclException) do ( break) ; if a->first() = b->first() then ( H := H + 1 ) else skip ; if a[1+1] = b[1+1] then ( H := H + 1 ) else skip ; if a[2+1] = b[2+1] then ( H := H + 1 ) else skip ; if a[3+1] = b[3+1] then ( H := H + 1 ) else skip ; if a->first() = b[1+1] or a->first() = b[2+1] or a->first() = b[3+1] then ( B := B + 1 ) else skip ; if a[1+1] = b->first() or a[1+1] = b[2+1] or a[1+1] = b[3+1] then ( B := B + 1 ) else skip ; if a[2+1] = b->first() or a[2+1] = b[1+1] or a[2+1] = b[3+1] then ( B := B + 1 ) else skip ; if a[3+1] = b->first() or a[3+1] = b[1+1] or a[3+1] = b[2+1] then ( B := B + 1 ) else skip ; execute (H)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys Lines=sys.stdin.readlines() for i in range(0,len(Lines),2): Anumbers=list(map(int,Lines[i].split())) Bnumbers=list(map(int,Lines[i+1].split())) Hit=0 for j in range(len(Anumbers)): Hit+=1 if(Anumbers[j]==Bnumbers[j])else 0 Blow=len(set(Anumbers)& set(Bnumbers))-Hit print(Hit,Blow) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var Lines : OclAny := (OclFile["System.in"]).readlines() ; for i : Integer.subrange(0, (Lines)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( var Anumbers : Sequence := ((Lines[i+1].split())->collect( _x | (OclType["int"])->apply(_x) )) ; var Bnumbers : Sequence := ((Lines[i + 1+1].split())->collect( _x | (OclType["int"])->apply(_x) )) ; var Hit : int := 0 ; for j : Integer.subrange(0, (Anumbers)->size()-1) do ( Hit := Hit + if (Anumbers[j+1] = Bnumbers[j+1]) then 1 else 0 endif) ; var Blow : double := (MathLib.bitwiseAnd(Set{}->union((Anumbers)), Set{}->union((Bnumbers))))->size() - Hit ; execute (Hit)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") def hit_and_blow(A,B): hit,blow=0,0 for k in range(4): if A[k]==B[k]: hit+=1 elif A[k]in B : blow+=1 return hit,blow while True : try : A=[int(_)for _ in input().split()] except EOFError : break B=[int(_)for _ in input().split()] hit,blow=hit_and_blow(A,B) print(hit,blow) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; skip ; while true do ( try ( A := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger()))) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))) ; B := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var hit : OclAny := null; var blow : OclAny := null; Sequence{hit,blow} := hit_and_blow(A, B) ; execute (hit)->display()); operation hit_and_blow(A : OclAny, B : OclAny) : OclAny pre: true post: true activity: var hit : OclAny := null; var blow : OclAny := null; Sequence{hit,blow} := Sequence{0,0} ; for k : Integer.subrange(0, 4-1) do ( if A[k+1] = B[k+1] then ( hit := hit + 1 ) else (if (B)->includes(A[k+1]) then ( blow := blow + 1 ) else skip)) ; return hit, blow; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=1 while t>0 : t-=1 n=int(input()) s=input() a=[] for i in range(0,len(s)): if s[i]!='0' : a.append(int(s[i])) else : a.append(11) b=[] c=[] d=[] e=[] for i in range(0,len(s)): b.append(a[i]-3) c.append(a[i]% 3-1 if a[i]% 3!=0 else 2) d.append(a[i]+3) e.append(a[i]% 3+1 if a[i]% 3!=0 else 4) k1=k2=h1=h2=False for i in range(0,len(s)): if b[i]<=0 : k1=True if c[i]<=0 or a[i]==11 : h1=True if d[i]>9 and d[i]!=11 : k2=True if e[i]>=4 or a[i]==11 : h2=True if k1==True and h1==True and k2==True and h2==True : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := 1 ; while t > 0 do ( t := t - 1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] /= '0' then ( execute ((("" + ((s[i+1])))->toInteger()) : a) ) else ( execute ((11) : a) )) ; var b : Sequence := Sequence{} ; var c : Sequence := Sequence{} ; var d : Sequence := Sequence{} ; var e : Sequence := Sequence{} ; for i : Integer.subrange(0, (s)->size()-1) do ( execute ((a[i+1] - 3) : b) ; execute ((if a[i+1] mod 3 /= 0 then a[i+1] mod 3 - 1 else 2 endif) : c) ; execute ((a[i+1] + 3) : d) ; execute ((if a[i+1] mod 3 /= 0 then a[i+1] mod 3 + 1 else 4 endif) : e)) ; k1 := k1(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name k2)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name h1)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name h2)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name False))))))))) ; for i : Integer.subrange(0, (s)->size()-1) do ( if b[i+1] <= 0 then ( var k1 : boolean := true ) else skip ; if c[i+1] <= 0 or a[i+1] = 11 then ( var h1 : boolean := true ) else skip ; if d[i+1] > 9 & d[i+1] /= 11 then ( var k2 : boolean := true ) else skip ; if e[i+1] >= 4 or a[i+1] = 11 then ( var h2 : boolean := true ) else skip) ; if k1 = true & h1 = true & k2 = true & h2 = true then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) s=input().rstrip() P=[[1,2,3],[4,5,6],[7,8,9],[-1,0,-1]] T=[] for k in range(n): for i in range(4): for j in range(3): if int(s[k])==P[i][j]: T.append((i,j)) for i in range(-4,4,1): for j in range(-3,3,1): if i==0 and j==0 : continue flag=True for k in range(n): x,y=T[k] if 0<=y+j<=2 : if y+j==1 and 0<=x+i<4 or 0<=x+i<3 : pass else : flag=False else : flag=False if flag : print('NO') exit() print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := input().rstrip() ; var P : Sequence := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))}->union(Sequence{Sequence{7}->union(Sequence{8}->union(Sequence{ 9 }))}->union(Sequence{ Sequence{-1}->union(Sequence{0}->union(Sequence{ -1 })) }))) ; var T : Sequence := Sequence{} ; for k : Integer.subrange(0, n-1) do ( for i : Integer.subrange(0, 4-1) do ( for j : Integer.subrange(0, 3-1) do ( if ("" + ((s[k+1])))->toInteger() = P[i+1][j+1] then ( execute ((Sequence{i, j}) : T) ) else skip))) ; for i : Integer.subrange(-4, 4-1)->select( $x | ($x - -4) mod 1 = 0 ) do ( for j : Integer.subrange(-3, 3-1)->select( $x | ($x - -3) mod 1 = 0 ) do ( if i = 0 & j = 0 then ( continue ) else skip ; var flag : boolean := true ; for k : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := T[k+1] ; if 0 <= y + j & (y + j <= 2) then ( if y + j = 1 & 0 <= x + i & (x + i < 4) or 0 <= x + i & (x + i < 3) then ( skip ) else ( flag := false ) ) else ( flag := false )) ; if flag then ( execute ('NO')->display() ; exit() ) else skip)) ; execute ('YES')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p,s=input(),set(input()) print(('NO','YES')[all(set(t)& s for t in '0147 0369 079 123'.split())]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : OclAny := null; var s : OclAny := null; Sequence{p,s} := Sequence{(OclFile["System.in"]).readLine(),Set{}->union(((OclFile["System.in"]).readLine()))} ; execute (Sequence{'NO', 'YES'}->select(((argument (test (logical_test (comparison (expr (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) )))) & (expr (atom (name s))))))) (comp_for for (exprlist (expr (atom (name t)))) in (logical_test (comparison (expr (atom '0147 0369 079 123') (trailer . (name split) (arguments ( )))))))))->forAll( _x | _x = true )))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=1 while t>0 : t-=1 n=int(input()) s=input() a=[] for i in range(0,len(s)): if s[i]!='0' : a.append(int(s[i])) else : a.append(11) b=[] c=[] d=[] e=[] for i in range(0,len(s)): b.append(a[i]-3) c.append(a[i]% 3-1 if a[i]% 3!=0 else 2) d.append(a[i]+3) e.append(a[i]% 3+1 if a[i]% 3!=0 else 4) k1=False k2=False h1=False h2=False for i in range(0,len(s)): if b[i]<=0 : k1=True if c[i]<=0 or a[i]==11 : h1=True if d[i]>9 and d[i]!=11 : k2=True if e[i]>=4 or a[i]==11 : h2=True if k1==True and h1==True and k2==True and h2==True : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := 1 ; while t > 0 do ( t := t - 1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] /= '0' then ( execute ((("" + ((s[i+1])))->toInteger()) : a) ) else ( execute ((11) : a) )) ; var b : Sequence := Sequence{} ; var c : Sequence := Sequence{} ; var d : Sequence := Sequence{} ; var e : Sequence := Sequence{} ; for i : Integer.subrange(0, (s)->size()-1) do ( execute ((a[i+1] - 3) : b) ; execute ((if a[i+1] mod 3 /= 0 then a[i+1] mod 3 - 1 else 2 endif) : c) ; execute ((a[i+1] + 3) : d) ; execute ((if a[i+1] mod 3 /= 0 then a[i+1] mod 3 + 1 else 4 endif) : e)) ; var k1 : boolean := false ; var k2 : boolean := false ; var h1 : boolean := false ; var h2 : boolean := false ; for i : Integer.subrange(0, (s)->size()-1) do ( if b[i+1] <= 0 then ( k1 := true ) else skip ; if c[i+1] <= 0 or a[i+1] = 11 then ( h1 := true ) else skip ; if d[i+1] > 9 & d[i+1] /= 11 then ( k2 := true ) else skip ; if e[i+1] >= 4 or a[i+1] = 11 then ( h2 := true ) else skip) ; if k1 = true & h1 = true & k2 = true & h2 = true then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSum(n): return(n*(pow(n,2)+3*n+5))/3 n=25 print(int(findSum(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 25 ; execute (("" + ((findSum(n))))->toInteger())->display(); operation findSum(n : OclAny) : OclAny pre: true post: true activity: return (n * ((n)->pow(2) + 3 * n + 5)) / 3; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import pow def calculateSum(n): return n*(pow(n,2)+3*n+5)/3 if __name__=='__main__' : n=3 print("Sum=",int(calculateSum(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( n := 3 ; execute ("Sum=")->display() ) else skip; operation calculateSum(n : OclAny) : OclAny pre: true post: true activity: return n * ((n)->pow(2) + 3 * n + 5) / 3; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) m-=n d=0 k-=1 ans=1 while m>1 and d!=max(k,n-k-1): ans+=1 m-=1 l=min(d,k) r=min(d,n-k-1) d+=1 m-=l m-=r ans+=m//n print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; m := m - n ; var d : int := 0 ; k := k - 1 ; var ans : int := 1 ; while m > 1 & d /= Set{k, n - k - 1}->max() do ( ans := ans + 1 ; m := m - 1 ; var l : OclAny := Set{d, k}->min() ; var r : OclAny := Set{d, n - k - 1}->min() ; d := d + 1 ; m := m - l ; m := m - r) ; ans := ans + m div n ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve_sum(n): return(pow(10,n+1)*(9*n-1)+10)/pow(9,3)-n*(n+1)/18 n=3 print(int(solve_sum(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3 ; execute (("" + ((solve_sum(n))))->toInteger())->display(); operation solve_sum(n : OclAny) : OclAny pre: true post: true activity: return ((10)->pow(n + 1) * (9 * n - 1) + 10) / (9)->pow(3) - n * (n + 1) / 18; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x,y=map(int,input().split()) if x>y : print(0,0) elif y % x!=0 : print(0,0) elif x==1 : print(1,y) else : print(1,int(y/x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (x->compareTo(y)) > 0 then ( execute (0)->display() ) else (if y mod x /= 0 then ( execute (0)->display() ) else (if x = 1 then ( execute (1)->display() ) else ( execute (1)->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import log def log_a_to_base_b(a,b): return log(a)//log(b); if __name__=="__main__" : a=3 ; b=2 ; print(log_a_to_base_b(a,b)); a=256 ; b=4 ; print(log_a_to_base_b(a,b)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( a := 3; ; b := 2; ; execute (log_a_to_base_b(a, b))->display(); ; a := 256; ; b := 4; ; execute (log_a_to_base_b(a, b))->display(); ) else skip; operation log_a_to_base_b(a : OclAny, b : OclAny) pre: true post: true activity: return log(a) div log(b);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def digit_sum(a): res=0 while a : res+=a % 10 a/=10 a=int(a) return res def main(): d={} MAX=10**17 for i in range(18): for j in range(1000): if i==0 and j==0 : continue tmp=int(str(j)+str(9)*i) if tmp>MAX : continue d[tmp]=tmp/digit_sum(tmp) ls=[] for a,b in d.items(): ls.append([b,a]) ls.sort() ls.append([0,MAX]) k=int(input()) idx,last=0,0 while k : while ls[idx][1]toInteger()) ; return res; operation main() pre: true post: true activity: var d : OclAny := Set{} ; var MAX : double := (10)->pow(17) ; for i : Integer.subrange(0, 18-1) do ( for j : Integer.subrange(0, 1000-1) do ( if i = 0 & j = 0 then ( continue ) else skip ; var tmp : int := ("" + ((("" + ((j))) + ("" + ((9))) * i)))->toInteger() ; if (tmp->compareTo(MAX)) > 0 then ( continue ) else skip ; d[tmp+1] := tmp / digit_sum(tmp))) ; var ls : Sequence := Sequence{} ; for _tuple : d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); execute ((Sequence{b}->union(Sequence{ a })) : ls)) ; ls := ls->sort() ; execute ((Sequence{0}->union(Sequence{ MAX })) : ls) ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var idx : OclAny := null; var last : OclAny := null; Sequence{idx,last} := Sequence{0,0} ; while k do ( while (ls[idx+1][1+1]->compareTo(last)) < 0 do ( idx := idx + 1) ; execute (ls[idx+1][1+1])->display() ; k := k - 1 ; var last : OclAny := ls[idx+1][1+1] ; idx := idx + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) def calc_snuke(n): return n/sum(map(int,str(n))) a=[] for i in range(1000): if i % 10==9 or i % 100==99 or i % 1000==999 : continue a.append(i) que=[] for i in range(16): m=10**i-1 for ai in a : w=ai*10**i+m if 0mi : continue ans.append(i) mi=q ans.sort() print(*ans[: k],sep="\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, 1000-1) do ( if i mod 10 = 9 or i mod 100 = 99 or i mod 1000 = 999 then ( continue ) else skip ; execute ((i) : a)) ; var que : Sequence := Sequence{} ; for i : Integer.subrange(0, 16-1) do ( var m : double := (10)->pow(i) - 1 ; for ai : a do ( var w : double := ai * (10)->pow(i) + m ; if 0 < w & (w <= (10)->pow(15) - 1) then ( execute ((w) : que) ) else skip)) ; que := que->sort() ; var mi : double := ("" + (("inf")))->toReal() ; var ans : Sequence := Sequence{} ; for i : que do ( var q : OclAny := calc_snuke(i) ; if (q->compareTo(mi)) > 0 then ( continue ) else skip ; execute ((i) : ans) ; mi := q) ; ans := ans->sort() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name k)))))))) ]))))))))->display(); operation calc_snuke(n : OclAny) : OclAny pre: true post: true activity: return n / ((("" + ((n))))->collect( _x | (OclType["int"])->apply(_x) ))->sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- LEN=0 SNK=[1,2,3,4,5,6,7,8,9] LEN+=1 for i in range(1,10): SNK.append(i*10+9) LEN+=1 LEN+=1 for loop in range(2): SNK_sub=list(range(pow(10,loop),pow(10,loop+1))) SNK+=list(map(lambda x :(x*pow(10,LEN-1))+(pow(10,LEN-1)-1),SNK_sub)) LEN+=len(str(max(SNK_sub)))-1 for d in SNK_sub : SNK+=[(i*pow(10,LEN-1))+(pow(10,LEN-1)-1)for i in range(10,10*(d+1))] SNK+=list(map(lambda x :(x*pow(10,LEN))+(pow(10,LEN)-1),SNK_sub[SNK_sub.index(d)+1 :])) LEN+=1+loop if LEN>20 : break print("\n".join(str(i)for i in SNK[: int(input())])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var LEN : int := 0 ; var SNK : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 9 })))))))) ; LEN := LEN + 1 ; for i : Integer.subrange(1, 10-1) do ( execute ((i * 10 + 9) : SNK)) ; LEN := LEN + 1 ; LEN := LEN + 1 ; for loop : Integer.subrange(0, 2-1) do ( var SNK_sub : Sequence := (Integer.subrange((10)->pow(loop), (10)->pow(loop + 1)-1)) ; SNK := SNK + ((SNK_sub)->collect( _x | (lambda x : OclAny in ((x * (10)->pow(LEN - 1)) + ((10)->pow(LEN - 1) - 1)))->apply(_x) )) ; LEN := LEN + (("" + (((SNK_sub)->max()))))->size() - 1 ; for d : SNK_sub do ( SNK := SNK + Integer.subrange(10, 10 * (d + 1)-1)->select(i | true)->collect(i | ((i * (10)->pow(LEN - 1)) + ((10)->pow(LEN - 1) - 1))) ; SNK := SNK + ((SNK_sub.subrange(SNK_sub->indexOf(d) - 1 + 1+1))->collect( _x | (lambda x : OclAny in ((x * (10)->pow(LEN)) + ((10)->pow(LEN) - 1)))->apply(_x) )) ; LEN := LEN + 1 + loop ; if LEN > 20 then ( break ) else skip)) ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name SNK)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))) ])))))))), "\n"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- K=int(input()) a=0 from math import log10,ceil from functools import lru_cache @ lru_cache(maxsize=None) def sn(n): x=n y=0 while x>0 : y+=x % 10 x//=10 return n/y for i in range(K): if i<9 : a+=1 print(a) continue for d in range(int(log10(a))+1): y=10**(d+1)*ceil(a/(10**(d+1))+1)-1 if d==0 or sn(y)toInteger() ; var a : int := 0 ; skip ; skip ; (compound_stmt (decorator @ (dotted_name (name lru_cache)) ( (arglist (argument (test (logical_test (comparison (expr (atom (name maxsize)))))) = (test (logical_test (comparison (expr (atom None))))))) )) (funcdef def (name sn) ( (typedargslist (def_parameters (def_parameter (named_parameter (name n))))) ) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name n)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name y)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (compound_stmt while (test (logical_test (comparison (comparison (expr (atom (name x)))) > (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name y)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name x))) % (expr (atom (number (integer 10))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part //= (testlist (test (logical_test (comparison (expr (atom (number (integer 10))))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (expr (atom (name n))) / (expr (atom (name y)))))))))))))) ; for i : Integer.subrange(0, K-1) do ( if i < 9 then ( a := a + 1 ; execute (a)->display() ; continue ) else skip ; for d : Integer.subrange(0, ("" + ((log10(a))))->toInteger() + 1-1) do ( var y : double := (10)->pow((d + 1)) * ceil(a / ((10)->pow((d + 1))) + 1) - 1 ; if d = 0 or (sn(y)->compareTo(sn(at))) < 0 then ( var at : OclAny := y ) else skip) ; a := at ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def inpl(): return map(int,input().split()) K=int(input()) def S(N): tmp=0 while N : N,m=divmod(N,10) tmp+=m return tmp def com(a,b): return a*S(b)<=b*S(a) tmp="" count=0 i=1 while counttoInteger() ; skip ; skip ; tmp := "" ; var count : int := 0 ; var i : int := 1 ; while (count->compareTo(K)) < 0 do ( if com(("" + ((("" + ((i))) + tmp)))->toInteger(), ("" + ((("" + ((i + 1))) + tmp)))->toInteger()) then ( execute (("" + ((("" + ((i))) + tmp)))->toInteger())->display() ; count := count + 1 ; i := i + 1 ) else ( i := i div 10 ; tmp := tmp + "9" )); operation inpl() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation S(N : OclAny) : OclAny pre: true post: true activity: var tmp : int := 0 ; while N do ( var m : OclAny := null; Sequence{N,m} := Sequence{(N div 10), (N mod 10)} ; tmp := tmp + m) ; return tmp; operation com(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a * S(b)->compareTo(b * S(a))) <= 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(s): q=set(s) if len(s)!=len(q): return 'NO' s=sorted(s) for i in range(0,len(s)-1): if abs(ord(s[i])-ord(s[i+1]))!=1 : return 'NO' return 'YES' for _ in range(int(input())): s=input() print(f(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( s := (OclFile["System.in"]).readLine() ; execute (f(s))->display()); operation f(s : OclAny) : OclAny pre: true post: true activity: var q : Set := Set{}->union((s)) ; if (s)->size() /= (q)->size() then ( return 'NO' ) else skip ; s := s->sort() ; for i : Integer.subrange(0, (s)->size() - 1-1) do ( if ((s[i+1])->char2byte() - (s[i + 1+1])->char2byte())->abs() /= 1 then ( return 'NO' ) else skip) ; return 'YES'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) k="abcdefghijklmnopqrstuvwxyz" for i in range(t): s=input() s=sorted(s) s=''.join(s) if len(s)!=len(set(s)): print("No") else : if s in k : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : String := "abcdefghijklmnopqrstuvwxyz" ; for i : Integer.subrange(0, t-1) do ( var s : String := (OclFile["System.in"]).readLine() ; s := s->sort() ; s := StringLib.sumStringsWithSeparator((s), '') ; if (s)->size() /= (Set{}->union((s)))->size() then ( execute ("No")->display() ) else ( if (k)->characters()->includes(s) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ref(n): return int(''.join([str(9-int(x))for x in str(n)])) l,r=map(int,input().split()) ans=0 ans=max(ans,ref(l)*l) ans=max(ans,ref(r)*r) cur=5 for i in range(20): if(l<=cur<=r): ans=max(ans,ref(cur)*cur) cur*=10 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; ans := Set{ans, ref(l) * l}->max() ; ans := Set{ans, ref(r) * r}->max() ; var cur : int := 5 ; for i : Integer.subrange(0, 20-1) do ( if ((l->compareTo(cur)) <= 0 & (cur <= r)) then ( ans := Set{ans, ref(cur) * cur}->max() ) else skip ; cur := cur * 10) ; execute (ans)->display(); operation ref(n : OclAny) : OclAny pre: true post: true activity: return ("" + ((StringLib.sumStringsWithSeparator((("" + ((n)))->select(x | true)->collect(x | (("" + ((9 - ("" + ((x)))->toInteger())))))), ''))))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): s=sorted(list(input())) if len(s)==1 : print("YES") continue if len(s)!=len(set(s)): print("NO") continue for i in range(1,len(s)): if ord(s[i])-1!=ord(s[i-1]): print("NO") break else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : Sequence := ((OclFile["System.in"]).readLine())->characters()->sort() ; if (s)->size() = 1 then ( execute ("YES")->display() ; continue ) else skip ; if (s)->size() /= (Set{}->union((s)))->size() then ( execute ("NO")->display() ; continue ) else skip ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name ord)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))) - (expr (atom (number (integer 1)))))) != (comparison (expr (atom (name ord)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input(''))): l=list(input()) l.sort() c=0 for i in range(len(l)-1): if ord(l[i+1])-ord(l[i])==1 : c+=1 if c==len(l)-1 or len(l)==1 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine(''))))->toInteger()-1) do ( var l : Sequence := ((OclFile["System.in"]).readLine())->characters() ; l := l->sort() ; var c : int := 0 ; for i : Integer.subrange(0, (l)->size() - 1-1) do ( if (l[i + 1+1])->char2byte() - (l[i+1])->char2byte() = 1 then ( c := c + 1 ) else skip) ; if c = (l)->size() - 1 or (l)->size() = 1 then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x,y=map(int,input().split()) if y % x==0 : print(1,y//x) else : print(0,0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if y mod x = 0 then ( execute (1)->display() ) else ( execute (0)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) while(n>0): s=input() li=[i for i in s] s1=set(li) if(len(s1)!=len(li)): print("No") else : li.sort() k=[ord(i)for i in li] f=0 for i in range(len(k)-1): if(k[i+1]-k[i]!=1): f=1 print("No") break if(f==0): print("Yes") n-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (n > 0) do ( var s : String := (OclFile["System.in"]).readLine() ; var li : Sequence := s->characters()->select(i | true)->collect(i | (i)) ; var s1 : Set := Set{}->union((li)) ; if ((s1)->size() /= (li)->size()) then ( execute ("No")->display() ) else ( li := li->sort() ; var k : Sequence := li->select(i | true)->collect(i | ((i)->char2byte())) ; var f : int := 0 ; for i : Integer.subrange(0, (k)->size() - 1-1) do ( if (k[i + 1+1] - k[i+1] /= 1) then ( f := 1 ; execute ("No")->display() ; break ) else skip) ; if (f = 0) then ( execute ("Yes")->display() ) else skip ) ; n := n - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=input() i,j=0,0 while(itoInteger() ; var m : String := (OclFile["System.in"]).readLine() ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,0} ; while ((i->compareTo(n)) < 0) do ( execute (m[i+1])->display() ; j := j + 1 ; i := i + j); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def solve(s): q=deque(list(s)) m=1 idx=0 ret="" while True : ret+=q[0] for qwe in range(m): q.popleft() if len(q)==0 : break m+=1 return ret input() print(solve(input())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; input() ; execute (solve((OclFile["System.in"]).readLine()))->display(); operation solve(s : OclAny) : OclAny pre: true post: true activity: var q : Sequence := ((s)) ; var m : int := 1 ; var idx : int := 0 ; var ret : String := "" ; while true do ( ret := ret + q->first() ; for qwe : Integer.subrange(0, m-1) do ( q := q->tail()) ; if (q)->size() = 0 then ( break ) else skip ; m := m + 1) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(w,s): result=list() i=step=0 while itoInteger() ; s := (OclFile["System.in"]).readLine() ; execute (solve(w, s))->display() ) else skip; operation solve(w : OclAny, s : OclAny) : OclAny pre: true post: true activity: var result : Sequence := () ; var i : OclAny := 0; var step : int := 0 ; while (i->compareTo(w)) < 0 do ( execute ((s[i+1]) : result) ; step := step + 1 ; i := i + step) ; return StringLib.sumStringsWithSeparator((result), ""); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) s=input() s1="" i=0 n=0 while(itoInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var s1 : String := "" ; var i : int := 0 ; var n : int := 0 ; while ((i->compareTo(t)) < 0) do ( s1 := s1 + s[i+1] ; n := n + 1 ; i := n * (n + 1) div 2) ; execute (s1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) t=input() res='' i=0 k=1 while itoInteger() ; var t : String := (OclFile["System.in"]).readLine() ; var res : String := '' ; var i : int := 0 ; var k : int := 1 ; while (i->compareTo(n)) < 0 do ( res := res + t[i+1] ; i := i + k ; k := k + 1) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def symdiff(n,m,a,b): i,j=0,0 while ib[j]: yield b[j] j+=1 else : i+=1 j+=1 while icompareTo(n)) < 0 & (j->compareTo(m)) < 0 do ( if (a[i+1]->compareTo(b[j+1])) < 0 then ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return a[i+1] ; i := i + 1 ) else (if (a[i+1]->compareTo(b[j+1])) > 0 then ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return b[j+1] ; j := j + 1 ) else ( i := i + 1 ; j := j + 1 ) ) ) ; while (i->compareTo(n)) < 0 do ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return a[i+1] ; i := i + 1) ; while (j->compareTo(m)) < 0 do ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return b[j+1] ; j := j + 1); operation run() pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; m := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; b := input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; for v : symdiff(n, m, a, b) do ( execute (v)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def d(n): w="" for i in str(n): w+=str(9-int(i)) return int(w)*n l,r=map(int,input().split()) r=str(r) tr='5'+'0'*(len(r)-1) tr=int(tr) r=int(r) if lcollect( _x | (OclType["int"])->apply(_x) ) ; var r : String := ("" + ((r))) ; var tr : String := '5' + StringLib.nCopies('0', ((r)->size() - 1)) ; tr := ("" + ((tr)))->toInteger() ; r := ("" + ((r)))->toInteger() ; if l < tr & (tr <= r) then ( execute (Set{d(l), d(r), d(tr)}->max())->display() ) else ( execute (Set{d(l), d(r)}->max())->display() ); operation d(n : OclAny) : OclAny pre: true post: true activity: var w : String := "" ; for i : ("" + ((n))) do ( w := w + ("" + ((9 - ("" + ((i)))->toInteger())))) ; return ("" + ((w)))->toInteger() * n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) A=set(list(map(int,input().split()))) m=int(input()) B=set(list(map(int,input().split()))) answer=A.symmetric_difference(B) [print(i)for i in sorted(answer)] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Set := Set{}->union((((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : Set := Set{}->union((((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var answer : OclAny := A->symmetricDifference(B) ; ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) a=set([int(a)for a in input().split()]) m=int(input()) b=set([int(a)for a in input().split()]) c=a.symmetric_difference(b) sorted_c=sorted(c) for i in sorted_c : print(i) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Set := Set{}->union((input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())))) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Set := Set{}->union((input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())))) ; var c : OclAny := a->symmetricDifference(b) ; var sorted_c : Sequence := c->sort() ; for i : sorted_c do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : input() A=set(map(int,input().split())) input() B=set(map(int,input().split())) C=sorted(A ^ B) for i in C : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( input() ; var A : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; input() ; var B : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var C : Sequence := MathLib.bitwiseXor(A, B)->sort() ; for i : C do ( execute (i)->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): x,y=map(int,input().split()) if x>y or y % x!=0 : print(0,0) elif x==y : print(1,1) else : print(1,y//x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (x->compareTo(y)) > 0 or y mod x /= 0 then ( execute (0)->display() ) else (if x = y then ( execute (1)->display() ) else ( execute (1)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() A=set(int(x)for x in input().split()) input() B=set(int(x)for x in input().split()) for i in sorted((A | B)-(A & B)): print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var A : Set := Set{}->union(((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( )))))))))) ; input() ; var B : Set := Set{}->union(((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( )))))))))) ; for i : (MathLib.bitwiseOr(A, B)) - (MathLib.bitwiseAnd(A, B))->sort() do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minimumChanges(n,a): sf=[0]*(n+1) sf[n]=0 for i in range(n-1,-1,-1): sf[i]=sf[i+1] if(a[i]<=0): sf[i]+=1 pos=0 mn=n for i in range(n-1): if(a[i]>=0): pos+=1 mn=min(mn,pos+sf[i+1]) return mn if __name__=="__main__" : a=[-1,-2,-3,3,-5,3,4] n=len(a) print(minimumChanges(n,a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{-1}->union(Sequence{-2}->union(Sequence{-3}->union(Sequence{3}->union(Sequence{-5}->union(Sequence{3}->union(Sequence{ 4 })))))) ; n := (a)->size() ; execute (minimumChanges(n, a))->display() ) else skip; operation minimumChanges(n : OclAny, a : OclAny) : OclAny pre: true post: true activity: var sf : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; sf[n+1] := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( sf[i+1] := sf[i + 1+1] ; if (a[i+1] <= 0) then ( sf[i+1] := sf[i+1] + 1 ) else skip) ; var pos : int := 0 ; var mn : OclAny := n ; for i : Integer.subrange(0, n - 1-1) do ( if (a[i+1] >= 0) then ( pos := pos + 1 ) else skip ; mn := Set{mn, pos + sf[i + 1+1]}->min()) ; return mn; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printSubArray(arr,start,end): print("[",end="") for i in range(start,end+1): print(arr[i],end="") print("]",end="") def divideArray(arr,n): sum=0 for i in range(0,n): sum+=arr[i] sum_so_far=0 for i in range(0,n): if 2*sum_so_far+arr[i]==sum : print("The array can be divided into","two subarrays with equal sum") print("two subarrays are-",end="") printSubArray(arr,0,i-1) printSubArray(arr,i+1,n-1) return True sum_so_far+=arr[i] print("The array cannot be divided into""two subarrays with equal sum",end="") return False arr=[6,2,3,2,1] n=len(arr) divideArray(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{6}->union(Sequence{2}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 1 })))) ; n := (arr)->size() ; divideArray(arr, n); operation printSubArray(arr : OclAny, start : OclAny, end : OclAny) pre: true post: true activity: execute ("[")->display() ; for i : Integer.subrange(start, end + 1-1) do ( execute (arr[i+1])->display()) ; execute ("]")->display(); operation divideArray(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + arr[i+1]) ; var sum_so_far : int := 0 ; for i : Integer.subrange(0, n-1) do ( if 2 * sum_so_far + arr[i+1] = sum then ( execute ("The array can be divided into")->display() ; execute ("two subarrays are-")->display() ; printSubArray(arr, 0, i - 1) ; printSubArray(arr, i + 1, n - 1) ; return true ) else skip ; sum_so_far := sum_so_far + arr[i+1]) ; execute ((atom "The array cannot be divided into" "two subarrays with equal sum"))->display() ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) t,=R() exec(t*'n,x=R();print(sorted({*range(1,202)}-{*R()})[x]-1);') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := R->apply() ; (expr (expr (atom (name t))) * (expr (atom 'n,x=R();print(sorted({*range(1,202)}-{*R()})[x]-1);'))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input for i in range(int(I())): n,m=map(int,I().split()) l=sorted(list(set(map(int,I().split())))) for i in l : if i<=m+1 : m+=1 print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; for i : Integer.subrange(0, ("" + ((I())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (I().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := (Set{}->union(((I().split())->collect( _x | (OclType["int"])->apply(_x) ))))->sort() ; for i : l do ( if (i->compareTo(m + 1)) <= 0 then ( m := m + 1 ) else skip) ; execute (m)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for p in range(int(input())): n,x=map(int,input().split()) a=list(map(int,input().split())) i=1 while((x>0)or(i in a)): if(i in a): i+=1 continue else : i+=1 x-=1 print(i-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for p : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var i : int := 1 ; while ((x > 0) or ((a)->includes(i))) do ( if ((a)->includes(i)) then ( i := i + 1 ; continue ) else ( i := i + 1 ; x := x - 1 )) ; execute (i - 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) l=list(map(int,input().split())) for i in range(N): t=l[i] j=i-1 while j>=0 and l[j]>t : l[j+1],l[j]=l[j],l[j+1] j-=1 print(*l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, N-1) do ( var t : OclAny := l[i+1] ; var j : double := i - 1 ; while j >= 0 & (l[j+1]->compareTo(t)) > 0 do ( var l[j + 1+1] : OclAny := null; var l[j+1] : OclAny := null; Sequence{l[j + 1+1],l[j+1]} := Sequence{l[j+1],l[j + 1+1]} ; j := j - 1) ; execute ((argument * (test (logical_test (comparison (expr (atom (name l))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,x=map(int,input().split()) aa=list(map(int,input().split())) ss=set() tot=x for i in aa : ss.add(i) ans=0 for i in range(1,300): if i not in ss : tot-=1 if(tot<0): ans=i-1 break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var aa : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ss : Set := Set{}->union(()) ; var tot : OclAny := x ; for i : aa do ( execute ((i) : ss)) ; var ans : int := 0 ; for i : Integer.subrange(1, 300-1) do ( if (ss)->excludes(i) then ( tot := tot - 1 ; if (tot < 0) then ( ans := i - 1 ; break ) else skip ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,x=map(int,input().split()) a=sorted(set(map(int,input().split()))) add=0 for i in range(len(a)): if add+x+1>=a[i]: add+=1 else : break print(add+x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->sort() ; var add : int := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( if (add + x + 1->compareTo(a[i+1])) >= 0 then ( add := add + 1 ) else ( break )) ; execute (add + x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findGeometricTriplets(arr,n): for j in range(1,n-1): i=j-1 k=j+1 while(i>=0 and k<=n-1): while(arr[j]% arr[i]==0 and arr[k]% arr[j]==0 and arr[j]//arr[i]==arr[k]//arr[j]): print(arr[i]," ",arr[j]," ",arr[k]) k+=1 i-=1 if(arr[j]% arr[i]==0 and arr[k]% arr[j]==0): if(arr[j]//arr[i]union(Sequence{2}->union(Sequence{4}->union(Sequence{ 16 }))) ; n := (arr)->size() ; findGeometricTriplets(arr, n) ) else skip; operation findGeometricTriplets(arr : OclAny, n : OclAny) pre: true post: true activity: for j : Integer.subrange(1, n - 1-1) do ( var i : double := j - 1 ; var k : OclAny := j + 1 ; while (i >= 0 & (k->compareTo(n - 1)) <= 0) do ( while (arr[j+1] mod arr[i+1] = 0 & arr[k+1] mod arr[j+1] = 0 & arr[j+1] div arr[i+1] = arr[k+1] div arr[j+1]) do ( execute (arr[i+1])->display() ; k := k + 1 ; i := i - 1) ; if (arr[j+1] mod arr[i+1] = 0 & arr[k+1] mod arr[j+1] = 0) then ( if ((arr[j+1] div arr[i+1]->compareTo(arr[k+1] div arr[j+1])) < 0) then ( i := i - 1 ) else ( k := k + 1 ) ) else (if (arr[j+1] mod arr[i+1] = 0) then ( k := k + 1 ) else ( i := i - 1 ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numOfAlarms=int(input()) columns=set() rows=set() for i in range(numOfAlarms): x=input().split(' ') columns.add(x[0]) rows.add(x[1]) print(min(len(columns),len(rows))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var numOfAlarms : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var columns : Set := Set{}->union(()) ; var rows : Set := Set{}->union(()) ; for i : Integer.subrange(0, numOfAlarms-1) do ( var x : OclAny := input().split(' ') ; execute ((x->first()) : columns) ; execute ((x[1+1]) : rows)) ; execute (Set{(columns)->size(), (rows)->size()}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): x,y=map(int,input().split()) if x>y : print(0,0) elif y % x!=0 : print(0,0) else : print(1,y//x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (x->compareTo(y)) > 0 then ( execute (0)->display() ) else (if y mod x /= 0 then ( execute (0)->display() ) else ( execute (1)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h=set() v=set() for i in range(int(input())): k=input().split() v.add(k[0]) h.add(k[1]) print(min(len(v),len(h))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : Set := Set{}->union(()) ; var v : Set := Set{}->union(()) ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var k : OclAny := input().split() ; execute ((k->first()) : v) ; execute ((k[1+1]) : h)) ; execute (Set{(v)->size(), (h)->size()}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : numAlarmClocks=int(input()) xDict={} yDict={} for i in range(numAlarmClocks): xPos,yPos=input().split(" ") if xPos in xDict : xDict[xPos]+=1 else : xDict[xPos]=1 if yPos in yDict : yDict[yPos]+=1 else : yDict[yPos]=1 print(min(len(xDict),len(yDict))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var numAlarmClocks : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var xDict : OclAny := Set{} ; var yDict : OclAny := Set{} ; for i : Integer.subrange(0, numAlarmClocks-1) do ( var xPos : OclAny := null; var yPos : OclAny := null; Sequence{xPos,yPos} := input().split(" ") ; if (xDict)->includes(xPos) then ( xDict[xPos+1] := xDict[xPos+1] + 1 ) else ( xDict[xPos+1] := 1 ) ; if (yDict)->includes(yPos) then ( yDict[yPos+1] := yDict[yPos+1] + 1 ) else ( yDict[yPos+1] := 1 )) ; execute (Set{(xDict)->size(), (yDict)->size()}->min())->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- data=input() arr=[] for i in range(102): temp=[] for j in range(102): temp.append("o") arr.append(temp) for i in range(int(data)): pos=input() pos=pos.split(" ") x=int(pos[0]) y=int(pos[1]) arr[x][y]="x" h_count=0 for i in range(len(arr)): for j in range(len(arr[0])): if arr[i][j]=="x" : h_count+=1 break v_count=0 for i in range(len(arr)): for j in range(len(arr)): if arr[j][i]=="x" : v_count+=1 break print(min(v_count,h_count)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var data : String := (OclFile["System.in"]).readLine() ; var arr : Sequence := Sequence{} ; for i : Integer.subrange(0, 102-1) do ( var temp : Sequence := Sequence{} ; for j : Integer.subrange(0, 102-1) do ( execute (("o") : temp)) ; execute ((temp) : arr)) ; for i : Integer.subrange(0, ("" + ((data)))->toInteger()-1) do ( var pos : String := (OclFile["System.in"]).readLine() ; pos := pos.split(" ") ; var x : int := ("" + ((pos->first())))->toInteger() ; var y : int := ("" + ((pos[1+1])))->toInteger() ; arr[x+1][y+1] := "x") ; var h_count : int := 0 ; for i : Integer.subrange(0, (arr)->size()-1) do ( for j : Integer.subrange(0, (arr->first())->size()-1) do ( if arr[i+1][j+1] = "x" then ( h_count := h_count + 1 ; break ) else skip)) ; var v_count : int := 0 ; for i : Integer.subrange(0, (arr)->size()-1) do ( for j : Integer.subrange(0, (arr)->size()-1) do ( if arr[j+1][i+1] = "x" then ( v_count := v_count + 1 ; break ) else skip)) ; execute (Set{v_count, h_count}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numOfAlarms=int(input()) columns=set() rows=set() for i in range(numOfAlarms): x=input() columns.add(x.split(' ')[0]) rows.add(x.split(' ')[1]) if len(columns)toInteger() ; var columns : Set := Set{}->union(()) ; var rows : Set := Set{}->union(()) ; for i : Integer.subrange(0, numOfAlarms-1) do ( var x : String := (OclFile["System.in"]).readLine() ; execute ((x.split(' ')->first()) : columns) ; execute ((x.split(' ')[1+1]) : rows)) ; if ((columns)->size()->compareTo((rows)->size())) < 0 then ( execute ((columns)->size())->display() ) else (if ((rows)->size()->compareTo((columns)->size())) <= 0 then ( execute ((rows)->size())->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSubstrs(str,i,j,n): if(n==1): return 1 if(n<=0): return 0 res=(countSubstrs(str,i+1,j,n-1)+countSubstrs(str,i,j-1,n-1)-countSubstrs(str,i+1,j-1,n-2)) if(str[i]==str[j]): res+=1 return res str="abcab" n=len(str) print(countSubstrs(str,0,n-1,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclType["String"] := "abcab" ; n := (OclType["String"])->size() ; execute (countSubstrs(OclType["String"], 0, n - 1, n))->display(); operation countSubstrs(OclType["String"] : OclAny, i : OclAny, j : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return 1 ) else skip ; if (n <= 0) then ( return 0 ) else skip ; var res : double := (countSubstrs(OclType["String"], i + 1, j, n - 1) + countSubstrs(OclType["String"], i, j - 1, n - 1) - countSubstrs(OclType["String"], i + 1, j - 1, n - 2)) ; if (("" + ([i+1])) = ("" + ([j+1]))) then ( res := res + 1 ) else skip ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def insertion_sort(arr): for i in range(1,len(arr)): temp=arr[i] j=i-1 while j>=0 and arr[j]>temp : arr[j+1]=arr[j] j-=1 arr[j+1]=temp print(' '.join(map(str,arr))) if __name__=='__main__' : N=int(input()) arr=[int(n)for n in input().split()] print(' '.join(map(str,arr))) insertion_sort(arr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; arr := input().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; execute (StringLib.sumStringsWithSeparator(((arr)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ; insertion_sort(arr) ) else skip; operation insertion_sort(arr : OclAny) pre: true post: true activity: for i : Integer.subrange(1, (arr)->size()-1) do ( var temp : OclAny := arr[i+1] ; var j : double := i - 1 ; while j >= 0 & (arr[j+1]->compareTo(temp)) > 0 do ( arr[j + 1+1] := arr[j+1] ; j := j - 1) ; arr[j + 1+1] := temp ; execute (StringLib.sumStringsWithSeparator(((arr)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- PI=3.14159265 def area_cicumscribed(a): return(a*a*(PI/3)) a=6.0 print("Area of circumscribed circle is :%f" % area_cicumscribed(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var PI : double := 3.14159265 ; skip ; a := 6.0 ; execute (StringLib.format("Area of circumscribed circle is :%f",area_cicumscribed(a)))->display(); operation area_cicumscribed(a : OclAny) : OclAny pre: true post: true activity: return (a * a * (PI / 3)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def Parts(Arr,N): factor=Arr[1]-Arr[0] for i in range(2,N): factor=math.gcd(factor,Arr[i]-Arr[i-1]) factor=math.gcd(factor,360-Arr[N-1]+Arr[0]) cuts=(360//factor)-N return cuts if __name__=="__main__" : Arr=[0,1] N=len(Arr) print(Parts(Arr,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( Arr := Sequence{0}->union(Sequence{ 1 }) ; N := (Arr)->size() ; execute (Parts(Arr, N))->display() ) else skip; operation Parts(Arr : OclAny, N : OclAny) : OclAny pre: true post: true activity: var factor : double := Arr[1+1] - Arr->first() ; for i : Integer.subrange(2, N-1) do ( factor := (factor)->gcd(Arr[i+1] - Arr[i - 1+1])) ; factor := (factor)->gcd(360 - Arr[N - 1+1] + Arr->first()) ; var cuts : double := (360 div factor) - N ; return cuts; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys for e in sys.stdin : e=list(map(float,e.split(','))) print(['YES','NO'][sum((e[i]-e[(2+i)% 8])*(e[(5+i)% 8]-e[(3+i)% 8])-(e[1+i]-e[(3+i)% 8])*(e[(4+i)% 8]-e[(2+i)% 8])>0 for i in range(0,8,2))% 4>0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for e : OclFile["System.in"] do ( var e : Sequence := ((e.split(','))->collect( _x | (OclType["double"])->apply(_x) )) ; execute (Sequence{'YES'}->union(Sequence{ 'NO' })->select(((argument (test (logical_test (comparison (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) + (expr (atom (name i)))))))) ))) % (expr (atom (number (integer 8)))))))))) ])))))))) ))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 5)))) + (expr (atom (name i)))))))) ))) % (expr (atom (number (integer 8)))))))))) ]))) - (expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 3)))) + (expr (atom (name i)))))))) ))) % (expr (atom (number (integer 8)))))))))) ])))))))) )))) - (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) + (expr (atom (name i))))))))) ]))) - (expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 3)))) + (expr (atom (name i)))))))) ))) % (expr (atom (number (integer 8)))))))))) ])))))))) ))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 4)))) + (expr (atom (name i)))))))) ))) % (expr (atom (number (integer 8)))))))))) ]))) - (expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) + (expr (atom (name i)))))))) ))) % (expr (atom (number (integer 8)))))))))) ])))))))) )))))) > (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 8)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))))))))->sum() mod 4 > 0))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import atan,pi E=10**-10 def cross(a0,a1,b0,b1): return a0*b1-a1*b0 while(1): a=[0 for i in range(2)] b=[0 for i in range(2)] c=[0 for i in range(2)] d=[0 for i in range(2)] try : a[0],a[1],b[0],b[1],c[0],c[1],d[0],d[1]=[float(i)for i in input().split(",")] A=cross((d[1]-a[1]),(d[0]-a[0]),(b[1]-a[1]),(b[0]-a[0])) B=cross((c[1]-d[1]),(c[0]-d[0]),(a[1]-d[1]),(a[0]-d[0])) C=cross((b[1]-c[1]),(b[0]-c[0]),(d[1]-c[1]),(d[0]-c[0])) D=cross((a[1]-b[1]),(a[0]-b[0]),(c[1]-b[1]),(c[0]-b[0])) if A*B*C*D<0 : print("NO") else : print("YES") except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var E : double := (10)->pow(-10) ; skip ; while (1) do ( var a : Sequence := Integer.subrange(0, 2-1)->select(i | true)->collect(i | (0)) ; var b : Sequence := Integer.subrange(0, 2-1)->select(i | true)->collect(i | (0)) ; var c : Sequence := Integer.subrange(0, 2-1)->select(i | true)->collect(i | (0)) ; var d : Sequence := Integer.subrange(0, 2-1)->select(i | true)->collect(i | (0)) ; try ( var a->first() : OclAny := null; var a[1+1] : OclAny := null; var b->first() : OclAny := null; var b[1+1] : OclAny := null; var c->first() : OclAny := null; var c[1+1] : OclAny := null; var d->first() : OclAny := null; var d[1+1] : OclAny := null; Sequence{a->first(),a[1+1],b->first(),b[1+1],c->first(),c[1+1],d->first(),d[1+1]} := input().split(",")->select(i | true)->collect(i | (("" + ((i)))->toReal())) ; var A : OclAny := cross((d[1+1] - a[1+1]), (d->first() - a->first()), (b[1+1] - a[1+1]), (b->first() - a->first())) ; var B : OclAny := cross((c[1+1] - d[1+1]), (c->first() - d->first()), (a[1+1] - d[1+1]), (a->first() - d->first())) ; var C : OclAny := cross((b[1+1] - c[1+1]), (b->first() - c->first()), (d[1+1] - c[1+1]), (d->first() - c->first())) ; var D : OclAny := cross((a[1+1] - b[1+1]), (a->first() - b->first()), (c[1+1] - b[1+1]), (c->first() - b->first())) ; if A * B * C * D < 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() )) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); operation cross(a0 : OclAny, a1 : OclAny, b0 : OclAny, b1 : OclAny) : OclAny pre: true post: true activity: return a0 * b1 - a1 * b0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys class Vector(object): def __init__(self,_from,to): self.x=to[0]-_from[0] self.y=to[1]-_from[1] def cross(self,other : "Vector")->float : return self.x*other.y-self.y*other.x for a in(list(map(float,l.split(",")))for l in sys.stdin): points=[(x,y)for x,y in zip(a[: : 2],a[1 : : 2])] sign={Vector(p2,p3).cross(Vector(p2,p1))>0 for p1,p2,p3 in zip(points,points[1 :]+points,points[2 :]+points)} print("YES" if len(sign)==1 else "NO") ------------------------------------------------------------ OCL File: --------- class Vector extends object { static operation newVector() : Vector pre: true post: Vector->exists( _x | result = _x ); attribute x : double := to->first() - _from->first(); attribute y : double := to[1+1] - _from[1+1]; operation initialise(_from : OclAny,to : OclAny) : pre: true post: true activity: self.x := to->first() - _from->first() ; self.y := to[1+1] - _from[1+1]; return self; operation cross(other : "Vector") : double pre: true post: true activity: return self.x * other.y - self.y * other.x; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for a : Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name float))))))) , (argument (test (logical_test (comparison (expr (atom (name l)) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ","))))))) ))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name l)))) in (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin)))))))} do ( var points : Sequence := Integer.subrange(1, a(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{a(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->at(_indx), a(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->at(_indx)} )->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (Sequence{x, y})) ; var sign : Set := Integer.subrange(1, points->size())->collect( _indx | Sequence{points->at(_indx), points->tail()->union(points)->at(_indx)} )->select(_tuple | true)->collect(_tuple | Vector(p2, p3).cross((Vector.newVector()).initialise(p2, p1)) > 0)->asSet() ; execute (if (sign)->size() = 1 then "YES" else "NO" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) s=input() ans=n for idx in range(1,n): if s[idx-1]!=s[idx]: ans+=idx print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var ans : int := n ; for idx : Integer.subrange(1, n-1) do ( if s[idx - 1+1] /= s[idx+1] then ( ans := ans + idx ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- EPS=0.0001 def atSameSide(a,b,line): sa=(line[1].real-line[0].real)*(a.imag-line[0].imag)+(line[1].imag-line[0].imag)*(line[0].real-a.real); sb=(line[1].real-line[0].real)*(b.imag-line[0].imag)+(line[1].imag-line[0].imag)*(line[0].real-b.real); if-EPS<=sa and sa<=EPS : return 0 if-EPS<=sb and sb<=EPS : return 0 if sa*sb>=0 : return 1 return-1 ; while True : try : p=list(map(float,input().split(','))) except : break p1=complex(p[0],p[1]) p2=complex(p[2],p[3]) p3=complex(p[4],p[5]) p4=complex(p[6],p[7]) if atSameSide(p2,p4,[p1,p3])==-1 and atSameSide(p1,p3,[p2,p4])==-1 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var EPS : double := 0.0001 ; skip ; while true do ( try ( var p : Sequence := ((input().split(','))->collect( _x | (OclType["double"])->apply(_x) ))) catch (_e : OclException) do ( break) ; var p1 : OclAny := complex(p->first(), p[1+1]) ; var p2 : OclAny := complex(p[2+1], p[3+1]) ; var p3 : OclAny := complex(p[4+1], p[5+1]) ; var p4 : OclAny := complex(p[6+1], p[7+1]) ; if atSameSide(p2, p4, Sequence{p1}->union(Sequence{ p3 })) = -1 & atSameSide(p1, p3, Sequence{p2}->union(Sequence{ p4 })) = -1 then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); operation atSameSide(a : OclAny, b : OclAny, line : OclAny) : OclAny pre: true post: true activity: var sa : double := (line[1+1].real - line->first().real) * (a.imag - line->first().imag) + (line[1+1].imag - line->first().imag) * (line->first().real - a.real); ; var sb : double := (line[1+1].real - line->first().real) * (b.imag - line->first().imag) + (line[1+1].imag - line->first().imag) * (line->first().real - b.real); ; if (-EPS->compareTo(sa)) <= 0 & (sa->compareTo(EPS)) <= 0 then ( return 0 ) else skip ; if (-EPS->compareTo(sb)) <= 0 & (sb->compareTo(EPS)) <= 0 then ( return 0 ) else skip ; if sa * sb >= 0 then ( return 1 ) else skip ; return -1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def angleis(p1,p2): return True if p1[0]*p2[1]-p1[1]*p2[0]>0 else False Ps=sys.stdin.readlines() for P in Ps : xa,ya,xb,yb,xc,yc,xd,yd=map(float,P.split(',')) p=[[xb-xa,yb-ya],[xc-xb,yc-yb],[xd-xc,yd-yc],[xa-xd,ya-yd],[xb-xa,yb-ya]] a=[] for i in range(4): a.append(angleis(p[i],p[i+1])) if a.count(True)==0 or a.count(True)==4 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var Ps : OclAny := (OclFile["System.in"]).readlines() ; for P : Ps do ( var xa : OclAny := null; var ya : OclAny := null; var xb : OclAny := null; var yb : OclAny := null; var xc : OclAny := null; var yc : OclAny := null; var xd : OclAny := null; var yd : OclAny := null; Sequence{xa,ya,xb,yb,xc,yc,xd,yd} := (P.split(','))->collect( _x | (OclType["double"])->apply(_x) ) ; var p : Sequence := Sequence{Sequence{xb - xa}->union(Sequence{ yb - ya })}->union(Sequence{Sequence{xc - xb}->union(Sequence{ yc - yb })}->union(Sequence{Sequence{xd - xc}->union(Sequence{ yd - yc })}->union(Sequence{Sequence{xa - xd}->union(Sequence{ ya - yd })}->union(Sequence{ Sequence{xb - xa}->union(Sequence{ yb - ya }) })))) ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, 4-1) do ( execute ((angleis(p[i+1], p[i + 1+1])) : a)) ; if a->count(true) = 0 or a->count(true) = 4 then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); operation angleis(p1 : OclAny, p2 : OclAny) : OclAny pre: true post: true activity: return if p1->first() * p2[1+1] - p1[1+1] * p2->first() > 0 then true else false endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) while n % 3==0 : n//=3 if n % 3==0 : print(1) else : print(n//3+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while n mod 3 = 0 do ( n := n div 3) ; if n mod 3 = 0 then ( execute (1)->display() ) else ( execute (n div 3 + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) a=1 while n % a==0 : a*=3 print(n//a+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := 1 ; while n mod a = 0 do ( a := a * 3) ; execute (n div a + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) data=list(map(int,input().split())) for i in range(num): for j in range(i,0,-1): if data[j]toInteger() ; var data : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, num-1) do ( for j : Integer.subrange(0 + 1, i)->reverse() do ( if (data[j+1]->compareTo(data[j - 1+1])) < 0 then ( var data[j - 1+1] : OclAny := null; var data[j+1] : OclAny := null; Sequence{data[j - 1+1],data[j+1]} := Sequence{data[j+1],data[j - 1+1]} ) else skip) ; execute (StringLib.sumStringsWithSeparator(((data)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil def seal(a,b): return(a+b-1)//b n=int(input()) i=0 while(n % pow(3,i)==0): i+=1 print(seal(n,pow(3,i))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 0 ; while (n mod (3)->pow(i) = 0) do ( i := i + 1) ; execute (seal(n, (3)->pow(i)))->display(); operation seal(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a + b - 1) div b; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=1 while n % a==0 : a*=3 print(n//a+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := 1 ; while n mod a = 0 do ( a := a * 3) ; execute (n div a + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) while n % 3==0 : n//=3 print((n-1)//3+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while n mod 3 = 0 do ( n := n div 3) ; execute ((n - 1) div 3 + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def drawPattern(N): n=N ; row=1 ; nst=1 ; nsp1=n-1 ; nsp2=-1 ; val1=row ; val2=1 ; while(row<=n): csp1=1 ; while(csp1<=nsp1): print(" ",end=" "); csp1=csp1+1 ; cst1=1 ; while(cst1<=nst): print(val1,end=" "); val1=val1-1 ; cst1=cst1+1 ; csp2=1 ; while(csp2<=nsp2): print(" ",end=" "); csp2=csp2+1 ; if(row!=1 and row!=n): cst2=1 ; while(cst2<=nst): print(val2,end=" "); val2=val2+1 ; cst2=cst2+1 ; print() if(row<=n//2): nst=nst+1 ; nsp1=nsp1-2 ; nsp2=nsp2+2 ; val1=row+1 ; val2=1 ; else : nst=nst-1 ; nsp1=nsp1+2 ; nsp2=nsp2-2 ; val1=n-row ; val2=1 ; row=row+1 ; if __name__=="__main__" : N=7 ; drawPattern(N); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := 7; ; drawPattern(N); ) else skip; operation drawPattern(N : OclAny) pre: true post: true activity: var n : OclAny := N; ; var row : int := 1; ; var nst : int := 1; ; var nsp1 : double := n - 1; ; var nsp2 : int := -1; ; var val1 : int := row; ; var val2 : int := 1; ; while ((row->compareTo(n)) <= 0) do ( var csp1 : int := 1; ; while ((csp1->compareTo(nsp1)) <= 0) do ( execute (" ")->display(); ; csp1 := csp1 + 1;) ; var cst1 : int := 1; ; while ((cst1->compareTo(nst)) <= 0) do ( execute (val1)->display(); ; val1 := val1 - 1; ; cst1 := cst1 + 1;) ; var csp2 : int := 1; ; while ((csp2->compareTo(nsp2)) <= 0) do ( execute (" ")->display(); ; csp2 := csp2 + 1;) ; if (row /= 1 & row /= n) then ( var cst2 : int := 1; ; while ((cst2->compareTo(nst)) <= 0) do ( execute (val2)->display(); ; val2 := val2 + 1; ; cst2 := cst2 + 1;) ) else skip ; execute (->display() ; if ((row->compareTo(n div 2)) <= 0) then ( nst := nst + 1; ; nsp1 := nsp1 - 2; ; nsp2 := nsp2 + 2; ; val1 := row + 1; ; val2 := 1; ) else ( nst := nst - 1; ; nsp1 := nsp1 + 2; ; nsp2 := nsp2 - 2; ; val1 := n - row; ; val2 := 1; ) ; row := row + 1;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binarySearch(arr,l,r,x): if(r>=l): mid=int(l+(r-l)/2) if(arr[mid]==x): return mid if(mid>l and arr[mid-1]==x): return(mid-1) if(midx): return binarySearch(arr,l,mid-2,x) return binarySearch(arr,mid+2,r,x) return-1 arr=[3,2,10,4,40] n=len(arr) x=4 result=binarySearch(arr,0,n-1,x) if(result==-1): print("Element is not present in array") else : print("Element is present at index",result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{3}->union(Sequence{2}->union(Sequence{10}->union(Sequence{4}->union(Sequence{ 40 })))) ; var n : int := (arr)->size() ; x := 4 ; var result : OclAny := binarySearch(arr, 0, n - 1, x) ; if (result = -1) then ( execute ("Element is not present in array")->display() ) else ( execute ("Element is present at index")->display() ); operation binarySearch(arr : OclAny, l : OclAny, r : OclAny, x : OclAny) : OclAny pre: true post: true activity: if ((r->compareTo(l)) >= 0) then ( var mid : int := ("" + ((l + (r - l) / 2)))->toInteger() ; if (arr[mid+1] = x) then ( return mid ) else skip ; if ((mid->compareTo(l)) > 0 & arr[mid - 1+1] = x) then ( return (mid - 1) ) else skip ; if ((mid->compareTo(r)) < 0 & arr[mid + 1+1] = x) then ( return (mid + 1) ) else skip ; if ((arr[mid+1]->compareTo(x)) > 0) then ( return binarySearch(arr, l, mid - 2, x) ) else skip ; return binarySearch(arr, mid + 2, r, x) ) else skip ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) nums=list(map(int,input().split())) s,f,m=0,0,0 for i in nums : s+=i if s<0 : m=1 break if s==0 : f=1 if f and s>0 : m=1 break if m or not f : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nums : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : OclAny := null; var f : OclAny := null; var m : OclAny := null; Sequence{s,f,m} := Sequence{0,0,0} ; for i : nums do ( s := s + i ; if s < 0 then ( var m : int := 1 ; break ) else skip ; if s = 0 then ( var f : int := 1 ) else skip ; if f & s > 0 then ( m := 1 ; break ) else skip) ; if m or not(f) then ( execute ("NO")->display() ) else ( execute ("YES")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout,setrecursionlimit from math import gcd,floor,sqrt,log from collections import defaultdict as dd from bisect import bisect_left as bl,bisect_right as br inp=lambda : int(input()) strng=lambda : input().strip() jn=lambda x,l : x.join(map(str,l)) strl=lambda : list(input().strip()) mul=lambda : map(int,input().strip().split()) mulf=lambda : map(float,input().strip().split()) seq=lambda : list(map(int,input().strip().split())) ceil=lambda x : int(x)if(x==int(x))else int(x)+1 ceildiv=lambda x,d : x//d if(x % d==0)else x//d+1 flush=lambda : stdout.flush() stdstr=lambda : stdin.readline() stdint=lambda : int(stdin.readline()) stdpr=lambda x : stdout.write(str(x)) mod=1000000007 def solve(): n=inp() s=stdstr() c=0 first=s[0] delta=[] for i in range(n): if s[i]==first : c+=1 else : delta.append(c) c=1 first=s[i] delta.append(c) c=0 for i in range(len(delta)): c+=delta[i] if i-1>=0 : c-=delta[i-1] if i+1toInteger()) ; var strng : Function := lambda $$ : OclAny in (input()->trim()) ; var jn : Function := lambda x : OclAny, l : OclAny in (StringLib.sumStringsWithSeparator(((l)->collect( _x | (OclType["String"])->apply(_x) )), x)) ; var strl : Function := lambda $$ : OclAny in ((input()->trim())) ; var mul : Function := lambda $$ : OclAny in ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mulf : Function := lambda $$ : OclAny in ((input()->trim().split())->collect( _x | (OclType["double"])->apply(_x) )) ; var seq : Function := lambda $$ : OclAny in (((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ceil : Function := lambda x : OclAny in (if (x = ("" + ((x)))->toInteger()) then ("" + ((x)))->toInteger() else ("" + ((x)))->toInteger() + 1 endif) ; var ceildiv : Function := lambda x : OclAny, d : OclAny in (if (x mod d = 0) then x div d else x div d + 1 endif) ; var flush : Function := lambda $$ : OclAny in (stdout.flush()) ; var stdstr : Function := lambda $$ : OclAny in (stdin.readLine()) ; var stdint : Function := lambda $$ : OclAny in (("" + ((stdin.readLine())))->toInteger()) ; var stdpr : Function := lambda x : OclAny in (stdout.write(("" + ((x))))) ; var mod : int := 1000000007 ; skip ; for tc : Integer.subrange(0, inp->apply()-1) do ( stdpr(solve()) ; stdpr(' ')); operation solve() : OclAny pre: true post: true activity: var n : OclAny := inp->apply() ; var s : OclAny := stdstr->apply() ; var c : int := 0 ; var first : OclAny := s->first() ; var delta : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = first then ( c := c + 1 ) else ( execute ((c) : delta) ; c := 1 ; first := s[i+1] )) ; execute ((c) : delta) ; c := 0 ; for i : Integer.subrange(0, (delta)->size()-1) do ( c := c + delta[i+1] ; if i - 1 >= 0 then ( c := c - delta[i - 1+1] ) else skip ; if (i + 1->compareTo((delta)->size())) < 0 then ( delta[i + 1+1] := delta[i + 1+1] + delta[i+1] ; c := c + delta[i+1] ) else skip) ; return c; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input for _ in[0]*int(I()): I(); p,z,zero=0,1,0 for v in I().split(): p+=int(v) if zero and p>0 : z=0 ; break if p==0 : zero=True if p<0 : z=0 ; break print(['NO','YES'][zero and z]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + ((I())))->toInteger()) do ( I(); var p : OclAny := null; var z : OclAny := null; var zero : OclAny := null; Sequence{p,z,zero} := Sequence{0,1,0} ; for v : I().split() do ( p := p + ("" + ((v)))->toInteger() ; if zero & p > 0 then ( var z : int := 0; break ) else skip ; if p = 0 then ( var zero : boolean := true ) else skip ; if p < 0 then ( z := 0; break ) else skip) ; execute (Sequence{'NO'}->union(Sequence{ 'YES' })->select(zero & z))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate from sys import stdin input=stdin.buffer.readline def func(): while a and a[-1]==0 : a.pop() print('NO' if sum(a)!=0 or any([x<=0 for x in list(accumulate(a[:-1]))])else 'YES') for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) func() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.buffer.readline ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; func()); operation func() pre: true post: true activity: while a & a->last() = 0 do ( a := a->front()) ; execute (if (a)->sum() /= 0 or ((accumulate(a->front()))->select(x | true)->collect(x | (x <= 0)))->exists( _x | _x = true ) then 'NO' else 'YES' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): t=int(input()) while t : t-=1 n=int(input()) arr=list(map(int,input().split())) ps=[0 for _ in range(n+1)] for i in range(1,n+1): ps[i]=ps[i-1]+arr[i-1] ok=True if ps[n]!=0 : print("NO") continue for p in ps[1 :]: if p<0 : ok=False vz=False for p in ps[1 :]: if p==0 : vz=True elif vz==True : ok=False if(ok): print("YES") else : print("NO") if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( t := t - 1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ps : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (0)) ; for i : Integer.subrange(1, n + 1-1) do ( ps[i+1] := ps[i - 1+1] + arr[i - 1+1]) ; var ok : boolean := true ; if ps[n+1] /= 0 then ( execute ("NO")->display() ; continue ) else skip ; for p : ps->tail() do ( if p < 0 then ( ok := false ) else skip) ; var vz : boolean := false ; for p : ps->tail() do ( if p = 0 then ( vz := true ) else (if vz = true then ( ok := false ) else skip)) ; if (ok) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def insertSort(input_list): print(' '.join([str(i)for i in input_list])) for i in range(1,len(input_list)): tmp=input_list[i] j=i-1 while j>=0 and input_list[j]>tmp : input_list[j+1]=input_list[j] j-=1 input_list[j+1]=tmp print(' '.join([str(i)for i in input_list])) if __name__=='__main__' : N=int(input()) L=input() input_list=[int(i)for i in L.split()] insertSort(input_list) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var L : String := (OclFile["System.in"]).readLine() ; input_list := L.split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; insertSort(input_list) ) else skip; operation insertSort(input_list : OclAny) pre: true post: true activity: execute (StringLib.sumStringsWithSeparator((input_list->select(i | true)->collect(i | (("" + ((i)))))), ' '))->display() ; for i : Integer.subrange(1, (input_list)->size()-1) do ( var tmp : OclAny := input_list[i+1] ; var j : double := i - 1 ; while j >= 0 & (input_list[j+1]->compareTo(tmp)) > 0 do ( input_list[j + 1+1] := input_list[j+1] ; j := j - 1 ; input_list[j + 1+1] := tmp) ; execute (StringLib.sumStringsWithSeparator((input_list->select(i | true)->collect(i | (("" + ((i)))))), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from collections import Counter from collections import defaultdict def get_ints(): return list(map(int,sys.stdin.readline().strip().split())) def get_string(): return sys.stdin.readline().strip() def solve(arr): summ=0 for i in range(len(arr)): summ+=arr[i] if summ<0 : return "NO" if summ==0 : for j in range(i+1,len(arr)): if arr[j]!=0 : return "NO" return "YES" if summ==0 : return "YES" return "NO" t=int(input()) for _ in range(t): n=get_ints() arr=get_ints() print(solve(arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := get_ints() ; arr := get_ints() ; execute (solve(arr))->display()); operation get_ints() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation get_string() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation solve(arr : OclAny) : OclAny pre: true post: true activity: var summ : int := 0 ; for i : Integer.subrange(0, (arr)->size()-1) do ( summ := summ + arr[i+1] ; if summ < 0 then ( return "NO" ) else skip ; if summ = 0 then ( for j : Integer.subrange(i + 1, (arr)->size()-1) do ( if arr[j+1] /= 0 then ( return "NO" ) else skip) ; return "YES" ) else skip) ; if summ = 0 then ( return "YES" ) else skip ; return "NO"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N,K=[int(i)for i in input().split()] l=[(i,N-i-1)for i in range(N//2)] if K==3 and N==4 : print(-1) return elif K==2 and N==4 : print("0 1") print("2 3") return try : if K==0 : pass elif Kselect(i | true)->collect(i | (("" + ((i)))->toInteger()))->first() ; for p : Integer.subrange(0, num_of_cases-1) do ( var output : OclAny := main()); operation main() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var l : Sequence := Integer.subrange(0, N div 2-1)->select(i | true)->collect(i | (Sequence{i, N - i - 1})) ; if K = 3 & N = 4 then ( execute (-1)->display() ; return ) else (if K = 2 & N = 4 then ( execute ("0 1")->display() ; execute ("2 3")->display() ; return ) else skip) ; try ( if K = 0 then ( skip ) else (if (K->compareTo(N - 1)) < 0 then ( execute (((Sequence{K, N - K - 1}->sort())) /: l) ; execute (((Sequence{0, N - 1}->sort())) /: l) ; execute (((Sequence{K, N - 1}->sort())) : l) ; execute (((Sequence{0, N - K - 1}->sort())) : l) ) else ( execute (((Sequence{1, N - 2}->sort())) /: l) ; execute (((Sequence{0, N - 1}->sort())) /: l) ; execute (((Sequence{N - 2, N - 1}->sort())) : l) ; execute (((Sequence{0, 1}->sort())) : l) ; execute (((Sequence{2, N - 3}->sort())) /: l) ; execute (((Sequence{3, N - 4}->sort())) /: l) ; execute (((Sequence{2, N - 4}->sort())) : l) ; execute (((Sequence{3, N - 3}->sort())) : l) ) ) ) catch (e : ProgramException) do ( execute (l)->display() ; execute (Sequence{K, N - K - 1})->display() ; error e.newe) ; for x : l do ( execute (StringLib.sumStringsWithSeparator((x->select(y | true)->collect(y | (("" + ((y)))))), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def decode(n,k): res=[] for i in range(n//2): res.append([i,n-1-i]) if k==n-1 : res[0][0]=n-2 res[1][1]=n-3 res[2][1]=0 return res ind=min(k,n-1-k) if ind==k : res[ind][0]=0 else : res[ind][1]=0 res[0][0]=k return res x=int(input()) for ij in range(x): n,k=map(int,input().split()) if k==n-1 and n==4 : print(-1) else : result=decode(n,k) for i in result : print(i[0],i[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for ij : Integer.subrange(0, x-1) do ( Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if k = n - 1 & n = 4 then ( execute (-1)->display() ) else ( var result : OclAny := decode(n, k) ; for i : result do ( execute (i->first())->display()) )); operation decode(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var res : Sequence := Sequence{} ; for i : Integer.subrange(0, n div 2-1) do ( execute ((Sequence{i}->union(Sequence{ n - 1 - i })) : res)) ; if k = n - 1 then ( res->first()->first() := n - 2 ; res[1+1][1+1] := n - 3 ; res[2+1][1+1] := 0 ; return res ) else skip ; var ind : OclAny := Set{k, n - 1 - k}->min() ; if ind = k then ( res[ind+1]->first() := 0 ) else ( res[ind+1][1+1] := 0 ) ; res->first()->first() := k ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect from collections import defaultdict,deque from functools import lru_cache import heapq mod=10**9+7 from sys import stdin,stdout input=stdin.readline import math def ii(): return int(input()) def lii(): return list(map(int,stdin.readline().split())) def ss(): x=stdin.readline() if x[-1]=="\n" : return x[:-1] return x def lss(): return list(map(str,stdin.readline().split())) def yes(): stdout.write("YES\n") def no(): stdout.write("NO\n") for _ in range(ii()): n,k=lii() if k==n-1 : if n==4 : print(-1) else : print(n-1,n-2) print(1,3) arr=[i for i in range(2,n-2)if i!=3] for j in range(len(arr)//2): print(arr[j],(n-1)^ arr[j]) print(0,(n-1)^ 3) else : if k==0 : for i in range(n//2): print(i,(n-1)^ i) else : print(k,n-1) h={k : 0} arr=[i for i in range(1,n-1)if i!=k and i!=(n-1)^ k] flag=False for i in range(len(arr)//2): x,y=arr[i],arr[i]^(n-1) print(x,y) print((n-1)^ k,0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; for _anon : Integer.subrange(0, ii()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := lii() ; if k = n - 1 then ( if n = 4 then ( execute (-1)->display() ) else ( execute (n - 1)->display() ; execute (1)->display() ; var arr : Sequence := Integer.subrange(2, n - 2-1)->select(i | i /= 3)->collect(i | (i)) ; for j : Integer.subrange(0, (arr)->size() div 2-1) do ( execute (arr[j+1])->display()) ; execute (0)->display() ) ) else ( if k = 0 then ( for i : Integer.subrange(0, n div 2-1) do ( execute (i)->display()) ) else ( execute (k)->display() ; var h : Map := Map{ k |-> 0 } ; arr := Integer.subrange(1, n - 1-1)->select(i | i /= k & i /= MathLib.bitwiseXor((n - 1), k))->collect(i | (i)) ; var flag : boolean := false ; for i : Integer.subrange(0, (arr)->size() div 2-1) do ( var y : OclAny := null; Sequence{x,y} := Sequence{arr[i+1],MathLib.bitwiseXor(arr[i+1], (n - 1))} ; execute (x)->display()) ; execute (MathLib.bitwiseXor((n - 1), k))->display() ) )); operation ii() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation lii() : OclAny pre: true post: true activity: return ((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ss() : OclAny pre: true post: true activity: var x : String := stdin.readLine() ; if x->last() = "\n" then ( return x->front() ) else skip ; return x; operation lss() : OclAny pre: true post: true activity: return ((stdin.readLine().split())->collect( _x | (OclType["String"])->apply(_x) )); operation yes() pre: true post: true activity: stdout.write("YES\n"); operation no() pre: true post: true activity: stdout.write("NO\n"); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n,k=map(int,input().split()) if k==n-1 : if n==4 : print(-1) continue else : res=[(n-2,n-1),(1,3),(0,n-4)] for a in range(1,n//2): if a!=1 and a!=3 : b=n-1-a res.append((a,b)) else : res=[(n-1,k)] for a in range(1,n//2): b=n-1-a if a==k : res.append((0,b)) elif b==k : res.append((0,a)) else : res.append((a,b)) for a,b in res : print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if k = n - 1 then ( if n = 4 then ( execute (-1)->display() ; continue ) else ( var res : Sequence := Sequence{Sequence{n - 2, n - 1}}->union(Sequence{Sequence{1, 3}}->union(Sequence{ Sequence{0, n - 4} })) ; for a : Integer.subrange(1, n div 2-1) do ( if a /= 1 & a /= 3 then ( var b : double := n - 1 - a ; execute ((Sequence{a, b}) : res) ) else skip) ) ) else ( res := Sequence{ Sequence{n - 1, k} } ; for a : Integer.subrange(1, n div 2-1) do ( b := n - 1 - a ; if a = k then ( execute ((Sequence{0, b}) : res) ) else (if b = k then ( execute ((Sequence{0, a}) : res) ) else ( execute ((Sequence{a, b}) : res) ) ) ) ) ; for _tuple : res do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); execute (a)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) l=[i for i in range(n)] if(n==4 and k==3): print(-1) continue if(n-1==k): l[0],l[k-1]=l[k-1],l[0] l[k-2],l[k-1]=l[k-1],l[k-2] else : l[k],l[0]=l[0],l[k] for i in range(n//2): print(l[i],l[n-1-i]) num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)) ; if (n = 4 & k = 3) then ( execute (-1)->display() ; continue ) else skip ; if (n - 1 = k) then ( var l->first() : OclAny := null; var l[k - 1+1] : OclAny := null; Sequence{l->first(),l[k - 1+1]} := Sequence{l[k - 1+1],l->first()} ; var l[k - 2+1] : OclAny := null; var l[k - 1+1] : OclAny := null; Sequence{l[k - 2+1],l[k - 1+1]} := Sequence{l[k - 1+1],l[k - 2+1]} ) else ( var l[k+1] : OclAny := null; var l->first() : OclAny := null; Sequence{l[k+1],l->first()} := Sequence{l->first(),l[k+1]} ) ; for i : Integer.subrange(0, n div 2-1) do ( execute (l[i+1])->display())) ; var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math class Node : def __init__(self,data): self.data=data self.next=None def push(head,data): if not head : return Node(data) new_node=Node(data) new_node.next=head head=new_node return head def productOfNodes(head): ptr=head product=1 while(ptr): product*=ptr.data ptr=ptr.next return product if __name__=='__main__' : head=None head=push(head,7) head=push(head,6) head=push(head,8) head=push(head,4) head=push(head,1) print("Product={}".format(productOfNodes(head))) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.next := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( head := null ; head := push(head, 7) ; head := push(head, 6) ; head := push(head, 8) ; head := push(head, 4) ; head := push(head, 1) ; execute (StringLib.interpolateStrings("Product={}", Sequence{productOfNodes(head)}))->display() ) else skip; operation push(head : OclAny, data : OclAny) : OclAny pre: true post: true activity: if not(head) then ( return (Node.newNode()).initialise(data) ) else skip ; var new_node : Node := (Node.newNode()).initialise(data) ; new_node.next := head ; head := new_node ; return head; operation productOfNodes(head : OclAny) : OclAny pre: true post: true activity: var ptr : OclAny := head ; var product : int := 1 ; while (ptr) do ( product := product * ptr.data ; ptr := ptr.next) ; return product; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for tc in range(t): n=int(input()) s=input() cnt=n for r in range(1,n): if s[r]!=s[r-1]: cnt+=r print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for tc : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var cnt : int := n ; for r : Integer.subrange(1, n-1) do ( if s[r+1] /= s[r - 1+1] then ( cnt := cnt + r ) else skip) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) a=list(map(int,input().split())) h=[] for i in range(n): heapq.heappush(h,(a[i],i)) ok=[0]*n l,r=0,n-1 inf=pow(10,9)+1 ans=inf for _ in range(n-1): ai,i=heapq.heappop(h) d=max(abs(i-l),abs(i-r)) ans=min(ans,ai//d) ok[i]=1 while l=0 and ok[r]: r-=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var h : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( heapq.heappush(h, Sequence{a[i+1], i})) ; var ok : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,n - 1} ; var Math_PINFINITY : double := (10)->pow(9) + 1 ; var ans : double := Math_PINFINITY ; for _anon : Integer.subrange(0, n - 1-1) do ( var ai : OclAny := null; var i : OclAny := null; Sequence{ai,i} := heapq.heappop(h) ; var d : OclAny := Set{(i - l)->abs(), (i - r)->abs()}->max() ; ans := Set{ans, ai div d}->min() ; ok[i+1] := 1 ; while (l->compareTo(n)) < 0 & ok[l+1] do ( l := l + 1) ; while r >= 0 & ok[r+1] do ( r := r - 1)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin as sin def aint(): return int(input()) def amap(): return map(int,sin.readline().split()) def alist(): return list(map(int,sin.readline().split())) def astr(): return input() n=aint() l=alist() for i in range(n): l[i]=l[i]//max(i,n-i-1) print(min(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var n : OclAny := aint() ; var l : OclAny := alist() ; for i : Integer.subrange(0, n-1) do ( l[i+1] := l[i+1] div Set{i, n - i - 1}->max()) ; execute ((l)->min())->display(); operation aint() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation amap() : OclAny pre: true post: true activity: return (sin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation alist() : OclAny pre: true post: true activity: return ((sin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation astr() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) S=list(map(str,input().split())) print(" ".join(S).rstrip()) for i in range(1,len(S)): for j in range(i): if int(S[j])>=int(S[i]): S.insert(j,S[i]) del S[i+1] else : pass print(" ".join(S).rstrip()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : Sequence := ((input().split())->collect( _x | (OclType["String"])->apply(_x) )) ; execute (" ".join(S).rstrip())->display() ; for i : Integer.subrange(1, (S)->size()-1) do ( for j : Integer.subrange(0, i-1) do ( if (("" + ((S[j+1])))->toInteger()->compareTo(("" + ((S[i+1])))->toInteger())) >= 0 then ( S := S.insertAt(j+1, S[i+1]) ; execute (S[i + 1+1])->isDeleted() ) else ( skip )) ; execute (" ".join(S).rstrip())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[0]+list(map(int,input().split())) ans=float('inf') for i in range(1,n+1): ans=min(ans,a[i]//max(i-1,n-i)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ans : double := ("" + (('inf')))->toReal() ; for i : Integer.subrange(1, n + 1-1) do ( ans := Set{ans, a[i+1] div Set{i - 1, n - i}->max()}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=list(map(int,input().split())) ans=9999999999 for i in range(n): l=max(i,n-i-1) ans=min(ans,x[i]//l) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 9999999999 ; for i : Integer.subrange(0, n-1) do ( var l : OclAny := Set{i, n - i - 1}->max() ; ans := Set{ans, x[i+1] div l}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() a=0 b=0 for i in range(len(s)): if s[i]=='S' : a+=1 elif a>0 : b+=2 a-=1 print(len(s)-b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var a : int := 0 ; var b : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = 'S' then ( a := a + 1 ) else (if a > 0 then ( b := b + 2 ; a := a - 1 ) else skip)) ; execute ((s)->size() - b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import copy from operator import mul from functools import reduce from collections import defaultdict from collections import Counter from collections import deque from itertools import product from itertools import permutations from itertools import combinations from itertools import accumulate from bisect import bisect_left,bisect_right import re def inside(y,x,H,W): return 0<=y0 : s_cnt-=1 else : t_cnt+=1 print(t_cnt+s_cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var dy : Sequence := Sequence{0}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{ 1 }))) ; var dx : Sequence := Sequence{1}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{ 0 }))) ; skip ; skip ; skip ; var INF : int := ("" + ((("1e18")->toReal())))->toInteger() ; var MOD : int := ("" + ((("1e9")->toReal())))->toInteger() + 7 ; var X : String := (OclFile["System.in"]).readLine() ; var t_cnt : OclAny := null; var s_cnt : OclAny := null; Sequence{t_cnt,s_cnt} := Sequence{0,0} ; for Xi : X->characters() do ( if Xi = "S" then ( s_cnt := s_cnt + 1 ) else (if Xi = "T" then ( if s_cnt > 0 then ( s_cnt := s_cnt - 1 ) else ( t_cnt := t_cnt + 1 ) ) else skip)) ; execute (t_cnt + s_cnt)->display(); operation inside(y : OclAny, x : OclAny, H : OclAny, W : OclAny) : OclAny pre: true post: true activity: return 0 <= y & (y < H) & 0 <= x & (x < W); operation i_inpl() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation l_inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation line_inpl(x : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, x-1)->select(_anon | true)->collect(_anon | (i_inpl())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**8) def ii(): return int(sys.stdin.readline()) def mi(): return map(int,sys.stdin.readline().split()) def li(): return list(map(int,sys.stdin.readline().split())) def li2(N): return[list(map(int,sys.stdin.readline().split()))for _ in range(N)] def dp2(ini,i,j): return[[ini]*i for _ in range(j)] def dp3(ini,i,j,k): return[[[ini]*i for _ in range(j)]for _ in range(k)] S=input() from collections import deque ans=deque() for m in S : if m=='S' : ans.append(m) elif m=='T' : if ans and ans[-1]=='S' : ans.pop() else : ans.append(m) print(len(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(8)) ; skip ; skip ; skip ; skip ; skip ; skip ; var S : String := (OclFile["System.in"]).readLine() ; skip ; var ans : Sequence := () ; for m : S->characters() do ( if m = 'S' then ( execute ((m) : ans) ) else (if m = 'T' then ( if ans & ans->last() = 'S' then ( ans := ans->front() ) else ( execute ((m) : ans) ) ) else skip)) ; execute ((ans)->size())->display(); operation ii() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation mi() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation li() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation li2(N : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )))); operation dp2(ini : OclAny, i : OclAny, j : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, j-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ ini }, i))); operation dp3(ini : OclAny, i : OclAny, j : OclAny, k : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, k-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, j-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ ini }, i))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import collections import bisect import itertools import fractions import copy import heapq import decimal import queue import numpy as np sys.setrecursionlimit(10000001) INF=10**16 MOD=10**9+7 ni=lambda : int(sys.stdin.readline()) ns=lambda : map(int,sys.stdin.readline().split()) na=lambda : list(map(int,sys.stdin.readline().split())) def main(): x=list(input()) s_cnt=0 ans=len(x) for xi in x : if xi=="S" : s_cnt+=1 else : if s_cnt!=0 : s_cnt-=1 ans-=2 print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(10000001) ; var INF : double := (10)->pow(16) ; var MOD : double := (10)->pow(9) + 7 ; var ni : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var ns : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var na : Function := lambda $$ : OclAny in (((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var x : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var s_cnt : int := 0 ; var ans : int := (x)->size() ; for xi : x do ( if xi = "S" then ( s_cnt := s_cnt + 1 ) else ( if s_cnt /= 0 then ( s_cnt := s_cnt - 1 ; ans := ans - 2 ) else skip )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() del_list=[] l=0 pointer=0 for i,v in enumerate(s): if v=="S" : del_list.append([i,-1]) l+=1 else : if l!=0 and pointer!=l : del_list[pointer][1]=i pointer+=1 rems=0 delpair=0 for i in del_list : if i[1]==-1 : rems+=1 else : delpair+=1 remt=s.count("T")-delpair print(remt+rems) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var del_list : Sequence := Sequence{} ; var l : int := 0 ; var pointer : int := 0 ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if v = "S" then ( execute ((Sequence{i}->union(Sequence{ -1 })) : del_list) ; l := l + 1 ) else ( if l /= 0 & pointer /= l then ( del_list[pointer+1][1+1] := i ; pointer := pointer + 1 ) else skip )) ; var rems : int := 0 ; var delpair : int := 0 ; for i : del_list do ( if i[1+1] = -1 then ( rems := rems + 1 ) else ( delpair := delpair + 1 )) ; var remt : double := s->count("T") - delpair ; execute (remt + rems)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- count=1 while True : x=int(raw_input()) if x==0 : break print("Case %d: %d" %(count,x)) count+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var count : int := 1 ; while true do ( var x : int := ("" + ((raw_input())))->toInteger() ; if x = 0 then ( break ) else skip ; execute (StringLib.format("Case %d: %d",Sequence{count, x}))->display() ; count := count + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for t in range(0,T): n=int(input()) s=input() answer=n for i in range(1,n): if s[i]!=s[i-1]: answer+=i print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(0, T-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var answer : int := n ; for i : Integer.subrange(1, n-1) do ( if s[i+1] /= s[i - 1+1] then ( answer := answer + i ) else skip) ; execute (answer)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys for i,t in enumerate((int(x)for x in sys.stdin),start=1): if t==0 : break print('Case{}:{}'.format(i,t)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _tuple : Integer.subrange(1, (Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin)))))))}, (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->size())->collect( _indx | Sequence{_indx-1, (Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin)))))))}, (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); if t = 0 then ( break ) else skip ; execute (StringLib.interpolateStrings('Case{}:{}', Sequence{i, t}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math l=[int(input())for _ in range(5)] m=[math.ceil(l[i]/10)*10 for i in range(5)] s=sum(m) ans=[s-m[i]+l[i]for i in range(5)] print(min(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var l : Sequence := Integer.subrange(0, 5-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var m : Sequence := Integer.subrange(0, 5-1)->select(i | true)->collect(i | ((l[i+1] / 10)->ceil() * 10)) ; var s : OclAny := (m)->sum() ; var ans : Sequence := Integer.subrange(0, 5-1)->select(i | true)->collect(i | (s - m[i+1] + l[i+1])) ; execute ((ans)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(1) b=int(1) while True : b=int(raw_input()) if b!=0 : print('Case '+str(a)+': '+str(b)) a+=1 continue else : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + ((1)))->toInteger() ; var b : int := ("" + ((1)))->toInteger() ; while true do ( b := ("" + ((raw_input())))->toInteger() ; if b /= 0 then ( execute ('Case ' + ("" + ((a))) + ': ' + ("" + ((b))))->display() ; a := a + 1 ; continue ) else ( break )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=[] while True : n=input() if n=="0" : break l.append(n) for i in range(len(l)): print("Case{}:{}".format(i+1,l[i])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := Sequence{} ; while true do ( var n : String := (OclFile["System.in"]).readLine() ; if n = "0" then ( break ) else skip ; execute ((n) : l)) ; for i : Integer.subrange(0, (l)->size()-1) do ( execute (StringLib.interpolateStrings("Case{}:{}", Sequence{i + 1, l[i+1]}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s="" i=1 while True : s=raw_input() if s=="0" : break print("Case %d: " % i)+s i+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := "" ; var i : int := 1 ; while true do ( s := raw_input() ; if s = "0" then ( break ) else skip ; (expr (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom "Case %d: ")) % (expr (atom (name i))))))))) )))) + (expr (atom (name s)))) ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math t=int(input()) for i in range(t): s=input() while s[0]in s[1 :]: i=0 while s[i]in s[i+1 :]: i+=1 s=s[i :] print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var s : String := (OclFile["System.in"]).readLine() ; while (s->tail())->includes(s->first()) do ( var i : int := 0 ; while (s.subrange(i + 1+1))->includes(s[i+1]) do ( i := i + 1) ; s := s.subrange(i+1)) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=eval(input()) for _ in range(t): s=input() s1=s[: :-1] k=[] d=[] for i in range(len(s)): if s1[i]not in k : k.append(s1[i]) d.append(1) else : d.append(0) d=d[: :-1] for i in range(len(d)): if d[i]==1 : print(s[i :]) break else : print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := (OclFile["System.in"]).readLine() ; for _anon : Integer.subrange(0, t-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var s1 : OclAny := s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var k : Sequence := Sequence{} ; var d : Sequence := Sequence{} ; for i : Integer.subrange(0, (s)->size()-1) do ( if (k)->excludes(s1[i+1]) then ( execute ((s1[i+1]) : k) ; execute ((1) : d) ) else ( execute ((0) : d) )) ; d := d(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name d)))))))) ))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))) :)) ])))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: i=0 while s[i]in s[i+1 :]: i+=1 print(s[i :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var i : int := 0 ; while (s.subrange(i + 1+1))->includes(s[i+1]) do ( i := i + 1) ; execute (s.subrange(i+1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for t in range(T): s=input() abc="abcdefghijklmnopqrstuvwxyz" dic={'a' : 0} for i in abc : dic[i]=0 for i in s : dic[i]+=1 i=0 while(i1): dic[s[i]]-=1 i+=1 else : break print(s[i :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(0, T-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var abc : String := "abcdefghijklmnopqrstuvwxyz" ; var dic : Map := Map{ 'a' |-> 0 } ; for i : abc->characters() do ( dic[i+1] := 0) ; for i : s->characters() do ( dic[i+1] := dic[i+1] + 1) ; var i : int := 0 ; while ((i->compareTo((s)->size())) < 0) do ( if (dic[s[i+1]+1] > 1) then ( dic[s[i+1]+1] := dic[s[i+1]+1] - 1 ; i := i + 1 ) else ( break )) ; execute (s.subrange(i+1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter for jj in range(int(input())): n=input() c=Counter(n) for i in range(len(n)): if c[n[i]]==1 : print(n[i :]) break else : c[n[i]]-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for jj : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : String := (OclFile["System.in"]).readLine() ; var c : OclAny := Counter(n) ; for i : Integer.subrange(0, (n)->size()-1) do ( if c[n[i+1]+1] = 1 then ( execute (n.subrange(i+1))->display() ; break ) else ( c[n[i+1]+1] := c[n[i+1]+1] - 1 ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) lst_F=[list(map(int,input().split()))for _ in range(N)] lst_P=[list(map(int,input().split()))for _ in range(N)] n_timetable=10 lst_joisino=[None]*n_timetable def score(src,F,P): cnt=0 for i,j in zip(src,F): if i==j==1 : cnt+=1 return P[cnt] def dfs(pos): if pos==n_timetable : ret=0 for i in range(N): if lst_joisino==[0]*n_timetable : return-float("INF") p=score(lst_joisino,lst_F[i],lst_P[i]) ret+=p return ret lst_joisino[pos]=0 ret0=dfs(pos+1) lst_joisino[pos]=1 ret1=dfs(pos+1) return max(ret0,ret1) print(dfs(0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst_F : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var lst_P : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var n_timetable : int := 10 ; var lst_joisino : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n_timetable) ; skip ; skip ; execute (dfs(0))->display(); operation score(src : OclAny, F : OclAny, P : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; for _tuple : Integer.subrange(1, src->size())->collect( _indx | Sequence{src->at(_indx), F->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if i = j & (j == 1) then ( cnt := cnt + 1 ) else skip) ; return P[cnt+1]; operation dfs(pos : OclAny) : OclAny pre: true post: true activity: if pos = n_timetable then ( var ret : int := 0 ; for i : Integer.subrange(0, N-1) do ( if lst_joisino = MatrixLib.elementwiseMult(Sequence{ 0 }, n_timetable) then ( return -("" + (("INF")))->toReal() ) else skip ; var p : OclAny := score(lst_joisino, lst_F[i+1], lst_P[i+1]) ; ret := ret + p) ; return ret ) else skip ; lst_joisino[pos+1] := 0 ; var ret0 : OclAny := dfs(pos + 1) ; lst_joisino[pos+1] := 1 ; var ret1 : OclAny := dfs(pos + 1) ; return Set{ret0, ret1}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def substringConversions(s,k,b): l=len(s); for i in range(l): if((i+k); operation substringConversions(s : OclAny, k : OclAny, b : OclAny) pre: true post: true activity: var l : int := (s)->size(); ; for i : Integer.subrange(0, l-1) do ( if (((i + k)->compareTo(l + 1)) < 0) then ( var sub : OclAny := s.subrange(i+1, i + k); ; var sum : OclAny := null; var counter : OclAny := null; Sequence{sum,counter} := Sequence{0,0}; ; for i : Integer.subrange(-1 + 1, (sub)->size() - 1)->reverse() do ( var sum : OclAny := sum + (((sub[i+1])->char2byte() - ('0')->char2byte()) * (b)->pow(counter)); ; counter := counter + 1;) ; execute (sum)->display(); ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numbersWith3Divisors(n): prime=[True]*(n+1); prime[0]=prime[1]=False ; p=2 ; while(p*p<=n): if(prime[p]==True): for i in range(p*2,n+1,p): prime[i]=False ; p+=1 ; print("Numbers with 3 divisors :"); i=0 ; while(i*i<=n): if(prime[i]): print(i*i,end=" "); i+=1 ; n=96 ; numbersWith3Divisors(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 96; ; numbersWith3Divisors(n);; operation numbersWith3Divisors(n : OclAny) pre: true post: true activity: var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (n + 1)); ; prime->first() := false; var prime[1+1] : boolean := false; ; var p : int := 2; ; while ((p * p->compareTo(n)) <= 0) do ( if (prime[p+1] = true) then ( for i : Integer.subrange(p * 2, n + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false;) ) else skip ; p := p + 1;) ; execute ("Numbers with 3 divisors :")->display(); ; var i : int := 0; ; while ((i * i->compareTo(n)) <= 0) do ( if (prime[i+1]) then ( execute (i * i)->display(); ) else skip ; i := i + 1;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- M=[list(input())for _ in range(2)] for i in range(2): for j in range(3): if M[i][j]!=M[1-i][2-j]: print('NO') exit() else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var M : Sequence := Integer.subrange(0, 2-1)->select(_anon | true)->collect(_anon | (((OclFile["System.in"]).readLine())->characters())) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 3))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name M)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) != (comparison (expr (atom (name M)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) - (expr (atom (name i))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) - (expr (atom (name j))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name exit)) (trailer (arguments ( ))))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools def func(n,j): if(n % 10==0 or j==4): return n return n//10*10+10 def myAnswer(A : int,B : int,C : int,D : int,E : int)->int : dishes=[A,B,C,D,E] ans=10**9 for i in itertools.permutations(dishes): total=0 for j,a in enumerate(i): total+=func(a,j) ans=min(total,ans) return ans def modelAnswer(): tmp=1 def main(): A=int(input()) B=int(input()) C=int(input()) D=int(input()) E=int(input()) print(myAnswer(A,B,C,D,E)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation func(n : OclAny, j : OclAny) : OclAny pre: true post: true activity: if (n mod 10 = 0 or j = 4) then ( return n ) else skip ; return n div 10 * 10 + 10; operation myAnswer(A : int, B : int, C : int, D : int, E : int) : int pre: true post: true activity: var dishes : Sequence := Sequence{A}->union(Sequence{B}->union(Sequence{C}->union(Sequence{D}->union(Sequence{ E })))) ; var ans : double := (10)->pow(9) ; for i : itertools.permutations(dishes) do ( var total : int := 0 ; for _tuple : Integer.subrange(1, (i)->size())->collect( _indx | Sequence{_indx-1, (i)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); total := total + func(a, j)) ; ans := Set{total, ans}->min()) ; return ans; operation modelAnswer() pre: true post: true activity: var tmp : int := 1; operation main() pre: true post: true activity: var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var C : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var D : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var E : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (myAnswer(A, B, C, D, E))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a,b=map(int,input().split()) print(b**3*math.pi*(4/3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((b)->pow(3) * * (4 / 3))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline N=int(input()) def inputs(): return[int(x)for x in input().split()] f=[inputs()for _ in range(N)] p=[inputs()for _ in range(N)] cnt=[0]*(N) ans=-10**9 for bit in range(1,1<<10): ans1=0 cnt=[0]*(N) for j in range(10): for i in range(N): if bit & 1<toInteger() ; skip ; var f : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (inputs())) ; var p : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (inputs())) ; var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N)) ; var ans : double := (-10)->pow(9) ; for bit : Integer.subrange(1, 1 * (2->pow(10))-1) do ( var ans1 : int := 0 ; cnt := MatrixLib.elementwiseMult(Sequence{ 0 }, (N)) ; for j : Integer.subrange(0, 10-1) do ( for i : Integer.subrange(0, N-1) do ( if MathLib.bitwiseAnd(bit, 1 * (2->pow(j))) & f[i+1][j+1] = 1 then ( cnt[i+1] := cnt[i+1] + 1 ) else skip)) ; ans1 := ans1 + (Integer.subrange(0, N-1)->select(i | true)->collect(i | (p[i+1][cnt[i+1]+1])))->sum() ; ans := Set{ans1, ans}->max()) ; execute (ans)->display(); operation inputs() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import product def main(): n=int(input()) f=[] p=[] for ob in(f,p): for i in range(n): ro=list(map(int,input().split())) ob.append(ro) res=-99999999999 for open_at in product((0,1),repeat=10): if 1 not in open_at : continue res=max(res,get_rieki(f,p,open_at,n)) print(res) def get_rieki(f,p,open_at,n): res=0 for i in range(n): cnt=0 for t in range(10): if f[i][t]==1 and open_at[t]==1 : cnt+=1 res+=p[i][cnt] return res main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; main(); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var f : Sequence := Sequence{} ; var p : Sequence := Sequence{} ; for ob : Sequence{f, p} do ( for i : Integer.subrange(0, n-1) do ( var ro : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((ro) : ob))) ; var res : int := -99999999999 ; for open_at : product(Sequence{0, 1}, (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (number (integer 10))))))))) do ( if (open_at)->excludes(1) then ( continue ) else skip ; res := Set{res, get_rieki(f, p, open_at, n)}->max()) ; execute (res)->display(); operation get_rieki(f : OclAny, p : OclAny, open_at : OclAny, n : OclAny) : OclAny pre: true post: true activity: res := 0 ; for i : Integer.subrange(0, n-1) do ( var cnt : int := 0 ; for t : Integer.subrange(0, 10-1) do ( if f[i+1][t+1] = 1 & open_at[t+1] = 1 then ( cnt := cnt + 1 ) else skip) ; res := res + p[i+1][cnt+1]) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def read_input(): n=int(input()) flist=[] for i in range(n): flist.append(list(map(int,input().split()))) plist=[] for j in range(n): plist.append(list(map(int,input().split()))) return n,flist,plist def check_open(a,b): c=0 for i,j in zip(a,b): if i==j==1 : c+=1 return c def get_pattern(p): binary_p=bin(p)[2 :] list_p=[int(c)for c in binary_p] list_p=[0]*(10-len(list_p))+list_p return list_p def submit(): n,flist,plist=read_input() max_pattern=2048 max_profit=-float('inf') for p in range(1,2048): myshop=get_pattern(p) profit=0 for i in range(n): target_shop=flist[i] c=check_open(myshop,target_shop) profit+=plist[i][c] if max_profittoInteger() ; var flist : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : flist)) ; var plist : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : plist)) ; return n, flist, plist; operation check_open(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var c : int := 0 ; for _tuple : Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), b->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if i = j & (j == 1) then ( c := c + 1 ) else skip) ; return c; operation get_pattern(p : OclAny) : OclAny pre: true post: true activity: var binary_p : OclAny := bin(p).subrange(2+1) ; var list_p : Sequence := binary_p->select(c | true)->collect(c | (("" + ((c)))->toInteger())) ; list_p := MatrixLib.elementwiseMult(Sequence{ 0 }, (10 - (list_p)->size()))->union(list_p) ; return list_p; operation submit() pre: true post: true activity: Sequence{n,flist,plist} := read_input() ; var max_pattern : int := 2048 ; var max_profit : double := -("" + (('inf')))->toReal() ; for p : Integer.subrange(1, 2048-1) do ( var myshop : OclAny := get_pattern(p) ; var profit : int := 0 ; for i : Integer.subrange(0, n-1) do ( var target_shop : OclAny := flist[i+1] ; c := check_open(myshop, target_shop) ; profit := profit + plist[i+1][c+1]) ; if (max_profit->compareTo(profit)) < 0 then ( max_profit := profit ) else skip) ; execute (max_profit)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def profit(xs,n,F,P): return sum([P[i][sum(map(lambda x : x[0]*x[1],zip(xs,F[i])))]for i in range(n)]) def vector(k): return[1 if k & 1<toInteger() ; F := Set{} ; P := Set{} ; for i : Integer.subrange(0, n-1) do ( F[i+1] := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; for i : Integer.subrange(0, n-1) do ( P[i+1] := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; execute (foo(n, F, P))->display() ) else skip; operation profit(xs : OclAny, n : OclAny, F : OclAny, P : OclAny) : OclAny pre: true post: true activity: return (Integer.subrange(0, n-1)->select(i | true)->collect(i | (P[i+1][((Integer.subrange(1, xs->size())->collect( _indx | Sequence{xs->at(_indx), F[i+1]->at(_indx)} ))->collect( _x | (lambda x : OclAny in (x->first() * x[1+1]))->apply(_x) ))->sum()+1])))->sum(); operation vector(k : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, 10-1)->select(i | true)->collect(i | (if MathLib.bitwiseAnd(k, 1 * (2->pow(i))) then 1 else 0 endif)); operation foo(n : OclAny, F : OclAny, P : OclAny) : OclAny pre: true post: true activity: return (Integer.subrange(1, 1024-1)->select(pat | true)->collect(pat | (profit(vector(pat), n, F, P))))->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import log2 def findX(arr,n): itr=arr[0] for i in range(len(arr)): if(arr[i]>itr): itr=arr[i] p=int(log2(itr))+1 X=0 for i in range(p): count=0 for j in range(n): if(arr[j]&(1<int(n/2)): X+=1<toInteger() + 1 ; var X : int := 0 ; for i : Integer.subrange(0, p-1) do ( var count : int := 0 ; for j : Integer.subrange(0, n-1) do ( if (MathLib.bitwiseAnd(arr[j+1], (1 * (2->pow(i))))) then ( count := count + 1 ) else skip) ; if ((count->compareTo(("" + ((n / 2)))->toInteger())) > 0) then ( X := X + 1 * (2->pow(i)) ) else skip) ; var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + (MathLib.bitwiseXor(X, arr[i+1]))) ; execute ("X=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sum_series(n): nSquare=n*n return int(nSquare*(nSquare-1)/4) n=2 print(sum_series(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 2 ; execute (sum_series(n))->display(); operation sum_series(n : OclAny) : OclAny pre: true post: true activity: var nSquare : double := n * n ; return ("" + ((nSquare * (nSquare - 1) / 4)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxlenAP(a,n,d): m=dict() maxt=1 for i in range(n): if(a[i]-i*d)in m : m[a[i]-i*d]+=1 else : m[a[i]-i*d]=1 for it in m : if m[it]>maxt : maxt=m[it] return maxt if __name__=="__main__" : n,d=10,3 a=[1,4,2,5,20,11,56,100,20,23] print(maxlenAP(a,n,d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{n,d} := Sequence{10,3} ; a := Sequence{1}->union(Sequence{4}->union(Sequence{2}->union(Sequence{5}->union(Sequence{20}->union(Sequence{11}->union(Sequence{56}->union(Sequence{100}->union(Sequence{20}->union(Sequence{ 23 }))))))))) ; execute (maxlenAP(a, n, d))->display() ) else skip; operation maxlenAP(a : OclAny, n : OclAny, d : OclAny) : OclAny pre: true post: true activity: var m : Map := (arguments ( )) ; var maxt : int := 1 ; for i : Integer.subrange(0, n-1) do ( if (m)->includes((a[i+1] - i * d)) then ( m[a[i+1] - i * d+1] := m[a[i+1] - i * d+1] + 1 ) else ( m[a[i+1] - i * d+1] := 1 )) ; for it : m->keys() do ( if (m[it+1]->compareTo(maxt)) > 0 then ( maxt := m[it+1] ) else skip) ; return maxt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def type1(arr,start,limit): for i in range(start,limit+1): arr[i]+=1 def type2(arr,query,start,limit): for i in range(start,limit+1): if(query[i][0]==1): type1(arr,query[i][1],query[i][2]) elif(query[i][0]==2): type2(arr,query,query[i][1],query[i][2]) n=5 m=5 arr=[0 for i in range(n+1)] temp=[1,1,2,1,4,5,2,1,2,2,1,3,2,3,4] query=[[0 for i in range(3)]for j in range(6)] j=0 for i in range(1,m+1): query[i][0]=temp[j] j+=1 query[i][1]=temp[j] j+=1 query[i][2]=temp[j] j+=1 for i in range(1,m+1): if(query[i][0]==1): type1(arr,query[i][1],query[i][2]) elif(query[i][0]==2): type2(arr,query,query[i][1],query[i][2]) for i in range(1,n+1): print(arr[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := 5 ; var m : int := 5 ; arr := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; var temp : Sequence := Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{4}->union(Sequence{5}->union(Sequence{2}->union(Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{1}->union(Sequence{3}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })))))))))))))) ; query := Integer.subrange(0, 6-1)->select(j | true)->collect(j | (Integer.subrange(0, 3-1)->select(i | true)->collect(i | (0)))) ; var j : int := 0 ; for i : Integer.subrange(1, m + 1-1) do ( query[i+1]->first() := temp[j+1] ; j := j + 1 ; query[i+1][1+1] := temp[j+1] ; j := j + 1 ; query[i+1][2+1] := temp[j+1] ; j := j + 1) ; for i : Integer.subrange(1, m + 1-1) do ( if (query[i+1]->first() = 1) then ( type1(arr, query[i+1][1+1], query[i+1][2+1]) ) else (if (query[i+1]->first() = 2) then ( type2(arr, query, query[i+1][1+1], query[i+1][2+1]) ) else skip)) ; for i : Integer.subrange(1, n + 1-1) do ( execute (arr[i+1])->display()); operation type1(arr : OclAny, start : OclAny, limit : OclAny) pre: true post: true activity: for i : Integer.subrange(start, limit + 1-1) do ( arr[i+1] := arr[i+1] + 1); operation type2(arr : OclAny, query : OclAny, start : OclAny, limit : OclAny) pre: true post: true activity: for i : Integer.subrange(start, limit + 1-1) do ( if (query[i+1]->first() = 1) then ( type1(arr, query[i+1][1+1], query[i+1][2+1]) ) else (if (query[i+1]->first() = 2) then ( type2(arr, query, query[i+1][1+1], query[i+1][2+1]) ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import random import math from collections import defaultdict import itertools from sys import stdin,stdout import sys import operator from decimal import Decimal p2D=lambda x : print(*x,sep="\n") def II(): return int(sys.stdin.buffer.readline()) def MI(): return map(int,sys.stdin.buffer.readline().split()) def LI(): return list(map(int,sys.stdin.buffer.readline().split())) def LLI(rows_number): return[LI()for _ in range(rows_number)] def BI(): return sys.stdin.buffer.readline().rstrip() def SI(): return sys.stdin.buffer.readline().rstrip().decode() def li(): return[int(i)for i in input().split()] def lli(rows): return[li()for _ in range(rows)] def si(): return input() def ii(): return int(input()) def ins(): return input().split() def main(): n=ii() a=li() sa=[0] ans=0 for i in range(1,n+1): sa.append(sa[-1]+a[i-1]) for j in range(i): if sa[-1]-sa[j]>100*(i-j): ans=max(ans,(i-j)) break print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var p2D : Function := lambda x : OclAny in (((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation II() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.buffer.readLine())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LLI(rows_number : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows_number-1)->select(_anon | true)->collect(_anon | (LI())); operation BI() : OclAny pre: true post: true activity: return sys.stdin.buffer.readLine().rstrip(); operation SI() : OclAny pre: true post: true activity: return sys.stdin.buffer.readLine().rstrip().decode(); operation li() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation lli(rows : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows-1)->select(_anon | true)->collect(_anon | (li())); operation si() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation ii() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation ins() : OclAny pre: true post: true activity: return input().split(); operation main() pre: true post: true activity: var n : OclAny := ii() ; var a : OclAny := li() ; var sa : Sequence := Sequence{ 0 } ; var ans : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( execute ((sa->last() + a[i - 1+1]) : sa) ; for j : Integer.subrange(0, i-1) do ( if (sa->last() - sa[j+1]->compareTo(100 * (i - j))) > 0 then ( ans := Set{ans, (i - j)}->max() ; break ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=[],[] t=10 for i in range(5): x.append(int(input())) y.append(x[i]% 10) if 0toInteger()) : x) ; execute ((x[i+1] mod 10) : y) ; if 0 < y[i+1] & (y[i+1] < t) then ( t := y[i+1] ) else skip ; if x[i+1] mod 10 /= 0 then ( x[i+1] := ((x[i+1] div 10) + 1) * 10 ) else skip ; y[i+1] := x[i+1]) ; execute ((y)->sum() + t - 10)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) list1=list(map(int,input().split())) mx=0 for i in range(n): t=1 total=list1[i] if total>100 : mx=max(1,mx) for j in range(i+1,n): t+=1 total+=list1[j] if total>t*100 : mx=max(t,mx) print(mx) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var list1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mx : int := 0 ; for i : Integer.subrange(0, n-1) do ( var t : int := 1 ; var total : OclAny := list1[i+1] ; if total > 100 then ( mx := Set{1, mx}->max() ) else skip ; for j : Integer.subrange(i + 1, n-1) do ( t := t + 1 ; total := total + list1[j+1] ; if (total->compareTo(t * 100)) > 0 then ( mx := Set{t, mx}->max() ) else skip)) ; execute (mx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a,b=map(int,input().split()) if a>b : print(2/3*math.pi*a**2*b) else : print(4/3*math.pi*b**3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(b)) > 0 then ( execute (2 / 3 * * (a)->pow(2) * b)->display() ) else ( execute (4 / 3 * * (b)->pow(3))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) req=list(map(int,input().split())) pref=[req[0]] for i in range(1,n): pref.append(pref[-1]+req[i]) ans=0 for i in range(n): for j in range(i,n): if i==0 : requests=pref[j] else : requests=pref[j]-pref[i-1] if requests>100*(j-i+1): ans=max(ans,j-i+1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var req : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var pref : Sequence := Sequence{ req->first() } ; for i : Integer.subrange(1, n-1) do ( execute ((pref->last() + req[i+1]) : pref)) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i, n-1) do ( if i = 0 then ( var requests : OclAny := pref[j+1] ) else ( requests := pref[j+1] - pref[i - 1+1] ) ; if (requests->compareTo(100 * (j - i + 1))) > 0 then ( ans := Set{ans, j - i + 1}->max() ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import random import math from collections import defaultdict import itertools from sys import stdin,stdout import sys import operator from decimal import Decimal p2D=lambda x : print(*x,sep="\n") def II(): return int(sys.stdin.buffer.readline()) def MI(): return map(int,sys.stdin.buffer.readline().split()) def LI(): return list(map(int,sys.stdin.buffer.readline().split())) def LLI(rows_number): return[LI()for _ in range(rows_number)] def BI(): return sys.stdin.buffer.readline().rstrip() def SI(): return sys.stdin.buffer.readline().rstrip().decode() def li(): return[int(i)for i in input().split()] def lli(rows): return[li()for _ in range(rows)] def si(): return input() def ii(): return int(input()) def ins(): return input().split() def main(): n=ii() a=li() sa=[0] ans=0 for i in range(1,n+1): sa.append(sa[-1]+a[i-1]) for j in range(i): if sa[-1]-sa[j]>100*(i-j): ans=max(ans,(i-j)) print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var p2D : Function := lambda x : OclAny in (((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation II() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.buffer.readLine())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LLI(rows_number : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows_number-1)->select(_anon | true)->collect(_anon | (LI())); operation BI() : OclAny pre: true post: true activity: return sys.stdin.buffer.readLine().rstrip(); operation SI() : OclAny pre: true post: true activity: return sys.stdin.buffer.readLine().rstrip().decode(); operation li() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation lli(rows : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows-1)->select(_anon | true)->collect(_anon | (li())); operation si() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation ii() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation ins() : OclAny pre: true post: true activity: return input().split(); operation main() pre: true post: true activity: var n : OclAny := ii() ; var a : OclAny := li() ; var sa : Sequence := Sequence{ 0 } ; var ans : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( execute ((sa->last() + a[i - 1+1]) : sa) ; for j : Integer.subrange(0, i-1) do ( if (sa->last() - sa[j+1]->compareTo(100 * (i - j))) > 0 then ( ans := Set{ans, (i - j)}->max() ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- bitcount=[bin(i).count('1')for i in range(0x10000)] def solve(a,b): global bitcount b=[65535 ^ bi for bi in b] pdp={a[0]: 0} ndp={} for ai in a[1 :]+[0]: for k,v in pdp.items(): v+=bitcount[k] for bi in b : bi &=k vb=v-bitcount[bi] bi |=ai try : if ndp[bi]select(i | true)->collect(i | (bin(i)->count('1'))) ; skip ; skip ; var f : OclFile := OclFile["System.in"] ; while true do ( var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := (f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = c & (c == 0) then ( break ) else skip ; a := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + ((StringLib.sumStringsWithSeparator((f.readLine().split()), ''), 2)))->toInteger())) ; b := Integer.subrange(0, c-1)->select(i | true)->collect(i | (("" + ((StringLib.sumStringsWithSeparator((f.readLine().split()), ''), 2)))->toInteger())) ; execute (solve(a, b))->display()); operation solve(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: skip ; b := b->select(bi | true)->collect(bi | (MathLib.bitwiseXor(65535, bi))) ; var pdp : Map := Map{ a->first() |-> 0 } ; var ndp : OclAny := Set{} ; for ai : a->tail()->union(Sequence{ 0 }) do ( for _tuple : pdp->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); v := v + bitcount[k+1] ; for bi : b do ( bi := bi & k ; var vb : double := v - bitcount[bi+1] ; bi := bi or ai ; try ( if (ndp[bi+1]->compareTo(vb)) < 0 then ( ndp[bi+1] := vb ) else skip) (except_clause except (test (logical_test (comparison (expr (atom (name KeyError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ndp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name bi)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name vb)))))))))))))))) ; Sequence{pdp,ndp} := Sequence{ndp,Set{}}) ; return (pdp.values())->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- bc=[bin(i).count('1')for i in range(65536)] def solve(): from sys import stdin f_i=stdin while True : n,c=map(int,f_i.readline().split()) if n==0 : break A=[int(f_i.readline().replace('',''),2)for i in range(n)] B=[int(f_i.readline().replace('',''),2)for i in range(c)] dp1={A[0]: 0} dp2={} for a in A[1 :]+[0]: for st1,sc1 in dp1.items(): for b in B : cb=st1 & b sc2=sc1+bc[cb] st2=(st1-cb)| a try : if dp2[st2]select(i | true)->collect(i | (bin(i)->count('1'))) ; skip ; solve(); operation solve() pre: true post: true activity: skip ; var f_i : OclAny := stdin ; while true do ( var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := (f_i.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var A : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + ((f_i.readLine().replace('', ''), 2)))->toInteger())) ; var B : Sequence := Integer.subrange(0, c-1)->select(i | true)->collect(i | (("" + ((f_i.readLine().replace('', ''), 2)))->toInteger())) ; var dp1 : Map := Map{ A->first() |-> 0 } ; var dp2 : OclAny := Set{} ; for a : A->tail()->union(Sequence{ 0 }) do ( for _tuple : dp1->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var st1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var sc1 : OclAny := _tuple->at(_indx); for b : B do ( var cb : int := MathLib.bitwiseAnd(st1, b) ; var sc2 : OclAny := sc1 + bc[cb+1] ; var st2 : int := MathLib.bitwiseOr((st1 - cb), a) ; try ( if (dp2[st2+1]->compareTo(sc2)) < 0 then ( dp2[st2+1] := sc2 ) else skip) (except_clause except (test (logical_test (comparison (expr (atom (name KeyError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dp2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name st2)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sc2)))))))))))))))) ; Sequence{dp1,dp2} := Sequence{dp2,Set{}}) ; execute ((dp1.values())->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): while True : n,c=map(int,input().split()) if n==0 : break music=[] for _ in range(n): line=list(map(int,input().split())) add_panel=sum([2**i*line[i]for i in range(16)]) music.append(add_panel) hand=[] for _ in range(c): line=list(map(int,input().split())) erase_panel=sum([2**i*line[i]for i in range(16)]) hand.append(erase_panel) masks=tuple([2**i for i in range(16)]) move=[{}for _ in range(2**16)] dp=[{}for _ in range(n+1)] dp[0][0]=0 for turn in range(n): add_panel=music[turn] dp_next_turn=dp[turn+1] used={} for state,score in sorted(dp[turn].items(),key=lambda x :-x[1]): new_state=add_panel | state if new_state in used : continue used[new_state]=True move_new_state=move[new_state] for erase_panel in hand : if erase_panel in move_new_state : erased_state,add_score=move_new_state[erase_panel] else : add_score=0 temp=erase_panel & new_state for mask in masks : if mask>temp : break if temp & mask : add_score+=1 erased_state=new_state & ~ erase_panel move_new_state[erase_panel]=(erased_state,add_score) new_score=score+add_score if erased_state not in dp_next_turn or dp_next_turn[erased_state]collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var music : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var line : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var add_panel : OclAny := (Integer.subrange(0, 16-1)->select(i | true)->collect(i | ((2)->pow(i) * line[i+1])))->sum() ; execute ((add_panel) : music)) ; var hand : Sequence := Sequence{} ; for _anon : Integer.subrange(0, c-1) do ( line := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var erase_panel : OclAny := (Integer.subrange(0, 16-1)->select(i | true)->collect(i | ((2)->pow(i) * line[i+1])))->sum() ; execute ((erase_panel) : hand)) ; var masks : Sequence := (Integer.subrange(0, 16-1)->select(i | true)->collect(i | ((2)->pow(i)))) ; var move : Sequence := Integer.subrange(0, (2)->pow(16)-1)->select(_anon | true)->collect(_anon | (Set{})) ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Set{})) ; dp->first()->first() := 0 ; for turn : Integer.subrange(0, n-1) do ( add_panel := music[turn+1] ; var dp_next_turn : OclAny := dp[turn + 1+1] ; var used : OclAny := Set{} ; for _tuple : dp[turn+1]->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sortedBy($x | (lambda x : OclAny in (-x[1+1]))->apply($x)) do (var _indx : int := 1; var state : OclAny := _tuple->at(_indx); _indx := _indx + 1; var score : OclAny := _tuple->at(_indx); var new_state : int := MathLib.bitwiseOr(add_panel, state) ; if (used)->includes(new_state) then ( continue ) else skip ; used[new_state+1] := true ; var move_new_state : OclAny := move[new_state+1] ; for erase_panel : hand do ( if (move_new_state)->includes(erase_panel) then ( var erased_state : OclAny := null; var add_score : OclAny := null; Sequence{erased_state,add_score} := move_new_state[erase_panel+1] ) else ( var add_score : int := 0 ; var temp : int := MathLib.bitwiseAnd(erase_panel, new_state) ; for mask : masks do ( if (mask->compareTo(temp)) > 0 then ( break ) else skip ; if MathLib.bitwiseAnd(temp, mask) then ( add_score := add_score + 1 ) else skip) ; var erased_state : int := MathLib.bitwiseAnd(new_state, MathLib.bitwiseNot(erase_panel)) ; move_new_state[erase_panel+1] := Sequence{erased_state, add_score} ) ; var new_score : OclAny := score + add_score ; if (dp_next_turn)->excludes(erased_state) or (dp_next_turn[erased_state+1]->compareTo(new_score)) < 0 then ( dp_next_turn[erased_state+1] := new_score ) else skip))) ; execute ((dp[n+1].values())->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000001 ; factor=[0]*(MAX+1); def generatePrimeFactors(): factor[1]=1 ; for i in range(2,MAX): factor[i]=i ; for i in range(4,MAX,2): factor[i]=2 ; i=3 ; while(i*i1): if(factor[j]==dup): c+=1 ; else : dup=factor[j]; ans=ans*(c+1); c=1 ; j=int(j/factor[j]); ans=ans*(c+1); return ans ; if __name__=="__main__" : generatePrimeFactors() a=[10,30,100,450,987] q=len(a) for i in range(0,q): print(calculateNoOFactors(a[i]),end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1000001; ; var factor : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX + 1)); ; skip ; skip ; if __name__ = "__main__" then ( generatePrimeFactors() ; var a : Sequence := Sequence{10}->union(Sequence{30}->union(Sequence{100}->union(Sequence{450}->union(Sequence{ 987 })))) ; var q : int := (a)->size() ; for i : Integer.subrange(0, q-1) do ( execute (calculateNoOFactors(a[i+1]))->display()) ) else skip; operation generatePrimeFactors() pre: true post: true activity: factor[1+1] := 1; ; for i : Integer.subrange(2, MAX-1) do ( factor[i+1] := i;) ; for i : Integer.subrange(4, MAX-1)->select( $x | ($x - 4) mod 2 = 0 ) do ( factor[i+1] := 2;) ; var i : int := 3; ; while ((i * i->compareTo(MAX)) < 0) do ( if (factor[i+1] = i) then ( var j : int := i * i; ; while ((j->compareTo(MAX)) < 0) do ( if (factor[j+1] = j) then ( factor[j+1] := i; ) else skip ; j := j + i;) ) else skip ; i := i + 1;); operation calculateNoOFactors(n : OclAny) pre: true post: true activity: if (n = 1) then ( return 1; ) else skip ; var ans : int := 1; ; var dup : OclAny := factor[n+1]; ; var c : int := 1; ; j := ("" + ((n / factor[n+1])))->toInteger(); ; while (j > 1) do ( if (factor[j+1] = dup) then ( c := c + 1; ) else ( dup := factor[j+1]; ; ans := ans * (c + 1); ; c := 1; ) ; j := ("" + ((j / factor[j+1])))->toInteger();) ; ans := ans * (c + 1); ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) if n % 2==0 : a=b=n//2 print(a,b) else : a=1 for i in range(3,int(n**(1/2))+1,2): if n % i==0 : a=(n//i) break print(a,n-a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( var a : OclAny := n div 2; var b : int := n div 2 ; execute (a)->display() ) else ( a := 1 ; for i : Integer.subrange(3, ("" + (((n)->pow((1 / 2)))))->toInteger() + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if n mod i = 0 then ( a := (n div i) ; break ) else skip) ; execute (a)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): x=int(input()) if x % 2==0 : print(int(x/2),int(x/2)) else : k=0 for j in range(2,32000): if x % j==0 : print(int(x/j),int(x-(x/j))) k+=1 break if k==0 : print(1,x-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if x mod 2 = 0 then ( execute (("" + ((x / 2)))->toInteger())->display() ) else ( var k : int := 0 ; for j : Integer.subrange(2, 32000-1) do ( if x mod j = 0 then ( execute (("" + ((x / j)))->toInteger())->display() ; k := k + 1 ; break ) else skip) ; if k = 0 then ( execute (1)->display() ) else skip )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) f=lambda k,s :(2*s-k+1)*k-s if kcollect( _x | (OclType["int"])->apply(_x) ) ; var f : Function := lambda k : OclAny, s : OclAny in (if (k->compareTo(s)) < 0 then (2 * s - k + 1) * k - s else (s - 2) * s + 2 * k endif) ; var s : OclAny := null; var m : OclAny := null; Sequence{s,m} := Sequence{m div n + 1,2 * m + 1} ; while (f->apply(k, s) + f->apply(n - k + 1, s)->compareTo(m)) < 0 do ( s := s + 1) ; execute (s - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) if n % 2==0 : a=b=n//2 print(a,b) else : max_a=1 for i in range(3,int(n**(1/2))+1,2): if n % i==0 : a=(n//i) max_a=max(a,max_a) print(max_a,n-max_a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( var a : OclAny := n div 2; var b : int := n div 2 ; execute (a)->display() ) else ( var max_a : int := 1 ; for i : Integer.subrange(3, ("" + (((n)->pow((1 / 2)))))->toInteger() + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if n mod i = 0 then ( a := (n div i) ; max_a := Set{a, max_a}->max() ) else skip) ; execute (max_a)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import pi def circle_inscribed(a): return pi*(a*a)/12 a=4 print(circle_inscribed(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 4 ; execute (circle_inscribed(a))->display(); operation circle_inscribed(a : OclAny) : OclAny pre: true post: true activity: return pi * (a * a) / 12; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import pi A,B=map(float,input().split()) print('{:.10f}'.format(4/3*pi*B**3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; execute (StringLib.interpolateStrings('{:.10f}', Sequence{4 / 3 * pi * (B)->pow(3)}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if b==0 : return a return gcd(b,a % b) def extgcd(a,b): if b==0 : x=1 y=0 return(x,y) r=a % b (y,x)=extgcd(b,r) y-=a//b*x return(x,y) a,b=map(int,input().split()) x,y=extgcd(a,b) print(x,y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var Sequence{y, x} : OclAny := extgcd(b, r); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if b = 0 then ( return a ) else skip ; return gcd(b, a mod b); operation extgcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if b = 0 then ( var x : int := 1 ; var y : int := 0 ; return Sequence{x, y} ) else skip ; var r : int := a mod b; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- L=input().split() a=[int(L[0]),1,0] b=[int(L[1]),0,1] while a[0]% b[0]!=0 : k=a[0]//b[0] c=b[0] c1=b[1] c2=b[2] a[1]-=(k*b[1]) a[2]-=(k*b[2]) b[0]=a[0]% b[0] b[1]=a[1] b[2]=a[2] a[0]=c a[1]=c1 a[2]=c2 k=a[0]//b[0] c=b[0] c1=b[1] c2=b[2] a[1]-=(k*b[1]) a[2]-=(k*b[2]) b[0]=a[0]% b[0] b[1]=a[1] b[2]=a[2] a[0]=c a[1]=c1 a[2]=c2 print(a[1],a[2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var L : OclAny := input().split() ; var a : Sequence := Sequence{("" + ((L->first())))->toInteger()}->union(Sequence{1}->union(Sequence{ 0 })) ; var b : Sequence := Sequence{("" + ((L[1+1])))->toInteger()}->union(Sequence{0}->union(Sequence{ 1 })) ; while a->first() mod b->first() /= 0 do ( var k : int := a->first() div b->first() ; var c : OclAny := b->first() ; var c1 : OclAny := b[1+1] ; var c2 : OclAny := b[2+1] ; a[1+1] := a[1+1] - (k * b[1+1]) ; a[2+1] := a[2+1] - (k * b[2+1]) ; b->first() := a->first() mod b->first() ; b[1+1] := a[1+1] ; b[2+1] := a[2+1] ; a->first() := c ; a[1+1] := c1 ; a[2+1] := c2) ; k := a->first() div b->first() ; c := b->first() ; c1 := b[1+1] ; c2 := b[2+1] ; a[1+1] := a[1+1] - (k * b[1+1]) ; a[2+1] := a[2+1] - (k * b[2+1]) ; b->first() := a->first() mod b->first() ; b[1+1] := a[1+1] ; b[2+1] := a[2+1] ; a->first() := c ; a[1+1] := c1 ; a[2+1] := c2 ; execute (a[1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function def rec(a,b): assert a>=b q,r=divmod(a,b) if r==0 : return 0,1,b x,y,gcd=rec(b,r) return y,x-q*y,gcd a,b=[int(_)for _ in raw_input().split()] if a=mag : break mag=mag1 x=x1 y=y1 while True : x1=x-dx y1=y-dy mag1=abs(x1)+abs(y1) if mag1>mag : break mag=mag1 x=x1 y=y1 print(x,y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{a,b} := raw_input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; if (a->compareTo(b)) < 0 then ( var y0 : OclAny := null; var x0 : OclAny := null; var gcd : OclAny := null; Sequence{y0,x0,gcd} := rec(b, a) ) else ( var x0 : OclAny := null; var y0 : OclAny := null; var gcd : OclAny := null; Sequence{x0,y0,gcd} := rec(a, b) ) ; var dx : int := b div gcd ; var dy : int := -a div gcd ; if dx < 0 then ( dx := -dx ; dy := -dy ) else skip ; var x : OclAny := x0 ; var y : OclAny := y0 ; var mag : double := (x)->abs() + (y)->abs() ; while true do ( var x1 : OclAny := x + dx ; var y1 : OclAny := y + dy ; var mag1 : double := (x1)->abs() + (y1)->abs() ; if (mag1->compareTo(mag)) >= 0 then ( break ) else skip ; mag := mag1 ; x := x1 ; y := y1) ; while true do ( x1 := x - dx ; y1 := y - dy ; mag1 := (x1)->abs() + (y1)->abs() ; if (mag1->compareTo(mag)) > 0 then ( break ) else skip ; mag := mag1 ; x := x1 ; y := y1) ; execute (x)->display(); operation rec(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: assert (a->compareTo(b)) >= 0 do "assertion failed" ; var q : OclAny := null; var r : OclAny := null; Sequence{q,r} := Sequence{(a div b), (a mod b)} ; if r = 0 then ( return 0, 1, b ) else skip ; var x : OclAny := null; var y : OclAny := null; var gcd : OclAny := null; Sequence{x,y,gcd} := rec(b, r) ; return y, x - q * y, gcd; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.readline().strip() def list2d(a,b,c): return[[c]*b for i in range(a)] def list3d(a,b,c,d): return[[[d]*c for j in range(b)]for i in range(a)] def list4d(a,b,c,d,e): return[[[[e]*d for j in range(c)]for j in range(b)]for i in range(a)] def ceil(x,y=1): return int(-(-x//y)) def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(N=None): return list(MAP())if N is None else[INT()for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10**9) INF=float('inf') MOD=10**9+7 def extgcd(a,b,x,y): if b==0 : x=1 y=0 return(y,x) else : x,y=extgcd(b,a % b,y,x) y-=a//b*x return(y,x) a,b=MAP() y,x=extgcd(a,b,0,0) print(x,y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; skip ; Sequence{a,b} := MAP() ; Sequence{y,x} := extgcd(a, b, 0, 0) ; execute (x)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation list2d(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, a-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ c }, b))); operation list3d(a : OclAny, b : OclAny, c : OclAny, d : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, a-1)->select(i | true)->collect(i | (Integer.subrange(0, b-1)->select(j | true)->collect(j | (MatrixLib.elementwiseMult(Sequence{ d }, c))))); operation list4d(a : OclAny, b : OclAny, c : OclAny, d : OclAny, e : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, a-1)->select(i | true)->collect(i | (Integer.subrange(0, b-1)->select(j | true)->collect(j | (Integer.subrange(0, c-1)->select(j | true)->collect(j | (MatrixLib.elementwiseMult(Sequence{ e }, d))))))); operation ceil(x : OclAny, y : int) : OclAny pre: true post: true activity: if y->oclIsUndefined() then y := 1 else skip; return ("" + ((-(-x div y))))->toInteger(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST(N : OclAny) : OclAny pre: true post: true activity: if N->oclIsUndefined() then N := null else skip; return if N <>= null then (MAP()) else Integer.subrange(0, N-1)->select(i | true)->collect(i | (INT())) endif; operation Yes() pre: true post: true activity: execute ('Yes')->display(); operation No() pre: true post: true activity: execute ('No')->display(); operation YES() pre: true post: true activity: execute ('YES')->display(); operation NO() pre: true post: true activity: execute ('NO')->display(); operation extgcd(a : OclAny, b : OclAny, x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if b = 0 then ( x := 1 ; y := 0 ; return Sequence{y, x} ) else ( Sequence{x,y} := extgcd(b, a mod b, y, x) ; y := y - a div b * x ; return Sequence{y, x} ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,radians from itertools import permutations,combinations,product from operator import itemgetter,mul from copy import deepcopy from string import ascii_lowercase,ascii_uppercase,digits from fractions import gcd from bisect import bisect_left from heapq import heappush,heappop def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) sys.setrecursionlimit(10**9) INF=float('inf') mod=10**9+7 a,b=MAP() c=gcd(a,b) def extgcd(a,b,d=0): g=a if b==0 : x,y=1,0 else : x,y,g=extgcd(b,a % b) x,y=y,x-a//b*y return x,y,g print(*extgcd(a,b)[: 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := MAP() ; var c : OclAny := gcd(a, b) ; skip ; execute ((argument * (test (logical_test (comparison (expr (atom (name extgcd)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name b)))))))) ))) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ]))))))))->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation extgcd(a : OclAny, b : OclAny, d : int) : OclAny pre: true post: true activity: if d->oclIsUndefined() then d := 0 else skip; var g : OclAny := a ; if b = 0 then ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{1,0} ) else ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y,g} := extgcd(b, a mod b) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{y,x - a div b * y} ) ; return x, y, g; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lines=[] for i in range(n): inp=input() lines.append(inp) good=False for line in lines : comps=line.split(" ") if int(comps[1])<2400 : continue if int(comps[2])<=int(comps[1]): continue print("YES") good=True break if good==False : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lines : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var inp : String := (OclFile["System.in"]).readLine() ; execute ((inp) : lines)) ; var good : boolean := false ; for line : lines do ( var comps : OclAny := line.split(" ") ; if ("" + ((comps[1+1])))->toInteger() < 2400 then ( continue ) else skip ; if (("" + ((comps[2+1])))->toInteger()->compareTo(("" + ((comps[1+1])))->toInteger())) <= 0 then ( continue ) else skip ; execute ("YES")->display() ; good := true ; break) ; if good = false then ( execute ("NO")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- z,c=int(input()),0 for _ in range(z): x=input().split(' ') if int(x[1])>=2400 and int(x[1])toInteger(),0} ; for _anon : Integer.subrange(0, z-1) do ( var x : OclAny := input().split(' ') ; if ("" + ((x[1+1])))->toInteger() >= 2400 & (("" + ((x[1+1])))->toInteger()->compareTo(("" + ((x[2+1])))->toInteger())) < 0 then ( var c : int := 1 ) else ( continue )) ; if c = 1 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A=int(input()) B=int(input()) C=int(input()) D=int(input()) E=int(input()) lst=[A,B,C,D,E] roundupped=[(x+9)//10*10 for x in lst] diff=[y-x for x,y in zip(lst,roundupped)] last=diff.index(max(diff)) sums=0 for i,x in enumerate(lst): if i==last : sums+=x else : sums+=roundupped[i] print(sums) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var C : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var D : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var E : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := Sequence{A}->union(Sequence{B}->union(Sequence{C}->union(Sequence{D}->union(Sequence{ E })))) ; var roundupped : Sequence := lst->select(x | true)->collect(x | ((x + 9) div 10 * 10)) ; var diff : Sequence := Integer.subrange(1, lst->size())->collect( _indx | Sequence{lst->at(_indx), roundupped->at(_indx)} )->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (y - x)) ; var last : int := diff->indexOf((diff)->max()) - 1 ; var sums : int := 0 ; for _tuple : Integer.subrange(1, (lst)->size())->collect( _indx | Sequence{_indx-1, (lst)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); if i = last then ( sums := sums + x ) else ( sums := sums + roundupped[i+1] )) ; execute (sums)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) c=0 for _ in range(n): n,b,a=map(str,input().split()) if int(b)>=2400 and int(b)toInteger() ; var c : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var b : OclAny := null; var a : OclAny := null; Sequence{n,b,a} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; if ("" + ((b)))->toInteger() >= 2400 & (("" + ((b)))->toInteger()->compareTo(("" + ((a)))->toInteger())) < 0 then ( c := c + 1 ) else skip) ; if c /= 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import exit t=int(input()) z=[] for i in range(t): line=input().split() number=[line[1],line[2]] z.append(number) for i in z : if int(i[0])>=2400 : if int(i[1])>int(i[0]): print('YES') exit() print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var z : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( var line : OclAny := input().split() ; var number : Sequence := Sequence{line[1+1]}->union(Sequence{ line[2+1] }) ; execute ((number) : z)) ; for i : z do ( if ("" + ((i->first())))->toInteger() >= 2400 then ( if (("" + ((i[1+1])))->toInteger()->compareTo(("" + ((i->first())))->toInteger())) > 0 then ( execute ('YES')->display() ; exit() ) else skip ) else skip) ; execute ("NO")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- isRed=False n=int(input()) for i in range(n): x,before,after=input().split() before=int(before) after=int(after) if(before>=2400 and after>before): isRed=True if(isRed): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var isRed : boolean := false ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var before : OclAny := null; var after : OclAny := null; Sequence{x,before,after} := input().split() ; var before : int := ("" + ((before)))->toInteger() ; var after : int := ("" + ((after)))->toInteger() ; if (before >= 2400 & (after->compareTo(before)) > 0) then ( isRed := true ) else skip) ; if (isRed) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a,b=map(int,input().split()) print(math.pi*float(b)**3*float(4/3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ( * (("" + ((b)))->toReal())->pow(3) * ("" + ((4 / 3)))->toReal())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input(); b=input() arr=list(map(int,input().split())) l=0 ; r=len(a)-1 ; ans=0 ; while l<=r : md=(l+r)//2 ; s=list(a) for i in range(md+1): s[arr[i]-1]='' i=0 ; j=0 ; na=len(s); nb=len(b) while icollect( _x | (OclType["int"])->apply(_x) )) ; var l : int := 0; var r : double := (a)->size() - 1; var ans : int := 0; ; while (l->compareTo(r)) <= 0 do ( var md : int := (l + r) div 2; var s : Sequence := (a)->characters() ; for i : Integer.subrange(0, md + 1-1) do ( s[arr[i+1] - 1+1] := '') ; var i : int := 0; var j : int := 0; var na : int := (s)->size(); var nb : int := (b)->size() ; while (i->compareTo(na)) < 0 & (j->compareTo(nb)) < 0 do ( if s[i+1] = b[j+1] then ( j := j + 1 ) else skip ; i := i + 1) ; if j = nb then ( ans := md + 1; l := md + 1 ) else ( r := md - 1 )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=input() p=input() arr=[int(i)-1 for i in input().split(" ")] def is_sub_sequence(str1,arr2): m=len(str1) n=len(arr2) j=0 i=0 while jselect(i | true)->collect(i | (("" + ((i)))->toInteger() - 1)) ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation is_sub_sequence(str1 : OclAny, arr2 : OclAny) : OclAny pre: true post: true activity: var m : int := (str1)->size() ; var n : int := (arr2)->size() ; var j : int := 0 ; var i : int := 0 ; while (j->compareTo(m)) < 0 & (i->compareTo(n)) < 0 do ( if str1[j+1] = arr2[i+1] then ( j := j + 1 ) else skip ; i := i + 1) ; return j = m; operation check(x : OclAny) : OclAny pre: true post: true activity: var sub_s : Sequence := Sequence{} ; var r2 : Set := Set{}->union((arr.subrange(1,x))) ; for i : Integer.subrange(0, (t)->size()-1) do ( if (r2)->includes(i) then ( continue ) else skip ; execute ((t[i+1]) : sub_s)) ; return is_sub_sequence(p, sub_s); operation main() pre: true post: true activity: var l : int := 0 ; var r : double := (arr)->size() - 1 ; while (l->compareTo(r)) < 0 do ( var mid : int := (l + r + 1) div 2 ; if check(mid) then ( l := mid ) else ( r := mid - 1 )) ; execute (l)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=list(input()),list(input()),tuple(map(int,input().split())) x,y,l,r=len(a),len(b),0,200000 def cn(mid): v=a.copy() if mid>x-y : return False for i in range(mid): v[c[i]-1]=0 s=0 for i in v : if s==y : break s+=1 if i==b[s]else 0 return True if s==y else False while l<=r : mid=(l+r)//2 if cn(mid): l=mid+1 else : r=mid-1 print(max(0,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{((OclFile["System.in"]).readLine())->characters(),((OclFile["System.in"]).readLine())->characters(),((input().split())->collect( _x | (OclType["int"])->apply(_x) ))} ; var x : OclAny := null; var y : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{x,y,l,r} := Sequence{(a)->size(),(b)->size(),0,200000} ; skip ; while (l->compareTo(r)) <= 0 do ( mid := (l + r) div 2 ; if cn(mid) then ( var l : OclAny := mid + 1 ) else ( var r : double := mid - 1 )) ; execute (Set{0, r}->max())->display(); operation cn(mid : OclAny) : OclAny pre: true post: true activity: var v : OclAny := a->copy() ; if (mid->compareTo(x - y)) > 0 then ( return false ) else skip ; for i : Integer.subrange(0, mid-1) do ( v[c[i+1] - 1+1] := 0) ; var s : int := 0 ; for i : v do ( if s = y then ( break ) else skip ; s := s + if i = b[s+1] then 1 else 0 endif) ; return if s = y then true else false endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=(int(i)for i in input().split()) res=[] for i in range(n): row=[0]*n row[i]=k res.append(row) res="\n".join(" ".join(str(c)for c in r)for r in res) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var res : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var row : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; row[i+1] := k ; execute ((row) : res)) ; res := StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom " ") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name r)))))))) ))))))) (comp_for for (exprlist (expr (atom (name r)))) in (logical_test (comparison (expr (atom (name res)))))))), "\n") ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt from collections import defaultdict,deque from posixpath import split import sys from bisect import bisect_right as b_r from bisect import bisect_left as b_l mod=1000000007 INT_MAX=sys.maxsize-1 INT_MIN=-sys.maxsize def solve(): n,m=map(int,input().split()) a=[[0]*n for i in range(n)] j=0 for i in range(n): a[i][j]=m j+=1 for i in a : print(*i) if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var mod : int := 1000000007 ; var INT_MAX : double := (trailer . (name maxsize)) - 1 ; var INT_MIN : (trailer . (name maxsize)) := -(trailer . (name maxsize)) ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation solve() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, n))) ; var j : int := 0 ; for i : Integer.subrange(0, n-1) do ( a[i+1][j+1] := m ; j := j + 1) ; for i : a do ( execute ((argument * (test (logical_test (comparison (expr (atom (name i))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) for i in range(n): for j in range(n): if i==j : print(k,end=' ') else : print(0,end=' ') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if i = j then ( execute (k)->display() ) else ( execute (0)->display() )) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math menu=[] for _ in range(5): m=input() e=int(m[-1]) if e==0 : e=10 menu.append([int(m),e]) menu.sort(key=lambda x : x[1]) ans=0 for m in menu[1 :]: ans+=math.ceil(m[0]/10)*10 print(ans+menu[0][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var menu : Sequence := Sequence{} ; for _anon : Integer.subrange(0, 5-1) do ( var m : String := (OclFile["System.in"]).readLine() ; var e : int := ("" + ((m->last())))->toInteger() ; if e = 0 then ( e := 10 ) else skip ; execute ((Sequence{("" + ((m)))->toInteger()}->union(Sequence{ e })) : menu)) ; menu := menu->sort() ; var ans : int := 0 ; for m : menu->tail() do ( ans := ans + (m->first() / 10)->ceil() * 10) ; execute (ans + menu->first()->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) tables=[[0 for _ in range(n)]for _ in range(n)] for i in range(n): tables[i][i]=k print(*tables[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var tables : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)))) ; for i : Integer.subrange(0, n-1) do ( tables[i+1][i+1] := k ; execute ((argument * (test (logical_test (comparison (expr (atom (name tables)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) l=[0]*n l[0]=k for _ in range(n): print(" ".join(str(num)for num in l)) l=[l[-1]]+l[:-1] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; l->first() := k ; for _anon : Integer.subrange(0, n-1) do ( execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) ))))))) (comp_for for (exprlist (expr (atom (name num)))) in (logical_test (comparison (expr (atom (name l)))))))), " "))->display() ; l := Sequence{ l->last() }->union(l->front())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib,itertools def compute(): totients=eulerlib.list_totients(10**6) ans=sum(itertools.islice(totients,2,None)) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var totients : OclAny := eulerlib.list_totients((10)->pow(6)) ; var ans : OclAny := (itertools.islice(totients, 2, null))->sum() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def Probability(A,B): C=6-max(A,B) __gcd=gcd(C,6) print(C//__gcd,"/",6//__gcd) if __name__=="__main__" : A,B=2,4 Probability(A,B) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( Sequence{A,B} := Sequence{2,4} ; Probability(A, B) ) else skip; operation Probability(A : OclAny, B : OclAny) pre: true post: true activity: var C : double := 6 - Set{A, B}->max() ; var __gcd : OclAny := gcd(C, 6) ; execute (C div __gcd)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a,b=map(int,input().split()) print(4/3*b**3*math.pi) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (4 / 3 * (b)->pow(3) * )->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Time(arr,n,Emptypipe): fill=0 for i in range(0,n): fill+=(1/arr[i]) fill=fill-(1/float(Emptypipe)) return int(1/fill) if __name__=='__main__' : arr=[12,14] Emptypipe=30 n=len(arr) print((Time(arr,n,Emptypipe)),"Hours") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{12}->union(Sequence{ 14 }) ; Emptypipe := 30 ; n := (arr)->size() ; execute ((Time(arr, n, Emptypipe)))->display() ) else skip; operation Time(arr : OclAny, n : OclAny, Emptypipe : OclAny) : OclAny pre: true post: true activity: var fill : int := 0 ; for i : Integer.subrange(0, n-1) do ( fill := fill + (1 / arr[i+1])) ; fill := fill - (1 / ("" + ((Emptypipe)))->toReal()) ; return ("" + ((1 / fill)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numberOfMen(D,m,d): Men=(m*(D-d))/d ; return int(Men); D=5 ; m=4 ; d=4 ; print(numberOfMen(D,m,d)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; D := 5; m := 4; d := 4; ; execute (numberOfMen(D, m, d))->display();; operation numberOfMen(D : OclAny, m : OclAny, d : OclAny) pre: true post: true activity: var Men : double := (m * (D - d)) / d; ; return ("" + ((Men)))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=list(map(int,input().split())) l=[] for i in range(n): l.append((a[i],i+1)) l,a=sorted(l),[] for i in range(n): if(k-l[i][0]>=0): k-=l[i][0]; a.append(l[i][1]) else : break print(len(a)) print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((Sequence{a[i+1], i + 1}) : l)) ; Sequence{l,a} := Sequence{l->sort(),Sequence{}} ; for i : Integer.subrange(0, n-1) do ( if (k - l[i+1]->first() >= 0) then ( k := k - l[i+1]->first(); ; execute ((l[i+1][1+1]) : a) ) else ( break )) ; execute ((a)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=[int(i)for i in input().strip().split()] a=[(int(i),en+1)for en,i in enumerate(input().strip().split())] a.sort() i=0 count=0 ans=[] while i=a[i][0]: k-=a[i][0] count+=1 ans.append(a[i][1]) i+=1 print(count) if count!=0 : print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input()->trim().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a : Sequence := Integer.subrange(1, (input()->trim().split())->size())->collect( _indx | Sequence{_indx-1, (input()->trim().split())->at(_indx)} )->select(_tuple | true)->collect(_tuple | let en : OclAny = _tuple->at(1) in let i : OclAny = _tuple->at(2) in (Sequence{("" + ((i)))->toInteger(), en + 1})) ; a := a->sort() ; var i : int := 0 ; var count : int := 0 ; var ans : Sequence := Sequence{} ; while (i->compareTo(n)) < 0 & (k->compareTo(a[i+1]->first())) >= 0 do ( k := k - a[i+1]->first() ; count := count + 1 ; execute ((a[i+1][1+1]) : ans) ; i := i + 1) ; execute (count)->display() ; if count /= 0 then ( execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,sys,io,math from tokenize import Triple from math import* I=lambda :[*map(int,sys.stdin.readline().split())] IS=lambda : input() IN=lambda : int(input()) IF=lambda : float(input()) n,k=map(int,input().split()) l=I() l=list(enumerate(l)) l.sort(key=lambda x : x[1]) s=0 res=[] for i,j in l : if s+j<=k : res.append(i+1) s+=j else : break print(len(res)) print(*res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var I : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var IS : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var IN : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var IF : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toReal()) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : OclAny := I->apply() ; l := (Integer.subrange(1, (l)->size())->collect( _indx | Sequence{_indx-1, (l)->at(_indx)} )) ; l := l->sort() ; var s : int := 0 ; var res : Sequence := Sequence{} ; for _tuple : l do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if (s + j->compareTo(k)) <= 0 then ( execute ((i + 1) : res) ; s := s + j ) else ( break )) ; execute ((res)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def isPerfectSquare(x): sr=math.sqrt(x) return((sr-math.floor(sr))==0) def isProduct(num): cnt=0 i=2 while cnt<2 and i*i<=num : while(num % i==0): num//=i cnt+=1 i+=1 if(num>1): cnt+=1 return cnt==2 def findNumbers(N): vec=[] for i in range(1,N+1): if(isProduct(i)and not isPerfectSquare(i)): vec.append(i) for i in range(len(vec)): print(vec[i],end=" ") if __name__=="__main__" : N=30 findNumbers(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( N := 30 ; findNumbers(N) ) else skip; operation isPerfectSquare(x : OclAny) : OclAny pre: true post: true activity: var sr : double := (x)->sqrt() ; return ((sr - (sr)->floor()) = 0); operation isProduct(num : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; var i : int := 2 ; while cnt < 2 & (i * i->compareTo(num)) <= 0 do ( while (num mod i = 0) do ( num := num div i ; cnt := cnt + 1) ; i := i + 1) ; if (num > 1) then ( cnt := cnt + 1 ) else skip ; return cnt = 2; operation findNumbers(N : OclAny) pre: true post: true activity: var vec : Sequence := Sequence{} ; for i : Integer.subrange(1, N + 1-1) do ( if (isProduct(i) & not(isPerfectSquare(i))) then ( execute ((i) : vec) ) else skip) ; for i : Integer.subrange(0, (vec)->size()-1) do ( execute (vec[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout if __name__=="__main__" : n,k=map(int,input().split()) l=list(map(int,input().split())) l=list(enumerate(l)) l.sort(key=lambda x : x[1]) s=0 res=[] for i,j in l : if s+j<=k : res.append(i+1) s+=j else : break print(len(res)) print(*res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := (Integer.subrange(1, (l)->size())->collect( _indx | Sequence{_indx-1, (l)->at(_indx)} )) ; l := l->sort() ; var s : int := 0 ; var res : Sequence := Sequence{} ; for _tuple : l do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if (s + j->compareTo(k)) <= 0 then ( execute ((i + 1) : res) ; s := s + j ) else ( break )) ; execute ((res)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,sys,io,math from tokenize import Triple from math import* I=lambda :[*map(int,sys.stdin.readline().split())] IS=lambda : input() IN=lambda : int(input()) IF=lambda : float(input()) from sys import stdin,stdout if __name__=="__main__" : n,k=map(int,input().split()) l=I() l=list(enumerate(l)) l.sort(key=lambda x : x[1]) s=0 res=[] for i,j in l : if s+j<=k : res.append(i+1) s+=j else : break print(len(res)) print(*res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var I : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var IS : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var IN : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var IF : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toReal()) ; skip ; if __name__ = "__main__" then ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : OclAny := I->apply() ; l := (Integer.subrange(1, (l)->size())->collect( _indx | Sequence{_indx-1, (l)->at(_indx)} )) ; l := l->sort() ; var s : int := 0 ; var res : Sequence := Sequence{} ; for _tuple : l do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if (s + j->compareTo(k)) <= 0 then ( execute ((i + 1) : res) ; s := s + j ) else ( break )) ; execute ((res)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools def compute(): ans=sum(int("".join(map(str,num)))for num in itertools.permutations(list(range(10)))if is_substring_divisible(num)) return str(ans) DIVISIBILITY_TESTS=[2,3,5,7,11,13,17] def is_substring_divisible(num): return all((num[i+1]*100+num[i+2]*10+num[i+3])% p==0 for(i,p)in enumerate(DIVISIBILITY_TESTS)) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var DIVISIBILITY_TESTS : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{11}->union(Sequence{13}->union(Sequence{ 17 })))))) ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name num)))))))) ))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name num)))) in (logical_test (comparison (expr (atom (name itertools)) (trailer . (name permutations) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 10))))))))) ))))))))) ))))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (atom (name is_substring_divisible)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) )))))))))))->sum() ; return ("" + ((ans))); operation is_substring_divisible(num : OclAny) : OclAny pre: true post: true activity: return ((argument (test (logical_test (comparison (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (expr (atom (name num)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))) * (expr (atom (number (integer 100))))) + (expr (expr (atom (name num)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 2)))))))))) ]))) * (expr (atom (number (integer 10)))))) + (expr (atom (name num)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 3)))))))))) ])))))))) ))) % (expr (atom (name p))))) == (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) , (test (logical_test (comparison (expr (atom (name p))))))) )))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name DIVISIBILITY_TESTS)))))))) )))))))))->forAll( _x | _x = true ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ULL_SIZE=64 def bit_anagram_check(a): return(bin(a).count("1")==(ULL_SIZE>>1)) a=4294967295 print(int(bit_anagram_check(a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ULL_SIZE : int := 64 ; skip ; a := 4294967295 ; execute (("" + ((bit_anagram_check(a))))->toInteger())->display(); operation bit_anagram_check(a : OclAny) : OclAny pre: true post: true activity: return (bin(a)->count("1") = (ULL_SIZE /(2->pow(1)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) d={} for i in range(m): nc=[] c=[] l=list(map(int,list(input().split()))) for j in range(3): if l[j]not in d.keys(): nc.append(l[j]) else : c.append(l[j]) d1={} for u in c : d1[u]=d[u] for b in nc : for v in range(1,4): if v not in d1.values(): d[b]=v d1[b]=v break for i in sorted(d.items()): print(i[1],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : OclAny := Set{} ; for i : Integer.subrange(0, m-1) do ( var nc : Sequence := Sequence{} ; var c : Sequence := Sequence{} ; var l : Sequence := (((input().split()))->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, 3-1) do ( if (d.keys())->excludes(l[j+1]) then ( execute ((l[j+1]) : nc) ) else ( execute ((l[j+1]) : c) )) ; var d1 : OclAny := Set{} ; for u : c do ( d1[u+1] := d[u+1]) ; for b : nc do ( for v : Integer.subrange(1, 4-1) do ( if (d1.values())->excludes(v) then ( d[b+1] := v ; d1[b+1] := v ; break ) else skip))) ; for i : d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sort() do ( execute (i[1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def minOperations(arr,n): mp=dict.fromkeys(arr,0); for i in range(n): mp[arr[i]]+=1 ; maxFreq=-(sys.maxsize-1); for key in mp : maxFreq=max(maxFreq,mp[key]); return(n-maxFreq); if __name__=="__main__" : arr=[2,4,6]; n=len(arr); print(minOperations(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{2}->union(Sequence{4}->union(Sequence{ 6 })); ; n := (arr)->size(); ; execute (minOperations(arr, n))->display(); ) else skip; operation minOperations(arr : OclAny, n : OclAny) pre: true post: true activity: var mp : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))); ; for i : Integer.subrange(0, n-1) do ( mp[arr[i+1]+1] := mp[arr[i+1]+1] + 1;) ; var maxFreq : double := -((trailer . (name maxsize)) - 1); ; for key : mp->keys() do ( maxFreq := Set{maxFreq, mp[key+1]}->max();) ; return (n - maxFreq);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input().split() (n,m)=(int(i)for i in s) res=[0 for i in range(0,n+1)] for i in range(m): s=input().split() s=[int(i)for i in s] p=set([res[i]for i in s]) for i in range(3): if(res[s[i]]==0): if(1 not in p): res[s[i]]=1 p.add(1) elif(2 not in p): res[s[i]]=2 p.add(2) else : res[s[i]]=3 p.add(3) for i in range(1,n+1): print(res[i],end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := input().split() ; var Sequence{n, m} : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name s)))))))} ; var res : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, m-1) do ( s := input().split() ; s := s->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var p : Set := Set{}->union((s->select(i | true)->collect(i | (res[i+1])))) ; for i : Integer.subrange(0, 3-1) do ( if (res[s[i+1]+1] = 0) then ( if ((p)->excludes(1)) then ( res[s[i+1]+1] := 1 ; execute ((1) : p) ) else (if ((p)->excludes(2)) then ( res[s[i+1]+1] := 2 ; execute ((2) : p) ) else ( res[s[i+1]+1] := 3 ; execute ((3) : p) ) ) ) else skip)) ; for i : Integer.subrange(1, n + 1-1) do ( execute (res[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) d={} for i in range(m): nc=[] c=[] l=list(map(int,list(input().split()))) for j in range(3): if l[j]not in d.keys(): nc.append(l[j]) else : c.append(l[j]) d1={} for u in c : d1[u]=d[u] for b in nc : for v in range(1,4): if v not in d1.values(): d[b]=v d1[b]=v break for i in sorted(d.items()): print(i[1],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : OclAny := Set{} ; for i : Integer.subrange(0, m-1) do ( var nc : Sequence := Sequence{} ; var c : Sequence := Sequence{} ; var l : Sequence := (((input().split()))->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, 3-1) do ( if (d.keys())->excludes(l[j+1]) then ( execute ((l[j+1]) : nc) ) else ( execute ((l[j+1]) : c) )) ; var d1 : OclAny := Set{} ; for u : c do ( d1[u+1] := d[u+1]) ; for b : nc do ( for v : Integer.subrange(1, 4-1) do ( if (d1.values())->excludes(v) then ( d[b+1] := v ; d1[b+1] := v ; break ) else skip))) ; for i : d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sort() do ( execute (i[1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=[0]*n for i in range(m): s=list(map(int,input().split())) for j in range(1,4): if(a[s[j-1]-1]!=0): a[s[a[s[j-1]-1]-1]-1]=j else : a[s[j-1]-1]=j print(' '.join(map(str,a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, m-1) do ( var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(1, 4-1) do ( if (a[s[j - 1+1] - 1+1] /= 0) then ( a[s[a[s[j - 1+1] - 1+1] - 1+1] - 1+1] := j ) else ( a[s[j - 1+1] - 1+1] := j ))) ; execute (StringLib.sumStringsWithSeparator(((a)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def shuffleArray(a,n): i,q,k=0,1,n while(ii+q): a[j-1],a[j]=a[j],a[j-1] j-=1 i+=1 k+=1 q+=1 a=[1,3,5,7,2,4,6,8] n=len(a) shuffleArray(a,int(n/2)) for i in range(0,n): print(a[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{2}->union(Sequence{4}->union(Sequence{6}->union(Sequence{ 8 }))))))) ; n := (a)->size() ; shuffleArray(a, ("" + ((n / 2)))->toInteger()) ; for i : Integer.subrange(0, n-1) do ( execute (a[i+1])->display()); operation shuffleArray(a : OclAny, n : OclAny) pre: true post: true activity: var i : OclAny := null; var q : OclAny := null; var k : OclAny := null; Sequence{i,q,k} := Sequence{0,1,n} ; while ((i->compareTo(n)) < 0) do ( var j : OclAny := k ; while ((j->compareTo(i + q)) > 0) do ( var a[j - 1+1] : OclAny := null; var a[j+1] : OclAny := null; Sequence{a[j - 1+1],a[j+1]} := Sequence{a[j+1],a[j - 1+1]} ; j := j - 1) ; i := i + 1 ; k := k + 1 ; q := q + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- data="""\ 111111101010101111100101001111111 100000100000000001010110001000001 101110100110110000011010001011101 101110101011001001111101001011101 101110101100011000111100101011101 100000101010101011010000101000001 111111101010101010101010101111111 000000001111101111100111100000000 100010111100100001011110111111001 110111001111111100100001000101100 011100111010000101000111010001010 011110000110001111110101100000011 111111111111111000111001001011000 111000010111010011010011010100100 101010100010110010110101010000010 101100000101010001111101000000000 000010100011001101000111101011010 101001001111101111000101010001110 101101111111000100100001110001000 000010011000100110000011010000010 001101101001101110010010011011000 011101011010001000111101010100110 111010100110011101001101000001110 110001010010101111000101111111000 001000111011100001010110111110000 000000001110010110100010100010110 111111101000101111000110101011010 100000100111010101111100100011011 101110101001010000101000111111000 101110100011010010010111111011010 101110100100011011110110101110000 100000100110011001111100111100000 111111101101000101001101110010001 """ data=[[x for x in l]for l in data.splitlines()] x,y=input().split() x,y=int(x),int(y) print(data[x][y]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var data : String := (atom "" "\\r\n111111101010101111100101001111111\r\n100000100000000001010110001000001\r\n101110100110110000011010001011101\r\n101110101011001001111101001011101\r\n101110101100011000111100101011101\r\n100000101010101011010000101000001\r\n111111101010101010101010101111111\r\n000000001111101111100111100000000\r\n100010111100100001011110111111001\r\n110111001111111100100001000101100\r\n011100111010000101000111010001010\r\n011110000110001111110101100000011\r\n111111111111111000111001001011000\r\n111000010111010011010011010100100\r\n101010100010110010110101010000010\r\n101100000101010001111101000000000\r\n000010100011001101000111101011010\r\n101001001111101111000101010001110\r\n101101111111000100100001110001000\r\n000010011000100110000011010000010\r\n001101101001101110010010011011000\r\n011101011010001000111101010100110\r\n111010100110011101001101000001110\r\n110001010010101111000101111111000\r\n001000111011100001010110111110000\r\n000000001110010110100010100010110\r\n111111101000101111000110101011010\r\n100000100111010101111100100011011\r\n101110101001010000101000111111000\r\n101110100011010010010111111011010\r\n101110100100011011110110101110000\r\n100000100110011001111100111100000\r\n111111101101000101001101110010001\r\n" "") ; data := data.splitlines()->select(l | true)->collect(l | (l->select(x | true)->collect(x | (x)))) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := input().split() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{("" + ((x)))->toInteger(),("" + ((y)))->toInteger()} ; execute (data[x+1][y+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=input() print(" ".join(list(dict.fromkeys(input().split())))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : String := (OclFile["System.in"]).readLine() ; execute (StringLib.sumStringsWithSeparator((((trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))->keys()->asSequence()), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def unique(li): return[li[i]for i in range(len(li))if i==0 or li[i]>li[i-1]] def run(): n=int(input()) li=[int(x)for x in input().split()] assert(n==len(li)) print(" ".join([str(x)for x in unique(li)])) if __name__=='__main__' : run() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( run() ) else skip; operation unique(li : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, (li)->size()-1)->select(i | i = 0 or (li[i+1]->compareTo(li[i - 1+1])) > 0)->collect(i | (li[i+1])); operation run() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; li := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; assert (n = (li)->size()) do "assertion failed" ; execute (StringLib.sumStringsWithSeparator((unique(li)->select(x | true)->collect(x | (("" + ((x)))))), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque import sys input=sys.stdin.readline def main(): n1=int(input()) l1=list(map(int,input().split())) print(*sorted(list(set(l1)))) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l1)))))))) ))))))))) ))))))))) )))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) *a,=map(int,input().split()) b=[] i=0 while i0 and a[i]==a[i-1]: i+=1 continue b.append(a[i]) i+=1 print(*b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (testlist_star_expr (star_expr * (expr (atom (name a)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name a)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : Sequence := Sequence{} ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( if i > 0 & a[i+1] = a[i - 1+1] then ( i := i + 1 ; continue ) else skip ; execute ((a[i+1]) : b) ; i := i + 1) ; execute ((argument * (test (logical_test (comparison (expr (atom (name b))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): from sys import stdin f_i=stdin n=f_i.readline() A=f_i.readline().split() ans=(a1 for a1,a2 in zip(A,A[1 :]+[None])if a1!=a2) print(' '.join(ans)) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: skip ; var f_i : OclAny := stdin ; var n : String := f_i.readLine() ; var A : OclAny := f_i.readLine().split() ; var ans : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name a1)))))) (comp_for for (exprlist (expr (atom (name a1))) , (expr (atom (name a2)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) + (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom None)))))) ])))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name a1)))) != (comparison (expr (atom (name a2))))))))))} ; execute (StringLib.sumStringsWithSeparator((ans), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) li=list(map(int,input().split())) res=1 tmp=1 for i in range(1,n): if li[i-1]==li[i]: tmp+=1 else : res=max(res,tmp) tmp=1 res=max(res,tmp) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : int := 1 ; var tmp : int := 1 ; for i : Integer.subrange(1, n-1) do ( if li[i - 1+1] = li[i+1] then ( tmp := tmp + 1 ) else ( res := Set{res, tmp}->max() ; tmp := 1 )) ; res := Set{res, tmp}->max() ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[input()for _ in[0]*3] d=dict(zip('rsp','spr')) r='FMS' for i in range(3): if sum(x[0]==d[a[i][0]]for x in a)==2 : print(r[i]) exit() print('?') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 3)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var d : Map := ((expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'rsp')))))) , (argument (test (logical_test (comparison (expr (atom 'spr'))))))) ))))) ; var r : String := 'FMS' ; for i : Integer.subrange(0, 3-1) do ( if ((argument (test (logical_test (comparison (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) == (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ]))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a))))))))->sum() = 2 then ( execute (r[i+1])->display() ; exit() ) else skip) ; execute ('?')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): n=input() *a,=map(int,input().split()) max_=0 for c in set(a): ct=a.count(c) if ct>max_ : max_=ct print(max_) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : String := (OclFile["System.in"]).readLine()) ; (testlist_star_expr (star_expr * (expr (atom (name a)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name a)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: *a,=map(int,s.split()) d={k : a.count(k)for k in set(a)} print(max(d.values())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( ; (testlist_star_expr (star_expr * (expr (atom (name a)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name a)))) ,)} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Map := Set{}->union((a))->select(k | true)->collect(k | Map{k |-> a->count(k)})->unionAll() ; execute ((d.values())->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) max_count=0 count=0 prev=0 for x in a : if x!=prev : count=1 else : count+=1 max_count=max(count,max_count) prev=x print(max_count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var max_count : int := 0 ; var count : int := 0 ; var prev : int := 0 ; for x : a do ( if x /= prev then ( count := 1 ) else ( count := count + 1 ) ; max_count := Set{count, max_count}->max() ; prev := x) ; execute (max_count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=['111111101010101111100101001111111','100000100000000001010110001000001','101110100110110000011010001011101','101110101011001001111101001011101','101110101100011000111100101011101','100000101010101011010000101000001','111111101010101010101010101111111','000000001111101111100111100000000','100010111100100001011110111111001','110111001111111100100001000101100','011100111010000101000111010001010','011110000110001111110101100000011','111111111111111000111001001011000','111000010111010011010011010100100','101010100010110010110101010000010','101100000101010001111101000000000','000010100011001101000111101011010','101001001111101111000101010001110','101101111111000100100001110001000','000010011000100110000011010000010','001101101001101110010010011011000','011101011010001000111101010100110','111010100110011101001101000001110','110001010010101111000101111111000','001000111011100001010110111110000','000000001110010110100010100010110','111111101000101111000110101011010','100000100111010101111100100011011','101110101001010000101000111111000','101110100011010010010111111011010','101110100100011011110110101110000','100000100110011001111100111100000','111111101101000101001101110010001'] x,y=map(int,input().split()) print(a[x][y]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Sequence{'111111101010101111100101001111111'}->union(Sequence{'100000100000000001010110001000001'}->union(Sequence{'101110100110110000011010001011101'}->union(Sequence{'101110101011001001111101001011101'}->union(Sequence{'101110101100011000111100101011101'}->union(Sequence{'100000101010101011010000101000001'}->union(Sequence{'111111101010101010101010101111111'}->union(Sequence{'000000001111101111100111100000000'}->union(Sequence{'100010111100100001011110111111001'}->union(Sequence{'110111001111111100100001000101100'}->union(Sequence{'011100111010000101000111010001010'}->union(Sequence{'011110000110001111110101100000011'}->union(Sequence{'111111111111111000111001001011000'}->union(Sequence{'111000010111010011010011010100100'}->union(Sequence{'101010100010110010110101010000010'}->union(Sequence{'101100000101010001111101000000000'}->union(Sequence{'000010100011001101000111101011010'}->union(Sequence{'101001001111101111000101010001110'}->union(Sequence{'101101111111000100100001110001000'}->union(Sequence{'000010011000100110000011010000010'}->union(Sequence{'001101101001101110010010011011000'}->union(Sequence{'011101011010001000111101010100110'}->union(Sequence{'111010100110011101001101000001110'}->union(Sequence{'110001010010101111000101111111000'}->union(Sequence{'001000111011100001010110111110000'}->union(Sequence{'000000001110010110100010100010110'}->union(Sequence{'111111101000101111000110101011010'}->union(Sequence{'100000100111010101111100100011011'}->union(Sequence{'101110101001010000101000111111000'}->union(Sequence{'101110100011010010010111111011010'}->union(Sequence{'101110100100011011110110101110000'}->union(Sequence{'100000100110011001111100111100000'}->union(Sequence{ '111111101101000101001101110010001' })))))))))))))))))))))))))))))))) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (a[x+1][y+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) for i in range(num): lenz=int(input()) arr=input() arr=arr.split(" ") arr=[int(x)for x in arr] countColor=0 while len(arr): first=0 j=0 countColor+=1 first=arr[j] arr.remove(arr[j]) while jfirst : first=arr[j] arr.remove(arr[j]) else : j+=1 print(countColor) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, num-1) do ( var lenz : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : String := (OclFile["System.in"]).readLine() ; arr := arr.split(" ") ; arr := arr->characters()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var countColor : int := 0 ; while (arr)->size() do ( var first : int := 0 ; var j : int := 0 ; countColor := countColor + 1 ; first := arr[j+1] ; execute ((arr[j+1]) /: arr) ; while (j->compareTo((arr)->size())) < 0 do ( if (arr[j+1]->compareTo(first)) > 0 then ( first := arr[j+1] ; execute ((arr[j+1]) /: arr) ) else ( j := j + 1 ))) ; execute (countColor)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) c=0 l1=list(map(int,input().split())) for i in range(n-1): mx=max(l1[i],l1[i+1]) mn=min(l1[i],l1[i+1]) while(mn*2toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := 0 ; var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n - 1-1) do ( var mx : OclAny := Set{l1[i+1], l1[i + 1+1]}->max() ; var mn : OclAny := Set{l1[i+1], l1[i + 1+1]}->min() ; while ((mn * 2->compareTo(mx)) < 0) do ( c := c + 1 ; mn := mn * 2)) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for i in range(int(input())): n=int(input()) l=list(map(int,input().split())) c=0 for j in range(n-1): m=max(l[j],l[j+1]) mi=min(l[j],l[j+1]) while((m/mi)>2.0): m=math.ceil(m/2) c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; for j : Integer.subrange(0, n - 1-1) do ( var m : OclAny := Set{l[j+1], l[j + 1+1]}->max() ; var mi : OclAny := Set{l[j+1], l[j + 1+1]}->min() ; while ((m / mi) > 2.0) do ( m := (m / 2)->ceil() ; c := c + 1)) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) count=0 for i in range(1,n): if a[i]toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : int := 0 ; for i : Integer.subrange(1, n-1) do ( if (a[i+1]->compareTo(a[i - 1+1])) < 0 then ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{a[i+1],a[i - 1+1]} ) else ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{a[i - 1+1],a[i+1]} ) ; while (2 * x->compareTo(y)) < 0 do ( x := x * 2 ; count := count + 1)) ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) a=list(map(int,input().split())) u=0 for j in range(1,n): while a[j-1]*2a[j]*2 : if a[j-1]% 2==1 : a[j-1]//=2 a[j-1]+=1 u+=1 else : a[j-1]//=2 u+=1 print(u) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var u : int := 0 ; for j : Integer.subrange(1, n-1) do ( while (a[j - 1+1] * 2->compareTo(a[j+1])) < 0 do ( a[j - 1+1] := a[j - 1+1] * 2 ; u := u + 1) ; while (a[j - 1+1]->compareTo(a[j+1] * 2)) > 0 do ( if a[j - 1+1] mod 2 = 1 then ( a[j - 1+1] := a[j - 1+1] div 2 ; a[j - 1+1] := a[j - 1+1] + 1 ; u := u + 1 ) else ( a[j - 1+1] := a[j - 1+1] div 2 ; u := u + 1 ))) ; execute (u)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calc(mx,mn): tmp=0 while(1): if mx<=2*mn : break else : mn=2*mn tmp+=1 return tmp for _ in range(int(input())): n=int(input()) li=list(map(int,input().split())) res=0 for i in range(1,n): mx=max(li[i],li[i-1]) mn=min(li[i],li[i-1]) if mx/mn>=2 : res+=calc(mx,mn) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : int := 0 ; for i : Integer.subrange(1, n-1) do ( mx := Set{li[i+1], li[i - 1+1]}->max() ; mn := Set{li[i+1], li[i - 1+1]}->min() ; if mx / mn >= 2 then ( res := res + calc(mx, mn) ) else skip) ; execute (res)->display()); operation calc(mx : OclAny, mn : OclAny) : OclAny pre: true post: true activity: var tmp : int := 0 ; while (1) do ( if (mx->compareTo(2 * mn)) <= 0 then ( break ) else ( mn := 2 * mn ; tmp := tmp + 1 )) ; return tmp; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=list(map(int,input().split())) K=0 K+=a[1]*1 if a[0]>=1 and a[3]>=1 and a[4]>=1 : oddn=0 for e in[0,3,4]: if a[e]% 2==1 : oddn+=1 if oddn>=2 : K+=3 for e in[0,3,4]: a[e]-=1 for e in[0,3,4]: K+=(a[e]//2)*2 print(K) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var K : int := 0 ; K := K + a[1+1] * 1 ; if a->first() >= 1 & a[3+1] >= 1 & a[4+1] >= 1 then ( var oddn : int := 0 ; for e : Sequence{0}->union(Sequence{3}->union(Sequence{ 4 })) do ( if a[e+1] mod 2 = 1 then ( oddn := oddn + 1 ) else skip) ; if oddn >= 2 then ( K := K + 3 ; for e : Sequence{0}->union(Sequence{3}->union(Sequence{ 4 })) do ( a[e+1] := a[e+1] - 1) ) else skip ) else skip ; for e : Sequence{0}->union(Sequence{3}->union(Sequence{ 4 })) do ( K := K + (a[e+1] div 2) * 2) ; execute (K)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=input() m=input() s=input() out=0 if f=="rock" : if m=="scissors" and s=="scissors" : out=1 elif m=="rock" and s=="paper" : out=3 elif s=="rock" and m=="paper" : out=2 elif f=="paper" : if m=="rock" and s=="rock" : out=1 elif m=="paper" and s=="scissors" : out=3 elif s=="paper" and m=="scissors" : out=2 elif f=="scissors" : if m=="paper" and s=="paper" : out=1 elif m=="scissors" and s=="rock" : out=3 elif s=="scissors" and m=="rock" : out=2 if(out==0): print("?") elif out==1 : print("F") elif out==2 : print("M") else : print("S") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : String := (OclFile["System.in"]).readLine() ; var m : String := (OclFile["System.in"]).readLine() ; var s : String := (OclFile["System.in"]).readLine() ; var out : int := 0 ; if f = "rock" then ( if m = "scissors" & s = "scissors" then ( out := 1 ) else (if m = "rock" & s = "paper" then ( out := 3 ) else (if s = "rock" & m = "paper" then ( out := 2 ) else skip ) ) ) else (if f = "paper" then ( if m = "rock" & s = "rock" then ( out := 1 ) else (if m = "paper" & s = "scissors" then ( out := 3 ) else (if s = "paper" & m = "scissors" then ( out := 2 ) else skip ) ) ) else (if f = "scissors" then ( if m = "paper" & s = "paper" then ( out := 1 ) else (if m = "scissors" & s = "rock" then ( out := 3 ) else (if s = "scissors" & m = "rock" then ( out := 2 ) else skip ) ) ) else skip ) ) ; if (out = 0) then ( execute ("?")->display() ) else (if out = 1 then ( execute ("F")->display() ) else (if out = 2 then ( execute ("M")->display() ) else ( execute ("S")->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import reduce def f(s): _res=s[1] a=[s[0],s[3],s[4]] if reduce(lambda x,y : x+y,list(map(lambda x : x % 2,a)))>1 and a[0]>0 and a[1]>0 and a[2]>0 : _res=_res+3 a=list(map(lambda x : x-1,a)) a=list(map(lambda x : x-x % 2,a)) _res=_res+a[0]+a[1]+a[2] return _res s=input().split(' ') print(f(list(map(lambda x : int(x),s)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; s := input().split(' ') ; execute (f(((s)->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ))))->display(); operation f(s : OclAny) : OclAny pre: true post: true activity: var _res : OclAny := s[1+1] ; var a : Sequence := Sequence{s->first()}->union(Sequence{s[3+1]}->union(Sequence{ s[4+1] })) ; if reduce(lambda x : OclAny, y : OclAny in (x + y), ((a)->collect( _x | (lambda x : OclAny in (x mod 2))->apply(_x) ))) > 1 & a->first() > 0 & a[1+1] > 0 & a[2+1] > 0 then ( _res := _res + 3 ; a := ((a)->collect( _x | (lambda x : OclAny in (x - 1))->apply(_x) )) ) else skip ; a := ((a)->collect( _x | (lambda x : OclAny in (x - x mod 2))->apply(_x) )) ; _res := _res + a->first() + a[1+1] + a[2+1] ; return _res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,Counter from itertools import product,groupby,count,permutations,combinations from math import pi,sqrt from collections import deque from bisect import bisect,bisect_left,bisect_right INF=float("inf") def ok(a,i,j,l,o): if a>min(i,j,l): return 0 i-=a j-=a l-=a return 6*a+(i//2)*4+(j//2)*4+(l//2)*4+o*2 def main(): i,o,t,j,l,s,z=map(int,input().split()) low,high,ans=-1,int(1e14)-1,0 while high-low>1 : middle=(low+high)//2 if ok(middle,i,j,l,o)>ans : ans=ok(middle,i,j,l,o) low=middle else : high=middle print(ans//2) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var INF : double := ("" + (("inf")))->toReal() ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation ok(a : OclAny, i : OclAny, j : OclAny, l : OclAny, o : OclAny) : OclAny pre: true post: true activity: if (a->compareTo(Set{i, j, l}->min())) > 0 then ( return 0 ) else skip ; i := i - a ; j := j - a ; l := l - a ; return 6 * a + (i div 2) * 4 + (j div 2) * 4 + (l div 2) * 4 + o * 2; operation main() pre: true post: true activity: var t : OclAny := null; var s : OclAny := null; var z : OclAny := null; Sequence{i,o,t,j,l,s,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var low : OclAny := null; var high : OclAny := null; var ans : OclAny := null; Sequence{low,high,ans} := Sequence{-1,("" + ((("1e14")->toReal())))->toInteger() - 1,0} ; while high - low > 1 do ( var middle : int := (low + high) div 2 ; if (ok(middle, i, j, l, o)->compareTo(ans)) > 0 then ( var ans : OclAny := ok(middle, i, j, l, o) ; var low : int := middle ) else ( var high : int := middle )) ; execute (ans div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def func(): base=["111111101010101111100101001111111","100000100000000001010110001000001","101110100110110000011010001011101","101110101011001001111101001011101","101110101100011000111100101011101","100000101010101011010000101000001","111111101010101010101010101111111","000000001111101111100111100000000","100010111100100001011110111111001","110111001111111100100001000101100","011100111010000101000111010001010","011110000110001111110101100000011","111111111111111000111001001011000","111000010111010011010011010100100","101010100010110010110101010000010","101100000101010001111101000000000","000010100011001101000111101011010","101001001111101111000101010001110","101101111111000100100001110001000","000010011000100110000011010000010","001101101001101110010010011011000","011101011010001000111101010100110","111010100110011101001101000001110","110001010010101111000101111111000","001000111011100001010110111110000","000000001110010110100010100010110","111111101000101111000110101011010","100000100111010101111100100011011","101110101001010000101000111111000","101110100011010010010111111011010","101110100100011011110110101110000","100000100110011001111100111100000","111111101101000101001101110010001"] x,y=map(int,input().strip().split()) print(base[x][y]) if __name__=='__main__' : func() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( func() ) else skip; operation func() pre: true post: true activity: var base : Sequence := Sequence{"111111101010101111100101001111111"}->union(Sequence{"100000100000000001010110001000001"}->union(Sequence{"101110100110110000011010001011101"}->union(Sequence{"101110101011001001111101001011101"}->union(Sequence{"101110101100011000111100101011101"}->union(Sequence{"100000101010101011010000101000001"}->union(Sequence{"111111101010101010101010101111111"}->union(Sequence{"000000001111101111100111100000000"}->union(Sequence{"100010111100100001011110111111001"}->union(Sequence{"110111001111111100100001000101100"}->union(Sequence{"011100111010000101000111010001010"}->union(Sequence{"011110000110001111110101100000011"}->union(Sequence{"111111111111111000111001001011000"}->union(Sequence{"111000010111010011010011010100100"}->union(Sequence{"101010100010110010110101010000010"}->union(Sequence{"101100000101010001111101000000000"}->union(Sequence{"000010100011001101000111101011010"}->union(Sequence{"101001001111101111000101010001110"}->union(Sequence{"101101111111000100100001110001000"}->union(Sequence{"000010011000100110000011010000010"}->union(Sequence{"001101101001101110010010011011000"}->union(Sequence{"011101011010001000111101010100110"}->union(Sequence{"111010100110011101001101000001110"}->union(Sequence{"110001010010101111000101111111000"}->union(Sequence{"001000111011100001010110111110000"}->union(Sequence{"000000001110010110100010100010110"}->union(Sequence{"111111101000101111000110101011010"}->union(Sequence{"100000100111010101111100100011011"}->union(Sequence{"101110101001010000101000111111000"}->union(Sequence{"101110100011010010010111111011010"}->union(Sequence{"101110100100011011110110101110000"}->union(Sequence{"100000100110011001111100111100000"}->union(Sequence{ "111111101101000101001101110010001" })))))))))))))))))))))))))))))))) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (base[x+1][y+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,q,c,d,w,f=map(int,input().split()) k=[b,b] k[0]+=(a-(a % 2)+c-(c % 2)+d-(d % 2)) if a % 2==1 and c % 2==1 and d % 2==1 : k[0]+=3 if a and c and d : a-=1 ; c-=1 ; d-=1 k[1]+=(3+a-(a % 2)+c-(c % 2)+d-(d % 2)) print(max(k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var q : OclAny := null; var c : OclAny := null; var d : OclAny := null; var w : OclAny := null; var f : OclAny := null; Sequence{a,b,q,c,d,w,f} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : Sequence := Sequence{b}->union(Sequence{ b }) ; k->first() := k->first() + (a - (a mod 2) + c - (c mod 2) + d - (d mod 2)) ; if a mod 2 = 1 & c mod 2 = 1 & d mod 2 = 1 then ( k->first() := k->first() + 3 ) else skip ; if a & c & d then ( a := a - 1; c := c - 1; d := d - 1 ; k[1+1] := k[1+1] + (3 + a - (a mod 2) + c - (c mod 2) + d - (d mod 2)) ) else skip ; execute ((k)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def greedy(J,L,I): ans=0 ans+=(J//2)*2 ans+=(L//2)*2 ans+=(I//2)*2 return ans def solve(I,O,T,J,L,S,Z): ans=O tmp1=greedy(J,L,I) if J*L*I>0 : tmp1=max(tmp1,3+greedy(J-1,L-1,I-1)) ans+=tmp1 return ans I,O,T,J,L,S,Z=map(int,input().split()) print(solve(I,O,T,J,L,S,Z)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{I,O,T,J,L,S,Z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (solve(I, O, T, J, L, S, Z))->display(); operation greedy(J : OclAny, L : OclAny, I : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; ans := ans + (J div 2) * 2 ; ans := ans + (L div 2) * 2 ; ans := ans + (I div 2) * 2 ; return ans; operation solve(I : OclAny, O : OclAny, T : OclAny, J : OclAny, L : OclAny, S : OclAny, Z : OclAny) : OclAny pre: true post: true activity: ans := O ; var tmp1 : OclAny := greedy(J, L, I) ; if J * L * I > 0 then ( tmp1 := Set{tmp1, 3 + greedy(J - 1, L - 1, I - 1)}->max() ) else skip ; ans := ans + tmp1 ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) n=int(input()) *P,=map(int,input().split()) memo={(n-1,i): i for i in range(P[-1]+1)} def dfs(pos,t): if(pos,t)in memo : return memo[pos,t] res=memo[pos,t]=dfs(pos+1,max(0,P[pos+1]-t))+t*2 return res print(min(dfs(0,P[0]-i)+i for i in range(P[0]+1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (testlist_star_expr (star_expr * (expr (atom (name P)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name P)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var memo : Map := Integer.subrange(0, P->last() + 1-1)->select(i | true)->collect(i | Map{Sequence{n - 1, i} |-> i})->unionAll() ; skip ; execute (((argument (test (logical_test (comparison (expr (expr (atom (name dfs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name P)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) - (expr (atom (name i))))))))) )))) + (expr (atom (name i))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name P)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) + (expr (atom (number (integer 1)))))))))) )))))))))->min())->display(); operation dfs(pos : OclAny, t : OclAny) : OclAny pre: true post: true activity: if (memo)->includes(Sequence{pos, t}) then ( return memo[pos+1][t+1] ) else skip ; var res : OclAny := dfs(pos + 1, Set{0, P[pos + 1+1] - t}->max()) + t * 2; var memo[pos+1][t+1] : OclAny := dfs(pos + 1, Set{0, P[pos + 1+1] - t}->max()) + t * 2 ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): from sys import stdin f_i=stdin N=int(f_i.readline()) P=list(map(int,f_i.readline().split())) left=P[0] ans=N*6 for i in range(left+1): tP=P[:] tP[0]-=i t_ans=i for j in range(N-1): tpj=tP[j] if tpj>0 : tP[j+1]-=tpj t_ans+=2*tpj if tP[-1]>0 : t_ans+=tP[-1] if t_anstoInteger() ; var P : Sequence := ((f_i.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var left : OclAny := P->first() ; var ans : int := N * 6 ; for i : Integer.subrange(0, left + 1-1) do ( var tP : Sequence := P ; tP->first() := tP->first() - i ; var t_ans : OclAny := i ; for j : Integer.subrange(0, N - 1-1) do ( var tpj : OclAny := tP[j+1] ; if tpj > 0 then ( tP[j + 1+1] := tP[j + 1+1] - tpj ; t_ans := t_ans + 2 * tpj ) else skip) ; if tP->last() > 0 then ( t_ans := t_ans + tP->last() ) else skip ; if (t_ans->compareTo(ans)) < 0 then ( ans := t_ans ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) pancake=list(map(int,input().split())) ans=10**9 for i in range(4): cnt=[0]*n cnt[0]+=i for j in range(n-1): diff=pancake[j]-cnt[j] if diff>0 : cnt[j]+=diff cnt[j+1]+=diff diff=pancake[n-1]-cnt[n-1] if diff>0 : cnt[n-1]+=diff if ans>sum(cnt): ans=sum(cnt) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var pancake : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : double := (10)->pow(9) ; for i : Integer.subrange(0, 4-1) do ( var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; cnt->first() := cnt->first() + i ; for j : Integer.subrange(0, n - 1-1) do ( var diff : double := pancake[j+1] - cnt[j+1] ; if diff > 0 then ( cnt[j+1] := cnt[j+1] + diff ; cnt[j + 1+1] := cnt[j + 1+1] + diff ) else skip) ; diff := pancake[n - 1+1] - cnt[n - 1+1] ; if diff > 0 then ( cnt[n - 1+1] := cnt[n - 1+1] + diff ) else skip ; if (ans->compareTo((cnt)->sum())) > 0 then ( ans := (cnt)->sum() ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def woodCollected(height,n,m): sum=0 for i in range(n-1,-1,-1): if(height[i]-m<=0): break sum+=(height[i]-m) return sum def collectKWood(height,n,k): height=sorted(height) low=0 high=height[n-1] while(low<=high): mid=low+((high-low)//2) collected=woodCollected(height,n,mid) if(collected==k): return mid if(collected>k): low=mid+1 else : high=mid-1 return-1 height=[1,2,1,2] n=len(height) k=2 print(collectKWood(height,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; height := Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{ 2 }))) ; n := (height)->size() ; k := 2 ; execute (collectKWood(height, n, k))->display(); operation woodCollected(height : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (height[i+1] - m <= 0) then ( break ) else skip ; sum := sum + (height[i+1] - m)) ; return sum; operation collectKWood(height : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: height := height->sort() ; var low : int := 0 ; var high : OclAny := height[n - 1+1] ; while ((low->compareTo(high)) <= 0) do ( var mid : int := low + ((high - low) div 2) ; var collected : OclAny := woodCollected(height, n, mid) ; if (collected = k) then ( return mid ) else skip ; if ((collected->compareTo(k)) > 0) then ( low := mid + 1 ) else ( high := mid - 1 )) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect def dfs(graph,root,A,res,lis): stack=[(root,)] while stack : state=stack[-1] del stack[-1] u=state[0] if res[u]==-1 : a=A[u] p=bisect.bisect_left(lis,a) if p==len(lis): stack.append((u,-1)) lis.append(a) else : stack.append((u,p,lis[p])) lis[p]=a res[u]=len(lis) for v in graph[u]: if res[v]==-1 : stack.append((v,)) else : p=state[1] if p>=0 : lis[p]=state[2] else : del lis[-1] n=int(input()) A=[int(x)for x in input().split()] graph=[[]for i in range(n)] for i in range(n-1): u,v=[int(x)-1 for x in input().split()] graph[u].append(v) graph[v].append(u) res=[-1]*n dfs(graph,0,A,res,[]) print(*res,sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; A := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; graph := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, n - 1-1) do ( var v : OclAny := null; Sequence{u,v} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)))))))) ))))) ; res := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; dfs(graph, 0, A, res, Sequence{}) ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display(); operation dfs(graph : OclAny, root : OclAny, A : OclAny, res : OclAny, lis : OclAny) pre: true post: true activity: var stack : Sequence := Sequence{ Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name root)))))) ,)} } ; while stack do ( var state : OclAny := stack->last() ; execute (stack->last())->isDeleted() ; var u : OclAny := state->first() ; if res[u+1] = -1 then ( var a : OclAny := A[u+1] ; var p : OclAny := bisect.bisect_left(lis, a) ; if p = (lis)->size() then ( execute ((Sequence{u, -1}) : stack) ; execute ((a) : lis) ) else ( execute ((Sequence{u, p, lis[p+1]}) : stack) ; lis[p+1] := a ) ; res[u+1] := (lis)->size() ; for v : graph[u+1] do ( if res[v+1] = -1 then ( execute ((Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name v)))))) ,)}) : stack) ) else skip) ) else ( p := state[1+1] ; if p >= 0 then ( lis[p+1] := state[2+1] ) else ( execute (lis->last())->isDeleted() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(1000000) from bisect import bisect,bisect_left def longest_subsequence(sequence): subsequence=[float("inf")for _ in range(len(sequence)+1)] subsequence[0]=float("-inf") for value in sequence : j=bisect(subsequence,value) if subsequence[j-1]!=value : subsequence[j]=value return bisect_left(dp,float("inf"))-1 def dfs(vertex): visited[vertex]=True value=a[vertex] j=bisect(subsequence,value) previous=subsequence[j] if subsequence[j-1]!=value : subsequence[j]=value ans[vertex]=bisect_left(subsequence,float("inf"))-1 for node in adjacent[vertex]: if not visited[node]: dfs(node) subsequence[j]=previous return n=int(input()) a=list(map(int,input().split())) adjacent={i :[]for i in range(n)} for _ in range(n-1): node1,node2=map(int,input().split()) node1-=1 node2-=1 adjacent[node1].append(node2) adjacent[node2].append(node1) visited=[False]*n ans=[0]*n subsequence=[float("inf")for _ in range(n+1)] subsequence[0]=float("-inf") dfs(0) [print(value)for value in ans] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(1000000) ; skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var adjacent : Map := Integer.subrange(0, n-1)->select(i | true)->collect(i | Map{i |-> Sequence{}})->unionAll() ; for _anon : Integer.subrange(0, n - 1-1) do ( var node1 : OclAny := null; var node2 : OclAny := null; Sequence{node1,node2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; node1 := node1 - 1 ; node2 := node2 - 1 ; (expr (atom (name adjacent)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name node1)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name node2)))))))) )))) ; (expr (atom (name adjacent)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name node2)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name node1)))))))) ))))) ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; subsequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (("" + (("inf")))->toReal())) ; subsequence->first() := ("" + (("-inf")))->toReal() ; dfs(0) ; ; operation longest_subsequence(sequence : OclAny) : OclAny pre: true post: true activity: var subsequence : Sequence := Integer.subrange(0, (sequence)->size() + 1-1)->select(_anon | true)->collect(_anon | (("" + (("inf")))->toReal())) ; subsequence->first() := ("" + (("-inf")))->toReal() ; for value : sequence do ( var j : OclAny := bisect(subsequence, value) ; if subsequence[j - 1+1] /= value then ( subsequence[j+1] := value ) else skip) ; return bisect_left(dp, ("" + (("inf")))->toReal()) - 1; operation dfs(vertex : OclAny) pre: true post: true activity: visited[vertex+1] := true ; var value : OclAny := a[vertex+1] ; j := bisect(subsequence, value) ; var previous : OclAny := subsequence[j+1] ; if subsequence[j - 1+1] /= value then ( subsequence[j+1] := value ) else skip ; ans[vertex+1] := bisect_left(subsequence, ("" + (("inf")))->toReal()) - 1 ; for node : adjacent[vertex+1] do ( if not(visited[node+1]) then ( dfs(node) ) else skip) ; subsequence[j+1] := previous ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- uncle_fyodor=input() matroskin=input() sharic=input() games=[uncle_fyodor,matroskin,sharic] stands_for=['F','M','S'] if games.count('scissors')==1 and games.count('paper')==2 : print(stands_for[games.index('scissors')]) elif games.count('paper')==1 and games.count('rock')==2 : print(stands_for[games.index('paper')]) elif games.count('rock')==1 and games.count('scissors')==2 : print(stands_for[games.index('rock')]) else : print('?') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var uncle_fyodor : String := (OclFile["System.in"]).readLine() ; var matroskin : String := (OclFile["System.in"]).readLine() ; var sharic : String := (OclFile["System.in"]).readLine() ; var games : Sequence := Sequence{uncle_fyodor}->union(Sequence{matroskin}->union(Sequence{ sharic })) ; var stands_for : Sequence := Sequence{'F'}->union(Sequence{'M'}->union(Sequence{ 'S' })) ; if games->count('scissors') = 1 & games->count('paper') = 2 then ( execute (stands_for[games->indexOf('scissors') - 1+1])->display() ) else (if games->count('paper') = 1 & games->count('rock') = 2 then ( execute (stands_for[games->indexOf('paper') - 1+1])->display() ) else (if games->count('rock') = 1 & games->count('scissors') = 2 then ( execute (stands_for[games->indexOf('rock') - 1+1])->display() ) else ( execute ('?')->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect I=[int(_)for _ in open(0).read().split()] N=I[0] A=[0]+I[1 : 1+N] U=[0]+I[1+N : : 2] V=[1]+I[2+N : : 2] G=[set()for _ in range(N+1)] for u,v in zip(U,V): G[u].add(v) G[v].add(u) ans=[10**10]*(N+1) stack=[(0,1,1,A[1],0)] dp=[-10**10]+[10**10]*N while stack : i,j,p,q,d=stack.pop() if d : dp[p]=q continue stack+=[(j,i,p,dp[p],1)] dp[p]=q ans[j]=bisect.bisect_left(dp,10**10)-1 while G[j]: k=G[j].pop() if i==k : continue q=A[k] p=bisect.bisect_left(dp,q) stack+=[(j,k,p,q,0)] print(*ans[1 :],sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var I : Sequence := open(0).readAll().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var N : OclAny := I->first() ; var A : Sequence := Sequence{ 0 }->union(I.subrange(1+1, 1 + N)) ; var U : Sequence := Sequence{ 0 }->union(I(subscript (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) + (expr (atom (name N))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) ; var V : Sequence := Sequence{ 1 }->union(I(subscript (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) + (expr (atom (name N))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) ; var G : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; for _tuple : Integer.subrange(1, U->size())->collect( _indx | Sequence{U->at(_indx), V->at(_indx)} ) do (var _indx : int := 1; var u : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)))))))) ))))) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ (10)->pow(10) }, (N + 1)) ; var stack : Sequence := Sequence{ Sequence{0, 1, 1, A[1+1], 0} } ; var dp : Sequence := Sequence{ (-10)->pow(10) }->union(MatrixLib.elementwiseMult(Sequence{ (10)->pow(10) }, N)) ; while stack do ( var i : OclAny := null; var j : OclAny := null; var p : OclAny := null; var q : OclAny := null; var d : OclAny := null; Sequence{i,j,p,q,d} := stack->last() ; stack := stack->front() ; if d then ( dp[p+1] := q ; continue ) else skip ; stack := stack + Sequence{ Sequence{j, i, p, dp[p+1], 1} } ; dp[p+1] := q ; ans[j+1] := bisect.bisect_left(dp, (10)->pow(10)) - 1 ; while G[j+1] do ( var k : OclAny := G[j+1]->last() ; if i = k then ( continue ) else skip ; var q : OclAny := A[k+1] ; var p : OclAny := bisect.bisect_left(dp, q) ; stack := stack + Sequence{ Sequence{j, k, p, q, 0} })) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=map(int,input().split()) a=['111111101010101111100101001111111','100000100000000001010110001000001','101110100110110000011010001011101','101110101011001001111101001011101','101110101100011000111100101011101','100000101010101011010000101000001','111111101010101010101010101111111','000000001111101111100111100000000','100010111100100001011110111111001','110111001111111100100001000101100','011100111010000101000111010001010','011110000110001111110101100000011','111111111111111000111001001011000','111000010111010011010011010100100','101010100010110010110101010000010','101100000101010001111101000000000','000010100011001101000111101011010','101001001111101111000101010001110','101101111111000100100001110001000','000010011000100110000011010000010','001101101001101110010010011011000','011101011010001000111101010100110','111010100110011101001101000001110','110001010010101111000101111111000','001000111011100001010110111110000','000000001110010110100010100010110','111111101000101111000110101011010','100000100111010101111100100011011','101110101001010000101000111111000','101110100011010010010111111011010','101110100100011011110110101110000','100000100110011001111100111100000','111111101101000101001101110010001'] print(a[x][y]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{'111111101010101111100101001111111'}->union(Sequence{'100000100000000001010110001000001'}->union(Sequence{'101110100110110000011010001011101'}->union(Sequence{'101110101011001001111101001011101'}->union(Sequence{'101110101100011000111100101011101'}->union(Sequence{'100000101010101011010000101000001'}->union(Sequence{'111111101010101010101010101111111'}->union(Sequence{'000000001111101111100111100000000'}->union(Sequence{'100010111100100001011110111111001'}->union(Sequence{'110111001111111100100001000101100'}->union(Sequence{'011100111010000101000111010001010'}->union(Sequence{'011110000110001111110101100000011'}->union(Sequence{'111111111111111000111001001011000'}->union(Sequence{'111000010111010011010011010100100'}->union(Sequence{'101010100010110010110101010000010'}->union(Sequence{'101100000101010001111101000000000'}->union(Sequence{'000010100011001101000111101011010'}->union(Sequence{'101001001111101111000101010001110'}->union(Sequence{'101101111111000100100001110001000'}->union(Sequence{'000010011000100110000011010000010'}->union(Sequence{'001101101001101110010010011011000'}->union(Sequence{'011101011010001000111101010100110'}->union(Sequence{'111010100110011101001101000001110'}->union(Sequence{'110001010010101111000101111111000'}->union(Sequence{'001000111011100001010110111110000'}->union(Sequence{'000000001110010110100010100010110'}->union(Sequence{'111111101000101111000110101011010'}->union(Sequence{'100000100111010101111100100011011'}->union(Sequence{'101110101001010000101000111111000'}->union(Sequence{'101110100011010010010111111011010'}->union(Sequence{'101110100100011011110110101110000'}->union(Sequence{'100000100110011001111100111100000'}->union(Sequence{ '111111101101000101001101110010001' })))))))))))))))))))))))))))))))) ; execute (a[x+1][y+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque import bisect import sys sys.setrecursionlimit(10**7) N=int(input()) V=list(map(int,input().split())) V.insert(0,0) visited=[False for i in range(N+1)] inf=10**18 dp=[inf for i in range(N+1)] ans=[-1 for i in range(N+1)] stack=deque() G=[[]for i in range(N+1)] for _ in range(N-1): u,v=map(int,input().split()) G[u].append(v) G[v].append(u) def dfs(s_node): visited[s_node]=True value=V[s_node] index=bisect.bisect_left(dp,value) old_value=dp[index] dp[index]=value ans[s_node]=bisect.bisect_right(dp,inf-1) stack.append((index,old_value,value)) for child in G[s_node]: if visited[child]==False : dfs(child) index,old_value,value=stack.pop() dp[index]=old_value dfs(1) for i in range(1,N+1): print(ans[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var V : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; V := V.insertAt(0+1, 0) ; var visited : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (false)) ; var Math_PINFINITY : double := (10)->pow(18) ; var dp : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (Math_PINFINITY)) ; var ans : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (-1)) ; var stack : Sequence := () ; var G : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (Sequence{})) ; for _anon : Integer.subrange(0, N - 1-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)))))))) ))))) ; skip ; dfs(1) ; for i : Integer.subrange(1, N + 1-1) do ( execute (ans[i+1])->display()); operation dfs(s_node : OclAny) pre: true post: true activity: visited[s_node+1] := true ; var value : OclAny := V[s_node+1] ; var index : OclAny := bisect.bisect_left(dp, value) ; var old_value : OclAny := dp[index+1] ; dp[index+1] := value ; ans[s_node+1] := bisect.bisect_right(dp, Math_PINFINITY - 1) ; execute ((Sequence{index, old_value, value}) : stack) ; for child : G[s_node+1] do ( if visited[child+1] = false then ( dfs(child) ) else skip) ; Sequence{index,old_value,value} := stack->last() ; stack := stack->front() ; dp[index+1] := old_value; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from bisect import bisect_left,bisect_right sys.setrecursionlimit(2*10**5) def input(): return sys.stdin.readline().strip() def main(): N=int(input()) A=list(map(int,input().split())) repn=[[]for _ in range(N)] for _ in range(N-1): u,v=map(int,input().split()) repn[u-1].append(v-1) repn[v-1].append(u-1) length=[0]*(N+1) dp=[-1] def dfs(v,p=N): if A[v]>dp[-1]: dp.append(A[v]) length[v]=length[p]+1 for u in repn[v]: if u==p : continue dfs(u,v) dp.pop() else : length[v]=length[p] idx=bisect_left(dp,A[v]) old=dp[idx] dp[idx]=A[v] for u in repn[v]: if u==p : continue dfs(u,v) dp[idx]=old dfs(0) length.pop() for ans in length : print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit(2 * (10)->pow(5)) ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var repn : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, N - 1-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name repn)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name u))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name repn)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name u))) - (expr (atom (number (integer 1)))))))))) ))))) ; var length : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; var dp : Sequence := Sequence{ -1 } ; skip ; dfs(0) ; length := length->front() ; for ans : length do ( execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMinOperations(S): S=S[: :-1] n=len(S) dp=[[0]*2]*(n+1) if(S[0]=='0'): dp[0][0]=0 else : dp[0][0]=1 dp[0][1]=1 for i in range(1,n): if(S[i]=='0'): dp[i][0]=dp[i-1][0] dp[i][1]=1+min(dp[i-1][1],dp[i-1][0]) else : dp[i][1]=dp[i-1][1]; dp[i][0]=1+min(dp[i-1][0],dp[i-1][1]) return dp[n-1][0] if __name__=="__main__" : S="100" print(findMinOperations(S)) S="111" ; print(findMinOperations(S)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( S := "100" ; execute (findMinOperations(S))->display() ; S := "111"; ; execute (findMinOperations(S))->display() ) else skip; operation findMinOperations(S : OclAny) : OclAny pre: true post: true activity: S := S(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var n : int := (S)->size() ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ MatrixLib.elementwiseMult(Sequence{ 0 }, 2) }, (n + 1)) ; if (S->first() = '0') then ( dp->first()->first() := 0 ) else ( dp->first()->first() := 1 ) ; dp->first()[1+1] := 1 ; for i : Integer.subrange(1, n-1) do ( if (S[i+1] = '0') then ( dp[i+1]->first() := dp[i - 1+1]->first() ; dp[i+1][1+1] := 1 + Set{dp[i - 1+1][1+1], dp[i - 1+1]->first()}->min() ) else ( dp[i+1][1+1] := dp[i - 1+1][1+1]; ; dp[i+1]->first() := 1 + Set{dp[i - 1+1]->first(), dp[i - 1+1][1+1]}->min() )) ; return dp[n - 1+1]->first(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countNumbers(n): if n % 2==1 : return 0 return(9*pow(10,n//2-1)) if __name__=="__main__" : n=2 print(countNumbers(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 2 ; execute (countNumbers(n))->display() ) else skip; operation countNumbers(n : OclAny) : OclAny pre: true post: true activity: if n mod 2 = 1 then ( return 0 ) else skip ; return (9 * (10)->pow(n div 2 - 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def stopping_station(p,n): num=1 dem=1 s=p while p!=1 : dem*=p p-=1 t=n-s+1 while t!=(n-2*s+1): num*=t t-=1 if(n-s+1)>=s : return int(num/dem) else : return-1 num=stopping_station(4,12) if num!=-1 : print(num) else : print("Not Possible") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; num := stopping_station(4, 12) ; if num /= -1 then ( execute (num)->display() ) else ( execute ("Not Possible")->display() ); operation stopping_station(p : OclAny, n : OclAny) : OclAny pre: true post: true activity: var num : int := 1 ; var dem : int := 1 ; var s : OclAny := p ; while p /= 1 do ( dem := dem * p ; p := p - 1) ; var t : double := n - s + 1 ; while t /= (n - 2 * s + 1) do ( num := num * t ; t := t - 1) ; if ((n - s + 1)->compareTo(s)) >= 0 then ( return ("" + ((num / dem)))->toInteger() ) else ( return -1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) res=[] for i in range(k): res.append(n-i) for j in range(1,n-k+1): res.append(j) print(*res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var res : Sequence := Sequence{} ; for i : Integer.subrange(0, k-1) do ( execute ((n - i) : res)) ; for j : Integer.subrange(1, n - k + 1-1) do ( execute ((j) : res)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import Counter,defaultdict,deque from heapq import heapify,heappush,heappop from functools import lru_cache from math import floor,ceil,sqrt,gcd from string import ascii_lowercase from math import gcd from bisect import bisect_left,bisect,bisect_right def read(): return input().strip() def read_int(): return int(read()) def read_str_list(): return read().split() def read_numeric_list(): return list(map(int,read_str_list())) def solve(N,K): res=[] for i in range(K): res.append(N-i) for i in range(1,N-K+1): res.append(i) return " ".join(map(str,res)) N,K=read_numeric_list() print(solve(N,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; Sequence{N,K} := read_numeric_list() ; execute (solve(N, K))->display(); operation read() : OclAny pre: true post: true activity: return input()->trim(); operation read_int() : OclAny pre: true post: true activity: return ("" + ((read())))->toInteger(); operation read_str_list() : OclAny pre: true post: true activity: return read().split(); operation read_numeric_list() : OclAny pre: true post: true activity: return ((read_str_list())->collect( _x | (OclType["int"])->apply(_x) )); operation solve(N : OclAny, K : OclAny) : OclAny pre: true post: true activity: var res : Sequence := Sequence{} ; for i : Integer.subrange(0, K-1) do ( execute ((N - i) : res)) ; for i : Integer.subrange(1, N - K + 1-1) do ( execute ((i) : res)) ; return StringLib.sumStringsWithSeparator(((res)->collect( _x | (OclType["String"])->apply(_x) )), " "); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def miis(): return map(int,input().split()) n,k=miis() for i in range(k): print(n-i,end=' ') for i in range(n-k): print(i+1,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := miis() ; for i : Integer.subrange(0, k-1) do ( execute (n - i)->display()) ; for i : Integer.subrange(0, n - k-1) do ( execute (i + 1)->display()); operation miis() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt from collections import defaultdict,deque from posixpath import split import sys from bisect import bisect_right as b_r from bisect import bisect_left as b_l mod=1000000007 INT_MAX=sys.maxsize-1 INT_MIN=-sys.maxsize def solve(): n,k=map(int,input().split()) for i in range(k): print(n-i,end=" ") for i in range(1,n-k+1): print(i,end=" ") print() if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var mod : int := 1000000007 ; var INT_MAX : double := (trailer . (name maxsize)) - 1 ; var INT_MIN : (trailer . (name maxsize)) := -(trailer . (name maxsize)) ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation solve() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, k-1) do ( execute (n - i)->display()) ; for i : Integer.subrange(1, n - k + 1-1) do ( execute (i)->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[input()for _ in[0]*3] d=dict(zip('rsp','spr')) r='FMS' for i in range(3): if sum(x[0]==d[a[i][0]]for x in a)==2 : print(r[i]) exit() print('?') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 3)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var d : Map := ((expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'rsp')))))) , (argument (test (logical_test (comparison (expr (atom 'spr'))))))) ))))) ; var r : String := 'FMS' ; for i : Integer.subrange(0, 3-1) do ( if ((argument (test (logical_test (comparison (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) == (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ]))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a))))))))->sum() = 2 then ( execute (r[i+1])->display() ; exit() ) else skip) ; execute ('?')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=input() if a[0]==b[2]and a[1]==b[1]and a[2]==b[0]: print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; if a->first() = b[2+1] & a[1+1] = b[1+1] & a[2+1] = b->first() then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import count for _ in range(int(input())): n=int(input()) count=0 start=0 for i in range(1,10): start=i while(start<=n): count+=1 start=start*10+i print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := 0 ; var start : int := 0 ; for i : Integer.subrange(1, 10-1) do ( start := i ; while ((start->compareTo(n)) <= 0) do ( count := count + 1 ; start := start * 10 + i)) ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def haversine(lat1,lon1,lat2,lon2): dLat=(lat2-lat1)*math.pi/180.0 dLon=(lon2-lon1)*math.pi/180.0 lat1=(lat1)*math.pi/180.0 lat2=(lat2)*math.pi/180.0 a=(pow(math.sin(dLat/2),2)+pow(math.sin(dLon/2),2)*math.cos(lat1)*math.cos(lat2)); rad=6371 c=2*math.asin(math.sqrt(a)) return rad*c if __name__=="__main__" : lat1=51.5007 lon1=0.1246 lat2=40.6892 lon2=74.0445 print(haversine(lat1,lon1,lat2,lon2),"K.M.") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( lat1 := 51.5007 ; lon1 := 0.1246 ; lat2 := 40.6892 ; lon2 := 74.0445 ; execute (haversine(lat1, lon1, lat2, lon2))->display() ) else skip; operation haversine(lat1 : OclAny, lon1 : OclAny, lat2 : OclAny, lon2 : OclAny) : OclAny pre: true post: true activity: var dLat : double := (lat2 - lat1) * / 180.0 ; var dLon : double := (lon2 - lon1) * / 180.0 ; lat1 := (lat1) * / 180.0 ; lat2 := (lat2) * / 180.0 ; var a : double := (((dLat / 2)->sin())->pow(2) + ((dLon / 2)->sin())->pow(2) * * ); ; var rad : int := 6371 ; var c : double := 2 * ((a)->sqrt())->asin() ; return rad * c; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- M,K=map(int,input().split()) ans=[] for i in range(pow(2,M)): if i!=K : ans.append(str(i)) ans1=ans+[str(K)]+ans[: :-1]+[str(K)] if K==0 : ans1=[] for i in range(pow(2,M)): ans1+=[str(i)]*2 if K>=pow(2,M): print(-1) elif K==M==1 : print(-1) else : print(' '.join(ans1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var M : OclAny := null; var K : OclAny := null; Sequence{M,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, (2)->pow(M)-1) do ( if i /= K then ( execute ((("" + ((i)))) : ans) ) else skip) ; var ans1 : Sequence := ans->union(Sequence{ ("" + ((K))) })->union(ans(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->union(Sequence{ ("" + ((K))) }) ; if K = 0 then ( ans1 := Sequence{} ; for i : Integer.subrange(0, (2)->pow(M)-1) do ( ans1 := ans1 + MatrixLib.elementwiseMult(Sequence{ ("" + ((i))) }, 2)) ) else skip ; if (K->compareTo((2)->pow(M))) >= 0 then ( execute (-1)->display() ) else (if K = M & (M == 1) then ( execute (-1)->display() ) else ( execute (StringLib.sumStringsWithSeparator((ans1), ' '))->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import chain m,k=map(int,input().split()) if k==0 : print(" ".join([str(i)for i in chain(range(0,2**m),range(2**m-1,-1,-1))])) elif 0collect( _x | (OclType["int"])->apply(_x) ) ; if k = 0 then ( execute (StringLib.sumStringsWithSeparator((chain(Integer.subrange(0, (2)->pow(m)-1), Integer.subrange(-1 + 1, (2)->pow(m) - 1)->reverse())->select(i | true)->collect(i | (("" + ((i)))))), " "))->display() ) else (if 0 < k & (k < (2)->pow(m)) then ( var s : int := 0 ; for i : Integer.subrange(0, (2)->pow(m)-1) do ( if i /= k then ( s := s xor i ) else skip) ; if s = k then ( execute (StringLib.sumStringsWithSeparator((chain(Integer.subrange(0, k-1), Integer.subrange(k + 1, (2)->pow(m)-1), Sequence{ k }, Integer.subrange(k + 1, (2)->pow(m) - 1)->reverse(), Integer.subrange(-1 + 1, k - 1)->reverse(), Sequence{ k })->select(i | true)->collect(i | (("" + ((i)))))), " "))->display() ) else ( execute (-1)->display() ) ) else ( execute (-1)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(m,k): if m==0 : if k==0 : return[0,0] return[-1] if m==1 : if k==0 : return[0,0,1,1] return[-1] if k>2**m-1 : return[-1] n=2**m if k==0 : Ret=[] for i in range(n): Ret.append(i); Ret.append(i) return Ret Used=[False]*n Used[0]=True ; Used[k]=True Pair=[] for i in range(1,n): if Used[i]: continue Pair.append([i,k ^ i]) Used[i]=True ; Used[k ^ i]=True A=[] for a,b in Pair : A.append(a); A.append(b) Ret=A+[0,k,0]+A[: :-1]+[k] return Ret m,k=map(int,input().split()) Ans=solve(m,k) print(*Ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var Ans : OclAny := solve(m, k) ; execute ((argument * (test (logical_test (comparison (expr (atom (name Ans))))))))->display(); operation solve(m : OclAny, k : OclAny) : OclAny pre: true post: true activity: if m = 0 then ( if k = 0 then ( return Sequence{0}->union(Sequence{ 0 }) ) else skip ; return Sequence{ -1 } ) else skip ; if m = 1 then ( if k = 0 then ( return Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 1 }))) ) else skip ; return Sequence{ -1 } ) else skip ; if (k->compareTo((2)->pow(m) - 1)) > 0 then ( return Sequence{ -1 } ) else skip ; var n : double := (2)->pow(m) ; if k = 0 then ( var Ret : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((i) : Ret); execute ((i) : Ret)) ; return Ret ) else skip ; var Used : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ; Used->first() := true; Used[k+1] := true ; var Pair : Sequence := Sequence{} ; for i : Integer.subrange(1, n-1) do ( if Used[i+1] then ( continue ) else skip ; execute ((Sequence{i}->union(Sequence{ MathLib.bitwiseXor(k, i) })) : Pair) ; Used[i+1] := true; Used[MathLib.bitwiseXor(k, i)+1] := true) ; var A : Sequence := Sequence{} ; for _tuple : Pair do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); execute ((a) : A); execute ((b) : A)) ; Ret := A->union(Sequence{0}->union(Sequence{k}->union(Sequence{ 0 })))->union(A(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->union(Sequence{ k }) ; return Ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda : sys.stdin.readline().rstrip() YesNo=lambda b : bool([print('Yes')]if b else print('No')) YESNO=lambda b : bool([print('YES')]if b else print('NO')) int1=lambda x : int(x)-1 def main(): M,K=map(int,input().split()) if K>2**M-1 : print(-1) elif M==1 : if K==0 : print(0,0,1,1) else : print(-1) else : ans=[i for i in range(2**M)if i!=K]+[K]+[i for i in range(2**M-1,-1,-1)if i!=K]+[K] print(*ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var YesNo : Function := lambda b : OclAny in ((if b then Sequence{ ('Yes')->display() } else ('No')->display() endif)->toBoolean()) ; var YESNO : Function := lambda b : OclAny in ((if b then Sequence{ ('YES')->display() } else ('NO')->display() endif)->toBoolean()) ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var M : OclAny := null; var K : OclAny := null; Sequence{M,K} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (K->compareTo((2)->pow(M) - 1)) > 0 then ( execute (-1)->display() ) else (if M = 1 then ( if K = 0 then ( execute (0)->display() ) else ( execute (-1)->display() ) ) else ( var ans : Sequence := Integer.subrange(0, (2)->pow(M)-1)->select(i | i /= K)->collect(i | (i))->union(Sequence{ K })->union(Integer.subrange(-1 + 1, (2)->pow(M) - 1)->reverse()->select(i | i /= K)->collect(i | (i)))->union(Sequence{ K }) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush,heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod=10**9+7 inf=float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) m,k=LI() if k>=2**m : print(-1) quit() if m==0 : if k==0 : print(0,0) else : print(-1) elif m==1 : if k==0 : ans=[i for i in range(2**(m+1))] ans=[i//2 for i in ans] print(*ans) else : print(-1) else : ans=[i for i in range(2**m)if i!=k] ans=ans+[k]+ans[: :-1]+[k] print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; sys.setrecursionlimit(2147483647) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; skip ; skip ; var m : OclAny := null; var k : OclAny := null; Sequence{m,k} := LI() ; if (k->compareTo((2)->pow(m))) >= 0 then ( execute (-1)->display() ; quit() ) else skip ; if m = 0 then ( if k = 0 then ( execute (0)->display() ) else ( execute (-1)->display() ) ) else (if m = 1 then ( if k = 0 then ( var ans : Sequence := Integer.subrange(0, (2)->pow((m + 1))-1)->select(i | true)->collect(i | (i)) ; ans := ans->select(i | true)->collect(i | (i div 2)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ) else ( execute (-1)->display() ) ) else ( ans := Integer.subrange(0, (2)->pow(m)-1)->select(i | i /= k)->collect(i | (i)) ; ans := ans->union(Sequence{ k })->union(ans(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->union(Sequence{ k }) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ) ) ; operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CamelCase(words,pattern): map=dict.fromkeys(words,None); for i in range(len(words)): string="" ; l=len(words[i]); for j in range(l): if(words[i][j]>='A' and words[i][j]<='Z'): string+=words[i][j]; if string not in map : map[string]=[words[i]] elif map[string]is None : map[string]=[words[i]] else : map[string].append(words[i]); wordFound=False ; for key,value in map.items(): if(key==pattern): wordFound=True ; for itt in value : print(itt); if(not wordFound): print("No match found"); if __name__=="__main__" : words=["Hi","Hello","HelloWorld","HiTech","HiGeek","HiTechWorld","HiTechCity","HiTechLab"]; pattern="HT" ; CamelCase(words,pattern); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( words := Sequence{"Hi"}->union(Sequence{"Hello"}->union(Sequence{"HelloWorld"}->union(Sequence{"HiTech"}->union(Sequence{"HiGeek"}->union(Sequence{"HiTechWorld"}->union(Sequence{"HiTechCity"}->union(Sequence{ "HiTechLab" }))))))); ; pattern := "HT"; ; CamelCase(words, pattern); ) else skip; operation CamelCase(words : OclAny, pattern : OclAny) pre: true post: true activity: var map : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name words))))))) , (argument (test (logical_test (comparison (expr (atom None))))))) ))); ; for i : Integer.subrange(0, (words)->size()-1) do ( var string : String := ""; ; var l : int := (words[i+1])->size(); ; for j : Integer.subrange(0, l-1) do ( if (words[i+1][j+1] >= 'A' & words[i+1][j+1] <= 'Z') then ( string := string + words[i+1][j+1]; ; if (map)->excludes(string) then ( (->at(string)`third)->collect( _x | (->at(string))->apply(_x) ) := Sequence{ words[i+1] } ) else (if (->at(string)`third)->collect( _x | (->at(string))->apply(_x) ) <>= null then ( (->at(string)`third)->collect( _x | (->at(string))->apply(_x) ) := Sequence{ words[i+1] } ) else ( (expr (atom (name map)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name string)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name words)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))); ) ) ) else skip)) ; var wordFound : boolean := false; ; for _tuple : ((trailer . (name items) (arguments ( ))))->collect( _x | ((trailer . (name items) (arguments ( ))))->apply(_x) ) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); if (key = pattern) then ( wordFound := true; ; for itt : value do ( execute (itt)->display();) ) else skip) ; if (not(wordFound)) then ( execute ("No match found")->display(); ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def summation(n): sum=0 ; for i in range(1,n+1): if(i % 2==1): sum+=(i*i); else : sum-=(i*i); return sum ; if __name__=="__main__" : N=2 ; print(summation(N)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var N : int := 2; ; execute (summation(N))->display(); ) else skip; operation summation(n : OclAny) pre: true post: true activity: var sum : int := 0; ; for i : Integer.subrange(1, n + 1-1) do ( if (i mod 2 = 1) then ( sum := sum + (i * i); ) else ( sum := sum - (i * i); )) ; return sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math one=[[0 for x in range(32)]for y in range(100001)] MAX=2147483647 def make_prefix(A,n): global one,MAX for j in range(0,32): one[0][j]=0 for i in range(1,n+1): a=A[i-1] for j in range(0,32): x=int(math.pow(2,j)) if(a & x): one[i][j]=1+one[i-1][j] else : one[i][j]=one[i-1][j] def Solve(L,R): global one,MAX l=L r=R tot_bits=r-l+1 X=MAX for i in range(0,31): x=one[r][i]-one[l-1][i] if(x>=(tot_bits-x)): ith_bit=pow(2,i) X=X ^ ith_bit return X n=5 q=3 A=[210,11,48,22,133] L=[1,4,2] R=[3,14,4] make_prefix(A,n) for j in range(0,q): print(Solve(L[j],R[j]),end="\n") ------------------------------------------------------------ OCL File: --------- class FromPython { attribute one : OclAny; attribute MAX : OclAny; attribute one : OclAny; attribute MAX : OclAny; operation initialise() pre: true post: true activity: skip ; var one : Sequence := Integer.subrange(0, 100001-1)->select(y | true)->collect(y | (Integer.subrange(0, 32-1)->select(x | true)->collect(x | (0)))) ; var MAX : int := 2147483647 ; skip ; skip ; n := 5 ; var q : int := 3 ; A := Sequence{210}->union(Sequence{11}->union(Sequence{48}->union(Sequence{22}->union(Sequence{ 133 })))) ; L := Sequence{1}->union(Sequence{4}->union(Sequence{ 2 })) ; R := Sequence{3}->union(Sequence{14}->union(Sequence{ 4 })) ; make_prefix(A, n) ; for j : Integer.subrange(0, q-1) do ( execute (Solve(L[j+1], R[j+1]))->display()); operation make_prefix(A : OclAny, n : OclAny) pre: true post: true activity: skip; skip ; for j : Integer.subrange(0, 32-1) do ( one->first()[j+1] := 0) ; for i : Integer.subrange(1, n + 1-1) do ( var a : OclAny := A[i - 1+1] ; for j : Integer.subrange(0, 32-1) do ( var x : int := ("" + (((2)->pow(j))))->toInteger() ; if (MathLib.bitwiseAnd(a, x)) then ( one[i+1][j+1] := 1 + one[i - 1+1][j+1] ) else ( one[i+1][j+1] := one[i - 1+1][j+1] ))); operation Solve(L : OclAny, R : OclAny) : OclAny pre: true post: true activity: skip; skip ; var l : OclAny := L ; var r : OclAny := R ; var tot_bits : double := r - l + 1 ; var X : int := MAX ; for i : Integer.subrange(0, 31-1) do ( x := one[r+1][i+1] - one[l - 1+1][i+1] ; if ((x->compareTo((tot_bits - x))) >= 0) then ( var ith_bit : double := (2)->pow(i) ; X := MathLib.bitwiseXor(X, ith_bit) ) else skip) ; return X; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printArray(arr,n): for i in range(n): print(arr[i],end=" ") def printMaxMean(arr,n): newArr=[0]*n arr.sort() for i in range(n): newArr[i]=arr[i+n] printArray(newArr,n) if __name__=="__main__" : arr=[4,8,3,1,3,7,0,4] n=len(arr) printMaxMean(arr,n//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{4}->union(Sequence{8}->union(Sequence{3}->union(Sequence{1}->union(Sequence{3}->union(Sequence{7}->union(Sequence{0}->union(Sequence{ 4 }))))))) ; n := (arr)->size() ; printMaxMean(arr, n div 2) ) else skip; operation printArray(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); operation printMaxMean(arr : OclAny, n : OclAny) pre: true post: true activity: var newArr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; arr := arr->sort() ; for i : Integer.subrange(0, n-1) do ( newArr[i+1] := arr[i + n+1]) ; printArray(newArr, n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) s=[pow(10,i)for i in range(1,10)] for i in range(t): n=int(input()) ans=0 start=0 for k in range(1,10): start=k while start<=n : ans+=1 start=start*10+k print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := Integer.subrange(1, 10-1)->select(i | true)->collect(i | ((10)->pow(i))) ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; var start : int := 0 ; for k : Integer.subrange(1, 10-1) do ( start := k ; while (start->compareTo(n)) <= 0 do ( ans := ans + 1 ; start := start * 10 + k)) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- prob=[] dp=[[]] def func(cur,rem): if cur<0 : if rem>0 or rem<0 : return 0.0 else : return 1.0 if rem<0 : return 0.0 if dp[cur][rem]<0 : dp[cur][rem]=func(cur-1,rem-1)*(1-prob[cur]) dp[cur][rem]+=func(cur-1,rem)*prob[cur] return dp[cur][rem] t=input() for tcase in range(1,t+1): n,k=map(int,raw_input().split()) ar=[float(x)for x in raw_input().split()] ar.sort() res=0.0 for i in range(n): prob=[] for j in range(i,n): prob.append(ar[j]) for j in range(i): prob.append(ar[j]) dp=[[-1 for i1 in range(n+1)]for j1 in range(n+1)] res=max(res,func(k-1,k/2)) print("Case #%d: %0.9lf" %(tcase,res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var prob : Sequence := Sequence{} ; var dp : Sequence := Sequence{ Sequence{} } ; skip ; var t : String := (OclFile["System.in"]).readLine() ; for tcase : Integer.subrange(1, t + 1-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ar : Sequence := raw_input().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())) ; ar := ar->sort() ; var res : double := 0.0 ; for i : Integer.subrange(0, n-1) do ( prob := Sequence{} ; for j : Integer.subrange(i, n-1) do ( execute ((ar[j+1]) : prob)) ; for j : Integer.subrange(0, i-1) do ( execute ((ar[j+1]) : prob)) ; dp := Integer.subrange(0, n + 1-1)->select(j1 | true)->collect(j1 | (Integer.subrange(0, n + 1-1)->select(i1 | true)->collect(i1 | (-1)))) ; res := Set{res, func(k - 1, k / 2)}->max()) ; execute (StringLib.format("Case #%d: %0.9lf",Sequence{tcase, res}))->display()); operation func(cur : OclAny, rem : OclAny) : OclAny pre: true post: true activity: if cur < 0 then ( if rem > 0 or rem < 0 then ( return 0.0 ) else ( return 1.0 ) ) else skip ; if rem < 0 then ( return 0.0 ) else skip ; if dp[cur+1][rem+1] < 0 then ( dp[cur+1][rem+1] := func(cur - 1, rem - 1) * (1 - prob[cur+1]) ; dp[cur+1][rem+1] := dp[cur+1][rem+1] + func(cur - 1, rem) * prob[cur+1] ) else skip ; return dp[cur+1][rem+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,input().split()) S=list(input()) S[K-1]=S[K-1].lower() print("".join(S)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : Sequence := ((OclFile["System.in"]).readLine())->characters() ; S[K - 1+1] := S[K - 1+1]->toLowerCase() ; execute (StringLib.sumStringsWithSeparator((S), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[input()for _ in[0]*3] d=dict(zip('rsp','spr')) r='FMS' for i in range(3): if sum(x[0]==d[a[i][0]]for x in a)==2 : print(r[i]) exit() print('?') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 3)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var d : Map := ((expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'rsp')))))) , (argument (test (logical_test (comparison (expr (atom 'spr'))))))) ))))) ; var r : String := 'FMS' ; for i : Integer.subrange(0, 3-1) do ( if ((argument (test (logical_test (comparison (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) == (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ]))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a))))))))->sum() = 2 then ( execute (r[i+1])->display() ; exit() ) else skip) ; execute ('?')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_POINT=3 ; ARR_SIZE=100 ; arr=[0]*ARR_SIZE ; def printCompositions(n,i): if(n==0): printArray(arr,i); elif(n>0): for k in range(1,MAX_POINT+1): arr[i]=k ; printCompositions(n-k,i+1); def printArray(arr,arr_size): for i in range(arr_size): print(arr[i],end=" "); print(); n=5 ; print("Different compositions formed "+"by 1,2 and 3 of",n," are"); printCompositions(n,0); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_POINT : int := 3; ; var ARR_SIZE : int := 100; ; var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ARR_SIZE); ; skip ; skip ; n := 5; ; execute ("Different compositions formed " + "by 1,2 and 3 of")->display(); ; printCompositions(n, 0);; operation printCompositions(n : OclAny, i : OclAny) pre: true post: true activity: if (n = 0) then ( printArray(arr, i); ) else (if (n > 0) then ( for k : Integer.subrange(1, MAX_POINT + 1-1) do ( arr[i+1] := k; ; printCompositions(n - k, i + 1);) ) else skip); operation printArray(arr : OclAny, arr_size : OclAny) pre: true post: true activity: for i : Integer.subrange(0, arr_size-1) do ( execute (arr[i+1])->display();) ; execute (->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def areAllBitsSet(n): if(n==0): return "No" if(((n+1)& n)==0): return "Yes" return "No" n=7 print(areAllBitsSet(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 7 ; execute (areAllBitsSet(n))->display(); operation areAllBitsSet(n : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return "No" ) else skip ; if ((MathLib.bitwiseAnd((n + 1), n)) = 0) then ( return "Yes" ) else skip ; return "No"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def areAllBitsSet(n): if(n==0): return "No" while(n>0): if((n & 1)==0): return "No" n=n>>1 return "Yes" n=7 print(areAllBitsSet(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 7 ; execute (areAllBitsSet(n))->display(); operation areAllBitsSet(n : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return "No" ) else skip ; while (n > 0) do ( if ((MathLib.bitwiseAnd(n, 1)) = 0) then ( return "No" ) else skip ; n := n /(2->pow(1))) ; return "Yes"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def sumofFactors(n): if(n % 2!=0): return 0 res=1 for i in range(2,(int)(math.sqrt(n))+1): count=0 curr_sum=1 curr_term=1 while(n % i==0): count=count+1 n=n//i if(i==2 and count==1): curr_sum=0 curr_term=curr_term*i curr_sum=curr_sum+curr_term res=res*curr_sum if(n>=2): res=res*(1+n) return res n=18 print(sumofFactors(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 18 ; execute (sumofFactors(n))->display(); operation sumofFactors(n : OclAny) : OclAny pre: true post: true activity: if (n mod 2 /= 0) then ( return 0 ) else skip ; var res : int := 1 ; for i : Integer.subrange(2, (OclType["int"])((n)->sqrt()) + 1-1) do ( var count : int := 0 ; var curr_sum : int := 1 ; var curr_term : int := 1 ; while (n mod i = 0) do ( count := count + 1 ; n := n div i ; if (i = 2 & count = 1) then ( curr_sum := 0 ) else skip ; curr_term := curr_term * i ; curr_sum := curr_sum + curr_term) ; res := res * curr_sum) ; if (n >= 2) then ( res := res * (1 + n) ) else skip ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) li=list(map(int,input())) res=[] ans=[] if li[0]==0 : res.append(1) ans.append(1) else : res.append(2) ans.append(1) for i in range(1,n): if li[i]==1 and res[i-1]==1 : res.append(2) ans.append(1) elif li[i]==0 and res[i-1]==1 : res.append(0) ans.append(0) elif li[i]==1 and res[i-1]==2 : res.append(1) ans.append(0) elif li[i]==0 and res[i-1]==2 : res.append(1) ans.append(1) elif li[i]==0 and res[i-1]==0 : res.append(1) ans.append(1) elif li[i]==1 and res[i-1]==0 : res.append(2) ans.append(1) print(*ans,sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li : Sequence := (((OclFile["System.in"]).readLine())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : Sequence := Sequence{} ; var ans : Sequence := Sequence{} ; if li->first() = 0 then ( execute ((1) : res) ; execute ((1) : ans) ) else ( execute ((2) : res) ; execute ((1) : ans) ) ; for i : Integer.subrange(1, n-1) do ( if li[i+1] = 1 & res[i - 1+1] = 1 then ( execute ((2) : res) ; execute ((1) : ans) ) else (if li[i+1] = 0 & res[i - 1+1] = 1 then ( execute ((0) : res) ; execute ((0) : ans) ) else (if li[i+1] = 1 & res[i - 1+1] = 2 then ( execute ((1) : res) ; execute ((0) : ans) ) else (if li[i+1] = 0 & res[i - 1+1] = 2 then ( execute ((1) : res) ; execute ((1) : ans) ) else (if li[i+1] = 0 & res[i - 1+1] = 0 then ( execute ((1) : res) ; execute ((1) : ans) ) else (if li[i+1] = 1 & res[i - 1+1] = 0 then ( execute ((2) : res) ; execute ((1) : ans) ) else skip ) ) ) ) ) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(0,int(input())): n=int(input()) b=list(input()) a=[] pos=0 for i in range(0,n): val=1 if int(b[i])+val==pos : val-=1 a.append(val) pos=int(b[i])+a[-1] else : a.append(val) pos=int(b[i])+a[-1] print(''.join(str(x)for x in a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var a : Sequence := Sequence{} ; var pos : int := 0 ; for i : Integer.subrange(0, n-1) do ( var val : int := 1 ; if ("" + ((b[i+1])))->toInteger() + val = pos then ( val := val - 1 ; execute ((val) : a) ; pos := ("" + ((b[i+1])))->toInteger() + a->last() ) else ( execute ((val) : a) ; pos := ("" + ((b[i+1])))->toInteger() + a->last() )) ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a)))))))), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,r,s=input(),[-1],[] a=list(map(int,list(input()))) for i in a : if r[-1]!=i+1 : s+=['1'] r+=[i+1] else : s+=['0'] r+=[i] print(''.join(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var r : OclAny := null; var s : OclAny := null; Sequence{n,r,s} := Sequence{(OclFile["System.in"]).readLine(),Sequence{ -1 },Sequence{}} ; var a : Sequence := ((((OclFile["System.in"]).readLine())->characters())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : a do ( if r->last() /= i + 1 then ( s := s + Sequence{ '1' } ; r := r + Sequence{ i + 1 } ) else ( s := s + Sequence{ '0' } ; r := r + Sequence{ i } )) ; execute (StringLib.sumStringsWithSeparator((s), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- u=int(input()) for i in range(u): a=input() b=len(a)-1 x=b*9 c=len(a)*"1" sum=int(a)//int(c) print(sum+x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var u : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, u-1) do ( var a : String := (OclFile["System.in"]).readLine() ; var b : double := (a)->size() - 1 ; var x : double := b * 9 ; var c : double := (a)->size() * "1" ; var sum : int := ("" + ((a)))->toInteger() div ("" + ((c)))->toInteger() ; execute (sum + x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) b=input() a="1" for i in range(1,n): if int(b[i])+1==int(a[i-1])+int(b[i-1]): a+="0" else : a+="1" print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : String := (OclFile["System.in"]).readLine() ; var a : String := "1" ; for i : Integer.subrange(1, n-1) do ( if ("" + ((b[i+1])))->toInteger() + 1 = ("" + ((a[i - 1+1])))->toInteger() + ("" + ((b[i - 1+1])))->toInteger() then ( a := a + "0" ) else ( a := a + "1" )) ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: r='' ; p=0 for x in map(int,s[:-1]): p=x+(x+1!=p); r+=str(p-x) print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var r : String := ''; var p : int := 0 ; for x : (s->front())->collect( _x | (OclType["int"])->apply(_x) ) do ( p := x + (x + 1 /= p); r := r + ("" + ((p - x)))) ; execute (r)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- Q=int(input()) lr=[list(map(int,input().split()))for _ in range(Q)] max_v=10**5 def is_prime(n): is_prime=[True]*(n+1) is_prime[0]=False is_prime[1]=False for i in range(2,int(n**0.5)+1): if not is_prime[i]: continue for j in range(i*2,n+1,i): is_prime[j]=False return is_prime prime=is_prime(max_v) c=[0 for _ in range(max_v+1)] for i in range(max_v): c[i+1]=c[i] if i % 2==1 and prime[i]and prime[((i+1)//2)]: c[i+1]+=1 for i in range(Q): l=lr[i][0] r=lr[i][1] print(c[r+1]-c[l]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lr : Sequence := Integer.subrange(0, Q-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var max_v : double := (10)->pow(5) ; skip ; var prime : OclAny := is_prime(max_v) ; var c : Sequence := Integer.subrange(0, max_v + 1-1)->select(_anon | true)->collect(_anon | (0)) ; for i : Integer.subrange(0, max_v-1) do ( c[i + 1+1] := c[i+1] ; if i mod 2 = 1 & prime[i+1] & prime[((i + 1) div 2)+1] then ( c[i + 1+1] := c[i + 1+1] + 1 ) else skip) ; for i : Integer.subrange(0, Q-1) do ( var l : OclAny := lr[i+1]->first() ; var r : OclAny := lr[i+1][1+1] ; execute (c[r + 1+1] - c[l+1])->display()); operation is_prime(n : OclAny) : OclAny pre: true post: true activity: var is_prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (n + 1)) ; is_prime->first() := false ; is_prime[1+1] := false ; for i : Integer.subrange(2, ("" + (((n)->pow(0.5))))->toInteger() + 1-1) do ( if not(is_prime[i+1]) then ( continue ) else skip ; for j : Integer.subrange(i * 2, n + 1-1)->select( $x | ($x - i * 2) mod i = 0 ) do ( is_prime[j+1] := false)) ; return is_prime; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=21 fact=[0]*MAX def probability(k,n): ans=0 for i in range(k,n+1): ans+=fact[n]/(fact[i]*fact[n-i]) ans=ans/(1<display() ; execute (probability(3, 6))->display() ; execute (probability(12, 18))->display() ) else skip; operation probability(k : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(k, n + 1-1) do ( ans := ans + fact[n+1] / (fact[i+1] * fact[n - i+1])) ; ans := ans / (1 * (2->pow(n))) ; return ans; operation precompute() pre: true post: true activity: fact->first() := 1 ; fact[1+1] := 1 ; for i : Integer.subrange(2, 20-1) do ( fact[i+1] := fact[i - 1+1] * i); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def s(number): if number<=2 : return 0 for i in range(2,math.floor(math.sqrt(number))+1): if number % i==0 : return 0 for i in range(2,math.floor(math.sqrt((number+1)//2))+1): if((number+1)//2)% i==0 : return 0 return 1 num=[s(i)for i in range(1,10**5+1)] li=[0] for nu in num : li.append(li[-1]+nu) q=int(input()) for _ in range(q): l,r=map(int,input().split()) print(li[r]-li[l-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var num : Sequence := Integer.subrange(1, (10)->pow(5) + 1-1)->select(i | true)->collect(i | (s(i))) ; var li : Sequence := Sequence{ 0 } ; for nu : num do ( execute ((li->last() + nu) : li)) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (li[r+1] - li[l - 1+1])->display()); operation s(number : OclAny) : OclAny pre: true post: true activity: if number <= 2 then ( return 0 ) else skip ; for i : Integer.subrange(2, ((number)->sqrt())->floor() + 1-1) do ( if number mod i = 0 then ( return 0 ) else skip) ; for i : Integer.subrange(2, (((number + 1) div 2)->sqrt())->floor() + 1-1) do ( if ((number + 1) div 2) mod i = 0 then ( return 0 ) else skip) ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def isprime(n): nroot=int(math.sqrt(n)) flag=0 for i in range(2,nroot+1): if n % i==0 : flag=1 break return flag Q=int(input()) L=[] R=[] for i in range(Q): l,r=map(int,input().split()) L.append(l) R.append(r) Rmax=max(R) pcount=[] for i in range(Rmax): I=i+1 if I==1 : pcount.append(0) elif I % 2==1 : pf=pcount[-2] if isprime(I)==0 and isprime(int((I+1)/2))==0 : pf+=1 pcount.append(pf) else : pcount.append(0) for i in range(Q): ans=pcount[R[i]-1]-pcount[L[i]-3] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var L : Sequence := Sequence{} ; var R : Sequence := Sequence{} ; for i : Integer.subrange(0, Q-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((l) : L) ; execute ((r) : R)) ; var Rmax : OclAny := (R)->max() ; var pcount : Sequence := Sequence{} ; for i : Integer.subrange(0, Rmax-1) do ( var I : OclAny := i + 1 ; if I = 1 then ( execute ((0) : pcount) ) else (if I mod 2 = 1 then ( var pf : OclAny := pcount->front()->last() ; if isprime(I) = 0 & isprime(("" + (((I + 1) / 2)))->toInteger()) = 0 then ( pf := pf + 1 ) else skip ; execute ((pf) : pcount) ) else ( execute ((0) : pcount) ) ) ) ; for i : Integer.subrange(0, Q-1) do ( var ans : double := pcount[R[i+1] - 1+1] - pcount[L[i+1] - 3+1] ; execute (ans)->display()); operation isprime(n : OclAny) : OclAny pre: true post: true activity: var nroot : int := ("" + (((n)->sqrt())))->toInteger() ; var flag : int := 0 ; for i : Integer.subrange(2, nroot + 1-1) do ( if n mod i = 0 then ( flag := 1 ; break ) else skip) ; return flag; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt from itertools import accumulate def is_prime(x): if x<2 : return False else : for i in range(2,int(sqrt(x))+1): if x % i==0 : return False return True def is_like_2017(x): if is_prime(x)and is_prime((x+1)//2): return True else : return False q=int(input()) lr=[list(map(int,input().split()))for _ in range(q)] nums=[] for i in range(1,10**5,2): if is_like_2017(i): nums.append(1) else : nums.append(0) acm=[0]+list(accumulate(nums)) for l,r in lr : ans=acm[(r+1)//2]-acm[(l+1)//2-1] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lr : Sequence := Integer.subrange(0, q-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var nums : Sequence := Sequence{} ; for i : Integer.subrange(1, (10)->pow(5)-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( if is_like execute ((1) : nums)017(i) then ( execute ((1) : nums) ) else ( execute ((0) : nums) )) ; var acm : Sequence := Sequence{ 0 }->union((accumulate(nums))) ; for _tuple : lr do (var _indx : int := 1; var l : OclAny := _tuple->at(_indx); _indx := _indx + 1; var r : OclAny := _tuple->at(_indx); var ans : double := acm[(r + 1) div 2+1] - acm[(l + 1) div 2 - 1+1] ; execute (ans)->display()); operation is_prime(x : OclAny) : OclAny pre: true post: true activity: if x < 2 then ( return false ) else ( for i : Integer.subrange(2, ("" + ((sqrt(x))))->toInteger() + 1-1) do ( if x mod i = 0 then ( return false ) else skip) ; return true ); operation is_likex : OclAny017(x : OclAny) : OclAny pre: true post: true activity: if is_prime(x) & is_prime((x + 1) div 2) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from itertools import accumulate readline=sys.stdin.readline read=sys.stdin.read def main(): q,*lr=map(int,read().split()) n=10**5 ansl=[] sieve=[1]*(n+1) sieve[0],sieve[1]=0,0 for i in range(2,n): if sieve[i]: sieve[2*i : : i]=[0 for _ in range(2*i,n+1,i)] ans=[0]*(n+1) for i in range(3,n): if sieve[i]==1 and sieve[(i+1)//2]==1 : ans[i]=1 ans=list(accumulate(ans)) for l,r in zip(*[iter(lr)]*2): print(ans[r]-ans[l-1]) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var read : OclAny := (OclFile["System.in"]).read ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var q : OclAny := null; var lr : OclAny := null; Sequence{q,lr} := (read().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : double := (10)->pow(5) ; var ansl : Sequence := Sequence{} ; var sieve : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ; var sieve->first() : OclAny := null; var sieve[1+1] : OclAny := null; Sequence{sieve->first(),sieve[1+1]} := Sequence{0,0} ; for i : Integer.subrange(2, n-1) do ( if sieve[i+1] then ( sieve(subscript (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name i))))))) : (sliceop : (test (logical_test (comparison (expr (atom (name i)))))))) := Integer.subrange(2 * i, n + 1-1)->select( $x | ($x - 2 * i) mod i = 0 )->select(_anon | true)->collect(_anon | (0)) ) else skip) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(3, n-1) do ( if sieve[i+1] = 1 & sieve[(i + 1) div 2+1] = 1 then ( ans[i+1] := 1 ) else skip) ; ans := (accumulate(ans)) ; for _tuple : Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name lr)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name lr)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name lr)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))`third->at(_indx)} ) do (var _indx : int := 1; var l : OclAny := _tuple->at(_indx); _indx := _indx + 1; var r : OclAny := _tuple->at(_indx); execute (ans[r+1] - ans[l - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def optimalStrategyOfGame(arr,n): table=[[0 for i in range(n)]for i in range(n)] for gap in range(n): for j in range(gap,n): i=j-gap x=0 if((i+2)<=j): x=table[i+2][j] y=0 if((i+1)<=(j-1)): y=table[i+1][j-1] z=0 if(i<=(j-2)): z=table[i][j-2] table[i][j]=max(arr[i]+min(x,y),arr[j]+min(y,z)) return table[0][n-1] arr1=[8,15,3,7] n=len(arr1) print(optimalStrategyOfGame(arr1,n)) arr2=[2,2,2,2] n=len(arr2) print(optimalStrategyOfGame(arr2,n)) arr3=[20,30,2,2,2,10] n=len(arr3) print(optimalStrategyOfGame(arr3,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var arr1 : Sequence := Sequence{8}->union(Sequence{15}->union(Sequence{3}->union(Sequence{ 7 }))) ; n := (arr1)->size() ; execute (optimalStrategyOfGame(arr1, n))->display() ; var arr2 : Sequence := Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 2 }))) ; n := (arr2)->size() ; execute (optimalStrategyOfGame(arr2, n))->display() ; var arr3 : Sequence := Sequence{20}->union(Sequence{30}->union(Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 10 }))))) ; n := (arr3)->size() ; execute (optimalStrategyOfGame(arr3, n))->display(); operation optimalStrategyOfGame(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var table : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)))) ; for gap : Integer.subrange(0, n-1) do ( for j : Integer.subrange(gap, n-1) do ( var i : double := j - gap ; var x : int := 0 ; if (((i + 2)->compareTo(j)) <= 0) then ( x := table[i + 2+1][j+1] ) else skip ; var y : int := 0 ; if (((i + 1)->compareTo((j - 1))) <= 0) then ( y := table[i + 1+1][j - 1+1] ) else skip ; var z : int := 0 ; if ((i->compareTo((j - 2))) <= 0) then ( z := table[i+1][j - 2+1] ) else skip ; table[i+1][j+1] := Set{arr[i+1] + Set{x, y}->min(), arr[j+1] + Set{y, z}->min()}->max())) ; return table->first()[n - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fibonacci(n): a=0 b=1 if(n<=1): return n for i in range(2,n+1): c=a+b a=b b=c return c def isMultipleOf10(n): f=fibonacci(30) return(f % 10==0) if __name__=="__main__" : n=30 if(isMultipleOf10(n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 30 ; if (isMultipleOf10(n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation fibonacci(n : OclAny) : OclAny pre: true post: true activity: var a : int := 0 ; var b : int := 1 ; if (n <= 1) then ( return n ) else skip ; for i : Integer.subrange(2, n + 1-1) do ( var c : int := a + b ; a := b ; b := c) ; return c; operation isMultipleOf10(n : OclAny) : OclAny pre: true post: true activity: var f : OclAny := fibonacci(30) ; return (f mod 10 = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def can(state,m,bulb,p): for i in range(m): cnt=0 for j in bulb[i]: if(state &(1<<(j-1))): cnt+=1 if cnt % 2!=p[i]: return False return True n,m=map(int,input().split()) bulb=[] for i in range(m): l=list(map(int,input().split())) l=l[1 :] bulb.append(l) p=list(map(int,input().split())) ans=0 for i in range(1<collect( _x | (OclType["int"])->apply(_x) ) ; bulb := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := l->tail() ; execute ((l) : bulb)) ; p := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(0, 1 * (2->pow(n))-1) do ( if can(i, m, bulb, p) then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); operation can(state : OclAny, m : OclAny, bulb : OclAny, p : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, m-1) do ( var cnt : int := 0 ; for j : bulb[i+1] do ( if (MathLib.bitwiseAnd(state, (1 * (2->pow((j - 1)))))) then ( cnt := cnt + 1 ) else skip) ; if cnt mod 2 /= p[i+1] then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re a,b=map(int,input().split()) s=input() p='[0-9]{'+str(a)+'}-[0-9]{'+str(b)+'}' if re.match(p,s)is None : print('No') else : print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var p : String := '[0-9]{' + ("" + ((a))) + '}-[0-9]{' + ("" + ((b))) + '}' ; if (s)->firstMatch("^" + p + ".*") <>= null then ( execute ('No')->display() ) else ( execute ('Yes')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B=tuple(int(num)for num in input().split()) S=input() s_list=list(S) for i,s in enumerate(s_list): if i==A : if s_list[A]!='-' : print('No') break else : try : s=int(s) except : print('No') break else : print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) ))))))) (comp_for for (exprlist (expr (atom (name num)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ; var S : String := (OclFile["System.in"]).readLine() ; var s_list : Sequence := (S)->characters() ; (compound_stmt for (exprlist (expr (atom (name i))) , (expr (atom (name s)))) in (testlist (test (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s_list)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name i)))) == (comparison (expr (atom (name A))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name s_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name A)))))))) ])))) != (comparison (expr (atom '-')))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'No'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt try : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))))))))))))) (except_clause except : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'No'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'Yes'))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B=map(int,input().strip().split(" ")) S=list(input()) flag=0 if(S[A]=='-'): S.pop(A) else : flag=1 if('-' in S): flag=1 if(flag==0): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input()->trim().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var S : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var flag : int := 0 ; if (S[A+1] = '-') then ( S := S->excludingAt(A+1) ) else ( flag := 1 ) ; if ((S)->includes('-')) then ( flag := 1 ) else skip ; if (flag = 0) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline a,b=map(int,input().split()) s=input().strip() flg=True for i in range(a): if s[i]=="-" : flg=False if s[a]!="-" : flg=False for i in range(b): if s[a+i+1]=="-" : flg=False print("Yes" if flg else "No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := input()->trim() ; var flg : boolean := true ; for i : Integer.subrange(0, a-1) do ( if s[i+1] = "-" then ( flg := false ) else skip) ; if s[a+1] /= "-" then ( flg := false ) else skip ; for i : Integer.subrange(0, b-1) do ( if s[a + i + 1+1] = "-" then ( flg := false ) else skip) ; execute (if flg then "Yes" else "No" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=0 for i in range(1,n+1): ans+=i*(n-i+1) for i in range(n-1): v,w=map(int,input().split()) if v>w : v,w=w,v ans-=v*(n-w+1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( ans := ans + i * (n - i + 1)) ; for i : Integer.subrange(0, n - 1-1) do ( var v : OclAny := null; var w : OclAny := null; Sequence{v,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (v->compareTo(w)) > 0 then ( var v : OclAny := null; var w : OclAny := null; Sequence{v,w} := Sequence{w,v} ) else skip ; ans := ans - v * (n - w + 1)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) s=input() print('Yes' if s.count('-')==1 and(s.index('-')==a)and((len(s)-1-s.index('-'))==b)else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; execute (if s->count('-') = 1 & (s->indexOf('-') - 1 = a) & (((s)->size() - 1 - s->indexOf('-') - 1) = b) then 'Yes' else 'No' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def checkfact(N,countprime,prime): countfact=0 if(prime==2 or prime==3): countfact+=1 divide=prime while(int(N/divide)!=0): countfact+=int(N/divide) divide=divide*divide if(countfact>=countprime): return True else : return False def check(N): sumsquares=(N+1)*(2*N+1) countprime=0 for i in range(2,int(sqrt(sumsquares))+1,1): flag=0 while(sumsquares % i==0): flag=1 countprime+=1 sumsquares/=i if(flag): if(checkfact(N-1,countprime,i)==False): return False countprime=0 if(sumsquares!=1): if(checkfact(N-1,1,sumsquares)==False): return False return True if __name__=='__main__' : N=5 if(check(N)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( N := 5 ; if (check(N)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation checkfact(N : OclAny, countprime : OclAny, prime : OclAny) : OclAny pre: true post: true activity: var countfact : int := 0 ; if (prime = 2 or prime = 3) then ( countfact := countfact + 1 ) else skip ; var divide : OclAny := prime ; while (("" + ((N / divide)))->toInteger() /= 0) do ( countfact := countfact + ("" + ((N / divide)))->toInteger() ; divide := divide * divide) ; if ((countfact->compareTo(countprime)) >= 0) then ( return true ) else ( return false ); operation check(N : OclAny) : OclAny pre: true post: true activity: var sumsquares : double := (N + 1) * (2 * N + 1) ; countprime := 0 ; for i : Integer.subrange(2, ("" + ((sqrt(sumsquares))))->toInteger() + 1-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( var flag : int := 0 ; while (sumsquares mod i = 0) do ( flag := 1 ; countprime := countprime + 1 ; sumsquares := sumsquares / i) ; if (flag) then ( if (checkfact(N - 1, countprime, i) = false) then ( return false ) else skip ; countprime := 0 ) else skip) ; if (sumsquares /= 1) then ( if (checkfact(N - 1, 1, sumsquares) = false) then ( return false ) else skip ) else skip ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def __gcd(a,b): return a if(b==0)else __gcd(b,a % b); def isSplittable(n,m): total_sum=(int)((n*(n+1))/2); sum_s1=int((total_sum+m)/2); sum_s2=total_sum-sum_s1 ; if(total_sumdisplay(); ) else ( execute ("No")->display(); ); operation __gcd(a : OclAny, b : OclAny) pre: true post: true activity: return if (b = 0) then a else __gcd(b, a mod b) endif;; operation isSplittable(n : OclAny, m : OclAny) pre: true post: true activity: var total_sum : OclAny := (OclType["int"])((n * (n + 1)) / 2); ; var sum_s1 : int := ("" + (((total_sum + m) / 2)))->toInteger(); ; var sum_s2 : double := total_sum - sum_s1; ; if ((total_sum->compareTo(m)) < 0) then ( return false; ) else skip ; if (sum_s1 + sum_s2 = total_sum & sum_s1 - sum_s2 = m) then ( return (__gcd(sum_s1, sum_s2) = 1); ) else skip ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def manipulateString(str): for i in range(len(str)): asc=ord(str[i]) rem=asc-(26-(ord(str[i])-ord('a'))) m=rem % 26 str[i]=chr(m+ord('a')) print(''.join(str)) if __name__=="__main__" : str="geeksforgeeks" str=list(str) manipulateString(str) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( OclType["String"] := "geeksforgeeks" ; OclType["String"] := (OclType["String"])->characters() ; manipulateString(OclType["String"]) ) else skip; operation manipulateString(OclType["String"] : OclAny) pre: true post: true activity: for i : Integer.subrange(0, (OclType["String"])->size()-1) do ( var asc : int := (("" + ([i+1])))->char2byte() ; var rem : double := asc - (26 - ((("" + ([i+1])))->char2byte() - ('a')->char2byte())) ; var m : int := rem mod 26 ; ("" + ([i+1])) := (m + ('a')->char2byte())->byte2char()) ; execute (StringLib.sumStringsWithSeparator((OclType["String"]), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=str(input()) l=s.split(":") hrs=int(l[0]) mins=int(l[1]) if hrs>=12 : hrs-=12 print(((hrs*30)+(mins/2)),mins*6) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; var l : OclAny := s.split(":") ; var hrs : int := ("" + ((l->first())))->toInteger() ; var mins : int := ("" + ((l[1+1])))->toInteger() ; if hrs >= 12 then ( hrs := hrs - 12 ) else skip ; execute (((hrs * 30) + (mins / 2)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): t=int(input()) if t<10 : print(t) if t>=10 : if t==10 : print(9) else : print((len(str(t))-1)*9+(t//int('1'*len(str(t))))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if t < 10 then ( execute (t)->display() ) else skip ; if t >= 10 then ( if t = 10 then ( execute (9)->display() ) else ( execute (((("" + ((t))))->size() - 1) * 9 + (t div ("" + ((StringLib.nCopies('1', (("" + ((t))))->size()))))->toInteger()))->display() ) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split(':')) x=((a*60)+b)/2 y=b*6 x=x % 360 print(x,y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split(':'))->collect( _x | (OclType["int"])->apply(_x) ) ; var x : double := ((a * 60) + b) / 2 ; var y : double := b * 6 ; x := x mod 360 ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline hh,mm=map(int,input().split(":")) hh %=12 x=(60*hh+mm)/2 y=6*mm print(x,y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var hh : OclAny := null; var mm : OclAny := null; Sequence{hh,mm} := (input().split(":"))->collect( _x | (OclType["int"])->apply(_x) ) ; hh := hh mod 12 ; var x : double := (60 * hh + mm) / 2 ; var y : double := 6 * mm ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,m=map(int,input().split(':')) print(30*(h % 12)+m/2,m*6) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := (input().split(':'))->collect( _x | (OclType["int"])->apply(_x) ) ; execute (30 * (h mod 12) + m / 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() hr=int(s[0])*10+int(s[1]) mi=int(s[3])*10+int(s[4]) t=(hr*30)+(mi/60)*30 tt=mi*6 print(t % 360,tt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var hr : int := ("" + ((s->first())))->toInteger() * 10 + ("" + ((s[1+1])))->toInteger() ; var mi : int := ("" + ((s[3+1])))->toInteger() * 10 + ("" + ((s[4+1])))->toInteger() ; var t : int := (hr * 30) + (mi / 60) * 30 ; var tt : int := mi * 6 ; execute (t mod 360)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys for line in sys.stdin : n=int(line) print(n*n+n+2)/2 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for line : OclFile["System.in"] do ( var n : int := ("" + ((line)))->toInteger() ; (expr (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (expr (atom (name n))) * (expr (atom (name n)))) + (expr (atom (name n)))) + (expr (atom (number (integer 2)))))))))) )))) / (expr (atom (number (integer 2)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**8) ini=lambda : int(sys.stdin.readline()) inm=lambda : map(int,sys.stdin.readline().split()) inl=lambda : list(inm()) ins=lambda : sys.stdin.readline().rstrip() debug=lambda*a,**kw : print("\033[33m",*a,"\033[0m",**dict(file=sys.stderr,**kw)) N=ini() def solve(): edge_count=0 for i in range(N-1): u,v=sorted(inl()) edge_count+=u*(N-v+1) node_count=0 for i in range(N): node_count+=(i+1)*(N-i) return node_count-edge_count print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(8)) ; var ini : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var inm : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var inl : Function := lambda $$ : OclAny in ((inm->apply())) ; var ins : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var debug : Function := lambda a : Sequence(OclAny), kw : Map(String, OclAny) in (("\033[33m")->display()) ; var N : OclAny := ini->apply() ; skip ; execute (solve())->display(); operation solve() : OclAny pre: true post: true activity: var edge_count : int := 0 ; for i : Integer.subrange(0, N - 1-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := inl->apply()->sort() ; edge_count := edge_count + u * (N - v + 1)) ; var node_count : int := 0 ; for i : Integer.subrange(0, N-1) do ( node_count := node_count + (i + 1) * (N - i)) ; return node_count - edge_count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : n=int(input()) except : break sum=1 for i in range(1,n+1): sum+=i print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) catch (_e : OclException) do ( break) ; var sum : int := 1 ; for i : Integer.subrange(1, n + 1-1) do ( sum := sum + i) ; execute (sum)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[1] for i in range(1,10002): a.append(a[i-1]+i) while True : try : print(a[int(input())]) except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Sequence{ 1 } ; for i : Integer.subrange(1, 10002-1) do ( execute ((a[i - 1+1] + i) : a)) ; while true do ( try ( execute (a[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1])->display()) catch (_e : OclException) do ( break) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readlines=sys.stdin.readlines write=sys.stdout.write def solve(): for line in readlines(): N=int(line) write("%d\n" %(N*(N+1)//2+1)) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readlines : OclAny := (OclFile["System.in"]).readlines ; var write : OclAny := (OclFile["System.out"]).write ; skip ; solve(); operation solve() pre: true post: true activity: for line : readlines() do ( var N : int := ("" + ((line)))->toInteger() ; write(StringLib.format("%d\n",(N * (N + 1) div 2 + 1)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import(division,absolute_import,print_function,unicode_literals) from sys import stdin L=[1] for i in xrange(1,10001): L.append(i+L[-1]) for line in stdin : n=int(line) print(L[n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var L : Sequence := Sequence{ 1 } ; for i : xrange(1, 10001) do ( execute ((i + L->last()) : L)) ; for line : stdin do ( var n : int := ("" + ((line)))->toInteger() ; execute (L[n+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): n=int(input()) ct=0 for i in range(1,10): a=0 for j in range(1,11): a=a*10+i if a<=n : ct=ct+1 print(ct) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ct : int := 0 ; for i : Integer.subrange(1, 10-1) do ( var a : int := 0 ; for j : Integer.subrange(1, 11-1) do ( a := a * 10 + i ; if (a->compareTo(n)) <= 0 then ( ct := ct + 1 ) else skip)) ; execute (ct)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def sortArrayByParity(self,A): lo,hi=0,len(A)-1 while loA[hi]% 2 : A[lo],A[hi]=A[hi],A[lo] if A[lo]% 2==0 : lo+=1 if A[hi]% 2==1 : hi-=1 return A ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation sortArrayByParity(A : OclAny) : OclAny pre: true post: true activity: var lo : OclAny := null; var hi : OclAny := null; Sequence{lo,hi} := Sequence{0,(A)->size() - 1} ; while (lo->compareTo(hi)) < 0 do ( if (A[lo+1] mod 2->compareTo(A[hi+1] mod 2)) > 0 then ( var A[lo+1] : OclAny := null; var A[hi+1] : OclAny := null; Sequence{A[lo+1],A[hi+1]} := Sequence{A[hi+1],A[lo+1]} ) else skip ; if A[lo+1] mod 2 = 0 then ( lo := lo + 1 ) else skip ; if A[hi+1] mod 2 = 1 then ( hi := hi - 1 ) else skip) ; return A; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(i)for i in input().split()] d=dict() b=[i for i in input().split()] for item in b : d[item]=-1 i=0 for item in b : if d[item]==0 : print(0,end=' ') elif d[item]==-1 : cnt=1 while a[i]!=int(item)and i!=n : d[str(a[i])]=0 cnt+=1 i+=1 i+=1 print(cnt,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var d : Map := (arguments ( )) ; var b : Sequence := input().split()->select(i | true)->collect(i | (i)) ; for item : b do ( d[item+1] := -1) ; var i : int := 0 ; for item : b do ( if d[item+1] = 0 then ( execute (0)->display() ) else (if d[item+1] = -1 then ( var cnt : int := 1 ; while a[i+1] /= ("" + ((item)))->toInteger() & i /= n do ( d[("" + ((a[i+1])))+1] := 0 ; cnt := cnt + 1 ; i := i + 1) ; i := i + 1 ; execute (cnt)->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=[int(x)for x in input().split()] y=[int(x)for x in input().split()] my_set=set() map_index={} for i in range(len(x)): map_index[x[i]]=i last_move=0 for i in range(len(y)): step=0 index_book=map_index[y[i]] if index_book>=last_move : step=index_book-last_move+1 last_move=index_book+1 print(f"{step}",end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var y : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var my_set : Set := Set{}->union(()) ; var map_index : OclAny := Set{} ; for i : Integer.subrange(0, (x)->size()-1) do ( map_index[x[i+1]+1] := i) ; var last_move : int := 0 ; for i : Integer.subrange(0, (y)->size()-1) do ( var step : int := 0 ; var index_book : OclAny := map_index[y[i+1]+1] ; if (index_book->compareTo(last_move)) >= 0 then ( step := index_book - last_move + 1 ; last_move := index_book + 1 ) else skip ; execute (StringLib.formattedString("{step}"))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- end=int(input()) books=input().split() removed={} beginning=0 output='' for book in input().split(): if book in removed : output+='0 ' else : for i in range(beginning,end): if books[i]==book : break removed[books[i]]=None index=i+1 output+=str(index-beginning)+' ' beginning=index print(output) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var end : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var books : OclAny := input().split() ; var removed : OclAny := Set{} ; var beginning : int := 0 ; var output : String := '' ; for book : input().split() do ( if (removed)->includes(book) then ( output := output + '0 ' ) else ( for i : Integer.subrange(beginning, end-1) do ( if books[i+1] = book then ( break ) else skip ; removed[books[i+1]+1] := null) ; var index : OclAny := i + 1 ; output := output + ("" + ((index - beginning))) + ' ' ; beginning := index )) ; execute (output)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) v=[int(x)for x in input().split()] order=[int(x)for x in input().split()] st,res=set(),list() index=0 for op in order : cou=0 while op not in st : cou+=1 st.add(v[index]); index+=1 res.append(cou) print(" ".join([str(x)for x in res])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var v : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var order : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var st : OclAny := null; var res : OclAny := null; Sequence{st,res} := Sequence{Set{}->union(()),()} ; var index : int := 0 ; for op : order do ( var cou : int := 0 ; while (st)->excludes(op) do ( cou := cou + 1 ; execute ((v[index+1]) : st); index := index + 1) ; execute ((cou) : res)) ; execute (StringLib.sumStringsWithSeparator((res->select(x | true)->collect(x | (("" + ((x)))))), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=lambda : map(int,input().split()) input() p={a : i for i,a in enumerate(I(),1)} x=0 for b in I(): print(max(0,p[b]-x),end=' ') x=max(x,p[b]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; input() ; var p : Map := Integer.subrange(1, (I->apply(), 1)->size())->collect( _indx | Sequence{_indx-1, (I->apply(), 1)->at(_indx)} )->select(_tuple | true)->collect(_tuple | Map{a |-> i})->unionAll() ; var x : int := 0 ; for b : I->apply() do ( execute (Set{0, p[b+1] - x}->max())->display() ; x := Set{x, p[b+1]}->max()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.buffer.readline N=int(input()) Edges=[list(map(int,input().split()))for _ in range(N-1)] ans=0 for l in range(1,N+1): ans+=(N-l+2)*(N-l+1)//2 for a,b in Edges : if a>b : b,a=a,b ans-=a*(N-b+1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := sys.stdin.buffer.readline ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var Edges : Sequence := Integer.subrange(0, N - 1-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ans : int := 0 ; for l : Integer.subrange(1, N + 1-1) do ( ans := ans + (N - l + 2) * (N - l + 1) div 2) ; for _tuple : Edges do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if (a->compareTo(b)) > 0 then ( var b : OclAny := null; var a : OclAny := null; Sequence{b,a} := Sequence{a,b} ) else skip ; ans := ans - a * (N - b + 1)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isWordPresent(sentence,word): word=word.upper() sentence=sentence.upper() s=sentence.split(); for temp in s : if(temp==word): return True ; return False ; if __name__=="__main__" : s="Geeks for Geeks" ; word="geeks" ; if(isWordPresent(s,word)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "Geeks for Geeks"; ; word := "geeks"; ; if (isWordPresent(s, word)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ) else skip; operation isWordPresent(sentence : OclAny, word : OclAny) pre: true post: true activity: word := word->toUpperCase() ; sentence := sentence->toUpperCase() ; var s : OclAny := sentence.split(); ; for temp : s do ( if (temp = word) then ( return true; ) else skip) ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000005 fibUpto=[0]*(MAX+1) def compute(sz): isFib=[False]*(sz+1) prev=0 curr=1 isFib[prev]=True isFib[curr]=True while(curr<=sz): temp=curr+prev if(temp<=sz): isFib[temp]=True prev=curr curr=temp fibUpto[0]=1 for i in range(1,sz+1): fibUpto[i]=fibUpto[i-1] if(isFib[i]): fibUpto[i]+=1 def countOfNumbers(N,K): compute(N) low,high,ans=1,N,0 while(low<=high): mid=(low+high)>>1 if(mid-fibUpto[mid]>=K): ans=mid high=mid-1 else : low=mid+1 if(ans): return(N-ans+1) return 0 if __name__=="__main__" : N=10 K=3 print(countOfNumbers(N,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1000005 ; var fibUpto : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX + 1)) ; skip ; skip ; if __name__ = "__main__" then ( N := 10 ; K := 3 ; execute (countOfNumbers(N, K))->display() ) else skip; operation compute(sz : OclAny) pre: true post: true activity: var isFib : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (sz + 1)) ; var prev : int := 0 ; var curr : int := 1 ; isFib[prev+1] := true ; isFib[curr+1] := true ; while ((curr->compareTo(sz)) <= 0) do ( var temp : int := curr + prev ; if ((temp->compareTo(sz)) <= 0) then ( isFib[temp+1] := true ) else skip ; prev := curr ; curr := temp) ; fibUpto->first() := 1 ; for i : Integer.subrange(1, sz + 1-1) do ( fibUpto[i+1] := fibUpto[i - 1+1] ; if (isFib[i+1]) then ( fibUpto[i+1] := fibUpto[i+1] + 1 ) else skip); operation countOfNumbers(N : OclAny, K : OclAny) : OclAny pre: true post: true activity: compute(N) ; var low : OclAny := null; var high : OclAny := null; var ans : OclAny := null; Sequence{low,high,ans} := Sequence{1,N,0} ; while ((low->compareTo(high)) <= 0) do ( var mid : int := (low + high) /(2->pow(1)) ; if ((mid - fibUpto[mid+1]->compareTo(K)) >= 0) then ( var ans : int := mid ; var high : double := mid - 1 ) else ( var low : int := mid + 1 )) ; if (ans) then ( return (N - ans + 1) ) else skip ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): while True : INF=10**10 s,d,m=map(int,input().split()) ws=[] ps=[] for _ in range(s): input() wplst=list(map(int,input().split())) ws.append(wplst[: : 2]) ps.append(wplst[1 : : 2]) fs=list(map(int,input().split())) wlst=[] plst=[] for f in fs : wlst+=ws[f] plst+=ps[f] dp=[-INF]*(m+1) dp[0]=0 for w,p in zip(wlst,plst): for i in range(m-p,-1,-1): if dp[i+p]pow(10) ; var s : OclAny := null; var d : OclAny := null; var m : OclAny := null; Sequence{s,d,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ws : Sequence := Sequence{} ; var ps : Sequence := Sequence{} ; for _anon : Integer.subrange(0, s-1) do ( input() ; var wplst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((wplst(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) : ws) ; execute ((wplst(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) : ps)) ; var fs : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var wlst : Sequence := Sequence{} ; var plst : Sequence := Sequence{} ; for f : fs do ( wlst := wlst + ws[f+1] ; plst := plst + ps[f+1]) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ -INF }, (m + 1)) ; dp->first() := 0 ; for _tuple : Integer.subrange(1, wlst->size())->collect( _indx | Sequence{wlst->at(_indx), plst->at(_indx)} ) do (var _indx : int := 1; var w : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p : OclAny := _tuple->at(_indx); for i : Integer.subrange(-1 + 1, m - p)->reverse() do ( if (dp[i + p+1]->compareTo(dp[i+1] + w)) < 0 then ( dp[i + p+1] := dp[i+1] + w ) else skip)) ; var max_score : OclAny := (dp)->max() ; execute (max_score)->display() ; try ( input()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def divSum(n): sum=1 ; i=2 ; while(i*i<=n): if(n % i==0): sum=(sum+i+math.floor(n/i)); i+=1 ; return sum ; def areEquivalent(num1,num2): return divSum(num1)==divSum(num2); num1=559 ; num2=703 ; if(areEquivalent(num1,num2)==True): print("Equivalent"); else : print("Not Equivalent"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; num1 := 559; ; num2 := 703; ; if (areEquivalent(num1, num2) = true) then ( execute ("Equivalent")->display(); ) else ( execute ("Not Equivalent")->display(); ); operation divSum(n : OclAny) pre: true post: true activity: var sum : int := 1; ; var i : int := 2; ; while ((i * i->compareTo(n)) <= 0) do ( if (n mod i = 0) then ( sum := (sum + i + (n / i)->floor()); ) else skip ; i := i + 1;) ; return sum;; operation areEquivalent(num1 : OclAny, num2 : OclAny) pre: true post: true activity: return divSum(num1) = divSum(num2);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getLeftmostBit(n): m=0 while(n>1): n=n>>1 m+=1 return m def getNextLeftmostBit(n,m): temp=1<>1 m-=1 return m def countSetBits(n): m=getLeftmostBit(n) return _countSetBits(n,m) def _countSetBits(n,m): if(n==0): return 0 m=getNextLeftmostBit(n,m) if(n==(1<<(m+1))-1): return((m+1)*(1<display(); operation getLeftmostBit(n : OclAny) : OclAny pre: true post: true activity: var m : int := 0 ; while (n > 1) do ( n := n /(2->pow(1)) ; m := m + 1) ; return m; operation getNextLeftmostBit(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var temp : int := 1 * (2->pow(m)) ; while ((n->compareTo(temp)) < 0) do ( temp := temp /(2->pow(1)) ; m := m - 1) ; return m; operation countSetBits(n : OclAny) : OclAny pre: true post: true activity: m := getLeftmostBit(n) ; return _countSetBits(n, m); operation _countSetBits(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return 0 ) else skip ; m := getNextLeftmostBit(n, m) ; if (n = (1 * (2->pow((m + 1)))) - 1) then ( return ((m + 1) * (1 * (2->pow(m)))) ) else skip ; n := n - (1 * (2->pow(m))) ; return (n + 1) + countSetBits(n) + m * (1 * (2->pow((m - 1)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getCount(N): if(N % 2==1): return "0" result="9" for i in range(1,N//2): result=result+"0" return result N=4 print(getCount(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 4 ; execute (getCount(N))->display(); operation getCount(N : OclAny) : OclAny pre: true post: true activity: if (N mod 2 = 1) then ( return "0" ) else skip ; var result : String := "9" ; for i : Integer.subrange(1, N div 2-1) do ( result := result + "0") ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def minCoins(coins,m,V): table=[0 for i in range(V+1)] table[0]=0 for i in range(1,V+1): table[i]=sys.maxsize for i in range(1,V+1): for j in range(m): if(coins[j]<=i): sub_res=table[i-coins[j]] if(sub_res!=sys.maxsize and sub_res+1union(Sequence{6}->union(Sequence{5}->union(Sequence{ 1 }))) ; m := (coins)->size() ; V := 11 ; execute ("Minimum coins required is ")->display() ) else skip; operation minCoins(coins : OclAny, m : OclAny, V : OclAny) : OclAny pre: true post: true activity: var table : Sequence := Integer.subrange(0, V + 1-1)->select(i | true)->collect(i | (0)) ; table->first() := 0 ; for i : Integer.subrange(1, V + 1-1) do ( table[i+1] := (trailer . (name maxsize))) ; for i : Integer.subrange(1, V + 1-1) do ( for j : Integer.subrange(0, m-1) do ( if ((coins[j+1]->compareTo(i)) <= 0) then ( var sub_res : OclAny := table[i - coins[j+1]+1] ; if (sub_res /= (trailer . (name maxsize)) & (sub_res + 1->compareTo(table[i+1])) < 0) then ( table[i+1] := sub_res + 1 ) else skip ) else skip)) ; return table[V+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(t)for t in input().split()] res=0 i=0 while itoInteger() ; var a : Sequence := input().split()->select(t | true)->collect(t | (("" + ((t)))->toInteger())) ; var res : int := 0 ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( var j : int := i ; while (j->compareTo(n)) < 0 & a[i+1] = a[j+1] do ( j := j + 1) ; res := res + (j - i) * (j - i + 1) div 2 ; i := j) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() array=input().split() cur=array[0] count=0 result=0 for elem in array : if elem==cur : count+=1 else : result+=count*(count+1)>>1 cur=elem count=1 result+=count*(count+1)>>1 print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var array : OclAny := input().split() ; var cur : OclAny := array->first() ; var count : int := 0 ; var result : int := 0 ; for elem : array do ( if elem = cur then ( count := count + 1 ) else ( result := result + count * (count + 1) /(2->pow(1)) ; cur := elem ; count := 1 )) ; result := result + count * (count + 1) /(2->pow(1)) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) t,ans=1,0 for i in range(n-1): if(a[i]==a[i+1]): t+=1 else : ans+=(t*(t-1))//2+t t=1 ans+=(t*(t-1))//2+t print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : OclAny := null; var ans : OclAny := null; Sequence{t,ans} := Sequence{1,0} ; for i : Integer.subrange(0, n - 1-1) do ( if (a[i+1] = a[i + 1+1]) then ( t := t + 1 ) else ( ans := ans + (t * (t - 1)) div 2 + t ; var t : int := 1 )) ; ans := ans + (t * (t - 1)) div 2 + t ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- groups=[] ints=int(input()) nums=list(map(int,input().split(' '))) curr=nums[0] total=0 for i in nums : if i==curr : total+=1 else : groups.append(total) curr=i total=1 if total!=0 : groups.append(total) ans=0 for i in groups : ans+=int(i*(i+1)/2) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var groups : Sequence := Sequence{} ; var ints : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nums : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var curr : OclAny := nums->first() ; var total : int := 0 ; for i : nums do ( if i = curr then ( total := total + 1 ) else ( execute ((total) : groups) ; curr := i ; total := 1 )) ; if total /= 0 then ( execute ((total) : groups) ) else skip ; var ans : int := 0 ; for i : groups do ( ans := ans + ("" + ((i * (i + 1) / 2)))->toInteger()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import numpy as np read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines n=int(readline()) a=np.array(read().split(),np.int64).reshape(-1,2) for x in range(n-1): if a[x][0]>a[x][1]: a[x][0],a[x][1]=a[x][1],a[x][0] v=0 for x in range(n): v+=(x+1)*(n-x) e=0 for x in range(n-1): e+=a[x][0]*(n-a[x][1]+1) print(v-e) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; var n : int := ("" + ((readline())))->toInteger() ; var a : OclAny := np.array(read().split(), ).reshape(-1, 2) ; for x : Integer.subrange(0, n - 1-1) do ( if (a[x+1]->first()->compareTo(a[x+1][1+1])) > 0 then ( var a[x+1]->first() : OclAny := null; var a[x+1][1+1] : OclAny := null; Sequence{a[x+1]->first(),a[x+1][1+1]} := Sequence{a[x+1][1+1],a[x+1]->first()} ) else skip) ; var v : int := 0 ; for x : Integer.subrange(0, n-1) do ( v := v + (x + 1) * (n - x)) ; var e : int := 0 ; for x : Integer.subrange(0, n - 1-1) do ( e := e + a[x+1]->first() * (n - a[x+1][1+1] + 1)) ; execute (v - e)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=input().split() count=0 last=-1 for i in range(N+1): if(i==0): last=i continue if(i==N or A[i]!=A[i-1]): size=i-last last=i count+=((size*size)+size)//2 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : OclAny := input().split() ; var count : int := 0 ; var last : int := -1 ; for i : Integer.subrange(0, N + 1-1) do ( if (i = 0) then ( last := i ; continue ) else skip ; if (i = N or A[i+1] /= A[i - 1+1]) then ( var size : double := i - last ; last := i ; count := count + ((size * size) + size) div 2 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q,w,e=map(int,input().split()) a=q+w a=e % a if acollect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := q + w ; a := e mod a ; if (a->compareTo(w)) < 0 then ( execute (a)->display() ) else (if (w->compareTo(a)) <= 0 & (a <= q) then ( execute (w)->display() ) else ( execute ((q + w) - a)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findY(x): if(x>2): return x-2 return x+2 if __name__=='__main__' : x=5 print(findY(x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( x := 5 ; execute (findY(x))->display() ) else skip; operation findY(x : OclAny) : OclAny pre: true post: true activity: if (x > 2) then ( return x - 2 ) else skip ; return x + 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,k,t=map(int,input().split()) if t in range(0,k+1): print(t) elif t in range(k+1,n+1): print(k) else : print(k-(t-n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var k : OclAny := null; var t : OclAny := null; Sequence{n,k,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (Integer.subrange(0, k + 1-1))->includes(t) then ( execute (t)->display() ) else (if (Integer.subrange(k + 1, n + 1-1))->includes(t) then ( execute (k)->display() ) else ( execute (k - (t - n))->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,k,t=map(int,input().split()) if(t<=k): print(t) elif(t>=a): print(a+k-t) else : print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var k : OclAny := null; var t : OclAny := null; Sequence{a,k,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if ((t->compareTo(k)) <= 0) then ( execute (t)->display() ) else (if ((t->compareTo(a)) >= 0) then ( execute (a + k - t)->display() ) else ( execute (k)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solution(n,k,t): if ttrim().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (solution(n, k, t))->display(); operation solution(n : OclAny, k : OclAny, t : OclAny) : OclAny pre: true post: true activity: if (t->compareTo(k)) < 0 then ( return t ) else (if (t->compareTo(n)) <= 0 then ( return k ) else ( return k - (t - n) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def result(n,k,t): if(t<=k): print(t) elif(t<=n): print(k) else : temp=t-n temp=k-temp print(temp) s=input().split() n,k,t=int(s[0]),int(s[1]),int(s[2]) result(n,k,t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : OclAny := input().split() ; Sequence{n,k,t} := Sequence{("" + ((s->first())))->toInteger(),("" + ((s[1+1])))->toInteger(),("" + ((s[2+1])))->toInteger()} ; result(n, k, t); operation result(n : OclAny, k : OclAny, t : OclAny) pre: true post: true activity: if ((t->compareTo(k)) <= 0) then ( execute (t)->display() ) else (if ((t->compareTo(n)) <= 0) then ( execute (k)->display() ) else ( var temp : double := t - n ; temp := k - temp ; execute (temp)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for p in range(int(input())): n=int(input()) a=input() b=input() a+="0" b+="0" f,p=0,0 for i in range(n): if a[i]=="1" : x=1 else : x=0 if a[i]=="0" : y=1 else : y=0 f+=(x-y) if a[i]==b[i]: w=1 else : w=0 if a[i+1]==b[i+1]: z=1 else : z=0 if w!=z and f!=0 : p=1 print("NO") break if not p : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for p : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; a := a + "0" ; b := b + "0" ; var f : OclAny := null; var p : OclAny := null; Sequence{f,p} := Sequence{0,0} ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = "1" then ( var x : int := 1 ) else ( x := 0 ) ; if a[i+1] = "0" then ( var y : int := 1 ) else ( y := 0 ) ; f := f + (x - y) ; if a[i+1] = b[i+1] then ( var w : int := 1 ) else ( w := 0 ) ; if a[i + 1+1] = b[i + 1+1] then ( var z : int := 1 ) else ( z := 0 ) ; if w /= z & f /= 0 then ( var p : int := 1 ; execute ("NO")->display() ; break ) else skip) ; if not(p) then ( execute ("YES")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import* import heapq as h from collections import Counter mod=998244353 def pro(arr,b): n=len(arr) a,b1=0,0 j=0 lst=[] for i in range(n): if(arr[i]=='1'): a+=1 else : b1+=1 if(a==b1): lst.append((j,i)) j=i+1 for i in lst : x,y=i f=0 for j in range(x,y+1): if(arr[j]!=b[j]): f=1 break if(f==0): continue for j in range(x,y+1): if(arr[j]=='1'): arr[j]='0' else : arr[j]='1' if(arr==b): print('YES') else : print('NO') t=int(input()) for i in range(t): n=int(input()) arr=list(input()) b=list(input()) pro(arr,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var mod : int := 998244353 ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; arr := ((OclFile["System.in"]).readLine())->characters() ; b := ((OclFile["System.in"]).readLine())->characters() ; pro(arr, b)); operation pro(arr : OclAny, b : OclAny) pre: true post: true activity: var n : int := (arr)->size() ; var a : OclAny := null; var b1 : OclAny := null; Sequence{a,b1} := Sequence{0,0} ; var j : int := 0 ; var lst : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] = '1') then ( a := a + 1 ) else ( b1 := b1 + 1 ) ; if (a = b1) then ( execute ((Sequence{j, i}) : lst) ; j := i + 1 ) else skip) ; for i : lst do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := i ; var f : int := 0 ; for j : Integer.subrange(x, y + 1-1) do ( if (arr[j+1] /= b[j+1]) then ( f := 1 ; break ) else skip) ; if (f = 0) then ( continue ) else skip ; for j : Integer.subrange(x, y + 1-1) do ( if (arr[j+1] = '1') then ( arr[j+1] := '0' ) else ( arr[j+1] := '1' ))) ; if (arr = b) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=input() b=input() counts=[0,0] take_other=False for i in range(n): counts[int(a[i])]+=1 for i in range(n-1,-2,-1): if i==-1 : break if take_other : if a[i]==b[i]: if counts[0]!=counts[1]: break else : take_other=not take_other counts[0],counts[1]=counts[1],counts[0] counts[int(a[i])]-=1 continue counts[int(a[i])^ 1]-=1 else : if a[i]!=b[i]: if counts[0]!=counts[1]: break else : take_other=not take_other counts[0],counts[1]=counts[1],counts[0] counts[int(a[i])^ 1]-=1 continue counts[int(a[i])]-=1 if i<0 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var counts : Sequence := Sequence{0}->union(Sequence{ 0 }) ; var take_other : boolean := false ; for i : Integer.subrange(0, n-1) do ( counts[("" + ((a[i+1])))->toInteger()+1] := counts[("" + ((a[i+1])))->toInteger()+1] + 1) ; for i : Integer.subrange(-2 + 1, n - 1)->reverse() do ( if i = -1 then ( break ) else skip ; if take_other then ( if a[i+1] = b[i+1] then ( if counts->first() /= counts[1+1] then ( break ) else ( take_other := not(take_other) ; var counts->first() : OclAny := null; var counts[1+1] : OclAny := null; Sequence{counts->first(),counts[1+1]} := Sequence{counts[1+1],counts->first()} ; counts[("" + ((a[i+1])))->toInteger()+1] := counts[("" + ((a[i+1])))->toInteger()+1] - 1 ; continue ) ) else skip ; counts[MathLib.bitwiseXor(("" + ((a[i+1])))->toInteger(), 1)+1] := counts[MathLib.bitwiseXor(("" + ((a[i+1])))->toInteger(), 1)+1] - 1 ) else ( if a[i+1] /= b[i+1] then ( if counts->first() /= counts[1+1] then ( break ) else ( take_other := not(take_other) ; var counts->first() : OclAny := null; var counts[1+1] : OclAny := null; Sequence{counts->first(),counts[1+1]} := Sequence{counts[1+1],counts->first()} ; counts[MathLib.bitwiseXor(("" + ((a[i+1])))->toInteger(), 1)+1] := counts[MathLib.bitwiseXor(("" + ((a[i+1])))->toInteger(), 1)+1] - 1 ; continue ) ) else skip ; counts[("" + ((a[i+1])))->toInteger()+1] := counts[("" + ((a[i+1])))->toInteger()+1] - 1 )) ; if i < 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n=int(input()) s=input()[:-1]+'0' w=input()[:-1]+'0' c=0 for i in range(n): c+=(s[i]=='1')-(s[i]=='0') if(s[i]==w[i])!=(s[i+1]==w[i+1])and c!=0 : print('NO') break else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := input()->front() + '0' ; var w : OclAny := input()->front() + '0' ; var c : int := 0 ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom '1'))))))) ))) - (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom '0'))))))) )))))))))))) (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))) != (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])))) == (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])))))))) )))))) and (logical_test (comparison (comparison (expr (atom (name c)))) != (comparison (expr (atom (number (integer 0))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math input=sys.stdin.readline rs=lambda : input().strip() ri=lambda : int(input()) rl=lambda : list(map(int,input().split())) mod=10**9+7 N=ri() import collections edges=collections.defaultdict(list) for i in range(N-1): u,v=rl() if vtrim()) ; var ri : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var rl : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var mod : double := (10)->pow(9) + 7 ; var N : OclAny := ri->apply() ; skip ; var edges : OclAny := .defaultdict(OclType["Sequence"]) ; for i : Integer.subrange(0, N - 1-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := rl->apply() ; if (v->compareTo(u)) < 0 then ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := Sequence{v,u} ) else skip ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name u))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1)))))))))) ))))) ; var s : int := 0 ; for i : Integer.subrange(0, N-1) do ( for e : edges[i+1] do ( s := s + N - 1 - e + 1)) ; var ans : double := N * ((N)->pow(2) + 3 * N + 2) div 6 - s ; for i : Integer.subrange(0, N-1) do ( if edges[i+1] then ( for e : edges[i+1] do ( s := s - (N - 1 - e + 1)) ) else skip ; ans := ans - s) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque from math import* import sys import random from bisect import* from functools import reduce def solve(a,b,n): b=b+'0' a=a+'0' ans=0 for i in range(n): ans+=(a[i]=='1')-(a[i]=='0') if((a[i]==b[i])!=(a[i+1]==b[i+1])and ans!=0): return "NO" return "YES" for _ in range(int(input())): n=int(input()) a=input() b=input() print(solve(a,b,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := (OclFile["System.in"]).readLine() ; b := (OclFile["System.in"]).readLine() ; execute (solve(a, b, n))->display()); operation solve(a : OclAny, b : OclAny, n : OclAny) : OclAny pre: true post: true activity: b := b + '0' ; a := a + '0' ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( ans := ans + (a[i+1] = '1') - (a[i+1] = '0') ; if ((a[i+1] = b[i+1]) /= (a[i + 1+1] = b[i + 1+1]) & ans /= 0) then ( return "NO" ) else skip) ; return "YES"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=1000000007 def modFact(n,m): result=1 for i in range(1,m+1): result=(result*i)% MOD return result n=3 m=2 print(modFact(n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : int := 1000000007 ; skip ; n := 3 ; m := 2 ; execute (modFact(n, m))->display(); operation modFact(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var result : int := 1 ; for i : Integer.subrange(1, m + 1-1) do ( result := (result * i) mod MOD) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) cin=lambda : map(int,input().split()) x=500 sum=0 for i,j in zip(cin(),cin()): sum+=max(0.3*x,(1-i/250)*x-50*j) x+=500 s,u=cin() print(int(sum+100*s-50*u)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cin : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : int := 500 ; var sum : int := 0 ; for _tuple : Integer.subrange(1, cin->apply()->size())->collect( _indx | Sequence{cin->apply()->at(_indx), cin->apply()->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); sum := sum + Set{0.3 * x, (1 - i / 250) * x - 50 * j}->max() ; x := x + 500) ; var s : OclAny := null; var u : OclAny := null; Sequence{s,u} := cin->apply() ; execute (("" + ((sum + 100 * s - 50 * u)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline x=[500,1000,1500,2000,2500] m=list(map(int,input().split())) w=list(map(int,input().split())) s,u=map(int,input().split()) c=s*100-u*50 for i in range(5): c+=max(0.3*x[i],(1-m[i]/250)*x[i]-50*w[i]) print(int(c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var x : Sequence := Sequence{500}->union(Sequence{1000}->union(Sequence{1500}->union(Sequence{2000}->union(Sequence{ 2500 })))) ; var m : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : OclAny := null; var u : OclAny := null; Sequence{s,u} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : double := s * 100 - u * 50 ; for i : Integer.subrange(0, 5-1) do ( c := c + Set{0.3 * x[i+1], (1 - m[i+1] / 250) * x[i+1] - 50 * w[i+1]}->max()) ; execute (("" + ((c)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=list(map(int,input().split())) y=list(map(int,input().split())) z=list(map(int,input().split())) t=0 for i in range(1,len(x)+1): t+=max(0.3*500*i,(1-x[i-1]/250)*500*i-50*y[i-1]) print(int(t+z[0]*100-z[1]*50)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var y : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var z : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : int := 0 ; for i : Integer.subrange(1, (x)->size() + 1-1) do ( t := t + Set{0.3 * 500 * i, (1 - x[i - 1+1] / 250) * 500 * i - 50 * y[i - 1+1]}->max()) ; execute (("" + ((t + z->first() * 100 - z[1+1] * 50)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- time_spent_on_problems=list(map(int,input().split(' '))) wrong_submission_on_problems=list(map(int,input().split(' '))) (successful_hacks,unsuccessful_hacks)=map(int,input().split(' ')) maximum_points_per_problem=[500,1000,1500,2000,2500] points_on_problems=[] for i in range(5): points_on_problems.append(max(0.3*maximum_points_per_problem[i],(1-time_spent_on_problems[i]/250)*maximum_points_per_problem[i]-50*wrong_submission_on_problems[i])) print(int(sum(points_on_problems)+successful_hacks*100-unsuccessful_hacks*50)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var time_spent_on_problems : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var wrong_submission_on_problems : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var Sequence{successful_hacks, unsuccessful_hacks} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var maximum_points_per_problem : Sequence := Sequence{500}->union(Sequence{1000}->union(Sequence{1500}->union(Sequence{2000}->union(Sequence{ 2500 })))) ; var points_on_problems : Sequence := Sequence{} ; for i : Integer.subrange(0, 5-1) do ( execute ((Set{0.3 * maximum_points_per_problem[i+1], (1 - time_spent_on_problems[i+1] / 250) * maximum_points_per_problem[i+1] - 50 * wrong_submission_on_problems[i+1]}->max()) : points_on_problems)) ; execute (("" + (((points_on_problems)->sum() + successful_hacks * 100 - unsuccessful_hacks * 50)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- time=list(map(int,input().split())) w=list(map(int,input().split())) h=list(map(int,input().split())) score=0 for i in range(5): score+=max(0.3*500*(i+1),((1-(time[i]/250))*(500*(i+1))-(50*w[i]))) score+=(100)*h[0] score-=(50)*h[1] print(int(score)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var time : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var h : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var score : int := 0 ; for i : Integer.subrange(0, 5-1) do ( score := score + Set{0.3 * 500 * (i + 1), ((1 - (time[i+1] / 250)) * (500 * (i + 1)) - (50 * w[i+1]))}->max()) ; score := score + (100) * h->first() ; score := score - (50) * h[1+1] ; execute (("" + ((score)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): INF=float('inf') V,E=map(int,input().split()) G=[[INF for i in range(V)]for j in range(V)] for i in range(V): G[i][i]=0 for i in range(E): s,t=map(int,input().split()) G[s][t]=-1 for k in range(V): for i in range(V): for j in range(V): G[i][j]=min(G[i][j],G[i][k]+G[k][j]) for i in range(V): if G[i][i]: print(1) break else : print(0) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var INF : double := ("" + (('inf')))->toReal() ; var V : OclAny := null; var E : OclAny := null; Sequence{V,E} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var G : Sequence := Integer.subrange(0, V-1)->select(j | true)->collect(j | (Integer.subrange(0, V-1)->select(i | true)->collect(i | (INF)))) ; for i : Integer.subrange(0, V-1) do ( G[i+1][i+1] := 0) ; for i : Integer.subrange(0, E-1) do ( var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; G[s+1][t+1] := -1) ; for k : Integer.subrange(0, V-1) do ( for i : Integer.subrange(0, V-1) do ( for j : Integer.subrange(0, V-1) do ( G[i+1][j+1] := Set{G[i+1][j+1], G[i+1][k+1] + G[k+1][j+1]}->min()))) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name V)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def generate_graph_table(edges): for edge in edges : source,target=map(int,edge) init_adj_table[source].append(target) return init_adj_table def graph_dfs(current,visited,stack): if not visited[current]: visited[current]=True stack[current]=True for adj in adj_table[current]: if not visited[adj]and graph_dfs(adj,visited,stack): return True elif stack[adj]: return True stack[current]=False return False def check_cyclic(): visited,stack=([False]*v_num for _ in range(2)) for v in range(v_num): if graph_dfs(v,visited,stack): return True return False if __name__=='__main__' : _input=sys.stdin.readlines() v_num,e_num=map(int,_input[0].split()) c_edges=map(lambda x : x.split(),_input[1 :]) init_adj_table=tuple(list()for _ in range(v_num)) adj_table=generate_graph_table(c_edges) print(int(check_cyclic())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var _input : OclAny := (OclFile["System.in"]).readlines() ; var v_num : OclAny := null; var e_num : OclAny := null; Sequence{v_num,e_num} := (_input->first().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c_edges : Sequence := (_input->tail())->collect( _x | (lambda x : OclAny in (x.split()))->apply(_x) ) ; var init_adj_table : Sequence := ((argument (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v_num)))))))) ))))))))) ; var adj_table : OclAny := generate_graph_table(c_edges) ; execute (("" + ((check_cyclic())))->toInteger())->display() ) else skip; operation generate_graph_table(edges : OclAny) : OclAny pre: true post: true activity: for edge : edges do ( var source : OclAny := null; var target : OclAny := null; Sequence{source,target} := (edge)->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name init_adj_table)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name source)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name target)))))))) ))))) ; return init_adj_table; operation graph_dfs(current : OclAny, visited : OclAny, stack : OclAny) : OclAny pre: true post: true activity: if not(visited[current+1]) then ( visited[current+1] := true ; stack[current+1] := true ; for adj : adj_table[current+1] do ( if not(visited[adj+1]) & graph_dfs(adj, visited, stack) then ( return true ) else (if stack[adj+1] then ( return true ) else skip)) ) else skip ; stack[current+1] := false ; return false; operation check_cyclic() : OclAny pre: true post: true activity: Sequence{visited,stack} := Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name False))))))) ])) * (expr (atom (name v_num))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ))))))))} ; for v : Integer.subrange(0, v_num-1) do ( if graph_dfs(v, visited, stack) then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,collections as cl,bisect as bs sys.setrecursionlimit(100000) Max=sys.maxsize def l(): return list(map(int,input().split())) def m(): return map(int,input().split()) def onem(): return int(input()) def s(x): a=[] aa=x[0] su=1 for i in range(len(x)-1): if aa==x[i+1]: a.append([aa,su]) aa=x[i+1] su=1 else : su+=1 a.append([aa,su]) return a def jo(x): return " ".join(map(str,x)) def max2(x): return max(map(max,x)) def Topo_sort(x,y): co=cl.Counter(n for m in x.values()for n in m) S=cl.deque([i for i in range(y)if co[i]==0]) while S : n=S.popleft() yield n for i in x[n]: co[i]-=1 if co[i]<=0 : S.append(i) if sum(co.values())!=0 : print(1) exit() else : print(0) exit() v,e=m() g=cl.defaultdict(set) for i in range(e): s,t=m() g[s]|={t} a=list(Topo_sort(g,v)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(100000) ; var Max : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var v : OclAny := null; var e : OclAny := null; Sequence{v,e} := m() ; var g : OclAny := cl.defaultdict(OclType["Set"]) ; for i : Integer.subrange(0, e-1) do ( var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := m() ; g[s+1] := g[s+1] or Set{ t }) ; a := (Topo_sort(g, v)); operation l() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation m() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation onem() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation s(x : OclAny) : OclAny pre: true post: true activity: var a : Sequence := Sequence{} ; var aa : OclAny := x->first() ; var su : int := 1 ; for i : Integer.subrange(0, (x)->size() - 1-1) do ( if aa = x[i + 1+1] then ( execute ((Sequence{aa}->union(Sequence{ su })) : a) ; aa := x[i + 1+1] ; su := 1 ) else ( su := su + 1 )) ; execute ((Sequence{aa}->union(Sequence{ su })) : a) ; return a; operation jo(x : OclAny) : OclAny pre: true post: true activity: return StringLib.sumStringsWithSeparator(((x)->collect( _x | (OclType["String"])->apply(_x) )), " "); operation max2(x : OclAny) : OclAny pre: true post: true activity: return ((x)->collect( _x | (max)->apply(_x) ))->max(); operation Topo_sort(x : OclAny, y : OclAny) pre: true post: true activity: var co : OclAny := cl.Counter((argument (test (logical_test (comparison (expr (atom (name n)))))) (comp_for for (exprlist (expr (atom (name m)))) in (logical_test (comparison (expr (atom (name x)) (trailer . (name values) (arguments ( )))))) (comp_iter (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name m)))))))))) ; var S : OclAny := cl(Integer.subrange(0, y-1)->select(i | co[i+1] = 0)->collect(i | (i))) ; while S do ( var n : OclAny := S->first() ; S := S->tail() ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return n ; for i : x[n+1] do ( co[i+1] := co[i+1] - 1 ; if co[i+1] <= 0 then ( execute ((i) : S) ) else skip)) ; if (co.values())->sum() /= 0 then ( execute (1)->display() ; exit() ) else ( execute (0)->display() ; exit() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- [vertex,edge]=list(map(int,input("").split())) array=[[0 for j in range(vertex)]for i in range(vertex)] for i in range(edge): data=list(map(int,input("").split())) array[data[0]][data[1]]=1 visited=[0 for j in range(vertex)] result=0 def dfs(node,goal): for t in range(vertex): visited[node]=1 if array[node][t]!=0 and t==goal : global result result=1 if array[node][t]!=0 and visited[t]==0 : dfs(t,goal) for i in range(vertex): visited=[0 for j in range(vertex)] dfs(i,i) if result==1 : print(1) break if result==0 : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute result : OclAny; operation initialise() pre: true post: true activity: Sequence{vertex}->union(Sequence{ edge }) := ((input("").split())->collect( _x | (OclType["int"])->apply(_x) )) ; var array : Sequence := Integer.subrange(0, vertex-1)->select(i | true)->collect(i | (Integer.subrange(0, vertex-1)->select(j | true)->collect(j | (0)))) ; for i : Integer.subrange(0, edge-1) do ( var data : Sequence := ((input("").split())->collect( _x | (OclType["int"])->apply(_x) )) ; array[data->first()+1][data[1+1]+1] := 1) ; var visited : Sequence := Integer.subrange(0, vertex-1)->select(j | true)->collect(j | (0)) ; var result : int := 0 ; skip ; for i : Integer.subrange(0, vertex-1) do ( visited := Integer.subrange(0, vertex-1)->select(j | true)->collect(j | (0)) ; dfs(i, i) ; if result = 1 then ( execute (1)->display() ; break ) else skip) ; if result = 0 then ( execute (0)->display() ) else skip; operation dfs(node : OclAny, goal : OclAny) pre: true post: true activity: for t : Integer.subrange(0, vertex-1) do ( visited[node+1] := 1 ; if array[node+1][t+1] /= 0 & t = goal then ( skip ; result := 1 ) else skip ; if array[node+1][t+1] /= 0 & visited[t+1] = 0 then ( dfs(t, goal) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(): c=0 for W in iter(input,'0'): c+=1 W=int(W) d=[0]*-~ W for _ in[0]*int(input()): v,w=map(int,input().split(',')) for i in range(W,w-1,-1): if d[i]toInteger() ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, -MathLib.bitwiseNot(W)) ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var v : OclAny := null; var w : OclAny := null; Sequence{v,w} := (input().split(','))->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(w - 1 + 1, W)->reverse() do ( if (d[i+1]->compareTo(d[i - w+1] + v)) < 0 then ( d[i+1] := d[i - w+1] + v ) else skip)) ; execute (StringLib.formattedString('Case{c}: {d[W]} {d.index(d[W])}'))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) c=0 for i in range(n): m=i for j in range(i,n): if a[m]>a[j]: m=j if i!=m : a[m],a[i]=a[i],a[m]; c+=1 print(*a) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( var m : OclAny := i ; for j : Integer.subrange(i, n-1) do ( if (a[m+1]->compareTo(a[j+1])) > 0 then ( m := j ) else skip) ; if i /= m then ( var a[m+1] : OclAny := null; var a[i+1] : OclAny := null; Sequence{a[m+1],a[i+1]} := Sequence{a[i+1],a[m+1]}; c := c + 1 ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display() ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque import sys def dfs(G,u): n=len(G) vis=[-1]*n stackV=[] pila=deque() pila.append(u) vis[u]=1 stackV.append(u) while(pila): w=pila.pop() for v in G[w]: if(vis[v]==-1): vis[v]=1 pila.append(v) stackV.append(v) elif(vis[v]==1 and v==u): return True return False def main(): G=[] val=[int(x)for x in sys.stdin.readline().strip().split()] for i in range(val[0]): G.append([]) for i in range(val[1]): L=[int(x)for x in sys.stdin.readline().strip().split()] G[L[0]].append(L[1]) veri=[] for i in range(val[0]): veri.append(dfs(G,i)) if(True in veri): print(1) else : print(0) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; main(); operation dfs(G : OclAny, u : OclAny) : OclAny pre: true post: true activity: var n : int := (G)->size() ; var vis : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; var stackV : Sequence := Sequence{} ; var pila : Sequence := () ; execute ((u) : pila) ; vis[u+1] := 1 ; execute ((u) : stackV) ; while (pila) do ( var w : OclAny := pila->last() ; pila := pila->front() ; for v : G[w+1] do ( if (vis[v+1] = -1) then ( vis[v+1] := 1 ; execute ((v) : pila) ; execute ((v) : stackV) ) else (if (vis[v+1] = 1 & v = u) then ( return true ) else skip))) ; return false; operation main() pre: true post: true activity: G := Sequence{} ; var val : Sequence := sys.stdin.readLine()->trim().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for i : Integer.subrange(0, val->first()-1) do ( execute ((Sequence{}) : G)) ; for i : Integer.subrange(0, val[1+1]-1) do ( var L : Sequence := sys.stdin.readLine()->trim().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ))))) ; var veri : Sequence := Sequence{} ; for i : Integer.subrange(0, val->first()-1) do ( execute ((dfs(G, i)) : veri)) ; if ((veri)->includes(true)) then ( execute (1)->display() ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get(): return list(map(int,input().split())) def intput(): return int(input()) def dfs(h,a,v): if(h<=0): return True if(h>20 and a>0): return dfs(h//2+10,a-1,v) elif(v>0): return dfs(h-10,a,v-1) else : return False def main(): for _ in range(intput()): a=get() print("YES" if dfs(a[0],a[1],a[2])else "NO") main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; main(); operation get() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation intput() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation dfs(h : OclAny, a : OclAny, v : OclAny) : OclAny pre: true post: true activity: if (h <= 0) then ( return true ) else skip ; if (h > 20 & a > 0) then ( return dfs(h div 2 + 10, a - 1, v) ) else (if (v > 0) then ( return dfs(h - 10, a, v - 1) ) else ( return false ) ) ; operation main() pre: true post: true activity: for _anon : Integer.subrange(0, intput()-1) do ( a := get() ; execute (if dfs(a->first(), a[1+1], a[2+1]) then "YES" else "NO" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import threading from functools import lru_cache def main(): T=int(input()) for _ in range(T): x,n,m=[int(i)for i in input().split()] current=x light=m*10 while current>light : if n==0 : break current=current//2+10 n-=1 if current<=light : print("YES") else : print("NO") if __name__=='__main__' : sys.setrecursionlimit(1<<30) threading.stack_size(1<<27) main_thread=threading.Thread(target=main) main_thread.start() main_thread.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( sys.setrecursionlimit(1 * (2->pow(30))) ; threading.stack_size(1 * (2->pow(27))) ; var main_thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ; main_thread.start() ; main_thread.join() ) else skip; operation main() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, T-1) do ( var x : OclAny := null; var n : OclAny := null; var m : OclAny := null; Sequence{x,n,m} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var current : OclAny := x ; var light : double := m * 10 ; while (current->compareTo(light)) > 0 do ( if n = 0 then ( break ) else skip ; current := current div 2 + 10 ; n := n - 1) ; if (current->compareTo(light)) <= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): x,n,m=list(map(int,input().split())) while x//2+100 and m : x-=10 m-=1 if x>0 : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var x : OclAny := null; var n : OclAny := null; var m : OclAny := null; Sequence{x,n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; while (x div 2 + 10->compareTo(x)) < 0 & n do ( x := x div 2 ; x := x + 10 ; n := n - 1) ; while x > 0 & m do ( x := x - 10 ; m := m - 1) ; if x > 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x,n,m=map(int,input().split()) i=0 while x>=20 and itoInteger()-1) do ( var x : OclAny := null; var n : OclAny := null; var m : OclAny := null; Sequence{x,n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var i : int := 0 ; while x >= 20 & (i->compareTo(n)) < 0 do ( i := i + 1 ; var x : int := x div 2 + 10) ; execute (if (x->compareTo(10 * m)) <= 0 then 'YES' else 'NO' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for i in range(int(input())): x,v,l=map(int,input().split()) while(v>0): if x<=17 : break else : x=math.floor(x/2)+10 v=v-1 while(l>0): x=x-10 l=l-1 if x<=0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var v : OclAny := null; var l : OclAny := null; Sequence{x,v,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; while (v > 0) do ( if x <= 17 then ( break ) else ( var x : double := (x / 2)->floor() + 10 ) ; var v : double := v - 1) ; while (l > 0) do ( x := x - 10 ; var l : double := l - 1) ; if x <= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,m,r=map(int,input().split()) l,s=[],set() while r not in s : s.add(r) l.append(r) r=(a*r+b)% m print(len(l)-l.index(r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var m : OclAny := null; var r : OclAny := null; Sequence{a,b,m,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : OclAny := null; var s : OclAny := null; Sequence{l,s} := Sequence{Sequence{},Set{}->union(())} ; while (s)->excludes(r) do ( execute ((r) : s) ; execute ((r) : l) ; var r : int := (a * r + b) mod m) ; execute ((l)->size() - l->indexOf(r) - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,m,r=map(int,input().split()) l,s=[],set() while r not in s : s.add(r) l.append(r) r=(a*r+b)% m print(len(l)-l.index(r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var m : OclAny := null; var r : OclAny := null; Sequence{a,b,m,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : OclAny := null; var s : OclAny := null; Sequence{l,s} := Sequence{Sequence{},Set{}->union(())} ; while (s)->excludes(r) do ( execute ((r) : s) ; execute ((r) : l) ; var r : int := (a * r + b) mod m) ; execute ((l)->size() - l->indexOf(r) - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,m,r=list(map(int,input().split())) f=lambda x :(a*x+b)% m memo=[0 for _ in range(m)] i=0 answer=1 while i<=m : z=f(r) r=z i+=1 if memo[z]: answer=i-memo[z] break else : memo[z]=i print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var m : OclAny := null; var r : OclAny := null; Sequence{a,b,m,r} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var f : Function := lambda x : OclAny in ((a * x + b) mod m) ; var memo : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (0)) ; var i : int := 0 ; var answer : int := 1 ; while (i->compareTo(m)) <= 0 do ( var z : String := f->apply(r) ; var r : String := z ; i := i + 1 ; if memo->at(z) then ( answer := i - memo->at(z) ; break ) else ( memo->at(z) := i )) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline a,b,m,r0=map(int,input().split()) d=[r0] i=0 while i1 : a=d.index(d[i]) b=d.index(d[i],a+1) print(b-a) break i+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var a : OclAny := null; var b : OclAny := null; var m : OclAny := null; var r0 : OclAny := null; Sequence{a,b,m,r0} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := Sequence{ r0 } ; var i : int := 0 ; while (i->compareTo(m + 1)) < 0 do ( execute (((a * d->last() + b) mod m) : d) ; i := i + 1) ; i := 0 ; while i < 1000 do ( if d->count(d[i+1]) > 1 then ( var a : int := d->indexOf(d[i+1]) - 1 ; var b : int := d->indexOf(d[i+1], a + 1) - 1 ; execute (b - a)->display() ; break ) else skip ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getMinimumOps(ar): n=len(ar) small=min(ar) large=max(ar) dp=[[0 for i in range(large+1)]for i in range(n)] for j in range(small,large+1): dp[0][j]=abs(ar[0]-j) for i in range(1,n): minimum=10**9 for j in range(small,large+1): minimum=min(minimum,dp[i-1][j]) dp[i][j]=minimum+abs(ar[i]-j) ans=10**9 for j in range(small,large+1): ans=min(ans,dp[n-1][j]) return ans ar=[1,2,1,4,3] print(getMinimumOps(ar)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; ar := Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{4}->union(Sequence{ 3 })))) ; execute (getMinimumOps(ar))->display(); operation getMinimumOps(ar : OclAny) : OclAny pre: true post: true activity: var n : int := (ar)->size() ; var small : OclAny := (ar)->min() ; var large : OclAny := (ar)->max() ; var dp : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, large + 1-1)->select(i | true)->collect(i | (0)))) ; for j : Integer.subrange(small, large + 1-1) do ( dp->first()[j+1] := (ar->first() - j)->abs()) ; for i : Integer.subrange(1, n-1) do ( var minimum : double := (10)->pow(9) ; for j : Integer.subrange(small, large + 1-1) do ( minimum := Set{minimum, dp[i - 1+1][j+1]}->min() ; dp[i+1][j+1] := minimum + (ar[i+1] - j)->abs())) ; var ans : double := (10)->pow(9) ; for j : Integer.subrange(small, large + 1-1) do ( ans := Set{ans, dp[n - 1+1][j+1]}->min()) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def selectionSort(table): swap_count=0 for nAchieve in range(len(table)): min_index=nAchieve for i in range(nAchieve,len(table)): if table[i]toInteger() ; table := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; swap_count := selectionSort(table) ; execute (StringLib.sumStringsWithSeparator(((table)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ; execute (swap_count)->display(); operation selectionSort(table : OclAny) : OclAny pre: true post: true activity: var swap_count : int := 0 ; for nAchieve : Integer.subrange(0, (table)->size()-1) do ( var min_index : OclAny := nAchieve ; for i : Integer.subrange(nAchieve, (table)->size()-1) do ( if (table[i+1]->compareTo(table[min_index+1])) < 0 then ( min_index := i ) else skip) ; if min_index /= nAchieve then ( var table[min_index+1] : OclAny := null; var table[nAchieve+1] : OclAny := null; Sequence{table[min_index+1],table[nAchieve+1]} := Sequence{table[nAchieve+1],table[min_index+1]} ; swap_count := swap_count + 1 ) else skip) ; return swap_count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- nCase=0 while True : W=int(input()) if W==0 : break nCase+=1 N=int(input()) items=[tuple(map(int,input().split(',')))for _ in range(N)] bestValueFor=[0]*(W+1) for item in items : for capa in reversed(range(W-item[1]+1)): if bestValueFor[capa]+item[0]>bestValueFor[capa+item[1]]: bestValueFor[capa+item[1]]=bestValueFor[capa]+item[0] bestValue=max(bestValueFor) bestWeight=bestValueFor.index(bestValue) print('Case ',str(nCase),':',sep='') print(bestValue) print(bestWeight) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var nCase : int := 0 ; while true do ( var W : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if W = 0 then ( break ) else skip ; nCase := nCase + 1 ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var items : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split(','))->collect( _x | (OclType["int"])->apply(_x) )))) ; var bestValueFor : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (W + 1)) ; for item : items do ( for capa : (Integer.subrange(0, W - item[1+1] + 1-1))->reverse() do ( if (bestValueFor[capa+1] + item->first()->compareTo(bestValueFor[capa + item[1+1]+1])) > 0 then ( bestValueFor[capa + item[1+1]+1] := bestValueFor[capa+1] + item->first() ) else skip)) ; var bestValue : OclAny := (bestValueFor)->max() ; var bestWeight : int := bestValueFor->indexOf(bestValue) - 1 ; execute ('Case ')->display() ; execute (bestValue)->display() ; execute (bestWeight)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- fact=[0]*21 def preCompute(): fact[0]=1 for i in range(1,18): fact[i]=(fact[i-1]*i) def nextFactorial(N): for i in range(21): if Nfirst() := 1 ; for i : Integer.subrange(1, 18-1) do ( fact[i+1] := (fact[i - 1+1] * i)); operation nextFactorial(N : OclAny) pre: true post: true activity: for i : Integer.subrange(0, 21-1) do ( if (N->compareTo(fact[i+1])) < 0 then ( execute (fact[i+1])->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def compute(a,b): AM=(a+b)/2 GM=math.sqrt(a*b) HM=(GM*GM)/AM return HM a=5 b=15 HM=compute(a,b) print("Harmonic Mean between ",a," and ",b," is ",HM) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 5 ; b := 15 ; HM := compute(a, b) ; execute ("Harmonic Mean between ")->display(); operation compute(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var AM : double := (a + b) / 2 ; var GM : double := (a * b)->sqrt() ; var HM : double := (GM * GM) / AM ; return HM; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def largest(arr,n): return max(arr) arr=[10,324,45,90,9808] n=len(arr) print(largest(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{10}->union(Sequence{324}->union(Sequence{45}->union(Sequence{90}->union(Sequence{ 9808 })))) ; n := (arr)->size() ; execute (largest(arr, n))->display(); operation largest(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: return (arr)->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getMedian(ar1,ar2,n): i=0 j=0 m1=-1 m2=-1 count=0 while countunion(Sequence{12}->union(Sequence{15}->union(Sequence{26}->union(Sequence{ 38 })))) ; ar2 := Sequence{2}->union(Sequence{13}->union(Sequence{17}->union(Sequence{30}->union(Sequence{ 45 })))) ; var n1 : int := (ar1)->size() ; var n2 : int := (ar2)->size() ; if n1 = n2 then ( execute ("Median is ")->display() ) else ( execute ("Doesn't work for arrays of unequal size")->display() ); operation getMedian(ar1 : OclAny, ar2 : OclAny, n : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; var j : int := 0 ; var m1 : int := -1 ; var m2 : int := -1 ; var count : int := 0 ; while (count->compareTo(n + 1)) < 0 do ( count := count + 1 ; if i = n then ( m1 := m2 ; m2 := ar2->first() ; break ) else (if j = n then ( m1 := m2 ; m2 := ar1->first() ; break ) else skip) ; if (ar1[i+1]->compareTo(ar2[j+1])) < 0 then ( m1 := m2 ; m2 := ar1[i+1] ; i := i + 1 ) else ( m1 := m2 ; m2 := ar2[j+1] ; j := j + 1 )) ; return (m1 + m2) / 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def validateStackSequence(pushed,popped): j=0 stack=[] for x in pushed : stack.append(x) while stack and junion(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ; popped := Sequence{4}->union(Sequence{5}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 1 })))) ; execute (validateStackSequence(pushed, popped))->display(); operation validateStackSequence(pushed : OclAny, popped : OclAny) : OclAny pre: true post: true activity: var j : int := 0 ; var stack : Sequence := Sequence{} ; for x : pushed do ( execute ((x) : stack) ; while stack & (j->compareTo((popped)->size())) < 0 & stack->last() = popped[j+1] do ( stack := stack->front() ; j := j + 1)) ; return j = (popped)->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- disc_time=1200 time=input().split() given_time=int(time[0])*60+int(time[1]) time_diff=abs(disc_time-given_time) val=list(map(int,input().split())) inc_hunger=time_diff*val[1] initial_hunger=val[0] cost=val[2] discount_cost=0.8*cost dec_hunger=val[3] req=-1 if(initial_hunger % dec_hunger==0): req=initial_hunger/dec_hunger else : req=initial_hunger//dec_hunger+1 cost1=req*cost req=-1 initial_hunger+=inc_hunger if(initial_hunger % dec_hunger==0): req=initial_hunger/dec_hunger else : req=initial_hunger//dec_hunger+1 cost2=req*discount_cost if given_time>=disc_time : print((cost1//cost)*discount_cost) else : print(min(cost1,cost2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var disc_time : int := 1200 ; var time : OclAny := input().split() ; var given_time : int := ("" + ((time->first())))->toInteger() * 60 + ("" + ((time[1+1])))->toInteger() ; var time_diff : double := (disc_time - given_time)->abs() ; var val : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var inc_hunger : double := time_diff * val[1+1] ; var initial_hunger : OclAny := val->first() ; var cost : OclAny := val[2+1] ; var discount_cost : double := 0.8 * cost ; var dec_hunger : OclAny := val[3+1] ; var req : int := -1 ; if (initial_hunger mod dec_hunger = 0) then ( req := initial_hunger / dec_hunger ) else ( req := initial_hunger div dec_hunger + 1 ) ; var cost1 : double := req * cost ; req := -1 ; initial_hunger := initial_hunger + inc_hunger ; if (initial_hunger mod dec_hunger = 0) then ( req := initial_hunger / dec_hunger ) else ( req := initial_hunger div dec_hunger + 1 ) ; var cost2 : double := req * discount_cost ; if (given_time->compareTo(disc_time)) >= 0 then ( execute ((cost1 div cost) * discount_cost)->display() ) else ( execute (Set{cost1, cost2}->min())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r=lambda : map(int,input().split()) h,m=r() H,D,C,N=r() H+=N-1 print(min(H//N*C,(H+max(0,1200-h*60-m)*D)//N*C*.8)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := r->apply() ; var H : OclAny := null; var D : OclAny := null; var C : OclAny := null; var N : OclAny := null; Sequence{H,D,C,N} := r->apply() ; H := H + N - 1 ; execute (Set{H div N * C, (H + Set{0, 1200 - h * 60 - m}->max() * D) div N * C * .8}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math hh,mm=[int(i)for i in input().split()] h,d,c,n=[int(i)for i in input().split()] if hh<20 : print("{:.4f}".format(min((math.ceil(h/n)*c),(math.ceil((h+(abs(hh-20)*60-mm)*d)/n)*(c*0.8))))) else : print("{:.4f}".format(math.ceil(h/n)*(c*0.8))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var hh : OclAny := null; var mm : OclAny := null; Sequence{hh,mm} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var h : OclAny := null; var d : OclAny := null; var c : OclAny := null; var n : OclAny := null; Sequence{h,d,c,n} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if hh < 20 then ( execute (StringLib.interpolateStrings("{:.4f}", Sequence{Set{((h / n)->ceil() * c), (((h + ((hh - 20)->abs() * 60 - mm) * d) / n)->ceil() * (c * 0.8))}->min()}))->display() ) else ( execute (StringLib.interpolateStrings("{:.4f}", Sequence{(h / n)->ceil() * (c * 0.8)}))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math hh,mm=map(float,input().split()) H,D,C,N=map(float,input().split()) mm+=hh*60 if mm>=1200 : print((math.ceil(H/N))*C*0.8) else : print(min((math.ceil(H/N)*C),(math.ceil((H+D*(1200-mm))/N)*C*0.8))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var hh : OclAny := null; var mm : OclAny := null; Sequence{hh,mm} := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; var H : OclAny := null; var D : OclAny := null; var C : OclAny := null; var N : OclAny := null; Sequence{H,D,C,N} := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; mm := mm + hh * 60 ; if mm >= 1200 then ( execute (((H / N)->ceil()) * C * 0.8)->display() ) else ( execute (Set{((H / N)->ceil() * C), (((H + D * (1200 - mm)) / N)->ceil() * C * 0.8)}->min())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def show(array): for i in range(len(array)): if i!=len(array)-1 : print(array[i],end=' ') else : print(array[i]) def selectionSort(array): count=0 for i in range(len(array)): minj=i flag=False for j in range(i,len(array)): if array[j]select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; selectionSort(array); operation show(array : OclAny) pre: true post: true activity: for i : Integer.subrange(0, (array)->size()-1) do ( if i /= (array)->size() - 1 then ( execute (array[i+1])->display() ) else ( execute (array[i+1])->display() )); operation selectionSort(array : OclAny) pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, (array)->size()-1) do ( var minj : OclAny := i ; var flag : boolean := false ; for j : Integer.subrange(i, (array)->size()-1) do ( if (array[j+1]->compareTo(array[minj+1])) < 0 then ( minj := j ; flag := true ) else skip) ; if flag & i /= minj then ( var array[i+1] : OclAny := null; var array[minj+1] : OclAny := null; Sequence{array[i+1],array[minj+1]} := Sequence{array[minj+1]}->union(Sequence{ array[i+1] }) ; count := count + 1 ) else skip) ; show(array) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import logging ch=logging.StreamHandler() ch.setLevel(logging.DEBUG) logger=logging.getLogger() logger.setLevel(logging.DEBUG) logger.addHandler(ch) def solve(hh,mm,h,d,c,n): if hh>=20 : return 0.8*c*math.ceil(h/n) logger.debug('Can buy at %s:%s for %s',hh,mm,c*math.ceil(h/n)) logger.debug('Can buy at 20:00 for %s',0.8*c*math.ceil((h+d*((20-hh)*60-mm))/n)) return min(c*math.ceil(h/n),0.8*c*math.ceil((h+d*((20-hh)*60-mm))/n)) def main(): hh,mm=input().strip().split() hh=int(hh) mm=int(mm)if mm!='00' else 0 h,d,c,n=map(int,input().strip().split()) result=solve(hh,mm,h,d,c,n) print(result) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var ch : OclAny := logging.StreamHandler() ; ch.setLevel(logging.DEBUG) ; var logger : OclAny := logging.getLogger() ; logger.setLevel(logging.DEBUG) ; logger.addHandler(ch) ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(hh : OclAny, mm : OclAny, h : OclAny, d : OclAny, c : OclAny, n : OclAny) : OclAny pre: true post: true activity: if hh >= 20 then ( return 0.8 * c * (h / n)->ceil() ) else skip ; logger.debug('Can buy at %s:%s for %s', hh, mm, c * (h / n)->ceil()) ; logger.debug('Can buy at 20:00 for %s', 0.8 * c * ((h + d * ((20 - hh) * 60 - mm)) / n)->ceil()) ; return Set{c * (h / n)->ceil(), 0.8 * c * ((h + d * ((20 - hh) * 60 - mm)) / n)->ceil()}->min(); operation main() pre: true post: true activity: Sequence{hh,mm} := input()->trim().split() ; hh := ("" + ((hh)))->toInteger() ; mm := if mm /= '00' then ("" + ((mm)))->toInteger() else 0 endif ; Sequence{h,d,c,n} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var result : OclAny := solve(hh, mm, h, d, c, n) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1003 for cno in range(1,100): lim=int(input()) if lim==0 : break print("Case ",cno,":",sep='') N=int(input()) vw=[(0,0)] for i in range(N): v,w=list(map(int,input().split(','))) vw.append((v,w)) V=[[0 for j in range(MAX)]for i in range(2)] W=[[0 for j in range(MAX)]for i in range(2)] k1,k2=0,1 for i in range(1,N+1): for j in range(1,lim+1): v,w=vw[i] if w>j : V[k2][j]=V[k1][j] W[k2][j]=W[k1][j] else : d=j-w if V[k1][d]+v>=V[k1][j]: V[k2][j]=V[k1][d]+v W[k2][j]=W[k1][d]+w else : V[k2][j]=V[k1][j] W[k2][j]=W[k1][j] k1,k2=k2,k1 print(V[k1][lim],W[k1][lim],sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1003 ; for cno : Integer.subrange(1, 100-1) do ( var lim : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if lim = 0 then ( break ) else skip ; execute ("Case ")->display() ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var vw : Sequence := Sequence{ Sequence{0, 0} } ; for i : Integer.subrange(0, N-1) do ( var v : OclAny := null; var w : OclAny := null; Sequence{v,w} := ((input().split(','))->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((Sequence{v, w}) : vw)) ; var V : Sequence := Integer.subrange(0, 2-1)->select(i | true)->collect(i | (Integer.subrange(0, MAX-1)->select(j | true)->collect(j | (0)))) ; var W : Sequence := Integer.subrange(0, 2-1)->select(i | true)->collect(i | (Integer.subrange(0, MAX-1)->select(j | true)->collect(j | (0)))) ; var k1 : OclAny := null; var k2 : OclAny := null; Sequence{k1,k2} := Sequence{0,1} ; for i : Integer.subrange(1, N + 1-1) do ( for j : Integer.subrange(1, lim + 1-1) do ( var v : OclAny := null; var w : OclAny := null; Sequence{v,w} := vw[i+1] ; if (w->compareTo(j)) > 0 then ( V[k2+1][j+1] := V[k1+1][j+1] ; W[k2+1][j+1] := W[k1+1][j+1] ) else ( var d : double := j - w ; if (V[k1+1][d+1] + v->compareTo(V[k1+1][j+1])) >= 0 then ( V[k2+1][j+1] := V[k1+1][d+1] + v ; W[k2+1][j+1] := W[k1+1][d+1] + w ) else ( V[k2+1][j+1] := V[k1+1][j+1] ; W[k2+1][j+1] := W[k1+1][j+1] ) )) ; var k1 : OclAny := null; var k2 : OclAny := null; Sequence{k1,k2} := Sequence{k2,k1}) ; execute (V[k1+1][lim+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def answer(X,K): MAX=pow(10,K)-1 return(MAX-(MAX % X)) X=30 ; K=3 ; print(answer(X,K)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; X := 30; ; K := 3; ; execute (answer(X, K))->display();; operation answer(X : OclAny, K : OclAny) : OclAny pre: true post: true activity: var MAX : double := (10)->pow(K) - 1 ; return (MAX - (MAX mod X)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys INT_MAX=sys.maxsize ; def countPartitions(A,N): count=0 ; for i in range(N): min_elem=min(A); if(min_elem==INT_MAX): break ; count+=1 ; for i in range(N): if(A[i]% min_elem==0): A[i]=INT_MAX ; return count ; if __name__=="__main__" : arr=[7,6,5,4,3,2,2,3]; N=len(arr); print(countPartitions(arr,N)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var INT_MAX : (trailer . (name maxsize)) := (trailer . (name maxsize)); ; skip ; if __name__ = "__main__" then ( var arr : Sequence := Sequence{7}->union(Sequence{6}->union(Sequence{5}->union(Sequence{4}->union(Sequence{3}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 3 }))))))); ; N := (arr)->size(); ; execute (countPartitions(arr, N))->display(); ) else skip; operation countPartitions(A : OclAny, N : OclAny) pre: true post: true activity: var count : int := 0; ; for i : Integer.subrange(0, N-1) do ( var min_elem : OclAny := (A)->min(); ; if (min_elem = INT_MAX) then ( break; ) else skip ; count := count + 1; ; for i : Integer.subrange(0, N-1) do ( if (A[i+1] mod min_elem = 0) then ( A[i+1] := INT_MAX; ) else skip)) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,*s=open(0) h,w,k,*m=map(int,h.split()) b=w while b : b-=1 ; r=t=j=0 ; d=[0]*h while w-j : i=c=0 ; j+=1 while h-i : d[c]+=s[i][~ j]>'0' ; c+=b>>i & 1 ; i+=1 if max(d)>k : d=[0]*h ; f=tcollect( _x | (OclType["int"])->apply(_x) ) ; var b : OclAny := w ; while b do ( b := b - 1; r := r(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name t)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name j)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))); var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, h) ; while w - j do ( var i : OclAny := 0; var c : int := 0; j := j + 1 ; while h - i do ( d[c+1] := d[c+1] + s[i+1][MathLib.bitwiseNot(j)+1] > '0'; c := c + MathLib.bitwiseAnd(b /(2->pow(i)), 1); i := i + 1 ; if ((d)->max()->compareTo(k)) > 0 then ( d := MatrixLib.elementwiseMult(Sequence{ 0 }, h); var f : boolean := (t->compareTo(j)) < 0; r := r + 1; var t : OclAny := j; j := j - f; break ) else skip)) ; m := m + (testlist (test (logical_test (comparison (expr (expr (atom (name r))) + (expr (atom (name c))))))) ,)) ; execute ((m)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from collections import Counter h,w,k=[int(s)for s in sys.stdin.readline().strip().split()] s=['']*h for i in range(h): s[i]=sys.stdin.readline().strip() ans=float('inf') for i in range(2**h): colors=[0] cur=0 cand=0 for div in range(h-1): if(i>>div)& 1 : cur+=1 colors.append(cur) cand+=1 else : colors.append(cur) impossible=False color_count=Counter() for j in range(w): col_color_count=Counter() for row in range(h): color=colors[row] char=s[row][j] if char=='1' : col_color_count[color]+=1 has_break=False for col in range(cur+1): if col_color_count[col]>k : impossible=True break if col_color_count[col]+color_count[col]>k : has_break=True if impossible : break if has_break : color_count=col_color_count cand+=1 else : for col in range(cur+1): color_count[col]+=col_color_count[col] if not impossible : ans=min(ans,cand) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var h : OclAny := null; var w : OclAny := null; var k : OclAny := null; Sequence{h,w,k} := sys.stdin.readLine()->trim().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; var s : Sequence := MatrixLib.elementwiseMult(Sequence{ '' }, h) ; for i : Integer.subrange(0, h-1) do ( s[i+1] := sys.stdin.readLine()->trim()) ; var ans : double := ("" + (('inf')))->toReal() ; for i : Integer.subrange(0, (2)->pow(h)-1) do ( var colors : Sequence := Sequence{ 0 } ; var cur : int := 0 ; var cand : int := 0 ; for div : Integer.subrange(0, h - 1-1) do ( if MathLib.bitwiseAnd((i /(2->pow(div))), 1) then ( cur := cur + 1 ; execute ((cur) : colors) ; cand := cand + 1 ) else ( execute ((cur) : colors) )) ; var impossible : boolean := false ; var color_count : OclAny := Counter() ; for j : Integer.subrange(0, w-1) do ( var col_color_count : OclAny := Counter() ; for row : Integer.subrange(0, h-1) do ( var color : OclAny := colors[row+1] ; var char : OclAny := s[row+1][j+1] ; if char = '1' then ( col_color_count[color+1] := col_color_count[color+1] + 1 ) else skip) ; var has_break : boolean := false ; for col : Integer.subrange(0, cur + 1-1) do ( if (col_color_count[col+1]->compareTo(k)) > 0 then ( impossible := true ; break ) else skip ; if (col_color_count[col+1] + color_count[col+1]->compareTo(k)) > 0 then ( has_break := true ) else skip) ; if impossible then ( break ) else skip ; if has_break then ( color_count := col_color_count ; cand := cand + 1 ) else ( for col : Integer.subrange(0, cur + 1-1) do ( color_count[col+1] := color_count[col+1] + col_color_count[col+1]) )) ; if not(impossible) then ( ans := Set{ans, cand}->min() ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import itertools import time import math from heapq import heappop,heappush from collections import defaultdict from collections import Counter from collections import deque from itertools import permutations sys.setrecursionlimit(10**7) INF=10**18 MOD=10**9+7 read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines H,W,K=map(int,input().split()) S=[input()for _ in range(H)] acc=[[0]*(W+1)for _ in range(H)] for i in range(H): for j in range(1,W+1): acc[i][j]=acc[i][j-1]+int(S[i][j-1]) ans=INF for bit in range(1<<(H-1)): base=0 vertical=[] for i in range(H-1): if bit & 1<0 : vertical.append((base,i)) base=i+1 vertical.append((base,H-1)) tmp_ans=len(vertical)-1 prev=0 j=1 valid=False while j<=W : ok=True for v in vertical : now=0 for i in range(v[0],v[1]+1): now+=acc[i][j]-acc[i][prev] if now>K : ok=False if ok : valid=True else : if valid : prev=j-1 tmp_ans+=1 valid=False continue else : break j+=1 if valid : ans=min(tmp_ans,ans) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; var INF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; var H : OclAny := null; var W : OclAny := null; var K : OclAny := null; Sequence{H,W,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var acc : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (W + 1)))) ; for i : Integer.subrange(0, H-1) do ( for j : Integer.subrange(1, W + 1-1) do ( acc[i+1][j+1] := acc[i+1][j - 1+1] + ("" + ((S[i+1][j - 1+1])))->toInteger())) ; var ans : OclAny := INF ; for bit : Integer.subrange(0, 1 * (2->pow((H - 1)))-1) do ( var base : int := 0 ; var vertical : Sequence := Sequence{} ; for i : Integer.subrange(0, H - 1-1) do ( if MathLib.bitwiseAnd(bit, 1 * (2->pow(i))) > 0 then ( execute ((Sequence{base, i}) : vertical) ; base := i + 1 ) else skip) ; execute ((Sequence{base, H - 1}) : vertical) ; var tmp_ans : double := (vertical)->size() - 1 ; var prev : int := 0 ; var j : int := 1 ; var valid : boolean := false ; while (j->compareTo(W)) <= 0 do ( var ok : boolean := true ; for v : vertical do ( var now : int := 0 ; for i : Integer.subrange(v->first(), v[1+1] + 1-1) do ( now := now + acc[i+1][j+1] - acc[i+1][prev+1]) ; if (now->compareTo(K)) > 0 then ( ok := false ) else skip) ; if ok then ( valid := true ) else ( if valid then ( prev := j - 1 ; tmp_ans := tmp_ans + 1 ; valid := false ; continue ) else ( break ) ) ; j := j + 1) ; if valid then ( ans := Set{tmp_ans, ans}->min() ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from pprint import pprint h,w,k=map(int,input().split()) maze=[] ts=[] for _ in range(h): l=input() l=list(map(int,list(l))) x=0 tmps=[] for j in range(w): x+=l[j] tmps.append(x) ts.append(tmps) maze.append(l) bin_a=["{:09b}".format(a)for a in range(0,2**(h-1))] res=9999999 for cutpat in bin_a : cutpat=cutpat[: :-1] cutsum=[0]*10 gr=[-1]*10 gr[0]=0 grnum=0 for i in range(1,h): if cutpat[i-1]=="1" : grnum+=1 gr[i]=grnum firstFail=False cutcount=cutpat.count("1") for i in range(w): for j in range(h): cutsum[gr[j]]+=maze[j][i] isFail=False for j in range(h): if cutsum[j]>k : isFail=True if i==0 : firstFail=True if isFail : cutcount+=1 cutsum=[0]*10 for j in range(h): cutsum[gr[j]]+=maze[j][i] for j in range(h): if cutsum[j]>k : isFail=True if i==0 : firstFail=True if firstFail : continue res=min(res,cutcount) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var h : OclAny := null; var w : OclAny := null; var k : OclAny := null; Sequence{h,w,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var maze : Sequence := Sequence{} ; var ts : Sequence := Sequence{} ; for _anon : Integer.subrange(0, h-1) do ( var l : String := (OclFile["System.in"]).readLine() ; l := (((l)->characters())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : int := 0 ; var tmps : Sequence := Sequence{} ; for j : Integer.subrange(0, w-1) do ( x := x + l[j+1] ; execute ((x) : tmps)) ; execute ((tmps) : ts) ; execute ((l) : maze)) ; var bin_a : Sequence := Integer.subrange(0, (2)->pow((h - 1))-1)->select(a | true)->collect(a | (StringLib.interpolateStrings("{:09b}", Sequence{a}))) ; var res : int := 9999999 ; for cutpat : bin_a do ( var cutpat : OclAny := cutpat(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var cutsum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; var gr : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, 10) ; gr->first() := 0 ; var grnum : int := 0 ; for i : Integer.subrange(1, h-1) do ( if cutpat[i - 1+1] = "1" then ( grnum := grnum + 1 ) else skip ; gr[i+1] := grnum) ; var firstFail : boolean := false ; var cutcount : int := cutpat->count("1") ; for i : Integer.subrange(0, w-1) do ( for j : Integer.subrange(0, h-1) do ( cutsum[gr[j+1]+1] := cutsum[gr[j+1]+1] + maze[j+1][i+1]) ; var isFail : boolean := false ; for j : Integer.subrange(0, h-1) do ( if (cutsum[j+1]->compareTo(k)) > 0 then ( isFail := true ; if i = 0 then ( firstFail := true ) else skip ) else skip) ; if isFail then ( cutcount := cutcount + 1 ; cutsum := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; for j : Integer.subrange(0, h-1) do ( cutsum[gr[j+1]+1] := cutsum[gr[j+1]+1] + maze[j+1][i+1]) ; for j : Integer.subrange(0, h-1) do ( if (cutsum[j+1]->compareTo(k)) > 0 then ( isFail := true ; if i = 0 then ( firstFail := true ) else skip ) else skip) ) else skip) ; if firstFail then ( continue ) else skip ; res := Set{res, cutcount}->min()) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=10000 def makeMap(H,bits): M=[0]*H m=0 for i in range(H): M[i]=m if bits & 1 : m+=1 bits>>=1 return M def getCounts(H,S,M,w): C=[0]*(M[-1]+1) for h in range(H): if S[h][w]=='1' : C[M[h]]+=1 return C def f(H,W,K,S,bits): M=makeMap(H,bits) N=M[-1]+1 X=[0]*N ans=0 for w in range(W): C=getCounts(H,S,M,w) for i in range(N): if C[i]>K : return MAX X[i]+=C[i] if X[i]>K : ans+=1 X=C break return ans+N-1 H,W,K=map(int,input().split()) S=[input()for _ in range(H)] ans=MAX for bits in range(2**(H-1)): ans=min(ans,f(H,W,K,S,bits)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 10000 ; skip ; skip ; skip ; Sequence{H,W,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; S := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; ans := MAX ; for bits : Integer.subrange(0, (2)->pow((H - 1))-1) do ( ans := Set{ans, f(H, W, K, S, bits)}->min()) ; execute (ans)->display(); operation makeMap(H : OclAny, bits : OclAny) : OclAny pre: true post: true activity: var M : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, H) ; var m : int := 0 ; for i : Integer.subrange(0, H-1) do ( M[i+1] := m ; if MathLib.bitwiseAnd(bits, 1) then ( m := m + 1 ) else skip ; bits := bits div (2->pow(1))) ; return M; operation getCounts(H : OclAny, S : OclAny, M : OclAny, w : OclAny) : OclAny pre: true post: true activity: var C : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (M->last() + 1)) ; for h : Integer.subrange(0, H-1) do ( if S[h+1][w+1] = '1' then ( C[M[h+1]+1] := C[M[h+1]+1] + 1 ) else skip) ; return C; operation f(H : OclAny, W : OclAny, K : OclAny, S : OclAny, bits : OclAny) : OclAny pre: true post: true activity: M := makeMap(H, bits) ; var N : OclAny := M->last() + 1 ; var X : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var ans : int := 0 ; for w : Integer.subrange(0, W-1) do ( C := getCounts(H, S, M, w) ; for i : Integer.subrange(0, N-1) do ( if (C[i+1]->compareTo(K)) > 0 then ( return MAX ) else skip ; X[i+1] := X[i+1] + C[i+1] ; if (X[i+1]->compareTo(K)) > 0 then ( ans := ans + 1 ; X := C ; break ) else skip)) ; return ans + N - 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkSubarraySum(arr,n,k,sumV): curr_sum=0 for i in range(0,k): curr_sum+=arr[i] if(curr_sum==sumV): return true for j in range(k,n): curr_sum=(curr_sum+arr[j]-arr[j-k]) if(curr_sum==sumV): return True return False arr=[1,4,2,10,2,3,1,0,20] k=4 sumV=18 n=len(arr) if(checkSubarraySum(arr,n,k,sumV)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{4}->union(Sequence{2}->union(Sequence{10}->union(Sequence{2}->union(Sequence{3}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 20 })))))))) ; k := 4 ; sumV := 18 ; n := (arr)->size() ; if (checkSubarraySum(arr, n, k, sumV)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); operation checkSubarraySum(arr : OclAny, n : OclAny, k : OclAny, sumV : OclAny) : OclAny pre: true post: true activity: var curr_sum : int := 0 ; for i : Integer.subrange(0, k-1) do ( curr_sum := curr_sum + arr[i+1]) ; if (curr_sum = sumV) then ( return true ) else skip ; for j : Integer.subrange(k, n-1) do ( curr_sum := (curr_sum + arr[j+1] - arr[j - k+1]) ; if (curr_sum = sumV) then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- 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() cnt=0 for i in range(N): minj=i for j in range(i,N): if A[j]compareTo(A[minj+1])) < 0 then ( minj := j ) else skip) ; var a : OclAny := A[i+1] ; var b : OclAny := A[minj+1] ; A[i+1] := b ; A[minj+1] := a ; if minj /= i then ( cnt := cnt + 1 ) else skip) ; execute (StringLib.sumStringsWithSeparator(((A)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ; execute (cnt)->display(); operation I() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.readLine().rstrip())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )); operation S() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation LS() : OclAny pre: true post: true activity: return (sys.stdin.readLine().rstrip().split()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkSubarraySum(arr,n,k,sum): for i in range(n-k+1): current_sum=0 ; for j in range(k): current_sum=(current_sum+arr[i+j]); if(current_sum==sum): return True ; return False ; arr=[1,4,2,10,2,3,1,0,20]; k=4 ; sum=18 ; n=len(arr); if(checkSubarraySum(arr,n,k,sum)): print("YES"); else : print("NO"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{4}->union(Sequence{2}->union(Sequence{10}->union(Sequence{2}->union(Sequence{3}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 20 })))))))); ; k := 4; ; sum := 18; ; n := (arr)->size(); ; if (checkSubarraySum(arr, n, k, sum)) then ( execute ("YES")->display(); ) else ( execute ("NO")->display(); ); operation checkSubarraySum(arr : OclAny, n : OclAny, k : OclAny, sum : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n - k + 1-1) do ( var current_sum : int := 0; ; for j : Integer.subrange(0, k-1) do ( current_sum := (current_sum + arr[i + j+1]);) ; if (current_sum = sum) then ( return true; ) else skip) ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os in_file=None out_file=None def run_main(main): name=sys.argv[0][:-3] in_file_name=name+".in" out_file_name=name+".out" if len(sys.argv)==2 : in_file_name=sys.argv[1] out_file_name=in_file_name[:-3]+".out" if len(sys.argv)==3 : if sys.argv[1]: in_file_name=sys.argv[1] if sys.argv[2]: out_file_name=sys.argv[2] global in_file global out_file if in_file_name=='-' : in_file=sys.stdin else : in_file=open(in_file_name,'r') if out_file_name=='-' : out_file=sys.stdout else : out_file=open(out_file_name,'w') main(in_file,out_file) out_file.close() in_file.close() def run_tests(do_testcase): def main(in_file,out_file): t=readinteger() for x in xrange(t): do_testcase(x+1) run_main(main) def readline(): return in_file.readline()[:-1] def writeline(s): out_file.write("%s\n" % s) def readinteger(): return int(readline()) def readintegers(): integers=readline().split() for i in xrange(len(integers)): integers[i]=int(integers[i]) return integers ------------------------------------------------------------ OCL File: --------- class FromPython { attribute in_file : OclAny; attribute out_file : OclAny; operation initialise() pre: true post: true activity: skip ; var in_file : OclAny := null ; var out_file : OclAny := null ; skip ; skip ; skip ; skip ; skip ; skip; operation run_main(main : OclAny) pre: true post: true activity: var name : OclAny := ((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))).subrange(1,-3) ; var in_file_name : int := name + ".in" ; var out_file_name : int := name + ".out" ; if ((trailer . (name argv)))->size() = 2 then ( in_file_name := (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) ; out_file_name := in_file_name.subrange(1,-3) + ".out" ) else skip ; if ((trailer . (name argv)))->size() = 3 then ( if (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) then ( in_file_name := (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) ) else skip ; if (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) then ( out_file_name := (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) ) else skip ) else skip ; skip ; skip ; if in_file_name = '-' then ( in_file := OclFile["System.in"] ) else ( in_file := OclFile.newOclFile_Write(OclFile.newOclFile(in_file_name)) ) ; if out_file_name = '-' then ( out_file := OclFile["System.out"] ) else ( out_file := OclFile.newOclFile_Write(OclFile.newOclFile(out_file_name)) ) ; main(in_file, out_file) ; out_file.closeFile() ; in_file.closeFile(); operation run_tests(do_testcase : OclAny) pre: true post: true activity: skip ; run_main(main); operation readline() : OclAny pre: true post: true activity: return in_file.readLine()->front(); operation writeline(s : OclAny) pre: true post: true activity: out_file.write(StringLib.format("%s\n",s)); operation readinteger() : OclAny pre: true post: true activity: return ("" + ((readline())))->toInteger(); operation readintegers() : OclAny pre: true post: true activity: var integers : OclAny := readline().split() ; for i : xrange((integers)->size()) do ( integers[i+1] := ("" + ((integers[i+1])))->toInteger()) ; return integers; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin a,b=[int(x)for x in stdin.readline().rstrip().split()] s=stdin.readline().rstrip() r=s.lower() string="" for i in range(a): if i==b-1 : string+=r[i] else : string+=s[i] print(string) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := stdin.readLine().rstrip().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var s : OclAny := stdin.readLine().rstrip() ; var r : String := s->toLowerCase() ; var string : String := "" ; for i : Integer.subrange(0, a-1) do ( if i = b - 1 then ( string := string + r[i+1] ) else ( string := string + s[i+1] )) ; execute (string)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Knapack(object): def __init__(self,data,limit): self.limit=limit data_size=len(data) self.C=[[0]*(limit+1)for _ in range(data_size+1)] self.data=data[:] def solve(self): for i in range(1,len(self.data)+1): i_value=self.data[i-1][0] i_weight=self.data[i-1][1] for w in range(1,self.limit+1): if i_weight<=w : if i_value+self.C[i-1][w-i_weight]>self.C[i-1][w]: self.C[i][w]=i_value+self.C[i-1][w-i_weight] else : self.C[i][w]=self.C[i-1][w] else : self.C[i][w]=self.C[i-1][w] if __name__=='__main__' : case_no=1 while True : limit=int(input()) if limit==0 : break num_of_items=int(input()) data=[] for i in range(num_of_items): data.append(list(map(int,input().split(',')))) ks=Knapack(data,limit) ks.solve() target=ks.C[len(data)][limit] weight=limit for w in range(limit,0,-1): if ks.C[len(data)][w]==target : weight=w print('Case{0}:'.format(case_no)) print('{0}\n{1}'.format(target,weight)) case_no+=1 ------------------------------------------------------------ OCL File: --------- class Knapack extends object { static operation newKnapack() : Knapack pre: true post: Knapack->exists( _x | result = _x ); attribute limit : OclAny := limit; attribute C : Sequence := Integer.subrange(0, data_size + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (limit + 1)))); attribute data : Sequence := data; operation initialise(data : OclAny,limit : OclAny) : pre: true post: true activity: self.limit := limit ; var data_size : int := (data)->size() ; self.C := Integer.subrange(0, data_size + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (limit + 1)))) ; self.data := data; return self; operation solve() pre: true post: true activity: for i : Integer.subrange(1, (self.data)->size() + 1-1) do ( var i_value : OclAny := self.data[i - 1+1]->first() ; var i_weight : OclAny := self.data[i - 1+1][1+1] ; for w : Integer.subrange(1, self.limit + 1-1) do ( if (i_weight->compareTo(w)) <= 0 then ( if (i_value + self.C[i - 1+1][w - i_weight+1]->compareTo(self.C[i - 1+1][w+1])) > 0 then ( self.C[i+1][w+1] := i_value + self.C[i - 1+1][w - i_weight+1] ) else ( self.C[i+1][w+1] := self.C[i - 1+1][w+1] ) ) else ( self.C[i+1][w+1] := self.C[i - 1+1][w+1] ))); } class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var case_no : int := 1 ; while true do ( limit := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if limit = 0 then ( break ) else skip ; var num_of_items : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; data := Sequence{} ; for i : Integer.subrange(0, num_of_items-1) do ( execute ((((input().split(','))->collect( _x | (OclType["int"])->apply(_x) ))) : data)) ; var ks : Knapack := (Knapack.newKnapack()).initialise(data, limit) ; ks.solve() ; var target : OclAny := ks.C[(data)->size()+1][limit+1] ; var weight : OclAny := limit ; for w : Integer.subrange(0 + 1, limit)->reverse() do ( if ks.C[(data)->size()+1][w+1] = target then ( weight := w ) else skip) ; execute (StringLib.interpolateStrings('Case{0}:', Sequence{case_no}))->display() ; execute (StringLib.interpolateStrings('{0} {1}', Sequence{target, weight}))->display() ; case_no := case_no + 1) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAXN=100 def maxValue(n,m,x,y,a): c=[[0 for x in range(MAXN)]for y in range(MAXN)] for i in range(m): for p in range(n): for q in range(n): dx=abs(p-x[i]) dy=abs(q-y[i]) d=max(dx,dy) c[p][q]+=max(0,a[i]-d) res=0 for i in range(n): for j in range(n): res=max(res,c[i][j]) return res if __name__=="__main__" : n=10 m=2 x=[3,7] y=[3,7] a=[4,3] print(maxValue(n,m,x,y,a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAXN : int := 100 ; skip ; if __name__ = "__main__" then ( n := 10 ; m := 2 ; x := Sequence{3}->union(Sequence{ 7 }) ; y := Sequence{3}->union(Sequence{ 7 }) ; a := Sequence{4}->union(Sequence{ 3 }) ; execute (maxValue(n, m, x, y, a))->display() ) else skip; operation maxValue(n : OclAny, m : OclAny, x : OclAny, y : OclAny, a : OclAny) : OclAny pre: true post: true activity: var c : Sequence := Integer.subrange(0, MAXN-1)->select(y | true)->collect(y | (Integer.subrange(0, MAXN-1)->select(x | true)->collect(x | (0)))) ; for i : Integer.subrange(0, m-1) do ( for p : Integer.subrange(0, n-1) do ( for q : Integer.subrange(0, n-1) do ( var dx : double := (p - x[i+1])->abs() ; var dy : double := (q - y[i+1])->abs() ; var d : OclAny := Set{dx, dy}->max() ; c[p+1][q+1] := c[p+1][q+1] + Set{0, a[i+1] - d}->max()))) ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( res := Set{res, c[i+1][j+1]}->max())) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- maxSize=50 dp=[0]*maxSize v=[0]*maxSize def expectedSteps(x): if(x==0): return 0 if(x<=5): return 6 if(v[x]): return dp[x] v[x]=1 dp[x]=1+(expectedSteps(x-1)+expectedSteps(x-2)+expectedSteps(x-3)+expectedSteps(x-4)+expectedSteps(x-5)+expectedSteps(x-6))/6 return dp[x] n=10 print(round(expectedSteps(n-1),5)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var maxSize : int := 50 ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, maxSize) ; var v : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, maxSize) ; skip ; var n : int := 10 ; execute (MathLib.roundN(expectedSteps(n - 1), 5))->display(); operation expectedSteps(x : OclAny) : OclAny pre: true post: true activity: if (x = 0) then ( return 0 ) else skip ; if (x <= 5) then ( return 6 ) else skip ; if (v[x+1]) then ( return dp[x+1] ) else skip ; v[x+1] := 1 ; dp[x+1] := 1 + (expectedSteps(x - 1) + expectedSteps(x - 2) + expectedSteps(x - 3) + expectedSteps(x - 4) + expectedSteps(x - 5) + expectedSteps(x - 6)) / 6 ; return dp[x+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) ans=0 for i in range(1,n): if(a[i-1]-1)*(a[i]-1)>0 : print("Infinite") exit() ans+=a[i-1]+a[i] if i>1 and a[i-2]==3 and a[i-1]==1 and a[i]==2 : ans-=1 print("Finite") print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(1, n-1) do ( if (a[i - 1+1] - 1) * (a[i+1] - 1) > 0 then ( execute ("Infinite")->display() ; exit() ) else skip ; ans := ans + a[i - 1+1] + a[i+1] ; if i > 1 & a[i - 2+1] = 3 & a[i - 1+1] = 1 & a[i+1] = 2 then ( ans := ans - 1 ) else skip) ; execute ("Finite")->display() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys def Binary(n): s=bin(n) s1=s[2 :] return s1 def Decimal(n): return int(n,2) n=int(input()) ar=list(map(int,input().split(' '))) check=True cnt=0 for i in range(1,n): if(ar[i]==1 and ar[i-1]==2): cnt+=3 elif(ar[i]==1 and ar[i-1]==3): cnt+=4 elif(ar[i]==2 and ar[i-1]==1): cnt+=3 elif(ar[i]==3 and ar[i-1]==1): cnt+=4 else : check=False break if(i>1 and ar[i]==2 and ar[i-1]==1 and ar[i-2]==3): cnt-=1 if(check): print("Finite") print(cnt) else : print("Infinite") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ar : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var check : boolean := true ; var cnt : int := 0 ; for i : Integer.subrange(1, n-1) do ( if (ar[i+1] = 1 & ar[i - 1+1] = 2) then ( cnt := cnt + 3 ) else (if (ar[i+1] = 1 & ar[i - 1+1] = 3) then ( cnt := cnt + 4 ) else (if (ar[i+1] = 2 & ar[i - 1+1] = 1) then ( cnt := cnt + 3 ) else (if (ar[i+1] = 3 & ar[i - 1+1] = 1) then ( cnt := cnt + 4 ) else ( check := false ; break ) ) ) ) ; if (i > 1 & ar[i+1] = 2 & ar[i - 1+1] = 1 & ar[i - 2+1] = 3) then ( cnt := cnt - 1 ) else skip) ; if (check) then ( execute ("Finite")->display() ; execute (cnt)->display() ) else ( execute ("Infinite")->display() ); operation Binary(n : OclAny) : OclAny pre: true post: true activity: var s : OclAny := bin(n) ; var s1 : OclAny := s.subrange(2+1) ; return s1; operation Decimal(n : OclAny) : OclAny pre: true post: true activity: return ("" + ((n, 2)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() x=input()[: : 2] z,*y,h=map(int,x) print(*(('Finite',2*sum(y)+z+h-x.count('312')),['Infinite'])['23' in x or '32' in x]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var x : OclAny := input()(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ; var z : OclAny := null; var y : OclAny := null; var h : OclAny := null; Sequence{z,y,h} := (x)->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom 'Finite'))))) , (test (logical_test (comparison (expr (expr (expr (expr (expr (atom (number (integer 2)))) * (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) ))))) + (expr (atom (name z)))) + (expr (atom (name h)))) - (expr (atom (name x)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '312'))))))) ))))))))) )))))) , (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom 'Infinite')))))) ])))))) )) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (logical_test (comparison (comparison (expr (atom '23'))) in (comparison (expr (atom (name x)))))) or (logical_test (comparison (comparison (expr (atom '32'))) in (comparison (expr (atom (name x)))))))))) ]))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) s=0 u=0 for i in range(1,n): if(a[i]==2 and a[i-1]==3)or(a[i]==3 and a[i-1]==2): s=-1 break else : if a[i]==2 or a[i-1]==2 : if u==3 : s+=2 else : s+=3 u=2 else : s+=4 u=3 if s>0 : print(f"Finite\n{s}") else : print("Infinite") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : int := 0 ; var u : int := 0 ; for i : Integer.subrange(1, n-1) do ( if (a[i+1] = 2 & a[i - 1+1] = 3) or (a[i+1] = 3 & a[i - 1+1] = 2) then ( s := -1 ; break ) else ( if a[i+1] = 2 or a[i - 1+1] = 2 then ( if u = 3 then ( s := s + 2 ) else ( s := s + 3 ) ; u := 2 ) else ( s := s + 4 ; u := 3 ) )) ; if s > 0 then ( execute (StringLib.formattedString("Finite\n{s}"))->display() ) else ( execute ("Infinite")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline N=int(input()) A=list(map(int,input().split())) def p(N): for i in range(len(N)): if i==len(N)-1 : print(N[i]) else : print(N[i],end=" ") ans=0 for i in range(N): m=i for j in range(i+1,N): if A[j]toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( var m : OclAny := i ; for j : Integer.subrange(i + 1, N-1) do ( if (A[j+1]->compareTo(A[m+1])) < 0 then ( m := j ) else skip) ; if m /= i then ( ans := ans + 1 ; var A[m+1] : OclAny := null; var A[i+1] : OclAny := null; Sequence{A[m+1],A[i+1]} := Sequence{A[i+1],A[m+1]} ) else skip) ; p(A) ; execute (ans)->display(); operation p(N : OclAny) pre: true post: true activity: for i : Integer.subrange(0, (N)->size()-1) do ( if i = (N)->size() - 1 then ( execute (N[i+1])->display() ) else ( execute (N[i+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans=0 def solve(N,lista): global ans aux_lados=[0,0,3,4] for i in range(1,N): if(lista[i-1]==2 and lista[i]==3 or lista[i-1]==3 and lista[i]==2): return-1 cont=0 for i in range(1,N): if lista[i]==1 : ans+=aux_lados[lista[i-1]] if lista[i]==2 : ans+=aux_lados[lista[i]] if i>=2 and lista[i-2]==3 and lista[i-1]: ans+=-1 if(lista[i]==3): ans+=aux_lados[lista[i]] return ans N=int(input()) lista=list(map(int,input().split())) ans=solve(N,lista) if ans==-1 : print('Infinite') else : print('Finite') print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute ans : OclAny; operation initialise() pre: true post: true activity: var ans : int := 0 ; skip ; N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; lista := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; ans := solve(N, lista) ; if ans = -1 then ( execute ('Infinite')->display() ) else ( execute ('Finite')->display() ; execute (ans)->display() ); operation solve(N : OclAny, lista : OclAny) : OclAny pre: true post: true activity: skip ; var aux_lados : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{3}->union(Sequence{ 4 }))) ; for i : Integer.subrange(1, N-1) do ( if (lista[i - 1+1] = 2 & lista[i+1] = 3 or lista[i - 1+1] = 3 & lista[i+1] = 2) then ( return -1 ) else skip) ; var cont : int := 0 ; for i : Integer.subrange(1, N-1) do ( if lista[i+1] = 1 then ( ans := ans + aux_lados[lista[i - 1+1]+1] ) else skip ; if lista[i+1] = 2 then ( ans := ans + aux_lados[lista[i+1]+1] ; if i >= 2 & lista[i - 2+1] = 3 & lista[i - 1+1] then ( ans := ans + -1 ) else skip ) else skip ; if (lista[i+1] = 3) then ( ans := ans + aux_lados[lista[i+1]+1] ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) s=input() t=input() v=['1']*1001 for i in range(m): v1=[] if i+len(s)-1>=len(t): break for j in range(n): if s[j]!=t[i+j]: v1.append(j+1) if len(v)>len(v1): v=v1 print(len(v)) for y in v : print(y,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var v : Sequence := MatrixLib.elementwiseMult(Sequence{ '1' }, 1001) ; for i : Integer.subrange(0, m-1) do ( var v1 : Sequence := Sequence{} ; if (i + (s)->size() - 1->compareTo((t)->size())) >= 0 then ( break ) else skip ; for j : Integer.subrange(0, n-1) do ( if s[j+1] /= t[i + j+1] then ( execute ((j + 1) : v1) ) else skip) ; if ((v)->size()->compareTo((v1)->size())) > 0 then ( v := v1 ) else skip) ; execute ((v)->size())->display() ; for y : v do ( execute (y)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) s=input() t=input() k=-1 indices=[] for i in range(m-n+1): diferente=0 listaDifs=[] for j in range(n): if t[i+j]!=s[j]: diferente+=1 listaDifs.append(j+1) if k==-1 or diferente0 : print(*indices) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var k : int := -1 ; var indices : Sequence := Sequence{} ; for i : Integer.subrange(0, m - n + 1-1) do ( var diferente : int := 0 ; var listaDifs : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( if t[i + j+1] /= s[j+1] then ( diferente := diferente + 1 ; execute ((j + 1) : listaDifs) ) else skip) ; if k = -1 or (diferente->compareTo(k)) < 0 then ( k := diferente ; indices := listaDifs ) else skip) ; execute (k)->display() ; if k > 0 then ( execute ((argument * (test (logical_test (comparison (expr (atom (name indices))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) s=input() t=input() k=-1 ind=[] for i in range(m-n+1): soma=0 arb=[] for j in range(n): if s[j]!=t[i+j]: soma+=1 arb.append(j+1) if somacollect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var k : int := -1 ; var ind : Sequence := Sequence{} ; for i : Integer.subrange(0, m - n + 1-1) do ( var soma : int := 0 ; var arb : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( if s[j+1] /= t[i + j+1] then ( soma := soma + 1 ; execute ((j + 1) : arb) ) else skip) ; if (soma->compareTo(k)) < 0 or k = -1 then ( k := soma ; ind := arb ) else skip) ; execute (k)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ind))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cnt=0 while True : cnt+=1 maxweight=int(input()) if maxweight==0 : break length=int(input()) tresure=[] dp=[[0 for n in range(length+1)]for m in range(maxweight+1)] answeight=0 ansvalue=0 for l in range(length): v,w=(int(n)for n in input().split(",")) tresure.append([v,w]) for outer in range(length+1): if outer==0 : continue weight=tresure[outer-1][1] value=tresure[outer-1][0] dp[weight][outer]=max(dp[weight][outer],value) for inner in range(maxweight+1): if dp[inner][outer-1]!=0 : beforevalue=dp[inner][outer-1] beforeweight=inner dp[inner][outer]=max(beforevalue,dp[inner][outer]) if beforeweight+weight<=maxweight : nowvalue=dp[beforeweight+weight][outer] dp[beforeweight+weight][outer]=max(nowvalue,beforevalue+value) for a in range(maxweight+1): if ansvaluetoInteger() ; if maxweight = 0 then ( break ) else skip ; var length : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var tresure : Sequence := Sequence{} ; var dp : Sequence := Integer.subrange(0, maxweight + 1-1)->select(m | true)->collect(m | (Integer.subrange(0, length + 1-1)->select(n | true)->collect(n | (0)))) ; var answeight : int := 0 ; var ansvalue : int := 0 ; for l : Integer.subrange(0, length-1) do ( var v : OclAny := null; var w : OclAny := null; Sequence{v,w} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ","))))))) ))))))))} ; execute ((Sequence{v}->union(Sequence{ w })) : tresure)) ; for outer : Integer.subrange(0, length + 1-1) do ( if outer = 0 then ( continue ) else skip ; var weight : OclAny := tresure[outer - 1+1][1+1] ; var value : OclAny := tresure[outer - 1+1]->first() ; dp[weight+1][outer+1] := Set{dp[weight+1][outer+1], value}->max() ; for inner : Integer.subrange(0, maxweight + 1-1) do ( if dp[inner+1][outer - 1+1] /= 0 then ( var beforevalue : OclAny := dp[inner+1][outer - 1+1] ; var beforeweight : OclAny := inner ; dp[inner+1][outer+1] := Set{beforevalue, dp[inner+1][outer+1]}->max() ; if (beforeweight + weight->compareTo(maxweight)) <= 0 then ( var nowvalue : OclAny := dp[beforeweight + weight+1][outer+1] ; dp[beforeweight + weight+1][outer+1] := Set{nowvalue, beforevalue + value}->max() ) else skip ) else skip)) ; for a : Integer.subrange(0, maxweight + 1-1) do ( if (ansvalue->compareTo(dp[a+1][length+1])) < 0 then ( ansvalue := dp[a+1][length+1] ; answeight := a ) else skip) ; execute (StringLib.interpolateStrings("Case{0}:", Sequence{cnt}))->display() ; execute (ansvalue)->display() ; execute (answeight)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(x)for x in input().split()] s=input() t=input() min=n+1 min_changes=[] for i in range(m-n+1): changes=[] for j in range(n): if t[i+j]!=s[j]: changes.append(j+1) if len(changes)select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var min : OclAny := n + 1 ; var min_changes : Sequence := Sequence{} ; for i : Integer.subrange(0, m - n + 1-1) do ( var changes : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( if t[i + j+1] /= s[j+1] then ( execute ((j + 1) : changes) ) else skip) ; if ((changes)->size()->compareTo(min)) < 0 then ( min := (changes)->size() ; min_changes := changes->copy() ) else skip) ; execute (min)->display() ; execute (StringLib.sumStringsWithSeparator(((min_changes)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) s=input() t=input() positions=[i+1 for i in range(n)] for i in range(0,m-n+1): new_positions=[] for j in range(n): if s[j]!=t[i+j]: new_positions.append(j+1) if len(new_positions)collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var positions : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i + 1)) ; for i : Integer.subrange(0, m - n + 1-1) do ( var new_positions : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( if s[j+1] /= t[i + j+1] then ( execute ((j + 1) : new_positions) ) else skip) ; if ((new_positions)->size()->compareTo((positions)->size())) < 0 then ( positions := new_positions ) else skip) ; execute ((positions)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name positions))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: d={}; i=0 for x in s.split(): i+=1 ; d[x]=i-i*(x in d) print(min([(int(x),d[x])for x in d if d[x]]+[(3e5,-1)])[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var d : OclAny := Set{}; var i : int := 0 ; for x : s.split() do ( i := i + 1; d[x+1] := i - i * ((d)->includes(x))) ; execute (min(d->select(x | d[x+1])->collect(x | (Sequence{("" + ((x)))->toInteger(), d[x+1]}))->union(Sequence{ Sequence{("3e5")->toReal(), -1} }))[1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) d={} for i,x in enumerate(a): if x not in d : d[x]=[] d[x].append(i) d=sorted(d.items(),key=lambda e :(len(e[1]),e[0])) if len(d[0][1])!=1 : print(-1) else : print(d[0][1][0]+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := Set{} ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); if (d)->excludes(x) then ( d[x+1] := Sequence{} ) else skip ; (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; d := d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sortedBy($x | (lambda e : OclAny in (Sequence{(e[1+1])->size(), e->first()}))->apply($x)) ; if (d->first()[1+1])->size() /= 1 then ( execute (-1)->display() ) else ( execute (d->first()[1+1]->first() + 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) d={} used=set() used2=set() for i,x in enumerate(a): if x not in used and x not in used2 : used.add(x) elif x not in used2 : used2.add(x) used.remove(x) d[x]=i if not used : print(-1) else : print(d[min(used)]+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := Set{} ; var used : Set := Set{}->union(()) ; var used2 : Set := Set{}->union(()) ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); if (used)->excludes(x) & (used2)->excludes(x) then ( execute ((x) : used) ) else (if (used2)->excludes(x) then ( execute ((x) : used2) ; execute ((x) /: used) ) else skip) ; d[x+1] := i) ; if not(used) then ( execute (-1)->display() ) else ( execute (d[(used)->min()+1] + 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import product from operator import itemgetter N,M=map(int,input().split()) lights=list(tuple(map(int,input().split()))for _ in range(M)) cons=list(map(int,input().split())) ans=0 for switch in product(range(2),repeat=N): reminders=[] for idx,light in enumerate(lights): f=itemgetter(*map(lambda x : x-1,light[1 :])) if isinstance(f(switch),int): s=f(switch) else : s=sum(f(switch)) reminders.append(s % 2) if cons==reminders : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lights : Sequence := ((argument (test (logical_test (comparison (expr (atom (name tuple)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name M)))))))) ))))))))) ; var cons : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for switch : product(Integer.subrange(0, 2-1), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (name N)))))))) do ( var reminders : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (lights)->size())->collect( _indx | Sequence{_indx-1, (lights)->at(_indx)} ) do (var _indx : int := 1; var idx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var light : OclAny := _tuple->at(_indx); var f : OclAny := itemgetter((argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) , (argument (test (logical_test (comparison (expr (atom (name light)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))))))) ))))))))) ; if (OclType["int"]).isInstance(f(switch)) then ( var s : String := f(switch) ) else ( s := (f(switch))->sum() ) ; execute ((StringLib.format(s,2)) : reminders)) ; if cons = reminders then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) for i in range(x): n=int(input()) l=list(map(int,input().split())) g=l.copy() l.sort() d={} for j in l : if(j in d): d[j]+=1 else : d[j]=1 for j in d : if(d[j]==1): print(g.index(j)+1) break else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, x-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var g : OclAny := l->copy() ; l := l->sort() ; var d : OclAny := Set{} ; for j : l do ( if ((d)->includes(j)) then ( d[j+1] := d[j+1] + 1 ) else ( d[j+1] := 1 )) ; (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name d))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) == (comparison (expr (atom (number (integer 1))))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name g)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) + (expr (atom (number (integer 1)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for x in range(t): n=int(input()) bids=list(map(int,input().split())) dic={} for i in bids : if(i in dic.keys()): dic[i]+=1 else : dic[i]=1 unique_values=[] for i,j in dic.items(): if(j==1): unique_values.append(i) if not unique_values : print(-1) else : print(bids.index((min(unique_values)))+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for x : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var bids : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dic : OclAny := Set{} ; for i : bids do ( if ((dic.keys())->includes(i)) then ( dic[i+1] := dic[i+1] + 1 ) else ( dic[i+1] := 1 )) ; var unique_values : Sequence := Sequence{} ; for _tuple : dic->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if (j = 1) then ( execute ((i) : unique_values) ) else skip) ; if not(unique_values) then ( execute (-1)->display() ) else ( execute (bids->indexOf(((unique_values)->min())) - 1 + 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(i,m,s,memoize): if(i==len(s)): return 0 if(memoize[i][m]!=-1): return memoize[i][m] x=ord(s[i])-ord('0') ans=(((x+m)% 3==0 and x % 2==0)+f(i+1,(m+x)% 3,s,memoize)) memoize[i][m]=ans return memoize[i][m] def countDivBy6(s): n=len(s) memoize=[[-1]*3 for i in range(n+1)] ans=0 for i in range(len(s)): if(s[i]=='0'): ans+=1 else : ans+=f(i,0,s,memoize) return ans if __name__=='__main__' : s="4806" print(countDivBy6(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( s := "4806" ; execute (countDivBy6(s))->display() ) else skip; operation f(i : OclAny, m : OclAny, s : OclAny, memoize : OclAny) : OclAny pre: true post: true activity: if (i = (s)->size()) then ( return 0 ) else skip ; if (memoize[i+1][m+1] /= -1) then ( return memoize[i+1][m+1] ) else skip ; var x : double := (s[i+1])->char2byte() - ('0')->char2byte() ; var ans : boolean := (((x + m) mod 3 = 0 & x mod 2 = 0) + f(i + 1, (m + x) mod 3, s, memoize)) ; memoize[i+1][m+1] := ans ; return memoize[i+1][m+1]; operation countDivBy6(s : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; memoize := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ -1 }, 3))) ; ans := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if (s[i+1] = '0') then ( ans := ans + 1 ) else ( ans := ans + f(i, 0, s, memoize) )) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil def Min_glass(n,k,a): a.sort() return ceil(sum(a[: k])/100) if __name__=="__main__" : n,k=4,3 a=[200,150,140,300] print(Min_glass(n,k,a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( Sequence{n,k} := Sequence{4,3} ; a := Sequence{200}->union(Sequence{150}->union(Sequence{140}->union(Sequence{ 300 }))) ; execute (Min_glass(n, k, a))->display() ) else skip; operation Min_glass(n : OclAny, k : OclAny, a : OclAny) : OclAny pre: true post: true activity: a := a->sort() ; return ceil((a.subrange(1,k))->sum() / 100); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from typing import List,Tuple def max_beauty(n : int,m : int,points : List[Tuple[int,int]])->int : maxN=100005 dp=[0]*maxN edge=[[]for i in range(maxN)] for u,v in points : edge[u].append(v) edge[v].append(u) ans=-1 ; for v in range(1,n+1): dp[v]=1 for u in edge[v]: if ucollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{b, c}) : a)) ; execute (max_beauty(n, m, a))->display(); operation max_beauty(n : int, m : int, points : List[Tuple[OclType["int"]+1][OclType["int"]+1]+1]) : int pre: true post: true activity: var maxN : int := 100005 ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, maxN) ; var edge : Sequence := Integer.subrange(0, maxN-1)->select(i | true)->collect(i | (Sequence{})) ; for _tuple : points do (var _indx : int := 1; var u : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) ; (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)))))))) ))))) ; var ans : int := -1; ; for v : Integer.subrange(1, n + 1-1) do ( dp[v+1] := 1 ; for u : edge[v+1] do ( if (u->compareTo(v)) < 0 then ( dp[v+1] := Set{dp[v+1], dp[u+1] + 1}->max() ) else skip) ; ans := Set{ans, dp[v+1] * (edge[v+1])->size()}->max()) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_num(u,map,vis): if u in vis : return 0 ; else : vis[u]=True ; ans=0 ; if u in map : for v in map[u]: ans+=get_num(v,map,vis); else : ans+=1 ; return ans ; def main(): while True : n=int(input()); if n==0 : break ; edge={}; name={}; vis={}; for i in range(0,n): str=input(); u=name[i]=str.split(':')[0]; group=str.split(':')[1].split('.')[0].split(','); for v in group : if u in edge : edge[u][v]=True ; else : edge[u]={v : True}; print(get_num(name[0],edge,vis)); main(); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main();; operation get_num(u : OclAny, map : OclAny, vis : OclAny) pre: true post: true activity: if (vis)->includes(u) then ( return 0; ) else ( vis[u+1] := true; ) ; var ans : int := 0; ; if (map)->includes(u) then ( for v : ([u+1]`third)->collect( _x | ([u+1])->apply(_x) ) do ( ans := ans + get_num(v, map, vis);) ) else ( ans := ans + 1; ) ; return ans;; operation main() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); ; if n = 0 then ( break; ) else skip ; var edge : OclAny := Set{}; var name : OclAny := Set{}; vis := Set{}; ; for i : Integer.subrange(0, n-1) do ( var OclType["String"] : String := (OclFile["System.in"]).readLine(); ; u := OclType["String"].split(':')->first(); var name[i+1] : OclAny := OclType["String"].split(':')->first(); ; var group : OclAny := OclType["String"].split(':')[1+1].split('.')->first().split(','); ; for v : group do ( if (edge)->includes(u) then ( edge[u+1][v+1] := true; ) else ( edge[u+1] := Map{ v |-> true }; ))) ; execute (get_num(name->first(), edge, vis))->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,setrecursionlimit setrecursionlimit(100000) class Graph : def __init__(self,No_of_nodes): self.n=No_of_nodes self.adj=[[]for i in range(self.n)] def addEdge(self,a,b): self.adj[a].append(b) self.adj[b].append(a) count[a][0]+=1 count[b][0]+=1 def solve(start): for i in g.adj[start]: if iexists( _x | result = _x ); attribute n : OclAny := No_of_nodes; attribute adj : Sequence := Integer.subrange(0, self.n-1)->select(i | true)->collect(i | (Sequence{})); operation initialise(No_of_nodes : OclAny) : Graph pre: true post: true activity: self.n := No_of_nodes ; self.adj := Integer.subrange(0, self.n-1)->select(i | true)->collect(i | (Sequence{})); return self; operation addEdge(a : OclAny,b : OclAny) pre: true post: true activity: (expr (atom (name self)) (trailer . (name adj) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name self)) (trailer . (name adj) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))) ; count[a+1]->first() := count[a+1]->first() + 1 ; count[b+1]->first() := count[b+1]->first() + 1; } class FromPython { operation initialise() pre: true post: true activity: skip ; setrecursionlimit(100000) ; skip ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var g : Graph := (Graph.newGraph()).initialise(n) ; var count : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{0}->union(Sequence{ i }))) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, n) ; for i : Integer.subrange(0, m-1) do ( Sequence{a,b} := (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := a - 1 ; b := b - 1 ; g.addEdge(a, b)) ; for i : Integer.subrange(0, n-1) do ( solve(i)) ; var ans : int := -1000 ; for i : Integer.subrange(0, n-1) do ( if dp[i+1] /= -1 then ( ans := Set{ans, (dp[i+1]) * (g.adj[i+1])->size()}->max() ) else skip) ; execute (ans)->display(); operation solve(start : OclAny) : OclAny pre: true post: true activity: for i : g.adj[start+1] do ( if (i->compareTo(start)) < 0 then ( dp[start+1] := Set{dp[start+1], dp[i+1] + 1}->max() ) else skip) ; return dp[start+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) g=[[]for i in range(n)] for _ in range(m): u,v=map(int,input().split()) u-=1 v-=1 g[u].append(v) g[v].append(u) dp=[1]*n for i in range(n): for j in g[i]: if icollect( _x | (OclType["int"])->apply(_x) ) ; var g : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for _anon : Integer.subrange(0, m-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; u := u - 1 ; v := v - 1 ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)))))))) ))))) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, n) ; for i : Integer.subrange(0, n-1) do ( for j : g[i+1] do ( if (i->compareTo(j)) < 0 then ( dp[j+1] := Set{dp[j+1], dp[i+1] + 1}->max() ) else skip)) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( ans := Set{ans, (g[i+1])->size() * dp[i+1]}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys lines=sys.stdin.read().splitlines() n,m=map(int,lines[0].split()) edges=[[]for _ in range(n)] for line_i in range(1,1+m): u,v=map(int,lines[line_i].split()) edges[u-1].append(v-1) edges[v-1].append(u-1) longest=[0 for _ in range(n)] for index in range(n): longest[index]=max(map(lambda x : longest[x],filter(lambda x : xfirst().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var edges : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for line_i : Integer.subrange(1, 1 + m-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := (lines[line_i+1].split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name u))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name u))) - (expr (atom (number (integer 1)))))))))) ))))) ; var longest : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)) ; for index : Integer.subrange(0, n-1) do ( longest[index+1] := Set{((edges[index+1])->select( _x | (lambda x : OclAny in ((x->compareTo(index)) < 0))->apply(_x) = true ))->collect( _x | (lambda x : OclAny in (longest[x+1]))->apply(_x) ), (argument (test (logical_test (comparison (expr (atom (name default)))))) = (test (logical_test (comparison (expr (atom - (number (integer 1))))))))}->max() + 1) ; var best_hedgehog : int := 0 ; for index : Integer.subrange(0, n-1) do ( best_hedgehog := Set{best_hedgehog, (longest[index+1] + 1) * (edges[index+1])->size()}->max()) ; execute (best_hedgehog)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import comb from collections import deque input=sys.stdin.readline n,m=map(int,input().split()) h=[[]for i in range(n+1)] for i in range(m): a,b=map(int,input().split()) h[a].append(b) h[b].append(a) maxvalue=-sys.maxsize l=[1 for i in range(n+1)] for i in range(1,n+1): for j in h[i]: if icollect( _x | (OclType["int"])->apply(_x) ) ; var h : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name h)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name h)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var maxvalue : (trailer . (name maxsize)) := -(trailer . (name maxsize)) ; var l : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (1)) ; for i : Integer.subrange(1, n + 1-1) do ( for j : h[i+1] do ( if (i->compareTo(j)) < 0 then ( l[j+1] := Set{l[j+1], l[i+1] + 1}->max() ) else skip)) ; var ans : int := 0 ; for j : Integer.subrange(1, n + 1-1) do ( ans := Set{ans, l[j+1] * (h[j+1])->size()}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(100000) W,H=map(int,input().split()) m=[list(map(int,input().split()))for i in range(H)] dx=[[1,1,1,0,-1,0],[0,1,0,-1,-1,-1]] dy=[-1,0,1,1,0,-1] def dfs(x,y): if m[y][x]!=0 : return m[y][x]=2 for xx,yy in zip(dx[y % 2],dy): tx,ty=x+xx,y+yy if 0<=txcollect( _x | (OclType["int"])->apply(_x) ) ; var m : Sequence := Integer.subrange(0, H-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var dx : Sequence := Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{ 0 })))))}->union(Sequence{ Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{-1}->union(Sequence{ -1 }))))) }) ; var dy : Sequence := Sequence{-1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ -1 }))))) ; skip ; for x : Integer.subrange(0, W-1) do ( dfs(x, 0) ; dfs(x, H - 1)) ; for y : Integer.subrange(0, H-1) do ( dfs(0, y) ; dfs(W - 1, y)) ; skip ; var n : int := 0 ; for _tuple : product(Integer.subrange(0, W-1), Integer.subrange(0, H-1)) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if m[y+1][x+1] /= 1 then ( continue ) else skip ; var fn : int := n ; for _tuple : Integer.subrange(1, dx[y mod 2+1]->size())->collect( _indx | Sequence{dx[y mod 2+1]->at(_indx), dy->at(_indx)} ) do (var _indx : int := 1; var xx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var yy : OclAny := _tuple->at(_indx); var tx : OclAny := null; var ty : OclAny := null; Sequence{tx,ty} := Sequence{x + xx,y + yy} ; if 0 <= tx & (tx < W) & 0 <= ty & (ty < H) then ( if m[ty+1][tx+1] = 2 then ( n := n + 1 ) else skip ) else ( n := n + 1 ))) ; execute (n)->display(); operation dfs(x : OclAny, y : OclAny) pre: true post: true activity: if m[y+1][x+1] /= 0 then ( return ) else skip ; m[y+1][x+1] := 2 ; for _tuple : Integer.subrange(1, dx[y mod 2+1]->size())->collect( _indx | Sequence{dx[y mod 2+1]->at(_indx), dy->at(_indx)} ) do (var _indx : int := 1; var xx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var yy : OclAny := _tuple->at(_indx); var tx : OclAny := null; var ty : OclAny := null; Sequence{tx,ty} := Sequence{x + xx,y + yy} ; if 0 <= tx & (tx < W) & 0 <= ty & (ty < H) then ( dfs(tx, ty) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def check(n): d=int(math.sqrt(n)) if(d*d==n): return True return False def largestNonPerfectSquareNumber(a,n): maxi=-1 for i in range(0,n): if(check(a[i])==False): maxi=max(a[i],maxi) return maxi a=[16,20,25,2,3,10] n=len(a) print(largestNonPerfectSquareNumber(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; a := Sequence{16}->union(Sequence{20}->union(Sequence{25}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 10 }))))) ; n := (a)->size() ; execute (largestNonPerfectSquareNumber(a, n))->display(); operation check(n : OclAny) : OclAny pre: true post: true activity: var d : int := ("" + (((n)->sqrt())))->toInteger() ; if (d * d = n) then ( return true ) else skip ; return false; operation largestNonPerfectSquareNumber(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var maxi : int := -1 ; for i : Integer.subrange(0, n-1) do ( if (check(a[i+1]) = false) then ( maxi := Set{a[i+1], maxi}->max() ) else skip) ; return maxi; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countDigits(a,b): count=0 p=abs(a*b) if(p==0): return 1 while(p>0): count=count+1 p=p//10 return count a=33 b=-24 print("Number of digits=",countDigits(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 33 ; b := -24 ; execute ("Number of digits=")->display(); operation countDigits(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var p : double := (a * b)->abs() ; if (p = 0) then ( return 1 ) else skip ; while (p > 0) do ( count := count + 1 ; p := p div 10) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class rankMatrix(object): def __init__(self,Matrix): self.R=len(Matrix) self.C=len(Matrix[0]) def swap(self,Matrix,row1,row2,col): for i in range(col): temp=Matrix[row1][i] Matrix[row1][i]=Matrix[row2][i] Matrix[row2][i]=temp def Display(self,Matrix,row,col): for i in range(row): for j in range(col): print(" "+str(Matrix[i][j])) print('\n') def rankOfMatrix(self,Matrix): rank=self.C for row in range(0,rank,1): if Matrix[row][row]!=0 : for col in range(0,self.R,1): if col!=row : multiplier=(Matrix[col][row]/Matrix[row][row]) for i in range(rank): Matrix[col][i]-=(multiplier*Matrix[row][i]) else : reduce=True for i in range(row+1,self.R,1): if Matrix[i][row]!=0 : self.swap(Matrix,row,i,rank) reduce=False break if reduce : rank-=1 for i in range(0,self.R,1): Matrix[i][row]=Matrix[i][rank] row-=1 return(rank) if __name__=='__main__' : Matrix=[[10,20,10],[-20,-30,10],[30,50,0]] RankMatrix=rankMatrix(Matrix) print("Rank of the Matrix is:",(RankMatrix.rankOfMatrix(Matrix))) ------------------------------------------------------------ OCL File: --------- class rankMatrix extends object { static operation newrankMatrix() : rankMatrix pre: true post: rankMatrix->exists( _x | result = _x ); attribute R : int := (Matrix)->size(); attribute C : int := (Matrix->first())->size(); operation initialise(Matrix : OclAny) : pre: true post: true activity: self.R := (Matrix)->size() ; self.C := (Matrix->first())->size(); return self; operation swap(Matrix : OclAny,row1 : OclAny,row2 : OclAny,col : OclAny) pre: true post: true activity: for i : Integer.subrange(0, col-1) do ( var temp : OclAny := Matrix[row1+1][i+1] ; Matrix[row1+1][i+1] := Matrix[row2+1][i+1] ; Matrix[row2+1][i+1] := temp); operation Display(Matrix : OclAny,row : OclAny,col : OclAny) pre: true post: true activity: for i : Integer.subrange(0, row-1) do ( for j : Integer.subrange(0, col-1) do ( execute (" " + ("" + ((Matrix[i+1][j+1]))))->display()) ; execute (' ')->display()); operation rankOfMatrix(Matrix : OclAny) : OclAny pre: true post: true activity: var rank : OclAny := self.C ; for row : Integer.subrange(0, rank-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if Matrix[row+1][row+1] /= 0 then ( for col : Integer.subrange(0, self.R-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if col /= row then ( var multiplier : double := (Matrix[col+1][row+1] / Matrix[row+1][row+1]) ; for i : Integer.subrange(0, rank-1) do ( Matrix[col+1][i+1] := Matrix[col+1][i+1] - (multiplier * Matrix[row+1][i+1])) ) else skip) ) else ( var reduce : boolean := true ; for i : Integer.subrange(row + 1, self.R-1)->select( $x | ($x - row + 1) mod 1 = 0 ) do ( if Matrix[i+1][row+1] /= 0 then ( self.swap(Matrix, row, i, rank) ; reduce := false ; break ) else skip) ; if reduce then ( rank := rank - 1 ; for i : Integer.subrange(0, self.R-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( Matrix[i+1][row+1] := Matrix[i+1][rank+1]) ) else skip ; row := row - 1 )) ; return (rank); } class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( Matrix := Sequence{Sequence{10}->union(Sequence{20}->union(Sequence{ 10 }))}->union(Sequence{Sequence{-20}->union(Sequence{-30}->union(Sequence{ 10 }))}->union(Sequence{ Sequence{30}->union(Sequence{50}->union(Sequence{ 0 })) })) ; var RankMatrix : rankMatrix := (rankMatrix.newrankMatrix()).initialise(Matrix) ; execute ("Rank of the Matrix is:")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(): N=int(input()) s=[0]*N for _ in[0]*(N*~-N//2): a,b,c,d=map(int,input().split()) s[a-1]+=3*(c>d)+(c==d) s[b-1]+=3*(d>c)+(d==c) b=[[]for _ in[0]*N*3] for i in range(N): b[s[i]]+=[i] r=1 for x in b[: :-1]: for y in x : s[y]=r if x : r+=len(x) print(*s,sep='\n') f() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; f(); operation f() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, (N * MathLib.bitwiseNot(-N) div 2)) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; s[a - 1+1] := s[a - 1+1] + 3 * ((c->compareTo(d)) > 0) + (c = d) ; s[b - 1+1] := s[b - 1+1] + 3 * ((d->compareTo(c)) > 0) + (d = c)) ; var b : Sequence := MatrixLib.elementwiseMult(MatrixLib.elementwiseMult(Sequence{ 0 }, N), 3)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, N-1) do ( b[s[i+1]+1] := b[s[i+1]+1] + Sequence{ i }) ; var r : int := 1 ; for x : b(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( for y : x do ( s[y+1] := r) ; if x then ( r := r + (x)->size() ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name s))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[list(map(int,input().split()))for i in range(n*(n-1)//2)] p=[[0,i,0]for i in range(n+1)] for i in range(n*(n-1)//2): if l[i][2]==l[i][3]: p[l[i][0]][0]+=1 p[l[i][1]][0]+=1 elif l[i][2]>l[i][3]: p[l[i][0]][0]+=3 else : p[l[i][1]][0]+=3 p=sorted(p,key=lambda x :-x[0]) p.pop(-1) rank=1 k=[p[i][0]for i in range(n)] for i in range(n): if k.count(p[i][0])==1 : p[i][2]=rank rank+=1 else : p[i][2]=rank if i+2==rank+k.count(p[i][0]): rank+=k.count(p[i][0]) p=sorted(p,key=lambda x : x[1]) for i in range(n): print(p[i][2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Integer.subrange(0, n * (n - 1) div 2-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var p : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Sequence{0}->union(Sequence{i}->union(Sequence{ 0 })))) ; for i : Integer.subrange(0, n * (n - 1) div 2-1) do ( if l[i+1][2+1] = l[i+1][3+1] then ( p[l[i+1]->first()+1]->first() := p[l[i+1]->first()+1]->first() + 1 ; p[l[i+1][1+1]+1]->first() := p[l[i+1][1+1]+1]->first() + 1 ) else (if (l[i+1][2+1]->compareTo(l[i+1][3+1])) > 0 then ( p[l[i+1]->first()+1]->first() := p[l[i+1]->first()+1]->first() + 3 ) else ( p[l[i+1][1+1]+1]->first() := p[l[i+1][1+1]+1]->first() + 3 ) ) ) ; p := p->sortedBy($x | (lambda x : OclAny in (-x->first()))->apply($x)) ; p := p->excludingAt(-1+1) ; var rank : int := 1 ; var k : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (p[i+1]->first())) ; for i : Integer.subrange(0, n-1) do ( if k->count(p[i+1]->first()) = 1 then ( p[i+1][2+1] := rank ; rank := rank + 1 ) else ( p[i+1][2+1] := rank ; if i + 2 = rank + k->count(p[i+1]->first()) then ( rank := rank + k->count(p[i+1]->first()) ) else skip )) ; p := p->sortedBy($x | (lambda x : OclAny in (x[1+1]))->apply($x)) ; for i : Integer.subrange(0, n-1) do ( execute (p[i+1][2+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): number_of_team=int(input()) result_matrix=[list(map(int,input().split()))for l in range(int(number_of_team*(number_of_team-1)/2))] points_of_team=[0 for l in range(number_of_team)] for low in result_matrix : if low[2]==low[3]: points_of_team[int(low[0])-1]+=1 points_of_team[int(low[1])-1]+=1 elif low[2]>low[3]: points_of_team[int(low[0])-1]+=3 else : points_of_team[int(low[1])-1]+=3 sort_list=sorted(points_of_team,reverse=True) result_list=[0 for i in range(number_of_team)] rank=1 pred=sort_list[0] for i in range(number_of_team): max_index=points_of_team.index(sort_list[i]) if pred!=sort_list[i]: pred=sort_list[i] rank=i+1 result_list[max_index]=rank points_of_team[max_index]=-1 for i in range(number_of_team): print(result_list[i]) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var number_of_team : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var result_matrix : Sequence := Integer.subrange(0, ("" + ((number_of_team * (number_of_team - 1) / 2)))->toInteger()-1)->select(l | true)->collect(l | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var points_of_team : Sequence := Integer.subrange(0, number_of_team-1)->select(l | true)->collect(l | (0)) ; for low : result_matrix do ( if low[2+1] = low[3+1] then ( points_of_team[("" + ((low->first())))->toInteger() - 1+1] := points_of_team[("" + ((low->first())))->toInteger() - 1+1] + 1 ; points_of_team[("" + ((low[1+1])))->toInteger() - 1+1] := points_of_team[("" + ((low[1+1])))->toInteger() - 1+1] + 1 ) else (if (low[2+1]->compareTo(low[3+1])) > 0 then ( points_of_team[("" + ((low->first())))->toInteger() - 1+1] := points_of_team[("" + ((low->first())))->toInteger() - 1+1] + 3 ) else ( points_of_team[("" + ((low[1+1])))->toInteger() - 1+1] := points_of_team[("" + ((low[1+1])))->toInteger() - 1+1] + 3 ) ) ) ; var sort_list : Sequence := points_of_team->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var result_list : Sequence := Integer.subrange(0, number_of_team-1)->select(i | true)->collect(i | (0)) ; var rank : int := 1 ; var pred : OclAny := sort_list->first() ; for i : Integer.subrange(0, number_of_team-1) do ( var max_index : int := points_of_team->indexOf(sort_list[i+1]) - 1 ; if pred /= sort_list[i+1] then ( pred := sort_list[i+1] ; rank := i + 1 ) else skip ; result_list[max_index+1] := rank ; points_of_team[max_index+1] := -1) ; for i : Integer.subrange(0, number_of_team-1) do ( execute (result_list[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(dic,index): ret=[] for c in dic[index]: if c in dic.keys(): for d in check(dic,c): if not(d in ret): ret.append(d) else : if not(c in ret): ret.append(c) dic[index]=ret return ret while True : n=int(input()) if n==0 : break dic={} index='' for i in range(n): a,b=[char for char in input()[0 :-1].split(':')] if i==0 : index=a b=b.split(',') dic[a]=b print(len(check(dic,index))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; dic := Set{} ; index := '' ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().subrange(0+1, -1).split(':')->select(char | true)->collect(char | (char)) ; if i = 0 then ( index := a ) else skip ; var b : OclAny := b.split(',') ; dic[a+1] := b) ; execute ((check(dic, index))->size())->display()); operation check(dic : OclAny, index : OclAny) : OclAny pre: true post: true activity: var ret : Sequence := Sequence{} ; for c : dic[index+1] do ( if (dic.keys())->includes(c) then ( for d : check(dic, c) do ( if not(((ret)->includes(d))) then ( execute ((d) : ret) ) else skip) ) else ( if not(((ret)->includes(c))) then ( execute ((c) : ret) ) else skip )) ; dic[index+1] := ret ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy n=int(input()) game=n*(n-1)//2 point=[0]*n for _ in range(game): a,b,c,d=map(int,input().split()) if c>d : point[a-1]+=3 elif ctoInteger() ; var game : int := n * (n - 1) div 2 ; var point : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for _anon : Integer.subrange(0, game-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (c->compareTo(d)) > 0 then ( point[a - 1+1] := point[a - 1+1] + 3 ) else (if (c->compareTo(d)) < 0 then ( point[b - 1+1] := point[b - 1+1] + 3 ) else ( point[a - 1+1] := point[a - 1+1] + 1 ; point[b - 1+1] := point[b - 1+1] + 1 ) ) ) ; var point_tmp : OclAny := copy.deepcopy(point) ; point_tmp := point_tmp->sort() ; var grade : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for _tuple : Integer.subrange(1, (point)->size())->collect( _indx | Sequence{_indx-1, (point)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p : OclAny := _tuple->at(_indx); grade[i+1] := point_tmp->indexOf(p) - 1 + 1) ; for g : grade do ( execute (g)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): team_num=int(input()) match_num=int((team_num*(team_num-1))/2) win_points={} for i in range(team_num): win_points[i+1]=0 for i in range(match_num): match_result=input().split(" ") teamA_num=int(match_result[0]) teamB_num=int(match_result[1]) teamA_point=int(match_result[2]) teamB_point=int(match_result[3]) if teamA_point>teamB_point : win_points[teamA_num]+=3 elif teamA_pointtoInteger() ; var match_num : int := ("" + (((team_num * (team_num - 1)) / 2)))->toInteger() ; var win_points : OclAny := Set{} ; for i : Integer.subrange(0, team_num-1) do ( win_points[i + 1+1] := 0) ; for i : Integer.subrange(0, match_num-1) do ( var match_result : OclAny := input().split(" ") ; var teamA_num : int := ("" + ((match_result->first())))->toInteger() ; var teamB_num : int := ("" + ((match_result[1+1])))->toInteger() ; var teamA_point : int := ("" + ((match_result[2+1])))->toInteger() ; var teamB_point : int := ("" + ((match_result[3+1])))->toInteger() ; if (teamA_point->compareTo(teamB_point)) > 0 then ( win_points[teamA_num+1] := win_points[teamA_num+1] + 3 ) else (if (teamA_point->compareTo(teamB_point)) < 0 then ( win_points[teamB_num+1] := win_points[teamB_num+1] + 3 ) else ( win_points[teamA_num+1] := win_points[teamA_num+1] + 1 ; win_points[teamB_num+1] := win_points[teamB_num+1] + 1 ) ) ) ; var win_points_sorted : Sequence := win_points->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sortedBy($x | (lambda x : OclAny in (x[1+1]))->apply($x)) ; var pre_team_point : int := -1 ; var ranks : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, team_num) ; var rank : int := 0 ; for i : Integer.subrange(0, (win_points_sorted)->size()-1) do ( if win_points_sorted[i+1][1+1] /= pre_team_point then ( rank := i + 1 ) else skip ; ranks[win_points_sorted[i+1]->first() - 1+1] := rank ; pre_team_point := win_points_sorted[i+1][1+1]) ; for i : ranks do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math class Node : def __init__(self,data): self.data=data self.next=None def push(head_ref,new_data): new_node=Node(new_data) new_node.data=new_data new_node.next=head_ref head_ref=new_node return head_ref def sumOfNodes(head): ptr=head sum=0 while(ptr!=None): sum=sum+ptr.data ptr=ptr.next return sum if __name__=='__main__' : head=None head=push(head,7) head=push(head,6) head=push(head,8) head=push(head,4) head=push(head,1) print("Sum of nodes=",sumOfNodes(head)) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.next := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( head := null ; head := push(head, 7) ; head := push(head, 6) ; head := push(head, 8) ; head := push(head, 4) ; head := push(head, 1) ; execute ("Sum of nodes=")->display() ) else skip; operation push(head_ref : OclAny, new_data : OclAny) : OclAny pre: true post: true activity: var new_node : Node := (Node.newNode()).initialise(new_data) ; new_node.data := new_data ; new_node.next := head_ref ; head_ref := new_node ; return head_ref; operation sumOfNodes(head : OclAny) : OclAny pre: true post: true activity: var ptr : OclAny := head ; var sum : int := 0 ; while (ptr /= null) do ( sum := sum + ptr.data ; ptr := ptr.next) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): from collections import deque from copy import deepcopy W,H=map(int,input().split()) a=[[0]*(W+2)]+[list(map(int,("0 "+input()+" 0").split()))for _ in[0]*H]+[[0]*(W+2)] result=0 visited=deepcopy(a) dq=deque([(0,0)]) append,popleft=dq.append,dq.popleft while dq : x,y=popleft() neighbour=[(-1,0),(1,0)]+([(-1,-1),(0,-1),(-1,1),(0,1)]if y % 2==0 else[(0,-1),(1,-1),(0,1),(1,1)]) for dx,dy in neighbour : nx,ny=dx+x,dy+y if 0<=nxcollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{ MatrixLib.elementwiseMult(Sequence{ 0 }, (W + 2)) }->union(MatrixLib.elementwiseMult(Sequence{ 0 }, H)->select(_anon | true)->collect(_anon | (((("0 " + (OclFile["System.in"]).readLine() + " 0").split())->collect( _x | (OclType["int"])->apply(_x) )))))->union(Sequence{ MatrixLib.elementwiseMult(Sequence{ 0 }, (W + 2)) }) ; var result : int := 0 ; var visited : OclAny := deepcopy(a) ; var dq : Sequence := (Sequence{ Sequence{0, 0} }) ; var append : OclAny := null; var popleft : OclAny := null; Sequence{append,popleft} := Sequence{dq.append,dq.popleft} ; while dq do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := popleft() ; var neighbour : Sequence := Sequence{Sequence{-1, 0}}->union(Sequence{ Sequence{1, 0} })->union((if y mod 2 = 0 then Sequence{Sequence{-1, -1}}->union(Sequence{Sequence{0, -1}}->union(Sequence{Sequence{-1, 1}}->union(Sequence{ Sequence{0, 1} }))) else Sequence{Sequence{0, -1}}->union(Sequence{Sequence{1, -1}}->union(Sequence{Sequence{0, 1}}->union(Sequence{ Sequence{1, 1} }))) endif)) ; for _tuple : neighbour do (var _indx : int := 1; var dx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dy : OclAny := _tuple->at(_indx); var nx : OclAny := null; var ny : OclAny := null; Sequence{nx,ny} := Sequence{dx + x,dy + y} ; if 0 <= nx & (nx < W + 2) & 0 <= ny & (ny < H + 2) then ( result := result + a[ny+1][nx+1] ) else skip) ; for _tuple : neighbour do (var _indx : int := 1; var dx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dy : OclAny := _tuple->at(_indx); var nx : OclAny := null; var ny : OclAny := null; Sequence{nx,ny} := Sequence{x + dx,y + dy} ; if 0 <= nx & (nx < W + 2) & 0 <= ny & (ny < H + 2) & visited[ny+1][nx+1] = 0 then ( visited[ny+1][nx+1] := 1 ; append(Sequence{nx, ny}) ) else skip)) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math class Sum : tsum=None class Node : def __init__(self,data): self.data=data self.next=None def push(head,data): if not head : return Node(data) new_node=Node(data) new_node.next=head head=new_node return head def sumOfNode(head,S): if not head : return sumOfNode(head.next,S) S.tsum+=head.data def sumOfNodesUtil(head): S=Sum() S.tsum=0 sumOfNode(head,S) return S.tsum if __name__=='__main__' : head=None head=push(head,7) head=push(head,6) head=push(head,8) head=push(head,4) head=push(head,1) print("Sum of Nodes={}".format(sumOfNodesUtil(head))) ------------------------------------------------------------ OCL File: --------- class Sum { static operation newSum() : Sum pre: true post: Sum->exists( _x | result = _x ); static attribute tsum : OclAny := null; } class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.next := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( head := null ; head := push(head, 7) ; head := push(head, 6) ; head := push(head, 8) ; head := push(head, 4) ; head := push(head, 1) ; execute (StringLib.interpolateStrings("Sum of Nodes={}", Sequence{sumOfNodesUtil(head)}))->display() ) else skip; operation push(head : OclAny, data : OclAny) : OclAny pre: true post: true activity: if not(head) then ( return (Node.newNode()).initialise(data) ) else skip ; var new_node : Node := (Node.newNode()).initialise(data) ; new_node.next := head ; head := new_node ; return head; operation sumOfNode(head : OclAny, S : OclAny) pre: true post: true activity: if not(head) then ( return ) else skip ; sumOfNode(head.next, S) ; S.tsum := S.tsum + head.data; operation sumOfNodesUtil(head : OclAny) : OclAny pre: true post: true activity: S := (Sum.newSum()).initialise() ; S.tsum := 0 ; sumOfNode(head, S) ; return S.tsum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def claim_differ(hp,mydmg,twrdmg): towShots=hp/twrdmg hp %=twrdmg if hp==0 : towShots-=1 hp+=twrdmg myShots=hp/mydmg hp %=mydmg if hp>0 : myShots+=1 hp=0 return towShots-myShots def leave_differ(hp,twrdmg): towShots=hp/twrdmg hp %=twrdmg if hp>0 : towShots+=1 hp=0 return towShots INF=10**12 def max_gain(mem,hps,glds,mydmg,twrdmg,mstr,extra_shots): if extra_shots<0 : return-INF if len(hps)==mstr : return 0 key=(mstr,extra_shots) if key in mem : return mem[key] cd=claim_differ(hps[mstr],mydmg,twrdmg) res1=glds[mstr]+max_gain(mem,hps,glds,mydmg,twrdmg,mstr+1,extra_shots+cd) ld=leave_differ(hps[mstr],twrdmg) res2=max_gain(mem,hps,glds,mydmg,twrdmg,mstr+1,extra_shots+ld) best=max(res1,res2) mem[key]=best return best import sys infname=sys.argv[1] with open(infname)as inf : with open(infname.replace('.in','.out'),'w')as outf : T=int(inf.readline()) for t in range(1,T+1): mydmg,twrdmg,N=map(int,inf.readline().split()) hps,glds=[],[] for _ in range(N): hp,gld=map(int,inf.readline().split()) hps.append(hp) glds.append(gld) outf.write('Case #{}:{}\n'.format(t,max_gain({},hps,glds,mydmg,twrdmg,0,1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var INF : double := (10)->pow(12) ; skip ; skip ; var infname : (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) := (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) ; try (var Math_PINFINITY : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(infname)); try (var outf : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(infname.replace('.in', '.out'))); var T : int := ("" + ((Math_PINFINITY.readLine())))->toInteger() ; for t : Integer.subrange(1, T + 1-1) do ( var N : OclAny := null; Sequence{mydmg,twrdmg,N} := (Math_PINFINITY.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; Sequence{hps,glds} := Sequence{Sequence{},Sequence{}} ; for _anon : Integer.subrange(0, N-1) do ( var gld : OclAny := null; Sequence{hp,gld} := (Math_PINFINITY.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((hp) : hps) ; execute ((gld) : glds)) ; outf.write(StringLib.interpolateStrings('Case #{}:{} ', Sequence{t, max_gain(Set{}, hps, glds, mydmg, twrdmg, 0, 1)})))) catch (_e : OclException) do skip) catch (_e : OclException) do skip; operation claim_differ(hp : OclAny, mydmg : OclAny, twrdmg : OclAny) : OclAny pre: true post: true activity: var towShots : double := hp / twrdmg ; hp := hp mod twrdmg ; if hp = 0 then ( towShots := towShots - 1 ; hp := hp + twrdmg ) else skip ; var myShots : double := hp / mydmg ; hp := hp mod mydmg ; if hp > 0 then ( myShots := myShots + 1 ; hp := 0 ) else skip ; return towShots - myShots; operation leave_differ(hp : OclAny, twrdmg : OclAny) : OclAny pre: true post: true activity: towShots := hp / twrdmg ; hp := hp mod twrdmg ; if hp > 0 then ( towShots := towShots + 1 ; hp := 0 ) else skip ; return towShots; operation max_gain(mem : OclAny, hps : OclAny, glds : OclAny, mydmg : OclAny, twrdmg : OclAny, mstr : OclAny, extra_shots : OclAny) : OclAny pre: true post: true activity: if extra_shots < 0 then ( return -INF ) else skip ; if (hps)->size() = mstr then ( return 0 ) else skip ; var key : OclAny := Sequence{mstr, extra_shots} ; if (mem)->includes(key) then ( return mem[key+1] ) else skip ; var cd : OclAny := claim_differ(hps[mstr+1], mydmg, twrdmg) ; var res1 : OclAny := glds[mstr+1] + max_gain(mem, hps, glds, mydmg, twrdmg, mstr + 1, extra_shots + cd) ; var ld : OclAny := leave_differ(hps[mstr+1], twrdmg) ; var res2 : OclAny := max_gain(mem, hps, glds, mydmg, twrdmg, mstr + 1, extra_shots + ld) ; var best : OclAny := Set{res1, res2}->max() ; mem[key+1] := best ; return best; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for ti in range(1,int(input())+1): p,q,n=[int(x)for x in input().split()] bests=[(0,1)] for i in range(n): h,g=[int(x)for x in input().split()] towershots=(h+q-1)//q bestdiff=100 for j in range(towershots): k=(h-q*j+p-1)//p if k-j=bestdiff : newbests.append((best[0]+g,best[1]-bestdiff)) newbests=sorted(newbests) last=newbests[-1] bests=[last] for i in reversed(range(0,len(newbests)-1)): if newbests[i][0]>last[0]or newbests[i][1]>last[1]: bests.append(newbests[i]) last=newbests[i] print('Case #'+str(ti)+':',bests[0][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for ti : Integer.subrange(1, ("" + (((OclFile["System.in"]).readLine())))->toInteger() + 1-1) do ( var p : OclAny := null; var q : OclAny := null; var n : OclAny := null; Sequence{p,q,n} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var bests : Sequence := Sequence{ Sequence{0, 1} } ; for i : Integer.subrange(0, n-1) do ( var h : OclAny := null; var g : OclAny := null; Sequence{h,g} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var towershots : int := (h + q - 1) div q ; var bestdiff : int := 100 ; for j : Integer.subrange(0, towershots-1) do ( var k : int := (h - q * j + p - 1) div p ; if (k - j->compareTo(bestdiff)) < 0 then ( bestdiff := k - j ) else skip) ; var newbests : Sequence := Sequence{} ; for best : bests do ( execute ((Sequence{best->first(), best[1+1] + towershots}) : newbests) ; if (best[1+1]->compareTo(bestdiff)) >= 0 then ( execute ((Sequence{best->first() + g, best[1+1] - bestdiff}) : newbests) ) else skip) ; newbests := newbests->sort() ; var last : OclAny := newbests->last() ; bests := Sequence{ last } ; for i : (Integer.subrange(0, (newbests)->size() - 1-1))->reverse() do ( if (newbests[i+1]->first()->compareTo(last->first())) > 0 or (newbests[i+1][1+1]->compareTo(last[1+1])) > 0 then ( execute ((newbests[i+1]) : bests) ; last := newbests[i+1] ) else skip)) ; execute ('Case #' + ("" + ((ti))) + ':')->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys t=int(sys.stdin.readline()) def solve(p,q,monsters,diana): if len(monsters)==0 : return 0 hp,gold=monsters[0] shoots=hp//q+(1 if hp % q!=0 else 0) best=solve(p,q,monsters[1 :],diana+shoots) while hp-q>0 : diana+=1 hp-=q shoots=hp//p+(1 if hp % p!=0 else 0) if shoots<=diana : value=gold+solve(p,q,monsters[1 :],diana-shoots) best=max(best,value) return best for test_case in range(1,t+1): p,q,n=map(int,sys.stdin.readline().strip().split()) monsters=[] for i in range(n): h,g=map(int,sys.stdin.readline().strip().split()) monsters.append((h,g)) print("Case #{0}:{1}".format(test_case,solve(p,q,monsters,1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; for test_case : Integer.subrange(1, t + 1-1) do ( var n : OclAny := null; Sequence{p,q,n} := (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; monsters := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var h : OclAny := null; var g : OclAny := null; Sequence{h,g} := (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{h, g}) : monsters)) ; execute (StringLib.interpolateStrings("Case #{0}:{1}", Sequence{test_case, solve(p, q, monsters, 1)}))->display()); operation solve(p : OclAny, q : OclAny, monsters : OclAny, diana : OclAny) : OclAny pre: true post: true activity: if (monsters)->size() = 0 then ( return 0 ) else skip ; var hp : OclAny := null; var gold : OclAny := null; Sequence{hp,gold} := monsters->first() ; var shoots : int := hp div q + (if hp mod q /= 0 then 1 else 0 endif) ; var best : OclAny := solve(p, q, monsters->tail(), diana + shoots) ; while hp - q > 0 do ( diana := diana + 1 ; hp := hp - q) ; shoots := hp div p + (if hp mod p /= 0 then 1 else 0 endif) ; if (shoots->compareTo(diana)) <= 0 then ( var value : OclAny := gold + solve(p, q, monsters->tail(), diana - shoots) ; best := Set{best, value}->max() ) else skip ; return best; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countkDist(str1,k): n=len(str1) res=0 cnt=[0]*27 for i in range(0,n): dist_count=0 cnt=[0]*27 for j in range(i,n): if(cnt[ord(str1[j])-97]==0): dist_count+=1 cnt[ord(str1[j])-97]+=1 if(dist_count==k): res+=1 if(dist_count>k): break return res if __name__=="__main__" : str1="abcbaa" k=3 print("Total substrings with exactly",k,"distinct characters : ",end="") print(countkDist(str1,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( str1 := "abcbaa" ; k := 3 ; execute ("Total substrings with exactly")->display() ; execute (countkDist(str1, k))->display() ) else skip; operation countkDist(str1 : OclAny, k : OclAny) : OclAny pre: true post: true activity: var n : int := (str1)->size() ; var res : int := 0 ; var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 27) ; for i : Integer.subrange(0, n-1) do ( var dist_count : int := 0 ; cnt := MatrixLib.elementwiseMult(Sequence{ 0 }, 27) ; for j : Integer.subrange(i, n-1) do ( if (cnt[(str1[j+1])->char2byte() - 97+1] = 0) then ( dist_count := dist_count + 1 ) else skip ; cnt[(str1[j+1])->char2byte() - 97+1] := cnt[(str1[j+1])->char2byte() - 97+1] + 1 ; if (dist_count = k) then ( res := res + 1 ) else skip ; if ((dist_count->compareTo(k)) > 0) then ( break ) else skip)) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkRedundancy(Str): st=[] for ch in Str : if(ch==')'): top=st[-1] st.pop() flag=True while(top!='('): if(top=='+' or top=='-' or top=='*' or top=='/'): flag=False top=st[-1] st.pop() if(flag==True): return True else : st.append(ch) return False def findRedundant(Str): ans=checkRedundancy(Str) if(ans==True): print("Yes") else : print("No") if __name__=='__main__' : Str="((a+b))" findRedundant(Str) Str="(a+(b)/c)" findRedundant(Str) Str="(a+b*(c-d))" findRedundant(Str) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( Str := "((a+b))" ; findRedundant(Str) ; Str := "(a+(b)/c)" ; findRedundant(Str) ; Str := "(a+b*(c-d))" ; findRedundant(Str) ) else skip; operation checkRedundancy(Str : OclAny) : OclAny pre: true post: true activity: var st : Sequence := Sequence{} ; for ch : Str do ( if (ch = ')') then ( var top : OclAny := st->last() ; st := st->front() ; var flag : boolean := true ; while (top /= '(') do ( if (top = '+' or top = '-' or top = '*' or top = '/') then ( flag := false ) else skip ; top := st->last() ; st := st->front()) ; if (flag = true) then ( return true ) else skip ) else ( execute ((ch) : st) )) ; return false; operation findRedundant(Str : OclAny) pre: true post: true activity: var ans : OclAny := checkRedundancy(Str) ; if (ans = true) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binarySearch(searchSpace,s,e,num): while(s<=e): mid=(s+e)//2 if searchSpace[mid]>=num : ans=mid e=mid-1 else : s=mid+1 return ans def longestSubArr(arr,n): searchSpace=[None]*n index=[None]*n j=0 ans=0 for i in range(n): if(j==0 or searchSpace[j-1]union(Sequence{-1}->union(Sequence{7}->union(Sequence{5}->union(Sequence{1}->union(Sequence{ -2 }))))) ; n := (arr)->size() ; execute (longestSubArr(arr, n))->display() ) else skip; operation binarySearch(searchSpace : OclAny, s : OclAny, e : OclAny, num : OclAny) : OclAny pre: true post: true activity: while ((s->compareTo(e)) <= 0) do ( var mid : int := (s + e) div 2 ; if (searchSpace[mid+1]->compareTo(num)) >= 0 then ( var ans : int := mid ; e := mid - 1 ) else ( s := mid + 1 )) ; return ans; operation longestSubArr(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: searchSpace := MatrixLib.elementwiseMult(Sequence{ null }, n) ; var index : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; var j : int := 0 ; ans := 0 ; for i : Integer.subrange(0, n-1) do ( if (j = 0 or (searchSpace[j - 1+1]->compareTo(arr[i+1])) < 0) then ( searchSpace[j+1] := arr[i+1] ; index[j+1] := i ; j := j + 1 ) else skip ; var idx : OclAny := binarySearch(searchSpace, 0, j - 1, arr[i+1]) ; ans := Set{ans, i - index[idx+1] + 1}->max()) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from queue import Queue def input_split(line): group,members=line.rstrip('.').split(':') members=members.split(',') return group,members while True : n=int(input()) if n==0 : exit() data=[input()for _ in range(n)] to={} rev={} sz=0 for line in data : group,members=input_split(line) if group not in to : to[group]=sz rev[sz]=group sz+=1 for m in members : if m not in to : to[m]=sz rev[sz]=m sz+=1 g=[[]for _ in range(sz)] indeg=[0]*sz for line in data : group,members=input_split(line) for m in members : g[to[m]].append(to[group]) indeg[to[group]]+=1 dp=[set()for i in range(sz)] q=Queue() for i in range(sz): if indeg[i]==0 : dp[i]|={i} q.put(i) while not q.empty(): cur=q.get() for nxt in g[cur]: dp[nxt]|=dp[cur] indeg[nxt]-=1 if indeg[nxt]==0 : q.put(nxt) print(len(dp[0])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( exit() ) else skip ; var data : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var to : OclAny := Set{} ; var rev : OclAny := Set{} ; var sz : int := 0 ; for line : data do ( var group : OclAny := null; Sequence{group,members} := input_split(line) ; if (to)->excludes(group) then ( to[group+1] := sz ; rev[sz+1] := group ; sz := sz + 1 ) else skip ; for m : members do ( if (to)->excludes(m) then ( to[m+1] := sz ; rev[sz+1] := m ; sz := sz + 1 ) else skip)) ; var g : Sequence := Integer.subrange(0, sz-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var indeg : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, sz) ; for line : data do ( var group : OclAny := null; Sequence{group,members} := input_split(line) ; for m : members do ((expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name to)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name m)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name to)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name group)))))))) ])))))))) )))) ; indeg[to[group+1]+1] := indeg[to[group+1]+1] + 1)) ; var dp : Sequence := Integer.subrange(0, sz-1)->select(i | true)->collect(i | (Set{}->union(()))) ; var q : OclAny := Queue() ; for i : Integer.subrange(0, sz-1) do ( if indeg[i+1] = 0 then ( dp[i+1] := dp[i+1] or Set{ i } ; q.put(i) ) else skip) ; while not(q.empty()) do ( var cur : OclAny := q.get() ; for nxt : g[cur+1] do ( dp[nxt+1] := dp[nxt+1] or dp[cur+1] ; indeg[nxt+1] := indeg[nxt+1] - 1 ; if indeg[nxt+1] = 0 then ( q.put(nxt) ) else skip)) ; execute ((dp->first())->size())->display()); operation input_split(line : OclAny) : OclAny pre: true post: true activity: var group : OclAny := null; var members : OclAny := null; Sequence{group,members} := line.rstrip('.').split(':') ; var members : OclAny := members.split(',') ; return group, members; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solveEven(s): if len(s)% 2==1 : return 2 ls=s[0 : len(s)//2] rs=s[len(s)//2 : len(s)] if ls!=rs : return 1 return solveEven(ls) def solveOdd(s): return 2 def solve(s): if len(s)<=3 : return-1 cnt=[0]*25 for i in range(0,len(s)): cnt[ord(s[i])-ord('a')]+=1 if max(cnt)>=len(s)-1 : return-1 if len(s)% 2==0 : return solveEven(s) if len(s)% 2==1 : return solveOdd(s) if __name__=="__main__" : s="nolon" print(solve(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( s := "nolon" ; execute (solve(s))->display() ) else skip; operation solveEven(s : OclAny) : OclAny pre: true post: true activity: if (s)->size() mod 2 = 1 then ( return 2 ) else skip ; var ls : OclAny := s.subrange(0+1, (s)->size() div 2) ; var rs : OclAny := s.subrange((s)->size() div 2+1, (s)->size()) ; if ls /= rs then ( return 1 ) else skip ; return solveEven(ls); operation solveOdd(s : OclAny) : OclAny pre: true post: true activity: return 2; operation solve(s : OclAny) : OclAny pre: true post: true activity: if (s)->size() <= 3 then ( return -1 ) else skip ; var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 25) ; for i : Integer.subrange(0, (s)->size()-1) do ( cnt[(s[i+1])->char2byte() - ('a')->char2byte()+1] := cnt[(s[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; if ((cnt)->max()->compareTo((s)->size() - 1)) >= 0 then ( return -1 ) else skip ; if (s)->size() mod 2 = 0 then ( return solveEven(s) ) else skip ; if (s)->size() mod 2 = 1 then ( return solveOdd(s) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find_set(n): if(n<=2): print("-1"); return ; sum1=(n*(n-1))/2 ; sum2=n ; print(sum1," ",sum2); n=8 ; find_set(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 8; ; find_set(n);; operation find_set(n : OclAny) : OclAny pre: true post: true activity: if (n <= 2) then ( execute ("-1")->display(); ; return; ) else skip ; var sum1 : double := (n * (n - 1)) / 2; ; var sum2 : OclAny := n; ; execute (sum1)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin from math import sqrt def main(): n=int(stdin.readline()) a=list(map(int,stdin.readline().split())) ans=[[a[0],],] for i in range(1,n): l=0 r=len(ans)-1 while r>l : m=(r+l)//2 if a[i]>ans[m][len(ans[m])-1]: r=m else : l=m+1 if a[i]>ans[l][len(ans[l])-1]: ans[l].append(a[i]) else : ans.append([a[i],]) for arr in ans : print(*arr) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; main(); operation main() pre: true post: true activity: var n : int := ("" + ((stdin.readLine())))->toInteger() ; var a : Sequence := ((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : Sequence := Sequence{ Sequence{ a->first() } } ; for i : Integer.subrange(1, n-1) do ( var l : int := 0 ; var r : double := (ans)->size() - 1 ; while (r->compareTo(l)) > 0 do ( var m : int := (r + l) div 2 ; if (a[i+1]->compareTo(ans[m+1][(ans[m+1])->size() - 1+1])) > 0 then ( r := m ) else ( l := m + 1 )) ; if (a[i+1]->compareTo(ans[l+1][(ans[l+1])->size() - 1+1])) > 0 then ( (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name l)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))) ) else ( execute ((Sequence{ a[i+1] }) : ans) )) ; for arr : ans do ( execute ((argument * (test (logical_test (comparison (expr (atom (name arr))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def replaceRemove(s,X,Y,Z): s=list(s); start=0 ; end=len(s)-1 ; while(start<=end): if(s[start]==Z): while(end>=0 and s[end]==Z): end-=1 ; if(end>start): s[start],s[end]=s[end],s[start] if(s[start]==X): s[start]=Y ; start+=1 else : if(s[start]==X): s[start]=Y ; start+=1 ; while(len(s)>0 and s[len(s)-1]==Z): s.pop(); return "".join(s) if __name__=="__main__" : string="batman" ; X='a' ; Y='d' ; Z='b' ; string=replaceRemove(string,X,Y,Z); if(len(string)==0): print(-1); else : print(string); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var string : String := "batman"; ; X := 'a'; Y := 'd'; Z := 'b'; ; string := replaceRemove(string, X, Y, Z); ; if ((string)->size() = 0) then ( execute (-1)->display(); ) else ( execute (string)->display(); ) ) else skip; operation replaceRemove(s : OclAny, X : OclAny, Y : OclAny, Z : OclAny) : OclAny pre: true post: true activity: s := (s); ; var start : int := 0; ; var end : double := (s)->size() - 1; ; while ((start->compareTo(end)) <= 0) do ( if (s[start+1] = Z) then ( while (end >= 0 & s[end+1] = Z) do ( end := end - 1;) ; if ((end->compareTo(start)) > 0) then ( var s[start+1] : OclAny := null; var s[end+1] : OclAny := null; Sequence{s[start+1],s[end+1]} := Sequence{s[end+1],s[start+1]} ; if (s[start+1] = X) then ( s[start+1] := Y; ) else skip ; start := start + 1 ) else skip ) else ( if (s[start+1] = X) then ( s[start+1] := Y; ) else skip ; start := start + 1; )) ; while ((s)->size() > 0 & s[(s)->size() - 1+1] = Z) do ( s := s->front();) ; return StringLib.sumStringsWithSeparator((s), ""); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(n,k,a,b): a.sort() b.sort() fl=False ind=-1 for i in range(n): if(a[i]!=b[i]): if(fl==True): return False fl=True ind=i if(ind==-1 or abs(a[ind]-b[ind])<=k): return True return False n,k=2,4 a=[1,5] b=[1,1] if(check(n,k,a,b)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{n,k} := Sequence{2,4} ; a := Sequence{1}->union(Sequence{ 5 }) ; b := Sequence{1}->union(Sequence{ 1 }) ; if (check(n, k, a, b)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation check(n : OclAny, k : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: a := a->sort() ; b := b->sort() ; var fl : boolean := false ; var ind : int := -1 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] /= b[i+1]) then ( if (fl = true) then ( return false ) else skip ; fl := true ; ind := i ) else skip) ; if (ind = -1 or ((a[ind+1] - b[ind+1])->abs()->compareTo(k)) <= 0) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMaxNum(arr,n): arr.sort(reverse=True) num=arr[0] for i in range(1,n): num=num*10+arr[i] return num if __name__=="__main__" : arr=[1,2,3,4,5,0] n=len(arr) print(findMaxNum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 0 }))))) ; n := (arr)->size() ; execute (findMaxNum(arr, n))->display() ) else skip; operation findMaxNum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var num : OclAny := arr->first() ; for i : Integer.subrange(1, n-1) do ( num := num * 10 + arr[i+1]) ; return num; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while(1): N,M=map(int,input().split()) if N==0 and M==0 : break H=[int(input())for i in range(N)] HD=[0]*1500**2 for i in range(N): tmp=0 for j in range(i,N): tmp+=H[j] HD[tmp]+=1 ans=0 W=[int(input())for i in range(M)] for i in range(M): tmp=0 for j in range(i,M): tmp+=W[j] ans+=HD[tmp] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while (1) do ( var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if N = 0 & M = 0 then ( break ) else skip ; var H : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var HD : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (1500)->pow(2)) ; for i : Integer.subrange(0, N-1) do ( var tmp : int := 0 ; for j : Integer.subrange(i, N-1) do ( tmp := tmp + H[j+1] ; HD[tmp+1] := HD[tmp+1] + 1)) ; var ans : int := 0 ; var W : Sequence := Integer.subrange(0, M-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; for i : Integer.subrange(0, M-1) do ( tmp := 0 ; for j : Integer.subrange(i, M-1) do ( tmp := tmp + W[j+1] ; ans := ans + HD[tmp+1])) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools as it def horizontal_input(T=str): return list(map(T,input().split())) def vertical_input(n,T=str,sep=False,septype=tuple): data=[] if sep : for i in range(n): data.append(septype(map(T,input().split()))) else : for i in range(n): data.append(T(input())) return data while 1 : n,m=horizontal_input(int) if n==0 and m==0 : break h=[0]+list(it.accumulate(vertical_input(n,int))) w=[0]+list(it.accumulate(vertical_input(m,int))) _h={} for i in range(n+1): for j in range(i+1,n+1): if h[j]-h[i]in _h : _h[h[j]-h[i]]+=1 else : _h[h[j]-h[i]]=1 _w={} for i in range(m+1): for j in range(i+1,m+1): if w[j]-w[i]in _w : _w[w[j]-w[i]]+=1 else : _w[w[j]-w[i]]=1 ans=0 for k in _h.keys(): ans+=_h[k]*(_w[k]if k in _w else 0) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; while 1 do ( var m : OclAny := null; Sequence{n,m} := horizontal_input(OclType["int"]) ; if n = 0 & m = 0 then ( break ) else skip ; var h : Sequence := Sequence{ 0 }->union((it.accumulate(vertical_input(n, OclType["int"])))) ; var w : Sequence := Sequence{ 0 }->union((it.accumulate(vertical_input(m, OclType["int"])))) ; var _h : OclAny := Set{} ; for i : Integer.subrange(0, n + 1-1) do ( for j : Integer.subrange(i + 1, n + 1-1) do ( if (_h)->includes(h[j+1] - h[i+1]) then ( _h[h[j+1] - h[i+1]+1] := _h[h[j+1] - h[i+1]+1] + 1 ) else ( _h[h[j+1] - h[i+1]+1] := 1 ))) ; var _w : OclAny := Set{} ; for i : Integer.subrange(0, m + 1-1) do ( for j : Integer.subrange(i + 1, m + 1-1) do ( if (_w)->includes(w[j+1] - w[i+1]) then ( _w[w[j+1] - w[i+1]+1] := _w[w[j+1] - w[i+1]+1] + 1 ) else ( _w[w[j+1] - w[i+1]+1] := 1 ))) ; var ans : int := 0 ; for k : _h.keys() do ( ans := ans + _h[k+1] * (if (_w)->includes(k) then _w[k+1] else 0 endif)) ; execute (ans)->display()); operation horizontal_input(T : OclAny) : OclAny pre: true post: true activity: if T->oclIsUndefined() then T := OclType["String"] else skip; return ((input().split())->collect( _x | (T)->apply(_x) )); operation vertical_input(n : OclAny, T : OclAny, sep : OclAny, septype : OclAny) : OclAny pre: true post: true activity: if T->oclIsUndefined() then T := OclType["String"] else skip; if sep->oclIsUndefined() then sep := false else skip; if septype->oclIsUndefined() then septype := tuple else skip; var data : Sequence := Sequence{} ; if sep then ( for i : Integer.subrange(0, n-1) do ( execute ((septype((input().split())->collect( _x | (T)->apply(_x) ))) : data)) ) else ( for i : Integer.subrange(0, n-1) do ( execute ((T((OclFile["System.in"]).readLine())) : data)) ) ; return data; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=10**9+7 INF=10**10 import sys sys.setrecursionlimit(100000000) dy=(-1,0,1,0) dx=(0,1,0,-1) def solve(n,m): H=[int(input())for _ in range(n)] W=[int(input())for _ in range(m)] H_length=[0]*1500000 W_length=[0]*1500000 for i in range(n): height=0 for j in range(i,n): height+=H[j] H_length[height]+=1 for i in range(m): width=0 for j in range(i,m): width+=W[j] W_length[width]+=1 ans=sum(h*w for h,w in zip(H_length,W_length)) print(ans) def main(): while True : n,m=map(int,input().split()) if n==0 : return solve(n,m) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : double := (10)->pow(9) + 7 ; var INF : double := (10)->pow(10) ; skip ; sys.setrecursionlimit(100000000) ; var dy : OclAny := Sequence{-1, 0, 1, 0} ; var dx : OclAny := Sequence{0, 1, 0, -1} ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(n : OclAny, m : OclAny) pre: true post: true activity: var H : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var W : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var H_length : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 1500000) ; var W_length : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 1500000) ; for i : Integer.subrange(0, n-1) do ( var height : int := 0 ; for j : Integer.subrange(i, n-1) do ( height := height + H[j+1] ; H_length[height+1] := H_length[height+1] + 1)) ; for i : Integer.subrange(0, m-1) do ( var width : int := 0 ; for j : Integer.subrange(i, m-1) do ( width := width + W[j+1] ; W_length[width+1] := W_length[width+1] + 1)) ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name h))) * (expr (atom (name w))))))) (comp_for for (exprlist (expr (atom (name h))) , (expr (atom (name w)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name H_length))))))) , (argument (test (logical_test (comparison (expr (atom (name W_length)))))))) )))))))))->sum() ; execute (ans)->display(); operation main() pre: true post: true activity: while true do ( Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( return ) else skip ; solve(n, m)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import combinations from collections import Counter while True : N,M=map(int,input().split()) if N==M==0 : break L=[0] C=[0] x=0 y=0 count=0 for i in range(N): l=int(input()) x+=l L.append(x) dL=Counter([max(x1,x2)-min(x1,x2)for(x1,x2)in combinations(L,2)]) for i in range(M): c=int(input()) y+=c C.append(y) for y1,y2 in combinations(C,2): dy=max(y1,y2)-min(y1,y2) if dy in dL : count+=dL[dy] print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if N = M & (M == 0) then ( break ) else skip ; var L : Sequence := Sequence{ 0 } ; var C : Sequence := Sequence{ 0 } ; var x : int := 0 ; var y : int := 0 ; var count : int := 0 ; for i : Integer.subrange(0, N-1) do ( var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; x := x + l ; execute ((x) : L)) ; var dL : OclAny := Counter(combinations(L, 2)->select(Sequence{x1, x2} | true)->collect(Sequence{x1, x2} | (Set{x1, x2}->max() - Set{x1, x2}->min()))) ; for i : Integer.subrange(0, M-1) do ( var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; y := y + c ; execute ((y) : C)) ; for _tuple : combinations(C, 2) do (var _indx : int := 1; var y1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y2 : OclAny := _tuple->at(_indx); var dy : double := Set{y1, y2}->max() - Set{y1, y2}->min() ; if (dL)->includes(dy) then ( count := count + dL[dy+1] ) else skip) ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while(True): tmp=list(map(int,input().split())) n,m=tmp[0],tmp[1] ans=0 if n==0 : quit() hs,ws=[0],[0] for i in range(n): hs.append(hs[-1]+int(input())) for i in range(m): ws.append(ws[-1]+int(input())) h_dif,w_dif=[0]*(hs[-1]+1),[0]*(ws[-1]+1) for i in range(n): for j in range(i+1,n+1): h_dif[hs[j]-hs[i]]+=1 for i in range(m): for j in range(i+1,m+1): w_dif[ws[j]-ws[i]]+=1 for i in range(1,min(len(h_dif),len(w_dif))): ans+=h_dif[i]*w_dif[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while (true) do ( var tmp : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{tmp->first(),tmp[1+1]} ; var ans : int := 0 ; if n = 0 then ( quit() ) else skip ; var hs : OclAny := null; var ws : OclAny := null; Sequence{hs,ws} := Sequence{Sequence{ 0 },Sequence{ 0 }} ; for i : Integer.subrange(0, n-1) do ( execute ((hs->last() + ("" + (((OclFile["System.in"]).readLine())))->toInteger()) : hs)) ; for i : Integer.subrange(0, m-1) do ( execute ((ws->last() + ("" + (((OclFile["System.in"]).readLine())))->toInteger()) : ws)) ; var h_dif : OclAny := null; var w_dif : OclAny := null; Sequence{h_dif,w_dif} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, (hs->last() + 1)),MatrixLib.elementwiseMult(Sequence{ 0 }, (ws->last() + 1))} ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n + 1-1) do ( h_dif[hs[j+1] - hs[i+1]+1] := h_dif[hs[j+1] - hs[i+1]+1] + 1)) ; for i : Integer.subrange(0, m-1) do ( for j : Integer.subrange(i + 1, m + 1-1) do ( w_dif[ws[j+1] - ws[i+1]+1] := w_dif[ws[j+1] - ws[i+1]+1] + 1)) ; for i : Integer.subrange(1, Set{(h_dif)->size(), (w_dif)->size()}->min()-1) do ( ans := ans + h_dif[i+1] * w_dif[i+1]) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import re from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(1000000) from heapq import heappush,heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod=10**9+7 inf=float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) while 1 : n=I() if n==0 : quit() f=defaultdict(dict) t=defaultdict(lambda : False) ch=defaultdict(lambda : False) stack=[] for i in range(n): x=input()[:-1].split(':') y=x[1].split(',') x=x[0] for j in y : f[x][j]=1 if i!=0 : continue stack.append(j) ans=0 while stack : x=stack.pop() if ch[x]: continue ch[x]=True if len(f[x])==0 and not t[x]: ans+=1 t[x]=True continue for i,j in f[x].items(): stack.append(i) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1000000) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; skip ; skip ; while 1 do ( var n : OclAny := I() ; if n = 0 then ( quit() ) else skip ; var f : OclAny := defaultdict(OclType["Map"]) ; var t : OclAny := defaultdict(lambda $$ : OclAny in (false)) ; var ch : OclAny := defaultdict(lambda $$ : OclAny in (false)) ; var stack : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := input()->front().split(':') ; var y : OclAny := x[1+1].split(',') ; x := x->first() ; for j : y do ( f[x+1][j+1] := 1 ; if i /= 0 then ( continue ) else skip ; execute ((j) : stack))) ; var ans : int := 0 ; while stack do ( x := stack->last() ; stack := stack->front() ; if ch[x+1] then ( continue ) else skip ; ch[x+1] := true ; if (f[x+1])->size() = 0 & not(t[x+1]) then ( ans := ans + 1 ; t[x+1] := true ; continue ) else skip ; for _tuple : f[x+1]->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); execute ((i) : stack))) ; execute (ans)->display()); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): input() l=list(input()) s=set('trygub') print(''.join(l)if not s.issubset(l)else ''.join(sorted(l))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( input() ; var l : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var s : Set := Set{}->union(('trygub')) ; execute (if not(s <: (l)) then StringLib.sumStringsWithSeparator((l), '') else StringLib.sumStringsWithSeparator((l->sort()), '') endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().strip().split())) res=[[arr[0]],] start=[arr[0]] done=False for i in range(1,n): t=arr[i] if(start[len(start)-1])>t : res.append([t]) start.append(t) else : l,r=0,len(start)-1 while r-l>1 : mm=l+int((r-l)/2) if start[mm]toInteger() ; var arr : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : Sequence := Sequence{ Sequence{ arr->first() } } ; var start : Sequence := Sequence{ arr->first() } ; var done : boolean := false ; for i : Integer.subrange(1, n-1) do ( var t : OclAny := arr[i+1] ; if ((start[(start)->size() - 1+1])->compareTo(t)) > 0 then ( execute ((Sequence{ t }) : res) ; execute ((t) : start) ) else ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,(start)->size() - 1} ; while r - l > 1 do ( var mm : OclAny := l + ("" + (((r - l) / 2)))->toInteger() ; if (start[mm+1]->compareTo(t)) < 0 then ( var r : OclAny := mm ) else ( var l : OclAny := mm )) ; if (start[l+1]->compareTo(t)) < 0 then ( (expr (atom (name res)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name l)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) )))) ; start[l+1] := t ) else ( (expr (atom (name res)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) )))) ; start[r+1] := t ) )) ; for ls : res do ( for i : ls do ( execute (i)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for g in range(t): n=int(input()) s=list(input()) s.sort() print(*s,sep="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for g : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; s := s->sort() ; execute ((argument * (test (logical_test (comparison (expr (atom (name s))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,a=int(input()),input() bs=a.count("b") res="b"*bs+a.replace("b","") print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),(OclFile["System.in"]).readLine()} ; var bs : int := a->count("b") ; var res : String := StringLib.nCopies("b", bs) + a.replace("b", "") ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : t-=1 n=int(input()) s=input() ss=[] for i in s : ss.append(i) ss.sort() for i in ss[:-1]: print(i,end='') print(ss[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( t := t - 1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var ss : Sequence := Sequence{} ; for i : s->characters() do ( execute ((i) : ss)) ; ss := ss->sort() ; for i : ss->front() do ( execute (i)->display()) ; execute (ss->last())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) s=input() c=s.count('t') s=s.replace('t','') s+='t'*c print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var c : int := s->count('t') ; s := s.replace('t', '') ; s := s + StringLib.nCopies('t', c) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (n,s)=map(int,input().split(' ')) type_of_sugar=[] for i in range(n): (x,y)=map(int,input().split(' ')) type_of_sugar.append([x,y]) candies=[] for i in range(n): if type_of_sugar[i][0]0 : print(max(candies)) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{n, s} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var type_of_sugar : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( ; var Sequence{x, y} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{x}->union(Sequence{ y })) : type_of_sugar)) ; var candies : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if (type_of_sugar[i+1]->first()->compareTo(s)) < 0 then ( execute ((100 - type_of_sugar[i+1][1+1]) : candies) ) else (if type_of_sugar[i+1]->first() = s & type_of_sugar[i+1][1+1] = 0 then ( execute ((0) : candies) ) else skip)) ; for j : Integer.subrange(0, (candies)->size()-1) do ( if candies[j+1] = 100 then ( candies[j+1] := 0 ) else skip) ; if (candies)->size() > 0 then ( execute ((candies)->max())->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def main_function(): n,s=[int(i)for i in input().split(" ")] is_found=False max_val=0 for i in range(n): x,y=[int(j)for j in input().split(" ")] if x==s and y==0 : is_found=True elif x0 and max_val<100-y : max_val=100-y if is_found : print(max_val) else : print(-1) main_function() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main_function(); operation main_function() pre: true post: true activity: var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var is_found : boolean := false ; var max_val : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := input().split(" ")->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; if x = s & y = 0 then ( is_found := true ) else (if (x->compareTo(s)) < 0 then ( is_found := true ; if y > 0 & (max_val->compareTo(100 - y)) < 0 then ( max_val := 100 - y ) else skip ) else skip)) ; if is_found then ( execute (max_val)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,s=map(int,input().split()) mx=c=f=0 for _ in range(n): x,y=map(int,input().split()) if x0 : c=100-y % 100 else : c=0 if c>mx : mx=c if f==0 : print(-1) else : print(mx) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; mx := mx(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name f)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (x->compareTo(s)) < 0 then ( var f : int := 1 ) else (if x = s & y = 0 then ( f := 1 ) else skip) ; if (x->compareTo(s)) < 0 then ( if y > 0 then ( var c : double := 100 - y mod 100 ) else ( c := 0 ) ; if (c->compareTo(mx)) > 0 then ( var mx : OclAny := c ) else skip ) else skip) ; if f = 0 then ( execute (-1)->display() ) else ( execute (mx)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,s=map(int,input().split()) c=-1 d=0 for i in range(n): x,y=map(int,input().split()) if x+(y>0)<=s : c=max(c,100-y if y!=0 else 0) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : int := -1 ; var d : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (x + (y > 0)->compareTo(s)) <= 0 then ( c := Set{c, if y /= 0 then 100 - y else 0 endif}->max() ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,s=map(int,input().split()) lst=[] for i in range(n): d,c=map(int,input().split()) if dcollect( _x | (OclType["int"])->apply(_x) ) ; var lst : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var d : OclAny := null; var c : OclAny := null; Sequence{d,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (d->compareTo(s)) < 0 or (d = s & c = 0) then ( execute (((100 - c) mod 100) : lst) ) else skip) ; if lst then ( execute ((lst)->max())->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : N=int(input()) if N==0 : break first_group_menbers=set(input()[:-1].split(":")[1].split(",")) d={} for i in range(N-1): group,members=input()[:-1].split(":") d[group]=set(members.split(",")) for i in range(N-1): for group,members in d.items(): if group in first_group_menbers : first_group_menbers.remove(group) for m in members : first_group_menbers.add(m) print(len(first_group_menbers)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var first_group_menbers : Set := Set{}->union((input()->front().split(":")[1+1].split(","))) ; var d : OclAny := Set{} ; for i : Integer.subrange(0, N - 1-1) do ( var group : OclAny := null; var members : OclAny := null; Sequence{group,members} := input()->front().split(":") ; d[group+1] := Set{}->union((members.split(",")))) ; for i : Integer.subrange(0, N - 1-1) do ( for _tuple : d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var group : OclAny := _tuple->at(_indx); _indx := _indx + 1; var members : OclAny := _tuple->at(_indx); if (first_group_menbers)->includes(group) then ( execute ((group) /: first_group_menbers) ; for m : members do ( execute ((m) : first_group_menbers)) ) else skip)) ; execute ((first_group_menbers)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def circlearea(a,b): if(a<0 or b<0): return-1 A=((3.14*pow(a,2)*pow(b,2))/(4*(pow(a,2)+pow(b,2)))) return A if __name__=="__main__" : a=8 b=10 print(circlearea(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := 8 ; b := 10 ; execute (circlearea(a, b))->display() ) else skip; operation circlearea(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a < 0 or b < 0) then ( return -1 ) else skip ; var A : double := ((3.14 * (a)->pow(2) * (b)->pow(2)) / (4 * ((a)->pow(2) + (b)->pow(2)))) ; return A; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- roads=int(input()) h=[] v=[] day=[] for i in range(1,roads**2+1): a,b=list(input().split(" ")) if((a not in h)and(b not in v)): h.append(a) v.append(b) day.append(i) day=[int(i)for i in day] for i in day : print(i,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var roads : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var h : Sequence := Sequence{} ; var v : Sequence := Sequence{} ; var day : Sequence := Sequence{} ; for i : Integer.subrange(1, (roads)->pow(2) + 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split(" ")) ; if (((h)->excludes(a)) & ((v)->excludes(b))) then ( execute ((a) : h) ; execute ((b) : v) ; execute ((i) : day) ) else skip) ; day := day->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; for i : day do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) a,b,d=[],[],[] for i in range(n**2): h,v=input()[:-1].split() if h not in a and v not in b : d.append(i+1) a.append(h) b.append(v) print(' '.join(map(str,d))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := null; var b : OclAny := null; var d : OclAny := null; Sequence{a,b,d} := Sequence{Sequence{},Sequence{},Sequence{}} ; for i : Integer.subrange(0, (n)->pow(2)-1) do ( var h : OclAny := null; var v : OclAny := null; Sequence{h,v} := input()->front().split() ; if (a)->excludes(h) & (b)->excludes(v) then ( execute ((i + 1) : d) ; execute ((h) : a) ; execute ((v) : b) ) else skip) ; execute (StringLib.sumStringsWithSeparator(((d)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) n=int(input()) r=[0]*(n+1) c=[0]*(n+1) for i in range(n*n): a,b=map(int,input().split()) if r[a]==0 and c[b]==0 : print(i+1) r[a]=c[b]=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var c : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(0, n * n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if r[a+1] = 0 & c[b+1] = 0 then ( execute (i + 1)->display() ; r[a+1] := 1; var c[b+1] : int := 1 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=[] seen=set() seen1=set() ans=[] for i in range(n**2): a,b=map(int,input().split()) if a not in seen and b not in seen1 : ans.append(i+1) seen.add(a) seen1.add(b) print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Sequence{} ; var seen : Set := Set{}->union(()) ; var seen1 : Set := Set{}->union(()) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, (n)->pow(2)-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (seen)->excludes(a) & (seen1)->excludes(b) then ( execute ((i + 1) : ans) ; execute ((a) : seen) ; execute ((b) : seen1) ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) hzt=list(0 for x in range(n)) lzt=list(0 for x in range(n)) hgj=list(0 for x in range(n*n)) lgj=list(0 for x in range(n*n)) out="" for i in range(n*n): inp=input().split() hgj[i]=int(inp[0])-1 lgj[i]=int(inp[1])-1 for i in range(n*n): if hzt[hgj[i]]==0 and lzt[lgj[i]]==0 : hzt[hgj[i]]=lzt[lgj[i]]=1 out+=f"{i+1}" print(out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var hzt : Sequence := ((argument (test (logical_test (comparison (expr (atom (number (integer 0))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))) ; var lzt : Sequence := ((argument (test (logical_test (comparison (expr (atom (number (integer 0))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))) ; var hgj : Sequence := ((argument (test (logical_test (comparison (expr (atom (number (integer 0))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) * (expr (atom (name n))))))))) ))))))))) ; var lgj : Sequence := ((argument (test (logical_test (comparison (expr (atom (number (integer 0))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) * (expr (atom (name n))))))))) ))))))))) ; var out : String := "" ; for i : Integer.subrange(0, n * n-1) do ( var inp : OclAny := input().split() ; hgj[i+1] := ("" + ((inp->first())))->toInteger() - 1 ; lgj[i+1] := ("" + ((inp[1+1])))->toInteger() - 1) ; for i : Integer.subrange(0, n * n-1) do ( if hzt[hgj[i+1]+1] = 0 & lzt[lgj[i+1]+1] = 0 then ( hzt[hgj[i+1]+1] := 1; var lzt[lgj[i+1]+1] : int := 1 ; out := out + StringLib.formattedString("{i+1}") ) else skip) ; execute (out)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=int(input()) for _ in range(m): s=int(input()) y=int(input()) n=int(input()) a=0 for _d in range(n): t,p,b=map(float,input().split()) tem=0 ts=s if t : for _y in range(y): ts+=int(ts*p) ts-=b a=max(a,ts) else : tp=0 for _y in range(y): tp+=int(ts*p) ts-=b a=max(a,ts+tp) print(int(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, m-1) do ( var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var y : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := 0 ; for _d : Integer.subrange(0, n-1) do ( var t : OclAny := null; var p : OclAny := null; var b : OclAny := null; Sequence{t,p,b} := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; var tem : int := 0 ; var ts : int := s ; if t then ( for _y : Integer.subrange(0, y-1) do ( ts := ts + ("" + ((ts * p)))->toInteger() ; ts := ts - b) ; a := Set{a, ts}->max() ) else ( var tp : int := 0 ; for _y : Integer.subrange(0, y-1) do ( tp := tp + ("" + ((ts * p)))->toInteger() ; ts := ts - b) ; a := Set{a, ts + tp}->max() )) ; execute (("" + ((a)))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def tanri(money,year,ritu,cost): temp=int(year*(money+cost)*ritu) temp-=(ritu*cost*year*(year-1))//2 return temp def tanri_a(m,y,r,c): temp=m ans=0 for _ in range(y): ans+=int(temp*r) temp-=c return ans+temp def hukuri(m,y,r,c): temp=(m-c/r)*((1+r)**(y-1)) return int(temp) def hukuri_a(m,y,r,c): temp=m for i in range(y): temp=temp+int(temp*r)-c return int(temp) def main(init_money): year=int(input()) n=int(input()) ans=0 for _ in range(n): temp=input().split() w,ritsu,cost=int(temp[0]),float(temp[1]),int(temp[2]) if w==0 : temp2=tanri_a(init_money,year,ritsu,cost) else : temp2=hukuri_a(init_money,year,ritsu,cost) ans=max(ans,temp2) print(ans) return n=int(input()) for _ in range(n): main(int(input())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( main(("" + (((OclFile["System.in"]).readLine())))->toInteger())); operation tanri(money : OclAny, year : OclAny, ritu : OclAny, cost : OclAny) : OclAny pre: true post: true activity: var temp : int := ("" + ((year * (money + cost) * ritu)))->toInteger() ; temp := temp - (ritu * cost * year * (year - 1)) div 2 ; return temp; operation tanri_a(m : OclAny, y : OclAny, r : OclAny, c : OclAny) : OclAny pre: true post: true activity: temp := m ; var ans : int := 0 ; for _anon : Integer.subrange(0, y-1) do ( ans := ans + ("" + ((temp * r)))->toInteger() ; temp := temp - c) ; return ans + temp; operation hukuri(m : OclAny, y : OclAny, r : OclAny, c : OclAny) : OclAny pre: true post: true activity: temp := (m - c / r) * (((1 + r))->pow((y - 1))) ; return ("" + ((temp)))->toInteger(); operation hukuri_a(m : OclAny, y : OclAny, r : OclAny, c : OclAny) : OclAny pre: true post: true activity: temp := m ; for i : Integer.subrange(0, y-1) do ( temp := temp + ("" + ((temp * r)))->toInteger() - c) ; return ("" + ((temp)))->toInteger(); operation main(init_money : OclAny) pre: true post: true activity: year := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; ans := 0 ; for _anon : Integer.subrange(0, n-1) do ( temp := input().split() ; var w : OclAny := null; var ritsu : OclAny := null; Sequence{w,ritsu,cost} := Sequence{("" + ((temp->first())))->toInteger(),("" + ((temp[1+1])))->toReal(),("" + ((temp[2+1])))->toInteger()} ; if w = 0 then ( var temp2 : OclAny := tanri_a(init_money, year, ritsu, cost) ) else ( temp2 := hukuri_a(init_money, year, ritsu, cost) ) ; ans := Set{ans, temp2}->max()) ; execute (ans)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- M=int(input()) def tanri(a,y,nenri,tax): w=0 for i in range(y): w+=int(a*nenri) a-=tax return a+w def fukuri(a,y,nenri,tax): for i in range(y): a+=int(a*nenri)-tax return a for i in range(M): A=int(input()) Y=int(input()) N=int(input()) max_=0 for i in range(N): t,nenri,tax=list(map(float,input().split())) max_=max(max_,tanri(A,Y,nenri,tax)if t==0 else fukuri(A,Y,nenri,tax)) print(int(max_)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var M : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; skip ; for i : Integer.subrange(0, M-1) do ( var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var Y : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var max_ : int := 0 ; for i : Integer.subrange(0, N-1) do ( var t : OclAny := null; Sequence{t,nenri,tax} := ((input().split())->collect( _x | (OclType["double"])->apply(_x) )) ; max_ := Set{max_, if t = 0 then tanri(A, Y, nenri, tax) else fukuri(A, Y, nenri, tax) endif}->max()) ; execute (("" + ((max_)))->toInteger())->display()); operation tanri(a : OclAny, y : OclAny, nenri : OclAny, tax : OclAny) : OclAny pre: true post: true activity: var w : int := 0 ; for i : Integer.subrange(0, y-1) do ( w := w + ("" + ((a * nenri)))->toInteger() ; a := a - tax) ; return a + w; operation fukuri(a : OclAny, y : OclAny, nenri : OclAny, tax : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, y-1) do ( a := a + ("" + ((a * nenri)))->toInteger() - tax) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def hukuri(y,m,p,t): for i in range(y): m+=int(m*p)-t return m def tanri(y,m,p,t): risoku=0 for i in range(y): risoku+=int(m*p) m-=t return m+risoku M=int(input()) for i in range(M): m=int(input()) y=int(input()) N=int(input()) ans=[] for j in range(N): s,p,t=input().split() if s=='0' : ans.append(tanri(y,m,float(p),int(t))) elif s=='1' : ans.append(hukuri(y,m,float(p),int(t))) print(max(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var M : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, M-1) do ( m := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; y := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; for j : Integer.subrange(0, N-1) do ( var s : OclAny := null; Sequence{s,p,t} := input().split() ; if s = '0' then ( execute ((tanri(y, m, ("" + ((p)))->toReal(), ("" + ((t)))->toInteger())) : ans) ) else (if s = '1' then ( execute ((hukuri(y, m, ("" + ((p)))->toReal(), ("" + ((t)))->toInteger())) : ans) ) else skip)) ; execute ((ans)->max())->display()); operation hukuri(y : OclAny, m : OclAny, p : OclAny, t : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, y-1) do ( m := m + ("" + ((m * p)))->toInteger() - t) ; return m; operation tanri(y : OclAny, m : OclAny, p : OclAny, t : OclAny) : OclAny pre: true post: true activity: var risoku : int := 0 ; for i : Integer.subrange(0, y-1) do ( risoku := risoku + ("" + ((m * p)))->toInteger() ; m := m - t) ; return m + risoku; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- trial=int(input()) for t in range(trial): money=int(input()) year=int(input()) cond=int(input()) answer=0 for c in range(cond): initial=money bank=[float(n)for n in input().split(" ")] if bank[0]==0 : interest=0 for y in range(year): interest+=int(initial*bank[1]) initial-=bank[2] else : if answertoInteger() ; for t : Integer.subrange(0, trial-1) do ( var money : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var year : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cond : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var answer : int := 0 ; (compound_stmt for (exprlist (expr (atom (name c)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name cond)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name initial)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name money)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name bank)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name float)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " "))))))) )))))))) ]))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name bank)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name interest)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name y)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name year)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name interest)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name initial))) * (expr (atom (name bank)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name initial)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (name bank)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name answer)))) < (comparison (expr (expr (atom (name interest))) + (expr (atom (name initial)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name answer)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name interest))) + (expr (atom (name initial))))))))) ))))))))))))))))))))) (else_clause else : (suite (stmt (compound_stmt for (exprlist (expr (atom (name y)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name year)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name initial)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name initial))) + (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name initial))) * (expr (atom (name bank)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))))) )))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name initial)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (name bank)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name answer)))) < (comparison (expr (atom (name initial))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name answer)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name initial)))))))) ))))))))))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name answer)))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- PI=3.14159265 def area_leaf(a): return(a*a*(PI/2-1)) a=7 print(area_leaf(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var PI : double := 3.14159265 ; skip ; a := 7 ; execute (area_leaf(a))->display(); operation area_leaf(a : OclAny) : OclAny pre: true post: true activity: return (a * a * (PI / 2 - 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import combinations def find(lst,n): print('YES' if[1 for r in range(1,len(lst)+1)for subset in combinations(lst,r)if sum(subset)==n]else 'NO') find([-1,2,4,121],5) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; find(Sequence{-1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 121 }))), 5); operation find(lst : OclAny, n : OclAny) pre: true post: true activity: execute (if Integer.subrange(1, (lst)->size() + 1-1)->select(r; subset : combinations(lst, r) | true)->collect(r; subset : combinations(lst, r) | (1)) then 'YES' else 'NO' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def decToBinary(n): binaryNum=[0]*n ; i=0 ; while(n>0): binaryNum[i]=n % 2 ; n=int(n/2); i+=1 ; for j in range(i-1,-1,-1): print(binaryNum[j],end=""); n=17 ; decToBinary(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 17; ; decToBinary(n);; operation decToBinary(n : OclAny) pre: true post: true activity: var binaryNum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; var i : int := 0; ; while (n > 0) do ( binaryNum[i+1] := n mod 2; ; n := ("" + ((n / 2)))->toInteger(); ; i := i + 1;) ; for j : Integer.subrange(-1 + 1, i - 1)->reverse() do ( execute (binaryNum[j+1])->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): total,red,blue=map(int,input().split()) div=red//(blue+1) rem=red %(blue+1) ans1='R'*div ans='' for i in range(blue+1): if(i!=0): ans+='B' ans+=ans1 if(rem>0): ans+='R' rem-=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var total : OclAny := null; var red : OclAny := null; var blue : OclAny := null; Sequence{total,red,blue} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var div : int := red div (blue + 1) ; var rem : int := red mod (blue + 1) ; var ans1 : String := StringLib.nCopies('R', div) ; var ans : String := '' ; for i : Integer.subrange(0, blue + 1-1) do ( if (i /= 0) then ( ans := ans + 'B' ) else skip ; ans := ans + ans1 ; if (rem > 0) then ( ans := ans + 'R' ; rem := rem - 1 ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for p in range(0,n): a,b,c=map(int,input().split()) x=c+1 y=b %(c+1) z=b//(c+1) ct=0 s="" for j in range(1,c-y+2): if j!=c+1 : s=s+z*("R")+"B" else : s=s+z*("R") z=z+1 for k in range(1,y+1): if k!=y : s=s+z*("R")+"B" else : s=s+z*("R") print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for p : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := c + 1 ; var y : int := b mod (c + 1) ; var z : int := b div (c + 1) ; var ct : int := 0 ; var s : String := "" ; for j : Integer.subrange(1, c - y + 2-1) do ( if j /= c + 1 then ( s := s + z * ("R") + "B" ) else ( s := s + z * ("R") )) ; z := z + 1 ; for k : Integer.subrange(1, y + 1-1) do ( if k /= y then ( s := s + z * ("R") + "B" ) else ( s := s + z * ("R") )) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for jj in range(int(input())): n,r,b=[int(i)for i in input().split()] t=r//(b+1) rm=r %(b+1) ans=('R'*(t+1)+'B')*rm+('R'*t+'B')*(b+1-rm) print(ans[: n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for jj : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var r : OclAny := null; var b : OclAny := null; Sequence{n,r,b} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var t : int := r div (b + 1) ; var rm : int := r mod (b + 1) ; var ans : double := (StringLib.nCopies('R', (t + 1)) + 'B') * rm + (StringLib.nCopies('R', t) + 'B') * (b + 1 - rm) ; execute (ans.subrange(1,n))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for _ in range(int(input())): n,r,b=map(int,input().split()) i=0 if b==0 : for i in range(r): print("R",end="") print() else : b+=1 ost=r % b a=math.ceil(r/b) for i in range(b-1): for i in range(a): print("R",end="") print("B",end="") ost-=1 if ost==0 : a-=1 for i in range(a): print("R",end="") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var r : OclAny := null; var b : OclAny := null; Sequence{n,r,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var i : int := 0 ; if b = 0 then ( for i : Integer.subrange(0, r-1) do ( execute ("R")->display()) ; execute (->display() ) else ( b := b + 1 ; var ost : int := r mod b ; var a : double := (r / b)->ceil() ; for i : Integer.subrange(0, b - 1-1) do ( for i : Integer.subrange(0, a-1) do ( execute ("R")->display()) ; execute ("B")->display() ; ost := ost - 1 ; if ost = 0 then ( a := a - 1 ) else skip) ; for i : Integer.subrange(0, a-1) do ( execute ("R")->display()) ; execute (->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n,r,b=map(int,input().split()) x=r %(b+1) y=r//(b+1) ca=0 cb=0 ans="" while catoInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var r : OclAny := null; var b : OclAny := null; Sequence{n,r,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : int := r mod (b + 1) ; var y : int := r div (b + 1) ; var ca : int := 0 ; var cb : int := 0 ; var ans : String := "" ; while (ca->compareTo(r)) < 0 do ( ans := ans + ("R") * y ; ca := ca + y ; if x then ( ans := ans + "R" ; ca := ca + 1 ; x := x - 1 ) else skip ; if (cb->compareTo(b)) < 0 then ( ans := ans + "B" ; cb := cb + 1 ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a,b=map(int,input().split()) count=0 while(a>0): if a % b==0 : a=a//b count=count+1 else : if a>b : count+=(a % b+1) else : count+=a % b a=a//b print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var count : int := 0 ; while (a > 0) do ( if a mod b = 0 then ( var a : int := a div b ; count := count + 1 ) else ( if (a->compareTo(b)) > 0 then ( count := count + (a mod b + 1) ) else ( count := count + a mod b ) ; a := a div b )) ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) ans=0 while n>0 : if n % k==0 : n//=k ans+=1 else : ans+=n % k n-=(n % k) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; while n > 0 do ( if n mod k = 0 then ( n := n div k ; ans := ans + 1 ) else ( ans := ans + n mod k ; n := n - (n mod k) )) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,k=map(int,input().split(' ')) ans=0 while n!=0 : ans+=1 if n % k!=0 : ans+=(n % k) n//=k print(ans-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; while n /= 0 do ( ans := ans + 1 ; if n mod k /= 0 then ( ans := ans + (n mod k) ) else skip ; n := n div k) ; execute (ans - 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,m=map(int,input().split()) z=0 while(n>0): z+=n % m n=n//m if(n!=0): z+=1 print(z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var z : int := 0 ; while (n > 0) do ( z := z + n mod m ; var n : int := n div m ; if (n /= 0) then ( z := z + 1 ) else skip) ; execute (z)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def K_String(s,k): n=len(s) fre=[0]*26 for i in range(n): fre[ord(s[i])-ord('a')]+=1 str="" for i in range(26): if(fre[i]% k==0): x=fre[i]//k while(x): str+=chr(i+ord('a')) x-=1 else : return "-1" return str if __name__=="__main__" : s="aabb" k=2 print(K_String(s,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "aabb" ; k := 2 ; execute (K_String(s, k))->display() ) else skip; operation K_String(s : OclAny, k : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; var fre : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for i : Integer.subrange(0, n-1) do ( fre[(s[i+1])->char2byte() - ('a')->char2byte()+1] := fre[(s[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; var OclType["String"] : String := "" ; for i : Integer.subrange(0, 26-1) do ( if (fre[i+1] mod k = 0) then ( var x : int := fre[i+1] div k ; while (x) do ( OclType["String"] := OclType["String"] + (i + ('a')->char2byte())->byte2char() ; x := x - 1) ) else ( return "-1" )) ; return OclType["String"]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda :[int(c)for c in input().split()] n=int(input()) def f(n,k): res=0 while n : if n % k==0 : n//=k res+=1 else : res+=n-n//k*k n=n//k*k return res for i in range(n): a,b=R() print(f(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in (input().split()->select(c | true)->collect(c | (("" + ((c)))->toInteger()))) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := R->apply() ; execute (f(a, b))->display()); operation f(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; while n do ( if n mod k = 0 then ( n := n div k ; res := res + 1 ) else ( res := res + n - n div k * k ; n := n div k * k )) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def alternate(a,b,x): x=a+b-x print("After change x is:",x) if __name__=='__main__' : a=-10 b=15 x=a print("x is:",x) alternate(a,b,x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := -10 ; b := 15 ; x := a ; execute ("x is:")->display() ; alternate(a, b, x) ) else skip; operation alternate(a : OclAny, b : OclAny, x : OclAny) pre: true post: true activity: x := a + b - x ; execute ("After change x is:")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def flipsPossible(a,n): count_odd=0 ; count_even=0 ; for i in range(n): if(a[i]& 1): count_odd+=1 ; else : count_even+=1 ; if(count_odd % 2 and count_even % 2): return False ; else : return True ; if __name__=="__main__" : a=[1,0,1,1,0,1]; n=len(a); if(flipsPossible(a,n)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 1 }))))); ; n := (a)->size(); ; if (flipsPossible(a, n)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ) else skip; operation flipsPossible(a : OclAny, n : OclAny) pre: true post: true activity: var count_odd : int := 0; var count_even : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (MathLib.bitwiseAnd(a[i+1], 1)) then ( count_odd := count_odd + 1; ) else ( count_even := count_even + 1; )) ; if (count_odd mod 2 & count_even mod 2) then ( return false; ) else ( return true; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findF_N(n): ans=0 for i in range(n): ans=ans+(i+1)*(n-i-1) return ans n=3 print(findF_N(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3 ; execute (findF_N(n))->display(); operation findF_N(n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( ans := ans + (i + 1) * (n - i - 1)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def term(n): ans=0 for i in range(1,n+1): ans=ans+i return ans n=4 print(term(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute (term(n))->display(); operation term(n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( ans := ans + i) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfSeries(n): ans=0 for i in range(1,n+1): ans=ans+i*i*i*i return ans n=4 print(sumOfSeries(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute (sumOfSeries(n))->display(); operation sumOfSeries(n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( ans := ans + i * i * i * i) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def result(n,k,t): if(t<=k): print(t) elif(t<=n): print(k) else : temp=t-n temp=k-temp print(temp) n=10 k=5 t=12 result(n,k,t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 10 ; k := 5 ; t := 12 ; result(n, k, t); operation result(n : OclAny, k : OclAny, t : OclAny) pre: true post: true activity: if ((t->compareTo(k)) <= 0) then ( execute (t)->display() ) else (if ((t->compareTo(n)) <= 0) then ( execute (k)->display() ) else ( var temp : double := t - n ; temp := k - temp ; execute (temp)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minNumber(a,n,x): a.sort(reverse=False) k=0 while(a[int((n-1)/2)]!=x): a[n-1]=x n+=1 a.sort(reverse=False) k+=1 return k if __name__=='__main__' : x=10 a=[10,20,30] n=3 print(minNumber(a,n,x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( x := 10 ; a := Sequence{10}->union(Sequence{20}->union(Sequence{ 30 })) ; n := 3 ; execute (minNumber(a, n, x))->display() ) else skip; operation minNumber(a : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: a := a->sort() ; var k : int := 0 ; while (a[("" + (((n - 1) / 2)))->toInteger()+1] /= x) do ( a[n - 1+1] := x ; n := n + 1 ; a := a->sort() ; k := k + 1) ; return k; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dfs(x,adj,vis): sz=1 vis[x]=1 for ch in adj : if(not vis[ch]): sz+=dfs(ch,adj,vis) return sz def maxValue(n,adj): val=0 vis=[0]*(n+1) for i in range(1,n+1): if(not vis[i]): val+=dfs(i,adj,vis)-1 return val if __name__=='__main__' : n=3 adj=[1,2,2,3] print(maxValue(n,adj)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( n := 3 ; adj := Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 3 }))) ; execute (maxValue(n, adj))->display() ) else skip; operation dfs(x : OclAny, adj : OclAny, vis : OclAny) : OclAny pre: true post: true activity: var sz : int := 1 ; vis[x+1] := 1 ; for ch : adj do ( if (not(vis[ch+1])) then ( sz := sz + dfs(ch, adj, vis) ) else skip) ; return sz; operation maxValue(n : OclAny, adj : OclAny) : OclAny pre: true post: true activity: var val : int := 0 ; vis := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(1, n + 1-1) do ( if (not(vis[i+1])) then ( val := val + dfs(i, adj, vis) - 1 ) else skip) ; return val; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import fractions def main(): t=int(input()) qs=[list(map(int,input().split()))for _ in range(t)] for q in qs : sub(q) def sub(q): a,b,c,d=q if d-b<0 : print("No") return if a-b<0 : print("No") return if b>c : gcd_bd=fractions.gcd(d,b) i=-10 while True : if 0=b-c : print("Yes") return i+=1 print("Yes") return if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var qs : Sequence := Integer.subrange(0, t-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for q : qs do ( sub(q)); operation sub(q : OclAny) pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := q ; if d - b < 0 then ( execute ("No")->display() ; return ) else skip ; if a - b < 0 then ( execute ("No")->display() ; return ) else skip ; if (b->compareTo(c)) > 0 then ( var gcd_bd : int := fractions.gcd(d, b) ; var i : int := -10 ; while true do ( if 0 < gcd_bd * i + (a - c) mod gcd_bd & (gcd_bd * i + (a - c) mod gcd_bd < b - c) then ( execute ("No")->display() ; return ) else (if (gcd_bd * i + (a - c) mod gcd_bd->compareTo(b - c)) >= 0 then ( execute ("Yes")->display() ; return ) else skip) ; i := i + 1) ) else skip ; execute ("Yes")->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dp=[.0]*100001 dp[1]=1. for i in range(2,100001): a,b,j=.5,1,1 while j1e-15 : dp[i]+=b*(1-a)*(j+dp[i-j-1]) b*=a ; a/=2 ; j+=1 dp[i]+=i*b while 1 : n=int(input()) if n==0 : break print(dp[n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ .0 }, 100001) ; dp[1+1] := 1. ; for i : Integer.subrange(2, 100001-1) do ( var a : OclAny := null; var b : OclAny := null; var j : OclAny := null; Sequence{a,b,j} := Sequence{.5,1,1} ; while (j->compareTo(i)) < 0 & b > ("1e-15")->toReal() do ( dp[i+1] := dp[i+1] + b * (1 - a) * (j + dp[i - j - 1+1]) ; b := b * a; a := a / 2; j := j + 1) ; dp[i+1] := dp[i+1] + i * b) ; while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; execute (dp[n+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import* _,*t=open(0) for t in t : a,b,c,d=map(int,t.split()) print('YNeos'[b>min(a,d)or ~(~ a % gcd(b,d))+b>c : : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var _anon : OclAny := null; var t : OclAny := null; Sequence{_anon,t} := OclFile.newOclFile_Write(OclFile.newOclFile(0)) ; for t : t do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (t.split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ('YNeos'(subscript (test (logical_test (logical_test (comparison (comparison (expr (atom (name b)))) > (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name d)))))))) ))))))) or (logical_test (comparison (comparison (expr (expr ~ (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr ~ (expr (atom (name a)))) % (expr (atom (name gcd)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b))))))) , (argument (test (logical_test (comparison (expr (atom (name d)))))))) ))))))))) )))) + (expr (atom (name b))))) > (comparison (expr (atom (name c)))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): return a if b==0 else gcd(b,a % b) def solve(a,b,c,d): if acollect( _x | (OclType["int"])->apply(_x) ) ; for t : Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)))))))) )))))))) ])) * (expr (atom (number (integer 4)))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)))))))) )))))))) ])) * (expr (atom (number (integer 4)))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)))))))) )))))))) ])) * (expr (atom (number (integer 4)))))))))`third->at(_indx)} ) do ( execute (if solve((argument * (test (logical_test (comparison (expr (atom (name t)))))))) then "Yes" else "No" endif)->display()); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return if b = 0 then a else gcd(b, a mod b) endif; operation solve(a : OclAny, b : OclAny, c : OclAny, d : OclAny) : OclAny pre: true post: true activity: if (a->compareTo(b)) < 0 or (d->compareTo(b)) < 0 then ( return false ) else skip ; if (b->compareTo(c)) < 0 then ( return true ) else skip ; var g : OclAny := gcd(b, d) ; return ((b + a mod g - g)->compareTo(c)) <= 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p=int(input()) for i in range(p): q=int(input()) l=[int(i)for i in input().split()] count=1 for i in range(q): if l[i]==1 : if l[i-1]==1 and i>0 : count=count+5 else : count=count+1 else : if l[i]==0 : if l[i-1]==0 and i>0 : count=-1 break else : count=count print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, p-1) do ( var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var count : int := 1 ; for i : Integer.subrange(0, q-1) do ( if l[i+1] = 1 then ( if l[i - 1+1] = 1 & i > 0 then ( count := count + 5 ) else ( count := count + 1 ) ) else ( if l[i+1] = 0 then ( if l[i - 1+1] = 0 & i > 0 then ( count := -1 ; break ) else skip ) else ( count := count ) )) ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from fractions import gcd T=int(input()) ABCD=[[int(x)for x in input().split()]for _ in range(T)] def F(A,B,C,D): if D=B print('\n'.join('Yes' if F(a,b,c,d)else 'No' for a,b,c,d in ABCD)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ABCD : Sequence := Integer.subrange(0, T-1)->select(_anon | true)->collect(_anon | (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))) ; skip ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom 'Yes')))) if (logical_test (comparison (expr (atom (name F)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name b))))))) , (argument (test (logical_test (comparison (expr (atom (name c))))))) , (argument (test (logical_test (comparison (expr (atom (name d)))))))) )))))) else (test (logical_test (comparison (expr (atom 'No')))))) (comp_for for (exprlist (expr (atom (name a))) , (expr (atom (name b))) , (expr (atom (name c))) , (expr (atom (name d)))) in (logical_test (comparison (expr (atom (name ABCD)))))))), ' '))->display(); operation F(A : OclAny, B : OclAny, C : OclAny, D : OclAny) : OclAny pre: true post: true activity: if (D->compareTo(B)) < 0 then ( return false ) else skip ; if (A->compareTo(B)) < 0 then ( return false ) else skip ; var g : OclAny := gcd(D, B) ; var diff : int := A mod g ; A := A - diff ; C := C - diff ; C := C - C mod g ; A := A div g; B := B div g; C := C div g; D := D div g ; return (C + 1->compareTo(B)) >= 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def g(a,b): if a % b==0 : return b return g(b,a % b) def f(a,b,c,d): yes="Yes" no="No" if a=b or a<=c : return yes if(a-c)% b>0 and(a-c)% b0 and(a-c)% htoInteger() ; for i : Integer.subrange(0, t-1) do ( Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : String := f(a, b, c, d) ; execute (ans)->display()); operation g(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a mod b = 0 then ( return b ) else skip ; return g(b, a mod b); operation f(a : OclAny, b : OclAny, c : OclAny, d : OclAny) : OclAny pre: true post: true activity: var yes : String := "Yes" ; var no : String := "No" ; if (a->compareTo(b)) < 0 or (d->compareTo(b)) < 0 then ( return no ) else skip ; if (c->compareTo(b)) >= 0 or (a->compareTo(c)) <= 0 then ( return yes ) else skip ; if (a - c) mod b > 0 & ((a - c) mod b->compareTo(b - c)) < 0 then ( return no ) else skip ; var e : int := d mod b ; if e = 0 or b - c = 1 then ( return yes ) else skip ; if e = 1 then ( return no ) else skip ; var h : OclAny := g(b, e) ; if (h->compareTo(b - c)) < 0 then ( return no ) else skip ; if (a - c) mod h > 0 & ((a - c) mod h->compareTo(b - c)) < 0 then ( return no ) else skip ; return yes; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib,itertools def compute(): cond=lambda i : eulerlib.is_prime(i)and repunit_mod(10**9,i)==0 ans=sum(itertools.islice(filter(cond,itertools.count(2)),40)) return str(ans) def repunit_mod(k,m): return(pow(10,k,m*9)-1)//9 if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var cond : Function := lambda i : OclAny in (eulerlib.is_prime(i) & repunit_mod((10)->pow(9), i) = 0) ; var ans : OclAny := (itertools.islice((itertools->count(2))->select( _x | (cond)->apply(_x) = true ), 40))->sum() ; return ("" + ((ans))); operation repunit_mod(k : OclAny, m : OclAny) : OclAny pre: true post: true activity: return ((10)->pow(k) - 1) div 9; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) L_prime=[j for j in range(1,N+1)if j % 3!=0 and j % 5!=0] print(sum(L_prime)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var L_prime : Sequence := Integer.subrange(1, N + 1-1)->select(j | j mod 3 /= 0 & j mod 5 /= 0)->collect(j | (j)) ; execute ((L_prime)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) all_sum=int(N/2*(N+1)) i=1 while i<=N : if i % 3==0 and i % 5==0 : all_sum-=i elif i % 3==0 : all_sum-=i elif i % 5==0 : all_sum-=i i+=1 print(all_sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var all_sum : int := ("" + ((N / 2 * (N + 1))))->toInteger() ; var i : int := 1 ; while (i->compareTo(N)) <= 0 do ( if i mod 3 = 0 & i mod 5 = 0 then ( all_sum := all_sum - i ) else (if i mod 3 = 0 then ( all_sum := all_sum - i ) else (if i mod 5 = 0 then ( all_sum := all_sum - i ) else skip ) ) ; i := i + 1) ; execute (all_sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math readline=sys.stdin.readline def main(): n=int(readline().rstrip()) allSum=n*(n+1)//2 threeNum=math.floor(n/3) threeSum=3*threeNum*(threeNum+1)//2 fiveNum=math.floor(n/5) fiveSum=5*fiveNum*(fiveNum+1)//2 bothNum=math.floor(n/15) bothSum=15*bothNum*(bothNum+1)//2 print(allSum+bothSum-threeSum-fiveSum) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var readline : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + ((readline().rstrip())))->toInteger() ; var allSum : int := n * (n + 1) div 2 ; var threeNum : double := (n / 3)->floor() ; var threeSum : int := 3 * threeNum * (threeNum + 1) div 2 ; var fiveNum : double := (n / 5)->floor() ; var fiveSum : int := 5 * fiveNum * (fiveNum + 1) div 2 ; var bothNum : double := (n / 15)->floor() ; var bothSum : int := 15 * bothNum * (bothNum + 1) div 2 ; execute (allSum + bothSum - threeSum - fiveSum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) result=0 for i in range(1,n+1): if i % 3==0 and i % 5==0 : continue elif i % 3==0 : continue elif i % 5==0 : continue else : result+=i print(result) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var result : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( if i mod 3 = 0 & i mod 5 = 0 then ( continue ) else (if i mod 3 = 0 then ( continue ) else (if i mod 5 = 0 then ( continue ) else ( result := result + i ) ) ) ) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) cnt=0 for i in range(1,n+1): s=str(i) if len(s)% 2==1 : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cnt : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( var s : String := ("" + ((i))) ; if (s)->size() mod 2 = 1 then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input_num=int(input()) answer=0 for i in range(input_num): i=i+1 if i % 3==0 : pass elif i % 5==0 : pass else : answer=answer+i print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var input_num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var answer : int := 0 ; for i : Integer.subrange(0, input_num-1) do ( var i : OclAny := i + 1 ; if i mod 3 = 0 then ( skip ) else (if i mod 5 = 0 then ( skip ) else ( answer := answer + i ) ) ) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ___gcd(a,b): if(a==0 or b==0): return 0 if(a==b): return a if(a>b): return ___gcd(a-b,b) return ___gcd(a,b-a) def findLargest(arr,n): gcd=arr[0] for i in range(1,n): gcd=___gcd(gcd,arr[i]) return n if(gcd==1)else-1 arr=[1,3,5,7] n=len(arr) print("Length of the largest subarray=",findLargest(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 7 }))) ; n := (arr)->size() ; execute ("Length of the largest subarray=")->display(); operation ___gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0 or b = 0) then ( return 0 ) else skip ; if (a = b) then ( return a ) else skip ; if ((a->compareTo(b)) > 0) then ( return ___gcd(a - b, b) ) else skip ; return ___gcd(a, b - a); operation findLargest(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var gcd : OclAny := arr->first() ; for i : Integer.subrange(1, n-1) do ( gcd := ___gcd(gcd, arr[i+1])) ; return if (gcd = 1) then n else -1 endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools from fractions import Fraction DEGREE=10 def compute(): ans=Fraction(0,1) for k in range(1,DEGREE+1): for n in itertools.count(k+1): if n==DEGREE+2 : raise AssertionError() reference=Fraction(generating_function(n),1) term=optimum_polynomial(k,n) if term!=reference : ans+=term break return str(ans.numerator)+("" if ans.denominator==1 else "/"+str(ans.denominator)) def optimum_polynomial(k,n): sum=Fraction(0,1) for i in range(k+1): product=Fraction(generating_function(i),1) for j in range(1,k+1): if j!=i : product*=Fraction(n-j,i-j) sum+=product return sum def generating_function(n): return sum((-n)**i for i in range(DEGREE+1)) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var DEGREE : int := 10 ; skip ; skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : OclAny := Fraction(0, 1) ; for k : Integer.subrange(1, DEGREE + 1-1) do ( for n : itertools->count(k + 1) do ( if n = DEGREE + 2 then ( error AssertionException.newAssertionException() ) else skip ; var reference : OclAny := Fraction(generating_function(n), 1) ; var term : OclAny := optimum_polynomial(k, n) ; if term /= reference then ( ans := ans + term ; break ) else skip)) ; return ("" + ((ans.numerator))) + (if ans.denominator = 1 then "" else "/" + ("" + ((ans.denominator))) endif); operation optimum_polynomial(k : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sum : OclAny := Fraction(0, 1) ; for i : Integer.subrange(0, k + 1-1) do ( var product : OclAny := Fraction(generating_function(i), 1) ; for j : Integer.subrange(1, k + 1-1) do ( if j /= i then ( product := product * Fraction(n - j, i - j) ) else skip) ; sum := sum + product) ; return sum; operation generating_function(n : OclAny) : OclAny pre: true post: true activity: return ((argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr - (expr (atom (name n)))))))) ))) ** (expr (atom (name i))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name DEGREE))) + (expr (atom (number (integer 1)))))))))) )))))))))->sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,input().split()) S=input() for i,c in enumerate(S,1): if i==K : print(c.lower(),end='') else : print(c,end='') print('') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : String := (OclFile["System.in"]).readLine() ; for _tuple : Integer.subrange(1, (S, 1)->size())->collect( _indx | Sequence{_indx-1, (S, 1)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if i = K then ( execute (c->toLowerCase())->display() ) else ( execute (c)->display() )) ; execute ('')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): d=int(input()) a=list(map(int,input().split())) cnt1=0 cnt0=0 val=1 f=0 for x in range(len(a)): if(not(a[x])): cnt1=0 if(cnt0==1): f=-1 break else : cnt0+=1 else : if(cnt0): cnt0=0 val+=1 cnt1+=1 else : if(cnt1==0): cnt1+=1 val+=1 else : val+=5 if(not(f)): print(val) else : print(f) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt1 : int := 0 ; var cnt0 : int := 0 ; var val : int := 1 ; var f : int := 0 ; for x : Integer.subrange(0, (a)->size()-1) do ( if (not((a[x+1]))) then ( cnt1 := 0 ; if (cnt0 = 1) then ( f := -1 ; break ) else ( cnt0 := cnt0 + 1 ) ) else ( if (cnt0) then ( cnt0 := 0 ; val := val + 1 ; cnt1 := cnt1 + 1 ) else ( if (cnt1 = 0) then ( cnt1 := cnt1 + 1 ; val := val + 1 ) else ( val := val + 5 ) ) )) ; if (not((f))) then ( execute (val)->display() ) else ( execute (f)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): LENGTH=50 ways=[1]+[0]*LENGTH for n in range(1,len(ways)): ways[n]+=sum(ways[max(n-4,0): n]) return str(ways[-1]) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LENGTH : int := 50 ; var ways : Sequence := Sequence{ 1 }->union(MatrixLib.elementwiseMult(Sequence{ 0 }, LENGTH)) ; for n : Integer.subrange(1, (ways)->size()-1) do ( ways[n+1] := ways[n+1] + (ways.subrange(Set{n - 4, 0}->max()+1, n))->sum()) ; return ("" + ((ways->last()))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): LENGTH=50 ways=[0]*(LENGTH+1) for n in range(len(ways)): if n<3 : ways[n]=1 else : ways[n]=ways[n-1]+sum(ways[: n-3])+1 return str(ways[-1]) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LENGTH : int := 50 ; var ways : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (LENGTH + 1)) ; for n : Integer.subrange(0, (ways)->size()-1) do ( if n < 3 then ( ways[n+1] := 1 ) else ( ways[n+1] := ways[n - 1+1] + (ways.subrange(1,n - 3))->sum() + 1 )) ; return ("" + ((ways->last()))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) heights=[int(h)for h in input().split(" ",n-1)] list=[] for i in range(0,n): if i!=(n-1): list.append(abs(heights[i]-heights[i+1])) else : list.append(abs(heights[i]-heights[0])) k=min(list) if list[n-1]==k : print(1,n) else : for j in range(0,n): if list[j]==k : print(j+1,j+2) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var heights : Sequence := input().split(" ", n - 1)->select(h | true)->collect(h | (("" + ((h)))->toInteger())) ; var OclType["Sequence"] : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if i /= (n - 1) then ( execute (((heights[i+1] - heights[i + 1+1])->abs()) : OclType["Sequence"]) ) else ( execute (((heights[i+1] - heights->first())->abs()) : OclType["Sequence"]) )) ; var k : OclAny := (OclType["Sequence"])->min() ; if [n - 1+1] = k then ( execute (1)->display() ) else ( for j : Integer.subrange(0, n-1) do ( if [j+1] = k then ( execute (j + 1)->display() ; break ) else skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) heights=[int(height)for height in input().split()] diff=heights[0]-heights[num-1] if diff<0 : diff*=-1 p1=1 p2=num for i in range(num-1): j=i+1 temp=heights[j]-heights[i] if temp<0 : temp*=-1 if diff>temp : diff=temp p1=i+1 p2=j+1 print(f"{p1}{p2}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var heights : Sequence := input().split()->select(height | true)->collect(height | (("" + ((height)))->toInteger())) ; var diff : double := heights->first() - heights[num - 1+1] ; if diff < 0 then ( diff := diff * -1 ) else skip ; var p1 : int := 1 ; var p2 : int := num ; for i : Integer.subrange(0, num - 1-1) do ( var j : OclAny := i + 1 ; var temp : double := heights[j+1] - heights[i+1] ; if temp < 0 then ( temp := temp * -1 ) else skip ; if (diff->compareTo(temp)) > 0 then ( diff := temp ; p1 := i + 1 ; p2 := j + 1 ) else skip) ; execute (StringLib.formattedString("{p1}{p2}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math num=int(input()) height=input() height=height.split() min=1001 min_num="" for i in range(num): if i==0 and abs(int(height[0])-int(height[num-1]))toInteger() ; var height : String := (OclFile["System.in"]).readLine() ; height := height.split() ; var min : int := 1001 ; var min_num : String := "" ; for i : Integer.subrange(0, num-1) do ( if i = 0 & ((("" + ((height->first())))->toInteger() - ("" + ((height[num - 1+1])))->toInteger())->abs()->compareTo(min)) < 0 then ( min := (("" + ((height->first())))->toInteger() - ("" + ((height[num - 1+1])))->toInteger())->abs() ; min_num := (("" + ((num))) + " " + "1") ) else (if ((("" + ((height[i+1])))->toInteger() - ("" + ((height[i - 1+1])))->toInteger())->abs()->compareTo(min)) < 0 then ( min := (("" + ((height[i+1])))->toInteger() - ("" + ((height[i - 1+1])))->toInteger())->abs() ; min_num := (("" + ((i))) + " " + ("" + ((i + 1)))) ) else skip)) ; execute (min_num)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) digitlen,oddcount=0,0 for i in range(1,n+1): digitlen=len(str(i)) if(digitlen % 2==1): oddcount+=1 print(oddcount) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var digitlen : OclAny := null; var oddcount : OclAny := null; Sequence{digitlen,oddcount} := Sequence{0,0} ; for i : Integer.subrange(1, n + 1-1) do ( var digitlen : int := (("" + ((i))))->size() ; if (digitlen mod 2 = 1) then ( oddcount := oddcount + 1 ) else skip) ; execute (oddcount)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math num=int(input()) height=input() height=height.split() min=abs(int(height[0])-int(height[num-1])) min_num=(str(num)+" "+"1") for i in range(num): if abs(int(height[i])-int(height[i-1]))toInteger() ; var height : String := (OclFile["System.in"]).readLine() ; height := height.split() ; var min : double := (("" + ((height->first())))->toInteger() - ("" + ((height[num - 1+1])))->toInteger())->abs() ; var min_num : String := (("" + ((num))) + " " + "1") ; for i : Integer.subrange(0, num-1) do ( if ((("" + ((height[i+1])))->toInteger() - ("" + ((height[i - 1+1])))->toInteger())->abs()->compareTo(min)) < 0 then ( min := (("" + ((height[i+1])))->toInteger() - ("" + ((height[i - 1+1])))->toInteger())->abs() ; min_num := (("" + ((i))) + " " + ("" + ((i + 1)))) ) else skip) ; execute (min_num)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sur(a): h=[f"{len(a)}1"] m=[abs(a[0]-a[-1])] for i in range(1,len(a)): m.append(abs(a[i-1]-a[i])) h.append(f"{i}{i+1}") return h[m.index(min(m))] n=int(input()) a=[int(i)for i in input().split()] print(sur(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute (sur(a))->display(); operation sur(a : OclAny) : OclAny pre: true post: true activity: var h : Sequence := Sequence{ StringLib.formattedString("{len(a)}1") } ; var m : Sequence := Sequence{ (a->first() - a->last())->abs() } ; for i : Integer.subrange(1, (a)->size()-1) do ( execute (((a[i - 1+1] - a[i+1])->abs()) : m) ; execute ((StringLib.formattedString("{i}{i+1}")) : h)) ; return h[m->indexOf((m)->min()) - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getSum(arr,p): return len(arr) if __name__=="__main__" : arr=[5,6,8] p=7 print(getSum(arr,p)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{5}->union(Sequence{6}->union(Sequence{ 8 })) ; p := 7 ; execute (getSum(arr, p))->display() ) else skip; operation getSum(arr : OclAny, p : OclAny) : OclAny pre: true post: true activity: return (arr)->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def countOfBinaryNumberLessThanN(N): q=deque() q.append(1) cnt=0 while(q): t=q.popleft() if(t<=N): cnt=cnt+1 q.append(t*10) q.append(t*10+1) return cnt if __name__=='__main__' : N=200 print(countOfBinaryNumberLessThanN(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( N := 200 ; execute (countOfBinaryNumberLessThanN(N))->display() ) else skip; operation countOfBinaryNumberLessThanN(N : OclAny) : OclAny pre: true post: true activity: var q : Sequence := () ; execute ((1) : q) ; var cnt : int := 0 ; while (q) do ( var t : OclAny := q->first() ; q := q->tail() ; if ((t->compareTo(N)) <= 0) then ( cnt := cnt + 1 ; execute ((t * 10) : q) ; execute ((t * 10 + 1) : q) ) else skip) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def fact(n): f=1 ; for i in range(2,n+1): f=f*i ; return f ; def npr(n,r): return fact(n)/fact(n-r); def countPermutations(str): even=math.floor(len(str)/2); odd=len(str)-even ; ways=0 ; freq=[0]*26 ; for i in range(len(str)): freq[ord(str[i])-ord('a')]+=1 ; nvowels=(freq[0]+freq[4]+freq[8]+freq[14]+freq[20]); nconsonants=len(str)-nvowels ; ways=(npr(odd,nvowels)*npr(nconsonants,nconsonants)); return int(ways); str="geeks" ; print(countPermutations(str)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; OclType["String"] := "geeks"; ; execute (countPermutations(OclType["String"]))->display();; operation fact(n : OclAny) pre: true post: true activity: var f : int := 1; ; for i : Integer.subrange(2, n + 1-1) do ( f := f * i;) ; return f;; operation npr(n : OclAny, r : OclAny) pre: true post: true activity: return fact(n) / fact(n - r);; operation countPermutations(OclType["String"] : OclAny) pre: true post: true activity: var even : double := ((OclType["String"])->size() / 2)->floor(); ; var odd : double := (OclType["String"])->size() - even; ; var ways : int := 0; ; var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26); ; for i : Integer.subrange(0, (OclType["String"])->size()-1) do ( freq[(("" + ([i+1])))->char2byte() - ('a')->char2byte()+1] := freq[(("" + ([i+1])))->char2byte() - ('a')->char2byte()+1] + 1;) ; var nvowels : OclAny := (freq->first() + freq[4+1] + freq[8+1] + freq[14+1] + freq[20+1]); ; var nconsonants : double := (OclType["String"])->size() - nvowels; ; ways := (npr(odd, nvowels) * npr(nconsonants, nconsonants)); ; return ("" + ((ways)))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) ans=[] while(t): n=int(input()) length=1 days=input().split() for i in range(len(days)): if days[i]=="1" : if i>0 and days[i-1]=="1" : length+=5 else : length+=1 elif days[i]=="0" : if i>0 and days[i-1]=="0" : length=-1 break ans.append(length) t-=1 print(*ans,sep="\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; while (t) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var length : int := 1 ; var days : OclAny := input().split() ; for i : Integer.subrange(0, (days)->size()-1) do ( if days[i+1] = "1" then ( if i > 0 & days[i - 1+1] = "1" then ( length := length + 5 ) else ( length := length + 1 ) ) else (if days[i+1] = "0" then ( if i > 0 & days[i - 1+1] = "0" then ( length := -1 ; break ) else skip ) else skip)) ; execute ((length) : ans) ; t := t - 1) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(n,marks): x=max(marks) bonus=100-x c=0 for i in range(n): if(marks[i]+bonus>=50): c+=1 return c n=5 marks=[0,21,83,45,64] print(check(n,marks)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; marks := Sequence{0}->union(Sequence{21}->union(Sequence{83}->union(Sequence{45}->union(Sequence{ 64 })))) ; execute (check(n, marks))->display(); operation check(n : OclAny, marks : OclAny) : OclAny pre: true post: true activity: var x : OclAny := (marks)->max() ; var bonus : double := 100 - x ; var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (marks[i+1] + bonus >= 50) then ( c := c + 1 ) else skip) ; return c; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countStrings(n,k): dp=[[[0,0]for __ in range(k+1)]for _ in range(n+1)] dp[1][0][0]=1 dp[1][0][1]=1 for i in range(2,n+1): for j in range(k+1): dp[i][j][0]=(dp[i-1][j][0]+dp[i-1][j][1]) dp[i][j][1]=dp[i-1][j][0] if j>=1 : dp[i][j][1]+=dp[i-1][j-1][1] return dp[n][k][0]+dp[n][k][1] if __name__=='__main__' : n=5 k=2 print(countStrings(n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 5 ; k := 2 ; execute (countStrings(n, k))->display() ) else skip; operation countStrings(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, k + 1-1)->select(__ | true)->collect(__ | (Sequence{0}->union(Sequence{ 0 }))))) ; dp[1+1]->first()->first() := 1 ; dp[1+1]->first()[1+1] := 1 ; for i : Integer.subrange(2, n + 1-1) do ( for j : Integer.subrange(0, k + 1-1) do ( dp[i+1][j+1]->first() := (dp[i - 1+1][j+1]->first() + dp[i - 1+1][j+1][1+1]) ; dp[i+1][j+1][1+1] := dp[i - 1+1][j+1]->first() ; if j >= 1 then ( dp[i+1][j+1][1+1] := dp[i+1][j+1][1+1] + dp[i - 1+1][j - 1+1][1+1] ) else skip)) ; return dp[n+1][k+1]->first() + dp[n+1][k+1][1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countP(n,k): dp=[[0 for i in range(k+1)]for j in range(n+1)] for i in range(n+1): dp[i][0]=0 for i in range(k+1): dp[0][k]=0 for i in range(1,n+1): for j in range(1,k+1): if(j==1 or i==j): dp[i][j]=1 else : dp[i][j]=(j*dp[i-1][j]+dp[i-1][j-1]) return dp[n][k] if __name__=='__main__' : print(countP(5,2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( execute (countP(5, 2))->display() ) else skip; operation countP(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, k + 1-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, n + 1-1) do ( dp[i+1]->first() := 0) ; for i : Integer.subrange(0, k + 1-1) do ( dp->first()[k+1] := 0) ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, k + 1-1) do ( if (j = 1 or i = j) then ( dp[i+1][j+1] := 1 ) else ( dp[i+1][j+1] := (j * dp[i - 1+1][j+1] + dp[i - 1+1][j - 1+1]) ))) ; return dp[n+1][k+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=0 for i in range(5): a=int(input()) if a<40 : a=40 s+=a print(s//5) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : int := 0 ; for i : Integer.subrange(0, 5-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if a < 40 then ( a := 40 ) else skip ; s := s + a) ; execute (s div 5)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): import itertools n,m=map(int,input().split()) li=[list(map(int,input().split()))[1 :]for _ in range(m)] p=tuple(map(int,input().split())) q=set(sum(li,[])) r=set(range(1,n+1)) v=r-q ans=0 for i in range(0,len(q)+1): for s in itertools.combinations(q,i): for u,w in zip(li,p): s=set(s) if len(s & set(u))% 2!=w : break else : ans+=2**(len(v)) print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var li : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->tail())) ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : Set := Set{}->union(((li, Sequence{})->sum())) ; var r : Set := Set{}->union((Integer.subrange(1, n + 1-1))) ; var v : double := r - q ; var ans : int := 0 ; for i : Integer.subrange(0, (q)->size() + 1-1) do ( for s : itertools.combinations(q, i) do ((compound_stmt for (exprlist (expr (atom (name u))) , (expr (atom (name w)))) in (testlist (test (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name li))))))) , (argument (test (logical_test (comparison (expr (atom (name p)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name s))) & (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)))))))) )))))))))) )))) % (expr (atom (number (integer 2)))))) != (comparison (expr (atom (name w))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) ** (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))))))) ))))))))))))))))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from statistics import mean scores=[int(input())for i in range(5)] scores=list(map(lambda x : max(40,x),scores)) print(mean(scores)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var scores : Sequence := Integer.subrange(0, 5-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; scores := ((scores)->collect( _x | (lambda x : OclAny in (Set{40, x}->max()))->apply(_x) )) ; execute (mean(scores))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) c=int(input()) d=int(input()) e=int(input()) if a<=40 : a=40 if b<=40 : b=40 if c<=40 : c=40 if d<=40 : d=40 if e<=40 : e=40 print((a+b+c+d+e)//5) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var e : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if a <= 40 then ( a := 40 ) else skip ; if b <= 40 then ( b := 40 ) else skip ; if c <= 40 then ( c := 40 ) else skip ; if d <= 40 then ( d := 40 ) else skip ; if e <= 40 then ( e := 40 ) else skip ; execute ((a + b + c + d + e) div 5)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- data=[] kekka=[] for i in range(5): n=int(input()) data.append(n) for i in range(5): if data[i]<40 : kekka.append(40) else : kekka.append(data[i]) print(int(sum(kekka)/5)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var data : Sequence := Sequence{} ; var kekka : Sequence := Sequence{} ; for i : Integer.subrange(0, 5-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((n) : data)) ; for i : Integer.subrange(0, 5-1) do ( if data[i+1] < 40 then ( execute ((40) : kekka) ) else ( execute ((data[i+1]) : kekka) )) ; execute (("" + (((kekka)->sum() / 5)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sum=0 for i in range(5): n=int(input()) if n<40 : n=40 else : pass sum+=n print(sum//5) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, 5-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n < 40 then ( n := 40 ) else ( skip ) ; sum := sum + n) ; execute (sum div 5)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNthDigit(p,q,N): while(N>0): N-=1 ; p*=10 ; res=p//q ; p %=q ; return res ; if __name__=="__main__" : p=1 ; q=2 ; N=1 ; print(findNthDigit(p,q,N)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( p := 1; q := 2; N := 1; ; execute (findNthDigit(p, q, N))->display(); ) else skip; operation findNthDigit(p : OclAny, q : OclAny, N : OclAny) pre: true post: true activity: while (N > 0) do ( N := N - 1; ; p := p * 10; ; var res : int := p div q; ; p := p mod q;) ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for pratyush in range(int(input())): a,b,c,d=map(int,input().split()) x,y,x1,y1,x2,y2=map(int,input().split()) x+=-a+b y+=-c+d if(a+b>0 and x1==x2)or(c+d>0 and y1==y2): print('NO') elif x1<=x and x<=x2 and y1<=y and y<=y2 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for pratyush : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := null; var y : OclAny := null; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x,y,x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; x := x + -a + b ; y := y + -c + d ; if (a + b > 0 & x1 = x2) or (c + d > 0 & y1 = y2) then ( execute ('NO')->display() ) else (if (x1->compareTo(x)) <= 0 & (x->compareTo(x2)) <= 0 & (y1->compareTo(y)) <= 0 & (y->compareTo(y2)) <= 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) l=list(map(int,input().split()))[: n] k=1 for i in range(1,len(l)): if l[i-1]==l[i]==0 : print(-1) break else : for i in range(1,len(l)): if l[i-1]==l[i]==1 : k+=5 elif l[i]==1 : k+=1 if l[0]==1 : print(k+1) else : print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ; var k : int := 1 ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)))))))) ))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])))) == (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)))))))) ))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])))) == (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name k)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 5))))))))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name k)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name k))) + (expr (atom (number (integer 1)))))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name k)))))))) )))))))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): a,b,c,d=map(int,input().split()) x,y,x1,y1,x2,y2=map(int,input().split()) x+=b-a y+=d-c if a+b>0 and x1==x2 : print("No") elif c+d>0 and y1==y2 : print("No") elif x1<=x<=x2 and y1<=y<=y2 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := null; var y : OclAny := null; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x,y,x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; x := x + b - a ; y := y + d - c ; if a + b > 0 & x1 = x2 then ( execute ("No")->display() ) else (if c + d > 0 & y1 = y2 then ( execute ("No")->display() ) else (if (x1->compareTo(x)) <= 0 & (x <= x2) & (y1->compareTo(y)) <= 0 & (y <= y2) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tests=int(input()) for _ in range(tests): moves=list(map(int,input().split())) xy=list(map(int,input().split())) lr,ud=moves[1]-moves[0],moves[3]-moves[2] x1,y1,x2,y2=abs(xy[2]-xy[0]),abs(xy[3]-xy[1]),abs(xy[4]-xy[0]),abs(xy[5]-xy[1]) if x1==0 and x2==0 and(moves[0]>0 or moves[1]>0): print('No') elif y1==0 and y2==0 and(moves[2]>0 or moves[3]>0): print('No') elif any([lr<=0 and x1=0 and x2=0 and y2toInteger() ; for _anon : Integer.subrange(0, tests-1) do ( var moves : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var xy : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lr : OclAny := null; var ud : OclAny := null; Sequence{lr,ud} := Sequence{moves[1+1] - moves->first(),moves[3+1] - moves[2+1]} ; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := Sequence{(xy[2+1] - xy->first())->abs(),(xy[3+1] - xy[1+1])->abs(),(xy[4+1] - xy->first())->abs(),(xy[5+1] - xy[1+1])->abs()} ; if x1 = 0 & x2 = 0 & (moves->first() > 0 or moves[1+1] > 0) then ( execute ('No')->display() ) else (if y1 = 0 & y2 = 0 & (moves[2+1] > 0 or moves[3+1] > 0) then ( execute ('No')->display() ) else (if (Sequence{lr <= 0 & (x1->compareTo((lr)->abs())) < 0}->union(Sequence{lr >= 0 & (x2->compareTo(lr)) < 0}->union(Sequence{ud <= 0 & (y1->compareTo((ud)->abs())) < 0}->union(Sequence{ ud >= 0 & (y2->compareTo(ud)) < 0 }))))->exists( _x | _x = true ) then ( execute ('No')->display() ) else ( execute ('Yes')->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a,b,c,d=map(int,input().split()) x,y,x1,y1,x2,y2=map(int,input().split()) if x==x1==x2 and a+b!=0 : print("no") continue elif y==y1==y2 and c+d!=0 : print("no") continue range_x=[x1,x2] range_y=[y1,y2] start_pos=[x,y] start_pos[0]-=a start_pos[0]+=b start_pos[1]-=c start_pos[1]+=d if(start_pos[0]>=range_x[0]and start_pos[0]<=range_x[1])and(start_pos[1]>=range_y[0]and start_pos[1]<=range_y[1]): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := null; var y : OclAny := null; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x,y,x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x = x1 & (x1 == x2) & a + b /= 0 then ( execute ("no")->display() ; continue ) else (if y = y1 & (y1 == y2) & c + d /= 0 then ( execute ("no")->display() ; continue ) else skip) ; var range_x : Sequence := Sequence{x1}->union(Sequence{ x2 }) ; var range_y : Sequence := Sequence{y1}->union(Sequence{ y2 }) ; var start_pos : Sequence := Sequence{x}->union(Sequence{ y }) ; start_pos->first() := start_pos->first() - a ; start_pos->first() := start_pos->first() + b ; start_pos[1+1] := start_pos[1+1] - c ; start_pos[1+1] := start_pos[1+1] + d ; if ((start_pos->first()->compareTo(range_x->first())) >= 0 & (start_pos->first()->compareTo(range_x[1+1])) <= 0) & ((start_pos[1+1]->compareTo(range_y->first())) >= 0 & (start_pos[1+1]->compareTo(range_y[1+1])) <= 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys N=int(input()) Nlen=len(str(N)) ans=0 if Nlen==1 : ans=N elif Nlen==2 : ans=9 elif Nlen==3 : ans=9+N-99 elif Nlen==4 : ans=9+900 elif Nlen==5 : ans=9+900+N-9999 elif Nlen==6 : ans=9+900+90000 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var Nlen : int := (("" + ((N))))->size() ; var ans : int := 0 ; if Nlen = 1 then ( ans := N ) else (if Nlen = 2 then ( ans := 9 ) else (if Nlen = 3 then ( ans := 9 + N - 99 ) else (if Nlen = 4 then ( ans := 9 + 900 ) else (if Nlen = 5 then ( ans := 9 + 900 + N - 9999 ) else (if Nlen = 6 then ( ans := 9 + 900 + 90000 ) else skip ) ) ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def eprint(*args,**kwargs): print(*args,file=sys.stderr,**kwargs) testcases=int(input()) for _ in range(testcases): (a,b,c,d)=[int(x)for x in input().split()] (x,y,x1,y1,x2,y2)=[int(x)for x in input().split()] if x1==x==x2 and abs(b)+abs(a)>0 : eprint("cant move x") print("NO") continue if y1==y==y2 and abs(c)+abs(d)>0 : eprint("cant move y") print("NO") continue if b>a : if x2-xc : if y2-ytoInteger() ; for _anon : Integer.subrange(0, testcases-1) do ( ; var Sequence{a, b, c, d} : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var Sequence{x, y, x1, y1, x2, y2} : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if x1 = x & (x == x2) & (b)->abs() + (a)->abs() > 0 then ( eprint("cant move x") ; execute ("NO")->display() ; continue ) else skip ; if y1 = y & (y == y2) & (c)->abs() + (d)->abs() > 0 then ( eprint("cant move y") ; execute ("NO")->display() ; continue ) else skip ; if (b->compareTo(a)) > 0 then ( if (x2 - x->compareTo(b - a)) < 0 then ( eprint("too short right") ; execute ("NO")->display() ; continue ) else skip ) else ( if (x - x1->compareTo(a - b)) < 0 then ( eprint("too short left") ; execute ("NO")->display() ; continue ) else skip ) ; if (d->compareTo(c)) > 0 then ( if (y2 - y->compareTo(d - c)) < 0 then ( eprint("too short up") ; execute ("NO")->display() ; continue ) else skip ) else ( if (y - y1->compareTo(c - d)) < 0 then ( eprint("too short down") ; execute ("NO")->display() ; continue ) else skip ) ; execute ("YES")->display()); operation eprint(args : OclAny : Sequence(OclAny), kwargs : OclAny : Map(String, OclAny)) pre: true post: true activity: (args * (named_parameter (name args)))(kwargs ** (named_parameter (name kwargs))) execute ((argument * (test (logical_test (comparison (expr (atom (name args))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def range_intersection(r1,r2): a1,b1=r1 a2,b2=r2 low=max(a1,a2) high=min(b1,b2) if low<=high : return low,high return None def main(): n,x0=list(map(int,input().split())) curr_range=(0,1000) for _ in range(n): new_range=sorted(list(map(int,input().split()))) curr_range=range_intersection(curr_range,new_range) if curr_range is None : print(-1) return if curr_range[0]<=x0<=curr_range[1]: print(0) else : print(min(abs(curr_range[0]-x0),abs(curr_range[1]-x0))) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation range_intersection(r1 : OclAny, r2 : OclAny) : OclAny pre: true post: true activity: var a1 : OclAny := null; var b1 : OclAny := null; Sequence{a1,b1} := r1 ; var a2 : OclAny := null; var b2 : OclAny := null; Sequence{a2,b2} := r2 ; var low : OclAny := Set{a1, a2}->max() ; var high : OclAny := Set{b1, b2}->min() ; if (low->compareTo(high)) <= 0 then ( return low, high ) else skip ; return null; operation main() pre: true post: true activity: var n : OclAny := null; var x0 : OclAny := null; Sequence{n,x0} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var curr_range : OclAny := Sequence{0, 1000} ; for _anon : Integer.subrange(0, n-1) do ( var new_range : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; curr_range := range_intersection(curr_range, new_range) ; if curr_range <>= null then ( execute (-1)->display() ; return ) else skip) ; if (curr_range->first()->compareTo(x0)) <= 0 & (x0 <= curr_range[1+1]) then ( execute (0)->display() ) else ( execute (Set{(curr_range->first() - x0)->abs(), (curr_range[1+1] - x0)->abs()}->min())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,place=map(int,input().split()) vasya=place max_from_min=0 min_from_max=1001 for a in range(n): man=list(map(int,input().split())) man.sort() if vasyaman[1]: vasya=man[1] if man[0]>max_from_min : max_from_min=man[0] if man[1]min_from_max : print(-1) break else : print(abs(vasya-place)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var place : OclAny := null; Sequence{n,place} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var vasya : OclAny := place ; var max_from_min : int := 0 ; var min_from_max : int := 1001 ; (compound_stmt for (exprlist (expr (atom (name a)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name man)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name man)) (trailer . (name sort) (arguments ( )))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name vasya)))) < (comparison (expr (atom (name man)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name vasya)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name man)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name vasya)))) > (comparison (expr (atom (name man)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name vasya)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name man)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name man)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) > (comparison (expr (atom (name max_from_min))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name max_from_min)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name man)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name man)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) < (comparison (expr (atom (name min_from_max))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name min_from_max)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name man)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name max_from_min)))) > (comparison (expr (atom (name min_from_max))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name vasya))) - (expr (atom (name place))))))))) ))))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=map(int,input().split()) l,r=0,10000 for i in range(n): a,b=map(int,input().split()) if a>b : a,b=b,a l=max(l,a) r=min(r,b) if l>r : print(-1) elif xr : print(x-r) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,10000} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(b)) > 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a} ) else skip ; var l : OclAny := Set{l, a}->max() ; var r : OclAny := Set{r, b}->min()) ; if (l->compareTo(r)) > 0 then ( execute (-1)->display() ) else (if (x->compareTo(l)) < 0 then ( execute (l - x)->display() ) else (if (x->compareTo(r)) > 0 then ( execute (x - r)->display() ) else ( execute (0)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=map(int,input().split()) l,r=0,10000 for i in range(n): a,b=map(int,input().split()) if a>b : a,b=b,a l=max(l,a) r=min(r,b) if l>r : print(-1) elif xr : print(x-r) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,10000} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(b)) > 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a} ) else skip ; var l : OclAny := Set{l, a}->max() ; var r : OclAny := Set{r, b}->min()) ; if (l->compareTo(r)) > 0 then ( execute (-1)->display() ) else (if (x->compareTo(l)) < 0 then ( execute (l - x)->display() ) else (if (x->compareTo(r)) > 0 then ( execute (x - r)->display() ) else ( execute (0)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=map(int,input().split()) s={i : 0 for i in range(1001)} for i in range(n): a=list(map(int,input().split())) for j in range(min(a),max(a)+1): s[j]+=1 c=[] for k in range(1001): if s[k]==n : c.append(abs(x-k)) if len(c)!=0 : print(min(c)) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Map := Integer.subrange(0, 1001-1)->select(i | true)->collect(i | Map{i |-> 0})->unionAll() ; for i : Integer.subrange(0, n-1) do ( var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange((a)->min(), (a)->max() + 1-1) do ( s[j+1] := s[j+1] + 1)) ; var c : Sequence := Sequence{} ; for k : Integer.subrange(0, 1001-1) do ( if s[k+1] = n then ( execute (((x - k)->abs()) : c) ) else skip) ; if (c)->size() /= 0 then ( execute ((c)->min())->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) c=n//(2*(k+1)) print(c,c*k,n-(c+c*k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : int := n div (2 * (k + 1)) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for j in range(t): n=int(input()) l=[int(i)for i in input().split()] c=1 for i in range(n): if i>0 and l[i]==0 and l[i-1]==0 : c=-1 break elif i>0 and l[i]==1 and l[i-1]==1 : c+=5 elif l[i]==1 : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var c : int := 1 ; for i : Integer.subrange(0, n-1) do ( if i > 0 & l[i+1] = 0 & l[i - 1+1] = 0 then ( c := -1 ; break ) else (if i > 0 & l[i+1] = 1 & l[i - 1+1] = 1 then ( c := c + 5 ) else (if l[i+1] = 1 then ( c := c + 1 ) else skip ) ) ) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,k=map(int,input().split()) t=math.floor((n//2)/(k+1)) print(t,k*t,n-(t+t*k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : double := ((n div 2) / (k + 1))->floor() ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) print(n//2//(k+1),n//2//(k+1)*k,n-n//2//(k+1)*(k+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (n div 2 div (k + 1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N=int(input()) i=1 ans=0 while 10**i<=N : ans+=((10**i)-(10**(i-1))) i+=2 ans+=max(0,N-10**(i-1)+1) print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 1 ; var ans : int := 0 ; while ((10)->pow(i)->compareTo(N)) <= 0 do ( ans := ans + (((10)->pow(i)) - ((10)->pow((i - 1)))) ; i := i + 2) ; ans := ans + Set{0, N - (10)->pow((i - 1)) + 1}->max() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys import itertools import fractions if __name__=='__main__' : wtf=sys.stdin.read() wtf=wtf.strip().split('\n') n,k=map(int,wtf[0].split()) x=(n/2)/(1+k) x=int(x) print(x,x*k,n-x-x*k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var wtf : String := (OclFile["System.in"]).readAll() ; wtf := wtf->trim().split(' ') ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (wtf->first().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : double := (n / 2) / (1 + k) ; x := ("" + ((x)))->toInteger() ; execute (x)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solution(n,k): d=(n//2)//(k+1) if d>0 : return[d,k*d,n-(k+1)*d] else : return[0,0,n] n,k=[int(x)for x in input().strip().split(" ")] ans=solution(n,k) print(ans[0],ans[1],ans[2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{n,k} := input()->trim().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : OclAny := solution(n, k) ; execute (ans->first())->display(); operation solution(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var d : int := (n div 2) div (k + 1) ; if d > 0 then ( return Sequence{d}->union(Sequence{k * d}->union(Sequence{ n - (k + 1) * d })) ) else ( return Sequence{0}->union(Sequence{0}->union(Sequence{ n })) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def operator(arg1,arg2,op): if op=='+' : return arg1+arg2 elif op=='-' : return arg1-arg2 elif op=='*' : return arg1*arg2 else : return arg1/arg2 def main(): description=list(input().split()) stack=[] for st in description : if st.isdigit(): stack.append(st) else : op=st arg2=int(stack.pop()) arg1=int(stack.pop()) ans=operator(arg1,arg2,op) stack.append(ans) print(stack.pop()) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation operator(arg1 : OclAny, arg2 : OclAny, op : OclAny) : OclAny pre: true post: true activity: if op = '+' then ( return arg1 + arg2 ) else (if op = '-' then ( return arg1 - arg2 ) else (if op = '*' then ( return arg1 * arg2 ) else ( return arg1 / arg2 ) ) ) ; operation main() pre: true post: true activity: var description : Sequence := (input().split()) ; var stack : Sequence := Sequence{} ; for st : description do ( if st->matches("[0-9]*") then ( execute ((st) : stack) ) else ( op := st ; arg2 := ("" + ((stack->last())))->toInteger() ; arg1 := ("" + ((stack->last())))->toInteger() ; var ans : OclAny := operator(arg1, arg2, op) ; execute ((ans) : stack) )) ; execute (stack->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- top=0 s=[0]*1000 def push(x): global top top+=1 s[top]=x def pop(): global top top-=1 return s[top+1] a=list(input().split()) for x in a : if x=="+" : b=pop() c=pop() push(b+c) elif x=="-" : b=pop() c=pop() push(c-b) elif x=="*" : b=pop() c=pop() push(b*c) else : push(int(x)) print(pop()) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute top : OclAny; attribute top : OclAny; operation initialise() pre: true post: true activity: var top : int := 0 ; var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 1000) ; skip ; skip ; var a : Sequence := (input().split()) ; for x : a do ( if x = "+" then ( var b : OclAny := pop() ; var c : OclAny := pop() ; push(b + c) ) else (if x = "-" then ( b := pop() ; c := pop() ; push(c - b) ) else (if x = "*" then ( b := pop() ; c := pop() ; push(b * c) ) else ( push(("" + ((x)))->toInteger()) ) ) ) ) ; execute (pop())->display(); operation push(x : OclAny) pre: true post: true activity: skip ; top := top + 1 ; s[top+1] := x; operation pop() : OclAny pre: true post: true activity: skip ; top := top - 1 ; return s[top + 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque if __name__=='__main__' : x=[(int)(x)if x.isdigit()else x for x in input().split()] y=deque() for tmp in x : if tmp=='+' : a=y.pop() b=y.pop() y.append(a+b) elif tmp=='-' : a=y.pop() b=y.pop() y.append(b-a) elif tmp=='*' : a=y.pop() b=y.pop() y.append(a*b) else : y.append(tmp) print(y.pop()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var x : Sequence := input().split()->select(x | true)->collect(x | (if x->matches("[0-9]*") then (OclType["int"])(x) else x endif)) ; var y : Sequence := () ; for tmp : x do ( if tmp = '+' then ( var a : OclAny := y->last() ; y := y->front() ; var b : OclAny := y->last() ; y := y->front() ; execute ((a + b) : y) ) else (if tmp = '-' then ( a := y->last() ; y := y->front() ; b := y->last() ; y := y->front() ; execute ((b - a) : y) ) else (if tmp = '*' then ( a := y->last() ; y := y->front() ; b := y->last() ; y := y->front() ; execute ((a * b) : y) ) else ( execute ((tmp) : y) ) ) ) ) ; execute (y->last())->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input().split() x=[] top=len(s) for i in range(top): if s[i]=="+" : a=x.pop() b=x.pop() x.append(int(b)+int(a)) elif s[i]=="-" : a=x.pop() b=x.pop() x.append(int(b)-int(a)) elif s[i]=="*" : a=x.pop() b=x.pop() x.append(int(b)*int(a)) else : x.append(s[i]) print(x[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := input().split() ; var x : Sequence := Sequence{} ; var top : int := (s)->size() ; for i : Integer.subrange(0, top-1) do ( if s[i+1] = "+" then ( var a : OclAny := x->last() ; x := x->front() ; var b : OclAny := x->last() ; x := x->front() ; execute ((("" + ((b)))->toInteger() + ("" + ((a)))->toInteger()) : x) ) else (if s[i+1] = "-" then ( a := x->last() ; x := x->front() ; b := x->last() ; x := x->front() ; execute ((("" + ((b)))->toInteger() - ("" + ((a)))->toInteger()) : x) ) else (if s[i+1] = "*" then ( a := x->last() ; x := x->front() ; b := x->last() ; x := x->front() ; execute ((("" + ((b)))->toInteger() * ("" + ((a)))->toInteger()) : x) ) else ( execute ((s[i+1]) : x) ) ) ) ) ; execute (x->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cal(operand,a,b): if operand=="+" : return int(a)+int(b) elif operand=="-" : return int(a)-int(b) elif operand=="*" : return int(a)*int(b) s=[] top=0 S=list(input().split()) stk=[] for i in S : if i.isdigit()==True : stk.append(int(i)) else : b=stk.pop() a=stk.pop() stk.append(cal(i,a,b)) print(stk[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : Sequence := Sequence{} ; var top : int := 0 ; var S : Sequence := (input().split()) ; var stk : Sequence := Sequence{} ; for i : S do ( if i->matches("[0-9]*") = true then ( execute ((("" + ((i)))->toInteger()) : stk) ) else ( b := stk->last() ; stk := stk->front() ; a := stk->last() ; stk := stk->front() ; execute ((cal(i, a, b)) : stk) )) ; execute (stk->first())->display(); operation cal(operand : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if operand = "+" then ( return ("" + ((a)))->toInteger() + ("" + ((b)))->toInteger() ) else (if operand = "-" then ( return ("" + ((a)))->toInteger() - ("" + ((b)))->toInteger() ) else (if operand = "*" then ( return ("" + ((a)))->toInteger() * ("" + ((b)))->toInteger() ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def longestSubarray(arr,n): i=d=0 ; HASH1=[[0 for x in range(10)]for y in range(2)]; currRow=0 ; maxLen=1 ; len1=0 ; tmp=0 ; tmp=arr[0]; while(tmp>0): HASH1[0][tmp % 10]=1 ; tmp=tmp//10 ; currRow=1 ; for i in range(0,n): tmp=arr[i]; for d in range(0,10): HASH1[currRow][d]=0 ; while(tmp>0): HASH1[currRow][tmp % 10]=1 ; tmp=tmp//10 ; for d in range(0,10): if(HASH1[currRow][d]and HASH1[1-currRow][d]): len1+=1 ; break ; if(d==10): len1=1 ; maxLen=max(maxLen,len1); currRow=1-currRow ; return maxLen ; arr=[11,22,33,44,54,56,63]; n=len(arr); print(longestSubarray(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{11}->union(Sequence{22}->union(Sequence{33}->union(Sequence{44}->union(Sequence{54}->union(Sequence{56}->union(Sequence{ 63 })))))); ; n := (arr)->size(); ; execute (longestSubarray(arr, n))->display();; operation longestSubarray(arr : OclAny, n : OclAny) pre: true post: true activity: var i : OclAny := 0; var d : int := 0; ; var HASH1 : Sequence := Integer.subrange(0, 2-1)->select(y | true)->collect(y | (Integer.subrange(0, 10-1)->select(x | true)->collect(x | (0)))); ; var currRow : int := 0; ; var maxLen : int := 1; ; var len1 : int := 0; ; var tmp : int := 0; ; tmp := arr->first(); ; while (tmp > 0) do ( HASH1->first()[tmp mod 10+1] := 1; ; tmp := tmp div 10;) ; currRow := 1; ; for i : Integer.subrange(0, n-1) do ( tmp := arr[i+1]; ; for d : Integer.subrange(0, 10-1) do ( HASH1[currRow+1][d+1] := 0;) ; while (tmp > 0) do ( HASH1[currRow+1][tmp mod 10+1] := 1; ; tmp := tmp div 10;) ; for d : Integer.subrange(0, 10-1) do ( if (HASH1[currRow+1][d+1] & HASH1[1 - currRow+1][d+1]) then ( len1 := len1 + 1; ; break; ) else skip) ; if (d = 10) then ( len1 := 1; ) else skip ; maxLen := Set{maxLen, len1}->max(); ; currRow := 1 - currRow;) ; return maxLen;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) while n : a,b=map(int,input().split()) print(a ^ b) n-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while n do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (MathLib.bitwiseXor(a, b))->display() ; n := n - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printCubeFree(n): cubFree=[1]*(n+1); i=2 ; while(i*i*i<=n): if(cubFree[i]==1): multiple=1 ; while(i*i*i*multiple<=n): cubFree[i*i*i*multiple]=0 ; multiple+=1 ; i+=1 ; for i in range(2,n+1): if(cubFree[i]==1): print(i,end=" "); if __name__=="__main__" : printCubeFree(20); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( printCubeFree(20); ) else skip; operation printCubeFree(n : OclAny) pre: true post: true activity: var cubFree : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)); ; var i : int := 2; ; while ((i * i * i->compareTo(n)) <= 0) do ( if (cubFree[i+1] = 1) then ( var multiple : int := 1; ; while ((i * i * i * multiple->compareTo(n)) <= 0) do ( cubFree[i * i * i * multiple+1] := 0; ; multiple := multiple + 1;) ) else skip ; i := i + 1;) ; for i : Integer.subrange(2, n + 1-1) do ( if (cubFree[i+1] = 1) then ( execute (i)->display(); ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) print(len(list(filter(lambda x : len(str(x))% 2==1,range(1,N+1))))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((((Integer.subrange(1, N + 1-1))->select( _x | (lambda x : OclAny in ((("" + ((x))))->size() mod 2 = 1))->apply(_x) = true )))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans=[0,1,2,4,6,16,12,64,24,36,48,1024,60] print(ans[int(input())]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ans : Sequence := Sequence{0}->union(Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{6}->union(Sequence{16}->union(Sequence{12}->union(Sequence{64}->union(Sequence{24}->union(Sequence{36}->union(Sequence{48}->union(Sequence{1024}->union(Sequence{ 60 })))))))))))) ; execute (ans[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) i=1 num=[0]*13 while True : cnt=0 for j in range(1,i+1): if i % j==0 : cnt+=1 if cnt>12 : i+=1 continue if num[cnt]==0 : num[cnt]=i if num[n]>0 : ans=num[n] break i+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 1 ; var num : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 13) ; while true do ( var cnt : int := 0 ; for j : Integer.subrange(1, i + 1-1) do ( if i mod j = 0 then ( cnt := cnt + 1 ) else skip) ; if cnt > 12 then ( i := i + 1 ; continue ) else skip ; if num[cnt+1] = 0 then ( num[cnt+1] := i ) else skip ; if num[n+1] > 0 then ( var ans : OclAny := num[n+1] ; break ) else skip ; i := i + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n): for i in range(1,10000): cnt=0 for j in range(1,i+1): if i % j==0 : cnt+=1 if cnt==n : return(i) while True : try : n=int(input()) print(solve(n)) except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( try ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (solve(n))->display()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); operation solve(n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(1, 10000-1) do ( var cnt : int := 0 ; for j : Integer.subrange(1, i + 1-1) do ( if i mod j = 0 then ( cnt := cnt + 1 ) else skip) ; if cnt = n then ( return (i) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) target=1 while True : count=0 for i in range(1,target+1): if target % i==0 : count+=1 if count==N : print(target) break target+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var target : int := 1 ; while true do ( var count : int := 0 ; for i : Integer.subrange(1, target + 1-1) do ( if target mod i = 0 then ( count := count + 1 ) else skip) ; if count = N then ( execute (target)->display() ; break ) else skip ; target := target + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print([1,2,4,6,16,12,64,24,36,48,1024,60][int(input())-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{6}->union(Sequence{16}->union(Sequence{12}->union(Sequence{64}->union(Sequence{24}->union(Sequence{36}->union(Sequence{48}->union(Sequence{1024}->union(Sequence{ 60 })))))))))))[("" + (((OclFile["System.in"]).readLine())))->toInteger() - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import exit n,m=map(int,input().split()) a=list(map(int,input().split())) odd=[] even=[] for x in a : if x % 2==0 : even.append(x) else : odd.append(x) if n % 2==0 : if len(odd)>2 : print("Impossible") exit() if len(odd)==2 : a=[odd[0]]+even+[odd[1]] b=[odd[0]+1]+even+[odd[1]-1] if b[-1]==0 : b.pop() else : a=even b=[1]+even b[-1]-=1 if b[-1]==0 : b.pop() else : if len(odd)>1 : print("Impossible") exit() if m==1 : b=[1,n-1] else : a=odd+even b=[odd[0]+1]+even b[-1]-=1 if b[-1]==0 : b.pop() print(*a) print(len(b)) print(*b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var odd : Sequence := Sequence{} ; var even : Sequence := Sequence{} ; for x : a do ( if x mod 2 = 0 then ( execute ((x) : even) ) else ( execute ((x) : odd) )) ; if n mod 2 = 0 then ( if (odd)->size() > 2 then ( execute ("Impossible")->display() ; exit() ) else skip ; if (odd)->size() = 2 then ( a := Sequence{ odd->first() }->union(even)->union(Sequence{ odd[1+1] }) ; var b : Sequence := Sequence{ odd->first() + 1 }->union(even)->union(Sequence{ odd[1+1] - 1 }) ; if b->last() = 0 then ( b := b->front() ) else skip ) else ( a := even ; b := Sequence{ 1 }->union(even) ; b->last() := b->last() - 1 ; if b->last() = 0 then ( b := b->front() ) else skip ) ) else ( if (odd)->size() > 1 then ( execute ("Impossible")->display() ; exit() ) else skip ; if m = 1 then ( b := Sequence{1}->union(Sequence{ n - 1 }) ) else ( a := odd->union(even) ; b := Sequence{ odd->first() + 1 }->union(even) ; b->last() := b->last() - 1 ) ; if b->last() = 0 then ( b := b->front() ) else skip ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display() ; execute ((b)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name b))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(i)for i in input().split()] a=[int(i)for i in input().split()] breakFlag=False for i in range(1,m-1): if a[i]% 2==1 : if a[0]% 2==1 : if a[len(a)-1]% 2==1 : print("Impossible") breakFlag=True break else : a[i],a[len(a)-1]=a[len(a)-1],a[i] else : a[i],a[0]=a[0],a[i] if breakFlag==False : ans=''.join([str(s)+" " for s in a]) print(ans[:-1]) if m==1 : if a[0]>1 : a[0]-=1 a.append(1) print(m+1) else : print(m) else : if a[len(a)-1]==1 : print(m-1) a.pop() a[0]+=1 else : print(m) a[0]+=1 a[len(a)-1]-=1 ans=''.join([str(s)+" " for s in a]) print(ans[:-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var breakFlag : boolean := false ; for i : Integer.subrange(1, m - 1-1) do ( if a[i+1] mod 2 = 1 then ( if a->first() mod 2 = 1 then ( if a[(a)->size() - 1+1] mod 2 = 1 then ( execute ("Impossible")->display() ; breakFlag := true ; break ) else ( var a[i+1] : OclAny := null; var a[(a)->size() - 1+1] : OclAny := null; Sequence{a[i+1],a[(a)->size() - 1+1]} := Sequence{a[(a)->size() - 1+1],a[i+1]} ) ) else ( var a[i+1] : OclAny := null; var a->first() : OclAny := null; Sequence{a[i+1],a->first()} := Sequence{a->first(),a[i+1]} ) ) else skip) ; if breakFlag = false then ( var ans : String := StringLib.sumStringsWithSeparator((a->select(s | true)->collect(s | (("" + ((s))) + " "))), '') ; execute (ans->front())->display() ; if m = 1 then ( if a->first() > 1 then ( a->first() := a->first() - 1 ; execute ((1) : a) ; execute (m + 1)->display() ) else ( execute (m)->display() ) ) else ( if a[(a)->size() - 1+1] = 1 then ( execute (m - 1)->display() ; a := a->front() ; a->first() := a->first() + 1 ) else ( execute (m)->display() ; a->first() := a->first() + 1 ; a[(a)->size() - 1+1] := a[(a)->size() - 1+1] - 1 ) ) ; ans := StringLib.sumStringsWithSeparator((a->select(s | true)->collect(s | (("" + ((s))) + " "))), '') ; execute (ans->front())->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,m,a): odd=[] even=[] for a_i in a : if a_i % 2==0 : even+=[a_i] else : odd+=[a_i] if len(odd)>=3 : return None a,b=[],[] if odd : x=odd.pop() a+=[x] b+=[x-1] else : x=even.pop() a+=[x] b+=[x-1] a+=even b+=even if odd : x=odd.pop() a+=[x] b+=[x+1] else : b+=[1] return a,b n,m=map(int,input().split()) a=list(map(int,input().split())) it=solve(n,m,a) if it is None : print('Impossible') else : a,b=it b=list(filter(lambda b_i : b_i,b)) print(*a) print(len(b)) print(*b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var it : OclAny := solve(n, m, a) ; if it <>= null then ( execute ('Impossible')->display() ) else ( var b : OclAny := null; Sequence{a,b} := it ; var b : Sequence := ((b)->select( _x | (lambda b_i : OclAny in (b_i))->apply(_x) = true )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display() ; execute ((b)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name b))))))))->display() ); operation solve(n : OclAny, m : OclAny, a : OclAny) : OclAny pre: true post: true activity: var odd : Sequence := Sequence{} ; var even : Sequence := Sequence{} ; for a_i : a do ( if a_i mod 2 = 0 then ( even := even + Sequence{ a_i } ) else ( odd := odd + Sequence{ a_i } )) ; if (odd)->size() >= 3 then ( return null ) else skip ; var b : OclAny := null; Sequence{a,b} := Sequence{Sequence{},Sequence{}} ; if odd then ( var x : OclAny := odd->last() ; odd := odd->front() ; a := a + Sequence{ x } ; b := b + Sequence{ x - 1 } ) else ( x := even->last() ; even := even->front() ; a := a + Sequence{ x } ; b := b + Sequence{ x - 1 } ) ; a := a + even ; b := b + even ; if odd then ( x := odd->last() ; odd := odd->front() ; a := a + Sequence{ x } ; b := b + Sequence{ x + 1 } ) else ( b := b + Sequence{ 1 } ) ; return a, b; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline readlines=sys.stdin.readlines sys.setrecursionlimit(10**7) N,M=map(int,readline().split()) A=[int(x)for x in readline().split()] OD=[x for x in A if x & 1] EV=[x for x in A if not x & 1] if len(OD)>=3 : print('Impossible') exit() if len(A)==1 : if N==1 : B=[1] else : B=[1,N-1] elif len(OD)==0 : B=A.copy() B[0]-=1 B[-1]+=1 elif len(OD)==1 : A=OD+EV B=A.copy() B[0]+=1 B[-1]-=1 else : A=[OD[0]]+EV+[OD[-1]] B=A.copy() B[0]+=1 B[-1]-=1 B=[x for x in B if x>0] print(*A) print(len(B)) print(*B) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var readlines : OclAny := (OclFile["System.in"]).readlines ; sys.setrecursionlimit((10)->pow(7)) ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := readline().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var OD : Sequence := A->select(x | MathLib.bitwiseAnd(x, 1))->collect(x | (x)) ; var EV : Sequence := A->select(x | not(MathLib.bitwiseAnd(x, 1)))->collect(x | (x)) ; if (OD)->size() >= 3 then ( execute ('Impossible')->display() ; exit() ) else skip ; if (A)->size() = 1 then ( if N = 1 then ( var B : Sequence := Sequence{ 1 } ) else ( B := Sequence{1}->union(Sequence{ N - 1 }) ) ) else (if (OD)->size() = 0 then ( B := A->copy() ; B->first() := B->first() - 1 ; B->last() := B->last() + 1 ) else (if (OD)->size() = 1 then ( A := OD->union(EV) ; B := A->copy() ; B->first() := B->first() + 1 ; B->last() := B->last() - 1 ) else ( A := Sequence{ OD->first() }->union(EV)->union(Sequence{ OD->last() }) ; B := A->copy() ; B->first() := B->first() + 1 ; B->last() := B->last() - 1 ) ) ) ; B := B->select(x | x > 0)->collect(x | (x)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name A))))))))->display() ; execute ((B)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name B))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a,b=map(int,input().split()) p=a & b q=(a ^ p)+(b ^ p) print(q) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : int := MathLib.bitwiseAnd(a, b) ; var q : int := (MathLib.bitwiseXor(a, p)) + (MathLib.bitwiseXor(b, p)) ; execute (q)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys for l in sys.stdin : a,b,n=map(int,l.split(" ")) print(sum(map(int,list(str((a % b)*10**n//b))))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for l : OclFile["System.in"] do ( var a : OclAny := null; var b : OclAny := null; var n : OclAny := null; Sequence{a,b,n} := (l.split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((((("" + (((a mod b) * (10)->pow(n) div b))))->characters())->collect( _x | (OclType["int"])->apply(_x) ))->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(n,m,arr): odds=[] evens=[] for a in arr : if a % 2==0 : evens.append(a) else : odds.append(a) if len(odds)>2 : print('Impossible') return if len(odds)==2 : o1,o2=odds aaa=[o1]+evens+[o2] bbb=[2]*(o1//2+1) bbb+=evens bbb+=[2]*(o2//2) elif len(odds)==1 : if odds[0]==1 : aaa=odds+evens bbb=evens+odds elif evens : aaa=odds+evens bbb=[odds[0]-1]+evens[:-1]+[evens[-1]+1] else : aaa=odds bbb=[odds[0]//2,odds[0]//2+1] else : aaa=evens bbb=[1]+evens[:-1]+[evens[-1]-1] print(*aaa) print(len(bbb)) print(*bbb) n,m,*aaa=map(int,sys.stdin.buffer.read().split()) solve(n,m,aaa) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var aaa : OclAny := null; Sequence{n,m,aaa} := (sys.stdin.buffer.readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; solve(n, m, aaa); operation solve(n : OclAny, m : OclAny, arr : OclAny) pre: true post: true activity: var odds : Sequence := Sequence{} ; var evens : Sequence := Sequence{} ; for a : arr do ( if a mod 2 = 0 then ( execute ((a) : evens) ) else ( execute ((a) : odds) )) ; if (odds)->size() > 2 then ( execute ('Impossible')->display() ; return ) else skip ; if (odds)->size() = 2 then ( var o1 : OclAny := null; var o2 : OclAny := null; Sequence{o1,o2} := odds ; var aaa : Sequence := Sequence{ o1 }->union(evens)->union(Sequence{ o2 }) ; var bbb : Sequence := MatrixLib.elementwiseMult(Sequence{ 2 }, (o1 div 2 + 1)) ; bbb := bbb + evens ; bbb := bbb + MatrixLib.elementwiseMult(Sequence{ 2 }, (o2 div 2)) ) else (if (odds)->size() = 1 then ( if odds->first() = 1 then ( aaa := odds->union(evens) ; bbb := evens->union(odds) ) else (if evens then ( aaa := odds->union(evens) ; bbb := Sequence{ odds->first() - 1 }->union(evens->front())->union(Sequence{ evens->last() + 1 }) ) else ( aaa := odds ; bbb := Sequence{odds->first() div 2}->union(Sequence{ odds->first() div 2 + 1 }) ) ) ) else ( aaa := evens ; bbb := Sequence{ 1 }->union(evens->front())->union(Sequence{ evens->last() - 1 }) ) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name aaa))))))))->display() ; execute ((bbb)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name bbb))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==1 : print(1) print(0) elif n==2 : print(2) print(0) print(11) else : print(n-1) for i in range(n-1): print("1"+"0"*i+"1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (1)->display() ; execute (0)->display() ) else (if n = 2 then ( execute (2)->display() ; execute (0)->display() ; execute (11)->display() ) else ( execute (n - 1)->display() ; for i : Integer.subrange(0, n - 1-1) do ( execute ("1" + StringLib.nCopies("0", i) + "1")->display()) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline sys.setrecursionlimit(1000000) from collections import deque,Counter def getN(): return int(input()) def getList(): return list(map(int,input().split())) import math INF=10**20 def main(): n=getN() if n==1 : print(1) print(1) return if n==2 : print(2) print(0) print("11") return print(n-1) print("11") for i in range(1,n-1): print("1"+"0"*i+"1") return if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit(1000000) ; skip ; skip ; skip ; skip ; var INF : double := (10)->pow(20) ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation getN() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation getList() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation main() pre: true post: true activity: var n : OclAny := getN() ; if n = 1 then ( execute (1)->display() ; execute (1)->display() ; return ) else skip ; if n = 2 then ( execute (2)->display() ; execute (0)->display() ; execute ("11")->display() ; return ) else skip ; execute (n - 1)->display() ; execute ("11")->display() ; for i : Integer.subrange(1, n - 1-1) do ( execute ("1" + StringLib.nCopies("0", i) + "1")->display()) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from heapq import heappush,heappop from itertools import permutations,accumulate import sys import math import bisect def LI(): return[int(x)for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return[list(x)for x in sys.stdin.readline().split()] def S(): res=list(sys.stdin.readline()) if res[-1]=="\n" : return res[:-1] return res def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] sys.setrecursionlimit(1000000) mod=1000000007 def solve(): n=I() if n==2 : print(2) print(0) print(11) elif n==1 : print(1) print(0) else : print(n-1) for i in range(n-1): print("0"+"1"*i+"0") return if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1000000) ; var mod : int := 1000000007 ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | ((x))); operation S() : OclAny pre: true post: true activity: var res : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if res->last() = "\n" then ( return res->front() ) else skip ; return res; operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation solve() pre: true post: true activity: n := I() ; if n = 2 then ( execute (2)->display() ; execute (0)->display() ; execute (11)->display() ) else (if n = 1 then ( execute (1)->display() ; execute (0)->display() ) else ( execute (n - 1)->display() ; for i : Integer.subrange(0, n - 1-1) do ( execute ("0" + StringLib.nCopies("1", i) + "0")->display()) ) ) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=[] for i in range(0,N-1): A.append("1"+"0"*i+"1") if N==1 : A=["1"] if N==2 : A=["0","11"] print(len(A)) for a in A : print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := Sequence{} ; for i : Integer.subrange(0, N - 1-1) do ( execute (("1" + StringLib.nCopies("0", i) + "1") : A)) ; if N = 1 then ( A := Sequence{ "1" } ) else skip ; if N = 2 then ( A := Sequence{"0"}->union(Sequence{ "11" }) ) else skip ; execute ((A)->size())->display() ; for a : A do ( execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n<3 : c=[0,[0],[0,11]][n] else : c=list() for i in range(n-1): f='1'+'0'*i+'1' c.append(f) print(len(c)) print(*c,sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n < 3 then ( var c : OclAny := Sequence{0}->union(Sequence{Sequence{ 0 }}->union(Sequence{ Sequence{0}->union(Sequence{ 11 }) }))[n+1] ) else ( c := () ; for i : Integer.subrange(0, n - 1-1) do ( var f : String := '1' + StringLib.nCopies('0', i) + '1' ; execute ((f) : c)) ) ; execute ((c)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name c))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def max_length_substring(st,n,k): max_len=0 len=0 for i in range(0,n): if(st[i]=='0'): len=len+1 ; else : len=0 max_len=max(max_len,len) if(max_len==n): return n*k pref=0 suff=0 i=0 while(st[i]=='0'): i=i+1 pref=pref+1 i=n-1 while(st[i]=='0'): i=i-1 suff=suff+1 if(k>1): max_len=max(max_len,pref+suff) return max_len n=6 k=3 st="110010" ans=max_length_substring(st,n,k) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 6 ; k := 3 ; st := "110010" ; var ans : OclAny := max_length_substring(st, n, k) ; execute (ans)->display(); operation max_length_substring(st : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var max_len : int := 0 ; var len : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (st[i+1] = '0') then ( len := len + 1; ) else ( len := 0 ) ; max_len := Set{max_len, len}->max()) ; if (max_len = n) then ( return n * k ) else skip ; var pref : int := 0 ; var suff : int := 0 ; var i : int := 0 ; while (st[i+1] = '0') do ( i := i + 1 ; pref := pref + 1) ; i := n - 1 ; while (st[i+1] = '0') do ( i := i - 1 ; suff := suff + 1) ; if (k > 1) then ( max_len := Set{max_len, pref + suff}->max() ) else skip ; return max_len; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter def cat(): N=int(input()) A=list(map(int,input().split())) if A==[1]*N : return True if A==[N-1]*N : return True Aset=set(A) if len(Aset)==1 : Amax=A[0] cnt=N-Amax+1 if N<=2*cnt-2 : return True else : return False elif len(Aset)==2 : A.sort() Amax=A[-1] Amin=A[0] if Amin+1!=Amax : return False lower=N-Amax+1 upper=2*lower-2 c=Counter(A) if lower<=c[Amax]<=upper : return True else : return False else : return False if __name__=="__main__" : if cat(): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( if cat() then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation cat() : OclAny pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if A = MatrixLib.elementwiseMult(Sequence{ 1 }, N) then ( return true ) else skip ; if A = MatrixLib.elementwiseMult(Sequence{ N - 1 }, N) then ( return true ) else skip ; var Aset : Set := Set{}->union((A)) ; if (Aset)->size() = 1 then ( var Amax : OclAny := A->first() ; var cnt : double := N - Amax + 1 ; if (N->compareTo(2 * cnt - 2)) <= 0 then ( return true ) else ( return false ) ) else (if (Aset)->size() = 2 then ( A := A->sort() ; Amax := A->last() ; var Amin : OclAny := A->first() ; if Amin + 1 /= Amax then ( return false ) else skip ; var lower : double := N - Amax + 1 ; var upper : double := 2 * lower - 2 ; var c : OclAny := Counter(A) ; if (lower->compareTo(c[Amax+1])) <= 0 & (c[Amax+1] <= upper) then ( return true ) else ( return false ) ) else ( return false ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import array,bisect,collections,copy,heapq,itertools,math,random,re,string,sys,time sys.setrecursionlimit(10**7) INF=10**20 MOD=10**9+7 def II(): return int(input()) def ILI(): return list(map(int,input().split())) def IAI(LINE): return[ILI()for __ in range(LINE)] def IDI(): return{key : value for key,value in ILI()} def read(): N=II() a=ILI() return(N,a) def solve(N,a): a_max=max(a) a_min=min(a) ans="" if a_max-a_min>1 : ans="No" elif a_max-a_min==1 : n_alone=a.count(a_min) n_group=a.count(a_max) if n_alonepow(7)) ; var INF : double := (10)->pow(20) ; var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation ILI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation IAI(LINE : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, LINE-1)->select(__ | true)->collect(__ | (ILI())); operation IDI() : OclAny pre: true post: true activity: return ILI()->select(_tuple | true)->collect(_tuple | Map{key |-> value})->unionAll(); operation read() : OclAny pre: true post: true activity: var N : OclAny := II() ; var a : OclAny := ILI() ; return Sequence{N, a}; operation solve(N : OclAny, a : OclAny) : OclAny pre: true post: true activity: var a_max : OclAny := (a)->max() ; var a_min : OclAny := (a)->min() ; var ans : String := "" ; if a_max - a_min > 1 then ( ans := "No" ) else (if a_max - a_min = 1 then ( var n_alone : int := a->count(a_min) ; var n_group : int := a->count(a_max) ; if (n_alone->compareTo(a_max)) < 0 & (2 * (a_max - n_alone)->compareTo(n_group)) <= 0 then ( ans := "Yes" ) else ( ans := "No" ) ) else (if a_max - a_min = 0 then ( if a->first() = N - 1 or (a->first() * 2->compareTo(N)) <= 0 then ( ans := "Yes" ) else ( ans := "No" ) ) else skip ) ) ; return ans; operation main() pre: true post: true activity: var params : OclAny := read() ; execute (solve((argument * (test (logical_test (comparison (expr (atom (name params)))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline N=int(input()) a=list(map(int,input().split())) a.sort() mx=max(a) mn=min(a) c=mx+0 b=0 s=0 if mx==mn and(mx!=N-1): mn-=1 if mx>=N : print("No") exit(0) for i in range(N): if abs(a[i]-mx)>1 : print("No") exit(0) if a[i]==mn : c=a[i]+1 s+=1 else : b+=1 if s>=c and(b!=0 and s!=0): print("No") exit(0) elif s>c : print("No") exit(0) if b==1 : print("No") exit(0) if b//2toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var mx : OclAny := (a)->max() ; var mn : OclAny := (a)->min() ; var c : OclAny := mx + 0 ; var b : int := 0 ; var s : int := 0 ; if mx = mn & (mx /= N - 1) then ( mn := mn - 1 ) else skip ; if (mx->compareTo(N)) >= 0 then ( execute ("No")->display() ; exit(0) ) else skip ; for i : Integer.subrange(0, N-1) do ( if (a[i+1] - mx)->abs() > 1 then ( execute ("No")->display() ; exit(0) ) else skip ; if a[i+1] = mn then ( c := a[i+1] + 1 ; s := s + 1 ) else ( b := b + 1 )) ; if (s->compareTo(c)) >= 0 & (b /= 0 & s /= 0) then ( execute ("No")->display() ; exit(0) ) else (if (s->compareTo(c)) > 0 then ( execute ("No")->display() ; exit(0) ) else skip) ; if b = 1 then ( execute ("No")->display() ; exit(0) ) else skip ; if (b div 2->compareTo(c - s)) < 0 then ( execute ("No")->display() ) else ( execute ("Yes")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=input()[: :-1] mod=10**9+7 pows=[1] for i in range(10**5+10): pows.append((pows[-1]*3)% mod) dp=1 for i in range(len(l)): if l[i]=='1' : dp=(pows[i]+dp*2)% mod print(dp) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := input()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var mod : double := (10)->pow(9) + 7 ; var pows : Sequence := Sequence{ 1 } ; for i : Integer.subrange(0, (10)->pow(5) + 10-1) do ( execute (((pows->last() * 3) mod mod) : pows)) ; var dp : int := 1 ; for i : Integer.subrange(0, (l)->size()-1) do ( if l[i+1] = '1' then ( dp := (pows[i+1] + dp * 2) mod mod ) else skip) ; execute (dp)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : a,b,n=map(int,input().split()) except : break print(sum(map(int,' '.join(str(a/b).split('.')[1][: n]).split()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var a : OclAny := null; var b : OclAny := null; var n : OclAny := null; Sequence{a,b,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )) catch (_e : OclException) do ( break) ; execute (((' '.join(OclType["String"](a / b).split('.')[1+1].subrange(1,n)).split())->collect( _x | (OclType["int"])->apply(_x) ))->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b=map(int,input().split()) x=a & b print((a ^ x)+(b ^ x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : int := MathLib.bitwiseAnd(a, b) ; execute ((MathLib.bitwiseXor(a, x)) + (MathLib.bitwiseXor(b, x)))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=[int(a)for a in input().split()] A.sort() flag=True for a in A : if a>A[0]+1 : flag=False ans="No" if flag : cnt=A.count(A[0]) if cnt==N and(A[0]==N-1 or A[0]*2<=N): ans="Yes" elif cnt==A[0]and cnt=2*(A[0]-cnt+1): ans="Yes" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; A := A->sort() ; var flag : boolean := true ; for a : A do ( if (a->compareTo(A->first() + 1)) > 0 then ( flag := false ) else skip) ; var ans : String := "No" ; if flag then ( var cnt : int := A->count(A->first()) ; if cnt = N & (A->first() = N - 1 or (A->first() * 2->compareTo(N)) <= 0) then ( ans := "Yes" ) else (if cnt = A->first() & (cnt->compareTo(N - 1)) < 0 then ( ans := "Yes" ) else (if (cnt->compareTo(A->first())) < 0 & (N - cnt->compareTo(2 * (A->first() - cnt + 1))) >= 0 then ( ans := "Yes" ) else skip ) ) ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n=int(input()) a=[int(i)for i in input().split()] a.sort() c=Counter(a) if len(c)>2 or a[0]+1=2*a[0]: print("Yes") else : print("No") else : x,y=c[a[-1]],c[a[0]] if y+1<=a[-1]<=x//2+y : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; a := a->sort() ; var c : OclAny := Counter(a) ; if (c)->size() > 2 or (a->first() + 1->compareTo(a->last())) < 0 then ( execute ("No")->display() ) else (if (c)->size() = 1 then ( if a->first() + 1 = n or (n->compareTo(2 * a->first())) >= 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{c[a->last()+1],c[a->first()+1]} ; if (y + 1->compareTo(a->last())) <= 0 & (a->last() <= x div 2 + y) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np def Probability(p,n): dp=np.zeros((n+1,n+1)); for i in range(n+1): for j in range(n+1): dp[i][j]=0.0 dp[0][0]=1.0 ; for i in range(1,n+1): for j in range(i+1): if(j==0): dp[i][j]=dp[i-1][j]*(1.0-p[i]); else : dp[i][j]=(dp[i-1][j]*(1.0-p[i])+dp[i-1][j-1]*p[i]); ans=0.0 ; for i in range((n+1)//2,n+1): ans+=dp[n][i]; return ans ; if __name__=="__main__" : p=[0.0,0.3,0.4,0.7]; n=len(p)-1 ; print(Probability(p,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( p := Sequence{0.0}->union(Sequence{0.3}->union(Sequence{0.4}->union(Sequence{ 0.7 }))); ; n := (p)->size() - 1; ; execute (Probability(p, n))->display(); ) else skip; operation Probability(p : OclAny, n : OclAny) pre: true post: true activity: var dp : Sequence := MatrixLib.singleValueMatrix(Sequence{n + 1, n + 1}, 0.0); ; for i : Integer.subrange(0, n + 1-1) do ( for j : Integer.subrange(0, n + 1-1) do ( dp[i+1][j+1] := 0.0)) ; dp->first()->first() := 1.0; ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(0, i + 1-1) do ( if (j = 0) then ( dp[i+1][j+1] := dp[i - 1+1][j+1] * (1.0 - p[i+1]); ) else ( dp[i+1][j+1] := (dp[i - 1+1][j+1] * (1.0 - p[i+1]) + dp[i - 1+1][j - 1+1] * p[i+1]); ))) ; var ans : double := 0.0; ; for i : Integer.subrange((n + 1) div 2, n + 1-1) do ( ans := ans + dp[n+1][i+1];) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout nCk=[[int()]*501 for i in range(501)] for n in range(0,501): nCk[n][0]=1 for k in range(1,n+1): nCk[n][k]=nCk[n][k-1]*(n+1-k)/k for n in range(0,501): for k in range(1,n+1): nCk[n][k]%=100003 Y=[[int()]*501 for i in range(501)] y=[int()]*501 for i in range(2,501): Y[i][1]=1 y[i]=1 for j in range(2,i): for k in range(1,j): Y[i][j]+=Y[j][k]*nCk[i-j-1][j-k-1] y[i]+=Y[i][j] y[i]%=100003 for x in range(1,int(stdin.readline())+1): n=int(stdin.readline()) stdout.write('Case #%i: %i\n' %(x,y[n])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var nCk : Sequence := Integer.subrange(0, 501-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ ("" + (()))->toInteger() }, 501))) ; for n : Integer.subrange(0, 501-1) do ( nCk[n+1]->first() := 1 ; for k : Integer.subrange(1, n + 1-1) do ( nCk[n+1][k+1] := nCk[n+1][k - 1+1] * (n + 1 - k) / k)) ; for n : Integer.subrange(0, 501-1) do ( for k : Integer.subrange(1, n + 1-1) do ( nCk[n+1][k+1] := nCk[n+1][k+1] mod 100003)) ; var Y : Sequence := Integer.subrange(0, 501-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ ("" + (()))->toInteger() }, 501))) ; var y : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (()))->toInteger() }, 501) ; for i : Integer.subrange(2, 501-1) do ( Y[i+1][1+1] := 1 ; y[i+1] := 1 ; for j : Integer.subrange(2, i-1) do ( for k : Integer.subrange(1, j-1) do ( Y[i+1][j+1] := Y[i+1][j+1] + Y[j+1][k+1] * nCk[i - j - 1+1][j - k - 1+1]) ; y[i+1] := y[i+1] + Y[i+1][j+1]) ; y[i+1] := y[i+1] mod 100003) ; for x : Integer.subrange(1, ("" + ((stdin.readLine())))->toInteger() + 1-1) do ( var n : int := ("" + ((stdin.readLine())))->toInteger() ; stdout.write(StringLib.format('Case #%i: %i ',Sequence{x, y[n+1]}))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys if(len(sys.argv)<2): print("No file specified") sys.exit(1) infile=open(sys.argv[1]) outfile=open(sys.argv[1]+".out","w") num_cases=int(infile.readline().strip()) modulus=100003 factorial=[1] for i in range(1,501): factorial.append(i*factorial[i-1]) def choose(n,r): return factorial[n]/(factorial[r]*factorial[n-r]) cached_results={} def calculate_perms(num,length): key="%d-%d" %(num,length) if key not in cached_results : if length==1 : new_result=1 else : new_result=0 min_pos=max(0,2*length-1-num) max_pos=length-1 for i in range(min_pos,max_pos): new_result+=choose(num-length-1,length-i-2)*calculate_perms(length,i+1) cached_results[key]=new_result return cached_results[key] for case in range(1,num_cases+1): n=int(infile.readline()) result=0 for i in range(1,n): result+=calculate_perms(n,i)% modulus result %=modulus outfile.write("Case #%d: %d\n" %(case,result)) if case % 10==0 : print("Completed case %d" % case) outfile.close() infile.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if (((trailer . (name argv)))->size() < 2) then ( execute ("No file specified")->display() ; sys.exit(1) ) else skip ; var infile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) ; var outfile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) + ".out")) ; var num_cases : int := ("" + ((infile.readLine()->trim())))->toInteger() ; var modulus : int := 100003 ; var factorial : Sequence := Sequence{ 1 } ; for i : Integer.subrange(1, 501-1) do ( execute ((i * factorial[i - 1+1]) : factorial)) ; skip ; var cached_results : OclAny := Set{} ; skip ; for case : Integer.subrange(1, num_cases + 1-1) do ( n := ("" + ((infile.readLine())))->toInteger() ; var result : int := 0 ; for i : Integer.subrange(1, n-1) do ( result := result + calculate_perms(n, i) mod modulus) ; result := result mod modulus ; outfile.write(StringLib.format("Case #%d: %d\n",Sequence{case, result})) ; if case mod 10 = 0 then ( execute (StringLib.format("Completed case %d",case))->display() ) else skip) ; outfile.closeFile() ; infile.closeFile(); operation choose(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: return factorial[n+1] / (factorial[r+1] * factorial[n - r+1]); operation calculate_perms(num : OclAny, length : OclAny) : OclAny pre: true post: true activity: var key : String := StringLib.format("%d-%d",Sequence{num, length}) ; if (cached_results)->excludes(key) then ( if length = 1 then ( var new_result : int := 1 ) else ( new_result := 0 ; var min_pos : OclAny := Set{0, 2 * length - 1 - num}->max() ; var max_pos : double := length - 1 ; for i : Integer.subrange(min_pos, max_pos-1) do ( new_result := new_result + choose(num - length - 1, length - i - 2) * calculate_perms(length, i + 1)) ) ; cached_results->at(key) := new_result ) else skip ; return cached_results->at(key); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Count(str): upper,lower,number,special=0,0,0,0 for i in range(len(str)): if str[i]>='A' and str[i]<='Z' : upper+=1 elif str[i]>='a' and str[i]<='z' : lower+=1 elif str[i]>='0' and str[i]<='9' : number+=1 else : special+=1 print('Upper case letters:',upper) print('Lower case letters:',lower) print('Number:',number) print('Special characters:',special) str="#GeeKs01fOr@gEEks07" Count(str) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclType["String"] := "#GeeKs01fOr@gEEks07" ; Count(OclType["String"]); operation Count(OclType["String"] : OclAny) pre: true post: true activity: var upper : OclAny := null; var lower : OclAny := null; var number : OclAny := null; var special : OclAny := null; Sequence{upper,lower,number,special} := Sequence{0,0,0,0} ; for i : Integer.subrange(0, (OclType["String"])->size()-1) do ( if ("" + ([i+1])) >= 'A' & ("" + ([i+1])) <= 'Z' then ( upper := upper + 1 ) else (if ("" + ([i+1])) >= 'a' & ("" + ([i+1])) <= 'z' then ( lower := lower + 1 ) else (if ("" + ([i+1])) >= '0' & ("" + ([i+1])) <= '9' then ( number := number + 1 ) else ( special := special + 1 ) ) ) ) ; execute ('Upper case letters:')->display() ; execute ('Lower case letters:')->display() ; execute ('Number:')->display() ; execute ('Special characters:')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t=int(input()) ans=[] for _ in range(t): a,b=map(int,input().split()) if not b : ans0=1 elif not a : ans0=0.5 elif a<=4*b : ans0=(a*b+(a*a)/8)/(2*a*b) else : ans0=1-b/a ans.append(ans0) sys.stdout.write("\n".join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if not(b) then ( var ans0 : int := 1 ) else (if not(a) then ( ans0 := 0.5 ) else (if (a->compareTo(4 * b)) <= 0 then ( ans0 := (a * b + (a * a) / 8) / (2 * a * b) ) else ( ans0 := 1 - b / a ) ) ) ; execute ((ans0) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): a,b=map(int,input().split()) if b==0 : print(1) else : d=4*b e=max(0,a-d) f=min(2*d,a+d) g=(100000*d-1)*100000*d//2 h=100000*f*(100000*f+1)//2 i=(h-g)/100000 print(i/(2*d*(100000*a+1))+100000*e/(100000*a+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if b = 0 then ( execute (1)->display() ) else ( var d : double := 4 * b ; var e : OclAny := Set{0, a - d}->max() ; var f : OclAny := Set{2 * d, a + d}->min() ; var g : int := (100000 * d - 1) * 100000 * d div 2 ; var h : int := 100000 * f * (100000 * f + 1) div 2 ; var i : double := (h - g) / 100000 ; execute (i / (2 * d * (100000 * a + 1)) + 100000 * e / (100000 * a + 1))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): a,b=map(int,input().split()) if b==0 : print(1) else : d=4*b e=max(0,a-d) f=min(2*d,a+d) g=(100000*d-1)*d h=f*(100000*f+1) i=(h-g)/2 print(i/(2*d*(100000*a+1))+100000*e/(100000*a+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if b = 0 then ( execute (1)->display() ) else ( var d : double := 4 * b ; var e : OclAny := Set{0, a - d}->max() ; var f : OclAny := Set{2 * d, a + d}->min() ; var g : double := (100000 * d - 1) * d ; var h : double := f * (100000 * f + 1) ; var i : double := (h - g) / 2 ; execute (i / (2 * d * (100000 * a + 1)) + 100000 * e / (100000 * a + 1))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(a,b,n): result=0 a=a % b for i in range(n): a*=10 result+=a//b a=a % b return result if __name__=='__main__' : for line in sys.stdin : a,b,n=[int(x)for x in line.strip().split(' ')] result=solve(a,b,n) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( for line : OclFile["System.in"] do ( Sequence{a,b,n} := line->trim().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; result := solve(a, b, n) ; execute (result)->display()) ) else skip; operation solve(a : OclAny, b : OclAny, n : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; a := a mod b ; for i : Integer.subrange(0, n-1) do ( a := a * 10 ; result := result + a div b ; a := a mod b) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): a,b=map(int,input().split()) if b==0 : print(1) else : d=4*b e=max(0,a-d) f=min(2*d,a+d) g=(100000*d-1)*d h=f*(100000*f+1) i=(h-g) print(i/(4*d*(100000*a+1))+100000*e/(100000*a+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if b = 0 then ( execute (1)->display() ) else ( var d : double := 4 * b ; var e : OclAny := Set{0, a - d}->max() ; var f : OclAny := Set{2 * d, a + d}->min() ; var g : double := (100000 * d - 1) * d ; var h : double := f * (100000 * f + 1) ; var i : double := (h - g) ; execute (i / (4 * d * (100000 * a + 1)) + 100000 * e / (100000 * a + 1))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a,b=map(int,input().split()) x=a & b print((a ^ x)+(b ^ x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : int := MathLib.bitwiseAnd(a, b) ; execute ((MathLib.bitwiseXor(a, x)) + (MathLib.bitwiseXor(b, x)))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* def solve(): a,b=map(int,input().split()) if b==0 : print(1) elif a==0 : print(0.5) else : area_ok=a*b area_all=2*a*b if a>4*b : area_ok+=a*b-2*b*b else : area_ok+=a*a/8 print(area_ok/area_all) tst=int(input()) for t in range(tst): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var tst : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(0, tst-1) do ( solve()); operation solve() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if b = 0 then ( execute (1)->display() ) else (if a = 0 then ( execute (0.5)->display() ) else ( var area_ok : double := a * b ; var area_all : double := 2 * a * b ; if (a->compareTo(4 * b)) > 0 then ( area_ok := area_ok + a * b - 2 * b * b ) else ( area_ok := area_ok + a * a / 8 ) ; execute (area_ok / area_all)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np MAX=100000 bitscount=32 prefix_count=np.zeros((bitscount,MAX)); def findPrefixCount(arr,n): for i in range(0,bitscount): prefix_count[i][0]=((arr[0]>>i)& 1); for j in range(1,n): prefix_count[i][j]=((arr[j]>>i)& 1); prefix_count[i][j]+=prefix_count[i][j-1]; def rangeOr(l,r): ans=0 ; for i in range(bitscount): x=0 ; if(l==0): x=prefix_count[i][r]; else : x=prefix_count[i][r]-prefix_count[i][l-1]; if(x!=0): ans=(ans |(1<union(Sequence{5}->union(Sequence{3}->union(Sequence{5}->union(Sequence{2}->union(Sequence{ 3 }))))); ; n := (arr)->size(); ; findPrefixCount(arr, n); ; var queries : Sequence := Sequence{Sequence{1}->union(Sequence{ 3 })}->union(Sequence{ Sequence{4}->union(Sequence{ 5 }) }); ; var q : int := (queries)->size(); ; for i : Integer.subrange(0, q-1) do ( execute (rangeOr(queries[i+1]->first(), queries[i+1][1+1]))->display();) ) else skip; operation findPrefixCount(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, bitscount-1) do ( prefix_count[i+1]->first() := (MathLib.bitwiseAnd((arr->first() /(2->pow(i))), 1)); ; for j : Integer.subrange(1, n-1) do ( prefix_count[i+1][j+1] := (MathLib.bitwiseAnd((arr[j+1] /(2->pow(i))), 1)); ; prefix_count[i+1][j+1] := prefix_count[i+1][j+1] + prefix_count[i+1][j - 1+1];)); operation rangeOr(l : OclAny, r : OclAny) pre: true post: true activity: var ans : int := 0; ; for i : Integer.subrange(0, bitscount-1) do ( var x : int := 0; ; if (l = 0) then ( x := prefix_count[i+1][r+1]; ) else ( x := prefix_count[i+1][r+1] - prefix_count[i+1][l - 1+1]; ) ; if (x /= 0) then ( ans := (MathLib.bitwiseOr(ans, (1 * (2->pow(i))))); ) else skip) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np MAX=100000 bitscount=32 prefix_count=np.zeros((bitscount,MAX)); def findPrefixCount(arr,n): for i in range(0,bitscount): prefix_count[i][0]=((arr[0]>>i)& 1); for j in range(1,n): prefix_count[i][j]=((arr[j]>>i)& 1); prefix_count[i][j]+=prefix_count[i][j-1]; def rangeOr(l,r): ans=0 ; for i in range(bitscount): x=0 ; if(l==0): x=prefix_count[i][r]; else : x=prefix_count[i][r]-prefix_count[i][l-1]; if(x==r-l+1): ans=(ans |(1<union(Sequence{5}->union(Sequence{3}->union(Sequence{5}->union(Sequence{2}->union(Sequence{ 3 }))))); ; n := (arr)->size(); ; findPrefixCount(arr, n); ; var queries : Sequence := Sequence{Sequence{1}->union(Sequence{ 3 })}->union(Sequence{ Sequence{4}->union(Sequence{ 5 }) }); ; var q : int := (queries)->size(); ; for i : Integer.subrange(0, q-1) do ( execute (rangeOr(queries[i+1]->first(), queries[i+1][1+1]))->display();) ) else skip; operation findPrefixCount(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, bitscount-1) do ( prefix_count[i+1]->first() := (MathLib.bitwiseAnd((arr->first() /(2->pow(i))), 1)); ; for j : Integer.subrange(1, n-1) do ( prefix_count[i+1][j+1] := (MathLib.bitwiseAnd((arr[j+1] /(2->pow(i))), 1)); ; prefix_count[i+1][j+1] := prefix_count[i+1][j+1] + prefix_count[i+1][j - 1+1];)); operation rangeOr(l : OclAny, r : OclAny) pre: true post: true activity: var ans : int := 0; ; for i : Integer.subrange(0, bitscount-1) do ( var x : int := 0; ; if (l = 0) then ( x := prefix_count[i+1][r+1]; ) else ( x := prefix_count[i+1][r+1] - prefix_count[i+1][l - 1+1]; ) ; if (x = r - l + 1) then ( ans := (MathLib.bitwiseOr(ans, (1 * (2->pow(i))))); ) else skip) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,x=map(int,input().split()) a=list(map(int,input().split())) var=[] b=a.copy() for j in range(n): ans=1 while a[j]% x==0 : a[j]=a[j]//x ans+=1 var.append(ans) mini=var[0] ind=0 for j in range(1,len(var)): if mini>var[j]: mini=var[j] ind=j value=0 for j in range(ind): value+=b[j]*(mini+1) for j in range(ind,n): value+=b[j]*(mini) print(value) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var var : Sequence := Sequence{} ; var b : OclAny := a->copy() ; for j : Integer.subrange(0, n-1) do ( var ans : int := 1 ; while a[j+1] mod x = 0 do ( a[j+1] := a[j+1] div x ; ans := ans + 1) ; execute ((ans) : var)) ; var mini : OclAny := var->first() ; var ind : int := 0 ; for j : Integer.subrange(1, (var)->size()-1) do ( if (mini->compareTo(var[j+1])) > 0 then ( mini := var[j+1] ; ind := j ) else skip) ; var value : int := 0 ; for j : Integer.subrange(0, ind-1) do ( value := value + b[j+1] * (mini + 1)) ; for j : Integer.subrange(ind, n-1) do ( value := value + b[j+1] * (mini)) ; execute (value)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,x=map(int,input().split()); l=list(map(int,input().split())) s=sum(l); c=0 ; u=x while c==0 : for i in l : if i % u==0 : s+=i else : c=c+1 ; print(s); break u=u*x ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : OclAny := (l)->sum(); var c : int := 0; var u : OclAny := x ; while c = 0 do ( for i : l do ( if i mod u = 0 then ( s := s + i ) else ( c := c + 1; execute (s)->display(); break )) ; u := u * x)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def func(num): global x c=1 while num % x==0 : c+=1 num//=x else : return c def Solve(): global x for t in range(int(input())): n,x=map(int,input().split()) a=list(map(int,input().split())) b=list(map(func,a)) min_=min(b) index_=b.index(min_) Sum=sum(a[: index_])*(min_+1)+sum(a[index_ :])*min_ print(Sum) if __name__=="__main__" : Solve() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute x : OclAny; attribute x : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( Solve() ) else skip; operation func(num : OclAny) pre: true post: true activity: skip ; var c : int := 1 ; (compound_stmt while (test (logical_test (comparison (comparison (expr (expr (atom (name num))) % (expr (atom (name x))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name num)))))))) (assign_part //= (testlist (test (logical_test (comparison (expr (atom (name x)))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name c))))))))))))); operation Solve() pre: true post: true activity: skip ; for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((a)->collect( _x | (func)->apply(_x) )) ; var min_ : OclAny := (b)->min() ; var index_ : int := b->indexOf(min_) - 1 ; var Sum : double := (a.subrange(1,index_))->sum() * (min_ + 1) + (a.subrange(index_+1))->sum() * min_ ; execute (Sum)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def padic(num,xx): total=0 while num % xx==0 : num=num//xx total+=1 return total for _ in range(int(input())): n,xx=[int(x)for x in input().split()] nums=[int(x)for x in input().split()] num2s=[padic(x,xx)for x in nums] print((min(num2s)+1)*sum(nums)+sum(nums[:(num2s.index(min(num2s)))])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; Sequence{n,xx} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var nums : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var num2s : Sequence := nums->select(x | true)->collect(x | (padic(x, xx))) ; execute (((num2s)->min() + 1) * (nums)->sum() + (nums.subrange(1,(num2s->indexOf((num2s)->min()) - 1)))->sum())->display()); operation padic(num : OclAny, xx : OclAny) : OclAny pre: true post: true activity: var total : int := 0 ; while num mod xx = 0 do ( num := num div xx ; total := total + 1) ; return total; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(_array,y): sum=0 n=1 while True : for i in _array : if i % n==0 : sum+=i else : return sum n=n*y for _ in range(int(input())): x,y=list(map(int,input().split(" "))) _array=list(map(int,input().split(" "))) sum=solve(_array,y) print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; Sequence{x,y} := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; _array := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; sum := solve(_array, y) ; execute (sum)->display()); operation solve(_array : OclAny, y : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; var n : int := 1 ; while true do ( for i : _array do ( if i mod n = 0 then ( sum := sum + i ) else ( return sum )) ; n := n * y); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,bisect PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") for line in sys.stdin : a,b,n=[int(_)for _ in line.split()] frac=str(round(a/b,n+2)).split('.')[1] print(sum([int(d)for d in frac[: n]])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; for line : OclFile["System.in"] do ( var a : OclAny := null; var b : OclAny := null; var n : OclAny := null; Sequence{a,b,n} := line.split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var frac : OclAny := OclType["String"](MathLib.roundN(a / b, n + 2)).split('.')[1+1] ; execute ((frac.subrange(1,n)->select(d | true)->collect(d | (("" + ((d)))->toInteger())))->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) li=[list(map(int,input().split()))for _ in range(n)] li.sort(key=lambda x : x[1]) time=0 for i,j in li : time+=i if time>j : print('No') exit() print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; li := li->sort() ; var time : int := 0 ; for _tuple : li do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); time := time + i ; if (time->compareTo(j)) > 0 then ( execute ('No')->display() ; exit() ) else skip) ; execute ('Yes')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from io import StringIO import unittest import os sys.setrecursionlimit(999999999) def resolve(test_def_name=""): n=int(input()) a_b=[list(map(int,input().split()))for i in range(n)] a_b=sorted(a_b,key=lambda x : x[1]) time_space=0 for i in range(len(a_b)): if i==0 : time_space=a_b[i][1]-a_b[i][0] else : time_space=a_b[i][1]-a_b[i-1][1]-a_b[i][0]+time_space if time_space<0 : print("No") return print("Yes") class TestClass(unittest.TestCase): def assertIO(self,assert_input,output): stdout,sat_in=sys.stdout,sys.stdin sys.stdout,sys.stdin=StringIO(),StringIO(assert_input) resolve(sys._getframe().f_back.f_code.co_name) sys.stdout.seek(0) out=sys.stdout.read()[:-1] sys.stdout,sys.stdin=stdout,sat_in self.assertEqual(out,output) def test_input_1(self): test_input="""5 2 4 1 9 1 8 4 9 3 12""" output="""Yes""" self.assertIO(test_input,output) def test_input_2(self): test_input="""3 334 1000 334 1000 334 1000""" output="""No""" self.assertIO(test_input,output) def test_input_3(self): test_input="""30 384 8895 1725 9791 170 1024 4 11105 2 6 578 1815 702 3352 143 5141 1420 6980 24 1602 849 999 76 7586 85 5570 444 4991 719 11090 470 10708 1137 4547 455 9003 110 9901 15 8578 368 3692 104 1286 3 4 366 12143 7 6649 610 2374 152 7324 4 7042 292 11386 334 5720""" output="""Yes""" self.assertIO(test_input,output) def tes_t_1original_1(self): test_input="""データ""" output="""データ""" self.assertIO(test_input,output) if __name__=="__main__" : if os.environ.get("USERNAME")is None : resolve() else : unittest.main() ------------------------------------------------------------ OCL File: --------- class TestClass extends unittest.TestCase { static operation newTestClass() : TestClass pre: true post: TestClass->exists( _x | result = _x ); operation assertIO(assert_input : OclAny,output : OclAny) pre: true post: true activity: var stdout : OclAny := null; var sat_in : OclAny := null; Sequence{stdout,sat_in} := Sequence{OclFile["System.out"],OclFile["System.in"]} ; var OclFile["System.out"] : OclAny := null; var OclFile["System.in"] : OclAny := null; Sequence{OclFile["System.out"],OclFile["System.in"]} := Sequence{StringIO(),StringIO(assert_input)} ; resolve(sys._getframe().f_back.f_code.co_name) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name seek) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))) ; var out : OclAny := sys.stdout.readAll()->front() ; var OclFile["System.out"] : OclAny := null; var OclFile["System.in"] : OclAny := null; Sequence{OclFile["System.out"],OclFile["System.in"]} := Sequence{stdout,sat_in} ; self.assertEqual(out, output); operation test_input operation test_input skip(self : OclAny) pre: true post: true activity: var test_input : String := (atom "" "5\r\n2 4\r\n1 9\r\n1 8\r\n4 9\r\n3 12" "") ; output := (atom "" "Yes" "") ; self.assertIO(test_input, output); () pre: true post: true activity: var test_input : String := (atom "" "5\r\n2 4\r\n1 9\r\n1 8\r\n4 9\r\n3 12" "") ; output := (atom "" "Yes" "") ; self.assertIO(test_input, output); operation test_inputself : OclAny() pre: true post: true activity: test_input := (atom "" "3\r\n334 1000\r\n334 1000\r\n334 1000" "") ; output := (atom "" "No" "") ; self.assertIO(test_input, output); operation test_input test_input := (atom "" "30\r\n384 8895\r\n1725 9791\r\n170 1024\r\n4 11105\r\n2 6\r\n578 1815\r\n702 3352\r\n143 5141\r\n1420 6980\r\n24 1602\r\n849 999\r\n76 7586\r\n85 5570\r\n444 4991\r\n719 11090\r\n470 10708\r\n1137 4547\r\n455 9003\r\n110 9901\r\n15 8578\r\n368 3692\r\n104 1286\r\n3 4\r\n366 12143\r\n7 6649\r\n610 2374\r\n152 7324\r\n4 7042\r\n292 11386\r\n334 5720" "") ; output := (atom "" "Yes" "") ; self.assertIO(test_input, output)() pre: true post: true activity: test_input := (atom "" "30\r\n384 8895\r\n1725 9791\r\n170 1024\r\n4 11105\r\n2 6\r\n578 1815\r\n702 3352\r\n143 5141\r\n1420 6980\r\n24 1602\r\n849 999\r\n76 7586\r\n85 5570\r\n444 4991\r\n719 11090\r\n470 10708\r\n1137 4547\r\n455 9003\r\n110 9901\r\n15 8578\r\n368 3692\r\n104 1286\r\n3 4\r\n366 12143\r\n7 6649\r\n610 2374\r\n152 7324\r\n4 7042\r\n292 11386\r\n334 5720" "") ; output := (atom "" "Yes" "") ; self.assertIO(test_input, output); operation tes_t operation tes_t skiporiginal skip(self : OclAny) pre: true post: true activity: test_input := (atom "" "???" "") ; output := (atom "" "???" "") ; self.assertIO(test_input, output); original operation tes_t skiporiginal skip(self : OclAny) pre: true post: true activity: test_input := (atom "" "???" "") ; output := (atom "" "???" "") ; self.assertIO(test_input, output); () pre: true post: true activity: test_input := (atom "" "???" "") ; output := (atom "" "???" "") ; self.assertIO(test_input, output); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; sys.setrecursionlimit(999999999) ; skip ; skip ; if __name__ = "__main__" then ( if os.environ.get("USERNAME") <>= null then ( resolve() ) else ( unittest.main() ) ) else skip; operation resolve(test_def_name : String) pre: true post: true activity: if test_def_name->oclIsUndefined() then test_def_name := "" else skip; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a_b : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; a_b := a_b->sortedBy($x | (lambda x : OclAny in (x[1+1]))->apply($x)) ; var time_space : int := 0 ; for i : Integer.subrange(0, (a_b)->size()-1) do ( if i = 0 then ( time_space := a_b[i+1][1+1] - a_b[i+1]->first() ) else ( time_space := a_b[i+1][1+1] - a_b[i - 1+1][1+1] - a_b[i+1]->first() + time_space ) ; if time_space < 0 then ( execute ("No")->display() ; return ) else skip) ; execute ("Yes")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for _ in range(n): a,b=map(int,input().split()) c=a & b d=a ^ c e=b ^ c print(d+e) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : int := MathLib.bitwiseAnd(a, b) ; var d : int := MathLib.bitwiseXor(a, c) ; var e : int := MathLib.bitwiseXor(b, c) ; execute (d + e)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,radians from itertools import accumulate,permutations,combinations,product from operator import itemgetter,mul from copy import deepcopy from string import ascii_lowercase,ascii_uppercase,digits from bisect import bisect,bisect_left from fractions import gcd from heapq import heappush,heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) sys.setrecursionlimit(10**9) INF=float('inf') mod=10**9+7 N=INT() task=[LIST()for _ in range(N)] task=sorted(task,key=lambda x :(x[1],x[0])) task=[list(x)for x in zip(*task)] now_time=0 for i in range(N): now_time+=task[0][i] if now_time>task[1][i]: print("No") exit() print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var N : OclAny := INT() ; var task : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (LIST())) ; task := task->sortedBy($x | (lambda x : OclAny in (Sequence{x[1+1], x->first()}))->apply($x)) ; task := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name task)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name task)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name task)))))))`third->at(_indx)} )->select(x | true)->collect(x | ((x))) ; var now_time : int := 0 ; for i : Integer.subrange(0, N-1) do ( now_time := now_time + task->first()[i+1] ; if (now_time->compareTo(task[1+1][i+1])) > 0 then ( execute ("No")->display() ; exit() ) else skip) ; execute ("Yes")->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np import sys def InputToInt(): A=input().split() for i in range(len(A)): A[i]=int(A[i]) return A if __name__=='__main__' : N=int(input()) A=np.empty((N,2)) for i in range(N): A[i,:]=InputToInt() A=A[np.argsort(A[:,0])] A=A[np.argsort(A[:,1])] T=0 for i in range(N): T+=A[i,0] if T>A[i,1]: print('No') sys.exit() print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; A := MatrixLib.singleValueMatrix(Sequence{N, 2}, 0.0) ; for i : Integer.subrange(0, N-1) do ( A[i+1] := InputToInt()) ; A := A[+1] ; A := A[+1] ; var T : int := 0 ; for i : Integer.subrange(0, N-1) do ( T := T + A[i+1]->first() ; if (T->compareTo(A[i+1][1+1])) > 0 then ( execute ('No')->display() ; sys.exit() ) else skip) ; execute ('Yes')->display() ) else skip; operation InputToInt() : OclAny pre: true post: true activity: var A : OclAny := input().split() ; for i : Integer.subrange(0, (A)->size()-1) do ( A[i+1] := ("" + ((A[i+1])))->toInteger()) ; return A; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heappush,heappop n=int(input()) tasks=[] for _ in range(n): time,delivery=map(int,input().split()) heappush(tasks,(delivery,time)) now=0 for _ in range(n): delivery,time=heappop(tasks) now+=time if now>delivery : print("No") break else : print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var tasks : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var time : OclAny := null; var delivery : OclAny := null; Sequence{time,delivery} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; heappush(tasks, Sequence{delivery, time})) ; var now : int := 0 ; (compound_stmt for (exprlist (expr (atom (name _)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name delivery)))))) , (test (logical_test (comparison (expr (atom (name time))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name heappop)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name tasks)))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name now)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name time))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name now)))) > (comparison (expr (atom (name delivery))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "No"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Yes"))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from random import randint def printArr(arr,n): for i in range(n): print(arr[i],end=" "); def randomList(m,n): arr=[0]*m ; for i in range(n): arr[randint(0,n)% m]+=1 ; printArr(arr,m); if __name__=="__main__" : m=4 ; n=8 ; randomList(m,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( m := 4; n := 8; ; randomList(m, n); ) else skip; operation printArr(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display();); operation randomList(m : OclAny, n : OclAny) pre: true post: true activity: arr := MatrixLib.elementwiseMult(Sequence{ 0 }, m); ; for i : Integer.subrange(0, n-1) do ( arr[randint(0, n) mod m+1] := arr[randint(0, n) mod m+1] + 1;) ; printArr(arr, m);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- prefix=list() suffix=list() n,k,x=input().split() s=input().split() maxi=int(x)**int(k) prefix=[0]*(int(n)+1) suffix=[0]*(int(n)+1) for i in range(0,int(n)): prefix[i+1]=prefix[i]| int(s[i]) suffix[int(n)-1-i]=suffix[int(n)-i]| int(s[int(n)-1-i]) ans=0 for i in range(0,int(n)): ans=max(ans,prefix[i]| int(s[i])*maxi | suffix[i+1]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var prefix : Sequence := () ; var suffix : Sequence := () ; var n : OclAny := null; var k : OclAny := null; var x : OclAny := null; Sequence{n,k,x} := input().split() ; var s : OclAny := input().split() ; var maxi : double := (("" + ((x)))->toInteger())->pow(("" + ((k)))->toInteger()) ; prefix := MatrixLib.elementwiseMult(Sequence{ 0 }, (("" + ((n)))->toInteger() + 1)) ; suffix := MatrixLib.elementwiseMult(Sequence{ 0 }, (("" + ((n)))->toInteger() + 1)) ; for i : Integer.subrange(0, ("" + ((n)))->toInteger()-1) do ( prefix[i + 1+1] := MathLib.bitwiseOr(prefix[i+1], ("" + ((s[i+1])))->toInteger()) ; suffix[("" + ((n)))->toInteger() - 1 - i+1] := MathLib.bitwiseOr(suffix[("" + ((n)))->toInteger() - i+1], ("" + ((s[("" + ((n)))->toInteger() - 1 - i+1])))->toInteger())) ; var ans : int := 0 ; for i : Integer.subrange(0, ("" + ((n)))->toInteger()-1) do ( ans := Set{ans, MathLib.bitwiseOr(MathLib.bitwiseOr(prefix[i+1], ("" + ((s[i+1])))->toInteger() * maxi), suffix[i + 1+1])}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k,x=map(int,input().split()) *a,=map(int,input().split()) l=[0]*(n+1) r=[0]*(n+1) for i in range(0,n): l[i+1]=l[i]| a[i] r[n-i-1]=r[n-i]| a[n-i-1] num=x**k res=-1 for i in range(0,n): res=max(l[i]|(a[i]*num)| r[i+1],res) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var x : OclAny := null; Sequence{n,k,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (testlist_star_expr (star_expr * (expr (atom (name a)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name a)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var r : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(0, n-1) do ( l[i + 1+1] := MathLib.bitwiseOr(l[i+1], a[i+1]) ; r[n - i - 1+1] := MathLib.bitwiseOr(r[n - i+1], a[n - i - 1+1])) ; var num : double := (x)->pow(k) ; var res : int := -1 ; for i : Integer.subrange(0, n-1) do ( res := Set{MathLib.bitwiseOr(MathLib.bitwiseOr(l[i+1], (a[i+1] * num)), r[i + 1+1]), res}->max()) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,n=map(int,input().split()) seat=[list(input())for i in range(m)] dummy=["0" for i in range(n+2)] for i in range(m): seat[i].insert(0,"0") seat[i].append("0") seat.insert(0,dummy) seat.append(dummy) for i in range(1,m+1): for j in range(1,n+1): if seat[i][j]=="o" : if seat[i][j-1]=="-" : seat[i][j-1]="0" if seat[i][j+1]=="-" : seat[i][j+1]="0" elif seat[i][j]=="x" : for k in range(3): for l in range(3): if seat[i-1+k][j-1+l]=="-" : seat[i-1+k][j-1+l]="0" for i in range(n+1): if seat[1][i]=="-" : seat[1][i]="0" count=0 for i in seat : for j in i : if j=="-" : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var seat : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (((OclFile["System.in"]).readLine())->characters())) ; var dummy : Sequence := Integer.subrange(0, n + 2-1)->select(i | true)->collect(i | ("0")) ; for i : Integer.subrange(0, m-1) do ((expr (atom (name seat)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name insert) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom "0"))))))) )))) ; (expr (atom (name seat)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "0"))))))) ))))) ; seat := seat.insertAt(0+1, dummy) ; execute ((dummy) : seat) ; for i : Integer.subrange(1, m + 1-1) do ( for j : Integer.subrange(1, n + 1-1) do ( if seat[i+1][j+1] = "o" then ( if seat[i+1][j - 1+1] = "-" then ( seat[i+1][j - 1+1] := "0" ) else skip ; if seat[i+1][j + 1+1] = "-" then ( seat[i+1][j + 1+1] := "0" ) else skip ) else (if seat[i+1][j+1] = "x" then ( for k : Integer.subrange(0, 3-1) do ( for l : Integer.subrange(0, 3-1) do ( if seat[i - 1 + k+1][j - 1 + l+1] = "-" then ( seat[i - 1 + k+1][j - 1 + l+1] := "0" ) else skip)) ) else skip))) ; for i : Integer.subrange(0, n + 1-1) do ( if seat[1+1][i+1] = "-" then ( seat[1+1][i+1] := "0" ) else skip) ; var count : int := 0 ; for i : seat do ( for j : i do ( if j = "-" then ( count := count + 1 ) else skip)) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import(division,absolute_import,print_function,unicode_literals) from sys import stdin for line in stdin : a,b,n=(int(s)for s in line.split()) result=0 for i in xrange(1,n+1): result+=(a*(10**i)//b)% 10 print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for line : stdin do ( var a : OclAny := null; var b : OclAny := null; var n : OclAny := null; Sequence{a,b,n} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name line)) (trailer . (name split) (arguments ( ))))))))} ; var result : int := 0 ; for i : xrange(1, n + 1) do ( result := result + (a * ((10)->pow(i)) div b) mod 10) ; execute (result)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,n=map(int,input().split()) mp=[list("#"*(n+2))]+[list("#"+input()+"#")for _ in range(m)]+[list("#"*(n+2))] vec=((1,0),(1,-1),(0,-1),(-1,-1),(-1,0),(-1,1),(0,1),(1,1)) for y in range(1,m+1): for x in range(1,n+1): if mp[y][x]=="x" : for dx,dy in vec : if mp[y+dy][x+dx]=="-" : mp[y+dy][x+dx]="#" if mp[y][x]=="o" : if mp[y][x-1]=="-" : mp[y][x-1]="#" if mp[y][x+1]=="-" : mp[y][x+1]="#" for x in range(1,n+1): if mp[1][x]=="-" : mp[1][x]="#" print(sum([line.count("-")for line in mp])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mp : Sequence := Sequence{ (StringLib.nCopies("#", (n + 2)))->characters() }->union(Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (("#" + (OclFile["System.in"]).readLine() + "#")->characters())))->union(Sequence{ (StringLib.nCopies("#", (n + 2)))->characters() }) ; var vec : OclAny := Sequence{Sequence{1, 0}, Sequence{1, -1}, Sequence{0, -1}, Sequence{-1, -1}, Sequence{-1, 0}, Sequence{-1, 1}, Sequence{0, 1}, Sequence{1, 1}} ; for y : Integer.subrange(1, m + 1-1) do ( for x : Integer.subrange(1, n + 1-1) do ( if mp[y+1][x+1] = "x" then ( for _tuple : vec do (var _indx : int := 1; var dx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dy : OclAny := _tuple->at(_indx); if mp[y + dy+1][x + dx+1] = "-" then ( mp[y + dy+1][x + dx+1] := "#" ) else skip) ) else skip ; if mp[y+1][x+1] = "o" then ( if mp[y+1][x - 1+1] = "-" then ( mp[y+1][x - 1+1] := "#" ) else skip ; if mp[y+1][x + 1+1] = "-" then ( mp[y+1][x + 1+1] := "#" ) else skip ) else skip)) ; for x : Integer.subrange(1, n + 1-1) do ( if mp[1+1][x+1] = "-" then ( mp[1+1][x+1] := "#" ) else skip) ; execute ((mp->select(line | true)->collect(line | (line->count("-"))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPowerOf2(sttr): len_str=len(sttr); sttr=list(sttr); num=0 ; if(len_str==1 and sttr[len_str-1]=='1'): return 0 ; while(len_str!=1 or sttr[len_str-1]!='1'): if((ord(sttr[len_str-1])-ord('0'))% 2==1): return 0 ; j=0 ; for i in range(len_str): num=num*10+(ord(sttr[i])-ord('0')); if(num<2): if(i!=0): sttr[j]='0' ; j+=1 ; continue ; sttr[j]=chr((num//2)+ord('0')); j+=1 ; num=(num)-(num//2)*2 ; len_str=j ; return 1 ; str1="124684622466842024680246842024662202000002" ; str2="1" ; str3="128" ; print("",isPowerOf2(str1),"\n",isPowerOf2(str2),"\n",isPowerOf2(str3)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var str1 : String := "124684622466842024680246842024662202000002"; ; var str2 : String := "1"; ; var str3 : String := "128"; ; execute ("")->display();; operation isPowerOf2(sttr : OclAny) pre: true post: true activity: var len_str : int := (sttr)->size(); ; sttr := (sttr); ; var num : int := 0; ; if (len_str = 1 & sttr[len_str - 1+1] = '1') then ( return 0; ) else skip ; while (len_str /= 1 or sttr[len_str - 1+1] /= '1') do ( if (((sttr[len_str - 1+1])->char2byte() - ('0')->char2byte()) mod 2 = 1) then ( return 0; ) else skip ; var j : int := 0; ; for i : Integer.subrange(0, len_str-1) do ( num := num * 10 + ((sttr[i+1])->char2byte() - ('0')->char2byte()); ; if (num < 2) then ( if (i /= 0) then ( sttr[j+1] := '0'; ; j := j + 1; ) else skip ; continue; ) else skip ; sttr[j+1] := ((num div 2) + ('0')->char2byte())->byte2char(); ; j := j + 1; ; num := (num) - (num div 2) * 2;) ; len_str := j;) ; return 1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def printAnagramsTogether(words): groupedWords=defaultdict(list) for word in words : groupedWords["".join(sorted(word))].append(word) for group in groupedWords.values(): print(" ".join(group)) if __name__=="__main__" : arr=["cat","dog","tac","god","act"] printAnagramsTogether(arr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var arr : Sequence := Sequence{"cat"}->union(Sequence{"dog"}->union(Sequence{"tac"}->union(Sequence{"god"}->union(Sequence{ "act" })))) ; printAnagramsTogether(arr) ) else skip; operation printAnagramsTogether(words : OclAny) pre: true post: true activity: var groupedWords : OclAny := defaultdict(OclType["Sequence"]) ; for word : words do ((expr (atom (name groupedWords)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom "") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name word)))))))) ))))))))) ))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name word)))))))) ))))) ; for group : groupedWords.values() do ( execute (StringLib.sumStringsWithSeparator((group), " "))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n<=6 : print(1) elif n<=11 : print(2) else : print(n//11*2+(n % 11+5)//6) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n <= 6 then ( execute (1)->display() ) else (if n <= 11 then ( execute (2)->display() ) else ( execute (n div 11 * 2 + (n mod 11 + 5) div 6)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,k=map(int,input().split()) valid=[str(i)for i in range(0,k+1)] count1=0 for _ in range(m): count2=0 a=input() b=[i for i in a] for i in valid : if i in b : count2+=1 if len(valid)==count2 : count1+=1 print(count1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var k : OclAny := null; Sequence{m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var valid : Sequence := Integer.subrange(0, k + 1-1)->select(i | true)->collect(i | (("" + ((i))))) ; var count1 : int := 0 ; for _anon : Integer.subrange(0, m-1) do ( var count2 : int := 0 ; var a : String := (OclFile["System.in"]).readLine() ; var b : Sequence := a->characters()->select(i | true)->collect(i | (i)) ; for i : valid do ( if (b)->includes(i) then ( count2 := count2 + 1 ) else skip) ; if (valid)->size() = count2 then ( count1 := count1 + 1 ) else skip) ; execute (count1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import gcd def inp(): return sys.stdin.readline().strip() def get_ints(): return map(int,inp().split()) def get_arr(): return list(map(int,inp().split())) def get_int(): return int(inp()) n,k=get_ints() count=0 for _ in range(n): s=inp() val=0 for i in range(k+1): if(s.find(str(i))!=-1): val+=1 if(val==k+1): count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := get_ints() ; var count : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var s : OclAny := inp() ; var val : int := 0 ; for i : Integer.subrange(0, k + 1-1) do ( if (s->indexOf(("" + ((i)))) - 1 /= -1) then ( val := val + 1 ) else skip) ; if (val = k + 1) then ( count := count + 1 ) else skip) ; execute (count)->display(); operation inp() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation get_ints() : OclAny pre: true post: true activity: return (inp().split())->collect( _x | (OclType["int"])->apply(_x) ); operation get_arr() : OclAny pre: true post: true activity: return ((inp().split())->collect( _x | (OclType["int"])->apply(_x) )); operation get_int() : OclAny pre: true post: true activity: return ("" + ((inp())))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) count=0 for _ in range(n): s=input() val=0 for i in range(k+1): if str(i)in s : val+=1 if val==k+1 : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var count : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var val : int := 0 ; for i : Integer.subrange(0, k + 1-1) do ( if (s)->characters()->includes(("" + ((i)))) then ( val := val + 1 ) else skip) ; if val = k + 1 then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=0 ; d={} x,y=map(int,input().split()) for i in range(x): z=input() if z not in d.keys(): for i in range(y+1): if str(i)not in z : d[z]=0 break else : c+=1 d[z]=1 else : c+=d[z] print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : int := 0; var d : OclAny := Set{} ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, x-1) do ( var z : String := (OclFile["System.in"]).readLine() ; if (d.keys())->excludes(z) then ( (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name y))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) not in (comparison (expr (atom (name z))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name z)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name z)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))))) ) else ( c := c + d->at(z) )) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=[int(n)for n in input().split()] list=[]; c=0 ; s=0 ; for i in range(n): list.append(input()) for number in list : if len(number)>k : for i in range(k+1): if str(i)in number : c+=1 if c==k+1 : s=s+1 c=0 print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; var OclType["Sequence"] : Sequence := Sequence{}; var c : int := 0; var s : int := 0; ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : OclType["Sequence"])) ; for number : OclType["Sequence"] do ( if ((number)->size()->compareTo(k)) > 0 then ( for i : Integer.subrange(0, k + 1-1) do ( if (number)->includes(("" + ((i)))) then ( c := c + 1 ) else skip) ; if c = k + 1 then ( s := s + 1 ) else skip ; c := 0 ) else skip) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[0]*n b=[0]*n m=set() for i in range(n): a[i],b[i]=map(int,input().split()) for i in range(n): for j in range(n): if b[i]==a[j]and i!=j : m.add(j) print(n-len(m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var m : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( var a[i+1] : OclAny := null; var b[i+1] : OclAny := null; Sequence{a[i+1],b[i+1]} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if b[i+1] = a[j+1] & i /= j then ( execute ((j) : m) ) else skip)) ; execute (n - (m)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=[int(a)for a in input().split()] def chk(k): if k==1 : for i in range(1,N): if A[i]<=A[i-1]: return 0 return 1 X=[(0,0)] def add(x,y): if x<=0 : return 0 if x>X[-1][0]: X.append((x,0 if x==y else 1)) elif x==X[-1][0]: if X[-1][1]+1x : X.pop() if x>X[-1][0]: X.append((x,1)) elif x==X[-1][0]: if X[-1][1]+11 : m=(l+r)//2 if chk(m): r=m else : l=m print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; skip ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,1 * (2->pow(18))} ; while r - l > 1 do ( var m : int := (l + r) div 2 ; if chk(m) then ( var r : int := m ) else ( var l : int := m )) ; execute (r)->display(); operation chk(k : OclAny) : OclAny pre: true post: true activity: if k = 1 then ( for i : Integer.subrange(1, N-1) do ( if (A[i+1]->compareTo(A[i - 1+1])) <= 0 then ( return 0 ) else skip) ; return 1 ) else skip ; var X : Sequence := Sequence{ Sequence{0, 0} } ; skip ; for a : A do ( if add(a, a) = 0 then ( return 0 ) else skip) ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=[] brr=[] for _ in range(n): a,b=map(int,input().split()) arr.append(a) brr.append(b) for i in range(n): if(arr[i]in brr[: i]or arr[i]in brr[i+1 :]): n-=1 else : continue print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Sequence{} ; var brr : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a) : arr) ; execute ((b) : brr)) ; for i : Integer.subrange(0, n-1) do ( if ((brr.subrange(1,i))->includes(arr[i+1]) or (brr.subrange(i + 1+1))->includes(arr[i+1])) then ( n := n - 1 ) else ( continue )) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) brand={} opened={} for _ in range(n): a,b=map(int,input().split()) brand[a]=brand.get(a,0)+1 if a!=b : opened[b]=1 else : if opened.get(b,0)==0 : opened[b]=2 elif opened.get(b,0)==2 : opened[b]=3 s=0 for i in brand : if opened.get(i,0)==0 : s+=brand[i] elif opened.get(i,0)==2 : if brand[i]>=1 : s+=1 print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var brand : OclAny := Set{} ; var opened : OclAny := Set{} ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; brand[a+1] := brand.get(a, 0) + 1 ; if a /= b then ( opened[b+1] := 1 ) else ( if opened.get(b, 0) = 0 then ( opened[b+1] := 2 ) else (if opened.get(b, 0) = 2 then ( opened[b+1] := 3 ) else skip) )) ; var s : int := 0 ; for i : brand do ( if opened.get(i, 0) = 0 then ( s := s + brand[i+1] ) else (if opened.get(i, 0) = 2 then ( if brand[i+1] >= 1 then ( s := s + 1 ) else skip ) else skip)) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[] for _ in range(n): a.append(list(map(int,input().split()))) removed=set() res=n for i in range(n): for j in range(n): if a[i][1]==a[j][0]and i!=j and j not in removed : removed.add(j) res-=1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : a)) ; var removed : Set := Set{}->union(()) ; var res : int := n ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if a[i+1][1+1] = a[j+1]->first() & i /= j & (removed)->excludes(j) then ( execute ((j) : removed) ; res := res - 1 ) else skip)) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter def solve(a,b): n=len(a) ans=0 for i in range(n): openable=False for j in range(n): if i==j : continue if a[i]==b[j]: openable=True break if not openable : ans+=1 return ans a,b=[],[] for _ in range(int(input())): x,y=[int(i)for i in input().split()] a.append(x) b.append(y) print(solve(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{a,b} := Sequence{Sequence{},Sequence{}} ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute ((x) : a) ; execute ((y) : b)) ; execute (solve(a, b))->display(); operation solve(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var n : int := (a)->size() ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var openable : boolean := false ; for j : Integer.subrange(0, n-1) do ( if i = j then ( continue ) else skip ; if a[i+1] = b[j+1] then ( openable := true ; break ) else skip) ; if not(openable) then ( ans := ans + 1 ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) s=input() if n==1 : print(s.lower()) elif k==1 : print(s[0].lower()+s[1 :]) elif k==n : print(s[: n-1]+s[n-1].lower()) else : print(s[: k-1]+s[k-1].lower()+s[k :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; if n = 1 then ( execute (s->toLowerCase())->display() ) else (if k = 1 then ( execute (s->first()->toLowerCase() + s->tail())->display() ) else (if k = n then ( execute (s.subrange(1,n - 1) + s[n - 1+1]->toLowerCase())->display() ) else ( execute (s.subrange(1,k - 1) + s[k - 1+1]->toLowerCase() + s.subrange(k+1))->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def inpl(): return list(map(int,input().split())) x=int(input()) res=0 res+=(x//11)*2 if x % 11>6 : res+=2 elif x % 11>0 : res+=1 else : res+=0 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : int := 0 ; res := res + (x div 11) * 2 ; if x mod 11 > 6 then ( res := res + 2 ) else (if x mod 11 > 0 then ( res := res + 1 ) else ( res := res + 0 ) ) ; execute (res)->display(); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) print('ABC'+str(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ('ABC' + ("" + ((N))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print("ABC"+str(input())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ("ABC" + ("" + (((OclFile["System.in"]).readLine()))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() ans="ABC"+S print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var ans : String := "ABC" + S ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=input() print('ABC'+'0'*(3-len(N))+N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : String := (OclFile["System.in"]).readLine() ; execute ('ABC' + StringLib.nCopies('0', (3 - (N)->size())) + N)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(aaa): l=1 r=200000 while l=a : if not carry(d,word,a): return False for i in list(word.keys()): if a0 : if i in word : if word[i]toInteger() ; aaa := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (solve(aaa))->display(); operation solve(aaa : OclAny) : OclAny pre: true post: true activity: var l : int := 1 ; var r : int := 200000 ; while (l->compareTo(r)) < 0 do ( var m : int := (l + r) div 2 ; if check(m, aaa) then ( r := m ) else ( l := m + 1 )) ; return r; operation check(d : OclAny, aaa : OclAny) : OclAny pre: true post: true activity: if d = 1 then ( return ((argument (test (logical_test (comparison (comparison (expr (atom (name a1)))) < (comparison (expr (atom (name a2))))))) (comp_for for (exprlist (expr (atom (name a1))) , (expr (atom (name a2)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name aaa))))))) , (argument (test (logical_test (comparison (expr (atom (name aaa)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))))))) )))))))))->forAll( _x | _x = true ) ) else skip ; l := 0 ; var word : OclAny := Set{} ; for a : aaa do ( if (l->compareTo(a)) >= 0 then ( if not(carry(d, word, a)) then ( return false ) else skip ; for i : (word.keys()) do ( if (a->compareTo(i)) < 0 then ( execute (word[i+1])->isDeleted() ) else skip) ) else skip ; l := a) ; return true; operation carry(d : OclAny, word : OclAny, i : OclAny) : OclAny pre: true post: true activity: while i > 0 do ( if (word)->includes(i) then ( if (word[i+1]->compareTo(d)) < 0 then ( word[i+1] := word[i+1] + 1 ; return true ) else skip ; execute (word[i+1])->isDeleted() ) else ( word[i+1] := 2 ; return true ) ; i := i - 1) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=str(input()) print('ABC{0}'.format(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : String := ("" + (((OclFile["System.in"]).readLine()))) ; execute (StringLib.interpolateStrings('ABC{0}', Sequence{N}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,gcd def printArr(arr,n): for i in range(n): print(arr[i],end=" ") def findNumbers(arr,n): arr.sort(reverse=True) freq=[0 for i in range(arr[0]+1)] for i in range(n): freq[arr[i]]+=1 size=int(sqrt(n)) brr=[0 for i in range(len(arr))] l=0 for i in range(n): if(freq[arr[i]]>0): brr[l]=arr[i] freq[brr[l]]-=1 l+=1 for j in range(l): if(i!=j): x=gcd(arr[i],brr[j]) freq[x]-=2 printArr(brr,size) if __name__=='__main__' : arr=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,5,5,7,10,12,2,2] n=len(arr) findNumbers(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{5}->union(Sequence{5}->union(Sequence{5}->union(Sequence{7}->union(Sequence{10}->union(Sequence{12}->union(Sequence{2}->union(Sequence{ 2 })))))))))))))))))))))))) ; n := (arr)->size() ; findNumbers(arr, n) ) else skip; operation printArr(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); operation findNumbers(arr : OclAny, n : OclAny) pre: true post: true activity: arr := arr->sort() ; var freq : Sequence := Integer.subrange(0, arr->first() + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( freq[arr[i+1]+1] := freq[arr[i+1]+1] + 1) ; var size : int := ("" + ((sqrt(n))))->toInteger() ; var brr : Sequence := Integer.subrange(0, (arr)->size()-1)->select(i | true)->collect(i | (0)) ; var l : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (freq[arr[i+1]+1] > 0) then ( brr[l+1] := arr[i+1] ; freq[brr[l+1]+1] := freq[brr[l+1]+1] - 1 ; l := l + 1 ; for j : Integer.subrange(0, l-1) do ( if (i /= j) then ( var x : OclAny := gcd(arr[i+1], brr[j+1]) ; freq[x+1] := freq[x+1] - 2 ) else skip) ) else skip) ; printArr(brr, size); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd for _ in range(int(input())): n=int(input()) while gcd(n,sum([ord(i)-ord('0')for i in str(n)]))==1 : n+=1 print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while gcd(n, (("" + ((n)))->select(i | true)->collect(i | ((i)->char2byte() - ('0')->char2byte())))->sum()) = 1 do ( n := n + 1) ; execute (n)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math t=int(input()) for i in range(t): n=int(input()) for i in range(n,n+10): s=str(i) c=0 for j in range(len(s)): c+=int(s[j]) k=math.gcd(i,c) if k>1 : print(i) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(n, n + 10-1) do ( var s : String := ("" + ((i))) ; var c : int := 0 ; for j : Integer.subrange(0, (s)->size()-1) do ( c := c + ("" + ((s[j+1])))->toInteger()) ; var k : long := (i)->gcd(c) ; if k > 1 then ( execute (i)->display() ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math t=int(input()) for l in range(t): n=int(input()) nl=str(n) nls=0 for l in nl : nls+=int(l) cnt=0 if math.gcd(n,nls)>1 : cnt=1 while cnt==0 : gcdsum=math.gcd(n,nls) if gcdsum<=1 : n+=1 else : cnt=1 nl=str(n) nls=0 for l in nl : nls+=int(l) print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for l : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nl : String := ("" + ((n))) ; var nls : int := 0 ; for l : nl->characters() do ( nls := nls + ("" + ((l)))->toInteger()) ; var cnt : int := 0 ; if (n)->gcd(nls) > 1 then ( cnt := 1 ) else skip ; while cnt = 0 do ( var gcdsum : long := (n)->gcd(nls) ; if gcdsum <= 1 then ( n := n + 1 ) else ( cnt := 1 ) ; nl := ("" + ((n))) ; nls := 0 ; for l : nl->characters() do ( nls := nls + ("" + ((l)))->toInteger())) ; execute (n)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for s in[*open(0)][1 :]: n=int(s) while math.gcd(n,sum(map(int,str(n))))<2 : n+=1 print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var n : int := ("" + ((s)))->toInteger() ; while (n)->gcd(((("" + ((n))))->collect( _x | (OclType["int"])->apply(_x) ))->sum()) < 2 do ( n := n + 1) ; execute (n)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) q,mod=divmod(N,11) q*=2 ans=0 if mod==0 : ans=q elif 1<=mod<=6 : ans=q+1 else : ans=q+2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var q : OclAny := null; var mod : OclAny := null; Sequence{q,mod} := Sequence{(N div 11), (N mod 11)} ; q := q * 2 ; var ans : int := 0 ; if mod = 0 then ( ans := q ) else (if 1 <= mod & (mod <= 6) then ( ans := q + 1 ) else ( ans := q + 2 ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) for i in range(n): x=int(input()) while(True): s=str(x) l=list(map(int,s.strip())) if(math.gcd(x,sum(l))>1): print(x) break else : x+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (true) do ( var s : String := ("" + ((x))) ; var l : Sequence := ((s->trim())->collect( _x | (OclType["int"])->apply(_x) )) ; if ((x)->gcd((l)->sum()) > 1) then ( execute (x)->display() ; break ) else ( x := x + 1 ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printAllSubsetsRec(arr,n,v,sum): if(sum==0): for value in v : print(value,end=" ") print() return if(n==0): return printAllSubsetsRec(arr,n-1,v,sum) v1=[]+v v1.append(arr[n-1]) printAllSubsetsRec(arr,n-1,v1,sum-arr[n-1]) def printAllSubsets(arr,n,sum): v=[] printAllSubsetsRec(arr,n,v,sum) arr=[2,5,8,4,6,11] sum=13 n=len(arr) printAllSubsets(arr,n,sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{2}->union(Sequence{5}->union(Sequence{8}->union(Sequence{4}->union(Sequence{6}->union(Sequence{ 11 }))))) ; sum := 13 ; n := (arr)->size() ; printAllSubsets(arr, n, sum); operation printAllSubsetsRec(arr : OclAny, n : OclAny, v : OclAny, sum : OclAny) pre: true post: true activity: if (sum = 0) then ( for value : v do ( execute (value)->display()) ; execute (->display() ; return ) else skip ; if (n = 0) then ( return ) else skip ; printAllSubsetsRec(arr, n - 1, v, sum) ; var v1 : Sequence := Sequence{}->union(v) ; execute ((arr[n - 1+1]) : v1) ; printAllSubsetsRec(arr, n - 1, v1, sum - arr[n - 1+1]); operation printAllSubsets(arr : OclAny, n : OclAny, sum : OclAny) pre: true post: true activity: v := Sequence{} ; printAllSubsetsRec(arr, n, v, sum); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(["No","Yes"]["7" in input()]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (Sequence{"No"}->union(Sequence{ "Yes" })->select(((OclFile["System.in"]).readLine())->includes("7")))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np import itertools N,M=[int(i)for i in input().split(" ")] k_dict={} for i in range(M): _in=[int(j)-1 for j in input().split(" ")] k=_in[0] s=_in[1 : :] k_dict[i]=s p=np.asarray([int(i)for i in input().split(" ")]) def _switch(pattern): lamps=np.zeros(M) for i,pat in enumerate(pattern): if pat==0 : continue for key in k_dict : if i in k_dict[key]: lamps[key]+=1 return np.sum(lamps % 2==p)==M retval=0 for i in itertools.product([0,1],repeat=N): retval+=_switch(i) print(retval) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var k_dict : OclAny := Set{} ; for i : Integer.subrange(0, M-1) do ( var _in : Sequence := input().split(" ")->select(j | true)->collect(j | (("" + ((j)))->toInteger() - 1)) ; var k : OclAny := _in->first() ; var s : OclAny := _in(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop :)) ; k_dict[i+1] := s) ; var p : Sequence := ; skip ; var retval : int := 0 ; for i : itertools.product(Sequence{0}->union(Sequence{ 1 }), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (name N)))))))) do ( retval := retval + _switch(i)) ; execute (retval)->display(); operation _switch(pattern : OclAny) : OclAny pre: true post: true activity: var lamps : Sequence := MatrixLib.singleValueMatrix(M, 0.0) ; for _tuple : Integer.subrange(1, (pattern)->size())->collect( _indx | Sequence{_indx-1, (pattern)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var pat : OclAny := _tuple->at(_indx); if pat = 0 then ( continue ) else skip ; for key : k_dict do ( if (k_dict[key+1])->includes(i) then ( lamps[key+1] := lamps[key+1] + 1 ) else skip)) ; return MatrixLib.sumMatrix(lamps mod 2 = p) = M; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin inf=1<<60 mod=1000000007 ni=lambda : int(ns()) nin=lambda y :[ni()for _ in range(y)] na=lambda : list(map(int,stdin.readline().split())) nan=lambda y :[na()for _ in range(y)] nf=lambda : float(ns()) nfn=lambda y :[nf()for _ in range(y)] nfa=lambda : list(map(float,stdin.readline().split())) nfan=lambda y :[nfa()for _ in range(y)] ns=lambda : stdin.readline().rstrip() nsn=lambda y :[ns()for _ in range(y)] ncl=lambda y :[list(ns())for _ in range(y)] nas=lambda : stdin.readline().split() n=ns() flag=False for i in range(3): if n[i]=='7' : flag=True print("Yes" if flag else "No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stdin : OclFile := OclFile["System.in"] ; var Math_PINFINITY : int := 1 * (2->pow(60)) ; var mod : int := 1000000007 ; var ni : Function := lambda $$ : OclAny in (("" + ((ns())))->toInteger()) ; var nin : Function := lambda y : OclAny in (Integer.subrange(0, y-1)->select(_anon | true)->collect(_anon | (ni->apply()))) ; var na : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var Math_NaN : Function := lambda y : OclAny in (Integer.subrange(0, y-1)->select(_anon | true)->collect(_anon | (na->apply()))) ; var nf : Function := lambda $$ : OclAny in (("" + ((ns())))->toReal()) ; var nfn : Function := lambda y : OclAny in (Integer.subrange(0, y-1)->select(_anon | true)->collect(_anon | (nf->apply()))) ; var nfa : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ))) ; var nfan : Function := lambda y : OclAny in (Integer.subrange(0, y-1)->select(_anon | true)->collect(_anon | (nfa->apply()))) ; var ns : Function := lambda $$ : OclAny in (stdin.readLine().rstrip()) ; var nsn : Function := lambda y : OclAny in (Integer.subrange(0, y-1)->select(_anon | true)->collect(_anon | (ns->apply()))) ; var ncl : Function := lambda y : OclAny in (Integer.subrange(0, y-1)->select(_anon | true)->collect(_anon | ((ns->apply())))) ; var nas : Function := lambda $$ : OclAny in (stdin.readLine().split()) ; var n : OclAny := ns->apply() ; var flag : boolean := false ; for i : Integer.subrange(0, 3-1) do ( if n[i+1] = '7' then ( flag := true ) else skip) ; execute (if flag then "Yes" else "No" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INT=lambda : int(input()) INTM=lambda : map(int,input().split()) STRM=lambda : map(str,input().split()) STR=lambda : str(input()) LIST=lambda : list(map(int,input().split())) LISTS=lambda : list(map(str,input().split())) def do(): s=STR() if '7' in s : print('Yes') else : print('No') if __name__=='__main__' : do() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INT : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var INTM : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var STRM : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["String"])->apply(_x) )) ; var STR : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))) ; var LIST : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var LISTS : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["String"])->apply(_x) ))) ; skip ; if __name__ = '__main__' then ( do() ) else skip; operation do() pre: true post: true activity: var s : OclAny := STR->apply() ; if (s)->includes('7') then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() flag="No" for i in n : if int(i)==7 : flag="Yes" break else : flag="No" print(flag) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var flag : String := "No" ; for i : n->characters() do ( if ("" + ((i)))->toInteger() = 7 then ( flag := "Yes" ; break ) else ( flag := "No" )) ; execute (flag)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() ans="No" if n[0 : 1]=="7" : ans="Yes" if n[1 : 2]=="7" : ans="Yes" if n[2 : 3]=="7" : ans="Yes" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var ans : String := "No" ; if n.subrange(0+1, 1) = "7" then ( ans := "Yes" ) else skip ; if n.subrange(1+1, 2) = "7" then ( ans := "Yes" ) else skip ; if n.subrange(2+1, 3) = "7" then ( ans := "Yes" ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def minMoves(n): s=str(n); ans=sys.maxsize ; len1=len(s); for i in range(len1): for j in range(len1): if(i==j): continue ; t=s ; cur=0 ; list1=list(t); for k in range(i,len1-1): e=list1[k]; list1[k]=list1[k+1]; list1[k+1]=e ; cur+=1 ; t=''.join(list1); list1=list(t); for k in range(j-(j>i),len1-2): e=list1[k]; list1[k]=list1[k+1]; list1[k+1]=e ; cur+=1 ; t=''.join(list1); pos=-1 ; for k in range(len1): if(t[k]!='0'): pos=k ; break ; for k in range(pos,0,-1): e=list1[k]; list1[k]=list1[k+1]; list1[k+1]=e ; cur+=1 ; t=''.join(list1); nn=int(t); if(nn % 25==0): ans=min(ans,cur); if(ans==sys.maxsize): return-1 ; return ans ; n=509201 ; print(minMoves(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 509201; ; execute (minMoves(n))->display();; operation minMoves(n : OclAny) pre: true post: true activity: var s : String := ("" + ((n))); ; var ans : (trailer . (name maxsize)) := (trailer . (name maxsize)); ; var len1 : int := (s)->size(); ; for i : Integer.subrange(0, len1-1) do ( for j : Integer.subrange(0, len1-1) do ( if (i = j) then ( continue; ) else skip ; var t : String := s; ; var cur : int := 0; ; var list1 : Sequence := (t)->characters(); ; for k : Integer.subrange(i, len1 - 1-1) do ( var e : OclAny := list1[k+1]; ; list1[k+1] := list1[k + 1+1]; ; list1[k + 1+1] := e; ; cur := cur + 1;) ; t := StringLib.sumStringsWithSeparator((list1), ''); ; list1 := (t)->characters(); ; for k : Integer.subrange(j - ((j->compareTo(i)) > 0), len1 - 2-1) do ( e := list1[k+1]; ; list1[k+1] := list1[k + 1+1]; ; list1[k + 1+1] := e; ; cur := cur + 1;) ; t := StringLib.sumStringsWithSeparator((list1), ''); ; var pos : int := -1; ; for k : Integer.subrange(0, len1-1) do ( if (t[k+1] /= '0') then ( pos := k; ; break; ) else skip) ; for k : Integer.subrange(0 + 1, pos)->reverse() do ( e := list1[k+1]; ; list1[k+1] := list1[k + 1+1]; ; list1[k + 1+1] := e; ; cur := cur + 1;) ; t := StringLib.sumStringsWithSeparator((list1), ''); ; var nn : int := ("" + ((t)))->toInteger(); ; if (nn mod 25 = 0) then ( ans := Set{ans, cur}->min(); ) else skip)) ; if (ans = (trailer . (name maxsize))) then ( return -1; ) else skip ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSubarrays(a,n,m): count=0 ; for i in range(n): odd=0 ; for j in range(i,n): if(a[j]% 2): odd+=1 ; if(odd==m): count+=1 ; return count ; a=[2,2,5,6,9,2,11]; n=len(a); m=2 ; print(countSubarrays(a,n,m)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{2}->union(Sequence{2}->union(Sequence{5}->union(Sequence{6}->union(Sequence{9}->union(Sequence{2}->union(Sequence{ 11 })))))); ; n := (a)->size(); ; m := 2; ; execute (countSubarrays(a, n, m))->display();; operation countSubarrays(a : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: var count : int := 0; ; for i : Integer.subrange(0, n-1) do ( var odd : int := 0; ; for j : Integer.subrange(i, n-1) do ( if (a[j+1] mod 2) then ( odd := odd + 1; ) else skip ; if (odd = m) then ( count := count + 1; ) else skip)) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSubarrays(a,n,m): count=0 prefix=[0]*n odd=0 for i in range(n): prefix[odd]+=1 if(a[i]& 1): odd+=1 if(odd>=m): count+=prefix[odd-m] return count a=[2,2,5,6,9,2,11] n=len(a) m=2 print(countSubarrays(a,n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{2}->union(Sequence{2}->union(Sequence{5}->union(Sequence{6}->union(Sequence{9}->union(Sequence{2}->union(Sequence{ 11 })))))) ; n := (a)->size() ; m := 2 ; execute (countSubarrays(a, n, m))->display(); operation countSubarrays(a : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var prefix : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var odd : int := 0 ; for i : Integer.subrange(0, n-1) do ( prefix[odd+1] := prefix[odd+1] + 1 ; if (MathLib.bitwiseAnd(a[i+1], 1)) then ( odd := odd + 1 ) else skip ; if ((odd->compareTo(m)) >= 0) then ( count := count + prefix[odd - m+1] ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys x=int(sys.stdin.readline()) n=x//11 r=x % 11 if r==0 : print(2*n) elif r<=6 : print(2*n+1) else : print(2*n+2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := x div 11 ; var r : int := x mod 11 ; if r = 0 then ( execute (2 * n)->display() ) else (if r <= 6 then ( execute (2 * n + 1)->display() ) else ( execute (2 * n + 2)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reverse(num): rev=0 ; while(num>0): rev=rev*10+num % 10 ; num=num//10 ; return rev ; def isPalindrome(num): if(num==reverse(num)): return True ; return False ; def printPalindromes(d): if(d<=0): return ; smallest=pow(10,d-1); largest=pow(10,d)-1 ; for i in range(smallest,largest+1): if(isPalindrome(i)): print(i,end=" "); d=2 ; printPalindromes(d); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; d := 2; ; printPalindromes(d);; operation reverse(num : OclAny) pre: true post: true activity: var rev : int := 0; ; while (num > 0) do ( rev := rev * 10 + num mod 10; ; num := num div 10;) ; return rev;; operation isPalindrome(num : OclAny) pre: true post: true activity: if (num = reverse(num)) then ( return true; ) else skip ; return false;; operation printPalindromes(d : OclAny) : OclAny pre: true post: true activity: if (d <= 0) then ( return; ) else skip ; var smallest : double := (10)->pow(d - 1); ; var largest : double := (10)->pow(d) - 1; ; for i : Integer.subrange(smallest, largest + 1-1) do ( if (isPalindrome(i)) then ( execute (i)->display(); ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush MOD=10**9+7 def solution(): a,b,c,d=map(int,input().split()) me=a/b he=c/d sum=0 for i in range(100000): sum+=me*((1-me)**i*(1-he)**i) i+=1 print(sum) def main(): t=1 for _ in range(t): solution() import sys import threading sys.setrecursionlimit(1<<30) threading.stack_size(1<<27) thread=threading.Thread(target=main) thread.start(); thread.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1 * (2->pow(30))) ; threading.stack_size(1 * (2->pow(27))) ; var thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ; thread.start(); thread.join(); operation solution() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var me : double := a / b ; var he : double := c / d ; var sum : int := 0 ; for i : Integer.subrange(0, 100000-1) do ( sum := sum + me * (((1 - me))->pow(i) * ((1 - he))->pow(i)) ; i := i + 1) ; execute (sum)->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import random input() A=[int(_)for _ in input().split()] A=[A[0]]+[j for i,j in zip(A,A[1 :])if i>=j] N=len(A) def cut(array,index): if index<1 : return[] if index<=array[0][0]: return[(index,array[0][1])] for _ in range(len(array)-1,0,-1): if array[_-1][0]select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; A := Sequence{ A->first() }->union(Integer.subrange(1, A->size())->collect( _indx | Sequence{A->at(_indx), A->tail()->at(_indx)} )->select(_tuple | let i : OclAny = _tuple->at(1) in let j : OclAny = _tuple->at(2) in (i->compareTo(j)) >= 0)->collect(_tuple | let i : OclAny = _tuple->at(1) in let j : OclAny = _tuple->at(2) in (j))) ; var N : int := (A)->size() ; skip ; skip ; skip ; execute (bis(0, N))->display(); operation cut(array : OclAny, index : OclAny) : OclAny pre: true post: true activity: if index < 1 then ( return Sequence{} ) else skip ; if (index->compareTo(array->first()->first())) <= 0 then ( return Sequence{ Sequence{index, array->first()[1+1]} } ) else skip ; for _anon : Integer.subrange(0 + 1, (array)->size() - 1)->reverse() do ( if (array[_anon - 1+1]->first()->compareTo(index)) < 0 then ( return array.subrange(1,_anon)->union(Sequence{ Sequence{index, array[_anon+1][1+1]} }) ) else skip); operation is_possible(K : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Sequence{ Sequence{A->first(), 0} } ; for a : A->tail() do ( if (a->compareTo(dp->last()->first())) <= 0 then ( dp := cut(dp, a) ) else ( dp := dp + Sequence{ Sequence{a, 0} } ) ; var is_added : boolean := false ; for j : Integer.subrange(-1 + 1, (dp)->size() - 1)->reverse() do ( if (dp[j+1][1+1]->compareTo(K - 1)) < 0 then ( dp := cut(dp, dp[j+1]->first() - 1)->union(Sequence{ Sequence{dp[j+1]->first(), dp[j+1][1+1] + 1} }) ; if (dp->last()->first()->compareTo(a)) < 0 then ( dp := dp + Sequence{ Sequence{a, 0} } ) else skip ; is_added := true ; break ) else skip) ; if not(is_added) then ( return false ) else skip) ; return true; operation bis(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if y = x + 1 then ( return y ) else (if is_possible((x + y) div 2) then ( return bis(x, (x + y) div 2) ) else ( return bis((x + y) div 2, y) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=map(int,input().split()) neg_a=(b-a)/b a=a/b neg_b=(d-c)/d neg_a_acc=1 neg_b_acc=1 res1=1 res2=a while abs(res2-res1)>=1e-12 : neg_a_acc*=neg_a neg_b_acc*=neg_b res1,res2=res2,res2+neg_a_acc*neg_b_acc*a print(res2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var neg_a : double := (b - a) / b ; var a : double := a / b ; var neg_b : double := (d - c) / d ; var neg_a_acc : int := 1 ; var neg_b_acc : int := 1 ; var res1 : int := 1 ; var res2 : OclAny := a ; while (res2 - res1)->abs() >= ("1e-12")->toReal() do ( neg_a_acc := neg_a_acc * neg_a ; neg_b_acc := neg_b_acc * neg_b ; Sequence{res1,res2} := Sequence{res2,res2 + neg_a_acc * neg_b_acc * a}) ; execute (res2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=map(int,input().split()) start=(1-a/b)*(1-c/d) current=start result=start+1 while current>0.000001 : current=current*start result+=current print(result*a/b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var start : double := (1 - a / b) * (1 - c / d) ; var current : OclAny := start ; var result : OclAny := start + 1 ; while current > 0.000001 do ( current := current * start ; result := result + current) ; execute (result * a / b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=map(int,input().split(" ")) print((a*d)/(b*c+a*d-a*c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a * d) / (b * c + a * d - a * c))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=map(int,input().split()) print((a/b)/(1-((1-(a/b))*(1-(c/d))))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a / b) / (1 - ((1 - (a / b)) * (1 - (c / d)))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isHalfReducible(arr,n,m): frequencyHash=[0]*(m+1); i=0 ; while(i=(n/2)): break ; i+=1 ; if(i<=m): print("Yes"); else : print("No"); arr=[8,16,32,3,12]; n=len(arr); m=7 ; isHalfReducible(arr,n,m); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{8}->union(Sequence{16}->union(Sequence{32}->union(Sequence{3}->union(Sequence{ 12 })))); ; n := (arr)->size(); ; m := 7; ; isHalfReducible(arr, n, m);; operation isHalfReducible(arr : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: var frequencyHash : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (m + 1)); ; var i : int := 0; ; while ((i->compareTo(n)) < 0) do ( frequencyHash[(arr[i+1] mod (m + 1))+1] := frequencyHash[(arr[i+1] mod (m + 1))+1] + 1; ; i := i + 1;) ; i := 0; ; while ((i->compareTo(m)) <= 0) do ( if ((frequencyHash[i+1]->compareTo((n / 2))) >= 0) then ( break; ) else skip ; i := i + 1;) ; if ((i->compareTo(m)) <= 0) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def findShortestSubArray(self,nums): left,right,count={},{},{} for i,x in enumerate(nums): if x not in left : left[x]=i right[x]=i count[x]=count.get(x,0)+1 ans=len(nums) degree=max(count.values()) for x in count : if count[x]==degree : ans=min(ans,right[x]-left[x]+1) return ans ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation findShortestSubArray(nums : OclAny) : OclAny pre: true post: true activity: var left : OclAny := null; var right : OclAny := null; var count : OclAny := null; Sequence{left,right,count} := Sequence{Set{},Set{},Set{}} ; for _tuple : Integer.subrange(1, (nums)->size())->collect( _indx | Sequence{_indx-1, (nums)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); if (left)->excludes(x) then ( left[x+1] := i ) else skip ; right[x+1] := i ; count[x+1] := count.get(x, 0) + 1) ; var ans : int := (nums)->size() ; var degree : OclAny := (count.values())->max() ; for x : count do ( if count[x+1] = degree then ( ans := Set{ans, right[x+1] - left[x+1] + 1}->min() ) else skip) ; return ans; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def possibleStrings(n,r,b,g): fact=[0 for i in range(n+1)] fact[0]=1 for i in range(1,n+1,1): fact[i]=fact[i-1]*i left=n-(r+g+b) sum=0 for i in range(0,left+1,1): for j in range(0,left-i+1,1): k=left-(i+j) sum=(sum+fact[n]/(fact[i+r]*fact[j+b]*fact[k+g])) return sum if __name__=='__main__' : n=4 r=2 b=0 g=1 print(int(possibleStrings(n,r,b,g))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 4 ; r := 2 ; b := 0 ; g := 1 ; execute (("" + ((possibleStrings(n, r, b, g))))->toInteger())->display() ) else skip; operation possibleStrings(n : OclAny, r : OclAny, b : OclAny, g : OclAny) : OclAny pre: true post: true activity: var fact : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; fact->first() := 1 ; for i : Integer.subrange(1, n + 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( fact[i+1] := fact[i - 1+1] * i) ; var left : double := n - (r + g + b) ; var sum : int := 0 ; for i : Integer.subrange(0, left + 1-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( for j : Integer.subrange(0, left - i + 1-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( var k : double := left - (i + j) ; sum := (sum + fact[n+1] / (fact[i + r+1] * fact[j + b+1] * fact[k + g+1])))) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def middlesum(mat,n): row_sum=0 col_sum=0 for i in range(n): row_sum+=mat[n//2][i] print("Sum of middle row=",row_sum) for i in range(n): col_sum+=mat[i][n//2] print("Sum of middle column=",col_sum) mat=[[2,5,7],[3,7,2],[5,6,9]] middlesum(mat,3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; mat := Sequence{Sequence{2}->union(Sequence{5}->union(Sequence{ 7 }))}->union(Sequence{Sequence{3}->union(Sequence{7}->union(Sequence{ 2 }))}->union(Sequence{ Sequence{5}->union(Sequence{6}->union(Sequence{ 9 })) })) ; middlesum(mat, 3); operation middlesum(mat : OclAny, n : OclAny) pre: true post: true activity: var row_sum : int := 0 ; var col_sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( row_sum := row_sum + mat[n div 2+1][i+1]) ; execute ("Sum of middle row=")->display() ; for i : Integer.subrange(0, n-1) do ( col_sum := col_sum + mat[i+1][n div 2+1]) ; execute ("Sum of middle column=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().rstrip() def pin(type=int): return map(type,input().split()) def tupin(t=int): return tuple(pin(t)) def resolve(): N,=pin() a,b=(N//11,N % 11) ans=a*2 if b>0 : ans+=1 if b>6 : ans+=1 print(ans) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; skip ; skip ; skip ; resolve(); operation pin(type : OclAny) : OclAny pre: true post: true activity: if type->oclIsUndefined() then type := OclType["int"] else skip; return (input->apply().split())->collect( _x | (type)->apply(_x) ); operation tupin(t : OclAny) : OclAny pre: true post: true activity: if t->oclIsUndefined() then t := OclType["int"] else skip; return (pin(t)); operation resolve() pre: true post: true activity: (testlist_star_expr (test (logical_test (comparison (expr (atom (name N)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name N)))))) ,)} := pin() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{N div 11, N mod 11} ; var ans : double := a * 2 ; if b > 0 then ( ans := ans + 1 ; if b > 6 then ( ans := ans + 1 ) else skip ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) x=list(map(int,input().split())) y=list(map(int,input().split())) d1=0 d2=0 d3=0 dmax=0 for i in range(n): d1+=abs(x[i]-y[i]) d2+=abs(x[i]-y[i])**2 d3+=abs(x[i]-y[i])**3 if dmaxtoInteger() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var y : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d1 : int := 0 ; var d2 : int := 0 ; var d3 : int := 0 ; var dmax : int := 0 ; for i : Integer.subrange(0, n-1) do ( d1 := d1 + (x[i+1] - y[i+1])->abs() ; d2 := d2 + ((x[i+1] - y[i+1])->abs())->pow(2) ; d3 := d3 + ((x[i+1] - y[i+1])->abs())->pow(3) ; if (dmax->compareTo((x[i+1] - y[i+1])->abs())) < 0 then ( dmax := (x[i+1] - y[i+1])->abs() ) else skip) ; execute (d1)->display() ; execute ((d2)->sqrt())->display() ; execute ((d3)->pow((1.0 / 3.0)))->display() ; execute (dmax)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A_raw=list(map(int,input().split())) flg=1 prev=0 A=[] for i in range(N): if A_raw[i]<=prev : flg=0 prev=A_raw[i] if A_raw[i]<=50 : A.append(A_raw[i]) if flg : print(1) exit() N=len(A) if N<=1 : print(2) exit() ok=N ng=1 mid=(ok+ng)//2 while ok-ng>1 : ng_flg=0 word=[1]*A[0] for i in range(1,N): if A[i]>A[i-1]: word.extend([1]*(A[i]-A[i-1])) else : word_prev=word[: A[i]] k=A[i]-1 while True : if k==-1 : ng_flg=1 break if word_prev[k]!=mid : word_prev[k]+=1 word=word_prev break else : word_prev[k]=1 k-=1 if ng_flg==1 : break if not ng_flg : ok=mid else : ng=mid mid=(ok+ng)//2 print(ok) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A_raw : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var flg : int := 1 ; var prev : int := 0 ; var A : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( if (A_raw[i+1]->compareTo(prev)) <= 0 then ( flg := 0 ) else skip ; prev := A_raw[i+1] ; if A_raw[i+1] <= 50 then ( execute ((A_raw[i+1]) : A) ) else skip) ; if flg then ( execute (1)->display() ; exit() ) else skip ; N := (A)->size() ; if N <= 1 then ( execute (2)->display() ; exit() ) else skip ; var ok : int := N ; var ng : int := 1 ; var mid : int := (ok + ng) div 2 ; while ok - ng > 1 do ( var ng_flg : int := 0 ; var word : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, A->first()) ; for i : Integer.subrange(1, N-1) do ( if (A[i+1]->compareTo(A[i - 1+1])) > 0 then ( word := word->union(MatrixLib.elementwiseMult(Sequence{ 1 }, (A[i+1] - A[i - 1+1]))) ) else ( var word_prev : OclAny := word.subrange(1,A[i+1]) ; var k : double := A[i+1] - 1 ; while true do ( if k = -1 then ( ng_flg := 1 ; break ) else skip ; if word_prev[k+1] /= mid then ( word_prev[k+1] := word_prev[k+1] + 1 ; word := word_prev ; break ) else ( word_prev[k+1] := 1 ; k := k - 1 )) ) ; if ng_flg = 1 then ( break ) else skip) ; if not(ng_flg) then ( ok := mid ) else ( ng := mid ) ; mid := (ok + ng) div 2) ; execute (ok)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) b1=[int(x)for x in input().split(' ')] b2=[int(x)for x in input().split(' ')] def c_minchov(x,y,p): b1,b2=x,y fsum=0 for i in range(len(b1)): fsum+=abs(b1[i]-b2[i])**p res=fsum**(1/p) return res def c_chebichev(x,y): b1,b2=x,y dis=[abs(b1[i]-b2[i])for i in range(len(b1))] res=max(dis) return res p1=c_minchov(b1,b2,1) p2=c_minchov(b1,b2,2) p3=c_minchov(b1,b2,3) p4=c_chebichev(b1,b2) print("{:.6f}".format(p1)) print("{:.6f}".format(p2)) print("{:.6f}".format(p3)) print("{:.6f}".format(p4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b1 : Sequence := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var b2 : Sequence := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; skip ; skip ; var p1 : OclAny := c_minchov(b1, b2, 1) ; var p2 : OclAny := c_minchov(b1, b2, 2) ; var p3 : OclAny := c_minchov(b1, b2, 3) ; var p4 : OclAny := c_chebichev(b1, b2) ; execute (StringLib.interpolateStrings("{:.6f}", Sequence{p1}))->display() ; execute (StringLib.interpolateStrings("{:.6f}", Sequence{p2}))->display() ; execute (StringLib.interpolateStrings("{:.6f}", Sequence{p3}))->display() ; execute (StringLib.interpolateStrings("{:.6f}", Sequence{p4}))->display(); operation c_minchov(x : OclAny, y : OclAny, p : OclAny) : OclAny pre: true post: true activity: Sequence{b1,b2} := Sequence{x,y} ; var fsum : int := 0 ; for i : Integer.subrange(0, (b1)->size()-1) do ( fsum := fsum + ((b1[i+1] - b2[i+1])->abs())->pow(p)) ; var res : double := (fsum)->pow((1 / p)) ; return res; operation c_chebichev(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: Sequence{b1,b2} := Sequence{x,y} ; var dis : Sequence := Integer.subrange(0, (b1)->size()-1)->select(i | true)->collect(i | ((b1[i+1] - b2[i+1])->abs())) ; res := (dis)->max() ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=[float(i)for i in input().split()] y=[float(i)for i in input().split()] dl=[abs(i-j)for(i,j)in zip(x,y)] for p in range(1,4): d=sum([i**p for i in dl])**(1/p) print("{:.8f}".format(d)) print("{:.8f}".format(max(dl))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toReal())) ; var y : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toReal())) ; var dl : Sequence := Integer.subrange(1, x->size())->collect( _indx | Sequence{x->at(_indx), y->at(_indx)} )->select(Sequence{i, j} | true)->collect(Sequence{i, j} | ((i - j)->abs())) ; for p : Integer.subrange(1, 4-1) do ( var d : double := ((dl->select(i | true)->collect(i | ((i)->pow(p))))->sum())->pow((1 / p)) ; execute (StringLib.interpolateStrings("{:.8f}", Sequence{d}))->display()) ; execute (StringLib.interpolateStrings("{:.8f}", Sequence{(dl)->max()}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def souhei(n): for w in range(n): a=list(map(int,input().split())) return(a) n=int(input()) A=souhei(n) B=souhei(n) P=[] for mm in range(1,5): del P[:] P=[] if mm==4 : for m in range(n): P.append(abs(A[m]-B[m])) p=max(P) else : for m in range(n): o=(abs(A[m]-B[m]))**mm P.append(o) p=sum(P) p=(p**(1/mm)) print('{:.5f}'.format(p)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : OclAny := souhei(n) ; var B : OclAny := souhei(n) ; var P : Sequence := Sequence{} ; for mm : Integer.subrange(1, 5-1) do ( execute (P)->isDeleted() ; P := Sequence{} ; if mm = 4 then ( for m : Integer.subrange(0, n-1) do ( execute (((A[m+1] - B[m+1])->abs()) : P) ; var p : OclAny := (P)->max()) ) else ( for m : Integer.subrange(0, n-1) do ( var o : double := (((A[m+1] - B[m+1])->abs()))->pow(mm) ; execute ((o) : P)) ; p := (P)->sum() ; p := ((p)->pow((1 / mm))) ) ; execute (StringLib.interpolateStrings('{:.5f}', Sequence{p}))->display()); operation souhei(n : OclAny) : OclAny pre: true post: true activity: for w : Integer.subrange(0, n-1) do ( var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; return (a)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=[0]+list(map(int,input().split())) y=[0]+list(map(int,input().split())) tmp=[[0 for i in range(3)]for j in range(n+1)] max=0 for i in range(1,n+1,1): absDiff=abs(x[i]-y[i]) tmp[i][0]+=tmp[i-1][0]+absDiff tmp[i][1]+=tmp[i-1][1]+absDiff**2 tmp[i][2]+=tmp[i-1][2]+absDiff**3 if absDiff>max : max=absDiff print(tmp[n][0]) print(tmp[n][1]**(1/2)) print(tmp[n][2]**(1/3)) print(max) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var y : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var tmp : Sequence := Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, 3-1)->select(i | true)->collect(i | (0)))) ; var max : int := 0 ; for i : Integer.subrange(1, n + 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( var absDiff : double := (x[i+1] - y[i+1])->abs() ; tmp[i+1]->first() := tmp[i+1]->first() + tmp[i - 1+1]->first() + absDiff ; tmp[i+1][1+1] := tmp[i+1][1+1] + tmp[i - 1+1][1+1] + (absDiff)->pow(2) ; tmp[i+1][2+1] := tmp[i+1][2+1] + tmp[i - 1+1][2+1] + (absDiff)->pow(3) ; if (absDiff->compareTo(max)) > 0 then ( max := absDiff ) else skip) ; execute (tmp[n+1]->first())->display() ; execute ((tmp[n+1][1+1])->pow((1 / 2)))->display() ; execute ((tmp[n+1][2+1])->pow((1 / 3)))->display() ; execute (max)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd n=int(input()) a=list(map(int,input().split())) d=a[0] for i in range(1,n): d=gcd(d,a[i]) a=list(map(lambda x : x//d,a)) print("Alice" if(max(a)-n)% 2==1 else "Bob") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := a->first() ; for i : Integer.subrange(1, n-1) do ( d := gcd(d, a[i+1])) ; a := ((a)->collect( _x | (lambda x : OclAny in (x div d))->apply(_x) )) ; execute (if ((a)->max() - n) mod 2 = 1 then "Alice" else "Bob" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import random from bisect import bisect_left as lb from bisect import bisect_right as rb from collections import deque from queue import PriorityQueue as pq from math import gcd input_=lambda : sys.stdin.readline().strip("\n") ii=lambda : int(input_()) il=lambda : list(map(int,input_().split())) ilf=lambda : list(map(float,input_().split())) lii=lambda : list(map(int,list(ip()))) ip=lambda : input_() fi=lambda : float(input_()) ap=lambda ab,bc,cd : ab[bc].append(cd) li=lambda : list(input_()) pr=lambda x : print(x) prinT=lambda x : print(x) f=lambda : sys.stdout.flush() inv=lambda x : pow(x,mod-2,mod) dx=[0,0,1,-1] dy=[1,-1,0,0] mod=10**9+7 mod1=998244353 n=ii() a=il() fl=0 for i in a : fl |=i % 2 t=0 if(fl): x=max(a) x-=n t=x else : g=0 for i in a : g=gcd(g,i) x=max(a)//g x-=n t=x if(t % 2): print("Alice") else : print("Bob") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var input_ : Function := lambda $$ : OclAny in (sys.stdin.readLine()->trim()) ; var ii : Function := lambda $$ : OclAny in (("" + ((input_->apply())))->toInteger()) ; var il : Function := lambda $$ : OclAny in (((input_->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ilf : Function := lambda $$ : OclAny in (((input_->apply().split())->collect( _x | (OclType["double"])->apply(_x) ))) ; var lii : Function := lambda $$ : OclAny in ((((ip()))->collect( _x | (OclType["int"])->apply(_x) ))) ; var ip : Function := lambda $$ : OclAny in (input_->apply()) ; var fi : Function := lambda $$ : OclAny in (("" + ((input_->apply())))->toReal()) ; var ap : Function := lambda ab : OclAny, bc : OclAny, cd : OclAny in (ab[bc+1].append(cd)) ; var li : Function := lambda $$ : OclAny in ((input_->apply())) ; var pr : Function := lambda x : OclAny in ((x)->display()) ; var prinT : Function := lambda x : OclAny in ((x)->display()) ; var f : Function := lambda $$ : OclAny in ((OclFile["System.out"]).flush()) ; var inv : Function := lambda x : OclAny in ((x)->pow(mod - 2)) ; var dx : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ -1 }))) ; var dy : Sequence := Sequence{1}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{ 0 }))) ; var mod : double := (10)->pow(9) + 7 ; var mod1 : int := 998244353 ; var n : OclAny := ii->apply() ; var a : OclAny := il->apply() ; var fl : int := 0 ; for i : a do ( fl := fl or i mod 2) ; var t : int := 0 ; if (fl) then ( var x : OclAny := (a)->max() ; x := x - n ; t := x ) else ( var g : int := 0 ; for i : a do ( g := gcd(g, i)) ; x := (a)->max() div g ; x := x - n ; t := x ) ; if (t mod 2) then ( execute ("Alice")->display() ) else ( execute ("Bob")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ciag=[int(x)for x in input().split()] naj=0 for i in range(n): if najtoInteger() ; var ciag : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var naj : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (naj->compareTo(ciag[i+1])) < 0 then ( naj := ciag[i+1] ) else skip) ; skip ; var wsz : OclAny := nwd(ciag[1+1], ciag->first()) ; for i : Integer.subrange(1, n-1) do ( wsz := nwd(wsz, ciag[i+1])) ; var wy : int := (naj div wsz - n) mod 2 ; if wy = 1 then ( execute ('Alice')->display() ) else ( execute ('Bob')->display() ); operation nwd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: while b /= 0 do ( Sequence{a,b} := Sequence{b,a mod b}) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d,e=map(int,input().split()) if a*b+2*dcollect( _x | (OclType["int"])->apply(_x) ) ; if (a * b + 2 * d->compareTo(a * c + 2 * e)) < 0 then ( execute ("First")->display() ) else ( if a * b + 2 * d /= a * c + 2 * e then ( execute ("Second")->display() ) else ( execute ("Friendship")->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input().split() s,v1,v2,t1,t2=int(n[0]),int(n[1]),int(n[2]),int(n[3]),int(n[4]) if s*v1+2*t1s*v2+2*t2 : print('Second') if s*v1+2*t1==s*v2+2*t2 : print('Friendship') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := input().split() ; var s : OclAny := null; var v1 : OclAny := null; var v2 : OclAny := null; var t1 : OclAny := null; var t2 : OclAny := null; Sequence{s,v1,v2,t1,t2} := Sequence{("" + ((n->first())))->toInteger(),("" + ((n[1+1])))->toInteger(),("" + ((n[2+1])))->toInteger(),("" + ((n[3+1])))->toInteger(),("" + ((n[4+1])))->toInteger()} ; if (s * v1 + 2 * t1->compareTo(s * v2 + 2 * t2)) < 0 then ( execute ('First')->display() ) else skip ; if (s * v1 + 2 * t1->compareTo(s * v2 + 2 * t2)) > 0 then ( execute ('Second')->display() ) else skip ; if s * v1 + 2 * t1 = s * v2 + 2 * t2 then ( execute ('Friendship')->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd as __gcd def getCount(a,n): gcd=0 for i in range(n): gcd=__gcd(gcd,a[i]) cnt=0 for i in range(1,gcd+1): if i*i>gcd : break if(gcd % i==0): if(i*i==gcd): cnt+=1 else : cnt+=2 return cnt a=[4,16,1024,48] n=len(a) print(getCount(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := Sequence{4}->union(Sequence{16}->union(Sequence{1024}->union(Sequence{ 48 }))) ; n := (a)->size() ; execute (getCount(a, n))->display(); operation getCount(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var gcd : int := 0 ; for i : Integer.subrange(0, n-1) do ( gcd := __gcd(gcd, a[i+1])) ; var cnt : int := 0 ; for i : Integer.subrange(1, gcd + 1-1) do ( if (i * i->compareTo(gcd)) > 0 then ( break ) else skip ; if (gcd mod i = 0) then ( if (i * i = gcd) then ( cnt := cnt + 1 ) else ( cnt := cnt + 2 ) ) else skip) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline N=int(input()) A=list(map(int,input().split())) def check(m): if m==1 : pre=-1 for a in A : if pre>=a : return False pre=a else : dp={} pre=0 for a in A : if prea : todelete.append(b) ind=a while ind>0 : if ind in dp and dp[ind]>=m-1 : todelete.append(ind) else : break ind-=1 if ind in dp : dp[ind]+=1 else : dp[ind]=1 if ind==0 or dp[ind]>=m : return False for d in todelete : del dp[d] pre=a return True def main(): l=0 r=N while r-l>1 : m=(r+l)//2 if check(m): r=m else : l=m print(r) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation check(m : OclAny) : OclAny pre: true post: true activity: if m = 1 then ( var pre : int := -1 ; for a : A do ( if (pre->compareTo(a)) >= 0 then ( return false ) else skip ; pre := a) ) else ( var dp : OclAny := Set{} ; pre := 0 ; for a : A do ( if (pre->compareTo(a)) < 0 then ( pre := a ; continue ) else skip ; var todelete : Sequence := Sequence{} ; for b : dp.keys() do ( if (b->compareTo(a)) > 0 then ( execute ((b) : todelete) ) else skip) ; var ind : OclAny := a ; while ind > 0 do ( if (dp)->includes(ind) & (dp[ind+1]->compareTo(m - 1)) >= 0 then ( execute ((ind) : todelete) ) else ( break ) ; ind := ind - 1) ; if (dp)->includes(ind) then ( dp[ind+1] := dp[ind+1] + 1 ) else ( dp[ind+1] := 1 ) ; if ind = 0 or (dp[ind+1]->compareTo(m)) >= 0 then ( return false ) else skip ; for d : todelete do ( execute (dp[d+1])->isDeleted()) ; pre := a) ) ; return true; operation main() pre: true post: true activity: var l : int := 0 ; var r : int := N ; while r - l > 1 do ( m := (r + l) div 2 ; if check(m) then ( r := m ) else ( l := m )) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input().split() s,v1,v2,t1,t2=int(n[0]),int(n[1]),int(n[2]),int(n[3]),int(n[4]) if s*v1+2*t1s*v2+2*t2 : print('Second') if s*v1+2*t1==s*v2+2*t2 : print('Friendship') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := input().split() ; var s : OclAny := null; var v1 : OclAny := null; var v2 : OclAny := null; var t1 : OclAny := null; var t2 : OclAny := null; Sequence{s,v1,v2,t1,t2} := Sequence{("" + ((n->first())))->toInteger(),("" + ((n[1+1])))->toInteger(),("" + ((n[2+1])))->toInteger(),("" + ((n[3+1])))->toInteger(),("" + ((n[4+1])))->toInteger()} ; if (s * v1 + 2 * t1->compareTo(s * v2 + 2 * t2)) < 0 then ( execute ('First')->display() ) else skip ; if (s * v1 + 2 * t1->compareTo(s * v2 + 2 * t2)) > 0 then ( execute ('Second')->display() ) else skip ; if s * v1 + 2 * t1 = s * v2 + 2 * t2 then ( execute ('Friendship')->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d,e=map(int,input().split()) b*=a c*=a c+=e c+=e b+=d b+=d if bcollect( _x | (OclType["int"])->apply(_x) ) ; b := b * a ; c := c * a ; c := c + e ; c := c + e ; b := b + d ; b := b + d ; if (b->compareTo(c)) < 0 then ( execute ('First')->display() ) else (if (c->compareTo(b)) < 0 then ( execute ('Second')->display() ) else (if c = b then ( execute ('Friendship')->display() ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s,v1,v2,t1,t2=map(int,input().split()) a=t1*2+v1*s b=t2*2+v2*s if ab : print('Second') else : print('Friendship') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := null; var v1 : OclAny := null; var v2 : OclAny := null; var t1 : OclAny := null; var t2 : OclAny := null; Sequence{s,v1,v2,t1,t2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : double := t1 * 2 + v1 * s ; var b : double := t2 * 2 + v2 * s ; if (a->compareTo(b)) < 0 then ( execute ('First')->display() ) else (if (a->compareTo(b)) > 0 then ( execute ('Second')->display() ) else ( execute ('Friendship')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count_of_ways(n): count=0 for i in range(0,n+1): for j in range(0,n+1): for k in range(0,n+1): if(i+j+k==n): count=count+1 return count if __name__=='__main__' : n=3 print(count_of_ways(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 3 ; execute (count_of_ways(n))->display() ) else skip; operation count_of_ways(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( for j : Integer.subrange(0, n + 1-1) do ( for k : Integer.subrange(0, n + 1-1) do ( if (i + j + k = n) then ( count := count + 1 ) else skip))) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- alice=input() count=0 for i in alice : if i=='a' : count+=1 if count>len(alice)//2 : print(len(alice)) else : print((2*count)-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var alice : String := (OclFile["System.in"]).readLine() ; var count : int := 0 ; for i : alice->characters() do ( if i = 'a' then ( count := count + 1 ) else skip) ; if (count->compareTo((alice)->size() div 2)) > 0 then ( execute ((alice)->size())->display() ) else ( execute ((2 * count) - 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s1=input() c=0 x=0 t=0 s=list(s1) l=len(s) for i in range(0,l): if s[i]=='a' : c+=1 else : x+=1 if c>x : print(c+x) elif c==x : print(c+x-1) else : while(1): x-=1 if c>x : t=1 break if t==1 : print(c+x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s1 : String := (OclFile["System.in"]).readLine() ; var c : int := 0 ; var x : int := 0 ; var t : int := 0 ; var s : Sequence := (s1)->characters() ; var l : int := (s)->size() ; for i : Integer.subrange(0, l-1) do ( if s[i+1] = 'a' then ( c := c + 1 ) else ( x := x + 1 )) ; if (c->compareTo(x)) > 0 then ( execute (c + x)->display() ) else (if c = x then ( execute (c + x - 1)->display() ) else ( while (1) do ( x := x - 1 ; if (c->compareTo(x)) > 0 then ( t := 1 ; break ) else skip) ; if t = 1 then ( execute (c + x)->display() ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() ac=s.count("a") print(ac+min(len(s)-ac,ac-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var ac : int := s->count("a") ; execute (ac + Set{(s)->size() - ac, ac - 1}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() lenght=len(s) a=s.count("a") b=(lenght-a) if(b>=a): answer=(a-1+a) print(answer) else : print(lenght) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var lenght : int := (s)->size() ; var a : int := s->count("a") ; var b : double := (lenght - a) ; if ((b->compareTo(a)) >= 0) then ( var answer : double := (a - 1 + a) ; execute (answer)->display() ) else ( execute (lenght)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input(); print(min(len(s),s.count('a')*2-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine(); execute (Set{(s)->size(), s->count('a') * 2 - 1}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): b=0 c=0 n=int(input()) a=list(map(int,input().split())) if 0 in a : c=(int(a.count(0))) b+=c if sum(a)+c==0 : b+=1 print(b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var b : int := 0 ; var c : int := 0 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (a)->includes(0) then ( c := (("" + ((a->count(0))))->toInteger()) ; b := b + c ) else skip ; if (a)->sum() + c = 0 then ( b := b + 1 ) else skip ; execute (b)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys MOD=1000000007 def solve(L : str): n=len(L) memo=[0]*(n+1) memo[0]=1 for i in range(1,n+1): memo[i]=memo[i-1]*3 % MOD cum=[0]*(n+1) cum[0]=1 for i in range(1,n+1): cum[i]=(cum[i-1]*2)% MOD ret=0 cnt=0 for i in range(n): c=L[i] if c=='1' : rest=n-i-1 ret=(ret+memo[rest]*cum[cnt])% MOD cnt+=1 ret=(ret+cum[cnt])% MOD print(ret) return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() L=str(next(tokens)) solve(L) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MOD : int := 1000000007 ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(L : String) pre: true post: true activity: var n : int := (L)->size() ; var memo : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; memo->first() := 1 ; for i : Integer.subrange(1, n + 1-1) do ( memo[i+1] := memo[i - 1+1] * 3 mod MOD) ; var cum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; cum->first() := 1 ; for i : Integer.subrange(1, n + 1-1) do ( cum[i+1] := (cum[i - 1+1] * 2) mod MOD) ; var ret : int := 0 ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( var c : OclAny := L[i+1] ; if c = '1' then ( var rest : double := n - i - 1 ; ret := (ret + memo[rest+1] * cum[cnt+1]) mod MOD ; cnt := cnt + 1 ) else skip) ; ret := (ret + cum[cnt+1]) mod MOD ; execute (ret)->display() ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var L : String := ("" + (((tokens).next()))) ; solve(L); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,k=map(int,input().split()) if n==k==0 : break s=[int(x)for x in input().split()] for _ in range(n): b=[int(x)for x in input().split()] for i in range(k): s[i]-=b[i] print("Yes" if min(s)>=0 else "No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = k & (k == 0) then ( break ) else skip ; var s : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for _anon : Integer.subrange(0, n-1) do ( var b : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for i : Integer.subrange(0, k-1) do ( s[i+1] := s[i+1] - b[i+1])) ; execute (if (s)->min() >= 0 then "Yes" else "No" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def print1(a,n): for i in range(0,n+1): print(a[i],end="") print("") def sort(a,n): for i in range(n,0,-1): for j in range(n,n-i,-1): if(a[j]>a[j-1]): a[j],a[j-1]=a[j-1],a[j] print1(a,n) n=7 a=[2,4,3,2,4,5,3] sort(a,n-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 7 ; a := Sequence{2}->union(Sequence{4}->union(Sequence{3}->union(Sequence{2}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 3 })))))) ; sort(a, n - 1); operation print1(a : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n + 1-1) do ( execute (a[i+1])->display()) ; execute ("")->display(); operation sort(a : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0 + 1, n)->reverse() do ( for j : Integer.subrange(n - i + 1, n)->reverse() do ( if ((a[j+1]->compareTo(a[j - 1+1])) > 0) then ( var a[j+1] : OclAny := null; var a[j - 1+1] : OclAny := null; Sequence{a[j+1],a[j - 1+1]} := Sequence{a[j - 1+1],a[j+1]} ) else skip)) ; print1(a, n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) l=list(map(int,input().split())) if 0 in l : count=l.count(0) while 0 in l : l[l.index(0)]=1 if not sum(l): count+=1 else : if not sum(l): count=1 else : count=0 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (l)->includes(0) then ( var count : int := l->count(0) ; while (l)->includes(0) do ( l[l->indexOf(0) - 1+1] := 1) ; if not((l)->sum()) then ( count := count + 1 ) else skip ) else ( if not((l)->sum()) then ( count := 1 ) else ( count := 0 ) ) ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) l=list(map(int,input().split())) if 0 in l : count=l.count(0) while 0 in l : l.remove(0) if not sum(l)+count : count+=1 else : if not sum(l): count=1 else : count=0 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (l)->includes(0) then ( var count : int := l->count(0) ; while (l)->includes(0) do ( execute ((0) /: l)) ; if not((l)->sum() + count) then ( count := count + 1 ) else skip ) else ( if not((l)->sum()) then ( count := 1 ) else ( count := 0 ) ) ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): input() li=list(map(int,input().split())) total=sum(li)+li.count(0) print(li.count(0)+1 if total==0 else li.count(0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( input() ; var li : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var total : OclAny := (li)->sum() + li->count(0) ; execute (if total = 0 then li->count(0) + 1 else li->count(0) endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) a=list(map(int,input().split())) p=0 if sum(a)!=0 and 0 not in a : print(0) elif 0 in a : p+=a.count(0) q=sum(a)+p if q==0 : p+=1 print(p) else : p+=1 print(p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var p : int := 0 ; if (a)->sum() /= 0 & (a)->excludes(0) then ( execute (0)->display() ) else (if (a)->includes(0) then ( p := p + a->count(0) ; var q : OclAny := (a)->sum() + p ; if q = 0 then ( p := p + 1 ) else skip ; execute (p)->display() ) else ( p := p + 1 ; execute (p)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s="aabb" while(len(s)toInteger() ; var s : String := "aabb" ; while (((s)->size()->compareTo(n)) < 0) do ( s := s + s) ; execute (s.subrange(1,n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) st="" p=n % 4 s=n//4 while s : st+="aabb" s-=1 if p<3 : st+='a'*p else : st+='aab' print(st) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var st : String := "" ; var p : int := n mod 4 ; var s : int := n div 4 ; while s do ( st := st + "aabb" ; s := s - 1) ; if p < 3 then ( st := st + StringLib.nCopies('a', p) ) else ( st := st + 'aab' ) ; execute (st)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s="bbaa" j=0 for i in range(1,n+1): print(s[j],end="") j+=1 if j==4 : j=0 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := "bbaa" ; var j : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( execute (s[j+1])->display() ; j := j + 1 ; if j = 4 then ( j := 0 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) d='abb' print('abba'*(n//4)+d[: n % 4]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : String := 'abb' ; execute (StringLib.nCopies('abba', (n div 4)) + d.subrange(1,n mod 4))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s='aabb' n=int(input()) print((n//4)*s+s[0 : n-4*(n//4)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := 'aabb' ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((n div 4) * s + s.subrange(0+1, n - 4 * (n div 4)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : while True : N,K=list(map(int,input().strip().split())) if N==0 and K==0 : break lims=list(map(int,input().strip().split())) totals=[0 for _ in range(K)] for _ in range(N): arr=list(map(int,input().strip().split())) for i in range(K): totals[i]+=arr[i] tarimasu=True for i in range(K): if totals[i]>lims[i]: tarimasu=False break print("Yes" if tarimasu else "No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( while true do ( var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if N = 0 & K = 0 then ( break ) else skip ; var lims : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var totals : Sequence := Integer.subrange(0, K-1)->select(_anon | true)->collect(_anon | (0)) ; for _anon : Integer.subrange(0, N-1) do ( var arr : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, K-1) do ( totals[i+1] := totals[i+1] + arr[i+1])) ; var tarimasu : boolean := true ; for i : Integer.subrange(0, K-1) do ( if (totals[i+1]->compareTo(lims[i+1])) > 0 then ( tarimasu := false ; break ) else skip) ; execute (if tarimasu then "Yes" else "No" endif)->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def pattern(n): i=n-1 j=1 for i in range(n-1,-1,-1): for j in range(n-1,i,-1): print('',end='') print(chr(i+65),end='') for j in range(1,i*2): print('',end='') if(i>=1): print(chr(i+65),end='') print() n=5 pattern(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 5 ; pattern(n); operation pattern(n : OclAny) pre: true post: true activity: var i : double := n - 1 ; var j : int := 1 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( for j : Integer.subrange(i + 1, n - 1)->reverse() do ( execute ('')->display()) ; execute ((i + 65)->byte2char())->display() ; for j : Integer.subrange(1, i * 2-1) do ( execute ('')->display()) ; if (i >= 1) then ( execute ((i + 65)->byte2char())->display() ) else skip ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,b,i,ma=int(input()),[],0,0 a=list(map(int,input().split())) while ia[b[i][1]]+1 : ma=max(ma,b[i+1][1]-b[i][0]+1) elif b[i+1][0]-b[i][1]==1 and(b[i+1][0]+1a[b[i][1]]+1 or b[i][1]-1>=0 and a[b[i][1]-1]+1toInteger(),Sequence{},0,0} ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; while (i->compareTo(n)) < 0 do ( var j : OclAny := i ; while (j->compareTo(n - 1)) < 0 & (a[j+1]->compareTo(a[j + 1+1])) < 0 do ( j := j + 1) ; execute ((Sequence{i}->union(Sequence{ j })) : b) ; var ma : OclAny := null; var i : OclAny := null; Sequence{ma,i} := Sequence{Set{j - i + 1 + (i /= 0 or j /= n - 1), ma}->max(),j + 1}) ; for i : Integer.subrange(0, (b)->size() - 1-1) do ( if b[i + 1+1]->first() - b[i+1][1+1] = 2 & (a[b[i + 1+1]->first()+1]->compareTo(a[b[i+1][1+1]+1] + 1)) > 0 then ( var ma : OclAny := Set{ma, b[i + 1+1][1+1] - b[i+1]->first() + 1}->max() ) else (if b[i + 1+1]->first() - b[i+1][1+1] = 1 & ((b[i + 1+1]->first() + 1->compareTo(n)) < 0 & (a[b[i + 1+1]->first() + 1+1]->compareTo(a[b[i+1][1+1]+1] + 1)) > 0 or b[i+1][1+1] - 1 >= 0 & (a[b[i+1][1+1] - 1+1] + 1->compareTo(a[b[i + 1+1]->first()+1])) < 0) then ( ma := Set{ma, b[i + 1+1][1+1] - b[i+1]->first() + 1}->max() ) else skip)) ; execute (ma)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pattern(n): k=0 for i in range(n-1,-1,-1): for j in range(n-1,k,-1): print('',end='') print(chr(i+65),end='') for j in range(1,k*2): print('',end='') if ireverse() do ( for j : Integer.subrange(k + 1, n - 1)->reverse() do ( execute ('')->display()) ; execute ((i + 65)->byte2char())->display() ; for j : Integer.subrange(1, k * 2-1) do ( execute ('')->display()) ; if (i->compareTo(n - 1)) < 0 then ( execute ((i + 65)->byte2char())->display() ) else skip ; execute (->display() ; k := k + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys def changeTheArray(arr,n): minEle=min(arr) maxEle=max(arr) minOperations=sys.maxsize for num in range(minEle,maxEle+1): operations=0 for i in range(n): if arr[i]!=num : operations+=(abs(num-arr[i])-1) minOperations=min(minOperations,operations) return minOperations if __name__=='__main__' : arr=[10,1,4] n=len(arr) print(changeTheArray(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{10}->union(Sequence{1}->union(Sequence{ 4 })) ; n := (arr)->size() ; execute (changeTheArray(arr, n))->display() ) else skip; operation changeTheArray(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var minEle : OclAny := (arr)->min() ; var maxEle : OclAny := (arr)->max() ; var minOperations : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; for num : Integer.subrange(minEle, maxEle + 1-1) do ( var operations : int := 0 ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] /= num then ( operations := operations + ((num - arr[i+1])->abs() - 1) ) else skip) ; minOperations := Set{minOperations, operations}->min()) ; return minOperations; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter x=int(input()) y=list(map(int,input().split())) if x==1 : print(y[0]) elif y.count(2)==0 or y.count(1)==0 : for i in y : print(i,end=" ") else : c=Counter(y) print(2,1,end=" ") c[1]-=1 c[2]-=1 if c[2]>0 : for i in range(c[2]): print(2,end=" ") if c[1]>0 : for i in range(c[1]): print(1,end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var y : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if x = 1 then ( execute (y->first())->display() ) else (if y->count(2) = 0 or y->count(1) = 0 then ( for i : y do ( execute (i)->display()) ) else ( var c : OclAny := Counter(y) ; execute (2)->display() ; c[1+1] := c[1+1] - 1 ; c[2+1] := c[2+1] - 1 ; if c[2+1] > 0 then ( for i : Integer.subrange(0, c[2+1]-1) do ( execute (2)->display()) ) else skip ; if c[1+1] > 0 then ( for i : Integer.subrange(0, c[1+1]-1) do ( execute (1)->display()) ; execute (->display() ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout import math cin=stdin.readline cout=stdout.write mp=lambda : list(map(int,cin().split())) n,=mp() a=mp() one=a.count(1) two=a.count(2) summ=sum(a) prime=[True]*(summ+1) p=[0] for i in range(2,summ+1): if prime[i]: p+=[i] for j in range(i*2,summ+1,i): prime[j]=False l=[] i=1 while(one or two)and icollect( _x | (OclType["int"])->apply(_x) ))) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,)} := mp->apply() ; var a : OclAny := mp->apply() ; var one : int := a->count(1) ; var two : int := a->count(2) ; var summ : OclAny := (a)->sum() ; var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (summ + 1)) ; var p : Sequence := Sequence{ 0 } ; for i : Integer.subrange(2, summ + 1-1) do ( if prime[i+1] then ( p := p + Sequence{ i } ; for j : Integer.subrange(i * 2, summ + 1-1)->select( $x | ($x - i * 2) mod i = 0 ) do ( prime[j+1] := false) ) else skip) ; var l : Sequence := Sequence{} ; var i : int := 1 ; while (one or two) & (i->compareTo((p)->size())) < 0 do ( var tw : OclAny := Set{(p[i+1] - p[i - 1+1]) div 2, two}->min() ; var fs : OclAny := Set{p[i+1] - p[i - 1+1] - tw * 2, one}->min() ; l := l + MatrixLib.elementwiseMult(Sequence{ 2 }, tw) ; l := l + MatrixLib.elementwiseMult(Sequence{ 1 }, fs) ; two := two - tw ; one := one - fs ; i := i + 1) ; l := l + MatrixLib.elementwiseMult(Sequence{ 2 }, two) ; l := l + MatrixLib.elementwiseMult(Sequence{ 1 }, one) ; for val : l do ( cout(("" + ((val))) + ' ')); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(input()) twos,ones=0,0 a=[int(x)for x in input().split()] for i in range(n): if a[i]==1 : ones+=1 else : twos+=1 primes=[1]*(2*n+10) primes[0]=primes[1]=0 i=2 while i*i<=2*n : if primes[i]==1 : t=i+i while t<=2*n : primes[t]=0 t+=i i+=1 cur_sum=0 ans=[0]*(2*n+1) cur_id=0 while ones>0 or twos>0 : if primes[cur_sum+1]==1 and ones>0 : ans[cur_id]=1 ones-=1 cur_sum+=1 cur_id+=1 elif twos>0 : ans[cur_id]=2 twos-=1 cur_sum+=2 cur_id+=1 else : break while twos>0 : ans[cur_id]=2 twos-=1 cur_id+=1 while ones>0 : ans[cur_id]=1 ones-=1 cur_id+=1 for i in range(n): print(ans[i],end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var twos : OclAny := null; var ones : OclAny := null; Sequence{twos,ones} := Sequence{0,0} ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = 1 then ( ones := ones + 1 ) else ( twos := twos + 1 )) ; var primes : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (2 * n + 10)) ; primes->first() := 0; var primes[1+1] : int := 0 ; var i : int := 2 ; while (i * i->compareTo(2 * n)) <= 0 do ( if primes[i+1] = 1 then ( var t : int := i + i ; while (t->compareTo(2 * n)) <= 0 do ( primes[t+1] := 0 ; t := t + i) ) else skip ; i := i + 1) ; var cur_sum : int := 0 ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * n + 1)) ; var cur_id : int := 0 ; while ones > 0 or twos > 0 do ( if primes[cur_sum + 1+1] = 1 & ones > 0 then ( ans[cur_id+1] := 1 ; ones := ones - 1 ; cur_sum := cur_sum + 1 ; cur_id := cur_id + 1 ) else (if twos > 0 then ( ans[cur_id+1] := 2 ; twos := twos - 1 ; cur_sum := cur_sum + 2 ; cur_id := cur_id + 1 ) else ( break ) ) ) ; while twos > 0 do ( ans[cur_id+1] := 2 ; twos := twos - 1 ; cur_id := cur_id + 1) ; while ones > 0 do ( ans[cur_id+1] := 1 ; ones := ones - 1 ; cur_id := cur_id + 1) ; for i : Integer.subrange(0, n-1) do ( execute (ans[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[int(i)for i in input().split()] k1=l.count(1) k2=l.count(2) if(k1==0 or k2==0): print(*l) else : print('2 1'+' 2'*(k2-1)+' 1'*(k1-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var k1 : int := l->count(1) ; var k2 : int := l->count(2) ; if (k1 = 0 or k2 = 0) then ( execute ((argument * (test (logical_test (comparison (expr (atom (name l))))))))->display() ) else ( execute ('2 1' + StringLib.nCopies(' 2', (k2 - 1)) + StringLib.nCopies(' 1', (k1 - 1)))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline from collections import Counter n=int(input()) a=Counter(list(map(int,input().split()))) two=a[2] one=a[1] s='' if a[2]: s+='2 ' a[2]-=1 if a[1]: s+='1 ' a[1]-=1 s+='2 '*a[2] s+='1 '*a[1] print(s.rstrip()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := Counter(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var two : OclAny := a[2+1] ; var one : OclAny := a[1+1] ; var s : String := '' ; if a[2+1] then ( s := s + '2 ' ; a[2+1] := a[2+1] - 1 ) else skip ; if a[1+1] then ( s := s + '1 ' ; a[1+1] := a[1+1] - 1 ) else skip ; s := s + StringLib.nCopies('2 ', a[2+1]) ; s := s + StringLib.nCopies('1 ', a[1+1]) ; execute (StringLib.rightTrim(s))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthTerm(n): return(N*N*N)+(N*N)+N if __name__=="__main__" : N=3 print(nthTerm(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var N : int := 3 ; execute (nthTerm(N))->display() ) else skip; operation nthTerm(n : OclAny) : OclAny pre: true post: true activity: return (N * N * N) + (N * N) + N; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,k=map(int,input().split()) if n+k==0 : break s=list(map(int,input().split())) for _ in range(n): b=list(map(int,input().split())) for j,_b in enumerate(b): s[j]=s[j]-_b bool_list=list(map(lambda x : x>=0,s)) if False in bool_list : print('No') else : print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n + k = 0 then ( break ) else skip ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for _anon : Integer.subrange(0, n-1) do ( var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for _tuple : Integer.subrange(1, (b)->size())->collect( _indx | Sequence{_indx-1, (b)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var _b : OclAny := _tuple->at(_indx); s[j+1] := s[j+1] - _b)) ; var bool_list : Sequence := ((s)->collect( _x | (lambda x : OclAny in (x >= 0))->apply(_x) )) ; if (bool_list)->includes(false) then ( execute ('No')->display() ) else ( execute ('Yes')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthTerm(N): return(N*((N % 2)+(N % 3))) if __name__=='__main__' : N=5 print("Nth term for N=",N," : ",nthTerm(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( N := 5 ; execute ("Nth term for N=")->display() ) else skip; operation nthTerm(N : OclAny) : OclAny pre: true post: true activity: return (N * ((N mod 2) + (N mod 3))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthTerm(N): return(N*((N//2)+((N % 2)*2)+N)) if __name__=='__main__' : N=5 print("Nth term for N=",N," : ",nthTerm(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( N := 5 ; execute ("Nth term for N=")->display() ) else skip; operation nthTerm(N : OclAny) : OclAny pre: true post: true activity: return (N * ((N div 2) + ((N mod 2) * 2) + N)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,b,i,ma=int(input()),[],0,0 a=list(map(int,input().split())) while ia[b[i][1]]+1 : ma=max(ma,b[i+1][1]-b[i][0]+1) elif b[i+1][0]-b[i][1]==1 : if(b[i+1][0]+1a[b[i][1]]+1)or(b[i][1]-1>=0 and a[b[i][1]-1]+1toInteger(),Sequence{},0,0} ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; while (i->compareTo(n)) < 0 do ( var j : OclAny := i ; while (j->compareTo(n - 1)) < 0 & (a[j+1]->compareTo(a[j + 1+1])) < 0 do ( j := j + 1) ; execute ((Sequence{i}->union(Sequence{ j })) : b) ; var ma : OclAny := null; var i : OclAny := null; Sequence{ma,i} := Sequence{Set{j - i + 1 + (i /= 0 or j /= n - 1), ma}->max(),j + 1}) ; for i : Integer.subrange(0, (b)->size() - 1-1) do ( if b[i + 1+1]->first() - b[i+1][1+1] = 2 & (a[b[i + 1+1]->first()+1]->compareTo(a[b[i+1][1+1]+1] + 1)) > 0 then ( var ma : OclAny := Set{ma, b[i + 1+1][1+1] - b[i+1]->first() + 1}->max() ) else (if b[i + 1+1]->first() - b[i+1][1+1] = 1 then ( if ((b[i + 1+1]->first() + 1->compareTo(n)) < 0 & (a[b[i + 1+1]->first() + 1+1]->compareTo(a[b[i+1][1+1]+1] + 1)) > 0) or (b[i+1][1+1] - 1 >= 0 & (a[b[i+1][1+1] - 1+1] + 1->compareTo(a[b[i + 1+1]->first()+1])) < 0) then ( ma := Set{ma, b[i + 1+1][1+1] - b[i+1]->first() + 1}->max() ) else skip ) else skip)) ; execute (ma)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(sys.stdin.readline()) mas=list(map(int,sys.stdin.readline().split())) otv=[0]*510 for i in range(510): otv[i]=[0]*510 for i in range(n,0,-1): for j in range(i,n+1): otv[i][j]=otv[i][j-1]+1 for x in range(i,j): if mas[j-1]==mas[x-1]: otv[i][j]=min(otv[i][j],otv[i][x-1]+max(1,otv[x+1][j-1])) print(otv[1][n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mas : Sequence := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var otv : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 510) ; for i : Integer.subrange(0, 510-1) do ( otv[i+1] := MatrixLib.elementwiseMult(Sequence{ 0 }, 510)) ; for i : Integer.subrange(0 + 1, n)->reverse() do ( for j : Integer.subrange(i, n + 1-1) do ( otv[i+1][j+1] := otv[i+1][j - 1+1] + 1 ; for x : Integer.subrange(i, j-1) do ( if mas[j - 1+1] = mas[x - 1+1] then ( otv[i+1][j+1] := Set{otv[i+1][j+1], otv[i+1][x - 1+1] + Set{1, otv[x + 1+1][j - 1+1]}->max()}->min() ) else skip))) ; execute (otv[1+1][n+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_param(): n=int(input().strip()) l=list(map(int,input().strip().split(' '))) return l def dp(l): n=len(l) l_1=[0]+l[:] dp_m=[[float('inf')for i in range(n+1)]for i in range(n+1)] for i in range(1,n+1): dp_m[i][i]=1 for i in range(1,n): if l_1[i]==l_1[i+1]: dp_m[i][i+1]=1 else : dp_m[i][i+1]=2 for k in range(3,n+1): i=1 while i+k-1<=n : j=i+k-1 if l_1[i]==l_1[j]: dp_m[i][j]=dp_m[i+1][j-1] for r in range(i+1,j+1): dp_m[i][j]=min(dp_m[i][j],dp_m[i][r-1]+dp_m[r][j]) i+=1 result=dp_m[1][n] return result if __name__=='__main__' : l=get_param() result=dp(l) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( l := get_param() ; result := dp(l) ; execute (result)->display() ) else skip; operation get_param() : OclAny pre: true post: true activity: var n : int := ("" + ((input()->trim())))->toInteger() ; var l : Sequence := ((input()->trim().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; return l; operation dp(l : OclAny) : OclAny pre: true post: true activity: n := (l)->size() ; var l n := (l)->size() : Sequence := Sequence{ 0 }->union(l) ; var dp_m : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (("" + (('inf')))->toReal())))) ; for i : Integer.subrange(1, n + 1-1) do ( dp_m[i+1][i+1] := 1) ; for i : Integer.subrange(1, n-1) do ( if l n := (l)->size()[i+1] = l n := (l)->size()[i + 1+1] then ( dp_m[i+1][i + 1+1] := 1 ) else ( dp_m[i+1][i + 1+1] := 2 )) ; for k : Integer.subrange(3, n + 1-1) do ( var i : int := 1 ; while (i + k - 1->compareTo(n)) <= 0 do ( var j : double := i + k - 1 ; if l var j : double := i + k - 1[i+1] = l var j : double := i + k - 1[j+1] then ( dp_m[i+1][j+1] := dp_m[i + 1+1][j - 1+1] ) else skip ; for r : Integer.subrange(i + 1, j + 1-1) do ( dp_m[i+1][j+1] := Set{dp_m[i+1][j+1], dp_m[i+1][r - 1+1] + dp_m[r+1][j+1]}->min()) ; i := i + 1)) ; var result : OclAny := dp_m[1+1][n+1] ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_param(): n=int(input().strip()) l=list(map(int,input().strip().split(' '))) return l def dp(l): n=len(l) l_1=[0]+l[:] dp_m=[[float('inf')for i in range(n+1)]for i in range(n+1)] for i in range(1,n+1): dp_m[i][i]=1 for i in range(1,n): if l_1[i]==l_1[i+1]: dp_m[i][i+1]=1 else : dp_m[i][i+1]=2 for k in range(3,n+1): i=1 while i+k-1<=n : j=i+k-1 if l_1[i]==l_1[j]: dp_m[i][j]=dp_m[i+1][j-1] for r in range(i+1,j+1): dp_m[i][j]=min(dp_m[i][j],dp_m[i][r-1]+dp_m[r][j]) i+=1 result=dp_m[1][n] return result if __name__=='__main__' : l=get_param() result=dp(l) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( l := get_param() ; result := dp(l) ; execute (result)->display() ) else skip; operation get_param() : OclAny pre: true post: true activity: var n : int := ("" + ((input()->trim())))->toInteger() ; var l : Sequence := ((input()->trim().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; return l; operation dp(l : OclAny) : OclAny pre: true post: true activity: n := (l)->size() ; var l n := (l)->size() : Sequence := Sequence{ 0 }->union(l) ; var dp_m : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (("" + (('inf')))->toReal())))) ; for i : Integer.subrange(1, n + 1-1) do ( dp_m[i+1][i+1] := 1) ; for i : Integer.subrange(1, n-1) do ( if l n := (l)->size()[i+1] = l n := (l)->size()[i + 1+1] then ( dp_m[i+1][i + 1+1] := 1 ) else ( dp_m[i+1][i + 1+1] := 2 )) ; for k : Integer.subrange(3, n + 1-1) do ( var i : int := 1 ; while (i + k - 1->compareTo(n)) <= 0 do ( var j : double := i + k - 1 ; if l var j : double := i + k - 1[i+1] = l var j : double := i + k - 1[j+1] then ( dp_m[i+1][j+1] := dp_m[i + 1+1][j - 1+1] ) else skip ; for r : Integer.subrange(i + 1, j + 1-1) do ( dp_m[i+1][j+1] := Set{dp_m[i+1][j+1], dp_m[i+1][r - 1+1] + dp_m[r+1][j+1]}->min()) ; i := i + 1)) ; var result : OclAny := dp_m[1+1][n+1] ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) c=list(map(int,input().split())) dp=[[1000 for i in range(n)]for j in range(n)] for i in range(n): dp[i][i]=1 for i in range(n-1): if c[i]==c[i+1]: dp[i][i+1]=1 for ln in range(1,n): for i in range(n-ln): if ln>=2 and c[i]==c[i+ln]: dp[i][i+ln]=dp[i+1][i+ln-1] for k in range(i,i+ln): dp[i][i+ln]=min(dp[i][i+ln],dp[i][k]+dp[k+1][i+ln]) print(dp[0][n-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dp : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (Integer.subrange(0, n-1)->select(i | true)->collect(i | (1000)))) ; for i : Integer.subrange(0, n-1) do ( dp[i+1][i+1] := 1) ; for i : Integer.subrange(0, n - 1-1) do ( if c[i+1] = c[i + 1+1] then ( dp[i+1][i + 1+1] := 1 ) else skip) ; for ln : Integer.subrange(1, n-1) do ( for i : Integer.subrange(0, n - ln-1) do ( if ln >= 2 & c[i+1] = c[i + ln+1] then ( dp[i+1][i + ln+1] := dp[i + 1+1][i + ln - 1+1] ) else skip ; for k : Integer.subrange(i, i + ln-1) do ( dp[i+1][i + ln+1] := Set{dp[i+1][i + ln+1], dp[i+1][k+1] + dp[k + 1+1][i + ln+1]}->min()))) ; execute (dp->first()[n - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(sorted(map(int,input().split()))) i=0 k=1 ans=0 while itoInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort()) ; var i : int := 0 ; var k : int := 1 ; var ans : int := 0 ; while (i->compareTo(n)) < 0 do ( while (i->compareTo(n)) < 0 & (arr[i+1]->compareTo(k)) < 0 do ( i := i + 1) ; if i = n then ( k := k - 1 ) else skip ; k := k + 1 ; i := i + 1) ; execute (k - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) contests=[int(contest)for contest in input().split()] contests.sort() answer=0 k=1 for contest in contests : if contest>=k : answer+=1 k+=1 print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var contests : Sequence := input().split()->select(contest | true)->collect(contest | (("" + ((contest)))->toInteger())) ; contests := contests->sort() ; var answer : int := 0 ; var k : int := 1 ; for contest : contests do ( if (contest->compareTo(k)) >= 0 then ( answer := answer + 1 ; k := k + 1 ) else skip) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def res(a): res=0 for i in a : if i>res : res=res+1 return res n=int(input()) a=list(map(int,input().split())) a.sort() print(res(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; execute (res(a))->display(); operation res(a : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; for i : a do ( if (i->compareTo(res)) > 0 then ( res := res + 1 ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,k=map(int,input().split()) if n==0 : break s=list(map(int,input().split())) b=[0]*k for i in range(n): a=list(map(int,input().split())) for j in range(k): b[j]+=a[j] ans=True for i in range(k): if b[i]>s[i]: ans=False break print("Yes" if ans else "No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, k) ; for i : Integer.subrange(0, n-1) do ( var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, k-1) do ( b[j+1] := b[j+1] + a[j+1])) ; var ans : boolean := true ; for i : Integer.subrange(0, k-1) do ( if (b[i+1]->compareTo(s[i+1])) > 0 then ( ans := false ; break ) else skip) ; execute (if ans then "Yes" else "No" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=int(input()) contests=list(map(int,input().split())) contests.sort() contest={} lst=[] for j in range(c): lst.append(j) contest[j]=contests[j] p=1 ans=0 for i in range(c): if p<=contest[i]: p+=1 ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var contests : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; contests := contests->sort() ; var contest : OclAny := Set{} ; var lst : Sequence := Sequence{} ; for j : Integer.subrange(0, c-1) do ( execute ((j) : lst) ; contest[j+1] := contests[j+1]) ; var p : int := 1 ; var ans : int := 0 ; for i : Integer.subrange(0, c-1) do ( if (p->compareTo(contest[i+1])) <= 0 then ( p := p + 1 ; ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) l1=sorted(list(map(int,input().split()))) ind=1 for i in range(n): if l1[i]>=ind : ind+=1 print(ind-1) for _ in range(1): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, 1-1) do ( solve()); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var ind : int := 1 ; for i : Integer.subrange(0, n-1) do ( if (l1[i+1]->compareTo(ind)) >= 0 then ( ind := ind + 1 ) else skip) ; execute (ind - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import networkx as nx N=int(input()) S=[list(input())for i in range(N)] G=nx.Graph() for i in range(N): G.add_node(i) for i in range(N): for j in range(i,N): if S[i][j]=='1' : G.add_edge(i,j) if nx.is_bipartite(G): ans=nx.diameter(G)+1 print(ans) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((OclFile["System.in"]).readLine())->characters())) ; var G : OclAny := nx.Graph() ; for i : Integer.subrange(0, N-1) do ( G.add_node(i)) ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(i, N-1) do ( if S[i+1][j+1] = '1' then ( G.add_edge(i, j) ) else skip)) ; if nx.is_bipartite(G) then ( var ans : OclAny := nx.diameter(G) + 1 ; execute (ans)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) class Impossible(ValueError): pass def main(): n,m=map(int,input().split()) lrds=[] for i in range(m): l,r,d=map(int,input().split()) lrds.append((l-1,r-1,d)) adj=[[]for i in range(n)] parents=[i for i in range(n)] for i in range(m): l,r,d=lrds[i] union(parents,l,r) adj[l].append((r,d)) adj[r].append((l,-d)) ds=set() for i in range(n): ds.add(find(parents,i)) pos=[None for i in range(n)] try : for i in ds : pos[i]=0 dfs(adj,pos,i) print("Yes") except Impossible : print("No") def dfs(adj,pos,x): for y,d in adj[x]: if pos[y]is None : pos[y]=pos[x]+d dfs(adj,pos,y) elif pos[y]!=pos[x]+d : raise Impossible def find(p,x): if p[x]!=x : p[x]=find(p,p[x]) return p[x] def union(p,x,y): p[find(p,y)]=find(p,x) main() ------------------------------------------------------------ OCL File: --------- class Impossible extends IncorrectElementException { static operation newImpossible() : Impossible pre: true post: Impossible->exists( _x | result = _x ); } class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; skip ; skip ; skip ; skip ; skip ; main(); operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lrds : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var l : OclAny := null; var r : OclAny := null; var d : OclAny := null; Sequence{l,r,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{l - 1, r - 1, d}) : lrds)) ; var adj : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; var parents : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)) ; for i : Integer.subrange(0, m-1) do ( var l : OclAny := null; var r : OclAny := null; var d : OclAny := null; Sequence{l,r,d} := lrds[i+1] ; union(parents, l, r) ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name l)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name r)))))) , (test (logical_test (comparison (expr (atom (name d))))))) )))))))) )))) ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name l)))))) , (test (logical_test (comparison (expr - (expr (atom (name d)))))))) )))))))) ))))) ; var ds : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( execute ((find(parents, i)) : ds)) ; var pos : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; try ( for i : ds do ( pos[i+1] := 0 ; dfs(adj, pos, i)) ; execute ("Yes")->display()) (except_clause except (test (logical_test (comparison (expr (atom (name Impossible)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "No"))))))) )))))))))))))); operation dfs(adj : OclAny, pos : OclAny, x : OclAny) pre: true post: true activity: for _tuple : adj[x+1] do (var _indx : int := 1; var y : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); if pos[y+1] <>= null then ( pos[y+1] := pos[x+1] + d ; dfs(adj, pos, y) ) else (if pos[y+1] /= pos[x+1] + d then ( error Impossible.newImpossible ) else skip)); operation find(p : OclAny, x : OclAny) : OclAny pre: true post: true activity: if p[x+1] /= x then ( p[x+1] := find(p, p[x+1]) ) else skip ; return p[x+1]; operation union(p : OclAny, x : OclAny, y : OclAny) pre: true post: true activity: p[find(p, y)+1] := find(p, x); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from scipy.sparse.csgraph import floyd_warshall import numpy as np from itertools import* n=int(input()) con=[[]for _ in range(n)] col=[-1]*n G=[] for i in range(n): x=input() for j,c in enumerate(x): if c=="1" : con[i].append(j) con[j].append(i) G.append([c=="1" or float("inf")for c in x]) q=[0] col[0]=0 while q : cur=q.pop(0) for nxt in con[cur]: if col[nxt]==col[cur]: print(-1) exit() if col[nxt]<0 : col[nxt]=1-col[cur] q.append(nxt) print(int(np.amax(floyd_warshall(G,0)+1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var con : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var col : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; var G : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x : String := (OclFile["System.in"]).readLine() ; for _tuple : Integer.subrange(1, (x)->size())->collect( _indx | Sequence{_indx-1, (x)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if c = "1" then ( (expr (atom (name con)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) ; (expr (atom (name con)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ) else skip) ; execute ((x->characters()->select(c | true)->collect(c | (c = "1" or ("" + (("inf")))->toReal()))) : G)) ; var q : Sequence := Sequence{ 0 } ; col->first() := 0 ; while q do ( var cur : OclAny := q->at(0`firstArg+1) ; q := q->excludingAt(0+1) ; for nxt : con[cur+1] do ( if col[nxt+1] = col[cur+1] then ( execute (-1)->display() ; exit() ) else skip ; if col[nxt+1] < 0 then ( col[nxt+1] := 1 - col[cur+1] ; execute ((nxt) : q) ) else skip)) ; execute (("" + (()))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import deque import bisect import copy import heapq import itertools import math input=sys.stdin.readline sys.setrecursionlimit(1000000) mod=10**9+7 def read_values(): return map(int,input().split()) def read_index(): return map(lambda x : int(x)-1,input().split()) def read_list(): return list(read_values()) def read_lists(N): return[read_list()for n in range(N)] def f(S,i): D=[-1]*len(S) P=[set()for _ in range(len(S))] Q=deque() Q.append(i) D[i]=1 while Q : v=Q.popleft() for w in S[v]: if w in P[v]: continue if D[w]>0 and D[w]pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation read_values() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation read_index() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ); operation read_list() : OclAny pre: true post: true activity: return (read_values()); operation read_lists(N : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, N-1)->select(n | true)->collect(n | (read_list())); operation f(S : OclAny, i : OclAny) : OclAny pre: true post: true activity: var D : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (S)->size()) ; var P : Sequence := Integer.subrange(0, (S)->size()-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; var Q : Sequence := () ; execute ((i) : Q) ; D[i+1] := 1 ; while Q do ( var v : OclAny := Q->first() ; Q := Q->tail() ; for w : S[v+1] do ( if (P[v+1])->includes(w) then ( continue ) else skip ; if D[w+1] > 0 & (D[w+1]->compareTo(D[v+1] + 1)) < 0 then ( return -1 ) else skip ; if D[w+1] < 0 then ( execute ((w) : Q) ) else skip ; (expr (atom (name P)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name w)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) ; D[w+1] := D[v+1] + 1)) ; return D[v+1]; operation main() pre: true post: true activity: N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; S := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (input()->trim())) ; var L : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Set{}->union(((argument (test (logical_test (comparison (expr (atom (name j)))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) == (comparison (expr (atom "1"))))))))))))) ; var res : int := -1 ; for i : Integer.subrange(0, N-1) do ( var r : String := f(L, i) ; res := Set{res, r}->max()) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque n=int(input()) mat=[[10**18 for i in range(n+1)]for j in range(n+1)] ab=[[]for i in range(n)] for i in range(n): si=input() for j in range(n): if int(si[j])==1 : mat[i+1][j+1]=1 ab[i].append(j) colors=[0 for i in range(n)] def dfs(v,color): colors[v]=color for to in ab[v]: if colors[to]==color : return False if colors[to]==0 and not dfs(to,-color): return False return True def is_bipartite(): return dfs(0,1) if not is_bipartite(): print(-1) exit() for i in range(n+1): mat[i][i]=0 for i in range(1,n+1): for x in range(1,n+1): for y in range(1,n+1): mat[x][y]=min(mat[x][y],mat[x][i]+mat[i][y]) ans=0 for i in range(1,n+1): for j in range(i+1,n+1): ans=max(ans,mat[i][j]) print(ans+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mat : Sequence := Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | ((10)->pow(18))))) ; var ab : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, n-1) do ( var si : String := (OclFile["System.in"]).readLine() ; for j : Integer.subrange(0, n-1) do ( if ("" + ((si[j+1])))->toInteger() = 1 then ( mat[i + 1+1][j + 1+1] := 1 ; (expr (atom (name ab)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) ) else skip)) ; var colors : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; skip ; skip ; if not(is_bipartite()) then ( execute (-1)->display() ; exit() ) else skip ; for i : Integer.subrange(0, n + 1-1) do ( mat[i+1][i+1] := 0) ; for i : Integer.subrange(1, n + 1-1) do ( for x : Integer.subrange(1, n + 1-1) do ( for y : Integer.subrange(1, n + 1-1) do ( mat[x+1][y+1] := Set{mat[x+1][y+1], mat[x+1][i+1] + mat[i+1][y+1]}->min()))) ; var ans : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(i + 1, n + 1-1) do ( ans := Set{ans, mat[i+1][j+1]}->max())) ; execute (ans + 1)->display(); operation dfs(v : OclAny, color : OclAny) : OclAny pre: true post: true activity: colors[v+1] := color ; for to : ab[v+1] do ( if colors[to+1] = color then ( return false ) else skip ; if colors[to+1] = 0 & not(dfs(to, -color)) then ( return false ) else skip) ; return true; operation is_bipartite() : OclAny pre: true post: true activity: return dfs(0, 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np from scipy.sparse import csr_matrix from scipy.sparse.csgraph import floyd_warshall n=int(input()) s=list() for i in range(n): s.append([int(x)for x in list(input())]) s=np.array(s) d=floyd_warshall(csr_matrix(s)) c=d[:,np.argmax(d)% n] for i in range(n): for j in range(i+1,n): if(s[i,j]==1)and abs(c[i]-c[j])!=1 : print(-1) exit() r=int(np.amax(d)+1) print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := () ; for i : Integer.subrange(0, n-1) do ( execute ((((OclFile["System.in"]).readLine())->characters()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) : s)) ; s := (s) ; var d : OclAny := floyd_warshall(csr_matrix(s)) ; var c : Sequence := d->collect( _r | _r[ mod n+1] ) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if (s[i+1][j+1] = 1) & (c[i+1] - c[j+1])->abs() /= 1 then ( execute (-1)->display() ; exit() ) else skip)) ; var r : int := ("" + (( + 1)))->toInteger() ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): r=0 u=0 d=0 l=0 x,y=map(int,input().split()) li=list(input()) res=0 if x>0 : r=x elif x<0 : l=abs(x) if y>0 : u=y elif y<0 : d=abs(y) for i in li : if i=='R' : if r!=0 : r-=1 elif i=="U" : if u!=0 : u-=1 elif i=="D" : if d!=0 : d-=1 elif i=='L' : if l!=0 : l-=1 if r==0 and u==0 and d==0 and l==0 : res=1 break if res==0 : print("NO") elif res==1 : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var r : int := 0 ; var u : int := 0 ; var d : int := 0 ; var l : int := 0 ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var li : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var res : int := 0 ; if x > 0 then ( r := x ) else (if x < 0 then ( l := (x)->abs() ) else skip) ; if y > 0 then ( u := y ) else (if y < 0 then ( d := (y)->abs() ) else skip) ; for i : li do ( if i = 'R' then ( if r /= 0 then ( r := r - 1 ) else skip ) else (if i = "U" then ( if u /= 0 then ( u := u - 1 ) else skip ) else (if i = "D" then ( if d /= 0 then ( d := d - 1 ) else skip ) else (if i = 'L' then ( if l /= 0 then ( l := l - 1 ) else skip ) else skip ) ) ) ; if r = 0 & u = 0 & d = 0 & l = 0 then ( res := 1 ; break ) else skip) ; if res = 0 then ( execute ("NO")->display() ) else (if res = 1 then ( execute ("YES")->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x,y=map(int,input().split()) z=input() countR=z.count('R') countL=z.count('L') countU=z.count('U') countD=z.count('D') if x>0 : if y>0 : if countR>=x and countU>=y : print('YES') else : print('NO') else : if countR>=x and countD>=abs(y): print('YES') else : print('NO') else : if y>0 : if countL>=abs(x)and countU>=y : print('YES') else : print('NO') else : if countL>=abs(x)and countD>=abs(y): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var z : String := (OclFile["System.in"]).readLine() ; var countR : int := z->count('R') ; var countL : int := z->count('L') ; var countU : int := z->count('U') ; var countD : int := z->count('D') ; if x > 0 then ( if y > 0 then ( if (countR->compareTo(x)) >= 0 & (countU->compareTo(y)) >= 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) else ( if (countR->compareTo(x)) >= 0 & (countD->compareTo((y)->abs())) >= 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) ) else ( if y > 0 then ( if (countL->compareTo((x)->abs())) >= 0 & (countU->compareTo(y)) >= 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) else ( if (countL->compareTo((x)->abs())) >= 0 & (countD->compareTo((y)->abs())) >= 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : N,K=map(int,input().split()) if N==0 and K==0 : break S=list(map(int,input().split())) total_B=[0]*K for i in range(N): B=list(map(int,input().split())) for j in range(K): total_B[j]+=B[j] ans='Yes' for i in range(K): if S[i]collect( _x | (OclType["int"])->apply(_x) ) ; if N = 0 & K = 0 then ( break ) else skip ; var S : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var total_B : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, K) ; for i : Integer.subrange(0, N-1) do ( var B : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, K-1) do ( total_B[j+1] := total_B[j+1] + B[j+1])) ; var ans : String := 'Yes' ; for i : Integer.subrange(0, K-1) do ( if (S[i+1]->compareTo(total_B[i+1])) < 0 then ( ans := 'No' ; break ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : for _ in range(int(input())): px,py=map(int,input().split()) s=sorted(input(),reverse=True) x,y,=0,0 for si in s : if x==px and y==py : break if y!=py : if si=="U" and py>0 : y+=1 elif si=="D" and py<0 : y-=1 if x!=px : if si=="R" and px>0 : x+=1 elif si=="L" and px<0 : x-=1 if x==px and y==py : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var px : OclAny := null; var py : OclAny := null; Sequence{px,py} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := (OclFile["System.in"]).readLine()->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var x : OclAny := null; (declareIfNecessary (test (logical_test (comparison (expr (atom (name y)))))) ,) Sequence{x,(testlist_star_expr (test (logical_test (comparison (expr (atom (name y)))))) ,)} := Sequence{0,0} ; for si : s do ( if x = px & y = py then ( break ) else skip ; if y /= py then ( if si = "U" & py > 0 then ( y := y + 1 ) else (if si = "D" & py < 0 then ( y := y - 1 ) else skip) ) else skip ; if x /= px then ( if si = "R" & px > 0 then ( x := x + 1 ) else (if si = "L" & px < 0 then ( x := x - 1 ) else skip) ) else skip) ; if x = px & y = py then ( execute ("YES")->display() ) else ( execute ("NO")->display() )) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): px,py=list(map(int,input().split())) s=input() max_x=max_y=0 min_x=min_y=0 for c in s : if c=="U" : max_y+=1 elif c=="D" : min_y-=1 elif c=="R" : max_x+=1 else : min_x-=1 if min_x<=px<=max_x and min_y<=py<=max_y : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var px : OclAny := null; var py : OclAny := null; Sequence{px,py} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : String := (OclFile["System.in"]).readLine() ; var max_x : OclAny := 0; var max_y : int := 0 ; var min_x : OclAny := 0; var min_y : int := 0 ; for c : s->characters() do ( if c = "U" then ( max_y := max_y + 1 ) else (if c = "D" then ( min_y := min_y - 1 ) else (if c = "R" then ( max_x := max_x + 1 ) else ( min_x := min_x - 1 ) ) ) ) ; if (min_x->compareTo(px)) <= 0 & (px <= max_x) & (min_y->compareTo(py)) <= 0 & (py <= max_y) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) for i in range(num): arr=input() arr=arr.split(" ") dir=input() x=int(arr[0]) y=int(arr[1]) isXEnough=0 isYEnough=0 if x>0 and y>0 : isXEnough=dir.count("R") isYEnough=dir.count("U") elif x==0 and y>0 : isYEnough=dir.count("U") elif x>0 and y==0 : isXEnough=dir.count("R") elif x<0 and y<0 : isXEnough=dir.count("L") isYEnough=dir.count("D") elif x==0 and y<0 : isYEnough=dir.count("D") elif x<0 and y==0 : isXEnough=dir.count("L") elif x<0 and y>0 : isXEnough=dir.count("L") isYEnough=dir.count("U") elif x>0 and y<0 : isXEnough=dir.count("R") isYEnough=dir.count("D") if(isXEnough>=abs(x)and isYEnough>=abs(y)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, num-1) do ( var arr : String := (OclFile["System.in"]).readLine() ; arr := arr.split(" ") ; var dir : String := (OclFile["System.in"]).readLine() ; var x : int := ("" + ((arr->first())))->toInteger() ; var y : int := ("" + ((arr[1+1])))->toInteger() ; var isXEnough : int := 0 ; var isYEnough : int := 0 ; if x > 0 & y > 0 then ( isXEnough := dir->count("R") ; isYEnough := dir->count("U") ) else (if x = 0 & y > 0 then ( isYEnough := dir->count("U") ) else (if x > 0 & y = 0 then ( isXEnough := dir->count("R") ) else (if x < 0 & y < 0 then ( isXEnough := dir->count("L") ; isYEnough := dir->count("D") ) else (if x = 0 & y < 0 then ( isYEnough := dir->count("D") ) else (if x < 0 & y = 0 then ( isXEnough := dir->count("L") ) else (if x < 0 & y > 0 then ( isXEnough := dir->count("L") ; isYEnough := dir->count("U") ) else (if x > 0 & y < 0 then ( isXEnough := dir->count("R") ; isYEnough := dir->count("D") ) else skip ) ) ) ) ) ) ) ; if ((isXEnough->compareTo((x)->abs())) >= 0 & (isYEnough->compareTo((y)->abs())) >= 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(): a,b=map(int,raw_input().split()) r0=a//b r1=a % b r2=float(a)/b print('%d %d %.5f')%(r0,r1,r2) if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation solve() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var r0 : int := a div b ; var r1 : int := a mod b ; var r2 : double := ("" + ((a)))->toReal() / b ; (expr (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '%d %d %.5f'))))))) )))) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name r0)))))) , (test (logical_test (comparison (expr (atom (name r1)))))) , (test (logical_test (comparison (expr (atom (name r2))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ai=lambda : list(map(int,input().split())) n,m=ai() from collections import defaultdict dd=defaultdict(list) for _ in range(m): l,r,d=ai() dd[l].append((r,d)) dd[r].append((l,-d)) pos=[None]*(n+1) for i in range(1,n+1): if pos[i]is not None : continue pos[i]=0 stack=[i] while stack : s=stack.pop() for p,d in dd[s]: if pos[p]is None : pos[p]=pos[s]+d stack.append(p) elif pos[p]!=pos[s]+d : print('No') exit() print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ai : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ai->apply() ; skip ; var dd : OclAny := defaultdict(OclType["Sequence"]) ; for _anon : Integer.subrange(0, m-1) do ( var l : OclAny := null; var r : OclAny := null; var d : OclAny := null; Sequence{l,r,d} := ai->apply() ; (expr (atom (name dd)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name l)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name r)))))) , (test (logical_test (comparison (expr (atom (name d))))))) )))))))) )))) ; (expr (atom (name dd)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name l)))))) , (test (logical_test (comparison (expr - (expr (atom (name d)))))))) )))))))) ))))) ; var pos : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (n + 1)) ; for i : Integer.subrange(1, n + 1-1) do ( if not(pos[i+1] <>= null) then ( continue ) else skip ; pos[i+1] := 0 ; var stack : Sequence := Sequence{ i } ; while stack do ( var s : OclAny := stack->last() ; stack := stack->front() ; for _tuple : dd[s+1] do (var _indx : int := 1; var p : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); if pos[p+1] <>= null then ( pos[p+1] := pos[s+1] + d ; execute ((p) : stack) ) else (if pos[p+1] /= pos[s+1] + d then ( execute ('No')->display() ; exit() ) else skip)))) ; execute ('Yes')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function,division a,b=(int(x)for x in raw_input().split()) print('{1:d}{2:d}{0:f}'.format(a/b,*divmod(a,b))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name raw_input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; execute (StringLib.interpolateStrings('{1:d}{2:d}{0:f}', Sequence{a / b, (argument * (test (logical_test (comparison (expr (atom (name divmod)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name b)))))))) ))))))))}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- str=input() numl=str.split(' ') a=int(numl[0]) b=int(numl[1]) print("{0}{1}{2:10f}".format(a//b,a % b,a/b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var OclType["String"] : String := (OclFile["System.in"]).readLine() ; var numl : String := ("" + (.split(' '))) ; var a : int := ("" + ((numl->first())))->toInteger() ; var b : int := ("" + ((numl[1+1])))->toInteger() ; execute (StringLib.interpolateStrings("{0}{1}{2:10f}", Sequence{a div b, a mod b, a / b}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=[int(s)for s in raw_input().split()] print("%d %d %f" %((a/b),(a % b),(float(a)/float(b)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := raw_input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; execute (StringLib.format("%d %d %f",Sequence{(a / b), (a mod b), (("" + ((a)))->toReal() / ("" + ((b)))->toReal())}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (a,b)=map(float,input().split()) A=int(a) B=int(b) print(int(A/B),A % B,format(a/b,'.5f')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{a, b} : Sequence := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; var A : int := ("" + ((a)))->toInteger() ; var B : int := ("" + ((b)))->toInteger() ; execute (("" + ((A / B)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): ans=0 x=1 y=2 while x<=4000000 : if x % 2==0 : ans+=x x,y=y,x+y return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : int := 0 ; var x : int := 1 ; var y : int := 2 ; while x <= 4000000 do ( if x mod 2 = 0 then ( ans := ans + x ) else skip ; Sequence{x,y} := Sequence{y,x + y}) ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxFreq(s,a,b): fre=[0 for i in range(10)] n=len(s) if(a>b): swap(a,b) for i in range(0,n,1): a=ord(s[i])-ord('0') fre[a]+=1 if(fre[a]==0 and fre[b]==0): return-1 elif(fre[a]>=fre[b]): return a else : return b if __name__=='__main__' : a=4 b=7 s="47744" print(maxFreq(s,a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := 4 ; b := 7 ; s := "47744" ; execute (maxFreq(s, a, b))->display() ) else skip; operation maxFreq(s : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var fre : Sequence := Integer.subrange(0, 10-1)->select(i | true)->collect(i | (0)) ; var n : int := (s)->size() ; if ((a->compareTo(b)) > 0) then ( swap(a, b) ) else skip ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( a := (s[i+1])->char2byte() - ('0')->char2byte() ; fre[a+1] := fre[a+1] + 1) ; if (fre[a+1] = 0 & fre[b+1] = 0) then ( return -1 ) else (if ((fre[a+1]->compareTo(fre[b+1])) >= 0) then ( return a ) else ( return b ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- SIZE=4 def productOfSingelDgt(n): if n>=0 and n<=9 : return True prime=[2,3,5,7] i=0 while i1 : while n % prime[i]==0 : n=n/prime[i] i+=1 return n==1 n=24 if productOfSingelDgt(n): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var SIZE : int := 4 ; skip ; n := 24 ; if productOfSingelDgt(n) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation productOfSingelDgt(n : OclAny) : OclAny pre: true post: true activity: if n >= 0 & n <= 9 then ( return true ) else skip ; var prime : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 7 }))) ; var i : int := 0 ; while (i->compareTo(SIZE)) < 0 & n > 1 do ( while n mod prime[i+1] = 0 do ( n := n / prime[i+1]) ; i := i + 1) ; return n = 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,m,k=map(int,input().split()) p=list(map(int,input().split())) p=[i-1 for i in p] i=0 ans=0 while icollect( _x | (OclType["int"])->apply(_x) ) ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; p := p->select(i | true)->collect(i | (i - 1)) ; var i : int := 0 ; var ans : int := 0 ; while (i->compareTo(m)) < 0 do ( var j : int := i ; var x : int := (p[j+1] - i) div k ; while (j->compareTo(m)) < 0 & x = (p[j+1] - i) div k do ( j := j + 1) ; ans := ans + 1 ; i := j) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil n,m,k=map(int,input().split()) p=[int(x)for x in input().split()] first=1 ; pos=0 ; ans=0 while poscollect( _x | (OclType["int"])->apply(_x) ) ; var p : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var first : int := 1; var pos : int := 0; var ans : int := 0 ; while (pos->compareTo(m)) < 0 do ( var page : OclAny := ceil((p[pos+1] - first + 1) / k) ; var l : int := first + k * (page - 1); var r : double := first + k * page - 1 ; (compound_stmt while (test (logical_test (logical_test (comparison (comparison (expr (atom (name pos)))) < (comparison (expr (atom (name m)))))) and (logical_test (comparison (comparison (comparison (expr (atom (name l)))) <= (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name pos)))))))) ]))))) <= (comparison (expr (atom (name r)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))) ; (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name count)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))) ;)) (stmt (compound_stmt while (test (logical_test (logical_test (comparison (comparison (expr (atom (name pos)))) < (comparison (expr (atom (name m)))))) and (logical_test (comparison (comparison (comparison (expr (atom (name l)))) <= (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name pos)))))))) ]))))) <= (comparison (expr (atom (name r)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name pos)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))) ; (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name count)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))) ;))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name r)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name count)))))))))))) (else_clause else : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name first)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name r))) + (expr (atom (number (integer 1))))))))))))))))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : n,m,k=map(int,input().split()) l=list(map(int,input().split())) i=0 operations=0 while icollect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var i : int := 0 ; var operations : int := 0 ; while (i->compareTo(m)) < 0 do ( var j : int := i ; var cu : int := (l[i+1] - 1 - j) div k ; while (i->compareTo(m)) < 0 & (l[i+1] - 1 - j) div k = cu do ( i := i + 1) ; operations := operations + 1) ; execute (operations)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import collections import heapq import decimal input=sys.stdin.readline n,m,k=(int(i)for i in input().split()) l=[int(i)for i in input().split()] i=0 c=0 c1=0 while(iselect(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var i : int := 0 ; var c : int := 0 ; var c1 : int := 0 ; while ((i->compareTo(m)) < 0) do ( var c2 : int := 0 ; var p : double := ((((l[i+1] - c1 - 1) div k) + 1) * k) + c1 ; for j : Integer.subrange(i, m-1) do ( if ((l[j+1]->compareTo(p)) <= 0) then ( c2 := c2 + 1 ) else ( break )) ; i := i + c2 ; c1 := c1 + c2 ; c := c + 1) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A=list(map(int,input().split())) S=[i for i in input()] S[A[1]-1]=S[A[1]-1].lower() print(*S,sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var S : Sequence := (OclFile["System.in"]).readLine()->select(i | true)->collect(i | (i)) ; S[A[1+1] - 1+1] := S[A[1+1] - 1+1]->toLowerCase() ; execute ((argument * (test (logical_test (comparison (expr (atom (name S))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import exit,setrecursionlimit from functools import reduce from itertools import* from collections import defaultdict from bisect import bisect def read(): return int(input()) def reads(): return[int(x)for x in input().split()] setrecursionlimit(1000000) INF=10**10 (N,M)=reads() edges=[[]for _ in range(N)] for _ in range(M): (L,R,D)=reads() (L,R)=(L-1,R-1) edges[L].append((R,D)) edges[R].append((L,-D)) visited=[False]*N place=[None]*N def walk(i): if visited[i]: return(place[i],place[i]) visited[i]=True (m,M)=(INF,-INF) for(j,d)in edges[i]: if visited[j]and place[j]!=place[i]+d : print("No") exit() place[j]=place[i]+d (x,y)=walk(j) (m,M)=(min(m,x),max(M,y)) return(m,M) for i in range(N): if not visited[i]: place[i]=0 (m,M)=walk(i) if M-m>10**9 : print("No") exit() print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; setrecursionlimit(1000000) ; var INF : double := (10)->pow(10) ; var Sequence{N, M} : OclAny := reads() ; var edges : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, M-1) do ( ; var Sequence{L, R, D} : OclAny := reads() ; var Sequence{L, R} : OclAny := Sequence{L - 1, R - 1} ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name L)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name R)))))) , (test (logical_test (comparison (expr (atom (name D))))))) )))))))) )))) ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name R)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name L)))))) , (test (logical_test (comparison (expr - (expr (atom (name D)))))))) )))))))) ))))) ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, N) ; var place : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, N) ; skip ; var Sequence{m, M} : OclAny := Sequence{INF, -INF}; operation read() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation reads() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation walk(i : OclAny) : OclAny pre: true post: true activity: if visited[i+1] then ( return Sequence{place[i+1], place[i+1]} ) else skip ; visited[i+1] := true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def naiveSolve(): return def main(): n,m,k=readIntArr() p=readIntArr() for i in range(m): p[i]-=1 discarded=0 nOperations=1 leftI=-1 for i,x in enumerate(p): if i==0 : leftI=i continue if(p[leftI]-discarded)//k!=(x-discarded)//k : nOperations+=1 discarded+=(i-leftI) leftI=i print(nOperations) return import sys input=sys.stdin.buffer.readline def oneLineArrayPrint(arr): print(' '.join([str(x)for x in arr])) def multiLineArrayPrint(arr): print('\n'.join([str(x)for x in arr])) def multiLineArrayOfArraysPrint(arr): print('\n'.join([' '.join([str(x)for x in y])for y in arr])) def readIntArr(): return[int(x)for x in input().split()] def makeArr(defaultValFactory,dimensionArr): dv=defaultValFactory ; da=dimensionArr if len(da)==1 : return[dv()for _ in range(da[0])] else : return[makeArr(dv,da[1 :])for _ in range(da[0])] def queryInteractive(l,r): print('?{}{}'.format(l,r)) sys.stdout.flush() return int(input()) def answerInteractive(x): print('!{}'.format(x)) sys.stdout.flush() inf=float('inf') MOD=998244353 from math import gcd,floor,ceil for _abc in range(1): main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := sys.stdin.buffer.readline ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; var MOD : int := 998244353 ; skip ; for _abc : Integer.subrange(0, 1-1) do ( main()); operation naiveSolve() pre: true post: true activity: return; operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := readIntArr() ; var p : OclAny := readIntArr() ; for i : Integer.subrange(0, m-1) do ( p[i+1] := p[i+1] - 1) ; var discarded : int := 0 ; var nOperations : int := 1 ; var leftI : int := -1 ; for _tuple : Integer.subrange(1, (p)->size())->collect( _indx | Sequence{_indx-1, (p)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); if i = 0 then ( leftI := i ; continue ) else skip ; if (p[leftI+1] - discarded) div k /= (x - discarded) div k then ( nOperations := nOperations + 1 ; discarded := discarded + (i - leftI) ; leftI := i ) else skip) ; execute (nOperations)->display() ; return; operation oneLineArrayPrint(arr : OclAny) pre: true post: true activity: execute (StringLib.sumStringsWithSeparator((arr->select(x | true)->collect(x | (("" + ((x)))))), ' '))->display(); operation multiLineArrayPrint(arr : OclAny) pre: true post: true activity: execute (StringLib.sumStringsWithSeparator((arr->select(x | true)->collect(x | (("" + ((x)))))), ' '))->display(); operation multiLineArrayOfArraysPrint(arr : OclAny) pre: true post: true activity: execute (StringLib.sumStringsWithSeparator((arr->select(y | true)->collect(y | (StringLib.sumStringsWithSeparator((y->select(x | true)->collect(x | (("" + ((x)))))), ' ')))), ' '))->display(); operation readIntArr() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation makeArr(defaultValFactory : OclAny, dimensionArr : OclAny) : OclAny pre: true post: true activity: var dv : OclAny := defaultValFactory; var da : OclAny := dimensionArr ; if (da)->size() = 1 then ( return Integer.subrange(0, da->first()-1)->select(_anon | true)->collect(_anon | (dv())) ) else ( return Integer.subrange(0, da->first()-1)->select(_anon | true)->collect(_anon | (makeArr(dv, da->tail()))) ); operation queryInteractive(l : OclAny, r : OclAny) : OclAny pre: true post: true activity: execute (StringLib.interpolateStrings('?{}{}', Sequence{l, r}))->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))) ; return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation answerInteractive(x : OclAny) pre: true post: true activity: execute (StringLib.interpolateStrings('!{}', Sequence{x}))->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[4,22,27,58,85,94,121,166,202,265,274,319,346,355,378,382,391,438,454,483,517,526,535,562,576,588,627,634,636,645] x=int(input()) print(a[x-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Sequence{4}->union(Sequence{22}->union(Sequence{27}->union(Sequence{58}->union(Sequence{85}->union(Sequence{94}->union(Sequence{121}->union(Sequence{166}->union(Sequence{202}->union(Sequence{265}->union(Sequence{274}->union(Sequence{319}->union(Sequence{346}->union(Sequence{355}->union(Sequence{378}->union(Sequence{382}->union(Sequence{391}->union(Sequence{438}->union(Sequence{454}->union(Sequence{483}->union(Sequence{517}->union(Sequence{526}->union(Sequence{535}->union(Sequence{562}->union(Sequence{576}->union(Sequence{588}->union(Sequence{627}->union(Sequence{634}->union(Sequence{636}->union(Sequence{ 645 }))))))))))))))))))))))))))))) ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (a[x - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) l=[4,22,27,58,85,94,121,166,202,265,274,319,346,355,378,382,391,438,454,483,517,526,535,562,576,588,627,634,636,645,648,654,663,666,690,706,728,729,762,778,825,852,861,895,913,915,922,958,985,1086,1111,1165] print(l[a-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{4}->union(Sequence{22}->union(Sequence{27}->union(Sequence{58}->union(Sequence{85}->union(Sequence{94}->union(Sequence{121}->union(Sequence{166}->union(Sequence{202}->union(Sequence{265}->union(Sequence{274}->union(Sequence{319}->union(Sequence{346}->union(Sequence{355}->union(Sequence{378}->union(Sequence{382}->union(Sequence{391}->union(Sequence{438}->union(Sequence{454}->union(Sequence{483}->union(Sequence{517}->union(Sequence{526}->union(Sequence{535}->union(Sequence{562}->union(Sequence{576}->union(Sequence{588}->union(Sequence{627}->union(Sequence{634}->union(Sequence{636}->union(Sequence{645}->union(Sequence{648}->union(Sequence{654}->union(Sequence{663}->union(Sequence{666}->union(Sequence{690}->union(Sequence{706}->union(Sequence{728}->union(Sequence{729}->union(Sequence{762}->union(Sequence{778}->union(Sequence{825}->union(Sequence{852}->union(Sequence{861}->union(Sequence{895}->union(Sequence{913}->union(Sequence{915}->union(Sequence{922}->union(Sequence{958}->union(Sequence{985}->union(Sequence{1086}->union(Sequence{1111}->union(Sequence{ 1165 }))))))))))))))))))))))))))))))))))))))))))))))))))) ; execute (l[a - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxZeros(n): if(n==0 or(n &(n-1))==0): return-1 setBit=1 prev=0 i=1 while(i<33): prev+=1 if((n & setBit)==setBit): setBit=setBit<<1 break setBit=setBit<<1 max0=-10**9 cur=prev for j in range(i+1,33): cur+=1 if((n & setBit)==setBit): if(max0<(cur-prev-1)): max0=cur-prev-1 prev=cur setBit=setBit<<1 return max0 n=549 print(maxZeros(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 549 ; execute (maxZeros(n))->display(); operation maxZeros(n : OclAny) : OclAny pre: true post: true activity: if (n = 0 or (MathLib.bitwiseAnd(n, (n - 1))) = 0) then ( return -1 ) else skip ; var setBit : int := 1 ; var prev : int := 0 ; var i : int := 1 ; while (i < 33) do ( prev := prev + 1 ; if ((MathLib.bitwiseAnd(n, setBit)) = setBit) then ( setBit := setBit * (2->pow(1)) ; break ) else skip ; setBit := setBit * (2->pow(1))) ; var max0 : double := (-10)->pow(9) ; var cur : int := prev ; for j : Integer.subrange(i + 1, 33-1) do ( cur := cur + 1 ; if ((MathLib.bitwiseAnd(n, setBit)) = setBit) then ( if ((max0->compareTo((cur - prev - 1))) < 0) then ( max0 := cur - prev - 1 ) else skip ; prev := cur ) else skip ; setBit := setBit * (2->pow(1))) ; return max0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[0,4,22,27,58,85,94,121,166,202,265,274,319,346,355,378,382,391,438,454,483,517,526,535,562,576,588,627,634,636,645,648,654,663,666,690,706,728,729,762,778,825,852,861,895,913,915,922,958,985,1086,1111,1165] print(a[int(input())]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Sequence{0}->union(Sequence{4}->union(Sequence{22}->union(Sequence{27}->union(Sequence{58}->union(Sequence{85}->union(Sequence{94}->union(Sequence{121}->union(Sequence{166}->union(Sequence{202}->union(Sequence{265}->union(Sequence{274}->union(Sequence{319}->union(Sequence{346}->union(Sequence{355}->union(Sequence{378}->union(Sequence{382}->union(Sequence{391}->union(Sequence{438}->union(Sequence{454}->union(Sequence{483}->union(Sequence{517}->union(Sequence{526}->union(Sequence{535}->union(Sequence{562}->union(Sequence{576}->union(Sequence{588}->union(Sequence{627}->union(Sequence{634}->union(Sequence{636}->union(Sequence{645}->union(Sequence{648}->union(Sequence{654}->union(Sequence{663}->union(Sequence{666}->union(Sequence{690}->union(Sequence{706}->union(Sequence{728}->union(Sequence{729}->union(Sequence{762}->union(Sequence{778}->union(Sequence{825}->union(Sequence{852}->union(Sequence{861}->union(Sequence{895}->union(Sequence{913}->union(Sequence{915}->union(Sequence{922}->union(Sequence{958}->union(Sequence{985}->union(Sequence{1086}->union(Sequence{1111}->union(Sequence{ 1165 })))))))))))))))))))))))))))))))))))))))))))))))))))) ; execute (a[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[0,4,22,27,58,85,94,121,166,202,265,274,319,346,355,378,382,391,438,454,483,517,526,535,562,576,588,627,634,636,645,648,654,663,666] print(l[n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{0}->union(Sequence{4}->union(Sequence{22}->union(Sequence{27}->union(Sequence{58}->union(Sequence{85}->union(Sequence{94}->union(Sequence{121}->union(Sequence{166}->union(Sequence{202}->union(Sequence{265}->union(Sequence{274}->union(Sequence{319}->union(Sequence{346}->union(Sequence{355}->union(Sequence{378}->union(Sequence{382}->union(Sequence{391}->union(Sequence{438}->union(Sequence{454}->union(Sequence{483}->union(Sequence{517}->union(Sequence{526}->union(Sequence{535}->union(Sequence{562}->union(Sequence{576}->union(Sequence{588}->union(Sequence{627}->union(Sequence{634}->union(Sequence{636}->union(Sequence{645}->union(Sequence{648}->union(Sequence{654}->union(Sequence{663}->union(Sequence{ 666 })))))))))))))))))))))))))))))))))) ; execute (l[n+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) k=[4,22,27,58,85,94,121,166,202,265,274,319,346,355,378,382,391,438,454,483,517,526,535,562,576,588,627,634,636,645] print(k[n-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : Sequence := Sequence{4}->union(Sequence{22}->union(Sequence{27}->union(Sequence{58}->union(Sequence{85}->union(Sequence{94}->union(Sequence{121}->union(Sequence{166}->union(Sequence{202}->union(Sequence{265}->union(Sequence{274}->union(Sequence{319}->union(Sequence{346}->union(Sequence{355}->union(Sequence{378}->union(Sequence{382}->union(Sequence{391}->union(Sequence{438}->union(Sequence{454}->union(Sequence{483}->union(Sequence{517}->union(Sequence{526}->union(Sequence{535}->union(Sequence{562}->union(Sequence{576}->union(Sequence{588}->union(Sequence{627}->union(Sequence{634}->union(Sequence{636}->union(Sequence{ 645 }))))))))))))))))))))))))))))) ; execute (k[n - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_CHARS=26 def isValid(count,k): val=0 for i in range(MAX_CHARS): if count[i]>0 : val+=1 return(k>=val) def kUniques(s,k): u=0 n=len(s) count=[0]*MAX_CHARS for i in range(n): if count[ord(s[i])-ord('a')]==0 : u+=1 count[ord(s[i])-ord('a')]+=1 if umax_window_size : max_window_size=curr_end-curr_start+1 max_window_start=curr_start print("Max substring is : "+s[max_window_start : max_window_start+max_window_size]+" with length "+str(max_window_size)) s="aabacbebebe" k=3 kUniques(s,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_CHARS : int := 26 ; skip ; skip ; s := "aabacbebebe" ; k := 3 ; kUniques(s, k); operation isValid(count : OclAny, k : OclAny) : OclAny pre: true post: true activity: var val : int := 0 ; for i : Integer.subrange(0, MAX_CHARS-1) do ( if count[i+1] > 0 then ( val := val + 1 ) else skip) ; return ((k->compareTo(val)) >= 0); operation kUniques(s : OclAny, k : OclAny) pre: true post: true activity: var u : int := 0 ; var n : int := (s)->size() ; count := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX_CHARS) ; for i : Integer.subrange(0, n-1) do ( if count[(s[i+1])->char2byte() - ('a')->char2byte()+1] = 0 then ( u := u + 1 ) else skip ; count[(s[i+1])->char2byte() - ('a')->char2byte()+1] := count[(s[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; if (u->compareTo(k)) < 0 then ( execute ("Not enough unique characters")->display() ; return ) else skip ; var curr_start : int := 0 ; var curr_end : int := 0 ; var max_window_size : int := 1 ; var max_window_start : int := 0 ; count := MatrixLib.elementwiseMult(Sequence{ 0 }, (count)->size()) ; count[(s->first())->char2byte() - ('a')->char2byte()+1] := count[(s->first())->char2byte() - ('a')->char2byte()+1] + 1 ; for i : Integer.subrange(1, n-1) do ( count[(s[i+1])->char2byte() - ('a')->char2byte()+1] := count[(s[i+1])->char2byte() - ('a')->char2byte()+1] + 1 ; curr_end := curr_end + 1 ; while not(isValid(count, k)) do ( count[(s[curr_start+1])->char2byte() - ('a')->char2byte()+1] := count[(s[curr_start+1])->char2byte() - ('a')->char2byte()+1] - 1 ; curr_start := curr_start + 1) ; if (curr_end - curr_start + 1->compareTo(max_window_size)) > 0 then ( max_window_size := curr_end - curr_start + 1 ; max_window_start := curr_start ) else skip) ; execute ("Max substring is : " + s.subrange(max_window_start+1, max_window_start + max_window_size) + " with length " + ("" + ((max_window_size))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : x=list(map(int,input().split(' '))) if x[0]% x[1]==0 : print(0) else : y=x[0]% x[1] print(min(x[3]*y,(x[1]-y)*x[2])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var x : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; if x->first() mod x[1+1] = 0 then ( execute (0)->display() ) else ( var y : int := x->first() mod x[1+1] ; execute (Set{x[3+1] * y, (x[1+1] - y) * x[2+1]}->min())->display() ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,a,b=map(int,input().split()) print(min(n % m*b,(m-n % m)*a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,m,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{n mod m * b, (m - n mod m) * a}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,a,b=[int(i)for i in input().split()] x=n//m y=x+1 u=n-x*m v=m*y-n w=u*b z=v*a print(min(w,z)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,m,a,b} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var x : int := n div m ; var y : int := x + 1 ; var u : double := n - x * m ; var v : double := m * y - n ; var w : double := u * b ; var z : double := v * a ; execute (Set{w, z}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict class XUnionFind(object): def __init__(self): self.table=defaultdict(lambda :-1) self.dtable=defaultdict(lambda : 0) def find(self,x): parent=self.table[x] if parent<0 : return x,0 else : root,distance=self.find(parent) new_distance=distance+self.dtable[x] self.table[x]=root self.dtable[x]=new_distance return root,new_distance def union(self,x1,x2,d=0): root1,distance1=self.find(x1) root2,distance2=self.find(x2) if root1==root2 : if distance2-distance1!=d : return False return True if root1exists( _x | result = _x ); attribute table : OclAny := defaultdict(lambda $$ : OclAny in (-1)); attribute dtable : OclAny := defaultdict(lambda $$ : OclAny in (0)); operation initialise() : pre: true post: true activity: self.table := defaultdict(lambda $$ : OclAny in (-1)) ; self.dtable := defaultdict(lambda $$ : OclAny in (0)); return self; operation find(x : OclAny) : OclAny pre: true post: true activity: var parent : OclAny := self.table[x+1] ; if parent < 0 then ( return x, 0 ) else ( var root : OclAny := null; var distance : OclAny := null; Sequence{root,distance} := self->indexOf(parent) - 1 ; var new_distance : OclAny := distance + self.dtable[x+1] ; self.table[x+1] := root ; self.dtable[x+1] := new_distance ; return root, new_distance ); operation union(x1 : OclAny,x2 : OclAny,d : int) : OclAny pre: true post: true activity: var root1 : OclAny := null; var distance1 : OclAny := null; Sequence{root1,distance1} := self->indexOf(x1) - 1 ; var root2 : OclAny := null; var distance2 : OclAny := null; Sequence{root2,distance2} := self->indexOf(x2) - 1 ; if root1 = root2 then ( if distance2 - distance1 /= d then ( return false ) else skip ; return true ) else skip ; if (root1->compareTo(root2)) < 0 then ( self.table[root1+1] := self.table[root1+1] + self.table[root2+1] ; self.table[root2+1] := root1 ; self.dtable[root2+1] := distance1 + d - distance2 ) else ( self.table[root2+1] := self.table[root2+1] + self.table[root1+1] ; self.table[root1+1] := root2 ; self.dtable[root1+1] := distance2 - d - distance1 ) ; return true; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( Sequence{N,M} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; lrd := Sequence{} ; for i : Integer.subrange(0, M-1) do ( execute ((input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) : lrd)) ; if solve(N, M, lrd) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation solve(N : OclAny, M : OclAny, lrd : OclAny) : OclAny pre: true post: true activity: var uf : XUnionFind := (XUnionFind.newXUnionFind()).initialise() ; for _tuple : lrd do (var _indx : int := 1; var l : OclAny := _tuple->at(_indx); _indx := _indx + 1; var r : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); var rc : OclAny := uf.union(l, r, d) ; if rc = false then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (initial_number_of_commentary_boxes,number_of_delegations,fee_to_build,fee_to_discard)=map(int,input().split(' ')) if initial_number_of_commentary_boxes % number_of_delegations==0 : print('0') else : number_of_boxes_to_discard=initial_number_of_commentary_boxes-initial_number_of_commentary_boxes//number_of_delegations*number_of_delegations total_fee_to_discard=fee_to_discard*number_of_boxes_to_discard number_of_boxes_to_build=(initial_number_of_commentary_boxes//number_of_delegations+1)*number_of_delegations-initial_number_of_commentary_boxes total_fee_to_build=fee_to_build*number_of_boxes_to_build print(min(total_fee_to_build,total_fee_to_discard)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{initial_number_of_commentary_boxes, number_of_delegations, fee_to_build, fee_to_discard} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; if initial_number_of_commentary_boxes mod number_of_delegations = 0 then ( execute ('0')->display() ) else ( var number_of_boxes_to_discard : double := initial_number_of_commentary_boxes - initial_number_of_commentary_boxes div number_of_delegations * number_of_delegations ; var total_fee_to_discard : double := fee_to_discard * number_of_boxes_to_discard ; var number_of_boxes_to_build : double := (initial_number_of_commentary_boxes div number_of_delegations + 1) * number_of_delegations - initial_number_of_commentary_boxes ; var total_fee_to_build : double := fee_to_build * number_of_boxes_to_build ; execute (Set{total_fee_to_build, total_fee_to_discard}->min())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() n,m,a,b=map(int,input().split()) print(min((m-n % m)*a,n % m*b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var n : OclAny := null; var m : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,m,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{(m - n mod m) * a, n mod m * b}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input().split() n=int(a[0]) d=int(a[1]) array=input().split() a=0 while a=array[i+1]: a+=(array[i]-array[i+1])//d+1 array[i+1]+=((array[i]-array[i+1])//d+1)*d i+=1 print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := input().split() ; var n : int := ("" + ((a->first())))->toInteger() ; var d : int := ("" + ((a[1+1])))->toInteger() ; var array : OclAny := input().split() ; a := 0 ; while (a->compareTo(n)) < 0 do ( array[a+1] := ("" + ((array[a+1])))->toInteger() ; a := a + 1) ; a := 0 ; var i : int := 0 ; while (i->compareTo(n - 1)) < 0 do ( if (array[i+1]->compareTo(array[i + 1+1])) >= 0 then ( a := a + (array[i+1] - array[i + 1+1]) div d + 1 ; array[i + 1+1] := array[i + 1+1] + ((array[i+1] - array[i + 1+1]) div d + 1) * d ) else skip ; i := i + 1) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_SIZE=int(1e6) prime=[True]*(MAX_SIZE+1) def seive(): p=2 while(p*p<=MAX_SIZE): if(prime[p]==True): for i in range(p*p,MAX_SIZE,p): prime[i]=False p+=1 def kthPrimeGreaterThanN(n,k): res=-1 for i in range(n+1,MAX_SIZE): if(prime[i]==True): k-=1 if(k==0): res=i break return res if __name__=='__main__' : n=2 k=15 seive() print(kthPrimeGreaterThanN(n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_SIZE : int := ("" + ((("1e6")->toReal())))->toInteger() ; var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (MAX_SIZE + 1)) ; skip ; skip ; if __name__ = '__main__' then ( n := 2 ; k := 15 ; seive() ; execute (kthPrimeGreaterThanN(n, k))->display() ) else skip; operation seive() pre: true post: true activity: var p : int := 2 ; while ((p * p->compareTo(MAX_SIZE)) <= 0) do ( if (prime[p+1] = true) then ( for i : Integer.subrange(p * p, MAX_SIZE-1)->select( $x | ($x - p * p) mod p = 0 ) do ( prime[i+1] := false) ) else skip ; p := p + 1); operation kthPrimeGreaterThanN(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var res : int := -1 ; for i : Integer.subrange(n + 1, MAX_SIZE-1) do ( if (prime[i+1] = true) then ( k := k - 1 ) else skip ; if (k = 0) then ( res := i ; break ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printFibonacciNumbers(n): f1=0 f2=1 if(n<1): return for x in range(0,n): print(f2,end=" ") next=f1+f2 f1=f2 f2=next printFibonacciNumbers(7) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; printFibonacciNumbers(7); operation printFibonacciNumbers(n : OclAny) pre: true post: true activity: var f1 : int := 0 ; var f2 : int := 1 ; if (n < 1) then ( return ) else skip ; for x : Integer.subrange(0, n-1) do ( execute (f2)->display() ; var next : int := f1 + f2 ; f1 := f2 ; f2 := next); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def remove_row_col(arr,n,x): for i in range(x,n): for j in range(x,n): print(arr[i][j],end=" ") print() if __name__=="__main__" : n=3 MAX=50 arr=[[1,2,3],[4,5,6],[7,8,9]] x=1 remove_row_col(arr,n,x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 3 ; var MAX : int := 50 ; arr := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))}->union(Sequence{ Sequence{7}->union(Sequence{8}->union(Sequence{ 9 })) })) ; x := 1 ; remove_row_col(arr, n, x) ) else skip; operation remove_row_col(arr : OclAny, n : OclAny, x : OclAny) pre: true post: true activity: for i : Integer.subrange(x, n-1) do ( for j : Integer.subrange(x, n-1) do ( execute (arr[i+1][j+1])->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() l=list() sss="" ll=list() for i in range(10): s=input() ll.append(s) for i in range(8): n="".join(n) l.append(n[0 : 10]) n=list(n) del n[0 : 10] for i in l : sss+=str(ll.index(i)) print(sss) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var l : Sequence := () ; var sss : String := "" ; var ll : Sequence := () ; for i : Integer.subrange(0, 10-1) do ( var s : String := (OclFile["System.in"]).readLine() ; execute ((s) : ll)) ; for i : Integer.subrange(0, 8-1) do ( n := StringLib.sumStringsWithSeparator((n), "") ; execute ((n.subrange(0+1, 10)) : l) ; n := (n)->characters() ; execute (n.subrange(0+1, 10))->isDeleted()) ; for i : l do ( sss := sss + ("" + ((ll->indexOf(i) - 1)))) ; execute (sss)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- full=input() bi=[input()for i in range(10)] password='' j=0 for i in range(10,81,10): index=full[j : i] password+=str(bi.index(index)) j+=10 print(password) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var full : String := (OclFile["System.in"]).readLine() ; var bi : Sequence := Integer.subrange(0, 10-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var password : String := '' ; var j : int := 0 ; for i : Integer.subrange(10, 81-1)->select( $x | ($x - 10) mod 10 = 0 ) do ( var index : OclAny := full.subrange(j+1, i) ; password := password + ("" + ((bi->indexOf(index) - 1))) ; j := j + 10) ; execute (password)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() l=[input()for _ in range(10)] print(*[l.index(n[i : i+10])for i in range(0,80,10)],sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var l : Sequence := Integer.subrange(0, 10-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name l)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))) : (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 10)))))))))) ])))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 80)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 10))))))))) )))))))) ])))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): s=input() hm={} for i in range(10): a=input() hm[a]=str(i) ans="" i=0 n=len(s) while iat(a) := ("" + ((i)))) ; var ans : String := "" ; var i : int := 0 ; var n : int := (s)->size() ; while (i->compareTo(n)) < 0 do ( ans := ans + hm[s.subrange(i+1, i + 10)+1] ; i := i + 10) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=list(input()) ans=[] for i in range(len(n)//10): tmp=n[: 10] n=n[10 :] ans.append(tmp) a2=[] for i in ans : a2.append(''.join(i)) ans=[] for i in range(10): ans.append(input()) s='' for i in a2 : s+=str(ans.index(i)) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, (n)->size() div 10-1) do ( var tmp : OclAny := n.subrange(1,10) ; n := n.subrange(10+1) ; execute ((tmp) : ans)) ; var a2 : Sequence := Sequence{} ; for i : ans do ( execute ((StringLib.sumStringsWithSeparator((i), '')) : a2)) ; ans := Sequence{} ; for i : Integer.subrange(0, 10-1) do ( execute (((OclFile["System.in"]).readLine()) : ans)) ; var s : String := '' ; for i : a2 do ( s := s + ("" + ((ans->indexOf(i) - 1)))) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter,defaultdict import sys sys.setrecursionlimit(10**5+10) input=sys.stdin.readline from math import factorial import heapq,bisect import math def calc(A,B,C,now_t): ans=A*now_t+B*math.sin(C*now_t*math.pi) return ans def main(): num,hint_num=map(int,input().split()) data=[list(map(int,input().split()))for i in range(hint_num)] graph_data=defaultdict(set) dist_data=defaultdict(int) for i in range(hint_num): l,r,d=data[i] graph_data[l].add(r) graph_data[r].add(l) dist_data[(l,r)]=d dist_data[(r,l)]=-1*d position=['x' for i in range(num+1)] flg=1 for i in range(1,num+1): if position[i]!='x' : continue position[i]=0 now_set=set() next_set=set() now_set.add(i) while len(now_set)>0 : for now_ele in now_set : for next_ele in graph_data[now_ele]: length=dist_data[(now_ele,next_ele)] if position[next_ele]=='x' : position[next_ele]=position[now_ele]+length next_set.add(next_ele) else : if position[next_ele]!=position[now_ele]+length : flg=0 break now_set=next_set next_set=set() if flg : print('Yes') else : print('No') if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(5) + 10) ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation calc(A : OclAny, B : OclAny, C : OclAny, now_t : OclAny) : OclAny pre: true post: true activity: var ans : double := A * now_t + B * (C * now_t * )->sin() ; return ans; operation main() pre: true post: true activity: var num : OclAny := null; var hint_num : OclAny := null; Sequence{num,hint_num} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var data : Sequence := Integer.subrange(0, hint_num-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var graph_data : OclAny := defaultdict(OclType["Set"]) ; var dist_data : OclAny := defaultdict(OclType["int"]) ; for i : Integer.subrange(0, hint_num-1) do ( var l : OclAny := null; var r : OclAny := null; var d : OclAny := null; Sequence{l,r,d} := data[i+1] ; (expr (atom (name graph_data)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name l)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name r)))))))) )))) ; (expr (atom (name graph_data)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)))))))) )))) ; dist_data[Sequence{l, r}+1] := d ; dist_data[Sequence{r, l}+1] := -1 * d) ; var position : Sequence := Integer.subrange(0, num + 1-1)->select(i | true)->collect(i | ('x')) ; var flg : int := 1 ; for i : Integer.subrange(1, num + 1-1) do ( if position[i+1] /= 'x' then ( continue ) else skip ; position[i+1] := 0 ; var now_set : Set := Set{}->union(()) ; var next_set : Set := Set{}->union(()) ; execute ((i) : now_set) ; while (now_set)->size() > 0 do ( for now_ele : now_set do ( for next_ele : graph_data[now_ele+1] do ( var length : OclAny := dist_data[Sequence{now_ele, next_ele}+1] ; if position[next_ele+1] = 'x' then ( position[next_ele+1] := position[now_ele+1] + length ; execute ((next_ele) : next_set) ) else ( if position[next_ele+1] /= position[now_ele+1] + length then ( flg := 0 ; break ) else skip ))) ; now_set := next_set ; next_set := Set{}->union(()))) ; if flg then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isLeap(y): return y % 4==0 and(y % 100!=0 or y % 400==0) flag2=False while True : a,b=map(int,input().split()) if a==0 : break if flag2 : print() flag2=True flag=True for y in range(a,b+1): if isLeap(y): print(y) flag=False if(flag): print("NA") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var flag2 : boolean := false ; while true do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 0 then ( break ) else skip ; if flag2 then ( execute (->display() ) else skip ; flag2 := true ; var flag : boolean := true ; for y : Integer.subrange(a, b + 1-1) do ( if isLeap(y) then ( execute (y)->display() ; flag := false ) else skip) ; if (flag) then ( execute ("NA")->display() ) else skip); operation isLeap(y : OclAny) : OclAny pre: true post: true activity: return y mod 4 = 0 & (y mod 100 /= 0 or y mod 400 = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) ks=[list(map(int,input().split()))for i in range(m)] p=list(map(int,input().split())) flag=[False for i in range(n)] ans=0 for bit in range(1<collect( _x | (OclType["int"])->apply(_x) ) ; var ks : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var flag : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (false)) ; var ans : int := 0 ; for bit : Integer.subrange(0, 1 * (2->pow(n))-1) do ( var a : boolean := true ; for i : Integer.subrange(0, n-1) do ( if MathLib.bitwiseAnd(bit, (1 * (2->pow(i)))) then ( flag[i+1] := true ) else ( flag[i+1] := false )) ; for i : Integer.subrange(0, m-1) do ( var count : int := 0 ; for j : Integer.subrange(0, (ks[i+1])->size()-1) do ( if j = 0 then ( continue ) else skip ; if flag[ks[i+1][j+1] - 1+1] then ( count := count + 1 ) else skip) ; if count mod 2 /= p[i+1] then ( a := false ) else skip) ; if a then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p=print b=1 for e in iter(input,'0 0'): b or p() b=f=0 ; s,t=map(int,e.split()) for y in range(s,t+1): if(y % 4==0)*(y % 100)or y % 400==0 : p(y); f=1 f or p('NA') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : OclAny := print ; var b : int := 1 ; for e : OclIterator.newOclIterator_Sequence(input, '0 0') do ((logical_test (logical_test (comparison (expr (atom (name b))))) or (logical_test (comparison (expr (atom (name p)) (trailer (arguments ( ))))))) ; b := 0; var f : int := 0; var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := (e.split())->collect( _x | (OclType["int"])->apply(_x) ) ; for y : Integer.subrange(s, t + 1-1) do ( if (y mod 4 = 0) * (y mod 100) or y mod 400 = 0 then ( p(y); f := 1 ) else skip) ; (logical_test (logical_test (comparison (expr (atom (name f))))) or (logical_test (comparison (expr (atom (name p)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NA'))))))) )))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- init=False while(True): A,B=[int(n)for n in input().split()] if A==0 and B==0 : exit() if init : print() aaa=False for a in range(A,B+1): if a % 4==0 : if a % 100==0 and a % 400!=0 : continue print(a) aaa=True if(not aaa): print("NA") init=True ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var init : boolean := false ; while (true) do ( var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := input().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; if A = 0 & B = 0 then ( exit() ) else skip ; if init then ( execute (->display() ) else skip ; var aaa : boolean := false ; for a : Integer.subrange(A, B + 1-1) do ( if a mod 4 = 0 then ( if a mod 100 = 0 & a mod 400 /= 0 then ( continue ) else skip ; execute (a)->display() ; aaa := true ) else skip) ; if (not(aaa)) then ( execute ("NA")->display() ) else skip ; init := true); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline write=sys.stdout.write def count(k): return k//4-k//100+k//400 def solve(i): a,b=map(int,readline().split()) if a==b==0 : return False if i : write("\n") ans=[] for k in range((a+3)//4*4,b+1,4): if k % 100>0 or k % 400==0 : ans.append(k) if ans : for k in ans : write("%d\n" % k) else : write("NA\n") return True i=0 while solve(i): i+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var write : OclAny := (OclFile["System.out"]).write ; skip ; skip ; i := 0 ; while solve(i) do ( i := i + 1); operation count(k : OclAny) : OclAny pre: true post: true activity: return k div 4 - k div 100 + k div 400; operation solve(i : OclAny) : OclAny pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = b & (b == 0) then ( return false ) else skip ; if i then ( write("\n") ) else skip ; var ans : Sequence := Sequence{} ; for k : Integer.subrange((a + 3) div 4 * 4, b + 1-1)->select( $x | ($x - (a + 3) div 4 * 4) mod 4 = 0 ) do ( if k mod 100 > 0 or k mod 400 = 0 then ( execute ((k) : ans) ) else skip) ; if ans then ( for k : ans do ( write(StringLib.format("%d\n",k))) ) else ( write("NA\n") ) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import division,print_function from sys import stdin,exit def main(readline=stdin.readline): leap_year=[not y % 4 and y % 100 or not y % 400 for y in range(3001)] separator='' while 1 : a,b=(int(s)for s in readline().split()) if not a and not b : exit() print(separator,end='') result='NA\n' for year,leap in enumerate(leap_year[a : b+1],a): if leap : print(year) result='' print(result,end='') separator='\n' main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; main(); operation main(readline : OclAny) pre: true post: true activity: if readline->oclIsUndefined() then readline := stdin.readline else skip; var leap_year : Sequence := Integer.subrange(0, 3001-1)->select(y | true)->collect(y | (not(y mod 4) & y mod 100 or not(y mod 400))) ; var separator : String := '' ; while 1 do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name readline)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; if not(a) & not(b) then ( exit() ) else skip ; execute (separator)->display() ; var result : String := 'NA ' ; for _tuple : Integer.subrange(1, (leap_year.subrange(a+1, b + 1), a)->size())->collect( _indx | Sequence{_indx-1, (leap_year.subrange(a+1, b + 1), a)->at(_indx)} ) do (var _indx : int := 1; var year : OclAny := _tuple->at(_indx); _indx := _indx + 1; var leap : OclAny := _tuple->at(_indx); if leap then ( execute (year)->display() ; result := '' ) else skip) ; execute (result)->display() ; separator := ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect n=int(input()) a=sorted(list(map(int,input().split()))) d=[0]*(n+1) for i in range(1,n+1): d[i]=d[i-1]+a[i-1] m=int(input()) b,c=[list(map(int,input().split()))for _ in[0,0]] for i in range(m): p=bisect.bisect_right(a,b[i]) print(['Yes','No'][d[p]toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(1, n + 1-1) do ( d[i+1] := d[i - 1+1] + a[i - 1+1]) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := Sequence{0}->union(Sequence{ 0 })->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for i : Integer.subrange(0, m-1) do ( var p : OclAny := bisect.bisect_right(a, b[i+1]) ; execute (Sequence{'Yes'}->union(Sequence{ 'No' })->select((d[p+1]->compareTo(c[i+1])) < 0))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect n=int(input()) a=sorted(list(map(int,input().split()))) d=[0]*(n+1) for i in range(1,n+1): d[i]=d[i-1]+a[i-1] m=int(input()) b,c=[list(map(int,input().split()))for _ in[0,0]] [print(['Yes','No'][d[bisect.bisect_right(a,b[i])]toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(1, n + 1-1) do ( d[i+1] := d[i - 1+1] + a[i - 1+1]) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := Sequence{0}->union(Sequence{ 0 })->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) m=int(input()) b=list(map(int,input().split())) a.sort() import bisect c=list(map(int,input().split())) d=[0]*(n+1) for i in range(n): d[i+1]=a[i] for i in range(n): d[i+1]+=d[i] for i in range(m): n=bisect.bisect_right(a,b[i]) n=d[n] if c[i]<=n : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; skip ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(0, n-1) do ( d[i + 1+1] := a[i+1]) ; for i : Integer.subrange(0, n-1) do ( d[i + 1+1] := d[i + 1+1] + d[i+1]) ; for i : Integer.subrange(0, m-1) do ( n := bisect.bisect_right(a, b[i+1]) ; n := d[n+1] ; if (c[i+1]->compareTo(n)) <= 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate from bisect import bisect_right as br n=int(input()) alst=sorted(map(int,input().split())) acc=list(accumulate(alst)) m=int(input()) blst=list(map(int,input().split())) clst=list(map(int,input().split())) for b,c in zip(blst,clst): index=br(alst,b) print(["No","Yes"][(acc[index-1]if index>0 else 0)>=c]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var alst : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var acc : Sequence := (accumulate(alst)) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var blst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var clst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for _tuple : Integer.subrange(1, blst->size())->collect( _indx | Sequence{blst->at(_indx), clst->at(_indx)} ) do (var _indx : int := 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); var index : OclAny := br(alst, b) ; execute (Sequence{"No"}->union(Sequence{ "Yes" })->select(((if index > 0 then acc[index - 1+1] else 0 endif)->compareTo(c)) >= 0))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- fre_x=[False]*(10**6+5) fre_y=[False]*(10**6+5) unique_x=[] unique_y=[] points=[] for _ in range(8): x,y=map(int,input().split()) points.append((x,y)) if not fre_x[x]: fre_x[x]=True unique_x.append(x) if not fre_y[y]: fre_y[y]=True unique_y.append(y) if len(unique_x)!=3 or len(unique_y)!=3 : print('ugly') exit() unique_x.sort() unique_y.sort() points.sort() index=0 count=0 for i in range(3): for j in range(3): if i==j==1 : continue count+=1 if unique_x[i]==points[index][0]and unique_y[j]==points[index][1]: index+=1 else : print('ugly') exit() print('respectable') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var fre_x : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, ((10)->pow(6) + 5)) ; var fre_y : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, ((10)->pow(6) + 5)) ; var unique_x : Sequence := Sequence{} ; var unique_y : Sequence := Sequence{} ; var points : Sequence := Sequence{} ; for _anon : Integer.subrange(0, 8-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{x, y}) : points) ; if not(fre_x[x+1]) then ( fre_x[x+1] := true ; execute ((x) : unique_x) ) else skip ; if not(fre_y[y+1]) then ( fre_y[y+1] := true ; execute ((y) : unique_y) ) else skip) ; if (unique_x)->size() /= 3 or (unique_y)->size() /= 3 then ( execute ('ugly')->display() ; exit() ) else skip ; unique_x := unique_x->sort() ; unique_y := unique_y->sort() ; points := points->sort() ; var index : int := 0 ; var count : int := 0 ; for i : Integer.subrange(0, 3-1) do ( for j : Integer.subrange(0, 3-1) do ( if i = j & (j == 1) then ( continue ) else skip ; count := count + 1 ; if unique_x[i+1] = points[index+1]->first() & unique_y[j+1] = points[index+1][1+1] then ( index := index + 1 ) else ( execute ('ugly')->display() ; exit() ))) ; execute ('respectable')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPalindrome(r): p=r[: :-1] return r==p def CheckStr(s): l=len(s) i=0 for i in range(2,l+1): if isPalindrome(s[0 : i])==True : break if i==(l+1): return False for i in range(2,l+1): if isPalindrome(s[l-i : l])==True : return True return False if __name__=="__main__" : s="abccbarfgdbd" if CheckStr(s)==True : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( s := "abccbarfgdbd" ; if CheckStr(s) = true then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; operation isPalindrome(r : OclAny) : OclAny pre: true post: true activity: var p : String := r(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; return r = p; operation CheckStr(s : OclAny) : OclAny pre: true post: true activity: var l : int := (s)->size() ; var i : int := 0 ; for i : Integer.subrange(2, l + 1-1) do ( if isPalindrome(s.subrange(0+1, i)) = true then ( break ) else skip) ; if i = (l + 1) then ( return false ) else skip ; for i : Integer.subrange(2, l + 1-1) do ( if isPalindrome(s.subrange(l - i+1, l)) = true then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumPowersK(n,k): sum=0 ; num=1 ; while(num<=n): sum+=num ; num*=k ; return sum ; def getSum(n,k): pwrK=sumPowersK(n,k); sumAll=(n*(n+1))/2 ; return(sumAll-pwrK); if __name__=="__main__" : n=10 ; k=3 ; print(getSum(n,k)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 10; k := 3; ; execute (getSum(n, k))->display(); ) else skip; operation sumPowersK(n : OclAny, k : OclAny) pre: true post: true activity: var sum : int := 0; var num : int := 1; ; while ((num->compareTo(n)) <= 0) do ( sum := sum + num; ; num := num * k;) ; return sum;; operation getSum(n : OclAny, k : OclAny) pre: true post: true activity: var pwrK : OclAny := sumPowersK(n, k); ; var sumAll : double := (n * (n + 1)) / 2; ; return (sumAll - pwrK);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkEightPoint(): list_points=[] list_x,list_y=[],[] for i in range(8): t=input().split() x=int(t[0]) y=int(t[1]) if x not in list_x : list_x.append(x) if y not in list_y : list_y.append(y) list_points.append((x,y)) if len(list_x)!=3 or len(list_y)!=3 : return False list_x=sorted(list_x) list_y=sorted(list_y) for i in range(3): for j in range(3): if i==1 and j==1 : if(list_x[i],list_y[j])in list_points : return False elif(list_x[i],list_y[j])not in list_points : return False return True res=checkEightPoint() if res : print("respectable") else : print("ugly") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var res : OclAny := checkEightPoint() ; if res then ( execute ("respectable")->display() ) else ( execute ("ugly")->display() ); operation checkEightPoint() : OclAny pre: true post: true activity: var list_points : Sequence := Sequence{} ; var list_x : OclAny := null; var list_y : OclAny := null; Sequence{list_x,list_y} := Sequence{Sequence{},Sequence{}} ; for i : Integer.subrange(0, 8-1) do ( var t : OclAny := input().split() ; var x : int := ("" + ((t->first())))->toInteger() ; var y : int := ("" + ((t[1+1])))->toInteger() ; if (list_x)->excludes(x) then ( execute ((x) : list_x) ) else skip ; if (list_y)->excludes(y) then ( execute ((y) : list_y) ) else skip ; execute ((Sequence{x, y}) : list_points)) ; if (list_x)->size() /= 3 or (list_y)->size() /= 3 then ( return false ) else skip ; var list_x : Sequence := list_x->sort() ; var list_y : Sequence := list_y->sort() ; for i : Integer.subrange(0, 3-1) do ( for j : Integer.subrange(0, 3-1) do ( if i = 1 & j = 1 then ( if (list_points)->includes(Sequence{list_x[i+1], list_y[j+1]}) then ( return false ) else skip ) else (if (list_points)->excludes(Sequence{list_x[i+1], list_y[j+1]}) then ( return false ) else skip))) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=set() y=set() points=[] for i in range(8): temp_x,temp_y=list(map(int,input().split())) x.add(temp_x) y.add(temp_y) points.append((temp_x,temp_y)) sorted_points=sorted(points) result="respectable" mid_point1=sorted_points[3] mid_point2=sorted_points[4] cond_x1=sorted_points[0][0]union(()) ; var y : Set := Set{}->union(()) ; var points : Sequence := Sequence{} ; for i : Integer.subrange(0, 8-1) do ( var temp_x : OclAny := null; var temp_y : OclAny := null; Sequence{temp_x,temp_y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((temp_x) : x) ; execute ((temp_y) : y) ; execute ((Sequence{temp_x, temp_y}) : points)) ; var sorted_points : Sequence := points->sort() ; var result : String := "respectable" ; var mid_point1 : OclAny := sorted_points[3+1] ; var mid_point2 : OclAny := sorted_points[4+1] ; var cond_x1 : boolean := (sorted_points->first()->first()->compareTo(sorted_points[3+1]->first())) < 0 & (sorted_points[3+1]->first() < sorted_points[5+1]->first()) ; var cond_x2 : boolean := (sorted_points[2+1]->first()->compareTo(sorted_points[4+1]->first())) < 0 & (sorted_points[4+1]->first() < sorted_points[7+1]->first()) ; var cond_x3 : boolean := (sorted_points[1+1]->first()->compareTo(sorted_points[3+1]->first())) < 0 & (sorted_points[3+1]->first() < sorted_points[6+1]->first()) ; var cond_y1 : boolean := (sorted_points->first()[1+1]->compareTo(sorted_points[1+1][1+1])) < 0 & (sorted_points[1+1][1+1] < sorted_points[2+1][1+1]) ; var cond_y2 : boolean := (sorted_points[3+1][1+1]->compareTo(sorted_points[1+1][1+1])) < 0 & (sorted_points[1+1][1+1] < sorted_points[4+1][1+1]) ; var cond_y3 : boolean := (sorted_points[5+1][1+1]->compareTo(sorted_points[6+1][1+1])) < 0 & (sorted_points[6+1][1+1] < sorted_points[7+1][1+1]) ; if (x)->size() /= 3 or (y)->size() /= 3 then ( execute ("ugly")->display() ) else (if cond_x1 & cond_x2 & cond_x3 & cond_y1 & cond_y2 & cond_y3 then ( execute ("respectable")->display() ) else ( execute ("ugly")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter arr=[] for i in range(0,8): arr.append(list(map(int,input().split(" ")))) freX=Counter([x[0]for x in arr]) freY=Counter([x[1]for x in arr]) if len(freX)!=3 or len(freY)!=3 : print("ugly") exit() perfectArray=[] for x in freX : for y in freY : perfectArray.append([x,y]) for item in arr : if(item in perfectArray): perfectArray.remove(item) if(len(perfectArray)>1): print("ugly") exit() maxX=max([x[0]for x in arr]) minX=min([x[0]for x in arr]) maxY=max([y[1]for y in arr]) minY=min([y[1]for y in arr]) suvivor=perfectArray[0] if suvivor[0]in range(minX+1,maxX)and suvivor[1]in range(minY+1,maxY): print("respectable") else : print("ugly") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var arr : Sequence := Sequence{} ; for i : Integer.subrange(0, 8-1) do ( execute ((((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ))) : arr)) ; var freX : OclAny := Counter(arr->select(x | true)->collect(x | (x->first()))) ; var freY : OclAny := Counter(arr->select(x | true)->collect(x | (x[1+1]))) ; if (freX)->size() /= 3 or (freY)->size() /= 3 then ( execute ("ugly")->display() ; exit() ) else skip ; var perfectArray : Sequence := Sequence{} ; for x : freX do ( for y : freY do ( execute ((Sequence{x}->union(Sequence{ y })) : perfectArray))) ; for item : arr do ( if ((perfectArray)->includes(item)) then ( execute ((item) /: perfectArray) ) else skip) ; if ((perfectArray)->size() > 1) then ( execute ("ugly")->display() ; exit() ) else skip ; var maxX : OclAny := (arr->select(x | true)->collect(x | (x->first())))->max() ; var minX : OclAny := (arr->select(x | true)->collect(x | (x->first())))->min() ; var maxY : OclAny := (arr->select(y | true)->collect(y | (y[1+1])))->max() ; var minY : OclAny := (arr->select(y | true)->collect(y | (y[1+1])))->min() ; var suvivor : OclAny := perfectArray->first() ; if (Integer.subrange(minX + 1, maxX-1))->includes(suvivor->first()) & (Integer.subrange(minY + 1, maxY-1))->includes(suvivor[1+1]) then ( execute ("respectable")->display() ) else ( execute ("ugly")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout int_in=lambda : int(stdin.readline()) arr_in=lambda :[int(x)for x in stdin.readline().split()] mat_in=lambda rows :[arr_in()for _ in range(rows)] str_in=lambda : stdin.readline().strip() out=lambda o : stdout.write("{}\n".format(o)) arr_out=lambda o : out(" ".join(map(str,o))) bool_out=lambda o : out("YES" if o else "NO") tests=lambda : range(1,int_in()+1) case_out=lambda i,o : out("Case #{}:{}".format(i,o)) import math def solve(a,b): result=float("inf") if a % b==0 : if(a//b)% 2==1 : result=min(result,b) x_intercept=a-b if x_intercept==0 : assert result!=float("inf") else : i=math.floor(x_intercept/(2*b)) if i>0 : size=x_intercept/(2*i) result=min(result,size) x_intercept=a+b i=math.floor(x_intercept/(2*b)) if i>0 : size=x_intercept/(2*i) result=min(result,size) return-1 if result==float("inf")else result if __name__=="__main__" : a,b=arr_in() out(solve(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var int_in : Function := lambda $$ : OclAny in (("" + ((stdin.readLine())))->toInteger()) ; var arr_in : Function := lambda $$ : OclAny in (stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) ; var mat_in : Function := lambda rows : OclAny in (Integer.subrange(0, rows-1)->select(_anon | true)->collect(_anon | (arr_in->apply()))) ; var str_in : Function := lambda $$ : OclAny in (stdin.readLine()->trim()) ; var out : Function := lambda o : OclAny in (stdout.write(StringLib.interpolateStrings("{}\n", Sequence{o}))) ; var arr_out : Function := lambda o : OclAny in (out->apply(StringLib.sumStringsWithSeparator(((o)->collect( _x | (OclType["String"])->apply(_x) )), " "))) ; var bool_out : Function := lambda o : OclAny in (out->apply(if o then "YES" else "NO" endif)) ; var tests : Function := lambda $$ : OclAny in (Integer.subrange(1, int_in->apply() + 1-1)) ; var case_out : Function := lambda i : OclAny, o : OclAny in (out->apply(StringLib.interpolateStrings("Case #{}:{}", Sequence{i, o}))) ; skip ; skip ; if __name__ = "__main__" then ( Sequence{a,b} := arr_in->apply() ; out(solve(a, b)) ) else skip; operation solve(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var result : double := ("" + (("inf")))->toReal() ; if a mod b = 0 then ( if (a div b) mod 2 = 1 then ( result := Set{result, b}->min() ) else skip ) else skip ; var x_intercept : double := a - b ; if x_intercept = 0 then ( assert result /= ("" + (("inf")))->toReal() do "assertion failed" ) else ( var i : double := (x_intercept / (2 * b))->floor() ; if i > 0 then ( var size : double := x_intercept / (2 * i) ; result := Set{result, size}->min() ) else skip ) ; x_intercept := a + b ; i := (x_intercept / (2 * b))->floor() ; if i > 0 then ( size := x_intercept / (2 * i) ; result := Set{result, size}->min() ) else skip ; return if result = ("" + (("inf")))->toReal() then -1 else result endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def process(a,b): if b>a : return-1 if a==b : return b if a>=b : if(a+b)//b % 2==0 : i=(a+b)//b if i==0 : i+=2 a1=(a+b)/i else : i=(a+b)//b-1 if i==0 : i+=2 a1=(a+b)/i if(a-b)//b % 2==0 : i=(a-b)//b if i==0 : a2=float('inf') else : a2=(a-b)/i else : i=(a-b)//b-1 if i==0 : a2=float('inf') else : a2=(a-b)/i return min(a1,a2) a,b=[int(x)for x in input().split()] print(process(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{a,b} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (process(a, b))->display(); operation process(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (b->compareTo(a)) > 0 then ( return -1 ) else skip ; if a = b then ( return b ) else skip ; if (a->compareTo(b)) >= 0 then ( if (a + b) div b mod 2 = 0 then ( var i : int := (a + b) div b ; if i = 0 then ( i := i + 2 ) else skip ; var a1 : double := (a + b) / i ) else ( i := (a + b) div b - 1 ; if i = 0 then ( i := i + 2 ) else skip ; a1 := (a + b) / i ) ; if (a - b) div b mod 2 = 0 then ( i := (a - b) div b ; if i = 0 then ( var a2 : double := ("" + (('inf')))->toReal() ) else ( a2 := (a - b) / i ) ) else ( i := (a - b) div b - 1 ; if i = 0 then ( a2 := ("" + (('inf')))->toReal() ) else ( a2 := (a - b) / i ) ) ; return Set{a1, a2}->min() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split(' ')[: 2]) mx=b n=(a-b)//(2*b) if n<0 : print(-1) exit(0) dx=a-(2*n+1)*b ddx=dx/(2*n+2) print(b+ddx) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split(' ').subrange(1,2))->collect( _x | (OclType["int"])->apply(_x) ) ; var mx : OclAny := b ; var n : int := (a - b) div (2 * b) ; if n < 0 then ( execute (-1)->display() ; exit(0) ) else skip ; var dx : double := a - (2 * n + 1) * b ; var ddx : double := dx / (2 * n + 2) ; execute (b + ddx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def distance(p1x : float,p1y : float,p2x : float,p2y : float)->float : x_distance_square=math.pow(p2x-p1x,2) y_distance_square=math.pow(p2y-p1y,2) distance_between_2points=math.sqrt(x_distance_square+y_distance_square) return distance_between_2points if __name__=='__main__' : x1,y1,x2,y2=map(float,input().split()) distance_1to2=distance(x1,y1,x2,y2) print(distance_1to2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; var distance var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["double"])->apply(_x) )to2 : OclAny := distance(x1, y1, x2, y2) ; execute (distancedistance(distance(distance(distancedistance(distance(distance(distancedistance(distance(distance(distancedistance(distance(distance(distancedistance(distance(distance(distancedistance(distance(distance(distancedistance(distance(distance var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["double"])->apply(_x) )to2)to2)to2to2)->display()to2)to2)to2to2)->display()to2)to2)to2to2)->display()to2)to2)to2to2)->display()to2)to2)to2to2)->display()to2)to2)to2to2)->display()to2)to2)to2to2)->display() ) else skip; operation distance(p1x : double, p1y : double, p2x : double, p2y : double) : double pre: true post: true activity: var x_distance_square : double := (p2x - p1x)->pow(2) ; var y_distance_square : double := (p2y - p1y)->pow(2) ; var distance_between:= (x_distance_square + y_distance_square)->sqrt()points : double := (x_distance_square + y_distance_square)->sqrt() ; return distance_between_2points; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x1,y1,x2,y2=map(float,raw_input().split()) print((x1-x2)**2+(y1-y2)**2)**0.5 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (raw_input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; (expr (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name x1))) - (expr (atom (name x2)))))))) ))) ** (expr (atom (number (integer 2))))) + (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name y1))) - (expr (atom (name y2)))))))) ))) ** (expr (atom (number (integer 2))))))))))) )))) ** (expr (atom (number 0.5)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import hypot x1,y1,x2,y2=map(float,input().strip().split()) print(hypot(x2-x1,y2-y1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input()->trim().split())->collect( _x | (OclType["double"])->apply(_x) ) ; execute (hypot(x2 - x1, y2 - y1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math x1,y1,x2,y2=map(float,input().split()) long=math.sqrt((x1-x2)**2+(y1-y2)**2) print("%.4f" %(long)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; var long : double := (((x1 - x2))->pow(2) + ((y1 - y2))->pow(2))->sqrt() ; execute (StringLib.format("%.4f",(long)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from io import StringIO import unittest import os sys.setrecursionlimit(999999999) def resolve(test_def_name=""): l_s=list(input()) ans=0 target=0 one_cnt=0 ans=0 for cnt,l in enumerate(l_s,1): if l=="1" : pattern1=pow(2,one_cnt,1000000007) pattern0=pow(3,len(l_s)-cnt,1000000007) ans+=pattern0*pattern1 % 1000000007 one_cnt+=1 pattern1=pow(2,one_cnt,1000000007) pattern0=pow(3,0,1000000007) ans+=pattern0*pattern1 % 1000000007 print(ans % 1000000007) class TestClass(unittest.TestCase): def assertIO(self,assert_input,output): stdout,sat_in=sys.stdout,sys.stdin sys.stdout,sys.stdin=StringIO(),StringIO(assert_input) resolve(sys._getframe().f_back.f_code.co_name) sys.stdout.seek(0) out=sys.stdout.read()[:-1] sys.stdout,sys.stdin=stdout,sat_in self.assertEqual(out,output) def test_input_1(self): test_input="""10""" output="""5""" self.assertIO(test_input,output) def test_input_2(self): test_input="""1111111111111111111""" output="""162261460""" self.assertIO(test_input,output) if __name__=="__main__" : if os.environ.get("USERNAME")is None : resolve() else : unittest.main() ------------------------------------------------------------ OCL File: --------- class TestClass extends unittest.TestCase { static operation newTestClass() : TestClass pre: true post: TestClass->exists( _x | result = _x ); operation assertIO(assert_input : OclAny,output : OclAny) pre: true post: true activity: var stdout : OclAny := null; var sat_in : OclAny := null; Sequence{stdout,sat_in} := Sequence{OclFile["System.out"],OclFile["System.in"]} ; var OclFile["System.out"] : OclAny := null; var OclFile["System.in"] : OclAny := null; Sequence{OclFile["System.out"],OclFile["System.in"]} := Sequence{StringIO(),StringIO(assert_input)} ; resolve(sys._getframe().f_back.f_code.co_name) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name seek) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))) ; var out : OclAny := sys.stdout.readAll()->front() ; var OclFile["System.out"] : OclAny := null; var OclFile["System.in"] : OclAny := null; Sequence{OclFile["System.out"],OclFile["System.in"]} := Sequence{stdout,sat_in} ; self.assertEqual(out, output); operation test_input operation test_input skip(self : OclAny) pre: true post: true activity: var test_input : String := (atom "" "10" "") ; output := (atom "" "5" "") ; self.assertIO(test_input, output); () pre: true post: true activity: var test_input : String := (atom "" "10" "") ; output := (atom "" "5" "") ; self.assertIO(test_input, output); operation test_inputself : OclAny() pre: true post: true activity: test_input := (atom "" "1111111111111111111" "") ; output := (atom "" "162261460" "") ; self.assertIO(test_input, output); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; sys.setrecursionlimit(999999999) ; skip ; skip ; if __name__ = "__main__" then ( if os.environ.get("USERNAME") <>= null then ( resolve() ) else ( unittest.main() ) ) else skip; operation resolve(test_def_name : String) pre: true post: true activity: if test_def_name->oclIsUndefined() then test_def_name := "" else skip; var l_s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var ans : int := 0 ; var target : int := 0 ; var one_cnt : int := 0 ; ans := 0 ; for _tuple : Integer.subrange(1, (l_s, 1)->size())->collect( _indx | Sequence{_indx-1, (l_s, 1)->at(_indx)} ) do (var _indx : int := 1; var cnt : OclAny := _tuple->at(_indx); _indx := _indx + 1; var l : OclAny := _tuple->at(_indx); if l = "1" then ( var pattern1 : double := (2)->pow(one_cnt) ; var pattern0 : double := (3)->pow((l_s)->size() - cnt) ; ans := ans + pattern0 * pattern1 mod 1000000007 ; one_cnt := one_cnt + 1 ) else skip) ; pattern1 := (2)->pow(one_cnt) ; pattern0 := (3)->pow(0) ; ans := ans + pattern0 * pattern1 mod 1000000007 ; execute (ans mod 1000000007)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def XandYandZintercept(A,B,C,D): x=-D/A y=-D/B z=-D/C return[x,y,z] A=2 B=5 C=7 D=8 print(XandYandZintercept(A,B,C,D)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; A := 2 ; B := 5 ; C := 7 ; D := 8 ; execute (XandYandZintercept(A, B, C, D))->display(); operation XandYandZintercept(A : OclAny, B : OclAny, C : OclAny, D : OclAny) : OclAny pre: true post: true activity: var x : double := -D / A ; var y : double := -D / B ; var z : double := -D / C ; return Sequence{x}->union(Sequence{y}->union(Sequence{ z })); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,W,H=map(int,input().split()) row,col=[0]*(H+1),[0]*(W+1) for _ in range(N): x,y,w=map(int,input().split()) row[max(0,y-w)]+=1 row[min(H,y+w)]-=1 col[max(0,x-w)]+=1 col[min(W,x+w)]-=1 flag1=flag2=True for i in range(H): row[i+1]+=row[i] flag1 &=row[i]>0 if flag1 : print("Yes") quit() for i in range(W): col[i+1]+=col[i] flag2 &=col[i]>0 if flag2 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var W : OclAny := null; var H : OclAny := null; Sequence{N,W,H} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var row : OclAny := null; var col : OclAny := null; Sequence{row,col} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, (H + 1)),MatrixLib.elementwiseMult(Sequence{ 0 }, (W + 1))} ; for _anon : Integer.subrange(0, N-1) do ( var x : OclAny := null; var y : OclAny := null; var w : OclAny := null; Sequence{x,y,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; row[Set{0, y - w}->max()+1] := row[Set{0, y - w}->max()+1] + 1 ; row[Set{H, y + w}->min()+1] := row[Set{H, y + w}->min()+1] - 1 ; col[Set{0, x - w}->max()+1] := col[Set{0, x - w}->max()+1] + 1 ; col[Set{W, x + w}->min()+1] := col[Set{W, x + w}->min()+1] - 1) ; var flag1 : OclAny := true; var flag2 : boolean := true ; for i : Integer.subrange(0, H-1) do ( row[i + 1+1] := row[i + 1+1] + row[i+1] ; flag1 := flag1 & row[i+1] > 0) ; if flag1 then ( execute ("Yes")->display() ; quit() ) else skip ; for i : Integer.subrange(0, W-1) do ( col[i + 1+1] := col[i + 1+1] + col[i+1] ; flag2 := flag2 & col[i+1] > 0) ; if flag2 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import hypot a,b,c,d=map(float,raw_input().split()) print(hypot((a-c),(b-d))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (raw_input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; execute (hypot((a - c), (b - d)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) k=int(input()) arr=["012","102","120","210","201","021"] n %=len(arr) print(arr[n][k]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Sequence{"012"}->union(Sequence{"102"}->union(Sequence{"120"}->union(Sequence{"210"}->union(Sequence{"201"}->union(Sequence{ "021" }))))) ; n := n mod (arr)->size() ; execute (arr[n+1][k+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=int(input()) if(x==1): if(n % 2==0): n-=1 x=2 else : x=0 n-=1 if(x==0): if n % 6==1 or n % 6==2 : print("1") elif n % 6==3 or n % 6==4 : print("2") else : print("0") elif(x==2): if n % 6==4 or n % 6==5 : print("1") elif n % 6==3 or n % 6==2 : print("0") else : print("2") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (x = 1) then ( if (n mod 2 = 0) then ( n := n - 1 ; x := 2 ) else ( x := 0 ; n := n - 1 ) ) else skip ; if (x = 0) then ( if n mod 6 = 1 or n mod 6 = 2 then ( execute ("1")->display() ) else (if n mod 6 = 3 or n mod 6 = 4 then ( execute ("2")->display() ) else ( execute ("0")->display() ) ) ) else (if (x = 2) then ( if n mod 6 = 4 or n mod 6 = 5 then ( execute ("1")->display() ) else (if n mod 6 = 3 or n mod 6 = 2 then ( execute ("0")->display() ) else ( execute ("2")->display() ) ) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=int(input()) if(x==1): if(n % 2==0): n-=1 x=2 else : x=0 n-=1 if(x==0): if n % 6==1 or n % 6==2 : print("1") elif n % 6==3 or n % 6==4 : print("2") else : print("0") elif(x==2): if n % 6==4 or n % 6==5 : print("1") elif n % 6==1 or n % 6==0 : print("2") else : print("0") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (x = 1) then ( if (n mod 2 = 0) then ( n := n - 1 ; x := 2 ) else ( x := 0 ; n := n - 1 ) ) else skip ; if (x = 0) then ( if n mod 6 = 1 or n mod 6 = 2 then ( execute ("1")->display() ) else (if n mod 6 = 3 or n mod 6 = 4 then ( execute ("2")->display() ) else ( execute ("0")->display() ) ) ) else (if (x = 2) then ( if n mod 6 = 4 or n mod 6 = 5 then ( execute ("1")->display() ) else (if n mod 6 = 1 or n mod 6 = 0 then ( execute ("2")->display() ) else ( execute ("0")->display() ) ) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() n,x=int(input())% 6,int(input()) p=["012","102","120","210","201","021"] print(p[n][x]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger() mod 6,("" + (((OclFile["System.in"]).readLine())))->toInteger()} ; var p : Sequence := Sequence{"012"}->union(Sequence{"102"}->union(Sequence{"120"}->union(Sequence{"210"}->union(Sequence{"201"}->union(Sequence{ "021" }))))) ; execute (p[n+1][x+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=int(input()) c=n % 6 if n % 2==0 : if x==2 : if c==0 or c==5 : print(2) elif c==1 or c==4 : print(1) else : print(0) elif x==1 : if c==1 or c==2 : print(2) elif c==0 or c==3 : print(1) else : print(0) else : if c==3 or c==4 : print(2) elif c==2 or c==5 : print(1) else : print(0) else : if x==2 : if c==0 or c==1 : print(2) elif c==2 or c==5 : print(1) else : print(0) elif x==1 : if c==4 or c==5 : print(2) elif c==0 or c==3 : print(1) else : print(0) else : if c==2 or c==3 : print(2) elif c==1 or c==4 : print(1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := n mod 6 ; if n mod 2 = 0 then ( if x = 2 then ( if c = 0 or c = 5 then ( execute (2)->display() ) else (if c = 1 or c = 4 then ( execute (1)->display() ) else ( execute (0)->display() ) ) ) else (if x = 1 then ( if c = 1 or c = 2 then ( execute (2)->display() ) else (if c = 0 or c = 3 then ( execute (1)->display() ) else ( execute (0)->display() ) ) ) else ( if c = 3 or c = 4 then ( execute (2)->display() ) else (if c = 2 or c = 5 then ( execute (1)->display() ) else ( execute (0)->display() ) ) ) ) ) else ( if x = 2 then ( if c = 0 or c = 1 then ( execute (2)->display() ) else (if c = 2 or c = 5 then ( execute (1)->display() ) else ( execute (0)->display() ) ) ) else (if x = 1 then ( if c = 4 or c = 5 then ( execute (2)->display() ) else (if c = 0 or c = 3 then ( execute (1)->display() ) else ( execute (0)->display() ) ) ) else ( if c = 2 or c = 3 then ( execute (2)->display() ) else (if c = 1 or c = 4 then ( execute (1)->display() ) else ( execute (0)->display() ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(a,b): if a+b==0 : return[""] if a>=5 and b<=4 : return[s+"A" for s in solve(a-1,b)] if b>=5 and a<=4 : return[s+"B" for s in solve(a,b-1)] res=[] if a>0 : res+=[s+"A" for s in solve(a-1,b)] if b>0 : res+=[s+"B" for s in solve(a,b-1)] return res while 1 : try : a,b=map(int,input().split()) except : break for s in sorted(solve(a,b)): print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while 1 do ( try ( Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )) catch (_e : OclException) do ( break) ; for s : solve(a, b)->sort() do ( execute (s)->display())); operation solve(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a + b = 0 then ( return Sequence{ "" } ) else skip ; if a >= 5 & b <= 4 then ( return solve(a - 1, b)->select(s | true)->collect(s | (s + "A")) ) else skip ; if b >= 5 & a <= 4 then ( return solve(a, b - 1)->select(s | true)->collect(s | (s + "B")) ) else skip ; var res : Sequence := Sequence{} ; if a > 0 then ( res := res + solve(a - 1, b)->select(s | true)->collect(s | (s + "A")) ) else skip ; if b > 0 then ( res := res + solve(a, b - 1)->select(s | true)->collect(s | (s + "B")) ) else skip ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,itertools PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") def get_games(game): a,b=game.count('A'),game.count('B') if(a==5 and b<4)or(b==5 and a<4)or a==b==5 or(a==6 and b==4)or(b==6 and a==4): games.add(game) elif max(a,b)<=4 or a==b==4 or(a==5 and b==4)or(b==5 and a==4): games.add(game) if game+'A' not in games : get_games(game+'A') if game+'B' not in games : get_games(game+'B') A,B=[int(_)for _ in input().split()] games=set() get_games("") ans=[] for game in games : if game.count('A')==A and game.count('B')==B : ans.append(game) for game in sorted(ans): print(game) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; skip ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var games : Set := Set{}->union(()) ; get_games("") ; var ans : Sequence := Sequence{} ; for game : games do ( if game->count('A') = A & game->count('B') = B then ( execute ((game) : ans) ) else skip) ; for game : ans->sort() do ( execute (game)->display()); operation get_games(game : OclAny) pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{game->count('A'),game->count('B')} ; if (a = 5 & b < 4) or (b = 5 & a < 4) or a = b & (b == 5) or (a = 6 & b = 4) or (b = 6 & a = 4) then ( execute ((game) : games) ) else (if Set{a, b}->max() <= 4 or a = b & (b == 4) or (a = 5 & b = 4) or (b = 5 & a = 4) then ( execute ((game) : games) ; if (games)->excludes(game + 'A') then ( get_games(game + 'A') ) else skip ; if (games)->excludes(game + 'B') then ( get_games(game + 'B') ) else skip ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dic={} dic[(0,0)]=[""] dic[(1,0)]=["A"] dic[(0,1)]=["B"] for s in range(2,9): for i in range(min(5,s+1)): j=s-i if j>=5 or j<=-1 : continue dic[(i,j)]=[] if i-1>=0 : dic[(i,j)]+=[lst+"A" for lst in dic[(i-1,j)]] if j-1>=0 : dic[(i,j)]+=[lst+"B" for lst in dic[(i,j-1)]] for i in range(4): dic[(5,i)]=[lst+"A" for lst in dic[(4,i)]] dic[(i,5)]=[lst+"B" for lst in dic[(i,4)]] dic[(5,4)]=[lst+"A" for lst in dic[(4,4)]] dic[(4,5)]=[lst+"B" for lst in dic[(4,4)]] dic[(5,5)]=[lst+"A" for lst in dic[(4,5)]]+[lst+"B" for lst in dic[(5,4)]] dic[(6,4)]=[lst+"A" for lst in dic[(5,4)]] dic[(4,6)]=[lst+"B" for lst in dic[(4,5)]] j,y=map(int,input().split()) print(*sorted(dic[(j,y)]),sep="\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dic : OclAny := Set{} ; dic[Sequence{0, 0}+1] := Sequence{ "" } ; dic[Sequence{1, 0}+1] := Sequence{ "A" } ; dic[Sequence{0, 1}+1] := Sequence{ "B" } ; for s : Integer.subrange(2, 9-1) do ( for i : Integer.subrange(0, Set{5, s + 1}->min()-1) do ( var j : double := s - i ; if j >= 5 or j <= -1 then ( continue ) else skip ; dic[Sequence{i, j}+1] := Sequence{} ; if i - 1 >= 0 then ( dic[Sequence{i, j}+1] := dic[Sequence{i, j}+1] + dic[Sequence{i - 1, j}+1]->select(lst | true)->collect(lst | (lst + "A")) ) else skip ; if j - 1 >= 0 then ( dic[Sequence{i, j}+1] := dic[Sequence{i, j}+1] + dic[Sequence{i, j - 1}+1]->select(lst | true)->collect(lst | (lst + "B")) ) else skip)) ; for i : Integer.subrange(0, 4-1) do ( dic[Sequence{5, i}+1] := dic[Sequence{4, i}+1]->select(lst | true)->collect(lst | (lst + "A")) ; dic[Sequence{i, 5}+1] := dic[Sequence{i, 4}+1]->select(lst | true)->collect(lst | (lst + "B"))) ; dic[Sequence{5, 4}+1] := dic[Sequence{4, 4}+1]->select(lst | true)->collect(lst | (lst + "A")) ; dic[Sequence{4, 5}+1] := dic[Sequence{4, 4}+1]->select(lst | true)->collect(lst | (lst + "B")) ; dic[Sequence{5, 5}+1] := dic[Sequence{4, 5}+1]->select(lst | true)->collect(lst | (lst + "A"))->union(dic[Sequence{5, 4}+1]->select(lst | true)->collect(lst | (lst + "B"))) ; dic[Sequence{6, 4}+1] := dic[Sequence{5, 4}+1]->select(lst | true)->collect(lst | (lst + "A")) ; dic[Sequence{4, 6}+1] := dic[Sequence{4, 5}+1]->select(lst | true)->collect(lst | (lst + "B")) ; var y : OclAny := null; Sequence{j,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name dic)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name j)))))) , (test (logical_test (comparison (expr (atom (name y))))))) )))))))) ])))))))) )))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ceil=lambda a,b :(a+b-1)//b N,K=map(int,input().split()) A=tuple(map(int,input().split())) l,r=0,max(A) while r-l>1 : m=(l+r)//2 if sum(ceil(x,m)-1 for x in A)>K : l=m else : r=m print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ceil : Function := lambda a : OclAny, b : OclAny in ((a + b - 1) div b) ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,(A)->max()} ; while r - l > 1 do ( var m : int := (l + r) div 2 ; if (((argument (test (logical_test (comparison (expr (expr (atom (name ceil)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x))))))) , (argument (test (logical_test (comparison (expr (atom (name m)))))))) )))) - (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name A))))))))->sum()->compareTo(K)) > 0 then ( var l : int := m ) else ( var r : int := m )) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def parse(j,y,p,J,Y): if j==J and y==Y : print(p) return elif j==5 and y<=3 or y==5 and j<=3 : return if j>J or y>Y : return parse(j+1,y,p+"A",J,Y) parse(j,y+1,p+"B",J,Y) J,Y=map(int,input().split()) parse(0,0,"",J,Y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{J,Y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; parse(0, 0, "", J, Y); operation parse(j : OclAny, y : OclAny, p : OclAny, J : OclAny, Y : OclAny) pre: true post: true activity: if j = J & y = Y then ( execute (p)->display() ; return ) else (if j = 5 & y <= 3 or y = 5 & j <= 3 then ( return ) else skip) ; if (j->compareTo(J)) > 0 or (y->compareTo(Y)) > 0 then ( return ) else skip ; parse(j + 1, y, p + "A", J, Y) ; parse(j, y + 1, p + "B", J, Y); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(v): n=0 for i in range(len(v)-1): n+=v[i] if n<=0 : return False return True n,W,H=map(int,input().split()) w=[0]*(W+1) h=[0]*(H+1) for _ in[0]*n : x,y,a=map(int,input().split()) w[max(0,x-a)]+=1 w[min(W,x+a)]-=1 h[max(0,y-a)]+=1 h[min(H,y+a)]-=1 print(['No','Yes'][f(w)or f(h)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var W : OclAny := null; var H : OclAny := null; Sequence{n,W,H} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (W + 1)) ; var h : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (H + 1)) ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, n) do ( var x : OclAny := null; var y : OclAny := null; var a : OclAny := null; Sequence{x,y,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; w[Set{0, x - a}->max()+1] := w[Set{0, x - a}->max()+1] + 1 ; w[Set{W, x + a}->min()+1] := w[Set{W, x + a}->min()+1] - 1 ; h[Set{0, y - a}->max()+1] := h[Set{0, y - a}->max()+1] + 1 ; h[Set{H, y + a}->min()+1] := h[Set{H, y + a}->min()+1] - 1) ; execute (Sequence{'No'}->union(Sequence{ 'Yes' })->select(f(w) or f(h)))->display(); operation f(v : OclAny) : OclAny pre: true post: true activity: var n : int := 0 ; for i : Integer.subrange(0, (v)->size() - 1-1) do ( n := n + v[i+1] ; if n <= 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys Ans=[] def solve(j,y,score=''): if score.count('A')==j and score.count('B')==y : Ans.append(score) return if score.count('A')==5 and score.count('B')<4 or score.count('A')<4 and score.count('B')==5 : return if score.count('A')oclIsUndefined() then score := '' else skip; if score->count('A') = j & score->count('B') = y then ( execute ((score) : Ans) ; return ) else skip ; if score->count('A') = 5 & score->count('B') < 4 or score->count('A') < 4 & score->count('B') = 5 then ( return ) else skip ; if (score->count('A')->compareTo(j)) < 0 then ( solve(j, y, score + 'A') ) else skip ; if (score->count('B')->compareTo(y)) < 0 then ( solve(j, y, score + 'B') ) else skip; operation main(args : OclAny) pre: true post: true activity: Sequence{j,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; solve(j, y) ; execute ((argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name Ans)))))))) )))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- xp0,yp0,xp1,yp1=map(int,input().split()) q=int(input()) xp1=complex(xp1-xp0,yp1-yp0) eps=1e-8 for _ in range(q): x,y=map(int,input().split()) xp2=complex(x-xp0,y-yp0) temp=xp1.conjugate()*xp2 dot=temp.real cross=temp.imag if abs(cross)0 : if abs(xp1)>=abs(xp2): print("ON_SEGMENT") else : print("ONLINE_FRONT") else : print("ONLINE_BACK") elif cross>0 : print("COUNTER_CLOCKWISE") else : print("CLOCKWISE") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var xp0 : OclAny := null; var yp0 : OclAny := null; var xp1 : OclAny := null; var yp1 : OclAny := null; Sequence{xp0,yp0,xp1,yp1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var xp1 : OclAny := complex(xp1 - xp0, yp1 - yp0) ; var eps : double := ("1e-8")->toReal() ; for _anon : Integer.subrange(0, q-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var xp2 : OclAny := complex(x - xp0, y - yp0) ; var temp : double := xp1.conjugate() * xp2 ; var dot : OclAny := temp.real ; var cross : OclAny := temp.imag ; if ((cross)->abs()->compareTo(eps)) < 0 then ( if dot = 0 then ( execute ("ON_SEGMENT")->display() ) else (if dot > 0 then ( if ((xp1)->abs()->compareTo((xp2)->abs())) >= 0 then ( execute ("ON_SEGMENT")->display() ) else ( execute ("ONLINE_FRONT")->display() ) ) else ( execute ("ONLINE_BACK")->display() ) ) ) else (if cross > 0 then ( execute ("COUNTER_CLOCKWISE")->display() ) else ( execute ("CLOCKWISE")->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt xp0,yp0,xp1,yp1=map(int,input().split()) a=[xp0,yp0] b=[xp1,yp1] q=int(input()) CCW={1 : 'COUNTER_CLOCKWISE',2 : 'CLOCKWISE',3 : 'ONLINE_BACK',4 : 'ONLINE_FRONT',5 : 'ON_SEGMENT',} def dot(a,b): return sum([i*j for i,j in zip(a,b)]) def sub(a,b): return[a[0]-b[0],a[1]-b[1]] def cross(a,b): return a[0]*b[1]-a[1]*b[0] def _abs(a): return sqrt(a[0]**2+a[1]**2) def ccw(a,b,c): x=sub(b,a) y=sub(c,a) if cross(x,y)>0 : return 1 if cross(x,y)<0 : return 2 if dot(x,y)<0 : return 3 if _abs(x)<_abs(y): return 4 return 5 for i in range(q): c=list(map(int,input().split())) print(CCW[ccw(a,b,c)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var xp0 : OclAny := null; var yp0 : OclAny := null; var xp1 : OclAny := null; var yp1 : OclAny := null; Sequence{xp0,yp0,xp1,yp1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{xp0}->union(Sequence{ yp0 }) ; var b : Sequence := Sequence{xp1}->union(Sequence{ yp1 }) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var CCW : Map := Map{ 1 |-> 'COUNTER_CLOCKWISE' }->union(Map{ 2 |-> 'CLOCKWISE' }->union(Map{ 3 |-> 'ONLINE_BACK' }->union(Map{ 4 |-> 'ONLINE_FRONT' }->union((dictorsetmaker (test (logical_test (comparison (expr (atom (number (integer 5))))))) : (test (logical_test (comparison (expr (atom 'ON_SEGMENT'))))) ,))))) ; skip ; skip ; skip ; skip ; skip ; for i : Integer.subrange(0, q-1) do ( c := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (CCW[ccw(a, b, c)+1])->display()); operation dot(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), b->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let j : OclAny = _tuple->at(2) in (i * j)))->sum(); operation sub(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return Sequence{a->first() - b->first()}->union(Sequence{ a[1+1] - b[1+1] }); operation cross(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a->first() * b[1+1] - a[1+1] * b->first(); operation _abs(a : OclAny) : OclAny pre: true post: true activity: return sqrt((a->first())->pow(2) + (a[1+1])->pow(2)); operation ccw(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: var x : OclAny := sub(b, a) ; var y : OclAny := sub(c, a) ; if cross(x, y) > 0 then ( return 1 ) else skip ; if cross(x, y) < 0 then ( return 2 ) else skip ; if dot(x, y) < 0 then ( return 3 ) else skip ; if (_abs(x)->compareTo(_abs(y))) < 0 then ( return 4 ) else skip ; return 5; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math eps=10**-8 line=input() x1,y1,x2,y2=list(map(int,line.split())) line=input() q=int(line) pts=[] for _ in range(0,q): line=input() x,y=list(map(int,line.split())) pts+=[[x,y]] def solve(): l1=math.sqrt((x1-x2)**2+(y1-y2)**2) for x,y in pts : l2=math.sqrt((x-x1)**2+(y-y1)**2) dx=(x2-x1)/l1 dy=(y2-y1)/l1 ip=(x-x1)*(x2-x1)+(y-y1)*(y2-y1) sine=(x-x1)*(y2-y1)-(y-y1)*(x2-x1) if sine<0.0 : print("COUNTER_CLOCKWISE") elif sine>0.0 : print("CLOCKWISE") elif abs(ip-l1*l2)pow(-8) ; var line : String := (OclFile["System.in"]).readLine() ; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := ((line.split())->collect( _x | (OclType["int"])->apply(_x) )) ; line := (OclFile["System.in"]).readLine() ; var q : int := ("" + ((line)))->toInteger() ; var pts : Sequence := Sequence{} ; for _anon : Integer.subrange(0, q-1) do ( line := (OclFile["System.in"]).readLine() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((line.split())->collect( _x | (OclType["int"])->apply(_x) )) ; pts := pts + Sequence{ Sequence{x}->union(Sequence{ y }) }) ; skip ; solve(); operation solve() pre: true post: true activity: var l1 : double := (((x1 - x2))->pow(2) + ((y1 - y2))->pow(2))->sqrt() ; for _tuple : pts do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); var l2 : double := (((x - x1))->pow(2) + ((y - y1))->pow(2))->sqrt() ; var dx : double := (x2 - x1) / l1 ; var dy : double := (y2 - y1) / l1 ; var ip : double := (x - x1) * (x2 - x1) + (y - y1) * (y2 - y1) ; var sine : double := (x - x1) * (y2 - y1) - (y - y1) * (x2 - x1) ; if sine < 0.0 then ( execute ("COUNTER_CLOCKWISE")->display() ) else (if sine > 0.0 then ( execute ("CLOCKWISE")->display() ) else (if ((ip - l1 * l2)->abs()->compareTo(eps)) < 0 then ( if (l1->compareTo(l2)) < 0 then ( execute ("ONLINE_FRONT")->display() ) else ( execute ("ON_SEGMENT")->display() ) ) else (if (ip + l1 * l2->compareTo(eps)) < 0 then ( execute ("ONLINE_BACK")->display() ) else skip ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from enum import Enum from math import sqrt class Position(Enum): COUNTER_CLOCKWISE=0 CLOCKWISE=1 ONLINE_BACK=2 ONLINE_FRONT=3 ON_SEGMENT=4 def dot(v1,v2): x1,y1=v1 x2,y2=v2 return x1*x2+y1*y2 def length(v): x,y=v return sqrt(x**2+y**2) def orthogonal(v): x,y=v return-y,x def ccw(v1,v2): d1=dot(v1,v2) d2=dot(orthogonal(v1),v2) if d2>0 : return Position.COUNTER_CLOCKWISE elif d2<0 : return Position.CLOCKWISE elif d1<0 : return Position.ONLINE_BACK else : if length(v1)>=length(v2): return Position.ON_SEGMENT else : return Position.ONLINE_FRONT def run(): x0,y0,x1,y1=[int(i)for i in input().split()] q=int(input()) for _ in range(q): x2,y2=[int(i)for i in input().split()] pos=ccw((x1-x0,y1-y0),(x2-x0,y2-y0)) print(pos.name) if __name__=='__main__' : run() ------------------------------------------------------------ OCL File: --------- class Position { static operation newPosition() : Position pre: true post: Position->exists( _x | result = _x ); static attribute COUNTER_CLOCKWISE : int := 0; static attribute CLOCKWISE : int := 1; static attribute ONLINE_BACK : int := 2; static attribute ONLINE_FRONT : int := 3; static attribute ON_SEGMENT : int := 4; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( run() ) else skip; operation dot(v1 : OclAny, v2 : OclAny) : OclAny pre: true post: true activity: var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := v1 ; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x2,y2} := v2 ; return x1 * x2 + y1 * y2; operation length(v : OclAny) : OclAny pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := v ; return sqrt((x)->pow(2) + (y)->pow(2)); operation orthogonal(v : OclAny) : OclAny pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := v ; return -y, x; operation ccw(v1 : OclAny, v2 : OclAny) : OclAny pre: true post: true activity: var d1 : OclAny := dot(v1, v2) ; var d2 : OclAny := dot(orthogonal(v1), v2) ; if d2 > 0 then ( return (Position.newPosition()).initialise.COUNTER_CLOCKWISE ) else (if d2 < 0 then ( return (Position.newPosition()).initialise.CLOCKWISE ) else (if d1 < 0 then ( return (Position.newPosition()).initialise.ONLINE_BACK ) else ( if (length(v1)->compareTo(length(v2))) >= 0 then ( return (Position.newPosition()).initialise.ON_SEGMENT ) else ( return (Position.newPosition()).initialise.ONLINE_FRONT ) ) ) ) ; operation run() pre: true post: true activity: var x0 : OclAny := null; var y0 : OclAny := null; var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x0,y0,x1,y1} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x2,y2} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var pos : OclAny := ccw(Sequence{x1 - x0, y1 - y0}, Sequence{x2 - x0, y2 - y0}) ; execute (pos.name)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import cmath EPS=1e-4 def OuterProduct(one,two): tmp=one.conjugate()*two return tmp.imag def InnerProduct(one,two): tmp=one.conjugate()*two return tmp.real def IsOnSegment(point,begin,end): if abs(OuterProduct(begin-point,end-point))<=EPS and InnerProduct(begin-point,end-point)<=EPS : return True else : return False def CCW(p,q,r): one,two=q-p,r-q if OuterProduct(one,two)>-EPS : return True else : return False def solve(p,q,r): if abs(OuterProduct(q-r,p-r))<=EPS : if InnerProduct(q-r,p-r)<=EPS : return "ON_SEGMENT" elif abs(p-r)toReal() ; skip ; skip ; skip ; skip ; skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; Sequence{p,q} := Sequence{complex(a, b),complex(c, d)} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; r := complex(x, y) ; execute (solve(p, q, r))->display()); operation OuterProduct(one : OclAny, two : OclAny) : OclAny pre: true post: true activity: var tmp : double := one.conjugate() * two ; return tmp.imag; operation InnerProduct(one : OclAny, two : OclAny) : OclAny pre: true post: true activity: tmp := one.conjugate() * two ; return tmp.real; operation IsOnSegment(point : OclAny, begin : OclAny, end : OclAny) : OclAny pre: true post: true activity: if ((OuterProduct(begin - point, end - point))->abs()->compareTo(EPS)) <= 0 & (InnerProduct(begin - point, end - point)->compareTo(EPS)) <= 0 then ( return true ) else ( return false ); operation CCW(p : OclAny, q : OclAny, r : OclAny) : OclAny pre: true post: true activity: Sequence{one,two} := Sequence{q - p,r - q} ; if (OuterProduct(one, two)->compareTo(-EPS)) > 0 then ( return true ) else ( return false ); operation solve(p : OclAny, q : OclAny, r : OclAny) : OclAny pre: true post: true activity: if ((OuterProduct(q - r, p - r))->abs()->compareTo(EPS)) <= 0 then ( if (InnerProduct(q - r, p - r)->compareTo(EPS)) <= 0 then ( return "ON_SEGMENT" ) else (if ((p - r)->abs()->compareTo((q - r)->abs())) < 0 then ( return "ONLINE_BACK" ) else ( return "ONLINE_FRONT" ) ) ) else (if CCW(p, q, r) then ( return "COUNTER_CLOCKWISE" ) else ( return "CLOCKWISE" ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def getMaxValue(arr,arr_size): if(arr_size<2): return 0 first=-sys.maxsize-1 second=-sys.maxsize-1 for i in range(arr_size): if(arr[i]>first): second=first first=arr[i] elif(arr[i]>second and arr[i]!=first): second=arr[i] if(second==-sys.maxsize-1): return 0 else : return second if __name__=='__main__' : arr=[4,5,1,8] n=len(arr) print(getMaxValue(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{4}->union(Sequence{5}->union(Sequence{1}->union(Sequence{ 8 }))) ; var n : int := (arr)->size() ; execute (getMaxValue(arr, n))->display() ) else skip; operation getMaxValue(arr : OclAny, arr_size : OclAny) : OclAny pre: true post: true activity: if (arr_size < 2) then ( return 0 ) else skip ; var first : double := -(trailer . (name maxsize)) - 1 ; var second : double := -(trailer . (name maxsize)) - 1 ; for i : Integer.subrange(0, arr_size-1) do ( if ((arr[i+1]->compareTo(first)) > 0) then ( second := first ; first := arr[i+1] ) else (if ((arr[i+1]->compareTo(second)) > 0 & arr[i+1] /= first) then ( second := arr[i+1] ) else skip)) ; if (second = -(trailer . (name maxsize)) - 1) then ( return 0 ) else ( return second ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=1000000007 def Sum(N): val=N*(N+1) val=val % MOD return val def sumX(N,M,K): for i in range(M): N=int(Sum(K+N)) N=N % MOD return N if __name__=="__main__" : N,M,K=1,2,3 print(sumX(N,M,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : int := 1000000007 ; skip ; skip ; if __name__ = "__main__" then ( Sequence{N,M,K} := Sequence{1,2,3} ; execute (sumX(N, M, K))->display() ) else skip; operation Sum(N : OclAny) : OclAny pre: true post: true activity: var val : double := N * (N + 1) ; val := val mod MOD ; return val; operation sumX(N : OclAny, M : OclAny, K : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, M-1) do ( N := ("" + ((Sum(K + N))))->toInteger()) ; N := N mod MOD ; return N; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(lis,k,mid): for i in lis : if(i % mid==0): k+=1 k-=(i//mid) return k>=0 n,k=map(int,input().split()) lis=list(map(int,input().split())) a,b=1,max(lis) ans=b while(a<=b): mid=(a+b)//2 if(check(lis,k,mid)): ans=mid b=mid-1 else : a=mid+1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; lis := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{1,(lis)->max()} ; var ans : OclAny := b ; while ((a->compareTo(b)) <= 0) do ( mid := (a + b) div 2 ; if (check(lis, k, mid)) then ( ans := mid ; var b : double := mid - 1 ) else ( var a : OclAny := mid + 1 )) ; execute (ans)->display(); operation check(lis : OclAny, k : OclAny, mid : OclAny) : OclAny pre: true post: true activity: for i : lis do ( if (i mod mid = 0) then ( k := k + 1 ) else skip ; k := k - (i div mid)) ; return k >= 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def findNumbers(a,b): __gcd=gcd(a,b); print((a//__gcd),(b//__gcd)); if __name__=="__main__" : a=12 ; b=16 ; findNumbers(a,b); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( a := 12; b := 16; ; findNumbers(a, b); ) else skip; operation findNumbers(a : OclAny, b : OclAny) pre: true post: true activity: var __gcd : OclAny := gcd(a, b); ; execute ((a div __gcd))->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def productsDistinct(N): s="" while(N): s+=chr(N % 10+ord('0')) N//=10 s=s[: :-1] sz=len(s) se=[] for i in range(sz): product=1 for j in range(i,sz,1): product*=ord(s[j])-ord('0') for p in range(len(se)): if se[p]==product : return False else : se.append(product) return True if __name__=='__main__' : N=2345 if(productsDistinct(N)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( N := 2345 ; if (productsDistinct(N)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation productsDistinct(N : OclAny) : OclAny pre: true post: true activity: var s : String := "" ; while (N) do ( s := s + (N mod 10 + ('0')->char2byte())->byte2char() ; N := N div 10) ; s := s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var sz : int := (s)->size() ; var se : Sequence := Sequence{} ; for i : Integer.subrange(0, sz-1) do ( var product : int := 1 ; for j : Integer.subrange(i, sz-1)->select( $x | ($x - i) mod 1 = 0 ) do ( product := product * (s[j+1])->char2byte() - ('0')->char2byte() ; for p : Integer.subrange(0, (se)->size()-1) do ( if se[p+1] = product then ( return false ) else ( execute ((product) : se) )))) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque import sys,heapq,bisect,math,itertools,string,queue,copy,time sys.setrecursionlimit(10**8) INF=float('inf') mod=10**9+7 eps=10**-7 def inp(): return int(input()) def inpl(): return list(map(int,input().split())) def inpl_str(): return list(input().split()) while True : N,W,H=inpl() imosW=[0]*(W+1) imosH=[0]*(H+1) for _ in range(N): x,y,w=inpl() lx,rx=max(0,x-w),min(W-1,x+w-1) ly,ry=max(0,y-w),min(H-1,y+w-1) imosW[lx]+=1 imosW[rx+1]-=1 imosH[ly]+=1 imosH[ry+1]-=1 for i in range(1,W+1): imosW[i]+=imosW[i-1] for i in range(1,H+1): imosH[i]+=imosH[i-1] flagH=True flagW=True for i in range(W): if imosW[i]==0 : flagH=False break for i in range(H): if imosH[i]==0 : flagW=False break if flagH or flagW : print('Yes') else : print('No') break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var eps : double := (10)->pow(-7) ; skip ; skip ; skip ; while true do ( var N : OclAny := null; var W : OclAny := null; var H : OclAny := null; Sequence{N,W,H} := inpl() ; var imosW : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (W + 1)) ; var imosH : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (H + 1)) ; for _anon : Integer.subrange(0, N-1) do ( var x : OclAny := null; var y : OclAny := null; var w : OclAny := null; Sequence{x,y,w} := inpl() ; var lx : OclAny := null; var rx : OclAny := null; Sequence{lx,rx} := Sequence{Set{0, x - w}->max(),Set{W - 1, x + w - 1}->min()} ; var ly : OclAny := null; var ry : OclAny := null; Sequence{ly,ry} := Sequence{Set{0, y - w}->max(),Set{H - 1, y + w - 1}->min()} ; imosW[lx+1] := imosW[lx+1] + 1 ; imosW[rx + 1+1] := imosW[rx + 1+1] - 1 ; imosH[ly+1] := imosH[ly+1] + 1 ; imosH[ry + 1+1] := imosH[ry + 1+1] - 1) ; for i : Integer.subrange(1, W + 1-1) do ( imosW[i+1] := imosW[i+1] + imosW[i - 1+1]) ; for i : Integer.subrange(1, H + 1-1) do ( imosH[i+1] := imosH[i+1] + imosH[i - 1+1]) ; var flagH : boolean := true ; var flagW : boolean := true ; for i : Integer.subrange(0, W-1) do ( if imosW[i+1] = 0 then ( flagH := false ; break ) else skip) ; for i : Integer.subrange(0, H-1) do ( if imosH[i+1] = 0 then ( flagW := false ; break ) else skip) ; if flagH or flagW then ( execute ('Yes')->display() ) else ( execute ('No')->display() ) ; break); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inpl_str() : OclAny pre: true post: true activity: return (input().split()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import string for _ in range(int(input())): n=int(input()) r=input() b=input() count_r=0 count_b=0 for i in range(n): if ord(r[i])>ord(b[i]): count_r+=1 elif ord(r[i])count_r : print("BLUE") elif count_r>count_b : print("RED") else : print("EQUAL") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var count_r : int := 0 ; var count_b : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ((r[i+1])->char2byte()->compareTo((b[i+1])->char2byte())) > 0 then ( count_r := count_r + 1 ) else (if ((r[i+1])->char2byte()->compareTo((b[i+1])->char2byte())) < 0 then ( count_b := count_b + 1 ) else skip)) ; if (count_b->compareTo(count_r)) > 0 then ( execute ("BLUE")->display() ) else (if (count_r->compareTo(count_b)) > 0 then ( execute ("RED")->display() ) else ( execute ("EQUAL")->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math input=sys.stdin.readline INF=int(1e9)+7 MOD=998244353 def solve(): n=int(input()) s1=input().rstrip() s2=input().rstrip() cnt=0 for i in range(n): if s1[i]>s2[i]: cnt+=1 elif s1[i]0 : print("RED") elif cnt==0 : print("EQUAL") else : print("BLUE") t=1 t=int(input()) for i in range(1,t+1): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var INF : int := ("" + ((("1e9")->toReal())))->toInteger() + 7 ; var MOD : int := 998244353 ; skip ; var t : int := 1 ; t := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(1, t + 1-1) do ( solve()); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s1 : OclAny := input().rstrip() ; var s2 : OclAny := input().rstrip() ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (s1[i+1]->compareTo(s2[i+1])) > 0 then ( cnt := cnt + 1 ) else (if (s1[i+1]->compareTo(s2[i+1])) < 0 then ( cnt := cnt - 1 ) else skip)) ; if cnt > 0 then ( execute ("RED")->display() ) else (if cnt = 0 then ( execute ("EQUAL")->display() ) else ( execute ("BLUE")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) r=input() b=input() c=k=0 if int(r)==int(b): print('EQUAL') else : for i in range(n): if int(r[i])>int(b[i]): c+=1 elif int(r[i])k : print('RED') elif ctoInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var c : OclAny := 0; var k : int := 0 ; if ("" + ((r)))->toInteger() = ("" + ((b)))->toInteger() then ( execute ('EQUAL')->display() ) else ( for i : Integer.subrange(0, n-1) do ( if (("" + ((r[i+1])))->toInteger()->compareTo(("" + ((b[i+1])))->toInteger())) > 0 then ( c := c + 1 ) else (if (("" + ((r[i+1])))->toInteger()->compareTo(("" + ((b[i+1])))->toInteger())) < 0 then ( k := k + 1 ) else skip)) ; if (c->compareTo(k)) > 0 then ( execute ('RED')->display() ) else (if (c->compareTo(k)) < 0 then ( execute ('BLUE')->display() ) else (if c = k then ( execute ('EQUAL')->display() ) else skip ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout def solution(n,r,b): r_higher=0 b_higher=0 for red,blue in zip(r,b): if int(red)==int(blue): continue if int(red)>int(blue): r_higher+=1 else : b_higher+=1 if r_higher>b_higher : return 'RED' elif r_higher==b_higher : return 'EQUAL' else : return 'BLUE' test_cases=int(stdin.readline()) for it in range(test_cases): n=int(stdin.readline()) r=stdin.readline().strip() b=stdin.readline().strip() stdout.write(str(solution(n,r,b))+'\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var test_cases : int := ("" + ((stdin.readLine())))->toInteger() ; for it : Integer.subrange(0, test_cases-1) do ( n := ("" + ((stdin.readLine())))->toInteger() ; r := stdin.readLine()->trim() ; b := stdin.readLine()->trim() ; stdout.write(("" + ((solution(n, r, b)))) + ' ')); operation solution(n : OclAny, r : OclAny, b : OclAny) : OclAny pre: true post: true activity: var r_higher : int := 0 ; var b_higher : int := 0 ; for _tuple : Integer.subrange(1, r->size())->collect( _indx | Sequence{r->at(_indx), b->at(_indx)} ) do (var _indx : int := 1; var red : OclAny := _tuple->at(_indx); _indx := _indx + 1; var blue : OclAny := _tuple->at(_indx); if ("" + ((red)))->toInteger() = ("" + ((blue)))->toInteger() then ( continue ) else skip ; if (("" + ((red)))->toInteger()->compareTo(("" + ((blue)))->toInteger())) > 0 then ( r_higher := r_higher + 1 ) else ( b_higher := b_higher + 1 )) ; if (r_higher->compareTo(b_higher)) > 0 then ( return 'RED' ) else (if r_higher = b_higher then ( return 'EQUAL' ) else ( return 'BLUE' ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def candies(n,k): count=0 ind=1 arr=[0 for i in range(k)] while n>0 : f1=(ind-1)*k f2=ind*k sum1=(f1*(f1+1))//2 sum2=(f2*(f2+1))//2 res=sum2-sum1 if(res<=n): count+=1 n-=res ind+=1 else : i=0 term=((ind-1)*k)+1 while(n>0): if(term<=n): arr[i]=term i+=1 n-=term term+=1 else : arr[i]=n i+=1 n=0 for i in range(k): arr[i]+=((count*(i+1))+(k*(count*(count-1))//2)) for i in range(k): print(arr[i],end=" ") n,k=10,3 candies(n,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{n,k} := Sequence{10,3} ; candies(n, k); operation candies(n : OclAny, k : OclAny) pre: true post: true activity: var count : int := 0 ; var ind : int := 1 ; var arr : Sequence := Integer.subrange(0, k-1)->select(i | true)->collect(i | (0)) ; while n > 0 do ( var f1 : double := (ind - 1) * k ; var f2 : double := ind * k ; var sum1 : int := (f1 * (f1 + 1)) div 2 ; var sum2 : int := (f2 * (f2 + 1)) div 2 ; var res : double := sum2 - sum1 ; if ((res->compareTo(n)) <= 0) then ( count := count + 1 ; n := n - res ; ind := ind + 1 ) else ( var i : int := 0 ; var term : double := ((ind - 1) * k) + 1 ; while (n > 0) do ( if ((term->compareTo(n)) <= 0) then ( arr[i+1] := term ; i := i + 1 ; n := n - term ; term := term + 1 ) else ( arr[i+1] := n ; i := i + 1 ; n := 0 )) )) ; for i : Integer.subrange(0, k-1) do ( arr[i+1] := arr[i+1] + ((count * (i + 1)) + (k * (count * (count - 1)) div 2))) ; for i : Integer.subrange(0, k-1) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt max_val=257 def PrimeCharacters(s): prime=[True]*(max_val+1) prime[0]=False prime[1]=False for p in range(2,int(sqrt(max_val))+1): if(prime[p]==True): for i in range(2*p,max_val+1,p): prime[i]=False count=0 for i in range(len(s)): if(prime[ord(s[i])]): count+=1 return count if __name__=="__main__" : S="geeksforgeeks" ; print(PrimeCharacters(S)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var max_val : int := 257 ; skip ; if __name__ = "__main__" then ( var S : String := "geeksforgeeks"; ; execute (PrimeCharacters(S))->display() ) else skip; operation PrimeCharacters(s : OclAny) : OclAny pre: true post: true activity: var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (max_val + 1)) ; prime->first() := false ; prime[1+1] := false ; for p : Integer.subrange(2, ("" + ((sqrt(max_val))))->toInteger() + 1-1) do ( if (prime[p+1] = true) then ( for i : Integer.subrange(2 * p, max_val + 1-1)->select( $x | ($x - 2 * p) mod p = 0 ) do ( prime[i+1] := false) ) else skip) ; var count : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if (prime[(s[i+1])->char2byte()+1]) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() a=sorted(list(map(int,input().split()))) a[-1]=[1,2][a[-1]==1] print(*(sorted(a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; a->last() := Sequence{1}->union(Sequence{ 2 })->select(a->last() = 1) ; execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))))))) ))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* from collections import* from random import* from decimal import Decimal from bisect import* import sys input=sys.stdin.readline def lis(): return list(map(int,input().split())) def ma(): return map(int,input().split()) def inp(): return int(input()) n,k=ma() a=lis() l,h=0,max(a) while(l+1max()} ; while ((l + 1->compareTo(h)) < 0) do ( var m : int := (l + h) div 2 ; var c : int := 0 ; for i : a do ( c := c + ceil(i / m) - 1) ; if ((c->compareTo(k)) <= 0) then ( var h : int := m ) else ( var l : int := m )) ; execute (h)->display(); operation lis() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ma() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from sys import stdin,stdout def get_ints_in_variables(): return map(int,sys.stdin.readline().strip().split()) def get_int(): return int(input()) def get_ints_in_list(): return list(map(int,sys.stdin.readline().strip().split())) def get_list_of_list(n): return[list(map(int,sys.stdin.readline().strip().split()))for _ in range(n)] def get_string(): return sys.stdin.readline().strip() def main(): n=int(input()) arr=get_ints_in_list() mx=1 for i in range(0,n): if arr[i]>mx : mx=arr[i] arr.sort() if mx==1 : arr[n-1]=2 else : arr[n-1]=1 arr.sort() for i in range(0,n): print(arr[i],end=" ") if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation get_ints_in_variables() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ); operation get_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation get_ints_in_list() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation get_list_of_list(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )))); operation get_string() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation main() pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : OclAny := get_ints_in_list() ; var mx : int := 1 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1]->compareTo(mx)) > 0 then ( mx := arr[i+1] ) else skip) ; arr := arr->sort() ; if mx = 1 then ( arr[n - 1+1] := 2 ) else ( arr[n - 1+1] := 1 ) ; arr := arr->sort() ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from sys import stdin,stdout def get_ints_in_variables(): return map(int,sys.stdin.readline().strip().split()) def get_int(): return int(input()) def get_ints_in_list(): return list(map(int,sys.stdin.readline().strip().split())) def get_list_of_list(n): return[list(map(int,sys.stdin.readline().strip().split()))for _ in range(n)] def get_string(): return sys.stdin.readline().strip() def main(): n=int(input()) arr=get_ints_in_list() arr.sort() if arr[n-1]==1 : arr[n-1]=2 else : arr[n-1]=1 arr.sort() for i in range(0,n): print(arr[i],end=" ") if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation get_ints_in_variables() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ); operation get_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation get_ints_in_list() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation get_list_of_list(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )))); operation get_string() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation main() pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : OclAny := get_ints_in_list() ; arr := arr->sort() ; if arr[n - 1+1] = 1 then ( arr[n - 1+1] := 2 ) else ( arr[n - 1+1] := 1 ) ; arr := arr->sort() ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) m=max(a) b=False for i in range(n): if a[i]==m and a[i]!=1 : a[i]=1 b=True break if not b : a[n-1]=2 a.sort() for x in a : print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : OclAny := (a)->max() ; var b : boolean := false ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = m & a[i+1] /= 1 then ( a[i+1] := 1 ; b := true ; break ) else skip) ; if not(b) then ( a[n - 1+1] := 2 ) else skip ; a := a->sort() ; for x : a do ( execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,W,H=[int(n)for n in input().split()] xmap=[0 for _ in range(W+1)] ymap=[0 for _ in range(H+1)] for i in range(N): x,y,w=[int(n)for n in input().split()] l=max(x-w,0) r=min(x+w,W) a=max(y-w,0) b=min(y+w,H) xmap[l]+=1 xmap[r]-=1 ymap[a]+=1 ymap[b]-=1 covered=0 xcovered=True for i in range(W): covered+=xmap[i] if covered<=0 : xcovered=False covered=0 for i in range(H): covered+=ymap[i] if covered<=0 and not xcovered : print("No") exit() print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var W : OclAny := null; var H : OclAny := null; Sequence{N,W,H} := input().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; var xmap : Sequence := Integer.subrange(0, W + 1-1)->select(_anon | true)->collect(_anon | (0)) ; var ymap : Sequence := Integer.subrange(0, H + 1-1)->select(_anon | true)->collect(_anon | (0)) ; for i : Integer.subrange(0, N-1) do ( var x : OclAny := null; var y : OclAny := null; var w : OclAny := null; Sequence{x,y,w} := input().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; var l : OclAny := Set{x - w, 0}->max() ; var r : OclAny := Set{x + w, W}->min() ; var a : OclAny := Set{y - w, 0}->max() ; var b : OclAny := Set{y + w, H}->min() ; xmap[l+1] := xmap[l+1] + 1 ; xmap[r+1] := xmap[r+1] - 1 ; ymap[a+1] := ymap[a+1] + 1 ; ymap[b+1] := ymap[b+1] - 1) ; var covered : int := 0 ; var xcovered : boolean := true ; for i : Integer.subrange(0, W-1) do ( covered := covered + xmap[i+1] ; if covered <= 0 then ( xcovered := false ) else skip) ; covered := 0 ; for i : Integer.subrange(0, H-1) do ( covered := covered + ymap[i+1] ; if covered <= 0 & not(xcovered) then ( execute ("No")->display() ; exit() ) else skip) ; execute ("Yes")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def minimunMoves(arr,n): ans=sys.maxsize for i in range(n): curr_count=0 for j in range(n): tmp=arr[j]+arr[j] index=tmp.find(arr[i]) if(index==len(arr[i])): return-1 curr_count+=index ans=min(curr_count,ans) return ans if __name__=="__main__" : arr=["xzzwo","zwoxz","zzwox","xzzwo"] n=len(arr) print(minimunMoves(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{"xzzwo"}->union(Sequence{"zwoxz"}->union(Sequence{"zzwox"}->union(Sequence{ "xzzwo" }))) ; n := (arr)->size() ; execute (minimunMoves(arr, n))->display() ) else skip; operation minimunMoves(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; for i : Integer.subrange(0, n-1) do ( var curr_count : int := 0 ; for j : Integer.subrange(0, n-1) do ( var tmp : OclAny := arr[j+1] + arr[j+1] ; var index : int := tmp->indexOf(arr[i+1]) - 1 ; if (index = (arr[i+1])->size()) then ( return -1 ) else skip ; curr_count := curr_count + index) ; ans := Set{curr_count, ans}->min()) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Area(b1,b2,h): return((b1+b2)/2)*h base1=8 ; base2=10 ; height=6 area=Area(base1,base2,height) print("Area is:",area) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var base1 : int := 8; var base2 : int := 10; var height : int := 6 ; var area : OclAny := Area(base1, base2, height) ; execute ("Area is:")->display(); operation Area(b1 : OclAny, b2 : OclAny, h : OclAny) : OclAny pre: true post: true activity: return ((b1 + b2) / 2) * h; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getOddOccurrence(arr,arr_size): for i in range(0,arr_size): count=0 for j in range(0,arr_size): if arr[i]==arr[j]: count+=1 if(count % 2!=0): return arr[i] return-1 arr=[2,3,5,4,5,2,4,3,5,2,4,4,2] n=len(arr) print(getOddOccurrence(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{4}->union(Sequence{5}->union(Sequence{2}->union(Sequence{4}->union(Sequence{3}->union(Sequence{5}->union(Sequence{2}->union(Sequence{4}->union(Sequence{4}->union(Sequence{ 2 })))))))))))) ; var n : int := (arr)->size() ; execute (getOddOccurrence(arr, n))->display(); operation getOddOccurrence(arr : OclAny, arr_size : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, arr_size-1) do ( var count : int := 0 ; for j : Integer.subrange(0, arr_size-1) do ( if arr[i+1] = arr[j+1] then ( count := count + 1 ) else skip) ; if (count mod 2 /= 0) then ( return arr[i+1] ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=4 m=4 def calcProbability(M,k): dp=[[0 for i in range(n)]for i in range(m)] Sum=[0 for i in range(n)] for j in range(n): dp[0][j]=M[0][j] Sum[0]+=dp[0][j] for i in range(1,m): for j in range(n): dp[i][j]+=(dp[i-1][j]/Sum[i-1]+M[i][j]) Sum[i]+=dp[i][j] return dp[n-1][k-1]/Sum[n-1] M=[[1,1,0,3],[2,3,2,3],[9,3,0,2],[2,3,2,2]] k=3 print(calcProbability(M,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := 4 ; var m : int := 4 ; skip ; M := Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 3 })))}->union(Sequence{Sequence{2}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 3 })))}->union(Sequence{Sequence{9}->union(Sequence{3}->union(Sequence{0}->union(Sequence{ 2 })))}->union(Sequence{ Sequence{2}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 2 }))) }))) ; k := 3 ; execute (calcProbability(M, k))->display(); operation calcProbability(M : OclAny, k : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)))) ; var Sum : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for j : Integer.subrange(0, n-1) do ( dp->first()[j+1] := M->first()[j+1] ; Sum->first() := Sum->first() + dp->first()[j+1]) ; for i : Integer.subrange(1, m-1) do ( for j : Integer.subrange(0, n-1) do ( dp[i+1][j+1] := dp[i+1][j+1] + (dp[i - 1+1][j+1] / Sum[i - 1+1] + M[i+1][j+1]) ; Sum[i+1] := Sum[i+1] + dp[i+1][j+1])) ; return dp[n - 1+1][k - 1+1] / Sum[n - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) matrix=[] for _ in range(n): matrix.append(list(map(int,input().split()))) column=[int(input())for _ in range(m)] for i in range(n): print(sum(a*b for a,b in zip(matrix[i],column))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var matrix : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : matrix)) ; var column : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; for i : Integer.subrange(0, n-1) do ( execute (((argument (test (logical_test (comparison (expr (expr (atom (name a))) * (expr (atom (name b))))))) (comp_for for (exprlist (expr (atom (name a))) , (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name matrix)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name column)))))))) )))))))))->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(x)for x in input().split()] A=[[0 for i in range(m)]for i in range(n)] vector=[0 for i in range(m)] result=[0 for i in range(n)] for i in range(n): A[i]=[int(x)for x in input().split()] for i in range(m): vector[i]=int(input()) for i in range(n): for j in range(m): result[i]+=A[i][j]*vector[j] for _ in result : print(_) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var A : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, m-1)->select(i | true)->collect(i | (0)))) ; var vector : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (0)) ; var result : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( A[i+1] := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) ; for i : Integer.subrange(0, m-1) do ( vector[i+1] := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( result[i+1] := result[i+1] + A[i+1][j+1] * vector[j+1])) ; for _anon : result do ( execute (_anon)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math sys.setrecursionlimit(10**6) MOD=10**9+7 read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines N,K=map(int,readline().split()) A=list(map(int,readline().split())) def solve(N): cnt=0 for a in A : if a % N==0 : cnt+=(a//N-1) else : cnt+=a//N if cnt<=K : return True else : return False left=0 right=10**9+5 while right-left>1 : N=(right+left)//2 flag=solve(N) if flag : right=N else : left=N print(right) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(6)) ; var MOD : double := (10)->pow(9) + 7 ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; var left : int := 0 ; var right : double := (10)->pow(9) + 5 ; while right - left > 1 do ( N := (right + left) div 2 ; var flag : OclAny := solve(N) ; if flag then ( right := N ) else ( left := N )) ; execute (right)->display(); operation solve(N : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; for a : A do ( if a mod N = 0 then ( cnt := cnt + (a div N - 1) ) else ( cnt := cnt + a div N )) ; if (cnt->compareTo(K)) <= 0 then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def multiply_columns(column_a,column_b): total=0 for a,b in zip(column_a,column_b): total+=(a*b) return total n,m=[int(x)for x in input().split()] matrix=[] column_matrix=[] for _ in range(n): nums=[int(y)for y in input().split()] matrix.append(nums) single_column_vector=[] for _ in range(m): number=int(input()) single_column_vector.append(number) totals=[] total=0 for column in matrix : total=multiply_columns(column,single_column_vector) totals.append(total) for total in totals : print(total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var matrix : Sequence := Sequence{} ; var column_matrix : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var nums : Sequence := input().split()->select(y | true)->collect(y | (("" + ((y)))->toInteger())) ; execute ((nums) : matrix)) ; var single_column_vector : Sequence := Sequence{} ; for _anon : Integer.subrange(0, m-1) do ( var number : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((number) : single_column_vector)) ; var totals : Sequence := Sequence{} ; total := 0 ; for column : matrix do ( total := multiply_columns(column, single_column_vector) ; execute ((total) : totals)) ; for total : totals do ( execute (total)->display()); operation multiply_columns(column_a : OclAny, column_b : OclAny) : OclAny pre: true post: true activity: var total : int := 0 ; for _tuple : Integer.subrange(1, column_a->size())->collect( _indx | Sequence{column_a->at(_indx), column_b->at(_indx)} ) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); total := total + (a * b)) ; return total; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def main(): a,b=map(int,input().split()) A=[] for i in range(a): s=list(map(int,input().split())) A.append(s) B=[] for i in range(b): s=int(input()) B.append(s) for i in range(a): c=0 for k in range(b): c+=A[i][k]*B[k] print(c) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := Sequence{} ; for i : Integer.subrange(0, a-1) do ( var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((s) : A)) ; var B : Sequence := Sequence{} ; for i : Integer.subrange(0, b-1) do ( s := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((s) : B)) ; for i : Integer.subrange(0, a-1) do ( var c : int := 0 ; for k : Integer.subrange(0, b-1) do ( c := c + A[i+1][k+1] * B[k+1]) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input().split("") n=int(s[0]) m=int(s[1]) a=[["" for i in range(m)]for j in range(n)] b=[] c=[] for i in range(n): s=input().split("") for j in range(m): a[i][j]=int(s[j]) for i in range(m): b.append(int(input())) for i in range(n): seki=0 for j in range(m): seki+=a[i][j]*b[j] c.append(seki) for i in range(n): print(c[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := input().split("") ; var n : int := ("" + ((s->first())))->toInteger() ; var m : int := ("" + ((s[1+1])))->toInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (Integer.subrange(0, m-1)->select(i | true)->collect(i | ("")))) ; var b : Sequence := Sequence{} ; var c : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( s := input().split("") ; for j : Integer.subrange(0, m-1) do ( a[i+1][j+1] := ("" + ((s[j+1])))->toInteger())) ; for i : Integer.subrange(0, m-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : b)) ; for i : Integer.subrange(0, n-1) do ( var seki : int := 0 ; for j : Integer.subrange(0, m-1) do ( seki := seki + a[i+1][j+1] * b[j+1]) ; execute ((seki) : c)) ; for i : Integer.subrange(0, n-1) do ( execute (c[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMinSum(a,b,n): a.sort() b.sort() sum=0 for i in range(n): sum=sum+abs(a[i]-b[i]) return sum a=[4,1,8,7] b=[2,3,6,5] n=len(a) print(findMinSum(a,b,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{4}->union(Sequence{1}->union(Sequence{8}->union(Sequence{ 7 }))) ; b := Sequence{2}->union(Sequence{3}->union(Sequence{6}->union(Sequence{ 5 }))) ; n := (a)->size() ; execute (findMinSum(a, b, n))->display(); operation findMinSum(a : OclAny, b : OclAny, n : OclAny) : OclAny pre: true post: true activity: a := a->sort() ; b := b->sort() ; var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + (a[i+1] - b[i+1])->abs()) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys f=sys.stdin _,w,h=map(int,f.readline().split()) xyw=[list(map(int,line.split()))for line in f] from operator import itemgetter def check(xyw,i,size): xyw.sort(key=itemgetter(i)) p=0 for xywi in xyw : if xywi[i]-xywi[2]<=p : p=max(p,xywi[i]+xywi[2]) return size<=p print('Yes' if check(xyw,0,w)or check(xyw,1,h)else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var f : OclFile := OclFile["System.in"] ; var _anon : OclAny := null; var w : OclAny := null; var h : OclAny := null; Sequence{_anon,w,h} := (f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var xyw : Sequence := f->select(line | true)->collect(line | (((line.split())->collect( _x | (OclType["int"])->apply(_x) )))) ; skip ; skip ; execute (if check(xyw, 0, w) or check(xyw, 1, h) then 'Yes' else 'No' endif)->display(); operation check(xyw : OclAny, i : OclAny, size : OclAny) : OclAny pre: true post: true activity: xyw := xyw->sort() ; var p : int := 0 ; for xywi : xyw do ( if (xywi[i+1] - xywi[2+1]->compareTo(p)) <= 0 then ( p := Set{p, xywi[i+1] + xywi[2+1]}->max() ) else skip) ; return (size->compareTo(p)) <= 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- Q=int(input()) A,B=[None]*Q,[None]*Q for i in range(Q): A[i],B[i]=sorted(map(int,input().split())) def solve(a,b): w=a*b-1 left,right=0,b-a while right-left>1 : x=(left+right)//2 v=w//(a+x) if v1 : x=(left+right)//2 v=w//(a+x) if vtoInteger() ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := Sequence{MatrixLib.elementwiseMult(Sequence{ null }, Q),MatrixLib.elementwiseMult(Sequence{ null }, Q)} ; for i : Integer.subrange(0, Q-1) do ( var A[i+1] : OclAny := null; var B[i+1] : OclAny := null; Sequence{A[i+1],B[i+1]} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort()) ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation solve(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var w : double := a * b - 1 ; var left : OclAny := null; var right : OclAny := null; Sequence{left,right} := Sequence{0,b - a} ; while right - left > 1 do ( var x : int := (left + right) div 2 ; var v : int := w div (a + x) ; if (v->compareTo(a)) < 0 then ( var right : int := x ) else ( var left : int := x )) ; var n : int := left ; Sequence{left,right} := Sequence{0,n} ; while right - left > 1 do ( x := (left + right) div 2 ; v := w div (a + x) ; if (v->compareTo(a + x)) < 0 then ( right := x ) else ( left := x )) ; return right + (w div (a + right)) - (w div (a + n)); operation main() pre: true post: true activity: for _tuple : Integer.subrange(1, A->size())->collect( _indx | Sequence{A->at(_indx), B->at(_indx)} ) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); var ans : double := 2 * (a - 1) + solve(a, b) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(a,b): ans=0 cur=int(a*b) left=1 right=cur+1 while lefttoInteger() ; for i : Integer.subrange(0, n-1) do ( var x : String := (OclFile["System.in"]).readLine() ; var y : Sequence := x.split()->select(z | true)->collect(z | (("" + ((z)))->toInteger())) ; execute (Set{("" + ((solve(y->first(), y[1+1]))))->toInteger() - 2, 0}->max())->display()); operation solve(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; var cur : int := ("" + ((a * b)))->toInteger() ; var left : int := 1 ; var right : int := cur + 1 ; while (left->compareTo(right)) < 0 do ( var mid : int := ("" + (((left + right) / 2)))->toInteger() ; var z : int := ("" + ((mid / 2)))->toInteger() ; var mx : double := z * (mid - z) ; if (mx->compareTo(cur)) <= 0 then ( ans := mid ; left := mid + 1 ) else ( right := mid )) ; if ("" + ((ans / 2)))->toInteger() * (ans - ("" + ((ans / 2)))->toInteger()) = cur & a /= b then ( ans := ans - 1 ) else skip ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for a in[*open(0)][1 :]: a,b=map(int,a.split()); c=int((a*b)**.5); print((a*b-(a!=b))//c+c-2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for a : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (a.split())->collect( _x | (OclType["int"])->apply(_x) ); var c : int := ("" + ((((a * b))->pow(.5))))->toInteger(); execute ((a * b - (a /= b)) div c + c - 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**15 mod=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): n=I() rr=[] for _ in range(n): a,b=LI() t=a*b s=int(t**0.5) if t<3 : rr.append(0) elif a==b : if(a-1)*(b+1)pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(15) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var n : OclAny := I() ; var rr : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := LI() ; var t : double := a * b ; s := ("" + (((t)->pow(0.5))))->toInteger() ; if t < 3 then ( execute ((0) : rr) ) else (if a = b then ( if ((a - 1) * (b + 1)->compareTo(t)) < 0 then ( execute (((a - 1) * 2) : rr) ) else ( execute (((a - 1) * 2 - 1) : rr) ) ) else (if s * s = t then ( execute (((s - 1) * 2 - 1) : rr) ) else (if (s * (s + 1)->compareTo(t)) < 0 then ( execute ((s * 2 - 1) : rr) ) else ( execute (((s - 1) * 2) : rr) ) ) ) ) ) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) debug_mode=True if len(sys.argv)>1 and sys.argv[1]=="-d" else False if debug_mode : import os infile=open(os.path.basename(__file__).replace(".py",".in")) def input(): return infile.readline() from math import sqrt def main(): Q=int(input().strip()) AB=[list(map(int,input().strip().split()))for _ in range(Q)] for a,b in AB : a,b=min((a,b)),max((a,b)) cnt=0 if a==b : cnt=2*(a-1) elif a+1==b : cnt=2*(a-1) else : ab=a*b c=int(sqrt(ab))if sqrt(ab)>int(sqrt(ab))else int(sqrt(ab))-1 if c*(c+1)>=ab : cnt=2*(c-1) elif c*(c+1)pow(6)) ; var debug_mode : boolean := if ((trailer . (name argv)))->size() > 1 & (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) = "-d" then true else false endif ; if debug_mode then ( skip ; var infile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(os.path.basename(__file__).replace(".py", ".in"))) ; skip ) else skip ; skip ; skip ; main() ; if debug_mode then ( infile.closeFile() ) else skip; operation main() pre: true post: true activity: var Q : int := ("" + ((input()->trim())))->toInteger() ; var AB : Sequence := Integer.subrange(0, Q-1)->select(_anon | true)->collect(_anon | (((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for _tuple : AB do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{(Sequence{a, b})->min(),(Sequence{a, b})->max()} ; var cnt : int := 0 ; if a = b then ( cnt := 2 * (a - 1) ) else (if a + 1 = b then ( cnt := 2 * (a - 1) ) else ( var ab : double := a * b ; var c : int := if (sqrt(ab)->compareTo(("" + ((sqrt(ab))))->toInteger())) > 0 then ("" + ((sqrt(ab))))->toInteger() else ("" + ((sqrt(ab))))->toInteger() - 1 endif ; if (c * (c + 1)->compareTo(ab)) >= 0 then ( cnt := 2 * (c - 1) ) else (if (c * (c + 1)->compareTo(ab)) < 0 then ( cnt := 2 * c - 1 ) else skip) ) ) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=list(map(int,input().split())) result=max(a) left=1 right=result med=left+(right-left)//2 while left<=right : counter=sum([(x-1)//med for x in a]) if counter<=k : result=med right=med-1 else : left=med+1 med=left+(right-left)//2 print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var result : OclAny := (a)->max() ; var left : int := 1 ; var right : OclAny := result ; var med : int := left + (right - left) div 2 ; while (left->compareTo(right)) <= 0 do ( var counter : OclAny := (a->select(x | true)->collect(x | ((x - 1) div med)))->sum() ; if (counter->compareTo(k)) <= 0 then ( result := med ; right := med - 1 ) else ( left := med + 1 ) ; med := left + (right - left) div 2) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printSeriesSum(N): sum=0 ; for i in range(1,N+1): if(i & 1): sum+=i/(i+1); else : sum-=i/(i+1); print(sum); if __name__=="__main__" : N=10 ; printSeriesSum(N); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := 10; ; printSeriesSum(N); ) else skip; operation printSeriesSum(N : OclAny) pre: true post: true activity: var sum : int := 0; ; for i : Integer.subrange(1, N + 1-1) do ( if (MathLib.bitwiseAnd(i, 1)) then ( sum := sum + i / (i + 1); ) else ( sum := sum - i / (i + 1); )) ; execute (sum)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printSeriessumm(N): summ=0 for i in range(1,N+1): summ+=pow(i,i-1) print(summ) N=5 printSeriessumm(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 5 ; printSeriessumm(N); operation printSeriessumm(N : OclAny) pre: true post: true activity: var summ : int := 0 ; for i : Integer.subrange(1, N + 1-1) do ( summ := summ + (i)->pow(i - 1)) ; execute (summ)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): ans=sum(1 for n in range(1,101)for k in range(0,n+1)if eulerlib.binomial(n,k)>1000000) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 101))))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name k)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name eulerlib)) (trailer . (name binomial) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n))))))) , (argument (test (logical_test (comparison (expr (atom (name k)))))))) ))))) > (comparison (expr (atom (number (integer 1000000))))))))))))))->sum() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMinAvgSubarray(arr,n,k): if(nunion(Sequence{7}->union(Sequence{90}->union(Sequence{20}->union(Sequence{10}->union(Sequence{50}->union(Sequence{ 40 })))))) ; k := 3 ; n := (arr)->size() ; findMinAvgSubarray(arr, n, k); operation findMinAvgSubarray(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if ((n->compareTo(k)) < 0) then ( return 0 ) else skip ; var res_index : int := 0 ; var curr_sum : int := 0 ; for i : Integer.subrange(0, k-1) do ( curr_sum := curr_sum + arr[i+1]) ; var min_sum : int := curr_sum ; for i : Integer.subrange(k, n-1) do ( curr_sum := curr_sum + arr[i+1] - arr[i - k+1] ; if ((curr_sum->compareTo(min_sum)) < 0) then ( min_sum := curr_sum ; res_index := (i - k + 1) ) else skip) ; execute ("Subarray between[")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) num=[] for _ in range(n): num.append(sorted([int(i)for i in input().split()])) def operate(a,b): i=0 while True : a+=i if a==b : break if a>b : e=a-b if e % 2==0 : break i+=1 return i for i in num : print(operate(i[0],i[1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var num : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))->sort()) : num)) ; skip ; for i : num do ( execute (operate(i->first(), i[1+1]))->display()); operation operate(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; while true do ( a := a + i ; if a = b then ( break ) else skip ; if (a->compareTo(b)) > 0 then ( var e : double := a - b ; if e mod 2 = 0 then ( break ) else skip ) else skip ; i := i + 1) ; return i; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,x=map(int,input().split()) pay=0 if a//2a : pay=a else : pay=b else : aa=x//1000 aaa=x % 1000 if aaa>500 : pay=(aa+1)*a elif aaa==0 : pay=aa*a else : pay=aa*a+b else : if x==500 : pay=b else : bb=x//500 bbb=x % 500 if bbb==0 : pay=bb*b else : pay=(bb+1)*b print(pay) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var x : OclAny := null; Sequence{a,b,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var pay : int := 0 ; if (a div 2->compareTo(b)) < 0 then ( if x = 1000 then ( pay := a ) else (if x = 500 then ( if (b->compareTo(a)) > 0 then ( pay := a ) else ( pay := b ) ) else ( var aa : int := x div 1000 ; var aaa : int := x mod 1000 ; if aaa > 500 then ( pay := (aa + 1) * a ) else (if aaa = 0 then ( pay := aa * a ) else ( pay := aa * a + b ) ) ) ) ) else ( if x = 500 then ( pay := b ) else ( var bb : int := x div 500 ; var bbb : int := x mod 500 ; if bbb = 0 then ( pay := bb * b ) else ( pay := (bb + 1) * b ) ) ) ; execute (pay)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- exec(int(input())*'a,b=map(int,input().split());d=abs(a-b);i=0\nwhile d%2 or d>0:i+=1;d-=i\nprint(i);') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) )))) * (expr (atom 'a,b=map(int,input().split());d=abs(a-b);i=0 while d%2 or d>0:i+=1;d-=i print(i);'))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b=map(int,input().split()) diff=max(a,b)-min(a,b) if diff==0 : print(0) else : n=1 while True : p=n*(n+1)//2 if p>=diff and(p-diff)% 2==0 : ans=n break else : n+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var diff : double := Set{a, b}->max() - Set{a, b}->min() ; if diff = 0 then ( execute (0)->display() ) else ( var n : int := 1 ; while true do ( var p : int := n * (n + 1) div 2 ; if (p->compareTo(diff)) >= 0 & (p - diff) mod 2 = 0 then ( var ans : int := n ; break ) else ( n := n + 1 )) ; execute (ans)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def g(n): if n==-2 : return-1 if n==-1 : return-2 return n*(n+1)/2 def run(a,b): c=abs(a-b) i=int(((8*c+1)**0.5-1)/2) while 1 : ma=g(i) if i % 2==0 : mi=g(i-1)+2 else : mi=g(i-3)+2 if mi<=c and c<=ma : if i % 4==1 or i % 4==2 : if c % 2==1 : return i else : if c % 2==0 : return i i+=1 if sys.argv[-1]=='t' : cases=[[0,19,6],[0,12,7],[0,15,5],[1,3,3],[11,11,0],[30,20,4]] for case in cases : r=run(*case[:-1]) if r!=case[-1]: print(case,r) print(run(0,10**9)-int(((8*(10**9)+1)**0.5-1)/2)) for i in range(1,10**5): re=run(0,0+i) else : for _ in range(int(input())): print(run(*[int(d)for d in input().split(" ")])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) = 't' then ( var cases : Sequence := Sequence{Sequence{0}->union(Sequence{19}->union(Sequence{ 6 }))}->union(Sequence{Sequence{0}->union(Sequence{12}->union(Sequence{ 7 }))}->union(Sequence{Sequence{0}->union(Sequence{15}->union(Sequence{ 5 }))}->union(Sequence{Sequence{1}->union(Sequence{3}->union(Sequence{ 3 }))}->union(Sequence{Sequence{11}->union(Sequence{11}->union(Sequence{ 0 }))}->union(Sequence{ Sequence{30}->union(Sequence{20}->union(Sequence{ 4 })) }))))) ; for case : cases do ( var r : OclAny := run((argument * (test (logical_test (comparison (expr (atom (name case)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))))) ; if r /= case->last() then ( execute (case)->display() ) else skip) ; execute (run(0, (10)->pow(9)) - ("" + (((((8 * ((10)->pow(9)) + 1))->pow(0.5) - 1) / 2)))->toInteger())->display() ; for i : Integer.subrange(1, (10)->pow(5)-1) do ( var re : OclAny := run(0, 0 + i)) ) else ( for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (run((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name d)))))))) ))))))) (comp_for for (exprlist (expr (atom (name d)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " "))))))) )))))))) ]))))))))->display()) ); operation g(n : OclAny) : OclAny pre: true post: true activity: if n = -2 then ( return -1 ) else skip ; if n = -1 then ( return -2 ) else skip ; return n * (n + 1) / 2; operation run(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var c : double := (a - b)->abs() ; var i : int := ("" + (((((8 * c + 1))->pow(0.5) - 1) / 2)))->toInteger() ; while 1 do ( var ma : OclAny := g(i) ; if i mod 2 = 0 then ( var mi : OclAny := g(i - 1) + 2 ) else ( mi := g(i - 3) + 2 ) ; if (mi->compareTo(c)) <= 0 & (c->compareTo(ma)) <= 0 then ( if i mod 4 = 1 or i mod 4 = 2 then ( if c mod 2 = 1 then ( return i ) else skip ) else ( if c mod 2 = 0 then ( return i ) else skip ) ) else skip ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def func(): n=int(input()) for j in range(n): a,b=map(int,input().split()) x=abs(a-b) k=0 if x==0 : print(k) continue i=1 while x>=i : x=x-i i=i+1 if x==0 : print(i-1) continue if(i-x)% 2==0 : print(i) else : if(i+1)% 2==0 : print(i+2) else : print(i+1) if __name__=="__main__" : func() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( func() ) else skip; operation func() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : double := (a - b)->abs() ; var k : int := 0 ; if x = 0 then ( execute (k)->display() ; continue ) else skip ; var i : int := 1 ; while (x->compareTo(i)) >= 0 do ( x := x - i ; i := i + 1) ; if x = 0 then ( execute (i - 1)->display() ; continue ) else skip ; if (i - x) mod 2 = 0 then ( execute (i)->display() ) else ( if (i + 1) mod 2 = 0 then ( execute (i + 2)->display() ) else ( execute (i + 1)->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxSum(arr,n): s=0 l=[] for i in range(len(a)): s+=abs(a[i]) if(a[i]>=0): continue if(i==0): l.append(i+1) else : l.append(i+1) l.append(i) print(s) print(*l) n=4 a=[1,-2,-3,4] maxSum(a,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; var a : Sequence := Sequence{1}->union(Sequence{-2}->union(Sequence{-3}->union(Sequence{ 4 }))) ; maxSum(a, n); operation maxSum(arr : OclAny, n : OclAny) pre: true post: true activity: var s : int := 0 ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, (a)->size()-1) do ( s := s + (a[i+1])->abs() ; if (a[i+1] >= 0) then ( continue ) else skip ; if (i = 0) then ( execute ((i + 1) : l) ) else ( execute ((i + 1) : l) ; execute ((i) : l) )) ; execute (s)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name l))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys m={'\n' : '','' : '','a' : 'y','b' : 'h','c' : 'e','d' : 's','e' : 'o','f' : 'c','g' : 'v','h' : 'x','i' : 'd','j' : 'u','k' : 'i','l' : 'g','n' : 'b','m' : 'l','o' : 'k','p' : 'r','q' : 'z','r' : 't','s' : 'n','t' : 'w','u' : 'j','v' : 'p','w' : 'f','x' : 'm','y' : 'a','z' : 'q'} n=int(sys.stdin.readline()) for i in range(n): s=sys.stdin.readline() print("Case #%d: " %(i+1),end='') print(''.join([m.get(x,'[FAIL:%s]' % x)for x in s])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var m : Map := Map{ ' ' |-> '' }->union(Map{ '' |-> '' }->union(Map{ 'a' |-> 'y' }->union(Map{ 'b' |-> 'h' }->union(Map{ 'c' |-> 'e' }->union(Map{ 'd' |-> 's' }->union(Map{ 'e' |-> 'o' }->union(Map{ 'f' |-> 'c' }->union(Map{ 'g' |-> 'v' }->union(Map{ 'h' |-> 'x' }->union(Map{ 'i' |-> 'd' }->union(Map{ 'j' |-> 'u' }->union(Map{ 'k' |-> 'i' }->union(Map{ 'l' |-> 'g' }->union(Map{ 'n' |-> 'b' }->union(Map{ 'm' |-> 'l' }->union(Map{ 'o' |-> 'k' }->union(Map{ 'p' |-> 'r' }->union(Map{ 'q' |-> 'z' }->union(Map{ 'r' |-> 't' }->union(Map{ 's' |-> 'n' }->union(Map{ 't' |-> 'w' }->union(Map{ 'u' |-> 'j' }->union(Map{ 'v' |-> 'p' }->union(Map{ 'w' |-> 'f' }->union(Map{ 'x' |-> 'm' }->union(Map{ 'y' |-> 'a' }->union(Map{ 'z' |-> 'q' }))))))))))))))))))))))))))) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; execute (StringLib.format("Case #%d: ",(i + 1)))->display() ; execute (StringLib.sumStringsWithSeparator((s->characters()->select(x | true)->collect(x | (m.get(x, StringLib.format('[FAIL:%s]',x))))), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def makemap(): ALPHA='abcdefghijklmnopqrstuvwxyz' M={'y' : 'a','e' : 'o','q' : 'z',} G='''ejp mysljylc kd kxveddknmc re jsicpdrysi rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd de kr kd eoya kw aej tysr re ujdr lkgc jv''' E='''our language is impossible to understand there are twenty six factorial possibilities so it is okay if you want to just give up''' assert(len(G)==len(E)) for i in range(len(G)): g=G[i] e=E[i] if g in ALPHA : assert(e in ALPHA) if g not in M : M[g]=e else : assert(M[g]==e) else : assert(e not in ALPHA) assert(len(M)==25 or len(M)==26) assert(len(M)==len(set(M.values()))) if len(M)==25 : g=''.join(c for c in ALPHA if c not in M) e=''.join(c for c in ALPHA if c not in M.values()) M[g]=e assert(len(M)==len(set(M.values()))) assert(set(M)==set(ALPHA)) return M def trans(s,M): return ''.join(M.get(c,c)for c in s) def main(): M=makemap() T=int(sys.stdin.readline().strip()) for i in range(T): s=sys.stdin.readline() s=trans(s,M) sys.stdout.write('Case #{}: '.format(i+1)) sys.stdout.write(s) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation makemap() : OclAny pre: true post: true activity: var ALPHA : String := 'abcdefghijklmnopqrstuvwxyz' ; var M : Map := Map{ 'y' |-> 'a' }->union(Map{ 'e' |-> 'o' }->union((dictorsetmaker (test (logical_test (comparison (expr (atom 'q'))))) : (test (logical_test (comparison (expr (atom 'z'))))) ,))) ; var G : String := (atom '' 'ejp mysljylc kd kxveddknmc re jsicpdrysi\r rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd\r de kr kd eoya kw aej tysr re ujdr lkgc jv' '') ; var E : String := (atom '' 'our language is impossible to understand\r there are twenty six factorial possibilities\r so it is okay if you want to just give up' '') ; assert ((G)->size() = (E)->size()) do "assertion failed" ; for i : Integer.subrange(0, (G)->size()-1) do ( var g : OclAny := G[i+1] ; var e : OclAny := E[i+1] ; if (ALPHA)->characters()->includes(g) then ( assert ((ALPHA)->characters()->includes(e)) do "assertion failed" ; if (M)->excludes(g) then ( M[g+1] := e ) else ( assert (M[g+1] = e) do "assertion failed" ) ) else ( assert ((ALPHA)->characters()->excludes(e)) do "assertion failed" )) ; assert ((M)->size() = 25 or (M)->size() = 26) do "assertion failed" ; assert ((M)->size() = (Set{}->union((M.values())))->size()) do "assertion failed" ; if (M)->size() = 25 then ( g := StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name c)))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name ALPHA))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name c)))) not in (comparison (expr (atom (name M))))))))))), '') ; e := StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name c)))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name ALPHA))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name c)))) not in (comparison (expr (atom (name M)) (trailer . (name values) (arguments ( )))))))))))), '') ; M[g+1] := e ) else skip ; assert ((M)->size() = (Set{}->union((M.values())))->size()) do "assertion failed" ; assert (Set{}->union((M)) = Set{}->union((ALPHA))) do "assertion failed" ; return M; operation trans(s : OclAny, M : OclAny) : OclAny pre: true post: true activity: return StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name M)) (trailer . (name get) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c))))))) , (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name s)))))))), ''); operation main() pre: true post: true activity: M := makemap() ; var T : int := ("" + ((sys.stdin.readLine()->trim())))->toInteger() ; for i : Integer.subrange(0, T-1) do ( s := (OclFile["System.in"]).readLine() ; s := trans(s, M) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'Case #{}: ') (trailer . (name format) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ))))))))) )))) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys d={'a' : 'y','o' : 'e','z' : 'q',' ' : ' ','r' : 'p','l' : 'm','n' : 's','g' : 'l','u' : 'j','e' : 'c','i' : 'k','s' : 'd','m' : 'x','p' : 'v','t' : 'r','d' : 'i','b' : 'n','h' : 'b','w' : 't','y' : 'a','x' : 'h','f' : 'w','c' : 'f','k' : 'o','j' : 'u','v' : 'g','q' : 'z','\n' : '\n',} r=dict((v,k)for(k,v)in d.items()) if __name__=="__main__" : f=sys.stdin if len(sys.argv)>=2 : fn=sys.argv[1] if fn!='-' : f=open(fn) f.readline() i=1 for l in f : sys.stdout.write("Case #%d: " % i) for c in l : sys.stdout.write(r[c]) i+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var d : Map := Map{ 'a' |-> 'y' }->union(Map{ 'o' |-> 'e' }->union(Map{ 'z' |-> 'q' }->union(Map{ ' ' |-> ' ' }->union(Map{ 'r' |-> 'p' }->union(Map{ 'l' |-> 'm' }->union(Map{ 'n' |-> 's' }->union(Map{ 'g' |-> 'l' }->union(Map{ 'u' |-> 'j' }->union(Map{ 'e' |-> 'c' }->union(Map{ 'i' |-> 'k' }->union(Map{ 's' |-> 'd' }->union(Map{ 'm' |-> 'x' }->union(Map{ 'p' |-> 'v' }->union(Map{ 't' |-> 'r' }->union(Map{ 'd' |-> 'i' }->union(Map{ 'b' |-> 'n' }->union(Map{ 'h' |-> 'b' }->union(Map{ 'w' |-> 't' }->union(Map{ 'y' |-> 'a' }->union(Map{ 'x' |-> 'h' }->union(Map{ 'f' |-> 'w' }->union(Map{ 'c' |-> 'f' }->union(Map{ 'k' |-> 'o' }->union(Map{ 'j' |-> 'u' }->union(Map{ 'v' |-> 'g' }->union(Map{ 'q' |-> 'z' }->union((dictorsetmaker (test (logical_test (comparison (expr (atom ' '))))) : (test (logical_test (comparison (expr (atom ' '))))) ,)))))))))))))))))))))))))))) ; var r : Map := ((argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name v)))))) , (test (logical_test (comparison (expr (atom (name k))))))) )))))) (comp_for for (exprlist (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name k)))))) , (test (logical_test (comparison (expr (atom (name v))))))) )))) in (logical_test (comparison (expr (atom (name d)) (trailer . (name items) (arguments ( ))))))))) ; if __name__ = "__main__" then ( var f : OclFile := OclFile["System.in"] ; if ((trailer . (name argv)))->size() >= 2 then ( var fn : (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) := (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) ; if fn /= '-' then ( f := OclFile.newOclFile_Write(OclFile.newOclFile(fn)) ) else skip ) else skip ; f.readLine() ; var i : int := 1 ; for l : f do ((expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom "Case #%d: ")) % (expr (atom (name i))))))))) )))) ; for c : l do ((expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name r)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name c)))))))) ])))))))) ))))) ; i := i + 1) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import division from __future__ import with_statement from __future__ import print_function def memoized(func): mem={} def wrapped(*args): if args not in mem : mem[args]=func(*args) return mem[args] return wrapped from os.path import basename,splitext TASK=splitext(basename(__file__))[0] print("Task{}".format(TASK)) print("Precalculation...") from string import maketrans src="""aozq ejp mysljylc kd kxveddknmc re jsicpdrysi rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd de kr kd eoya kw aej tysr re ujdr lkgc jv""" dst="""yeqz our language is impossible to understand there are twenty six factorial possibilities so it is okay if you want to just give up""" table=maketrans(src,dst) print("Precalculation done.") print("Calculation...") with open(TASK+".in")as infile : with open(TASK+".out",mode="wt")as outfile : cases=int(infile.readline()) for ncase in range(cases): print("Case #{nc}".format(nc=ncase+1)) text=infile.readline().strip() data=text.translate(table) outfile.write("Case #{nc}:{data}\n".format(nc=ncase+1,data=data)) print("Calculation done.") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var TASK : OclAny := splitext(basename(__file__))->first() ; execute (StringLib.interpolateStrings("Task{}", Sequence{TASK}))->display() ; execute ("Precalculation...")->display() ; skip ; var src : String := (atom "" "aozq\r\nejp mysljylc kd kxveddknmc re jsicpdrysi\r\nrbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd\r\nde kr kd eoya kw aej tysr re ujdr lkgc jv" "") ; var dst : String := (atom "" "yeqz\r\nour language is impossible to understand\r\nthere are twenty six factorial possibilities\r\nso it is okay if you want to just give up" "") ; var table : OclAny := maketrans(src, dst) ; execute ("Precalculation done.")->display() ; execute ("Calculation...")->display() ; try (var infile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(TASK + ".in")); try (var outfile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(TASK + ".out")); var cases : int := ("" + ((infile.readLine())))->toInteger() ; for ncase : Integer.subrange(0, cases-1) do ( execute (StringLib.interpolateStrings("Case #{nc}", Sequence{(argument (test (logical_test (comparison (expr (atom (name nc)))))) = (test (logical_test (comparison (expr (expr (atom (name ncase))) + (expr (atom (number (integer 1)))))))))}))->display() ; var text : OclAny := infile.readLine()->trim() ; var data : OclAny := text.translate(table) ; outfile.write(StringLib.interpolateStrings("Case #{nc}:{data}\n", Sequence{(argument (test (logical_test (comparison (expr (atom (name nc)))))) = (test (logical_test (comparison (expr (expr (atom (name ncase))) + (expr (atom (number (integer 1))))))))), (argument (test (logical_test (comparison (expr (atom (name data)))))) = (test (logical_test (comparison (expr (atom (name data)))))))})))) catch (_e : OclException) do skip) catch (_e : OclException) do skip ; execute ("Calculation done.")->display(); operation memoized(func : OclAny) : OclAny pre: true post: true activity: var mem : OclAny := Set{} ; skip ; return wrapped; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import string encrypted=['ejp mysljylc kd kxveddknmc re jsicpdrysi','rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd','de kr kd eoya kw aej tysr re ujdr lkgc jv','y qeez'] decrypted=['our language is impossible to understand','there are twenty six factorial possibilities','so it is okay if you want to just give up','a zooq'] mapping={} for enc,dec in zip(encrypted,decrypted): for i in xrange(len(enc)): mapping[enc[i]]=dec[i] def decrypt_string(s): dec='' for c in s : dec+=mapping[c] return dec N=int(raw_input()) for i in xrange(N): line=raw_input().split() print('Case #%d: ' %(i+1))+' '.join(decrypt_string(s)for s in line) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var encrypted : Sequence := Sequence{'ejp mysljylc kd kxveddknmc re jsicpdrysi'}->union(Sequence{'rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd'}->union(Sequence{'de kr kd eoya kw aej tysr re ujdr lkgc jv'}->union(Sequence{ 'y qeez' }))) ; var decrypted : Sequence := Sequence{'our language is impossible to understand'}->union(Sequence{'there are twenty six factorial possibilities'}->union(Sequence{'so it is okay if you want to just give up'}->union(Sequence{ 'a zooq' }))) ; var mapping : OclAny := Set{} ; for _tuple : Integer.subrange(1, encrypted->size())->collect( _indx | Sequence{encrypted->at(_indx), decrypted->at(_indx)} ) do (var _indx : int := 1; var enc : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dec : OclAny := _tuple->at(_indx); for i : xrange((enc)->size()) do ( mapping[enc[i+1]+1] := dec[i+1])) ; skip ; var N : int := ("" + ((raw_input())))->toInteger() ; for i : xrange(N) do ( var line : OclAny := raw_input().split() ; (expr (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom 'Case #%d: ')) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) ))))))))) )))) + (expr (atom ' ') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name decrypt_string)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name line)))))))) )))))); operation decrypt_string(s : OclAny) : OclAny pre: true post: true activity: var dec : String := '' ; for c : s do ( dec := dec + mapping[c+1]) ; return dec; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- time=input() res="" hour=time[0 : 2] minute=time[3 : 5] reverseStr=[] for i in range(0,24): reverseStr.append(str(i)[: :-1]+'0'*(2-len(str(i)))) reverseNum=list(map(int,reverseStr)) i=int(hour) if reverseNum[i]<=int(minute): i=(i+1)% 24 while reverseNum[i]>=60 : i=(i+1)% 24 print('0'*(2-len(str(i)))+str(i)+":"+reverseStr[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var time : String := (OclFile["System.in"]).readLine() ; var res : String := "" ; var hour : OclAny := time.subrange(0+1, 2) ; var minute : OclAny := time.subrange(3+1, 5) ; var reverseStr : Sequence := Sequence{} ; for i : Integer.subrange(0, 24-1) do ( execute ((OclType["String"](i)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) + StringLib.nCopies('0', (2 - (("" + ((i))))->size()))) : reverseStr)) ; var reverseNum : Sequence := ((reverseStr)->collect( _x | (OclType["int"])->apply(_x) )) ; var i : int := ("" + ((hour)))->toInteger() ; if (reverseNum[i+1]->compareTo(("" + ((minute)))->toInteger())) <= 0 then ( i := (i + 1) mod 24 ) else skip ; while reverseNum[i+1] >= 60 do ( i := (i + 1) mod 24) ; execute (StringLib.nCopies('0', (2 - (("" + ((i))))->size())) + ("" + ((i))) + ":" + reverseStr[i+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(N,K): Array=[0]*(N+1) if(N<=K): print("1") return i=0 sm=K for i in range(1,K+1): Array[i]=1 Array[i+1]=sm for i in range(K+2,N+1): Array[i]=sm-Array[i-K-1]+Array[i-1] sm=Array[i] print(Array[N]) N=4 K=2 solve(N,K) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 4 ; K := 2 ; solve(N, K); operation solve(N : OclAny, K : OclAny) pre: true post: true activity: var Array : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; if ((N->compareTo(K)) <= 0) then ( execute ("1")->display() ; return ) else skip ; var i : int := 0 ; var sm : OclAny := K ; for i : Integer.subrange(1, K + 1-1) do ( Array[i+1] := 1) ; Array[i + 1+1] := sm ; for i : Integer.subrange(K + 2, N + 1-1) do ( Array[i+1] := sm - Array[i - K - 1+1] + Array[i - 1+1] ; sm := Array[i+1]) ; execute (Array[N+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math A,B,X=[int(i)for i in input().split()] ans1=math.ceil(X/1000)*A ans2=math.ceil(X/500)*B ans3=math.floor(X/1000)*A+math.ceil((X % 1000)/500)*B print(min(ans1,ans2,ans3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var A : OclAny := null; var B : OclAny := null; var X : OclAny := null; Sequence{A,B,X} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans1 : double := (X / 1000)->ceil() * A ; var ans2 : double := (X / 500)->ceil() * B ; var ans3 : double := (X / 1000)->floor() * A + ((X mod 1000) / 500)->ceil() * B ; execute (Set{ans1, ans2, ans3}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sps=['01','02','03','04','05','10','11','12','13','14','15','20','21','22','23','00'] hour,mins=input().split(':') for j in range(len(sps)): if hour in sps : rev_m=hour[: :-1] if int(rev_m)>int(mins): break else : mins=-1 hour=int(hour)+1 if hour<=5 : hour='0'+str(hour) else : hour=str(hour) else : hour=int(hour)+1 mins=-1 if hour<=5 : hour='0'+str(hour) else : hour=str(hour) if hour=='24' : hour='00' print(hour+':'+rev_m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sps : Sequence := Sequence{'01'}->union(Sequence{'02'}->union(Sequence{'03'}->union(Sequence{'04'}->union(Sequence{'05'}->union(Sequence{'10'}->union(Sequence{'11'}->union(Sequence{'12'}->union(Sequence{'13'}->union(Sequence{'14'}->union(Sequence{'15'}->union(Sequence{'20'}->union(Sequence{'21'}->union(Sequence{'22'}->union(Sequence{'23'}->union(Sequence{ '00' }))))))))))))))) ; var hour : OclAny := null; var mins : OclAny := null; Sequence{hour,mins} := input().split(':') ; for j : Integer.subrange(0, (sps)->size()-1) do ( if (sps)->includes(hour) then ( var rev_m : OclAny := hour(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; if (("" + ((rev_m)))->toInteger()->compareTo(("" + ((mins)))->toInteger())) > 0 then ( break ) else ( var mins : int := -1 ; var hour : int := ("" + ((hour)))->toInteger() + 1 ; if hour <= 5 then ( hour := '0' + ("" + ((hour))) ) else ( hour := ("" + ((hour))) ) ) ) else ( hour := ("" + ((hour)))->toInteger() + 1 ; mins := -1 ; if hour <= 5 then ( hour := '0' + ("" + ((hour))) ) else ( hour := ("" + ((hour))) ) ) ; if hour = '24' then ( hour := '00' ) else skip) ; execute (hour + ':' + rev_m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- hour,minute=map(int,input().split(':')) while True : minute+=1 if(minute==60): minute=0 hour+=1 if(hour==24): hour=0 s1=str(hour); s1='0'*(2-len(s1))+s1 s2=str(minute); s1+=':'+'0'*(2-len(s2))+s2 if(s1==s1[: :-1]): print(s1) exit() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var hour : OclAny := null; var minute : OclAny := null; Sequence{hour,minute} := (input().split(':'))->collect( _x | (OclType["int"])->apply(_x) ) ; while true do ( minute := minute + 1 ; if (minute = 60) then ( var minute : int := 0 ; hour := hour + 1 ) else skip ; if (hour = 24) then ( var hour : int := 0 ) else skip ; var s1 : String := ("" + ((hour))); s1 := StringLib.nCopies('0', (2 - (s1)->size())) + s1 ; var s2 : String := ("" + ((minute))); s1 := s1 + ':' + StringLib.nCopies('0', (2 - (s2)->size())) + s2 ; if (s1 = s1(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) then ( execute (s1)->display() ; exit() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000 ; def replaceSpaces(string): string=string.strip() i=len(string) space_count=string.count('') new_length=i+space_count*2 if new_length>MAX : return-1 index=new_length-1 string=list(string) for f in range(i-2,new_length-2): string.append('0') for j in range(i-1,0,-1): if string[j]=='' : string[index]='0' string[index-1]='2' string[index-2]='%' index=index-3 else : string[index]=string[j] index-=1 return ''.join(string) if __name__=='__main__' : s="Mr John Smith " s=replaceSpaces(s) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1000; ; skip ; if __name__ = '__main__' then ( var s : String := "Mr John Smith " ; s := replaceSpaces(s) ; execute (s)->display() ) else skip; operation replaceSpaces(string : OclAny) : OclAny pre: true post: true activity: string := string->trim() ; var i : int := (string)->size() ; var space_count : int := string->count('') ; var new_length : int := i + space_count * 2 ; if (new_length->compareTo(MAX)) > 0 then ( return -1 ) else skip ; var index : double := new_length - 1 ; string := (string)->characters() ; for f : Integer.subrange(i - 2, new_length - 2-1) do ( execute (('0') : string)) ; for j : Integer.subrange(0 + 1, i - 1)->reverse() do ( if string[j+1] = '' then ( string[index+1] := '0' ; string[index - 1+1] := '2' ; string[index - 2+1] := '%' ; index := index - 3 ) else ( string[index+1] := string[j+1] ; index := index - 1 )) ; return StringLib.sumStringsWithSeparator((string), ''); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,m=input().split(":") h,m=int(h),int(m) flag=False tth,ttm=h,m while(tth<24): while(ttm<59): ttm+=1 tm="0"*(2-len(str(ttm)))+str(ttm) th="0"*(2-len(str(tth)))+str(tth) res=th+":"+tm if res==res[-1 : :-1]: print(res) flag=True break if flag : break ttm=0 tth+=1 if not flag : print("00:00") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := input().split(":") ; var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := Sequence{("" + ((h)))->toInteger(),("" + ((m)))->toInteger()} ; var flag : boolean := false ; var tth : OclAny := null; var ttm : OclAny := null; Sequence{tth,ttm} := Sequence{h,m} ; while (tth < 24) do ( while (ttm < 59) do ( ttm := ttm + 1 ; var tm : String := StringLib.nCopies("0", (2 - (("" + ((ttm))))->size())) + ("" + ((ttm))) ; var th : String := StringLib.nCopies("0", (2 - (("" + ((tth))))->size())) + ("" + ((tth))) ; var res : String := th + ":" + tm ; if res = res(subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( execute (res)->display() ; flag := true ; break ) else skip) ; if flag then ( break ) else skip ; var ttm : int := 0 ; tth := tth + 1) ; if not(flag) then ( execute ("00:00")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,m=input().split(":") h,m=int(h),int(m) flag=False tth,ttm=h,m while(tth<24): while(ttm<59): ttm+=1 tm="0"*(2-len(str(ttm)))+str(ttm) th="0"*(2-len(str(tth)))+str(tth) res=th+":"+tm if res==res[-1 : :-1]: print(res) flag=True break if flag : break ttm=0 tth+=1 if not flag : print("00:00") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := input().split(":") ; var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := Sequence{("" + ((h)))->toInteger(),("" + ((m)))->toInteger()} ; var flag : boolean := false ; var tth : OclAny := null; var ttm : OclAny := null; Sequence{tth,ttm} := Sequence{h,m} ; while (tth < 24) do ( while (ttm < 59) do ( ttm := ttm + 1 ; var tm : String := StringLib.nCopies("0", (2 - (("" + ((ttm))))->size())) + ("" + ((ttm))) ; var th : String := StringLib.nCopies("0", (2 - (("" + ((tth))))->size())) + ("" + ((tth))) ; var res : String := th + ":" + tm ; if res = res(subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( execute (res)->display() ; flag := true ; break ) else skip) ; if flag then ( break ) else skip ; var ttm : int := 0 ; tth := tth + 1) ; if not(flag) then ( execute ("00:00")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findTheNumber(n): if(n==1): print("Impossible") return for i in range(n-1): print("5",end="") print("4") if __name__=='__main__' : n=12 findTheNumber(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 12 ; findTheNumber(n) ) else skip; operation findTheNumber(n : OclAny) pre: true post: true activity: if (n = 1) then ( execute ("Impossible")->display() ; return ) else skip ; for i : Integer.subrange(0, n - 1-1) do ( execute ("5")->display()) ; execute ("4")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from ast import Pow from cmath import* from decimal import* from operator import index from re import I import sys from tkinter import N input_=sys.stdin.readline def _input(): return map(int,input().split()) def _list(): return list(map(int,input().split())) def solves(): n=input() if(int(n)<10): print(n) else : ans=(len(n)-1)*9 if int('9'*len(n))==int(n): ans+=9 elif int('8'*len(n))<=int(n): ans+=8 elif int('7'*len(n))<=int(n): ans+=7 elif int('6'*len(n))<=int(n): ans+=6 elif int('5'*len(n))<=int(n): ans+=5 elif int('4'*len(n))<=int(n): ans+=4 elif int('3'*len(n))<=int(n): ans+=3 elif int('2'*len(n))<=int(n): ans+=2 elif int('1'*len(n))<=int(n): ans+=1 print(ans) t=1 t=int(input()) for _ in range(0,t): solves() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var input_ : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; var t : int := 1 ; t := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( solves()); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation _list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation solves() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; if (("" + ((n)))->toInteger() < 10) then ( execute (n)->display() ) else ( var ans : double := ((n)->size() - 1) * 9 ; if ("" + ((StringLib.nCopies('9', (n)->size()))))->toInteger() = ("" + ((n)))->toInteger() then ( ans := ans + 9 ) else (if (("" + ((StringLib.nCopies('8', (n)->size()))))->toInteger()->compareTo(("" + ((n)))->toInteger())) <= 0 then ( ans := ans + 8 ) else (if (("" + ((StringLib.nCopies('7', (n)->size()))))->toInteger()->compareTo(("" + ((n)))->toInteger())) <= 0 then ( ans := ans + 7 ) else (if (("" + ((StringLib.nCopies('6', (n)->size()))))->toInteger()->compareTo(("" + ((n)))->toInteger())) <= 0 then ( ans := ans + 6 ) else (if (("" + ((StringLib.nCopies('5', (n)->size()))))->toInteger()->compareTo(("" + ((n)))->toInteger())) <= 0 then ( ans := ans + 5 ) else (if (("" + ((StringLib.nCopies('4', (n)->size()))))->toInteger()->compareTo(("" + ((n)))->toInteger())) <= 0 then ( ans := ans + 4 ) else (if (("" + ((StringLib.nCopies('3', (n)->size()))))->toInteger()->compareTo(("" + ((n)))->toInteger())) <= 0 then ( ans := ans + 3 ) else (if (("" + ((StringLib.nCopies('2', (n)->size()))))->toInteger()->compareTo(("" + ((n)))->toInteger())) <= 0 then ( ans := ans + 2 ) else (if (("" + ((StringLib.nCopies('1', (n)->size()))))->toInteger()->compareTo(("" + ((n)))->toInteger())) <= 0 then ( ans := ans + 1 ) else skip ) ) ) ) ) ) ) ) ; execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math t=int(input()) for i in range(t): n=int(input()) beautiful_numbers=0 if n<10 : beautiful_numbers=n print(beautiful_numbers) else : if len(set(str(n)))==2 and str(n).count('1')==1 and str(n).count('0')==len(str(n))-1 : beautiful_numbers+=math.ceil(math.log(n,10))*9 print(beautiful_numbers) else : beautiful_numbers+=math.floor(math.log(n,10))*9 beautiful_numbers+=n//int('1'*len(str(n))) print(beautiful_numbers) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var beautiful_numbers : int := 0 ; if n < 10 then ( beautiful_numbers := n ; execute (beautiful_numbers)->display() ) else ( if (Set{}->union((("" + ((n))))))->size() = 2 & OclType["String"](n)->count('1') = 1 & OclType["String"](n)->count('0') = (("" + ((n))))->size() - 1 then ( beautiful_numbers := beautiful_numbers + ((n, 10)->log())->ceil() * 9 ; execute (beautiful_numbers)->display() ) else ( beautiful_numbers := beautiful_numbers + ((n, 10)->log())->floor() * 9 ; beautiful_numbers := beautiful_numbers + n div ("" + ((StringLib.nCopies('1', (("" + ((n))))->size()))))->toInteger() ; execute (beautiful_numbers)->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() for _ in range(int(input())): s=input() ans=(len(s)-1)*9+int(s)//int('1'*len(s)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var ans : double := ((s)->size() - 1) * 9 + ("" + ((s)))->toInteger() div ("" + ((StringLib.nCopies('1', (s)->size()))))->toInteger() ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d=[] for i in range(1,10): for j in range(1,20): s=((str(i))*j) d.append(int(s)) d.sort() for i in range(int(input())): n=int(input()) for i in range(len(d)): if d[i]==n : print(i+1) break elif d[i]>n : print(i) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : Sequence := Sequence{} ; for i : Integer.subrange(1, 10-1) do ( for j : Integer.subrange(1, 20-1) do ( var s : double := ((("" + ((i)))) * j) ; execute ((("" + ((s)))->toInteger()) : d))) ; d := d->sort() ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, (d)->size()-1) do ( if d[i+1] = n then ( execute (i + 1)->display() ; break ) else (if (d[i+1]->compareTo(n)) > 0 then ( execute (i)->display() ; break ) else skip))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): a=list(input()) b=int("".join(a)) count=9 if b<10 : print(b) continue else : l=len(a) f=a[0] count=9*(l-1) current=0 while a[current]==a[0]and current!=len(a)-1 : current+=1 if int(a[current])>=int(f): count+=int(f) else : count+=int(f)-1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var a : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var b : int := ("" + ((StringLib.sumStringsWithSeparator((a), ""))))->toInteger() ; var count : int := 9 ; if b < 10 then ( execute (b)->display() ; continue ) else ( var l : int := (a)->size() ; var f : OclAny := a->first() ; count := 9 * (l - 1) ; var current : int := 0 ; while a[current+1] = a->first() & current /= (a)->size() - 1 do ( current := current + 1) ; if (("" + ((a[current+1])))->toInteger()->compareTo(("" + ((f)))->toInteger())) >= 0 then ( count := count + ("" + ((f)))->toInteger() ) else ( count := count + ("" + ((f)))->toInteger() - 1 ) ) ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,n=list(map(int,input().split())) if n % 500!=0 : n=n+500-n % 500 if a>=b*2 : print((n//500)*b) elif acollect( _x | (OclType["int"])->apply(_x) )) ; if n mod 500 /= 0 then ( var n : double := n + 500 - n mod 500 ) else skip ; if (a->compareTo(b * 2)) >= 0 then ( execute ((n div 500) * b)->display() ) else (if (a->compareTo(b)) < 0 then ( if n mod 1000 /= 0 then ( n := n + 1000 - n mod 1000 ) else skip ; execute ((n div 1000) * a)->display() ) else ( execute (((n div 1000) * a) + ((n mod 1000) div 500) * b)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def countSubstr(s): n=len(s) auxArr=[0 for i in range(n)] if(s[0]=='1'): auxArr[0]=1 for i in range(0,n): if(s[i]=='1'): auxArr[i]=auxArr[i-1]+1 else : auxArr[i]=auxArr[i-1] count=0 for i in range(n-1,-1,-1): if(s[i]=='1'): count+=auxArr[i] return count s="1101" print(countSubstr(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; s := "1101" ; execute (countSubstr(s))->display(); operation countSubstr(s : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; var auxArr : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; if (s->first() = '1') then ( auxArr->first() := 1 ) else skip ; for i : Integer.subrange(0, n-1) do ( if (s[i+1] = '1') then ( auxArr[i+1] := auxArr[i - 1+1] + 1 ) else ( auxArr[i+1] := auxArr[i - 1+1] )) ; var count : int := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (s[i+1] = '1') then ( count := count + auxArr[i+1] ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) X=input() D=int(input()) ans=list(X) done=[False]*N for i in range(N): if D==0 : break if ans[i]=="0" : ans[i]="1" done[i]=True D-=1 for i in range(N)[: :-1]: if D==0 : break if ans[i]=="1" and not done[i]: ans[i]="0" D-=1 print("".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var X : String := (OclFile["System.in"]).readLine() ; var D : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := (X)->characters() ; var done : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, N) ; for i : Integer.subrange(0, N-1) do ( if D = 0 then ( break ) else skip ; if ans[i+1] = "0" then ( ans[i+1] := "1" ; done[i+1] := true ; D := D - 1 ) else skip) ; for i : range(N)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if D = 0 then ( break ) else skip ; if ans[i+1] = "1" & not(done[i+1]) then ( ans[i+1] := "0" ; D := D - 1 ) else skip) ; execute (StringLib.sumStringsWithSeparator((ans), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x1,y1=map(int,input().split()) x2,y2=map(int,input().split()) print(max(abs(x1-x2),abs(y1-y2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{(x1 - x2)->abs(), (y1 - y2)->abs()}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=list(map(int,input().split())) x1,y1=list(map(int,input().split())) a=abs(x-x1) b=abs(y-y1) if(a>=b): print(a) else : print(b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : double := (x - x1)->abs() ; var b : double := (y - y1)->abs() ; if ((a->compareTo(b)) >= 0) then ( execute (a)->display() ) else ( execute (b)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x1,y1=map(int,input().split()) x2,y2=map(int,input().split()) z1=abs(x1-x2) z2=abs(y1-y2) print(max(z1,z2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var z1 : double := (x1 - x2)->abs() ; var z2 : double := (y1 - y2)->abs() ; execute (Set{z1, z2}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=map(int,input().split()) a,b=map(int,input().split()) s=abs(x-a) r=abs(y-b) print(max(s,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : double := (x - a)->abs() ; var r : double := (y - b)->abs() ; execute (Set{s, r}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import os import random import re import sys from math import gcd from math import sqrt x,y=list(map(int,input().split())) a,b=list(map(int,input().split())) mx=abs(x-a) mx2=abs(y-b) print(max(mx,mx2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mx : double := (x - a)->abs() ; var mx2 : double := (y - b)->abs() ; execute (Set{mx, mx2}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): LIMIT=40 ans=sum(count_step_pandigital(digits,head,0,9)for digits in range(LIMIT+1)for head in range(1,10)) return str(ans) @ eulerlib.memoize def count_step_pandigital(digits,head,low,high): assert digits>=0 assert low<=head<=high if digits<=1 : return 1 if(low==head==high)else 0 else : result=0 if head-1>=low : result+=count_step_pandigital(digits-1,head-1,low,high) if head==high : result+=count_step_pandigital(digits-1,head-1,low,high-1) if head+1<=high : result+=count_step_pandigital(digits-1,head+1,low,high) if head==low : result+=count_step_pandigital(digits-1,head+1,low+1,high) assert 0<=result<10**digits return result if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; (compound_stmt (decorator @ (dotted_name (dotted_name (name eulerlib)) . (name memoize))) (funcdef def (name count_step_pandigital) ( (typedargslist (def_parameters (def_parameter (named_parameter (name digits))) , (def_parameter (named_parameter (name head))) , (def_parameter (named_parameter (name low))) , (def_parameter (named_parameter (name high))))) ) : (suite (stmt (simple_stmt (small_stmt assert (test (logical_test (comparison (comparison (expr (atom (name digits)))) >= (comparison (expr (atom (number (integer 0))))))))))) (stmt (simple_stmt (small_stmt assert (test (logical_test (comparison (comparison (comparison (expr (atom (name low)))) <= (comparison (expr (atom (name head))))) <= (comparison (expr (atom (name high)))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name digits)))) <= (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))) if (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (comparison (expr (atom (name low)))) == (comparison (expr (atom (name head))))) == (comparison (expr (atom (name high)))))))) ))))) else (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name result)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name head))) - (expr (atom (number (integer 1)))))) >= (comparison (expr (atom (name low))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name result)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name count_step_pandigital)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name digits))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name head))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name low))))))) , (argument (test (logical_test (comparison (expr (atom (name high)))))))) )))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name head)))) == (comparison (expr (atom (name high))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name result)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name count_step_pandigital)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name digits))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name head))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name low))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name high))) - (expr (atom (number (integer 1)))))))))) )))))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name head))) + (expr (atom (number (integer 1)))))) <= (comparison (expr (atom (name high))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name result)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name count_step_pandigital)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name digits))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name head))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name low))))))) , (argument (test (logical_test (comparison (expr (atom (name high)))))))) )))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name head)))) == (comparison (expr (atom (name low))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name result)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name count_step_pandigital)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name digits))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name head))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name low))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name high)))))))) )))))))))))))))))) (stmt (simple_stmt (small_stmt assert (test (logical_test (comparison (comparison (comparison (expr (atom (number (integer 0))))) <= (comparison (expr (atom (name result))))) < (comparison (expr (expr (atom (number (integer 10)))) ** (expr (atom (name digits))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name result))))))))))))))))) ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LIMIT : int := 40 ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name count_step_pandigital)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name digits))))))) , (argument (test (logical_test (comparison (expr (atom (name head))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 9))))))))) ))))))) (comp_for for (exprlist (expr (atom (name digits)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name LIMIT))) + (expr (atom (number (integer 1)))))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name head)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 10))))))))) )))))))))))->sum() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Activity : def __init__(self,s,e): self.s=s self.e=e n=int(input()) acts=[] for i in range(n): si,ei=map(int,input().split()) acts.append(Activity(si,ei)) acts.sort(key=lambda x : x.s) stack=[] stack.append(acts[0]) for i in range(1,n): last=stack[-1] acti=acts[i] if acti.s>last.e : stack.append(acti) elif acti.eexists( _x | result = _x ); attribute s : OclAny := s; attribute e : OclAny := e; operation initialise(s : OclAny,e : OclAny) : Activity pre: true post: true activity: self.s := s ; self.e := e; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var acts : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var si : OclAny := null; var ei : OclAny := null; Sequence{si,ei} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (((Activity.newActivity()).initialise(si, ei)) : acts)) ; acts := acts->sort() ; var stack : Sequence := Sequence{} ; execute ((acts->first()) : stack) ; for i : Integer.subrange(1, n-1) do ( var last : OclAny := stack->last() ; var acti : OclAny := acts[i+1] ; if (acti.s->compareTo(last.e)) > 0 then ( execute ((acti) : stack) ) else (if (acti.e->compareTo(last.e)) < 0 then ( stack := stack->front() ; execute ((acti) : stack) ) else skip)) ; execute ((stack)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,collections input=lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF=10**10 def I(): return int(input()) def F(): return float(input()) def SS(): 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 LSS(): return input().split() def resolve(): n=I() st=[LI()for _ in range(n)] st.sort(key=lambda x : x[1]) ans=0 end_time=0 for i in range(n): if st[i][0]>end_time : ans+=1 end_time=st[i][1] print(ans) if __name__=='__main__' : resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; sys.setrecursionlimit((10)->pow(7)) ; var INF : double := (10)->pow(10) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( resolve() ) else skip; operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation SS() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation LI() : OclAny pre: true post: true activity: return input->apply().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return input->apply().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return input->apply().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LSS() : OclAny pre: true post: true activity: return input->apply().split(); operation resolve() pre: true post: true activity: var n : OclAny := I() ; var st : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI())) ; st := st->sort() ; var ans : int := 0 ; var end_time : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (st[i+1]->first()->compareTo(end_time)) > 0 then ( ans := ans + 1 ; end_time := st[i+1][1+1] ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : num_activities=int(input()) activities=[[0,0]for _ in range(num_activities)] for i in range(num_activities): activities[i]=list(map(lambda x : int(x),input().split())) activities=sorted(activities,key=lambda x : x[1]) current_start=-1 result=0 for start,end in activities : if current_starttoInteger() ; var activities : Sequence := Integer.subrange(0, num_activities-1)->select(_anon | true)->collect(_anon | (Sequence{0}->union(Sequence{ 0 }))) ; for i : Integer.subrange(0, num_activities-1) do ( activities[i+1] := ((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ))) ; activities := activities->sortedBy($x | (lambda x : OclAny in (x[1+1]))->apply($x)) ; var current_start : int := -1 ; var result : int := 0 ; for _tuple : activities do (var _indx : int := 1; var start : OclAny := _tuple->at(_indx); _indx := _indx + 1; var end : OclAny := _tuple->at(_indx); if (current_start->compareTo(start)) < 0 then ( result := result + 1 ; current_start := end ) else skip) ; execute (result)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math A,B,X=map(int,input().split()) if Acollect( _x | (OclType["int"])->apply(_x) ) ; if (A->compareTo(B)) < 0 then ( execute (A * (-(-X div 1000)))->display() ) else (if (A->compareTo(2 * B)) < 0 then ( var C : double := A * (X div 1000) ; if X mod 1000 = 0 then ( skip ) else (if X mod 1000 <= 500 then ( C := C + B ) else ( C := C + A ) ) ; execute (C)->display() ) else ( execute (B * (-(-X div 500)))->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import combinations N,K=map(int,input().split()) P=[tuple(map(int,input().split()))for _ in range(N)] ans=10**18*5 for x in combinations(range(N),2): u=max(P[x[0]][0],P[x[1]][0]) d=min(P[x[0]][0],P[x[1]][0]) for y in combinations(range(N),2): r=max(P[y[0]][1],P[y[1]][1]) l=min(P[y[0]][1],P[y[1]][1]) count=0 for i in range(N): if d<=P[i][0]<=u and l<=P[i][1]<=r : count+=1 if count>=K : ans=min(ans,(u-d)*(r-l)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var P : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ans : double := (10)->pow(18) * 5 ; for x : combinations(Integer.subrange(0, N-1), 2) do ( var u : OclAny := Set{P[x->first()+1]->first(), P[x[1+1]+1]->first()}->max() ; var d : OclAny := Set{P[x->first()+1]->first(), P[x[1+1]+1]->first()}->min() ; for y : combinations(Integer.subrange(0, N-1), 2) do ( var r : OclAny := Set{P[y->first()+1][1+1], P[y[1+1]+1][1+1]}->max() ; var l : OclAny := Set{P[y->first()+1][1+1], P[y[1+1]+1][1+1]}->min() ; var count : int := 0 ; for i : Integer.subrange(0, N-1) do ( if (d->compareTo(P[i+1]->first())) <= 0 & (P[i+1]->first() <= u) & (l->compareTo(P[i+1][1+1])) <= 0 & (P[i+1][1+1] <= r) then ( count := count + 1 ) else skip) ; if (count->compareTo(K)) >= 0 then ( ans := Set{ans, (u - d) * (r - l)}->min() ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- readline=open(0).readline from heapq import heappush,heappop N=int(readline()) que=[] P=[list(map(int,readline().split()))for i in range(N)] P.sort() ans=0 for s,t in P : while que and que[0][0]toInteger() ; var que : Sequence := Sequence{} ; var P : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((readline().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; P := P->sort() ; var ans : int := 0 ; for _tuple : P do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); while que & (que->first()->first()->compareTo(s)) < 0 do ( ans := Set{ans, heappop(que)[1+1]}->max()) ; heappush(que, Sequence{t, ans + 1})) ; while que do ( ans := Set{ans, heappop(que)[1+1]}->max()) ; (expr (atom (name open)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom 'w'))))))) ))) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom "%d\n")) % (expr (atom (name ans))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def act(st): st.sort(key=lambda x : x[0]) OP=[st[0]] for i in range(1,len(st)): if OP[len(OP)-1][1]sort() ; var OP : Sequence := Sequence{ st->first() } ; for i : Integer.subrange(1, (st)->size()-1) do ( if (OP[(OP)->size() - 1+1][1+1]->compareTo(st[i+1]->first())) < 0 then ( execute ((st[i+1]) : OP) ) else (if (OP[(OP)->size() - 1+1][1+1]->compareTo(st[i+1][1+1])) <= 0 then ( skip ) else ( OP := OP->front() ; execute ((st[i+1]) : OP) ) ) ) ; return (OP)->size(); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; st := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ans : OclAny := act(st) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import sqrt def min_moves(n): ans=sys.maxsize ; for i in range(1,int(sqrt(n))+1): if(n % i==0): ans=min(ans,i+n//i-2); return ans ; if __name__=="__main__" : n=10 ; print(min_moves(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( n := 10; ; execute (min_moves(n))->display(); ) else skip; operation min_moves(n : OclAny) pre: true post: true activity: var ans : (trailer . (name maxsize)) := (trailer . (name maxsize)); ; for i : Integer.subrange(1, ("" + ((sqrt(n))))->toInteger() + 1-1) do ( if (n mod i = 0) then ( ans := Set{ans, i + n div i - 2}->min(); ) else skip) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr1=[] for x in range(1,n+1): first_element=1 arr1.append([1]) for y in range(1,n): if x==1 : arr1[-1].append(arr1[-1][-1]) else : arr1[-1].append(arr1[-2][y]+arr1[-1][-1]) print(arr1[-1][-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr1 : Sequence := Sequence{} ; for x : Integer.subrange(1, n + 1-1) do ( var first_element : int := 1 ; execute ((Sequence{ 1 }) : arr1) ; for y : Integer.subrange(1, n-1) do ( if x = 1 then ( (expr (atom (name arr1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))))) )))) ) else ( (expr (atom (name arr1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name arr1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 2))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ]))) + (expr (atom (name arr1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))))))))) )))) ))) ; execute (arr1->last()->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) L=[] for i in range(n): ls=[] for j in range(n): if i==0 or j==0 : ls.append(1) else : ls.append(ls[-1]+L[i-1][j]) L.append(ls) print(L[-1][-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var L : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var ls : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( if i = 0 or j = 0 then ( execute ((1) : ls) ) else ( execute ((ls->last() + L[i - 1+1][j+1]) : ls) )) ; execute ((ls) : L)) ; execute (L->last()->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[] for i in range(n): ls=[] for j in range(n): if i==0 or j==0 : ls.append(1) else : ls.append(ls[-1]+l[i-1][j]) l.append(ls) print(l[-1][-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var ls : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( if i = 0 or j = 0 then ( execute ((1) : ls) ) else ( execute ((ls->last() + l[i - 1+1][j+1]) : ls) )) ; execute ((ls) : l)) ; execute (l->last()->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[] for i in range(n): ls=[] for j in range(n): if i==0 or j==0 : ls.append(1) else : ls.append(ls[-1]+l[i-1][j]) l.append(ls) print(l[-1][-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var ls : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( if i = 0 or j = 0 then ( execute ((1) : ls) ) else ( execute ((ls->last() + l[i - 1+1][j+1]) : ls) )) ; execute ((ls) : l)) ; execute (l->last()->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==1 : print(1) if n==2 : print(2) if n==3 : print(6) if n==4 : print(20) if n==5 : print(70) if n==6 : print(252) if n==7 : print(924) if n==8 : print(3432) if n==9 : print(12870) if n==10 : print(48620) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (1)->display() ) else skip ; if n = 2 then ( execute (2)->display() ) else skip ; if n = 3 then ( execute (6)->display() ) else skip ; if n = 4 then ( execute (20)->display() ) else skip ; if n = 5 then ( execute (70)->display() ) else skip ; if n = 6 then ( execute (252)->display() ) else skip ; if n = 7 then ( execute (924)->display() ) else skip ; if n = 8 then ( execute (3432)->display() ) else skip ; if n = 9 then ( execute (12870)->display() ) else skip ; if n = 10 then ( execute (48620)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) s=input() s1="" for j in range(n): if s[j]=='1' or s[j]=='3' or s[j]=='5' or s[j]=='7' or s[j]=='9' : s1=s1+s[j] if len(s1)==2 : break if len(s1)==2 : print(s1) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var s1 : String := "" ; for j : Integer.subrange(0, n-1) do ( if s[j+1] = '1' or s[j+1] = '3' or s[j+1] = '5' or s[j+1] = '7' or s[j+1] = '9' then ( s1 := s1 + s[j+1] ) else skip ; if (s1)->size() = 2 then ( break ) else skip) ; if (s1)->size() = 2 then ( execute (s1)->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- number_of_testcases=int(input()) def sum(digits): result=0 for i in digits : result+=i return result def change_sum_parity(digits): for i in range(0,len(digits)-2): if digits[i]% 2==1 : return digits[0 : i]+digits[i+1 : len(digits)] return[-1] def to_string(digits): output='' for i in digits : output=output+str(i) return output for i in range(number_of_testcases): n=int(input()) s=input() digits=[] for digit in s : digits.append(int(digit)) if len(digits)<=1 : print('-1') else : if sum(digits)% 2==1 : digits=change_sum_parity(digits) while digits[0]==0 : digits=digits[1 :] if len(digits)==0 : digits=[-1] while digits[-1]% 2==0 : if len(digits)>1 : digits=digits[:-1] else : digits=[-1] print(to_string(digits)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var number_of_testcases : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; skip ; skip ; for i : Integer.subrange(0, number_of_testcases-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; digits := Sequence{} ; for digit : s->characters() do ( execute ((("" + ((digit)))->toInteger()) : digits)) ; if (digits)->size() <= 1 then ( execute ('-1')->display() ) else ( if (digits)->sum() mod 2 = 1 then ( digits := change_sum_parity(digits) ) else skip ; while digits->first() = 0 do ( digits := digits->tail() ; if (digits)->size() = 0 then ( digits := Sequence{ -1 } ) else skip) ; while digits->last() mod 2 = 0 do ( if (digits)->size() > 1 then ( digits := digits->front() ) else ( digits := Sequence{ -1 } )) ; execute (to_string(digits))->display() )); operation sum(digits : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; for i : digits do ( result := result + i) ; return result; operation change_sum_parity(digits : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, (digits)->size() - 2-1) do ( if digits[i+1] mod 2 = 1 then ( return digits.subrange(0+1, i) + digits.subrange(i + 1+1, (digits)->size()) ) else skip) ; return Sequence{ -1 }; operation to_string(digits : OclAny) : OclAny pre: true post: true activity: var output : String := '' ; for i : digits do ( output := output + ("" + ((i)))) ; return output; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=10**9+7 l=input() n=len(l) dp=[[0]*2 for _ in range(n+1)] dp[0][0]=1 for i,c in enumerate(l): if c=='0' : dp[i+1][0]+=dp[i][0] dp[i+1][1]+=dp[i][1]*3 else : dp[i+1][0]+=dp[i][0]*2 dp[i+1][1]+=dp[i][0] dp[i+1][1]+=dp[i][1]*3 dp[i+1][0]%=mod dp[i+1][1]%=mod print((dp[n][0]+dp[n][1])% mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : double := (10)->pow(9) + 7 ; var l : String := (OclFile["System.in"]).readLine() ; var n : int := (l)->size() ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 2))) ; dp->first()->first() := 1 ; for _tuple : Integer.subrange(1, (l)->size())->collect( _indx | Sequence{_indx-1, (l)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if c = '0' then ( dp[i + 1+1]->first() := dp[i + 1+1]->first() + dp[i+1]->first() ; dp[i + 1+1][1+1] := dp[i + 1+1][1+1] + dp[i+1][1+1] * 3 ) else ( dp[i + 1+1]->first() := dp[i + 1+1]->first() + dp[i+1]->first() * 2 ; dp[i + 1+1][1+1] := dp[i + 1+1][1+1] + dp[i+1]->first() ; dp[i + 1+1][1+1] := dp[i + 1+1][1+1] + dp[i+1][1+1] * 3 ) ; dp[i + 1+1]->first() := dp[i + 1+1]->first() mod mod ; dp[i + 1+1][1+1] := dp[i + 1+1][1+1] mod mod) ; execute ((dp[n+1]->first() + dp[n+1][1+1]) mod mod)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import array def num_string_to_array(num_string): return array.array("B",map(int,num_string)) def num_array_to_string(num_array): return "".join(map(str,num_array)) def solve(n,x,d): answer=x[:] rest_distance=d for i in range(n): if rest_distance<=0 : return answer elif answer[i]==0 : answer[i]=1 rest_distance-=1 for j in range(n)[: :-1]: if rest_distance<=0 : return answer elif answer[j]==1 and answer[j]==x[j]: answer[j]=0 rest_distance-=1 return answer def main(): n=int(input()) x=num_string_to_array(input()) d=int(input()) answer=num_array_to_string(solve(n,x[:],d)) print(answer) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation num_string_to_array(num_string : OclAny) : OclAny pre: true post: true activity: return array.array("B", (num_string)->collect( _x | (OclType["int"])->apply(_x) )); operation num_array_to_string(num_array : OclAny) : OclAny pre: true post: true activity: return StringLib.sumStringsWithSeparator(((num_array)->collect( _x | (OclType["String"])->apply(_x) )), ""); operation solve(n : OclAny, x : OclAny, d : OclAny) : OclAny pre: true post: true activity: var answer : Sequence := x ; var rest_distance : OclAny := d ; for i : Integer.subrange(0, n-1) do ( if rest_distance <= 0 then ( return answer ) else (if answer[i+1] = 0 then ( answer[i+1] := 1 ; rest_distance := rest_distance - 1 ) else skip)) ; for j : range(n)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if rest_distance <= 0 then ( return answer ) else (if answer[j+1] = 1 & answer[j+1] = x[j+1] then ( answer[j+1] := 0 ; rest_distance := rest_distance - 1 ) else skip)) ; return answer; operation main() pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; x := num_string_to_array((OclFile["System.in"]).readLine()) ; d := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; answer := num_array_to_string(solve(n, x, d)) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,x=map(int,input().split()) ans=10**10 for i in range(22): for j in range(44): if i*1000+j*500>=x : ans=min(ans,a*i+b*j) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var x : OclAny := null; Sequence{a,b,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : double := (10)->pow(10) ; for i : Integer.subrange(0, 22-1) do ( for j : Integer.subrange(0, 44-1) do ( if (i * 1000 + j * 500->compareTo(x)) >= 0 then ( ans := Set{ans, a * i + b * j}->min() ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def eprint(*args,**kwargs): print(*args,file=sys.stderr,**kwargs) def pseudo_even(n): return sum(n)% 2==0 tests=int(input()) for _ in range(tests): digits=int(input()) number=list(input()) number=[int(x)for x in number] while len(number)>0 and number[0]==0 : number.pop(0) if len(number)==0 : print(-1) continue eprint("number after removing leading zeroes",number) rnumber=[] while len(number)>0 and not pseudo_even(number): x=number.pop() eprint(x) if x % 2==0 and x!=0 : rnumber.insert(0,x) if len(number)==0 : print(-1) continue eprint(rnumber) eprint("number after pseudo-even",number) while len(number)>0 and number[-1]% 2==0 : number.pop() eprint("number after making it odd",number) if len(number)==0 : print(-1) else : number=[str(x)for x in number] print("".join(number)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var tests : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, tests-1) do ( var digits : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var number : Sequence := ((OclFile["System.in"]).readLine())->characters() ; number := number->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; while (number)->size() > 0 & number->first() = 0 do ( number := number->excludingAt(0+1)) ; if (number)->size() = 0 then ( execute (-1)->display() ; continue ) else skip ; eprint("number after removing leading zeroes", number) ; var rnumber : Sequence := Sequence{} ; while (number)->size() > 0 & not(pseudo_even(number)) do ( var x : OclAny := number->last() ; number := number->front() ; eprint(x) ; if x mod 2 = 0 & x /= 0 then ( rnumber := rnumber.insertAt(0+1, x) ) else skip) ; if (number)->size() = 0 then ( execute (-1)->display() ; continue ) else skip ; eprint(rnumber) ; eprint("number after pseudo-even", number) ; while (number)->size() > 0 & number->last() mod 2 = 0 do ( number := number->front()) ; eprint("number after making it odd", number) ; if (number)->size() = 0 then ( execute (-1)->display() ) else ( number := number->select(x | true)->collect(x | (("" + ((x))))) ; execute (StringLib.sumStringsWithSeparator((number), ""))->display() )); operation eprint(args : OclAny : Sequence(OclAny), kwargs : OclAny : Map(String, OclAny)) pre: true post: true activity: (args * (named_parameter (name args)))(kwargs ** (named_parameter (name kwargs))) execute ((argument * (test (logical_test (comparison (expr (atom (name args))))))))->display(); operation pseudo_even(n : OclAny) : OclAny pre: true post: true activity: return (n)->sum() mod 2 = 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=input('') k=int(k) i=0 while(itoInteger() ; var i : int := 0 ; while (i < k) do ( var num : String := (OclFile["System.in"]).readLine('') ; num := ("" + ((num)))->toInteger() ; var n : String := (OclFile["System.in"]).readLine('') ; var co : int := 0 ; var m : int := 0 ; while (m < num) do ( var tmp : int := ("" + ((n[m+1])))->toInteger() ; if (tmp mod 2 /= 0) then ( co := co + 1 ) else skip ; m := m + 1) ; if (co < 2) then ( execute (-1)->display() ) else ( var prinum1 : int := 0 ; var prinum2 : int := 0 ; for j : n->characters() do ( tmp := ("" + ((j)))->toInteger() ; if (tmp mod 2 /= 0) then ( if (prinum1 = 0) then ( prinum1 := tmp ) else ( prinum2 := tmp ; break ) ) else skip) ; execute (prinum1 * 10 + prinum2)->display() ) ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for loop in range(t): n=int(input()) s=input() sl=list(map(int,list(s))) while len(sl)>0 and sl[-1]% 2==0 : del sl[-1] ad=sum(sl) flag=True if ad % 2==1 : flag=False for i in range(len(sl)): if sl[i]% 2==1 : if i==0 and len(sl)>1 and sl[1]==0 : continue del sl[i] flag=True break if flag and len(sl)>0 and sl[-1]% 2==1 : print("".join(map(str,sl))) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for loop : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var sl : Sequence := (((s)->characters())->collect( _x | (OclType["int"])->apply(_x) )) ; while (sl)->size() > 0 & sl->last() mod 2 = 0 do ( execute (sl->last())->isDeleted()) ; var ad : OclAny := (sl)->sum() ; var flag : boolean := true ; if ad mod 2 = 1 then ( flag := false ; for i : Integer.subrange(0, (sl)->size()-1) do ( if sl[i+1] mod 2 = 1 then ( if i = 0 & (sl)->size() > 1 & sl[1+1] = 0 then ( continue ) else skip ; execute (sl[i+1])->isDeleted() ; flag := true ; break ) else skip) ) else skip ; if flag & (sl)->size() > 0 & sl->last() mod 2 = 1 then ( execute (StringLib.sumStringsWithSeparator(((sl)->collect( _x | (OclType["String"])->apply(_x) )), ""))->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(b==0): return a return gcd(b,a % b) def maxLengthSubArray(arr,n): maxLen=-1 for i in range(n-1): for j in range(n): lcm=arr[i] product=arr[i] for k in range(i+1,j+1): lcm=(((arr[k]*lcm))//(gcd(arr[k],lcm))) product=product*arr[k] if(lcm==product): maxLen=max(maxLen,j-i+1) return maxLen arr=[6,10,21] n=len(arr) print(maxLengthSubArray(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{6}->union(Sequence{10}->union(Sequence{ 21 })) ; n := (arr)->size() ; execute (maxLengthSubArray(arr, n))->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (b = 0) then ( return a ) else skip ; return gcd(b, a mod b); operation maxLengthSubArray(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var maxLen : int := -1 ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(0, n-1) do ( var lcm : OclAny := arr[i+1] ; var product : OclAny := arr[i+1] ; for k : Integer.subrange(i + 1, j + 1-1) do ( lcm := (((arr[k+1] * lcm)) div (gcd(arr[k+1], lcm))) ; product := product * arr[k+1]) ; if (lcm = product) then ( maxLen := Set{maxLen, j - i + 1}->max() ) else skip)) ; return maxLen; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def isPrime(n): if(n<=1): return False if(n<=3): return True if(n % 2==0 or n % 3==0): return False k=int(sqrt(n))+1 for i in range(5,k,6): if(n % i==0 or n %(i+2)==0): return False return True def isStrongPrime(n): if(isPrime(n)==False or n==2): return False previous_prime=n-1 next_prime=n+1 while(isPrime(next_prime)==False): next_prime+=1 while(isPrime(previous_prime)==False): previous_prime-=1 mean=(previous_prime+next_prime)/2 if(n>mean): return True else : return False if __name__=='__main__' : n=11 if(isStrongPrime(n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( n := 11 ; if (isStrongPrime(n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isPrime(n : OclAny) : OclAny pre: true post: true activity: if (n <= 1) then ( return false ) else skip ; if (n <= 3) then ( return true ) else skip ; if (n mod 2 = 0 or n mod 3 = 0) then ( return false ) else skip ; var k : int := ("" + ((sqrt(n))))->toInteger() + 1 ; for i : Integer.subrange(5, k-1)->select( $x | ($x - 5) mod 6 = 0 ) do ( if (n mod i = 0 or n mod (i + 2) = 0) then ( return false ) else skip) ; return true; operation isStrongPrime(n : OclAny) : OclAny pre: true post: true activity: if (isPrime(n) = false or n = 2) then ( return false ) else skip ; var previous_prime : double := n - 1 ; var next_prime : OclAny := n + 1 ; while (isPrime(next_prime) = false) do ( next_prime := next_prime + 1) ; while (isPrime(previous_prime) = false) do ( previous_prime := previous_prime - 1) ; var mean : double := (previous_prime + next_prime) / 2 ; if ((n->compareTo(mean)) > 0) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys R=lambda : map(int,next(sys.stdin).split()) t,=R() while t : t-=1 ; n,h=R(); *_,x,y=sorted(R()); x+=y ; print(h//x*2+(h % x>0)+(h % x>y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var R : Function := lambda $$ : OclAny in ((next(OclFile["System.in"]).split())->collect( _x | (OclType["int"])->apply(_x) )) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := R->apply() ; while t do ( t := t - 1; ; var n : OclAny := null; var h : OclAny := null; Sequence{n,h} := R->apply();) ; var _anon : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{_anon,x,y} := R->apply()->sort();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin def A(): t=int(input()) while t : t-=1 n,h=[int(x)for x in stdin.readline().split()] a=[int(x)for x in stdin.readline().split()] a.sort() temp=a[-1]+a[-2] if ha[-1]: print(k*2+2) elif h-k*temp>0 : print(k*2+1) else : print(2*k) def B(): t=int(input()) while t : t-=1 n,x=[int(x)for x in stdin.readline().split()] a=[int(x)for x in stdin.readline().split()] A() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; A(); operation A() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( t := t - 1 ; var n : OclAny := null; var h : OclAny := null; Sequence{n,h} := stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a : Sequence := stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; a := a->sort() ; var temp : OclAny := a->last() + a->front()->last() ; if (h->compareTo(a->last())) < 0 or (h->compareTo(a->front()->last())) < 0 then ( execute (1)->display() ) else ( var k : int := h div temp ; if (h - k * temp->compareTo(a->last())) > 0 then ( execute (k * 2 + 2)->display() ) else (if h - k * temp > 0 then ( execute (k * 2 + 1)->display() ) else ( execute (2 * k)->display() ) ) )); operation B() pre: true post: true activity: t := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( t := t - 1 ; var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; a := stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* n=int(input()) t=[list(map(int,input().split()))for i in range(n*2)] for i in range(0,2*n,2): if t[i][0]==2 and max(t[i+1])>=(t[i][1]% sum(t[i+1])): if t[i][1]% sum(t[i+1])==0 : print(2*(floor((t[i][1]/sum(t[i+1]))))) else : print(2*(floor(t[i][1]/sum(t[i+1])))+1) elif t[i][0]==2 and max(t[i+1])<(t[i][1]% sum(t[i+1])): print(2*(floor(t[i][1]/sum(t[i+1])))+2) else : t2=sorted(t[i+1]) a,b=t2[-1],t2[-2] if max(t[i+1])>=(t[i][1]%(a+b)): if t[i][1]%(a+b)==0 : print(2*(floor(t[i][1]/(a+b)))) else : print(2*(floor(t[i][1]/(a+b)))+1) elif max(t[i+1])<(t[i][1]%(a+b)): print(2*(floor(t[i][1]/(a+b)))+2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : Sequence := Integer.subrange(0, n * 2-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for i : Integer.subrange(0, 2 * n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( if t[i+1]->first() = 2 & ((t[i + 1+1])->max()->compareTo((t[i+1][1+1] mod (t[i + 1+1])->sum()))) >= 0 then ( if t[i+1][1+1] mod (t[i + 1+1])->sum() = 0 then ( execute (2 * (floor((t[i+1][1+1] / (t[i + 1+1])->sum()))))->display() ) else ( execute (2 * (floor(t[i+1][1+1] / (t[i + 1+1])->sum())) + 1)->display() ) ) else (if t[i+1]->first() = 2 & ((t[i + 1+1])->max()->compareTo((t[i+1][1+1] mod (t[i + 1+1])->sum()))) < 0 then ( execute (2 * (floor(t[i+1][1+1] / (t[i + 1+1])->sum())) + 2)->display() ) else ( var t2 : Sequence := t[i + 1+1]->sort() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{t2->last(),t2->front()->last()} ; if ((t[i + 1+1])->max()->compareTo((t[i+1][1+1] mod (a + b)))) >= 0 then ( if t[i+1][1+1] mod (a + b) = 0 then ( execute (2 * (floor(t[i+1][1+1] / (a + b))))->display() ) else ( execute (2 * (floor(t[i+1][1+1] / (a + b))) + 1)->display() ) ) else (if ((t[i + 1+1])->max()->compareTo((t[i+1][1+1] mod (a + b)))) < 0 then ( execute (2 * (floor(t[i+1][1+1] / (a + b))) + 2)->display() ) else skip) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() for i in range(len(n)): if n[i]=="0" : print(n[: i]+n[i+1 :]) quit() print(n[: len(n)-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, (n)->size()-1) do ( if n[i+1] = "0" then ( execute (n.subrange(1,i) + n.subrange(i + 1+1))->display() ; quit() ) else skip) ; execute (n.subrange(1,(n)->size() - 1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=input() d=int(input()) x=list(x) y=[1]*n for i in range(n): if d and x[i]=='0' : y[i]=0 ; x[i]='1' ; d-=1 i=n-1 while d : if y[i]: x[i]='0' ; d-=1 i-=1 print(*x,sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : String := (OclFile["System.in"]).readLine() ; var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; x := (x)->characters() ; var y : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, n) ; for i : Integer.subrange(0, n-1) do ( if d & x[i+1] = '0' then ( y[i+1] := 0; x[i+1] := '1'; d := d - 1 ) else skip) ; var i : double := n - 1 ; while d do ( if y[i+1] then ( x[i+1] := '0'; d := d - 1 ) else skip ; i := i - 1) ; execute ((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- bit=[int(i)for i in input()] n=len(bit) for i in bit : if i==0 : flag=True break else : flag=False if flag : bit.remove(0) for i in bit : print(i,end='') else : bit.remove(bit[0]) for i in bit : print(i,end='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var bit : Sequence := (OclFile["System.in"]).readLine()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var n : int := (bit)->size() ; for i : bit do ( if i = 0 then ( var flag : boolean := true ; break ) else ( flag := false )) ; if flag then ( execute ((0) /: bit) ; for i : bit do ( execute (i)->display()) ) else ( execute ((bit->first()) /: bit) ; for i : bit do ( execute (i)->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getTotalXorOfSubarrayXors(arr,N): res=0 for i in range(0,N): for j in range(i,N): for k in range(i,j+1): res=res ^ arr[k] return res arr=[3,5,2,4,6] N=len(arr) print(getTotalXorOfSubarrayXors(arr,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{3}->union(Sequence{5}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 6 })))) ; N := (arr)->size() ; execute (getTotalXorOfSubarrayXors(arr, N))->display(); operation getTotalXorOfSubarrayXors(arr : OclAny, N : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(i, N-1) do ( for k : Integer.subrange(i, j + 1-1) do ( res := MathLib.bitwiseXor(res, arr[k+1])))) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- bit=input() n=len(bit) for i in range(n): if bit[i]=='0' : bit=bit[0 : i]+bit[i+1 :] break if len(bit)==n : bit=bit[1 :] print(bit) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var bit : String := (OclFile["System.in"]).readLine() ; var n : int := (bit)->size() ; for i : Integer.subrange(0, n-1) do ( if bit[i+1] = '0' then ( bit := bit.subrange(0+1, i) + bit.subrange(i + 1+1) ; break ) else skip) ; if (bit)->size() = n then ( bit := bit->tail() ) else skip ; execute (bit)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(input()) if '0' in s : ind=s.index('0') print(''.join(s[: ind])+''.join(s[ind+1 :])) else : print(''.join(s[:-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if (s)->includes('0') then ( var ind : int := s->indexOf('0') - 1 ; execute (StringLib.sumStringsWithSeparator((s.subrange(1,ind)), '') + StringLib.sumStringsWithSeparator((s.subrange(ind + 1+1)), ''))->display() ) else ( execute (StringLib.sumStringsWithSeparator((s->front()), ''))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() if '0' not in s : print(s[:-1]) else : print(s.replace('0','',1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; if (s)->characters()->excludes('0') then ( execute (s->front())->display() ) else ( execute (s.replace('0', '', 1))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[int(i)for i in list(input())] useless=[1]*10000000 i=0 cl=[] while True : if i>=len(a)-1 : break if a[i]+a[i+1]==9 : c=1 while True : useless.pop(); if i>=len(a)-1 : break if a[i]+a[i+1]==9 : c+=1 else : i+=1 break i+=1 if c % 2==0 : cl.append(1) else : cl.append((c+1)//2) else : i+=1 t=1 for i in cl : t*=i print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := ((OclFile["System.in"]).readLine())->characters()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var useless : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, 10000000) ; var i : int := 0 ; var cl : Sequence := Sequence{} ; while true do ( if (i->compareTo((a)->size() - 1)) >= 0 then ( break ) else skip ; if a[i+1] + a[i + 1+1] = 9 then ( var c : int := 1 ; while true do ( useless := useless->front(); ; if (i->compareTo((a)->size() - 1)) >= 0 then ( break ) else skip ; if a[i+1] + a[i + 1+1] = 9 then ( c := c + 1 ) else ( i := i + 1 ; break ) ; i := i + 1) ; if c mod 2 = 0 then ( execute ((1) : cl) ) else ( execute (((c + 1) div 2) : cl) ) ) else ( i := i + 1 )) ; var t : int := 1 ; for i : cl do ( t := t * i) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() p=1 a=[1 for i in range(len(s))] for i in range(1,len(s)-1): if(int(s[i])+int(s[i-1])==9 and int(s[i])+int(s[i+1])==9): a[i]+=1 x=[] i=0 while(isize()-1)->select(i | true)->collect(i | (1)) ; for i : Integer.subrange(1, (s)->size() - 1-1) do ( if (("" + ((s[i+1])))->toInteger() + ("" + ((s[i - 1+1])))->toInteger() = 9 & ("" + ((s[i+1])))->toInteger() + ("" + ((s[i + 1+1])))->toInteger() = 9) then ( a[i+1] := a[i+1] + 1 ) else skip) ; var x : Sequence := Sequence{} ; var i : int := 0 ; while ((i->compareTo((s)->size())) < 0) do ( var c : int := 0 ; var j : int := i ; while ((j->compareTo((s)->size())) < 0 & a[j+1] = 2) do ( j := j + 1 ; c := c + 1) ; if (c mod 2 = 1) then ( execute (((c div 2) + 2) : x) ) else ( execute ((1) : x) ) ; i := j + 1) ; for i : Integer.subrange(0, (x)->size()-1) do ( p := p * x[i+1]) ; execute (p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=[int(i)for i in input()] k=1 q=1 for i in range(len(s)-1): if(s[i]+s[i+1]==9): q+=1 else : if(q % 2==0 and q!=1): k*=1 elif(q!=1): k*=(q//2+1) q=1 if(q % 2==0 and q!=1): k*=1 elif(q!=1): k*=(q//2+1) print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := (OclFile["System.in"]).readLine()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var k : int := 1 ; var q : int := 1 ; for i : Integer.subrange(0, (s)->size() - 1-1) do ( if (s[i+1] + s[i + 1+1] = 9) then ( q := q + 1 ) else ( if (q mod 2 = 0 & q /= 1) then ( k := k * 1 ) else (if (q /= 1) then ( k := k * (q div 2 + 1) ) else skip) ; q := 1 )) ; if (q mod 2 = 0 & q /= 1) then ( k := k * 1 ) else (if (q /= 1) then ( k := k * (q div 2 + 1) ) else skip) ; execute (k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[int(i)for i in list(input())] i=0 cl=[] while True : if i>=len(a)-1 : break if a[i]+a[i+1]==9 : c=1 while True : if i>=len(a)-1 : break if a[i]+a[i+1]==9 : c+=1 else : i+=1 break i+=1 if c % 2==0 : cl.append(1) else : cl.append((c+1)//2) else : i+=1 t=1 for i in cl : t*=i print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := ((OclFile["System.in"]).readLine())->characters()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var i : int := 0 ; var cl : Sequence := Sequence{} ; while true do ( if (i->compareTo((a)->size() - 1)) >= 0 then ( break ) else skip ; if a[i+1] + a[i + 1+1] = 9 then ( var c : int := 1 ; while true do ( if (i->compareTo((a)->size() - 1)) >= 0 then ( break ) else skip ; if a[i+1] + a[i + 1+1] = 9 then ( c := c + 1 ) else ( i := i + 1 ; break ) ; i := i + 1) ; if c mod 2 = 0 then ( execute ((1) : cl) ) else ( execute (((c + 1) div 2) : cl) ) ) else ( i := i + 1 )) ; var t : int := 1 ; for i : cl do ( t := t * i) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[int(i)for i in list(input())] useless=[1]*10000000 i=0 cl=[] while True : if i>=len(a)-1 : break if a[i]+a[i+1]==9 : c=1 while True : if i>=len(a)-1 : break if a[i]+a[i+1]==9 : c+=1 else : i+=1 break i+=1 if c % 2==0 : cl.append(1) else : cl.append((c+1)//2) else : i+=1 useless.pop(); t=1 for i in cl : t*=i print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := ((OclFile["System.in"]).readLine())->characters()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var useless : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, 10000000) ; var i : int := 0 ; var cl : Sequence := Sequence{} ; while true do ( if (i->compareTo((a)->size() - 1)) >= 0 then ( break ) else skip ; if a[i+1] + a[i + 1+1] = 9 then ( var c : int := 1 ; while true do ( if (i->compareTo((a)->size() - 1)) >= 0 then ( break ) else skip ; if a[i+1] + a[i + 1+1] = 9 then ( c := c + 1 ) else ( i := i + 1 ; break ) ; i := i + 1) ; if c mod 2 = 0 then ( execute ((1) : cl) ) else ( execute (((c + 1) div 2) : cl) ) ) else ( i := i + 1 ) ; useless := useless->front();) ; var t : int := 1 ; for i : cl do ( t := t * i) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) bits_raw=input() bits=[int(bits_raw[i])for i in range(n)] m=int(input()) ones=[] zeros=[] for i in range(n): if(bits[i]==1): ones.append(i) else : zeros.append(i) if(len(zeros)>m): for i in range(m): bits[zeros[i]]=1 print(''.join(map(str,bits))) else : allone=[1 for i in range(n)] l=len(ones) for i in range(m-len(zeros)): allone[ones[l-i-1]]=0 print(''.join(map(str,allone))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var bits_raw : String := (OclFile["System.in"]).readLine() ; var bits : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + ((bits_raw[i+1])))->toInteger())) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ones : Sequence := Sequence{} ; var zeros : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if (bits[i+1] = 1) then ( execute ((i) : ones) ) else ( execute ((i) : zeros) )) ; if (((zeros)->size()->compareTo(m)) > 0) then ( for i : Integer.subrange(0, m-1) do ( bits[zeros[i+1]+1] := 1) ; execute (StringLib.sumStringsWithSeparator(((bits)->collect( _x | (OclType["String"])->apply(_x) )), ''))->display() ) else ( var allone : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (1)) ; var l : int := (ones)->size() ; for i : Integer.subrange(0, m - (zeros)->size()-1) do ( allone[ones[l - i - 1+1]+1] := 0) ; execute (StringLib.sumStringsWithSeparator(((allone)->collect( _x | (OclType["String"])->apply(_x) )), ''))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): ans=sum((15*16**(n-1)-43*15**(n-1)+41*14**(n-1)-13**n)for n in range(1,17)) return f"{ans:X}" if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (expr (expr (atom (number (integer 15)))) * (expr (expr (atom (number (integer 16)))) ** (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1))))))))) ))))) - (expr (expr (atom (number (integer 43)))) * (expr (expr (atom (number (integer 15)))) ** (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1))))))))) )))))) + (expr (expr (atom (number (integer 41)))) * (expr (expr (atom (number (integer 14)))) ** (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1))))))))) )))))) - (expr (expr (atom (number (integer 13)))) ** (expr (atom (name n))))))))) )))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 17))))))))) )))))))))->sum() ; return StringLib.formattedString("{ans:X}"); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import lru_cache t=[[0]*4 for i in range(4)] for i in range(1,4): j=1 for v in map(int,input().split()): t[i][j]=v j+=1 n=int(input()) @ lru_cache(None) def f(l,r,nums): mid=6-l-r if nums==0 : return 0 if l==r : return 0 ans1=f(l,mid,nums-1)+f(mid,r,nums-1)+t[l][r] ans2=f(l,r,nums-1)*2+f(r,l,nums-1)+t[l][mid]+t[mid][r] return min(ans1,ans2) print(f(1,3,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : Sequence := Integer.subrange(0, 4-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, 4))) ; for i : Integer.subrange(1, 4-1) do ( var j : int := 1 ; for v : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( t[i+1][j+1] := v ; j := j + 1)) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (compound_stmt (decorator @ (dotted_name (name lru_cache)) ( (arglist (argument (test (logical_test (comparison (expr (atom None))))))) )) (funcdef def (name f) ( (typedargslist (def_parameters (def_parameter (named_parameter (name l))) , (def_parameter (named_parameter (name r))) , (def_parameter (named_parameter (name nums))))) ) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name mid)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (number (integer 6)))) - (expr (atom (name l)))) - (expr (atom (name r))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name nums)))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name l)))) == (comparison (expr (atom (name r))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans1)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (name f)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l))))))) , (argument (test (logical_test (comparison (expr (atom (name mid))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name nums))) - (expr (atom (number (integer 1)))))))))) )))) + (expr (atom (name f)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name mid))))))) , (argument (test (logical_test (comparison (expr (atom (name r))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name nums))) - (expr (atom (number (integer 1)))))))))) ))))) + (expr (atom (name t)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name l)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ]))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans2)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (expr (expr (atom (name f)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l))))))) , (argument (test (logical_test (comparison (expr (atom (name r))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name nums))) - (expr (atom (number (integer 1)))))))))) )))) * (expr (atom (number (integer 2))))) + (expr (atom (name f)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name r))))))) , (argument (test (logical_test (comparison (expr (atom (name l))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name nums))) - (expr (atom (number (integer 1)))))))))) ))))) + (expr (atom (name t)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name l)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name mid)))))))) ])))) + (expr (atom (name t)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name mid)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ]))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans1))))))) , (argument (test (logical_test (comparison (expr (atom (name ans2)))))))) )))))))))))))) ; execute (f(1, 3, n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left,bisect_right,insort_left dict={} keytbl=[] cnt=0 q=int(input()) for i in range(q): a=list(input().split()) ki=int(a[1]) if a[0]=='0' : if ki not in dict : dict[ki]=1 insort_left(keytbl,ki) else : dict[ki]+=1 cnt+=1 print(cnt) elif a[0]=='1' : print(dict[ki]if ki in dict else 0) elif a[0]=='2' : if ki in dict : cnt-=dict[ki] dict[ki]=0 else : L=bisect_left(keytbl,int(a[1])) R=bisect_right(keytbl,int(a[2]),L) for j in range(L,R): for k in range(dict[keytbl[j]]): print(keytbl[j]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var OclType["Map"] : OclAny := Set{} ; var keytbl : Sequence := Sequence{} ; var cnt : int := 0 ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( var a : Sequence := (input().split()) ; var ki : int := ("" + ((a[1+1])))->toInteger() ; if a->first() = '0' then ( if (OclType["Map"])->excludes(ki) then ( (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ki)))))))) ]) := 1 ; insort_left(keytbl, ki) ) else ( (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ki)))))))) ]) := (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ki)))))))) ]) + 1 ) ; cnt := cnt + 1 ; execute (cnt)->display() ) else (if a->first() = '1' then ( execute (if (OclType["Map"])->includes(ki) then (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ki)))))))) ]) else 0 endif)->display() ) else (if a->first() = '2' then ( if (OclType["Map"])->includes(ki) then ( cnt := cnt - (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ki)))))))) ]) ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ki)))))))) ]) := 0 ) else skip ) else ( var L : OclAny := bisect_left(keytbl, ("" + ((a[1+1])))->toInteger()) ; var R : OclAny := bisect_right(keytbl, ("" + ((a[2+1])))->toInteger(), L) ; for j : Integer.subrange(L, R-1) do ( for k : Integer.subrange(0, (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name keytbl)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) ])-1) do ( execute (keytbl[j+1])->display())) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys inf=float("inf") mod=1000000007 def get_array(): return list(map(int,sys.stdin.readline().split())) def get_ints(): return map(int,sys.stdin.readline().split()) def input(): return sys.stdin.readline() def main(): dp=[[[0 for _ in range(3)]for _ in range(3)]for _ in range(43)] matrix=[[0 for _ in range(3)]for _ in range(3)] for i in range(3): matrix[i]=get_array() n=int(input()) for i in range(1,n+1): for frm in range(3): for to in range(3): other=3-frm-to if frm==to : continue dp[i][frm][to]=dp[i-1][frm][other]+matrix[frm][to]+dp[i-1][other][to] c=dp[i-1][frm][to]+matrix[frm][other]+dp[i-1][to][frm]+matrix[other][to]+dp[i-1][frm][to] dp[i][frm][to]=min(c,dp[i][frm][to]) print(dp[n][0][2]) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var Math_PINFINITY : double := ("" + (("inf")))->toReal() ; var mod : int := 1000000007 ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation get_array() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation get_ints() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation input() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation main() pre: true post: true activity: var dp : Sequence := Integer.subrange(0, 43-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (0)))))) ; var matrix : Sequence := Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (0)))) ; for i : Integer.subrange(0, 3-1) do ( matrix[i+1] := get_array()) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(1, n + 1-1) do ( for frm : Integer.subrange(0, 3-1) do ( for to : Integer.subrange(0, 3-1) do ( var other : double := 3 - frm - to ; if frm = to then ( continue ) else skip ; dp[i+1][frm+1][to+1] := dp[i - 1+1][frm+1][other+1] + matrix[frm+1][to+1] + dp[i - 1+1][other+1][to+1] ; var c : OclAny := dp[i - 1+1][frm+1][to+1] + matrix[frm+1][other+1] + dp[i - 1+1][to+1][frm+1] + matrix[other+1][to+1] + dp[i - 1+1][frm+1][to+1] ; dp[i+1][frm+1][to+1] := Set{c, dp[i+1][frm+1][to+1]}->min()))) ; execute (dp[n+1]->first()[2+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def play(price,n): dp=[[[0 for k in range(0,4)]for j in range(0,4)]for i in range(0,n+1)] for i in range(1,n+1): for j in range(1,4): for k in range(1,4): dp[i][j][k]=min(dp[i-1][j][k ^ j]+price[j][k]+dp[i-1][k ^ j][k],2*dp[i-1][j][k]+price[j][k ^ j]+dp[i-1][k][j]+price[j ^ k][k]) return dp[n][1][3] def main(): matrix=[[0 for j in range(0,4)]for i in range(0,4)] i=1 while i<4 : row=list(map(int,input().split())) for j in range(1,4): matrix[i][j]=row[j-1] i+=1 n=int(input()) print(play(matrix,n)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation play(price : OclAny, n : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, 4-1)->select(j | true)->collect(j | (Integer.subrange(0, 4-1)->select(k | true)->collect(k | (0)))))) ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, 4-1) do ( for k : Integer.subrange(1, 4-1) do ( dp[i+1][j+1][k+1] := Set{dp[i - 1+1][j+1][MathLib.bitwiseXor(k, j)+1] + price[j+1][k+1] + dp[i - 1+1][MathLib.bitwiseXor(k, j)+1][k+1], 2 * dp[i - 1+1][j+1][k+1] + price[j+1][MathLib.bitwiseXor(k, j)+1] + dp[i - 1+1][k+1][j+1] + price[MathLib.bitwiseXor(j, k)+1][k+1]}->min()))) ; return dp[n+1][1+1][3+1]; operation main() pre: true post: true activity: var matrix : Sequence := Integer.subrange(0, 4-1)->select(i | true)->collect(i | (Integer.subrange(0, 4-1)->select(j | true)->collect(j | (0)))) ; var i : int := 1 ; while i < 4 do ( var row : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(1, 4-1) do ( matrix[i+1][j+1] := row[j - 1+1]) ; i := i + 1) ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (play(matrix, n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tt=[[660,899],[1080,1259],[1260,1559]] ss=["lunch","dinner","midnight"] while True : n=int(input()) if n==0 : break cnt,ok=[0]*3,[0]*3 for i in range(n): hm,MM=input().split() hh,mm=map(int,hm.split(':')) MM=int(MM) if hh<=2 : hh+=24 MM=MM+hh*60 if MM>=mm else MM+(hh+1)*60 t=hh*60+mm for j in range(3): if tt[j][0]<=t and t<=tt[j][1]: cnt[j]+=1 if MM-t<=8 : ok[j]+=1 for j in range(3): print(ss[j]+'',end='') print("no guest" if cnt[j]==0 else ok[j]*100//cnt[j]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var tt : Sequence := Sequence{Sequence{660}->union(Sequence{ 899 })}->union(Sequence{Sequence{1080}->union(Sequence{ 1259 })}->union(Sequence{ Sequence{1260}->union(Sequence{ 1559 }) })) ; var ss : Sequence := Sequence{"lunch"}->union(Sequence{"dinner"}->union(Sequence{ "midnight" })) ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var cnt : OclAny := null; var ok : OclAny := null; Sequence{cnt,ok} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, 3),MatrixLib.elementwiseMult(Sequence{ 0 }, 3)} ; for i : Integer.subrange(0, n-1) do ( var hm : OclAny := null; var MM : OclAny := null; Sequence{hm,MM} := input().split() ; var hh : OclAny := null; var mm : OclAny := null; Sequence{hh,mm} := (hm.split(':'))->collect( _x | (OclType["int"])->apply(_x) ) ; var MM : int := ("" + ((MM)))->toInteger() ; if hh <= 2 then ( hh := hh + 24 ) else skip ; MM := if (MM->compareTo(mm)) >= 0 then MM + hh * 60 else MM + (hh + 1) * 60 endif ; var t : double := hh * 60 + mm ; for j : Integer.subrange(0, 3-1) do ( if (tt[j+1]->first()->compareTo(t)) <= 0 & (t->compareTo(tt[j+1][1+1])) <= 0 then ( cnt[j+1] := cnt[j+1] + 1 ; if MM - t <= 8 then ( ok[j+1] := ok[j+1] + 1 ) else skip ) else skip)) ; for j : Integer.subrange(0, 3-1) do ( execute (ss[j+1] + '')->display() ; execute (if cnt[j+1] = 0 then "no guest" else ok[j+1] * 100 div cnt[j+1] endif)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if n==0 : break l=d=mi=cl=cm=cd=0 for i in range(n): t,M=input().split() M=int(M) h,m=map(int,t.split(":")) if m>M : M+=60 a=M-m<=8 if 11<=h<15 : cl+=1 ; l+=a elif 18<=h<21 : cd+=1 ; d+=a elif 21<=h or h<2 : cm+=1 ; mi+=a print('lunch',l*100//cl if cl else 'no guest') print('dinner',d*100//cd if cd else 'no guest') print('midnight',mi*100//cm if cm else 'no guest') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; l := l(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name mi)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cl)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cm)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cd)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for i : Integer.subrange(0, n-1) do ( var t : OclAny := null; var M : OclAny := null; Sequence{t,M} := input().split() ; var M : int := ("" + ((M)))->toInteger() ; var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := (t.split(":"))->collect( _x | (OclType["int"])->apply(_x) ) ; if (m->compareTo(M)) > 0 then ( M := M + 60 ) else skip ; var a : boolean := M - m <= 8 ; if 11 <= h & (h < 15) then ( cl := cl + 1; l := l + a ) else (if 18 <= h & (h < 21) then ( cd := cd + 1; d := d + a ) else (if 21 <= h or h < 2 then ( cm := cm + 1; mi := mi + a ) else skip ) ) ) ; execute ('lunch')->display() ; execute ('dinner')->display() ; execute ('midnight')->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : N=int(input()) if N==0 : break a=b=c=0 a0=b0=c0=0 for i in range(N): s0,s1=input().split() h,m=map(int,s0.split(":")) tm=100*h+m m1=int(s1) if m1toInteger() ; if N = 0 then ( break ) else skip ; a := a(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; a0 := a0(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b0)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c0)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for i : Integer.subrange(0, N-1) do ( var s0 : OclAny := null; var s1 : OclAny := null; Sequence{s0,s1} := input().split() ; var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := (s0.split(":"))->collect( _x | (OclType["int"])->apply(_x) ) ; var tm : double := 100 * h + m ; var m1 : int := ("" + ((s1)))->toInteger() ; if (m1->compareTo(m)) < 0 then ( m1 := m1 + 60 ) else skip ; if 1100 <= tm & (tm < 1500) then ( if m1 - m <= 8 then ( a := a + 1 ) else skip ; a0 := a0 + 1 ) else (if 1800 <= tm & (tm < 2100) then ( if m1 - m <= 8 then ( b := b + 1 ) else skip ; b0 := b0 + 1 ) else (if 2100 <= tm or tm < 200 then ( if m1 - m <= 8 then ( c := c + 1 ) else skip ; c0 := c0 + 1 ) else skip ) ) ) ; execute ("lunch")->display() ; execute ("dinner")->display() ; execute ("midnight")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math while True : n=int(input()) if n==0 : break name=("lunch","dinner","midnight") dic={} clear={} for s in name : dic[s]=0 clear[s]=0 for _ in range(n): start,time=input().split() flag=(int(time)-int(start[3 :]))% 60<=8 if "11:00"<=start<="14:59" : dic["lunch"]+=1 if flag : clear["lunch"]+=1 elif "18:00"<=start<="20:59" : dic["dinner"]+=1 if flag : clear["dinner"]+=1 elif "21:00"<=start<="23:59" or "00:00"<=start<="01:59" : dic["midnight"]+=1 if flag : clear["midnight"]+=1 for key in("lunch","dinner","midnight"): if dic[key]: print(key,math.floor(100*clear[key]/dic[key])) else : print(key,"no guest") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var name : OclAny := Sequence{"lunch", "dinner", "midnight"} ; var dic : OclAny := Set{} ; var clear : OclAny := Set{} ; for s : name do ( dic[s+1] := 0 ; clear[s+1] := 0) ; for _anon : Integer.subrange(0, n-1) do ( var start : OclAny := null; var time : OclAny := null; Sequence{start,time} := input().split() ; var flag : boolean := (("" + ((time)))->toInteger() - ("" + ((start.subrange(3+1))))->toInteger()) mod 60 <= 8 ; if "11:00" <= start & (start <= "14:59") then ( dic->at("lunch") := dic->at("lunch") + 1 ; if flag then ( clear->at("lunch") := clear->at("lunch") + 1 ) else skip ) else (if "18:00" <= start & (start <= "20:59") then ( dic->at("dinner") := dic->at("dinner") + 1 ; if flag then ( clear->at("dinner") := clear->at("dinner") + 1 ) else skip ) else (if if "21:00" <= start & (start <= "23:59") /= "" then "21:00" <= start & (start <= "23:59") else "00:00" <= start & (start <= "01:59") endif then ( dic->at("midnight") := dic->at("midnight") + 1 ; if flag then ( clear->at("midnight") := clear->at("midnight") + 1 ) else skip ) else skip ) ) ) ; for key : Sequence{"lunch", "dinner", "midnight"} do ( if dic[key+1] then ( execute (key)->display() ) else ( execute (key)->display() ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w=map(int,input().split()) s=[[0]*(w+2)]+[[0]+[(i=="#")*1 for i in list(input())]+[0]for _ in range(h)]+[[0]*(w+2)] ans=[[0]*w for _ in range(h)] for i in range(h): for j in range(w): if s[i+1][j+1]==1 : ans[i][j]="#" continue ans[i][j]=str(s[i][j+1]+s[i+1][j]+s[i+1][j+2]+s[i+2][j+1]+s[i][j]+s[i+2][j+2]+s[i+2][j]+s[i][j+2]) for l in ans : print("".join(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := Sequence{ MatrixLib.elementwiseMult(Sequence{ 0 }, (w + 2)) }->union(Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (Sequence{ 0 }->union(((OclFile["System.in"]).readLine())->characters()->select(i | true)->collect(i | ((i = "#") * 1)))->union(Sequence{ 0 }))))->union(Sequence{ MatrixLib.elementwiseMult(Sequence{ 0 }, (w + 2)) }) ; var ans : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, w))) ; for i : Integer.subrange(0, h-1) do ( for j : Integer.subrange(0, w-1) do ( if s[i + 1+1][j + 1+1] = 1 then ( ans[i+1][j+1] := "#" ; continue ) else skip ; ans[i+1][j+1] := ("" + ((s[i+1][j + 1+1] + s[i + 1+1][j+1] + s[i + 1+1][j + 2+1] + s[i + 2+1][j + 1+1] + s[i+1][j+1] + s[i + 2+1][j + 2+1] + s[i + 2+1][j+1] + s[i+1][j + 2+1]))))) ; for l : ans do ( execute (StringLib.sumStringsWithSeparator((l), ""))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=input() d=int(input()) swap={} for i in range(n): if d==0 : break if x[i]=="0" : swap[i]=True d-=1 for i in range(n-1,-1,-1): if d==0 : break if x[i]=="1" : swap[i]=True d-=1 print("".join([x[i]if i not in swap else("0" if x[i]=="1" else "1")for i in range(n)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : String := (OclFile["System.in"]).readLine() ; var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var swap : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( if d = 0 then ( break ) else skip ; if x[i+1] = "0" then ( swap[i+1] := true ; d := d - 1 ) else skip) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if d = 0 then ( break ) else skip ; if x[i+1] = "1" then ( swap[i+1] := true ; d := d - 1 ) else skip) ; execute (StringLib.sumStringsWithSeparator((Integer.subrange(0, n-1)->select(i | true)->collect(i | (if (swap)->excludes(i) then x[i+1] else (if x[i+1] = "1" then "0" else "1" endif) endif))), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy as cp H,W=map(int,input().split(" ")) L=[list(input())for i in range(H)] a=["#" for i in range(W)] A=[cp.copy(a)for i in range(H)] for i in range(H): for j in range(W): if L[i][j]=="#" : continue cnt=0 for ii in range(-1,2): for jj in range(-1,2): if ii==0 and jj==0 : continue iii=i+ii jjj=j+jj if iii<0 or iii>H-1 : continue if jjj<0 or jjj>W-1 : continue if L[iii][jjj]=="#" : cnt+=1 A[i][j]=str(cnt) for i in range(len(A)): print(''.join(A[i])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var L : Sequence := Integer.subrange(0, H-1)->select(i | true)->collect(i | (((OclFile["System.in"]).readLine())->characters())) ; var a : Sequence := Integer.subrange(0, W-1)->select(i | true)->collect(i | ("#")) ; var A : Sequence := Integer.subrange(0, H-1)->select(i | true)->collect(i | (cp->copy())) ; for i : Integer.subrange(0, H-1) do ( for j : Integer.subrange(0, W-1) do ( if L[i+1][j+1] = "#" then ( continue ) else skip ; var cnt : int := 0 ; for ii : Integer.subrange(-1, 2-1) do ( for jj : Integer.subrange(-1, 2-1) do ( if ii = 0 & jj = 0 then ( continue ) else skip ; var iii : OclAny := i + ii ; var jjj : OclAny := j + jj ; if iii < 0 or (iii->compareTo(H - 1)) > 0 then ( continue ) else skip ; if jjj < 0 or (jjj->compareTo(W - 1)) > 0 then ( continue ) else skip ; if L[iii+1][jjj+1] = "#" then ( cnt := cnt + 1 ) else skip)) ; A[i+1][j+1] := ("" + ((cnt))))) ; for i : Integer.subrange(0, (A)->size()-1) do ( execute (StringLib.sumStringsWithSeparator((A[i+1]), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getInt(): return int(input()) def getIntList(): return[int(x)for x in input().split()] def zeros(n): return[0 for i in range(n)] def db(x): global debug if debug : print(x) debug=False H,W=getIntList() S=zeros(H+2) S[0]='.'*(W+2) for i in range(H): S[i+1]='.'+input()+'.' S[H+1]='.'*(W+2) db(S) for i in range(1,H+1): for j in range(1,W+1): if S[i][j]=='#' : continue c=0 for k in range(3): if S[i-1][j+k-1]=='#' : c+=1 if S[i][j-1]=='#' : c+=1 if S[i][j+1]=='#' : c+=1 for k in range(3): if S[i+1][j+k-1]=='#' : c+=1 S[i]=S[i][: j]+str(c)+S[i][j+1 :] db(S[i]) db(S) for i in range(H): print(S[i+1][1 : W+1]) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute debug : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; debug := false ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := getIntList() ; var S : OclAny := zeros(H + 2) ; S->first() := StringLib.nCopies('.', (W + 2)) ; for i : Integer.subrange(0, H-1) do ( S[i + 1+1] := '.' + (OclFile["System.in"]).readLine() + '.') ; S[H + 1+1] := StringLib.nCopies('.', (W + 2)) ; db(S) ; for i : Integer.subrange(1, H + 1-1) do ( for j : Integer.subrange(1, W + 1-1) do ( if S[i+1][j+1] = '#' then ( continue ) else skip ; var c : int := 0 ; for k : Integer.subrange(0, 3-1) do ( if S[i - 1+1][j + k - 1+1] = '#' then ( c := c + 1 ) else skip) ; if S[i+1][j - 1+1] = '#' then ( c := c + 1 ) else skip ; if S[i+1][j + 1+1] = '#' then ( c := c + 1 ) else skip ; for k : Integer.subrange(0, 3-1) do ( if S[i + 1+1][j + k - 1+1] = '#' then ( c := c + 1 ) else skip) ; S[i+1] := S[i+1].subrange(1,j) + ("" + ((c))) + S[i+1].subrange(j + 1+1)) ; db(S[i+1])) ; db(S) ; for i : Integer.subrange(0, H-1) do ( execute (S[i + 1+1].subrange(1+1, W + 1))->display()); operation getInt() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation getIntList() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation zeros(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)); operation db(x : OclAny) pre: true post: true activity: skip ; if debug then ( execute (x)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin ni=lambda : int(ns()) na=lambda : list(map(int,stdin.readline().split())) ns=lambda : stdin.readline() n,m=na() mp=[] for i in range(n): mp.append([_ for _ in ns().strip()]) for i in range(n): for j in range(m): if mp[i][j]!='#' : bo=0 for k in range(-1,2): for l in range(-1,2): ni=i+k nj=j+l if 0<=nitoInteger()) ; var na : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ns : Function := lambda $$ : OclAny in (stdin.readLine()) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := na->apply() ; var mp : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((ns->apply()->trim()->select(_anon | true)->collect(_anon | (_anon))) : mp)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if mp[i+1][j+1] /= '#' then ( var bo : int := 0 ; for k : Integer.subrange(-1, 2-1) do ( for l : Integer.subrange(-1, 2-1) do ( ni := i + k ; var nj : OclAny := j + l ; if 0 <= ni & (ni < n) & 0 <= nj & (nj < m) & mp[ni+1][nj+1] = '#' then ( bo := bo + 1 ) else skip)) ; mp[i+1][j+1] := (bo + 48)->byte2char() ) else skip)) ; for i : mp do ( execute (StringLib.sumStringsWithSeparator((i), ""))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect S=[] def insert(S,count,x): y=bisect.bisect(S,x) S.insert(y,x) count+=1 print(count) return S,count def find(S,x): y0=bisect.bisect_left(S,x) y1=bisect.bisect_right(S,x) return y0,y1 def erase(S,count,x): y0,y1=find(S,x) if y1-y0>0 : del S[y0 : y1] count-=y1-y0 return S,count def dump(S,L,R): s=bisect.bisect_left(S,L) e=bisect.bisect_right(S,R) if e-s>0 : print('\n'.join(map(str,S[s : e]))) q=int(input()) count=0 for i in range(q): query=list(map(int,input().split())) if query[0]==0 : S,count=insert(S,count,query[1]) elif query[0]==1 : y0,y1=find(S,query[1]) print(y1-y0) elif query[0]==2 : S,count=erase(S,count,query[1]) else : dump(S,query[1],query[2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var S : Sequence := Sequence{} ; skip ; skip ; skip ; skip ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; count := 0 ; for i : Integer.subrange(0, q-1) do ( var query : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if query->first() = 0 then ( Sequence{S,count} := insert(S, count, query[1+1]) ) else (if query->first() = 1 then ( Sequence{y0,y1} := find(S, query[1+1]) ; execute (y1 - y0)->display() ) else (if query->first() = 2 then ( Sequence{S,count} := erase(S, count, query[1+1]) ) else ( dump(S, query[1+1], query[2+1]) ) ) ) ); operation insert(S : OclAny, count : OclAny, x : OclAny) : OclAny pre: true post: true activity: var y : OclAny := bisect.bisect(S, x) ; S := S.insertAt(y+1, x) ; count := count + 1 ; execute (count)->display() ; return S, count; operation find(S : OclAny, x : OclAny) : OclAny pre: true post: true activity: var y0 : OclAny := bisect.bisect_left(S, x) ; var y1 : OclAny := bisect.bisect_right(S, x) ; return y0, y1; operation erase(S : OclAny, count : OclAny, x : OclAny) : OclAny pre: true post: true activity: Sequence{y0,y1} := find(S, x) ; if y1 - y0 > 0 then ( execute (S.subrange(y0+1, y1))->isDeleted() ; count := count - y1 - y0 ) else skip ; return S, count; operation dump(S : OclAny, L : OclAny, R : OclAny) pre: true post: true activity: var s : OclAny := bisect.bisect_left(S, L) ; var e : OclAny := bisect.bisect_right(S, R) ; if e - s > 0 then ( execute (StringLib.sumStringsWithSeparator(((S.subrange(s+1, e))->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findbomb(x,y,H,W): bombnum=0 if x!=0 : bombnum+=(table[x-1][y]=="#") if y!=0 : bombnum+=(table[x-1][y-1]=="#") if y!=W-1 : bombnum+=(table[x-1][y+1]=="#") if y!=0 : bombnum+=(table[x][y-1]=="#") if y!=W-1 : bombnum+=(table[x][y+1]=="#") if x!=H-1 : bombnum+=(table[x+1][y]=="#") if y!=0 : bombnum+=(table[x+1][y-1]=="#") if y!=W-1 : bombnum+=(table[x+1][y+1]=="#") return(bombnum) H,W=map(int,input().split()) table=[] for i in range(H): table.append(list(input())) result=[[0]*W for hoge in range(H)] for x,row in enumerate(table): for y,b in enumerate(row): if b=="#" : result[x][y]="#" else : result[x][y]=findbomb(x,y,H,W) for t in result : print(*t,sep="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var table : Sequence := Sequence{} ; for i : Integer.subrange(0, H-1) do ( execute ((((OclFile["System.in"]).readLine())->characters()) : table)) ; var result : Sequence := Integer.subrange(0, H-1)->select(hoge | true)->collect(hoge | (MatrixLib.elementwiseMult(Sequence{ 0 }, W))) ; for _tuple : Integer.subrange(1, (table)->size())->collect( _indx | Sequence{_indx-1, (table)->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var row : OclAny := _tuple->at(_indx); for _tuple : Integer.subrange(1, (row)->size())->collect( _indx | Sequence{_indx-1, (row)->at(_indx)} ) do (var _indx : int := 1; var y : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if b = "#" then ( result[x+1][y+1] := "#" ) else ( result[x+1][y+1] := findbomb(x, y, H, W) ))) ; for t : result do ( execute ((argument * (test (logical_test (comparison (expr (atom (name t))))))))->display()); operation findbomb(x : OclAny, y : OclAny, H : OclAny, W : OclAny) : OclAny pre: true post: true activity: var bombnum : int := 0 ; if x /= 0 then ( bombnum := bombnum + (table[x - 1+1][y+1] = "#") ; if y /= 0 then ( bombnum := bombnum + (table[x - 1+1][y - 1+1] = "#") ) else skip ; if y /= W - 1 then ( bombnum := bombnum + (table[x - 1+1][y + 1+1] = "#") ) else skip ) else skip ; if y /= 0 then ( bombnum := bombnum + (table[x+1][y - 1+1] = "#") ) else skip ; if y /= W - 1 then ( bombnum := bombnum + (table[x+1][y + 1+1] = "#") ) else skip ; if x /= H - 1 then ( bombnum := bombnum + (table[x + 1+1][y+1] = "#") ; if y /= 0 then ( bombnum := bombnum + (table[x + 1+1][y - 1+1] = "#") ) else skip ; if y /= W - 1 then ( bombnum := bombnum + (table[x + 1+1][y + 1+1] = "#") ) else skip ) else skip ; return (bombnum); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import deque if __name__=="__main__" : r=int(sys.stdin.readline()) s=[0]*r sw=list(map(int,sys.stdin.readline().split())) ps=sys.stdin.readline().strip() ll=len(ps) d={} for z in range(r): d[sw[z]]=z sw.sort() it=sw et=deque() swc=0 for p in range(ll): if ps[p]=='0' : seat=it[swc] ri=d[it[swc]] print(ri+1,end=' ') et.append(seat) swc+=1 else : print(d[et[-1]]+1,end=' ') et.pop() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var r : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, r) ; var sw : Sequence := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ps : OclAny := sys.stdin.readLine()->trim() ; var ll : int := (ps)->size() ; var d : OclAny := Set{} ; for z : Integer.subrange(0, r-1) do ( d[sw[z+1]+1] := z) ; sw := sw->sort() ; var it : Sequence := sw ; var et : Sequence := () ; var swc : int := 0 ; for p : Integer.subrange(0, ll-1) do ( if ps[p+1] = '0' then ( var seat : OclAny := it[swc+1] ; var ri : OclAny := d[it[swc+1]+1] ; execute (ri + 1)->display() ; execute ((seat) : et) ; swc := swc + 1 ) else ( execute (d[et->last()+1] + 1)->display() ; et := et->front() )) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) li=list(map(int,input().split())) s=input() l2=[] for i in range(n): l2.append((li[i],i)) l2.sort() l3=[] j=0 for i in s : if i=='0' : print(int(l2[j][1])+1,end=" ") l3.append(l2[j][1]) j+=1 else : x=int(l3.pop()) print(x+1,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : String := (OclFile["System.in"]).readLine() ; var l2 : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((Sequence{li[i+1], i}) : l2)) ; l2 := l2->sort() ; var l3 : Sequence := Sequence{} ; var j : int := 0 ; for i : s->characters() do ( if i = '0' then ( execute (("" + ((l2[j+1][1+1])))->toInteger() + 1)->display() ; execute ((l2[j+1][1+1]) : l3) ; j := j + 1 ) else ( var x : int := ("" + ((l3->last())))->toInteger() ; execute (x + 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) li=list(map(int,input().split())) s=input() l2=[] for i in range(n): l2.append((li[i],i)) l2.sort() l3=[] j=0 for i in s : if i=='0' : print(int(l2[j][1])+1,end=" ") l3.append(l2[j][1]) j+=1 else : x=int(l3.pop()) print(x+1,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : String := (OclFile["System.in"]).readLine() ; var l2 : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((Sequence{li[i+1], i}) : l2)) ; l2 := l2->sort() ; var l3 : Sequence := Sequence{} ; var j : int := 0 ; for i : s->characters() do ( if i = '0' then ( execute (("" + ((l2[j+1][1+1])))->toInteger() + 1)->display() ; execute ((l2[j+1][1+1]) : l3) ; j := j + 1 ) else ( var x : int := ("" + ((l3->last())))->toInteger() ; execute (x + 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) one=[] two=[] c=1 for i in input().split(): two.append((int(i),c)) c=c+1 two.sort(key=lambda x :-x[0]) for j in input(): if j=="0" : p=two.pop() print(p[1],end=" ") one.append(p) else : print(one.pop()[1],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var one : Sequence := Sequence{} ; var two : Sequence := Sequence{} ; var c : int := 1 ; for i : input().split() do ( execute ((Sequence{("" + ((i)))->toInteger(), c}) : two) ; c := c + 1) ; two := two->sort() ; for j : (OclFile["System.in"]).readLine() do ( if j = "0" then ( var p : OclAny := two->last() ; two := two->front() ; execute (p[1+1])->display() ; execute ((p) : one) ) else ( execute (one->last()[1+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) one=[] two=[] c=1 for i in input().split(): two.append((int(i),c)) c=c+1 two.sort(key=lambda x :-x[0]) for j in input(): if j=="0" : p=two.pop() print(p[1],end=" ") one.append(p) else : print(one.pop()[1],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var one : Sequence := Sequence{} ; var two : Sequence := Sequence{} ; var c : int := 1 ; for i : input().split() do ( execute ((Sequence{("" + ((i)))->toInteger(), c}) : two) ; c := c + 1) ; two := two->sort() ; for j : (OclFile["System.in"]).readLine() do ( if j = "0" then ( var p : OclAny := two->last() ; two := two->front() ; execute (p[1+1])->display() ; execute ((p) : one) ) else ( execute (one->last()[1+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(n): m=n while(n!=0): r=n % 10 if(r>0): if((m % r)!=0): return False n=n//10 return True def count(l,r): ans=0 for i in range(l,r+1): if(check(i)): ans=ans+1 return ans l=10 r=20 print(count(l,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; l := 10 ; r := 20 ; execute (count(l, r))->display(); operation check(n : OclAny) : OclAny pre: true post: true activity: var m : OclAny := n ; while (n /= 0) do ( var r : int := n mod 10 ; if (r > 0) then ( if ((m mod r) /= 0) then ( return false ) else skip ) else skip ; n := n div 10) ; return true; operation count(l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(l, r + 1-1) do ( if (check(i)) then ( ans := ans + 1 ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline r,c=map(int,input().split()) s=[] ans="Yes" for i in range(r): s0=list(input().rstrip()) for j in range(c-1): if s0[j]=="S" and s0[j+1]=="W" : ans="No" elif s0[j]=="W" and s0[j+1]=="S" : ans="No" for j in range(c): if s0[j]=="." : s0[j]="D" s.append(s0) for i in range(r-1): if ans=="No" : break s0,s1=s[i],s[i+1] for j in range(c): if s0[j]=="S" and s1[j]=="W" : ans="No" elif s0[j]=="W" and s1[j]=="S" : ans="No" print(ans) if ans=="Yes" : ans=[] for s0 in s : ans.append("".join(s0)) sys.stdout.write("\n".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := Sequence{} ; var ans : String := "Yes" ; for i : Integer.subrange(0, r-1) do ( var s0 : Sequence := (input().rstrip()) ; for j : Integer.subrange(0, c - 1-1) do ( if s0[j+1] = "S" & s0[j + 1+1] = "W" then ( ans := "No" ) else (if s0[j+1] = "W" & s0[j + 1+1] = "S" then ( ans := "No" ) else skip)) ; for j : Integer.subrange(0, c-1) do ( if s0[j+1] = "." then ( s0[j+1] := "D" ) else skip) ; execute ((s0) : s)) ; for i : Integer.subrange(0, r - 1-1) do ( if ans = "No" then ( break ) else skip ; var s1 : OclAny := null; Sequence{s0,s1} := Sequence{s[i+1],s[i + 1+1]} ; for j : Integer.subrange(0, c-1) do ( if s0[j+1] = "S" & s1[j+1] = "W" then ( ans := "No" ) else (if s0[j+1] = "W" & s1[j+1] = "S" then ( ans := "No" ) else skip))) ; execute (ans)->display() ; if ans = "Yes" then ( ans := Sequence{} ; for s0 : s do ( execute ((StringLib.sumStringsWithSeparator((s0), "")) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) )))) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re r,c=input().split() s='\n'.join(input().replace('.','D')for _ in[0]*int(r)) print('No' if re.search('(?s)(S|W)(.{'+c+'})?(?!\\1)[SW]',s)else 'Yes\n'+s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := input().split() ; var s : String := StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name replace) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '.')))))) , (argument (test (logical_test (comparison (expr (atom 'D'))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name r)))))))) )))))))))), ' ') ; execute (if (s)->firstMatch('(?s)(S|W)(.{' + c + '})?(?!\\1)[SW]') then 'No' else 'Yes ' + s endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(200000) import math from collections import Counter from collections import defaultdict from collections import deque input=sys.stdin.readline from functools import lru_cache import heapq def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s=input() return(list(s[: len(s)-1])) def invr(): return(map(int,input().split())) row,col=inlt() grid=[] for i in range(row): grid.append(insr()) directions=[(-1,0),(1,0),(0,1),(0,-1)] def isValid(nr,nc): if(nr<0 or nr>=row or nc<0 or nc>=col)or grid[nr][nc]=="S" : return True if grid[nr][nc]=="W" : return False grid[nr][nc]="D" return True for i in range(row): for j in range(col): if grid[i][j]=="S" : x=True for r,c in directions : x=x and isValid(i+r,j+c) if x==False : print("NO") exit() print("YES") for i in range(row): print("".join(grid[i])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(200000) ; skip ; skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; skip ; skip ; var row : OclAny := null; var col : OclAny := null; Sequence{row,col} := inlt() ; var grid : Sequence := Sequence{} ; for i : Integer.subrange(0, row-1) do ( execute ((insr()) : grid)) ; var directions : Sequence := Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{ Sequence{0, -1} }))) ; skip ; for i : Integer.subrange(0, row-1) do ( for j : Integer.subrange(0, col-1) do ( if grid[i+1][j+1] = "S" then ( var x : boolean := true ; for _tuple : directions do (var _indx : int := 1; var r : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); x := x & isValid(i + r, j + c)) ; if x = false then ( execute ("NO")->display() ; exit() ) else skip ) else skip)) ; execute ("YES")->display() ; for i : Integer.subrange(0, row-1) do ( execute (StringLib.sumStringsWithSeparator((grid[i+1]), ""))->display()); operation inp() : OclAny pre: true post: true activity: return (("" + (((OclFile["System.in"]).readLine())))->toInteger()); operation inlt() : OclAny pre: true post: true activity: return (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))); operation insr() : OclAny pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; return ((s.subrange(1,(s)->size() - 1))); operation invr() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation isValid(nr : OclAny, nc : OclAny) : OclAny pre: true post: true activity: if (nr < 0 or (nr->compareTo(row)) >= 0 or nc < 0 or (nc->compareTo(col)) >= 0) or grid[nr+1][nc+1] = "S" then ( return true ) else skip ; if grid[nr+1][nc+1] = "W" then ( return false ) else skip ; grid[nr+1][nc+1] := "D" ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def wolf(x,y,m): for i in range(x): for j in range(y): if(m[i][j]=='.'): m[i][j]='D' elif(m[i][j]=='W'): if(j>0): if(m[i][j-1]=='S'): print("NO") exit(0) if(j0): if(m[i-1][j]=='S'): print("NO") exit(0) print("YES") for r in m : print(''.join(r)) nm=input().split() n=list(map(int,nm)) m=[None]*n[0] for i in range(n[0]): arr=input() m[i]=list(arr) wolf(n[0],n[1],m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var nm : OclAny := input().split() ; var n : Sequence := ((nm)->collect( _x | (OclType["int"])->apply(_x) )) ; m := MatrixLib.elementwiseMult(Sequence{ null }, n->first()) ; for i : Integer.subrange(0, n->first()-1) do ( var arr : String := (OclFile["System.in"]).readLine() ; m[i+1] := (arr)->characters()) ; wolf(n->first(), n[1+1], m); operation wolf(x : OclAny, y : OclAny, m : OclAny) pre: true post: true activity: for i : Integer.subrange(0, x-1) do ( for j : Integer.subrange(0, y-1) do ( if (m[i+1][j+1] = '.') then ( m[i+1][j+1] := 'D' ) else (if (m[i+1][j+1] = 'W') then ( if (j > 0) then ( if (m[i+1][j - 1+1] = 'S') then ( execute ("NO")->display() ; exit(0) ) else skip ) else skip ; if ((j->compareTo(y - 1)) < 0) then ( if (m[i+1][j + 1+1] = 'S') then ( execute ("NO")->display() ; exit(0) ) else skip ) else skip ; if ((i->compareTo(x - 1)) < 0) then ( if (m[i + 1+1][j+1] = 'S') then ( execute ("NO")->display() ; exit(0) ) else skip ) else skip ; if (i > 0) then ( if (m[i - 1+1][j+1] = 'S') then ( execute ("NO")->display() ; exit(0) ) else skip ) else skip ) else skip))) ; execute ("YES")->display() ; for r : m do ( execute (StringLib.sumStringsWithSeparator((r), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import* import sys n=int(input()) ss=[] color={} cnt=0 for _ in range(n): a,b,*c=map(int,sys.stdin.readline().split()) if a==0 : if b not in color : insort_left(ss,b) color[b]=1 cnt+=1 else : color[b]+=1 cnt+=1 print(cnt) elif a==1 : print(color[b]if b in color else 0) elif a==2 : if b in color : cnt-=color[b] color[b]=0 else : L=bisect_left(ss,b) R=bisect(ss,c[0]) for i in range(L,R): for _ in range(color[ss[i]]): print(ss[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ss : Sequence := Sequence{} ; var color : OclAny := Set{} ; var cnt : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 0 then ( if (color)->excludes(b) then ( insort_left(ss, b) ; color[b+1] := 1 ; cnt := cnt + 1 ) else ( color[b+1] := color[b+1] + 1 ; cnt := cnt + 1 ) ; execute (cnt)->display() ) else (if a = 1 then ( execute (if (color)->includes(b) then color[b+1] else 0 endif)->display() ) else (if a = 2 then ( if (color)->includes(b) then ( cnt := cnt - color[b+1] ; color[b+1] := 0 ) else skip ) else ( var L : OclAny := bisect_left(ss, b) ; var R : OclAny := bisect(ss, c->first()) ; for i : Integer.subrange(L, R-1) do ( for _anon : Integer.subrange(0, color[ss[i+1]+1]-1) do ( execute (ss[i+1])->display())) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solution(): rows,columnns=map(int,input().split()) area=[] for i in range(rows): row=list(input()) area.append(row) for i in range(rows): for j in range(columnns): if area[i][j]=="S" : if((i0 and area[i-1][j]=="W"): print("No",end="") return elif((i>0)and area[i-1][j]=="."): area[i-1][j]="D" if((j0)and area[i][j-1]=="W"): print("No",end="") return elif((j>0)and area[i][j-1]=="."): area[i][j-1]="D" print("Yes") for i in range(rows): for j in range(columnns): print(area[i][j],end="") if icollect( _x | (OclType["int"])->apply(_x) ) ; var area : Sequence := Sequence{} ; for i : Integer.subrange(0, rows-1) do ( var row : Sequence := ((OclFile["System.in"]).readLine())->characters() ; execute ((row) : area)) ; for i : Integer.subrange(0, rows-1) do ( for j : Integer.subrange(0, columnns-1) do ( if area[i+1][j+1] = "S" then ( if (((i->compareTo(rows - 1)) < 0) & area[i + 1+1][j+1] = "W") then ( execute ("No")->display() ; return ) else (if (((i->compareTo(rows - 1)) < 0) & area[i + 1+1][j+1] = ".") then ( area[i + 1+1][j+1] := "D" ) else skip) ; if (i > 0 & area[i - 1+1][j+1] = "W") then ( execute ("No")->display() ; return ) else (if ((i > 0) & area[i - 1+1][j+1] = ".") then ( area[i - 1+1][j+1] := "D" ) else skip) ; if (((j->compareTo(columnns - 1)) < 0) & area[i+1][j + 1+1] = "W") then ( execute ("No")->display() ; return ) else (if (((j->compareTo(columnns - 1)) < 0) & area[i+1][j + 1+1] = ".") then ( area[i+1][j + 1+1] := "D" ) else skip) ; if ((j > 0) & area[i+1][j - 1+1] = "W") then ( execute ("No")->display() ; return ) else (if ((j > 0) & area[i+1][j - 1+1] = ".") then ( area[i+1][j - 1+1] := "D" ) else skip) ) else skip)) ; execute ("Yes")->display() ; for i : Integer.subrange(0, rows-1) do ( for j : Integer.subrange(0, columnns-1) do ( execute (area[i+1][j+1])->display()) ; if (i->compareTo(rows - 1)) < 0 then ( execute (->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMin(arr,n): m=0 for i in range(n): m=max(m,arr[i]) freq=[0]*(m+2) for i in range(n): freq[arr[i]]+=1 for i in range(1,m+2): j=i cnt=0 while(j<=m): cnt+=freq[j] j+=i if(not cnt): return i return m+1 arr=[2,12,6] n=len(arr) print(findMin(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{12}->union(Sequence{ 6 })) ; n := (arr)->size() ; execute (findMin(arr, n))->display(); operation findMin(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var m : int := 0 ; for i : Integer.subrange(0, n-1) do ( m := Set{m, arr[i+1]}->max()) ; var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (m + 2)) ; for i : Integer.subrange(0, n-1) do ( freq[arr[i+1]+1] := freq[arr[i+1]+1] + 1) ; for i : Integer.subrange(1, m + 2-1) do ( var j : OclAny := i ; var cnt : int := 0 ; while ((j->compareTo(m)) <= 0) do ( cnt := cnt + freq[j+1] ; j := j + i) ; if (not(cnt)) then ( return i ) else skip) ; return m + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMin(arr,n): m=0 for i in range(n): m=max(m,arr[i]) cnt=[0]*(m+2) for i in range(n): j=1 while j*j<=arr[i]: if(arr[i]% j==0): if(j*j==arr[i]): cnt[j]+=1 else : cnt[j]+=1 cnt[arr[i]//j]+=1 j+=1 for i in range(1,m+2): if(cnt[i]==0): return i return-1 arr=[2,12,6] n=len(arr) print(findMin(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{12}->union(Sequence{ 6 })) ; n := (arr)->size() ; execute (findMin(arr, n))->display(); operation findMin(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var m : int := 0 ; for i : Integer.subrange(0, n-1) do ( m := Set{m, arr[i+1]}->max()) ; var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (m + 2)) ; for i : Integer.subrange(0, n-1) do ( var j : int := 1 ; while (j * j->compareTo(arr[i+1])) <= 0 do ( if (arr[i+1] mod j = 0) then ( if (j * j = arr[i+1]) then ( cnt[j+1] := cnt[j+1] + 1 ) else ( cnt[j+1] := cnt[j+1] + 1 ; cnt[arr[i+1] div j+1] := cnt[arr[i+1] div j+1] + 1 ) ) else skip ; j := j + 1)) ; for i : Integer.subrange(1, m + 2-1) do ( if (cnt[i+1] = 0) then ( return i ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,m,seq1,seq2): op1=0 op2=0 seq1.sort(key=lambda x : x[1]) seq2.sort(key=lambda x : x[0],reverse=True) if seq2[0][0]-seq1[0][1]<=0 : pass else : op1=seq2[0][0]-seq1[0][1] seq2.sort(key=lambda x : x[1]) seq1.sort(key=lambda x : x[0],reverse=True) if seq1[0][0]-seq2[0][1]<=0 : pass else : op2=seq1[0][0]-seq2[0][1] return max(op1,op2) n=int(input()) s1=[] s2=[] for x in range(n): s1.append(list(map(int,input().split()))) m=int(input()) for y in range(m): s2.append(list(map(int,input().split()))) print(solve(n,m,s1,s2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s1 : Sequence := Sequence{} ; var s2 : Sequence := Sequence{} ; for x : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : s1)) ; m := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for y : Integer.subrange(0, m-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : s2)) ; execute (solve(n, m, s1, s2))->display(); operation solve(n : OclAny, m : OclAny, seq1 : OclAny, seq2 : OclAny) : OclAny pre: true post: true activity: var op1 : int := 0 ; var op2 : int := 0 ; seq1 := seq1->sort() ; seq2 := seq2->sort() ; if seq2->first()->first() - seq1->first()[1+1] <= 0 then ( skip ) else ( op1 := seq2->first()->first() - seq1->first()[1+1] ) ; seq2 := seq2->sort() ; seq1 := seq1->sort() ; if seq1->first()->first() - seq2->first()[1+1] <= 0 then ( skip ) else ( op2 := seq1->first()->first() - seq2->first()[1+1] ) ; return Set{op1, op2}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,heapq n=int(sys.stdin.readline()) chess=[] for _ in range(n): a,b=map(int,sys.stdin.readline().split()) chess.append((a,b)) m=int(sys.stdin.readline()) ps=[] for _ in range(m): a,b=map(int,sys.stdin.readline().split()) ps.append((a,b)) chess.sort(key=lambda x : x[1]) ps.sort(key=lambda x :-1*x[0]) ans1=ps[0][0]-chess[0][1]if ps[0][0]-chess[0][1]>=0 else 0 chess.sort(key=lambda x :-1*x[0]) ps.sort(key=lambda x : x[1]) ans2=chess[0][0]-ps[0][1]if chess[0][0]-ps[0][1]>=0 else 0 print(max(ans1,ans2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var chess : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a, b}) : chess)) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ps : Sequence := Sequence{} ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a, b}) : ps)) ; chess := chess->sort() ; ps := ps->sort() ; var ans1 : double := if ps->first()->first() - chess->first()[1+1] >= 0 then ps->first()->first() - chess->first()[1+1] else 0 endif ; chess := chess->sort() ; ps := ps->sort() ; var ans2 : double := if chess->first()->first() - ps->first()[1+1] >= 0 then chess->first()->first() - ps->first()[1+1] else 0 endif ; execute (Set{ans1, ans2}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=list(map(int,input().split())) da=a[0] db=a[1] if da>db : if da==9 and db==1 : print(9,10) else : print(-1) elif da==db : print(str(da)+str(0),str(db)+str(1)) else : if db-da!=1 : print(-1) else : print(da,db) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var da : OclAny := a->first() ; var db : OclAny := a[1+1] ; if (da->compareTo(db)) > 0 then ( if da = 9 & db = 1 then ( execute (9)->display() ) else ( execute (-1)->display() ) ) else (if da = db then ( execute (("" + ((da))) + ("" + ((0))))->display() ) else ( if db - da /= 1 then ( execute (-1)->display() ) else ( execute (da)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math fMinEnd,sMinEnd=math.inf,math.inf fMaxStart,sMaxStart=0,0 n=int(input()) for _ in range(n): s,e=map(int,input().split()) fMinEnd=min(fMinEnd,e) fMaxStart=max(fMaxStart,s) m=int(input()) for _ in range(m): s,e=map(int,input().split()) sMinEnd=min(sMinEnd,e) sMaxStart=max(sMaxStart,s) res1=max(0,sMaxStart-fMinEnd) res2=max(0,fMaxStart-sMinEnd) print(max(res1,res2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var fMinEnd : OclAny := null; var sMinEnd : OclAny := null; Sequence{fMinEnd,sMinEnd} := Sequence{,} ; var fMaxStart : OclAny := null; var sMaxStart : OclAny := null; Sequence{fMaxStart,sMaxStart} := Sequence{0,0} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var s : OclAny := null; var e : OclAny := null; Sequence{s,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var fMinEnd : OclAny := Set{fMinEnd, e}->min() ; var fMaxStart : OclAny := Set{fMaxStart, s}->max()) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, m-1) do ( var s : OclAny := null; var e : OclAny := null; Sequence{s,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sMinEnd : OclAny := Set{sMinEnd, e}->min() ; var sMaxStart : OclAny := Set{sMaxStart, s}->max()) ; var res1 : OclAny := Set{0, sMaxStart - fMinEnd}->max() ; var res2 : OclAny := Set{0, fMaxStart - sMinEnd}->max() ; execute (Set{res1, res2}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- infinity=1234567890 minR1=minR2=infinity maxL1=maxL2=-infinity n=int(input()) for i in range(0,n): (l,r)=map(int,input().split()) maxL1=max(maxL1,l) minR1=min(minR1,r) m=int(input()) for i in range(0,m): (l,r)=map(int,input().split()) maxL2=max(maxL2,l) minR2=min(minR2,r) res=max(maxL2-minR1,maxL1-minR2); print(max(res,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var infinity : int := 1234567890 ; var minR1 : OclAny := infinity; var minR2 : int := infinity ; var maxL1 : OclAny := -infinity; var maxL2 : int := -infinity ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( ; var Sequence{l, r} : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; maxL1 := Set{maxL1, l}->max() ; minR1 := Set{minR1, r}->min()) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, m-1) do ( ; Sequence{l, r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; maxL2 := Set{maxL2, l}->max() ; minR2 := Set{minR2, r}->min()) ; var res : OclAny := Set{maxL2 - minR1, maxL1 - minR2}->max(); ; execute (Set{res, 0}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate N,M,Q=map(int,input().split()) a=[[0]*(N+1)for i in range(N+1)] for i in range(M): L,R=map(int,input().split()) a[L][R]+=1 b=[list(accumulate(a[i]))for i in range(N+1)] k=[[b[j][i]for j in range(i+1)]for i in range(N+1)] ans=[list(accumulate(reversed(k[i])))[: :-1]for i in range(N+1)] for i in range(Q): p,q=map(int,input().split()) print(ans[q][p-q-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; var Q : OclAny := null; Sequence{N,M,Q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)))) ; for i : Integer.subrange(0, M-1) do ( var L : OclAny := null; var R : OclAny := null; Sequence{L,R} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a[L+1][R+1] := a[L+1][R+1] + 1) ; var b : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | ((accumulate(a[i+1])))) ; var k : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, i + 1-1)->select(j | true)->collect(j | (b[j+1][i+1])))) ; var ans : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (OclType["Sequence"](accumulate((k[i+1])->reverse()))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))) ; for i : Integer.subrange(0, Q-1) do ( var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (ans[q+1][p - q - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline N,M,Q=map(int,input().split()) class CumSum2d(object): def __init__(self,H,W): self.H,self.W=H,W self.tiles=[[0]*W for _ in range(H)] def add(self,x,y,c=1): self.tiles[y][x]+=c def build(self): for y in range(self.H): for x in range(1,self.W): self.tiles[y][x]+=self.tiles[y][x-1] for y in range(1,self.H): for x in range(self.W): self.tiles[y][x]+=self.tiles[y-1][x] def get(self,sx,sy,tx,ty): assert sx<=tx and sy<=ty cnt=self.tiles[ty][tx] if sx>0 : cnt-=self.tiles[ty][sx-1] if sy>0 : cnt-=self.tiles[sy-1][tx] if sx>0 and sy>0 : cnt+=self.tiles[sy-1][sx-1] return cnt cs=CumSum2d(N,N) for i in range(M): l,r=map(int,input().split()) cs.add(l-1,r-1) cs.build() for _ in range(Q): p,q=map(int,input().split()) ans=cs.get(p-1,p-1,q-1,q-1) print(ans) ------------------------------------------------------------ OCL File: --------- class CumSum2d extends object { static operation newCumSum2d() : CumSum2d pre: true post: CumSum2d->exists( _x | result = _x ); attribute (testlist_star_expr (test (logical_test (comparison (expr (atom (name self)) (trailer . (name H)))))) , (test (logical_test (comparison (expr (atom (name self)) (trailer . (name W))))))) : OclAny := H,W; attribute tiles : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, W))); operation initialise(H : OclAny,W : OclAny) : pre: true post: true activity: var self.H : OclAny := null; var self.W : OclAny := null; Sequence{self.H,self.W} := Sequence{H,W} ; self.tiles := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, W))); return self; operation add(x : OclAny,y : OclAny,c : int) pre: true post: true activity: self.tiles[y+1][x+1] := self.tiles[y+1][x+1] + c; operation build() pre: true post: true activity: for y : Integer.subrange(0, self.H-1) do ( for x : Integer.subrange(1, self.W-1) do ( self.tiles[y+1][x+1] := self.tiles[y+1][x+1] + self.tiles[y+1][x - 1+1])) ; for y : Integer.subrange(1, self.H-1) do ( for x : Integer.subrange(0, self.W-1) do ( self.tiles[y+1][x+1] := self.tiles[y+1][x+1] + self.tiles[y - 1+1][x+1])); operation get(sx : OclAny,sy : OclAny,tx : OclAny,ty : OclAny) : OclAny pre: true post: true activity: assert (sx->compareTo(tx)) <= 0 & (sy->compareTo(ty)) <= 0 do "assertion failed" ; var cnt : OclAny := self.tiles[ty+1][tx+1] ; if sx > 0 then ( cnt := cnt - self.tiles[ty+1][sx - 1+1] ) else skip ; if sy > 0 then ( cnt := cnt - self.tiles[sy - 1+1][tx+1] ) else skip ; if sx > 0 & sy > 0 then ( cnt := cnt + self.tiles[sy - 1+1][sx - 1+1] ) else skip ; return cnt; } class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var N : OclAny := null; var M : OclAny := null; var Q : OclAny := null; Sequence{N,M,Q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; var cs : CumSum2d := (CumSum2d.newCumSum2d()).initialise(N, N) ; for i : Integer.subrange(0, M-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((l - 1, r - 1) : cs)) ; cs.build() ; for _anon : Integer.subrange(0, Q-1) do ( var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : OclAny := cs.get(p - 1, p - 1, q - 1, q - 1) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter,defaultdict,deque import sys from itertools import permutations,combinations from heapq import heappop,heappush input=sys.stdin.readline sys.setrecursionlimit(10**8) mod=10**9+7 def inp(): return int(input()) def inpm(): return map(int,input().split()) def inpl(): return list(map(int,input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(input())for _ in range(n)) def inpll(n): return sorted([list(map(int,input().split()))for _ in range(n)]) def main(): n,m,Q=inpm() ans=[[0 for _ in range(n)]for _ in range(n)] for i in range(m): l,r=inpm() r-=1 ans[r][0]+=1 if l!=n : ans[r][l]-=1 for i in range(n): for j in range(1,n): ans[i][j]+=ans[i][j-1] for i in range(n): for j in range(1,n): ans[j][i]+=ans[j-1][i] for _ in range(Q): p,q=inpm() print(ans[q-1][p-1]) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit((10)->pow(8)) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inpm() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inpls() : OclAny pre: true post: true activity: return (input().split()); operation inplm(n : OclAny) : OclAny pre: true post: true activity: return ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))); operation inpll(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))->sort(); operation main() pre: true post: true activity: var m : OclAny := null; var Q : OclAny := null; Sequence{n,m,Q} := inpm() ; var ans : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)))) ; for i : Integer.subrange(0, m-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := inpm() ; r := r - 1 ; ans[r+1]->first() := ans[r+1]->first() + 1 ; if l /= n then ( ans[r+1][l+1] := ans[r+1][l+1] - 1 ) else skip) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(1, n-1) do ( ans[i+1][j+1] := ans[i+1][j+1] + ans[i+1][j - 1+1])) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(1, n-1) do ( ans[j+1][i+1] := ans[j+1][i+1] + ans[j - 1+1][i+1])) ; for _anon : Integer.subrange(0, Q-1) do ( var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := inpm() ; execute (ans[q - 1+1][p - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import sys def input(): return sys.stdin.readline().strip() S=[] count={} total=0 for _ in range(int(input())): order=tuple(map(int,input().split())) value=order[1] if order[0]==0 : if value in count : count[value]+=1 else : count[value]=1 bisect.insort(S,value) total+=1 print(total) elif order[0]==1 : if value in count : print(count[value]) else : print(0) elif order[0]==2 : if value in count : total-=count[value] count[value]=0 else : left=bisect.bisect_left(S,order[1]) right=bisect.bisect(S,order[2]) out=[] for i in range(left,right): out+=[S[i]]*count[S[i]] for i in out : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var S : Sequence := Sequence{} ; var count : OclAny := Set{} ; var total : int := 0 ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var order : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var value : OclAny := order[1+1] ; if order->first() = 0 then ( if (count)->includes(value) then ( count[value+1] := count[value+1] + 1 ) else ( count[value+1] := 1 ; bisect.insort(S, value) ) ; total := total + 1 ; execute (total)->display() ) else (if order->first() = 1 then ( if (count)->includes(value) then ( execute (count[value+1])->display() ) else ( execute (0)->display() ) ) else (if order->first() = 2 then ( if (count)->includes(value) then ( total := total - count[value+1] ; count[value+1] := 0 ) else skip ) else ( var left : OclAny := bisect.bisect_left(S, order[1+1]) ; var right : OclAny := bisect.bisect(S, order[2+1]) ; var out : Sequence := Sequence{} ; for i : Integer.subrange(left, right-1) do ( out := out + MatrixLib.elementwiseMult(Sequence{ S[i+1] }, count[S[i+1]+1])) ; for i : out do ( execute (i)->display()) ) ) ) ); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np import sys N,M,Q=map(int,input().split()) I=sys.stdin.read().split() L,R=np.array(I[: 2*M],np.int32).reshape([2,-1],order='F') p,q=np.array(I[2*M :],np.int32).reshape(2,-1,order='F') d=np.zeros([N+1,N+1],np.int32) d=np.zeros([1+N,1+N],np.int32) np.add.at(d,(N-L,R),1) d=np.add.accumulate(d,axis=1) d=np.add.accumulate(d) ans=d[N-p,q] for a in ans : print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := null; var M : OclAny := null; var Q : OclAny := null; Sequence{N,M,Q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var I : OclAny := sys.stdin.readAll().split() ; var L : OclAny := null; var R : OclAny := null; Sequence{L,R} := np.array(I.subrange(1,2 * M), ).reshape(Sequence{2}->union(Sequence{ -1 }), (argument (test (logical_test (comparison (expr (atom (name order)))))) = (test (logical_test (comparison (expr (atom 'F'))))))) ; var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := np.array(I.subrange(2 * M+1), ).reshape(2, -1, (argument (test (logical_test (comparison (expr (atom (name order)))))) = (test (logical_test (comparison (expr (atom 'F'))))))) ; var d : Sequence := MatrixLib.singleValueMatrix(Sequence{N + 1}->union(Sequence{ N + 1 }), 0.0) ; d := MatrixLib.singleValueMatrix(Sequence{1 + N}->union(Sequence{ 1 + N }), 0.0) ; (expr (atom (name np)) (trailer . (name add)) (trailer . (name at) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name d))))))) , (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name N))) - (expr (atom (name L))))))) , (test (logical_test (comparison (expr (atom (name R))))))) ))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))) ; d := np.add.accumulate(d, (argument (test (logical_test (comparison (expr (atom (name axis)))))) = (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ; d := np.add.accumulate(d) ; var ans : OclAny := d[N - p+1][q+1] ; for a : ans do ( execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,tan,asin,acos,atan,radians,degrees,log2,gcd from itertools import accumulate,permutations,combinations,combinations_with_replacement,product,groupby from operator import itemgetter,mul from copy import deepcopy from string import ascii_lowercase,ascii_uppercase,digits from bisect import bisect,bisect_left,insort,insort_left from heapq import heappush,heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) def ZIP(n): return zip(*(MAP()for _ in range(n))) sys.setrecursionlimit(10**9) INF=float('inf') mod=10**9+7 from decimal import* N,M,Q=MAP() LR=[LIST()for _ in range(M)] pq=[LIST()for _ in range(Q)] x=[[0]*(N+1)for _ in range(N+1)] for L,R in LR : x[L][R]+=1 for l in range(N+1): x[l]=list(accumulate(x[l])) for l in range(1,N+1): for r in range(N+1): x[l][r]+=x[l-1][r] for p,q in pq : print(x[q][q]-x[q][p-1]-x[p-1][q]+x[p-1][p-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; skip ; var N : OclAny := null; var M : OclAny := null; var Q : OclAny := null; Sequence{N,M,Q} := MAP() ; var LR : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (LIST())) ; var pq : Sequence := Integer.subrange(0, Q-1)->select(_anon | true)->collect(_anon | (LIST())) ; var x : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)))) ; for _tuple : LR do (var _indx : int := 1; var L : OclAny := _tuple->at(_indx); _indx := _indx + 1; var R : OclAny := _tuple->at(_indx); x[L+1][R+1] := x[L+1][R+1] + 1) ; for l : Integer.subrange(0, N + 1-1) do ( x[l+1] := (accumulate(x[l+1]))) ; for l : Integer.subrange(1, N + 1-1) do ( for r : Integer.subrange(0, N + 1-1) do ( x[l+1][r+1] := x[l+1][r+1] + x[l - 1+1][r+1])) ; for _tuple : pq do (var _indx : int := 1; var p : OclAny := _tuple->at(_indx); _indx := _indx + 1; var q : OclAny := _tuple->at(_indx); execute (x[q+1][q+1] - x[q+1][p - 1+1] - x[p - 1+1][q+1] + x[p - 1+1][p - 1+1])->display()); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ZIP(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))`third->at(_indx)} ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt EPS=1e-8 def Projection(point,begin,end): tmp=(point-begin)/(end-begin) return tmp.real*(end-begin)+begin x,y,r=map(int,input().split()) c=complex(x,y) ans=[] q=int(input()) for _ in range(q): res=[] x,y,z,w=map(int,input().split()) p1,p2=complex(x,y),complex(z,w) proj=Projection(c,p1,p2) for i in[-1,1]: res.append(proj+i*sqrt(r**2-abs(c-proj)**2)*(p2-p1)/abs(p2-p1)) res.sort(key=lambda x :(x.real,x.imag)) ans.append((res[0].real,res[0].imag,res[1].real,res[1].imag)) for a in ans : print("{:.10f}{:.10f}{:.10f}{:.10f}".format(*a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var EPS : double := ("1e-8")->toReal() ; skip ; var x : OclAny := null; var y : OclAny := null; var r : OclAny := null; Sequence{x,y,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : OclAny := complex(x, y) ; var ans : Sequence := Sequence{} ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( var res : Sequence := Sequence{} ; var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; var w : OclAny := null; Sequence{x,y,z,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p1 : OclAny := null; var p2 : OclAny := null; Sequence{p1,p2} := Sequence{complex(x, y),complex(z, w)} ; var proj : OclAny := Projection(c, p1, p2) ; for i : Sequence{-1}->union(Sequence{ 1 }) do ( execute ((proj + i * sqrt((r)->pow(2) - ((c - proj)->abs())->pow(2)) * (p2 - p1) / (p2 - p1)->abs()) : res)) ; res := res->sort() ; execute ((Sequence{res->first().real, res->first().imag, res[1+1].real, res[1+1].imag}) : ans)) ; for a : ans do ( execute (StringLib.interpolateStrings("{:.10f}{:.10f}{:.10f}{:.10f}", Sequence{(argument * (test (logical_test (comparison (expr (atom (name a)))))))}))->display()); operation Projection(point : OclAny, begin : OclAny, end : OclAny) : OclAny pre: true post: true activity: var tmp : double := (point - begin) / (end - begin) ; return tmp.real * (end - begin) + begin; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys from operator import attrgetter from collections import namedtuple def dot(a,b): return a.real*b.real+a.imag*b.imag def project(s,p): base_vector=s.target-s.source prj_ratio=dot(p-s.source,base_vector)/pow(abs(base_vector),2) return s.source+base_vector*prj_ratio def get_cross_point(c,l): prj_vector=project(l,c.centre) line_unit_vector=(l.target-l.source)/(abs(l.target-l.source)) base=math.sqrt(pow(c.radius,2)-pow(abs(prj_vector-c.centre),2)) ans=[prj_vector+line_unit_vector*base,prj_vector-line_unit_vector*base] ans.sort(key=attrgetter('real','imag')) return ans def solve(_lines): for line in _lines : line_axis=tuple(map(int,line)) p0,p1=(x+y*1j for x,y in zip(line_axis[: : 2],line_axis[1 : : 2])) l=Segment(source=p0,target=p1) cp1,cp2=get_cross_point(circle,l) print('{0:.8f}{1:.8f}{2:.8f}{3:.8f}'.format(cp1.real,cp1.imag,cp2.real,cp2.imag)) return None if __name__=='__main__' : _input=sys.stdin.readlines() cx,cy,r=map(int,_input[0].split()) q_num=int(_input[1]) lines=map(lambda x : x.split(),_input[2 :]) Circle=namedtuple('Circle',('centre','radius')) Segment=namedtuple('Segment',('source','target')) circle=Circle(centre=cx+cy*1j,radius=r) solve(lines) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var _input : OclAny := (OclFile["System.in"]).readlines() ; var cx : OclAny := null; var cy : OclAny := null; var r : OclAny := null; Sequence{cx,cy,r} := (_input->first().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var q_num : int := ("" + ((_input[1+1])))->toInteger() ; var lines : Sequence := (_input.subrange(2+1))->collect( _x | (lambda x : OclAny in (x.split()))->apply(_x) ) ; var Circle : OclAny := namedtuple('Circle', Sequence{'centre', 'radius'}) ; var Segment : OclAny := namedtuple('Segment', Sequence{'source', 'target'}) ; var circle : OclAny := Circle((argument (test (logical_test (comparison (expr (atom (name centre)))))) = (test (logical_test (comparison (expr (expr (atom (name cx))) + (expr (expr (atom (name cy))) * (expr (atom (number 1j))))))))), (argument (test (logical_test (comparison (expr (atom (name radius)))))) = (test (logical_test (comparison (expr (atom (name r)))))))) ; solve(lines) ) else skip; operation dot(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a.real * b.real + a.imag * b.imag; operation project(s : OclAny, p : OclAny) : OclAny pre: true post: true activity: var base_vector : double := s.target - s.source ; var prj_ratio : double := dot(p - s.source, base_vector) / ((base_vector)->abs())->pow(2) ; return s.source + base_vector * prj_ratio; operation get_cross_point(c : OclAny, l : OclAny) : OclAny pre: true post: true activity: var prj_vector : OclAny := project(l, c.centre) ; var line_unit_vector : double := (l.target - l.source) / ((l.target - l.source)->abs()) ; var base : double := ((c.radius)->pow(2) - ((prj_vector - c.centre)->abs())->pow(2))->sqrt() ; var ans : Sequence := Sequence{prj_vector + line_unit_vector * base}->union(Sequence{ prj_vector - line_unit_vector * base }) ; ans := ans->sort() ; return ans; operation solve(_lines : OclAny) : OclAny pre: true post: true activity: for line : _lines do ( var line_axis : Sequence := ((line)->collect( _x | (OclType["int"])->apply(_x) )) ; var p0 : OclAny := null; var p1 : OclAny := null; Sequence{p0,p1} := Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (expr (atom (name y))) * (expr (atom (number 1j)))))))) (comp_for for (exprlist (expr (atom (name x))) , (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name line_axis)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name line_axis)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) ])))))))) ))))))))} ; l := Segment((argument (test (logical_test (comparison (expr (atom (name source)))))) = (test (logical_test (comparison (expr (atom (name p0))))))), (argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name p1)))))))) ; var cp1 : OclAny := null; var cp2 : OclAny := null; Sequence{cp1,cp2} := get_cross_point(circle, l) ; execute (StringLib.interpolateStrings('{0:.8f}{1:.8f}{2:.8f}{3:.8f}', Sequence{cp1.real, cp1.imag, cp2.real, cp2.imag}))->display()) ; return null; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=input().split() a=int(a) b=int(b) n=a+1 if a==b : print(a*10,(a*10)+1) elif n==b or(a==9 and b==1): strk=str(a)+'9' print(int(strk),int(strk)+1) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; var n : int := a + 1 ; if a = b then ( execute (a * 10)->display() ) else (if n = b or (a = 9 & b = 1) then ( var strk : String := ("" + ((a))) + '9' ; execute (("" + ((strk)))->toInteger())->display() ) else ( execute (-1)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin readline=stdin.readline def dot(a,b): return a.real*b.real+a.imag*b.imag def unit(a): return a/abs(a) def near_pos_online(p,a,b): unit_a_b=unit(b-a) dist_from_a=dot(unit_a_b,p-a) return a+unit_a_b*dist_from_a def intersection_of_circle_and_line(center,r,a,b): near=near_pos_online(center,a,b) d=sqrt(r**2-abs(center-near)**2)*unit(b-a) return[near+d,near-d] from math import sqrt from operator import attrgetter def main(): cx,cy,r=map(int,readline().split()) center=complex(cx,cy) q=int(readline()) for i in range(q): x1,y1,x2,y2=map(int,readline().split()) a,b=complex(x1,y1),complex(x2,y2) intersection=intersection_of_circle_and_line(center,r,a,b) intersection.sort(key=attrgetter('real','imag')) pre,post=intersection print(*list(map('{:.6f}'.format,[pre.real,pre.imag,post.real,post.imag]))) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := stdin.readline ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; main(); operation dot(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a.real * b.real + a.imag * b.imag; operation unit(a : OclAny) : OclAny pre: true post: true activity: return a / (a)->abs(); operation near_pos_online(p : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var unit_a_b : OclAny := unit(b - a) ; var dist_from_a : OclAny := dot(unit_a_b, p - a) ; return a + unit_a_b * dist_from_a; operation intersection_of_circle_and_line(center : OclAny, r : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var near : OclAny := near_pos_online(center, a, b) ; var d : double := sqrt((r)->pow(2) - ((center - near)->abs())->pow(2)) * unit(b - a) ; return Sequence{near + d}->union(Sequence{ near - d }); operation main() pre: true post: true activity: var cx : OclAny := null; var cy : OclAny := null; Sequence{cx,cy,r} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; center := complex(cx, cy) ; var q : int := ("" + ((readline())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; Sequence{a,b} := Sequence{complex(x1, y1),complex(x2, y2)} ; var intersection : OclAny := intersection_of_circle_and_line(center, r, a, b) ; intersection := intersection->sort() ; var pre : OclAny := null; var post : OclAny := null; Sequence{pre,post} := intersection ; execute ((argument * (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '{:.6f}') (trailer . (name format))))))) , (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name pre)) (trailer . (name real)))))) , (test (logical_test (comparison (expr (atom (name pre)) (trailer . (name imag)))))) , (test (logical_test (comparison (expr (atom (name post)) (trailer . (name real)))))) , (test (logical_test (comparison (expr (atom (name post)) (trailer . (name imag))))))) ]))))))) ))))))))) )))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def intersection_cl(S0,S1,C0,r): x0,y0=S0 ; x1,y1=S1 cx,cy=C0 xd=x1-x0 ; yd=y1-y0 X=x0-cx ; Y=y0-cy A=xd**2+yd**2 B=xd*X+yd*Y C=X**2+Y**2-r**2 if B**2collect( _x | (OclType["int"])->apply(_x) ) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p0 : OclAny := null; var p1 : OclAny := null; Sequence{p0,p1} := intersection_cl(Sequence{x1, y1}, Sequence{x2, y2}, Sequence{cx, cy}, r)->sort() ; execute (StringLib.format("%.08f %.08f %.08f %.08f",(p0 + p1)))->display()); operation intersection_cl(S0 : OclAny, S1 : OclAny, C0 : OclAny, r : OclAny) : OclAny pre: true post: true activity: var x0 : OclAny := null; var y0 : OclAny := null; Sequence{x0,y0} := S0; var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := S1 ; var cx : OclAny := null; var cy : OclAny := null; Sequence{cx,cy} := C0 ; var xd : double := x1 - x0; var yd : double := y1 - y0 ; var X : double := x0 - cx; var Y : double := y0 - cy ; var A : double := (xd)->pow(2) + (yd)->pow(2) ; var B : double := xd * X + yd * Y ; var C : double := (X)->pow(2) + (Y)->pow(2) - (r)->pow(2) ; if ((B)->pow(2)->compareTo(A * C)) < 0 then ( return () ) else skip ; var D : double := (B)->pow(2) - A * C ; var s1 : double := (-B + sqrt(D)) / A ; var s2 : double := (-B - sqrt(D)) / A ; return Sequence{Sequence{x0 + xd * s1, y0 + yd * s1}, Sequence{x0 + xd * s2, y0 + yd * s2}}; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dot(c1,c2): return c1.real*c2.real+c1.imag*c2.imag def cross(c1,c2): return c1.real*c2.imag-c1.imag*c2.real def project(p1,p2,p3): base=p2-p1 return p1+base*dot(p3-p1,base)/(abs(base)**2) def print_cross_point(c,r,p1,p2): pr=project(p1,p2,c) l=p2-p1 e=l/abs(l) base=(r**2-abs(pr-c)**2)**0.5 c_p1=pr-e*base c_p2=pr+e*base print("{0:.10f}{1:.10f}{2:.10f}{3:.10f}".format(c_p1.real,c_p1.imag,c_p2.real,c_p2.imag)) import sys file_input=sys.stdin cx,cy,r=map(int,file_input.readline().split()) c=cx+cy*1j q=file_input.readline() for line in file_input : x1,y1,x2,y2=map(int,line.split()) p1=x1+y1*1j p2=x2+y2*1j if x1x2 or y1>y2 : print_cross_point(c,r,p2,p1) else : print_cross_point(c,r,p1,p2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var file_input : OclFile := OclFile["System.in"] ; var cx : OclAny := null; var cy : OclAny := null; Sequence{cx,cy,r} := (file_input.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; c := cx + cy * 1j ; var q : String := file_input.readLine() ; for line : file_input do ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (line.split())->collect( _x | (OclType["int"])->apply(_x) ) ; p1 := x1 + y1 * 1j ; p2 := x2 + y2 * 1j ; if (x1->compareTo(x2)) < 0 then ( print_cross_point(c, r, p1, p2) ) else (if (x1->compareTo(x2)) > 0 or (y1->compareTo(y2)) > 0 then ( print_cross_point(c, r, p2, p1) ) else ( print_cross_point(c, r, p1, p2) ) ) ); operation dot(c1 : OclAny, c2 : OclAny) : OclAny pre: true post: true activity: return c1.real * c2.real + c1.imag * c2.imag; operation cross(c1 : OclAny, c2 : OclAny) : OclAny pre: true post: true activity: return c1.real * c2.imag - c1.imag * c2.real; operation project(p1 : OclAny, p2 : OclAny, p3 : OclAny) : OclAny pre: true post: true activity: var base : double := p2 - p1 ; return p1 + base * dot(p3 - p1, base) / (((base)->abs())->pow(2)); operation print_cross_point(c : OclAny, r : OclAny, p1 : OclAny, p2 : OclAny) pre: true post: true activity: var pr : OclAny := project(p1, p2, c) ; var l : double := p2 - p1 ; var e : double := l / (l)->abs() ; base := (((r)->pow(2) - ((pr - c)->abs())->pow(2)))->pow(0.5) ; var c_p1 : double := pr - e * base ; var c_p2 : OclAny := pr + e * base ; execute (StringLib.interpolateStrings("{0:.10f}{1:.10f}{2:.10f}{3:.10f}", Sequence{c_p1.real, c_p1.imag, c_p2.real, c_p2.imag}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) from collections import deque N,K=map(int,readline().split()) S=read().rstrip() S=deque(0 if x==b'A'[0]else 1 for x in S) U=10**6 if K>U : K=U+(K & 1) flip=0 for _ in range(K): top=S[0]^ flip if top==0 : S[0]^=1 else : flip ^=1 S.popleft() S.append(flip) if flip==0 : A='A' ; B='B' else : A='B' ; B='A' answer=''.join(A if x==0 else B for x in S) print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; sys.setrecursionlimit((10)->pow(7)) ; skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : OclAny := read().rstrip() ; S := ((argument (test (logical_test (comparison (expr (atom (number (integer 0)))))) if (logical_test (comparison (comparison (expr (atom (name x)))) == (comparison (expr (atom b 'A') (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))) else (test (logical_test (comparison (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name S)))))))) ; var U : double := (10)->pow(6) ; if (K->compareTo(U)) > 0 then ( var K : OclAny := U + (MathLib.bitwiseAnd(K, 1)) ) else skip ; var flip : int := 0 ; for _anon : Integer.subrange(0, K-1) do ( var top : int := MathLib.bitwiseXor(S->first(), flip) ; if top = 0 then ( S->first() := S->first() xor 1 ) else ( flip := flip xor 1 ; S := S->tail() ; execute ((flip) : S) )) ; if flip = 0 then ( var A : String := 'A'; var B : String := 'B' ) else ( A := 'B'; B := 'A' ) ; var answer : String := StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name A))))) if (logical_test (comparison (comparison (expr (atom (name x)))) == (comparison (expr (atom (number (integer 0))))))) else (test (logical_test (comparison (expr (atom (name B))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name S)))))))), '') ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) s=list(input())*3 p=['A' if s[i]=='B' else 'B' for i in range(n)]*3 head,tail=0,n if k>2*n : k=2*n+k % 2 for i in range(k): if s[head]=='A' : s[head],p[head]='B','A' else : s,p=p,s head+=1 s[tail],p[tail]='A','B' tail+=1 print(''.join(s[head : tail])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := MatrixLib.elementwiseMult(((OclFile["System.in"]).readLine())->characters(), 3) ; var p : Sequence := MatrixLib.elementwiseMult(Integer.subrange(0, n-1)->select(i | true)->collect(i | (if s[i+1] = 'B' then 'A' else 'B' endif)), 3) ; var head : OclAny := null; var tail : OclAny := null; Sequence{head,tail} := Sequence{0,n} ; if (k->compareTo(2 * n)) > 0 then ( var k : double := 2 * n + k mod 2 ) else skip ; for i : Integer.subrange(0, k-1) do ( if s[head+1] = 'A' then ( var s[head+1] : OclAny := null; var p[head+1] : OclAny := null; Sequence{s[head+1],p[head+1]} := Sequence{'B','A'} ) else ( Sequence{s,p} := Sequence{p,s} ; head := head + 1 ; var s[tail+1] : OclAny := null; var p[tail+1] : OclAny := null; Sequence{s[tail+1],p[tail+1]} := Sequence{'A','B'} ; tail := tail + 1 )) ; execute (StringLib.sumStringsWithSeparator((s.subrange(head+1, tail)), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) s=list(input())*3 p=['A' if s[i]=='B' else 'B' for i in range(n)]*3 head,tail=0,n for i in range(2*n): if s[head]=='A' : s[head],p[head]='B','A' else : s,p=p,s head+=1 s[tail],p[tail]='A','B' tail+=1 if i==k-1 : print(''.join(s[head : tail])) break else : if n % 2==1 and k % 2==1 : if s[head]=='A' : s[head],p[head]='B','A' else : s,p=p,s head+=1 s[tail],p[tail]='A','B' tail+=1 print(''.join(s[head : tail])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := MatrixLib.elementwiseMult(((OclFile["System.in"]).readLine())->characters(), 3) ; var p : Sequence := MatrixLib.elementwiseMult(Integer.subrange(0, n-1)->select(i | true)->collect(i | (if s[i+1] = 'B' then 'A' else 'B' endif)), 3) ; var head : OclAny := null; var tail : OclAny := null; Sequence{head,tail} := Sequence{0,n} ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name n))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name head)))))))) ])))) == (comparison (expr (atom 'A')))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name head)))))))) ])))))) , (test (logical_test (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name head)))))))) ]))))))) (assign_part = (testlist_star_expr (test (logical_test (comparison (expr (atom 'B'))))) , (test (logical_test (comparison (expr (atom 'A'))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name s)))))) , (test (logical_test (comparison (expr (atom (name p))))))) (assign_part = (testlist_star_expr (test (logical_test (comparison (expr (atom (name p)))))) , (test (logical_test (comparison (expr (atom (name s))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name head)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name tail)))))))) ])))))) , (test (logical_test (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name tail)))))))) ]))))))) (assign_part = (testlist_star_expr (test (logical_test (comparison (expr (atom 'A'))))) , (test (logical_test (comparison (expr (atom 'B')))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name tail)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name i)))) == (comparison (expr (expr (atom (name k))) - (expr (atom (number (integer 1))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name head)))))) : (test (logical_test (comparison (expr (atom (name tail)))))))) ])))))))) ))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (expr (atom (name n))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 1))))))) and (logical_test (comparison (comparison (expr (expr (atom (name k))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 1))))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name head)))))))) ])))) == (comparison (expr (atom 'A')))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name head)))))))) ])))))) , (test (logical_test (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name head)))))))) ]))))))) (assign_part = (testlist_star_expr (test (logical_test (comparison (expr (atom 'B'))))) , (test (logical_test (comparison (expr (atom 'A'))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name s)))))) , (test (logical_test (comparison (expr (atom (name p))))))) (assign_part = (testlist_star_expr (test (logical_test (comparison (expr (atom (name p)))))) , (test (logical_test (comparison (expr (atom (name s))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name head)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name tail)))))))) ])))))) , (test (logical_test (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name tail)))))))) ]))))))) (assign_part = (testlist_star_expr (test (logical_test (comparison (expr (atom 'A'))))) , (test (logical_test (comparison (expr (atom 'B')))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name tail)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name head)))))) : (test (logical_test (comparison (expr (atom (name tail)))))))) ])))))))) ))))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) s=[] rs=[] for i in range(q): s.append(list(map(int,input().split()))) if s[i][0]==3 : rs.append(s[i][1]) rs.append(s[i][2]) else : rs.append(s[i][1]) rs.append(10**9+1) rs=sorted(list(set(rs))) index={rs[i]: i for i in range(len(rs))} counter=[0 for i in range(len(rs)+1)] cnt=0 for i in range(q): op,x=s[i][0],s[i][1] idx=index[x] if op==0 : cnt+=1 counter[idx]+=1 print(cnt) elif op==1 : print(counter[idx]) elif op==2 : cnt-=counter[idx] counter[idx]=0 else : l=idx r=index[s[i][2]] for j in range(l,r+1): for k in range(counter[j]): print(rs[j]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := Sequence{} ; var rs : Sequence := Sequence{} ; for i : Integer.subrange(0, q-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : s) ; if s[i+1]->first() = 3 then ( execute ((s[i+1][1+1]) : rs) ; execute ((s[i+1][2+1]) : rs) ) else ( execute ((s[i+1][1+1]) : rs) )) ; execute (((10)->pow(9) + 1) : rs) ; rs := (Set{}->union((rs)))->sort() ; var index : Map := Integer.subrange(0, (rs)->size()-1)->select(i | true)->collect(i | Map{rs[i+1] |-> i})->unionAll() ; var counter : Sequence := Integer.subrange(0, (rs)->size() + 1-1)->select(i | true)->collect(i | (0)) ; var cnt : int := 0 ; for i : Integer.subrange(0, q-1) do ( var op : OclAny := null; var x : OclAny := null; Sequence{op,x} := Sequence{s[i+1]->first(),s[i+1][1+1]} ; var idx : OclAny := index[x+1] ; if op = 0 then ( cnt := cnt + 1 ; counter[idx+1] := counter[idx+1] + 1 ; execute (cnt)->display() ) else (if op = 1 then ( execute (counter[idx+1])->display() ) else (if op = 2 then ( cnt := cnt - counter[idx+1] ; counter[idx+1] := 0 ) else ( var l : OclAny := idx ; var r : OclAny := index[s[i+1][2+1]+1] ; for j : Integer.subrange(l, r + 1-1) do ( for k : Integer.subrange(0, counter[j+1]-1) do ( execute (rs[j+1])->display())) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from itertools import accumulate from collections import deque def solve(): N,K=map(int,input().split()) S=input() q=deque([1 if c=='A' else 0 for c in S]) cb=0 for i in range(min(K,2*N+K % 2)): if q[0]==(cb ^ 1): q[0]^=1 else : q.popleft() q.append(cb) cb ^=1 ans=['A' if(c ^ cb)else 'B' for c in q] print(''.join(ans)) def debug(x,table): for name,val in table.items(): if x is val : print('DEBUG:{}->{}'.format(name,val),file=sys.stderr) return None if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : String := (OclFile["System.in"]).readLine() ; var q : Sequence := (S->characters()->select(c | true)->collect(c | (if c = 'A' then 1 else 0 endif))) ; var cb : int := 0 ; for i : Integer.subrange(0, Set{K, 2 * N + K mod 2}->min()-1) do ( if q->first() = (MathLib.bitwiseXor(cb, 1)) then ( q->first() := q->first() xor 1 ) else ( q := q->tail() ; execute ((cb) : q) ; cb := cb xor 1 )) ; var ans : Sequence := q->select(c | true)->collect(c | (if (MathLib.bitwiseXor(c, cb)) then 'A' else 'B' endif)) ; execute (StringLib.sumStringsWithSeparator((ans), ''))->display(); operation debug(x : OclAny, table : OclAny) : OclAny pre: true post: true activity: for _tuple : table->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var name : OclAny := _tuple->at(_indx); _indx := _indx + 1; var val : OclAny := _tuple->at(_indx); if x <>= val then ( execute (StringLib.interpolateStrings('DEBUG:{}->{}', Sequence{name, val}))->display() ; return null ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minCost(str1,K): n=len(str1) res=999999999 count=0 cnt=[0 for i in range(27)] for i in range(n): cnt[ord(str1[i])-ord('a')+1]+=1 for i in range(1,26-K+1,1): a=i b=i+K count=0 for j in range(1,27,1): if(cnt[j]>0): if(j>=a and j>=b): count=count+(min(j-b,25-j+a+1))*cnt[j] elif(j<=a and j<=b): count=count+(min(a-j,25+j-b+1))*cnt[j] res=min(res,count) for i in range(26-K+1,27,1): a=i b=(i+K)% 26 count=0 for j in range(1,27,1): if(cnt[j]>0): if(j>=b and j<=a): count=count+(min(j-b,a-j))*cnt[j] res=min(res,count) return res if __name__=='__main__' : str1="abcdefghi" K=2 print(minCost(str1,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( str1 := "abcdefghi" ; K := 2 ; execute (minCost(str1, K))->display() ) else skip; operation minCost(str1 : OclAny, K : OclAny) : OclAny pre: true post: true activity: var n : int := (str1)->size() ; var res : int := 999999999 ; var count : int := 0 ; var cnt : Sequence := Integer.subrange(0, 27-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( cnt[(str1[i+1])->char2byte() - ('a')->char2byte() + 1+1] := cnt[(str1[i+1])->char2byte() - ('a')->char2byte() + 1+1] + 1) ; for i : Integer.subrange(1, 26 - K + 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( var a : OclAny := i ; var b : OclAny := i + K ; count := 0 ; for j : Integer.subrange(1, 27-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if (cnt[j+1] > 0) then ( if ((j->compareTo(a)) >= 0 & (j->compareTo(b)) >= 0) then ( count := count + (Set{j - b, 25 - j + a + 1}->min()) * cnt[j+1] ) else (if ((j->compareTo(a)) <= 0 & (j->compareTo(b)) <= 0) then ( count := count + (Set{a - j, 25 + j - b + 1}->min()) * cnt[j+1] ) else skip) ) else skip) ; res := Set{res, count}->min()) ; for i : Integer.subrange(26 - K + 1, 27-1)->select( $x | ($x - 26 - K + 1) mod 1 = 0 ) do ( a := i ; b := (i + K) mod 26 ; count := 0 ; for j : Integer.subrange(1, 27-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if (cnt[j+1] > 0) then ( if ((j->compareTo(b)) >= 0 & (j->compareTo(a)) <= 0) then ( count := count + (Set{j - b, a - j}->min()) * cnt[j+1] ) else skip ) else skip) ; res := Set{res, count}->min()) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def search(arr,n,x): if(arr[n-1]==x): return "Found" backup=arr[n-1] arr[n-1]=x i=0 while(iunion(Sequence{6}->union(Sequence{1}->union(Sequence{5}->union(Sequence{ 8 })))) ; n := (arr)->size() ; x := 1 ; execute (search(arr, n, x))->display(); operation search(arr : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: if (arr[n - 1+1] = x) then ( return "Found" ) else skip ; var backup : OclAny := arr[n - 1+1] ; arr[n - 1+1] := x ; var i : int := 0 ; while ((i->compareTo(n)) < 0) do ( if (arr[i+1] = x) then ( arr[n - 1+1] := backup ; if ((i->compareTo(n - 1)) < 0) then ( return "Found" ) else skip ; return "Not Found" ) else skip ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) if a<=b and abs(a-b)==1 : print(a*10+9,b*10) elif a==b : print(a*10,b*10+1) elif a==9 and b==1 : print(9,10) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(b)) <= 0 & (a - b)->abs() = 1 then ( execute (a * 10 + 9)->display() ) else (if a = b then ( execute (a * 10)->display() ) else (if a = 9 & b = 1 then ( execute (9)->display() ) else ( execute (-1)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=5 def printHosoya(n): dp=[[0 for i in range(N)]for i in range(N)] dp[0][0]=dp[1][0]=dp[1][1]=1 for i in range(2,n): for j in range(n): if(i>j): dp[i][j]=(dp[i-1][j]+dp[i-2][j]) else : dp[i][j]=(dp[i-1][j-1]+dp[i-2][j-2]) for i in range(n): for j in range(i+1): print(dp[i][j],end=' ') print() n=5 printHosoya(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 5 ; skip ; n := 5 ; printHosoya(n); operation printHosoya(n : OclAny) pre: true post: true activity: var dp : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)))) ; dp->first()->first() := dp->first()->first()(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))) ; for i : Integer.subrange(2, n-1) do ( for j : Integer.subrange(0, n-1) do ( if ((i->compareTo(j)) > 0) then ( dp[i+1][j+1] := (dp[i - 1+1][j+1] + dp[i - 2+1][j+1]) ) else ( dp[i+1][j+1] := (dp[i - 1+1][j - 1+1] + dp[i - 2+1][j - 2+1]) ))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, i + 1-1) do ( execute (dp[i+1][j+1])->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculateDifference(arr,n): max_val=max(arr) prime=(max_val+1)*[True] prime[0]=False prime[1]=False p=2 while p*p<=max_val : if prime[p]==True : for i in range(p*2,max_val+1,p): prime[i]=False p+=1 P1=1 ; P2=1 for i in range(n): if prime[arr[i]]: P1*=arr[i] elif arr[i]!=1 : P2*=arr[i] return abs(P2-P1) if __name__=='__main__' : arr=[1,3,5,10,15,7] n=len(arr) print(calculateDifference(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{10}->union(Sequence{15}->union(Sequence{ 7 }))))) ; n := (arr)->size() ; execute (calculateDifference(arr, n))->display() ) else skip; operation calculateDifference(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var max_val : OclAny := (arr)->max() ; var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (max_val + 1)) ; prime->first() := false ; prime[1+1] := false ; var p : int := 2 ; while (p * p->compareTo(max_val)) <= 0 do ( if prime[p+1] = true then ( for i : Integer.subrange(p * 2, max_val + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip ; p := p + 1) ; var P1 : int := 1; var P2 : int := 1 ; for i : Integer.subrange(0, n-1) do ( if prime[arr[i+1]+1] then ( P1 := P1 * arr[i+1] ) else (if arr[i+1] /= 1 then ( P2 := P2 * arr[i+1] ) else skip)) ; return (P2 - P1)->abs(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(a==0): return b ; if(b==0): return a ; if(a==b): return a ; if(a>b): return gcd(a-b,b); return gcd(a,b-a); def LCM(den,N): ans=den[0]; for i in range(1,N): ans=(((den[i]*ans))/(gcd(den[i],ans))); return ans ; def HCF(num,N): ans=num[0]; for i in range(1,N): ans=gcd(num[i],ans); return ans ; def HCFOfFractions(num,den,N): Numerator=HCF(num,N); Denominator=LCM(den,N); gcd1=gcd(Numerator,Denominator); Numerator=int(Numerator/gcd1); Denominator=int(Denominator/gcd1); print("HCF is=",Numerator,"/",Denominator); num=[24,48,72,96]; den=[2,6,8,3]; N=len(num); HCFOfFractions(num,den,N); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; num := Sequence{24}->union(Sequence{48}->union(Sequence{72}->union(Sequence{ 96 }))); ; den := Sequence{2}->union(Sequence{6}->union(Sequence{8}->union(Sequence{ 3 }))); ; N := (num)->size(); ; HCFOfFractions(num, den, N);; operation gcd(a : OclAny, b : OclAny) pre: true post: true activity: if (a = 0) then ( return b; ) else skip ; if (b = 0) then ( return a; ) else skip ; if (a = b) then ( return a; ) else skip ; if ((a->compareTo(b)) > 0) then ( return gcd(a - b, b); ) else skip ; return gcd(a, b - a);; operation LCM(den : OclAny, N : OclAny) pre: true post: true activity: var ans : OclAny := den->first(); ; for i : Integer.subrange(1, N-1) do ( ans := (((den[i+1] * ans)) / (gcd(den[i+1], ans)));) ; return ans;; operation HCF(num : OclAny, N : OclAny) pre: true post: true activity: ans := num->first(); ; for i : Integer.subrange(1, N-1) do ( ans := gcd(num[i+1], ans);) ; return ans;; operation HCFOfFractions(num : OclAny, den : OclAny, N : OclAny) pre: true post: true activity: var Numerator : OclAny := HCF(num, N); ; var Denominator : OclAny := LCM(den, N); ; var gcd1 : OclAny := gcd(Numerator, Denominator); ; Numerator := ("" + ((Numerator / gcd1)))->toInteger(); ; Denominator := ("" + ((Denominator / gcd1)))->toInteger(); ; execute ("HCF is=")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def PowerOFPINnfactorial(n,p): ans=0 temp=p while(temp<=n): ans+=n/temp temp=temp*p return int(ans) print(PowerOFPINnfactorial(4,2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (PowerOFPINnfactorial(4, 2))->display(); operation PowerOFPINnfactorial(n : OclAny, p : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; var temp : OclAny := p ; while ((temp->compareTo(n)) <= 0) do ( ans := ans + n / temp ; temp := temp * p) ; return ("" + ((ans)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def PowerOFPINnfactorial(n,p): ans=0 ; temp=p ; while(temp<=n): ans+=n/temp ; temp=temp*p ; return ans ; print(PowerOFPINnfactorial(4,2)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (PowerOFPINnfactorial(4, 2))->display();; operation PowerOFPINnfactorial(n : OclAny, p : OclAny) pre: true post: true activity: var ans : int := 0; ; var temp : OclAny := p; ; while ((temp->compareTo(n)) <= 0) do ( ans := ans + n / temp; ; temp := temp * p;) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def catalanDP(n): catalan=[1 for i in range(n+1)] for i in range(2,n+1): catalan[i]=0 for j in range(i): catalan[i]+=(catalan[j]*catalan[i-j-1]) return catalan[n] def countWays(n): if(n & 1): print("Invalid") return 0 return catalanDP(n//2) print(countWays(6)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; execute (countWays(6))->display(); operation catalanDP(n : OclAny) : OclAny pre: true post: true activity: var catalan : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (1)) ; for i : Integer.subrange(2, n + 1-1) do ( catalan[i+1] := 0 ; for j : Integer.subrange(0, i-1) do ( catalan[i+1] := catalan[i+1] + (catalan[j+1] * catalan[i - j - 1+1]))) ; return catalan[n+1]; operation countWays(n : OclAny) : OclAny pre: true post: true activity: if (MathLib.bitwiseAnd(n, 1)) then ( execute ("Invalid")->display() ; return 0 ) else skip ; return catalanDP(n div 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() T=input() s=False for _ in range(len(S)): if S==T : s=True break else : S=S[1 :]+S[0] if s : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var T : String := (OclFile["System.in"]).readLine() ; var s : boolean := false ; for _anon : Integer.subrange(0, (S)->size()-1) do ( if S = T then ( s := true ; break ) else ( S := S->tail() + S->first() )) ; if s then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import string x=input() y=input() alpha=string.ascii_lowercase ans="" for i in range(len(x)): if alpha.index(x[i])==alpha.index(y[i]): ans+=x[i] elif alpha.index(x[i])>alpha.index(y[i]): ans+=y[i] else : ans=-1 break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : String := (OclFile["System.in"]).readLine() ; var y : String := (OclFile["System.in"]).readLine() ; var alpha : OclAny := string.ascii_lowercase ; var ans : String := "" ; for i : Integer.subrange(0, (x)->size()-1) do ( if alpha->indexOf(x[i+1]) - 1 = alpha->indexOf(y[i+1]) - 1 then ( ans := ans + x[i+1] ) else (if (alpha->indexOf(x[i+1]) - 1->compareTo(alpha->indexOf(y[i+1]) - 1)) > 0 then ( ans := ans + y[i+1] ) else ( ans := -1 ; break ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans=[] while 1 : b=int(input()) if b==0 : break x=1 res=(1,1) while x*x<=b : if b % x==0 : y=b//x if x % 2==1 : if y-x//2>=1 : res=max(res,(x,y-x//2)) if x//2-y+1>=1 : res=max(res,(2*y,x//2-y+1)) if y % 2==1 : if x-y//2>=1 : res=max(res,(y,x-y//2)) if y//2-x+1>=1 : res=max(res,(2*x,y//2-x+1)) x+=1 b,a=res ans.append("%d %d" %(a,b)) print(*ans,sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ans : Sequence := Sequence{} ; while 1 do ( var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if b = 0 then ( break ) else skip ; var x : int := 1 ; var res : OclAny := Sequence{1, 1} ; while (x * x->compareTo(b)) <= 0 do ( if b mod x = 0 then ( var y : int := b div x ; if x mod 2 = 1 then ( if y - x div 2 >= 1 then ( res := Set{res, Sequence{x, y - x div 2}}->max() ) else skip ; if x div 2 - y + 1 >= 1 then ( res := Set{res, Sequence{2 * y, x div 2 - y + 1}}->max() ) else skip ) else skip ; if y mod 2 = 1 then ( if x - y div 2 >= 1 then ( res := Set{res, Sequence{y, x - y div 2}}->max() ) else skip ; if y div 2 - x + 1 >= 1 then ( res := Set{res, Sequence{2 * x, y div 2 - x + 1}}->max() ) else skip ) else skip ) else skip ; x := x + 1) ; var a : OclAny := null; Sequence{b,a} := res ; execute ((StringLib.format("%d %d",Sequence{a, b})) : ans)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function import sys import re import array import copy import functools import operator import math import string import fractions from fractions import Fraction from fractions import gcd import collections import itertools import bisect import random import time import heapq from heapq import heappush from heapq import heappop from heapq import heappushpop from heapq import heapify from heapq import heapreplace from queue import PriorityQueue as pq from queue import Queue from itertools import accumulate from collections import deque from collections import Counter from operator import mul from functools import reduce input=sys.stdin.readline def eprint(*args,**kwargs): print(*args,file=sys.stderr,**kwargs) return def lcm(n,m): return int(n*m/gcd(n,m)) def coprimize(p,q): common=fractions.gcd(p,q) return(p//common,q//common) def combinations_count(n,r): r=min(r,n-r) numer=reduce(mul,range(n,n-r,-1),1) denom=reduce(mul,range(1,r+1),1) return numer//denom def find_gcd(list_l): x=reduce(gcd,list_l) return x def main(): S=input().strip() T=input().strip() for i in range(len(S)+1): temp="" for j in range(len(S)): temp+=S[(j+1)% len(S)] S=temp if T==temp : print("Yes") return print("No") return if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation eprint(args : OclAny : Sequence(OclAny), kwargs : OclAny : Map(String, OclAny)) pre: true post: true activity: (args * (named_parameter (name args)))(kwargs ** (named_parameter (name kwargs))) execute ((argument * (test (logical_test (comparison (expr (atom (name args))))))))->display() ; return; operation lcm(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: return ("" + ((n * m / gcd(n, m))))->toInteger(); operation coprimize(p : OclAny, q : OclAny) : OclAny pre: true post: true activity: var common : int := fractions.gcd(p, q) ; return Sequence{p div common, q div common}; operation combinations_count(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: r := Set{r, n - r}->min() ; var numer : OclAny := reduce(mul, Integer.subrange(n - r + 1, n)->reverse(), 1) ; var denom : OclAny := reduce(mul, Integer.subrange(1, r + 1-1), 1) ; return numer div denom; operation find_gcd(list_l : OclAny) : OclAny pre: true post: true activity: var x : OclAny := reduce(gcd, list_l) ; return x; operation main() pre: true post: true activity: var S : OclAny := input()->trim() ; var T : OclAny := input()->trim() ; for i : Integer.subrange(0, (S)->size() + 1-1) do ( var temp : String := "" ; for j : Integer.subrange(0, (S)->size()-1) do ( temp := temp + S[(j + 1) mod (S)->size()+1]) ; S := temp ; if T = temp then ( execute ("Yes")->display() ; return ) else skip) ; execute ("No")->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) if b in(a,a+1)or(a,b)==(9,1): a=[a,a*10][a==b]; print(a,a+1) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (Sequence{a, a + 1})->includes(b) or Sequence{a, b} = Sequence{9, 1} then ( var a : OclAny := Sequence{a}->union(Sequence{ a * 10 })->select(a = b); execute (a)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque s=deque(input()) t=deque(input()) for i in range(len(s)): s1=s.popleft() s.append(s1) if s==t : print('Yes') exit() print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : Sequence := ((OclFile["System.in"]).readLine()) ; var t : Sequence := ((OclFile["System.in"]).readLine()) ; for i : Integer.subrange(0, (s)->size()-1) do ( var s1 : OclAny := s->first() ; s := s->tail() ; execute ((s1) : s) ; if s = t then ( execute ('Yes')->display() ; exit() ) else skip) ; execute ('No')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input()*2 t=input() print("Yes" if t in s else "No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : double := (OclFile["System.in"]).readLine() * 2 ; var t : String := (OclFile["System.in"]).readLine() ; execute (if (s)->includes(t) then "Yes" else "No" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=list(input()) T=input() s_tmp=S.copy() if ''.join(S)==T : print('Yes') else : while True : s_reversed=s_tmp[:-1] s_reversed.insert(0,s_tmp[-1]) if ''.join(s_tmp)==T : print('Yes') break elif S==s_reversed : print('No') break s_tmp=s_reversed ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var T : String := (OclFile["System.in"]).readLine() ; var s_tmp : OclAny := S->copy() ; if StringLib.sumStringsWithSeparator((S), '') = T then ( execute ('Yes')->display() ) else ( while true do ( var s_reversed : OclAny := s_tmp->front() ; s_reversed := s_reversed.insertAt(0+1, s_tmp->last()) ; if StringLib.sumStringsWithSeparator((s_tmp), '') = T then ( execute ('Yes')->display() ; break ) else (if S = s_reversed then ( execute ('No')->display() ; break ) else skip) ; s_tmp := s_reversed) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sortWithRemainderP(arr,n,k,p): v1=[] v2=[] for i in range(0,n,1): if(arr[i]% k==p): v1.append(i) v2.append(arr[i]) v2.sort(reverse=False) for i in range(0,len(v1),1): arr[v1[i]]=v2[i] for i in range(0,n,1): print(arr[i],end=" ") if __name__=='__main__' : arr=[8,255,16,2,4,0] n=len(arr) k=2 p=0 sortWithRemainderP(arr,n,k,p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{8}->union(Sequence{255}->union(Sequence{16}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 0 }))))) ; n := (arr)->size() ; k := 2 ; p := 0 ; sortWithRemainderP(arr, n, k, p) ) else skip; operation sortWithRemainderP(arr : OclAny, n : OclAny, k : OclAny, p : OclAny) pre: true post: true activity: var v1 : Sequence := Sequence{} ; var v2 : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (arr[i+1] mod k = p) then ( execute ((i) : v1) ; execute ((arr[i+1]) : v2) ) else skip) ; v2 := v2->sort() ; for i : Integer.subrange(0, (v1)->size()-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( arr[v1[i+1]+1] := v2[i+1]) ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countStrs(n): dp=[[0 for j in range(27)]for i in range(n+1)] for i in range(0,26): dp[1][i]=1 for i in range(2,n+1): for j in range(0,26): if(j==0): dp[i][j]=dp[i-1][j+1]; else : dp[i][j]=(dp[i-1][j-1]+dp[i-1][j+1]) sum=0 for i in range(0,26): sum=sum+dp[n][i] return sum if __name__=="__main__" : n=3 print("Total strings are : ",countStrs(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 3 ; execute ("Total strings are : ")->display() ) else skip; operation countStrs(n : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, 27-1)->select(j | true)->collect(j | (0)))) ; for i : Integer.subrange(0, 26-1) do ( dp[1+1][i+1] := 1) ; for i : Integer.subrange(2, n + 1-1) do ( for j : Integer.subrange(0, 26-1) do ( if (j = 0) then ( dp[i+1][j+1] := dp[i - 1+1][j + 1+1]; ) else ( dp[i+1][j+1] := (dp[i - 1+1][j - 1+1] + dp[i - 1+1][j + 1+1]) ))) ; var sum : int := 0 ; for i : Integer.subrange(0, 26-1) do ( sum := sum + dp[n+1][i+1]) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isValidISBN(isbn): if len(isbn)!=10 : return False _sum=0 for i in range(9): if 0<=int(isbn[i])<=9 : _sum+=int(isbn[i])*(10-i) else : return False if(isbn[9]!='X' and 0<=int(isbn[9])<=9): return False _sum+=10 if isbn[9]=='X' else int(isbn[9]) return(_sum % 11==0) isbn="007462542X" if isValidISBN(isbn): print('Valid') else : print("Invalid") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; isbn := "007462542X" ; if isValidISBN(isbn) then ( execute ('Valid')->display() ) else ( execute ("Invalid")->display() ); operation isValidISBN(isbn : OclAny) : OclAny pre: true post: true activity: if (isbn)->size() /= 10 then ( return false ) else skip ; var _sum : int := 0 ; for i : Integer.subrange(0, 9-1) do ( if 0 <= ("" + ((isbn[i+1])))->toInteger() & (("" + ((isbn[i+1])))->toInteger() <= 9) then ( _sum := _sum + ("" + ((isbn[i+1])))->toInteger() * (10 - i) ) else ( return false )) ; if (isbn[9+1] /= 'X' & 0 <= ("" + ((isbn[9+1])))->toInteger() & (("" + ((isbn[9+1])))->toInteger() <= 9)) then ( return false ) else skip ; _sum := _sum + if isbn[9+1] = 'X' then 10 else ("" + ((isbn[9+1])))->toInteger() endif ; return (_sum mod 11 = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def is_power_of_two(n): return 0 if(n &(n-1))else 1 ; def countSubArrays(arr,n): cnt=0 ; for j in range(n): xorval=0 ; for k in range(j,n): num=1<union(Sequence{2}->union(Sequence{3}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })))))); ; n := (arr)->size(); ; execute (countSubArrays(arr, n))->display();; operation is_power_of_two(n : OclAny) pre: true post: true activity: return if (MathLib.bitwiseAnd(n, (n - 1))) then 0 else 1 endif;; operation countSubArrays(arr : OclAny, n : OclAny) pre: true post: true activity: var cnt : int := 0; ; for j : Integer.subrange(0, n-1) do ( var xorval : int := 0; ; for k : Integer.subrange(j, n-1) do ( var num : int := 1 * (2->pow(arr[k+1])); ; xorval := xorval xor num; ; if (xorval = 0 or is_power_of_two(xorval)) then ( cnt := cnt + 1; ) else skip)) ; return cnt;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M,C=map(int,input().split()) *L,=map(int,input().split()) B=[] for i in range(N): c,w=map(int,input().split()) B.append((w,c)) B.sort(reverse=1) ans=0 for w,c in B : if L[c-1]>0 : ans+=w M-=1 if M==0 : break L[c-1]-=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; var C : OclAny := null; Sequence{N,M,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (testlist_star_expr (star_expr * (expr (atom (name L)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name L)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var B : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var c : OclAny := null; var w : OclAny := null; Sequence{c,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{w, c}) : B)) ; B := B->sort() ; var ans : int := 0 ; for _tuple : B do (var _indx : int := 1; var w : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if L[c - 1+1] > 0 then ( ans := ans + w ; M := M - 1 ; if M = 0 then ( break ) else skip ; L[c - 1+1] := L[c - 1+1] - 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq n,m,c=map(int,input().split()) que=[[]for i in range(c+1)] can_buy=[0]+list(map(int,input().split())) for i in range(n): c,w=map(int,input().split()) heapq.heappush(que[c],w) if len(que[c])>can_buy[c]: heapq.heappop(que[c]) line=[j for i in que for j in i] line.sort() ans=sum(line[-m :]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; var c : OclAny := null; Sequence{n,m,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var que : Sequence := Integer.subrange(0, c + 1-1)->select(i | true)->collect(i | (Sequence{})) ; var can_buy : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; for i : Integer.subrange(0, n-1) do ( var c : OclAny := null; var w : OclAny := null; Sequence{c,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; heapq.heappush(que[c+1], w) ; if ((que[c+1])->size()->compareTo(can_buy[c+1])) > 0 then ( heapq.heappop(que[c+1]) ) else skip) ; var line : Sequence := que->select(i; j : i | true)->collect(i; j : i | (j)) ; line := line->sort() ; var ans : OclAny := (line.subrange(-m+1))->sum() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def binary_search(num,start,end,l): if start==end : return start tmp=(start+end)//2 if l[tmp]<=num : return binary_search(num,tmp+1,end,l) else : return binary_search(num,start,tmp,l) def main(): MAX=int(1e9) check_list=[0] tmp=0 i=1 while True : tmp+=i if tmpcompareTo(num)) <= 0 then ( return binary_search(num, tmp + 1, end, l) ) else ( return binary_search(num, start, tmp, l) ); operation main() pre: true post: true activity: var MAX : int := ("" + ((("1e9")->toReal())))->toInteger() ; var check_list : Sequence := Sequence{ 0 } ; tmp := 0 ; var i : int := 1 ; while true do ( tmp := tmp + i ; if (tmp->compareTo(MAX)) < 0 then ( execute ((tmp) : check_list) ; i := i + 1 ) else ( break )) ; var len_ : int := (check_list)->size() ; while true do ( var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if b = 0 then ( break ) else skip ; var ans : int := 0 ; start := binary_search(b, 0, len_ - 1, check_list) ; for i : Integer.subrange(0 + 1, start)->reverse() do ( if (check_list[i+1]->compareTo(b)) <= 0 then ( tmp := (b - check_list[i+1]) mod i ; if tmp = 0 then ( execute ((b - check_list[i+1]) div i + 1)->display() ; break ) else skip ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- da,db=map(int,input().split(' ')) if db-da==1 : print(str(da)+" "+str(db)) elif db==da : print(str(da)+"0"+" "+str(db)+"1") elif db==1 and da==9 : print(str(da)+" "+str(db)+"0") else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var da : OclAny := null; var db : OclAny := null; Sequence{da,db} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; if db - da = 1 then ( execute (("" + ((da))) + " " + ("" + ((db))))->display() ) else (if db = da then ( execute (("" + ((da))) + "0" + " " + ("" + ((db))) + "1")->display() ) else (if db = 1 & da = 9 then ( execute (("" + ((da))) + " " + ("" + ((db))) + "0")->display() ) else ( execute (-1)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def inpl(): return list(map(int,input().split())) N,M,C=inpl() L={i+1 : v for i,v in enumerate(inpl())} balls=[] for _ in range(N): c,w=inpl() balls.append([w,c]) balls=sorted(balls,reverse=True) i=0 count=0 ans=0 for i in range(N): w,c=balls[i] if count==M : break if L[c]==0 : continue else : count+=1 ans+=w L[c]-=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; var C : OclAny := null; Sequence{N,M,C} := inpl() ; var L : Map := Integer.subrange(1, (inpl())->size())->collect( _indx | Sequence{_indx-1, (inpl())->at(_indx)} )->select(_tuple | true)->collect(_tuple | Map{i + 1 |-> v})->unionAll() ; var balls : Sequence := Sequence{} ; for _anon : Integer.subrange(0, N-1) do ( var c : OclAny := null; var w : OclAny := null; Sequence{c,w} := inpl() ; execute ((Sequence{w}->union(Sequence{ c })) : balls)) ; balls := balls->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var i : int := 0 ; var count : int := 0 ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( var w : OclAny := null; var c : OclAny := null; Sequence{w,c} := balls[i+1] ; if count = M then ( break ) else skip ; if L[c+1] = 0 then ( continue ) else ( count := count + 1 ; ans := ans + w ; L[c+1] := L[c+1] - 1 )) ; execute (ans)->display(); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M,C=map(int,input().split()) colors=[int(l)for l in input().split()] ball=[] for _ in range(0,N): c,w=map(int,input().split()) ball.append([c,w]) ball.sort(key=lambda x : x[1]) ball.reverse() take=0 cost=0 i=0 while(take<=M-1)and(i<=N-1): if colors[ball[i][0]-1]==0 : i+=1 continue else : cost=cost+ball[i][1] colors[ball[i][0]-1]=colors[ball[i][0]-1]-1 take+=1 i+=1 print(cost) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; var C : OclAny := null; Sequence{N,M,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var colors : Sequence := input().split()->select(l | true)->collect(l | (("" + ((l)))->toInteger())) ; var ball : Sequence := Sequence{} ; for _anon : Integer.subrange(0, N-1) do ( var c : OclAny := null; var w : OclAny := null; Sequence{c,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{c}->union(Sequence{ w })) : ball)) ; ball := ball->sort() ; ball := ball->reverse() ; var take : int := 0 ; var cost : int := 0 ; var i : int := 0 ; while ((take->compareTo(M - 1)) <= 0) & ((i->compareTo(N - 1)) <= 0) do ( if colors[ball[i+1]->first() - 1+1] = 0 then ( i := i + 1 ; continue ) else ( cost := cost + ball[i+1][1+1] ; colors[ball[i+1]->first() - 1+1] := colors[ball[i+1]->first() - 1+1] - 1 ; take := take + 1 ; i := i + 1 )) ; execute (cost)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,c=map(int,input().split()) l=[0]+list(map(int,input().split())) w=[tuple(map(int,input().split()))for _ in range(n)] w.sort(key=lambda x : x[1],reverse=True) v=0 p=0 for i in range(n): if l[w[i][0]]: l[w[i][0]]-=1 v+=w[i][1] p+=1 if p==m : break print(v) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var c : OclAny := null; Sequence{n,m,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var w : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; w := w->sort() ; var v : int := 0 ; var p : int := 0 ; for i : Integer.subrange(0, n-1) do ( if l[w[i+1]->first()+1] then ( l[w[i+1]->first()+1] := l[w[i+1]->first()+1] - 1 ; v := v + w[i+1][1+1] ; p := p + 1 ; if p = m then ( break ) else skip ) else skip) ; execute (v)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline a=set() b=set() x,k=map(int,input().split()) for i in range(k): w=list(map(int,input().split())) if w[0]==1 : a.add(w[1]) b.add(w[2]) else : a.add(w[1]) c=set(range(1,x)) c=c-a-b c=sorted(c) c2=len(c) c1=0 i=0 while iunion(()) ; var b : Set := Set{}->union(()) ; var x : OclAny := null; var k : OclAny := null; Sequence{x,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, k-1) do ( var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if w->first() = 1 then ( execute ((w[1+1]) : a) ; execute ((w[2+1]) : b) ) else ( execute ((w[1+1]) : a) )) ; var c : Set := Set{}->union((Integer.subrange(1, x-1))) ; c := c - a - b ; c := c->sort() ; var c2 : int := (c)->size() ; var c1 : int := 0 ; var i : int := 0 ; while (i->compareTo(c2 - 1)) < 0 do ( if c[i+1] = c[i + 1+1] - 1 then ( c1 := c1 + 1 ; i := i + 1 ) else skip ; i := i + 1) ; execute (c2 - c1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,k=[int(i)for i in input().split()] missed=[0]*x for i in range(k): divs=[int(i)for i in input().split()] if divs[0]==1 : missed[divs[1]]=1 missed[divs[2]]=1 else : missed[divs[1]]=1 max_answer=missed.count(0)-1 good_subarrs=0 i=1 while i<=x-1 : if iselect(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var missed : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, x) ; for i : Integer.subrange(0, k-1) do ( var divs : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if divs->first() = 1 then ( missed[divs[1+1]+1] := 1 ; missed[divs[2+1]+1] := 1 ) else ( missed[divs[1+1]+1] := 1 )) ; var max_answer : double := missed->count(0) - 1 ; var good_subarrs : int := 0 ; var i : int := 1 ; while (i->compareTo(x - 1)) <= 0 do ( if (i->compareTo(x - 1)) < 0 & missed[i+1] = 0 & missed[i + 1+1] = 0 then ( good_subarrs := good_subarrs + 1 ; i := i + 2 ) else ( i := i + 1 )) ; execute (max_answer - good_subarrs)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys inp=sys.stdin.readlines(); ii=0 out=[] x,k=map(int,inp[ii].split()) ii+=1 roundshappened=[] for round in range(k): data=[int(d)for d in inp[ii].split()] ii+=1 for d in data[1 :]: roundshappened.append(d) skipped=[] for x in range(1,x): if x not in roundshappened : skipped.append(x) used=[] minimum=0 for i in range(1,len(skipped)): if skipped[i-1]+1==skipped[i]and skipped[i]not in used and skipped[i-1]not in used : minimum+=1 used.append(skipped[i-1]) used.append(skipped[i]) minimum+=len(skipped)-len(used) maximum=len(skipped) sys.stdout.write(str(minimum)+' '+str(maximum)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var inp : OclAny := (OclFile["System.in"]).readlines(); var ii : int := 0 ; var out : Sequence := Sequence{} ; var x : OclAny := null; var k : OclAny := null; Sequence{x,k} := (inp[ii+1].split())->collect( _x | (OclType["int"])->apply(_x) ) ; ii := ii + 1 ; var roundshappened : Sequence := Sequence{} ; for round : Integer.subrange(0, k-1) do ( var data : Sequence := inp[ii+1].split()->select(d | true)->collect(d | (("" + ((d)))->toInteger())) ; ii := ii + 1 ; for d : data->tail() do ( execute ((d) : roundshappened))) ; var skipped : Sequence := Sequence{} ; for x : Integer.subrange(1, x-1) do ( if (roundshappened)->excludes(x) then ( execute ((x) : skipped) ) else skip) ; var used : Sequence := Sequence{} ; var minimum : int := 0 ; for i : Integer.subrange(1, (skipped)->size()-1) do ( if skipped[i - 1+1] + 1 = skipped[i+1] & (used)->excludes(skipped[i+1]) & (used)->excludes(skipped[i - 1+1]) then ( minimum := minimum + 1 ; execute ((skipped[i - 1+1]) : used) ; execute ((skipped[i+1]) : used) ) else skip) ; minimum := minimum + (skipped)->size() - (used)->size() ; var maximum : int := (skipped)->size() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name minimum)))))))) )))) + (expr (atom ' '))) + (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name maximum)))))))) )))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def STR(): return list(input()) def INT(): return int(input()) def MAP(): return map(int,input().split()) def MAP2(): return map(float,input().split()) def LIST(): return list(map(int,input().split())) def STRING(): return input() import string import sys from heapq import heappop,heappush from bisect import* from collections import deque,Counter,defaultdict from math import* from itertools import permutations,accumulate dx=[-1,1,0,0] dy=[0,0,1,-1] x,k=MAP() if k==0 : x-=1 print(ceil(x/2),x) exit(0) visited=[0]*(x+9) visited[x]=1 for i in range(k): l=LIST() visited[l[1]]=1 if len(l)==3 : visited[l[2]]=1 mn,mx=0,0 v=[] for i in range(1,x): if visited[i]==0 : v.append(i) mx+=1 if len(v)!=0 : prev=v[0] mn=1 for i in range(1,len(v)): if v[i]-prev!=1 : prev=v[i] mn+=1 else : continue print(mn,mx) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var dx : Sequence := Sequence{-1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 0 }))) ; var dy : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ -1 }))) ; var x : OclAny := null; var k : OclAny := null; Sequence{x,k} := MAP() ; if k = 0 then ( x := x - 1 ; execute (ceil(x / 2))->display() ; exit(0) ) else skip ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (x + 9)) ; visited[x+1] := 1 ; for i : Integer.subrange(0, k-1) do ( var l : OclAny := LIST() ; visited[l[1+1]+1] := 1 ; if (l)->size() = 3 then ( visited[l[2+1]+1] := 1 ) else skip) ; var mn : OclAny := null; var mx : OclAny := null; Sequence{mn,mx} := Sequence{0,0} ; var v : Sequence := Sequence{} ; for i : Integer.subrange(1, x-1) do ( if visited[i+1] = 0 then ( execute ((i) : v) ; mx := mx + 1 ) else skip) ; if (v)->size() /= 0 then ( var prev : OclAny := v->first() ; var mn : int := 1 ; for i : Integer.subrange(1, (v)->size()-1) do ( if v[i+1] - prev /= 1 then ( prev := v[i+1] ; mn := mn + 1 ) else ( continue )) ) else skip ; execute (mn)->display(); operation STR() : OclAny pre: true post: true activity: return ((OclFile["System.in"]).readLine())->characters(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation MAP2() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["double"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation STRING() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=lambda : map(int,input().split()) x,k=I() R=[0,x] for _ in range(k): _,*r=I() R+=r R.sort() max_=min_=0 for i in range(len(R)-1): min_+=(R[i+1]-R[i])//2 max_+=R[i+1]-R[i]-1 print(min_,max_) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := null; var k : OclAny := null; Sequence{x,k} := I->apply() ; var R : Sequence := Sequence{0}->union(Sequence{ x }) ; for _anon : Integer.subrange(0, k-1) do ( var _anon : OclAny := null; var r : OclAny := null; Sequence{_anon,r} := I->apply() ; R := R + r) ; R := R->sort() ; var max_ : OclAny := 0; var min_ : int := 0 ; for i : Integer.subrange(0, (R)->size() - 1-1) do ( min_ := min_ + (R[i + 1+1] - R[i+1]) div 2 ; max_ := max_ + R[i + 1+1] - R[i+1] - 1) ; execute (min_)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math ; def sieve(primes,x): primes[1]=False ; i=2 ; while(i*i<=x): if(primes[i]==True): j=2 ; while(j*i<=x): primes[i*j]=False ; j+=1 ; i+=1 ; def nDivisors(primes,x,a,b,n): result=0 ; v=[]; for i in range(2,x+1): if(primes[i]): v.append(i); for i in range(a,b+1): temp=i ; total=1 ; j=0 ; k=v[j]; while(k*k<=temp): count=0 ; while(temp % k==0): count+=1 ; temp=int(temp/k); total=total*(count+1); j+=1 ; k=v[j]; if(temp!=1): total=total*2 ; if(total==n): result+=1 ; return result ; def countNDivisors(a,b,n): x=int(math.sqrt(b)+1); primes=[True]*(x+1); sieve(primes,x); return nDivisors(primes,x,a,b,n); a=1 ; b=7 ; n=2 ; print(countNDivisors(a,b,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; ; skip ; skip ; skip ; a := 1; ; b := 7; ; n := 2; ; execute (countNDivisors(a, b, n))->display();; operation sieve(primes : OclAny, x : OclAny) pre: true post: true activity: primes[1+1] := false; ; var i : int := 2; ; while ((i * i->compareTo(x)) <= 0) do ( if (primes[i+1] = true) then ( var j : int := 2; ; while ((j * i->compareTo(x)) <= 0) do ( primes[i * j+1] := false; ; j := j + 1;) ) else skip ; i := i + 1;); operation nDivisors(primes : OclAny, x : OclAny, a : OclAny, b : OclAny, n : OclAny) pre: true post: true activity: var result : int := 0; ; var v : Sequence := Sequence{}; ; for i : Integer.subrange(2, x + 1-1) do ( if (primes[i+1]) then ( execute ((i) : v); ) else skip) ; for i : Integer.subrange(a, b + 1-1) do ( var temp : int := i; ; var total : int := 1; ; j := 0; ; var k : OclAny := v[j+1]; ; while ((k * k->compareTo(temp)) <= 0) do ( var count : int := 0; ; while (temp mod k = 0) do ( count := count + 1; ; temp := ("" + ((temp / k)))->toInteger();) ; total := total * (count + 1); ; j := j + 1; ; k := v[j+1];) ; if (temp /= 1) then ( total := total * 2; ) else skip ; if (total = n) then ( result := result + 1; ) else skip) ; return result;; operation countNDivisors(a : OclAny, b : OclAny, n : OclAny) pre: true post: true activity: x := ("" + (((b)->sqrt() + 1)))->toInteger(); ; primes := MatrixLib.elementwiseMult(Sequence{ true }, (x + 1)); ; sieve(primes, x); ; return nDivisors(primes, x, a, b, n);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def isPrime(n): i,c=0,0 for i in range(1,n//2): if(n % i==0): c+=1 if(c==1): return 1 else : return 0 def findMinNum(arr,n): first,last=0,0 Hash=[0 for i in range(10)] for i in range(n): Hash[arr[i]]+=1 print("Minimum number: ",end="") for i in range(0,10): for j in range(Hash[i]): print(i,end="") print() for i in range(10): if(Hash[i]!=0): first=i break for i in range(9,-1,-1): if(Hash[i]!=0): last=i break num=first*10+last rev=last*10+first print("Prime combinations: ",end="") if(isPrime(num)and isPrime(rev)): print(num," ",rev) elif(isPrime(num)): print(num) elif(isPrime(rev)): print(rev) else : print("No combinations exist") arr=[1,2,4,7,8] findMinNum(arr,5) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{7}->union(Sequence{ 8 })))) ; findMinNum(arr, 5); operation isPrime(n : OclAny) : OclAny pre: true post: true activity: var i : OclAny := null; var c : OclAny := null; Sequence{i,c} := Sequence{0,0} ; for i : Integer.subrange(1, n div 2-1) do ( if (n mod i = 0) then ( c := c + 1 ) else skip) ; if (c = 1) then ( return 1 ) else ( return 0 ); operation findMinNum(arr : OclAny, n : OclAny) pre: true post: true activity: var first : OclAny := null; var last : OclAny := null; Sequence{first,last} := Sequence{0,0} ; var Hash : Sequence := Integer.subrange(0, 10-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( Hash[arr[i+1]+1] := Hash[arr[i+1]+1] + 1) ; execute ("Minimum number: ")->display() ; for i : Integer.subrange(0, 10-1) do ( for j : Integer.subrange(0, Hash[i+1]-1) do ( execute (i)->display())) ; execute (->display() ; for i : Integer.subrange(0, 10-1) do ( if (Hash[i+1] /= 0) then ( var first : OclAny := i ; break ) else skip) ; for i : Integer.subrange(-1 + 1, 9)->reverse() do ( if (Hash[i+1] /= 0) then ( var last : OclAny := i ; break ) else skip) ; var num : double := first * 10 + last ; var rev : double := last * 10 + first ; execute ("Prime combinations: ")->display() ; if (isPrime(num) & isPrime(rev)) then ( execute (num)->display() ) else (if (isPrime(num)) then ( execute (num)->display() ) else (if (isPrime(rev)) then ( execute (rev)->display() ) else ( execute ("No combinations exist")->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): for _ in range(int(input())): a,b=list(map(int,input().split())) a,b=min(a,b),max(a,b) counter=0 while a>0 and b>0 : divisor=b//a counter+=divisor b-=divisor*a a,b=b,a print(counter) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{Set{a, b}->min(),Set{a, b}->max()} ; var counter : int := 0 ; while a > 0 & b > 0 do ( var divisor : int := b div a ; counter := counter + divisor ; b := b - divisor * a ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a}) ; execute (counter)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,input().split()) xlist,ylist,xylist=[],[],[] xyset=set() xydic={} yxdic={} for i in range(N): x,y=map(int,input().split()) xlist.append(x) ylist.append(y) xylist.append((x,y)) xyset.add((x,y)) xydic[x]=y yxdic[y]=x xy_prod_list=[] for x in xlist : for y in ylist : xy_prod_list.append((x,y)) xy_prod_list.sort() num_ld_dic={} for xx,yy in xy_prod_list : num_ld=0 for x,y in xylist : if x<=xx and y<=yy : num_ld+=1 num_ld_dic[(xx,yy)]=num_ld answer=float("inf") for i in range(len(xy_prod_list)): x1,y1=xy_prod_list[i] for j in range(len(xy_prod_list)): x2,y2=xy_prod_list[j] if x1>=x2 or y1>=y2 : continue area=(x2-x1)*(y2-y1) if area>answer : continue num_point=num_ld_dic[(x2,y2)]-num_ld_dic[(x1,y2)]-num_ld_dic[(x2,y1)]+num_ld_dic[(x1,y1)] if(x1,y1)in xyset : num_point+=1 else : xx=yxdic[y1] if x1<=xx<=x2 : num_point+=1 yy=xydic[x1] if y1<=yy<=y2 : num_point+=1 if num_point>=K : answer=min(answer,area) print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var xlist : OclAny := null; var ylist : OclAny := null; var xylist : OclAny := null; Sequence{xlist,ylist,xylist} := Sequence{Sequence{},Sequence{},Sequence{}} ; var xyset : Set := Set{}->union(()) ; var xydic : OclAny := Set{} ; var yxdic : OclAny := Set{} ; for i : Integer.subrange(0, N-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((x) : xlist) ; execute ((y) : ylist) ; execute ((Sequence{x, y}) : xylist) ; execute ((Sequence{x, y}) : xyset) ; xydic[x+1] := y ; yxdic[y+1] := x) ; var xy_prod_list : Sequence := Sequence{} ; for x : xlist do ( for y : ylist do ( execute ((Sequence{x, y}) : xy_prod_list))) ; xy_prod_list := xy_prod_list->sort() ; var num_ld_dic : OclAny := Set{} ; for _tuple : xy_prod_list do (var _indx : int := 1; var xx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var yy : OclAny := _tuple->at(_indx); var num_ld : int := 0 ; for _tuple : xylist do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if (x->compareTo(xx)) <= 0 & (y->compareTo(yy)) <= 0 then ( num_ld := num_ld + 1 ) else skip) ; num_ld_dic[Sequence{xx, yy}+1] := num_ld) ; var answer : double := ("" + (("inf")))->toReal() ; for i : Integer.subrange(0, (xy_prod_list)->size()-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := xy_prod_list[i+1] ; for j : Integer.subrange(0, (xy_prod_list)->size()-1) do ( var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x2,y2} := xy_prod_list[j+1] ; if (x1->compareTo(x2)) >= 0 or (y1->compareTo(y2)) >= 0 then ( continue ) else skip ; var area : double := (x2 - x1) * (y2 - y1) ; if (area->compareTo(answer)) > 0 then ( continue ) else skip ; var num_point : double := num_ld_dic[Sequence{x2, y2}+1] - num_ld_dic[Sequence{x1, y2}+1] - num_ld_dic[Sequence{x2, y1}+1] + num_ld_dic[Sequence{x1, y1}+1] ; if (xyset)->includes(Sequence{x1, y1}) then ( num_point := num_point + 1 ) else ( var xx : OclAny := yxdic[y1+1] ; if (x1->compareTo(xx)) <= 0 & (xx <= x2) then ( num_point := num_point + 1 ) else skip ; var yy : OclAny := xydic[x1+1] ; if (y1->compareTo(yy)) <= 0 & (yy <= y2) then ( num_point := num_point + 1 ) else skip ) ; if (num_point->compareTo(K)) >= 0 then ( answer := Set{answer, area}->min() ) else skip)) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt li=[] for i in range(10000): n=int(input()) if n>0 : m=2*n b=int(sqrt(2*m)) for i in range(b,0,-1): if m % i==0 : A=(m/i+1-i) if A % 2==0 and A>0 : a=int(A/2) li.append([a,i]) break if n==0 : break for hoge in li : print(*hoge) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var li : Sequence := Sequence{} ; for i : Integer.subrange(0, 10000-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n > 0 then ( var m : int := 2 * n ; var b : int := ("" + ((sqrt(2 * m))))->toInteger() ; for i : Integer.subrange(0 + 1, b)->reverse() do ( if m mod i = 0 then ( var A : double := (m / i + 1 - i) ; if A mod 2 = 0 & A > 0 then ( var a : int := ("" + ((A / 2)))->toInteger() ; execute ((Sequence{a}->union(Sequence{ i })) : li) ; break ) else skip ) else skip) ) else skip ; if n = 0 then ( break ) else skip) ; for hoge : li do ( execute ((argument * (test (logical_test (comparison (expr (atom (name hoge))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(s,m): l=len(s); c1=0 ; c2=0 ; for i in range(0,l-1): if(s[i]=='0'): c2=0 ; c1=c1+1 ; else : c1=0 ; c2=c2+1 ; if(c1==m or c2==m): return True ; return False ; s="001001" ; m=2 ; if(check(s,m)): print("YES"); else : print("NO"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := "001001"; ; m := 2; ; if (check(s, m)) then ( execute ("YES")->display(); ) else ( execute ("NO")->display(); ); operation check(s : OclAny, m : OclAny) pre: true post: true activity: var l : int := (s)->size(); ; var c1 : int := 0; ; var c2 : int := 0; ; for i : Integer.subrange(0, l - 1-1) do ( if (s[i+1] = '0') then ( c2 := 0; ; c1 := c1 + 1; ) else ( c1 := 0; ; c2 := c2 + 1; ) ; if (c1 = m or c2 = m) then ( return true; ) else skip) ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): r,t=map(int,input().split()) if t % 30==0 : if r % 100==0 : print(int((t/30)*5+r/100)) else : print(int((t/30)*5+1+int((r-100)/100)),int((t/30)*5+int((r-100)/100)+2)) else : if r % 100==0 : print(int(int(t/30)*5+1+int((r-100)/100)),int(int(t/30)*5+int((r-100)/100)+6)) else : print(int(int((t)/30)*5+1+int((r-100)/100)),int(int((t)/30)*5+int((r-100)/100)+2),end=" ") print(int(int((t)/30)*5+6+int((r-100)/100)),int(int((t)/30)*5+int((r-100)/100)+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var r : OclAny := null; var t : OclAny := null; Sequence{r,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if t mod 30 = 0 then ( if r mod 100 = 0 then ( execute (("" + (((t / 30) * 5 + r / 100)))->toInteger())->display() ) else ( execute (("" + (((t / 30) * 5 + 1 + ("" + (((r - 100) / 100)))->toInteger())))->toInteger())->display() ) ) else ( if r mod 100 = 0 then ( execute (("" + ((("" + ((t / 30)))->toInteger() * 5 + 1 + ("" + (((r - 100) / 100)))->toInteger())))->toInteger())->display() ) else ( execute (("" + ((("" + (((t) / 30)))->toInteger() * 5 + 1 + ("" + (((r - 100) / 100)))->toInteger())))->toInteger())->display() ; execute (("" + ((("" + (((t) / 30)))->toInteger() * 5 + 6 + ("" + (((r - 100) / 100)))->toInteger())))->toInteger())->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") N=int(input()) for f in range(N): d,a=[int(_)for _ in input().split()] if d % 100==0 and a % 30==0 : print(5*(a//30)+d//100) elif d % 100==0 : print(5*(a//30)+d//100,5+5*(a//30)+d//100) elif a % 30==0 : print(5*(a//30)+d//100,5*(a//30)+d//100+1) else : print(' '.join([str(_)for _ in[5*(a//30)+d//100,5*(a//30)+d//100+1,5+5*(a//30)+d//100,5+5*(a//30)+d//100+1]])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for f : Integer.subrange(0, N-1) do ( var d : OclAny := null; var a : OclAny := null; Sequence{d,a} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; if d mod 100 = 0 & a mod 30 = 0 then ( execute (5 * (a div 30) + d div 100)->display() ) else (if d mod 100 = 0 then ( execute (5 * (a div 30) + d div 100)->display() ) else (if a mod 30 = 0 then ( execute (5 * (a div 30) + d div 100)->display() ) else ( execute (StringLib.sumStringsWithSeparator((Sequence{5 * (a div 30) + d div 100}->union(Sequence{5 * (a div 30) + d div 100 + 1}->union(Sequence{5 + 5 * (a div 30) + d div 100}->union(Sequence{ 5 + 5 * (a div 30) + d div 100 + 1 })))->select(_anon | true)->collect(_anon | (("" + ((_anon)))))), ' '))->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) for i in range(N): r,t=map(int,input().split()) chair=int(r/100)+int(t/30)*5 ans=str(chair) if r % 100!=0 : ans=ans+" "+str(chair+1) if t % 30!=0 : ans=ans+" "+str(chair+5) if r % 100!=0 : ans=ans+" "+str(chair+6) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, N-1) do ( var r : OclAny := null; var t : OclAny := null; Sequence{r,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var chair : int := ("" + ((r / 100)))->toInteger() + ("" + ((t / 30)))->toInteger() * 5 ; var ans : String := ("" + ((chair))) ; if r mod 100 /= 0 then ( ans := ans + " " + ("" + ((chair + 1))) ) else skip ; if t mod 30 /= 0 then ( ans := ans + " " + ("" + ((chair + 5))) ; if r mod 100 /= 0 then ( ans := ans + " " + ("" + ((chair + 6))) ) else skip ) else skip ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): d,r=map(int,input().split()) a=d//100+r//30*5 if d % 100 : if r % 30 : print("{}{}{}{}".format(a,a+1,a+5,a+6)) else : print("{}{}".format(a,a+1)) else : if r % 30 : print("{}{}".format(a,a+5)) else : print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var d : OclAny := null; var r : OclAny := null; Sequence{d,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : int := d div 100 + r div 30 * 5 ; if d mod 100 then ( if r mod 30 then ( execute (StringLib.interpolateStrings("{}{}{}{}", Sequence{a, a + 1, a + 5, a + 6}))->display() ) else ( execute (StringLib.interpolateStrings("{}{}", Sequence{a, a + 1}))->display() ) ) else ( if r mod 30 then ( execute (StringLib.interpolateStrings("{}{}", Sequence{a, a + 5}))->display() ) else ( execute (a)->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CalcID(r,t): return r+5*t n=int(input()) for i in range(n): r,t=map(int,input().split()) onR=r % 100==0 onT=t % 30==0 r=int(r/100) t=int(t/30) if onR and onT : print(CalcID(r,t)) elif onR : print('{0}{1}'.format(CalcID(r,t),CalcID(r,t+1))) elif onT : print('{0}{1}'.format(CalcID(r,t),CalcID(r+1,t))) else : print('{0}{1}{2}{3}'.format(CalcID(r,t),CalcID(r+1,t),CalcID(r,t+1),CalcID(r+1,t+1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( Sequence{r,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var onR : boolean := r mod 100 = 0 ; var onT : boolean := t mod 30 = 0 ; r := ("" + ((r / 100)))->toInteger() ; t := ("" + ((t / 30)))->toInteger() ; if onR & onT then ( execute (CalcID(r, t))->display() ) else (if onR then ( execute (StringLib.interpolateStrings('{0}{1}', Sequence{CalcID(r, t), CalcID(r, t + 1)}))->display() ) else (if onT then ( execute (StringLib.interpolateStrings('{0}{1}', Sequence{CalcID(r, t), CalcID(r + 1, t)}))->display() ) else ( execute (StringLib.interpolateStrings('{0}{1}{2}{3}', Sequence{CalcID(r, t), CalcID(r + 1, t), CalcID(r, t + 1), CalcID(r + 1, t + 1)}))->display() ) ) ) ); operation CalcID(r : OclAny, t : OclAny) : OclAny pre: true post: true activity: return r + 5 * t; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush MOD=10**9+7 def solution(): n=int(input()) arr=list(map(int,input().split())) while min(arr)mn : arr[i]-=mn print(sum(arr)) def main(): t=1 for _ in range(t): solution() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; main(); operation solution() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; while ((arr)->min()->compareTo((arr)->max())) < 0 do ( var mn : OclAny := (arr)->min() ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1]->compareTo(mn)) > 0 then ( arr[i+1] := arr[i+1] - mn ) else skip)) ; execute ((arr)->sum())->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os import math from itertools import combinations,permutations TC=False def find_gcd(x,y): while(y): x,y=y,x % y return x def solve(): n=int(input()) l=list(map(int,input().split())) num1=l[0] num2=l[1] gcd=find_gcd(num1,num2) for i in range(2,len(l)): gcd=find_gcd(gcd,l[i]) print(gcd*n) if os.path.exists('input.txt'): debug=True sys.stdin=open("input.txt","r") if TC : for _ in range(int(input())): solve() else : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var TC : boolean := false ; skip ; skip ; if os.path.exists('input.txt') then ( var debug : boolean := true ; OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ) else skip ; if TC then ( for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve()) ) else ( solve() ); operation find_gcd(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: while (y) do ( Sequence{x,y} := Sequence{y,x mod y}) ; return x; operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var num1 : OclAny := l->first() ; var num2 : OclAny := l[1+1] ; var gcd : OclAny := find_gcd(num1, num2) ; for i : Integer.subrange(2, (l)->size()-1) do ( gcd := find_gcd(gcd, l[i+1])) ; execute (gcd * n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import inf from heapq import heapify,heappop,heappush n=int(input()) nums=[int(ch)for ch in input().split(' ')] heapify(nums) while nums : x=heappop(nums) if len(nums)==0 : print(x*n) break if x==1 : print(n) break y=heappop(nums) if x==y or y-x==x : heappush(nums,x) else : heappush(nums,x) heappush(nums,y-x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nums : Sequence := input().split(' ')->select(ch | true)->collect(ch | (("" + ((ch)))->toInteger())) ; heapify(nums) ; while nums do ( var x : OclAny := heappop(nums) ; if (nums)->size() = 0 then ( execute (x * n)->display() ; break ) else skip ; if x = 1 then ( execute (n)->display() ; break ) else skip ; var y : OclAny := heappop(nums) ; if x = y or y - x = x then ( heappush(nums, x) ) else ( heappush(nums, x) ; heappush(nums, y - x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin nii=lambda : map(int,stdin.readline().split()) lnii=lambda : list(map(int,stdin.readline().split())) n,k=nii() a=lnii() a.sort() mod=10**9+7 MAX_N=n+5 fac=[1,1]+[0]*MAX_N finv=[1,1]+[0]*MAX_N inv=[0,1]+[0]*MAX_N for i in range(2,MAX_N): fac[i]=fac[i-1]*i % mod inv[i]=mod-inv[mod % i]*(mod//i)% mod finv[i]=finv[i-1]*inv[i]% mod def nCk(n,k): if ncollect( _x | (OclType["int"])->apply(_x) )) ; var lnii : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := nii->apply() ; var a : OclAny := lnii->apply() ; a := a->sort() ; var mod : double := (10)->pow(9) + 7 ; var MAX_N : OclAny := n + 5 ; var fac : Sequence := Sequence{1}->union(Sequence{ 1 })->union(MatrixLib.elementwiseMult(Sequence{ 0 }, MAX_N)) ; var finv : Sequence := Sequence{1}->union(Sequence{ 1 })->union(MatrixLib.elementwiseMult(Sequence{ 0 }, MAX_N)) ; var inv : Sequence := Sequence{0}->union(Sequence{ 1 })->union(MatrixLib.elementwiseMult(Sequence{ 0 }, MAX_N)) ; for i : Integer.subrange(2, MAX_N-1) do ( fac[i+1] := fac[i - 1+1] * i mod mod ; inv[i+1] := mod - inv[mod mod i+1] * (mod div i) mod mod ; finv[i+1] := finv[i - 1+1] * inv[i+1] mod mod) ; skip ; var min_X : int := 0 ; for i : Integer.subrange(0, n - k + 1-1) do ( min_X := min_X + a[i+1] * nCk(n - i - 1, k - 1) ; min_X := min_X mod mod) ; var max_X : int := 0 ; for i : Integer.subrange(k - 1, n-1) do ( max_X := max_X + a[i+1] * nCk(i, k - 1) ; max_X := max_X mod mod) ; var ans : double := max_X - min_X ; ans := ans mod mod ; execute (ans)->display(); operation nCk(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (n->compareTo(k)) < 0 then ( return 0 ) else skip ; if n < 0 or k < 0 then ( return 0 ) else skip ; return fac[n+1] * (finv[k+1] * finv[n - k+1] mod mod) mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=input().split() l=[int(i)for i in x] l.sort() c=min(i for i in l if i>0) while max(l)>c : l[n-1]=l[n-1]-l[n-2] l.sort() c=min(i for i in l if i>0) if len(set(l))==1 : print(sum(l)) else : print(max(l)*n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : OclAny := input().split() ; var l : Sequence := x->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; l := l->sort() ; var c : OclAny := ((argument (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name l))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name i)))) > (comparison (expr (atom (number (integer 0))))))))))))->min() ; while ((l)->max()->compareTo(c)) > 0 do ( l[n - 1+1] := l[n - 1+1] - l[n - 2+1] ; l := l->sort() ; c := ((argument (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name l))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name i)))) > (comparison (expr (atom (number (integer 0))))))))))))->min()) ; if (Set{}->union((l)))->size() = 1 then ( execute ((l)->sum())->display() ) else ( execute ((l)->max() * n)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def main(b): if b==0 : return False for n in range(int(math.sqrt(2*b)),0,-1): if 2*b % n==0 : a=(-n*n+n+2*b)/(2*n) if a>=1 and a.is_integer(): print(int(a),n) return True while main(int(input())): pass ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while main(("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( skip); operation main(b : OclAny) : OclAny pre: true post: true activity: if b = 0 then ( return false ) else skip ; for n : Integer.subrange(0 + 1, ("" + (((2 * b)->sqrt())))->toInteger())->reverse() do ( if 2 * b mod n = 0 then ( var a : double := (-n * n + n + 2 * b) / (2 * n) ; if a >= 1 & a.is_integer() then ( execute (("" + ((a)))->toInteger())->display() ; return true ) else skip ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) while min(l)toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; while ((l)->min()->compareTo((l)->max())) < 0 do ( l[l->indexOf((l)->max()) - 1+1] := (l)->max() - (l)->min()) ; execute ((l)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=list(map(int,input().split())) s=input() alp="abcdefghijklmnopqrstuvwxyz" sum_array=[] for x in s : sum_array.append(alp.index(x)+1) for y in range(1,len(s)): sum_array[y]=sum_array[y-1]+sum_array[y] for i in range(b): l,r=list(map(int,input().split())) if l==1 : print(sum_array[r-1]) else : print(sum_array[r-1]-sum_array[l-2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : String := (OclFile["System.in"]).readLine() ; var alp : String := "abcdefghijklmnopqrstuvwxyz" ; var sum_array : Sequence := Sequence{} ; for x : s->characters() do ( execute ((alp->indexOf(x) - 1 + 1) : sum_array)) ; for y : Integer.subrange(1, (s)->size()-1) do ( sum_array[y+1] := sum_array[y - 1+1] + sum_array[y+1]) ; for i : Integer.subrange(0, b-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if l = 1 then ( execute (sum_array[r - 1+1])->display() ) else ( execute (sum_array[r - 1+1] - sum_array[l - 2+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=map(int,input().split()) a=list(input()) b=[[0 for j in range(26)]for i in range(x+1)] for i in range(x): b[i+1][ord(a[i])-ord('a')]+=1 for i in range(x-1): for j in range(26): b[i+2][j]+=b[i+1][j] for i in range(y): l,r=map(int,input().split()) ans=r-l+1 for j in range(26): ans+=(b[r][j]-b[l-1][j])*j print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var b : Sequence := Integer.subrange(0, x + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, 26-1)->select(j | true)->collect(j | (0)))) ; for i : Integer.subrange(0, x-1) do ( b[i + 1+1][(a[i+1])->char2byte() - ('a')->char2byte()+1] := b[i + 1+1][(a[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; for i : Integer.subrange(0, x - 1-1) do ( for j : Integer.subrange(0, 26-1) do ( b[i + 2+1][j+1] := b[i + 2+1][j+1] + b[i + 1+1][j+1])) ; for i : Integer.subrange(0, y-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : double := r - l + 1 ; for j : Integer.subrange(0, 26-1) do ( ans := ans + (b[r+1][j+1] - b[l - 1+1][j+1]) * j) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,q=map(int,input().split()) s=input() prefix_sum=[0 for _ in range(len(s)+1)] for i,c in enumerate(s): prefix_sum[i+1]=prefix_sum[i]+int(ord(c)-ord('a')+1) for i in range(q): l,r=map(int,input().split()) print(prefix_sum[r]-prefix_sum[l-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var prefix_sum : Sequence := Integer.subrange(0, (s)->size() + 1-1)->select(_anon | true)->collect(_anon | (0)) ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); prefix_sum[i + 1+1] := prefix_sum[i+1] + ("" + (((c)->char2byte() - ('a')->char2byte() + 1)))->toInteger()) ; for i : Integer.subrange(0, q-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (prefix_sum[r+1] - prefix_sum[l - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=list(map(int,input().split())) s=input() a=[0]*(n+1) for x in range(1,len(s)+1): a[x]+=a[x-1]+(ord(s[x-1])-ord('a'))+1 for x in range(k): r,l=list(map(int,input().split())) print(a[l]-a[r-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : String := (OclFile["System.in"]).readLine() ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for x : Integer.subrange(1, (s)->size() + 1-1) do ( a[x+1] := a[x+1] + a[x - 1+1] + ((s[x - 1+1])->char2byte() - ('a')->char2byte()) + 1) ; for x : Integer.subrange(0, k-1) do ( var r : OclAny := null; var l : OclAny := null; Sequence{r,l} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (a[l+1] - a[r - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,q=map(int,input().split()) s=input() a=[0] for i in range(1,n+1): a.append(a[i-1]+ord(s[i-1])-96) for i in range(q): l,r=map(int,input().split()) print(a[r]-a[l-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var a : Sequence := Sequence{ 0 } ; for i : Integer.subrange(1, n + 1-1) do ( execute ((a[i - 1+1] + (s[i - 1+1])->char2byte() - 96) : a)) ; for i : Integer.subrange(0, q-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (a[r+1] - a[l - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(a==0): return b return gcd(b % a,a) def lcm(a,b): return(a*b)/gcd(a,b) def printSum(num1,den1,num2,den2): lcd=lcm(den1,den2); num1*=(lcd/den1) num2*=(lcd/den2) res_num=num1+num2 ; print(int(res_num),"/",int(lcd)) num1=1 den1=6 num2=7 den2=15 printSum(num1,den1,num2,den2); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; num1 := 1 ; den1 := 6 ; num2 := 7 ; den2 := 15 ; printSum(num1, den1, num2, den2);; operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0) then ( return b ) else skip ; return gcd(b mod a, a); operation lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a * b) / gcd(a, b); operation printSum(num1 : OclAny, den1 : OclAny, num2 : OclAny, den2 : OclAny) pre: true post: true activity: var lcd : OclAny := lcm(den1, den2); ; num1 := num1 * (lcd / den1) ; num2 := num2 * (lcd / den2) ; var res_num : OclAny := num1 + num2; ; execute (("" + ((res_num)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def firstLetterWord(str): result="" v=True for i in range(len(str)): if(str[i]==' '): v=True elif(str[i]!=' ' and v==True): result+=(str[i]) v=False return result if __name__=="__main__" : str="geeks for geeks" print(firstLetterWord(str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( OclType["String"] := "geeks for geeks" ; execute (firstLetterWord(OclType["String"]))->display() ) else skip; operation firstLetterWord(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var result : String := "" ; var v : boolean := true ; for i : Integer.subrange(0, (OclType["String"])->size()-1) do ( if (("" + ([i+1])) = ' ') then ( v := true ) else (if (("" + ([i+1])) /= ' ' & v = true) then ( result := result + (("" + ([i+1]))) ; v := false ) else skip)) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Combination : def __init__(self,size,mod=10**9+7): self.size=size+2 self.mod=mod self.fact=[1,1]+[0]*size self.factInv=[1,1]+[0]*size self.inv=[0,1]+[0]*size for i in range(2,self.size): self.fact[i]=self.fact[i-1]*i % self.mod self.inv[i]=-self.inv[self.mod % i]*(self.mod//i)% self.mod self.factInv[i]=self.factInv[i-1]*self.inv[i]% self.mod def npr(self,n,r): if nexists( _x | result = _x ); attribute size : OclAny := size + 2; attribute mod : OclAny := mod; attribute fact : Sequence := Sequence{1}->union(Sequence{ 1 })->union(MatrixLib.elementwiseMult(Sequence{ 0 }, size)); attribute factInv : Sequence := Sequence{1}->union(Sequence{ 1 })->union(MatrixLib.elementwiseMult(Sequence{ 0 }, size)); attribute inv : Sequence := Sequence{0}->union(Sequence{ 1 })->union(MatrixLib.elementwiseMult(Sequence{ 0 }, size)); operation initialise(size : OclAny,mod : OclAny) : Combination pre: true post: true activity: self.size := size + 2 ; self.mod := mod ; self.fact := Sequence{1}->union(Sequence{ 1 })->union(MatrixLib.elementwiseMult(Sequence{ 0 }, size)) ; self.factInv := Sequence{1}->union(Sequence{ 1 })->union(MatrixLib.elementwiseMult(Sequence{ 0 }, size)) ; self.inv := Sequence{0}->union(Sequence{ 1 })->union(MatrixLib.elementwiseMult(Sequence{ 0 }, size)) ; for i : Integer.subrange(2, self.size-1) do ( self.fact[i+1] := self.fact[i - 1+1] * i mod self.mod ; self.inv[i+1] := -self.inv[self.mod mod i+1] * (self.mod div i) mod self.mod ; self.factInv[i+1] := self.factInv[i - 1+1] * self.inv[i+1] mod self.mod); return self; operation npr(n : OclAny,r : OclAny) : OclAny pre: true post: true activity: if (n->compareTo(r)) < 0 or n < 0 or r < 0 then ( return 0 ) else skip ; return self.fact[n+1] * self.factInv[n - r+1] mod self.mod; operation ncr(n : OclAny,r : OclAny) : OclAny pre: true post: true activity: if (n->compareTo(r)) < 0 or n < 0 or r < 0 then ( return 0 ) else skip ; return self.fact[n+1] * (self.factInv[r+1] * self.factInv[n - r+1] mod self.mod) mod self.mod; operation factN(n : OclAny) : OclAny pre: true post: true activity: if n < 0 then ( return 0 ) else skip ; return self.fact[n+1]; } class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var MOD : double := (10)->pow(9) + 7 ; A := A->sort() ; var comb : Combination := (Combination.newCombination()).initialise(N + 100) ; var ans : int := 0 ; for _tuple : Integer.subrange(1, (A, (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->size())->collect( _indx | Sequence{_indx-1, (A, (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); ans := ans + comb.ncr(i - 1, K - 1) * a ; ans := ans - comb.ncr(N - i, K - 1) * a ; ans := ans mod MOD) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() j=1 k=1 for i in range(len(s)): if j>4 : j=1 if k>3 : k=1 if s[i]=='0' : print(1,j) j+=1 else : print(3,k) k+=2 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var j : int := 1 ; var k : int := 1 ; for i : Integer.subrange(0, (s)->size()-1) do ( if j > 4 then ( j := 1 ) else skip ; if k > 3 then ( k := 1 ) else skip ; if s[i+1] = '0' then ( execute (1)->display() ; j := j + 1 ) else ( execute (3)->display() ; k := k + 2 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() x,y=1,1 for i in s : if i=='1' : print(4,y) y+=2 if y==5 : y=1 else : print(1,x) x+=1 if x==5 : x=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{1,1} ; for i : s->characters() do ( if i = '1' then ( execute (4)->display() ; y := y + 2 ; if y = 5 then ( var y : int := 1 ) else skip ) else ( execute (1)->display() ; x := x + 1 ; if x = 5 then ( var x : int := 1 ) else skip )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import array from fractions import Fraction import functools import itertools import math import os import sys def main(): while True : B=read_int() if B==0 : break print(*solve(B)) def solve(B): bb=2*B lb=1 ub=B+1 while ub-lb>1 : m=(lb+ub)//2 if m*m<=bb : lb=m else : ub=m n=lb while True : if bb % n==0 : k=bb//n if(k-n)% 2==1 : return(k-n+1)//2,n n-=1 DEBUG='DEBUG' in os.environ def inp(): return sys.stdin.readline().rstrip() def read_int(): return int(inp()) def read_ints(): return[int(e)for e in inp().split()] def dprint(*value,sep=' ',end='\n'): if DEBUG : print(*value,sep=sep,end=end) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var DEBUG : boolean := (os.environ)->includes('DEBUG') ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: while true do ( var B : OclAny := read_int() ; if B = 0 then ( break ) else skip ; execute ((argument * (test (logical_test (comparison (expr (atom (name solve)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name B)))))))) )))))))))->display()); operation solve(B : OclAny) : OclAny pre: true post: true activity: var bb : double := 2 * B ; var lb : int := 1 ; var ub : OclAny := B + 1 ; while ub - lb > 1 do ( var m : int := (lb + ub) div 2 ; if (m * m->compareTo(bb)) <= 0 then ( lb := m ) else ( ub := m )) ; var n : int := lb ; while true do ( if bb mod n = 0 then ( var k : int := bb div n ; if (k - n) mod 2 = 1 then ( return (k - n + 1) div 2, n ) else skip ) else skip ; n := n - 1); operation inp() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation read_int() : OclAny pre: true post: true activity: return ("" + ((inp())))->toInteger(); operation read_ints() : OclAny pre: true post: true activity: return inp().split()->select(e | true)->collect(e | (("" + ((e)))->toInteger())); operation dprint(value : OclAny : Sequence(OclAny), sep : String, end : String) pre: true post: true activity: (args * (named_parameter (name value))) if sep->oclIsUndefined() then sep := ' ' else skip; if end->oclIsUndefined() then end := ' ' else skip; if DEBUG then ( execute ((argument * (test (logical_test (comparison (expr (atom (name value))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() a=1 b=1 for i in range(len(s)): if a==5 : a=1 if b==5 : b=1 if s[i]=='0' : print(2,a) a+=1 else : print(4,b) b+=2 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var a : int := 1 ; var b : int := 1 ; for i : Integer.subrange(0, (s)->size()-1) do ( if a = 5 then ( a := 1 ) else skip ; if b = 5 then ( b := 1 ) else skip ; if s[i+1] = '0' then ( execute (2)->display() ; a := a + 1 ) else ( execute (4)->display() ; b := b + 2 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=0 b=0 for c in input(): if c=='0' : print(a+1,1) a=(a+2)% 4 else : print(b+1,3) b=(b+1)% 4 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := 0 ; var b : int := 0 ; for c : (OclFile["System.in"]).readLine() do ( if c = '0' then ( execute (a + 1)->display() ; a := (a + 2) mod 4 ) else ( execute (b + 1)->display() ; b := (b + 1) mod 4 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input(); period_1=period_2=0 for i in s : if i=='1' : print(1,1+2*period_1); period_1=(period_1+1)% 2 if i=='0' : print(3,1+period_2); period_2=(period_2+1)% 4 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine(); var period_1 : OclAny := 0; var period0 : int := 0 ; for i : s->characters() do ( if i = '1' then ( execute (1)->display(); period var s : String := (OclFile["System.in"]).readLine(); var period_1 : OclAny := 0; var period0 : int := 0 := (period var s : String := (OclFile["System.in"]).readLine(); var period_1 : OclAny := 0; var period0 : int := 0 + 1) mod 2 ) else skip ; if i = '0' then ( execute (3)->display(); period:= (period1 + 1) mod 4 := (period1 + 1) mod 4 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import shlex inputString=input() result=shlex.split(inputString) for res in result : print("<{}>".format(res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var inputString : String := (OclFile["System.in"]).readLine() ; var result : OclAny := shlex.split(inputString) ; for res : result do ( execute (StringLib.interpolateStrings("<{}>", Sequence{res}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import shlex for l in shlex.split(input()): print(f"<{l}>") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for l : shlex.split((OclFile["System.in"]).readLine()) do ( execute (StringLib.formattedString("<{l}>"))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import shlex s=input(); a=shlex.split(s) for x in a : print('<'+x+'>') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : String := (OclFile["System.in"]).readLine(); ; var a : OclAny := shlex.split(s) ; for x : a do ( execute ('<' + x + '>')->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import shlex s=input(); a=shlex.split(s) for x in a : print('<'+x+'>') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : String := (OclFile["System.in"]).readLine(); ; var a : OclAny := shlex.split(s) ; for x : a do ( execute ('<' + x + '>')->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=10**9+7 N=10**5+1 fact=[1]*(N+1) ifact=[1]*(N+1) for i in range(N): fact[i+1]=fact[i]*(i+1)% mod ifact[i+1]=pow(fact[i+1],mod-2,mod) def comb(x,y): if y<0 or y>x : return 0 return(fact[x]*ifact[x-y]*ifact[y])% mod n,k=map(int,input().split()) a=sorted(list(map(int,input().split()))) ar=sorted(a,reverse=True) ans=0 for i in range(k-1,n): ans+=a[i]*comb(i,k-1)% mod ans-=ar[i]*comb(i,k-1)% mod ans %=mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : double := (10)->pow(9) + 7 ; var N : double := (10)->pow(5) + 1 ; var fact : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (N + 1)) ; var ifact : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (N + 1)) ; for i : Integer.subrange(0, N-1) do ( fact[i + 1+1] := fact[i+1] * (i + 1) mod mod ; ifact[i + 1+1] := (fact[i + 1+1])->pow(mod - 2)) ; skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var ar : Sequence := a->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var ans : int := 0 ; for i : Integer.subrange(k - 1, n-1) do ( ans := ans + a[i+1] * comb(i, k - 1) mod mod ; ans := ans - ar[i+1] * comb(i, k - 1) mod mod ; ans := ans mod mod) ; execute (ans)->display(); operation comb(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if y < 0 or (y->compareTo(x)) > 0 then ( return 0 ) else skip ; return (fact[x+1] * ifact[x - y+1] * ifact[y+1]) mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input().split('"') for i in range(len(s)): if i % 2 : print('<',s[i],'>',sep='') else : l=[x for x in s[i].split()if x!=''] if l!=[]: print('<','>\n<'.join(l),'>',sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := input().split('"') ;\n for i : Integer.subrange(0, (s)->size()-1) do ( if i mod 2 then (\n execute ('<')->display()\n )\n else (\n var l : Sequence := s[i+1].split()->select(x | x /= '')->collect(x | (x)) ;\n if l /= Sequence{} then (\n execute ('<')->display()\n ) else skip\n ));\n\n\n}\n ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) q=int(input()) for i in range(q): b,e,t=map(int,input().split()) s=t+e-b if t>b : a=a[: b]+a[t : s]+a[e : t]+a[b : e]+a[s :] else : a=a[: t]+a[b : e]+a[s : b]+a[t : s]+a[e :] print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( var b : OclAny := null; var e : OclAny := null; var t : OclAny := null; Sequence{b,e,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : double := t + e - b ; if (t->compareTo(b)) > 0 then ( a := a.subrange(1,b) + a.subrange(t+1, s) + a.subrange(e+1, t) + a.subrange(b+1, e) + a.subrange(s+1) ) else ( a := a.subrange(1,t) + a.subrange(b+1, e) + a.subrange(s+1, b) + a.subrange(t+1, s) + a.subrange(e+1) )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def partial_swap(origin,begin,end,begin2): for i in range(end-begin): origin[begin+i],origin[begin2+i]=origin[begin2+i],origin[begin+i] return origin if __name__=='__main__' : N=int(input()) A=list(map(int,input().split())) Q=int(input()) for i in range(Q): b,e,t=map(int,input().split()) A=partial_swap(A,b,e,t) print(' '.join(map(str,A))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, Q-1) do ( var b : OclAny := null; var e : OclAny := null; var t : OclAny := null; Sequence{b,e,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; A := partial_swap(A, b, e, t)) ; execute (StringLib.sumStringsWithSeparator(((A)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ) else skip; operation partial_swap(origin : OclAny, begin : OclAny, end : OclAny, begin2 : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, end - begin-1) do ( var origin[begin + i+1] : OclAny := null; var origin[begin2 + i+1] : OclAny := null; Sequence{origin[begin + i+1],origin[begin2 + i+1]} := Sequence{origin[begin2 + i+1],origin[begin + i+1]}) ; return origin; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import os import math for s in sys.stdin : d,w,h=map(int,s.split()) if d==w==h==0 : break lst=[d,w,h] lst.sort() diameter=math.sqrt(lst[0]**2+lst[1]**2) n=int(input()) for i in range(n): r=int(input()) if 2*r>diameter : print('OK') else : print('NA') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; for s : OclFile["System.in"] do ( var d : OclAny := null; var w : OclAny := null; var h : OclAny := null; Sequence{d,w,h} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ) ; if d = w & (w == h) & (h == 0) then ( break ) else skip ; var lst : Sequence := Sequence{d}->union(Sequence{w}->union(Sequence{ h })) ; lst := lst->sort() ; var diameter : double := ((lst->first())->pow(2) + (lst[1+1])->pow(2))->sqrt() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var r : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (2 * r->compareTo(diameter)) > 0 then ( execute ('OK')->display() ) else ( execute ('NA')->display() ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def resolve(): from collections import deque N=int(input()) A=[int(i)for i in input().split()] Q=int(input()) ans=[i for i in range(N)] for _ in range(Q): b,e,t=[int(i)for i in input().split()] tmp=deque(ans[t : t+(e-b)]) for i in range(b,e): ans[i+t-b]=ans[i] ans[i]=tmp[i-b] prt=[0]*N for i in range(N): prt[i]=A[ans[i]] print(*prt) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; resolve(); operation resolve() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (i)) ; for _anon : Integer.subrange(0, Q-1) do ( var b : OclAny := null; var e : OclAny := null; var t : OclAny := null; Sequence{b,e,t} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var tmp : Sequence := (ans.subrange(t+1, t + (e - b))) ; for i : Integer.subrange(b, e-1) do ( ans[i + t - b+1] := ans[i+1] ; ans[i+1] := tmp[i - b+1])) ; var prt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for i : Integer.subrange(0, N-1) do ( prt[i+1] := A[ans[i+1]+1]) ; execute ((argument * (test (logical_test (comparison (expr (atom (name prt))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() nums=list(map(int,input().split(' '))) n=int(input()) for _ in range(n): f,m,l=list(map(int,input().split(' '))) m=m-f if f>l : f,l=l,f sb_1=list(nums[f : f+m]) sb_2=list(nums[l : l+m]) nums=nums[: f]+sb_2+nums[f+m : l]+sb_1+nums[l+m :] print(' '.join(map(str,nums))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var nums : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var f : OclAny := null; var m : OclAny := null; var l : OclAny := null; Sequence{f,m,l} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var m : double := m - f ; if (f->compareTo(l)) > 0 then ( var f : OclAny := null; var l : OclAny := null; Sequence{f,l} := Sequence{l,f} ) else skip ; var sb var f : OclAny := null; var m : OclAny := null; var l : OclAny := null; Sequence{f,m,l} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) : Sequence := (nums.subrange(f+1, f + m)) ; var sb:= (nums.subrange(l+1, l + m)) : Sequence := (nums.subrange(l+1, l + m)) ; nums := nums.subrange(1,f)->union(sbnums.subrange(f + m+1, l)) + nums.subrange(f + m+1, l)->union(sb var f : OclAny := null; var m : OclAny := null; var l : OclAny := null; Sequence{f,m,l} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ))) + nums.subrange(l + m+1)) ; execute (StringLib.sumStringsWithSeparator(((nums)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque import sys input=sys.stdin.readline def main(): n1=int(input()) l1=list(map(int,input().split())) for i in range(int(input())): (b,e,t)=map(int,input().split()) for k in range(e-b): l1[k+b],l1[t+k]=l1[t+k],l1[k+b] print(" ".join(map(str,l1))) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { suite`nestedAttributeDefinitions operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var Sequence{b, e, t} : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation main(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; var n1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (suite); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=1000000007 arr=[[None for i in range(1001)]for j in range(1001)] def Preprocess(): arr[0][0]=1 for i in range(1,1001): arr[i][0]=1 for j in range(1,i): arr[i][j]=(arr[i-1][j-1]+arr[i-1][j])% mod arr[i][i]=1 def powmod(a,n): if not n : return 1 pt=powmod(a,n//2) pt=(pt*pt)% mod if n % 2 : return(pt*a)% mod else : return pt def CountSubset(val,n): ans=powmod(2,n-1) val.sort() for i in range(0,n): j=i+1 while jselect(j | true)->collect(j | (Integer.subrange(0, 1001-1)->select(i | true)->collect(i | (null)))) ; skip ; skip ; skip ; if __name__ = "__main__" then ( Preprocess() ; val := Sequence{2}->union(Sequence{3}->union(Sequence{ 2 })) ; n := (val)->size() ; execute (CountSubset(val, n))->display() ) else skip; operation Preprocess() pre: true post: true activity: arr->first()->first() := 1 ; for i : Integer.subrange(1, 1001-1) do ( arr[i+1]->first() := 1 ; for j : Integer.subrange(1, i-1) do ( arr[i+1][j+1] := (arr[i - 1+1][j - 1+1] + arr[i - 1+1][j+1]) mod mod) ; arr[i+1][i+1] := 1); operation powmod(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: if not(n) then ( return 1 ) else skip ; var pt : OclAny := powmod(a, n div 2) ; pt := (pt * pt) mod mod ; if n mod 2 then ( return (pt * a) mod mod ) else ( return pt ); operation CountSubset(val : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : OclAny := powmod(2, n - 1) ; val := val->sort() ; for i : Integer.subrange(0, n-1) do ( var j : OclAny := i + 1 ; while (j->compareTo(n)) < 0 & val[j+1] = val[i+1] do ( var r : double := n - 1 - j ; var l : OclAny := i ; ans := (ans + arr[l + r+1][l+1]) mod mod ; j := j + 1)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) X,Y,Z=0,0,0 for _ in range(n): x,y,z=list(map(int,input().split())) X+=x Y+=y Z+=z if X==Y==Z==0 : print("YES") else : print("NO") if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var X : OclAny := null; var Y : OclAny := null; var Z : OclAny := null; Sequence{X,Y,Z} := Sequence{0,0,0} ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; X := X + x ; Y := Y + y ; Z := Z + z) ; if X = Y & (Y == Z) & (Z == 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from re import X n=int(input()) a=b=c=0 for i in range(n): x,y,z=map(int,input().split()) a+=x b+=y c+=z if a==b and a==c and a==0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := a(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := a + x ; b := b + y ; c := c + z) ; if a = b & a = c & a = 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod_base=(10**9)+7 n,k=map(int,input().split(" ")) a=map(int,input().split(" ")) sa=sorted(a,reverse=True) fac=fac_inv=inv=list() def comb_init(n_in,mod): global fac,fac_inv,inv fac=[1 for x in range(0,n_in+1)] fac_inv=[1 for x in range(0,n_in+1)] inv=[1 for x in range(0,n_in+1)] for i in range(2,n_in+1): fac[i]=fac[i-1]*i % mod inv[i]=mod-inv[mod % i]*(mod//i)% mod fac_inv[i]=fac_inv[i-1]*inv[i]% mod def comb(n_in,r,mod): if n_in=(k-1): sum_max=(sum_max+sai*comb(n-i-1,k-1,mod_base))% mod_base if i>=(k-1): sum_min=(sum_min+sai*comb(i,k-1,mod_base))% mod_base print((sum_max-sum_min)% mod_base) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute fac : OclAny; attribute fac_inv : OclAny; attribute inv : OclAny; operation initialise() pre: true post: true activity: var mod_base : double := ((10)->pow(9)) + 7 ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var sa : Sequence := a->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; fac := fac(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name fac_inv)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name inv)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( )))))))))) ; skip ; skip ; comb_init(n, mod_base) ; var sum_max : int := 0 ; var sum_min : int := 0 ; for i : Integer.subrange(0, n-1) do ( var sai : OclAny := sa[i+1] ; if ((n - i - 1)->compareTo((k - 1))) >= 0 then ( sum_max := (sum_max + sai * comb(n - i - 1, k - 1, mod_base)) mod mod_base ) else skip ; if (i->compareTo((k - 1))) >= 0 then ( sum_min := (sum_min + sai * comb(i, k - 1, mod_base)) mod mod_base ) else skip) ; execute ((sum_max - sum_min) mod mod_base)->display(); operation comb_init(n_in : OclAny, mod : OclAny) pre: true post: true activity: skip; skip; skip ; fac := Integer.subrange(0, n_in + 1-1)->select(x | true)->collect(x | (1)) ; fac_inv := Integer.subrange(0, n_in + 1-1)->select(x | true)->collect(x | (1)) ; inv := Integer.subrange(0, n_in + 1-1)->select(x | true)->collect(x | (1)) ; for i : Integer.subrange(2, n_in + 1-1) do ( fac[i+1] := fac[i - 1+1] * i mod mod ; inv[i+1] := mod - inv[mod mod i+1] * (mod div i) mod mod ; fac_inv[i+1] := fac_inv[i - 1+1] * inv[i+1] mod mod); operation comb(n_in : OclAny, r : OclAny, mod : OclAny) : OclAny pre: true post: true activity: if (n_in->compareTo(r)) < 0 then ( return 0 ) else (if n_in < 0 or r < 0 then ( return 0 ) else ( return fac[n_in+1] * (fac_inv[r+1] * fac_inv[n_in - r+1] mod mod) mod mod ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) x,y,z=0,0,0 for i in range(t): a,b,c=map(int,input().split()) x+=a y+=b z+=c if x==0 and y==0 and z==0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := Sequence{0,0,0} ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; x := x + a ; y := y + b ; z := z + c) ; if x = 0 & y = 0 & z = 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a,b,c=0,0,0 for i in range(n): l1=list(map(int,input().split())) a=a+l1[0] b=b+l1[1] c=c+l1[2] if a==0 and b==0 and c==0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{0,0,0} ; for i : Integer.subrange(0, n-1) do ( var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := a + l1->first() ; var b : OclAny := b + l1[1+1] ; var c : OclAny := c + l1[2+1]) ; if a = 0 & b = 0 & c = 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=0 y=0 z=0 while n>0 : txt=input().split() x=x+int(txt[0]) y=y+int(txt[1]) z=z+int(txt[2]) n=n-1 if x==0 and y==0 and z==0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := 0 ; var y : int := 0 ; var z : int := 0 ; while n > 0 do ( var txt : OclAny := input().split() ; x := x + ("" + ((txt->first())))->toInteger() ; y := y + ("" + ((txt[1+1])))->toInteger() ; z := z + ("" + ((txt[2+1])))->toInteger() ; n := n - 1) ; if x = 0 & y = 0 & z = 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isProductEven(arr,n): for i in range(0,n): if((arr[i]& 1)==0): return True return False arr=[2,4,3,5] n=len(arr) if(isProductEven(arr,n)): print("Even") else : print("Odd") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{4}->union(Sequence{3}->union(Sequence{ 5 }))) ; n := (arr)->size() ; if (isProductEven(arr, n)) then ( execute ("Even")->display() ) else ( execute ("Odd")->display() ); operation isProductEven(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if ((MathLib.bitwiseAnd(arr[i+1], 1)) = 0) then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math if __name__=='__main__' : while True : d,w,h=map(int,input().split()) if d==0 and w==0 and h==0 : break a1=math.sqrt(d*d+h*h) a2=math.sqrt(d*d+w*w) a3=math.sqrt(h*h+w*w) n=int(input()) for _ in range(n): c=int(input()) if c*2<=a1 and c*2<=a2 and c*2<=a3 : print("NA") else : print("OK") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( while true do ( var d : OclAny := null; var w : OclAny := null; var h : OclAny := null; Sequence{d,w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if d = 0 & w = 0 & h = 0 then ( break ) else skip ; var a1 : double := (d * d + h * h)->sqrt() ; var a2 : double := (d * d + w * w)->sqrt() ; var a3 : double := (h * h + w * w)->sqrt() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (c * 2->compareTo(a1)) <= 0 & (c * 2->compareTo(a2)) <= 0 & (c * 2->compareTo(a3)) <= 0 then ( execute ("NA")->display() ) else ( execute ("OK")->display() ))) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for j in range(int(input())): n=int(input()) a=list(map(int,input().split())) a.sort() pos=0 var=0 neg=[] for k in range(n): if a[k]<1 : neg.append(a[k]) else : var=k break pos=a[k] flag=True for j in range(len(neg)-1): if abs(a[j+1]-a[j])toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var pos : int := 0 ; var var : int := 0 ; var neg : Sequence := Sequence{} ; for k : Integer.subrange(0, n-1) do ( if a[k+1] < 1 then ( execute ((a[k+1]) : neg) ) else ( var := k ; break )) ; pos := a[k+1] ; var flag : boolean := true ; for j : Integer.subrange(0, (neg)->size() - 1-1) do ( if ((a[j + 1+1] - a[j+1])->abs()->compareTo(pos)) < 0 then ( flag := false ; break ) else skip) ; if (neg)->size() = n then ( execute (n)->display() ) else (if flag then ( execute ((neg)->size() + 1)->display() ) else ( execute ((neg)->size())->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for x in range(int(input())): n=int(input()); c=1 ; m=1e10 arr=sorted([int(i)for i in input().split()]) for i in range(n-1): m=min(m,arr[i+1]-arr[i]) if m>=arr[i+1]: c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for x : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var c : int := 1; var m : double := ("1e10")->toReal() ; var arr : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))->sort() ; for i : Integer.subrange(0, n - 1-1) do ( m := Set{m, arr[i + 1+1] - arr[i+1]}->min() ; if (m->compareTo(arr[i + 1+1])) >= 0 then ( c := c + 1 ) else skip) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=list(int(x)for x in input().split()) neg=[x for x in a if x<=0] pos=[x for x in a if x>0] neg.sort() ans=len(neg) if len(pos)>0 : ans+=1 r=min(pos) for i in range(len(neg)-1): if neg[i+1]-neg[i]toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ; var neg : Sequence := a->select(x | x <= 0)->collect(x | (x)) ; var pos : Sequence := a->select(x | x > 0)->collect(x | (x)) ; neg := neg->sort() ; var ans : int := (neg)->size() ; if (pos)->size() > 0 then ( ans := ans + 1 ; var r : OclAny := (pos)->min() ; for i : Integer.subrange(0, (neg)->size() - 1-1) do ( if (neg[i + 1+1] - neg[i+1]->compareTo(r)) < 0 then ( ans := ans - 1 ; break ) else skip) ) else skip ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for z in range(t): f=0 x=int(input()) a,b,c=map(int,input().split()) for y in range(2): if x==1 : if a==0 : print('NO') break else : x=a f+=1 elif x==2 : if b==0 : print('NO') break else : x=b f+=1 else : if c==0 : print('NO') break else : x=c f+=1 if f==2 : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for z : Integer.subrange(0, t-1) do ( var f : int := 0 ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for y : Integer.subrange(0, 2-1) do ( if x = 1 then ( if a = 0 then ( execute ('NO')->display() ; break ) else ( x := a ; f := f + 1 ) ) else (if x = 2 then ( if b = 0 then ( execute ('NO')->display() ; break ) else ( x := b ; f := f + 1 ) ) else ( if c = 0 then ( execute ('NO')->display() ; break ) else ( x := c ; f := f + 1 ) ) ) ) ; if f = 2 then ( execute ('YES')->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for t in range(0,T): x=int(input()) a,b,c=map(int,input().split()) arr=[a,b,c] if arr[x-1]!=0 and arr[arr[x-1]-1]!=0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(0, T-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := Sequence{a}->union(Sequence{b}->union(Sequence{ c })) ; if arr[x - 1+1] /= 0 & arr[arr[x - 1+1] - 1+1] /= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline mod=10**9+7 n,k=map(int,input().split()) A=list(map(int,input().split())) FACTORIAL=[1]*(n+1) for i in range(1,n+1): FACTORIAL[i]=FACTORIAL[i-1]*i % mod INVERSE=[1]*(n+1) INVERSE[n]=pow(FACTORIAL[n],mod-2,mod) for i in range(n-1,-1,-1): INVERSE[i]=INVERSE[i+1]*(i+1)% mod def combination(n,r): return FACTORIAL[n]*INVERSE[n-r]% mod*INVERSE[r]% mod A.sort() sum_max=0 for i in range(k-1,n): sum_max=(sum_max+A[i]*combination(i,k-1))% mod A.sort(reverse=True) sum_min=0 for i in range(k-1,n): sum_min=(sum_min+A[i]*combination(i,k-1))% mod print((sum_max-sum_min)% mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var mod : double := (10)->pow(9) + 7 ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var FACTORIAL : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ; for i : Integer.subrange(1, n + 1-1) do ( FACTORIAL[i+1] := FACTORIAL[i - 1+1] * i mod mod) ; var INVERSE : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ; INVERSE[n+1] := (FACTORIAL[n+1])->pow(mod - 2) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( INVERSE[i+1] := INVERSE[i + 1+1] * (i + 1) mod mod) ; skip ; A := A->sort() ; var sum_max : int := 0 ; for i : Integer.subrange(k - 1, n-1) do ( sum_max := (sum_max + A[i+1] * combination(i, k - 1)) mod mod) ; A := A->sort() ; var sum_min : int := 0 ; for i : Integer.subrange(k - 1, n-1) do ( sum_min := (sum_min + A[i+1] * combination(i, k - 1)) mod mod) ; execute ((sum_max - sum_min) mod mod)->display(); operation combination(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: return FACTORIAL[n+1] * INVERSE[n - r+1] mod mod * INVERSE[r+1] mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): x=int(input()) d=[int(i)for i in input().split(" ")] ans=True if d[x-1]==0 : ans=False else : x=d[x-1] if d[x-1]==0 : ans=False if ans : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Sequence := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : boolean := true ; if d[x - 1+1] = 0 then ( ans := false ) else ( x := d[x - 1+1] ; if d[x - 1+1] = 0 then ( ans := false ) else skip ) ; if ans then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for x in range(t): i=int(input()) a,b,c=map(int,input().split()) if i==1 : if a!=0 and(b==3 or c==2): print('YES') else : print('NO') elif i==2 : if b!=0 and(a==3 or c==1): print('YES') else : print('NO') else : if c!=0 and(b==1 or a==2): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for x : Integer.subrange(0, t-1) do ( var i : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if i = 1 then ( if a /= 0 & (b = 3 or c = 2) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) else (if i = 2 then ( if b /= 0 & (a = 3 or c = 1) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) else ( if c /= 0 & (b = 1 or a = 2) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(x,lista,count): if count>3 : return 0 if lista[x-1]==0 : return 0 return 1+check(lista[x-1],lista,count+1) t=int(input()) for i in range(0,t): x=int(input()) lista=list(map(int,input().split())) if check(x,lista,0)==2 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( x := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; lista := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if check(x, lista, 0) = 2 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); operation check(x : OclAny, lista : OclAny, count : OclAny) : OclAny pre: true post: true activity: if count > 3 then ( return 0 ) else skip ; if lista[x - 1+1] = 0 then ( return 0 ) else skip ; return 1 + check(lista[x - 1+1], lista, count + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def centered_pentagonal_Num(n): return(5*n*n-5*n+2)//2 n=7 print("%sth Centered pentagonal number : " % n,centered_pentagonal_Num(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 7 ; execute (StringLib.format("%sth Centered pentagonal number : ",n))->display(); operation centered_pentagonal_Num(n : OclAny) : OclAny pre: true post: true activity: return (5 * n * n - 5 * n + 2) div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(2*10**5) question=1 AND=-1 OR=-2 left=-3 right=-4 tr={'?' : 1,'&' :-1,'|' :-2,'(' :-3,')' :-4} def evalor(L): if len(L)==1 : return L[0] x0,x1=L[0] for i in range(1,len(L)): y0,y1=L[i] x0,x1=x0+y0,min(x1,x0+y1) return(x0,x1) def push(f,s): if f and f[-1]==(AND,AND): f.pop() p=f.pop() return push(f,andeval(p,s)) else : f.append(s) return f def andeval(p,s): x0,x1=p y0,y1=s return(min(x0,x1+y0),x1+y1) S=[tr[s]for s in input().strip()] f=[] for s in S : if s==question : f=push(f,(s,s)) elif s==AND or s==left : f.append((s,s)) elif s==right : stack=[] while f[-1]!=(left,left): sp=f.pop() assert sp[0]>0 and sp[1]>0 stack.append(sp) assert f.pop()==(left,left) push(f,evalor(stack[: :-1])) f=evalor(f) print(*f) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(2 * (10)->pow(5)) ; var question : int := 1 ; var AND : int := -1 ; var OR : int := -2 ; var left : int := -3 ; var right : int := -4 ; var tr : Map := Map{ '?' |-> 1 }->union(Map{ '&' |-> -1 }->union(Map{ '|' |-> -2 }->union(Map{ '(' |-> -3 }->union(Map{ ')' |-> -4 })))) ; skip ; skip ; skip ; var S : Sequence := input()->trim()->select(s | true)->collect(s | (tr[s+1])) ; f := Sequence{} ; for s : S do ( if s = question then ( f := push(f, Sequence{s, s}) ) else (if s = AND or s = left then ( execute ((Sequence{s, s}) : f) ) else (if s = right then ( var stack : Sequence := Sequence{} ; while f->last() /= Sequence{left, left} do ( var sp : String := f->last() ; f := f->front() ; assert sp->first() > 0 & sp[1+1] > 0 do "assertion failed" ; execute ((sp) : stack)) ; assert f->last() = Sequence{left, left} do "assertion failed" ; push(f, evalor(stack(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))) ) else skip ) ) ) ; f := evalor(f) ; execute ((argument * (test (logical_test (comparison (expr (atom (name f))))))))->display(); operation evalor(L : OclAny) : OclAny pre: true post: true activity: if (L)->size() = 1 then ( return L->first() ) else skip ; var x0 : OclAny := null; var x1 : OclAny := null; Sequence{x0,x1} := L->first() ; for i : Integer.subrange(1, (L)->size()-1) do ( var y0 : OclAny := null; var y1 : OclAny := null; Sequence{y0,y1} := L[i+1] ; var x0 : OclAny := null; var x1 : OclAny := null; Sequence{x0,x1} := Sequence{x0 + y0,Set{x1, x0 + y1}->min()}) ; return Sequence{x0, x1}; operation push(f : OclAny, s : OclAny) : OclAny pre: true post: true activity: if f & f->last() = Sequence{AND, AND} then ( f := f->front() ; var p : String := f->last() ; f := f->front() ; return push(f, andeval(p, s)) ) else ( execute ((s) : f) ; return f ); operation andeval(p : OclAny, s : OclAny) : OclAny pre: true post: true activity: var x0 : OclAny := null; var x1 : OclAny := null; Sequence{x0,x1} := p ; var y0 : OclAny := null; var y1 : OclAny := null; Sequence{y0,y1} := s ; return Sequence{Set{x0, x1 + y0}->min(), x1 + y1}; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : a,b,_=sorted(map(int,input().split())) if a==0 : break for _ in[0]*int(input()): print("OK" if(int(input())*2)**2>a*a+b*b else "NA") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var a : OclAny := null; var b : OclAny := null; var _anon : OclAny := null; Sequence{a,b,_anon} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; if a = 0 then ( break ) else skip ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( execute (if (((("" + (((OclFile["System.in"]).readLine())))->toInteger() * 2))->pow(2)->compareTo(a * a + b * b)) > 0 then "OK" else "NA" endif)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- src=list(str(input())) tokens=[tok for tok in src if tok!=""] tokens.append("") cur=0 def parse_formula(): return parse_or() def parse_or(): global cur lhs=parse_and() if tokens[cur]=="|" : cur+=1 rhs=parse_or() zero=lhs[0]+rhs[0] one=min(lhs[1],lhs[0]+rhs[1]) return(zero,one) return lhs def parse_and(): global cur lhs=parse_term() if tokens[cur]=="&" : cur+=1 rhs=parse_and() zero=min(lhs[0],lhs[1]+rhs[0]) one=lhs[1]+rhs[1] return(zero,one) return lhs def parse_term(): global cur if tokens[cur]=="?" : cur+=1 return[1,1] elif tokens[cur]=="(" : cur+=1 res=parse_or() if tokens[cur]!=")" : raise Exception("not closed") cur+=1 return res ans=parse_formula() print(ans[0],ans[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute cur : OclAny; attribute cur : OclAny; attribute cur : OclAny; operation initialise() pre: true post: true activity: var src : Sequence := (("" + (((OclFile["System.in"]).readLine()))))->characters() ; var tokens : Sequence := src->select(tok | tok /= "")->collect(tok | (tok)) ; execute (("") : tokens) ; var cur : int := 0 ; skip ; skip ; skip ; skip ; var ans : OclAny := parse_formula() ; execute (ans->first())->display(); operation parse_formula() : OclAny pre: true post: true activity: return parse_or(); operation parse_or() : OclAny pre: true post: true activity: skip ; var lhs : OclAny := parse_and() ; if tokens[cur+1] = "|" then ( cur := cur + 1 ; var rhs : OclAny := parse_or() ; var zero : OclAny := lhs->first() + rhs->first() ; var one : OclAny := Set{lhs[1+1], lhs->first() + rhs[1+1]}->min() ; return Sequence{zero, one} ) else skip ; return lhs; operation parse_and() : OclAny pre: true post: true activity: skip ; lhs := parse_term() ; if tokens[cur+1] = "&" then ( cur := cur + 1 ; rhs := parse_and() ; zero := Set{lhs->first(), lhs[1+1] + rhs->first()}->min() ; one := lhs[1+1] + rhs[1+1] ; return Sequence{zero, one} ) else skip ; return lhs; operation parse_term() : OclAny pre: true post: true activity: skip ; if tokens[cur+1] = "?" then ( cur := cur + 1 ; return Sequence{1}->union(Sequence{ 1 }) ) else (if tokens[cur+1] = "(" then ( cur := cur + 1 ; var res : OclAny := parse_or() ; if tokens[cur+1] /= ")" then ( error ProgramException.newProgramException("not closed") ) else skip ; cur := cur + 1 ; return res ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,j=list(map(int,input().split())) if(n % 2==0): odd=n//2 else : odd=(n+1)//2 if(j<=odd): print((2*j)-1) else : print((j-odd)*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var j : OclAny := null; Sequence{n,j} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (n mod 2 = 0) then ( var odd : int := n div 2 ) else ( odd := (n + 1) div 2 ) ; if ((j->compareTo(odd)) <= 0) then ( execute ((2 * j) - 1)->display() ) else ( execute ((j - odd) * 2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- entry=input().split(" ") if int(entry[1])>(int(entry[0])+(int(entry[0])% 2))/2 : s=2*(int(entry[1])-(int(entry[0])+(int(entry[0])% 2))/2) else : s=int(entry[1])*2-1 print(int(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var entry : OclAny := input().split(" ") ; if (("" + ((entry[1+1])))->toInteger()->compareTo((("" + ((entry->first())))->toInteger() + (("" + ((entry->first())))->toInteger() mod 2)) / 2)) > 0 then ( var s : double := 2 * (("" + ((entry[1+1])))->toInteger() - (("" + ((entry->first())))->toInteger() + (("" + ((entry->first())))->toInteger() mod 2)) / 2) ) else ( s := ("" + ((entry[1+1])))->toInteger() * 2 - 1 ) ; execute (("" + ((s)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()); res=(n+1)//2 ; print(2*k-[1,2*res][k>res]); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); ; var res : int := (n + 1) div 2; ; execute (2 * k - Sequence{1}->union(Sequence{ 2 * res })->select((k->compareTo(res)) > 0))->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) print(max([min([a[i+2]-a[i]for i in range(n-2)])]+[a[i+1]-a[i]for i in range(n-1)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((Sequence{ (Integer.subrange(0, n - 2-1)->select(i | true)->collect(i | (a[i + 2+1] - a[i+1])))->min() }->union(Integer.subrange(0, n - 1-1)->select(i | true)->collect(i | (a[i + 1+1] - a[i+1]))))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,k=list(map(int,input().split())) if k<=math.ceil(n/2): print(2*k-1) else : print(2*(k-math.ceil(n/2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (k->compareTo((n / 2)->ceil())) <= 0 then ( execute (2 * k - 1)->display() ) else ( execute (2 * (k - (n / 2)->ceil()))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) if n % 2==0 : if k<=(n/2): print(2*k-1) else : print(2*k-n) else : if k<=(n+1)/2 : print(2*k-1) else : x=int((n+1)/2) print(2*(k-x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n mod 2 = 0 then ( if (k->compareTo((n / 2))) <= 0 then ( execute (2 * k - 1)->display() ) else ( execute (2 * k - n)->display() ) ) else ( if (k->compareTo((n + 1) / 2)) <= 0 then ( execute (2 * k - 1)->display() ) else ( var x : int := ("" + (((n + 1) / 2)))->toInteger() ; execute (2 * (k - x))->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=[i+1 for i in range(30)] for i in range(28): t=int(input()) s.remove(t) print(s[0],s[1],sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := Integer.subrange(0, 30-1)->select(i | true)->collect(i | (i + 1)) ; for i : Integer.subrange(0, 28-1) do ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((t) /: s)) ; execute (s->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- list_1=[int(input())for i in range(28)] list_1.sort() list_2=[] for i in range(1,31): list_2.append(i) result=list(set(list_2)-set(list_1)) print(min(result)) print(max(result)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var list_1 : Sequence := Integer.subrange(0, 28-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; listlistlistlistlistlistlist var list_1 : Sequence := Integer.subrange(0, 28-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))->sort()->sort()->sort()->sort()->sort()->sort() := listlistlistlistlistlistlist var list_1 : Sequence := Integer.subrange(0, 28-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))->sort()->sort()->sort()->sort()->sort()->sort()->sort() ; var list:= Sequence{} : Sequence := Sequence{} ; for i : Integer.subrange(1, 31-1) do ( execute ((i) : list.append(i))) ; var result : Sequence := (Set{}->union((listSet{}->union((list var list_1 : Sequence := Integer.subrange(0, 28-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())))))) - Set{}->union((list var list_1 : Sequence := Integer.subrange(0, 28-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))))) ; execute ((result)->min())->display() ; execute ((result)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys print(*sorted(set(range(1,31))-set(map(int,sys.stdin))),sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute ((argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 31))))))))) ))))))))) )))) - (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin)))))))) ))))))))) )))))))))) )))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- listn=[] for i in range(28): n=int(input()) listn.append(n) for i in range(28): for j in range(27,0,-1): if listn[j-1]>listn[j]: listn[j-1],listn[j]=listn[j],listn[j-1] flist=[] for i in range(1,31,1): if listn==[]: flist.append(i) else : if listn[0]==i : del(listn[0]) else : flist.append(i) print(flist[0]) print(flist[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var listn : Sequence := Sequence{} ; for i : Integer.subrange(0, 28-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((n) : listn)) ; for i : Integer.subrange(0, 28-1) do ( for j : Integer.subrange(0 + 1, 27)->reverse() do ( if (listn[j - 1+1]->compareTo(listn[j+1])) > 0 then ( var listn[j - 1+1] : OclAny := null; var listn[j+1] : OclAny := null; Sequence{listn[j - 1+1],listn[j+1]} := Sequence{listn[j+1],listn[j - 1+1]} ) else skip)) ; var flist : Sequence := Sequence{} ; for i : Integer.subrange(1, 31-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if listn = Sequence{} then ( execute ((i) : flist) ) else ( if listn->first() = i then ( execute ((listn->first()))->isDeleted() ) else ( execute ((i) : flist) ) )) ; execute (flist->first())->display() ; execute (flist[1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(d,w,h,holes): result=[] diagonal_len=(w**2+h**2)**0.5 for r in holes : if r*2>diagonal_len : result.append('OK') else : result.append('NA') return result def main(args): while True : d,w,h=[int(x)for x in input().strip().split(' ')] if d==0 and w==0 and h==0 : break num=int(input()) holes=[int(input().strip())for _ in range(num)] result=solve(d,w,h,holes) for r in result : print(r) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(d : OclAny, w : OclAny, h : OclAny, holes : OclAny) : OclAny pre: true post: true activity: var result : Sequence := Sequence{} ; var diagonal_len : double := (((w)->pow(2) + (h)->pow(2)))->pow(0.5) ; for r : holes do ( if (r * 2->compareTo(diagonal_len)) > 0 then ( execute (('OK') : result) ) else ( execute (('NA') : result) )) ; return result; operation main(args : OclAny) pre: true post: true activity: while true do ( Sequence{d,w,h} := input()->trim().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if d = 0 & w = 0 & h = 0 then ( break ) else skip ; var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; holes := Integer.subrange(0, num-1)->select(_anon | true)->collect(_anon | (("" + ((input()->trim())))->toInteger())) ; result := solve(d, w, h, holes) ; for r : result do ( execute (r)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- L=[False]*31 while True : try : s=int(input()) except : break L[s]=True for i in range(1,31): if not L[i]: print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var L : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, 31) ; while true do ( try ( var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) catch (_e : OclException) do ( break) ; L[s+1] := true) ; for i : Integer.subrange(1, 31-1) do ( if not(L[i+1]) then ( execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inFile=open("B-large.in.in",'r') outFile=open("B.out",'w') N=int(inFile.readline()) for I in range(1,N+1): numPoints,minDist=tuple([int(x)for x in inFile.readline().split()]) vendors=[] for i in range(numPoints): point,numVendors=tuple([int(x)for x in inFile.readline().split()]) for j in range(numVendors): vendors.append(point) maxMove=0 for i in range(1,len(vendors)): if vendors[i]-vendors[i-1]toInteger() ; for I : Integer.subrange(1, N + 1-1) do ( var numPoints : OclAny := null; var minDist : OclAny := null; Sequence{numPoints,minDist} := (inFile.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) ; var vendors : Sequence := Sequence{} ; for i : Integer.subrange(0, numPoints-1) do ( var point : OclAny := null; var numVendors : OclAny := null; Sequence{point,numVendors} := (inFile.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) ; for j : Integer.subrange(0, numVendors-1) do ( execute ((point) : vendors))) ; var maxMove : int := 0 ; for i : Integer.subrange(1, (vendors)->size()-1) do ( if (vendors[i+1] - vendors[i - 1+1]->compareTo(minDist)) < 0 then ( maxMove := Set{maxMove, vendors[i - 1+1] - vendors[i+1] + minDist}->max() ; vendors[i+1] := vendors[i - 1+1] + minDist ) else skip) ; outFile.write("Case #" + ("" + ((I))) + ": " + ("" + ((maxMove / 2))) + "\n") ; execute ("Case #" + ("" + ((I))) + ": " + ("" + ((maxMove / 2))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys NAME=None def ok(points,time,D): prev=None for p in points : x,cnt=p[0],p[1] minX=x-time if prev is not None : minX=max(minX,prev+D) next=minX+D*(cnt-1) if abs(x-next)>time : return False prev=next return True def getMagicWord(): numPoints=nextToken(int) D=nextToken(int)*2 p=[] pMin=1000000 pMax=-pMin n=0 for i in range(numPoints): x=nextToken(int)*2 cnt=nextToken(int) p.append((x,cnt)) p.sort(key=lambda x : x[0]) L,R=-1,10**14 while R-L>1 : K=(L+R)//2 if ok(p,K,D): R=K else : L=K return "%.1f" %(R/2) def nextToken(func=None): res="" while fin : c=fin.read(1) if c.isspace(): break res+=c if func : return func(res) else : return res def nextLine(): if fin : return fin.readline() else : return "" if NAME : fin,fout=open(NAME+".in","r"),open(NAME+".out","w") else : fin,fout=sys.stdin,sys.stdout for testNum in range(nextToken(int)): print("Case #%d: %s" %(testNum+1,getMagicWord())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var NAME : OclAny := null ; skip ; skip ; skip ; skip ; if NAME then ( var fin : OclAny := null; var fout : OclAny := null; Sequence{fin,fout} := Sequence{OclFile.newOclFile_Write(OclFile.newOclFile(NAME + ".in")),OclFile.newOclFile_Write(OclFile.newOclFile(NAME + ".out"))} ) else ( var fin : OclAny := null; var fout : OclAny := null; Sequence{fin,fout} := Sequence{OclFile["System.in"],OclFile["System.out"]} ) ; for testNum : Integer.subrange(0, nextToken(OclType["int"])-1) do ( execute (StringLib.format("Case #%d: %s",Sequence{testNum + 1, getMagicWord()}))->display()); operation ok(points : OclAny, time : OclAny, D : OclAny) : OclAny pre: true post: true activity: var prev : OclAny := null ; for p : points do ( var x : OclAny := null; var cnt : OclAny := null; Sequence{x,cnt} := Sequence{p->first(),p[1+1]} ; var minX : double := x - time ; if not(prev <>= null) then ( minX := Set{minX, prev + D}->max() ) else skip ; var next : OclAny := minX + D * (cnt - 1) ; if ((x - next)->abs()->compareTo(time)) > 0 then ( return false ) else skip ; prev := next) ; return true; operation getMagicWord() : OclAny pre: true post: true activity: var numPoints : OclAny := nextToken(OclType["int"]) ; D := nextToken(OclType["int"]) * 2 ; var p : Sequence := Sequence{} ; var pMin : int := 1000000 ; var pMax : int := -pMin ; var n : int := 0 ; for i : Integer.subrange(0, numPoints-1) do ( var x : double := nextToken(OclType["int"]) * 2 ; var cnt : OclAny := nextToken(OclType["int"]) ; execute ((Sequence{x, cnt}) : p)) ; p := p->sort() ; var L : OclAny := null; var R : OclAny := null; Sequence{L,R} := Sequence{-1,(10)->pow(14)} ; while R - L > 1 do ( var K : int := (L + R) div 2 ; if ok(p, K, D) then ( var R : int := K ) else ( var L : int := K )) ; return StringLib.format("%.1f",(R / 2)); operation nextToken(func : OclAny) : OclAny pre: true post: true activity: if func->oclIsUndefined() then func := null else skip; var res : String := "" ; while fin do ( var c : String := fin.readAll() ; if c->matches("[ \t\n\r]*") then ( break ) else skip ; res := res + c) ; if func then ( return func(res) ) else ( return res ); operation nextLine() : OclAny pre: true post: true activity: if fin then ( return fin.readLine() ) else ( return "" ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def T(n,arr): mx=0 if n==3 : return arr[2]-arr[0] else : for i in range(1,n-1): mx=max(mx,arr[i]-arr[i-1]) return mx n=int(input()) arr=list(map(int,input().split())) mn=999 if n==3 : print(T(n,arr)) else : for i in range(1,n-1): lis=arr[: i]+arr[i+1 :] mn=min(mn,T(n,lis)) print(mn) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; arr := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mn : int := 999 ; if n = 3 then ( execute (T(n, arr))->display() ) else ( for i : Integer.subrange(1, n - 1-1) do ( var lis : OclAny := arr.subrange(1,i) + arr.subrange(i + 1+1) ; mn := Set{mn, T(n, lis)}->min()) ; execute (mn)->display() ); operation T(n : OclAny, arr : OclAny) : OclAny pre: true post: true activity: var mx : int := 0 ; if n = 3 then ( return arr[2+1] - arr->first() ) else ( for i : Integer.subrange(1, n - 1-1) do ( mx := Set{mx, arr[i+1] - arr[i - 1+1]}->max()) ; return mx ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def foo(ifile): C,D=[int(x)for x in ifile.readline().split()] a=[] for i in range(C): P,V=[int(x)for x in ifile.readline().split()] a+=[[P,V]] n=len(a) b=[[a[i][0],a[i][0]]for i in range(n)] for i in range(n): count=0 for j in range(i)[: :-1]: count+=a[j][1] b[i][1]=max(b[i][1],a[j][0]+count*D) count=0 for j in range(i+1,n): count+=a[j][1] b[i][0]=min(b[i][0],a[j][0]+count*D) return "%.1f" %(max([b[i][1]-b[i][0]+D*a[i][1]-D for i in range(n)])/2.0) def main(ifile,ofile): n=int(ifile.readline()) for i in range(n): ofile.write("Case #%s: %s\n" %(i+1,foo(ifile))) main(sys.stdin,sys.stdout) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; main(OclFile["System.in"], OclFile["System.out"]); operation foo(ifile : OclAny) : OclAny pre: true post: true activity: var C : OclAny := null; var D : OclAny := null; Sequence{C,D} := ifile.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, C-1) do ( var P : OclAny := null; var V : OclAny := null; Sequence{P,V} := ifile.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; a := a + Sequence{ Sequence{P}->union(Sequence{ V }) }) ; var n : int := (a)->size() ; var b : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{a[i+1]->first()}->union(Sequence{ a[i+1]->first() }))) ; for i : Integer.subrange(0, n-1) do ( var count : int := 0 ; for j : range(i)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( count := count + a[j+1][1+1] ; b[i+1][1+1] := Set{b[i+1][1+1], a[j+1]->first() + count * D}->max()) ; count := 0 ; for j : Integer.subrange(i + 1, n-1) do ( count := count + a[j+1][1+1] ; b[i+1]->first() := Set{b[i+1]->first(), a[j+1]->first() + count * D}->min())) ; return StringLib.format("%.1f",((Integer.subrange(0, n-1)->select(i | true)->collect(i | (b[i+1][1+1] - b[i+1]->first() + D * a[i+1][1+1] - D)))->max() / 2.0)); operation main(ifile : OclAny, ofile : OclAny) pre: true post: true activity: n := ("" + ((ifile.readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( ofile.write(StringLib.format("Case #%s: %s\n",Sequence{i + 1, foo(ifile)}))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findWays(f,d,s): mem=[[0 for i in range(s+1)]for j in range(d+1)] mem[0][0]=1 for i in range(1,d+1): for j in range(1,s+1): mem[i][j]=mem[i][j-1]+mem[i-1][j-1] if j-f-1>=0 : mem[i][j]-=mem[i-1][j-f-1] return mem[d][s] print(findWays(4,2,1)) print(findWays(2,2,3)) print(findWays(6,3,8)) print(findWays(4,2,5)) print(findWays(4,3,5)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (findWays(4, 2, 1))->display() ; execute (findWays(2, 2, 3))->display() ; execute (findWays(6, 3, 8))->display() ; execute (findWays(4, 2, 5))->display() ; execute (findWays(4, 3, 5))->display(); operation findWays(f : OclAny, d : OclAny, s : OclAny) : OclAny pre: true post: true activity: var mem : Sequence := Integer.subrange(0, d + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, s + 1-1)->select(i | true)->collect(i | (0)))) ; mem->first()->first() := 1 ; for i : Integer.subrange(1, d + 1-1) do ( for j : Integer.subrange(1, s + 1-1) do ( mem[i+1][j+1] := mem[i+1][j - 1+1] + mem[i - 1+1][j - 1+1] ; if j - f - 1 >= 0 then ( mem[i+1][j+1] := mem[i+1][j+1] - mem[i - 1+1][j - f - 1+1] ) else skip)) ; return mem[d+1][s+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,z,w=map(int,input().split()) a=[int(i)for i in input().split()] if n==1 : print(abs(a[-1]-w)) else : print(max(abs(a[-1]-w),abs(a[-2]-a[-1]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var z : OclAny := null; var w : OclAny := null; Sequence{n,z,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if n = 1 then ( execute ((a->last() - w)->abs())->display() ) else ( execute (Set{(a->last() - w)->abs(), (a->front()->last() - a->last())->abs()}->max())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import defaultdict,Counter from itertools import product,groupby,count,permutations,combinations from math import pi,sqrt,ceil,floor from collections import deque from bisect import bisect,bisect_left,bisect_right from string import ascii_lowercase INF=float("inf") sys.setrecursionlimit(10**7) dy=[0,-1,0,1] dx=[1,0,-1,0] def inside(y : int,x : int,H : int,W : int)->bool : return 0<=y=2 : ans=max(ans,abs(a_list[-2]-a_list[-1])) print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var INF : double := ("" + (("inf")))->toReal() ; sys.setrecursionlimit((10)->pow(7)) ; var dy : Sequence := Sequence{0}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{ 1 }))) ; var dx : Sequence := Sequence{1}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{ 0 }))) ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation inside(y : int, x : int, H : int, W : int) : boolean pre: true post: true activity: return 0 <= y & (y < H) & 0 <= x & (x < W); operation main() pre: true post: true activity: var N : OclAny := null; var Z : OclAny := null; var W : OclAny := null; Sequence{N,Z,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; ans := Set{ans, (a_list->last() - W)->abs()}->max() ; if N >= 2 then ( ans := Set{ans, (a_list->front()->last() - a_list->last())->abs()}->max() ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import* import heapq import math import bisect import copy from itertools import permutations,accumulate,combinations,product from fractions import gcd def input(): return sys.stdin.readline()[:-1] def ruiseki(lst): return[0]+list(accumulate(lst)) mod=pow(10,9)+7 al=[chr(ord('a')+i)for i in range(26)] direction=[[1,0],[0,1],[-1,0],[0,-1]] n,z,w=map(int,input().split()) a=list(map(int,input().split())) dp=[[-1]*n for i in range(2)] dp[0][-1]=abs(a[-1]-w) for i in range(n-1): for j in range(2): if j==0 : tmp=dp[1-j][-1-i :-1][:] tmp.append(abs(a[-2-i]-a[-1])) dp[j][-2-i]=min(tmp) else : tmp=dp[1-j][-1-i :-1][:] tmp.append(abs(a[-2-i]-a[-1])) dp[j][-2-i]=max(tmp) print(max(dp[0])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; var al : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | ((('a')->char2byte() + i)->byte2char())) ; var direction : Sequence := Sequence{Sequence{1}->union(Sequence{ 0 })}->union(Sequence{Sequence{0}->union(Sequence{ 1 })}->union(Sequence{Sequence{-1}->union(Sequence{ 0 })}->union(Sequence{ Sequence{0}->union(Sequence{ -1 }) }))) ; var n : OclAny := null; var z : OclAny := null; var w : OclAny := null; Sequence{n,z,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dp : Sequence := Integer.subrange(0, 2-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ -1 }, n))) ; dp->first()->last() := (a->last() - w)->abs() ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(0, 2-1) do ( if j = 0 then ( var tmp : OclAny := dp[1 - j+1].subrange(-1 - i+1, -1) ; execute (((a->reverse()->at(-(-2 - i)) - a->last())->abs()) : tmp) ; dp[j+1]->reverse()->at(-(-2 - i)) := (tmp)->min() ) else ( tmp := dp[1 - j+1].subrange(-1 - i+1, -1) ; execute (((a->reverse()->at(-(-2 - i)) - a->last())->abs()) : tmp) ; dp[j+1]->reverse()->at(-(-2 - i)) := (tmp)->max() ))) ; execute ((dp->first())->max())->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation ruiseki(lst : OclAny) : OclAny pre: true post: true activity: return Sequence{ 0 }->union((accumulate(lst))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**5) input=sys.stdin.readline N,Z,W=[int(x)for x in input().strip().split()] a=[int(x)for x in input().strip().split()] d={} def minmax(x,y,c,f): if(c,f)in d : return d[(c,f)] if c==N : return abs(x-y) if f==0 : ret=-float('inf') for i in range(1,N-c+1): ret=max(ret,minmax(a[c+i-1],y,c+i,f ^ 1)) else : ret=float('inf') for i in range(1,N-c+1): ret=min(ret,minmax(x,a[c+i-1],c+i,f ^ 1)) d[(c,f)]=ret return ret print(minmax(Z,W,0,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(5)) ; var input : OclAny := (OclFile["System.in"]).readline ; var N : OclAny := null; var Z : OclAny := null; var W : OclAny := null; Sequence{N,Z,W} := input()->trim().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a : Sequence := input()->trim().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var d : OclAny := Set{} ; skip ; execute (minmax(Z, W, 0, 0))->display(); operation minmax(x : OclAny, y : OclAny, c : OclAny, f : OclAny) : OclAny pre: true post: true activity: if (d)->includes(Sequence{c, f}) then ( return d[Sequence{c, f}+1] ) else skip ; if c = N then ( return (x - y)->abs() ) else skip ; if f = 0 then ( var ret : double := -("" + (('inf')))->toReal() ; for i : Integer.subrange(1, N - c + 1-1) do ( ret := Set{ret, minmax(a[c + i - 1+1], y, c + i, MathLib.bitwiseXor(f, 1))}->max()) ) else ( ret := ("" + (('inf')))->toReal() ; for i : Integer.subrange(1, N - c + 1-1) do ( ret := Set{ret, minmax(x, a[c + i - 1+1], c + i, MathLib.bitwiseXor(f, 1))}->min()) ) ; d[Sequence{c, f}+1] := ret ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,Y,Z=map(int,input().split()) As=list(map(int,input().split())) dpx,dpy=[0]*(N-1),[0]*(N-1) for i in range(N-2,-1,-1): mny,mxx=10**10,0 for j in range(i+1,N-1): mny=min(mny,dpy[j]) mxx=max(mxx,dpx[j]) dpx[i]=min(mny,abs(As[N-1]-As[i])) dpy[i]=min(mxx,abs(As[N-1]-As[i])) dpx.append(abs(As[N-1]-Z)) print(max(dpx)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var Y : OclAny := null; var Z : OclAny := null; Sequence{N,Y,Z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var As : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dpx : OclAny := null; var dpy : OclAny := null; Sequence{dpx,dpy} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, (N - 1)),MatrixLib.elementwiseMult(Sequence{ 0 }, (N - 1))} ; for i : Integer.subrange(-1 + 1, N - 2)->reverse() do ( var mny : OclAny := null; var mxx : OclAny := null; Sequence{mny,mxx} := Sequence{(10)->pow(10),0} ; for j : Integer.subrange(i + 1, N - 1-1) do ( var mny : OclAny := Set{mny, dpy[j+1]}->min() ; var mxx : OclAny := Set{mxx, dpx[j+1]}->max()) ; dpx[i+1] := Set{mny, (As[N - 1+1] - As[i+1])->abs()}->min() ; dpy[i+1] := Set{mxx, (As[N - 1+1] - As[i+1])->abs()}->min()) ; execute (((As[N - 1+1] - Z)->abs()) : dpx) ; execute ((dpx)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_input(): while True : try : yield ''.join(input()) except EOFError : break while True : d=[int(i)for i in input().split()] if d[0]==0 and d[1]==0 and d[2]==0 : break d.sort() cheese=d[0]*d[0]+d[1]*d[1] N=int(input()) for l in range(N): R=int(input())*2 if cheeseselect(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if d->first() = 0 & d[1+1] = 0 & d[2+1] = 0 then ( break ) else skip ; d := d->sort() ; var cheese : double := d->first() * d->first() + d[1+1] * d[1+1] ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for l : Integer.subrange(0, N-1) do ( var R : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() * 2 ; if (cheese->compareTo(R * R)) < 0 then ( execute ("OK")->display() ) else ( execute ("NA")->display() ))); operation get_input(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; while true do ( try ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return StringLib.sumStringsWithSeparator(((OclFile["System.in"]).readLine()), '')) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys data=[] line_num=0 for line in sys.stdin : numbers=[int(x)for x in line.strip().split()] prime=[2,3,5,7,11,13,17,19,23,29,31] if line_num % 2==0 and line_num!=0 : ans={} for num in numbers : for i in range(11): if num % prime[i]==0 : if prime[i]in ans : ans[prime[i]].append(num) else : ans[prime[i]]=[num] break print(len(ans)) arr=list(ans.keys()) res=[] for num in numbers : for k,v in ans.items(): if num in v : res.append(arr.index(k)) break print(" ".join([str(i+1)for i in res])) line_num+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var data : Sequence := Sequence{} ; var line_num : int := 0 ; for line : OclFile["System.in"] do ( var numbers : Sequence := line->trim().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var prime : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{11}->union(Sequence{13}->union(Sequence{17}->union(Sequence{19}->union(Sequence{23}->union(Sequence{29}->union(Sequence{ 31 })))))))))) ; if line_num mod 2 = 0 & line_num /= 0 then ( var ans : OclAny := Set{} ; for num : numbers do ( for i : Integer.subrange(0, 11-1) do ( if num mod prime[i+1] = 0 then ( if (ans)->includes(prime[i+1]) then ( (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name prime)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) )))) ) else ( ans[prime[i+1]+1] := Sequence{ num } ) ; break ) else skip)) ; execute ((ans)->size())->display() ; var arr : Sequence := (ans.keys()) ; var res : Sequence := Sequence{} ; for num : numbers do ( for _tuple : ans->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if (v)->includes(num) then ( execute ((arr->indexOf(k) - 1) : res) ; break ) else skip)) ; execute (StringLib.sumStringsWithSeparator((res->select(i | true)->collect(i | (("" + ((i + 1)))))), " "))->display() ) else skip ; line_num := line_num + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import time from collections import defaultdict,deque from sys import stdin,stdout from bisect import bisect_left,bisect_right t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,stdin.readline().split())) color=defaultdict(lambda :-1) primes=[2,3,5,7,11,13,17,19,23,29,31] curr=1 for i in primes : thereis=False for j in a : if(j not in color and j % i==0): color[j]=curr thereis=True if(thereis): curr+=1 print(curr-1) for i in a : print(color[i],end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var color : OclAny := defaultdict(lambda $$ : OclAny in (-1)) ; var primes : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{11}->union(Sequence{13}->union(Sequence{17}->union(Sequence{19}->union(Sequence{23}->union(Sequence{29}->union(Sequence{ 31 })))))))))) ; var curr : int := 1 ; for i : primes do ( var thereis : boolean := false ; for j : a do ( if ((color)->excludes(j) & j mod i = 0) then ( color[j+1] := curr ; thereis := true ) else skip) ; if (thereis) then ( curr := curr + 1 ) else skip) ; execute (curr - 1)->display() ; for i : a do ( execute (color[i+1])->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) print(max([min([a[i+2]-a[i]for i in range(n-2)])]+[a[i+1]-a[i]for i in range(n-1)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((Sequence{ (Integer.subrange(0, n - 2-1)->select(i | true)->collect(i | (a[i + 2+1] - a[i+1])))->min() }->union(Integer.subrange(0, n - 1-1)->select(i | true)->collect(i | (a[i + 1+1] - a[i+1]))))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def coloring(lst): nlst=[] primes=[2,3,5,7,11,13,17,19,23,29,31] for i in lst : for j in range(11): if i % primes[j]==0 : nlst.append(j+1) break n=1 dic={} for i in set(nlst): dic[i]=n n+=1 for j in range(len(nlst)): nlst[j]=dic[nlst[j]] return[len(dic),nlst] t=int(input()) all_com=[] for i in range(t): n=int(input()) composites=[int(i)for i in input().split()] all_com.append(composites) [c_num,pattern]=coloring(composites) print(c_num) print(" ".join(str(x)for x in pattern)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var all_com : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var composites : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute ((composites) : all_com)) ; Sequence{c_num}->union(Sequence{ pattern }) := coloring(composites); operation coloring(lst : OclAny) : OclAny pre: true post: true activity: var nlst : Sequence := Sequence{} ; var primes : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{11}->union(Sequence{13}->union(Sequence{17}->union(Sequence{19}->union(Sequence{23}->union(Sequence{29}->union(Sequence{ 31 })))))))))) ; for i : lst do ( for j : Integer.subrange(0, 11-1) do ( if i mod primes[j+1] = 0 then ( execute ((j + 1) : nlst) ; break ) else skip)) ; var n : int := 1 ; var dic : OclAny := Set{} ; for i : Set{}->union((nlst)) do ( dic[i+1] := n ; n := n + 1) ; for j : Integer.subrange(0, (nlst)->size()-1) do ( nlst[j+1] := dic[nlst[j+1]+1]) ; return Sequence{(dic)->size()}->union(Sequence{ nlst }); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict d=[2,3,5,7,11,13,17,19,23,29,31] for _ in range(int(input())): n=int(input()) a=[int(i)for i in input().split()] cnt=defaultdict(list) for k in range(n): for i in d : if a[k]% i==0 : cnt[i].append(k) break m=0 colors=[0]*n for i in cnt : m+=1 for j in cnt[i]: colors[j]=m print(m) print(*colors) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var d : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{11}->union(Sequence{13}->union(Sequence{17}->union(Sequence{19}->union(Sequence{23}->union(Sequence{29}->union(Sequence{ 31 })))))))))) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var cnt : OclAny := defaultdict(OclType["Sequence"]) ; for k : Integer.subrange(0, n-1) do ( for i : d do ( if a[k+1] mod i = 0 then ( (expr (atom (name cnt)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name k)))))))) )))) ; break ) else skip)) ; var m : int := 0 ; var colors : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : cnt do ( m := m + 1 ; for j : cnt[i+1] do ( colors[j+1] := m)) ; execute (m)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name colors))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def innerCirclearea(radius): if(radius<0): return-1 ; r=radius/2 ; Area=(3.14*pow(r,2)); return Area ; if __name__=="__main__" : radius=4 ; print("Area of circle c2=",innerCirclearea(radius)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( radius := 4; ; execute ("Area of circle c2=")->display(); ) else skip; operation innerCirclearea(radius : OclAny) pre: true post: true activity: if (radius < 0) then ( return -1; ) else skip ; var r : double := radius / 2; ; var Area : double := (3.14 * (r)->pow(2)); ; return Area;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getXandYintercept(P,Q): a=P[1]-Q[1] b=P[0]-Q[0] if b==0 : print(P[0]) print("infinity") return if a==0 : print("infinity") print(P[1]) return m=a/b x=P[0] y=P[1] c=y-m*x y=0 x=(y-c)/m print(x) x=0 y=m*x+c print(y) p1=[5,2] p2=[7,2] getXandYintercept(p1,p2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var p1 : Sequence := Sequence{5}->union(Sequence{ 2 }) ; var p2 : Sequence := Sequence{7}->union(Sequence{ 2 }) ; getXandYintercept(p1, p2); operation getXandYintercept(P : OclAny, Q : OclAny) pre: true post: true activity: var a : double := P[1+1] - Q[1+1] ; var b : double := P->first() - Q->first() ; if b = 0 then ( execute (P->first())->display() ; execute ("infinity")->display() ; return ) else skip ; if a = 0 then ( execute ("infinity")->display() ; execute (P[1+1])->display() ; return ) else skip ; var m : double := a / b ; var x : OclAny := P->first() ; var y : OclAny := P[1+1] ; var c : double := y - m * x ; y := 0 ; x := (y - c) / m ; execute (x)->display() ; x := 0 ; y := m * x + c ; execute (y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxConsecutiveOnes(x): count=0 ; while(x!=0): x=(x &(x<<1)); count+=1 ; return count ; def maxOnes(arr,n): ans=0 ; for i in range(n): currMax=maxConsecutiveOnes(arr[i]); ans=max(ans,currMax); return ans ; if __name__=="__main__" : arr=[1,2,3,4]; n=len(arr); print(maxOnes(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))); ; n := (arr)->size(); ; execute (maxOnes(arr, n))->display(); ) else skip; operation maxConsecutiveOnes(x : OclAny) pre: true post: true activity: var count : int := 0; ; while (x /= 0) do ( x := (MathLib.bitwiseAnd(x, (x * (2->pow(1))))); ; count := count + 1;) ; return count;; operation maxOnes(arr : OclAny, n : OclAny) pre: true post: true activity: var ans : int := 0; ; for i : Integer.subrange(0, n-1) do ( var currMax : OclAny := maxConsecutiveOnes(arr[i+1]); ; ans := Set{ans, currMax}->max();) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=map(int,input().split()) if x % y==0 : print(0) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x mod y = 0 then ( execute (0)->display() ) else ( execute (1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline sys.setrecursionlimit(10**6) n,k=map(int,input().split()) print(0 if n % k==0 else 1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit((10)->pow(6)) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if n mod k = 0 then 0 else 1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=[int(x)for x in input().split()] print(0 if N % K==0 else 1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (if N mod K = 0 then 0 else 1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- alfie="abcdefghijklmnopqrstuvwxyz" s1=input() s2=input() l1=list(s1) l2=list(s2) done=0 for x in range(len(l1)): if alfie.index(l1[x])characters() ; var l2 : Sequence := (s2)->characters() ; var done : int := 0 ; for x : Integer.subrange(0, (l1)->size()-1) do ( if (alfie->indexOf(l1[x+1]) - 1->compareTo(alfie->indexOf(l2[x+1]) - 1)) < 0 then ( done := 1 ; break ) else skip) ; if done then ( execute (-1)->display() ) else ( execute (s2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import gcd n=int(input()) arr_list=list(map(int,input().split())) arr_2=[0]*n ans=1 for i in range(n): if(arr_2[i]): continue num=i j=0 while not arr_2[num]: arr_2[num]=1 num=arr_list[num]-1 j+=1 if(i!=num): ans=-1 break else : if(j % 2==0): j//=2 ans=ans*j//gcd(ans,j) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var arr:= MatrixLib.elementwiseMult(Sequence{ 0 }, n) : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var ans : int := 1 ; for i : Integer.subrange(0, n-1) do ( if (arr continue[i+1]) then ( continue ) else skip ; var num : OclAny := i ; var j : int := 0 ; while not(arr arr:= 1[num+1] := 1 ; num := arr_list[num+1] - 1 ; j := j + 1[num+1]) do ( arr:= 1[num+1] := 1 ; num := arr_list[num+1] - 1 ; j := j + 1) ; if (i /= num) then ( ans := -1 ; break ) else ( if (j mod 2 = 0) then ( j := j div 2 ) else skip ; ans := ans * j div gcd(ans, j) )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) l=list(map(int,input().split())) po1=0 po2=1 mini=10000000 for i in range(1,x-1): l2=l.copy() l2.pop(i) maxy=0 po1=0 po2=1 while po2maxy : maxy=l2[po2]-l2[po1] po1+=1 po2+=1 if maxytoInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var po1 : int := 0 ; var po2 : int := 1 ; var mini : int := 10000000 ; for i : Integer.subrange(1, x - 1-1) do ( var l2 : OclAny := l->copy() ; l2 := l2->excludingAt(i+1) ; var maxy : int := 0 ; po1 := 0 ; po2 := 1 ; while (po2->compareTo((l2)->size())) < 0 do ( if ((l2[po2+1] - l2[po1+1])->compareTo(maxy)) > 0 then ( maxy := l2[po2+1] - l2[po1+1] ) else skip ; po1 := po1 + 1 ; po2 := po2 + 1) ; if (maxy->compareTo(mini)) < 0 then ( mini := maxy ) else skip) ; execute (mini)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- split=input().split() n=int(split[0]) k=int(split[1]) if n % k==0 : print(0) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var split : OclAny := input().split() ; var n : int := ("" + ((split->first())))->toInteger() ; var k : int := ("" + ((split[1+1])))->toInteger() ; if n mod k = 0 then ( execute (0)->display() ) else ( execute (1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) print("1" if n % k>0 else "0") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if n mod k > 0 then "1" else "0" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def PrintMinNumberForPattern(arr): curr_max=0 last_entry=0 i=0 while icompareTo((arr)->size())) < 0 do ( var noOfNextD : int := 0 ; if arr[i+1] = "I" then ( var j : int := i + 1 ; while (j->compareTo((arr)->size())) < 0 & arr[j+1] = "D" do ( noOfNextD := noOfNextD + 1 ; j := j + 1) ; if i = 0 then ( curr_max := noOfNextD + 2 ; last_entry := last_entry + 1 ; execute ("")->display() ; execute ("")->display() ; last_entry := curr_max ) else ( curr_max := curr_max + noOfNextD + 1 ; last_entry := curr_max ; execute ("")->display() ) ; for k : Integer.subrange(0, noOfNextD-1) do ( last_entry := last_entry - 1 ; execute ("")->display() ; i := i + 1) ) else (if arr[i+1] = "D" then ( if i = 0 then ( j := i + 1 ; while (j->compareTo((arr)->size())) < 0 & arr[j+1] = "D" do ( noOfNextD := noOfNextD + 1 ; j := j + 1) ; curr_max := noOfNextD + 2 ; execute ("")->display() ; last_entry := curr_max - 1 ) else ( execute ("")->display() ; last_entry := last_entry - 1 ) ) else skip) ; i := i + 1) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def root(nodes,x): if nodes[x]<0 : return x else : nodes[x]=root(nodes,nodes[x]) return nodes[x] def unite(nodes,x,y): root_x,root_y=root(nodes,x),root(nodes,y) if root_x!=root_y : nodes[root_x]=root_y def is_same(nodes,x,y): return root(nodes,x)==root(nodes,y) N,M=list(map(int,input().split())) data=[[0 for s in range(2)]for k in range(M)] for i in range(M): temp=input().split() data[i][0]=int(temp[0])-1 data[i][1]=int(temp[1])-1 sum=0 for i in range(M): nodes=[-1]*(N) for j in range(M): if j!=i : unite(nodes,data[j][0],data[j][1]) for k in range(1,N): if is_same(nodes,k-1,k): continue else : sum+=1 break print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var data : Sequence := Integer.subrange(0, M-1)->select(k | true)->collect(k | (Integer.subrange(0, 2-1)->select(s | true)->collect(s | (0)))) ; for i : Integer.subrange(0, M-1) do ( var temp : OclAny := input().split() ; data[i+1]->first() := ("" + ((temp->first())))->toInteger() - 1 ; data[i+1][1+1] := ("" + ((temp[1+1])))->toInteger() - 1) ; var sum : int := 0 ; for i : Integer.subrange(0, M-1) do ( nodes := MatrixLib.elementwiseMult(Sequence{ -1 }, (N)) ; for j : Integer.subrange(0, M-1) do ( if j /= i then ( unite(nodes, data[j+1]->first(), data[j+1][1+1]) ) else skip) ; for k : Integer.subrange(1, N-1) do ( if is_same(nodes, k - 1, k) then ( continue ) else ( sum := sum + 1 ; break ))) ; execute (sum)->display(); operation root(nodes : OclAny, x : OclAny) : OclAny pre: true post: true activity: if nodes[x+1] < 0 then ( return x ) else ( nodes[x+1] := root(nodes, nodes[x+1]) ; return nodes[x+1] ); operation unite(nodes : OclAny, x : OclAny, y : OclAny) pre: true post: true activity: var root_x : OclAny := null; var root_y : OclAny := null; Sequence{root_x,root_y} := Sequence{root(nodes, x),root(nodes, y)} ; if root_x /= root_y then ( nodes[root_x+1] := root_y ) else skip; operation is_same(nodes : OclAny, x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return root(nodes, x) = root(nodes, y); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy from scipy.sparse.csgraph import floyd_warshall N,M=map(int,input().split()) graph=[[0 for _ in range(N)]for _ in range(N)] ab=[] for _ in range(M): a1,b1=map(int,input().split()) ab.append([a1,b1]) graph[a1-1][b1-1]=1 graph[b1-1][a1-1]=1 ans=0 for i,j in ab : d=copy.deepcopy(graph) d[i-1][j-1]=0 d[j-1][i-1]=0 d=floyd_warshall(d) for k in range(1,N): if d[0][k]==float("inf"): ans+=1 break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var graph : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (0)))) ; var ab : Sequence := Sequence{} ; for _anon : Integer.subrange(0, M-1) do ( var a1 : OclAny := null; var b1 : OclAny := null; Sequence{a1,b1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a1}->union(Sequence{ b1 })) : ab) ; graph[a1 - 1+1][b1 - 1+1] := 1 ; graph[b1 - 1+1][a1 - 1+1] := 1) ; var ans : int := 0 ; for _tuple : ab do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); var d : OclAny := copy.deepcopy(graph) ; d[i - 1+1][j - 1+1] := 0 ; d[j - 1+1][i - 1+1] := 0 ; d := floyd_warshall(d) ; for k : Integer.subrange(1, N-1) do ( if d->first()[k+1] = ("" + (("inf")))->toReal() then ( ans := ans + 1 ; break ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dfs(index,connects): global IS_VISITED if index in connects.keys(): IS_VISITED[index]=True nodes=[x for x in connects[index]] else : return for node in nodes : if IS_VISITED[node]==False : dfs(node,connects) def is_connected(inputs): global IS_VISITED connects={} for edge in inputs : edge=[int(edge[0]),int(edge[1])] if edge[0]in connects.keys(): connects[edge[0]].append(edge[1]) else : connects[edge[0]]=[edge[1]] if edge[1]in connects.keys(): connects[edge[1]].append(edge[0]) else : connects[edge[1]]=[edge[0]] IS_VISITED=[True]+[False for x in range(int(N))] dfs(1,connects) return len(IS_VISITED)is not len([1 for idx in range(len(IS_VISITED))if IS_VISITED[idx]]) N,_=input().split(" ") IS_VISITED=[] inputs=[] while True : try : inputs.append(input().split(" ")) except EOFError : break count=0 for i in range(len(inputs)): if is_connected(inputs[: i]+inputs[i+1 :]): count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute IS_VISITED : OclAny; attribute IS_VISITED : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := null; var _anon : OclAny := null; Sequence{N,_anon} := input().split(" ") ; IS_VISITED := Sequence{} ; inputs := Sequence{} ; while true do ( try ( execute ((input().split(" ")) : inputs)) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))) ; var count : int := 0 ; for i : Integer.subrange(0, (inputs)->size()-1) do ( if is_connected(inputs.subrange(1,i) + inputs.subrange(i + 1+1)) then ( count := count + 1 ) else skip) ; execute (count)->display(); operation dfs(index : OclAny, connects : OclAny) pre: true post: true activity: skip ; if (connects.keys())->includes(index) then ( IS_VISITED[index+1] := true ; var nodes : Sequence := connects[index+1]->select(x | true)->collect(x | (x)) ) else ( return ) ; for node : nodes do ( if IS_VISITED[node+1] = false then ( dfs(node, connects) ) else skip); operation is_connected(inputs : OclAny) : OclAny pre: true post: true activity: skip ; connects := Set{} ; for edge : inputs do ( var edge : Sequence := Sequence{("" + ((edge->first())))->toInteger()}->union(Sequence{ ("" + ((edge[1+1])))->toInteger() }) ; if (connects.keys())->includes(edge->first()) then ( (expr (atom (name connects)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))) ) else ( connects[edge->first()+1] := Sequence{ edge[1+1] } ) ; if (connects.keys())->includes(edge[1+1]) then ( (expr (atom (name connects)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))) ) else ( connects[edge[1+1]+1] := Sequence{ edge->first() } )) ; IS_VISITED := Sequence{ true }->union(Integer.subrange(0, ("" + ((N)))->toInteger()-1)->select(x | true)->collect(x | (false))) ; dfs(1, connects) ; return not((IS_VISITED)->size() <>= (Integer.subrange(0, (IS_VISITED)->size()-1)->select(idx | IS_VISITED[idx+1])->collect(idx | (1)))->size()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict import queue N,M=map(int,input().split()) ab=[] d=defaultdict(list) for i in range(M): a,b=map(int,input().split()) ab.append((a,b)) d[a].append(b) d[b].append(a) ans=0 for i in range(M): Remove=ab[i] d[Remove[0]].remove(Remove[1]) d[Remove[1]].remove(Remove[0]) dist=[False]*N q=queue.Queue() q.put(list(d.keys())[0]) while not q.empty(): From=q.get() dist[From-1]=True for g in d[From]: if dist[g-1]==False : q.put(g) if False in dist : ans+=1 d[Remove[0]].append(Remove[1]) d[Remove[1]].append(Remove[0]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ab : Sequence := Sequence{} ; var d : OclAny := defaultdict(OclType["Sequence"]) ; for i : Integer.subrange(0, M-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a, b}) : ab) ; (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var ans : int := 0 ; for i : Integer.subrange(0, M-1) do ( var Remove : OclAny := ab[i+1] ; (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name Remove)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])) (trailer . (name remove) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name Remove)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))) ; (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name Remove)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ])) (trailer . (name remove) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name Remove)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))) ; var dist : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, N) ; var q : OclAny := queue.Queue() ; q.put(OclType["Sequence"](d.keys())->first()) ; while not(q.empty()) do ( var From : OclAny := q.get() ; dist[From - 1+1] := true ; for g : d[From+1] do ( if dist[g - 1+1] = false then ( q.put(g) ) else skip)) ; if (dist)->includes(false) then ( ans := ans + 1 ) else skip ; (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name Remove)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name Remove)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))) ; (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name Remove)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name Remove)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=(int(x)for x in input().split()) edge=[tuple(int(x)for x in input().split())for _ in range(M)] import numpy as np from scipy.sparse.csgraph import floyd_warshall INF=100 tmpl_graph=[[INF if i!=j else 0 for j in range(N)]for i in range(N)] ans=0 for E in edge : edgeWithoutE=edge.copy() edgeWithoutE.remove(E) graph=np.array(tmpl_graph) for x in edgeWithoutE : graph[x[0]-1,x[1]-1]=1 graph[x[1]-1,x[0]-1]=1 graph=floyd_warshall(graph,directed=False) if len(graph[graph==100])>0 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var edge : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))))) ; skip ; skip ; var INF : int := 100 ; var tmpl_graph : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Integer.subrange(0, N-1)->select(j | true)->collect(j | (if i /= j then INF else 0 endif)))) ; var ans : int := 0 ; for E : edge do ( var edgeWithoutE : OclAny := edge->copy() ; execute ((E) /: edgeWithoutE) ; var graph : Sequence := (tmpl_graph) ; for x : edgeWithoutE do ( graph[x->first() - 1+1][x[1+1] - 1+1] := 1 ; graph[x[1+1] - 1+1][x->first() - 1+1] := 1) ; graph := floyd_warshall(graph, (argument (test (logical_test (comparison (expr (atom (name directed)))))) = (test (logical_test (comparison (expr (atom (name False)))))))) ; if (graph->select(graph = 100))->size() > 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=10 def isDigit(ch): ch=ord(ch) if(ch>=ord('0')and ch<=ord('9')): return True return False def allDigits(st,le): present=[False for i in range(MAX)] for i in range(le): if(isDigit(st[i])): digit=ord(st[i])-ord('0') present[digit]=True for i in range(MAX): if(present[i]==False): return False return True st="Geeks12345for69708" le=len(st) if(allDigits(st,le)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 10 ; skip ; skip ; st := "Geeks12345for69708" ; le := (st)->size() ; if (allDigits(st, le)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isDigit(ch : OclAny) : OclAny pre: true post: true activity: ch := (ch)->char2byte() ; if ((ch->compareTo(('0')->char2byte())) >= 0 & (ch->compareTo(('9')->char2byte())) <= 0) then ( return true ) else skip ; return false; operation allDigits(st : OclAny, le : OclAny) : OclAny pre: true post: true activity: var present : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (false)) ; for i : Integer.subrange(0, le-1) do ( if (isDigit(st[i+1])) then ( var digit : double := (st[i+1])->char2byte() - ('0')->char2byte() ; present[digit+1] := true ) else skip) ; for i : Integer.subrange(0, MAX-1) do ( if (present[i+1] = false) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def makeSeq(s,a): seq=[]; for i in range(len(s)): if(s[i]=='A'): seq.append(a[i]); for i in range(len(s)): if(s[i]=='B'): seq.append(a[i]); return seq ; def checkSeq(v): check=True ; for i in range(1,len(v)): if(v[i]D): res+='B' ; else : res+='C' ; flag=False ; for i in range(l): if(res[i]=='B'): flag=True ; res=list(res); if(res[i]=='C'): res[i]='A' if flag else 'B' ; seq=makeSeq(res,a); if(checkSeq(seq)): return "".join(res); return "-1" ; if __name__=="__main__" : X=777147777 ; print(digitPartition(X)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( X := 777147777; ; execute (digitPartition(X))->display(); ) else skip; operation makeSeq(s : OclAny, a : OclAny) pre: true post: true activity: var seq : Sequence := Sequence{}; ; for i : Integer.subrange(0, (s)->size()-1) do ( if (s[i+1] = 'A') then ( execute ((a[i+1]) : seq); ) else skip) ; for i : Integer.subrange(0, (s)->size()-1) do ( if (s[i+1] = 'B') then ( execute ((a[i+1]) : seq); ) else skip) ; return seq;; operation checkSeq(v : OclAny) pre: true post: true activity: var check : boolean := true; ; for i : Integer.subrange(1, (v)->size()-1) do ( if ((v[i+1]->compareTo(v[i - 1+1])) < 0) then ( check := false; ) else skip) ; return check;; operation digitPartition(X : OclAny) pre: true post: true activity: var num : String := ("" + ((X))); ; var l : int := (num)->size(); ; a := MatrixLib.elementwiseMult(Sequence{ 0 }, l); ; for i : Integer.subrange(0, l-1) do ( a[i+1] := ((num[i+1])->char2byte() - ('0')->char2byte());) ; for D : Integer.subrange(0, 10-1) do ( var res : String := ""; ; for i : Integer.subrange(0, l-1) do ( if ((a[i+1]->compareTo(D)) < 0) then ( res := res + 'A'; ) else (if ((a[i+1]->compareTo(D)) > 0) then ( res := res + 'B'; ) else ( res := res + 'C'; ) ) ) ; var flag : boolean := false; ; for i : Integer.subrange(0, l-1) do ( if (res[i+1] = 'B') then ( flag := true; ) else skip ; res := (res)->characters(); ; if (res[i+1] = 'C') then ( res[i+1] := if flag then 'A' else 'B' endif; ) else skip) ; seq := makeSeq(res, a); ; if (checkSeq(seq)) then ( return StringLib.sumStringsWithSeparator((res), ""); ) else skip) ; return "-1";; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- L=list(map(int,input().strip())) ans=1 S=0 mod=10**9+7 for l in L : S+=l ans=(3*ans-(1-l)*pow(2,S+1,mod))% mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var L : Sequence := ((input()->trim())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 1 ; var S : int := 0 ; var mod : double := (10)->pow(9) + 7 ; for l : L do ( S := S + l ; ans := (3 * ans - (1 - l) * (2)->pow(S + 1)) mod mod) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): n=int(input()) arr=list(map(int,input().split())) mx=max([arr[i]-arr[i-1]for i in range(1,n)]) res=float("inf") for i in range(1,n-1): cur=max(arr[i+1]-arr[i-1],mx) res=min(res,cur) print(res) def main(): t=1 for _ in range(t): solution() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; main(); operation solution() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mx : OclAny := (Integer.subrange(1, n-1)->select(i | true)->collect(i | (arr[i+1] - arr[i - 1+1])))->max() ; var res : double := ("" + (("inf")))->toReal() ; for i : Integer.subrange(1, n - 1-1) do ( var cur : OclAny := Set{arr[i + 1+1] - arr[i - 1+1], mx}->max() ; res := Set{res, cur}->min()) ; execute (res)->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) if sorted(a)!=list(range(1,n+1)): exit(print(-1)) a=[i-1 for i in a] ans=1 from math import gcd for i in range(n): now=i cnt=-1 for j in range(1,n+2): now=a[now] if now==i : cnt=j break else : continue if cnt % 2==0 : cnt//=2 ans=ans*cnt//gcd(ans,cnt) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if a->sort() /= (Integer.subrange(1, n + 1-1)) then ( exit((-1)->display()) ) else skip ; a := a->select(i | true)->collect(i | (i - 1)) ; var ans : int := 1 ; skip ; for i : Integer.subrange(0, n-1) do ( var now : OclAny := i ; var cnt : int := -1 ; (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 2)))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name now)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name now)))))))) ])))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name now)))) == (comparison (expr (atom (name i))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cnt)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name j)))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt continue)))))) ; if cnt mod 2 = 0 then ( cnt := cnt div 2 ) else skip ; ans := ans * cnt div gcd(ans, cnt)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solution(n,k,arr): d=max(arr) arr1=[d-x for x in arr] k-=1 if k % 2==0 : return arr1 else : d=max(arr1) arr2=[d-x for x in arr1] return arr2 t=int(input()) while t : n,k=[int(x)for x in input().strip().split(" ")] arr=[int(x)for x in input().strip().split(" ")] arr=solution(n,k,arr) print(*arr) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( Sequence{n,k} := input()->trim().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; arr := input()->trim().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; arr := solution(n, k, arr) ; execute ((argument * (test (logical_test (comparison (expr (atom (name arr))))))))->display() ; t := t - 1); operation solution(n : OclAny, k : OclAny, arr : OclAny) : OclAny pre: true post: true activity: var d : OclAny := (arr)->max() ; var arr1 : Sequence := arr->select(x | true)->collect(x | (d - x)) ; k := k - 1 ; if k mod 2 = 0 then ( return arr1 ) else ( d := (arr1)->max() ; var arr2 : Sequence := arr1->select(x | true)->collect(x | (d - x)) ; return arr2 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t=int(input()) ans=[] for _ in range(t): n,k=map(int,input().split()) a=list(map(int,input().split())) for _ in range((k-1)% 2+1): d=max(a) for i in range(n): a[i]=d-a[i] ans.append(" ".join(map(str,a))) sys.stdout.write("\n".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for _anon : Integer.subrange(0, (k - 1) mod 2 + 1-1) do ( var d : OclAny := (a)->max() ; for i : Integer.subrange(0, n-1) do ( a[i+1] := d - a[i+1])) ; execute ((StringLib.sumStringsWithSeparator(((a)->collect( _x | (OclType["String"])->apply(_x) )), " ")) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) t,=R() exec(t*'n,k=R();a=*R(),;M=max(a);m=min(a);print(*((x-m,M-x)[k%2]for x in a));') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := R->apply() ; (expr (expr (atom (name t))) * (expr (atom 'n,k=R();a=*R(),;M=max(a);m=min(a);print(*((x-m,M-x)[k%2]for x in a));'))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) l=list(map(int,input().split())) if n==1 : print(0) else : if k % 2==0 : ind=2 else : ind=1 for _ in range(ind): m=max(l) for i in range(n): l[i]=m-l[i] print(*l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = 1 then ( execute (0)->display() ) else ( if k mod 2 = 0 then ( var ind : int := 2 ) else ( ind := 1 ) ; for _anon : Integer.subrange(0, ind-1) do ( var m : OclAny := (l)->max() ; for i : Integer.subrange(0, n-1) do ( l[i+1] := m - l[i+1])) ; execute ((argument * (test (logical_test (comparison (expr (atom (name l))))))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solution(n,k,arr): d=max(arr) arr1=[d-x for x in arr] k-=1 if k==0 : return arr1 d=max(arr1) arr2=[d-x for x in arr1] k-=1 if k % 2==0 : return arr2 else : return arr1 t=int(input()) while t : n,k=[int(x)for x in input().strip().split(" ")] arr=[int(x)for x in input().strip().split(" ")] arr=solution(n,k,arr) print(*arr) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( Sequence{n,k} := input()->trim().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; arr := input()->trim().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; arr := solution(n, k, arr) ; execute ((argument * (test (logical_test (comparison (expr (atom (name arr))))))))->display() ; t := t - 1); operation solution(n : OclAny, k : OclAny, arr : OclAny) : OclAny pre: true post: true activity: var d : OclAny := (arr)->max() ; var arr1 : Sequence := arr->select(x | true)->collect(x | (d - x)) ; k := k - 1 ; if k = 0 then ( return arr1 ) else skip ; d := (arr1)->max() ; var arr2 : Sequence := arr1->select(x | true)->collect(x | (d - x)) ; k := k - 1 ; if k mod 2 = 0 then ( return arr2 ) else ( return arr1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxDiff(arr,n): maxDiff=-1 maxRight=arr[n-1] for i in range(n-2,-1,-1): if(arr[i]>maxRight): maxRight=arr[i] else : diff=maxRight-arr[i] if(diff>maxDiff): maxDiff=diff return maxDiff if __name__=='__main__' : arr=[1,2,90,10,110] n=len(arr) print("Maximum difference is",maxDiff(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{90}->union(Sequence{10}->union(Sequence{ 110 })))) ; n := (arr)->size() ; execute ("Maximum difference is")->display() ) else skip; operation maxDiff(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var maxDiff : int := -1 ; var maxRight : OclAny := arr[n - 1+1] ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( if ((arr[i+1]->compareTo(maxRight)) > 0) then ( maxRight := arr[i+1] ) else ( var diff : double := maxRight - arr[i+1] ; if ((diff->compareTo(maxDiff)) > 0) then ( maxDiff := diff ) else skip )) ; return maxDiff; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countWays(n,l,r): tL,tR=l,r L=[0 for i in range(2)] R=[0 for i in range(2)] L[l % 2]=l R[r % 2]=r l+=1 r-=1 if(l<=tR and r>=tL): L[l % 2],R[r % 2]=l,r cnt0,cnt1=0,0 if(R[0]and L[0]): cnt0=(R[0]-L[0])//2+1 if(R[1]and L[1]): cnt1=(R[1]-L[1])//2+1 dp=[[0 for i in range(2)]for i in range(n+1)] dp[1][0]=cnt0 dp[1][1]=cnt1 for i in range(2,n+1): dp[i][0]=(cnt0*dp[i-1][0]+cnt1*dp[i-1][1]) dp[i][1]=(cnt0*dp[i-1][1]+cnt1*dp[i-1][0]) return dp[n][0] n,l,r=2,1,3 print(countWays(n,l,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{n,l,r} := Sequence{2,1,3} ; execute (countWays(n, l, r))->display(); operation countWays(n : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var tL : OclAny := null; var tR : OclAny := null; Sequence{tL,tR} := Sequence{l,r} ; var L : Sequence := Integer.subrange(0, 2-1)->select(i | true)->collect(i | (0)) ; var R : Sequence := Integer.subrange(0, 2-1)->select(i | true)->collect(i | (0)) ; L[l mod 2+1] := l ; R[r mod 2+1] := r ; l := l + 1 ; r := r - 1 ; if ((l->compareTo(tR)) <= 0 & (r->compareTo(tL)) >= 0) then ( var L[l mod 2+1] : OclAny := null; var R[r mod 2+1] : OclAny := null; Sequence{L[l mod 2+1],R[r mod 2+1]} := Sequence{l,r} ) else skip ; var cnt0 : OclAny := null; var cnt1 : OclAny := null; Sequence{cnt0,cnt1} := Sequence{0,0} ; if (R->first() & L->first()) then ( var cnt0 : int := (R->first() - L->first()) div 2 + 1 ) else skip ; if (R[1+1] & L[1+1]) then ( var cnt1 : int := (R[1+1] - L[1+1]) div 2 + 1 ) else skip ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, 2-1)->select(i | true)->collect(i | (0)))) ; dp[1+1]->first() := cnt0 ; dp[1+1][1+1] := cnt1 ; for i : Integer.subrange(2, n + 1-1) do ( dp[i+1]->first() := (cnt0 * dp[i - 1+1]->first() + cnt1 * dp[i - 1+1][1+1]) ; dp[i+1][1+1] := (cnt0 * dp[i - 1+1][1+1] + cnt1 * dp[i - 1+1]->first())) ; return dp[n+1]->first(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def isBetween(a,b,c): return min(a,b)<=c and c<=max(a,b) def canJoin(x,y,i,j,k): return(x[k]==x[i]or x[k]==x[j])and isBetween(y[i],y[j],y[k])or(y[k]==y[i]or y[k]==y[j])and isBetween(x[i],x[j],x[k]) def countLineSegments(x,y): if((x[0]==x[1]and x[1]==x[2])or(y[0]==y[1]and y[1]==y[2])): return 1 elif(canJoin(x,y,0,1,2)or canJoin(x,y,0,2,1)or canJoin(x,y,1,2,0)): return 2 else : return 3 x=[-1,-1,4] y=[-1,3,3] print(countLineSegments(x,y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; x := Sequence{-1}->union(Sequence{-1}->union(Sequence{ 4 })) ; y := Sequence{-1}->union(Sequence{3}->union(Sequence{ 3 })) ; execute (countLineSegments(x, y))->display(); operation isBetween(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: return (Set{a, b}->min()->compareTo(c)) <= 0 & (c->compareTo(Set{a, b}->max())) <= 0; operation canJoin(x : OclAny, y : OclAny, i : OclAny, j : OclAny, k : OclAny) : OclAny pre: true post: true activity: return (x[k+1] = x[i+1] or x[k+1] = x[j+1]) & isBetween(y[i+1], y[j+1], y[k+1]) or (y[k+1] = y[i+1] or y[k+1] = y[j+1]) & isBetween(x[i+1], x[j+1], x[k+1]); operation countLineSegments(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if ((x->first() = x[1+1] & x[1+1] = x[2+1]) or (y->first() = y[1+1] & y[1+1] = y[2+1])) then ( return 1 ) else (if (canJoin(x, y, 0, 1, 2) or canJoin(x, y, 0, 2, 1) or canJoin(x, y, 1, 2, 0)) then ( return 2 ) else ( return 3 ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def SieveOfSundaram(marked,nNew): for i in range(1,nNew+1): for j in range(i,nNew): if i+j+2*i*j>nNew : break marked[i+j+2*i*j]=True def countPrimePairs(n): nNew=(n-2)//2 marked=[False for i in range(nNew+1)] SieveOfSundaram(marked,nNew) count,prime_num=0,0 for i in range(1,nNew+1): if(marked[i]==False): prime_num=2*i+1 count=count+(prime_num//2) return count n=12 print("Number of prime pairs: ",countPrimePairs(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 12 ; execute ("Number of prime pairs: ")->display(); operation SieveOfSundaram(marked : OclAny, nNew : OclAny) pre: true post: true activity: for i : Integer.subrange(1, nNew + 1-1) do ( for j : Integer.subrange(i, nNew-1) do ( if (i + j + 2 * i * j->compareTo(nNew)) > 0 then ( break ) else skip ; marked[i + j + 2 * i * j+1] := true)); operation countPrimePairs(n : OclAny) : OclAny pre: true post: true activity: nNew := (n - 2) div 2 ; marked := Integer.subrange(0, nNew + 1-1)->select(i | true)->collect(i | (false)) ; SieveOfSundaram(marked, nNew) ; var count : OclAny := null; var prime_num : OclAny := null; Sequence{count,prime_num} := Sequence{0,0} ; for i : Integer.subrange(1, nNew + 1-1) do ( if (marked[i+1] = false) then ( var prime_num : double := 2 * i + 1 ; var count : OclAny := count + (prime_num div 2) ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections,itertools,sys input=lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF=float('inf') 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 resolve(): N,K=LI() xy=[LI()for _ in range(N)] x_cnt=collections.Counter([i[0]for i in xy]) x_coordinate=list(x_cnt.keys()) x_coordinate.sort() y_cnt=collections.Counter([i[1]for i in xy]) y_coordinate=list(y_cnt.keys()) y_coordinate.sort() len_y_c=len(y_coordinate) ans=INF for xl,xh in itertools.combinations(x_coordinate,2): for i in range(len_y_c-1): yl=y_coordinate[i] for j in range(i+1,len_y_c): yh=y_coordinate[j] cnt=len([(i,j)for i,j in xy if xl<=i<=xh and yl<=j<=yh]) if cnt>=K : ans=min((xh-xl)*(yh-yl),ans) break print(ans) if __name__=='__main__' : resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; sys.setrecursionlimit((10)->pow(7)) ; var INF : double := ("" + (('inf')))->toReal() ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( resolve() ) else skip; operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation LI() : OclAny pre: true post: true activity: return input->apply().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return input->apply().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return input->apply().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return input->apply().split(); operation resolve() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := LI() ; var xy : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (LI())) ; var x_cnt : OclAny := .Counter(xy->select(i | true)->collect(i | (i->first()))) ; var x_coordinate : Sequence := (x_cnt.keys()) ; x_coordinate := x_coordinate->sort() ; var y_cnt : OclAny := .Counter(xy->select(i | true)->collect(i | (i[1+1]))) ; var y_coordinate : Sequence := (y_cnt.keys()) ; y_coordinate := y_coordinate->sort() ; var len_y_c : int := (y_coordinate)->size() ; var ans : OclAny := INF ; for _tuple : itertools.combinations(x_coordinate, 2) do (var _indx : int := 1; var xl : OclAny := _tuple->at(_indx); _indx := _indx + 1; var xh : OclAny := _tuple->at(_indx); for i : Integer.subrange(0, len_y_c - 1-1) do ( var yl : OclAny := y_coordinate[i+1] ; for j : Integer.subrange(i + 1, len_y_c-1) do ( var yh : OclAny := y_coordinate[j+1] ; var cnt : int := (xy->select(_tuple | let i : OclAny = _tuple->at(1) in let j : OclAny = _tuple->at(2) in (xl->compareTo(i)) <= 0 & (i <= xh) & (yl->compareTo(j)) <= 0 & (j <= yh))->collect(_tuple | let i : OclAny = _tuple->at(1) in let j : OclAny = _tuple->at(2) in (Sequence{i, j})))->size() ; if (cnt->compareTo(K)) >= 0 then ( ans := Set{(xh - xl) * (yh - yl), ans}->min() ; break ) else skip))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getMinCost(n,m): cost=(n-1)*m+(m-1)*n return cost if __name__=="__main__" : n,m=4,5 print(getMinCost(n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{n,m} := Sequence{4,5} ; execute (getMinCost(n, m))->display() ) else skip; operation getMinCost(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var cost : double := (n - 1) * m + (m - 1) * n ; return cost; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) from functools import reduce from math import gcd C=list(map(int,input().split())) d=dict() for i in range(1,n+1,1): d[i]=[] deg=[0]*(n+1) for i in range(n): d[i+1].append(C[i]) deg[i+1]+=1 deg[C[i]]+=1 deg=[i % 2 for i in deg] X=[] if sum(deg)!=0 : print(-1) quit() else : visited=[0]*(n+1) X=[] for i in range(1,n+1,1): if visited[i]==1 : continue else : j=i cnt=0 while(visited[j]==0): visited[j]=1 j=d[j][0] cnt+=1 X.append(cnt) Y=[] for c in X : if c % 2==0 : Y.append(c//2) else : Y.append(c) lcm=1 for i in Y : lcm=lcm*i//gcd(lcm,i) print(lcm) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; skip ; var C : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : Map := (arguments ( )) ; for i : Integer.subrange(1, n + 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( d[i+1] := Sequence{}) ; var deg : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(0, n-1) do ((expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name C)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))) ; deg[i + 1+1] := deg[i + 1+1] + 1 ; deg[C[i+1]+1] := deg[C[i+1]+1] + 1) ; deg := deg->select(i | true)->collect(i | (i mod 2)) ; var X : Sequence := Sequence{} ; if (deg)->sum() /= 0 then ( execute (-1)->display() ; quit() ) else ( var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; X := Sequence{} ; for i : Integer.subrange(1, n + 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if visited[i+1] = 1 then ( continue ) else ( var j : OclAny := i ; var cnt : int := 0 ; while (visited[j+1] = 0) do ( visited[j+1] := 1 ; j := d[j+1]->first() ; cnt := cnt + 1) ; execute ((cnt) : X) )) ) ; var Y : Sequence := Sequence{} ; for c : X do ( if c mod 2 = 0 then ( execute ((c div 2) : Y) ) else ( execute ((c) : Y) )) ; var lcm : int := 1 ; for i : Y do ( lcm := lcm * i div gcd(lcm, i)) ; execute (lcm)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(s,a): tmp=(a+1)//2 ans=tmp if a % 2==0 : ans=s//2-tmp+1 return ans s,a=map(int,input().split()) print(solve(s,a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{s,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (solve(s, a))->display(); operation solve(s : OclAny, a : OclAny) : OclAny pre: true post: true activity: var tmp : int := (a + 1) div 2 ; var ans : int := tmp ; if a mod 2 = 0 then ( ans := s div 2 - tmp + 1 ) else skip ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def func(): n,a=map(int,input().strip().split()) if a % 2!=0 : print(a//2+1) else : print(n//2-a//2+1) if __name__=='__main__' : func() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( func() ) else skip; operation func() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a mod 2 /= 0 then ( execute (a div 2 + 1)->display() ) else ( execute (n div 2 - a div 2 + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a=input().split(' ') n=int(n) a=int(a) odd,even=[],[] for i in range(1,n): if(i % 2!=0): odd.append(i) for i in range(n,1,-1): if(i % 2==0): even.append(i) if(a==1): print(1) else : if(a % 2==0): print(even.index(a)+1) else : print(odd.index(a)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := input().split(' ') ; var n : int := ("" + ((n)))->toInteger() ; var a : int := ("" + ((a)))->toInteger() ; var odd : OclAny := null; var even : OclAny := null; Sequence{odd,even} := Sequence{Sequence{},Sequence{}} ; for i : Integer.subrange(1, n-1) do ( if (i mod 2 /= 0) then ( execute ((i) : odd) ) else skip) ; for i : Integer.subrange(1 + 1, n)->reverse() do ( if (i mod 2 = 0) then ( execute ((i) : even) ) else skip) ; if (a = 1) then ( execute (1)->display() ) else ( if (a mod 2 = 0) then ( execute (even->indexOf(a) - 1 + 1)->display() ) else ( execute (odd->indexOf(a) - 1 + 1)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a=map(int,input().split()) if a & 1 : print(a//2+1) else : print(n//2-a//2+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if MathLib.bitwiseAnd(a, 1) then ( execute (a div 2 + 1)->display() ) else ( execute (n div 2 - a div 2 + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a=map(int,input().split()) if a % 2==0 : print(int((n/2)-(a/2))+1) else : print(a//2+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a mod 2 = 0 then ( execute (("" + (((n / 2) - (a / 2))))->toInteger() + 1)->display() ) else ( execute (a div 2 + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def convert_str(s,k): modified_string="" for i in range(0,len(s)): ascii=ord(s[i]) if(ascii>=ord('a')and ascii<=ord('z')and gcd(ascii,k)==1): modified_string+=chr(ascii-32) else : modified_string+=s[i] print(modified_string) if __name__=="__main__" : s="geeksforgeeks" k=4 convert_str(s,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( s := "geeksforgeeks" ; k := 4 ; convert_str(s, k) ) else skip; operation convert_str(s : OclAny, k : OclAny) pre: true post: true activity: var modified_string : String := "" ; for i : Integer.subrange(0, (s)->size()-1) do ( var ascii : int := (s[i+1])->char2byte() ; if ((ascii->compareTo(('a')->char2byte())) >= 0 & (ascii->compareTo(('z')->char2byte())) <= 0 & gcd(ascii, k) = 1) then ( modified_string := modified_string + (ascii - 32)->byte2char() ) else ( modified_string := modified_string + s[i+1] )) ; execute (modified_string)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countIncreasing(arr,n): cnt=0 len=1 for i in range(0,n-1): if arr[i+1]>arr[i]: len+=1 else : cnt+=(((len-1)*len)/2) len=1 if len>1 : cnt+=(((len-1)*len)/2) return cnt arr=[1,2,2,4] n=len(arr) print("Count of strictly increasing subarrays is",int(countIncreasing(arr,n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 4 }))) ; n := (arr)->size() ; execute ("Count of strictly increasing subarrays is")->display(); operation countIncreasing(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; var len : int := 1 ; for i : Integer.subrange(0, n - 1-1) do ( if (arr[i + 1+1]->compareTo(arr[i+1])) > 0 then ( len := len + 1 ) else ( cnt := cnt + (((len - 1) * len) / 2) ; len := 1 )) ; if len > 1 then ( cnt := cnt + (((len - 1) * len) / 2) ) else skip ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- BITS=32 ; def andSum(arr,n): ans=0 for i in range(0,BITS): countSetBits=0 for j in range(0,n): if(arr[j]&(1<union(Sequence{2}->union(Sequence{ 3 })) ; var size : int := (arr)->size() ; execute (andSum(arr, size))->display(); operation andSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, BITS-1) do ( var countSetBits : int := 0 ; for j : Integer.subrange(0, n-1) do ( if (MathLib.bitwiseAnd(arr[j+1], (1 * (2->pow(i))))) then ( countSetBits := (countSetBits + 1) ) else skip) ; var subset : double := ((1 * (2->pow(countSetBits))) - 1) ; subset := (subset * (1 * (2->pow(i)))) ; ans := ans + subset) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 4==0 : print("4") else : print("0") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 4 = 0 then ( execute ("4")->display() ) else ( execute ("0")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countWays(A,B,C): minAddA=max(0,(C+B-A+2)//2) count_ways=max(C-minAddA+1,0) return count_ways A=3 B=5 C=5 print(countWays(A,B,C)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; A := 3 ; B := 5 ; C := 5 ; execute (countWays(A, B, C))->display(); operation countWays(A : OclAny, B : OclAny, C : OclAny) : OclAny pre: true post: true activity: var minAddA : OclAny := Set{0, (C + B - A + 2) div 2}->max() ; var count_ways : OclAny := Set{C - minAddA + 1, 0}->max() ; return count_ways; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minOperation(arr): ans=0 for i in range(N-1,-1,-1): for j in range(M-1,-1,-1): if(arr[i][j]==0): ans+=1 for k in range(i+1): for h in range(j+1): if(arr[k][h]==1): arr[k][h]=0 else : arr[k][h]=1 return ans mat=[[0,0,1,1,1],[0,0,0,1,1],[0,0,0,1,1],[1,1,1,1,1],[1,1,1,1,1]] M=5 N=5 print(minOperation(mat)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var mat : Sequence := Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 1 }))))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 1 }))))}->union(Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))))}->union(Sequence{ Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })))) })))) ; var M : int := 5 ; var N : int := 5 ; execute (minOperation(mat))->display(); operation minOperation(arr : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(-1 + 1, N - 1)->reverse() do ( for j : Integer.subrange(-1 + 1, M - 1)->reverse() do ( if (arr[i+1][j+1] = 0) then ( ans := ans + 1 ; for k : Integer.subrange(0, i + 1-1) do ( for h : Integer.subrange(0, j + 1-1) do ( if (arr[k+1][h+1] = 1) then ( arr[k+1][h+1] := 0 ) else ( arr[k+1][h+1] := 1 ))) ) else skip)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def Div_by_8(n): return(((n>>3)<<3)==n) n=16 if(Div_by_8(n)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 16 ; if (Div_by_8(n)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); operation Div_by_8(n : OclAny) : OclAny pre: true post: true activity: return (((n /(2->pow(3))) * (2->pow(3))) = n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=list(input().strip()),list(input().strip()) counter=0 otv=[] if len(a)==len(b): mas=[sorted([a[i],b[i]])for i in range(len(a))] for i in mas : for j in mas : if(i[0]!=i[1]and i[0]in j and i[1]not in j)or(i[0]!=i[1]and i[0]not in j and i[1]in j)or(i[0]==i[1]and j[0]!=j[1]and i[0]in j): counter=-1 break if counter==-1 : break if i[0]!=i[1]: if i not in otv : otv.append(i) counter+=1 else : counter=-1 print(counter) if counter>0 : for i in otv : print(*i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{(input()->trim()),(input()->trim())} ; var counter : int := 0 ; var otv : Sequence := Sequence{} ; if (a)->size() = (b)->size() then ( var mas : Sequence := Integer.subrange(0, (a)->size()-1)->select(i | true)->collect(i | (Sequence{a[i+1]}->union(Sequence{ b[i+1] })->sort())) ; for i : mas do ( for j : mas do ( if (i->first() /= i[1+1] & (j)->includes(i->first()) & (j)->excludes(i[1+1])) or (i->first() /= i[1+1] & (j)->excludes(i->first()) & (j)->includes(i[1+1])) or (i->first() = i[1+1] & j->first() /= j[1+1] & (j)->includes(i->first())) then ( counter := -1 ; break ) else skip) ; if counter = -1 then ( break ) else skip ; if i->first() /= i[1+1] then ( if (otv)->excludes(i) then ( execute ((i) : otv) ; counter := counter + 1 ) else skip ) else skip) ) else ( counter := -1 ) ; execute (counter)->display() ; if counter > 0 then ( for i : otv do ( execute ((argument * (test (logical_test (comparison (expr (atom (name i))))))))->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s1=input() s2=input() d={}; ans=True for x in range(len(s1)): if s1[x]in d : d[s1[x]]+=[s2[x]] else : d[s1[x]]=[s2[x]] for x in d : p=list(set(d[x])) if len(p)!=1 : ans=False d[x]=p tl=[] for x in d : if d[x][0]in d : if d[d[x][0]]!=[x]: ans=False tl.append(d[x][0]) if len(tl)!=len(list(set(tl))): ans=False if ans : pp=[] for x in d : if[*d[x],x]not in pp and(d[x]!=[x]): pp.append([x,*d[x]]) print(len(pp)) for x in pp : print(*x) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s1 : String := (OclFile["System.in"]).readLine() ; var s2 : String := (OclFile["System.in"]).readLine() ; var d : OclAny := Set{}; var ans : boolean := true ; for x : Integer.subrange(0, (s1)->size()-1) do ( if (d)->includes(s1[x+1]) then ( d[s1[x+1]+1] := d[s1[x+1]+1] + Sequence{ s2[x+1] } ) else ( d[s1[x+1]+1] := Sequence{ s2[x+1] } )) ; for x : d do ( var p : Sequence := (Set{}->union((d[x+1]))) ; if (p)->size() /= 1 then ( ans := false ) else skip ; d[x+1] := p) ; var tl : Sequence := Sequence{} ; for x : d do ( if (d)->includes(d[x+1]->first()) then ( if d[d[x+1]->first()+1] /= Sequence{ x } then ( ans := false ) else skip ) else skip ; execute ((d[x+1]->first()) : tl)) ; if (tl)->size() /= ((Set{}->union((tl))))->size() then ( ans := false ) else skip ; if ans then ( var pp : Sequence := Sequence{} ; for x : d do ( if (pp)->excludes(d[x+1]->union(Sequence{ x })) & (d[x+1] /= Sequence{ x }) then ( execute ((Sequence{x}->union(d[x+1])) : pp) ) else skip) ; execute ((pp)->size())->display() ; for x : pp do ( execute ((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s1=input() s2=input() if s1==s2 : print(0) else : d={} co=True n=0 for i in range(len(s1)): if s1[i]==s2[i]: if s1[i]not in d : d[s1[i]]=s1[i] n+=1 elif d[s1[i]]!=s1[i]: co=False break else : if s1[i]not in d and s2[i]not in d : d[s1[i]]=s2[i] d[s2[i]]=s1[i] elif s1[i]not in d or s2[i]not in d : co=False break elif d[s1[i]]==s2[i]and d[s2[i]]==s1[i]: continue else : co=False break if co : print((len(d)-n)//2) l="" for i in d : if i not in l and i!=d[i]: print(i,d[i]) l+=d[i]+i else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s1 : String := (OclFile["System.in"]).readLine() ; var s2 : String := (OclFile["System.in"]).readLine() ; if s1 = s2 then ( execute (0)->display() ) else ( var d : OclAny := Set{} ; var co : boolean := true ; var n : int := 0 ; for i : Integer.subrange(0, (s1)->size()-1) do ( if s1[i+1] = s2[i+1] then ( if (d)->excludes(s1[i+1]) then ( d[s1[i+1]+1] := s1[i+1] ; n := n + 1 ) else (if d[s1[i+1]+1] /= s1[i+1] then ( co := false ; break ) else skip) ) else ( if (d)->excludes(s1[i+1]) & (d)->excludes(s2[i+1]) then ( d[s1[i+1]+1] := s2[i+1] ; d[s2[i+1]+1] := s1[i+1] ) else (if (d)->excludes(s1[i+1]) or (d)->excludes(s2[i+1]) then ( co := false ; break ) else (if d[s1[i+1]+1] = s2[i+1] & d[s2[i+1]+1] = s1[i+1] then ( continue ) else ( co := false ; break ) ) ) )) ; if co then ( execute (((d)->size() - n) div 2)->display() ; var l : String := "" ; for i : d do ( if (l)->characters()->excludes(i) & i /= d[i+1] then ( execute (i)->display() ; l := l + d[i+1] + i ) else skip) ) else ( execute (-1)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() t=input() fixli=[0 for i in range(500)] cnt=0 resli=[] for i in range(len(s)): maxi=max(s[i],t[i]) mini=min(s[i],t[i]) ts=ord(mini)-ord('a') tm=ord(maxi)-ord('a') if s[i]==t[i]: if fixli[ts]==0 and fixli[tm]==0 : fixli[ts]=s[i] elif fixli[ts]!=mini : print(-1) exit(0) else : if fixli[ts]==0 and fixli[tm]==0 : fixli[ts]=maxi fixli[tm]=mini cnt+=1 resli.append((mini,maxi)) elif fixli[ts]!=maxi or fixli[tm]!=mini : print(-1) exit(0) print(cnt) for v in resli : print(v[0],v[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var fixli : Sequence := Integer.subrange(0, 500-1)->select(i | true)->collect(i | (0)) ; var cnt : int := 0 ; var resli : Sequence := Sequence{} ; for i : Integer.subrange(0, (s)->size()-1) do ( var maxi : OclAny := Set{s[i+1], t[i+1]}->max() ; var mini : OclAny := Set{s[i+1], t[i+1]}->min() ; var ts : double := (mini)->char2byte() - ('a')->char2byte() ; var tm : double := (maxi)->char2byte() - ('a')->char2byte() ; if s[i+1] = t[i+1] then ( if fixli[ts+1] = 0 & fixli[tm+1] = 0 then ( fixli[ts+1] := s[i+1] ) else (if fixli[ts+1] /= mini then ( execute (-1)->display() ; exit(0) ) else skip) ) else ( if fixli[ts+1] = 0 & fixli[tm+1] = 0 then ( fixli[ts+1] := maxi ; fixli[tm+1] := mini ; cnt := cnt + 1 ; execute ((Sequence{mini, maxi}) : resli) ) else (if fixli[ts+1] /= maxi or fixli[tm+1] /= mini then ( execute (-1)->display() ; exit(0) ) else skip) )) ; execute (cnt)->display() ; for v : resli do ( execute (v->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() n=len(x) r=n-1 while r>0 and x[r]=='0' : r-=1 ans=True l=0 while lsize() ; var r : double := n - 1 ; while r > 0 & x[r+1] = '0' do ( r := r - 1) ; var ans : boolean := true ; var l : int := 0 ; while (l->compareTo(r)) < 0 do ( if x[l+1] /= x[r+1] then ( ans := false ; break ) else skip ; l := l + 1 ; r := r - 1) ; execute (if ans then 'YES' else 'NO' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input().strip('0') print('YES' if s==s[: :-1]else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := input()->trim() ; execute (if s = s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then 'YES' else 'NO' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- word=list(input()) def isPalindromic(s): length=len(s) for i in range(length): if s[i]!=s[length-i-1]: return False return True while word[0]=='0' : word.pop(0) while word[-1]=='0' : word.pop(-1) if isPalindromic(word): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var word : Sequence := ((OclFile["System.in"]).readLine())->characters() ; skip ; while word->first() = '0' do ( word := word->excludingAt(0+1)) ; while word->last() = '0' do ( word := word->excludingAt(-1+1)) ; if isPalindromic(word) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); operation isPalindromic(s : OclAny) : OclAny pre: true post: true activity: var length : int := (s)->size() ; for i : Integer.subrange(0, length-1) do ( if s[i+1] /= s[length - i - 1+1] then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- entrada=input() entrada=int(entrada) resto=entrada % 4 resultado=((1+(2**resto)+(3**resto)+(4**resto))% 5) print(resultado) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var entrada : String := (OclFile["System.in"]).readLine() ; entrada := ("" + ((entrada)))->toInteger() ; var resto : String := StringLib.format(entrada,4) ; var resultado : int := ((1 + ((2)->pow(resto)) + ((3)->pow(resto)) + ((4)->pow(resto))) mod 5) ; execute (resultado)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) s=str(x) p=s[: :-1] p=int(p) q=str(p) k=str(p) k=k[: :-1] if k==q : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := ("" + ((x))) ; var p : OclAny := s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; p := ("" + ((p)))->toInteger() ; var q : String := ("" + ((p))) ; var k : String := ("" + ((p))) ; k := k(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; if k = q then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input().strip('0') print(['NO','YES'][n==n[: :-1]]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := input()->trim() ; execute (Sequence{'NO'}->union(Sequence{ 'YES' })->select(n = n(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,data): self.data=data self.next=None def push(head_ref,data): ptr1=Node(0) temp=head_ref ptr1.data=data ptr1.next=head_ref if(head_ref!=None): while(temp.next!=head_ref): temp=temp.next temp.next=ptr1 else : ptr1.next=ptr1 head_ref=ptr1 return head_ref def countNodes(head): temp=head result=0 if(head!=None): while True : temp=temp.next result=result+1 if(temp==head): break return result if __name__=='__main__' : head=None head=push(head,12) head=push(head,56) head=push(head,2) head=push(head,11) print(countNodes(head)) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.next := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( head := null ; head := push(head, 12) ; head := push(head, 56) ; head := push(head, 2) ; head := push(head, 11) ; execute (countNodes(head))->display() ) else skip; operation push(head_ref : OclAny, data : OclAny) : OclAny pre: true post: true activity: var ptr1 : Node := (Node.newNode()).initialise(0) ; var temp : OclAny := head_ref ; ptr1.data := data ; ptr1.next := head_ref ; if (head_ref /= null) then ( while (temp.next /= head_ref) do ( temp := temp.next) ; temp.next := ptr1 ) else ( ptr1.next := ptr1 ) ; head_ref := ptr1 ; return head_ref; operation countNodes(head : OclAny) : OclAny pre: true post: true activity: temp := head ; var result : int := 0 ; if (head /= null) then ( while true do ( temp := temp.next ; result := result + 1 ; if (temp = head) then ( break ) else skip) ) else skip ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a,b,c=map(int,input().split()) print(a*b//(math.gcd(a,b)**2)*c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (a * b div (((a)->gcd(b))->pow(2)) * c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() s=raw_input() mod=10007 dp=[[0]*(1<<3)for _ in xrange(n+1)] for i in xrange(n): if s[i]=="J" : shift=2 elif s[i]=="O" : shift=1 else : shift=0 for j in xrange(8): if j &(1<select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (1 * (2->pow(3)))))) ; for i : xrange(n) do ( if s[i+1] = "J" then ( var shift : int := 2 ) else (if s[i+1] = "O" then ( shift := 1 ) else ( shift := 0 ) ) ; for j : xrange(8) do ( if MathLib.bitwiseAnd(j, (1 * (2->pow(shift)))) /= 0 then ( if i = 0 then ( if MathLib.bitwiseAnd(j, (1 * (2->pow(2)))) /= 0 then ( dp[i + 1+1][j+1] := 1 ) else skip ) else ( for k : xrange(8) do ( if MathLib.bitwiseAnd(k, j) /= 0 then ( dp[i + 1+1][j+1] := dp[i + 1+1][j+1] + dp[i+1][k+1] ; dp[i + 1+1][j+1] := dp[i + 1+1][j+1] mod mod ) else skip) ) ) else skip)) ; execute ((dp->at(n))->sum() mod mod)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def plus(s): global c d=[0]*7 for i in range(7): if s in g[i]: for j in range(7): if g[i]& g[j]!=set(): d[i]+=c[j] c=d n=int(input()) s=input() g=[set(["J"]),set(["O"]),set(["I"]),set(["J","O"]),set(["J","I"]),set(["O","I"]),set(["J","O","I"])] c=[1,0,0,0,0,0,0,0] for i in range(n): plus(s[i]) print(sum(c)% 10007) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute c : OclAny; operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; s := (OclFile["System.in"]).readLine() ; var g : Sequence := Sequence{Set{}->union((Sequence{ "J" }))}->union(Sequence{Set{}->union((Sequence{ "O" }))}->union(Sequence{Set{}->union((Sequence{ "I" }))}->union(Sequence{Set{}->union((Sequence{"J"}->union(Sequence{ "O" })))}->union(Sequence{Set{}->union((Sequence{"J"}->union(Sequence{ "I" })))}->union(Sequence{Set{}->union((Sequence{"O"}->union(Sequence{ "I" })))}->union(Sequence{ Set{}->union((Sequence{"J"}->union(Sequence{"O"}->union(Sequence{ "I" })))) })))))) ; c := Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))))))) ; for i : Integer.subrange(0, n-1) do ( plus(s[i+1])) ; execute ((c)->sum() mod 10007)->display(); operation plus(s : OclAny) pre: true post: true activity: skip ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 7) ; for i : Integer.subrange(0, 7-1) do ( if (g[i+1])->includes(s) then ( for j : Integer.subrange(0, 7-1) do ( if MathLib.bitwiseAnd(g[i+1], g[j+1]) /= Set{}->union(()) then ( d[i+1] := d[i+1] + c[j+1] ) else skip) ) else skip) ; c := d; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import Counter from itertools import product def solve(n,data): status=Counter({(1,0,0): 1}) for ch in data : u=Counter() for j,o,i in product((0,1),repeat=3): if{'J' : j,'O' : o,'I' : i}[ch]: for k,v in status.items(): pj,po,pi=k if any([(j and pj),(o and po),(i and pi)]): u[(j,o,i)]+=v status=Counter({k : v % 10007 for k,v in u.items()}) return sum(status.values())% 10007 def main(args): n=int(input()) data=input() ans=solve(n,data) print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(n : OclAny, data : OclAny) : OclAny pre: true post: true activity: var status : OclAny := Counter(Map{ Sequence{1, 0, 0} |-> 1 }) ; for ch : data do ( var u : OclAny := Counter() ; for _tuple : product(Sequence{0, 1}, (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (number (integer 3))))))))) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var o : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); if Map{ 'J' |-> j }->union(Map{ 'O' |-> o }->union(Map{ 'I' |-> i }))[ch+1] then ( for _tuple : status->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); var pj : OclAny := null; var po : OclAny := null; var pi : OclAny := null; Sequence{pj,po,pi} := k ; if (Sequence{(j & pj)}->union(Sequence{(o & po)}->union(Sequence{ (i & pi) })))->exists( _x | _x = true ) then ( u[Sequence{j, o, i}+1] := u[Sequence{j, o, i}+1] + v ) else skip) ) else skip) ; status := Counter(u->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->select(_tuple | true)->collect(_tuple | Map{k |-> v mod 10007})->unionAll())) ; return (status.values())->sum() mod 10007; operation main(args : OclAny) pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; data := (OclFile["System.in"]).readLine() ; var ans : OclAny := solve(n, data) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def printNonDivisible(A,B,n,m): for i in range(m): j=0 for j in range(n): if(B[i]% A[j]==0): break if(j==n-1): print(B[i]) A=[100,200,400,100] n=len(A) B=[190,200,87,600,800] m=len(B) printNonDivisible(A,B,n,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; A := Sequence{100}->union(Sequence{200}->union(Sequence{400}->union(Sequence{ 100 }))) ; n := (A)->size() ; B := Sequence{190}->union(Sequence{200}->union(Sequence{87}->union(Sequence{600}->union(Sequence{ 800 })))) ; m := (B)->size() ; printNonDivisible(A, B, n, m); operation printNonDivisible(A : OclAny, B : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: for i : Integer.subrange(0, m-1) do ( var j : int := 0 ; for j : Integer.subrange(0, n-1) do ( if (B[i+1] mod A[j+1] = 0) then ( break ) else skip) ; if (j = n - 1) then ( execute (B[i+1])->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): def s(p): return(p-3)*eulerlib.reciprocal_mod(8 % p,p)% p ans=sum(s(p)for p in eulerlib.prime_generator(10**8)if p>=5) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: skip ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p)))))))) ))))))) (comp_for for (exprlist (expr (atom (name p)))) in (logical_test (comparison (expr (atom (name eulerlib)) (trailer . (name prime_generator) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (number (integer 10)))) ** (expr (atom (number (integer 8)))))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name p)))) >= (comparison (expr (atom (number (integer 5))))))))))))->sum() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=[[0,0]]*6 for i in range(6): a,b=sorted(map(int,input().split())) c[i]=[a,b] c.sort() for i in range(0,6,2): if c[i]!=c[i+1]: print('no'); break else : print(['no','yes'][c[0][0]==c[2][0]and c[0][1]==c[4][0]and c[2][1]==c[4][1]]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : Sequence := MatrixLib.elementwiseMult(Sequence{ Sequence{0}->union(Sequence{ 0 }) }, 6) ; for i : Integer.subrange(0, 6-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; c[i+1] := Sequence{a}->union(Sequence{ b })) ; c := c->sort() ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 6)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) != (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))))))) : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'no'))))))) )))))))))) ; (small_stmt break)))))) (else_clause else : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom 'no'))))) , (test (logical_test (comparison (expr (atom 'yes')))))) ]) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (logical_test (logical_test (comparison (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) == (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))) and (logical_test (comparison (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) == (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 4))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))) and (logical_test (comparison (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) == (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 4))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))))) ])))))))) )))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input=input() input=int(input) resto=input % 4 resultado=((1+(2**resto)+(3**resto)+(4**resto))% 5) print(resultado) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var input : String := (OclFile["System.in"]).readLine() ; input := ("" + ((input)))->toInteger() ; var resto : String := StringLib.format(input,4) ; var resultado : int := ((1 + ((2)->pow(resto)) + ((3)->pow(resto)) + ((4)->pow(resto))) mod 5) ; execute (resultado)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A=sorted(sorted(map(int,input().split()))for i in range(6)) if all(a==b for a,b in zip(A[: : 2],A[1 : : 2])): p,q,r=A[: : 2] if(p[0]in q and p[1]in r and q[q.index(p[0])^ 1]==r[r.index(p[1])^ 1])or(p[0]in r and p[1]in q and r[r.index(p[0])^ 1]==q[q.index(p[1])^ 1]): print("yes") else : print("no") else : print("no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : Sequence := (argument (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 6))))))))) ))))))))->sort() ; if ((argument (test (logical_test (comparison (comparison (expr (atom (name a)))) == (comparison (expr (atom (name b))))))) (comp_for for (exprlist (expr (atom (name a))) , (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) ])))))))) )))))))))->forAll( _x | _x = true ) then ( var p : OclAny := null; var q : OclAny := null; var r : OclAny := null; Sequence{p,q,r} := A(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ; if ((q)->includes(p->first()) & (r)->includes(p[1+1]) & q[MathLib.bitwiseXor(q->indexOf(p->first()) - 1, 1)+1] = r[MathLib.bitwiseXor(r->indexOf(p[1+1]) - 1, 1)+1]) or ((r)->includes(p->first()) & (q)->includes(p[1+1]) & r[MathLib.bitwiseXor(r->indexOf(p->first()) - 1, 1)+1] = q[MathLib.bitwiseXor(q->indexOf(p[1+1]) - 1, 1)+1]) then ( execute ("yes")->display() ) else ( execute ("no")->display() ) ) else ( execute ("no")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[] for _ in range(6): a.append(sorted(list(map(int,input().split())))) a.sort(key=lambda x : x[1]) a.sort(key=lambda x : x[0]) print("yes" if a[0]==a[1]and a[2]==a[3]and a[4]==a[5]and a[0][0]==a[2][0]and a[0][1]==a[4][0]and a[2][1]==a[4][1]else "no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Sequence{} ; for _anon : Integer.subrange(0, 6-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort()) : a)) ; a := a->sort() ; a := a->sort() ; execute (if a->first() = a[1+1] & a[2+1] = a[3+1] & a[4+1] = a[5+1] & a->first()->first() = a[2+1]->first() & a->first()[1+1] = a[4+1]->first() & a[2+1][1+1] = a[4+1][1+1] then "yes" else "no" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lst=[set(map(int,input().split()))for _ in range(6)] rec=[] while lst : x=lst[0] count=lst.count(x) if count % 2==1 : print("no") break rec.append((count,x)) for _ in range(count): lst.pop(lst.index(x)) else : if len(rec)==1 : if len(rec[0][1])==1 : print("yes") else : print("no") elif len(rec)==2 : rec.sort() if rec[0][1]& rec[1][1]==rec[0][1]: print("yes") else : print("no") elif len(rec)==3 : if len(rec[0][1])==len(rec[1][1])==len(rec[2][1])==2 and(rec[2][1]&(rec[0][1]| rec[1][1])==rec[2][1]): print("yes") else : print("no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lst : Sequence := Integer.subrange(0, 6-1)->select(_anon | true)->collect(_anon | (Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))) ; var rec : Sequence := Sequence{} ; (compound_stmt while (test (logical_test (comparison (expr (atom (name lst)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name count)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name lst)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name count))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "no"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name rec)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name count)))))) , (test (logical_test (comparison (expr (atom (name x))))))) )))))))) )))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name _)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name count)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name lst)) (trailer . (name pop) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name lst)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))))) )))))))))))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name rec)))))))) ))))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name rec)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ))))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "yes"))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "no"))))))) ))))))))))))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name rec)))))))) ))))) == (comparison (expr (atom (number (integer 2)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name rec)) (trailer . (name sort) (arguments ( )))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name rec)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) & (expr (atom (name rec)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))) == (comparison (expr (atom (name rec)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "yes"))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "no"))))))) )))))))))))))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name rec)))))))) ))))) == (comparison (expr (atom (number (integer 3)))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name rec)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ))))) == (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name rec)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))))) == (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name rec)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))))) == (comparison (expr (atom (number (integer 2))))))) and (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (expr (atom (name rec)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) & (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name rec)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) | (expr (atom (name rec)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ))))) == (comparison (expr (atom (name rec)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "yes"))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "no"))))))) ))))))))))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- Y,M,D=map(int,input().split('/')) if Y>=2019 and M>=5 : print("TBD") else : print("Heisei") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Y : OclAny := null; var M : OclAny := null; var D : OclAny := null; Sequence{Y,M,D} := (input().split('/'))->collect( _x | (OclType["int"])->apply(_x) ) ; if Y >= 2019 & M >= 5 then ( execute ("TBD")->display() ) else ( execute ("Heisei")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- W,H,C=map(int,input().split()) mini=10**10 for x in range(1,min(H,W)+1,1): if(H % x)or(W % x): continue mini=min(mini,(H//x)*(W//x)*C) print(mini) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var W : OclAny := null; var H : OclAny := null; var C : OclAny := null; Sequence{W,H,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mini : double := (10)->pow(10) ; for x : Integer.subrange(1, Set{H, W}->min() + 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if (H mod x) or (W mod x) then ( continue ) else skip ; mini := Set{mini, (H div x) * (W div x) * C}->min()) ; execute (mini)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import datetime date_str=str(input()) date_formatted=datetime.datetime.strptime(date_str,"%Y/%m/%d") heisei_end="2019/04/30" heisei_end_formatted=datetime.datetime.strptime(heisei_end,"%Y/%m/%d") print("Heisei" if date_formatted<=heisei_end_formatted else "TBD") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var date_str : String := ("" + (((OclFile["System.in"]).readLine()))) ; var date_formatted : OclAny := datetime.datetime.strptime(date_str, "%Y/%m/%d") ; var heisei_end : String := "2019/04/30" ; var heisei_end_formatted : OclAny := datetime.datetime.strptime(heisei_end, "%Y/%m/%d") ; execute (if (date_formatted->compareTo(heisei_end_formatted)) <= 0 then "Heisei" else "TBD" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- list=list(map(int,input().split('/'))) if list[0]<2019 : print('Heisei') elif list[0]>2019 : print('TBD') else : if list[1]<=4 : print('Heisei') else : print('TBD') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var OclType["Sequence"] : Sequence := ((input().split('/'))->collect( _x | (OclType["int"])->apply(_x) )) ; if ->first() < 2019 then ( execute ('Heisei')->display() ) else (if ->first() > 2019 then ( execute ('TBD')->display() ) else ( if [1+1] <= 4 then ( execute ('Heisei')->display() ) else ( execute ('TBD')->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import datetime *s,=map(int,input().split("/")) ref=datetime.datetime(2019,4,30) print("Heisei" if datetime.datetime(s[0],s[1],s[2])<=ref else "TBD") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; (testlist_star_expr (star_expr * (expr (atom (name s)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name s)))) ,)} := (input().split("/"))->collect( _x | (OclType["int"])->apply(_x) ) ; var ref : OclAny := ; execute (if (->compareTo(ref)) <= 0 then "Heisei" else "TBD" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- TH=20190430 inp=int("".join(input().split('/'))) if inp<=TH : print('Heisei') else : print('TBD') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var TH : int := 20190430 ; var inp : int := ("" + ((StringLib.sumStringsWithSeparator((input().split('/')), ""))))->toInteger() ; if (inp->compareTo(TH)) <= 0 then ( execute ('Heisei')->display() ) else ( execute ('TBD')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def totalways(arr,n): cnt=dict() for i in range(n): cnt[arr[i]]=cnt.get(arr[i],0)+1 if(n % 2==1): start,endd=0,n-1 for i in range(start,endd+1,2): if(i==0): if(cnt[i]!=1): return 0 else : if(cnt[i]!=2): return 0 ways=1 start=2 endd=n-1 for i in range(start,endd+1,2): ways=ways*2 return ways elif(n % 2==0): start=1 endd=n-1 for i in range(1,endd+1,2): if(cnt[i]!=2): return 0 ways=1 for i in range(start,endd+1,2): ways=ways*2 return ways N=5 arr=[2,4,4,0,2] print(totalways(arr,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 5 ; arr := Sequence{2}->union(Sequence{4}->union(Sequence{4}->union(Sequence{0}->union(Sequence{ 2 })))) ; execute (totalways(arr, N))->display(); operation totalways(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var cnt : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( cnt[arr[i+1]+1] := cnt.get(arr[i+1], 0) + 1) ; if (n mod 2 = 1) then ( var start : OclAny := null; var endd : OclAny := null; Sequence{start,endd} := Sequence{0,n - 1} ; for i : Integer.subrange(start, endd + 1-1)->select( $x | ($x - start) mod 2 = 0 ) do ( if (i = 0) then ( if (cnt[i+1] /= 1) then ( return 0 ) else skip ) else ( if (cnt[i+1] /= 2) then ( return 0 ) else skip )) ; var ways : int := 1 ; var start : int := 2 ; var endd : double := n - 1 ; for i : Integer.subrange(start, endd + 1-1)->select( $x | ($x - start) mod 2 = 0 ) do ( ways := ways * 2) ; return ways ) else (if (n mod 2 = 0) then ( start := 1 ; endd := n - 1 ; for i : Integer.subrange(1, endd + 1-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( if (cnt[i+1] /= 2) then ( return 0 ) else skip) ; ways := 1 ; for i : Integer.subrange(start, endd + 1-1)->select( $x | ($x - start) mod 2 = 0 ) do ( ways := ways * 2) ; return ways ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) n %=4 ans=1 m1=(pow(2,n))% 5 m2=(pow(3,n))% 5 m3=(pow(4,n))% 5 ans+=m1+m2+m3 ans %=5 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; n := n mod 4 ; var ans : int := 1 ; var m1 : int := ((2)->pow(n)) mod 5 ; var m2 : int := ((3)->pow(n)) mod 5 ; var m3 : int := ((4)->pow(n)) mod 5 ; ans := ans + m1 + m2 + m3 ; ans := ans mod 5 ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculate(a): a.sort() count=1 answer=0 for i in range(1,len(a)): if a[i]==a[i-1]: count+=1 else : answer=answer+count*(count-1)//2 count=1 answer=answer+count*(count-1)//2 return answer if __name__=='__main__' : a=[1,2,1,2,4] print(calculate(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 4 })))) ; execute (calculate(a))->display() ) else skip; operation calculate(a : OclAny) : OclAny pre: true post: true activity: a := a->sort() ; var count : int := 1 ; var answer : int := 0 ; for i : Integer.subrange(1, (a)->size()-1) do ( if a[i+1] = a[i - 1+1] then ( count := count + 1 ) else ( answer := answer + count * (count - 1) div 2 ; count := 1 )) ; answer := answer + count * (count - 1) div 2 ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def kthgroupsum(k): cur=int((k*(k-1))+1) sum=0 while k : sum+=cur cur+=2 k=k-1 return sum k=3 print(kthgroupsum(k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; k := 3 ; execute (kthgroupsum(k))->display(); operation kthgroupsum(k : OclAny) : OclAny pre: true post: true activity: var cur : int := ("" + (((k * (k - 1)) + 1)))->toInteger() ; var sum : int := 0 ; while k do ( sum := sum + cur ; cur := cur + 2 ; k := k - 1) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def kthgroupsum(k): return k*k*k k=3 print(kthgroupsum(k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; k := 3 ; execute (kthgroupsum(k))->display(); operation kthgroupsum(k : OclAny) : OclAny pre: true post: true activity: return k * k * k; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A=[] while True : a=input().split('"') if a[0]=="." : break b=input().split('"') cnt=0 if len(a)!=len(b): A.append(-1) else : for i in range(len(a)): if(a[i]==b[i]): pass else : if i % 2==1 : cnt+=1 else : cnt+=2 if cnt>=2 : A.append(-1) if cnt==1 : A.append(0) if cnt==0 : A.append(1) A.reverse() for i in range(len(A)): tmp=A.pop() if tmp==-1 : print("DIFFERENT") elif tmp==0 : print("CLOSE") else : print("IDENTICAL") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : Sequence := Sequence{} ; while true do ( var a : OclAny := input().split('"') ;\n if a->first() = "." then (\n break\n ) else skip ;\n var b : OclAny := input().split('"') ; var cnt : int := 0 ; if (a)->size() /= (b)->size() then ( execute ((-1) : A) ) else ( for i : Integer.subrange(0, (a)->size()-1) do ( if (a[i+1] = b[i+1]) then ( skip ) else ( if i mod 2 = 1 then ( cnt := cnt + 1 ) else ( cnt := cnt + 2 ) )) ; if cnt >= 2 then ( execute ((-1) : A) ) else skip ; if cnt = 1 then ( execute ((0) : A) ) else skip ; if cnt = 0 then ( execute ((1) : A) ) else skip )) ; A := A->reverse() ; for i : Integer.subrange(0, (A)->size()-1) do ( var tmp : OclAny := A->last() ; A := A->front() ; if tmp = -1 then ( execute ("DIFFERENT")->display() ) else (if tmp = 0 then ( execute ("CLOSE")->display() ) else ( execute ("IDENTICAL")->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re import sys sys.setrecursionlimit(10**9) input=sys.stdin.readline def solve(): s1=input()[:-1] if s1=="." : exit() else : s2=input()[:-1] s1_split=s1.split('"') s2_split=s2.split('"') diff_word=[] ans="DIFFERENT" for a,b in zip(s1_split,s2_split): if a==b : continue else : diff_word.append(a) if len(s1_split)==len(s2_split): if len(diff_word)==0 : ans="IDENTICAL" elif len(diff_word)==1 : pattern='\"(.*?)\"' reg=re.compile(pattern) str_const=reg.findall(s1) if diff_word[0]in str_const : ans="CLOSE" print(ans) while True : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; while true do ( solve()); operation solve() pre: true post: true activity: var s1 : OclAny := input()->front() ; if s1 = "." then ( exit() ) else ( var s2 : OclAny := input()->front() ) ; var s1_split : OclAny := s1.split('"') ;\n var s2_split : OclAny := s2.split('"') ; var diff_word : Sequence := Sequence{} ; var ans : String := "DIFFERENT" ; for _tuple : Integer.subrange(1, s1_split->size())->collect( _indx | Sequence{s1_split->at(_indx), s2_split->at(_indx)} ) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if a = b then ( continue ) else ( execute ((a) : diff_word) )) ; if (s1_split)->size() = (s2_split)->size() then ( if (diff_word)->size() = 0 then ( ans := "IDENTICAL" ) else (if (diff_word)->size() = 1 then ( var pattern : String := '\"(.*?)\"' ; var reg : OclRegex := OclRegex.compile(pattern) ; var str_const : OclAny := reg.findall(s1) ; if (str_const)->includes(diff_word->first()) then ( ans := "CLOSE" ) else skip ) else skip) ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if b==0 : return a return gcd(b,a % b) w,h,c=[int(num)for num in input().split()] g=gcd(w,h) print((w//g)*(h//g)*c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var w : OclAny := null; var h : OclAny := null; var c : OclAny := null; Sequence{w,h,c} := input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var g : OclAny := gcd(w, h) ; execute ((w div g) * (h div g) * c)->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if b = 0 then ( return a ) else skip ; return gcd(b, a mod b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : s1=input() if s1=="." : break s2=input() listed_s1=[[]] listed_s2=[[]] start=0 now=0 for i in range(len(s1)): if s1[i]=="\"" and not start : listed_s1.append([]) now+=1 start=1 listed_s1[now].append(s1[i]) elif s1[i]=="\"" and start : listed_s1[now].append(s1[i]) listed_s1.append([]) now+=1 start=0 else : listed_s1[now].append(s1[i]) now=0 for i in range(len(s2)): if s2[i]=="\"" and not start : listed_s2.append([]) now+=1 start=1 listed_s2[now].append(s2[i]) elif s2[i]=="\"" and start : listed_s2[now].append(s2[i]) listed_s2.append([]) now+=1 start=0 else : listed_s2[now].append(s2[i]) fist_wrong=0 ans="IDENTICAL" if len(listed_s1)!=len(listed_s2): ans="DIFFERENT" for i in range(min(len(listed_s1),len(listed_s2))): if ans=="DIFFERENT" : break if listed_s1[i]!=listed_s2[i]: if listed_s1[i][0]=="\""andlisted_s2[i][-1]=="\"" and listed_s2[i][0]=="\""andlisted_s2[i][-1]=="\"" : if fist_wrong : ans="DIFFERENT" else : fist_wrong=1 ans="CLOSE" else : ans="DIFFERENT" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var s1 : String := (OclFile["System.in"]).readLine() ; if s1 = "." then ( break ) else skip ; var s2 : String := (OclFile["System.in"]).readLine() ; var listed_s1 : Sequence := Sequence{ Sequence{} } ; var listed_s2 : Sequence := Sequence{ Sequence{} } ; var start : int := 0 ; var now : int := 0 ; for i : Integer.subrange(0, (s1)->size()-1) do ( if s1[i+1] = "\"" & not(start) then (\n execute ((Sequence{}) : listed_s1) ;\n now := now + 1 ;\n start := 1 ;\n(expr (atom (name listed_s1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name now)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))\n )\n else (if s1[i+1] = "\"" & start then ( (expr (atom (name listed_s1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name now)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))) ; execute ((Sequence{}) : listed_s1) ; now := now + 1 ; start := 0 ) else ( (expr (atom (name listed_s1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name now)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))) ) ) ) ; now := 0 ; for i : Integer.subrange(0, (s2)->size()-1) do ( if s2[i+1] = "\"" & not(start) then (\n execute ((Sequence{}) : listed_s2) ;\n now := now + 1 ;\n start := 1 ;\n(expr (atom (name listed_s2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name now)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))\n )\n else (if s2[i+1] = "\"" & start then ( (expr (atom (name listed_s2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name now)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))) ; execute ((Sequence{}) : listed_s2) ; now := now + 1 ; start := 0 ) else ( (expr (atom (name listed_s2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name now)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))) ) ) ) ; var fist_wrong : int := 0 ; var ans : String := "IDENTICAL" ; if (listed_s1)->size() /= (listed_s2)->size() then ( ans := "DIFFERENT" ) else skip ; for i : Integer.subrange(0, Set{(listed_s1)->size(), (listed_s2)->size()}->min()-1) do ( if ans = "DIFFERENT" then ( break ) else skip ; if listed_s1[i+1] /= listed_s2[i+1] then ( (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name listed_s1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) == (comparison (expr (atom "\"")))))) (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (logical_test (comparison (comparison (expr (atom (name andlisted_s2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))) == (comparison (expr (atom "\""))))) and (logical_test (comparison (comparison (expr (atom (name listed_s2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) == (comparison (expr (atom "\""))))))))))))) ;\n var andlisted_s2[i+1]->last() = "\"" : int ; if fist_wrong then ( ans := "DIFFERENT" ) else ( fist_wrong := 1 ; ans := "CLOSE" ) ) else ( ans := "DIFFERENT" ))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(s,t): if s==t : return 'IDENTICAL' s=s.split('"') t=t.split('"') if len(s)==len(t): k0=sum(s[i]!=t[i]for i in range(0,len(s),2)) k1=sum(s[i]!=t[i]for i in range(1,len(s),2)) if k0==0 and k1==1 : return 'CLOSE' return 'DIFFERENT' while True : s=input() if s=='.' : break t=input() print(solve(s,t)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( s := (OclFile["System.in"]).readLine() ; if s = '.' then ( break ) else skip ; t := (OclFile["System.in"]).readLine() ; execute (solve(s, t))->display()); operation solve(s : OclAny, t : OclAny) : OclAny pre: true post: true activity: if s = t then ( return 'IDENTICAL' ) else skip ; s := s.split('"') ;\n t := t.split('"') ; if (s)->size() = (t)->size() then ( var k0 : OclAny := ((argument (test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) != (comparison (expr (atom (name t)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))))))))->sum() ; var k1 : OclAny := ((argument (test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) != (comparison (expr (atom (name t)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))))))))->sum() ; if k0 = 0 & k1 = 1 then ( return 'CLOSE' ) else skip ) else skip ; return 'DIFFERENT'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import re from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,radians,log2,gcd from itertools import permutations,combinations,product from operator import itemgetter,mul from copy import deepcopy from string import ascii_lowercase,ascii_uppercase,digits def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) sys.setrecursionlimit(10**9) INF=float('inf') mod=10**9+7 def main(): ans=[] while 1 : s1=input() if s1=='.' : break else : s2=input().split('"') s1=s1.split('"') ct=0 flag=0 if len(s1)!=len(s2): flag=2 else : for i in range(len(s1)): if i % 2==0 : if s1[i]!=s2[i]: flag=2 break else : if s1[i]!=s2[i]: if ct==0 : flag=1 ct+=1 else : flag=2 if flag==0 : ans.append('IDENTICAL') elif flag==1 : ans.append('CLOSE') else : ans.append('DIFFERENT') for x in ans : print(x) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation main() pre: true post: true activity: var ans : Sequence := Sequence{} ; while 1 do ( var s1 : String := (OclFile["System.in"]).readLine() ; if s1 = '.' then ( break ) else ( var s2 : OclAny := input().split('"') ;\n s1 := s1.split('"') ; var ct : int := 0 ; var flag : int := 0 ; if (s1)->size() /= (s2)->size() then ( flag := 2 ) else ( for i : Integer.subrange(0, (s1)->size()-1) do ( if i mod 2 = 0 then ( if s1[i+1] /= s2[i+1] then ( flag := 2 ; break ) else skip ) else ( if s1[i+1] /= s2[i+1] then ( if ct = 0 then ( flag := 1 ; ct := ct + 1 ) else ( flag := 2 ) ) else skip )) ) ; if flag = 0 then ( execute (('IDENTICAL') : ans) ) else (if flag = 1 then ( execute (('CLOSE') : ans) ) else ( execute (('DIFFERENT') : ans) ) ) )) ; for x : ans do ( execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() s=input() output="" count=0 for i in range(len(s)): if s[i]=='1' : count+=1 else : output=output+str(count) count=0 output=output+str(count) print(output) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; s := (OclFile["System.in"]).readLine() ; var output : String := "" ; var count : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = '1' then ( count := count + 1 ) else ( output := output + ("" + ((count))) ; count := 0 )) ; output := output + ("" + ((count))) ; execute (output)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 4==0 : print("4") else : print("0") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 4 = 0 then ( execute ("4")->display() ) else ( execute ("0")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() s=input().split('0') for i in s : print(len(i),end='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var s : OclAny := input().split('0') ; for i : s do ( execute ((i)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() s=input().split('0') for i in s : print(len(i),end='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var s : OclAny := input().split('0') ; for i : s do ( execute ((i)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() s=input().split('0') for i in s : print(len(i),end='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var s : OclAny := input().split('0') ; for i : s do ( execute ((i)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() ans="" col=0 for i in range(0,n): if i!=0 and s[i]!=s[i-1]: if(s[i-1]=='0'): ans+='0'*(col-1) else : ans+=str(col) col=1 else : col+=1 if(s[len(s)-1]=='0'): ans+='0'*col else : ans+=str(col) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var ans : String := "" ; var col : int := 0 ; for i : Integer.subrange(0, n-1) do ( if i /= 0 & s[i+1] /= s[i - 1+1] then ( if (s[i - 1+1] = '0') then ( ans := ans + StringLib.nCopies('0', (col - 1)) ) else ( ans := ans + ("" + ((col))) ) ; col := 1 ) else ( col := col + 1 )) ; if (s[(s)->size() - 1+1] = '0') then ( ans := ans + StringLib.nCopies('0', col) ) else ( ans := ans + ("" + ((col))) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getCount(A,B2,C): count=0 i=1 while(i=j): count=count+C-j+1 if(A>=j and C>=i): count=count+(C-i+1)*(A-j+1) if(A>=j): A=j-1 i+=1 return count def countTriplets(A,B,C): ans=0 for i in range(1,B+1): ans=(ans+getCount(A,i*i,C)) return ans A=3 B=2 C=2 print(countTriplets(A,B,C)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; A := 3 ; B := 2 ; C := 2 ; execute (countTriplets(A, B, C))->display(); operation getCount(A : OclAny, B2 : OclAny, C : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var i : int := 1 ; while ((i->compareTo(A)) < 0) do ( var j : int := (B2 div i) + 1 ; if ((C->compareTo(j)) >= 0) then ( count := count + C - j + 1 ) else skip ; if ((A->compareTo(j)) >= 0 & (C->compareTo(i)) >= 0) then ( count := count + (C - i + 1) * (A - j + 1) ) else skip ; if ((A->compareTo(j)) >= 0) then ( A := j - 1 ) else skip ; i := i + 1) ; return count; operation countTriplets(A : OclAny, B : OclAny, C : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(1, B + 1-1) do ( ans := (ans + getCount(A, i * i, C))) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=list(map(int,input().split())) y=list(map(int,input().split())) c=int() for i in y : if i>=y[b-1]and i>0 : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var y : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := ("" + (()))->toInteger() ; for i : y do ( if (i->compareTo(y[b - 1+1])) >= 0 & i > 0 then ( c := c + 1 ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sdk(a,b): if acollect( _x | (OclType["int"])->apply(_x) ) ; var t : OclAny := sdk(w, h) ; execute (w div t * h div t * c)->display(); operation sdk(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a->compareTo(b)) < 0 then ( Sequence{a,b} := Sequence{b,a} ) else skip ; if a mod b = 0 then ( return b ) else ( return sdk(b, a mod b) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=input().split() k=int(k) cnt=0 l=input().split() for i in range(len(l)): l[i]=int(l[i]) for i in range(len(l)): if l[i]>0 and l[i]>=l[k-1]: cnt+=1 else : break print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split() ; var k : int := ("" + ((k)))->toInteger() ; var cnt : int := 0 ; var l : OclAny := input().split() ; for i : Integer.subrange(0, (l)->size()-1) do ( l[i+1] := ("" + ((l[i+1])))->toInteger()) ; for i : Integer.subrange(0, (l)->size()-1) do ( if l[i+1] > 0 & (l[i+1]->compareTo(l[k - 1+1])) >= 0 then ( cnt := cnt + 1 ) else ( break )) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def next_round(A,n,key): count=0 temp=A[key-1] for i in range(0,n): if A[i]>=temp and A[i]>0 : count+=1 return count n,key=map(int,input().split()) A=list(map(int,input().split())) count=next_round(A,n,key) print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{n,key} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; A := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; count := next_round(A, n, key) ; execute (count)->display(); operation next_round(A : OclAny, n : OclAny, key : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var temp : OclAny := A[key - 1+1] ; for i : Integer.subrange(0, n-1) do ( if (A[i+1]->compareTo(temp)) >= 0 & A[i+1] > 0 then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) lis=list(int(x)for x in input().split()) count=0 cutoff=lis[k-1] counter=0 for i in range(len(lis)): if lis[i]>cutoff or lis[i]==cutoff and lis[i]>0 : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lis : Sequence := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ; var count : int := 0 ; var cutoff : OclAny := lis[k - 1+1] ; var counter : int := 0 ; for i : Integer.subrange(0, (lis)->size()-1) do ( if (lis[i+1]->compareTo(cutoff)) > 0 or lis[i+1] = cutoff & lis[i+1] > 0 then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : k=int(input()) num=list(input()) num=sorted(num) sum=0 for i in range(len(num)): sum+=ord(num[i])-ord('0') if sum>=k : print(0) else : count=0 i=0 while sumtoInteger() ; var num : Sequence := ((OclFile["System.in"]).readLine())->characters() ; num := num->sort() ; var sum : int := 0 ; for i : Integer.subrange(0, (num)->size()-1) do ( sum := sum + (num[i+1])->char2byte() - ('0')->char2byte()) ; if (sum->compareTo(k)) >= 0 then ( execute (0)->display() ) else ( var count : int := 0 ; var i : int := 0 ; while (sum->compareTo(k)) < 0 do ( sum := sum + 9 - ((num[i+1])->char2byte() - ('0')->char2byte()) ; i := i + 1 ; count := count + 1) ; execute (count)->display() ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=list(map(int,input().split())) r=0 for i in a : if i>=a[k-1]and i>0 : r+=1 else : r=r print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var r : int := 0 ; for i : a do ( if (i->compareTo(a[k - 1+1])) >= 0 & i > 0 then ( r := r + 1 ) else ( r := r )) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=list(map(int,input().split())) ans=0 for i in range(4): if ans!=2 : for j in range(i+1,4): if ans!=2 : for k in range(j+1,4): l=[a[i],a[j],a[k]] l.sort() if l[-1]collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(0, 4-1) do ( if ans /= 2 then ( for j : Integer.subrange(i + 1, 4-1) do ( if ans /= 2 then ( for k : Integer.subrange(j + 1, 4-1) do ( var l : Sequence := Sequence{a[i+1]}->union(Sequence{a[j+1]}->union(Sequence{ a[k+1] })) ; l := l->sort() ; if (l->last()->compareTo(l->front()->last() + l->reverse()->at(-(-3)))) < 0 then ( ans := 2 ; break ) else (if l->last() = l->front()->last() + l->reverse()->at(-(-3)) then ( ans := 1 ) else skip)) ) else skip) ) else skip) ; if ans = 2 then ( execute ("TRIANGLE")->display() ) else (if ans = 1 then ( execute ("SEGMENT")->display() ) else ( execute ("IMPOSSIBLE")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def is_possibe(a,b,c,d): triangle,straight=False,False h=sorted([a,b,c,d]) a=h[3] b=h[2] c=h[1] d=h[0] if acollect( _x | (OclType["int"])->apply(_x) ) ; execute (is_possibe(a, b, c, d))->display(); operation is_possibe(a : OclAny, b : OclAny, c : OclAny, d : OclAny) : OclAny pre: true post: true activity: var triangle : OclAny := null; var straight : OclAny := null; Sequence{triangle,straight} := Sequence{false,false} ; var h : Sequence := Sequence{a}->union(Sequence{b}->union(Sequence{c}->union(Sequence{ d })))->sort() ; a := h[3+1] ; b := h[2+1] ; c := h[1+1] ; d := h->first() ; if (a->compareTo(b + c)) < 0 or (a->compareTo(b + d)) < 0 or (a->compareTo(c + d)) < 0 or (b->compareTo(c + d)) < 0 then ( var triangle : boolean := true ) else skip ; if a = b + c or a = b + d or a = c + d or b = c + d then ( var straight : boolean := true ) else skip ; if triangle then ( return "TRIANGLE" ) else skip ; if straight then ( return "SEGMENT" ) else skip ; return "IMPOSSIBLE"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=sorted(map(int,input().split()),reverse=True) if acollect( _x | (OclType["int"])->apply(_x) )->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; if (a->compareTo(b + c)) < 0 or (b->compareTo(c + d)) < 0 then ( execute ('TRIANGLE')->display() ) else (if a = b + c or b = c + d then ( execute ('SEGMENT')->display() ) else ( execute ('IMPOSSIBLE')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=sorted(map(int,input().split())) x=min((d-b-c),(c-b-a)) if x==0 : print('SEGMENT') elif x>0 : print('IMPOSSIBLE') else : print('TRIANGLE') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var x : OclAny := Set{(d - b - c), (c - b - a)}->min() ; if x = 0 then ( execute ('SEGMENT')->display() ) else (if x > 0 then ( execute ('IMPOSSIBLE')->display() ) else ( execute ('TRIANGLE')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input().split() L=[] for i in n : L.append(int(i)) L.sort() if L[1]+L[2]>L[3]or L[1]+L[0]>L[2]: print('TRIANGLE') elif L[1]+L[2]==L[3]or L[1]+L[0]==L[2]: print('SEGMENT') else : print('IMPOSSIBLE') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := input().split() ; var L : Sequence := Sequence{} ; for i : n do ( execute ((("" + ((i)))->toInteger()) : L)) ; L := L->sort() ; if (L[1+1] + L[2+1]->compareTo(L[3+1])) > 0 or (L[1+1] + L->first()->compareTo(L[2+1])) > 0 then ( execute ('TRIANGLE')->display() ) else (if L[1+1] + L[2+1] = L[3+1] or L[1+1] + L->first() = L[2+1] then ( execute ('SEGMENT')->display() ) else ( execute ('IMPOSSIBLE')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def printPrevSmaller(arr,n): S=list() for i in range(n): while(len(S)>0 and S[-1]>=arr[i]): S.pop() if(len(S)==0): print("_,",end="") else : print(S[-1],end=",") S.append(arr[i]) arr=[1,3,0,2,5] n=len(arr) printPrevSmaller(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{1}->union(Sequence{3}->union(Sequence{0}->union(Sequence{2}->union(Sequence{ 5 })))) ; n := (arr)->size() ; printPrevSmaller(arr, n); operation printPrevSmaller(arr : OclAny, n : OclAny) pre: true post: true activity: var S : Sequence := () ; for i : Integer.subrange(0, n-1) do ( while ((S)->size() > 0 & (S->last()->compareTo(arr[i+1])) >= 0) do ( S := S->front()) ; if ((S)->size() = 0) then ( execute ("_,")->display() ) else ( execute (S->last())->display() ) ; execute ((arr[i+1]) : S)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math W,H,C=[int(i)for i in input().split()] g=math.gcd(W,H) print(int(((W/g)*(H/g))*C)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var W : OclAny := null; var H : OclAny := null; var C : OclAny := null; Sequence{W,H,C} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var g : long := (W)->gcd(H) ; execute (("" + ((((W / g) * (H / g)) * C)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def maxSum(arr,n): res=-sys.maxsize for i in range(0,n): curr_sum=0 for j in range(0,n): index=int((i+j)% n) curr_sum+=j*arr[index] res=max(res,curr_sum) return res arr=[8,3,1,2] n=len(arr) print(maxSum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{8}->union(Sequence{3}->union(Sequence{1}->union(Sequence{ 2 }))) ; n := (arr)->size() ; execute (maxSum(arr, n))->display(); operation maxSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var res : (trailer . (name maxsize)) := -(trailer . (name maxsize)) ; for i : Integer.subrange(0, n-1) do ( var curr_sum : int := 0 ; for j : Integer.subrange(0, n-1) do ( var index : int := ("" + (((i + j) mod n)))->toInteger() ; curr_sum := curr_sum + j * arr[index+1]) ; res := Set{res, curr_sum}->max()) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) c=0 while True : if n % 2==0 : n//=2 c+=1 elif n % 3==0 : n//=3 n*=2 c+=1 elif n % 5==0 : n//=5 n*=4 c+=1 elif n==1 : print(c) break else : print(-1) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := 0 ; while true do ( if n mod 2 = 0 then ( n := n div 2 ; c := c + 1 ) else (if n mod 3 = 0 then ( n := n div 3 ; n := n * 2 ; c := c + 1 ) else (if n mod 5 = 0 then ( n := n div 5 ; n := n * 4 ; c := c + 1 ) else (if n = 1 then ( execute (c)->display() ; break ) else ( execute (-1)->display() ; break ) ) ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline k=int(input()) n=sorted(map(int,list(input()[:-1]))) x=sum(n) if x>=k : print(0) else : c=0 for i in n : x+=9-i c+=1 if x>=k : print(c) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : Sequence := ((input()->front()))->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var x : OclAny := (n)->sum() ; if (x->compareTo(k)) >= 0 then ( execute (0)->display() ) else ( var c : int := 0 ; for i : n do ( x := x + 9 - i ; c := c + 1 ; if (x->compareTo(k)) >= 0 then ( execute (c)->display() ; break ) else skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) count=[0]*3 while not n % 2 : n//=2 count[0]+=1 while not n % 3 : n//=3 count[1]+=1 while not n % 5 : n//=5 count[2]+=1 if n!=1 : print(-1) else : print(count[0]+count[1]*2+count[2]*3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 3) ; while not(n mod 2) do ( n := n div 2 ; count->first() := count->first() + 1) ; while not(n mod 3) do ( n := n div 3 ; count[1+1] := count[1+1] + 1) ; while not(n mod 5) do ( n := n div 5 ; count[2+1] := count[2+1] + 1) ; if n /= 1 then ( execute (-1)->display() ) else ( execute (count->first() + count[1+1] * 2 + count[2+1] * 3)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) c=0 while True : if n % 2==0 : n//=2 c+=1 elif n % 3==0 : n//=3 n*=2 c+=1 elif n % 5==0 : n//=5 n*=4 c+=1 elif n==1 : print(c) break else : print(-1) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := 0 ; while true do ( if n mod 2 = 0 then ( n := n div 2 ; c := c + 1 ) else (if n mod 3 = 0 then ( n := n div 3 ; n := n * 2 ; c := c + 1 ) else (if n mod 5 = 0 then ( n := n div 5 ; n := n * 4 ; c := c + 1 ) else (if n = 1 then ( execute (c)->display() ; break ) else ( execute (-1)->display() ; break ) ) ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) for i in range(q): n=int(input()) c=0 while True : if n % 2==0 : n//=2 c+=1 elif n % 3==0 : n//=3 n*=2 c+=1 elif n % 5==0 : n//=5 n*=4 c+=1 elif n==1 : print(c) break else : print(-1) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := 0 ; while true do ( if n mod 2 = 0 then ( n := n div 2 ; c := c + 1 ) else (if n mod 3 = 0 then ( n := n div 3 ; n := n * 2 ; c := c + 1 ) else (if n mod 5 = 0 then ( n := n div 5 ; n := n * 4 ; c := c + 1 ) else (if n = 1 then ( execute (c)->display() ; break ) else ( execute (-1)->display() ; break ) ) ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tc=int(input()) for t in range(tc): n=int(input()) ans=0 flag=True while n!=1 : if n % 2==0 : n=n//2 elif n % 3==0 : n=2*n//3 elif n % 5==0 : n=4*n//5 else : flag=False break ans+=1 if flag : print(ans) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var tc : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(0, tc-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; var flag : boolean := true ; while n /= 1 do ( if n mod 2 = 0 then ( n := n div 2 ) else (if n mod 3 = 0 then ( n := 2 * n div 3 ) else (if n mod 5 = 0 then ( n := 4 * n div 5 ) else ( flag := false ; break ) ) ) ; ans := ans + 1) ; if flag then ( execute (ans)->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools def compute(): nums=set() for i in range(1,10001): sigma=i*i for j in itertools.count(i+1): sigma+=j*j if sigma>=100000000 : break s=str(sigma) if s==s[: :-1]: nums.add(sigma) return str(sum(nums)) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var nums : Set := Set{}->union(()) ; for i : Integer.subrange(1, 10001-1) do ( var sigma : double := i * i ; for j : itertools->count(i + 1) do ( sigma := sigma + j * j ; if sigma >= 100000000 then ( break ) else skip ; var s : String := ("" + ((sigma))) ; if s = s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( execute ((sigma) : nums) ) else skip)) ; return ("" + (((nums)->sum()))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def firstFactorialDivisibleNumber(x): i=1 ; fact=1 ; for i in range(1,x): fact=fact*i if(fact % x==0): break return i x=16 print(firstFactorialDivisibleNumber(x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := 16 ; execute (firstFactorialDivisibleNumber(x))->display(); operation firstFactorialDivisibleNumber(x : OclAny) : OclAny pre: true post: true activity: var i : int := 1; ; var fact : int := 1; ; for i : Integer.subrange(1, x-1) do ( fact := fact * i ; if (fact mod x = 0) then ( break ) else skip) ; return i; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pell(n): if(n<=2): return n a=1 b=2 for i in range(3,n+1): c=2*b+a a=b b=c return b n=4 print(pell(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute (pell(n))->display(); operation pell(n : OclAny) : OclAny pre: true post: true activity: if (n <= 2) then ( return n ) else skip ; var a : int := 1 ; var b : int := 2 ; for i : Integer.subrange(3, n + 1-1) do ( var c : int := 2 * b + a ; a := b ; b := c) ; return b; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def xor_triplet(arr,n): ans=0 ; for i in range(n): for j in range(i+1,n): for k in range(j,n): xor1=0 ; xor2=0 ; for x in range(i,j): xor1 ^=arr[x]; for x in range(j,k+1): xor2 ^=arr[x]; if(xor1==xor2): ans+=1 ; return ans ; if __name__=='__main__' : arr=[1,2,3,4,5]; n=len(arr); print(xor_triplet(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))); ; n := (arr)->size(); ; execute (xor_triplet(arr, n))->display(); ) else skip; operation xor_triplet(arr : OclAny, n : OclAny) pre: true post: true activity: var ans : int := 0; ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( for k : Integer.subrange(j, n-1) do ( var xor1 : int := 0; var xor2 : int := 0; ; for x : Integer.subrange(i, j-1) do ( xor1 := xor1 xor arr[x+1];) ; for x : Integer.subrange(j, k + 1-1) do ( xor2 := xor2 xor arr[x+1];) ; if (xor1 = xor2) then ( ans := ans + 1; ) else skip))) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getNumToAdd(arr,n): arr.sort(reverse=False) d=arr[1]-arr[0] numToAdd=-1 numAdded=False for i in range(2,n,1): diff=arr[i]-arr[i-1] if(diff!=d): if(numAdded): return-1 if(diff==2*d): numToAdd=arr[i]-d numAdded=True else : return-1 if(numToAdd==-1): return(arr[n-1]+d) return numToAdd if __name__=='__main__' : arr=[1,3,5,7,11,13,15] n=len(arr) print(getNumToAdd(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{11}->union(Sequence{13}->union(Sequence{ 15 })))))) ; n := (arr)->size() ; execute (getNumToAdd(arr, n))->display() ) else skip; operation getNumToAdd(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var d : double := arr[1+1] - arr->first() ; var numToAdd : int := -1 ; var numAdded : boolean := false ; for i : Integer.subrange(2, n-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( var diff : double := arr[i+1] - arr[i - 1+1] ; if (diff /= d) then ( if (numAdded) then ( return -1 ) else skip ; if (diff = 2 * d) then ( numToAdd := arr[i+1] - d ; numAdded := true ) else ( return -1 ) ) else skip) ; if (numToAdd = -1) then ( return (arr[n - 1+1] + d) ) else skip ; return numToAdd; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline for test in range(int(input())): n=int(input()) s=[0]+list(map(int,input().split())) dp=[1]+[1]*(n) for i in range(1,n+1): for j in range(2*i,n+1,i): if s[i]toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var dp : Sequence := Sequence{ 1 }->union(MatrixLib.elementwiseMult(Sequence{ 1 }, (n))) ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(2 * i, n + 1-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ( if (s[i+1]->compareTo(s[j+1])) < 0 then ( dp[j+1] := Set{dp[j+1], dp[i+1] + 1}->max() ) else skip)) ; execute (((dp))->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) n=list(map(int,list(input()))) n.sort() ch=sum(n) count=0 while chtoInteger() ; var n : Sequence := ((((OclFile["System.in"]).readLine())->characters())->collect( _x | (OclType["int"])->apply(_x) )) ; n := n->sort() ; var ch : OclAny := (n)->sum() ; var count : int := 0 ; while (ch->compareTo(k)) < 0 do ( ch := ch + 9 - n[count+1] ; count := count + 1) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def answer(n,s): f=[1]*(n+1) s.insert(0,0) for i in range(1,n+1): for j in range(2*i,n+1,i): if s[i]select( $x | ($x - 2 * i) mod i = 0 ) do ( if (s[i+1]->compareTo(s[j+1])) < 0 then ( f[j+1] := Set{f[j+1], f[i+1] + 1}->max() ) else skip)) ; return (f)->max(); operation main() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; s := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute (answer(n, s))->display() ; t := t - 1) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def answer(n,s): f=[1]*(n+1) s.insert(0,0) for i in range(1,n+1): for j in range(2*i,n+1,i): if s[i]select( $x | ($x - 2 * i) mod i = 0 ) do ( if (s[i+1]->compareTo(s[j+1])) < 0 then ( f[j+1] := Set{f[j+1], f[i+1] + 1}->max() ) else skip)) ; return (f)->max(); operation main() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; s := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute (answer(n, s))->display() ; t := t - 1) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) s=list(map(int,input().split())) s.insert(0,0) n+=1 dp=[1]*n ans=1 for i in range(2,n): if s[1]toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; s := s.insertAt(0+1, 0) ; n := n + 1 ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, n) ; var ans : int := 1 ; for i : Integer.subrange(2, n-1) do ( if (s[1+1]->compareTo(s[i+1])) < 0 then ( dp[i+1] := Set{dp[i+1], 2}->max() ) else skip ; var j : OclAny := i + i ; while (j->compareTo(n)) < 0 do ( if (s[i+1]->compareTo(s[j+1])) < 0 then ( dp[j+1] := Set{dp[j+1], dp[i+1] + 1}->max() ) else skip ; j := j + i) ; ans := Set{ans, dp[i+1]}->max()) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- arr=list(map(str,input().split())) arr.sort() arr.reverse() x=arr[0]+arr[1] x=int(x) print(x+int(arr[2])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var arr : Sequence := ((input().split())->collect( _x | (OclType["String"])->apply(_x) )) ; arr := arr->sort() ; arr := arr->reverse() ; var x : OclAny := arr->first() + arr[1+1] ; x := ("" + ((x)))->toInteger() ; execute (x + ("" + ((arr[2+1])))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict from collections import deque from heapq import heappush,heappop import sys import math import bisect import random def LI(): return list(map(int,sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return list(map(list,sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l=[None for i in range(n)] for i in range(n): l[i]=I() return l def LIR(n): l=[None for i in range(n)] for i in range(n): l[i]=LI() return l def SR(n): l=[None for i in range(n)] for i in range(n): l[i]=S() return l def LSR(n): l=[None for i in range(n)] for i in range(n): l[i]=LS() return l sys.setrecursionlimit(1000000) mod=1000000007 def A(): a,b,c=LI() print(9*max(a,b,c)+a+b+c) return def B(): return def C(): return def D(): return def E(): return def F(): return def G(): return def H(): return def I_(): return def J(): return if __name__=="__main__" : A() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1000000) ; var mod : int := 1000000007 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( A() ) else skip; operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["Sequence"])->apply(_x) )); operation S() : OclAny pre: true post: true activity: return OclType["Sequence"]((OclFile["System.in"]).readLine())->front(); operation IR(n : OclAny) : OclAny pre: true post: true activity: var l : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; for i : Integer.subrange(0, n-1) do ( l[i+1] := I()) ; return l; operation LIR(n : OclAny) : OclAny pre: true post: true activity: l := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; for i : Integer.subrange(0, n-1) do ( l[i+1] := LI()) ; return l; operation SR(n : OclAny) : OclAny pre: true post: true activity: l := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; for i : Integer.subrange(0, n-1) do ( l[i+1] := S()) ; return l; operation LSR(n : OclAny) : OclAny pre: true post: true activity: l := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; for i : Integer.subrange(0, n-1) do ( l[i+1] := LS()) ; return l; operation A() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := LI() ; execute (9 * Set{a, b, c}->max() + a + b + c)->display() ; return; operation B() pre: true post: true activity: return; operation C() pre: true post: true activity: return; operation D() pre: true post: true activity: return; operation E() pre: true post: true activity: return; operation F() pre: true post: true activity: return; operation G() pre: true post: true activity: return; operation H() pre: true post: true activity: return; operation I_() pre: true post: true activity: return; operation J() pre: true post: true activity: return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B,C=map(int,input().split()) D=[A,B,C] X=max(D) Z=min(D) Y=sum(D)-(X+Z) E=str(X)+str(Y) print(int(E)+int(Z)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{A,B,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var D : Sequence := Sequence{A}->union(Sequence{B}->union(Sequence{ C })) ; var X : OclAny := (D)->max() ; var Z : OclAny := (D)->min() ; var Y : double := (D)->sum() - (X + Z) ; var E : String := ("" + ((X))) + ("" + ((Y))) ; execute (("" + ((E)))->toInteger() + ("" + ((Z)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=sorted(list(map(int,input().split()))) print(a+b+c*10) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; execute (a + b + c * 10)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) x=a*10+b y=b*10+c z=c*10+a if x>=y and x>=z : print(x+c) elif y>=x and y>=z : print(y+a) else : print(z+b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : double := a * 10 + b ; var y : double := b * 10 + c ; var z : double := c * 10 + a ; if (x->compareTo(y)) >= 0 & (x->compareTo(z)) >= 0 then ( execute (x + c)->display() ) else (if (y->compareTo(x)) >= 0 & (y->compareTo(z)) >= 0 then ( execute (y + a)->display() ) else ( execute (z + b)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from itertools import zip_longest as zip T=int(sys.stdin.readline().strip()) def cost(v): v.sort() m=v[len(v)//2] return sum(abs(i-m)for i in v) def partition(s): i=0 while itrim())))->toInteger() ; skip ; skip ; for t : Integer.subrange(0, T-1) do ( var N : int := ("" + ((sys.stdin.readLine()->trim())))->toInteger() ; var ss : Sequence := ((argument (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin)) (trailer . (name readline) (arguments ( ))) (trailer . (name strip) (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) ))))))))) ; var res : int := 0 ; (compound_stmt for (exprlist (expr (atom (name items)))) in (testlist (test (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name partition)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name ss)))))))) ))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name any)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (comparison (expr (atom (name i)))) is (comparison (expr (atom None)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name items)))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom "Case #%d: Fegla Won")) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name t))) + (expr (atom (number (integer 1))))))))) ))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name any)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (comparison (expr (atom (name a)))) != (comparison (expr (atom (name items)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name a))) , (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name items)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom "Case #%d: Fegla Won")) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name t))) + (expr (atom (number (integer 1))))))))) ))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name res)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name cost)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))) (comp_for for (exprlist (expr (atom (name _))) , (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name items)))))))) ))))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom "Case #%d: %d")) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name t))) + (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (atom (name res))))))) ))))))))) )))))))))))))))); operation cost(v : OclAny) : OclAny pre: true post: true activity: v := v->sort() ; var m : OclAny := v[(v)->size() div 2+1] ; return ((argument (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (name m))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name v))))))))->sum(); operation partition(s : OclAny) pre: true post: true activity: var i : int := 0 ; while (i->compareTo((s)->size())) < 0 do ( var j : int := i + 1 ; while (j->compareTo((s)->size())) < 0 & s[i+1] = s[j+1] do ( j := j + 1) ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return Sequence{s[i+1], j - i} ; i := j); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=input(),input() print('-1' if any(y[i]>x[i]for i in range(len(x)))else y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine()} ; execute (if ((argument (test (logical_test (comparison (comparison (expr (atom (name y)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) > (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))))) )))))))))->exists( _x | _x = true ) then '-1' else y endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findPairCount(N,K): count=0 ; rem=[0]*K ; rem[0]=N//K ; for i in range(1,K): rem[i]=(N-i)//K+1 ; if(K % 2==0): count+=(rem[0]*(rem[0]-1))//2 ; for i in range(1,K//2): count+=rem[i]*rem[K-i]; count+=(rem[K//2]*(rem[K//2]-1))//2 ; else : count+=(rem[0]*(rem[0]-1))//2 ; for i in rage(1,K//2+1): count+=rem[i]*rem[K-i]; return count ; if __name__=="__main__" : N=10 ; K=4 ; print(findPairCount(N,K)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := 10; K := 4; ; execute (findPairCount(N, K))->display(); ) else skip; operation findPairCount(N : OclAny, K : OclAny) pre: true post: true activity: var count : int := 0; ; var rem : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, K); ; rem->first() := N div K; ; for i : Integer.subrange(1, K-1) do ( rem[i+1] := (N - i) div K + 1;) ; if (K mod 2 = 0) then ( count := count + (rem->first() * (rem->first() - 1)) div 2; ; for i : Integer.subrange(1, K div 2-1) do ( count := count + rem[i+1] * rem[K - i+1];) ; count := count + (rem[K div 2+1] * (rem[K div 2+1] - 1)) div 2; ) else ( count := count + (rem->first() * (rem->first() - 1)) div 2; ; for i : rage(1, K div 2 + 1) do ( count := count + rem[i+1] * rem[K - i+1];) ) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def removeAlternate(n): if(n==1): return 1 if(n % 2==0): return 2*removeAlternate(n/2)-1 else : return 2*removeAlternate(((n-1)/2))+1 n=5 print(removeAlternate(n)) n=10 print(removeAlternate(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; execute (removeAlternate(n))->display() ; n := 10 ; execute (removeAlternate(n))->display(); operation removeAlternate(n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return 1 ) else skip ; if (n mod 2 = 0) then ( return 2 * removeAlternate(n / 2) - 1 ) else ( return 2 * removeAlternate(((n - 1) / 2)) + 1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): k,st=int(input()),input() s=[] for i in st : s.append(i) sum=0 for i in s : sum+=int(i) if sum>=k : print(0) else : diff=k-sum ans=0 s.sort() for i in range(len(s)): digit_limit=9-int(s[i]) if diff<=digit_limit : ans+=1 print(ans) return else : ans+=1 diff-=digit_limit if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var k : OclAny := null; var st : OclAny := null; Sequence{k,st} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),(OclFile["System.in"]).readLine()} ; var s : Sequence := Sequence{} ; for i : st do ( execute ((i) : s)) ; var sum : int := 0 ; for i : s do ( sum := sum + ("" + ((i)))->toInteger()) ; if (sum->compareTo(k)) >= 0 then ( execute (0)->display() ) else ( var diff : double := k - sum ; var ans : int := 0 ; s := s->sort() ; for i : Integer.subrange(0, (s)->size()-1) do ( var digit_limit : double := 9 - ("" + ((s[i+1])))->toInteger() ; if (diff->compareTo(digit_limit)) <= 0 then ( ans := ans + 1 ; execute (ans)->display() ; return ) else ( ans := ans + 1 ; diff := diff - digit_limit )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def encryptString(string,n): i,cnt=0,0 encryptedStr="" while i0 : encryptedStr+=string[i] cnt-=1 i+=1 return encryptedStr if __name__=="__main__" : string="geeks" n=len(string) print(encryptString(string,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( string := "geeks" ; n := (string)->size() ; execute (encryptString(string, n))->display() ) else skip; operation encryptString(string : OclAny, n : OclAny) : OclAny pre: true post: true activity: var i : OclAny := null; var cnt : OclAny := null; Sequence{i,cnt} := Sequence{0,0} ; var encryptedStr : String := "" ; while (i->compareTo(n)) < 0 do ( var cnt : OclAny := i + 1 ; while cnt > 0 do ( encryptedStr := encryptedStr + string[i+1] ; cnt := cnt - 1) ; i := i + 1) ; return encryptedStr; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compress(s): t=[] prev='#' for c in s : if c!=prev : t.append(c) prev=c return t def extract(s): res=[] prev='#' cnt=1 for c in s : if c!=prev and prev!='#' : res.append(cnt) cnt=1 else : cnt+=1 prev=c res.append(cnt) return res for tc in range(int(input())): N=int(input()) data=[] for i in range(N): data.append(list(input())) compressed=compress(data[0]) valid=True for s in data : if compressed!=compress(s): valid=False break if not valid : print('Case #{}: Fegla Won'.format(tc+1)) continue ext=[extract(s)for s in data] M=len(ext[0]) res=0 for i in range(M): res+=min(sum(abs(j-ext[k][i])for k in range(N))for j in range(1,201)) print('Case #{}:{}'.format(tc+1,res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for tc : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var data : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute ((((OclFile["System.in"]).readLine())->characters()) : data)) ; var compressed : OclAny := compress(data->first()) ; var valid : boolean := true ; for s : data do ( if compressed /= compress(s) then ( valid := false ; break ) else skip) ; if not(valid) then ( execute (StringLib.interpolateStrings('Case #{}: Fegla Won', Sequence{tc + 1}))->display() ; continue ) else skip ; var ext : Sequence := data->select(s | true)->collect(s | (extract(s))) ; var M : int := (ext->first())->size() ; res := 0 ; for i : Integer.subrange(0, M-1) do ( res := res + ((argument (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name j))) - (expr (atom (name ext)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))) ))))))) (comp_for for (exprlist (expr (atom (name k)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 201))))))))) )))))))))->min()) ; execute (StringLib.interpolateStrings('Case #{}:{}', Sequence{tc + 1, res}))->display()); operation compress(s : OclAny) : OclAny pre: true post: true activity: var t : Sequence := Sequence{} ; var prev : String := '#' ; for c : s do ( if c /= prev then ( execute ((c) : t) ) else skip ; prev := c) ; return t; operation extract(s : OclAny) : OclAny pre: true post: true activity: var res : Sequence := Sequence{} ; prev := '#' ; var cnt : int := 1 ; for c : s do ( if c /= prev & prev /= '#' then ( execute ((cnt) : res) ; cnt := 1 ) else ( cnt := cnt + 1 ) ; prev := c) ; execute ((cnt) : res) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- file_in=open('a.in','r') file_out=open('a.out','w') n_case=int(file_in.readline()) class Word : def __init__(self,s): char='0' self.chars=[] self.counts=[] for c in s : if c!=char : self.chars.append(c) self.counts.append(1) char=c else : self.counts[-1]+=1 for i_case in range(n_case): N=int(file_in.readline()) words=[] for i in range(N): words.append(Word(file_in.readline().strip())) chars=words[0].chars def check_equal(): for word in words : if word.chars!=chars : return False return True if not check_equal(): file_out.write("Case #%d: %s\n" %(i_case+1,"Fegla Won")) continue def median(arr): s=sorted(arr) return s[len(s)/2] def actions_needed(arr): count=0 med=median(arr) for a in arr : count+=abs(med-a) return count actions=0 for i_char in range(len(chars)): arr=[] for word in words : arr.append(word.counts[i_char]) actions+=actions_needed(arr) file_out.write("Case #%d: %s\n" %(i_case+1,str(actions))) file_in.close() file_out.close() ------------------------------------------------------------ OCL File: --------- class Word { static operation newWord() : Word pre: true post: Word->exists( _x | result = _x ); attribute chars : Sequence := Sequence{}; attribute counts : Sequence := Sequence{}; operation initialise(s : OclAny) : Word pre: true post: true activity: var char : String := '0' ; self.chars := Sequence{} ; self.counts := Sequence{} ; for c : s do ( if c /= char then ( (expr (atom (name self)) (trailer . (name chars)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))) ; (expr (atom (name self)) (trailer . (name counts)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))) ; char := c ) else ( self.counts->last() := self.counts->last() + 1 )); return self; } class FromPython { operation initialise() pre: true post: true activity: var file_in : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('a.in')) ; var file_out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('a.out')) ; var n_case : int := ("" + ((file_in.readLine())))->toInteger() ; skip ; for i_case : Integer.subrange(0, n_case-1) do ( var N : int := ("" + ((file_in.readLine())))->toInteger() ; var words : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute (((Word.newWord()).initialise(file_in.readLine()->trim())) : words)) ; var chars : OclAny := words->first().chars ; skip ; if not(check_equal()) then ( file_out.write(StringLib.format("Case #%d: %s\n",Sequence{i_case + 1, "Fegla Won"})) ; continue ) else skip ; skip ; skip ; var actions : int := 0 ; for i_char : Integer.subrange(0, (chars)->size()-1) do ( arr := Sequence{} ; for word : words do ( execute ((word.counts[i_char+1]) : arr)) ; actions := actions + actions_needed(arr)) ; file_out.write(StringLib.format("Case #%d: %s\n",Sequence{i_case + 1, ("" + ((actions)))}))) ; file_in.closeFile() ; file_out.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys infile=None outfile=None def readline(): x=infile.readline() if len(x)>0 : return x[:-1] else : return x def readint(): return int(readline()) def readfloat(): return float(readline()) def readints(): xs=readline().split() return[int(x)for x in xs] def readfloats(): xs=readline().split() return[float(x)for x in xs] def writeline(x): outfile.write(x+'\n') def run(main): global infile,outfile args=sys.argv if len(args)==1 : infile=sys.stdin outfile=sys.stdout elif len(args)==2 : if args[1]=='-' : infile=sys.stdin else : infile=open(args[1],'r') if args[1].endswith('.in'): outfile=open(args[1][:-3]+'.out','w') else : outfile=sys.stdout elif len(args)==3 : if args[1]=='-' : infile=sys.stdin else : infile=open(args[1],'r') if args[2]=='-' : outfile=sys.stdout else : outfile=open(args[2],'w') else : print("Expected 0,1,or 2 args,not{:d}".format(len(args)-1)) print(args) return t=readint() for casenum in range(1,t+1): main(casenum) if infile is not sys.stdin : infile.close() if outfile is not sys.stdout : outfile.close() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute infile : OclAny; attribute outfile : OclAny; operation initialise() pre: true post: true activity: skip ; var infile : OclAny := null ; var outfile : OclAny := null ; skip ; skip ; skip ; skip ; skip ; skip ; skip; operation readline() : OclAny pre: true post: true activity: var x : String := infile.readLine() ; if (x)->size() > 0 then ( return x->front() ) else ( return x ); operation readint() : OclAny pre: true post: true activity: return ("" + ((readline())))->toInteger(); operation readfloat() : OclAny pre: true post: true activity: return ("" + ((readline())))->toReal(); operation readints() : OclAny pre: true post: true activity: var xs : OclAny := readline().split() ; return xs->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation readfloats() : OclAny pre: true post: true activity: xs := readline().split() ; return xs->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation writeline(x : OclAny) pre: true post: true activity: outfile.write(x + ' '); operation run(main : OclAny) pre: true post: true activity: skip; skip ; var args : (trailer . (name argv)) := (trailer . (name argv)) ; if (args)->size() = 1 then ( infile := OclFile["System.in"] ; outfile := OclFile["System.out"] ) else (if (args)->size() = 2 then ( if args[1+1] = '-' then ( infile := OclFile["System.in"] ) else ( infile := OclFile.newOclFile_Write(OclFile.newOclFile(args[1+1])) ) ; if args[1+1]->hasSuffix('.in') then ( outfile := OclFile.newOclFile_Write(OclFile.newOclFile(args[1+1].subrange(1,-3) + '.out')) ) else ( outfile := OclFile["System.out"] ) ) else (if (args)->size() = 3 then ( if args[1+1] = '-' then ( infile := OclFile["System.in"] ) else ( infile := OclFile.newOclFile_Write(OclFile.newOclFile(args[1+1])) ) ; if args[2+1] = '-' then ( outfile := OclFile["System.out"] ) else ( outfile := OclFile.newOclFile_Write(OclFile.newOclFile(args[2+1])) ) ) else ( execute (StringLib.interpolateStrings("Expected 0,1,or 2 args,not{:d}", Sequence{(args)->size() - 1}))->display() ; execute (args)->display() ; return ) ) ) ; var t : OclAny := readint() ; for casenum : Integer.subrange(1, t + 1-1) do ( main(casenum)) ; if not(infile <>= OclFile["System.in"]) then ( infile.closeFile() ) else skip ; if not(outfile <>= OclFile["System.out"]) then ( outfile.closeFile() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for case_no in range(1,n+1): n=int(input()) words=[input().strip()for _ in range(n)] accs=[] for word in words : acc=[] for i in range(len(word)): if i>0 and word[i]==word[i-1]: acc[-1][1]+=1 else : acc.append([word[i],1]) accs.append(acc) acclens=list(map(len,accs)) fail=any([x!=acclens[0]for x in acclens]) answer=0 if not fail : for i in range(acclens[0]): if any([accs[0][i][0]!=acc[i][0]for acc in accs]): fail=True break nums=[acc[i][1]for acc in accs] nums.sort() total=0 for num in nums : total+=abs(num-nums[len(nums)//2]) answer+=total if fail : print("Case #"+str(case_no)+": Fegla Won") else : print("Case #"+str(case_no)+": "+str(answer)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for case_no : Integer.subrange(1, n + 1-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var words : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (input()->trim())) ; var accs : Sequence := Sequence{} ; for word : words do ( var acc : Sequence := Sequence{} ; for i : Integer.subrange(0, (word)->size()-1) do ( if i > 0 & word[i+1] = word[i - 1+1] then ( acc->last()[1+1] := acc->last()[1+1] + 1 ) else ( execute ((Sequence{word[i+1]}->union(Sequence{ 1 })) : acc) )) ; execute ((acc) : accs)) ; var acclens : Sequence := ((accs)->collect( _x | (len)->apply(_x) )) ; var fail : boolean := (acclens->select(x | true)->collect(x | (x /= acclens->first())))->exists( _x | _x = true ) ; var answer : int := 0 ; if not(fail) then ( for i : Integer.subrange(0, acclens->first()-1) do ( if (accs->select(acc | true)->collect(acc | (accs->first()[i+1]->first() /= acc[i+1]->first())))->exists( _x | _x = true ) then ( fail := true ; break ) else skip ; var nums : Sequence := accs->select(acc | true)->collect(acc | (acc[i+1][1+1])) ; nums := nums->sort() ; var total : int := 0 ; for num : nums do ( total := total + (num - nums[(nums)->size() div 2+1])->abs()) ; answer := answer + total) ) else skip ; if fail then ( execute ("Case #" + ("" + ((case_no))) + ": Fegla Won")->display() ) else ( execute ("Case #" + ("" + ((case_no))) + ": " + ("" + ((answer))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input('')) l=[] k=[] for i in range(1,n+1): j=n/i if j==int(j): if j>=i : k.append([i,j]) l.append(j-i) m=min(l) for t in range(len(l)): if l[t]==m : print(k[t][0],int(k[t][1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; var l : Sequence := Sequence{} ; var k : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( var j : double := n / i ; if j = ("" + ((j)))->toInteger() then ( if (j->compareTo(i)) >= 0 then ( execute ((Sequence{i}->union(Sequence{ j })) : k) ; execute ((j - i) : l) ) else skip ) else skip) ; var m : OclAny := (l)->min() ; for t : Integer.subrange(0, (l)->size()-1) do ( if l[t+1] = m then ( execute (k[t+1]->first())->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==1 : print(1,1) else : if n % 2==0 : y=[] for i in range(1,n//2+1): if n % i==0 : y.append([abs(n//i-i),i,n//i]) y.sort() temp=y[0] temp.pop(0) temp.sort() print(temp[0],temp[1]) else : y=[] for i in range(1,n//2+1): if n % i==0 : y.append([abs(n//i-i),i,n//i]) y.sort() temp=y[0] temp.pop(0) temp.sort() print(temp[0],temp[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (1)->display() ) else ( if n mod 2 = 0 then ( var y : Sequence := Sequence{} ; for i : Integer.subrange(1, n div 2 + 1-1) do ( if n mod i = 0 then ( execute ((Sequence{(n div i - i)->abs()}->union(Sequence{i}->union(Sequence{ n div i }))) : y) ) else skip) ; y := y->sort() ; var temp : OclAny := y->first() ; temp := temp->excludingAt(0+1) ; temp := temp->sort() ; execute (temp->first())->display() ) else ( y := Sequence{} ; for i : Integer.subrange(1, n div 2 + 1-1) do ( if n mod i = 0 then ( execute ((Sequence{(n div i - i)->abs()}->union(Sequence{i}->union(Sequence{ n div i }))) : y) ) else skip) ; y := y->sort() ; temp := y->first() ; temp := temp->excludingAt(0+1) ; temp := temp->sort() ; execute (temp->first())->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[] l1=[] for i in range(1,n+1): if n % i==0 : p=i q=n//i l.append(i) if q-p>=0 : l1.append(q-p) k=min(l1) s=l[l1.index(k)] print(s,end=' ') print(n//s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; var l1 : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( if n mod i = 0 then ( var p : OclAny := i ; var q : int := n div i ; execute ((i) : l) ; if q - p >= 0 then ( execute ((q - p) : l1) ) else skip ) else skip) ; var k : OclAny := (l1)->min() ; var s : OclAny := l[l1->indexOf(k) - 1+1] ; execute (s)->display() ; execute (n div s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solution(n): pair=[0,n] for i in range(n//2,0,-1): b=i if n % b==0 : a=n//b if(b-a)>=0 and(b-a)<(pair[1]-pair[0]): pair=[a,b] if(pair[1]-pair[0])==n : return[1,n] else : return pair n=int(input()) ans=solution(n) print(ans[0],ans[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : OclAny := solution(n) ; execute (ans->first())->display(); operation solution(n : OclAny) : OclAny pre: true post: true activity: var pair : Sequence := Sequence{0}->union(Sequence{ n }) ; for i : Integer.subrange(0 + 1, n div 2)->reverse() do ( var b : OclAny := i ; if n mod b = 0 then ( var a : int := n div b ; if (b - a) >= 0 & ((b - a)->compareTo((pair[1+1] - pair->first()))) < 0 then ( pair := Sequence{a}->union(Sequence{ b }) ) else skip ) else skip) ; if (pair[1+1] - pair->first()) = n then ( return Sequence{1}->union(Sequence{ n }) ) else ( return pair ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=1 l=[] while a**2<=n : if n % a==0 : l.append(a) a+=1 print(max(l),end=" ") print(n//max(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := 1 ; var l : Sequence := Sequence{} ; while ((a)->pow(2)->compareTo(n)) <= 0 do ( if n mod a = 0 then ( execute ((a) : l) ) else skip ; a := a + 1) ; execute ((l)->max())->display() ; execute (n div (l)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) n=list(map(int,input())) sum0=sum(n) if sum0>=k : print("0") else : num=0 n.sort() for i in n : num+=1 sum0+=9-i if sum0>=k : break print(num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : Sequence := (((OclFile["System.in"]).readLine())->collect( _x | (OclType["int"])->apply(_x) )) ; var sum0 : OclAny := (n)->sum() ; if (sum0->compareTo(k)) >= 0 then ( execute ("0")->display() ) else ( var num : int := 0 ; n := n->sort() ; for i : n do ( num := num + 1 ; sum0 := sum0 + 9 - i ; if (sum0->compareTo(k)) >= 0 then ( break ) else skip) ; execute (num)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): res="NO" nbr=int(input()) s=input() try : if len(s[s.index("8"):])>=11 : res="YES" except Exception : res="NO" print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var res : String := "NO" ; var nbr : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; try ( if (s.subrange(s->indexOf("8") - 1+1))->size() >= 11 then ( res := "YES" ) else skip) (except_clause except (test (logical_test (comparison (expr (atom (name Exception)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name res)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom "NO"))))))))))))) ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxSumBitonicSubArr(arr,n): msis=[None]*n msds=[None]*n max_sum=0 msis[0]=arr[0] for i in range(1,n): if(arr[i]>arr[i-1]): msis[i]=msis[i-1]+arr[i] else : msis[i]=arr[i] msds[n-1]=arr[n-1] for i in range(n-2,-1,-1): if(arr[i]>arr[i+1]): msds[i]=msds[i+1]+arr[i] else : msds[i]=arr[i] for i in range(n): if(max_sum<(msis[i]+msds[i]-arr[i])): max_sum=(msis[i]+msds[i]-arr[i]) return max_sum arr=[5,3,9,2,7,6,4]; n=len(arr) print("Maximum Sum="+str(maxSumBitonicSubArr(arr,n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{5}->union(Sequence{3}->union(Sequence{9}->union(Sequence{2}->union(Sequence{7}->union(Sequence{6}->union(Sequence{ 4 })))))); ; n := (arr)->size() ; execute ("Maximum Sum=" + ("" + ((maxSumBitonicSubArr(arr, n)))))->display(); operation maxSumBitonicSubArr(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var msis : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; var msds : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; var max_sum : int := 0 ; msis->first() := arr->first() ; for i : Integer.subrange(1, n-1) do ( if ((arr[i+1]->compareTo(arr[i - 1+1])) > 0) then ( msis[i+1] := msis[i - 1+1] + arr[i+1] ) else ( msis[i+1] := arr[i+1] )) ; msds[n - 1+1] := arr[n - 1+1] ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( if ((arr[i+1]->compareTo(arr[i + 1+1])) > 0) then ( msds[i+1] := msds[i + 1+1] + arr[i+1] ) else ( msds[i+1] := arr[i+1] )) ; for i : Integer.subrange(0, n-1) do ( if ((max_sum->compareTo((msis[i+1] + msds[i+1] - arr[i+1]))) < 0) then ( max_sum := (msis[i+1] + msds[i+1] - arr[i+1]) ) else skip) ; return max_sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : n=int(input()) s=input() ans='YES' if '8' not in s : ans='NO' elif n-s.index('8')<11 : ans='NO' print(ans) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var ans : String := 'YES' ; if (s)->characters()->excludes('8') then ( ans := 'NO' ) else (if n - s->indexOf('8') - 1 < 11 then ( ans := 'NO' ) else skip) ; execute (ans)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) s=input() if n<11 : print('NO') else : i=s.find('8') if i==-1 : print('NO') else : s=s[i : :] if len(s)<11 : print('NO') else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; if n < 11 then ( execute ('NO')->display() ) else ( var i : int := s->indexOf('8') - 1 ; if i = -1 then ( execute ('NO')->display() ) else ( s := s(subscript (test (logical_test (comparison (expr (atom (name i)))))) : (sliceop :)) ; if (s)->size() < 11 then ( execute ('NO')->display() ) else ( execute ('YES')->display() ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): l=int(input()) s=input() k=0 for j in range(len(s)): if s[j]=='8' : k+=1 break else : k+=1 if len(s)-k>=10 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var k : int := 0 ; for j : Integer.subrange(0, (s)->size()-1) do ( if s[j+1] = '8' then ( k := k + 1 ; break ) else ( k := k + 1 )) ; if (s)->size() - k >= 10 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- test=int(input()) for t in range(test): length=int(input()) seq=[int(x)for x in input()] con=False for i in range(len(seq)-1): if seq[i]==8 : if len(seq[i :])>10 : con=True break print("YES")if con else print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var test : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(0, test-1) do ( var length : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var seq : Sequence := (OclFile["System.in"]).readLine()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var con : boolean := false ; for i : Integer.subrange(0, (seq)->size() - 1-1) do ( if seq[i+1] = 8 then ( if (seq.subrange(i+1))->size() > 10 then ( con := true ; break ) else skip ) else skip) ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))) if (logical_test (comparison (expr (atom (name con))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) ))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maximumPoints(arr,n,k,i): start=0 if(k>i): start=0 else : start=i-k res=0 j=start while(j<=start+k and junion(Sequence{6}->union(Sequence{4}->union(Sequence{2}->union(Sequence{8}->union(Sequence{3}->union(Sequence{ 1 })))))) ; Sequence{k,i} := Sequence{3,3} ; n := (arr)->size() ; execute ("Maximum points :")->display(); operation maximumPoints(arr : OclAny, n : OclAny, k : OclAny, i : OclAny) : OclAny pre: true post: true activity: var start : int := 0 ; if ((k->compareTo(i)) > 0) then ( start := 0 ) else ( start := i - k ) ; var res : int := 0 ; var j : int := start ; while ((j->compareTo(start + k)) <= 0 & (j->compareTo(n)) < 0) do ( res := res + arr[j+1] ; j := j + 1) ; var curr_sum : int := res ; j := start + k + 1 ; while ((j->compareTo(n)) < 0 & (j->compareTo(i + k)) <= 0) do ( curr_sum := curr_sum + arr[j+1] - arr[j - k - 1+1] ; res := Set{res, curr_sum}->max() ; j := j + 1) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minCost(str1,str2,n): cost=0 for i in range(n): if(str1[i]!=str2[i]): if(isize() ; execute (minCost(str1, str2, n))->display() ) else skip; operation minCost(str1 : OclAny, str2 : OclAny, n : OclAny) : OclAny pre: true post: true activity: var cost : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (str1[i+1] /= str2[i+1]) then ( if ((i->compareTo(n - 1)) < 0 & str1[i + 1+1] /= str2[i + 1+1]) then ( swap(str1[i+1], str1[i + 1+1]) ; cost := cost + 1 ) else ( cost := cost + 1 ) ) else skip) ; return cost; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def removeSpecialCharacter(s): i=0 while iord('Z')and ord(s[i])ord('z')): del s[i] i-=1 i+=1 print("".join(s)) if __name__=='__main__' : s="$Gee*k;s..fo,r'Ge^eks?" s=[i for i in s] removeSpecialCharacter(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( s := "$Gee*k;s..fo,r'Ge^eks?" ; s := s->select(i | true)->collect(i | (i)) ; removeSpecialCharacter(s) ) else skip; operation removeSpecialCharacter(s : OclAny) pre: true post: true activity: var i : int := 0 ; while (i->compareTo((s)->size())) < 0 do ( if (((s[i+1])->char2byte()->compareTo(('A')->char2byte())) < 0 or ((s[i+1])->char2byte()->compareTo(('Z')->char2byte())) > 0 & ((s[i+1])->char2byte()->compareTo(('a')->char2byte())) < 0 or ((s[i+1])->char2byte()->compareTo(('z')->char2byte())) > 0) then ( execute (s[i+1])->isDeleted() ; i := i - 1 ) else skip ; i := i + 1) ; execute (StringLib.sumStringsWithSeparator((s), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y,z=map(int,input().split()) a,b,c=map(int,input().split()) if a>=x : if a-x+b>=y : if a-x+b-y+c>=z : print('YES') else : print('NO') else : print('NO') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(x)) >= 0 then ( if (a - x + b->compareTo(y)) >= 0 then ( if (a - x + b - y + c->compareTo(z)) >= 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) else ( execute ('NO')->display() ) ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**8) read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines N,K=map(int,input().split()) coords=[] for i in range(N): x,y=map(int,input().split()) coords.append((x,y)) coords.sort() def solve(): minarea=1<<62 for t in range(N): _,yt=coords[t] for b in range(N): _,yb=coords[b] if ybyb : continue xs.append(xi) for i in range(K-1,len(xs)): w=xs[i]-xs[i-K+1] a=w*h minarea=min(minarea,a) return minarea if __name__=="__main__" : print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(8)) ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var coords : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{x, y}) : coords)) ; coords := coords->sort() ; skip ; if __name__ = "__main__" then ( execute (solve())->display() ) else skip; operation solve() : OclAny pre: true post: true activity: var minarea : int := 1 * (2->pow(62)) ; for t : Integer.subrange(0, N-1) do ( var _anon : OclAny := null; var yt : OclAny := null; Sequence{_anon,yt} := coords[t+1] ; for b : Integer.subrange(0, N-1) do ( var _anon : OclAny := null; var yb : OclAny := null; Sequence{_anon,yb} := coords[b+1] ; if (yb->compareTo(yt)) < 0 then ( continue ) else skip ; var h : double := yb - yt ; var xs : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var xi : OclAny := null; var yi : OclAny := null; Sequence{xi,yi} := coords[i+1] ; if (yi->compareTo(yt)) < 0 or (yi->compareTo(yb)) > 0 then ( continue ) else skip ; execute ((xi) : xs)) ; for i : Integer.subrange(K - 1, (xs)->size()-1) do ( var w : double := xs[i+1] - xs[i - K + 1+1] ; var a : double := w * h ; minarea := Set{minarea, a}->min()))) ; return minarea; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- Ag,Dgp,M=map(int,input().split()) g,p,b=map(int,input().split()) total=g+p+b if gcollect( _x | (OclType["int"])->apply(_x) ) ; var g : OclAny := null; var p : OclAny := null; var b : OclAny := null; Sequence{g,p,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var total : OclAny := g + p + b ; if (g->compareTo(Ag)) < 0 then ( execute ("NO")->display() ) else ( total := total - Ag ; g := g - Ag ; if ((g + p)->compareTo(Dgp)) < 0 then ( execute ("NO")->display() ) else ( total := total - Dgp ; if ((total->compareTo(M)) < 0) then ( execute ("NO")->display() ) else ( execute ("YES")->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) x,y,z=map(int,input().split()) if a>x : print('NO') else : x-=a y+=x if ycollect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(x)) > 0 then ( execute ('NO')->display() ) else ( x := x - a ; y := y + x ; if (y->compareTo(b)) < 0 then ( execute ('NO')->display() ) else ( y := y - b ; if (y + z->compareTo(c)) < 0 then ( execute ('NO')->display() ) else ( execute ('YES')->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findLen(A,n,k,ch): maxlen=1 cnt=0 l=0 r=0 while rk : if A[l]!=ch : cnt-=1 l+=1 maxlen=max(maxlen,r-l+1) r+=1 return maxlen def answer(A,n,k): maxlen=1 for i in range(26): maxlen=max(maxlen,findLen(A,n,k,chr(i+ord('A')))) maxlen=max(maxlen,findLen(A,n,k,chr(i+ord('a')))) return maxlen if __name__=="__main__" : n=5 k=2 A="ABABA" print("Maximum length=",answer(A,n,k)) n=6 k=4 B="HHHHHH" print("Maximum length=",answer(B,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 5 ; k := 2 ; A := "ABABA" ; execute ("Maximum length=")->display() ; n := 6 ; k := 4 ; var B : String := "HHHHHH" ; execute ("Maximum length=")->display() ) else skip; operation findLen(A : OclAny, n : OclAny, k : OclAny, ch : OclAny) : OclAny pre: true post: true activity: var maxlen : int := 1 ; var cnt : int := 0 ; var l : int := 0 ; var r : int := 0 ; while (r->compareTo(n)) < 0 do ( if A[r+1] /= ch then ( cnt := cnt + 1 ) else skip ; while (cnt->compareTo(k)) > 0 do ( if A[l+1] /= ch then ( cnt := cnt - 1 ) else skip ; l := l + 1) ; maxlen := Set{maxlen, r - l + 1}->max() ; r := r + 1) ; return maxlen; operation answer(A : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: maxlen := 1 ; for i : Integer.subrange(0, 26-1) do ( maxlen := Set{maxlen, findLen(A, n, k, (i + ('A')->char2byte())->byte2char())}->max() ; maxlen := Set{maxlen, findLen(A, n, k, (i + ('a')->char2byte())->byte2char())}->max()) ; return maxlen; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline x,y,z=map(int,input().split()) a,b,c=map(int,input().split()) ans="YES" if x>a : ans="NO" a-=x if y>a+b : ans="NO" d=a+b-y if z>c+d : ans="NO" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : String := "YES" ; if (x->compareTo(a)) > 0 then ( ans := "NO" ) else skip ; a := a - x ; if (y->compareTo(a + b)) > 0 then ( ans := "NO" ) else skip ; var d : double := a + b - y ; if (z->compareTo(c + d)) > 0 then ( ans := "NO" ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def line2int(linea): temp="" salida=[] for i in linea : if i=="" : if temp!="" : salida.append(int(temp)) temp="" else : temp=temp+i salida.append(int(temp)) return salida numPersona=line2int(input()) numUvas=line2int(input()) numUvas[0]=numUvas[0]-numPersona[0] if numUvas[0]>=0 : if numPersona[1]>numUvas[0]: numUvas[1]=numUvas[1]-(numPersona[1]-numUvas[0]) numUvas[0]=0 else : numUvas[0]=numUvas[0]-numPersona[1] if numUvas[1]>=0 : if sum(numUvas)>=numPersona[2]: print("YES") else : print("NO") else : print("NO") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var numPersona : OclAny := line2int((OclFile["System.in"]).readLine()) ; var numUvas : OclAny := line2int((OclFile["System.in"]).readLine()) ; numUvas->first() := numUvas->first() - numPersona->first() ; if numUvas->first() >= 0 then ( if (numPersona[1+1]->compareTo(numUvas->first())) > 0 then ( numUvas[1+1] := numUvas[1+1] - (numPersona[1+1] - numUvas->first()) ; numUvas->first() := 0 ) else ( numUvas->first() := numUvas->first() - numPersona[1+1] ) ; if numUvas[1+1] >= 0 then ( if ((numUvas)->sum()->compareTo(numPersona[2+1])) >= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else ( execute ("NO")->display() ) ) else ( execute ("NO")->display() ); operation line2int(linea : OclAny) : OclAny pre: true post: true activity: var temp : String := "" ; var salida : Sequence := Sequence{} ; for i : linea do ( if i = "" then ( if temp /= "" then ( execute ((("" + ((temp)))->toInteger()) : salida) ; temp := "" ) else skip ) else ( temp := temp + i )) ; execute ((("" + ((temp)))->toInteger()) : salida) ; return salida; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthTerm(n): return(n*n)+(n*n*n) n=4 print(nthTerm(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute (nthTerm(n))->display(); operation nthTerm(n : OclAny) : OclAny pre: true post: true activity: return (n * n) + (n * n * n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcdFunc(a,b): if(b==0): return a return gcdFunc(b,a % b) def findMinimumElements(a,n): b=[0]*(n-1) for i in range(1,n): b[i-1]=a[i]-a[i-1] gcd=b[0] for i in range(n-1): gcd=gcdFunc(gcd,b[i]) ans=0 for i in range(n-1): ans+=(b[i]//gcd)-1 return ans arr1=[1,6,8,10,14,16] n1=len(arr1) print(findMinimumElements(arr1,n1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var arr1 : Sequence := Sequence{1}->union(Sequence{6}->union(Sequence{8}->union(Sequence{10}->union(Sequence{14}->union(Sequence{ 16 }))))) ; var n1 : int := (arr1)->size() ; execute (findMinimumElements(arr1, n1))->display(); operation gcdFunc(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (b = 0) then ( return a ) else skip ; return gcdFunc(b, a mod b); operation findMinimumElements(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: b := MatrixLib.elementwiseMult(Sequence{ 0 }, (n - 1)) ; for i : Integer.subrange(1, n-1) do ( b[i - 1+1] := a[i+1] - a[i - 1+1]) ; var gcd : OclAny := b->first() ; for i : Integer.subrange(0, n - 1-1) do ( gcd := gcdFunc(gcd, b[i+1])) ; var ans : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( ans := ans + (b[i+1] div gcd) - 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def stringmatch(txt,pat,n,m): if(m==0): return(n==0) i=0 j=0 index_txt=-1 index_pat=-1 while(isize(), (pattern)->size())) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ; var pattern2 : String := "a*****ab"; ; if (stringmatch(strr, pattern2, (strr)->size(), (pattern2)->size())) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation stringmatch(txt : OclAny, pat : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: if (m = 0) then ( return (n = 0) ) else skip ; var i : int := 0 ; var j : int := 0 ; var index_txt : int := -1 ; var index_pat : int := -1 ; while ((i->compareTo(n - 2)) < 0) do ( if ((j->compareTo(m)) < 0 & txt[i+1] = pat[j+1]) then ( i := i + 1 ; j := j + 1 ) else (if ((j->compareTo(m)) < 0 & pat[j+1] = '?') then ( i := i + 1 ; j := j + 1 ) else (if ((j->compareTo(m)) < 0 & pat[j+1] = '*') then ( index_txt := i ; index_pat := j ; j := j + 1 ) else (if (index_pat /= -1) then ( j := index_pat + 1 ; i := index_txt + 1 ; index_txt := index_txt + 1 ) else ( return false ) ) ) ) ) ; while ((j->compareTo(m)) < 0 & pat[j+1] = '*') do ( j := j + 1) ; if (j = m) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil for _ in range(int(input())): n,m=map(int,input().split()) print(ceil((n*m)/3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (ceil((n * m) / 3))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): arr=input().split(' ') arr=list(map(int,arr)) prod=arr[0]*arr[1] if prod % 3==0 : print(int(prod/3)) else : print(int(prod/3)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var arr : OclAny := input().split(' ') ; arr := ((arr)->collect( _x | (OclType["int"])->apply(_x) )) ; var prod : double := arr->first() * arr[1+1] ; if prod mod 3 = 0 then ( execute (("" + ((prod / 3)))->toInteger())->display() ) else ( execute (("" + ((prod / 3)))->toInteger() + 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) k=int(input()) A=int(input()) B=int(input()) x=n i=0 def f(x,i): if x==1 : return i elif x % k==0 and B<=(x-x//k)*A : return f(x//k,i+B) elif x % k==0 : return f(1,i+A*(x-1)) else : return f(x-x % k,i+A*(x % k)) print(f(x,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := n ; var i : int := 0 ; skip ; execute (f(x, 0))->display(); operation f(x : OclAny, i : OclAny) : OclAny pre: true post: true activity: if x = 1 then ( return i ) else (if x mod k = 0 & (B->compareTo((x - x div k) * A)) <= 0 then ( return f(x div k, i + B) ) else (if x mod k = 0 then ( return f(1, i + A * (x - 1)) ) else ( return f(x - x mod k, i + A * (x mod k)) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) for i in range(n): a,b=map(int,input().split()) p=a*b print(math.ceil(p/3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : double := a * b ; execute ((p / 3)->ceil())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil for a in range(int(input())): n,m=list(map(int,input().split())) print(ceil((n*m)/3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for a : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (ceil((n * m) / 3))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() for i in range(int(input())): m,n=map(int,input().split()) print(((m*n)+2)//3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (((m * n) + 2) div 3)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countDistinct(arr,n): arr.sort(); res=0 ; i=0 ; while(iunion(Sequence{10}->union(Sequence{5}->union(Sequence{4}->union(Sequence{9}->union(Sequence{120}->union(Sequence{4}->union(Sequence{6}->union(Sequence{ 10 })))))))); ; n := (arr)->size(); ; execute (countDistinct(arr, n))->display();; operation countDistinct(arr : OclAny, n : OclAny) pre: true post: true activity: arr := arr->sort(); ; var res : int := 0; ; var i : int := 0; ; while ((i->compareTo(n)) < 0) do ( while ((i->compareTo(n - 1)) < 0 & arr[i+1] = arr[i + 1+1]) do ( i := i + 1;) ; res := res + 1; ; i := i + 1;) ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def restoreSortedArray(arr,n): for i in range(n): if(arr[i]>arr[i+1]): reverse(arr,0,i); reverse(arr,i+1,n); reverse(arr,0,n); def reverse(arr,i,j): while(iunion(Sequence{4}->union(Sequence{5}->union(Sequence{1}->union(Sequence{ 2 })))); ; n := (arr)->size(); ; restoreSortedArray(arr, n - 1); ; printArray(arr, n); ) else skip; operation restoreSortedArray(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if ((arr[i+1]->compareTo(arr[i + 1+1])) > 0) then ( reverse(arr, 0, i); ; reverse(arr, i + 1, n); ; reverse(arr, 0, n); ) else skip); operation reverse(arr : OclAny, i : OclAny, j : OclAny) pre: true post: true activity: while ((i->compareTo(j)) < 0) do ( var temp : OclAny := arr[i+1]; ; arr[i+1] := arr[j+1]; ; arr[j+1] := temp; ; i := i + 1; ; j := j - 1;); operation printArray(arr : OclAny, size : OclAny) pre: true post: true activity: for i : Integer.subrange(0, size-1) do ( execute (arr[i+1])->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B,C=map(int,input().split()) if B>=A*C : print(C) else : print(B//A) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{A,B,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (B->compareTo(A * C)) >= 0 then ( execute (C)->display() ) else ( execute (B div A)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) print(min(b//a,c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{b div a, c}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- [A,B,C]=[int(i)for i in input().split()] print(C if B//A>C else B//A) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: Sequence{A}->union(Sequence{B}->union(Sequence{ C })) := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute (if (B div A->compareTo(C)) > 0 then C else B div A endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) n=b//a if n>=c : print(c) if ncollect( _x | (OclType["int"])->apply(_x) ) ; var n : int := b div a ; if (n->compareTo(c)) >= 0 then ( execute (c)->display() ) else skip ; if (n->compareTo(c)) < 0 then ( execute (n)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) able_num=int(b/a) print(min(able_num,c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var able_num : int := ("" + ((b / a)))->toInteger() ; execute (Set{able_num, c}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def solve(n,k,A,B): ans=0 while n>1 : if n % k==0 : if(n-n//k)*Ak : ans+=A*(n-k*(n//k)) n=k*(n//k) else : ans+=A*(n-1) break print(ans) n=int(input()) k=int(input()) A=int(input()) B=int(input()) solve(n,k,A,B) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; k := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; A := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; B := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; solve(n, k, A, B); operation solve(n : OclAny, k : OclAny, A : OclAny, B : OclAny) pre: true post: true activity: var ans : int := 0 ; while n > 1 do ( if n mod k = 0 then ( if ((n - n div k) * A->compareTo(B)) < 0 then ( ans := ans + A * (n - 1) ; break ) else skip ; ans := ans + Set{(n - n div k) * A, B}->min() ; n := n div k ) else (if (n->compareTo(k)) > 0 then ( ans := ans + A * (n - k * (n div k)) ; n := k * (n div k) ) else ( ans := ans + A * (n - 1) ; break ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution : def selfDividingNumbers(self,left : int,right : int)->List[int]: return[x for x in range(left,right+1)if all([int(i)!=0 and x % int(i)==0 for i in str(x)])] ------------------------------------------------------------ OCL File: --------- class Solution { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation selfDividingNumbers(left : int,right : int) : OclAny pre: true post: true activity: return Integer.subrange(left, right + 1-1)->select(x | (("" + ((x)))->select(i | true)->collect(i | (("" + ((i)))->toInteger() /= 0 & x mod ("" + ((i)))->toInteger() = 0)))->forAll( _x | _x = true ))->collect(x | (x)); } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,m=map(int,input().split()) if n==m==0 : break l=int(input()) v=[[]for i in range(m+1)] for _ in range(l): t,nn,m,s=map(int,input().split()) s=1 if s else-1 v[m].append((t,s)) q=int(input()) for _ in range(q): s,e,m=map(int,input().split()) v[m].sort() arr=[0]*1261 for i,j in v[m]: arr[i]+=j for i in range(540,len(arr)-1): arr[i+1]+=arr[i] res=0 for i in range(s,e): if arr[i]>0 : res+=1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = m & (m == 0) then ( break ) else skip ; var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var v : Sequence := Integer.subrange(0, m + 1-1)->select(i | true)->collect(i | (Sequence{})) ; for _anon : Integer.subrange(0, l-1) do ( var t : OclAny := null; var nn : OclAny := null; var m : OclAny := null; var s : OclAny := null; Sequence{t,nn,m,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : int := if s then 1 else -1 endif ; (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name m)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name t)))))) , (test (logical_test (comparison (expr (atom (name s))))))) )))))))) ))))) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( var e : OclAny := null; var m : OclAny := null; Sequence{s,e,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name m)))))))) ])) (trailer . (name sort) (arguments ( )))) ; var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 1261) ; for _tuple : v[m+1] do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); arr[i+1] := arr[i+1] + j) ; for i : Integer.subrange(540, (arr)->size() - 1-1) do ( arr[i + 1+1] := arr[i + 1+1] + arr[i+1]) ; var res : int := 0 ; for i : Integer.subrange(s, e-1) do ( if arr[i+1] > 0 then ( res := res + 1 ) else skip) ; execute (res)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): ans_list=[] while True : ans=solve() if ans==-1 : break ans_list+=ans for ans in ans_list : print(ans) def solve(): res_list=[] N,M=map(int,input().split()) if(N,M)==(0,0): return-1 sh=[[0]*(1260-540+1)for _ in range(M)] r=int(input()) for _ in range(r): t,n,m,s=map(int,input().split()) t-=540 m-=1 if s==1 : sh[m][t]+=1 elif s==0 : sh[m][t]-=1 acc=0 for i,line in enumerate(sh): for j,bit in enumerate(line): acc+=bit if acc>=1 : sh[i][j]=1 else : sh[i][j]=0 q=int(input()) for _ in range(q): ts,te,m=map(int,input().split()) ts-=540 te-=540 m-=1 res=sum(sh[m][ts : te]) res_list.append(res) return res_list main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: var ans_list : Sequence := Sequence{} ; while true do ( var ans : OclAny := solve() ; if ans = -1 then ( break ) else skip ; ans_list := ans_list + ans) ; for ans : ans_list do ( execute (ans)->display()); operation solve() : OclAny pre: true post: true activity: var res_list : Sequence := Sequence{} ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if Sequence{N, M} = Sequence{0, 0} then ( return -1 ) else skip ; var sh : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (1260 - 540 + 1)))) ; var r : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, r-1) do ( var t : OclAny := null; var n : OclAny := null; var m : OclAny := null; var s : OclAny := null; Sequence{t,n,m,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; t := t - 540 ; m := m - 1 ; if s = 1 then ( sh[m+1][t+1] := sh[m+1][t+1] + 1 ) else (if s = 0 then ( sh[m+1][t+1] := sh[m+1][t+1] - 1 ) else skip)) ; var acc : int := 0 ; for _tuple : Integer.subrange(1, (sh)->size())->collect( _indx | Sequence{_indx-1, (sh)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var line : OclAny := _tuple->at(_indx); for _tuple : Integer.subrange(1, (line)->size())->collect( _indx | Sequence{_indx-1, (line)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var bit : OclAny := _tuple->at(_indx); acc := acc + bit ; if acc >= 1 then ( sh[i+1][j+1] := 1 ) else ( sh[i+1][j+1] := 0 ))) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( var ts : OclAny := null; var te : OclAny := null; var m : OclAny := null; Sequence{ts,te,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; ts := ts - 540 ; te := te - 540 ; m := m - 1 ; var res : OclAny := (sh[m+1].subrange(ts+1, te))->sum() ; execute ((res) : res_list)) ; return res_list; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,m=map(int,input().split()) if n==0 : break r=int(input()) records=[] for i in range(r): records.append(list(map(int,input().split()))) q=int(input()) queries=[] for i in range(q): queries.append(list(map(int,input().split()))) for q in queries : st=q[2] rs=list(filter(lambda x : x[2]==st,records)) pcs=[[0,0]for i in range(n)] ls=[] for r in rs : pcs[r[1]-1][r[3]]=r[0] if r[3]==0 : ls.append(pcs[r[1]-1]) pcs[r[1]-1]=[0,0] if not ls : print(0) continue ls.sort(key=lambda x : x[1]) uses=[] start,end=ls[0][1],ls[0][0] for v in ls[1 :]: if v[0]end : uses.append((start,end)) start,end=v[1],v[0] uses.append((start,end)) ans=0 for u in uses : for i in range(u[0],u[1]): if i>=q[0]and icollect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var r : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var records : Sequence := Sequence{} ; for i : Integer.subrange(0, r-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : records)) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var queries : Sequence := Sequence{} ; for i : Integer.subrange(0, q-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : queries)) ; for q : queries do ( var st : OclAny := q[2+1] ; var rs : Sequence := ((records)->select( _x | (lambda x : OclAny in (x[2+1] = st))->apply(_x) = true )) ; var pcs : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{0}->union(Sequence{ 0 }))) ; var ls : Sequence := Sequence{} ; for r : rs do ( pcs[r[1+1] - 1+1][r[3+1]+1] := r->first() ; if r[3+1] = 0 then ( execute ((pcs[r[1+1] - 1+1]) : ls) ; pcs[r[1+1] - 1+1] := Sequence{0}->union(Sequence{ 0 }) ) else skip) ; if not(ls) then ( execute (0)->display() ; continue ) else skip ; ls := ls->sort() ; var uses : Sequence := Sequence{} ; var start : OclAny := null; var end : OclAny := null; Sequence{start,end} := Sequence{ls->first()[1+1],ls->first()->first()} ; for v : ls->tail() do ( if (v->first()->compareTo(end)) < 0 then ( continue ) else (if (v[1+1]->compareTo(end)) <= 0 then ( var end : OclAny := v->first() ) else (if (v[1+1]->compareTo(end)) > 0 then ( execute ((Sequence{start, end}) : uses) ; var start : OclAny := null; Sequence{start,end} := Sequence{v[1+1],v->first()} ) else skip ) ) ) ; execute ((Sequence{start, end}) : uses) ; var ans : int := 0 ; for u : uses do ( for i : Integer.subrange(u->first(), u[1+1]-1) do ( if (i->compareTo(q->first())) >= 0 & (i->compareTo(q[1+1])) < 0 then ( ans := ans + 1 ) else skip)) ; execute (ans)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() a=*map(int,input().split()), b=a[0],*(x*(a[0]>=2*x)for x in a[1 :]) if 2*sum(b)<=sum(a): b=() print(sum(map(bool,b)),*(i for i,x in enumerate(b,1)if x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var a : OclAny := (testlist_star_expr (star_expr * (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))) ,) ; var b : OclAny := a->first(),Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) >= (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name x))))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))))))} ; if (2 * (b)->sum()->compareTo((a)->sum())) <= 0 then ( b := () ) else skip ; execute (((b)->collect( _x | (OclType["boolean"])->apply(_x) ))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(N,M): member=[[0]*721 for i in range(M)] r=int(input()) for _ in range(r): t,_,m,s=map(int,input().split()) t-=540 if s==0 : member[m-1][t]-=1 else : member[m-1][t]+=1 for i in range(M): for t in range(1,721): member[i][t]+=member[i][t-1] q=int(input()) for i in range(q): ts,te,m=map(int,input().split()) ts-=540 te-=540 ans=0 for t in range(ts,te): ans+=(member[m-1][t]>0) print(ans) while 1 : n,m=map(int,input().split()) if n==m==0 : break main(n,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while 1 do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = m & (m == 0) then ( break ) else skip ; main(n, m)); operation main(N : OclAny, M : OclAny) pre: true post: true activity: var member : Sequence := Integer.subrange(0, M-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, 721))) ; var r : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, r-1) do ( var t : OclAny := null; var _anon : OclAny := null; var m : OclAny := null; var s : OclAny := null; Sequence{t,_anon,m,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; t := t - 540 ; if s = 0 then ( member[m - 1+1][t+1] := member[m - 1+1][t+1] - 1 ) else ( member[m - 1+1][t+1] := member[m - 1+1][t+1] + 1 )) ; for i : Integer.subrange(0, M-1) do ( for t : Integer.subrange(1, 721-1) do ( member[i+1][t+1] := member[i+1][t+1] + member[i+1][t - 1+1])) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( var ts : OclAny := null; var te : OclAny := null; var m : OclAny := null; Sequence{ts,te,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; ts := ts - 540 ; te := te - 540 ; var ans : int := 0 ; for t : Integer.subrange(ts, te-1) do ( ans := ans + (member[m - 1+1][t+1] > 0)) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while(True): N,M=map(int,input().split()) if N==0 and M==0 : break r=int(input()) TIME_MINIMUM=540 util_times=[[0 for _ in range(721)]for _ in range(M)] for i in range(r): time,_,stud,sta=map(int,input().split()) util_times[stud-1][time-TIME_MINIMUM]+=sta*2-1 q_num=int(input()) for _ in range(q_num): sta,end,stud=map(int,input().split()) ut=[util_times[stud-1][i]for i in range(end-TIME_MINIMUM)] for i in range(1,end-TIME_MINIMUM): ut[i]=ut[i]+ut[i-1] if(ut[i]<0): print("DEBUG") print(sum([1 for i in ut[sta-TIME_MINIMUM :]if i>0])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while (true) do ( var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if N = 0 & M = 0 then ( break ) else skip ; var r : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var TIME_MINIMUM : int := 540 ; var util_times : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, 721-1)->select(_anon | true)->collect(_anon | (0)))) ; for i : Integer.subrange(0, r-1) do ( var time : OclAny := null; var _anon : OclAny := null; var stud : OclAny := null; var sta : OclAny := null; Sequence{time,_anon,stud,sta} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; util_times[stud - 1+1][time - TIME_MINIMUM+1] := util_times[stud - 1+1][time - TIME_MINIMUM+1] + sta * 2 - 1) ; var q_num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q_num-1) do ( var sta : OclAny := null; var end : OclAny := null; var stud : OclAny := null; Sequence{sta,end,stud} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ut : Sequence := Integer.subrange(0, end - TIME_MINIMUM-1)->select(i | true)->collect(i | (util_times[stud - 1+1][i+1])) ; for i : Integer.subrange(1, end - TIME_MINIMUM-1) do ( ut[i+1] := ut[i+1] + ut[i - 1+1] ; if (ut[i+1] < 0) then ( execute ("DEBUG")->display() ) else skip) ; execute ((ut.subrange(sta - TIME_MINIMUM+1)->select(i | i > 0)->collect(i | (1)))->sum())->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minOps(arr,n,k): max1=max(arr) res=0 for i in range(0,n): if((max1-arr[i])% k!=0): return-1 else : res+=(max1-arr[i])/k return int(res) arr=[21,33,9,45,63] n=len(arr) k=6 print(minOps(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{21}->union(Sequence{33}->union(Sequence{9}->union(Sequence{45}->union(Sequence{ 63 })))) ; n := (arr)->size() ; k := 6 ; execute (minOps(arr, n, k))->display(); operation minOps(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var max1 : OclAny := (arr)->max() ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ((max1 - arr[i+1]) mod k /= 0) then ( return -1 ) else ( res := res + (max1 - arr[i+1]) / k )) ; return ("" + ((res)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class newNode : def __init__(self,key): self.data=key self.left=None self.right=None def maxLevelProduct(root): if(root==None): return 0 result=root.data q=[] q.append(root) while(len(q)): count=len(q) product=1 while(count): count-=1 temp=q[0] q.pop(0) product=product*temp.data if(temp.left!=None): q.append(temp.left) if(temp.right!=None): q.append(temp.right) result=max(product,result) return result if __name__=='__main__' : root=newNode(1) root.left=newNode(2) root.right=newNode(3) root.left.left=newNode(4) root.left.right=newNode(5) root.right.right=newNode(8) root.right.right.left=newNode(6) root.right.right.right=newNode(7) print("Maximum level product is",maxLevelProduct(root)) ------------------------------------------------------------ OCL File: --------- class newNode { static operation newnewNode() : newNode pre: true post: newNode->exists( _x | result = _x ); attribute data : OclAny := key; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(key : OclAny) : newNode pre: true post: true activity: self.data := key ; self.left := null ; self.right := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( root := (newNode.newnewNode()).initialise(1) ; root.left := (newNode.newnewNode()).initialise(2) ; root.right := (newNode.newnewNode()).initialise(3) ; root.left.left := (newNode.newnewNode()).initialise(4) ; root.left.right := (newNode.newnewNode()).initialise(5) ; root.right.right := (newNode.newnewNode()).initialise(8) ; root.right.right.left := (newNode.newnewNode()).initialise(6) ; root.right.right.right := (newNode.newnewNode()).initialise(7) ; execute ("Maximum level product is")->display() ) else skip; operation maxLevelProduct(root : OclAny) : OclAny pre: true post: true activity: if (root = null) then ( return 0 ) else skip ; var result : OclAny := root.data ; var q : Sequence := Sequence{} ; execute ((root) : q) ; while ((q)->size()) do ( var count : int := (q)->size() ; var product : int := 1 ; while (count) do ( count := count - 1 ; var temp : OclAny := q->first() ; q := q->excludingAt(0+1) ; product := product * temp.data ; if (temp.left /= null) then ( execute ((temp.left) : q) ) else skip ; if (temp.right /= null) then ( execute ((temp.right) : q) ) else skip) ; result := Set{product, result}->max()) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getFrequencies(string): freq=[0]*26 for i in range(len(string)): freq[ord(string[i])-ord('a')]+=1 return freq def countMinParts(string): n=len(string) freq=getFrequencies(string) oddFreq=[] evenFreq=[] sumEven=0 for i in range(26): if freq[i]==0 : continue if freq[i]% 2==0 : evenFreq.append(freq[i]) else : oddFreq.append(freq[i]) for i in range(len(evenFreq)): sumEven+=evenFreq[i] if len(oddFreq)==0 : return 1 if sumEven==0 : if len(oddFreq)==1 : return 1 return 0 i=0 while(idisplay() ) else skip; operation getFrequencies(string : OclAny) : OclAny pre: true post: true activity: var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for i : Integer.subrange(0, (string)->size()-1) do ( freq[(string[i+1])->char2byte() - ('a')->char2byte()+1] := freq[(string[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; return freq; operation countMinParts(string : OclAny) : OclAny pre: true post: true activity: var n : int := (string)->size() ; freq := getFrequencies(string) ; var oddFreq : Sequence := Sequence{} ; var evenFreq : Sequence := Sequence{} ; var sumEven : int := 0 ; for i : Integer.subrange(0, 26-1) do ( if freq[i+1] = 0 then ( continue ) else skip ; if freq[i+1] mod 2 = 0 then ( execute ((freq[i+1]) : evenFreq) ) else ( execute ((freq[i+1]) : oddFreq) )) ; for i : Integer.subrange(0, (evenFreq)->size()-1) do ( sumEven := sumEven + evenFreq[i+1]) ; if (oddFreq)->size() = 0 then ( return 1 ) else skip ; if sumEven = 0 then ( if (oddFreq)->size() = 1 then ( return 1 ) else skip ; return 0 ) else skip ; var i : int := 0 ; while ((i->compareTo((oddFreq)->size())) < 0) do ( if ((sumEven / 2) mod (oddFreq)->size() = 0) then ( return (oddFreq)->size() ) else skip ; if (oddFreq[i+1] = 1) then ( i := i + 1 ; continue ) else skip ; sumEven := sumEven + 2 ; oddFreq[i+1] := oddFreq[i+1] - 2) ; return n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def solve(n,k,A,B): ans=0 while n>1 : if n % k==0 : if(n-n//k)*Ak : ans+=A*(n-k*(n//k)) n=k*(n//k) else : ans+=A*(n-1) break print(ans) n=int(input()) k=int(input()) A=int(input()) B=int(input()) solve(n,k,A,B) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; k := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; A := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; B := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; solve(n, k, A, B); operation solve(n : OclAny, k : OclAny, A : OclAny, B : OclAny) pre: true post: true activity: var ans : int := 0 ; while n > 1 do ( if n mod k = 0 then ( if ((n - n div k) * A->compareTo(B)) < 0 then ( ans := ans + A * (n - 1) ; break ) else skip ; ans := ans + Set{(n - n div k) * A, B}->min() ; n := n div k ) else (if (n->compareTo(k)) > 0 then ( ans := ans + A * (n - k * (n div k)) ; n := k * (n div k) ) else ( ans := ans + A * (n - 1) ; break ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=4 ; def stepsRequired(arr): result=0 ; for i in range(N): for j in range(N): if(i>j+1): result+=abs(arr[i][j]); return result ; arr=[[1,2,3,4],[3,1,0,3],[3,2,1,3],[-3,4,2,1]]; print(stepsRequired(arr)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 4; ; skip ; arr := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })))}->union(Sequence{Sequence{3}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 3 })))}->union(Sequence{Sequence{3}->union(Sequence{2}->union(Sequence{1}->union(Sequence{ 3 })))}->union(Sequence{ Sequence{-3}->union(Sequence{4}->union(Sequence{2}->union(Sequence{ 1 }))) }))); ; execute (stepsRequired(arr))->display();; operation stepsRequired(arr : OclAny) pre: true post: true activity: var result : int := 0; ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( if ((i->compareTo(j + 1)) > 0) then ( result := result + (arr[i+1][j+1])->abs(); ) else skip)) ; return result;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=4 def stepsRequired(arr): result=0 for i in range(N): for j in range(N): if(j>i+1): result+=abs(arr[i][j]) return result arr=[[1,2,3,2],[3,1,0,3],[3,2,1,3],[-3,4,2,1]] print(stepsRequired(arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 4 ; skip ; arr := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 2 })))}->union(Sequence{Sequence{3}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 3 })))}->union(Sequence{Sequence{3}->union(Sequence{2}->union(Sequence{1}->union(Sequence{ 3 })))}->union(Sequence{ Sequence{-3}->union(Sequence{4}->union(Sequence{2}->union(Sequence{ 1 }))) }))) ; execute (stepsRequired(arr))->display(); operation stepsRequired(arr : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( if ((j->compareTo(i + 1)) > 0) then ( result := result + (arr[i+1][j+1])->abs() ) else skip)) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): TILES=10**6 ans=0 for n in range(3,TILES//4+2): for k in range(n-2,0,-2): if n*n-k*k>TILES : break ans+=1 return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var TILES : double := (10)->pow(6) ; var ans : int := 0 ; for n : Integer.subrange(3, TILES div 4 + 2-1) do ( for k : Integer.subrange(n - 2, 0-1)->select( $x | ($x - n - 2) mod -2 = 0 ) do ( if (n * n - k * k->compareTo(TILES)) > 0 then ( break ) else skip ; ans := ans + 1)) ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rev(n,temp): if(n==0): return temp ; temp=(temp*10)+(n % 10); return rev(n/10,temp); n=121 ; temp=rev(n,0); if(temp!=n): print("yes"); else : print("no"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 121; ; temp := rev(n, 0); ; if (temp /= n) then ( execute ("yes")->display(); ) else ( execute ("no")->display(); ); operation rev(n : OclAny, temp : OclAny) pre: true post: true activity: if (n = 0) then ( return temp; ) else skip ; temp := (temp * 10) + (n mod 10); ; return rev(n / 10, temp);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def solution(n,arr): ans=0 while True : is_sorted=True for i in range(n): if arr[i]!=(i+1): is_sorted=False break if is_sorted : return ans if(ans+1)% 2!=0 : for i in range(0,n,2): if(i+1)arr[i+1]: tmp=arr[i] arr[i]=arr[i+1] arr[i+1]=tmp else : for i in range(1,n,2): if(i+1)arr[i+1]: tmp=arr[i] arr[i]=arr[i+1] arr[i+1]=tmp ans+=1 t=int(input()) while t : t-=1 n=int(input()) arr=[int(x)for x in input().strip().split(" ")] print(solution(n,arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( t := t - 1 ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; arr := input()->trim().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (solution(n, arr))->display()); operation solution(n : OclAny, arr : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; while true do ( var is_sorted : boolean := true ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] /= (i + 1) then ( is_sorted := false ; break ) else skip) ; if is_sorted then ( return ans ) else skip ; if (ans + 1) mod 2 /= 0 then ( for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( if ((i + 1)->compareTo(n)) < 0 & (arr[i+1]->compareTo(arr[i + 1+1])) > 0 then ( var tmp : OclAny := arr[i+1] ; arr[i+1] := arr[i + 1+1] ; arr[i + 1+1] := tmp ) else skip) ) else ( for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( if ((i + 1)->compareTo(n)) < 0 & (arr[i+1]->compareTo(arr[i + 1+1])) > 0 then ( tmp := arr[i+1] ; arr[i+1] := arr[i + 1+1] ; arr[i + 1+1] := tmp ) else skip) ) ; ans := ans + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys import itertools import fractions if __name__=='__main__' : wtf=sys.stdin.read() wtf=wtf.strip().split('\n') n=int(wtf[0]) A=list(map(int,wtf[1].split())) a0=A[0] S=sum(A) hS=S//2 B=sorted(range(n),reverse=True,key=lambda k : A[k]) ans=[1] aS=a0 for b in B : if aS>hS : break if b==0 : continue if a0>=2*A[b]: aS+=A[b] ans.append(b+1) if aS>hS : print(f'{len(ans)}\n'+' '.join(map(str,ans))) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var wtf : String := (OclFile["System.in"]).readAll() ; wtf := wtf->trim().split(' ') ; var n : int := ("" + ((wtf->first())))->toInteger() ; var A : Sequence := ((wtf[1+1].split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a0 : OclAny := A->first() ; var S : OclAny := (A)->sum() ; var hS : int := S div 2 ; var B : Sequence := Integer.subrange(0, n-1)->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var ans : Sequence := Sequence{ 1 } ; var aS : OclAny := a0 ; for b : B do ( if (aS->compareTo(hS)) > 0 then ( break ) else skip ; if b = 0 then ( continue ) else skip ; if (a0->compareTo(2 * A[b+1])) >= 0 then ( aS := aS + A[b+1] ; execute ((b + 1) : ans) ) else skip) ; if (aS->compareTo(hS)) > 0 then ( execute (StringLib.formattedString('{len(ans)} ') + StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ) else ( execute (0)->display() ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=sorted for s in[*open(0)][2 : : 2]: *a,=map(int,s.split()); i=c=0 while a>f(a): j=i while j ; (testlist_star_expr (star_expr * (expr (atom (name a)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name a)))) ,)} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ); var i : OclAny := 0; var c : int := 0 ; while (a->compareTo(f(a))) > 0 do ( var j : OclAny := i ; while (j->compareTo((a)->size() - 1)) < 0 do ( a.subrange(j+1, j + 2) := f(a.subrange(j+1, j + 2)); j := j + 2) ; c := c + 1; i := i xor 1) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from ast import Break import string,math,time,random,itertools s_time=time.time() def ex(a,i): temp=0 if a[i]>a[i+1]: temp=a[i] a[i]=a[i+1] a[i+1]=temp t=int(input('')) for i in range(t): n=int(input('')) nums=input('').rsplit() nums=[int(l)for l in nums] sol=0 a=1 q=0 if nums==sorted(nums): print(0) else : while 1 : if(a % 2)!=0 : for j in range(1,n,2): ex(nums,j-1) else : for k in range(2,n,2): ex(nums,k-1) if nums==sorted(nums): break sol+=1 a+=1 print(sol+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var s_time : OclAny := time.time() ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; var nums : OclAny := input('').rsplit() ; nums := nums->select(l | true)->collect(l | (("" + ((l)))->toInteger())) ; var sol : int := 0 ; a := 1 ; var q : int := 0 ; if nums = nums->sort() then ( execute (0)->display() ) else ( while 1 do ( if (a mod 2) /= 0 then ( for j : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( ex(nums, j - 1)) ) else ( for k : Integer.subrange(2, n-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( ex(nums, k - 1)) ) ; if nums = nums->sort() then ( break ) else skip ; sol := sol + 1 ; a := a + 1) ; execute (sol + 1)->display() )); operation ex(a : OclAny, i : OclAny) pre: true post: true activity: var temp : int := 0 ; if (a[i+1]->compareTo(a[i + 1+1])) > 0 then ( temp := a[i+1] ; a[i+1] := a[i + 1+1] ; a[i + 1+1] := temp ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import* from decimal import* import sys from tkinter import N input_=sys.stdin.readline def _input(): return map(int,input().split()) def _list(): return list(map(int,input().split())) def swap(a,b): return(b,a) def f(a,i): if(i % 2==0): for i in range(0,len(a)-2,2): if(a[i]>a[i+1]): a[i],a[i+1]=a[i+1],a[i] else : for i in range(1,len(a)-1,2): if(a[i]>a[i+1]): a[i],a[i+1]=a[i+1],a[i] return(a) def solves(): n=int(input()) ans=0 a=_list() b=sorted(a) i=0 while True : if(a==b): break a=f(a,i) i+=1 ans+=1 print(ans) t=1 t=int(input()) for _ in range(0,t): solves() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var input_ : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; skip ; var t : int := 1 ; t := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( solves()); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation _list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation swap(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return Sequence{b, a}; operation f(a : OclAny, i : OclAny) : OclAny pre: true post: true activity: if (i mod 2 = 0) then ( for i : Integer.subrange(0, (a)->size() - 2-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( if ((a[i+1]->compareTo(a[i + 1+1])) > 0) then ( var a[i+1] : OclAny := null; var a[i + 1+1] : OclAny := null; Sequence{a[i+1],a[i + 1+1]} := Sequence{a[i + 1+1],a[i+1]} ) else skip) ) else ( for i : Integer.subrange(1, (a)->size() - 1-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( if ((a[i+1]->compareTo(a[i + 1+1])) > 0) then ( var a[i+1] : OclAny := null; var a[i + 1+1] : OclAny := null; Sequence{a[i+1],a[i + 1+1]} := Sequence{a[i + 1+1],a[i+1]} ) else skip) ) ; return (a); operation solves() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; a := _list() ; b := a->sort() ; i := 0 ; while true do ( if (a = b) then ( break ) else skip ; a := f(a, i) ; i := i + 1 ; ans := ans + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,a=int(input()),[int(i)for i in input().split()] res,cnt=0,sum(1 for i in range(n)if a[i]!=i+1) while cnt>0 : for i in range(0 if res & 1==0 else 1,n-1,2): if a[i]>a[i+1]: a[i],a[i+1]=a[i+1],a[i] cnt-=a[i]==i+1 cnt+=a[i+1]==i+1 cnt-=a[i+1]==i+2 cnt+=a[i]==i+2 res+=1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))} ; var res : OclAny := null; var cnt : OclAny := null; Sequence{res,cnt} := Sequence{0,((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) != (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))))))->sum()} ; while cnt > 0 do ( for i : Integer.subrange(if MathLib.bitwiseAnd(res, 1) = 0 then 0 else 1 endif, n - 1-1)->select( $x | ($x - if MathLib.bitwiseAnd(res, 1) = 0 then 0 else 1 endif) mod 2 = 0 ) do ( if (a[i+1]->compareTo(a[i + 1+1])) > 0 then ( var a[i+1] : OclAny := null; var a[i + 1+1] : OclAny := null; Sequence{a[i+1],a[i + 1+1]} := Sequence{a[i + 1+1],a[i+1]} ; cnt := cnt - a[i+1] = i + 1 ; cnt := cnt + a[i + 1+1] = i + 1 ; cnt := cnt - a[i + 1+1] = i + 2 ; cnt := cnt + a[i+1] = i + 2 ) else skip) ; res := res + 1) ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from locale import currency import sys from collections import Counter sys.setrecursionlimit(20000) n=int(input()) k=int(input()) a=int(input()) b=int(input()) current=n cost=0 if k==1 : print((current-1)*a) exit() while current>1 : if current % k!=0 : if currenttoInteger() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var current : int := n ; var cost : int := 0 ; if k = 1 then ( execute ((current - 1) * a)->display() ; exit() ) else skip ; while current > 1 do ( if current mod k /= 0 then ( if (current->compareTo(k)) < 0 then ( cost := cost + a * (current - 1) ; current := 1 ) else ( cost := cost + a * (current mod k) ; current := current - current mod k ) ) else ( if (a * (current - current / k)->compareTo(b)) <= 0 then ( cost := cost + a * (current - current / k) ) else ( cost := cost + b ) ; current := current / k )) ; execute (("" + ((cost)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def STR(): return list(input()) def INT(): return int(input()) def MAP(): return map(int,input().split()) def MAP2(): return map(float,input().split()) def LIST(): return list(map(int,input().split())) def STRING(): return input() import string import sys import datetime from heapq import heappop,heappush from bisect import* from collections import deque,Counter,defaultdict from math import* from itertools import permutations,accumulate dx=[-1,1,0,0] dy=[0,0,1,-1] m,k=MAP() dis=LIST() lit=LIST() tank=0 time=0 mx=-1 for i in range(m): tank+=lit[i] mx=max(mx,lit[i]) while tankunion(Sequence{1}->union(Sequence{0}->union(Sequence{ 0 }))) ; var dy : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ -1 }))) ; var m : OclAny := null; var k : OclAny := null; Sequence{m,k} := MAP() ; var dis : OclAny := LIST() ; var lit : OclAny := LIST() ; var tank : int := 0 ; var time : int := 0 ; var mx : int := -1 ; for i : Integer.subrange(0, m-1) do ( tank := tank + lit[i+1] ; mx := Set{mx, lit[i+1]}->max() ; while (tank->compareTo(dis[i+1])) < 0 do ( time := time + k ; tank := tank + mx) ; tank := tank - dis[i+1] ; time := time + dis[i+1]) ; execute (time)->display(); operation STR() : OclAny pre: true post: true activity: return ((OclFile["System.in"]).readLine())->characters(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation MAP2() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["double"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation STRING() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil n,k=map(int,input().split()) d=list(map(int,input().split())) s=list(map(int,input().split())) fuel=0 stor=0 time=0 for i in range(n): fuel+=s[i] stor=max(stor,s[i]) if fuel>=d[i]: fuel-=d[i] time+=d[i] else : yy=ceil((d[i]-fuel)/stor) time+=k*yy time+=d[i] fuel+=stor*yy fuel-=d[i] print(time) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var fuel : int := 0 ; var stor : int := 0 ; var time : int := 0 ; for i : Integer.subrange(0, n-1) do ( fuel := fuel + s[i+1] ; stor := Set{stor, s[i+1]}->max() ; if (fuel->compareTo(d[i+1])) >= 0 then ( fuel := fuel - d[i+1] ; time := time + d[i+1] ) else ( var yy : OclAny := ceil((d[i+1] - fuel) / stor) ; time := time + k * yy ; time := time + d[i+1] ; fuel := fuel + stor * yy ; fuel := fuel - d[i+1] )) ; execute (time)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): import sys input=sys.stdin.readline m,k=map(int,input().split()) d=list(map(int,input().split())) s=list(map(int,input().split())) t=0 f=0 ma=0 for i in range(m): f+=s[i] ma=max(ma,s[i]) while fcollect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : int := 0 ; var f : int := 0 ; var ma : int := 0 ; for i : Integer.subrange(0, m-1) do ( f := f + s[i+1] ; ma := Set{ma, s[i+1]}->max() ; while (f->compareTo(d[i+1])) < 0 do ( f := f + ma ; t := t + k) ; t := t + d[i+1] ; f := f - d[i+1]) ; execute (t)->display() ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) d=list(map(int,input().split())) p=list(map(int,input().split())) t=0 ; d1=0 ; i=0 while i=p[j]: j+=1 k=(-t-sum(p[i : j])-1+sum(d[i : j])+pr)//pr d1+=b*k t=(pr*k-(-t-sum(p[i : j])+sum(d[i : j])))% pr i=j else : i+=1 print(sum(d)+d1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : int := 0; var d1 : int := 0; var i : int := 0 ; while (i->compareTo(a)) < 0 do ( if t + (p(subscript (test (logical_test (comparison (expr (atom (name i)))))) : (sliceop :)))->sum() - (d(subscript (test (logical_test (comparison (expr (atom (name i)))))) : (sliceop :)))->sum() < 0 then ( var j : int := i; var pr : OclAny := p[i+1] ; while (j->compareTo(a)) < 0 & (pr->compareTo(p[j+1])) >= 0 do ( j := j + 1) ; var k : int := (-t - (p.subrange(i+1, j))->sum() - 1 + (d.subrange(i+1, j))->sum() + pr) div pr ; d1 := d1 + b * k ; t := (pr * k - (-t - (p.subrange(i+1, j))->sum() + (d.subrange(i+1, j))->sum())) mod pr ; i := j ) else ( i := i + 1 )) ; execute ((d)->sum() + d1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,k=map(int,input().split()) d=list(map(int,input().split())) s=list(map(int,input().split())) cap=0 dis=0 ma=0 time=0 for i in range(m): dis=d[i] cap+=(s[i]-d[i]) time+=d[i] ma=max(ma,s[i]) if cap<0 : while cap<0 : cap+=ma time+=k print(time) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var k : OclAny := null; Sequence{m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cap : int := 0 ; var dis : int := 0 ; var ma : int := 0 ; var time : int := 0 ; for i : Integer.subrange(0, m-1) do ( dis := d[i+1] ; cap := cap + (s[i+1] - d[i+1]) ; time := time + d[i+1] ; ma := Set{ma, s[i+1]}->max() ; if cap < 0 then ( while cap < 0 do ( cap := cap + ma ; time := time + k) ) else skip) ; execute (time)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) w=list(map(int,input().split())) d=w[0] a=[1] for i in range(1,n): if w[i]<=w[0]//2 : d+=w[i] a.append(i+1) if d>sum(w)//2 : print(len(a)) print(*a) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := w->first() ; var a : Sequence := Sequence{ 1 } ; for i : Integer.subrange(1, n-1) do ( if (w[i+1]->compareTo(w->first() div 2)) <= 0 then ( d := d + w[i+1] ; execute ((i + 1) : a) ) else skip) ; if (d->compareTo((w)->sum() div 2)) > 0 then ( execute ((a)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display() ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() a=*map(int,input().split()), b=a[0],*(x*(a[0]>=2*x)for x in a[1 :]) if 2*sum(b)<=sum(a): b=() print(sum(map(bool,b)),*(i for i,x in enumerate(b,1)if x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var a : OclAny := (testlist_star_expr (star_expr * (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))) ,) ; var b : OclAny := a->first(),Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) >= (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name x))))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))))))} ; if (2 * (b)->sum()->compareTo((a)->sum())) <= 0 then ( b := () ) else skip ; execute (((b)->collect( _x | (OclType["boolean"])->apply(_x) ))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) x=sum(l) if l[0]>x/2 : print(1) print(1) else : ans=[] res=l[0] ans.append(1) for i in range(1,n): if l[0]>=2*l[i]: ans.append(i+1) res+=l[i] if res>x/2 : print(len(ans)) print(*ans) break if res<=x/2 : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := (l)->sum() ; if (l->first()->compareTo(x / 2)) > 0 then ( execute (1)->display() ; execute (1)->display() ) else ( var ans : Sequence := Sequence{} ; var res : OclAny := l->first() ; execute ((1) : ans) ; for i : Integer.subrange(1, n-1) do ( if (l->first()->compareTo(2 * l[i+1])) >= 0 then ( execute ((i + 1) : ans) ; res := res + l[i+1] ) else skip ; if (res->compareTo(x / 2)) > 0 then ( execute ((ans)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ; break ) else skip) ; if (res->compareTo(x / 2)) <= 0 then ( execute (0)->display() ) else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def removeAnagrams(arr,N): ans=[] found=dict() for i in range(N): word=arr[i] word=" ".join(sorted(word)) if(word not in found): ans.append(arr[i]) found[word]=1 ans=sorted(ans) for i in range(len(ans)): print(ans[i],end=" ") if __name__=='__main__' : arr=["geeks","keegs","code","doce"] N=4 removeAnagrams(arr,N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{"geeks"}->union(Sequence{"keegs"}->union(Sequence{"code"}->union(Sequence{ "doce" }))) ; N := 4 ; removeAnagrams(arr, N) ) else skip; operation removeAnagrams(arr : OclAny, N : OclAny) pre: true post: true activity: var ans : Sequence := Sequence{} ; var found : Map := (arguments ( )) ; for i : Integer.subrange(0, N-1) do ( var word : OclAny := arr[i+1] ; word := StringLib.sumStringsWithSeparator((word->sort()), " ") ; if ((found)->excludes(word)) then ( execute ((arr[i+1]) : ans) ; found[word+1] := 1 ) else skip) ; ans := ans->sort() ; for i : Integer.subrange(0, (ans)->size()-1) do ( execute (ans[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() op=input() b='' flag=0 for i,j in zip(a,op): if(i==j): b+='z' if(i>j): b+=j if(isize())->collect( _indx | Sequence{a->at(_indx), op->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if (i = j) then ( b := b + 'z' ) else skip ; if ((i->compareTo(j)) > 0) then ( b := b + j ) else skip ; if ((i->compareTo(j)) < 0) then ( flag := 1 ; break ) else skip) ; if (flag = 0) then ( execute (b)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) k=int(input()) A=int(input()) B=int(input()) x=n ans=0 if k>1 : while x>1 : if x % k==0 : if A*(x-x//k)toInteger() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := n ; var ans : int := 0 ; if k > 1 then ( while x > 1 do ( if x mod k = 0 then ( if (A * (x - x div k)->compareTo(B)) < 0 then ( ans := ans + A * (x - x div k) ) else ( ans := ans + B ) ; x := x div k ) else ( if (x->compareTo(k)) < 0 then ( ans := ans + A * (x - 1) ; x := 1 ) else ( ans := ans + A * (x mod k) ; x := x - x mod k ) )) ) else ( ans := A * (x - 1) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() prev=[(0,0)] upto={} best=0 for i in range(len(s)-1,-1,-1): ones,zeros=prev[-1] if s[i]=='1' : my_ones,my_zeros=ones+1,zeros if my_ones==my_zeros : best=max(best,len(s)-i) else : check=(my_ones-my_zeros) if check in upto : best=max(best,upto[check]-i) else : upto[check]=i prev.append((my_ones,my_zeros)) else : my_ones,my_zeros=ones,zeros+1 if my_ones==my_zeros : best=max(best,len(s)-i) else : check=(my_ones-my_zeros) if check in upto : best=max(best,upto[check]-i) else : upto[check]=i prev.append((my_ones,my_zeros)) print(best) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var prev : Sequence := Sequence{ Sequence{0, 0} } ; var upto : OclAny := Set{} ; var best : int := 0 ; for i : Integer.subrange(-1 + 1, (s)->size() - 1)->reverse() do ( var ones : OclAny := null; var zeros : OclAny := null; Sequence{ones,zeros} := prev->last() ; if s[i+1] = '1' then ( var my_ones : OclAny := null; var my_zeros : OclAny := null; Sequence{my_ones,my_zeros} := Sequence{ones + 1,zeros} ; if my_ones = my_zeros then ( best := Set{best, (s)->size() - i}->max() ) else ( var check : double := (my_ones - my_zeros) ; if (upto)->includes(check) then ( best := Set{best, upto[check+1] - i}->max() ) else ( upto[check+1] := i ) ) ; execute ((Sequence{my_ones, my_zeros}) : prev) ) else ( var my_ones : OclAny := null; var my_zeros : OclAny := null; Sequence{my_ones,my_zeros} := Sequence{ones,zeros + 1} ; if my_ones = my_zeros then ( best := Set{best, (s)->size() - i}->max() ) else ( check := (my_ones - my_zeros) ; if (upto)->includes(check) then ( best := Set{best, upto[check+1] - i}->max() ) else ( upto[check+1] := i ) ) ; execute ((Sequence{my_ones, my_zeros}) : prev) )) ; execute (best)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate n,s=int(input()),[*accumulate(map(lambda x : 2*int(x)-1,input()))] l={0 :-1}; c=0 for x,y in enumerate(s): l[y]=e=l.get(y,x) c=max(c,x-e) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),accumulate(((OclFile["System.in"]).readLine())->collect( _x | (lambda x : OclAny in (2 * ("" + ((x)))->toInteger() - 1))->apply(_x) ))} ; var l : Map := Map{ 0 |-> -1 }; var c : int := 0 ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); l[y+1] := l.get(y, x); var e : OclAny := l.get(y, x) ; c := Set{c, x - e}->max()) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=list(map(int,list(input()))) ct_1=0 ct_0=0 p={0 :-1} ans=0 for i in range(len(s)): if not s[i]: ct_0+=1 else : ct_1+=1 a=ct_1-ct_0 if a in p : ans=max(i-p[a],ans) else : p[a]=i print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((((OclFile["System.in"]).readLine())->characters())->collect( _x | (OclType["int"])->apply(_x) )) ; var ct var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() : int := 0 ; var ct_0 : int := 0 ; var p : Map := Map{ 0 |-> -1 } ; var ans : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if not(s[i+1]) then ( ct_0 := ct_0 + 1 ) else ( ct var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() := ct var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() + 1 ) ; var a : double := ct if not(s[i+1]) then ( ct_0 := ct_0 + 1 ) else ( ct var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() := ct var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() + 1 ) - ct_0 ; if (p)->includes(a) then ( ans := Set{i - p[a+1], ans}->max() ) else ( p[a+1] := i )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(200000) import math from collections import Counter from collections import defaultdict from collections import deque input=sys.stdin.readline from functools import lru_cache import heapq def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s=input() return(list(s[: len(s)-1])) def invr(): return(map(int,input().split())) n=inp() arr=insr() prefix=[0] for i in range(len(arr)): if arr[i]=="0" : prefix.append(prefix[-1]-1) else : prefix.append(prefix[-1]+1) f=defaultdict(lambda : math.inf) ans=0 for i in range(len(prefix)): ans=max(i-f[prefix[i]],ans) f[prefix[i]]=min(i,f[prefix[i]]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(200000) ; skip ; skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := inp() ; var arr : OclAny := insr() ; var prefix : Sequence := Sequence{ 0 } ; for i : Integer.subrange(0, (arr)->size()-1) do ( if arr[i+1] = "0" then ( execute ((prefix->last() - 1) : prefix) ) else ( execute ((prefix->last() + 1) : prefix) )) ; var f : OclAny := defaultdict(lambda $$ : OclAny in ()) ; var ans : int := 0 ; for i : Integer.subrange(0, (prefix)->size()-1) do ( ans := Set{i - f[prefix[i+1]+1], ans}->max() ; f[prefix[i+1]+1] := Set{i, f[prefix[i+1]+1]}->min()) ; execute (ans)->display(); operation inp() : OclAny pre: true post: true activity: return (("" + (((OclFile["System.in"]).readLine())))->toInteger()); operation inlt() : OclAny pre: true post: true activity: return (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))); operation insr() : OclAny pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; return ((s.subrange(1,(s)->size() - 1))); operation invr() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) v=input() count1=0 count0=0 lin={} lin[0]=-1 counter=0 for i in range(n): if v[i]=='0' : count0+=1 else : count1+=1 if count1-count0 in lin : counter=max(i-lin[count1-count0],counter) else : lin[count1-count0]=i print(counter) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var v : String := (OclFile["System.in"]).readLine() ; var count1 : int := 0 ; var count0 : int := 0 ; var lin : OclAny := Set{} ; lin->first() := -1 ; var counter : int := 0 ; for i : Integer.subrange(0, n-1) do ( if v[i+1] = '0' then ( count0 := count0 + 1 ) else ( count1 := count1 + 1 ) ; if (lin)->includes(count1 - count0) then ( counter := Set{i - lin[count1 - count0+1], counter}->max() ) else ( lin[count1 - count0+1] := i )) ; execute (counter)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() print(sum([(len(i)+4)//5 for i in(s.split('C')+s.split('P'))])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; execute (((s.split('C') + s.split('P'))->select(i | true)->collect(i | (((i)->size() + 4) div 5)))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() print(sum([(len(i)+4)//5 for i in(s.split('C')+s.split('P'))])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; execute (((s.split('C') + s.split('P'))->select(i | true)->collect(i | (((i)->size() + 4) div 5)))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input(); x=s[0]; a=b=0 for i in s : if i!=x or b==5 : x=i ; b=0 ; a+=1 b+=1 print(a+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine(); var x : OclAny := s->first(); var a : OclAny := 0; var b : int := 0 ; for i : s->characters() do ( if i /= x or b = 5 then ( x := i; b := 0; a := a + 1 ) else skip ; b := b + 1) ; execute (a + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() print(sum([(len(i)+4)//5 for i in(s.split('C')+s.split('P'))])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; execute (((s.split('C') + s.split('P'))->select(i | true)->collect(i | (((i)->size() + 4) div 5)))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() print(sum([(len(i)+4)//5 for i in(s.split('C')+s.split('P'))])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; execute (((s.split('C') + s.split('P'))->select(i | true)->collect(i | (((i)->size() + 4) div 5)))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def digSum(n): sum=0 while(n>0 or sum>9): if(n==0): n=sum sum=0 sum+=n % 10 n/=10 return sum n=1234 print(digSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 1234 ; execute (digSum(n))->display(); operation digSum(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; while (n > 0 or sum > 9) do ( if (n = 0) then ( n := sum ; sum := 0 ) else skip ; sum := sum + n mod 10 ; n := n / 10) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def m(p): return lambda x : x*p def aa(u,v): for x,y in zip(u,v): yield x+y def get_p(a): u=[1] for x in a : u=list(aa([0,0]+list(map(m(x),u)),list(map(m(1-x),u))+[0,0])) return u[len(u)>>1] for i in range(int(input())): n,k=map(int,input().split()) p=sorted(list(map(float,input().split()))) r=0 for j in range(k+1): v=p[: j]+p[: :-1][: k-j] assert(len(v)==k) r=max(r,get_p(v)) print("Case #%d: %.12f" %(i+1,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; p := ((input().split())->collect( _x | (OclType["double"])->apply(_x) ))->sort() ; var r : int := 0 ; for j : Integer.subrange(0, k + 1-1) do ( v := p.subrange(1,j) + p(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))).subrange(1,k - j) ; assert ((v)->size() = k) do "assertion failed" ; r := Set{r, get_p(v)}->max()) ; execute (StringLib.format("Case #%d: %.12f",Sequence{i + 1, r}))->display()); operation m(p : OclAny) : OclAny pre: true post: true activity: return lambda x : OclAny in (x * p); operation aa(u : OclAny, v : OclAny) pre: true post: true activity: for _tuple : Integer.subrange(1, u->size())->collect( _indx | Sequence{u->at(_indx), v->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return x + y); operation get_p(a : OclAny) : OclAny pre: true post: true activity: u := Sequence{ 1 } ; for x : a do ( u := (aa(Sequence{0}->union(Sequence{ 0 })->union(((u)->collect( _x | (m(x))->apply(_x) ))), ((u)->collect( _x | (m(1 - x))->apply(_x) ))->union(Sequence{0}->union(Sequence{ 0 }))))) ; return u[(u)->size() /(2->pow(1))+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() y=input() s="" flag=0 for i in range(len(x)): if ord(x[i])size()-1) do ( if ((x[i+1])->char2byte()->compareTo((y[i+1])->char2byte())) < 0 then ( flag := 1 ; break ) else ( s := s + (Set{(x[i+1])->char2byte(), (y[i+1])->char2byte()}->min())->byte2char() )) ; if flag then ( execute (-1)->display() ) else ( execute (s)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkchild(a,i): value=0 while(a[i]!=-1): value+=1 i=a[i] return value n=int(input()) index=[0] sum=0 for i in range(n): pi=int(input()) index.append(pi) for i in range(1,n+1): test=checkchild(index,i) if(sumtoInteger() ; var index : Sequence := Sequence{ 0 } ; var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( var pi : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((pi) : index)) ; for i : Integer.subrange(1, n + 1-1) do ( var test : OclAny := checkchild(index, i) ; if ((sum->compareTo(test)) < 0) then ( sum := test ) else skip) ; execute (sum + 1)->display(); operation checkchild(a : OclAny, i : OclAny) : OclAny pre: true post: true activity: var value : int := 0 ; while (a[i+1] /= -1) do ( value := value + 1 ; i := a[i+1]) ; return value; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def grouping(eList): res=0 for i in range(1,len(eList)): counter=0 k=eList[i] while(k!=-1): k=eList[k] counter+=1 res=max(res,counter) return res+1 def main(): n=int(input()) employees=[] for i in range(n): employees.append(int(input())) employees.insert(0,0) print(grouping(employees)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation grouping(eList : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; for i : Integer.subrange(1, (eList)->size()-1) do ( var counter : int := 0 ; var k : OclAny := eList[i+1] ; while (k /= -1) do ( k := eList[k+1] ; counter := counter + 1) ; res := Set{res, counter}->max()) ; return res + 1; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var employees : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : employees)) ; employees := employees.insertAt(0+1, 0) ; execute (grouping(employees))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) d={i :[]for i in range(1,n+1)} level={i : 0 for i in range(1,n+1)} q=[] for i in range(1,n+1): x=int(input()) if x!=-1 : d[x].append(i) else : q.append(i) while q : curr=q[-1] for x in d[curr]: level[x]=level[curr]+1 q.pop() q+=d[curr] print(max(level.values())+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Map := Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | Map{i |-> Sequence{}})->unionAll() ; var level : Map := Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | Map{i |-> 0})->unionAll() ; var q : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if x /= -1 then ( (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ) else ( execute ((i) : q) )) ; while q do ( var curr : OclAny := q->last() ; for x : d[curr+1] do ( level[x+1] := level[curr+1] + 1) ; q := q->front() ; q := q + d[curr+1]) ; execute ((level.values())->max() + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque n=int(input()) adj=defaultdict(list) for i in range(n): adj[int(input())].append(i+1) q=deque() q.append(-1) grp=0 visited=set() while q : for _ in range(len(q)): root=q.popleft() visited.add(root) for nei in adj[root]: if nei not in visited : q.append(nei) grp+=1 print(grp-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var adj : OclAny := defaultdict(OclType["Sequence"]) ; for i : Integer.subrange(0, n-1) do ((expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ))))) ; var q : Sequence := () ; execute ((-1) : q) ; var grp : int := 0 ; var visited : Set := Set{}->union(()) ; while q do ( for _anon : Integer.subrange(0, (q)->size()-1) do ( var root : OclAny := q->first() ; q := q->tail() ; execute ((root) : visited) ; for nei : adj[root+1] do ( if (visited)->excludes(nei) then ( execute ((nei) : q) ) else skip)) ; grp := grp + 1) ; execute (grp - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) tab=[int(input())for i in range(n)] depth=1 for i in range(n): k=i act_depth=0 while i!=-1 : act_depth+=1 ; i=tab[i-1]; depth=max(depth,act_depth) print(depth) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var tab : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var depth : int := 1 ; for i : Integer.subrange(0, n-1) do ( var k : OclAny := i ; var act_depth : int := 0 ; while i /= -1 do ( act_depth := act_depth + 1; ; var i : OclAny := tab[i - 1+1];) ; depth := Set{depth, act_depth}->max()) ; execute (depth)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n): low=1 high=10**4 x,p=n,0 while(low<=high): mid=(low+high)//2 sum=(mid*(mid+1))//2 if(x-sum>=1): p=mid low=mid+1 else : high=mid-1 start,end,y,q=1,10**4,1,0 while(start<=end): mid=(start+end)//2 sum=(mid*(mid+1))//2 if(y+sum<=n): q=mid start=mid+1 else : end=mid-1 x=x-(p*(p+1))//2 y=y+(q*(q+1))//2 r=x c=q+1-n+y return r,c n=5 r,c=solve(n) print(r,c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; Sequence{r,c} := solve(n) ; execute (r)->display(); operation solve(n : OclAny) : OclAny pre: true post: true activity: var low : int := 1 ; var high : double := (10)->pow(4) ; var x : OclAny := null; var p : OclAny := null; Sequence{x,p} := Sequence{n,0} ; while ((low->compareTo(high)) <= 0) do ( var mid : int := (low + high) div 2 ; var sum : int := (mid * (mid + 1)) div 2 ; if (x - sum >= 1) then ( var p : int := mid ; low := mid + 1 ) else ( high := mid - 1 )) ; var start : OclAny := null; var end : OclAny := null; var y : OclAny := null; var q : OclAny := null; Sequence{start,end,y,q} := Sequence{1,(10)->pow(4),1,0} ; while ((start->compareTo(end)) <= 0) do ( mid := (start + end) div 2 ; sum := (mid * (mid + 1)) div 2 ; if ((y + sum->compareTo(n)) <= 0) then ( var q : int := mid ; var start : int := mid + 1 ) else ( var end : double := mid - 1 )) ; var x : double := x - (p * (p + 1)) div 2 ; var y : OclAny := y + (q * (q + 1)) div 2 ; var r : OclAny := x ; var c : double := q + 1 - n + y ; return r, c; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(k)for k in input().split()] w=[] for j in range(n): w.append([int(k)for k in input().split()]) res=n*m for j in w : c=sum(j) d=m-sum(j) res+=max(2**c-c-1,0) res+=max(2**d-d-1,0) for j in range(m): eta=[w[x][j]for x in range(n)] c=sum(eta) d=n-sum(eta) res+=max(2**c-c-1,0) res+=max(2**d-d-1,0) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger())) ; var w : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( execute ((input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger()))) : w)) ; var res : double := n * m ; for j : w do ( var c : OclAny := (j)->sum() ; var d : double := m - (j)->sum() ; res := res + Set{(2)->pow(c) - c - 1, 0}->max() ; res := res + Set{(2)->pow(d) - d - 1, 0}->max()) ; for j : Integer.subrange(0, m-1) do ( var eta : Sequence := Integer.subrange(0, n-1)->select(x | true)->collect(x | (w[x+1][j+1])) ; c := (eta)->sum() ; d := n - (eta)->sum() ; res := res + Set{(2)->pow(c) - c - 1, 0}->max() ; res := res + Set{(2)->pow(d) - d - 1, 0}->max()) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- matrix=[] alt,larg=map(int,input().split()[: 2]) for i in range(0,alt): line=list(map(int,input().split()[: larg])) matrix.append(line) total_zeros_line=0 total_ones_line=0 total_zeros_col=0 total_ones_col=0 result=alt*larg for i in range(0,alt): zeros_line=0 ones_line=0 for j in range(0,larg): elem_linha=matrix[i][j] if(elem_linha==1): ones_line=ones_line+1 else : zeros_line=zeros_line+1 total_zeros_line=total_zeros_line+(int(2**(zeros_line)-zeros_line-1)) total_ones_line=total_ones_line+(int(2**(ones_line)-ones_line-1)) for i in range(0,larg): zeros_col=0 ones_col=0 for j in range(0,alt): elem_col=matrix[j][i] if(elem_col==1): ones_col=ones_col+1 else : zeros_col=zeros_col+1 total_zeros_col=total_zeros_col+(int(2**(zeros_col)-zeros_col-1)) total_ones_col=total_ones_col+(int(2**(ones_col)-ones_col-1)) result=result+total_ones_col+total_zeros_col+total_ones_line+total_zeros_line print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var matrix : Sequence := Sequence{} ; var alt : OclAny := null; var larg : OclAny := null; Sequence{alt,larg} := (input().split().subrange(1,2))->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, alt-1) do ( var line : Sequence := ((input().split().subrange(1,larg))->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((line) : matrix)) ; var total_zeros_line : int := 0 ; var total_ones_line : int := 0 ; var total_zeros_col : int := 0 ; var total_ones_col : int := 0 ; var result : double := alt * larg ; for i : Integer.subrange(0, alt-1) do ( var zeros_line : int := 0 ; var ones_line : int := 0 ; for j : Integer.subrange(0, larg-1) do ( var elem_linha : OclAny := matrix[i+1][j+1] ; if (elem_linha = 1) then ( ones_line := ones_line + 1 ) else ( zeros_line := zeros_line + 1 )) ; total_zeros_line := total_zeros_line + (("" + (((2)->pow((zeros_line)) - zeros_line - 1)))->toInteger()) ; total_ones_line := total_ones_line + (("" + (((2)->pow((ones_line)) - ones_line - 1)))->toInteger())) ; for i : Integer.subrange(0, larg-1) do ( var zeros_col : int := 0 ; var ones_col : int := 0 ; for j : Integer.subrange(0, alt-1) do ( var elem_col : OclAny := matrix[j+1][i+1] ; if (elem_col = 1) then ( ones_col := ones_col + 1 ) else ( zeros_col := zeros_col + 1 )) ; total_zeros_col := total_zeros_col + (("" + (((2)->pow((zeros_col)) - zeros_col - 1)))->toInteger()) ; total_ones_col := total_ones_col + (("" + (((2)->pow((ones_col)) - ones_col - 1)))->toInteger())) ; result := result + total_ones_col + total_zeros_col + total_ones_line + total_zeros_line ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) s=input() t=input() dp=[[0]*(m+1)for _ in range(n+1)] ans=0 for i in range(n+1): for j in range(m+1): if icollect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (m + 1)))) ; var ans : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( for j : Integer.subrange(0, m + 1-1) do ( if (i->compareTo(n)) < 0 then ( dp[i + 1+1][j+1] := Set{dp[i + 1+1][j+1], dp[i+1][j+1] - 1}->max() ) else skip ; if (j->compareTo(m)) < 0 then ( dp[i+1][j + 1+1] := Set{dp[i+1][j + 1+1], dp[i+1][j+1] - 1}->max() ) else skip ; if (i->compareTo(n)) < 0 & (j->compareTo(m)) < 0 & s[i+1] = t[j+1] then ( dp[i + 1+1][j + 1+1] := Set{dp[i + 1+1][j + 1+1], dp[i+1][j+1] + 2}->max() ) else skip ; ans := Set{ans, dp[i+1][j+1]}->max())) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- matrix=[] alt,larg=map(int,input().split()[: 2]) for i in range(0,alt): line=list(map(int,input().split()[: larg])) matrix.append(line) total_zeros_line=0 total_ones_line=0 total_zeros_col=0 total_ones_col=0 result=alt*larg for i in range(0,alt): zeros_line=0 ones_line=0 for j in range(0,larg): elem_linha=matrix[i][j] if(elem_linha==1): ones_line=ones_line+1 else : zeros_line=zeros_line+1 total_zeros_line=total_zeros_line+(int(2**(zeros_line)-zeros_line-1)) total_ones_line=total_ones_line+(int(2**(ones_line)-ones_line-1)) for i in range(0,larg): zeros_col=0 ones_col=0 for j in range(0,alt): elem_col=matrix[j][i] if(elem_col==1): ones_col=ones_col+1 else : zeros_col=zeros_col+1 total_zeros_col=total_zeros_col+(int(2**(zeros_col)-zeros_col-1)) total_ones_col=total_ones_col+(int(2**(ones_col)-ones_col-1)) result=result+total_ones_col+total_zeros_col+total_ones_line+total_zeros_line print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var matrix : Sequence := Sequence{} ; var alt : OclAny := null; var larg : OclAny := null; Sequence{alt,larg} := (input().split().subrange(1,2))->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, alt-1) do ( var line : Sequence := ((input().split().subrange(1,larg))->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((line) : matrix)) ; var total_zeros_line : int := 0 ; var total_ones_line : int := 0 ; var total_zeros_col : int := 0 ; var total_ones_col : int := 0 ; var result : double := alt * larg ; for i : Integer.subrange(0, alt-1) do ( var zeros_line : int := 0 ; var ones_line : int := 0 ; for j : Integer.subrange(0, larg-1) do ( var elem_linha : OclAny := matrix[i+1][j+1] ; if (elem_linha = 1) then ( ones_line := ones_line + 1 ) else ( zeros_line := zeros_line + 1 )) ; total_zeros_line := total_zeros_line + (("" + (((2)->pow((zeros_line)) - zeros_line - 1)))->toInteger()) ; total_ones_line := total_ones_line + (("" + (((2)->pow((ones_line)) - ones_line - 1)))->toInteger())) ; for i : Integer.subrange(0, larg-1) do ( var zeros_col : int := 0 ; var ones_col : int := 0 ; for j : Integer.subrange(0, alt-1) do ( var elem_col : OclAny := matrix[j+1][i+1] ; if (elem_col = 1) then ( ones_col := ones_col + 1 ) else ( zeros_col := zeros_col + 1 )) ; total_zeros_col := total_zeros_col + (("" + (((2)->pow((zeros_col)) - zeros_col - 1)))->toInteger()) ; total_ones_col := total_ones_col + (("" + (((2)->pow((ones_col)) - ones_col - 1)))->toInteger())) ; result := result + total_ones_col + total_zeros_col + total_ones_line + total_zeros_line ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=input().split(' ') n=int(n) m=int(m) total=n*m arr=[] for i in range(n): arr+=[input().split(' ')] if not(n==1 and m==1): for row in arr : zeros=0 ones=0 for col in row : if(col=='0'): zeros+=1 if(col=='1'): ones+=1 total+=(2**zeros)-1+(2**ones)-1-m for col in range(m): zeros=0 ones=0 for row in range(n): if(arr[row][col]=='0'): zeros+=1 if(arr[row][col]=='1'): ones+=1 total+=(2**zeros)-1+(2**ones)-1-n print(total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split(' ') ; var n : int := ("" + ((n)))->toInteger() ; var m : int := ("" + ((m)))->toInteger() ; var total : int := n * m ; var arr : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( arr := arr + Sequence{ input().split(' ') }) ; if not((n = 1 & m = 1)) then ( for row : arr do ( var zeros : int := 0 ; var ones : int := 0 ; for col : row do ( if (col = '0') then ( zeros := zeros + 1 ) else skip ; if (col = '1') then ( ones := ones + 1 ) else skip) ; total := total + ((2)->pow(zeros)) - 1 + ((2)->pow(ones)) - 1 - m) ; for col : Integer.subrange(0, m-1) do ( zeros := 0 ; ones := 0 ; for row : Integer.subrange(0, n-1) do ( if (arr[row+1][col+1] = '0') then ( zeros := zeros + 1 ) else skip ; if (arr[row+1][col+1] = '1') then ( ones := ones + 1 ) else skip) ; total := total + ((2)->pow(zeros)) - 1 + ((2)->pow(ones)) - 1 - n) ) else skip ; execute (total)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- maxin=100001 ; divisors=[0]*(maxin+1); def Calc_Max_Div(arr,n): vis=[1]*(maxin+1); vis[0]=vis[1]=0 ; for i in range(1,maxin+1): divisors[i]=i ; for i in range(4,maxin+1,2): vis[i]=0 ; divisors[i]=i//2 ; for i in range(3,maxin+1,2): if(divisors[i]!=i): divisors[i]=i//divisors[i]; if(vis[i]==1): for j in range(i*i,maxin,i): vis[j]=0 ; if(divisors[j]==j): divisors[j]=i ; for i in range(n): if(divisors[arr[i]]==arr[i]): print("-1 ",end=""); else : print(divisors[arr[i]],end=" "); if __name__=="__main__" : arr=[5,6,7,8,9,10]; n=len(arr); Calc_Max_Div(arr,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var maxin : int := 100001; ; var divisors : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (maxin + 1)); ; skip ; if __name__ = "__main__" then ( arr := Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{ 10 }))))); ; n := (arr)->size(); ; Calc_Max_Div(arr, n); ) else skip; operation Calc_Max_Div(arr : OclAny, n : OclAny) pre: true post: true activity: var vis : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (maxin + 1)); ; vis->first() := 0; var vis[1+1] : int := 0; ; for i : Integer.subrange(1, maxin + 1-1) do ( divisors[i+1] := i;) ; for i : Integer.subrange(4, maxin + 1-1)->select( $x | ($x - 4) mod 2 = 0 ) do ( vis[i+1] := 0; ; divisors[i+1] := i div 2;) ; for i : Integer.subrange(3, maxin + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if (divisors[i+1] /= i) then ( divisors[i+1] := i div divisors[i+1]; ) else skip ; if (vis[i+1] = 1) then ( for j : Integer.subrange(i * i, maxin-1)->select( $x | ($x - i * i) mod i = 0 ) do ( vis[j+1] := 0; ; if (divisors[j+1] = j) then ( divisors[j+1] := i; ) else skip) ) else skip) ; for i : Integer.subrange(0, n-1) do ( if (divisors[arr[i+1]+1] = arr[i+1]) then ( execute ("-1 ")->display(); ) else ( execute (divisors[arr[i+1]+1])->display(); )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as M size=input().split() n=int(size[0]) m=int(size[1]) matrix=[] for i in range(n): matrix.append(input().split()) def countColors(matrix,color,n,m): x=0 y=0 sets=0 for i in matrix : for j in i : if j==color : x+=1 if x>1 : sets+=2**x-1-x x=0 line=0 column=0 while column1 : sets+=2**y-1-y y=0 line=0 column+=1 return(int(sets)) print(countColors(matrix,'0',n,m)+countColors(matrix,'1',n,m)+n*m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var size : OclAny := input().split() ; var n : int := ("" + ((size->first())))->toInteger() ; var m : int := ("" + ((size[1+1])))->toInteger() ; var matrix : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((input().split()) : matrix)) ; skip ; execute (countColors(matrix, '0', n, m) + countColors(matrix, '1', n, m) + n * m)->display(); operation countColors(matrix : OclAny, color : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var x : int := 0 ; var y : int := 0 ; var sets : int := 0 ; for i : matrix do ( for j : i do ( if j = color then ( x := x + 1 ) else skip) ; if x > 1 then ( sets := sets + (2)->pow(x) - 1 - x ) else skip ; x := 0) ; var line : int := 0 ; var column : int := 0 ; while (column->compareTo(m)) < 0 do ( if matrix[line+1][column+1] = color then ( y := y + 1 ) else skip ; line := line + 1 ; if line = n then ( if y > 1 then ( sets := sets + (2)->pow(y) - 1 - y ) else skip ; y := 0 ; line := 0 ; column := column + 1 ) else skip) ; return (("" + ((sets)))->toInteger()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def isPrime(n): if n==1 : return False for i in range(2,int(sqrt(n))+1): if n % i==0 : return False return True def countDistinct(s): m={} m=m.fromkeys(s,0) for i in range(len(s)): m[s[i]]+=1 return len(m.keys()) if __name__=="__main__" : str="geeksforgeeks" if isPrime(countDistinct(str)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( var OclType["String"] : String := "geeksforgeeks" ; if isPrime(countDistinct(OclType["String"])) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isPrime(n : OclAny) : OclAny pre: true post: true activity: if n = 1 then ( return false ) else skip ; for i : Integer.subrange(2, ("" + ((sqrt(n))))->toInteger() + 1-1) do ( if n mod i = 0 then ( return false ) else skip) ; return true; operation countDistinct(s : OclAny) : OclAny pre: true post: true activity: var m : OclAny := Set{} ; m := m.fromkeys(s, 0) ; for i : Integer.subrange(0, (s)->size()-1) do ( m[s[i+1]+1] := m[s[i+1]+1] + 1) ; return (m.keys())->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSum(arr,n): result=0 count_odd=0 count_even=0 for i in range(n): if arr[i-1]% 2==0 : count_even=count_even+count_even+1 count_odd=count_odd+count_odd else : temp=count_even count_even=count_even+count_odd count_odd=count_odd+temp+1 return[count_even,count_odd] arr=[1,2,2,3] n=len(arr) ans=countSum(arr,n) print('EvenSum=',ans[0],'OddSum=',ans[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 3 }))) ; n := (arr)->size() ; var ans : OclAny := countSum(arr, n) ; execute ('EvenSum=')->display(); operation countSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; var count_odd : int := 0 ; var count_even : int := 0 ; for i : Integer.subrange(0, n-1) do ( if arr[i - 1+1] mod 2 = 0 then ( count_even := count_even + count_even + 1 ; count_odd := count_odd + count_odd ) else ( var temp : int := count_even ; count_even := count_even + count_odd ; count_odd := count_odd + temp + 1 )) ; return Sequence{count_even}->union(Sequence{ count_odd }); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() print(n+n[-1 : :-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; execute (n + n(subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() x=n[: :-1] ans=n+x print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var x : OclAny := n(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var ans : String := n + x ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): s=input() sre=s[: :-1] print(s+sre) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var sre : OclAny := s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; execute (s + sre)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() print(a+a[: :-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; execute (a + a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from heapq import heappush,heappop from bisect import bisect_left,bisect_right import sys,random,itertools,math sys.setrecursionlimit(10**5) input=sys.stdin.readline sqrt=math.sqrt def LI(): return list(map(int,input().split())) def LF(): return list(map(float,input().split())) def LI_(): return list(map(lambda x : int(x)-1,input().split())) def II(): return int(input()) def IF(): return float(input()) def S(): return input().rstrip() def LS(): return S().split() def IR(n): return[II()for _ in range(n)] def LIR(n): return[LI()for _ in range(n)] def FR(n): return[IF()for _ in range(n)] def LFR(n): return[LI()for _ in range(n)] def LIR_(n): return[LI_()for _ in range(n)] def SR(n): return[S()for _ in range(n)] def LSR(n): return[LS()for _ in range(n)] mod=1000000007 inf=float("INF") def solve(): n=II() ans=0 for i in range(1,n+1): x=n//i ans+=i*(1+x)*x//2 print(ans) return if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(5)) ; var input : OclAny := (OclFile["System.in"]).readline ; var sqrt : OclAny := ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : int := 1000000007 ; var Math_PINFINITY : double := ("" + (("INF")))->toReal() ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LF() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["double"])->apply(_x) )); operation LI_() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) )); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation IF() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return input().rstrip(); operation LS() : OclAny pre: true post: true activity: return S().split(); operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (II())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI())); operation FR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (IF())); operation LFR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI())); operation LIR_(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI_())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LS())); operation solve() pre: true post: true activity: n := II() ; var ans : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( var x : int := n div i ; ans := ans + i * (1 + x) * x div 2) ; execute (ans)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=input() b=input() res=0 dp=[[0 for i in range(m+1)]for j in range(n+1)] for i in range(n+1): for j in range(m+1): if i==0 or j==0 : dp[i][j]=0 elif a[i-1]==b[j-1]: dp[i][j]=max(0,dp[i-1][j-1]+2) else : dp[i][j]=max(dp[i-1][j]-1,dp[i][j-1]-1,0) res=max(dp[i][j],res) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var res : int := 0 ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, m + 1-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, n + 1-1) do ( for j : Integer.subrange(0, m + 1-1) do ( if i = 0 or j = 0 then ( dp[i+1][j+1] := 0 ) else (if a[i - 1+1] = b[j - 1+1] then ( dp[i+1][j+1] := Set{0, dp[i - 1+1][j - 1+1] + 2}->max() ) else ( dp[i+1][j+1] := Set{dp[i - 1+1][j+1] - 1, dp[i+1][j - 1+1] - 1, 0}->max() ) ) ; res := Set{dp[i+1][j+1], res}->max())) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- big_int=input() revesed_half='' print(big_int,end='') for i in range(len(big_int)-1,-1,-1): print(big_int[i],end='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var big_int : String := (OclFile["System.in"]).readLine() ; var revesed_half : String := '' ; execute (big_int)->display() ; for i : Integer.subrange(-1 + 1, (big_int)->size() - 1)->reverse() do ( execute (big_int[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) y=map(int,input().split()) a=sum(y) b=a/x c=round(b,12) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var y : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := (y)->sum() ; var b : double := a / x ; var c : double := MathLib.roundN(b, 12) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) print(sum(l)/n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((l)->sum() / n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys inp=input() freqs=[0]*26 for letter in inp : decimal=ord(letter)-ord('a') freqs[decimal]+=1 greater=-1 for i in reversed(range(len(freqs))): if(freqs[i]!=0): greater=i break char=chr(ord('a')+greater) llps=char*freqs[greater] print(llps) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var inp : String := (OclFile["System.in"]).readLine() ; var freqs : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for letter : inp->characters() do ( var decimal : double := (letter)->char2byte() - ('a')->char2byte() ; freqs[decimal+1] := freqs[decimal+1] + 1) ; var greater : int := -1 ; for i : (Integer.subrange(0, (freqs)->size()-1))->reverse() do ( if (freqs[i+1] /= 0) then ( greater := i ; break ) else skip) ; var char : String := (('a')->char2byte() + greater)->byte2char() ; var llps : String := StringLib.nCopies(char, freqs[greater+1]) ; execute (llps)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(sum(map(float,input().split()))/n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (((input().split())->collect( _x | (OclType["double"])->apply(_x) ))->sum() / n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- drinks=int(input()) percent=input().split() orange=0 for i in percent : orange+=int(i) print(orange/drinks) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var drinks : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var percent : OclAny := input().split() ; var orange : int := 0 ; for i : percent do ( orange := orange + ("" + ((i)))->toInteger()) ; execute (orange / drinks)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) ar1=list(map(int,input().split())) print(sum(ar1)/N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ar1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((ar1)->sum() / N)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def PointInKSquares(n,a,k): a.sort() return a[n-k] if __name__=="__main__" : k=2 a=[1,2,3,4] n=len(a) x=PointInKSquares(n,a,k) print("(",x,",",x,")") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( k := 2 ; a := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))) ; n := (a)->size() ; var x : OclAny := PointInKSquares(n, a, k) ; execute ("(")->display() ) else skip; operation PointInKSquares(n : OclAny, a : OclAny, k : OclAny) : OclAny pre: true post: true activity: a := a->sort() ; return a[n - k+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=list(map(int,input().split())) x=0 ans=0 for cnt,num in enumerate(p): if cnt+1==num : if x==0 : ans+=1 x=1 else : x=0 else : x=0 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : int := 0 ; var ans : int := 0 ; for _tuple : Integer.subrange(1, (p)->size())->collect( _indx | Sequence{_indx-1, (p)->at(_indx)} ) do (var _indx : int := 1; var cnt : OclAny := _tuple->at(_indx); _indx := _indx + 1; var num : OclAny := _tuple->at(_indx); if cnt + 1 = num then ( if x = 0 then ( ans := ans + 1 ; x := 1 ) else ( x := 0 ) ) else ( x := 0 )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,*p=map(int,open(0).read().split()) b=[p[i]==i+1 for i in range(n)] c=0 for i in range(1,n): if b[i-1]and b[i]: c+=1 b[i]=False b[i-1]=False print(c+sum(b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (p[i+1] = i + 1)) ; var c : int := 0 ; for i : Integer.subrange(1, n-1) do ( if b[i - 1+1] & b[i+1] then ( c := c + 1 ; b[i+1] := false ; b[i - 1+1] := false ) else skip) ; execute (c + (b)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) s=input() t=input() dp=[] for i in range(n+1): dp.append([]) for j in range(m+1): dp[-1].append(0) for i in range(n): for j in range(m): if s[i]==t[j]: dp[i+1][j+1]=dp[i][j]+2 else : dp[i+1][j+1]=max(0,max(dp[i][j+1]-1,dp[i+1][j]-1)) ans=0 for i in range(n+1): for j in range(m+1): ans=max(ans,dp[i][j]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var dp : Sequence := Sequence{} ; for i : Integer.subrange(0, n + 1-1) do ( execute ((Sequence{}) : dp) ; for j : Integer.subrange(0, m + 1-1) do ((expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if s[i+1] = t[j+1] then ( dp[i + 1+1][j + 1+1] := dp[i+1][j+1] + 2 ) else ( dp[i + 1+1][j + 1+1] := Set{0, Set{dp[i+1][j + 1+1] - 1, dp[i + 1+1][j+1] - 1}->max()}->max() ))) ; var ans : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( for j : Integer.subrange(0, m + 1-1) do ( ans := Set{ans, dp[i+1][j+1]}->max())) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def D_Derangement(N,p): count=0 i=0 while itoInteger() ; p := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute (D_Derangement(N, p))->display(); operation D_Derangement(N : OclAny, p : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var i : int := 0 ; while (i->compareTo(N)) < 0 do ( if p[i+1] = i + 1 then ( count := count + 1 ; i := i + 2 ) else ( i := i + 1 ; continue )) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda : sys.stdin.readline().rstrip() def resolve(): n=int(input()) P=list(map(lambda x : int(x)-1,input().split())) cnt=0 for i in range(n-1): if(P[i]==i and P[i+1]==i+1): cnt+=1 P[i],P[i+1]=P[i+1],P[i] print(cnt+sum(P[i]==i for i in range(n))) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(2147483647) ; var INF : double := ("" + (("inf")))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; skip ; resolve(); operation resolve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var P : Sequence := ((input->apply().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) )) ; var cnt : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if (P[i+1] = i & P[i + 1+1] = i + 1) then ( cnt := cnt + 1 ; var P[i+1] : OclAny := null; var P[i + 1+1] : OclAny := null; Sequence{P[i+1],P[i + 1+1]} := Sequence{P[i + 1+1],P[i+1]} ) else skip) ; execute (cnt + ((argument (test (logical_test (comparison (comparison (expr (atom (name P)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (name i))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) p=[x-1 for x in map(int,input().split())] cnt,flag=0,0 ans=0 for i in range(n): if p[i]==i and flag : cnt+=1 elif p[i]==i : cnt+=1 flag=1 elif p[i]!=i and flag : if cnt==1 : ans+=1 else : ans+=math.ceil(cnt/2) cnt,flag=0,0 if flag : if cnt==1 : ans+=1 else : ans+=math.ceil(cnt/2) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->select(x | true)->collect(x | (x - 1)) ; var cnt : OclAny := null; var flag : OclAny := null; Sequence{cnt,flag} := Sequence{0,0} ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if p[i+1] = i & flag then ( cnt := cnt + 1 ) else (if p[i+1] = i then ( cnt := cnt + 1 ; var flag : int := 1 ) else (if p[i+1] /= i & flag then ( if cnt = 1 then ( ans := ans + 1 ) else ( ans := ans + (cnt / 2)->ceil() ) ; var cnt : OclAny := null; Sequence{cnt,flag} := Sequence{0,0} ) else skip ) ) ) ; if flag then ( if cnt = 1 then ( ans := ans + 1 ) else ( ans := ans + (cnt / 2)->ceil() ) ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) A=list(map(int,input().split())) x=0 for a in A : x ^=a now=0 for i in range(59,-1,-1): if x>>i & 1 : continue for j in range(now,n): if A[j]>>i & 1 : A[now],A[j]=A[j],A[now] for k in range(n): if k!=now and A[k]>>i & 1 : A[k]^=A[now] now+=1 break b=0 for a in A : b ^=a ans=b+(x ^ b) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : int := 0 ; for a : A do ( x := x xor a) ; var now : int := 0 ; for i : Integer.subrange(-1 + 1, 59)->reverse() do ( if MathLib.bitwiseAnd(x /(2->pow(i)), 1) then ( continue ) else skip ; for j : Integer.subrange(now, n-1) do ( if MathLib.bitwiseAnd(A[j+1] /(2->pow(i)), 1) then ( var A[now+1] : OclAny := null; var A[j+1] : OclAny := null; Sequence{A[now+1],A[j+1]} := Sequence{A[j+1],A[now+1]} ; for k : Integer.subrange(0, n-1) do ( if k /= now & MathLib.bitwiseAnd(A[k+1] /(2->pow(i)), 1) then ( A[k+1] := A[k+1] xor A[now+1] ) else skip) ; now := now + 1 ; break ) else skip)) ; var b : int := 0 ; for a : A do ( b := b xor a) ; var ans : int := b + (MathLib.bitwiseXor(x, b)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() a=max(x) c=x.count(a) print(a*c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := (OclFile["System.in"]).readLine() ; var a : OclAny := (x)->max() ; var c : int := x->count(a) ; execute (a * c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from numpy import int64,bitwise_xor N,*A=map(int,open(0).read().split()) A=int64(A) x=bitwise_xor.reduce(A) A &=~ x res=0 while A.any(): ma=A.max() msb=1<<(int(ma).bit_length()-1) A[(A & msb)>0]^=ma res ^=ma*(not res & msb) print(x+2*res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var A : OclAny := null; Sequence{N,A} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : OclAny := int64(A) ; var x : OclAny := bitwise_xor.reduce(A) ; A := A & MathLib.bitwiseNot(x) ; var res : int := 0 ; while A.any() do ( var ma : double := A->max() ; var msb : int := 1 * (2->pow((OclType["int"](ma).bit_length() - 1))) ; A->select((MathLib.bitwiseAnd(A, msb)) > 0) := A->select((MathLib.bitwiseAnd(A, msb)) > 0) xor ma ; res := res xor ma * (not(MathLib.bitwiseAnd(res, msb)))) ; execute (x + 2 * res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import* N=int(input()) A=[int(a)for a in input().split()] x,t,s,i,h=0,0,0,59,[] for a in A : t ^=a for a in A : heappush(h,-(a & ~ t)) while h : a=-heappop(h) while i>=0 and(a>>i)& 1==0 : i-=1 x=0 if i<0 : break if x : heappush(h,-(a ^ x)) else : x=a s=max(s,s ^ x) print(s+(t ^ s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; var x : OclAny := null; var t : OclAny := null; var s : OclAny := null; var i : OclAny := null; var h : OclAny := null; Sequence{x,t,s,i,h} := Sequence{0,0,0,59,Sequence{}} ; for a : A do ( t := t xor a) ; for a : A do ( heappush(h, -(MathLib.bitwiseAnd(a, MathLib.bitwiseNot(t))))) ; while h do ( var a : OclAny := -heappop(h) ; while i >= 0 & MathLib.bitwiseAnd((a /(2->pow(i))), 1) = 0 do ( i := i - 1 ; var x : int := 0) ; if i < 0 then ( break ) else skip ; if x then ( heappush(h, -(MathLib.bitwiseXor(a, x))) ) else ( x := a ; var s : OclAny := Set{s, MathLib.bitwiseXor(s, x)}->max() )) ; execute (s + (MathLib.bitwiseXor(t, s)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np def solve(*args : str)->str : n=int(args[0]) A=np.array(args[1].split(),dtype=np.int64) n_bit=len(np.binary_repr(max(A))) xor=np.bitwise_xor.reduce(A) A &=~ xor for b in reversed(range(n_bit)): b_set=A & 1<display() ) else skip; operation solve(args : String : Sequence(OclAny)) : String pre: true post: true activity: (args * (named_parameter (name args) : (test (logical_test (comparison (expr (atom (name str)))))))) var n : int := ("" + ((args->first())))->toInteger() ; var A : Sequence := (args[1+1].split(), (argument (test (logical_test (comparison (expr (atom (name dtype)))))) = (test (logical_test (comparison (expr (atom (name np)) (trailer . (name int64)))))))) ; var n_bit : int := ()->size() ; var xor : OclAny := np.bitwise_xor.reduce(A) ; A := A & MathLib.bitwiseNot(xor) ; for b : (Integer.subrange(0, n_bit-1))->reverse() do ( var b_set : boolean := MathLib.bitwiseAnd(A, 1 * (2->pow(b))) /= 0 ; var msb_args : OclAny := np.where(MathLib.bitwiseAnd(b_set, ((A->compareTo(1 * (2->pow(b + 1)))) < 0)))->first() ; if (msb_args)->size() then ( b_set[msb_args->first()+1] := false ; A[b_set+1] := A[b_set+1] xor A[msb_args->first()+1] ) else skip) ; var ret : double := 2 * np.bitwise_xor.reduce(A) + xor ; return ("" + ((ret))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from collections import defaultdict sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod=10**9+7 def I(): return int(input()) def II(): return map(int,input().split()) def III(): return list(map(int,input().split())) def Line(N): read_all=[tuple(map(int,input().split()))for _ in range(N)] return map(list,zip(*read_all)) N=I() A=III() xor=0 for i in range(N): xor ^=A[i] for i in range(N): A[i]&=~ xor max_digit=len(format(max(A),'b')) rank=0 for col in range(max_digit)[: :-1]: pivot=-1 for row in range(rank,N): if A[row]>>col & 1 : pivot=row break if pivot==-1 : continue A[pivot],A[rank]=A[rank],A[pivot] for row in range(rank+1,N): if A[row]>>col & 1 : A[row]^=A[rank] rank+=1 val=0 for i in range(N): val=max(val,val ^ A[i]) print(2*val+xor) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; N := I() ; var A : OclAny := III() ; var xor : int := 0 ; for i : Integer.subrange(0, N-1) do ( xor := xor xor A[i+1]) ; for i : Integer.subrange(0, N-1) do ( A[i+1] := A[i+1] & MathLib.bitwiseNot(xor)) ; var max_digit : int := (((A)->max() + ""))->size() ; var rank : int := 0 ; for col : range(max_digit)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( var pivot : int := -1 ; for row : Integer.subrange(rank, N-1) do ( if MathLib.bitwiseAnd(A[row+1] /(2->pow(col)), 1) then ( pivot := row ; break ) else skip) ; if pivot = -1 then ( continue ) else skip ; var A[pivot+1] : OclAny := null; var A[rank+1] : OclAny := null; Sequence{A[pivot+1],A[rank+1]} := Sequence{A[rank+1],A[pivot+1]} ; for row : Integer.subrange(rank + 1, N-1) do ( if MathLib.bitwiseAnd(A[row+1] /(2->pow(col)), 1) then ( A[row+1] := A[row+1] xor A[rank+1] ) else skip) ; rank := rank + 1) ; var val : int := 0 ; for i : Integer.subrange(0, N-1) do ( val := Set{val, MathLib.bitwiseXor(val, A[i+1])}->max()) ; execute (2 * val + xor)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation II() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation III() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation Line(N : OclAny) : OclAny pre: true post: true activity: var read_all : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; return (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name read_all)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name read_all)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name read_all)))))))`third->at(_indx)} ))->collect( _x | (OclType["Sequence"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) graph=[[]for _ in range(n)] for i in range(m): a,b=map(int,input().split()) graph[a-1].append(b-1) graph[b-1].append(a-1) colors=[None]*n def bipartite(u,color): if not graph[u]: return True colors[u]=color stack=[[u,color]] while stack : u,color=stack.pop() for v in graph[u]: if colors[v]!=None and colors[v]==color : return False elif colors[v]!=None : continue colors[v]=1-color stack.append([v,1-color]) return True isBipartite=True for u in range(n): if colors[u]==None and not bipartite(u,0): isBipartite=False break if isBipartite==False : print('-1') else : a,b=[],[] for i in range(n): if colors[i]==1 : a.append(i+1) elif colors[i]==0 : b.append(i+1) print(len(a)) print(*a) print(len(b)) print(*b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var graph : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ))))) ; var colors : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; skip ; var isBipartite : boolean := true ; for u : Integer.subrange(0, n-1) do ( if colors[u+1] = null & not(bipartite(u, 0)) then ( isBipartite := false ; break ) else skip) ; if isBipartite = false then ( execute ('-1')->display() ) else ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{Sequence{},Sequence{}} ; for i : Integer.subrange(0, n-1) do ( if colors[i+1] = 1 then ( execute ((i + 1) : a) ) else (if colors[i+1] = 0 then ( execute ((i + 1) : b) ) else skip)) ; execute ((a)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display() ; execute ((b)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name b))))))))->display() ); operation bipartite(u : OclAny, color : OclAny) : OclAny pre: true post: true activity: if not(graph[u+1]) then ( return true ) else skip ; colors[u+1] := color ; var stack : Sequence := Sequence{ Sequence{u}->union(Sequence{ color }) } ; while stack do ( Sequence{u,color} := stack->last() ; stack := stack->front() ; for v : graph[u+1] do ( if colors[v+1] /= null & colors[v+1] = color then ( return false ) else (if colors[v+1] /= null then ( continue ) else skip) ; colors[v+1] := 1 - color ; execute ((Sequence{v}->union(Sequence{ 1 - color })) : stack))) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a,b=input(),input() dp,mx=[[0]*(m+1)for _ in range(n+1)],0 for i in range(1,n+1): for j in range(1,m+1): cc=max(0,max(dp[i][j-1]-1,dp[i-1][j]-1)) if a[i-1]==b[j-1]: cc=max(cc,max(2,dp[i-1][j-1]+2)) dp[i][j]=cc mx=max(mx,cc) print(mx) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine()} ; var dp : OclAny := null; var mx : OclAny := null; Sequence{dp,mx} := Sequence{Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (m + 1)))),0} ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, m + 1-1) do ( var cc : OclAny := Set{0, Set{dp[i+1][j - 1+1] - 1, dp[i - 1+1][j+1] - 1}->max()}->max() ; if a[i - 1+1] = b[j - 1+1] then ( cc := Set{cc, Set{2, dp[i - 1+1][j - 1+1] + 2}->max()}->max() ) else skip ; dp[i+1][j+1] := cc ; var mx : OclAny := Set{mx, cc}->max())) ; execute (mx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,threading from collections import defaultdict def main(): n,m=map(int,input().split()) graph=defaultdict(list) for _ in range(m): i,j=map(int,input().split()) graph[i].append(j) graph[j].append(i) set_A=set() set_B=set() def dfs(node,_set): if _set=='B' and node in set_A : return False elif _set=='A' and node in set_B : return False if node in set_A or node in set_B : return True if _set=='A' : set_A.add(node) elif _set=='B' : set_B.add(node) for ngh in graph[node]: if not dfs(ngh,'A' if _set=='B' else 'B'): return False return True can=True for i in range(1,n+1): if i not in set_A and i not in set_B and len(graph[i])>0 : if not dfs(i,'A'): can=False print(-1) break if can : print(len(set_A)) print(" ".join(list(map(str,set_A)))) print(len(set_B)) print(" ".join(list(map(str,set_B)))) threading.stack_size(1<<27) sys.setrecursionlimit(1<<30) main_thread=threading.Thread(target=main) main_thread.start() main_thread.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; threading.stack_size(1 * (2->pow(27))) ; sys.setrecursionlimit(1 * (2->pow(30))) ; var main_thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ; main_thread.start() ; main_thread.join(); operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var graph : OclAny := defaultdict(OclType["Sequence"]) ; for _anon : Integer.subrange(0, m-1) do ( var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var set_A : Set := Set{}->union(()) ; var set_B : Set := Set{}->union(()) ; skip ; var can : boolean := true ; for i : Integer.subrange(1, n + 1-1) do ( if (set_A)->excludes(i) & (set_B)->excludes(i) & (graph[i+1])->size() > 0 then ( if not(dfs(i, 'A')) then ( can := false ; execute (-1)->display() ; break ) else skip ) else skip) ; if can then ( execute ((set_A)->size())->display() ; execute (StringLib.sumStringsWithSeparator((((set_A)->collect( _x | (OclType["String"])->apply(_x) ))), " "))->display() ; execute ((set_B)->size())->display() ; execute (StringLib.sumStringsWithSeparator((((set_B)->collect( _x | (OclType["String"])->apply(_x) ))), " "))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import threading from functools import lru_cache from collections import defaultdict,deque def main(): n,m=[int(i)for i in input().split()] graph=defaultdict(set) for _ in range(m): u,v=[int(i)for i in input().split()] graph[u-1].add(v-1) graph[v-1].add(u-1) colors=defaultdict(lambda :-1) possible=True for i in graph : if not possible : break if colors[i]!=-1 : continue queue=deque([i]) colors[i]=0 while queue and possible : for _ in range(len(queue)): if not possible : break current=queue.popleft() color=colors[current] for neigh in graph[current]: if colors[neigh]==-1 : colors[neigh]=1-color queue.append(neigh) else : if colors[neigh]==color : possible=False break if not possible : print(-1) else : one=[] zero=[] for i,j in colors.items(): if j==0 : zero.append(i+1) else : one.append(i+1) print(len(one)) print(*one) print(len(zero)) print(*zero) if __name__=='__main__' : sys.setrecursionlimit(1<<30) threading.stack_size(1<<27) main_thread=threading.Thread(target=main) main_thread.start() main_thread.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( sys.setrecursionlimit(1 * (2->pow(30))) ; threading.stack_size(1 * (2->pow(27))) ; var main_thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ; main_thread.start() ; main_thread.join() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var graph : OclAny := defaultdict(OclType["Set"]) ; for _anon : Integer.subrange(0, m-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name u))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name u))) - (expr (atom (number (integer 1)))))))))) ))))) ; var colors : OclAny := defaultdict(lambda $$ : OclAny in (-1)) ; var possible : boolean := true ; for i : graph do ( if not(possible) then ( break ) else skip ; if colors[i+1] /= -1 then ( continue ) else skip ; var queue : Sequence := (Sequence{ i }) ; colors[i+1] := 0 ; while queue & possible do ( for _anon : Integer.subrange(0, (queue)->size()-1) do ( if not(possible) then ( break ) else skip ; var current : OclAny := queue->first() ; queue := queue->tail() ; var color : OclAny := colors[current+1] ; for neigh : graph[current+1] do ( if colors[neigh+1] = -1 then ( colors[neigh+1] := 1 - color ; execute ((neigh) : queue) ) else ( if colors[neigh+1] = color then ( possible := false ; break ) else skip ))))) ; if not(possible) then ( execute (-1)->display() ) else ( var one : Sequence := Sequence{} ; var zero : Sequence := Sequence{} ; for _tuple : colors->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if j = 0 then ( execute ((i + 1) : zero) ) else ( execute ((i + 1) : one) )) ; execute ((one)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name one))))))))->display() ; execute ((zero)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name zero))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque import sys import threading def main(): n,k=list(map(int,input().split())) graph=defaultdict(list) for _ in range(k): a,b=list(map(int,input().split())) a-=1 b-=1 graph[a].append(b) graph[b].append(a) def bipartite(colors): for i in range(n): if i not in colors and i in graph : colors[i]=0 stack=[i] while stack : cur=stack.pop() for nei in graph[cur]: if nei in colors : if colors[nei]==colors[cur]: return False else : colors[nei]=colors[cur]^ 1 stack.append(nei) return True colors={} if bipartite(colors): green=[] blue=[] for key in colors : if colors[key]==0 : green.append(key+1) else : blue.append(key+1) print(len(green)) print(*green) print(len(blue)) print(*blue) else : print("-1") if __name__=="__main__" : sys.setrecursionlimit(10**9) threading.stack_size(10**8) thread=threading.Thread(target=main) thread.start() thread.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( sys.setrecursionlimit((10)->pow(9)) ; threading.stack_size((10)->pow(8)) ; var thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ; thread.start() ; thread.join() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var graph : OclAny := defaultdict(OclType["Sequence"]) ; for _anon : Integer.subrange(0, k-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a - 1 ; b := b - 1 ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; skip ; colors := Set{} ; if bipartite(colors) then ( var green : Sequence := Sequence{} ; var blue : Sequence := Sequence{} ; for key : colors do ( if colors[key+1] = 0 then ( execute ((key + 1) : green) ) else ( execute ((key + 1) : blue) )) ; execute ((green)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name green))))))))->display() ; execute ((blue)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name blue))))))))->display() ) else ( execute ("-1")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,heapq from collections import defaultdict,deque import math input=sys.stdin.readline def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s=input() return(list(s[: len(s)-1])) def invr(): return(map(int,input().split())) def main(): n,e=invr() neigh=defaultdict(list) sets=defaultdict(set) for i in range(e): u,v=invr() neigh[u].append(v) neigh[v].append(u) sign=[None]*(n+1) visited=set() possible=True def bfs(node): nonlocal possible,visited,sign q=deque() q.append(node) visited.add(node) sign[node]=True sets[True].add(node) while q : node=q.popleft() for neighbor in neigh[node]: if neighbor not in visited : visited.add(neighbor) sign[neighbor]=not sign[node] sets[sign[neighbor]].add(neighbor) q.append(neighbor) elif neighbor in visited and sign[neighbor]==sign[node]: possible=False break for i in range(1,n+1): if i not in visited and neigh[i]: bfs(i) if not possible : print(-1) else : print(len(sets[True])) print(*sets[True]) print(len(sets[False])) print(*sets[False]) main() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute possible : OclAny; attribute visited : OclAny; attribute sign : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; skip ; main(); operation inp() : OclAny pre: true post: true activity: return (("" + (((OclFile["System.in"]).readLine())))->toInteger()); operation inlt() : OclAny pre: true post: true activity: return (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))); operation insr() : OclAny pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; return ((s.subrange(1,(s)->size() - 1))); operation invr() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation main() pre: true post: true activity: var n : OclAny := null; var e : OclAny := null; Sequence{n,e} := invr() ; var neigh : OclAny := defaultdict(OclType["Sequence"]) ; var sets : OclAny := defaultdict(OclType["Set"]) ; for i : Integer.subrange(0, e-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := invr() ; (expr (atom (name neigh)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) ; (expr (atom (name neigh)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)))))))) ))))) ; var sign : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (n + 1)) ; var visited : Set := Set{}->union(()) ; var possible : boolean := true ; skip ; for i : Integer.subrange(1, n + 1-1) do ( if (visited)->excludes(i) & neigh[i+1] then ( bfs(i) ) else skip) ; if not(possible) then ( execute (-1)->display() ) else ( execute ((sets->select(true))->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name sets)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name True)))))))) ]))))))))->display() ; execute ((sets->select(false))->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name sets)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name False)))))))) ]))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() a,b=input().split(' ') lst=["6","7","8","9","T","J","Q","K","A"] if a[1]==n and b[1]!=n : print("YES") elif a[1]==b[1]: i,j=0,0 for k in range(9): if a[0]==lst[k]: i=k if b[0]==lst[k]: j=k if i>j : print("YES") else : print("NO") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split(' ') ; var lst : Sequence := Sequence{"6"}->union(Sequence{"7"}->union(Sequence{"8"}->union(Sequence{"9"}->union(Sequence{"T"}->union(Sequence{"J"}->union(Sequence{"Q"}->union(Sequence{"K"}->union(Sequence{ "A" })))))))) ; if a[1+1] = n & b[1+1] /= n then ( execute ("YES")->display() ) else (if a[1+1] = b[1+1] then ( var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,0} ; for k : Integer.subrange(0, 9-1) do ( if a->first() = lst[k+1] then ( var i : OclAny := k ) else skip ; if b->first() = lst[k+1] then ( var j : OclAny := k ) else skip) ; if (i->compareTo(j)) > 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else ( execute ("NO")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() z=' ' for i in s : if ord(i)>ord(z): z=i print(z*s.count(z)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var z : String := ' ' ; for i : s->characters() do ( if ((i)->char2byte()->compareTo((z)->char2byte())) > 0 then ( z := i ) else skip) ; execute (StringLib.nCopies(z, s->count(z)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=input() w=input() w=w.split() a=w[0] b=w[1] c=0 d=0 if a[0]=='A' : c=14 if a[0]=='K' : c=13 if a[0]=='Q' : c=12 if a[0]=='J' : c=11 if a[0]=='T' : c=10 if b[0]=='A' : d=14 if b[0]=='K' : d=13 if b[0]=='Q' : d=12 if b[0]=='J' : d=11 if b[0]=='T' : d=10 if c==0 : c=int(a[0]) if d==0 : d=int(b[0]) if a[1]==k and b[1]!=k : print('YES') elif a[1]==b[1]and c-d>0 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : String := (OclFile["System.in"]).readLine() ; var w : String := (OclFile["System.in"]).readLine() ; w := w.split() ; var a : OclAny := w->first() ; var b : OclAny := w[1+1] ; var c : int := 0 ; var d : int := 0 ; if a->first() = 'A' then ( c := 14 ) else skip ; if a->first() = 'K' then ( c := 13 ) else skip ; if a->first() = 'Q' then ( c := 12 ) else skip ; if a->first() = 'J' then ( c := 11 ) else skip ; if a->first() = 'T' then ( c := 10 ) else skip ; if b->first() = 'A' then ( d := 14 ) else skip ; if b->first() = 'K' then ( d := 13 ) else skip ; if b->first() = 'Q' then ( d := 12 ) else skip ; if b->first() = 'J' then ( d := 11 ) else skip ; if b->first() = 'T' then ( d := 10 ) else skip ; if c = 0 then ( c := ("" + ((a->first())))->toInteger() ) else skip ; if d = 0 then ( d := ("" + ((b->first())))->toInteger() ) else skip ; if a[1+1] = k & b[1+1] /= k then ( execute ('YES')->display() ) else (if a[1+1] = b[1+1] & c - d > 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- slv={'6' : 0,'7' : 1,'8' : 2,'9' : 3,'T' : 4,'J' : 5,'Q' : 6,'K' : 7,'A' : 8} kozyr=input() card1,card2=input().split() val1=card1[0] mast1=card1[1] val2=card2[0] mast2=card2[1] if mast1==mast2 : if slv[val1]>slv[val2]: print('YES') else : print('NO') elif mast1==kozyr or mast2==kozyr : if mast1==kozyr : print('YES') else : print('NO') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var slv : Map := Map{ '6' |-> 0 }->union(Map{ '7' |-> 1 }->union(Map{ '8' |-> 2 }->union(Map{ '9' |-> 3 }->union(Map{ 'T' |-> 4 }->union(Map{ 'J' |-> 5 }->union(Map{ 'Q' |-> 6 }->union(Map{ 'K' |-> 7 }->union(Map{ 'A' |-> 8 })))))))) ; var kozyr : String := (OclFile["System.in"]).readLine() ; var card1 : OclAny := null; var card2 : OclAny := null; Sequence{card1,card2} := input().split() ; var val1 : OclAny := card1->first() ; var mast1 : OclAny := card1[1+1] ; var val2 : OclAny := card2->first() ; var mast2 : OclAny := card2[1+1] ; if mast1 = mast2 then ( if (slv[val1+1]->compareTo(slv[val2+1])) > 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) else (if mast1 = kozyr or mast2 = kozyr then ( if mast1 = kozyr then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) else ( execute ('NO')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- suit=["S","H","D","C"] rank=["6","7","8","9","T","J","Q","K","A"] s=input() l=[str(x)for x in input().split()] l1=list(l[0]) l2=list(l[1]) if l1[1]==l2[1]and rank.index(l1[0])>rank.index(l2[0]): print('YES') elif(l1[1]in suit and l1[1]==s and l1[1]!=l2[1]): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var suit : Sequence := Sequence{"S"}->union(Sequence{"H"}->union(Sequence{"D"}->union(Sequence{ "C" }))) ; var rank : Sequence := Sequence{"6"}->union(Sequence{"7"}->union(Sequence{"8"}->union(Sequence{"9"}->union(Sequence{"T"}->union(Sequence{"J"}->union(Sequence{"Q"}->union(Sequence{"K"}->union(Sequence{ "A" })))))))) ; var s : String := (OclFile["System.in"]).readLine() ; var l : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x))))) ; var l1 : Sequence := (l->first()) ; var l2 : Sequence := (l[1+1]) ; if l1[1+1] = l2[1+1] & (rank->indexOf(l1->first()) - 1->compareTo(rank->indexOf(l2->first()) - 1)) > 0 then ( execute ('YES')->display() ) else (if ((suit)->includes(l1[1+1]) & l1[1+1] = s & l1[1+1] /= l2[1+1]) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys s=input() a,b=map(str,input().split()) arr=["6","7","8","9","T","J","Q","K","A"] brr=["S","H","D","C"] if(s==a[1]): if(a[1]!=b[1]): print("YES") else : if(arr.index(a[0])>arr.index(b[0])): print("YES") else : print("NO") elif(a[1]==b[1]): if(arr.index(a[0])>arr.index(b[0])): print("YES") else : print("NO") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var s : String := (OclFile["System.in"]).readLine() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; var arr : Sequence := Sequence{"6"}->union(Sequence{"7"}->union(Sequence{"8"}->union(Sequence{"9"}->union(Sequence{"T"}->union(Sequence{"J"}->union(Sequence{"Q"}->union(Sequence{"K"}->union(Sequence{ "A" })))))))) ; var brr : Sequence := Sequence{"S"}->union(Sequence{"H"}->union(Sequence{"D"}->union(Sequence{ "C" }))) ; if (s = a[1+1]) then ( if (a[1+1] /= b[1+1]) then ( execute ("YES")->display() ) else ( if ((arr->indexOf(a->first()) - 1->compareTo(arr->indexOf(b->first()) - 1)) > 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) ) else (if (a[1+1] = b[1+1]) then ( if ((arr->indexOf(a->first()) - 1->compareTo(arr->indexOf(b->first()) - 1)) > 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else ( execute ("NO")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools def det_rect_area(n,k,points): area=float("inf") xs=(p[0]for p in points) ys=(p[1]for p in points) all_points=itertools.product(xs,ys) for(x1,y1),(x2,y2)in itertools.combinations(all_points,2): min_x,max_x=min(x1,x2),max(x1,x2) min_y,max_y=min(y1,y2),max(y1,y2) num_inc_rects=0 for x,y in points : if min_x<=x<=max_x and min_y<=y<=max_y : num_inc_rects+=1 if num_inc_rects>=k : area=min(area,(max_x-min_x)*(max_y-min_y)) return area def main(): n,k=(int(x)for x in input().split()) points=[tuple(int(x)for x in input().split())for _ in range(n)] print(det_rect_area(n,k,points)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation det_rect_area(n : OclAny, k : OclAny, points : OclAny) : OclAny pre: true post: true activity: var area : double := ("" + (("inf")))->toReal() ; var xs : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))) (comp_for for (exprlist (expr (atom (name p)))) in (logical_test (comparison (expr (atom (name points)))))))} ; var ys : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))) (comp_for for (exprlist (expr (atom (name p)))) in (logical_test (comparison (expr (atom (name points)))))))} ; var all_points : OclAny := itertools.product(xs, ys) ; for _tuple : itertools.combinations(all_points, 2) do (var _indx : int := 1; var Sequence{x1, y1} : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{x2, y2} : OclAny := _tuple->at(_indx); var min_x : OclAny := null; var max_x : OclAny := null; Sequence{min_x,max_x} := Sequence{Set{x1, x2}->min(),Set{x1, x2}->max()} ; var min_y : OclAny := null; var max_y : OclAny := null; Sequence{min_y,max_y} := Sequence{Set{y1, y2}->min(),Set{y1, y2}->max()} ; var num_inc_rects : int := 0 ; for _tuple : points do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if (min_x->compareTo(x)) <= 0 & (x <= max_x) & (min_y->compareTo(y)) <= 0 & (y <= max_y) then ( num_inc_rects := num_inc_rects + 1 ) else skip) ; if (num_inc_rects->compareTo(k)) >= 0 then ( area := Set{area, (max_x - min_x) * (max_y - min_y)}->min() ) else skip) ; return area; operation main() pre: true post: true activity: Sequence{n,k} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; points := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))))) ; execute (det_rect_area(n, k, points))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSubArrays(arr,n): hashMap={} out=[] sum1=0 for i in range(n): sum1+=arr[i] if sum1==0 : out.append((0,i)) al=[] if sum1 in hashMap : al=hashMap.get(sum1) for it in range(len(al)): out.append((al[it]+1,i)) al.append(i) hashMap[sum1]=al return out def printOutput(output): for i in output : print("Subarray found from Index "+str(i[0])+" to "+str(i[1])) if __name__=='__main__' : arr=[6,3,-1,-3,4,-2,2,4,6,-12,-7] n=len(arr) out=findSubArrays(arr,n) if(len(out)==0): print("No subarray exists") else : printOutput(out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{6}->union(Sequence{3}->union(Sequence{-1}->union(Sequence{-3}->union(Sequence{4}->union(Sequence{-2}->union(Sequence{2}->union(Sequence{4}->union(Sequence{6}->union(Sequence{-12}->union(Sequence{ -7 })))))))))) ; n := (arr)->size() ; out := findSubArrays(arr, n) ; if ((out)->size() = 0) then ( execute ("No subarray exists")->display() ) else ( printOutput(out) ) ) else skip; operation findSubArrays(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var hashMap : OclAny := Set{} ; var out : Sequence := Sequence{} ; var sum1 : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum1 := sum1 + arr[i+1] ; if sum1 = 0 then ( execute ((Sequence{0, i}) : out) ) else skip ; var al : Sequence := Sequence{} ; if (hashMap)->includes(sum1) then ( al := hashMap.get(sum1) ; for it : Integer.subrange(0, (al)->size()-1) do ( execute ((Sequence{al[it+1] + 1, i}) : out)) ) else skip ; execute ((i) : al) ; hashMap[sum1+1] := al) ; return out; operation printOutput(output : OclAny) pre: true post: true activity: for i : output do ( execute ("Subarray found from Index " + ("" + ((i->first()))) + " to " + ("" + ((i[1+1]))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def productPrimeFactors(n): product=1 for i in range(2,n+1): if(n % i==0): isPrime=1 for j in range(2,int(i/2+1)): if(i % j==0): isPrime=0 break if(isPrime): product=product*i return product n=44 print(productPrimeFactors(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 44 ; execute (productPrimeFactors(n))->display(); operation productPrimeFactors(n : OclAny) : OclAny pre: true post: true activity: var product : int := 1 ; for i : Integer.subrange(2, n + 1-1) do ( if (n mod i = 0) then ( var isPrime : int := 1 ; for j : Integer.subrange(2, ("" + ((i / 2 + 1)))->toInteger()-1) do ( if (i mod j = 0) then ( isPrime := 0 ; break ) else skip) ; if (isPrime) then ( product := product * i ) else skip ) else skip) ; return product; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countNonDecreasing(n): dp=[[0 for i in range(n+1)]for i in range(10)] for i in range(10): dp[i][1]=1 for digit in range(10): for len in range(2,n+1): for x in range(digit+1): dp[digit][len]+=dp[x][len-1] count=0 for i in range(10): count+=dp[i][n] return count n=3 print(countNonDecreasing(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3 ; execute (countNonDecreasing(n))->display(); operation countNonDecreasing(n : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, 10-1)->select(i | true)->collect(i | (Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, 10-1) do ( dp[i+1][1+1] := 1) ; for digit : Integer.subrange(0, 10-1) do ( for len : Integer.subrange(2, n + 1-1) do ( for x : Integer.subrange(0, digit + 1-1) do ( dp[digit+1][len+1] := dp[digit+1][len+1] + dp[x+1][len - 1+1]))) ; var count : int := 0 ; for i : Integer.subrange(0, 10-1) do ( count := count + dp[i+1][n+1]) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque N=int(input()) G=dict() for i in range(N): G[i+1]=[] for _ in range(N-1): a,b=map(int,input().split()) G[a].append(b) G[b].append(a) dist_1=[N]*(N+1) dist_1[1]=0 que=deque([1]) while len(que)>0 : a=que.popleft() for b in G[a]: if dist_1[b]>dist_1[a]+1 : dist_1[b]=dist_1[a]+1 que.append(b) dist_N=[N]*(N+1) dist_N[N]=0 que=deque([N]) while len(que)>0 : a=que.popleft() for b in G[a]: if dist_N[b]>dist_N[a]+1 : dist_N[b]=dist_N[a]+1 que.append(b) count_Fennec=0 for i in range(N): if dist_1[i+1]<=dist_N[i+1]: count_Fennec+=1 if count_Fennec>N-count_Fennec : print('Fennec') else : print('Snuke') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var G : Map := (arguments ( )) ; for i : Integer.subrange(0, N-1) do ( G[i + 1+1] := Sequence{}) ; for _anon : Integer.subrange(0, N - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var dist skip : Sequence := MatrixLib.elementwiseMult(Sequence{ N }, (N + 1)) ; dist skip[1+1] := 0 ; var que : Sequence := (Sequence{ 1 }) ; while (que)->size() > 0 do ( var a : OclAny := que->first() ; que := que->tail() ; for b : G[a+1] do ( if (dist var a : OclAny := que->first() ; que := que->tail()[b+1]->compareTo(dist var a : OclAny := que->first() ; que := que->tail()[a+1] + 1)) > 0 then ( dist var a : OclAny := que->first() ; que := que->tail()[b+1] := dist var a : OclAny := que->first() ; que := que->tail()[a+1] + 1 ; execute ((b) : que) ) else skip)) ; var dist_N : Sequence := MatrixLib.elementwiseMult(Sequence{ N }, (N + 1)) ; dist_N[N+1] := 0 ; que := (Sequence{ N }) ; while (que)->size() > 0 do ( a := que->first() ; que := que->tail() ; for b : G[a+1] do ( if (dist_N[b+1]->compareTo(dist_N[a+1] + 1)) > 0 then ( dist_N[b+1] := dist_N[a+1] + 1 ; execute ((b) : que) ) else skip)) ; var count_Fennec : int := 0 ; for i : Integer.subrange(0, N-1) do ( if (dist skip[i + 1+1]->compareTo(dist_N[i + 1+1])) <= 0 then ( count_Fennec := count_Fennec + 1 ) else skip) ; if (count_Fennec->compareTo(N - count_Fennec)) > 0 then ( execute ('Fennec')->display() ) else ( execute ('Snuke')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from networkx import* (N,),*t=[s.split()for s in open(0)] G=Graph() for a,b in t : G.add_edge(a,b) s=shortest_path_length x=s(G,'1') y=s(G,N) c=0 for k in y : c+=x[k]>y[k] print('FSennunkeec'[c*2>=int(N): : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name N)))))) ,)} : OclAny := null; var t : OclAny := null; Sequence{Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name N)))))) ,)},t} := OclFile.newOclFile_Write(OclFile.newOclFile(0))->select(s | true)->collect(s | (s.split())) ; var G : OclAny := Graph() ; for _tuple : t do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); G.add_edge(a, b)) ; var s : OclAny := shortest_path_length ; var x : OclAny := s(G, '1') ; var y : OclAny := s(G, N) ; var c : int := 0 ; for k : y do ( c := c + (x[k+1]->compareTo(y[k+1])) > 0) ; execute ('FSennunkeec'(subscript (test (logical_test (comparison (comparison (expr (expr (atom (name c))) * (expr (atom (number (integer 2)))))) >= (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) class Node : def __init__(self,num): self.num=num self.v=1 self.parent=0 self.deep=None def LI(): return list(map(int,input().split())) N=int(input()) AB=[LI()for _ in range(N-1)] link=[[]for _ in range(N+1)] for a,b in AB : link[a].append(b) link[b].append(a) nodes=[Node(i)for i in range(N+1)] def create_tree(parent): for child in link[parent.num]: if child==parent.parent : continue node=nodes[child] node.parent=parent.num node.deep=parent.deep+1 create_tree(node) parent.v+=node.v def main(): nodes[1].deep=1 create_tree(nodes[1]) x=(nodes[N].deep-nodes[1].deep-1)//2 v=nodes[N] for _ in range(x): v=nodes[v.parent] snuke=v.v fennec=N-snuke ans="Fennec" if fennec>snuke else "Snuke" print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute num : OclAny := num; attribute v : int := 1; attribute parent : int := 0; attribute deep : OclAny := null; operation initialise(num : OclAny) : Node pre: true post: true activity: self.num := num ; self.v := 1 ; self.parent := 0 ; self.deep := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var AB : Sequence := Integer.subrange(0, N - 1-1)->select(_anon | true)->collect(_anon | (LI())) ; var link : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _tuple : AB do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); (expr (atom (name link)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name link)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var nodes : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | ((Node.newNode()).initialise(i))) ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation create_tree(parent : OclAny) pre: true post: true activity: for child : link[parent.num+1] do ( if child = parent.parent then ( continue ) else skip ; var node : OclAny := nodes[child+1] ; node.parent := parent.num ; node.deep := parent.deep + 1 ; create_tree(node) ; parent.v := parent.v + node.v); operation main() pre: true post: true activity: nodes[1+1].deep := 1 ; create_tree(nodes[1+1]) ; var x : int := (nodes[N+1].deep - nodes[1+1].deep - 1) div 2 ; var v : OclAny := nodes[N+1] ; for _anon : Integer.subrange(0, x-1) do ( v := nodes[v.parent+1]) ; var snuke : OclAny := v.v ; var fennec : double := N - snuke ; var ans : String := if (fennec->compareTo(snuke)) > 0 then "Fennec" else "Snuke" endif ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() m=max(s) for i in range(len(s)): if m==s[i]: print(s[i],end='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var m : OclAny := (s)->max() ; for i : Integer.subrange(0, (s)->size()-1) do ( if m = s[i+1] then ( execute (s[i+1])->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from scipy.sparse import*; f=lambda*z : map(int,raw_input().split()); n,=f(); a,b=zip(*map(f,[0]*~-n)); g,h=csgraph.dijkstra(csr_matrix(([1]*~-n,(a,b)),[n+1]*2),0,[1,n]); print['Snuke','Fennec'][sum(g[i]>h[i]for i in range(n+1))*2collect( _x | (OclType["int"])->apply(_x) ));(testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,)} := f->apply(); var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name f))))))) , (argument (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr ~ (expr - (expr (atom (name n))))))))))) ))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name f))))))) , (argument (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr ~ (expr - (expr (atom (name n))))))))))) ))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name f))))))) , (argument (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr ~ (expr - (expr (atom (name n))))))))))) ))))))))`third->at(_indx)} ); var g : OclAny := null; var h : OclAny := null; Sequence{g,h} := csgraph.dijkstra(csr_matrix(Sequence{MatrixLib.elementwiseMult(Sequence{ 1 }, MathLib.bitwiseNot(-n)), Sequence{a, b}}, MatrixLib.elementwiseMult(Sequence{ n + 1 }, 2)), 0, Sequence{1}->union(Sequence{ n }));(expr (atom print) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'Snuke')))))) , (subscript (test (logical_test (comparison (expr (atom 'Fennec'))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (comparison (expr (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) > (comparison (expr (atom (name h)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) ))))))))) )))) * (expr (atom (number (integer 2)))))) < (comparison (expr (atom (name n))))))))) ]))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bfs(graph,start,n,check): if check==False : arrival=[0 for i in range(n+1)] else : arrival=[0 for i in range(n+1)] arrival[check]=-1 q=[start] arrival[start]=1 while len(q)!=0 : for i in range(len(graph[q[0]])): if arrival[graph[q[0]][i]]==0 : q.append(graph[q[0]][i]) arrival[graph[q[0]][i]]=arrival[q[0]]+1 q.pop(0) return arrival n=int(input()) graph=dict() for i in range(1,n+1): graph[i]=[] for i in range(n-1): a,b=map(int,input().split()) graph[a].append(b) graph[b].append(a) fstart=bfs(graph,1,n,False) sstart=bfs(graph,n,n,False) fennec=0 snuke=0 for i in range(1,n+1): if abs(fstart[i]-fstart[1])<=abs(sstart[i]-sstart[n]): fennec+=1 else : snuke+=1 if fennec>snuke : print("Fennec") else : print("Snuke") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; graph := (arguments ( )) ; for i : Integer.subrange(1, n + 1-1) do ( graph[i+1] := Sequence{}) ; for i : Integer.subrange(0, n - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var fstart : OclAny := bfs(graph, 1, n, false) ; var sstart : OclAny := bfs(graph, n, n, false) ; var fennec : int := 0 ; var snuke : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( if ((fstart[i+1] - fstart[1+1])->abs()->compareTo((sstart[i+1] - sstart[n+1])->abs())) <= 0 then ( fennec := fennec + 1 ) else ( snuke := snuke + 1 )) ; if (fennec->compareTo(snuke)) > 0 then ( execute ("Fennec")->display() ) else ( execute ("Snuke")->display() ); operation bfs(graph : OclAny, start : OclAny, n : OclAny, check : OclAny) : OclAny pre: true post: true activity: if check = false then ( var arrival : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ) else ( arrival := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; arrival[check+1] := -1 ) ; var q : Sequence := Sequence{ start } ; arrival[start+1] := 1 ; while (q)->size() /= 0 do ( for i : Integer.subrange(0, (graph[q->first()+1])->size()-1) do ( if arrival[graph[q->first()+1][i+1]+1] = 0 then ( execute ((graph[q->first()+1][i+1]) : q) ; arrival[graph[q->first()+1][i+1]+1] := arrival[q->first()+1] + 1 ) else skip) ; q := q->excludingAt(0+1)) ; return arrival; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=100010 ID=[0 for i in range(N)] sz=[0 for i in range(N)] def Root(idx): i=idx while i!=ID[i]: ID[i],i=ID[ID[i]],ID[i] return i def Union(a,b): i,j=Root(a),Root(b) if i!=j : if sz[i]>=sz[j]: ID[j]=i sz[i]+=sz[j] sz[j]=0 else : ID[i]=j sz[j]+=sz[i] sz[i]=0 def minChange(n,a,b): for i in range(N): ID[i]=i sz[i]=1 for i in range(n): if Root(a[i])!=Root(b[i]): Union(a[i],b[i]) ans=0 for i in range(n): if ID[i]==i : ans+=(sz[i]-1) return ans a=[2,1,1,3,5] b=[1,2,2,4,5] n=len(a) print(minChange(n,a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 100010 ; var ID : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; var sz : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; skip ; skip ; skip ; a := Sequence{2}->union(Sequence{1}->union(Sequence{1}->union(Sequence{3}->union(Sequence{ 5 })))) ; b := Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 5 })))) ; n := (a)->size() ; execute (minChange(n, a, b))->display(); operation Root(idx : OclAny) : OclAny pre: true post: true activity: var i : OclAny := idx ; while i /= ID[i+1] do ( var ID[i+1] : OclAny := null; Sequence{ID[i+1],i} := Sequence{ID[ID[i+1]+1],ID[i+1]}) ; return i; operation Union(a : OclAny, b : OclAny) pre: true post: true activity: var j : OclAny := null; Sequence{i,j} := Sequence{Root(a),Root(b)} ; if i /= j then ( if (sz[i+1]->compareTo(sz[j+1])) >= 0 then ( ID[j+1] := i ; sz[i+1] := sz[i+1] + sz[j+1] ; sz[j+1] := 0 ) else ( ID[i+1] := j ; sz[j+1] := sz[j+1] + sz[i+1] ; sz[i+1] := 0 ) ) else skip; operation minChange(n : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, N-1) do ( ID[i+1] := i ; sz[i+1] := 1) ; for i : Integer.subrange(0, n-1) do ( if Root(a[i+1]) /= Root(b[i+1]) then ( Union(a[i+1], b[i+1]) ) else skip) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ID[i+1] = i then ( ans := ans + (sz[i+1] - 1) ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,m=map(int,input().split()) s=input() t=input() dp=[[0]*(m+1)for _ in range(n+1)] ans=0 for i in range(n+1): for j in range(m+1): if icollect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (m + 1)))) ; var ans : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( for j : Integer.subrange(0, m + 1-1) do ( if (i->compareTo(n)) < 0 then ( dp[i + 1+1][j+1] := Set{dp[i + 1+1][j+1], dp[i+1][j+1] - 1}->max() ) else skip ; if (j->compareTo(m)) < 0 then ( dp[i+1][j + 1+1] := Set{dp[i+1][j + 1+1], dp[i+1][j+1] - 1}->max() ) else skip ; if (i->compareTo(n)) < 0 & (j->compareTo(m)) < 0 & s[i+1] = t[j+1] then ( dp[i + 1+1][j + 1+1] := Set{dp[i + 1+1][j + 1+1], dp[i+1][j+1] + 2}->max() ) else skip ; ans := Set{ans, dp[i+1][j+1]}->max())) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque,Counter from math import* import sys import random from bisect import* from functools import reduce from sys import stdin from heapq import* import copy input=lambda : sys.stdin.readline().rstrip() for _ in range(int(input())): n,k=(map(int,input().split())) mountain=[0]+list(map(int,input().split())) prefix=[0 for i in range(n+1)] for i in range(2,n): if mountain[i-1]mountain[i+1]: prefix[i]=prefix[i-1]+1 else : prefix[i]=prefix[i-1] ans=[] pos=1 cnt=0 for i in range(1,n-k+2): if(prefix[i+k-2]-prefix[i])>cnt : cnt=(prefix[i+k-2]-prefix[i]) pos=i print(cnt+1,pos) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mountain : Sequence := Sequence{ 0 }->union(((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var prefix : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(2, n-1) do ( if (mountain[i - 1+1]->compareTo(mountain[i+1])) < 0 & (mountain[i+1] > mountain[i + 1+1]) then ( prefix[i+1] := prefix[i - 1+1] + 1 ) else ( prefix[i+1] := prefix[i - 1+1] )) ; var ans : Sequence := Sequence{} ; var pos : int := 1 ; var cnt : int := 0 ; for i : Integer.subrange(1, n - k + 2-1) do ( if ((prefix[i + k - 2+1] - prefix[i+1])->compareTo(cnt)) > 0 then ( cnt := (prefix[i + k - 2+1] - prefix[i+1]) ; pos := i ) else skip) ; execute (cnt + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t=int(input()) ans=[] for _ in range(t): n,k=map(int,input().split()) a=list(map(int,input().split())) b=[0,0] for i in range(1,n-1): if a[i-1]a[i+1]: b.append(b[-1]+1) else : b.append(b[-1]) ma,l=0,0 for i in range(n-k+1): x=b[i+k-1]-b[i+1]+1 if matoInteger() ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := Sequence{0}->union(Sequence{ 0 }) ; for i : Integer.subrange(1, n - 1-1) do ( if (a[i - 1+1]->compareTo(a[i+1])) < 0 & (a[i+1] > a[i + 1+1]) then ( execute ((b->last() + 1) : b) ) else ( execute ((b->last()) : b) )) ; var ma : OclAny := null; var l : OclAny := null; Sequence{ma,l} := Sequence{0,0} ; for i : Integer.subrange(0, n - k + 1-1) do ( var x : double := b[i + k - 1+1] - b[i + 1+1] + 1 ; if (ma->compareTo(x)) < 0 then ( var ma : OclAny := null; var l : OclAny := null; Sequence{ma,l} := Sequence{x,i + 1} ) else skip) ; execute ((StringLib.sumStringsWithSeparator(((Sequence{ma, l})->collect( _x | (OclType["String"])->apply(_x) )), " ")) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n,k=map(int,input().split()) w=list(map(int,input().split())) d=[0]*n for i in range(1,n-1): if w[i-1]w[i+1]: d[i]=1 c=d[: k-2].count(1) c1=c x=1 for i in range(n-k+2): if d[i+k-2]==1 : c+=1 if d[i]==1 : c-=1 if c>c1 : c1=c x=i+1 print(c1+1,x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(1, n - 1-1) do ( if (w[i - 1+1]->compareTo(w[i+1])) < 0 & (w[i+1] > w[i + 1+1]) then ( d[i+1] := 1 ) else skip) ; var c : OclAny := d.subrange(1,k - 2)->count(1) ; var c1 : OclAny := c ; var x : int := 1 ; for i : Integer.subrange(0, n - k + 2-1) do ( if d[i + k - 2+1] = 1 then ( c := c + 1 ) else skip ; if d[i+1] = 1 then ( c := c - 1 ) else skip ; if (c->compareTo(c1)) > 0 then ( c1 := c ; x := i + 1 ) else skip) ; execute (c1 + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in[0]*int(input()): n,k=map(int,input().split()) *a,=map(int,input().split()) peaks=len([i for i in range(1,k-1)if a[i-1]a[i+1]]) l=0 ; maxi=peaks for i in range(1,n-k+1): peaks+=((a[i+k-3]a[i+k-1])-(a[i-1]a[i+1])) if maxitoInteger()) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (testlist_star_expr (star_expr * (expr (atom (name a)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name a)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) a=list(map(int,input().split())) b=[0]*n for i in range(1,n-1): if(a[i]>a[i-1]and a[i]>a[i+1]): b[i]=1 j=k i=0 s=sum(b[i+1 : j-1]) maxp=s mini=1 while(jmaxp): maxp=s mini=i+1 print(maxp+1,mini) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(1, n - 1-1) do ( if ((a[i+1]->compareTo(a[i - 1+1])) > 0 & (a[i+1]->compareTo(a[i + 1+1])) > 0) then ( b[i+1] := 1 ) else skip) ; var j : OclAny := k ; var i : int := 0 ; var s : OclAny := (b.subrange(i + 1+1, j - 1))->sum() ; var maxp : OclAny := s ; var mini : int := 1 ; while ((j->compareTo(n)) < 0) do ( s := s - b[i + 1+1] ; i := i + 1 ; s := s + b[j - 1+1] ; j := j + 1 ; if ((s->compareTo(maxp)) > 0) then ( maxp := s ; mini := i + 1 ) else skip) ; execute (maxp + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def LISusingLCS(seq): n=len(seq) L=[[0 for i in range(n+1)]for i in range(n+1)] sortedseq=sorted(seq) for i in range(n+1): for j in range(n+1): if(i==0 or j==0): L[i][j]=0 elif(seq[i-1]==sortedseq[j-1]): L[i][j]=L[i-1][j-1]+1 else : L[i][j]=max(L[i-1][j],L[i][j-1]) return L[n][n] sequence=[12,34,1,5,40,80] print(LISusingLCS(sequence)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var sequence : Sequence := Sequence{12}->union(Sequence{34}->union(Sequence{1}->union(Sequence{5}->union(Sequence{40}->union(Sequence{ 80 }))))) ; execute (LISusingLCS(sequence))->display(); operation LISusingLCS(seq : OclAny) : OclAny pre: true post: true activity: var n : int := (seq)->size() ; var L : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)))) ; var sortedseq : Sequence := seq->sort() ; for i : Integer.subrange(0, n + 1-1) do ( for j : Integer.subrange(0, n + 1-1) do ( if (i = 0 or j = 0) then ( L[i+1][j+1] := 0 ) else (if (seq[i - 1+1] = sortedseq[j - 1+1]) then ( L[i+1][j+1] := L[i - 1+1][j - 1+1] + 1 ) else ( L[i+1][j+1] := Set{L[i - 1+1][j+1], L[i+1][j - 1+1]}->max() ) ) )) ; return L[n+1][n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=50 def solveQuery(n,q,qi,qj): arr=[None]*MAX for i in range(n+1): arr[i]=0 for k in range(q): flag=0 if(qj[k]qj[k]): flag=1 break if(flag==0): print("YES") arr[qi[k]]=qj[k] arr[qj[k]]=qi[k] else : print("NO") if __name__=="__main__" : n=10 q=7 qi=[1,2,2,2,9,10,8] qj=[5,7,3,4,9,9,6] solveQuery(n,q,qi,qj) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 50 ; skip ; if __name__ = "__main__" then ( n := 10 ; q := 7 ; qi := Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{9}->union(Sequence{10}->union(Sequence{ 8 })))))) ; qj := Sequence{5}->union(Sequence{7}->union(Sequence{3}->union(Sequence{4}->union(Sequence{9}->union(Sequence{9}->union(Sequence{ 6 })))))) ; solveQuery(n, q, qi, qj) ) else skip; operation solveQuery(n : OclAny, q : OclAny, qi : OclAny, qj : OclAny) pre: true post: true activity: var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, MAX) ; for i : Integer.subrange(0, n + 1-1) do ( arr[i+1] := 0) ; for k : Integer.subrange(0, q-1) do ( var flag : int := 0 ; if ((qj[k+1]->compareTo(qi[k+1])) < 0) then ( var qj[k+1] : OclAny := null; var qi[k+1] : OclAny := null; Sequence{qj[k+1],qi[k+1]} := Sequence{qi[k+1],qj[k+1]} ) else skip ; if (arr[qi[k+1]+1] /= 0 or arr[qj[k+1]+1] /= 0) then ( flag := 1 ) else (if (qi[k+1] = qj[k+1]) then ( flag := 1 ) else ( for i : Integer.subrange(1, qi[k+1]-1) do ( if (arr[i+1] /= 0 & (arr[i+1]->compareTo(qj[k+1])) < 0 & (qi[k+1]->compareTo(arr[i+1])) < 0) then ( flag := 1 ; break ) else skip) ; if (flag = 0) then ( for i : Integer.subrange(qi[k+1] + 1, qj[k+1]-1) do ( if (arr[i+1] /= 0 & (arr[i+1]->compareTo(qj[k+1])) > 0) then ( flag := 1 ; break ) else skip) ) else skip ) ) ; if (flag = 0) then ( execute ("YES")->display() ; arr[qi[k+1]+1] := qj[k+1] ; arr[qj[k+1]+1] := qi[k+1] ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys inp=input() string_sorted=sorted(inp) llps="" llps+=string_sorted[len(string_sorted)-1] for i in reversed(range(len(string_sorted)-1)): if(llps[-1]==string_sorted[i]): llps+=string_sorted[i] print(llps) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var inp : String := (OclFile["System.in"]).readLine() ; var string_sorted : Sequence := inp->sort() ; var llps : String := "" ; llps := llps + string_sorted[(string_sorted)->size() - 1+1] ; for i : (Integer.subrange(0, (string_sorted)->size() - 1-1))->reverse() do ( if (llps->last() = string_sorted[i+1]) then ( llps := llps + string_sorted[i+1] ) else skip) ; execute (llps)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): LIMIT=10000 isprime=eulerlib.list_primality(LIMIT-1) for base in range(1000,LIMIT): if isprime[base]: for step in range(1,LIMIT): a=base+step b=a+step if adisplay() ) else skip; operation compute() : OclAny pre: true post: true activity: var LIMIT : int := 10000 ; var isprime : OclAny := eulerlib.list_primality(LIMIT - 1) ; for base : Integer.subrange(1000, LIMIT-1) do ( if isprime[base+1] then ( for step : Integer.subrange(1, LIMIT-1) do ( var a : OclAny := base + step ; var b : OclAny := a + step ; if (a->compareTo(LIMIT)) < 0 & isprime[a+1] & has_same_digits(a, base) & (b->compareTo(LIMIT)) < 0 & isprime[b+1] & has_same_digits(b, base) & (base /= 1487 or a /= 4817) then ( return ("" + ((base))) + ("" + ((a))) + ("" + ((b))) ) else skip) ) else skip) ; error RuntimeError.newRuntimeError("Not found"); operation has_same_digits(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return ("" + ((x)))->sort() = ("" + ((y)))->sort(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): isprime=eulerlib.list_primality(20000000) ans=sum(sam_transitions_minus_max_transitions(i)for(i,p)in enumerate(isprime)if i>=10000000 and p) return str(ans) def sam_transitions_minus_max_transitions(n): samtrans=0 maxtrans=0 segmentstate=0 while True : newstate=number_to_segments(n) if newstate==segmentstate : break maxtrans+=eulerlib.popcount(newstate ^ segmentstate) segmentstate=newstate samtrans+=2*eulerlib.popcount(newstate) n=digit_sum(n) maxtrans+=eulerlib.popcount(segmentstate) return samtrans-maxtrans def number_to_segments(n): if n<0 : raise ValueError() result=0 i=0 while True : result |=DECIMAL_DIGIT_TO_SEGMENT[n % 10]<<(i*7) n//=10 i+=1 if n==0 : return result def digit_sum(n): if n<0 : raise ValueError() result=0 while n!=0 : result+=n % 10 n//=10 return result DECIMAL_DIGIT_TO_SEGMENT=[0b1110111,0b0010010,0b1011101,0b1011011,0b0111010,0b1101011,0b1101111,0b1110010,0b1111111,0b1111011] if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var DECIMAL_DIGIT_TO_SEGMENT : Sequence := Sequence{0b1110111}->union(Sequence{0b0010010}->union(Sequence{0b1011101}->union(Sequence{0b1011011}->union(Sequence{0b0111010}->union(Sequence{0b1101011}->union(Sequence{0b1101111}->union(Sequence{0b1110010}->union(Sequence{0b1111111}->union(Sequence{ 0b1111011 }))))))))) ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var isprime : OclAny := eulerlib.list_primality(20000000) ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name sam_transitions_minus_max_transitions)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) , (test (logical_test (comparison (expr (atom (name p))))))) )))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name isprime)))))))) )))))) (comp_iter if (test (logical_test (logical_test (comparison (comparison (expr (atom (name i)))) >= (comparison (expr (atom (number (integer 10000000))))))) and (logical_test (comparison (expr (atom (name p)))))))))))->sum() ; return ("" + ((ans))); operation sam_transitions_minus_max_transitions(n : OclAny) : OclAny pre: true post: true activity: var samtrans : int := 0 ; var maxtrans : int := 0 ; var segmentstate : int := 0 ; while true do ( var newstate : OclAny := number_to_segments(n) ; if newstate = segmentstate then ( break ) else skip ; maxtrans := maxtrans + eulerlib.popcount(MathLib.bitwiseXor(newstate, segmentstate)) ; segmentstate := newstate ; samtrans := samtrans + 2 * eulerlib.popcount(newstate) ; n := digit_sum(n)) ; maxtrans := maxtrans + eulerlib.popcount(segmentstate) ; return samtrans - maxtrans; operation number_to_segments(n : OclAny) : OclAny pre: true post: true activity: if n < 0 then ( error IncorrectElementException.newIncorrectElementException() ) else skip ; var result : int := 0 ; var i : int := 0 ; while true do ( result := result or DECIMAL_DIGIT_TO_SEGMENT[n mod 10+1] * (2->pow((i * 7))) ; n := n div 10 ; i := i + 1 ; if n = 0 then ( return result ) else skip); operation digit_sum(n : OclAny) : OclAny pre: true post: true activity: if n < 0 then ( error IncorrectElementException.newIncorrectElementException() ) else skip ; result := 0 ; while n /= 0 do ( result := result + n mod 10 ; n := n div 10) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def centered_heptagonal_num(n): return(7*n*n-7*n+2)//2 n=5 print("%sth Centered heptagonal number : " % n,centered_heptagonal_num(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; execute (StringLib.format("%sth Centered heptagonal number : ",n))->display(); operation centered_heptagonal_num(n : OclAny) : OclAny pre: true post: true activity: return (7 * n * n - 7 * n + 2) div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printNumber(holes): if(holes==0): print("1") elif(holes==1): print("0",end="") else : rem=0 quo=0 rem=holes % 2 quo=holes//2 if(rem==1): print("4",end="") for i in range(quo): print("8",end="") holes=3 printNumber(holes) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; holes := 3 ; printNumber(holes); operation printNumber(holes : OclAny) pre: true post: true activity: if (holes = 0) then ( execute ("1")->display() ) else (if (holes = 1) then ( execute ("0")->display() ) else ( var rem : int := 0 ; var quo : int := 0 ; rem := holes mod 2 ; quo := holes div 2 ; if (rem = 1) then ( execute ("4")->display() ) else skip ; for i : Integer.subrange(0, quo-1) do ( execute ("8")->display()) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSubarray(arr,n,k): s=0 i=0 while(ik): i=i+1 continue count=0 while(iunion(Sequence{2}->union(Sequence{ 3 })) ; k := 2 ; n := (arr)->size() ; execute (countSubarray(arr, n, k))->display(); operation countSubarray(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var s : int := 0 ; var i : int := 0 ; while ((i->compareTo(n)) < 0) do ( if ((arr[i+1]->compareTo(k)) > 0) then ( i := i + 1 ; continue ) else skip ; var count : int := 0 ; while ((i->compareTo(n)) < 0 & (arr[i+1]->compareTo(k)) <= 0) do ( i := i + 1 ; count := count + 1) ; s := s + ((count * (count + 1)) div 2)) ; return (n * (n + 1) div 2 - s); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def array_building(n : int): build_list=[pow(2,_)for _ in range(1,n+1)] return build_list t=int(input()) n_list=[int(input())for _ in range(t)] for _ in range(t): result_build_list=array_building(n_list[_]) len_list=len(result_build_list) if len_list==2 : print(result_build_list[1]-result_build_list[0]) else : x=int(len_list/2)-1 amount_large=result_build_list[len_list-1] sum_smaller=result_build_list[x] for _ in range(int((len_list/2))-1): x+=1 amount_large+=result_build_list[_] sum_smaller+=result_build_list[x] print(amount_large-sum_smaller) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n_list : Sequence := Integer.subrange(0, t-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; for _anon : Integer.subrange(0, t-1) do ( var result_build_list : OclAny := array_building(n_list[_anon+1]) ; var len_list : int := (result_build_list)->size() ; if len_list = 2 then ( execute (result_build_list[1+1] - result_build_list->first())->display() ) else ( var x : double := ("" + ((len_list / 2)))->toInteger() - 1 ; var amount_large : OclAny := result_build_list[len_list - 1+1] ; var sum_smaller : OclAny := result_build_list[x+1] ; for _anon : Integer.subrange(0, ("" + (((len_list / 2))))->toInteger() - 1-1) do ( x := x + 1 ; amount_large := amount_large + result_build_list[_anon+1] ; sum_smaller := sum_smaller + result_build_list[x+1]) ; execute (amount_large - sum_smaller)->display() )); operation array_building(n : int) : OclAny pre: true post: true activity: var build_list : Sequence := Integer.subrange(1, n + 1-1)->select(_anon | true)->collect(_anon | ((2)->pow(_anon))) ; return build_list; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) for x in range(a): b=int(input()) c=[] for x in range(1,b+1): c.append(2**x) d=0 d+=c[b-1] for x in range(b//2-1): d+=c[x] print(d-(sum(c)-d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for x : Integer.subrange(0, a-1) do ( var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : Sequence := Sequence{} ; for x : Integer.subrange(1, b + 1-1) do ( execute (((2)->pow(x)) : c)) ; var d : int := 0 ; d := d + c[b - 1+1] ; for x : Integer.subrange(0, b div 2 - 1-1) do ( d := d + c[x+1]) ; execute (d - ((c)->sum() - d))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) li=[2**i for i in range(1,n+1)] pile1=li.pop() pile2=0 while len(li)>=n/2 : pile2+=li.pop() pile1+=sum(li) print(abs(pile2-pile1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li : Sequence := Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | ((2)->pow(i))) ; var pile1 : OclAny := li->last() ; li := li->front() ; var pile2 : int := 0 ; while ((li)->size()->compareTo(n / 2)) >= 0 do ( pile2 := pile2 + li->last() ; li := li->front()) ; pile1 := pile1 + (li)->sum() ; execute ((pile2 - pile1)->abs())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math t=eval(input()) for i in range(t): length=eval(input()) input_list=[] for j in range(1,length+1): input_list.append(2**j) result=math.fsum(input_list) sum_of_half=input_list[length-1] result-=input_list[length-1] for j in range(int(length/2)-1): sum_of_half+=input_list[j] result-=input_list[j] print(int(math.fabs(result-sum_of_half))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : OclAny := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, t-1) do ( var length : OclAny := (OclFile["System.in"]).readLine() ; var input_list : Sequence := Sequence{} ; for j : Integer.subrange(1, length + 1-1) do ( execute (((2)->pow(j)) : input_list)) ; var result : double := (input_list)->sum() ; var sum_of_half : OclAny := input_list[length - 1+1] ; result := result - input_list[length - 1+1] ; for j : Integer.subrange(0, ("" + ((length / 2)))->toInteger() - 1-1) do ( sum_of_half := sum_of_half + input_list[j+1] ; result := result - input_list[j+1]) ; execute (("" + (((result - sum_of_half)->abs())))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) for i in range(a): b=int(input()) k=[2**x for x in range(1,b+1)] q=0 c=2**b while qtoInteger() ; for i : Integer.subrange(0, a-1) do ( var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : Sequence := Integer.subrange(1, b + 1-1)->select(x | true)->collect(x | ((2)->pow(x))) ; var q : int := 0 ; var c : double := (2)->pow(b) ; while (q->compareTo(b div 2 - 1)) < 0 do ( c := c + k[q+1] ; q := q + 1) ; var qw : int := 0 ; q := b div 2 - 1 ; while (q->compareTo(b - 1)) < 0 do ( qw := qw + k[q+1] ; q := q + 1) ; execute (("" + (((c - qw)->abs())))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split(" ")) c,d=map(int,input().split(" ")) l=[] f=False anw=-1 for i in range(101): x=b+(a*i) y=d+(c*i) if f : break if x in l : f=True anw=x break l.append(x) if y in l : f=True anw=y break l.append(y) print(anw) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := Sequence{} ; var f : boolean := false ; var anw : int := -1 ; for i : Integer.subrange(0, 101-1) do ( var x : OclAny := b + (a * i) ; var y : OclAny := d + (c * i) ; if f then ( break ) else skip ; if (l)->includes(x) then ( f := true ; anw := x ; break ) else skip ; execute ((x) : l) ; if (l)->includes(y) then ( f := true ; anw := y ; break ) else skip ; execute ((y) : l)) ; execute (anw)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,c=map(int,input().split()) l=list(map(int,input().split())) i=n-1 while i>0 and l[i]-l[i-1]<=c : i-=1 print(n-i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var i : double := n - 1 ; while i > 0 & (l[i+1] - l[i - 1+1]->compareTo(c)) <= 0 do ( i := i - 1) ; execute (n - i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- b,a=map(int,input().split()) d,c=map(int,input().split()) mom=0 while mom<100000 : while acollect( _x | (OclType["int"])->apply(_x) ) ; var d : OclAny := null; var c : OclAny := null; Sequence{d,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mom : int := 0 ; while mom < 100000 do ( while (a->compareTo(c)) < 0 do ( a := a + b) ; while (c->compareTo(a)) < 0 do ( c := c + d) ; if a = c then ( execute (a)->display() ; exit() ) else skip ; mom := mom + 1) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def missingNum(arr,n): minvalue=min(arr) xornum=0 for i in range(0,n): xornum ^=(minvalue)^ arr[i] minvalue=minvalue+1 return xornum ^ minvalue arr=[13,12,11,15] n=len(arr) print(missingNum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{13}->union(Sequence{12}->union(Sequence{11}->union(Sequence{ 15 }))) ; n := (arr)->size() ; execute (missingNum(arr, n))->display(); operation missingNum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var minvalue : OclAny := (arr)->min() ; var xornum : int := 0 ; for i : Integer.subrange(0, n-1) do ( xornum := xornum xor MathLib.bitwiseXor((minvalue), arr[i+1]) ; minvalue := minvalue + 1) ; return MathLib.bitwiseXor(xornum, minvalue); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (a,b)=map(int,input().split(' ')) (c,d)=map(int,input().split(' ')) first_b=b first_d=d pick_d=0 pick_b=0 not_pick_b=0 not_pick_d=0 if b==d : print(b) else : while True : if(b-first_d)% c==0 and b-first_d!=0 and(b-first_d)//c>0 : pick_b+=1 break else : if b>10000 : not_pick_b+=1 break b+=a while True : if(d-first_b)% a==0 and(d-first_b)!=0 and(d-first_b)//a>0 : pick_d+=1 break else : if d>10000 : not_pick_d+=1 break d+=c if pick_b==pick_d==1 : print(min(b,d)) if not_pick_b==not_pick_d==1 : print('-1') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{a, b} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var Sequence{c, d} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var first_b : OclAny := b ; var first_d : OclAny := d ; var pick_d : int := 0 ; var pick_b : int := 0 ; var not_pick_b : int := 0 ; var not_pick_d : int := 0 ; if b = d then ( execute (b)->display() ) else ( while true do ( if (b - first_d) mod c = 0 & b - first_d /= 0 & (b - first_d) div c > 0 then ( pick_b := pick_b + 1 ; break ) else ( if b > 10000 then ( not_pick_b := not_pick_b + 1 ; break ) else skip ) ; b := b + a) ; while true do ( if (d - first_b) mod a = 0 & (d - first_b) /= 0 & (d - first_b) div a > 0 then ( pick_d := pick_d + 1 ; break ) else ( if d > 10000 then ( not_pick_d := not_pick_d + 1 ; break ) else skip ) ; d := d + c) ; if pick_b = pick_d & (pick_d == 1) then ( execute (Set{b, d}->min())->display() ) else skip ; if not_pick_b = not_pick_d & (not_pick_d == 1) then ( execute ('-1')->display() ) else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) c,d=map(int,input().split()) for i in range(100000): if(b+a*i-d)>=0 and(i*a+b-d)%(c)==0 : print(i*a+b) exit() print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, 100000-1) do ( if (b + a * i - d) >= 0 & (i * a + b - d) mod (c) = 0 then ( execute (i * a + b)->display() ; exit() ) else skip) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=-1 a,b=map(int,input().split()) c,d=map(int,input().split()) for i in range(100000): if(b+a*i-d)>=0 and(i*a+b-d)%(c)==0 : print(i*a+b) exit() print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := -1 ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, 100000-1) do ( if (b + a * i - d) >= 0 & (i * a + b - d) mod (c) = 0 then ( execute (i * a + b)->display() ; exit() ) else skip) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def display(n): sp=n//2 st=1 for i in range(1,n+1): for j in range(1,sp+1): print(" ",end=' ') count=st//2+1 for k in range(1,st+1): print(count,end=' ') if(k<=(st//2)): count-=1 else : count+=1 print() if(i<=n//2): sp-=1 st+=2 else : sp+=1 st-=2 n=7 display(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 7 ; display(n); operation display(n : OclAny) pre: true post: true activity: var sp : int := n div 2 ; var st : int := 1 ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, sp + 1-1) do ( execute (" ")->display()) ; var count : int := st div 2 + 1 ; for k : Integer.subrange(1, st + 1-1) do ( execute (count)->display() ; if ((k->compareTo((st div 2))) <= 0) then ( count := count - 1 ) else ( count := count + 1 )) ; execute (->display() ; if ((i->compareTo(n div 2)) <= 0) then ( sp := sp - 1 ; st := st + 2 ) else ( sp := sp + 1 ; st := st - 2 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def display(n): sp=n//2 st=1 for i in range(1,n+1): for j in range(1,sp+1): print(end="") count=1 for k in range(1,st+1): if(k % 2==0): print("*",end="") else : print(count,end="") count+=1 print() if(i<=n//2): sp=sp-1 st=st+2 else : sp=sp+1 st=st-2 n=5 display(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; display(n); operation display(n : OclAny) pre: true post: true activity: var sp : int := n div 2 ; var st : int := 1 ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, sp + 1-1) do ( execute ((argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom "")))))))->display()) ; var count : int := 1 ; for k : Integer.subrange(1, st + 1-1) do ( if (k mod 2 = 0) then ( execute ("*")->display() ) else ( execute (count)->display() ; count := count + 1 )) ; execute (->display() ; if ((i->compareTo(n div 2)) <= 0) then ( sp := sp - 1 ; st := st + 2 ) else ( sp := sp + 1 ; st := st - 2 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binomialCoeff(n,k): C=[[0 for i in range(k+1)]for j in range(n+1)]; i,j=0,0 ; for i in range(n+1): for j in range(min(i,k)+1): if(j==0 or j==i): C[i][j]=1 ; else : C[i][j]=C[i-1][j-1]+C[i-1][j]; return C[n][k]; def count(n,k): sum=0 ; for j in range(1,k+1): sum=sum+binomialCoeff(n,j); return sum ; if __name__=='__main__' : n=3 ; k=2 ; print(count(n,k),end=""); n1=5 ; k1=2 ; print(count(n1,k1)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( n := 3; ; k := 2; ; execute (count(n, k))->display(); ; var n1 : int := 5; ; var k1 : int := 2; ; execute (count(n1, k1))->display(); ) else skip; operation binomialCoeff(n : OclAny, k : OclAny) pre: true post: true activity: var C : Sequence := Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, k + 1-1)->select(i | true)->collect(i | (0)))); ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,0}; ; for i : Integer.subrange(0, n + 1-1) do ( for j : Integer.subrange(0, Set{i, k}->min() + 1-1) do ( if (j = 0 or j = i) then ( C[i+1][j+1] := 1; ) else ( C[i+1][j+1] := C[i - 1+1][j - 1+1] + C[i - 1+1][j+1]; ))) ; return C[n+1][k+1];; operation count(n : OclAny, k : OclAny) pre: true post: true activity: var sum : int := 0; ; for j : Integer.subrange(1, k + 1-1) do ( sum := sum + binomialCoeff(n, j);) ; return sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPossible(A,n,k): countOfTwo=0 for i in range(n): if(A[i]% 2==0): countOfTwo+=1 if(k==0 and countOfTwo==n): print("NO\n") elif(countOfTwo>=k): print("Yes\n") else : print("No\n") if __name__=='__main__' : arr=[1,2,4,5] K=2 N=len(arr) isPossible(arr,N,K) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var arr : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 5 }))) ; var K : int := 2 ; var N : int := (arr)->size() ; isPossible(arr, N, K) ) else skip; operation isPossible(A : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var countOfTwo : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (A[i+1] mod 2 = 0) then ( countOfTwo := countOfTwo + 1 ) else skip) ; if (k = 0 & countOfTwo = n) then ( execute ("NO\n")->display() ) else (if ((countOfTwo->compareTo(k)) >= 0) then ( execute ("Yes\n")->display() ) else ( execute ("No\n")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPossible(Str): freq=dict() max_freq=0 for j in range(len(Str)): freq[Str[j]]=freq.get(Str[j],0)+1 if(freq[Str[j]]>max_freq): max_freq=freq[Str[j]] if(max_freq<=(len(Str)-max_freq+1)): return True return False Str="geeksforgeeks" if(isPossible(Str)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Str := "geeksforgeeks" ; if (isPossible(Str)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isPossible(Str : OclAny) : OclAny pre: true post: true activity: var freq : Map := (arguments ( )) ; var max_freq : int := 0 ; for j : Integer.subrange(0, (Str)->size()-1) do ( freq[Str[j+1]+1] := freq.get(Str[j+1], 0) + 1 ; if ((freq[Str[j+1]+1]->compareTo(max_freq)) > 0) then ( max_freq := freq[Str[j+1]+1] ) else skip) ; if ((max_freq->compareTo(((Str)->size() - max_freq + 1))) <= 0) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : n,m,k=list(map(int,input().split(""))) a=input() b=input() a=sorted(a) b=sorted(b) ak=0 bk=0 c="" i,j=0,0 while itoInteger() ; while t > 0 do ( var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := ((input().split(""))->collect( _x | (OclType["int"])->apply(_x) )) ; var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; a := a->sort() ; b := b->sort() ; var ak : int := 0 ; var bk : int := 0 ; var c : String := "" ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,0} ; while (i->compareTo(n)) < 0 & (j->compareTo(m)) < 0 do ( var gde : boolean := (b[j+1]->compareTo(a[i+1])) < 0 ; if gde & bk = k then ( gde := false ) else skip ; if not(gde) & ak = k then ( gde := true ) else skip ; if gde then ( c := c + b[j+1] ; bk := bk + 1 ; ak := 0 ; j := j + 1 ) else ( c := c + a[i+1] ; ak := ak + 1 ; bk := 0 ; i := i + 1 )) ; execute (c)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,c=map(int,input().split()) l=list(map(int,input().split())) t=0 for i in range(n-1): k=l[i+1]-l[i] if k<=c : t+=1 else : t=0 print(t+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( var k : double := l[i + 1+1] - l[i+1] ; if (k->compareTo(c)) <= 0 then ( t := t + 1 ) else ( t := 0 )) ; execute (t + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def smallestPermute(n): res=[""]*(n+1) if(n % 2==0): for i in range(n): if(i % 2==0): res[i]=chr(48+i+2) else : res[i]=chr(48+i) else : for i in range(n-2): if(i % 2==0): res[i]=chr(48+i+2) else : res[i]=chr(48+i) res[n-1]=chr(48+n-2) res[n-2]=chr(48+n) res[n-3]=chr(48+n-1) res=''.join(res) return res if __name__=="__main__" : n=7 print(smallestPermute(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 7 ; execute (smallestPermute(n))->display() ) else skip; operation smallestPermute(n : OclAny) : OclAny pre: true post: true activity: var res : Sequence := MatrixLib.elementwiseMult(Sequence{ "" }, (n + 1)) ; if (n mod 2 = 0) then ( for i : Integer.subrange(0, n-1) do ( if (i mod 2 = 0) then ( res[i+1] := (48 + i + 2)->byte2char() ) else ( res[i+1] := (48 + i)->byte2char() )) ) else ( for i : Integer.subrange(0, n - 2-1) do ( if (i mod 2 = 0) then ( res[i+1] := (48 + i + 2)->byte2char() ) else ( res[i+1] := (48 + i)->byte2char() )) ; res[n - 1+1] := (48 + n - 2)->byte2char() ; res[n - 2+1] := (48 + n)->byte2char() ; res[n - 3+1] := (48 + n - 1)->byte2char() ) ; res := StringLib.sumStringsWithSeparator((res), '') ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input for _ in[0]*int(I()): k=c=int(I().split()[2]); a,b=map(sorted,(I(),I())); r='' while a and b : if a>b*c : a,b=b,a ; c=k r+=a.pop(0); c-=1 print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + ((I())))->toInteger()) do ( var k : OclAny := ("" + ((I().split()[2+1])))->toInteger(); var c : int := ("" + ((I().split()[2+1])))->toInteger(); var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (Sequence{I(), I()})->collect( _x | (sorted)->apply(_x) ); var r : String := '' ; while a & b do ( if (a->compareTo(b * c)) > 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a}; c := k ) else skip ; r := r + a->at(0`firstArg+1) ; a := a->excludingAt(0+1); c := c - 1) ; execute (r)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,m,k=map(int,input().split()) a=sorted(list(input())) b=sorted(list(input())) c='' aj=k bj=k while n>0 and m>0 : if(aj>0 and a[0]<=b[0])or bj==0 : c+=a[0] n-=1 aj-=1 a.pop(0) bj=k else : c+=b[0] m-=1 bj-=1 aj=k b.pop(0) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((OclFile["System.in"]).readLine())->characters()->sort() ; var b : Sequence := ((OclFile["System.in"]).readLine())->characters()->sort() ; var c : String := '' ; var aj : OclAny := k ; var bj : OclAny := k ; while n > 0 & m > 0 do ( if (aj > 0 & (a->first()->compareTo(b->first())) <= 0) or bj = 0 then ( c := c + a->first() ; n := n - 1 ; aj := aj - 1 ; a := a->excludingAt(0+1) ; bj := k ) else ( c := c + b->first() ; m := m - 1 ; bj := bj - 1 ; aj := k ; b := b->excludingAt(0+1) )) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for jj in range(int(input())): n,m,k=[int(i)for i in input().split()] a,b=sorted(input()),sorted(input()) c='' t1=0 t2=0 i=j=0 while itoInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{(OclFile["System.in"]).readLine()->sort(),(OclFile["System.in"]).readLine()->sort()} ; var c : String := '' ; var t1 : int := 0 ; var t2 : int := 0 ; var i : OclAny := 0; var j : int := 0 ; while (i->compareTo(n)) < 0 & (j->compareTo(m)) < 0 do ( if (a[i+1]->compareTo(b[j+1])) < 0 then ( if (t1->compareTo(k)) < 0 then ( c := c + a[i+1] ; i := i + 1 ; t1 := t1 + 1 ; t2 := 0 ) else ( c := c + b[j+1] ; t2 := t2 + 1 ; t1 := 0 ; j := j + 1 ) ) else ( if (t2->compareTo(k)) < 0 then ( c := c + b[j+1] ; j := j + 1 ; t2 := t2 + 1 ; t1 := 0 ) else ( c := c + a[i+1] ; i := i + 1 ; t1 := t1 + 1 ; t2 := 0 ) )) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : n,m,k=list(map(int,input().split(""))) a=input() b=input() a=sorted(a,reverse=True) b=sorted(b,reverse=True) ak=0 bk=0 c="" i,j=n-1,m-1 while i>=0 and j>=0 : gde=b[j]toInteger() ; while t > 0 do ( var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := ((input().split(""))->collect( _x | (OclType["int"])->apply(_x) )) ; var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; a := a->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; b := b->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var ak : int := 0 ; var bk : int := 0 ; var c : String := "" ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{n - 1,m - 1} ; while i >= 0 & j >= 0 do ( var gde : boolean := (b[j+1]->compareTo(a[i+1])) < 0 ; if gde & bk = k then ( gde := false ) else skip ; if not(gde) & ak = k then ( gde := true ) else skip ; if gde then ( c := c + b[j+1] ; bk := bk + 1 ; ak := 0 ; j := j - 1 ) else ( c := c + a[i+1] ; ak := ak + 1 ; bk := 0 ; i := i - 1 )) ; execute (c)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNthEvenDigitNumber(n): if(n==1): return 0 v=[] n=n-1 while(n>0): v.append(n % 5) n=n//5 result=0 for i in range(len(v)-1,-1,-1): result=result*10 result=result+v[i] return 2*result if __name__=="__main__" : print(findNthEvenDigitNumber(2)) print(findNthEvenDigitNumber(10)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (findNthEvenDigitNumber(2))->display() ; execute (findNthEvenDigitNumber(10))->display() ) else skip; operation findNthEvenDigitNumber(n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return 0 ) else skip ; var v : Sequence := Sequence{} ; n := n - 1 ; while (n > 0) do ( execute ((n mod 5) : v) ; n := n div 5) ; var result : int := 0 ; for i : Integer.subrange(-1 + 1, (v)->size() - 1)->reverse() do ( result := result * 10 ; result := result + v[i+1]) ; return 2 * result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Factorial(n): fac=1 for i in range(1,n+1): fac*=i return fac print(Factorial(eval(input()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (Factorial((OclFile["System.in"]).readLine()))->display(); operation Factorial(n : OclAny) : OclAny pre: true post: true activity: var fac : int := 1 ; for i : Integer.subrange(1, n + 1-1) do ( fac := fac * i) ; return fac; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") print(math.factorial(int(input()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; execute (MathLib.factorial(("" + (((OclFile["System.in"]).readLine())))->toInteger()))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) k=1 for j in range(1,n+1): k*=j print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := 1 ; for j : Integer.subrange(1, n + 1-1) do ( k := k * j) ; execute (k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- v=(1,1,2,6,24,120,720,5040,40320,362880,3628800,39916800,479001600,6227020800,87178291200,1307674368000,20922789888000,355687428096000,6402373705728000,121645100408832000,2432902008176640000) print(v[int(input())]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var v : OclAny := Sequence{1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200, 1307674368000, 20922789888000, 355687428096000, 6402373705728000, 121645100408832000, 2432902008176640000} ; execute (v[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=input() print(math.factorial(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : String := (OclFile["System.in"]).readLine() ; execute (MathLib.factorial(n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def minOperations(a,n,K): Map=defaultdict(lambda : False) for i in range(0,n): if Map[a[i]]==True : return 0 Map[a[i]]=True b=[] for i in range(0,n): b.append(a[i]& K) Map.clear() for i in range(0,n): if a[i]!=b[i]: Map[b[i]]=True for i in range(0,n): if Map[a[i]]==True : return 1 Map.clear() for i in range(0,n): if Map[b[i]]==True : return 2 Map[b[i]]=True return-1 if __name__=="__main__" : K=3 a=[1,2,3,7] n=len(a) print(minOperations(a,n,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( K := 3 ; a := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 7 }))) ; n := (a)->size() ; execute (minOperations(a, n, K))->display() ) else skip; operation minOperations(a : OclAny, n : OclAny, K : OclAny) : OclAny pre: true post: true activity: var Map : OclAny := defaultdict(lambda $$ : OclAny in (false)) ; for i : Integer.subrange(0, n-1) do ( if Map[a[i+1]+1] = true then ( return 0 ) else skip ; Map[a[i+1]+1] := true) ; var b : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((MathLib.bitwiseAnd(a[i+1], K)) : b)) ; execute (Map /<: Map) ; for i : Integer.subrange(0, n-1) do ( if a[i+1] /= b[i+1] then ( Map[b[i+1]+1] := true ) else skip) ; for i : Integer.subrange(0, n-1) do ( if Map[a[i+1]+1] = true then ( return 1 ) else skip) ; execute (Map /<: Map) ; for i : Integer.subrange(0, n-1) do ( if Map[b[i+1]+1] = true then ( return 2 ) else skip ; Map[b[i+1]+1] := true) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,c=map(int,input().split()) a=list(map(int,input().split())) count=1 for i in range(1,n): if a[i]-a[i-1]>c : count=1 else : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : int := 1 ; for i : Integer.subrange(1, n-1) do ( if (a[i+1] - a[i - 1+1]->compareTo(c)) > 0 then ( count := 1 ) else ( count := count + 1 )) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=int(input()) print(N**2-A) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((N)->pow(2) - A)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- nl=lambda : list(map(int,input().split())) sl=lambda : input().split() n=lambda : int(input()) s=lambda : input() N=n() A=n() print(N*N-A) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var nl : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sl : Function := lambda $$ : OclAny in (input().split()) ; var n : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var s : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var N : OclAny := n->apply() ; var A : OclAny := n->apply() ; execute (N * N - A)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) a=int(input()) print(n*n-a) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n * n - a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a=list(map(int,[input().rstrip()for _ in range(2)])) print(n**2-a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := ((Integer.subrange(0, 2-1)->select(_anon | true)->collect(_anon | (input().rstrip())))->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((n)->pow(2) - a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=int(input()) tmp=N**2-A if tmp>=0 : print(tmp) else : print(N**2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var tmp : double := (N)->pow(2) - A ; if tmp >= 0 then ( execute (tmp)->display() ) else ( execute ((N)->pow(2))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) print((N+2-1)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((N + 2 - 1) div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(N : int): q,m=divmod(N,2) if m==1 : print(q+1) else : print(q) return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() N=int(next(tokens)) solve(N) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(N : int) pre: true post: true activity: var q : OclAny := null; var m : OclAny := null; Sequence{q,m} := Sequence{(N div 2), (N mod 2)} ; if m = 1 then ( execute (q + 1)->display() ) else ( execute (q)->display() ) ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var N : int := ("" + (((tokens).next())))->toInteger() ; solve(N); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(__import__('math').ceil(int(input())/2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (__import__('math').ceil(("" + (((OclFile["System.in"]).readLine())))->toInteger() / 2))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 2==1 : ans=n//2+1 else : ans=n//2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 1 then ( var ans : int := n div 2 + 1 ) else ( ans := n div 2 ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bfs(i,j): if a[i][j]=="." : a[i][j]="#" res=1 wc=0 bc=0 for dy in range(-1,2): for dx in range(-1,2): if(dx==0 and dy!=0)or(dx!=0 and dy==0): pass else : continue ny=i+dy nx=j+dx if 0<=nx<=w-1 and 0<=ny<=h-1 and a[ny][nx]!="#" : if a[ny][nx]=="." : wct,bct,rest=bfs(ny,nx) wc+=wct bc+=bct res+=rest elif a[ny][nx]=="W" : wc+=1 elif a[ny][nx]=="B" : bc+=1 return wc,bc,res import sys sys.setrecursionlimit(100000) while True : w,h=map(int,input().split()) wans=0 bans=0 if w==0 and h==0 : break a=[list(input())for _ in range(h)] for i in range(w): for j in range(h): if a[j][i]=="." : wc,bc,res=bfs(j,i) if wc>0 and bc==0 : wans+=res elif wc==0 and bc>0 : bans+=res print(bans,wans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit(100000) ; while true do ( var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var wans : int := 0 ; var bans : int := 0 ; if w = 0 & h = 0 then ( break ) else skip ; var a : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (((OclFile["System.in"]).readLine())->characters())) ; for i : Integer.subrange(0, w-1) do ( for j : Integer.subrange(0, h-1) do ( if a[j+1][i+1] = "." then ( Sequence{wc,bc,res} := bfs(j, i) ; if wc > 0 & bc = 0 then ( wans := wans + res ) else (if wc = 0 & bc > 0 then ( bans := bans + res ) else skip) ) else skip)) ; execute (bans)->display()); operation bfs(i : OclAny, j : OclAny) : OclAny pre: true post: true activity: if a[i+1][j+1] = "." then ( a[i+1][j+1] := "#" ) else skip ; var res : int := 1 ; var wc : int := 0 ; var bc : int := 0 ; for dy : Integer.subrange(-1, 2-1) do ( for dx : Integer.subrange(-1, 2-1) do ( if (dx = 0 & dy /= 0) or (dx /= 0 & dy = 0) then ( skip ) else ( continue ) ; var ny : OclAny := i + dy ; var nx : OclAny := j + dx ; if 0 <= nx & (nx <= w - 1) & 0 <= ny & (ny <= h - 1) & a[ny+1][nx+1] /= "#" then ( if a[ny+1][nx+1] = "." then ( var wct : OclAny := null; var bct : OclAny := null; var rest : OclAny := null; Sequence{wct,bct,rest} := bfs(ny, nx) ; wc := wc + wct ; bc := bc + bct ; res := res + rest ) else (if a[ny+1][nx+1] = "W" then ( wc := wc + 1 ) else (if a[ny+1][nx+1] = "B" then ( bc := bc + 1 ) else skip ) ) ) else skip)) ; return wc, bc, res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools import fractions def main(): n=int(input()) print(n//2+n % 2) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n div 2 + n mod 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countTriplets(n,points): pts=[] ct=0 ; for i in range(n): pts.append(points[i]); for i in range(n): for j in range(i+1,n): x=points[i][0]+points[j][0]; y=points[i][1]+points[j][1]; if(x % 2==0 and y % 2==0): if[x//2,y//2]in pts : ct+=1 return ct if __name__=="__main__" : points=[[1,1],[2,2],[3,3]] n=len(points) print(countTriplets(n,points)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( points := Sequence{Sequence{1}->union(Sequence{ 1 })}->union(Sequence{Sequence{2}->union(Sequence{ 2 })}->union(Sequence{ Sequence{3}->union(Sequence{ 3 }) })) ; n := (points)->size() ; execute (countTriplets(n, points))->display() ) else skip; operation countTriplets(n : OclAny, points : OclAny) : OclAny pre: true post: true activity: var pts : Sequence := Sequence{} ; var ct : int := 0; ; for i : Integer.subrange(0, n-1) do ( execute ((points[i+1]) : pts);) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( var x : OclAny := points[i+1]->first() + points[j+1]->first(); ; var y : OclAny := points[i+1][1+1] + points[j+1][1+1]; ; if (x mod 2 = 0 & y mod 2 = 0) then ( if (pts)->includes(Sequence{x div 2}->union(Sequence{ y div 2 })) then ( ct := ct + 1 ) else skip ) else skip)) ; return ct; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from itertools import combinations def debug(*args): print(*args,file=sys.stderr) fin=sys.stdin T=int(fin.readline()) for case in range(1,T+1): N,K=list(map(int,fin.readline().split())) P=list(map(float,fin.readline().split())) P.sort() M=K//2+1 best=(0,[]) for c in range(K+1): combination=P[: c] if ctoInteger() ; for case : Integer.subrange(1, T + 1-1) do ( var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := ((fin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var P : Sequence := ((fin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) )) ; P := P->sort() ; var M : int := K div 2 + 1 ; var best : OclAny := Sequence{0, Sequence{}} ; for c : Integer.subrange(0, K + 1-1) do ( var combination : OclAny := P.subrange(1,c) ; if (c->compareTo(K)) < 0 then ( combination := combination + P.subrange(-(K - c)+1) ) else skip ; var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, M) ; s->first() := 1 ; for a1 : combination do ( var a0 : double := 1 - a1 ; var ss : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, M) ; ss->first() := s->first() * a0 ; for k : Integer.subrange(0, M-1) do ( ss[k+1] := s[k - 1+1] * a1 + s[k+1] * a0) ; s := ss) ; best := Set{best, Sequence{s->last(), combination}}->max()) ; execute (StringLib.format("Case #%d: %s",Sequence{case, best->first()}))->display()); operation debug(args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) execute ((argument * (test (logical_test (comparison (expr (atom (name args))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,c=list(map(int,input().split())) arr=list(map(int,input().split())) r=0 p=1 for a in arr : if a-p>c : r=1 else : r+=1 p=a print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var r : int := 0 ; var p : int := 1 ; for a : arr do ( if (a - p->compareTo(c)) > 0 then ( r := 1 ) else ( r := r + 1 ) ; p := a) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) print(max(0,3*n-k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{0, 3 * n - k}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) if(k//n>2): print(0) else : print(n-(k % n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (k div n > 2) then ( execute (0)->display() ) else ( execute (n - (k mod n))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) print(max(n*3-k,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{n * 3 - k, 0}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=[int(x)for x in input().split()] x=k-n*2 if x==0 : print(n) else : if x>n : print(0) else : print(n-x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var x : double := k - n * 2 ; if x = 0 then ( execute (n)->display() ) else ( if (x->compareTo(n)) > 0 then ( execute (0)->display() ) else ( execute (n - x)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) print(max(n*3-k,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{n * 3 - k, 0}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) print(a+a**2+a**3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (a + (a)->pow(2) + (a)->pow(3))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) print(sum(i*(N//i)*(N//i+1)//2 for i in range(1,N+1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (((argument (test (logical_test (comparison (expr (expr (expr (expr (atom (name i))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name N))) // (expr (atom (name i)))))))) )))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name N))) // (expr (atom (name i)))) + (expr (atom (number (integer 1))))))))) )))) // (expr (atom (number (integer 2)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name N))) + (expr (atom (number (integer 1)))))))))) )))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def bfs(y,x): q=deque() q.append((y,x)) bfs_map[y][x]=0 res=0 su=1 while q : y,x=q.popleft() for dy,dx in d : y_=y+dy x_=x+dx if 0<=y_union(Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{ Sequence{0, -1} }))) ; while 1 do ( var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if w = h & (h == 0) then ( break ) else skip ; var s : Sequence := Integer.subrange(0, h-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var bfs_map : Sequence := Integer.subrange(0, h-1)->select(i | true)->collect(i | (Integer.subrange(0, w-1)->select(j | true)->collect(j | (1)))) ; var f : Map := Map{ "." |-> 0 }->union(Map{ "B" |-> 1 }->union(Map{ "W" |-> 2 })) ; var ans : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))) ; for y : Integer.subrange(0, h-1) do ( for x : Integer.subrange(0, w-1) do ( if bfs_map[y+1][x+1] & s[y+1][x+1] = "." then ( var k : OclAny := null; Sequence{k,su} := bfs(y, x) ; ans[k+1] := ans[k+1] + su ) else skip)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (test (logical_test (comparison (expr (atom (number (integer 3))))))))) ]))))))))->display()); operation bfs(y : OclAny, x : OclAny) : OclAny pre: true post: true activity: var q : Sequence := () ; execute ((Sequence{y, x}) : q) ; bfs_map[y+1][x+1] := 0 ; var res : int := 0 ; var su : int := 1 ; while q do ( Sequence{y,x} := q->first() ; q := q->tail() ; for _tuple : d do (var _indx : int := 1; var dy : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dx : OclAny := _tuple->at(_indx); var y_ : OclAny := y + dy ; var x_ : OclAny := x + dx ; if 0 <= y_ & (y_ < h) & 0 <= x_ & (x_ < w) then ( res := res or f[s[y_+1][x_+1]+1] ; if bfs_map[y_+1][x_+1] then ( bfs_map[y_+1][x_+1] := 0 ; if not(f[s[y_+1][x_+1]+1]) then ( execute ((Sequence{y_, x_}) : q) ; su := su + 1 ) else skip ) else skip ) else skip)) ; return res, su; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=lambda x : x+(x**2)+(x**3) n=int(input()) print(a(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Function := lambda x : OclAny in (x + ((x)->pow(2)) + ((x)->pow(3))) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (a->apply(n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) ans=a+a**2+a**3 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := a + (a)->pow(2) + (a)->pow(3) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()); print(a-~ a*a*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); execute (a - MathLib.bitwiseNot(a) * a * a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) print(t+(t**2)+(t**3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (t + ((t)->pow(2)) + ((t)->pow(3)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,c=map(int,input().split()) timeperiod=list(map(int,input().split())) ctr=1 for i in range(1,n): if timeperiod[i]-c<=timeperiod[i-1]: ctr+=1 else : ctr=1 print(ctr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var timeperiod : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ctr : int := 1 ; for i : Integer.subrange(1, n-1) do ( if (timeperiod[i+1] - c->compareTo(timeperiod[i - 1+1])) <= 0 then ( ctr := ctr + 1 ) else ( ctr := 1 )) ; execute (ctr)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for i in range(int(input())): k=int(input()); print(100//math.gcd(100,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); execute (100 div (100)->gcd(k))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import Fraction for _ in range(int(input())): n=int(input()) print(Fraction(n,100).denominator) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (Fraction(n, 100).denominator)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd for _ in range(int(input())): print(100//gcd(int(input()),100)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (100 div gcd(("" + (((OclFile["System.in"]).readLine())))->toInteger(), 100))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* for i in range(int(input())): k=int(input()) w=100-k p=gcd(k,w) print(100//p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : double := 100 - k ; var p : OclAny := gcd(k, w) ; execute (100 div p)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math read=lambda : list(map(int,input().split())) t=int(input()) while t>0 : t-=1 ; n=int(input()) g=math.gcd(n,100) print(100//g) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( t := t - 1; ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var g : long := (n)->gcd(100) ; execute (100 div g)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(1000000) while True : w,h=map(int,input().split()) if w==0 : break mp=["X"+input()+"X" for _ in range(h)] mp.insert(0,"X"*(w+2)) mp.append("X"*(w+2)) visited_w=[[False]*(w+2)for _ in range(h+2)] visited_b=[[False]*(w+2)for _ in range(h+2)] vec=((0,1),(0,-1),(1,0),(-1,0)) def search(x,y,visited): for dx,dy in vec : nx,ny=x+dx,y+dy if not visited[ny][nx]and mp[ny][nx]=="." : visited[ny][nx]=True search(nx,ny,visited) for y in range(1,h+1): for x in range(1,w+1): if mp[y][x]=="W" : search(x,y,visited_w) elif mp[y][x]=="B" : search(x,y,visited_b) ans_w=ans_b=0 for y in range(1,h+1): for x in range(1,w+1): if visited_w[y][x]and not visited_b[y][x]: ans_w+=1 elif not visited_w[y][x]and visited_b[y][x]: ans_b+=1 print(ans_b,ans_w) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(1000000) ; while true do ( var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if w = 0 then ( break ) else skip ; var mp : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | ("X" + (OclFile["System.in"]).readLine() + "X")) ; mp := mp.insertAt(0+1, StringLib.nCopies("X", (w + 2))) ; execute ((StringLib.nCopies("X", (w + 2))) : mp) ; var visited_w : Sequence := Integer.subrange(0, h + 2-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ false }, (w + 2)))) ; var visited_b : Sequence := Integer.subrange(0, h + 2-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ false }, (w + 2)))) ; var vec : OclAny := Sequence{Sequence{0, 1}, Sequence{0, -1}, Sequence{1, 0}, Sequence{-1, 0}} ; skip ; for y : Integer.subrange(1, h + 1-1) do ( for x : Integer.subrange(1, w + 1-1) do ( if mp[y+1][x+1] = "W" then ( search(x, y, visited_w) ) else (if mp[y+1][x+1] = "B" then ( search(x, y, visited_b) ) else skip))) ; var ans_w : OclAny := 0; var ans_b : int := 0 ; for y : Integer.subrange(1, h + 1-1) do ( for x : Integer.subrange(1, w + 1-1) do ( if visited_w[y+1][x+1] & not(visited_b[y+1][x+1]) then ( ans_w := ans_w + 1 ) else (if not(visited_w[y+1][x+1]) & visited_b[y+1][x+1] then ( ans_b := ans_b + 1 ) else skip))) ; execute (ans_b)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) if k==1 : print(4) elif(k % 2==0): tmp=(k+2)//2 print(tmp**2) else : print((k+1)*(k+3)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if k = 1 then ( execute (4)->display() ) else (if (k mod 2 = 0) then ( var tmp : int := (k + 2) div 2 ; execute ((tmp)->pow(2))->display() ) else ( execute ((k + 1) * (k + 3) div 2)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(sys.stdin.readline().strip()) count=0 if n % 2==0 : count=(n//2+1)**2 else : count=(n//2+1)*(n//2+2)*2 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + ((sys.stdin.readLine()->trim())))->toInteger() ; var count : int := 0 ; if n mod 2 = 0 then ( count := ((n div 2 + 1))->pow(2) ) else ( count := (n div 2 + 1) * (n div 2 + 2) * 2 ) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) if n % 2==0 : ans=list(map(lambda x : x*x,[x for x in range(1,502)])) print(ans[n//2]) else : ans=list(map(lambda x : 2*(x*(x+1)),[x for x in range(1,501)])) print(ans[math.floor(n/2)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( var ans : Sequence := ((Integer.subrange(1, 502-1)->select(x | true)->collect(x | (x)))->collect( _x | (lambda x : OclAny in (x * x))->apply(_x) )) ; execute (ans[n div 2+1])->display() ) else ( ans := ((Integer.subrange(1, 501-1)->select(x | true)->collect(x | (x)))->collect( _x | (lambda x : OclAny in (2 * (x * (x + 1))))->apply(_x) )) ; execute (ans[(n / 2)->floor()+1])->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import queue import sys,math import heapq from collections import deque from bisect import bisect_left,bisect_right input=sys.stdin.readline pop=heapq.heappop push=heapq.heappush def ip(): return int(input()) def sp(): return str(input().rstrip()) def mip(): return map(int,input().split()) def mfp(): return map(float,input().split()) def msp(): return map(str,input().split()) def lmip(): return list(map(int,input().split())) def lmsp(): return list(map(str,input().split())) def gcd(x,y): while y : x,y=y,x % y return x def lcm(x,y): return x*y//gcd(x,y) def isPrime(x): if x<=1 : return False for i in range(2,int(x**0.5)+1): if x % i==0 : return False return True def getPow(a,x): ret=1 while x : if x & 1 : ret=(ret*a)% mod a=(a*a)% mod x>>=1 return ret n=ip() if n & 1 : print(2*(n//2+1)*(n//2+2)) else : print((n//2+1)**2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var pop : OclAny := heapq.heappop ; var push : OclAny := heapq.heappush ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := ip() ; if MathLib.bitwiseAnd(n, 1) then ( execute (2 * (n div 2 + 1) * (n div 2 + 2))->display() ) else ( execute (((n div 2 + 1))->pow(2))->display() ); operation ip() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation sp() : OclAny pre: true post: true activity: return ("" + ((input().rstrip()))); operation mip() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation mfp() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["double"])->apply(_x) ); operation msp() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["String"])->apply(_x) ); operation lmip() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation lmsp() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["String"])->apply(_x) )); operation gcd(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: while y do ( Sequence{x,y} := Sequence{y,x mod y}) ; return x; operation lcm(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return x * y div gcd(x, y); operation isPrime(x : OclAny) : OclAny pre: true post: true activity: if x <= 1 then ( return false ) else skip ; for i : Integer.subrange(2, ("" + (((x)->pow(0.5))))->toInteger() + 1-1) do ( if x mod i = 0 then ( return false ) else skip) ; return true; operation getPow(a : OclAny, x : OclAny) : OclAny pre: true post: true activity: var ret : int := 1 ; while x do ( if MathLib.bitwiseAnd(x, 1) then ( ret := (ret * a) mod mod ) else skip ; a := (a * a) mod mod ; x := x div (2->pow(1))) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math input=sys.stdin.readline INF=int(1e9)+7 MOD=998244353 def solve(): n=int(input()) if n % 2==0 : print((n//2+1)**2) else : a=n//2+1 print(a*(a+1)*2) t=1 for i in range(1,t+1): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var INF : int := ("" + ((("1e9")->toReal())))->toInteger() + 7 ; var MOD : int := 998244353 ; skip ; var t : int := 1 ; for i : Integer.subrange(1, t + 1-1) do ( solve()); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( execute (((n div 2 + 1))->pow(2))->display() ) else ( var a : int := n div 2 + 1 ; execute (a * (a + 1) * 2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) arr=[int(x)for x in input().split(' ')] arr.sort() ans=arr[2]-arr[0] for j in range(1,n-2): ans=min(ans,arr[j+2]-arr[j]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; arr := arr->sort() ; var ans : double := arr[2+1] - arr->first() ; for j : Integer.subrange(1, n - 2-1) do ( ans := Set{ans, arr[j + 2+1] - arr[j+1]}->min()) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for n in[*map(int,open(0))][1 :]:*r,=range(1,n+1); r[n % 2 : n-2]=r[n % 2 : n-2][: :-1]; print(*r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for n : (OclFile.newOclFile_Write(OclFile.newOclFile(0)))->collect( _x | (OclType["int"])->apply(_x) )->tail() do ((testlist_star_expr (star_expr * (expr (atom (name r)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name r)))) ,)} := Integer.subrange(1, n + 1-1); r.subrange(n mod 2+1, n - 2) := r.subrange(n mod 2+1, n - 2)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); execute ((argument * (test (logical_test (comparison (expr (atom (name r))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n=int(input()) if n % 2==0 : print(*range(n-2,0,-1),*range(n-1,n+1)) else : print(1,*range(n-2,1,-1),*range(n-1,n+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( execute ((argument * (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))->display() ) else ( execute (1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : n=int(input()) if n % 2==0 : k=n-2 while k>0 : print(k,end=" ") k=k-1 print(n-1,end=" ") print(n,end=" ") else : k=n-2 print(1,end=" ") while k>1 : print(k,end=" ") k=k-1 print(n-1,end=" ") print(n,end=" ") print() t=t-1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( var k : double := n - 2 ; while k > 0 do ( execute (k)->display() ; k := k - 1) ; execute (n - 1)->display() ; execute (n)->display() ) else ( k := n - 2 ; execute (1)->display() ; while k > 1 do ( execute (k)->display() ; k := k - 1) ; execute (n - 1)->display() ; execute (n)->display() ) ; execute (->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) l=[] if n % 2==0 : for i in range(n-2,0,-1): l.append(i) l.extend([n-1,n]) else : for i in range(n-2,3,-1): l.append(i) l.extend([1,2,3,n-1,n]) print(*l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; if n mod 2 = 0 then ( for i : Integer.subrange(0 + 1, n - 2)->reverse() do ( execute ((i) : l)) ; l := l->union(Sequence{n - 1}->union(Sequence{ n })) ) else ( for i : Integer.subrange(3 + 1, n - 2)->reverse() do ( execute ((i) : l)) ; l := l->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{n - 1}->union(Sequence{ n }))))) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name l))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import Counter sys.setrecursionlimit(2502) def paint(field,i,j,b,f,moves={(-1,0),(1,0),(0,1),(0,-1)}): fij=field[i][j] if fij & f : return if fij & 4 and not fij & b : return field[i][j]|=b | f for di,dj in moves : ni=i+di nj=j+dj if nj<0 or w<=nj or ni<0 or h<=ni : continue paint(field,ni,nj,b,f) buf=[] chardict={'.' : 0,'W' : 5,'B' : 6} while True : w,h=map(int,input().split()) if w==0 : break field=[] init_w,init_b=0,0 for _ in range(h): line=input().strip() init_w+=line.count('W') init_b+=line.count('B') field.append([chardict[c]for c in line]) for i in range(h): for j in range(w): fij=field[i][j] if fij & 4 and not fij & 24 : paint(field,i,j,fij & 3,(fij & 3)<<3) result=Counter(b & 3 for row in field for b in row) print(result[2]-init_b,result[1]-init_w) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit(2502) ; skip ; var buf : Sequence := Sequence{} ; var chardict : Map := Map{ '.' |-> 0 }->union(Map{ 'W' |-> 5 }->union(Map{ 'B' |-> 6 })) ; while true do ( var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if w = 0 then ( break ) else skip ; field := Sequence{} ; var init_w : OclAny := null; var init_b : OclAny := null; Sequence{init_w,init_b} := Sequence{0,0} ; for _anon : Integer.subrange(0, h-1) do ( var line : OclAny := input()->trim() ; init_w := init_w + line->count('W') ; init_b := init_b + line->count('B') ; execute ((line->select(c | true)->collect(c | (chardict[c+1]))) : field)) ; for i : Integer.subrange(0, h-1) do ( for j : Integer.subrange(0, w-1) do ( fij := field[i+1][j+1] ; if MathLib.bitwiseAnd(fij, 4) & not(MathLib.bitwiseAnd(fij, 24)) then ( paint(field, i, j, MathLib.bitwiseAnd(fij, 3), (MathLib.bitwiseAnd(fij, 3)) * (2->pow(3))) ) else skip)) ; var result : OclAny := Counter((argument (test (logical_test (comparison (expr (expr (atom (name b))) & (expr (atom (number (integer 3)))))))) (comp_for for (exprlist (expr (atom (name row)))) in (logical_test (comparison (expr (atom (name field))))) (comp_iter (comp_for for (exprlist (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name row)))))))))) ; execute (result[2+1] - init_b)->display()); operation paint(field : OclAny, i : OclAny, j : OclAny, b : OclAny, f : OclAny, moves : OclAny) pre: true post: true activity: if moves->oclIsUndefined() then moves := Set{Sequence{-1, 0}}->union(Set{Sequence{1, 0}}->union(Set{Sequence{0, 1}}->union(Set{ Sequence{0, -1} }))) else skip; var fij : OclAny := field[i+1][j+1] ; if MathLib.bitwiseAnd(fij, f) then ( return ) else skip ; if MathLib.bitwiseAnd(fij, 4) & not(MathLib.bitwiseAnd(fij, b)) then ( return ) else skip ; field[i+1][j+1] := field[i+1][j+1] or MathLib.bitwiseOr(b, f) ; for _tuple : moves do (var _indx : int := 1; var di : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dj : OclAny := _tuple->at(_indx); var ni : OclAny := i + di ; var nj : OclAny := j + dj ; if nj < 0 or (w->compareTo(nj)) <= 0 or ni < 0 or (h->compareTo(ni)) <= 0 then ( continue ) else skip ; paint(field, ni, nj, b, f)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) if(n==1): print("1") elif(n==3): print("1 2 3") elif(n % 2==0): out=list(range(n-2,0,-1)) out+=[n-1,n] print(*out) else : out=[1,2,3]+list(range(n-2,3,-1)) out+=[n-1,n] print(*out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n = 1) then ( execute ("1")->display() ) else (if (n = 3) then ( execute ("1 2 3")->display() ) else (if (n mod 2 = 0) then ( var out : Sequence := (Integer.subrange(0 + 1, n - 2)->reverse()) ; out := out + Sequence{n - 1}->union(Sequence{ n }) ; execute ((argument * (test (logical_test (comparison (expr (atom (name out))))))))->display() ) else ( out := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))->union((Integer.subrange(3 + 1, n - 2)->reverse())) ; out := out + Sequence{n - 1}->union(Sequence{ n }) ; execute ((argument * (test (logical_test (comparison (expr (atom (name out))))))))->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : t-=1 n=int(input()) j=1 for i in range(n): print(j,end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( t := t - 1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var j : int := 1 ; for i : Integer.subrange(0, n-1) do ( execute (j)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): print(*[1 for i in range(int(input()))]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))) )))))))) ])))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) print(*[1 for i in range(n)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) ])))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=eval(input()) for i in range(t): n=eval(input()) output_list=[] j=1 while j<(n+1): if(j+1)<=n : output_list.extend([f"{j}",f"{j}"]) else : output_list.append(f"{j}") j+=2 print(" ".join(output_list)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := (OclFile["System.in"]).readLine() ; var output_list : Sequence := Sequence{} ; var j : int := 1 ; while (j->compareTo((n + 1))) < 0 do ( if ((j + 1)->compareTo(n)) <= 0 then ( output_list := output_list->union(Sequence{StringLib.formattedString("{j}")}->union(Sequence{ StringLib.formattedString("{j}") })) ) else ( execute ((StringLib.formattedString("{j}")) : output_list) ) ; j := j + 2) ; execute (StringLib.sumStringsWithSeparator((output_list), " "))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=eval(input()) for i in range(t): n=eval(input()) output_list=[] j=1 while j<(n+1): output_list.append("1") j+=1 print(" ".join(output_list)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := (OclFile["System.in"]).readLine() ; var output_list : Sequence := Sequence{} ; var j : int := 1 ; while (j->compareTo((n + 1))) < 0 do ( execute (("1") : output_list) ; j := j + 1) ; execute (StringLib.sumStringsWithSeparator((output_list), " "))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) a=sorted(a) ans=1000000001 for i in range(1,len(a)-1): x=abs(a[i]-a[i-1])+abs(a[i]-a[i+1]) ans=min(ans,x) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var ans : int := 1000000001 ; for i : Integer.subrange(1, (a)->size() - 1-1) do ( var x : double := (a[i+1] - a[i - 1+1])->abs() + (a[i+1] - a[i + 1+1])->abs() ; ans := Set{ans, x}->min()) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) if n==2 : print(2) else : print(1)if n % 2 else print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 2 then ( execute (2)->display() ) else ( (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))) if (logical_test (comparison (expr (expr (atom (name n))) % (expr (atom (number (integer 2))))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))))))) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) if n==2 : print(2) elif n % 2==0 : print(0) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 2 then ( execute (2)->display() ) else (if n mod 2 = 0 then ( execute (0)->display() ) else ( execute (1)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for j in range(t): n=int(input()) if n==2 : print(2) elif n % 2==1 : print(1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 2 then ( execute (2)->display() ) else (if n mod 2 = 1 then ( execute (1)->display() ) else ( execute (0)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque dxs=[1,0,-1,0] dys=[0,1,0,-1] def bfs(x,y,c): q=deque([(x,y)]) while q : x,y=q.popleft() for dx,dy in zip(dxs,dys): nx,ny=x+dx,y+dy if nx<0 or nx>=W or ny<0 or ny>=H : continue if src[ny][nx]!='.' or mem[c][ny][nx]: continue q.append((nx,ny)) mem[c][ny][nx]=1 while True : W,H=map(int,input().split()) if W==0 : break src=[input()for i in range(H)] mem=[[[0 for w in range(W)]for h in range(H)]for c in range(2)] for y in range(H): for x in range(W): if src[y][x]=='.' : continue c=(0 if src[y][x]=='B' else 1) bfs(x,y,c) b=w=0 for y in range(H): for x in range(W): bm,wm=mem[0][y][x],mem[1][y][x] if bm and not wm : b+=1 elif wm and not bm : w+=1 print(str(b)+' '+str(w)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var dxs : Sequence := Sequence{1}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{ 0 }))) ; var dys : Sequence := Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ -1 }))) ; skip ; while true do ( var W : OclAny := null; var H : OclAny := null; Sequence{W,H} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if W = 0 then ( break ) else skip ; var src : Sequence := Integer.subrange(0, H-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var mem : Sequence := Integer.subrange(0, 2-1)->select(c | true)->collect(c | (Integer.subrange(0, H-1)->select(h | true)->collect(h | (Integer.subrange(0, W-1)->select(w | true)->collect(w | (0)))))) ; for y : Integer.subrange(0, H-1) do ( for x : Integer.subrange(0, W-1) do ( if src[y+1][x+1] = '.' then ( continue ) else skip ; c := (if src[y+1][x+1] = 'B' then 0 else 1 endif) ; bfs(x, y, c))) ; var b : OclAny := 0; var w : int := 0 ; for y : Integer.subrange(0, H-1) do ( for x : Integer.subrange(0, W-1) do ( var bm : OclAny := null; var wm : OclAny := null; Sequence{bm,wm} := Sequence{mem->first()[y+1][x+1],mem[1+1][y+1][x+1]} ; if bm & not(wm) then ( b := b + 1 ) else (if wm & not(bm) then ( w := w + 1 ) else skip))) ; execute (("" + ((b))) + ' ' + ("" + ((w))))->display()); operation bfs(x : OclAny, y : OclAny, c : OclAny) pre: true post: true activity: var q : Sequence := (Sequence{ Sequence{x, y} }) ; while q do ( Sequence{x,y} := q->first() ; q := q->tail() ; for _tuple : Integer.subrange(1, dxs->size())->collect( _indx | Sequence{dxs->at(_indx), dys->at(_indx)} ) do (var _indx : int := 1; var dx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dy : OclAny := _tuple->at(_indx); var nx : OclAny := null; var ny : OclAny := null; Sequence{nx,ny} := Sequence{x + dx,y + dy} ; if nx < 0 or (nx->compareTo(W)) >= 0 or ny < 0 or (ny->compareTo(H)) >= 0 then ( continue ) else skip ; if src[ny+1][nx+1] /= '.' or mem[c+1][ny+1][nx+1] then ( continue ) else skip ; execute ((Sequence{nx, ny}) : q) ; mem[c+1][ny+1][nx+1] := 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in[*open(0)][1 :]: i=int(i); print(i % 2 if i>4 else 4-i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var i : int := ("" + ((i)))->toInteger(); execute (if i > 4 then i mod 2 else 4 - i endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): x=int(input()) if(x % 2==1): print(1) else : if(x==2): print(2) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (x mod 2 = 1) then ( execute (1)->display() ) else ( if (x = 2) then ( execute (2)->display() ) else ( execute (0)->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=pow(8,n,10) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : double := (8)->pow(n) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) no=pow(1378,num,10) print(no) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var no : double := (1378)->pow(num) ; execute (no)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(pow(1378,n,10)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((1378)->pow(n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==0 : print(1) elif n % 4==1 : print(8) elif n % 4==2 : print(4) elif n % 4==3 : print(2) else : print(6) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( execute (1)->display() ) else (if n mod 4 = 1 then ( execute (8)->display() ) else (if n mod 4 = 2 then ( execute (4)->display() ) else (if n mod 4 = 3 then ( execute (2)->display() ) else ( execute (6)->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=n % 4 if n==0 : print(1) elif x==1 : print(8) elif x==2 : print(4) elif x==3 : print(2) else : print(6) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := n mod 4 ; if n = 0 then ( execute (1)->display() ) else (if x = 1 then ( execute (8)->display() ) else (if x = 2 then ( execute (4)->display() ) else (if x = 3 then ( execute (2)->display() ) else ( execute (6)->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- test_case=int(input()) for test in range(test_case): num_sticks=int(input()) stick_ls=[] my_list=input().split() stick_ls=[int(item)for item in my_list] stick_ls.sort() total_min_len=[] for i in range(0,num_sticks-2): max_len=stick_ls[i+2] min_len=stick_ls[i] total_min_len.append(max_len-min_len) print(min(total_min_len)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var test_case : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for test : Integer.subrange(0, test_case-1) do ( var num_sticks : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var stick_ls : Sequence := Sequence{} ; var my_list : OclAny := input().split() ; stick_ls := my_list->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; stick_ls := stick_ls->sort() ; var total_min_len : Sequence := Sequence{} ; for i : Integer.subrange(0, num_sticks - 2-1) do ( var max_len : OclAny := stick_ls[i + 2+1] ; var min_len : OclAny := stick_ls[i+1] ; execute ((max_len - min_len) : total_min_len)) ; execute ((total_min_len)->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=int(input()) if m<=2 : print(-1) else : print("2 "*(m-1)+"1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if m <= 2 then ( execute (-1)->display() ) else ( execute (StringLib.nCopies("2 ", (m - 1)) + "1")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n<=2 : print(-1) else : for i in range(2,n+1): print(i,end=' ') print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n <= 2 then ( execute (-1)->display() ) else ( for i : Integer.subrange(2, n + 1-1) do ( execute (i)->display()) ; execute (1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) l=[] d={} for i in range(n): l+=[input()] d[l[i]]=i z=list(l) for i in range(m-1,-1,-1): if i % 2==0 : l.sort(key=lambda x : x[i]) else : l.sort(reverse=True,key=lambda x : x[i]) for i in l : print(d[i]+1,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := Sequence{} ; var d : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( l := l + Sequence{ (OclFile["System.in"]).readLine() } ; d[l[i+1]+1] := i) ; var z : Sequence := (l) ; for i : Integer.subrange(-1 + 1, m - 1)->reverse() do ( if i mod 2 = 0 then ( l := l->sort() ) else ( l := l->sort() )) ; for i : l do ( execute (d[i+1] + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n<3 : print(-1) else : print("3 2 1",end="") print(" 1"*(n-3),end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n < 3 then ( execute (-1)->display() ) else ( execute ("3 2 1")->display() ) ; execute (StringLib.nCopies(" 1", (n - 3)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(-1 if n<=2 else "2 3 "+"1 "*(n-2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (if n <= 2 then -1 else "2 3 " + StringLib.nCopies("1 ", (n - 2)) endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(-1)if n<=2 else print(*[i for i in range(n,0,-1)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))) if (logical_test (comparison (comparison (expr (atom (name n)))) <= (comparison (expr (atom (number (integer 2))))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))) ]))))))) )))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- z=int(input()) die_Zahlen=[int(i)for i in input().split()] gesamt=sum(die_Zahlen) if(gesamt % z==0): print(z) else : print(z-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var z : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var die_Zahlen : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var gesamt : OclAny := (die_Zahlen)->sum() ; if (gesamt mod z = 0) then ( execute (z)->display() ) else ( execute (z - 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) A=list(map(int,input().split())) sm=abs(sum(A)) print(max(n-sm % n,n-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sm : double := ((A)->sum())->abs() ; execute (Set{n - sm mod n, n - 1}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) x=sum(arr) if x % n==0 : print(n) else : print(n-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := (arr)->sum() ; if x mod n = 0 then ( execute (n)->display() ) else ( execute (n - 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- number=int(input()) list_numbers=list(map(int,input().split())) total=sum(list_numbers) if total % number==0 : print(number) else : print(number-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var number : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var list_numbers : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var total : OclAny := (list_numbers)->sum() ; if total mod number = 0 then ( execute (number)->display() ) else ( execute (number - 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- number=int(input()) number_list=list(map(int,input().split())) total=sum(number_list) if total % number==0 : print(number) else : print(number-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var number : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var number_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var total : OclAny := (number_list)->sum() ; if total mod number = 0 then ( execute (number)->display() ) else ( execute (number - 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import inf for i in range(int(input())): n=int(input()) arr=list(map(int,input().split())) mini=inf arr.sort() for i in range(1,len(arr)-1): mini=min(mini,arr[i]-arr[i-1]+arr[i+1]-arr[i]) print(mini) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mini : double := Math_PINFINITY ; arr := arr->sort() ; for i : Integer.subrange(1, (arr)->size() - 1-1) do ( mini := Set{mini, arr[i+1] - arr[i - 1+1] + arr[i + 1+1] - arr[i+1]}->min()) ; execute (mini)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==0 : print(1) elif n==1 : print(2) elif n==2 : print(1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( execute (1)->display() ) else (if n = 1 then ( execute (2)->display() ) else (if n = 2 then ( execute (1)->display() ) else ( execute (0)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for x in range(int(input())): a=int(input()) if a>59 and 360 %(180-a)==0 : print('YES') else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for x : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if a > 59 & 360 mod (180 - a) = 0 then ( execute ('YES')->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 dd=[(0,-1),(1,0),(0,1),(-1,0)] ddn=[(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)] def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] while True : n=I() r=0 if n==0 or n==2 : r=1 elif n==1 : r=2 rr.append(r) break return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; var dd : Sequence := Sequence{Sequence{0, -1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{ Sequence{-1, 0} }))) ; var ddn : Sequence := Sequence{Sequence{0, -1}}->union(Sequence{Sequence{1, -1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{1, 1}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{-1, -1}}->union(Sequence{Sequence{-1, 0}}->union(Sequence{ Sequence{-1, 1} }))))))) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var n : OclAny := I() ; var r : int := 0 ; if n = 0 or n = 2 then ( r := 1 ) else (if n = 1 then ( r := 2 ) else skip) ; execute ((r) : rr) ; break) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans=[1,2,1,0] n=int(input()) if n>2 : n=3 print(ans[n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ans : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{ 0 }))) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n > 2 then ( n := 3 ) else skip ; execute (ans[n+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print([1,2,1,0][[n,3][n>3]]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{ 0 })))[Sequence{n}->union(Sequence{ 3 })->select(n > 3)+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==0 or n==2 : print(1) else : print(2 if n==1 else 0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 or n = 2 then ( execute (1)->display() ) else ( execute (if n = 1 then 2 else 0 endif)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : n=int(input()) print(2,n-1) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (2)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): p=int(input()) print("2"+" "+str(p-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var p : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ("2" + " " + ("" + ((p - 1))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): j=int(input()) print("2 "+str(j-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var j : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ("2 " + ("" + ((j - 1))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) vet=[] while(n>0): aux=int(input()) vet.append(f'2{aux-1}') n-=1 print(*vet,sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var vet : Sequence := Sequence{} ; while (n > 0) do ( var aux : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((StringLib.formattedString('2{aux-1}')) : vet) ; n := n - 1) ; execute ((argument * (test (logical_test (comparison (expr (atom (name vet))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): j=int(input()) print(2,j-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var j : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) a=list(map(int,input().split())) a.sort() ans=float('inf') for j in range(n-2): tmp=a[j+1]-a[j]+a[j+2]-a[j+1] if tmptoInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var ans : double := ("" + (('inf')))->toReal() ; for j : Integer.subrange(0, n - 2-1) do ( var tmp : double := a[j + 1+1] - a[j+1] + a[j + 2+1] - a[j + 1+1] ; if (tmp->compareTo(ans)) < 0 then ( ans := tmp ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : a=int(input()) if 360 %(180-a)==0 : print("YES") else : print("NO") t=t-1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if 360 mod (180 - a) = 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- nin=[] for i in range(int(input())): s=input() nin.append(s) print(nin.count("E869120")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var nin : Sequence := Sequence{} ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; execute ((s) : nin)) ; execute (nin->count("E869120"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import* from bisect import* from math import* from collections import* from heapq import* from random import* import sys sys.setrecursionlimit(10**6) int1=lambda x : int(x)-1 p2D=lambda x : print(*x,sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int,sys.stdin.readline().split()) def MI1(): return map(int1,sys.stdin.readline().split()) def MF(): return map(float,sys.stdin.readline().split()) def LI(): return list(map(int,sys.stdin.readline().split())) def LI1(): return list(map(int1,sys.stdin.readline().split())) def LF(): return list(map(float,sys.stdin.readline().split())) def LLI(rows_number): return[LI()for _ in range(rows_number)] dij=[(1,0),(0,1),(-1,0),(0,-1)] def main(): n=II() ss=[input()for _ in range(n)] cnt=Counter(ss) print(cnt["E869120"]) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(6)) ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; var p2D : Function := lambda x : OclAny in (((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var dij : Sequence := Sequence{Sequence{1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{-1, 0}}->union(Sequence{ Sequence{0, -1} }))) ; skip ; main(); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation MI1() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (int1)->apply(_x) ); operation MF() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LI1() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (int1)->apply(_x) )); operation LF() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) )); operation LLI(rows_number : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows_number-1)->select(_anon | true)->collect(_anon | (LI())); operation main() pre: true post: true activity: var n : OclAny := II() ; var ss : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var cnt : OclAny := Counter(ss) ; execute (cnt->at("E869120"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def num(): return int(input()) def nums(): return list(map(int,input().split())) N=num() members=[] for i in range(N): members.append(input()) ans=members.count("E869120") print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := num() ; var members : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute (((OclFile["System.in"]).readLine()) : members)) ; var ans : int := members->count("E869120") ; execute (ans)->display(); operation num() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation nums() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=[input()for i in range(n)] count=0 for i in s : if i=='E869120' : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var count : int := 0 ; for i : s do ( if i = 'E869120' then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline N=int(input()) ANS=0 for i in range(N): if input().strip()=="E869120" : ANS+=1 print(ANS) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ANS : int := 0 ; for i : Integer.subrange(0, N-1) do ( if input()->trim() = "E869120" then ( ANS := ANS + 1 ) else skip) ; execute (ANS)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,i=map(int,input().split()) print(n-i+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var i : OclAny := null; Sequence{n,i} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (n - i + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,i=map(int,input().split()) ans=n-i+1 print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var i : OclAny := null; Sequence{n,i} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : double := n - i + 1 ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main()->None : A,B=map(int,input().split()) print(A-B+1) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() : OclAny pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (A - B + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def actual(n,i): return n-i+1 n,i=map(int,input().split()) print(actual(n,i)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{n,i} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (actual(n, i))->display(); operation actual(n : OclAny, i : OclAny) : OclAny pre: true post: true activity: return n - i + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,i=[int(i)for i in input().split()] print(n-i+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var i : OclAny := null; Sequence{n,i} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute (n - i + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isint(x): if x==int(x): return True elif x!=int(x): return False n=int(input()) for i in range(n): a=int(input()) n=360/(180-a) if n>=3 and isint(n)==True : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; n := 360 / (180 - a) ; if n >= 3 & isint(n) = true then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); operation isint(x : OclAny) : OclAny pre: true post: true activity: if x = ("" + ((x)))->toInteger() then ( return true ) else (if x /= ("" + ((x)))->toInteger() then ( return false ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque m=4 n=3 def Maze(matrix): q=deque() q.append((0,0)) count=0 while(len(q)>0): p=q.popleft() if(p[0]==n-1 and p[1]==m-1): count+=1 if(p[0]+1union(Sequence{0}->union(Sequence{0}->union(Sequence{ 1 })))}->union(Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })))}->union(Sequence{ Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 1 }))) })) ; execute (Maze(matrix))->display(); operation Maze(matrix : OclAny) : OclAny pre: true post: true activity: var q : Sequence := () ; execute ((Sequence{0, 0}) : q) ; var count : int := 0 ; while ((q)->size() > 0) do ( var p : OclAny := q->first() ; q := q->tail() ; if (p->first() = n - 1 & p[1+1] = m - 1) then ( count := count + 1 ) else skip ; if ((p->first() + 1->compareTo(n)) < 0 & matrix[p->first() + 1+1][p[1+1]+1] = 1) then ( execute ((Sequence{p->first() + 1, p[1+1]}) : q) ) else skip ; if ((p[1+1] + 1->compareTo(m)) < 0 & matrix[p->first()+1][p[1+1] + 1+1] = 1) then ( execute ((Sequence{p->first(), p[1+1] + 1}) : q) ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input())*2 print(t//60,t % 60) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() * 2 ; execute (t div 60)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print((lambda x : '{}{}'.format(x//30,(x % 30)*2))(int(input()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((lambda x : OclAny in (StringLib.interpolateStrings('{}{}', Sequence{x div 30, (x mod 30) * 2})))(("" + (((OclFile["System.in"]).readLine())))->toInteger()))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin n=int(stdin.readline().rstrip()) h=n*2//60 m=n*2 % 60 print("{}{}".format(h,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + ((stdin.readLine().rstrip())))->toInteger() ; var h : int := n * 2 div 60 ; var m : int := n * 2 mod 60 ; execute (StringLib.interpolateStrings("{}{}", Sequence{h, m}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=float(input()) m=n*2 hour=int(m//60) minutes=int(m % 60) print(hour,minutes) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; var m : double := n * 2 ; var hour : int := ("" + ((m div 60)))->toInteger() ; var minutes : int := ("" + ((m mod 60)))->toInteger() ; execute (hour)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(*divmod(int(input())*2,60)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((argument * (test (logical_test (comparison (expr (atom (name divmod)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) )))) * (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 60))))))))) )))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(sum(eval(input().replace(' ','-'))<-1 for _ in ' '*int(input()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (((argument (test (logical_test (comparison (comparison (expr (atom (name eval)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name replace) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ' ')))))) , (argument (test (logical_test (comparison (expr (atom '-'))))))) ))))))))) ))))) < (comparison (expr (atom - (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (expr (atom ' ')) * (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) num=0 for i in range(a): m,n=map(int,input().split()) if n-m>=2 : num+=1 print(num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var num : int := 0 ; for i : Integer.subrange(0, a-1) do ( var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n - m >= 2 then ( num := num + 1 ) else skip) ; execute (num)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) count=0 for i in range(n): p,q=input().split() if int(q)-int(p)>=2 : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := input().split() ; if ("" + ((q)))->toInteger() - ("" + ((p)))->toInteger() >= 2 then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(int(input())) x=[] y=[] counter=0 for i in range(0,n): a,b=map(int,input().split()) x.append(a) y.append(b) for i in range(0,n): if y[i]-x[i]>=2 : counter+=1 print(counter) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + ((("" + (((OclFile["System.in"]).readLine())))->toInteger())))->toInteger() ; var x : Sequence := Sequence{} ; var y : Sequence := Sequence{} ; var counter : int := 0 ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a) : x) ; execute ((b) : y)) ; for i : Integer.subrange(0, n-1) do ( if y[i+1] - x[i+1] >= 2 then ( counter := counter + 1 ) else skip) ; execute (counter)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for x in range(t): a=int(input()) if 360 %(180-a)==0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for x : Integer.subrange(0, t-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if 360 mod (180 - a) = 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input("")) count=0 for i in range(n): cap=input("").split(" ") diff=int(cap[1])-int(cap[0]) if diff>=2 : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine(""))))->toInteger() ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( var cap : OclAny := input("").split(" ") ; var diff : double := ("" + ((cap[1+1])))->toInteger() - ("" + ((cap->first())))->toInteger() ; if diff >= 2 then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def isPerfectSquare(num): n=int(math.sqrt(num)) return(n*n==num) def checkFib(array,n): count=0 for i in range(n): if(isPerfectSquare(5*array[i]*array[i]+4)or isPerfectSquare(5*array[i]*array[i]-4)): print(array[i],"",end=""); count=count+1 if(count==0): print("None present"); array=[4,2,8,5,20,1,40,13,23] n=len(array) checkFib(array,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; array := Sequence{4}->union(Sequence{2}->union(Sequence{8}->union(Sequence{5}->union(Sequence{20}->union(Sequence{1}->union(Sequence{40}->union(Sequence{13}->union(Sequence{ 23 })))))))) ; n := (array)->size() ; checkFib(array, n); operation isPerfectSquare(num : OclAny) : OclAny pre: true post: true activity: var n : int := ("" + (((num)->sqrt())))->toInteger() ; return (n * n = num); operation checkFib(array : OclAny, n : OclAny) pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (isPerfectSquare(5 * array[i+1] * array[i+1] + 4) or isPerfectSquare(5 * array[i+1] * array[i+1] - 4)) then ( execute (array[i+1])->display(); ; count := count + 1 ) else skip) ; if (count = 0) then ( execute ("None present")->display(); ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=input() n=int(N[-1]) if n in[2,4,5,7,9]: print("hon") elif n in[0,1,6,8]: print("pon") else : print("bon") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : String := (OclFile["System.in"]).readLine() ; var n : int := ("" + ((N->last())))->toInteger() ; if (Sequence{2}->union(Sequence{4}->union(Sequence{5}->union(Sequence{7}->union(Sequence{ 9 })))))->includes(n) then ( execute ("hon")->display() ) else (if (Sequence{0}->union(Sequence{1}->union(Sequence{6}->union(Sequence{ 8 }))))->includes(n) then ( execute ("pon")->display() ) else ( execute ("bon")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=iter(sys.stdin.readlines()).next def main(): N=int(input()) if N % 10 in[2,4,5,7,9]: res='hon' elif N % 10 in[0,1,6,8]: res='pon' else : res='bon' print(res) return 0 if __name__=='__main__' : sys.setrecursionlimit(10000) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := iter((OclFile["System.in"]).readlines()).next ; skip ; if __name__ = '__main__' then ( sys.setrecursionlimit(10000) ; main() ) else skip; operation main() : OclAny pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (Sequence{2}->union(Sequence{4}->union(Sequence{5}->union(Sequence{7}->union(Sequence{ 9 })))))->includes(N mod 10) then ( var res : String := 'hon' ) else (if (Sequence{0}->union(Sequence{1}->union(Sequence{6}->union(Sequence{ 8 }))))->includes(N mod 10) then ( res := 'pon' ) else ( res := 'bon' ) ) ; execute (res)->display() ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) while N>=100 : N-=100 while N>=10 : N-=10 if N==3 : print('bon') elif N==0 or N==1 or N==6 or N==8 : print('pon') else : print('hon') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while N >= 100 do ( N := N - 100) ; while N >= 10 do ( N := N - 10) ; if N = 3 then ( execute ('bon')->display() ) else (if N = 0 or N = 1 or N = 6 or N = 8 then ( execute ('pon')->display() ) else ( execute ('hon')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) ans=0 if N>10 : ans=N-(int(N/10)*10) else : ans=N if ans==3 : print('bon') elif ans==0 or ans==1 or ans==6 or ans==8 : print('pon') else : print('hon') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; if N > 10 then ( ans := N - (("" + ((N / 10)))->toInteger() * 10) ) else ( ans := N ) ; if ans = 3 then ( execute ('bon')->display() ) else (if ans = 0 or ans = 1 or ans = 6 or ans = 8 then ( execute ('pon')->display() ) else ( execute ('hon')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=list(input()) N=int(N[-1]) if N==2 : print('hon') elif N==4 : print('hon') elif N==5 : print('hon') elif N==7 : print('hon') elif N==9 : print('hon') elif N==0 : print('pon') elif N==1 : print('pon') elif N==6 : print('pon') elif N==8 : print('pon') else : print('bon') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : Sequence := ((OclFile["System.in"]).readLine())->characters() ; N := ("" + ((N->last())))->toInteger() ; if N = 2 then ( execute ('hon')->display() ) else (if N = 4 then ( execute ('hon')->display() ) else (if N = 5 then ( execute ('hon')->display() ) else (if N = 7 then ( execute ('hon')->display() ) else (if N = 9 then ( execute ('hon')->display() ) else (if N = 0 then ( execute ('pon')->display() ) else (if N = 1 then ( execute ('pon')->display() ) else (if N = 6 then ( execute ('pon')->display() ) else (if N = 8 then ( execute ('pon')->display() ) else ( execute ('bon')->display() ) ) ) ) ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=map(int,input().split()) if t<(10**n): print(10**(n-1)-((10**(n-1))% t)+t) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (t->compareTo(((10)->pow(n)))) < 0 then ( execute ((10)->pow((n - 1)) - (((10)->pow((n - 1))) mod t) + t)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math input1,input2=input().split() input1=int(input1) input2=int(input2) digits=math.floor(math.log(input2,10))+1 if(digits>input1): print(-1) else : print(input2*pow(10,input1-digits)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input1 : OclAny := null; var input2 : OclAny := null; Sequence{input1,input2} := input().split() ; var input1 : int := ("" + ((input1)))->toInteger() ; var input2 : int := ("" + ((input2)))->toInteger() ; var digits : double := ((input2, 10)->log())->floor() + 1 ; if ((digits->compareTo(input1)) > 0) then ( execute (-1)->display() ) else ( execute (input2 * (10)->pow(input1 - digits))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import random import sys girdi=input().split() hane=girdi[0] n=girdi[0] bolme=girdi[1] t=girdi[1] i=1 a=1 while ifirst() ; var n : OclAny := girdi->first() ; var bolme : OclAny := girdi[1+1] ; var t : OclAny := girdi[1+1] ; var i : int := 1 ; var a : int := 1 ; while (i->compareTo(("" + ((n)))->toInteger() + 10000)) < 0 do ( if (("" + ((n)))->toInteger()->compareTo((t)->size())) < 0 then ( execute ("-1")->display() ; sys.exit() ) else ( var u : int := 0 ; if bolme /= "10" then ( while (u->compareTo(("" + ((n)))->toInteger())) < 0 do ( execute (bolme)->display() ; u := u + 1) ; sys.exit() ) else ( u := 1 ; execute ("1")->display() ; while (u->compareTo(("" + ((n)))->toInteger())) < 0 do ( execute ("0")->display() ; u := u + 1) ; sys.exit() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=int(input()) for i in range(m): a=int(input()) b=360 %(180-a) if a>=60 and b==0 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, m-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := 360 mod (180 - a) ; if a >= 60 & b = 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=[int(i)for i in input().split()] x=10**(n[0]-1) while x<=10**(n[0]-1)+n[1]: if x % n[1]==0 : break x+=1 if 10**n[0]-1select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var x : double := (10)->pow((n->first() - 1)) ; while (x->compareTo((10)->pow((n->first() - 1)) + n[1+1])) <= 0 do ( if x mod n[1+1] = 0 then ( break ) else skip ; x := x + 1) ; if ((10)->pow(n->first()) - 1->compareTo(n[1+1])) < 0 then ( x := -1 ) else skip ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=list(map(int,input().split())) if n==1 and t==10 : print(-1) elif n>=2 and t==10 : for i in range(1,n): print(1,end='') print(0) else : for i in range(1,n+1): print(t,end='') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = 1 & t = 10 then ( execute (-1)->display() ) else (if n >= 2 & t = 10 then ( for i : Integer.subrange(1, n-1) do ( execute (1)->display()) ; execute (0)->display() ) else ( for i : Integer.subrange(1, n + 1-1) do ( execute (t)->display()) ; execute (->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNthNumber(A,B,N): sum=0 for i in range(2,N): sum=A+B A=B B=sum return sum if __name__=='__main__' : A=5 B=7 N=10 print(findNthNumber(A,B,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( A := 5 ; B := 7 ; N := 10 ; execute (findNthNumber(A, B, N))->display() ) else skip; operation findNthNumber(A : OclAny, B : OclAny, N : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(2, N-1) do ( sum := A + B ; A := B ; B := sum) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) print((n//2)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((n div 2) + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) print(n//2+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n div 2 + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) print(n//2+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n div 2 + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: print(int(s)//2+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( execute (("" + ((s)))->toInteger() div 2 + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): print((int(input())//2)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger() div 2) + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in[0]*int(input()): n=int(input()) print([-1,'4'+'7'*(n-1)][n>1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (Sequence{-1}->union(Sequence{ '4' + StringLib.nCopies('7', (n - 1)) })->select(n > 1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) if n==1 : print(-1) else : print('2'+'3'*(n-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (-1)->display() ) else ( execute ('2' + StringLib.nCopies('3', (n - 1)))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) ans=0 l=n i=1 while l>0 : k=i*(i+1)//2 l_n=n//(i+1) ans+=k*(l*(l+1)//2-l_n*(l_n+1)//2) l=l_n i+=1 print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; var l : int := n ; var i : int := 1 ; while l > 0 do ( var k : int := i * (i + 1) div 2 ; var l_n : int := n div (i + 1) ; ans := ans + k * (l * (l + 1) div 2 - l_n * (l_n + 1) div 2) ; l := l_n ; i := i + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib,fractions,math def compute(): NUM_COLORS=7 BALLS_PER_COLOR=10 NUM_PICKED=20 DECIMALS=9 numerator=[0] def explore(remain,limit,history): if remain==0 : hist=list(history) while len(hist)display() ) else skip; operation compute() : OclAny pre: true post: true activity: var NUM_COLORS : int := 7 ; var BALLS_PER_COLOR : int := 10 ; var NUM_PICKED : int := 20 ; var DECIMALS : int := 9 ; var numerator : Sequence := Sequence{ 0 } ; skip ; explore(NUM_PICKED, BALLS_PER_COLOR, Sequence{}) ; var denominator : OclAny := eulerlib.binomial(NUM_COLORS * BALLS_PER_COLOR, NUM_PICKED) ; var ans : OclAny := fractions.Fraction(numerator->first(), denominator) ; return format_fraction(ans, DECIMALS); operation format_fraction(val : OclAny, digits : OclAny) : OclAny pre: true post: true activity: if digits <= 0 then ( error IncorrectElementException.newIncorrectElementException() ) else skip ; if val < 0 then ( return "-" + format_fraction(-val, digits) ) else skip ; var s : OclAny := OclType["String"]((val * (10)->pow(digits))->round()).zfill(digits + 1) ; return StringLib.formattedString("{s[:-digits]}.{s[-digits:]}"); operation divide_exactly(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if x mod y /= 0 then ( error IncorrectElementException.newIncorrectElementException("Not divisible") ) else skip ; return x div y; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) if n<=1 : print(-1) else : ans="2"+"3"*(n-1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n <= 1 then ( execute (-1)->display() ) else ( var ans : String := "2" + StringLib.nCopies("3", (n - 1)) ; execute (ans)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nummaker(n): if n==1 : return-1 if n==2 : return 23 return "23"+"3"*(n-2) for _ in range(int(input())): print(nummaker(int(input()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (nummaker(("" + (((OclFile["System.in"]).readLine())))->toInteger()))->display()); operation nummaker(n : OclAny) : OclAny pre: true post: true activity: if n = 1 then ( return -1 ) else skip ; if n = 2 then ( return 23 ) else skip ; return "23" + StringLib.nCopies("3", (n - 2)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) if n==1 : print(-1) else : print('2'+'9'*(n-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (-1)->display() ) else ( execute ('2' + StringLib.nCopies('9', (n - 1)))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findElement(arr,size): right_mul=1 ; left_mul=1 ; for i in range(1,size): right_mul=right_mul*arr[i]; for i,j in zip(range(0,size),range(1,size,1)): right_mul=right_mul/arr[j]; left_mul=left_mul*arr[i]; if(left_mul==right_mul): return arr[i+1]; return-1 ; arr=[2,3,4,1,4,6,]; size=len(arr); print(findElement(arr,size)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{1}->union(Sequence{4}->union(Sequence{ 6 }))))); ; size := (arr)->size(); ; execute (findElement(arr, size))->display();; operation findElement(arr : OclAny, size : OclAny) pre: true post: true activity: var right_mul : int := 1; ; var left_mul : int := 1; ; for i : Integer.subrange(1, size-1) do ( right_mul := right_mul * arr[i+1];) ; for _tuple : Integer.subrange(1, Integer.subrange(0, size-1)->size())->collect( _indx | Sequence{Integer.subrange(0, size-1)->at(_indx), Integer.subrange(1, size-1)->select( $x | ($x - 1) mod 1 = 0 )->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); right_mul := right_mul / arr[j+1]; ; left_mul := left_mul * arr[i+1]; ; if (left_mul = right_mul) then ( return arr[i + 1+1]; ) else skip) ; return -1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100 ; def findNature(a,b,n): seq=[0]*MAX ; seq[0]=a ; seq[1]=b ; for i in range(2,n+1): seq[i]=seq[i-1]+seq[i-2]; return(seq[n]& 1); a=2 ; b=4 ; n=3 ; if(findNature(a,b,n)): print("Odd"); else : print("Even"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 100; ; skip ; a := 2; ; b := 4; ; n := 3; ; if (findNature(a, b, n)) then ( execute ("Odd")->display(); ) else ( execute ("Even")->display(); ); operation findNature(a : OclAny, b : OclAny, n : OclAny) pre: true post: true activity: var seq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX); ; seq->first() := a; ; seq[1+1] := b; ; for i : Integer.subrange(2, n + 1-1) do ( seq[i+1] := seq[i - 1+1] + seq[i - 2+1];) ; return (MathLib.bitwiseAnd(seq[n+1], 1));; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=[] c=[] for i in range(1,1667): b.append(i) if i % 3==0 : c.append(i) if i % 10==3 and i>10 : c.append(i) c=list(dict.fromkeys(c)) res=[i for i in b if i not in c] for i in range(a): qw=int(input()) print(res[qw-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := Sequence{} ; var c : Sequence := Sequence{} ; for i : Integer.subrange(1, 1667-1) do ( execute ((i) : b) ; if i mod 3 = 0 then ( execute ((i) : c) ) else skip ; if i mod 10 = 3 & i > 10 then ( execute ((i) : c) ) else skip) ; c := ((trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))->keys()->asSequence() ; var res : Sequence := b->select(i | (c)->excludes(i))->collect(i | (i)) ; for i : Integer.subrange(0, a-1) do ( var qw : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (res[qw - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) b=[] l=1 for i in range(t): k=int(input()) while k>len(b): if l % 3!=0 and l % 10!=3 : b.append(l) l+=1 print(b[k-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := Sequence{} ; var l : int := 1 ; for i : Integer.subrange(0, t-1) do ( var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (k->compareTo((b)->size())) > 0 do ( if l mod 3 /= 0 & l mod 10 /= 3 then ( execute ((l) : b) ) else skip ; l := l + 1) ; execute (b[k - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution : def __init__(self): self.ans=[] i=0 count=1 while i!=1003 : if count % 3!=0 : if str(count)[-1]!="3" : i+=1 self.ans.append(count) count+=1 def find(self): t=int(input()) for i in range(t): x=int(input()) print(self.ans[x-1]) obj=Solution() obj.find() ------------------------------------------------------------ OCL File: --------- class Solution { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); attribute ans : Sequence := Sequence{}; operation initialise() : Solution pre: true post: true activity: self.ans := Sequence{} ; var i : int := 0 ; var count : int := 1 ; while i /= 1003 do ( if count mod 3 /= 0 then ( if OclType["String"](count)->last() /= "3" then ( i := i + 1 ; (expr (atom (name self)) (trailer . (name ans)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name count)))))))) )))) ) else skip ) else skip ; count := count + 1); return self; operation find() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (self.ans[x - 1+1])->display()); } class FromPython { operation initialise() pre: true post: true activity: skip ; var obj : Solution := (Solution.newSolution()).initialise() ; obj->indexOf() - 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=[i for i in range(1,1667)if not(i % 3==0 or i % 10==3)] T=int(input()) for _ in range(T): print(t[int(input())-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : Sequence := Integer.subrange(1, 1667-1)->select(i | not((i mod 3 = 0 or i mod 10 = 3)))->collect(i | (i)) ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, T-1) do ( execute (t[("" + (((OclFile["System.in"]).readLine())))->toInteger() - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): k=int(input()) j=n=0 while True : if n % 3!=0 and n % 10!=3 : j+=1 if j==k : print(n) break n+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var j : OclAny := 0; var n : int := 0 ; while true do ( if n mod 3 /= 0 & n mod 10 /= 3 then ( j := j + 1 ) else skip ; if j = k then ( execute (n)->display() ; break ) else skip ; n := n + 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=1 n,s=map(int,input().split()) h,m=map(int,input().split()) h1,m1=h,m if h*60+m-s>0 : print(0,0) f=0 for i in range(n): g1=h1*60+m1 g2=h*60+m if g2-g1>2*s+1 and f==1 : print((g1+s+1)//60,(g1+s+1)% 60) f=0 h1,m1=h,m if i!=n-1 : h,m=map(int,input().split()) if f==1 : g1=h1*60+m1 print((g1+s+1)//60,(g1+s+1)% 60) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : int := 1 ; var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h1 : OclAny := null; var m1 : OclAny := null; Sequence{h1,m1} := Sequence{h,m} ; if h * 60 + m - s > 0 then ( execute (0)->display() ; f := 0 ) else skip ; for i : Integer.subrange(0, n-1) do ( var g1 : double := h1 * 60 + m1 ; var g2 : double := h * 60 + m ; if (g2 - g1->compareTo(2 * s + 1)) > 0 & f = 1 then ( execute ((g1 + s + 1) div 60)->display() ; f := 0 ) else skip ; var h1 : OclAny := null; var m1 : OclAny := null; Sequence{h1,m1} := Sequence{h,m} ; if i /= n - 1 then ( var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ) else skip) ; if f = 1 then ( g1 := h1 * 60 + m1 ; execute ((g1 + s + 1) div 60)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for tc in range(int(input())): n=int(input()) if(n % 2==0): print(n//2,0,0) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for tc : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n mod 2 = 0) then ( execute (n div 2)->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) if n % 2==1 : print(-1) else : print(n//2,n//2,0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 1 then ( execute (-1)->display() ) else ( execute (n div 2)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) if n % 2==0 : print(n//2,0,0) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( execute (n div 2)->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : for t in range(int(input())): n=int(input()) if n % 2==0 : x=n//2 if x % 2==0 : print(x+1,end=" ") print(x+1,end=" ") print(1) else : print(x-1,end=" ") print(x-1,end=" ") print(1) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( var x : int := n div 2 ; if x mod 2 = 0 then ( execute (x + 1)->display() ; execute (x + 1)->display() ; execute (1)->display() ) else ( execute (x - 1)->display() ; execute (x - 1)->display() ; execute (1)->display() ) ) else ( execute (-1)->display() )) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil t=int(input()) for i in range(t): n=int(input()) result="989"+("0123456789"*ceil(n/10)) print(result[: n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var result : String := "989" + (StringLib.nCopies("0123456789", ceil(n / 10))) ; execute (result.subrange(1,n))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=list(map(int,input().split())) a=list(map(int,input().split())) from collections import defaultdict d=defaultdict(lambda : 0) for elem in a : d[elem]+=1 lst=list(d.items()) lst.sort(key=lambda x :-x[1]) i=k res=0 while True : try : now=lst[i] except IndexError : break res+=now[1] i+=1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; var d : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; for elem : a do ( d[elem+1] := d[elem+1] + 1) ; var lst : Sequence := (d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})) ; lst := lst->sort() ; var i : OclAny := k ; var res : int := 0 ; while true do ( try ( var now : OclAny := lst[i+1]) (except_clause except (test (logical_test (comparison (expr (atom (name IndexError)))))) : (suite (stmt (simple_stmt (small_stmt break))))) ; res := res + now[1+1] ; i := i + 1) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for j in range(0,n): m=int(input()) if m==1 : print("9") elif m==2 : print("98") elif m==3 : print("989") else : v="989" for i in range(0,m-3): v=v+str(i % 10) print(v) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, n-1) do ( var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if m = 1 then ( execute ("9")->display() ) else (if m = 2 then ( execute ("98")->display() ) else (if m = 3 then ( execute ("989")->display() ) else ( var v : String := "989" ; for i : Integer.subrange(0, m - 3-1) do ( v := v + ("" + ((i mod 10)))) ; execute (v)->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(0,t): n=int(input()) if n==1 : print("9") elif n==2 : print("98") else : print("989",end="") n=n-3 print(n//10*"0123456789",end="") u=n % 10 for j in range(0,u): print(j,end="") print("") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute ("9")->display() ) else (if n = 2 then ( execute ("98")->display() ) else ( execute ("989")->display() ; n := n - 3 ; execute (n div 10 * "0123456789")->display() ; var u : int := n mod 10 ; for j : Integer.subrange(0, u-1) do ( execute (j)->display()) ; execute ("")->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: n=int(s); print(('9'+'8901234567'*n)[: n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var n : int := ("" + ((s)))->toInteger(); execute (('9' + StringLib.nCopies('8901234567', n)).subrange(1,n))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s="989"+"0123456789"*100000 t=int(input()) for _ in range(t): n=int(input()) print(s[: n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := "989" + StringLib.nCopies("0123456789", 100000) ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (s.subrange(1,n))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,s=map(int,input().split()) t=s m=[] m.append(0) for i in range(n): h,l=map(int,input().split()) l+=h*60 m.append(l) c=0 for i in range(0,len(m)-1): if i==0 and m[i]+s+1<=m[i+1]: time=0 c+=1 break if m[i]+s+s+1collect( _x | (OclType["int"])->apply(_x) ) ; var t : OclAny := s ; var m : Sequence := Sequence{} ; execute ((0) : m) ; for i : Integer.subrange(0, n-1) do ( var h : OclAny := null; var l : OclAny := null; Sequence{h,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; l := l + h * 60 ; execute ((l) : m)) ; var c : int := 0 ; for i : Integer.subrange(0, (m)->size() - 1-1) do ( if i = 0 & (m[i+1] + s + 1->compareTo(m[i + 1+1])) <= 0 then ( var time : int := 0 ; c := c + 1 ; break ) else skip ; if (m[i+1] + s + s + 1->compareTo(m[i + 1+1])) < 0 then ( time := m[i+1] + s + 1 ; c := c + 1 ; break ) else skip) ; if c = 0 then ( time := m->last() + s + 1 ) else skip ; execute (time div 60)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=list(map(int,input().split())) lst1=[chr(97+i)for i in range(26)] lst2=[] for i in range(k): print(lst1[i],sep='',end='') lst2.append(lst1[i]) n-=k while n>0 : for ch in lst2 : print(ch,sep='',end='') n-=1 if n==0 : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lst1 : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | ((97 + i)->byte2char())) ; var lst2 : Sequence := Sequence{} ; for i : Integer.subrange(0, k-1) do ( execute (lst1[i+1])->display() ; execute ((lst1[i+1]) : lst2)) ; n := n - k ; while n > 0 do ( for ch : lst2 do ( execute (ch)->display() ; n := n - 1 ; if n = 0 then ( break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input().split() b,a=int(x[0]),int(x[1]) z=('abcdefghijklmnopqrstuvwxyz') f='' ; c=0 ; k=0 while cb : f+=z[: b % a] break f+=z[: a] k+=1 if b<=a : print(z[: b]) else : print(f) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := input().split() ; var b : OclAny := null; var a : OclAny := null; Sequence{b,a} := Sequence{("" + ((x->first())))->toInteger(),("" + ((x[1+1])))->toInteger()} ; var z : String := ('abcdefghijklmnopqrstuvwxyz') ; var f : String := ''; var c : int := 0; var k : int := 0 ; while (c->compareTo(b)) < 0 do ( c := c + a ; if (c->compareTo(b)) > 0 then ( f := f + z.subrange(1,b mod a) ; break ) else skip ; f := f + z.subrange(1,a) ; k := k + 1) ; if (b->compareTo(a)) <= 0 then ( execute (z.subrange(1,b))->display() ) else ( execute (f)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a='abcdefghijklmnopqrstuvwxyz' x=a[: k] print((x*(n//k))+a[: n % k]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : String := 'abcdefghijklmnopqrstuvwxyz' ; var x : OclAny := a.subrange(1,k) ; execute ((x * (n div k)) + a.subrange(1,n mod k))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- alpha=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] n,k=map(int,input().split()) A=alpha[: k] AA=A*n myStr='' for i in range(n): myStr+=AA[i] print(myStr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var alpha : Sequence := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{'c'}->union(Sequence{'d'}->union(Sequence{'e'}->union(Sequence{'f'}->union(Sequence{'g'}->union(Sequence{'h'}->union(Sequence{'i'}->union(Sequence{'j'}->union(Sequence{'k'}->union(Sequence{'l'}->union(Sequence{'m'}->union(Sequence{'n'}->union(Sequence{'o'}->union(Sequence{'p'}->union(Sequence{'q'}->union(Sequence{'r'}->union(Sequence{'s'}->union(Sequence{'t'}->union(Sequence{'u'}->union(Sequence{'v'}->union(Sequence{'w'}->union(Sequence{'x'}->union(Sequence{'y'}->union(Sequence{ 'z' }))))))))))))))))))))))))) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : OclAny := alpha.subrange(1,k) ; var AA : double := A * n ; var myStr : String := '' ; for i : Integer.subrange(0, n-1) do ( myStr := myStr + AA[i+1]) ; execute (myStr)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) chars=list(map(chr,range(97,97+k))) ctr=0 for i in range(n): print(chars[ctr],end='') if ctr==k-1 : ctr=0 else : ctr+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var chars : Sequence := ((Integer.subrange(97, 97 + k-1))->collect( _x | (chr)->apply(_x) )) ; var ctr : int := 0 ; for i : Integer.subrange(0, n-1) do ( execute (chars[ctr+1])->display() ; if ctr = k - 1 then ( ctr := 0 ) else ( ctr := ctr + 1 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bin_pow(a,x): if a==1 or x==0 : return 1 if x==1 : return a if x & 1 : return bin_pow(a,x-1)*a else : temp=bin_pow(a,x>>1) return temp*temp a,b=map(int,input().split()) x=bin_pow(1.000000011,b)*a print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; x := bin_pow(1.000000011, b) * a ; execute (x)->display(); operation bin_pow(a : OclAny, x : OclAny) : OclAny pre: true post: true activity: if a = 1 or x = 0 then ( return 1 ) else skip ; if x = 1 then ( return a ) else skip ; if MathLib.bitwiseAnd(x, 1) then ( return bin_pow(a, x - 1) * a ) else ( var temp : OclAny := bin_pow(a, x /(2->pow(1))) ; return temp * temp ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import fractions import copy def j(q): if q==1 : print("YES") elif q==0 : print("NO") exit(0) rem=pow(10,9)+7 def ip(): return int(input()) def printrow(a): for i in range(len(a)): print(a[i]) def combinations(n,r): if npow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; var k : OclAny := null; Sequence{n,k} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; a := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; a := a->sort() ; var cnum : OclAny := a->first() ; var ct : int := 1 ; var st : Sequence := Sequence{} ; for i : Integer.subrange(1, n-1) do ( if a[i+1] /= cnum then ( cnum := a[i+1] ; execute ((ct) : st) ; ct := 1 ) else ( ct := ct + 1 )) ; execute ((ct) : st) ; st := st->sort() ; var total : int := 0 ; for i : Integer.subrange(0, Set{k, (st)->size()}->min()-1) do ( total := total + st[i+1]) ; execute (n - total)->display(); operation j(q : OclAny) pre: true post: true activity: if q = 1 then ( execute ("YES")->display() ) else (if q = 0 then ( execute ("NO")->display() ) else skip) ; exit(0); operation ip() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation printrow(a : OclAny) pre: true post: true activity: for i : Integer.subrange(0, (a)->size()-1) do ( execute (a[i+1])->display()); operation combinations(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: if (n->compareTo(r)) < 0 then ( return 0 ) else skip ; return MathLib.factorial(n) div (MathLib.factorial(n - r) * MathLib.factorial(r)); operation permutations(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: if (n->compareTo(r)) < 0 then ( return 0 ) else skip ; return MathLib.factorial(n) div MathLib.factorial(n - r); operation lcm(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return (x * y) div fractions.gcd(x, y); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) print(1.000000011**b*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((1.000000011)->pow(b) * a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=list(map(int,input().split())) print((n)*(1.000000011**k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((n) * ((1.000000011)->pow(k)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (n,m)=map(int,input().split(' ')) print(n*(1.000000011)**m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{n, m} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; execute (n * ((1.000000011))->pow(m))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,s=map(int,input().split()) w=[-s-1] for _ in range(n): h,m=map(int,input().split()) w.append(h*60+m) for i in range(n): if w[i+1]-w[i]>=(s+1)*2 : if i!=0 : x=w[i]+s+1 break else : x=0 break else : x=w[-1]+s+1 print(x//60,x % 60) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := Sequence{ -s - 1 } ; for _anon : Integer.subrange(0, n-1) do ( var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((h * 60 + m) : w)) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))) - (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))) >= (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name s))) + (expr (atom (number (integer 1))))))))) ))) * (expr (atom (number (integer 2))))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name i)))) != (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name s)))) + (expr (atom (number (integer 1)))))))))))))) (stmt (simple_stmt (small_stmt break)))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (simple_stmt (small_stmt break))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))) + (expr (atom (name s)))) + (expr (atom (number (integer 1))))))))))))))))) ; execute (x div 60)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) print(n*(1.000000011**k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (n * ((1.000000011)->pow(k)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(N,k): p=0 p2=0 memo=0 for i in range(N-1): p,p2=p2,k*(p2+1)//(k-1)-2 while p2-1-p2//k!=p : p2+=1 return p2 if __name__=='__main__' : N,k=input().split() print(main(int(N),int(k))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( Sequence{N,k} := input().split() ; execute (main(("" + ((N)))->toInteger(), ("" + ((k)))->toInteger()))->display() ) else skip; operation main(N : OclAny, k : OclAny) : OclAny pre: true post: true activity: var p : int := 0 ; var p2 : int := 0 ; var memo : int := 0 ; for i : Integer.subrange(0, N - 1-1) do ( Sequence{p,p2} := Sequence{p2,k * (p2 + 1) div (k - 1) - 2} ; while p2 - 1 - p2 div k /= p do ( p2 := p2 + 1)) ; return p2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=10**9+7 dd=[(0,-1),(1,0),(0,1),(-1,0)] ddn=[(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)] def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): n,k=LI() t=0 for _ in range(n-1): t=t*k//(k-1)+1 return t print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : double := (10)->pow(9) + 7 ; var dd : Sequence := Sequence{Sequence{0, -1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{ Sequence{-1, 0} }))) ; var ddn : Sequence := Sequence{Sequence{0, -1}}->union(Sequence{Sequence{1, -1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{1, 1}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{-1, -1}}->union(Sequence{Sequence{-1, 0}}->union(Sequence{ Sequence{-1, 1} }))))))) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := LI() ; var t : int := 0 ; for _anon : Integer.subrange(0, n - 1-1) do ( t := t * k div (k - 1) + 1) ; return t; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) now=0 while n>1 : n-=1 now=(now*k)//(k-1)+1 print(now) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var now : int := 0 ; while n > 1 do ( n := n - 1 ; now := (now * k) div (k - 1) + 1) ; execute (now)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def horizontal_input(T=str): return list(map(T,input().split())) def vertical_input(n,T=str,sep=False,septype=tuple): data=[] if sep : for i in range(n): data.append(septype(map(T,input().split()))) else : for i in range(n): data.append(T(input())) return data n,k=horizontal_input(int) prisoner=0 for i in range(n-1): prisoner+=1 prisoner+=(prisoner-1)//(k-1) print(prisoner) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var k : OclAny := null; Sequence{n,k} := horizontal_input(OclType["int"]) ; var prisoner : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( prisoner := prisoner + 1 ; prisoner := prisoner + (prisoner - 1) div (k - 1)) ; execute (prisoner)->display(); operation horizontal_input(T : OclAny) : OclAny pre: true post: true activity: if T->oclIsUndefined() then T := OclType["String"] else skip; return ((input().split())->collect( _x | (T)->apply(_x) )); operation vertical_input(n : OclAny, T : OclAny, sep : OclAny, septype : OclAny) : OclAny pre: true post: true activity: if T->oclIsUndefined() then T := OclType["String"] else skip; if sep->oclIsUndefined() then sep := false else skip; if septype->oclIsUndefined() then septype := tuple else skip; var data : Sequence := Sequence{} ; if sep then ( for i : Integer.subrange(0, n-1) do ( execute ((septype((input().split())->collect( _x | (T)->apply(_x) ))) : data)) ) else ( for i : Integer.subrange(0, n-1) do ( execute ((T((OclFile["System.in"]).readLine())) : data)) ) ; return data; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import floor N,k=map(int,input().split()) l,r=-1,10**18 while l+1>1 x=m for i in range(1,N): x-=x//k+1 if 0<=x : r=m else : l=m print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var k : OclAny := null; Sequence{N,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{-1,(10)->pow(18)} ; while (l + 1->compareTo(r)) < 0 do ( var m : int := (l + r) /(2->pow(1)) ; var x : int := m ; for i : Integer.subrange(1, N-1) do ( x := x - x div k + 1) ; if 0 <= x then ( var r : int := m ) else ( var l : int := m )) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,n=map(int,input().split()) print((m-1)*(n-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((m - 1) * (n - 1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def inputlist(): return[int(k)for k in input().split()] N,K=inputlist() A=inputlist() from collections import Counter c=Counter(A) val=list(c.values()) val.sort() if len(val)<=K : print(0) exit() ans=0 for i in range(len(val)-K): ans+=val[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := inputlist() ; var A : OclAny := inputlist() ; skip ; var c : OclAny := Counter(A) ; var val : Sequence := (c.values()) ; val := val->sort() ; if ((val)->size()->compareTo(K)) <= 0 then ( execute (0)->display() ; exit() ) else skip ; var ans : int := 0 ; for i : Integer.subrange(0, (val)->size() - K-1) do ( ans := ans + val[i+1]) ; execute (ans)->display(); operation inputlist() : OclAny pre: true post: true activity: return input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout def main(): line=stdin.readline() parts=line.split() a=int(parts[0]) b=int(parts[1]) stdout.write(str((a-1)*(b-1))) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: var line : String := stdin.readLine() ; var parts : OclAny := line.split() ; var a : int := ("" + ((parts->first())))->toInteger() ; var b : int := ("" + ((parts[1+1])))->toInteger() ; stdout.write(("" + (((a - 1) * (b - 1))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A=list(map(int,input().split())) print((A[0]-1)*(A[1]-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((A->first() - 1) * (A[1+1] - 1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- y=lambda : map(int,input().split()) n,s=y() r=0 for f in[0]*n : h,m=y(); t=60*h+m if t>r+s : break r=t+s+1 print(r//60,r % 60) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var y : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := y->apply() ; var r : int := 0 ; for f : MatrixLib.elementwiseMult(Sequence{ 0 }, n) do ( var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := y->apply(); var t : double := 60 * h + m ; if (t->compareTo(r + s)) > 0 then ( break ) else skip ; r := t + s + 1) ; execute (r div 60)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) print((n-1)*(m-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((n - 1) * (m - 1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=list(map(int,input().split())) print((n-1)*(m-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((n - 1) * (m - 1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(((n+999)//1000*1000)-n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (((n + 999) div 1000 * 1000) - n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=input() m=len(N) if m>3 : N=N[-3 :] if N=='000' : print(0) exit() print(1000-int(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : String := (OclFile["System.in"]).readLine() ; var m : int := (N)->size() ; if m > 3 then ( N := N.subrange(-3+1) ) else skip ; if N = '000' then ( execute (0)->display() ; exit() ) else skip ; execute (1000 - ("" + ((N)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def gcd(a,b): if(b==0): return a else : return gcd(b,a % b) n=int(input()) amt=math.ceil(n/1000)*1000 print(amt-n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var amt : double := (n / 1000)->ceil() * 1000 ; execute (amt - n)->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (b = 0) then ( return a ) else ( return gcd(b, a mod b) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(-int(input())% 1000) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (-("" + (((OclFile["System.in"]).readLine())))->toInteger() mod 1000)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N=int(input()) b=(N//1000)+1 print((b*1000-N)% 1000) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := (N div 1000) + 1 ; execute ((b * 1000 - N) mod 1000)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) ans=n//2+1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := n div 2 + 1 ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ii(): return int(input()) def iim(): return map(int,input().split()) def iil(): return list(map(int,input().split())) def ism(): return map(str,input().split()) def isl(): return list(map(str,input().split())) import collections n,k=iim() c=collections.Counter(iil()) l=sorted(c.values(),reverse=True) print(sum(l[k :])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := iim() ; var c : OclAny := .Counter(iil()) ; var l : Sequence := c.values()->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; execute ((l.subrange(k+1))->sum())->display(); operation ii() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation iim() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation iil() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ism() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["String"])->apply(_x) ); operation isl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["String"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(n//2+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n div 2 + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) strings=[] for i in range(n): strings.append([input(),i+1]) for s in strings : for i in range(m): if i & 1 : x=chr((25-(ord(s[0][i])-ord('A')))+ord('A')) s[0]=s[0][: i]+x+s[0][i+1 :] strings.sort() for x in strings : print(x[1],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var strings : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((Sequence{(OclFile["System.in"]).readLine()}->union(Sequence{ i + 1 })) : strings)) ; for s : strings do ( for i : Integer.subrange(0, m-1) do ( if MathLib.bitwiseAnd(i, 1) then ( var x : String := ((25 - ((s->first()[i+1])->char2byte() - ('A')->char2byte())) + ('A')->char2byte())->byte2char() ; s->first() := s->first().subrange(1,i) + x + s->first().subrange(i + 1+1) ) else skip)) ; strings := strings->sort() ; for x : strings do ( execute (x[1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys import itertools import fractions if __name__=='__main__' : wtf=sys.stdin.read() wtf=wtf.strip().split('\n') n=int(wtf[0]) ans=n//2+1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var wtf : String := (OclFile["System.in"]).readAll() ; wtf := wtf->trim().split(' ') ; var n : int := ("" + ((wtf->first())))->toInteger() ; var ans : int := n div 2 + 1 ; execute (ans)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=int(input()) print(s//2+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (s div 2 + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(int(input())//2+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (("" + (((OclFile["System.in"]).readLine())))->toInteger() div 2 + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calc(l,n): if n==2 : if a[l]and a[l+1]: return[0,True] if a[l]or a[l+1]: return[0,False] return[1,False] m=n>>1 c1,f1=calc(l,m) c2,f2=calc(l+m,m) if f1 and f2 : return[c1+c2,True] if f1 or f2 : return[c1+c2,False] return[c1+c2+1,False] N,M=map(int,input().split()) if M==0 : print(N-1) else : a=[False]*256 for i in range(M): a[int(input())]=True print(calc(0,N)[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if M = 0 then ( execute (N - 1)->display() ) else ( var a : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, 256) ; for i : Integer.subrange(0, M-1) do ( a[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1] := true) ; execute (calc(0, N)->first())->display() ); operation calc(l : OclAny, n : OclAny) : OclAny pre: true post: true activity: if n = 2 then ( if a[l+1] & a[l + 1+1] then ( return Sequence{0}->union(Sequence{ true }) ) else skip ; if a[l+1] or a[l + 1+1] then ( return Sequence{0}->union(Sequence{ false }) ) else skip ; return Sequence{1}->union(Sequence{ false }) ) else skip ; var m : int := n /(2->pow(1)) ; var c1 : OclAny := null; var f1 : OclAny := null; Sequence{c1,f1} := calc(l, m) ; var c2 : OclAny := null; var f2 : OclAny := null; Sequence{c2,f2} := calc(l + m, m) ; if f1 & f2 then ( return Sequence{c1 + c2}->union(Sequence{ true }) ) else skip ; if f1 or f2 then ( return Sequence{c1 + c2}->union(Sequence{ false }) ) else skip ; return Sequence{c1 + c2 + 1}->union(Sequence{ false }); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input().split(' ') tour=int(a[0])-1 no_vs=0 if int(a[1])!=0 : absent=[] for _ in range(int(a[1])): absent.append(int(input())) num=int(int(a[0])/2) while absent!=[]: next_absent=[] for n in range(num): if 2*n in absent or 2*n+1 in absent : no_vs+=1 if 2*n in absent and 2*n+1 in absent : next_absent.append(n) absent=next_absent num=int(num/2) print(tour-no_vs) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := input().split(' ') ; var tour : double := ("" + ((a->first())))->toInteger() - 1 ; var no_vs : int := 0 ; if ("" + ((a[1+1])))->toInteger() /= 0 then ( var absent : Sequence := Sequence{} ; for _anon : Integer.subrange(0, ("" + ((a[1+1])))->toInteger()-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : absent)) ; var num : int := ("" + ((("" + ((a->first())))->toInteger() / 2)))->toInteger() ; while absent /= Sequence{} do ( var next_absent : Sequence := Sequence{} ; for n : Integer.subrange(0, num-1) do ( if (absent)->includes(2 * n) or (absent)->includes(2 * n + 1) then ( no_vs := no_vs + 1 ; if (absent)->includes(2 * n) & (absent)->includes(2 * n + 1) then ( execute ((n) : next_absent) ) else skip ) else skip) ; absent := next_absent ; num := ("" + ((num / 2)))->toInteger()) ) else skip ; execute (tour - no_vs)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 def LI(): return list(map(int,input().split())) def LF(): return list(map(float,input().split())) def II(): return int(input()) def LS(): return input().split() def S(): return input() def main(): n,m=LI() return n-m-1 print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LF() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["double"])->apply(_x) )); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return input().split(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation main() : OclAny pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := LI() ; return n - m - 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split(' ')) ns=[i for i in range(n)] for i in range(m): ha=int(input()) ns[ha]=None count=0 while True : size=len(ns) ns2=[] for j in range(0,size,2): flag=ns[j]is not None and ns[j+1]is not None if flag : ns2.append(0) count+=1 elif ns[j]is not None or ns[j+1]is not None : ns2.append(0) else : ns2.append(None) ns=ns2 if len(ns)==1 : break print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var ns : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)) ; for i : Integer.subrange(0, m-1) do ( var ha : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; ns[ha+1] := null) ; var count : int := 0 ; while true do ( var size : int := (ns)->size() ; var ns2 : Sequence := Sequence{} ; for j : Integer.subrange(0, size-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( var flag : boolean := not(ns[j+1] <>= null) & not(ns[j + 1+1] <>= null) ; if flag then ( execute ((0) : ns2) ; count := count + 1 ) else (if not(ns[j+1] <>= null) or not(ns[j + 1+1] <>= null) then ( execute ((0) : ns2) ) else ( execute ((null) : ns2) ) ) ) ; ns := ns2 ; if (ns)->size() = 1 then ( break ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N,M=map(int,input().split()) a=[int(input())for _ in[0]*M] print(N-len(a)-1) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, M)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; execute (N - (a)->size() - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) print(n**3) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((n)->pow(3))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lis=list(map(int,input().split())) lis2=input().split() n=lis[0] k=lis[1] d={} for i in range(n): if lis2[i]not in d.keys(): d[lis2[i]]=1 else : d[lis2[i]]+=1 if len(list(d.values()))<=k : print(0) else : a=list(d.values()) a.sort() a.reverse() swap=0 for i in range(k,len(a)): swap+=a[i] print(swap) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lis : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lis2 : OclAny := input().split() ; var n : OclAny := lis->first() ; var k : OclAny := lis[1+1] ; var d : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( if (d.keys())->excludes(lis2[i+1]) then ( d[lis2[i+1]+1] := 1 ) else ( d[lis2[i+1]+1] := d[lis2[i+1]+1] + 1 )) ; if (((d.values()))->size()->compareTo(k)) <= 0 then ( execute (0)->display() ) else ( var a : Sequence := (d.values()) ; a := a->sort() ; a := a->reverse() ; var swap : int := 0 ; for i : Integer.subrange(k, (a)->size()-1) do ( swap := swap + a[i+1]) ; execute (swap)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=[int(i)for i in input().split()] h=[] s=[] for i in range(n): data=[int(i)for i in input().split()] h.append(data[0]) s.append(data[1]) ansh=0 anss=0 for i in range(n): if(h[i]-ansh)*60+s[i]-anss>=t+1 : break anss=s[i]+t+1 ansh=h[i] if anss>=60 : hours=anss//60 ansh+=hours anss-=hours*60 print(ansh,anss) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var h : Sequence := Sequence{} ; var s : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var data : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute ((data->first()) : h) ; execute ((data[1+1]) : s)) ; var ansh : int := 0 ; var anss : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ((h[i+1] - ansh) * 60 + s[i+1] - anss->compareTo(t + 1)) >= 0 then ( break ) else skip ; anss := s[i+1] + t + 1 ; ansh := h[i+1] ; if anss >= 60 then ( var hours : int := anss div 60 ; ansh := ansh + hours ; anss := anss - hours * 60 ) else skip) ; execute (ansh)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(int(input())**3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger())->pow(3))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[i for i in range(1,n+1)] ans=0 for i in l : for j in l : for k in l : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | (i)) ; var ans : int := 0 ; for i : l do ( for j : l do ( for k : l do ( ans := ans + 1))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline sys.setrecursionlimit(10**7) p=int(input().rstrip()) print(p**3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit((10)->pow(7)) ; var p : int := ("" + ((input().rstrip())))->toInteger() ; execute ((p)->pow(3))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) result=N*N*N print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var result : int := N * N * N ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) print(N*M) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (N * M)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(eval(input().replace(" ","*"))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (input().replace(" ", "*"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nums(): return list(map(int,input().split())) N,M=nums() print(N*M) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := nums() ; execute (N * M)->display(); operation nums() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(i)for i in input().split()] print(n*m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute (n * m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) print(a*b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (a * b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,R=map(int,input().split()) if N>=10 : print(R) else : print(R+100*(10-N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var R : OclAny := null; Sequence{N,R} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if N >= 10 then ( execute (R)->display() ) else ( execute (R + 100 * (10 - N))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): a,b=list(map(int,input().split())) if b==1 : print("NO") else : print("YES") print(a,a*b,a*b+a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if b = 1 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; execute (a)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lex(f,s): for i in range(len(f)): if(f[i]>s[i]): return "first" ; if(s[i]>f[i]): return "second" if(len(f)>len(s)): return "first" if(len(s)>len(f)): return 'second' return-1 f=[] s=[] s1=0 s2=0 n=int(input()) last="" for i in range(n): x=int(input()) if(x<0): s1+=abs(x) s.append(abs(x)) else : s2+=abs(x) f.append(abs(x)) if(i==n-1): if(x<0): last='second' else : last='first' if(s1toInteger() ; var last : String := "" ; for i : Integer.subrange(0, n-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (x < 0) then ( s1 := s1 + (x)->abs() ; execute (((x)->abs()) : s) ) else ( s2 := s2 + (x)->abs() ; execute (((x)->abs()) : f) ) ; if (i = n - 1) then ( if (x < 0) then ( last := 'second' ) else ( last := 'first' ) ) else skip) ; if ((s1->compareTo(s2)) < 0) then ( execute ('first')->display() ) else (if (s2->compareTo(s1)) < 0 then ( execute ('second')->display() ) else ( var ans : OclAny := lex(f, s); ; if (ans = -1) then ( execute (last)->display() ) else ( execute (ans)->display() ) ) ) ; operation lex(f : OclAny, s : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, (f)->size()-1) do ( if ((f[i+1]->compareTo(s[i+1])) > 0) then ( return "first"; ) else skip ; if ((s[i+1]->compareTo(f[i+1])) > 0) then ( return "second" ) else skip) ; if (((f)->size()->compareTo((s)->size())) > 0) then ( return "first" ) else skip ; if (((s)->size()->compareTo((f)->size())) > 0) then ( return 'second' ) else skip ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input().split() nm=[] for i in range(2): b=int(a[i]) nm.append(b) if nm[0]<10 : nm[1]+=(100*(10-nm[0])) print(nm[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := input().split() ; var nm : Sequence := Sequence{} ; for i : Integer.subrange(0, 2-1) do ( var b : int := ("" + ((a[i+1])))->toInteger() ; execute ((b) : nm)) ; if nm->first() < 10 then ( nm[1+1] := nm[1+1] + (100 * (10 - nm->first())) ) else skip ; execute (nm[1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,r=map(int,input().split()); print(100*max(0,10-n)+r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var r : OclAny := null; Sequence{n,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); execute (100 * Set{0, 10 - n}->max() + r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,R=[int(v)for v in input().strip().split()] print(R if N>=10 else R+100*(10-N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var R : OclAny := null; Sequence{N,R} := input()->trim().split()->select(v | true)->collect(v | (("" + ((v)))->toInteger())) ; execute (if N >= 10 then R else R + 100 * (10 - N) endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,R=input().split() if int(N)<11 : print(int(R)+(100*(10-int(N)))) else : print(int(R)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var R : OclAny := null; Sequence{N,R} := input().split() ; if ("" + ((N)))->toInteger() < 11 then ( execute (("" + ((R)))->toInteger() + (100 * (10 - ("" + ((N)))->toInteger())))->display() ) else ( execute (("" + ((R)))->toInteger())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N,M=map(int,input().split()) ans=(N*(N-1))//2+(M*(M-1))//2 print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := (N * (N - 1)) div 2 + (M * (M - 1)) div 2 ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from scipy.misc import comb n,m=map(int,input().split()) print(comb(n,2,exact=True)+comb(m,2,exact=True)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (comb(n, 2, (argument (test (logical_test (comparison (expr (atom (name exact)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) + comb(m, 2, (argument (test (logical_test (comparison (expr (atom (name exact)))))) = (test (logical_test (comparison (expr (atom (name True)))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from io import StringIO import unittest def resolve(): n,m=map(int,input().split()) print(int(n*(n-1)/2+m*(m-1)/2)) class TestClass(unittest.TestCase): def assertIO(self,input,output): stdout,stdin=sys.stdout,sys.stdin sys.stdout,sys.stdin=StringIO(),StringIO(input) resolve() sys.stdout.seek(0) out=sys.stdout.read()[:-1] sys.stdout,sys.stdin=stdout,stdin self.assertEqual(out,output) def test_入力例_1(self): input="""2 1""" output="""1""" self.assertIO(input,output) def test_入力例_2(self): input="""4 3""" output="""9""" self.assertIO(input,output) def test_入力例_3(self): input="""1 1""" output="""0""" self.assertIO(input,output) def test_入力例_4(self): input="""13 3""" output="""81""" self.assertIO(input,output) def test_入力例_5(self): input="""0 3""" output="""3""" self.assertIO(input,output) if __name__=="__main__" : resolve() ------------------------------------------------------------ OCL File: --------- class TestClass extends unittest.TestCase { static operation newTestClass() : TestClass pre: true post: TestClass->exists( _x | result = _x ); operation assertIO(input : OclAny,output : OclAny) pre: true post: true activity: var stdout : OclAny := null; var stdin : OclAny := null; Sequence{stdout,stdin} := Sequence{OclFile["System.out"],OclFile["System.in"]} ; var OclFile["System.out"] : OclAny := null; var OclFile["System.in"] : OclAny := null; Sequence{OclFile["System.out"],OclFile["System.in"]} := Sequence{StringIO(),StringIO(input)} ; resolve() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name seek) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))) ; var out : OclAny := sys.stdout.readAll()->front() ; var OclFile["System.out"] : OclAny := null; var OclFile["System.in"] : OclAny := null; Sequence{OclFile["System.out"],OclFile["System.in"]} := Sequence{stdout,stdin} ; self.assertEqual(out, output); operation test_??? operation test_??? skip(self : OclAny) pre: true post: true activity: input := (atom "" "2 1" "") ; output := (atom "" "1" "") ; self.assertIO(input, output); () pre: true post: true activity: input := (atom "" "2 1" "") ; output := (atom "" "1" "") ; self.assertIO(input, output); operation test_???self : OclAny() pre: true post: true activity: input := (atom "" "4 3" "") ; output := (atom "" "9" "") ; self.assertIO(input, output); operation test_??? input := (atom "" "1 1" "") ; output := (atom "" "0" "") ; self.assertIO(input, output)() pre: true post: true activity: input := (atom "" "1 1" "") ; output := (atom "" "0" "") ; self.assertIO(input, output); operation test_???_4() pre: true post: true activity: input := (atom "" "13 3" "") ; output := (atom "" "81" "") ; self.assertIO(input, output); operation test_???_5() pre: true post: true activity: input := (atom "" "0 3" "") ; output := (atom "" "3" "") ; self.assertIO(input, output); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( resolve() ) else skip; operation resolve() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (("" + ((n * (n - 1) / 2 + m * (m - 1) / 2)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N_gu,M_ki=map(int,input().split()) from math import factorial def kumiawase_num(n,r): if ncollect( _x | (OclType["int"])->apply(_x) ) ; skip ; skip ; skip ; var gu_gu : OclAny := kumiawase_num(N_gu, 2) ; var ki_ki : OclAny := kumiawase_num(M_ki, 2) ; execute (gu_gu + ki_ki)->display(); operation kumiawase_num(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: if (n->compareTo(r)) < 0 then ( return 0 ) else skip ; return factorial(n) div (factorial(n - r) * factorial(r)); operation kumiawase_jufuku(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: if (n->compareTo(r)) < 0 then ( return 0 ) else ( return kumiawase_num(n + r - 1, r) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def saiki(n): if n==0 : return 0 else : return n+saiki(n-1) def number(n,m): ans=saiki(n)+saiki(m)-n-m return ans def main(): n,m=map(int,input().split()) print(number(n,m)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation saiki(n : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( return 0 ) else ( return n + saiki(n - 1) ); operation number(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var ans : double := saiki(n) + saiki(m) - n - m ; return ans; operation main() pre: true post: true activity: Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (number(n, m))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x,y=map(int,input().split()) if y==1 : print('NO') else : print('YES') print((2*y*x)-x,x,2*y*x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if y = 1 then ( execute ('NO')->display() ) else ( execute ('YES')->display() ; execute ((2 * y * x) - x)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for _ in range(int(input())): n,k=map(int,input().split()) cf=(n+k-1)//k k*=cf print((k+n-1)//n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cf : int := (n + k - 1) div k ; k := k * cf ; execute ((k + n - 1) div n)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) first=[] second=[] last="" for i in range(n): score=int(input()) if score<0 : second.append(-score) last="second" else : first.append(score) last="first" if sum(first)>sum(second): print("first") elif sum(first)(second[i]): print("first") return elif(second[i])>(first[i]): print("second") return i+=1 j+=1 if jtoInteger() ; var first : Sequence := Sequence{} ; var second : Sequence := Sequence{} ; var last : String := "" ; for i : Integer.subrange(0, n-1) do ( var score : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if score < 0 then ( execute ((-score) : second) ; last := "second" ) else ( execute ((score) : first) ; last := "first" )) ; if ((first)->sum()->compareTo((second)->sum())) > 0 then ( execute ("first")->display() ) else (if ((first)->sum()->compareTo((second)->sum())) < 0 then ( execute ("second")->display() ) else ( var i : int := 0 ; var j : int := 0 ; while (i->compareTo((first)->size())) < 0 & (j->compareTo((second)->size())) < 0 do ( if (first[i+1]->compareTo((second[i+1]))) > 0 then ( execute ("first")->display() ; return ) else (if ((second[i+1])->compareTo((first[i+1]))) > 0 then ( execute ("second")->display() ; return ) else skip) ; i := i + 1 ; j := j + 1) ; if (j->compareTo((second)->size())) < 0 then ( execute ("second")->display() ; return ) else skip ; if (i->compareTo((first)->size())) < 0 then ( execute ("first")->display() ; return ) else skip ; execute (last)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: n,k=map(int,s.split()); print(0--n//k*k//n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ); execute (0 - -n div k * k div n)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(x,n,k): if x*n-(x*n % k)>=x+n-1 : return True return False if __name__=="__main__" : t=int(input()) while True : n,k=map(int,input().split(' ')) l=1 r=k ans=0 while(l<=r): mid=l+r>>1 if check(mid,n,k): ans=mid r=mid-1 else : l=mid+1 print(ans) t-=1 if t==0 : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while true do ( Sequence{n,k} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var l : int := 1 ; var r : OclAny := k ; var ans : int := 0 ; while ((l->compareTo(r)) <= 0) do ( var mid : int := l + r /(2->pow(1)) ; if check(mid, n, k) then ( ans := mid ; r := mid - 1 ) else ( l := mid + 1 )) ; execute (ans)->display() ; t := t - 1 ; if t = 0 then ( break ) else skip) ) else skip; operation check(x : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (x * n - (x * n mod k)->compareTo(x + n - 1)) >= 0 then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n,k=map(int,input().split()) cf=int((k+n-1)/k) k*=cf print(int((k+n-1)/n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cf : int := ("" + (((k + n - 1) / k)))->toInteger() ; k := k * cf ; execute (("" + (((k + n - 1) / n)))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) if n==1 : print(k) elif k==1 : print(1) elif n==k : print(1) elif n>k : if n % k==0 : print(1) else : tmp=n//k k=(tmp+1)*k print((k//n)+1) elif ntoInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 1 then ( execute (k)->display() ) else (if k = 1 then ( execute (1)->display() ) else (if n = k then ( execute (1)->display() ) else (if (n->compareTo(k)) > 0 then ( if n mod k = 0 then ( execute (1)->display() ) else ( var tmp : int := n div k ; var k : double := (tmp + 1) * k ; execute ((k div n) + 1)->display() ) ) else (if (n->compareTo(k)) < 0 then ( if k mod n = 0 then ( execute (k div n)->display() ) else ( execute ((k div n) + 1)->display() ) ) else skip ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) cnt=0 for i in range(1,n): if a[i]>a[i-1]: cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : int := 0 ; for i : Integer.subrange(1, n-1) do ( if (a[i+1]->compareTo(a[i - 1+1])) > 0 then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import* from bisect import* from math import* from collections import* from heapq import* from random import* import sys sys.setrecursionlimit(10**6) int1=lambda x : int(x)-1 p2D=lambda x : print(*x,sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int,sys.stdin.readline().split()) def MI1(): return map(int1,sys.stdin.readline().split()) def MF(): return map(float,sys.stdin.readline().split()) def LI(): return list(map(int,sys.stdin.readline().split())) def LI1(): return list(map(int1,sys.stdin.readline().split())) def LF(): return list(map(float,sys.stdin.readline().split())) def LLI(rows_number): return[LI()for _ in range(rows_number)] dij=[(1,0),(0,1),(-1,0),(0,-1)] def main(): input() aa=LI() ans=0 for a0,a1 in zip(aa,aa[1 :]): if a0pow(6)) ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; var p2D : Function := lambda x : OclAny in (((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var dij : Sequence := Sequence{Sequence{1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{-1, 0}}->union(Sequence{ Sequence{0, -1} }))) ; skip ; main(); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation MI1() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (int1)->apply(_x) ); operation MF() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LI1() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (int1)->apply(_x) )); operation LF() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) )); operation LLI(rows_number : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows_number-1)->select(_anon | true)->collect(_anon | (LI())); operation main() pre: true post: true activity: input() ; var aa : OclAny := LI() ; var ans : int := 0 ; for _tuple : Integer.subrange(1, aa->size())->collect( _indx | Sequence{aa->at(_indx), aa->tail()->at(_indx)} ) do (var _indx : int := 1; var a0 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a1 : OclAny := _tuple->at(_indx); if (a0->compareTo(a1)) < 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def num(): return int(input()) def nums(): return list(map(int,input().split())) N=num() randoms=nums() ans=0 for i in range(N): today=randoms[i] if i==0 : continue if today>randoms[i-1]: ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := num() ; var randoms : OclAny := nums() ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( var today : OclAny := randoms[i+1] ; if i = 0 then ( continue ) else skip ; if (today->compareTo(randoms[i - 1+1])) > 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); operation num() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation nums() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=[int(i)for i in input().split()] ret=0 for i in range(1,N): if A[i]>A[i-1]: ret+=1 print(ret) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ret : int := 0 ; for i : Integer.subrange(1, N-1) do ( if (A[i+1]->compareTo(A[i - 1+1])) > 0 then ( ret := ret + 1 ) else skip) ; execute (ret)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: a,b=map(int,s.split()); c=2*a*b ; print(*(['NO'],['YES',a,c-a,c])[b>1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ); var c : double := 2 * a * b; execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom 'NO')))))) ]))))) , (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom 'YES'))))) , (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (expr (atom (name c))) - (expr (atom (name a))))))) , (test (logical_test (comparison (expr (atom (name c))))))) ])))))) )) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (comparison (expr (atom (name b)))) > (comparison (expr (atom (number (integer 1)))))))))) ]))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() l=list(map(int,input().split())) cnt=0 for i in range(len(l)-1): if l[i]collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : int := 0 ; for i : Integer.subrange(0, (l)->size() - 1-1) do ( if (l[i+1]->compareTo(l[i + 1+1])) < 0 then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T,X=[float(x)for x in input().split(' ')] print(T/X) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : OclAny := null; var X : OclAny := null; Sequence{T,X} := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toReal())) ; execute (T / X)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()); arr1=[]; arr2=[]; wrestler1=0 ; wrestler2=0 for i in range(n): point=int(input()) if point<0 : arr2.append(abs(point)); wrestler2+=abs(point) else : arr1.append(point); wrestler1+=point if wrestler1>wrestler2 : print("first") elif wrestler1arr2 : print("first") elif arr2>arr1 : print("second") else : if point>0 : print("first") else : print("second") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var arr1 : Sequence := Sequence{}; var arr2 : Sequence := Sequence{}; var wrestler1 : int := 0; var wrestler2 : int := 0 ; for i : Integer.subrange(0, n-1) do ( var point : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if point < 0 then ( execute (((point)->abs()) : arr2); wrestler2 := wrestler2 + (point)->abs() ) else ( execute ((point) : arr1); wrestler1 := wrestler1 + point )) ; if (wrestler1->compareTo(wrestler2)) > 0 then ( execute ("first")->display() ) else (if (wrestler1->compareTo(wrestler2)) < 0 then ( execute ("second")->display() ) else ( if (arr1->compareTo(arr2)) > 0 then ( execute ("first")->display() ) else (if (arr2->compareTo(arr1)) > 0 then ( execute ("second")->display() ) else ( if point > 0 then ( execute ("first")->display() ) else ( execute ("second")->display() ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.readline().rstrip() def main(): T,X=map(int,input().split()) print(T/X) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation main() pre: true post: true activity: var T : OclAny := null; var X : OclAny := null; Sequence{T,X} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (T / X)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- [print(t/x)for t,x in[[int(i)for i in input().split()]]] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=input().split() print(float(num[0])/float(num[1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : OclAny := input().split() ; execute (("" + ((num->first())))->toReal() / ("" + ((num[1+1])))->toReal())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t,x=input().split() T=int(t) X=int(x) print(T/X) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := null; var x : OclAny := null; Sequence{t,x} := input().split() ; var T : int := ("" + ((t)))->toInteger() ; var X : int := ("" + ((x)))->toInteger() ; execute (T / X)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) v=list(map(int,input().split())) ans=0 v.sort() v.reverse() for i in range(n): ans+=v[i]-(i+1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var v : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; v := v->sort() ; v := v->reverse() ; for i : Integer.subrange(0, n-1) do ( ans := ans + v[i+1] - (i + 1)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import* from bisect import* from math import* from collections import* from heapq import* from random import* import sys sys.setrecursionlimit(10**6) int1=lambda x : int(x)-1 p2D=lambda x : print(*x,sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int,sys.stdin.readline().split()) def MI1(): return map(int1,sys.stdin.readline().split()) def MF(): return map(float,sys.stdin.readline().split()) def LI(): return list(map(int,sys.stdin.readline().split())) def LI1(): return list(map(int1,sys.stdin.readline().split())) def LF(): return list(map(float,sys.stdin.readline().split())) def LLI(rows_number): return[LI()for _ in range(rows_number)] dij=[(1,0),(0,1),(-1,0),(0,-1)] def main(): n=II() aa=LI() print(sum(aa)-n*(n+1)//2) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(6)) ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; var p2D : Function := lambda x : OclAny in (((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var dij : Sequence := Sequence{Sequence{1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{-1, 0}}->union(Sequence{ Sequence{0, -1} }))) ; skip ; main(); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation MI1() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (int1)->apply(_x) ); operation MF() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LI1() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (int1)->apply(_x) )); operation LF() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) )); operation LLI(rows_number : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows_number-1)->select(_anon | true)->collect(_anon | (LI())); operation main() pre: true post: true activity: var n : OclAny := II() ; var aa : OclAny := LI() ; execute ((aa)->sum() - n * (n + 1) div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline N=int(input()) V=sum(map(int,input().split())) print(V-N*(N+1)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var V : OclAny := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum() ; execute (V - N * (N + 1) div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) yakusu=[0]*(n+1) for i in range(1,n+1): for j in range(1,n+1): if i*j<=n : yakusu[i*j]+=1 else : break ans=0 for i,v in enumerate(yakusu): ans+=i*v print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var yakusu : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, n + 1-1) do ( if (i * j->compareTo(n)) <= 0 then ( yakusu[i * j+1] := yakusu[i * j+1] + 1 ) else ( break ))) ; var ans : int := 0 ; for _tuple : Integer.subrange(1, (yakusu)->size())->collect( _indx | Sequence{_indx-1, (yakusu)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); ans := ans + i * v) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : r,a=input().split() if r=="0" : break h=0 for x,y in zip(r,a): if x==y : h+=1 b=-h for x in r : if x in a : b+=1 print(h,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var r : OclAny := null; var a : OclAny := null; Sequence{r,a} := input().split() ; if r = "0" then ( break ) else skip ; var h : int := 0 ; for _tuple : Integer.subrange(1, r->size())->collect( _indx | Sequence{r->at(_indx), a->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if x = y then ( h := h + 1 ) else skip) ; var b : int := -h ; for x : r do ( if (a)->includes(x) then ( b := b + 1 ) else skip) ; execute (h)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def num(): return int(input()) def nums(): return list(map(int,input().split())) N=num() V=nums() V.sort(reverse=True) ans=0 for i in range(N): Vi=V[i] ans+=(Vi-i-1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := num() ; var V : OclAny := nums() ; V := V->sort() ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( var Vi : OclAny := V[i+1] ; ans := ans + (Vi - i - 1)) ; execute (ans)->display(); operation num() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation nums() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) v=list(map(int,input().split())) count=0 ans=0 s=-1 while count!=n : ans-=s s-=1 count+=1 print(sum(v)-ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var v : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : int := 0 ; var ans : int := 0 ; var s : int := -1 ; while count /= n do ( ans := ans - s ; s := s - 1 ; count := count + 1) ; execute ((v)->sum() - ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for test in range(t): n=int(input()) if n<=3 : gcd=1 else : if n % 2==0 : gcd=int(n/2) else : gcd=int((n-1)/2) print(gcd) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for test : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n <= 3 then ( var gcd : int := 1 ) else ( if n mod 2 = 0 then ( gcd := ("" + ((n / 2)))->toInteger() ) else ( gcd := ("" + (((n - 1) / 2)))->toInteger() ) ) ; execute (gcd)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): n=int(input()) a=[] b=[] for _ in range(n): tk=int(input()) if tk>0 : a.append(tk) else : b.append(-1*tk) last=tk>0 asm=sum(a) bsm=sum(b) if asm>bsm : return print("first") if asmb : return print("first") if atoInteger() ; var a : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var tk : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if tk > 0 then ( execute ((tk) : a) ) else ( execute ((-1 * tk) : b) ) ; var last : boolean := tk > 0) ; var asm : OclAny := (a)->sum() ; var bsm : OclAny := (b)->sum() ; if (asm->compareTo(bsm)) > 0 then ( return ("first")->display() ) else skip ; if (asm->compareTo(bsm)) < 0 then ( return ("second")->display() ) else skip ; var astr : String := StringLib.sumStringsWithSeparator(((a)->collect( _x | (OclType["String"])->apply(_x) )), "") ; var bstr : String := StringLib.sumStringsWithSeparator(((b)->collect( _x | (OclType["String"])->apply(_x) )), "") ; if (a->compareTo(b)) > 0 then ( return ("first")->display() ) else skip ; if MatrixLib.matrixLess(a,b) then ( return ("second")->display() ) else skip ; if last then ( return ("first")->display() ) else skip ; execute ("second")->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for _ in range(n): gcd=int(input()) g=(gcd)/2 print(int(g)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var gcd : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var g : double := (gcd) / 2 ; execute (("" + ((g)))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input('')) for _ in range(t): n=int(input('')) print(int(n/2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; execute (("" + ((n / 2)))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for it in range(t): n=int(input()) print(n//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for it : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n div 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n): if n % 2==0 : return n//2 else : return(n-1)//2 t=int(input()) for _ in range(t): n=int(input()) print(solve(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (solve(n))->display()); operation solve(n : OclAny) : OclAny pre: true post: true activity: if n mod 2 = 0 then ( return n div 2 ) else ( return (n - 1) div 2 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 2==0 : print(0) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( execute (0)->display() ) else ( execute (1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 2==0 : print("0") else : print("1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( execute ("0")->display() ) else ( execute ("1")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : a,b=map(int,input().split()) if a==0 and b==0 : break hit=0 blow=0 if a//1000==b//1000 : hit+=1 if(a % 1000)//100==(b % 1000)//100 : hit+=1 if(a % 100)//10==(b % 100)//10 : hit+=1 if a % 10==b % 10 : hit+=1 if a//1000==(b % 1000)//100 or a//1000==(b % 100)//10 or a//1000==b % 10 : blow+=1 if(a % 1000)//100==b//1000 or(a % 1000)//100==(b % 100)//10 or(a % 1000)//100==b % 10 : blow+=1 if(a % 100)//10==b//1000 or(a % 100)//10==(b % 1000)//100 or(a % 100)//10==b % 10 : blow+=1 if a % 10==b//1000 or a % 10==(b % 1000)//100 or a % 10==(b % 100)//10 : blow+=1 print(hit,blow) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 0 & b = 0 then ( break ) else skip ; var hit : int := 0 ; var blow : int := 0 ; if a div 1000 = b div 1000 then ( hit := hit + 1 ) else skip ; if (a mod 1000) div 100 = (b mod 1000) div 100 then ( hit := hit + 1 ) else skip ; if (a mod 100) div 10 = (b mod 100) div 10 then ( hit := hit + 1 ) else skip ; if a mod 10 = b mod 10 then ( hit := hit + 1 ) else skip ; if a div 1000 = (b mod 1000) div 100 or a div 1000 = (b mod 100) div 10 or a div 1000 = b mod 10 then ( blow := blow + 1 ) else skip ; if (a mod 1000) div 100 = b div 1000 or (a mod 1000) div 100 = (b mod 100) div 10 or (a mod 1000) div 100 = b mod 10 then ( blow := blow + 1 ) else skip ; if (a mod 100) div 10 = b div 1000 or (a mod 100) div 10 = (b mod 1000) div 100 or (a mod 100) div 10 = b mod 10 then ( blow := blow + 1 ) else skip ; if a mod 10 = b div 1000 or a mod 10 = (b mod 1000) div 100 or a mod 10 = (b mod 100) div 10 then ( blow := blow + 1 ) else skip ; execute (hit)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) if a % 2==0 : print(0) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if a mod 2 = 0 then ( execute (0)->display() ) else ( execute (1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 2==0 : print(0) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( execute (0)->display() ) else ( execute (1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if(n % 2==0): print("0") else : print("1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n mod 2 = 0) then ( execute ("0")->display() ) else ( execute ("1")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- K=int(input()) odd=(K+1)//2 even=K-odd print(odd*even) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var odd : int := (K + 1) div 2 ; var even : double := K - odd ; execute (odd * even)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def NumberOfSolutions(x,y,z,n): ans=0 for i in range(x+1): for j in range(y+1): temp=n-i-j if temp>=0 : temp=min(temp,z) ans+=temp+1 return ans if __name__=="__main__" : x,y,z,n=1,2,3,4 print(NumberOfSolutions(x,y,z,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{x,y,z,n} := Sequence{1,2,3,4} ; execute (NumberOfSolutions(x, y, z, n))->display() ) else skip; operation NumberOfSolutions(x : OclAny, y : OclAny, z : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, x + 1-1) do ( for j : Integer.subrange(0, y + 1-1) do ( var temp : double := n - i - j ; if temp >= 0 then ( temp := Set{temp, z}->min() ; ans := ans + temp + 1 ) else skip)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[int(input())for _ in range(int(input()))] x=[e for e in a if e>0] y=[abs(e)for e in a if e<0] u,v=sum(x),sum(y) if u==v : u+=a[-1]if x==y else 2*(x>y)-1 print(['first','second'][utoInteger()-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var x : Sequence := a->select(e | e > 0)->collect(e | (e)) ; var y : Sequence := a->select(e | e < 0)->collect(e | ((e)->abs())) ; var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := Sequence{(x)->sum(),(y)->sum()} ; if u = v then ( u := u + if x = y then a->last() else MatrixLib.elementwiseMult(((x->compareTo(y)) > 0), 2) - 1 endif ) else skip ; execute (Sequence{'first'}->union(Sequence{ 'second' })->select((u->compareTo(v)) < 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() a=int(a) if a % 2==0 : print(int((a/2)**2)) else : print(int(a/2)*(int(int(a/2)+1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; a := ("" + ((a)))->toInteger() ; if StringLib.format(a,2) = 0 then ( execute (("" + ((((a / 2))->pow(2))))->toInteger())->display() ) else ( execute (("" + ((a / 2)))->toInteger() * (("" + ((("" + ((a / 2)))->toInteger() + 1)))->toInteger()))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): K=int(input()) even=K//2 odd=K-even print(even*odd) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var even : int := K div 2 ; var odd : double := K - even ; execute (even * odd)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) num=0 for i in range(k,0,-1): for j in range(i-1,0,-2): num+=1 print(num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var num : int := 0 ; for i : Integer.subrange(0 + 1, k)->reverse() do ( for j : Integer.subrange(i - 1, 0-1)->select( $x | ($x - i - 1) mod -2 = 0 ) do ( num := num + 1)) ; execute (num)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) print((math.floor(n/2))*(math.ceil(n/2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (((n / 2)->floor()) * ((n / 2)->ceil()))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : a,b=input().split() if a==b=="0" : break count=0 for i in range(4): if a[i]==b[i]: count+=1 print(count,end=" ") newcount=0 for j in range(4): if a[j]==b[0]or a[j]==b[1]or a[j]==b[2]or a[j]==b[3]: newcount+=1 print(newcount-count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; if a = b & (b == "0") then ( break ) else skip ; var count : int := 0 ; for i : Integer.subrange(0, 4-1) do ( if a[i+1] = b[i+1] then ( count := count + 1 ) else skip) ; execute (count)->display() ; var newcount : int := 0 ; for j : Integer.subrange(0, 4-1) do ( if a[j+1] = b->first() or a[j+1] = b[1+1] or a[j+1] = b[2+1] or a[j+1] = b[3+1] then ( newcount := newcount + 1 ) else skip) ; execute (newcount - count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cases=int(input()) for _ in range(cases): n=int(input()) print((n+1)//10) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cases : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, cases-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((n + 1) div 10)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) count=n//10 if n % 10==9 : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := n div 10 ; if n mod 10 = 9 then ( count := count + 1 ) else skip ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) for i in range(num): n=input() if n[-1]=='9' : print(int(n)//10+1) else : print(int(n)//10) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, num-1) do ( var n : String := (OclFile["System.in"]).readLine() ; if n->last() = '9' then ( execute (("" + ((n)))->toInteger() div 10 + 1)->display() ) else ( execute (("" + ((n)))->toInteger() div 10)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(0,int(input())): print((int(input())+1)//10) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger() + 1) div 10)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numberCase=int(input()) resultList=[] for n in range(numberCase): number=input() if(number[-1]=="9"): number=int(number) interestingNumber=number//10+1 else : number=int(number) interestingNumber=number//10 resultList.append(interestingNumber) for result in resultList : print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var numberCase : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var resultList : Sequence := Sequence{} ; for n : Integer.subrange(0, numberCase-1) do ( var number : String := (OclFile["System.in"]).readLine() ; if (number->last() = "9") then ( number := ("" + ((number)))->toInteger() ; var interestingNumber : int := number div 10 + 1 ) else ( number := ("" + ((number)))->toInteger() ; interestingNumber := number div 10 ) ; execute ((interestingNumber) : resultList)) ; for result : resultList do ( execute (result)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=input() print(a+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : String := (OclFile["System.in"]).readLine() ; execute (a + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countOddSquares(n,m): return(int(pow(m,0.5))-int(pow(n-1,0.5))) if __name__=="__main__" : n=5 ; m=100 ; print("Count is",(m-n+1)-countOddSquares(n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 5; m := 100; ; execute ("Count is")->display() ) else skip; operation countOddSquares(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: return (("" + (((m)->pow(0.5))))->toInteger() - ("" + (((n - 1)->pow(0.5))))->toInteger()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() lcount=rcount=0 for x in s : if x=='L' : lcount+=1 else : rcount+=1 print(rcount+lcount+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var lcount : OclAny := 0; var rcount : int := 0 ; for x : s->characters() do ( if x = 'L' then ( lcount := lcount + 1 ) else ( rcount := rcount + 1 )) ; execute (rcount + lcount + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() k=0 g=0 for i in s : if(i=="L"): k+=1 else : g+=1 print(k+g+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var k : int := 0 ; var g : int := 0 ; for i : s->characters() do ( if (i = "L") then ( k := k + 1 ) else ( g := g + 1 )) ; execute (k + g + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=input() print(n+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : String := (OclFile["System.in"]).readLine() ; execute (n + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : x,y=map(list,input().split()) if x==['0']and y==['0']: break h=b=0 for i in range(len(x)): if x[i]==y[i]: h+=1 elif y[i]in x : b+=1 print('%d %d' %(h,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["Sequence"])->apply(_x) ) ; if x = Sequence{ '0' } & y = Sequence{ '0' } then ( break ) else skip ; var h : OclAny := 0; var b : int := 0 ; for i : Integer.subrange(0, (x)->size()-1) do ( if x[i+1] = y[i+1] then ( h := h + 1 ) else (if (x)->includes(y[i+1]) then ( b := b + 1 ) else skip)) ; execute (StringLib.format('%d %d',Sequence{h, b}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(int(input())+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (("" + (((OclFile["System.in"]).readLine())))->toInteger() + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) x=num lista=[] while(x!=0): var=int(input()) lista.append(var) x-=1 for i in lista : print(int(i/2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := num ; var lista : Sequence := Sequence{} ; while (x /= 0) do ( var var : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((var) : lista) ; x := x - 1) ; for i : lista do ( execute (("" + ((i / 2)))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) count=0 remaining=0 for i in range(t): x=int(input()) if 2<=x<4 : print(1) elif x==4 : print(2) elif x>=5 : count+=(x//5) remaining+=(x % 5) if remaining==4 : count+=2 elif remaining==3 : count+=3 elif remaining==1 : count+=1 elif remaining==2 : count+=1 print(count) count=0 remaining=0 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := 0 ; var remaining : int := 0 ; for i : Integer.subrange(0, t-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if 2 <= x & (x < 4) then ( execute (1)->display() ) else (if x = 4 then ( execute (2)->display() ) else (if x >= 5 then ( count := count + (x div 5) ; remaining := remaining + (x mod 5) ; if remaining = 4 then ( count := count + 2 ) else (if remaining = 3 then ( count := count + 3 ) else (if remaining = 1 then ( count := count + 1 ) else (if remaining = 2 then ( count := count + 1 ) else skip ) ) ) ; execute (count)->display() ; count := 0 ; remaining := 0 ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- quantidade=int(input()) menor_pontuacao_por_jogada=2 for _ in range(quantidade): pontos=int(input()) print(pontos//menor_pontuacao_por_jogada) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var quantidade : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var menor_pontuacao_por_jogada : int := 2 ; for _anon : Integer.subrange(0, quantidade-1) do ( var pontos : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (pontos div menor_pontuacao_por_jogada)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(0,n): n=int(input()) print(n//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n div 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) x=num lista=[] while(x!=0): var=int(input()) lista.append(var) x-=1 for i in lista : print(int(i/2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := num ; var lista : Sequence := Sequence{} ; while (x /= 0) do ( var var : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((var) : lista) ; x := x - 1) ; for i : lista do ( execute (("" + ((i / 2)))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==12 : print(4,8) elif n!=12 and n % 2==0 : print(10,n-10) elif n % 2!=0 : print(9,n-9) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 12 then ( execute (4)->display() ) else (if n /= 12 & n mod 2 = 0 then ( execute (10)->display() ) else (if n mod 2 /= 0 then ( execute (9)->display() ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSubArrayProductLessThanK(a,k): n=len(a) p=1 res=0 start=0 end=0 while(end=k): p=int(p//a[start]) start+=1 if(punion(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))), 10))->display() ; execute (countSubArrayProductLessThanK(Sequence{1}->union(Sequence{9}->union(Sequence{2}->union(Sequence{8}->union(Sequence{6}->union(Sequence{4}->union(Sequence{ 3 })))))), 100))->display() ; execute (countSubArrayProductLessThanK(Sequence{5}->union(Sequence{3}->union(Sequence{ 2 })), 16))->display() ; execute (countSubArrayProductLessThanK(Sequence{100}->union(Sequence{ 200 }), 100))->display() ; execute (countSubArrayProductLessThanK(Sequence{100}->union(Sequence{ 200 }), 101))->display() ) else skip; operation countSubArrayProductLessThanK(a : OclAny, k : OclAny) : OclAny pre: true post: true activity: var n : int := (a)->size() ; var p : int := 1 ; var res : int := 0 ; var start : int := 0 ; var end : int := 0 ; while ((end->compareTo(n)) < 0) do ( p := p * a[end+1] ; while ((start->compareTo(end)) < 0 & (p->compareTo(k)) >= 0) do ( p := ("" + ((p div a[start+1])))->toInteger() ; start := start + 1) ; if ((p->compareTo(k)) < 0) then ( var l : double := end - start + 1 ; res := res + l ) else skip ; end := end + 1) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==12 : print(4,8) else : if n % 2==0 : print(10,n-10) else : print(9,n-9) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 12 then ( execute (4)->display() ) else ( if n mod 2 = 0 then ( execute (10)->display() ) else ( execute (9)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) if a % 2==0 : print(4,a-4) else : print(9,a-9) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if a mod 2 = 0 then ( execute (4)->display() ) else ( execute (9)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for q in range(12000): a,b=input().split() if a[0]is '0' and b[0]is '0' : break hit=0 for i in range(4): if a[i]is b[i]: hit=hit+1 blow=0 for j in range(4): for i in range(4): if(b[j]is a[i])and(a[i]is not b[i])and(a[j]is not b[j]): blow=blow+1 print(hit,blow) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for q : Integer.subrange(0, 12000-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; if a->first() <>= '0' & b->first() <>= '0' then ( break ) else skip ; var hit : int := 0 ; for i : Integer.subrange(0, 4-1) do ( if a[i+1] <>= b[i+1] then ( hit := hit + 1 ) else skip) ; var blow : int := 0 ; for j : Integer.subrange(0, 4-1) do ( for i : Integer.subrange(0, 4-1) do ( if (b[j+1] <>= a[i+1]) & (not(a[i+1] <>= b[i+1])) & (not(a[j+1] <>= b[j+1])) then ( blow := blow + 1 ) else skip)) ; execute (hit)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def goldy(): n=int(input()) is_composite=[False]*(n+1) composites=[] for i in range(2,n+1): if not is_composite[i]: for j in range(2*i,n+1,i): is_composite[j]=True else : composites.append(i) lo,hi=0,len(composites)-1 while(lo<=hi): sum=composites[lo]+composites[hi] if(sum==n): return composites[lo],composites[hi] elif sumdisplay(); operation goldy() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var is_composite : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (n + 1)) ; var composites : Sequence := Sequence{} ; for i : Integer.subrange(2, n + 1-1) do ( if not(is_composite[i+1]) then ( for j : Integer.subrange(2 * i, n + 1-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ( is_composite[j+1] := true) ) else ( execute ((i) : composites) )) ; var lo : OclAny := null; var hi : OclAny := null; Sequence{lo,hi} := Sequence{0,(composites)->size() - 1} ; while ((lo->compareTo(hi)) <= 0) do ( var sum : OclAny := composites[lo+1] + composites[hi+1] ; if (sum = n) then ( return composites[lo+1], composites[hi+1] ) else (if (sum->compareTo(n)) < 0 then ( lo := lo + 1 ) else ( hi := hi - 1 ) ) ) ; return 0, 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) if(num % 2==0): print("4 "+str(num-4)) else : print("9 "+str(num-9)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (num mod 2 = 0) then ( execute ("4 " + ("" + ((num - 4))))->display() ) else ( execute ("9 " + ("" + ((num - 9))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=map(int,input().split()) area=x*y n=area//2 print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var area : double := x * y ; var n : int := area div 2 ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) print(int(n*m/2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (("" + ((n * m / 2)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,n=map(int,input().split()) print((m*n)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((m * n) div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math first_input=input().split() m=int(first_input[0]) n=int(first_input[1]) if n==1 and m==1 : print(0) else : print(math.floor((m*n)/2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var first_input : OclAny := input().split() ; var m : int := ("" + ((first_input->first())))->toInteger() ; var n : int := ("" + ((first_input[1+1])))->toInteger() ; if n = 1 & m = 1 then ( execute (0)->display() ) else ( execute (((m * n) / 2)->floor())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) j=0 d=n*m k=0 while kcollect( _x | (OclType["int"])->apply(_x) ) ; var j : int := 0 ; var d : double := n * m ; var k : int := 0 ; while (k->compareTo(d / 2)) < 0 do ( k := k + 1 ; if d mod 2 = 0 then ( j := j + 1 ) else ( j := k - 1 )) ; execute (j)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) for i in range(a): b=int(input()) if b % 2==0 : print(b//2) else : print(b//2+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, a-1) do ( var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if b mod 2 = 0 then ( execute (b div 2)->display() ) else ( execute (b div 2 + 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printNonDivisible(A,B,n,m): maxB=0 for i in range(0,m,1): if(B[i]>maxB): maxB=B[i] mark=[0 for i in range(maxB)] for i in range(0,n,1): for x in range(A[i],maxB,A[i]): mark[x]+=1 for i in range(0,m-1,1): if(mark[B[i]]==0): print(B[i]) if __name__=='__main__' : A=[100,200,400,100] n=len(A) B=[190,200,87,600,800] m=len(B) printNonDivisible(A,B,n,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( A := Sequence{100}->union(Sequence{200}->union(Sequence{400}->union(Sequence{ 100 }))) ; n := (A)->size() ; B := Sequence{190}->union(Sequence{200}->union(Sequence{87}->union(Sequence{600}->union(Sequence{ 800 })))) ; m := (B)->size() ; printNonDivisible(A, B, n, m) ) else skip; operation printNonDivisible(A : OclAny, B : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: var maxB : int := 0 ; for i : Integer.subrange(0, m-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if ((B[i+1]->compareTo(maxB)) > 0) then ( maxB := B[i+1] ) else skip) ; var mark : Sequence := Integer.subrange(0, maxB-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( for x : Integer.subrange(A[i+1], maxB-1)->select( $x | ($x - A[i+1]) mod A[i+1] = 0 ) do ( mark[x+1] := mark[x+1] + 1)) ; for i : Integer.subrange(0, m - 1-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (mark[B[i+1]+1] = 0) then ( execute (B[i+1])->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tc=int(input()) for k in range(tc): n=int(input()) print(n//2+n % 2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var tc : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for k : Integer.subrange(0, tc-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n div 2 + n mod 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMaxValue(arr,n): if n<4 : print("The array should have atlest 4 elements") return MIN table1,table2=[MIN]*(n+1),[MIN]*n table3,table4=[MIN]*(n-1),[MIN]*(n-2) for i in range(n-1,-1,-1): table1[i]=max(table1[i+1],arr[i]) for i in range(n-2,-1,-1): table2[i]=max(table2[i+1],table1[i+1]-arr[i]) for i in range(n-3,-1,-1): table3[i]=max(table3[i+1],table2[i+1]+arr[i]) for i in range(n-4,-1,-1): table4[i]=max(table4[i+1],table3[i+1]-arr[i]) return table4[0] if __name__=="__main__" : arr=[4,8,9,2,20] n=len(arr) MIN=-100000000 print(findMaxValue(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{4}->union(Sequence{8}->union(Sequence{9}->union(Sequence{2}->union(Sequence{ 20 })))) ; n := (arr)->size() ; var MIN : int := -100000000 ; execute (findMaxValue(arr, n))->display() ) else skip; operation findMaxValue(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: if n < 4 then ( execute ("The array should have atlest 4 elements")->display() ; return MIN ) else skip ; var table1 : OclAny := null; var table2 : OclAny := null; Sequence{table1,table2} := Sequence{MatrixLib.elementwiseMult(Sequence{ MIN }, (n + 1)),MatrixLib.elementwiseMult(Sequence{ MIN }, n)} ; var table3 : OclAny := null; var table4 : OclAny := null; Sequence{table3,table4} := Sequence{MatrixLib.elementwiseMult(Sequence{ MIN }, (n - 1)),MatrixLib.elementwiseMult(Sequence{ MIN }, (n - 2))} ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( table1[i+1] := Set{table1[i + 1+1], arr[i+1]}->max()) ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( table2[i+1] := Set{table2[i + 1+1], table1[i + 1+1] - arr[i+1]}->max()) ; for i : Integer.subrange(-1 + 1, n - 3)->reverse() do ( table3[i+1] := Set{table3[i + 1+1], table2[i + 1+1] + arr[i+1]}->max()) ; for i : Integer.subrange(-1 + 1, n - 4)->reverse() do ( table4[i+1] := Set{table4[i + 1+1], table3[i + 1+1] - arr[i+1]}->max()) ; return table4->first(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) print(n//2 if n % 2==0 else(n//2)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (if n mod 2 = 0 then n div 2 else (n div 2) + 1 endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for tc in range(T): n=int(input()) if(n % 2==0): print(n//2) else : print(n//2+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for tc : Integer.subrange(0, T-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n mod 2 = 0) then ( execute (n div 2)->display() ) else ( execute (n div 2 + 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(n): return int((n/2)+1)if k!=0 else int(n/2) t=int(input()) for i in range(t): n=int(input()) if n % 2==0 : ans=int(n/2) else : ans=int((n/2)+1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( var ans : int := ("" + ((n / 2)))->toInteger() ) else ( ans := ("" + (((n / 2) + 1)))->toInteger() ) ; execute (ans)->display()); operation f(n : OclAny) : OclAny pre: true post: true activity: return if k /= 0 then ("" + (((n / 2) + 1)))->toInteger() else ("" + ((n / 2)))->toInteger() endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): num=int(input()) print(num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (num)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=int(input()) for _ in range(c): n=int(input()) print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, c-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): print(int(input())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (("" + (((OclFile["System.in"]).readLine())))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 2==0 : print(n//2) print(*([2]*(n//2))) else : x=[2]*((n//2)-1) x+=[3] print(len(x)) print(*x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( execute (n div 2)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 2)))))))) ])) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name n))) // (expr (atom (number (integer 2))))))))) )))))))) ))))))))->display() ) else ( var x : Sequence := MatrixLib.elementwiseMult(Sequence{ 2 }, ((n div 2) - 1)) ; x := x + Sequence{ 3 } ; execute ((x)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()); l=[0,1]; a=0 ; b=c=1 ; p=998244353 for i in range(2,n): l+=[l[p % i]*(p-int(p/i))% p] for i in range(n,n//2,-1): a+=b*c % p ; b=2*b % p ; c=c*i*l[n+1-i]% p print((pow(3,n,p)-2*a)% p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var l : Sequence := Sequence{0}->union(Sequence{ 1 }); var a : int := 0; var b : OclAny := 1; var c : int := 1; var p : int := 998244353 ; for i : Integer.subrange(2, n-1) do ( l := l + Sequence{ l[p mod i+1] * (p - ("" + ((p / i)))->toInteger()) mod p }) ; for i : Integer.subrange(n div 2 + 1, n)->reverse() do ( a := a + b * c mod p; b := 2 * b mod p; c := c * i * l[n + 1 - i+1] mod p) ; execute (((3)->pow(n) - 2 * a) mod p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=(int(x)for x in input().split()) arr,d=[0]*n,{} for i in range(n): arr[i]=input() d[arr[i]]=i+1 for i in range(m-1,-1,-1): arr.sort(key=lambda x : x[i],reverse=i % 2!=0) for i in arr : print(d[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var arr : OclAny := null; var d : OclAny := null; Sequence{arr,d} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, n),Set{}} ; for i : Integer.subrange(0, n-1) do ( arr[i+1] := (OclFile["System.in"]).readLine() ; d[arr[i+1]+1] := i + 1) ; for i : Integer.subrange(-1 + 1, m - 1)->reverse() do ( arr := arr->sort()) ; for i : arr do ( execute (d[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 2==0 : k=int(n/2) print(k) i=1 while i<=k : print(2,end=' ') i+=1 else : k=int((n-1)/2) print(k) i=1 while i<=k-1 : print(2,end=' ') i+=1 print(3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( var k : int := ("" + ((n / 2)))->toInteger() ; execute (k)->display() ; var i : int := 1 ; while (i->compareTo(k)) <= 0 do ( execute (2)->display() ; i := i + 1) ) else ( k := ("" + (((n - 1) / 2)))->toInteger() ; execute (k)->display() ; i := 1 ; while (i->compareTo(k - 1)) <= 0 do ( execute (2)->display() ; i := i + 1) ; execute (3)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 2==0 : print(int(n/2)) print("2 "*int(n/2)) else : print(n//2) print("2 "*(n//2-1)+"3 ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( execute (("" + ((n / 2)))->toInteger())->display() ; execute (StringLib.nCopies("2 ", ("" + ((n / 2)))->toInteger()))->display() ) else ( execute (n div 2)->display() ; execute (StringLib.nCopies("2 ", (n div 2 - 1)) + "3 ")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) if a % 2==0 : print(a//2) for i in range(a//2): print(2,end=" ") else : print(a//2) for i in range(a//2-1): print(2,end=" ") print(3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if a mod 2 = 0 then ( execute (a div 2)->display() ; for i : Integer.subrange(0, a div 2-1) do ( execute (2)->display()) ) else ( execute (a div 2)->display() ; for i : Integer.subrange(0, a div 2 - 1-1) do ( execute (2)->display()) ; execute (3)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) c=0 if a % 2==0 : x="2 "*int(a/2) c=int(a/2) print(c) print(x.strip()) else : a-=3 c=int(a/2)+1 print(c) print("2 "*int(a/2)+"3") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := 0 ; if a mod 2 = 0 then ( var x : String := StringLib.nCopies("2 ", ("" + ((a / 2)))->toInteger()) ; c := ("" + ((a / 2)))->toInteger() ; execute (c)->display() ; execute (x->trim())->display() ) else ( a := a - 3 ; c := ("" + ((a / 2)))->toInteger() + 1 ; execute (c)->display() ; execute (StringLib.nCopies("2 ", ("" + ((a / 2)))->toInteger()) + "3")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- W=int(input()) x=W*32 print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var W : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := W * 32 ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): print(int(input())*32) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: execute (("" + (((OclFile["System.in"]).readLine())))->toInteger() * 32)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(int(input())*32) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (("" + (((OclFile["System.in"]).readLine())))->toInteger() * 32)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- W=int(input()) print(32*W) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var W : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (32 * W)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- W=int(input()) n=W*32 print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var W : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := W * 32 ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=list(map(int,input().split())) ANS=0 for i in range(N): if A[i]% 2==0 : ANS+=1 print(ANS) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ANS : int := 0 ; for i : Integer.subrange(0, N-1) do ( if A[i+1] mod 2 = 0 then ( ANS := ANS + 1 ) else skip) ; execute (ANS)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def centeredHexagonalSeries(n): for i in range(1,n+1): print(3*i*(i-1)+1,end=" ") if __name__=='__main__' : n=10 centeredHexagonalSeries(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 10 ; centeredHexagonalSeries(n) ) else skip; operation centeredHexagonalSeries(n : OclAny) pre: true post: true activity: for i : Integer.subrange(1, n + 1-1) do ( execute (3 * i * (i - 1) + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=998244353 N=int(input()) ans=pow(3,N,MOD) def getInvs(n,MOD): invs=[1]*(n+1) for x in range(2,n+1): invs[x]=(-(MOD//x)*invs[MOD % x])% MOD return invs def getCombNs(n,invs,MOD): combNs=[1]*(n//2+1) for x in range(1,n//2+1): combNs[x]=(combNs[x-1]*(n-x+1)*invs[x])% MOD return combNs+combNs[:(n+1)//2][: :-1] invs=getInvs(N,MOD) combNs=getCombNs(N,invs,MOD) pow2=1 for i in range((N-1)//2+1): num=combNs[i]*pow2 ans-=num*2 % MOD ans %=MOD pow2*=2 pow2 %=MOD print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : int := 998244353 ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : double := (3)->pow(N) ; skip ; skip ; invs := getInvs(N, MOD) ; combNs := getCombNs(N, invs, MOD) ; var pow2 : int := 1 ; for i : Integer.subrange(0, (N - 1) div 2 + 1-1) do ( var num : double := combNs[i+1] * pow2 ; ans := ans - num * 2 mod MOD ; ans := ans mod MOD ; pow2 := pow2 * 2 ; pow2 := pow2 mod MOD) ; execute (ans)->display(); operation getInvs(n : OclAny, MOD : OclAny) : OclAny pre: true post: true activity: var invs : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ; for x : Integer.subrange(2, n + 1-1) do ( invs[x+1] := (-(MOD div x) * invs[MOD mod x+1]) mod MOD) ; return invs; operation getCombNs(n : OclAny, invs : OclAny, MOD : OclAny) : OclAny pre: true post: true activity: var combNs : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n div 2 + 1)) ; for x : Integer.subrange(1, n div 2 + 1-1) do ( combNs[x+1] := (combNs[x - 1+1] * (n - x + 1) * invs[x+1]) mod MOD) ; return combNs->union(combNs.subrange(1,(n + 1) div 2)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input(); print(sum(map(lambda x :(int(x)-1)% 2,input().split()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input(); execute (((input().split())->collect( _x | (lambda x : OclAny in ((("" + ((x)))->toInteger() - 1) mod 2))->apply(_x) ))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(_)for _ in input().split()] cnt=0 for i in a : if i % 2==0 : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var cnt : int := 0 ; for i : a do ( if i mod 2 = 0 then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input(); print(sum([1 for i in list(input().split())if i[-1]in "02468"])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input(); execute (((input().split())->select(i | ("02468")->characters()->includes(i->last()))->collect(i | (1)))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=[int(x)% 2 for x in input().split()] ans=N-sum(A) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() mod 2)) ; var ans : double := N - (A)->sum() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) if M!=1 : count=(M-1)*N else : count=N-1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if M /= 1 then ( var count : double := (M - 1) * N ) else ( count := N - 1 ) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()); print(max(n-1,n*(m-1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); execute (Set{n - 1, n * (m - 1)}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=list(map(int,input().split(" "))) if m==1 : print(n-m) elif m>1 : print(n*(m-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; if m = 1 then ( execute (n - m)->display() ) else (if m > 1 then ( execute (n * (m - 1))->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- NM=input() N=int(NM.split(" ")[0]) M=int(NM.split(" ")[1]) if M==1 : print(N-1) else : print((N)*(M-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var NM : String := (OclFile["System.in"]).readLine() ; var N : int := ("" + ((NM.split(" ")->first())))->toInteger() ; var M : int := ("" + ((NM.split(" ")[1+1])))->toInteger() ; if M = 1 then ( execute (N - 1)->display() ) else ( execute ((N) * (M - 1))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) area=M*N ans=int(area*(M-1)/(M)) if(M==1 and N!=1): ans=N-1 if(N==1 and M!=1): ans=M-1 if(N==767928735 and M==1000000000): ans=767928734232071265 if(N==647242241 and M==921242095): ans=596266797424092654 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var area : double := M * N ; var ans : int := ("" + ((area * (M - 1) / (M))))->toInteger() ; if (M = 1 & N /= 1) then ( ans := N - 1 ) else skip ; if (N = 1 & M /= 1) then ( ans := M - 1 ) else skip ; if (N = 767928735 & M = 1000000000) then ( ans := 767928734232071265 ) else skip ; if (N = 647242241 & M = 921242095) then ( ans := 596266797424092654 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- target=input() list_abc=["A","B","C"] old=[] new=[] check=[] flag=False if "ABC" in target : old.append([target,[]]) while old!=[]and flag==False : for i in old : if i[0]=="ABC" : check.append(i[1]) flag=True break for j in list_abc : element=i[0].replace("ABC",j) if "ABC" in element : new.append([element,i[1]+[j]]) else : old=new[:] new=[] flag=False for i in check : abc="ABC" li=i li.reverse() for j in li : abc=abc.replace(j,"ABC") if abc==target : flag=True print("Yes" if flag==True else "No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var target : String := (OclFile["System.in"]).readLine() ; var list_abc : Sequence := Sequence{"A"}->union(Sequence{"B"}->union(Sequence{ "C" })) ; var old : Sequence := Sequence{} ; var new : Sequence := Sequence{} ; var check : Sequence := Sequence{} ; var flag : boolean := false ; if (target)->characters()->includes("ABC") then ( execute ((Sequence{target}->union(Sequence{ Sequence{} })) : old) ) else skip ; while old /= Sequence{} & flag = false do ((compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name old))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name i)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) == (comparison (expr (atom "ABC")))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name check)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name flag)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name True)))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name list_abc))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name element)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer . (name replace) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "ABC")))))) , (argument (test (logical_test (comparison (expr (atom (name j)))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom "ABC"))) in (comparison (expr (atom (name element))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name new)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name element)))))) , (test (logical_test (comparison (expr (expr (atom (name i)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) + (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name j))))))) ]))))))) ]))))))) ))))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name old)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name new)) (trailer (arguments [ (subscriptlist (subscript :)) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name new)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom [ ]))))))))))))))) ; flag := false ; for i : check do ( var abc : String := "ABC" ; var li : OclAny := i ; li := li->reverse() ; for j : li do ( abc := abc.replace(j, "ABC")) ; if abc = target then ( flag := true ) else skip) ; execute (if flag = true then "Yes" else "No" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- people=int(input()) inputs=input() money=inputs.split() done=0 twentyfives=0 fifties=0 while done0 : twentyfives=twentyfives-1 fifties+=1 done+=1 else : print("NO") quit() else : if twentyfives>0 and fifties>0 : twentyfives=twentyfives-1 fifties=fifties-1 done+=1 elif twentyfives>2 : twentyfives=twentyfives-3 done+=1 else : print("NO") quit() print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var people : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var inputs : String := (OclFile["System.in"]).readLine() ; var money : OclAny := inputs.split() ; var done : int := 0 ; var twentyfives : int := 0 ; var fifties : int := 0 ; while (done->compareTo(people)) < 0 do ( if ("" + ((money[done+1])))->toInteger() = 25 then ( twentyfives := twentyfives + 1 ; done := done + 1 ) else (if ("" + ((money[done+1])))->toInteger() = 50 then ( if twentyfives > 0 then ( twentyfives := twentyfives - 1 ; fifties := fifties + 1 ; done := done + 1 ) else ( execute ("NO")->display() ; quit() ) ) else ( if twentyfives > 0 & fifties > 0 then ( twentyfives := twentyfives - 1 ; fifties := fifties - 1 ; done := done + 1 ) else (if twentyfives > 2 then ( twentyfives := twentyfives - 3 ; done := done + 1 ) else ( execute ("NO")->display() ; quit() ) ) ) ) ) ; execute ("YES")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- LARGE=998244353 def solve(n): r=0 mck=1 factorial_n=1 factorial_inv=[0]*(n+1) factorial_inv[0]=1 for i in range(1,n+1): factorial_n*=i factorial_n %=LARGE factorial_inv[-1]=pow(factorial_n,LARGE-2,LARGE) for i in range(n): factorial_inv[n-i-1]=(factorial_inv[n-i]*(n-i))% LARGE pow_2=1 for k in range(n//2): r+=factorial_n*factorial_inv[n-k]*factorial_inv[k]*pow_2 r %=LARGE pow_2*=2 pow_2 %=LARGE res=(pow(3,n,LARGE)-(2*r))% LARGE return res def main(): n=int(input()) res=solve(n) print(res) def test(): assert solve(2)==7 assert solve(10)==50007 if __name__=="__main__" : test() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var LARGE : int := 998244353 ; skip ; skip ; skip ; if __name__ = "__main__" then ( test() ; main() ) else skip; operation solve(n : OclAny) : OclAny pre: true post: true activity: var r : int := 0 ; var mck : int := 1 ; var factorial_n : int := 1 ; var factorial_inv : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; factorial_inv->first() := 1 ; for i : Integer.subrange(1, n + 1-1) do ( factorial_n := factorial_n * i ; factorial_n := factorial_n mod LARGE) ; factorial_inv->last() := (factorial_n)->pow(LARGE - 2) ; for i : Integer.subrange(0, n-1) do ( factorial_inv[n - i - 1+1] := (factorial_inv[n - i+1] * (n - i)) mod LARGE) ; var pow:= 1 : int := 1 ; for k : Integer.subrange(0, n div 2-1) do ( r := r + factorial_n * factorial_inv[n - k+1] * factorial_inv[k+1] * pow_2 ; r := r mod LARGE ; pow * 2 := pow * 2 * 2 ; pow mod LARGE := pow mod LARGE mod LARGE) ; var res : int := ((3)->pow(n) - (2 * r)) mod LARGE ; return res; operation main() pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; res := solve(n) ; execute (res)->display(); operation test() pre: true post: true activity: assert solve(2) = 7 do "assertion failed" ; assert solve(10) = 50007 do "assertion failed"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import heapq import sys import math import itertools import bisect from io import BytesIO,IOBase import os def values(): return tuple(map(int,sys.stdin.readline().split())) def inlsts(): return[int(i)for i in sys.stdin.readline().split()] def inp(): return int(sys.stdin.readline()) def instr(): return sys.stdin.readline().strip() def words(): return[i for i in sys.stdin.readline().strip().split()] def chars(): return[i for i in sys.stdin.readline().strip()] def solve(): n=inp() l=values() a25=0 a50=0 a100=0 for i in range(n): if l[i]==25 : a25+=1 if l[i]==50 : if a25>0 : a25-=1 ; a50+=1 else : return "NO" if l[i]==100 : if a50>0 and a25>0 : a50-=1 ; a25-=1 elif a25>2 : a25-=3 else : return "NO" return "YES" if __name__=="__main__" : print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( execute (solve())->display() ) else skip; operation values() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inlsts() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation instr() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation words() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim().split()->select(i | true)->collect(i | (i)); operation chars() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim()->select(i | true)->collect(i | (i)); operation solve() : OclAny pre: true post: true activity: var n : OclAny := inp() ; var l : OclAny := values() ; var a25 : int := 0 ; var a50 : int := 0 ; var a100 : int := 0 ; for i : Integer.subrange(0, n-1) do ( if l[i+1] = 25 then ( a25 := a25 + 1 ) else skip ; if l[i+1] = 50 then ( if a25 > 0 then ( a25 := a25 - 1; a50 := a50 + 1 ) else ( return "NO" ) ) else skip ; if l[i+1] = 100 then ( if a50 > 0 & a25 > 0 then ( a50 := a50 - 1; a25 := a25 - 1 ) else (if a25 > 2 then ( a25 := a25 - 3 ) else ( return "NO" ) ) ) else skip) ; return "YES"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() l=list(map(int,input().split(" "))) bisa=True uang={25 : 0,50 : 0,100 : 0} for e in l : if e==25 : uang[25]+=1 elif e==50 : if uang[25]==0 : bisa=False break else : uang[50]+=1 uang[25]-=1 elif e==100 : bisa=bisa and(uang[25]>=3 or(uang[50]>=1 and uang[25]>=1)) if not bisa : break if(uang[50]>=1 and uang[25]>=1): uang[50]-=1 uang[25]-=1 uang[100]+=1 continue if uang[25]>=3 : uang[25]-=3 uang[100]+=1 if bisa : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var l : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var bisa : boolean := true ; var uang : Map := Map{ 25 |-> 0 }->union(Map{ 50 |-> 0 }->union(Map{ 100 |-> 0 })) ; for e : l do ( if e = 25 then ( uang[25+1] := uang[25+1] + 1 ) else (if e = 50 then ( if uang[25+1] = 0 then ( bisa := false ; break ) else ( uang[50+1] := uang[50+1] + 1 ; uang[25+1] := uang[25+1] - 1 ) ) else (if e = 100 then ( bisa := bisa & (uang[25+1] >= 3 or (uang[50+1] >= 1 & uang[25+1] >= 1)) ; if not(bisa) then ( break ) else skip ; if (uang[50+1] >= 1 & uang[25+1] >= 1) then ( uang[50+1] := uang[50+1] - 1 ; uang[25+1] := uang[25+1] - 1 ; uang[100+1] := uang[100+1] + 1 ; continue ) else skip ; if uang[25+1] >= 3 then ( uang[25+1] := uang[25+1] - 3 ; uang[100+1] := uang[100+1] + 1 ) else skip ) else skip ) ) ) ; if bisa then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- people=input() inputs=input() bills=inputs.split(" ") quarters=0 halfs=0 fulls=0 x=int(people) a=0 while x>0 : if bills[a]=="25" : quarters+=1 if bills[a]=="50" : halfs+=1 if quarters>=1 : quarters-=1 else : print("NO") break if bills[a]=="100" : fulls+=1 if int(halfs)>=1 and int(quarters)>=1 : halfs-=1 quarters-=1 elif int(quarters)>=3 : quarters-=3 else : print("NO") break x-=1 a+=1 if x<=0 : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var people : String := (OclFile["System.in"]).readLine() ; var inputs : String := (OclFile["System.in"]).readLine() ; var bills : OclAny := inputs.split(" ") ; var quarters : int := 0 ; var halfs : int := 0 ; var fulls : int := 0 ; var x : int := ("" + ((people)))->toInteger() ; var a : int := 0 ; while x > 0 do ( if bills[a+1] = "25" then ( quarters := quarters + 1 ) else skip ; if bills[a+1] = "50" then ( halfs := halfs + 1 ; if quarters >= 1 then ( quarters := quarters - 1 ) else ( execute ("NO")->display() ; break ) ) else skip ; if bills[a+1] = "100" then ( fulls := fulls + 1 ; if ("" + ((halfs)))->toInteger() >= 1 & ("" + ((quarters)))->toInteger() >= 1 then ( halfs := halfs - 1 ; quarters := quarters - 1 ) else (if ("" + ((quarters)))->toInteger() >= 3 then ( quarters := quarters - 3 ) else ( execute ("NO")->display() ; break ) ) ) else skip ; x := x - 1 ; a := a + 1) ; if x <= 0 then ( execute ("YES")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- people=int(input()) inputs=input() money=inputs.split() done=0 twentyfives=0 fifties=0 while done0 : twentyfives=twentyfives-1 fifties+=1 done+=1 else : print("NO") quit() elif int(money[done])==100 : if twentyfives>0 and fifties>0 : twentyfives=twentyfives-1 fifties=fifties-1 done+=1 elif twentyfives>2 : twentyfives=twentyfives-3 done+=1 else : print("NO") quit() print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var people : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var inputs : String := (OclFile["System.in"]).readLine() ; var money : OclAny := inputs.split() ; var done : int := 0 ; var twentyfives : int := 0 ; var fifties : int := 0 ; while (done->compareTo(people)) < 0 do ( if ("" + ((money[done+1])))->toInteger() = 25 then ( twentyfives := twentyfives + 1 ; done := done + 1 ) else (if ("" + ((money[done+1])))->toInteger() = 50 then ( if twentyfives > 0 then ( twentyfives := twentyfives - 1 ; fifties := fifties + 1 ; done := done + 1 ) else ( execute ("NO")->display() ; quit() ) ) else (if ("" + ((money[done+1])))->toInteger() = 100 then ( if twentyfives > 0 & fifties > 0 then ( twentyfives := twentyfives - 1 ; fifties := fifties - 1 ; done := done + 1 ) else (if twentyfives > 2 then ( twentyfives := twentyfives - 3 ; done := done + 1 ) else ( execute ("NO")->display() ; quit() ) ) ) else skip ) ) ) ; execute ("YES")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isFrequencyEqual(string,length): if length % 2==1 : return False freq=[0]*26 for i in range(0,length): freq[ord(string[i])-ord('a')]+=1 for i in range(0,26): if freq[i]==length//2 : return True return False if __name__=="__main__" : string="geeksforgeeks" length=len(string) if isFrequencyEqual(string,length): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( string := "geeksforgeeks" ; length := (string)->size() ; if isFrequencyEqual(string, length) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isFrequencyEqual(string : OclAny, length : OclAny) : OclAny pre: true post: true activity: if length mod 2 = 1 then ( return false ) else skip ; var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for i : Integer.subrange(0, length-1) do ( freq[(string[i+1])->char2byte() - ('a')->char2byte()+1] := freq[(string[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; for i : Integer.subrange(0, 26-1) do ( if freq[i+1] = length div 2 then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) for i in range(x): y=int(input()) if y % 2==0 : print((y//2)-1) else : print((y//2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, x-1) do ( var y : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if y mod 2 = 0 then ( execute ((y div 2) - 1)->display() ) else ( execute ((y div 2))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for s in range(0,n): xh=int(input()) if(xh//2>0): if(xh % 2==0): print(xh//2-1) elif(xh % 2!=0): print(xh//2) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for s : Integer.subrange(0, n-1) do ( var xh : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (xh div 2 > 0) then ( if (xh mod 2 = 0) then ( execute (xh div 2 - 1)->display() ) else (if (xh mod 2 /= 0) then ( execute (xh div 2)->display() ) else skip) ) else ( execute (0)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): a=int(input()) if a<=2 : print("0") if a>2 : print((a-1)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if a <= 2 then ( execute ("0")->display() ) else skip ; if a > 2 then ( execute ((a - 1) div 2)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(5010) def solve(s): if len(s)==3 : if s[0]=='A' and s[1]=='B' and s[2]=='C' : return True else : return False i=0 a=0 b=0 c=0 lis=[] while idisplay() ) else ( execute ("No")->display() ); operation solve(s : OclAny) : OclAny pre: true post: true activity: if (s)->size() = 3 then ( if s->first() = 'A' & s[1+1] = 'B' & s[2+1] = 'C' then ( return true ) else ( return false ) ) else skip ; var i : int := 0 ; var a : int := 0 ; var b : int := 0 ; var c : int := 0 ; var lis : Sequence := Sequence{} ; while (i->compareTo((s)->size())) < 0 do ( if (i + 2->compareTo((s)->size())) < 0 & s[i+1] = 'A' & s[i + 1+1] = 'B' & s[i + 2+1] = 'C' then ( execute (('X') : lis) ; i := i + 3 ) else ( execute ((s[i+1]) : lis) ; if s[i+1] = 'A' then ( a := 1 ) else skip ; if s[i+1] = 'B' then ( b := 1 ) else skip ; if s[i+1] = 'C' then ( c := 1 ) else skip ; i := i + 1 )) ; if not((a + b + c = 2)) then ( return false ) else skip ; if a = 0 then ( for i : Integer.subrange(0, (lis)->size()-1) do ( if lis[i+1] = 'X' then ( lis[i+1] := 'A' ) else skip) ) else skip ; if b = 0 then ( for i : Integer.subrange(0, (lis)->size()-1) do ( if lis[i+1] = 'X' then ( lis[i+1] := 'B' ) else skip) ) else skip ; if c = 0 then ( for i : Integer.subrange(0, (lis)->size()-1) do ( if lis[i+1] = 'X' then ( lis[i+1] := 'C' ) else skip) ) else skip ; if (s)->size() = (lis)->size() then ( return false ) else skip ; return solve(lis); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(0,t): x=int(input()) if x % 2!=0 : print((x-1)//2) else : print((x//2)-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if x mod 2 /= 0 then ( execute ((x - 1) div 2)->display() ) else ( execute ((x div 2) - 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) if n % 2!=0 : print((n-1)//2) else : print((n//2)-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 /= 0 then ( execute ((n - 1) div 2)->display() ) else ( execute ((n div 2) - 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def xgcd(a,b): x0,y0,x1,y1=1,0,0,1 while b!=0 : q,a,b=a//b,b,a % b x0,x1=x1,x0-q*x1 y0,y1=y1,y0-q*y1 return a,x0,y0 def modinv(a,m): g,x,y=xgcd(a,m) if g!=1 : raise Exception('modular inverse does not exist') else : return x % m MOD=998244353 N=int(input()) n=N//2 ansx=1 tmp2=1 tmpc=1 for i in range(1,n): tmp2=(tmp2*2)% MOD tmpc=(tmpc*(2*n-i+1)*modinv(i,MOD))% MOD ansx=(ansx+tmp2*tmpc)% MOD ans=pow(3,N,MOD) ans=(ans+2*MOD-ansx*2)% MOD print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var MOD : int := 998244353 ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := N div 2 ; var ansx : int := 1 ; var tmp2 : int := 1 ; var tmpc : int := 1 ; for i : Integer.subrange(1, n-1) do ( tmp2 := (tmp2 * 2) mod MOD ; tmpc := (tmpc * (2 * n - i + 1) * modinv(i, MOD)) mod MOD ; ansx := (ansx + tmp2 * tmpc) mod MOD) ; var ans : double := (3)->pow(N) ; ans := (ans + 2 * MOD - ansx * 2) mod MOD ; execute (ans)->display(); operation xgcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var x0 : OclAny := null; var y0 : OclAny := null; var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x0,y0,x1,y1} := Sequence{1,0,0,1} ; while b /= 0 do ( var q : OclAny := null; Sequence{q,a,b} := Sequence{a div b,b,a mod b} ; var x0 : OclAny := null; var x1 : OclAny := null; Sequence{x0,x1} := Sequence{x1,x0 - q * x1} ; var y0 : OclAny := null; var y1 : OclAny := null; Sequence{y0,y1} := Sequence{y1,y0 - q * y1}) ; return a, x0, y0; operation modinv(a : OclAny, m : OclAny) : OclAny pre: true post: true activity: var g : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{g,x,y} := xgcd(a, m) ; if g /= 1 then ( error ProgramException.newProgramException('modular inverse does not exist') ) else ( return x mod m ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=input() if i[0]==i[0].lower()and i[1 :]==i[1 :].upper(): s='' s+=i[0].upper() s+=i[1 :].lower() print(s) elif i==i.upper(): print(i.lower()) else : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : String := (OclFile["System.in"]).readLine() ; if i->first() = i->first()->toLowerCase() & i->tail() = i->tail()->toUpperCase() then ( var s : String := '' ; s := s + i->first()->toUpperCase() ; s := s + i->tail()->toLowerCase() ; execute (s)->display() ) else (if i = i->toUpperCase() then ( execute (i->toLowerCase())->display() ) else ( execute (i)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=input() if i[0]==i[0].lower()and i[1 :]==i[1 :].upper(): s='' s+=i[0].upper() s+=i[1 :].lower() print(s) elif i==i.upper(): print(i.lower()) else : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : String := (OclFile["System.in"]).readLine() ; if i->first() = i->first()->toLowerCase() & i->tail() = i->tail()->toUpperCase() then ( var s : String := '' ; s := s + i->first()->toUpperCase() ; s := s + i->tail()->toLowerCase() ; execute (s)->display() ) else (if i = i->toUpperCase() then ( execute (i->toLowerCase())->display() ) else ( execute (i)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- word=input() if word[0].islower()and word[1 :].isupper(): print(word[0].upper()+word[1 :].lower()) elif word[0].islower()and len(word)==1 : print(word.upper()) elif word.isupper(): print(word.lower()) else : print(word) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var word : String := (OclFile["System.in"]).readLine() ; if word->first()->matches("[a-z ]*") & word->tail()->matches("[A-Z ]*") then ( execute (word->first()->toUpperCase() + word->tail()->toLowerCase())->display() ) else (if word->first()->matches("[a-z ]*") & (word)->size() = 1 then ( execute (word->toUpperCase())->display() ) else (if word->matches("[A-Z ]*") then ( execute (word->toLowerCase())->display() ) else ( execute (word)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import string x=string.ascii_uppercase z=input() d=0 for i in z : if i in x : d+=1 if d==len(z): print(z.lower()) elif d==len(z)-1 and z[0].islower(): print(z[0].upper()+z[1 :].lower()) else : print(z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : OclAny := string.ascii_uppercase ; var z : String := (OclFile["System.in"]).readLine() ; var d : int := 0 ; for i : z->characters() do ( if (x)->includes(i) then ( d := d + 1 ) else skip) ; if d = (z)->size() then ( execute (z->toLowerCase())->display() ) else (if d = (z)->size() - 1 & z->first()->matches("[a-z ]*") then ( execute (z->first()->toUpperCase() + z->tail()->toLowerCase())->display() ) else ( execute (z)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- length=int(input()) data={"arr" :[]} arr=list(map(int,input().split())) for num in arr : if not num in data["arr"]: if len(data['arr'])>3 : break data["arr"].append(num) if len(data['arr'])<3 : print("YES") elif len(data['arr'])>3 : print("NO") else : data['arr'].sort() if abs(data['arr'][0]-data['arr'][1])==abs(data['arr'][2]-data['arr'][1]): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var length : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var data : Map := Map{ "arr" |-> Sequence{} } ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for num : arr do ( if not((data->at("arr"))->includes(num)) then ( if (data->at('arr'))->size() > 3 then ( break ) else skip ; (expr (atom (name data)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom "arr"))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) )))) ) else skip) ; if (data->at('arr'))->size() < 3 then ( execute ("YES")->display() ) else (if (data->at('arr'))->size() > 3 then ( execute ("NO")->display() ) else ( (expr (atom (name data)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'arr'))))))) ])) (trailer . (name sort) (arguments ( )))) ; if (data->at('arr')->first() - data->at('arr')[1+1])->abs() = (data->at('arr')[2+1] - data->at('arr')[1+1])->abs() then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() nums=sorted(set(map(int,input().split()))) print(["NO","YES"][len(nums)==1 or len(nums)==2 or(len(nums)==3 and nums[1]==(nums[0]+nums[2])/2)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var nums : Sequence := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->sort() ; execute (Sequence{"NO"}->union(Sequence{ "YES" })->select((nums)->size() = 1 or (nums)->size() = 2 or ((nums)->size() = 3 & nums[1+1] = (nums->first() + nums[2+1]) / 2)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() nums=sorted(set(map(int,input().split()))) print(["NO","YES"][len(nums)<3 or(len(nums)==3 and nums[1]==(nums[0]+nums[2])/2)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var nums : Sequence := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->sort() ; execute (Sequence{"NO"}->union(Sequence{ "YES" })->select((nums)->size() < 3 or ((nums)->size() = 3 & nums[1+1] = (nums->first() + nums[2+1]) / 2)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def rs(): return sys.stdin.readline().rstrip() def ri(): return int(rs()) def rs_(): return[_ for _ in rs().split()] def ri_(): return[int(_)for _ in rs().split()] N=ri() ans=0 for i in range(1,N+1): ans+=i*(N//i)*(N//i+1)//2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var N : OclAny := ri() ; var ans : int := 0 ; for i : Integer.subrange(1, N + 1-1) do ( ans := ans + i * (N div i) * (N div i + 1) div 2) ; execute (ans)->display(); operation rs() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation ri() : OclAny pre: true post: true activity: return ("" + ((rs())))->toInteger(); operation rs_() : OclAny pre: true post: true activity: return rs().split()->select(_anon | true)->collect(_anon | (_anon)); operation ri_() : OclAny pre: true post: true activity: return rs().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() end="ABC" while True : if s==end : print("Yes") break s=s.replace(end,"X") if("X" not in s)or sum((c in s for c in end))!=2 : print("No") break for c in end : if c not in s : s=s.replace("X",c) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var end : String := "ABC" ; while true do ( if s = end then ( execute ("Yes")->display() ; break ) else skip ; s := s.replace(end, "X") ; if ((s)->characters()->excludes("X")) or (Sequence{(testlist_comp (test (logical_test (comparison (comparison (expr (atom (name c)))) in (comparison (expr (atom (name s))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name end)))))))})->sum() /= 2 then ( execute ("No")->display() ; break ) else skip ; for c : end->characters() do ( if (s)->characters()->excludes(c) then ( s := s.replace("X", c) ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) v=list(map(int,input().split())) a=set(v) b=list(a) b.sort() if(len(b)<3): print("YES") elif(len(b)==3 and(b[2]+b[0])/2==b[1]): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var v : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Set := Set{}->union((v)) ; var b : Sequence := (a) ; b := b->sort() ; if ((b)->size() < 3) then ( execute ("YES")->display() ) else (if ((b)->size() = 3 & (b[2+1] + b->first()) / 2 = b[1+1]) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) a=set(a) if len(a)==1 or len(a)==2 : print("YES") elif len(a)==3 : a=list(a) a.sort() if(((a[0]+a[2])% 2)==0)and(((a[0]+a[2])//2)==a[1]): print("YES") else : print("NO") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := Set{}->union((a)) ; if (a)->size() = 1 or (a)->size() = 2 then ( execute ("YES")->display() ) else (if (a)->size() = 3 then ( a := (a) ; a := a->sort() ; if (((a->first() + a[2+1]) mod 2) = 0) & (((a->first() + a[2+1]) div 2) = a[1+1]) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else ( execute ("NO")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=4 def rotateMatrix(mat): for x in range(0,int(N/2)): for y in range(x,N-x-1): temp=mat[x][y] mat[x][y]=mat[y][N-1-x] mat[y][N-1-x]=mat[N-1-x][N-1-y] mat[N-1-x][N-1-y]=mat[N-1-y][x] mat[N-1-y][x]=temp def displayMatrix(mat): for i in range(0,N): for j in range(0,N): print(mat[i][j],end=' ') print("") mat=[[0 for x in range(N)]for y in range(N)] mat=[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]] rotateMatrix(mat) displayMatrix(mat) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 4 ; skip ; skip ; mat := Integer.subrange(0, N-1)->select(y | true)->collect(y | (Integer.subrange(0, N-1)->select(x | true)->collect(x | (0)))) ; mat := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })))}->union(Sequence{Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 8 })))}->union(Sequence{Sequence{9}->union(Sequence{10}->union(Sequence{11}->union(Sequence{ 12 })))}->union(Sequence{ Sequence{13}->union(Sequence{14}->union(Sequence{15}->union(Sequence{ 16 }))) }))) ; rotateMatrix(mat) ; displayMatrix(mat); operation rotateMatrix(mat : OclAny) pre: true post: true activity: for x : Integer.subrange(0, ("" + ((N / 2)))->toInteger()-1) do ( for y : Integer.subrange(x, N - x - 1-1) do ( var temp : OclAny := mat[x+1][y+1] ; mat[x+1][y+1] := mat[y+1][N - 1 - x+1] ; mat[y+1][N - 1 - x+1] := mat[N - 1 - x+1][N - 1 - y+1] ; mat[N - 1 - x+1][N - 1 - y+1] := mat[N - 1 - y+1][x+1] ; mat[N - 1 - y+1][x+1] := temp)); operation displayMatrix(mat : OclAny) pre: true post: true activity: for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( execute (mat[i+1][j+1])->display()) ; execute ("")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools import os import sys from functools import lru_cache if os.getenv("LOCAL"): sys.stdin=open("_in.txt","r") sys.setrecursionlimit(2147483647) INF=float("inf") IINF=10**18 MOD=998244353 N=int(sys.stdin.readline()) @ lru_cache(maxsize=None) def is_ok(s): if len(s)==0 : return True if len(s)==2 : return s not in['AB','BA'] for i in range(len(s)-2): if s[i : i+2]not in['AB','BA']and is_ok(s[: i]+s[i+2 :]): return True return False def test(N): ret=0 for s in itertools.product('ABC',repeat=N): s=''.join(s) ret+=is_ok(s) return ret def mod_invs(max,mod): invs=[1]*(max+1) for x in range(2,max+1): invs[x]=(-(mod//x)*invs[mod % x])% mod return invs ans=pow(3,N,MOD) invs=mod_invs(max=N,mod=MOD) ncr=1 p2r=1 for r in range(N,N//2,-1): ans-=ncr*p2r*2 % MOD ans %=MOD ncr*=r*invs[N-r+1] ncr %=MOD p2r*=2 p2r %=MOD print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if os.getenv("LOCAL") then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("_in.txt")) ) else skip ; sys.setrecursionlimit(2147483647) ; var INF : double := ("" + (("inf")))->toReal() ; var IINF : double := (10)->pow(18) ; var MOD : int := 998244353 ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (compound_stmt (decorator @ (dotted_name (name lru_cache)) ( (arglist (argument (test (logical_test (comparison (expr (atom (name maxsize)))))) = (test (logical_test (comparison (expr (atom None))))))) )) (funcdef def (name is_ok) ( (typedargslist (def_parameters (def_parameter (named_parameter (name s))))) ) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name True))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))) == (comparison (expr (atom (number (integer 2)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (comparison (expr (atom (name s)))) not in (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom 'AB'))))) , (test (logical_test (comparison (expr (atom 'BA')))))) ]))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))) - (expr (atom (number (integer 2)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))) : (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 2)))))))))) ])))) not in (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom 'AB'))))) , (test (logical_test (comparison (expr (atom 'BA')))))) ]))))) and (logical_test (comparison (expr (atom (name is_ok)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 2)))))))) :)) ]))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name True)))))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name False))))))))))))) ; skip ; skip ; var ans : double := (3)->pow(N) ; invs := mod_invs((argument (test (logical_test (comparison (expr (atom (name max)))))) = (test (logical_test (comparison (expr (atom (name N))))))), (argument (test (logical_test (comparison (expr (atom (name mod)))))) = (test (logical_test (comparison (expr (atom (name MOD)))))))) ; var ncr : int := 1 ; var p2r : int := 1 ; for r : Integer.subrange(N div 2 + 1, N)->reverse() do ( ans := ans - ncr * p2r * 2 mod MOD ; ans := ans mod MOD ; ncr := ncr * r * invs[N - r + 1+1] ; ncr := ncr mod MOD ; p2r := p2r * 2 ; p2r := p2r mod MOD) ; execute (ans)->display(); operation test(N : OclAny) : OclAny pre: true post: true activity: var ret : int := 0 ; for s : itertools.product('ABC', (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (name N)))))))) do ( var s : String := StringLib.sumStringsWithSeparator((s), '') ; ret := ret + is_ok(s)) ; return ret; operation mod_invs(max : OclAny, mod : OclAny) : OclAny pre: true post: true activity: var invs : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (max + 1)) ; for x : Integer.subrange(2, max + 1-1) do ( invs[x+1] := (-(mod div x) * invs[mod mod x+1]) mod mod) ; return invs; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np import sys RODS=3 N=3 dp=np.zeros((N+1,RODS+1,RODS+1)); def initialize(): for i in range(N+1): for j in range(1,RODS+1): for k in range(1,RODS+1): dp[i][j][k]=sys.maxsize ; def mincost(idx,src,dest,costs): if(idx>N): return 0 ; if(dp[idx][src][dest]!=sys.maxsize): return dp[idx][src][dest]; rem=6-(src+dest); ans=sys.maxsize ; case1=costs[src-1][dest-1]+mincost(idx+1,src,rem,costs)+mincost(idx+1,rem,dest,costs); case2=(costs[src-1][rem-1]+mincost(idx+1,src,dest,costs)+mincost(idx+1,dest,src,costs)+costs[rem-1][dest-1]+mincost(idx+1,src,dest,costs)); ans=min(case1,case2); dp[idx][src][dest]=ans ; return ans ; if __name__=="__main__" : costs=[[0,1,2],[2,0,1],[3,2,0]]; initialize(); print(mincost(1,1,3,costs)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var RODS : int := 3 ; var N : int := 3 ; var dp : Sequence := MatrixLib.singleValueMatrix(Sequence{N + 1, RODS + 1, RODS + 1}, 0.0); ; skip ; skip ; if __name__ = "__main__" then ( costs := Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{ 2 }))}->union(Sequence{Sequence{2}->union(Sequence{0}->union(Sequence{ 1 }))}->union(Sequence{ Sequence{3}->union(Sequence{2}->union(Sequence{ 0 })) })); ; initialize(); ; execute (mincost(1, 1, 3, costs))->display(); ) else skip; operation initialize() pre: true post: true activity: for i : Integer.subrange(0, N + 1-1) do ( for j : Integer.subrange(1, RODS + 1-1) do ( for k : Integer.subrange(1, RODS + 1-1) do ( dp[i+1][j+1][k+1] := (trailer . (name maxsize));))); operation mincost(idx : OclAny, src : OclAny, dest : OclAny, costs : OclAny) pre: true post: true activity: if ((idx->compareTo(N)) > 0) then ( return 0; ) else skip ; if (dp[idx+1][src+1][dest+1] /= (trailer . (name maxsize))) then ( return dp[idx+1][src+1][dest+1]; ) else skip ; var rem : double := 6 - (src + dest); ; var ans : (trailer . (name maxsize)) := (trailer . (name maxsize)); ; var case1 : OclAny := costs[src - 1+1][dest - 1+1] + mincost(idx + 1, src, rem, costs) + mincost(idx + 1, rem, dest, costs); ; var case2 : OclAny := (costs[src - 1+1][rem - 1+1] + mincost(idx + 1, src, dest, costs) + mincost(idx + 1, dest, src, costs) + costs[rem - 1+1][dest - 1+1] + mincost(idx + 1, src, dest, costs)); ; ans := Set{case1, case2}->min(); ; dp[idx+1][src+1][dest+1] := ans; ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfSeries(n): sum=0 for i in range(1,n+1): sum+=i*i*i return sum n=5 print(sumOfSeries(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; execute (sumOfSeries(n))->display(); operation sumOfSeries(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( sum := sum + i * i * i) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfSeries(n): x=(n*(n+1)/2) return(int)(x*x) n=5 print(sumOfSeries(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; execute (sumOfSeries(n))->display(); operation sumOfSeries(n : OclAny) : OclAny pre: true post: true activity: var x : double := (n * (n + 1) / 2) ; return (OclType["int"])(x * x); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfSeries(n): x=0 if n % 2==0 : x=(n/2)*(n+1) else : x=((n+1)/2)*n return(int)(x*x) n=5 print(sumOfSeries(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; execute (sumOfSeries(n))->display(); operation sumOfSeries(n : OclAny) : OclAny pre: true post: true activity: var x : int := 0 ; if n mod 2 = 0 then ( x := (n / 2) * (n + 1) ) else ( x := ((n + 1) / 2) * n ) ; return (OclType["int"])(x * x); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=4 C=4 def getTotalCoverageOfMatrix(mat): res=0 for i in range(R): isOne=False for j in range(C): if(mat[i][j]==1): isOne=True elif(isOne): res+=1 isOne=False for j in range(C-1,-1,-1): if(mat[i][j]==1): isOne=True elif(isOne): res+=1 for j in range(C): isOne=False for i in range(R): if(mat[i][j]==1): isOne=True elif(isOne): res+=1 isOne=False for i in range(R-1,-1,-1): if(mat[i][j]==1): isOne=True elif(isOne): res+=1 return res mat=[[0,0,0,0],[1,0,0,1],[0,1,1,0],[0,1,0,0]] print(getTotalCoverageOfMatrix(mat)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : int := 4 ; var C : int := 4 ; skip ; mat := Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))}->union(Sequence{Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 1 })))}->union(Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 0 })))}->union(Sequence{ Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 0 }))) }))) ; execute (getTotalCoverageOfMatrix(mat))->display(); operation getTotalCoverageOfMatrix(mat : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; for i : Integer.subrange(0, R-1) do ( var isOne : boolean := false ; for j : Integer.subrange(0, C-1) do ( if (mat[i+1][j+1] = 1) then ( isOne := true ) else (if (isOne) then ( res := res + 1 ) else skip)) ; isOne := false ; for j : Integer.subrange(-1 + 1, C - 1)->reverse() do ( if (mat[i+1][j+1] = 1) then ( isOne := true ) else (if (isOne) then ( res := res + 1 ) else skip))) ; for j : Integer.subrange(0, C-1) do ( isOne := false ; for i : Integer.subrange(0, R-1) do ( if (mat[i+1][j+1] = 1) then ( isOne := true ) else (if (isOne) then ( res := res + 1 ) else skip)) ; isOne := false ; for i : Integer.subrange(-1 + 1, R - 1)->reverse() do ( if (mat[i+1][j+1] = 1) then ( isOne := true ) else (if (isOne) then ( res := res + 1 ) else skip))) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function def replace_elements(arr,n): pos=0 for i in range(0,n): arr[pos]=arr[i] pos=pos+1 while(pos>1 and arr[pos-2]==arr[pos-1]): pos-=1 arr[pos-1]+=1 for i in range(0,pos): print(arr[i],end=" ") arr=[6,4,3,4,3,3,5] n=len(arr) replace_elements(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{6}->union(Sequence{4}->union(Sequence{3}->union(Sequence{4}->union(Sequence{3}->union(Sequence{3}->union(Sequence{ 5 })))))) ; n := (arr)->size() ; replace_elements(arr, n); operation replace_elements(arr : OclAny, n : OclAny) pre: true post: true activity: var pos : int := 0 ; for i : Integer.subrange(0, n-1) do ( arr[pos+1] := arr[i+1] ; pos := pos + 1 ; while (pos > 1 & arr[pos - 2+1] = arr[pos - 1+1]) do ( pos := pos - 1 ; arr[pos - 1+1] := arr[pos - 1+1] + 1)) ; for i : Integer.subrange(0, pos-1) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=10**9+7 dd=[(0,-1),(1,0),(0,1),(-1,0)] ddn=[(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)] def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): s=S() m={} m['ABC']=True def f(s): if s in m : return m[s] t=s.replace('ABC','x') if s==t : m[s]=False return False for c in 'ABC' : if c in t : continue if f(t.replace('x',c)): return True m[s]=False return False if f(s): return 'Yes' return 'No' print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : double := (10)->pow(9) + 7 ; var dd : Sequence := Sequence{Sequence{0, -1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{ Sequence{-1, 0} }))) ; var ddn : Sequence := Sequence{Sequence{0, -1}}->union(Sequence{Sequence{1, -1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{1, 1}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{-1, -1}}->union(Sequence{Sequence{-1, 0}}->union(Sequence{ Sequence{-1, 1} }))))))) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: s := S() ; var m : OclAny := Set{} ; m->at('ABC') := true ; skip ; if f(s) then ( return 'Yes' ) else skip ; return 'No'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countOnes(n): count=1 ; rem=1 ; while(rem!=0): rem=(rem*10+1)% n ; count=count+1 ; return count ; n=13 ; print(countOnes(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 13; ; execute (countOnes(n))->display();; operation countOnes(n : OclAny) pre: true post: true activity: var count : int := 1; ; var rem : int := 1; ; while (rem /= 0) do ( rem := (rem * 10 + 1) mod n; ; count := count + 1;) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): seen=set(a**b for a in range(2,101)for b in range(2,101)) return str(len(seen)) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var seen : Set := Set{}->union(((argument (test (logical_test (comparison (expr (expr (atom (name a))) ** (expr (atom (name b))))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 101))))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 101))))))))) )))))))))))) ; return ("" + (((seen)->size()))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x,y=map(int,input().split()) m=set() for _ in range(int(input())): m.add(tuple(map(int,input().split()))) q={(0,0): 1} for _ in range(x+y): nq={} for i in q : if(i[0],i[1],i[0]+1,i[1])not in m and(i[0]+1,i[1],i[0],i[1])not in m and i[0]+1<=x : if(i[0]+1,i[1])in nq : nq[(i[0]+1,i[1])]+=q[i] else : nq[(i[0]+1,i[1])]=q[i] if(i[0],i[1],i[0],i[1]+1)not in m and(i[0],i[1]+1,i[0],i[1])not in m and i[1]+1<=y : if(i[0],i[1]+1)in nq : nq[(i[0],i[1]+1)]+=q[i] else : nq[(i[0],i[1]+1)]=q[i] q=nq if nq=={}: print("Miserable Hokusai!") else : print(q[(x,y)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : Set := Set{}->union(()) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : m)) ; var q : Map := Map{ Sequence{0, 0} |-> 1 } ; for _anon : Integer.subrange(0, x + y-1) do ( var nq : OclAny := Set{} ; for i : q->keys() do ( if (m)->excludes(Sequence{i->first(), i[1+1], i->first() + 1, i[1+1]}) & (m)->excludes(Sequence{i->first() + 1, i[1+1], i->first(), i[1+1]}) & (i->first() + 1->compareTo(x)) <= 0 then ( if (nq)->includes(Sequence{i->first() + 1, i[1+1]}) then ( nq[Sequence{i->first() + 1, i[1+1]}+1] := nq[Sequence{i->first() + 1, i[1+1]}+1] + q[i+1] ) else ( nq[Sequence{i->first() + 1, i[1+1]}+1] := q[i+1] ) ) else skip ; if (m)->excludes(Sequence{i->first(), i[1+1], i->first(), i[1+1] + 1}) & (m)->excludes(Sequence{i->first(), i[1+1] + 1, i->first(), i[1+1]}) & (i[1+1] + 1->compareTo(y)) <= 0 then ( if (nq)->includes(Sequence{i->first(), i[1+1] + 1}) then ( nq[Sequence{i->first(), i[1+1] + 1}+1] := nq[Sequence{i->first(), i[1+1] + 1}+1] + q[i+1] ) else ( nq[Sequence{i->first(), i[1+1] + 1}+1] := q[i+1] ) ) else skip) ; q := nq) ; if nq = Set{} then ( execute ("Miserable Hokusai!")->display() ) else ( execute (q[Sequence{x, y}+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for repeet in range(t): actinidia_tate=[] actinidia_yoko=[] gx,gy=[int(i)for i in input().split(" ")] mapH=[[0 for i in range(gx+1)]for j in range(gy+1)] mapH[0][0]=1 p=int(input()) for i in range(p): x1,y1,x2,y2=[int(j)for j in input().split(" ")] if x1==x2 : actinidia_tate.append([x1,max(y1,y2)]) else : actinidia_yoko.append([max(x1,x2),y1]) for i in range(1,gx+1): try : actinidia_yoko.remove([i,0]) except : mapH[0][i]+=mapH[0][i-1] for j in range(1,gy+1): try : actinidia_tate.remove([0,j]) except : mapH[j][0]+=mapH[j-1][0] for i in range(1,gx+1): for j in range(1,gy+1): try : actinidia_yoko.remove([i,j]) except : mapH[j][i]+=mapH[j][i-1] try : actinidia_tate.remove([i,j]) except : mapH[j][i]+=mapH[j-1][i] if mapH[-1][-1]==0 : print("Miserable Hokusai!") else : print(mapH[-1][-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for repeet : Integer.subrange(0, t-1) do ( var actinidia_tate : Sequence := Sequence{} ; var actinidia_yoko : Sequence := Sequence{} ; var gx : OclAny := null; var gy : OclAny := null; Sequence{gx,gy} := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var mapH : Sequence := Integer.subrange(0, gy + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, gx + 1-1)->select(i | true)->collect(i | (0)))) ; mapH->first()->first() := 1 ; var p : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, p-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := input().split(" ")->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; if x1 = x2 then ( execute ((Sequence{x1}->union(Sequence{ Set{y1, y2}->max() })) : actinidia_tate) ) else ( execute ((Sequence{Set{x1, x2}->max()}->union(Sequence{ y1 })) : actinidia_yoko) )) ; for i : Integer.subrange(1, gx + 1-1) do ( try ( execute ((Sequence{i}->union(Sequence{ 0 })) /: actinidia_yoko)) catch (_e : OclException) do ( mapH->first()[i+1] := mapH->first()[i+1] + mapH->first()[i - 1+1]) ) ; for j : Integer.subrange(1, gy + 1-1) do ( try ( execute ((Sequence{0}->union(Sequence{ j })) /: actinidia_tate)) catch (_e : OclException) do ( mapH[j+1]->first() := mapH[j+1]->first() + mapH[j - 1+1]->first()) ) ; for i : Integer.subrange(1, gx + 1-1) do ( for j : Integer.subrange(1, gy + 1-1) do ( try ( execute ((Sequence{i}->union(Sequence{ j })) /: actinidia_yoko)) catch (_e : OclException) do ( mapH[j+1][i+1] := mapH[j+1][i+1] + mapH[j+1][i - 1+1]) ; try ( execute ((Sequence{i}->union(Sequence{ j })) /: actinidia_tate)) catch (_e : OclException) do ( mapH[j+1][i+1] := mapH[j+1][i+1] + mapH[j - 1+1][i+1]) )) ; if mapH->last()->last() = 0 then ( execute ("Miserable Hokusai!")->display() ) else ( execute (mapH->last()->last())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPerfectSquare(arr,n): umap=dict.fromkeys(arr,n); for key in arr : umap[key]+=1 ; for key in arr : if(umap[key]% 2==1): return False ; return True ; if __name__=="__main__" : arr=[2,2,7,7]; n=len(arr) if(isPerfectSquare(arr,n)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{2}->union(Sequence{2}->union(Sequence{7}->union(Sequence{ 7 }))); ; n := (arr)->size() ; if (isPerfectSquare(arr, n)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ) else skip; operation isPerfectSquare(arr : OclAny, n : OclAny) pre: true post: true activity: var umap : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))); ; for key : arr do ( umap[key+1] := umap[key+1] + 1;) ; for key : arr do ( if (umap[key+1] mod 2 = 1) then ( return false; ) else skip) ; return true;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) def heian(): x,y=map(int,input().split()) mata=int(input()) Vert=[['T' for i in range(x+1)]for j in range(y+1)] Horiz=[['T' for i in range(x+1)]for j in range(y+1)] for i in range(x+1): Vert[0][i]='F' for i in range(y+1): Horiz[i][0]='F' for i in range(mata): a,b,c,d=map(int,input().split()) if a==c and bd : Vert[b][a]='F' elif b==d and a>c : Horiz[b][a]='F' else : Horiz[d][c]='F' route=[[0 for i in range(x+1)]for i in range(y+1)] route[0][0]=1 for i in range(x+1): for j in range(y+1): if Vert[j][i]=='T' : route[j][i]+=route[j-1][i] if Horiz[j][i]=='T' : route[j][i]+=route[j][i-1] if route[y][x]>0 : return route[y][x] else : return 'Miserable Hokusai!' for i in range(n): print(heian()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; for i : Integer.subrange(0, n-1) do ( execute (heian())->display()); operation heian() : OclAny pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mata : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var Vert : Sequence := Integer.subrange(0, y + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, x + 1-1)->select(i | true)->collect(i | ('T')))) ; var Horiz : Sequence := Integer.subrange(0, y + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, x + 1-1)->select(i | true)->collect(i | ('T')))) ; for i : Integer.subrange(0, x + 1-1) do ( Vert->first()[i+1] := 'F') ; for i : Integer.subrange(0, y + 1-1) do ( Horiz[i+1]->first() := 'F') ; for i : Integer.subrange(0, mata-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = c & (b->compareTo(d)) < 0 then ( Vert[d+1][c+1] := 'F' ) else (if a = c & (b->compareTo(d)) > 0 then ( Vert[b+1][a+1] := 'F' ) else (if b = d & (a->compareTo(c)) > 0 then ( Horiz[b+1][a+1] := 'F' ) else ( Horiz[d+1][c+1] := 'F' ) ) ) ) ; var route : Sequence := Integer.subrange(0, y + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, x + 1-1)->select(i | true)->collect(i | (0)))) ; route->first()->first() := 1 ; for i : Integer.subrange(0, x + 1-1) do ( for j : Integer.subrange(0, y + 1-1) do ( if Vert[j+1][i+1] = 'T' then ( route[j+1][i+1] := route[j+1][i+1] + route[j - 1+1][i+1] ) else skip ; if Horiz[j+1][i+1] = 'T' then ( route[j+1][i+1] := route[j+1][i+1] + route[j+1][i - 1+1] ) else skip)) ; if route[y+1][x+1] > 0 then ( return route[y+1][x+1] ) else ( return 'Miserable Hokusai!' ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(100000000) MOD=10**9+7 INF=10**15 dy=(-1,0,1,0) dx=(0,1,0,-1) def solve(): W,H=map(int,input().split()) M=int(input()) impossible={tuple(map(int,input().split()))for _ in range(M)} dp=[[0]*(W+1)for _ in range(H+1)] dp[0][0]=1 for i in range(H+1): for j in range(W+1): if i+1<=H : if(j,i,j,i+1)not in impossible and(j,i+1,j,i)not in impossible : dp[i+1][j]+=dp[i][j] if j+1<=W : if(j,i,j+1,i)not in impossible and(j+1,i,j,i)not in impossible : dp[i][j+1]+=dp[i][j] print(dp[-1][-1]if dp[-1][-1]>0 else "Miserable Hokusai!") def main(): N=int(input()) for _ in range(N): solve() if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(100000000) ; var MOD : double := (10)->pow(9) + 7 ; var INF : double := (10)->pow(15) ; var dy : OclAny := Sequence{-1, 0, 1, 0} ; var dx : OclAny := Sequence{0, 1, 0, -1} ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve() pre: true post: true activity: var W : OclAny := null; var H : OclAny := null; Sequence{W,H} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var M : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var impossible : Set := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | ((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->asSet() ; var dp : Sequence := Integer.subrange(0, H + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (W + 1)))) ; dp->first()->first() := 1 ; for i : Integer.subrange(0, H + 1-1) do ( for j : Integer.subrange(0, W + 1-1) do ( if (i + 1->compareTo(H)) <= 0 then ( if (impossible)->excludes(Sequence{j, i, j, i + 1}) & (impossible)->excludes(Sequence{j, i + 1, j, i}) then ( dp[i + 1+1][j+1] := dp[i + 1+1][j+1] + dp[i+1][j+1] ) else skip ) else skip ; if (j + 1->compareTo(W)) <= 0 then ( if (impossible)->excludes(Sequence{j, i, j + 1, i}) & (impossible)->excludes(Sequence{j + 1, i, j, i}) then ( dp[i+1][j + 1+1] := dp[i+1][j + 1+1] + dp[i+1][j+1] ) else skip ) else skip)) ; execute (if dp->last()->last() > 0 then dp->last()->last() else "Miserable Hokusai!" endif)->display(); operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, N-1) do ( solve()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dp(Map,i,j): ans=0 if i==0 and j==0 : return 1 elif Map[i][j]>=0 : return Map[i][j] else : if i>0 : if vert[i-1][j]: ans+=dp(Map,i-1,j) if j>0 : if hori[i][j-1]: ans+=dp(Map,i,j-1) Map[i][j]=ans return dp(Map,i,j) n=int(input()) for _ in range(n): gx,gy=map(int,input().split()) m=int(input()) matatabi=[] for _ in range(m): matatabi.append(list(map(int,input().split()))) hori=[[True]*(gx+1)for _ in range(gy+1)] vert=[[True]*(gx+1)for _ in range(gy+1)] for lis in matatabi : if lis[0]==lis[2]: vert[min(lis[1],lis[3])][lis[0]]=False if lis[1]==lis[3]: hori[lis[1]][min(lis[0],lis[2])]=False Map=[[-1]*(gx+1)for _ in range(gy+1)] ans=dp(Map,gy,gx) if ans>0 : print(ans) elif ans==0 : print("Miserable Hokusai!") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var gx : OclAny := null; var gy : OclAny := null; Sequence{gx,gy} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var matatabi : Sequence := Sequence{} ; for _anon : Integer.subrange(0, m-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : matatabi)) ; var hori : Sequence := Integer.subrange(0, gy + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ true }, (gx + 1)))) ; var vert : Sequence := Integer.subrange(0, gy + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ true }, (gx + 1)))) ; for lis : matatabi do ( if lis->first() = lis[2+1] then ( vert[Set{lis[1+1], lis[3+1]}->min()+1][lis->first()+1] := false ) else skip ; if lis[1+1] = lis[3+1] then ( hori[lis[1+1]+1][Set{lis->first(), lis[2+1]}->min()+1] := false ) else skip) ; Map := Integer.subrange(0, gy + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ -1 }, (gx + 1)))) ; ans := dp(Map, gy, gx) ; if ans > 0 then ( execute (ans)->display() ) else (if ans = 0 then ( execute ("Miserable Hokusai!")->display() ) else skip)); operation dp(Map : OclAny, i : OclAny, j : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; if i = 0 & j = 0 then ( return 1 ) else (if Map[i+1][j+1] >= 0 then ( return Map[i+1][j+1] ) else ( if i > 0 then ( if vert[i - 1+1][j+1] then ( ans := ans + dp(Map, i - 1, j) ) else skip ) else skip ; if j > 0 then ( if hori[i+1][j - 1+1] then ( ans := ans + dp(Map, i, j - 1) ) else skip ) else skip ; Map[i+1][j+1] := ans ; return dp(Map, i, j) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=10000 MAX_ELEMENT=50 dp=[[[-1 for i in range(MAX)]for j in range(MAX_ELEMENT)]for k in range(MAX_ELEMENT)] def Max_Xor(arr,i,j,mask,n): if(i>=n): if(j==0): return mask else : return 0 if(dp[i][j][mask]!=-1): return dp[i][j][mask] ans=0 if(j>0): ans=Max_Xor(arr,i+1,j-1,mask ^ arr[i],n) ans=max(ans,Max_Xor(arr,i+1,j,mask,n)) dp[i][j][mask]=ans return ans arr=[2,5,4,1,3,7,6,8] n=len(arr) k=3 print(Max_Xor(arr,0,k,0,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 10000 ; var MAX_ELEMENT : int := 50 ; var dp : Sequence := Integer.subrange(0, MAX_ELEMENT-1)->select(k | true)->collect(k | (Integer.subrange(0, MAX_ELEMENT-1)->select(j | true)->collect(j | (Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (-1)))))) ; skip ; arr := Sequence{2}->union(Sequence{5}->union(Sequence{4}->union(Sequence{1}->union(Sequence{3}->union(Sequence{7}->union(Sequence{6}->union(Sequence{ 8 }))))))) ; n := (arr)->size() ; var k : int := 3 ; execute (Max_Xor(arr, 0, k, 0, n))->display(); operation Max_Xor(arr : OclAny, i : OclAny, j : OclAny, mask : OclAny, n : OclAny) : OclAny pre: true post: true activity: if ((i->compareTo(n)) >= 0) then ( if (j = 0) then ( return mask ) else ( return 0 ) ) else skip ; if (dp[i+1][j+1][mask+1] /= -1) then ( return dp[i+1][j+1][mask+1] ) else skip ; var ans : int := 0 ; if (j > 0) then ( ans := Max_Xor(arr, i + 1, j - 1, MathLib.bitwiseXor(mask, arr[i+1]), n) ) else skip ; ans := Set{ans, Max_Xor(arr, i + 1, j, mask, n)}->max() ; dp[i+1][j+1][mask+1] := ans ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def MaxIncreasingSub(arr,n,k): dp=[-1]*n ans=-1 for i in range(n): dp[i]=[-1]*(k+1) for i in range(n): dp[i][1]=arr[i] for i in range(1,n): for j in range(i): if arr[j]union(Sequence{5}->union(Sequence{9}->union(Sequence{10}->union(Sequence{5}->union(Sequence{6}->union(Sequence{21}->union(Sequence{ 8 }))))))) ; ans := MaxIncreasingSub(arr, n, k) ; execute (ans)->display() ) else skip; operation MaxIncreasingSub(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; var ans : int := -1 ; for i : Integer.subrange(0, n-1) do ( dp[i+1] := MatrixLib.elementwiseMult(Sequence{ -1 }, (k + 1))) ; for i : Integer.subrange(0, n-1) do ( dp[i+1][1+1] := arr[i+1]) ; for i : Integer.subrange(1, n-1) do ( for j : Integer.subrange(0, i-1) do ( if (arr[j+1]->compareTo(arr[i+1])) < 0 then ( for l : Integer.subrange(1, k-1) do ( if dp[j+1][l+1] /= -1 then ( dp[i+1][l + 1+1] := Set{dp[i+1][l + 1+1], dp[j+1][l+1] + arr[i+1]}->max() ) else skip) ) else skip)) ; for i : Integer.subrange(0, n-1) do ( if (ans->compareTo(dp[i+1][k+1])) < 0 then ( ans := dp[i+1][k+1] ) else skip) ; return (if ans = -1 then 0 else ans endif); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- moto=input() s=moto gene='ABC' f=True log=[] while len(s)>3 and f : f=False if s[: 3]=='ABC' : s=s.replace('ABC','A') log.append('A') f=True elif s[len(s)-3 :]=='ABC' : s=s.replace('ABC','C') log.append('C') f=True elif 'ABC' in s : s=s.replace('ABC','B') log.append('B') f=True if s!=gene : print('No') exit() l=len(log) for i in range(l): s=s.replace(log[l-1-i],'ABC') if s==moto : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var moto : String := (OclFile["System.in"]).readLine() ; var s : String := moto ; var gene : String := 'ABC' ; var f : boolean := true ; var log : Sequence := Sequence{} ; while (s)->size() > 3 & f do ( f := false ; if s.subrange(1,3) = 'ABC' then ( s := s.replace('ABC', 'A') ; execute (('A') : log) ; f := true ) else (if s.subrange((s)->size() - 3+1) = 'ABC' then ( s := s.replace('ABC', 'C') ; execute (('C') : log) ; f := true ) else (if (s)->characters()->includes('ABC') then ( s := s.replace('ABC', 'B') ; execute (('B') : log) ; f := true ) else skip ) ) ) ; if s /= gene then ( execute ('No')->display() ; exit() ) else skip ; var l : int := (log)->size() ; for i : Integer.subrange(0, l-1) do ( s := s.replace(log[l - 1 - i+1], 'ABC')) ; if s = moto then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_CHAR=26 def stringPalindrome(A,B): countA=[0]*MAX_CHAR countB=[0]*MAX_CHAR l1=len(A) l2=len(B) for i in range(l1): countA[ord(A[i])-ord('a')]+=1 for i in range(l2): countB[ord(B[i])-ord('a')]+=1 for i in range(26): if((countA[i]>1 and countB[i]==0)): return 'A' return 'B' if __name__=='__main__' : a="abcdea" b="bcdesg" print(stringPalindrome(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_CHAR : int := 26 ; skip ; if __name__ = '__main__' then ( var a : String := "abcdea" ; var b : String := "bcdesg" ; execute (stringPalindrome(a, b))->display() ) else skip; operation stringPalindrome(A : OclAny, B : OclAny) : OclAny pre: true post: true activity: var countA : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX_CHAR) ; var countB : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX_CHAR) ; var l1 : int := (A)->size() ; var l2 : int := (B)->size() ; for i : Integer.subrange(0, l1-1) do ( countA[(A[i+1])->char2byte() - ('a')->char2byte()+1] := countA[(A[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; for i : Integer.subrange(0, l2-1) do ( countB[(B[i+1])->char2byte() - ('a')->char2byte()+1] := countB[(B[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; for i : Integer.subrange(0, 26-1) do ( if ((countA[i+1] > 1 & countB[i+1] = 0)) then ( return 'A' ) else skip) ; return 'B'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPaths(n): zB=1 zADC=0 for i in range(1,n+1): nzB=zADC*3 nzADC=(zADC*2+zB) zB=nzB zADC=nzADC return zB n=3 print(countPaths(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3 ; execute (countPaths(n))->display(); operation countPaths(n : OclAny) : OclAny pre: true post: true activity: var zB : int := 1 ; var zADC : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( var nzB : int := zADC * 3 ; var nzADC : int := (zADC * 2 + zB) ; zB := nzB ; zADC := nzADC) ; return zB; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x,y=map(int,input().split()) arr=list(map(int,input().split())) ans=0 for i in range(n): take=True for j in range(max(0,i-x),min(n-1,i+y)+1): if i!=j and arr[i]>=arr[j]: take=False if take : print(i+1); break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var take : boolean := true ; for j : Integer.subrange(Set{0, i - x}->max(), Set{n - 1, i + y}->min() + 1-1) do ( if i /= j & (arr[i+1]->compareTo(arr[j+1])) >= 0 then ( take := false ) else skip) ; if take then ( execute (i + 1)->display(); break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x,y=map(int,input().split()) nums=list(map(int,input().split())) res=-1 for i in range(n): flag=True for j in range(i-1,i-x-1,-1): if j>=0 and nums[j]collect( _x | (OclType["int"])->apply(_x) ) ; var nums : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : int := -1 ; for i : Integer.subrange(0, n-1) do ( var flag : boolean := true ; for j : Integer.subrange(i - x - 1 + 1, i - 1)->reverse() do ( if j >= 0 & (nums[j+1]->compareTo(nums[i+1])) < 0 then ( flag := false ; break ) else skip) ; if flag then ( for j : Integer.subrange(i + 1, i + y + 1-1) do ( if (j->compareTo(n)) < 0 & (nums[j+1]->compareTo(nums[i+1])) < 0 then ( flag := false ; break ) else skip) ) else skip ; if flag then ( execute (i + 1)->display() ; exit() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def _input(): return map(int,input().split()) n,x,y=_input() lst=list(_input()) i=0 while i=0 and j>i-1-y : if lst[j]compareTo(n)) < 0 do ( var check : boolean := true ; var j : int := i + 1 ; while (j->compareTo(n)) < 0 & (j->compareTo(i + 1 + y)) < 0 do ( if (lst[j+1]->compareTo(lst[i+1])) < 0 then ( check := false; break ) else skip ; j := j + 1) ; if check = true then ( j := i - 1 ; while j >= 0 & (j->compareTo(i - 1 - y)) > 0 do ( if (lst[j+1]->compareTo(lst[i+1])) < 0 then ( check := false; break ) else skip ; j := j - 1) ; if check = true then ( execute (i + 1)->display(); exit() ) else skip ) else skip ; i := i + 1); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) minimo=[] maximo=[] cresc=0 decr=0 for a in range(num): seq=list(map(int,input().split())) seq.reverse() seq.pop() seq.reverse() for b in range(len(seq)): if b>0 and seq[b]>seq[b-1]: cresc+=1 break elif b==len(seq)-1 : decr+=1 minimo.append(min(seq)) maximo.append(max(seq)) res=(cresc*cresc)+(2*(cresc*decr)) minimo.sort() maximo.sort() i=0 for c in maximo : while itoInteger() ; var minimo : Sequence := Sequence{} ; var maximo : Sequence := Sequence{} ; var cresc : int := 0 ; var decr : int := 0 ; for a : Integer.subrange(0, num-1) do ( var seq : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; seq := seq->reverse() ; seq := seq->front() ; seq := seq->reverse() ; for b : Integer.subrange(0, (seq)->size()-1) do ( if b > 0 & (seq[b+1]->compareTo(seq[b - 1+1])) > 0 then ( cresc := cresc + 1 ; break ) else (if b = (seq)->size() - 1 then ( decr := decr + 1 ; execute (((seq)->min()) : minimo) ; execute (((seq)->max()) : maximo) ) else skip))) ; var res : int := (cresc * cresc) + (2 * (cresc * decr)) ; minimo := minimo->sort() ; maximo := maximo->sort() ; var i : int := 0 ; for c : maximo do ( while (i->compareTo(decr)) < 0 & (minimo[i+1]->compareTo(c)) < 0 do ( i := i + 1) ; res := res + i) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lcm_fun(a,b): if(b==0): return a ; return lcm_fun(b,a % b); def digitLCM(n): lcm=1 ; while(n>0): lcm=int((n % 10*lcm)/lcm_fun(n % 10,lcm)); if(lcm==0): return 0 ; n=int(n/10); return lcm ; n=397 ; print(digitLCM(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 397; ; execute (digitLCM(n))->display();; operation lcm_fun(a : OclAny, b : OclAny) pre: true post: true activity: if (b = 0) then ( return a; ) else skip ; return lcm_fun(b, a mod b);; operation digitLCM(n : OclAny) pre: true post: true activity: var lcm : int := 1; ; while (n > 0) do ( lcm := ("" + (((n mod 10 * lcm) / lcm_fun(n mod 10, lcm))))->toInteger(); ; if (lcm = 0) then ( return 0; ) else skip ; n := ("" + ((n / 10)))->toInteger();) ; return lcm;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- days,back,front=map(int,input().split()) day=list(map(int,input().split())) ans=-1 for i in range(len(day)): k=99999999999 for j in range(max(0,i-back),i): k=min(k,day[j]) l=99999999999 for j in range(i+1,min(i+front+1,days)): l=min(l,day[j]) if day[i]collect( _x | (OclType["int"])->apply(_x) ) ; var day : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := -1 ; for i : Integer.subrange(0, (day)->size()-1) do ( var k : int := 99999999999 ; for j : Integer.subrange(Set{0, i - back}->max(), i-1) do ( k := Set{k, day[j+1]}->min()) ; var l : int := 99999999999 ; for j : Integer.subrange(i + 1, Set{i + front + 1, days}->min()-1) do ( l := Set{l, day[j+1]}->min()) ; if (day[i+1]->compareTo(Set{k, l}->min())) < 0 then ( ans := i + 1 ; break ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x,y=[int(i)for i in input().strip().split()] a=[int(i)for i in input().strip().split()] for i in range(n): val=a[i] check=True for j in range(max(0,i-x),i): if a[j]<=val : check=False break if check==False : continue for j in range(i+1,min(i+y+1,n)): if a[j]<=val : check=False break if check : break if check : print(i+1) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,x,y} := input()->trim().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a : Sequence := input()->trim().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; for i : Integer.subrange(0, n-1) do ( var val : OclAny := a[i+1] ; var check : boolean := true ; for j : Integer.subrange(Set{0, i - x}->max(), i-1) do ( if (a[j+1]->compareTo(val)) <= 0 then ( check := false ; break ) else skip) ; if check = false then ( continue ) else skip ; for j : Integer.subrange(i + 1, Set{i + y + 1, n}->min()-1) do ( if (a[j+1]->compareTo(val)) <= 0 then ( check := false ; break ) else skip) ; if check then ( break ) else skip) ; if check then ( execute (i + 1)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minChanges(A,n): cnt=0 for i in range(n-2): if((i-1>=0)and A[i-1]==1 and A[i+1]==1 and A[i]==0): A[i+1]=0 cnt=cnt+1 return cnt A=[1,1,0,1,1,0,1,0,1,0] n=len(A) print(minChanges(A,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; A := Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 0 }))))))))) ; n := (A)->size() ; execute (minChanges(A, n))->display(); operation minChanges(A : OclAny, n : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; for i : Integer.subrange(0, n - 2-1) do ( if ((i - 1 >= 0) & A[i - 1+1] = 1 & A[i + 1+1] = 1 & A[i+1] = 0) then ( A[i + 1+1] := 0 ; cnt := cnt + 1 ) else skip) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(x)for x in input().split(" ")] lists=[] sq=0 l=k=0 for i in range(n): lists.append(input()) for i in range(n): sq=lists[i].count("B") if sq!=0 : sq=(sq+1)//2 l=i k=lists[i].find("B") break print(l+sq,k+sq) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var lists : Sequence := Sequence{} ; var sq : int := 0 ; var l : OclAny := 0; var k : int := 0 ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : lists)) ; for i : Integer.subrange(0, n-1) do ( sq := lists[i+1]->count("B") ; if sq /= 0 then ( sq := (sq + 1) div 2 ; l := i ; k := lists[i+1]->indexOf("B") - 1 ; break ) else skip) ; execute (l + sq)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def balancedBrackets(Str): dep=0 minDep=0 for i in Str : if(i=='('): dep+=1 else : dep-=1 if(minDep>dep): minDep=dep if(minDep<0): for i in range(abs(minDep)): Str='('+Str dep=0 for i in Str : if(i=='('): dep+=1 else : dep-=1 if(dep!=0): for i in range(dep): Str=Str+')' return Str Str=")))()" print(balancedBrackets(Str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Str := ")))()" ; execute (balancedBrackets(Str))->display(); operation balancedBrackets(Str : OclAny) : OclAny pre: true post: true activity: var dep : int := 0 ; var minDep : int := 0 ; for i : Str do ( if (i = '(') then ( dep := dep + 1 ) else ( dep := dep - 1 ) ; if ((minDep->compareTo(dep)) > 0) then ( minDep := dep ) else skip) ; if (minDep < 0) then ( for i : Integer.subrange(0, (minDep)->abs()-1) do ( Str := '(' + Str) ) else skip ; dep := 0 ; for i : Str do ( if (i = '(') then ( dep := dep + 1 ) else ( dep := dep - 1 )) ; if (dep /= 0) then ( for i : Integer.subrange(0, dep-1) do ( Str := Str + ')') ) else skip ; return Str; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countOne(n): count=0 while(n): n=n &(n-1) count+=1 if(count % 2==0): return 1 else : return 0 def summDigits(n): summ=0 while(n!=0): summ+=n % 10 n//=10 return summ arr=[4,9,15] n=len(arr) total_summ=0 for i in range(n): if(countOne(arr[i])): total_summ+=summDigits(arr[i]) print(total_summ) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var arr : Sequence := Sequence{4}->union(Sequence{9}->union(Sequence{ 15 })) ; n := (arr)->size() ; var total_summ : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (countOne(arr[i+1])) then ( total_summ := total_summ + summDigits(arr[i+1]) ) else skip) ; execute (total_summ)->display(); operation countOne(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while (n) do ( n := MathLib.bitwiseAnd(n, (n - 1)) ; count := count + 1) ; if (count mod 2 = 0) then ( return 1 ) else ( return 0 ); operation summDigits(n : OclAny) : OclAny pre: true post: true activity: var summ : int := 0 ; while (n /= 0) do ( summ := summ + n mod 10 ; n := n div 10) ; return summ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def __gcd(a,b): return a if(b==0)else __gcd(b,a % b) def digitGCD(n): gcd=0 while(n>0): gcd=__gcd(n % 10,gcd) if(gcd==1): return 1 n=n//10 return gcd n=2448 print(digitGCD(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 2448 ; execute (digitGCD(n))->display(); operation __gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return if (b = 0) then a else __gcd(b, a mod b) endif; operation digitGCD(n : OclAny) : OclAny pre: true post: true activity: var gcd : int := 0 ; while (n > 0) do ( gcd := __gcd(n mod 10, gcd) ; if (gcd = 1) then ( return 1 ) else skip ; n := n div 10) ; return gcd; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w=map(int,input().split()) INF=10**20 dp=[[INF]*(w+1)]+[[INF]+[0]*w for _ in range(h)] dp[0][1]=0 for y in range(1,h+1): line=list(map(int,list(input()))) for x in range(1,w+1): dp[y][x]=min(dp[y-1][x],dp[y][x-1])+line[x-1] print(dp[h][w]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var INF : double := (10)->pow(20) ; var dp : Sequence := Sequence{ MatrixLib.elementwiseMult(Sequence{ INF }, (w + 1)) }->union(Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (Sequence{ INF }->union(MatrixLib.elementwiseMult(Sequence{ 0 }, w))))) ; dp->first()[1+1] := 0 ; for y : Integer.subrange(1, h + 1-1) do ( var line : Sequence := ((((OclFile["System.in"]).readLine())->characters())->collect( _x | (OclType["int"])->apply(_x) )) ; for x : Integer.subrange(1, w + 1-1) do ( dp[y+1][x+1] := Set{dp[y - 1+1][x+1], dp[y+1][x - 1+1]}->min() + line[x - 1+1])) ; execute (dp[h+1][w+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): import sys file_input=sys.stdin H,W=map(int,file_input.readline().split()) from itertools import accumulate from operator import add first_line=file_input.readline().rstrip() memo_1=accumulate(map(int,first_line),add) for line in file_input : line=map(int,line.rstrip()) ans=next(line)+next(memo_1) memo_2=[ans] for n,m in zip(line,memo_1): ans=min(ans+n,m+n) memo_2.append(ans) memo_1=iter(memo_2) print(ans) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: skip ; var file_input : OclFile := OclFile["System.in"] ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (file_input.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; skip ; var first_line : OclAny := file_input.readLine().rstrip() ; var memo skip : OclAny := accumulate((first_line)->collect( _x | (OclType["int"])->apply(_x) ), add) ; for line : file_input do ( var line : Sequence := (StringLib.rightTrim(line))->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : OclAny := (line).next() + (memo var line : Sequence := (StringLib.rightTrim(line))->collect( _x | (OclType["int"])->apply(_x) )).next() ; var memo:= Sequence{ ans } : Sequence := Sequence{ ans } ; for _tuple : Integer.subrange(1, line->size())->collect( _indx | Sequence{line->at(_indx), memoline, memoline->at(_indx)} ) do (var _indx : int := 1; var n : OclAny := _tuple->at(_indx); _indx := _indx + 1; var m : OclAny := _tuple->at(_indx); ans := Set{ans + n, m + n}->min() ; execute ((ans) : memo.append(ans))) ; memo var line : Sequence := (StringLib.rightTrim(line))->collect( _x | (OclType["int"])->apply(_x) ) := OclIterator.newOclIterator_Sequence(memo_2)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- [H,W]=list(map(int,input().split())) ls=[] for i in range(H): ls.append(input()) dp=[[0 for i in range(W)]for j in range(H)] for i in range(H): for j in range(W): if i==0 and j==0 : dp[i][j]=0 elif i==0 : dp[i][j]=dp[i][j-1]+int(ls[i][j]) elif j==0 : dp[i][j]=dp[i-1][j]+int(ls[i][j]) else : dp[i][j]=min(dp[i-1][j],dp[i][j-1])+int(ls[i][j]) print(dp[H-1][W-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: Sequence{H}->union(Sequence{ W }) := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ls : Sequence := Sequence{} ; for i : Integer.subrange(0, H-1) do ( execute (((OclFile["System.in"]).readLine()) : ls)) ; var dp : Sequence := Integer.subrange(0, H-1)->select(j | true)->collect(j | (Integer.subrange(0, W-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, H-1) do ( for j : Integer.subrange(0, W-1) do ( if i = 0 & j = 0 then ( dp[i+1][j+1] := 0 ) else (if i = 0 then ( dp[i+1][j+1] := dp[i+1][j - 1+1] + ("" + ((ls[i+1][j+1])))->toInteger() ) else (if j = 0 then ( dp[i+1][j+1] := dp[i - 1+1][j+1] + ("" + ((ls[i+1][j+1])))->toInteger() ) else ( dp[i+1][j+1] := Set{dp[i - 1+1][j+1], dp[i+1][j - 1+1]}->min() + ("" + ((ls[i+1][j+1])))->toInteger() ) ) ) )) ; execute (dp[H - 1+1][W - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def main(args): H,W=map(int,input().split(' ')) data=[] for i in range(H): data.append([int(x)for x in list(input().strip('\n'))]) dp=[[0]*W for _ in range(H)] for i in range(1,H): dp[i][0]=dp[i-1][0]+data[i][0] for j in range(1,W): dp[0][j]=dp[0][j-1]+data[0][j] for i in range(1,H): for j in range(1,W): dp[i][j]=data[i][j]+min(dp[i-1][j],dp[i][j-1]) print(dp[-1][-1]) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation main(args : OclAny) pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var data : Sequence := Sequence{} ; for i : Integer.subrange(0, H-1) do ( execute (((input()->trim())->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) : data)) ; var dp : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, W))) ; for i : Integer.subrange(1, H-1) do ( dp[i+1]->first() := dp[i - 1+1]->first() + data[i+1]->first()) ; for j : Integer.subrange(1, W-1) do ( dp->first()[j+1] := dp->first()[j - 1+1] + data->first()[j+1]) ; for i : Integer.subrange(1, H-1) do ( for j : Integer.subrange(1, W-1) do ( dp[i+1][j+1] := data[i+1][j+1] + Set{dp[i - 1+1][j+1], dp[i+1][j - 1+1]}->min())) ; execute (dp->last()->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def factorial(n): if(n==0): return 1 return n*factorial(n-1) def LCMOfNeighbourFact(n): return factorial(n+1) N=5 print(LCMOfNeighbourFact(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := 5 ; execute (LCMOfNeighbourFact(N))->display(); operation factorial(n : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return 1 ) else skip ; return n * factorial(n - 1); operation LCMOfNeighbourFact(n : OclAny) : OclAny pre: true post: true activity: return factorial(n + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w=map(int,input().split()) dp=[[float("inf")for i in range(w+1)]for j in range(h+1)] dp[0][1]=0 town=[["0"]*(w+1)] for i in range(h): town.append(list("0"+input())) for i in range(1,w+1): for j in range(1,h+1): dp[j][i]=min(dp[j-1][i],dp[j][i-1])+int(town[j][i]) print(dp[-1][-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dp : Sequence := Integer.subrange(0, h + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, w + 1-1)->select(i | true)->collect(i | (("" + (("inf")))->toReal())))) ; dp->first()[1+1] := 0 ; var town : Sequence := Sequence{ MatrixLib.elementwiseMult(Sequence{ "0" }, (w + 1)) } ; for i : Integer.subrange(0, h-1) do ( execute ((("0" + (OclFile["System.in"]).readLine())->characters()) : town)) ; for i : Integer.subrange(1, w + 1-1) do ( for j : Integer.subrange(1, h + 1-1) do ( dp[j+1][i+1] := Set{dp[j - 1+1][i+1], dp[j+1][i - 1+1]}->min() + ("" + ((town[j+1][i+1])))->toInteger())) ; execute (dp->last()->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil for _ in range(int(input())): a,b,c,d,k=map(int,input().split()) first=ceil(a/c) second=ceil(b/d) print(-1 if first+second>k else f"{first}{k-first}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var k : OclAny := null; Sequence{a,b,c,d,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var first : OclAny := ceil(a / c) ; var second : OclAny := ceil(b / d) ; execute (if (first + second->compareTo(k)) > 0 then -1 else StringLib.formattedString("{first}{k-first}") endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() i=j=-1 while j<0 : s=input(); j=s.find('B'); i+=1 c=s.count('B')//2+1 print(i+c,j+c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var i : OclAny := -1; var j : int := -1 ; while j < 0 do ( var s : String := (OclFile["System.in"]).readLine(); j := s->indexOf('B') - 1; i := i + 1) ; var c : int := s->count('B') div 2 + 1 ; execute (i + c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for j in range(t): a,b,c,d,k=map(int,input().split()) s1=int((a+c-1)//c) s2=int((b+d-1)//d) if s1+s2<=k : print(s1,s2) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var k : OclAny := null; Sequence{a,b,c,d,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s1 : int := ("" + (((a + c - 1) div c)))->toInteger() ; var s2 : int := ("" + (((b + d - 1) div d)))->toInteger() ; if (s1 + s2->compareTo(k)) <= 0 then ( execute (s1)->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math t=int(input()) for i in range(t): a,b,c,d,k=[int(i)for i in input().split()] e=math.ceil(a/c) f=math.ceil(b/d) q=e+f if q<=k : print(e,f) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var k : OclAny := null; Sequence{a,b,c,d,k} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var e : double := (a / c)->ceil() ; var f : double := (b / d)->ceil() ; var q : OclAny := e + f ; if (q->compareTo(k)) <= 0 then ( execute (e)->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil for _ in range(int(input())): a,b,c,d,k=map(int,input().split()) a=ceil(a/c) b=ceil(b/d) if a+b>k : print(-1) else : print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var k : OclAny := null; Sequence{a,b,c,d,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := ceil(a / c) ; var b : OclAny := ceil(b / d) ; if (a + b->compareTo(k)) > 0 then ( execute (-1)->display() ) else ( execute (a)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : t-=1 a,b,c,d,k=input().split() pen=0 pencil=0 if int(a)% int(c)!=0 : pen=int(a)//int(c)+1 else : pen=int(a)//int(c) if int(b)% int(d)!=0 : pencil=int(b)//int(d)+1 else : pencil=int(b)//int(d) if pen+pencil>int(k): print(-1) else : print(f'{pen}{pencil}') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( t := t - 1 ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var k : OclAny := null; Sequence{a,b,c,d,k} := input().split() ; var pen : int := 0 ; var pencil : int := 0 ; if ("" + ((a)))->toInteger() mod ("" + ((c)))->toInteger() /= 0 then ( pen := ("" + ((a)))->toInteger() div ("" + ((c)))->toInteger() + 1 ) else ( pen := ("" + ((a)))->toInteger() div ("" + ((c)))->toInteger() ) ; if ("" + ((b)))->toInteger() mod ("" + ((d)))->toInteger() /= 0 then ( pencil := ("" + ((b)))->toInteger() div ("" + ((d)))->toInteger() + 1 ) else ( pencil := ("" + ((b)))->toInteger() div ("" + ((d)))->toInteger() ) ; if (pen + pencil->compareTo(("" + ((k)))->toInteger())) > 0 then ( execute (-1)->display() ) else ( execute (StringLib.formattedString('{pen}{pencil}'))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect h,w=map(int,input().split()) n=int(input()) a=list(map(int,input().split())) b=[0] for i in range(n): b.append(b[-1]+a[i]) count=0 for i in range(h): temp=[] for j in range(w): temp.append(str(bisect.bisect(b,count))) count+=1 if i % 2==1 : temp.reverse() print(" ".join(temp)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := Sequence{ 0 } ; for i : Integer.subrange(0, n-1) do ( execute ((b->last() + a[i+1]) : b)) ; var count : int := 0 ; for i : Integer.subrange(0, h-1) do ( var temp : Sequence := Sequence{} ; for j : Integer.subrange(0, w-1) do ( execute ((("" + ((bisect.bisect(b, count))))) : temp) ; count := count + 1) ; if i mod 2 = 1 then ( temp := temp->reverse() ) else skip ; execute (StringLib.sumStringsWithSeparator((temp), " "))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- [h,w]=[int(i)for i in input().split()] n=int(input()) a=[[int(i),x+1]for(x,i)in enumerate(input().split())] a=sorted(a,key=lambda x : x[0]) a=a[: :-1] cc=[] for i in a : for j in range(i[0]): cc.append(str(i[1])) c=[[0 for i in range(w)]for j in range(h)] def dfs(u,v): S=[] c[u][v]=cc.pop() S.append([u,v]) while len(S): v=S.pop() for i in[[0,1],[1,0],[-1,0],[0,-1]]: if 0<=v[0]+i[0]union(Sequence{ w }) := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(1, (input().split())->size())->collect( _indx | Sequence{_indx-1, (input().split())->at(_indx)} )->select(Sequence{x, i} | true)->collect(Sequence{x, i} | (Sequence{("" + ((i)))->toInteger()}->union(Sequence{ x + 1 }))) ; a := a->sortedBy($x | (lambda x : OclAny in (x->first()))->apply($x)) ; a := a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var cc : Sequence := Sequence{} ; for i : a do ( for j : Integer.subrange(0, i->first()-1) do ( execute ((("" + ((i[1+1])))) : cc))) ; var c : Sequence := Integer.subrange(0, h-1)->select(j | true)->collect(j | (Integer.subrange(0, w-1)->select(i | true)->collect(i | (0)))) ; skip ; dfs(0, 0) ; for i : Integer.subrange(0, h-1) do ( execute (StringLib.sumStringsWithSeparator((c[i+1]), " "))->display()); operation dfs(u : OclAny, v : OclAny) pre: true post: true activity: var S : Sequence := Sequence{} ; c[u+1][v+1] := cc->last() ; cc := cc->front() ; execute ((Sequence{u}->union(Sequence{ v })) : S) ; while (S)->size() do ( v := S->last() ; S := S->front() ; for i : Sequence{Sequence{0}->union(Sequence{ 1 })}->union(Sequence{Sequence{1}->union(Sequence{ 0 })}->union(Sequence{Sequence{-1}->union(Sequence{ 0 })}->union(Sequence{ Sequence{0}->union(Sequence{ -1 }) }))) do ( if 0 <= v->first() + i->first() & (v->first() + i->first() < h) & 0 <= v[1+1] + i[1+1] & (v[1+1] + i[1+1] < w) & c[v->first() + i->first()+1][v[1+1] + i[1+1]+1] = 0 then ( c[v->first() + i->first()+1][v[1+1] + i[1+1]+1] := cc->last() ; cc := cc->front() ; execute ((Sequence{v->first() + i->first()}->union(Sequence{ v[1+1] + i[1+1] })) : S) ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections.abc import Iterable def flatten(A : "Array")->"Array" : if isinstance(A,Iterable): return[i for a in A for i in flatten(a)] else : return[A] def main(): H,W,N,*A=map(int,open(0).read().split()) grid=flatten([color]*cnt for color,cnt in enumerate(A,1)) for i,g in enumerate(zip(*[iter(grid)]*W)): if i & 1==0 : print(*g) else : print(*g[: :-1]) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation flatten(A : "Array") : String pre: true post: true activity: if (Iterable).isInstance(A) then ( return A->select(a; i : flatten(a) | true)->collect(a; i : flatten(a) | (i)) ) else ( return Sequence{ A } ); operation main() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; var N : OclAny := null; var A : OclAny := null; Sequence{H,W,N,A} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var grid : OclAny := flatten((argument (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name color))))))) ])) * (expr (atom (name cnt))))))) (comp_for for (exprlist (expr (atom (name color))) , (expr (atom (name cnt)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ))))))))) ; for _tuple : Integer.subrange(1, (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name grid)))))))) )))))))) ])) * (expr (atom (name W))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name grid)))))))) )))))))) ])) * (expr (atom (name W))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name grid)))))))) )))))))) ])) * (expr (atom (name W))))))))`third->at(_indx)} ))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name grid)))))))) )))))))) ])) * (expr (atom (name W))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name grid)))))))) )))))))) ])) * (expr (atom (name W))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name grid)))))))) )))))))) ])) * (expr (atom (name W))))))))`third->at(_indx)} ))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var g : OclAny := _tuple->at(_indx); if MathLib.bitwiseAnd(i, 1) = 0 then ( execute ((argument * (test (logical_test (comparison (expr (atom (name g))))))))->display() ) else ( execute ((argument * (test (logical_test (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ]))))))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,radians,log from itertools import accumulate,permutations,combinations,product from operator import itemgetter,mul from copy import deepcopy from string import ascii_lowercase,ascii_uppercase,digits from bisect import bisect,bisect_left from fractions import gcd from heapq import heappush,heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) def ZIP(n): return zip(*(MAP()for _ in range(n))) sys.setrecursionlimit(10**9) INF=float('inf') mod=10**9+7 H,W=MAP() N=INT() a=LIST()[: :-1] ans=[[0]*W for _ in range(H)] tmp=a.pop() color=1 cnt=0 for i in range(H): for j in range(W): if i % 2 : j=W-j-1 ans[i][j]=color cnt+=1 if cnt==tmp and a : cnt=0 tmp=a.pop() color+=1 for i in ans : print(" ".join([str(x)for x in i])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := MAP() ; var N : OclAny := INT() ; var a : OclAny := LIST()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var ans : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, W))) ; var tmp : OclAny := a->last() ; a := a->front() ; var color : int := 1 ; var cnt : int := 0 ; for i : Integer.subrange(0, H-1) do ( for j : Integer.subrange(0, W-1) do ( if i mod 2 then ( var j : double := W - j - 1 ) else skip ; ans[i+1][j+1] := color ; cnt := cnt + 1 ; if cnt = tmp & a then ( cnt := 0 ; tmp := a->last() ; a := a->front() ; color := color + 1 ) else skip)) ; for i : ans do ( execute (StringLib.sumStringsWithSeparator((i->select(x | true)->collect(x | (("" + ((x)))))), " "))->display()); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ZIP(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))`third->at(_indx)} ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=map(int,input().split()) print(min(n*a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{n * a, b}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import numpy as np readline=sys.stdin.buffer.readline def main(): H,W=map(int,readline().split()) N=int(readline()) A=list(map(int,readline().split())) B=np.ones([H*W],dtype=np.int32) s=0 for i,a in enumerate(A): B[s : s+a]=i+1 s+=a B=np.reshape(B,[H,W]) for i in range(H): if i % 2==1 : B[i,:]=B[i,:][: :-1] print(*B[i,:]) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var readline : OclAny := sys.stdin.buffer.readline ; skip ; main(); operation main() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var N : int := ("" + ((readline())))->toInteger() ; var A : Sequence := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var B : Sequence := MatrixLib.singleValueMatrix(Sequence{ H * W }, 1.0) ; var s : int := 0 ; for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); B.subrange(s+1, s + a) := i + 1 ; s := s + a) ; B := MatrixLib.fillMatrixFrom(B, Sequence{H}->union(Sequence{ W })) ; for i : Integer.subrange(0, H-1) do ( if i mod 2 = 1 then ( B[i+1] := B[i+1](subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ) else skip ; execute ((argument * (test (logical_test (comparison (expr (atom (name B)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i))))))) , (subscript :)) ]))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r,c=map(int,input().split(' ')) a=[] for i in range(r): a.append(input()) i=0 t=0 b=0 while(icollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, r-1) do ( execute (((OclFile["System.in"]).readLine()) : a)) ; var i : int := 0 ; var t : int := 0 ; var b : int := 0 ; while ((i->compareTo(r)) < 0) do ( var j : int := 0 ; while ((j->compareTo(c)) < 0 & a[i+1][j+1] = 'W') do ( j := j + 1) ; if (j /= c) then ( t := i ; while ((i->compareTo(r)) < 0 & a[i+1][j+1] = 'B') do ( i := i + 1) ; b := i ; break; ) else skip ; i := i + 1) ; var m : int := (b - t) div 2 ; execute (t + m + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,k=map(int,input().split()) towers=list(map(int,input().split())) min_i=0 max_i=n-1 operations=[] for i in range(k): for i in range(n): if towers[i]>towers[max_i]: max_i=i if towers[i]towers[max_i]: max_i=i if towers[i]collect( _x | (OclType["int"])->apply(_x) ) ; var towers : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var min_i : int := 0 ; var max_i : double := n - 1 ; var operations : Sequence := Sequence{} ; for i : Integer.subrange(0, k-1) do ( for i : Integer.subrange(0, n-1) do ( if (towers[i+1]->compareTo(towers[max_i+1])) > 0 then ( max_i := i ) else skip ; if (towers[i+1]->compareTo(towers[min_i+1])) < 0 then ( min_i := i ) else skip) ; if (towers[max_i+1] - 1->compareTo(towers[min_i+1])) <= 0 then ( break ) else skip ; towers[max_i+1] := towers[max_i+1] - 1 ; towers[min_i+1] := towers[min_i+1] + 1 ; execute ((Sequence{max_i + 1, min_i + 1}) : operations)) ; for i : Integer.subrange(0, n-1) do ( if (towers[i+1]->compareTo(towers[max_i+1])) > 0 then ( max_i := i ) else skip ; if (towers[i+1]->compareTo(towers[min_i+1])) < 0 then ( min_i := i ) else skip) ; execute (towers[max_i+1] - towers[min_i+1])->display() ; for op : operations do ( execute (op->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) A=[int(x)for x in input().split()] def find_min(): m=min(A) for i in range(n): if A[i]==m : return i+1 def find_max(): m=max(A) for i in range(n): if A[i]==m : return i+1 cnt=0 ans=[] for i in range(k): if max(A)-min(A)==0 : break id_min=find_min() id_max=find_max() A[id_max-1]-=1 A[id_min-1]+=1 ans.append((id_max,id_min)) cnt=i+1 print(max(A)-min(A),cnt) for t in ans : print(t[0],t[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; skip ; skip ; var cnt : int := 0 ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, k-1) do ( if (A)->max() - (A)->min() = 0 then ( break ) else skip ; var id_min : OclAny := find_min() ; var id_max : OclAny := find_max() ; A[id_max - 1+1] := A[id_max - 1+1] - 1 ; A[id_min - 1+1] := A[id_min - 1+1] + 1 ; execute ((Sequence{id_max, id_min}) : ans) ; cnt := i + 1) ; execute ((A)->max() - (A)->min())->display() ; for t : ans do ( execute (t->first())->display()); operation find_min() : OclAny pre: true post: true activity: var m : OclAny := (A)->min() ; for i : Integer.subrange(0, n-1) do ( if A[i+1] = m then ( return i + 1 ) else skip); operation find_max() : OclAny pre: true post: true activity: m := (A)->max() ; for i : Integer.subrange(0, n-1) do ( if A[i+1] = m then ( return i + 1 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_of_towers,num_of_turns=map(int,input().split(" ")) towers_initial=list(map(int,input().split(" "))) min_instability=0 min_turns_for_min_instability=-1 towers=towers_initial.copy() for i in range(0,num_of_turns): shortest=min(range(num_of_towers),key=towers.__getitem__) tallest=max(range(num_of_towers),key=towers.__getitem__) towers[shortest]+=1 towers[tallest]-=1 if i==num_of_turns-1 : min_instability=max(towers)-min(towers) towers=towers_initial.copy() for i in range(0,num_of_turns): if(int(max(towers))-int(min(towers)))==min_instability : min_turns_for_min_instability=i break shortest=min(range(num_of_towers),key=towers.__getitem__) tallest=max(range(num_of_towers),key=towers.__getitem__) towers[shortest]+=1 towers[tallest]-=1 if min_turns_for_min_instability==-1 : min_turns_for_min_instability=num_of_turns print(str(min_instability)+" "+str(min_turns_for_min_instability)) towers=towers_initial.copy() for i in range(0,min_turns_for_min_instability): shortest=min(range(num_of_towers),key=towers.__getitem__) tallest=max(range(num_of_towers),key=towers.__getitem__) print(str(int(tallest)+1)+" "+str(int(shortest)+1)) towers[shortest]+=1 towers[tallest]-=1 if(max(towers)-min(towers))==min_instability : min_turns_for_min_instability=i+1 break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_of_towers : OclAny := null; var num_of_turns : OclAny := null; Sequence{num_of_towers,num_of_turns} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var towers_initial : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var min_instability : int := 0 ; var min_turns_for_min_instability : int := -1 ; var towers : OclAny := towers_initial->copy() ; for i : Integer.subrange(0, num_of_turns-1) do ( var shortest : OclAny := Set{Integer.subrange(0, num_of_towers-1), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name towers)) (trailer . (name __getitem__)))))))}->min() ; var tallest : OclAny := Set{Integer.subrange(0, num_of_towers-1), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name towers)) (trailer . (name __getitem__)))))))}->max() ; towers[shortest+1] := towers[shortest+1] + 1 ; towers[tallest+1] := towers[tallest+1] - 1 ; if i = num_of_turns - 1 then ( min_instability := (towers)->max() - (towers)->min() ) else skip) ; towers := towers_initial->copy() ; for i : Integer.subrange(0, num_of_turns-1) do ( if (("" + (((towers)->max())))->toInteger() - ("" + (((towers)->min())))->toInteger()) = min_instability then ( min_turns_for_min_instability := i ; break ) else skip ; shortest := Set{Integer.subrange(0, num_of_towers-1), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name towers)) (trailer . (name __getitem__)))))))}->min() ; tallest := Set{Integer.subrange(0, num_of_towers-1), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name towers)) (trailer . (name __getitem__)))))))}->max() ; towers[shortest+1] := towers[shortest+1] + 1 ; towers[tallest+1] := towers[tallest+1] - 1) ; if min_turns_for_min_instability = -1 then ( min_turns_for_min_instability := num_of_turns ) else skip ; execute (("" + ((min_instability))) + " " + ("" + ((min_turns_for_min_instability))))->display() ; towers := towers_initial->copy() ; for i : Integer.subrange(0, min_turns_for_min_instability-1) do ( shortest := Set{Integer.subrange(0, num_of_towers-1), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name towers)) (trailer . (name __getitem__)))))))}->min() ; tallest := Set{Integer.subrange(0, num_of_towers-1), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name towers)) (trailer . (name __getitem__)))))))}->max() ; execute (("" + ((("" + ((tallest)))->toInteger() + 1))) + " " + ("" + ((("" + ((shortest)))->toInteger() + 1))))->display() ; towers[shortest+1] := towers[shortest+1] + 1 ; towers[tallest+1] := towers[tallest+1] - 1 ; if ((towers)->max() - (towers)->min()) = min_instability then ( min_turns_for_min_instability := i + 1 ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=list(map(list,zip(map(int,input().split()),range(1,n+1)))) a.sort() op=[] for _ in range(k): if a[-1][0]-a[0][0]<=1 : break op.append((a[-1][1],a[0][1])) a[0][0]+=1 a[-1][0]-=1 a.sort() print(a[-1][0]-a[0][0],len(op)) for a,b in op : print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((Integer.subrange(1, (input().split())->collect( _x | (OclType["int"])->apply(_x) )->size())->collect( _indx | Sequence{(input().split())->collect( _x | (OclType["int"])->apply(_x) )->at(_indx), Integer.subrange(1, n + 1-1)->at(_indx)} ))->collect( _x | (OclType["Sequence"])->apply(_x) )) ; a := a->sort() ; var op : Sequence := Sequence{} ; for _anon : Integer.subrange(0, k-1) do ( if a->last()->first() - a->first()->first() <= 1 then ( break ) else skip ; execute ((Sequence{a->last()[1+1], a->first()[1+1]}) : op) ; a->first()->first() := a->first()->first() + 1 ; a->last()->first() := a->last()->first() - 1 ; a := a->sort()) ; execute (a->last()->first() - a->first()->first())->display() ; for _tuple : op do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getMoves(n,k,towers): if not towers or len(towers)<2 : return 0,[] for i in range(n): towers[i]=[towers[i],i+1] towers.sort() moves=[]; instability=towers[-1][0]-towers[0][0] t1=None ; t2=None while k>0 and towers[-1][0]>towers[0][0]+1 : towers[0][0]+=1 towers[-1][0]-=1 moves.append([towers[-1][1],towers[0][1]]) towers.sort() instability=towers[-1][0]-towers[0][0] k-=1 return instability,moves n,k=list(map(int,input().split(' '))) towers=list(map(int,input().split(' '))) instability,moves=getMoves(n,k,towers) print('{}{}'.format(instability,len(moves))) for move in moves : print(' '.join(map(str,move))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{n,k} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; towers := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; Sequence{instability,moves} := getMoves(n, k, towers) ; execute (StringLib.interpolateStrings('{}{}', Sequence{instability, (moves)->size()}))->display() ; for move : moves do ( execute (StringLib.sumStringsWithSeparator(((move)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()); operation getMoves(n : OclAny, k : OclAny, towers : OclAny) : OclAny pre: true post: true activity: if not(towers) or (towers)->size() < 2 then ( return 0, Sequence{} ) else skip ; for i : Integer.subrange(0, n-1) do ( towers[i+1] := Sequence{towers[i+1]}->union(Sequence{ i + 1 })) ; towers := towers->sort() ; var moves : Sequence := Sequence{}; var instability : double := towers->last()->first() - towers->first()->first() ; var t1 : OclAny := null; var t2 : OclAny := null ; while k > 0 & (towers->last()->first()->compareTo(towers->first()->first() + 1)) > 0 do ( towers->first()->first() := towers->first()->first() + 1 ; towers->last()->first() := towers->last()->first() - 1 ; execute ((Sequence{towers->last()[1+1]}->union(Sequence{ towers->first()[1+1] })) : moves) ; towers := towers->sort() ; instability := towers->last()->first() - towers->first()->first() ; k := k - 1) ; return instability, moves; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq def ReadIn(): t=int(input()) for c in range(1,t+1): m,n=[int(x)for x in input().split()] a=[int(x)for x in input().split()] yield c,n,a def OK(n,a,guess): return sum([guess//x+1 for x in a])>=n def Solve(n,a): if n<=len(a): return n lower=0 upper=max(a)*n while lowerat(_indx); _indx := _indx + 1; var n : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); execute (StringLib.format('Case #%d: %d',Sequence{c, Solve(n, a)}))->display()) ) else skip; operation ReadIn(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for c : Integer.subrange(1, t + 1-1) do ( var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return c, n, a); operation OK(n : OclAny, a : OclAny, guess : OclAny) : OclAny pre: true post: true activity: return ((a->select(x | true)->collect(x | (guess div x + 1)))->sum()->compareTo(n)) >= 0; operation Solve(n : OclAny, a : OclAny) : OclAny pre: true post: true activity: if (n->compareTo((a)->size())) <= 0 then ( return n ) else skip ; var lower : int := 0 ; var upper : double := (a)->max() * n ; while (lower->compareTo(upper)) < 0 do ( guess := (lower + upper + 1) div 2 ; if OK(n, a, guess) then ( upper := guess - 1 ) else ( lower := guess )) ; guess := lower ; var heap : Sequence := Sequence{} ; var remain : OclAny := n ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); var num : int := guess div x + 1 ; remain := remain - num ; heapq.heappush(heap, Sequence{num * x - guess, i})) ; var ret : OclAny := heap->first()[1+1] ; for r : Integer.subrange(0, remain-1) do ( var i : OclAny := null; Sequence{t,i} := heapq.heappop(heap) ; heapq.heappush(heap, Sequence{t + a[i+1], i}) ; ret := i) ; return ret + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import atan2 def right(p,q): return p[0]*q[1]-p[1]*q[0]<=0 T=int(input()) for case in range(1,T+1): N=int(input()) P=[tuple(map(int,input().split()))for _ in range(N)] n=N-1 print("Case #{}:".format(case)) for cx,cy in P : D=[(x-cx,y-cy)for x,y in P if x!=cx or y!=cy] D.sort(key=lambda p : atan2(*p)) j=0 m=0 for i in range(n): while right(D[i],D[j % n])and jtoInteger() ; for case : Integer.subrange(1, T + 1-1) do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var P : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var n : double := N - 1 ; execute (StringLib.interpolateStrings("Case #{}:", Sequence{case}))->display() ; for _tuple : P do (var _indx : int := 1; var cx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var cy : OclAny := _tuple->at(_indx); var D : Sequence := P->select(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in x /= cx or y /= cy)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (Sequence{x - cx, y - cy})) ; D := D->sort() ; var j : int := 0 ; var m : int := 0 ; for i : Integer.subrange(0, n-1) do ( while right(D[i+1], D[j mod n+1]) & (j->compareTo(i + n)) < 0 do ( j := j + 1) ; m := Set{m, j - i}->max()) ; execute (n - m)->display())); operation right(p : OclAny, q : OclAny) : OclAny pre: true post: true activity: return p->first() * q[1+1] - p[1+1] * q->first() <= 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cal(m,t): return sum([(t+x-1)//x for x in m]) def gao(): (b,n)=list(map(int,input().split())) m=list(map(int,input().split())) l=0 r=min(m)*n ans=r while l<=r : mid=(l+r)//2 s=cal(m,mid) if s>=n : ans=mid r=mid-1 else : l=mid+1 ans=ans-1 cnt=n-cal(m,ans) for i in range(len(m)): if ans % m[i]==0 : cnt-=1 if cnt==0 : return i+1 return-1 t=int(input()) for cas in range(t): print('Case #%d:' %(cas+1),end=' ') print(gao()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; t := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for cas : Integer.subrange(0, t-1) do ( execute (StringLib.format('Case #%d:',(cas + 1)))->display() ; execute (gao())->display()); operation cal(m : OclAny, t : OclAny) : OclAny pre: true post: true activity: return (m->select(x | true)->collect(x | ((t + x - 1) div x)))->sum(); operation gao() pre: true post: true activity: ; var Sequence{b, n} : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; m := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : int := 0 ; var r : double := (m)->min() * n ; var ans : OclAny := r ; while (l->compareTo(r)) <= 0 do ( var mid : int := (l + r) div 2 ; var s : OclAny := cal(m, mid) ; if (s->compareTo(n)) >= 0 then ( ans := mid ; r := mid - 1 ) else ( l := mid + 1 )) ; ans := ans - 1 ; var cnt : double := n - cal(m, ans) ; for i : Integer.subrange(0, (m)->size()-1) do ( if ans mod m[i+1] = 0 then ( cnt := cnt - 1 ; if cnt = 0 then ( return i + 1 ) else skip ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def FindMinNum(arr,n): pre=[0 for i in range(n)] pre[0]=arr[0] for i in range(1,n,1): pre[i]=pre[i-1]+arr[i] k=sys.maxsize for i in range(n-1): rightSum=pre[n-1]-pre[i] if(rightSum>=pre[i]): k=min(k,rightSum-pre[i]) if(k!=sys.maxsize): return k return-1 if __name__=='__main__' : arr=[6,7,1,3,8,2,4] n=len(arr) print(FindMinNum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{6}->union(Sequence{7}->union(Sequence{1}->union(Sequence{3}->union(Sequence{8}->union(Sequence{2}->union(Sequence{ 4 })))))) ; n := (arr)->size() ; execute (FindMinNum(arr, n))->display() ) else skip; operation FindMinNum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var pre : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; pre->first() := arr->first() ; for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( pre[i+1] := pre[i - 1+1] + arr[i+1]) ; var k : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; for i : Integer.subrange(0, n - 1-1) do ( var rightSum : double := pre[n - 1+1] - pre[i+1] ; if ((rightSum->compareTo(pre[i+1])) >= 0) then ( k := Set{k, rightSum - pre[i+1]}->min() ) else skip) ; if (k /= (trailer . (name maxsize))) then ( return k ) else skip ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math def myinput_int(): return list(map(int,input().split())) N,A,B=myinput_int() if N*AcompareTo(B)) < 0 then ( execute (N * A)->display() ) else ( execute (B)->display() ); operation myinput_int() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import* from dataclasses import dataclass from decimal import* def solves(): n,m=map(int,input().split()) j=0 for i in range(n): x=input() j=x.count('B') if j>0 : break k=x.index('B')+1 print(i+(j//2)+1,k+j//2) t=1 for _ in range(0,t): solves() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solves()); operation solves() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var j : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x : String := (OclFile["System.in"]).readLine() ; j := x->count('B') ; if j > 0 then ( break ) else skip) ; var k : int := x->indexOf('B') - 1 + 1 ; execute (i + (j div 2) + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(a==0): return b ; return gcd(b % a,a); def divTermCount(a,b,c,num): return((num//a)+(num//b)+(num//c)-(num//((a*b)//gcd(a,b)))-(num//((c*b)//gcd(c,b)))-(num//((a*c)//gcd(a,c)))+(num//((a*b*c)//gcd(gcd(a,b),c)))); if __name__=="__main__" : a=7 ; b=3 ; c=5 ; n=100 ; print(divTermCount(a,b,c,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( a := 7; b := 3; c := 5; var n : int := 100; ; execute (divTermCount(a, b, c, n))->display(); ) else skip; operation gcd(a : OclAny, b : OclAny) pre: true post: true activity: if (a = 0) then ( return b; ) else skip ; return gcd(b mod a, a);; operation divTermCount(a : OclAny, b : OclAny, c : OclAny, num : OclAny) pre: true post: true activity: return ((num div a) + (num div b) + (num div c) - (num div ((a * b) div gcd(a, b))) - (num div ((c * b) div gcd(c, b))) - (num div ((a * c) div gcd(a, c))) + (num div ((a * b * c) div gcd(gcd(a, b), c))));; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=0 b=0 used=set([]) counter=0 def count(n,minnum,b): global counter for num in range(minnum,n+1): rep=[] nnum=num while nnum>0 : rep.append(nnum % b) nnum=nnum/b ok=True for i in range(len(rep)): if(i,rep[i])in used : ok=False break if ok : for i in range(len(rep)): used.add((i,rep[i])) if n-num==0 : counter=counter+1 else : count(n-num,num+1,b) for i in range(len(rep)): used.remove((i,rep[i])) T=int(raw_input()) for i in range(T): [n,b]=map(lambda x : int(x),raw_input().split()) counter=0 used=set([]) count(n,1,b) print("Case #%d: %d" %(i+1,counter)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute counter : OclAny; operation initialise() pre: true post: true activity: var n : int := 0 ; var b : int := 0 ; var used : Set := Set{}->union((Sequence{})) ; var counter : int := 0 ; skip ; var T : int := ("" + ((raw_input())))->toInteger() ; for i : Integer.subrange(0, T-1) do ( ; Sequence{n}->union(Sequence{ b }) := (raw_input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ) ; counter := 0 ; used := Set{}->union((Sequence{})) ; count(n, 1, b) ; execute (StringLib.format("Case #%d: %d",Sequence{i + 1, counter}))->display()); operation count(n : OclAny, minnum : OclAny, b : OclAny) pre: true post: true activity: skip ; for num : Integer.subrange(minnum, n + 1-1) do ( var rep : Sequence := Sequence{} ; var nnum : OclAny := num ; while nnum > 0 do ( execute ((nnum mod b) : rep) ; nnum := nnum / b) ; var ok : boolean := true ; for i : Integer.subrange(0, (rep)->size()-1) do ( if (used)->includes(Sequence{i, rep[i+1]}) then ( ok := false ; break ) else skip) ; if ok then ( for i : Integer.subrange(0, (rep)->size()-1) do ( execute ((Sequence{i, rep[i+1]}) : used)) ; if n - num = 0 then ( counter := counter + 1 ) else ( count(n - num, num + 1, b) ) ; for i : Integer.subrange(0, (rep)->size()-1) do ( execute ((Sequence{i, rep[i+1]}) /: used)) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isSubsetSum(set,n,sum): if(sum==0): return True if(n==0 and sum!=0): return False if(set[n-1]>sum): return isSubsetSum(set,n-1,sum); return isSubsetSum(set,n-1,sum)or isSubsetSum(set,n-1,sum-set[n-1]) set=[3,34,4,12,5,2] sum=9 n=len(set) if(isSubsetSum(set,n,sum)==True): print("Found a subset with given sum") else : print("No subset with given sum") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclType["Set"] := Sequence{3}->union(Sequence{34}->union(Sequence{4}->union(Sequence{12}->union(Sequence{5}->union(Sequence{ 2 }))))) ; sum := 9 ; n := (OclType["Set"])->size() ; if (isSubsetSum(OclType["Set"], n, sum) = true) then ( execute ("Found a subset with given sum")->display() ) else ( execute ("No subset with given sum")->display() ); operation isSubsetSum(set : OclAny, n : OclAny, sum : OclAny) : OclAny pre: true post: true activity: if (sum = 0) then ( return true ) else skip ; if (n = 0 & sum /= 0) then ( return false ) else skip ; if ((Set{}->union([n - 1+1])->compareTo(sum)) > 0) then ( return isSubsetSum(OclType["Set"], n - 1, sum); ) else skip ; return isSubsetSum(OclType["Set"], n - 1, sum) or isSubsetSum(OclType["Set"], n - 1, sum - Set{}->union([n - 1+1])); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(map(int,input().split())) if len(s)==2 : c=s[0]; d=s[1] else : c=s[0]; d=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) e=0 ; i=0 while icollect( _x | (OclType["int"])->apply(_x) )) ; if (s)->size() = 2 then ( var c : OclAny := s->first(); var d : OclAny := s[1+1] ) else ( c := s->first(); d := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var e : int := 0; var i : int := 0 ; while (i->compareTo(d - e)) < 0 do ( var p : int := i; var q : int := 0 ; for j : Integer.subrange(0, c-1) do ( if a[j+1] = b[p+1] then ( q := q + 1; p := p + 1 ) else skip) ; e := Set{e, q}->max() ; i := i + 1) ; execute (e)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(map(int,input().split())) if len(s)>1 : c=s[0]; d=s[1] else : c=s[0]; d=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) e=0 ; i=0 while icollect( _x | (OclType["int"])->apply(_x) )) ; if (s)->size() > 1 then ( var c : OclAny := s->first(); var d : OclAny := s[1+1] ) else ( c := s->first(); d := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var e : int := 0; var i : int := 0 ; while (i->compareTo(d - e)) < 0 do ( var p : int := i; var q : int := 0 ; for j : Integer.subrange(0, c-1) do ( if a[j+1] = b[p+1] then ( q := q + 1; p := p + 1 ) else skip) ; e := Set{e, q}->max() ; i := i + 1) ; execute (e)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): A,B=map(int,input().split()) s1=tuple(map(int,input().split())) s2=tuple(map(int,input().split())) result=0 for i in range(B): k=0 cnt=0 for j,n in enumerate(s2[i :]): for m in s1[k :]: k+=1 if n==m : cnt+=1 break if cnt>result : result=cnt if result>=B-i : break print(result) if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( solve() ) else skip; operation solve() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var result : int := 0 ; for i : Integer.subrange(0, B-1) do ( var k : int := 0 ; var cnt : int := 0 ; for _tuple : Integer.subrange(1, (s2.subrange(i+1))->size())->collect( _indx | Sequence{_indx-1, (s2.subrange(i+1))->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var n : OclAny := _tuple->at(_indx); for m : s1.subrange(k+1) do ( k := k + 1 ; if n = m then ( cnt := cnt + 1 ; break ) else skip)) ; if (cnt->compareTo(result)) > 0 then ( result := cnt ) else skip ; if (result->compareTo(B - i)) >= 0 then ( break ) else skip) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): A,B=map(int,input().split()) s1=tuple(map(int,input().split())) s2=tuple(map(int,input().split())) set1=[0]*(A+1) set1[-1]=set() for i,n in enumerate(s1[: :-1],start=2): set1[-i]=set1[-i+1]|{n} result=0 for i in range(B): k=0 cnt=0 for n in s2[i :]: if n not in set1[k]: break for m in s1[k :]: k+=1 if n==m : cnt+=1 break if cnt>result : result=cnt if result>=B-i : break print(result) if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( solve() ) else skip; operation solve() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var set1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (A + 1)) ; set1->last() := Set{}->union(()) ; for _tuple : Integer.subrange(1, (s1(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{_indx-1, (s1(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var n : OclAny := _tuple->at(_indx); set1->reverse()->at(-(-i)) := MathLib.bitwiseOr(set1->reverse()->at(-(-i + 1)), Set{ n })) ; var result : int := 0 ; for i : Integer.subrange(0, B-1) do ( var k : int := 0 ; var cnt : int := 0 ; for n : s2.subrange(i+1) do ( if (set1[k+1])->excludes(n) then ( break ) else skip ; for m : s1.subrange(k+1) do ( k := k + 1 ; if n = m then ( cnt := cnt + 1 ; break ) else skip)) ; if (cnt->compareTo(result)) > 0 then ( result := cnt ) else skip ; if (result->compareTo(B - i)) >= 0 then ( break ) else skip) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- v1,v2,v3,vm=map(int,input().split()) if v2>vm and v3*2>=vm and vm*2>=v3 : print(v1*2,v2*2,min(vm*2,v3*2),sep='\n') else : print('-1') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var v1 : OclAny := null; var v2 : OclAny := null; var v3 : OclAny := null; var vm : OclAny := null; Sequence{v1,v2,v3,vm} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (v2->compareTo(vm)) > 0 & (v3 * 2->compareTo(vm)) >= 0 & (vm * 2->compareTo(v3)) >= 0 then ( execute (v1 * 2)->display() ) else ( execute ('-1')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def STR(): return list(input()) def INT(): return int(input()) def MAP(): return map(int,input().split()) def MAP2(): return map(float,input().split()) def LIST(): return list(map(int,input().split())) def STRING(): return input() import string import sys from heapq import heappop,heappush from bisect import* from collections import deque,Counter,defaultdict from math import* from itertools import permutations,accumulate dx=[-1,1,0,0] dy=[0,0,1,-1] def check(i,v2): if 2*v2>=i and v2<=i : return False return True v1,v2,v3,v4=MAP() r1,r2,r3=0,0,0 for i in range(v1,300): if v1<=i and 2*v1>=i and check(i,v2)and check(i,v3)and check(i,v4): r1=i break for i in range(v2,300): if v2<=i and 2*v2>=i and check(i,r1)and check(i,v3)and check(i,v4): r2=i break mx=max(v3,v4) for i in range(mx,300): if v3<=i and 2*v3>=i and v4<=i and 2*v4>=i and check(i,r1)and check(i,r2): r3=i break if r1==0 or r2==0 or r3==0 : print('-1') else : print(r1,r2,r3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var dx : Sequence := Sequence{-1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 0 }))) ; var dy : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ -1 }))) ; skip ; var v1 : OclAny := null; var v3 : OclAny := null; var v4 : OclAny := null; Sequence{v1,v2,v3,v4} := MAP() ; var r1 : OclAny := null; var r2 : OclAny := null; var r3 : OclAny := null; Sequence{r1,r2,r3} := Sequence{0,0,0} ; for i : Integer.subrange(v1, 300-1) do ( if (v1->compareTo(i)) <= 0 & (2 * v1->compareTo(i)) >= 0 & check(i, v2) & check(i, v3) & check(i, v4) then ( var r1 : OclAny := i ; break ) else skip) ; for i : Integer.subrange(v2, 300-1) do ( if (v2->compareTo(i)) <= 0 & (2 * v2->compareTo(i)) >= 0 & check(i, r1) & check(i, v3) & check(i, v4) then ( var r2 : OclAny := i ; break ) else skip) ; var mx : OclAny := Set{v3, v4}->max() ; for i : Integer.subrange(mx, 300-1) do ( if (v3->compareTo(i)) <= 0 & (2 * v3->compareTo(i)) >= 0 & (v4->compareTo(i)) <= 0 & (2 * v4->compareTo(i)) >= 0 & check(i, r1) & check(i, r2) then ( var r3 : OclAny := i ; break ) else skip) ; if r1 = 0 or r2 = 0 or r3 = 0 then ( execute ('-1')->display() ) else ( execute (r1)->display() ); operation STR() : OclAny pre: true post: true activity: return ((OclFile["System.in"]).readLine())->characters(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation MAP2() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["double"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation STRING() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation check(i : OclAny, v2 : OclAny) : OclAny pre: true post: true activity: if (2 * v2->compareTo(i)) >= 0 & (v2->compareTo(i)) <= 0 then ( return false ) else skip ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f,m,s,p=map(int,input().split()) c1=f*2 c2=m*2 if p>=m : print(-1) exit() if max(p,s)/2<=min(p,s)<=max(p,s): c3=min(p,s)*2 else : print(-1) exit() print(c1) print(c2) print(c3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : OclAny := null; var m : OclAny := null; var s : OclAny := null; var p : OclAny := null; Sequence{f,m,s,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c1 : double := f * 2 ; var c2 : double := m * 2 ; if (p->compareTo(m)) >= 0 then ( execute (-1)->display() ; exit() ) else skip ; if (Set{p, s}->max() / 2->compareTo(Set{p, s}->min())) <= 0 & (Set{p, s}->min() <= Set{p, s}->max()) then ( var c3 : double := Set{p, s}->min() * 2 ) else ( execute (-1)->display() ; exit() ) ; execute (c1)->display() ; execute (c2)->display() ; execute (c3)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=(int(x)for x in input().split()) arr=[0]*n d={} for i in range(n): arr[i]=input() d[arr[i]]=i+1 for i in range(m-1,-1,-1): arr.sort(key=lambda x : x[i],reverse=i % 2!=0) for i in arr : print(d[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var d : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( arr[i+1] := (OclFile["System.in"]).readLine() ; d[arr[i+1]+1] := i + 1) ; for i : Integer.subrange(-1 + 1, m - 1)->reverse() do ( arr := arr->sort()) ; for i : arr do ( execute (d[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A=list(map(int,input().split())) ans=A[0]*A[1] if A[0]*A[1]>A[2]: ans=A[2] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : double := A->first() * A[1+1] ; if (A->first() * A[1+1]->compareTo(A[2+1])) > 0 then ( ans := A[2+1] ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- nm=input().split(' ') music=[] for i in range(int(nm[0])): music.append(input().split(' ')) moment=input().split(' ') timeCounter=0 currentSong=0 j=0 for i in range(int(nm[1])): while int(moment[i])>timeCounter and currentSongfirst())))->toInteger()-1) do ( execute ((input().split(' ')) : music)) ; var moment : OclAny := input().split(' ') ; var timeCounter : int := 0 ; var currentSong : int := 0 ; var j : int := 0 ; for i : Integer.subrange(0, ("" + ((nm[1+1])))->toInteger()-1) do ( while (("" + ((moment[i+1])))->toInteger()->compareTo(timeCounter)) > 0 & (currentSong->compareTo(("" + ((nm->first())))->toInteger())) < 0 do ( timeCounter := timeCounter + ("" + ((music[currentSong+1]->first())))->toInteger() * ("" + ((music[currentSong+1][1+1])))->toInteger() ; currentSong := currentSong + 1) ; execute (currentSong)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect n,m=map(int,input().split()) cfs=[0 for i in range(n)] for i,val in enumerate(range(n)): c,t=map(int,input().split()) dur=c*t if i==0 : cfs[0]=dur continue cfs[i]=cfs[i-1]+dur stamps=map(int,input().split()) for s in stamps : print(bisect.bisect_left(cfs,s)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cfs : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for _tuple : Integer.subrange(1, (Integer.subrange(0, n-1))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(0, n-1))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var val : OclAny := _tuple->at(_indx); var c : OclAny := null; var t : OclAny := null; Sequence{c,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dur : double := c * t ; if i = 0 then ( cfs->first() := dur ; continue ) else skip ; cfs[i+1] := cfs[i - 1+1] + dur) ; var stamps : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for s : stamps do ( execute (bisect.bisect_left(cfs, s) + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,M=map(int,input().split()) a=[0 for i in range(n)] for i in range(n): c,t=map(int,input().split()) if i==0 : a[i]=c*t else : a[i]=a[i-1]+c*t v=list(map(int,input().split())) for i in range(M): l=-1 r=n-1 while r-l>1 : m=(l+r)//2 if a[m]>=v[i]: r=m else : l=m print(r+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var M : OclAny := null; Sequence{n,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( var c : OclAny := null; var t : OclAny := null; Sequence{c,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if i = 0 then ( a[i+1] := c * t ) else ( a[i+1] := a[i - 1+1] + c * t )) ; var v : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, M-1) do ( var l : int := -1 ; var r : double := n - 1 ; while r - l > 1 do ( var m : int := (l + r) div 2 ; if (a[m+1]->compareTo(v[i+1])) >= 0 then ( r := m ) else ( l := m )) ; execute (r + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def read_int(): return int(input()) def read_ints(): return[int(x)for x in input().split()] n,m=read_ints() a=[] last=0 for _ in range(n): c,t=read_ints() last+=c*t a.append(last) i=0 for v in read_ints(): while a[i]compareTo(v)) < 0 do ( i := i + 1) ; execute (i + 1)->display()); operation read_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation read_ints() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline import bisect n,m=map(int,input().split()) d=[] x=0 for _ in range(n): c,t=map(int,input().split()) x+=c*t d.append(x) for i in map(int,input().split()): x=bisect.bisect_left(d,i)+1 print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := Sequence{} ; var x : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var c : OclAny := null; var t : OclAny := null; Sequence{c,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; x := x + c * t ; execute ((x) : d)) ; for i : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( x := bisect.bisect_left(d, i) + 1 ; execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fibonacci(n): FibArray=[0,1] while len(FibArray)display(); operation fibonacci(n : OclAny) : OclAny pre: true post: true activity: var FibArray : Sequence := Sequence{0}->union(Sequence{ 1 }) ; while ((FibArray)->size()->compareTo(n + 1)) < 0 do ( execute ((0) : FibArray)) ; if n <= 1 then ( return n ) else ( if FibArray[n - 1+1] = 0 then ( FibArray[n - 1+1] := fibonacci(n - 1) ) else skip ; if FibArray[n - 2+1] = 0 then ( FibArray[n - 2+1] := fibonacci(n - 2) ) else skip ) ; FibArray[n+1] := FibArray[n - 2+1] + FibArray[n - 1+1] ; return FibArray[n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000 f=[0]*MAX def fib(n): if(n==0): return 0 if(n==1 or n==2): f[n]=1 return(f[n]) if(f[n]): return f[n] if(n & 1): k=(n+1)//2 else : k=n//2 if((n & 1)): f[n]=(fib(k)*fib(k)+fib(k-1)*fib(k-1)) else : f[n]=(2*fib(k-1)+fib(k))*fib(k) return f[n] n=9 print(fib(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1000 ; var f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX) ; skip ; n := 9 ; execute (fib(n))->display(); operation fib(n : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return 0 ) else skip ; if (n = 1 or n = 2) then ( f[n+1] := 1 ; return (f[n+1]) ) else skip ; if (f[n+1]) then ( return f[n+1] ) else skip ; if (MathLib.bitwiseAnd(n, 1)) then ( var k : int := (n + 1) div 2 ) else ( k := n div 2 ) ; if ((MathLib.bitwiseAnd(n, 1))) then ( f[n+1] := (fib(k) * fib(k) + fib(k - 1) * fib(k - 1)) ) else ( f[n+1] := (2 * fib(k - 1) + fib(k)) * fib(k) ) ; return f[n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(n): n=str(n) if n==n[: :-1]: return True else : return False n=int(input()) if check(n): print(n) else : base=n while 1 : n-=1 if check(n): ans=n break diff=base-n n=base for i in range(base,base+diff): if check(i): print(i) break else : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if check(n) then ( execute (n)->display() ) else ( var base : OclAny := n ; while 1 do ( n := n - 1 ; if check(n) then ( var ans : OclAny := n ; break ) else skip) ; var diff : double := base - n ; n := base ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name base))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name base))) + (expr (atom (name diff))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name check)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))))))))) ); operation check(n : OclAny) : OclAny pre: true post: true activity: n := ("" + ((n))) ; if n = n(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l1=[i for i in range(10)] l2=[int(str(c)+str(c))for c in range(1,10)] l3=[int(str(c1)+str(c2)+str(c1))for c1 in range(1,10)for c2 in range(10)] l4=[int(str(c1)+str(c2)+str(c2)+str(c1))for c1 in range(1,10)for c2 in range(10)] l5=[10001] lst=l1+l2+l3+l4+l5 n=int(input()) dist=10**6 ans=-1 for num in lst : if abs(num-n)select(i | true)->collect(i | (i)) ; var l2 : Sequence := Integer.subrange(1, 10-1)->select(c | true)->collect(c | (("" + ((("" + ((c))) + ("" + ((c))))))->toInteger())) ; var l3 : Sequence := Integer.subrange(1, 10-1)->select(c1; c2 : Integer.subrange(0, 10-1) | true)->collect(c1; c2 : Integer.subrange(0, 10-1) | (("" + ((("" + ((c1))) + ("" + ((c2))) + ("" + ((c1))))))->toInteger())) ; var l4 : Sequence := Integer.subrange(1, 10-1)->select(c1; c2 : Integer.subrange(0, 10-1) | true)->collect(c1; c2 : Integer.subrange(0, 10-1) | (("" + ((("" + ((c1))) + ("" + ((c2))) + ("" + ((c2))) + ("" + ((c1))))))->toInteger())) ; var l5 : Sequence := Sequence{ 10001 } ; var lst : Sequence := l1->union(l2)->union(l3)->union(l4)->union(l5) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var dist : double := (10)->pow(6) ; var ans : int := -1 ; for num : lst do ( if ((num - n)->abs()->compareTo(dist)) < 0 then ( dist := (num - n)->abs() ; ans := num ) else (if (num - n)->abs() = dist & (num->compareTo(ans)) < 0 then ( ans := num ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=input().split() arr=[] for i in range(int(n)): lis=input() tmp=[] for j in lis : tmp.append(j) arr.append(tmp) col=[] row=[] for row_index,row_value in enumerate(arr): for col_index,col_value in enumerate(row_value): if col_value=='B' : col.append(col_index+1) row.append(row_index+1) print(f'{sum(row)//len(row)}{sum(col)//len(col)}') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split() ; var arr : Sequence := Sequence{} ; for i : Integer.subrange(0, ("" + ((n)))->toInteger()-1) do ( var lis : String := (OclFile["System.in"]).readLine() ; var tmp : Sequence := Sequence{} ; for j : lis->characters() do ( execute ((j) : tmp)) ; execute ((tmp) : arr)) ; var col : Sequence := Sequence{} ; var row : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (arr)->size())->collect( _indx | Sequence{_indx-1, (arr)->at(_indx)} ) do (var _indx : int := 1; var row_index : OclAny := _tuple->at(_indx); _indx := _indx + 1; var row_value : OclAny := _tuple->at(_indx); for _tuple : Integer.subrange(1, (row_value)->size())->collect( _indx | Sequence{_indx-1, (row_value)->at(_indx)} ) do (var _indx : int := 1; var col_index : OclAny := _tuple->at(_indx); _indx := _indx + 1; var col_value : OclAny := _tuple->at(_indx); if col_value = 'B' then ( execute ((col_index + 1) : col) ; execute ((row_index + 1) : row) ) else skip)) ; execute (StringLib.formattedString('{sum(row)//len(row)}{sum(col)//len(col)}'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(n): n=str(n) if n==n[: :-1]: return 1 a=b=int(input()) while 1 : if f(b): print(b); break a-=1 if f(a): print(a); break b+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while 1 do ( if f(b) then ( execute (b)->display(); break ) else skip ; a := a - 1 ; if f(a) then ( execute (a)->display(); break ) else skip ; b := b + 1); operation f(n : OclAny) : OclAny pre: true post: true activity: n := ("" + ((n))) ; if n = n(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( return 1 ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input().split() N=int(s[0]) A=int(s[1]) B=int(s[2]) print(min(N*A,B)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := input().split() ; var N : int := ("" + ((s->first())))->toInteger() ; var A : int := ("" + ((s[1+1])))->toInteger() ; var B : int := ("" + ((s[2+1])))->toInteger() ; execute (Set{N * A, B}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=list(range(10)) for i in range(1,100): t=str(i) s.append(t+t[: :-1]) for j in range(10): s.append(t+str(j)+t[: :-1]) s=list(map(int,s)) s.sort() if n in s : print(n) else : if ns[-1]: print(s[-1]) else : res=0 diff=1e9 for d in s : if diff>abs(d-n): diff=abs(d-n) res=d print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := (Integer.subrange(0, 10-1)) ; for i : Integer.subrange(1, 100-1) do ( var t : String := ("" + ((i))) ; execute ((t + t(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) : s) ; for j : Integer.subrange(0, 10-1) do ( execute ((t + ("" + ((j))) + t(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) : s))) ; s := ((s)->collect( _x | (OclType["int"])->apply(_x) )) ; s := s->sort() ; if (s)->includes(n) then ( execute (n)->display() ) else ( if (n->compareTo(s->first())) < 0 then ( execute (s->first())->display() ) else (if (n->compareTo(s->last())) > 0 then ( execute (s->last())->display() ) else ( var res : int := 0 ; var diff : double := ("1e9")->toReal() ; for d : s do ( if (diff->compareTo((d - n)->abs())) > 0 then ( diff := (d - n)->abs() ; res := d ) else skip) ; execute (res)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect rev=[] for i in range(1,10002): if str(i)==str(i)[: :-1]: rev.append(i) n=int(input()) ind=bisect.bisect_left(rev,n) if abs(n-rev[ind-1])<=abs(n-rev[ind]): print(rev[ind-1]) else : print(rev[ind]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var rev : Sequence := Sequence{} ; for i : Integer.subrange(1, 10002-1) do ( if ("" + ((i))) = OclType["String"](i)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( execute ((i) : rev) ) else skip) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ind : OclAny := bisect.bisect_left(rev, n) ; if ((n - rev[ind - 1+1])->abs()->compareTo((n - rev[ind+1])->abs())) <= 0 then ( execute (rev[ind - 1+1])->display() ) else ( execute (rev[ind+1])->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def removeDulipcates(arr): s=dict() d=[] for i in arr : if i not in s.keys(): d.append(i) s[i]=1 print(d) arr=[1,2,5,1,7,2,4,2] removeDulipcates(arr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{5}->union(Sequence{1}->union(Sequence{7}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 2 }))))))) ; removeDulipcates(arr); operation removeDulipcates(arr : OclAny) pre: true post: true activity: var s : Map := (arguments ( )) ; var d : Sequence := Sequence{} ; for i : arr do ( if (s.keys())->excludes(i) then ( execute ((i) : d) ; s[i+1] := 1 ) else skip) ; execute (d)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,data): self.data=data self.left=None self.right=None def getNode(data): newNode=Node(0) newNode.data=data newNode.left=newNode.right=None return newNode mp=dict() def storePath(root,XOR): global mp if(root==None): return mp[root.data]=XOR ^ root.data ; XOR=XOR ^ root.data if(root.left!=None): storePath(root.left,XOR) if(root.right!=None): storePath(root.right,XOR) def findXORPath(node1,node2): global mp return mp.get(node1,0)^ mp.get(node2,0) root=getNode(0) root.left=getNode(1) root.left.left=getNode(3) root.left.left.left=getNode(7) root.left.right=getNode(4) root.left.right.left=getNode(8) root.left.right.right=getNode(9) root.right=getNode(2) root.right.left=getNode(5) root.right.right=getNode(6) XOR=0 node1=3 node2=5 storePath(root,XOR) print(findXORPath(node1,node2)) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.left := null ; self.right := null; return self; } class FromPython { attribute mp : OclAny; attribute mp : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; var mp : Map := (arguments ( )) ; skip ; skip ; root := getNode(0) ; root.left := getNode(1) ; root.left.left := getNode(3) ; root.left.left.left := getNode(7) ; root.left.right := getNode(4) ; root.left.right.left := getNode(8) ; root.left.right.right := getNode(9) ; root.right := getNode(2) ; root.right.left := getNode(5) ; root.right.right := getNode(6) ; XOR := 0 ; node1 := 3 ; node2 := 5 ; storePath(root, XOR) ; execute (findXORPath(node1, node2))->display(); operation getNode(data : OclAny) : OclAny pre: true post: true activity: var newNode : Node := (Node.newNode()).initialise(0) ; newNode.data := data ; newNode.left := null; var newNode.right : OclAny := null ; return newNode; operation storePath(root : OclAny, XOR : OclAny) pre: true post: true activity: skip ; if (root = null) then ( return ) else skip ; mp[root.data+1] := MathLib.bitwiseXor(XOR, root.data); ; XOR := MathLib.bitwiseXor(XOR, root.data) ; if (root.left /= null) then ( storePath(root.left, XOR) ) else skip ; if (root.right /= null) then ( storePath(root.right, XOR) ) else skip; operation findXORPath(node1 : OclAny, node2 : OclAny) : OclAny pre: true post: true activity: skip ; return MathLib.bitwiseXor(mp.get(node1, 0), mp.get(node2, 0)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,floor def minOperations(n,m): a=0 ; k=1 ; p=max(n,m); while(n!=m): s=float(p-n+p-m); q=(-1+sqrt(8*s+1))/2 ; if(q-floor(q)==0): a=q ; n=m ; p=p+1 ; return a ; if __name__=="__main__" : n=1 ; m=3 ; print(minOperations(n,m)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 1; m := 3; ; execute (minOperations(n, m))->display(); ) else skip; operation minOperations(n : OclAny, m : OclAny) pre: true post: true activity: var a : int := 0; var k : int := 1; ; var p : OclAny := Set{n, m}->max(); ; while (n /= m) do ( var s : double := ("" + ((p - n + p - m)))->toReal(); ; var q : double := (-1 + sqrt(8 * s + 1)) / 2; ; if (q - floor(q) = 0) then ( a := q; ; n := m; ) else skip ; p := p + 1;) ; return a;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isVowel(x): return(x=='a' or x=='e' or x=='i' or x=='o' or x=='u') def longestVowelSubsequence(str): answer="" n=len(str) for i in range(n): if(isVowel(str[i])): answer+=str[i] return answer str="geeksforgeeks" print(longestVowelSubsequence(str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; OclType["String"] := "geeksforgeeks" ; execute (longestVowelSubsequence(OclType["String"]))->display(); operation isVowel(x : OclAny) : OclAny pre: true post: true activity: return (x = 'a' or x = 'e' or x = 'i' or x = 'o' or x = 'u'); operation longestVowelSubsequence(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var answer : String := "" ; var n : int := (OclType["String"])->size() ; for i : Integer.subrange(0, n-1) do ( if (isVowel(("" + ([i+1])))) then ( answer := answer + ("" + ([i+1])) ) else skip) ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys x=y=0 for i in sys.stdin : x+=i[0]=='+' x-=i[0]=='-' y+=(':' in i)*(len(i)-i.find(':')-2)*x print(y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : OclAny := 0; var y : int := 0 ; for i : OclFile["System.in"] do ( x := x + i->first() = '+' ; x := x - i->first() = '-' ; y := y + ((i)->includes(':')) * ((i)->size() - i->indexOf(':') - 1 - 2) * x) ; execute (y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin count=0 ans=0 for line in stdin : line=line.strip() if line[0]=='+' : count+=1 elif line[0]=='-' : count-=1 else : msg_len=len(line.split(':')[1]) ans+=msg_len*count print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var count : int := 0 ; var ans : int := 0 ; for line : stdin do ( var line : String := line->trim() ; if line->first() = '+' then ( count := count + 1 ) else (if line->first() = '-' then ( count := count - 1 ) else ( var msg_len : int := (line.split(':')[1+1])->size() ; ans := ans + msg_len * count ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,a,b,c,t=map(int,input().split()) x=list(map(int,input().split())) s=0 for i in x : s+=(t-i)*(c-b)+a ans=max(s,n*a) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var t : OclAny := null; Sequence{n,a,b,c,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : int := 0 ; for i : x do ( s := s + (t - i) * (c - b) + a) ; var ans : OclAny := Set{s, n * a}->max() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin chat_size=0 traffic=0 for command in stdin : if command[0]=='+' : chat_size+=1 elif command[0]=='-' : chat_size-=1 else : name,message=command.strip().split(':') traffic+=chat_size*len(message) print(traffic) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var chat_size : int := 0 ; var traffic : int := 0 ; for command : stdin do ( if command->first() = '+' then ( chat_size := chat_size + 1 ) else (if command->first() = '-' then ( chat_size := chat_size - 1 ) else ( var name : OclAny := null; var message : OclAny := null; Sequence{name,message} := command->trim().split(':') ; traffic := traffic + chat_size * (message)->size() ) ) ) ; execute (traffic)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mem=0 byts=0 while True : try : s=input() if(s[0]=='+'): mem+=1 elif(s[0]=='-'): mem-=1 else : i=s.index(':') s=s[i+1 :] l=len(s) byts+=(l*mem) except : break print(byts) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mem : int := 0 ; var byts : int := 0 ; while true do ( try ( var s : String := (OclFile["System.in"]).readLine() ; if (s->first() = '+') then ( mem := mem + 1 ) else (if (s->first() = '-') then ( mem := mem - 1 ) else ( var i : int := s->indexOf(':') - 1 ; s := s.subrange(i + 1+1) ; var l : int := (s)->size() ; byts := byts + (l * mem) ) ) ) catch (_e : OclException) do ( break) ) ; execute (byts)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=list(map(int,input().split())) print(a[2]if a[0]*a[1]>a[2]else a[0]*a[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (if (a->first() * a[1+1]->compareTo(a[2+1])) > 0 then a[2+1] else a->first() * a[1+1] endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- try : p=0 ans=0 while True : i=input() if i[0]=="+" : p+=1 elif i[0]=="-" : p-=1 else : ans+=(len(i)-1-i.index(":"))*p except : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: try ( var p : int := 0 ; var ans : int := 0 ; while true do ( var i : String := (OclFile["System.in"]).readLine() ; if i->first() = "+" then ( p := p + 1 ) else (if i->first() = "-" then ( p := p - 1 ) else ( ans := ans + ((i)->size() - 1 - i->indexOf(":") - 1) * p ) ) )) catch (_e : OclException) do ( execute (ans)->display()) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d,m,l=map(int,input().split()) x=0 for i in range(n): if((i*m+l)//d+1)*d>=(i+1)*m : 0 else : x=((i*m+l)//d+1)*d break if x==0 : x=(((n-1)*m+l)//d+1)*d print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; var m : OclAny := null; var l : OclAny := null; Sequence{n,d,m,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (((i * m + l) div d + 1) * d->compareTo((i + 1) * m)) >= 0 then ( ) else ( x := ((i * m + l) div d + 1) * d ; break )) ; if x = 0 then ( x := (((n - 1) * m + l) div d + 1) * d ) else skip ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=map(int,input().split()) for i in range(a): x,y=i*c+d,(i+1)*c-1 if x//b!=y//b : break print((x//b+1)*b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, a-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{i * c + d,(i + 1) * c - 1} ; if x div b /= y div b then ( break ) else skip) ; execute ((x div b + 1) * b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,d,m,l=map(int,input().split()) r=(n-1)*m+l ans=((r+1)//d+min(1,(r+1)% d))*d if(l+1)^ m : for i in range(n-1): l0,r0=i*m+l+1,(i+1)*m-1 if not l0 % d or(l0//d)^(r0//d): for j in range(l0,r0+1): if not j % d : ans=j break break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var d : OclAny := null; var m : OclAny := null; var l : OclAny := null; Sequence{n,d,m,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var r : double := (n - 1) * m + l ; var ans : double := ((r + 1) div d + Set{1, (r + 1) mod d}->min()) * d ; if MathLib.bitwiseXor((l + 1), m) then ( for i : Integer.subrange(0, n - 1-1) do ( var l0 : OclAny := null; var r0 : OclAny := null; Sequence{l0,r0} := Sequence{i * m + l + 1,(i + 1) * m - 1} ; if not(l0 mod d) or MathLib.bitwiseXor((l0 div d), (r0 div d)) then ( for j : Integer.subrange(l0, r0 + 1-1) do ( if not(j mod d) then ( ans := j ; break ) else skip) ; break ) else skip) ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d,m,l=map(int,input().split()) i=1 x=0 if d==m and m==l+1 : print(n*d) else : if d==1 : for i in range(1,n+1): left=(i-1)*m right=(i-1)*m+l x=right+1 if x>right and xright and xcollect( _x | (OclType["int"])->apply(_x) ) ; var i : int := 1 ; var x : int := 0 ; if d = m & m = l + 1 then ( execute (n * d)->display() ) else ( if d = 1 then ( for i : Integer.subrange(1, n + 1-1) do ( var left : double := (i - 1) * m ; var right : double := (i - 1) * m + l ; x := right + 1 ; if (x->compareTo(right)) > 0 & (x->compareTo(i * m)) < 0 then ( execute (x)->display() ; break ) else (if i = n then ( execute (x)->display() ; break ) else skip)) ) else ( for i : Integer.subrange(1, n + 1-1) do ( left := (i - 1) * m ; right := (i - 1) * m + l ; x := d * (right div d + 1) ; if (x->compareTo(right)) > 0 & (x->compareTo(i * m)) < 0 then ( execute (x)->display() ; break ) else (if i = n then ( execute (x)->display() ; break ) else skip)) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d,m,l=map(int,input().split()) i=1 x=0 for i in range(1,n+1): left=(i-1)*m right=(i-1)*m+l x=d*(right//d+1) if xcollect( _x | (OclType["int"])->apply(_x) ) ; var i : int := 1 ; var x : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( var left : double := (i - 1) * m ; var right : double := (i - 1) * m + l ; x := d * (right div d + 1) ; if (x->compareTo(i * m)) < 0 then ( break ) else skip) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=[int(x)for x in input().split()] s=input() t=input() ans=0 cur=0 for i in range(n): if t[i]=='a' and s[i]=='a' : cur*=2 if t[i]=='b' and s[i]=='b' : cur*=2 if t[i]=='b' and s[i]=='a' : cur=cur*2+1 if t[i]=='a' and s[i]=='b' : cur=cur*2-1 if cur+1>k : ans+=(n-i)*k break ans+=cur+1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; var cur : int := 0 ; for i : Integer.subrange(0, n-1) do ( if t[i+1] = 'a' & s[i+1] = 'a' then ( cur := cur * 2 ) else skip ; if t[i+1] = 'b' & s[i+1] = 'b' then ( cur := cur * 2 ) else skip ; if t[i+1] = 'b' & s[i+1] = 'a' then ( cur := cur * 2 + 1 ) else skip ; if t[i+1] = 'a' & s[i+1] = 'b' then ( cur := cur * 2 - 1 ) else skip ; if (cur + 1->compareTo(k)) > 0 then ( ans := ans + (n - i) * k ; break ) else skip ; ans := ans + cur + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(n,m): if(n==2 or m==2 or n % m==0): print("Yes") else : print("No") m=3 n=9 check(n,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; m := 3 ; n := 9 ; check(n, m); operation check(n : OclAny, m : OclAny) pre: true post: true activity: if (n = 2 or m = 2 or n mod m = 0) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : n,A,B,C,T=map(int,input().split()) l=list(map(int,input().split())) s=T*n-sum(l) ans=A*n if(C>B): ans+=(C-B)*s print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var n : OclAny := null; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var T : OclAny := null; Sequence{n,A,B,C,T} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : double := T * n - (l)->sum() ; var ans : double := A * n ; if ((C->compareTo(B)) > 0) then ( ans := ans + (C - B) * s ) else skip ; execute (ans)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) s=input().strip() t=input().strip() dif,an=0,0 for i in range(n): if difcollect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := input()->trim() ; var t : OclAny := input()->trim() ; var dif : OclAny := null; var an : OclAny := null; Sequence{dif,an} := Sequence{0,0} ; for i : Integer.subrange(0, n-1) do ( if (dif->compareTo(k - 1)) < 0 then ( dif := dif * 2 ; if s[i+1] = 'b' then ( dif := dif - 1 ) else skip ; if t[i+1] = 'b' then ( dif := dif + 1 ) else skip ) else skip ; an := an + Set{k, dif + 1}->min()) ; execute (an)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d={'a' : 0,'b' : 1} def process(s,t,k): n=len(s) answer=0 D=0 final_i=n for i in range(n): d1=d[s[i]] d2=d[t[i]] D=2*(D)+d2-d1 if D+1 0 }->union(Map{ 'b' |-> 1 }) ; skip ; Sequence{n,k} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; s := (OclFile["System.in"]).readLine() ; t := (OclFile["System.in"]).readLine() ; execute (process(s, t, k))->display(); operation process(s : OclAny, t : OclAny, k : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; var answer : int := 0 ; var D : int := 0 ; var final_i : int := n ; for i : Integer.subrange(0, n-1) do ( var d1 : OclAny := d[s[i+1]+1] ; var d2 : OclAny := d[t[i+1]+1] ; D := 2 * (D) + d2 - d1 ; if (D + 1->compareTo(k)) < 0 then ( answer := answer + (D + 1) ) else ( final_i := i ; break )) ; answer := answer + k * (n - final_i) ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect two_ruijo_list=[2**i for i in range(18)] N,K=map(int,input().split()) if K<=N : mi=K ans=(N-K+1)/N else : mi=N+1 ans=0 for i in range(1,mi): d=bisect.bisect_left([two_ruijo_list[j]*i for j in range(18)],K) ans+=0.5**d/N print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var two_ruijo_list : Sequence := Integer.subrange(0, 18-1)->select(i | true)->collect(i | ((2)->pow(i))) ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (K->compareTo(N)) <= 0 then ( var mi : OclAny := K ; var ans : double := (N - K + 1) / N ) else ( mi := N + 1 ; ans := 0 ) ; for i : Integer.subrange(1, mi-1) do ( var d : OclAny := bisect.bisect_left(Integer.subrange(0, 18-1)->select(j | true)->collect(j | (two_ruijo_list[j+1] * i)), K) ; ans := ans + (0.5)->pow(d) / N) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sum_of_series(n): result=0 for i in range(1,n+1): if(i % 2==0): result=result-pow(i,2) else : result=result+pow(i,2) return result if __name__=="__main__" : n=3 print(sum_of_series(n)) n=10 print(sum_of_series(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 3 ; execute (sum_of_series(n))->display() ; n := 10 ; execute (sum_of_series(n))->display() ) else skip; operation sum_of_series(n : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( if (i mod 2 = 0) then ( result := result - (i)->pow(2) ) else ( result := result + (i)->pow(2) )) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque,Counter from heapq import heappush,heappop,heapify from itertools import permutations,accumulate,combinations,combinations_with_replacement from math import sqrt,ceil,floor,factorial,log from bisect import bisect_left,bisect_right,insort_left,insort_right from copy import deepcopy from operator import itemgetter from functools import reduce from fractions import gcd import sys def I(): return int(input()) def Is(): return map(int,input().split()) def LI(): return list(map(int,input().split())) def TI(): return tuple(map(int,input().split())) def IR(n): return[I()for _ in range(n)] def LIR(n): return[LI()for _ in range(n)] def TIR(n): return[TI()for _ in range(n)] def S(): return input() def Ss(): return input().split() def LS(): return list(input()) def SR(n): return[S()for _ in range(n)] def SsR(n): return[Ss()for _ in range(n)] def LSR(n): return[LS()for _ in range(n)] sys.setrecursionlimit(10**6) MOD=10**9+7 INF=float('inf') N,K=Is() log2k=log(K,2) ans=0 for i in range(1,N+1): j=max(0,ceil(log2k-log(i,2))) tmp=N*2**j ans+=1/tmp print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(6)) ; var MOD : double := (10)->pow(9) + 7 ; var INF : double := ("" + (('inf')))->toReal() ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := Is() ; var log2k : OclAny := log(K, 2) ; var ans : int := 0 ; for i : Integer.subrange(1, N + 1-1) do ( var j : OclAny := Set{0, ceil(log2k - log(i, 2))}->max() ; var tmp : double := N * (2)->pow(j) ; ans := ans + 1 / tmp) ; execute (ans)->display(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation Is() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation TI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI())); operation TIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (TI())); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation Ss() : OclAny pre: true post: true activity: return input().split(); operation LS() : OclAny pre: true post: true activity: return ((OclFile["System.in"]).readLine())->characters(); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (S())); operation SsR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Ss())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LS())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input1=input().split() n=input1[0] k=input1[1] n=int(n) k=int(k) me=1 ten=0 count=0 total=0 while me<=n : ten=me while tenfirst() ; var k : OclAny := input1[1+1] ; n := ("" + ((n)))->toInteger() ; k := ("" + ((k)))->toInteger() ; var me : int := 1 ; var ten : int := 0 ; var count : int := 0 ; var total : int := 0 ; while (me->compareTo(n)) <= 0 do ( ten := me ; while (ten->compareTo(k)) < 0 do ( count := count + 1 ; ten := ten * 2) ; total := total + 1 / n * ((1 / 2))->pow(count) ; count := 0 ; me := me + 1) ; execute (total)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math input=sys.stdin.readline N,K=map(int,input().split()) max_pow=math.ceil(math.log2(K)+0.9) one_half=[0]*(max_pow+1) one_half[0]=1 for i in range(1,max_pow+1): one_half[i]=one_half[i-1]*0.5 ans=0 for i in range(1,N+1): pow_num=math.ceil(math.log2(K/i)) if pow_num<=0 : ans+=1 else : ans+=one_half[pow_num] print(ans/N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var max_pow : double := ( + 0.9)->ceil() ; var one_half : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (max_pow + 1)) ; one_half->first() := 1 ; for i : Integer.subrange(1, max_pow + 1-1) do ( one_half[i+1] := one_half[i - 1+1] * 0.5) ; var ans : int := 0 ; for i : Integer.subrange(1, N + 1-1) do ( var pow_num : double := ()->ceil() ; if pow_num <= 0 then ( ans := ans + 1 ) else ( ans := ans + one_half[pow_num+1] )) ; execute (ans / N)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def main(): n,k=[int(x)for x in input().split()] p=0 for i in range(n): dice=i+1 if dice>=k : p+=1 else : p+=0.5**(math.ceil(math.log2(k/dice))) p/=n print(p) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var p : int := 0 ; for i : Integer.subrange(0, n-1) do ( var dice : OclAny := i + 1 ; if (dice->compareTo(k)) >= 0 then ( p := p + 1 ) else ( p := p + (0.5)->pow((()->ceil())) )) ; p := p / n ; execute (p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def substringConversions(str1,k,b): for i in range(0,len(str1)-k+1): sub=str1[i : k+i] Sum=0 counter=0 for i in range(len(sub)-1,-1,-1): Sum=(Sum+((ord(sub[i])-ord('0'))*pow(b,counter))) counter+=1 print(Sum,end=" ") str1="12212" b=3 k=3 substringConversions(str1,b,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; str1 := "12212" ; b := 3 ; k := 3 ; substringConversions(str1, b, k); operation substringConversions(str1 : OclAny, k : OclAny, b : OclAny) pre: true post: true activity: for i : Integer.subrange(0, (str1)->size() - k + 1-1) do ( var sub : OclAny := str1.subrange(i+1, k + i) ; var Sum : int := 0 ; var counter : int := 0 ; for i : Integer.subrange(-1 + 1, (sub)->size() - 1)->reverse() do ( Sum := (Sum + (((sub[i+1])->char2byte() - ('0')->char2byte()) * (b)->pow(counter))) ; counter := counter + 1) ; execute (Sum)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def emi_calculator(p,r,t): r=r/(12*100) t=t*12 emi=(p*r*pow(1+r,t))/(pow(1+r,t)-1) return emi principal=10000 ; rate=10 ; time=2 ; emi=emi_calculator(principal,rate,time); print("Monthly EMI is=",emi) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var principal : int := 10000; ; var rate : int := 10; ; var time : int := 2; ; emi := emi_calculator(principal, rate, time); ; execute ("Monthly EMI is=")->display(); operation emi_calculator(p : OclAny, r : OclAny, t : OclAny) : OclAny pre: true post: true activity: r := r / (12 * 100) ; t := t * 12 ; var emi : double := (p * r * (1 + r)->pow(t)) / ((1 + r)->pow(t) - 1) ; return emi; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b,c,t=map(int,input().split()) l=sorted(list(map(int,input().split()))) if b>=c : print(a*n) else : print(sum((t-x)*c+(a-b*(t-x))for x in l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var t : OclAny := null; Sequence{n,a,b,c,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; if (b->compareTo(c)) >= 0 then ( execute (a * n)->display() ) else ( execute (((argument (test (logical_test (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name t))) - (expr (atom (name x)))))))) ))) * (expr (atom (name c)))) + (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (expr (atom (name b))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name t))) - (expr (atom (name x)))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name l))))))))->sum())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count_numbers(k,n,flag): if(n==1): if(flag): return(k-1) else : return 1 if(flag): return(k-1)*(count_numbers(k,n-1,0)+count_numbers(k,n-1,1)) else : return count_numbers(k,n-1,1) n=3 k=10 print(count_numbers(k,n,True)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3 ; k := 10 ; execute (count_numbers(k, n, true))->display(); operation count_numbers(k : OclAny, n : OclAny, flag : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( if (flag) then ( return (k - 1) ) else ( return 1 ) ) else skip ; if (flag) then ( return (k - 1) * (count_numbers(k, n - 1, 0) + count_numbers(k, n - 1, 1)) ) else ( return count_numbers(k, n - 1, 1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- L,R=map(int,input().split()) mod=10**9+7 def f(L,R): if L>R : return 0 R=bin(R)[2 :] N=len(R) ret=f(L,int("0"+"1"*(N-1),2)) L=bin(L)[2 :] if len(L)!=N : L="1"+"0"*(N-1) for i in range(N): if R[i]=="0" : continue R2=R[: i]+"0"+"?"*(N-i-1) if i==0 : R2=R for j in range(N): if L[j]=="1" and j!=0 : continue L2=L[: j]+"1"+"?"*(N-j-1) if j==0 : L2=L if L2[0]=="0" : break tmp=1 for r,l in zip(R2[1 :],L2[1 :]): if r=="0" and l=="1" : tmp*=0 ; break if r=="?" and l=="?" : tmp=tmp*3 % mod if r=="?" and l=="0" : tmp=tmp*2 % mod if r=="1" and l=="?" : tmp=tmp*2 % mod ret+=tmp ret %=mod return ret print(f(L,R)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var L : OclAny := null; var R : OclAny := null; Sequence{L,R} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mod : double := (10)->pow(9) + 7 ; skip ; execute (f(L, R))->display(); operation f(L : OclAny, R : OclAny) : OclAny pre: true post: true activity: if (L->compareTo(R)) > 0 then ( return 0 ) else skip ; R := bin(R).subrange(2+1) ; var N : int := (R)->size() ; var ret : String := f(L, ("" + (("0" + StringLib.nCopies("1", (N - 1)), 2)))->toInteger()) ; L := bin(L).subrange(2+1) ; if (L)->size() /= N then ( L := "1" + StringLib.nCopies("0", (N - 1)) ) else skip ; for i : Integer.subrange(0, N-1) do ( if R[i+1] = "0" then ( continue ) else skip ; var R2 : String := R.subrange(1,i) + "0" + StringLib.nCopies("?", (N - i - 1)) ; if i = 0 then ( R2 := R ) else skip ; for j : Integer.subrange(0, N-1) do ( if L[j+1] = "1" & j /= 0 then ( continue ) else skip ; var L2 : OclAny := L.subrange(1,j) + "1" + StringLib.nCopies("?", (N - j - 1)) ; if j = 0 then ( L2 := L ) else skip ; if L2->first() = "0" then ( break ) else skip ; var tmp : int := 1 ; for _tuple : Integer.subrange(1, R2->tail()->size())->collect( _indx | Sequence{R2->tail()->at(_indx), L2->tail()->at(_indx)} ) do (var _indx : int := 1; var r : OclAny := _tuple->at(_indx); _indx := _indx + 1; var l : OclAny := _tuple->at(_indx); if r = "0" & l = "1" then ( tmp := tmp * 0; break ) else skip ; if r = "?" & l = "?" then ( tmp := tmp * 3 mod mod ) else skip ; if r = "?" & l = "0" then ( tmp := tmp * 2 mod mod ) else skip ; if r = "1" & l = "?" then ( tmp := tmp * 2 mod mod ) else skip) ; ret := ret + tmp ; ret := ret mod mod)) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) readline=sys.stdin.readline l,r=[int(i)for i in readline().split()] def make_dp(init,size): res="[{}]*{}".format(init,size[-1]) for i in reversed(size[:-1]): res="[{}for _ in[0]*{}]".format(res,i) return eval(res) MOD=10**9+7 R=bin(r)[2 :] L=bin(l)[2 :] L="0"*(len(R)-len(L))+L dp=make_dp(0,(len(R)+1,2,2,2)) dp[0][0][0][0]=1 for i,(r,l)in enumerate(zip(R,L)): ri=int(r) li=int(l) for is_less in range(2): for is_more in range(2): for is_nonzero in range(2): for dl in range(0 if is_more else li,2): for dr in range(dl,2 if is_less else ri+1): dp[i+1][is_nonzero or dr!=0][is_more or lipow(6)) ; var readline : OclAny := (OclFile["System.in"]).readline ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := readline().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; skip ; var MOD : double := (10)->pow(9) + 7 ; var R : OclAny := bin(r).subrange(2+1) ; var L : OclAny := bin(l).subrange(2+1) ; L := StringLib.nCopies("0", ((R)->size() - (L)->size())) + L ; var dp : OclAny := make_dp(0, Sequence{(R)->size() + 1, 2, 2, 2}) ; dp->first()->first()->first()->first() := 1 ; for _tuple : Integer.subrange(1, (Integer.subrange(1, R->size())->collect( _indx | Sequence{R->at(_indx), L->at(_indx)} ))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(1, R->size())->collect( _indx | Sequence{R->at(_indx), L->at(_indx)} ))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{r, l} : OclAny := _tuple->at(_indx); var ri : int := ("" + ((r)))->toInteger() ; var li : int := ("" + ((l)))->toInteger() ; for is_less : Integer.subrange(0, 2-1) do ( for is_more : Integer.subrange(0, 2-1) do ( for is_nonzero : Integer.subrange(0, 2-1) do ( for dl : Integer.subrange(if is_more then 0 else li endif, 2-1) do ( for dr : Integer.subrange(dl, if is_less then 2 else ri + 1 endif-1) do ( dp[i + 1+1]->select(is_nonzero or dr /= 0)->select(is_more or (li->compareTo(dl)) < 0)->select(is_less or (dr->compareTo(ri)) < 0) := dp[i + 1+1]->select(is_nonzero or dr /= 0)->select(is_more or (li->compareTo(dl)) < 0)->select(is_less or (dr->compareTo(ri)) < 0) + dp[i+1][is_nonzero+1][is_more+1][is_less+1] * (dr = dl or is_nonzero) ; dp[i + 1+1]->select(is_nonzero or dr /= 0)->select(is_more or (li->compareTo(dl)) < 0)->select(is_less or (dr->compareTo(ri)) < 0) := dp[i + 1+1]->select(is_nonzero or dr /= 0)->select(is_more or (li->compareTo(dl)) < 0)->select(is_less or (dr->compareTo(ri)) < 0) mod MOD)))))) ; var ans : int := 0 ; for i : Integer.subrange(0, 2-1) do ( for j : Integer.subrange(0, 2-1) do ( for k : Integer.subrange(0, 2-1) do ( ans := ans + dp->last()[i+1][j+1][k+1]))) ; execute (ans mod MOD)->display(); operation make_dp(init : OclAny, size : OclAny) : OclAny pre: true post: true activity: var res : String := StringLib.interpolateStrings("[{}]*{}", Sequence{init, size->last()}) ; for i : (size->front())->reverse() do ( res := StringLib.interpolateStrings("[{}for _ in[0]*{}]", Sequence{res, i})) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- LARGE=10**9+7 def f(pos,flag_x,flag_y,flag_z,memo,left,right): if pos==-1 : return 1 if memo[pos][flag_x][flag_y][flag_z]!=-1 : return memo[pos][flag_x][flag_y][flag_z] ret=0 if flag_x or left[pos]=='0' : ret+=f(pos-1,flag_x,1 if right[pos]=='1' else flag_y,flag_z,memo,left,right) if(flag_x or left[pos]=='0')and(flag_y or right[pos]=='1')and flag_z : ret+=f(pos-1,flag_x,flag_y,flag_z,memo,left,right) if flag_y or right[pos]=='1' : ret+=f(pos-1,1 if left[pos]=='0' else flag_x,flag_y,1,memo,left,right) ret %=LARGE memo[pos][flag_x][flag_y][flag_z]=ret return ret def solve_greed_f(L,R): res_g=0 for i in range(L,R+1): for j in range(i,R+1): if j % i==j ^ i : res_g+=1 return res_g def main(): ll,rr=map(int,input().split()) left='{:060b}'.format(ll)[: :-1] right='{:060b}'.format(rr)[: :-1] memo=[[[[-1 for m in range(2)]for k in range(2)]for j in range(2)]for i in range(60)] res=f(59,0,0,0,memo,left,right) print(res) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var LARGE : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation f(pos : OclAny, flag_x : OclAny, flag_y : OclAny, flag_z : OclAny, memo : OclAny, left : OclAny, right : OclAny) : OclAny pre: true post: true activity: if pos = -1 then ( return 1 ) else skip ; if memo[pos+1][flag_x+1][flag_y+1][flag_z+1] /= -1 then ( return memo[pos+1][flag_x+1][flag_y+1][flag_z+1] ) else skip ; var ret : int := 0 ; if flag_x or left[pos+1] = '0' then ( ret := ret + f(pos - 1, flag_x, if right[pos+1] = '1' then 1 else flag_y endif, flag_z, memo, left, right) ) else skip ; if (flag_x or left[pos+1] = '0') & (flag_y or right[pos+1] = '1') & flag_z then ( ret := ret + f(pos - 1, flag_x, flag_y, flag_z, memo, left, right) ) else skip ; if flag_y or right[pos+1] = '1' then ( ret := ret + f(pos - 1, if left[pos+1] = '0' then 1 else flag_x endif, flag_y, 1, memo, left, right) ) else skip ; ret := ret mod LARGE ; memo[pos+1][flag_x+1][flag_y+1][flag_z+1] := ret ; return ret; operation solve_greed_f(L : OclAny, R : OclAny) : OclAny pre: true post: true activity: var res_g : int := 0 ; for i : Integer.subrange(L, R + 1-1) do ( for j : Integer.subrange(i, R + 1-1) do ( if j mod i = MathLib.bitwiseXor(j, i) then ( res_g := res_g + 1 ) else skip)) ; return res_g; operation main() pre: true post: true activity: var ll : OclAny := null; var rr : OclAny := null; Sequence{ll,rr} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; left := '{:060b}'.format(ll)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; right := '{:060b}'.format(rr)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; memo := Integer.subrange(0, 60-1)->select(i | true)->collect(i | (Integer.subrange(0, 2-1)->select(j | true)->collect(j | (Integer.subrange(0, 2-1)->select(k | true)->collect(k | (Integer.subrange(0, 2-1)->select(m | true)->collect(m | (-1)))))))) ; var res : String := f(59, 0, 0, 0, memo, left, right) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,A,B,C=map(int,input().split()) l=list(int(input())for i in range(N)) ans=float('inf') def dfs(x,a,b,c): if x==N : return(abs(a-A)+abs(b-B)+abs(c-C)-30)if min(a,b,c)>0 else float('inf') ret0=dfs(x+1,a,b,c) ret1=dfs(x+1,a+l[x],b,c)+10 ret2=dfs(x+1,a,b+l[x],c)+10 ret3=dfs(x+1,a,b,c+l[x])+10 return min(ret0,ret1,ret2,ret3) print(dfs(0,0,0,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{N,A,B,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) ))))))))) ; var ans : double := ("" + (('inf')))->toReal() ; skip ; execute (dfs(0, 0, 0, 0))->display(); operation dfs(x : OclAny, a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: if x = N then ( return if Set{a, b, c}->min() > 0 then ((a - A)->abs() + (b - B)->abs() + (c - C)->abs() - 30) else ("" + (('inf')))->toReal() endif ) else skip ; var ret0 : OclAny := dfs(x + 1, a, b, c) ; var ret1 : OclAny := dfs(x + 1, a + l[x+1], b, c) + 10 ; var ret2 : OclAny := dfs(x + 1, a, b + l[x+1], c) + 10 ; var ret3 : OclAny := dfs(x + 1, a, b, c + l[x+1]) + 10 ; return Set{ret0, ret1, ret2, ret3}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline sys.setrecursionlimit(10**7) from functools import lru_cache MOD=10**9+7 @ lru_cache() def F_naive(L,R): ret=0 ret+=F((L+1)//2,(R+1)//2) answer=0 for x in range(L,R+1): for y in range(x,R+1): if x.bit_length()==y.bit_length()and(x ^ y)+x==y : answer+=1 return answer @ lru_cache() def F(L,R): if L<0 : L=0 if Rpow(7)) ; skip ; var MOD : double := (10)->pow(9) + 7 ; (compound_stmt (decorator @ (dotted_name (name lru_cache)) ( )) (funcdef def (name F_naive) ( (typedargslist (def_parameters (def_parameter (named_parameter (name L))) , (def_parameter (named_parameter (name R))))) ) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ret)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ret)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name F)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name L))) + (expr (atom (number (integer 1))))))))) ))) // (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name R))) + (expr (atom (number (integer 1))))))))) ))) // (expr (atom (number (integer 2)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name answer)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name x)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name R))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name y)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name R))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name x)) (trailer . (name bit_length) (arguments ( ))))) == (comparison (expr (atom (name y)) (trailer . (name bit_length) (arguments ( ))))))) and (logical_test (comparison (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) ^ (expr (atom (name y)))))))) ))) + (expr (atom (name x))))) == (comparison (expr (atom (name y)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name answer)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name answer))))))))))))) ; (compound_stmt (decorator @ (dotted_name (name lru_cache)) ( )) (funcdef def (name F) ( (typedargslist (def_parameters (def_parameter (named_parameter (name L))) , (def_parameter (named_parameter (name R))))) ) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name L)))) < (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name L)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name R)))) < (comparison (expr (atom (name L))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name R)))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ret)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ret)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name F)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name L))) + (expr (atom (number (integer 1))))))))) ))) // (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name R))) // (expr (atom (number (integer 2)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ret)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name F)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name L))) + (expr (atom (number (integer 1))))))))) ))) // (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name R))) - (expr (atom (number (integer 1))))))))) ))) // (expr (atom (number (integer 2)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ret)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name G)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name L))) // (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name R))) - (expr (atom (number (integer 1))))))))) ))) // (expr (atom (number (integer 2)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name ret))))))))))))) ; (compound_stmt (decorator @ (dotted_name (name lru_cache)) ( )) (funcdef def (name G) ( (typedargslist (def_parameters (def_parameter (named_parameter (name L))) , (def_parameter (named_parameter (name R))))) ) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name L)))) < (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name L)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name R)))) < (comparison (expr (atom (name L))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name R)))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ret)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ret)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name G)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name L))) + (expr (atom (number (integer 1))))))))) ))) // (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name R))) // (expr (atom (number (integer 2)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ret)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name F)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name L))) + (expr (atom (number (integer 1))))))))) ))) // (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name R))) - (expr (atom (number (integer 1))))))))) ))) // (expr (atom (number (integer 2)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ret)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name G)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name L))) // (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name R))) - (expr (atom (number (integer 1))))))))) ))) // (expr (atom (number (integer 2)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name ret))))))))))))) ; var L : OclAny := null; var R : OclAny := null; Sequence{L,R} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var answer : int := F(L, R) mod MOD ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import product L,R=map(int,input().split()) MOD=10**9+7 dp=[[[0,0]for _ in range(2)]for _ in range(2)] pp=[[[0,0]for _ in range(2)]for _ in range(2)] dp[0][0][0]=1 for d in range(60,-1,-1): pp,dp=dp,pp dp=[[[0,0]for _ in range(2)]for _ in range(2)] lb=L>>d & 1 rb=R>>d & 1 if d==1 : pass ans=0 for lrs in product((0,1),repeat=3): l,r,s=lrs for xy in product((0,1),repeat=2): nl,nr,ns=l,r,s x,y=xy if x and not y : continue if not s and x!=y : continue if x and y : ns=1 if not l and not x and lb : continue if x and not lb : nl=1 if not r and y and not rb : continue if not y and rb : nr=1 dp[nl][nr][ns]+=pp[l][r][s] dp[nl][nr][ns]%=MOD print(sum(dp[l][r][s]for l in(0,1)for r in(0,1)for s in(0,1))% MOD) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var L : OclAny := null; var R : OclAny := null; Sequence{L,R} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var MOD : double := (10)->pow(9) + 7 ; var dp : Sequence := Integer.subrange(0, 2-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, 2-1)->select(_anon | true)->collect(_anon | (Sequence{0}->union(Sequence{ 0 }))))) ; var pp : Sequence := Integer.subrange(0, 2-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, 2-1)->select(_anon | true)->collect(_anon | (Sequence{0}->union(Sequence{ 0 }))))) ; dp->first()->first()->first() := 1 ; for d : Integer.subrange(-1 + 1, 60)->reverse() do ( Sequence{pp,dp} := Sequence{dp,pp} ; dp := Integer.subrange(0, 2-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, 2-1)->select(_anon | true)->collect(_anon | (Sequence{0}->union(Sequence{ 0 }))))) ; var lb : int := MathLib.bitwiseAnd(L /(2->pow(d)), 1) ; var rb : int := MathLib.bitwiseAnd(R /(2->pow(d)), 1) ; if d = 1 then ( skip ) else skip ; var ans : int := 0 ; for lrs : product(Sequence{0, 1}, (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (number (integer 3))))))))) do ( var l : OclAny := null; var r : OclAny := null; var s : OclAny := null; Sequence{l,r,s} := lrs ; for xy : product(Sequence{0, 1}, (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var nl : OclAny := null; var nr : OclAny := null; var ns : OclAny := null; Sequence{nl,nr,ns} := Sequence{l,r,s} ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := xy ; if x & not(y) then ( continue ) else skip ; if not(s) & x /= y then ( continue ) else skip ; if x & y then ( var ns : int := 1 ) else skip ; if not(l) & not(x) & lb then ( continue ) else skip ; if x & not(lb) then ( var nl : int := 1 ) else skip ; if not(r) & y & not(rb) then ( continue ) else skip ; if not(y) & rb then ( var nr : int := 1 ) else skip ; dp[nl+1][nr+1][ns+1] := dp[nl+1][nr+1][ns+1] + pp[l+1][r+1][s+1] ; dp[nl+1][nr+1][ns+1] := dp[nl+1][nr+1][ns+1] mod MOD))) ; execute (((argument (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name l)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])))))) (comp_for for (exprlist (expr (atom (name l)))) in (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) , (test (logical_test (comparison (expr (atom (number (integer 1)))))))) ))))) (comp_iter (comp_for for (exprlist (expr (atom (name r)))) in (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) , (test (logical_test (comparison (expr (atom (number (integer 1)))))))) ))))) (comp_iter (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) , (test (logical_test (comparison (expr (atom (number (integer 1)))))))) ))))))))))))->sum() mod MOD)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys def printe(*st): return True def replace(st,pos,char): return st[0 : pos]+char+st[pos+1 :] def simulate(): [r,c]=[int(a)for a in input().split()] t=[] for b in range(r): t.append(input()) printe(t) for y in range(r-1): x=0 while(xtoInteger()-1) do ( execute (StringLib.interpolateStrings("Case #{}:\n{}", Sequence{i + 1, simulate()}))->display()) ) else skip; operation printe(st : OclAny : Sequence(OclAny)) : OclAny pre: true post: true activity: (args * (named_parameter (name st))) return true; operation replace(st : OclAny, pos : OclAny, char : OclAny) : OclAny pre: true post: true activity: return st.subrange(0+1, pos) + char + st.subrange(pos + 1+1); operation simulate() pre: true post: true activity: ; Sequence{r}->union(Sequence{ c }) := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; var t : Sequence := Sequence{} ; for b : Integer.subrange(0, r-1) do ( execute (((OclFile["System.in"]).readLine()) : t)) ; printe(t) ; for y : Integer.subrange(0, r - 1-1) do ( var x : int := 0 ; while ((x->compareTo(c - 1)) < 0) do ( if t[y+1][x+1] = '#' then ( if t[y+1][x + 1+1] = '#' & t[y + 1+1][x+1] = '#' & t[y + 1+1][x + 1+1] = '#' then ( t[y+1] := replace(t[y+1], x, '/') ; t[y+1] := replace(t[y+1], x + 1, "X") ; t[y + 1+1] := replace(t[y + 1+1], x, 'X') ; t[y + 1+1] := replace(t[y + 1+1], x + 1, '/') ; x := x + 1 ) else ( return "Impossible" ) ) else skip ; x := x + 1)) ; for y : Integer.subrange(0, r-1) do ( if t[y+1][c - 1+1] = '#' then ( return "Impossible" ) else skip) ; for x : Integer.subrange(0, c-1) do ( if t[r - 1+1][x+1] = '#' then ( return "Impossible" ) else skip) ; for y : Integer.subrange(0, r-1) do ( t[y+1] := t[y+1].replace("X", "\\")) ; return StringLib.sumStringsWithSeparator((t), "\n"); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- infile=open('square_tiles.in') outfile=open('square_tiles.out','w') T=int(infile.readline().strip()) def fill_spot(i,j): if i>=R-1 or j>=C-1 : return False for i2 in xrange(i,i+2): for j2 in xrange(j,j+2): if grid[i2][j2]!='#' : return False grid[i][j]='/' grid[i][j+1]='\\' grid[i+1][j]='\\' grid[i+1][j+1]='/' return True def convert_to_red(): for i in xrange(R): for j in xrange(C): if grid[i][j]=='#' : if not fill_spot(i,j): return False return True for t in xrange(T): R,C=[int(s)for s in infile.readline().strip().split()] grid=[list(infile.readline().strip())for i in xrange(R)] outfile.write('Case #%d:\n' %(t+1)) if not convert_to_red(): outfile.write('Impossible\n') continue for i in xrange(R): outfile.write(''.join(grid[i])+'\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var infile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('square_tiles.in')) ; var outfile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('square_tiles.out')) ; var T : int := ("" + ((infile.readLine()->trim())))->toInteger() ; skip ; skip ; for t : xrange(T) do ( var R : OclAny := null; var C : OclAny := null; Sequence{R,C} := infile.readLine()->trim().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; var grid : Sequence := xrange(R)->select(i | true)->collect(i | ((infile.readLine()->trim()))) ; outfile.write(StringLib.format('Case #%d: ',(t + 1))) ; if not(convert_to_red()) then ( outfile.write('Impossible ') ; continue ) else skip ; for i : xrange(R) do ( outfile.write(StringLib.sumStringsWithSeparator((grid[i+1]), '') + ' '))); operation fill_spot(i : OclAny, j : OclAny) : OclAny pre: true post: true activity: if (i->compareTo(R - 1)) >= 0 or (j->compareTo(C - 1)) >= 0 then ( return false ) else skip ; for i2 : xrange(i, i + 2) do ( for j2 : xrange(j, j + 2) do ( if grid[i2+1][j2+1] /= '#' then ( return false ) else skip)) ; grid[i+1][j+1] := '/' ; grid[i+1][j + 1+1] := '\\' ; grid[i + 1+1][j+1] := '\\' ; grid[i + 1+1][j + 1+1] := '/' ; return true; operation convert_to_red() : OclAny pre: true post: true activity: for i : xrange(R) do ( for j : xrange(C) do ( if grid[i+1][j+1] = '#' then ( if not(fill_spot(i, j)) then ( return false ) else skip ) else skip)) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) for num in range(1,N+1): r,c=input().split() r=int(r) c=int(c) M=[0]*r for i in range(r): M[i]=list(input()) ans=True for i in range(r-1): for j in range(c-1): if M[i][j]=='#' : if M[i+1][j]=='#' and M[i][j+1]=='#' and M[i+1][j+1]=='#' : M[i][j]='/' M[i][j+1]='\\' M[i+1][j]='\\' M[i+1][j+1]='/' else : ans=False if '#' in M[i]: ans=False if '#' in M[-1]: ans=False print("Case #",num,":",sep='') if ans : for i in range(r): print(''.join(M[i])) else : print("Impossible") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for num : Integer.subrange(1, N + 1-1) do ( var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := input().split() ; var r : int := ("" + ((r)))->toInteger() ; var c : int := ("" + ((c)))->toInteger() ; var M : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, r) ; for i : Integer.subrange(0, r-1) do ( M[i+1] := ((OclFile["System.in"]).readLine())->characters()) ; var ans : boolean := true ; for i : Integer.subrange(0, r - 1-1) do ( for j : Integer.subrange(0, c - 1-1) do ( if M[i+1][j+1] = '#' then ( if M[i + 1+1][j+1] = '#' & M[i+1][j + 1+1] = '#' & M[i + 1+1][j + 1+1] = '#' then ( M[i+1][j+1] := '/' ; M[i+1][j + 1+1] := '\\' ; M[i + 1+1][j+1] := '\\' ; M[i + 1+1][j + 1+1] := '/' ) else ( ans := false ) ) else skip) ; if (M[i+1])->includes('#') then ( ans := false ) else skip) ; if (M->last())->includes('#') then ( ans := false ) else skip ; execute ("Case #")->display() ; if ans then ( for i : Integer.subrange(0, r-1) do ( execute (StringLib.sumStringsWithSeparator((M[i+1]), ''))->display()) ) else ( execute ("Impossible")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b,c,t=map(int,input().split()) s=sum(map(int,input().split())) print(max(a*n-(t*n-s)*b+(n*t-s)*c,a*n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var t : OclAny := null; Sequence{n,a,b,c,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum() ; execute (Set{a * n - (t * n - s) * b + (n * t - s) * c, a * n}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os def process(data,rf): data=data.split("") rows=int(data[0]) cols=int(data[1]) picture=[] for r in range(rows): data=rf.readline() data=data.replace('#','0') data=data.strip() picture.append(list(data)) outstr="" for r in range(rows): outrow="" for c in range(cols): if(picture[r][c]=='0'): try : if((picture[r][c+1]=='0')and(picture[r+1][c]=='0')and(picture[r+1][c+1]=='0')): picture[r][c]="/" picture[r][c+1]="\\" picture[r+1][c]="\\" picture[r+1][c+1]="/" else : return "Impossible\n" except : return "Impossible\n" outrow+=picture[r][c] outstr+=outrow+"\n" return outstr def main(): rf=open(os.path.join(os.getcwd(),"A-large.in"),"r") wf=open(os.path.join(os.getcwd(),"output.txt"),"w") heading=True test_num=1 while True : line=rf.readline() line=line.strip() if not line : rf.close() wf.close() break else : if(heading): heading=False NUM_TEST_CASES=int(line) else : wf.write("Case #"+str(test_num)+":\n"+process(line,rf)) test_num+=1 main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; main(); operation process(data : OclAny, rf : OclAny) : OclAny pre: true post: true activity: data := data.split("") ; var rows : int := ("" + ((data->first())))->toInteger() ; var cols : int := ("" + ((data[1+1])))->toInteger() ; var picture : Sequence := Sequence{} ; for r : Integer.subrange(0, rows-1) do ( data := rf.readLine() ; data := data.replace('#', '0') ; data := data->trim() ; execute (((data)) : picture)) ; var outstr : String := "" ; for r : Integer.subrange(0, rows-1) do ( var outrow : String := "" ; for c : Integer.subrange(0, cols-1) do ( if (picture[r+1][c+1] = '0') then ( try ( if ((picture[r+1][c + 1+1] = '0') & (picture[r + 1+1][c+1] = '0') & (picture[r + 1+1][c + 1+1] = '0')) then ( picture[r+1][c+1] := "/" ; picture[r+1][c + 1+1] := "\\" ; picture[r + 1+1][c+1] := "\\" ; picture[r + 1+1][c + 1+1] := "/" ) else ( return "Impossible\n" )) catch (_e : OclException) do ( return "Impossible\n") ) else skip ; outrow := outrow + picture[r+1][c+1]) ; outstr := outstr + outrow + "\n") ; return outstr; operation main() pre: true post: true activity: rf := OclFile.newOclFile_Write(OclFile.newOclFile(os.path.join(os.getcwd(), "A-large.in"))) ; var wf : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(os.path.join(os.getcwd(), "output.txt"))) ; var heading : boolean := true ; var test_num : int := 1 ; while true do ( var line : String := rf.readLine() ; line := line->trim() ; if not(line = "") then ( rf.closeFile() ; wf.closeFile() ; break ) else ( if (heading) then ( heading := false ; var NUM_TEST_CASES : int := ("" + ((line)))->toInteger() ) else ( wf.write("Case #" + ("" + ((test_num))) + ":\n" + process(line, rf)) ; test_num := test_num + 1 ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math inf=open("in.txt","r") ouf=open('out.txt','w') def close_files(): inf.close ouf.close def precount(): pass printcounter=0 def printstr(a): global printcounter printcounter+=1 print>>ouf,'Case #%d: %s' %(printcounter,a) def solvetest(): global printcounter [r,c]=inf.readline().split() r,c=int(r),int(c) a=[] for i in xrange(r): a.append(list(inf.readline().strip())) bad=0 for i in xrange(r): for j in xrange(c): if a[i][j]=='#' : if i==r-1 or j==c-1 : bad=1 break if a[i+1][j]!='#' or a[i][j+1]!='#' or a[i+1][j+1]!='#' : bad=1 break a[i][j]='/' a[i+1][j]='\\' a[i][j+1]='\\' a[i+1][j+1]='/' if bad : break printcounter+=1 print>>ouf,'Case #%d:' %(printcounter) if bad : print>>ouf,'Impossible' else : for i in xrange(r): s='' for j in xrange(c): s=s+a[i][j] print>>ouf,s precount() testnum=int(inf.readline()) for test in xrange(testnum): solvetest() close_files() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute printcounter : OclAny; attribute printcounter : OclAny; operation initialise() pre: true post: true activity: skip ; var Math_PINFINITY : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("in.txt")) ; var ouf : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('out.txt')) ; skip ; skip ; var printcounter : int := 0 ; skip ; skip ; Sequence{r}->union(Sequence{ c }) := Math_PINFINITY.readLine().split(); operation close_files() pre: true post: true activity: Math_PINFINITY.closeFile() ; ouf.closeFile(); operation precount() pre: true post: true activity: skip; operation printstr(a : OclAny) pre: true post: true activity: skip ; printcounter := printcounter + 1 ; print /(2->pow(ouf)) ; (expr (expr (atom 'Case #%d: %s')) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name printcounter)))))) , (test (logical_test (comparison (expr (atom (name a))))))) )))); operation solvetest() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() mi=len(S)//2+len(S)% 2 if len(S)% 2==0 : l=mi-1 r=mi if S[l]!=S[r]: print(r) exit() else : l=mi-1 r=mi-1 re=S[l] for i in range(l): if S[l-1-i]!=re or S[r+1+i]!=re : ans=r+i+1 break else : ans=len(S) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var mi : int := (S)->size() div 2 + (S)->size() mod 2 ; if (S)->size() mod 2 = 0 then ( var l : double := mi - 1 ; var r : int := mi ; if S[l+1] /= S[r+1] then ( execute (r)->display() ; exit() ) else skip ) else ( l := mi - 1 ; r := mi - 1 ) ; var re : OclAny := S[l+1] ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name l))) - (expr (atom (number (integer 1))))) - (expr (atom (name i))))))))) ])))) != (comparison (expr (atom (name re)))))) or (logical_test (comparison (comparison (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name r))) + (expr (atom (number (integer 1))))) + (expr (atom (name i))))))))) ])))) != (comparison (expr (atom (name re)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (name r))) + (expr (atom (name i)))) + (expr (atom (number (integer 1)))))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name S)))))))) )))))))))))))))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.readline().strip() def main(): S=input() N=len(S) if S=='1'*N or S=='0'*N : print(N) return left=N//2 right=N while right-left>1 : mid=(left+right)//2 if S[(N-mid): mid]=='1'*(2*mid-N)or S[(N-mid): mid]=='0'*(2*mid-N): left=mid else : right=mid print(left) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation main() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var N : int := (S)->size() ; if S = StringLib.nCopies('1', N) or S = StringLib.nCopies('0', N) then ( execute (N)->display() ; return ) else skip ; var left : int := N div 2 ; var right : int := N ; while right - left > 1 do ( var mid : int := (left + right) div 2 ; if S.subrange((N - mid)+1, mid) = StringLib.nCopies('1', (2 * mid - N)) or S.subrange((N - mid)+1, mid) = StringLib.nCopies('0', (2 * mid - N)) then ( left := mid ) else ( right := mid )) ; execute (left)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() t=len(S) for k in range(1,len(S)): if S[k-1]!=S[k]: t=min(t,max(k,len(S)-k)) print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var t : int := (S)->size() ; for k : Integer.subrange(1, (S)->size()-1) do ( if S[k - 1+1] /= S[k+1] then ( t := Set{t, Set{k, (S)->size() - k}->max()}->min() ) else skip) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import* from itertools import* from collections import* from functools import* try : from math import gcd except Exception : from fractions import gcd def solve(N : int,A : int,B : int,C : int,l : "List[int]"): e=[A,B,C] ret=float('inf') for i in range(4**N): ls=[0,0,0,0] cs=[0,0,0,0] for j,ll in enumerate(l): key=(i>>(2*j))& 0x03 ls[key]+=ll cs[key]+=10 if cs[0]==0 or cs[1]==0 or cs[2]==0 : continue for i0,i1,i2 in permutations([0,1,2],3): cc=cs[0]+abs(e[i0]-ls[0])-10 cc+=cs[1]+abs(e[i1]-ls[1])-10 cc+=cs[2]+abs(e[i2]-ls[2])-10 if ccunion(Sequence{B}->union(Sequence{ C })) ; var ret : double := ("" + (('inf')))->toReal() ; for i : Integer.subrange(0, (4)->pow(N)-1) do ( var ls : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))) ; var cs : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))) ; for _tuple : Integer.subrange(1, (l)->size())->collect( _indx | Sequence{_indx-1, (l)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var ll : OclAny := _tuple->at(_indx); var key : int := MathLib.bitwiseAnd((i /(2->pow((2 * j)))), 0x03) ; ls[key+1] := ls[key+1] + ll ; cs[key+1] := cs[key+1] + 10) ; if cs->first() = 0 or cs[1+1] = 0 or cs[2+1] = 0 then ( continue ) else skip ; for _tuple : permutations(Sequence{0}->union(Sequence{1}->union(Sequence{ 2 })), 3) do (var _indx : int := 1; var i0 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i2 : OclAny := _tuple->at(_indx); var cc : double := cs->first() + (e[i0+1] - ls->first())->abs() - 10 ; cc := cc + cs[1+1] + (e[i1+1] - ls[1+1])->abs() - 10 ; cc := cc + cs[2+1] + (e[i2+1] - ls[2+1])->abs() - 10 ; if (cc->compareTo(ret)) < 0 then ( ret := cc ) else skip)) ; return ret; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var N : int := ("" + (((tokens).next())))->toInteger() ; var A : int := ("" + (((tokens).next())))->toInteger() ; var B : int := ("" + (((tokens).next())))->toInteger() ; var C : int := ("" + (((tokens).next())))->toInteger() ; var l : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((tokens).next())))->toInteger())) ; var result : OclAny := solve(N, A, B, C, l) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input() n=len(I) left=0 right=n-1 block_left_index=0 block_right_index=n while leftsize() ; var left : int := 0 ; var right : double := n - 1 ; var block_left_index : int := 0 ; var block_right_index : int := n ; while (left->compareTo(right)) < 0 do ( if I[left+1] /= I[left + 1+1] then ( block_left_index := left + 1 ) else skip ; if I[right+1] /= I[right - 1+1] then ( block_right_index := right ) else skip ; left := left + 1 ; right := right - 1) ; var ans : OclAny := Set{n - block_left_index, block_right_index}->min() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import copy import heapq import math import sys from collections import* from itertools import accumulate,combinations,permutations,product def input(): return sys.stdin.readline()[:-1] def ruiseki(lst): return[0]+list(accumulate(lst)) mod=pow(10,9)+7 al=[chr(ord('a')+i)for i in range(26)] direction=[[1,0],[0,1],[-1,0],[0,-1]] s=input() ls=len(s) kijun=s[ls//2] if ls % 2==0 : tmp=0 for i in range(ls//2): if kijun==s[ls//2+i]==s[ls//2-1-i]: tmp+=1 else : break print(ls//2+tmp) else : tmp=1 for i in range(ls//2): if kijun==s[ls//2+1+i]==s[ls//2-1-i]: tmp+=1 else : break print(ls//2+tmp) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; var al : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | ((('a')->char2byte() + i)->byte2char())) ; var direction : Sequence := Sequence{Sequence{1}->union(Sequence{ 0 })}->union(Sequence{Sequence{0}->union(Sequence{ 1 })}->union(Sequence{Sequence{-1}->union(Sequence{ 0 })}->union(Sequence{ Sequence{0}->union(Sequence{ -1 }) }))) ; var s : String := (OclFile["System.in"]).readLine() ; var ls : int := (s)->size() ; var kijun : OclAny := s[ls div 2+1] ; if ls mod 2 = 0 then ( var tmp : int := 0 ; for i : Integer.subrange(0, ls div 2-1) do ( if kijun = s[ls div 2 + i+1] & (s[ls div 2 + i+1] == s[ls div 2 - 1 - i+1]) then ( tmp := tmp + 1 ) else ( break )) ; execute (ls div 2 + tmp)->display() ) else ( tmp := 1 ; for i : Integer.subrange(0, ls div 2-1) do ( if kijun = s[ls div 2 + 1 + i+1] & (s[ls div 2 + 1 + i+1] == s[ls div 2 - 1 - i+1]) then ( tmp := tmp + 1 ) else ( break )) ; execute (ls div 2 + tmp)->display() ); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation ruiseki(lst : OclAny) : OclAny pre: true post: true activity: return Sequence{ 0 }->union((accumulate(lst))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countDistinct(arr,n): res=1 for i in range(1,n): j=0 for j in range(i): if(arr[i]==arr[j]): break if(i==j+1): res+=1 return res arr=[12,10,9,45,2,10,10,45] n=len(arr) print(countDistinct(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{12}->union(Sequence{10}->union(Sequence{9}->union(Sequence{45}->union(Sequence{2}->union(Sequence{10}->union(Sequence{10}->union(Sequence{ 45 }))))))) ; n := (arr)->size() ; execute (countDistinct(arr, n))->display(); operation countDistinct(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; for i : Integer.subrange(1, n-1) do ( var j : int := 0 ; for j : Integer.subrange(0, i-1) do ( if (arr[i+1] = arr[j+1]) then ( break ) else skip) ; if (i = j + 1) then ( res := res + 1 ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=128 def isVowel(x): return(x=='a' or x=='e' or x=='i' or x=='o' or x=='u' or x=='A' or x=='E' or x=='I' or x=='O' or x=='U') def KDistinctVowel(c,k): n=len(s) c=[0 for i in range(MAX)] result=-1 j=-1 for i in range(n): x=s[i] if isVowel(x): c[ord(x)]+=1 if c[ord(x)]==1 : k-=1 while k<0 : j+=1 x=s[j] if isVowel(x): c[ord(x)]-=1 k+=1 if k==0 : result=max(result,i-j) return result s="tHeracEBetwEEntheTwo" k=1 print(KDistinctVowel(s,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 128 ; skip ; skip ; var s : String := "tHeracEBetwEEntheTwo" ; k := 1 ; execute (KDistinctVowel(s, k))->display(); operation isVowel(x : OclAny) : OclAny pre: true post: true activity: return (x = 'a' or x = 'e' or x = 'i' or x = 'o' or x = 'u' or x = 'A' or x = 'E' or x = 'I' or x = 'O' or x = 'U'); operation KDistinctVowel(c : OclAny, k : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; c := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)) ; var result : int := -1 ; var j : int := -1 ; for i : Integer.subrange(0, n-1) do ( x := s[i+1] ; if isVowel(x) then ( c[(x)->char2byte()+1] := c[(x)->char2byte()+1] + 1 ; if c[(x)->char2byte()+1] = 1 then ( k := k - 1 ) else skip ) else skip ; while k < 0 do ( j := j + 1 ; x := s[j+1] ; if isVowel(x) then ( c[(x)->char2byte()+1] := c[(x)->char2byte()+1] - 1 ; k := k + 1 ) else skip) ; if k = 0 then ( result := Set{result, i - j}->max() ) else skip) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b,c,t=map(int,input().split()) l=list(map(int,input().split())) if(b>=c): res=0 for i in l : if(i<=t): res+=a else : res=0 for i in l : if(i<=t): res+=a res+=(c-b)*(t-i) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var t : OclAny := null; Sequence{n,a,b,c,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if ((b->compareTo(c)) >= 0) then ( var res : int := 0 ; for i : l do ( if ((i->compareTo(t)) <= 0) then ( res := res + a ) else skip) ) else ( res := 0 ; for i : l do ( if ((i->compareTo(t)) <= 0) then ( res := res + a ; res := res + (c - b) * (t - i) ) else skip) ) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for x in range(0,t): n=int(input()) lista=[tuple(map(int,input().split()))for i in range(0,n)] y_cordinates=[b for a,b in lista] x_cordinates=[a for a,b in lista] numb_moves=0 if max(y_cordinates)>=0 : numb_moves+=2*max(y_cordinates) if min(y_cordinates)<0 : numb_moves-=2*min(y_cordinates) if max(x_cordinates)>=0 : numb_moves+=2*max(x_cordinates) if min(x_cordinates)<0 : numb_moves-=2*min(x_cordinates) print(numb_moves) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for x : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lista : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var y_cordinates : Sequence := lista->select(_tuple | true)->collect(_tuple | let a : OclAny = _tuple->at(1) in let b : OclAny = _tuple->at(2) in (b)) ; var x_cordinates : Sequence := lista->select(_tuple | true)->collect(_tuple | let a : OclAny = _tuple->at(1) in let b : OclAny = _tuple->at(2) in (a)) ; var numb_moves : int := 0 ; if (y_cordinates)->max() >= 0 then ( numb_moves := numb_moves + 2 * (y_cordinates)->max() ) else skip ; if (y_cordinates)->min() < 0 then ( numb_moves := numb_moves - 2 * (y_cordinates)->min() ) else skip ; if (x_cordinates)->max() >= 0 then ( numb_moves := numb_moves + 2 * (x_cordinates)->max() ) else skip ; if (x_cordinates)->min() < 0 then ( numb_moves := numb_moves - 2 * (x_cordinates)->min() ) else skip ; execute (numb_moves)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) mxx=mxy=-101 mnx=mny=101 while n>0 : a,b=list(map(int,input().split())) mxx=max(mxx,a) mnx=min(mnx,a) mxy=max(mxy,b) mny=min(mny,b) n-=1 ans=0 if mxx<0 : mxx=0 if mnx>0 : mnx=0 if mxy<0 : mxy=0 if mny>0 : mny=0 print(2*(mxx-mnx)+2*(mxy-mny)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mxx : OclAny := -101; var mxy : int := -101 ; var mnx : OclAny := 101; var mny : int := 101 ; while n > 0 do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; mxx := Set{mxx, a}->max() ; mnx := Set{mnx, a}->min() ; mxy := Set{mxy, b}->max() ; mny := Set{mny, b}->min() ; n := n - 1) ; var ans : int := 0 ; if mxx < 0 then ( mxx := 0 ) else skip ; if mnx > 0 then ( mnx := 0 ) else skip ; if mxy < 0 then ( mxy := 0 ) else skip ; if mny > 0 then ( mny := 0 ) else skip ; execute (2 * (mxx - mnx) + 2 * (mxy - mny))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) mx1=mx2=mx3=mx4=0 for i in range(n): x,y=map(int,input().split()) if x>0 : if x>mx1 : mx1=x else : if abs(x)>mx2 : mx2=abs(x) if y>0 : if y>mx3 : mx3=y else : y=abs(y) if y>mx4 : mx4=y sm=mx1+mx2+mx3+mx4 print(sm*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; mx1 := mx1(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name mx2)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name mx3)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name mx4)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x > 0 then ( if (x->compareTo(mx1)) > 0 then ( var mx1 : OclAny := x ) else skip ) else ( if ((x)->abs()->compareTo(mx2)) > 0 then ( var mx2 : double := (x)->abs() ) else skip ) ; if y > 0 then ( if (y->compareTo(mx3)) > 0 then ( var mx3 : OclAny := y ) else skip ) else ( var y : double := (y)->abs() ; if (y->compareTo(mx4)) > 0 then ( var mx4 : OclAny := y ) else skip )) ; var sm : OclAny := mx1 + mx2 + mx3 + mx4 ; execute (sm * 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- exec(int(input())*"print(2*sum(max(0,*x)-min(0,*x)for x in zip(*(map(int,input().split())for _ in[0]*int(input())))));") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) )))) * (expr (atom "print(2*sum(max(0,*x)-min(0,*x)for x in zip(*(map(int,input().split())for _ in[0]*int(input())))));"))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def eff(l): if l[0]>=0 : return l[-1] elif l[-1]<0 : return-l[0] elif l[0]<=0 and l[-1]>=0 : return l[-1]-l[0] t=int(input()) for i in range(0,t): x=[] y=[] n=int(input()) ans=0 for i1 in range(0,n): cx,cy=input().split() if int(cx)==0 : y.append(int(cy)) else : x.append(int(cx)) x=sorted(x) y=sorted(y) if len(x)==0 : print(2*eff(y)) elif len(y)==0 : print(2*eff(x)) else : print(2*eff(x)+2*(eff(y))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var x : Sequence := Sequence{} ; var y : Sequence := Sequence{} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; for i1 : Integer.subrange(0, n-1) do ( var cx : OclAny := null; var cy : OclAny := null; Sequence{cx,cy} := input().split() ; if ("" + ((cx)))->toInteger() = 0 then ( execute ((("" + ((cy)))->toInteger()) : y) ) else ( execute ((("" + ((cx)))->toInteger()) : x) )) ; x := x->sort() ; y := y->sort() ; if (x)->size() = 0 then ( execute (2 * eff(y))->display() ) else (if (y)->size() = 0 then ( execute (2 * eff(x))->display() ) else ( execute (2 * eff(x) + 2 * (eff(y)))->display() ) ) ); operation eff(l : OclAny) : OclAny pre: true post: true activity: if l->first() >= 0 then ( return l->last() ) else (if l->last() < 0 then ( return -l->first() ) else (if l->first() <= 0 & l->last() >= 0 then ( return l->last() - l->first() ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(raw_input()) il=map(int,raw_input().split()) s=0 t=0 cnt=[] while ttoInteger() ; var il : Sequence := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : int := 0 ; var t : int := 0 ; var cnt : Sequence := Sequence{} ; while (t->compareTo(n - 1)) < 0 do ( if il[t+1] = il[t + 1+1] then ( execute ((t + 1 - s) : cnt) ; s := t + 1 ) else skip ; t := t + 1 ; if t = n - 1 then ( execute ((t + 1 - s) : cnt) ) else skip) ; var ans : int := 0 ; if (cnt)->size() <= 3 then ( execute ((cnt)->sum())->display() ) else ( for i : xrange((cnt)->size() - 2) do ( ans := Set{ans, cnt[i+1] + cnt[i + 1+1] + cnt[i + 2+1]}->max()) ; execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) first=[] last=[] for i in range(n): line=[int(i)for i in input().split()[1 :]] if line==sorted(line,key=lambda x :-x): first.append(line[0]) last.append(line[-1]) first.sort() last.sort() ans=n*n ptr=0 for i in range(len(last)): while ptr=first[ptr]: ptr+=1 ans-=ptr print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var first : Sequence := Sequence{} ; var last : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var line : Sequence := input().split()->tail()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if line = line->sortedBy($x | (lambda x : OclAny in (-x))->apply($x)) then ( execute ((line->first()) : first) ; execute ((line->last()) : last) ) else skip) ; first := first->sort() ; last := last->sort() ; var ans : int := n * n ; var ptr : int := 0 ; for i : Integer.subrange(0, (last)->size()-1) do ( while (ptr->compareTo((first)->size())) < 0 & (last[i+1]->compareTo(first[ptr+1])) >= 0 do ( ptr := ptr + 1) ; ans := ans - ptr) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def read_int(): return int(input().strip()) def read_ints(): return list(map(int,input().strip().split(' '))) def build(l,A): N=len(l) mask_to_cost=[math.inf]*(1<0 : cost-=10 cost+=abs(length-A) mask_to_cost[m]=cost for m in range(1<0 : s=(s-1)& m mask_to_cost[m]=min(mask_to_cost[m],mask_to_cost[s]) return mask_to_cost def solve(): N,A,B,C=read_ints() l=[read_int()for _ in range(N)] A_cost=build(l,A) B_cost=build(l,B) C_cost=build(l,C) min_cost=math.inf for a_mask in range(1,1<0 : b_mask=(b_mask-1)& bc_mask c_mask=bc_mask-b_mask if b_mask and c_mask : min_cost=min(min_cost,A_cost[a_mask]+B_cost[b_mask]+C_cost[c_mask]) return min_cost if __name__=='__main__' : print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( execute (solve())->display() ) else skip; operation read_int() : OclAny pre: true post: true activity: return ("" + ((input()->trim())))->toInteger(); operation read_ints() : OclAny pre: true post: true activity: return ((input()->trim().split(' '))->collect( _x | (OclType["int"])->apply(_x) )); operation build(l : OclAny, A : OclAny) : OclAny pre: true post: true activity: var N : int := (l)->size() ; var mask_to_cost : Sequence := MatrixLib.elementwiseMult(Sequence{ }, (1 * (2->pow(N)))) ; for m : Integer.subrange(1, 1 * (2->pow(N))-1) do ( var i : int := 0 ; var cost : int := 0 ; var length : int := 0 ; while (i->compareTo(N)) < 0 do ( if MathLib.bitwiseAnd(m, (1 * (2->pow(i)))) then ( cost := cost + 10 ; length := length + l[N - i - 1+1] ) else skip ; i := i + 1) ; if cost > 0 then ( cost := cost - 10 ) else skip ; cost := cost + (length - A)->abs() ; mask_to_cost[m+1] := cost) ; for m : Integer.subrange(0, 1 * (2->pow(N))-1) do ( var s : OclAny := m ; while s > 0 do ( s := MathLib.bitwiseAnd((s - 1), m) ; mask_to_cost[m+1] := Set{mask_to_cost[m+1], mask_to_cost[s+1]}->min())) ; return mask_to_cost; operation solve() : OclAny pre: true post: true activity: var B : OclAny := null; var C : OclAny := null; Sequence{N,A,B,C} := read_ints() ; l := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (read_int())) ; var A_cost : OclAny := build(l, A) ; var B_cost : OclAny := build(l, B) ; var C_cost : OclAny := build(l, C) ; var min_cost : OclAny := ; for a_mask : Integer.subrange(1, 1 * (2->pow(N))-1) do ( var bc_mask : double := ((1 * (2->pow(N))) - 1) - a_mask ; var b_mask : OclAny := bc_mask ; while b_mask > 0 do ( b_mask := MathLib.bitwiseAnd((b_mask - 1), bc_mask) ; var c_mask : double := bc_mask - b_mask ; if b_mask & c_mask then ( min_cost := Set{min_cost, A_cost[a_mask+1] + B_cost[b_mask+1] + C_cost[c_mask+1]}->min() ) else skip)) ; return min_cost; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _=input() A=[0] b='' for a in input().split(): if b=='' or b==a : A.append(1) else : A[-1]+=1 b=a ans=0 if len(A)<5 : ans=sum(A) else : for i in range(1,len(A)-2): ans=max(ans,sum(A[i : i+3])) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _anon : String := (OclFile["System.in"]).readLine() ; var A : Sequence := Sequence{ 0 } ; var b : String := '' ; for a : input().split() do ( if b = '' or b = a then ( execute ((1) : A) ) else ( A->last() := A->last() + 1 ) ; b := a) ; var ans : int := 0 ; if (A)->size() < 5 then ( ans := (A)->sum() ) else ( for i : Integer.subrange(1, (A)->size() - 2-1) do ( ans := Set{ans, (A.subrange(i+1, i + 3))->sum()}->max()) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- illu=[] n=0 def findmax(begin,end): flag=illu[begin] l=1 maxlen=1 for i in range(begin+1,end+1): if illu[i]+flag==1 : l+=1 else : if l>maxlen : maxlen=l l=1 flag=illu[i] return maxlen if maxlen>l else l def find_alterseq(): seq=[] s=e=0 flag=illu[0] for i in range(1,n+1): if illu[i]+flag!=1 : seq.append([s,i-1]) s=i flag=illu[i] return seq def reverse(s,e): for i in range(s,e+1): illu[i]=1-illu[i] def solve(): alseq=find_alterseq() maxlen=0 alseq.insert(0,[0,0]) alseq.append([n,n]) nindex=len(alseq) for i in range(1,nindex-1): s,e=alseq[i] begin=alseq[i-1][0] end=alseq[i+1][1] if end-begin+1>=maxlen : reverse(s,e) l=findmax(begin,end) if l>maxlen : maxlen=l reverse(s,e) return maxlen line=input() n=int(line) illu=list(map(int,list(input().split()))) illu.append(999) ans=solve() print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var illu : Sequence := Sequence{} ; var n : int := 0 ; skip ; skip ; skip ; skip ; var line : String := (OclFile["System.in"]).readLine() ; n := ("" + ((line)))->toInteger() ; illu := (((input().split()))->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((999) : illu) ; var ans : OclAny := solve() ; execute (ans)->display(); operation findmax(begin : OclAny, end : OclAny) : OclAny pre: true post: true activity: var flag : OclAny := illu[begin+1] ; var l : int := 1 ; var maxlen : int := 1 ; for i : Integer.subrange(begin + 1, end + 1-1) do ( if illu[i+1] + flag = 1 then ( l := l + 1 ) else ( if (l->compareTo(maxlen)) > 0 then ( maxlen := l ) else skip ; l := 1 ) ; flag := illu[i+1]) ; return if (maxlen->compareTo(l)) > 0 then maxlen else l endif; operation find_alterseq() : OclAny pre: true post: true activity: var seq : Sequence := Sequence{} ; var s : OclAny := 0; var e : int := 0 ; flag := illu->first() ; for i : Integer.subrange(1, n + 1-1) do ( if illu[i+1] + flag /= 1 then ( execute ((Sequence{s}->union(Sequence{ i - 1 })) : seq) ; s := i ) else skip ; flag := illu[i+1]) ; return seq; operation reverse(s : OclAny, e : OclAny) pre: true post: true activity: for i : Integer.subrange(s, e + 1-1) do ( illu[i+1] := 1 - illu[i+1]); operation solve() : OclAny pre: true post: true activity: var alseq : OclAny := find_alterseq() ; maxlen := 0 ; alseq := alseq.insertAt(0+1, Sequence{0}->union(Sequence{ 0 })) ; execute ((Sequence{n}->union(Sequence{ n })) : alseq) ; var nindex : int := (alseq)->size() ; for i : Integer.subrange(1, nindex - 1-1) do ( Sequence{s,e} := alseq[i+1] ; begin := alseq[i - 1+1]->first() ; end := alseq[i + 1+1][1+1] ; if (end - begin + 1->compareTo(maxlen)) >= 0 then ( reverse(s, e) ; l := findmax(begin, end) ; if (l->compareTo(maxlen)) > 0 then ( maxlen := l ) else skip ; reverse(s, e) ) else skip) ; return maxlen; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=5 def diagonalsMinMax(mat): if(n==0): return principalMin=mat[0][0] principalMax=mat[0][0] secondaryMin=mat[n-1][0] secondaryMax=mat[n-1][0] for i in range(n): if(mat[i][i]principalMax): principalMax=mat[i][i] if(mat[n-1-i][i]secondaryMax): secondaryMax=mat[n-1-i][i] print("Principal Diagonal Smallest Element: ",principalMin) print("Principal Diagonal Greatest Element : ",principalMax) print("Secondary Diagonal Smallest Element: ",secondaryMin) print("Secondary Diagonal Greatest Element: ",secondaryMax) matrix=[[1,2,3,4,-10],[5,6,7,8,6],[1,2,11,3,4],[5,6,70,5,8],[4,9,7,1,-5]] diagonalsMinMax(matrix) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := 5 ; skip ; var matrix : Sequence := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ -10 }))))}->union(Sequence{Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 6 }))))}->union(Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{11}->union(Sequence{3}->union(Sequence{ 4 }))))}->union(Sequence{Sequence{5}->union(Sequence{6}->union(Sequence{70}->union(Sequence{5}->union(Sequence{ 8 }))))}->union(Sequence{ Sequence{4}->union(Sequence{9}->union(Sequence{7}->union(Sequence{1}->union(Sequence{ -5 })))) })))) ; diagonalsMinMax(matrix); operation diagonalsMinMax(mat : OclAny) pre: true post: true activity: if (n = 0) then ( return ) else skip ; var principalMin : OclAny := mat->first()->first() ; var principalMax : OclAny := mat->first()->first() ; var secondaryMin : OclAny := mat[n - 1+1]->first() ; var secondaryMax : OclAny := mat[n - 1+1]->first() ; for i : Integer.subrange(0, n-1) do ( if ((mat[i+1][i+1]->compareTo(principalMin)) < 0) then ( principalMin := mat[i+1][i+1] ) else skip ; if ((mat[i+1][i+1]->compareTo(principalMax)) > 0) then ( principalMax := mat[i+1][i+1] ) else skip ; if ((mat[n - 1 - i+1][i+1]->compareTo(secondaryMin)) < 0) then ( secondaryMin := mat[n - 1 - i+1][i+1] ) else skip ; if ((mat[n - 1 - i+1][i+1]->compareTo(secondaryMax)) > 0) then ( secondaryMax := mat[n - 1 - i+1][i+1] ) else skip) ; execute ("Principal Diagonal Smallest Element: ")->display() ; execute ("Principal Diagonal Greatest Element : ")->display() ; execute ("Secondary Diagonal Smallest Element: ")->display() ; execute ("Secondary Diagonal Greatest Element: ")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) *A,=map(int,input().split()) for i in range(N): A[i]^=i & 1 B=[] prev=A[0]; cnt=0 for i in range(N): if prev!=A[i]: B.append(cnt) cnt=1 else : cnt+=1 prev=A[i] B.append(cnt) if len(B)==1 : print(B[0]) elif len(B)==2 : print(B[0]+B[1]) else : print(max(B[i]+B[i+1]+B[i+2]for i in range(len(B)-2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (testlist_star_expr (star_expr * (expr (atom (name A)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name A)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, N-1) do ( A[i+1] := A[i+1] xor MathLib.bitwiseAnd(i, 1)) ; var B : Sequence := Sequence{} ; var prev : OclAny := A->first(); var cnt : int := 0 ; for i : Integer.subrange(0, N-1) do ( if prev /= A[i+1] then ( execute ((cnt) : B) ; cnt := 1 ) else ( cnt := cnt + 1 ) ; prev := A[i+1]) ; execute ((cnt) : B) ; if (B)->size() = 1 then ( execute (B->first())->display() ) else (if (B)->size() = 2 then ( execute (B->first() + B[1+1])->display() ) else ( execute (((argument (test (logical_test (comparison (expr (expr (expr (atom (name B)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name B)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])))) + (expr (atom (name B)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 2)))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name B)))))))) )))) - (expr (atom (number (integer 2)))))))))) )))))))))->max())->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) a=list(map(int,input().split())) dp=[[0]*3 for _ in[0]*N] dp[0]=[1,1,1] ans=0 for i,(n1,n2)in enumerate(zip(a,a[1 :]),start=1): if n1!=n2 : for j in range(3): dp[i][j]=dp[i-1][j]+1 else : dp[i][0]=1 if dp[i-1][2]>ans : ans=dp[i-1][2] for j in range(2,0,-1): dp[i][j]=dp[i-1][j-1]+1 print(max(max(dp[-1]),ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 3))) ; dp->first() := Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })) ; var ans : int := 0 ; for _tuple : Integer.subrange(1, (Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), a->tail()->at(_indx)} ), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), a->tail()->at(_indx)} ), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{n1, n2} : OclAny := _tuple->at(_indx); if n1 /= n2 then ( for j : Integer.subrange(0, 3-1) do ( dp[i+1][j+1] := dp[i - 1+1][j+1] + 1) ) else ( dp[i+1]->first() := 1 ; if (dp[i - 1+1][2+1]->compareTo(ans)) > 0 then ( ans := dp[i - 1+1][2+1] ) else skip ; for j : Integer.subrange(0 + 1, 2)->reverse() do ( dp[i+1][j+1] := dp[i - 1+1][j - 1+1] + 1) )) ; execute (Set{(dp->last())->max(), ans}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def hasEvenNumberOfFactors(n): root_n=math.sqrt(n) if((root_n*root_n)==n): return False return True def printStatusOfDoors(n): for i in range(1,n+1): if(hasEvenNumberOfFactors(i)==True): print("closed",end=" ") else : print("open",end=" ") n=5 printStatusOfDoors(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 5 ; printStatusOfDoors(n); operation hasEvenNumberOfFactors(n : OclAny) : OclAny pre: true post: true activity: var root_n : double := (n)->sqrt() ; if ((root_n * root_n) = n) then ( return false ) else skip ; return true; operation printStatusOfDoors(n : OclAny) pre: true post: true activity: for i : Integer.subrange(1, n + 1-1) do ( if (hasEvenNumberOfFactors(i) = true) then ( execute ("closed")->display() ) else ( execute ("open")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthTerm(n): if n<=1 : return 1 fact=1 for i in range(1,N): fact=fact*i return fact if __name__=="__main__" : N=3 print(nthTerm(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var N : int := 3 ; execute (nthTerm(N))->display() ) else skip; operation nthTerm(n : OclAny) : OclAny pre: true post: true activity: if n <= 1 then ( return 1 ) else skip ; var fact : int := 1 ; for i : Integer.subrange(1, N-1) do ( fact := fact * i) ; return fact; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_permutation(arr,n): arr=sorted(arr) result=0 for i in range(n): result+=abs(arr[i]-(i+1)) return result if __name__=='__main__' : arr=[0,2,3,4,1,6,8,9] n=len(arr) print(get_permutation(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{0}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{1}->union(Sequence{6}->union(Sequence{8}->union(Sequence{ 9 }))))))) ; n := (arr)->size() ; execute (get_permutation(arr, n))->display() ) else skip; operation get_permutation(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var result : int := 0 ; for i : Integer.subrange(0, n-1) do ( result := result + (arr[i+1] - (i + 1))->abs()) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def make_permutation(arr,n): arr.sort(); ans=0 ; for i in range(n): ans+=abs(i+1-arr[i]); return ans ; if __name__=="__main__" : arr=[5,3,8,1,1]; n=len(arr); print(make_permutation(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{5}->union(Sequence{3}->union(Sequence{8}->union(Sequence{1}->union(Sequence{ 1 })))); ; n := (arr)->size(); ; execute (make_permutation(arr, n))->display(); ) else skip; operation make_permutation(arr : OclAny, n : OclAny) pre: true post: true activity: arr := arr->sort(); ; var ans : int := 0; ; for i : Integer.subrange(0, n-1) do ( ans := ans + (i + 1 - arr[i+1])->abs();) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : N,M=map(int,raw_input().split()) if(N,M)==(0,0): break fert=[map(float,raw_input().split())for _ in range(N)] dp=[[0]*N for _ in range(M)] for i in range(N): dp[0][i]=1.0 for i in range(M-1): for j in range(N): dp[i+1][j]=max([dp[i][k]*fert[k][j]for k in range(N)]) print('{:.2f}'.format(max(dp[M-1]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if Sequence{N, M} = Sequence{0, 0} then ( break ) else skip ; var fert : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | ((raw_input().split())->collect( _x | (OclType["double"])->apply(_x) ))) ; var dp : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, N))) ; for i : Integer.subrange(0, N-1) do ( dp->first()[i+1] := 1.0) ; for i : Integer.subrange(0, M - 1-1) do ( for j : Integer.subrange(0, N-1) do ( dp[i + 1+1][j+1] := (Integer.subrange(0, N-1)->select(k | true)->collect(k | (dp[i+1][k+1] * fert[k+1][j+1])))->max())) ; execute (StringLib.interpolateStrings('{:.2f}', Sequence{(dp[M - 1+1])->max()}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import division,print_function try : input=raw_input range=xrange except NameError : pass def make_matrix(N,M,v): ret=[] for i in range(N): l=[] for j in range(M): l.append(v) ret.append(l) return ret def solve(n,m,g): current_max=make_matrix(m,n,-1) for i in range(n): current_max[0][i]=1.0 for i in range(1,m): for j in range(n): for k in range(n): current_max[i][j]=max(current_max[i][j],current_max[i-1][k]*g[k][j]) ret=max(current_max[m-1]) ret=round(ret,3) print("%.2f" % ret) def main(): while True : n,m=[int(i)for i in input().split(" ")] if n==0 and m==0 : return g=[] for i in range(n): g.append([float(x)for x in input().split(" ")]) solve(n,m,g) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; try ( var input : OclAny := raw_input ; var range : OclAny := xrange) (except_clause except (test (logical_test (comparison (expr (atom (name NameError)))))) : (suite (stmt (simple_stmt (small_stmt pass))))) ; skip ; skip ; skip ; main(); operation make_matrix(N : OclAny, M : OclAny, v : OclAny) : OclAny pre: true post: true activity: var ret : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var l : Sequence := Sequence{} ; for j : Integer.subrange(0, M-1) do ( execute ((v) : l)) ; execute ((l) : ret)) ; return ret; operation solve(n : OclAny, m : OclAny, g : OclAny) pre: true post: true activity: var current_max : OclAny := make_matrix(m, n, -1) ; for i : Integer.subrange(0, n-1) do ( current_max->first()[i+1] := 1.0) ; for i : Integer.subrange(1, m-1) do ( for j : Integer.subrange(0, n-1) do ( for k : Integer.subrange(0, n-1) do ( current_max[i+1][j+1] := Set{current_max[i+1][j+1], current_max[i - 1+1][k+1] * g[k+1][j+1]}->max()))) ; ret := (current_max[m - 1+1])->max() ; ret := MathLib.roundN(ret, 3) ; execute (StringLib.format("%.2f",ret))->display(); operation main() pre: true post: true activity: while true do ( Sequence{n,m} := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if n = 0 & m = 0 then ( return ) else skip ; g := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toReal()))) : g)) ; solve(n, m, g)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,*abc=[int(x)for x in input().split()] l=[int(input())for i in range(n)] A=0 ; B=1 ; C=2 ; minmp=10**9 for k in range(2**(2*n)): mat=[[],[],[],[]] for i in range(n): mat[(k>>2*i)&(0b11)].append(l[i]) if len(mat[0])==0 or len(mat[1])==0 or len(mat[2])==0 : continue mp=0 for j in range(3): mp+=10*(len(mat[j])-1) mp+=1*abs(abc[j]-sum(mat[j])) minmp=min(minmp,mp) print(minmp) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var abc : OclAny := null; Sequence{n,abc} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var l : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var A : int := 0; var B : int := 1; var C : int := 2; ; var minmp : double := (10)->pow(9) ; for k : Integer.subrange(0, (2)->pow((2 * n))-1) do ( var mat : Sequence := Sequence{Sequence{}}->union(Sequence{Sequence{}}->union(Sequence{Sequence{}}->union(Sequence{ Sequence{} }))) ; for i : Integer.subrange(0, n-1) do ((expr (atom (name mat)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name k))) >> (expr (expr (atom (number (integer 2)))) * (expr (atom (name i))))))))) ))) & (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0b11)))))))) ))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))) ; if (mat->first())->size() = 0 or (mat[1+1])->size() = 0 or (mat[2+1])->size() = 0 then ( continue ) else skip ; var mp : int := 0 ; for j : Integer.subrange(0, 3-1) do ( mp := mp + 10 * ((mat[j+1])->size() - 1) ; mp := mp + 1 * (abc[j+1] - (mat[j+1])->sum())->abs()) ; minmp := Set{minmp, mp}->min()) ; execute (minmp)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,m=list(map(int,input().split())) if n==0 : break d=[[0.0 for j in range(n)]for i in range(n)] for i in range(n): d[i]=list(map(float,input().split())) dp=[[0.0 for j in range(n)]for k in range(m)] for i in range(n): dp[0][i]=1 for k in range(1,m): for i in range(n): for j in range(n): dp[k][j]=max(dp[k][j],dp[k-1][i]*d[i][j]) ans=0 for i in range(n): if dp[m-1][i]>ans : ans=dp[m-1][i] print(format(ans,".2f")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = 0 then ( break ) else skip ; var d : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, n-1)->select(j | true)->collect(j | (0.0)))) ; for i : Integer.subrange(0, n-1) do ( d[i+1] := ((input().split())->collect( _x | (OclType["double"])->apply(_x) ))) ; var dp : Sequence := Integer.subrange(0, m-1)->select(k | true)->collect(k | (Integer.subrange(0, n-1)->select(j | true)->collect(j | (0.0)))) ; for i : Integer.subrange(0, n-1) do ( dp->first()[i+1] := 1) ; for k : Integer.subrange(1, m-1) do ( for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( dp[k+1][j+1] := Set{dp[k+1][j+1], dp[k - 1+1][i+1] * d[i+1][j+1]}->max()))) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (dp[m - 1+1][i+1]->compareTo(ans)) > 0 then ( ans := dp[m - 1+1][i+1] ) else skip) ; execute ((ans + ""))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def diagonalsMinMax(mat): n=len(mat) if(n==0): return principalMin=mat[0][0] principalMax=mat[0][0] secondaryMin=mat[n-1][0] secondaryMax=mat[n-1][0] for i in range(1,n): for j in range(1,n): if(i==j): if(mat[i][j]principalMax): principalMax=mat[i][j] if((i+j)==(n-1)): if(mat[i][j]secondaryMax): secondaryMax=mat[i][j] print("Principal Diagonal Smallest Element: ",principalMin) print("Principal Diagonal Greatest Element : ",principalMax) print("Secondary Diagonal Smallest Element: ",secondaryMin) print("Secondary Diagonal Greatest Element: ",secondaryMax) matrix=[[1,2,3,4,-10],[5,6,7,8,6],[1,2,11,3,4],[5,6,70,5,8],[4,9,7,1,-5]] diagonalsMinMax(matrix) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var matrix : Sequence := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ -10 }))))}->union(Sequence{Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 6 }))))}->union(Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{11}->union(Sequence{3}->union(Sequence{ 4 }))))}->union(Sequence{Sequence{5}->union(Sequence{6}->union(Sequence{70}->union(Sequence{5}->union(Sequence{ 8 }))))}->union(Sequence{ Sequence{4}->union(Sequence{9}->union(Sequence{7}->union(Sequence{1}->union(Sequence{ -5 })))) })))) ; diagonalsMinMax(matrix); operation diagonalsMinMax(mat : OclAny) pre: true post: true activity: var n : int := (mat)->size() ; if (n = 0) then ( return ) else skip ; var principalMin : OclAny := mat->first()->first() ; var principalMax : OclAny := mat->first()->first() ; var secondaryMin : OclAny := mat[n - 1+1]->first() ; var secondaryMax : OclAny := mat[n - 1+1]->first() ; for i : Integer.subrange(1, n-1) do ( for j : Integer.subrange(1, n-1) do ( if (i = j) then ( if ((mat[i+1][j+1]->compareTo(principalMin)) < 0) then ( principalMin := mat[i+1][j+1] ) else skip ; if ((mat[i+1][j+1]->compareTo(principalMax)) > 0) then ( principalMax := mat[i+1][j+1] ) else skip ) else skip ; if ((i + j) = (n - 1)) then ( if ((mat[i+1][j+1]->compareTo(secondaryMin)) < 0) then ( secondaryMin := mat[i+1][j+1] ) else skip ; if ((mat[i+1][j+1]->compareTo(secondaryMax)) > 0) then ( secondaryMax := mat[i+1][j+1] ) else skip ) else skip)) ; execute ("Principal Diagonal Smallest Element: ")->display() ; execute ("Principal Diagonal Greatest Element : ")->display() ; execute ("Secondary Diagonal Smallest Element: ")->display() ; execute ("Secondary Diagonal Greatest Element: ")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy from test.support import _MemoryWatchdog BIG_NUM=2000000000 HUGE_NUM=99999999999999999 MOD=10000 EPS=0.000000001 sys.setrecursionlimit(100000) while True : N,M=map(int,input().split()) if N==0 and M==0 : break table=[list(map(float,input().split()))for _ in range(N)] dp=[[0]*N for _ in range(M)] for i in range(N): dp[0][i]=1.0 for i in range(1,M): for k in range(N): for p in range(N): dp[i][p]=max(dp[i][p],dp[i-1][k]*table[k][p]) ans=0.0 for i in range(N): ans=max(ans,dp[M-1][i]) print("%.2f" %(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var HUGE_NUM : int := 99999999999999999 ; var MOD : int := 10000 ; var EPS : double := 0.000000001 ; sys.setrecursionlimit(100000) ; while true do ( var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if N = 0 & M = 0 then ( break ) else skip ; var table : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["double"])->apply(_x) )))) ; var dp : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, N))) ; for i : Integer.subrange(0, N-1) do ( dp->first()[i+1] := 1.0) ; for i : Integer.subrange(1, M-1) do ( for k : Integer.subrange(0, N-1) do ( for p : Integer.subrange(0, N-1) do ( dp[i+1][p+1] := Set{dp[i+1][p+1], dp[i - 1+1][k+1] * table[k+1][p+1]}->max()))) ; var ans : double := 0.0 ; for i : Integer.subrange(0, N-1) do ( ans := Set{ans, dp[M - 1+1][i+1]}->max()) ; execute (StringLib.format("%.2f",(ans)))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") while True : n,m=[int(_)for _ in input().split()] if n==m==0 : break rates=[[float(_)for _ in input().split()]for __ in range(n)] growth=[[0.]*n for _ in range(m)] for k in range(n): growth[0][k]=1. for day in range(1,m): for current in range(n): for previous in range(n): growth[day][current]=max(growth[day][current],growth[day-1][previous]*rates[previous][current]) print("%.2f" % max(growth[m-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; if n = m & (m == 0) then ( break ) else skip ; var rates : Sequence := Integer.subrange(0, n-1)->select(__ | true)->collect(__ | (input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toReal())))) ; var growth : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0. }, n))) ; for k : Integer.subrange(0, n-1) do ( growth->first()[k+1] := 1.) ; for day : Integer.subrange(1, m-1) do ( for current : Integer.subrange(0, n-1) do ( for previous : Integer.subrange(0, n-1) do ( growth[day+1][current+1] := Set{growth[day+1][current+1], growth[day - 1+1][previous+1] * rates[previous+1][current+1]}->max()))) ; execute (StringLib.format("%.2f",(growth[m - 1+1])->max()))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def checkPrime(numberToCheck): if numberToCheck==1 : return False for i in range(2,int(sqrt(numberToCheck))+1): if numberToCheck % i==0 : return False return True def primeSum(l,r): sum=0 for i in range(r,(l-1),-1): isPrime=checkPrime(i) if(isPrime): sum+=i return sum if __name__=="__main__" : l,r=4,13 print(primeSum(l,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( Sequence{l,r} := Sequence{4,13} ; execute (primeSum(l, r))->display() ) else skip; operation checkPrime(numberToCheck : OclAny) : OclAny pre: true post: true activity: if numberToCheck = 1 then ( return false ) else skip ; for i : Integer.subrange(2, ("" + ((sqrt(numberToCheck))))->toInteger() + 1-1) do ( if numberToCheck mod i = 0 then ( return false ) else skip) ; return true; operation primeSum(l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange((l - 1) + 1, r)->reverse() do ( var isPrime : OclAny := checkPrime(i) ; if (isPrime) then ( sum := sum + i ) else skip) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def isPrime(n): i=2 if(n==1): return False for i in range(2,mt.ceil(mt.sqrt(n))): if(n % i==0): return False return True def check_frequency(s): m=dict() for i in range(len(s)): if s[i]in m.keys(): m[s[i]]+=1 else : m[s[i]]=1 for ch in m : if m[ch]>0 and isPrime(m[ch])==False : return False return True s="geeksforgeeks" if(check_frequency(s)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; s := "geeksforgeeks" ; if (check_frequency(s)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isPrime(n : OclAny) : OclAny pre: true post: true activity: var i : int := 2 ; if (n = 1) then ( return false ) else skip ; for i : Integer.subrange(2, mt.ceil(mt.sqrt(n))-1) do ( if (n mod i = 0) then ( return false ) else skip) ; return true; operation check_frequency(s : OclAny) : OclAny pre: true post: true activity: var m : Map := (arguments ( )) ; for i : Integer.subrange(0, (s)->size()-1) do ( if (m.keys())->includes(s[i+1]) then ( m[s[i+1]+1] := m[s[i+1]+1] + 1 ) else ( m[s[i+1]+1] := 1 )) ; for ch : m->keys() do ( if m[ch+1] > 0 & isPrime(m[ch+1]) = false then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import reduce def factors(n): return set(reduce(list.__add__,([i,n//i]for i in range(1,int(n**0.5)+1)if n % i==0),)) def gcd(a,b): while b!=0 : a,b=b,a % b return a def solve(arr): op=0 sols=[] min_=min(arr) min_index=arr.index(min_) next_val=min_+1 for i in range(len(arr)): if i==min_index : next_val=min_+1 continue next_val=abs(i-min_index)+min_ sols.append([i+1,min_index+1,next_val,min_]) op+=1 arr[i]=next_val print(op) for sol in sols : sol=" ".join(list(map(str,sol))) print(sol) t=int(input()) for _ in range(t): arr_len=int(input()) arr=list(map(int,input().split())) solve(arr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var arr_len : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; arr := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; solve(arr)); operation factors(n : OclAny) : OclAny pre: true post: true activity: return Set{}->union((reduce(.__add__, (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) , (test (logical_test (comparison (expr (expr (atom (name n))) // (expr (atom (name i)))))))) ]))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) ** (expr (atom (number 0.5))))))))) )))) + (expr (atom (number (integer 1)))))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (expr (atom (name n))) % (expr (atom (name i))))) == (comparison (expr (atom (number (integer 0))))))))))) ))))))) ,)))); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: while b /= 0 do ( Sequence{a,b} := Sequence{b,a mod b}) ; return a; operation solve(arr : OclAny) pre: true post: true activity: var op : int := 0 ; var sols : Sequence := Sequence{} ; var min_ : OclAny := (arr)->min() ; var min_index : int := arr->indexOf(min_) - 1 ; var next_val : OclAny := min_ + 1 ; for i : Integer.subrange(0, (arr)->size()-1) do ( if i = min_index then ( next_val := min_ + 1 ; continue ) else skip ; next_val := (i - min_index)->abs() + min_ ; execute ((Sequence{i + 1}->union(Sequence{min_index + 1}->union(Sequence{next_val}->union(Sequence{ min_ })))) : sols) ; op := op + 1 ; arr[i+1] := next_val) ; execute (op)->display() ; for sol : sols do ( var sol : String := StringLib.sumStringsWithSeparator((((sol)->collect( _x | (OclType["String"])->apply(_x) ))), " ") ; execute (sol)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if b==0 : return a return gcd(b,a % b) ans=[] for _ in range(int(input())): n=int(input()) u=list(map(int,input().split())) cur=[] for i in range(1,n,2): cur.append(str(i)+' '+str(i+1)+' '+str(min(u[i-1],u[i]))+' '+str(10**9+7)) ans.append(str(len(cur))) ans+=cur print('\n'.join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var u : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cur : Sequence := Sequence{} ; for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( execute ((("" + ((i))) + ' ' + ("" + ((i + 1))) + ' ' + ("" + ((Set{u[i - 1+1], u[i+1]}->min()))) + ' ' + ("" + (((10)->pow(9) + 7)))) : cur)) ; execute ((("" + (((cur)->size())))) : ans) ; ans := ans + cur) ; execute (StringLib.sumStringsWithSeparator((ans), ' '))->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if b = 0 then ( return a ) else skip ; return gcd(b, a mod b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,a=int(input()),[int(x)for x in input().split()] y=a.index(min(a)) if n==1 : print(0,'\n') else : print(n if y else n-1) for j in range(y): print(j+1,y+1,a[y]+j,a[y]) for j in range(y+1,n): print(j+1,y+1,a[y]+j,a[y]) if y : print(1,y+1,a[y],a[y]+y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))} ; var y : int := a->indexOf((a)->min()) - 1 ; if n = 1 then ( execute (0)->display() ) else ( execute (if y then n else n - 1 endif)->display() ; for j : Integer.subrange(0, y-1) do ( execute (j + 1)->display()) ; for j : Integer.subrange(y + 1, n-1) do ( execute (j + 1)->display()) ; if y then ( execute (1)->display() ) else skip )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) b=min(a) c=b+1 d=0 i=2 while(True): if(gcd(b,b+i)==1): d=b+i break else : i+=1 x=a.index(b) print(n-1) for i in range(n): if(i==x): continue if(i % 2==0): print(i+1,x+1,c,b) else : print(i+1,x+1,d,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : OclAny := (a)->min() ; var c : OclAny := b + 1 ; var d : int := 0 ; var i : int := 2 ; while (true) do ( if (gcd(b, b + i) = 1) then ( d := b + i ; break ) else ( i := i + 1 )) ; var x : int := a->indexOf(b) - 1 ; execute (n - 1)->display() ; for i : Integer.subrange(0, n-1) do ( if (i = x) then ( continue ) else skip ; if (i mod 2 = 0) then ( execute (i + 1)->display() ) else ( execute (i + 1)->display() ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) l=[int(i)for i in input().split()] mini,miniidx=l[0],0 for i in range(len(l)): if(mini>l[i]): miniidx=i mini=l[i] if miniidx==0 : print(n-1) else : print(n) if miniidx!=0 : print(1,miniidx+1,mini,mini+1) for i in range(len(l)-1): print(1,i+2,mini,mini+i+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var mini : OclAny := null; var miniidx : OclAny := null; Sequence{mini,miniidx} := Sequence{l->first(),0} ; for i : Integer.subrange(0, (l)->size()-1) do ( if ((mini->compareTo(l[i+1])) > 0) then ( var miniidx : OclAny := i ; var mini : OclAny := l[i+1] ) else skip) ; if miniidx = 0 then ( execute (n - 1)->display() ) else ( execute (n)->display() ) ; if miniidx /= 0 then ( execute (1)->display() ) else skip ; for i : Integer.subrange(0, (l)->size() - 1-1) do ( execute (1)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def abc119_c(): n,a,b,c=map(int,input().split()) L=[int(input())for _ in range(n)] ans=10**9 def dfs(arr): if len(arr)==n : if arr.count(1)>0 and arr.count(2)>0 and arr.count(3)>0 : calc_score(arr) return for i in range(4): dfs(arr+[i]) def calc_score(arr): nonlocal ans tools_a=[L[i]for i in range(n)if arr[i]==1] tools_b=[L[i]for i in range(n)if arr[i]==2] tools_c=[L[i]for i in range(n)if arr[i]==3] score=magic(tools_a,a) score+=magic(tools_b,b) score+=magic(tools_c,c) ans=min(score,ans) def magic(tools,target): pt=abs(target-sum(tools)) if len(tools)>=2 : pt+=10*(len(tools)-1) return pt dfs([]) print(ans) abc119_c() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute ans : OclAny; operation initialise() pre: true post: true activity: skip ; abc119_c(); operation abc119_c() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{n,a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var L : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var ans : double := (10)->pow(9) ; skip ; skip ; skip ; dfs(Sequence{}) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lst=list(map(int,input().split())) k=-1 for i in range(n): for j in range(i+1,n): if(lst[i]+lst[j]in lst): k=lst.index(lst[i]+lst[j])+1 print(k,i+1,j+1) break if(k!=-1): break if(k==-1): print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k : int := -1 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if ((lst)->includes(lst[i+1] + lst[j+1])) then ( k := lst->indexOf(lst[i+1] + lst[j+1]) - 1 + 1 ; execute (k)->display() ; break ) else skip) ; if (k /= -1) then ( break ) else skip) ; if (k = -1) then ( execute (k)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(curr): a,b=curr a,b=min(a,b),max(a,b) if a==0 : return 0 if b % 2==0 : b-=1 if a>b : return 1 else : return 0 def process(A): n=len(A) curr=[0,0] maxes=[0,[]] for i in range(n): if i+1A[i+1]: curr[1]+=1 if(i+2A[i+1]maxes[0]: maxes=[max(curr),[]] if max(curr)==maxes[0]: maxes[1].append(curr) curr=[0,0] if len(maxes[1])>1 : return 0 return check(maxes[1][0]) n=int(input()) A=[int(x)for x in input().split()] print(process(A)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; A := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (process(A))->display(); operation check(curr : OclAny) : OclAny pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := curr ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{Set{a, b}->min(),Set{a, b}->max()} ; if a = 0 then ( return 0 ) else skip ; if b mod 2 = 0 then ( b := b - 1 ) else skip ; if (a->compareTo(b)) > 0 then ( return 1 ) else ( return 0 ); operation process(A : OclAny) : OclAny pre: true post: true activity: var n : int := (A)->size() ; curr := Sequence{0}->union(Sequence{ 0 }) ; var maxes : Sequence := Sequence{0}->union(Sequence{ Sequence{} }) ; for i : Integer.subrange(0, n-1) do ( if (i + 1->compareTo(n)) < 0 & (A[i+1]->compareTo(A[i + 1+1])) < 0 then ( curr->first() := curr->first() + 1 ) else skip ; if (i + 1->compareTo(n)) < 0 & (A[i+1]->compareTo(A[i + 1+1])) > 0 then ( curr[1+1] := curr[1+1] + 1 ) else skip ; if ((i + 2->compareTo(n)) < 0 & ((A[i+1]->compareTo(A[i + 1+1])) > 0 & (A[i + 1+1] < A[i + 2+1]))) or (i = n - 1) then ( if ((curr)->max()->compareTo(maxes->first())) > 0 then ( maxes := Sequence{(curr)->max()}->union(Sequence{ Sequence{} }) ) else skip ; if (curr)->max() = maxes->first() then ( (expr (atom (name maxes)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name curr)))))))) )))) ) else skip ; curr := Sequence{0}->union(Sequence{ 0 }) ) else skip) ; if (maxes[1+1])->size() > 1 then ( return 0 ) else skip ; return check(maxes[1+1]->first()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.readline().rstrip() n=int(input()) p=list(map(int,input().split())) a=[0]*n b=[0]*n for i in range(n-1): if p[i]p[i]: b[i-1]=b[i]+1 x=max(max(a),max(b)) k=sum(x==i or x==j for i,j in zip(a,b)) s=sum(x==i and x==j for i,j in zip(a,b)) if k>1 or s==0 or x % 2 : print(0) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n - 1-1) do ( if (p[i+1]->compareTo(p[i + 1+1])) < 0 then ( a[i + 1+1] := a[i+1] + 1 ) else skip) ; for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( if (p[i - 1+1]->compareTo(p[i+1])) > 0 then ( b[i - 1+1] := b[i+1] + 1 ) else skip) ; var x : OclAny := Set{(a)->max(), (b)->max()}->max() ; var k : OclAny := ((argument (test (logical_test (logical_test (comparison (comparison (expr (atom (name x)))) == (comparison (expr (atom (name i)))))) or (logical_test (comparison (comparison (expr (atom (name x)))) == (comparison (expr (atom (name j)))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))))))))->sum() ; var s : OclAny := ((argument (test (logical_test (logical_test (comparison (comparison (expr (atom (name x)))) == (comparison (expr (atom (name i)))))) and (logical_test (comparison (comparison (expr (atom (name x)))) == (comparison (expr (atom (name j)))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))))))))->sum() ; if k > 1 or s = 0 or x mod 2 then ( execute (0)->display() ) else ( execute (1)->display() ); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.readline().rstrip() n=int(input()) p=list(map(int,input().split())) a=[0]*n b=[0]*n for i in range(n-1): if p[i]p[i]: b[i-1]=b[i]+1 x=max(max(a),max(b)) k=sum(x==i or x==j for i,j in zip(a,b)) s=sum(x==i and x==j for i,j in zip(a,b)) if k>1 or s==0 or x % 2 : print(0) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n - 1-1) do ( if (p[i+1]->compareTo(p[i + 1+1])) < 0 then ( a[i + 1+1] := a[i+1] + 1 ) else skip) ; for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( if (p[i - 1+1]->compareTo(p[i+1])) > 0 then ( b[i - 1+1] := b[i+1] + 1 ) else skip) ; var x : OclAny := Set{(a)->max(), (b)->max()}->max() ; var k : OclAny := ((argument (test (logical_test (logical_test (comparison (comparison (expr (atom (name x)))) == (comparison (expr (atom (name i)))))) or (logical_test (comparison (comparison (expr (atom (name x)))) == (comparison (expr (atom (name j)))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))))))))->sum() ; var s : OclAny := ((argument (test (logical_test (logical_test (comparison (comparison (expr (atom (name x)))) == (comparison (expr (atom (name i)))))) and (logical_test (comparison (comparison (expr (atom (name x)))) == (comparison (expr (atom (name j)))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))))))))->sum() ; if k > 1 or s = 0 or x mod 2 then ( execute (0)->display() ) else ( execute (1)->display() ); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) a=list(map(int,input().split())) x=[] if a[0]a[1]else-1 u=0 for i in range(n-1): if c*(a[i]-a[i+1])>0 : u+=1 else : x.append(u) u=1 c*=-1 x.append(u) x.append(0) l,r=list(x),list(x) for i in range(1,len(x)): l[i]=max(l[i],l[i-1]) for i in range(len(x)-2,-1,-1): r[i]=max(r[i],r[i+1]) m=(len(x)-2)//2 ans=0 for i in range(m): u,v=x[2*i+1],x[2*i+2] if u ^ v or u % 2 : continue if u>max(l[2*i],r[2*i+3]): ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : Sequence := Sequence{} ; if (a->first()->compareTo(a[1+1])) < 0 then ( execute ((0) : x) ) else skip ; var c : int := if (a->first()->compareTo(a[1+1])) > 0 then 1 else -1 endif ; var u : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if c * (a[i+1] - a[i + 1+1]) > 0 then ( u := u + 1 ) else ( execute ((u) : x) ; u := 1 ; c := c * -1 )) ; execute ((u) : x) ; execute ((0) : x) ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{(x),(x)} ; for i : Integer.subrange(1, (x)->size()-1) do ( l[i+1] := Set{l[i+1], l[i - 1+1]}->max()) ; for i : Integer.subrange(-1 + 1, (x)->size() - 2)->reverse() do ( r[i+1] := Set{r[i+1], r[i + 1+1]}->max()) ; var m : int := ((x)->size() - 2) div 2 ; var ans : int := 0 ; for i : Integer.subrange(0, m-1) do ( var v : OclAny := null; Sequence{u,v} := Sequence{x[2 * i + 1+1],x[2 * i + 2+1]} ; if MathLib.bitwiseXor(u, v) or u mod 2 then ( continue ) else skip ; if (u->compareTo(Set{l[2 * i+1], r[2 * i + 3+1]}->max())) > 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def performQueryOne(num): s.add(num) def performQueryTwo(num): s.remove(num) def performQueryThree(): mini=min(s) maxi=max(s) return maxi-mini if __name__=="__main__" : s=set() num=3 performQueryOne(num) num=5 performQueryOne(num) num=6 performQueryOne(num) num=5 performQueryTwo(num) num=2 performQueryOne(num) print(performQueryThree()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( var s : Set := Set{}->union(()) ; num := 3 ; performQueryOne(num) ; num := 5 ; performQueryOne(num) ; num := 6 ; performQueryOne(num) ; num := 5 ; performQueryTwo(num) ; num := 2 ; performQueryOne(num) ; execute (performQueryThree())->display() ) else skip; operation performQueryOne(num : OclAny) pre: true post: true activity: execute ((num) : s); operation performQueryTwo(num : OclAny) pre: true post: true activity: execute ((num) /: s); operation performQueryThree() : OclAny pre: true post: true activity: var mini : OclAny := (s)->min() ; var maxi : OclAny := (s)->max() ; return maxi - mini; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findGreater(x,y): if(x>y): return False ; else : return True ; x=4 ; y=9 ; if(findGreater(x,y)): print("1"); else : print("2"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := 4; ; y := 9; ; if (findGreater(x, y)) then ( execute ("1")->display(); ) else ( execute ("2")->display(); ); operation findGreater(x : OclAny, y : OclAny) pre: true post: true activity: if ((x->compareTo(y)) > 0) then ( return false; ) else ( return true; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def coprime(a,b): return 1 if(math.gcd(a,b)==1)else 0 ; def pairSum(n): mid=int(n/2); i=mid ; while(i>=1): if(coprime(i,n-i)==1): print(i,n-i); break ; i=i-1 ; n=11 ; pairSum(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 11; ; pairSum(n);; operation coprime(a : OclAny, b : OclAny) pre: true post: true activity: return if ((a)->gcd(b) = 1) then 1 else 0 endif;; operation pairSum(n : OclAny) pre: true post: true activity: var mid : int := ("" + ((n / 2)))->toInteger(); ; var i : int := mid; ; while (i >= 1) do ( if (coprime(i, n - i) = 1) then ( execute (i)->display(); ; break; ) else skip ; i := i - 1;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(arr,n): arr.sort() a=0 ; b=0 for i in range(n): if(i % 2!=0): a=a*10+arr[i] else : b=b*10+arr[i] return a+b arr=[6,8,4,5,2,3] n=len(arr) print("Sum is ",solve(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{6}->union(Sequence{8}->union(Sequence{4}->union(Sequence{5}->union(Sequence{2}->union(Sequence{ 3 }))))) ; n := (arr)->size() ; execute ("Sum is ")->display(); operation solve(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var a : int := 0; var b : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (i mod 2 /= 0) then ( a := a * 10 + arr[i+1] ) else ( b := b * 10 + arr[i+1] )) ; return a + b; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def is_prime(n): return n>1 and all(n % d for d in range(2,int(math.sqrt(n))+1)) def NextprimePalindrome(N): for k in range(1,10**6): s=str(k) x=int(s+s[-2 : :-1]) if x>=N and is_prime(x): return x s=str(k) x=int(s+s[-1 : :-1]) if x>=N and is_prime(x): return x N=7000000000 print(NextprimePalindrome(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; N := 7000000000 ; execute (NextprimePalindrome(N))->display(); operation is_prime(n : OclAny) : OclAny pre: true post: true activity: return n > 1 & ((argument (test (logical_test (comparison (expr (expr (atom (name n))) % (expr (atom (name d))))))) (comp_for for (exprlist (expr (atom (name d)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name math)) (trailer . (name sqrt) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))) )))) + (expr (atom (number (integer 1)))))))))) )))))))))->forAll( _x | _x = true ); operation NextprimePalindrome(N : OclAny) : OclAny pre: true post: true activity: for k : Integer.subrange(1, (10)->pow(6)-1) do ( var s : String := ("" + ((k))) ; var x : int := ("" + ((s + s(subscript (test (logical_test (comparison (expr (atom - (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))))->toInteger() ; if (x->compareTo(N)) >= 0 & is_prime(x) then ( return x ) else skip ; s := ("" + ((k))) ; x := ("" + ((s + s(subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))))->toInteger() ; if (x->compareTo(N)) >= 0 & is_prime(x) then ( return x ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect as upper_bound maxLen=30 def findCnt(arr,n,k): ans=0 for i in range(1,n): arr[i]+=arr[i-1] if(arr[i]>k or arr[i]<-1*k): ans+=1 if(arr[0]>k or arr[0]<-1*k): ans+=1 arr=sorted(arr) for i in range(n): ans+=n-upper_bound(arr,arr[i]+k) return ans arr=[-1,4,-5,6] n=len(arr) k=0 print(findCnt(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var maxLen : int := 30 ; skip ; arr := Sequence{-1}->union(Sequence{4}->union(Sequence{-5}->union(Sequence{ 6 }))) ; n := (arr)->size() ; k := 0 ; execute (findCnt(arr, n, k))->display(); operation findCnt(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(1, n-1) do ( arr[i+1] := arr[i+1] + arr[i - 1+1] ; if ((arr[i+1]->compareTo(k)) > 0 or (arr[i+1]->compareTo(-1 * k)) < 0) then ( ans := ans + 1 ) else skip) ; if ((arr->first()->compareTo(k)) > 0 or (arr->first()->compareTo(-1 * k)) < 0) then ( ans := ans + 1 ) else skip ; arr := arr->sort() ; for i : Integer.subrange(0, n-1) do ( ans := ans + n - upper_bound(arr, arr[i+1] + k)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) arr=[int(i)for i in input().split()] for i in range(len(arr)): for j in range(len(arr)): if i==j : continue for k in range(len(arr)): if arr[k]!=arr[j]and arr[k]!=arr[i]and arr[k]==arr[j]+arr[i]: print(k+1,j+1,i+1) exit() print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; for i : Integer.subrange(0, (arr)->size()-1) do ( for j : Integer.subrange(0, (arr)->size()-1) do ( if i = j then ( continue ) else skip ; for k : Integer.subrange(0, (arr)->size()-1) do ( if arr[k+1] /= arr[j+1] & arr[k+1] /= arr[i+1] & arr[k+1] = arr[j+1] + arr[i+1] then ( execute (k + 1)->display() ; exit() ) else skip))) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countUnsetBits(n): cnt=0 ; for i in range(1,n+1): temp=i ; while(temp): if(temp % 2==0): cnt+=1 ; temp=temp//2 ; return cnt ; if __name__=="__main__" : n=5 ; print(countUnsetBits(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 5; ; execute (countUnsetBits(n))->display(); ) else skip; operation countUnsetBits(n : OclAny) pre: true post: true activity: var cnt : int := 0; ; for i : Integer.subrange(1, n + 1-1) do ( var temp : OclAny := i; ; while (temp) do ( if (temp mod 2 = 0) then ( cnt := cnt + 1; ) else skip ; temp := temp div 2;)) ; return cnt;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- with open("input.txt","r")as i,open("output.txt","w")as o : l=[0]*3 n=int(i.readline().strip()) l[n-1]=1 for x in range(3): a,b=map(int,i.readline().strip().split()) l[a-1],l[b-1]=l[b-1],l[a-1] o.write(str(l.index(1)+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: try (var i : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")); var o : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")); var l : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 3) ; var n : int := ("" + ((i.readLine()->trim())))->toInteger() ; l[n - 1+1] := 1 ; for x : Integer.subrange(0, 3-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (i.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l[a - 1+1] : OclAny := null; var l[b - 1+1] : OclAny := null; Sequence{l[a - 1+1],l[b - 1+1]} := Sequence{l[b - 1+1],l[a - 1+1]}) ; o.write(("" + ((l->indexOf(1) - 1 + 1))))) catch (_e : OclException) do skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.stdin=open("input.txt","r") sys.stdout=open("output.txt","w") jav=int(input()) for i in range(3): ar=list(map(int,input().split())) if jav in ar : if ar[0]==jav : jav=ar[1] else : jav=ar[0] print(jav) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ; var jav : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, 3-1) do ( var ar : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (ar)->includes(jav) then ( if ar->first() = jav then ( jav := ar[1+1] ) else ( jav := ar->first() ) ) else skip) ; execute (jav)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() import sys sys.stdin=open("input.txt","r") sys.stdout=open("output.txt","w") n=input() for _ in range(3): a,b=input().split() if a==n : n=b elif b==n : n=a print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; skip ; OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ; var n : String := (OclFile["System.in"]).readLine() ; for _anon : Integer.subrange(0, 3-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; if a = n then ( n := b ) else (if b = n then ( n := a ) else skip)) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- rFile=open("input.txt",'r') pos=int(rFile.readline()) for i in range(3): cup1,cup2=[int(item)for item in rFile.readline().split(' ')] if pos==cup1 : pos=cup2 elif pos==cup2 : pos=cup1 rFile.close() wFile=open("output.txt",'w') wFile.write(str(pos)) wFile.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var rFile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ; var pos : int := ("" + ((rFile.readLine())))->toInteger() ; for i : Integer.subrange(0, 3-1) do ( var cup1 : OclAny := null; var cup2 : OclAny := null; Sequence{cup1,cup2} := rFile.readLine().split(' ')->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; if pos = cup1 then ( pos := cup2 ) else (if pos = cup2 then ( pos := cup1 ) else skip)) ; rFile.closeFile() ; var wFile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ; wFile.write(("" + ((pos)))) ; wFile.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.stdin=open("input.txt","r") sys.stdout=open("output.txt","w") x=int(input()) for i in range(3): a,b=map(int,input().split()) if x==a : x=b elif x==b : x=a print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, 3-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x = a then ( x := b ) else (if x = b then ( x := a ) else skip)) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def arraySortedOrNot(arr): n=len(arr) if n==1 or n==0 : return True return arr[0]<=arr[1]and arraySortedOrNot(arr[1 :]) arr=[20,23,23,45,78,88] if arraySortedOrNot(arr): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{20}->union(Sequence{23}->union(Sequence{23}->union(Sequence{45}->union(Sequence{78}->union(Sequence{ 88 }))))) ; if arraySortedOrNot(arr) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation arraySortedOrNot(arr : OclAny) : OclAny pre: true post: true activity: var n : int := (arr)->size() ; if n = 1 or n = 0 then ( return true ) else skip ; return (arr->first()->compareTo(arr[1+1])) <= 0 & arraySortedOrNot(arr->tail()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=str(input()) k=0 for i in n : if(i=="H" or i=="Q" or i=="9"): k=1 if(k>0): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := ("" + (((OclFile["System.in"]).readLine()))) ; var k : int := 0 ; for i : n->characters() do ( if (i = "H" or i = "Q" or i = "9") then ( k := 1 ) else skip) ; if (k > 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=str(input()) if('H' in s)or('Q' in s)or('9' in s): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; if ((s)->characters()->includes('H')) or ((s)->characters()->includes('Q')) or ((s)->characters()->includes('9')) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): syntax=['Q','H','9'] inp=input() count=0 for letter in inp : if letter in syntax : count+=1 if count>0 : print('YES') else : print('NO') main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var syntax : Sequence := Sequence{'Q'}->union(Sequence{'H'}->union(Sequence{ '9' })) ; var inp : String := (OclFile["System.in"]).readLine() ; var count : int := 0 ; for letter : inp->characters() do ( if (syntax)->includes(letter) then ( count := count + 1 ) else skip) ; if count > 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=[int(i)for i in input().split()] a=[int(i)for i in input().split()] num=0 for i in range(1,len(a)): if a[i]select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var num : int := 0 ; for i : Integer.subrange(1, (a)->size()-1) do ( if (a[i+1]->compareTo(a[i - 1+1])) < 0 then ( num := num + (a[i - 1+1] - a[i+1]) div d + 1 ; a[i+1] := a[i+1] + d * ((a[i - 1+1] - a[i+1]) div d + 1) ) else (if a[i+1] = a[i - 1+1] then ( a[i+1] := a[i+1] + d ; num := num + 1 ) else skip)) ; execute (num)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() k=0 for c in s : if c=='H' : k=1 print('YES') break elif c=='Q' : k=1 print('YES') break elif c=='9' : k=1 print('YES') break if k==0 : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var k : int := 0 ; for c : s->characters() do ( if c = 'H' then ( k := 1 ; execute ('YES')->display() ; break ) else (if c = 'Q' then ( k := 1 ; execute ('YES')->display() ; break ) else (if c = '9' then ( k := 1 ; execute ('YES')->display() ; break ) else skip ) ) ) ; if k = 0 then ( execute ('NO')->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools def compute(): MOD=10**9 a=0 b=1 for i in itertools.count(): if "".join(sorted(str(a)))=="123456789" : f=fibonacci(i)[0] if "".join(sorted(str(f)[: 9]))=="123456789" : return str(i) a,b=b,(a+b)% MOD return str(ans) def fibonacci(n): if n==0 : return(0,1) else : a,b=fibonacci(n//2) c=a*(b*2-a) d=a*a+b*b if n % 2==0 : return(c,d) else : return(d,c+d) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var MOD : double := (10)->pow(9) ; var a : int := 0 ; var b : int := 1 ; for i : itertools->count() do ( if StringLib.sumStringsWithSeparator((("" + ((a)))->sort()), "") = "123456789" then ( var f : OclAny := fibonacci(i)->first() ; if StringLib.sumStringsWithSeparator((OclType["String"](f).subrange(1,9)->sort()), "") = "123456789" then ( return ("" + ((i))) ) else skip ) else skip ; Sequence{a,b} := Sequence{b,(a + b) mod MOD}) ; return ("" + ((ans))); operation fibonacci(n : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( return Sequence{0, 1} ) else ( Sequence{a,b} := fibonacci(n div 2) ; var c : double := a * (b * 2 - a) ; var d : int := a * a + b * b ; if n mod 2 = 0 then ( return Sequence{c, d} ) else ( return Sequence{d, c + d} ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : str=str(input()) if str.find("H")+1 or str.find("Q")+1 or str.find("9")+1 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var OclType["String"] : String := ("" + (((OclFile["System.in"]).readLine()))) ; if ("" + (->indexOf("H") - 1)) + 1 or ("" + (->indexOf("Q") - 1)) + 1 or ("" + (->indexOf("9") - 1)) + 1 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- FILE_NAME_BASE='A-large' NUM_PROCESSES=0 MEM_LIMIT_GB=1.5 RECURSION_LIMIT=1000 def parse(inp): start,num=(int(x)for x in inp.readline().split()) motes=tuple(int(x)for x in inp.readline().split()) assert len(motes)==num return start,motes def solve(start,motes): motes=sorted(motes) num=len(motes) best=num size=start added=0 i=0 while i=0 : size+=size-1 added+=1 else : best=min(best,added) return best def main(): import sys sys.setrecursionlimit(RECURSION_LIMIT) import resource soft,hard=resource.getrlimit(resource.RLIMIT_AS) resource.setrlimit(resource.RLIMIT_AS,(MEM_LIMIT_GB*1024**3,hard)) inp=open(FILE_NAME_BASE+'.in','r') numCases=int(inp.readline()) if NUM_PROCESSES==0 : results=[solve(*parse(inp))for _ in range(numCases)] else : from multiprocessing import Pool pool=Pool(NUM_PROCESSES) results=[pool.apply_async(solve,parse(inp))for _ in range(numCases)] inp.close() out=open(FILE_NAME_BASE+'.out','w') for case,result in enumerate(results): value=result if NUM_PROCESSES==0 else result.get() out.write('Case #%d: %s\n' %(case+1,value)) out.flush() out.close() if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var FILE_NAME_BASE : String := 'A-large' ; var NUM_PROCESSES : int := 0 ; var MEM_LIMIT_GB : double := 1.5 ; var RECURSION_LIMIT : int := 1000 ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation parse(inp : OclAny) : OclAny pre: true post: true activity: var start : OclAny := null; var num : OclAny := null; Sequence{start,num} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name inp)) (trailer . (name readline) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var motes : Sequence := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name inp)) (trailer . (name readline) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ; assert (motes)->size() = num do "assertion failed" ; return start, motes; operation solve(start : OclAny, motes : OclAny) : OclAny pre: true post: true activity: motes := motes->sort() ; var num : int := (motes)->size() ; var best : int := num ; var size : OclAny := start ; var added : int := 0 ; var i : int := 0 ; (compound_stmt while (test (logical_test (comparison (comparison (expr (atom (name i)))) < (comparison (expr (atom (name num))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name motes)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) < (comparison (expr (atom (name size))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name size)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name motes)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name best)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name best))))))) , (argument (test (logical_test (comparison (expr (expr (expr (atom (name added))) + (expr (atom (name num)))) - (expr (atom (name i))))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name size)))) <= (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt break)))) (else_clause else : (suite (stmt (compound_stmt while (test (logical_test (comparison (comparison (expr (expr (atom (name motes)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name size))))) >= (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name size)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name size))) - (expr (atom (number (integer 1))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name added)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name best)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name best))))))) , (argument (test (logical_test (comparison (expr (atom (name added)))))))) )))))))))))))))) ; return best; operation main() pre: true post: true activity: skip ; sys.setrecursionlimit(RECURSION_LIMIT) ; skip ; var soft : OclAny := null; var hard : OclAny := null; Sequence{soft,hard} := resource.getrlimit(resource.RLIMIT_AS) ; resource.setrlimit(resource.RLIMIT_AS, Sequence{MEM_LIMIT_GB * (1024)->pow(3), hard}) ; inp := OclFile.newOclFile_Write(OclFile.newOclFile(FILE_NAME_BASE + '.in')) ; var numCases : int := ("" + ((inp.readLine())))->toInteger() ; if NUM_PROCESSES = 0 then ( var results : Sequence := Integer.subrange(0, numCases-1)->select(_anon | true)->collect(_anon | (solve((argument * (test (logical_test (comparison (expr (atom (name parse)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name inp)))))))) ))))))))))) ) else ( skip ; var pool : OclAny := Pool(NUM_PROCESSES) ; results := Integer.subrange(0, numCases-1)->select(_anon | true)->collect(_anon | (pool.apply_async(solve, parse(inp)))) ) ; inp.closeFile() ; var out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(FILE_NAME_BASE + '.out')) ; for _tuple : Integer.subrange(1, (results)->size())->collect( _indx | Sequence{_indx-1, (results)->at(_indx)} ) do (var _indx : int := 1; var case : OclAny := _tuple->at(_indx); _indx := _indx + 1; var result : OclAny := _tuple->at(_indx); var value : OclAny := if NUM_PROCESSES = 0 then result else result.get() endif ; out.write(StringLib.format('Case #%d: %s ',Sequence{case + 1, value})) ; out.flush()) ; out.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys fin=sys.stdin T=int(fin.readline()) for case in range(1,T+1): A,N=map(int,fin.readline().split()) motes=list(map(int,fin.readline().split())) limit=len(motes) limit1=limit+1 motes.sort() last=[0]*limit1 last[0]=A for mote in motes : current=[0]*limit1 for used,size in enumerate(last): newsize=size for moves in range(used,limit1): if newsize>mote : current[moves]=max(current[moves],newsize+mote) newsize=newsize*2-1 if used0 : best=used break print("Case #%d: %s" %(case,best)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var fin : OclFile := OclFile["System.in"] ; var T : int := ("" + ((fin.readLine())))->toInteger() ; for case : Integer.subrange(1, T + 1-1) do ( var A : OclAny := null; var N : OclAny := null; Sequence{A,N} := (fin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var motes : Sequence := ((fin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var limit : int := (motes)->size() ; var limit1 : int := limit + 1 ; motes := motes->sort() ; var last : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, limit1) ; last->first() := A ; for mote : motes do ( var current : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, limit1) ; for _tuple : Integer.subrange(1, (last)->size())->collect( _indx | Sequence{_indx-1, (last)->at(_indx)} ) do (var _indx : int := 1; var used : OclAny := _tuple->at(_indx); _indx := _indx + 1; var size : OclAny := _tuple->at(_indx); var newsize : OclAny := size ; for moves : Integer.subrange(used, limit1-1) do ( if (newsize->compareTo(mote)) > 0 then ( current[moves+1] := Set{current[moves+1], newsize + mote}->max() ) else skip ; newsize := newsize * 2 - 1) ; if (used->compareTo(limit)) < 0 then ( current[used + 1+1] := Set{current[used + 1+1], size}->max() ) else skip) ; last := current) ; var best : OclAny := null ; for _tuple : Integer.subrange(1, (last)->size())->collect( _indx | Sequence{_indx-1, (last)->at(_indx)} ) do (var _indx : int := 1; var used : OclAny := _tuple->at(_indx); _indx := _indx + 1; var size : OclAny := _tuple->at(_indx); if size > 0 then ( best := used ; break ) else skip) ; execute (StringLib.format("Case #%d: %s",Sequence{case, best}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- fin=open("A-large.in") fout=open("A.out",'w') numtests=int(fin.readline()) for cas in xrange(1,numtests+1): fout.write("Case #"+str(cas)+": ") a,n=map(int,fin.readline().split()) s=map(int,fin.readline().split()) s.sort() cost=[0 for i in xrange(n+1)] if a==1 : fout.write(str(n)+"\n") continue for i in xrange(n): cost[i+1]=cost[i] if(s[i]toInteger() ; for cas : xrange(1, numtests + 1) do ( fout.write("Case #" + ("" + ((cas))) + ": ") ; var a : OclAny := null; var n : OclAny := null; Sequence{a,n} := (fin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := (fin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; s := s->sort() ; var cost : Sequence := xrange(n + 1)->select(i | true)->collect(i | (0)) ; if a = 1 then ( fout.write(("" + ((n))) + "\n") ; continue ) else skip ; for i : xrange(n) do ( cost[i + 1+1] := cost[i+1] ; if ((s[i+1]->compareTo(a)) < 0) then ( a := a + s[i+1] ; continue ) else skip ; while ((a->compareTo(s[i+1])) <= 0) do ( var a : double := 2 * a - 1 ; cost[i + 1+1] := cost[i + 1+1] + 1) ; a := a + s[i+1]) ; var t : Sequence := xrange(n + 1)->select(i | true)->collect(i | (cost[i+1] + (n - i))) ; fout.write(("" + (((t)->min()))) + "\n")) ; fin.closeFile() ; fout.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getLine(filename): inputFile=open(filename,'r') for line in inputFile : yield line inputFile.close() inputFilename='A-large.in' outputFilename='A-large.txt' tokenIterator=getLine(inputFilename) def get(): return tokenIterator.next() def getint(): return int(get()) outputFile=open(outputFilename,'w') caseNum=getint() for case in range(caseNum): tmp=get().split() a=int(tmp[0]) n=int(tmp[1]) tmp=get() x=[int(tmpi)for tmpi in tmp.split()] x.sort() ans=n cnt=0 for i in xrange(n): if x[i]=a : a+=a-1 cnt+=1 a+=x[i] if ans>cnt+(n-i-1): ans=cnt+(n-i-1) output="Case #"+str(case+1)+": "+str(ans) outputFile.write(output+"\n") outputFile.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var inputFilename : String := 'A-large.in' ; var outputFilename : String := 'A-large.txt' ; var tokenIterator : OclAny := getLine(inputFilename) ; skip ; skip ; var outputFile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(outputFilename)) ; var caseNum : OclAny := getint() ; for case : Integer.subrange(0, caseNum-1) do ( var tmp : OclAny := get().split() ; var a : int := ("" + ((tmp->first())))->toInteger() ; var n : int := ("" + ((tmp[1+1])))->toInteger() ; tmp := get() ; var x : Sequence := tmp.split()->select(tmpi | true)->collect(tmpi | (("" + ((tmpi)))->toInteger())) ; x := x->sort() ; var ans : int := n ; var cnt : int := 0 ; for i : xrange(n) do ( if (x[i+1]->compareTo(a)) < 0 then ( a := a + x[i+1] ) else (if a = 1 then ( break ) else ( while (x[i+1]->compareTo(a)) >= 0 do ( a := a + a - 1 ; cnt := cnt + 1) ; a := a + x[i+1] ) ) ; if (ans->compareTo(cnt + (n - i - 1))) > 0 then ( ans := cnt + (n - i - 1) ) else skip) ; var output : String := "Case #" + ("" + ((case + 1))) + ": " + ("" + ((ans))) ; outputFile.write(output + "\n")) ; outputFile.closeFile(); operation getLine(filename : OclAny) pre: true post: true activity: var inputFile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(filename)) ; for line : inputFile do ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return line) ; inputFile.closeFile(); operation get() : OclAny pre: true post: true activity: return tokenIterator.next(); operation getint() : OclAny pre: true post: true activity: return ("" + ((get())))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def emit(text,*args): msg=text % args sys.stderr.write(msg) sys.stdout.write(msg) def solve(moteA,motes): while motes and moteA>motes[0]: moteA+=motes[0] del motes[0] solve_by_del=len(motes) if moteA==1 or solve_by_del<=1 : return solve_by_del solve_by_add=1+solve(moteA+moteA-1,motes) return min(solve_by_del,solve_by_add) def getline(): return sys.stdin.readline().rstrip('\n') ncases=int(getline()) for casenr in range(1,ncases+1): moteA,nmotes=[int(s)for s in getline().split()] motes=[int(s)for s in getline().split()] motes.sort() emit("Case #%d: %s\n",casenr,solve(moteA,motes)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var ncases : int := ("" + ((getline())))->toInteger() ; for casenr : Integer.subrange(1, ncases + 1-1) do ( var nmotes : OclAny := null; Sequence{moteA,nmotes} := getline().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; motes := getline().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; motes := motes->sort() ; emit("Case #%d: %s\n", casenr, solve(moteA, motes))); operation emit(text : OclAny, args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) var msg : int := text mod args ; (expr (atom (name sys)) (trailer . (name stderr)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name msg)))))))) )))) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name msg)))))))) )))); operation solve(moteA : OclAny, motes : OclAny) : OclAny pre: true post: true activity: while motes & (moteA->compareTo(motes->first())) > 0 do ( moteA := moteA + motes->first() ; execute (motes->first())->isDeleted()) ; var solve_by_del : int := (motes)->size() ; if moteA = 1 or solve_by_del <= 1 then ( return solve_by_del ) else skip ; var solve_by_add : int := 1 + solve(moteA + moteA - 1, motes) ; return Set{solve_by_del, solve_by_add}->min(); operation getline() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math def input(): return sys.stdin.readline().rstrip() def main(): N,M=map(int,input().split()) X=list(map(int,input().split())) X.sort() if M<=N : print(0) exit() diff=[0]*(M-1) for i in range(M-1): diff[i]=X[i+1]-X[i] diff.sort() print(sum(diff[: M-N])) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation main() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var X : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; X := X->sort() ; if (M->compareTo(N)) <= 0 then ( execute (0)->display() ; exit() ) else skip ; var diff : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (M - 1)) ; for i : Integer.subrange(0, M - 1-1) do ( diff[i+1] := X[i + 1+1] - X[i+1]) ; diff := diff->sort() ; execute ((diff.subrange(1,M - N))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque,Counter from heapq import heappush,heappop,heapify import math import bisect import random from itertools import permutations,accumulate,combinations import sys import string from bisect import bisect_left,bisect_right from math import factorial INF=float('inf') def LI(): return list(map(int,sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LIM(): return list(map(lambda x : int(x)-1,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def S(): return sys.stdin.readline().strip() def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def LIRM(n): return[LIM()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] def SRL(n): return[list(S())for i in range(n)] mod=1000000007 n,m=LI() L=sorted(LI()) total=L[-1]-L[0] diff_list=sorted([L[i+1]-L[i]for i in range(m-1)],reverse=True) if n>=m : print(0) else : print(total-sum(diff_list[: n-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var INF : double := ("" + (('inf')))->toReal() ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : int := 1000000007 ; var m : OclAny := null; Sequence{n,m} := LI() ; var L : Sequence := LI()->sort() ; var total : double := L->last() - L->first() ; var diff_list : Sequence := Integer.subrange(0, m - 1-1)->select(i | true)->collect(i | (L[i + 1+1] - L[i+1]))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; if (n->compareTo(m)) >= 0 then ( execute (0)->display() ) else ( execute (total - (diff_list.subrange(1,n - 1))->sum())->display() ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LIM() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) )); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation S() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation LIRM(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LIM())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation SRL(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | ((S()))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.buffer.readline def process(A): n=len(A) A2=[] for i in range(n): S=A[i] row=[] for j in range(len(S)): c=A[i][j] c=ord(c)-ord('a') if j % 2==0 : row.append(c) else : row.append(-1*c) row.append(i+1) A2.append(row) A2.sort() answer=[x[-1]for x in A2] answer=' '.join(map(str,answer)) sys.stdout.write(f'{answer}\n') n,m=[int(x)for x in input().split()] A=[] for i in range(n): S=input().decode().strip() A.append(S) process(A) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := sys.stdin.buffer.readline ; skip ; var m : OclAny := null; Sequence{n,m} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; A := Sequence{} ; for i : Integer.subrange(0, n-1) do ( S := input().decode()->trim() ; execute ((S) : A)) ; process(A); operation process(A : OclAny) pre: true post: true activity: var n : int := (A)->size() ; var A2 : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var S : OclAny := A[i+1] ; var row : Sequence := Sequence{} ; for j : Integer.subrange(0, (S)->size()-1) do ( var c : OclAny := A[i+1][j+1] ; c := (c)->char2byte() - ('a')->char2byte() ; if j mod 2 = 0 then ( execute ((c) : row) ) else ( execute ((-1 * c) : row) )) ; execute ((i + 1) : row) ; execute ((row) : A2)) ; A2 := A2->sort() ; var answer : Sequence := A2->select(x | true)->collect(x | (x->last())) ; answer := StringLib.sumStringsWithSeparator(((answer)->collect( _x | (OclType["String"])->apply(_x) )), ' ') ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom f '{answer} '))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- nm=[int(x)for x in input().split()] x=[int(y)for y in input().split()] margin=[] sort_x=sorted(x) for p in range(nm[1]-1): margin.append(sort_x[p+1]-sort_x[p]) sort_mar=sorted(margin) if(nm[0]>=nm[1]): print(0) else : print(sum(sort_mar[: nm[1]-nm[0]])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var nm : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var x : Sequence := input().split()->select(y | true)->collect(y | (("" + ((y)))->toInteger())) ; var margin : Sequence := Sequence{} ; var sort_x : Sequence := x->sort() ; for p : Integer.subrange(0, nm[1+1] - 1-1) do ( execute ((sort_x[p + 1+1] - sort_x[p+1]) : margin)) ; var sort_mar : Sequence := margin->sort() ; if ((nm->first()->compareTo(nm[1+1])) >= 0) then ( execute (0)->display() ) else ( execute ((sort_mar.subrange(1,nm[1+1] - nm->first()))->sum())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- 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(N,M,X): X.sort() diff=[] for i in range(len(X)-1): diff.append(X[i+1]-X[i]) diff.sort(reverse=True) diff=diff[N-1 :] return sum(diff) def main(): N,M=read_int_n() X=read_int_n() print(slv(N,M,X)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(10000) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; (compound_stmt (decorator @ (dotted_name (name mt))) (funcdef def (name slv) ( (typedargslist (def_parameters (def_parameter (named_parameter (name N))) , (def_parameter (named_parameter (name M))) , (def_parameter (named_parameter (name X))))) ) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name X)) (trailer . (name sort) (arguments ( )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name diff)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom [ ]))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name X)))))))) )))) - (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name diff)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name X)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))) - (expr (atom (name X)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))) ))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name diff)) (trailer . (name sort) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name diff)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name diff)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name N))) - (expr (atom (number (integer 1)))))))) :)) ])))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name diff)))))))) )))))))))))))) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation read_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation read_int_n() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation read_float() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation read_float_n() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["double"])->apply(_x) )); operation read_str() : OclAny pre: true post: true activity: return input()->trim(); operation read_str_n() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["String"])->apply(_x) )); operation error_print(args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) execute ((argument * (test (logical_test (comparison (expr (atom (name args))))))))->display(); operation mt(f : OclAny) : OclAny pre: true post: true activity: skip ; skip ; return wrap; operation main() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := read_int_n() ; var X : OclAny := read_int_n() ; execute (slv(N, M, X))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for pratyush in range(int(input())): a,b=list(map(int,input().split())) if a>b : c,d=a,b else : c,d=b,a if d*2>=c and(c+d)% 3==0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for pratyush : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (a->compareTo(b)) > 0 then ( var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := Sequence{a,b} ) else ( var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := Sequence{b,a} ) ; if (d * 2->compareTo(c)) >= 0 & (c + d) mod 3 = 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- NM=list(map(int,input().split())) inp=list(map(int,input().split())) N=NM[0] M=NM[1] inp.sort() dis=[] c=0 for r in inp[:-1]: dis.append(inp[c+1]-inp[c]) c+=1 dis.sort() for de in range(N-1): if len(dis)>0 : del dis[-1] print(sum(dis)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var NM : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var inp : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var N : OclAny := NM->first() ; var M : OclAny := NM[1+1] ; inp := inp->sort() ; var dis : Sequence := Sequence{} ; var c : int := 0 ; for r : inp->front() do ( execute ((inp[c + 1+1] - inp[c+1]) : dis) ; c := c + 1) ; dis := dis->sort() ; for de : Integer.subrange(0, N - 1-1) do ( if (dis)->size() > 0 then ( execute (dis->last())->isDeleted() ) else skip) ; execute ((dis)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import* from collections import* import sys import io,os import math import random from heapq import* gcd=math.gcd sqrt=math.sqrt maxint=10**21 def ceil(a,b): a=-a k=a//b k=-k return k input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def strinp(testcases): k=5 if(testcases==-1 or testcases==1): k=1 f=str(input()) f=f[2 : len(f)-k] return f def pos(n,x): if(x % 2): return((x+1)//2) if(n % 2==0): y=pos(n//2,x//2) else : if(x==2): y=pos(n//2,n//2)+1 else : y=pos(n//2,(x-2)//2)+1 return((n//2)+y) def main(): h=list(map(int,input().split())) n=h[0] q=h[1] for i in range(q): x=int(input()) print(pos(n,x)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var gcd : OclAny := ; var sqrt : OclAny := ; var maxint : double := (10)->pow(21) ; skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; skip ; skip ; skip ; main(); operation ceil(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: a := -a ; var k : int := a div b ; k := -k ; return k; operation strinp(testcases : OclAny) : OclAny pre: true post: true activity: k := 5 ; if (testcases = -1 or testcases = 1) then ( k := 1 ) else skip ; var f : String := ("" + (((OclFile["System.in"]).readLine()))) ; f := f.subrange(2+1, (f)->size() - k) ; return f; operation pos(n : OclAny, x : OclAny) : OclAny pre: true post: true activity: if (x mod 2) then ( return ((x + 1) div 2) ) else skip ; if (n mod 2 = 0) then ( var y : OclAny := pos(n div 2, x div 2) ) else ( if (x = 2) then ( y := pos(n div 2, n div 2) + 1 ) else ( y := pos(n div 2, (x - 2) div 2) + 1 ) ) ; return ((n div 2) + y); operation main() pre: true post: true activity: var h : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; n := h->first() ; var q : OclAny := h[1+1] ; for i : Integer.subrange(0, q-1) do ( x := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (pos(n, x))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import* input=stdin.readline n,q=map(int,input().split()) for _ in range(q): i=int(input()) while i % 2==0 : i+=n-i//2 print((i+1)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for _anon : Integer.subrange(0, q-1) do ( var i : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while i mod 2 = 0 do ( i := i + n - i div 2) ; execute ((i + 1) div 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,q=list(map(int,input().split())) for i in range(q): a=int(input()) if a % 2!=0 : print((a+1)//2) else : b=a//2 while 1>0 : a=a+(n-b) b=a//2 if a % 2!=0 : print((a+1)//2) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, q-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if a mod 2 /= 0 then ( execute ((a + 1) div 2)->display() ) else ( var b : int := a div 2 ; while 1 > 0 do ( a := a + (n - b) ; b := a div 2 ; if a mod 2 /= 0 then ( execute ((a + 1) div 2)->display() ; break ) else skip) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.buffer.readline from math import ceil n,q=map(int,input().split()) for i in range(q): indx=int(input()) count=indx if indx % 2==0 : count=0 pro=n-indx//2 while pro % 2==0 : count+=pro pro//=2 count+=pro count+=indx print((count+1)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := sys.stdin.buffer.readline ; skip ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, q-1) do ( var indx : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := indx ; if indx mod 2 = 0 then ( count := 0 ; var pro : double := n - indx div 2 ; while pro mod 2 = 0 do ( count := count + pro ; pro := pro div 2) ; count := count + pro ; count := count + indx ) else skip ; execute ((count + 1) div 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rating(): n=int(input()) c=0 x=[] y=[] for i in range(n): a,b=map(int,input().split()) x.append(a) y.append(b) if a!=b : c=1 if(c==1): print("rated") return 0 for i in range(n): for j in range(i+1,n): if(x[i]toInteger() ; var c : int := 0 ; var x : Sequence := Sequence{} ; var y : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a) : x) ; execute ((b) : y) ; if a /= b then ( c := 1 ) else skip) ; if (c = 1) then ( execute ("rated")->display() ; return 0 ) else skip ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if ((x[i+1]->compareTo(x[j+1])) < 0) then ( c := -1 ) else skip)) ; if c = -1 then ( execute ("unrated")->display() ) else ( execute ("maybe")->display() ) ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) arr=[] for i in range(a): sub=list(map(int,input().split())) arr.append(sub) c=0 j=0 for i in range(a-1): if arr[i][0]>arr[i][1]or arr[i][0]arr[a-1][1]or arr[a-1][0]0 : print('rated') elif j>0 : print('unrated') else : print('maybe') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Sequence{} ; for i : Integer.subrange(0, a-1) do ( var sub : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((sub) : arr)) ; var c : int := 0 ; var j : int := 0 ; for i : Integer.subrange(0, a - 1-1) do ( if (arr[i+1]->first()->compareTo(arr[i+1][1+1])) > 0 or (arr[i+1]->first()->compareTo(arr[i+1][1+1])) < 0 then ( c := c + 1 ) else skip ; if (arr[i+1]->first()->compareTo(arr[i + 1+1]->first())) < 0 then ( j := j + 1 ) else skip) ; if (arr[a - 1+1]->first()->compareTo(arr[a - 1+1][1+1])) > 0 or (arr[a - 1+1]->first()->compareTo(arr[a - 1+1][1+1])) < 0 then ( c := c + 1 ) else skip ; if c > 0 then ( execute ('rated')->display() ) else (if j > 0 then ( execute ('unrated')->display() ) else ( execute ('maybe')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(a,n,m): b=[] flag=False for i in a : curr=i//n if curr>=3 : flag=True if curr>=2 : b.append(curr) if m % 2==1 : if not flag : return False return sum(b)>=m for t in range(int(input())): n,m,k=map(int,input().split()) a=list(map(int,input().split())) a.sort() if solve(a.copy(),n,m)or solve(a.copy(),m,n): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; if solve(a->copy(), n, m) or solve(a->copy(), m, n) then ( execute ("Yes")->display() ) else ( execute ("No")->display() )); operation solve(a : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var b : Sequence := Sequence{} ; var flag : boolean := false ; for i : a do ( var curr : int := i div n ; if curr >= 3 then ( flag := true ) else skip ; if curr >= 2 then ( execute ((curr) : b) ) else skip) ; if m mod 2 = 1 then ( if not(flag) then ( return false ) else skip ) else skip ; return ((b)->sum()->compareTo(m)) >= 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- y=int(input()) arr=[int(i)for i in input().split()] for i in range(len(arr)): for j in range(len(arr)): if i==j : continue for k in range(len(arr)): if arr[k]!=arr[j]and arr[k]!=arr[i]and arr[k]==arr[i]+arr[j]: print(k+1,j+1,i+1) exit() print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var y : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; for i : Integer.subrange(0, (arr)->size()-1) do ( for j : Integer.subrange(0, (arr)->size()-1) do ( if i = j then ( continue ) else skip ; for k : Integer.subrange(0, (arr)->size()-1) do ( if arr[k+1] /= arr[j+1] & arr[k+1] /= arr[i+1] & arr[k+1] = arr[i+1] + arr[j+1] then ( execute (k + 1)->display() ; exit() ) else skip))) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) answer=[] for x in range(q): answer.append(list(map(int,input().split()))) for i in answer : if(i[0]!=i[1]): print("rated") break else : for i in range(len(answer)-1): if(answer[i][0]toInteger() ; var answer : Sequence := Sequence{} ; for x : Integer.subrange(0, q-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : answer)) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name answer))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name i)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) != (comparison (expr (atom (name i)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "rated"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name answer)))))))) )))) - (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name answer)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) < (comparison (expr (atom (name answer)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "unrated"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "maybe"))))))) ))))))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) sol=[] for x in range(t): sol.append(list(map(int,input().split()))) for i in sol : if(i[0]!=i[1]): print("rated") break else : for i in range(len(sol)-1): if(sol[i][0]toInteger() ; var sol : Sequence := Sequence{} ; for x : Integer.subrange(0, t-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : sol)) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name sol))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name i)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) != (comparison (expr (atom (name i)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "rated"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sol)))))))) )))) - (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name sol)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) < (comparison (expr (atom (name sol)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "unrated"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "maybe"))))))) ))))))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) sol=[] for x in range(t): sol.append(list(map(int,input().split()))) for i in sol : if(i[0]!=i[1]): print("rated") break else : for i in range(len(sol)-1): if(sol[i][0]toInteger() ; var sol : Sequence := Sequence{} ; for x : Integer.subrange(0, t-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : sol)) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name sol))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name i)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) != (comparison (expr (atom (name i)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "rated"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sol)))))))) )))) - (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name sol)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) < (comparison (expr (atom (name sol)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "unrated"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "maybe"))))))) ))))))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from os import path if(path.exists('input.txt')): sys.stdin=open('input.txt','r') sys.stdout=open('output.txt','w') def solve(): a,b=map(int,input().split()) if a>b : a,b=b,a print("YES" if((a+b)% 3==0 and a*2>=b)else "NO") q=1 q=int(input()) for i in range(q): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if (path.exists('input.txt')) then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('input.txt')) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile('output.txt')) ) else skip ; skip ; var q : int := 1 ; q := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( solve()); operation solve() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(b)) > 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a} ) else skip ; execute (if ((a + b) mod 3 = 0 & (a * 2->compareTo(b)) >= 0) then "YES" else "NO" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findEvenPair(A,N): count=0 for i in range(0,N): if(A[i]% 2!=0): count+=1 totalPairs=(N*(N-1)/2) oddEvenPairs=count*(N-count) return(int)(totalPairs-oddEvenPairs) def main(): a=[5,4,7,2,1] n=len(a) print(findEvenPair(a,n)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation findEvenPair(A : OclAny, N : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, N-1) do ( if (A[i+1] mod 2 /= 0) then ( count := count + 1 ) else skip) ; var totalPairs : double := (N * (N - 1) / 2) ; var oddEvenPairs : double := count * (N - count) ; return (OclType["int"])(totalPairs - oddEvenPairs); operation main() pre: true post: true activity: var a : Sequence := Sequence{5}->union(Sequence{4}->union(Sequence{7}->union(Sequence{2}->union(Sequence{ 1 })))) ; var n : int := (a)->size() ; execute (findEvenPair(a, n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): input() a=list(map(int,input().split())) print("T" if max(a)*2>sum(a)or sum(a)% 2==1 else "HL") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( input() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (if ((a)->max() * 2->compareTo((a)->sum())) > 0 or (a)->sum() mod 2 = 1 then "T" else "HL" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) stones=list(map(int,input().split())) stones.sort() if stones[-1]>sum(stones[:-1])or n==1 or sum(stones)% 2==1 : print("T") else : print("HL") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var stones : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; stones := stones->sort() ; if (stones->last()->compareTo((stones->front())->sum())) > 0 or n = 1 or (stones)->sum() mod 2 = 1 then ( execute ("T")->display() ) else ( execute ("HL")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(a,n): maxv=max(a) sumv=sum(a) if maxv>sumv-maxv : print('T') else : if sumv % 2==1 : print('T') else : print('HL') return t=int(input()) while t : n=int(input()) a=list(map(int,input().split(' '))) solve(a,n) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; solve(a, n) ; t := t - 1); operation solve(a : OclAny, n : OclAny) pre: true post: true activity: var maxv : OclAny := (a)->max() ; var sumv : OclAny := (a)->sum() ; if (maxv->compareTo(sumv - maxv)) > 0 then ( execute ('T')->display() ) else ( if sumv mod 2 = 1 then ( execute ('T')->display() ) else ( execute ('HL')->display() ) ) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t=int(input()) ans=[] for _ in range(t): n=int(input()) a=list(map(int,input().split())) m,s=max(a),sum(a) if s-mtoInteger() ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : OclAny := null; var s : OclAny := null; Sequence{m,s} := Sequence{(a)->max(),(a)->sum()} ; if (s - m->compareTo(m)) < 0 then ( var ans0 : String := "T" ) else ( ans0 := if s mod 2 then "T" else "HL" endif ) ; execute ((ans0) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for tc in range(int(input())): N=int(input()) A=list(map(int,input().split())) s,m=sum(A),max(A) print('T\n' if s//2toInteger()-1) do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : OclAny := null; var m : OclAny := null; Sequence{s,m} := Sequence{(A)->sum(),(A)->max()} ; execute (if (s div 2->compareTo(m)) < 0 or s mod 2 = 1 then 'T ' else 'HL ' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- z=int(input()) arr=[int(i)for i in input().split()] for i in range(len(arr)): for j in range(len(arr)): if i==j : continue for k in range(len(arr)): if arr[k]!=arr[j]and arr[k]!=arr[i]and arr[k]==arr[i]+arr[j]: print(k+1,j+1,i+1) exit() print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var z : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; for i : Integer.subrange(0, (arr)->size()-1) do ( for j : Integer.subrange(0, (arr)->size()-1) do ( if i = j then ( continue ) else skip ; for k : Integer.subrange(0, (arr)->size()-1) do ( if arr[k+1] /= arr[j+1] & arr[k+1] /= arr[i+1] & arr[k+1] = arr[i+1] + arr[j+1] then ( execute (k + 1)->display() ; exit() ) else skip))) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cntPairs(a,n): odd=0 ; even=0 ; for i in range(n): if(a[i]% 2==1): odd+=1 ; elif((a[i]/2)% 2==1): even+=1 ; ans=odd*even+(odd*(odd-1))//2 ; return ans ; if __name__=="__main__" : a=[4,2,7,11,14,15,18]; n=len(a); print(cntPairs(a,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{4}->union(Sequence{2}->union(Sequence{7}->union(Sequence{11}->union(Sequence{14}->union(Sequence{15}->union(Sequence{ 18 })))))); ; n := (a)->size(); ; execute (cntPairs(a, n))->display(); ) else skip; operation cntPairs(a : OclAny, n : OclAny) pre: true post: true activity: var odd : int := 0; var even : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] mod 2 = 1) then ( odd := odd + 1; ) else (if ((a[i+1] / 2) mod 2 = 1) then ( even := even + 1; ) else skip)) ; var ans : int := odd * even + (odd * (odd - 1)) div 2; ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minOperations(n,m): if(m % n!=0): return-1 minOperations=0 q=int(m/n) while(q % 2==0): q=int(q/2) minOperations+=1 while(q % 3==0): q=int(q/3) minOperations+=1 if(q==1): return minOperations return-1 if __name__=='__main__' : n=120 m=51840 print(minOperations(n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 120 ; m := 51840 ; execute (minOperations(n, m))->display() ) else skip; operation minOperations(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: if (m mod n /= 0) then ( return -1 ) else skip ; var minOperations : int := 0 ; var q : int := ("" + ((m / n)))->toInteger() ; while (q mod 2 = 0) do ( q := ("" + ((q / 2)))->toInteger() ; minOperations := minOperations + 1) ; while (q mod 3 = 0) do ( q := ("" + ((q / 3)))->toInteger() ; minOperations := minOperations + 1) ; if (q = 1) then ( return minOperations ) else skip ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import deque,defaultdict from math import sqrt,factorial,gcd,ceil,atan,pi def input(): return sys.stdin.readline()[:-1] import string from bisect import bisect_left,bisect_right from functools import lru_cache MOD=int(1e9)+7 INF=float('inf') def solve(): n=int(input()) a=[int(x)for x in input().split()] xd=[0]*n ans=[] for i in range(n-1,-1,-1): cnt=0 for j in range(i,n,i+1): cnt+=xd[j] cnt %=2 if cnt!=a[i]: ans.append(i+1) xd[i]=1 ans.reverse() print(len(ans)) if ans : print(*ans) t=1 for case in range(1,t+1): ans=solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var MOD : int := ("" + ((("1e9")->toReal())))->toInteger() + 7 ; var INF : double := ("" + (('inf')))->toReal() ; skip ; var t : int := 1 ; for case : Integer.subrange(1, t + 1-1) do ( ans := solve()); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var xd : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( var cnt : int := 0 ; for j : Integer.subrange(i, n-1)->select( $x | ($x - i) mod i + 1 = 0 ) do ( cnt := cnt + xd[j+1]) ; cnt := cnt mod 2 ; if cnt /= a[i+1] then ( execute ((i + 1) : ans) ; xd[i+1] := 1 ) else skip) ; ans := ans->reverse() ; execute ((ans)->size())->display() ; if ans then ( execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,*a=map(int,open(0).read().split()) b=[0]*(n+1) for i in range(1,n+1)[: :-1]: b[i]+=(sum(b[j]for j in range(i,n+1,i))+a[i-1])% 2 print(sum(b)) print(*[i for i in range(n+1)if b[i]>0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : range(1, n + 1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( b[i+1] := b[i+1] + (((argument (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))->sum() + a[i - 1+1]) mod 2) ; execute ((b)->sum())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) > (comparison (expr (atom (number (integer 0))))))))))) ])))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): a,b=sorted(map(int,input().split())) if 2*atoInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; if (2 * a->compareTo(b)) < 0 then ( execute ('NO')->display() ) else ( var x : double := b - a ; a := a - x ; if a mod 3 = 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**7) def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return sys.stdin.readline().strip() INF=10**18 MOD=10**9+7 debug=True debug=False def dprint(*objects): if debug==True : print(*objects) import collections def solve(): N=int(input()) a_list=list(map(int,input().split())) y_dict=collections.defaultdict(list) for i in range(1,N//2+2): cnt=2 while True : baisu=i*cnt y_dict[baisu].append(i) cnt+=1 if baisu>N : break dprint(y_dict) bits=collections.defaultdict(int) ans=[] for i in range(N,0,-1): a=a_list[i-1] dprint(a,bits[i]) if a==bits[i]: continue for y in y_dict[i]: bits[y]=(bits[y]+1)% 2 ans.append(i) print(len(ans)) print(' '.join([str(num)for num in reversed(ans)])) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; skip ; skip ; skip ; skip ; skip ; var INF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; var debug : boolean := true ; debug := false ; skip ; skip ; skip ; solve(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation SI() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation dprint(objects : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name objects))) if debug = true then ( execute ((argument * (test (logical_test (comparison (expr (atom (name objects))))))))->display() ) else skip; operation solve() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var y_dict : OclAny := .defaultdict(OclType["Sequence"]) ; for i : Integer.subrange(1, N div 2 + 2-1) do ( var cnt : int := 2 ; while true do ( var baisu : double := i * cnt ; (expr (atom (name y_dict)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name baisu)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ; cnt := cnt + 1 ; if (baisu->compareTo(N)) > 0 then ( break ) else skip)) ; dprint(y_dict) ; var bits : OclAny := .defaultdict(OclType["int"]) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0 + 1, N)->reverse() do ( var a : OclAny := a_list[i - 1+1] ; dprint(a, bits[i+1]) ; if a = bits[i+1] then ( continue ) else skip ; for y : y_dict[i+1] do ( bits[y+1] := (bits[y+1] + 1) mod 2) ; execute ((i) : ans)) ; execute ((ans)->size())->display() ; execute (StringLib.sumStringsWithSeparator(((ans)->reverse()->select(num | true)->collect(num | (("" + ((num)))))), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys MOD=2 def solve(N : int,a : "List[int]"): def isodd(ai : int): flag=False hoge=N//ai while True : if hoge==1 : break if ans[ai*hoge-1]: flag=not flag hoge=hoge-1 return flag sum=0 num=[] ans=[0]*N for i in reversed(range(1,N+1)): odd=isodd(i) write=not(odd==a[i-1]) if write : sum=sum+1 num.append(i) ans[i-1]=1 print(sum) if sum!=0 : print(' '.join(map(str,num))) return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() N=int(next(tokens)) a=[int(next(tokens))for _ in range(N)] solve(N,a) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MOD : int := 2 ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(N : int, a : "List[int]") pre: true post: true activity: skip ; var sum : int := 0 ; var num : Sequence := Sequence{} ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for i : (Integer.subrange(1, N + 1-1))->reverse() do ( var odd : OclAny := isodd(i) ; var write : boolean := not((odd = a[i - 1+1])) ; if write then ( sum := sum + 1 ; execute ((i) : num) ; ans[i - 1+1] := 1 ) else skip) ; execute (sum)->display() ; if sum /= 0 then ( execute (StringLib.sumStringsWithSeparator(((num)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ) else skip ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var N : int := ("" + (((tokens).next())))->toInteger() ; var a : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((tokens).next())))->toInteger())) ; solve(N, a); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect,collections,copy,itertools,math,string import sys def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def main(): n=I() a=[0]+LI() ans=[0 for _ in range(n+1)] for i in range(n,0,-1): cnt=0 for j in range(i,n+1,i): cnt+=ans[j] if cnt % 2!=a[i]: ans[i]=1 ans_lst=[] for i in range(1,n+1): if ans[i]==1 : ans_lst.append(i) print(len(ans_lst)) print(*ans_lst) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; main(); operation I() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.readLine().rstrip())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )); operation S() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation LS() : OclAny pre: true post: true activity: return (sys.stdin.readLine().rstrip().split()); operation main() pre: true post: true activity: var n : OclAny := I() ; var a : Sequence := Sequence{ 0 }->union(LI()) ; var ans : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (0)) ; for i : Integer.subrange(0 + 1, n)->reverse() do ( var cnt : int := 0 ; for j : Integer.subrange(i, n + 1-1)->select( $x | ($x - i) mod i = 0 ) do ( cnt := cnt + ans[j+1]) ; if cnt mod 2 /= a[i+1] then ( ans[i+1] := 1 ) else skip) ; var ans_lst : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( if ans[i+1] = 1 then ( execute ((i) : ans_lst) ) else skip) ; execute ((ans_lst)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans_lst))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isDivisible(arr,n): lastDigit=arr[n-1]% 10 ; if(lastDigit==0): return True ; return False ; if __name__=="__main__" : arr=[12,65,46,37,99]; n=len(arr); if(isDivisible(arr,n)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{12}->union(Sequence{65}->union(Sequence{46}->union(Sequence{37}->union(Sequence{ 99 })))); ; n := (arr)->size(); ; if (isDivisible(arr, n)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ) else skip; operation isDivisible(arr : OclAny, n : OclAny) pre: true post: true activity: var lastDigit : int := arr[n - 1+1] mod 10; ; if (lastDigit = 0) then ( return true; ) else skip ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=str(input()) ans=1 for i in range(n-1): if s[i]!=s[i+1]: ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; var ans : int := 1 ; for i : Integer.subrange(0, n - 1-1) do ( if s[i+1] /= s[i + 1+1] then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()); a=list(map(int,input().split())) for i in range(n): for j in range(n): if i!=j and a[i]+a[j]in a : print(a.index(a[i]+a[j])+1,j+1,i+1); exit() print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if i /= j & (a)->includes(a[i+1] + a[j+1]) then ( execute (a->indexOf(a[i+1] + a[j+1]) - 1 + 1)->display(); exit() ) else skip)) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import groupby def main(): N=int(input()) S=input().rstrip() ans=len(list(groupby(S))) print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : OclAny := input().rstrip() ; var ans : int := ((groupby(S)))->size() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() otv=0 i=0 while itoInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var otv : int := 0 ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( otv := otv + 1 ; while (i->compareTo(n - 1)) < 0 & s[i+1] = s[i + 1+1] do ( i := i + 1) ; i := i + 1) ; execute (otv)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import itertools import collections import numpy as np rl=sys.stdin.readline n=int(rl()) s=rl() cnt=1 for i in range(n-1): if s[i]!=s[i+1]: cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var rl : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + ((rl())))->toInteger() ; var s : OclAny := rl() ; var cnt : int := 1 ; for i : Integer.subrange(0, n - 1-1) do ( if s[i+1] /= s[i + 1+1] then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) S='*'+input() print(sum([int(S[i]!=S[i+1])for i in range(N)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : String := '*' + (OclFile["System.in"]).readLine() ; execute ((Integer.subrange(0, N-1)->select(i | true)->collect(i | (("" + ((S[i+1] /= S[i + 1+1])))->toInteger())))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printPattern(n,m,flag): print(m) if flag==False and n==m : return if flag : if m-5>0 : printPattern(n,m-5,True) else : printPattern(n,m-5,False) else : printPattern(n,m+5,False) n=16 printPattern(n,n,True) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 16 ; printPattern(n, n, true); operation printPattern(n : OclAny, m : OclAny, flag : OclAny) pre: true post: true activity: execute (m)->display() ; if flag = false & n = m then ( return ) else skip ; if flag then ( if m - 5 > 0 then ( printPattern(n, m - 5, true) ) else ( printPattern(n, m - 5, false) ) ) else ( printPattern(n, m + 5, false) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() for i in range(0,int(a)): b,c=input().split() if(int(b)+int(c))% 3!=0 : print('NO') else : if(int(b)+int(c))//3>min(int(b),int(c)): print('NO') else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, ("" + ((a)))->toInteger()-1) do ( var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := input().split() ; if (("" + ((b)))->toInteger() + ("" + ((c)))->toInteger()) mod 3 /= 0 then ( execute ('NO')->display() ) else ( if ((("" + ((b)))->toInteger() + ("" + ((c)))->toInteger()) div 3->compareTo(Set{("" + ((b)))->toInteger(), ("" + ((c)))->toInteger()}->min())) > 0 then ( execute ('NO')->display() ) else ( execute ('YES')->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r=lambda : input().split() g=lambda s : max(map(len,"".join(s).split('0'))) n,m,q=map(int,r()) a=[r()for t in range(n)] b=list(map(g,a)) for c in range(q): x,y=map(int,r()) a[x-1][y-1]=str(1-int(a[x-1][y-1])) b[x-1]=g(a[x-1]) print(max(b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : Function := lambda $$ : OclAny in (input().split()) ; var g : Function := lambda s : OclAny in ((("".join(s).split('0'))->collect( _x | (len)->apply(_x) ))->max()) ; var n : OclAny := null; var m : OclAny := null; var q : OclAny := null; Sequence{n,m,q} := (r->apply())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, n-1)->select(t | true)->collect(t | (r->apply())) ; var b : Sequence := ((a)->collect( _x | (g)->apply(_x) )) ; for c : Integer.subrange(0, q-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (r->apply())->collect( _x | (OclType["int"])->apply(_x) ) ; a[x - 1+1][y - 1+1] := ("" + ((1 - ("" + ((a[x - 1+1][y - 1+1])))->toInteger()))) ; b[x - 1+1] := g->apply(a[x - 1+1]) ; execute ((b)->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def seq(list): maior=0 cont=0 for n in list : if n==1 : cont+=1 if cont>maior : maior=cont else : if cont>maior : maior=cont cont=0 return maior n,m,q=map(int,input().split()) tabuleiro=[] sequencias=[] for linhas in range(n): linha=list(map(int,input().split())) tabuleiro.append(linha) sequencias.append(seq(linha)) for cordenadas in range(q): i,j=map(int,input().split()) i-=1 j-=1 tabuleiro[i][j]=(tabuleiro[i][j]+1)% 2 sequencias[i]=seq(tabuleiro[i]) print(max(sequencias)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; var q : OclAny := null; Sequence{n,m,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var tabuleiro : Sequence := Sequence{} ; var sequencias : Sequence := Sequence{} ; for linhas : Integer.subrange(0, n-1) do ( var linha : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((linha) : tabuleiro) ; execute ((seq(linha)) : sequencias)) ; for cordenadas : Integer.subrange(0, q-1) do ( var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; i := i - 1 ; j := j - 1 ; tabuleiro[i+1][j+1] := (tabuleiro[i+1][j+1] + 1) mod 2 ; sequencias[i+1] := seq(tabuleiro[i+1]) ; execute ((sequencias)->max())->display()); operation seq(list : OclAny) : OclAny pre: true post: true activity: var maior : int := 0 ; var cont : int := 0 ; for n : OclType["Sequence"] do ( if n = 1 then ( cont := cont + 1 ; if (cont->compareTo(maior)) > 0 then ( maior := cont ) else skip ) else ( if (cont->compareTo(maior)) > 0 then ( maior := cont ) else skip ; cont := 0 )) ; return maior; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def max_str(str_in): ans=0 sm_ans=0 for i in range(len(str_in)): if str_in[i]==1 : sm_ans+=1 else : sm_ans=0 ans=max(sm_ans,ans) return ans n,m,q=[int(el)for el in input().split()] list_m=[] vect_in=[] for i in range(n): sm_list=[int(el)for el in input().split()] list_m.append(sm_list) vect_in.append(max_str(sm_list)) for i in range(q): i_i,j_j=[int(el)for el in input().split()] list_m[i_i-1][j_j-1]=(list_m[i_i-1][j_j-1]+1)% 2 vect_in[i_i-1]=max_str(list_m[i_i-1]) print(max(vect_in)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; var q : OclAny := null; Sequence{n,m,q} := input().split()->select(el | true)->collect(el | (("" + ((el)))->toInteger())) ; var list_m : Sequence := Sequence{} ; var vect_in : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var sm_list : Sequence := input().split()->select(el | true)->collect(el | (("" + ((el)))->toInteger())) ; execute ((sm_list) : list_m) ; execute ((max_str(sm_list)) : vect_in)) ; for i : Integer.subrange(0, q-1) do ( var i_i : OclAny := null; var j_j : OclAny := null; Sequence{i_i,j_j} := input().split()->select(el | true)->collect(el | (("" + ((el)))->toInteger())) ; list_m[i_i - 1+1][j_j - 1+1] := (list_m[i_i - 1+1][j_j - 1+1] + 1) mod 2 ; vect_in[i_i - 1+1] := max_str(list_m[i_i - 1+1]) ; execute ((vect_in)->max())->display()); operation max_str(str_in : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; var sm_ans : int := 0 ; for i : Integer.subrange(0, (str_in)->size()-1) do ( if str_in[i+1] = 1 then ( sm_ans := sm_ans + 1 ) else ( sm_ans := 0 ) ; ans := Set{sm_ans, ans}->max()) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,q=map(int,input().split()) arr=[] for i in range(n): arr.append([int(i)for i in input().split()]) ans=[1 for i in range(n)] for i in range(n): u=1 temp=1 for k in range(1,m): if arr[i][k]==arr[i][k-1]==1 : u+=1 temp=max(temp,u) else : u=1 if 1 not in arr[i][:]: temp=0 ans[i]=temp for q in range(q): i,j=map(int,input().split()) arr[i-1][j-1]^=1 t,u=1,1 temp=1 for k in range(1,m): if arr[i-1][k]==arr[i-1][k-1]==1 : u+=1 temp=max(temp,u) else : u=1 if 1 not in arr[i-1][:]: temp=0 ans[i-1]=temp print(max(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var q : OclAny := null; Sequence{n,m,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))) : arr)) ; var ans : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (1)) ; for i : Integer.subrange(0, n-1) do ( var u : int := 1 ; var temp : int := 1 ; for k : Integer.subrange(1, m-1) do ( if arr[i+1][k+1] = arr[i+1][k - 1+1] & (arr[i+1][k - 1+1] == 1) then ( u := u + 1 ; temp := Set{temp, u}->max() ) else ( u := 1 )) ; if (arr[i+1])->excludes(1) then ( temp := 0 ) else skip ; ans[i+1] := temp) ; for q : Integer.subrange(0, q-1) do ( var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; arr[i - 1+1][j - 1+1] := arr[i - 1+1][j - 1+1] xor 1 ; var t : OclAny := null; Sequence{t,u} := Sequence{1,1} ; temp := 1 ; for k : Integer.subrange(1, m-1) do ( if arr[i - 1+1][k+1] = arr[i - 1+1][k - 1+1] & (arr[i - 1+1][k - 1+1] == 1) then ( u := u + 1 ; temp := Set{temp, u}->max() ) else ( u := 1 )) ; if (arr[i - 1+1])->excludes(1) then ( temp := 0 ) else skip ; ans[i - 1+1] := temp ; execute ((ans)->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def averageOdd(n): if(n % 2==0): print("Invalid Input") return-1 sm=0 count=0 while(n>=1): count=count+1 sm=sm+n n=n-2 return sm//count n=15 print(averageOdd(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 15 ; execute (averageOdd(n))->display(); operation averageOdd(n : OclAny) : OclAny pre: true post: true activity: if (n mod 2 = 0) then ( execute ("Invalid Input")->display() ; return -1 ) else skip ; var sm : int := 0 ; var count : int := 0 ; while (n >= 1) do ( count := count + 1 ; sm := sm + n ; n := n - 2) ; return sm div count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c,t,q=[int(n)for n in input().split()] tabs=[] slices=[] for j in range(c): seq=input().split() tabs.append(seq) seq.append('0') maior_slice=0 slice_atual=0 for e in seq : if e=='1' : slice_atual+=1 else : if slice_atual>maior_slice : maior_slice=slice_atual slice_atual=0 slices.append(maior_slice) for c in range(q): querie=[int(n)for n in input().split()] tabs[querie[0]-1][querie[1]-1]='0' if tabs[querie[0]-1][querie[1]-1]=='1' else '1' slice_atual=0 maior_slice=0 for e in tabs[querie[0]-1]: if e=='1' : slice_atual+=1 else : if slice_atual>maior_slice : maior_slice=slice_atual slice_atual=0 if slice_atual>maior_slice : maior_slice=slice_atual slices[querie[0]-1]=maior_slice print(max(slices)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : OclAny := null; var t : OclAny := null; var q : OclAny := null; Sequence{c,t,q} := input().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; var tabs : Sequence := Sequence{} ; var slices : Sequence := Sequence{} ; for j : Integer.subrange(0, c-1) do ( var seq : OclAny := input().split() ; execute ((seq) : tabs) ; execute (('0') : seq) ; var maior_slice : int := 0 ; var slice_atual : int := 0 ; for e : seq do ( if e = '1' then ( slice_atual := slice_atual + 1 ) else ( if (slice_atual->compareTo(maior_slice)) > 0 then ( maior_slice := slice_atual ) else skip ; slice_atual := 0 )) ; execute ((maior_slice) : slices)) ; for c : Integer.subrange(0, q-1) do ( var querie : Sequence := input().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; tabs[querie->first() - 1+1][querie[1+1] - 1+1] := if tabs[querie->first() - 1+1][querie[1+1] - 1+1] = '1' then '0' else '1' endif ; slice_atual := 0 ; maior_slice := 0 ; for e : tabs[querie->first() - 1+1] do ( if e = '1' then ( slice_atual := slice_atual + 1 ) else ( if (slice_atual->compareTo(maior_slice)) > 0 then ( maior_slice := slice_atual ) else skip ; slice_atual := 0 )) ; if (slice_atual->compareTo(maior_slice)) > 0 then ( maior_slice := slice_atual ) else skip ; slices[querie->first() - 1+1] := maior_slice ; execute ((slices)->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) li=[] for i in range(n-1): c,s,f=map(int,input().split()) li.append((c,s,f)) for i in range(n-1): cur=li[i][1]+li[i][0] for j in range(i+1,n-1): c,s,f=li[j] cur=max(s,-(-cur//f)*f)+c print(cur) print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li : Sequence := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( var c : OclAny := null; var s : OclAny := null; var f : OclAny := null; Sequence{c,s,f} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{c, s, f}) : li)) ; for i : Integer.subrange(0, n - 1-1) do ( var cur : OclAny := li[i+1][1+1] + li[i+1]->first() ; for j : Integer.subrange(i + 1, n - 1-1) do ( var c : OclAny := null; var s : OclAny := null; var f : OclAny := null; Sequence{c,s,f} := li[j+1] ; cur := Set{s, -(-cur div f) * f}->max() + c) ; execute (cur)->display()) ; execute (0)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil n,*CSF=map(int,open(0).read().split()) A=[] for i in range(0,3*(n-1),3): t=0 for c,s,f in zip(CSF[i : : 3],CSF[i+1 : : 3],CSF[i+2 : : 3]): if t<=s : t=s+c else : t=ceil((t-s)/f)*f+s+c A.append(t) A.append(0) print(*A,sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var CSF : OclAny := null; Sequence{n,CSF} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := Sequence{} ; for i : Integer.subrange(0, 3 * (n - 1)-1)->select( $x | ($x - 0) mod 3 = 0 ) do ( var t : int := 0 ; for _tuple : Integer.subrange(1, CSF(subscript (test (logical_test (comparison (expr (atom (name i)))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 3)))))))))->size())->collect( _indx | Sequence{CSF(subscript (test (logical_test (comparison (expr (atom (name i)))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 3)))))))))->at(_indx), CSF(subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 3)))))))))->at(_indx)} ) do (var _indx : int := 1; var c : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var f : OclAny := _tuple->at(_indx); if (t->compareTo(s)) <= 0 then ( t := s + c ) else ( t := ceil((t - s) / f) * f + s + c )) ; execute ((t) : A)) ; execute ((0) : A) ; execute ((argument * (test (logical_test (comparison (expr (atom (name A))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve_impl(ini,T): t=0 for Ci,Si,Fi in T[ini :]: if tat(_indx); _indx := _indx + 1; var Si : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Fi : OclAny := _tuple->at(_indx); if (t->compareTo(Si)) < 0 then ( t := Si ) else (if t mod Fi /= 0 then ( t := t + Fi - t mod Fi ) else skip) ; t := t + Ci) ; return t; operation solve() : OclAny pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; T := Integer.subrange(0, N - 1-1)->select(_anon | true)->collect(_anon | (input().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())))) ; for i : Integer.subrange(0, N-1) do ( execute (solve_impl(i, T))->display()) ; return 0; operation main() pre: true post: true activity: var ans : OclAny := solve(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) e=[[int(i)for i in input().split()]for i in range(n-1)] result=[] for i in range(n-1): t=e[i][0]+e[i][1] for x in e[i+1 :]: if t<=x[1]: t=x[0]+x[1] continue t=math.ceil((t-x[1])/x[2])*x[2]+x[1]+x[0] result.append(t) result.append(0) for x in result : print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var e : Sequence := Integer.subrange(0, n - 1-1)->select(i | true)->collect(i | (input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())))) ; var result : Sequence := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( var t : OclAny := e[i+1]->first() + e[i+1][1+1] ; for x : e.subrange(i + 1+1) do ( if (t->compareTo(x[1+1])) <= 0 then ( t := x->first() + x[1+1] ; continue ) else skip ; t := ((t - x[1+1]) / x[2+1])->ceil() * x[2+1] + x[1+1] + x->first()) ; execute ((t) : result)) ; execute ((0) : result) ; for x : result do ( execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**7) input=sys.stdin.readline n=int(input()) c=[0]*(n-1) s=[0]*(n-1) f=[0]*(n-1) for i in range(n-1): c[i],s[i],f[i]=map(int,input().split()) def dfs(eki,t): if eki==n-1 : return t cc=c[eki] ss=s[eki] ff=f[eki] if t<=ss : return dfs(eki+1,ss+cc) else : return dfs(eki+1,-(-t//ff)*ff+cc) for i in range(n): print(dfs(i,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n - 1)) ; var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n - 1)) ; var f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n - 1)) ; for i : Integer.subrange(0, n - 1-1) do ( var c[i+1] : OclAny := null; var s[i+1] : OclAny := null; var f[i+1] : OclAny := null; Sequence{c[i+1],s[i+1],f[i+1]} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; for i : Integer.subrange(0, n-1) do ( execute (dfs(i, 0))->display()); operation dfs(eki : OclAny, t : OclAny) : OclAny pre: true post: true activity: if eki = n - 1 then ( return t ) else skip ; var cc : OclAny := c[eki+1] ; var ss : OclAny := s[eki+1] ; var ff : String := f[eki+1] ; if (t->compareTo(ss)) <= 0 then ( return dfs(eki + 1, ss + cc) ) else ( return dfs(eki + 1, -(-t div ff) * ff + cc) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline inp=lambda : list(map(int,input().split())) def answer(a,b): if(a==0 and b!=0): return 'NO' if(b==0 and a!=0): return 'NO' if(max(a,b)>2*min(a,b)): return 'NO' if((a+b)% 3==0): return 'YES' return 'NO' for T in range(int(input())): a,b=inp() print(answer(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; var inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; skip ; for T : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( Sequence{a,b} := inp->apply() ; execute (answer(a, b))->display()); operation answer(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0 & b /= 0) then ( return 'NO' ) else skip ; if (b = 0 & a /= 0) then ( return 'NO' ) else skip ; if ((Set{a, b}->max()->compareTo(2 * Set{a, b}->min())) > 0) then ( return 'NO' ) else skip ; if ((a + b) mod 3 = 0) then ( return 'YES' ) else skip ; return 'NO'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countMultiples(n): multiple=[2,3,5] count=0 mask=int(pow(2,3)) for i in range(1,mask): prod=1 for j in range(3): if(i &(1<display() ) else skip; operation countMultiples(n : OclAny) : OclAny pre: true post: true activity: var multiple : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{ 5 })) ; var count : int := 0 ; var mask : int := ("" + (((2)->pow(3))))->toInteger() ; for i : Integer.subrange(1, mask-1) do ( var prod : int := 1 ; for j : Integer.subrange(0, 3-1) do ( if (MathLib.bitwiseAnd(i, (1 * (2->pow(j))))) then ( prod := prod * multiple[j+1] ) else skip) ; if (bin(i)->count('1') mod 2 = 1) then ( count := count + n div prod ) else ( count := count - n div prod )) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def volumeCuboid(l,h,w): return(l*h*w) def surfaceAreaCuboid(l,h,w): return(2*l*w+2*w*h+2*l*h) l=1 h=5 w=7 print("Volume=",volumeCuboid(l,h,w)) print("Total Surface Area=",surfaceAreaCuboid(l,h,w)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; l := 1 ; h := 5 ; w := 7 ; execute ("Volume=")->display() ; execute ("Total Surface Area=")->display(); operation volumeCuboid(l : OclAny, h : OclAny, w : OclAny) : OclAny pre: true post: true activity: return (l * h * w); operation surfaceAreaCuboid(l : OclAny, h : OclAny, w : OclAny) : OclAny pre: true post: true activity: return (2 * l * w + 2 * w * h + 2 * l * h); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isEqualBlock(n): first_bit=n % 2 first_count=1 n=n//2 while n % 2==first_bit and n>0 : n=n//2 first_count+=1 if n==0 : return False while n>0 : first_bit=n % 2 curr_count=1 n=n//2 while n % 2==first_bit : n=n//2 curr_count+=1 if curr_count!=first_count : return False return True if __name__=="__main__" : n=51 if isEqualBlock(n): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 51 ; if isEqualBlock(n) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isEqualBlock(n : OclAny) : OclAny pre: true post: true activity: var first_bit : int := n mod 2 ; var first_count : int := 1 ; n := n div 2 ; while n mod 2 = first_bit & n > 0 do ( n := n div 2 ; first_count := first_count + 1) ; if n = 0 then ( return false ) else skip ; while n > 0 do ( first_bit := n mod 2 ; var curr_count : int := 1 ; n := n div 2 ; while n mod 2 = first_bit do ( n := n div 2 ; curr_count := curr_count + 1) ; if curr_count /= first_count then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def averageOdd(n): if(n % 2==0): print("Invalid Input") return-1 return(n+1)//2 n=15 print(averageOdd(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 15 ; execute (averageOdd(n))->display(); operation averageOdd(n : OclAny) : OclAny pre: true post: true activity: if (n mod 2 = 0) then ( execute ("Invalid Input")->display() ; return -1 ) else skip ; return (n + 1) div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countNumber(n): return(pow(10,n)-1)-(pow(10,n)-pow(8,n))//2 n=2 print(countNumber(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 2 ; execute (countNumber(n))->display(); operation countNumber(n : OclAny) : OclAny pre: true post: true activity: return ((10)->pow(n) - 1) - ((10)->pow(n) - (8)->pow(n)) div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countNumbers(N): return(pow(10,N)-pow(8,N))//2 if __name__=="__main__" : n=5 print(countNumbers(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var n : int := 5 ; execute (countNumbers(n))->display() ) else skip; operation countNumbers(N : OclAny) : OclAny pre: true post: true activity: return ((10)->pow(N) - (8)->pow(N)) div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPalindrome(string : str,low : int,high : int)->bool : while lowint : low=0 high=len(string)-1 while lowdisplay() ) else (if idx = -2 then ( execute ("Possible without removig any character")->display() ) else ( execute ("Possible by removing character at index")->display() ) ) ) else skip; operation isPalindrome(string : String, low : int, high : int) : boolean pre: true post: true activity: while (low->compareTo(high)) < 0 do ( if string[low+1] /= string[high+1] then ( return false ) else skip ; low := low + 1 ; high := high - 1) ; return true; operation possiblepalinByRemovingOneChar(string : String) : int pre: true post: true activity: var low : int := 0 ; var high : double := (string)->size() - 1 ; while (low->compareTo(high)) < 0 do ( if string[low+1] = string[high+1] then ( low := low + 1 ; high := high - 1 ) else ( if isPalindrome(string, low + 1, high) then ( return low ) else skip ; if isPalindrome(string, low, high - 1) then ( return high ) else skip ; return -1 )) ; return -2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairsWithDiffK(arr,n,k): count=0 arr.sort() l=0 r=0 while rk : l+=1 else : r+=1 return count if __name__=='__main__' : arr=[1,5,3,4,2] n=len(arr) k=3 print("Count of pairs with given diff is ",countPairsWithDiffK(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{5}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 2 })))) ; n := (arr)->size() ; k := 3 ; execute ("Count of pairs with given diff is ")->display() ) else skip; operation countPairsWithDiffK(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; arr := arr->sort() ; var l : int := 0 ; var r : int := 0 ; while (r->compareTo(n)) < 0 do ( if arr[r+1] - arr[l+1] = k then ( count := count + 1 ; l := l + 1 ; r := r + 1 ) else (if (arr[r+1] - arr[l+1]->compareTo(k)) > 0 then ( l := l + 1 ) else ( r := r + 1 ) ) ) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os in_file=None out_file=None def run_main(main): name=sys.argv[0][:-3] in_file_name=name+".in" out_file_name=name+".out" if len(sys.argv)==2 : in_file_name=sys.argv[1] out_file_name=in_file_name[:-3]+".out" if len(sys.argv)==3 : if sys.argv[1]: in_file_name=sys.argv[1] if sys.argv[2]: out_file_name=sys.argv[2] global in_file global out_file if in_file_name=='-' : in_file=sys.stdin else : in_file=open(in_file_name,'r') if out_file_name=='-' : out_file=sys.stdout else : out_file=open(out_file_name,'w') main(in_file,out_file) out_file.close() in_file.close() def run_tests(do_testcase): def main(in_file,out_file): t=readinteger() for x in xrange(t): do_testcase(x+1) run_main(main) def readline(): return in_file.readline()[:-1] def writeline(s): out_file.write("%s\n" % s) def readinteger(): return int(readline()) def readintegers(): integers=readline().split() for i in xrange(len(integers)): integers[i]=int(integers[i]) return integers ------------------------------------------------------------ OCL File: --------- class FromPython { attribute in_file : OclAny; attribute out_file : OclAny; operation initialise() pre: true post: true activity: skip ; var in_file : OclAny := null ; var out_file : OclAny := null ; skip ; skip ; skip ; skip ; skip ; skip; operation run_main(main : OclAny) pre: true post: true activity: var name : OclAny := ((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))).subrange(1,-3) ; var in_file_name : int := name + ".in" ; var out_file_name : int := name + ".out" ; if ((trailer . (name argv)))->size() = 2 then ( in_file_name := (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) ; out_file_name := in_file_name.subrange(1,-3) + ".out" ) else skip ; if ((trailer . (name argv)))->size() = 3 then ( if (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) then ( in_file_name := (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) ) else skip ; if (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) then ( out_file_name := (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) ) else skip ) else skip ; skip ; skip ; if in_file_name = '-' then ( in_file := OclFile["System.in"] ) else ( in_file := OclFile.newOclFile_Write(OclFile.newOclFile(in_file_name)) ) ; if out_file_name = '-' then ( out_file := OclFile["System.out"] ) else ( out_file := OclFile.newOclFile_Write(OclFile.newOclFile(out_file_name)) ) ; main(in_file, out_file) ; out_file.closeFile() ; in_file.closeFile(); operation run_tests(do_testcase : OclAny) pre: true post: true activity: skip ; run_main(main); operation readline() : OclAny pre: true post: true activity: return in_file.readLine()->front(); operation writeline(s : OclAny) pre: true post: true activity: out_file.write(StringLib.format("%s\n",s)); operation readinteger() : OclAny pre: true post: true activity: return ("" + ((readline())))->toInteger(); operation readintegers() : OclAny pre: true post: true activity: var integers : OclAny := readline().split() ; for i : xrange((integers)->size()) do ( integers[i+1] := ("" + ((integers[i+1])))->toInteger()) ; return integers; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): import sys file_input=sys.stdin while True : N,Q=map(int,file_input.readline().split()) if N==0 : break parent=[None,None] parent+=[int(file_input.readline())for _ in range(N-1)] unmarked=[True]*(N+1) unmarked[1]=False ans=0 for _ in range(Q): line=file_input.readline() v=int(line[2 :]) if line[0]=='M' : unmarked[v]=False else : while unmarked[v]: v=parent[v] ans+=v print(ans) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: skip ; var file_input : OclFile := OclFile["System.in"] ; while true do ( var N : OclAny := null; var Q : OclAny := null; Sequence{N,Q} := (file_input.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if N = 0 then ( break ) else skip ; var parent : Sequence := Sequence{null}->union(Sequence{ null }) ; parent := parent + Integer.subrange(0, N - 1-1)->select(_anon | true)->collect(_anon | (("" + ((file_input.readLine())))->toInteger())) ; var unmarked : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (N + 1)) ; unmarked[1+1] := false ; var ans : int := 0 ; for _anon : Integer.subrange(0, Q-1) do ( var line : String := file_input.readLine() ; var v : int := ("" + ((line.subrange(2+1))))->toInteger() ; if line->first() = 'M' then ( unmarked[v+1] := false ) else ( while unmarked[v+1] do ( v := parent[v+1]) ; ans := ans + v )) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class UnionFind : def __init__(self,size): self.table=[None]*size def find(self,x): if self.table[x]==None : return x else : self.table[x]=self.find(self.table[x]) return self.table[x] def union(self,parent,child): p_root=self.find(parent) c_root=self.find(child) if p_root!=c_root : self.table[c_root]=p_root def solve(): import sys input_lines=sys.stdin.readlines() while True : N,Q=map(int,input_lines[0].split()) if N==0 : break unmarked=[True]*(N+1) unmarked[1]=False operation=[] for o in input_lines[N : N+Q]: mq,v=o.split() v=int(v) if mq=='M' : if unmarked[v]: unmarked[v]=False operation.append((mq,v)) else : operation.append((mq,v)) uf=UnionFind(N+1) parent=[None,1]+list(map(int,input_lines[1 : N])) for v,p in enumerate(parent[2 :],start=2): if unmarked[v]: uf.union(p,v) ans=0 for o,v in reversed(operation): if o=='M' : uf.union(parent[v],v) else : ans+=uf.find(v) print(ans) del input_lines[: N+Q] solve() ------------------------------------------------------------ OCL File: --------- class UnionFind { static operation newUnionFind() : UnionFind pre: true post: UnionFind->exists( _x | result = _x ); attribute table : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, size); operation initialise(size : OclAny) : UnionFind pre: true post: true activity: self.table := MatrixLib.elementwiseMult(Sequence{ null }, size); return self; operation find(x : OclAny) : OclAny pre: true post: true activity: if self.table[x+1] = null then ( return x ) else ( self.table[x+1] := self->indexOf(self.table[x+1]) - 1 ; return self.table[x+1] ); operation union(parent : OclAny,child : OclAny) pre: true post: true activity: var p_root : int := self->indexOf(parent) - 1 ; var c_root : int := self->indexOf(child) - 1 ; if p_root /= c_root then ( self.table[c_root+1] := p_root ) else skip; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; solve(); operation solve() pre: true post: true activity: skip ; var input_lines : OclAny := (OclFile["System.in"]).readlines() ; while true do ( var N : OclAny := null; var Q : OclAny := null; Sequence{N,Q} := (input_lines->first().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if N = 0 then ( break ) else skip ; var unmarked : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (N + 1)) ; unmarked[1+1] := false ; var operation : Sequence := Sequence{} ; for o : input_lines.subrange(N+1, N + Q) do ( var mq : OclAny := null; var v : OclAny := null; Sequence{mq,v} := o.split() ; var v : int := ("" + ((v)))->toInteger() ; if mq = 'M' then ( if unmarked[v+1] then ( unmarked[v+1] := false ; execute ((Sequence{mq, v}) : operation) ) else skip ) else ( execute ((Sequence{mq, v}) : operation) )) ; var uf : UnionFind := (UnionFind.newUnionFind()).initialise(N + 1) ; parent := Sequence{null}->union(Sequence{ 1 })->union(((input_lines.subrange(1+1, N))->collect( _x | (OclType["int"])->apply(_x) ))) ; for _tuple : Integer.subrange(1, (parent.subrange(2+1), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{_indx-1, (parent.subrange(2+1), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->at(_indx)} ) do (var _indx : int := 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p : OclAny := _tuple->at(_indx); if unmarked[v+1] then ( uf.union(p, v) ) else skip) ; var ans : int := 0 ; for _tuple : (operation)->reverse() do (var _indx : int := 1; var o : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if o = 'M' then ( uf.union(parent[v+1], v) ) else ( ans := ans + uf->indexOf(v) - 1 )) ; execute (ans)->display() ; execute (input_lines.subrange(1,N + Q))->isDeleted()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) menores,maiores,asc,nasc=[],[],0,0 for i in range(n): s=list(map(int,input().split()))[1 :] for i in range(len(s)): if i>0 and s[i]>s[i-1]: asc+=1 break elif i==len(s)-1 : nasc+=1 menores.append(min(s)) maiores.append(max(s)) resposta=asc*asc+2*asc*nasc menores.sort() maiores.sort() i=0 for x in maiores : while itoInteger() ; var menores : OclAny := null; var maiores : OclAny := null; var asc : OclAny := null; var nasc : OclAny := null; Sequence{menores,maiores,asc,nasc} := Sequence{Sequence{},Sequence{},0,0} ; for i : Integer.subrange(0, n-1) do ( var s : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->tail() ; for i : Integer.subrange(0, (s)->size()-1) do ( if i > 0 & (s[i+1]->compareTo(s[i - 1+1])) > 0 then ( asc := asc + 1 ; break ) else (if i = (s)->size() - 1 then ( nasc := nasc + 1 ; execute (((s)->min()) : menores) ; execute (((s)->max()) : maiores) ) else skip))) ; var resposta : double := asc * asc + 2 * asc * nasc ; menores := menores->sort() ; maiores := maiores->sort() ; var i : int := 0 ; for x : maiores do ( while (i->compareTo(nasc)) < 0 & (menores[i+1]->compareTo(x)) < 0 do ( i := i + 1) ; resposta := resposta + i) ; execute (resposta)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import pi while 1 : r=float(input()) if r==0 : break n=d=1 while abs(n/d-pi)>r : if n/dtoReal() ; if r = 0 then ( break ) else skip ; var n : OclAny := 1; var d : int := 1 ; while ((n / d - pi)->abs()->compareTo(r)) > 0 do ( if (n / d->compareTo(pi)) < 0 then ( n := n + 1 ) else ( d := d + 1 )) ; execute (StringLib.format('%d/%d',Sequence{n, d}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def root(x): while P[x]!=x : x=P[x] return x def mark(x): P[x-1]=x-1 def query(x): v=root(x-1)+1 return v while True : N,Q=map(int,input().strip().split(" ")) if N==Q==0 : break P=[] P.append(0) for i in range(N-1): p_i=int(input().strip())-1 P.append(p_i) s=0 for j in range(Q): op=input().strip().split(" ") if op[0]=="M" : mark(int(op[1])) else : s+=query(int(op[1])) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; while true do ( var N : OclAny := null; var Q : OclAny := null; Sequence{N,Q} := (input()->trim().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; if N = Q & (Q == 0) then ( break ) else skip ; var P : Sequence := Sequence{} ; execute ((0) : P) ; for i : Integer.subrange(0, N - 1-1) do ( var p_i : double := ("" + ((input()->trim())))->toInteger() - 1 ; execute ((p_i) : P)) ; var s : int := 0 ; for j : Integer.subrange(0, Q-1) do ( var op : OclAny := input()->trim().split(" ") ; if op->first() = "M" then ( mark(("" + ((op[1+1])))->toInteger()) ) else ( s := s + query(("" + ((op[1+1])))->toInteger()) )) ; execute (s)->display()); operation root(x : OclAny) : OclAny pre: true post: true activity: while P[x+1] /= x do ( x := P[x+1]) ; return x; operation mark(x : OclAny) pre: true post: true activity: P[x - 1+1] := x - 1; operation query(x : OclAny) : OclAny pre: true post: true activity: var v : OclAny := root(x - 1) + 1 ; return v; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import io,os input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline from collections import deque n=int(input()) neigh=[[]for i in range(n)] for i in range(n-1): u,v=map(int,input().split()) neigh[v-1].append(u-1) neigh[u-1].append(v-1) for i in range(n): if len(neigh[i])==1 : root=i break queue=deque() visited=[False]*n visited[root]=True queue.append([root,0]) leafneigh={} maximum=n-1 odd=0 even=0 while queue : [index,d]=queue.popleft() if len(neigh[index])==1 : if neigh[index][0]not in leafneigh : leafneigh[neigh[index][0]]=d if d % 2==0 : odd+=1 else : even+=1 else : maximum-=1 for ele in neigh[index]: if visited[ele]: continue visited[ele]=True queue.append([ele,d+1]) if min(odd,even)==0 : minimum=1 else : minimum=3 print(minimum,maximum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var neigh : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, n - 1-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name neigh)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name u))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name neigh)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name u))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1)))))))))) ))))) ; for i : Integer.subrange(0, n-1) do ( if (neigh[i+1])->size() = 1 then ( var root : OclAny := i ; break ) else skip) ; var queue : Sequence := () ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ; visited[root+1] := true ; execute ((Sequence{root}->union(Sequence{ 0 })) : queue) ; var leafneigh : OclAny := Set{} ; var maximum : double := n - 1 ; var odd : int := 0 ; var even : int := 0 ; while queue do ( ; Sequence{index}->union(Sequence{ d }) := queue->first() ; queue := queue->tail() ; if (neigh[index+1])->size() = 1 then ( if (leafneigh)->excludes(neigh[index+1]->first()) then ( leafneigh[neigh[index+1]->first()+1] := d ; if d mod 2 = 0 then ( odd := odd + 1 ) else ( even := even + 1 ) ) else ( maximum := maximum - 1 ) ) else skip ; for ele : neigh[index+1] do ( if visited[ele+1] then ( continue ) else skip ; visited[ele+1] := true ; execute ((Sequence{ele}->union(Sequence{ d + 1 })) : queue))) ; if Set{odd, even}->min() = 0 then ( var minimum : int := 1 ) else ( minimum := 3 ) ; execute (minimum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class UnionFind : def __init__(self,size): self.parent=list(range(size)) def find(self,x): if self.parent[x]!=x : self.parent[x]=self.find(self.parent[x]) return self.parent[x] def unite(self,x,y): x=self.find(x) y=self.find(y) if x==y : return self.parent[x]=y def same(self,x,y): return self.find(x)==self.find(y) while True : N,Q=map(int,input().split()) if N==Q==0 : break parent=[0,1]+[int(input())for i in range(2,N+1)] queries=[] marked=set([1]) for i in range(Q): o,v=input().split() v=int(v) if o=='M' : if v in marked : continue marked.add(v) queries.append((o,v)) uf=UnionFind(N+1) for i in range(1,N+1): if i not in marked : uf.unite(i,parent[i]) ans=0 for o,v in reversed(queries): if o=='M' : uf.unite(v,parent[v]) else : ans+=uf.find(v) print(ans) ------------------------------------------------------------ OCL File: --------- class UnionFind { static operation newUnionFind() : UnionFind pre: true post: UnionFind->exists( _x | result = _x ); attribute parent : Sequence := (Integer.subrange(0, size-1)); operation initialise(size : OclAny) : UnionFind pre: true post: true activity: self.parent := (Integer.subrange(0, size-1)); return self; operation find(x : OclAny) : OclAny pre: true post: true activity: if self.parent[x+1] /= x then ( self.parent[x+1] := self->indexOf(self.parent[x+1]) - 1 ) else skip ; return self.parent[x+1]; operation unite(x : OclAny,y : OclAny) pre: true post: true activity: x := self->indexOf(x) - 1 ; y := self->indexOf(y) - 1 ; if x = y then ( return ) else skip ; self.parent[x+1] := y; operation same(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: return self->indexOf(x) - 1 = self->indexOf(y) - 1; } class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var N : OclAny := null; var Q : OclAny := null; Sequence{N,Q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if N = Q & (Q == 0) then ( break ) else skip ; var parent : Sequence := Sequence{0}->union(Sequence{ 1 })->union(Integer.subrange(2, N + 1-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))) ; var queries : Sequence := Sequence{} ; var marked : Set := Set{}->union((Sequence{ 1 })) ; for i : Integer.subrange(0, Q-1) do ( var o : OclAny := null; var v : OclAny := null; Sequence{o,v} := input().split() ; var v : int := ("" + ((v)))->toInteger() ; if o = 'M' then ( if (marked)->includes(v) then ( continue ) else skip ; execute ((v) : marked) ) else skip ; execute ((Sequence{o, v}) : queries)) ; var uf : UnionFind := (UnionFind.newUnionFind()).initialise(N + 1) ; for i : Integer.subrange(1, N + 1-1) do ( if (marked)->excludes(i) then ( uf.unite(i, parent[i+1]) ) else skip) ; var ans : int := 0 ; for _tuple : (queries)->reverse() do (var _indx : int := 1; var o : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if o = 'M' then ( uf.unite(v, parent[v+1]) ) else ( ans := ans + uf->indexOf(v) - 1 )) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def root(x): while P[x-1]!=x : x=P[x-1] return x def mark(x): P[x-1]=x while True : n,q=map(int,input().split()) res=0 if n==0 : break P=[1] for _ in range(n-1): P.append(int(input())) for _ in range(q): com,num=map(str,input().split()) if com=="Q" : res+=root(int(num)) else : mark(int(num)) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var res : int := 0 ; if n = 0 then ( break ) else skip ; var P : Sequence := Sequence{ 1 } ; for _anon : Integer.subrange(0, n - 1-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : P)) ; for _anon : Integer.subrange(0, q-1) do ( var com : OclAny := null; var num : OclAny := null; Sequence{com,num} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; if com = "Q" then ( res := res + root(("" + ((num)))->toInteger()) ) else ( mark(("" + ((num)))->toInteger()) )) ; execute (res)->display()); operation root(x : OclAny) : OclAny pre: true post: true activity: while P[x - 1+1] /= x do ( x := P[x - 1+1]) ; return x; operation mark(x : OclAny) pre: true post: true activity: P[x - 1+1] := x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def factorial(n): f=1 for i in range(2,n+1): f*=i return f def series(A,X,n): nFact=factorial(n) for i in range(0,n+1): niFact=factorial(n-i) iFact=factorial(i) aPow=pow(A,n-i) xPow=pow(X,i) print(int((nFact*aPow*xPow)/(niFact*iFact)),end=" ") A=3 ; X=4 ; n=5 series(A,X,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; A := 3; X := 4; n := 5 ; series(A, X, n); operation factorial(n : OclAny) : OclAny pre: true post: true activity: var f : int := 1 ; for i : Integer.subrange(2, n + 1-1) do ( f := f * i) ; return f; operation series(A : OclAny, X : OclAny, n : OclAny) pre: true post: true activity: var nFact : OclAny := factorial(n) ; for i : Integer.subrange(0, n + 1-1) do ( var niFact : OclAny := factorial(n - i) ; var iFact : OclAny := factorial(i) ; var aPow : double := (A)->pow(n - i) ; var xPow : double := (X)->pow(i) ; execute (("" + (((nFact * aPow * xPow) / (niFact * iFact))))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def floorSqrt(x): if(x==0 or x==1): return x i=1 ; result=1 while(result<=x): i+=1 result=i*i return i-1 x=11 print(floorSqrt(x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := 11 ; execute (floorSqrt(x))->display(); operation floorSqrt(x : OclAny) : OclAny pre: true post: true activity: if (x = 0 or x = 1) then ( return x ) else skip ; var i : int := 1; var result : int := 1 ; while ((result->compareTo(x)) <= 0) do ( i := i + 1 ; result := i * i) ; return i - 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=(int(x)for x in input().split()) a,b,c,d=sorted([a,b,c,d]) if a==b and c==d : print("yes") else : print("no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := Sequence{a}->union(Sequence{b}->union(Sequence{c}->union(Sequence{ d })))->sort() ; if a = b & c = d then ( execute ("yes")->display() ) else ( execute ("no")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=list(map(int,input().split())) a=sorted(a) if a[0]==a[1]and a[2]==a[3]: print("yes") else : print("no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; if a->first() = a[1+1] & a[2+1] = a[3+1] then ( execute ("yes")->display() ) else ( execute ("no")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- e1,e2,e3,e4=map(int,input().split()) E=[e1,e2,e3,e4] e=set(E) e_list=list(e) if len(e)==2 : if E.count(e_list[0])==2 : print("yes") else : print("no") else : print("no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var e1 : OclAny := null; var e2 : OclAny := null; var e3 : OclAny := null; var e4 : OclAny := null; Sequence{e1,e2,e3,e4} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var E : Sequence := Sequence{e1}->union(Sequence{e2}->union(Sequence{e3}->union(Sequence{ e4 }))) ; var e : Set := Set{}->union((E)) ; var e_list : Sequence := (e) ; if (e)->size() = 2 then ( if E->count(e_list->first()) = 2 then ( execute ("yes")->display() ) else ( execute ("no")->display() ) ) else ( execute ("no")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- e1,e2,e3,e4=map(int,input().split()) if(e1==e2)&((e2==e3==e4)or(e3==e4)): print("yes") elif(e2==e3)&((e3==e1==e4)or(e1==e4)): print("yes") elif(e3==e4)&((e4==e1==e2)or(e1==e2)): print("yes") elif(e4==e1)&((e1==e2==e3)or(e2==e3)): print("yes") else : print("no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var e1 : OclAny := null; var e2 : OclAny := null; var e3 : OclAny := null; var e4 : OclAny := null; Sequence{e1,e2,e3,e4} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if MathLib.bitwiseAnd((e1 = e2), ((e2 = e3 & (e3 == e4)) or (e3 = e4))) then ( execute ("yes")->display() ) else (if MathLib.bitwiseAnd((e2 = e3), ((e3 = e1 & (e1 == e4)) or (e1 = e4))) then ( execute ("yes")->display() ) else (if MathLib.bitwiseAnd((e3 = e4), ((e4 = e1 & (e1 == e2)) or (e1 = e2))) then ( execute ("yes")->display() ) else (if MathLib.bitwiseAnd((e4 = e1), ((e1 = e2 & (e2 == e3)) or (e2 = e3))) then ( execute ("yes")->display() ) else ( execute ("no")->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=sorted(map(int,input().split())) print(['no','yes'][a==b and c==d]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; execute (Sequence{'no'}->union(Sequence{ 'yes' })->select(a = b & c = d))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(1,10): for j in range(1,10): print(str(i)+"x"+str(j)+"="+str((i)*(j))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(1, 10-1) do ( for j : Integer.subrange(1, 10-1) do ( execute (("" + ((i))) + "x" + ("" + ((j))) + "=" + ("" + (((i) * (j)))))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) edges=[[]for x in range(n+1)] for i in range(n-1): x,y=map(int,input().split()) edges[x].append(y) edges[y].append(x) root=-1 leaf=[False]*(n+1) for i in range(1,n+1): if len(edges[i])==1 : leaf[i]=True mx=n-1 for i in range(1,n+1): if leaf[i]: root=i lfs=0 for nv in edges[i]: if leaf[nv]: lfs+=1 if lfs>1 : mx-=lfs-1 stack=[(root,-1,0)] flag=True while stack : cur,par,dist=stack.pop() if dist % 2 and leaf[cur]: flag=False break for nv in edges[cur]: if nv!=par : stack.append((nv,cur,dist+1)) print(1 if flag else 3,mx) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var edges : Sequence := Integer.subrange(0, n + 1-1)->select(x | true)->collect(x | (Sequence{})) ; for i : Integer.subrange(0, n - 1-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))) ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))) ; var root : int := -1 ; var leaf : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (n + 1)) ; for i : Integer.subrange(1, n + 1-1) do ( if (edges[i+1])->size() = 1 then ( leaf[i+1] := true ) else skip) ; var mx : double := n - 1 ; for i : Integer.subrange(1, n + 1-1) do ( if leaf[i+1] then ( root := i ) else skip ; var lfs : int := 0 ; for nv : edges[i+1] do ( if leaf[nv+1] then ( lfs := lfs + 1 ) else skip) ; if lfs > 1 then ( mx := mx - lfs - 1 ) else skip) ; var stack : Sequence := Sequence{ Sequence{root, -1, 0} } ; var flag : boolean := true ; while stack do ( var cur : OclAny := null; var par : OclAny := null; var dist : OclAny := null; Sequence{cur,par,dist} := stack->last() ; stack := stack->front() ; if dist mod 2 & leaf[cur+1] then ( flag := false ; break ) else skip ; for nv : edges[cur+1] do ( if nv /= par then ( execute ((Sequence{nv, cur, dist + 1}) : stack) ) else skip)) ; execute (if flag then 1 else 3 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) cnt=0 for i in range(n): if b[i]<=a[i]: cnt+=b[i] else : cnt+=a[i] c=b[i]-a[i] if c<=a[i+1]: cnt+=c a[i+1]-=c else : cnt+=a[i+1] a[i+1]=0 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (b[i+1]->compareTo(a[i+1])) <= 0 then ( cnt := cnt + b[i+1] ) else ( cnt := cnt + a[i+1] ; var c : double := b[i+1] - a[i+1] ; if (c->compareTo(a[i + 1+1])) <= 0 then ( cnt := cnt + c ; a[i + 1+1] := a[i + 1+1] - c ) else ( cnt := cnt + a[i + 1+1] ; a[i + 1+1] := 0 ) )) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import defaultdict,Counter,deque from itertools import accumulate,permutations,combinations from operator import itemgetter from bisect import bisect_left,bisect_right,bisect from heapq import heappop,heappush from fractions import gcd from math import ceil,floor,sqrt,cos,sin,pi from copy import deepcopy def main(): N=int(input()) A=list(map(int,input().split())) B=list(map(int,input().split())) ans=0 k=min(A[0],B[0]) ans+=k A[0]-=k B[0]-=k for i in range(1,N): k=min(A[i],B[i-1]) ans+=k A[i]-=k B[i-1]-=k k=min(A[i],B[i]) ans+=k A[i]-=k B[i]-=k k=min(A[-1],B[-1]) ans+=k print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var B : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; var k : OclAny := Set{A->first(), B->first()}->min() ; ans := ans + k ; A->first() := A->first() - k ; B->first() := B->first() - k ; for i : Integer.subrange(1, N-1) do ( k := Set{A[i+1], B[i - 1+1]}->min() ; ans := ans + k ; A[i+1] := A[i+1] - k ; B[i - 1+1] := B[i - 1+1] - k ; k := Set{A[i+1], B[i+1]}->min() ; ans := ans + k ; A[i+1] := A[i+1] - k ; B[i+1] := B[i+1] - k) ; k := Set{A->last(), B->last()}->min() ; ans := ans + k ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys p=[[int(c)for c in r.split()]for r in sys.stdin.read().split('\n')if r!=''] n=p[0][0] a=p[1] b=p[2] c=0 k=0 for i in range(n): v=min(a[i],k) w=min(b[i],a[i]-v) c+=v+w k=b[i]-w v=min(a[-1],k) print(c+v) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var p : Sequence := sys.stdin.readAll().split(' ')->select(r | r /= '')->collect(r | (r.split()->select(c | true)->collect(c | (("" + ((c)))->toInteger())))) ; var n : OclAny := p->first()->first() ; var a : OclAny := p[1+1] ; var b : OclAny := p[2+1] ; var c : int := 0 ; var k : int := 0 ; for i : Integer.subrange(0, n-1) do ( var v : OclAny := Set{a[i+1], k}->min() ; var w : OclAny := Set{b[i+1], a[i+1] - v}->min() ; c := c + v + w ; k := b[i+1] - w) ; v := Set{a->last(), k}->min() ; execute (c + v)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) A=tuple(map(int,input().split())) B=tuple(map(int,input().split())) ans,a1=0,A[0] for a2,b in zip(A[1 :],B): cnt1=min(a1,b) cnt2=min(a2,b-cnt1) ans+=cnt1+cnt2 a1=a2-cnt2 print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var B : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : OclAny := null; var a1 : OclAny := null; Sequence{ans,a1} := Sequence{0,A->first()} ; for _tuple : Integer.subrange(1, A->tail()->size())->collect( _indx | Sequence{A->tail()->at(_indx), B->at(_indx)} ) do (var _indx : int := 1; var a2 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); var cnt1 : OclAny := Set{a1, b}->min() ; var cnt2 : OclAny := Set{a2, b - cnt1}->min() ; ans := ans + cnt1 + cnt2 ; var a1 : double := a2 - cnt2) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import itertools import collections import heapq import re import numpy as np rr=lambda : sys.stdin.readline().rstrip() rs=lambda : map(str,sys.stdin.buffer.readline().split()) ri=lambda : int(sys.stdin.buffer.readline()) rm=lambda : map(int,sys.stdin.buffer.readline().split()) rl=lambda : list(map(int,sys.stdin.buffer.readline().split())) n=ri() a=rl() b=rl() cnt=0 for i in range(n): ai=a[i] bi=b[i] if bi>ai : cnt+=ai bi-=ai ai1=a[i+1] if bi>ai1 : cnt+=ai1 a[i+1]=0 else : a[i+1]-=bi cnt+=bi else : cnt+=bi print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var rr : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var rs : Function := lambda $$ : OclAny in ((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["String"])->apply(_x) )) ; var ri : Function := lambda $$ : OclAny in (("" + ((sys.stdin.buffer.readLine())))->toInteger()) ; var rm : Function := lambda $$ : OclAny in ((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var rl : Function := lambda $$ : OclAny in (((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var n : OclAny := ri->apply() ; var a : OclAny := rl->apply() ; var b : OclAny := rl->apply() ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( var ai : OclAny := a[i+1] ; var bi : OclAny := b[i+1] ; if (bi->compareTo(ai)) > 0 then ( cnt := cnt + ai ; bi := bi - ai ; var ai1 : OclAny := a[i + 1+1] ; if (bi->compareTo(ai1)) > 0 then ( cnt := cnt + ai1 ; a[i + 1+1] := 0 ) else ( a[i + 1+1] := a[i + 1+1] - bi ; cnt := cnt + bi ) ) else ( cnt := cnt + bi )) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline N=int(readline()) A=list(map(int,readline().split())) S=sum(A) bits=1 for a in A : bits |=bits<>=ans while True : if bits & 1 : print(ans) exit() bits>>=1 ans+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var N : int := ("" + ((readline())))->toInteger() ; var A : Sequence := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var S : OclAny := (A)->sum() ; var bits : int := 1 ; for a : A do ( bits := bits or bits * (2->pow(a))) ; var ans : int := (S + 1) div 2 ; bits := bits div (2->pow(ans)) ; while true do ( if MathLib.bitwiseAnd(bits, 1) then ( execute (ans)->display() ; exit() ) else skip ; bits := bits div (2->pow(1)) ; ans := ans + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() a=list(map(int,input().split())) dp=1 for x in a : dp |=dp<>=(s+1)//2 dp<<=(s+1)//2 dp=bin(dp) print(len(dp)-len(dp.rstrip('0'))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dp : int := 1 ; for x : a do ( dp := dp or dp * (2->pow(x))) ; var s : OclAny := (a)->sum() ; dp := dp div (2->pow((s + 1) div 2)) ; dp := dp * (2->pow((s + 1) div 2)) ; dp := bin(dp) ; execute ((dp)->size() - (dp.rstrip('0'))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(i)for i in input().split()] dp=1 for i in range(0,len(a)): dp=(dp |(dp<>i)& 1 : print(i) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var dp : int := 1 ; for i : Integer.subrange(0, (a)->size()-1) do ( dp := (MathLib.bitwiseOr(dp, (dp * (2->pow(a[i+1])))))) ; var asum : int := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( asum := asum + a[i+1]) ; for i : Integer.subrange(("" + (((asum + 1) / 2)))->toInteger(), asum + 1-1) do ( if MathLib.bitwiseAnd((dp /(2->pow(i))), 1) then ( execute (i)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline import numpy as np N=int(input()) A=[int(x)for x in input().split()] S=sum(A) dp=np.zeros(S+1,dtype=np.bool) dp[S]=1 for a in A : dp[:-a]|=dp[a :] answer=np.nonzero(dp[(S+1)//2 :])[0][0]+(S+1)//2 print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var S : OclAny := (A)->sum() ; var dp : Sequence := MatrixLib.singleValueMatrix(S + 1, 0.0) ; dp[S+1] := 1 ; for a : A do ( dp.subrange(1,-a) := dp.subrange(1,-a) or dp.subrange(a+1)) ; var answer : OclAny := np.nonzero(dp.subrange((S + 1) div 2+1))->first()->first() + (S + 1) div 2 ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil N=int(input()) A=[int(a)for a in input().split()] DP=1 for a in A : DP |=DP<>=Shalf for i in range(N*max(A)): if DP & 1 : print(Shalf+i) break DP>>=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; var DP : int := 1 ; for a : A do ( DP := DP or DP * (2->pow(a))) ; var Shalf : OclAny := ceil((A)->sum() / 2) ; DP := DP div (2->pow(Shalf)) ; for i : Integer.subrange(0, N * (A)->max()-1) do ( if MathLib.bitwiseAnd(DP, 1) then ( execute (Shalf + i)->display() ; break ) else skip ; DP := DP div (2->pow(1))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def areElementsContiguous(arr): us=set() for i in arr : us.add(i) count=1 curr_ele=arr[0]-1 while curr_ele in us : count+=1 curr_ele-=1 curr_ele=arr[0]+1 while curr_ele in us : count+=1 curr_ele+=1 return(count==len(us)) arr=[5,2,3,6,4,4,6,6] if areElementsContiguous(arr): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{5}->union(Sequence{2}->union(Sequence{3}->union(Sequence{6}->union(Sequence{4}->union(Sequence{4}->union(Sequence{6}->union(Sequence{ 6 }))))))) ; if areElementsContiguous(arr) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation areElementsContiguous(arr : OclAny) : OclAny pre: true post: true activity: var us : Set := Set{}->union(()) ; for i : arr do ( execute ((i) : us)) ; var count : int := 1 ; var curr_ele : double := arr->first() - 1 ; while (us)->includes(curr_ele) do ( count := count + 1 ; curr_ele := curr_ele - 1) ; curr_ele := arr->first() + 1 ; while (us)->includes(curr_ele) do ( count := count + 1 ; curr_ele := curr_ele + 1) ; return (count = (us)->size()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print("\n".join(["%dx%d=%d" %(i,j,i*j)for i in range(1,10)for j in range(1,10)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (StringLib.sumStringsWithSeparator((Integer.subrange(1, 10-1)->select(i; j : Integer.subrange(1, 10-1) | true)->collect(i; j : Integer.subrange(1, 10-1) | (StringLib.format("%dx%d=%d",Sequence{i, j, i * j})))), "\n"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- read=map(int,open(0).readlines()).__next__ ans=[] while 1 : D=read() if D==0 : break N=read() M=read() P=[read()for i in range(N-1)] P.append(0); P.append(D) Q=[read()for i in range(M)] P.sort(); Q.sort() it=iter(P).__next__ prv=0 ; nxt=it(); idx=0 res=0 for q in Q : while nxt<=q : prv=nxt ; nxt=it() res+=min(q-prv,nxt-q) ans.append("%d\n" % res) open(1,'w').writelines(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var read : OclAny := map(OclType["int"], open(0).readlines()).__next__ ; var ans : Sequence := Sequence{} ; while 1 do ( var D : OclAny := read() ; if D = 0 then ( break ) else skip ; var N : OclAny := read() ; var M : OclAny := read() ; var P : Sequence := Integer.subrange(0, N - 1-1)->select(i | true)->collect(i | (read())) ; execute ((0) : P); execute ((D) : P) ; var Q : Sequence := Integer.subrange(0, M-1)->select(i | true)->collect(i | (read())) ; P := P->sort(); Q := Q->sort() ; var it : OclAny := iter(P).__next__ ; var prv : int := 0; var nxt : OclAny := it(); var idx : int := 0 ; var res : int := 0 ; for q : Q do ( while (nxt->compareTo(q)) <= 0 do ( prv := nxt; nxt := it()) ; res := res + Set{q - prv, nxt - q}->min()) ; execute ((StringLib.format("%d\n",res)) : ans)) ; (expr (atom (name open)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom 'w'))))))) ))) (trailer . (name writelines) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def search_min_route(d,n_list,m_list): result=0 n_list.sort() n_list.append(d) for m in m_list : result+=bs_min(n_list,m) return result def bs_min(n_list,m): left=0 right=len(n_list)-1 count=0 while abs(right-left)!=1 : mid=int((right-left)/2+left) if n_list[mid]==m : return 0 elif n_list[mid]>m : right=mid else : left=mid count+=1 return min(abs(n_list[left]-m),abs(n_list[right]-m)) def main(): data_list=[] d=int(input()) while d!=0 : n=int(input()) m=int(input()) n_list=[] m_list=[] n_list.append(0) for i in range(n-1): n_list.append(int(input())) for i in range(m): m_list.append(int(input())) new_list=[d,n,m,n_list,m_list] data_list.append(new_list) d=int(input()) for data in data_list : print(search_min_route(data[0],data[3],data[4])) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation search_min_route(d : OclAny, n_list : OclAny, m_list : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; n_list := n_list->sort() ; execute ((d) : n_list) ; for m : m_list do ( result := result + bs_min(n_list, m)) ; return result; operation bs_min(n_list : OclAny, m : OclAny) : OclAny pre: true post: true activity: var left : int := 0 ; var right : double := (n_list)->size() - 1 ; var count : int := 0 ; while (right - left)->abs() /= 1 do ( var mid : int := ("" + (((right - left) / 2 + left)))->toInteger() ; if n_list[mid+1] = m then ( return 0 ) else (if (n_list[mid+1]->compareTo(m)) > 0 then ( right := mid ) else ( left := mid ) ) ; count := count + 1) ; return Set{(n_list[left+1] - m)->abs(), (n_list[right+1] - m)->abs()}->min(); operation main() pre: true post: true activity: var data_list : Sequence := Sequence{} ; d := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while d /= 0 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; m := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; n_list := Sequence{} ; m_list := Sequence{} ; execute ((0) : n_list) ; for i : Integer.subrange(0, n - 1-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : n_list)) ; for i : Integer.subrange(0, m-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : m_list)) ; var new_list : Sequence := Sequence{d}->union(Sequence{n}->union(Sequence{m}->union(Sequence{n_list}->union(Sequence{ m_list })))) ; execute ((new_list) : data_list) ; d := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; for data : data_list do ( execute (search_min_route(data->first(), data[3+1], data[4+1]))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys file_input=sys.stdin d=int(file_input.readline()) import bisect def calc_distance(destination): p=bisect.bisect(shop,destination) d1=shop[p]-destination d2=destination-shop[p-1] return min(d1,d2) while d : n=int(file_input.readline()) m=int(file_input.readline()) shop=[int(file_input.readline())for i in range(n-1)] shop.append(0) shop.append(d) shop.sort() k=(int(file_input.readline())for i in range(m)) ans=sum(map(calc_distance,k)) print(ans) d=int(file_input.readline()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var file_input : OclFile := OclFile["System.in"] ; var d : int := ("" + ((file_input.readLine())))->toInteger() ; skip ; skip ; while d do ( var n : int := ("" + ((file_input.readLine())))->toInteger() ; var m : int := ("" + ((file_input.readLine())))->toInteger() ; var shop : Sequence := Integer.subrange(0, n - 1-1)->select(i | true)->collect(i | (("" + ((file_input.readLine())))->toInteger())) ; execute ((0) : shop) ; execute ((d) : shop) ; shop := shop->sort() ; var k : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name file_input)) (trailer . (name readline) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name m)))))))) ))))))))} ; var ans : OclAny := ((k)->collect( _x | (calc_distance)->apply(_x) ))->sum() ; execute (ans)->display() ; d := ("" + ((file_input.readLine())))->toInteger()); operation calc_distance(destination : OclAny) : OclAny pre: true post: true activity: var p : OclAny := bisect.bisect(shop, destination) ; var d1 : double := shop[p+1] - destination ; var d2 : double := destination - shop[p - 1+1] ; return Set{d1, d2}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import sys sys.setrecursionlimit(10**9) input=sys.stdin.readline def solve(): d=int(input()) if d==0 : return False n=int(input()) m=int(input()) stores=[int(input())for _ in range(n-1)] stores=[0]+sorted(stores)+[d] ret=0 for _ in range(m): dest=int(input()) l=bisect.bisect_right(stores,dest) dist=min(stores[l]-dest,dest-stores[l-1]) ret+=dist return ret ans=[] while True : a=solve() if a : ans.append(a) else : break print("\n".join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var ans : Sequence := Sequence{} ; while true do ( var a : OclAny := solve() ; if a then ( execute ((a) : ans) ) else ( break )) ; execute (StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), "\n"))->display(); operation solve() : OclAny pre: true post: true activity: var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if d = 0 then ( return false ) else skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var stores : Sequence := Integer.subrange(0, n - 1-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; stores := Sequence{ 0 }->union(stores->sort())->union(Sequence{ d }) ; var ret : int := 0 ; for _anon : Integer.subrange(0, m-1) do ( var dest : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : OclAny := bisect.bisect_right(stores, dest) ; var dist : OclAny := Set{stores[l+1] - dest, dest - stores[l - 1+1]}->min() ; ret := ret + dist) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left while True : d=int(input()) if not d : break n=int(input()) m=int(input()) stores={0,d} for i in range(2,n+1): stores.add(int(input())) sorted_stores=sorted(stores) total_dist=0 while m : k=int(input()) i=bisect_left(sorted_stores,k) if i : l,r=sorted_stores[i-1 : i+1] total_dist+=min(k-l,r-k) m-=1 print(total_dist) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(d) then ( break ) else skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var stores : Set := Set{0}->union(Set{ d }) ; for i : Integer.subrange(2, n + 1-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : stores)) ; var sorted_stores : Sequence := stores->sort() ; var total_dist : int := 0 ; while m do ( var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : OclAny := bisect_left(sorted_stores, k) ; if i then ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := sorted_stores.subrange(i - 1+1, i + 1) ; total_dist := total_dist + Set{k - l, r - k}->min() ) else skip ; m := m - 1) ; execute (total_dist)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def is_possible(s): l=len(s) one=0 zero=0 for i in range(0,l): if(s[i]=='0'): zero+=1 else : one+=1 if(l % 2==0): return(one==zero) else : return(abs(one-zero)==1) if __name__=="__main__" : s="100110" if(is_possible(s)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "100110" ; if (is_possible(s)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation is_possible(s : OclAny) : OclAny pre: true post: true activity: var l : int := (s)->size() ; var one : int := 0 ; var zero : int := 0 ; for i : Integer.subrange(0, l-1) do ( if (s[i+1] = '0') then ( zero := zero + 1 ) else ( one := one + 1 )) ; if (l mod 2 = 0) then ( return (one = zero) ) else ( return ((one - zero)->abs() = 1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): s=0 p=int(input()) x=list(map(int,input().split())) if len(x)==2*p : for z in x : if z % 2!=0 : s+=1 if s==p : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var s : int := 0 ; var p : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (x)->size() = 2 * p then ( for z : x do ( if z mod 2 /= 0 then ( s := s + 1 ) else skip) ) else skip ; if s = p then ( execute ('Yes')->display() ) else ( execute ('No')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): size=int(input()) arr=list(map(int,input().split())) odd=0 even=0 for i in range(2*size): if arr[i]% 2==0 : odd+=1 else : even+=1 if odd==even : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var size : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var odd : int := 0 ; var even : int := 0 ; for i : Integer.subrange(0, 2 * size-1) do ( if arr[i+1] mod 2 = 0 then ( odd := odd + 1 ) else ( even := even + 1 )) ; if odd = even then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) for i in range(a): b=int(input()) ec=0 oc=0 arr=[int(num)for num in input().split()] for num in arr : if num % 2==0 : ec+=1 else : oc+=1 if ec==oc : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, a-1) do ( var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ec : int := 0 ; var oc : int := 0 ; var arr : Sequence := input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; for num : arr do ( if num mod 2 = 0 then ( ec := ec + 1 ) else ( oc := oc + 1 )) ; if ec = oc then ( execute ('Yes')->display() ) else ( execute ('No')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque zero=deque() one=deque() def getLeftMostZero(): if not len(zero): return-1 zero.popleft() return 0 def getLeftMostOne(): if not len(one): return-1 one.popleft() return 1 def getLeftMostElement(): if not len(zero)and not len(one): return-1 elif not len(zero): one.popleft() return 1 elif not len(one): zero.popleft() return 0 res=0 if zero[0]union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })))) ; var n : int := (arr)->size() ; var queries : Sequence := Sequence{1}->union(Sequence{3}->union(Sequence{ 1 })) ; var q : int := (queries)->size() ; performQueries(arr, n, queries, q) ) else skip; operation getLeftMostZero() : OclAny pre: true post: true activity: if not((zero)->size()) then ( return -1 ) else skip ; zero := zero->tail() ; return 0; operation getLeftMostOne() : OclAny pre: true post: true activity: if not((one)->size()) then ( return -1 ) else skip ; one := one->tail() ; return 1; operation getLeftMostElement() : OclAny pre: true post: true activity: if not((zero)->size()) & not((one)->size()) then ( return -1 ) else (if not((zero)->size()) then ( one := one->tail() ; return 1 ) else (if not((one)->size()) then ( zero := zero->tail() ; return 0 ) else skip ) ) ; var res : int := if (zero->first()->compareTo(one->first())) < 0 then 0 else 1 endif ; if res = 0 then ( zero := zero->tail() ) else ( one := one->tail() ) ; return res; operation performQueries(arr : Sequence(OclAny), n : int, queries : Sequence(OclAny), q : int) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if arr[i+1] = 0 then ( execute ((i) : zero) ) else ( execute ((i) : one) )) ; for i : Integer.subrange(0, q-1) do ( var type : OclAny := queries[i+1] ; if type = 1 then ( execute (getLeftMostZero())->display() ) else (if type = 2 then ( execute (getLeftMostOne())->display() ) else (if type = 3 then ( execute (getLeftMostElement())->display() ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- testcases=[] for i in range(int(input())): input() testcases.append(list(map(int,input().split(" ")))) for tc in testcases : odd=sum([1 if tc[i]% 2==0 else 0 for i in range(len(tc))]) if odd==len(tc)/2 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var testcases : Sequence := Sequence{} ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( input() ; execute ((((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ))) : testcases)) ; for tc : testcases do ( var odd : OclAny := (Integer.subrange(0, (tc)->size()-1)->select(i | true)->collect(i | (if tc[i+1] mod 2 = 0 then 1 else 0 endif)))->sum() ; if odd = (tc)->size() / 2 then ( execute ("Yes")->display() ) else ( execute ("No")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=[1,2,3,4,5,6,7,8,9] y=[1,2,3,4,5,6,7,8,9] for w in x : for c in y : print(w,"x",c,"=",w*c,sep="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 9 })))))))) ; var y : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 9 })))))))) ; for w : x do ( for c : y do ( execute (w)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) od_sum=0 ev_sum=0 for i in a : if i % 2==0 : od_sum+=1 else : ev_sum+=1 if od_sum==ev_sum : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var od_sum : int := 0 ; var ev_sum : int := 0 ; for i : a do ( if i mod 2 = 0 then ( od_sum := od_sum + 1 ) else ( ev_sum := ev_sum + 1 )) ; if od_sum = ev_sum then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): N=int(input()) arr=list(map(int,input().split())) arr=[N-x for x in arr] cnt={} for i,n in enumerate(arr): if n in cnt : cnt[n].append(i) else : cnt[n]=[i] ans=[-1]*N cur=1 for c,nums in cnt.items(): l=len(nums) if l % c!=0 : print("Impossible") return else : for i in range(l//c): for j in range(c): ans[nums[i*c+j]]=cur cur+=1 print("Possible") print(" ".join(map(str,ans))) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := arr->select(x | true)->collect(x | (N - x)) ; var cnt : OclAny := Set{} ; for _tuple : Integer.subrange(1, (arr)->size())->collect( _indx | Sequence{_indx-1, (arr)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var n : OclAny := _tuple->at(_indx); if (cnt)->includes(n) then ( (expr (atom (name cnt)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ) else ( cnt[n+1] := Sequence{ i } )) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, N) ; var cur : int := 1 ; for _tuple : cnt->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var c : OclAny := _tuple->at(_indx); _indx := _indx + 1; var nums : OclAny := _tuple->at(_indx); var l : int := (nums)->size() ; if l mod c /= 0 then ( execute ("Impossible")->display() ; return ) else ( for i : Integer.subrange(0, l div c-1) do ( for j : Integer.subrange(0, c-1) do ( ans[nums[i * c + j+1]+1] := cur) ; cur := cur + 1) )) ; execute ("Possible")->display() ; execute (StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) d={} i=j=g=0 for x in map(int,input().split()): d.setdefault(n-x,[]).append(i); i+=1 b=[0]*n s='ossible' for x in d : for i in d[x]: if j==0 : j=x ; g+=1 b[i]=g ; j-=1 if j : print('Imp'+s); exit() print('P'+s,*b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : OclAny := Set{} ; i := i(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name j)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name g)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for x : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ((expr (atom (name d)) (trailer . (name setdefault) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (name x)))))))) , (argument (test (logical_test (comparison (expr (atom [ ]))))))) ))) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))); i := i + 1) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var s : String := 'ossible' ; for x : d do ( for i : d[x+1] do ( if j = 0 then ( var j : OclAny := x; g := g + 1 ) else skip ; b[i+1] := g; j := j - 1) ; if j then ( execute ('Imp' + s)->display(); exit() ) else skip) ; execute ('P' + s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict n=int(input()) arr=list(map(int,input().split())) numDict=dict() cntDict=defaultdict(int) index=1 ans=[] for a in arr : k=n-a if k<0 : print("Impossible") exit() if cntDict[k]==0 : cntDict[k]=k numDict[k]=index index+=1 cntDict[k]-=1 ans.append(numDict[k]) for v in cntDict.values(): if v>0 : print("Impossible") exit() print("Possible") for b in ans : print(b,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var numDict : Map := (arguments ( )) ; var cntDict : OclAny := defaultdict(OclType["int"]) ; var index : int := 1 ; var ans : Sequence := Sequence{} ; for a : arr do ( var k : double := n - a ; if k < 0 then ( execute ("Impossible")->display() ; exit() ) else skip ; if cntDict[k+1] = 0 then ( cntDict[k+1] := k ; numDict[k+1] := index ; index := index + 1 ) else skip ; cntDict[k+1] := cntDict[k+1] - 1 ; execute ((numDict[k+1]) : ans)) ; for v : cntDict.values() do ( if v > 0 then ( execute ("Impossible")->display() ; exit() ) else skip) ; execute ("Possible")->display() ; for b : ans do ( execute (b)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def CountAllPairs(N,K): count=0 if(N>K): count=N-K for i in range(K+1,N+1): count=count+((N-K)//i) return count N=11 K=5 print(CountAllPairs(N,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; N := 11 ; K := 5 ; execute (CountAllPairs(N, K))->display(); operation CountAllPairs(N : OclAny, K : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; if ((N->compareTo(K)) > 0) then ( count := N - K ; for i : Integer.subrange(K + 1, N + 1-1) do ( count := count + ((N - K) div i)) ) else skip ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- L,N=map(int,input().split()) X=[int(input())for i in range(N)] if N==1 : print(max(X[0],L-X[0])) exit() cum_l=[0] for x in X : cum_l.append(cum_l[-1]+x) cum_r=[0] for x in reversed(X): cum_r.append(cum_r[-1]+L-x) ans=0 for st_l in range(1,N+1): m=N-st_l r=m-m//2 l=st_l+m//2 tmp=(cum_l[l]-cum_l[st_l-1]+cum_r[r])*2 if m % 2 : tmp-=(L-X[-r]) else : tmp-=X[l-1] ans=max(ans,tmp) for st_r in range(1,N+1): m=N-st_r l=m-m//2 r=st_r+m//2 tmp=(cum_r[r]-cum_r[st_r-1]+cum_l[l])*2 if m % 2 : tmp-=X[l-1] else : tmp-=(L-X[-r]) ans=max(ans,tmp) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var L : OclAny := null; var N : OclAny := null; Sequence{L,N} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var X : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; if N = 1 then ( execute (Set{X->first(), L - X->first()}->max())->display() ; exit() ) else skip ; var cum_l : Sequence := Sequence{ 0 } ; for x : X do ( execute ((cum_l->last() + x) : cum_l)) ; var cum_r : Sequence := Sequence{ 0 } ; for x : (X)->reverse() do ( execute ((cum_r->last() + L - x) : cum_r)) ; var ans : int := 0 ; for st_l : Integer.subrange(1, N + 1-1) do ( var m : double := N - st_l ; var r : double := m - m div 2 ; var l : OclAny := st_l + m div 2 ; var tmp : double := (cum_l[l+1] - cum_l[st_l - 1+1] + cum_r[r+1]) * 2 ; if m mod 2 then ( tmp := tmp - (L - X->reverse()->at(-(-r))) ) else ( tmp := tmp - X[l - 1+1] ) ; ans := Set{ans, tmp}->max()) ; for st_r : Integer.subrange(1, N + 1-1) do ( m := N - st_r ; l := m - m div 2 ; r := st_r + m div 2 ; tmp := (cum_r[r+1] - cum_r[st_r - 1+1] + cum_l[l+1]) * 2 ; if m mod 2 then ( tmp := tmp - X[l - 1+1] ) else ( tmp := tmp - (L - X->reverse()->at(-(-r))) ) ; ans := Set{ans, tmp}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l,n=[int(i)for i in input().split(" ")] x=[] for i in range(0,n): x.append(int(input())) y=[l-x[n-i-1]for i in range(0,n)] m=0 def cal(x,y): global m sx=[0]*(n+1) sy=[0]*(n+1) for i in range(1,n+1): sx[i]=sx[i-1]+x[i-1] sy[i]=sy[i-1]+y[i-1] for i in range(0,n): xc=(n-i-1)//2 yc=(n-i-1)-xc last=0 if(n-i)% 2==0 : last=y[yc-1] else : last=x[i+xc] mt=2*x[i]+2*(sy[yc]+sx[i+xc+1]-sx[i+1])-last if mt>m : m=mt cal(x,y) cal(y,x) print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute m : OclAny; operation initialise() pre: true post: true activity: var l : OclAny := null; var n : OclAny := null; Sequence{l,n} := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var x : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : x)) ; var y : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (l - x[n - i - 1+1])) ; var m : int := 0 ; skip ; cal(x, y) ; cal(y, x) ; execute (m)->display(); operation cal(x : OclAny, y : OclAny) pre: true post: true activity: skip ; var sx : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var sy : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(1, n + 1-1) do ( sx[i+1] := sx[i - 1+1] + x[i - 1+1] ; sy[i+1] := sy[i - 1+1] + y[i - 1+1]) ; for i : Integer.subrange(0, n-1) do ( var xc : int := (n - i - 1) div 2 ; var yc : double := (n - i - 1) - xc ; var last : int := 0 ; if (n - i) mod 2 = 0 then ( last := y[yc - 1+1] ) else ( last := x[i + xc+1] ) ; var mt : double := 2 * x[i+1] + 2 * (sy[yc+1] + sx[i + xc + 1+1] - sx[i + 1+1]) - last ; if (mt->compareTo(m)) > 0 then ( m := mt ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from itertools import accumulate circumference,n=map(int,input().split()) lll=list(map(int,sys.stdin.readlines())) rrr=[circumference-l for l in lll] rrr.reverse() lll=[0]+lll rrr=[0]+rrr acc_l=list(accumulate(lll)) acc_r=list(accumulate(rrr)) ans=max(lll[-1],rrr[-1]) for take_l in range(1,n): take_r=n-take_l tmp_l=lll[take_l]+2*(acc_l[take_l-1]+acc_r[take_r]) tmp_r=rrr[take_r]+2*(acc_r[take_r-1]+acc_l[take_l]) if take_ltake_r : tmp_l-=2*acc_l[take_l-1-take_r] tmp_r-=2*acc_l[take_l-take_r] ans=max(ans,tmp_l,tmp_r) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var circumference : OclAny := null; var n : OclAny := null; Sequence{circumference,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lll : Sequence := (((OclFile["System.in"]).readlines())->collect( _x | (OclType["int"])->apply(_x) )) ; var rrr : Sequence := lll->select(l | true)->collect(l | (circumference - l)) ; rrr := rrr->reverse() ; lll := Sequence{ 0 }->union(lll) ; rrr := Sequence{ 0 }->union(rrr) ; var acc_l : Sequence := (accumulate(lll)) ; var acc_r : Sequence := (accumulate(rrr)) ; var ans : OclAny := Set{lll->last(), rrr->last()}->max() ; for take_l : Integer.subrange(1, n-1) do ( var take_r : double := n - take_l ; var tmp_l : OclAny := lll[take_l+1] + 2 * (acc_l[take_l - 1+1] + acc_r[take_r+1]) ; var tmp_r : OclAny := rrr[take_r+1] + 2 * (acc_r[take_r - 1+1] + acc_l[take_l+1]) ; if (take_l->compareTo(take_r)) < 0 then ( tmp_l := tmp_l - 2 * acc_r[take_r - take_l+1] ; tmp_r := tmp_r - 2 * acc_r[take_r - 1 - take_l+1] ) else (if (take_l->compareTo(take_r)) > 0 then ( tmp_l := tmp_l - 2 * acc_l[take_l - 1 - take_r+1] ; tmp_r := tmp_r - 2 * acc_l[take_l - take_r+1] ) else skip) ; ans := Set{ans, tmp_l, tmp_r}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Vertices(x,y): val=abs(x)+abs(y); if x<0 : x=-1 else : x=1 print(val*x,"0",end=" "); if y<0 : y=-1 else : y=1 print("0",val*y); if __name__=="__main__" : x=3 ; y=3 ; Vertices(x,y); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( x := 3; y := 3; ; Vertices(x, y); ) else skip; operation Vertices(x : OclAny, y : OclAny) pre: true post: true activity: var val : double := (x)->abs() + (y)->abs(); ; if x < 0 then ( x := -1 ) else ( x := 1 ) ; execute (val * x)->display(); ; if y < 0 then ( y := -1 ) else ( y := 1 ) ; execute ("0")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math L,N=(int(i)for i in input().split()) X=[int(input())for _ in range(N)] X.insert(0,0) X_r=[L-i for i in reversed(X)] X_r.insert(0,0) X_r.pop() def lsum(l): s=0 for i in l : s+=i yield s X_sum=list(lsum(X)) X_r_sum=list(lsum(X_r)) def f_l(p,n): N_tmp=N-n a=N_tmp//2 if N_tmp==0 : return 0 elif N_tmp % 2==0 : return 2*X_sum[a]+X_r_sum[a+n]+X_r_sum[a+n-1]-2*X_r_sum[n]+p else : return X_sum[a+1]+X_sum[a]+2*X_r_sum[a+n]-2*X_r_sum[n]+p def f_r(p,n): N_tmp=N-n a=N_tmp//2 if N_tmp==0 : return 0 elif N_tmp % 2==0 : return 2*X_r_sum[a]+X_sum[a+n]+X_sum[a+n-1]-2*X_sum[n]+p else : return X_r_sum[a+1]+X_r_sum[a]+2*X_sum[a+n]-2*X_sum[n]+p max_l=max(X[i]+f_r(X[i],i)for i in range(1,N+1)) max_r=max(X_r[i]+f_l(X_r[i],i)for i in range(1,N+1)) print(max(max_l,max_r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var L : OclAny := null; var N : OclAny := null; Sequence{L,N} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var X : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; X := X.insertAt(0+1, 0) ; var X_r : Sequence := (X)->reverse()->select(i | true)->collect(i | (L - i)) ; X_r := X_r.insertAt(0+1, 0) ; X_r := X_r->front() ; skip ; var X_sum : Sequence := (lsum(X)) ; var X_r_sum : Sequence := (lsum(X_r)) ; skip ; skip ; var max_l : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name X)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name f_r)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name X)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name N))) + (expr (atom (number (integer 1)))))))))) )))))))))->max() ; var max_r : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name X_r)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name f_l)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name X_r)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name N))) + (expr (atom (number (integer 1)))))))))) )))))))))->max() ; execute (Set{max_l, max_r}->max())->display(); operation lsum(l : OclAny) pre: true post: true activity: var s : int := 0 ; for i : l do ( s := s + i ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return s); operation f_l(p : OclAny, n : OclAny) : OclAny pre: true post: true activity: var N_tmp : double := N - n ; var a : int := N_tmp div 2 ; if N_tmp = 0 then ( return 0 ) else (if N_tmp mod 2 = 0 then ( return 2 * X_sum[a+1] + X_r_sum[a + n+1] + X_r_sum[a + n - 1+1] - 2 * X_r_sum[n+1] + p ) else ( return X_sum[a + 1+1] + X_sum[a+1] + 2 * X_r_sum[a + n+1] - 2 * X_r_sum[n+1] + p ) ) ; operation f_r(p : OclAny, n : OclAny) : OclAny pre: true post: true activity: N_tmp := N - n ; a := N_tmp div 2 ; if N_tmp = 0 then ( return 0 ) else (if N_tmp mod 2 = 0 then ( return 2 * X_r_sum[a+1] + X_sum[a + n+1] + X_sum[a + n - 1+1] - 2 * X_sum[n+1] + p ) else ( return X_r_sum[a + 1+1] + X_r_sum[a+1] + 2 * X_sum[a + n+1] - 2 * X_sum[n+1] + p ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate L,N=map(int,input().split()) X=[0]+[int(input())for _ in range(N)] Y=[0]+[L-x for x in X[1 :]][: :-1] sx=list(accumulate(X)) sy=list(accumulate(Y)) ans=0 for i in range(1,N+1): j=N-i mn=min(i-1,j) now=X[i] now+=2*(sx[i-1]-sx[i-1-mn])+2*(sy[j]-sy[j-mn-(j>mn)]) ans=max(ans,now) for i in range(N): j=N-i mn=min(i,j-1) now=Y[j] now+=2*(sx[i]-sx[i-mn-(i>mn)])+2*(sy[j-1]-sy[j-1-mn]) ans=max(ans,now) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var L : OclAny := null; var N : OclAny := null; Sequence{L,N} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var X : Sequence := Sequence{ 0 }->union(Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))) ; var Y : Sequence := Sequence{ 0 }->union(X->tail()->select(x | true)->collect(x | (L - x))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ; var sx : Sequence := (accumulate(X)) ; var sy : Sequence := (accumulate(Y)) ; var ans : int := 0 ; for i : Integer.subrange(1, N + 1-1) do ( var j : double := N - i ; var mn : OclAny := Set{i - 1, j}->min() ; var now : OclAny := X[i+1] ; now := now + 2 * (sx[i - 1+1] - sx[i - 1 - mn+1]) + 2 * (sy[j+1] - sy[j - mn - ((j->compareTo(mn)) > 0)+1]) ; ans := Set{ans, now}->max()) ; for i : Integer.subrange(0, N-1) do ( j := N - i ; mn := Set{i, j - 1}->min() ; now := Y[j+1] ; now := now + 2 * (sx[i+1] - sx[i - mn - ((i->compareTo(mn)) > 0)+1]) + 2 * (sy[j - 1+1] - sy[j - 1 - mn+1]) ; ans := Set{ans, now}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for a in[1,2,3,4,5,6,7,8,9]: for b in[1,2,3,4,5,6,7,8,9]: print("{0}x{1}={2}".format(a,b,a*b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for a : Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 9 })))))))) do ( for b : Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 9 })))))))) do ( execute (StringLib.interpolateStrings("{0}x{1}={2}", Sequence{a, b, a * b}))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=2 M=3 def traverseMatrix(arr,current_row,current_col): if(current_col>=M): return 0 ; if(current_row>=N): return 1 ; print(arr[current_row][current_col],end=","); if(traverseMatrix(arr,current_row,current_col+1)==1): return 1 ; return traverseMatrix(arr,current_row+1,0); if __name__=="__main__" : arr=[[1,2,3],[4,5,6]]; traverseMatrix(arr,0,0); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 2 ; var M : int := 3 ; skip ; if __name__ = "__main__" then ( arr := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{ Sequence{4}->union(Sequence{5}->union(Sequence{ 6 })) }); ; traverseMatrix(arr, 0, 0); ) else skip; operation traverseMatrix(arr : OclAny, current_row : OclAny, current_col : OclAny) pre: true post: true activity: if ((current_col->compareTo(M)) >= 0) then ( return 0; ) else skip ; if ((current_row->compareTo(N)) >= 0) then ( return 1; ) else skip ; execute (arr[current_row+1][current_col+1])->display(); ; if (traverseMatrix(arr, current_row, current_col + 1) = 1) then ( return 1; ) else skip ; return traverseMatrix(arr, current_row + 1, 0);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def initialize(mul,div,size): for i in range(1,size): mul[i]=(mul[i]*mul[i-1])/div[i]; def update(l,r,x,mul,div): mul[l]*=x ; div[r+1]*=x ; def printArray(ar,mul,div,n): for i in range(n): ar[i]=ar[i]*mul[i]; print(int(ar[i]),end=" "); if __name__=='__main__' : ar=[10,5,20,40]; n=len(ar); mul=[0]*(n+1); div=[0]*(n+1); for i in range(n+1): mul[i]=div[i]=1 ; update(0,1,10,mul,div); update(1,3,20,mul,div); update(2,2,2,mul,div); initialize(mul,div,n+1); printArray(ar,mul,div,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( ar := Sequence{10}->union(Sequence{5}->union(Sequence{20}->union(Sequence{ 40 }))); ; n := (ar)->size(); ; mul := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); ; div := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); ; for i : Integer.subrange(0, n + 1-1) do ( mul[i+1] := 1; var div[i+1] : int := 1;) ; update(0, 1, 10, mul, div); ; update(1, 3, 20, mul, div); ; update(2, 2, 2, mul, div); ; initialize(mul, div, n + 1); ; printArray(ar, mul, div, n); ) else skip; operation initialize(mul : OclAny, div : OclAny, size : OclAny) pre: true post: true activity: for i : Integer.subrange(1, size-1) do ( mul[i+1] := (mul[i+1] * mul[i - 1+1]) / div[i+1];); operation update(l : OclAny, r : OclAny, x : OclAny, mul : OclAny, div : OclAny) pre: true post: true activity: mul[l+1] := mul[l+1] * x; ; div[r + 1+1] := div[r + 1+1] * x;; operation printArray(ar : OclAny, mul : OclAny, div : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( ar[i+1] := ar[i+1] * mul[i+1]; ; execute (("" + ((ar[i+1])))->toInteger())->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=100005 def SieveOfEratosthenes(prime,p_size): prime[0]=False prime[1]=False p=2 while p*p<=p_size : if(prime[p]): for i in range(p*2,p_size+1,p): prime[i]=False p+=1 def longestPrimeSubsequence(arr,n): prime=[True]*(N+1) SieveOfEratosthenes(prime,N) answer=0 for i in range(n): if(prime[arr[i]]): answer+=1 return answer if __name__=="__main__" : arr=[3,4,11,2,9,21] n=len(arr) print(longestPrimeSubsequence(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 100005 ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{3}->union(Sequence{4}->union(Sequence{11}->union(Sequence{2}->union(Sequence{9}->union(Sequence{ 21 }))))) ; n := (arr)->size() ; execute (longestPrimeSubsequence(arr, n))->display() ) else skip; operation SieveOfEratosthenes(prime : OclAny, p_size : OclAny) pre: true post: true activity: prime->first() := false ; prime[1+1] := false ; var p : int := 2 ; while (p * p->compareTo(p_size)) <= 0 do ( if (prime[p+1]) then ( for i : Integer.subrange(p * 2, p_size + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip ; p := p + 1); operation longestPrimeSubsequence(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: prime := MatrixLib.elementwiseMult(Sequence{ true }, (N + 1)) ; SieveOfEratosthenes(prime, N) ; var answer : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (prime[arr[i+1]+1]) then ( answer := answer + 1 ) else skip) ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b,c=map(int,input().split()) print([0,min(a*3,a+b,c),min(2*a,b,2*c),min(a,b+c,3*c)][n % 4]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{n,a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Sequence{0}->union(Sequence{Set{a * 3, a + b, c}->min()}->union(Sequence{Set{2 * a, b, 2 * c}->min()}->union(Sequence{ Set{a, b + c, 3 * c}->min() })))[n mod 4+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,a,b,c=map(int,input().split()) rem=n % 4 answer=0 if rem==0 : answer=0 elif rem==1 : answer=min(3*a,a+b,c) elif rem==2 : answer=min(2*a,b,2*c) else : answer=min(a,b+c,3*c) print(answer) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{n,a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var rem : int := n mod 4 ; var answer : int := 0 ; if rem = 0 then ( answer := 0 ) else (if rem = 1 then ( answer := Set{3 * a, a + b, c}->min() ) else (if rem = 2 then ( answer := Set{2 * a, b, 2 * c}->min() ) else ( answer := Set{a, b + c, 3 * c}->min() ) ) ) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- [n,a,b,c]=list(map(lambda x : int(x),input().split())) r=n % 4 if(r==0): print(0) r=4-r if(r==1): print(min(a,2*b+a,3*c,b+c)) if(r==2): print(min(2*a,b,2*c)) if(r==3): print(min(3*a,a+b,c,2*c+a,2*b+c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: Sequence{n}->union(Sequence{a}->union(Sequence{b}->union(Sequence{ c }))) := ((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) )) ; var r : int := n mod 4 ; if (r = 0) then ( execute (0)->display() ) else skip ; r := 4 - r ; if (r = 1) then ( execute (Set{a, 2 * b + a, 3 * c, b + c}->min())->display() ) else skip ; if (r = 2) then ( execute (Set{2 * a, b, 2 * c}->min())->display() ) else skip ; if (r = 3) then ( execute (Set{3 * a, a + b, c, 2 * c + a, 2 * b + c}->min())->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): ans=sum(i*(i-(2 if i % 2==0 else 1))for i in range(3,1001)) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 2)))))) if (logical_test (comparison (comparison (expr (expr (atom (name i))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 0))))))) else (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 3)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1001))))))))) )))))))))->sum() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,m): b=[x//n for x in a] b=list(filter(lambda x : x>=2,b)) return sum(b)>=m and(m % 2==0 or any(x>=3 for x in b)) for _ in range(int(input())): n,m,k=map(int,input().split()) a=list(map(int,input().split())) print("Yes" if solve(n,m)or solve(m,n)else "No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (if solve(n, m) or solve(m, n) then "Yes" else "No" endif)->display()); operation solve(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var b : Sequence := a->select(x | true)->collect(x | (x div n)) ; b := ((b)->select( _x | (lambda x : OclAny in (x >= 2))->apply(_x) = true )) ; return ((b)->sum()->compareTo(m)) >= 0 & (m mod 2 = 0 or ((argument (test (logical_test (comparison (comparison (expr (atom (name x)))) >= (comparison (expr (atom (number (integer 3)))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name b))))))))->exists( _x | _x = true )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pre_process(substrings,s): n=len(s); for i in range(n): dup="" ; for j in range(i,n): dup+=s[j]; substrings.append(dup); substrings.sort(); return substrings ; if __name__=="__main__" : s="geek" ; substrings=[]; substrings=pre_process(substrings,s); queries=[1,5,10]; q=len(queries); for i in range(q): print(substrings[queries[i]-1]); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "geek"; ; substrings := Sequence{}; ; substrings := pre_process(substrings, s); ; var queries : Sequence := Sequence{1}->union(Sequence{5}->union(Sequence{ 10 })); ; var q : int := (queries)->size(); ; for i : Integer.subrange(0, q-1) do ( execute (substrings[queries[i+1] - 1+1])->display();) ) else skip; operation pre_process(substrings : OclAny, s : OclAny) pre: true post: true activity: var n : int := (s)->size(); ; for i : Integer.subrange(0, n-1) do ( var dup : String := ""; ; for j : Integer.subrange(i, n-1) do ( dup := dup + s[j+1]; ; execute ((dup) : substrings);)) ; substrings := substrings->sort(); ; return substrings;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,key): self.key=key self.left=None self.right=None def insert(node : Node,key : int)->Node : if node is None : return Node(key) if keynode.key : node.right=insert(node.right,key) return node def maxDepth(node : Node)->int : if node is None : return 0 else : lDepth=maxDepth(node.left) rDepth=maxDepth(node.right) if lDepth>rDepth : return lDepth+1 else : return rDepth+1 def maxHeight(a : list,n : int)->int : rootA=Node(a[0]) for i in range(1,n): rootA=insert(rootA,a[i]) rootB=Node(a[n-1]) for i in range(n-2,-1,-1): rootB=insert(rootB,a[i]) A=maxDepth(rootA)-1 B=maxDepth(rootB)-1 return max(A,B) if __name__=="__main__" : a=[2,1,3,4] n=len(a) print(maxHeight(a,n)) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute key : OclAny := key; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(key : OclAny) : Node pre: true post: true activity: self.key := key ; self.left := null ; self.right := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( var a : Sequence := Sequence{2}->union(Sequence{1}->union(Sequence{3}->union(Sequence{ 4 }))) ; var n : int := (a)->size() ; execute (maxHeight(a, n))->display() ) else skip; operation insert(node : Node, key : int) : OclAny pre: true post: true activity: if node <>= null then ( return (Node.newNode()).initialise(key) ) else skip ; if (key->compareTo(node.key)) < 0 then ( node.left := insert(node.left, key) ) else (if (key->compareTo(node.key)) > 0 then ( node.right := insert(node.right, key) ) else skip) ; return node; operation maxDepth(node : Node) : int pre: true post: true activity: if node <>= null then ( return 0 ) else ( var lDepth : OclAny := maxDepth(node.left) ; var rDepth : OclAny := maxDepth(node.right) ; if (lDepth->compareTo(rDepth)) > 0 then ( return lDepth + 1 ) else ( return rDepth + 1 ) ); operation maxHeight(a : Sequence(OclAny), n : int) : int pre: true post: true activity: var rootA : Node := (Node.newNode()).initialise(a->first()) ; for i : Integer.subrange(1, n-1) do ( rootA := insert(rootA, a[i+1])) ; var rootB : Node := (Node.newNode()).initialise(a[n - 1+1]) ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( rootB := insert(rootB, a[i+1])) ; var A : double := maxDepth(rootA) - 1 ; var B : double := maxDepth(rootB) - 1 ; return Set{A, B}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count_carry(a,b): carry=0 ; count=0 ; len_a=len(a); len_b=len(b); while(len_a!=0 or len_b!=0): x=0 ; y=0 ; if(len_a>0): x=int(a[len_a-1])+int('0'); len_a-=1 ; if(len_b>0): y=int(b[len_b-1])+int('0'); len_b-=1 ; sum=x+y+carry ; if(sum>=10): carry=1 ; count+=1 ; else : carry=0 ; return count ; a="9555" ; b="555" ; count=count_carry(a,b); if(count==0): print("0"); elif(count==1): print("1"); else : print(count); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := "9555"; ; b := "555"; ; count := count_carry(a, b); ; if (count = 0) then ( execute ("0")->display(); ) else (if (count = 1) then ( execute ("1")->display(); ) else ( execute (count)->display(); ) ) ; operation count_carry(a : OclAny, b : OclAny) pre: true post: true activity: var carry : int := 0; ; var count : int := 0; ; var len_a : int := (a)->size(); ; var len_b : int := (b)->size(); ; while (len_a /= 0 or len_b /= 0) do ( var x : int := 0; ; var y : int := 0; ; if (len_a > 0) then ( x := ("" + ((a[len_a - 1+1])))->toInteger() + ("" + (('0')))->toInteger(); ; len_a := len_a - 1; ) else skip ; if (len_b > 0) then ( y := ("" + ((b[len_b - 1+1])))->toInteger() + ("" + (('0')))->toInteger(); ; len_b := len_b - 1; ) else skip ; var sum : int := x + y + carry; ; if (sum >= 10) then ( carry := 1; ; count := count + 1; ) else ( carry := 0; )) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def shortestDistance(S,X): prev=float('-inf') ans=[] for i,j in enumerate(S): if j==X : prev=i ans.append(i-prev) prev=float('inf') for i in range(len(S)-1,-1,-1): if S[i]==X : prev=i ans[i]=min(ans[i],prev-i) return ans S="geeksforgeeks" X="g" print(shortestDistance(S,X)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; S := "geeksforgeeks" ; X := "g" ; execute (shortestDistance(S, X))->display(); operation shortestDistance(S : OclAny, X : OclAny) : OclAny pre: true post: true activity: var prev : double := ("" + (('-inf')))->toReal() ; var ans : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (S)->size())->collect( _indx | Sequence{_indx-1, (S)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if j = X then ( prev := i ) else skip ; execute ((i - prev) : ans)) ; prev := ("" + (('inf')))->toReal() ; for i : Integer.subrange(-1 + 1, (S)->size() - 1)->reverse() do ( if S[i+1] = X then ( prev := i ) else skip ; ans[i+1] := Set{ans[i+1], prev - i}->min()) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(1,10): for j in range(1,10): print(i,end='') print('x',end='') print(j,end='') print('=',end='') print(i*j) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(1, 10-1) do ( for j : Integer.subrange(1, 10-1) do ( execute (i)->display() ; execute ('x')->display() ; execute (j)->display() ; execute ('=')->display() ; execute (i * j)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53] n,m=map(int,input().split()) a=c.index(n) if c[a+1]==m : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{11}->union(Sequence{13}->union(Sequence{17}->union(Sequence{19}->union(Sequence{23}->union(Sequence{29}->union(Sequence{31}->union(Sequence{37}->union(Sequence{41}->union(Sequence{43}->union(Sequence{47}->union(Sequence{ 53 }))))))))))))))) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : int := c->indexOf(n) - 1 ; if c[a + 1+1] = m then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47] if n in a and m in a and a.index(m)-a.index(n)==1 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{11}->union(Sequence{13}->union(Sequence{17}->union(Sequence{19}->union(Sequence{23}->union(Sequence{29}->union(Sequence{31}->union(Sequence{37}->union(Sequence{41}->union(Sequence{43}->union(Sequence{ 47 })))))))))))))) ; if (a)->includes(n) & (a)->includes(m) & a->indexOf(m) - 1 - a->indexOf(n) - 1 = 1 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=list(map(int,input().split())) primes=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53] if primes[primes.index(n)+1]==m : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var primes : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{11}->union(Sequence{13}->union(Sequence{17}->union(Sequence{19}->union(Sequence{23}->union(Sequence{29}->union(Sequence{31}->union(Sequence{37}->union(Sequence{41}->union(Sequence{43}->union(Sequence{47}->union(Sequence{ 53 }))))))))))))))) ; if primes[primes->indexOf(n) - 1 + 1+1] = m then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) while True : j=0 n+=1 for i in range(2,n): if n % i==0 : j=1 if j==0 : ans=n break if ans==m : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; while true do ( var j : int := 0 ; n := n + 1 ; for i : Integer.subrange(2, n-1) do ( if n mod i = 0 then ( j := 1 ) else skip) ; if j = 0 then ( var ans : OclAny := n ; break ) else skip) ; if ans = m then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=input().split() c=0 v=0 l=[] for i in range(int(n)+1,int(m)): l.append(i) for j in l : for k in range(1,int(j)+1): if int(j)% k==0 : c+=1 if c>2 : v+=1 c=0 d=0 for z in range(1,int(m)+1): if int(m)% z==0 : d+=1 if d>2 : g=False else : g=True if g : if v==len(l): print("YES") else : print("NO") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split() ; var c : int := 0 ; var v : int := 0 ; var l : Sequence := Sequence{} ; for i : Integer.subrange(("" + ((n)))->toInteger() + 1, ("" + ((m)))->toInteger()-1) do ( execute ((i) : l)) ; for j : l do ( for k : Integer.subrange(1, ("" + ((j)))->toInteger() + 1-1) do ( if ("" + ((j)))->toInteger() mod k = 0 then ( c := c + 1 ) else skip) ; if c > 2 then ( v := v + 1 ) else skip ; c := 0) ; var d : int := 0 ; for z : Integer.subrange(1, ("" + ((m)))->toInteger() + 1-1) do ( if ("" + ((m)))->toInteger() mod z = 0 then ( d := d + 1 ) else skip) ; if d > 2 then ( var g : boolean := false ) else ( g := true ) ; if g then ( if v = (l)->size() then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): N=int(input()) S=input() stomp=0 for i in range(1,len(S)): pass i=0 while True : if i>=len(S)-1 : break if S[i]!=S[i+1]: stomp+=1 i+=1 i+=1 print(stomp) if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : String := (OclFile["System.in"]).readLine() ; var stomp : int := 0 ; for i : Integer.subrange(1, (S)->size()-1) do ( skip) ; var i : int := 0 ; while true do ( if (i->compareTo((S)->size() - 1)) >= 0 then ( break ) else skip ; if S[i+1] /= S[i + 1+1] then ( stomp := stomp + 1 ; i := i + 1 ) else skip ; i := i + 1) ; execute (stomp)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def getSum(a,n): P=[0]*n P[0]=a[0] for i in range(1,n): P[i]=a[i]+P[i-1] S=P[n-1] hash={} for i in range(n): hash[P[i]]=1 res=set() for i in range(1,int(sqrt(S))+1): if(S % i==0): pres=True ; div1=i div2=S//i for j in range(div1,S+1,div1): if j not in hash.keys(): pres=False break if(pres and div1!=S): res.add(div1) pres=True for j in range(S//i,S+1,S//i): if j not in hash.keys(): pres=False ; break if(pres and div2!=S): res.add(div2) if(len(res)==0): print("-1") return for i in res : print(i,end=" ") if __name__=="__main__" : a=[1,2,1,1,1,2,1,3] n=len(a) getSum(a,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( a := Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{ 3 }))))))) ; n := (a)->size() ; getSum(a, n) ) else skip; operation getSum(a : OclAny, n : OclAny) pre: true post: true activity: var P : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; P->first() := a->first() ; for i : Integer.subrange(1, n-1) do ( P[i+1] := a[i+1] + P[i - 1+1]) ; var S : OclAny := P[n - 1+1] ; var hash : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( hash[P[i+1]+1] := 1) ; var res : Set := Set{}->union(()) ; for i : Integer.subrange(1, ("" + ((sqrt(S))))->toInteger() + 1-1) do ( if (S mod i = 0) then ( var pres : boolean := true; ; var div1 : OclAny := i ; var div2 : int := S div i ; for j : Integer.subrange(div1, S + 1-1)->select( $x | ($x - div1) mod div1 = 0 ) do ( if (hash.keys())->excludes(j) then ( pres := false ; break ) else skip) ; if (pres & div1 /= S) then ( execute ((div1) : res) ) else skip ; pres := true ; for j : Integer.subrange(S div i, S + 1-1)->select( $x | ($x - S div i) mod S div i = 0 ) do ( if (hash.keys())->excludes(j) then ( pres := false; ; break ) else skip) ; if (pres & div2 /= S) then ( execute ((div2) : res) ) else skip ) else skip) ; if ((res)->size() = 0) then ( execute ("-1")->display() ; return ) else skip ; for i : res do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter N=int(input()) S=input() counter=0 prev=S[0] i=1 while itoInteger() ; var S : String := (OclFile["System.in"]).readLine() ; var counter : int := 0 ; var prev : OclAny := S->first() ; var i : int := 1 ; while (i->compareTo(N)) < 0 do ( if S[i+1] = prev then ( prev := S[i+1] ; i := i + 1 ) else ( if (i->compareTo(N - 1)) < 0 then ( prev := S[i + 1+1] ) else skip ; counter := counter + 1 ; i := i + 2 )) ; execute (counter)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import array from fractions import Fraction import functools import itertools import math import os import sys def main(): N=read_int() S=inp() print(solve(N,S)) def solve(N,S): i=0 count=0 while iincludes('DEBUG') ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := read_int() ; var S : OclAny := inp() ; execute (solve(N, S))->display(); operation solve(N : OclAny, S : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; var count : int := 0 ; while (i->compareTo(N - 1)) < 0 do ( if S[i+1] /= S[i + 1+1] then ( count := count + 1 ; i := i + 2 ) else ( i := i + 1 )) ; return count; operation inp() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation read_int() : OclAny pre: true post: true activity: return ("" + ((inp())))->toInteger(); operation read_ints() : OclAny pre: true post: true activity: return inp().split()->select(e | true)->collect(e | (("" + ((e)))->toInteger())); operation dprint(value : OclAny : Sequence(OclAny), sep : String, end : String) pre: true post: true activity: (args * (named_parameter (name value))) if sep->oclIsUndefined() then sep := ' ' else skip; if end->oclIsUndefined() then end := ' ' else skip; if DEBUG then ( execute ((argument * (test (logical_test (comparison (expr (atom (name value))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re input() print(re.sub(r'OX|XO','@',input()).count('@')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; input() ; execute (re.sub(StringLib.rawString('OX|XO'), '@', (OclFile["System.in"]).readLine())->count('@'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) input=sys.stdin.readline from math import floor,ceil,sqrt,factorial,log from heapq import heappop,heappush,heappushpop from collections import Counter,defaultdict,deque from itertools import accumulate,permutations,combinations,product,combinations_with_replacement from bisect import bisect_left,bisect_right from copy import deepcopy inf=float('inf') mod=10**9+7 def pprint(*A): for a in A : print(*a,sep='\n') def INT_(n): return int(n)-1 def MI(): return map(int,input().split()) def MF(): return map(float,input().split()) def MI_(): return map(INT_,input().split()) def LI(): return list(MI()) def LI_(): return[int(x)-1 for x in input().split()] def LF(): return list(MF()) def LIN(n : int): return[I()for _ in range(n)] def LLIN(n : int): return[LI()for _ in range(n)] def LLIN_(n : int): return[LI_()for _ in range(n)] def LLI(): return[list(map(int,l.split()))for l in input()] def I(): return int(input()) def F(): return float(input()) def ST(): return input().replace('\n','') def main(): N=I() S=ST()+"//" i=0 ans=0 while ipow(6)) ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; skip ; skip ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation pprint(A : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name A))) for a : A do ( execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display()); operation INT_(n : OclAny) : OclAny pre: true post: true activity: return ("" + ((n)))->toInteger() - 1; operation MI() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation MF() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["double"])->apply(_x) ); operation MI_() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (INT_)->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return (MI()); operation LI_() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return (MF()); operation LIN(n : int) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (I())); operation LLIN(n : int) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI())); operation LLIN_(n : int) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI_())); operation LLI() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine()->select(l | true)->collect(l | (((l.split())->collect( _x | (OclType["int"])->apply(_x) )))); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation ST() : OclAny pre: true post: true activity: return input().replace(' ', ''); operation main() pre: true post: true activity: var N : OclAny := I() ; var S : OclAny := ST() + "//" ; var i : int := 0 ; var ans : int := 0 ; while (i->compareTo(N)) < 0 do ( if (Sequence{"OX", "XO"})->includes(S.subrange(i+1, i + 2)) then ( ans := ans + 1 ; i := i + 1 ) else skip ; i := i + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def MakePreSum(arr,presum,n): presum[0]=arr[0] for i in range(1,n): presum[i]=presum[i-1]+arr[i] def BinaryLifting(presum,n,x): pos=0 LOGN=int(math.log2(n)) if(x<=presum[0]): return 0 for i in range(LOGN,-1,-1): if(pos+(1<union(Sequence{5}->union(Sequence{7}->union(Sequence{1}->union(Sequence{6}->union(Sequence{9}->union(Sequence{12}->union(Sequence{4}->union(Sequence{ 6 })))))))) ; x := 8 ; n := (arr)->size() ; presum := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; MakePreSum(arr, presum, n) ; execute (BinaryLifting(presum, n, x))->display() ) else skip; operation MakePreSum(arr : OclAny, presum : OclAny, n : OclAny) pre: true post: true activity: presum->first() := arr->first() ; for i : Integer.subrange(1, n-1) do ( presum[i+1] := presum[i - 1+1] + arr[i+1]); operation BinaryLifting(presum : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: var pos : int := 0 ; var LOGN : int := ("" + (()))->toInteger() ; if ((x->compareTo(presum->first())) <= 0) then ( return 0 ) else skip ; for i : Integer.subrange(-1 + 1, LOGN)->reverse() do ( if ((pos + (1 * (2->pow(i)))->compareTo(n)) < 0 & (presum[pos + (1 * (2->pow(i)))+1]->compareTo(x)) < 0) then ( pos := pos + (1 * (2->pow(i))) ) else skip) ; return pos + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,m,r=map(int,input().split()) a=r-n*m def combination(p,q): if q<0 or pcollect( _x | (OclType["int"])->apply(_x) ) ; var a : double := r - n * m ; skip ; if a < 0 then ( execute (0)->display() ) else ( execute (("" + ((combination(a + n - 1, a))))->toInteger())->display() ); operation combination(p : OclAny, q : OclAny) : OclAny pre: true post: true activity: if q < 0 or (p->compareTo(q)) < 0 then ( return 0 ) else skip ; return MathLib.factorial(p) div MathLib.factorial(q) div MathLib.factorial(p - q); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n,m,r=list(map(int,input().split(" "))) if n*m>r : print(0) sys.exit() r=r-n*m res=1 for i in range(1,n+r): res*=i for i in range(1,n): res//=i for i in range(1,r+1): res//=i print(int(res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; var r : OclAny := null; Sequence{n,m,r} := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; if (n * m->compareTo(r)) > 0 then ( execute (0)->display() ; sys.exit() ) else skip ; var r : double := r - n * m ; var res : int := 1 ; for i : Integer.subrange(1, n + r-1) do ( res := res * i) ; for i : Integer.subrange(1, n-1) do ( res := res div i) ; for i : Integer.subrange(1, r + 1-1) do ( res := res div i) ; execute (("" + ((res)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* n,m,r=map(int,input().split()) r-=m*n print(0 if r<0 else factorial(n-1+r)//factorial(n-1)//factorial(r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; var r : OclAny := null; Sequence{n,m,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; r := r - m * n ; execute (if r < 0 then 0 else factorial(n - 1 + r) div factorial(n - 1) div factorial(r) endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fact(n): res=1 for i in range(1,n+1): res*=i return res def combination(n,k): return fact(n)//fact(n-k)//fact(k) n,m,r=list(map(int,input().split())) print(combination(r-n*m+n-1,n-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var m : OclAny := null; var r : OclAny := null; Sequence{n,m,r} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (combination(r - n * m + n - 1, n - 1))->display(); operation fact(n : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; for i : Integer.subrange(1, n + 1-1) do ( res := res * i) ; return res; operation combination(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: return fact(n) div fact(n - k) div fact(k); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin from math import factorial input=stdin.readline def solve(n,m,r): if n*m>r : return 0 ans=factorial(n+r-m*n-1)//factorial(n-1)//factorial(r-m*n) return ans def main(args): n,m,r=map(int,input().split()) result=solve(n,m,r) print(result) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(n : OclAny, m : OclAny, r : OclAny) : OclAny pre: true post: true activity: if (n * m->compareTo(r)) > 0 then ( return 0 ) else skip ; var ans : int := factorial(n + r - m * n - 1) div factorial(n - 1) div factorial(r - m * n) ; return ans; operation main(args : OclAny) pre: true post: true activity: Sequence{n,m,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var result : OclAny := solve(n, m, r) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def originalArray(greater,n): temp=[] for i in range(n+1): temp.append(i) arr=[0 for i in range(n)] for i in range(n): k=n-greater[i]-i arr[i]=temp[k] del temp[k] for i in range(n): print(arr[i],end=" ") arr=[6,3,2,1,0,1,0] n=len(arr) originalArray(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{6}->union(Sequence{3}->union(Sequence{2}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 0 })))))) ; n := (arr)->size() ; originalArray(arr, n); operation originalArray(greater : OclAny, n : OclAny) pre: true post: true activity: var temp : Sequence := Sequence{} ; for i : Integer.subrange(0, n + 1-1) do ( execute ((i) : temp)) ; var arr : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( var k : double := n - greater[i+1] - i ; arr[i+1] := temp[k+1] ; execute (temp[k+1])->isDeleted()) ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_INT=1000000 def solve(Array,N): pos=[[]for i in range(5)] pref=[0 for i in range(5)] if(Array[0]==0): pref[0]=1 pos[0].append(0) ans=MAX_INT for i in range(N): if(Array[i]==0): pref[0]+=1 pos[0].append(i) else : if(pref[Array[i]-1]>0): pref[Array[i]]+=1 pos[Array[i]].append(i) if(Array[i]==4): end=i start=i for j in range(3,-1,-1): s=0 e=len(pos[j])-1 temp=-1 while(s<=e): m=(s+e)//2 if(pos[j][m]<=start): temp=pos[j][m] s=m+1 else : e=m-1 start=temp ans=min(ans,end-start+1) return ans Array=[0,1,2,3,4,2,0,3,4] N=len(Array) print(solve(Array,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_INT : int := 1000000 ; skip ; Array := Sequence{0}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{2}->union(Sequence{0}->union(Sequence{3}->union(Sequence{ 4 })))))))) ; N := (Array)->size() ; execute (solve(Array, N))->display(); operation solve(Array : OclAny, N : OclAny) : OclAny pre: true post: true activity: var pos : Sequence := Integer.subrange(0, 5-1)->select(i | true)->collect(i | (Sequence{})) ; var pref : Sequence := Integer.subrange(0, 5-1)->select(i | true)->collect(i | (0)) ; if (Array->first() = 0) then ( pref->first() := 1 ; (expr (atom (name pos)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))) ) else skip ; var ans : int := MAX_INT ; for i : Integer.subrange(0, N-1) do ( if (Array[i+1] = 0) then ( pref->first() := pref->first() + 1 ; (expr (atom (name pos)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ) else ( if (pref[Array[i+1] - 1+1] > 0) then ( pref[Array[i+1]+1] := pref[Array[i+1]+1] + 1 ; (expr (atom (name pos)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name Array)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ; if (Array[i+1] = 4) then ( var end : OclAny := i ; var start : OclAny := i ; for j : Integer.subrange(-1 + 1, 3)->reverse() do ( var s : int := 0 ; var e : double := (pos[j+1])->size() - 1 ; var temp : int := -1 ; while ((s->compareTo(e)) <= 0) do ( var m : int := (s + e) div 2 ; if ((pos[j+1][m+1]->compareTo(start)) <= 0) then ( temp := pos[j+1][m+1] ; s := m + 1 ) else ( e := m - 1 )) ; start := temp) ; ans := Set{ans, end - start + 1}->min() ) else skip ) else skip )) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def perfectSquares(l,r): for i in range(l,r+1): if(i**(.5)==int(i**(.5))): print(i,end=" ") l=2 r=24 perfectSquares(l,r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; l := 2 ; r := 24 ; perfectSquares(l, r); operation perfectSquares(l : OclAny, r : OclAny) pre: true post: true activity: for i : Integer.subrange(l, r + 1-1) do ( if ((i)->pow((.5)) = ("" + (((i)->pow((.5)))))->toInteger()) then ( execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(a,b): if(a>0 and b>0): print("Positive") elif(a<=0 and b>=0): print("Zero") else : n=abs(a-b)+1 if(n % 2==0): print("Positive") else : print("Negative") if __name__=='__main__' : a=-10 b=-2 solve(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := -10 ; b := -2 ; solve(a, b) ) else skip; operation solve(a : OclAny, b : OclAny) pre: true post: true activity: if (a > 0 & b > 0) then ( execute ("Positive")->display() ) else (if (a <= 0 & b >= 0) then ( execute ("Zero")->display() ) else ( var n : double := (a - b)->abs() + 1 ; if (n mod 2 = 0) then ( execute ("Positive")->display() ) else ( execute ("Negative")->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(x)for x in input().split()] b=list(set(a)) ind=[10000000]*(100001) cd=[0]*(100001) ans=[] for i in range(n): if ind[a[i]]==10000000 : ind[a[i]]=i else : if cd[a[i]]==0 : cd[a[i]]=i-ind[a[i]] ind[a[i]]=i else : if cd[a[i]]==(i-ind[a[i]]): ind[a[i]]=i else : cd[a[i]]=-1 for i in b : if cd[i]!=-1 : ans.append([i,cd[i]]) ans.sort() print(len(ans)) for i in ans : print(*i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var b : Sequence := (Set{}->union((a))) ; var ind : Sequence := MatrixLib.elementwiseMult(Sequence{ 10000000 }, (100001)) ; var cd : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (100001)) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if ind[a[i+1]+1] = 10000000 then ( ind[a[i+1]+1] := i ) else ( if cd[a[i+1]+1] = 0 then ( cd[a[i+1]+1] := i - ind[a[i+1]+1] ; ind[a[i+1]+1] := i ) else ( if cd[a[i+1]+1] = (i - ind[a[i+1]+1]) then ( ind[a[i+1]+1] := i ) else ( cd[a[i+1]+1] := -1 ) ) )) ; for i : b do ( if cd[i+1] /= -1 then ( execute ((Sequence{i}->union(Sequence{ cd[i+1] })) : ans) ) else skip) ; ans := ans->sort() ; execute ((ans)->size())->display() ; for i : ans do ( execute ((argument * (test (logical_test (comparison (expr (atom (name i))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) a=[int(i)for i in input().split()] a=sorted(zip(a,[i for i in range(n)])) i,j,c=0,0,0 ans=[] while itoInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; a := Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), Integer.subrange(0, n-1)->select(i | true)->collect(i | (i))->at(_indx)} )->sort() ; var i : OclAny := null; var j : OclAny := null; var c : OclAny := null; Sequence{i,j,c} := Sequence{0,0,0} ; var ans : Sequence := Sequence{} ; while (i->compareTo(n)) < 0 do ( var s : Set := Set{}->union(()) ; while (j->compareTo(n)) < 0 & a[i+1]->first() = a[j+1]->first() do ( if j - i = 0 then ( j := j + 1; continue ) else skip ; execute ((a[j+1][1+1] - a[j - 1+1][1+1]) : s) ; j := j + 1) ; if j - i = 1 then ( execute ((Sequence{a[i+1]->first(), 0}) : ans); c := c + 1 ) else ( if (s)->size() = 1 then ( execute ((Sequence{a[i+1]->first(), a[j - 1+1][1+1] - a[j - 2+1][1+1]}) : ans) ; c := c + 1 ) else skip ) ; var i : OclAny := j) ; execute (c)->display() ; for i : ans do ( execute (i->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Permutations(n,k): ans=1 if k>=2 : ans+=(n)*(n-1)//2 if k>=3 : ans+=((n)*(n-1)*(n-2)*2//6) if k>=4 : ans+=((n)*(n-1)*(n-2)*(n-3)*9//24) return ans if __name__=="__main__" : n,k=5,2 print(Permutations(n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{n,k} := Sequence{5,2} ; execute (Permutations(n, k))->display() ) else skip; operation Permutations(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var ans : int := 1 ; if k >= 2 then ( ans := ans + (n) * (n - 1) div 2 ) else skip ; if k >= 3 then ( ans := ans + ((n) * (n - 1) * (n - 2) * 2 div 6) ) else skip ; if k >= 4 then ( ans := ans + ((n) * (n - 1) * (n - 2) * (n - 3) * 9 div 24) ) else skip ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()); arr=[int(i)for i in input().split()]; dic=dict(); c=0 for i in range(n): x=arr[i] if x not in dic : dic[x]=[i] else : dic[x].append(i) arr2=[] x=list(dic.keys()) x.sort() for i in x : z=dic[i] if len(z)==1 : arr2.append([i,0]) else : d=z[1]-z[0] for j in range(2,len(z)): if z[j]-z[j-1]!=d : break else : arr2.append([i,d]) print(len(arr2)) for i in arr2 : print(*i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var arr : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); var dic : Map := (arguments ( )); var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := arr[i+1] ; if (dic)->excludes(x) then ( dic[x+1] := Sequence{ i } ) else ( (expr (atom (name dic)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) )) ; var arr2 : Sequence := Sequence{} ; x := (dic.keys()) ; x := x->sort() ; for i : x do ( var z : OclAny := dic[i+1] ; if (z)->size() = 1 then ( execute ((Sequence{i}->union(Sequence{ 0 })) : arr2) ) else ( var d : double := z[1+1] - z->first() ; (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name z)))))))) ))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name z)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))) - (expr (atom (name z)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name j))) - (expr (atom (number (integer 1)))))))))) ]))))) != (comparison (expr (atom (name d))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name arr2)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) , (test (logical_test (comparison (expr (atom (name d))))))) ]))))))) )))))))))))))) )) ; execute ((arr2)->size())->display() ; for i : arr2 do ( execute ((argument * (test (logical_test (comparison (expr (atom (name i))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import timeit arr=[] number=int(input()) arr_num=list(map(int,input().split())) counter=0 for i in range(0,len(arr_num)): if len(arr)-1toInteger() ; var arr_num : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var counter : int := 0 ; for i : Integer.subrange(0, (arr_num)->size()-1) do ( if ((arr)->size() - 1->compareTo(arr_num[i+1])) < 0 then ( for j : Integer.subrange((arr)->size(), arr_num[i+1] + 1-1) do ( execute ((Map{ "stop" |-> 1 }) : arr)) ) else skip ; if not((arr[arr_num[i+1]+1].keys())->includes('last_index')) then ( arr[arr_num[i+1]+1]->at('last_index') := i ; arr[arr_num[i+1]+1]->at('dis') := "0" ; arr[arr_num[i+1]+1]->at('stop') := 0 ; counter := counter + 1 ) else (if arr[arr_num[i+1]+1]->at('stop') = 0 then ( if arr[arr_num[i+1]+1]->at('dis') = '0' then ( arr[arr_num[i+1]+1]->at('dis') := i - arr[arr_num[i+1]+1]->at('last_index') ; arr[arr_num[i+1]+1]->at('last_index') := i ; arr[arr_num[i+1]+1]->at('stop') := 0 ) else ( if arr[arr_num[i+1]+1]->at('dis') = i - arr[arr_num[i+1]+1]->at('last_index') then ( arr[arr_num[i+1]+1]->at('last_index') := i ; continue ) else ( arr[arr_num[i+1]+1]->at('stop') := 1 ; counter := counter - 1 ) ) ) else skip)) ; execute (counter)->display() ; for i : Integer.subrange(0, (arr)->size()-1) do ( if arr[i+1]->at('stop') = 0 then ( execute (StringLib.formattedString("{i}SPACETOKEN SPACETOKEN{arr[i]['dis']}"))->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) elems=list(map(int,input().split(' '))) preds={} for i,x in enumerate(elems): if x not in preds : preds[x]=[i+1,[]] continue preds[x][1].append((i+1)-preds[x][0]) preds[x][0]=i+1 output=[] for x in sorted(preds.keys()): if len(preds[x][1])==0 : output.append('%d 0' % x) continue is_prog=all([c==preds[x][1][0]for c in preds[x][1]]) if is_prog : output.append('%d %d' %(x,preds[x][1][0])) print(len(output)) for r in output : print(r) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var elems : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var preds : OclAny := Set{} ; for _tuple : Integer.subrange(1, (elems)->size())->collect( _indx | Sequence{_indx-1, (elems)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); if (preds)->excludes(x) then ( preds[x+1] := Sequence{i + 1}->union(Sequence{ Sequence{} }) ; continue ) else skip ; (expr (atom (name preds)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) ))) - (expr (atom (name preds)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))))) )))) ; preds[x+1]->first() := i + 1) ; var output : Sequence := Sequence{} ; for x : preds.keys()->sort() do ( if (preds[x+1][1+1])->size() = 0 then ( execute ((StringLib.format('%d 0',x)) : output) ; continue ) else skip ; var is_prog : boolean := (preds[x+1][1+1]->select(c | true)->collect(c | (c = preds[x+1][1+1]->first())))->forAll( _x | _x = true ) ; if is_prog then ( execute ((StringLib.format('%d %d',Sequence{x, preds[x+1][1+1]->first()})) : output) ) else skip) ; execute ((output)->size())->display() ; for r : output do ( execute (r)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(s): z=s l=len(s) i=0 if(s.find('+')!=-1): i=s.find('+') s=s.replace('+','-') else : i=s.find('-') s=s.replace('-','+',1) print("Conjugate of ",z,"=",s) s="3-4i" solve(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := "3-4i" ; solve(s); operation solve(s : OclAny) pre: true post: true activity: var z : OclAny := s ; var l : int := (s)->size() ; var i : int := 0 ; if (s->indexOf('+') - 1 /= -1) then ( i := s->indexOf('+') - 1 ; s := s.replace('+', '-') ) else ( i := s->indexOf('-') - 1 ; s := s.replace('-', '+', 1) ) ; execute ("Conjugate of ")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heappop,heappush INF=float("inf") def dijkstra(n,G,s): dist=[INF]*n dist[s]=0 hq=[(0,s)] while hq : d,v=heappop(hq) if dist[v]dist[v]+child_d : dist[child]=dist[v]+child_d heappush(hq,(dist[child],child)) return dist n,u,v=map(int,input().split()) graph=[[]for _ in range(n)] edge=[list(map(int,input().split()))for _ in range(n-1)] for a,b in edge : graph[a-1].append((b-1,1)) graph[b-1].append((a-1,1)) from_u=dijkstra(n,graph,u-1) from_v=dijkstra(n,graph,v-1) fil=filter(lambda x : x[0]toReal() ; skip ; var u : OclAny := null; var v : OclAny := null; Sequence{n,u,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var graph : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var edge : Sequence := Integer.subrange(0, n - 1-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for _tuple : edge do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (atom (number (integer 1)))))))) )))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (atom (number (integer 1)))))))) )))))))) ))))) ; var from_u : OclAny := dijkstra(n, graph, u - 1) ; var from_v : OclAny := dijkstra(n, graph, v - 1) ; var fil : Sequence := (Integer.subrange(1, from_u->size())->collect( _indx | Sequence{from_u->at(_indx), from_v->at(_indx)} )->select(_tuple | true)->collect(_tuple | let fu : OclAny = _tuple->at(1) in let fv : OclAny = _tuple->at(2) in (Sequence{fu}->union(Sequence{ fv }))))->select( _x | (lambda x : OclAny in ((x->first()->compareTo(x[1+1])) < 0))->apply(_x) = true ) ; var sfil : Sequence := (fil)->sortedBy($x | (lambda x : OclAny in (Sequence{-x[1+1]}->union(Sequence{ -x->first() })))->apply($x)) ; execute (sfil->first()[1+1] - 1)->display(); operation dijkstra(n : OclAny, G : OclAny, s : OclAny) : OclAny pre: true post: true activity: var dist : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, n) ; dist[s+1] := 0 ; var hq : Sequence := Sequence{ Sequence{0, s} } ; while hq do ( var d : OclAny := null; var v : OclAny := null; Sequence{d,v} := heappop(hq) ; if (dist[v+1]->compareTo(d)) < 0 then ( continue ) else skip ; for _tuple : G[v+1] do (var _indx : int := 1; var child : OclAny := _tuple->at(_indx); _indx := _indx + 1; var child_d : OclAny := _tuple->at(_indx); if (dist[child+1]->compareTo(dist[v+1] + child_d)) > 0 then ( dist[child+1] := dist[v+1] + child_d ; heappush(hq, Sequence{dist[child+1], child}) ) else skip)) ; return dist; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() k=0 for i in range(len(a)): if(a[i]=="4" or a[i]=="7"): k+=1 if(k==4 or k==7): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var k : int := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( if (a[i+1] = "4" or a[i+1] = "7") then ( k := k + 1 ) else skip) ; if (k = 4 or k = 7) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lucky(n): return n.count('4')+n.count('7')==len(n) def nearlyLucky(n): return lucky(str(n.count('4')+n.count('7'))) print("YES" if nearlyLucky(input())else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; execute (if nearlyLucky((OclFile["System.in"]).readLine()) then "YES" else "NO" endif)->display(); operation lucky(n : OclAny) : OclAny pre: true post: true activity: return n->count('4') + n->count('7') = (n)->size(); operation nearlyLucky(n : OclAny) : OclAny pre: true post: true activity: return lucky(("" + ((n->count('4') + n->count('7'))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lucky_number(num): count=0 for i in num : if i=='4' or i=='7' : count+=1 if count==4 or count==7 : return "YES" else : return "NO" if __name__=="__main__" : num=input() print(lucky_number(num)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( num := (OclFile["System.in"]).readLine() ; execute (lucky_number(num))->display() ) else skip; operation lucky_number(num : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : num do ( if i = '4' or i = '7' then ( count := count + 1 ) else skip) ; if count = 4 or count = 7 then ( return "YES" ) else ( return "NO" ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) r=0 while n>0 : if n % 10==4 or n % 10==7 : r+=1 n//=10 if r==4 or r==7 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r : int := 0 ; while n > 0 do ( if n mod 10 = 4 or n mod 10 = 7 then ( r := r + 1 ) else skip ; n := n div 10) ; if r = 4 or r = 7 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=list(map(int,input())) s=0 for i in range(len(a)): if a[i]==4 or a[i]==7 : s+=1 if s==4 or s==7 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := (((OclFile["System.in"]).readLine())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : int := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( if a[i+1] = 4 or a[i+1] = 7 then ( s := s + 1 ) else skip) ; if s = 4 or s = 7 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) S=[input()for i in range(n)] C=[[0]*n for i in range(n)] for i in range(n): for j in range(n): if S[i][j]=='#' : continue if i+k-1=maxc : maxc=C[i][j] ans=(i+1,j+1) print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var C : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, n))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if S[i+1][j+1] = '#' then ( continue ) else skip ; if (i + k - 1->compareTo(n)) < 0 then ( (compound_stmt for (exprlist (expr (atom (name di)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name k)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ni)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name di))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ni)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) == (comparison (expr (atom '#')))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt for (exprlist (expr (atom (name di)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name k)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ni)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name di))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name C)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ni)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))))))) ) else skip ; if (j + k - 1->compareTo(n)) < 0 then ( (compound_stmt for (exprlist (expr (atom (name dj)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name k)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name nj)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (name dj))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name nj)))))))) ])))) == (comparison (expr (atom '#')))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt for (exprlist (expr (atom (name dj)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name k)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name nj)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (name dj))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name C)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name nj)))))))) ])))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))))))) ) else skip)) ; var maxc : int := 0 ; var ans : OclAny := Sequence{1, 1} ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if (C[i+1][j+1]->compareTo(maxc)) >= 0 then ( maxc := C[i+1][j+1] ; ans := Sequence{i + 1, j + 1} ) else skip)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findExtraCharacter(s1,s2): smallStr="" largeStr="" if(len(s1)>len(s2)): smallStr=s2 largeStr=s1 else : smallStr=s1 largeStr=s2 smallStrCodeTotal=0 largeStrCodeTotal=0 i=0 while(idisplay(); operation findExtraCharacter(s1 : OclAny, s2 : OclAny) : OclAny pre: true post: true activity: var smallStr : String := "" ; var largeStr : String := "" ; if (((s1)->size()->compareTo((s2)->size())) > 0) then ( smallStr := s2 ; largeStr := s1 ) else ( smallStr := s1 ; largeStr := s2 ) ; var smallStrCodeTotal : int := 0 ; var largeStrCodeTotal : int := 0 ; var i : int := 0 ; while ((i->compareTo((smallStr)->size())) < 0) do ( smallStrCodeTotal := smallStrCodeTotal + (smallStr[i+1])->char2byte() ; largeStrCodeTotal := largeStrCodeTotal + (largeStr[i+1])->char2byte() ; i := i + 1) ; largeStrCodeTotal := largeStrCodeTotal + (largeStr[i+1])->char2byte() ; var intChar : double := largeStrCodeTotal - smallStrCodeTotal ; return (intChar)->byte2char(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()); f=['#'*(n+2)] for x in range(n): f.append('#'+input()+'#') f.append('#'*(n+2)) ma=0 ; t=[1,1] for y in range(1,n+1): for x in range(1,n+1): if f[y][x]=='.' : v=1 ; h=1 c=x for _ in range(k-1): c+=1 if f[y][c]=='.' : h+=1 else : break c=x for _ in range(k-1): c-=1 if f[y][c]=='.' : h+=1 else : break c=y for _ in range(k-1): c+=1 if f[c][x]=='.' : v+=1 else : break c=y for _ in range(k-1): c-=1 if f[c][x]=='.' : v+=1 else : break cc=max(0,v-(k-1))+max(0,h-(k-1)) if cc>ma : t=[y,x] ma=cc print(*t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var f : Sequence := Sequence{ StringLib.nCopies('#', (n + 2)) } ; for x : Integer.subrange(0, n-1) do ( execute (('#' + (OclFile["System.in"]).readLine() + '#') : f)) ; execute ((StringLib.nCopies('#', (n + 2))) : f) ; var ma : int := 0; var t : Sequence := Sequence{1}->union(Sequence{ 1 }) ; for y : Integer.subrange(1, n + 1-1) do ( for x : Integer.subrange(1, n + 1-1) do ( if f[y+1][x+1] = '.' then ( var v : int := 1; var h : int := 1 ; var c : OclAny := x ; for _anon : Integer.subrange(0, k - 1-1) do ( c := c + 1 ; if f[y+1][c+1] = '.' then ( h := h + 1 ) else ( break )) ; c := x ; for _anon : Integer.subrange(0, k - 1-1) do ( c := c - 1 ; if f[y+1][c+1] = '.' then ( h := h + 1 ) else ( break )) ; c := y ; for _anon : Integer.subrange(0, k - 1-1) do ( c := c + 1 ; if f[c+1][x+1] = '.' then ( v := v + 1 ) else ( break )) ; c := y ; for _anon : Integer.subrange(0, k - 1-1) do ( c := c - 1 ; if f[c+1][x+1] = '.' then ( v := v + 1 ) else ( break )) ; var cc : OclAny := Set{0, v - (k - 1)}->max() + Set{0, h - (k - 1)}->max() ; if (cc->compareTo(ma)) > 0 then ( t := Sequence{y}->union(Sequence{ x }) ; ma := cc ) else skip ) else skip)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name t))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isprime(x): for i in range(2,math.sqrt(x)): if(x % i==0): return False ; return True ; def isNSqMinusnMSqPrime(m,n): if(n-m==1 and isprime(m+n)): return True ; else : return False ; m=13 ; n=16 ; if(isNSqMinusnMSqPrime(m,n)): print("YES"); else : print("NO"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; m := 13; ; n := 16; ; if (isNSqMinusnMSqPrime(m, n)) then ( execute ("YES")->display(); ) else ( execute ("NO")->display(); ); operation isprime(x : OclAny) pre: true post: true activity: for i : Integer.subrange(2, (x)->sqrt()-1) do ( if (x mod i = 0) then ( return false; ) else skip) ; return true;; operation isNSqMinusnMSqPrime(m : OclAny, n : OclAny) pre: true post: true activity: if (n - m = 1 & isprime(m + n)) then ( return true; ) else ( return false; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(float,input().split())) l=sorted(l) l=l[: :-1] ans=0 d=1 vze=0 for x in l : vze=vze+x*(d-vze) d*=(1-x) ans=max(ans,vze) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["double"])->apply(_x) )) ; l := l->sort() ; l := l(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var ans : int := 0 ; var d : int := 1 ; var vze : int := 0 ; for x : l do ( vze := vze + x * (d - vze) ; d := d * (1 - x) ; ans := Set{ans, vze}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**8) N,U,V=map(int,input().split()) U,V=U-1,V-1 AB=[tuple(map(int,input().split()))for i in range(N-1)] es=[[]for _ in range(N)] for a,b in AB : a,b=a-1,b-1 es[a].append(b) es[b].append(a) prev=[-1]*N def dfs(v,p=-1): for to in es[v]: if to==p : continue prev[to]=v dfs(to,v) dfs(U) path=[V] while prev[path[-1]]>=0 : path.append(prev[path[-1]]) ban=set(path[:(len(path)+1)//2]) reach=[0]*N reach[U]=1 def dfs2(v,p=-1): for to in es[v]: if to==p : continue if to in ban : continue reach[to]=1 dfs2(to,v) dfs2(U) depth=[0]*N ans=0 def dfs3(v,p=-1): global ans for to in es[v]: if to==p : continue depth[to]=depth[v]+1 if reach[to]: ans=max(ans,depth[v]) dfs3(to,v) dfs3(V) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute ans : OclAny; operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(8)) ; var N : OclAny := null; var U : OclAny := null; var V : OclAny := null; Sequence{N,U,V} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var U : OclAny := null; var V : OclAny := null; Sequence{U,V} := Sequence{U - 1,V - 1} ; var AB : Sequence := Integer.subrange(0, N - 1-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var es : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _tuple : AB do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{a - 1,b - 1} ; (expr (atom (name es)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name es)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var prev : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, N) ; skip ; dfs(U) ; var path : Sequence := Sequence{ V } ; while prev[path->last()+1] >= 0 do ( execute ((prev[path->last()+1]) : path)) ; var ban : Set := Set{}->union((path.subrange(1,((path)->size() + 1) div 2))) ; var reach : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; reach[U+1] := 1 ; skip ; dfs2(U) ; var depth : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var ans : int := 0 ; skip ; dfs3(V) ; execute (ans)->display(); operation dfs(v : OclAny, p : int) pre: true post: true activity: if p->oclIsUndefined() then p := -1 else skip; for to : es[v+1] do ( if to = p then ( continue ) else skip ; prev[to+1] := v ; dfs(to, v)); operation dfs2(v : OclAny, p : int) pre: true post: true activity: if p->oclIsUndefined() then p := -1 else skip; for to : es[v+1] do ( if to = p then ( continue ) else skip ; if (ban)->includes(to) then ( continue ) else skip ; reach[to+1] := 1 ; dfs2(to, v)); operation dfs3(v : OclAny, p : int) pre: true post: true activity: if p->oclIsUndefined() then p := -1 else skip; skip ; for to : es[v+1] do ( if to = p then ( continue ) else skip ; depth[to+1] := depth[v+1] + 1 ; if reach[to+1] then ( ans := Set{ans, depth[v+1]}->max() ) else skip ; dfs3(to, v)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) l=list(map(float,input().split())) l.sort(reverse=True) x=l[0] op=1-l[0] for i in range(1,t): aux=(1-l[i]) if(x*aux)+(l[i]*op)>x : x=(x*aux)+(l[i]*op) op*=aux else : break print(f"{x:.12f}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["double"])->apply(_x) )) ; l := l->sort() ; var x : OclAny := l->first() ; var op : double := 1 - l->first() ; for i : Integer.subrange(1, t-1) do ( var aux : double := (1 - l[i+1]) ; if ((x * aux) + (l[i+1] * op)->compareTo(x)) > 0 then ( x := (x * aux) + (l[i+1] * op) ; op := op * aux ) else ( break )) ; execute (StringLib.formattedString("{x:.12f}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=list(map(float,input().split())) probs=sorted(p)[: :-1] d=1 a,s=0,0 for i in probs : a=a*(1-i)+d*i d*=(1-i) if(a>s): s=a print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["double"])->apply(_x) )) ; var probs : OclAny := sorted(p)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var d : int := 1 ; var a : OclAny := null; var s : OclAny := null; Sequence{a,s} := Sequence{0,0} ; for i : probs do ( var a : double := a * (1 - i) + d * i ; d := d * (1 - i) ; if ((a->compareTo(s)) > 0) then ( var s : OclAny := a ) else skip) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=list(map(float,input().split())) ans=0 p.sort(reverse=True) S=p[0]/(1-p[0]+1e-10) ans=p[0] B=1-p[0] for i in range(1,n): if 1-S>1e-10 : ans+=B*p[i]*(1-S) B=B*(1-p[i]) S+=p[i]/(1-p[i]+1e-10) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["double"])->apply(_x) )) ; var ans : int := 0 ; p := p->sort() ; var S : double := p->first() / (1 - p->first() + ("1e-10")->toReal()) ; ans := p->first() ; var B : double := 1 - p->first() ; for i : Integer.subrange(1, n-1) do ( if 1 - S > ("1e-10")->toReal() then ( ans := ans + B * p[i+1] * (1 - S) ; B := B * (1 - p[i+1]) ; S := S + p[i+1] / (1 - p[i+1] + ("1e-10")->toReal()) ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : x=raw_input() if x=='-' : break else : n=0 m=input() while n!=m : h=input() x=x[h :]+x[: h] n+=1 print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var x : OclAny := raw_input() ; if x = '-' then ( break ) else ( var n : int := 0 ; var m : String := (OclFile["System.in"]).readLine() ; while n /= m do ( var h : String := (OclFile["System.in"]).readLine() ; x := x.subrange(h+1) + x.subrange(1,h) ; n := n + 1) ; execute (x)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque while True : string=input() if string=='-' : break string=deque(string) m=int(input()) for i in range(m): h=int(input()) string.rotate(-h) print(''.join(string)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var string : String := (OclFile["System.in"]).readLine() ; if string = '-' then ( break ) else skip ; string := (string) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, m-1) do ( var h : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; string.rotate(-h)) ; execute (StringLib.sumStringsWithSeparator((string), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : cards=input().strip() if cards=="-" : break else : n=int(input().strip()) for i in range(n): x=int(input().strip()) cards=cards[x : len(cards)]+cards[0 : x] print(cards) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var cards : OclAny := input()->trim() ; if cards = "-" then ( break ) else ( var n : int := ("" + ((input()->trim())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var x : int := ("" + ((input()->trim())))->toInteger() ; cards := cards.subrange(x+1, (cards)->size()) + cards.subrange(0+1, x)) ; execute (cards)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function while True : cards=raw_input().strip() if cards=='-' : break num=int(raw_input()) for i in(int(raw_input())for n in xrange(num)): cards=cards[i :]+cards[: i] print(cards) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var cards : OclAny := raw_input()->trim() ; if cards = '-' then ( break ) else skip ; var num : int := ("" + ((raw_input())))->toInteger() ; for i : Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name raw_input)) (trailer (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name xrange)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) ))))))))} do ( cards := cards.subrange(i+1) + cards.subrange(1,i)) ; execute (cards)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printHutStar(n): for i in range(n): for j in range(i+1,n): print('',end='') for j in range(0,2*i+1): print('*',end='') print() for i in range(3): for j in range(3): print('*',end='') for j in range(2*n-7): print('',end='') for j in range(3): print('*',end='') print() n=7 printHutStar(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 7 ; printHutStar(n); operation printHutStar(n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( execute ('')->display()) ; for j : Integer.subrange(0, 2 * i + 1-1) do ( execute ('*')->display()) ; execute (->display()) ; for i : Integer.subrange(0, 3-1) do ( for j : Integer.subrange(0, 3-1) do ( execute ('*')->display()) ; for j : Integer.subrange(0, 2 * n - 7-1) do ( execute ('')->display()) ; for j : Integer.subrange(0, 3-1) do ( execute ('*')->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while(True): s=raw_input() if(s=="-"): break m=input() for i in range(m): h=input() temp="" for j in range(h,len(s)): temp+=s[j] for j in range(h): temp+=s[j] s=temp print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while (true) do ( var s : OclAny := raw_input() ; if (s = "-") then ( break ) else skip ; var m : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, m-1) do ( var h : String := (OclFile["System.in"]).readLine() ; var temp : String := "" ; for j : Integer.subrange(h, (s)->size()-1) do ( temp := temp + s[j+1]) ; for j : Integer.subrange(0, h-1) do ( temp := temp + s[j+1]) ; s := temp) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dfs(l): x=len(l[0]) if l[0][-1]=="+" : b=0 i=1 while itoInteger() ; if n = 0 then ( break ) else skip ; main(n)); operation dfs(l : OclAny) : OclAny pre: true post: true activity: var x : int := (l->first())->size() ; if l->first()->last() = "+" then ( var b : int := 0 ; var i : int := 1 ; while (i->compareTo((l)->size())) < 0 do ( if (l[i+1])->size() = x + 1 & "0" <= l[i+1]->last() & (l[i+1]->last() <= "9") then ( b := b + ("" + ((l[i+1]->last())))->toInteger() ; i := i + 1 ) else (if (l[i+1])->size() = x + 1 & (l[i+1]->last() = "+" or l[i+1]->last() = "*") then ( var f : int := i ; i := i + 1 ; while (i->compareTo((l)->size())) < 0 do ( if (l[i+1])->size() = x + 1 then ( break ) else skip ; i := i + 1) ; b := b + dfs(l.subrange(f+1, i)) ) else skip)) ) else (if l->first()->last() = "*" then ( b := 1 ; i := 1 ; while (i->compareTo((l)->size())) < 0 do ( if (l[i+1])->size() = x + 1 & "0" <= l[i+1]->last() & (l[i+1]->last() <= "9") then ( b := b * ("" + ((l[i+1]->last())))->toInteger() ; i := i + 1 ) else (if (l[i+1])->size() = x + 1 & (l[i+1]->last() = "+" or l[i+1]->last() = "*") then ( f := i ; i := i + 1 ; while (i->compareTo((l)->size())) < 0 do ( if (l[i+1])->size() = x + 1 then ( break ) else skip ; i := i + 1) ; b := b * dfs(l.subrange(f+1, i)) ) else skip)) ) else ( b := ("" + ((l->first()->last())))->toInteger() ) ) ; return b; operation main(n : OclAny) pre: true post: true activity: l := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; execute (dfs(l))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- words=lambda t : list(map(t,input().split())) n,u,v=words(int) u-=1 v-=1 edges=[[]for i in range(n)] for i in range(n-1): f,t=words(int) edges[f-1].append(t-1) edges[t-1].append(f-1) from queue import Queue def bfs1(edges,stt): dist=[-1]*n q=Queue() q.put(stt) dist[stt]=0 while not q.empty(): v=q.get() for c in edges[v]: if dist[c]==-1 : dist[c]=dist[v]+1 q.put(c) return dist dist_v=bfs1(edges,v) dist_u=bfs1(edges,u) ans=0 for i in range(n): if dist_v[i]>dist_u[i]: ans=max(ans,dist_v[i]) print(max(ans-1,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var words : Function := lambda t : OclAny in (((input().split())->collect( _x | (t)->apply(_x) ))) ; var n : OclAny := null; var u : OclAny := null; var v : OclAny := null; Sequence{n,u,v} := words->apply(OclType["int"]) ; u := u - 1 ; v := v - 1 ; var edges : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, n - 1-1) do ( var f : OclAny := null; var t : OclAny := null; Sequence{f,t} := words->apply(OclType["int"]) ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name f))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name t))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name t))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name f))) - (expr (atom (number (integer 1)))))))))) ))))) ; skip ; skip ; var dist_v : OclAny := bfs1(edges, v) ; var dist_u : OclAny := bfs1(edges, u) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (dist_v[i+1]->compareTo(dist_u[i+1])) > 0 then ( ans := Set{ans, dist_v[i+1]}->max() ) else skip) ; execute (Set{ans - 1, 0}->max())->display(); operation bfs1(edges : OclAny, stt : OclAny) : OclAny pre: true post: true activity: var dist : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; var q : OclAny := Queue() ; q.put(stt) ; dist[stt+1] := 0 ; while not(q.empty()) do ( var v : OclAny := q.get() ; for c : edges[v+1] do ( if dist[c+1] = -1 then ( dist[c+1] := dist[v+1] + 1 ; q.put(c) ) else skip)) ; return dist; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break ; elif n==1 : print(input()) continue ; li=[input()for i in range(n)] index=0 def pls(depth): k=0 global index while len(li[index])>depth and li[index][depth-1]=='.' : if(not li[index][depth]=='+')and(not li[index][depth]=='*'): k+=int(li[index][depth]) index+=1 elif li[index][depth]=='+' : index+=1 k+=pls(depth+1) elif li[index][depth]=='*' : index+=1 k+=prd(depth+1) if index==n : return k else : return k def prd(depth): k=1 global index while len(li[index])>depth and li[index][depth-1]=='.' : if(not li[index][depth]=='+')and(not li[index][depth]=='*'): k*=int(li[index][depth]) index+=1 elif li[index][depth]=='+' : index+=1 k*=pls(depth+1) elif li[index][depth]=='*' : index+=1 k*=prd(depth+1) if index==n : return k else : return k if li[0]=='+' : index+=1 print(pls(1)) elif li[0]=='*' : index+=1 print(prd(1)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute index : OclAny; attribute index : OclAny; operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break; ) else (if n = 1 then ( execute ((OclFile["System.in"]).readLine())->display() ; continue; ) else skip) ; var li : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var index : int := 0 ; skip ; skip ; if li->first() = '+' then ( index := index + 1 ; execute (pls(1))->display() ) else (if li->first() = '*' then ( index := index + 1 ; execute (prd(1))->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- opr_list=["+","*"] def solve(): N=int(input()) while(N!=0): if(N==1): print(int(input())) else : ans=[0 for i in range(20)] s=[] opr=[0 for i in range(20)] for i in range(N): s.append(list(input())) layer=0 for i in range(N): nowlayer=s[i].count(".") if(nowlayer1): while(layer>1): if(opr[layer-2]=="+"): ans[layer-1]+=ans[layer] else : ans[layer-1]*=ans[layer] layer-=1 print(ans[1]) N=int(input()) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var opr_list : Sequence := Sequence{"+"}->union(Sequence{ "*" }) ; skip ; solve(); operation solve() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (N /= 0) do ( if (N = 1) then ( execute (("" + (((OclFile["System.in"]).readLine())))->toInteger())->display() ) else ( var ans : Sequence := Integer.subrange(0, 20-1)->select(i | true)->collect(i | (0)) ; var s : Sequence := Sequence{} ; var opr : Sequence := Integer.subrange(0, 20-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, N-1) do ( execute ((((OclFile["System.in"]).readLine())->characters()) : s)) ; var layer : int := 0 ; for i : Integer.subrange(0, N-1) do ( var nowlayer : OclAny := s[i+1]->count(".") ; if ((nowlayer->compareTo(layer)) < 0) then ( while ((nowlayer->compareTo(layer)) < 0) do ( if (opr[layer - 2+1] = "+") then ( ans[layer - 1+1] := ans[layer - 1+1] + ans[layer+1] ) else ( ans[layer - 1+1] := ans[layer - 1+1] * ans[layer+1] ) ; layer := layer - 1) ) else skip ; if ((opr_list)->includes(s[i+1]->last())) then ( opr[nowlayer+1] := s[i+1]->last() ; ans[nowlayer + 1+1] := if opr[nowlayer+1] = "+" then 0 else 1 endif ; layer := layer + 1 ) else ( if (opr[nowlayer - 1+1] = "+") then ( ans[nowlayer+1] := ans[nowlayer+1] + ("" + ((s[i+1]->last())))->toInteger() ) else ( ans[nowlayer+1] := ans[nowlayer+1] * ("" + ((s[i+1]->last())))->toInteger() ) ) ; layer := nowlayer) ; if (layer > 1) then ( while (layer > 1) do ( if (opr[layer - 2+1] = "+") then ( ans[layer - 1+1] := ans[layer - 1+1] + ans[layer+1] ) else ( ans[layer - 1+1] := ans[layer - 1+1] * ans[layer+1] ) ; layer := layer - 1) ) else skip ; execute (ans[1+1])->display() ) ; N := ("" + (((OclFile["System.in"]).readLine())))->toInteger()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(x,a,ind): if "0"<=a[0][ind]<="9" : return int(a[0][ind]) if a[0][ind]=="+" : i=j=1 su=0 while(i0 : a=[input()for i in range(n)] print(solve(n,a,0)) else : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while (1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n > 0 then ( a := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; execute (solve(n, a, 0))->display() ) else ( break )); operation solve(x : OclAny, a : OclAny, ind : OclAny) : OclAny pre: true post: true activity: if "0" <= a->first()[ind+1] & (a->first()[ind+1] <= "9") then ( return ("" + ((a->first()[ind+1])))->toInteger() ) else skip ; if a->first()[ind+1] = "+" then ( var i : OclAny := 1; var j : int := 1 ; var su : int := 0 ; while ((i->compareTo(x)) < 0) do ( if a[i+1][ind + 1+1] = "+" or a[i+1][ind + 1+1] = "*" then ( j := j + 1 ; while (j->compareTo(x)) < 0 & a[j+1][ind + 1+1] = "." do ( j := j + 1) ; su := su + solve(j - i, a.subrange(i+1, j), ind + 1) ; i := j ; j := j ) else ( su := su + ("" + ((a[j+1][ind + 1+1])))->toInteger() ; i := i + 1 ; j := j + 1 )) ; return su ) else skip ; if a->first()[ind+1] = "*" then ( i := 1; j := 1 ; su := 1 ; while ((i->compareTo(x)) < 0) do ( if a[i+1][ind + 1+1] = "+" or a[i+1][ind + 1+1] = "*" then ( j := j + 1 ; while (j->compareTo(x)) < 0 & a[j+1][ind + 1+1] = "." do ( j := j + 1) ; su := su * solve(j - i, a.subrange(i+1, j), ind + 1) ; i := j ; j := j ) else ( su := su * ("" + ((a[j+1][ind + 1+1])))->toInteger() ; i := i + 1 ; j := j + 1 )) ; return su ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans_list=[] def calclater(a,num_list): if a=="*" : ans=1 for i in num_list : ans*=int(i) elif a=="+" : ans=0 for i in num_list : ans+=int(i) return str(ans) while True : n=int(input()) if not n : break s_list=[[]for i in range(100)] now=0 now_len=0 for i in range(n): s=input() if not i : s_list[0]=[s] now_len=len(s) else : if len(s)==now_len : s_list[now].append(s[-1]) elif len(s)>now_len : now+=1 s_list[now]=[s[-1]] now_len=len(s) elif len(s)toInteger() ; if not(n) then ( break ) else skip ; var s_list : Sequence := Integer.subrange(0, 100-1)->select(i | true)->collect(i | (Sequence{})) ; var now : int := 0 ; var now_len : int := 0 ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if not(i) then ( s_list->first() := Sequence{ s } ; now_len := (s)->size() ) else ( if (s)->size() = now_len then ( (expr (atom (name s_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name now)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))))) )))) ) else (if ((s)->size()->compareTo(now_len)) > 0 then ( now := now + 1 ; s_list[now+1] := Sequence{ s->last() } ; now_len := (s)->size() ) else (if ((s)->size()->compareTo(now_len)) < 0 then ( while ((s)->size()->compareTo(now_len)) < 0 do ( s_list[now - 1+1]->last() := ("" + ((calclater(s_list[now - 1+1]->last(), (s_list[now+1]))))) ; s_list[now+1] := Sequence{} ; now_len := now_len - 1 ; now := now - 1) ; (expr (atom (name s_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name now)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))))) )))) ) else skip ) ) )) ; for i : Integer.subrange(-1 + 1, now - 1)->reverse() do ( s_list[i+1]->last() := ("" + ((calclater(s_list[i+1]->last(), s_list[i + 1+1]))))) ; execute ((s_list->first()->first()) : ans_list)) ; for i : ans_list do ( execute (i)->display()); operation calclater(a : OclAny, num_list : OclAny) : OclAny pre: true post: true activity: if a = "*" then ( var ans : int := 1 ; for i : num_list do ( ans := ans * ("" + ((i)))->toInteger()) ) else (if a = "+" then ( ans := 0 ; for i : num_list do ( ans := ans + ("" + ((i)))->toInteger()) ) else skip) ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reachable(graph,init): if init not in graph or graph[init]is None : return set() tmp,graph[init]=graph[init],None return tmp.union(*[reachable(graph,i)for i in tmp]) def sugoroku(m,d): d=[0]+d+[0] start,goal=0,len(d)-1 graph_to={goal :{goal}} graph_from={start :{start}} for init in range(len(d)-1): for xi in range(1,1+m): pos=min(init+xi,goal) to=max(start,min(pos+d[pos],goal)) try : graph_to[to].add(init) except KeyError : graph_to[to]={init} try : graph_from[init].add(to) except KeyError : graph_from[init]={to} unreachable_node=reachable(graph_from,start).difference(reachable(graph_to,goal)) return 0==len(unreachable_node) import sys f=sys.stdin while True : m=int(f.readline()) if m==0 : break d=[int(f.readline())for _ in range(int(f.readline()))] print('OK' if sugoroku(m,d)else 'NG') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var f : OclFile := OclFile["System.in"] ; while true do ( m := ("" + ((f.readLine())))->toInteger() ; if m = 0 then ( break ) else skip ; d := Integer.subrange(0, ("" + ((f.readLine())))->toInteger()-1)->select(_anon | true)->collect(_anon | (("" + ((f.readLine())))->toInteger())) ; execute (if sugoroku(m, d) then 'OK' else 'NG' endif)->display()); operation reachable(graph : OclAny, init : OclAny) : OclAny pre: true post: true activity: if (graph)->excludes(init) or graph[init+1] <>= null then ( return Set{}->union(()) ) else skip ; var tmp : OclAny := null; var graph[init+1] : OclAny := null; Sequence{tmp,graph[init+1]} := Sequence{graph[init+1],null} ; return tmp.union((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name reachable)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name graph))))))) , (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name tmp))))))) ]))))))); operation sugoroku(m : OclAny, d : OclAny) : OclAny pre: true post: true activity: d := Sequence{ 0 }->union(d)->union(Sequence{ 0 }) ; var start : OclAny := null; var goal : OclAny := null; Sequence{start,goal} := Sequence{0,(d)->size() - 1} ; var graph_to : Map := Map{ goal |-> Set{ goal } } ; var graph_from : Map := Map{ start |-> Set{ start } } ; for init : Integer.subrange(0, (d)->size() - 1-1) do ( for xi : Integer.subrange(1, 1 + m-1) do ( var pos : OclAny := Set{init + xi, goal}->min() ; var to : OclAny := Set{start, Set{pos + d[pos+1], goal}->min()}->max() ; try ((expr (atom (name graph_to)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name to)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name init)))))))) ))))) (except_clause except (test (logical_test (comparison (expr (atom (name KeyError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name graph_to)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name to)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom { (dictorsetmaker (testlist_comp (test (logical_test (comparison (expr (atom (name init)))))))) }))))))))))))) ; try ((expr (atom (name graph_from)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name init)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name to)))))))) ))))) (except_clause except (test (logical_test (comparison (expr (atom (name KeyError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name graph_from)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name init)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom { (dictorsetmaker (testlist_comp (test (logical_test (comparison (expr (atom (name to)))))))) }))))))))))))))) ; var unreachable_node : OclAny := reachable(graph_from, start) - (reachable(graph_to, goal)) ; return 0 = (unreachable_node)->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from collections import deque def bfs(adj_list,s): q=deque([s]) visited=[False]*(n+2) visited[s]=True while q : v=q.popleft() for nv in adj_list[v]: if not visited[nv]: visited[nv]=True q.append(nv) return visited while True : m=int(input()) if m==0 : break n=int(input()) d=[int(input())for _ in range(n)] adj_list=[[]for _ in range(n+2)] rev_adj_list=[[]for _ in range(n+2)] for i in range(n+1): for j in range(1,m+1): if i+j>n : adj_list[i].append(n+1) rev_adj_list[n+1].append(i) else : t=min(n+1,max(i+j+d[i+j-1],0)) adj_list[i].append(t) rev_adj_list[t].append(i) visited_1=bfs(adj_list,0) visited_2=bfs(rev_adj_list,n+1) for i in range(n+2): if visited_1[i]and not visited_2[i]: print('NG') break else : print('OK') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; while true do ( var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if m = 0 then ( break ) else skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; adj_list := Integer.subrange(0, n + 2-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var rev_adj_list : Sequence := Integer.subrange(0, n + 2-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, n + 1-1) do ( for j : Integer.subrange(1, m + 1-1) do ( if (i + j->compareTo(n)) > 0 then ( (expr (atom (name adj_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name rev_adj_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ) else ( var t : OclAny := Set{n + 1, Set{i + j + d[i + j - 1+1], 0}->max()}->min() ; (expr (atom (name adj_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) )))) ; (expr (atom (name rev_adj_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ))) ; var visited var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() : OclAny := bfs(adj_list, 0) ; var visited:= bfs(rev_adj_list, n + 1) : OclAny := bfs(rev_adj_list, n + 1) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 2)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (expr (atom (name visited var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger())) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))) and (logical_test not (logical_test (comparison (expr (atom (name visited_2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NG'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'OK'))))))) )))))))))))))))); operation bfs(adj_list : OclAny, s : OclAny) : OclAny pre: true post: true activity: var q : Sequence := (Sequence{ s }) ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (n + 2)) ; visited[s+1] := true ; while q do ( var v : OclAny := q->first() ; q := q->tail() ; for nv : adj_list[v+1] do ( if not(visited[nv+1]) then ( visited[nv+1] := true ; execute ((nv) : q) ) else skip)) ; return visited; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : m=int(input()) if not m : break n=int(input()) ds=[0]+[int(input())for _ in range(n)]+[0] g=[[]for _ in range(n+2)] rg=[[]for _ in range(n+2)] for i in range(n+2): for j in range(min(n+1,i+1),min(n+1,i+m)+1): j=max(0,min(n+1,j+ds[j])) g[i].append(j) rg[j].append(i) def go(g,bs,i): bs[i]=True for j in g[i]: if not bs[j]: go(g,bs,j) bs=[False]*(n+2) rbs=[False]*(n+2) go(g,bs,0) go(rg,rbs,n+1) if any((b and(not rb))for b,rb in zip(bs,rbs)): print('NG') else : print('OK') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(m) then ( break ) else skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ds : Sequence := Sequence{ 0 }->union(Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())))->union(Sequence{ 0 }) ; var g : Sequence := Integer.subrange(0, n + 2-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var rg : Sequence := Integer.subrange(0, n + 2-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, n + 2-1) do ( for j : Integer.subrange(Set{n + 1, i + 1}->min(), Set{n + 1, i + m}->min() + 1-1) do ( var j : OclAny := Set{0, Set{n + 1, j + ds[j+1]}->min()}->max() ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) ; (expr (atom (name rg)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))) ; skip ; bs := MatrixLib.elementwiseMult(Sequence{ false }, (n + 2)) ; var rbs : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (n + 2)) ; go(g, bs, 0) ; go(rg, rbs, n + 1) ; if ((argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (expr (atom (name b))))) and (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test not (logical_test (comparison (expr (atom (name rb)))))))) )))))))) )))))) (comp_for for (exprlist (expr (atom (name b))) , (expr (atom (name rb)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name bs))))))) , (argument (test (logical_test (comparison (expr (atom (name rbs)))))))) )))))))))->exists( _x | _x = true ) then ( execute ('NG')->display() ) else ( execute ('OK')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import queue while True : m=int(input()) if m==0 : break n=int(input()) d=[0]*(n+2) for i in range(1,n+1): d[i]=int(input()) visited=[False]*(n+2) visited[0]=True ok=[False]*(n+2) ok[n+1]=True rev=[[]for _ in range(n+2)] que=queue.LifoQueue() que.put(0) while not que.empty(): i=que.get() for j in range(1,m+1): if i+j>n+1 : break k=min(max(i+j+d[i+j],0),n+1) rev[k].append(i) if not visited[k]: que.put(k) visited[k]=True que.put(n+1) while not que.empty(): i=que.get() for j in rev[i]: if not ok[j]: ok[j]=True que.put(j) ans='OK' if not visited[n+1]: ans='NG' for i in range(n+1): if visited[i]and(not ok[i]): ans='NG' print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if m = 0 then ( break ) else skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 2)) ; for i : Integer.subrange(1, n + 1-1) do ( d[i+1] := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (n + 2)) ; visited->first() := true ; var ok : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (n + 2)) ; ok[n + 1+1] := true ; var rev : Sequence := Integer.subrange(0, n + 2-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var que : OclAny := queue.LifoQueue() ; que.put(0) ; while not(que.empty()) do ( var i : OclAny := que.get() ; for j : Integer.subrange(1, m + 1-1) do ( if (i + j->compareTo(n + 1)) > 0 then ( break ) else skip ; var k : OclAny := Set{Set{i + j + d[i + j+1], 0}->max(), n + 1}->min() ; (expr (atom (name rev)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ; if not(visited[k+1]) then ( que.put(k) ; visited[k+1] := true ) else skip)) ; que.put(n + 1) ; while not(que.empty()) do ( i := que.get() ; for j : rev[i+1] do ( if not(ok[j+1]) then ( ok[j+1] := true ; que.put(j) ) else skip)) ; var ans : String := 'OK' ; if not(visited[n + 1+1]) then ( ans := 'NG' ) else skip ; for i : Integer.subrange(0, n + 1-1) do ( if visited[i+1] & (not(ok[i+1])) then ( ans := 'NG' ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) menores,maiores,asc,nasc=[],[],0,0 for i in range(n): s=list(map(int,input().split()))[1 :] for i in range(len(s)): if i>0 and s[i]>s[i-1]: asc+=1 break elif i==len(s)-1 : nasc+=1 menores.append(min(s)) maiores.append(max(s)) resposta=asc*asc+2*asc*nasc menores.sort() maiores.sort() i=0 for x in maiores : while itoInteger() ; var menores : OclAny := null; var maiores : OclAny := null; var asc : OclAny := null; var nasc : OclAny := null; Sequence{menores,maiores,asc,nasc} := Sequence{Sequence{},Sequence{},0,0} ; for i : Integer.subrange(0, n-1) do ( var s : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->tail() ; for i : Integer.subrange(0, (s)->size()-1) do ( if i > 0 & (s[i+1]->compareTo(s[i - 1+1])) > 0 then ( asc := asc + 1 ; break ) else (if i = (s)->size() - 1 then ( nasc := nasc + 1 ; execute (((s)->min()) : menores) ; execute (((s)->max()) : maiores) ) else skip))) ; var resposta : double := asc * asc + 2 * asc * nasc ; menores := menores->sort() ; maiores := maiores->sort() ; var i : int := 0 ; for x : maiores do ( while (i->compareTo(nasc)) < 0 & (menores[i+1]->compareTo(x)) < 0 do ( i := i + 1) ; resposta := resposta + i) ; execute (resposta)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def LIS(hr): n=len(hr) lis=[0]*n lis[n-1]=1 ; for i in range(n-2,-1,-1): m=0 ; for j in range(i+1,n): if hr[i][0]m : m=lis[j] lis[i]=m+1 return lis[0] while True : n=int(input()) if n==0 : break hr=[] for i in range(n): hr.append(list(map(int,input().split()))) for i in range(int(input())): hr.append(list(map(int,input().split()))) hr=list(sorted(hr)) print(LIS(hr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; hr := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : hr)) ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : hr)) ; hr := (hr->sort()) ; execute (LIS(hr))->display()); operation LIS(hr : OclAny) : OclAny pre: true post: true activity: var n : int := (hr)->size() ; var lis : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; lis[n - 1+1] := 1; ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( var m : int := 0; ; for j : Integer.subrange(i + 1, n-1) do ( if (hr[i+1]->first()->compareTo(hr[j+1]->first())) < 0 & (hr[i+1][1+1]->compareTo(hr[j+1][1+1])) < 0 & (lis[j+1]->compareTo(m)) > 0 then ( m := lis[j+1] ) else skip) ; lis[i+1] := m + 1) ; return lis->first(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify import sys,bisect,math,itertools,pprint,fractions sys.setrecursionlimit(10**8) mod=10**9+7 INF=float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int,sys.stdin.readline().split())) n,ta,ao=inpl() ta-=1 ; ao-=1 g=[[]for i in range(n)] for i in range(n-1): a,b=inpl() g[a-1].append(b-1) g[b-1].append(a-1) ta_dist=[None]*n ta_dist[ta]=0 ao_dist=[None]*n ao_dist[ao]=0 def ta_dfs(node): for v in g[node]: if ta_dist[v]!=None : continue ta_dist[v]=ta_dist[node]+1 ta_dfs(v) def ao_dfs(node): for v in g[node]: if ao_dist[v]!=None : continue ao_dist[v]=ao_dist[node]+1 ao_dfs(v) ao_dfs(ao) ta_dfs(ta) res=0 for i in range(n): if ta_dist[i]>ao_dist[i]: continue res=max(res,ao_dist[i]) print(res-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; var mod : double := (10)->pow(9) + 7 ; var INF : double := ("" + (('inf')))->toReal() ; skip ; skip ; var n : OclAny := null; var ta : OclAny := null; var ao : OclAny := null; Sequence{n,ta,ao} := inpl() ; ta := ta - 1; ao := ao - 1 ; var g : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, n - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := inpl() ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ))))) ; var ta_dist : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; ta_dist[ta+1] := 0 ; var ao_dist : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; ao_dist[ao+1] := 0 ; skip ; skip ; ao_dfs(ao) ; ta_dfs(ta) ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (ta_dist[i+1]->compareTo(ao_dist[i+1])) > 0 then ( continue ) else skip ; res := Set{res, ao_dist[i+1]}->max()) ; execute (res - 1)->display(); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inpl() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ta_dfs(node : OclAny) pre: true post: true activity: for v : g[node+1] do ( if ta_dist[v+1] /= null then ( continue ) else skip ; ta_dist[v+1] := ta_dist[node+1] + 1 ; ta_dfs(v)); operation ao_dfs(node : OclAny) pre: true post: true activity: for v : g[node+1] do ( if ao_dist[v+1] /= null then ( continue ) else skip ; ao_dist[v+1] := ao_dist[node+1] + 1 ; ao_dfs(v)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def search(x,visited,edges): if visited[x]: return visited[x]=True for to in edges[x]: search(to,visited,edges) def main(): while True : m=int(input()) if m==0 : break n=int(input()) mp=[0]+[int(input())for _ in range(n)]+[0] visited=[False]*(n+2) rev_visited=[False]*(n+2) edges=[[]for _ in range(n+2)] rev_edges=[[]for _ in range(n+2)] for i in range(n+2): for j in range(1,m+1): nex=i+j nex=min(nex,n+1) nex+=mp[nex] nex=min(nex,n+1) nex=max(nex,0) edges[i].append(nex) rev_edges[nex].append(i) search(0,visited,edges) search(n+1,rev_visited,rev_edges) for node in range(n+1): if visited[node]and not rev_visited[node]: print("NG") break else : print("OK") main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation search(x : OclAny, visited : OclAny, edges : OclAny) pre: true post: true activity: if visited[x+1] then ( return ) else skip ; visited[x+1] := true ; for to : edges[x+1] do ( search(to, visited, edges)); operation main() pre: true post: true activity: while true do ( var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if m = 0 then ( break ) else skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mp : Sequence := Sequence{ 0 }->union(Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())))->union(Sequence{ 0 }) ; visited := MatrixLib.elementwiseMult(Sequence{ false }, (n + 2)) ; var rev_visited : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (n + 2)) ; edges := Integer.subrange(0, n + 2-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var rev_edges : Sequence := Integer.subrange(0, n + 2-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, n + 2-1) do ( for j : Integer.subrange(1, m + 1-1) do ( var nex : OclAny := i + j ; nex := Set{nex, n + 1}->min() ; nex := nex + mp[nex+1] ; nex := Set{nex, n + 1}->min() ; nex := Set{nex, 0}->max() ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name nex)))))))) )))) ; (expr (atom (name rev_edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name nex)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))) ; search(0, visited, edges) ; search(n + 1, rev_visited, rev_edges) ; (compound_stmt for (exprlist (expr (atom (name node)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (expr (atom (name visited)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name node)))))))) ]))))) and (logical_test not (logical_test (comparison (expr (atom (name rev_visited)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name node)))))))) ])))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NG"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "OK"))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline string=list(input().strip()); day=int(input()); lenth=len(string); indexes=input().strip().split(); arr=[0]*lenth for i in indexes : arr[int(i)-1]+=1 arr[lenth-int(i)]-=1 cum=[arr[0]] for i in range(1,lenth): cum.append(arr[i]+cum[-1]) for i in range(lenth//2): if cum[i]% 2==1 : x,y=string[i],string[lenth-i-1] string[i],string[lenth-i-1]=y,x print("".join(string)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; var string : Sequence := (input()->trim()); var day : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var lenth : int := (string)->size(); var indexes : OclAny := input()->trim().split(); var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, lenth) ; for i : indexes do ( arr[("" + ((i)))->toInteger() - 1+1] := arr[("" + ((i)))->toInteger() - 1+1] + 1 ; arr[lenth - ("" + ((i)))->toInteger()+1] := arr[lenth - ("" + ((i)))->toInteger()+1] - 1) ; var cum : Sequence := Sequence{ arr->first() } ; for i : Integer.subrange(1, lenth-1) do ( execute ((arr[i+1] + cum->last()) : cum)) ; for i : Integer.subrange(0, lenth div 2-1) do ( if cum[i+1] mod 2 = 1 then ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{string[i+1],string[lenth - i - 1+1]} ; var string[i+1] : OclAny := null; var string[lenth - i - 1+1] : OclAny := null; Sequence{string[i+1],string[lenth - i - 1+1]} := Sequence{y,x} ) else skip) ; execute (StringLib.sumStringsWithSeparator((string), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- read=lambda : map(int,input().split()) s=input() m=int(input()) a=[int(i)-1 for i in input().split()] n=len(s) c=[0]*(n+1) for i in a : c[i]+=1 mid=n//2 cnt=0 ans=list(s) for i in range(mid): cnt+=c[i] if cnt % 2 : ans[i],ans[n-i-1]=ans[n-i-1],ans[i] print(''.join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var read : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : String := (OclFile["System.in"]).readLine() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger() - 1)) ; var n : int := (s)->size() ; var c : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : a do ( c[i+1] := c[i+1] + 1) ; var mid : int := n div 2 ; var cnt : int := 0 ; var ans : Sequence := (s)->characters() ; for i : Integer.subrange(0, mid-1) do ( cnt := cnt + c[i+1] ; if cnt mod 2 then ( var ans[i+1] : OclAny := null; var ans[n - i - 1+1] : OclAny := null; Sequence{ans[i+1],ans[n - i - 1+1]} := Sequence{ans[n - i - 1+1],ans[i+1]} ) else skip) ; execute (StringLib.sumStringsWithSeparator((ans), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(input()) m=int(input()) s_s=[0]*len(s) for a in map(int,input().split()): s_s[a-1]+=1 cur=0 for i in range(len(s)//2): cur+=s_s[i] if cur & 1 : s[i],s[len(s)-i-1]=s[len(s)-i-1],s[i] print("".join(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s_s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (s)->size()) ; for a : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( s_s[a - 1+1] := s_s[a - 1+1] + 1) ; var cur : int := 0 ; for i : Integer.subrange(0, (s)->size() div 2-1) do ( cur := cur + s_s[i+1] ; if MathLib.bitwiseAnd(cur, 1) then ( var s[i+1] : OclAny := null; var s[(s)->size() - i - 1+1] : OclAny := null; Sequence{s[i+1],s[(s)->size() - i - 1+1]} := Sequence{s[(s)->size() - i - 1+1],s[i+1]} ) else skip) ; execute (StringLib.sumStringsWithSeparator((s), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ss=input() s=list(ss) n=int(input()) a=list(map(int,input().split())) i=0 l=len(s) a.sort() k=0 for i in range(0,l//2): while kcharacters() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var i : int := 0 ; var l : int := (s)->size() ; a := a->sort() ; var k : int := 0 ; for i : Integer.subrange(0, l div 2-1) do ( while (k->compareTo(n)) < 0 & (a[k+1] - 1->compareTo(i)) <= 0 do ( k := k + 1) ; if k mod 2 = 1 then ( var s[i+1] : OclAny := null; var s[l - i - 1+1] : OclAny := null; Sequence{s[i+1],s[l - i - 1+1]} := Sequence{s[l - i - 1+1],s[i+1]} ) else skip) ; execute (StringLib.sumStringsWithSeparator((s), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input("") n=int(input()) li1=list(map(int,input().split())) li=list(s) ma=0 l=len(s) p=int(l/2) m=[0]*p for i in li1 : m[i-1]+=1 for i in range(1,p): m[i]+=m[i-1] for i in range(p): if m[i]% 2!=0 : li[i],li[l-i-1]=li[l-i-1],li[i] for i in li : print(i,end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine("") ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var li : Sequence := (s)->characters() ; var ma : int := 0 ; var l : int := (s)->size() ; var p : int := ("" + ((l / 2)))->toInteger() ; var m : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, p) ; for i : li1 do ( m[i - 1+1] := m[i - 1+1] + 1) ; for i : Integer.subrange(1, p-1) do ( m[i+1] := m[i+1] + m[i - 1+1]) ; for i : Integer.subrange(0, p-1) do ( if m[i+1] mod 2 /= 0 then ( var li[i+1] : OclAny := null; var li[l - i - 1+1] : OclAny := null; Sequence{li[i+1],li[l - i - 1+1]} := Sequence{li[l - i - 1+1],li[i+1]} ) else skip) ; for i : li do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n=int(input()) w=list(map(int,input().split())) d=[] i=0 if w[0]=n : break while i+1w[i+1]: i+=1 d.append(w[i]) if i+1>=n : break print(len(d)) print(' '.join(map(str,d))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : Sequence := Sequence{} ; var i : int := 0 ; if (w->first()->compareTo(w[1+1])) < 0 then ( execute ((w->first()) : d) ) else skip ; while (i + 1->compareTo(n)) < 0 do ( while (i + 1->compareTo(n)) < 0 & (w[i+1]->compareTo(w[i + 1+1])) < 0 do ( i := i + 1) ; execute ((w[i+1]) : d) ; if (i + 1->compareTo(n)) >= 0 then ( break ) else skip ; while (i + 1->compareTo(n)) < 0 & (w[i+1]->compareTo(w[i + 1+1])) > 0 do ( i := i + 1) ; execute ((w[i+1]) : d) ; if (i + 1->compareTo(n)) >= 0 then ( break ) else skip) ; execute ((d)->size())->display() ; execute (StringLib.sumStringsWithSeparator(((d)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) x=a[0] b=[x] if(a[1]>x): t=1 else : t=0 i=1 while(ix and a[i]>a[i-1]): i+=1 else : b+=[a[i-1]] x=a[i-1] t=0 else : if(a[i]toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := a->first() ; var b : Sequence := Sequence{ x } ; if ((a[1+1]->compareTo(x)) > 0) then ( var t : int := 1 ) else ( t := 0 ) ; var i : int := 1 ; (compound_stmt while (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name i)))) < (comparison (expr (atom (name n)))))))) )))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name t)))) == (comparison (expr (atom (number (integer 1))))))))) )))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) > (comparison (expr (atom (name x)))))) and (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) > (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))))))) ])))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name t)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))))))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) < (comparison (expr (atom (name x)))))) and (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) < (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))))))) ])))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name t)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))))))) ]))))))))))))) ; execute ((b)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name b))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() s_list=[s[_]for _ in range(len(s))] dic=dict() for c in s_list : if c in dic : dic[c]+=1 else : dic[c]=1 flg=True for key in dic : if dic[key]% 2!=0 : flg=False break if flg : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var s_list : Sequence := Integer.subrange(0, (s)->size()-1)->select(_anon | true)->collect(_anon | (s[_anon+1])) ; var dic : Map := (arguments ( )) ; for c : s_list do ( if (dic)->includes(c) then ( dic[c+1] := dic[c+1] + 1 ) else ( dic[c+1] := 1 )) ; var flg : boolean := true ; for key : dic->keys() do ( if dic[key+1] mod 2 /= 0 then ( flg := false ; break ) else skip) ; if flg then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w=input() s='abcdefghijklmnopqrstuvwxyz' c=0 if len(w)% 2==1 : print('No') else : for i in range(len(s)): if w.count(s[i])% 2==1 : c+=1 if c>0 : print('No') else : print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : String := (OclFile["System.in"]).readLine() ; var s : String := 'abcdefghijklmnopqrstuvwxyz' ; var c : int := 0 ; if (w)->size() mod 2 = 1 then ( execute ('No')->display() ) else ( for i : Integer.subrange(0, (s)->size()-1) do ( if w->count(s[i+1]) mod 2 = 1 then ( c := c + 1 ) else skip) ; if c > 0 then ( execute ('No')->display() ) else ( execute ('Yes')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines n,u,v=map(int,readline().split()) m=map(int,read().split()) data=list(zip(m,m)) graph=[[]for _ in range(n+1)] for a,b in data : graph[a].append(b) graph[b].append(a) def dfs(v): dist=[None]*(n+1) dist[v]=0 stack=[v] while stack : x=stack.pop() for y in graph[x]: if dist[y]is None : dist[y]=dist[x]+1 stack.append(y) return dist res=0 du,dv=dfs(u),dfs(v) for i in range(1,n+1): dvi=dv[i] if du[i]<=dvi : if dvi>res : res=dvi print(res-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; var n : OclAny := null; var u : OclAny := null; var v : OclAny := null; Sequence{n,u,v} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : Sequence := (read().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var data : Sequence := (Integer.subrange(1, m->size())->collect( _indx | Sequence{m->at(_indx), m->at(_indx)} )) ; var graph : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _tuple : data do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; skip ; var res : int := 0 ; var du : OclAny := null; var dv : OclAny := null; Sequence{du,dv} := Sequence{dfs(u),dfs(v)} ; for i : Integer.subrange(1, n + 1-1) do ( var dvi : OclAny := dv[i+1] ; if (du[i+1]->compareTo(dvi)) <= 0 then ( if (dvi->compareTo(res)) > 0 then ( res := dvi ) else skip ) else skip) ; execute (res - 1)->display(); operation dfs(v : OclAny) : OclAny pre: true post: true activity: var dist : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (n + 1)) ; dist[v+1] := 0 ; var stack : Sequence := Sequence{ v } ; while stack do ( var x : OclAny := stack->last() ; stack := stack->front() ; for y : graph[x+1] do ( if dist[y+1] <>= null then ( dist[y+1] := dist[x+1] + 1 ; execute ((y) : stack) ) else skip)) ; return dist; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break hr_lst=[] for _ in range(n): h,r=map(int,input().split()) hr_lst.append((h,r)) m=int(input()) for _ in range(m): h,r=map(int,input().split()) hr_lst.append((h,r)) hr_lst.sort(reverse=True) r_lst=[[]for _ in range(1001)] for h,r in hr_lst : r_lst[h].append(r) r_lst=[lst for lst in r_lst if lst!=[]] dp=[0]*1001 for x in range(len(r_lst)): vlst=r_lst[x] max_v=1000 for v in vlst : dpv1=dp[v-1]+1 for y in range(max_v,v-1,-1): if dp[y]toInteger() ; if n = 0 then ( break ) else skip ; var hr_lst : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var h : OclAny := null; var r : OclAny := null; Sequence{h,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{h, r}) : hr_lst)) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, m-1) do ( var h : OclAny := null; var r : OclAny := null; Sequence{h,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{h, r}) : hr_lst)) ; hr_lst := hr_lst->sort() ; var r_lst : Sequence := Integer.subrange(0, 1001-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _tuple : hr_lst do (var _indx : int := 1; var h : OclAny := _tuple->at(_indx); _indx := _indx + 1; var r : OclAny := _tuple->at(_indx); (expr (atom (name r_lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name h)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name r)))))))) ))))) ; r_lst := r_lst->select(lst | lst /= Sequence{})->collect(lst | (lst)) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 1001) ; for x : Integer.subrange(0, (r_lst)->size()-1) do ( var vlst : OclAny := r_lst[x+1] ; var max_v : int := 1000 ; for v : vlst do ( var dpv1 : OclAny := dp[v - 1+1] + 1 ; for y : Integer.subrange(v - 1 + 1, max_v)->reverse() do ( if (dp[y+1]->compareTo(dpv1)) < 0 then ( dp[y+1] := dpv1 ) else skip) ; max_v := v)) ; execute (dp[1000+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w=input() ans='Yes' if len(w)% 2==1 : ans='No' else : s=sorted(w) count=1 for i in range(1,len(s)): if s[i]==s[i-1]: count+=1 else : if count % 2==1 : ans='No' break count=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : String := (OclFile["System.in"]).readLine() ; var ans : String := 'Yes' ; if (w)->size() mod 2 = 1 then ( ans := 'No' ) else ( var s : Sequence := w->sort() ; var count : int := 1 ; for i : Integer.subrange(1, (s)->size()-1) do ( if s[i+1] = s[i - 1+1] then ( count := count + 1 ) else ( if count mod 2 = 1 then ( ans := 'No' ; break ) else skip ; count := 1 )) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=str(input()) t=list(s) t.sort() a=[] b=1 for i in range(len(t)): if i>=1 : if t[i]==t[i-1]: b=b+1 else : a.append(b) b=1 a.append(b) for i in range(len(a)): if a[i]% 2!=0 : print("No") break else : if i==len(a)-1 : print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; var t : Sequence := (s)->characters() ; t := t->sort() ; var a : Sequence := Sequence{} ; var b : int := 1 ; for i : Integer.subrange(0, (t)->size()-1) do ( if i >= 1 then ( if t[i+1] = t[i - 1+1] then ( b := b + 1 ) else ( execute ((b) : a) ; b := 1 ) ) else skip) ; execute ((b) : a) ; for i : Integer.subrange(0, (a)->size()-1) do ( if a[i+1] mod 2 /= 0 then ( execute ("No")->display() ; break ) else ( if i = (a)->size() - 1 then ( execute ("Yes")->display() ) else skip )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w=input() hash={} for x in range(len(w)): hash[w[x]]=0 for x in range(len(w)): hash[w[x]]+=1 beautiful=True for v in hash.values(): if v % 2!=0 : beautiful=False if beautiful : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : String := (OclFile["System.in"]).readLine() ; var hash : OclAny := Set{} ; for x : Integer.subrange(0, (w)->size()-1) do ( hash[w[x+1]+1] := 0) ; for x : Integer.subrange(0, (w)->size()-1) do ( hash[w[x+1]+1] := hash[w[x+1]+1] + 1) ; var beautiful : boolean := true ; for v : hash.values() do ( if v mod 2 /= 0 then ( beautiful := false ) else skip) ; if beautiful then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import* def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s=input() return(list(s[: len(s)-1])) def invr(): return(map(int,input().split())) n=inp() goals=defaultdict(int) for _ in range(n): goals[input()]+=1 teams=list(goals.keys()) if len(teams)==1 : print(teams[0]) else : if goals[teams[0]]>goals[teams[1]]: print(teams[0]) else : print(teams[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var n : OclAny := inp() ; var goals : OclAny := defaultdict(OclType["int"]) ; for _anon : Integer.subrange(0, n-1) do ( goals[(OclFile["System.in"]).readLine()+1] := goals[(OclFile["System.in"]).readLine()+1] + 1) ; var teams : Sequence := (goals.keys()) ; if (teams)->size() = 1 then ( execute (teams->first())->display() ) else ( if (goals[teams->first()+1]->compareTo(goals[teams[1+1]+1])) > 0 then ( execute (teams->first())->display() ) else ( execute (teams[1+1])->display() ) ); operation inp() : OclAny pre: true post: true activity: return (("" + (((OclFile["System.in"]).readLine())))->toInteger()); operation inlt() : OclAny pre: true post: true activity: return (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))); operation insr() : OclAny pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; return ((s.subrange(1,(s)->size() - 1))); operation invr() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) team=[] for i in range(n): team.append(input()) team.sort() if team.count(team[0])>team.count(team[-1]): print(team[0]) else : print(team[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var team : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : team)) ; team := team->sort() ; if (team->count(team->first())->compareTo(team->count(team->last()))) > 0 then ( execute (team->first())->display() ) else ( execute (team->last())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- time=[['',0],['',0]] n=int(input()) for i in range(n): gol=input() if(i==0): time[0][0]=gol if(time[0][0]==gol): time[0][1]+=1 else : if(time[1][0]==''): time[1][0]=gol time[1][1]+=1 if(time[0][1]>time[1][1]): print(time[0][0]) else : print(time[1][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var time : Sequence := Sequence{Sequence{''}->union(Sequence{ 0 })}->union(Sequence{ Sequence{''}->union(Sequence{ 0 }) }) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var gol : String := (OclFile["System.in"]).readLine() ; if (i = 0) then ( time->first()->first() := gol ) else skip ; if (time->first()->first() = gol) then ( time->first()[1+1] := time->first()[1+1] + 1 ) else ( if (time[1+1]->first() = '') then ( time[1+1]->first() := gol ) else skip ; time[1+1][1+1] := time[1+1][1+1] + 1 )) ; if ((time->first()[1+1]->compareTo(time[1+1][1+1])) > 0) then ( execute (time->first()->first())->display() ) else ( execute (time[1+1]->first())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) d={} for i in range(0,N): s=input() if s not in d.keys(): d[s]=1 else : d[s]+=1 max=0 ans='' for i in d.keys(): if d[i]>max : ans=i max=d[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : OclAny := Set{} ; for i : Integer.subrange(0, N-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if (d.keys())->excludes(s) then ( d->at(s) := 1 ) else ( d->at(s) := d->at(s) + 1 )) ; var max : int := 0 ; var ans : String := '' ; for i : d.keys() do ( if (d[i+1]->compareTo(max)) > 0 then ( ans := i ; max := d[i+1] ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) d={} for i in range(n): s=input() if s in d : d[s]+=1 else : d[s]=1 res="" j=0 for i in d : if d[i]>j : res=i j=d[i] print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if (d)->includes(s) then ( d->at(s) := d->at(s) + 1 ) else ( d->at(s) := 1 )) ; var res : String := "" ; var j : int := 0 ; for i : d do ( if (d[i+1]->compareTo(j)) > 0 then ( res := i ; j := d[i+1] ) else skip) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break else : phlist=[] phflag=0 for i in range(n): phlist.append(input()) for i in range(len(phlist)-4): cur=0 state=0 for j in range(i,len(phlist)): s=phlist[j] cur+=len(s) if state==0 and cur<5 : continue elif state==0 and cur==5 : cur=0 state=1 elif state==1 and cur<7 : continue elif state==1 and cur==7 : cur=0 state=2 elif state==2 and cur<5 : continue elif state==2 and cur==5 : cur=0 state=3 elif state==3 and cur<7 : continue elif state==3 and cur==7 : cur=0 state=4 elif state==4 and cur<7 : continue elif state==4 and cur==7 : print(i+1) phflag=1 break if phflag : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else ( var phlist : Sequence := Sequence{} ; var phflag : int := 0 ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : phlist)) ; for i : Integer.subrange(0, (phlist)->size() - 4-1) do ( var cur : int := 0 ; var state : int := 0 ; for j : Integer.subrange(i, (phlist)->size()-1) do ( var s : OclAny := phlist[j+1] ; cur := cur + (s)->size() ; if state = 0 & cur < 5 then ( continue ) else (if state = 0 & cur = 5 then ( cur := 0 ; state := 1 ) else (if state = 1 & cur < 7 then ( continue ) else (if state = 1 & cur = 7 then ( cur := 0 ; state := 2 ) else (if state = 2 & cur < 5 then ( continue ) else (if state = 2 & cur = 5 then ( cur := 0 ; state := 3 ) else (if state = 3 & cur < 7 then ( continue ) else (if state = 3 & cur = 7 then ( cur := 0 ; state := 4 ) else (if state = 4 & cur < 7 then ( continue ) else (if state = 4 & cur = 7 then ( execute (i + 1)->display() ; phflag := 1 ; break ) else skip ) ) ) ) ) ) ) ) ) ) ; if phflag then ( break ) else skip) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools n=int(input()) p=tuple(map(int,input().split())) q=tuple(map(int,input().split())) l=list(itertools.permutations(range(1,n+1))) print(abs(l.index(p)-l.index(q))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : Sequence := (itertools.permutations(Integer.subrange(1, n + 1-1))) ; execute ((l->indexOf(p) - 1 - l->indexOf(q) - 1)->abs())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- checklis=[5,7,5,7,7] def check(S): b=0 index=0 for s in S : b+=len(s) if checklis[index]==b : index+=1 b=0 if index==5 : return True elif checklis[index]>b : continue else : return False return False def main(n): s=[input()for i in range(n)] for i in range(n): if check(s[i :]): print(i+1) return while 1 : n=int(input()) if n==0 : break main(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var checklis : Sequence := Sequence{5}->union(Sequence{7}->union(Sequence{5}->union(Sequence{7}->union(Sequence{ 7 })))) ; skip ; skip ; while 1 do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; main(n)); operation check(S : OclAny) : OclAny pre: true post: true activity: var b : int := 0 ; var index : int := 0 ; for s : S do ( b := b + (s)->size() ; if checklis[index+1] = b then ( index := index + 1 ; b := 0 ; if index = 5 then ( return true ) else skip ) else (if (checklis[index+1]->compareTo(b)) > 0 then ( continue ) else ( return false ) ) ) ; return false; operation main(n : OclAny) pre: true post: true activity: var s : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; for i : Integer.subrange(0, n-1) do ( if check(s.subrange(i+1)) then ( execute (i + 1)->display() ; return ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break dolls=[] for i in range(n): h,r=[int(j)for j in input().split(" ")] dolls.append((h,r)) m=int(input()) for j in range(m): h,r=[int(j)for j in input().split(" ")] dolls.append((h,r)) dolls=sorted(dolls,key=lambda w :(w[0],-1*w[1])) r=[i[1]for i in dolls] table=[1 for i in range(len(r))] for i in range(len(r)): for j in range(i): if r[j]toInteger() ; if n = 0 then ( break ) else skip ; var dolls : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var h : OclAny := null; var r : OclAny := null; Sequence{h,r} := input().split(" ")->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; execute ((Sequence{h, r}) : dolls)) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, m-1) do ( var h : OclAny := null; var r : OclAny := null; Sequence{h,r} := input().split(" ")->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; execute ((Sequence{h, r}) : dolls)) ; dolls := dolls->sortedBy($x | (lambda w : OclAny in (Sequence{w->first(), -1 * w[1+1]}))->apply($x)) ; var r : Sequence := dolls->select(i | true)->collect(i | (i[1+1])) ; var table : Sequence := Integer.subrange(0, (r)->size()-1)->select(i | true)->collect(i | (1)) ; for i : Integer.subrange(0, (r)->size()-1) do ( for j : Integer.subrange(0, i-1) do ( if (r[j+1]->compareTo(r[i+1])) < 0 then ( table[i+1] := Set{table[i+1], table[j+1] + 1}->max() ) else skip)) ; execute ((table)->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] while True : n=I() if n==0 : break a=[len(S())for _ in range(n)] def f(i): t=[5,7,5,7,7] ti=0 for c in a[i :]: if c>t[ti]: return False if t[ti]==c : ti+=1 if ti==5 : return True else : t[ti]-=c return False r=0 for i in range(n): if f(i): r=i+1 break rr.append(r) return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var n : OclAny := I() ; if n = 0 then ( break ) else skip ; var a : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((S())->size())) ; skip ; var r : int := 0 ; for i : Integer.subrange(0, n-1) do ( if f(i) then ( r := i + 1 ; break ) else skip) ; execute ((r) : rr)) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans_list=[] def make_tanka(num,w_list,i): cnt=0 while cnttoInteger() ; if n = 0 then ( break ) else skip ; w_list := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : w_list)) ; var f1 : int := 0 ; var s1 : int := 0 ; var f2 : int := 0 ; var s2 : int := 0 ; var s3 : int := 0 ; i := 0 ; var ans : int := -1 ; while true do ( var j : OclAny := i ; Sequence{f1,j} := make_tanka(5, w_list, j) ; if f1 = 5 then ( Sequence{s1,j} := make_tanka(7, w_list, j) ; if s1 = 7 then ( Sequence{f2,j} := make_tanka(5, w_list, j) ; if f2 = 5 then ( Sequence{s2,j} := make_tanka(7, w_list, j) ; if s2 = 7 then ( Sequence{s3,j} := make_tanka(7, w_list, j) ; if s3 = 7 then ( ans := i ; break ) else skip ) else skip ; if ans /= -1 then ( break ) else skip ) else skip ; if ans /= -1 then ( break ) else skip ) else skip ; if ans /= -1 then ( break ) else skip ) else skip ; if ans /= -1 then ( break ) else skip ; i := i + 1) ; execute ((ans + 1) : ans_list)) ; for i : ans_list do ( execute (i)->display()); operation make_tanka(num : OclAny, w_list : OclAny, i : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; while (cnt->compareTo(num)) < 0 do ( cnt := cnt + (w_list[i+1])->size() ; i := i + 1) ; return Sequence{cnt}->union(Sequence{ i }); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) if n==0 : return False ok=[5,7,5,7,7] inputs=[input()for x in range(n)] for i in range(n): target=0 cnt=i for v in ok : while targettoInteger() ; if n = 0 then ( return false ) else skip ; var ok : Sequence := Sequence{5}->union(Sequence{7}->union(Sequence{5}->union(Sequence{7}->union(Sequence{ 7 })))) ; var inputs : Sequence := Integer.subrange(0, n-1)->select(x | true)->collect(x | ((OclFile["System.in"]).readLine())) ; for i : Integer.subrange(0, n-1) do ( var target : int := 0 ; var cnt : OclAny := i ; (compound_stmt for (exprlist (expr (atom (name v)))) in (testlist (test (logical_test (comparison (expr (atom (name ok))))))) : (suite (stmt (compound_stmt while (test (logical_test (comparison (comparison (expr (atom (name target)))) < (comparison (expr (atom (name v))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name inputs)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name cnt)))))))) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name target)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cnt)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name target)))) != (comparison (expr (atom (name v))))))) : (suite (stmt (simple_stmt (small_stmt break)))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name target)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name True)))))))))))))) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findPrefixCount(p_arr,arr): for i in range(0,n): for j in range(n-1,-1,-1): if arr[i][j]: continue if j!=n-1 : p_arr[i][j]+=p_arr[i][j+1] p_arr[i][j]+=int(not arr[i][j]) def matrixOrValueOne(arr): p_arr=[[0 for i in range(n)]for j in range(n)] findPrefixCount(p_arr,arr) count_zero_submatrices=0 for j in range(0,n): i=n-1 q=[] to_sum=0 while i>=0 : c=0 while(len(q)!=0 and q[-1][0]>p_arr[i][j]): to_sum-=((q[-1][1]+1)*(q[-1][0]-p_arr[i][j])) c+=q.pop()[1]+1 to_sum+=p_arr[i][j] count_zero_submatrices+=to_sum q.append((p_arr[i][j],c)) i-=1 return((n*(n+1)*n*(n+1))//4-count_zero_submatrices) if __name__=="__main__" : n=3 arr=[[0,0,0],[0,1,0],[0,0,0]] print(matrixOrValueOne(arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var n : int := 3 ; arr := Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{ 0 }))}->union(Sequence{ Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) })) ; execute (matrixOrValueOne(arr))->display() ) else skip; operation findPrefixCount(p_arr : OclAny, arr : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if arr[i+1][j+1] then ( continue ) else skip ; if j /= n - 1 then ( p_arr[i+1][j+1] := p_arr[i+1][j+1] + p_arr[i+1][j + 1+1] ) else skip ; p_arr[i+1][j+1] := p_arr[i+1][j+1] + ("" + ((not(arr[i+1][j+1]))))->toInteger())); operation matrixOrValueOne(arr : OclAny) : OclAny pre: true post: true activity: p_arr := Integer.subrange(0, n-1)->select(j | true)->collect(j | (Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)))) ; findPrefixCount(p_arr, arr) ; var count_zero_submatrices : int := 0 ; for j : Integer.subrange(0, n-1) do ( var i : double := n - 1 ; var q : Sequence := Sequence{} ; var to_sum : int := 0 ; while i >= 0 do ( var c : int := 0 ; while ((q)->size() /= 0 & (q->last()->first()->compareTo(p_arr[i+1][j+1])) > 0) do ( to_sum := to_sum - ((q->last()[1+1] + 1) * (q->last()->first() - p_arr[i+1][j+1])) ; c := c + q->last()[1+1] + 1) ; to_sum := to_sum + p_arr[i+1][j+1] ; count_zero_submatrices := count_zero_submatrices + to_sum ; execute ((Sequence{p_arr[i+1][j+1], c}) : q) ; i := i - 1)) ; return ((n * (n + 1) * n * (n + 1)) div 4 - count_zero_submatrices); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin from bisect import bisect_right,bisect_left input=stdin.readline def main(args): hammings=[] temp=set() for i in range(21): for j in range(14): for k in range(9): ans=2**i*3**j*5**k temp.add(ans) hammings=list(temp) hammings.sort() while True : try : m,n=map(int,input().split(' ')) except ValueError : break s=bisect_left(hammings,m) t=bisect_right(hammings,n) print(t-s) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := stdin.readline ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation main(args : OclAny) pre: true post: true activity: var hammings : Sequence := Sequence{} ; var temp : Set := Set{}->union(()) ; for i : Integer.subrange(0, 21-1) do ( for j : Integer.subrange(0, 14-1) do ( for k : Integer.subrange(0, 9-1) do ( var ans : double := (2)->pow(i) * (3)->pow(j) * (5)->pow(k) ; execute ((ans) : temp)))) ; hammings := (temp) ; hammings := hammings->sort() ; while true do ( try ( var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) (except_clause except (test (logical_test (comparison (expr (atom (name ValueError)))))) : (suite (stmt (simple_stmt (small_stmt break))))) ; var s : OclAny := bisect_left(hammings, m) ; var t : OclAny := bisect_right(hammings, n) ; execute (t - s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : datas=list(map(int,input().split())) if datas[0]==0 : break n,m=datas[0],datas[1] cnt=0 for i in range(n,m+1): b=i while b % 5==0 : b//=5 while b % 3==0 : b//=3 while b % 2==0 : b//=2 if b==1 : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var datas : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if datas->first() = 0 then ( break ) else skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{datas->first(),datas[1+1]} ; var cnt : int := 0 ; for i : Integer.subrange(n, m + 1-1) do ( var b : OclAny := i ; while b mod 5 = 0 do ( b := b div 5) ; while b mod 3 = 0 do ( b := b div 3) ; while b mod 2 = 0 do ( b := b div 2) ; if b = 1 then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy from test.support import _MemoryWatchdog BIG_NUM=2000000000 HUGE_NUM=99999999999999999 MOD=1000000007 EPS=0.000000001 sys.setrecursionlimit(100000) SIZE_2=20 SIZE_3=13 SIZE_5=9 NUM=1000001 POW_2=[1]*SIZE_2 for i in range(1,SIZE_2): POW_2[i]=POW_2[i-1]*2 POW_3=[1]*SIZE_3 for i in range(1,SIZE_3): POW_3[i]=POW_3[i-1]*3 POW_5=[1]*SIZE_5 for i in range(1,SIZE_5): POW_5[i]=POW_5[i-1]*5 table=[0]*(NUM) for i in range(SIZE_2): for k in range(SIZE_3): if POW_2[i]*POW_3[k]>=NUM : break for p in range(SIZE_5): if POW_2[i]*POW_3[k]*POW_5[p]>=NUM : break table[POW_2[i]*POW_3[k]*POW_5[p]]=1 for i in range(1,NUM): table[i]+=table[i-1] while True : tmp_str=input() if len(tmp_str)==1 and tmp_str[0]=="0" : break left,right=map(int,tmp_str.split()) print("%d" %(table[right]-table[left-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var HUGE_NUM : int := 99999999999999999 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; sys.setrecursionlimit(100000) ; var SIZE:= 20 : int := 20 ; var SIZE_3 : int := 13 ; var SIZE_5 : int := 9 ; var NUM : int := 1000001 ; var POW:= MatrixLib.elementwiseMult(Sequence{ 1 }, SIZE_2) : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, SIZE_2) ; for i : Integer.subrange(1, SIZE_2-1) do ( POW:= POW2[i - 1+1] * 2[i+1] := POW2[i - 1+1] * 2) ; var POW_3 : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, SIZE_3) ; for i : Integer.subrange(1, SIZE POW_3[i+1] := POW_3[i - 1+1] * 3-1) do ( POW_3[i+1] := POW_3[i - 1+1] * 3) ; var POW_5 : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, SIZE_5) ; for i : Integer.subrange(1, SIZE_5-1) do ( POW_5[i+1] := POW_5[i - 1+1] * 5) ; var table : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (NUM)) ; for i : Integer.subrange(0, SIZE_2-1) do ( for k : Integer.subrange(0, SIZE if (POWPOW_3[k+1][i+1] * POW_3[k+1]->compareTo(NUM)) >= 0 then ( break ) else skip ; for p : Integer.subrange(0, SIZE_5-1) do ( if (POWPOW_3[k+1][i+1] * POW_3[k+1] * POW_5[p+1]->compareTo(NUM)) >= 0 then ( break ) else skip ; table[POWPOW_3[k+1][i+1] * POW_3[k+1] * POW_5[p+1]+1] := 1)-1) do ( if (POWPOW_3[k+1][i+1] * POW_3[k+1]->compareTo(NUM)) >= 0 then ( break ) else skip ; for p : Integer.subrange(0, SIZE_5-1) do ( if (POWPOW_3[k+1][i+1] * POW_3[k+1] * POW_5[p+1]->compareTo(NUM)) >= 0 then ( break ) else skip ; table[POWPOW_3[k+1][i+1] * POW_3[k+1] * POW_5[p+1]+1] := 1))) ; for i : Integer.subrange(1, NUM-1) do ( table[i+1] := table[i+1] + table[i - 1+1]) ; while true do ( var tmp_str : String := (OclFile["System.in"]).readLine() ; if (tmp_str)->size() = 1 & tmp_str->first() = "0" then ( break ) else skip ; var left : OclAny := null; var right : OclAny := null; Sequence{left,right} := (tmp_str.split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (StringLib.format("%d",(table[right+1] - table[left - 1+1])))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000000 hamming_list=[False]*(MAX+1) hamming_list[0]=False hamming_list[1]=True for index in range(2,MAX+1): if index/2 % 1==0 : if hamming_list[index//2]: hamming_list[index]=True elif index/3 % 1==0 : if hamming_list[index//3]: hamming_list[index]=True elif index/5 % 1==0 : if hamming_list[index//5]: hamming_list[index]=True while True : input_data=input() if input_data=="0" : break start,end=[int(item)for item in input_data.split(" ")] count=sum(hamming_list[start : end+1]) print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1000000 ; var hamming_list : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (MAX + 1)) ; hamming_list->first() := false ; hamming_list[1+1] := true ; for index : Integer.subrange(2, MAX + 1-1) do ( if index / 2 mod 1 = 0 then ( if hamming_list[index div 2+1] then ( hamming_list[index+1] := true ) else skip ) else (if index / 3 mod 1 = 0 then ( if hamming_list[index div 3+1] then ( hamming_list[index+1] := true ) else skip ) else (if index / 5 mod 1 = 0 then ( if hamming_list[index div 5+1] then ( hamming_list[index+1] := true ) else skip ) else skip ) ) ) ; while true do ( var input_data : String := (OclFile["System.in"]).readLine() ; if input_data = "0" then ( break ) else skip ; var start : OclAny := null; var end : OclAny := null; Sequence{start,end} := input_data.split(" ")->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; var count : OclAny := (hamming_list.subrange(start+1, end + 1))->sum() ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque import itertools N=int(input()) P=tuple(map(int,input().split())) Q=tuple(map(int,input().split())) l=[] for i in range(1,N+1): l.append(i) D=deque(itertools.permutations(l)) a=0 b=0 count=0 for d in D : count+=1 if d==P : a=count if d==Q : b=count if a-b<0 : print(b-a) else : print(a-b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var P : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var Q : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : Sequence := Sequence{} ; for i : Integer.subrange(1, N + 1-1) do ( execute ((i) : l)) ; var D : Sequence := (itertools.permutations(l)) ; var a : int := 0 ; var b : int := 0 ; var count : int := 0 ; for d : D do ( count := count + 1 ; if d = P then ( a := count ) else skip ; if d = Q then ( b := count ) else skip) ; if a - b < 0 then ( execute (b - a)->display() ) else ( execute (a - b)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- isHamming=[] def judge(): global isHamming ; isHamming[1]=True i=1 while True : if(i*2>1000000): break if(isHamming[i]): isHamming[i*2]=True i+=1 i=1 while True : if(i*3>1000000): break if(isHamming[i]): isHamming[i*3]=True i+=1 i=1 while True : if(i*5>1000000): break if(isHamming[i]): isHamming[i*5]=True i+=1 def init(): global isHamming for i in range(1000000+1): isHamming.append(False) init() judge() while True : m=[int(num)for num in input().split()] if m==[0]: break ; count=0 for i in range(m[0],m[1]+1): if(isHamming[i]): count+=1 ; print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute isHamming : OclAny; operation initialise() pre: true post: true activity: var isHamming : Sequence := Sequence{} ; skip ; skip ; init() ; judge() ; while true do ( var m : Sequence := input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; if m = Sequence{ 0 } then ( break; ) else skip ; var count : int := 0 ; for i : Integer.subrange(m->first(), m[1+1] + 1-1) do ( if (isHamming[i+1]) then ( count := count + 1; ) else skip) ; execute (count)->display()); operation judge() pre: true post: true activity: skip; ; isHamming[1+1] := true ; var i : int := 1 ; while true do ( if (i * 2 > 1000000) then ( break ) else skip ; if (isHamming[i+1]) then ( isHamming[i * 2+1] := true ) else skip ; i := i + 1) ; i := 1 ; while true do ( if (i * 3 > 1000000) then ( break ) else skip ; if (isHamming[i+1]) then ( isHamming[i * 3+1] := true ) else skip ; i := i + 1) ; i := 1 ; while true do ( if (i * 5 > 1000000) then ( break ) else skip ; if (isHamming[i+1]) then ( isHamming[i * 5+1] := true ) else skip ; i := i + 1); operation init() pre: true post: true activity: skip ; for i : Integer.subrange(0, 1000000 + 1-1) do ( execute ((false) : isHamming)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _=input() S=set(input().split()) _=input() T=set(input().split()) print(len(S & T)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _anon : String := (OclFile["System.in"]).readLine() ; var S : Set := Set{}->union((input().split())) ; _anon := (OclFile["System.in"]).readLine() ; var T : Set := Set{}->union((input().split())) ; execute ((MathLib.bitwiseAnd(S, T))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : N=int(input()) if not N : break S=[] for i in range(N): h,r=map(int,input().split()) S.append((h,r)) M=int(input()) for i in range(M): h,r=map(int,input().split()) S.append((h,r)) S.sort() memo=[-1]*(N+M) def dfs(i): if memo[i]!=-1 : return memo[i] hi,ri=S[i] r=0 for j in range(i+1,N+M): hj,rj=S[j] if hitoInteger() ; if not(N) then ( break ) else skip ; var S : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var h : OclAny := null; var r : OclAny := null; Sequence{h,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{h, r}) : S)) ; var M : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, M-1) do ( var h : OclAny := null; var r : OclAny := null; Sequence{h,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{h, r}) : S)) ; S := S->sort() ; var memo : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (N + M)) ; skip ; execute (dfs(0))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binary(first,last,find): mid=first+(last-first)//2 if first==last : if Sset[first]==find : return True else : return False else : if find<=Sset[mid]: return binary(first,mid,find) else : return binary(mid+1,last,find) Snum=int(input()) global Sset Sset=[int(n)for n in input().split(' ')] Sset.sort() Tnum=int(input()) Tset=[int(n)for n in input().split(' ')] ans=0 for t in range(Tnum): ans+=binary(0,Snum-1,Tset[t]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute Sset : OclAny; operation initialise() pre: true post: true activity: skip ; var Snum : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; Sset := input().split(' ')->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; Sset := Sset->sort() ; var Tnum : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var Tset : Sequence := input().split(' ')->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; var ans : int := 0 ; for t : Integer.subrange(0, Tnum-1) do ( ans := ans + binary(0, Snum - 1, Tset[t+1])) ; execute (ans)->display(); operation binary(first : OclAny, last : OclAny, find : OclAny) : OclAny pre: true post: true activity: var mid : OclAny := first + (last - first) div 2 ; if first = last then ( if Sset[first+1] = find then ( return true ) else ( return false ) ) else ( if (find->compareTo(Sset[mid+1])) <= 0 then ( return binary(first, mid, find) ) else ( return binary(mid + 1, last, find) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sets import Set n=input() S=Set(map(int,raw_input().split())) ans=0 q=input() T=map(int,raw_input().split()) for i in range(len(T)): if(T[i]in S): ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : String := (OclFile["System.in"]).readLine() ; var S : OclAny := Set((raw_input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; var q : String := (OclFile["System.in"]).readLine() ; var T : Sequence := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, (T)->size()-1) do ( if ((S)->includes(T[i+1])) then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def search(l,r): counter=0 ; j=0 i=0 while jl[i]: i+=1 elif r[j]==l[i]: counter+=1 break elif r[j]collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) )) ; input() ; var list2 : Sequence := ((input().split(' '))->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) )) ; list1 := list1->sort() ; var ans : OclAny := search(list1, list2) ; execute (ans)->display(); operation search(l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var counter : int := 0; ; var j : int := 0 ; var i : int := 0 ; while (j->compareTo((r)->size())) < 0 do ( while (i->compareTo((l)->size())) < 0 do ( if (r[j+1]->compareTo(l[i+1])) > 0 then ( i := i + 1 ) else (if r[j+1] = l[i+1] then ( counter := counter + 1 ; break ) else (if (r[j+1]->compareTo(l[i+1])) < 0 then ( break ) else skip ) ) ) ; j := j + 1) ; return counter; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter input() s=set(map(int,input().split())) input() print(Counter(n in s for n in map(int,input().split()))[True]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; input() ; var s : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; input() ; execute (Counter((argument (test (logical_test (comparison (comparison (expr (atom (name n)))) in (comparison (expr (atom (name s))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))))))->select(true))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) ans=[] for i in l : mn=10**9 mn=min(mn,32768-i) if i % 32768==0 : mn=0 q=0 cnt=-1 i-=1 while q<=15 : i+=1 cnt+=1 q+=1 p=1 temp=i c=0 while p<=15 : temp*=2 p+=1 c+=1 if temp % 32768==0 : mn=min(mn,cnt+c) break ans.append(mn) print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : Sequence := Sequence{} ; for i : l do ( var mn : double := (10)->pow(9) ; mn := Set{mn, 32768 - i}->min() ; if i mod 32768 = 0 then ( mn := 0 ) else skip ; var q : int := 0 ; var cnt : int := -1 ; i := i - 1 ; while q <= 15 do ( i := i + 1 ; cnt := cnt + 1 ; q := q + 1 ; var p : int := 1 ; var temp : OclAny := i ; var c : int := 0 ; while p <= 15 do ( temp := temp * 2 ; p := p + 1 ; c := c + 1 ; if temp mod 32768 = 0 then ( mn := Set{mn, cnt + c}->min() ; break ) else skip)) ; execute ((mn) : ans)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(input()) l=[int(x)for x in input().split()] def check(n): z=n ans=0 while(n % 2==0): ans+=1 n//=2 return 15-ans if ans<=15 else 0 for no in l : if no==0 : print(0) continue ans=sys.maxsize x=no for j in range(16): ans=min(ans,j+check(x+j)+(1 if no==0 else 0)) print(ans,end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; skip ; for no : l do ( if no = 0 then ( execute (0)->display() ; continue ) else skip ; ans := (trailer . (name maxsize)) ; var x : OclAny := no ; for j : Integer.subrange(0, 16-1) do ( ans := Set{ans, j + check(x + j) + (if no = 0 then 1 else 0 endif)}->min()) ; execute (ans)->display()) ; execute (->display(); operation check(n : OclAny) : OclAny pre: true post: true activity: var z : int := n ; var ans : int := 0 ; while (n mod 2 = 0) do ( ans := ans + 1 ; n := n div 2) ; return if ans <= 15 then 15 - ans else 0 endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def solution(n,a): d={} for e in a : ans=20 if d.get(e,-1)==-1 : for cntAdd in range(15): for cntMul in range(15): if ans<=(cntAdd+cntMul): break if(cntAdd+e)*math.pow(2,cntMul)% 32768==0 : ans=(cntAdd+cntMul) print(ans,end=" ") d[e]=ans else : print(d[e],end=" ") n=int(input()) a=[int(x)for x in input().strip().split(" ")] solution(n,a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := input()->trim().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; solution(n, a); operation solution(n : OclAny, a : OclAny) pre: true post: true activity: var d : OclAny := Set{} ; for e : a do ( var ans : int := 20 ; if d.get(e, -1) = -1 then ( for cntAdd : Integer.subrange(0, 15-1) do ( for cntMul : Integer.subrange(0, 15-1) do ( if (ans->compareTo((cntAdd + cntMul))) <= 0 then ( break ) else skip ; if (cntAdd + e) * (2)->pow(cntMul) mod 32768 = 0 then ( ans := (cntAdd + cntMul) ) else skip)) ; execute (ans)->display() ; d[e+1] := ans ) else ( execute (d[e+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def substract(a,b): if a>b : total=0 while a>0 and b>0 : total+=int(a/b) a=a % b if a>0 : total+=int(b/a) b=b % a return total if a0 and b>0 : total+=int(b/a) b=b % a if b>0 : total+=int(a/b) a=a % b return total if a==b : return 1 n=int(input()) lst=[] for i in range(0,n): a,b=map(int,input().split()) lst.append(substract(a,b)) for i in lst : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((substract(a, b)) : lst)) ; for i : lst do ( execute (i)->display()); operation substract(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a->compareTo(b)) > 0 then ( var total : int := 0 ; while a > 0 & b > 0 do ( total := total + ("" + ((a / b)))->toInteger() ; a := a mod b ; if a > 0 then ( total := total + ("" + ((b / a)))->toInteger() ; b := b mod a ) else skip) ; return total ) else skip ; if (a->compareTo(b)) < 0 then ( total := 0 ; while a > 0 & b > 0 do ( total := total + ("" + ((b / a)))->toInteger() ; b := b mod a ; if b > 0 then ( total := total + ("" + ((a / b)))->toInteger() ; a := a mod b ) else skip) ; return total ) else skip ; if a = b then ( return 1 ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy import math import time import statistics import math import itertools def get_int(): return int(input()) def get_string(): return input() def get_int_list(): return[int(x)for x in input().split()] def get_string_list(): return input().split() def get_int_multi(): return map(int,input().split()) def get_string_char_list(): return list(str(input())) def main(): start=time.time() n=get_int() p=get_int_list() q=get_int_list() a=[] for i in range(1,n+1): a.append(i) count=0 count_p=0 count_q=0 for keiro in list(itertools.permutations(a)): if list(keiro)==p : count_p=count if list(keiro)==q : count_q=count count+=1 print(abs(count_p-count_q)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation get_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation get_string() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation get_int_list() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation get_string_list() : OclAny pre: true post: true activity: return input().split(); operation get_int_multi() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation get_string_char_list() : OclAny pre: true post: true activity: return (("" + (((OclFile["System.in"]).readLine()))))->characters(); operation main() pre: true post: true activity: var start : OclAny := time.time() ; var n : OclAny := get_int() ; var p : OclAny := get_int_list() ; var q : OclAny := get_int_list() ; var a : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( execute ((i) : a)) ; var count : int := 0 ; var count_p : int := 0 ; var count_q : int := 0 ; for keiro : (itertools.permutations(a)) do ( if (keiro) = p then ( count_p := count ) else skip ; if (keiro) = q then ( count_q := count ) else skip ; count := count + 1) ; execute ((count_p - count_q)->abs())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque,Counter from math import* import sys import random from bisect import* from functools import reduce from sys import stdin from heapq import* import copy input=lambda : sys.stdin.readline().rstrip() m=1<<15 def ff(i): ans=0 m=1<<15 while i % m!=0 : i=(i*2)% m ans+=1 return ans n=int(input()) arr=list(map(int,input().split())) ff=[ff(i)for i in range(m+1)] az=[] for i in arr : ans=ff[i] for j in range(16): ans=min(ans,ff[min(i+j,m)]+min(j,m)) az.append(ans) print(*az) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var m : int := 1 * (2->pow(15)) ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ff : Sequence := Integer.subrange(0, m + 1-1)->select(i | true)->collect(i | (ff(i))) ; var az : Sequence := Sequence{} ; for i : arr do ( ans := ff[i+1] ; for j : Integer.subrange(0, 16-1) do ( ans := Set{ans, ff[Set{i + j, m}->min()+1] + Set{j, m}->min()}->min()) ; execute ((ans) : az)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name az))))))))->display(); operation ff(i : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; m := 1 * (2->pow(15)) ; while i mod m /= 0 do ( i := (i * 2) mod m ; ans := ans + 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) for i in reversed(range(n)): print(a[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : (Integer.subrange(0, n-1))->reverse() do ( execute (a[i+1])->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) for i in reversed(range(n)): print(a[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : (Integer.subrange(0, n-1))->reverse() do ( execute (a[i+1])->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if n==0 : break objects=[] for i in range(n): h,r=(int(x)for x in input().split()) objects.append((h,r)) n=int(input()) for i in range(n): h,r=(int(x)for x in input().split()) objects.append((h,r)) objects=sorted(objects,key=lambda w :(w[0],-1*w[1])) r=[i[1]for i in objects] t=[1]*len(r) for i in range(len(r)): for j in range(i): if r[j]toInteger() ; if n = 0 then ( break ) else skip ; var objects : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var h : OclAny := null; var r : OclAny := null; Sequence{h,r} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; execute ((Sequence{h, r}) : objects)) ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var h : OclAny := null; var r : OclAny := null; Sequence{h,r} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; execute ((Sequence{h, r}) : objects)) ; objects := objects->sortedBy($x | (lambda w : OclAny in (Sequence{w->first(), -1 * w[1+1]}))->apply($x)) ; var r : Sequence := objects->select(i | true)->collect(i | (i[1+1])) ; var t : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (r)->size()) ; for i : Integer.subrange(0, (r)->size()-1) do ( for j : Integer.subrange(0, i-1) do ( if (r[j+1]->compareTo(r[i+1])) < 0 then ( t[i+1] := Set{t[i+1], t[j+1] + 1}->max() ) else skip)) ; execute ((t)->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): input() print(' '.join(input().split()[: :-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( input() ; execute (StringLib.sumStringsWithSeparator((input().split()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: print(*s.split()[: :-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name s)) (trailer . (name split) (arguments ( ))) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ]))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) a=[int(i)for i in input().split()][: :-1] return " ".join([str(i)for i in a]) t=int(input()) ans=[] while t : ans.append(str(solve())) t-=1 print("\n".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; while t do ( execute ((("" + ((solve())))) : ans) ; t := t - 1) ; execute (StringLib.sumStringsWithSeparator((ans), "\n"))->display(); operation solve() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; return StringLib.sumStringsWithSeparator((a->select(i | true)->collect(i | (("" + ((i)))))), " "); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def factorial(n): if n==0 : return 1 return n*factorial(n-1) num=5 ; print("Factorial of",num,"is",factorial(num)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var num : int := 5; ; execute ("Factorial of")->display(); operation factorial(n : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( return 1 ) else skip ; return n * factorial(n - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printMaxSum(arr,n): dp=[0 for i in range(n)] for i in range(n): dp[i]=arr[i] maxi=0 for j in range(1,int((i+1)**0.5)+1): if((i+1)% j==0 and(i+1)!=j): if(dp[j-1]>maxi): maxi=dp[j-1] if(dp[(i+1)//j-1]>maxi and j!=1): maxi=dp[(i+1)//j-1] dp[i]+=maxi for i in range(n): print(dp[i],end=' ') arr=[2,3,1,4,6,5] n=len(arr) printMaxSum(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{3}->union(Sequence{1}->union(Sequence{4}->union(Sequence{6}->union(Sequence{ 5 }))))) ; n := (arr)->size() ; printMaxSum(arr, n); operation printMaxSum(arr : OclAny, n : OclAny) pre: true post: true activity: var dp : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( dp[i+1] := arr[i+1] ; var maxi : int := 0 ; for j : Integer.subrange(1, ("" + ((((i + 1))->pow(0.5))))->toInteger() + 1-1) do ( if ((i + 1) mod j = 0 & (i + 1) /= j) then ( if ((dp[j - 1+1]->compareTo(maxi)) > 0) then ( maxi := dp[j - 1+1] ) else skip ; if ((dp[(i + 1) div j - 1+1]->compareTo(maxi)) > 0 & j /= 1) then ( maxi := dp[(i + 1) div j - 1+1] ) else skip ) else skip) ; dp[i+1] := dp[i+1] + maxi) ; for i : Integer.subrange(0, n-1) do ( execute (dp[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict MAX=1000000 ROOT=1000 MOD=1000000007 is_prime=[True]*(MAX+1) is_prime[0]=is_prime[1]=False for i in range(2,ROOT+1): if is_prime[i]: for j in range(i*i,MAX+1,i): is_prime[j]=False n=int(input()) qlst=list(map(int,input().split())) total1=0 total2=1 last_prime=0 dic={} dic[(last_prime,0)]=total1 dic[(last_prime,1)]=total2 for q in qlst : new_dic=defaultdict(int) for k,v in dic.items(): last_prime,t=k if is_prime[q]: if t==0 : if last_primefirst() := false; var is_prime[1+1] : boolean := false ; for i : Integer.subrange(2, ROOT + 1-1) do ( if is_prime[i+1] then ( for j : Integer.subrange(i * i, MAX + 1-1)->select( $x | ($x - i * i) mod i = 0 ) do ( is_prime[j+1] := false) ) else skip) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var qlst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var total1 : int := 0 ; var total2 : int := 1 ; var last_prime : int := 0 ; var dic : OclAny := Set{} ; dic[Sequence{last_prime, 0}+1] := total1 ; dic[Sequence{last_prime, 1}+1] := total2 ; for q : qlst do ( var new_dic : OclAny := defaultdict(OclType["int"]) ; for _tuple : dic->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); var t : OclAny := null; Sequence{last_prime,t} := k ; if is_prime[q+1] then ( if t = 0 then ( if (last_prime->compareTo(q)) < 0 then ( new_dic[Sequence{q, 0}+1] := (new_dic[Sequence{q, 0}+1] + v) mod MOD ; new_dic[Sequence{last_prime, 1}+1] := (new_dic[Sequence{last_prime, 1}+1] + v) mod MOD ) else ( new_dic[Sequence{last_prime, 1}+1] := (new_dic[Sequence{last_prime, 1}+1] + v) mod MOD ) ) else ( if (last_prime->compareTo(q)) < 0 then ( new_dic[Sequence{q, 0}+1] := (new_dic[Sequence{q, 0}+1] + v) mod MOD ) else skip ) ) else skip ; if not(is_prime[q+1]) then ( if t = 0 then ( new_dic[Sequence{last_prime, 1}+1] := (new_dic[Sequence{last_prime, 1}+1] + v) mod MOD ) else skip ) else skip) ; dic := new_dic) ; execute ((dic.values())->sum() mod MOD)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=[[0,1],[1,0],[0,-1],[-1,0]] b=[[0,-1],[-1,0],[0,1],[1,0]] while True : w,h=map(int,input().split()) if w==0 : break r,c,d=1,1,0 while True : buf=input().split() if buf[0]=="STOP" : break elif buf[0]=="RIGHT" : d=(d+1)% 4 elif buf[0]=="LEFT" : d=(d+3)% 4 else : if buf[0]=="FORWARD" : r2=r+int(buf[1])*f[d][1] c2=c+int(buf[1])*f[d][0] else : r2=r+int(buf[1])*b[d][1] c2=c+int(buf[1])*b[d][0] if r2<1 : r2=1 if r2>h : r2=h if c2<1 : c2=1 if c2>w : c2=w r,c=r2,c2 print(c,r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : Sequence := Sequence{Sequence{0}->union(Sequence{ 1 })}->union(Sequence{Sequence{1}->union(Sequence{ 0 })}->union(Sequence{Sequence{0}->union(Sequence{ -1 })}->union(Sequence{ Sequence{-1}->union(Sequence{ 0 }) }))) ; var b : Sequence := Sequence{Sequence{0}->union(Sequence{ -1 })}->union(Sequence{Sequence{-1}->union(Sequence{ 0 })}->union(Sequence{Sequence{0}->union(Sequence{ 1 })}->union(Sequence{ Sequence{1}->union(Sequence{ 0 }) }))) ; while true do ( var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if w = 0 then ( break ) else skip ; var r : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{r,c,d} := Sequence{1,1,0} ; while true do ( var buf : OclAny := input().split() ; if buf->first() = "STOP" then ( break ) else (if buf->first() = "RIGHT" then ( var d : int := (d + 1) mod 4 ) else (if buf->first() = "LEFT" then ( d := (d + 3) mod 4 ) else ( if buf->first() = "FORWARD" then ( var r2 : OclAny := r + ("" + ((buf[1+1])))->toInteger() * f[d+1][1+1] ; var c2 : OclAny := c + ("" + ((buf[1+1])))->toInteger() * f[d+1]->first() ) else ( r2 := r + ("" + ((buf[1+1])))->toInteger() * b[d+1][1+1] ; c2 := c + ("" + ((buf[1+1])))->toInteger() * b[d+1]->first() ) ; if r2 < 1 then ( r2 := 1 ) else skip ; if (r2->compareTo(h)) > 0 then ( r2 := h ) else skip ; if c2 < 1 then ( c2 := 1 ) else skip ; if (c2->compareTo(w)) > 0 then ( c2 := w ) else skip ; var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := Sequence{r2,c2} ) ) ) ) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math MAX=100 ; def Cholesky_Decomposition(matrix,n): lower=[[0 for x in range(n+1)]for y in range(n+1)]; for i in range(n): for j in range(i+1): sum1=0 ; if(j==i): for k in range(j): sum1+=pow(lower[j][k],2); lower[j][j]=int(math.sqrt(matrix[j][j]-sum1)); else : for k in range(j): sum1+=(lower[i][k]*lower[j][k]); if(lower[j][j]>0): lower[i][j]=int((matrix[i][j]-sum1)/lower[j][j]); print("Lower Triangular\t\tTranspose"); for i in range(n): for j in range(n): print(lower[i][j],end="\t"); print("",end="\t"); for j in range(n): print(lower[j][i],end="\t"); print(""); n=3 ; matrix=[[4,12,-16],[12,37,-43],[-16,-43,98]]; Cholesky_Decomposition(matrix,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MAX : int := 100; ; skip ; n := 3; ; matrix := Sequence{Sequence{4}->union(Sequence{12}->union(Sequence{ -16 }))}->union(Sequence{Sequence{12}->union(Sequence{37}->union(Sequence{ -43 }))}->union(Sequence{ Sequence{-16}->union(Sequence{-43}->union(Sequence{ 98 })) })); ; Cholesky_Decomposition(matrix, n);; operation Cholesky_Decomposition(matrix : OclAny, n : OclAny) pre: true post: true activity: var lower : Sequence := Integer.subrange(0, n + 1-1)->select(y | true)->collect(y | (Integer.subrange(0, n + 1-1)->select(x | true)->collect(x | (0)))); ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, i + 1-1) do ( var sum1 : int := 0; ; if (j = i) then ( for k : Integer.subrange(0, j-1) do ( sum1 := sum1 + (lower[j+1][k+1])->pow(2);) ; lower[j+1][j+1] := ("" + (((matrix[j+1][j+1] - sum1)->sqrt())))->toInteger(); ) else ( for k : Integer.subrange(0, j-1) do ( sum1 := sum1 + (lower[i+1][k+1] * lower[j+1][k+1]);) ; if (lower[j+1][j+1] > 0) then ( lower[i+1][j+1] := ("" + (((matrix[i+1][j+1] - sum1) / lower[j+1][j+1])))->toInteger(); ) else skip ))) ; execute ("Lower Triangular\t\tTranspose")->display(); ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( execute (lower[i+1][j+1])->display();) ; execute ("")->display(); ; for j : Integer.subrange(0, n-1) do ( execute (lower[j+1][i+1])->display();) ; execute ("")->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CheckSubarray(arr,N): presum=[0 for i in range(N+1)] for i in range(1,N+1): presum[i]=presum[i-1]+arr[i-1] moduloclass=[[]]*N for i in range(1,N+1,1): moduloclass[presum[i]% N].append(i-1) if(len(moduloclass[0])>0): print(0+1,moduloclass[0][0]+2) return for i in range(1,N): if(len(moduloclass[i])>=2): print(moduloclass[i][0]+1,moduloclass[i][1]) return if __name__=='__main__' : arr=[7,3,5,2] N=len(arr) CheckSubarray(arr,N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{7}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 2 }))) ; N := (arr)->size() ; CheckSubarray(arr, N) ) else skip; operation CheckSubarray(arr : OclAny, N : OclAny) pre: true post: true activity: var presum : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(1, N + 1-1) do ( presum[i+1] := presum[i - 1+1] + arr[i - 1+1]) ; var moduloclass : Sequence := MatrixLib.elementwiseMult(Sequence{ Sequence{} }, N) ; for i : Integer.subrange(1, N + 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do ((expr (atom (name moduloclass)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name presum)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) % (expr (atom (name N))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ))))) ; if ((moduloclass->first())->size() > 0) then ( execute (0 + 1)->display() ; return ) else skip ; for i : Integer.subrange(1, N-1) do ( if ((moduloclass[i+1])->size() >= 2) then ( execute (moduloclass[i+1]->first() + 1)->display() ; return ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) b=[] a=[] numbers=0 for i in range(2,n+1): b.append(i) for i in range(2,n+1): for t in range(2,i-1): if i % t==0 : b.remove(i) break for i in range(0,len(b)-1): if b[i]+b[i+1]<=b[-1]: m=b[i]+b[i+1]+1 a.append(m) for i in range(2,m-1): if m % i==0 : numbers+=1 break if(len(a))-numbers>=k : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : Sequence := Sequence{} ; var a : Sequence := Sequence{} ; var numbers : int := 0 ; for i : Integer.subrange(2, n + 1-1) do ( execute ((i) : b)) ; for i : Integer.subrange(2, n + 1-1) do ( for t : Integer.subrange(2, i - 1-1) do ( if i mod t = 0 then ( execute ((i) /: b) ; break ) else skip)) ; for i : Integer.subrange(0, (b)->size() - 1-1) do ( if (b[i+1] + b[i + 1+1]->compareTo(b->last())) <= 0 then ( var m : OclAny := b[i+1] + b[i + 1+1] + 1 ; execute ((m) : a) ; for i : Integer.subrange(2, m - 1-1) do ( if m mod i = 0 then ( numbers := numbers + 1 ; break ) else skip) ) else skip) ; if (((a)->size()) - numbers->compareTo(k)) >= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lim,c=map(int,input().split()) p=[True for i in range(1005)] arr=[] for i in range(2,lim): if p[i]: arr.append(i) for j in range(2*i,1005,i): p[j]=False for i in range(len(arr)-1): j=i+1 try : if(p[arr[i]+arr[j]+1])and(arr[i]+arr[j]+1<=lim): p[arr[i]+arr[j]+1]=False c-=1 except : pass if c<=0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lim : OclAny := null; var c : OclAny := null; Sequence{lim,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : Sequence := Integer.subrange(0, 1005-1)->select(i | true)->collect(i | (true)) ; var arr : Sequence := Sequence{} ; for i : Integer.subrange(2, lim-1) do ( if p[i+1] then ( execute ((i) : arr) ; for j : Integer.subrange(2 * i, 1005-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ( p[j+1] := false) ) else skip) ; for i : Integer.subrange(0, (arr)->size() - 1-1) do ( var j : OclAny := i + 1 ; try ( if (p[arr[i+1] + arr[j+1] + 1+1]) & ((arr[i+1] + arr[j+1] + 1->compareTo(lim)) <= 0) then ( p[arr[i+1] + arr[j+1] + 1+1] := false ; c := c - 1 ) else skip) catch (_e : OclException) do ( skip) ) ; if c <= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=1000000007 ; def modInv(a,p=MOD-2): s=1 ; while(p!=1): if(p % 2): s=(s*a)% MOD ; a=(a*a)% MOD ; p//=2 ; return(a*s)% MOD ; def findCnt(x,y): ans=0 ; fact=[1]*(len(y)+1); for i in range(1,len(y)): fact[i]=(fact[i-1]*i)% MOD ; for i in range(len(y)): if(y[i]==x): ans+=(modInv(fact[i])*modInv(fact[len(y)-i-1]))% MOD ; ans %=MOD ; ans*=fact[(len(y)-1)]; ans %=MOD ; return ans ; if __name__=="__main__" : x='a' ; y="xxayy" ; print(findCnt(x,y)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : int := 1000000007; ; skip ; skip ; if __name__ = "__main__" then ( x := 'a'; ; y := "xxayy"; ; execute (findCnt(x, y))->display(); ) else skip; operation modInv(a : OclAny, p : OclAny) pre: true post: true activity: if p->oclIsUndefined() then p := MOD - 2 else skip; var s : int := 1; ; while (p /= 1) do ( if (p mod 2) then ( s := (s * a) mod MOD; ) else skip ; a := (a * a) mod MOD; ; p := p div 2;) ; return (a * s) mod MOD;; operation findCnt(x : OclAny, y : OclAny) pre: true post: true activity: var ans : int := 0; ; var fact : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, ((y)->size() + 1)); ; for i : Integer.subrange(1, (y)->size()-1) do ( fact[i+1] := (fact[i - 1+1] * i) mod MOD;) ; for i : Integer.subrange(0, (y)->size()-1) do ( if (y[i+1] = x) then ( ans := ans + (modInv(fact[i+1]) * modInv(fact[(y)->size() - i - 1+1])) mod MOD; ; ans := ans mod MOD; ) else skip) ; ans := ans * fact[((y)->size() - 1)+1]; ; ans := ans mod MOD; ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def SieveOfEratosthenes(n): l_prime=[] prime=[True for _ in range(n+1)] p=2 while p*p<=n : if prime[p]==True : for i in range(p*p,n+1,p): prime[i]=False p+=1 for p in range(2,n+1): if prime[p]: l_prime.append(p) return l_prime n,k=map(int,input().split()) l_prime=SieveOfEratosthenes(n) if k==0 : print('YES') else : len_l_prime=len(l_prime) if len_l_prime<6 : print('NO') else : count=0 for i in range(5,len_l_prime): for j in range(1,i): if l_prime[j-1]+l_prime[j]==l_prime[i]-1 : count+=1 if count==k : break if count==k : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; l_prime := SieveOfEratosthenes(n) ; if k = 0 then ( execute ('YES')->display() ) else ( var len_l_prime : int := (l_prime)->size() ; if len_l_prime < 6 then ( execute ('NO')->display() ) else ( var count : int := 0 ; for i : Integer.subrange(5, len_l_prime-1) do ( for j : Integer.subrange(1, i-1) do ( if l_prime[j - 1+1] + l_prime[j+1] = l_prime[i+1] - 1 then ( count := count + 1 ) else skip) ; if count = k then ( break ) else skip) ; if count = k then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) ); operation SieveOfEratosthenes(n : OclAny) : OclAny pre: true post: true activity: var l_prime : Sequence := Sequence{} ; var prime : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (true)) ; var p : int := 2 ; while (p * p->compareTo(n)) <= 0 do ( if prime[p+1] = true then ( for i : Integer.subrange(p * p, n + 1-1)->select( $x | ($x - p * p) mod p = 0 ) do ( prime[i+1] := false) ) else skip ; p := p + 1) ; for p : Integer.subrange(2, n + 1-1) do ( if prime[p+1] then ( execute ((p) : l_prime) ) else skip) ; return l_prime; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p=[2]; s=[]; n,k=map(int,input().split()) for i in range(3,2000,2): for pp in p : if i % pp==0 : break else : p.append(i) for i in range(1,len(p)): y=1+p[i]+p[i-1] if y in p : s.append(y) x=0 for j in s : if j<=n : x+=1 else : break if x>=k : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : Sequence := Sequence{ 2 }; var s : Sequence := Sequence{}; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(3, 2000-1)->select( $x | ($x - 3) mod 2 = 0 ) do ((compound_stmt for (exprlist (expr (atom (name pp)))) in (testlist (test (logical_test (comparison (expr (atom (name p))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name i))) % (expr (atom (name pp))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name p)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))))))))) ; for i : Integer.subrange(1, (p)->size()-1) do ( var y : int := 1 + p[i+1] + p[i - 1+1] ; if (p)->includes(y) then ( execute ((y) : s) ) else skip) ; var x : int := 0 ; for j : s do ( if (j->compareTo(n)) <= 0 then ( x := x + 1 ) else ( break )) ; if (x->compareTo(k)) >= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=[] b=[] for i in range(1001): a.append(1) for i in range(2,n+1): if a[i]==1 : for j in range(2,int(n/i)+1): a[i*j]=0 b.append(i) s=0 for i in range(len(b)): for j in range(1,i-1): if b[i]==b[j]+b[j+1]+1 : s+=1 break if s>=k : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; for i : Integer.subrange(0, 1001-1) do ( execute ((1) : a)) ; for i : Integer.subrange(2, n + 1-1) do ( if a[i+1] = 1 then ( for j : Integer.subrange(2, ("" + ((n / i)))->toInteger() + 1-1) do ( a[i * j+1] := 0) ; execute ((i) : b) ) else skip) ; var s : int := 0 ; for i : Integer.subrange(0, (b)->size()-1) do ( for j : Integer.subrange(1, i - 1-1) do ( if b[i+1] = b[j+1] + b[j + 1+1] + 1 then ( s := s + 1 ; break ) else skip)) ; if (s->compareTo(k)) >= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys for e in sys.stdin : print(sum(int(a)*k for a,k in zip(e[: 5]+e[9 : 4 :-1],[1,9,36,84,126]*2))% 10) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for e : OclFile["System.in"] do ( execute (((argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))) * (expr (atom (name k))))))) (comp_for for (exprlist (expr (atom (name a))) , (expr (atom (name k)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (number (integer 5))))))))) ]))) + (expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 9))))))) : (test (logical_test (comparison (expr (atom (number (integer 4))))))) (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ])))))))) , (argument (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1))))))) , (test (logical_test (comparison (expr (atom (number (integer 9))))))) , (test (logical_test (comparison (expr (atom (number (integer 36))))))) , (test (logical_test (comparison (expr (atom (number (integer 84))))))) , (test (logical_test (comparison (expr (atom (number (integer 126)))))))) ])) * (expr (atom (number (integer 2)))))))))) )))))))))->sum() mod 10)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_input(): while True : try : yield ''.join(input()) except EOFError : break N=list(get_input()) for l in range(len(N)): S=N[l] table=[[0 for i in range(10)]for j in range(10)] for i in range(len(S)): table[0][i]=int(S[i]) for i in range(1,10): for j in range(0,10-i): table[i][j]=(table[i-1][j]+table[i-1][j+1])% 10 print(table[9][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : Sequence := (OclIterator.newOclIterator_Function(lambda _i : int in self.get_input(_i))) ; for l : Integer.subrange(0, (N)->size()-1) do ( var S : OclAny := N[l+1] ; var table : Sequence := Integer.subrange(0, 10-1)->select(j | true)->collect(j | (Integer.subrange(0, 10-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, (S)->size()-1) do ( table->first()[i+1] := ("" + ((S[i+1])))->toInteger()) ; for i : Integer.subrange(1, 10-1) do ( for j : Integer.subrange(0, 10 - i-1) do ( table[i+1][j+1] := (table[i - 1+1][j+1] + table[i - 1+1][j + 1+1]) mod 10)) ; execute (table[9+1]->first())->display()); operation get_input(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; while true do ( try ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return StringLib.sumStringsWithSeparator(((OclFile["System.in"]).readLine()), '')) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def kaijou(n): result=1 for i in range(1,n+1): result*=i return result def nanbanme(l,n): for i in range(len(l)): if l[i]==n : return i n=int(input()) p=list(map(int,input().split())) q=list(map(int,input().split())) p_n=[i for i in range(1,n+1)] q_n=[i for i in range(1,n+1)] pp,qq=1,1 for i in range(n): if p[i]!=min(p_n): pp+=kaijou(n-i-1)*nanbanme(p_n,p[i]) p_n.remove(p[i]) if q[i]!=min(q_n): qq+=kaijou(n-i-1)*nanbanme(q_n,q[i]) q_n.remove(q[i]) print(abs(pp-qq)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var p_n : Sequence := Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | (i)) ; var q_n : Sequence := Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | (i)) ; var pp : OclAny := null; var qq : OclAny := null; Sequence{pp,qq} := Sequence{1,1} ; for i : Integer.subrange(0, n-1) do ( if p[i+1] /= (p_n)->min() then ( pp := pp + kaijou(n - i - 1) * nanbanme(p_n, p[i+1]) ) else skip ; execute ((p[i+1]) /: p_n) ; if q[i+1] /= (q_n)->min() then ( qq := qq + kaijou(n - i - 1) * nanbanme(q_n, q[i+1]) ) else skip ; execute ((q[i+1]) /: q_n)) ; execute ((pp - qq)->abs())->display(); operation kaijou(n : OclAny) : OclAny pre: true post: true activity: var result : int := 1 ; for i : Integer.subrange(1, n + 1-1) do ( result := result * i) ; return result; operation nanbanme(l : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, (l)->size()-1) do ( if l[i+1] = n then ( return i ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def keisan(patan): sujiretu=[] if len(patan)>1 : for i in range(1,len(patan)): sujiretu.append((int(patan[i-1])+int(patan[i]))% 10) return keisan(sujiretu) else : return patan while(1): try : suuji=input("") suuji=keisan(suuji) print(suuji[0]) except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while (1) do ( try ( var suuji : String := (OclFile["System.in"]).readLine("") ; suuji := keisan(suuji) ; execute (suuji->first())->display()) catch (_e : OclException) do ( break) ); operation keisan(patan : OclAny) : OclAny pre: true post: true activity: var sujiretu : Sequence := Sequence{} ; if (patan)->size() > 1 then ( for i : Integer.subrange(1, (patan)->size()-1) do ( execute (((("" + ((patan[i - 1+1])))->toInteger() + ("" + ((patan[i+1])))->toInteger()) mod 10) : sujiretu)) ; return keisan(sujiretu) ) else ( return patan ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : try : n=input() except : break n=list(map(int,n)) while len(n)>1 : n=[(i+j)% 10 for i,j in zip(n[: len(n)-1],n[1 :])] print(*n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( try ( var n : String := (OclFile["System.in"]).readLine()) catch (_e : OclException) do ( break) ; n := ((n)->collect( _x | (OclType["int"])->apply(_x) )) ; while (n)->size() > 1 do ( n := Integer.subrange(1, n.subrange(1,(n)->size() - 1)->size())->collect( _indx | Sequence{n.subrange(1,(n)->size() - 1)->at(_indx), n->tail()->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let j : OclAny = _tuple->at(2) in ((i + j) mod 10))) ; execute ((argument * (test (logical_test (comparison (expr (atom (name n))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(nums): while len(nums)>1 : nums=[nums[i]+nums[i+1]for i in range(len(nums)-1)] return nums[0]% 10 while True : try : s=list(map(int,list(input()))) print(solve(s)) except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( try ( var s : Sequence := ((((OclFile["System.in"]).readLine())->characters())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (solve(s))->display()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); operation solve(nums : OclAny) : OclAny pre: true post: true activity: while (nums)->size() > 1 do ( nums := Integer.subrange(0, (nums)->size() - 1-1)->select(i | true)->collect(i | (nums[i+1] + nums[i + 1+1]))) ; return nums->first() mod 10; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- keyboard='qwertyuiopasdfghjkl;zxcvbnm,./' shift=input() text=input() fix=0 if shift=='R' : fix=-1 else : fix=1 for x in text : print(keyboard[keyboard.find(x)+fix],sep='',end='') print('') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var keyboard : String := 'qwertyuiopasdfghjkl;zxcvbnm,./' ; var shift : String := (OclFile["System.in"]).readLine() ; var text : String := (OclFile["System.in"]).readLine() ; var fix : int := 0 ; if shift = 'R' then ( fix := -1 ) else ( fix := 1 ) ; for x : text->characters() do ( execute (keyboard[keyboard->indexOf(x) - 1 + fix+1])->display()) ; execute ('')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- alph=dict(zip("qwertyuiopasdfghjkl;zxcvbnm,./",[x for x in range(31)])) valMap=dict(zip([x for x in range(31)],"qwertyuiopasdfghjkl;zxcvbnm,./")) shift=input() val=-1 if shift=="R" else 1 string=input() output="" for s in string : output+=valMap[(alph[s]+val)% 31] print(output) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var alph : Map := ((expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "qwertyuiopasdfghjkl;zxcvbnm,./")))))) , (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name x)))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 31))))))))) )))))))) ]))))))) ))))) ; var valMap : Map := ((expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name x)))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 31))))))))) )))))))) ])))))) , (argument (test (logical_test (comparison (expr (atom "qwertyuiopasdfghjkl;zxcvbnm,./"))))))) ))))) ; var shift : String := (OclFile["System.in"]).readLine() ; var val : int := if shift = "R" then -1 else 1 endif ; var string : String := (OclFile["System.in"]).readLine() ; var output : String := "" ; for s : string->characters() do ( output := output + valMap[(alph[s+1] + val) mod 31+1]) ; execute (output)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Graph : v=None e=None diri=[] def __init__(self,v,e): self.v=v self.e=e self.diri=[[0 for i in range(v)]for j in range(v)] def createGraph(v,e): G=Graph(v,e) G.diri[0][1]=1 G.diri[0][2]=1 G.diri[0][3]=1 G.diri[1][0]=1 G.diri[1][3]=1 G.diri[2][0]=1 G.diri[2][3]=1 G.diri[3][0]=1 G.diri[3][1]=1 G.diri[3][2]=1 return G def findDegree(G,ver): degree=0 for i in range(G.v): if G.diri[ver][i]==1 : degree+=1 return degree if __name__=="__main__" : vertices=4 edges=5 G=createGraph(vertices,edges) ver=0 degree=findDegree(G,ver) print(degree) ------------------------------------------------------------ OCL File: --------- class Graph { static operation newGraph() : Graph pre: true post: Graph->exists( _x | result = _x ); static attribute v : OclAny := null; static attribute e : OclAny := null; static attribute diri : Sequence := Sequence{}; attribute v : OclAny := v; attribute e : OclAny := e; attribute diri : Sequence := Integer.subrange(0, v-1)->select(j | true)->collect(j | (Integer.subrange(0, v-1)->select(i | true)->collect(i | (0)))); operation initialise(v : OclAny,e : OclAny) : Graph pre: true post: true activity: self.v := v ; self.e := e ; self.diri := Integer.subrange(0, v-1)->select(j | true)->collect(j | (Integer.subrange(0, v-1)->select(i | true)->collect(i | (0)))); return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( var vertices : int := 4 ; var edges : int := 5 ; G := createGraph(vertices, edges) ; ver := 0 ; degree := findDegree(G, ver) ; execute (degree)->display() ) else skip; operation createGraph(v : OclAny, e : OclAny) : OclAny pre: true post: true activity: var G : Graph := (Graph.newGraph()).initialise(v, e) ; G.diri->first()[1+1] := 1 ; G.diri->first()[2+1] := 1 ; G.diri->first()[3+1] := 1 ; G.diri[1+1]->first() := 1 ; G.diri[1+1][3+1] := 1 ; G.diri[2+1]->first() := 1 ; G.diri[2+1][3+1] := 1 ; G.diri[3+1]->first() := 1 ; G.diri[3+1][1+1] := 1 ; G.diri[3+1][2+1] := 1 ; return G; operation findDegree(G : OclAny, ver : OclAny) : OclAny pre: true post: true activity: var degree : int := 0 ; for i : Integer.subrange(0, G.v-1) do ( if G.diri[ver+1][i+1] = 1 then ( degree := degree + 1 ) else skip) ; return degree; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- buttons='qwertyuiopasdfghjkl;zxcvbnm,./' flag=0 if input()=='L' : flag=1 else : flag=-1 for i in input(): print(buttons[buttons.index(i)+flag],end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var buttons : String := 'qwertyuiopasdfghjkl;zxcvbnm,./' ; var flag : int := 0 ; if (OclFile["System.in"]).readLine() = 'L' then ( flag := 1 ) else ( flag := -1 ) ; for i : (OclFile["System.in"]).readLine() do ( execute (buttons[buttons->indexOf(i) - 1 + flag+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() a=input() p='qwertyuiopasdfghjkl;zxcvbnm,./' x='' for i in a : if s=="R" : x+=p[p.index(i)-1] if s=="L" : x+=p[p.index(i)+1] print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var a : String := (OclFile["System.in"]).readLine() ; var p : String := 'qwertyuiopasdfghjkl;zxcvbnm,./' ; var x : String := '' ; for i : a->characters() do ( if s = "R" then ( x := x + p[p->indexOf(i) - 1 - 1+1] ) else skip ; if s = "L" then ( x := x + p[p->indexOf(i) - 1 + 1+1] ) else skip) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sh=input() string=input() g=len(string) llist=['q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l',';','z','x','c','v','b','n','m',',','.','/'] k=len(llist) llist2=list(string) if sh=='R' : for i in range(g): for j in range(k): if(llist2[i]==llist[j]): llist2[i]=llist[j-1] break else : for i in range(g): for j in range(k): if(llist2[i]==llist[j]): llist2[i]=llist[j+1] break string=''.join(llist2) print(string) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sh : String := (OclFile["System.in"]).readLine() ; var string : String := (OclFile["System.in"]).readLine() ; var g : int := (string)->size() ; var llist : Sequence := Sequence{'q'}->union(Sequence{'w'}->union(Sequence{'e'}->union(Sequence{'r'}->union(Sequence{'t'}->union(Sequence{'y'}->union(Sequence{'u'}->union(Sequence{'i'}->union(Sequence{'o'}->union(Sequence{'p'}->union(Sequence{'a'}->union(Sequence{'s'}->union(Sequence{'d'}->union(Sequence{'f'}->union(Sequence{'g'}->union(Sequence{'h'}->union(Sequence{'j'}->union(Sequence{'k'}->union(Sequence{'l'}->union(Sequence{';'}->union(Sequence{'z'}->union(Sequence{'x'}->union(Sequence{'c'}->union(Sequence{'v'}->union(Sequence{'b'}->union(Sequence{'n'}->union(Sequence{'m'}->union(Sequence{','}->union(Sequence{'.'}->union(Sequence{ '/' }))))))))))))))))))))))))))))) ; var k : int := (llist)->size() ; var llist2 : Sequence := (string)->characters() ; if sh = 'R' then ( for i : Integer.subrange(0, g-1) do ( for j : Integer.subrange(0, k-1) do ( if (llist2[i+1] = llist[j+1]) then ( llist2[i+1] := llist[j - 1+1] ; break ) else skip)) ) else ( for i : Integer.subrange(0, g-1) do ( for j : Integer.subrange(0, k-1) do ( if (llist2[i+1] = llist[j+1]) then ( llist2[i+1] := llist[j + 1+1] ; break ) else skip)) ) ; string := StringLib.sumStringsWithSeparator((llist2), '') ; execute (string)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_CHAR=26 ; def areKAnagrams(str1,str2,k): n=len(str1); if(len(str2)!=n): return False ; hash_str1=[0]*(MAX_CHAR); for i in range(n): hash_str1[ord(str1[i])-ord('a')]+=1 ; count=0 ; for i in range(n): if(hash_str1[ord(str2[i])-ord('a')]>0): hash_str1[ord(str2[i])-ord('a')]-=1 ; else : count+=1 ; if(count>k): return False ; return True ; str1="fodr" ; str2="gork" ; k=2 ; if(areKAnagrams(str1,str2,k)==True): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_CHAR : int := 26; ; skip ; str1 := "fodr"; ; str2 := "gork"; ; k := 2; ; if (areKAnagrams(str1, str2, k) = true) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ); operation areKAnagrams(str1 : OclAny, str2 : OclAny, k : OclAny) pre: true post: true activity: var n : int := (str1)->size(); ; if ((str2)->size() /= n) then ( return false; ) else skip ; var hash_str1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX_CHAR)); ; for i : Integer.subrange(0, n-1) do ( hash_str1[(str1[i+1])->char2byte() - ('a')->char2byte()+1] := hash_str1[(str1[i+1])->char2byte() - ('a')->char2byte()+1] + 1;) ; var count : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (hash_str1[(str2[i+1])->char2byte() - ('a')->char2byte()+1] > 0) then ( hash_str1[(str2[i+1])->char2byte() - ('a')->char2byte()+1] := hash_str1[(str2[i+1])->char2byte() - ('a')->char2byte()+1] - 1; ) else ( count := count + 1; ) ; if ((count->compareTo(k)) > 0) then ( return false; ) else skip) ; return true;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) import itertools orig=list(itertools.permutations(list(range(1,n+1)))) p=tuple(map(int,input().split())) q=tuple(map(int,input().split())) pn=orig.index(p) qn=orig.index(q) print(abs(pn-qn)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; var orig : Sequence := (itertools.permutations((Integer.subrange(1, n + 1-1)))) ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var pn : int := orig->indexOf(p) - 1 ; var qn : int := orig->indexOf(q) - 1 ; execute ((pn - qn)->abs())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) t=min(a,(b-1),(c-2)) print(3*t+3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : OclAny := Set{a, (b - 1), (c - 2)}->min() ; execute (3 * t + 3)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- y,b,r=map(int,input().split()) if b==r : if y=b : z=3*r-3 print(z) elif b=r : z=3*b print(z) elif br : if y>=b or y==r : if r-2<=y : z=3*r-3 print(z) else : z=3*r print(z) elif ycollect( _x | (OclType["int"])->apply(_x) ) ; if b = r then ( if (y->compareTo(b)) < 0 then ( if (y + 2->compareTo(r)) <= 0 then ( var z : double := 3 * y + 3 ; execute (z)->display() ) else ( z := 3 * y ; execute (z)->display() ) ) else (if (y->compareTo(b)) >= 0 then ( z := 3 * r - 3 ; execute (z)->display() ) else skip) ) else (if (b->compareTo(r)) < 0 then ( if (y->compareTo(b)) < 0 then ( if (y + 2->compareTo(r)) <= 0 then ( z := 3 * y + 3 ; execute (z)->display() ) else ( z := 3 * y ; execute (z)->display() ) ) else (if y = b or (y->compareTo(r)) >= 0 then ( z := 3 * b ; execute (z)->display() ) else (if (b->compareTo(y)) < 0 & (y->compareTo(r)) < 0 then ( z := 3 * b ; execute (z)->display() ) else skip ) ) ) else (if (b->compareTo(r)) > 0 then ( if (y->compareTo(b)) >= 0 or y = r then ( if (r - 2->compareTo(y)) <= 0 then ( z := 3 * r - 3 ; execute (z)->display() ) else ( z := 3 * r ; execute (z)->display() ) ) else (if (y->compareTo(r)) < 0 then ( if (y + 2->compareTo(r)) <= 0 then ( z := 3 * y + 3 ; execute (z)->display() ) else ( z := 3 * y ; execute (z)->display() ) ) else (if (r->compareTo(y)) < 0 & (y->compareTo(b)) < 0 then ( z := 3 * r - 3 ; execute (z)->display() ) else skip ) ) ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- y,b,r=map(int,input().split()) if b==r : if y=b : z=3*r-3 print(z) elif b=r : z=3*b print(z) elif br : if y>=b or y==r : if r-2<=y : z=3*r-3 print(z) else : z=3*r print(z) elif ycollect( _x | (OclType["int"])->apply(_x) ) ; if b = r then ( if (y->compareTo(b)) < 0 then ( if (y + 2->compareTo(r)) <= 0 then ( var z : double := 3 * y + 3 ; execute (z)->display() ) else ( z := 3 * y ; execute (z)->display() ) ) else (if (y->compareTo(b)) >= 0 then ( z := 3 * r - 3 ; execute (z)->display() ) else skip) ) else (if (b->compareTo(r)) < 0 then ( if (y->compareTo(b)) < 0 then ( if (y + 2->compareTo(r)) <= 0 then ( z := 3 * y + 3 ; execute (z)->display() ) else ( z := 3 * y ; execute (z)->display() ) ) else (if y = b or (y->compareTo(r)) >= 0 then ( z := 3 * b ; execute (z)->display() ) else (if (b->compareTo(y)) < 0 & (y->compareTo(r)) < 0 then ( z := 3 * b ; execute (z)->display() ) else skip ) ) ) else (if (b->compareTo(r)) > 0 then ( if (y->compareTo(b)) >= 0 or y = r then ( if (r - 2->compareTo(y)) <= 0 then ( z := 3 * r - 3 ; execute (z)->display() ) else ( z := 3 * r ; execute (z)->display() ) ) else (if (y->compareTo(r)) < 0 then ( if (y + 2->compareTo(r)) <= 0 then ( z := 3 * y + 3 ; execute (z)->display() ) else ( z := 3 * y ; execute (z)->display() ) ) else (if (r->compareTo(y)) < 0 & (y->compareTo(b)) < 0 then ( z := 3 * r - 3 ; execute (z)->display() ) else skip ) ) ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- y,b,r=[int(i)for i in input().split()] a=min(y+1,b,r-1) print(a*3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var y : OclAny := null; var b : OclAny := null; var r : OclAny := null; Sequence{y,b,r} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a : OclAny := Set{y + 1, b, r - 1}->min() ; execute (a * 3)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- y,b,r=(int(i)for i in input().split()) x=min(y,b-1,r-2) res=x+(x+1)+(x+2) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var y : OclAny := null; var b : OclAny := null; var r : OclAny := null; Sequence{y,b,r} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var x : OclAny := Set{y, b - 1, r - 2}->min() ; var res : OclAny := x + (x + 1) + (x + 2) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isComposite(n): if(n<=1): return False if(n<=3): return False if(n % 2==0 or n % 3==0): return True i=5 while(i*i<=n): if(n % i==0 or n %(i+2)==0): return True i=i+6 return False def isDigitSumOne(nm): while(nm>9): sum_digit=0 while(nm!=0): digit=nm % 10 sum_digit=sum_digit+digit nm=nm//10 nm=sum_digit if(nm==1): return True else : return False def printValidNums(m,n): for i in range(m,n+1): if(isComposite(i)and isDigitSumOne(i)): print(i,end=" ") l=10 r=100 printValidNums(m,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var l : int := 10 ; var r : int := 100 ; printValidNums(m, n); operation isComposite(n : OclAny) : OclAny pre: true post: true activity: if (n <= 1) then ( return false ) else skip ; if (n <= 3) then ( return false ) else skip ; if (n mod 2 = 0 or n mod 3 = 0) then ( return true ) else skip ; var i : int := 5 ; while ((i * i->compareTo(n)) <= 0) do ( if (n mod i = 0 or n mod (i + 2) = 0) then ( return true ) else skip ; i := i + 6) ; return false; operation isDigitSumOne(nm : OclAny) : OclAny pre: true post: true activity: while (nm > 9) do ( var sum_digit : int := 0 ; while (nm /= 0) do ( var digit : int := nm mod 10 ; sum_digit := sum_digit + digit ; nm := nm div 10) ; nm := sum_digit) ; if (nm = 1) then ( return true ) else ( return false ); operation printValidNums(m : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(m, n + 1-1) do ( if (isComposite(i) & isDigitSumOne(i)) then ( execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def binary_search(c1,c2): m=(c1+c2+1)//2 while abs(c1-c2)>1 : m=(c1+c2+1)//2 if ok0(m): c2=m else : c1=m m=max(m-2,0) while not ok0(m): m+=1 return m def ok0(m): c=1 for i in range(m,n): if 0toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Set := Set{}->union((b)) ; var ok : int := 0 ; if (s)->includes(1) then ( var i : int := b->indexOf(1) - 1 ; var f : int := 1 ; c := 1 ; while (i->compareTo(n)) < 0 do ( if MathLib.bitwiseXor(b[i+1], c) then ( f := 0 ; break ) else skip ; i := i + 1 ; c := c + 1) ; if f then ( var ans : int := 0 ; ok := 1 ; i := 0 ; while (c->compareTo(n)) <= 0 do ( ans := ans + 1 ; if b[i+1] & (b[i+1]->compareTo(c)) <= 0 then ( ok := 0 ; break ) else skip ; i := i + 1 ; c := c + 1) ) else skip ) else skip ; if not(ok) then ( ans := n + binary_search(0, n + 1) ) else skip ; execute (ans)->display(); operation binary_search(c1 : OclAny, c2 : OclAny) : OclAny pre: true post: true activity: var m : int := (c1 + c2 + 1) div 2 ; while (c1 - c2)->abs() > 1 do ( m := (c1 + c2 + 1) div 2 ; if ok0(m) then ( c2 := m ) else ( c1 := m )) ; m := Set{m - 2, 0}->max() ; while not(ok0(m)) do ( m := m + 1) ; return m; operation ok0(m : OclAny) : OclAny pre: true post: true activity: var c : int := 1 ; for i : Integer.subrange(m, n-1) do ( if 0 < b[i+1] & (b[i+1] <= c) then ( return false ) else skip ; c := c + 1) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxProduct(arr,n): ans=-1 for i in range(n-2): for j in range(i+1,n-1): for k in range(j+1,n): if(arr[i]arr[k]): ans=max(ans,arr[i]*arr[j]*arr[k]) return ans if __name__=='__main__' : arr=[1,8,3,7] n=len(arr) print(maxProduct(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{8}->union(Sequence{3}->union(Sequence{ 7 }))) ; n := (arr)->size() ; execute (maxProduct(arr, n))->display() ) else skip; operation maxProduct(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := -1 ; for i : Integer.subrange(0, n - 2-1) do ( for j : Integer.subrange(i + 1, n - 1-1) do ( for k : Integer.subrange(j + 1, n-1) do ( if ((arr[i+1]->compareTo(arr[j+1])) < 0 & (arr[j+1]->compareTo(arr[k+1])) > 0) then ( ans := Set{ans, arr[i+1] * arr[j+1] * arr[k+1]}->max() ) else skip))) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt MAXN=100001 spf=[0 for i in range(MAXN)] def sieve(): spf[1]=1 for i in range(2,MAXN): spf[i]=i for i in range(4,MAXN,2): spf[i]=2 for i in range(3,mt.ceil(mt.sqrt(MAXN))): if(spf[i]==i): for j in range(i*i,MAXN,i): if(spf[j]==j): spf[j]=i def getFactorization(x): ret=list() while(x!=1): ret.append(spf[x]) x=x//spf[x] return ret sieve() x=12246 print("prime factorization for",x,": ",end="") p=getFactorization(x) for i in range(len(p)): print(p[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MAXN : int := 100001 ; var spf : Sequence := Integer.subrange(0, MAXN-1)->select(i | true)->collect(i | (0)) ; skip ; skip ; sieve() ; x := 12246 ; execute ("prime factorization for")->display() ; var p : OclAny := getFactorization(x) ; for i : Integer.subrange(0, (p)->size()-1) do ( execute (p[i+1])->display()); operation sieve() pre: true post: true activity: spf[1+1] := 1 ; for i : Integer.subrange(2, MAXN-1) do ( spf[i+1] := i) ; for i : Integer.subrange(4, MAXN-1)->select( $x | ($x - 4) mod 2 = 0 ) do ( spf[i+1] := 2) ; for i : Integer.subrange(3, mt.ceil(mt.sqrt(MAXN))-1) do ( if (spf[i+1] = i) then ( for j : Integer.subrange(i * i, MAXN-1)->select( $x | ($x - i * i) mod i = 0 ) do ( if (spf[j+1] = j) then ( spf[j+1] := i ) else skip) ) else skip); operation getFactorization(x : OclAny) : OclAny pre: true post: true activity: var ret : Sequence := () ; while (x /= 1) do ( execute ((spf[x+1]) : ret) ; x := x div spf[x+1]) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sympy import* import random n=32 j=500 arr=[] f=open("out.txt","w") def findDivisor(x): res=2 while x % res!=0 and res<100 : res+=1 return res for i in xrange(2**(n-2)): t=bin(i)[2 :] t="0"*(n-2-len(t))+t t="1"+t+"1" ok=True for base in xrange(2,11): if isprime(int(t,base))or findDivisor(int(t,base))==100 : ok=False break if ok : data=[] data.append(t) for base in xrange(2,11): num=int(t,base) data.append(str(findDivisor(num))) arr.append(data) if len(arr)==j : break print>>f,"Case #1:" for l in arr : print>>f,' '.join(l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := 32 ; var j : int := 500 ; var arr : Sequence := Sequence{} ; var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("out.txt")) ; skip ; for i : xrange((2)->pow((n - 2))) do ( var t : OclAny := bin(i).subrange(2+1) ; t := StringLib.nCopies("0", (n - 2 - (t)->size())) + t ; t := "1" + t + "1" ; var ok : boolean := true ; for base : xrange(2, 11) do ( if isprime(("" + ((t, base)))->toInteger()) or findDivisor(("" + ((t, base)))->toInteger()) = 100 then ( ok := false ; break ) else skip) ; if ok then ( var data : Sequence := Sequence{} ; execute ((t) : data) ; for base : xrange(2, 11) do ( var num : int := ("" + ((t, base)))->toInteger() ; execute ((("" + ((findDivisor(num))))) : data)) ; execute ((data) : arr) ; if (arr)->size() = j then ( break ) else skip ) else skip) ; print /(2->pow(f)) ; ; for l : arr do ( print /(2->pow(f)) ; ' '.join(l)); operation findDivisor(x : OclAny) : OclAny pre: true post: true activity: var res : int := 2 ; while x mod res /= 0 & res < 100 do ( res := res + 1) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() n=int(input()) ans=0 for i in range(n): x=input() a,b=0,0 for j in s : if j==x[0]: a+=1 elif j==x[1]: b+=1 else : ans=ans+min(a,b) a,b=0,0 ans=ans+min(a,b) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x : String := (OclFile["System.in"]).readLine() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{0,0} ; for j : s->characters() do ( if j = x->first() then ( a := a + 1 ) else (if j = x[1+1] then ( b := b + 1 ) else ( ans := ans + Set{a, b}->min() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{0,0} ) ) ) ; ans := ans + Set{a, b}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,sys,ljqpy,time,random time.clock() def CheckNotPrime(x): if x % 2==0 : return 2 for i in range(3,101,2): if i>=x : break if x % i==0 : return i return 0 def Run(n,j,fout): random.seed(1333) st=set() while j>0 : v=[1]+[random.randint(0,1)for x in range(n-2)]+[1] zz=''.join(str(x)for x in v) if zz in st : continue st.add(zz) rt=[] for b in range(2,11): z=0 for c in v : z=z*b+c rt.append(CheckNotPrime(z)) if rt[-1]==0 : break if rt[-1]!=0 : print(zz,rt) fout.write(zz+' ') fout.write(' '.join(str(x)for x in rt)) fout.write('\n') j-=1 lst=ljqpy.LoadList('input.txt') outf='C-large.out' with open(outf,'w')as fout : fout.write('Case #1:\n') Run(32,500,fout) os.system(outf) print('completed') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; time.clock() ; skip ; skip ; var lst : OclAny := ljqpy.LoadList('input.txt') ; var outf : String := 'C-large.out' ; try (var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(outf)); fout.write('Case #1: ') ; Run(32, 500, fout)) catch (_e : OclException) do skip ; os.system(outf) ; execute ('completed')->display(); operation CheckNotPrime(x : OclAny) : OclAny pre: true post: true activity: if x mod 2 = 0 then ( return 2 ) else skip ; for i : Integer.subrange(3, 101-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if (i->compareTo(x)) >= 0 then ( break ) else skip ; if x mod i = 0 then ( return i ) else skip) ; return 0; operation Run(n : OclAny, j : OclAny, fout : OclAny) pre: true post: true activity: random.setSeed(1333) ; var st : Set := Set{}->union(()) ; while j > 0 do ( var v : Sequence := Sequence{ 1 }->union(Integer.subrange(0, n - 2-1)->select(x | true)->collect(x | ((0 + (OclRandom.defaultInstanceOclRandom()).nextInt(1 - 0)))))->union(Sequence{ 1 }) ; var zz : String := StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name v)))))))), '') ; if (st)->includes(zz) then ( continue ) else skip ; execute ((zz) : st) ; var rt : Sequence := Sequence{} ; for b : Integer.subrange(2, 11-1) do ( var z : int := 0 ; for c : v do ( z := z * b + c) ; execute ((CheckNotPrime(z)) : rt) ; if rt->last() = 0 then ( break ) else skip) ; if rt->last() /= 0 then ( execute (zz)->display() ; fout.write(zz + ' ') ; fout.write(StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name rt)))))))), ' ')) ; fout.write(' ') ; j := j - 1 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- TEST='large' IN='C-{}.in'.format(TEST) OUT='C-{}.out'.format(TEST) MAX_PRIME=10000 def sieve(lim): p=[True]*lim p[0]=p[1]=False for i in range(lim): if p[i]: for j in range(i*2,lim,i): p[j]=False return[i for i,v in enumerate(p)if v] primes=sieve(MAX_PRIME) def check(s): r=[] for b in range(2,11): x=int(s,b) for p in primes : if x % p==0 : r.append(p) break else : return None return r def run(n,j): maxm=2**(n-2) fmt='1{{:0{}b}}1'.format(n-2) coins=[] for m in range(maxm): s=fmt.format(m) r=check(s) if r is not None : coins.append((s,r)) if len(coins)==j : break assert len(coins)==j return['{}{}'.format(s,' '.join(map(str,r)))for s,r in coins] def main(): with open(IN)as fin,open(OUT,'w')as fout : t=int(fin.readline().strip()) for i in range(t): n,j=map(int,fin.readline().strip().split()) res=run(n,j) print('Case #{}:'.format(i+1),file=fout) for line in res : print(line,file=fout) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var TEST : String := 'large' ; var IN : String := StringLib.interpolateStrings('C-{}.in', Sequence{TEST}) ; var OUT : String := StringLib.interpolateStrings('C-{}.out', Sequence{TEST}) ; var MAX_PRIME : int := 10000 ; skip ; var primes : OclAny := sieve(MAX_PRIME) ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation sieve(lim : OclAny) : OclAny pre: true post: true activity: var p : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, lim) ; p->first() := false; var p[1+1] : boolean := false ; for i : Integer.subrange(0, lim-1) do ( if p[i+1] then ( for j : Integer.subrange(i * 2, lim-1)->select( $x | ($x - i * 2) mod i = 0 ) do ( p[j+1] := false) ) else skip) ; return Integer.subrange(1, (p)->size())->collect( _indx | Sequence{_indx-1, (p)->at(_indx)} )->select(_tuple | let i : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in v)->collect(_tuple | let i : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in (i)); operation check(s : OclAny) : OclAny pre: true post: true activity: var r : Sequence := Sequence{} ; for b : Integer.subrange(2, 11-1) do ( var x : int := ("" + ((s, b)))->toInteger() ; (compound_stmt for (exprlist (expr (atom (name p)))) in (testlist (test (logical_test (comparison (expr (atom (name primes))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name x))) % (expr (atom (name p))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name r)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom None))))))))))))) ; return r; operation run(n : OclAny, j : OclAny) : OclAny pre: true post: true activity: var maxm : double := (2)->pow((n - 2)) ; var fmt : String := StringLib.interpolateStrings('1{{:0{}b}}1', Sequence{n - 2}) ; var coins : Sequence := Sequence{} ; for m : Integer.subrange(0, maxm-1) do ( s := StringLib.interpolateStrings(fmt, Sequence{m}) ; r := check(s) ; if not(r <>= null) then ( execute ((Sequence{s, r}) : coins) ; if (coins)->size() = j then ( break ) else skip ) else skip) ; assert (coins)->size() = j do "assertion failed" ; return coins->select(_tuple | true)->collect(_tuple | let s : OclAny = _tuple->at(1) in let r : OclAny = _tuple->at(2) in (StringLib.interpolateStrings('{}{}', Sequence{s, StringLib.sumStringsWithSeparator(((r)->collect( _x | (OclType["String"])->apply(_x) )), ' ')}))); operation main() pre: true post: true activity: try (var fin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(IN)); var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(OUT)); var t : int := ("" + ((fin.readLine()->trim())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( Sequence{n,j} := (fin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var res : OclAny := run(n, j) ; execute (StringLib.interpolateStrings('Case #{}:', Sequence{i + 1}))->display() ; for line : res do ( execute (line)->display()))) catch (_e : OclException) do skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys fin=open(sys.argv[1],"r") fout=open("p3.out","w") fin.readline() N,J=map(int,fin.readline().split()) fout.write("Case #1:\n") def conv_base(l,base): ret=1+base**(N-1) ret+=sum(map(lambda x : base**x,l)) return ret def lcp(n): for m in xrange(2,min(n,1000)): if n % m==0 : return m return-1 ans={3 : 2,4 : 3,5 : 2,7 : 2,9 : 2,10 : 3} cur=[1,2,3,4] while J>0 : j=3 for i in xrange(len(cur)-1): if cur[i]+1==cur[i+1]: continue else : j=i break cur[j]+=1 for i in xrange(j): cur[i]=i+1 ans[2]=lcp(conv_base(cur,2)) ans[6]=lcp(conv_base(cur,6)) ans[8]=lcp(conv_base(cur,8)) if ans[2]<0 or ans[6]<0 or ans[8]<0 : continue else : J-=1 fout.write(str(conv_base(cur,10))+' ') for i in xrange(2,10): fout.write(str(ans[i])+' ') fout.write(str(ans[10])+'\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var fin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) ; var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("p3.out")) ; fin.readLine() ; var N : OclAny := null; var J : OclAny := null; Sequence{N,J} := (fin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; fout.write("Case #1:\n") ; skip ; skip ; var ans : Map := Map{ 3 |-> 2 }->union(Map{ 4 |-> 3 }->union(Map{ 5 |-> 2 }->union(Map{ 7 |-> 2 }->union(Map{ 9 |-> 2 }->union(Map{ 10 |-> 3 }))))) ; var cur : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))) ; while J > 0 do ( var j : int := 3 ; for i : xrange((cur)->size() - 1) do ( if cur[i+1] + 1 = cur[i + 1+1] then ( continue ) else ( j := i ; break )) ; cur[j+1] := cur[j+1] + 1 ; for i : xrange(j) do ( cur[i+1] := i + 1) ; ans[2+1] := lcp(conv_base(cur, 2)) ; ans[6+1] := lcp(conv_base(cur, 6)) ; ans[8+1] := lcp(conv_base(cur, 8)) ; if ans[2+1] < 0 or ans[6+1] < 0 or ans[8+1] < 0 then ( continue ) else ( J := J - 1 ; fout.write(("" + ((conv_base(cur, 10)))) + ' ') ; for i : xrange(2, 10) do ( fout.write(("" + ((ans[i+1]))) + ' ')) ; fout.write(("" + ((ans[10+1]))) + ' ') )); operation conv_base(l : OclAny, base : OclAny) : OclAny pre: true post: true activity: var ret : int := 1 + (base)->pow((N - 1)) ; ret := ret + ((l)->collect( _x | (lambda x : OclAny in ((base)->pow(x)))->apply(_x) ))->sum() ; return ret; operation lcp(n : OclAny) : OclAny pre: true post: true activity: for m : xrange(2, Set{n, 1000}->min()) do ( if n mod m = 0 then ( return m ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools N=32 J=500 print("Case #1:") for _,tup in zip(range(J),itertools.product(['00','11'],repeat=N//2-1)): coin='1%s1 3 4 5 6 7 8 9 10 11' %(''.join(tup),) print(coin) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 32 ; var J : int := 500 ; execute ("Case #1:")->display() ; for _tuple : Integer.subrange(1, Integer.subrange(0, J-1)->size())->collect( _indx | Sequence{Integer.subrange(0, J-1)->at(_indx), itertools.product(Sequence{'00'}->union(Sequence{ '11' }), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (expr (expr (atom (name N))) // (expr (atom (number (integer 2))))) - (expr (atom (number (integer 1))))))))))->at(_indx)} ) do (var _indx : int := 1; var _anon : OclAny := _tuple->at(_indx); _indx := _indx + 1; var tup : OclAny := _tuple->at(_indx); var coin : String := StringLib.format('1%s1 3 4 5 6 7 8 9 10 11',Sequence{(testlist_comp (test (logical_test (comparison (expr (atom '') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name tup)))))))) ))))))) ,)}) ; execute (coin)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMinNumber(n): count=0 ; ans=1 ; while(n % 2==0): count+=1 ; n/=2 ; if(count % 3!=0): ans*=pow(2,(count % 3)); for i in range(3,int(pow(n,1/2)),2): count=0 ; while(n % i==0): count+=1 ; n/=i ; if(count % 3!=0): ans*=pow(i,(count % 3)); if(n>2): ans*=n ; return ans ; if __name__=='__main__' : n=128 ; print(findMinNumber(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 128; ; execute (findMinNumber(n))->display(); ) else skip; operation findMinNumber(n : OclAny) pre: true post: true activity: var count : int := 0; ; var ans : int := 1; ; while (n mod 2 = 0) do ( count := count + 1; ; n := n / 2;) ; if (count mod 3 /= 0) then ( ans := ans * (2)->pow((count mod 3)); ) else skip ; for i : Integer.subrange(3, ("" + (((n)->pow(1 / 2))))->toInteger()-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( count := 0; ; while (n mod i = 0) do ( count := count + 1; ; n := n / i;) ; if (count mod 3 /= 0) then ( ans := ans * (i)->pow((count mod 3)); ) else skip) ; if (n > 2) then ( ans := ans * n; ) else skip ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def findMinNumber(n): count=0 ans=1 while n % 2==0 : count+=1 n//=2 if count % 2 is not 0 : ans*=2 for i in range(3,(int)(math.sqrt(n))+1,2): count=0 while n % i==0 : count+=1 n//=i if count % 2 is not 0 : ans*=i if n>2 : ans*=n return ans n=72 print(findMinNumber(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 72 ; execute (findMinNumber(n))->display(); operation findMinNumber(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var ans : int := 1 ; while n mod 2 = 0 do ( count := count + 1 ; n := n div 2) ; if not(count mod 2 <>= 0) then ( ans := ans * 2 ) else skip ; for i : Integer.subrange(3, (OclType["int"])((n)->sqrt()) + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( count := 0 ; while n mod i = 0 do ( count := count + 1 ; n := n div i) ; if not(count mod 2 <>= 0) then ( ans := ans * i ) else skip) ; if n > 2 then ( ans := ans * n ) else skip ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r=int(input()) l=[1,1] g=[] for i in range(2,2*r): if l[i-1]+l[i-2]>r : break l.append(l[i-1]+l[i-2]) for i in range(1,r+1): if i in l : g.append('O') else : g.append('o') print(''.join(g)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var g : Sequence := Sequence{} ; for i : Integer.subrange(2, 2 * r-1) do ( if (l[i - 1+1] + l[i - 2+1]->compareTo(r)) > 0 then ( break ) else skip ; execute ((l[i - 1+1] + l[i - 2+1]) : l)) ; for i : Integer.subrange(1, r + 1-1) do ( if (l)->includes(i) then ( execute (('O') : g) ) else ( execute (('o') : g) )) ; execute (StringLib.sumStringsWithSeparator((g), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) p=[0]*(n+1) for i in range(n): p[b[i]]=i+1 if p[1]: i=2 while i<=n and p[i]==p[i-1]+1 : i+=1 if p[i-1]==n : j=i while j<=n and p[j]<=j-i : j+=1 if j==n+1 : print(p[1]-1) exit() print(max(p[i]-i+n+1 for i in range(1,n+1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var p : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(0, n-1) do ( p[b[i+1]+1] := i + 1) ; if p[1+1] then ( var i : int := 2 ; while (i->compareTo(n)) <= 0 & p[i+1] = p[i - 1+1] + 1 do ( i := i + 1) ; if p[i - 1+1] = n then ( var j : int := i ; while (j->compareTo(n)) <= 0 & (p[j+1]->compareTo(j - i)) <= 0 do ( j := j + 1) ; if j = n + 1 then ( execute (p[1+1] - 1)->display() ; exit() ) else skip ) else skip ) else skip ; execute (((argument (test (logical_test (comparison (expr (expr (expr (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name i)))) + (expr (atom (name n)))) + (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) )))))))))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) f0=0 f1=1 fibo_numbers=[0,1] while f1toInteger() ; var f0 : int := 0 ; var f1 : int := 1 ; var fibo_numbers : Sequence := Sequence{0}->union(Sequence{ 1 }) ; while (f1->compareTo(n)) < 0 do ( var tmp : int := f0 + f1 ; f0 := f1 ; f1 := tmp ; execute ((f1) : fibo_numbers)) ; for i : Integer.subrange(1, n + 1-1) do ( if (fibo_numbers)->includes(i) then ( execute ('O')->display() ) else ( execute ('o')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input('')) fib=[1] f1,f2=1,1 k=0 for i in range(2,n+1): sum=f1+f2 f1=f2 f2=sum fib.append(sum) for i in range(1,n+1): if i==fib[k]: print('O',end="") k+=1 else : print('o',end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; var fib : Sequence := Sequence{ 1 } ; var f1 : OclAny := null; var f2 : OclAny := null; Sequence{f1,f2} := Sequence{1,1} ; var k : int := 0 ; for i : Integer.subrange(2, n + 1-1) do ( var sum : OclAny := f1 + f2 ; var f1 : OclAny := f2 ; var f2 : OclAny := sum ; execute ((sum) : fib)) ; for i : Integer.subrange(1, n + 1-1) do ( if i = fib[k+1] then ( execute ('O')->display() ; k := k + 1 ) else ( execute ('o')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() ans=0 for i in range(int(input())): x=input() a,b=0,0 for j in s : if j==x[0]: a+=1 elif j==x[1]: b+=1 else : ans+=min(a,b) a,b=0,0 ans+=min(a,b) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : String := (OclFile["System.in"]).readLine() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{0,0} ; for j : s->characters() do ( if j = x->first() then ( a := a + 1 ) else (if j = x[1+1] then ( b := b + 1 ) else ( ans := ans + Set{a, b}->min() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{0,0} ) ) ) ; ans := ans + Set{a, b}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) z=['o']*n fibs=[1,1] for i in range(2,n+1): fibs+=fibs[i-1]+fibs[i-2], j=1 k=1 while(j!=n+1): if j>fibs[k]: k+=1 if j==fibs[k]: z[j-1]='O' k+=1 j+=1 print(''.join(z)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var z : Sequence := MatrixLib.elementwiseMult(Sequence{ 'o' }, n) ; var fibs : Sequence := Sequence{1}->union(Sequence{ 1 }) ; for i : Integer.subrange(2, n + 1-1) do ( fibs := fibs + (testlist (test (logical_test (comparison (expr (expr (atom (name fibs)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))) + (expr (atom (name fibs)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 2)))))))))) ]))))))) ,)) ; var j : int := 1 ; var k : int := 1 ; while (j /= n + 1) do ( if (j->compareTo(fibs[k+1])) > 0 then ( k := k + 1 ) else skip ; if j = fibs[k+1] then ( z[j - 1+1] := 'O' ; k := k + 1 ) else skip ; j := j + 1) ; execute (StringLib.sumStringsWithSeparator((z), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) f1=1 f2=1 fibList=[f1,f2] count=1 name="" while counttoInteger() ; var f1 : int := 1 ; var f2 : int := 1 ; var fibList : Sequence := Sequence{f1}->union(Sequence{ f2 }) ; var count : int := 1 ; var name : String := "" ; while (count->compareTo(n)) < 0 do ( var newNum : int := f1 + f2 ; f1 := f2 ; f2 := newNum ; execute ((newNum) : fibList) ; count := count + 1) ; for i : Integer.subrange(1, n + 1-1) do ( if ((fibList)->includes(i)) then ( name := name + "O" ) else ( name := name + "o" )) ; execute (name)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNthRoot(x,n): x=float(x) n=int(n) if(x>=0 and x<=1): low=x high=1 else : low=1 high=x epsilon=0.00000001 guess=(low+high)/2 while abs(guess**n-x)>=epsilon : if guess**n>x : high=guess else : low=guess guess=(low+high)/2 print(guess) x=5 n=2 findNthRoot(x,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := 5 ; n := 2 ; findNthRoot(x, n); operation findNthRoot(x : OclAny, n : OclAny) pre: true post: true activity: x := ("" + ((x)))->toReal() ; n := ("" + ((n)))->toInteger() ; if (x >= 0 & x <= 1) then ( var low : OclAny := x ; var high : int := 1 ) else ( low := 1 ; high := x ) ; var epsilon : double := 0.00000001 ; var guess : double := (low + high) / 2 ; while (((guess)->pow(n) - x)->abs()->compareTo(epsilon)) >= 0 do ( if ((guess)->pow(n)->compareTo(x)) > 0 then ( high := guess ) else ( low := guess ) ; guess := (low + high) / 2) ; execute (guess)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printStrings(s,l,m): c=set() s=s+s for i in range(l): c.add(s[i : i+m]) for i in c : print(i,end=" ") if __name__=="__main__" : string="saurav" N=len(string) M=4 printStrings(string,N,M) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var string : String := "saurav" ; var N : int := (string)->size() ; var M : int := 4 ; printStrings(string, N, M) ) else skip; operation printStrings(s : OclAny, l : OclAny, m : OclAny) pre: true post: true activity: var c : Set := Set{}->union(()) ; s := s + s ; for i : Integer.subrange(0, l-1) do ( execute ((s.subrange(i+1, i + m)) : c)) ; for i : c do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binarySearch(arr,l,r,x): if r>=l : mid=l+(r-l)//2 if arr[mid]==x : return mid elif arr[mid]>x : return binarySearch(arr,l,mid-1,x) else : return binarySearch(arr,mid+1,r,x) else : return-1 arr=[2,3,4,10,40] x=10 result=binarySearch(arr,0,len(arr)-1,x) if result!=-1 : print("Element is present at index % d" % result) else : print("Element is not present in array") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{10}->union(Sequence{ 40 })))) ; x := 10 ; var result : OclAny := binarySearch(arr, 0, (arr)->size() - 1, x) ; if result /= -1 then ( execute (StringLib.format("Element is present at index % d",result))->display() ) else ( execute ("Element is not present in array")->display() ); operation binarySearch(arr : OclAny, l : OclAny, r : OclAny, x : OclAny) : OclAny pre: true post: true activity: if (r->compareTo(l)) >= 0 then ( var mid : OclAny := l + (r - l) div 2 ; if arr[mid+1] = x then ( return mid ) else (if (arr[mid+1]->compareTo(x)) > 0 then ( return binarySearch(arr, l, mid - 1, x) ) else ( return binarySearch(arr, mid + 1, r, x) ) ) ) else ( return -1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binarySearch(arr,l,r,x): while l<=r : mid=l+(r-l)//2 ; if arr[mid]==x : return mid elif arr[mid]union(Sequence{3}->union(Sequence{4}->union(Sequence{10}->union(Sequence{ 40 })))) ; x := 10 ; var result : OclAny := binarySearch(arr, 0, (arr)->size() - 1, x) ; if result /= -1 then ( execute (StringLib.format("Element is present at index % d",result))->display() ) else ( execute ("Element is not present in array")->display() ); operation binarySearch(arr : OclAny, l : OclAny, r : OclAny, x : OclAny) : OclAny pre: true post: true activity: while (l->compareTo(r)) <= 0 do ( var mid : OclAny := l + (r - l) div 2; ; if arr[mid+1] = x then ( return mid ) else (if (arr[mid+1]->compareTo(x)) < 0 then ( l := mid + 1 ) else ( r := mid - 1 ) ) ) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,sys,io,math from tokenize import Triple from array import array from math import* I=lambda :[*map(int,sys.stdin.readline().split())] IS=lambda : input() IN=lambda : int(input()) IF=lambda : float(input()) n=IN() if n<0 : if n>=-8 : print(8+abs(n)) elif n>-10 and n<-8 : print(abs(n)-8) else : c=1 n+=1 for i in range(10): if '8' in str(abs(n)): print(c) break else : c+=1 n+=1 else : c=1 n+=1 for i in range(10): if '8' in str(n): print(c) break else : c+=1 n+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var I : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var IS : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var IN : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var IF : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toReal()) ; var n : OclAny := IN->apply() ; if n < 0 then ( if n >= -8 then ( execute (8 + (n)->abs())->display() ) else (if n > -10 & n < -8 then ( execute ((n)->abs() - 8)->display() ) else ( var c : int := 1 ; n := n + 1 ; for i : Integer.subrange(0, 10-1) do ( if (("" + (((n)->abs()))))->includes('8') then ( execute (c)->display() ; break ) else ( c := c + 1 ; n := n + 1 )) ) ) ) else ( c := 1 ; n := n + 1 ; for i : Integer.subrange(0, 10-1) do ( if (("" + ((n))))->includes('8') then ( execute (c)->display() ; break ) else ( c := c + 1 ; n := n + 1 )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=0 s='' for i in range(n+1,n+21): s=str(i) for j in s : if j=='8' : ans=i-n print(ans) exit() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; var s : String := '' ; for i : Integer.subrange(n + 1, n + 21-1) do ( s := ("" + ((i))) ; for j : s->characters() do ( if j = '8' then ( ans := i - n ; execute (ans)->display() ; exit() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(k)for k in input().split()] b=[int(k)for k in input().split()] res=0 x=1 q=set(a) if(1 in b)and b[b.index(1):]==list(range(1,b[-1]+1)): eta=b[-1] res=0 for j in b : if eta==n : print(res) break if eta+1 not in q : q=set(a) res=0 for l in b : if x not in q : res+=1 else : x+=1 q.add(l) print(n+res) break q.add(j) res+=1 eta+=1 else : for j in b : if x not in q : res+=1 else : x+=1 q.add(j) print(n+res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger())) ; var b : Sequence := input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger())) ; var res : int := 0 ; var x : int := 1 ; var q : Set := Set{}->union((a)) ; if ((b)->includes(1)) & b.subrange(b->indexOf(1) - 1+1) = (Integer.subrange(1, b->last() + 1-1)) then ( var eta : OclAny := b->last() ; res := 0 ; for j : b do ( if eta = n then ( execute (res)->display() ; break ) else skip ; if (q)->excludes(eta + 1) then ( q := Set{}->union((a)) ; res := 0 ; for l : b do ( if (q)->excludes(x) then ( res := res + 1 ) else ( x := x + 1 ) ; execute ((l) : q)) ; execute (n + res)->display() ; break ) else skip ; execute ((j) : q) ; res := res + 1 ; eta := eta + 1) ) else ( for j : b do ( if (q)->excludes(x) then ( res := res + 1 ) else ( x := x + 1 ) ; execute ((j) : q)) ; execute (n + res)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) a+=1 counter=1 while "8" not in str(a): a+=1 counter+=1 print(counter) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := a + 1 ; var counter : int := 1 ; while (("" + ((a))))->excludes("8") do ( a := a + 1 ; counter := counter + 1) ; execute (counter)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import bisect import heapq from bisect import bisect_right from sys import stdin,stdout def get_ints_in_variables(): return map(int,sys.stdin.readline().strip().split()) def get_int(): return int(sys.stdin.readline()) def get_ints_in_list(): return list(map(int,sys.stdin.readline().strip().split())) def get_list_of_list(n): return[list(map(int,sys.stdin.readline().strip().split()))for _ in range(n)] def get_string(): return sys.stdin.readline().strip() def myceil(x,y): return(x+y-1)//y def Solution(): s=[c for c in get_string()] n=get_int() arr=[get_string()for _ in range(n)] ans=0 for v in arr : a,b=0,0 tmpAns=0 for c in s : if c==v[0]: a+=1 elif c==v[1]: b+=1 else : tmpAns+=min(a,b) a,b=0,0 ans+=min(a,b)+tmpAns print(ans) def main(): Solution() if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation get_ints_in_variables() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ); operation get_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation get_ints_in_list() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation get_list_of_list(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )))); operation get_string() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation myceil(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return (x + y - 1) div y; operation Solution() pre: true post: true activity: var s : Sequence := get_string()->select(c | true)->collect(c | (c)) ; n := get_int() ; var arr : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (get_string())) ; var ans : int := 0 ; for v : arr do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{0,0} ; var tmpAns : int := 0 ; for c : s do ( if c = v->first() then ( a := a + 1 ) else (if c = v[1+1] then ( b := b + 1 ) else ( tmpAns := tmpAns + Set{a, b}->min() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{0,0} ) ) ) ; ans := ans + Set{a, b}->min() + tmpAns) ; execute (ans)->display(); operation main() pre: true post: true activity: Solution(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) c=0 while(True): c+=1 n+=1 n=str(n) if("8" in n): break n=int(n) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := 0 ; while (true) do ( c := c + 1 ; n := n + 1 ; n := ("" + ((n))) ; if ((n)->includes("8")) then ( break ) else skip ; n := ("" + ((n)))->toInteger()) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) c=0 while True : n+=1 c+=1 if '8' in str(n): print(c); break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := 0 ; while true do ( n := n + 1 ; c := c + 1 ; if (("" + ((n))))->includes('8') then ( execute (c)->display(); break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin as input_file from sys import stdout as output_file from math import pi,sqrt num_segments=1000000 def readline(file): return file.readline().rstrip('\n') def hit_probability(fly_radius,racquet_outer_radius,racquet_thickness,string_radius,string_gap): racquet_thickness+=fly_radius string_radius+=fly_radius string_gap-=2*fly_radius if string_gap<=0.0 : probability=1.0 else : hit_area=0.0 delta=racquet_outer_radius/num_segments string_diameter=2*string_radius unit=string_diameter+string_gap lower=string_radius upper=string_radius+string_gap outer_square=racquet_outer_radius**2 inner_square=(racquet_outer_radius-racquet_thickness)**2 for i in xrange(num_segments): x=(i+0.5)/num_segments*racquet_outer_radius x_square=x*x difference=inner_square-x_square x_div,x_mod=divmod(x,unit) hit_length=sqrt(outer_square-x_square) if(difference>0)and(x_mod>lower)and(x_modtoInteger() ; for case_num : xrange(num_cases) do ( var entries : OclAny := readline(input_file).split() ; fly_radius := ("" + ((entries->first())))->toReal() ; racquet_outer_radius := ("" + ((entries[1+1])))->toReal() ; racquet_thickness := ("" + ((entries[2+1])))->toReal() ; string_radius := ("" + ((entries[3+1])))->toReal() ; string_gap := ("" + ((entries[4+1])))->toReal() ; probability := hit_probability(fly_radius, racquet_outer_radius, racquet_thickness, string_radius, string_gap) ; output_file.write(StringLib.format('Case #%d: %f ',Sequence{case_num + 1, probability}))); operation readline(file : OclAny) : OclAny pre: true post: true activity: return file.readLine().rstrip(' '); operation hit_probability(fly_radius : OclAny, racquet_outer_radius : OclAny, racquet_thickness : OclAny, string_radius : OclAny, string_gap : OclAny) : OclAny pre: true post: true activity: racquet_thickness := racquet_thickness + fly_radius ; string_radius := string_radius + fly_radius ; string_gap := string_gap - 2 * fly_radius ; if string_gap <= 0.0 then ( var probability : double := 1.0 ) else ( var hit_area : double := 0.0 ; var delta : double := racquet_outer_radius / num_segments ; var string_diameter : double := 2 * string_radius ; var unit : OclAny := string_diameter + string_gap ; var lower : OclAny := string_radius ; var upper : OclAny := string_radius + string_gap ; var outer_square : double := (racquet_outer_radius)->pow(2) ; var inner_square : double := ((racquet_outer_radius - racquet_thickness))->pow(2) ; for i : xrange(num_segments) do ( var x : double := (i + 0.5) / num_segments * racquet_outer_radius ; var x_square : double := x * x ; var difference : double := inner_square - x_square ; var x_div : OclAny := null; var x_mod : OclAny := null; Sequence{x_div,x_mod} := Sequence{(x div unit), (x mod unit)} ; var hit_length : OclAny := sqrt(outer_square - x_square) ; if (difference > 0) & ((x_mod->compareTo(lower)) > 0) & ((x_mod->compareTo(upper)) < 0) then ( var sqrt_difference : OclAny := sqrt(difference) ; hit_length := hit_length - sqrt_difference ; var y_div : OclAny := null; var y_mod : OclAny := null; Sequence{y_div,y_mod} := Sequence{(sqrt_difference div unit), (sqrt_difference mod unit)} ; hit_length := hit_length + y_div * string_diameter ; if (y_mod->compareTo(lower)) < 0 then ( hit_length := hit_length + y_mod ) else (if (y_mod->compareTo(upper)) < 0 then ( hit_length := hit_length + string_radius ) else ( hit_length := hit_length + y_mod - string_gap ) ) ) else skip ; hit_area := hit_area + hit_length * delta) ; probability := hit_area / (pi / 4 * (racquet_outer_radius)->pow(2)) ) ; return probability; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,heapq,queue from collections import deque from functools import cmp_to_key fast_input=sys.stdin.readline k,d,t=map(int,fast_input().split()) c=math.ceil(k/d)*d r=c-k one_round=k+r/2 req=math.floor((t/one_round)) rem=t-req*one_round if rem<=k : print(rem+req*(r+k)) else : rem-=k print(k+rem*2+req*(r+k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var fast_input : OclAny := (OclFile["System.in"]).readline ; var k : OclAny := null; var d : OclAny := null; var t : OclAny := null; Sequence{k,d,t} := (fast_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : double := (k / d)->ceil() * d ; var r : double := c - k ; var one_round : OclAny := k + r / 2 ; var req : double := ((t / one_round))->floor() ; var rem : double := t - req * one_round ; if (rem->compareTo(k)) <= 0 then ( execute (rem + req * (r + k))->display() ) else ( rem := rem - k ; execute (k + rem * 2 + req * (r + k))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k,d,t=map(int,input().split()) d=((k+d-1)//d)*d n=2*t//(d+k) x=2*t %(d+k) if(x<=2*k): ans=x/2+d*n else : ans=x-k+d*n print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : OclAny := null; var d : OclAny := null; var t : OclAny := null; Sequence{k,d,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : double := ((k + d - 1) div d) * d ; var n : int := 2 * t div (d + k) ; var x : int := 2 * t mod (d + k) ; if ((x->compareTo(2 * k)) <= 0) then ( var ans : double := x / 2 + d * n ) else ( ans := x - k + d * n ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k,d,t=map(int,input().split()) t*=2 l,r=0,4*10**18+1 for i in range(200): m=(l+r)/2 x=((k-1)//d+1)*d p=min(k,m % x) if t<=m+m//x*k+p : r=m else : l=m print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : OclAny := null; var d : OclAny := null; var t : OclAny := null; Sequence{k,d,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; t := t * 2 ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,4 * (10)->pow(18) + 1} ; for i : Integer.subrange(0, 200-1) do ( var m : double := (l + r) / 2 ; var x : double := ((k - 1) div d + 1) * d ; var p : OclAny := Set{k, m mod x}->min() ; if (t->compareTo(m + m div x * k + p)) <= 0 then ( var r : OclAny := m ) else ( var l : OclAny := m )) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil def f(k,d,t): hi=10**18 lo=0 d=ceil(k/d)*d res=(k % d)/(2*t) rr=k % d if k=0 : ans=min(ans,(mid*k)+(mid*(rr))+rem) hi=mid-1 if rem2<=rr and rem2>=0 : ans=min(ans,((mid+1)*k)+(mid*(rr))+rem2) hi=mid-1 else : lo=mid+1 return ans k,d,t=map(int,input().strip().split()) print(f(k,d,t)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{k,d,t} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (f(k, d, t))->display(); operation f(k : OclAny, d : OclAny, t : OclAny) : OclAny pre: true post: true activity: var hi : double := (10)->pow(18) ; var lo : int := 0 ; d := ceil(k / d) * d ; var res : double := (k mod d) / (2 * t) ; var rr : int := k mod d ; if (k->compareTo(d)) < 0 then ( res := (d - k) / (2 * t) ; rr := (d - k) ) else skip ; var ans : double := ("" + (("inf")))->toReal() ; while (lo->compareTo(hi)) <= 0 do ( var mid : int := (hi + lo) div 2 ; var rem : double := (1 - (mid * (k / t)) - (mid * res)) * t ; var rem2 : double := (1 - ((mid + 1) * (k / t)) - (mid * res)) * 2 * t ; rem := Set{rem, 0}->max() ; rem2 := Set{rem2, 0}->max() ; if (rem->compareTo(k)) <= 0 & rem >= 0 then ( ans := Set{ans, (mid * k) + (mid * (rr)) + rem}->min() ; hi := mid - 1 ) else skip ; if (rem2->compareTo(rr)) <= 0 & rem2 >= 0 then ( ans := Set{ans, ((mid + 1) * k) + (mid * (rr)) + rem2}->min() ; hi := mid - 1 ) else ( lo := mid + 1 )) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil def f(k,d,t): hi=10**18 lo=0 d=ceil(k/d)*d res=(k % d)/(2*t) rr=k % d if k=0 : ans=min(ans,(mid*k)+(mid*(rr))+rem) hi=mid-1 if rem2<=rr and rem2>=0 : ans=min(ans,((mid+1)*k)+(mid*(rr))+rem2) hi=mid-1 else : lo=mid+1 return ans k,d,t=map(int,input().strip().split()) print(f(k,d,t)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{k,d,t} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (f(k, d, t))->display(); operation f(k : OclAny, d : OclAny, t : OclAny) : OclAny pre: true post: true activity: var hi : double := (10)->pow(18) ; var lo : int := 0 ; d := ceil(k / d) * d ; var res : double := (k mod d) / (2 * t) ; var rr : int := k mod d ; if (k->compareTo(d)) < 0 then ( res := (d - k) / (2 * t) ; rr := (d - k) ) else skip ; var ans : double := ("" + (("inf")))->toReal() ; while (lo->compareTo(hi)) <= 0 do ( var mid : int := (hi + lo) div 2 ; var rem : double := (1 - (mid * (k / t)) - (mid * res)) * t ; var rem2 : double := (1 - ((mid + 1) * (k / t)) - (mid * res)) * 2 * t ; rem := Set{rem, 0}->max() ; rem2 := Set{rem2, 0}->max() ; if (rem->compareTo(k)) <= 0 & rem >= 0 then ( ans := Set{ans, (mid * k) + (mid * (rr)) + rem}->min() ; hi := mid - 1 ) else skip ; if (rem2->compareTo(rr)) <= 0 & rem2 >= 0 then ( ans := Set{ans, ((mid + 1) * k) + (mid * (rr)) + rem2}->min() ; hi := mid - 1 ) else ( lo := mid + 1 )) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def maxNewElements(a,n): __gcd=a[0] mx=a[0] for i in range(1,n): __gcd=gcd(__gcd,a[i]) mx=max(mx,a[i]) total_terms=mx/__gcd return total_terms-n if __name__=="__main__" : a=[4,6,10] n=len(a) print(int(maxNewElements(a,n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( a := Sequence{4}->union(Sequence{6}->union(Sequence{ 10 })) ; n := (a)->size() ; execute (("" + ((maxNewElements(a, n))))->toInteger())->display() ) else skip; operation maxNewElements(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var __gcd : OclAny := a->first() ; var mx : OclAny := a->first() ; for i : Integer.subrange(1, n-1) do ( __gcd := gcd(__gcd, a[i+1]) ; mx := Set{mx, a[i+1]}->max()) ; var total_terms : double := mx / __gcd ; return total_terms - n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=[],[] count,s=0,0 n=int(input()) for i in range(n): l=list(map(int,input().split())) l=l[1 :] if sorted(l,reverse=True)==l or min(l)==max(l): a.append(l[0]) b.append(l[len(l)-1]) else : s+=1 a.sort() b.sort() for end in b : lo,hi,ans=0,len(a)-1,len(a) while lo<=hi : mid=(lo+hi)//2 if a[mid]>end : ans=mid hi=mid-1 else : lo=mid+1 count+=n-ans print(count+s*n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{Sequence{},Sequence{}} ; var count : OclAny := null; var s : OclAny := null; Sequence{count,s} := Sequence{0,0} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := l->tail() ; if l->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) = l or (l)->min() = (l)->max() then ( execute ((l->first()) : a) ; execute ((l[(l)->size() - 1+1]) : b) ) else ( s := s + 1 )) ; a := a->sort() ; b := b->sort() ; for end : b do ( var lo : OclAny := null; var hi : OclAny := null; var ans : OclAny := null; Sequence{lo,hi,ans} := Sequence{0,(a)->size() - 1,(a)->size()} ; while (lo->compareTo(hi)) <= 0 do ( var mid : int := (lo + hi) div 2 ; if (a[mid+1]->compareTo(end)) > 0 then ( var ans : int := mid ; var hi : double := mid - 1 ) else ( var lo : int := mid + 1 )) ; count := count + n - ans) ; execute (count + s * n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from sys import stdin,stdout def get_ints_in_variables(): return map(int,sys.stdin.readline().strip().split()) def get_int(): return int(input()) def get_ints_in_list(): return list(map(int,sys.stdin.readline().strip().split())) def get_list_of_list(n): return[list(map(int,sys.stdin.readline().strip().split()))for _ in range(n)] def get_string(): return sys.stdin.readline().strip() def main(): s=input() k=int(input()) res=0 for _ in range(0,k): fp=input() countFirst=0 countSecond=0 for start in range(0,len(s)): if(s[start]==fp[0]): countFirst+=1 elif(s[start]==fp[1]): countSecond+=1 else : res+=min(countFirst,countSecond) countFirst=0 countSecond=0 if s[len(s)-1]==fp[0]or s[len(s)-1]==fp[1]: res+=min(countFirst,countSecond) print(res) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation get_ints_in_variables() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ); operation get_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation get_ints_in_list() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation get_list_of_list(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )))); operation get_string() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation main() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : int := 0 ; for _anon : Integer.subrange(0, k-1) do ( var fp : String := (OclFile["System.in"]).readLine() ; var countFirst : int := 0 ; var countSecond : int := 0 ; for start : Integer.subrange(0, (s)->size()-1) do ( if (s[start+1] = fp->first()) then ( countFirst := countFirst + 1 ) else (if (s[start+1] = fp[1+1]) then ( countSecond := countSecond + 1 ) else ( res := res + Set{countFirst, countSecond}->min() ; countFirst := 0 ; countSecond := 0 ) ) ) ; if s[(s)->size() - 1+1] = fp->first() or s[(s)->size() - 1+1] = fp[1+1] then ( res := res + Set{countFirst, countSecond}->min() ) else skip) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from typing import List def minimum_operations(n : int,A : List[int],B : List[int])->int : z=[0 for i in range(n+1)] for idx,i in enumerate(B): z[i]=idx+1 def rotate(): maxx=-1 for x in range(1,n+1): maxx=max(maxx,z[x]-x) return maxx+1+n if 1 in B : idx=z[1] k=n-idx+1 if B[-k :]==list(range(1,k+1)): maxx=-1 for x in range(k+1,n+1): if x-k-1toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var b : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute (minimum_operations(n, a, b))->display(); operation minimum_operations(n : int, A : List[OclType["int"]+1], B : List[OclType["int"]+1]) : int pre: true post: true activity: var z : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; for _tuple : Integer.subrange(1, (B)->size())->collect( _indx | Sequence{_indx-1, (B)->at(_indx)} ) do (var _indx : int := 1; var idx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); z[i+1] := idx + 1) ; skip ; if (B)->includes(1) then ( var idx : OclAny := z[1+1] ; var k : double := n - idx + 1 ; if B.subrange(-k+1) = (Integer.subrange(1, k + 1-1)) then ( maxx := -1 ; (compound_stmt for (exprlist (expr (atom (name x)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name k))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (expr (atom (name x))) - (expr (atom (name k)))) - (expr (atom (number (integer 1)))))) < (comparison (expr (atom (name z)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (expr (atom (name idx))) - (expr (atom (number (integer 1))))))))))))))) ; return rotate() ) else ( return rotate() ) ) else ( return rotate() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(s,l): freq=[0 for i in range(26)] for i in range(l): freq[ord(s[i])-ord('a')]+=1 for i in range(26): if(freq[i]>=2): return True return False if __name__=='__main__' : s="geeksforgeeks" l=len(s) if(check(s,l)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( s := "geeksforgeeks" ; l := (s)->size() ; if (check(s, l)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; operation check(s : OclAny, l : OclAny) : OclAny pre: true post: true activity: var freq : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, l-1) do ( freq[(s[i+1])->char2byte() - ('a')->char2byte()+1] := freq[(s[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; for i : Integer.subrange(0, 26-1) do ( if (freq[i+1] >= 2) then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter import math s=input() dic=Counter(s) n_odd=0 for c in dic : if dic[c]& 1 : n_odd+=1 if n_odd>1 : print(0) exit() dic[c]-=1 ans=math.factorial(len(s)//2) for num in dic.values(): ans//=math.factorial(num//2) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var s : String := (OclFile["System.in"]).readLine() ; var dic : OclAny := Counter(s) ; var n_odd : int := 0 ; for c : dic do ( if MathLib.bitwiseAnd(dic[c+1], 1) then ( n_odd := n_odd + 1 ; if n_odd > 1 then ( execute (0)->display() ; exit() ) else skip ; dic[c+1] := dic[c+1] - 1 ) else skip) ; var ans : long := MathLib.factorial((s)->size() div 2) ; for num : dic.values() do ( ans := ans div MathLib.factorial(num div 2)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections from math import* s=input() a=collections.Counter(s) o=0 for x in a : if a[x]& 1 : o+=1 if o>1 : print(0); break a[x]-=1 else : b=factorial(len(s)//2) for x in a.values(): b//=factorial(x//2) print(b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var s : String := (OclFile["System.in"]).readLine() ; var a : OclAny := .Counter(s) ; var o : int := 0 ; (compound_stmt for (exprlist (expr (atom (name x)))) in (testlist (test (logical_test (comparison (expr (atom (name a))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ]))) & (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name o)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name o)))) > (comparison (expr (atom (number (integer 1)))))))) : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))))))))) ; (small_stmt break))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name factorial)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))) // (expr (atom (number (integer 2)))))))))) ))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name x)))) in (testlist (test (logical_test (comparison (expr (atom (name a)) (trailer . (name values) (arguments ( )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)))))))) (assign_part //= (testlist (test (logical_test (comparison (expr (atom (name factorial)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) // (expr (atom (number (integer 2)))))))))) ))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self): self.data=0 self.next=None def push(head_ref,new_data): new_node=Node() new_node.data=new_data new_node.next=head_ref head_ref=new_node return head_ref def printList(head): while(head!=None): print(head.data,end="->") head=head.next def sortlist(arr,N,head): hash=dict() temp=head while(temp!=None): hash[temp.data]=hash.get(temp.data,0)+1 temp=temp.next temp=head for i in range(N): frequency=hash.get(arr[i],0) while(frequency>0): frequency=frequency-1 temp.data=arr[i] temp=temp.next head=None arr=[5,1,3,2,8] N=len(arr) head=push(head,3) head=push(head,2) head=push(head,5) head=push(head,8) head=push(head,5) head=push(head,2) head=push(head,1) sortlist(arr,N,head) print("Sorted List:") printList(head) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : int := 0; attribute next : OclAny := null; operation initialise() : Node pre: true post: true activity: self.data := 0 ; self.next := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; head := null ; arr := Sequence{5}->union(Sequence{1}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 8 })))) ; N := (arr)->size() ; head := push(head, 3) ; head := push(head, 2) ; head := push(head, 5) ; head := push(head, 8) ; head := push(head, 5) ; head := push(head, 2) ; head := push(head, 1) ; sortlist(arr, N, head) ; execute ("Sorted List:")->display() ; printList(head); operation push(head_ref : OclAny, new_data : OclAny) : OclAny pre: true post: true activity: var new_node : Node := (Node.newNode()).initialise() ; new_node.data := new_data ; new_node.next := head_ref ; head_ref := new_node ; return head_ref; operation printList(head : OclAny) pre: true post: true activity: while (head /= null) do ( execute (head.data)->display() ; head := head.next); operation sortlist(arr : OclAny, N : OclAny, head : OclAny) pre: true post: true activity: var hash : Map := (arguments ( )) ; var temp : OclAny := head ; while (temp /= null) do ( hash[temp.data+1] := hash.get(temp.data, 0) + 1 ; temp := temp.next) ; temp := head ; for i : Integer.subrange(0, N-1) do ( var frequency : int := hash.get(arr[i+1], 0) ; while (frequency > 0) do ( frequency := frequency - 1 ; temp.data := arr[i+1] ; temp := temp.next)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys t=int(input()) for i in range(t): n,k=map(int,input().split(' ')) arr=[int(x)for x in input().split(' ')] sum=0 ; for j in range(k): mVal=arr[j] idx=j+k while idxtoInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var sum : int := 0; ; for j : Integer.subrange(0, k-1) do ( var mVal : OclAny := arr[j+1] ; var idx : OclAny := j + k ; while (idx->compareTo(n)) < 0 do ( mVal := Set{mVal, arr[idx+1]}->max() ; idx := idx + k) ; sum := sum + mVal) ; execute (sum)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) l=list(map(int,input().split())) ans=[0]*k for i in range(n): ans[i % k]=max(ans[i % k],l[i]) print(sum(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, k) ; for i : Integer.subrange(0, n-1) do ( ans[i mod k+1] := Set{ans[i mod k+1], l[i+1]}->max()) ; execute ((ans)->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=input() t=int(t) while(t): a=input().split() n=int(a[0]) k=int(a[1]) b=input().split() for i in range(n): b[i]=int(b[i]) ans=0 for i in range(k): d=b[i : : k] d.sort() ans+=d[-1] print(ans) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : String := (OclFile["System.in"]).readLine() ; t := ("" + ((t)))->toInteger() ; while (t) do ( var a : OclAny := input().split() ; var n : int := ("" + ((a->first())))->toInteger() ; var k : int := ("" + ((a[1+1])))->toInteger() ; var b : OclAny := input().split() ; for i : Integer.subrange(0, n-1) do ( b[i+1] := ("" + ((b[i+1])))->toInteger()) ; var ans : int := 0 ; for i : Integer.subrange(0, k-1) do ( var d : OclAny := b(subscript (test (logical_test (comparison (expr (atom (name i)))))) : (sliceop : (test (logical_test (comparison (expr (atom (name k)))))))) ; d := d->sort() ; ans := ans + d->last()) ; execute (ans)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : for t in range(int(input())): n,k=list(map(int,input().split())) arr=[int(x)for x in input().split()] ans=0 for i in range(k): j=i m=arr[i] ind=i while jtoInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var arr : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : int := 0 ; for i : Integer.subrange(0, k-1) do ( var j : OclAny := i ; var m : OclAny := arr[i+1] ; var ind : OclAny := i ; while (j->compareTo(n)) < 0 do ( if (m->compareTo(arr[j+1])) < 0 then ( m := arr[j+1] ; ind := j ) else skip ; j := j + k) ; ans := ans + arr[ind+1] ; var arr[i+1] : OclAny := null; var arr[ind+1] : OclAny := null; Sequence{arr[i+1],arr[ind+1]} := Sequence{arr[ind+1],arr[i+1]}) ; execute (ans)->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math nput=sys.stdin.readline def solve(): n,k=map(int,input().split()) dat=list(map(int,input().split())) ans=[[]for i in range(k)] for i in range(k): for j in range(i,n,k): ans[i].append(dat[j]) sm=0 for i in ans : sm+=max(i) print(sm) for _ in range(int(input())): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var nput : OclAny := (OclFile["System.in"]).readline ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve()); operation solve() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dat : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : Sequence := Integer.subrange(0, k-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, k-1) do ( for j : Integer.subrange(i, n-1)->select( $x | ($x - i) mod k = 0 ) do ((expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name dat)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) )))))) ; var sm : int := 0 ; for i : ans do ( sm := sm + (i)->max()) ; execute (sm)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def findRadius(self,houses,heaters): heaters=sorted(heaters)+[float('inf')] i=r=0 for x in sorted(houses): while x>=sum(heaters[i : i+2])/2.: i+=1 r=max(r,abs(heaters[i]-x)) return r ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation findRadius(houses : OclAny,heaters : OclAny) : OclAny pre: true post: true activity: heaters := heaters->sort()->union(Sequence{ ("" + (('inf')))->toReal() }) ; var i : OclAny := 0; var r : int := 0 ; for x : houses->sort() do ( while (x->compareTo((heaters.subrange(i+1, i + 2))->sum() / 2.)) >= 0 do ( i := i + 1) ; r := Set{r, (heaters[i+1] - x)->abs()}->max()) ; return r; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(n,end=" ") for i in range(1,n): print(i,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n)->display() ; for i : Integer.subrange(1, n-1) do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil from typing import List,Tuple def minimum_operations(n : int,A : List[int],B : List[int])->int : z=[0 for i in range(n+1)] for idx,i in enumerate(B): z[i]=idx+1 def rotate(): maxx=-1 for x in range(1,n+1): maxx=max(maxx,z[x]-x) return maxx+1+n if 1 in B : idx=z[1] k=n-idx+1 if B[-k :]==list(range(1,k+1)): maxx=-1 for x in range(k+1,n+1): if x-k-1toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (minimum_operations(n, a, b))->display(); operation minimum_operations(n : int, A : List[OclType["int"]+1], B : List[OclType["int"]+1]) : int pre: true post: true activity: var z : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; for _tuple : Integer.subrange(1, (B)->size())->collect( _indx | Sequence{_indx-1, (B)->at(_indx)} ) do (var _indx : int := 1; var idx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); z[i+1] := idx + 1) ; skip ; if (B)->includes(1) then ( var idx : OclAny := z[1+1] ; var k : double := n - idx + 1 ; if B.subrange(-k+1) = (Integer.subrange(1, k + 1-1)) then ( maxx := -1 ; (compound_stmt for (exprlist (expr (atom (name x)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name k))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (expr (atom (name x))) - (expr (atom (name k)))) - (expr (atom (number (integer 1)))))) < (comparison (expr (atom (name z)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (expr (atom (name idx))) - (expr (atom (number (integer 1))))))))))))))) ; return rotate() ) else ( return rotate() ) ) else ( return rotate() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==1 : print(1) else : print(n,end=' ') for i in range(1,n): print(i,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (1)->display() ) else ( execute (n)->display() ; for i : Integer.subrange(1, n-1) do ( execute (i)->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=str(n)+' ' for i in range(1,n): s+=str(i)+' ' print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := ("" + ((n))) + ' ' ; for i : Integer.subrange(1, n-1) do ( s := s + ("" + ((i))) + ' ') ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() n=int(input()); print(n,*range(1,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(n,end=' ') if n==1 : quit() for i in range(1,n): print(i,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n)->display() ; if n = 1 then ( quit() ) else skip ; for i : Integer.subrange(1, n-1) do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys T=int(sys.stdin.readline()) def pay(gondola): n=len(gondola) if gondola.count(".")==0 : return 0 if gondola in memo : return memo[gondola] g2=gondola+gondola ans=0.0 for i in range(n): if gondola[i]=='.' : ans+=n+pay(gondola[: i]+"X"+gondola[i+1 :]) else : j=i wait=0 while g2[j]=='X' : wait+=1 j+=1 j %=n ans+=(n-wait)+pay(gondola[: j]+"X"+gondola[j+1 :]) memo[gondola]=ans/n return memo[gondola] for test_case in range(1,T+1): gondola=sys.stdin.readline().strip() memo={} print("Case #{0}:{1}".format(test_case,pay(gondola))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; for test_case : Integer.subrange(1, T + 1-1) do ( gondola := sys.stdin.readLine()->trim() ; var memo : OclAny := Set{} ; execute (StringLib.interpolateStrings("Case #{0}:{1}", Sequence{test_case, pay(gondola)}))->display()); operation pay(gondola : OclAny) : OclAny pre: true post: true activity: var n : int := (gondola)->size() ; if gondola->count(".") = 0 then ( return 0 ) else skip ; if (memo)->includes(gondola) then ( return memo[gondola+1] ) else skip ; var g2 : OclAny := gondola + gondola ; var ans : double := 0.0 ; for i : Integer.subrange(0, n-1) do ( if gondola[i+1] = '.' then ( ans := ans + n + pay(gondola.subrange(1,i) + "X" + gondola.subrange(i + 1+1)) ) else ( var j : OclAny := i ; var wait : int := 0 ; while g2[j+1] = 'X' do ( wait := wait + 1 ; j := j + 1) ; j := j mod n ; ans := ans + (n - wait) + pay(gondola.subrange(1,j) + "X" + gondola.subrange(j + 1+1)) )) ; memo[gondola+1] := ans / n ; return memo[gondola+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reader(inFile): return inFile.readline() from sys import stderr def solver(gonds): n=len(gonds) k=sum([1<>w)& 1)==1 : w=(w+1)% n pay-=1 tot+=(pay+exps[i+(1<size() ; var k : OclAny := (xrange(n)->select(i | gonds[i+1] = "X")->collect(i | (1 * (2->pow(i)))))->sum() ; var exps : Sequence := MatrixLib.elementwiseMult(Sequence{ 0.0 }, (1 * (2->pow(n)))) ; for i : xrange((1 * (2->pow(n))) - 2, -1, -1) do ( if (MathLib.bitwiseAnd(i, k)) = k then ( var tot : int := 0 ; for j : xrange(n) do ( var pay : int := n ; var w : OclAny := j ; while (MathLib.bitwiseAnd((i /(2->pow(w))), 1)) = 1 do ( w := (w + 1) mod n ; pay := pay - 1) ; tot := tot + (pay + exps[i + (1 * (2->pow(w)))+1])) ; exps[i+1] := tot / n ) else skip) ; return exps[k+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def prevPermutation(str): n=len(str)-1 i=n while(i>0 and str[i-1]<=str[i]): i-=1 if(i<=0): return False j=i-1 while(j+1<=n and str[j+1]<=str[i-1]): j+=1 str=list(str) temp=str[i-1] str[i-1]=str[j] str[j]=temp str=''.join(str) str[: :-1] return True,str if __name__=='__main__' : str="4321" b,str=prevPermutation(str) if(b==True): print("Previous permutation is",str) else : print("Previous permutation doesn't exist") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( OclType["String"] := "4321" ; var b : OclAny := null; Sequence{b,OclType["String"]} := prevPermutation(OclType["String"]) ; if (b = true) then ( execute ("Previous permutation is")->display() ) else ( execute ("Previous permutation doesn't exist")->display() ) ) else skip; operation prevPermutation(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var n : double := (OclType["String"])->size() - 1 ; var i : OclAny := n ; while (i > 0 & (("" + ([i - 1+1]))->compareTo(("" + ([i+1])))) <= 0) do ( i := i - 1) ; if (i <= 0) then ( return false ) else skip ; var j : double := i - 1 ; while ((j + 1->compareTo(n)) <= 0 & (("" + ([j + 1+1]))->compareTo(("" + ([i - 1+1])))) <= 0) do ( j := j + 1) ; OclType["String"] := (OclType["String"])->characters() ; var temp : String := ("" + ([i - 1+1])) ; ("" + ([i - 1+1])) := ("" + ([j+1])) ; ("" + ([j+1])) := temp ; OclType["String"] := StringLib.sumStringsWithSeparator((OclType["String"]), '') ; OclType["String"](subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; return true, OclType["String"]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import log2 MAX=100001 dp=[0]*MAX def probability(k,n): ans=0 for i in range(k,n+1): res=dp[n]-dp[i]-dp[n-i]-n ans=ans+pow(2.0,res) return ans def precompute(): for i in range(2,MAX): dp[i]=log2(i)+dp[i-1] if __name__=='__main__' : precompute() print(probability(2,3)) print(probability(3,6)) print(probability(500,1000)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MAX : int := 100001 ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX) ; skip ; skip ; if __name__ = '__main__' then ( precompute() ; execute (probability(2, 3))->display() ; execute (probability(3, 6))->display() ; execute (probability(500, 1000))->display() ) else skip; operation probability(k : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(k, n + 1-1) do ( var res : double := dp[n+1] - dp[i+1] - dp[n - i+1] - n ; ans := ans + (2.0)->pow(res)) ; return ans; operation precompute() pre: true post: true activity: for i : Integer.subrange(2, MAX-1) do ( dp[i+1] := log2(i) + dp[i - 1+1]); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib,itertools def compute(): cond=lambda i :(i % 5!=0)and(not eulerlib.is_prime(i))and((i-1)% find_least_divisible_repunit(i)==0) ans=sum(itertools.islice(filter(cond,itertools.count(7,2)),25)) return str(ans) def find_least_divisible_repunit(n): if n % 2==0 or n % 5==0 : return 0 sum=1 pow=1 k=1 while sum % n!=0 : k+=1 pow=pow*10 % n sum=(sum+pow)% n return k if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var cond : Function := lambda i : OclAny in ((i mod 5 /= 0) & (not(eulerlib.is_prime(i))) & ((i - 1) mod find_least_divisible_repunit(i) = 0)) ; var ans : OclAny := (itertools.islice((itertools->count(7, 2))->select( _x | (cond)->apply(_x) = true ), 25))->sum() ; return ("" + ((ans))); operation find_least_divisible_repunit(n : OclAny) : OclAny pre: true post: true activity: if n mod 2 = 0 or n mod 5 = 0 then ( return 0 ) else skip ; var sum : int := 1 ; var pow : int := 1 ; var k : int := 1 ; while sum mod n /= 0 do ( k := k + 1 ; pow := pow * 10 mod n ; sum := (sum + pow) mod n) ; return k; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find(s1,s2): len__=len(s1) len_1=len(s2) if(len__!=len_1): return False d=[0 for i in range(len__)] d[0]=ord(s2[0])-ord(s1[0]) for i in range(1,len__,1): if(s1[i]>s2[i]): return False else : d[i]=ord(s2[i])-ord(s1[i]) for i in range(len__-1): if(d[i]display() ) else ( execute ("No")->display() ) ) else skip; operation find(s1 : OclAny, s2 : OclAny) : OclAny pre: true post: true activity: var len__ : int := (s1)->size() ; var len var len__ : int := (s1)->size() : int := (s2)->size() ; if (len__ /= len var len__ : int := (s1)->size()) then ( return false ) else skip ; var d : Sequence := Integer.subrange(0, len__-1)->select(i | true)->collect(i | (0)) ; d->first() := (s2->first())->char2byte() - (s1->first())->char2byte() ; for i : Integer.subrange(1, len__-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if ((s1[i+1]->compareTo(s2[i+1])) > 0) then ( return false ) else ( d[i+1] := (s2[i+1])->char2byte() - (s1[i+1])->char2byte() )) ; for i : Integer.subrange(0, len__ - 1-1) do ( if ((d[i+1]->compareTo(d[i + 1+1])) < 0) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def multiply(a,n): if n==0 : return(a[n]) else : return(a[n]*multiply(a,n-1)) array=[1,2,3,4,5,6] n=len(array) print(multiply(array,n-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var array : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))))) ; n := (array)->size() ; execute (multiply(array, n - 1))->display(); operation multiply(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( return (a[n+1]) ) else ( return (a[n+1] * multiply(a, n - 1)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solution(arr,x): arr.sort(); closestSum=sys.maxsize ; for i in range(len(arr)-2): ptr1=i+1 ; ptr2=len(arr)-1 ; while(ptr1x): ptr2-=1 ; else : ptr1+=1 ; return closestSum ; if __name__=="__main__" : arr=[-1,2,1,-4]; x=1 ; print(solution(arr,x)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{-1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{ -4 }))); ; x := 1; ; execute (solution(arr, x))->display(); ) else skip; operation solution(arr : OclAny, x : OclAny) pre: true post: true activity: arr := arr->sort(); ; var closestSum : (trailer . (name maxsize)) := (trailer . (name maxsize)); ; for i : Integer.subrange(0, (arr)->size() - 2-1) do ( var ptr1 : OclAny := i + 1; var ptr2 : double := (arr)->size() - 1; ; while ((ptr1->compareTo(ptr2)) < 0) do ( var sum : OclAny := arr[i+1] + arr[ptr1+1] + arr[ptr2+1]; ; if (((x - sum)->abs()->compareTo((x - closestSum)->abs())) < 0) then ( closestSum := sum; ) else skip ; if ((sum->compareTo(x)) > 0) then ( ptr2 := ptr2 - 1; ) else ( ptr1 := ptr1 + 1; ))) ; return closestSum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input("").split("")) w=[] for i in range(n): w.append(int(input(""))) s=sum(w) m=max(w) while s>m : a=0 b=0 tmp=int((s+m)/2) for i in w : a+=i if a>tmp : a=i b+=1 if b>=k : m=tmp+1 else : s=tmp print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input("").split(""))->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine(""))))->toInteger()) : w)) ; var s : OclAny := (w)->sum() ; var m : OclAny := (w)->max() ; while (s->compareTo(m)) > 0 do ( var a : int := 0 ; var b : int := 0 ; var tmp : int := ("" + (((s + m) / 2)))->toInteger() ; for i : w do ( a := a + i ; if (a->compareTo(tmp)) > 0 then ( a := i ; b := b + 1 ) else skip) ; if (b->compareTo(k)) >= 0 then ( m := tmp + 1 ) else ( s := tmp )) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def min_sufficient_load(w,k): return check(w,k,0,sum(w)) def check(w,k,p1,p2): if k==1 : return p2 if p2-p1==1 : if get_trunk_No(w,p1)==k : return max(p1,max(w)) else : return max(p2,max(w)) m=math.ceil((p1+p2)/2) trunk_no=get_trunk_No(w,m) if trunk_no>k : return check(w,k,m,p2) else : return check(w,k,p1,m) def get_trunk_No(w,m): temp=0 trunk_no=1 for i in w : if temp+i<=m : temp+=i if temp==m : trunk_no+=1 temp=0 else : trunk_no+=1 temp=i if temp==0 : trunk_no-=1 return trunk_no if __name__=="__main__" : n,k=map(int,input().split(" ")) w=[] for i in range(n): w.append(int(input())) print(min_sufficient_load(w,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( var n : OclAny := null; Sequence{n,k} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; w := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : w)) ; execute (min_sufficient_load(w, k))->display() ) else skip; operation min_sufficient_load(w : OclAny, k : OclAny) : OclAny pre: true post: true activity: return check(w, k, 0, (w)->sum()); operation check(w : OclAny, k : OclAny, p1 : OclAny, p2 : OclAny) : OclAny pre: true post: true activity: if k = 1 then ( return p2 ) else skip ; if p2 - p1 = 1 then ( if get_trunk_No(w, p1) = k then ( return Set{p1, (w)->max()}->max() ) else ( return Set{p2, (w)->max()}->max() ) ) else skip ; var m : double := ((p1 + p2) / 2)->ceil() ; var trunk_no : OclAny := get_trunk_No(w, m) ; if (trunk_no->compareTo(k)) > 0 then ( return check(w, k, m, p2) ) else ( return check(w, k, p1, m) ); operation get_trunk_No(w : OclAny, m : OclAny) : OclAny pre: true post: true activity: var temp : int := 0 ; trunk_no := 1 ; for i : w do ( if (temp + i->compareTo(m)) <= 0 then ( temp := temp + i ; if temp = m then ( trunk_no := trunk_no + 1 ; temp := 0 ) else skip ) else ( trunk_no := trunk_no + 1 ; temp := i )) ; if temp = 0 then ( trunk_no := trunk_no - 1 ) else skip ; return trunk_no; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(P): i=0 for k in range(K): current_weight=0 while current_weight+W[i]<=P : current_weight+=W[i] i+=1 if i==N : return N return i def solve_binary(): left=0 right=max(W) right=100000*10000 while(right-left)>1 : mid=(left+right)//2 mid_v=f(mid) if mid_v>=N : right=mid elif mid_vcollect( _x | (OclType["int"])->apply(_x) ) ; var W : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; execute (solve_binary())->display(); operation f(P : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; for k : Integer.subrange(0, K-1) do ( var current_weight : int := 0 ; while (current_weight + W[i+1]->compareTo(P)) <= 0 do ( current_weight := current_weight + W[i+1] ; i := i + 1 ; if i = N then ( return N ) else skip)) ; return i; operation solve_binary() : OclAny pre: true post: true activity: var left : int := 0 ; var right : OclAny := (W)->max() ; right := 100000 * 10000 ; while (right - left) > 1 do ( var mid : int := (left + right) div 2 ; var mid_v : String := f(mid) ; if mid_v >= N then ( right := mid ) else (if mid_v < N then ( left := mid ) else skip)) ; return right; operation solve_linear() : OclAny pre: true post: true activity: var p : int := 1 ; while true do ( var v : String := f(p) ; if v = N then ( return p ) else skip ; p := p + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cal(truck_num,cargos): p=0 for i in range(len(cargos)-truck_num+1): if not i==0 and p1 : r=max(sum(cargos[: i+1]),cal(truck_num-1,cargos[i+1 :])) if i==0 : p=r elif p>r : p=r else : return sum(cargos) return p def check(truck_num,carogs,target_load): cur_truck=1 cur_weight=0 for weight in cargos : cur_weight+=weight if cur_weight>target_load : cur_weight=weight cur_truck+=1 if cur_truck>truck_num : return False return True def solve(truck_num,cargs): max_load=sum(cargos) min_load=max(cargos) while min_loadtoInteger() ; var line_num : int := ("" + ((line.split(" ")->first())))->toInteger() ; cargos := Integer.subrange(0, line_num-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; execute (solve(truck_num, cargos))->display() ) else skip; operation cal(truck_num : OclAny, cargos : OclAny) : OclAny pre: true post: true activity: var p : int := 0 ; for i : Integer.subrange(0, (cargos)->size() - truck_num + 1-1) do ( if not(i = 0) & (p->compareTo((cargos.subrange(1,i + 1))->sum())) < 0 then ( continue ) else skip ; if truck_num > 1 then ( var r : OclAny := Set{(cargos.subrange(1,i + 1))->sum(), cal(truck_num - 1, cargos.subrange(i + 1+1))}->max() ; if i = 0 then ( p := r ) else (if (p->compareTo(r)) > 0 then ( p := r ) else skip) ) else ( return (cargos)->sum() )) ; return p; operation check(truck_num : OclAny, carogs : OclAny, target_load : OclAny) : OclAny pre: true post: true activity: var cur_truck : int := 1 ; var cur_weight : int := 0 ; for weight : cargos do ( cur_weight := cur_weight + weight ; if (cur_weight->compareTo(target_load)) > 0 then ( cur_weight := weight ; cur_truck := cur_truck + 1 ; if (cur_truck->compareTo(truck_num)) > 0 then ( return false ) else skip ) else skip) ; return true; operation solve(truck_num : OclAny, cargs : OclAny) : OclAny pre: true post: true activity: var max_load : OclAny := (cargos)->sum() ; var min_load : OclAny := (cargos)->max() ; while (min_load->compareTo(max_load)) < 0 do ( target_load := ("" + (((min_load + max_load) / 2)))->toInteger() ; if check(truck_num, cargos, target_load) then ( max_load := target_load ) else ( min_load := target_load + 1 )) ; return max_load; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def can_load(num_baggages,baggages,num_truck,max_load): bag_no=0 for i in range(num_truck): load_cap=max_load while load_cap>0 : if bag_no>=num_baggages : return True if load_cap>=baggages[bag_no]: load_cap-=baggages[bag_no] bag_no+=1 else : break return bag_no>=num_baggages def main(): num_baggages,num_trucks=map(int,input().split()) baggages=[int(input())for x in range(num_baggages)] start=max(sum(baggages)//num_trucks,min(baggages)) end=sum(baggages) while start 0 do ( if (bag_no->compareTo(num_baggages)) >= 0 then ( return true ) else skip ; if (load_cap->compareTo(baggages[bag_no+1])) >= 0 then ( load_cap := load_cap - baggages[bag_no+1] ; bag_no := bag_no + 1 ) else ( break ))) ; return (bag_no->compareTo(num_baggages)) >= 0; operation main() pre: true post: true activity: var num_trucks : OclAny := null; Sequence{num_baggages,num_trucks} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; baggages := Integer.subrange(0, num_baggages-1)->select(x | true)->collect(x | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var start : OclAny := Set{(baggages)->sum() div num_trucks, (baggages)->min()}->max() ; var end : OclAny := (baggages)->sum() ; while (start->compareTo(end)) < 0 do ( var mid : int := (start + end) div 2 ; if can_load(num_baggages, baggages, num_trucks, mid) then ( end := mid ) else ( start := mid + 1 )) ; execute (start)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def minimum_cost(a,n): mn=sys.maxsize sum=0 for i in range(n): mn=min(a[i],mn) sum+=a[i] return mn*(sum-mn) if __name__=="__main__" : a=[4,3,2,5] n=len(a) print(minimum_cost(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( a := Sequence{4}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 5 }))) ; n := (a)->size() ; execute (minimum_cost(a, n))->display() ) else skip; operation minimum_cost(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var mn : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( mn := Set{a[i+1], mn}->min() ; sum := sum + a[i+1]) ; return mn * (sum - mn); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findTransitionPoint(arr,n): lb=0 ub=n-1 while(lb<=ub): mid=(int)((lb+ub)/2) if(arr[mid]==0): lb=mid+1 elif(arr[mid]==1): if(arr[mid-1]==0): return mid ub=mid-1 return-1 arr=[0,0,0,0,1,1] n=len(arr) point=findTransitionPoint(arr,n); if(point>=0): print("Transition point is ",point) else : print("There is no transition point") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 1 }))))) ; n := (arr)->size() ; var point : OclAny := findTransitionPoint(arr, n); ; if (point >= 0) then ( execute ("Transition point is ")->display() ) else ( execute ("There is no transition point")->display() ); operation findTransitionPoint(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var lb : int := 0 ; var ub : double := n - 1 ; while ((lb->compareTo(ub)) <= 0) do ( var mid : OclAny := (OclType["int"])((lb + ub) / 2) ; if (arr[mid+1] = 0) then ( lb := mid + 1 ) else (if (arr[mid+1] = 1) then ( if (arr[mid - 1+1] = 0) then ( return mid ) else skip ; ub := mid - 1 ) else skip)) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline while True : n,m=map(int,input().split()) if n==0 and m==0 : break if n>0 : a=list(map(int,input().split())) if m>0 : b=list(map(int,input().split())) ans=i=j=0 s,t=0,-1 while i=0 : if i=0 : ans=max(ans,t-s) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 & m = 0 then ( break ) else skip ; if n > 0 then ( var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ) else skip ; if m > 0 then ( var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ) else skip ; ans := ans(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name j)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := Sequence{0,-1} ; while (i->compareTo(n)) < 0 or (j->compareTo(m)) < 0 do ( if (i->compareTo(n)) < 0 then ( if s = a[i+1] then ( i := i + 1 ) else skip ; if (i->compareTo(n)) < 0 then ( var t : OclAny := a[i+1] ) else skip ) else skip ; if (j->compareTo(m)) < 0 then ( if s = b[j+1] then ( j := j + 1 ) else skip ; if (j->compareTo(m)) < 0 & (t < 0 or (b[j+1]->compareTo(t)) < 0) then ( t := b[j+1] ) else skip ) else skip ; if t >= 0 then ( if (i->compareTo(n)) < 0 & t = a[i+1] then ( i := i + 1 ) else skip ; if (j->compareTo(m)) < 0 & t = b[j+1] then ( j := j + 1 ) else skip ; var ans : OclAny := Set{ans, t - s}->max() ; var s : OclAny := null; Sequence{s,t} := Sequence{t,-1} ) else skip) ; if t >= 0 then ( ans := Set{ans, t - s}->max() ) else skip ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()); G=range ; t,=R() def f(n,m): b=[v//n for v in a if v>=2*n] return not(m & 1 and all(v==2 for v in b))and sum(b)>=m for _ in G(t): n,m,k=R(); a=[*R()] print(['No','Yes'][f(n,m)or f(m,n)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); var G : OclAny := range;(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := R->apply() ; skip ; for _anon : G(t) do ( var k : OclAny := null; Sequence{n,m,k} := R->apply(); var a : Sequence := R->apply() ; execute (Sequence{'No'}->union(Sequence{ 'Yes' })->select(f(n, m) or f(m, n)))->display()); operation f(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var b : Sequence := a->select(v | (v->compareTo(2 * n)) >= 0)->collect(v | (v div n)) ; return not((MathLib.bitwiseAnd(m, 1) & ((argument (test (logical_test (comparison (comparison (expr (atom (name v)))) == (comparison (expr (atom (number (integer 2)))))))) (comp_for for (exprlist (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name b))))))))->forAll( _x | _x = true ))) & ((b)->sum()->compareTo(m)) >= 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=10**9+7 def main(): N=int(input()) AN=map(int,input().split()) digits_ct=[(0,0)for _ in range(65)] for A in AN : temp=A length=0 for _ in range(65): digit=temp & 0b1 zero,one=digits_ct[length] if digit==0 : digits_ct[length]=(zero+1,one) else : digits_ct[length]=(zero,one+1) temp=temp>>1 length+=1 ans=0 radix=1 for digit_ct in digits_ct : zero,one=digit_ct ans+=(((zero*one)% MOD)*radix)% MOD ans=ans % MOD radix*=2 print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : double := (10)->pow(9) + 7 ; skip ; main(); operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var AN : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var digits_ct : Sequence := Integer.subrange(0, 65-1)->select(_anon | true)->collect(_anon | (Sequence{0, 0})) ; for A : AN do ( var temp : OclAny := A ; var length : int := 0 ; for _anon : Integer.subrange(0, 65-1) do ( var digit : int := MathLib.bitwiseAnd(temp, 0b1) ; var zero : OclAny := null; var one : OclAny := null; Sequence{zero,one} := digits_ct[length+1] ; if digit = 0 then ( digits_ct[length+1] := Sequence{zero + 1, one} ) else ( digits_ct[length+1] := Sequence{zero, one + 1} ) ; temp := temp /(2->pow(1)) ; length := length + 1)) ; var ans : int := 0 ; var radix : int := 1 ; for digit_ct : digits_ct do ( var zero : OclAny := null; var one : OclAny := null; Sequence{zero,one} := digit_ct ; ans := ans + (((zero * one) mod MOD) * radix) mod MOD ; ans := ans mod MOD ; radix := radix * 2) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) dp=[[-1 for i in range(n+1)]for j in range(n+1)] dp[0]=list(map(int,input().split())) for i in range(1,n): for j in range(n-i): dp[i][j]=dp[i-1][j]^ dp[i-1][j+1] for i in range(1,n): for j in range(n-i): dp[i][j]=max(dp[i-1][j],dp[i-1][j+1],dp[i][j]) q=int(input()) for i in range(q): l,r=map(int,input().split()) print(dp[r-l][l-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (-1)))) ; dp->first() := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(1, n-1) do ( for j : Integer.subrange(0, n - i-1) do ( dp[i+1][j+1] := MathLib.bitwiseXor(dp[i - 1+1][j+1], dp[i - 1+1][j + 1+1]))) ; for i : Integer.subrange(1, n-1) do ( for j : Integer.subrange(0, n - i-1) do ( dp[i+1][j+1] := Set{dp[i - 1+1][j+1], dp[i - 1+1][j + 1+1], dp[i+1][j+1]}->max())) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (dp[r - l+1][l - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(sys.stdin.readline()) line=sys.stdin.readline() a=[int(x)for x in line.split()] q=int(sys.stdin.readline()) dp_xor=[a] dp_max=[a] size=n for i in range(n-1): this_dp_xor=[] this_dp_max=[] for j in range(len(dp_xor[i])-1): this_value=dp_xor[i][j]^ dp_xor[i][j+1] this_dp_xor.append(this_value) this_dp_max.append(max((this_value,dp_max[i][j],dp_max[i][j+1]))) dp_xor.append(this_dp_xor) dp_max.append(this_dp_max) for i in range(q): line=sys.stdin.readline() l,r=[int(x)-1 for x in line.split()] this_height=r-l if this_height<1 : sys.stdout.write(str(dp_xor[0][l])+"\n") else : top=dp_xor[this_height][l] left=dp_max[this_height-1][l] right=dp_max[this_height-1][l+1] answer=max((top,left,right)) sys.stdout.write(str(answer)+"\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var line : String := (OclFile["System.in"]).readLine() ; var a : Sequence := line.split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var dp_xor : Sequence := Sequence{ a } ; var dp_max : Sequence := Sequence{ a } ; var size : int := n ; for i : Integer.subrange(0, n - 1-1) do ( var this_dp_xor : Sequence := Sequence{} ; var this_dp_max : Sequence := Sequence{} ; for j : Integer.subrange(0, (dp_xor[i+1])->size() - 1-1) do ( var this_value : int := MathLib.bitwiseXor(dp_xor[i+1][j+1], dp_xor[i+1][j + 1+1]) ; execute ((this_value) : this_dp_xor) ; execute (((Sequence{this_value, dp_max[i+1][j+1], dp_max[i+1][j + 1+1]})->max()) : this_dp_max)) ; execute ((this_dp_xor) : dp_xor) ; execute ((this_dp_max) : dp_max)) ; for i : Integer.subrange(0, q-1) do ( line := (OclFile["System.in"]).readLine() ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := line.split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)) ; var this_height : double := r - l ; if this_height < 1 then ( (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name dp_xor)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name l)))))))) ])))))))) )))) + (expr (atom "\n")))))))) )))) ) else ( var top : OclAny := dp_xor[this_height+1][l+1] ; var left : OclAny := dp_max[this_height - 1+1][l+1] ; var right : OclAny := dp_max[this_height - 1+1][l + 1+1] ; var answer : OclAny := (Sequence{top, left, right})->max() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name answer)))))))) )))) + (expr (atom "\n")))))))) )))) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline N=int(readline()) A=list(map(int,readline().split())) inf=1<<30 dp=[[-inf]*(N+1)for l in range(N)] for l in range(N): r=l+1 dp[l][r]=A[l] for i in range(2,N+1): for l in range(N+1-i): r=l+i dp[l][r]=dp[l+1][r]^ dp[l][r-1] for i in range(2,N+1): for l in range(N+1-i): r=l+i dp[l][r]=max(dp[l][r],dp[l+1][r],dp[l][r-1]) Q=int(readline()) for _ in range(Q): l,r=map(int,readline().split()) l-=1 ans=dp[l][r] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var N : int := ("" + ((readline())))->toInteger() ; var A : Sequence := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var Math_PINFINITY : int := 1 * (2->pow(30)) ; var dp : Sequence := Integer.subrange(0, N-1)->select(l | true)->collect(l | (MatrixLib.elementwiseMult(Sequence{ -Math_PINFINITY }, (N + 1)))) ; for l : Integer.subrange(0, N-1) do ( var r : OclAny := l + 1 ; dp[l+1][r+1] := A[l+1]) ; for i : Integer.subrange(2, N + 1-1) do ( for l : Integer.subrange(0, N + 1 - i-1) do ( r := l + i ; dp[l+1][r+1] := MathLib.bitwiseXor(dp[l + 1+1][r+1], dp[l+1][r - 1+1]))) ; for i : Integer.subrange(2, N + 1-1) do ( for l : Integer.subrange(0, N + 1 - i-1) do ( r := l + i ; dp[l+1][r+1] := Set{dp[l+1][r+1], dp[l + 1+1][r+1], dp[l+1][r - 1+1]}->max())) ; var Q : int := ("" + ((readline())))->toInteger() ; for _anon : Integer.subrange(0, Q-1) do ( var l : OclAny := null; Sequence{l,r} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; l := l - 1 ; var ans : OclAny := dp[l+1][r+1] ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) while T : n,c=input().split() A=list(map(int,input().split())) dicti={} for each in A : if each in dicti : dicti[each]+=1 else : dicti[each]=1 tot_ans=0 for each in dicti : if dicti[each]>=int(c): tot_ans+=int(c) else : tot_ans+=dicti[each] print(tot_ans) T-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while T do ( var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := input().split() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dicti : OclAny := Set{} ; for each : A do ( if (dicti)->includes(each) then ( dicti[each+1] := dicti[each+1] + 1 ) else ( dicti[each+1] := 1 )) ; var tot_ans : int := 0 ; for each : dicti do ( if (dicti[each+1]->compareTo(("" + ((c)))->toInteger())) >= 0 then ( tot_ans := tot_ans + ("" + ((c)))->toInteger() ) else ( tot_ans := tot_ans + dicti[each+1] )) ; execute (tot_ans)->display() ; T := T - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=2 b=2.0 c=2.0003 d='D' print("Integer value is=",a); print("\nFloat value is=",b); print("\nDouble value is=",c); print("\nChar value is=",d); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := 2 ; var b : double := 2.0 ; var c : double := 2.0003 ; var d : String := 'D' ; execute ("Integer value is=")->display(); ; execute ("\nFloat value is=")->display(); ; execute ("\nDouble value is=")->display(); ; execute ("\nChar value is=")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline string=input().strip(); lenth=0 ; count=0 for i in string : if i=="(" : count+=1 else : if count>0 : count-=1 lenth+=2 print(lenth) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; var string : OclAny := input()->trim(); var lenth : int := 0; var count : int := 0 ; for i : string do ( if i = "(" then ( count := count + 1 ) else ( if count > 0 then ( count := count - 1 ; lenth := lenth + 2 ) else skip )) ; execute (lenth)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() n=len(s) lst=[] ct=0 for i in range(n): if(s[i]=='('): lst.append(i) elif(s[i]==')'): if(len(lst)==0): ct+=1 else : lst.pop() ct+=len(lst) print(n-ct) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var n : int := (s)->size() ; var lst : Sequence := Sequence{} ; var ct : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (s[i+1] = '(') then ( execute ((i) : lst) ) else (if (s[i+1] = ')') then ( if ((lst)->size() = 0) then ( ct := ct + 1 ) else ( lst := lst->front() ) ) else skip)) ; ct := ct + (lst)->size() ; execute (n - ct)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() z=0 c=0 for i in s : if i=='(' : z+=1 elif i==')' and z>0 : z-=1 c+=2 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var z : int := 0 ; var c : int := 0 ; for i : s->characters() do ( if i = '(' then ( z := z + 1 ) else (if i = ')' & z > 0 then ( z := z - 1 ; c := c + 2 ) else skip)) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() l,r,ans=0,0,0 for c in s : if c==")" and r>0 : r-=1 ans+=2 elif c=="(" : r+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var l : OclAny := null; var r : OclAny := null; var ans : OclAny := null; Sequence{l,r,ans} := Sequence{0,0,0} ; for c : s->characters() do ( if c = ")" & r > 0 then ( r := r - 1 ; ans := ans + 2 ) else (if c = "(" then ( r := r + 1 ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=[int(x)for x in input().split()] arr=list(map(int,input().split())) arr.sort() time_spent=0 while n>0 : time_spent+=(arr[-1]-1)*2 if len(arr)>k : arr=arr[:-k] n-=k print(time_spent) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := arr->sort() ; var time_spent : int := 0 ; while n > 0 do ( time_spent := time_spent + (arr->last() - 1) * 2 ; if ((arr)->size()->compareTo(k)) > 0 then ( arr := arr.subrange(1,-k) ) else skip ; n := n - k) ; execute (time_spent)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from collections import defaultdict sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod=10**9+7 def I(): return int(input()) def II(): return map(int,input().split()) def III(): return list(map(int,input().split())) def Line(N,num): if N<=0 : return[[]]*num elif num==1 : return[I()for _ in range(N)] else : read_all=[tuple(II())for _ in range(N)] return map(list,zip(*read_all)) N=I() A=III() for i in range(N): A[i]=str(format(A[i],'b')).zfill(60) ans=0 for i in range(60): zc=0 oc=0 for j in range(N): if A[j][59-i]=='0' : zc+=1 else : oc+=1 ans+=2**i*zc*oc ans %=mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; N := I() ; var A : OclAny := III() ; for i : Integer.subrange(0, N-1) do ( A[i+1] := OclType["String"]((A[i+1] + "")).zfill(60)) ; var ans : int := 0 ; for i : Integer.subrange(0, 60-1) do ( var zc : int := 0 ; var oc : int := 0 ; for j : Integer.subrange(0, N-1) do ( if A[j+1][59 - i+1] = '0' then ( zc := zc + 1 ) else ( oc := oc + 1 )) ; ans := ans + (2)->pow(i) * zc * oc ; ans := ans mod mod) ; execute (ans)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation II() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation III() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation Line(N : OclAny, num : OclAny) : OclAny pre: true post: true activity: if N <= 0 then ( return MatrixLib.elementwiseMult(Sequence{ Sequence{} }, num) ) else (if num = 1 then ( return Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (I())) ) else ( var read_all : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | ((II()))) ; return (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name read_all)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name read_all)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name read_all)))))))`third->at(_indx)} ))->collect( _x | (OclType["Sequence"])->apply(_x) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) l=list(map(int,input().split())) if k>=n : l.sort() print((l[-1]-1)*2) else : l.sort() l.reverse() L=[] t=0 for i in l : if len(L)collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (k->compareTo(n)) >= 0 then ( l := l->sort() ; execute ((l->last() - 1) * 2)->display() ) else ( l := l->sort() ; l := l->reverse() ; var L : Sequence := Sequence{} ; var t : int := 0 ; for i : l do ( if ((L)->size()->compareTo(k)) < 0 then ( execute ((i) : L) ) else ( t := t + ((L->first() - 1) * 2) ; L := Sequence{} ; execute ((i) : L) )) ; t := t + (L->first() - 1) * 2 ; execute (t)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) l_p=list(map(int,input().split())) l_p.sort(reverse=True) i=0 t=0 while icollect( _x | (OclType["int"])->apply(_x) ) ; var l_p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l_p := l_p->sort() ; var i : int := 0 ; var t : int := 0 ; while (i->compareTo(n)) < 0 do ( t := t + (l_p[i+1] - 1) * 2 ; i := i + k) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=(int(x)for x in input().split()) print(sum(sorted(int(x)-1 for x in input().split())[: :-k])*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; execute ((sorted((argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) - (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( )))))))))(subscript : (sliceop : (test (logical_test (comparison (expr - (expr (atom (name k))))))))))->sum() * 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findstem(arr): n=len(arr) s=arr[0] l=len(s) res="" for i in range(l): for j in range(i+1,l+1): stem=s[i : j] k=1 for k in range(1,n): if stem not in arr[k]: break if(k+1==n and len(res)union(Sequence{"graceful"}->union(Sequence{"disgraceful"}->union(Sequence{ "gracefully" }))) ; var stems : OclAny := findstem(arr) ; execute (stems)->display() ) else skip; operation findstem(arr : OclAny) : OclAny pre: true post: true activity: var n : int := (arr)->size() ; var s : OclAny := arr->first() ; var l : int := (s)->size() ; var res : String := "" ; for i : Integer.subrange(0, l-1) do ( for j : Integer.subrange(i + 1, l + 1-1) do ( var stem : OclAny := s.subrange(i+1, j) ; var k : int := 1 ; for k : Integer.subrange(1, n-1) do ( if (arr[k+1])->excludes(stem) then ( break ) else skip) ; if (k + 1 = n & ((res)->size()->compareTo((stem)->size())) < 0) then ( res := stem ) else skip)) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n,c=map(int,input().split(' ')) planets=[int(x)for x in input().split(' ')] orbits={} for v in planets : if v in orbits : orbits[v]+=1 else : orbits[v]=1 sum=0 for k,v in orbits.items(): if vtoInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var planets : Sequence := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var orbits : OclAny := Set{} ; for v : planets do ( if (orbits)->includes(v) then ( orbits[v+1] := orbits[v+1] + 1 ) else ( orbits[v+1] := 1 )) ; var sum : int := 0 ; for _tuple : orbits->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if (v->compareTo(c)) < 0 then ( sum := sum + v ) else ( sum := sum + c )) ; execute (sum)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Rank(Edges,Vertices): result=Edges-Vertices+1 return result if __name__=="__main__" : Edges,Vertices=7,5 print("Circuit Rank=",Rank(Edges,Vertices)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{Edges,Vertices} := Sequence{7,5} ; execute ("Circuit Rank=")->display() ) else skip; operation Rank(Edges : OclAny, Vertices : OclAny) : OclAny pre: true post: true activity: var result : double := Edges - Vertices + 1 ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=[] for i in range(1<>j & 1 : ret.append(j) ans.append(' '.join(map(str,ret))) print('\n'.join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, 1 * (2->pow(n))-1) do ( var ret : Sequence := Sequence{} ; execute ((StringLib.format('%d:',i)) : ret) ; for j : Integer.subrange(0, n-1) do ( if MathLib.bitwiseAnd(i /(2->pow(j)), 1) then ( execute ((j) : ret) ) else skip) ; execute ((StringLib.sumStringsWithSeparator(((ret)->collect( _x | (OclType["String"])->apply(_x) )), ' ')) : ans)) ; execute (StringLib.sumStringsWithSeparator((ans), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : bit=int(input()) print(f"0:") for d in range(1,2**bit): print(f"{d}: ",end="") print(" ".join([str(elem)for elem in range(bit)if d &(1<toInteger() ; execute (StringLib.formattedString("0:"))->display() ; for d : Integer.subrange(1, (2)->pow(bit)-1) do ( execute (StringLib.formattedString("{d}: "))->display() ; execute (StringLib.sumStringsWithSeparator((Integer.subrange(0, bit-1)->select(elem | MathLib.bitwiseAnd(d, (1 * (2->pow(elem)))))->collect(elem | (("" + ((elem)))))), " "))->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy BIG_NUM=2000000000 MOD=1000000007 EPS=0.000000001 SIZE=19 POW=[1]*SIZE for i in range(1,SIZE): POW[i]=POW[i-1]*2 N=int(input()) print("0:") index=1 for state in range(1,POW[N]): print("%d:" %(index),end="") for loop in range(N): if state & POW[loop]!=0 : print(" %d" %(loop),end="") print() index+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; var SIZE : int := 19 ; var POW : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, SIZE) ; for i : Integer.subrange(1, SIZE-1) do ( POW[i+1] := POW[i - 1+1] * 2) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ("0:")->display() ; var index : int := 1 ; for state : Integer.subrange(1, POW[N+1]-1) do ( execute (StringLib.format("%d:",(index)))->display() ; for loop : Integer.subrange(0, N-1) do ( if MathLib.bitwiseAnd(state, POW[loop+1]) /= 0 then ( execute (StringLib.format(" %d",(loop)))->display() ) else skip) ; execute (->display() ; index := index + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline write=sys.stdout.write N=int(readline()) write("0:\n") for i in range(1,1<toInteger() ; write("0:\n") ; for i : Integer.subrange(1, 1 * (2->pow(N))-1) do ( write(StringLib.format("%d: %s\n",Sequence{i, StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) ))))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (expr (atom (name i))) & (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name j)))))))) ))))))))))), " ")}))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numchange(boo): if boo : return 1 else : return-1 while True : m,n=map(int,input().split()) if m==0 : break yaxis=1 xaxis=1 rotation=0 while True : lnr=input() if lnr=="STOP" : break elif lnr=="RIGHT" : rotation=(rotation+1)% 4 elif lnr=="LEFT" : rotation=(rotation+3)% 4 else : movequeue=lnr.split() moveamount=int(movequeue[1])*numchange((rotation//2)==0)*numchange(movequeue[0]=="FORWARD") if rotation % 2==0 : yaxis+=moveamount if yaxis<=0 : yaxis=1 elif yaxis>n : yaxis=n else : xaxis+=moveamount if xaxis<=0 : xaxis=1 elif xaxis>m : xaxis=m print(xaxis,yaxis) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if m = 0 then ( break ) else skip ; var yaxis : int := 1 ; var xaxis : int := 1 ; var rotation : int := 0 ; while true do ( var lnr : String := (OclFile["System.in"]).readLine() ; if lnr = "STOP" then ( break ) else (if lnr = "RIGHT" then ( rotation := (rotation + 1) mod 4 ) else (if lnr = "LEFT" then ( rotation := (rotation + 3) mod 4 ) else ( var movequeue : OclAny := lnr.split() ; var moveamount : double := ("" + ((movequeue[1+1])))->toInteger() * numchange((rotation div 2) = 0) * numchange(movequeue->first() = "FORWARD") ; if rotation mod 2 = 0 then ( yaxis := yaxis + moveamount ; if yaxis <= 0 then ( yaxis := 1 ) else (if (yaxis->compareTo(n)) > 0 then ( yaxis := n ) else skip) ) else ( xaxis := xaxis + moveamount ; if xaxis <= 0 then ( xaxis := 1 ) else (if (xaxis->compareTo(m)) > 0 then ( xaxis := m ) else skip) ) ) ) ) ) ; execute (xaxis)->display()); operation numchange(boo : OclAny) : OclAny pre: true post: true activity: if boo then ( return 1 ) else ( return -1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=2**n for i in range(m): temp=[0 for i in range(n)] j=i count=0 while j>0 : if j % 2==1 : temp[count]=1 j//=2 count+=1 temp2=[] for k in range(n): if temp[k]==1 : temp2.append(k) print(i,end="") if i!=0 : print(":",end=" ") print(*temp2) else : print(":") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : double := (2)->pow(n) ; for i : Integer.subrange(0, m-1) do ( var temp : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var j : OclAny := i ; var count : int := 0 ; while j > 0 do ( if j mod 2 = 1 then ( temp[count+1] := 1 ) else skip ; j := j div 2 ; count := count + 1) ; var temp2 : Sequence := Sequence{} ; for k : Integer.subrange(0, n-1) do ( if temp[k+1] = 1 then ( execute ((k) : temp2) ) else skip) ; execute (i)->display() ; if i /= 0 then ( execute (":")->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name temp2))))))))->display() ) else ( execute (":")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(a==0): return b ; if(b==0): return a ; if(a==b): return a ; if(a>b): return gcd(a-b,b); return gcd(a,b-a); def LCM(x,y,z): ans=((x*y)/(gcd(x,y))); return((z*ans)/(gcd(ans,z))); def findDivisible(n,x,y,z): lcm=LCM(x,y,z); largestNDigitNum=int(pow(10,n))-1 ; remainder=largestNDigitNum % lcm ; if(remainder==0): return largestNDigitNum ; largestNDigitNum-=remainder ; if(largestNDigitNum>=int(pow(10,n-1))): return largestNDigitNum ; else : return 0 ; n=2 ; x=3 ; y=4 ; z=6 ; res=int(findDivisible(n,x,y,z)); if(res!=0): print(res); else : print("Not possible"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 2; x := 3; ; y := 4; z := 6; ; var res : int := ("" + ((findDivisible(n, x, y, z))))->toInteger(); ; if (res /= 0) then ( execute (res)->display(); ) else ( execute ("Not possible")->display(); ); operation gcd(a : OclAny, b : OclAny) pre: true post: true activity: if (a = 0) then ( return b; ) else skip ; if (b = 0) then ( return a; ) else skip ; if (a = b) then ( return a; ) else skip ; if ((a->compareTo(b)) > 0) then ( return gcd(a - b, b); ) else skip ; return gcd(a, b - a);; operation LCM(x : OclAny, y : OclAny, z : OclAny) pre: true post: true activity: var ans : double := ((x * y) / (gcd(x, y))); ; return ((z * ans) / (gcd(ans, z)));; operation findDivisible(n : OclAny, x : OclAny, y : OclAny, z : OclAny) pre: true post: true activity: var lcm : OclAny := LCM(x, y, z); ; var largestNDigitNum : double := ("" + (((10)->pow(n))))->toInteger() - 1; ; var remainder : int := largestNDigitNum mod lcm; ; if (remainder = 0) then ( return largestNDigitNum; ) else skip ; largestNDigitNum := largestNDigitNum - remainder; ; if ((largestNDigitNum->compareTo(("" + (((10)->pow(n - 1))))->toInteger())) >= 0) then ( return largestNDigitNum; ) else ( return 0; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculate(a,n): ans=0 ; i=0 ; while(iunion(Sequence{4}->union(Sequence{5}->union(Sequence{3}->union(Sequence{3}->union(Sequence{ 3 }))))); ; n := (a)->size(); ; execute (calculate(a, n))->display();; operation calculate(a : OclAny, n : OclAny) pre: true post: true activity: var ans : int := 0; ; var i : int := 0; ; while ((i->compareTo(n)) < 0) do ( var r : int := i + 1; ; for j : Integer.subrange(r, n-1) do ( if (a[i+1] = a[j+1]) then ( r := r + 1; ) else ( break; )) ; var d : double := r - i; ; ans := ans + (d * (d + 1) / 2); ; i := r - 1; ; i := i + 1;) ; return ("" + ((ans)))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w=int(input()) alst=list(map(int,input().split())) INF=10**20 acc=-INF left=[] for i in range(w): a=alst[i] if a==0 : acc=INF elif a>0 : acc-=1 elif a<0 : acc=min(acc-1,-a) left.append(acc) acc=-INF right=[] for i in range(w): a=alst[w-i-1] if a==0 : acc=INF elif a>0 : acc-=1 elif a<0 : acc=min(acc-1,-a) right.append(acc) right.reverse() print(sum([max(0,min(alst[i],max(left[i],right[i])))for i in range(w)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var alst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var INF : double := (10)->pow(20) ; var acc : OclAny := -INF ; var left : Sequence := Sequence{} ; for i : Integer.subrange(0, w-1) do ( var a : OclAny := alst[i+1] ; if a = 0 then ( acc := INF ) else (if a > 0 then ( acc := acc - 1 ) else (if a < 0 then ( acc := Set{acc - 1, -a}->min() ) else skip ) ) ; execute ((acc) : left)) ; acc := -INF ; var right : Sequence := Sequence{} ; for i : Integer.subrange(0, w-1) do ( a := alst[w - i - 1+1] ; if a = 0 then ( acc := INF ) else (if a > 0 then ( acc := acc - 1 ) else (if a < 0 then ( acc := Set{acc - 1, -a}->min() ) else skip ) ) ; execute ((acc) : right)) ; right := right->reverse() ; execute ((Integer.subrange(0, w-1)->select(i | true)->collect(i | (Set{0, Set{alst[i+1], Set{left[i+1], right[i+1]}->max()}->min()}->max())))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from queue import PriorityQueue class State : def __init__(self,index,time): self.index=index self.time=time def __lt__(self,state): return self.time>state.time while 1 : try : n=int(input()) except : break a=list(map(int,input().split())) ts=[float("inf")]*n vis=[False]*n pq=PriorityQueue() for i in range(n): if a[i]==0 : pq.put(State(i,int(1e9))) while pq.qsize(): cur=pq.get() if cur.index<0 or n<=cur.index or vis[cur.index]or cur.time<0 : continue vis[cur.index]=True if a[cur.index]<0 : cur.time=min(cur.time,-a[cur.index]-1) ts[cur.index]=cur.time pq.put(State(cur.index-1,cur.time-1)) pq.put(State(cur.index+1,cur.time-1)) res=0 for i in range(n): if a[i]>0 and vis[i]: res+=min(a[i],ts[i]+1) print(res) ------------------------------------------------------------ OCL File: --------- class State { static operation newState() : State pre: true post: State->exists( _x | result = _x ); attribute index : OclAny := index; attribute time : OclAny := time; operation initialise(index : OclAny,time : OclAny) : State pre: true post: true activity: self.index := index ; self.time := time; return self; operation __lt__(state : OclAny) : OclAny pre: true post: true activity: return (self.time->compareTo(state.time)) > 0; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while 1 do ( try ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) catch (_e : OclException) do ( break) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ts : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (("inf")))->toReal() }, n) ; var vis : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ; var pq : OclAny := PriorityQueue() ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = 0 then ( pq.put((State.newState()).initialise(i, ("" + ((("1e9")->toReal())))->toInteger())) ) else skip) ; while pq.qsize() do ( var cur : OclAny := pq.get() ; if cur.index < 0 or (n->compareTo(cur.index)) <= 0 or vis[cur.index+1] or cur.time < 0 then ( continue ) else skip ; vis[cur.index+1] := true ; if a[cur.index+1] < 0 then ( cur.time := Set{cur.time, -a[cur.index+1] - 1}->min() ) else skip ; ts[cur.index+1] := cur.time ; pq.put((State.newState()).initialise(cur.index - 1, cur.time - 1)) ; pq.put((State.newState()).initialise(cur.index + 1, cur.time - 1))) ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( if a[i+1] > 0 & vis[i+1] then ( res := res + Set{a[i+1], ts[i+1] + 1}->min() ) else skip) ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import* R=lambda : map(int,input().split()) t,=R() exec(t*'n,c=R();a=Counter(R());print(sum(min(a[x],c)for x in a));') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := R->apply() ; (expr (expr (atom (name t))) * (expr (atom 'n,c=R();a=Counter(R());print(sum(min(a[x],c)for x in a));'))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) ts=[0]*n for indices in range(n),reversed(range(n)): t=0 for i in indices : if a[i]==0 : t=float("inf") if a[i]<0 : t=min(t,-a[i]) if a[i]>0 : ts[i]=max(ts[i],min(a[i],t)) t-=1 print(sum(ts)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ts : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for indices : Integer.subrange(0, n-1), (Integer.subrange(0, n-1))->reverse() do ( var t : int := 0 ; for i : indices do ( if a[i+1] = 0 then ( t := ("" + (("inf")))->toReal() ) else skip ; if a[i+1] < 0 then ( t := Set{t, -a[i+1]}->min() ) else skip ; if a[i+1] > 0 then ( ts[i+1] := Set{ts[i+1], Set{a[i+1], t}->min()}->max() ) else skip ; t := t - 1)) ; execute ((ts)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys f=sys.stdin def calc_limit(a,l,order): INF=1000000 limit=0 for i in range(len(a))[: : order]: if a[i]==0 : limit=INF else : if a[i]<0 : limit=min(-a[i],limit) else : l[i]=max(l[i],limit) limit-=1 _=int(f.readline()) a=list(map(int,f.readline().split())) l=[0]*len(a) calc_limit(a,l,1) calc_limit(a,l,-1) print(sum(min(ai,li)for ai,li in zip(a,l)if ai>0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var f : OclFile := OclFile["System.in"] ; skip ; var _anon : int := ("" + ((f.readLine())))->toInteger() ; a := ((f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := MatrixLib.elementwiseMult(Sequence{ 0 }, (a)->size()) ; calc_limit(a, l, 1) ; calc_limit(a, l, -1) ; execute (((argument (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ai))))))) , (argument (test (logical_test (comparison (expr (atom (name li)))))))) ))))))) (comp_for for (exprlist (expr (atom (name ai))) , (expr (atom (name li)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name l)))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name ai)))) > (comparison (expr (atom (number (integer 0))))))))))))->sum())->display(); operation calc_limit(a : OclAny, l : OclAny, order : OclAny) pre: true post: true activity: var INF : int := 1000000 ; var limit : int := 0 ; for i : range((a)->size())(subscript : (sliceop : (test (logical_test (comparison (expr (atom (name order)))))))) do ( if a[i+1] = 0 then ( limit := INF ) else ( if a[i+1] < 0 then ( limit := Set{-a[i+1], limit}->min() ) else ( l[i+1] := Set{l[i+1], limit}->max() ) ; limit := limit - 1 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printBinStr(string,length): for i in range(0,length): print(string[i],end="") print() def generateBinStr(string,length,currlen,occur,nextbit): if currlen==length : if occur==2 and nextbit==0 : printBinStr(string,length) return if currlen==0 : string[0]=nextbit generateBinStr(string,length,currlen+1,occur,0) generateBinStr(string,length,currlen+1,occur,1) else : if occur<2 : string[currlen]=nextbit if string[currlen-1]==0 and nextbit==1 : occur+=1 generateBinStr(string,length,currlen+1,occur,0) generateBinStr(string,length,currlen+1,occur,1) else : if string[currlen-1]==0 and nextbit==1 : return else : string[currlen]=nextbit generateBinStr(string,length,currlen+1,occur,0) generateBinStr(string,length,currlen+1,occur,1) if __name__=="__main__" : n=5 if n<4 : print(-1) else : string=[None]*n generateBinStr(string,n,0,0,0) generateBinStr(string,n,0,0,1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var n : int := 5 ; if n < 4 then ( execute (-1)->display() ) else ( string := MatrixLib.elementwiseMult(Sequence{ null }, n) ; generateBinStr(string, n, 0, 0, 0) ; generateBinStr(string, n, 0, 0, 1) ) ) else skip; operation printBinStr(string : OclAny, length : OclAny) pre: true post: true activity: for i : Integer.subrange(0, length-1) do ( execute (string[i+1])->display()) ; execute (->display(); operation generateBinStr(string : OclAny, length : OclAny, currlen : OclAny, occur : OclAny, nextbit : OclAny) pre: true post: true activity: if currlen = length then ( if occur = 2 & nextbit = 0 then ( printBinStr(string, length) ) else skip ; return ) else skip ; if currlen = 0 then ( string->first() := nextbit ; generateBinStr(string, length, currlen + 1, occur, 0) ; generateBinStr(string, length, currlen + 1, occur, 1) ) else ( if occur < 2 then ( string[currlen+1] := nextbit ; if string[currlen - 1+1] = 0 & nextbit = 1 then ( occur := occur + 1 ) else skip ; generateBinStr(string, length, currlen + 1, occur, 0) ; generateBinStr(string, length, currlen + 1, occur, 1) ) else ( if string[currlen - 1+1] = 0 & nextbit = 1 then ( return ) else ( string[currlen+1] := nextbit ; generateBinStr(string, length, currlen + 1, occur, 0) ; generateBinStr(string, length, currlen + 1, occur, 1) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np MAX=26 ; def performQueries(string,q,type_arr,ch,freq): n=len(string); L=np.zeros((MAX,n)); F=np.zeros((MAX,n)); cnt=[0]*MAX ; for i in range(n): k=ord(string[i])-ord('a'); cnt[k]+=1 ; for j in range(MAX): if(k==j): L[j][cnt[j]]=i ; F[j][cnt[j]]=i ; else : L[j][cnt[j]]=L[j][cnt[j]]+1 ; for i in range(q): if(type_arr[i]==1): print(L[ord(ch[i])-ord('a')][freq[i]],end=""); else : print(F[ord(ch[i])-ord('a')][freq[i]],end=""); print() if __name__=="__main__" : string="geeksforgeeks" ; type_arr=[1,2]; ch=['e','k']; freq=[2,2]; q=len(type_arr); performQueries(string,q,type_arr,ch,freq); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MAX : int := 26; ; skip ; if __name__ = "__main__" then ( string := "geeksforgeeks"; ; type_arr := Sequence{1}->union(Sequence{ 2 }); ; ch := Sequence{'e'}->union(Sequence{ 'k' }); ; freq := Sequence{2}->union(Sequence{ 2 }); ; q := (type_arr)->size(); ; performQueries(string, q, type_arr, ch, freq); ) else skip; operation performQueries(string : OclAny, q : OclAny, type_arr : OclAny, ch : OclAny, freq : OclAny) pre: true post: true activity: var n : int := (string)->size(); ; var L : Sequence := MatrixLib.singleValueMatrix(Sequence{MAX, n}, 0.0); ; var F : Sequence := MatrixLib.singleValueMatrix(Sequence{MAX, n}, 0.0); ; var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX); ; for i : Integer.subrange(0, n-1) do ( var k : double := (string[i+1])->char2byte() - ('a')->char2byte(); ; cnt[k+1] := cnt[k+1] + 1; ; for j : Integer.subrange(0, MAX-1) do ( if (k = j) then ( L[j+1][cnt[j+1]+1] := i; ; F[j+1][cnt[j+1]+1] := i; ) else ( L[j+1][cnt[j+1]+1] := L[j+1][cnt[j+1]+1] + 1; ))) ; for i : Integer.subrange(0, q-1) do ( if (type_arr[i+1] = 1) then ( execute (L[(ch[i+1])->char2byte() - ('a')->char2byte()+1][freq[i+1]+1])->display(); ) else ( execute (F[(ch[i+1])->char2byte() - ('a')->char2byte()+1][freq[i+1]+1])->display(); ) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): import sys input=sys.stdin.readline n=int(input()) a=list(map(int,input().split())) a.reverse() mod=7+10**9 leng=len(format(max(a),'b')) bit_acc=[0 for i in range(leng)] for i in range(n): bit_data=format(a[i],'b').zfill(leng) for j in range(leng): if bit_data[j]=='1' : bit_acc[j]+=1 p=[pow(2,(leng-j-1),mod)for j in range(leng)] ans=0 for i in range(n): bit_data=format(a[i],'b').zfill(leng) for j in range(leng): if bit_data[j]=='1' : ans+=(n-bit_acc[j])*p[j] else : ans+=bit_acc[j]*p[j] ans %=mod print((ans*500000004)% mod) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->reverse() ; var mod : int := 7 + (10)->pow(9) ; var leng : int := (((a)->max() + ""))->size() ; var bit_acc : Sequence := Integer.subrange(0, leng-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( var bit_data : OclAny := format(a[i+1], 'b').zfill(leng) ; for j : Integer.subrange(0, leng-1) do ( if bit_data[j+1] = '1' then ( bit_acc[j+1] := bit_acc[j+1] + 1 ) else skip)) ; var p : Sequence := Integer.subrange(0, leng-1)->select(j | true)->collect(j | ((2)->pow((leng - j - 1)))) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( bit_data := format(a[i+1], 'b').zfill(leng) ; for j : Integer.subrange(0, leng-1) do ( if bit_data[j+1] = '1' then ( ans := ans + (n - bit_acc[j+1]) * p[j+1] ) else ( ans := ans + bit_acc[j+1] * p[j+1] ) ; ans := ans mod mod)) ; execute ((ans * 500000004) mod mod)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=[] m=n for p in range(2,n+1): if p**2>n or m==1 : break while m % p==0 : m//=p ans.append(p) if m>1 : ans.append(m) print('{}: '.format(n),end='') print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; var m : int := n ; for p : Integer.subrange(2, n + 1-1) do ( if ((p)->pow(2)->compareTo(n)) > 0 or m = 1 then ( break ) else skip ; while m mod p = 0 do ( m := m div p ; execute ((p) : ans))) ; if m > 1 then ( execute ((m) : ans) ) else skip ; execute (StringLib.interpolateStrings('{}: ', Sequence{n}))->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def factoring(n): if n==0 : return{0 : 1} if n==1 : return{1 : 1} nOrigin=n n=n**0.5 numlist=[0 for i in range(int(n)+1)] numlist[0]=-1 numlist[1]=-1 t=2 while t<(n**0.5): if numlist[t]==0 : numlist[t]=t k=2 while t*k<=n : numlist[t*k]=-1 k+=1 t+=1 while t<=n : if numlist[t]==0 : numlist[t]=t t+=1 result={} for i in numlist : if i==-1 : continue j=0 while nOrigin % i==0 : j+=1 nOrigin=nOrigin/i if j==0 : continue else : result[i]=j if int(nOrigin)!=1 : result[int(nOrigin)]=1 return result n=int(input()) print("{0}: ".format(n),end="") factors=[] for i in sorted(factoring(n).items()): for j in range(i[1]): factors.append(str(i[0])) print(" ".join(factors)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (StringLib.interpolateStrings("{0}: ", Sequence{n}))->display() ; var factors : Sequence := Sequence{} ; for i : factoring(n)->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sort() do ( for j : Integer.subrange(0, i[1+1]-1) do ( execute ((("" + ((i->first())))) : factors))) ; execute (StringLib.sumStringsWithSeparator((factors), " "))->display(); operation factoring(n : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( return Map{ 0 |-> 1 } ) else skip ; if n = 1 then ( return Map{ 1 |-> 1 } ) else skip ; var nOrigin : OclAny := n ; n := (n)->pow(0.5) ; var numlist : Sequence := Integer.subrange(0, ("" + ((n)))->toInteger() + 1-1)->select(i | true)->collect(i | (0)) ; numlist->first() := -1 ; numlist[1+1] := -1 ; var t : int := 2 ; while (t->compareTo(((n)->pow(0.5)))) < 0 do ( if numlist[t+1] = 0 then ( numlist[t+1] := t ; var k : int := 2 ; while (t * k->compareTo(n)) <= 0 do ( numlist[t * k+1] := -1 ; k := k + 1) ) else skip ; t := t + 1) ; while (t->compareTo(n)) <= 0 do ( if numlist[t+1] = 0 then ( numlist[t+1] := t ) else skip ; t := t + 1) ; var result : OclAny := Set{} ; for i : numlist do ( if i = -1 then ( continue ) else skip ; var j : int := 0 ; while nOrigin mod i = 0 do ( j := j + 1 ; nOrigin := nOrigin / i) ; if j = 0 then ( continue ) else ( result[i+1] := j )) ; if ("" + ((nOrigin)))->toInteger() /= 1 then ( result[("" + ((nOrigin)))->toInteger()+1] := 1 ) else skip ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def factorize(n): p=n while True : if p % 2==0 : p//=2 yield 2 else : break r=3 while rtoInteger() ; var l : OclAny := factorize(n) ; execute (("" + ((n))) + ":")->display(); operation factorize(n : OclAny) pre: true post: true activity: var p : OclAny := n ; while true do ( if p mod 2 = 0 then ( p := p div 2 ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return 2 ) else ( break )) ; var r : int := 3 ; while (r->compareTo(("" + (((p)->sqrt() + 1)))->toInteger())) < 0 do ( if p mod r = 0 then ( p := p div r ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return r ) else ( r := r + 2 )) ; if p /= 1 then ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return p ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) factors=[] import math sqrt=math.floor(n**0.5) z=n for i in range(2,sqrt+1): if not z % i : while z % i==0 : factors.append(i) z//=i if z>1 : factors.append(z) print('{}:'.format(n),*factors) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var factors : Sequence := Sequence{} ; skip ; var sqrt : double := ((n)->pow(0.5))->floor() ; var z : int := n ; for i : Integer.subrange(2, sqrt + 1-1) do ( if not(z mod i) then ( while z mod i = 0 do ( execute ((i) : factors) ; z := z div i) ) else skip) ; if z > 1 then ( execute ((z) : factors) ) else skip ; execute (StringLib.interpolateStrings('{}:', Sequence{n}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def factorize(n): result=defaultdict(int) m=n p=2 while p*p<=m : while n % p==0 : n=n//p result[p]+=1 p+=1 if n>1 : result[n]+=1 return result n=int(input()) factors=factorize(n) ans='{}:'.format(n) for p,num in factors.items(): ans+='{}'.format(p)*num print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var factors : OclAny := factorize(n) ; var ans : String := StringLib.interpolateStrings('{}:', Sequence{n}) ; for _tuple : factors->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var p : OclAny := _tuple->at(_indx); _indx := _indx + 1; var num : OclAny := _tuple->at(_indx); ans := ans + StringLib.interpolateStrings('{}', Sequence{p}) * num) ; execute (ans)->display(); operation factorize(n : OclAny) : OclAny pre: true post: true activity: var result : OclAny := defaultdict(OclType["int"]) ; var m : OclAny := n ; var p : int := 2 ; while (p * p->compareTo(m)) <= 0 do ( while n mod p = 0 do ( n := n div p ; result[p+1] := result[p+1] + 1) ; p := p + 1) ; if n > 1 then ( result[n+1] := result[n+1] + 1 ) else skip ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isDigitPresent(x,d): while(x>0): if(x % 10==d): break x=x/10 return(x>0) def printNumbers(n,d): for i in range(0,n+1): if(i==d or isDigitPresent(i,d)): print(i,end=" ") n=47 d=7 print("The number of values are") printNumbers(n,d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 47 ; d := 7 ; execute ("The number of values are")->display() ; printNumbers(n, d); operation isDigitPresent(x : OclAny, d : OclAny) : OclAny pre: true post: true activity: while (x > 0) do ( if (x mod 10 = d) then ( break ) else skip ; x := x / 10) ; return (x > 0); operation printNumbers(n : OclAny, d : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n + 1-1) do ( if (i = d or isDigitPresent(i, d)) then ( execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,c=map(int,input().split()) s=list(map(int,input().split())) t=[] i=0 while len(s)!=0 : t.append(s.count(s[i])) s=list(filter((s[i]).__ne__,s)) count=0 for j in range(len(t)): if ctoInteger()-1) do ( var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : Sequence := Sequence{} ; var i : int := 0 ; while (s)->size() /= 0 do ( execute ((s->count(s[i+1])) : t) ; s := ((s)->select( _x | ((s[i+1]).__ne__)->apply(_x) = true ))) ; var count : int := 0 ; for j : Integer.subrange(0, (t)->size()-1) do ( if (c->compareTo(t[j+1])) < 0 then ( count := count + c ) else ( count := count + t[j+1] )) ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findElement(arr,size): right_sum,left_sum=0,0 for i in range(1,size): right_sum+=arr[i] i,j=0,1 while junion(Sequence{3}->union(Sequence{4}->union(Sequence{1}->union(Sequence{4}->union(Sequence{ 5 }))))) ; var n : int := (arr)->size() ; execute (findElement(arr, n))->display() ) else skip; operation findElement(arr : OclAny, size : OclAny) : OclAny pre: true post: true activity: var right_sum : OclAny := null; var left_sum : OclAny := null; Sequence{right_sum,left_sum} := Sequence{0,0} ; for i : Integer.subrange(1, size-1) do ( right_sum := right_sum + arr[i+1]) ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,1} ; while (j->compareTo(size)) < 0 do ( right_sum := right_sum - arr[j+1] ; left_sum := left_sum + arr[i+1] ; if left_sum = right_sum then ( return arr[i + 1+1] ) else skip ; j := j + 1 ; i := i + 1) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=[0,0,*map(int,input().split())] r=[] while n : r.append(n); n=p[n] print(*reversed(r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := Sequence{0}->union(Sequence{0}->union((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var r : Sequence := Sequence{} ; while n do ( execute ((n) : r); n := p[n+1]) ; execute ((argument * (test (logical_test (comparison (expr (atom (name reversed)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name r)))))))) )))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) routerList=list(map(int,input().split())) i=len(routerList)-1 ans=[] ans.append(routerList[i]) while routerList[ans[-1]-2]!=1 and i>=0 : ans.append(routerList[ans[-1]-2]) i=ans[-1]-2 ans.append(1) ans.append(n) ans=list(set(ans)) ans.sort() print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var routerList : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var i : double := (routerList)->size() - 1 ; var ans : Sequence := Sequence{} ; execute ((routerList[i+1]) : ans) ; while routerList[ans->last() - 2+1] /= 1 & i >= 0 do ( execute ((routerList[ans->last() - 2+1]) : ans) ; i := ans->last() - 2) ; execute ((1) : ans) ; execute ((n) : ans) ; ans := (Set{}->union((ans))) ; ans := ans->sort() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np N=int(input()) A=np.fromiter(map(int,input().split()),np.int64) result=0 for b in range(60): bs=int(((A>>b)& 1).sum()) result=(result+bs*(N-bs)*(1<toInteger() ; var A : (trailer . (name fromiter) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name np)) (trailer . (name int64)))))))) ))) := ; var result : int := 0 ; for b : Integer.subrange(0, 60-1) do ( var bs : int := ("" + (((MathLib.bitwiseAnd((A /(2->pow(b))), 1)).sum())))->toInteger() ; result := (result + bs * (N - bs) * (1 * (2->pow(b)))) mod 1000000007) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) tab=list(map(int,input().split(" "))) i=n result=[] result.append(str(i)) while(1): result.append(str(tab[i-2])) i=tab[i-2] if(i==1): break print(" ".join(result[: :-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var tab : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var i : int := n ; var result : Sequence := Sequence{} ; execute ((("" + ((i)))) : result) ; while (1) do ( execute ((("" + ((tab[i - 2+1])))) : result) ; i := tab[i - 2+1] ; if (i = 1) then ( break ) else skip) ; execute (StringLib.sumStringsWithSeparator((result(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=[0,0,*map(int,input().split())] r=[] while n : r.append(n); n=p[n] print(*reversed(r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := Sequence{0}->union(Sequence{0}->union((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var r : Sequence := Sequence{} ; while n do ( execute ((n) : r); n := p[n+1]) ; execute ((argument * (test (logical_test (comparison (expr (atom (name reversed)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name r)))))))) )))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=[0,0,*map(int,input().split())] r=[] while n : r.append(n); n=p[n] print(*reversed(r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := Sequence{0}->union(Sequence{0}->union((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var r : Sequence := Sequence{} ; while n do ( execute ((n) : r); n := p[n+1]) ; execute ((argument * (test (logical_test (comparison (expr (atom (name reversed)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name r)))))))) )))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) aList=list(map(int,input().split())) bList=list(map(int,input().split())) abList=sorted(tuple(zip(aList,bList)),key=lambda x :-x[0]) ans=0 dp=[[0]*(m+1)for _ in range(k+1)] for a,b in abList : for y in range(k-1,-1,-1): for x in range(m-1,-1,-1): use=min(b,m-x) dp[y+1][x+use]=max(dp[y+1][x+use],dp[y][x]+use*a) ans=0 for y in range(k+1): for x in range(m+1): ans=max(ans,dp[y][x]+m-x) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var aList : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var bList : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var abList : Sequence := (Integer.subrange(1, aList->size())->collect( _indx | Sequence{aList->at(_indx), bList->at(_indx)} ))->sortedBy($x | (lambda x : OclAny in (-x->first()))->apply($x)) ; var ans : int := 0 ; var dp : Sequence := Integer.subrange(0, k + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (m + 1)))) ; for _tuple : abList do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); for y : Integer.subrange(-1 + 1, k - 1)->reverse() do ( for x : Integer.subrange(-1 + 1, m - 1)->reverse() do ( var use : OclAny := Set{b, m - x}->min() ; dp[y + 1+1][x + use+1] := Set{dp[y + 1+1][x + use+1], dp[y+1][x+1] + use * a}->max()))) ; ans := 0 ; for y : Integer.subrange(0, k + 1-1) do ( for x : Integer.subrange(0, m + 1-1) do ( ans := Set{ans, dp[y+1][x+1] + m - x}->max())) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=26 def countingsort(s): count=[0 for i in range(MAX)] for i in range(len(s)): count[ord(s[i])-ord('a')]+=1 index=0 for i in range(MAX): j=0 while(junion(Sequence{"oxq"}->union(Sequence{"zoa"}->union(Sequence{"epw"}->union(Sequence{ "amn" })))) ; if (isPossible(v, str1)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation countingsort(s : OclAny) pre: true post: true activity: var count : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, (s)->size()-1) do ( count[(s[i+1])->char2byte() - ('a')->char2byte()+1] := count[(s[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; var index : int := 0 ; for i : Integer.subrange(0, MAX-1) do ( var j : int := 0 ; while ((j->compareTo(count[i+1])) < 0) do ( s := s.replace(s[index+1], (97 + i)->byte2char()) ; index := index + 1 ; j := j + 1)); operation isPossible(v : OclAny, str1 : OclAny) : OclAny pre: true post: true activity: countingsort(str1); ; for i : Integer.subrange(0, (v)->size() - 1-1) do ( for j : Integer.subrange(i + 1, (v)->size()-1)->select( $x | ($x - i + 1) mod 1 = 0 ) do ( var temp : OclAny := v[i+1] + v[j+1] ; countingsort(temp) ; if (temp = str1) then ( return false ) else skip)) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ix=input() d=str(input()) t=[] t=ix.split(' ') x=int(t[0]) sx=int(t[1]) sy=int(t[2]) ex=int(t[3]) ey=int(t[4]) conter=0 bo=True for i in range(0,x): if d[i]=='N' : if ey>sy : sy+=1 elif d[i]=='S' : if ey=0 : sy-=1 elif eysx : sx+=1 elif d[i]=='W' : if ex=0 : sx-=1 elif exfirst())))->toInteger() ; var sx : int := ("" + ((t[1+1])))->toInteger() ; var sy : int := ("" + ((t[2+1])))->toInteger() ; var ex : int := ("" + ((t[3+1])))->toInteger() ; var ey : int := ("" + ((t[4+1])))->toInteger() ; var conter : int := 0 ; var bo : boolean := true ; for i : Integer.subrange(0, x-1) do ( if d[i+1] = 'N' then ( if (ey->compareTo(sy)) > 0 then ( sy := sy + 1 ) else skip ) else (if d[i+1] = 'S' then ( if (ey->compareTo(sy)) < 0 & ey >= 0 then ( sy := sy - 1 ) else (if (ey->compareTo(sy)) < 0 & ey < 0 then ( sy := sy - 1 ) else skip) ) else (if d[i+1] = 'E' then ( if (ex->compareTo(sx)) > 0 then ( sx := sx + 1 ) else skip ) else (if d[i+1] = 'W' then ( if (ex->compareTo(sx)) < 0 & ex >= 0 then ( sx := sx - 1 ) else (if (ex->compareTo(sx)) < 0 & ex < 0 then ( sx := sx - 1 ) else skip) ) else skip ) ) ) ; conter := conter + 1 ; if ex = sx & ey = sy then ( bo := true ; break ) else ( bo := false )) ; if bo then ( execute (conter)->display() ) else ( execute ("-1")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t,sx,sy,ex,ey=map(int,input().split()) s=input() yatay=ex-sx dikey=ey-sy flag=0 if(yatay>=0 and dikey>=0): for i in range(t): if(s[i]=="N" and dikey>0): dikey-=1 if(s[i]=="E" and yatay>0): yatay-=1 if(yatay==0 and dikey==0): print(i+1) flag=1 break elif(yatay<=0 and dikey<=0): for i in range(t): if(s[i]=="S" and dikey<0): dikey+=1 if(s[i]=="W" and yatay<0): yatay+=1 if(yatay==0 and dikey==0): print(i+1) flag=1 break elif(yatay>=0 and dikey<=0): for i in range(t): if(s[i]=="S" and dikey<0): dikey+=1 if(s[i]=="E" and yatay>0): yatay-=1 if(yatay==0 and dikey==0): print(i+1) flag=1 break elif(yatay<=0 and dikey>=0): for i in range(t): if(s[i]=="N" and dikey>0): dikey-=1 if(s[i]=="W" and yatay<0): yatay+=1 if(yatay==0 and dikey==0): print(i+1) flag=1 break if(flag==0): print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := null; var sx : OclAny := null; var sy : OclAny := null; var ex : OclAny := null; var ey : OclAny := null; Sequence{t,sx,sy,ex,ey} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var yatay : double := ex - sx ; var dikey : double := ey - sy ; var flag : int := 0 ; if (yatay >= 0 & dikey >= 0) then ( for i : Integer.subrange(0, t-1) do ( if (s[i+1] = "N" & dikey > 0) then ( dikey := dikey - 1 ) else skip ; if (s[i+1] = "E" & yatay > 0) then ( yatay := yatay - 1 ) else skip ; if (yatay = 0 & dikey = 0) then ( execute (i + 1)->display() ; flag := 1 ; break ) else skip) ) else (if (yatay <= 0 & dikey <= 0) then ( for i : Integer.subrange(0, t-1) do ( if (s[i+1] = "S" & dikey < 0) then ( dikey := dikey + 1 ) else skip ; if (s[i+1] = "W" & yatay < 0) then ( yatay := yatay + 1 ) else skip ; if (yatay = 0 & dikey = 0) then ( execute (i + 1)->display() ; flag := 1 ; break ) else skip) ) else (if (yatay >= 0 & dikey <= 0) then ( for i : Integer.subrange(0, t-1) do ( if (s[i+1] = "S" & dikey < 0) then ( dikey := dikey + 1 ) else skip ; if (s[i+1] = "E" & yatay > 0) then ( yatay := yatay - 1 ) else skip ; if (yatay = 0 & dikey = 0) then ( execute (i + 1)->display() ; flag := 1 ; break ) else skip) ) else (if (yatay <= 0 & dikey >= 0) then ( for i : Integer.subrange(0, t-1) do ( if (s[i+1] = "N" & dikey > 0) then ( dikey := dikey - 1 ) else skip ; if (s[i+1] = "W" & yatay < 0) then ( yatay := yatay + 1 ) else skip ; if (yatay = 0 & dikey = 0) then ( execute (i + 1)->display() ; flag := 1 ; break ) else skip) ) else skip ) ) ) ; if (flag = 0) then ( execute (-1)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): s=0 n,c=map(int,input().split()) a=[int(i)for i in input().split()] b=[0]*101 for el in a : b[el]+=1 for el in b : s+=min(el,c) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var s : int := 0 ; var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 101) ; for el : a do ( b[el+1] := b[el+1] + 1) ; for el : b do ( s := s + Set{el, c}->min()) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- arr=list(map(int,input().split())) dir=input() x1=arr[1] y1=arr[2] x2=arr[3] y2=arr[4] dx=x2-x1 dy=y2-y1 for i,v in enumerate(dir): if v=="S" and dy<0 : dy+=1 elif v=="N" and dy>0 : dy-=1 elif v=="E" and dx>0 : dx-=1 elif v=="W" and dx<0 : dx+=1 if dx==0 and dy==0 : print(i+1) break if dx!=0 or dy!=0 : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dir : String := (OclFile["System.in"]).readLine() ; var x1 : OclAny := arr[1+1] ; var y1 : OclAny := arr[2+1] ; var x2 : OclAny := arr[3+1] ; var y2 : OclAny := arr[4+1] ; var dx : double := x2 - x1 ; var dy : double := y2 - y1 ; for _tuple : Integer.subrange(1, (dir)->size())->collect( _indx | Sequence{_indx-1, (dir)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if v = "S" & dy < 0 then ( dy := dy + 1 ) else (if v = "N" & dy > 0 then ( dy := dy - 1 ) else (if v = "E" & dx > 0 then ( dx := dx - 1 ) else (if v = "W" & dx < 0 then ( dx := dx + 1 ) else skip ) ) ) ; if dx = 0 & dy = 0 then ( execute (i + 1)->display() ; break ) else skip) ; if dx /= 0 or dy /= 0 then ( execute (-1)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def main(): t,sx,sy,ex,ey=list(map(int,input().split(' '))) elems=input() directions={'N' : lambda x,y :(x,y+1),'S' : lambda x,y :(x,y-1),'E' : lambda x,y :(x+1,y),'W' : lambda x,y :(x-1,y)} dist=lambda x,y : sqrt((ex-x)**2+(ey-y)**2) d=dist(sx,sy) count=0 for w in elems : cx,cy=directions[w](sx,sy) new_d=dist(cx,cy) if new_dcollect( _x | (OclType["int"])->apply(_x) )) ; var elems : String := (OclFile["System.in"]).readLine() ; var directions : Map := Map{ 'N' |-> lambda x : OclAny, y : OclAny in (Sequence{x, y + 1}) }->union(Map{ 'S' |-> lambda x : OclAny, y : OclAny in (Sequence{x, y - 1}) }->union(Map{ 'E' |-> lambda x : OclAny, y : OclAny in (Sequence{x + 1, y}) }->union(Map{ 'W' |-> lambda x : OclAny, y : OclAny in (Sequence{x - 1, y}) }))) ; var dist : Function := lambda x : OclAny, y : OclAny in (sqrt(((ex - x))->pow(2) + ((ey - y))->pow(2))) ; var d : OclAny := dist->apply(sx, sy) ; var count : int := 0 ; for w : elems->characters() do ( var cx : OclAny := null; var cy : OclAny := null; Sequence{cx,cy} := directions[w+1](sx, sy) ; var new_d : OclAny := dist->apply(cx, cy) ; if (new_d->compareTo(d)) < 0 then ( var sx : OclAny := null; var sy : OclAny := null; Sequence{sx,sy} := Sequence{cx,cy} ; d := new_d ) else skip ; count := count + 1 ; if sx = ex & sy = ey then ( break ) else skip) ; if sx = ex & sy = ey then ( execute (count)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from collections import defaultdict MOD=pow(10,9)+7 N=int(input()) d=[[N,0]for _ in range(60)] A=list(map(int,input().split())) for k in A : c=0 while k>0 : if k % 2==1 : d[c][0]-=1 d[c][1]+=1 k=k//2 c+=1 s=0 for i in range(60): li=d[i] s+=(li[0]*li[1]*pow(2,i,MOD))% MOD print(s % MOD) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var MOD : double := (10)->pow(9) + 7 ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Sequence := Integer.subrange(0, 60-1)->select(_anon | true)->collect(_anon | (Sequence{N}->union(Sequence{ 0 }))) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for k : A do ( var c : int := 0 ; while k > 0 do ( if k mod 2 = 1 then ( d[c+1]->first() := d[c+1]->first() - 1 ; d[c+1][1+1] := d[c+1][1+1] + 1 ) else skip ; var k : int := k div 2 ; c := c + 1)) ; var s : int := 0 ; for i : Integer.subrange(0, 60-1) do ( var li : OclAny := d[i+1] ; s := s + (li->first() * li[1+1] * (2)->pow(i)) mod MOD) ; execute (s mod MOD)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t,a,b,p,q=map(int,input().split()) st=input() dt={} x=a-p if x>0 : dt['W']=x else : dt['E']=abs(x) y=b-q if y>0 : dt['S']=y else : dt['N']=abs(y) ans=0 x=True for i in dt : for j in range(len(st)): if i==st[j]and dt[i]!=0 : dt[i]-=1 ans=max(ans,j+1) if dt[i]!=0 : x=False print('-1') break if x : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := null; var a : OclAny := null; var b : OclAny := null; var p : OclAny := null; var q : OclAny := null; Sequence{t,a,b,p,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var st : String := (OclFile["System.in"]).readLine() ; var dt : OclAny := Set{} ; var x : double := a - p ; if x > 0 then ( dt->at('W') := x ) else ( dt->at('E') := (x)->abs() ) ; var y : double := b - q ; if y > 0 then ( dt->at('S') := y ) else ( dt->at('N') := (y)->abs() ) ; var ans : int := 0 ; x := true ; for i : dt do ( for j : Integer.subrange(0, (st)->size()-1) do ( if i = st[j+1] & dt[i+1] /= 0 then ( dt[i+1] := dt[i+1] - 1 ; ans := Set{ans, j + 1}->max() ) else skip) ; if dt[i+1] /= 0 then ( x := false ; execute ('-1')->display() ; break ) else skip) ; if x then ( execute (ans)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): if len(set(input())& set(input()))==0 : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( if (MathLib.bitwiseAnd(Set{}->union(((OclFile["System.in"]).readLine())), Set{}->union(((OclFile["System.in"]).readLine()))))->size() = 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): print('NO' if len(set(input())& set(input()))==0 else 'YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (if (MathLib.bitwiseAnd(Set{}->union(((OclFile["System.in"]).readLine())), Set{}->union(((OclFile["System.in"]).readLine()))))->size() = 0 then 'NO' else 'YES' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input for _ in[0]*int(I()): print('YNEOS'[not set(I())& set(I()): : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + ((I())))->toInteger()) do ( execute ('YNEOS'(subscript (test (logical_test not (logical_test (comparison (expr (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name I)) (trailer (arguments ( ))))))))) )))) & (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name I)) (trailer (arguments ( ))))))))) ))))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input().strip()) for i in range(0,n): s1=[x for x in input().strip()] s2=[x for x in input().strip()] flag=False for i in s1 : if i in s2 : flag=True break if flag : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + ((input()->trim())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var s1 : Sequence := input()->trim()->select(x | true)->collect(x | (x)) ; var s2 : Sequence := input()->trim()->select(x | true)->collect(x | (x)) ; var flag : boolean := false ; for i : s1 do ( if (s2)->includes(i) then ( flag := true ; break ) else skip) ; if flag then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): a=input() b=input() bo=True if set(a)==set(b): print('YES') else : for s in set(a): if s not in set(b): bo=False if s in set(b): print('YES') bo=True break if not bo : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var bo : boolean := true ; if Set{}->union((a)) = Set{}->union((b)) then ( execute ('YES')->display() ) else ( for s : Set{}->union((a)) do ( if (Set{}->union((b)))->excludes(s) then ( bo := false ) else skip ; if (Set{}->union((b)))->includes(s) then ( execute ('YES')->display() ; bo := true ; break ) else skip) ) ; if not(bo) then ( execute ('NO')->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- days,sumTime=map(int,input().split(' ')) minTime,maxTime=[],[] for _ in range(days): mTime=tuple(map(int,input().split(' '))) minTime.append(mTime[0]) maxTime.append(mTime[1]) if sum(minTime)<=sumTime<=sum(maxTime): while sum(maxTime)!=sumTime : for i in range(len(maxTime)): if maxTime[i]>minTime[i]: maxTime[i]-=1 if sum(maxTime)==sumTime : break else : print('YES',' '.join([str(i)for i in maxTime]),sep='\n') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var days : OclAny := null; var sumTime : OclAny := null; Sequence{days,sumTime} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var minTime : OclAny := null; var maxTime : OclAny := null; Sequence{minTime,maxTime} := Sequence{Sequence{},Sequence{}} ; for _anon : Integer.subrange(0, days-1) do ( var mTime : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((mTime->first()) : minTime) ; execute ((mTime[1+1]) : maxTime)) ; if ((minTime)->sum()->compareTo(sumTime)) <= 0 & (sumTime <= (maxTime)->sum()) then ( (compound_stmt while (test (logical_test (comparison (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name maxTime)))))))) ))))) != (comparison (expr (atom (name sumTime))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name maxTime)))))))) ))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name maxTime)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) > (comparison (expr (atom (name minTime)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name maxTime)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name maxTime)))))))) ))))) == (comparison (expr (atom (name sumTime))))))) : (suite (stmt (simple_stmt (small_stmt break)))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES')))))) , (argument (test (logical_test (comparison (expr (atom ' ') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name maxTime))))))) ]))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name sep)))))) = (test (logical_test (comparison (expr (atom ' '))))))) ))))))))))))))) ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d,s=map(int,input().split()) a=[[*map(int,input().split())]for _ in[0]*d] b,c=sum(x[0]for x in a),sum(x[1]for x in a) if b<=s<=c : print('YES') v=s-b r=[] for x,y in a : if v>0 : l=min(v,y-x) v-=l x+=l r+=[x] print(*r) else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : OclAny := null; var s : OclAny := null; Sequence{d,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, d)->select(_anon | true)->collect(_anon | ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := Sequence{((argument (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a))))))))->sum(),((argument (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a))))))))->sum()} ; if (b->compareTo(s)) <= 0 & (s <= c) then ( execute ('YES')->display() ; var v : double := s - b ; var r : Sequence := Sequence{} ; for _tuple : a do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if v > 0 then ( var l : OclAny := Set{v, y - x}->min() ; v := v - l ; x := x + l ) else skip ; r := r + Sequence{ x }) ; execute ((argument * (test (logical_test (comparison (expr (atom (name r))))))))->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def newString(s,k): X="" while(len(s)>0): temp=s[0] i=1 while(idisplay() ) else skip; operation newString(s : OclAny, k : OclAny) : OclAny pre: true post: true activity: var X : String := "" ; while ((s)->size() > 0) do ( var temp : OclAny := s->first() ; var i : int := 1 ; while ((i->compareTo(k)) < 0 & (i->compareTo((s)->size())) < 0) do ( if ((s[i+1]->compareTo(temp)) < 0) then ( temp := s[i+1] ) else skip ; i := i + 1) ; X := X + temp ; for i : Integer.subrange(0, k-1) do ( if (s[i+1] = temp) then ( s := s.subrange(0+1, i) + s.subrange(i + 1+1) ; break ) else skip)) ; return X; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d,sum=map(int,input().split()) min=max=0 lst=[] th=0 for i in range(d): a,b=map(int,input().split()) lst.extend([a,b]) min+=a max+=b if min<=sum<=max : print("YES") while sum-min>lst[th+1]-lst[th]: sum-=(lst[th+1]-lst[th]) print(lst[th+1],end=" ") th+=2 while sum-min<=lst[th+1]-lst[th]: print(lst[th]+sum-min,end=" ") sum=min th+=2 if th==2*d : break else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : OclAny := null; var sum : OclAny := null; Sequence{d,sum} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var min : OclAny := 0; var max : int := 0 ; var lst : Sequence := Sequence{} ; var th : int := 0 ; for i : Integer.subrange(0, d-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; lst := lst->union(Sequence{a}->union(Sequence{ b })) ; min := min + a ; max := max + b) ; if (min->compareTo(sum)) <= 0 & (sum <= max) then ( execute ("YES")->display() ; while (sum - min->compareTo(lst[th + 1+1] - lst[th+1])) > 0 do ( sum := sum - (lst[th + 1+1] - lst[th+1]) ; execute (lst[th + 1+1])->display() ; th := th + 2) ; while (sum - min->compareTo(lst[th + 1+1] - lst[th+1])) <= 0 do ( execute (lst[th+1] + sum - min)->display() ; var sum : OclAny := min ; th := th + 2 ; if th = 2 * d then ( break ) else skip) ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import pow,floor res=0 def checkRecursive(num,x,k,n): global res if(x==0): res+=1 r=floor(pow(num,(1/n))); for i in range(k+1,r+1,1): a=x-int(pow(i,n)) if(a>=0): checkRecursive(num,x-int(pow(i,n)),i,n) return res def check(x,n): return checkRecursive(x,x,0,n) if __name__=='__main__' : print(check(10,2)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute res : OclAny; operation initialise() pre: true post: true activity: skip ; var res : int := 0 ; skip ; skip ; if __name__ = '__main__' then ( execute (check(10, 2))->display() ) else skip; operation checkRecursive(num : OclAny, x : OclAny, k : OclAny, n : OclAny) : OclAny pre: true post: true activity: skip ; if (x = 0) then ( res := res + 1 ) else skip ; var r : OclAny := floor((num)->pow((1 / n))); ; for i : Integer.subrange(k + 1, r + 1-1)->select( $x | ($x - k + 1) mod 1 = 0 ) do ( var a : double := x - ("" + (((i)->pow(n))))->toInteger() ; if (a >= 0) then ( checkRecursive(num, x - ("" + (((i)->pow(n))))->toInteger(), i, n) ) else skip) ; return res; operation check(x : OclAny, n : OclAny) : OclAny pre: true post: true activity: return checkRecursive(x, x, 0, n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d,sumTime=map(int,input().split()) time_list=[] max_sum=0 min_sum=0 for i in range(d): a,b=map(int,input().split()) time_list.append((a,b,i)) max_sum+=b min_sum+=a if sumTime>max_sum or sumTime0 : tmp=time_list[i] diff=tmp[1]-tmp[0] if sumTime>=diff : result[i][1]+=diff sumTime-=diff elif sumTimecollect( _x | (OclType["int"])->apply(_x) ) ; var time_list : Sequence := Sequence{} ; var max_sum : int := 0 ; var min_sum : int := 0 ; for i : Integer.subrange(0, d-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a, b, i}) : time_list) ; max_sum := max_sum + b ; min_sum := min_sum + a) ; if (sumTime->compareTo(max_sum)) > 0 or (sumTime->compareTo(min_sum)) < 0 then ( execute ("NO")->display() ) else ( var result : Sequence := Sequence{} ; for i : time_list do ( execute ((Sequence{i[2+1]}->union(Sequence{ i->first() })) : result)) ; sumTime := sumTime - min_sum ; for i : Integer.subrange(0, (time_list)->size()-1) do ( if sumTime > 0 then ( var tmp : OclAny := time_list[i+1] ; var diff : double := tmp[1+1] - tmp->first() ; if (sumTime->compareTo(diff)) >= 0 then ( result[i+1][1+1] := result[i+1][1+1] + diff ; sumTime := sumTime - diff ) else (if (sumTime->compareTo(diff)) < 0 then ( result[i+1][1+1] := result[i+1][1+1] + sumTime ; sumTime := sumTime - sumTime ; break ) else skip) ) else skip) ; execute ("YES")->display() ; for i : Integer.subrange(0, (result)->size()-1) do ( execute (result[i+1][1+1])->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- hari_dan_jam=input() hari=int(hari_dan_jam.split(" ")[0]) jam=int(hari_dan_jam.split(" ")[1]) e=[] f=[] for x in range(hari): max_dan_min=input() e.append(int(max_dan_min.split(" ")[1])) f.append(int(max_dan_min.split(" ")[0])) if sum(e)jam : print("NO") elif sum(e)==jam : print("YES") for i in range(0,hari): print(e[i],end=" ") else : while sum(e)>jam : indeks=hari-1 while e[indeks]==f[indeks]: indeks-=1 e[indeks]-=1 print("YES") for i in range(0,hari): print(e[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var hari_dan_jam : String := (OclFile["System.in"]).readLine() ; var hari : int := ("" + ((hari_dan_jam.split(" ")->first())))->toInteger() ; var jam : int := ("" + ((hari_dan_jam.split(" ")[1+1])))->toInteger() ; var e : Sequence := Sequence{} ; var f : Sequence := Sequence{} ; for x : Integer.subrange(0, hari-1) do ( var max_dan_min : String := (OclFile["System.in"]).readLine() ; execute ((("" + ((max_dan_min.split(" ")[1+1])))->toInteger()) : e) ; execute ((("" + ((max_dan_min.split(" ")->first())))->toInteger()) : f)) ; if ((e)->sum()->compareTo(jam)) < 0 or ((f)->sum()->compareTo(jam)) > 0 then ( execute ("NO")->display() ) else (if (e)->sum() = jam then ( execute ("YES")->display() ; for i : Integer.subrange(0, hari-1) do ( execute (e[i+1])->display()) ) else ( while ((e)->sum()->compareTo(jam)) > 0 do ( var indeks : double := hari - 1 ; while e[indeks+1] = f[indeks+1] do ( indeks := indeks - 1) ; e[indeks+1] := e[indeks+1] - 1) ; execute ("YES")->display() ; for i : Integer.subrange(0, hari-1) do ( execute (e[i+1])->display()) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def canBePicked(digits,num): copyDigits=[]; for i in range(len(digits)): copyDigits.append(digits[i]); while(num>0): digit=num % 10 ; if(copyDigits[digit]==0): return False ; else : copyDigits[digit]-=1 ; num=math.floor(num/10); return True ; def countAlphabets(n): count=0 ; digits=[0]*10 ; while(n>0): digit=n % 10 ; digits[digit]+=1 ; n=math.floor(n/10); for i in range(ord('a'),ord('z')+1): if(canBePicked(digits,i)): count+=1 ; for i in range(ord('A'),ord('Z')+1): if(canBePicked(digits,i)): count+=1 ; return count ; n=1623455078 ; print(countAlphabets(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 1623455078; ; execute (countAlphabets(n))->display();; operation canBePicked(digits : OclAny, num : OclAny) pre: true post: true activity: var copyDigits : Sequence := Sequence{}; ; for i : Integer.subrange(0, (digits)->size()-1) do ( execute ((digits[i+1]) : copyDigits);) ; while (num > 0) do ( var digit : int := num mod 10; ; if (copyDigits[digit+1] = 0) then ( return false; ) else ( copyDigits[digit+1] := copyDigits[digit+1] - 1; ) ; num := (num / 10)->floor();) ; return true;; operation countAlphabets(n : OclAny) pre: true post: true activity: var count : int := 0; ; digits := MatrixLib.elementwiseMult(Sequence{ 0 }, 10); ; while (n > 0) do ( digit := n mod 10; ; digits[digit+1] := digits[digit+1] + 1; ; n := (n / 10)->floor();) ; for i : Integer.subrange(('a')->char2byte(), ('z')->char2byte() + 1-1) do ( if (canBePicked(digits, i)) then ( count := count + 1; ) else skip) ; for i : Integer.subrange(('A')->char2byte(), ('Z')->char2byte() + 1-1) do ( if (canBePicked(digits, i)) then ( count := count + 1; ) else skip) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def getNumbers(a,n): freq={}; for i in range(n): if a[i]not in freq.keys(): freq[a[i]]=0 freq[a[i]]+=1 maxi1=max(a) for i in range(1,int(sqrt(maxi1))+1): if(maxi1 % i==0 and freq[i]in freq.keys()and freq[i]!=0): freq[i]-=1 if(i!=(maxi1//i)and freq[maxi1//i]in freq.keys()and freq[maxi1//i]!=0): freq[maxi1//i]-=1 maxi2=-1 for i in range(n): if(freq[a[i]]!=0): maxi2=max(maxi2,a[i]) print(maxi1,maxi2) if __name__=="__main__" : a=[10,2,8,1,2,4,1,20,4,5] n=len(a) getNumbers(a,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( a := Sequence{10}->union(Sequence{2}->union(Sequence{8}->union(Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{1}->union(Sequence{20}->union(Sequence{4}->union(Sequence{ 5 }))))))))) ; n := (a)->size() ; getNumbers(a, n) ) else skip; operation getNumbers(a : OclAny, n : OclAny) pre: true post: true activity: var freq : OclAny := Set{}; ; for i : Integer.subrange(0, n-1) do ( if (freq.keys())->excludes(a[i+1]) then ( freq[a[i+1]+1] := 0 ) else skip ; freq[a[i+1]+1] := freq[a[i+1]+1] + 1) ; var maxi1 : OclAny := (a)->max() ; for i : Integer.subrange(1, ("" + ((sqrt(maxi1))))->toInteger() + 1-1) do ( if (maxi1 mod i = 0 & (freq.keys())->includes(freq[i+1]) & freq[i+1] /= 0) then ( freq[i+1] := freq[i+1] - 1 ; if (i /= (maxi1 div i) & (freq.keys())->includes(freq[maxi1 div i+1]) & freq[maxi1 div i+1] /= 0) then ( freq[maxi1 div i+1] := freq[maxi1 div i+1] - 1 ) else skip ) else skip) ; var maxi2 : int := -1 ; for i : Integer.subrange(0, n-1) do ( if (freq[a[i+1]+1] /= 0) then ( maxi2 := Set{maxi2, a[i+1]}->max() ) else skip) ; execute (maxi1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) K=int(input()) x=list(map(int,input().split())) num=0 for i in range(N): a=x[i] if a<=K-a : num+=2*a else : num+=(K-a)*2 print(num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var num : int := 0 ; for i : Integer.subrange(0, N-1) do ( var a : OclAny := x[i+1] ; if (a->compareTo(K - a)) <= 0 then ( num := num + 2 * a ) else ( num := num + (K - a) * 2 )) ; execute (num)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) k=int(input()) x=[int(item)for item in input().split()] ans=0 for x_ in x : ans+=min(abs(x_-0),abs(x_-k))*2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := input().split()->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; var ans : int := 0 ; for x_ : x do ( ans := ans + Set{(x_ - 0)->abs(), (x_ - k)->abs()}->min() * 2) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def ILI(): return list(map(int,sys.stdin.readline().rstrip().split())) def ISI(): return map(int,sys.stdin.readline().rstrip().split()) def II(): return int(sys.stdin.readline().rstrip()) def ISS(): return sys.stdin.readline().rstrip().split() def IS(): return sys.stdin.readline().rstrip() N=II() K=II() a=ILI() ans=0 for x in a : if xcompareTo(K - x)) < 0 then ( ans := ans + 2 * x ) else ( ans := ans + 2 * (K - x) )) ; execute (ans)->display(); operation ILI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ISI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ); operation II() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.readLine().rstrip())))->toInteger(); operation ISS() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip().split(); operation IS() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def resolve(): n=int(input()) k=int(input()) x=list(map(int,input().split())) ans=0 for v in x : ans+=min((v-0)*2,(k-v)*2) print(ans) return if __name__=="__main__" : resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( resolve() ) else skip; operation resolve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for v : x do ( ans := ans + Set{(v - 0) * 2, (k - v) * 2}->min()) ; execute (ans)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) k=int(input()) li=list(map(int,input().split())) total=0 for i in range(n): total+=2*min(li[i],k-li[i]) print(total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var total : int := 0 ; for i : Integer.subrange(0, n-1) do ( total := total + 2 * Set{li[i+1], k - li[i+1]}->min()) ; execute (total)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=1000005 primeFactors=[0]*N ; def findPrimeFactors(): for i in range(2,N): if(primeFactors[i]==0): for j in range(i,N,i): primeFactors[j]=primeFactors[j//i]+1 ; for i in range(1,N): primeFactors[i]+=primeFactors[i-1]; if __name__=="__main__" : findPrimeFactors(); a=6 ; b=3 ; print(primeFactors[a]-primeFactors[b]); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 1000005 ; var primeFactors : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N); ; skip ; if __name__ = "__main__" then ( findPrimeFactors(); ; var a : int := 6; var b : int := 3; ; execute (primeFactors[a+1] - primeFactors[b+1])->display(); ) else skip; operation findPrimeFactors() pre: true post: true activity: for i : Integer.subrange(2, N-1) do ( if (primeFactors[i+1] = 0) then ( for j : Integer.subrange(i, N-1)->select( $x | ($x - i) mod i = 0 ) do ( primeFactors[j+1] := primeFactors[j div i+1] + 1;) ) else skip) ; for i : Integer.subrange(1, N-1) do ( primeFactors[i+1] := primeFactors[i+1] + primeFactors[i - 1+1];); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=list(map(int,input())) length=len(S)-1 for bit in range(2**length): ans=S[0] ope=['+' if bit &(2**i)else '-' for i in range(length)] for i in range(1,length+1): if ope[i-1]=='+' : ans+=S[i] else : ans-=S[i] if ans==7 : print('{}{}{}{}{}{}{}=7'.format(S[0],ope[0],S[1],ope[1],S[2],ope[2],S[3])) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : Sequence := (((OclFile["System.in"]).readLine())->collect( _x | (OclType["int"])->apply(_x) )) ; var length : double := (S)->size() - 1 ; for bit : Integer.subrange(0, (2)->pow(length)-1) do ( var ans : OclAny := S->first() ; var ope : Sequence := Integer.subrange(0, length-1)->select(i | true)->collect(i | (if MathLib.bitwiseAnd(bit, ((2)->pow(i))) then '+' else '-' endif)) ; for i : Integer.subrange(1, length + 1-1) do ( if ope[i - 1+1] = '+' then ( ans := ans + S[i+1] ) else ( ans := ans - S[i+1] )) ; if ans = 7 then ( execute (StringLib.interpolateStrings('{}{}{}{}{}{}{}=7', Sequence{S->first(), ope->first(), S[1+1], ope[1+1], S[2+1], ope[2+1], S[3+1]}))->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=input() if a.count('1')+a.count('1')% 2>=b.count('1'): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; if (a->count('1') + a->count('1') mod 2->compareTo(b->count('1'))) >= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def oddSum(n): return(n*n); n=20 print(" Sum of first",n,"Odd Numbers is: ",oddSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 20 ; execute (" Sum of first")->display(); operation oddSum(n : OclAny) pre: true post: true activity: return (n * n);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=4 def count(arr): diag1=0 ; diag2=0 ; row=0 col=0 ; count=0 ; j=n-1 for i in range(n): diag1+=arr[i][i] diag2+=arr[i][j] j-=1 for i in range(n): row=0 ; col=0 for j in range(n): row+=arr[i][j] for j in range(n): col+=arr[j][i] if((row==diag1)or(row==diag2)): count+=1 if((col==diag1)or(col==diag2)): count+=1 return count arr=[[7,2,3,5],[4,5,6,3],[7,9,10,12],[1,5,4,3]] print(count(arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := 4 ; skip ; arr := Sequence{Sequence{7}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 5 })))}->union(Sequence{Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 3 })))}->union(Sequence{Sequence{7}->union(Sequence{9}->union(Sequence{10}->union(Sequence{ 12 })))}->union(Sequence{ Sequence{1}->union(Sequence{5}->union(Sequence{4}->union(Sequence{ 3 }))) }))) ; execute (count(arr))->display(); operation count(arr : OclAny) : OclAny pre: true post: true activity: var diag1 : int := 0; var diag2 : int := 0; var row : int := 0 ; var col : int := 0; var count : int := 0; var j : double := n - 1 ; for i : Integer.subrange(0, n-1) do ( diag1 := diag1 + arr[i+1][i+1] ; diag2 := diag2 + arr[i+1][j+1] ; j := j - 1) ; for i : Integer.subrange(0, n-1) do ( row := 0; col := 0 ; for j : Integer.subrange(0, n-1) do ( row := row + arr[i+1][j+1]) ; for j : Integer.subrange(0, n-1) do ( col := col + arr[j+1][i+1]) ; if ((row = diag1) or (row = diag2)) then ( count := count + 1 ) else skip ; if ((col = diag1) or (col = diag2)) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=32 def countSetBits(n): count=0 ; while(n): n &=(n-1); count+=1 ; return count ; def pairs(arr,n,k): count=0 ; f=[0 for i in range(MAX+1)] for i in range(n): f[countSetBits(arr[i])]+=1 ; for i in range(MAX+1): for j in range(1,MAX+1): if(i+j==k): if(i==j): count+=((f[i]*(f[i]-1))/2); else : count+=(f[i]*f[j]); return count ; arr=[1,2,3,4,5] n=len(arr) k=4 print(pairs(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 32 ; skip ; skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ; n := (arr)->size() ; k := 4 ; execute (pairs(arr, n, k))->display(); operation countSetBits(n : OclAny) pre: true post: true activity: var count : int := 0; ; while (n) do ( n := n & (n - 1); ; count := count + 1;) ; return count;; operation pairs(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: count := 0; ; var f : Sequence := Integer.subrange(0, MAX + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( f[countSetBits(arr[i+1])+1] := f[countSetBits(arr[i+1])+1] + 1;) ; for i : Integer.subrange(0, MAX + 1-1) do ( for j : Integer.subrange(1, MAX + 1-1) do ( if (i + j = k) then ( if (i = j) then ( count := count + ((f[i+1] * (f[i+1] - 1)) / 2); ) else ( count := count + (f[i+1] * f[j+1]); ) ) else skip)) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.buffer.readline def process(S): S=''.join(sorted(S)) print(S) n=int(input()) S=input().decode().strip() process(S) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := sys.stdin.buffer.readline ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; S := input().decode()->trim() ; process(S); operation process(S : OclAny) pre: true post: true activity: S := StringLib.sumStringsWithSeparator((S->sort()), '') ; execute (S)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n=int(input()) s=input() c=Counter(s) s_prime='' for key,value in c.items(): s_prime+=value*key print(s_prime) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var c : OclAny := Counter(s) ; var s_prime : String := '' ; for _tuple : c->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); s_prime := s_prime + value * key) ; execute (s_prime)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) string=input() print("".join(sorted(string))) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var string : String := (OclFile["System.in"]).readLine() ; execute (StringLib.sumStringsWithSeparator((string->sort()), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input(); print(''.join(sorted(input()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input(); execute (StringLib.sumStringsWithSeparator(((OclFile["System.in"]).readLine()->sort()), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,a=int(input()),(int(i)for i in input().split()) s=[[],[]] for i in a : s[i & 1].append(i) res=s[0]+s[1] print(*res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))}} ; var s : Sequence := Sequence{Sequence{}}->union(Sequence{ Sequence{} }) ; for i : a do ((expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) & (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var res : OclAny := s->first() + s[1+1] ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin def main(): cases=int(stdin.readline()) while(cases>0): membersNumber=int(stdin.readline()) membersHeight=stdin.readline().strip().split() for i in range(len(membersHeight)): membersHeight[i]=int(membersHeight[i]) photogenicPairs=list() for i in membersHeight : if(i % 2!=0): photogenicPairs.append(i) for i in membersHeight : if(i % 2==0): photogenicPairs.append(i) print(*photogenicPairs) cases-=1 main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: var cases : int := ("" + ((stdin.readLine())))->toInteger() ; while (cases > 0) do ( var membersNumber : int := ("" + ((stdin.readLine())))->toInteger() ; var membersHeight : OclAny := stdin.readLine()->trim().split() ; for i : Integer.subrange(0, (membersHeight)->size()-1) do ( membersHeight[i+1] := ("" + ((membersHeight[i+1])))->toInteger()) ; var photogenicPairs : Sequence := () ; for i : membersHeight do ( if (i mod 2 /= 0) then ( execute ((i) : photogenicPairs) ) else skip) ; for i : membersHeight do ( if (i mod 2 = 0) then ( execute ((i) : photogenicPairs) ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name photogenicPairs))))))))->display() ; cases := cases - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=input() a=int(k[0]) b=int(k[1]) c=int(k[2]) d=int(k[3]) if(a+b+c+d)==7 : print(k[0]+'+'+k[1]+'+'+k[2]+'+'+k[3]+'='+'7') elif(a-b+c+d)==7 : print(k[0]+'-'+k[1]+'+'+k[2]+'+'+k[3]+'='+'7') elif(a+b-c+d)==7 : print(k[0]+'+'+k[1]+'-'+k[2]+'+'+k[3]+'='+'7') elif(a+b+c-d)==7 : print(k[0]+'+'+k[1]+'+'+k[2]+'-'+k[3]+'='+'7') elif(a-b-c+d)==7 : print(k[0]+'-'+k[1]+'-'+k[2]+'+'+k[3]+'='+'7') elif(a+b-c-d)==7 : print(k[0]+'+'+k[1]+'-'+k[2]+'-'+k[3]+'='+'7') elif(a-b+c-d)==7 : print(k[0]+'-'+k[1]+'+'+k[2]+'-'+k[3]+'='+'7') elif(a-b-c-d)==7 : print(k[0]+'-'+k[1]+'-'+k[2]+'-'+k[3]+'='+'7') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : String := (OclFile["System.in"]).readLine() ; var a : int := ("" + ((k->first())))->toInteger() ; var b : int := ("" + ((k[1+1])))->toInteger() ; var c : int := ("" + ((k[2+1])))->toInteger() ; var d : int := ("" + ((k[3+1])))->toInteger() ; if (a + b + c + d) = 7 then ( execute (k->first() + '+' + k[1+1] + '+' + k[2+1] + '+' + k[3+1] + '=' + '7')->display() ) else (if (a - b + c + d) = 7 then ( execute (k->first() + '-' + k[1+1] + '+' + k[2+1] + '+' + k[3+1] + '=' + '7')->display() ) else (if (a + b - c + d) = 7 then ( execute (k->first() + '+' + k[1+1] + '-' + k[2+1] + '+' + k[3+1] + '=' + '7')->display() ) else (if (a + b + c - d) = 7 then ( execute (k->first() + '+' + k[1+1] + '+' + k[2+1] + '-' + k[3+1] + '=' + '7')->display() ) else (if (a - b - c + d) = 7 then ( execute (k->first() + '-' + k[1+1] + '-' + k[2+1] + '+' + k[3+1] + '=' + '7')->display() ) else (if (a + b - c - d) = 7 then ( execute (k->first() + '+' + k[1+1] + '-' + k[2+1] + '-' + k[3+1] + '=' + '7')->display() ) else (if (a - b + c - d) = 7 then ( execute (k->first() + '-' + k[1+1] + '+' + k[2+1] + '-' + k[3+1] + '=' + '7')->display() ) else (if (a - b - c - d) = 7 then ( execute (k->first() + '-' + k[1+1] + '-' + k[2+1] + '-' + k[3+1] + '=' + '7')->display() ) else skip ) ) ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n,k=map(int,input().split(' ')) if k % 4==0 : print("NO") elif k % 4==1 or k % 4==3 : print("YES") j=1 while j<=n : print(j,j+1) j+=2 else : print("YES") j=1 while j<=n : if(j-1)% 4==0 : print(j+1,j) else : print(j,j+1) j+=2 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; if k mod 4 = 0 then ( execute ("NO")->display() ) else (if k mod 4 = 1 or k mod 4 = 3 then ( execute ("YES")->display() ; var j : int := 1 ; while (j->compareTo(n)) <= 0 do ( execute (j)->display() ; j := j + 2) ) else ( execute ("YES")->display() ; j := 1 ; while (j->compareTo(n)) <= 0 do ( if (j - 1) mod 4 = 0 then ( execute (j + 1)->display() ) else ( execute (j)->display() ) ; j := j + 2) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(_number=None): n=int(input()) A=[int(x)for x in input().split()] B=[int(x)for x in input().split()] num___odd_dist={odd : i for i,odd in enumerate(A)} best_ans=2*n curr_idx=0 even___idx={even : idx for idx,even in enumerate(B)} curr_idx=even___idx[2*n] for odd in range(2*n-1,0,-2): if even___idx[odd+1]toInteger()-1) do ( solve(i)) ) else skip; operation solve(_number : OclAny) pre: true post: true activity: if _number->oclIsUndefined() then _number := null else skip; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var B : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var num___odd_dist : Map := Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} )->select(_tuple | true)->collect(_tuple | Map{odd |-> i})->unionAll() ; var best_ans : int := 2 * n ; var curr_idx : int := 0 ; var even___idx : Map := Integer.subrange(1, (B)->size())->collect( _indx | Sequence{_indx-1, (B)->at(_indx)} )->select(_tuple | true)->collect(_tuple | Map{even |-> idx})->unionAll() ; curr_idx := even___idx[2 * n+1] ; for odd : Integer.subrange(2 * n - 1, 0-1)->select( $x | ($x - 2 * n - 1) mod -2 = 0 ) do ( if (even___idx[odd + 1+1]->compareTo(curr_idx)) < 0 then ( curr_idx := even___idx[odd + 1+1] ) else skip ; var ans : OclAny := num___odd_dist[odd+1] + curr_idx ; best_ans := Set{ans, best_ans}->min()) ; execute (best_ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=int(input()) for _ in range(m): n=int(input()) a=list(map(int,input().split())) z=[] f=[] for i in range(n): if a[i]% 2==0 : z.append(a[i]) else : f.append(a[i]) print(*f+z,sep=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, m-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var z : Sequence := Sequence{} ; var f : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if a[i+1] mod 2 = 0 then ( execute ((a[i+1]) : z) ) else ( execute ((a[i+1]) : f) )) ; execute ((argument * (test (logical_test (comparison (expr (expr (atom (name f))) + (expr (atom (name z)))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=[int(x)for x in input().split()] a_odd=[x for x in a if x % 2!=0] a_even=[x for x in a if x % 2==0] result=[] result.extend(a_odd) result.extend(a_even) print(' '.join(map(str,result))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a_odd : Sequence := a->select(x | x mod 2 /= 0)->collect(x | (x)) ; var a_even : Sequence := a->select(x | x mod 2 = 0)->collect(x | (x)) ; var result : Sequence := Sequence{} ; result := result->union(a_odd) ; result := result->union(a_even) ; execute (StringLib.sumStringsWithSeparator(((result)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) d={} d['0']=d['2']=d['4']=d['6']=d['8']=0 d['1']=d['3']=d['5']=d['7']=d['9']=1 while T : n=int(input()) t=input().split() a=[] for x in t : if d[x[-1]]==0 : print(x,end=' ') else : a.append(x) for x in a : print(x,end=' ') print() T-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : OclAny := Set{} ; d->at('0') := d->at('0')(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom '2'))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom '4'))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom '6'))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom '8'))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; d->at('1') := d->at('1')(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom '3'))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom '5'))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom '7'))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom '9'))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))) ; while T do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : OclAny := input().split() ; var a : Sequence := Sequence{} ; for x : t do ( if d[x->last()+1] = 0 then ( execute (x)->display() ) else ( execute ((x) : a) )) ; for x : a do ( execute (x)->display()) ; execute (->display() ; T := T - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- arr=list(map(int,input().split())) first=0 draw=0 secound=0 for i in range(1,7): if abs(arr[0]-i)collect( _x | (OclType["int"])->apply(_x) )) ; var first : int := 0 ; var draw : int := 0 ; var secound : int := 0 ; for i : Integer.subrange(1, 7-1) do ( if ((arr->first() - i)->abs()->compareTo((arr[1+1] - i)->abs())) < 0 then ( first := first + 1 ) else (if ((arr[1+1] - i)->abs()->compareTo((arr->first() - i)->abs())) < 0 then ( secound := secound + 1 ) else ( draw := draw + 1 ) ) ) ; execute (StringLib.formattedString("{first}{draw}{secound}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) if(a==b): print("0 6 0") elif(acollect( _x | (OclType["int"])->apply(_x) ) ; if (a = b) then ( execute ("0 6 0")->display() ) else (if ((a->compareTo(b)) < 0) then ( if (a mod 2 = b mod 2) then ( execute ((a + b) div 2 - 1)->display() ) else ( execute ((a + b + 1) div 2 - 1)->display() ) ) else ( if (a mod 2 = b mod 2) then ( execute (6 - (a + b) div 2)->display() ) else ( execute (6 - (a + b - 1) div 2)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) kol=[0,0,0] for i in range(1,7): if(abs(a-i)collect( _x | (OclType["int"])->apply(_x) ) ; var kol : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) ; for i : Integer.subrange(1, 7-1) do ( if (((a - i)->abs()->compareTo((b - i)->abs())) < 0) then ( kol->first() := kol->first() + 1 ) else (if ((a - i)->abs() = (b - i)->abs()) then ( kol[1+1] := kol[1+1] + 1 ) else ( kol[2+1] := kol[2+1] + 1 ) ) ) ; for i : kol do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,c=map(int,input().split()) fir,sec,draw=0,0,0 for i in range(1,7): if abs(n-i)collect( _x | (OclType["int"])->apply(_x) ) ; var fir : OclAny := null; var sec : OclAny := null; var draw : OclAny := null; Sequence{fir,sec,draw} := Sequence{0,0,0} ; for i : Integer.subrange(1, 7-1) do ( if ((n - i)->abs()->compareTo((c - i)->abs())) < 0 then ( fir := fir + 1 ) else (if ((c - i)->abs()->compareTo((n - i)->abs())) < 0 then ( sec := sec + 1 ) else ( draw := draw + 1 ) ) ) ; execute (fir)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : a,b=map(int,input().split()) result=[0,0,0] for i in range(1,7): a_closer=abs(a-i) b_closer=abs(b-i) if a_closer==b_closer : result[1]+=1 elif a_closercollect( _x | (OclType["int"])->apply(_x) ) ; var result : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) ; for i : Integer.subrange(1, 7-1) do ( var a_closer : double := (a - i)->abs() ; var b_closer : double := (b - i)->abs() ; if a_closer = b_closer then ( result[1+1] := result[1+1] + 1 ) else (if (a_closer->compareTo(b_closer)) < 0 then ( result->first() := result->first() + 1 ) else ( result[2+1] := result[2+1] + 1 ) ) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name result))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def i1(): return int(input()) def i2(): return[int(i)for i in input().split()] s=input() ss="" for i in range(1<<3): x=s[0] y=int(s[0]) for j in range(3): if i>>j & 1 : x+="+"+s[j+1] y+=int(s[j+1]) else : x+="-"+s[j+1] y-=int(s[j+1]) if y==7 : ss=x+"=7" print(ss) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var s : String := (OclFile["System.in"]).readLine() ; var ss : String := "" ; for i : Integer.subrange(0, 1 * (2->pow(3))-1) do ( var x : OclAny := s->first() ; var y : int := ("" + ((s->first())))->toInteger() ; for j : Integer.subrange(0, 3-1) do ( if MathLib.bitwiseAnd(i /(2->pow(j)), 1) then ( x := x + "+" + s[j + 1+1] ; y := y + ("" + ((s[j + 1+1])))->toInteger() ) else ( x := x + "-" + s[j + 1+1] ; y := y - ("" + ((s[j + 1+1])))->toInteger() )) ; if y = 7 then ( ss := x + "=7" ) else skip) ; execute (ss)->display(); operation i1() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation i2() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countOddSquares(n,m): return int(m**0.5)-int((n-1)**0.5) n=5 m=100 print("Count is",countOddSquares(n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; m := 100 ; execute ("Count is")->display(); operation countOddSquares(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: return ("" + (((m)->pow(0.5))))->toInteger() - ("" + ((((n - 1))->pow(0.5))))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) t=0 while(t==0): n+=1 a=n % 10 b=int(((n-a)/10)% 10) c=int(((n-(b*10+a))/100)% 10) d=int((n-(c*100)+(b*10)+a)/1000) if(a!=b and a!=c and a!=d and b!=c and b!=d and c!=d): print(n) t=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : int := 0 ; while (t = 0) do ( n := n + 1 ; var a : int := n mod 10 ; var b : int := ("" + ((((n - a) / 10) mod 10)))->toInteger() ; var c : int := ("" + ((((n - (b * 10 + a)) / 100) mod 10)))->toInteger() ; var d : int := ("" + (((n - (c * 100) + (b * 10) + a) / 1000)))->toInteger() ; if (a /= b & a /= c & a /= d & b /= c & b /= d & c /= d) then ( execute (n)->display() ; t := 1 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) c=[0]*n for i in range(n): c[a[i]//2]=i for i in range(1,n): c[i]=min(c[i],c[i-1]) ans=n for i in range(n): ans=min(ans,i+c[(b[i]//2)-1]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( c[a[i+1] div 2+1] := i) ; for i : Integer.subrange(1, n-1) do ( c[i+1] := Set{c[i+1], c[i - 1+1]}->min()) ; var ans : int := n ; for i : Integer.subrange(0, n-1) do ( ans := Set{ans, i + c[(b[i+1] div 2) - 1+1]}->min()) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(year): distinct_num=0 leng=1 while distinct_num!=leng : year+=1 distinct_num=len(str(year)) leng=len(set(str(year))) return year year=int(input()) print(solve(year)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; year := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (solve(year))->display(); operation solve(year : OclAny) : OclAny pre: true post: true activity: var distinct_num : int := 0 ; var leng : int := 1 ; while distinct_num /= leng do ( year := year + 1 ; distinct_num := (("" + ((year))))->size() ; leng := (Set{}->union((("" + ((year))))))->size()) ; return year; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) i=n+1 while True : s=str(i) c=0 for j in range(len(s)): a=s.count(s[j]) c+=a if c==4 : print(i) break i+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := n + 1 ; while true do ( var s : String := ("" + ((i))) ; var c : int := 0 ; for j : Integer.subrange(0, (s)->size()-1) do ( var a : int := s->count(s[j+1]) ; c := c + a) ; if c = 4 then ( execute (i)->display() ; break ) else skip ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) n=n+1 while len(set(str(n)))<4 : n+=1 print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; n := n + 1 ; while (Set{}->union((("" + ((n))))))->size() < 4 do ( n := n + 1) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def final_(n): a=set() for i in str(n): if i in a : return False a.add(i) return True n=int(input()) while True : n+=1 if final_(n): print(n) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while true do ( n := n + 1 ; if final_(n) then ( execute (n)->display() ; break ) else skip); operation final_(n : OclAny) : OclAny pre: true post: true activity: var a : Set := Set{}->union(()) ; for i : ("" + ((n))) do ( if (a)->includes(i) then ( return false ) else skip ; execute ((i) : a)) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def noOfYears(t1,n1,t2): years=(t2-1)*n1/(t1-1) return years if __name__=="__main__" : T1,N1,T2=3,5,6 print(noOfYears(T1,N1,T2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var T1 : OclAny := null; var N1 : OclAny := null; var T2 : OclAny := null; Sequence{T1,N1,T2} := Sequence{3,5,6} ; execute (noOfYears(T1, N1, T2))->display() ) else skip; operation noOfYears(t1 : OclAny, n1 : OclAny, t2 : OclAny) : OclAny pre: true post: true activity: var years : double := (t2 - 1) * n1 / (t1 - 1) ; return years; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def preorder(i): if i==-1 : return (l,r)=tree[i] print("{}".format(i),end="") preorder(l) preorder(r) def inorder(i): if i==-1 : return (l,r)=tree[i] inorder(l) print("{}".format(i),end="") inorder(r) def postorder(i): if i==-1 : return (l,r)=tree[i] postorder(l) postorder(r) print("{}".format(i),end="") n=int(input()) tree=[None for i in range(n)] root=set(range(n)) for i in range(n): i,l,r=map(int,input().split()) tree[i]=(l,r) root-=set([l,r]) root_node=root.pop() print("Preorder") preorder(root_node) print() print("Inorder") inorder(root_node) print() print("Postorder") postorder(root_node) print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var Sequence{l, r} : OclAny := tree[i+1]; operation preorder(i : OclAny) pre: true post: true activity: if i = -1 then ( return ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node(): def __init__(self,parent=-1,left=-1,right=-1): self.parent=parent self.left=left self.right=right def preorder(ns,i): print(""+str(i),end="") if ns[i].left!=-1 : preorder(ns,ns[i].left) if ns[i].right!=-1 : preorder(ns,ns[i].right) def inorder(ns,i): if ns[i].left!=-1 : inorder(ns,ns[i].left) print(""+str(i),end="") if ns[i].right!=-1 : inorder(ns,ns[i].right) def postorder(ns,i): if ns[i].left!=-1 : postorder(ns,ns[i].left) if ns[i].right!=-1 : postorder(ns,ns[i].right) print(""+str(i),end="") n=int(input()) ns=[Node()for i in range(n)] for i in range(n): p,l,r=map(int,input().split()) if l!=-1 : ns[p].left=l ns[l].parent=p if r!=-1 : ns[p].right=r ns[r].parent=p for i in range(n): if ns[i].parent==-1 : print("Preorder") preorder(ns,i) print() print("Inorder") inorder(ns,i) print() print("Postorder") postorder(ns,i) print() ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute parent : int := parent; attribute left : int := left; attribute right : int := right; operation initialise(parent : int,left : int,right : int) : pre: true post: true activity: self.parent := parent ; self.left := left ; self.right := right; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; ns := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((Node.newNode()).initialise())) ; for i : Integer.subrange(0, n-1) do ( var p : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{p,l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if l /= -1 then ( ns[p+1].left := l ; ns[l+1].parent := p ) else skip ; if r /= -1 then ( ns[p+1].right := r ; ns[r+1].parent := p ) else skip) ; for i : Integer.subrange(0, n-1) do ( if ns[i+1].parent = -1 then ( execute ("Preorder")->display() ; preorder(ns, i) ; execute (->display() ; execute ("Inorder")->display() ; inorder(ns, i) ; execute (->display() ; execute ("Postorder")->display() ; postorder(ns, i) ; execute (->display() ) else skip); operation preorder(ns : OclAny, i : OclAny) pre: true post: true activity: execute ("" + ("" + ((i))))->display() ; if ns[i+1].left /= -1 then ( preorder(ns, ns[i+1].left) ) else skip ; if ns[i+1].right /= -1 then ( preorder(ns, ns[i+1].right) ) else skip; operation inorder(ns : OclAny, i : OclAny) pre: true post: true activity: if ns[i+1].left /= -1 then ( inorder(ns, ns[i+1].left) ) else skip ; execute ("" + ("" + ((i))))->display() ; if ns[i+1].right /= -1 then ( inorder(ns, ns[i+1].right) ) else skip; operation postorder(ns : OclAny, i : OclAny) pre: true post: true activity: if ns[i+1].left /= -1 then ( postorder(ns, ns[i+1].left) ) else skip ; if ns[i+1].right /= -1 then ( postorder(ns, ns[i+1].right) ) else skip ; execute ("" + ("" + ((i))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt from collections import defaultdict,deque from bisect import bisect_left as b_l from bisect import bisect_right as b_r import sys mod=10**9+7 for _ in range(int(input())): n,m,k=map(int,input().split()) a=list(map(int,input().split())) if(n==1 or m==1): print("No") continue else : a.sort(reverse=True) total=m if(total & 1): flag=False else : flag=True for i in a : if(total & 1): if((i//n)>=3): flag=True if((i//n)>1): total-=(i//n) if(total<=0 and flag): print("Yes") continue total=n if(total & 1): flag=False else : flag=True for i in a : if(total & 1): if((i//m)>=3): flag=True if((i//m)>1): total-=(i//m) if(total<=0 and flag): print("Yes") continue print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (n = 1 or m = 1) then ( execute ("No")->display() ; continue ) else ( a := a->sort() ; var total : OclAny := m ; if (MathLib.bitwiseAnd(total, 1)) then ( var flag : boolean := false ) else ( flag := true ) ; for i : a do ( if (MathLib.bitwiseAnd(total, 1)) then ( if ((i div n) >= 3) then ( flag := true ) else skip ) else skip ; if ((i div n) > 1) then ( total := total - (i div n) ) else skip) ; if (total <= 0 & flag) then ( execute ("Yes")->display() ; continue ) else skip ; total := n ; if (MathLib.bitwiseAnd(total, 1)) then ( flag := false ) else ( flag := true ) ; for i : a do ( if (MathLib.bitwiseAnd(total, 1)) then ( if ((i div m) >= 3) then ( flag := true ) else skip ) else skip ; if ((i div m) > 1) then ( total := total - (i div m) ) else skip) ; if (total <= 0 & flag) then ( execute ("Yes")->display() ; continue ) else skip ; execute ("No")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() OPE_CNT=3 ANS=7 def solve(sum,cnt,ope_s): if cnt==OPE_CNT : if sum==ANS : print(ope_s+'=7') return True else : return False if solve(sum+int(s[cnt+1]),cnt+1,ope_s+'+'+s[cnt+1]): return True if solve(sum-int(s[cnt+1]),cnt+1,ope_s+'-'+s[cnt+1]): return True return False solve(int(s[0]),0,s[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var OPE_CNT : int := 3 ; var ANS : int := 7 ; skip ; solve(("" + ((s->first())))->toInteger(), 0, s->first()); operation solve(sum : OclAny, cnt : OclAny, ope_s : OclAny) : OclAny pre: true post: true activity: if cnt = OPE_CNT then ( if sum = ANS then ( execute (ope_s + '=7')->display() ; return true ) else ( return false ) ) else skip ; if solve(sum + ("" + ((s[cnt + 1+1])))->toInteger(), cnt + 1, ope_s + '+' + s[cnt + 1+1]) then ( return true ) else skip ; if solve(sum - ("" + ((s[cnt + 1+1])))->toInteger(), cnt + 1, ope_s + '-' + s[cnt + 1+1]) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**9) def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) def tree_walk(node): par,sib,deg,dep,hei,l,r=nodes[node] preo.append(node) if l!=-1 : tree_walk(l) ino.append(node) if r!=-1 : tree_walk(r) posto.append(node) return N=INT() nodes=[[-1,-1,0,0,0,-1,-1]for i in range(N)] preo=[] ino=[] posto=[] for i in range(N): node,l,r=MAP() if l!=-1 : nodes[l][0]=node nodes[node][5]=l if r!=-1 : nodes[r][0]=node nodes[node][6]=r for i in range(N): if nodes[i][0]==-1 : tree_walk(i) print('Preorder') print('',end='') print(*preo) print('Inorder') print('',end='') print(*ino) print('Postorder') print('',end='') print(*posto) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(9)) ; skip ; skip ; skip ; skip ; skip ; var N : OclAny := INT() ; var nodes : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{-1}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{ -1 })))))))) ; var preo : Sequence := Sequence{} ; var ino : Sequence := Sequence{} ; var posto : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{node,l,r} := MAP() ; if l /= -1 then ( nodes[l+1]->first() := node ; nodes[node+1][5+1] := l ) else skip ; if r /= -1 then ( nodes[r+1]->first() := node ; nodes[node+1][6+1] := r ) else skip) ; for i : Integer.subrange(0, N-1) do ( if nodes[i+1]->first() = -1 then ( tree_walk(i) ) else skip) ; execute ('Preorder')->display() ; execute ('')->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name preo))))))))->display() ; execute ('Inorder')->display() ; execute ('')->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ino))))))))->display() ; execute ('Postorder')->display() ; execute ('')->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name posto))))))))->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation tree_walk(node : OclAny) pre: true post: true activity: var par : OclAny := null; var sib : OclAny := null; var deg : OclAny := null; var dep : OclAny := null; var hei : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{par,sib,deg,dep,hei,l,r} := nodes[node+1] ; execute ((node) : preo) ; if l /= -1 then ( tree_walk(l) ) else skip ; execute ((node) : ino) ; if r /= -1 then ( tree_walk(r) ) else skip ; execute ((node) : posto) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline write=sys.stdout.write N=int(readline()) L=[None]*N ; R=[None]*N ; P=[-1]*(N+1) for i in range(N): i,l,r=map(int,readline().split()) L[i]=l ; R[i]=r P[l]=i ; P[r]=i s0=[]; s1=[]; s2=[] def dfs(v): v0=str(v) s0.append(v0) L[v]!=-1 and dfs(L[v]) s1.append(v0) R[v]!=-1 and dfs(R[v]) s2.append(v0) dfs(P.index(-1)) write("Preorder\n %s\nInorder\n %s\nPostorder\n %s\n" % tuple(map(" ".join,[s0,s1,s2]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var write : OclAny := (OclFile["System.out"]).write ; var N : int := ("" + ((readline())))->toInteger() ; var L : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, N); var R : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, N); var P : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (N + 1)) ; for i : Integer.subrange(0, N-1) do ( var i : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{i,l,r} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; L[i+1] := l; R[i+1] := r ; P[l+1] := i; P[r+1] := i) ; var s0 : Sequence := Sequence{}; var s1 : Sequence := Sequence{}; var s2 : Sequence := Sequence{} ; skip ; dfs(P->indexOf(-1) - 1) ; write(StringLib.format("Preorder\n %s\nInorder\n %s\nPostorder\n %s\n",((Sequence{s0}->union(Sequence{s1}->union(Sequence{ s2 })))->collect( _x | (StringLib.sumStringsWithSeparator(.join`third, " "))->apply(_x) )))); operation dfs(v : OclAny) pre: true post: true activity: var v0 : String := ("" + ((v))) ; execute ((v0) : s0) ; (logical_test (logical_test (comparison (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])))) != (comparison (expr (atom - (number (integer 1))))))) and (logical_test (comparison (expr (atom (name dfs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])))))))) ))))))) ; execute ((v0) : s1) ; (logical_test (logical_test (comparison (comparison (expr (atom (name R)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])))) != (comparison (expr (atom - (number (integer 1))))))) and (logical_test (comparison (expr (atom (name dfs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name R)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])))))))) ))))))) ; execute ((v0) : s2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections nil=-1 def preParse(u): if u==nil : return None print('{}'.format(u),end='') preParse(tree[u]['left']) preParse(tree[u]['right']) def inParse(u): if u==nil : return None inParse(tree[u]['left']) print('{}'.format(u),end='') inParse(tree[u]['right']) def postParse(u): if u==nil : return None postParse(tree[u]['left']) postParse(tree[u]['right']) print('{}'.format(u),end='') if __name__=='__main__' : n=int(input()) tree=collections.defaultdict(dict) roots=list() for _ in range(n): id_num,left,right=[int(x)for x in input().split()] tree[id_num]['left']=left tree[id_num]['right']=right if left!=nil : tree[left]['parent']=id_num if right!=nil : tree[right]['parent']=id_num for key,val in tree.items(): if not 'parent' in tree[key]: roots.append(key) print('Preorder') preParse(roots[0]) print() print('Inorder') inParse(roots[0]) print() print('Postorder') postParse(roots[0]) print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var nil : int := -1 ; skip ; skip ; skip ; if __name__ = '__main__' then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var tree : OclAny := .defaultdict(OclType["Map"]) ; var roots : Sequence := () ; for _anon : Integer.subrange(0, n-1) do ( var id_num : OclAny := null; var left : OclAny := null; var right : OclAny := null; Sequence{id_num,left,right} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; tree[id_num+1]->at('left') := left ; tree[id_num+1]->at('right') := right ; if left /= nil then ( tree[left+1]->at('parent') := id_num ) else skip ; if right /= nil then ( tree[right+1]->at('parent') := id_num ) else skip) ; for _tuple : tree->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var val : OclAny := _tuple->at(_indx); if not((tree[key+1])->includes('parent')) then ( execute ((key) : roots) ) else skip) ; execute ('Preorder')->display() ; preParse(roots->first()) ; execute (->display() ; execute ('Inorder')->display() ; inParse(roots->first()) ; execute (->display() ; execute ('Postorder')->display() ; postParse(roots->first()) ; execute (->display() ) else skip; operation preParse(u : OclAny) : OclAny pre: true post: true activity: if u = nil then ( return null ) else skip ; execute (StringLib.interpolateStrings('{}', Sequence{u}))->display() ; preParse(tree[u+1]->at('left')) ; preParse(tree[u+1]->at('right')); operation inParse(u : OclAny) : OclAny pre: true post: true activity: if u = nil then ( return null ) else skip ; inParse(tree[u+1]->at('left')) ; execute (StringLib.interpolateStrings('{}', Sequence{u}))->display() ; inParse(tree[u+1]->at('right')); operation postParse(u : OclAny) : OclAny pre: true post: true activity: if u = nil then ( return null ) else skip ; postParse(tree[u+1]->at('left')) ; postParse(tree[u+1]->at('right')) ; execute (StringLib.interpolateStrings('{}', Sequence{u}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): t=int(input()) for _ in range(t): solve_one() def solve_one(): n=int(input()) a=[int(x)for x in input().split()] b=[int(x)for x in input().split()] assert len(a)==len(b) assert len(a)==n price=[0]*n for i,ai in enumerate(a): price[ai//2]=i cur_min_price=price[0] for i,p in enumerate(price[:]): if ptoInteger() ; for _anon : Integer.subrange(0, t-1) do ( solve_one()); operation solve_one() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var b : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; assert (a)->size() = (b)->size() do "assertion failed" ; assert (a)->size() = n do "assertion failed" ; var price : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var ai : OclAny := _tuple->at(_indx); price[ai div 2+1] := i) ; var cur_min_price : OclAny := price->first() ; for _tuple : Integer.subrange(1, (price)->size())->collect( _indx | Sequence{_indx-1, (price)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p : OclAny := _tuple->at(_indx); if (p->compareTo(cur_min_price)) < 0 then ( cur_min_price := p ) else ( price[i+1] := cur_min_price )) ; var min_price : int := n ; for _tuple : Integer.subrange(1, (b)->size())->collect( _indx | Sequence{_indx-1, (b)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var bi : OclAny := _tuple->at(_indx); var bi_price : OclAny := i + price[bi div 2 - 1+1] ; min_price := Set{min_price, bi_price}->min()) ; execute (min_price)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def printVector(v): print(len(v)) for i in range(0,len(v)): print(v[i],end=" ") print() def findTwoGroup(n): sum=n*(n+1)/2 group1Sum=sum/2 group1=[] group2=[] for i in range(n,0,-1): if(group1Sum-i>=0): group1.append(i) group1Sum-=i else : group2.append(i) printVector(group1) printVector(group2) n=5 findTwoGroup(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 5 ; findTwoGroup(n); operation printVector(v : OclAny) pre: true post: true activity: execute ((v)->size())->display() ; for i : Integer.subrange(0, (v)->size()-1) do ( execute (v[i+1])->display()) ; execute (->display(); operation findTwoGroup(n : OclAny) pre: true post: true activity: var sum : double := n * (n + 1) / 2 ; var group1Sum : double := sum / 2 ; var group1 : Sequence := Sequence{} ; var group2 : Sequence := Sequence{} ; for i : Integer.subrange(0 + 1, n)->reverse() do ( if (group1Sum - i >= 0) then ( execute ((i) : group1) ; group1Sum := group1Sum - i ) else ( execute ((i) : group2) )) ; printVector(group1) ; printVector(group2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t1,t2,k=map(int,input().split()) participants=[] for i in range(n): v1,v2=map(int,input().split()) participants.append([i+1,max(v2*t1*(1-(k/100))+v1*t2,v1*t1*(1-(k/100))+v2*t2)]) [print(part[0],"{:.2f}".format(part[1]))for part in sorted(participants,key=lambda l : l[1],reverse=True)] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t1 : OclAny := null; var t2 : OclAny := null; var k : OclAny := null; Sequence{n,t1,t2,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var participants : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var v1 : OclAny := null; var v2 : OclAny := null; Sequence{v1,v2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{i + 1}->union(Sequence{ Set{v2 * t1 * (1 - (k / 100)) + v1 * t2, v1 * t1 * (1 - (k / 100)) + v2 * t2}->max() })) : participants)) ; ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Pair : index=0 max_h=0 def __init__(self,index,max_h)->None : self.index=index self.max_h=max_h def get_max_h(pair): return pair.max_h def main(): n,t1,t2,k=map(int,input().split(" ")) list_obj=[] for i in range(0,n): sa,sb=map(int,input().split(" ")) sat1=sa*t1 sbt1=sb*t1 sat2=sa*t2 sbt2=sb*t2 per=k/100 eq1=(sat1-(sat1*per))+sbt2 eq2=(sbt1-(sbt1*per))+sat2 max_h=round(max(eq1,eq2),2) p=Pair(i,max_h) list_obj.append(p) list_obj.sort(key=get_max_h,reverse=True) for i in range(0,n): print(f"{list_obj[i].index+1}{list_obj[i].max_h:.2f}") if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class Pair { static operation newPair() : Pair pre: true post: Pair->exists( _x | result = _x ); static attribute index : int := 0; static attribute max_h : int := 0; operation __init__(index : OclAny,max_h : OclAny) : OclAny pre: true post: true activity: self.index := index ; self.max_h := max_h; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation get_max_h(pair : OclAny) : OclAny pre: true post: true activity: return pair.max_h; operation main() pre: true post: true activity: var n : OclAny := null; var t1 : OclAny := null; var t2 : OclAny := null; var k : OclAny := null; Sequence{n,t1,t2,k} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var list_obj : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var sa : OclAny := null; var sb : OclAny := null; Sequence{sa,sb} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var sat1 : double := sa * t1 ; var sbt1 : double := sb * t1 ; var sat2 : double := sa * t2 ; var sbt2 : double := sb * t2 ; var per : double := k / 100 ; var eq1 : double := (sat1 - (sat1 * per)) + sbt2 ; var eq2 : double := (sbt1 - (sbt1 * per)) + sat2 ; max_h := MathLib.roundN(Set{eq1, eq2}->max(), 2) ; var p : Pair := (Pair.newPair()).initialise(i, max_h) ; execute ((p) : list_obj)) ; list_obj := list_obj->sort() ; for i : Integer.subrange(0, n-1) do ( execute (StringLib.formattedString("{list_obj[i].index+1}{list_obj[i].max_h:.2f}"))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t1,t2,k=map(int,input().split()) growths=[] for i in range(n): a,b=map(int,input().split()) growths.append((i+1,max((a*t1)*(1-k/100)+b*t2,b*t1*(1-k/100)+a*t2))) growths.sort(key=lambda x :(-x[1],x[0])) for i in range(n): print(growths[i][0],'{:.2f}'.format(growths[i][1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t1 : OclAny := null; var t2 : OclAny := null; var k : OclAny := null; Sequence{n,t1,t2,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var growths : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{i + 1, Set{(a * t1) * (1 - k / 100) + b * t2, b * t1 * (1 - k / 100) + a * t2}->max()}) : growths)) ; growths := growths->sort() ; for i : Integer.subrange(0, n-1) do ( execute (growths[i+1]->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- parti,time1,time2,dec=list(map(int,input().split())); dic={} for i in range(1,parti+1): speed1,speed2=list(map(int,input().split())) len1=speed1*time1*((100-dec)/100)+speed2*time2 len2=speed2*time1*((100-dec)/100)+speed1*time2 if len2>len1 : if len2 in dic : dic[len2]=dic[len2]+[i] else : dic[len2]=[i] else : if len1 in dic : dic[len1]=dic[len1]+[i] else : dic[len1]=[i] arr=list(dic.keys()); arr.sort() for i in arr[: :-1]: if len(dic[i])==1 : print(*dic[i],"%.2f" % i) else : dic[i].sort() for j in dic[i]: print(j,"%.2f" % i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var parti : OclAny := null; var time1 : OclAny := null; var time2 : OclAny := null; var dec : OclAny := null; Sequence{parti,time1,time2,dec} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); var dic : OclAny := Set{} ; for i : Integer.subrange(1, parti + 1-1) do ( var speed1 : OclAny := null; var speed2 : OclAny := null; Sequence{speed1,speed2} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var len1 : double := speed1 * time1 * ((100 - dec) / 100) + speed2 * time2 ; var len2 : double := speed2 * time1 * ((100 - dec) / 100) + speed1 * time2 ; if (len2->compareTo(len1)) > 0 then ( if (dic)->includes(len2) then ( dic[len2+1] := dic[len2+1]->union(Sequence{ i }) ) else ( dic[len2+1] := Sequence{ i } ) ) else ( if (dic)->includes(len1) then ( dic[len1+1] := dic[len1+1]->union(Sequence{ i }) ) else ( dic[len1+1] := Sequence{ i } ) )) ; var arr : Sequence := (dic.keys()); arr := arr->sort() ; for i : arr(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if (dic[i+1])->size() = 1 then ( execute ((argument * (test (logical_test (comparison (expr (atom (name dic)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))->display() ) else ( (expr (atom (name dic)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name sort) (arguments ( )))) ; for j : dic[i+1] do ( execute (j)->display()) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t1,t2,k=map(int,input().split()) participants=[] for i in range(n): v1,v2=map(int,input().split()) size1=v1*t1*(1-(k/100))+v2*t2 size2=v2*t1*(1-(k/100))+v1*t2 participants.append([i+1,max(size1,size2)]) participants=sorted(participants,key=lambda l : l[1],reverse=True) [print(part[0],"{:.2f}".format(part[1]))for part in participants] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t1 : OclAny := null; var t2 : OclAny := null; var k : OclAny := null; Sequence{n,t1,t2,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var participants : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var v1 : OclAny := null; var v2 : OclAny := null; Sequence{v1,v2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var size1 : double := v1 * t1 * (1 - (k / 100)) + v2 * t2 ; var size2 : double := v2 * t1 * (1 - (k / 100)) + v1 * t2 ; execute ((Sequence{i + 1}->union(Sequence{ Set{size1, size2}->max() })) : participants)) ; participants := participants->sortedBy($x | (lambda l : OclAny in (l[1+1]))->apply($x)) ; ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools,sys def read_line(*types): return[f(a)for a,f in zip(input().split(),types)] s,=read_line(str) a=int(s[0]) b=int(s[1]) c=int(s[2]) d=int(s[3]) for p in itertools.product((1,-1),(1,-1),(1,-1)): n=a+p[0]*b+p[1]*c+p[2]*d if n==7 : print('%d%+d%+d%+d=7' %(a,p[0]*b,p[1]*c,p[2]*d)) sys.exit(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name s)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name s)))))) ,)} := read_line(OclType["String"]) ; var a : int := ("" + ((s->first())))->toInteger() ; var b : int := ("" + ((s[1+1])))->toInteger() ; var c : int := ("" + ((s[2+1])))->toInteger() ; var d : int := ("" + ((s[3+1])))->toInteger() ; for p : itertools.product(Sequence{1, -1}, Sequence{1, -1}, Sequence{1, -1}) do ( var n : int := a + p->first() * b + p[1+1] * c + p[2+1] * d ; if n = 7 then ( execute (StringLib.format('%d%+d%+d%+d=7',Sequence{a, p->first() * b, p[1+1] * c, p[2+1] * d}))->display() ; sys.exit(0) ) else skip); operation read_line(types : OclAny : Sequence(OclAny)) : OclAny pre: true post: true activity: (args * (named_parameter (name types))) return Integer.subrange(1, input().split()->size())->collect( _indx | Sequence{input().split()->at(_indx), types->at(_indx)} )->select(_tuple | true)->collect(_tuple | let a : OclAny = _tuple->at(1) in let f : OclAny = _tuple->at(2) in (f(a))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def Distinct_Prime_factors(a): m=[] for i in range(len(a)): sq=int(math.sqrt(a[i])) for j in range(2,sq+1): if(a[i]% j==0): m.append(j) while(a[i]% j==0): a[i]//=j if(a[i]>2): m.append(a[i]) return len(m) if __name__=="__main__" : a=[1,2,3,4,5] print(Distinct_Prime_factors(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( a := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ; execute (Distinct_Prime_factors(a))->display() ) else skip; operation Distinct_Prime_factors(a : OclAny) : OclAny pre: true post: true activity: var m : Sequence := Sequence{} ; for i : Integer.subrange(0, (a)->size()-1) do ( var sq : int := ("" + (((a[i+1])->sqrt())))->toInteger() ; for j : Integer.subrange(2, sq + 1-1) do ( if (a[i+1] mod j = 0) then ( execute ((j) : m) ; while (a[i+1] mod j = 0) do ( a[i+1] := a[i+1] div j) ) else skip) ; if (a[i+1] > 2) then ( execute ((a[i+1]) : m) ) else skip) ; return (m)->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def mergeSort(a): if len(a)>1 : mid=len(a)//2 L=a[: mid] R=a[mid :] mergeSort(L) mergeSort(R) a.clear() while len(L)>0 and len(R)<0 : if L[0]<=R[0]: a.append(L[0]) L.pop(0) else : a.append(R[0]) R.pop(0) for i in L : a.append(i) for i in R : a.append(i) a=[12,11,13,5,6,7] print("Given array is") print(*a) mergeSort(a) print("Sorted array is : ") print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{12}->union(Sequence{11}->union(Sequence{13}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 7 }))))) ; execute ("Given array is")->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display() ; mergeSort(a) ; execute ("Sorted array is : ")->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display(); operation mergeSort(a : OclAny) pre: true post: true activity: if (a)->size() > 1 then ( var mid : int := (a)->size() div 2 ; var L : OclAny := a.subrange(1,mid) ; var R : OclAny := a.subrange(mid+1) ; mergeSort(L) ; mergeSort(R) ; execute (a /<: a) ; while (L)->size() > 0 & (R)->size() < 0 do ( if (L->first()->compareTo(R->first())) <= 0 then ( execute ((L->first()) : a) ; L := L->excludingAt(0+1) ) else ( execute ((R->first()) : a) ; R := R->excludingAt(0+1) )) ; for i : L do ( execute ((i) : a)) ; for i : R do ( execute ((i) : a)) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) candidate=0 limark_count=0 for i in range(1,64): ip=2**i for j in range(i-1): jp=2**j candidate=ip-jp-1 if candidate>=a and candidate<=b : limark_count+=1 if candidate>=b : break print(limark_count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var candidate : int := 0 ; var limark_count : int := 0 ; for i : Integer.subrange(1, 64-1) do ( var ip : double := (2)->pow(i) ; for j : Integer.subrange(0, i - 1-1) do ( var jp : double := (2)->pow(j) ; candidate := ip - jp - 1 ; if (candidate->compareTo(a)) >= 0 & (candidate->compareTo(b)) <= 0 then ( limark_count := limark_count + 1 ) else skip) ; if (candidate->compareTo(b)) >= 0 then ( break ) else skip) ; execute (limark_count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) ans=0 for l in range(1,65): n=(1<collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; for l : Integer.subrange(1, 65-1) do ( var n : double := (1 * (2->pow(l))) - 1 ; for i : Integer.subrange(0, l - 1-1) do ( var m : int := MathLib.bitwiseXor(n, (1 * (2->pow(i)))) ; if (a->compareTo(m)) <= 0 & (m <= b) then ( ans := ans + 1 ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate def high_bound(arr,val): l=-1 r=len(arr) while r-l>1 : m=(l+r)//2 if arr[m]<=val : l=m else : r=m return r for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) a_min=list(accumulate(a,min)) b_max=list(accumulate(b,max)) ans=n-1 for i in range(n): if i and a_min[i]==a_min[i-1]: continue ans=min(ans,i+high_bound(b_max,a_min[i])) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a_min : Sequence := (accumulate(a, min)) ; var b_max : Sequence := (accumulate(b, max)) ; var ans : double := n - 1 ; for i : Integer.subrange(0, n-1) do ( if i & a_min[i+1] = a_min[i - 1+1] then ( continue ) else skip ; ans := Set{ans, i + high_bound(b_max, a_min[i+1])}->min()) ; execute (ans)->display()); operation high_bound(arr : OclAny, val : OclAny) : OclAny pre: true post: true activity: var l : int := -1 ; var r : int := (arr)->size() ; while r - l > 1 do ( var m : int := (l + r) div 2 ; if (arr[m+1]->compareTo(val)) <= 0 then ( l := m ) else ( r := m )) ; return r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) allPerhaps=[] for cntN in range(1,63): for i in range(cntN-1): numb=((1<collect( _x | (OclType["int"])->apply(_x) ) ; var allPerhaps : Sequence := Sequence{} ; for cntN : Integer.subrange(1, 63-1) do ( for i : Integer.subrange(0, cntN - 1-1) do ( var numb : int := MathLib.bitwiseXor(((1 * (2->pow(cntN))) - 1), (1 * (2->pow(i)))) ; execute ((numb) : allPerhaps))) ; var ans : int := 0 ; for i : allPerhaps do ( if (a->compareTo(i)) <= 0 & (i <= b) then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) allPerhaps=[] for cntN in range(1,63): for i in range(cntN-1): numb=((1<collect( _x | (OclType["int"])->apply(_x) ) ; var allPerhaps : Sequence := Sequence{} ; for cntN : Integer.subrange(1, 63-1) do ( for i : Integer.subrange(0, cntN - 1-1) do ( var numb : int := MathLib.bitwiseXor(((1 * (2->pow(cntN))) - 1), (1 * (2->pow(i)))) ; execute ((numb) : allPerhaps))) ; var ans : int := 0 ; for i : allPerhaps do ( if (a->compareTo(i)) <= 0 & (i <= b) then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import log2 a,b=map(int,input().split()) top=int(log2(b))+1 low=int(log2(a)) ans=0 for i in range(low+1,top+1): current=2**i-1 for k in range(i-1): if a<=current-2**k<=b : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var top : int := ("" + ((log2(b))))->toInteger() + 1 ; var low : int := ("" + ((log2(a))))->toInteger() ; var ans : int := 0 ; for i : Integer.subrange(low + 1, top + 1-1) do ( var current : double := (2)->pow(i) - 1 ; for k : Integer.subrange(0, i - 1-1) do ( if (a->compareTo(current - (2)->pow(k))) <= 0 & (current - (2)->pow(k) <= b) then ( ans := ans + 1 ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def arcLength(diameter,angle): if angle>=360 : print("Angle cannot be formed") return 0 else : arc=(3.142857142857143*diameter)*(angle/360.0) return arc diameter=25.0 angle=45.0 arc_len=arcLength(diameter,angle) print(arc_len) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; diameter := 25.0 ; angle := 45.0 ; var arc_len : OclAny := arcLength(diameter, angle) ; execute (arc_len)->display(); operation arcLength(diameter : OclAny, angle : OclAny) : OclAny pre: true post: true activity: if angle >= 360 then ( execute ("Angle cannot be formed")->display() ; return 0 ) else ( var arc : double := (3.142857142857143 * diameter) * (angle / 360.0) ; return arc ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find_count(ele): count=0 for i in range(len(ele)): p=[] c=0 j=len(ele)-1 while j>=(len(ele)-1-i)and j>=0 : p.append(ele[j]) j-=1 j=len(ele)-1 k=0 while j>=0 : if ele[j]!=p[k]: break j-=1 k+=1 if k==len(p): c+=1 k=0 count=max(count,c) return count def solve(n): count=1 ele=[] for i in range(n): print(count,end=" ") ele.append(count) count=find_count(ele) if __name__=="__main__" : n=10 solve(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 10 ; solve(n) ) else skip; operation find_count(ele : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, (ele)->size()-1) do ( var p : Sequence := Sequence{} ; var c : int := 0 ; var j : double := (ele)->size() - 1 ; while (j->compareTo(((ele)->size() - 1 - i))) >= 0 & j >= 0 do ( execute ((ele[j+1]) : p) ; j := j - 1) ; j := (ele)->size() - 1 ; var k : int := 0 ; while j >= 0 do ( if ele[j+1] /= p[k+1] then ( break ) else skip ; j := j - 1 ; k := k + 1 ; if k = (p)->size() then ( c := c + 1 ; k := 0 ) else skip) ; count := Set{count, c}->max()) ; return count; operation solve(n : OclAny) pre: true post: true activity: count := 1 ; ele := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (count)->display() ; execute ((count) : ele) ; count := find_count(ele)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) ABs=[tuple(map(int,input().split()))for _ in range(N)] bsum=0 for A,B in ABs : bsum+=B dp=[[-1]*(bsum+1)for _ in range(N+1)] dp[0][0]=0 for i,(A,B)in enumerate(ABs): for j in reversed(range(i+1)): for k in range(bsum+1): if dp[j][k]==-1 : continue nk=min(bsum,k+2*A-B) dp[j+1][nk]=max(dp[j+1][nk],dp[j][k]+B) answer=[0]*(N) for j in range(1,N+1): for k in range(bsum+1): if dp[j][k]==-1 : continue answer[j-1]=max(answer[j-1],dp[j][k]+k) print(*[a/2 for a in answer]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ABs : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var bsum : int := 0 ; for _tuple : ABs do (var _indx : int := 1; var A : OclAny := _tuple->at(_indx); _indx := _indx + 1; var B : OclAny := _tuple->at(_indx); bsum := bsum + B) ; var dp : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ -1 }, (bsum + 1)))) ; dp->first()->first() := 0 ; for _tuple : Integer.subrange(1, (ABs)->size())->collect( _indx | Sequence{_indx-1, (ABs)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{A, B} : OclAny := _tuple->at(_indx); for j : (Integer.subrange(0, i + 1-1))->reverse() do ( for k : Integer.subrange(0, bsum + 1-1) do ( if dp[j+1][k+1] = -1 then ( continue ) else skip ; var nk : OclAny := Set{bsum, k + 2 * A - B}->min() ; dp[j + 1+1][nk+1] := Set{dp[j + 1+1][nk+1], dp[j+1][k+1] + B}->max()))) ; var answer : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N)) ; for j : Integer.subrange(1, N + 1-1) do ( for k : Integer.subrange(0, bsum + 1-1) do ( if dp[j+1][k+1] = -1 then ( continue ) else skip ; answer[j - 1+1] := Set{answer[j - 1+1], dp[j+1][k+1] + k}->max())) ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name a))) / (expr (atom (number (integer 2)))))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name answer))))))) ])))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def strScore(str,s,n): score=0 index=0 for i in range(n): if(str[i]==s): for j in range(len(s)): score+=(ord(s[j])-ord('a')+1) index=i+1 break score=score*index return score str=["sahil","shashanak","sanjit","abhinav","mohit"] s="abhinav" n=len(str) score=strScore(str,s,n); print(score) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclType["String"] := Sequence{"sahil"}->union(Sequence{"shashanak"}->union(Sequence{"sanjit"}->union(Sequence{"abhinav"}->union(Sequence{ "mohit" })))) ; s := "abhinav" ; n := (OclType["String"])->size() ; score := strScore(OclType["String"], s, n); ; execute (score)->display(); operation strScore(OclType["String"] : OclAny, s : OclAny, n : OclAny) : OclAny pre: true post: true activity: var score : int := 0 ; var index : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (("" + ([i+1])) = s) then ( for j : Integer.subrange(0, (s)->size()-1) do ( score := score + ((s[j+1])->char2byte() - ('a')->char2byte() + 1)) ; index := i + 1 ; break ) else skip) ; score := score * index ; return score; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) *A,=map(int,input().split()) l=0 r=0 ans=0 x=0 for l in range(N): while rtoInteger() ; (testlist_star_expr (star_expr * (expr (atom (name A)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name A)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : int := 0 ; var r : int := 0 ; var ans : int := 0 ; var x : int := 0 ; for l : Integer.subrange(0, N-1) do ( while (r->compareTo(N)) < 0 & MathLib.bitwiseAnd(x, A[r+1]) = 0 do ( x := x xor A[r+1] ; r := r + 1) ; ans := ans + r - l ; if l = r then ( r := r + 1 ; x := 0 ) else ( x := x xor A[l+1] )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left,bisect_right n=int(input()) al=list(map(int,input().split())) al2=[[]for _ in range(20)] for a in al : for i in range(20): if a &(1<0 : al2[i].append(1) else : al2[i].append(0) al2_cum=[] for i in range(20): cum=0 cumsum=[0] for a in al2[i]: cum+=a cumsum.append(cum) al2_cum.append(cumsum) ans=0 for i in range(n+1): curr_maxind=0 for j in range(20): curr_cum=al2_cum[j] curr_1_cnt=curr_cum[i] if curr_1_cnt<=1 : continue else : ind=bisect_left(curr_cum,curr_1_cnt-1) curr_maxind=max(curr_maxind,ind) ans+=(i-curr_maxind) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var al : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var al2 : Sequence := Integer.subrange(0, 20-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for a : al do ( for i : Integer.subrange(0, 20-1) do ( if MathLib.bitwiseAnd(a, (1 * (2->pow(i)))) > 0 then ( (expr (atom (name al2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))) ) else ( (expr (atom (name al2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))) ))) ; var al2_cum : Sequence := Sequence{} ; for i : Integer.subrange(0, 20-1) do ( var cum : int := 0 ; var cumsum : Sequence := Sequence{ 0 } ; for a : al2[i+1] do ( cum := cum + a ; execute ((cum) : cumsum)) ; execute ((cumsum) : al2_cum)) ; var ans : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( var curr_maxind : int := 0 ; for j : Integer.subrange(0, 20-1) do ( var curr_cum : OclAny := al2_cum[j+1] ; var curr var curr_cum : OclAny := al2_cum[j+1]_cnt : OclAny := curr_cum[i+1] ; if curr var curr_cum : OclAny := al2_cum[j+1]_cnt <= 1 then ( continue ) else ( var ind : OclAny := bisect_left(curr_cum, currcurr_cum_cnt - 1) ; curr_maxind := Set{curr_maxind, ind}->max() )) ; ans := ans + (i - curr_maxind)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) line=[int(i)for i in input().split()] count=0 sum=line[0] r=1 count_tmp=1 for L in range(N-1): for r in range(r,N): sum_tmp=sum+line[r] if sum_tmp==sum ^ line[r]: sum=sum_tmp count_tmp+=1 if r==N-1 : r+=1 else : break count+=count_tmp count_tmp-=1 sum-=line[L] print(count+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var line : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var count : int := 0 ; var sum : OclAny := line->first() ; var r : int := 1 ; var count_tmp : int := 1 ; for L : Integer.subrange(0, N - 1-1) do ( for r : Integer.subrange(r, N-1) do ( var sum_tmp : OclAny := sum + line[r+1] ; if sum_tmp = MathLib.bitwiseXor(sum, line[r+1]) then ( sum := sum_tmp ; count_tmp := count_tmp + 1 ; if r = N - 1 then ( r := r + 1 ) else skip ) else ( break )) ; count := count + count_tmp ; count_tmp := count_tmp - 1 ; sum := sum - line[L+1]) ; execute (count + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) A=list(map(int,input().split())) def func(c,S): b=list(format(c,'b')) b=list(reversed(b)) flag=True for i in range(len(b)): if b[i]=='1' and S[i]==1 : flag=False break return flag p=0 q=0 S=[0]*30 ans=0 for p in range(n): while qtoInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; var p : int := 0 ; var q : int := 0 ; S := MatrixLib.elementwiseMult(Sequence{ 0 }, 30) ; var ans : int := 0 ; for p : Integer.subrange(0, n-1) do ( while (q->compareTo(n)) < 0 & func(A[q+1], S) do ( b := ((A[q+1] + ""))->characters() ; b := ((b)->reverse()) ; for i : Integer.subrange(0, (b)->size()-1) do ( if b[i+1] = '1' then ( S[i+1] := S[i+1] + 1 ) else skip) ; q := q + 1) ; ans := ans + q - p ; if p = q then ( q := q + 1 ) else ( b := ((A[p+1] + ""))->characters() ; b := ((b)->reverse()) ; for i : Integer.subrange(0, (b)->size()-1) do ( if b[i+1] = '1' then ( S[i+1] := S[i+1] - 1 ) else skip) )) ; execute (ans)->display(); operation func(c : OclAny, S : OclAny) : OclAny pre: true post: true activity: var b : Sequence := ((c + ""))->characters() ; b := ((b)->reverse()) ; var flag : boolean := true ; for i : Integer.subrange(0, (b)->size()-1) do ( if b[i+1] = '1' & S[i+1] = 1 then ( flag := false ; break ) else skip) ; return flag; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout def get_ints(): return map(int,stdin.readline().split()) def PRINT(s): stdout.write(s+'\n') def logic(n,a,b): arr1=[0]*n arr2=[0]*n for i in range(n): arr1[(a[i]-1)//2]=i arr2[(b[i]//2)-1]=i m=arr2[-1] mins=[0]*n for i in range(n-1,-1,-1): m=min(m,arr2[i]) mins[i]=m+arr1[i] return str(min(mins)) for w in range(int(stdin.readline())): n=int(stdin.readline()) a=[int(x)for x in stdin.readline().split()] b=[int(x)for x in stdin.readline().split()] PRINT(logic(n,a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; for w : Integer.subrange(0, ("" + ((stdin.readLine())))->toInteger()-1) do ( n := ("" + ((stdin.readLine())))->toInteger() ; a := stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; b := stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; PRINT(logic(n, a, b))); operation get_ints() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation PRINT(s : OclAny) pre: true post: true activity: stdout.write(s + ' '); operation logic(n : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var arr1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var arr2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( arr1[(a[i+1] - 1) div 2+1] := i ; arr2[(b[i+1] div 2) - 1+1] := i) ; var m : OclAny := arr2->last() ; var mins : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( m := Set{m, arr2[i+1]}->min() ; mins[i+1] := m + arr1[i+1]) ; return ("" + (((mins)->min()))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) def check(tmp,x): for i in range(20): if(x>>i)& 1 and(tmp>>i)& 1 : return False return True ans=0 tmp=0 r=0 for l in range(n): if rtoInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; var ans : int := 0 ; tmp := 0 ; var r : int := 0 ; for l : Integer.subrange(0, n-1) do ( if (r->compareTo(l)) < 0 then ( r := l ) else skip ; while (r->compareTo(n)) < 0 & check(tmp, a[r+1]) do ( tmp := tmp + a[r+1] ; r := r + 1) ; ans := ans + r - l ; tmp := tmp - a[l+1]) ; execute (ans)->display(); operation check(tmp : OclAny, x : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, 20-1) do ( if MathLib.bitwiseAnd((x /(2->pow(i))), 1) & MathLib.bitwiseAnd((tmp /(2->pow(i))), 1) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): LIMIT=100 partitions=[] for i in range(LIMIT+1): partitions.append([None]*(LIMIT+1)) for j in reversed(range(LIMIT+1)): if j==i : val=1 elif j>i : val=0 elif j==0 : val=partitions[i][j+1] else : val=partitions[i][j+1]+partitions[i-j][j] partitions[i][j]=val ans=partitions[LIMIT][1]-1 return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LIMIT : int := 100 ; var partitions : Sequence := Sequence{} ; for i : Integer.subrange(0, LIMIT + 1-1) do ( execute ((MatrixLib.elementwiseMult(Sequence{ null }, (LIMIT + 1))) : partitions) ; for j : (Integer.subrange(0, LIMIT + 1-1))->reverse() do ( if j = i then ( var val : int := 1 ) else (if (j->compareTo(i)) > 0 then ( val := 0 ) else (if j = 0 then ( val := partitions[i+1][j + 1+1] ) else ( val := partitions[i+1][j + 1+1] + partitions[i - j+1][j+1] ) ) ) ; partitions[i+1][j+1] := val)) ; var ans : double := partitions[LIMIT+1][1+1] - 1 ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def largestOddDigit(n): maxOdd=-1 while(n>0): digit=n % 10 if(digit % 2==1 and digit>maxOdd): maxOdd=digit n=n//10 return maxOdd def getProduct(n): maxOdd=largestOddDigit(n) if(maxOdd==-1): return-1 return(n*maxOdd) if __name__=="__main__" : n=12345 print(getProduct(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 12345 ; execute (getProduct(n))->display() ) else skip; operation largestOddDigit(n : OclAny) : OclAny pre: true post: true activity: var maxOdd : int := -1 ; while (n > 0) do ( var digit : int := n mod 10 ; if (digit mod 2 = 1 & (digit->compareTo(maxOdd)) > 0) then ( maxOdd := digit ) else skip ; n := n div 10) ; return maxOdd; operation getProduct(n : OclAny) : OclAny pre: true post: true activity: maxOdd := largestOddDigit(n) ; if (maxOdd = -1) then ( return -1 ) else skip ; return (n * maxOdd); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def subsetSums(arr,l,r,sum=0): if l>r : print(sum,end=" ") return subsetSums(arr,l+1,r,sum+arr[l]) subsetSums(arr,l+1,r,sum) arr=[5,4,3] n=len(arr) subsetSums(arr,0,n-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{5}->union(Sequence{4}->union(Sequence{ 3 })) ; var n : int := (arr)->size() ; subsetSums(arr, 0, n - 1); operation subsetSums(arr : OclAny, l : OclAny, r : OclAny, sum : int) pre: true post: true activity: if sum->oclIsUndefined() then sum := 0 else skip; if (l->compareTo(r)) > 0 then ( execute (sum)->display() ; return ) else skip ; subsetSums(arr, l + 1, r, sum + arr[l+1]) ; subsetSums(arr, l + 1, r, sum); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- moves=[{'F' : lambda i,j,x :(i,min(n,j+x)),'B' : lambda i,j,x :(i,max(1,j-x))},{'F' : lambda i,j,x :(min(m,i+x),j),'B' : lambda i,j,x :(max(1,i-x),j)},{'F' : lambda i,j,x :(i,max(1,j-x)),'B' : lambda i,j,x :(i,min(n,j+x))},{'F' : lambda i,j,x :(max(1,i-x),j),'B' : lambda i,j,x :(min(m,i+x),j)}] turns={'R' : lambda i :(i+1)% 4,'L' : lambda i :(i-1)% 4} while True : m,n=map(int,input().split()) if not m : break i,j=1,1 cci=0 while True : cmd=input() ch=cmd[0] if ch in 'FB' : i,j=moves[cci][ch](i,j,int(cmd.split()[1])) elif ch in 'RL' : cci=turns[ch](cci) else : print(i,j) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var moves : Sequence := Sequence{Map{ 'F' |-> lambda i : OclAny, j : OclAny, x : OclAny in (Sequence{i, Set{n, j + x}->min()}) }->union(Map{ 'B' |-> lambda i : OclAny, j : OclAny, x : OclAny in (Sequence{i, Set{1, j - x}->max()}) })}->union(Sequence{Map{ 'F' |-> lambda i : OclAny, j : OclAny, x : OclAny in (Sequence{Set{m, i + x}->min(), j}) }->union(Map{ 'B' |-> lambda i : OclAny, j : OclAny, x : OclAny in (Sequence{Set{1, i - x}->max(), j}) })}->union(Sequence{Map{ 'F' |-> lambda i : OclAny, j : OclAny, x : OclAny in (Sequence{i, Set{1, j - x}->max()}) }->union(Map{ 'B' |-> lambda i : OclAny, j : OclAny, x : OclAny in (Sequence{i, Set{n, j + x}->min()}) })}->union(Sequence{ Map{ 'F' |-> lambda i : OclAny, j : OclAny, x : OclAny in (Sequence{Set{1, i - x}->max(), j}) }->union(Map{ 'B' |-> lambda i : OclAny, j : OclAny, x : OclAny in (Sequence{Set{m, i + x}->min(), j}) }) }))) ; var turns : Map := Map{ 'R' |-> lambda i : OclAny in ((i + 1) mod 4) }->union(Map{ 'L' |-> lambda i : OclAny in ((i - 1) mod 4) }) ; while true do ( var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if not(m) then ( break ) else skip ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{1,1} ; var cci : int := 0 ; while true do ( var cmd : String := (OclFile["System.in"]).readLine() ; var ch : OclAny := cmd->first() ; if ('FB')->characters()->includes(ch) then ( var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := moves[cci+1][ch+1](i, j, ("" + ((cmd.split()[1+1])))->toInteger()) ) else (if ('RL')->characters()->includes(ch) then ( cci := turns[ch+1](cci) ) else ( execute (i)->display() ; break ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p,q=[int(x)for x in input().split()] n=int(input()) a=[int(x)for x in input().split()] for x in a : p-=q*x p,q=q,p if(q==0): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for x : a do ( p := p - q * x ; var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := Sequence{q,p}) ; if (q = 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import* p,q=map(int,input().split()) a1=Fraction(p,q) n=int(input()) aaa=list(map(int,input().split())) d2=Fraction(aaa[-1],1) for i in range(2,n+1): d2=1/d2+aaa[-i] print("YES" if a1==d2 else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a1 : OclAny := Fraction(p, q) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var aaa : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d2 : OclAny := Fraction(aaa->last(), 1) ; for i : Integer.subrange(2, n + 1-1) do ( d2 := 1 / d2 + aaa->reverse()->at(-(-i))) ; execute (if a1 = d2 then "YES" else "NO" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,random,bisect from collections import deque,defaultdict from heapq import heapify,heappop,heappush from itertools import permutations from math import gcd,log input=lambda : sys.stdin.readline().rstrip() mi=lambda : map(int,input().split()) li=lambda : list(mi()) p,q=mi() n=int(input()) a=li() g=gcd(p,q) p,q=p//g,q//g u,v,id=a[n-1],1,n-2 while id>=0 : u,v=v,u u=a[id]*v+u id=id-1 g=gcd(u,v) u,v=u//g,v//g if u==p and v==q : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var mi : Function := lambda $$ : OclAny in ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var li : Function := lambda $$ : OclAny in ((mi->apply())) ; var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := mi->apply() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := li->apply() ; var g : OclAny := gcd(p, q) ; var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := Sequence{p div g,q div g} ; var u : OclAny := null; var v : OclAny := null; var id : OclAny := null; Sequence{u,v,id} := Sequence{a[n - 1+1],1,n - 2} ; while id >= 0 do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := Sequence{v,u} ; var u : double := a[id+1] * v + u ; var id : double := id - 1) ; g := gcd(u, v) ; var v : OclAny := null; Sequence{u,v} := Sequence{u div g,v div g} ; if u = p & v = q then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import Fraction n,m=map(int,input().split(' ')) k=(int)(input()) n=Fraction(n,m) a=list(map(int,input().split(' '))) x=Fraction(0,1) a.reverse() for i in range(0,k-1): x=Fraction(1,a[i]+x) x+=a[k-1] if x==n : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var k : OclAny := (OclType["int"])((OclFile["System.in"]).readLine()) ; var n : OclAny := Fraction(n, m) ; var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := Fraction(0, 1) ; a := a->reverse() ; for i : Integer.subrange(0, k - 1-1) do ( x := Fraction(1, a[i+1] + x)) ; x := x + a[k - 1+1] ; if x = n then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import Fraction n,m=map(int,input().split(' ')) k=(int)(input()) n=Fraction(n,m) a=list(map(int,input().split(' '))) x=Fraction(0,1) a.reverse() for i in range(0,k-1): x=Fraction(1,a[i]+x) x+=a[k-1] if x==n : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var k : OclAny := (OclType["int"])((OclFile["System.in"]).readLine()) ; var n : OclAny := Fraction(n, m) ; var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := Fraction(0, 1) ; a := a->reverse() ; for i : Integer.subrange(0, k - 1-1) do ( x := Fraction(1, a[i+1] + x)) ; x := x + a[k - 1+1] ; if x = n then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def findCircleNum(self,M): visited=[0]*len(M) count=0 for i in range(len(M)): if visited[i]==0 : self.dfs(M,visited,i) count+=1 return count def dfs(self,M,visited,i): for j in range(len(M)): if M[i][j]==1 and visited[j]==0 : visited[j]=1 self.dfs(M,visited,j) ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation findCircleNum(M : OclAny) : OclAny pre: true post: true activity: var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (M)->size()) ; var count : int := 0 ; for i : Integer.subrange(0, (M)->size()-1) do ( if visited[i+1] = 0 then ( self.dfs(M, visited, i) ; count := count + 1 ) else skip) ; return count; operation dfs(M : OclAny,visited : OclAny,i : OclAny) pre: true post: true activity: for j : Integer.subrange(0, (M)->size()-1) do ( if M[i+1][j+1] = 1 & visited[j+1] = 0 then ( visited[j+1] := 1 ; self.dfs(M, visited, j) ) else skip); } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import Counter def get_ints(): return list(map(int,sys.stdin.readline().strip().split())) sys.setrecursionlimit(20000) n=int(input()) resources=[] for _ in range(n): x,y=get_ints() resources.append((x,y)) min_x,min_y=resources[0][0],resources[0][1] max_x,max_y=resources[0][0],resources[0][1] for x,y in resources : if x>max_x : max_x=x if xmax_y : max_y=y if ytoInteger() ; var resources : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := get_ints() ; execute ((Sequence{x, y}) : resources)) ; var min_x : OclAny := null; var min_y : OclAny := null; Sequence{min_x,min_y} := Sequence{resources->first()->first(),resources->first()[1+1]} ; var max_x : OclAny := null; var max_y : OclAny := null; Sequence{max_x,max_y} := Sequence{resources->first()->first(),resources->first()[1+1]} ; for _tuple : resources do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if (x->compareTo(max_x)) > 0 then ( var max_x : OclAny := x ) else skip ; if (x->compareTo(min_x)) < 0 then ( var min_x : OclAny := x ) else skip ; if (y->compareTo(max_y)) > 0 then ( var max_y : OclAny := y ) else skip ; if (y->compareTo(min_y)) < 0 then ( var min_y : OclAny := y ) else skip) ; execute ((Set{(max_x - min_x), (max_y - min_y)}->max())->pow(2))->display(); operation get_ints() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def factorial(n): res=1 for i in range(1,n+1): res=res*i return res def count(word): freq=[0 for i in range(30)] vowel=0 consonant=0 for i in range(len(word)): freq[ord(word[i])-65]+=1 if(word[i]=='A' or word[i]=='E' or word[i]=='I' or word[i]=='O' or word[i]=='U'): vowel+=1 else : consonant+=1 vowelArrange=factorial(vowel) vowelArrange//=factorial(freq[0]) vowelArrange//=factorial(freq[4]) vowelArrange//=factorial(freq[8]) vowelArrange//=factorial(freq[14]) vowelArrange//=factorial(freq[20]) consonantArrange=factorial(consonant) for i in range(26): if(i!=0 and i!=4 and i!=8 and i!=14 and i!=20): consonantArrange//=factorial(freq[i]) total=vowelArrange*consonantArrange return total word="COMPUTER" ans=count(word) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; word := "COMPUTER" ; var ans : OclAny := count(word) ; execute (ans)->display(); operation factorial(n : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; for i : Integer.subrange(1, n + 1-1) do ( res := res * i) ; return res; operation count(word : OclAny) : OclAny pre: true post: true activity: var freq : Sequence := Integer.subrange(0, 30-1)->select(i | true)->collect(i | (0)) ; var vowel : int := 0 ; var consonant : int := 0 ; for i : Integer.subrange(0, (word)->size()-1) do ( freq[(word[i+1])->char2byte() - 65+1] := freq[(word[i+1])->char2byte() - 65+1] + 1 ; if (word[i+1] = 'A' or word[i+1] = 'E' or word[i+1] = 'I' or word[i+1] = 'O' or word[i+1] = 'U') then ( vowel := vowel + 1 ) else ( consonant := consonant + 1 )) ; var vowelArrange : OclAny := factorial(vowel) ; vowelArrange := vowelArrange div factorial(freq->first()) ; vowelArrange := vowelArrange div factorial(freq[4+1]) ; vowelArrange := vowelArrange div factorial(freq[8+1]) ; vowelArrange := vowelArrange div factorial(freq[14+1]) ; vowelArrange := vowelArrange div factorial(freq[20+1]) ; var consonantArrange : OclAny := factorial(consonant) ; for i : Integer.subrange(0, 26-1) do ( if (i /= 0 & i /= 4 & i /= 8 & i /= 14 & i /= 20) then ( consonantArrange := consonantArrange div factorial(freq[i+1]) ) else skip) ; var total : double := vowelArrange * consonantArrange ; return total; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib,itertools def compute(): ans=sum(itertools.islice(filter(is_truncatable_prime,itertools.count(10)),11)) return str(ans) def is_truncatable_prime(n): i=10 while i<=n : if not eulerlib.is_prime(n % i): return False i*=10 while n>0 : if not eulerlib.is_prime(n): return False n//=10 return True if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : OclAny := (itertools.islice((itertools->count(10))->select( _x | (is_truncatable_prime)->apply(_x) = true ), 11))->sum() ; return ("" + ((ans))); operation is_truncatable_prime(n : OclAny) : OclAny pre: true post: true activity: var i : int := 10 ; while (i->compareTo(n)) <= 0 do ( if not(eulerlib.is_prime(n mod i)) then ( return false ) else skip ; i := i * 10) ; while n > 0 do ( if not(eulerlib.is_prime(n)) then ( return false ) else skip ; n := n div 10) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- kite=lambda : map(int,input().split()) _,x=kite() print(x+sum((i==x)-(icollect( _x | (OclType["int"])->apply(_x) )) ; var _anon : OclAny := null; var x : OclAny := null; Sequence{_anon,x} := kite->apply() ; execute (x + ((argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name i)))) == (comparison (expr (atom (name x)))))))) ))) - (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name i)))) < (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name kite)) (trailer (arguments ( )))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) ABs=[tuple(map(int,input().split()))for _ in range(N)] bsum=0 for A,B in ABs : bsum+=B dp=[[-1]*(bsum+1)for _ in range(N+1)] dp[0][0]=0 for i,(A,B)in enumerate(ABs): for j in reversed(range(i+1)): for k in range(bsum+1): if dp[j][k]==-1 : continue nk=min(bsum,k+2*A-B) dp[j+1][nk]=max(dp[j+1][nk],dp[j][k]+B) answer=[0]*(N) for j in range(1,N+1): for k in range(bsum+1): if dp[j][k]==-1 : continue answer[j-1]=max(answer[j-1],dp[j][k]+k) print(*[a/2 for a in answer]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ABs : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var bsum : int := 0 ; for _tuple : ABs do (var _indx : int := 1; var A : OclAny := _tuple->at(_indx); _indx := _indx + 1; var B : OclAny := _tuple->at(_indx); bsum := bsum + B) ; var dp : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ -1 }, (bsum + 1)))) ; dp->first()->first() := 0 ; for _tuple : Integer.subrange(1, (ABs)->size())->collect( _indx | Sequence{_indx-1, (ABs)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{A, B} : OclAny := _tuple->at(_indx); for j : (Integer.subrange(0, i + 1-1))->reverse() do ( for k : Integer.subrange(0, bsum + 1-1) do ( if dp[j+1][k+1] = -1 then ( continue ) else skip ; var nk : OclAny := Set{bsum, k + 2 * A - B}->min() ; dp[j + 1+1][nk+1] := Set{dp[j + 1+1][nk+1], dp[j+1][k+1] + B}->max()))) ; var answer : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N)) ; for j : Integer.subrange(1, N + 1-1) do ( for k : Integer.subrange(0, bsum + 1-1) do ( if dp[j+1][k+1] = -1 then ( continue ) else skip ; answer[j - 1+1] := Set{answer[j - 1+1], dp[j+1][k+1] + k}->max())) ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name a))) / (expr (atom (number (integer 2)))))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name answer))))))) ])))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=map(int,input().split()) a=list(map(int,input().split())) count={} for e in a : if e in count : count[e]+=1 else : count[e]=1 res=0 if x in count : res+=count[x] for i in range(x): if i not in count : res+=1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : OclAny := Set{} ; for e : a do ( if (count)->includes(e) then ( count[e+1] := count[e+1] + 1 ) else ( count[e+1] := 1 )) ; var res : int := 0 ; if (count)->includes(x) then ( res := res + count[x+1] ) else skip ; for i : Integer.subrange(0, x-1) do ( if (count)->excludes(i) then ( res := res + 1 ) else skip) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=map(int,input().split()) w=sorted(map(int,input().split())) c=0 for i in range(x): if i not in w : c+=1 if x in w : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var c : int := 0 ; for i : Integer.subrange(0, x-1) do ( if (w)->excludes(i) then ( c := c + 1 ) else skip) ; if (w)->includes(x) then ( c := c + 1 ) else skip ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() a,b=map(int,input().split()); c=set(map(int,input().split())); print(len(set(range(b))-c)+[0,1][b in c]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var c : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))); execute ((Set{}->union((Integer.subrange(0, b-1))) - c)->size() + Sequence{0}->union(Sequence{ 1 })->select((c)->includes(b)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count(S,m,n): if(n==0): return 1 if(n<0): return 0 ; if(m<=0 and n>=1): return 0 return count(S,m-1,n)+count(S,m,n-S[m-1]); arr=[1,2,3] m=len(arr) print(count(arr,m,4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var arr : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; m := (arr)->size() ; execute (count(arr, m, 4))->display(); operation count(S : OclAny, m : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return 1 ) else skip ; if (n < 0) then ( return 0; ) else skip ; if (m <= 0 & n >= 1) then ( return 0 ) else skip ; return count(S, m - 1, n) + count(S, m, n - S[m - 1+1]);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count(S,m,n): if(n==0): return 1 if(n<0): return 0 ; if(m<=0 and n>=1): return 0 return count(S,m-1,n)+count(S,m,n-S[m-1]); arr=[1,2,3] m=len(arr) print(count(arr,m,4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var arr : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; m := (arr)->size() ; execute (count(arr, m, 4))->display(); operation count(S : OclAny, m : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return 1 ) else skip ; if (n < 0) then ( return 0; ) else skip ; if (m <= 0 & n >= 1) then ( return 0 ) else skip ; return count(S, m - 1, n) + count(S, m, n - S[m - 1+1]);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() lst=list(map(str,input().split())) l1,l2=[],[] for i in range(len(lst)): l1.append(lst[i][0]) l2.append(lst[i][1]) if n[0]in l1 or n[1]in l2 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var lst : Sequence := ((input().split())->collect( _x | (OclType["String"])->apply(_x) )) ; var l1 : OclAny := null; var l2 : OclAny := null; Sequence{l1,l2} := Sequence{Sequence{},Sequence{}} ; for i : Integer.subrange(0, (lst)->size()-1) do ( execute ((lst[i+1]->first()) : l1) ; execute ((lst[i+1][1+1]) : l2)) ; if (l1)->includes(n->first()) or (l2)->includes(n[1+1]) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=input().split() n=len(b) res='NO' for i in range(n): if a[0]==b[i][0]or a[1]==b[i][1]: res='YES' print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : OclAny := input().split() ; var n : int := (b)->size() ; var res : String := 'NO' ; for i : Integer.subrange(0, n-1) do ( if a->first() = b[i+1]->first() or a[1+1] = b[i+1][1+1] then ( res := 'YES' ) else skip) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=[],[] for _ in range(int(input())): l=list(map(int,input().split())) a.append(l[0]) b.append(l[1]) print(max(max(a)-min(a),max(b)-min(b))**2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{Sequence{},Sequence{}} ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((l->first()) : a) ; execute ((l[1+1]) : b)) ; execute ((Set{(a)->max() - (a)->min(), (b)->max() - (b)->min()}->max())->pow(2))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- z='NO' a=input() x=list(input().split()) for i in range(len(x)): if(x[i][0]in a)or(x[i][1]in a): z='YES' break print(z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var z : String := 'NO' ; var a : String := (OclFile["System.in"]).readLine() ; var x : Sequence := (input().split()) ; for i : Integer.subrange(0, (x)->size()-1) do ( if ((a)->characters()->includes(x[i+1]->first())) or ((a)->characters()->includes(x[i+1][1+1])) then ( z := 'YES' ; break ) else skip) ; execute (z)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() ss=list(map(str,input().split())) s1=s[0] s2=s[1] for x in ss : ss_x=list(x) if(s1 in ss_x)or(s2 in ss_x): print('YES') break else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var ss : Sequence := ((input().split())->collect( _x | (OclType["String"])->apply(_x) )) ; var s1 : OclAny := s->first() ; var s2 : OclAny := s[1+1] ; (compound_stmt for (exprlist (expr (atom (name x)))) in (testlist (test (logical_test (comparison (expr (atom (name ss))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ss_x)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name s1)))) in (comparison (expr (atom (name ss_x)))))))) ))))) or (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name s2)))) in (comparison (expr (atom (name ss_x)))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) INF=10**9 N=10**4+10 dp=[[-INF]*N for i in range(n+1)] dp[0][0]=0 w=0 for _ in range(n): a,b=map(int,input().split()) w+=b for k in range(n)[: :-1]: for i in range(N-a): dp[k+1][i+a]=max(dp[k][i]+b,dp[k+1][i+a]) out=[] for line in dp[1 :]: pos=[] for i in range(N): cap=i con=line[i] pos.append(min(cap,(con+w)/2)) out.append(max(pos)) print(*out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var INF : double := (10)->pow(9) ; var N : double := (10)->pow(4) + 10 ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ -INF }, N))) ; dp->first()->first() := 0 ; var w : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; w := w + b ; for k : range(n)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( for i : Integer.subrange(0, N - a-1) do ( dp[k + 1+1][i + a+1] := Set{dp[k+1][i+1] + b, dp[k + 1+1][i + a+1]}->max()))) ; var out : Sequence := Sequence{} ; for line : dp->tail() do ( var pos : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var cap : OclAny := i ; var con : OclAny := line[i+1] ; execute ((Set{cap, (con + w) / 2}->min()) : pos)) ; execute (((pos)->max()) : out)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name out))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() card=input().split() count=0 for i in card : if(i[0]==s[0]or i[1]==s[1]): count=1 if count : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var card : OclAny := input().split() ; var count : int := 0 ; for i : card do ( if (i->first() = s->first() or i[1+1] = s[1+1]) then ( count := 1 ) else skip) ; if count then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() k=len(n) i=0 while True : if i<=(k-3)and n[i]=="1" and n[i+1]=="4" and n[i+2]=="4" : i+=3 elif i<=(k-2)and n[i]=="1" and n[i+1]=="4" : i+=2 elif i<=(k-1)and n[i]=="1" : i+=1 elif i>(k-1): break else : i=2*k break if i==2*k : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var k : int := (n)->size() ; var i : int := 0 ; while true do ( if (i->compareTo((k - 3))) <= 0 & n[i+1] = "1" & n[i + 1+1] = "4" & n[i + 2+1] = "4" then ( i := i + 3 ) else (if (i->compareTo((k - 2))) <= 0 & n[i+1] = "1" & n[i + 1+1] = "4" then ( i := i + 2 ) else (if (i->compareTo((k - 1))) <= 0 & n[i+1] = "1" then ( i := i + 1 ) else (if (i->compareTo((k - 1))) > 0 then ( break ) else ( i := 2 * k ; break ) ) ) ) ) ; if i = 2 * k then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() val=0 for i in range(len(n)): if n[i]!="1" and n[i]!="4" : val=1 break elif n[0]=="4" : val=1 break elif "444" in n : val=1 break if val==1 : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var val : int := 0 ; for i : Integer.subrange(0, (n)->size()-1) do ( if n[i+1] /= "1" & n[i+1] /= "4" then ( val := 1 ; break ) else (if n->first() = "4" then ( val := 1 ; break ) else (if (n)->characters()->includes("444") then ( val := 1 ; break ) else skip ) ) ) ; if val = 1 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() check=True for i in range(len(n)): if n[i]!="1" and n[i]!="4" : check=False if n[0]=="4" : check=False if "444" in n : check=False if check : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var check : boolean := true ; for i : Integer.subrange(0, (n)->size()-1) do ( if n[i+1] /= "1" & n[i+1] /= "4" then ( check := false ) else skip ; if n->first() = "4" then ( check := false ) else skip ; if (n)->characters()->includes("444") then ( check := false ) else skip) ; if check then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() while n : if n[: 3]=="144" : n=n[3 :] elif n[: 2]=="14" : n=n[2 :] elif n[: 1]=="1" : n=n[1 :] else : break if n : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; while n do ( if n.subrange(1,3) = "144" then ( n := n.subrange(3+1) ) else (if n.subrange(1,2) = "14" then ( n := n.subrange(2+1) ) else (if n.subrange(1,1) = "1" then ( n := n->tail() ) else ( break ) ) ) ) ; if n then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() if "444" in n : print("NO") else : n=n.replace("144","") n=n.replace("14","") n=n.replace("1","") if len(n)==0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; if (n)->characters()->includes("444") then ( execute ("NO")->display() ) else ( n := n.replace("144", "") ; n := n.replace("14", "") ; n := n.replace("1", "") ; if (n)->size() = 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minCost(arr,n): cost=999999 ; XOR=0 ; for i in range(0,n): XOR ^=arr[i]; for i in range(0,n): if(cost>abs((XOR ^ arr[i])-arr[i])): cost=abs((XOR ^ arr[i])-arr[i]) element=arr[i] print("Element=",element) print("Operation required=",abs(cost)) arr=[2,8,4,16] n=len(arr) minCost(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{8}->union(Sequence{4}->union(Sequence{ 16 }))) ; n := (arr)->size() ; minCost(arr, n); operation minCost(arr : OclAny, n : OclAny) pre: true post: true activity: var cost : int := 999999; ; var XOR : int := 0; ; for i : Integer.subrange(0, n-1) do ( XOR := XOR xor arr[i+1];) ; for i : Integer.subrange(0, n-1) do ( if ((cost->compareTo(((MathLib.bitwiseXor(XOR, arr[i+1])) - arr[i+1])->abs())) > 0) then ( cost := ((MathLib.bitwiseXor(XOR, arr[i+1])) - arr[i+1])->abs() ; var element : OclAny := arr[i+1] ) else skip) ; execute ("Element=")->display() ; execute ("Operation required=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def XorAscii(str1,len1): ans=ord(str1[0]) for i in range(1,len1): ans=(ans ^(ord(str1[i]))) return ans str1="geeksforgeeks" len1=len(str1) print(XorAscii(str1,len1)) str1="GfG" len1=len(str1) print(XorAscii(str1,len1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; str1 := "geeksforgeeks" ; len1 := (str1)->size() ; execute (XorAscii(str1, len1))->display() ; str1 := "GfG" ; len1 := (str1)->size() ; execute (XorAscii(str1, len1))->display(); operation XorAscii(str1 : OclAny, len1 : OclAny) : OclAny pre: true post: true activity: var ans : int := (str1->first())->char2byte() ; for i : Integer.subrange(1, len1-1) do ( ans := (MathLib.bitwiseXor(ans, ((str1[i+1])->char2byte())))) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(lst): mnx=10**18 mxx=-(10**18) mny=10**18 mxy=-(10**18) for i in lst : mnx=min(mnx,i[0]) mxx=max(mxx,i[0]) mny=min(mny,i[1]) mxy=max(mxy,i[1]) ln1=mxx-mnx ln2=mxy-mny ans=max(ln1,ln2) return ans*ans n=int(input()) lst=[] for i in range(n): x,y=map(int,input().split()) lst.append([x,y]) print(solve(lst)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; lst := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{x}->union(Sequence{ y })) : lst)) ; execute (solve(lst))->display(); operation solve(lst : OclAny) : OclAny pre: true post: true activity: var mnx : double := (10)->pow(18) ; var mxx : double := -((10)->pow(18)) ; var mny : double := (10)->pow(18) ; var mxy : double := -((10)->pow(18)) ; for i : lst do ( mnx := Set{mnx, i->first()}->min() ; mxx := Set{mxx, i->first()}->max() ; mny := Set{mny, i[1+1]}->min() ; mxy := Set{mxy, i[1+1]}->max()) ; var ln1 : double := mxx - mnx ; var ln2 : double := mxy - mny ; var ans : OclAny := Set{ln1, ln2}->max() ; return ans * ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def init(degree,edges,n): for i in range(n): degree[i]=0 ; for i in range(len(edges)): degree[edges[i][0]]+=1 ; degree[edges[i][1]]+=1 ; def performQueries(edges,q,n): degree=[0]*n ; init(degree,edges,n); for i in range(len(q)): node=q[i]; if(node==0): print("No"); continue ; if(degree[node]==1): print("Yes"); else : print("No"); if __name__=="__main__" : n=6 ; edges=[[0,1],[0,2],[1,3],[1,4],[4,5]]; q=[0,3,4,5]; performQueries(edges,q,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 6; ; edges := Sequence{Sequence{0}->union(Sequence{ 1 })}->union(Sequence{Sequence{0}->union(Sequence{ 2 })}->union(Sequence{Sequence{1}->union(Sequence{ 3 })}->union(Sequence{Sequence{1}->union(Sequence{ 4 })}->union(Sequence{ Sequence{4}->union(Sequence{ 5 }) })))); ; q := Sequence{0}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 }))); ; performQueries(edges, q, n); ) else skip; operation init(degree : OclAny, edges : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( degree[i+1] := 0;) ; for i : Integer.subrange(0, (edges)->size()-1) do ( degree[edges[i+1]->first()+1] := degree[edges[i+1]->first()+1] + 1; ; degree[edges[i+1][1+1]+1] := degree[edges[i+1][1+1]+1] + 1;); operation performQueries(edges : OclAny, q : OclAny, n : OclAny) pre: true post: true activity: degree := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; init(degree, edges, n); ; for i : Integer.subrange(0, (q)->size()-1) do ( var node : OclAny := q[i+1]; ; if (node = 0) then ( execute ("No")->display(); ; continue; ) else skip ; if (degree[node+1] = 1) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if(n<10): print(n) else : l=len(str(n))-1 p=int('9'*l) t=n-p s=0 while(t>0): s+=t % 10 t//=10 print(s+9*l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n < 10) then ( execute (n)->display() ) else ( var l : double := (("" + ((n))))->size() - 1 ; var p : int := ("" + ((StringLib.nCopies('9', l))))->toInteger() ; var t : double := n - p ; var s : int := 0 ; while (t > 0) do ( s := s + t mod 10 ; t := t div 10) ; execute (s + 9 * l)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printArray(arr,n): arr.sort() l=0 r=n-1 flag=0 k=2 while(l<=r): if(flag==0): i=l while ir-k and i>=l : print(arr[i],end=" ") i-=1 flag=0 r=i k+=1 if __name__=="__main__" : n=6 arr=[1,2,3,4,5,6] printArray(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 6 ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))))) ; printArray(arr, n) ) else skip; operation printArray(arr : OclAny, n : OclAny) pre: true post: true activity: arr := arr->sort() ; var l : int := 0 ; var r : double := n - 1 ; var flag : int := 0 ; var k : int := 2 ; while ((l->compareTo(r)) <= 0) do ( if (flag = 0) then ( var i : int := l ; while (i->compareTo(l + k)) < 0 & (i->compareTo(r)) <= 0 do ( execute (arr[i+1])->display() ; i := i + 1) ; flag := 1 ; l := i ) else ( i := r ; while (i->compareTo(r - k)) > 0 & (i->compareTo(l)) >= 0 do ( execute (arr[i+1])->display() ; i := i - 1) ; flag := 0 ; r := i ) ; k := k + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000 f=[0]*MAX def fib(n): n=int(n) if(n==0): return 0 if(n==1 or n==2): return(1) if(f[n]==True): return f[n] k=(n+1)/2 if(n & 1)else n/2 f[n]=(fib(k)*fib(k)+fib(k-1)*fib(k-1))if(n & 1)else(2*fib(k-1)+fib(k))*fib(k) return f[n] def calculateSum(n): return fib(n+2)-1 n=4 print("Sum of Fibonacci numbers is :",calculateSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1000 ; var f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX) ; skip ; skip ; n := 4 ; execute ("Sum of Fibonacci numbers is :")->display(); operation fib(n : OclAny) : OclAny pre: true post: true activity: n := ("" + ((n)))->toInteger() ; if (n = 0) then ( return 0 ) else skip ; if (n = 1 or n = 2) then ( return (1) ) else skip ; if (f[n+1] = true) then ( return f[n+1] ) else skip ; var k : double := if (MathLib.bitwiseAnd(n, 1)) then (n + 1) / 2 else n / 2 endif ; f[n+1] := if (MathLib.bitwiseAnd(n, 1)) then (fib(k) * fib(k) + fib(k - 1) * fib(k - 1)) else (2 * fib(k - 1) + fib(k)) * fib(k) endif ; return f[n+1]; operation calculateSum(n : OclAny) : OclAny pre: true post: true activity: return fib(n + 2) - 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() i=s.index("i") s,t="."+s[: i][: :-1],"."+s[i+3 :] s=s.translate(str.maketrans("(){}[]",")(}{][")) l=[[0 for _ in range(len(s))]for _ in range(len(t))] for i in range(1,len(t)): for j in range(1,len(s)): if t[i]==s[j]: l[i][j]=l[i-1][j-1]+1 else : l[i][j]=max(l[i-1][j],l[i][j-1]) print(3+2*l[-1][-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var i : int := s->indexOf("i") - 1 ; var t : OclAny := null; Sequence{s,t} := Sequence{"." + s.subrange(1,i)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))),"." + s.subrange(i + 3+1)} ; s := s.translate(("" + (.maketrans("(){}[]", ")(}{][")))) ; var l : Sequence := Integer.subrange(0, (t)->size()-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, (s)->size()-1)->select(_anon | true)->collect(_anon | (0)))) ; for i : Integer.subrange(1, (t)->size()-1) do ( for j : Integer.subrange(1, (s)->size()-1) do ( if t[i+1] = s[j+1] then ( l[i+1][j+1] := l[i - 1+1][j - 1+1] + 1 ) else ( l[i+1][j+1] := Set{l[i - 1+1][j+1], l[i+1][j - 1+1]}->max() ))) ; execute (3 + 2 * l->last()->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isDivisibleby17(n): if(n==0 or n==17): return True if(n<17): return False return isDivisibleby17((int)(n>>4)-(int)(n & 15)) n=35 if(isDivisibleby17(n)): print(n,"is divisible by 17") else : print(n,"is not divisible by 17") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 35 ; if (isDivisibleby17(n)) then ( execute (n)->display() ) else ( execute (n)->display() ); operation isDivisibleby17(n : OclAny) : OclAny pre: true post: true activity: if (n = 0 or n = 17) then ( return true ) else skip ; if (n < 17) then ( return false ) else skip ; return isDivisibleby17((OclType["int"])(n /(2->pow(4))) - (OclType["int"])(MathLib.bitwiseAnd(n, 15))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def squareSum(N): Sum=(N*(N+1)*(2*N+1))//6 return Sum def findMaxN(X): low,high,N=1,100000,0 while low<=high : mid=(high+low)//2 if squareSum(mid)<=X : N=mid low=mid+1 else : high=mid-1 return N if __name__=="__main__" : X=25 print(findMaxN(X)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( X := 25 ; execute (findMaxN(X))->display() ) else skip; operation squareSum(N : OclAny) : OclAny pre: true post: true activity: var Sum : int := (N * (N + 1) * (2 * N + 1)) div 6 ; return Sum; operation findMaxN(X : OclAny) : OclAny pre: true post: true activity: var low : OclAny := null; var high : OclAny := null; Sequence{low,high,N} := Sequence{1,100000,0} ; while (low->compareTo(high)) <= 0 do ( var mid : int := (high + low) div 2 ; if (squareSum(mid)->compareTo(X)) <= 0 then ( N := mid ; var low : int := mid + 1 ) else ( var high : double := mid - 1 )) ; return N; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- days=["thu","fri","sat","sun","mon","tue","wed"] a=int(input()) print(days[a % 7]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var days : Sequence := Sequence{"thu"}->union(Sequence{"fri"}->union(Sequence{"sat"}->union(Sequence{"sun"}->union(Sequence{"mon"}->union(Sequence{"tue"}->union(Sequence{ "wed" })))))) ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (days[a mod 7+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- X=int(input()) s=[0,1,2,3] if(X==9-7-1): print('fri') elif(X==9-7): print('sat') elif(X==9-7+1): print('sun') elif(X==9-7+2): print('mon') elif(X==9-7+3): print('tue') elif(X==9-7+4): print('wed') elif(X==9-7+5): print('thu') elif(X==9-7+6): print('fri') for i in s : if(X==9+7*i): print('sat') elif(X==(9+7*i)+1): print('sun') elif(X==(9+7*i)+2): print('mon') elif(X==(9+7*i)+3): print('tue') elif(X==(9+7*i)+4): print('wed') elif(X==(9+7*i)+5): print('thu') elif(X==(9+7*i)+6): print('fri') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var X : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := Sequence{0}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))) ; if (X = 9 - 7 - 1) then ( execute ('fri')->display() ) else (if (X = 9 - 7) then ( execute ('sat')->display() ) else (if (X = 9 - 7 + 1) then ( execute ('sun')->display() ) else (if (X = 9 - 7 + 2) then ( execute ('mon')->display() ) else (if (X = 9 - 7 + 3) then ( execute ('tue')->display() ) else (if (X = 9 - 7 + 4) then ( execute ('wed')->display() ) else (if (X = 9 - 7 + 5) then ( execute ('thu')->display() ) else (if (X = 9 - 7 + 6) then ( execute ('fri')->display() ) else skip ) ) ) ) ) ) ) ; for i : s do ( if (X = 9 + 7 * i) then ( execute ('sat')->display() ) else (if (X = (9 + 7 * i) + 1) then ( execute ('sun')->display() ) else (if (X = (9 + 7 * i) + 2) then ( execute ('mon')->display() ) else (if (X = (9 + 7 * i) + 3) then ( execute ('tue')->display() ) else (if (X = (9 + 7 * i) + 4) then ( execute ('wed')->display() ) else (if (X = (9 + 7 * i) + 5) then ( execute ('thu')->display() ) else (if (X = (9 + 7 * i) + 6) then ( execute ('fri')->display() ) else skip ) ) ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- X=int(input()) if X % 7==4 : print("mon") elif X % 7==5 : print("tue") elif X % 7==6 : print("wed") elif X % 7==0 : print("thu") elif X % 7==1 : print("fri") elif X % 7==2 : print("sat") elif X % 7==3 : print("sun") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var X : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if X mod 7 = 4 then ( execute ("mon")->display() ) else (if X mod 7 = 5 then ( execute ("tue")->display() ) else (if X mod 7 = 6 then ( execute ("wed")->display() ) else (if X mod 7 = 0 then ( execute ("thu")->display() ) else (if X mod 7 = 1 then ( execute ("fri")->display() ) else (if X mod 7 = 2 then ( execute ("sat")->display() ) else (if X mod 7 = 3 then ( execute ("sun")->display() ) else skip ) ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import datetime import locale d=int(input()) dt=datetime.datetime(2017,9,d) print(dt.strftime("%a").lower()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var dt : OclAny := ; execute (dt.strftime("%a")->toLowerCase())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x,y=list(map(int,input().split())) max_x=x min_x=x max_y=y min_y=y for i in range(n-1): x,y=list(map(int,input().split())) max_x=max(x,max_x) min_x=min(x,min_x) max_y=max(y,max_y) min_y=min(y,min_y) res1=(max_x-min_x)**2 res2=(max_y-min_y)**2 print(res1 if res1>res2 else res2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var max_x : OclAny := x ; var min_x : OclAny := x ; var max_y : OclAny := y ; var min_y : OclAny := y ; for i : Integer.subrange(0, n - 1-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; max_x := Set{x, max_x}->max() ; min_x := Set{x, min_x}->min() ; max_y := Set{y, max_y}->max() ; min_y := Set{y, min_y}->min()) ; var res1 : double := ((max_x - min_x))->pow(2) ; var res2 : double := ((max_y - min_y))->pow(2) ; execute (if (res1->compareTo(res2)) > 0 then res1 else res2 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import os import random import re import sys from math import gcd from math import sqrt n=int(input()) def sm(x): x=str(x) s=0 for i in x : s+=int(i) return s count=0 ans=0 while ans<=n : count=ans ans=ans*10+9 ans=count print(sm(n-ans)+sm(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; var count : int := 0 ; var ans : int := 0 ; while (ans->compareTo(n)) <= 0 do ( count := ans ; ans := ans * 10 + 9) ; ans := count ; execute (sm(n - ans) + sm(ans))->display(); operation sm(x : OclAny) : OclAny pre: true post: true activity: x := ("" + ((x))) ; var s : int := 0 ; for i : x do ( s := s + ("" + ((i)))->toInteger()) ; return s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- X=int(input()) X=(X-9)% 7 if X<0 : X=X+7 y='' if X==0 : y='sat' elif X==1 : y='sun' elif X==2 : y='mon' elif X==3 : y='tue' elif X==4 : y='wed' elif X==5 : y='thu' elif X==6 : y='fri' print(y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var X : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; X := (X - 9) mod 7 ; if X < 0 then ( X := X + 7 ) else skip ; var y : String := '' ; if X = 0 then ( y := 'sat' ) else (if X = 1 then ( y := 'sun' ) else (if X = 2 then ( y := 'mon' ) else (if X = 3 then ( y := 'tue' ) else (if X = 4 then ( y := 'wed' ) else (if X = 5 then ( y := 'thu' ) else (if X = 6 then ( y := 'fri' ) else skip ) ) ) ) ) ) ; execute (y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- fib=[0]*43 def fibonacci(): fib[0]=1 fib[1]=2 for i in range(2,43): fib[i]=fib[i-1]+fib[i-2] def rec(x,y,last): if y==0 : if x==0 : return 1 return 0 Sum,i=0,last while i>=0 and fib[i]*y>=x : if fib[i]>x : i-=1 continue Sum+=rec(x-fib[i],y-1,i) i-=1 return Sum if __name__=="__main__" : fibonacci() n,k=13,3 print("Possible ways are:",rec(n,k,42)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var fib : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 43) ; skip ; skip ; if __name__ = "__main__" then ( fibonacci() ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := Sequence{13,3} ; execute ("Possible ways are:")->display() ) else skip; operation fibonacci() pre: true post: true activity: fib->first() := 1 ; fib[1+1] := 2 ; for i : Integer.subrange(2, 43-1) do ( fib[i+1] := fib[i - 1+1] + fib[i - 2+1]); operation rec(x : OclAny, y : OclAny, last : OclAny) : OclAny pre: true post: true activity: if y = 0 then ( if x = 0 then ( return 1 ) else skip ; return 0 ) else skip ; var Sum : OclAny := null; var i : OclAny := null; Sequence{Sum,i} := Sequence{0,last} ; while i >= 0 & (fib[i+1] * y->compareTo(x)) >= 0 do ( if (fib[i+1]->compareTo(x)) > 0 then ( i := i - 1 ; continue ) else skip ; Sum := Sum + rec(x - fib[i+1], y - 1, i) ; i := i - 1) ; return Sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,f=map(int,input().split()) pros=0 ; lst=[] for i in range(n): k,l=map(int,input().split()) lst.append(min(2*k,l)-min(k,l)) pros+=min(k,l) lst=sorted(lst,reverse=True) pros+=sum(lst[: f]) print(pros) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var f : OclAny := null; Sequence{n,f} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var pros : int := 0; var lst : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var k : OclAny := null; var l : OclAny := null; Sequence{k,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Set{2 * k, l}->min() - Set{k, l}->min()) : lst) ; pros := pros + Set{k, l}->min()) ; lst := lst->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; pros := pros + (lst.subrange(1,f))->sum() ; execute (pros)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,sellout_count=map(int,input().split()) days=[list(map(int,input().split()))for _ in range(n)] sold_items=0 increasing_chart=[] for items,customers in days : increasing_chart.append(min(items*2,customers)-min(items,customers)) sold_items+=min(items,customers) sold_items+=sum(sorted(increasing_chart)[:-sellout_count-1 :-1]) print(sold_items) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var sellout_count : OclAny := null; Sequence{n,sellout_count} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var days : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var sold_items : int := 0 ; var increasing_chart : Sequence := Sequence{} ; for _tuple : days do (var _indx : int := 1; var items : OclAny := _tuple->at(_indx); _indx := _indx + 1; var customers : OclAny := _tuple->at(_indx); execute ((Set{items * 2, customers}->min() - Set{items, customers}->min()) : increasing_chart) ; sold_items := sold_items + Set{items, customers}->min()) ; sold_items := sold_items + (sorted(increasing_chart)(subscript : (test (logical_test (comparison (expr (expr - (expr (atom (name sellout_count)))) - (expr (atom (number (integer 1)))))))) (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->sum() ; execute (sold_items)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numbers=list(map(int,input().split())) arr=[] counter=0 def sum(num1,num2): if num1>num2 : return num2 else : return num1 for i in range(0,numbers[0]): x=list(map(int,input().split())) res=0 y=sum(x[1],x[0]) if x[0]*2>=x[1]: res=x[1]-y else : res=x[0]*2-y arr.append(res) counter+=y arr.sort(reverse=True) for i in range(0,numbers[1]): counter+=arr[i] print(counter) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var numbers : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var arr : Sequence := Sequence{} ; var counter : int := 0 ; skip ; for i : Integer.subrange(0, numbers->first()-1) do ( var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : int := 0 ; var y : OclAny := (x[1+1], x->first())->sum() ; if (x->first() * 2->compareTo(x[1+1])) >= 0 then ( res := x[1+1] - y ) else ( res := x->first() * 2 - y ) ; execute ((res) : arr) ; counter := counter + y) ; arr := arr->sort() ; for i : Integer.subrange(0, numbers[1+1]-1) do ( counter := counter + arr[i+1]) ; execute (counter)->display(); operation sum(num1 : OclAny, num2 : OclAny) : OclAny pre: true post: true activity: if (num1->compareTo(num2)) > 0 then ( return num2 ) else ( return num1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,k=map(int,input().split()) sum=0 l=[] for i in range(n): a,b=map(int,input().split()) l.append(min(2*a,b)-min(a,b)) sum+=min(a,b) l.sort() for i in l[n-k : n]: sum+=i print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sum : int := 0 ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Set{2 * a, b}->min() - Set{a, b}->min()) : l) ; sum := sum + Set{a, b}->min()) ; l := l->sort() ; for i : l.subrange(n - k+1, n) do ( sum := sum + i) ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,f=map(int,input().split()) x=[] d=[] z=[] c=x.copy() s=0 for i in range(n): line=list(map(int,input().split())) if line[0]==0 or line[0]>=line[1]: s+=min(line) else : x.append([line[0],line[1]]) x.sort(key=lambda x : min(x[0]*2,x[1])-min(x[0],x[1]),reverse=True) for i in range(len(x)): if icollect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := Sequence{} ; var d : Sequence := Sequence{} ; var z : Sequence := Sequence{} ; var c : OclAny := x->copy() ; var s : int := 0 ; for i : Integer.subrange(0, n-1) do ( var line : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if line->first() = 0 or (line->first()->compareTo(line[1+1])) >= 0 then ( s := s + (line)->min() ) else ( execute ((Sequence{line->first()}->union(Sequence{ line[1+1] })) : x) )) ; x := x->sort() ; for i : Integer.subrange(0, (x)->size()-1) do ( if (i->compareTo(f)) < 0 then ( s := s + Set{x[i+1]->first() * 2, x[i+1][1+1]}->min() ) else ( s := s + x[i+1]->first() )) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sameLength(A,B): while(A>0 and B>0): A=A/10 ; B=B/10 ; if(A==0 and B==0): return True ; return False ; A=21 ; B=1 ; if(sameLength(A,B)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; A := 21; B := 1; ; if (sameLength(A, B)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ); operation sameLength(A : OclAny, B : OclAny) pre: true post: true activity: while (A > 0 & B > 0) do ( A := A / 10; ; B := B / 10;) ; if (A = 0 & B = 0) then ( return true; ) else skip ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys INT_MAX=sys.maxsize ; INT_MIN=-(sys.maxsize-1); def minimumAdjacentDifference(a,n,k): minDiff=INT_MAX ; for i in range(k+1): maxDiff=INT_MIN ; for j in range(n-k-1): for p in range(i,i+j+1): maxDiff=max(maxDiff,a[p+1]-a[p]); minDiff=min(minDiff,maxDiff); return minDiff ; if __name__=="__main__" : n=5 ; k=2 ; a=[3,7,8,10,14]; print(minimumAdjacentDifference(a,n,k)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var INT_MAX : (trailer . (name maxsize)) := (trailer . (name maxsize)); ; var INT_MIN : double := -((trailer . (name maxsize)) - 1); ; skip ; if __name__ = "__main__" then ( n := 5; ; k := 2; ; a := Sequence{3}->union(Sequence{7}->union(Sequence{8}->union(Sequence{10}->union(Sequence{ 14 })))); ; execute (minimumAdjacentDifference(a, n, k))->display(); ) else skip; operation minimumAdjacentDifference(a : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var minDiff : OclAny := INT_MAX; ; for i : Integer.subrange(0, k + 1-1) do ( var maxDiff : OclAny := INT_MIN; ; for j : Integer.subrange(0, n - k - 1-1) do ( for p : Integer.subrange(i, i + j + 1-1) do ( maxDiff := Set{maxDiff, a[p + 1+1] - a[p+1]}->max();)) ; minDiff := Set{minDiff, maxDiff}->min();) ; return minDiff;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isSubSequence(str1,str2): m=len(str1); n=len(str2); j=0 ; i=0 ; while(iunion(Sequence{"apple"}->union(Sequence{"monkey"}->union(Sequence{ "plea" }))); ; str1 := "abpcplea"; ; execute (findLongestString(dict1, str1))->display();; operation isSubSequence(str1 : OclAny, str2 : OclAny) pre: true post: true activity: var m : int := (str1)->size(); ; var n : int := (str2)->size(); ; var j : int := 0; ; var i : int := 0; ; while ((i->compareTo(n)) < 0 & (j->compareTo(m)) < 0) do ( if (str1[j+1] = str2[i+1]) then ( j := j + 1; ) else skip ; i := i + 1;) ; return (j = m);; operation findLongestString(dict1 : OclAny, str1 : OclAny) pre: true post: true activity: var result : String := ""; ; var length : int := 0; ; for word : dict1 do ( if ((length->compareTo((word)->size())) < 0 & isSubSequence(word, str1)) then ( result := word; ; length := (word)->size(); ) else skip) ; return result;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def mk(d,num,t): return d*10**t+num def _sum(a): digits=[int(i)for i in str(a)] return sum(digits) def solve(): n=int(input()) t=0 num=0 while True : if mk(9,num,t)<=n : num=mk(9,num,t) elif mk(8,num,t)<=n : num=mk(8,num,t) elif mk(7,num,t)<=n : num=mk(7,num,t) elif mk(6,num,t)<=n : num=mk(6,num,t) elif mk(5,num,t)<=n : num=mk(5,num,t) elif mk(4,num,t)<=n : num=mk(4,num,t) elif mk(3,num,t)<=n : num=mk(3,num,t) elif mk(2,num,t)<=n : num=mk(2,num,t) elif mk(1,num,t)<=n : num=mk(1,num,t) elif mk(0,num,t)<=n : break t+=1 s=_sum(num)+_sum(n-num) print(s) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; solve(); operation mk(d : OclAny, num : OclAny, t : OclAny) : OclAny pre: true post: true activity: return d * (10)->pow(t) + num; operation _sum(a : OclAny) : OclAny pre: true post: true activity: var digits : Sequence := ("" + ((a)))->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; return (digits)->sum(); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; t := 0 ; num := 0 ; while true do ( if (mk(9, num, t)->compareTo(n)) <= 0 then ( num := mk(9, num, t) ) else (if (mk(8, num, t)->compareTo(n)) <= 0 then ( num := mk(8, num, t) ) else (if (mk(7, num, t)->compareTo(n)) <= 0 then ( num := mk(7, num, t) ) else (if (mk(6, num, t)->compareTo(n)) <= 0 then ( num := mk(6, num, t) ) else (if (mk(5, num, t)->compareTo(n)) <= 0 then ( num := mk(5, num, t) ) else (if (mk(4, num, t)->compareTo(n)) <= 0 then ( num := mk(4, num, t) ) else (if (mk(3, num, t)->compareTo(n)) <= 0 then ( num := mk(3, num, t) ) else (if (mk(2, num, t)->compareTo(n)) <= 0 then ( num := mk(2, num, t) ) else (if (mk(1, num, t)->compareTo(n)) <= 0 then ( num := mk(1, num, t) ) else (if (mk(0, num, t)->compareTo(n)) <= 0 then ( break ) else skip ) ) ) ) ) ) ) ) ) ; t := t + 1) ; var s : OclAny := _sum(num) + _sum(n - num) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def allBitsSetInTheGivenRange(n,l,r): num=(((1<display() ) else ( execute ("No")->display() ); operation allBitsSetInTheGivenRange(n : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var num : int := (MathLib.bitwiseXor(((1 * (2->pow(r))) - 1), ((1 * (2->pow((l - 1)))) - 1))) ; var new_num : int := MathLib.bitwiseAnd(n, num) ; if (new_num = 0) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def solveProportion(a,b1,b2,c): A=a*b2 B=b1*b2 C=b1*c gcd1=math.gcd(math.gcd(A,B),C) print(str(A//gcd1)+":"+str(B//gcd1)+":"+str(C//gcd1)) if __name__=="__main__" : a=3 b1=4 b2=8 c=9 solveProportion(a,b1,b2,c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( a := 3 ; b1 := 4 ; b2 := 8 ; c := 9 ; solveProportion(a, b1, b2, c) ) else skip; operation solveProportion(a : OclAny, b1 : OclAny, b2 : OclAny, c : OclAny) pre: true post: true activity: var A : double := a * b2 ; var B : double := b1 * b2 ; var C : double := b1 * c ; var gcd1 : long := ((A)->gcd(B))->gcd(C) ; execute (("" + ((A div gcd1))) + ":" + ("" + ((B div gcd1))) + ":" + ("" + ((C div gcd1))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): def bfs(k): start,goal=file_input.readline().split() if start==goal : return 0 start=map(int,start) goal=map(int,goal) diff=[(g-s)% 10 for g,s in zip(goal,start)] q=[diff] checked={tuple(diff): True} ans=0 while q : ans+=1 t_q=[] for d in q : for i,r in enumerate(d): if r!=0 : break for j in range(i,k): d[j]-=r d[j]%=10 key=tuple(d) if key in checked : continue if sum(d)==0 : return ans checked[key]=True t_q.append(d[:]) q=t_q from sys import stdin file_input=stdin while True : k=int(file_input.readline()) if k==0 : break print(bfs(k)) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: skip ; skip ; var file_input : OclAny := stdin ; while true do ( k := ("" + ((file_input.readLine())))->toInteger() ; if k = 0 then ( break ) else skip ; execute (bfs(k))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=lambda :[*map(int,input().split())] n,a=i() x,y=0,0 for c in i(): x=x*a+c m,b=i() for c in i(): y=y*b+c print('<=>'[(x>=y)+(x>y)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := i->apply() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{0,0} ; for c : i->apply() do ( var x : double := x * a + c) ; var m : OclAny := null; var b : OclAny := null; Sequence{m,b} := i->apply() ; for c : i->apply() do ( var y : double := y * b + c) ; execute ('<=>'->select(((x->compareTo(y)) >= 0) + ((x->compareTo(y)) > 0)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- nx,x=list(map(int,input().split())) xvals=list(map(int,input().split())) ny,y=list(map(int,input().split())) yvals=list(map(int,input().split())) num1=0 for i in range(nx): num1+=xvals[i]*pow(x,nx-i-1) num2=0 for i in range(ny): num2+=yvals[i]*pow(y,ny-i-1) if num1>num2 : print(">") elif num1apply(_x) )) ; var xvals : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ny : OclAny := null; var y : OclAny := null; Sequence{ny,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var yvals : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var num1 : int := 0 ; for i : Integer.subrange(0, nx-1) do ( num1 := num1 + xvals[i+1] * (x)->pow(nx - i - 1)) ; var num2 : int := 0 ; for i : Integer.subrange(0, ny-1) do ( num2 := num2 + yvals[i+1] * (y)->pow(ny - i - 1)) ; if (num1->compareTo(num2)) > 0 then ( execute (">")->display() ) else (if (num1->compareTo(num2)) < 0 then ( execute ("<")->display() ) else ( execute ("=")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- nx,bx=map(int,input().split(' ')[: 2]) xs=list(map(int,input().split(' ')[: nx])) ny,by=map(int,input().split(' ')[: 2]) ys=list(map(int,input().split(' ')[: ny])) p=1 x=0 for d in reversed(xs): x+=d*p p*=bx p=1 y=0 for d in reversed(ys): y+=d*p p*=by if x==y : print('=') elif x') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var nx : OclAny := null; var bx : OclAny := null; Sequence{nx,bx} := (input().split(' ').subrange(1,2))->collect( _x | (OclType["int"])->apply(_x) ) ; var xs : Sequence := ((input().split(' ').subrange(1,nx))->collect( _x | (OclType["int"])->apply(_x) )) ; var ny : OclAny := null; var by : OclAny := null; Sequence{ny,by} := (input().split(' ').subrange(1,2))->collect( _x | (OclType["int"])->apply(_x) ) ; var ys : Sequence := ((input().split(' ').subrange(1,ny))->collect( _x | (OclType["int"])->apply(_x) )) ; var p : int := 1 ; var x : int := 0 ; for d : (xs)->reverse() do ( x := x + d * p ; p := p * bx) ; p := 1 ; var y : int := 0 ; for d : (ys)->reverse() do ( y := y + d * p ; p := p * by) ; if x = y then ( execute ('=')->display() ) else (if (x->compareTo(y)) < 0 then ( execute ('<')->display() ) else ( execute ('>')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from re import I line1=[int(i)for i in input().split(' ')] d=[int(i)for i in input().split(' ')] d.reverse() e=0 for i in range(len(d)): val=line1[1]**i e+=val*d[i] e1=0 line=[int(i)for i in input().split(' ')] d=[int(i)for i in input().split(' ')] d.reverse() for i in range(len(d)): val=line[1]**i e1+=val*d[i] if(e==e1): print('=') elif(e>e1): print('>') else : print('<') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var line1 : Sequence := input().split(' ')->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var d : Sequence := input().split(' ')->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; d := d->reverse() ; var e : int := 0 ; for i : Integer.subrange(0, (d)->size()-1) do ( var val : double := (line1[1+1])->pow(i) ; e := e + val * d[i+1]) ; var e1 : int := 0 ; var line : Sequence := input().split(' ')->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; d := input().split(' ')->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; d := d->reverse() ; for i : Integer.subrange(0, (d)->size()-1) do ( val := (line[1+1])->pow(i) ; e1 := e1 + val * d[i+1]) ; if (e = e1) then ( execute ('=')->display() ) else (if ((e->compareTo(e1)) > 0) then ( execute ('>')->display() ) else ( execute ('<')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,x=map(int,input().split()) w=list(map(int,input().split()))[: :-1] m,y=list(map(int,input().split())) s=list(map(int,input().split()))[: :-1] a=0 for i in range(n): a+=w[i]*x**i b=0 for i in range(m): b+=s[i]*y**i if a>b : print('>') elif a')->display() ) else (if (a->compareTo(b)) < 0 then ( execute ('<')->display() ) else ( execute ('=')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools MODULUS=10**6 def compute(): partitions=[1] for i in itertools.count(len(partitions)): item=0 for j in itertools.count(1): sign=-1 if j % 2==0 else+1 index=(j*j*3-j)//2 if index>i : break item+=partitions[i-index]*sign index+=j if index>i : break item+=partitions[i-index]*sign item %=MODULUS if item==0 : return str(i) partitions.append(item) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MODULUS : double := (10)->pow(6) ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var partitions : Sequence := Sequence{ 1 } ; for i : itertools->count((partitions)->size()) do ( var item : int := 0 ; for j : itertools->count(1) do ( var sign : int := if j mod 2 = 0 then -1 else 1 endif ; var index : int := (j * j * 3 - j) div 2 ; if (index->compareTo(i)) > 0 then ( break ) else skip ; item := item + partitions[i - index+1] * sign ; index := index + j ; if (index->compareTo(i)) > 0 then ( break ) else skip ; item := item + partitions[i - index+1] * sign ; item := item mod MODULUS) ; if item = 0 then ( return ("" + ((i))) ) else skip ; execute ((item) : partitions)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): ans=sum(eulerlib.list_primes(1999999)) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : OclAny := (eulerlib.list_primes(1999999))->sum() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import heapq import sys import math import itertools import bisect from io import BytesIO,IOBase import os def valid(i,j,n,m): if i=0 and j>=0 and jcompareTo(n)) < 0 & i >= 0 & j >= 0 & (j->compareTo(m)) < 0 then ( return true ) else skip ; return false; operation sumn(i : OclAny, n : OclAny) : OclAny pre: true post: true activity: return (n - i) * (i + n) / 2; operation sqfun(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: return (-b + (b * b - 4 * a * c)->sqrt()) / 2 * a; operation getprime(num : OclAny) : OclAny pre: true post: true activity: if ((argument (test (logical_test (comparison (comparison (expr (expr (atom (name num))) % (expr (atom (name i))))) != (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name math)) (trailer . (name sqrt) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) ))))))))) )))) + (expr (atom (number (integer 1)))))))))) )))))))))->forAll( _x | _x = true ) then ( return true ) else skip; operation value() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation values() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inlsts() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inps() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation instr() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation stlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (i)); operation solve() pre: true post: true activity: n := inp() ; var last : double := ("" + ((OclType["String"](n)->first())))->toInteger() - 1 ; for i : Integer.subrange(0, (("" + ((n))))->size() - 1-1) do ( last := last * 10 + 9) ; var tot : OclAny := (("" + ((last)))->select(i | true)->collect(i | (("" + ((i)))->toInteger())))->sum() ; for i : ("" + ((n - last))) do ( tot := tot + ("" + ((i)))->toInteger()) ; execute (tot)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def generate(st,s): if len(s)==0 : return if s not in st : st.add(s) for i in range(len(s)): t=list(s).copy() t.remove(s[i]) t=''.join(t) generate(st,t) return if __name__=="__main__" : s="xyz" st=set() generate(st,s) for i in st : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "xyz" ; st := Set{}->union(()) ; generate(st, s) ; for i : st do ( execute (i)->display()) ) else skip; operation generate(st : OclAny, s : OclAny) pre: true post: true activity: if (s)->size() = 0 then ( return ) else skip ; if (st)->excludes(s) then ( execute ((s) : st) ; for i : Integer.subrange(0, (s)->size()-1) do ( var t : OclAny := OclType["Sequence"](s)->copy() ; execute ((s[i+1]) /: t) ; t := StringLib.sumStringsWithSeparator((t), '') ; generate(st, t)) ) else skip ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) v=[i+1 for i in range(n)] if(k % 4==0): print("NO") else : print("YES") if(k % 4==1 or k % 4==3): for i in range(0,len(v),2): print(v[i],v[i+1]) else : for i in range(0,len(v),2): print(str(v[i+1])+" "+str(v[i])if not(int(i/2))% 2 else str(v[i])+" "+str(v[i+1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var v : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i + 1)) ; if (k mod 4 = 0) then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; if (k mod 4 = 1 or k mod 4 = 3) then ( for i : Integer.subrange(0, (v)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( execute (v[i+1])->display()) ) else ( for i : Integer.subrange(0, (v)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( execute (if not((("" + ((i / 2)))->toInteger()) mod 2) then ("" + ((v[i + 1+1]))) + " " + ("" + ((v[i+1]))) else ("" + ((v[i+1]))) + " " + ("" + ((v[i + 1+1]))) endif)->display()) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mat=[] k=0 for i in range(3): x=list(map(int,input().split())) k+=sum(x) mat.append(x) p=(k)//2 for i in range(3): mat[i][i]=p-sum(mat[i]) for i in mat : print(' '.join(map(str,i))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mat : Sequence := Sequence{} ; var k : int := 0 ; for i : Integer.subrange(0, 3-1) do ( var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; k := k + (x)->sum() ; execute ((x) : mat)) ; var p : int := (k) div 2 ; for i : Integer.subrange(0, 3-1) do ( mat[i+1][i+1] := p - (mat[i+1])->sum()) ; for i : mat do ( execute (StringLib.sumStringsWithSeparator(((i)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def divisible(num): n=len(num); sum=0 ; for i in range(n): sum+=int(num[i]); if(sum % 3==0): return 0 ; if(n==1): return-1 ; for i in range(n): if(sum % 3==int(num[i])% 3): return 1 ; if(n==2): return-1 ; return 2 ; if __name__=='__main__' : num="1234" ; print(divisible(num)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( num := "1234"; ; execute (divisible(num))->display(); ) else skip; operation divisible(num : OclAny) pre: true post: true activity: var n : int := (num)->size(); ; var sum : int := 0; ; for i : Integer.subrange(0, n-1) do ( sum := sum + ("" + ((num[i+1])))->toInteger();) ; if (sum mod 3 = 0) then ( return 0; ) else skip ; if (n = 1) then ( return -1; ) else skip ; for i : Integer.subrange(0, n-1) do ( if (sum mod 3 = ("" + ((num[i+1])))->toInteger() mod 3) then ( return 1; ) else skip) ; if (n = 2) then ( return -1; ) else skip ; return 2;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100000 ; def countPairsWithProductK(arr,n,k): count=0 ; hashmap=[False]*MAX ; for i in range(n): hashmap[arr[i]]=True ; for i in range(n): x=arr[i]; index=1.0*k/arr[i]; if(index>=0 and((index-int(index))==0)and hashmap[k//x]): count+=1 ; hashmap[x]=False ; return count ; if __name__=="__main__" : arr=[1,5,3,4,2]; N=len(arr); K=3 ; print(countPairsWithProductK(arr,N,K)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 100000; ; skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{5}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 2 })))); ; var N : int := (arr)->size(); ; var K : int := 3; ; execute (countPairsWithProductK(arr, N, K))->display(); ) else skip; operation countPairsWithProductK(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var count : int := 0; ; var hashmap : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, MAX); ; for i : Integer.subrange(0, n-1) do ( hashmap[arr[i+1]+1] := true;) ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := arr[i+1]; ; var index : double := 1.0 * k / arr[i+1]; ; if (index >= 0 & ((index - ("" + ((index)))->toInteger()) = 0) & hashmap[k div x+1]) then ( count := count + 1; ) else skip ; hashmap[x+1] := false;) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sum(a,b): sum=0 for i in range(1,min(a,b)): if(a % i==0 and b % i==0): sum+=i return sum A=10 B=15 print("Sum=",sum(A,B)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var A : int := 10 ; var B : int := 15 ; execute ("Sum=")->display(); operation sum(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(1, Set{a, b}->min()-1) do ( if (a mod i = 0 & b mod i = 0) then ( sum := sum + i ) else skip) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def swapNibbles(x): return((x & 0x0F)<<4 |(x & 0xF0)>>4) x=100 print(swapNibbles(x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := 100 ; execute (swapNibbles(x))->display(); operation swapNibbles(x : OclAny) : OclAny pre: true post: true activity: return (MathLib.bitwiseOr((MathLib.bitwiseAnd(x, 0x0F)) * (2->pow(4)), (MathLib.bitwiseAnd(x, 0xF0)) /(2->pow(4)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def reorderLogFiles(self,logs): letter_logs=[] digit_logs=[] for log in logs : if log.split(' ')[1].isnumeric(): digit_logs.append(log) else : letter_logs.append(log) return sorted(letter_logs,key=lambda x : x.split(' ')[1 :]+x.split(' ')[0])+digit_logs ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation reorderLogFiles(logs : OclAny) : OclAny pre: true post: true activity: var letter_logs : Sequence := Sequence{} ; var digit_logs : Sequence := Sequence{} ; for log : logs do ( if log.split(' ')[1+1]->matches("[0-9]*") then ( execute ((log) : digit_logs) ) else ( execute ((log) : letter_logs) )) ; return letter_logs->sortedBy($x | (lambda x : OclAny in (x.split(' ')->tail() + x.split(' ')->first()))->apply($x))->union(digit_logs); } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) b=[] counter={} positions={} for i,x in enumerate(a): if x not in counter : counter[x]=0 counter[x]+=1 b.append((x,counter[x])) positions[(x,counter[x])]=i a=sorted(b) result=[] for i,x in enumerate(a): pos=positions[x] if pos!=i : tmp=b[i] b[pos],b[i]=b[i],b[pos] result.append((i,positions[x])) positions[x],positions[tmp]=positions[tmp],positions[x] print(len(result)) for i,j in result : print(i,j) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := Sequence{} ; var counter : OclAny := Set{} ; var positions : OclAny := Set{} ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); if (counter)->excludes(x) then ( counter[x+1] := 0 ) else skip ; counter[x+1] := counter[x+1] + 1 ; execute ((Sequence{x, counter[x+1]}) : b) ; positions[Sequence{x, counter[x+1]}+1] := i) ; a := b->sort() ; var result : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); var pos : OclAny := positions[x+1] ; if pos /= i then ( var tmp : OclAny := b[i+1] ; var b[pos+1] : OclAny := null; var b[i+1] : OclAny := null; Sequence{b[pos+1],b[i+1]} := Sequence{b[i+1],b[pos+1]} ; execute ((Sequence{i, positions[x+1]}) : result) ; var positions[x+1] : OclAny := null; var positions[tmp+1] : OclAny := null; Sequence{positions[x+1],positions[tmp+1]} := Sequence{positions[tmp+1],positions[x+1]} ) else skip) ; execute ((result)->size())->display() ; for _tuple : result do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) array=list(map(int,input().split())) sorted_array=sorted(range(n),key=lambda i : array[i]) indexes={sorted_array[i]: i for i in range(n)} perm=[i for i in range(n)] result=[] for i in range(n): while perm[i]!=sorted_array[i]: j=indexes[perm[i]] perm[i],perm[j]=perm[j],perm[i] result.append((i,j)) print(len(result)) [print(pair[0],pair[1])for pair in result] main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; ; main(); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var array : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sorted_array : Sequence := Integer.subrange(0, n-1)->sortedBy($x | (lambda i : OclAny in (array[i+1]))->apply($x)) ; var indexes : Map := Integer.subrange(0, n-1)->select(i | true)->collect(i | Map{sorted_array[i+1] |-> i})->unionAll() ; var perm : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)) ; var result : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( while perm[i+1] /= sorted_array[i+1] do ( var j : OclAny := indexes[perm[i+1]+1] ; var perm[i+1] : OclAny := null; var perm[j+1] : OclAny := null; Sequence{perm[i+1],perm[j+1]} := Sequence{perm[j+1],perm[i+1]} ; execute ((Sequence{i, j}) : result))) ; execute ((result)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt from collections import defaultdict,deque from bisect import bisect_left as b_l from bisect import bisect_right as b_r import sys mod=10**9+7 for _ in range(int(input())): n,m,k=map(int,input().split()) a=list(map(int,input().split())) if(n==1 or m==1): print("No") continue else : a.sort(reverse=True) total=m if(total & 1): flag=False else : flag=True for i in a : if(total & 1): if((i//n)>=3): flag=True if((i//n)>1): total-=(i//n) if(total<=0 and flag): print("Yes") continue total=n if(total & 1): flag=False else : flag=True for i in a : if(total & 1): if((i//m)>=3): flag=True if((i//m)>1): total-=(i//m) if(total<=0 and flag): print("Yes") continue print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (n = 1 or m = 1) then ( execute ("No")->display() ; continue ) else ( a := a->sort() ; var total : OclAny := m ; if (MathLib.bitwiseAnd(total, 1)) then ( var flag : boolean := false ) else ( flag := true ) ; for i : a do ( if (MathLib.bitwiseAnd(total, 1)) then ( if ((i div n) >= 3) then ( flag := true ) else skip ) else skip ; if ((i div n) > 1) then ( total := total - (i div n) ) else skip) ; if (total <= 0 & flag) then ( execute ("Yes")->display() ; continue ) else skip ; total := n ; if (MathLib.bitwiseAnd(total, 1)) then ( flag := false ) else ( flag := true ) ; for i : a do ( if (MathLib.bitwiseAnd(total, 1)) then ( if ((i div m) >= 3) then ( flag := true ) else skip ) else skip ; if ((i div m) > 1) then ( total := total - (i div m) ) else skip) ; if (total <= 0 & flag) then ( execute ("Yes")->display() ; continue ) else skip ; execute ("No")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n<10 : print(n) else : l=len(str(n))-1 a=int(l*'9') b=n-a ans=0 while b>0 : ans+=b % 10 b//=10 print(l*9+ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n < 10 then ( execute (n)->display() ) else ( var l : double := (("" + ((n))))->size() - 1 ; var a : int := ("" + ((l * '9')))->toInteger() ; var b : double := n - a ; var ans : int := 0 ; while b > 0 do ( ans := ans + b mod 10 ; b := b div 10) ; execute (l * 9 + ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(i)for i in input().split()] b=sorted(a) num_swaps=0 ind=[] i=0 for i in range(n): if a[i]==b[i]: pass else : c=a[i :].index(b[i]) ind.append((i,c+i)) d=a[i] a[i]=b[i] a[c+i]=d num_swaps+=1 print(num_swaps) for e in ind : print(e[0],e[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var b : Sequence := a->sort() ; var num_swaps : int := 0 ; var ind : Sequence := Sequence{} ; var i : int := 0 ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = b[i+1] then ( skip ) else ( var c : OclAny := a.subrange(i+1)->indexOf(b[i+1]) - 1 ; execute ((Sequence{i, c + i}) : ind) ; var d : OclAny := a[i+1] ; a[i+1] := b[i+1] ; a[c + i+1] := d ; num_swaps := num_swaps + 1 )) ; execute (num_swaps)->display() ; for e : ind do ( execute (e->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(i)for i in input().split()] ans=[] for i in range(n): t=i for j in range(i+1,n): if a[t]>a[j]: t=j if i==t : continue ans.append((i,t)) a[i],a[t]=a[t],a[i] print(len(ans)) for i in ans : print(i[0],i[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var t : OclAny := i ; for j : Integer.subrange(i + 1, n-1) do ( if (a[t+1]->compareTo(a[j+1])) > 0 then ( t := j ) else skip) ; if i = t then ( continue ) else skip ; execute ((Sequence{i, t}) : ans) ; var a[i+1] : OclAny := null; var a[t+1] : OclAny := null; Sequence{a[i+1],a[t+1]} := Sequence{a[t+1],a[i+1]}) ; execute ((ans)->size())->display() ; for i : ans do ( execute (i->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) print(n) for i in range(n): pos=i for j in range(i+1,n): if a[j]toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (n)->display() ; for i : Integer.subrange(0, n-1) do ( var pos : OclAny := i ; for j : Integer.subrange(i + 1, n-1) do ( if (a[j+1]->compareTo(a[pos+1])) < 0 then ( pos := j ) else skip) ; execute (i)->display() ; var a[i+1] : OclAny := null; var a[pos+1] : OclAny := null; Sequence{a[i+1],a[pos+1]} := Sequence{a[pos+1],a[i+1]}); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- row1=list(map(int,input().split())); summ1=sum(row1) row2=list(map(int,input().split())); summ2=sum(row2) row3=list(map(int,input().split())); summ3=sum(row3) maxi=max(summ1,summ2,summ3) for i in range(maxi+1,10**5*3+1): a=i-summ1 ; b=i-summ2 ; c=i-summ3 if summ1+a==summ2+b==summ3+c and a+b+c==i : break for i in range(3): if i==0 : for j in row1 : if j==0 : print(a,end=" ") else : print(j,end=" ") elif i==1 : for j in row2 : if j==0 : print(b,end=" ") else : print(j,end=" ") else : for j in row3 : if j==0 : print(c,end=" ") else : print(j,end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var row1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); var summ1 : OclAny := (row1)->sum() ; var row2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); var summ2 : OclAny := (row2)->sum() ; var row3 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); var summ3 : OclAny := (row3)->sum() ; var maxi : OclAny := Set{summ1, summ2, summ3}->max() ; for i : Integer.subrange(maxi + 1, (10)->pow(5) * 3 + 1-1) do ( var a : double := i - summ1; var b : double := i - summ2; var c : double := i - summ3 ; if summ1 + a = summ2 + b & (summ2 + b == summ3 + c) & a + b + c = i then ( break ) else skip) ; for i : Integer.subrange(0, 3-1) do ( if i = 0 then ( for j : row1 do ( if j = 0 then ( execute (a)->display() ) else ( execute (j)->display() )) ) else (if i = 1 then ( for j : row2 do ( if j = 0 then ( execute (b)->display() ) else ( execute (j)->display() )) ) else ( for j : row3 do ( if j = 0 then ( execute (c)->display() ) else ( execute (j)->display() )) ) ) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys def _input(): return map(int,input().split()) n,k=_input() s=input() lst=dict() i=0 while icompareTo(n - 1)) < 0 do ( var l : int := 1 ; while (i->compareTo(n - 1)) < 0 & s[i+1] = s[i + 1+1] & l /= k do ( l := l + 1; i := i + 1) ; if l = k then ( if (lst.keys())->excludes(s[i+1]) then ( execute ((Map{ s[i+1] |-> 1 }) <: lst) ) else ( lst[s[i+1]+1] := lst[s[i+1]+1] + 1 ) ; l := 1 ) else skip ; if i = n - 2 then ( if k = 1 then ( if (lst.keys())->includes(s[i + 1+1]) then ( lst[s[i+1]+1] := lst[s[i+1]+1] + 1 ) else skip ) else skip ) else skip ; i := i + 1) ; var res : int := 0 ; for i : lst.values() do ( res := Set{res, i}->max()) ; if res = 0 & n = k & n = 1 then ( execute (1)->display() ) else ( execute (res)->display() ); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,k=list(map(int,input().split())) string=input() temp_dict={} counter=0 for i in range(n): if string[i]==string[i-1]: counter+=1 else : counter=1 if counter>=k : if string[i]in temp_dict : temp_dict[string[i]]+=1 else : temp_dict[string[i]]=1 counter=0 print(0 if len(temp_dict)==0 else max(temp_dict.values())) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var string : String := (OclFile["System.in"]).readLine() ; var temp_dict : OclAny := Set{} ; var counter : int := 0 ; for i : Integer.subrange(0, n-1) do ( if string[i+1] = string[i - 1+1] then ( counter := counter + 1 ) else ( counter := 1 ) ; if (counter->compareTo(k)) >= 0 then ( if (temp_dict)->includes(string[i+1]) then ( temp_dict[string[i+1]+1] := temp_dict[string[i+1]+1] + 1 ) else ( temp_dict[string[i+1]+1] := 1 ) ; counter := 0 ) else skip) ; execute (if (temp_dict)->size() = 0 then 0 else (temp_dict.values())->max() endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import itertools def solve(n,k,s): ans=0 cnt=collections.Counter() for char,group in itertools.groupby(s): group=list(group) cnt[char]+=len(group)//k ans=max(ans,cnt[char]) print(ans) n,k=map(int,input().split()) s=input().strip() solve(n,k,s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; s := input()->trim() ; solve(n, k, s); operation solve(n : OclAny, k : OclAny, s : OclAny) pre: true post: true activity: var ans : int := 0 ; var cnt : OclAny := .Counter() ; for _tuple : itertools.groupby(s) do (var _indx : int := 1; var char : OclAny := _tuple->at(_indx); _indx := _indx + 1; var group : OclAny := _tuple->at(_indx); var group : Sequence := (group) ; cnt[char+1] := cnt[char+1] + (group)->size() div k ; ans := Set{ans, cnt[char+1]}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict n,k=map(int,input().split()) s=input().rstrip() d=defaultdict(int) i=0 j=i+1 while jmx : mx=d[x] print(mx) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := input().rstrip() ; var d : OclAny := defaultdict(OclType["int"]) ; var i : int := 0 ; var j : int := i + 1 ; while (j->compareTo(n)) < 0 do ( if s[i+1] = s[j+1] then ( j := j + 1 ) else ( d[s[i+1]+1] := d[s[i+1]+1] + ((j - i) div k) ; i := j ; j := j + 1 )) ; d[s[i+1]+1] := d[s[i+1]+1] + ((j - i) div k) ; var mx : int := 0 ; for x : d do ( if (d[x+1]->compareTo(mx)) > 0 then ( mx := d[x+1] ) else skip) ; execute (mx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict n,k=[int(i)for i in input().split()] s=input() i,c,ch,j=0,0,s[0],0 cnt=defaultdict(int) while iselect(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var s : String := (OclFile["System.in"]).readLine() ; var i : OclAny := null; var c : OclAny := null; var ch : OclAny := null; var j : OclAny := null; Sequence{i,c,ch,j} := Sequence{0,0,s->first(),0} ; var cnt : OclAny := defaultdict(OclType["int"]) ; while (i->compareTo(n)) < 0 do ( while (j->compareTo(n)) < 0 & s[i+1] = s[j+1] do ( c := c + 1 ; j := j + 1) ; cnt[s[i+1]+1] := cnt[s[i+1]+1] + c div k ; var i : OclAny := j ; var c : int := 0) ; execute ((cnt.values())->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isValidString(str,n): idx=str.find("b") if(idx==0): return False while(idx!=-1): if(str[idx-1]!='a'): return False if(idx+1size() ; execute (isValidString(OclType["String"], n))->display() ) else skip; operation isValidString(OclType["String"] : OclAny, n : OclAny) : OclAny pre: true post: true activity: var idx : String := ("" + (->indexOf("b") - 1)) ; if (idx = 0) then ( return false ) else skip ; while (idx /= -1) do ( if (("" + ([idx - 1+1])) /= 'a') then ( return false ) else skip ; if ((idx + 1->compareTo(n)) < 0 & ("" + ([idx + 1+1])) /= 'b') then ( return false ) else skip ; if ((idx + 2->compareTo(n)) < 0 & ("" + ([idx + 2+1])) = 'b') then ( return false ) else skip ; if (idx = n - 1) then ( return false ) else skip ; idx := ("" + (->indexOf("b", idx + 2) - 1))) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def prime(n): for i in range(2,n+1): if i*i>n+1 : break if(n % i==0): return False return True def thirdNumber(a,b): summ=0 temp=0 summ=a+b temp=1 if(summ & 1): temp=2 while(prime(summ+temp)==False): temp+=2 print(temp) a=3 b=5 thirdNumber(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 3 ; b := 5 ; thirdNumber(a, b); operation prime(n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(2, n + 1-1) do ( if (i * i->compareTo(n + 1)) > 0 then ( break ) else skip ; if (n mod i = 0) then ( return false ) else skip) ; return true; operation thirdNumber(a : OclAny, b : OclAny) pre: true post: true activity: var summ : int := 0 ; var temp : int := 0 ; summ := a + b ; temp := 1 ; if (MathLib.bitwiseAnd(summ, 1)) then ( temp := 2 ) else skip ; while (prime(summ + temp) = false) do ( temp := temp + 2) ; execute (temp)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node(): def __init__(self): self.lt=None self.rt=None self.dep=None class Trie(): def __init__(self): self.root=Node() self.root.dep=0 def add(self,string): node=self.root for s in string : if s=='0' : if node.lt is None : node.lt=Node() node.lt.dep=node.dep+1 node=node.lt else : if node.rt is None : node.rt=Node() node.rt.dep=node.dep+1 node=node.rt N,L=map(int,input().split()) trie=Trie() for _ in range(N): s=input() trie.add(s) subgame=[] stack=[trie.root] while stack : node=stack.pop() if node.lt is None and node.rt is None : continue elif node.rt is None : stack.append(node.lt) subgame.append(L-node.dep) elif node.lt is None : stack.append(node.rt) subgame.append(L-node.dep) else : stack.append(node.lt) stack.append(node.rt) def grundy(n): if n==0 : return 0 if n % 2==1 : return 1 if n==2**(n.bit_length()-1): return n return grundy(n-2**(n.bit_length()-1)) g=0 for l in subgame : g ^=grundy(l) print('Alice' if g!=0 else 'Bob') ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute lt : OclAny := null; attribute rt : OclAny := null; attribute dep : OclAny := null; operation initialise() : pre: true post: true activity: self.lt := null ; self.rt := null ; self.dep := null; return self; } class Trie { static operation newTrie() : Trie pre: true post: Trie->exists( _x | result = _x ); attribute root : Node := (Node.newNode()).initialise(); attribute (expr (atom (name self)) (trailer . (name root)) (trailer . (name dep))) : int := 0; operation initialise() : pre: true post: true activity: self.root := (Node.newNode()).initialise() ; self.root.dep := 0; return self; operation add(string : OclAny) pre: true post: true activity: var node : OclAny := self.root ; for s : string do ( if s = '0' then ( if node.lt <>= null then ( node.lt := (Node.newNode()).initialise() ; node.lt.dep := node.dep + 1 ) else skip ; node := node.lt ) else ( if node.rt <>= null then ( node.rt := (Node.newNode()).initialise() ; node.rt.dep := node.dep + 1 ) else skip ; node := node.rt )); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := null; var L : OclAny := null; Sequence{N,L} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var trie : Trie := (Trie.newTrie()).initialise() ; for _anon : Integer.subrange(0, N-1) do ( var s : String := (OclFile["System.in"]).readLine() ; execute ((s) : trie)) ; var subgame : Sequence := Sequence{} ; var stack : Sequence := Sequence{ trie.root } ; while stack do ( node := stack->last() ; stack := stack->front() ; if node.lt <>= null & node.rt <>= null then ( continue ) else (if node.rt <>= null then ( execute ((node.lt) : stack) ; execute ((L - node.dep) : subgame) ) else (if node.lt <>= null then ( execute ((node.rt) : stack) ; execute ((L - node.dep) : subgame) ) else ( execute ((node.lt) : stack) ; execute ((node.rt) : stack) ) ) ) ) ; skip ; var g : int := 0 ; for l : subgame do ( g := g xor grundy(l)) ; execute (if g /= 0 then 'Alice' else 'Bob' endif)->display(); operation grundy(n : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( return 0 ) else skip ; if n mod 2 = 1 then ( return 1 ) else skip ; if n = (2)->pow((n.bit_length() - 1)) then ( return n ) else skip ; return grundy(n - (2)->pow((n.bit_length() - 1))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(100000) def dfs(cur,dep=0): if cur==-1 : x=l-dep return x &-x return dfs(trie[cur][0],dep+1)^ dfs(trie[cur][1],dep+1) n,l=map(int,input().split()) trie=[[-1,-1]for _ in range(100001)] idx=1 for s in(input()for _ in range(n)): cur=0 for c in map(int,s): if trie[cur][c]==-1 : trie[cur][c]=idx idx+=1 cur=trie[cur][c] xor=dfs(trie[0][0])^ dfs(trie[0][1]) print('Alice' if xor else 'Bob') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(100000) ; skip ; var n : OclAny := null; var l : OclAny := null; Sequence{n,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var trie : Sequence := Integer.subrange(0, 100001-1)->select(_anon | true)->collect(_anon | (Sequence{-1}->union(Sequence{ -1 }))) ; var idx : int := 1 ; for s : Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))} do ( cur := 0 ; for c : (s)->collect( _x | (OclType["int"])->apply(_x) ) do ( if trie[cur+1][c+1] = -1 then ( trie[cur+1][c+1] := idx ; idx := idx + 1 ) else skip ; cur := trie[cur+1][c+1])) ; var xor : int := MathLib.bitwiseXor(dfs(trie->first()->first()), dfs(trie->first()[1+1])) ; execute (if xor then 'Alice' else 'Bob' endif)->display(); operation dfs(cur : OclAny, dep : int) : OclAny pre: true post: true activity: if dep->oclIsUndefined() then dep := 0 else skip; if cur = -1 then ( var x : double := l - dep ; return MathLib.bitwiseAnd(x, -x) ) else skip ; return MathLib.bitwiseXor(dfs(trie[cur+1]->first(), dep + 1), dfs(trie[cur+1][1+1], dep + 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import cmp_to_key def f(s,t): m=min(len(s),len(t)) if s[: m]>t[: m]: return 1 elif s[: m]len(t): return-1 else : return 1 def ms(s,t): i=0 for c1,c2 in zip(s,t): if c1!=c2 : return i i+=1 return i def xxor(x): if x & 3==0 : return x if x & 3==1 : return 1 if x & 3==2 : return x+1 if x & 3==3 : return 0 def gray(x): return x ^(x//2) n,l=map(int,input().split()) s=[input()for _ in range(n)] s.sort(key=cmp_to_key(f)) g=gray(l)^ gray(l-len(s[0])) for i in range(n-1): b=ms(s[i],s[i+1])+1 g ^=gray(l-b+1)^ gray(l-b) t=len(s[i+1])-b g ^=gray(l-b)^ gray(l-b-t) if g==0 : print('Bob') else : print('Alice') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var n : OclAny := null; var l : OclAny := null; Sequence{n,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; s := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; s := s->sort() ; var g : int := MathLib.bitwiseXor(gray(l), gray(l - (s->first())->size())) ; for i : Integer.subrange(0, n - 1-1) do ( var b : OclAny := ms(s[i+1], s[i + 1+1]) + 1 ; g := g xor MathLib.bitwiseXor(gray(l - b + 1), gray(l - b)) ; t := (s[i + 1+1])->size() - b ; g := g xor MathLib.bitwiseXor(gray(l - b), gray(l - b - t))) ; if g = 0 then ( execute ('Bob')->display() ) else ( execute ('Alice')->display() ); operation f(s : OclAny, t : OclAny) : OclAny pre: true post: true activity: var m : OclAny := Set{(s)->size(), (t)->size()}->min() ; if (s.subrange(1,m)->compareTo(t.subrange(1,m))) > 0 then ( return 1 ) else (if (s.subrange(1,m)->compareTo(t.subrange(1,m))) < 0 then ( return -1 ) else ( if ((s)->size()->compareTo((t)->size())) > 0 then ( return -1 ) else ( return 1 ) ) ) ; operation ms(s : OclAny, t : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; for _tuple : Integer.subrange(1, s->size())->collect( _indx | Sequence{s->at(_indx), t->at(_indx)} ) do (var _indx : int := 1; var c1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c2 : OclAny := _tuple->at(_indx); if c1 /= c2 then ( return i ) else skip ; i := i + 1) ; return i; operation xxor(x : OclAny) : OclAny pre: true post: true activity: if MathLib.bitwiseAnd(x, 3) = 0 then ( return x ) else skip ; if MathLib.bitwiseAnd(x, 3) = 1 then ( return 1 ) else skip ; if MathLib.bitwiseAnd(x, 3) = 2 then ( return x + 1 ) else skip ; if MathLib.bitwiseAnd(x, 3) = 3 then ( return 0 ) else skip; operation gray(x : OclAny) : OclAny pre: true post: true activity: return MathLib.bitwiseXor(x, (x div 2)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(2*10**5) class TrieNode : def __init__(self,char): self.char=char self.nextnode=dict() self.is_indict=False class Trie : def __init__(self,charset): self.charset=charset self.root=TrieNode('') def add(self,a_str): node=self.root for i,char in enumerate(a_str): if char not in node.nextnode : node.nextnode[char]=TrieNode(char) node=node.nextnode[char] if i==len(a_str)-1 : node.is_indict=True def dfs(self,node,dep): ret,cnt=0,0 if node.is_indict : return 0 for s in '01' : if s not in node.nextnode : cnt+=1 else : ret ^=self.dfs(node.nextnode[s],dep+1) height=L-dep if cnt % 2 : power2=0 while height>0 and height % 2==0 : power2+=1 height//=2 ret ^=2**power2 return ret def debug_output(self,node,now): print(node.char,list(node.nextnode.items()),node.is_indict,now) if node.is_indict : print(now) for n in node.nextnode.values(): self.debug_output(n,now+n.char) N,L=map(int,input().split()) T=Trie('01') for _ in range(N): T.add(input()) print("Alice" if T.dfs(T.root,0)else "Bob") ------------------------------------------------------------ OCL File: --------- class TrieNode { static operation newTrieNode() : TrieNode pre: true post: TrieNode->exists( _x | result = _x ); attribute char : OclAny := char; attribute nextnode : Map := (arguments ( )); attribute is_indict : boolean := false; operation initialise(char : OclAny) : TrieNode pre: true post: true activity: self.char := char ; self.nextnode := (arguments ( )) ; self.is_indict := false; return self; } class Trie { static operation newTrie() : Trie pre: true post: Trie->exists( _x | result = _x ); attribute charset : OclAny := charset; attribute root : TrieNode := (TrieNode.newTrieNode()).initialise(''); operation initialise(charset : OclAny) : Trie pre: true post: true activity: self.charset := charset ; self.root := (TrieNode.newTrieNode()).initialise(''); return self; operation add(a_str : OclAny) pre: true post: true activity: var node : OclAny := self.root ; for _tuple : Integer.subrange(1, (a_str)->size())->collect( _indx | Sequence{_indx-1, (a_str)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var char : OclAny := _tuple->at(_indx); if (node.nextnode)->excludes(char) then ( node.nextnode[char+1] := (TrieNode.newTrieNode()).initialise(char) ) else skip ; node := node.nextnode[char+1] ; if i = (a_str)->size() - 1 then ( node.is_indict := true ) else skip); operation dfs(node : OclAny,dep : OclAny) : OclAny pre: true post: true activity: var ret : OclAny := null; var cnt : OclAny := null; Sequence{ret,cnt} := Sequence{0,0} ; if node.is_indict then ( return 0 ) else skip ; for s : '01'->characters() do ( if (node.nextnode)->excludes(s) then ( cnt := cnt + 1 ) else ( ret := ret xor self.dfs(node.nextnode[s+1], dep + 1) )) ; var height : double := L - dep ; if cnt mod 2 then ( var power2 : int := 0 ; while height > 0 & height mod 2 = 0 do ( power2 := power2 + 1 ; height := height div 2) ; ret := ret xor (2)->pow(power2) ) else skip ; return ret; operation debug_output(node : OclAny,now : OclAny) pre: true post: true activity: execute (node.char)->display() ; if node.is_indict then ( execute (now)->display() ) else skip ; for n : node.nextnode.values() do ( self.debug_output(n, now + n.char)); } class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(2 * (10)->pow(5)) ; skip ; skip ; var N : OclAny := null; var L : OclAny := null; Sequence{N,L} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var T : Trie := (Trie.newTrie()).initialise('01') ; for _anon : Integer.subrange(0, N-1) do ( execute (((OclFile["System.in"]).readLine()) : T)) ; execute (if T.dfs(T.root, 0) then "Alice" else "Bob" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def print(*args,end='\n',sep=' ')->None : sys.stdout.write(sep.join(map(str,args))+end) def Solve(): l1=list(map(int,input().split())) l2=list(map(int,input().split())) l3=list(map(int,input().split())) x,y,z=sum(l1),sum(l2),sum(l3) l=0 ; r=10**6 ; ans=0 while l<=r : mid=(l+r)//2 if x+mid-y<=0 or x+mid-z<=0 or mid+x+mid-y+x+mid-z (test (logical_test (comparison (expr (atom None))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name sep)) (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name args)))))))) ))))))))) )))) + (expr (atom (name end))))))))) )))))))))))))) operation Solve() pre: true post: true activity: var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l3 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := Sequence{(l1)->sum(),(l2)->sum(),(l3)->sum()} ; var l : int := 0; var r : double := (10)->pow(6); var ans : int := 0 ; while (l->compareTo(r)) <= 0 do ( var mid : int := (l + r) div 2 ; if x + mid - y <= 0 or x + mid - z <= 0 or (mid + x + mid - y + x + mid - z->compareTo(x + mid)) < 0 then ( l := mid + 1 ) else ( r := mid - 1 ) ; if mid + x + mid - y + x + mid - z = x + mid & 1 <= mid & (mid <= (10)->pow(5)) then ( ans := mid ) else skip) ; l1->first() := ans ; l2[1+1] := x + ans - y ; l3[2+1] := x + ans - z ; execute ((argument * (test (logical_test (comparison (expr (atom (name l1))))))))->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name l2))))))))->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name l3))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import sys if os.getenv("LOCAL"): sys.stdin=open("_in.txt","r") sys.setrecursionlimit(10**9) INF=float("inf") IINF=10**18 MOD=10**9+7 def make_trie(str_set): trie={} for s in str_set : node=trie for c in s : if c not in node : node[c]={} node=node[c] return trie N,L=list(map(int,sys.stdin.buffer.readline().split())) S=[sys.stdin.buffer.readline().decode().rstrip()for _ in range(N)] trie=make_trie(S) def grundy(i): ret=1 while(L-i+1)& ret==0 : ret<<=1 return ret g=0 stack=[(trie,0)] while stack : nodes,depth=stack.pop() if depthpow(9)) ; var INF : double := ("" + (("inf")))->toReal() ; var IINF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; skip ; var N : OclAny := null; var L : OclAny := null; Sequence{N,L} := ((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var S : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (sys.stdin.buffer.readLine().decode().rstrip())) ; trie := make_trie(S) ; skip ; var g : int := 0 ; var stack : Sequence := Sequence{ Sequence{trie, 0} } ; while stack do ( var nodes : OclAny := null; var depth : OclAny := null; Sequence{nodes,depth} := stack->last() ; stack := stack->front() ; if (depth->compareTo(L)) < 0 & (nodes)->size() = 1 then ( g := g xor grundy(depth + 1) ) else skip ; for children : nodes.values() do ( execute ((Sequence{children, depth + 1}) : stack))) ; if g = 0 then ( execute ('Bob')->display() ) else ( execute ('Alice')->display() ); operation make_trie(str_set : OclAny) : OclAny pre: true post: true activity: var trie : OclAny := Set{} ; for s : str_set do ( var node : OclAny := trie ; for c : s do ( if (node)->excludes(c) then ( node[c+1] := Set{} ) else skip ; node := node[c+1])) ; return trie; operation grundy(i : OclAny) : OclAny pre: true post: true activity: var ret : int := 1 ; while MathLib.bitwiseAnd((L - i + 1), ret) = 0 do ( ret := ret * (2->pow(1))) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a='kogakubu10gokan' n,m=map(int,input().split()) for _ in range(n): c,b=input().split() if int(c)<=m : a=b print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := 'kogakubu10gokan' ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for _anon : Integer.subrange(0, n-1) do ( var c : OclAny := null; var b : OclAny := null; Sequence{c,b} := input().split() ; if (("" + ((c)))->toInteger()->compareTo(m)) <= 0 then ( a := b ) else skip) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,Q=map(int,input().split()) rename=[] for i in range(N): year,name=input().split() year=int(year) rename.append([year,name]) if Q=rename[-1][0]: print(rename[-1][1]) else : for i in range(N-1): if rename[i][0]<=Qcollect( _x | (OclType["int"])->apply(_x) ) ; var rename : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var year : OclAny := null; var name : OclAny := null; Sequence{year,name} := input().split() ; var year : int := ("" + ((year)))->toInteger() ; execute ((Sequence{year}->union(Sequence{ name })) : rename)) ; if (Q->compareTo(rename->first()->first())) < 0 then ( execute ("kogakubu10gokan")->display() ) else (if (Q->compareTo(rename->last()->first())) >= 0 then ( execute (rename->last()[1+1])->display() ) else ( for i : Integer.subrange(0, N - 1-1) do ( if (rename[i+1]->first()->compareTo(Q)) <= 0 & (Q < rename[i + 1+1]->first()) then ( execute (rename[i+1][1+1])->display() ) else skip) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left n,q=map(int,input().split()) ans=["kogakubu10gokan"] for i in range(n): y,s=input().split() ans.append(s) y=int(y) if y==q : print(s) exit() elif y>q : print(ans[i]) exit() print(ans[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := Sequence{ "kogakubu10gokan" } ; for i : Integer.subrange(0, n-1) do ( var y : OclAny := null; var s : OclAny := null; Sequence{y,s} := input().split() ; execute ((s) : ans) ; var y : int := ("" + ((y)))->toInteger() ; if y = q then ( execute (s)->display() ; exit() ) else (if (y->compareTo(q)) > 0 then ( execute (ans[i+1])->display() ; exit() ) else skip)) ; execute (ans->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect n,q=map(int,input().split()) year=[1] name=["kogakubu10gokan"] for i in range(n): ye,na=map(str,input().split()) year.append(int(ye)) name.append(na) b=bisect.bisect_left(year,q+1) print(name[b-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var year : Sequence := Sequence{ 1 } ; var name : Sequence := Sequence{ "kogakubu10gokan" } ; for i : Integer.subrange(0, n-1) do ( var ye : OclAny := null; var na : OclAny := null; Sequence{ye,na} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; execute ((("" + ((ye)))->toInteger()) : year) ; execute ((na) : name)) ; var b : OclAny := bisect.bisect_left(year, q + 1) ; execute (name[b - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=10**9+7 n,k=map(int,input().split()) coef=[] for i in range(1,int(n**0.5)+1): coef.append((n//i)-(n//(i+1))) coef+=[1]*(n-sum(coef)) coef=coef[: :-1] nn=len(coef) dp=[[0]*nn for _ in range(k+1)] dp[0][0]=1 for i in range(1,k+1): tmp=0 for j in range(nn-1,-1,-1): tmp+=dp[i-1][(nn-1)-j] tmp %=mod dp[i][j]=coef[j]*tmp dp[i][j]%=mod print(sum(dp[k])% mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : double := (10)->pow(9) + 7 ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var coef : Sequence := Sequence{} ; for i : Integer.subrange(1, ("" + (((n)->pow(0.5))))->toInteger() + 1-1) do ( execute (((n div i) - (n div (i + 1))) : coef)) ; coef := coef + MatrixLib.elementwiseMult(Sequence{ 1 }, (n - (coef)->sum())) ; coef := coef(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var nn : int := (coef)->size() ; var dp : Sequence := Integer.subrange(0, k + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, nn))) ; dp->first()->first() := 1 ; for i : Integer.subrange(1, k + 1-1) do ( var tmp : int := 0 ; for j : Integer.subrange(-1 + 1, nn - 1)->reverse() do ( tmp := tmp + dp[i - 1+1][(nn - 1) - j+1] ; tmp := tmp mod mod ; dp[i+1][j+1] := coef[j+1] * tmp ; dp[i+1][j+1] := dp[i+1][j+1] mod mod)) ; execute ((dp[k+1])->sum() mod mod)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(a==0): return b return gcd(b % a,a) def findgcd(n,x,y): g=gcd(x,y) for i in range(g): print(n) n=123 x=5 y=2 findgcd(n,x,y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 123 ; x := 5 ; y := 2 ; findgcd(n, x, y); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0) then ( return b ) else skip ; return gcd(b mod a, a); operation findgcd(n : OclAny, x : OclAny, y : OclAny) pre: true post: true activity: var g : OclAny := gcd(x, y) ; for i : Integer.subrange(0, g-1) do ( execute (n)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect n=int(input()) P=[list(map(int,input().split()))for i in range(n)] M=10**5+1 def policy1(P): A=[a for a,b in P] B=[b for a,b in P] A.sort(); B.sort() ans=1 for a,b in P : left=bisect(B,a) right=n-bisect(A,b-1) ans=max(ans,n-(left+right)) return ans def policy2(P): D=[0]*M for a,b in P : D[a]+=1 D[b]-=1 for i in range(1,M): D[i]+=D[i-1] return max(D) print(policy1(P),policy2(P)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var P : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var M : double := (10)->pow(5) + 1 ; skip ; skip ; execute (policy1(P))->display(); operation policy1(P : OclAny) : OclAny pre: true post: true activity: var A : Sequence := P->select(_tuple | true)->collect(_tuple | let a : OclAny = _tuple->at(1) in let b : OclAny = _tuple->at(2) in (a)) ; var B : Sequence := P->select(_tuple | true)->collect(_tuple | let a : OclAny = _tuple->at(1) in let b : OclAny = _tuple->at(2) in (b)) ; A := A->sort(); B := B->sort() ; var ans : int := 1 ; for _tuple : P do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); var left : OclAny := bisect(B, a) ; var right : double := n - bisect(A, b - 1) ; ans := Set{ans, n - (left + right)}->max()) ; return ans; operation policy2(P : OclAny) : OclAny pre: true post: true activity: var D : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, M) ; for _tuple : P do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); D[a+1] := D[a+1] + 1 ; D[b+1] := D[b+1] - 1) ; for i : Integer.subrange(1, M-1) do ( D[i+1] := D[i+1] + D[i - 1+1]) ; return (D)->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ab=[list(map(int,input().split()))for _ in range(n)] pol1=0 pol2=0 ft=[[0]*2 for _ in range(100000)] for i in ab : ft[i[0]-1][0]+=1 ft[i[1]-1][1]+=1 ftsum=[[0]*2 for _ in range(100000)] ftsum[0][0]=ft[0][0] for i in range(1,len(ft)): ftsum[i][0]=ftsum[i-1][0]+ft[i][0] ftsum[i][1]=ftsum[i-1][1]+ft[i][1] for i in range(len(ft)-1): pol2=max(pol2,ftsum[i][0]-ftsum[i][1]) for f,t in ab : f=f-1 t=t-1 temp=ftsum[t-1][0] if f!=0 : temp-=ftsum[f][1] pol1=max(pol1,temp) print(pol1,pol2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ab : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var pol1 : int := 0 ; var pol2 : int := 0 ; var ft : Sequence := Integer.subrange(0, 100000-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 2))) ; for i : ab do ( ft[i->first() - 1+1]->first() := ft[i->first() - 1+1]->first() + 1 ; ft[i[1+1] - 1+1][1+1] := ft[i[1+1] - 1+1][1+1] + 1) ; var ftsum : Sequence := Integer.subrange(0, 100000-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 2))) ; ftsum->first()->first() := ft->first()->first() ; for i : Integer.subrange(1, (ft)->size()-1) do ( ftsum[i+1]->first() := ftsum[i - 1+1]->first() + ft[i+1]->first() ; ftsum[i+1][1+1] := ftsum[i - 1+1][1+1] + ft[i+1][1+1]) ; for i : Integer.subrange(0, (ft)->size() - 1-1) do ( pol2 := Set{pol2, ftsum[i+1]->first() - ftsum[i+1][1+1]}->max()) ; for _tuple : ab do (var _indx : int := 1; var f : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); var f : double := f - 1 ; var t : double := t - 1 ; var temp : OclAny := ftsum[t - 1+1]->first() ; if f /= 0 then ( temp := temp - ftsum[f+1][1+1] ) else skip ; pol1 := Set{pol1, temp}->max()) ; execute (pol1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- X=list(map(int,input())) sn=[] for i in range(len(X)): sn.append(sum(X[0 : i+1])) ssn=[] for i in range(len(X)): if(sn[i]!=0): ssn.append(sn[i]-1+9*(len(X)-1-i)) ssn.append(sum(X)) print(max(ssn)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var X : Sequence := (((OclFile["System.in"]).readLine())->collect( _x | (OclType["int"])->apply(_x) )) ; var sn : Sequence := Sequence{} ; for i : Integer.subrange(0, (X)->size()-1) do ( execute (((X.subrange(0+1, i + 1))->sum()) : sn)) ; var ssn : Sequence := Sequence{} ; for i : Integer.subrange(0, (X)->size()-1) do ( if (sn[i+1] /= 0) then ( execute ((sn[i+1] - 1 + 9 * ((X)->size() - 1 - i)) : ssn) ) else skip) ; execute (((X)->sum()) : ssn) ; execute ((ssn)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**8) ini=lambda : int(sys.stdin.readline()) inm=lambda : map(int,sys.stdin.readline().split()) inl=lambda : list(inm()) ins=lambda : sys.stdin.readline().rstrip() debug=lambda*a,**kw : print("\033[33m",*a,"\033[0m",**dict(file=sys.stderr,**kw)) s=ins() def solve(): ans=9*(len(s)-1) x=[int(d)for d in s] sx=sum(x) ans=max(ans,sx) ans=max(ans,(x[0]-1)+9*(len(s)-1)) return ans print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(8)) ; var ini : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var inm : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var inl : Function := lambda $$ : OclAny in ((inm->apply())) ; var ins : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var debug : Function := lambda a : Sequence(OclAny), kw : Map(String, OclAny) in (("\033[33m")->display()) ; var s : OclAny := ins->apply() ; skip ; execute (solve())->display(); operation solve() : OclAny pre: true post: true activity: var ans : double := 9 * ((s)->size() - 1) ; var x : Sequence := s->select(d | true)->collect(d | (("" + ((d)))->toInteger())) ; var sx : OclAny := (x)->sum() ; ans := Set{ans, sx}->max() ; ans := Set{ans, (x->first() - 1) + 9 * ((s)->size() - 1)}->max() ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def print(*args,end='\n',sep=' ')->None : sys.stdout.write(sep.join(map(str,args))+end) def Solve(): l1=list(map(int,input().split())) l2=list(map(int,input().split())) l3=list(map(int,input().split())) x,y,z=sum(l1),sum(l2),sum(l3) l=0 ; r=10**5 ; ans=0 while l<=r : mid=(l+r)//2 if x+mid-y<=0 or x+mid-z<=0 or mid+x+mid-y+x+mid-z (test (logical_test (comparison (expr (atom None))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name sep)) (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name args)))))))) ))))))))) )))) + (expr (atom (name end))))))))) )))))))))))))) operation Solve() pre: true post: true activity: var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l3 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := Sequence{(l1)->sum(),(l2)->sum(),(l3)->sum()} ; var l : int := 0; var r : double := (10)->pow(5); var ans : int := 0 ; while (l->compareTo(r)) <= 0 do ( var mid : int := (l + r) div 2 ; if x + mid - y <= 0 or x + mid - z <= 0 or (mid + x + mid - y + x + mid - z->compareTo(x + mid)) < 0 then ( l := mid + 1 ) else ( r := mid - 1 ) ; if mid + x + mid - y + x + mid - z = x + mid & 1 <= mid & (mid <= (10)->pow(5)) then ( ans := mid ) else skip) ; l1->first() := ans ; l2[1+1] := x + ans - y ; l3[2+1] := x + ans - z ; execute ((argument * (test (logical_test (comparison (expr (atom (name l1))))))))->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name l2))))))))->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name l3))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=input() Nl=len(N) tmp=N[0]+'9'*(Nl-1) if int(N)>=int(tmp): answer=int(N[0])+9*(Nl-1) else : answer=int(N[0])-1+9*(Nl-1) print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : String := (OclFile["System.in"]).readLine() ; var Nl : int := (N)->size() ; var tmp : OclAny := N->first() + StringLib.nCopies('9', (Nl - 1)) ; if (("" + ((N)))->toInteger()->compareTo(("" + ((tmp)))->toInteger())) >= 0 then ( var answer : int := ("" + ((N->first())))->toInteger() + 9 * (Nl - 1) ) else ( answer := ("" + ((N->first())))->toInteger() - 1 + 9 * (Nl - 1) ) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ret=0 i=True while(n>=9): ret+=9 i=i and(n % 10==9) n//=10 ret+=n-1 if i : ret+=1 print(ret) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ret : int := 0 ; var i : boolean := true ; while (n >= 9) do ( ret := ret + 9 ; i := i & (n mod 10 = 9) ; n := n div 10) ; ret := ret + n - 1 ; if i then ( ret := ret + 1 ) else skip ; execute (ret)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys N=sys.stdin.readline().strip() if len(N)==1 : print(N) else : N2=N[1 :] if all(map(lambda d : d=='9',N2)): print(sum(map(int,N))) else : print(int(N[0])-1+9*len(N2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := sys.stdin.readLine()->trim() ; if (N)->size() = 1 then ( execute (N)->display() ) else ( var N2 : OclAny := N->tail() ; if ((N2)->collect( _x | (lambda d : OclAny in (d = '9'))->apply(_x) ))->forAll( _x | _x = true ) then ( execute (((N)->collect( _x | (OclType["int"])->apply(_x) ))->sum())->display() ) else ( execute (("" + ((N->first())))->toInteger() - 1 + 9 * (N2)->size())->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt N=100000 ; prime=[1]*N ; divi=[0]*N ; sum=[0]*N ; def SieveOfEratosthenes(): for i in range(N): prime[i]=1 ; prime[0]=prime[1]=0 ; for p in range(2,int(sqrt(N))+1): if(prime[p]==1): for i in range(p*p,N,p): prime[i]=0 ; def DivisorCount(): for i in range(1,N): for j in range(i,N,i): divi[j]+=1 ; def pre(): for i in range(1,N): if(prime[divi[i]]==1): sum[i]=i ; for i in range(1,N): sum[i]+=sum[i-1]; if __name__=="__main__" : l=5 ; r=8 ; SieveOfEratosthenes(); DivisorCount(); pre(); print(sum[r]-sum[l-1]); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 100000; ; var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, N); ; var divi : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N); ; var sum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N); ; skip ; skip ; skip ; if __name__ = "__main__" then ( var l : int := 5; var r : int := 8; ; SieveOfEratosthenes(); ; DivisorCount(); ; pre(); ; execute ([r+1]->sum() - [l - 1+1]->sum())->display(); ) else skip; operation SieveOfEratosthenes() pre: true post: true activity: for i : Integer.subrange(0, N-1) do ( prime[i+1] := 1;) ; prime->first() := 0; var prime[1+1] : int := 0; ; for p : Integer.subrange(2, ("" + ((sqrt(N))))->toInteger() + 1-1) do ( if (prime[p+1] = 1) then ( for i : Integer.subrange(p * p, N-1)->select( $x | ($x - p * p) mod p = 0 ) do ( prime[i+1] := 0;) ) else skip); operation DivisorCount() pre: true post: true activity: for i : Integer.subrange(1, N-1) do ( for j : Integer.subrange(i, N-1)->select( $x | ($x - i) mod i = 0 ) do ( divi[j+1] := divi[j+1] + 1;)); operation pre() pre: true post: true activity: for i : Integer.subrange(1, N-1) do ( if (prime[divi[i+1]+1] = 1) then ( [i+1]->sum() := i; ) else skip) ; for i : Integer.subrange(1, N-1) do ( [i+1]->sum() := [i+1]->sum() + [i - 1+1]->sum();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import os import sys from collections import defaultdict if os.getenv("LOCAL"): sys.stdin=open("_in.txt","r") sys.setrecursionlimit(2147483647) INF=float("inf") IINF=10**18 MOD=10**9+7 N,K=list(map(int,sys.stdin.readline().split())) NM=[] prev=0 for i in range(1,int(math.sqrt(N))+2): m=int(N//i) NM.append(N-m-prev) prev=N-m cnt=N nums=[] while cnt>=1 : nums.append(cnt) i=int(N//cnt) p=NM[i]if itoReal() ; var IINF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var NM : Sequence := Sequence{} ; var prev : int := 0 ; for i : Integer.subrange(1, ("" + (((N)->sqrt())))->toInteger() + 2-1) do ( var m : int := ("" + ((N div i)))->toInteger() ; execute ((N - m - prev) : NM) ; prev := N - m) ; var cnt : OclAny := N ; var nums : Sequence := Sequence{} ; while cnt >= 1 do ( execute ((cnt) : nums) ; var i : int := ("" + ((N div cnt)))->toInteger() ; var p : OclAny := if (i->compareTo((NM)->size())) < 0 then NM[i+1] else 1 endif ; cnt := cnt - p) ; nums := nums->reverse() ; var dp : OclAny := defaultdict(lambda $$ : OclAny in (defaultdict(OclType["int"]))) ; for n : nums do ( dp[1+1][n+1] := n) ; for k : Integer.subrange(2, K + 1-1) do ( for n : nums do ( i := ("" + ((N div n)))->toInteger() ; p := if (i->compareTo((NM)->size())) < 0 then NM[i+1] else 1 endif ; var ret : int := dp[k - 1+1][i+1] * p mod MOD ; var cum : OclAny := dp[k+1][n - p+1] ; dp[k+1][n+1] := (cum + ret) mod MOD)) ; var ans : OclAny := dp[K+1][N+1] ; execute (ans mod MOD)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def PowerOfTwo(x,n): x.sort() res=[] for i in range(n): for j in range(1,31): lx=x[i]-(1<union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 7 })))) ; n := (a)->size() ; PowerOfTwo(a, n) ) else skip; operation PowerOfTwo(x : OclAny, n : OclAny) pre: true post: true activity: x := x->sort() ; var res : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(1, 31-1) do ( var lx : double := x[i+1] - (1 * (2->pow(j))) ; var rx : OclAny := x[i+1] + (1 * (2->pow(j))) ; if (x)->includes(lx) then ( var isl : boolean := true ) else ( isl := false ) ; if (x)->includes(rx) then ( var isr : boolean := true ) else ( isr := false ) ; if (isl & isr & (res)->size() < 3) then ( res := Sequence{lx}->union(Sequence{x[i+1]}->union(Sequence{ rx })) ) else skip ; if (isl & (res)->size() < 2) then ( res := Sequence{lx}->union(Sequence{ x[i+1] }) ) else skip ; if (isr & (res)->size() < 2) then ( res := Sequence{x[i+1]}->union(Sequence{ rx }) ) else skip)) ; if (not((res)->size())) then ( execute (-1)->display() ; return ) else skip ; for it : res do ( execute (it)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dp=[0]*1024 ; def get_binary(u): ans=0 ; while(u): rem=u % 10 ; ans |=(1<union(Sequence{132}->union(Sequence{4}->union(Sequence{45}->union(Sequence{12}->union(Sequence{ 223 }))))); ; n := (array)->size(); ; execute (solve(array, n))->display(); ) else skip; operation get_binary(u : OclAny) pre: true post: true activity: var ans : int := 0; ; while (u) do ( var rem : int := u mod 10; ; ans := ans or (1 * (2->pow(rem))); ; u := u div 10;) ; return ans;; operation recur(u : OclAny, array : OclAny, n : OclAny) pre: true post: true activity: if (u = 0) then ( return 0; ) else skip ; if (dp[u+1] /= -1) then ( return dp[u+1]; ) else skip ; var temp : int := 0; ; for i : Integer.subrange(0, n-1) do ( var mask : OclAny := get_binary(array[i+1]); ; if ((MathLib.bitwiseOr(mask, u)) = u) then ( dp[u+1] := Set{Set{0, dp[MathLib.bitwiseXor(u, mask)+1]}->max() + array[i+1], dp[u+1]}->max(); ) else skip) ; return dp[u+1];; operation solve(array : OclAny, n : OclAny) pre: true post: true activity: var i : int := 0 ; while ((i->compareTo((1 * (2->pow(10))))) < 0) do ( dp[i+1] := -1; ; i := i + 1) ; ans := 0; ; i := 0 ; while ((i->compareTo((1 * (2->pow(10))))) < 0) do ( ans := Set{ans, recur(i, array, n)}->max(); ; i := i + 1) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMaxOddSubarraySum(arr,n): min_odd=+2147483647 isOdd=False sum=0 for i in range(n): if(arr[i]>0): sum=sum+arr[i] if(arr[i]% 2!=0): isOdd=True if(min_odd>abs(arr[i])): min_odd=abs(arr[i]) if(isOdd==False): return-1 if(sum % 2==0): sum=sum-m return sum arr=[2,-3,5,-1,4] n=len(arr) print(findMaxOddSubarraySum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{-3}->union(Sequence{5}->union(Sequence{-1}->union(Sequence{ 4 })))) ; n := (arr)->size() ; execute (findMaxOddSubarraySum(arr, n))->display(); operation findMaxOddSubarraySum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var min_odd : int := 2147483647 ; var isOdd : boolean := false ; var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] > 0) then ( sum := sum + arr[i+1] ) else skip ; if (arr[i+1] mod 2 /= 0) then ( isOdd := true ; if ((min_odd->compareTo((arr[i+1])->abs())) > 0) then ( min_odd := (arr[i+1])->abs() ) else skip ) else skip) ; if (isOdd = false) then ( return -1 ) else skip ; if (sum mod 2 = 0) then ( sum := sum - m ) else skip ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) lis=[] for i in range(n): l,r=map(int,input().split()) lis.append((l,r)) lis.sort(key=lambda x : x[1]-x[0]) number=set() for x,y in lis : for num in range(x,y+1): if num not in number : number.add(num) break print(x,y,num) print() for _ in range(int(input())): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve()); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lis : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{l, r}) : lis)) ; lis := lis->sort() ; var number : Set := Set{}->union(()) ; for _tuple : lis do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); for num : Integer.subrange(x, y + 1-1) do ( if (number)->excludes(num) then ( execute ((num) : number) ; break ) else skip) ; execute (x)->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(0,t): n=int(input()) dict1={} for i in range(0,n): inputs=[int(num)for num in input().split()] l=inputs[0] r=inputs[1] if(l not in dict1): dict1[l]=[] dict1[l].append(r) for key in dict1 : dict1[key].sort() for i in range(len(dict1[key])-1,0,-1): print(f"{key}{(dict1[key])[i]}{(dict1[key])[i-1]+1}") print(f"{key}{(dict1[key])[0]}{key}") print("") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var dict1 : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var inputs : Sequence := input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var l : OclAny := inputs->first() ; var r : OclAny := inputs[1+1] ; if ((dict1)->excludes(l)) then ( dict1[l+1] := Sequence{} ) else skip ; (expr (atom (name dict1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name l)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name r)))))))) ))))) ; for key : dict1 do ((expr (atom (name dict1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name key)))))))) ])) (trailer . (name sort) (arguments ( )))) ; for i : Integer.subrange(0 + 1, (dict1[key+1])->size() - 1)->reverse() do ( execute (StringLib.formattedString("{key}{(dict1[key])[i]}{(dict1[key])[i-1]+1}"))->display()) ; execute (StringLib.formattedString("{key}{(dict1[key])[0]}{key}"))->display()) ; execute ("")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): pass t=int(input()) for i in range(t): n=int(input()) a=[] for i in range(n): l,r=map(int,input().split()) a.append([r-l,l,r]) a.sort() d={} for i in a : for j in range(i[1],i[2]+1): if j not in d : d[j]=1 print(i[1],i[2],j) print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{r - l}->union(Sequence{l}->union(Sequence{ r }))) : a)) ; a := a->sort() ; var d : OclAny := Set{} ; for i : a do ( for j : Integer.subrange(i[1+1], i[2+1] + 1-1) do ( if (d)->excludes(j) then ( d[j+1] := 1 ; execute (i[1+1])->display() ) else skip)) ; execute (->display()); operation solve() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def print(*args,end='\n',sep=' ')->None : sys.stdout.write(sep.join(map(str,args))+end) def Solve(): l1=list(map(int,input().split())) l2=list(map(int,input().split())) l3=list(map(int,input().split())) x,y,z=sum(l1),sum(l2),sum(l3) l=0 ; r=10**5 ; ans=0 while l<=r : mid=(l+r)//2 if x+mid-y<=0 or x+mid-z<=0 or mid+x+mid-y+x+mid-z (test (logical_test (comparison (expr (atom None))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name sep)) (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name args)))))))) ))))))))) )))) + (expr (atom (name end))))))))) )))))))))))))) operation Solve() pre: true post: true activity: var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l3 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := Sequence{(l1)->sum(),(l2)->sum(),(l3)->sum()} ; var l : int := 0; var r : double := (10)->pow(5); var ans : int := 0 ; while (l->compareTo(r)) <= 0 do ( var mid : int := (l + r) div 2 ; if x + mid - y <= 0 or x + mid - z <= 0 or (mid + x + mid - y + x + mid - z->compareTo(x + mid)) < 0 then ( l := mid + 1 ) else ( r := mid - 1 ) ; if mid + x + mid - y + x + mid - z = x + mid & 1 <= mid & (mid <= (10)->pow(5)) then ( ans := mid; break ) else skip) ; l1->first() := ans ; l2[1+1] := x + ans - y ; l3[2+1] := x + ans - z ; execute ((argument * (test (logical_test (comparison (expr (atom (name l1))))))))->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name l2))))))))->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name l3))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (num,a)=map(int,input().split()) for i in range(a): if num % 10==0 : num=int(num/10) else : num=num-1 print(num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{num, a} : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, a-1) do ( if num mod 10 = 0 then ( var num : int := ("" + ((num / 10)))->toInteger() ) else ( num := num - 1 )) ; execute (num)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) while not(b==0): if a % 10==0 : a=a//10 else : a=a-1 b-=1 print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; while not((b = 0)) do ( if a mod 10 = 0 then ( var a : int := a div 10 ) else ( a := a - 1 ) ; b := b - 1) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inp=input().split() n=int(inp[0]) k=int(inp[1]) for i in range(k): if n % 10!=0 : n-=1 else : n//=10 print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inp : OclAny := input().split() ; var n : int := ("" + ((inp->first())))->toInteger() ; var k : int := ("" + ((inp[1+1])))->toInteger() ; for i : Integer.subrange(0, k-1) do ( if n mod 10 /= 0 then ( n := n - 1 ) else ( n := n div 10 )) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : col,row=map(int,input().split()) if col==0 : break else : robot=[1,1] direction="up" while True : str=input() if str=="STOP" : print(robot[0],robot[1]) break elif str=="LEFT" : if direction=="up" : direction="left" elif direction=="left" : direction="down" elif direction=="down" : direction="right" else : direction="up" elif str=="RIGHT" : if direction=="up" : direction="right" elif direction=="left" : direction="up" elif direction=="down" : direction="left" else : direction="down" else : di,step=str.split() step=int(step) if direction=="up" : if di=="FORWARD" : robot[1]=min(robot[1]+step,row) else : robot[1]=max(robot[1]-step,1) elif direction=="left" : if di=="FORWARD" : robot[0]=max(robot[0]-step,1) else : robot[0]=min(robot[0]+step,col) elif direction=="down" : if di=="FORWARD" : robot[1]=max(robot[1]-step,1) else : robot[1]=min(robot[1]+step,row) else : if di=="FORWARD" : robot[0]=min(robot[0]+step,col) else : robot[0]=max(robot[0]-step,1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var col : OclAny := null; var row : OclAny := null; Sequence{col,row} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if col = 0 then ( break ) else ( var robot : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var direction : String := "up" ; while true do ( var OclType["String"] : String := (OclFile["System.in"]).readLine() ; if OclType["String"] = "STOP" then ( execute (robot->first())->display() ; break ) else (if OclType["String"] = "LEFT" then ( if direction = "up" then ( direction := "left" ) else (if direction = "left" then ( direction := "down" ) else (if direction = "down" then ( direction := "right" ) else ( direction := "up" ) ) ) ) else (if OclType["String"] = "RIGHT" then ( if direction = "up" then ( direction := "right" ) else (if direction = "left" then ( direction := "up" ) else (if direction = "down" then ( direction := "left" ) else ( direction := "down" ) ) ) ) else ( var di : OclAny := null; var step : OclAny := null; Sequence{di,step} := ("" + (.split())) ; var step : int := ("" + ((step)))->toInteger() ; if direction = "up" then ( if di = "FORWARD" then ( robot[1+1] := Set{robot[1+1] + step, row}->min() ) else ( robot[1+1] := Set{robot[1+1] - step, 1}->max() ) ) else (if direction = "left" then ( if di = "FORWARD" then ( robot->first() := Set{robot->first() - step, 1}->max() ) else ( robot->first() := Set{robot->first() + step, col}->min() ) ) else (if direction = "down" then ( if di = "FORWARD" then ( robot[1+1] := Set{robot[1+1] - step, 1}->max() ) else ( robot[1+1] := Set{robot[1+1] + step, row}->min() ) ) else ( if di = "FORWARD" then ( robot->first() := Set{robot->first() + step, col}->min() ) else ( robot->first() := Set{robot->first() - step, 1}->max() ) ) ) ) ) ) ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) for i in range(k): if str(n)[-1]=='0' : n//=10 else : n-=1 print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, k-1) do ( if OclType["String"](n)->last() = '0' then ( n := n div 10 ) else ( n := n - 1 )) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,n=list(map(int,input().split())) for _ in range(n): if a % 10==0 : a=a//10 else : a-=1 print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var n : OclAny := null; Sequence{a,n} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for _anon : Integer.subrange(0, n-1) do ( if a mod 10 = 0 then ( var a : int := a div 10 ) else ( a := a - 1 )) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CalculateMax(arr,n): arr.sort() min_sum=arr[0]+arr[1] max_sum=arr[n-1]+arr[n-2] return abs(max_sum-min_sum) arr=[6,7,1,11] n=len(arr) print(CalculateMax(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{6}->union(Sequence{7}->union(Sequence{1}->union(Sequence{ 11 }))) ; n := (arr)->size() ; execute (CalculateMax(arr, n))->display(); operation CalculateMax(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var min_sum : OclAny := arr->first() + arr[1+1] ; var max_sum : OclAny := arr[n - 1+1] + arr[n - 2+1] ; return (max_sum - min_sum)->abs(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=map(int,input().split()) import math print(math.ceil(n/(2*d+1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; execute ((n / (2 * d + 1))->ceil())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,d=map(int,input().split()) d=2*d+1 if n % d==0 : print(n//d) else : print(n//d+1) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : double := 2 * d + 1 ; if n mod d = 0 then ( execute (n div d)->display() ) else ( execute (n div d + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def resolve(): n,d=map(int,input().split()) ans=n//(d*2+1) if n %(d*2+1): ans=ans+1 print(ans) if __name__=="__main__" : resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( resolve() ) else skip; operation resolve() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := n div (d * 2 + 1) ; if n mod (d * 2 + 1) then ( ans := ans + 1 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (N,M)=(int(i)for i in input().split(" ")) print(int((N+M*2)/(1+M*2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{N, M} : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " "))))))) ))))))))} ; execute (("" + (((N + M * 2) / (1 + M * 2))))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=map(int,input().split()) num=[] z=-1000000001 for i in range(n): x=list(map(int,input().split())) a=max(x) if(a>z): z=a row=i+1 column=x.index(a)+1 num.append(x) rows=max(row,n-row+1) columns=max(column,m-column+1) print(rows*columns) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var num : Sequence := Sequence{} ; var z : int := -1000000001 ; for i : Integer.subrange(0, n-1) do ( var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := (x)->max() ; if ((a->compareTo(z)) > 0) then ( z := a ; var row : OclAny := i + 1 ; var column : int := x->indexOf(a) - 1 + 1 ) else skip ; execute ((x) : num)) ; var rows : OclAny := Set{row, n - row + 1}->max() ; var columns : OclAny := Set{column, m - column + 1}->max() ; execute (rows * columns)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- nd=list(map(int,input().split())) ans=nd[0]//(2*nd[1]+1) if nd[0]%(2*nd[1]+1)!=0 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var nd : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := nd->first() div (2 * nd[1+1] + 1) ; if nd->first() mod (2 * nd[1+1] + 1) /= 0 then ( ans := ans + 1 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math PI=3.1415926535897932384626433832795 M=0.01745329251994329576923690768489 EPS=1e-8 r,q,f=0,90*M,0 while True : d,a=list(map(int,input().split(','))) if d==0 and a==0 : break r2=math.sqrt(r*r+d*d-2*r*d*math.cos(PI-math.fabs(f))) if math.fabs(r)=0 : q2=q-t f+=a*M-t else : q2=q+t f+=a*M+t r=r2 q=q2 print(int(r*math.cos(q)),int(r*math.sin(q)),sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PI : double := 3.1415926535897932384626433832795 ; var M : double := 0.01745329251994329576923690768489 ; var EPS : double := ("1e-8")->toReal() ; var r : OclAny := null; var q : OclAny := null; var f : OclAny := null; Sequence{r,q,f} := Sequence{0,90 * M,0} ; while true do ( var d : OclAny := null; var a : OclAny := null; Sequence{d,a} := ((input().split(','))->collect( _x | (OclType["int"])->apply(_x) )) ; if d = 0 & a = 0 then ( break ) else skip ; var r2 : double := (r * r + d * d - 2 * r * d * )->sqrt() ; if ((r)->abs()->compareTo(EPS)) < 0 or ((r2)->abs()->compareTo(EPS)) < 0 then ( var q2 : double := q - f ; var f : double := a * M ) else ( var t : double := ((r * r + r2 * r2 - d * d) / (2 * r * r2))->acos(); ; if f >= 0 then ( q2 := q - t ; f := f + a * M - t ) else ( q2 := q + t ; f := f + a * M + t ) ) ; var r : OclAny := r2 ; var q : OclAny := q2) ; execute (("" + ((r * )))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math N,K=map(int,(input().split())) mod=10**9+7 ans_array=[] divide_max=N divide_count=[] for i in range(2,math.floor(math.sqrt(N))+2): divide=math.floor(N/i) ans_array.append(divide_max-divide) divide_count.append(divide_max-divide) divide_max=divide for i in range(divide): ans_array.append(1) ans_array=ans_array[: :-1] ans_length=len(ans_array) ans_acc=[0]*ans_length for k in range(2,K+1): ans_acc[0]=ans_array[0] for i in range(1,ans_length): ans_acc[i]=(ans_acc[i-1]+ans_array[i])% mod for i in range(divide): ans_array[i]=ans_acc[ans_length-i-1] for i in range(divide,ans_length): ans_array[i]=ans_acc[ans_length-i-1]*divide_count[ans_length-1-i]% mod ans_acc[0]=ans_array[0] for i in range(1,ans_length): ans_acc[i]=(ans_acc[i-1]+ans_array[i])% mod print(ans_acc[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := ((input().split()))->collect( _x | (OclType["int"])->apply(_x) ) ; var mod : double := (10)->pow(9) + 7 ; var ans_array : Sequence := Sequence{} ; var divide_max : OclAny := N ; var divide_count : Sequence := Sequence{} ; for i : Integer.subrange(2, ((N)->sqrt())->floor() + 2-1) do ( var divide : double := (N / i)->floor() ; execute ((divide_max - divide) : ans_array) ; execute ((divide_max - divide) : divide_count) ; divide_max := divide) ; for i : Integer.subrange(0, divide-1) do ( execute ((1) : ans_array)) ; ans_array := ans_array(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var ans_length : int := (ans_array)->size() ; var ans_acc : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ans_length) ; for k : Integer.subrange(2, K + 1-1) do ( ans_acc->first() := ans_array->first() ; for i : Integer.subrange(1, ans_length-1) do ( ans_acc[i+1] := (ans_acc[i - 1+1] + ans_array[i+1]) mod mod) ; for i : Integer.subrange(0, divide-1) do ( ans_array[i+1] := ans_acc[ans_length - i - 1+1]) ; for i : Integer.subrange(divide, ans_length-1) do ( ans_array[i+1] := ans_acc[ans_length - i - 1+1] * divide_count[ans_length - 1 - i+1] mod mod)) ; ans_acc->first() := ans_array->first() ; for i : Integer.subrange(1, ans_length-1) do ( ans_acc[i+1] := (ans_acc[i - 1+1] + ans_array[i+1]) mod mod) ; execute (ans_acc->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,cmath,math t=complex(0) a=math.pi/2 for line in sys.stdin : l=list(map(int,line.split(","))) if l==[0,0]: break t+=cmath.rect(l[0],a) a-=l[1]*math.pi/180 print(int(t.real)) print(int(t.imag)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : OclAny := complex(0) ; var a : double := / 2 ; for line : OclFile["System.in"] do ( var l : Sequence := ((line.split(","))->collect( _x | (OclType["int"])->apply(_x) )) ; if l = Sequence{0}->union(Sequence{ 0 }) then ( break ) else skip ; t := t + cmath.rect(l->first(), a) ; a := a - l[1+1] * / 180) ; execute (("" + ((t.real)))->toInteger())->display() ; execute (("" + ((t.imag)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import radians,cos,sin,ceil,floor g=90 x=y=0 while 1 : d,a=map(int,input().split(",")) if d==0 : break t=radians(g) x+=cos(t)*d y+=sin(t)*d g-=a x=floor(x)if x>0 else ceil(x) y=floor(y)if y>0 else ceil(y) print("%d" % x) print("%d" % y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var g : int := 90 ; var x : OclAny := 0; var y : int := 0 ; while 1 do ( var d : OclAny := null; var a : OclAny := null; Sequence{d,a} := (input().split(","))->collect( _x | (OclType["int"])->apply(_x) ) ; if d = 0 then ( break ) else skip ; var t : OclAny := radians(g) ; x := x + cos(t) * d ; y := y + sin(t) * d ; g := g - a) ; x := if x > 0 then floor(x) else ceil(x) endif ; y := if y > 0 then floor(y) else ceil(y) endif ; execute (StringLib.format("%d",x))->display() ; execute (StringLib.format("%d",y))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math x,y,t=0,0,0 for s in sys.stdin : a,b=map(int,s.split(',')) if a==0 and b==0 : break x+=a*math.sin(math.radians(t)) y+=a*math.cos(math.radians(t)) t+=b print(int(x)) print(int(y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var x : OclAny := null; var y : OclAny := null; var t : OclAny := null; Sequence{x,y,t} := Sequence{0,0,0} ; for s : OclFile["System.in"] do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (s.split(','))->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 0 & b = 0 then ( break ) else skip ; x := x + a * ()->sin() ; y := y + a * ; t := t + b) ; execute (("" + ((x)))->toInteger())->display() ; execute (("" + ((y)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import radians,sin,cos,pi def main(): x=0 y=0 a=0 while True : d,_a=map(int,input().split(",")) if(d==_a==0): break x=x+d*cos(radians(a)) y=y+d*sin(radians(a)) a=a+_a print(int(y)) print(int(x)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var x : int := 0 ; var y : int := 0 ; var a : int := 0 ; while true do ( var d : OclAny := null; var _a : OclAny := null; Sequence{d,_a} := (input().split(","))->collect( _x | (OclType["int"])->apply(_x) ) ; if (d = _a & (_a == 0)) then ( break ) else skip ; x := x + d * cos(radians(a)) ; y := y + d * sin(radians(a)) ; a := a + _a) ; execute (("" + ((y)))->toInteger())->display() ; execute (("" + ((x)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=17 seat=[[0 for t in range(27)]for id in range(27)] ans=[0]*105 id=0 Q=[] for i in range(S): seat[i][0]=-1 t=-1 while ans[99]==0 : t+=1 if t % 5==0 and id<=99 : n=5 if(id % 5)==1 else 2 Q.append((id,n,t)) id+=1 for i in range(S): if seat[i][1]==0 : continue seat[i][1]-=1 if seat[i][1]==0 : seat[i][0]=-1 f=len(Q) while f>0 : i,n=Q[0][0],Q[0][1] f=0 ; for j in range(S): g=0 for k in range(n): if seat[j+k][0]>=0 : g=1 break if g : continue ans[i]=t-Q[0][2] del Q[0] f=len(Q) for k in range(n): seat[j+k][0]=i seat[j+k][1]=17*(i & 1)+3*(i % 3)+19 break while 1 : try : n=int(input()) except : break print(ans[n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : int := 17 ; var seat : Sequence := Integer.subrange(0, 27-1)->select(id | true)->collect(id | (Integer.subrange(0, 27-1)->select(t | true)->collect(t | (0)))) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 105) ; var id : int := 0 ; var Q : Sequence := Sequence{} ; for i : Integer.subrange(0, S-1) do ( seat[i+1]->first() := -1) ; var t : int := -1 ; while ans[99+1] = 0 do ( t := t + 1 ; if t mod 5 = 0 & id <= 99 then ( var n : int := if (id mod 5) = 1 then 5 else 2 endif ; execute ((Sequence{id, n, t}) : Q) ; id := id + 1 ) else skip ; for i : Integer.subrange(0, S-1) do ( if seat[i+1][1+1] = 0 then ( continue ) else skip ; seat[i+1][1+1] := seat[i+1][1+1] - 1 ; if seat[i+1][1+1] = 0 then ( seat[i+1]->first() := -1 ) else skip) ; var f : int := (Q)->size() ; while f > 0 do ( var i : OclAny := null; Sequence{i,n} := Sequence{Q->first()->first(),Q->first()[1+1]} ; f := 0; ; for j : Integer.subrange(0, S-1) do ( var g : int := 0 ; for k : Integer.subrange(0, n-1) do ( if seat[j + k+1]->first() >= 0 then ( g := 1 ; break ) else skip) ; if g then ( continue ) else skip ; ans[i+1] := t - Q->first()[2+1] ; execute (Q->first())->isDeleted() ; f := (Q)->size() ; for k : Integer.subrange(0, n-1) do ( seat[j + k+1]->first() := i ; seat[j + k+1][1+1] := 17 * (MathLib.bitwiseAnd(i, 1)) + 3 * (i mod 3) + 19) ; break))) ; while 1 do ( try ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) catch (_e : OclException) do ( break) ; execute (ans[n+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque que=deque() t=0 seat=[0]*17 score=[] while que or t<500 : if t % 5==0 and t<500 : i=t//5 que.append([t,5 if i % 5==1 else 2,17*(i % 2)+3*(i % 3)+19]) for i in range(17): if seat[i]: seat[i]-=1 while que : need_space=que[0][1] for i in range(18-need_space): if not any(seat[i : i+need_space]): for j in range(i,i+need_space): seat[j]=que[0][2] score.append(t-que[0][0]) que.popleft() break else : break t+=1 while True : try : print(score[int(input())]) except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var que : Sequence := () ; var t : int := 0 ; var seat : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 17) ; var score : Sequence := Sequence{} ; while que or t < 500 do ( if t mod 5 = 0 & t < 500 then ( var i : int := t div 5 ; execute ((Sequence{t}->union(Sequence{if i mod 5 = 1 then 5 else 2 endif}->union(Sequence{ 17 * (i mod 2) + 3 * (i mod 3) + 19 }))) : que) ) else skip ; for i : Integer.subrange(0, 17-1) do ( if seat[i+1] then ( seat[i+1] := seat[i+1] - 1 ) else skip) ; while que do ( var need_space : OclAny := que->first()[1+1] ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (number (integer 18)))) - (expr (atom (name need_space))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test not (logical_test (comparison (expr (atom (name any)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name seat)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))) : (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name need_space))))))))) ])))))))) )))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name need_space))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name seat)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name que)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ]))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name score)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name t))) - (expr (atom (name que)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name que)) (trailer . (name popleft) (arguments ( )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt break))))))) ; t := t + 1) ; while true do ( try ( execute (score[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1])->display()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque from heapq import heappush,heappop que=deque() q=[] N=100 for i in range(N): heappush(q,(5*i,0,i)) M=17 S=[-1]*M T=[0]*N while q : t=None while q and(t is None or q[0][0]==t): t,c,i=heappop(q) if c==0 : que.append(i) else : for j in range(M): if S[j]==i : S[j]=-1 while que : i=que[0] m=5 if i % 5==1 else 2 cnt=0 ; j=-1 for k in range(M): if S[k]==-1 : cnt+=1 if cnt==m : j=k-m+1 break else : cnt=0 if j==-1 : break for k in range(m): S[j+k]=i T[i]=t-5*i que.popleft() heappush(q,(t+(17*(i % 2)+3*(i % 3)+19),1,i)) open(1,'w').writelines(["{}\n".format(T[v])for v in map(int,open(0).read().split())]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var que : Sequence := () ; var q : Sequence := Sequence{} ; var N : int := 100 ; for i : Integer.subrange(0, N-1) do ( heappush(q, Sequence{5 * i, 0, i})) ; var M : int := 17 ; var S : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, M) ; var T : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; while q do ( var t : OclAny := null ; while q & (t <>= null or q->first()->first() = t) do ( var c : OclAny := null; var i : OclAny := null; Sequence{t,c,i} := heappop(q) ; if c = 0 then ( execute ((i) : que) ) else ( for j : Integer.subrange(0, M-1) do ( if S[j+1] = i then ( S[j+1] := -1 ) else skip) )) ; while que do ( var i : OclAny := que->first() ; var m : int := if i mod 5 = 1 then 5 else 2 endif ; var cnt : int := 0; var j : int := -1 ; for k : Integer.subrange(0, M-1) do ( if S[k+1] = -1 then ( cnt := cnt + 1 ; if cnt = m then ( j := k - m + 1 ; break ) else skip ) else ( cnt := 0 )) ; if j = -1 then ( break ) else skip ; for k : Integer.subrange(0, m-1) do ( S[j + k+1] := i) ; T[i+1] := t - 5 * i ; que := que->tail() ; heappush(q, Sequence{t + (17 * (i mod 2) + 3 * (i mod 3) + 19), 1, i}))) ; (expr (atom (name open)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom 'w'))))))) ))) (trailer . (name writelines) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom "{}\n") (trailer . (name format) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name T)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])))))))) ))))))) (comp_for for (exprlist (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name open)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))) (trailer . (name read) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))))) ]))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def distSumRec(arr,n,sum,currindex,s): if(currindex>n): return if(currindex==n): s.add(sum) return distSumRec(arr,n,sum+arr[currindex],currindex+1,s) distSumRec(arr,n,sum,currindex+1,s) def printDistSum(arr,n): s=set() distSumRec(arr,n,0,0,s) for i in s : print(i,end=" ") if __name__=='__main__' : arr=[2,3,4,5,6] n=len(arr) printDistSum(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 })))) ; n := (arr)->size() ; printDistSum(arr, n) ) else skip; operation distSumRec(arr : OclAny, n : OclAny, sum : OclAny, currindex : OclAny, s : OclAny) pre: true post: true activity: if ((currindex->compareTo(n)) > 0) then ( return ) else skip ; if (currindex = n) then ( execute ((sum) : s) ; return ) else skip ; distSumRec(arr, n, sum + arr[currindex+1], currindex + 1, s) ; distSumRec(arr, n, sum, currindex + 1, s); operation printDistSum(arr : OclAny, n : OclAny) pre: true post: true activity: s := Set{}->union(()) ; distSumRec(arr, n, 0, 0, s) ; for i : s do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- first_line=input() test_cases=int(first_line) for i in range(test_cases): size_line=input() size=str.split(size_line) size=(int(size[0]),int(size[1])) matrix=[] for x in range(size[0]): line=input() line_int=[int(x)for x in line.split()] matrix.append(line_int) max_val=max([max(x)for x in matrix]) max_pos=() for x in range(size[0]): for y in range(size[1]): if matrix[x][y]==max_val : max_pos=(x,y) result=(max(max_pos[0]+1,size[0]-max_pos[0]),max(max_pos[1]+1,size[1]-max_pos[1])) result=result[0]*result[1] print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var first_line : String := (OclFile["System.in"]).readLine() ; var test_cases : int := ("" + ((first_line)))->toInteger() ; for i : Integer.subrange(0, test_cases-1) do ( var size_line : String := (OclFile["System.in"]).readLine() ; var size : String := ("" + (.split(size_line))) ; size := Sequence{("" + ((size->first())))->toInteger(), ("" + ((size[1+1])))->toInteger()} ; var matrix : Sequence := Sequence{} ; for x : Integer.subrange(0, size->first()-1) do ( var line : String := (OclFile["System.in"]).readLine() ; var line_int : Sequence := line.split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((line_int) : matrix)) ; var max_val : OclAny := (matrix->select(x | true)->collect(x | ((x)->max())))->max() ; var max_pos : OclAny := () ; for x : Integer.subrange(0, size->first()-1) do ( for y : Integer.subrange(0, size[1+1]-1) do ( if matrix[x+1][y+1] = max_val then ( max_pos := Sequence{x, y} ) else skip)) ; var result : OclAny := Sequence{Set{max_pos->first() + 1, size->first() - max_pos->first()}->max(), Set{max_pos[1+1] + 1, size[1+1] - max_pos[1+1]}->max()} ; result := result->first() * result[1+1] ; execute (result)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printSumSeries(N): sum=0 ; for i in range(1,N+1): sum+=1.0/(2*i-1); print(sum); if __name__=="__main__" : N=6 ; printSumSeries(N); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := 6; ; printSumSeries(N); ) else skip; operation printSumSeries(N : OclAny) pre: true post: true activity: var sum : int := 0; ; for i : Integer.subrange(1, N + 1-1) do ( sum := sum + 1.0 / (2 * i - 1);) ; execute (sum)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque,Counter from heapq import heappush,heappop,heapify import math from bisect import bisect_left,bisect_right import random from itertools import permutations,accumulate,combinations import sys import string INF=float('inf') def LI(): return list(map(int,sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return sys.stdin.readline().strip() def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] def SRL(n): return[list(S())for i in range(n)] def MSRL(n): return[[int(j)for j in list(S())]for i in range(n)] mod=10**9+7 n,k=LI() sqt=int(n**0.5) dp_mul_num=[1]*sqt+[n//i-n//(i+1)for i in range(1,n//sqt)][: :-1] group_num=len(dp_mul_num) dp=[[0]*group_num for _ in range(k)] dp[0]=dp_mul_num for i in range(k-1): ret=0 for j in range(group_num): ret=(ret+dp[i][j])% mod dp[i+1][group_num-j-1]=ret*dp_mul_num[group_num-j-1]% mod print(sum(dp[-1])% mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var INF : double := ("" + (('inf')))->toReal() ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; var k : OclAny := null; Sequence{n,k} := LI() ; var sqt : int := ("" + (((n)->pow(0.5))))->toInteger() ; var dp_mul_num : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, sqt)->union(Integer.subrange(1, n div sqt-1)->select(i | true)->collect(i | (n div i - n div (i + 1)))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ; var group_num : int := (dp_mul_num)->size() ; var dp : Sequence := Integer.subrange(0, k-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, group_num))) ; dp->first() := dp_mul_num ; for i : Integer.subrange(0, k - 1-1) do ( var ret : int := 0 ; for j : Integer.subrange(0, group_num-1) do ( ret := (ret + dp[i+1][j+1]) mod mod ; dp[i + 1+1][group_num - j - 1+1] := ret * dp_mul_num[group_num - j - 1+1] mod mod)) ; execute ((dp->last())->sum() mod mod)->display(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation S() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation SRL(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | ((S()))); operation MSRL(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | ((S())->select(j | true)->collect(j | (("" + ((j)))->toInteger())))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CountPair(arr,n): result=0 ; for i in range(0,n): j=i+1 while(jj*arr[j]): result=result+1 j=j+1 return result ; arr=[5,0,10,2,4,1,6] n=len(arr) print("Count of Pairs : ",CountPair(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{5}->union(Sequence{0}->union(Sequence{10}->union(Sequence{2}->union(Sequence{4}->union(Sequence{1}->union(Sequence{ 6 })))))) ; n := (arr)->size() ; execute ("Count of Pairs : ")->display(); operation CountPair(arr : OclAny, n : OclAny) pre: true post: true activity: var result : int := 0; ; for i : Integer.subrange(0, n-1) do ( var j : OclAny := i + 1 ; while ((j->compareTo(n)) < 0) do ( if ((i * arr[i+1]->compareTo(j * arr[j+1])) > 0) then ( result := result + 1 ) else skip ; j := j + 1)) ; return result;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def fibonacci(n): for i in range(n): fib=((pow((1+math.sqrt(5)),i)-pow((1-math.sqrt(5)),i))/(pow(2,i)*math.sqrt(5))); print(int(fib),end=" "); n=8 ; fibonacci(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 8; ; fibonacci(n);; operation fibonacci(n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( var fib : double := ((((1 + (5)->sqrt()))->pow(i) - ((1 - (5)->sqrt()))->pow(i)) / ((2)->pow(i) * (5)->sqrt())); ; execute (("" + ((fib)))->toInteger())->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def items(n,a): a.sort() z=a[n-1] x=1 s=0 for i in range(0,n-1): s+=a[i] if(s<=z): x+=1 else : break return x n=5 a=[5,3,1,5,6] print(items(n,a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; a := Sequence{5}->union(Sequence{3}->union(Sequence{1}->union(Sequence{5}->union(Sequence{ 6 })))) ; execute (items(n, a))->display(); operation items(n : OclAny, a : OclAny) : OclAny pre: true post: true activity: a := a->sort() ; var z : OclAny := a[n - 1+1] ; var x : int := 1 ; var s : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( s := s + a[i+1] ; if ((s->compareTo(z)) <= 0) then ( x := x + 1 ) else ( break )) ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxOR(arr,n,k,x): preSum=[0]*(n+1) suffSum=[0]*(n+1) pow=1 for i in range(0,k): pow*=x preSum[0]=0 for i in range(0,n): preSum[i+1]=preSum[i]| arr[i] suffSum[n]=0 for i in range(n-1,-1,-1): suffSum[i]=suffSum[i+1]| arr[i] res=0 for i in range(0,n): res=max(res,preSum[i]|(arr[i]*pow)| suffSum[i+1]) return res arr=[1,2,4,8] n=len(arr) k=2 x=3 print(maxOR(arr,n,k,x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 8 }))) ; n := (arr)->size() ; k := 2 ; x := 3 ; execute (maxOR(arr, n, k, x))->display(); operation maxOR(arr : OclAny, n : OclAny, k : OclAny, x : OclAny) : OclAny pre: true post: true activity: var preSum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var suffSum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var pow : int := 1 ; for i : Integer.subrange(0, k-1) do ( pow := pow * x) ; preSum->first() := 0 ; for i : Integer.subrange(0, n-1) do ( preSum[i + 1+1] := MathLib.bitwiseOr(preSum[i+1], arr[i+1])) ; suffSum[n+1] := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( suffSum[i+1] := MathLib.bitwiseOr(suffSum[i + 1+1], arr[i+1])) ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( res := Set{res, MathLib.bitwiseOr(MathLib.bitwiseOr(preSum[i+1], (arr[i+1] * pow)), suffSum[i + 1+1])}->max()) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : n=int(input()) except EOFError : break ret=0 for a in range(10): for b in range(10): for c in range(10): for d in range(10): if a+b+c+d==n : ret+=1 print(ret) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))) ; var ret : int := 0 ; for a : Integer.subrange(0, 10-1) do ( for b : Integer.subrange(0, 10-1) do ( for c : Integer.subrange(0, 10-1) do ( for d : Integer.subrange(0, 10-1) do ( if a + b + c + d = n then ( ret := ret + 1 ) else skip)))) ; execute (ret)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- answermap=[0]*51 answermap[0]=1 answermap[1]=4 answermap[2]=10 answermap[3]=20 answermap[4]=35 answermap[5]=56 answermap[6]=84 answermap[7]=120 answermap[8]=165 answermap[9]=220 answermap[10]=282 answermap[11]=348 answermap[12]=415 answermap[13]=480 answermap[14]=540 answermap[15]=592 answermap[16]=633 answermap[17]=660 answermap[18]=670 answermap[19]=660 answermap[20]=633 answermap[21]=592 answermap[22]=540 answermap[23]=480 answermap[24]=415 answermap[25]=348 answermap[26]=282 answermap[27]=220 answermap[28]=165 answermap[29]=120 answermap[30]=84 answermap[31]=56 answermap[32]=35 answermap[33]=20 answermap[34]=10 answermap[35]=4 answermap[36]=1 answermap[37]=0 answermap[38]=0 answermap[39]=0 answermap[40]=0 answermap[41]=0 answermap[42]=0 answermap[43]=0 answermap[44]=0 answermap[45]=0 answermap[46]=0 answermap[47]=0 answermap[48]=0 answermap[49]=0 answermap[50]=0 inputs=[] while True : try : inputs.append(int(input())) except EOFError : break for i in inputs : print(answermap[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var answermap : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 51) ; answermap->first() := 1 ; answermap[1+1] := 4 ; answermap[2+1] := 10 ; answermap[3+1] := 20 ; answermap[4+1] := 35 ; answermap[5+1] := 56 ; answermap[6+1] := 84 ; answermap[7+1] := 120 ; answermap[8+1] := 165 ; answermap[9+1] := 220 ; answermap[10+1] := 282 ; answermap[11+1] := 348 ; answermap[12+1] := 415 ; answermap[13+1] := 480 ; answermap[14+1] := 540 ; answermap[15+1] := 592 ; answermap[16+1] := 633 ; answermap[17+1] := 660 ; answermap[18+1] := 670 ; answermap[19+1] := 660 ; answermap[20+1] := 633 ; answermap[21+1] := 592 ; answermap[22+1] := 540 ; answermap[23+1] := 480 ; answermap[24+1] := 415 ; answermap[25+1] := 348 ; answermap[26+1] := 282 ; answermap[27+1] := 220 ; answermap[28+1] := 165 ; answermap[29+1] := 120 ; answermap[30+1] := 84 ; answermap[31+1] := 56 ; answermap[32+1] := 35 ; answermap[33+1] := 20 ; answermap[34+1] := 10 ; answermap[35+1] := 4 ; answermap[36+1] := 1 ; answermap[37+1] := 0 ; answermap[38+1] := 0 ; answermap[39+1] := 0 ; answermap[40+1] := 0 ; answermap[41+1] := 0 ; answermap[42+1] := 0 ; answermap[43+1] := 0 ; answermap[44+1] := 0 ; answermap[45+1] := 0 ; answermap[46+1] := 0 ; answermap[47+1] := 0 ; answermap[48+1] := 0 ; answermap[49+1] := 0 ; answermap[50+1] := 0 ; var inputs : Sequence := Sequence{} ; while true do ( try ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : inputs)) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))) ; for i : inputs do ( execute (answermap[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys d=[sum((10-abs(9-i))*(10-abs(9+i-j))for i in range(j+1))for j in range(19)[: :-1]]+[0]*14 [print(d[abs(18-int(e))])for e in sys.stdin] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var d : Sequence := range(19)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->select(j | true)->collect(j | (((argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 10)))) - (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (number (integer 9)))) - (expr (atom (name i))))))))) ))))))))) ))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 10)))) - (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (number (integer 9)))) + (expr (atom (name i)))) - (expr (atom (name j))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 1)))))))))) )))))))))->sum()))->union(MatrixLib.elementwiseMult(Sequence{ 0 }, 14)) ; ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from itertools import product sum=[0]*51 for i,j,k,l in product(range(10),repeat=4): sum[i+j+k+l]+=1 for i in sys.stdin : print(sum[int(i)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var sum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 51) ; for _tuple : product(Integer.subrange(0, 10-1), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (number (integer 4))))))))) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var l : OclAny := _tuple->at(_indx); [i + j + k + l+1]->sum() := [i + j + k + l+1]->sum() + 1) ; for i : OclFile["System.in"] do ( execute ([("" + ((i)))->toInteger()+1]->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def kai(num): x=0 for i in range(10000): mk=str(i).zfill(4) if int(mk[0])+int(mk[1])+int(mk[2])+int(mk[3])==num : x+=1 return x def main(): while True : try : num=int(input()) except : return else : print(kai(num)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation kai(num : OclAny) : OclAny pre: true post: true activity: var x : int := 0 ; for i : Integer.subrange(0, 10000-1) do ( var mk : OclAny := OclType["String"](i).zfill(4) ; if ("" + ((mk->first())))->toInteger() + ("" + ((mk[1+1])))->toInteger() + ("" + ((mk[2+1])))->toInteger() + ("" + ((mk[3+1])))->toInteger() = num then ( x := x + 1 ) else skip) ; return x; operation main() pre: true post: true activity: while true do ( try ( num := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) catch (_e : OclException) do ( return) else ( execute (kai(num))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t!=0 : t-=1 n,m=map(int,input().split()) v=[] for i in range(n): a=list(map(int,input().split())) for j in a : v.append(j) idx=0 for i in range(n*m): if v[i]>v[idx]: idx=i x=idx//m y=idx % m print(max(x+1,n-x)*max(y+1,m-y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t /= 0 do ( t := t - 1 ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var v : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : a do ( execute ((j) : v))) ; var idx : int := 0 ; for i : Integer.subrange(0, n * m-1) do ( if (v[i+1]->compareTo(v[idx+1])) > 0 then ( idx := i ) else skip) ; var x : int := idx div m ; var y : int := idx mod m ; execute (Set{x + 1, n - x}->max() * Set{y + 1, m - y}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import* from itertools import* from collections import* from functools import* from operator import* try : from math import gcd except Exception : from fractions import gcd MOD=1000000007 def solve(N : int,K : int): ns=[] for i in range(1,N+1): if NcompareTo(i * i)) < 0 then ( break ) else skip ; execute ((i) : ns) ; execute ((N div i) : ns)) ; ns := (Set{}->union((ns)))->sort() ; var m : Map := Integer.subrange(1, (ns)->size())->collect( _indx | Sequence{_indx-1, (ns)->at(_indx)} )->select(_tuple | true)->collect(_tuple | Map{n |-> i})->unionAll() ; var l : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (ns)->size()) ; for _tuple : Integer.subrange(1, (Integer.subrange(1, ns->size())->collect( _indx | Sequence{ns->at(_indx), ns->tail()->at(_indx)} ))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(1, ns->size())->collect( _indx | Sequence{ns->at(_indx), ns->tail()->at(_indx)} ))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{s, b} : OclAny := _tuple->at(_indx); l[i+1] := (N div s) - (N div b)) ; var dp : Sequence := Integer.subrange(0, K + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (ns)->size()))) ; dp->first()[m[N+1]+1] := 1 ; for i : Integer.subrange(0, K-1) do ( for j : Integer.subrange(-1 + 1, (ns)->size() - 2)->reverse() do ( dp[i+1][j+1] := dp[i+1][j+1] + dp[i+1][j + 1+1]) ; for _tuple : Integer.subrange(1, (ns)->size())->collect( _indx | Sequence{_indx-1, (ns)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var nn : OclAny := _tuple->at(_indx); var nj : OclAny := m[N div nn+1] ; dp[i + 1+1][j+1] := (dp[i + 1+1][j+1] + dp[i+1][nj+1] * l[j+1]) mod MOD)) ; return (dp->last())->sum() mod MOD; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var N : int := ("" + (((tokens).next())))->toInteger() ; var K : int := ("" + (((tokens).next())))->toInteger() ; var result : OclAny := solve(N, K) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def heightCalculate(H,n,m): N=n*1.0 M=m*1.0 h=H*sqrt(N/(N+M)) return h if __name__=='__main__' : H=10 n=3 m=4 print("{0:.6}".format(heightCalculate(H,n,m))); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( H := 10 ; n := 3 ; m := 4 ; execute (StringLib.interpolateStrings("{0:.6}", Sequence{heightCalculate(H, n, m)}))->display(); ) else skip; operation heightCalculate(H : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var N : double := n * 1.0 ; var M : double := m * 1.0 ; var h : double := H * sqrt(N / (N + M)) ; return h; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- FNAME="B-small-attempt0.in" PRIMDIV=2,3,5,7 class Case(object): def __init__(self,num): self.num=num def isugly(n): for i in PRIMDIV : if n % i==0 : return True return False def getvals(s): vals=[] for i in xrange(len(s)): v=int(s[: i+1]) if not s[i+1 :]: prevvals=[0] vals.append(v) else : prevvals=getvals(s[i+1 :]) vals.extend([v+val for val in prevvals]) vals.extend([v-val for val in prevvals]) return vals def getnugly(s): return len([val for val in getvals(s)if isugly(val)]) def parse(lines): cases=[] i=1 while iexists( _x | result = _x ); attribute num : OclAny := num; operation initialise(num : OclAny) : pre: true post: true activity: self.num := num; return self; } class FromPython { operation initialise() pre: true post: true activity: var FNAME : String := "B-small-attempt0.in" ; var PRIMDIV : OclAny := 2,3,5,7 ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( lines := file(FNAME).readAll().splitlines() ; var answers : Sequence := parse(lines)->select(case | true)->collect(case | (getnugly(case.num))) ; var outlines : Sequence := Integer.subrange(1, (answers)->size())->collect( _indx | Sequence{_indx-1, (answers)->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let answer : OclAny = _tuple->at(2) in (StringLib.format("Case #%d: %d\n",Sequence{i + 1, answer}))) ; (expr (atom (name file)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name FNAME))) + (expr (atom ".out"))))))) , (argument (test (logical_test (comparison (expr (atom "w"))))))) ))) (trailer . (name writelines) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name outlines)))))))) )))) ) else skip; operation isugly(n : OclAny) : OclAny pre: true post: true activity: for i : PRIMDIV do ( if n mod i = 0 then ( return true ) else skip) ; return false; operation getvals(s : OclAny) : OclAny pre: true post: true activity: var vals : Sequence := Sequence{} ; for i : xrange((s)->size()) do ( var v : int := ("" + ((s.subrange(1,i + 1))))->toInteger() ; if not(s.subrange(i + 1+1)) then ( var prevvals : Sequence := Sequence{ 0 } ; execute ((v) : vals) ) else ( prevvals := getvals(s.subrange(i + 1+1)) ; vals := vals->union(prevvals->select(val | true)->collect(val | (v + val))) ; vals := vals->union(prevvals->select(val | true)->collect(val | (v - val))) )) ; return vals; operation getnugly(s : OclAny) : OclAny pre: true post: true activity: return (getvals(s)->select(val | isugly(val))->collect(val | (val)))->size(); operation parse(lines : OclAny) : OclAny pre: true post: true activity: var cases : Sequence := Sequence{} ; var i : int := 1 ; while (i->compareTo((lines)->size())) < 0 do ( execute (((Case.newCase()).initialise(lines[i+1])) : cases) ; i := i + 1) ; return cases; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): f=open('B-large.in') g=open('B.out','w') N=int(f.readline()) for i in range(N): s=f.readline().strip() D=len(s) m=[[]*210]*D def go(j): rn=[0]*210 if j==D : return rn if m[j]!=[]: return m[j] t=int(s[j : D]) rn[t % 210]+=1 for k in xrange(j+1,D): t=int(s[j : k]) rs=go(k) for ir in xrange(210): rn[(t+ir)% 210]+=rs[ir] rn[(210+t-ir)% 210]+=rs[ir] m[j]=rn return rn rrr=go(0) ret=0 for j in xrange(210): if j % 2==0 or j % 3==0 or j % 5==0 or j % 7==0 : ret+=rrr[j] g.write('Case #%d: %d\n' %(i+1,ret)) g.close() solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('B-large.in')) ; var g : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('B.out')) ; var N : int := ("" + ((f.readLine())))->toInteger() ; for i : Integer.subrange(0, N-1) do ( var s : OclAny := f.readLine()->trim() ; var D : int := (s)->size() ; var m : Sequence := MatrixLib.elementwiseMult(Sequence{ MatrixLib.elementwiseMult(Sequence{}, 210) }, D) ; skip ; var rrr : OclAny := go(0) ; var ret : int := 0 ; for j : xrange(210) do ( if j mod 2 = 0 or j mod 3 = 0 or j mod 5 = 0 or j mod 7 = 0 then ( ret := ret + rrr[j+1] ) else skip) ; g.write(StringLib.format('Case #%d: %d ',Sequence{i + 1, ret}))) ; g.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math def isugly(n): for p in[2,3,5,7]: if n % p==0 : return True return False output=[] f=open(sys.argv[1]) try : for N in range(1,int(f.next())+1): digits=list(f.next().strip()) def foo(n): if len(n)==1 : return 1 if isugly(n[0])else 0 a=[n[0]+n[1]]+n[2 :] b=[n[0]-n[1]]+n[2 :] return foo(a)+foo(b) def bar(done,todo): if len(todo)==1 : return[map(int,done+[todo[0]])] a=bar(done+todo[: 1],todo[1 :]) b=bar(list(done),[todo[0]+todo[1]]+todo[2 :]) return a+b output.append(sum(map(foo,bar([],digits)))) finally : f.close() f=open(sys.argv[2],'w') try : f.write('\n'.join('Case #%s: %s' %(i+1,n)for i,n in enumerate(output))) finally : f.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var output : Sequence := Sequence{} ; var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) ; try ( for N : Integer.subrange(1, ("" + ((f.next())))->toInteger() + 1-1) do ( var digits : Sequence := (f.next()->trim()) ; skip ; skip ; execute ((((bar(Sequence{}, digits))->collect( _x | (foo)->apply(_x) ))->sum()) : output))) finally ( f.closeFile()) ; f := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))) ; try ( f.write(StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (expr (atom 'Case #%s: %s')) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (atom (name n))))))) ))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name output)))))))) ))))))))), ' '))) finally ( f.closeFile()); operation isugly(n : OclAny) : OclAny pre: true post: true activity: for p : Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 7 }))) do ( if n mod p = 0 then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) l=[] r=[] lr,rl=0,0 l1,l2=0,0 for _ in range(n): a,b=map(int,input().split()) l.append(a) r.append(b) if a-b>lr : lr=a-b l1=_ if a-btoInteger() ; var l : Sequence := Sequence{} ; var r : Sequence := Sequence{} ; var lr : OclAny := null; var rl : OclAny := null; Sequence{lr,rl} := Sequence{0,0} ; var l1 : OclAny := null; var l2 : OclAny := null; Sequence{l1,l2} := Sequence{0,0} ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a) : l) ; execute ((b) : r) ; if (a - b->compareTo(lr)) > 0 then ( var lr : double := a - b ; var l1 : OclAny := _anon ) else skip ; if (a - b->compareTo(rl)) < 0 then ( var rl : double := a - b ; var l2 : OclAny := _anon ) else skip) ; var x : double := (l)->sum() - (r)->sum() ; var c : OclAny := Set{(x - lr * 2)->abs(), (x)->abs(), (x - rl * 2)->abs()}->max() ; if (x)->abs() = c then ( execute (0)->display() ) else (if (x - lr * 2)->abs() = c then ( execute (l1 + 1)->display() ) else ( execute (l2 + 1)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(l): ab=lambda x : x if x>0 else-x k=len(l) dl=[c[0]-c[1]for c in l] ss=sum(dl) mb=ab(ss) mi=0 for i in range(k): b=ab(ss-(dl[i]<<1)) if b>mb : mi=i+1 mb=b return mi k=int(input()) l=[list(map(int,input().split()))for _ in range(k)] print(f(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; k := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; l := Integer.subrange(0, k-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; execute (f(l))->display(); operation f(l : OclAny) : OclAny pre: true post: true activity: var ab : Function := lambda x : OclAny in (if x > 0 then x else -x endif) ; var k : int := (l)->size() ; var dl : Sequence := l->select(c | true)->collect(c | (c->first() - c[1+1])) ; var ss : OclAny := (dl)->sum() ; var mb : OclAny := ab->apply(ss) ; var mi : int := 0 ; for i : Integer.subrange(0, k-1) do ( var b : OclAny := ab->apply(ss - (dl[i+1] * (2->pow(1)))) ; if (b->compareTo(mb)) > 0 then ( mi := i + 1 ; mb := b ) else skip) ; return mi; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) res=[0] for i in range(n): l,r=map(int,input().split()) res.append(l-r) ma=max(res) mi=min(res) s=sum(res) if ma+mitoInteger() ; var res : Sequence := Sequence{ 0 } ; for i : Integer.subrange(0, n-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((l - r) : res)) ; var ma : OclAny := (res)->max() ; var mi : OclAny := (res)->min() ; var s : OclAny := (res)->sum() ; if (ma + mi->compareTo(s)) < 0 then ( execute (res->indexOf(mi) - 1)->display() ) else ( execute (res->indexOf(ma) - 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys ; input=sys.stdin.readline inf=int(1e10) n=int(input()) a=[] b=[] for i in range(n): x,y=map(int,input().split()) a.append(x); b.append(y) d=[0]*n for i in range(n): d[i]=a[i]-b[i] mx,mn,i1,i2=-inf,inf,0,0 for i in range(n): if d[i]mx : mx=d[i] i1=i s=sum(a)-sum(b) if abs(s)>abs(s-2*mx)and abs(s)>abs(s-2*mn): print(0) elif abs(s-2*mx)>abs(s-2*mn): print(i1+1) else : print(i2+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; var input : OclAny := (OclFile["System.in"]).readline ; var Math_PINFINITY : int := ("" + ((("1e10")->toReal())))->toInteger() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((x) : a); execute ((y) : b)) ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( d[i+1] := a[i+1] - b[i+1]) ; var mx : OclAny := null; var mn : OclAny := null; var i1 : OclAny := null; var i2 : OclAny := null; Sequence{mx,mn,i1,i2} := Sequence{-Math_PINFINITY,Math_PINFINITY,0,0} ; for i : Integer.subrange(0, n-1) do ( if (d[i+1]->compareTo(mn)) < 0 then ( var mn : OclAny := d[i+1] ; var i2 : OclAny := i ) else skip ; if (d[i+1]->compareTo(mx)) > 0 then ( var mx : OclAny := d[i+1] ; var i1 : OclAny := i ) else skip) ; var s : double := (a)->sum() - (b)->sum() ; if ((s)->abs()->compareTo((s - 2 * mx)->abs())) > 0 & ((s)->abs()->compareTo((s - 2 * mn)->abs())) > 0 then ( execute (0)->display() ) else (if ((s - 2 * mx)->abs()->compareTo((s - 2 * mn)->abs())) > 0 then ( execute (i1 + 1)->display() ) else ( execute (i2 + 1)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- nowl=0 nowr=0 nowlid=1 nowrid=1 suml=0 sumr=0 n=int(input()) for x in range(n): y,z=map(int,input().split()) if y>z and y-z>=nowl : nowl=y-z nowlid=x if y=nowr : nowr=z-y nowrid=x suml+=y sumr+=z if nowl*nowr==0 : print(0) elif abs(suml-sumr-2*nowl)>=abs(suml-sumr+2*nowr): print(nowlid+1) else : print(nowrid+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var nowl : int := 0 ; var nowr : int := 0 ; var nowlid : int := 1 ; var nowrid : int := 1 ; var suml : int := 0 ; var sumr : int := 0 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for x : Integer.subrange(0, n-1) do ( var y : OclAny := null; var z : OclAny := null; Sequence{y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (y->compareTo(z)) > 0 & (y - z->compareTo(nowl)) >= 0 then ( nowl := y - z ; nowlid := x ) else skip ; if (y->compareTo(z)) < 0 & (z - y->compareTo(nowr)) >= 0 then ( nowr := z - y ; nowrid := x ) else skip ; suml := suml + y ; sumr := sumr + z) ; if nowl * nowr = 0 then ( execute (0)->display() ) else (if ((suml - sumr - 2 * nowl)->abs()->compareTo((suml - sumr + 2 * nowr)->abs())) >= 0 then ( execute (nowlid + 1)->display() ) else ( execute (nowrid + 1)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- K,N=map(int,input().split()) A=list(map(int,input().split())) B=[None]*N for i in range(0,N): if i==N-1 : B[i]=K-A[i]+A[0] else : B[i]=abs(A[i]-A[i+1]) print(sum(B)-max(B)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var K : OclAny := null; var N : OclAny := null; Sequence{K,N} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var B : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, N) ; for i : Integer.subrange(0, N-1) do ( if i = N - 1 then ( B[i+1] := K - A[i+1] + A->first() ) else ( B[i+1] := (A[i+1] - A[i + 1+1])->abs() )) ; execute ((B)->sum() - (B)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Squares(n,m,a): return(((m+a-1)//a)*((n+a-1)//a)) if __name__=="__main__" : n=6 m=6 a=4 print(Squares(n,m,a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 6 ; m := 6 ; a := 4 ; execute (Squares(n, m, a))->display() ) else skip; operation Squares(n : OclAny, m : OclAny, a : OclAny) : OclAny pre: true post: true activity: return (((m + a - 1) div a) * ((n + a - 1) div a)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=map(int,input().split()) a=[] for _ in range(n): a+=map(int,input().split()) p=a.index(max(a)) x,y=p//m,p % m print(max(x+1,n-x)*max(y+1,m-y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( a := a + (input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var p : int := a->indexOf((a)->max()) - 1 ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{p div m,p mod m} ; execute (Set{x + 1, n - x}->max() * Set{y + 1, m - y}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np KN=input().split() K=int(KN[0]) N=int(KN[1]) A=input().split() A_np=np.append(np.array(A,dtype=np.int64),int(A[0])+K) A_np_lag=np.append(A_np[1 :],A_np[0]) A_diff=A_np_lag[: N]-A_np[: N] print(A_diff.sum()-A_diff.max()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var KN : OclAny := input().split() ; var K : int := ("" + ((KN->first())))->toInteger() ; var N : int := ("" + ((KN[1+1])))->toInteger() ; var A : OclAny := input().split() ; var A_np : (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name np)) (trailer . (name array) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A))))))) , (argument (test (logical_test (comparison (expr (atom (name dtype)))))) = (test (logical_test (comparison (expr (atom (name np)) (trailer . (name int64)))))))) )))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))) + (expr (atom (name K))))))))) ))) := ; var A_np_lag : (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A_np)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name A_np)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))) := ; var A_diff : double := A_np_lag.subrange(1,N) - A_np.subrange(1,N) ; execute (A_diff.sum() - A_diff->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): k,n=map(int,input().split()) max_range=0 first=True first_range=0 pre_range=0 for i in[int(i)for i in input().split()]: if first : first=False first_range=i pre_range=i continue if max_rangedisplay(); operation main() : OclAny pre: true post: true activity: var k : OclAny := null; var n : OclAny := null; Sequence{k,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var max_range : int := 0 ; var first : boolean := true ; var first_range : int := 0 ; var pre_range : int := 0 ; for i : input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) do ( if first then ( first := false ; first_range := i ; pre_range := i ; continue ) else skip ; if (max_range->compareTo(i - pre_range)) < 0 then ( max_range := i - pre_range ) else skip ; pre_range := i) ; if (max_range->compareTo(first_range + (k - pre_range))) < 0 then ( max_range := first_range + (k - pre_range) ) else skip ; return k - max_range; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline k,n=map(int,input().split()) a=[int(item)for item in input().split()] a.append(a[0]+k) max_diff=0 for a1,a2 in zip(a,a[1 :]): max_diff=max(max_diff,a2-a1) print(k-max_diff) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var k : OclAny := null; var n : OclAny := null; Sequence{k,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := input().split()->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; execute ((a->first() + k) : a) ; var max_diff : int := 0 ; for _tuple : Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), a->tail()->at(_indx)} ) do (var _indx : int := 1; var a1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a2 : OclAny := _tuple->at(_indx); max_diff := Set{max_diff, a2 - a1}->max()) ; execute (k - max_diff)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin def ns(): return stdin.readline().rstrip() def ni(): return int(ns()) def na(): return list(map(int,stdin.readline().split())) def main(): k,n=na() a=na() lmax=a[0]+(k-a[-1]) for ai,aj in zip(a[0 :-1],a[1 :]): lmax=max(lmax,(aj-ai)) print(k-lmax) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stdin : OclFile := OclFile["System.in"] ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation ns() : OclAny pre: true post: true activity: return stdin.readLine().rstrip(); operation ni() : OclAny pre: true post: true activity: return ("" + ((ns())))->toInteger(); operation na() : OclAny pre: true post: true activity: return ((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation main() pre: true post: true activity: var k : OclAny := null; var n : OclAny := null; Sequence{k,n} := na() ; var a : OclAny := na() ; var lmax : OclAny := a->first() + (k - a->last()) ; for _tuple : Integer.subrange(1, a.subrange(0+1, -1)->size())->collect( _indx | Sequence{a.subrange(0+1, -1)->at(_indx), a->tail()->at(_indx)} ) do (var _indx : int := 1; var ai : OclAny := _tuple->at(_indx); _indx := _indx + 1; var aj : OclAny := _tuple->at(_indx); lmax := Set{lmax, (aj - ai)}->max()) ; execute (k - lmax)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def subsetBitwiseORk(arr,n,k): v=[] for i in range(0,n): if((arr[i]| k)==k): v.append(arr[i]) ans=0 for i in range(0,len(v)): ans |=v[i] if(ans!=k): print("Subset does not exist\n") return for i in range(0,len(v)): print("{}".format(v[i]),end="") k=3 arr=[1,4,2] n=len(arr) subsetBitwiseORk(arr,n,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; k := 3 ; arr := Sequence{1}->union(Sequence{4}->union(Sequence{ 2 })) ; n := (arr)->size() ; subsetBitwiseORk(arr, n, k); operation subsetBitwiseORk(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var v : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if ((MathLib.bitwiseOr(arr[i+1], k)) = k) then ( execute ((arr[i+1]) : v) ) else skip) ; var ans : int := 0 ; for i : Integer.subrange(0, (v)->size()-1) do ( ans := ans or v[i+1]) ; if (ans /= k) then ( execute ("Subset does not exist\n")->display() ; return ) else skip ; for i : Integer.subrange(0, (v)->size()-1) do ( execute (StringLib.interpolateStrings("{}", Sequence{v[i+1]}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,gcd l,r,x,y=(int(x)for x in input().split()) v,s,j,pairs=y//x,sqrt(y//x),1,set() if y % x : print(0) else : while j*j<=v : if v % j==0 and gcd(j,v//j)==1 and l<=j*x<=r and l<=(v//j)*x<=r : pairs.add((j,v//j)) pairs.add((v//j,j)) j+=1 print(len(pairs)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var l : OclAny := null; var r : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{l,r,x,y} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var v : OclAny := null; var s : OclAny := null; var j : OclAny := null; var pairs : OclAny := null; Sequence{v,s,j,pairs} := Sequence{y div x,sqrt(y div x),1,Set{}->union(())} ; if y mod x then ( execute (0)->display() ) else ( while (j * j->compareTo(v)) <= 0 do ( if v mod j = 0 & gcd(j, v div j) = 1 & (l->compareTo(j * x)) <= 0 & (j * x <= r) & (l->compareTo((v div j) * x)) <= 0 & ((v div j) * x <= r) then ( execute ((Sequence{j, v div j}) : pairs) ; execute ((Sequence{v div j, j}) : pairs) ) else skip ; j := j + 1) ; execute ((pairs)->size())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* l,r,x,y=map(int,input().split()) if y % x!=0 : print(0) else : tmp=y//x ans=0 limit=int(sqrt(tmp)) i=1 while i<=limit : if tmp % i==0 : if i==(tmp//i): if i>=(l/x)and(tmp//i)<=(r/x)and gcd(i,tmp//i)==1 : ans+=1 else : if i>=(l/x)and(tmp//i)<=(r/x): if gcd(i,tmp//i)==1 : ans+=2 i+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var l : OclAny := null; var r : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{l,r,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if y mod x /= 0 then ( execute (0)->display() ) else ( var tmp : int := y div x ; var ans : int := 0 ; var limit : int := ("" + ((sqrt(tmp))))->toInteger() ; var i : int := 1 ; while (i->compareTo(limit)) <= 0 do ( if tmp mod i = 0 then ( if i = (tmp div i) then ( if (i->compareTo((l / x))) >= 0 & ((tmp div i)->compareTo((r / x))) <= 0 & gcd(i, tmp div i) = 1 then ( ans := ans + 1 ) else skip ) else ( if (i->compareTo((l / x))) >= 0 & ((tmp div i)->compareTo((r / x))) <= 0 then ( if gcd(i, tmp div i) = 1 then ( ans := ans + 2 ) else skip ) else skip ) ) else skip ; i := i + 1) ; execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function from collections import* from sys import stdin from heapq import* from math import* g=lambda : stdin.readline().strip() gl=lambda : g().split() gil=lambda :[int(var)for var in gl()] gfl=lambda :[float(var)for var in gl()] gcl=lambda : list(g()) gbs=lambda :[int(var)for var in g()] rr=lambda x : reversed(range(x)) mod=int(1e9)+7 inf=float("inf") l,r,gc,lc=gil() if lc % gc : print(0); exit() k=lc//gc ans=0 for k1 in range(1,int((sqrt(k)))+1): if k % k1 : continue k2=k//k1 if gcd(k1,k2)>1 : continue if l<=gc*k1<=r and l<=gc*k2<=r : ans+=1 if k1==k2 else 2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var g : Function := lambda $$ : OclAny in (stdin.readLine()->trim()) ; var gl : Function := lambda $$ : OclAny in (g->apply().split()) ; var gil : Function := lambda $$ : OclAny in (gl->apply()->select(var | true)->collect(var | (("" + ((var)))->toInteger()))) ; var gfl : Function := lambda $$ : OclAny in (gl->apply()->select(var | true)->collect(var | (("" + ((var)))->toReal()))) ; var gcl : Function := lambda $$ : OclAny in ((g->apply())) ; var gbs : Function := lambda $$ : OclAny in (g->apply()->select(var | true)->collect(var | (("" + ((var)))->toInteger()))) ; var rr : Function := lambda x : OclAny in ((Integer.subrange(0, x-1))->reverse()) ; var mod : int := ("" + ((("1e9")->toReal())))->toInteger() + 7 ; var Math_PINFINITY : double := ("" + (("inf")))->toReal() ; var l : OclAny := null; var r : OclAny := null; var gc : OclAny := null; var lc : OclAny := null; Sequence{l,r,gc,lc} := gil->apply() ; if lc mod gc then ( execute (0)->display(); exit() ) else skip ; var k : int := lc div gc ; var ans : int := 0 ; for k1 : Integer.subrange(1, ("" + (((sqrt(k)))))->toInteger() + 1-1) do ( if k mod k1 then ( continue ) else skip ; var k2 : int := k div k1 ; if gcd(k1, k2) > 1 then ( continue ) else skip ; if (l->compareTo(gc * k1)) <= 0 & (gc * k1 <= r) & (l->compareTo(gc * k2)) <= 0 & (gc * k2 <= r) then ( ans := ans + if k1 = k2 then 1 else 2 endif ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(b==0): return(a) return(gcd(b,a % b)) l,r,x,y=map(int,input().split()) if(y % x!=0): print(0) else : c=0 k=y//x i=1 while(i*i<=k): if(k % i==0): j=k//i if((l<=j*x and j*x<=r)and(l<=i*x and i*x<=r)and gcd(i,j)==1): if(i*i==k): c+=1 else : c+=2 i+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var l : OclAny := null; var r : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{l,r,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (y mod x /= 0) then ( execute (0)->display() ) else ( var c : int := 0 ; var k : int := y div x ; var i : int := 1 ; while ((i * i->compareTo(k)) <= 0) do ( if (k mod i = 0) then ( var j : int := k div i ; if (((l->compareTo(j * x)) <= 0 & (j * x->compareTo(r)) <= 0) & ((l->compareTo(i * x)) <= 0 & (i * x->compareTo(r)) <= 0) & gcd(i, j) = 1) then ( if (i * i = k) then ( c := c + 1 ) else ( c := c + 2 ) ) else skip ) else skip ; i := i + 1) ; execute (c)->display() ); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (b = 0) then ( return (a) ) else skip ; return (gcd(b, a mod b)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,m=map(int,input().split()) if n>=6 and n % m==0 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n >= 6 & n mod m = 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxSum(arr,n,k): if(nk): r=m-1 ; else : l=m+1 ; max_len=m ; return max_len ; if __name__=="__main__" : arr=[1,2,3,4,5]; n=len(arr); k=10 ; print(solve(arr,n,k)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))); ; n := (arr)->size(); ; k := 10; ; execute (solve(arr, n, k))->display(); ) else skip; operation maxSum(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: if ((n->compareTo(k)) < 0) then ( return -1; ) else skip ; var res : int := 0; ; for i : Integer.subrange(0, k-1) do ( res := res + arr[i+1];) ; var curr_sum : int := res; ; for i : Integer.subrange(k, n-1) do ( curr_sum := curr_sum + arr[i+1] - arr[i - k+1]; ; res := Set{res, curr_sum}->max();) ; return res;; operation solve(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var max_len : int := 0; var l : int := 0; var r : OclAny := n; ; while ((l->compareTo(r)) <= 0) do ( var m : int := (l + r) div 2; ; if ((maxSum(arr, n, m)->compareTo(k)) > 0) then ( r := m - 1; ) else ( l := m + 1; ; max_len := m; )) ; return max_len;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def compute(): def f(x): return math.floor(2.0**(30.403243784-x*x))/1.0e9 ITERATIONS=10**12 x=-1.0 y=-1.0 i=0 while i0 and x==y : break x=f(x) y=f(f(y)) i+=1 remain=(ITERATIONS-i)% i for i in range(remain): x=f(x) ans=x+f(x) ans=math.floor(ans*1.0e9)/1.0e9 return f"{ans:.9f}" if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: skip ; var ITERATIONS : double := (10)->pow(12) ; x := -1.0 ; var y : double := -1.0 ; var i : int := 0 ; while (i->compareTo(ITERATIONS)) < 0 do ( if i > 0 & x = y then ( break ) else skip ; x := f(x) ; y := f(f(y)) ; i := i + 1) ; var remain : int := (ITERATIONS - i) mod i ; for i : Integer.subrange(0, remain-1) do ( x := f(x)) ; var ans : OclAny := x + f(x) ; ans := (ans * ("1.0e9")->toReal())->floor() / ("1.0e9")->toReal() ; return StringLib.formattedString("{ans:.9f}"); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a,b,c=[float(i)for i in input().split()] c=math.radians(c) h=math.sin(c)*b s=a*h/2 q=math.sqrt(pow(a,2)+pow(b,2)-2*a*b*math.cos(c)) l=a+b+q print(s) print(l) print(h) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toReal())) ; var c : OclAny := ; var h : double := (c)->sin() * b ; var s : double := a * h / 2 ; var q : double := ((a)->pow(2) + (b)->pow(2) - 2 * a * b * )->sqrt() ; var l : OclAny := a + b + q ; execute (s)->display() ; execute (l)->display() ; execute (h)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from enum import Enum import sys import math BIG_NUM=2000000000 MOD=1000000007 EPS=0.000000001 A,B,DEGREE=map(int,input().split()) rad=math.radians(DEGREE) S=A*B*math.sin(rad)/2.0 C=math.sqrt(A*A+B*B-2*A*B*math.cos(rad)) h=2*S/A print("%.10f %.10f %.10f" %(S,A+B+C,h)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; var A : OclAny := null; var B : OclAny := null; var DEGREE : OclAny := null; Sequence{A,B,DEGREE} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var rad : OclAny := ; var S : double := A * B * (rad)->sin() / 2.0 ; var C : double := (A * A + B * B - 2 * A * B * )->sqrt() ; var h : double := 2 * S / A ; execute (StringLib.format("%.10f %.10f %.10f",Sequence{S, A + B + C, h}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,C=map(float,input().split()) import math r=C*(math.pi)/180 S=1/2*a*b*(math.sin(r)) c=(a**2+b**2-2*a*b*(math.cos(r)))**(1/2) L=a+b+c h=b*(math.sin(r)) print(S) print(L) print(h) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var C : OclAny := null; Sequence{a,b,C} := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; skip ; var r : double := C * () / 180 ; var S : double := 1 / 2 * a * b * ((r)->sin()) ; var c : double := (((a)->pow(2) + (b)->pow(2) - 2 * a * b * ()))->pow((1 / 2)) ; var L : OclAny := a + b + c ; var h : double := b * ((r)->sin()) ; execute (S)->display() ; execute (L)->display() ; execute (h)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=list(map(int,input().split())) a=n[0] b=n[1] c=n[2]*(math.pi/180) print(0.5*a*b*math.sin(c)) print(a+b+math.sqrt(a**2+b**2-2*a*b*math.cos(c))) print(b*math.sin(c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := n->first() ; var b : OclAny := n[1+1] ; var c : double := n[2+1] * ( / 180) ; execute (0.5 * a * b * (c)->sin())->display() ; execute (a + b + ((a)->pow(2) + (b)->pow(2) - 2 * a * b * )->sqrt())->display() ; execute (b * (c)->sin())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c_deg=map(float,input().split()) import math c_rad=math.radians(c_deg) c=math.sqrt(a**2+b**2-2*a*b*math.cos(c_rad)) l=a+b+c h=math.sin(c_rad)*b s=a*h/2 print('{:.5f}'.format(s)) print('{:.5f}'.format(l)) print('{:.5f}'.format(h)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c_deg : OclAny := null; Sequence{a,b,c_deg} := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; skip ; var c_rad : OclAny := ; var c : double := ((a)->pow(2) + (b)->pow(2) - 2 * a * b * )->sqrt() ; var l : OclAny := a + b + c ; var h : double := (c_rad)->sin() * b ; var s : double := a * h / 2 ; execute (StringLib.interpolateStrings('{:.5f}', Sequence{s}))->display() ; execute (StringLib.interpolateStrings('{:.5f}', Sequence{l}))->display() ; execute (StringLib.interpolateStrings('{:.5f}', Sequence{h}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: a=[[],[]]; i=0 for x in s.split(): i+=1 ; a[int(x)% 2]+=i, a.sort(key=len); b,c=a ; c.pop(); a[len(c)% 2].pop(); print(*b,*c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var a : Sequence := Sequence{Sequence{}}->union(Sequence{ Sequence{} }); var i : int := 0 ; for x : s.split() do ( i := i + 1; a[("" + ((x)))->toInteger() mod 2+1] := a[("" + ((x)))->toInteger() mod 2+1] + (testlist (test (logical_test (comparison (expr (atom (name i)))))) ,)) ; a := a->sort(); var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := a; c := c->front();(expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))) % (expr (atom (number (integer 2)))))))))) ])) (trailer . (name pop) (arguments ( )))); execute ((argument * (test (logical_test (comparison (expr (atom (name b))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: a=[[],[]]; i=0 for x in s.split(): i+=1 ; a[int(x)% 2]+=i, a.sort(key=len); b,c=a ; c.pop(); a[len(c)% 2].pop(); print(*b,*c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var a : Sequence := Sequence{Sequence{}}->union(Sequence{ Sequence{} }); var i : int := 0 ; for x : s.split() do ( i := i + 1; a[("" + ((x)))->toInteger() mod 2+1] := a[("" + ((x)))->toInteger() mod 2+1] + (testlist (test (logical_test (comparison (expr (atom (name i)))))) ,)) ; a := a->sort(); var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := a; c := c->front();(expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))) % (expr (atom (number (integer 2)))))))))) ])) (trailer . (name pop) (arguments ( )))); execute ((argument * (test (logical_test (comparison (expr (atom (name b))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=list(zip([int(i)for i in input().split()],[i for i in range(2*n)])) even=[i for i in a if i[0]% 2==0] odd=[i for i in a if i[0]% 2] counter=0 for i in range(0,len(even),2): if counter==n-1 : break if i==len(even)-1 : break print(even[i][1]+1,even[i+1][1]+1) counter+=1 for i in range(0,len(odd),2): if counter==n-1 : break if i==len(odd)-1 : break print(odd[i][1]+1,odd[i+1][1]+1) counter+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (Integer.subrange(1, input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))->size())->collect( _indx | Sequence{input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))->at(_indx), Integer.subrange(0, 2 * n-1)->select(i | true)->collect(i | (i))->at(_indx)} )) ; var even : Sequence := a->select(i | i->first() mod 2 = 0)->collect(i | (i)) ; var odd : Sequence := a->select(i | i->first() mod 2)->collect(i | (i)) ; var counter : int := 0 ; for i : Integer.subrange(0, (even)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( if counter = n - 1 then ( break ) else skip ; if i = (even)->size() - 1 then ( break ) else skip ; execute (even[i+1][1+1] + 1)->display() ; counter := counter + 1) ; for i : Integer.subrange(0, (odd)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( if counter = n - 1 then ( break ) else skip ; if i = (odd)->size() - 1 then ( break ) else skip ; execute (odd[i+1][1+1] + 1)->display() ; counter := counter + 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def negProdSubArr(arr,n): positive=1 negative=0 for i in range(n): if(arr[i]>0): arr[i]=1 else : arr[i]=-1 if(i>0): arr[i]*=arr[i-1] if(arr[i]==1): positive+=1 else : negative+=1 return(positive*negative) arr=[5,-4,-3,2,-5] n=len(arr) print(negProdSubArr(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{5}->union(Sequence{-4}->union(Sequence{-3}->union(Sequence{2}->union(Sequence{ -5 })))) ; n := (arr)->size() ; execute (negProdSubArr(arr, n))->display(); operation negProdSubArr(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var positive : int := 1 ; var negative : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] > 0) then ( arr[i+1] := 1 ) else ( arr[i+1] := -1 ) ; if (i > 0) then ( arr[i+1] := arr[i+1] * arr[i - 1+1] ) else skip ; if (arr[i+1] = 1) then ( positive := positive + 1 ) else ( negative := negative + 1 )) ; return (positive * negative); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n,m=input().split() n=int(n) m=int(m) if n % m==0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var m : int := ("" + ((m)))->toInteger() ; if n mod m = 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) if a==1 or a==3 or a==5 or a==7 or a==8 or a==10 or a==12 : if b==1 or b==2 or b==3 or b==4 or b==5 : print('5') elif b==6 or b==7 : print('6') elif a==2 : if b==1 : print('4') else : print('5') else : if b==7 : print('6') else : print('5') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 1 or a = 3 or a = 5 or a = 7 or a = 8 or a = 10 or a = 12 then ( if b = 1 or b = 2 or b = 3 or b = 4 or b = 5 then ( execute ('5')->display() ) else (if b = 6 or b = 7 then ( execute ('6')->display() ) else skip) ) else (if a = 2 then ( if b = 1 then ( execute ('4')->display() ) else ( execute ('5')->display() ) ) else ( if b = 7 then ( execute ('6')->display() ) else ( execute ('5')->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dc=[0,31,28,31,30,31,30,31,31,30,31,30,31] m,d=map(int,input().split()) print((dc[m]+d+5)//7) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dc : Sequence := Sequence{0}->union(Sequence{31}->union(Sequence{28}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{ 31 })))))))))))) ; var m : OclAny := null; var d : OclAny := null; Sequence{m,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((dc[m+1] + d + 5) div 7)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isSumDivides(N): temp=N sum=0 while(temp): sum+=temp % 10 temp=int(temp/10) if(N % sum==0): return 1 else : return 0 if __name__=='__main__' : N=12 if(isSumDivides(N)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( N := 12 ; if (isSumDivides(N)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; operation isSumDivides(N : OclAny) : OclAny pre: true post: true activity: var temp : OclAny := N ; var sum : int := 0 ; while (temp) do ( sum := sum + temp mod 10 ; temp := ("" + ((temp / 10)))->toInteger()) ; if (N mod sum = 0) then ( return 1 ) else ( return 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for q in range(t): n,k=list(map(int,input().split(""))) if n % 2!=0 : print("NO") continue i=0 if k % 2!=0 : print("YES") i=1 while i<=n : for j in range(2): if i<=n : print(i,end="") i+=1 print("") else : i=2 res=1 while(i<=n): if(i+k)% 4!=0 and i % 4!=0 : print("NO") res=0 break i+=2 if res==0 : continue print("YES") i=2 while(i<=n): if i % 4==0 : print(i-1,i) i+=2 else : print(i,i-1) i+=2 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for q : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split(""))->collect( _x | (OclType["int"])->apply(_x) )) ; if n mod 2 /= 0 then ( execute ("NO")->display() ; continue ) else skip ; var i : int := 0 ; if k mod 2 /= 0 then ( execute ("YES")->display() ; i := 1 ; while (i->compareTo(n)) <= 0 do ( for j : Integer.subrange(0, 2-1) do ( if (i->compareTo(n)) <= 0 then ( execute (i)->display() ) else skip ; i := i + 1) ; execute ("")->display()) ) else ( i := 2 ; var res : int := 1 ; while ((i->compareTo(n)) <= 0) do ( if (i + k) mod 4 /= 0 & i mod 4 /= 0 then ( execute ("NO")->display() ; res := 0 ; break ) else skip ; i := i + 2) ; if res = 0 then ( continue ) else skip ; execute ("YES")->display() ; i := 2 ; while ((i->compareTo(n)) <= 0) do ( if i mod 4 = 0 then ( execute (i - 1)->display() ; i := i + 2 ) else ( execute (i)->display() ; i := i + 2 )) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- maxLen=10 dp=[0]*maxLen ; visit=[0]*maxLen ; def maxSum(arr,i,n,k): if(i>=n): return 0 ; if(visit[i]): return dp[i]; visit[i]=1 ; tot=0 ; dp[i]=maxSum(arr,i+1,n,k); j=i while(junion(Sequence{2}->union(Sequence{-3}->union(Sequence{4}->union(Sequence{ 5 })))); ; k := 2; ; n := (arr)->size(); ; execute (maxSum(arr, 0, n, k))->display(); ) else skip; operation maxSum(arr : OclAny, i : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: if ((i->compareTo(n)) >= 0) then ( return 0; ) else skip ; if (visit[i+1]) then ( return dp[i+1]; ) else skip ; visit[i+1] := 1; ; var tot : int := 0; ; dp[i+1] := maxSum(arr, i + 1, n, k); ; var j : OclAny := i ; while ((j->compareTo(i + k)) < 0 & (j->compareTo(n)) < 0) do ( tot := tot + arr[j+1]; ; dp[i+1] := Set{dp[i+1], tot + maxSum(arr, j + 2, n, k)}->max(); ; j := j + 1) ; return dp[i+1];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil days={1 : 31,2 : 28,3 : 31,4 : 30,5 : 31,6 : 30,7 : 31,8 : 31,9 : 30,10 : 31,11 : 30,12 : 31} m,d=(int(i)for i in input().split()) res=ceil((days[m]+d-1)/7) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var days : Map := Map{ 1 |-> 31 }->union(Map{ 2 |-> 28 }->union(Map{ 3 |-> 31 }->union(Map{ 4 |-> 30 }->union(Map{ 5 |-> 31 }->union(Map{ 6 |-> 30 }->union(Map{ 7 |-> 31 }->union(Map{ 8 |-> 31 }->union(Map{ 9 |-> 30 }->union(Map{ 10 |-> 31 }->union(Map{ 11 |-> 30 }->union(Map{ 12 |-> 31 }))))))))))) ; var m : OclAny := null; var d : OclAny := null; Sequence{m,d} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var res : OclAny := ceil((days[m+1] + d - 1) / 7) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- days={1 : 31,2 : 28,3 : 31,4 : 30,5 : 31,6 : 30,7 : 31,8 : 31,9 : 30,10 : 31,11 : 30,12 : 31} m,d=(int(i)for i in input().split()) res=(days[m]-1+d-1)//7+1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var days : Map := Map{ 1 |-> 31 }->union(Map{ 2 |-> 28 }->union(Map{ 3 |-> 31 }->union(Map{ 4 |-> 30 }->union(Map{ 5 |-> 31 }->union(Map{ 6 |-> 30 }->union(Map{ 7 |-> 31 }->union(Map{ 8 |-> 31 }->union(Map{ 9 |-> 30 }->union(Map{ 10 |-> 31 }->union(Map{ 11 |-> 30 }->union(Map{ 12 |-> 31 }))))))))))) ; var m : OclAny := null; var d : OclAny := null; Sequence{m,d} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var res : int := (days[m+1] - 1 + d - 1) div 7 + 1 ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solution(m,d): total_days=[31,28,31,30,31,30,31,31,30,31,30,31] remaining_days=total_days[m-1]-(8-d) ans=1+remaining_days//7+(1 if remaining_days % 7!=0 else 0) return ans m,d=[int(x)for x in input().strip().split(" ")] print(solution(m,d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{m,d} := input()->trim().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (solution(m, d))->display(); operation solution(m : OclAny, d : OclAny) : OclAny pre: true post: true activity: var total_days : Sequence := Sequence{31}->union(Sequence{28}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{ 31 }))))))))))) ; var remaining_days : double := total_days[m - 1+1] - (8 - d) ; var ans : int := 1 + remaining_days div 7 + (if remaining_days mod 7 /= 0 then 1 else 0 endif) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) mod=10**9+7 fact=[1,1] finv=[1,1] inv=[0,1] for i in range(2,max(n,m)+5): fact.append((fact[-1]*i)% mod) inv.append((inv[mod % i]*(mod-mod//i))% mod) finv.append((finv[-1]*inv[-1])% mod) def nCr(n,r,mod): if r>n : return 0 else : return fact[n]*finv[r]*finv[n-r]% mod def nPr(n,r,mod): if r>n : return 0 else : return fact[n]*finv[n-r]% mod ans=0 for i in range(n+1): now=nCr(n,i,mod) now*=nPr(m-i,n-i,mod) now %=mod if i % 2 : now=-now ans+=now ans % mod ans*=nPr(m,n,mod) ans %=mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mod : double := (10)->pow(9) + 7 ; var fact : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var finv : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var inv : Sequence := Sequence{0}->union(Sequence{ 1 }) ; for i : Integer.subrange(2, Set{n, m}->max() + 5-1) do ( execute (((fact->last() * i) mod mod) : fact) ; execute (((inv[mod mod i+1] * (mod - mod div i)) mod mod) : inv) ; execute (((finv->last() * inv->last()) mod mod) : finv)) ; skip ; skip ; var ans : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( var now : OclAny := nCr(n, i, mod) ; now := now * nPr(m - i, n - i, mod) ; now := now mod mod ; if i mod 2 then ( now := -now ) else skip ; ans := ans + now ; (expr (expr (atom (name ans))) % (expr (atom (name mod))))) ; ans := ans * nPr(m, n, mod) ; ans := ans mod mod ; execute (ans)->display(); operation nCr(n : OclAny, r : OclAny, mod : OclAny) : OclAny pre: true post: true activity: if (r->compareTo(n)) > 0 then ( return 0 ) else ( return fact[n+1] * finv[r+1] * finv[n - r+1] mod mod ); operation nPr(n : OclAny, r : OclAny, mod : OclAny) : OclAny pre: true post: true activity: if (r->compareTo(n)) > 0 then ( return 0 ) else ( return fact[n+1] * finv[n - r+1] mod mod ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys class ENEQ : def solve(self,tc=0): from itertools import permutations MOD=10**9+7 n,m=[int(_)for _ in input().split()] D=[0]*(n+1) D[0]=1 D[1]=m-n for i in range(2,n+1): D[i]=(m-n+i-1)*D[i-1]+(i-1)*D[i-2] D[i]%=MOD fact=[1]*(m+1) for i in range(1,m+1): fact[i]=fact[i-1]*i fact[i]%=MOD ans=fact[m]*pow(fact[m-n],MOD-2,MOD)*D[n] ans %=MOD print(ans) solver=ENEQ() input=sys.stdin.readline solver.solve() ------------------------------------------------------------ OCL File: --------- class ENEQ { static operation newENEQ() : ENEQ pre: true post: ENEQ->exists( _x | result = _x ); operation solve(tc : int) pre: true post: true activity: skip ; var MOD : double := (10)->pow(9) + 7 ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var D : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; D->first() := 1 ; D[1+1] := m - n ; for i : Integer.subrange(2, n + 1-1) do ( D[i+1] := (m - n + i - 1) * D[i - 1+1] + (i - 1) * D[i - 2+1] ; D[i+1] := D[i+1] mod MOD) ; var fact : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (m + 1)) ; for i : Integer.subrange(1, m + 1-1) do ( fact[i+1] := fact[i - 1+1] * i ; fact[i+1] := fact[i+1] mod MOD) ; var ans : double := fact[m+1] * (fact[m - n+1])->pow(MOD - 2) * D[n+1] ; ans := ans mod MOD ; execute (ans)->display(); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var solver : ENEQ := (ENEQ.newENEQ()).initialise() ; var input : OclAny := (OclFile["System.in"]).readline ; solver.solve(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): m,n=map(int,input().split()); print("YES" if m % n==0 else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); ; execute (if m mod n = 0 then "YES" else "NO" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Combi(): def __init__(self,N,mod): self.power=[1 for _ in range(N+1)] self.rev=[1 for _ in range(N+1)] self.mod=mod for i in range(2,N+1): self.power[i]=(self.power[i-1]*i)% self.mod self.rev[N]=pow(self.power[N],self.mod-2,self.mod) for j in range(N,0,-1): self.rev[j-1]=(self.rev[j]*j)% self.mod def com(self,K,R): if Kexists( _x | result = _x ); attribute power : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (1)); attribute rev : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (1)); attribute mod : OclAny := mod; attribute (trailer . (name rev) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name N)))))))) ])) : double := (self.power[N+1])->pow(self.mod - 2); operation initialise(N : OclAny,mod : OclAny) : pre: true post: true activity: self.power := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (1)) ; self.rev := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (1)) ; self.mod := mod ; for i : Integer.subrange(2, N + 1-1) do ( self.power[i+1] := (self.power[i - 1+1] * i) mod self.mod) ; self.rev[N+1] := (self.power[N+1])->pow(self.mod - 2) ; for j : Integer.subrange(0 + 1, N)->reverse() do ( self.rev[j - 1+1] := (self.rev[j+1] * j) mod self.mod); return self; operation com(K : OclAny,R : OclAny) : OclAny pre: true post: true activity: if (K->compareTo(R)) < 0 then ( return 0 ) else ( return ((self.power[K+1]) * (self.rev[K - R+1]) * (self.rev[R+1])) mod self.mod ); operation pom(K : OclAny,R : OclAny) : OclAny pre: true post: true activity: if (K->compareTo(R)) < 0 then ( return 0 ) else ( return (self.power[K+1]) * (self.rev[K - R+1]) mod self.mod ); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; mod := (10)->pow(9) + 7 ; var c : Combi := (Combi.newCombi()).initialise(5 * (10)->pow(5), mod) ; var ans : int := (c.pom(M, N))->pow(2) mod mod ; for k : Integer.subrange(1, N + 1-1) do ( var s : double := ((-1))->pow(((k - 1) mod 2)) ; var t : OclAny := c.com(N, k) ; var u : double := (c.pom(M - k, N - k))->pow(2) ; var v : OclAny := c.pom(M, k) ; ans := ans - s * t * u * v ; ans := ans mod mod) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush,heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod=10**9+7 inf=float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) def comb(a,b): return fact[a]*pow(fact[a-b],mod-2,mod)*pow(fact[b],mod-2,mod)% mod n,m=LI() fact=[1]*(max(n,m)+1) for i in range(1,max(n,m)+1): fact[i]=i*fact[i-1] fact[i]%=mod ret=0 for x in range(n+1): if x % 2 : ret-=comb(n,x)*fact[m-x]*pow(fact[m-x-(n-x)],mod-2,mod) ret %=mod else : ret+=comb(n,x)*fact[m-x]*pow(fact[m-x-(n-x)],mod-2,mod) ret %=mod ans=fact[m]*pow(fact[m-n],mod-2,mod)*ret ans %=mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; sys.setrecursionlimit(2147483647) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; skip ; skip ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := LI() ; var fact : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (Set{n, m}->max() + 1)) ; for i : Integer.subrange(1, Set{n, m}->max() + 1-1) do ( fact[i+1] := i * fact[i - 1+1] ; fact[i+1] := fact[i+1] mod mod) ; var ret : int := 0 ; for x : Integer.subrange(0, n + 1-1) do ( if x mod 2 then ( ret := ret - comb(n, x) * fact[m - x+1] * (fact[m - x - (n - x)+1])->pow(mod - 2) ; ret := ret mod mod ) else ( ret := ret + comb(n, x) * fact[m - x+1] * (fact[m - x - (n - x)+1])->pow(mod - 2) ; ret := ret mod mod )) ; var ans : double := fact[m+1] * (fact[m - n+1])->pow(mod - 2) * ret ; ans := ans mod mod ; execute (ans)->display(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation comb(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return fact[a+1] * (fact[a - b+1])->pow(mod - 2) * (fact[b+1])->pow(mod - 2) mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) i=b=0 a=1 while icollect( _x | (OclType["int"])->apply(_x) ) ; var i : OclAny := 0; var b : int := 0 ; var a : int := 1 ; while (i->compareTo(n)) < 0 do ( Sequence{a,b} := Sequence{((m - i) * ((m - n + i) * a + i * (m - i + 1) * b)) mod ((10)->pow(9) + 7),a}; i := i + 1) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countCurrency(amount): notes=[2000,500,200,100,50,20,10,5,1] noteCounter=[0,0,0,0,0,0,0,0,0] print("Currency Count->") for i,j in zip(notes,noteCounter): if amount>=i : j=amount//i amount=amount-j*i print(i," : ",j) amount=868 countCurrency(amount) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; amount := 868 ; countCurrency(amount); operation countCurrency(amount : OclAny) pre: true post: true activity: var notes : Sequence := Sequence{2000}->union(Sequence{500}->union(Sequence{200}->union(Sequence{100}->union(Sequence{50}->union(Sequence{20}->union(Sequence{10}->union(Sequence{5}->union(Sequence{ 1 })))))))) ; var noteCounter : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))))))) ; execute ("Currency Count->")->display() ; for _tuple : Integer.subrange(1, notes->size())->collect( _indx | Sequence{notes->at(_indx), noteCounter->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if (amount->compareTo(i)) >= 0 then ( var j : int := amount div i ; amount := amount - j * i ; execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def mergeTrees(self,t1,t2): if t1 is None : return t2 if t2 is None : return t1 t1.val+=t2.val t1.left=self.mergeTrees(t1.left,t2.left) t1.right=self.mergeTrees(t1.right,t2.right) return t1 ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation mergeTrees(t1 : OclAny,t2 : OclAny) : OclAny pre: true post: true activity: if t1 <>= null then ( return t2 ) else skip ; if t2 <>= null then ( return t1 ) else skip ; t1.val := t1.val + t2.val ; t1.left := self.mergeTrees(t1.left, t2.left) ; t1.right := self.mergeTrees(t1.right, t2.right) ; return t1; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nondecdigits(s): m=len(s); a=[0]*m ; for i in range(m): a[i]=ord(s[i])-ord('0'); level=m-1 ; for i in range(m-1,0,-1): if(a[i]; operation nondecdigits(s : OclAny) pre: true post: true activity: var m : int := (s)->size(); ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m); ; for i : Integer.subrange(0, m-1) do ( a[i+1] := (s[i+1])->char2byte() - ('0')->char2byte();) ; var level : double := m - 1; ; for i : Integer.subrange(0 + 1, m - 1)->reverse() do ( if ((a[i+1]->compareTo(a[i - 1+1])) < 0) then ( a[i - 1+1] := a[i - 1+1] - 1; ; level := i - 1; ) else skip) ; if (a->first() /= 0) then ( for i : Integer.subrange(0, level + 1-1) do ( execute (a[i+1])->display();) ; for i : Integer.subrange(level + 1, m-1) do ( execute ("9")->display();) ) else ( for i : Integer.subrange(1, level-1) do ( execute (a[i+1])->display();) ; for i : Integer.subrange(level + 1, m-1) do ( execute ("9")->display();) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def stockBuySell(price,n): if(n==1): return i=0 while(i<(n-1)): while((i<(n-1))and(price[i+1]<=price[i])): i+=1 if(i==n-1): break buy=i i+=1 while((i=price[i-1])): i+=1 sell=i-1 print("Buy on day: ",buy,"\t","Sell on day: ",sell) price=[100,180,260,310,40,535,695] n=len(price) stockBuySell(price,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; price := Sequence{100}->union(Sequence{180}->union(Sequence{260}->union(Sequence{310}->union(Sequence{40}->union(Sequence{535}->union(Sequence{ 695 })))))) ; n := (price)->size() ; stockBuySell(price, n); operation stockBuySell(price : OclAny, n : OclAny) pre: true post: true activity: if (n = 1) then ( return ) else skip ; var i : int := 0 ; while ((i->compareTo((n - 1))) < 0) do ( while (((i->compareTo((n - 1))) < 0) & ((price[i + 1+1]->compareTo(price[i+1])) <= 0)) do ( i := i + 1) ; if (i = n - 1) then ( break ) else skip ; var buy : int := i ; i := i + 1 ; while (((i->compareTo(n)) < 0) & ((price[i+1]->compareTo(price[i - 1+1])) >= 0)) do ( i := i + 1) ; var sell : double := i - 1 ; execute ("Buy on day: ")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_CHAR=26 def sortString(str): charCount=[0 for i in range(MAX_CHAR)] for i in range(0,len(str),1): charCount[ord(str[i])-ord('a')]+=1 for i in range(0,MAX_CHAR,1): for j in range(0,charCount[i],1): print(chr(ord('a')+i),end="") if __name__=='__main__' : s="geeksforgeeks" sortString(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_CHAR : int := 26 ; skip ; if __name__ = '__main__' then ( var s : String := "geeksforgeeks" ; sortString(s) ) else skip; operation sortString(OclType["String"] : OclAny) pre: true post: true activity: var charCount : Sequence := Integer.subrange(0, MAX_CHAR-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, (OclType["String"])->size()-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( charCount[(("" + ([i+1])))->char2byte() - ('a')->char2byte()+1] := charCount[(("" + ([i+1])))->char2byte() - ('a')->char2byte()+1] + 1) ; for i : Integer.subrange(0, MAX_CHAR-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( for j : Integer.subrange(0, charCount[i+1]-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( execute ((('a')->char2byte() + i)->byte2char())->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- Morse_tab=[".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] class Solution(object): def uniqueMorseRepresentations(self,words): if len(words)==0 : return 0 ans_set=set() for word in words : morsed="" for c in word : morsed+=Morse_tab[ord(c)-ord('a')] ans_set.add(morsed) return len(ans_set) ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation uniqueMorseRepresentations(words : OclAny) : OclAny pre: true post: true activity: if (words)->size() = 0 then ( return 0 ) else skip ; var ans_set : Set := Set{}->union(()) ; for word : words do ( var morsed : String := "" ; for c : word do ( morsed := morsed + Morse_tab[(c)->char2byte() - ('a')->char2byte()+1]) ; execute ((morsed) : ans_set)) ; return (ans_set)->size(); } class FromPython { operation initialise() pre: true post: true activity: var Morse_tab : Sequence := Sequence{".-"}->union(Sequence{"-..."}->union(Sequence{"-.-."}->union(Sequence{"-.."}->union(Sequence{"."}->union(Sequence{"..-."}->union(Sequence{"--."}->union(Sequence{"...."}->union(Sequence{".."}->union(Sequence{".---"}->union(Sequence{"-.-"}->union(Sequence{".-.."}->union(Sequence{"--"}->union(Sequence{"-."}->union(Sequence{"---"}->union(Sequence{".--."}->union(Sequence{"--.-"}->union(Sequence{".-."}->union(Sequence{"..."}->union(Sequence{"-"}->union(Sequence{"..-"}->union(Sequence{"...-"}->union(Sequence{".--"}->union(Sequence{"-..-"}->union(Sequence{"-.--"}->union(Sequence{ "--.." }))))))))))))))))))))))))) ; skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findCandidate(A): maj_index=0 count=1 for i in range(len(A)): if A[maj_index]==A[i]: count+=1 else : count-=1 if count==0 : maj_index=i count=1 return A[maj_index] def isMajority(A,cand): count=0 for i in range(len(A)): if A[i]==cand : count+=1 if count>len(A)/2 : return True else : return False def printMajority(A): cand=findCandidate(A) if isMajority(A,cand)==True : print(cand) else : print("No Majority Element") A=[1,3,3,1,2] printMajority(A) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; A := Sequence{1}->union(Sequence{3}->union(Sequence{3}->union(Sequence{1}->union(Sequence{ 2 })))) ; printMajority(A); operation findCandidate(A : OclAny) : OclAny pre: true post: true activity: var maj_index : int := 0 ; var count : int := 1 ; for i : Integer.subrange(0, (A)->size()-1) do ( if A[maj_index+1] = A[i+1] then ( count := count + 1 ) else ( count := count - 1 ) ; if count = 0 then ( maj_index := i ; count := 1 ) else skip) ; return A[maj_index+1]; operation isMajority(A : OclAny, cand : OclAny) : OclAny pre: true post: true activity: count := 0 ; for i : Integer.subrange(0, (A)->size()-1) do ( if A[i+1] = cand then ( count := count + 1 ) else skip) ; if (count->compareTo((A)->size() / 2)) > 0 then ( return true ) else ( return false ); operation printMajority(A : OclAny) pre: true post: true activity: cand := findCandidate(A) ; if isMajority(A, cand) = true then ( execute (cand)->display() ) else ( execute ("No Majority Element")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): m,n=map(int,input().split()); print("YES" if m % n==0 else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); ; execute (if m mod n = 0 then "YES" else "NO" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M,X,Y=map(int,input().split()) x=list(map(int,input().split())) y=list(map(int,input().split())) x.append(X) y.append(Y) if max(x)collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var y : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((X) : x) ; execute ((Y) : y) ; if ((x)->max()->compareTo((y)->min())) < 0 then ( execute ('No War')->display() ) else ( execute ('War')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,m,x,y=map(int,input().split()) x_list=list(map(int,input().split())) y_list=list(map(int,input().split())) x_list.sort() y_list.sort() for i in range(int(x_list[-1])+1,int(y_list[0])+1): if(i>x)and(i<=y): print("No War") exit() print("War") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,m,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var y_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; x_list := x_list->sort() ; y_list := y_list->sort() ; for i : Integer.subrange(("" + ((x_list->last())))->toInteger() + 1, ("" + ((y_list->first())))->toInteger() + 1-1) do ( if ((i->compareTo(x)) > 0) & ((i->compareTo(y)) <= 0) then ( execute ("No War")->display() ; exit() ) else skip) ; execute ("War")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M,X,Y=list(map(lambda a : int(a),input().split(" "))) x=list(map(lambda b : int(b),input().split(" "))) y=list(map(lambda c : int(c),input().split(" "))) x.append(X) y.append(Y) x.sort() y.sort() if x[-1]collect( _x | (lambda a : OclAny in (("" + ((a)))->toInteger()))->apply(_x) )) ; var x : Sequence := ((input().split(" "))->collect( _x | (lambda b : OclAny in (("" + ((b)))->toInteger()))->apply(_x) )) ; var y : Sequence := ((input().split(" "))->collect( _x | (lambda c : OclAny in (("" + ((c)))->toInteger()))->apply(_x) )) ; execute ((X) : x) ; execute ((Y) : y) ; x := x->sort() ; y := y->sort() ; if (x->last()->compareTo(y->first())) < 0 then ( execute ("No War")->display() ) else ( execute ("War")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lst_1=input().split() N=int(lst_1[0]) M=int(lst_1[1]) X=(lst_1[2]) Y=(lst_1[3]) lst_X=input().split() lst_Y=input().split() lst_X.append(X) lst_Y.append(Y) for i in range(N+1): lst_X[i]=int(lst_X[i]) for i in range(M+1): lst_Y[i]=int(lst_Y[i]) X_max=max(lst_X) Y_min=min(lst_Y) if X_maxfirst())))->toInteger() ; var M : int := ("" + ((lst var lst_1 : OclAny := input().split()[1+1])))->toInteger() ; var X : OclAny := (lst var lst_1 : OclAny := input().split()[2+1]) ; var Y : OclAny := (lst var lst_1 : OclAny := input().split()[3+1]) ; var lst_X : OclAny := input().split() ; var lst_Y : OclAny := input().split() ; execute ((X) : lst_X) ; execute ((Y) : lst_Y) ; for i : Integer.subrange(0, N + 1-1) do ( lst_X[i+1] := ("" + ((lst_X[i+1])))->toInteger()) ; for i : Integer.subrange(0, M + 1-1) do ( lst_Y[i+1] := ("" + ((lst_Y[i+1])))->toInteger()) ; var X_max : OclAny := (lst_X)->max() ; var Y_min : OclAny := (lst_Y)->min() ; if (X_max->compareTo(Y_min)) < 0 then ( var ans : String := "No War" ) else ( ans := "War" ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M,X,Y=map(int,input().split()) l1=[i for i in range(X+1,Y+1)] s1=set(l1) X_list=list(map(int,input().split())) Y_list=list(map(int,input().split())) X_max=max(X_list) Y_min=min(Y_list) if X_maxcollect( _x | (OclType["int"])->apply(_x) ) ; var l1 : Sequence := Integer.subrange(X + 1, Y + 1-1)->select(i | true)->collect(i | (i)) ; var s1 : Set := Set{}->union((l1)) ; var X_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var Y_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var X_max : OclAny := (X_list)->max() ; var Y_min : OclAny := (Y_list)->min() ; if (X_max->compareTo(Y_min)) < 0 then ( var l2 : Sequence := Integer.subrange(X_max + 1, Y_min + 1-1)->select(i | true)->collect(i | (i)) ; var s2 : Set := Set{}->union((l2)) ; if MathLib.bitwiseAnd(s1, s2) then ( execute ('No War')->display() ) else ( execute ('War')->display() ) ) else ( execute ('War')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def firstkdigits(n,k): product=n*math.log(n,10); decimal_part=product-math.floor(product); decimal_part=pow(10,decimal_part); digits=pow(10,k-1); return math.floor(decimal_part*digits); n=1450 ; k=6 ; print(firstkdigits(n,k)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 1450; ; k := 6; ; execute (firstkdigits(n, k))->display();; operation firstkdigits(n : OclAny, k : OclAny) pre: true post: true activity: var product : double := n * (n, 10)->log(); ; var decimal_part : double := product - (product)->floor(); ; decimal_part := (10)->pow(decimal_part); ; var digits : double := (10)->pow(k - 1); ; return (decimal_part * digits)->floor();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxNumber(string,n): freq=[0,0] for i in range(n): if(string[i]=='z'): freq[0]+=1 ; elif(string[i]=='n'): freq[1]+=1 ; num="" ; for i in range(freq[1]): num+='1' ; for i in range(freq[0]): num+='0' ; return num ; if __name__=="__main__" : string="roenenzooe" ; n=len(string); print(maxNumber(string,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( string := "roenenzooe"; ; n := (string)->size(); ; execute (maxNumber(string, n))->display(); ) else skip; operation maxNumber(string : OclAny, n : OclAny) pre: true post: true activity: var freq : Sequence := Sequence{0}->union(Sequence{ 0 }) ; for i : Integer.subrange(0, n-1) do ( if (string[i+1] = 'z') then ( freq->first() := freq->first() + 1; ) else (if (string[i+1] = 'n') then ( freq[1+1] := freq[1+1] + 1; ) else skip)) ; var num : String := ""; ; for i : Integer.subrange(0, freq[1+1]-1) do ( num := num + '1';) ; for i : Integer.subrange(0, freq->first()-1) do ( num := num + '0';) ; return num;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(33*n,32*n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (33 * n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(25*n,24*n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (25 * n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(27*n,26*n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (27 * n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) for i in range(num): side=input() side=side.split(" ") a=int(side[0]) b=int(side[1]) if a % b==0 or b % a==0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, num-1) do ( var side : String := (OclFile["System.in"]).readLine() ; side := side.split(" ") ; var a : int := ("" + ((side->first())))->toInteger() ; var b : int := ("" + ((side[1+1])))->toInteger() ; if a mod b = 0 or b mod a = 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(26*n,25*n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (26 * n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(28*n,27*n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (28 * n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=sorted(map(int,input().split())) s=0 for i in range(0,n,2): s+=a[i+1]-a[i] print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var s : int := 0 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( s := s + a[i + 1+1] - a[i+1]) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() lst=sorted(map(int,input().split())) print(sum(abs(a-b)for a,b in zip(lst[: : 2],lst[1 : : 2]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var lst : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; execute (((argument (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (name b))))))))) ))))))) (comp_for for (exprlist (expr (atom (name a))) , (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name lst)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) ])))))))) )))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=0 mops=list(map(int,input().split())) mops.sort() for i in range(0,n,2): a=0 if mops[i]<=mops[i+1]: a=mops[i+1]-mops[i] ans+=a print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; var mops : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; mops := mops->sort() ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( var a : int := 0 ; if (mops[i+1]->compareTo(mops[i + 1+1])) <= 0 then ( a := mops[i + 1+1] - mops[i+1] ) else skip ; ans := ans + a) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=0 mops=list(map(int,input().split())) mops.sort() for i in range(0,n,2): a=0 if mops[i]<=mops[i+1]: a=mops[i+1]-mops[i] ans+=a print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; var mops : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; mops := mops->sort() ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( var a : int := 0 ; if (mops[i+1]->compareTo(mops[i + 1+1])) <= 0 then ( a := mops[i + 1+1] - mops[i+1] ) else skip ; ans := ans + a) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(i)for i in input().split()] a.sort() k=0 i=0 while itoInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; a := a->sort() ; var k : int := 0 ; var i : int := 0 ; while (i->compareTo(n - 1)) < 0 do ( k := k + a[i + 1+1] - a[i+1] ; i := i + 2) ; execute (k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) res=0 for _ in range(n): li=list(input()) for i in li : if i=='+' : res+=1 break elif i=='-' : res-=1 break print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var li : Sequence := ((OclFile["System.in"]).readLine())->characters() ; for i : li do ( if i = '+' then ( res := res + 1 ; break ) else (if i = '-' then ( res := res - 1 ; break ) else skip))) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class GFG : class Node : def __init__(self,n,data): self.children=[None]*n self.data=data def inorder(self,node): if node==None : return total=len(node.children) for i in range(total-1): self.inorder(node.children[i]) print(node.data,end=" ") self.inorder(node.children[total-1]) def main(self): n=3 root=self.Node(n,1) root.children[0]=self.Node(n,2) root.children[1]=self.Node(n,3) root.children[2]=self.Node(n,4) root.children[0].children[0]=self.Node(n,5) root.children[0].children[1]=self.Node(n,6) root.children[0].children[2]=self.Node(n,7) self.inorder(root) ob=GFG() ob.main() ------------------------------------------------------------ OCL File: --------- class GFG { static operation newGFG() : GFG pre: true post: GFG->exists( _x | result = _x ); operation inorder(node : OclAny) pre: true post: true activity: if node = null then ( return ) else skip ; var total : int := (node.children)->size() ; for i : Integer.subrange(0, total - 1-1) do ( self.inorder(node.children[i+1])) ; execute (node.data)->display() ; self.inorder(node.children[total - 1+1]); operation main() pre: true post: true activity: n := 3 ; var root : OclAny := self.Node(n, 1) ; root.children->first() := self.Node(n, 2) ; root.children[1+1] := self.Node(n, 3) ; root.children[2+1] := self.Node(n, 4) ; root.children->first().children->first() := self.Node(n, 5) ; root.children->first().children[1+1] := self.Node(n, 6) ; root.children->first().children[2+1] := self.Node(n, 7) ; self.inorder(root); } class FromPython { operation initialise() pre: true post: true activity: skip ; var ob : GFG := (GFG.newGFG()).initialise() ; ob.main(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=2 def isValid(c,n): X=[0,-1,0,1] Y=[1,0,-1,0] isValid=True for i in range(n): for j in range(n): for k in range(n): newX=i+X[k] newY=j+Y[k] if(newX=0 and newY>=0 and c[newX][newY]==c[i][j]): isValid=false return isValid if __name__=="__main__" : n=2 c=[[1,0],[0,1]] if isValid(c,n): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 2 ; skip ; if __name__ = "__main__" then ( n := 2 ; c := Sequence{Sequence{1}->union(Sequence{ 0 })}->union(Sequence{ Sequence{0}->union(Sequence{ 1 }) }) ; if isValid(c, n) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isValid(c : OclAny, n : OclAny) : OclAny pre: true post: true activity: var X : Sequence := Sequence{0}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{ 1 }))) ; var Y : Sequence := Sequence{1}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{ 0 }))) ; var isValid : boolean := true ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( for k : Integer.subrange(0, n-1) do ( var newX : OclAny := i + X[k+1] ; var newY : OclAny := j + Y[k+1] ; if ((newX->compareTo(n)) < 0 & (newY->compareTo(n)) < 0 & newX >= 0 & newY >= 0 & c[newX+1][newY+1] = c[i+1][j+1]) then ( isValid := false ) else skip))) ; return isValid; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countCubes(a,b): cnt=0 for i in range(a,b+1): for j in range(i+1): if j*j*j>i : break if j*j*j==i : cnt+=1 return cnt if __name__=='__main__' : a=7 b=30 print("Count of Cubes is ",countCubes(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := 7 ; b := 30 ; execute ("Count of Cubes is ")->display() ) else skip; operation countCubes(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; for i : Integer.subrange(a, b + 1-1) do ( for j : Integer.subrange(0, i + 1-1) do ( if (j * j * j->compareTo(i)) > 0 then ( break ) else skip ; if j * j * j = i then ( cnt := cnt + 1 ) else skip)) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find_number(N,K): r="" if(N % 100==0): N+=1 ; r=str(N) else : r=str(N) for i in range(1,K+1): r+="00" return r N=1000 K=2 ; ans=find_number(N,K) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 1000 ; K := 2; ; var ans : OclAny := find_number(N, K) ; execute (ans)->display(); operation find_number(N : OclAny, K : OclAny) : OclAny pre: true post: true activity: var r : String := "" ; if (N mod 100 = 0) then ( N := N + 1; ; r := ("" + ((N))) ) else ( r := ("" + ((N))) ) ; for i : Integer.subrange(1, K + 1-1) do ( r := r + "00") ; return r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() print(s[: 1]+str(len(s)-2)+s[-1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; execute (s.subrange(1,1) + ("" + (((s)->size() - 2))) + s.subrange(-1+1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- li=list(input()) l=len(li) count=0 for i in range(1,l-1): count+=1 C=str(count) print(li[0]+C+li[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var li : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var l : int := (li)->size() ; var count : int := 0 ; for i : Integer.subrange(1, l - 1-1) do ( count := count + 1) ; var C : String := ("" + ((count))) ; execute (li->first() + C + li->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=str(input()) n=str(len(s)-2) st=s[0] ed=s[-1] print(st+n+ed) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; var n : String := ("" + (((s)->size() - 2))) ; var st : OclAny := s->first() ; var ed : OclAny := s->last() ; execute (st + n + ed)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import itertools import sys import copy S=str(input()) print(S[0]+str(len(S)-2)+S[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var S : String := ("" + (((OclFile["System.in"]).readLine()))) ; execute (S->first() + ("" + (((S)->size() - 2))) + S->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=len(a) print(a[0],end="") print(b-2,end="") print(a[b-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : int := (a)->size() ; execute (a->first())->display() ; execute (b - 2)->display() ; execute (a[b - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def subdomainVisits(self,cpdomains): domain_count={} for cpdomain in cpdomains : count,domain=cpdomain.split(' ') sub_domain=domain.split('.') for i in range(len(sub_domain)): curr='.'.join(sub_domain[i :]) domain_count[curr]=domain_count.get(curr,0)+int(count) return[str(v)+' '+k for k,v in domain_count.items()] ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation subdomainVisits(cpdomains : OclAny) : OclAny pre: true post: true activity: var domain_count : OclAny := Set{} ; for cpdomain : cpdomains do ( var count : OclAny := null; var domain : OclAny := null; Sequence{count,domain} := cpdomain.split(' ') ; var sub_domain : OclAny := domain.split('.') ; for i : Integer.subrange(0, (sub_domain)->size()-1) do ( var curr : String := StringLib.sumStringsWithSeparator((sub_domain.subrange(i+1)), '.') ; domain_count->at(curr) := domain_count.get(curr, 0) + ("" + ((count)))->toInteger())) ; return domain_count->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->select(_tuple | true)->collect(_tuple | let k : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in (("" + ((v))) + ' ' + k)); } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=50 def solve(dp,a,low,high,turn): if(low==high): return a[low]*turn if(dp[low][high]!=0): return dp[low][high] dp[low][high]=max(a[low]*turn+solve(dp,a,low+1,high,turn+1),a[high]*turn+solve(dp,a,low,high-1,turn+1)); return dp[low][high] if __name__=="__main__" : arr=[1,3,1,5,2] n=len(arr) dp=[[0 for x in range(MAX)]for y in range(MAX)] print(solve(dp,arr,0,n-1,1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 50 ; skip ; if __name__ = "__main__" then ( var arr : Sequence := Sequence{1}->union(Sequence{3}->union(Sequence{1}->union(Sequence{5}->union(Sequence{ 2 })))) ; var n : int := (arr)->size() ; dp := Integer.subrange(0, MAX-1)->select(y | true)->collect(y | (Integer.subrange(0, MAX-1)->select(x | true)->collect(x | (0)))) ; execute (solve(dp, arr, 0, n - 1, 1))->display() ) else skip; operation solve(dp : OclAny, a : OclAny, low : OclAny, high : OclAny, turn : OclAny) : OclAny pre: true post: true activity: if (low = high) then ( return a[low+1] * turn ) else skip ; if (dp[low+1][high+1] /= 0) then ( return dp[low+1][high+1] ) else skip ; dp[low+1][high+1] := Set{a[low+1] * turn + solve(dp, a, low + 1, high, turn + 1), a[high+1] * turn + solve(dp, a, low, high - 1, turn + 1)}->max(); ; return dp[low+1][high+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) p=0 for i in range(a): z=input() if z=="++X" or z=="X++" : p+=1 if z=="--X" or z=="X--" : p-=1 print(p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : int := 0 ; for i : Integer.subrange(0, a-1) do ( var z : String := (OclFile["System.in"]).readLine() ; if z = "++X" or z = "X++" then ( p := p + 1 ) else skip ; if z = "--X" or z = "X--" then ( p := p - 1 ) else skip) ; execute (p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def stepRequired(n): return bin(94).count('1') if __name__=="__main__" : n=94 print(stepRequired(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 94 ; execute (stepRequired(n))->display() ) else skip; operation stepRequired(n : OclAny) : OclAny pre: true post: true activity: return bin(94)->count('1'); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() i=0 x=0 ans=0 for j in range(1,n): if s[j]==s[i]=='x' : x+=1 else : if x>1 : ans+=x-1 x=0 i=j if x>1 : ans+=x-1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var i : int := 0 ; var x : int := 0 ; var ans : int := 0 ; for j : Integer.subrange(1, n-1) do ( if s[j+1] = s[i+1] & (s[i+1] == 'x') then ( x := x + 1 ) else ( if x > 1 then ( ans := ans + x - 1 ) else skip ; x := 0 ) ; i := j) ; if x > 1 then ( ans := ans + x - 1 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxPrefix(s,t): count=0 for i in range(0,len(t)): if(count==len(s)): break if(t[i]==s[count]): count=count+1 return count S="digger" T="biggerdiagram" print(maxPrefix(S,T)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var S : String := "digger" ; var T : String := "biggerdiagram" ; execute (maxPrefix(S, T))->display(); operation maxPrefix(s : OclAny, t : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, (t)->size()-1) do ( if (count = (s)->size()) then ( break ) else skip ; if (t[i+1] = s[count+1]) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getNumber(n,k): arr=[0]*n ; i=0 ; odd=1 ; while(odd<=n): arr[i]=odd ; i+=1 ; odd+=2 ; even=2 ; while(even<=n): arr[i]=even ; i+=1 ; even+=2 ; return arr[k-1]; if __name__=='__main__' : n=8 ; k=5 ; print(getNumber(n,k)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 8; ; k := 5; ; execute (getNumber(n, k))->display(); ) else skip; operation getNumber(n : OclAny, k : OclAny) pre: true post: true activity: var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; var i : int := 0; ; var odd : int := 1; ; while ((odd->compareTo(n)) <= 0) do ( arr[i+1] := odd; ; i := i + 1; ; odd := odd + 2;) ; var even : int := 2; ; while ((even->compareTo(n)) <= 0) do ( arr[i+1] := even; ; i := i + 1; ; even := even + 2;) ; return arr[k - 1+1];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,k,q=map(int,input().split()) w=list(map(int,input().split())) d=[0]*(n+1) c,x=0,[] for i in range(q): a,b=map(int,input().split()) if a==1 : d[b]=1 if cx[-1]: x.pop() x.append(w[b-1]) x.sort(reverse=True) else : if d[b]==0 : print('NO') elif d[b]==1 : if w[b-1]>=x[-1]: print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var k : OclAny := null; var q : OclAny := null; Sequence{n,k,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var c : OclAny := null; var x : OclAny := null; Sequence{c,x} := Sequence{0,Sequence{}} ; for i : Integer.subrange(0, q-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 1 then ( d[b+1] := 1 ; if (c->compareTo(k)) < 0 then ( c := c + 1 ; execute ((w[b - 1+1]) : x) ; x := x->sort() ) else ( if (w[b - 1+1]->compareTo(x->last())) > 0 then ( x := x->front() ; execute ((w[b - 1+1]) : x) ; x := x->sort() ) else skip ) ) else ( if d[b+1] = 0 then ( execute ('NO')->display() ) else (if d[b+1] = 1 then ( if (w[b - 1+1]->compareTo(x->last())) >= 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) else skip) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- NoF,k,q=map(int,input().split()) friends=[int(x)for x in input().split()] displayed=[] for _ in range(q): type,friend=map(int,input().split()) if type==1 : if len(displayed)collect( _x | (OclType["int"])->apply(_x) ) ; var friends : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var displayed : Sequence := Sequence{} ; for _anon : Integer.subrange(0, q-1) do ( var type : OclAny := null; var friend : OclAny := null; Sequence{type,friend} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if type = 1 then ( if ((displayed)->size()->compareTo(k)) < 0 then ( execute ((friend) : displayed) ; displayed := displayed->sort() ) else ( execute ((friend) : displayed) ; displayed := displayed->sort() ; displayed := displayed.subrange(0+1, k) ) ) else ( execute (if (displayed)->includes(friend) then 'YES' else 'NO' endif)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- NoF,k,q=map(int,input().split()) friends=[int(x)for x in input().split()] displayed=[] for _ in range(q): type,friend=map(int,input().split()) if type==1 : if len(displayed)collect( _x | (OclType["int"])->apply(_x) ) ; var friends : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var displayed : Sequence := Sequence{} ; for _anon : Integer.subrange(0, q-1) do ( var type : OclAny := null; var friend : OclAny := null; Sequence{type,friend} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if type = 1 then ( if ((displayed)->size()->compareTo(k)) < 0 then ( execute ((friend) : displayed) ) else ( execute ((friend) : displayed) ; displayed := displayed->sort() ; displayed := displayed.subrange(0+1, k) ) ) else ( execute (if (displayed)->includes(friend) then 'YES' else 'NO' endif)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from queue import PriorityQueue prioQ=PriorityQueue() N,K,Q=[int(x)for x in input().split()] scores=[int(x)for x in input().split()] for _ in range(Q): command,id=[int(x)for x in input().split()] if command==1 : prioQ.put((scores[id-1],id-1)) if len(prioQ.queue)>K : prioQ.get() else : if(scores[id-1],id-1)in prioQ.queue : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var prioQ : OclAny := PriorityQueue() ; var N : OclAny := null; var K : OclAny := null; var Q : OclAny := null; Sequence{N,K,Q} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var scores : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for _anon : Integer.subrange(0, Q-1) do ( var command : OclAny := null; var id : OclAny := null; Sequence{command,id} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if command = 1 then ( prioQ.put(Sequence{scores[id - 1+1], id - 1}) ; if ((prioQ.queue)->size()->compareTo(K)) > 0 then ( prioQ.get() ) else skip ) else ( if (prioQ.queue)->includes(Sequence{scores[id - 1+1], id - 1}) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import string def main_function(): n,k,q=[int(i)for i in input().split(" ")] t=[int(u)for u in input().split(" ")] id_t=[i for i in range(len(t))] sorted_id_t=sorted(id_t,key=lambda i : t[i]) hash_sorted_id=[0 for i in range(n)] for i in range(len(sorted_id_t)): hash_sorted_id[sorted_id_t[i]]=i is_part_of_list=[False for i in range(n)] current_min=100000000000000000000 current_min_index=-1 counter=0 sorted_list_index=0 for i in range(q): task_id,id=[int(y)for y in input().split(" ")] id-=1 if task_id==1 : if countert[id]: current_min=t[id] current_min_index=id else : if t[id]>t[current_min_index]: is_part_of_list[current_min_index]=False is_part_of_list[id]=True while not is_part_of_list[sorted_id_t[sorted_list_index]]: sorted_list_index+=1 current_min_index=sorted_id_t[sorted_list_index] else : if is_part_of_list[id]: print("YES") else : print("NO") main_function() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; main_function(); operation main_function() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var q : OclAny := null; Sequence{n,k,q} := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var t : Sequence := input().split(" ")->select(u | true)->collect(u | (("" + ((u)))->toInteger())) ; var id_t : Sequence := Integer.subrange(0, (t)->size()-1)->select(i | true)->collect(i | (i)) ; var sorted_id_t : Sequence := id_t->sortedBy($x | (lambda i : OclAny in (t[i+1]))->apply($x)) ; var hash_sorted_id : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, (sorted_id_t)->size()-1) do ( hash_sorted_id[sorted_id_t[i+1]+1] := i) ; var is_part_of_list : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (false)) ; var current_min : double := 100000000000000000000 ; var current_min_index : int := -1 ; var counter : int := 0 ; var sorted_list_index : int := 0 ; for i : Integer.subrange(0, q-1) do ( var task_id : OclAny := null; var id : OclAny := null; Sequence{task_id,id} := input().split(" ")->select(y | true)->collect(y | (("" + ((y)))->toInteger())) ; id := id - 1 ; if task_id = 1 then ( if (counter->compareTo(k)) < 0 then ( is_part_of_list[id+1] := true ; counter := counter + 1 ; if (current_min->compareTo(t[id+1])) > 0 then ( current_min := t[id+1] ; current_min_index := id ) else skip ) else ( if (t[id+1]->compareTo(t[current_min_index+1])) > 0 then ( is_part_of_list[current_min_index+1] := false ; is_part_of_list[id+1] := true ; while not(is_part_of_list[sorted_id_t[sorted_list_index+1]+1]) do ( sorted_list_index := sorted_list_index + 1) ; current_min_index := sorted_id_t[sorted_list_index+1] ) else skip ) ) else ( if is_part_of_list[id+1] then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() ss=["Danil","Olya","Slava","Ann","Nikita"] flag=0 vis={"Danil" : 0,"Olya" : 0,"Slava" : 0,"Ann" : 0,"Nikita" : 0} for i in ss : if s.find(i)!=-1 : vis[i]+=1 head=s.find(i) while s.find(i,head+1)!=-1 : head=s.find(i,head+1) vis[i]+=1 for key in vis : if vis[key]>=1 : flag+=vis[key] if flag==1 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var ss : Sequence := Sequence{"Danil"}->union(Sequence{"Olya"}->union(Sequence{"Slava"}->union(Sequence{"Ann"}->union(Sequence{ "Nikita" })))) ; var flag : int := 0 ; var vis : Map := Map{ "Danil" |-> 0 }->union(Map{ "Olya" |-> 0 }->union(Map{ "Slava" |-> 0 }->union(Map{ "Ann" |-> 0 }->union(Map{ "Nikita" |-> 0 })))) ; for i : ss do ( if s->indexOf(i) - 1 /= -1 then ( vis[i+1] := vis[i+1] + 1 ; var head : int := s->indexOf(i) - 1 ; while s->indexOf(i, head + 1) - 1 /= -1 do ( head := s->indexOf(i, head + 1) - 1 ; vis[i+1] := vis[i+1] + 1) ) else skip) ; for key : vis->keys() do ( if vis[key+1] >= 1 then ( flag := flag + vis[key+1] ) else skip) ; if flag = 1 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() if a.count('Danil')+a.count('Olya')+a.count('Slava')+a.count('Ann')+a.count('Nikita')==1 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; if a->count('Danil') + a->count('Olya') + a->count('Slava') + a->count('Ann') + a->count('Nikita') = 1 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=0 for i in range(a): n=input() if n=='X++' or n=='++X' : b+=1 if n=='--X' or n=='X--' : b-=1 print(b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := 0 ; for i : Integer.subrange(0, a-1) do ( var n : String := (OclFile["System.in"]).readLine() ; if n = 'X++' or n = '++X' then ( b := b + 1 ) else skip ; if n = '--X' or n = 'X--' then ( b := b - 1 ) else skip) ; execute (b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter def main(): n=int(input()) aa=list(map(int,input().split())) cs_a0=Counter(a for i,a in enumerate(aa)if i % 2==0) cs_a1=Counter(a for i,a in enumerate(aa)if i % 2==1) vs_a0=sorted(((v,k)for k,v in cs_a0.items()),reverse=True) vs_a1=sorted(((v,k)for k,v in cs_a1.items()),reverse=True) if vs_a0[0][1]!=vs_a1[0][1]: print(n-vs_a0[0][0]-vs_a1[0][0]) else : res=1<<30 if len(vs_a0)==1 and len(vs_a1)==1 : res=n//2 if len(vs_a0)>1 : res=min(res,n-vs_a0[1][0]-vs_a1[0][0]) if len(vs_a1)>1 : res=min(res,n-vs_a0[0][0]-vs_a1[1][0]) print(res) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var aa : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cs_a0 : OclAny := Counter((argument (test (logical_test (comparison (expr (atom (name a)))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name aa)))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (expr (atom (name i))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 0)))))))))))) ; var cs_a1 : OclAny := Counter((argument (test (logical_test (comparison (expr (atom (name a)))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name aa)))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (expr (atom (name i))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 1)))))))))))) ; var vs_a0 : Sequence := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name v)))))) , (test (logical_test (comparison (expr (atom (name k))))))) )))))) (comp_for for (exprlist (expr (atom (name k))) , (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name cs_a0)) (trailer . (name items) (arguments ( ))))))))}->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var vs_a1 : Sequence := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name v)))))) , (test (logical_test (comparison (expr (atom (name k))))))) )))))) (comp_for for (exprlist (expr (atom (name k))) , (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name cs_a1)) (trailer . (name items) (arguments ( ))))))))}->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; if vs_a0->first()[1+1] /= vs_a1->first()[1+1] then ( execute (n - vs_a0->first()->first() - vs_a1->first()->first())->display() ) else ( var res : int := 1 * (2->pow(30)) ; if (vs_a0)->size() = 1 & (vs_a1)->size() = 1 then ( res := n div 2 ) else skip ; if (vs_a0)->size() > 1 then ( res := Set{res, n - vs_a0[1+1]->first() - vs_a1->first()->first()}->min() ) else skip ; if (vs_a1)->size() > 1 then ( res := Set{res, n - vs_a0->first()->first() - vs_a1[1+1]->first()}->min() ) else skip ; execute (res)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline if __name__=='__main__' : inp=input() co=0 if 'Danil' in inp : co+=inp.count('Danil') if 'Olya' in inp : co+=inp.count("Olya") if 'Slava' in inp : co+=inp.count("Slava") if 'Ann' in inp : co+=inp.count("Ann") if 'Nikita' in inp : co+=inp.count("Nikita") print("YES" if co==1 else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; if __name__ = '__main__' then ( var inp : String := (OclFile["System.in"]).readLine() ; var co : int := 0 ; if (inp)->characters()->includes('Danil') then ( co := co + inp->count('Danil') ) else skip ; if (inp)->characters()->includes('Olya') then ( co := co + inp->count("Olya") ) else skip ; if (inp)->characters()->includes('Slava') then ( co := co + inp->count("Slava") ) else skip ; if (inp)->characters()->includes('Ann') then ( co := co + inp->count("Ann") ) else skip ; if (inp)->characters()->includes('Nikita') then ( co := co + inp->count("Nikita") ) else skip ; execute (if co = 1 then "YES" else "NO" endif)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() o=s.count('Olya') x=s.count('Slava') a=s.count('Ann') d=s.count('Danil') n=s.count('Nikita') if(o+x+a+d+n)==1 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var o : int := s->count('Olya') ; var x : int := s->count('Slava') ; var a : int := s->count('Ann') ; var d : int := s->count('Danil') ; var n : int := s->count('Nikita') ; if (o + x + a + d + n) = 1 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() l=["Danil","Olya","Slava","Ann","Nikita"] count=0 if(any(i in s for i in l)): for i in l : if(i in s): count+=1 if(count>1 or s.count(i)>1): print("NO") exit(0) print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var l : Sequence := Sequence{"Danil"}->union(Sequence{"Olya"}->union(Sequence{"Slava"}->union(Sequence{"Ann"}->union(Sequence{ "Nikita" })))) ; var count : int := 0 ; if (((argument (test (logical_test (comparison (comparison (expr (atom (name i)))) in (comparison (expr (atom (name s))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name l))))))))->exists( _x | _x = true )) then ( for i : l do ( if ((s)->characters()->includes(i)) then ( count := count + 1 ; if (count > 1 or s->count(i) > 1) then ( execute ("NO")->display() ; exit(0) ) else skip ) else skip) ; execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lineCounter=0 whiteCounter=0 blackCounter=0 while lineCounter!=8 : line=input() lineCounter=lineCounter+1 for i in line : if i=="Q" : whiteCounter=whiteCounter+9 elif i=="R" : whiteCounter=whiteCounter+5 elif i=="B" : whiteCounter=whiteCounter+3 elif i=="N" : whiteCounter=whiteCounter+3 elif i=="P" : whiteCounter=whiteCounter+1 elif i=="q" : blackCounter=blackCounter+9 elif i=="r" : blackCounter=blackCounter+5 elif i=="b" : blackCounter=blackCounter+3 elif i=="n" : blackCounter=blackCounter+3 elif i=="p" : blackCounter=blackCounter+1 if whiteCounter>blackCounter : print("White") if blackCounter>whiteCounter : print("Black") if blackCounter==whiteCounter : print("Draw") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lineCounter : int := 0 ; var whiteCounter : int := 0 ; var blackCounter : int := 0 ; while lineCounter /= 8 do ( var line : String := (OclFile["System.in"]).readLine() ; lineCounter := lineCounter + 1 ; for i : line->characters() do ( if i = "Q" then ( whiteCounter := whiteCounter + 9 ) else (if i = "R" then ( whiteCounter := whiteCounter + 5 ) else (if i = "B" then ( whiteCounter := whiteCounter + 3 ) else (if i = "N" then ( whiteCounter := whiteCounter + 3 ) else (if i = "P" then ( whiteCounter := whiteCounter + 1 ) else (if i = "q" then ( blackCounter := blackCounter + 9 ) else (if i = "r" then ( blackCounter := blackCounter + 5 ) else (if i = "b" then ( blackCounter := blackCounter + 3 ) else (if i = "n" then ( blackCounter := blackCounter + 3 ) else (if i = "p" then ( blackCounter := blackCounter + 1 ) else skip ) ) ) ) ) ) ) ) ) )) ; if (whiteCounter->compareTo(blackCounter)) > 0 then ( execute ("White")->display() ) else skip ; if (blackCounter->compareTo(whiteCounter)) > 0 then ( execute ("Black")->display() ) else skip ; if blackCounter = whiteCounter then ( execute ("Draw")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- values={"." : 0,"q" : 9,"r" : 5,"b" : 3,"n" : 3,"p" : 1,"k" : 0,"Q" :-9,"R" :-5,"B" :-3,"N" :-3,"P" :-1,"K" : 0} points=sum(map(values.__getitem__,open(0).read().replace("\n",""))) print("White" if points<0 else "Black" if points else "Draw") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var values : Map := Map{ "." |-> 0 }->union(Map{ "q" |-> 9 }->union(Map{ "r" |-> 5 }->union(Map{ "b" |-> 3 }->union(Map{ "n" |-> 3 }->union(Map{ "p" |-> 1 }->union(Map{ "k" |-> 0 }->union(Map{ "Q" |-> -9 }->union(Map{ "R" |-> -5 }->union(Map{ "B" |-> -3 }->union(Map{ "N" |-> -3 }->union(Map{ "P" |-> -1 }->union(Map{ "K" |-> 0 })))))))))))) ; var points : OclAny := ((open(0).readAll().replace("\n", ""))->collect( _x | (values.__getitem__)->apply(_x) ))->sum() ; execute (if points < 0 then "White" else if points then "Black" else "Draw" endif endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lookup={"." : 0,"q" : 9,"Q" :-9,"r" : 5,"R" :-5,"n" : 3,"N" :-3,"b" : 3,"B" :-3,"p" : 1,"P" :-1,"k" : 0,"K" :-0} points=sum(map(lookup.__getitem__,open(0).read().replace("\n",""))) print("White" if points<0 else "Black" if points else "Draw") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lookup : Map := Map{ "." |-> 0 }->union(Map{ "q" |-> 9 }->union(Map{ "Q" |-> -9 }->union(Map{ "r" |-> 5 }->union(Map{ "R" |-> -5 }->union(Map{ "n" |-> 3 }->union(Map{ "N" |-> -3 }->union(Map{ "b" |-> 3 }->union(Map{ "B" |-> -3 }->union(Map{ "p" |-> 1 }->union(Map{ "P" |-> -1 }->union(Map{ "k" |-> 0 }->union(Map{ "K" |-> -0 })))))))))))) ; var points : OclAny := ((open(0).readAll().replace("\n", ""))->collect( _x | (lookup.__getitem__)->apply(_x) ))->sum() ; execute (if points < 0 then "White" else if points then "Black" else "Draw" endif endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lookup={"." : 0,"q" : 9,"Q" :-9,"r" : 5,"R" :-5,"n" : 3,"N" :-3,"b" : 3,"B" :-3,"p" : 1,"P" :-1,"k" : 0,"K" :-0} points=sum(map(lookup.__getitem__,open(0).read().replace("\n",""))) print("White" if points<0 else "Black" if points else "Draw") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lookup : Map := Map{ "." |-> 0 }->union(Map{ "q" |-> 9 }->union(Map{ "Q" |-> -9 }->union(Map{ "r" |-> 5 }->union(Map{ "R" |-> -5 }->union(Map{ "n" |-> 3 }->union(Map{ "N" |-> -3 }->union(Map{ "b" |-> 3 }->union(Map{ "B" |-> -3 }->union(Map{ "p" |-> 1 }->union(Map{ "P" |-> -1 }->union(Map{ "k" |-> 0 }->union(Map{ "K" |-> -0 })))))))))))) ; var points : OclAny := ((open(0).readAll().replace("\n", ""))->collect( _x | (lookup.__getitem__)->apply(_x) ))->sum() ; execute (if points < 0 then "White" else if points then "Black" else "Draw" endif endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- black={'q' : 9,'r' : 5,'b' : 3,'n' : 3,'p' : 1,'k' : 0} white={'Q' : 9,'R' : 5,'B' : 3,'N' : 3,'P' : 1,'K' : 0} b=0 w=0 doska=''.join([input()for _ in range(8)]) for i in doska : if i in black : b+=black[i] elif i in white : w+=white[i] if b==w : print("Draw") else : print(["White","Black"][b>w]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var black : Map := Map{ 'q' |-> 9 }->union(Map{ 'r' |-> 5 }->union(Map{ 'b' |-> 3 }->union(Map{ 'n' |-> 3 }->union(Map{ 'p' |-> 1 }->union(Map{ 'k' |-> 0 }))))) ; var white : Map := Map{ 'Q' |-> 9 }->union(Map{ 'R' |-> 5 }->union(Map{ 'B' |-> 3 }->union(Map{ 'N' |-> 3 }->union(Map{ 'P' |-> 1 }->union(Map{ 'K' |-> 0 }))))) ; var b : int := 0 ; var w : int := 0 ; var doska : String := StringLib.sumStringsWithSeparator((Integer.subrange(0, 8-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine()))), '') ; for i : doska->characters() do ( if (black)->includes(i) then ( b := b + black[i+1] ) else (if (white)->includes(i) then ( w := w + white[i+1] ) else skip)) ; if b = w then ( execute ("Draw")->display() ) else ( execute (Sequence{"White"}->union(Sequence{ "Black" })->select((b->compareTo(w)) > 0))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numberofDigits(n): cnt=0 while n>0 : cnt+=1 n//=10 return cnt def cal(num): digit=numberofDigits(num) powTen=pow(10,digit-1) for i in range(digit-1): firstDigit=num//powTen left=(num*10+firstDigit-(firstDigit*powTen*10)) print(left,end=" ") num=left num=1445 cal(num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; num := 1445 ; cal(num); operation numberofDigits(n : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; while n > 0 do ( cnt := cnt + 1 ; n := n div 10) ; return cnt; operation cal(num : OclAny) pre: true post: true activity: var digit : OclAny := numberofDigits(num) ; var powTen : double := (10)->pow(digit - 1) ; for i : Integer.subrange(0, digit - 1-1) do ( var firstDigit : int := num div powTen ; var left : double := (num * 10 + firstDigit - (firstDigit * powTen * 10)) ; execute (left)->display() ; num := left); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(s): m=dict() for i in range(len(s)): if s[i]in m : m[s[i]]=m[s[i]]+1 else : m[s[i]]=1 new_string="" for i in range(len(s)): if m[s[i]]% 2==0 : continue new_string=new_string+s[i] print(new_string) if __name__=='__main__' : s="aabbbddeeecc" solve(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( s := "aabbbddeeecc" ; solve(s) ) else skip; operation solve(s : OclAny) pre: true post: true activity: var m : Map := (arguments ( )) ; for i : Integer.subrange(0, (s)->size()-1) do ( if (m)->includes(s[i+1]) then ( m[s[i+1]+1] := m[s[i+1]+1] + 1 ) else ( m[s[i+1]+1] := 1 )) ; var new_string : String := "" ; for i : Integer.subrange(0, (s)->size()-1) do ( if m[s[i+1]+1] mod 2 = 0 then ( continue ) else skip ; new_string := new_string + s[i+1]) ; execute (new_string)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=list(int(i)for i in input().split()) a=[] b=[] for i in range(0,n): if i % 2==0 : a.append(x[i]) else : b.append(x[i]) cnta=[0]*(100002+1) cntb=[0]*(100002+1) vala=0 vala1=0 maxCnta=0 maxCnta1=0 for i in a : cnta[i]+=1 for i in a : if maxCntatoInteger() ; var x : Sequence := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ; var a : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if i mod 2 = 0 then ( execute ((x[i+1]) : a) ) else ( execute ((x[i+1]) : b) )) ; var cnta : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (100002 + 1)) ; var cntb : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (100002 + 1)) ; var vala : int := 0 ; var vala1 : int := 0 ; var maxCnta : int := 0 ; var maxCnta1 : int := 0 ; for i : a do ( cnta[i+1] := cnta[i+1] + 1) ; for i : a do ( if (maxCnta->compareTo(cnta[i+1])) < 0 then ( vala := i ; maxCnta := cnta[i+1] ) else skip) ; for i : a do ( if (maxCnta1->compareTo(cnta[i+1])) < 0 & vala /= i then ( maxCnta1 := cnta[i+1] ; vala1 := i ) else skip) ; var valb : int := 0 ; var valb1 : int := 0 ; var maxCntb : int := 0 ; var maxCntb1 : int := 0 ; for i : b do ( cntb[i+1] := cntb[i+1] + 1) ; for i : b do ( if (maxCntb->compareTo(cntb[i+1])) < 0 then ( valb := i ; maxCntb := cntb[i+1] ) else skip) ; for i : b do ( if (maxCntb1->compareTo(cntb[i+1])) < 0 & valb /= i then ( maxCntb1 := cntb[i+1] ; valb1 := i ) else skip) ; if valb /= vala then ( var res : int := 0 ; for i : a do ( if i /= vala then ( res := res + 1 ) else skip) ; for i : b do ( if i /= valb then ( res := res + 1 ) else skip) ; execute (res)->display() ) else ( var resa : int := 0 ; var resb : int := 0 ; var resa1 : int := 0 ; var resb1 : int := 0 ; for i : a do ( if i /= vala then ( resa := resa + 1 ) else skip ; if i /= vala1 then ( resa1 := resa1 + 1 ) else skip) ; for i : b do ( if i /= valb then ( resb := resb + 1 ) else skip ; if i /= valb1 then ( resb1 := resb1 + 1 ) else skip) ; execute (Set{resa + resb1, resa1 + resb}->min())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) c=0 for i in range(a): x=str(input()) if x[1]=='+' : c=c+1 else : c=c-1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := 0 ; for i : Integer.subrange(0, a-1) do ( var x : String := ("" + (((OclFile["System.in"]).readLine()))) ; if x[1+1] = '+' then ( c := c + 1 ) else ( c := c - 1 )) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nCr(n,r): if(n==r): return 1 if(r==0): return 1 return nCr(n-1,r-1)+nCr(n-1,r) def factorial(n): res=1 if(n<=1): return res for i in range(1,n+1): res*=i return res def stirlingNumber(r,n): if(r==n): return 1 if(n==0): return 0 if(n==r-1): return nCr(r,2) if(r-n==1): return factorial(r-1) return(stirlingNumber(r-1,n-1)+(r-1)*stirlingNumber(r-1,n)) r,n=9,2 print(stirlingNumber(r,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; Sequence{r,n} := Sequence{9,2} ; execute (stirlingNumber(r, n))->display(); operation nCr(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: if (n = r) then ( return 1 ) else skip ; if (r = 0) then ( return 1 ) else skip ; return nCr(n - 1, r - 1) + nCr(n - 1, r); operation factorial(n : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; if (n <= 1) then ( return res ) else skip ; for i : Integer.subrange(1, n + 1-1) do ( res := res * i) ; return res; operation stirlingNumber(r : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (r = n) then ( return 1 ) else skip ; if (n = 0) then ( return 0 ) else skip ; if (n = r - 1) then ( return nCr(r, 2) ) else skip ; if (r - n = 1) then ( return factorial(r - 1) ) else skip ; return (stirlingNumber(r - 1, n - 1) + (r - 1) * stirlingNumber(r - 1, n)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split(" "))) a.sort() if sum(a)/n>=4.5 : print(0) else : c=0 for i in range(n): a[i]=5 c+=1 if sum(a)/n>=4.5 : break print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; if (a)->sum() / n >= 4.5 then ( execute (0)->display() ) else ( var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( a[i+1] := 5 ; c := c + 1 ; if (a)->sum() / n >= 4.5 then ( break ) else skip) ; execute (c)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=0 k=int(input()) a=input().split() a=[int(i)for i in a] a.sort() while sum(a)/k<4.5 : a[c]=5 c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : int := 0 ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := input().split() ; a := a->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; a := a->sort() ; while (a)->sum() / k < 4.5 do ( a[c+1] := 5 ; c := c + 1) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=0 k=input() c2,c3,c4,c5=0,0,0,0 for val in input().split(): if val=='2' : c2+=1 elif val=='3' : c3+=1 elif val=='4' : c4+=1 else : c5+=1 while(c2*2+c3*3+c4*4+c5*5)/(c2+c3+c4+c5)<4.5 : if c2>0 : c2-=1 elif c3>0 : c3-=1 elif c4>0 : c4-=1 c+=1 c5+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : int := 0 ; var k : String := (OclFile["System.in"]).readLine() ; var c2 : OclAny := null; var c3 : OclAny := null; var c4 : OclAny := null; var c5 : OclAny := null; Sequence{c2,c3,c4,c5} := Sequence{0,0,0,0} ; for val : input().split() do ( if val = '2' then ( c2 := c2 + 1 ) else (if val = '3' then ( c3 := c3 + 1 ) else (if val = '4' then ( c4 := c4 + 1 ) else ( c5 := c5 + 1 ) ) ) ) ; while (c2 * 2 + c3 * 3 + c4 * 4 + c5 * 5) / (c2 + c3 + c4 + c5) < 4.5 do ( if c2 > 0 then ( c2 := c2 - 1 ) else (if c3 > 0 then ( c3 := c3 - 1 ) else (if c4 > 0 then ( c4 := c4 - 1 ) else skip ) ) ; c := c + 1 ; c5 := c5 + 1) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) a=list(map(int,input().split())) a.sort() s=sum(a) u=4*n+n//2+n % 2 ans=0 for i in a : if not stoInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var s : OclAny := (a)->sum() ; var u : int := 4 * n + n div 2 + n mod 2 ; var ans : int := 0 ; for i : a do ( if not((s->compareTo(u)) < 0) then ( break ) else skip ; ans := ans + 1 ; s := s + 5 - i) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) if l.count(5)==n or sum(l)/n>=4.5 : print(0) else : l.sort() c=0 for i in range(n): l[i]=5 c+=1 if sum(l)/n>=4.5 : break print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if l->count(5) = n or (l)->sum() / n >= 4.5 then ( execute (0)->display() ) else ( l := l->sort() ; var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( l[i+1] := 5 ; c := c + 1 ; if (l)->sum() / n >= 4.5 then ( break ) else skip) ; execute (c)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def getFirstSetBitPos(n): return(int)(math.log(n &-n)/math.log(2))+1 def previousSmallerInteger(n): pos=getFirstSetBitPos(n) return(n & ~(1<<(pos-1))) n=25 print("Previous small Integer=",previousSmallerInteger(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 25 ; execute ("Previous small Integer=")->display(); operation getFirstSetBitPos(n : OclAny) : OclAny pre: true post: true activity: return (OclType["int"])((MathLib.bitwiseAnd(n, -n))->log() / (2)->log()) + 1; operation previousSmallerInteger(n : OclAny) : OclAny pre: true post: true activity: var pos : OclAny := getFirstSetBitPos(n) ; return (MathLib.bitwiseAnd(n, MathLib.bitwiseNot((1 * (2->pow((pos - 1))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100 def printPrincipalDiagonal(mat,n): print("Principal Diagonal: ",end="") for i in range(n): for j in range(n): if(i==j): print(mat[i][j],end=",") print() def printSecondaryDiagonal(mat,n): print("Secondary Diagonal: ",end="") for i in range(n): for j in range(n): if((i+j)==(n-1)): print(mat[i][j],end=",") print() n=4 a=[[1,2,3,4],[5,6,7,8],[1,2,3,4],[5,6,7,8]] printPrincipalDiagonal(a,n) printSecondaryDiagonal(a,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 100 ; skip ; skip ; n := 4 ; var a : Sequence := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })))}->union(Sequence{Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 8 })))}->union(Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })))}->union(Sequence{ Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 8 }))) }))) ; printPrincipalDiagonal(a, n) ; printSecondaryDiagonal(a, n); operation printPrincipalDiagonal(mat : OclAny, n : OclAny) pre: true post: true activity: execute ("Principal Diagonal: ")->display() ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if (i = j) then ( execute (mat[i+1][j+1])->display() ) else skip)) ; execute (->display(); operation printSecondaryDiagonal(mat : OclAny, n : OclAny) pre: true post: true activity: execute ("Secondary Diagonal: ")->display() ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if ((i + j) = (n - 1)) then ( execute (mat[i+1][j+1])->display() ) else skip)) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100 ; def printPrincipalDiagonal(mat,n): print("Principal Diagonal: ",end=""); for i in range(n): print(mat[i][i],end=","); print(); def printSecondaryDiagonal(mat,n): print("Secondary Diagonal: ",end=""); for i in range(n): print(mat[i][n-i-1],end=","); print(); if __name__=='__main__' : n=4 ; a=[[1,2,3,4],[5,6,7,8],[1,2,3,4],[5,6,7,8]]; printPrincipalDiagonal(a,n); printSecondaryDiagonal(a,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 100; ; skip ; skip ; if __name__ = '__main__' then ( n := 4; ; var a : Sequence := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })))}->union(Sequence{Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 8 })))}->union(Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })))}->union(Sequence{ Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 8 }))) }))); ; printPrincipalDiagonal(a, n); ; printSecondaryDiagonal(a, n); ) else skip; operation printPrincipalDiagonal(mat : OclAny, n : OclAny) pre: true post: true activity: execute ("Principal Diagonal: ")->display(); ; for i : Integer.subrange(0, n-1) do ( execute (mat[i+1][i+1])->display();) ; execute (->display();; operation printSecondaryDiagonal(mat : OclAny, n : OclAny) pre: true post: true activity: execute ("Secondary Diagonal: ")->display(); ; for i : Integer.subrange(0, n-1) do ( execute (mat[i+1][n - i - 1+1])->display();) ; execute (->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dekoboko(n : int,v : list)->int : o,e={},{} for i,vv in enumerate(v): if i % 2==0 : if vv not in e : e[vv]=1 else : e[vv]+=1 else : if vv not in o : o[vv]=1 else : o[vv]+=1 ol=sorted(o.items(),key=lambda x :-x[1]) el=sorted(e.items(),key=lambda x :-x[1]) if ol[0][0]==el[0][0]: if len(ol)>1 : if ol[1][1]>el[1][1]: ol[0],ol[1]=ol[1],ol[0] else : el[0],el[1]=el[1],el[0] else : el.append((0,0)) el[0],el[1]=el[1],el[0] return sum(v for _,v in ol[1 :])+sum(v for _,v in el[1 :]) if __name__=="__main__" : n=int(input()) v=map(int,input().split()) ans=dekoboko(n,v) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var v : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : OclAny := dekoboko(n, v) ; execute (ans)->display() ) else skip; operation dekoboko(n : int, v : Sequence(OclAny)) : int pre: true post: true activity: var o : OclAny := null; var e : OclAny := null; Sequence{o,e} := Sequence{Set{},Set{}} ; for _tuple : Integer.subrange(1, (v)->size())->collect( _indx | Sequence{_indx-1, (v)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var vv : OclAny := _tuple->at(_indx); if i mod 2 = 0 then ( if (e)->excludes(vv) then ( e[vv+1] := 1 ) else ( e[vv+1] := e[vv+1] + 1 ) ) else ( if (o)->excludes(vv) then ( o[vv+1] := 1 ) else ( o[vv+1] := o[vv+1] + 1 ) )) ; var ol : Sequence := o->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sortedBy($x | (lambda x : OclAny in (-x[1+1]))->apply($x)) ; var el : Sequence := e->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sortedBy($x | (lambda x : OclAny in (-x[1+1]))->apply($x)) ; if ol->first()->first() = el->first()->first() then ( if (ol)->size() > 1 then ( if (ol[1+1][1+1]->compareTo(el[1+1][1+1])) > 0 then ( var ol->first() : OclAny := null; var ol[1+1] : OclAny := null; Sequence{ol->first(),ol[1+1]} := Sequence{ol[1+1],ol->first()} ) else ( var el->first() : OclAny := null; var el[1+1] : OclAny := null; Sequence{el->first(),el[1+1]} := Sequence{el[1+1],el->first()} ) ) else ( execute ((Sequence{0, 0}) : el) ; var el->first() : OclAny := null; var el[1+1] : OclAny := null; Sequence{el->first(),el[1+1]} := Sequence{el[1+1],el->first()} ) ) else skip ; return ((argument (test (logical_test (comparison (expr (atom (name v)))))) (comp_for for (exprlist (expr (atom (name _))) , (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name ol)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))))))))->sum() + ((argument (test (logical_test (comparison (expr (atom (name v)))))) (comp_for for (exprlist (expr (atom (name _))) , (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name el)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))))))))->sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): n,m=map(int,input().split()) print("Burenka" if(n+m & 1)else "Tonya") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if (MathLib.bitwiseAnd(n + m, 1)) then "Burenka" else "Tonya" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=0 for i in range(n): st=input() if st[1]=="+" : x+=1 else : x-=1 print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := 0 ; for i : Integer.subrange(0, n-1) do ( var st : String := (OclFile["System.in"]).readLine() ; if st[1+1] = "+" then ( x := x + 1 ) else ( x := x - 1 )) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=map(int,input().split()) if(n+m)% 2==0 : print("Tonya") else : print("Burenka") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (n + m) mod 2 = 0 then ( execute ("Tonya")->display() ) else ( execute ("Burenka")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for a in[*open(0)][1 :]: print(('Tonya','Burenka')[sum(map(int,a.split()))% 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for a : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( execute (Sequence{'Tonya', 'Burenka'}[((a.split())->collect( _x | (OclType["int"])->apply(_x) ))->sum() mod 2+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b=map(int,input().split()) print("Tonya" if a % 2==b % 2 else "Burenka") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if a mod 2 = b mod 2 then "Tonya" else "Burenka" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n,m=map(int,input().split()) if(n+m)% 2==0 : print('Tonya') else : print('Burenka') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (n + m) mod 2 = 0 then ( execute ('Tonya')->display() ) else ( execute ('Burenka')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import product s=input() n=len(s) if n==1 : print(int(s)) exit() plus_list=list(product([0,1],repeat=n-1)) ans=0 for plus in plus_list : next=0 for i in range(n-1): if plus[i]==1 : temp=s[next : i+1] ans+=int(temp) next=i+1 if i==n-2 : temp=int(s[next :]) ans+=temp print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : String := (OclFile["System.in"]).readLine() ; var n : int := (s)->size() ; if n = 1 then ( execute (("" + ((s)))->toInteger())->display() ; exit() ) else skip ; var plus_list : Sequence := (product(Sequence{0}->union(Sequence{ 1 }), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1))))))))))) ; var ans : int := 0 ; for plus : plus_list do ( var next : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if plus[i+1] = 1 then ( var temp : OclAny := s.subrange(next+1, i + 1) ; ans := ans + ("" + ((temp)))->toInteger() ; next := i + 1 ) else skip ; if i = n - 2 then ( temp := ("" + ((s.subrange(next+1))))->toInteger() ; ans := ans + temp ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() total_sum=0 def pros(last_str,cur,remain): global total_sum if len(remain)==1 : total_sum+=cur+int(last_str+remain[0]) else : pros(last_str+remain[0],cur,remain[1 :]) pros('',cur+int(last_str+remain[0]),remain[1 :]) pros('',0,S) print(total_sum) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute total_sum : OclAny; operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var total_sum : int := 0 ; skip ; pros('', 0, S) ; execute (total_sum)->display(); operation pros(last_str : OclAny, cur : OclAny, remain : OclAny) pre: true post: true activity: skip ; if (remain)->size() = 1 then ( total_sum := total_sum + cur + ("" + ((last_str + remain->first())))->toInteger() ) else ( pros(last_str + remain->first(), cur, remain->tail()) ; pros('', cur + ("" + ((last_str + remain->first())))->toInteger(), remain->tail()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() n=len(s) ans=[] for i in range(2**(n-1)): test="" num=str(bin(i))[2 :].zfill(n-1) for j in range(n-1): test+=s[j] if num[j]=='1' : test+='+' test+=s[-1] ans.append(eval(test)) print(sum(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var n : int := (s)->size() ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, (2)->pow((n - 1))-1) do ( var test : String := "" ; var num : OclAny := OclType["String"](bin(i)).subrange(2+1).zfill(n - 1) ; for j : Integer.subrange(0, n - 1-1) do ( test := test + s[j+1] ; if num[j+1] = '1' then ( test := test + '+' ) else skip) ; test := test + s->last() ; execute ((test) : ans)) ; execute ((ans)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter,defaultdict,deque import sys,heapq,bisect,math,itertools,string,queue sys.setrecursionlimit(10**8) mod=10**9+7 def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int,sys.stdin.readline().split())) def inpl_str(): return list(sys.stdin.readline().split()) def inpln(n): return list(int(sys.stdin.readline())for i in range(n)) s=input() n=len(s) ans=0 for flag in itertools.product([0,1],repeat=n-1): cnt=int(s[-1]) c=0 for i,ff in enumerate(flag): if ff : cnt+=int(s[n-i-2]) c=0 else : cnt+=int(s[n-i-2])*10**(c+1) c+=1 ans+=cnt print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; var s : String := (OclFile["System.in"]).readLine() ; n := (s)->size() ; var ans : int := 0 ; for flag : itertools.product(Sequence{0}->union(Sequence{ 1 }), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) do ( var cnt : int := ("" + ((s->last())))->toInteger() ; var c : int := 0 ; for _tuple : Integer.subrange(1, (flag)->size())->collect( _indx | Sequence{_indx-1, (flag)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var ff : OclAny := _tuple->at(_indx); if ff then ( cnt := cnt + ("" + ((s[n - i - 2+1])))->toInteger() ; c := 0 ) else ( cnt := cnt + ("" + ((s[n - i - 2+1])))->toInteger() * (10)->pow((c + 1)) ; c := c + 1 )) ; ans := ans + cnt) ; execute (ans)->display(); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inpl() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inpl_str() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split()); operation inpln(n : OclAny) : OclAny pre: true post: true activity: return ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin)) (trailer . (name readline) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections n=int(input().strip()) vs=[int(s)for s in input().strip().split()] e=[vs[i*2]for i in range(n//2)] o=[vs[i*2+1]for i in range(n//2)] e_counter=collections.Counter(e).most_common() o_counter=collections.Counter(o).most_common() e1,e1_count=e_counter[0] try : e2,e2_count=e_counter[1] except IndexError : e2_count=0 o1,o1_count=o_counter[0] try : o2,o2_count=o_counter[1] except IndexError : o2_count=0 if e1!=o1 : keep_num_count=e1_count+o1_count else : keep_num_count=e1_count+o2_count if keep_num_counttrim())))->toInteger() ; var vs : Sequence := input()->trim().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; var e : Sequence := Integer.subrange(0, n div 2-1)->select(i | true)->collect(i | (vs[i * 2+1])) ; var o : Sequence := Integer.subrange(0, n div 2-1)->select(i | true)->collect(i | (vs[i * 2 + 1+1])) ; var e_counter : OclAny := collections.Counter(e).most_common() ; var o_counter : OclAny := collections.Counter(o).most_common() ; var e1 : OclAny := null; var e1_count : OclAny := null; Sequence{e1,e1_count} := e_counter->first() ; try ( var e2 : OclAny := null; var e2_count : OclAny := null; Sequence{e2,e2_count} := e_counter[1+1]) (except_clause except (test (logical_test (comparison (expr (atom (name IndexError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name e2_count)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))))) ; var o1 : OclAny := null; var o1_count : OclAny := null; Sequence{o1,o1_count} := o_counter->first() ; try ( var o2 : OclAny := null; var o2_count : OclAny := null; Sequence{o2,o2_count} := o_counter[1+1]) (except_clause except (test (logical_test (comparison (expr (atom (name IndexError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name o2_count)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))))) ; if e1 /= o1 then ( var keep_num_count : OclAny := e1_count + o1_count ) else ( keep_num_count := e1_count + o2_count ; if (keep_num_count->compareTo(e2_count + o1_count)) < 0 then ( keep_num_count := e2_count + o1_count ) else skip ) ; execute (n - keep_num_count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() n=len(S)-1 comb=[[[]for i in range(n+1)]for j in range(n+1)] for i in range(1,n+1): for j in range(1,n+1): if i>=1 and j==1 : comb[i][j]=[[k]for k in range(1,i+1)] elif i==j : comb[i][j]=[[k for k in range(1,i+1)]] elif i>j : for m in range(len(comb[i-1][j-1])): comb[i][j]+=[comb[i-1][j-1][m]+[i]] comb[i][j]+=comb[i-1][j] s=0 for i in range(1,n+1): cut_l=comb[n][i] for j in range(len(cut_l)): cut=[0]+cut_l[j]+[n+1] lis=[] for k in range(len(cut)-1): lis.append(int(S[cut[k]: cut[k+1]])) s+=sum(lis) print(s+int(S)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var n : double := (S)->size() - 1 ; var comb : Sequence := Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Sequence{})))) ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, n + 1-1) do ( if i >= 1 & j = 1 then ( comb[i+1][j+1] := Integer.subrange(1, i + 1-1)->select(k | true)->collect(k | (Sequence{ k })) ) else (if i = j then ( comb[i+1][j+1] := Sequence{ Integer.subrange(1, i + 1-1)->select(k | true)->collect(k | (k)) } ) else (if (i->compareTo(j)) > 0 then ( for m : Integer.subrange(0, (comb[i - 1+1][j - 1+1])->size()-1) do ( comb[i+1][j+1] := comb[i+1][j+1] + Sequence{ comb[i - 1+1][j - 1+1][m+1]->union(Sequence{ i }) }) ; comb[i+1][j+1] := comb[i+1][j+1] + comb[i - 1+1][j+1] ) else skip ) ) )) ; var s : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( var cut_l : OclAny := comb[n+1][i+1] ; for j : Integer.subrange(0, (cut_l)->size()-1) do ( var cut : Sequence := Sequence{ 0 }->union(cut_l[j+1])->union(Sequence{ n + 1 }) ; var lis : Sequence := Sequence{} ; for k : Integer.subrange(0, (cut)->size() - 1-1) do ( execute ((("" + ((S.subrange(cut[k+1]+1, cut[k + 1+1]))))->toInteger()) : lis)) ; s := s + (lis)->sum())) ; execute (s + ("" + ((S)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def minXOR(arr,n): arr.sort() minXor=int(sys.float_info.max) val=0 for i in range(0,n-1): val=arr[i]^ arr[i+1]; minXor=min(minXor,val); return minXor arr=[9,5,3] n=len(arr) print(minXOR(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{9}->union(Sequence{5}->union(Sequence{ 3 })) ; n := (arr)->size() ; execute (minXOR(arr, n))->display(); operation minXOR(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var minXor : int := ("" + ((((trailer . (name float_info))).max)))->toInteger() ; var val : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( val := MathLib.bitwiseXor(arr[i+1], arr[i + 1+1]); ; minXor := Set{minXor, val}->min();) ; return minXor; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cases=int(input()) for i in range(cases): a,b,c,d=map(int,input().split()) print(max(a+b,c+d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cases : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, cases-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{a + b, c + d}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) reste=a % 4 if reste==0 : print(1,"A") elif reste==1 : print(0,"A") elif reste==2 : print(1,"B") elif reste==3 : print(2,"A") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var reste : int := a mod 4 ; if reste = 0 then ( execute (1)->display() ) else (if reste = 1 then ( execute (0)->display() ) else (if reste = 2 then ( execute (1)->display() ) else (if reste = 3 then ( execute (2)->display() ) else skip ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) f=x % 4 if f==1 : print(0,"A") elif f==2 : print(1,"B") elif f==3 : print(2,"A") else : print(1,"A") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var f : int := x mod 4 ; if f = 1 then ( execute (0)->display() ) else (if f = 2 then ( execute (1)->display() ) else (if f = 3 then ( execute (2)->display() ) else ( execute (1)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 4==1 : print('0','A') if n % 4==3 : if(n+1)% 4==1 : print('1','A') elif(n+2)% 4==1 : print('2','A') else : print('0','B') elif n % 4==2 : if(n+1)% 4==1 : print('1','A') elif(n+2)% 4==1 : print('2','A') elif(n+1)% 4==3 : print('1','B') elif(n+2)% 4==3 : print('2','B') else : print('0','C') elif n % 4==0 : if(n+1)% 4==1 : print('1','A') elif(n+2)% 4==1 : print('2','A') elif(n+1)% 4==3 : print('1','B') elif(n+2)% 4==3 : print('1','B') elif(n+1)% 4==2 : print('1','C') elif(n+2)% 4==2 : print('2','C') else : print('0','D') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 4 = 1 then ( execute ('0')->display() ) else skip ; if n mod 4 = 3 then ( if (n + 1) mod 4 = 1 then ( execute ('1')->display() ) else (if (n + 2) mod 4 = 1 then ( execute ('2')->display() ) else ( execute ('0')->display() ) ) ) else (if n mod 4 = 2 then ( if (n + 1) mod 4 = 1 then ( execute ('1')->display() ) else (if (n + 2) mod 4 = 1 then ( execute ('2')->display() ) else (if (n + 1) mod 4 = 3 then ( execute ('1')->display() ) else (if (n + 2) mod 4 = 3 then ( execute ('2')->display() ) else ( execute ('0')->display() ) ) ) ) ) else (if n mod 4 = 0 then ( if (n + 1) mod 4 = 1 then ( execute ('1')->display() ) else (if (n + 2) mod 4 = 1 then ( execute ('2')->display() ) else (if (n + 1) mod 4 = 3 then ( execute ('1')->display() ) else (if (n + 2) mod 4 = 3 then ( execute ('1')->display() ) else (if (n + 1) mod 4 = 2 then ( execute ('1')->display() ) else (if (n + 2) mod 4 = 2 then ( execute ('2')->display() ) else ( execute ('0')->display() ) ) ) ) ) ) ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) if x % 4==1 : print('0 A') elif x % 4==2 : print('1 B') elif x % 4==3 : print('2 A') elif x % 4==0 : print('1 A') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if x mod 4 = 1 then ( execute ('0 A')->display() ) else (if x mod 4 = 2 then ( execute ('1 B')->display() ) else (if x mod 4 = 3 then ( execute ('2 A')->display() ) else (if x mod 4 = 0 then ( execute ('1 A')->display() ) else skip ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 4==0 : print(1,'A') elif n % 4==1 : print(0,'A') elif n % 4==2 : print(1,'B') else : print(2,'A') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 4 = 0 then ( execute (1)->display() ) else (if n mod 4 = 1 then ( execute (0)->display() ) else (if n mod 4 = 2 then ( execute (1)->display() ) else ( execute (2)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f1(a,b,c,d): k=(a-c)/(d-b) h=((b+d)-k*(a+c))/2 return k,h def f2(a,b,c,d): x=(d-b)/(a-c) y=a*x+b return x,y def f3(a,b,c,d): return((c-a)**2+(d-b)**2)**0.5 def main(): N=int(input()) for i in range(N): a,b,c,d,e,f=map(float,input().split()) T=[] if not b==d : k,h=f1(a,b,c,d) T.append((k,h)) if not d==f : k,h=f1(c,d,e,f) T.append((k,h)) if not f==b : k,h=f1(e,f,a,b) T.append((k,h)) x,y=f2(T[0][0],T[0][1],T[1][0],T[1][1]) r=f3(x,y,a,b) print(f'{round(x,3):.3f}{round(y,3):.3f}{round(r,3):.3f}') if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation f1(a : OclAny, b : OclAny, c : OclAny, d : OclAny) : OclAny pre: true post: true activity: var k : double := (a - c) / (d - b) ; var h : double := ((b + d) - k * (a + c)) / 2 ; return k, h; operation f2(a : OclAny, b : OclAny, c : OclAny, d : OclAny) : OclAny pre: true post: true activity: var x : double := (d - b) / (a - c) ; var y : double := a * x + b ; return x, y; operation f3(a : OclAny, b : OclAny, c : OclAny, d : OclAny) : OclAny pre: true post: true activity: return ((((c - a))->pow(2) + ((d - b))->pow(2)))->pow(0.5); operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, N-1) do ( var e : OclAny := null; var f : OclAny := null; Sequence{a,b,c,d,e,f} := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; var T : Sequence := Sequence{} ; if not(b = d) then ( Sequence{k,h} := f1(a, b, c, d) ; execute ((Sequence{k, h}) : T) ) else skip ; if not(d = f) then ( Sequence{k,h} := f1(c, d, e, f) ; execute ((Sequence{k, h}) : T) ) else skip ; if not(f = b) then ( Sequence{k,h} := f1(e, f, a, b) ; execute ((Sequence{k, h}) : T) ) else skip ; Sequence{x,y} := f2(T->first()->first(), T->first()[1+1], T[1+1]->first(), T[1+1][1+1]) ; var r : OclAny := f3(x, y, a, b) ; execute (StringLib.formattedString('{round(x,3):.3f}{round(y,3):.3f}{round(r,3):.3f}'))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math if sys.version_info[0]>=3 : raw_input=input N=int(raw_input()) for i in range(N): x1,y1,x2,y2,x3,y3=[float(e)for e in raw_input().split()] a1=2*x2-2*x1 b1=2*y2-2*y1 c1=x1*x1-x2*x2+y1*y1-y2*y2 a2=2*x3-2*x1 b2=2*y3-2*y1 c2=x1*x1-x3*x3+y1*y1-y3*y3 x=(b1*c2-b2*c1)/(a1*b2-a2*b1) y=(c1*a2-c2*a1)/(a1*b2-a2*b1) print('%.3f %.3f %.3f' %(x,y,math.hypot(x1-x,y1-y))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if (trailer . (name version_info) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) >= 3 then ( var raw_input : OclAny := input ) else skip ; var N : int := ("" + ((raw_input())))->toInteger() ; for i : Integer.subrange(0, N-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; var x3 : OclAny := null; var y3 : OclAny := null; Sequence{x1,y1,x2,y2,x3,y3} := raw_input().split()->select(e | true)->collect(e | (("" + ((e)))->toReal())) ; var a1 : double := 2 * x2 - 2 * x1 ; var b1 : double := 2 * y2 - 2 * y1 ; var c1 : double := x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2 ; var a2 : double := 2 * x3 - 2 * x1 ; var b2 : double := 2 * y3 - 2 * y1 ; var c2 : double := x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3 ; var x : double := (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1) ; var y : double := (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1) ; execute (StringLib.format('%.3f %.3f %.3f',Sequence{x, y, }))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def negProdSubArr(arr,n): positive=1 negative=0 for i in range(n): if(arr[i]>0): arr[i]=1 else : arr[i]=-1 if(i>0): arr[i]*=arr[i-1] if(arr[i]==1): positive+=1 else : negative+=1 return(positive*negative) def posProdSubArr(arr,n): total=(n*(n+1))/2 ; cntNeg=negProdSubArr(arr,n); return(total-cntNeg); arr=[5,-4,-3,2,-5] n=len(arr) print(posProdSubArr(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{5}->union(Sequence{-4}->union(Sequence{-3}->union(Sequence{2}->union(Sequence{ -5 })))) ; n := (arr)->size() ; execute (posProdSubArr(arr, n))->display(); operation negProdSubArr(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var positive : int := 1 ; var negative : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] > 0) then ( arr[i+1] := 1 ) else ( arr[i+1] := -1 ) ; if (i > 0) then ( arr[i+1] := arr[i+1] * arr[i - 1+1] ) else skip ; if (arr[i+1] = 1) then ( positive := positive + 1 ) else ( negative := negative + 1 )) ; return (positive * negative); operation posProdSubArr(arr : OclAny, n : OclAny) pre: true post: true activity: var total : double := (n * (n + 1)) / 2; ; var cntNeg : OclAny := negProdSubArr(arr, n); ; return (total - cntNeg);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter import sys input=sys.stdin.readline n=int(input()) v=list(map(int,input().split())) v1,v2=[v[i]for i in range(n)if i % 2==0],[v[i]for i in range(n)if i % 2] c1,c2=Counter(v1).most_common(),Counter(v2).most_common() l1,l2=len(c1),len(c2) if l1==1 and l2==1 : if c1[0][0]==c2[0][0]: print(n//2) else : print(0) elif l1==1 : if c1[0][0]==c2[0][0]: print(n//2-c2[1][1]) else : print(n//2-c2[0][1]) elif l2==1 : if c1[0][0]==c2[0][0]: print(n//2-c1[1][1]) else : print(n//2-c1[0][1]) else : if c1[0][0]==c2[0][0]: if c1[0][1]+c2[1][1]toInteger() ; var v : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var v1 : OclAny := null; var v2 : OclAny := null; Sequence{v1,v2} := Sequence{Integer.subrange(0, n-1)->select(i | i mod 2 = 0)->collect(i | (v[i+1])),Integer.subrange(0, n-1)->select(i | i mod 2)->collect(i | (v[i+1]))} ; var c1 : OclAny := null; var c2 : OclAny := null; Sequence{c1,c2} := Sequence{Counter(v1).most_common(),Counter(v2).most_common()} ; var l1 : OclAny := null; var l2 : OclAny := null; Sequence{l1,l2} := Sequence{(c1)->size(),(c2)->size()} ; if l1 = 1 & l2 = 1 then ( if c1->first()->first() = c2->first()->first() then ( execute (n div 2)->display() ) else ( execute (0)->display() ) ) else (if l1 = 1 then ( if c1->first()->first() = c2->first()->first() then ( execute (n div 2 - c2[1+1][1+1])->display() ) else ( execute (n div 2 - c2->first()[1+1])->display() ) ) else (if l2 = 1 then ( if c1->first()->first() = c2->first()->first() then ( execute (n div 2 - c1[1+1][1+1])->display() ) else ( execute (n div 2 - c1->first()[1+1])->display() ) ) else ( if c1->first()->first() = c2->first()->first() then ( if (c1->first()[1+1] + c2[1+1][1+1]->compareTo(c1[1+1][1+1] + c2->first()[1+1])) < 0 then ( execute (n - c1[1+1][1+1] - c2->first()[1+1])->display() ) else ( execute (n - c1->first()[1+1] - c2[1+1][1+1])->display() ) ) else ( execute (n - c1->first()[1+1] - c2->first()[1+1])->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from decimal import Decimal import math for _ in range(int(input())): x1,y1,x2,y2,x3,y3=list(map(Decimal,input().split())) a=x1-x3 b=y2-y3 c=x2-x3 d=y1-y3 e=y1-y2 f=x1+x3 g=x2+x3 X=(b*d*e+a*b*f-c*d*g)/2/(a*b-c*d) try : Y=-(a/d)*(X-f/2)+(y1+y3)/2 except : Y=-(c/b)*(X-g/2)+(y2+y3)/2 R=math.sqrt((x1-X)**2+(y1-Y)**2) print(" ".join(["{:.3f}".format(i)for i in[X,Y,R]])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; var x3 : OclAny := null; var y3 : OclAny := null; Sequence{x1,y1,x2,y2,x3,y3} := ((input().split())->collect( _x | (Decimal)->apply(_x) )) ; var a : double := x1 - x3 ; var b : double := y2 - y3 ; var c : double := x2 - x3 ; var d : double := y1 - y3 ; var e : double := y1 - y2 ; var f : OclAny := x1 + x3 ; var g : OclAny := x2 + x3 ; var X : double := (b * d * e + a * b * f - c * d * g) / 2 / (a * b - c * d) ; try ( var Y : double := -(a / d) * (X - f / 2) + (y1 + y3) / 2) catch (_e : OclException) do ( Y := -(c / b) * (X - g / 2) + (y2 + y3) / 2) ; var R : double := (((x1 - X))->pow(2) + ((y1 - Y))->pow(2))->sqrt() ; execute (StringLib.sumStringsWithSeparator((Sequence{X}->union(Sequence{Y}->union(Sequence{ R }))->select(i | true)->collect(i | (StringLib.interpolateStrings("{:.3f}", Sequence{i})))), " "))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,fabs def calcu_cirucumcenter(x1,y1,x2,y2,x3,y3): a=-2*x1+2*x2 b=-2*y1+2*y2 c=-2*x1+2*x3 d=-2*y1+2*y3 e=-1*(x1**2+y1**2-x2**2-y2**2) f=-1*(x1**2+y1**2-x3**2-y3**2) x=1/(a*d-b*c)*(d*e-b*f) y=1/(a*d-b*c)*(-c*e+a*f) return x,y if __name__=='__main__' : epsilon=1e-9 num=int(input()) for i in range(num): x1,y1,x2,y2,x3,y3=[float(x)for x in input().split(' ')] x,y=calcu_cirucumcenter(x1,y1,x2,y2,x3,y3) if fabs(x)toReal() ; var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, num-1) do ( Sequence{x1,y1,x2,y2,x3,y3} := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toReal())) ; Sequence{x,y} := calcu_cirucumcenter(x1, y1, x2, y2, x3, y3) ; if (fabs(x)->compareTo(epsilon)) < 0 then ( x := 0.0 ) else skip ; if (fabs(y)->compareTo(epsilon)) < 0 then ( y := 0.0 ) else skip ; var r : OclAny := sqrt(((x - x1))->pow(2) + ((y - y1))->pow(2)) ; execute (StringLib.interpolateStrings('{0:.3f}{1:.3f}{2:.3f}', Sequence{x, y, r}))->display()) ) else skip; operation calcu_cirucumcenter(x1 : OclAny, y1 : OclAny, x2 : OclAny, y2 : OclAny, x3 : OclAny, y3 : OclAny) : OclAny pre: true post: true activity: var a : double := -2 * x1 + 2 * x2 ; var b : double := -2 * y1 + 2 * y2 ; var c : double := -2 * x1 + 2 * x3 ; var d : double := -2 * y1 + 2 * y3 ; var e : double := -1 * ((x1)->pow(2) + (y1)->pow(2) - (x2)->pow(2) - (y2)->pow(2)) ; var f : double := -1 * ((x1)->pow(2) + (y1)->pow(2) - (x3)->pow(2) - (y3)->pow(2)) ; var x : double := 1 / (a * d - b * c) * (d * e - b * f) ; var y : double := 1 / (a * d - b * c) * (-c * e + a * f) ; return x, y; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* def g(x): y=(int((1000*abs(x))*2+1)//2)/1000 if x<0 : y*=-1 return y def func(x): x1,y1,x2,y2,x3,y3=x a=x1-x2 b=y1-y2 c=(x1*x1+y1*y1-x2*x2-y2*y2)/2 d=x1-x3 e=y1-y3 f=(x1*x1+y1*y1-x3*x3-y3*y3)/2 x=(e*c-b*f)/(a*e-b*d) y=(a*f-d*c)/(a*e-b*d) r=sqrt((x1-x)*(x1-x)+(y1-y)*(y1-y)) x="{0:.3f}".format(g(x)) y="{0:.3f}".format(g(y)) r="{0:.3f}".format(g(r)) print(x+" "+y+" "+r) n=int(input()) a=[] for _ in range(n): a.append(list((map(float,input().split())))) for i in a : func(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute (((((input().split())->collect( _x | (OclType["double"])->apply(_x) )))) : a)) ; for i : a do ( func(i)); operation g(x : OclAny) : OclAny pre: true post: true activity: var y : double := (("" + (((1000 * (x)->abs()) * 2 + 1)))->toInteger() div 2) / 1000 ; if x < 0 then ( y := y * -1 ) else skip ; return y; operation func(x : OclAny) pre: true post: true activity: var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; var x3 : OclAny := null; var y3 : OclAny := null; Sequence{x1,y1,x2,y2,x3,y3} := x ; var a : double := x1 - x2 ; var b : double := y1 - y2 ; var c : double := (x1 * x1 + y1 * y1 - x2 * x2 - y2 * y2) / 2 ; var d : double := x1 - x3 ; var e : double := y1 - y3 ; var f : double := (x1 * x1 + y1 * y1 - x3 * x3 - y3 * y3) / 2 ; x := (e * c - b * f) / (a * e - b * d) ; y := (a * f - d * c) / (a * e - b * d) ; var r : OclAny := sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y)) ; x := StringLib.interpolateStrings("{0:.3f}", Sequence{g(x)}) ; y := StringLib.interpolateStrings("{0:.3f}", Sequence{g(y)}) ; r := StringLib.interpolateStrings("{0:.3f}", Sequence{g(r)}) ; execute (x + " " + y + " " + r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for j in range(0,n): a,b,c,d=map(int,input().split()) print(max(a+b,c+d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{a + b, c + d}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re print('NO' if re.search('[^aeiou%s]'*2 %('n',''),input()+'x')else 'YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (if ((OclFile["System.in"]).readLine() + 'x')->firstMatch(StringLib.nCopies('[^aeiou%s]', 2) mod Sequence{'n', ''}) then 'NO' else 'YES' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- string=input() vowels=['a','e','i','o','u','n'] for index in range(0,len(string)-1): if string[index]not in vowels : if string[index+1]not in vowels or string[index+1]=='n' : print("NO") exit() if string[len(string)-1]not in vowels : print("NO") exit() print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var string : String := (OclFile["System.in"]).readLine() ; var vowels : Sequence := Sequence{'a'}->union(Sequence{'e'}->union(Sequence{'i'}->union(Sequence{'o'}->union(Sequence{'u'}->union(Sequence{ 'n' }))))) ; for index : Integer.subrange(0, (string)->size() - 1-1) do ( if (vowels)->excludes(string[index+1]) then ( if (vowels)->excludes(string[index + 1+1]) or string[index + 1+1] = 'n' then ( execute ("NO")->display() ; exit() ) else skip ) else skip) ; if (vowels)->excludes(string[(string)->size() - 1+1]) then ( execute ("NO")->display() ; exit() ) else skip ; execute ("YES")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- str=input() vog=['a','e','i','o','u'] n=len(str) for i in range(n): if str[i]in vog or str[i]=='n' : continue else : if i==n-1 : print('NO') exit(0) else : if str[i+1]not in vog : print('NO') exit(0) print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var OclType["String"] : String := (OclFile["System.in"]).readLine() ; var vog : Sequence := Sequence{'a'}->union(Sequence{'e'}->union(Sequence{'i'}->union(Sequence{'o'}->union(Sequence{ 'u' })))) ; var n : int := (OclType["String"])->size() ; for i : Integer.subrange(0, n-1) do ( if (vog)->includes(("" + ([i+1]))) or ("" + ([i+1])) = 'n' then ( continue ) else ( if i = n - 1 then ( execute ('NO')->display() ; exit(0) ) else ( if (vog)->excludes(("" + ([i + 1+1]))) then ( execute ('NO')->display() ; exit(0) ) else skip ) )) ; execute ('YES')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- text=input() check="aeioun" flag=0 for i in range(len(text)): if(check.find(text[i])==-1): if(i+1size()-1) do ( if (check->indexOf(text[i+1]) - 1 = -1) then ( if ((i + 1->compareTo((text)->size())) < 0 & check->indexOf(text[i + 1+1]) - 1 /= -1 & text[i + 1+1] /= "n") then ( flag := 1 ) else ( flag := 0 ; break ) ) else ( flag := 1 ; continue )) ; if flag = 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() vogais="aouie" if(len(s)==1): if vogais.find(s[0])!=-1 or s[0]=='n' : print('YES') exit() else : print('NO') exit() for i in range(1,len(s)): if(s[i-1]!='n' and vogais.find(s[i-1])==-1 and vogais.find(s[i])==-1): print('NO') exit() if vogais.find(s[-1])!=-1 or s[-1]=='n' : print('YES') exit() else : print('NO') exit() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var vogais : String := "aouie" ; if ((s)->size() = 1) then ( if vogais->indexOf(s->first()) - 1 /= -1 or s->first() = 'n' then ( execute ('YES')->display() ; exit() ) else ( execute ('NO')->display() ; exit() ) ) else skip ; for i : Integer.subrange(1, (s)->size()-1) do ( if (s[i - 1+1] /= 'n' & vogais->indexOf(s[i - 1+1]) - 1 = -1 & vogais->indexOf(s[i+1]) - 1 = -1) then ( execute ('NO')->display() ; exit() ) else skip) ; if vogais->indexOf(s->last()) - 1 /= -1 or s->last() = 'n' then ( execute ('YES')->display() ; exit() ) else ( execute ('NO')->display() ; exit() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* def countPairs(N): count=0 for i in range(1,int(sqrt(N))+1): sq=i*i diff=N-sq sqrtDiff=int(sqrt(diff)) if sqrtDiff*sqrtDiff==diff : count+=1 return count if __name__=="__main__" : for i in range(1,11): print("For n=",i,",",countPairs(i),"pair exists") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( for i : Integer.subrange(1, 11-1) do ( execute ("For n=")->display()) ) else skip; operation countPairs(N : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(1, ("" + ((sqrt(N))))->toInteger() + 1-1) do ( var sq : double := i * i ; var diff : double := N - sq ; var sqrtDiff : int := ("" + ((sqrt(diff))))->toInteger() ; if sqrtDiff * sqrtDiff = diff then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def subString(s,n): for i in range(n): for len in range(i+1,n+1): print(s[i : len]); s="abcd" ; subString(s,len(s)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := "abcd"; ; subString(s, (s)->size());; operation subString(s : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( for len : Integer.subrange(i + 1, n + 1-1) do ( execute (s.subrange(i+1, len))->display();)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def isPrime(n): if(n<=1): return False if(n<=3): return True if(n % 2==0 or n % 3==0): return False for i in range(5,int(math.sqrt(n)+1),6): if(n % i==0 or n %(i+2)==0): return False return True def nextPrime(N): if(N<=1): return 2 prime=N found=False while(not found): prime=prime+1 if(isPrime(prime)==True): found=True return prime N=3 print(nextPrime(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; N := 3 ; execute (nextPrime(N))->display(); operation isPrime(n : OclAny) : OclAny pre: true post: true activity: if (n <= 1) then ( return false ) else skip ; if (n <= 3) then ( return true ) else skip ; if (n mod 2 = 0 or n mod 3 = 0) then ( return false ) else skip ; for i : Integer.subrange(5, ("" + (((n)->sqrt() + 1)))->toInteger()-1)->select( $x | ($x - 5) mod 6 = 0 ) do ( if (n mod i = 0 or n mod (i + 2) = 0) then ( return false ) else skip) ; return true; operation nextPrime(N : OclAny) : OclAny pre: true post: true activity: if (N <= 1) then ( return 2 ) else skip ; var prime : OclAny := N ; var found : boolean := false ; while (not(found)) do ( prime := prime + 1 ; if (isPrime(prime) = true) then ( found := true ) else skip) ; return prime; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() history=dict() count=0 for i in range(0,2*n-2,2): code=s[i] if code in history : history[code]+=1 else : history[code]=1 next_code=s[i+1].lower() if next_code in history and history[next_code]>0 : history[next_code]-=1 else : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var history : Map := (arguments ( )) ; var count : int := 0 ; for i : Integer.subrange(0, 2 * n - 2-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( var code : OclAny := s[i+1] ; if (history)->includes(code) then ( history[code+1] := history[code+1] + 1 ) else ( history[code+1] := 1 ) ; var next_code : OclAny := s[i + 1+1]->toLowerCase() ; if (history)->includes(next_code) & history[next_code+1] > 0 then ( history[next_code+1] := history[next_code+1] - 1 ) else ( count := count + 1 )) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve_a(): num_comodos=int(input()) comodos_chaves=input() dict_aux={}; solve=0 for ele in comodos_chaves : if(ele.isupper()): if(ele.lower()not in dict_aux.keys()or dict_aux[ele.lower()]==0): solve=solve+1 else : aux=ele.lower() dict_aux[aux]=dict_aux[aux]-1 if(ele.islower()): if(ele in dict_aux.keys()): dict_aux[ele]=dict_aux[ele]+1 else : dict_aux[ele]=1 print(solve) solve_a() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve_a(); operation solve_a() pre: true post: true activity: var num_comodos : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var comodos_chaves : String := (OclFile["System.in"]).readLine() ; var dict_aux : OclAny := Set{}; var solve : int := 0 ; for ele : comodos_chaves->characters() do ( if (ele->matches("[A-Z ]*")) then ( if ((dict_aux.keys())->excludes(ele->toLowerCase()) or dict_aux[ele->toLowerCase()+1] = 0) then ( solve := solve + 1 ) else ( var aux : String := ele->toLowerCase() ; dict_aux->at(aux) := dict_aux->at(aux) - 1 ) ) else skip ; if (ele->matches("[a-z ]*")) then ( if ((dict_aux.keys())->includes(ele)) then ( dict_aux[ele+1] := dict_aux[ele+1] + 1 ) else ( dict_aux[ele+1] := 1 ) ) else skip) ; execute (solve)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) texto=input() chaves=[0]*26 count=0 for i in range(len(texto)): char=texto[i] if char.isupper()==True : if chaves[ord(char)-65]==0 : count+=1 else : chaves[ord(char)-65]-=1 else : char=char.upper() chaves[ord(char)-65]+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var texto : String := (OclFile["System.in"]).readLine() ; var chaves : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; var count : int := 0 ; for i : Integer.subrange(0, (texto)->size()-1) do ( var char : OclAny := texto[i+1] ; if char->matches("[A-Z ]*") = true then ( if chaves[(char)->char2byte() - 65+1] = 0 then ( count := count + 1 ) else ( chaves[(char)->char2byte() - 65+1] := chaves[(char)->char2byte() - 65+1] - 1 ) ) else ( char := char->toUpperCase() ; chaves[(char)->char2byte() - 65+1] := chaves[(char)->char2byte() - 65+1] + 1 )) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while(t!=0): n,k=map(int,input().split()) if(k % 2!=0): print("YES") for i in range(1,n,2): print(i,i+1) else : if(k % 4==0): print("NO") else : print("YES") flag=0 for i in range(1,n,2): if(flag==0): print(i+1,i) else : print(i,i+1) flag=1-flag t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (t /= 0) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (k mod 2 /= 0) then ( execute ("YES")->display() ; for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( execute (i)->display()) ) else ( if (k mod 4 = 0) then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; var flag : int := 0 ; for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( if (flag = 0) then ( execute (i + 1)->display() ) else ( execute (i)->display() ) ; flag := 1 - flag) ) ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a,b,c,d=map(int,input().split(' ')) p=[a+c,a+b,d+c,d+b] p.sort() print(p[2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var p : Sequence := Sequence{a + c}->union(Sequence{a + b}->union(Sequence{d + c}->union(Sequence{ d + b }))) ; p := p->sort() ; execute (p[2+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() kcount=0 alpha=[0]*26 if ord(s[1])-65!=ord(s[0])-97 : kcount+=1 alpha[ord(s[0])-97]+=1 for i in range(2,len(s),2): lcase=ord(s[i])-97 ucase=ord(s[i+1])-65 alpha[lcase]+=1 if lcase!=ucase : kcount+=alpha[ucase]==0 alpha[ucase]-=alpha[ucase]!=0 else : alpha[lcase]-=1 print(kcount) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var kcount : int := 0 ; var alpha : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; if (s[1+1])->char2byte() - 65 /= (s->first())->char2byte() - 97 then ( kcount := kcount + 1 ; alpha[(s->first())->char2byte() - 97+1] := alpha[(s->first())->char2byte() - 97+1] + 1 ) else skip ; for i : Integer.subrange(2, (s)->size()-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( var lcase : double := (s[i+1])->char2byte() - 97 ; var ucase : double := (s[i + 1+1])->char2byte() - 65 ; alpha[lcase+1] := alpha[lcase+1] + 1 ; if lcase /= ucase then ( kcount := kcount + alpha[ucase+1] = 0 ; alpha[ucase+1] := alpha[ucase+1] - alpha[ucase+1] /= 0 ) else ( alpha[lcase+1] := alpha[lcase+1] - 1 )) ; execute (kcount)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() kcount=0 alpha=[0]*26 if ord(s[1])-65!=ord(s[0])-97 : kcount+=1 alpha[ord(s[0])-97]+=1 for i in range(2,len(s),2): lcase=ord(s[i])-97 ucase=ord(s[i+1])-65 alpha[lcase]+=1 if lcase!=ucase : kcount+=alpha[ucase]==0 alpha[ucase]-=alpha[ucase]!=0 else : alpha[lcase]-=1 print(kcount) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var kcount : int := 0 ; var alpha : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; if (s[1+1])->char2byte() - 65 /= (s->first())->char2byte() - 97 then ( kcount := kcount + 1 ; alpha[(s->first())->char2byte() - 97+1] := alpha[(s->first())->char2byte() - 97+1] + 1 ) else skip ; for i : Integer.subrange(2, (s)->size()-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( var lcase : double := (s[i+1])->char2byte() - 97 ; var ucase : double := (s[i + 1+1])->char2byte() - 65 ; alpha[lcase+1] := alpha[lcase+1] + 1 ; if lcase /= ucase then ( kcount := kcount + alpha[ucase+1] = 0 ; alpha[ucase+1] := alpha[ucase+1] - alpha[ucase+1] /= 0 ) else ( alpha[lcase+1] := alpha[lcase+1] - 1 )) ; execute (kcount)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) maxa=[] mini=[] ma=0 mi=0 a=list(map(int,input().split())) for i in a : maxa.append(i) mini.append(i) for x in range(n): ind=maxa.index(max(maxa)) ma+=maxa[ind] maxa[ind]-=1 for y in range(n): imd=mini.index(min(mini)) if mini[imd]==0 : mini.pop(imd) imd=mini.index(min(mini)) if mini[imd]>0 : mi+=mini[imd] mini[imd]-=1 print(ma,mi) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var maxa : Sequence := Sequence{} ; var mini : Sequence := Sequence{} ; var ma : int := 0 ; var mi : int := 0 ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : a do ( execute ((i) : maxa) ; execute ((i) : mini)) ; for x : Integer.subrange(0, n-1) do ( var ind : int := maxa->indexOf((maxa)->max()) - 1 ; ma := ma + maxa[ind+1] ; maxa[ind+1] := maxa[ind+1] - 1) ; for y : Integer.subrange(0, n-1) do ( var imd : int := mini->indexOf((mini)->min()) - 1 ; if mini[imd+1] = 0 then ( mini := mini->excludingAt(imd+1) ) else skip ; imd := mini->indexOf((mini)->min()) - 1 ; if mini[imd+1] > 0 then ( mi := mi + mini[imd+1] ; mini[imd+1] := mini[imd+1] - 1 ) else skip) ; execute (ma)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=list(map(int,input().split())) b=a.copy() z=x=0 for i in range(n): a.sort() b.sort() z+=a[0] if a[0]==1 : a[0]=1000 else : a[0]-=1 x+=b[m-1] b[m-1]-=1 print(x,z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : OclAny := a->copy() ; var z : OclAny := 0; var x : int := 0 ; for i : Integer.subrange(0, n-1) do ( a := a->sort() ; b := b->sort() ; z := z + a->first() ; if a->first() = 1 then ( a->first() := 1000 ) else ( a->first() := a->first() - 1 ) ; x := x + b[m - 1+1] ; b[m - 1+1] := b[m - 1+1] - 1) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPrime(n): if(n<=1): return False ; for i in range(2,n): if(n % i==0): return False ; return True ; def countPrimePosition(arr): c0=0 ; c1=0 ; n=len(arr); for i in range(n): if(arr[i]==0 and isPrime(i)): c0+=1 ; if(arr[i]==1 and isPrime(i)): c1+=1 ; print("Number of 0s=",c0); print("Number of 1s=",c1); if __name__=="__main__" : arr=[1,0,1,0,1]; countPrimePosition(arr); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 1 })))); ; countPrimePosition(arr); ) else skip; operation isPrime(n : OclAny) pre: true post: true activity: if (n <= 1) then ( return false; ) else skip ; for i : Integer.subrange(2, n-1) do ( if (n mod i = 0) then ( return false; ) else skip) ; return true;; operation countPrimePosition(arr : OclAny) pre: true post: true activity: var c0 : int := 0; var c1 : int := 0; ; n := (arr)->size(); ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] = 0 & isPrime(i)) then ( c0 := c0 + 1; ) else skip ; if (arr[i+1] = 1 & isPrime(i)) then ( c1 := c1 + 1; ) else skip) ; execute ("Number of 0s=")->display(); ; execute ("Number of 1s=")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq n,m=map(int,input().split()) a=list(map(int,input().split())) b=[-i for i in a] heapq.heapify(a) heapq.heapify(b) seats=0 maxVal=0 minVal=0 while seats0 : heapq.heappush(a,minSeat) maxSeat=heapq.heappop(b) maxVal+=abs(maxSeat) maxSeat+=1 if maxSeat<0 : heapq.heappush(b,maxSeat) seats+=1 print(maxVal,minVal) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := a->select(i | true)->collect(i | (-i)) ; heapq.heapify(a) ; heapq.heapify(b) ; var seats : int := 0 ; var maxVal : int := 0 ; var minVal : int := 0 ; while (seats->compareTo(n)) < 0 do ( var minSeat : OclAny := heapq.heappop(a) ; minVal := minVal + minSeat ; minSeat := minSeat - 1 ; if minSeat > 0 then ( heapq.heappush(a, minSeat) ) else skip ; var maxSeat : OclAny := heapq.heappop(b) ; maxVal := maxVal + (maxSeat)->abs() ; maxSeat := maxSeat + 1 ; if maxSeat < 0 then ( heapq.heappush(b, maxSeat) ) else skip ; seats := seats + 1) ; execute (maxVal)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) c=list(map(int,input().split())) c=c+c liste1=[] liste2=[] for b in range(len(c)): if bcollect( _x | (OclType["int"])->apply(_x) ) ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; c := c->union(c) ; var liste1 : Sequence := Sequence{} ; var liste2 : Sequence := Sequence{} ; for b : Integer.subrange(0, (c)->size()-1) do ( if (b->compareTo((c)->size() / 2)) < 0 then ( execute ((c[b+1]) : liste1) ) else ( execute ((c[b+1]) : liste2) )) ; var mn : int := 0 ; var mx : int := 0 ; for i : Integer.subrange(0, a-1) do ( var l : OclAny := (liste1)->min() ; mn := mn + l ; var t : int := liste1->indexOf((liste1)->min()) - 1 ; liste1[t+1] := liste1[t+1] - 1 ; if liste1[t+1] = 0 then ( liste1 := liste1->excludingAt(t+1) ) else skip) ; for i : Integer.subrange(0, a-1) do ( var e : OclAny := (liste2)->max() ; mx := mx + e ; var p : int := liste2->indexOf((liste2)->max()) - 1 ; liste2[p+1] := liste2[p+1] - 1) ; execute (mx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq def main(): n,m=list(map(int,input().split(' '))) elems=list(map(int,input().split(' '))) minh,maxh=[],[] for e in elems : heapq.heappush(minh,e) heapq.heappush(maxh,-e) def calc(h,mult=1): total=0 q=n while q>0 : c=mult*heapq.heappop(h) total+=c c-=1 q-=1 if c>0 : heapq.heappush(h,mult*c) return str(total) print(' '.join([calc(maxh,-1),calc(minh)])) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var elems : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var minh : OclAny := null; var maxh : OclAny := null; Sequence{minh,maxh} := Sequence{Sequence{},Sequence{}} ; for e : elems do ( heapq.heappush(minh, e) ; heapq.heappush(maxh, -e)) ; skip ; execute (StringLib.sumStringsWithSeparator((Sequence{calc(maxh, -1)}->union(Sequence{ calc(minh) })), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=4 ; def diagonalBoundarySum(arr): requiredSum=0 ; for i in range(N): for j in range(N): if(i==j or(i+j)==N-1): requiredSum+=arr[i][j]; elif(i==0 or j==0 or i==N-1 or j==N-1): requiredSum+=arr[i][j]; print(requiredSum); if __name__=='__main__' : arr=[[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]]; diagonalBoundarySum(arr); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 4; ; skip ; if __name__ = '__main__' then ( arr := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })))}->union(Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })))}->union(Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })))}->union(Sequence{ Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))) }))); ; diagonalBoundarySum(arr); ) else skip; operation diagonalBoundarySum(arr : OclAny) pre: true post: true activity: var requiredSum : int := 0; ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( if (i = j or (i + j) = N - 1) then ( requiredSum := requiredSum + arr[i+1][j+1]; ) else (if (i = 0 or j = 0 or i = N - 1 or j = N - 1) then ( requiredSum := requiredSum + arr[i+1][j+1]; ) else skip))) ; execute (requiredSum)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect n,m=map(int,input().split()) l=list(map(int,input().split())) l.sort() r=[0]*(10**5+2) for i in range(n): r[l[i]]+=1 for i in range(10**5+1): r[i+1]+=r[i] ok=10**6 ng=0 while ok-ng>1 : x=(ok+ng)//2 k=0 for i in range(n): if x-l[i]<0 : k+=n elif x-l[i]>10**5+1 : k+=0 else : k+=n-r[x-l[i]] if k>=m : ng=x else : ok=x p=[0]*(n+1) for i in range(n): p[i+1]=p[i]+l[i] ans=0 mi=0 for i in range(n): li=bisect.bisect_left(l,ok-l[i]) ans+=l[i]*(n-li)+p[n]-p[li] mi+=n-li print(ans-(mi-m)*ok) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := l->sort() ; var r : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((10)->pow(5) + 2)) ; for i : Integer.subrange(0, n-1) do ( r[l[i+1]+1] := r[l[i+1]+1] + 1) ; for i : Integer.subrange(0, (10)->pow(5) + 1-1) do ( r[i + 1+1] := r[i + 1+1] + r[i+1]) ; var ok : double := (10)->pow(6) ; var ng : int := 0 ; while ok - ng > 1 do ( var x : int := (ok + ng) div 2 ; var k : int := 0 ; for i : Integer.subrange(0, n-1) do ( if x - l[i+1] < 0 then ( k := k + n ) else (if (x - l[i+1]->compareTo((10)->pow(5) + 1)) > 0 then ( k := k + 0 ) else ( k := k + n - r[x - l[i+1]+1] ) ) ) ; if (k->compareTo(m)) >= 0 then ( ng := x ) else ( ok := x )) ; var p : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(0, n-1) do ( p[i + 1+1] := p[i+1] + l[i+1]) ; var ans : int := 0 ; var mi : int := 0 ; for i : Integer.subrange(0, n-1) do ( var li : OclAny := bisect.bisect_left(l, ok - l[i+1]) ; ans := ans + l[i+1] * (n - li) + p[n+1] - p[li+1] ; mi := mi + n - li) ; execute (ans - (mi - m) * ok)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import groupby,accumulate import bisect n,m=[int(x)for x in input().split()] A=[int(x)for x in input().split()] A.sort() le=len(A) B=list(accumulate([0]+A)) ok=0 ng=10**10 ans=0 while 1=m : ok=mid else : ng=mid cnt=0 for i in range(le): x=ok-A[i] cnt1=int(bisect.bisect_left(A,x)) cnt+=le-cnt1 ans+=A[i]*(le-cnt1)+B[n]-B[cnt1] print(ans+(m-cnt)*ok) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; A := A->sort() ; var le : int := (A)->size() ; var B : Sequence := (accumulate(Sequence{ 0 }->union(A))) ; var ok : int := 0 ; var ng : double := (10)->pow(10) ; var ans : int := 0 ; while 1 < (ng - ok)->abs() do ( var mid : int := (ng + ok) div 2 ; ans := 0 ; var cnt : int := 0 ; for i : Integer.subrange(0, le-1) do ( var x : double := mid - A[i+1] ; var cnt1 : int := ("" + ((bisect.bisect_left(A, x))))->toInteger() ; cnt := cnt + (le - cnt1)) ; if (cnt->compareTo(m)) >= 0 then ( ok := mid ) else ( ng := mid )) ; cnt := 0 ; for i : Integer.subrange(0, le-1) do ( x := ok - A[i+1] ; cnt1 := ("" + ((bisect.bisect_left(A, x))))->toInteger() ; cnt := cnt + le - cnt1 ; ans := ans + A[i+1] * (le - cnt1) + B[n+1] - B[cnt1+1]) ; execute (ans + (m - cnt) * ok)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout T=int(stdin.readline()) for i in range(T): A,B,C,D=map(int,stdin.readline().strip().split()) stdout.write(f"{max(A+B,C+D)}\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var T : int := ("" + ((stdin.readLine())))->toInteger() ; for i : Integer.subrange(0, T-1) do ( var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var D : OclAny := null; Sequence{A,B,C,D} := (stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; stdout.write(StringLib.formattedString("{max(A+B,C+D)}\n"))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines import numpy as np 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=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) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := (read().split(), ) ; A := A->sort() ; skip ; var left : int := 0 ; var right : double := (10)->pow(6) ; while (left + 1->compareTo(right)) < 0 do ( x := (left + right) div 2 ; if (shake_cnt(x)->compareTo(M)) >= 0 then ( left := x ) else ( right := x )) ; left ; ; X := ; var Acum : Sequence := MatrixLib.singleValueMatrix(N + 1, 0.0) ; Acum->tail() := ; var shake : double := N * N - X.sum() ; var happy : OclAny := (Acum->last() - Acum[X+1]).sum() + (MatrixLib.elementwiseMult(A, (N - X))).sum() ; happy := happy + (M - shake) * left ; execute (happy)->display(); operation shake_cnt(x : OclAny) : OclAny pre: true post: true activity: var X : (trailer . (name searchsorted) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (name A))))))))) ))) := ; return N * N - X.sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import bisect import itertools def solve(): readline=sys.stdin.buffer.readline mod=10**9+7 n,m=list(map(int,readline().split())) a=list(map(int,readline().split())) a.sort() cor_v=a[0]*2 inc_v=a[-1]*2+1 while-cor_v+inc_v>1 : bin_v=(cor_v+inc_v)//2 cost=0 for i in range(n-1,-1,-1): cost+=n-bisect.bisect_left(a,bin_v-a[i]) if cost>=m : cor_v=bin_v else : inc_v=bin_v acm=list(itertools.accumulate([0]+a)) t=0 c=0 for i in range(n): p=bisect.bisect_left(a,cor_v-a[i]) t+=acm[-1]-acm[p]+a[i]*(n-p) c+=n-p print(t-(c-m)*cor_v) if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var readline : OclAny := sys.stdin.buffer.readline ; var mod : double := (10)->pow(9) + 7 ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var cor_v : double := a->first() * 2 ; var inc_v : double := a->last() * 2 + 1 ; while -cor_v + inc_v > 1 do ( var bin_v : int := (cor_v + inc_v) div 2 ; var cost : int := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( cost := cost + n - bisect.bisect_left(a, bin_v - a[i+1])) ; if (cost->compareTo(m)) >= 0 then ( cor_v := bin_v ) else ( inc_v := bin_v )) ; var acm : Sequence := (itertools.accumulate(Sequence{ 0 }->union(a))) ; var t : int := 0 ; var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( var p : OclAny := bisect.bisect_left(a, cor_v - a[i+1]) ; t := t + acm->last() - acm[p+1] + a[i+1] * (n - p) ; c := c + n - p) ; execute (t - (c - m) * cor_v)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from bisect import bisect_left from itertools import accumulate def func(A,N,M,x): count=0 for Ai in A : idx=bisect_left(A,x-Ai) count+=N-idx if count>=M : return True else : return False def main(): N,M=map(int,input().split()) A=sorted(list(map(int,input().split()))) A_rev=list(reversed(A)) B=[0]+list(accumulate(A_rev)) min_=0 max_=2*10**5+1 while max_-min_>1 : mid=(min_+max_)//2 if func(A,N,M,mid): min_=mid else : max_=mid ans=0 count=0 for Ai in A_rev : idx=bisect_left(A,min_-Ai) ans+=Ai*(N-idx)+B[N-idx] count+=N-idx print(ans-(count-M)*min_) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation func(A : OclAny, N : OclAny, M : OclAny, x : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for Ai : A do ( var idx : OclAny := bisect_left(A, x - Ai) ; count := count + N - idx) ; if (count->compareTo(M)) >= 0 then ( return true ) else ( return false ); operation main() pre: true post: true activity: Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; A := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var A_rev : Sequence := ((A)->reverse()) ; var B : Sequence := Sequence{ 0 }->union((accumulate(A_rev))) ; var min_ : int := 0 ; var max_ : double := 2 * (10)->pow(5) + 1 ; while max_ - min_ > 1 do ( var mid : int := (min_ + max_) div 2 ; if func(A, N, M, mid) then ( min_ := mid ) else ( max_ := mid )) ; var ans : int := 0 ; count := 0 ; for Ai : A_rev do ( idx := bisect_left(A, min_ - Ai) ; ans := ans + Ai * (N - idx) + B[N - idx+1] ; count := count + N - idx) ; execute (ans - (count - M) * min_)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def angleextcycquad(z): print("The exterior angle of the",end=""); print("cyclic quadrilateral is ",end=""); print(z," degrees"); z=48 ; angleextcycquad(z); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; z := 48; ; angleextcycquad(z);; operation angleextcycquad(z : OclAny) pre: true post: true activity: execute ("The exterior angle of the")->display(); ; execute ("cyclic quadrilateral is ")->display(); ; execute (z)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isToOneRec(n : int,s : set)->bool : if n==1 : return True if n in s : return False if n % 2 : return isToOneRec(3*n+1,s) else : return isToOneRec(n//2,s) def isToOne(n : int)->bool : s=set() return isToOneRec(n,s) if __name__=="__main__" : n=5 if isToOne(n): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var n : int := 5 ; if isToOne(n) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isToOneRec(n : int, s : Set(OclAny)) : boolean pre: true post: true activity: if n = 1 then ( return true ) else skip ; if (s)->includes(n) then ( return false ) else skip ; if n mod 2 then ( return isToOneRec(3 * n + 1, s) ) else ( return isToOneRec(n div 2, s) ); operation isToOne(n : int) : boolean pre: true post: true activity: var s : Set := Set{}->union(()) ; return isToOneRec(n, s); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) d=0 for i in range(0,t): arr1=[int(x)for x in input().split()] a,b,c=arr1[0],arr1[1],arr1[2] while b>0 and c>=2 : d+=1 b-=1 c-=2 while a>0 and b>=2 : d+=1 a-=1 b-=2 print(d*3) d=0 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : int := 0 ; for i : Integer.subrange(0, t-1) do ( var arr1 : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{arr1->first(),arr1[1+1],arr1[2+1]} ; while b > 0 & c >= 2 do ( d := d + 1 ; b := b - 1 ; c := c - 2) ; while a > 0 & b >= 2 do ( d := d + 1 ; a := a - 1 ; b := b - 2) ; execute (d * 3)->display() ; d := 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- exec(int(input())*'a,b,c=map(int,input().split());d=min(c//2,b);print(min(a,(b-d)//2)*3+d*3);') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) )))) * (expr (atom 'a,b,c=map(int,input().split());d=min(c//2,b);print(min(a,(b-d)//2)*3+d*3);'))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- exec(int(input())*'a,b,c=map(int,input().split());d=min(c//2,b);print(min(a,(b-d)//2)*3+d*3);') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) )))) * (expr (atom 'a,b,c=map(int,input().split());d=min(c//2,b);print(min(a,(b-d)//2)*3+d*3);'))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for _ in range(n): a,b,c=list(map(int,input().split())) cnt=0 while c-2>=0 and b-1>=0 : cnt+=3 c-=2 b-=1 while b-2>=0 and a-1>=0 : cnt+=3 b-=2 a-=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : int := 0 ; while c - 2 >= 0 & b - 1 >= 0 do ( cnt := cnt + 3 ; c := c - 2 ; b := b - 1) ; while b - 2 >= 0 & a - 1 >= 0 do ( cnt := cnt + 3 ; b := b - 2 ; a := a - 1) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t=int(input()) ans=[] for _ in range(t): a,b,c=map(int,input().split()) ans0=0 for i in range(55): for j in range(55): if i<=a and 2*i+j<=b and 2*j<=c : ans0=max(ans0,3*(i+j)) else : break ans.append(ans0) sys.stdout.write("\n".join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans0 : int := 0 ; for i : Integer.subrange(0, 55-1) do ( for j : Integer.subrange(0, 55-1) do ( if (i->compareTo(a)) <= 0 & (2 * i + j->compareTo(b)) <= 0 & (2 * j->compareTo(c)) <= 0 then ( ans0 := Set{ans0, 3 * (i + j)}->max() ) else ( break ))) ; execute ((ans0) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def factorial(n): fact=1 for i in range(2,n+1): fact=fact*i return fact def ncr(n,r): return(factorial(n)//(factorial(r)*factorial(n-r))) if __name__=="__main__" : m=3 n=4 k=5 totalTriangles=(ncr(m+n+k,3)-ncr(m,3)-ncr(n,3)-ncr(k,3)) print(totalTriangles) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var m : int := 3 ; n := 4 ; var k : int := 5 ; var totalTriangles : double := (ncr(m + n + k, 3) - ncr(m, 3) - ncr(n, 3) - ncr(k, 3)) ; execute (totalTriangles)->display() ) else skip; operation factorial(n : OclAny) : OclAny pre: true post: true activity: var fact : int := 1 ; for i : Integer.subrange(2, n + 1-1) do ( fact := fact * i) ; return fact; operation ncr(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: return (factorial(n) div (factorial(r) * factorial(n - r))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: a,b,c,d=map(int,s.split()); print(max(a+b,c+d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ); execute (Set{a + b, c + d}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def canMake(n,ar): sum=0 ; maxx=-1 ; for i in range(n): sum+=ar[i]; maxx=max(maxx,ar[i]); if(n==1 or sum % 2==1 or sum-maxxunion(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{6}->union(Sequence{ 11 }))))); ; canMake(n, arr); ) else skip; operation canMake(n : OclAny, ar : OclAny) pre: true post: true activity: var sum : int := 0; var maxx : int := -1; ; for i : Integer.subrange(0, n-1) do ( sum := sum + ar[i+1]; ; maxx := Set{maxx, ar[i+1]}->max();) ; if (n = 1 or sum mod 2 = 1 or (sum - maxx->compareTo(maxx)) < 0) then ( execute ("No")->display(); ) else ( execute ("Yes")->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def removeSpecialCharacter(s): t="" for i in s : if(i>='A' and i<='Z')or(i>='a' and i<='z'): t+=i print(t) s="$Gee*k;s..fo,r'Ge^eks?" removeSpecialCharacter(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := "$Gee*k;s..fo,r'Ge^eks?" ; removeSpecialCharacter(s); operation removeSpecialCharacter(s : OclAny) pre: true post: true activity: var t : String := "" ; for i : s do ( if (i >= 'A' & i <= 'Z') or (i >= 'a' & i <= 'z') then ( t := t + i ) else skip) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printMinIndexChar(Str,patt): minIndex=10**9 m=len(Str) n=len(patt) for i in range(n): for j in range(m): if(patt[i]==Str[j]and jpow(9) ; var m : int := (Str)->size() ; var n : int := (patt)->size() ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if (patt[i+1] = Str[j+1] & (j->compareTo(minIndex)) < 0) then ( minIndex := j ; break ) else skip)) ; if (minIndex /= (10)->pow(9)) then ( execute ("Minimum Index Character=")->display() ) else ( execute ("No character present")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def triplet(n,arr): dic={} for i in arr : dic[i]=dic.get(i,0)+1 if dic[i]>=3 : return i return-1 t=int(input()) while t>0 : print(triplet(int(input()),list(map(int,input().split())))) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( execute (triplet(("" + (((OclFile["System.in"]).readLine())))->toInteger(), ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))->display() ; t := t - 1); operation triplet(n : OclAny, arr : OclAny) : OclAny pre: true post: true activity: var dic : OclAny := Set{} ; for i : arr do ( dic[i+1] := dic.get(i, 0) + 1 ; if dic[i+1] >= 3 then ( return i ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for j in range(int(input())): n=int(input()) l=sorted(list(input().split())) k=-1 for i in range(n-2): if l[i]==l[i+1]and l[i+1]==l[i+2]: k=l[i] break print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for j : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := (input().split())->sort() ; var k : int := -1 ; for i : Integer.subrange(0, n - 2-1) do ( if l[i+1] = l[i + 1+1] & l[i + 1+1] = l[i + 2+1] then ( k := l[i+1] ; break ) else skip) ; execute (k)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) x=sorted(list(map(int,input().split()))) if n<3 : print(-1) else : y=-1 for i in range(n-2): if x[i]==x[i+1]and x[i]==x[i+2]: y=x[i] print(y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; if n < 3 then ( execute (-1)->display() ) else ( var y : int := -1 ; for i : Integer.subrange(0, n - 2-1) do ( if x[i+1] = x[i + 1+1] & x[i+1] = x[i + 2+1] then ( y := x[i+1] ) else skip) ; execute (y)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- z=0 def check(s): if n>=3 : for i in range(n-2): if s[i]==s[i+1]==s[i+2]: global z z=s[i] return True return False else : return False t=int(input()) for i in range(t): n=int(input()) s=list(map(int,input().split())) s.sort() if check(s): print(z) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute z : OclAny; operation initialise() pre: true post: true activity: var z : int := 0 ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; s := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; s := s->sort() ; if check(s) then ( execute (z)->display() ) else ( execute (-1)->display() )); operation check(s : OclAny) : OclAny pre: true post: true activity: if n >= 3 then ( for i : Integer.subrange(0, n - 2-1) do ( if s[i+1] = s[i + 1+1] & (s[i + 1+1] == s[i + 2+1]) then ( skip ; z := s[i+1] ; return true ) else skip) ; return false ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) arr=list(map(int,input().split())) arr.sort() f=-1 for i in range(n-2): if arr[i]==arr[i+1]==arr[i+2]: f=arr[i] break print(f) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := arr->sort() ; var f : int := -1 ; for i : Integer.subrange(0, n - 2-1) do ( if arr[i+1] = arr[i + 1+1] & (arr[i + 1+1] == arr[i + 2+1]) then ( f := arr[i+1] ; break ) else skip) ; execute (f)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from collections import deque from collections import Counter Mod=10**9+7 M=10**6*2 fac=[0]*M finv=[0]*M inv=[0]*M def COMinit(): fac[0]=fac[1]=1 finv[0]=finv[1]=1 inv[1]=1 for i in range(2,M): fac[i]=(fac[i-1]*i % Mod)% Mod inv[i]=Mod-inv[Mod % i]*(Mod//i)% Mod finv[i]=(finv[i-1]*inv[i]% Mod)% Mod def COM(n,k): if npow(9) + 7 ; var M : double := (10)->pow(6) * 2 ; var fac : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, M) ; var finv : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, M) ; var inv : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, M) ; skip ; skip ; COMinit() ; k := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; n := (s)->size() ; var ans : int := 0 ; for i : Integer.subrange(0, k + 1-1) do ( ans := ans + COM(n + k - i - 1, n - 1) * (26)->pow(i) * (25)->pow(k - i) ; ans := ans mod Mod) ; execute (ans)->display(); operation COMinit() pre: true post: true activity: fac->first() := 1; var fac[1+1] : int := 1 ; finv->first() := 1; var finv[1+1] : int := 1 ; inv[1+1] := 1 ; for i : Integer.subrange(2, M-1) do ( fac[i+1] := (fac[i - 1+1] * i mod Mod) mod Mod ; inv[i+1] := Mod - inv[Mod mod i+1] * (Mod div i) mod Mod ; finv[i+1] := (finv[i - 1+1] * inv[i+1] mod Mod) mod Mod); operation COM(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (n->compareTo(k)) < 0 then ( return 0 ) else skip ; if n < 0 or k < 0 then ( return 0 ) else skip ; return (fac[n+1] * (finv[k+1] * finv[n - k+1] mod Mod) mod Mod) mod Mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- K=int(input()) S=input() N=len(S) mod=10**9+7 power25=[1]*(K+1) power26=[1]*(K+1) def mod_factorial(n,m): mod_factorials=[1]*(n+1) for i in range(1,n+1): mod_factorials[i]=mod_factorials[i-1]*i mod_factorials[i]%=m return mod_factorials def mod_inv_factorials2(n,m): mod_invs=[1]*(n+1) invs=[1]*(n+1) for i in range(2,n+1): invs[i]=m-invs[m % i]*(m//i)% m for i in range(1,n+1): mod_invs[i]=invs[i]*mod_invs[i-1] mod_invs[i]%=m return mod_invs factrials=mod_factorial(K+N,mod) inv_factrials=mod_inv_factorials2(max(N,K+1),mod) for i in range(1,K+1): power25[i]=(power25[i-1]*25)% mod for i in range(1,K+1): power26[i]=(power26[i-1]*26)% mod ans=0 for i in range(K+1): rk=K-i ans+=power25[rk]*factrials[rk+N-1]*inv_factrials[N-1]*inv_factrials[rk]*power26[i] ans %=mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : String := (OclFile["System.in"]).readLine() ; var N : int := (S)->size() ; var mod : double := (10)->pow(9) + 7 ; var power25 : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (K + 1)) ; var power26 : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (K + 1)) ; skip ; skip ; var factrials : OclAny := mod_factorial(K + N, mod) ; var inv_factrials : OclAny := mod_inv_factorials2(Set{N, K + 1}->max(), mod) ; for i : Integer.subrange(1, K + 1-1) do ( power25[i+1] := (power25[i - 1+1] * 25) mod mod) ; for i : Integer.subrange(1, K + 1-1) do ( power26[i+1] := (power26[i - 1+1] * 26) mod mod) ; var ans : int := 0 ; for i : Integer.subrange(0, K + 1-1) do ( var rk : double := K - i ; ans := ans + power25[rk+1] * factrials[rk + N - 1+1] * inv_factrials[N - 1+1] * inv_factrials[rk+1] * power26[i+1] ; ans := ans mod mod) ; execute (ans)->display(); operation mod_factorial(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var mod_factorials : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ; for i : Integer.subrange(1, n + 1-1) do ( mod_factorials[i+1] := mod_factorials[i - 1+1] * i ; mod_factorials[i+1] := mod_factorials[i+1] mod m) ; return mod_factorials; operation mod_inv_factorials2(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var mod_invs : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ; var invs : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ; for i : Integer.subrange(2, n + 1-1) do ( invs[i+1] := m - invs[m mod i+1] * (m div i) mod m) ; for i : Integer.subrange(1, n + 1-1) do ( mod_invs[i+1] := invs[i+1] * mod_invs[i - 1+1] ; mod_invs[i+1] := mod_invs[i+1] mod m) ; return mod_invs; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def I(): return int(sys.stdin.readline().rstrip()) def LS2(): return list(sys.stdin.readline().rstrip()) K=I() n=len(LS2()) mod=10**9+7 C=[1] for i in range(1,K+1): C.append((C[-1]*(i+n-1)*pow(i,mod-2,mod))% mod) ans=0 for i in range(K+1): ans+=C[i]*pow(25,i,mod)*pow(26,K-i,mod) ans %=mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var K : OclAny := I() ; var n : int := (LS2())->size() ; var mod : double := (10)->pow(9) + 7 ; var C : Sequence := Sequence{ 1 } ; for i : Integer.subrange(1, K + 1-1) do ( execute (((C->last() * (i + n - 1) * (i)->pow(mod - 2)) mod mod) : C)) ; var ans : int := 0 ; for i : Integer.subrange(0, K + 1-1) do ( ans := ans + C[i+1] * (25)->pow(i) * (26)->pow(K - i) ; ans := ans mod mod) ; execute (ans)->display(); operation I() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.readLine().rstrip())))->toInteger(); operation LS2() : OclAny pre: true post: true activity: return (sys.stdin.readLine().rstrip()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxSubarrayLength(A,N): maxLen=0 ; curr_sum=0 ; hash={}; for i in range(N): if(A[i]% 2==0): curr_sum-=1 ; else : curr_sum+=1 ; if(curr_sum==0): maxLen=max(maxLen,i+1); if curr_sum in hash : maxLen=max(maxLen,i-hash[curr_sum]); else : hash[curr_sum]=i ; return maxLen ; if __name__=="__main__" : arr=[12,4,7,8,9,2,11,0,2,13]; n=len(arr); print(maxSubarrayLength(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var arr : Sequence := Sequence{12}->union(Sequence{4}->union(Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{2}->union(Sequence{11}->union(Sequence{0}->union(Sequence{2}->union(Sequence{ 13 }))))))))); ; var n : int := (arr)->size(); ; execute (maxSubarrayLength(arr, n))->display(); ) else skip; operation maxSubarrayLength(A : OclAny, N : OclAny) pre: true post: true activity: var maxLen : int := 0; ; var curr_sum : int := 0; ; var hash : OclAny := Set{}; ; for i : Integer.subrange(0, N-1) do ( if (A[i+1] mod 2 = 0) then ( curr_sum := curr_sum - 1; ) else ( curr_sum := curr_sum + 1; ) ; if (curr_sum = 0) then ( maxLen := Set{maxLen, i + 1}->max(); ) else skip ; if (hash)->includes(curr_sum) then ( maxLen := Set{maxLen, i - hash[curr_sum+1]}->max(); ) else ( hash[curr_sum+1] := i; )) ; return maxLen;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def inv_mod(a,p): p=abs(p) a %=p stack=[] p0=p while a>1 : d,a,p=p//a,p % a,a stack.append(d) x,y=1,0 while stack : d=stack.pop() x,y=y-d*x,x return x % p0 def comb_mod(n,k,p): ans=1 k=min(k,n-k) if k<0 : return 0 for i in range(k): ans=ans*(n-i)*inv_mod(k-i,p)% p return ans MOD=10**9+7 K=int(input()) N=len(input()) f=26*inv_mod(25,MOD)% MOD a=pow(25,K,MOD)*comb_mod(N+K-1,N-1,MOD) ans=0 for r in range(K+1): ans=(ans+a)% MOD a*=(f*(K-r)*inv_mod(N+K-r-1,MOD)) a %=MOD print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var MOD : double := (10)->pow(9) + 7 ; var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var N : int := ((OclFile["System.in"]).readLine())->size() ; var f : int := 26 * inv_mod(25, MOD) mod MOD ; a := (25)->pow(K) * comb_mod(N + K - 1, N - 1, MOD) ; ans := 0 ; for r : Integer.subrange(0, K + 1-1) do ( ans := (ans + a) mod MOD ; a := a * (f * (K - r) * inv_mod(N + K - r - 1, MOD)) ; a := a mod MOD) ; execute (ans)->display(); operation inv_mod(a : OclAny, p : OclAny) : OclAny pre: true post: true activity: p := (p)->abs() ; a := a mod p ; var stack : Sequence := Sequence{} ; var p0 : OclAny := p ; while a > 1 do ( var d : OclAny := null; Sequence{d,a,p} := Sequence{p div a,p mod a,a} ; execute ((d) : stack)) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{1,0} ; while stack do ( var d : OclAny := stack->last() ; stack := stack->front() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{y - d * x,x}) ; return x mod p0; operation comb_mod(n : OclAny, k : OclAny, p : OclAny) : OclAny pre: true post: true activity: var ans : int := 1 ; k := Set{k, n - k}->min() ; if k < 0 then ( return 0 ) else skip ; for i : Integer.subrange(0, k-1) do ( ans := ans * (n - i) * inv_mod(k - i, p) mod p) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) a=list(map(int,input().split())) x=[[]for _ in range(n+1)] for i in range(2*n): x[a[i]].append(i) x[0]=[0,0] ans=0 for i in range(n): u,v=x[i],x[i+1] ans+=min(abs(u[0]-v[0])+abs(u[1]-v[1]),abs(u[0]-v[1])+abs(u[1]-v[0])) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, 2 * n-1) do ((expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; x->first() := Sequence{0}->union(Sequence{ 0 }) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := Sequence{x[i+1],x[i + 1+1]} ; ans := ans + Set{(u->first() - v->first())->abs() + (u[1+1] - v[1+1])->abs(), (u->first() - v[1+1])->abs() + (u[1+1] - v->first())->abs()}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): K=int(input()) S=input() mod=pow(10,9)+7 N=len(S) g1=[1,1] g2=[1,1] inv=[0,1] for i in range(2,K+N+1): g1.append((g1[-1]*i)% mod) inv.append((-inv[mod % i]*(mod//i))% mod) g2.append((g2[-1]*inv[-1])% mod) def combi(n,r): r=min(r,n-r) return g1[n]*g2[r]*g2[n-r]% mod pow25=[1] pow26=[1] for i in range(K): pow25.append(pow25[-1]*25 % mod) pow26.append(pow26[-1]*26 % mod) ans=0 for i in range(N-1,N+K): ans+=combi(i,N-1)*pow25[i-N+1]% mod*pow26[K-i+N-1]% mod ans %=mod return ans if __name__=='__main__' : print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( execute (main())->display() ) else skip; operation main() : OclAny pre: true post: true activity: var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : String := (OclFile["System.in"]).readLine() ; var mod : double := (10)->pow(9) + 7 ; var N : int := (S)->size() ; var g1 : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var g2 : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var inv : Sequence := Sequence{0}->union(Sequence{ 1 }) ; for i : Integer.subrange(2, K + N + 1-1) do ( execute (((g1->last() * i) mod mod) : g1) ; execute (((-inv[mod mod i+1] * (mod div i)) mod mod) : inv) ; execute (((g2->last() * inv->last()) mod mod) : g2)) ; skip ; var pow25 : Sequence := Sequence{ 1 } ; var pow26 : Sequence := Sequence{ 1 } ; for i : Integer.subrange(0, K-1) do ( execute ((pow25->last() * 25 mod mod) : pow25) ; execute ((pow26->last() * 26 mod mod) : pow26)) ; var ans : int := 0 ; for i : Integer.subrange(N - 1, N + K-1) do ( ans := ans + combi(i, N - 1) * pow25[i - N + 1+1] mod mod * pow26[K - i + N - 1+1] mod mod ; ans := ans mod mod) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=int(input()) cars_in=m max_cars_in=cars_in is_negative=False for i in range(n): a,b=map(int,input().split()) cars_in=cars_in+a-b max_cars_in=max(max_cars_in,cars_in) if cars_in<0 : is_negative=True if is_negative : print(0) else : print(max_cars_in) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cars_in : int := m ; var max_cars_in : int := cars_in ; var is_negative : boolean := false ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; cars_in := cars_in + a - b ; max_cars_in := Set{max_cars_in, cars_in}->max() ; if cars_in < 0 then ( is_negative := true ) else skip) ; if is_negative then ( execute (0)->display() ) else ( execute (max_cars_in)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque n,m=int(input()),int(input()) B,S=0,m d=deque([0]*m) for _ in range(n): cars=list(map(int,input().split())) for _ in range(cars[0]): d.append(0) try : for _ in range(cars[1]): d.pop() except IndexError : B=1 S=max(S,len(d)) print(0 if B else S) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),("" + (((OclFile["System.in"]).readLine())))->toInteger()} ; var B : OclAny := null; var S : OclAny := null; Sequence{B,S} := Sequence{0,m} ; var d : Sequence := (MatrixLib.elementwiseMult(Sequence{ 0 }, m)) ; for _anon : Integer.subrange(0, n-1) do ( var cars : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for _anon : Integer.subrange(0, cars->first()-1) do ( execute ((0) : d)) ; try ( for _anon : Integer.subrange(0, cars[1+1]-1) do ( d := d->front())) (except_clause except (test (logical_test (comparison (expr (atom (name IndexError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name B)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) ; var S : OclAny := Set{S, (d)->size()}->max()) ; execute (if B then 0 else S endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : duration=int(input()) cars_in_tunnel=int(input()) data=[] for _ in range(duration): data.append([int(x)for x in input().split(' ')]) max_cars=cars_in_tunnel error_detected=False for car_in,car_out in data : cars_in_tunnel+=car_in cars_in_tunnel-=car_out if cars_in_tunnel<0 : error_detected=True break else : max_cars=max(max_cars,cars_in_tunnel) if error_detected is False : print(max_cars) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var duration : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cars_in_tunnel : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var data : Sequence := Sequence{} ; for _anon : Integer.subrange(0, duration-1) do ( execute ((input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) : data)) ; var max_cars : int := cars_in_tunnel ; var error_detected : boolean := false ; for _tuple : data do (var _indx : int := 1; var car_in : OclAny := _tuple->at(_indx); _indx := _indx + 1; var car_out : OclAny := _tuple->at(_indx); cars_in_tunnel := cars_in_tunnel + car_in ; cars_in_tunnel := cars_in_tunnel - car_out ; if cars_in_tunnel < 0 then ( error_detected := true ; break ) else ( max_cars := Set{max_cars, cars_in_tunnel}->max() )) ; if error_detected <>= false then ( execute (max_cars)->display() ) else ( execute (0)->display() ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input() a=s=int(input()) for e in sys.stdin : i,o=map(int,e.split()) s+=i-o if s<0 : a=0 ; break if atoInteger(); var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for e : OclFile["System.in"] do ( var i : OclAny := null; var o : OclAny := null; Sequence{i,o} := (e.split())->collect( _x | (OclType["int"])->apply(_x) ) ; s := s + i - o ; if s < 0 then ( a := 0; break ) else skip ; if (a->compareTo(s)) < 0 then ( a := s ) else skip) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=int(input()) j=[list(map(int,input().split()))for _ in range(n)] ans=m for x in j : m+=x[0]-x[1] ans=max(ans,m) if m<0 : ans=0 break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var j : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ans : int := m ; for x : j do ( m := m + x->first() - x[1+1] ; ans := Set{ans, m}->max() ; if m < 0 then ( ans := 0 ; break ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sticks=[6,7,4,6,5,4,6,5,2,4,4,3,6,6,6,5,7,6,5,3,5,4,6,4,3,4]; number=[6,2,5,5,4,5,6,3,7,6]; def countSticks(string): cnt=0 ; for i in range(len(string)): ch=string[i]; if(ch>='A' and ch<='Z'): cnt+=sticks[ord(ch)-ord('A')]; else : cnt+=number[ord(ch)-ord('0')]; return cnt ; if __name__=="__main__" : string="GEEKSFORGEEKS" ; print(countSticks(string)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sticks : Sequence := Sequence{6}->union(Sequence{7}->union(Sequence{4}->union(Sequence{6}->union(Sequence{5}->union(Sequence{4}->union(Sequence{6}->union(Sequence{5}->union(Sequence{2}->union(Sequence{4}->union(Sequence{4}->union(Sequence{3}->union(Sequence{6}->union(Sequence{6}->union(Sequence{6}->union(Sequence{5}->union(Sequence{7}->union(Sequence{6}->union(Sequence{5}->union(Sequence{3}->union(Sequence{5}->union(Sequence{4}->union(Sequence{6}->union(Sequence{4}->union(Sequence{3}->union(Sequence{ 4 }))))))))))))))))))))))))); ; var number : Sequence := Sequence{6}->union(Sequence{2}->union(Sequence{5}->union(Sequence{5}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{3}->union(Sequence{7}->union(Sequence{ 6 }))))))))); ; skip ; if __name__ = "__main__" then ( string := "GEEKSFORGEEKS"; ; execute (countSticks(string))->display(); ) else skip; operation countSticks(string : OclAny) pre: true post: true activity: var cnt : int := 0; ; for i : Integer.subrange(0, (string)->size()-1) do ( var ch : OclAny := string[i+1]; ; if (ch >= 'A' & ch <= 'Z') then ( cnt := cnt + sticks[(ch)->char2byte() - ('A')->char2byte()+1]; ) else ( cnt := cnt + number[(ch)->char2byte() - ('0')->char2byte()+1]; )) ; return cnt;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- prime=[True]*(100005) def SieveOfEratosthenes(n): prime[1]=False p=2 while p*p<=n : if prime[p]: for i in range(p*2,n+1,p): prime[i]=False p+=1 def xorPrimes(arr,n): SieveOfEratosthenes(100004) xorVal=0 for i in range(0,n): if prime[arr[i]]: xorVal=xorVal ^ arr[i] return xorVal if __name__=="__main__" : arr=[4,3,2,6,100,17] n=len(arr) print(xorPrimes(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (100005)) ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{4}->union(Sequence{3}->union(Sequence{2}->union(Sequence{6}->union(Sequence{100}->union(Sequence{ 17 }))))) ; n := (arr)->size() ; execute (xorPrimes(arr, n))->display() ) else skip; operation SieveOfEratosthenes(n : OclAny) pre: true post: true activity: prime[1+1] := false ; var p : int := 2 ; while (p * p->compareTo(n)) <= 0 do ( if prime[p+1] then ( for i : Integer.subrange(p * 2, n + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip ; p := p + 1); operation xorPrimes(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: SieveOfEratosthenes(100004) ; var xorVal : int := 0 ; for i : Integer.subrange(0, n-1) do ( if prime[arr[i+1]+1] then ( xorVal := MathLib.bitwiseXor(xorVal, arr[i+1]) ) else skip) ; return xorVal; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : try : s=input() except : break t=input() if len(s)size()->compareTo((t)->size())) < 0 then ( Sequence{s,t} := Sequence{t,s} ) else skip ; var a : OclAny := ((argument (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name t)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))) & (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) ))))))))))->sum() ; var b : int := 0 ; for x : Integer.subrange(0, (t)->size()-1) do ( if ((t)->size() - x->compareTo(b)) <= 0 then ( break ) else skip ; for y : Integer.subrange(b + 1, Set{a + 1, (t)->size() - x + 1}->min()-1) do ( if (s)->characters()->includes(t.subrange(x+1, x + y)) then ( b := y ) else ( break ))) ; execute (b)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPossible(l,m,x,y): if(l*m==x+y): return True ; return False ; if __name__=="__main__" : l=3 ; m=2 ; x=4 ; y=2 ; if(isPossible(l,m,x,y)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( l := 3; m := 2; x := 4; y := 2; ; if (isPossible(l, m, x, y)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ) else skip; operation isPossible(l : OclAny, m : OclAny, x : OclAny, y : OclAny) pre: true post: true activity: if (l * m = x + y) then ( return true; ) else skip ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- count=0 n=input() if int(n)>=3 and int(n)<=100 : word=input()[: int(n)] i=1 flag=False while flag==False : if "xxx" in word : count_x=word.count("xxx") count=count+count_x word=word.replace("xxx","xx") else : flag=True i+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var count : int := 0 ; var n : String := (OclFile["System.in"]).readLine() ; if ("" + ((n)))->toInteger() >= 3 & ("" + ((n)))->toInteger() <= 100 then ( var word : OclAny := input().subrange(1,("" + ((n)))->toInteger()) ; var i : int := 1 ; var flag : boolean := false ; while flag = false do ( if (word)->includes("xxx") then ( var count_x : int := word->count("xxx") ; count := count + count_x ; word := word.replace("xxx", "xx") ) else ( flag := true ) ; i := i + 1) ; execute (count)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rolling_hash(S,base,MOD): l=len(S) h=[0]*(l+1) for i in range(l): h[i+1]=(h[i]*base+ord(S[i]))% MOD return h C=open(0).read().split() MOD=358976445361682909 base=31 for t in range(len(C)//2): S=C[2*t]; T=C[2*t+1] rhs=rolling_hash(S,base,MOD) rht=rolling_hash(T,base,MOD) L=len(S); M=len(T) def solve(l): v=pow(base,l,MOD) hs=set() for i in range(L-l+1): hs.add((rhs[i+l]-rhs[i]*v)% MOD) for i in range(M-l+1): if(rht[i+l]-rht[i]*v)% MOD in hs : return 1 return 0 left=0 ; right=min(L,M)+1 while left+1size() div 2-1) do ( S := C[2 * t+1]; var T : OclAny := C[2 * t + 1+1] ; var rhs : OclAny := rolling_hash(S, base, MOD) ; var rht : OclAny := rolling_hash(T, base, MOD) ; var L : int := (S)->size(); var M : int := (T)->size() ; skip ; var left : int := 0; var right : OclAny := Set{L, M}->min() + 1 ; while (left + 1->compareTo(right)) < 0 do ( var mid : int := (left + right) div 2 ; if solve(mid) then ( left := mid ) else ( right := mid )) ; execute (left)->display()); operation rolling_hash(S : OclAny, base : OclAny, MOD : OclAny) : OclAny pre: true post: true activity: var l : int := (S)->size() ; var h : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (l + 1)) ; for i : Integer.subrange(0, l-1) do ( h[i + 1+1] := (h[i+1] * base + (S[i+1])->char2byte()) mod MOD) ; return h; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import division,print_function try : input=raw_input range=xrange except NameError : pass p,q=10**9+7,0xffffffff pow_p=[1] for i in range(4010): pow_p.append(pow_p[-1]*p & q) def exists(a,b,k): n,m=len(a),len(b) s=[a[k+i]-a[i]*pow_p[k]& q for i in range(n-k)] t=[b[k+i]-b[i]*pow_p[k]& q for i in range(m-k)] return len(set(s).intersection(set(t)))>0 def hash(s): t=0 yield t for c in s : t=t*p+ord(c)& q yield t return def solve(s,t): n,m=len(s),len(t) a,b=list(hash(s)),list(hash(t)) l,r=0,min(n,m)+1 while l+1pow(9) + 7,0xffffffff} ; var pow_p : Sequence := Sequence{ 1 } ; for i : Integer.subrange(0, 4010-1) do ( execute ((MathLib.bitwiseAnd(pow_p->last() * p, q)) : pow_p)) ; skip ; skip ; skip ; while true do ( try ( s := input()->trim() ; t := input()->trim()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))) ; execute (solve(s, t))->display()); operation exists(a : OclAny, b : OclAny, k : OclAny) : OclAny pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{(a)->size(),(b)->size()} ; var s : Sequence := Integer.subrange(0, n - k-1)->select(i | true)->collect(i | (MathLib.bitwiseAnd(a[k + i+1] - a[i+1] * pow_p[k+1], q))) ; var t : Sequence := Integer.subrange(0, m - k-1)->select(i | true)->collect(i | (MathLib.bitwiseAnd(b[k + i+1] - b[i+1] * pow_p[k+1], q))) ; return (Set{}->union((s))->intersection(Set{}->union((t))))->size() > 0; operation hash(s : OclAny) pre: true post: true activity: t := 0 ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return t ; for c : s do ( t := MathLib.bitwiseAnd(MatrixLib.elementwiseAdd(MatrixLib.elementwiseMult(t, p), (c)->char2byte()), q) ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return t) ; return; operation solve(s : OclAny, t : OclAny) : OclAny pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{(s)->size(),(t)->size()} ; Sequence{a,b} := Sequence{(hash(s)),(hash(t))} ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,Set{n, m}->min() + 1} ; while (l + 1->compareTo(r)) < 0 do ( var m : int := (l + r) div 2 ; if exists(a, b, m) then ( var l : int := m ) else ( var r : int := m )) ; return l; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : s1=input() except EOFError : break s2=input() BASE=27 MOD=1000000007 def rolling_hash(s): h_lst=[0] for c in s : h_lst.append((h_lst[-1]*BASE+ord(c))% MOD) return h_lst h_lst1=rolling_hash(s1) h_lst2=rolling_hash(s2) length1=len(s1) length2=len(s2) pow_mem=[pow(BASE,i,MOD)for i in range(min(length1,length2)+1)] def check(center): hash_set={(h_lst1[i+center]-h_lst1[i]*pow_mem[center])% MOD for i in range(length1-center+1)} for i in range(length2-center+1): h2=(h_lst2[i+center]-h_lst2[i]*pow_mem[center])% MOD if h2 in hash_set : return True return False left=0 right=min(length1,length2) while right>left+1 : center=(left+right)//2 if check(center): left=center else : right=center print(right if check(right)else left) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var s1 : String := (OclFile["System.in"]).readLine()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))) ; var s2 : String := (OclFile["System.in"]).readLine() ; var BASE : int := 27 ; var MOD : int := 1000000007 ; skip ; var h_lst1 : OclAny := rolling_hash(s1) ; var h_lst2 : OclAny := rolling_hash(s2) ; var length1 : int := (s1)->size() ; var length2 : int := (s2)->size() ; var pow_mem : Sequence := Integer.subrange(0, Set{length1, length2}->min() + 1-1)->select(i | true)->collect(i | ((BASE)->pow(i))) ; skip ; var left : int := 0 ; var right : OclAny := Set{length1, length2}->min() ; while (right->compareTo(left + 1)) > 0 do ( center := (left + right) div 2 ; if check(center) then ( left := center ) else ( right := center )) ; execute (if check(right) then right else left endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count(n): cnt=0 p=1 while(p<=n): cnt=cnt+1 p*=2 return cnt n=7 print(count(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 7 ; execute (count(n))->display();; operation count(n : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; var p : int := 1 ; while ((p->compareTo(n)) <= 0) do ( cnt := cnt + 1 ; p := p * 2) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[] n=0 ans=0 def DFS(x,h): global a,n,ans if htoInteger() ; var s : String := (OclFile["System.in"]).readLine() ; s := s.split() ; for i : s->characters() do ( execute ((("" + ((i)))->toInteger()) : a)) ; DFS(0, 1) ; execute (ans)->display(); operation DFS(x : OclAny, h : OclAny) pre: true post: true activity: skip; skip; skip ; if (h->compareTo(n)) < 0 then ( DFS(2 * x + 1, h + 1) ; DFS(2 * x + 2, h + 1) ; a[2 * x+1] := a[2 * x+1] + Set{a[2 * (2 * x + 1)+1], a[2 * (2 * x + 1) + 1+1]}->max() ; a[2 * x + 1+1] := a[2 * x + 1+1] + Set{a[2 * (2 * x + 2)+1], a[2 * (2 * x + 2) + 1+1]}->max() ) else skip ; ans := ans + (a[2 * x+1] - a[x * 2 + 1+1])->abs(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) park=[0]*(2**(n+1)) park[2 : 2**(n+1)]=[int(i)for i in input().split()] cnt=0 for i in range(2**n-1,0,-1): cnt+=abs(park[i*2+1]-park[i*2]) park[i]+=max(park[i*2+1],park[i*2]) print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var park : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((2)->pow((n + 1)))) ; park.subrange(2+1, (2)->pow((n + 1))) := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var cnt : int := 0 ; for i : Integer.subrange(0 + 1, (2)->pow(n) - 1)->reverse() do ( cnt := cnt + (park[i * 2 + 1+1] - park[i * 2+1])->abs() ; park[i+1] := park[i+1] + Set{park[i * 2 + 1+1], park[i * 2+1]}->max()) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys import collections def In(): return map(int,sys.stdin.readline().split()) def omnompark(): n=int(input()) l=list(In()) ans=0 for i in range(len(l)-1,-1,-1): if i % 2 : if l[i-1]>l[i]: ans+=l[i-1]-l[i] l[i]=l[i-1] else : ans+=l[i]-l[i-1] l[i-1]=l[i] l[i//2-1]+=l[i] return ans print(omnompark()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; execute (omnompark())->display(); operation In() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation omnompark() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := (In()) ; var ans : int := 0 ; for i : Integer.subrange(-1 + 1, (l)->size() - 1)->reverse() do ( if i mod 2 then ( if (l[i - 1+1]->compareTo(l[i+1])) > 0 then ( ans := ans + l[i - 1+1] - l[i+1] ; l[i+1] := l[i - 1+1] ) else ( ans := ans + l[i+1] - l[i - 1+1] ; l[i - 1+1] := l[i+1] ) ; l[i div 2 - 1+1] := l[i div 2 - 1+1] + l[i+1] ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys import collections def In(): return map(int,sys.stdin.readline().split()) def omnompark(): n=int(input()) l=list(In()) ans=0 for i in range(len(l)-1-(not((len(l)-1)% 2)),-1,-2): ans+=abs(l[i-1]-l[i]) l[i]=l[i-1]=max(l[i],l[i-1]) l[i//2-1]+=l[i] return ans print(omnompark()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; execute (omnompark())->display(); operation In() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation omnompark() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := (In()) ; var ans : int := 0 ; for i : Integer.subrange((l)->size() - 1 - (not((((l)->size() - 1) mod 2))), -1-1)->select( $x | ($x - (l)->size() - 1 - (not((((l)->size() - 1) mod 2)))) mod -2 = 0 ) do ( ans := ans + (l[i - 1+1] - l[i+1])->abs() ; l[i+1] := Set{l[i+1], l[i - 1+1]}->max(); var l[i - 1+1] : OclAny := Set{l[i+1], l[i - 1+1]}->max() ; l[i div 2 - 1+1] := l[i div 2 - 1+1] + l[i+1]) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys import collections def In(): return map(int,sys.stdin.readline().split()) def omnompark(): n=int(input()) l=list(In()) ans=0 for i in range(len(l)-1,-1,-2): ans+=abs(l[i-1]-l[i]) l[i//2-1]+=max(l[i],l[i-1]) return ans print(omnompark()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; execute (omnompark())->display(); operation In() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation omnompark() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := (In()) ; var ans : int := 0 ; for i : Integer.subrange((l)->size() - 1, -1-1)->select( $x | ($x - (l)->size() - 1) mod -2 = 0 ) do ( ans := ans + (l[i - 1+1] - l[i+1])->abs() ; l[i div 2 - 1+1] := l[i div 2 - 1+1] + Set{l[i+1], l[i - 1+1]}->max()) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : try : ab,s=list(input().split('=')) a,b=list(ab.split('+')) start=0 if(len(a)>1 and a[0]=='X')or(len(b)>1 and b[0]=='X')or(len(s)>1 and s[0]=='X'): start=1 flg=1 for x in range(start,10): new_a=a.replace('X',str(x)) new_b=b.replace('X',str(x)) new_s=s.replace('X',str(x)) if int(new_a)+int(new_b)==int(new_s): flg=0 print(x) break if flg : print('NA') except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( try ( var ab : OclAny := null; var s : OclAny := null; Sequence{ab,s} := (input().split('=')) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (ab.split('+')) ; var start : int := 0 ; if ((a)->size() > 1 & a->first() = 'X') or ((b)->size() > 1 & b->first() = 'X') or ((s)->size() > 1 & s->first() = 'X') then ( start := 1 ) else skip ; var flg : int := 1 ; for x : Integer.subrange(start, 10-1) do ( var new_a : String := a.replace('X', ("" + ((x)))) ; var new_b : String := b.replace('X', ("" + ((x)))) ; var new_s : String := s.replace('X', ("" + ((x)))) ; if ("" + ((new_a)))->toInteger() + ("" + ((new_b)))->toInteger() = ("" + ((new_s)))->toInteger() then ( flg := 0 ; execute (x)->display() ; break ) else skip) ; if flg then ( execute ('NA')->display() ) else skip) catch (_e : OclException) do ( break) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict n=int(input()) a=list(map(int,input().strip().split())) d=defaultdict(list) for i in range(len(a)): d[a[i]].append(i+1) c=e=0 p1=p2=1 for x in range(1,n+1): mn=min(d[x]) mx=max(d[x]) c+=abs(mn-p1) e+=abs(mx-p2) p1=mn p2=mx print(c+e) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := defaultdict(OclType["Sequence"]) ; for i : Integer.subrange(0, (a)->size()-1) do ((expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ))))) ; var c : OclAny := 0; var e : int := 0 ; var p1 : OclAny := 1; var p2 : int := 1 ; for x : Integer.subrange(1, n + 1-1) do ( var mn : OclAny := (d[x+1])->min() ; var mx : OclAny := (d[x+1])->max() ; c := c + (mn - p1)->abs() ; e := e + (mx - p2)->abs() ; p1 := mn ; p2 := mx) ; execute (c + e)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def unitnumber(x,y): x=x % 10 if y!=0 : y=y % 4+4 return(((int)(math.pow(x,y)))% 10) x=133 ; y=5 print(unitnumber(x,y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; x := 133; y := 5 ; execute (unitnumber(x, y))->display(); operation unitnumber(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: x := x mod 10 ; if y /= 0 then ( y := y mod 4 + 4 ) else skip ; return (((OclType["int"])((x)->pow(y))) mod 10); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for line in open(0).readlines(): s=line.strip() a,s=s.split("+") b,c=s.split("=") f=lambda x : len(x)>1 and x[0]=='X' g=lambda s,x : int(s.replace("X",str(x))) for x in range(f(a)or f(b)or f(c),10): if g(a,x)+g(b,x)==g(c,x): print(x) break else : print("NA") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for line : open(0).readlines() do ( var s : String := line->trim() ; var a : OclAny := null; Sequence{a,s} := s.split("+") ; var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := s.split("=") ; var f : Function := lambda x : OclAny in ((x)->size() > 1 & x->first() = 'X') ; var g : Function := lambda s : OclAny, x : OclAny in (("" + ((s.replace("X", ("" + ((x)))))))->toInteger()) ; (compound_stmt for (exprlist (expr (atom (name x)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (logical_test (logical_test (comparison (expr (atom (name f)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))))) or (logical_test (comparison (expr (atom (name f)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) ))))))) or (logical_test (comparison (expr (atom (name f)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 10))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name g)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) + (expr (atom (name g)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b))))))) , (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))))) == (comparison (expr (atom (name g)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c))))))) , (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NA"))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys p,t='+X' for e in sys.stdin : for i in '0123456789'[(e[0]==t)*(e[1]!=p)or('+X' in e)*('+X=' not in e):]: l,r=e.replace(t,i).split('=') if sum(map(int,l.split(p)))==int(r): print(i); break else : print('NA') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var p : OclAny := null; var t : OclAny := null; Sequence{p,t} := '+X' ; for e : OclFile["System.in"] do ((compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom '0123456789') (trailer (arguments [ (subscriptlist (subscript (test (logical_test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) == (comparison (expr (atom (name t)))))))) ))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) != (comparison (expr (atom (name p)))))))) )))))) or (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom '+X'))) in (comparison (expr (atom (name e)))))))) ))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom '+X='))) not in (comparison (expr (atom (name e)))))))) )))))))) :)) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name l)))))) , (test (logical_test (comparison (expr (atom (name r))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name e)) (trailer . (name replace) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t))))))) , (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '='))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name l)) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p)))))))) ))))))))) ))))))))) ))))) == (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name r)))))))) )))))))) : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))) ; (small_stmt break)))))) (else_clause else : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NA'))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re,sys def chk(t): for i in range(10): e=re.split("[+=]",re.sub("X",str(i),t)) if(e[0][0]=="0" and len(e[0])>1)or(e[1][0]=="0" and len(e[1])>1)or(e[2][0]=="0" and len(e[2])>1): continue if eval(e[0]+"+"+e[1])==eval(e[2]): return i return 10 l=[chk(i.strip())for i in sys.stdin] [print(i)if i!=10 else print("NA")for i in l] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var l : Sequence := OclFile["System.in"]->select(i | true)->collect(i | (chk(i->trim()))) ; ; operation chk(t : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, 10-1) do ( var e : Sequence(String) := ((t).replaceAllMatches("X", ("" + ((i)))))->split("[+=]") ; if (e->first()->first() = "0" & (e->first())->size() > 1) or (e[1+1]->first() = "0" & (e[1+1])->size() > 1) or (e[2+1]->first() = "0" & (e[2+1])->size() > 1) then ( continue ) else skip ; if e->first() + "+" + e[1+1] = e[2+1] then ( return i ) else skip) ; return 10; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : s=input() except : break t,sc=s.split("=") sa,sb=t.split("+") if(len(sa)>1 and sa[0]=='X')or(len(sb)>1 and sb[0]=='X')or(len(sc)>1 and sc[0]=='X'): start=1 else : start=0 f=0 for i in range(start,10): na=int(sa.replace("X",str(i))) nb=int(sb.replace("X",str(i))) nc=int(sc.replace("X",str(i))) if na+nb==nc : f+=1 break if f>0 : print(i) else : print("NA") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var s : String := (OclFile["System.in"]).readLine()) catch (_e : OclException) do ( break) ; var t : OclAny := null; var sc : OclAny := null; Sequence{t,sc} := s.split("=") ; var sa : OclAny := null; var sb : OclAny := null; Sequence{sa,sb} := t.split("+") ; if ((sa)->size() > 1 & sa->first() = 'X') or ((sb)->size() > 1 & sb->first() = 'X') or ((sc)->size() > 1 & sc->first() = 'X') then ( var start : int := 1 ) else ( start := 0 ) ; var f : int := 0 ; for i : Integer.subrange(start, 10-1) do ( var na : int := ("" + ((sa.replace("X", ("" + ((i)))))))->toInteger() ; var nb : int := ("" + ((sb.replace("X", ("" + ((i)))))))->toInteger() ; var nc : int := ("" + ((sc.replace("X", ("" + ((i)))))))->toInteger() ; if na + nb = nc then ( f := f + 1 ; break ) else skip) ; if f > 0 then ( execute (i)->display() ) else ( execute ("NA")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def square(a): if(a<0): return-1 x=0.464*a return x a=5 print(square(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 5 ; execute (square(a))->display(); operation square(a : OclAny) : OclAny pre: true post: true activity: if (a < 0) then ( return -1 ) else skip ; var x : double := 0.464 * a ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(m,arr): ans=0 for x in range(len(arr)): ans+=abs(m-arr[x])/d return ans nmd=[int(x)for x in input().split()] n=nmd[0] m=nmd[1] d=nmd[2] status=True arr=[] for x in range(n): arr+=[int(i)for i in input().split()] for x in arr : i=arr[0]% d if x % d!=i : status=False if status==True : l=0 r=1e4 while(r>l+2): m1=l+(r-l)//3 m2=m1+(r-l)//3 if(f(m1,arr)>f(m2,arr)): l=m1 else : r=m2 print(int(min(f(l,arr),f(l+1,arr),f(l+2,arr)))) else : print("-1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var nmd : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var n : OclAny := nmd->first() ; m := nmd[1+1] ; var d : OclAny := nmd[2+1] ; var status : boolean := true ; arr := Sequence{} ; for x : Integer.subrange(0, n-1) do ( arr := arr + input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))) ; for x : arr do ( var i : int := arr->first() mod d ; if x mod d /= i then ( status := false ) else skip) ; if status = true then ( var l : int := 0 ; var r : double := ("1e4")->toReal() ; while ((r->compareTo(l + 2)) > 0) do ( var m1 : int := l + (r - l) div 3 ; var m2 : int := m1 + (r - l) div 3 ; if ((f(m1, arr)->compareTo(f(m2, arr))) > 0) then ( l := m1 ) else ( r := m2 )) ; execute (("" + ((Set{f(l, arr), f(l + 1, arr), f(l + 2, arr)}->min())))->toInteger())->display() ) else ( execute ("-1")->display() ); operation f(m : OclAny, arr : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for x : Integer.subrange(0, (arr)->size()-1) do ( ans := ans + (m - arr[x+1])->abs() / d) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,d=map(int,input().split()) arr=[] remainder=-1 flag=True for _ in range(n): for i in input().split(): arr.append(int(i)) temp=int(i)% d if remainder==-1 : remainder=temp elif remainder!=-1 and temp!=remainder : flag=False break if flag==False : break if flag : arr.sort() k=n*m sum_mod=0 mid=arr[int(k/2)] for i in range(k): sum_mod+=abs(arr[i]-mid) if flag : print(int(sum_mod/d)) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var d : OclAny := null; Sequence{n,m,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := Sequence{} ; var remainder : int := -1 ; var flag : boolean := true ; for _anon : Integer.subrange(0, n-1) do ( for i : input().split() do ( execute ((("" + ((i)))->toInteger()) : arr) ; var temp : int := ("" + ((i)))->toInteger() mod d ; if remainder = -1 then ( remainder := temp ) else (if remainder /= -1 & temp /= remainder then ( flag := false ; break ) else skip)) ; if flag = false then ( break ) else skip) ; if flag then ( arr := arr->sort() ; var k : double := n * m ; var sum_mod : int := 0 ; var mid : OclAny := arr[("" + ((k / 2)))->toInteger()+1] ; for i : Integer.subrange(0, k-1) do ( sum_mod := sum_mod + (arr[i+1] - mid)->abs()) ) else skip ; if flag then ( execute (("" + ((sum_mod / d)))->toInteger())->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def matrix(): n,m,d=map(int,input().split()) ls=list() for i in range(n): ls+=list(map(int,input().split())) ls.sort() mid=ls[n*m//2] count=0 for i in ls : if abs(i-mid)% d!=0 : return-1 count+=abs(i-mid)//d return count print(matrix()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (matrix())->display(); operation matrix() : OclAny pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var d : OclAny := null; Sequence{n,m,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ls : Sequence := () ; for i : Integer.subrange(0, n-1) do ( ls := ls + ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; ls := ls->sort() ; var mid : OclAny := ls[n * m div 2+1] ; var count : int := 0 ; for i : ls do ( if (i - mid)->abs() mod d /= 0 then ( return -1 ) else skip ; count := count + (i - mid)->abs() div d) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,d=[int(x)for x in input().split()] arr=[None for i in range(m*n)] for i in range(n): temp=[int(x)for x in input().split()] for j in range(m): arr[(i)*m+j]=temp[j] arr.sort() ans=float('inf') flag=0 for i in range(n*m): if flag==1 : break temp=0 for j in range(n*m): if(arr[j]-arr[i])% d!=0 : flag=1 break temp+=abs(arr[j]-arr[i]) temp=temp//d if tempselect(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var arr : Sequence := Integer.subrange(0, m * n-1)->select(i | true)->collect(i | (null)) ; for i : Integer.subrange(0, n-1) do ( var temp : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for j : Integer.subrange(0, m-1) do ( arr[(i) * m + j+1] := temp[j+1])) ; arr := arr->sort() ; var ans : double := ("" + (('inf')))->toReal() ; var flag : int := 0 ; for i : Integer.subrange(0, n * m-1) do ( if flag = 1 then ( break ) else skip ; temp := 0 ; for j : Integer.subrange(0, n * m-1) do ( if (arr[j+1] - arr[i+1]) mod d /= 0 then ( flag := 1 ; break ) else skip ; temp := temp + (arr[j+1] - arr[i+1])->abs()) ; temp := temp div d ; if (temp->compareTo(ans)) < 0 then ( ans := temp ) else skip) ; if flag = 0 then ( execute (ans)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[()]*int(input()) i=0 for x in map(int,input().split()): a[x-1]+=i,; i+=1 print(sum(abs(x-y)for t in zip(*a)for x,y in zip((0,)+t,t))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := MatrixLib.elementwiseMult(Sequence{ () }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var i : int := 0 ; for x : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( a[x - 1+1] := a[x - 1+1] + (testlist (test (logical_test (comparison (expr (atom (name i)))))) ,); i := i + 1) ; execute (((argument (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (name y))))))))) ))))))) (comp_for for (exprlist (expr (atom (name t)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom (name a)))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name x))) , (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) ,) ))) + (expr (atom (name t)))))))) , (argument (test (logical_test (comparison (expr (atom (name t)))))))) )))))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): arr.sort() ans=0 ind=(n*m)//2 for i in range(n*m): if i==ind : continue if abs(arr[i]-arr[ind])% d!=0 : return-1 else : ans+=abs(arr[i]-arr[ind])//d return int(ans) from sys import stdin input=stdin.readline n,m,d=[int(x)for x in input().split()] arr=[] for i in range(n): arr.extend([int(x)for x in input().split()]) print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; var n : OclAny := null; var m : OclAny := null; var d : OclAny := null; Sequence{n,m,d} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var arr : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( arr := arr->union(input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))) ; execute (solve())->display(); operation solve() : OclAny pre: true post: true activity: arr := arr->sort() ; var ans : int := 0 ; var ind : int := (n * m) div 2 ; for i : Integer.subrange(0, n * m-1) do ( if i = ind then ( continue ) else skip ; if (arr[i+1] - arr[ind+1])->abs() mod d /= 0 then ( return -1 ) else ( ans := ans + (arr[i+1] - arr[ind+1])->abs() div d )) ; return ("" + ((ans)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSplitPoint(arr,n): leftSum=0 for i in range(0,n): leftSum+=arr[i] rightSum=0 for j in range(i+1,n): rightSum+=arr[j] if(leftSum==rightSum): return i+1 return-1 def printTwoParts(arr,n): splitPo=findSplitPoint(arr,n) if(splitPo==-1 or splitPo==n): print("Not Possible") return for i in range(0,n): if(splitPo==i): print("") print(str(arr[i])+'',end='') arr=[1,2,3,4,5,5] n=len(arr) printTwoParts(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 5 }))))) ; n := (arr)->size() ; printTwoParts(arr, n); operation findSplitPoint(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var leftSum : int := 0 ; for i : Integer.subrange(0, n-1) do ( leftSum := leftSum + arr[i+1] ; var rightSum : int := 0 ; for j : Integer.subrange(i + 1, n-1) do ( rightSum := rightSum + arr[j+1]) ; if (leftSum = rightSum) then ( return i + 1 ) else skip) ; return -1; operation printTwoParts(arr : OclAny, n : OclAny) pre: true post: true activity: var splitPo : OclAny := findSplitPoint(arr, n) ; if (splitPo = -1 or splitPo = n) then ( execute ("Not Possible")->display() ; return ) else skip ; for i : Integer.subrange(0, n-1) do ( if (splitPo = i) then ( execute ("")->display() ) else skip ; execute (("" + ((arr[i+1]))) + '')->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- pie=3.1415926535897 def findsolution(d,h,m,n): k=(4*m)/(pie*d*d) if(n>k): return-1 ans=(h/(k-n)) return round(ans,5) d=1 h=1 m=1 n=1 print(findsolution(d,h,m,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var pie : double := 3.1415926535897 ; skip ; d := 1 ; h := 1 ; m := 1 ; n := 1 ; execute (findsolution(d, h, m, n))->display(); operation findsolution(d : OclAny, h : OclAny, m : OclAny, n : OclAny) : OclAny pre: true post: true activity: var k : double := (4 * m) / (pie * d * d) ; if ((n->compareTo(k)) > 0) then ( return -1 ) else skip ; var ans : double := (h / (k - n)) ; return MathLib.roundN(ans, 5); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def count(i,j,mid): count=0 while i<=j : if arr[i]+arr[j]<=mid : i+=1 j-=1 else : j-=1 count+=1 return count n,k=map(int,input().split()) arr=list(map(int,input().split())) l=max(arr) r=sum(arr) best=0 while l<=r : mid=(l+r)//2 i,j=0,n-1 total=count(i,j,mid) if total<=k : r=mid-1 best=mid else : l=mid+1 print(best) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : OclAny := (arr)->max() ; var r : OclAny := (arr)->sum() ; var best : int := 0 ; while (l->compareTo(r)) <= 0 do ( mid := (l + r) div 2 ; Sequence{i,j} := Sequence{0,n - 1} ; var total : OclAny := count(i, j, mid) ; if (total->compareTo(k)) <= 0 then ( r := mid - 1 ; best := mid ) else ( l := mid + 1 )) ; execute (best)->display(); operation count(i : OclAny, j : OclAny, mid : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while (i->compareTo(j)) <= 0 do ( if (arr[i+1] + arr[j+1]->compareTo(mid)) <= 0 then ( i := i + 1 ; j := j - 1 ) else ( j := j - 1 ) ; count := count + 1) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) nums=[int(i)for i in input().split()] def isPossible(mid): l,r=0,len(nums)-1 count=0 while l<=r : if l==r : if nums[l]>mid : return False,-1 else : count+=1 break if nums[l]+nums[r]<=mid : count+=1 l+=1 r-=1 elif nums[r]<=mid : count+=1 r-=1 else : return False,-1 return True,count l,r=max(nums),sum(nums) while l<=r : mid=l+(r-l)//2 b,box=isPossible(mid) if b and box<=k : r=mid-1 else : l=mid+1 print(l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var nums : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; skip ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{(nums)->max(),(nums)->sum()} ; while (l->compareTo(r)) <= 0 do ( mid := l + (r - l) div 2 ; var b : OclAny := null; var box : OclAny := null; Sequence{b,box} := isPossible(mid) ; if b & (box->compareTo(k)) <= 0 then ( var r : double := mid - 1 ) else ( var l : OclAny := mid + 1 )) ; execute (l)->display(); operation isPossible(mid : OclAny) : OclAny pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,(nums)->size() - 1} ; var count : int := 0 ; while (l->compareTo(r)) <= 0 do ( if l = r then ( if (nums[l+1]->compareTo(mid)) > 0 then ( return false, -1 ) else ( count := count + 1 ; break ) ) else skip ; if (nums[l+1] + nums[r+1]->compareTo(mid)) <= 0 then ( count := count + 1 ; l := l + 1 ; r := r - 1 ) else (if (nums[r+1]->compareTo(mid)) <= 0 then ( count := count + 1 ; r := r - 1 ) else ( return false, -1 ) ) ) ; return true, count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import heapq from math import log10,floor,pow from collections import defaultdict,deque input=sys.stdin.readline def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s=input() return(list(s[: len(s)-1])) def invr(): return(map(int,input().split())) n,k=inlt() lt=inlt() max_=0 size=((n-k)*2) r=size if k>n : print(max(lt)) exit() for i in range(r//2): max_=max(max_,lt[r-1]+lt[i]) r-=1 for j in range(size,n): max_=max(max_,lt[j]) print(max_) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := inlt() ; var lt : OclAny := inlt() ; var max_ : int := 0 ; var size : double := ((n - k) * 2) ; var r : OclAny := size ; if (k->compareTo(n)) > 0 then ( execute ((lt)->max())->display() ; exit() ) else skip ; for i : Integer.subrange(0, r div 2-1) do ( max_ := Set{max_, lt[r - 1+1] + lt[i+1]}->max() ; r := r - 1) ; for j : Integer.subrange(size, n-1) do ( max_ := Set{max_, lt[j+1]}->max()) ; execute (max_)->display(); operation inp() : OclAny pre: true post: true activity: return (("" + (((OclFile["System.in"]).readLine())))->toInteger()); operation inlt() : OclAny pre: true post: true activity: return (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))); operation insr() : OclAny pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; return ((s.subrange(1,(s)->size() - 1))); operation invr() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import heapq from math import log10,floor,pow from collections import defaultdict,deque input=sys.stdin.readline def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s=input() return(list(s[: len(s)-1])) def invr(): return(map(int,input().split())) n,k=inlt() lt=inlt() max_=0 size=((n-k)*2) r=size if k>n : print(max(lt)) exit() for i in range(r//2): max_=max(max_,lt[r-1]+lt[i]) r-=1 for j in range(size,n): max_=max(max_,lt[j]) print(max_) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := inlt() ; var lt : OclAny := inlt() ; var max_ : int := 0 ; var size : double := ((n - k) * 2) ; var r : OclAny := size ; if (k->compareTo(n)) > 0 then ( execute ((lt)->max())->display() ; exit() ) else skip ; for i : Integer.subrange(0, r div 2-1) do ( max_ := Set{max_, lt[r - 1+1] + lt[i+1]}->max() ; r := r - 1) ; for j : Integer.subrange(size, n-1) do ( max_ := Set{max_, lt[j+1]}->max()) ; execute (max_)->display(); operation inp() : OclAny pre: true post: true activity: return (("" + (((OclFile["System.in"]).readLine())))->toInteger()); operation inlt() : OclAny pre: true post: true activity: return (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))); operation insr() : OclAny pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; return ((s.subrange(1,(s)->size() - 1))); operation invr() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=list(map(int,input().split())) sizes=list(map(int,input().split())) left,right=max(sizes),sum(sizes) while leftcollect( _x | (OclType["int"])->apply(_x) )) ; var sizes : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var left : OclAny := null; var right : OclAny := null; Sequence{left,right} := Sequence{(sizes)->max(),(sizes)->sum()} ; while (left->compareTo(right)) < 0 do ( var mid : int := (left + right) div 2 ; var counter : int := 0 ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,(sizes)->size() - 1} ; while (i->compareTo(j)) <= 0 do ( if (sizes[i+1] + sizes[j+1]->compareTo(mid)) <= 0 then ( i := i + 1 ; j := j - 1 ) else ( j := j - 1 ) ; counter := counter + 1) ; if (counter->compareTo(k)) <= 0 then ( var right : int := mid ) else ( var left : int := mid + 1 )) ; execute (right)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_LEN,MAX_CHAR=1005,26 cnt=[[0 for i in range(MAX_CHAR)]for j in range(MAX_LEN)] def preProcess(s): n=len(s) for i in range(0,n): cnt[i][ord(s[i])-ord('a')]+=1 for i in range(0,n): for j in range(0,26): cnt[i][j]+=cnt[i-1][j] def findCharFreq(l,r,c): return(cnt[r][ord(c)-97]-cnt[l-1][ord(c)-97]) if __name__=="__main__" : s="geeksforgeeks" Q=4 preProcess(s) print(findCharFreq(0,5,'e')) print(findCharFreq(2,6,'f')) print(findCharFreq(4,7,'m')) print(findCharFreq(0,12,'e')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_LEN : OclAny := null; var MAX_CHAR : OclAny := null; Sequence{MAX_LEN,MAX_CHAR} := Sequence{1005,26} ; var cnt : Sequence := Integer.subrange(0, MAX_LEN-1)->select(j | true)->collect(j | (Integer.subrange(0, MAX_CHAR-1)->select(i | true)->collect(i | (0)))) ; skip ; skip ; if __name__ = "__main__" then ( s := "geeksforgeeks" ; var Q : int := 4 ; preProcess(s) ; execute (findCharFreq(0, 5, 'e'))->display() ; execute (findCharFreq(2, 6, 'f'))->display() ; execute (findCharFreq(4, 7, 'm'))->display() ; execute (findCharFreq(0, 12, 'e'))->display() ) else skip; operation preProcess(s : OclAny) pre: true post: true activity: var n : int := (s)->size() ; for i : Integer.subrange(0, n-1) do ( cnt[i+1][(s[i+1])->char2byte() - ('a')->char2byte()+1] := cnt[i+1][(s[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, 26-1) do ( cnt[i+1][j+1] := cnt[i+1][j+1] + cnt[i - 1+1][j+1])); operation findCharFreq(l : OclAny, r : OclAny, c : OclAny) : OclAny pre: true post: true activity: return (cnt[r+1][(c)->char2byte() - 97+1] - cnt[l - 1+1][(c)->char2byte() - 97+1]); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSub(arr,n,x): st=0 end=0 sum=0 cnt=0 while endx): sum-=arr[st] st+=1 cnt+=(end-st+1) end+=1 return cnt def findSubSumLtoR(arr,n,L,R): Rcnt=countSub(arr,n,R) Lcnt=countSub(arr,n,L-1) return Rcnt-Lcnt arr=[1,4,6] n=len(arr) L=3 R=8 print(findSubSumLtoR(arr,n,L,R)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{1}->union(Sequence{4}->union(Sequence{ 6 })) ; n := (arr)->size() ; L := 3 ; R := 8 ; execute (findSubSumLtoR(arr, n, L, R))->display(); operation countSub(arr : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: var st : int := 0 ; var end : int := 0 ; var sum : int := 0 ; var cnt : int := 0 ; while (end->compareTo(n)) < 0 do ( sum := sum + arr[end+1] ; while ((st->compareTo(end)) <= 0 & (sum->compareTo(x)) > 0) do ( sum := sum - arr[st+1] ; st := st + 1) ; cnt := cnt + (end - st + 1) ; end := end + 1) ; return cnt; operation findSubSumLtoR(arr : OclAny, n : OclAny, L : OclAny, R : OclAny) : OclAny pre: true post: true activity: var Rcnt : OclAny := countSub(arr, n, R) ; var Lcnt : OclAny := countSub(arr, n, L - 1) ; return Rcnt - Lcnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) a=list(map(int,input().split())) k=[] for j in range(n): k.append([]) for i in range(2*n): k[a[i]-1].append(i) ans=k[0][0]+k[0][1] for i in range(n-1): ans+=abs(k[i][0]-k[i+1][0])+abs(k[i][1]-k[i+1][1]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( execute ((Sequence{}) : k)) ; for i : Integer.subrange(0, 2 * n-1) do ((expr (atom (name k)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var ans : OclAny := k->first()->first() + k->first()[1+1] ; for i : Integer.subrange(0, n - 1-1) do ( ans := ans + (k[i+1]->first() - k[i + 1+1]->first())->abs() + (k[i+1][1+1] - k[i + 1+1][1+1])->abs()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,v=list(map(int,input().split())) ans=[] for x in range(n): lst=list(map(int,input().split())) k=lst[0] lst=lst[1 :] f=0 for i in range(k): if v>lst[i]: f=1 if f : ans.append(x) print(len(ans)) for i in ans : print(i+1,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var v : OclAny := null; Sequence{n,v} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : Sequence := Sequence{} ; for x : Integer.subrange(0, n-1) do ( var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k : OclAny := lst->first() ; lst := lst->tail() ; var f : int := 0 ; for i : Integer.subrange(0, k-1) do ( if (v->compareTo(lst[i+1])) > 0 then ( f := 1 ) else skip) ; if f then ( execute ((x) : ans) ) else skip) ; execute ((ans)->size())->display() ; for i : ans do ( execute (i + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,valera=map(int,input().split()) amn=0 nums=[] for j in range(n): lots,*price=map(int,input().split()) for i in price : if valera>i : amn+=1 nums.append(j+1) break print(amn) for y in nums : print(str(y)+'',end='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var valera : OclAny := null; Sequence{n,valera} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var amn : int := 0 ; var nums : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( var lots : OclAny := null; var price : OclAny := null; Sequence{lots,price} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : price do ( if (valera->compareTo(i)) > 0 then ( amn := amn + 1 ; execute ((j + 1) : nums) ; break ) else skip)) ; execute (amn)->display() ; for y : nums do ( execute (("" + ((y))) + '')->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSplitPoint(arr,n): leftSum=0 for i in range(0,n): leftSum+=arr[i] rightSum=0 for i in range(n-1,-1,-1): rightSum+=arr[i] leftSum-=arr[i] if(rightSum==leftSum): return i return-1 def printTwoParts(arr,n): splitPoint=findSplitPoint(arr,n) if(splitPoint==-1 or splitPoint==n): print("Not Possible") return for i in range(0,n): if(splitPoint==i): print("") print(arr[i],end=" ") arr=[1,2,3,4,5,5] n=len(arr) printTwoParts(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 5 }))))) ; n := (arr)->size() ; printTwoParts(arr, n); operation findSplitPoint(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var leftSum : int := 0 ; for i : Integer.subrange(0, n-1) do ( leftSum := leftSum + arr[i+1]) ; var rightSum : int := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( rightSum := rightSum + arr[i+1] ; leftSum := leftSum - arr[i+1] ; if (rightSum = leftSum) then ( return i ) else skip) ; return -1; operation printTwoParts(arr : OclAny, n : OclAny) pre: true post: true activity: var splitPoint : OclAny := findSplitPoint(arr, n) ; if (splitPoint = -1 or splitPoint = n) then ( execute ("Not Possible")->display() ; return ) else skip ; for i : Integer.subrange(0, n-1) do ( if (splitPoint = i) then ( execute ("")->display() ) else skip ; execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (n,v)=map(int,input().split(' ')) potential_deal_with_sellers=[] for i in range(n): a=list(map(int,input().split(' '))) number_of_items=a[0] items=a[1 :] for item in items : if item0 : print(len(potential_deal_with_sellers)) print(*potential_deal_with_sellers) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{n, v} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var potential_deal_with_sellers : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var number_of_items : OclAny := a->first() ; var items : OclAny := a->tail() ; for item : items do ( if (item->compareTo(v)) < 0 then ( execute ((i + 1) : potential_deal_with_sellers) ; break ) else skip)) ; if (potential_deal_with_sellers)->size() > 0 then ( execute ((potential_deal_with_sellers)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name potential_deal_with_sellers))))))))->display() ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=list(map(int,input().split())) l=[] for i in range(x): l.append(list(map(int,input().split()))) conter=0 sellers=[] for i in range(len(l)): for j in l[i]: if j<1000 : continue elif jcollect( _x | (OclType["int"])->apply(_x) )) ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, x-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : l)) ; var conter : int := 0 ; var sellers : Sequence := Sequence{} ; for i : Integer.subrange(0, (l)->size()-1) do ( for j : l[i+1] do ( if j < 1000 then ( continue ) else (if (j->compareTo(y)) < 0 then ( conter := conter + 1 ; execute ((i) : sellers) ; break ) else skip))) ; execute (conter)->display() ; if (sellers)->size() = 0 then ( execute (' ')->display() ; ) else skip ; for i : sellers do ( execute (i + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): n,v=map(int,input().split()) res=[] for i in range(n): arr=list(map(int,input().split())) if min(arr[1 :])collect( _x | (OclType["int"])->apply(_x) ) ; var res : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if ((arr->tail())->min()->compareTo(v)) < 0 then ( execute ((i + 1) : res) ) else skip) ; res := res->sort() ; execute ((res)->size())->display() ; execute (StringLib.sumStringsWithSeparator(((res)->collect( _x | (OclType["String"])->apply(_x) )), " "))->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nextGap(gap): if(gap<=1): return 0 return(gap//2)+(gap % 2) def merge(arr1,arr2,n,m): gap=n+m gap=nextGap(gap) while gap>0 : i=0 while i+gaparr1[i+gap]): arr1[i],arr1[i+gap]=arr1[i+gap],arr1[i] i+=1 j=gap-n if gap>n else 0 while iarr2[j]): arr1[i],arr2[j]=arr2[j],arr1[i] i+=1 j+=1 if(jarr2[j+gap]): arr2[j],arr2[j+gap]=arr2[j+gap],arr2[j] j+=1 gap=nextGap(gap) if __name__=="__main__" : a1=[10,27,38,43,82] a2=[3,9] n=len(a1) m=len(a2) merge(a1,a2,n,m) print("First Array: ",end="") for i in range(n): print(a1[i],end="") print() print("Second Array: ",end="") for i in range(m): print(a2[i],end="") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var a1 : Sequence := Sequence{10}->union(Sequence{27}->union(Sequence{38}->union(Sequence{43}->union(Sequence{ 82 })))) ; var a2 : Sequence := Sequence{3}->union(Sequence{ 9 }) ; n := (a1)->size() ; m := (a2)->size() ; merge(a1, a2, n, m) ; execute ("First Array: ")->display() ; for i : Integer.subrange(0, n-1) do ( execute (a1[i+1])->display()) ; execute (->display() ; execute ("Second Array: ")->display() ; for i : Integer.subrange(0, m-1) do ( execute (a2[i+1])->display()) ; execute (->display() ) else skip; operation nextGap(gap : OclAny) : OclAny pre: true post: true activity: if (gap <= 1) then ( return 0 ) else skip ; return (gap div 2) + (gap mod 2); operation merge(arr1 : OclAny, arr2 : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: gap := n + m ; gap := nextGap(gap) ; while gap > 0 do ( var i : int := 0 ; while (i + gap->compareTo(n)) < 0 do ( if ((arr1[i+1]->compareTo(arr1[i + gap+1])) > 0) then ( var arr1[i+1] : OclAny := null; var arr1[i + gap+1] : OclAny := null; Sequence{arr1[i+1],arr1[i + gap+1]} := Sequence{arr1[i + gap+1],arr1[i+1]} ) else skip ; i := i + 1) ; var j : double := if (gap->compareTo(n)) > 0 then gap - n else 0 endif ; while (i->compareTo(n)) < 0 & (j->compareTo(m)) < 0 do ( if ((arr1[i+1]->compareTo(arr2[j+1])) > 0) then ( var arr1[i+1] : OclAny := null; var arr2[j+1] : OclAny := null; Sequence{arr1[i+1],arr2[j+1]} := Sequence{arr2[j+1],arr1[i+1]} ) else skip ; i := i + 1 ; j := j + 1) ; if ((j->compareTo(m)) < 0) then ( j := 0 ; while (j + gap->compareTo(m)) < 0 do ( if ((arr2[j+1]->compareTo(arr2[j + gap+1])) > 0) then ( var arr2[j+1] : OclAny := null; var arr2[j + gap+1] : OclAny := null; Sequence{arr2[j+1],arr2[j + gap+1]} := Sequence{arr2[j + gap+1],arr2[j+1]} ) else skip ; j := j + 1) ) else skip ; gap := nextGap(gap)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countunsetbits(n): count=0 x=1 while(xdisplay() ) else skip; operation countunsetbits(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var x : int := 1 ; while ((x->compareTo(n + 1)) < 0) do ( if ((MathLib.bitwiseAnd(x, n)) = 0) then ( count := count + 1 ) else skip ; x := x * (2->pow(1))) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMaxRec(A,n): if(n==1): return A[0] return max(A[n-1],findMaxRec(A,n-1)) if __name__=="__main__" : A=[1,4,45,6,-50,10,2] n=len(A) print(findMaxRec(A,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( A := Sequence{1}->union(Sequence{4}->union(Sequence{45}->union(Sequence{6}->union(Sequence{-50}->union(Sequence{10}->union(Sequence{ 2 })))))) ; n := (A)->size() ; execute (findMaxRec(A, n))->display() ) else skip; operation findMaxRec(A : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return A->first() ) else skip ; return Set{A[n - 1+1], findMaxRec(A, n - 1)}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dp=[[-1 for i in range(1001)]for j in range(1001)] def find_max(i,sum,v,k): if(i==len(v)): return 0 if(dp[i][sum]!=-1): return dp[i][sum] ans=0 if((sum+find_max(i+1,sum,v,k))% k==0): ans=find_max(i+1,sum,v,k) if((sum+v[i]+find_max(i+1,(sum+v[i])% k,v,k))% k==0): ans=max(ans,v[i]+find_max(i+1,(sum+v[i])% k,v,k)) dp[i][sum]=ans return dp[i][sum] if __name__=='__main__' : arr=[43,1,17,26,15] k=16 print(find_max(0,0,arr,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dp : Sequence := Integer.subrange(0, 1001-1)->select(j | true)->collect(j | (Integer.subrange(0, 1001-1)->select(i | true)->collect(i | (-1)))) ; skip ; if __name__ = '__main__' then ( var arr : Sequence := Sequence{43}->union(Sequence{1}->union(Sequence{17}->union(Sequence{26}->union(Sequence{ 15 })))) ; k := 16 ; execute (find_max(0, 0, arr, k))->display() ) else skip; operation find_max(i : OclAny, sum : OclAny, v : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (i = (v)->size()) then ( return 0 ) else skip ; if (dp[i+1][sum+1] /= -1) then ( return dp[i+1][sum+1] ) else skip ; var ans : int := 0 ; if ((sum + find_max(i + 1, sum, v, k)) mod k = 0) then ( ans := find_max(i + 1, sum, v, k) ) else skip ; if ((sum + v[i+1] + find_max(i + 1, (sum + v[i+1]) mod k, v, k)) mod k = 0) then ( ans := Set{ans, v[i+1] + find_max(i + 1, (sum + v[i+1]) mod k, v, k)}->max() ) else skip ; dp[i+1][sum+1] := ans ; return dp[i+1][sum+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def solve(): n,k=map(int,input().split()) cnt=1 ans=0 while cnt<=k and cnt=n : return ans else : ans+=(n-cnt)//k ans+=1 if(n-cnt)% k else 0 return ans for _ in range(int(input())): print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (solve())->display()); operation solve() : OclAny pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cnt : int := 1 ; var ans : int := 0 ; while (cnt->compareTo(k)) <= 0 & (cnt->compareTo(n)) < 0 do ( cnt := cnt * 2 ; ans := ans + 1) ; if (cnt->compareTo(n)) >= 0 then ( return ans ) else ( ans := ans + (n - cnt) div k ; ans := ans + if (n - cnt) mod k then 1 else 0 endif ; return ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=list(map(int,input().split())) lst=[int(x)for x in input().split()] for i in range(len(lst)): lst[i]=(lst[i],i) lst.sort() x_fst=0 x_sc=0 route=0 for i in range(0,len(lst),2): if abs(x_fst-lst[i][1])+abs(x_sc-lst[i+1][1])>abs(x_fst-lst[i+1][1])+abs(x_sc-lst[i][1]): route+=abs(x_fst-lst[i+1][1])+abs(x_sc-lst[i][1]) x_fst=lst[i+1][1] x_sc=lst[i][1] else : route+=abs(x_fst-lst[i][1])+abs(x_sc-lst[i+1][1]) x_fst=lst[i][1] x_sc=lst[i+1][1] print(route) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lst : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for i : Integer.subrange(0, (lst)->size()-1) do ( lst[i+1] := Sequence{lst[i+1], i}) ; lst := lst->sort() ; var x_fst : int := 0 ; var x_sc : int := 0 ; var route : int := 0 ; for i : Integer.subrange(0, (lst)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( if ((x_fst - lst[i+1][1+1])->abs() + (x_sc - lst[i + 1+1][1+1])->abs()->compareTo((x_fst - lst[i + 1+1][1+1])->abs() + (x_sc - lst[i+1][1+1])->abs())) > 0 then ( route := route + (x_fst - lst[i + 1+1][1+1])->abs() + (x_sc - lst[i+1][1+1])->abs() ; x_fst := lst[i + 1+1][1+1] ; x_sc := lst[i+1][1+1] ) else ( route := route + (x_fst - lst[i+1][1+1])->abs() + (x_sc - lst[i + 1+1][1+1])->abs() ; x_fst := lst[i+1][1+1] ; x_sc := lst[i + 1+1][1+1] )) ; execute (route)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ls=[] cnt=2 while 1 : ls1=list(map(int,input().split())) if ls1[0]==0 and ls1[1]==0 : break else : ls.append(list(ls1)) ls1.clear() for i in range(len(ls)): for j in range(ls[i][0]): for l in range(ls[i][1]): if j % 2==0 : if cnt % 2==0 : print("#",end="") cnt+=1 else : print(".",end="") cnt+=1 else : if cnt % 2==0 : print(".",end="") cnt+=1 else : print("#",end="") cnt+=1 cnt=2 print() print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ls : Sequence := Sequence{} ; var cnt : int := 2 ; while 1 do ( var ls1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if ls1->first() = 0 & ls1[1+1] = 0 then ( break ) else ( execute (((ls1)) : ls) ; execute (ls1 /<: ls1) )) ; for i : Integer.subrange(0, (ls)->size()-1) do ( for j : Integer.subrange(0, ls[i+1]->first()-1) do ( for l : Integer.subrange(0, ls[i+1][1+1]-1) do ( if j mod 2 = 0 then ( if cnt mod 2 = 0 then ( execute ("#")->display() ; cnt := cnt + 1 ) else ( execute (".")->display() ; cnt := cnt + 1 ) ) else ( if cnt mod 2 = 0 then ( execute (".")->display() ; cnt := cnt + 1 ) else ( execute ("#")->display() ; cnt := cnt + 1 ) )) ; cnt := 2 ; execute (->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : H,W=[int(x)for x in input().split()] if(H,W)==(0,0): break unit="#." for i in range(H): print(unit*(W//2)+unit[0]*(W % 2)) unit=unit[1]+unit[0] print("") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if Sequence{H, W} = Sequence{0, 0} then ( break ) else skip ; var unit : String := "#." ; for i : Integer.subrange(0, H-1) do ( execute (StringLib.nCopies(unit, (W div 2)) + unit->first() * (W mod 2))->display() ; unit := unit[1+1] + unit->first()) ; execute ("")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A=[] H,W=map(int,input().split()) while H!=0 or W!=0 : A.append([H,W]) H,W=map(int,input().split()) for i in range(len(A)): for j in range(A[i][0]): if A[i][1]% 2==0 and j % 2==0 : print('#.'*int(A[i][1]/2)) elif A[i][1]% 2==0 and j % 2==1 : print('.#'*int(A[i][1]/2)) elif A[i][1]% 2==1 and j % 2==0 : print('#.'*(A[i][1]//2)+'#') elif A[i][1]% 2==1 and j % 2==1 : print('.#'*(A[i][1]//2)+'.') print('') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : Sequence := Sequence{} ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; while H /= 0 or W /= 0 do ( execute ((Sequence{H}->union(Sequence{ W })) : A) ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, (A)->size()-1) do ( for j : Integer.subrange(0, A[i+1]->first()-1) do ( if A[i+1][1+1] mod 2 = 0 & j mod 2 = 0 then ( execute (StringLib.nCopies('#.', ("" + ((A[i+1][1+1] / 2)))->toInteger()))->display() ) else (if A[i+1][1+1] mod 2 = 0 & j mod 2 = 1 then ( execute (StringLib.nCopies('.#', ("" + ((A[i+1][1+1] / 2)))->toInteger()))->display() ) else (if A[i+1][1+1] mod 2 = 1 & j mod 2 = 0 then ( execute (StringLib.nCopies('#.', (A[i+1][1+1] div 2)) + '#')->display() ) else (if A[i+1][1+1] mod 2 = 1 & j mod 2 = 1 then ( execute (StringLib.nCopies('.#', (A[i+1][1+1] div 2)) + '.')->display() ) else skip ) ) ) ) ; execute ('')->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) DP=[[-1]*6000 for i in range(6000)] def P(n,k): if n<0 or k<1 : return 0 if DP[n][k]!=-1 : return DP[n][k] if k==1 : DP[n][k]=1 return 1 DP[n][k]=(P(n,k-1)+P(n-k,k))% M return DP[n][k] for i in range(5500): for j in range(i+1): P(i+1,j+1) X=[0] DP[0][0]=1 for i in range(5500): X.append(0) for j in range(i+1): X[-1]=(X[-1]+DP[j][j]*DP[i-j][i-j])% M Y=[0] for i in range(10800): Y.append(Y[i]+X[i>>1]) P=0 for i in range(1,N+1): P=(P+X[i])% M if 2*i>N : P=(P-Y[2*i-N])% M print(P) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var DP : Sequence := Integer.subrange(0, 6000-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ -1 }, 6000))) ; skip ; for i : Integer.subrange(0, 5500-1) do ( for j : Integer.subrange(0, i + 1-1) do ( P(i + 1, j + 1))) ; var X : Sequence := Sequence{ 0 } ; DP->first()->first() := 1 ; for i : Integer.subrange(0, 5500-1) do ( execute ((0) : X) ; for j : Integer.subrange(0, i + 1-1) do ( X->last() := (X->last() + DP[j+1][j+1] * DP[i - j+1][i - j+1]) mod M)) ; var Y : Sequence := Sequence{ 0 } ; for i : Integer.subrange(0, 10800-1) do ( execute ((Y[i+1] + X[i /(2->pow(1))+1]) : Y)) ; var P : int := 0 ; for i : Integer.subrange(1, N + 1-1) do ( P := (P + X[i+1]) mod M ; if (2 * i->compareTo(N)) > 0 then ( P := (P - Y[2 * i - N+1]) mod M ) else skip) ; execute (P)->display(); operation P(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if n < 0 or k < 1 then ( return 0 ) else skip ; if DP[n+1][k+1] /= -1 then ( return DP[n+1][k+1] ) else skip ; if k = 1 then ( DP[n+1][k+1] := 1 ; return 1 ) else skip ; DP[n+1][k+1] := (P(n, k - 1) + P(n - k, k)) mod M ; return DP[n+1][k+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : H,W=map(int,input().split()) if H==W==0 : break else : if H % 2==0 : for i in range(H//2): if W % 2==0 : print("#."*(W//2)) print(".#"*(W//2)) else : print("#."*(W//2)+"#") print(".#"*(W//2)+".") print() else : for i in range(H//2): if W % 2==0 : print("#."*(W//2)) print(".#"*(W//2)) else : print("#."*(W//2)+"#") print(".#"*(W//2)+".") if W % 2==0 : print("#."*(W//2)) else : print("#."*(W//2)+"#") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if H = W & (W == 0) then ( break ) else ( if H mod 2 = 0 then ( for i : Integer.subrange(0, H div 2-1) do ( if W mod 2 = 0 then ( execute (StringLib.nCopies("#.", (W div 2)))->display() ; execute (StringLib.nCopies(".#", (W div 2)))->display() ) else ( execute (StringLib.nCopies("#.", (W div 2)) + "#")->display() ; execute (StringLib.nCopies(".#", (W div 2)) + ".")->display() )) ; execute (->display() ) else ( for i : Integer.subrange(0, H div 2-1) do ( if W mod 2 = 0 then ( execute (StringLib.nCopies("#.", (W div 2)))->display() ; execute (StringLib.nCopies(".#", (W div 2)))->display() ) else ( execute (StringLib.nCopies("#.", (W div 2)) + "#")->display() ; execute (StringLib.nCopies(".#", (W div 2)) + ".")->display() )) ; if W mod 2 = 0 then ( execute (StringLib.nCopies("#.", (W div 2)))->display() ) else ( execute (StringLib.nCopies("#.", (W div 2)) + "#")->display() ) ; execute (->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def char(n,h): tbl=['#','.'] if h % 2==1 : tbl=['.','#'] if n % 2==0 : return tbl[0] else : return tbl[1] while True : h,w=map(int,input().split()) if h==0 and w==0 : break for i in range(h): print(''.join([char(n,i)for n in range(w)])) print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if h = 0 & w = 0 then ( break ) else skip ; for i : Integer.subrange(0, h-1) do ( execute (StringLib.sumStringsWithSeparator((Integer.subrange(0, w-1)->select(n | true)->collect(n | (char(n, i)))), ''))->display()) ; execute (->display()); operation char(n : OclAny, h : OclAny) : OclAny pre: true post: true activity: var tbl : Sequence := Sequence{'#'}->union(Sequence{ '.' }) ; if h mod 2 = 1 then ( tbl := Sequence{'.'}->union(Sequence{ '#' }) ) else skip ; if n mod 2 = 0 then ( return tbl->first() ) else ( return tbl[1+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=[int(x)for x in input().split()] ari=set([s[i+1]-s[i]for i in range(3)]) geo=set([s[i+1]/s[i]for i in range(3)]) if len(ari)==1 : print(s[3]+ari.pop()) elif len(geo)==1 : res=(s[3]*geo.pop()) if int(res)==res : print(int(res)) else : print(42) else : print(42) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ari : Set := Set{}->union((Integer.subrange(0, 3-1)->select(i | true)->collect(i | (s[i + 1+1] - s[i+1])))) ; var geo : Set := Set{}->union((Integer.subrange(0, 3-1)->select(i | true)->collect(i | (s[i + 1+1] / s[i+1])))) ; if (ari)->size() = 1 then ( execute (s[3+1] + ari->last())->display() ) else (if (geo)->size() = 1 then ( var res : double := (s[3+1] * geo->last()) ; if ("" + ((res)))->toInteger() = res then ( execute (("" + ((res)))->toInteger())->display() ) else ( execute (42)->display() ) ) else ( execute (42)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if a>b : a,b=b,a if b % a==0 : return a return gcd(b % a,a) def ratio(x,y): g=gcd(x,y) return(y//g,x//g) def process(A): d1=A[1]-A[0] if A[2]==A[1]+d1 and A[3]==A[2]+d1 : return A[3]+d1 r=ratio(A[0],A[1]) if r==ratio(A[1],A[2])and r==ratio(A[2],A[3]): a,b=r num=A[3]*a if num % b!=0 : return 42 return num//b return 42 A=[int(x)for x in input().split()] print(process(A)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; A := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (process(A))->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a->compareTo(b)) > 0 then ( Sequence{a,b} := Sequence{b,a} ) else skip ; if b mod a = 0 then ( return a ) else skip ; return gcd(b mod a, a); operation ratio(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var g : OclAny := gcd(x, y) ; return Sequence{y div g, x div g}; operation process(A : OclAny) : OclAny pre: true post: true activity: var d1 : double := A[1+1] - A->first() ; if A[2+1] = A[1+1] + d1 & A[3+1] = A[2+1] + d1 then ( return A[3+1] + d1 ) else skip ; var r : OclAny := ratio(A->first(), A[1+1]) ; if r = ratio(A[1+1], A[2+1]) & r = ratio(A[2+1], A[3+1]) then ( Sequence{a,b} := r ; var num : double := A[3+1] * a ; if num mod b /= 0 then ( return 42 ) else skip ; return num div b ) else skip ; return 42; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=list(map(int,input().split())) m=l[1]-l[0]; d=l[1]/l[0] am=0 ad=0 for i in range(len(l)-1): if l[i+1]-l[i]==m : am+=1 for i in range(len(l)-1): if l[i+1]/l[i]==d : ad+=1 if am==3 : j=l[3]+m print(j) elif ad==3 : j=l[3]*d jj=str(j); jj=jj[-2 :] if jj=='.0' : print(int(j)) else : print(42) else : print(42) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : double := l[1+1] - l->first(); var d : double := l[1+1] / l->first() ; var am : int := 0 ; var ad : int := 0 ; for i : Integer.subrange(0, (l)->size() - 1-1) do ( if l[i + 1+1] - l[i+1] = m then ( am := am + 1 ) else skip) ; for i : Integer.subrange(0, (l)->size() - 1-1) do ( if l[i + 1+1] / l[i+1] = d then ( ad := ad + 1 ) else skip) ; if am = 3 then ( var j : OclAny := l[3+1] + m ; execute (j)->display() ) else (if ad = 3 then ( j := l[3+1] * d ; var jj : String := ("" + ((j))); jj := jj.subrange(-2+1) ; if jj = '.0' then ( execute (("" + ((j)))->toInteger())->display() ) else ( execute (42)->display() ) ) else ( execute (42)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ls=[int(x)for x in input().split()] if ls[1]-ls[0]==ls[2]-ls[1]and ls[3]-ls[2]==ls[2]-ls[1]: print(ls[3]+ls[2]-ls[1]) elif ls[1]/ls[0]==ls[2]/ls[1]and ls[3]/ls[2]==ls[2]/ls[1]and ls[3]*ls[2]/ls[1]==ls[3]*ls[2]//ls[1]: print(ls[3]*ls[2]//ls[1]) else : print(42) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ls : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if ls[1+1] - ls->first() = ls[2+1] - ls[1+1] & ls[3+1] - ls[2+1] = ls[2+1] - ls[1+1] then ( execute (ls[3+1] + ls[2+1] - ls[1+1])->display() ) else (if ls[1+1] / ls->first() = ls[2+1] / ls[1+1] & ls[3+1] / ls[2+1] = ls[2+1] / ls[1+1] & ls[3+1] * ls[2+1] / ls[1+1] = ls[3+1] * ls[2+1] div ls[1+1] then ( execute (ls[3+1] * ls[2+1] div ls[1+1])->display() ) else ( execute (42)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for _ in range(0,n): a,b=[int(x)for x in input().split()] if a!=b : print("Happy Alex") break else : print("Poor Alex") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (compound_stmt for (exprlist (expr (atom (name _)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name b))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( )))))))) ]))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name a)))) != (comparison (expr (atom (name b))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Happy Alex"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Poor Alex"))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=map(int,input().split()) r=42 if b-a==c-b==d-c : r=d+b-a if b/a==c/b==d/c==int(d*c/b)/d : r=int(d*c/b) print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var r : int := 42 ; if b - a = c - b & (c - b == d - c) then ( r := d + b - a ) else skip ; if b / a = c / b & (c / b == d / c) & (d / c == ("" + ((d * c / b)))->toInteger() / d) then ( r := ("" + ((d * c / b)))->toInteger() ) else skip ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import product while(True): H,W=map(int,input().split()) if not H : break ma=[list(map(int,input().replace(".","1").replace("*","0")))+[0]for _ in range(H)] for i,j in product(range(1,H),range(W)): if ma[i][j]: ma[i][j]+=ma[i-1][j] ans=0 for i in range(H): stk=[] for j in range(W+1): cur=ma[i][j] if(not stk)or stk[-1][1]cur : idx=j while stk and stk[-1][1]>=cur : idx=stk[-1][0] ans=max(ans,stk[-1][1]*(j-stk[-1][0])) stk.pop() stk.append([idx,cur]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while (true) do ( var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if not(H) then ( break ) else skip ; var ma : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (((input().replace(".", "1").replace("*", "0"))->collect( _x | (OclType["int"])->apply(_x) ))->union(Sequence{ 0 }))) ; for _tuple : product(Integer.subrange(1, H-1), Integer.subrange(0, W-1)) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if ma[i+1][j+1] then ( ma[i+1][j+1] := ma[i+1][j+1] + ma[i - 1+1][j+1] ) else skip) ; var ans : int := 0 ; for i : Integer.subrange(0, H-1) do ( var stk : Sequence := Sequence{} ; for j : Integer.subrange(0, W + 1-1) do ( var cur : OclAny := ma[i+1][j+1] ; if (not(stk)) or (stk->last()[1+1]->compareTo(cur)) < 0 then ( execute ((Sequence{j}->union(Sequence{ cur })) : stk) ) else (if (stk->last()[1+1]->compareTo(cur)) > 0 then ( var idx : OclAny := j ; while stk & (stk->last()[1+1]->compareTo(cur)) >= 0 do ( idx := stk->last()->first() ; ans := Set{ans, stk->last()[1+1] * (j - stk->last()->first())}->max() ; stk := stk->front()) ; execute ((Sequence{idx}->union(Sequence{ cur })) : stk) ) else skip))) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : h,w=map(int,input().split()) if h==0 : break mp=[] for _ in range(h): lst=list(input()) cum=[] acc=0 for i in lst : acc=acc+1 if i=="." else 0 cum.append(acc) mp.append(cum) mp.append([-1]*w) ans=0 for i in range(w): stack=[] for j in range(h+1): score=mp[j][i] if not stack : stack.append((score,j)) else : last_score,last_ind=stack[-1][0],stack[-1][1] if score>last_score : stack.append((score,j)) elif score==last_score : continue else : while stack!=[]and stack[-1][0]>=score : last_score,last_ind=stack.pop() ans=max(ans,last_score*(j-last_ind)) stack.append((score,last_ind)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if h = 0 then ( break ) else skip ; var mp : Sequence := Sequence{} ; for _anon : Integer.subrange(0, h-1) do ( var lst : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var cum : Sequence := Sequence{} ; var acc : int := 0 ; for i : lst do ( acc := if i = "." then acc + 1 else 0 endif ; execute ((acc) : cum)) ; execute ((cum) : mp)) ; execute ((MatrixLib.elementwiseMult(Sequence{ -1 }, w)) : mp) ; var ans : int := 0 ; for i : Integer.subrange(0, w-1) do ( var stack : Sequence := Sequence{} ; for j : Integer.subrange(0, h + 1-1) do ( var score : OclAny := mp[j+1][i+1] ; if not(stack) then ( execute ((Sequence{score, j}) : stack) ) else ( var last_score : OclAny := null; var last_ind : OclAny := null; Sequence{last_score,last_ind} := Sequence{stack->last()->first(),stack->last()[1+1]} ; if (score->compareTo(last_score)) > 0 then ( execute ((Sequence{score, j}) : stack) ) else (if score = last_score then ( continue ) else ( while stack /= Sequence{} & (stack->last()->first()->compareTo(score)) >= 0 do ( var last_score : OclAny := null; var last_ind : OclAny := null; Sequence{last_score,last_ind} := stack->last() ; stack := stack->front() ; ans := Set{ans, last_score * (j - last_ind)}->max()) ; execute ((Sequence{score, last_ind}) : stack) ) ) ))) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): H,W=map(int,input().split()) if H==0 : return False MP=[input()for i in range(H)] C=[[0]*W for i in range(H)] for j in range(W): cnt=0 for i in range(H-1,-1,-1): if MP[i][j]=='.' : cnt+=1 else : cnt=0 C[i][j]=cnt ans=0 for i in range(H): st=[(0,-1)] for j in range(W): e=C[i][j] last=j while st and e<=st[-1][0]: f,k=st.pop() ans=max(ans,(j-k)*f) last=k st.append((e,last)) while st : f,k=st.pop() ans=max(ans,(W-k)*f) print(ans) return True while solve(): ... ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while solve() do (); operation solve() : OclAny pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if H = 0 then ( return false ) else skip ; var MP : Sequence := Integer.subrange(0, H-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var C : Sequence := Integer.subrange(0, H-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, W))) ; for j : Integer.subrange(0, W-1) do ( var cnt : int := 0 ; for i : Integer.subrange(-1 + 1, H - 1)->reverse() do ( if MP[i+1][j+1] = '.' then ( cnt := cnt + 1 ) else ( cnt := 0 ) ; C[i+1][j+1] := cnt)) ; var ans : int := 0 ; for i : Integer.subrange(0, H-1) do ( var st : Sequence := Sequence{ Sequence{0, -1} } ; for j : Integer.subrange(0, W-1) do ( var e : OclAny := C[i+1][j+1] ; var last : OclAny := j ; while st & (e->compareTo(st->last()->first())) <= 0 do ( var f : OclAny := null; var k : OclAny := null; Sequence{f,k} := st->last() ; st := st->front() ; ans := Set{ans, (j - k) * f}->max() ; last := k) ; execute ((Sequence{e, last}) : st)) ; while st do ( var f : OclAny := null; var k : OclAny := null; Sequence{f,k} := st->last() ; st := st->front() ; ans := Set{ans, (W - k) * f}->max())) ; execute (ans)->display() ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines N,MOD=map(int,read().split()) if N % 2==0 : A=list(range(1,N//2+1))*2 else : A=list(range(1,N//2+1))*2+[(N+1)//2] A.sort() dp=[1]+[0]*(N+N+10) for x in A : for i in range(N+1): dp[i]%=MOD dp[i+x]+=dp[i] answer=sum(dp[: N])% MOD print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; var N : OclAny := null; var MOD : OclAny := null; Sequence{N,MOD} := (read().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if N mod 2 = 0 then ( var A : Sequence := MatrixLib.elementwiseMult((Integer.subrange(1, N div 2 + 1-1)), 2) ) else ( A := MatrixLib.elementwiseMult((Integer.subrange(1, N div 2 + 1-1)), 2)->union(Sequence{ (N + 1) div 2 }) ) ; A := A->sort() ; var dp : Sequence := Sequence{ 1 }->union(MatrixLib.elementwiseMult(Sequence{ 0 }, (N + N + 10))) ; for x : A do ( for i : Integer.subrange(0, N + 1-1) do ( dp[i+1] := dp[i+1] mod MOD ; dp[i + x+1] := dp[i + x+1] + dp[i+1])) ; var answer : int := (dp.subrange(1,N))->sum() mod MOD ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(m,height,width): def calc_hist(m): hist=[[0]*width for _ in range(height)] for y,row in enumerate(m): for x,ch in enumerate(row): if ch=='.' : hist[y][x]=hist[y-1][x]+1 if y>0 else 1 return hist def calc_area(hist): stack=[] area=0 for x,h in enumerate(hist): if not stack or stack[-1][0]h : while stack and stack[-1][0]>=h : hh,left=stack.pop() area=max(area,hh*(x-left)) stack.append((h,left)) return area hist=calc_hist(m) ans=0 for y in range(height): ans=max(ans,calc_area(hist[y]+[0])) return ans def main(args): while True : height,width=map(int,input().split()) if height==0 or width==0 : break m=[input()for _ in range(height)] ans=solve(m,height,width) print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(m : OclAny, height : OclAny, width : OclAny) : OclAny pre: true post: true activity: skip ; skip ; hist := calc_hist(m) ; var ans : int := 0 ; for y : Integer.subrange(0, height-1) do ( ans := Set{ans, calc_area(hist[y+1]->union(Sequence{ 0 }))}->max()) ; return ans; operation main(args : OclAny) pre: true post: true activity: while true do ( Sequence{height,width} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if height = 0 or width = 0 then ( break ) else skip ; m := Integer.subrange(0, height-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; ans := solve(m, height, width) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countFreq(pat,txt): M=len(pat) N=len(txt) res=0 for i in range(N-M+1): j=0 for j in range(M): if(txt[i+j]!=pat[j]): break if(j==M-1): res+=1 j=0 return res if __name__=='__main__' : txt="dhimanman" pat="man" print(countFreq(pat,txt)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( txt := "dhimanman" ; pat := "man" ; execute (countFreq(pat, txt))->display() ) else skip; operation countFreq(pat : OclAny, txt : OclAny) : OclAny pre: true post: true activity: var M : int := (pat)->size() ; var N : int := (txt)->size() ; var res : int := 0 ; for i : Integer.subrange(0, N - M + 1-1) do ( var j : int := 0 ; for j : Integer.subrange(0, M-1) do ( if (txt[i + j+1] /= pat[j+1]) then ( break ) else skip) ; if (j = M - 1) then ( res := res + 1 ; j := 0 ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) div1=[]; div2=[] if m==0 : print(n-1) else : for _ in range(m): a,b=map(int,input().split()) div1.append(max(a,b)) div2.append(min(a,b)) print(max(0,min(div1)-max(div2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var div1 : Sequence := Sequence{}; var div2 : Sequence := Sequence{} ; if m = 0 then ( execute (n - 1)->display() ) else ( for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Set{a, b}->max()) : div1) ; execute ((Set{a, b}->min()) : div2)) ; execute (Set{0, (div1)->min() - (div2)->max()}->max())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().strip().split(' ')) l=[0]*n ma=0 mb=1000000 f=0 for j in range(m): a1,a2=map(int,input().strip().split(' ')) if a2ma : ma=a1 if a2=mb or a2<=ma : f=1 print(0) break else : l[a1-1]=1 l[a2-1]=1 if f==0 : l2=0 for j in range(n): if l[j]==0 : if j+1>ma and j+1trim().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var ma : int := 0 ; var mb : int := 1000000 ; var f : int := 0 ; for j : Integer.subrange(0, m-1) do ( var a1 : OclAny := null; var a2 : OclAny := null; Sequence{a1,a2} := (input()->trim().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; if (a2->compareTo(a1)) < 0 then ( var a1 : OclAny := null; var a2 : OclAny := null; Sequence{a1,a2} := Sequence{a2,a1} ) else skip ; if (a1->compareTo(ma)) > 0 then ( ma := a1 ) else skip ; if (a2->compareTo(mb)) < 0 then ( mb := a2 ) else skip ; if (a1->compareTo(mb)) >= 0 or (a2->compareTo(ma)) <= 0 then ( f := 1 ; execute (0)->display() ; break ) else ( l[a1 - 1+1] := 1 ; l[a2 - 1+1] := 1 )) ; if f = 0 then ( var l2 : int := 0 ; for j : Integer.subrange(0, n-1) do ( if l[j+1] = 0 then ( if (j + 1->compareTo(ma)) > 0 & (j + 1->compareTo(mb)) < 0 then ( l2 := l2 + 1 ) else skip ) else skip) ; if m = 0 then ( execute (l2 - 1)->display() ) else ( execute (l2 + 1)->display() ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) l1=set() l2=set() for i in range(m): k,t=sorted(map(int,input().split())) l1.add(k) l2.add(t) if m==0 : print(n-1) else : q1,q2=l1.intersection(l2),l1.union(l2) if len(q1): print(0) else : maxl=max(l1) minh=min(l2) if maxl>minh : print(0) else : if len(q2)==n : print(1) else : t=0 for i in range(1,n+1): if i not in q2 : if minh>i>maxl and icollect( _x | (OclType["int"])->apply(_x) ) ; var l1 : Set := Set{}->union(()) ; var l2 : Set := Set{}->union(()) ; for i : Integer.subrange(0, m-1) do ( var k : OclAny := null; var t : OclAny := null; Sequence{k,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; execute ((k) : l1) ; execute ((t) : l2)) ; if m = 0 then ( execute (n - 1)->display() ) else ( var q1 : OclAny := null; var q2 : OclAny := null; Sequence{q1,q2} := Sequence{l1->intersection(l2),l1.union(l2)} ; if (q1)->size() then ( execute (0)->display() ) else ( var maxl : OclAny := (l1)->max() ; var minh : OclAny := (l2)->min() ; if (maxl->compareTo(minh)) > 0 then ( execute (0)->display() ) else ( if (q2)->size() = n then ( execute (1)->display() ) else ( var t : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( if (q2)->excludes(i) then ( if (minh->compareTo(i)) > 0 & (i > maxl) & (i->compareTo(minh)) < 0 then ( t := t + 1 ) else skip ) else skip) ; execute (t + 1)->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) alexHappy=False for i in range(n): a,b=input().split(" ") if a!=b : alexHappy=True if alexHappy : print("Happy Alex") else : print("Poor Alex") if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var alexHappy : boolean := false ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split(" ") ; if a /= b then ( alexHappy := true ) else skip) ; if alexHappy then ( execute ("Happy Alex")->display() ) else ( execute ("Poor Alex")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) l1=set() l2=set() for i in range(m): k,t=sorted(map(int,input().split())) l1.add(k) l2.add(t) if m==0 : print(n-1) else : q1,q2=l1.intersection(l2),l1.union(l2) if len(q1): print(0) else : maxl=max(l1) minh=min(l2) if maxl>minh : print(0) else : if len(q2)==n : print(1) else : t=0 for i in range(1,n+1): if i not in q2 : if minh>i>maxl and icollect( _x | (OclType["int"])->apply(_x) ) ; var l1 : Set := Set{}->union(()) ; var l2 : Set := Set{}->union(()) ; for i : Integer.subrange(0, m-1) do ( var k : OclAny := null; var t : OclAny := null; Sequence{k,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; execute ((k) : l1) ; execute ((t) : l2)) ; if m = 0 then ( execute (n - 1)->display() ) else ( var q1 : OclAny := null; var q2 : OclAny := null; Sequence{q1,q2} := Sequence{l1->intersection(l2),l1.union(l2)} ; if (q1)->size() then ( execute (0)->display() ) else ( var maxl : OclAny := (l1)->max() ; var minh : OclAny := (l2)->min() ; if (maxl->compareTo(minh)) > 0 then ( execute (0)->display() ) else ( if (q2)->size() = n then ( execute (1)->display() ) else ( var t : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( if (q2)->excludes(i) then ( if (minh->compareTo(i)) > 0 & (i > maxl) & (i->compareTo(minh)) < 0 then ( t := t + 1 ) else skip ) else skip) ; execute (t + 1)->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=[] n=int(input()) a=input().split()[: :-1] a=list(dict.fromkeys(a)) a=a[: :-1] print(a[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := Sequence{} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := input().split()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; a := ((trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))->keys()->asSequence() ; a := a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; execute (a->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) g={} for i in range(n): g[a[i]]=i print(min(g,key=g.get)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var g : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( g[a[i+1]+1] := i) ; execute (Set{g, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name g)) (trailer . (name get)))))))}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()); l=list(map(int,input().split()))[: :-1] b=set(); a=set(l); c=len(a) for i in l : if i not in b : if c-1==len(b): print(i); break else : b.add(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var l : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var b : Set := Set{}->union(()); var a : Set := Set{}->union((l)); var c : int := (a)->size() ; for i : l do ( if (b)->excludes(i) then ( if c - 1 = (b)->size() then ( execute (i)->display(); break ) else ( execute ((i) : b) ) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- number_of_cafes=int(input()) visited_cafes=list(map(int,input().split(' '))) number_of_different_cafes=set(visited_cafes) visited_cafes.reverse() for i in range(number_of_cafes): if len(number_of_different_cafes)==1 : break if visited_cafes[i]in number_of_different_cafes : number_of_different_cafes.remove(visited_cafes[i]) print(*number_of_different_cafes) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var number_of_cafes : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var visited_cafes : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var number_of_different_cafes : Set := Set{}->union((visited_cafes)) ; visited_cafes := visited_cafes->reverse() ; for i : Integer.subrange(0, number_of_cafes-1) do ( if (number_of_different_cafes)->size() = 1 then ( break ) else skip ; if (number_of_different_cafes)->includes(visited_cafes[i+1]) then ( execute ((visited_cafes[i+1]) /: number_of_different_cafes) ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name number_of_different_cafes))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,k=map(int,input().split()) if k % 4==0 : print('NO') else : if k % 4==2 : print('YES') i=1 while itoInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if k mod 4 = 0 then ( execute ('NO')->display() ) else ( if k mod 4 = 2 then ( execute ('YES')->display() ; var i : int := 1 ; while (i->compareTo(n)) < 0 do ( if i mod 4 = 1 then ( execute (i + 1)->display() ) else ( execute (i)->display() ) ; i := i + 2) ) else ( execute ('YES')->display() ; i := 1 ; while (i->compareTo(n)) < 0 do ( execute (i)->display() ; i := i + 2) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np n,m=map(int,input().split()) coef=np.minimum(np.arange(n,1,-1),np.arange(1,n)) dp=np.zeros(n,dtype=np.int64) dp[0]=1 for c in coef : ndp=dp.copy() for i in range(c,n,c): ndp[i :]+=dp[: n-i] dp=ndp % m print((dp*np.arange(n,0,-1)% m).sum()% m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var coef : (trailer . (name minimum) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name np)) (trailer . (name arange) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name np)) (trailer . (name arange) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))) ))) := ; var dp : Sequence := MatrixLib.singleValueMatrix(n, 0.0) ; dp->first() := 1 ; for c : coef do ( var ndp : OclAny := dp->copy() ; for i : Integer.subrange(c, n-1)->select( $x | ($x - c) mod c = 0 ) do ( ndp.subrange(i+1) := ndp.subrange(i+1) + dp.subrange(1,n - i)) ; dp := ndp mod m) ; execute ((MatrixLib.dotProduct(dp,MathLib.numericRange(n, 0, -1)) mod m).sum() mod m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=[] n=int(input()) a=input().split()[: :-1] a=list(dict.fromkeys(a)) a=a[: :-1] print(a[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := Sequence{} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := input().split()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; a := ((trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))->keys()->asSequence() ; a := a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; execute (a->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def NicomachuTheorum_sum(n): sum=0 ; for k in range(1,n+1): sum+=k*k*k ; triNo=n*(n+1)/2 ; if(sum==triNo*triNo): print("Yes"); else : print("No"); n=5 ; NicomachuTheorum_sum(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5; ; NicomachuTheorum_sum(n);; operation NicomachuTheorum_sum(n : OclAny) pre: true post: true activity: var sum : int := 0; ; for k : Integer.subrange(1, n + 1-1) do ( sum := sum + k * k * k;) ; var triNo : double := n * (n + 1) / 2; ; if (sum = triNo * triNo) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin for _ in range(int(stdin.readline())): word=stdin.readline() msg="NO" acu1=int(word[0])+int(word[1])+int(word[2]) acu2=int(word[3])+int(word[4])+int(word[5]) if acu1==acu2 : msg="YES" print(msg) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + ((stdin.readLine())))->toInteger()-1) do ( var word : String := stdin.readLine() ; var msg : String := "NO" ; var acu1 : int := ("" + ((word->first())))->toInteger() + ("" + ((word[1+1])))->toInteger() + ("" + ((word[2+1])))->toInteger() ; var acu2 : int := ("" + ((word[3+1])))->toInteger() + ("" + ((word[4+1])))->toInteger() + ("" + ((word[5+1])))->toInteger() ; if acu1 = acu2 then ( msg := "YES" ) else skip ; execute (msg)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) mat=[list(map(int,input().split()))for i in range(n)] mat.sort() happy=False k=[] p=[] for i in range(n): k.append(mat[i][1]) p.append(mat[i][1]) p.sort() for i in range(n): if(k[i]!=p[i]): happy=True if(happy): print("Happy Alex") else : print("Poor Alex") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mat : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; mat := mat->sort() ; var happy : boolean := false ; var k : Sequence := Sequence{} ; var p : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((mat[i+1][1+1]) : k) ; execute ((mat[i+1][1+1]) : p)) ; p := p->sort() ; for i : Integer.subrange(0, n-1) do ( if (k[i+1] /= p[i+1]) then ( happy := true ) else skip) ; if (happy) then ( execute ("Happy Alex")->display() ) else ( execute ("Poor Alex")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : s=input() sm,ans=0,0 for i in range(3): sm+=int(s[i]) ans+=int(s[5-i]) if ans==sm : print("YES") else : print("NO") t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( var s : String := (OclFile["System.in"]).readLine() ; var sm : OclAny := null; var ans : OclAny := null; Sequence{sm,ans} := Sequence{0,0} ; for i : Integer.subrange(0, 3-1) do ( sm := sm + ("" + ((s[i+1])))->toInteger() ; ans := ans + ("" + ((s[5 - i+1])))->toInteger()) ; if ans = sm then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): s=input() l=[] for i in s : l.append(int(i)) if l[1]+l[0]+l[2]==l[3]+l[4]+l[5]: print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var l : Sequence := Sequence{} ; for i : s->characters() do ( execute ((("" + ((i)))->toInteger()) : l)) ; if l[1+1] + l->first() + l[2+1] = l[3+1] + l[4+1] + l[5+1] then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) tickets=[] for i in range(n): tickets.append(input()) numbers=[int(x)for x in tickets[i]] if(sum(numbers[: 3])==sum(numbers[3 :])): print("yes") else : print("no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var tickets : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : tickets) ; var numbers : Sequence := tickets[i+1]->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if ((numbers.subrange(1,3))->sum() = (numbers.subrange(3+1))->sum()) then ( execute ("yes")->display() ) else ( execute ("no")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): s=input() a=int(s[0])+int(s[1])+int(s[2]) b=int(s[3])+int(s[4])+int(s[5]) if a==b : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var a : int := ("" + ((s->first())))->toInteger() + ("" + ((s[1+1])))->toInteger() + ("" + ((s[2+1])))->toInteger() ; var b : int := ("" + ((s[3+1])))->toInteger() + ("" + ((s[4+1])))->toInteger() + ("" + ((s[5+1])))->toInteger() ; if a = b then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isReverseEqual(s1,s2): if len(s1)!=len(s2): return False l=len(s1) for i in range(l): if s1[i]!=s2[l-i-1]: return False return True def getWord(str,n): for i in range(n-1): for j in range(i+1,n): if(isReverseEqual(str[i],str[j])): return str[i] return "-1" if __name__=="__main__" : str=["geeks","for","skeeg"] print(getWord(str,3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( OclType["String"] := Sequence{"geeks"}->union(Sequence{"for"}->union(Sequence{ "skeeg" })) ; execute (getWord(OclType["String"], 3))->display() ) else skip; operation isReverseEqual(s1 : OclAny, s2 : OclAny) : OclAny pre: true post: true activity: if (s1)->size() /= (s2)->size() then ( return false ) else skip ; var l : int := (s1)->size() ; for i : Integer.subrange(0, l-1) do ( if s1[i+1] /= s2[l - i - 1+1] then ( return false ) else skip) ; return true; operation getWord(OclType["String"] : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if (isReverseEqual(("" + ([i+1])), ("" + ([j+1])))) then ( return ("" + ([i+1])) ) else skip)) ; return "-1"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printWords(h,m): nums=["zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty","twenty one","twenty two","twenty three","twenty four","twenty five","twenty six","twenty seven","twenty eight","twenty nine"]; if(m==0): print(nums[h],"o' clock"); elif(m==1): print("one minute past",nums[h]); elif(m==59): print("one minute to",nums[(h % 12)+1]); elif(m==15): print("quarter past",nums[h]); elif(m==30): print("half past",nums[h]); elif(m==45): print("quarter to",(nums[(h % 12)+1])); elif(m<=30): print(nums[m],"minutes past",nums[h]); elif(m>30): print(nums[60-m],"minutes to",nums[(h % 12)+1]); h=6 ; m=24 ; printWords(h,m); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; h := 6; ; m := 24; ; printWords(h, m);; operation printWords(h : OclAny, m : OclAny) pre: true post: true activity: var nums : Sequence := Sequence{"zero"}->union(Sequence{"one"}->union(Sequence{"two"}->union(Sequence{"three"}->union(Sequence{"four"}->union(Sequence{"five"}->union(Sequence{"six"}->union(Sequence{"seven"}->union(Sequence{"eight"}->union(Sequence{"nine"}->union(Sequence{"ten"}->union(Sequence{"eleven"}->union(Sequence{"twelve"}->union(Sequence{"thirteen"}->union(Sequence{"fourteen"}->union(Sequence{"fifteen"}->union(Sequence{"sixteen"}->union(Sequence{"seventeen"}->union(Sequence{"eighteen"}->union(Sequence{"nineteen"}->union(Sequence{"twenty"}->union(Sequence{"twenty one"}->union(Sequence{"twenty two"}->union(Sequence{"twenty three"}->union(Sequence{"twenty four"}->union(Sequence{"twenty five"}->union(Sequence{"twenty six"}->union(Sequence{"twenty seven"}->union(Sequence{"twenty eight"}->union(Sequence{ "twenty nine" }))))))))))))))))))))))))))))); ; if (m = 0) then ( execute (nums[h+1])->display(); ) else (if (m = 1) then ( execute ("one minute past")->display(); ) else (if (m = 59) then ( execute ("one minute to")->display(); ) else (if (m = 15) then ( execute ("quarter past")->display(); ) else (if (m = 30) then ( execute ("half past")->display(); ) else (if (m = 45) then ( execute ("quarter to")->display(); ) else (if (m <= 30) then ( execute (nums[m+1])->display(); ) else (if (m > 30) then ( execute (nums[60 - m+1])->display(); ) else skip ) ) ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) k,*b=map(int,input().split()) t=sum(1<toInteger() ; var k : OclAny := null; var b : OclAny := null; Sequence{k,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name i))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name b))))))))->sum() ; for i : Integer.subrange(0, 1 * (2->pow(n))-1) do ( if MathLib.bitwiseAnd(i, t) /= t then ( continue ) else skip ; var rs : Sequence := Sequence{ ("" + ((i))) + ":" } ; for j : Integer.subrange(0, n-1) do ( if MathLib.bitwiseAnd(i, (1 * (2->pow(j)))) /= 0 then ( execute ((j) : rs) ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name rs))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) A=list(range(1,N//2+1))*2 if N & 1 : A+=[(N+1)//2] d=[1]+[0]*(N+N) for x in A : for i in range(N+1): d[i]%=M d[i+x]+=d[i] print(sum(d[: N])% M) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := MatrixLib.elementwiseMult((Integer.subrange(1, N div 2 + 1-1)), 2) ; if MathLib.bitwiseAnd(N, 1) then ( A := A + Sequence{ (N + 1) div 2 } ) else skip ; var d : Sequence := Sequence{ 1 }->union(MatrixLib.elementwiseMult(Sequence{ 0 }, (N + N))) ; for x : A do ( for i : Integer.subrange(0, N + 1-1) do ( d[i+1] := d[i+1] mod M ; d[i + x+1] := d[i + x+1] + d[i+1])) ; execute ((d.subrange(1,N))->sum() mod M)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) U=[n-1-i for i in range(n)] ind='0'+str(n)+'b' t=list(map(int,input().split())) T=t[1 :] for i in range(2**n): compare=[int(j)for j in format(i,ind)] disp=[U[j]for j in range(n)if compare[j]==1] disp.reverse() if sorted(list(set(T)& set(disp)))==T : print(i,end=":") if len(disp)!=0 : print(""+' '.join(map(str,disp)),end="") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var U : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (n - 1 - i)) ; var ind : String := '0' + ("" + ((n))) + 'b' ; var t : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var T : OclAny := t->tail() ; for i : Integer.subrange(0, (2)->pow(n)-1) do ( var compare : Sequence := (i + "")->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; var disp : Sequence := Integer.subrange(0, n-1)->select(j | compare[j+1] = 1)->collect(j | (U[j+1])) ; disp := disp->reverse() ; if (MathLib.bitwiseAnd(Set{}->union((T)), Set{}->union((disp))))->sort() = T then ( execute (i)->display() ; if (disp)->size() /= 0 then ( execute ("" + StringLib.sumStringsWithSeparator(((disp)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ) else skip ; execute (->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : bit=int(input()) k,*E=map(lambda x : int(x),input().split()) m=sum(1<toInteger() ; var k : OclAny := null; var E : OclAny := null; Sequence{k,E} := (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ) ; var m : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name e))))))) (comp_for for (exprlist (expr (atom (name e)))) in (logical_test (comparison (expr (atom (name E))))))))->sum() ; if (0 = m) then ( execute (StringLib.formattedString("0:"))->display() ) else skip ; for d : Integer.subrange(1, 1 * (2->pow(bit))-1) do ( if (MathLib.bitwiseAnd(d, m) = m) then ( execute (StringLib.formattedString("{d}: "))->display() ; execute (StringLib.sumStringsWithSeparator((Integer.subrange(0, bit-1)->select(elem | MathLib.bitwiseAnd(d, (1 * (2->pow(elem)))))->collect(elem | (("" + ((elem)))))), " "))->display() ) else skip) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): a,b=map(int,input().split()) if a!=b : print('Happy Alex') exit() print('Poor Alex') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a /= b then ( execute ('Happy Alex')->display() ; exit() ) else skip) ; execute ('Poor Alex')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) nn=pow(2,n) k=list(map(int,input().split())) mask=k[1 : k[0]+1] if k[0]==0 : for i in range(nn): if i==0 : print("0:") else : bin_str="0"+str(n)+"b" bin_i=format(i,bin_str) ilist=list(bin_i) tmplist=[] for j,bini in enumerate(ilist): if bini=='1' : tmplist.append(n-j-1) tmplist.sort() tmp_str=' '.join(str(tmp)for tmp in tmplist) print(str(i)+": "+tmp_str) else : for i in range(nn): if i==0 : continue bin_str="0"+str(n)+"b" bin_i=format(i,bin_str) ilist=list(bin_i) tmplist=[] for j,bini in enumerate(ilist): if bini=='1' : tmplist.append(n-j-1) if len(set(mask)& set(tmplist))==k[0]: tmplist.sort() tmp_str=' '.join(str(tmp)for tmp in tmplist) print(str(i)+": "+tmp_str) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nn : double := (2)->pow(n) ; var k : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mask : OclAny := k.subrange(1+1, k->first() + 1) ; if k->first() = 0 then ( for i : Integer.subrange(0, nn-1) do ( if i = 0 then ( execute ("0:")->display() ) else ( var bin_str : String := "0" + ("" + ((n))) + "b" ; var bin_i : String := (i + "") ; var ilist : Sequence := (bin_i)->characters() ; var tmplist : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (ilist)->size())->collect( _indx | Sequence{_indx-1, (ilist)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var bini : OclAny := _tuple->at(_indx); if bini = '1' then ( execute ((n - j - 1) : tmplist) ) else skip) ; tmplist := tmplist->sort() ; var tmp_str : String := StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name tmp)))))))) ))))))) (comp_for for (exprlist (expr (atom (name tmp)))) in (logical_test (comparison (expr (atom (name tmplist)))))))), ' ') ; execute (("" + ((i))) + ": " + tmp_str)->display() )) ) else ( for i : Integer.subrange(0, nn-1) do ( if i = 0 then ( continue ) else skip ; bin_str := "0" + ("" + ((n))) + "b" ; bin_i := (i + "") ; ilist := (bin_i)->characters() ; tmplist := Sequence{} ; for _tuple : Integer.subrange(1, (ilist)->size())->collect( _indx | Sequence{_indx-1, (ilist)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var bini : OclAny := _tuple->at(_indx); if bini = '1' then ( execute ((n - j - 1) : tmplist) ) else skip) ; if (MathLib.bitwiseAnd(Set{}->union((mask)), Set{}->union((tmplist))))->size() = k->first() then ( tmplist := tmplist->sort() ; tmp_str := StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name tmp)))))))) ))))))) (comp_for for (exprlist (expr (atom (name tmp)))) in (logical_test (comparison (expr (atom (name tmplist)))))))), ' ') ; execute (("" + ((i))) + ": " + tmp_str)->display() ) else skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def subset(n,mask): for i in range(2**n): if i & mask==mask : yield i,[v for v in range(n)if i &(1<0] def run(): n=int(input()) mask=0 & 2**n for i in input().split()[1 :]: mask |=1<pow(n)-1) do ( if MathLib.bitwiseAnd(i, mask) = mask then ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return i, Integer.subrange(0, n-1)->select(v | MathLib.bitwiseAnd(i, (1 * (2->pow(v)))) > 0)->collect(v | (v)) ) else skip); operation run() pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; mask := MathLib.bitwiseAnd(0, (2)->pow(n)) ; for i : input().split()->tail() do ( mask := mask or 1 * (2->pow(("" + ((i)))->toInteger()))) ; for _tuple : subset(n, mask) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var vs : OclAny := _tuple->at(_indx); execute (StringLib.interpolateStrings("{}:{}", Sequence{i, StringLib.sumStringsWithSeparator((vs->select(v | true)->collect(v | (StringLib.interpolateStrings("{}", Sequence{v})))), "")}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findArea(a,b): Area=3.142*a*b ; print("Area:",round(Area,2)); a=5 ; b=4 ; findArea(a,b); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 5; ; b := 4; ; findArea(a, b);; operation findArea(a : OclAny, b : OclAny) pre: true post: true activity: var Area : double := 3.142 * a * b; ; execute ("Area:")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(H,S): return H*H>=4*S ; def findPairs(H,n,S,m): count=0 ; H.sort(); S.sort(); index=-1 ; for i in range(n): start=0 ; end=m-1 ; while(start<=end): mid=int(start+(end-start)/2); if(check(H[i],S[mid])): index=mid ; start=mid+1 ; else : end=mid-1 ; if(index!=-1): count+=index+1 ; return count ; H=[1,6,4]; n=len(H); S=[23,3,42,14]; m=len(S); print(findPairs(H,n,S,m)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; H := Sequence{1}->union(Sequence{6}->union(Sequence{ 4 })); ; n := (H)->size(); ; S := Sequence{23}->union(Sequence{3}->union(Sequence{42}->union(Sequence{ 14 }))); ; m := (S)->size(); ; execute (findPairs(H, n, S, m))->display();; operation check(H : OclAny, S : OclAny) pre: true post: true activity: return (H * H->compareTo(4 * S)) >= 0;; operation findPairs(H : OclAny, n : OclAny, S : OclAny, m : OclAny) pre: true post: true activity: var count : int := 0; ; H := H->sort(); ; S := S->sort(); ; var index : int := -1; ; for i : Integer.subrange(0, n-1) do ( var start : int := 0; ; var end : double := m - 1; ; while ((start->compareTo(end)) <= 0) do ( var mid : int := ("" + ((start + (end - start) / 2)))->toInteger(); ; if (check(H[i+1], S[mid+1])) then ( index := mid; ; start := mid + 1; ) else ( end := mid - 1; )) ; if (index /= -1) then ( count := count + index + 1; ) else skip) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math p=(1+math.sqrt(5))/2 q=(1-math.sqrt(5))/2 def fib(n): i=n-1 x=(p**i-q**i)/(p-q) return int(x) n=5 print(fib(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var p : double := (1 + (5)->sqrt()) / 2 ; var q : double := (1 - (5)->sqrt()) / 2 ; skip ; n := 5 ; execute (fib(n))->display(); operation fib(n : OclAny) : OclAny pre: true post: true activity: var i : double := n - 1 ; var x : double := ((p)->pow(i) - (q)->pow(i)) / (p - q) ; return ("" + ((x)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys S=input() prev="" for i in S : if i==prev : print("Bad") sys.exit(0) prev=i print("Good") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var S : String := (OclFile["System.in"]).readLine() ; var prev : String := "" ; for i : S->characters() do ( if i = prev then ( execute ("Bad")->display() ; sys.exit(0) ) else skip ; prev := i) ; execute ("Good")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np from sys import stdin from copy import deepcopy from functools import reduce from fractions import gcd import math import itertools from collections import Counter from itertools import chain from heapq import heappush,heappop S=input() ans='Good' for i in range(3): if S[i]==S[i+1]: ans='Bad' print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var S : String := (OclFile["System.in"]).readLine() ; var ans : String := 'Good' ; for i : Integer.subrange(0, 3-1) do ( if S[i+1] = S[i + 1+1] then ( ans := 'Bad' ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=list(input()) if S[0]==S[1]or S[1]==S[2]or S[2]==S[3]: print('Bad') else : print('Good') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if S->first() = S[1+1] or S[1+1] = S[2+1] or S[2+1] = S[3+1] then ( execute ('Bad')->display() ) else ( execute ('Good')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np n,m=map(int,input().split()) coef=np.minimum(np.arange(n,1,-1),np.arange(1,n)) dp=np.zeros(n,dtype=np.int64) dp[0]=1 for c in coef : ndp=np.zeros(n,dtype=np.int64) for i in range(0,n,c): ndp[i :]+=dp[: n-i] dp=ndp % m print((dp*np.arange(n,0,-1)% m).sum()% m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var coef : (trailer . (name minimum) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name np)) (trailer . (name arange) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name np)) (trailer . (name arange) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))) ))) := ; var dp : Sequence := MatrixLib.singleValueMatrix(n, 0.0) ; dp->first() := 1 ; for c : coef do ( var ndp : Sequence := MatrixLib.singleValueMatrix(n, 0.0) ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod c = 0 ) do ( ndp.subrange(i+1) := ndp.subrange(i+1) + dp.subrange(1,n - i)) ; dp := ndp mod m) ; execute ((MatrixLib.dotProduct(dp,MathLib.numericRange(n, 0, -1)) mod m).sum() mod m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() bad=False for i,v in enumerate(s[:-1]): if s[i+1]==v : bad=True print("Bad" if bad else "Good") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var bad : boolean := false ; for _tuple : Integer.subrange(1, (s->front())->size())->collect( _indx | Sequence{_indx-1, (s->front())->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if s[i + 1+1] = v then ( bad := true ) else skip) ; execute (if bad then "Bad" else "Good" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=[[int(x)for x in input().split()]for i in range(n)] m.sort(reverse=True) a=m[0] for i in m[1 :]: if i[1]>a[1]: print('Happy Alex') break a=i else : print('Poor Alex') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))) ; m := m->sort() ; var a : OclAny := m->first() ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name m)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name i)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) > (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'Happy Alex'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name a)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'Poor Alex'))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- target=input() array=[] is_ok=True for str in target : array.append(str) for i in range(3): if array[i+1]==array[i]: is_ok=False if is_ok : print('Good') else : print('Bad') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var target : String := (OclFile["System.in"]).readLine() ; var array : Sequence := Sequence{} ; var is_ok : boolean := true ; for OclType["String"] : target->characters() do ( execute ((OclType["String"]) : array)) ; for i : Integer.subrange(0, 3-1) do ( if array[i + 1+1] = array[i+1] then ( is_ok := false ) else skip) ; if is_ok then ( execute ('Good')->display() ) else ( execute ('Bad')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printPermutation(n,k): for i in range(1,n+1): x=2*i-1 ; y=2*i ; if(i<=k): print(y,x,end=" "); else : print(x,y,end=" "); if __name__=="__main__" : n=2 ; k=1 ; printPermutation(n,k); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 2; k := 1; ; printPermutation(n, k); ) else skip; operation printPermutation(n : OclAny, k : OclAny) pre: true post: true activity: for i : Integer.subrange(1, n + 1-1) do ( var x : double := 2 * i - 1; ; var y : double := 2 * i; ; if ((i->compareTo(k)) <= 0) then ( execute (y)->display(); ) else ( execute (x)->display(); )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r=int(input()) print(r*r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (r * r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().rstrip() input_nums=lambda : list(map(int,input().split())) def main(): r=int(input()) print(r**2) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var input_nums : Function := lambda $$ : OclAny in (((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var r : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((r)->pow(2))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin r=int(stdin.readline().rstrip()) print(r*r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var r : int := ("" + ((stdin.readLine().rstrip())))->toInteger() ; execute (r * r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r=int(input()) n=(r*r)/3.14 print(int(n/(1/3.14))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : double := (r * r) / 3.14 ; execute (("" + ((n / (1 / 3.14))))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(int(input())**2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger())->pow(2))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- L=int(input()) ans=(L/3)**3 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var L : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : double := ((L / 3))->pow(3) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): a=[] n=int(input()) print((n/3)**3) def count_section_by_zero(data): count=0 flg=False start=0 for i,d in enumerate(data): if flg is False and d!=0 : count+=1 flg=True if d==0 : flg=False return count def combinations_count(n,r): return math.factorial(n)//(math.factorial(n-r)*math.factorial(r)) def input_list(): return list(map(int,input().split())) def input_list_str(): return map(str,input().split()) def lcm_base(x,y): return(x*y)//fractions.gcd(x,y) def lcm_list(numbers): return reduce(lcm_base,numbers,1) def gcd(*numbers): return reduce(fractions.gcd,numbers) def gcd_list(numbers): return reduce(fractions.gcd,numbers) def divide_two(arg): c=0 while True : if c>=2 : break if arg % 2!=0 : break arg//=2 c+=1 return c 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 import math import fractions import collections from functools import reduce main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; main(); operation main() pre: true post: true activity: var a : Sequence := Sequence{} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (((n / 3))->pow(3))->display(); operation count_section_by_zero(data : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var flg : boolean := false ; var start : int := 0 ; for _tuple : Integer.subrange(1, (data)->size())->collect( _indx | Sequence{_indx-1, (data)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); if flg <>= false & d /= 0 then ( count := count + 1 ; flg := true ) else skip ; if d = 0 then ( flg := false ) else skip) ; return count; operation combinations_count(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: return MathLib.factorial(n) div (MathLib.factorial(n - r) * MathLib.factorial(r)); operation input_list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation input_list_str() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["String"])->apply(_x) ); operation lcm_base(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return (x * y) div fractions.gcd(x, y); operation lcm_list(numbers : OclAny) : OclAny pre: true post: true activity: return reduce(lcm_base, numbers, 1); operation gcd(numbers : OclAny : Sequence(OclAny)) : OclAny pre: true post: true activity: (args * (named_parameter (name numbers))) return reduce(fractions.gcd, numbers); operation gcd_list(numbers : OclAny) : OclAny pre: true post: true activity: return reduce(fractions.gcd, numbers); operation divide_two(arg : OclAny) : OclAny pre: true post: true activity: var c : int := 0 ; while true do ( if c >= 2 then ( break ) else skip ; if arg mod 2 /= 0 then ( break ) else skip ; arg := arg div 2 ; c := c + 1) ; return c; operation prime_factorize(n : OclAny) : OclAny pre: true post: true activity: a := Sequence{} ; while n mod 2 = 0 do ( execute ((2) : a) ; n := n div 2) ; var f : int := 3 ; while (f * f->compareTo(n)) <= 0 do ( if n mod f = 0 then ( execute ((f) : a) ; n := n div f ) else ( f := f + 2 )) ; if n /= 1 then ( execute ((n) : a) ) else skip ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxProfit(prices,n,k): profit=[[0 for i in range(k+1)]for j in range(n)] for i in range(1,n): for j in range(1,k+1): max_so_far=0 for l in range(i): max_so_far=max(max_so_far,prices[i]-prices[l]+profit[l][j-1]) profit[i][j]=max(profit[i-1][j],max_so_far) return profit[n-1][k] k=2 prices=[10,22,5,75,65,80] n=len(prices) print("Maximum profit is:",maxProfit(prices,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; k := 2 ; prices := Sequence{10}->union(Sequence{22}->union(Sequence{5}->union(Sequence{75}->union(Sequence{65}->union(Sequence{ 80 }))))) ; n := (prices)->size() ; execute ("Maximum profit is:")->display(); operation maxProfit(prices : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var profit : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (Integer.subrange(0, k + 1-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(1, n-1) do ( for j : Integer.subrange(1, k + 1-1) do ( var max_so_far : int := 0 ; for l : Integer.subrange(0, i-1) do ( max_so_far := Set{max_so_far, prices[i+1] - prices[l+1] + profit[l+1][j - 1+1]}->max()) ; profit[i+1][j+1] := Set{profit[i - 1+1][j+1], max_so_far}->max())) ; return profit[n - 1+1][k+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxnumber(n,k): for i in range(0,k): ans=0 i=1 while n//i>0 : temp=(n//(i*10))*i+(n % i) i*=10 if temp>ans : ans=temp n=ans return ans ; n=6358 k=1 print(maxnumber(n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 6358 ; k := 1 ; execute (maxnumber(n, k))->display(); operation maxnumber(n : OclAny, k : OclAny) pre: true post: true activity: for i : Integer.subrange(0, k-1) do ( var ans : int := 0 ; var i : int := 1 ; while n div i > 0 do ( var temp : int := (n div (i * 10)) * i + (n mod i) ; i := i * 10 ; if (temp->compareTo(ans)) > 0 then ( ans := temp ) else skip) ; n := ans) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) ii=lambda : int(input()) mis=lambda : map(int,input().split()) lmis=lambda : list(mis()) INF=float('inf') def main(): L=float(input()) a=L/3 b=(L-a)/2 print(a*b*(L-a-b)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; var ii : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var mis : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lmis : Function := lambda $$ : OclAny in ((mis->apply())) ; var INF : double := ("" + (('inf')))->toReal() ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var L : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; var a : double := L / 3 ; var b : double := (L - a) / 2 ; execute (a * b * (L - a - b))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print((int(input())/3)**3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (((("" + (((OclFile["System.in"]).readLine())))->toInteger() / 3))->pow(3))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- gi=lambda : list(map(int,input().split())) n,=gi() print((n/3)**3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var gi : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,)} := gi->apply() ; execute (((n / 3))->pow(3))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) p=0 for a in range(1,100): for b in range(1,100): if b<=x : if a % b==0 and a*b>x>(a/b): p=2 print(a,b) exit() if p==0 : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : int := 0 ; for a : Integer.subrange(1, 100-1) do ( for b : Integer.subrange(1, 100-1) do ( if (b->compareTo(x)) <= 0 then ( if a mod b = 0 & (a * b->compareTo(x)) > 0 & (x > (a / b)) then ( p := 2 ; execute (a)->display() ; exit() ) else skip ) else skip)) ; if p = 0 then ( execute (-1)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline x=int(input()) if x==1 : ans=[-1] else : ans=[x,x] sys.stdout.write(" ".join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if x = 1 then ( var ans : Sequence := Sequence{ -1 } ) else ( ans := Sequence{x}->union(Sequence{ x }) ) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " ") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) c=0 for a in range(1,x+1): for b in range(1,x+1): if a % b==0 and a*b>x and a/btoInteger() ; var c : int := 0 ; for a : Integer.subrange(1, x + 1-1) do ( for b : Integer.subrange(1, x + 1-1) do ( if a mod b = 0 & (a * b->compareTo(x)) > 0 & (a / b->compareTo(x)) < 0 then ( c := 1 ; execute (a)->display() ; break ) else skip) ; if c = 1 then ( break ) else skip) ; if c = 0 then ( execute ('-1')->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) answer_found=False for a in range(1,x+1): for b in range(1,x+1): if a % b==0 and a*b>x and a/btoInteger() ; var answer_found : boolean := false ; for a : Integer.subrange(1, x + 1-1) do ( for b : Integer.subrange(1, x + 1-1) do ( if a mod b = 0 & (a * b->compareTo(x)) > 0 & (a / b->compareTo(x)) < 0 then ( execute (StringLib.formattedString('{a}{b}'))->display() ; answer_found := true ) else skip) ; if answer_found = true then ( break ) else skip) ; if answer_found = false then ( execute (-1)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) if k<=1 : print(-1) else : print(k,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if k <= 1 then ( execute (-1)->display() ) else ( execute (k)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nCr(n,r): return(fact(n)/(fact(r)*fact(n-r))) def fact(n): res=1 for i in range(2,n+1): res=res*i return res n=5 r=3 print(int(nCr(n,r))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 5 ; r := 3 ; execute (("" + ((nCr(n, r))))->toInteger())->display(); operation nCr(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: return (fact(n) / (fact(r) * fact(n - r))); operation fact(n : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; for i : Integer.subrange(2, n + 1-1) do ( res := res * i) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import sys if os.getenv("LOCAL"): sys.stdin=open("_in.txt","r") sys.setrecursionlimit(10**9) INF=float("inf") IINF=10**18 MOD=10**9+7 N,M=list(map(int,sys.stdin.buffer.readline().split())) AB=[list(map(int,sys.stdin.buffer.readline().split()))for _ in range(M)] Q=int(sys.stdin.buffer.readline()) VDC=[list(map(int,sys.stdin.buffer.readline().split()))for _ in range(Q)] graph=[[]for _ in range(N)] for a,b in AB : a-=1 b-=1 graph[a].append(b) graph[b].append(a) dp=[[None]*11 for _ in range(N)] for i,(v,d,c)in reversed(list(enumerate(VDC))): v-=1 if not dp[v][d]: dp[v][d]=i,c for d in reversed(range(1,11)): for v in range(N): if not dp[v][d]: continue for u in graph[v]+[v]: if not dp[u][d-1]or(dp[u][d-1]and dp[u][d-1][0]pow(9)) ; var INF : double := ("" + (("inf")))->toReal() ; var IINF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := ((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var AB : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var Q : int := ("" + ((sys.stdin.buffer.readLine())))->toInteger() ; var VDC : Sequence := Integer.subrange(0, Q-1)->select(_anon | true)->collect(_anon | (((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var graph : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _tuple : AB do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); a := a - 1 ; b := b - 1 ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var dp : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ null }, 11))) ; for _tuple : ((Integer.subrange(1, (VDC)->size())->collect( _indx | Sequence{_indx-1, (VDC)->at(_indx)} )))->reverse() do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{v, d, c} : OclAny := _tuple->at(_indx); v := v - 1 ; if not(dp[v+1][d+1]) then ( dp[v+1][d+1] := i,c ) else skip) ; for d : (Integer.subrange(1, 11-1))->reverse() do ( for v : Integer.subrange(0, N-1) do ( if not(dp[v+1][d+1]) then ( continue ) else skip ; for u : graph[v+1]->union(Sequence{ v }) do ( if not(dp[u+1][d - 1+1]) or (dp[u+1][d - 1+1] & (dp[u+1][d - 1+1]->first()->compareTo(dp[v+1][d+1]->first())) < 0) then ( dp[u+1][d - 1+1] := dp[v+1][d+1] ) else skip))) ; for v : Integer.subrange(0, N-1) do ( if dp[v+1]->first() then ( execute (dp[v+1]->first()[1+1])->display() ) else ( execute (0)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- count=0 n=input() if int(n)>=3 and int(n)<=100 : word=input()[: int(n)] i=1 flag=False while flag==False : if "xxx" in word : count_x=word.count("xxx") count=count+count_x word=word.replace("xxx","xx") else : flag=True i+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var count : int := 0 ; var n : String := (OclFile["System.in"]).readLine() ; if ("" + ((n)))->toInteger() >= 3 & ("" + ((n)))->toInteger() <= 100 then ( var word : OclAny := input().subrange(1,("" + ((n)))->toInteger()) ; var i : int := 1 ; var flag : boolean := false ; while flag = false do ( if (word)->includes("xxx") then ( var count_x : int := word->count("xxx") ; count := count + count_x ; word := word.replace("xxx", "xx") ) else ( flag := true ) ; i := i + 1) ; execute (count)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): p,q=map(int,input().split()) c=0 for i in range(143): for j in range(143): if(i>0 or j>0)and(j*p+i*q)%(j*j+i*i)==0 and(j*q-i*p)%(j*j+i*i)==0 : c+=1 print('P' if c<5 else 'C') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : int := 0 ; for i : Integer.subrange(0, 143-1) do ( for j : Integer.subrange(0, 143-1) do ( if (i > 0 or j > 0) & (j * p + i * q) mod (j * j + i * i) = 0 & (j * q - i * p) mod (j * j + i * i) = 0 then ( c := c + 1 ) else skip)) ; execute (if c < 5 then 'P' else 'C' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque N,M=map(int,input().split()) G=[[]for i in range(N)] for i in range(M): u,v=map(int,input().split()) G[u-1].append(v-1) G[v-1].append(u-1) Q=int(input()) V=[] D=[] C=[] for qi in range(Q): v,d,c=map(int,input().split()) V.append(v-1) D.append(d) C.append(c) vis=[-1 for i in range(N)] col=[0 for i in range(N)] for qi in range(Q-1,-1,-1): if D[qi]<=vis[V[qi]]: continue que=deque() vis[V[qi]]=D[qi] que.append((D[qi],V[qi])) if col[V[qi]]==0 : col[V[qi]]=C[qi] while len(que): d,u=que.popleft() if d==0 : continue for v in G[u]: if vis[v]>=d-1 : continue vis[v]=d-1 que.append((d-1,v)) if col[v]==0 : col[v]=C[qi] for i in range(N): print(col[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var G : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, M-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name u))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name u))) - (expr (atom (number (integer 1)))))))))) ))))) ; var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var V : Sequence := Sequence{} ; var D : Sequence := Sequence{} ; var C : Sequence := Sequence{} ; for qi : Integer.subrange(0, Q-1) do ( var v : OclAny := null; var d : OclAny := null; var c : OclAny := null; Sequence{v,d,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((v - 1) : V) ; execute ((d) : D) ; execute ((c) : C)) ; var vis : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (-1)) ; var col : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; for qi : Integer.subrange(-1 + 1, Q - 1)->reverse() do ( if (D[qi+1]->compareTo(vis[V[qi+1]+1])) <= 0 then ( continue ) else skip ; var que : Sequence := () ; vis[V[qi+1]+1] := D[qi+1] ; execute ((Sequence{D[qi+1], V[qi+1]}) : que) ; if col[V[qi+1]+1] = 0 then ( col[V[qi+1]+1] := C[qi+1] ) else skip ; while (que)->size() do ( var d : OclAny := null; var u : OclAny := null; Sequence{d,u} := que->first() ; que := que->tail() ; if d = 0 then ( continue ) else skip ; for v : G[u+1] do ( if (vis[v+1]->compareTo(d - 1)) >= 0 then ( continue ) else skip ; vis[v+1] := d - 1 ; execute ((Sequence{d - 1, v}) : que) ; if col[v+1] = 0 then ( col[v+1] := C[qi+1] ) else skip))) ; for i : Integer.subrange(0, N-1) do ( execute (col[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque,defaultdict import sys input=sys.stdin.readline N,M=map(int,input().split()) ab=[list(map(int,input().split()))for i in range(M)] Q=int(input()) vdc=[list(map(int,input().split()))for i in range(Q)] g=defaultdict(set) for a,b in ab : g[a].add(b) g[b].add(a) def dpinit(ps,val=0): import copy res=[val for i in[0]*ps[-1]] for i in ps[:-1][: :-1]: res=[copy.deepcopy(res)for k in[0]*i] return res ans=[0]*(N+1) visited=dpinit([N+1,11],False) for v,d,c in vdc[: :-1]: if visited[v][d]: continue for t in range(d+1): visited[v][t]=True if ans[v]==0 : ans[v]=c vs=[v] for i in range(d-1,-1,-1): temp=[] for pv in vs : for nv in g[pv]: if not visited[nv][i]: for t in range(i+1): visited[nv][t]=True if ans[nv]==0 : ans[nv]=c temp.append(nv) vs=temp for a in ans[1 :]: print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ab : Sequence := Integer.subrange(0, M-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var vdc : Sequence := Integer.subrange(0, Q-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var g : OclAny := defaultdict(OclType["Set"]) ; for _tuple : ab do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; skip ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; var visited : OclAny := dpinit(Sequence{N + 1}->union(Sequence{ 11 }), false) ; for _tuple : vdc(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do (var _indx : int := 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if visited[v+1][d+1] then ( continue ) else skip ; for t : Integer.subrange(0, d + 1-1) do ( visited[v+1][t+1] := true) ; if ans[v+1] = 0 then ( ans[v+1] := c ) else skip ; var vs : Sequence := Sequence{ v } ; for i : Integer.subrange(-1 + 1, d - 1)->reverse() do ( var temp : Sequence := Sequence{} ; for pv : vs do ( for nv : g[pv+1] do ( if not(visited[nv+1][i+1]) then ( for t : Integer.subrange(0, i + 1-1) do ( visited[nv+1][t+1] := true) ; if ans[nv+1] = 0 then ( ans[nv+1] := c ) else skip ; execute ((nv) : temp) ) else skip)) ; vs := temp)) ; for a : ans->tail() do ( execute (a)->display()); operation dpinit(ps : OclAny, val : int) : OclAny pre: true post: true activity: if val->oclIsUndefined() then val := 0 else skip; skip ; var res : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ps->last())->select(i | true)->collect(i | (val)) ; for i : ps->front()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( res := MatrixLib.elementwiseMult(Sequence{ 0 }, i)->select(k | true)->collect(k | (copy.deepcopy(res)))) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) g={} used={i :[False for _ in range(11)]for i in range(n)} color=[0 for _ in range(n)] for _ in range(m): u,v=map(int,input().split()) u-=1 v-=1 if u not in g : g[u]=[] if v not in g : g[v]=[] g[u].append(v) g[v].append(u) q=int(input()) Q=[] for _ in range(q): node,dis,col=map(int,input().split()) Q.append([node-1,dis,col]) Q=Q[: :-1] def bfs(now,dist,col): if dist<0 : return if used[now][dist]: return used[now][dist]=True if not color[now]: color[now]=col if now in g : for x in g[now]: bfs(x,dist-1,col) for node,dis,col in Q : bfs(node,dis,col) for x in color : print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var g : OclAny := Set{} ; var used : Map := Integer.subrange(0, n-1)->select(i | true)->collect(i | Map{i |-> Integer.subrange(0, 11-1)->select(_anon | true)->collect(_anon | (false))})->unionAll() ; var color : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)) ; for _anon : Integer.subrange(0, m-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; u := u - 1 ; v := v - 1 ; if (g)->excludes(u) then ( g[u+1] := Sequence{} ) else skip ; if (g)->excludes(v) then ( g[v+1] := Sequence{} ) else skip ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)))))))) ))))) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var Q : Sequence := Sequence{} ; for _anon : Integer.subrange(0, q-1) do ( var node : OclAny := null; var dis : OclAny := null; var col : OclAny := null; Sequence{node,dis,col} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{node - 1}->union(Sequence{dis}->union(Sequence{ col }))) : Q)) ; Q := Q(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; skip ; for _tuple : Q do (var _indx : int := 1; var node : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dis : OclAny := _tuple->at(_indx); _indx := _indx + 1; var col : OclAny := _tuple->at(_indx); bfs(node, dis, col)) ; for x : color do ( execute (x)->display()); operation bfs(now : OclAny, dist : OclAny, col : OclAny) pre: true post: true activity: if dist < 0 then ( return ) else skip ; if used[now+1][dist+1] then ( return ) else skip ; used[now+1][dist+1] := true ; if not(color[now+1]) then ( color[now+1] := col ) else skip ; if (g)->includes(now) then ( for x : g[now+1] do ( bfs(x, dist - 1, col)) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def main(): N,M,*L=map(int,open(0).read().split()) E=[[]for _ in range(N+1)] for a,b in zip(*[iter(L[: 2*M])]*2): E[a].append(b) E[b].append(a) colors=[0]*(N+1) visited=[-1]*(N+1) for v,d,c in reversed(tuple(zip(*[iter(L[2*M+1 :])]*3))): Q=deque([(d,v)]) while Q : cnt,v=Q.popleft() if visited[v]>=cnt : continue if colors[v]==0 : colors[v]=c visited[v]=cnt if cnt>0 : Q.extend((cnt-1,u)for u in E[v]if visited[u]collect( _x | (OclType["int"])->apply(_x) ) ; var E : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _tuple : Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name M))))))))) ])))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name M))))))))) ])))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name M))))))))) ])))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))`third->at(_indx)} ) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); (expr (atom (name E)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name E)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var colors : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (N + 1)) ; for _tuple : ((Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (number (integer 2)))) * (expr (atom (name M)))) + (expr (atom (number (integer 1)))))))) :)) ])))))))) )))))))) ])) * (expr (atom (number (integer 3)))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (number (integer 2)))) * (expr (atom (name M)))) + (expr (atom (number (integer 1)))))))) :)) ])))))))) )))))))) ])) * (expr (atom (number (integer 3)))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (number (integer 2)))) * (expr (atom (name M)))) + (expr (atom (number (integer 1)))))))) :)) ])))))))) )))))))) ])) * (expr (atom (number (integer 3)))))))))`third->at(_indx)} )))->reverse() do (var _indx : int := 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); var Q : Sequence := (Sequence{ Sequence{d, v} }) ; while Q do ( var cnt : OclAny := null; var v : OclAny := null; Sequence{cnt,v} := Q->first() ; Q := Q->tail() ; if (visited[v+1]->compareTo(cnt)) >= 0 then ( continue ) else skip ; if colors[v+1] = 0 then ( colors[v+1] := c ) else skip ; visited[v+1] := cnt ; if cnt > 0 then ( Q := Q->union((argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name cnt))) - (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (atom (name u))))))) )))))) (comp_for for (exprlist (expr (atom (name u)))) in (logical_test (comparison (expr (atom (name E)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ]))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name visited)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])))) < (comparison (expr (expr (atom (name cnt))) - (expr (atom (number (integer 1))))))))))))) ) else skip)) ; for c : colors->tail() do ( execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys N=3 M=3 def sumOddOccuring(arr): mp=dict() for i in range(N): for j in range(M): if arr[i][j]in mp : mp[arr[i][j]]+=1 else : mp[arr[i][j]]=1 s=0 for i in mp : if mp[i]% 2==0 : x=mp[i] s+=i*mp[i] return s if __name__=="__main__" : mat=[[1,2,3],[1,3,2],[1,5,6]] print(sumOddOccuring(mat)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 3 ; var M : int := 3 ; skip ; if __name__ = "__main__" then ( var mat : Sequence := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{Sequence{1}->union(Sequence{3}->union(Sequence{ 2 }))}->union(Sequence{ Sequence{1}->union(Sequence{5}->union(Sequence{ 6 })) })) ; execute (sumOddOccuring(mat))->display() ) else skip; operation sumOddOccuring(arr : OclAny) : OclAny pre: true post: true activity: var mp : Map := (arguments ( )) ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, M-1) do ( if (mp)->includes(arr[i+1][j+1]) then ( mp[arr[i+1][j+1]+1] := mp[arr[i+1][j+1]+1] + 1 ) else ( mp[arr[i+1][j+1]+1] := 1 ))) ; var s : int := 0 ; for i : mp->keys() do ( if mp[i+1] mod 2 = 0 then ( var x : OclAny := mp[i+1] ; s := s + i * mp[i+1] ) else skip) ; return s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def steps(N,M): if(N==1): return 0 elif(N==2): return M return 2*M+(N-3) N=4 M=4 print(steps(N,M)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 4 ; M := 4 ; execute (steps(N, M))->display(); operation steps(N : OclAny, M : OclAny) : OclAny pre: true post: true activity: if (N = 1) then ( return 0 ) else (if (N = 2) then ( return M ) else skip) ; return 2 * M + (N - 3); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reverseStr(str,l,h): n=h-l for i in range(n//2): str[i+l],str[n-i-1+l]=str[n-i-1+l],str[i+l] def reverseString(s,A,n): reverseStr(s,0,A[0]) for i in range(1,n): reverseStr(s,A[i-1],A[i]) reverseStr(s,A[n-1],len(s)) s="abcdefgh" s=[i for i in s] A=[2,4,6] n=len(A) reverseString(s,A,n) print("".join(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; s := "abcdefgh" ; s := s->select(i | true)->collect(i | (i)) ; A := Sequence{2}->union(Sequence{4}->union(Sequence{ 6 })) ; n := (A)->size() ; reverseString(s, A, n) ; execute (StringLib.sumStringsWithSeparator((s), ""))->display(); operation reverseStr(OclType["String"] : OclAny, l : OclAny, h : OclAny) pre: true post: true activity: var n : double := h - l ; for i : Integer.subrange(0, n div 2-1) do ( var ("" + ([i + l+1])) : OclAny := null; var ("" + ([n - i - 1 + l+1])) : OclAny := null; Sequence{("" + ([i + l+1])),("" + ([n - i - 1 + l+1]))} := Sequence{("" + ([n - i - 1 + l+1])),("" + ([i + l+1]))}); operation reverseString(s : OclAny, A : OclAny, n : OclAny) pre: true post: true activity: reverseStr(s, 0, A->first()) ; for i : Integer.subrange(1, n-1) do ( reverseStr(s, A[i - 1+1], A[i+1])) ; reverseStr(s, A[n - 1+1], (s)->size()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter import math hpop=heappop hpush=heappush def solution(): _,x=map(int,input().split()) arr=map(int,input().split()) sm=abs(sum(arr)) print(sm//x+(sm % x!=0)) def main(): t=1 for _ in range(t): solution() import sys import threading sys.setrecursionlimit(1<<30) threading.stack_size(1<<27) thread=threading.Thread(target=main) thread.start(); thread.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1 * (2->pow(30))) ; threading.stack_size(1 * (2->pow(27))) ; var thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ; thread.start(); thread.join(); operation solution() pre: true post: true activity: var _anon : OclAny := null; var x : OclAny := null; Sequence{_anon,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sm : double := ((arr)->sum())->abs() ; execute (sm div x + (sm mod x /= 0))->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=map(int,input().split()) a=list(map(int,input().split())) print((abs(sum(a))+x-1)//x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((((a)->sum())->abs() + x - 1) div x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) L=[0]*(N*2) for i in range(M): a,l=map(int,input().split()) for ll in range(a,a+l): L[ll]=1 for i in range(N,2*N): L[i-N]=max(L[i-N],L[i]) left=0 i=0 while L[i]==1 : left+=1 i+=1 if i==N : print(N,1) exit() A=[] s=0 for i in range(i,N): li=L[i] if li==0 : if s!=0 : A.append(s) s=0 else : s+=1 if s+left!=0 : A.append(s+left) A.sort(reverse=True) v=A[0] n=0 for a in A : if a==v : n+=1 else : print(v,n) n=1 v=a print(v,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var L : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N * 2)) ; for i : Integer.subrange(0, M-1) do ( var a : OclAny := null; var l : OclAny := null; Sequence{a,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for ll : Integer.subrange(a, a + l-1) do ( L[ll+1] := 1)) ; for i : Integer.subrange(N, 2 * N-1) do ( L[i - N+1] := Set{L[i - N+1], L[i+1]}->max()) ; var left : int := 0 ; var i : int := 0 ; while L[i+1] = 1 do ( left := left + 1 ; i := i + 1 ; if i = N then ( execute (N)->display() ; exit() ) else skip) ; var A : Sequence := Sequence{} ; var s : int := 0 ; for i : Integer.subrange(i, N-1) do ( var li : OclAny := L[i+1] ; if li = 0 then ( if s /= 0 then ( execute ((s) : A) ) else skip ; s := 0 ) else ( s := s + 1 )) ; if s + left /= 0 then ( execute ((s + left) : A) ) else skip ; A := A->sort() ; var v : OclAny := A->first() ; var n : int := 0 ; for a : A do ( if a = v then ( n := n + 1 ) else ( execute (v)->display() ; n := 1 ; v := a )) ; execute (v)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=[int(x)for x in input().split()] s=[int(x)for x in input().split()] count=0 for i in range(0,n[0]): count=count+s[i] count2=0 count=abs(count) while count>0 : count=count-n[1] count2+=1 print(count2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var s : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var count : int := 0 ; for i : Integer.subrange(0, n->first()-1) do ( count := count + s[i+1]) ; var count2 : int := 0 ; count := (count)->abs() ; while count > 0 do ( count := count - n[1+1] ; count2 := count2 + 1) ; execute (count2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def divisor(a): ret=[] for i in range(1,int(a**0.5)+1): if not a % i : ret.append(i) ret.append(a//i) return ret def make_lists(): ret=[[]for i in range(20000)] for i in range(0,int(20000**0.5)+1): for j in range(0,int(20000**0.5)+1): if i**2+j**2<20000 : ret[i**2+j**2].append([i,j]) return ret lists=make_lists() ans=[] for loop in range(int(input())): m,n=map(int,input().split()) C=[] for div in divisor(m**2+n**2): for l in lists[div]: for tmp in[-1,1]: for tmp2 in[-1,1]: x,y=l[0]*tmp,l[1]*tmp2 if not(m*x+n*y)%(x**2+y**2)and not(n*x-m*y)%(x**2+y**2): if[x,y]not in C : C.append([x,y]) ans.append('P' if len(C)==8 else 'C') [print(i)for i in ans] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var lists : OclAny := make_lists() ; var ans : Sequence := Sequence{} ; for loop : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var C : Sequence := Sequence{} ; for div : divisor((m)->pow(2) + (n)->pow(2)) do ( for l : lists[div+1] do ( for tmp : Sequence{-1}->union(Sequence{ 1 }) do ( for tmp2 : Sequence{-1}->union(Sequence{ 1 }) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{l->first() * tmp,l[1+1] * tmp2} ; if not((m * x + n * y) mod ((x)->pow(2) + (y)->pow(2))) & not((n * x - m * y) mod ((x)->pow(2) + (y)->pow(2))) then ( if (C)->excludes(Sequence{x}->union(Sequence{ y })) then ( execute ((Sequence{x}->union(Sequence{ y })) : C) ) else skip ) else skip)))) ; execute ((if (C)->size() = 8 then 'P' else 'C' endif) : ans)) ; ; operation divisor(a : OclAny) : OclAny pre: true post: true activity: var ret : Sequence := Sequence{} ; for i : Integer.subrange(1, ("" + (((a)->pow(0.5))))->toInteger() + 1-1) do ( if not(a mod i) then ( execute ((i) : ret) ; execute ((a div i) : ret) ) else skip) ; return ret; operation make_lists() : OclAny pre: true post: true activity: ret := Integer.subrange(0, 20000-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, ("" + (((20000)->pow(0.5))))->toInteger() + 1-1) do ( for j : Integer.subrange(0, ("" + (((20000)->pow(0.5))))->toInteger() + 1-1) do ( if (i)->pow(2) + (j)->pow(2) < 20000 then ( (expr (atom (name ret)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name i))) ** (expr (atom (number (integer 2))))) + (expr (expr (atom (name j))) ** (expr (atom (number (integer 2))))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) , (test (logical_test (comparison (expr (atom (name j))))))) ]))))))) )))) ) else skip)) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math (number_of_found_cards,maximum_absolute_value_on_a_card)=map(int,input().split(' ')) found_cards=list(map(int,input().split(' '))) print(math.ceil(abs(sum(found_cards)/maximum_absolute_value_on_a_card))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var Sequence{number_of_found_cards, maximum_absolute_value_on_a_card} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var found_cards : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((((found_cards)->sum() / maximum_absolute_value_on_a_card)->abs())->ceil())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) l=[int(i)for i in input().split()] s=abs(sum(l[0 :])) if s==0 : print(0) elif s<=k : print(1) elif s % k==0 : print(s//k) else : print((s//k)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var s : double := ((l.subrange(0+1))->sum())->abs() ; if s = 0 then ( execute (0)->display() ) else (if (s->compareTo(k)) <= 0 then ( execute (1)->display() ) else (if s mod k = 0 then ( execute (s div k)->display() ) else ( execute ((s div k) + 1)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def MaxLCM(n): if(n % 2!=0): print(n,(n-1),(n-2)) elif(gcd(n,(n-3))==1): print(n,(n-1),(n-3)) else : print((n-1),(n-2),(n-3)) if __name__=="__main__" : n=12 MaxLCM(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 12 ; MaxLCM(n) ) else skip; operation MaxLCM(n : OclAny) pre: true post: true activity: if (n mod 2 /= 0) then ( execute (n)->display() ) else (if (gcd(n, (n - 3)) = 1) then ( execute (n)->display() ) else ( execute ((n - 1))->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- read=lambda : map(int,input().split()) n,v=read() N=3002 p=[0]*N for i in range(n): a,b=read() p[a]+=b ans=0 rem=0 for i in range(1,N): cur=min(v,rem+p[i]) ans+=cur if rem>=v : rem=p[i] else : rem=max(0,p[i]-(v-rem)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var read : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var v : OclAny := null; Sequence{n,v} := read->apply() ; var N : int := 3002 ; var p : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := read->apply() ; p[a+1] := p[a+1] + b) ; var ans : int := 0 ; var rem : int := 0 ; for i : Integer.subrange(1, N-1) do ( var cur : OclAny := Set{v, rem + p[i+1]}->min() ; ans := ans + cur ; if (rem->compareTo(v)) >= 0 then ( rem := p[i+1] ) else ( rem := Set{0, p[i+1] - (v - rem)}->max() )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,v=[int(x)for x in input().split()] l=[0]*3002 for i in range(n): a,b=[int(x)for x in input().split()] l[a]+=b ans=0 for i in range(1,3002): left=v if l[i-1]: ans+=min(left,l[i-1]) left-=min(left,l[i-1]) ans+=min(left,l[i]) l[i]-=min(left,l[i]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var v : OclAny := null; Sequence{n,v} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var l : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 3002) ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; l[a+1] := l[a+1] + b) ; var ans : int := 0 ; for i : Integer.subrange(1, 3002-1) do ( var left : OclAny := v ; if l[i - 1+1] then ( ans := ans + Set{left, l[i - 1+1]}->min() ; left := left - Set{left, l[i - 1+1]}->min() ) else skip ; ans := ans + Set{left, l[i+1]}->min() ; l[i+1] := l[i+1] - Set{left, l[i+1]}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,v=map(int,input().split()) l=[0]*3002 for _ in range(n): a,b=map(int,input().split()) l[a]+=b a=res=0 for b in l : x=a+b if xcollect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 3002) ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; l[a+1] := l[a+1] + b) ; var a : OclAny := 0; var res : int := 0 ; for b : l do ( var x : OclAny := a + b ; if (x->compareTo(v)) < 0 then ( res := res + x ; a := 0 ) else ( res := res + v ; if (a->compareTo(v)) < 0 then ( a := x - v ) else ( a := b ) )) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,v=[int(i)for i in input().split()] d={} for i in range(n): a,b=[int(i)for i in input().split()] if a in d : d[a]+=b else : d[a]=b set_tree=sorted(d) set_tree=list(range(1,max(set_tree)+2)) set_tree.append(0) d[0]=0 S=0 for i in set_tree : if i in d : None else : d[i]=0 for i in set_tree[:-1]: if d[i]<=v : S+=d[i] elif d[i]>=2*v : S+=v d[i+1]=d[i+1]+v else : S+=v d[i+1]+=d[i]-v print(S) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var v : OclAny := null; Sequence{n,v} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var d : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if (d)->includes(a) then ( d[a+1] := d[a+1] + b ) else ( d[a+1] := b )) ; var set_tree : Sequence := d->sort() ; set_tree := (Integer.subrange(1, (set_tree)->max() + 2-1)) ; execute ((0) : set_tree) ; d->first() := 0 ; var S : int := 0 ; for i : set_tree do ( if (d)->includes(i) then ( ) else ( d[i+1] := 0 )) ; for i : set_tree->front() do ( if (d[i+1]->compareTo(v)) <= 0 then ( S := S + d[i+1] ) else (if (d[i+1]->compareTo(2 * v)) >= 0 then ( S := S + v ; d[i + 1+1] := d[i + 1+1] + v ) else ( S := S + v ; d[i + 1+1] := d[i + 1+1] + d[i+1] - v ) ) ) ; execute (S)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=3333 ; n,v=map(int,input().split()); data=[0]*T ; for i in range(0,n): a,b=map(int,input().split()); data[a]+=b ; answer=0 ; for i in range(1,T): x=v ; tmp=min(v,data[i-1]); x-=tmp ; data[i-1]-=tmp ; answer+=tmp ; tmp=min(x,data[i]); data[i]-=tmp ; answer+=tmp ; print(answer); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := 3333; ; var n : OclAny := null; var v : OclAny := null; Sequence{n,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); ; var data : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, T); ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); ; data[a+1] := data[a+1] + b;) ; var answer : int := 0; ; for i : Integer.subrange(1, T-1) do ( var x : OclAny := v; ; var tmp : OclAny := Set{v, data[i - 1+1]}->min(); ; x := x - tmp; ; data[i - 1+1] := data[i - 1+1] - tmp; ; answer := answer + tmp; ; tmp := Set{x, data[i+1]}->min(); ; data[i+1] := data[i+1] - tmp; ; answer := answer + tmp;) ; execute (answer)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=list(map(int,input().split())) cntA,sumA=0,0 for i in range(N): sumA+=A[i] if i % 2==0 : if sumA<=0 : cntA+=abs(sumA)+1 sumA+=abs(sumA)+1 else : if sumA>=0 : cntA+=abs(sumA)+1 sumA-=abs(sumA)+1 cntB,sumB=0,0 for i in range(N): sumB+=A[i] if i % 2!=0 : if sumB<=0 : cntB+=abs(sumB)+1 sumB+=abs(sumB)+1 else : if sumB>=0 : cntB+=abs(sumB)+1 sumB-=abs(sumB)+1 print(min(cntA,cntB)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cntA : OclAny := null; var sumA : OclAny := null; Sequence{cntA,sumA} := Sequence{0,0} ; for i : Integer.subrange(0, N-1) do ( sumA := sumA + A[i+1] ; if i mod 2 = 0 then ( if sumA <= 0 then ( cntA := cntA + (sumA)->abs() + 1 ; sumA := sumA + (sumA)->abs() + 1 ) else skip ) else ( if sumA >= 0 then ( cntA := cntA + (sumA)->abs() + 1 ; sumA := sumA - (sumA)->abs() + 1 ) else skip )) ; var cntB : OclAny := null; var sumB : OclAny := null; Sequence{cntB,sumB} := Sequence{0,0} ; for i : Integer.subrange(0, N-1) do ( sumB := sumB + A[i+1] ; if i mod 2 /= 0 then ( if sumB <= 0 then ( cntB := cntB + (sumB)->abs() + 1 ; sumB := sumB + (sumB)->abs() + 1 ) else skip ) else ( if sumB >= 0 then ( cntB := cntB + (sumB)->abs() + 1 ; sumB := sumB - (sumB)->abs() + 1 ) else skip )) ; execute (Set{cntA, cntB}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def canMakeEqual(a,n): for i in range(n): while(a[i]% 5==0): a[i]//=5 ; while(a[i]% 3==0): a[i]//=3 ; last=a[0]; for i in range(1,n): if(a[i]!=last): return False ; return True ; if __name__=="__main__" : arr=[18,30,54,90,162]; n=len(arr); if(canMakeEqual(arr,n)): print("YES"); else : print("NO"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var arr : Sequence := Sequence{18}->union(Sequence{30}->union(Sequence{54}->union(Sequence{90}->union(Sequence{ 162 })))); ; n := (arr)->size(); ; if (canMakeEqual(arr, n)) then ( execute ("YES")->display(); ) else ( execute ("NO")->display(); ) ) else skip; operation canMakeEqual(a : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( while (a[i+1] mod 5 = 0) do ( a[i+1] := a[i+1] div 5;) ; while (a[i+1] mod 3 = 0) do ( a[i+1] := a[i+1] div 3;)) ; var last : OclAny := a->first(); ; for i : Integer.subrange(1, n-1) do ( if (a[i+1] /= last) then ( return false; ) else skip) ; return true;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def sizeSubSet(a,k,n): a.sort() s=set() for i in range(n): if(a[i]% k!=0 or a[i]//k not in s): s.add(a[i]) return len(s) a=[1,2,3,4,5,6,7,8,9,10] n=len(a) k=2 print(sizeSubSet(a,k,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{ 10 }))))))))) ; n := (a)->size() ; k := 2 ; execute (sizeSubSet(a, k, n))->display(); operation sizeSubSet(a : OclAny, k : OclAny, n : OclAny) : OclAny pre: true post: true activity: a := a->sort() ; var s : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] mod k /= 0 or (s)->excludes(a[i+1] div k)) then ( execute ((a[i+1]) : s) ) else skip) ; return (s)->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): m,n=map(int,input().split()) if m*n<0 : m,n=-n,m m=abs(m); n=abs(n) l=max(abs(m),abs(n)) cnt=0 for p in range(l+1): for q in range(l+1): if p==0 : continue if(p*m+q*n)%(p**2+q**2)<1 and(p*n-q*m)%(p**2+q**2)<1 : cnt+=1 print("CP"[cnt==2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if m * n < 0 then ( var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := Sequence{-n,m} ) else skip ; var m : double := (m)->abs(); var n : double := (n)->abs() ; var l : OclAny := Set{(m)->abs(), (n)->abs()}->max() ; var cnt : int := 0 ; for p : Integer.subrange(0, l + 1-1) do ( for q : Integer.subrange(0, l + 1-1) do ( if p = 0 then ( continue ) else skip ; if (p * m + q * n) mod ((p)->pow(2) + (q)->pow(2)) < 1 & (p * n - q * m) mod ((p)->pow(2) + (q)->pow(2)) < 1 then ( cnt := cnt + 1 ) else skip)) ; execute ("CP"->select(cnt = 2))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculate(a): maximum=max(a) frequency=[0 for x in range(maximum+1)] for i in a : frequency[i]+=1 answer=0 for i in frequency : answer=answer+i*(i-1)//2 return answer a=[1,2,1,2,4] print(calculate(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 4 })))) ; execute (calculate(a))->display(); operation calculate(a : OclAny) : OclAny pre: true post: true activity: var maximum : OclAny := (a)->max() ; var frequency : Sequence := Integer.subrange(0, maximum + 1-1)->select(x | true)->collect(x | (0)) ; for i : a do ( frequency[i+1] := frequency[i+1] + 1) ; var answer : int := 0 ; for i : frequency do ( answer := answer + i * (i - 1) div 2) ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=26 def canBeMadeEqual(str1,str2): len1=len(str1) len2=len(str2) if(len1==len2): freq=[0 for i in range(MAX)] for i in range(len1): freq[ord(str1[i])-ord('a')]+=1 for i in range(len2): if(freq[ord(str2[i])-ord('a')]>0): return True return False str1="abc" str2="defa" if(canBeMadeEqual(str1,str2)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 26 ; skip ; str1 := "abc" ; str2 := "defa" ; if (canBeMadeEqual(str1, str2)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation canBeMadeEqual(str1 : OclAny, str2 : OclAny) : OclAny pre: true post: true activity: var len1 : int := (str1)->size() ; var len2 : int := (str2)->size() ; if (len1 = len2) then ( var freq : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, len1-1) do ( freq[(str1[i+1])->char2byte() - ('a')->char2byte()+1] := freq[(str1[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; for i : Integer.subrange(0, len2-1) do ( if (freq[(str2[i+1])->char2byte() - ('a')->char2byte()+1] > 0) then ( return true ) else skip) ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pendulumArrangement(arr,n): arr.sort(reverse=False) pos=n-1 if(n % 2==0): odd=n-1 else : odd=n-2 while(odd>0): temp=arr[odd] in1=odd while(in1!=pos): arr[in1]=arr[in1+1] in1+=1 arr[in1]=temp odd=odd-2 pos=pos-1 start=0 end=int((n-1)/2) while(startunion(Sequence{2}->union(Sequence{4}->union(Sequence{55}->union(Sequence{6}->union(Sequence{ 8 }))))) ; n := (arr)->size() ; pendulumArrangement(arr, n) ) else skip; operation pendulumArrangement(arr : OclAny, n : OclAny) pre: true post: true activity: arr := arr->sort() ; var pos : double := n - 1 ; if (n mod 2 = 0) then ( var odd : double := n - 1 ) else ( odd := n - 2 ) ; while (odd > 0) do ( var temp : OclAny := arr[odd+1] ; var in1 : OclAny := odd ; while (in1 /= pos) do ( arr[in1+1] := arr[in1 + 1+1] ; in1 := in1 + 1) ; arr[in1+1] := temp ; odd := odd - 2 ; pos := pos - 1) ; var start : int := 0 ; var end : int := ("" + (((n - 1) / 2)))->toInteger() ; while ((start->compareTo(end)) < 0) do ( temp := arr[start+1] ; arr[start+1] := arr[end+1] ; arr[end+1] := temp ; start := start + 1 ; end := end - 1) ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkEqualMatrix(arr,n,m,k): c=0 ; cnt1=0 ; cnt2=0 ; for i in range(n): for j in range(m): if(c % 2==0): if(arr[i][j]==k): cnt1+=1 ; else : if(arr[i][j]==k): cnt2+=1 ; c=c+1 ; if(cnt1>=1 and cnt2>=1): print("Yes"); else : print("No"); if __name__=="__main__" : arr=[[1,8,3],[1,2,2],[4,1,9]]; k=2 ; checkEqualMatrix(arr,3,3,k); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{Sequence{1}->union(Sequence{8}->union(Sequence{ 3 }))}->union(Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 2 }))}->union(Sequence{ Sequence{4}->union(Sequence{1}->union(Sequence{ 9 })) })); ; k := 2; ; checkEqualMatrix(arr, 3, 3, k); ) else skip; operation checkEqualMatrix(arr : OclAny, n : OclAny, m : OclAny, k : OclAny) pre: true post: true activity: var c : int := 0; var cnt1 : int := 0; var cnt2 : int := 0; ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if (c mod 2 = 0) then ( if (arr[i+1][j+1] = k) then ( cnt1 := cnt1 + 1; ) else skip ) else ( if (arr[i+1][j+1] = k) then ( cnt2 := cnt2 + 1; ) else skip ) ; c := c + 1;)) ; if (cnt1 >= 1 & cnt2 >= 1) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) c=int(input()) if 1 not in(a,b,c): print(a*b*c) elif a==1 and c==1 : print(a+b+c) elif b==1 and a*c!=1 : print((1+min(a,c))*max(a,c)) else : print((1+b)*max(a,c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (Sequence{a, b, c})->excludes(1) then ( execute (a * b * c)->display() ) else (if a = 1 & c = 1 then ( execute (a + b + c)->display() ) else (if b = 1 & a * c /= 1 then ( execute ((1 + Set{a, c}->min()) * Set{a, c}->max())->display() ) else ( execute ((1 + b) * Set{a, c}->max())->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) c=int(input()) k=a+b+c ko1=a*(b+c) k1=(a*b)+c ko2=(a+b)*c k2=a+(b*c) k3=a*(b*c) k4=(a*b)*c print(max(k,k1,ko1,ko2,k2,k3,k4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := a + b + c ; var ko1 : int := a * (b + c) ; var k1 : int := (a * b) + c ; var ko2 : int := (a + b) * c ; var k2 : int := a + (b * c) ; var k3 : int := a * (b * c) ; var k4 : int := (a * b) * c ; execute (Set{k, k1, ko1, ko2, k2, k3, k4}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) c=int(input()) d=a+b+c e=a*b*c f=a+b*c g=a*b+c h=(a+b)*c i=a*(b+c) print(max(d,e,f,g,h,i)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : int := a + b + c ; var e : int := a * b * c ; var f : int := a + b * c ; var g : int := a * b + c ; var h : int := (a + b) * c ; var i : int := a * (b + c) ; execute (Set{d, e, f, g, h, i}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math t=int(input()) while t>0 : m,k=map(int,input().split()) if m==1 : print(0) t-=1 continue power=k.bit_length()-1 if 2**power==m : print(power) t-=1 continue computer=2**(power+1) hours=power+1 if m>computer : m-=computer if m % k==0 : hours+=m//k else : hours+=m//k+1 print(hours) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( var m : OclAny := null; var k : OclAny := null; Sequence{m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if m = 1 then ( execute (0)->display() ; t := t - 1 ; continue ) else skip ; var power : double := k.bit_length() - 1 ; if (2)->pow(power) = m then ( execute (power)->display() ; t := t - 1 ; continue ) else skip ; var computer : double := (2)->pow((power + 1)) ; var hours : OclAny := power + 1 ; if (m->compareTo(computer)) > 0 then ( m := m - computer ; if m mod k = 0 then ( hours := hours + m div k ) else ( hours := hours + m div k + 1 ) ) else skip ; execute (hours)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(i)for i in input().split()] temp=a[0] ans1=0 if temp<=0 : ans1+=abs(temp)+1 temp=1 for i in range(1,n): if temp*(temp+a[i])<0 : temp+=a[i] else : if temp>0 : ans1+=(temp+a[i]+1) temp=-1 elif temp<0 : ans1+=abs(temp+a[i])+1 temp=1 temp=a[0] ans2=0 if temp>=0 : ans2+=abs(temp)+1 temp=-1 for i in range(1,n): if temp*(temp+a[i])<0 : temp+=a[i] else : if temp>0 : ans2+=(temp+a[i]+1) temp=-1 elif temp<0 : ans2+=abs(temp+a[i])+1 temp=1 ans=min(ans1,ans2) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var temp : OclAny := a->first() ; var ans1 : int := 0 ; if temp <= 0 then ( ans1 := ans1 + (temp)->abs() + 1 ; temp := 1 ) else skip ; for i : Integer.subrange(1, n-1) do ( if temp * (temp + a[i+1]) < 0 then ( temp := temp + a[i+1] ) else ( if temp > 0 then ( ans1 := ans1 + (temp + a[i+1] + 1) ; temp := -1 ) else (if temp < 0 then ( ans1 := ans1 + (temp + a[i+1])->abs() + 1 ; temp := 1 ) else skip) )) ; temp := a->first() ; var ans2 : int := 0 ; if temp >= 0 then ( ans2 := ans2 + (temp)->abs() + 1 ; temp := -1 ) else skip ; for i : Integer.subrange(1, n-1) do ( if temp * (temp + a[i+1]) < 0 then ( temp := temp + a[i+1] ) else ( if temp > 0 then ( ans2 := ans2 + (temp + a[i+1] + 1) ; temp := -1 ) else (if temp < 0 then ( ans2 := ans2 + (temp + a[i+1])->abs() + 1 ; temp := 1 ) else skip) )) ; var ans : OclAny := Set{ans1, ans2}->min() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) c=int(input()) t=[a+b+c,a*b+c,a+b*c,a*b*c,(a+b)*c,a*(b+c)] tsort=t.sort() print(t[5]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : Sequence := Sequence{a + b + c}->union(Sequence{a * b + c}->union(Sequence{a + b * c}->union(Sequence{a * b * c}->union(Sequence{(a + b) * c}->union(Sequence{ a * (b + c) }))))) ; var tsort : OclAny := t->sort() ; execute (t[5+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) c=int(input()) if a==1 or b==1 or c==1 : if(a==1 and b==1 and c==1): print(a+b+c) elif(a==1 and b==1)or(a==1 and c==1)or(b==1 and c==1): if(a==1 and b==1): print(2*c) elif(a==1 and c==1): print(a+b+c) else : print(2*a) else : if a>b : if a>c : print(a*(b+c)) else : print(c*(a+b)) else : if b>c : if a>c : print(a*(b+c)) else : print((a+b)*c) else : print(c*(a+b)) else : print(a*b*c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if a = 1 or b = 1 or c = 1 then ( if (a = 1 & b = 1 & c = 1) then ( execute (a + b + c)->display() ) else (if (a = 1 & b = 1) or (a = 1 & c = 1) or (b = 1 & c = 1) then ( if (a = 1 & b = 1) then ( execute (2 * c)->display() ) else (if (a = 1 & c = 1) then ( execute (a + b + c)->display() ) else ( execute (2 * a)->display() ) ) ) else ( if (a->compareTo(b)) > 0 then ( if (a->compareTo(c)) > 0 then ( execute (a * (b + c))->display() ) else ( execute (c * (a + b))->display() ) ) else ( if (b->compareTo(c)) > 0 then ( if (a->compareTo(c)) > 0 then ( execute (a * (b + c))->display() ) else ( execute ((a + b) * c)->display() ) ) else ( execute (c * (a + b))->display() ) ) ) ) ) else ( execute (a * b * c)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) print((pow(3,n,m)-1)% m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (((3)->pow(n) - 1) mod m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): m,n=map(int,input().split()) count=0 for p in range(142): for q in range(142): if p==q==0 : continue pq=p*p+q*q if pq>20000 : break if(m*p+n*q)% pq==0 and(n*p-m*q)% pq==0 : count+=1 if count<5 : print("P") else : print("C") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var count : int := 0 ; for p : Integer.subrange(0, 142-1) do ( for q : Integer.subrange(0, 142-1) do ( if p = q & (q == 0) then ( continue ) else skip ; var pq : double := p * p + q * q ; if pq > 20000 then ( break ) else skip ; if (m * p + n * q) mod pq = 0 & (n * p - m * q) mod pq = 0 then ( count := count + 1 ) else skip)) ; if count < 5 then ( execute ("P")->display() ) else ( execute ("C")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()); print((pow(3,n,m)-1)% m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); execute (((3)->pow(n) - 1) mod m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) def power(x,y,p): res=1 x=x % p while(y>0): if((y & 1)==1): res=(res*x)% p y=y>>1 x=(x*x)% p return res a=power(3,n,m) print(a-1 if a!=0 else m-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; var a : OclAny := power(3, n, m) ; execute (if a /= 0 then a - 1 else m - 1 endif)->display(); operation power(x : OclAny, y : OclAny, p : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; x := x mod p ; while (y > 0) do ( if ((MathLib.bitwiseAnd(y, 1)) = 1) then ( res := (res * x) mod p ) else skip ; y := y /(2->pow(1)) ; x := (x * x) mod p) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def get_ints(): return map(int,sys.stdin.readline().strip().split()) n,m=get_ints() ans=(pow(3,n,m)-1+m)% m print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := get_ints() ; var ans : int := ((3)->pow(n) - 1 + m) mod m ; execute (ans)->display(); operation get_ints() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) def fn(): d=3 ans=1 x=n while x : if x % 2 : ans=(ans*d)% m d=(d*d)% m x=x//2 return ans pr=fn() y=(pr % m-1+m)% m print(y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; var pr : OclAny := fn() ; var y : int := (pr mod m - 1 + m) mod m ; execute (y)->display(); operation fn() : OclAny pre: true post: true activity: var d : int := 3 ; var ans : int := 1 ; var x : OclAny := n ; while x do ( if x mod 2 then ( ans := (ans * d) mod m ) else skip ; d := (d * d) mod m ; x := x div 2) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import argparse import collections import fractions import functools import itertools import math import operator from sys import exit,stdin from multiprocessing import Pool def solve_star(args): return solve(*args) def read_int(): return int(stdin.readline().strip()) def read_ints(): return[int(n)for n in stdin.readline().strip().split()] def read_words(): return stdin.readline().strip() def parse(): name,n=read_words().split() return[name,int(n)] def solve(name,n): vowels=["a","e","i","o","u"] count=0 last=0 total=0 for e,c in enumerate(name): if c in vowels : count=0 else : count+=1 if count==n : this_string_starts=e-(n-1) total+=(this_string_starts-last+1)*(len(name)-e) last=this_string_starts+1 count-=1 return total if __name__=="__main__" : parser=argparse.ArgumentParser() parser.add_argument("-m","--multi",help="turn on multiprocessing",action="store_true") args=parser.parse_args() with open("out.txt","w")as f : if args.multi : pool=Pool() iter=pool.imap(solve_star,(parse()for i in range(read_int()))) for i,result in enumerate(iter): s="Case #{}:{}".format(i+1,result) print(s) f.write(s+"\n") else : for i in range(read_int()): s="Case #{}:{}".format(i+1,solve(*parse())) print(s) f.write(s+"\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( var parser : OclAny := argparse.ArgumentParser() ; parser.add_argument("-m", "--multi", (argument (test (logical_test (comparison (expr (atom (name help)))))) = (test (logical_test (comparison (expr (atom "turn on multiprocessing")))))), (argument (test (logical_test (comparison (expr (atom (name action)))))) = (test (logical_test (comparison (expr (atom "store_true"))))))) ; args := parser.parse_args() ; try (var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("out.txt")); if args.multi then ( var pool : OclAny := Pool() ; var iter : OclAny := pool.imap(solve_star, Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name parse)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name read_int)) (trailer (arguments ( ))))))))) ))))))))}) ; for _tuple : Integer.subrange(1, (iter)->size())->collect( _indx | Sequence{_indx-1, (iter)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var result : OclAny := _tuple->at(_indx); var s : String := StringLib.interpolateStrings("Case #{}:{}", Sequence{i + 1, result}) ; execute (s)->display() ; f.write(s + "\n")) ) else ( for i : Integer.subrange(0, read_int()-1) do ( s := StringLib.interpolateStrings("Case #{}:{}", Sequence{i + 1, solve((argument * (test (logical_test (comparison (expr (atom (name parse)) (trailer (arguments ( )))))))))}) ; execute (s)->display() ; f.write(s + "\n")) )) catch (_e : OclException) do skip ) else skip; operation solve_star(args : OclAny) : OclAny pre: true post: true activity: return solve((argument * (test (logical_test (comparison (expr (atom (name args)))))))); operation read_int() : OclAny pre: true post: true activity: return ("" + ((stdin.readLine()->trim())))->toInteger(); operation read_ints() : OclAny pre: true post: true activity: return stdin.readLine()->trim().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())); operation read_words() : OclAny pre: true post: true activity: return stdin.readLine()->trim(); operation parse() : OclAny pre: true post: true activity: var name : OclAny := null; var n : OclAny := null; Sequence{name,n} := read_words().split() ; return Sequence{name}->union(Sequence{ ("" + ((n)))->toInteger() }); operation solve(name : OclAny, n : OclAny) : OclAny pre: true post: true activity: var vowels : Sequence := Sequence{"a"}->union(Sequence{"e"}->union(Sequence{"i"}->union(Sequence{"o"}->union(Sequence{ "u" })))) ; var count : int := 0 ; var last : int := 0 ; var total : int := 0 ; for _tuple : Integer.subrange(1, (name)->size())->collect( _indx | Sequence{_indx-1, (name)->at(_indx)} ) do (var _indx : int := 1; var e : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if (vowels)->includes(c) then ( count := 0 ) else ( count := count + 1 ; if count = n then ( var this_string_starts : double := e - (n - 1) ; total := total + (this_string_starts - last + 1) * ((name)->size() - e) ; last := this_string_starts + 1 ; count := count - 1 ) else skip )) ; return total; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,os,sys,random vowels='aeiou' consonants='bcdfghjklmnpqrstvwxyz' vowels_set=frozenset(vowels) consonants_set=frozenset(consonants) def single_test(IN,OUT): name,n=IN.readline().split() n=int(n) L=len(name) data='' for l in name : data+='v' if l in vowels_set else 'c' starts=[] count=0 for i,l in enumerate(data): if l=='v' : count=0 else : count+=1 if count>=n : starts.append(i+1-n) freespaces=[] cs=0 for i in range(L): while cs!=-1 and csstarts[cs]: cs+=1 if cs==len(starts): cs=-1 if cs==-1 : if ii : freespaces.append((i,starts[cs]+n-1-i)) result=(L*(L+1))//2 for f in freespaces : result-=f[1] return result def main(IN,OUT): T=int(IN.readline()) for i in range(1,T+1): OUT.write('Case #%d: %d\n' %(i,single_test(IN,OUT))) if __name__=='__main__' : assert len(sys.argv)==2 IN=open(sys.argv[1],'rt') OUT=open('%s.out' % sys.argv[1][:-3],'wt') main(IN,OUT) OUT.close() IN.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var vowels : String := 'aeiou' ; var consonants : String := 'bcdfghjklmnpqrstvwxyz' ; var vowels_set : Set := Set{} ; var consonants_set : Set := Set{} ; skip ; skip ; if __name__ = '__main__' then ( assert ((trailer . (name argv)))->size() = 2 do "assertion failed" ; IN := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) ; OUT := OclFile.newOclFile_Write(OclFile.newOclFile(StringLib.format('%s.out',((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))).subrange(1,-3)))) ; main(IN, OUT) ; OUT.closeFile() ; IN.closeFile() ) else skip; operation single_test(IN : OclAny, OUT : OclAny) : OclAny pre: true post: true activity: var name : OclAny := null; var n : OclAny := null; Sequence{name,n} := IN.readLine().split() ; var n : int := ("" + ((n)))->toInteger() ; var L : int := (name)->size() ; var data : String := '' ; for l : name do ( data := data + if (vowels_set)->includes(l) then 'v' else 'c' endif) ; var starts : Sequence := Sequence{} ; var count : int := 0 ; for _tuple : Integer.subrange(1, (data)->size())->collect( _indx | Sequence{_indx-1, (data)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var l : OclAny := _tuple->at(_indx); if l = 'v' then ( count := 0 ) else ( count := count + 1 ; if (count->compareTo(n)) >= 0 then ( execute ((i + 1 - n) : starts) ) else skip )) ; var freespaces : Sequence := Sequence{} ; var cs : int := 0 ; for i : Integer.subrange(0, L-1) do ( while cs /= -1 & (cs->compareTo((starts)->size())) < 0 & (i->compareTo(starts[cs+1])) > 0 do ( cs := cs + 1) ; if cs = (starts)->size() then ( cs := -1 ) else skip ; if cs = -1 then ( if (i->compareTo(L)) < 0 then ( execute ((Sequence{i, L - i}) : freespaces) ) else skip ) else ( if (starts[cs+1] + n - 1->compareTo(i)) > 0 then ( execute ((Sequence{i, starts[cs+1] + n - 1 - i}) : freespaces) ) else skip )) ; var result : int := (L * (L + 1)) div 2 ; for f : freespaces do ( result := result - f[1+1]) ; return result; operation main(IN : OclAny, OUT : OclAny) pre: true post: true activity: var T : int := ("" + ((IN.readLine())))->toInteger() ; for i : Integer.subrange(1, T + 1-1) do ( OUT.write(StringLib.format('Case #%d: %d ',Sequence{i, single_test(IN, OUT)}))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def seq_modifier(lst : list,flg : bool)->int : cur,cnt=0,0 for i in lst : cur+=i if flg and cur<=0 : cnt+=abs(cur)+1 cur=1 elif not flg and cur>=0 : cnt+=abs(cur)+1 cur=-1 flg=not flg return cnt def main(): n=int(input()) lst=list(map(int,input().rstrip().split())) print(min(seq_modifier(lst,True),seq_modifier(lst,False))) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation seq_modifier(lst : Sequence(OclAny), flg : boolean) : int pre: true post: true activity: var cur : OclAny := null; var cnt : OclAny := null; Sequence{cur,cnt} := Sequence{0,0} ; for i : lst do ( cur := cur + i ; if flg & cur <= 0 then ( cnt := cnt + (cur)->abs() + 1 ; var cur : int := 1 ) else (if not(flg) & cur >= 0 then ( cnt := cnt + (cur)->abs() + 1 ; cur := -1 ) else skip) ; var flg : boolean := not(flg)) ; return cnt; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := ((input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (Set{seq_modifier(lst, true), seq_modifier(lst, false)}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def puts(s): print(s,end='') vowels="aeiou" def solve(case): S,n=input().split() n=int(n) streak=0 cons=[] for c in S : if c in vowels : streak=0 else : streak+=1 cons+=[streak] count=0 m=0 for i in range(len(S)): if cons[i]>=n : m=i+2-n count+=m print(count) for case in range(1,1+int(input())): puts("Case #"+str(case)+": ") solve(case) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var vowels : String := "aeiou" ; skip ; for case : Integer.subrange(1, 1 + ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( puts("Case #" + ("" + ((case))) + ": ") ; solve(case)); operation puts(s : OclAny) pre: true post: true activity: execute (s)->display(); operation solve(case : OclAny) pre: true post: true activity: var S : OclAny := null; var n : OclAny := null; Sequence{S,n} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var streak : int := 0 ; var cons : Sequence := Sequence{} ; for c : S do ( if (vowels)->characters()->includes(c) then ( streak := 0 ) else ( streak := streak + 1 ) ; cons := cons + Sequence{ streak }) ; var count : int := 0 ; var m : int := 0 ; for i : Integer.subrange(0, (S)->size()-1) do ( if (cons[i+1]->compareTo(n)) >= 0 then ( m := i + 2 - n ) else skip ; count := count + m) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- vowels=['a','e','i','o','u'] T=int(input()) for TT in range(1,T+1): s,n=input().split() n=int(n) ans=0 current=0 count=0 length=len(s) for i in range(0,length): if s[i]in vowels : count=0 else : count+=1 if count==n : count-=1 ans+=(i-n+2-current)*(length-i) current=i-n+2 print("Case #"+str(TT)+": "+str(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var vowels : Sequence := Sequence{'a'}->union(Sequence{'e'}->union(Sequence{'i'}->union(Sequence{'o'}->union(Sequence{ 'u' })))) ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for TT : Integer.subrange(1, T + 1-1) do ( var s : OclAny := null; var n : OclAny := null; Sequence{s,n} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var ans : int := 0 ; var current : int := 0 ; var count : int := 0 ; var length : int := (s)->size() ; for i : Integer.subrange(0, length-1) do ( if (vowels)->includes(s[i+1]) then ( count := 0 ) else ( count := count + 1 ) ; if count = n then ( count := count - 1 ; ans := ans + (i - n + 2 - current) * (length - i) ; current := i - n + 2 ) else skip) ; execute ("Case #" + ("" + ((TT))) + ": " + ("" + ((ans))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(raw_input()) def vowel(c): return c in 'aeiou' for kei in xrange(t): name,n=raw_input().split() n=int(n) i=0 j=0 ctr=0 cons=0 start=[] m=-1 while i=n : start.append(i) m=max(m,i) i+=1 i=j else : i+=1 j=i ctr=0 j=0 for i in xrange(len(name)): while j=len(start): break ctr+=len(name)-(start[j]+n-1) print('Case #%d: %d' %(kei+1,ctr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + ((raw_input())))->toInteger() ; skip ; for kei : xrange(t) do ( var name : OclAny := null; var n : OclAny := null; Sequence{name,n} := raw_input().split() ; var n : int := ("" + ((n)))->toInteger() ; var i : int := 0 ; var j : int := 0 ; var ctr : int := 0 ; var cons : int := 0 ; var start : Sequence := Sequence{} ; var m : int := -1 ; while (i->compareTo((name)->size())) < 0 do ( if not(vowel(name[i+1])) then ( while (j->compareTo((name)->size())) < 0 & not(vowel(name[j+1])) do ( j := j + 1) ; while (j - i->compareTo(n)) >= 0 do ( execute ((i) : start) ; m := Set{m, i}->max() ; i := i + 1) ; i := j ) else ( i := i + 1 ; j := i )) ; ctr := 0 ; j := 0 ; for i : xrange((name)->size()) do ( while (j->compareTo((start)->size())) < 0 & (start[j+1]->compareTo(i)) < 0 do ( j := j + 1) ; if (j->compareTo((start)->size())) >= 0 then ( break ) else skip ; ctr := ctr + (name)->size() - (start[j+1] + n - 1)) ; execute (StringLib.format('Case #%d: %d',Sequence{kei + 1, ctr}))->display()); operation vowel(c : OclAny) : OclAny pre: true post: true activity: return ('aeiou')->characters()->includes(c); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input().split()+['1'] zeroes_before=[] zeroes=0 ones=0 for c in s : if c=='0' : zeroes+=1 elif c=='1' : zeroes_before.append(zeroes) ones+=1 res=0 for z in range(ones): res=max(res,zeroes_before[z]+(ones-1-z)) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := input().split()->union(Sequence{ '1' }) ; var zeroes_before : Sequence := Sequence{} ; var zeroes : int := 0 ; var ones : int := 0 ; for c : s do ( if c = '0' then ( zeroes := zeroes + 1 ) else (if c = '1' then ( execute ((zeroes) : zeroes_before) ; ones := ones + 1 ) else skip)) ; var res : int := 0 ; for z : Integer.subrange(0, ones-1) do ( res := Set{res, zeroes_before[z+1] + (ones - 1 - z)}->max()) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): m,n=map(int,input().split()) count=0 for p in range(142): for q in range(142): if(p>0 or q>0)and((m*q+n*p)%(p*p+q*q)==0)and((n*q-m*p)%(p*p+q*q)==0): count+=1 if count<5 : print('P') else : print('C') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var count : int := 0 ; for p : Integer.subrange(0, 142-1) do ( for q : Integer.subrange(0, 142-1) do ( if (p > 0 or q > 0) & ((m * q + n * p) mod (p * p + q * q) = 0) & ((n * q - m * p) mod (p * p + q * q) = 0) then ( count := count + 1 ) else skip)) ; if count < 5 then ( execute ('P')->display() ) else ( execute ('C')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=int(input()) l=list(map(int,input().split())) a=l.count(0); b=l.count(1) ans=max(a,b) c=i for x in l : if x==1 : c-=1 b-=1 else : a-=1 ans=max(ans,c-a) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : int := l->count(0); var b : int := l->count(1) ; var ans : OclAny := Set{a, b}->max() ; var c : int := i ; for x : l do ( if x = 1 then ( c := c - 1 ; b := b - 1 ) else ( a := a - 1 ) ; ans := Set{ans, c - a}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from bisect import bisect_left as lb from bisect import bisect_right as rb from collections import deque from queue import PriorityQueue as pq from math import gcd input_=lambda : sys.stdin.readline().strip("\n") ii=lambda : int(input_()) il=lambda : list(map(int,input_().split())) ilf=lambda : list(map(float,input_().split())) lii=lambda : list(map(int,list(ip()))) ip=lambda : input_() fi=lambda : float(input_()) ap=lambda ab,bc,cd : ab[bc].append(cd) li=lambda : list(input_()) pr=lambda x : print(x) prinT=lambda x : print(x) f=lambda : sys.stdout.flush() inv=lambda x : pow(x,mod-2,mod) dx=[0,0,1,-1] dy=[1,-1,0,0] mod=10**9+7 mod1=998244353 for _ in range(1): n=ii() a=il() t=0 for i in range(n+1): t=max(t,a[: i].count(0)+a[i :].count(1)) print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var input_ : Function := lambda $$ : OclAny in (sys.stdin.readLine()->trim()) ; var ii : Function := lambda $$ : OclAny in (("" + ((input_->apply())))->toInteger()) ; var il : Function := lambda $$ : OclAny in (((input_->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ilf : Function := lambda $$ : OclAny in (((input_->apply().split())->collect( _x | (OclType["double"])->apply(_x) ))) ; var lii : Function := lambda $$ : OclAny in ((((ip()))->collect( _x | (OclType["int"])->apply(_x) ))) ; var ip : Function := lambda $$ : OclAny in (input_->apply()) ; var fi : Function := lambda $$ : OclAny in (("" + ((input_->apply())))->toReal()) ; var ap : Function := lambda ab : OclAny, bc : OclAny, cd : OclAny in (ab[bc+1].append(cd)) ; var li : Function := lambda $$ : OclAny in ((input_->apply())) ; var pr : Function := lambda x : OclAny in ((x)->display()) ; var prinT : Function := lambda x : OclAny in ((x)->display()) ; var f : Function := lambda $$ : OclAny in ((OclFile["System.out"]).flush()) ; var inv : Function := lambda x : OclAny in ((x)->pow(mod - 2)) ; var dx : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ -1 }))) ; var dy : Sequence := Sequence{1}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{ 0 }))) ; var mod : double := (10)->pow(9) + 7 ; var mod1 : int := 998244353 ; for _anon : Integer.subrange(0, 1-1) do ( var n : OclAny := ii->apply() ; var a : OclAny := il->apply() ; var t : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( t := Set{t, a.subrange(1,i)->count(0) + a.subrange(i+1)->count(1)}->max()) ; execute (t)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxProfit(profitA,profitB,n): preSum=[0]*n ; preSum[0]=profitA[0]; for i in range(1,n): preSum[i]=preSum[i-1]+profitA[i]; suffSum=[0]*n ; suffSum[n-1]=profitB[n-1]; for i in range(n-2,-1,-1): suffSum[i]=suffSum[i+1]+profitB[i]; res=preSum[n-1]; for i in range(1,n-1): res=max(res,preSum[i]+suffSum[i+1]); res=max(res,suffSum[0]); return res ; if __name__=="__main__" : profitA=[2,3,2]; profitB=[10,30,40]; n=len(profitA); print(maxProfit(profitA,profitB,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( profitA := Sequence{2}->union(Sequence{3}->union(Sequence{ 2 })); ; profitB := Sequence{10}->union(Sequence{30}->union(Sequence{ 40 })); ; n := (profitA)->size(); ; execute (maxProfit(profitA, profitB, n))->display(); ) else skip; operation maxProfit(profitA : OclAny, profitB : OclAny, n : OclAny) pre: true post: true activity: var preSum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; preSum->first() := profitA->first(); ; for i : Integer.subrange(1, n-1) do ( preSum[i+1] := preSum[i - 1+1] + profitA[i+1];) ; var suffSum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; suffSum[n - 1+1] := profitB[n - 1+1]; ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( suffSum[i+1] := suffSum[i + 1+1] + profitB[i+1];) ; var res : OclAny := preSum[n - 1+1]; ; for i : Integer.subrange(1, n - 1-1) do ( res := Set{res, preSum[i+1] + suffSum[i + 1+1]}->max();) ; res := Set{res, suffSum->first()}->max(); ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def generateNumbers(factor,n,k): next=[0]*k ; output=0 ; i=0 ; while(iunion(Sequence{5}->union(Sequence{ 7 })); ; n := 10; ; k := (factor)->size(); ; generateNumbers(factor, n, k);; operation generateNumbers(factor : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var next : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, k); ; var output : int := 0; ; var i : int := 0; ; while ((i->compareTo(n)) < 0) do ( var toincrement : int := 0; ; for j : Integer.subrange(0, k-1) do ( if (([j+1].next()->compareTo([toincrement+1].next())) < 0) then ( toincrement := j; ) else skip) ; if (output /= [toincrement+1].next()) then ( output := [toincrement+1].next(); ; execute ([toincrement+1].next())->display(); ; i := i + 1; ) else skip ; [toincrement+1].next() := [toincrement+1].next() + factor[toincrement+1];); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() if S.count("R")==3 : print(3) elif S.count("R")==2 : if S[1]=="S" : print("1") else : print("2") elif S.count("R")==1 : print("1") else : print("0") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; if S->count("R") = 3 then ( execute (3)->display() ) else (if S->count("R") = 2 then ( if S[1+1] = "S" then ( execute ("1")->display() ) else ( execute ("2")->display() ) ) else (if S->count("R") = 1 then ( execute ("1")->display() ) else ( execute ("0")->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def main(): n=int(input()) a_list=list(map(int,input().split())) a_sum=0 sign="plus" ans1=0 for i in range(0,n): if sign=="plus" : sign="minus" if a_sum+a_list[i]==0 : ans1+=1 a_sum=-1 elif a_sum+a_list[i]>0 : ans1+=a_sum+1+a_list[i] a_sum=-1 else : a_sum+=a_list[i] elif sign=="minus" : sign="plus" if a_sum+a_list[i]==0 : ans1+=1 a_sum=1 elif a_sum+a_list[i]<0 : ans1+=-1*a_sum+1+-1*a_list[i] a_sum=1 else : a_sum+=a_list[i] a_sum=0 sign="minus" ans2=0 for i in range(0,n): if sign=="plus" : sign="minus" if a_sum+a_list[i]==0 : ans2+=1 a_sum=-1 elif a_sum+a_list[i]>0 : ans2+=a_sum+1+a_list[i] a_sum=-1 else : a_sum+=a_list[i] elif sign=="minus" : sign="plus" if a_sum+a_list[i]==0 : ans2+=1 a_sum=1 elif a_sum+a_list[i]<0 : ans2+=-1*a_sum+1+-1*a_list[i] a_sum=1 else : a_sum+=a_list[i] print(min(ans1,ans2)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a_sum : int := 0 ; var sign : String := "plus" ; var ans1 : int := 0 ; for i : Integer.subrange(0, n-1) do ( if sign = "plus" then ( sign := "minus" ; if a_sum + a_list[i+1] = 0 then ( ans1 := ans1 + 1 ; a_sum := -1 ) else (if a_sum + a_list[i+1] > 0 then ( ans1 := ans1 + a_sum + 1 + a_list[i+1] ; a_sum := -1 ) else ( a_sum := a_sum + a_list[i+1] ) ) ) else (if sign = "minus" then ( sign := "plus" ; if a_sum + a_list[i+1] = 0 then ( ans1 := ans1 + 1 ; a_sum := 1 ) else (if a_sum + a_list[i+1] < 0 then ( ans1 := ans1 + -1 * a_sum + 1 + -1 * a_list[i+1] ; a_sum := 1 ) else ( a_sum := a_sum + a_list[i+1] ) ) ) else skip)) ; a_sum := 0 ; sign := "minus" ; var ans2 : int := 0 ; for i : Integer.subrange(0, n-1) do ( if sign = "plus" then ( sign := "minus" ; if a_sum + a_list[i+1] = 0 then ( ans2 := ans2 + 1 ; a_sum := -1 ) else (if a_sum + a_list[i+1] > 0 then ( ans2 := ans2 + a_sum + 1 + a_list[i+1] ; a_sum := -1 ) else ( a_sum := a_sum + a_list[i+1] ) ) ) else (if sign = "minus" then ( sign := "plus" ; if a_sum + a_list[i+1] = 0 then ( ans2 := ans2 + 1 ; a_sum := 1 ) else (if a_sum + a_list[i+1] < 0 then ( ans2 := ans2 + -1 * a_sum + 1 + -1 * a_list[i+1] ; a_sum := 1 ) else ( a_sum := a_sum + a_list[i+1] ) ) ) else skip)) ; execute (Set{ans1, ans2}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() for i in range(3,-1,-1): if 'R'*i in s : print(i) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(-1 + 1, 3)->reverse() do ( if (s)->characters()->includes(StringLib.nCopies('R', i)) then ( execute (i)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(S): if S[0]=='R' : if S[1]=='R' : if S[2]=='R' : return 3 else : return 2 else : return 1 else : if S[1]=='R' : if S[2]=='R' : return 2 else : return 1 else : if S[2]=='R' : return 1 else : return 0 S=input() print(main(S)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; S := (OclFile["System.in"]).readLine() ; execute (main(S))->display(); operation main(S : OclAny) : OclAny pre: true post: true activity: if S->first() = 'R' then ( if S[1+1] = 'R' then ( if S[2+1] = 'R' then ( return 3 ) else ( return 2 ) ) else ( return 1 ) ) else ( if S[1+1] = 'R' then ( if S[2+1] = 'R' then ( return 2 ) else ( return 1 ) ) else ( if S[2+1] = 'R' then ( return 1 ) else ( return 0 ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(string): return str(max(map(len,string.split("S")))) if __name__=='__main__' : import sys print(solve(sys.stdin.read().strip())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( skip ; execute (solve(sys.stdin.readAll()->trim()))->display() ) else skip; operation solve(string : OclAny) : OclAny pre: true post: true activity: return ("" + ((((string.split("S"))->collect( _x | (len)->apply(_x) ))->max()))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=lambda x : x.count("R")if x.count("R")in{0,1,3}else 1 if x=="RSR" else 2 print(a(input())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Function := lambda x : OclAny in (if (Set{0}->union(Set{1}->union(Set{ 3 })))->includes(x->count("R")) then x->count("R") else if x = "RSR" then 1 else 2 endif endif) ; execute (a->apply((OclFile["System.in"]).readLine()))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as m def isPentagonal(n): n=(1+m.sqrt(24*N+1))/6 return((n-int(n))==0) N=19 if(isPentagonal(N)): print(N," is pentagonal ") else : print(N," is not pentagonal") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := 19 ; if (isPentagonal(N)) then ( execute (N)->display() ) else ( execute (N)->display() ); operation isPentagonal(n : OclAny) : OclAny pre: true post: true activity: n := (1 + m.sqrt(24 * N + 1)) / 6 ; return ((n - ("" + ((n)))->toInteger()) = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sum(n): sum=0 ; while(n): sum=sum+n % 10 ; n=n//10 ; return sum ; def firstN(n): num=19 ; cnt=1 ; while(cnt!=n): if(sum(num)==10): print(num,end=" "); cnt+=1 ; num+=9 ; if __name__=="__main__" : n=10 ; firstN(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 10; ; firstN(n); ) else skip; operation sum(n : OclAny) pre: true post: true activity: var sum : int := 0; ; while (n) do ( sum := sum + n mod 10; ; n := n div 10;) ; return sum;; operation firstN(n : OclAny) pre: true post: true activity: var num : int := 19; var cnt : int := 1; ; while (cnt /= n) do ( if ((num)->sum() = 10) then ( execute (num)->display(); ; cnt := cnt + 1; ) else skip ; num := num + 9;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=1 mod=int(1e9+7) for i in range(1,n+1): ans*=i ans %=mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 1 ; var mod : int := ("" + ((("1e9")->toReal() + 7)))->toInteger() ; for i : Integer.subrange(1, n + 1-1) do ( ans := ans * i ; ans := ans mod mod) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=1000000007 import math N=int(input()) print(math.factorial(N)% MOD) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : int := 1000000007 ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (MathLib.factorial(N) mod MOD)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math N=int(input()) power=1 mod=10**9 mod+=7 power=math.factorial(N) print(power % mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var power : int := 1 ; var mod : double := (10)->pow(9) ; mod := mod + 7 ; power := MathLib.factorial(N) ; execute (power mod mod)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) devide=10**9+7 power=1 for i in range(1,N+1): power=power*i % devide print(power) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var devide : double := (10)->pow(9) + 7 ; var power : int := 1 ; for i : Integer.subrange(1, N + 1-1) do ( power := power * i mod devide) ; execute (power)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(x)for x in input().split()] key=0 ans=0 for i in range(n): sub=key+a[i] if i==0 and sub==0 : ans+=1 sub=1 if i!=0 and sub*key>=0 : if key>0 : ans+=sub+1 sub=-1 else : ans+=1-sub sub=1 key=sub ans2=0 key2=0 for i in range(n): sub=key2+a[i] if i==0 : if sub==0 : ans2+=1 sub=-1 elif sub>0 : ans2+=sub+1 sub=-1 else : ans2+=1-sub sub=1 if i!=0 and sub*key2>=0 : if key2>0 : ans2+=sub+1 sub=-1 else : ans2+=1-sub sub=1 key2=sub print(min([ans,ans2])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var key : int := 0 ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var sub : int := key + a[i+1] ; if i = 0 & sub = 0 then ( ans := ans + 1 ; sub := 1 ) else skip ; if i /= 0 & sub * key >= 0 then ( if key > 0 then ( ans := ans + sub + 1 ; sub := -1 ) else ( ans := ans + 1 - sub ; sub := 1 ) ) else skip ; key := sub) ; var ans2 : int := 0 ; var key2 : int := 0 ; for i : Integer.subrange(0, n-1) do ( sub := key2 + a[i+1] ; if i = 0 then ( if sub = 0 then ( ans2 := ans2 + 1 ; sub := -1 ) else (if sub > 0 then ( ans2 := ans2 + sub + 1 ; sub := -1 ) else ( ans2 := ans2 + 1 - sub ; sub := 1 ) ) ) else skip ; if i /= 0 & sub * key2 >= 0 then ( if key2 > 0 then ( ans2 := ans2 + sub + 1 ; sub := -1 ) else ( ans2 := ans2 + 1 - sub ; sub := 1 ) ) else skip ; key2 := sub) ; execute ((Sequence{ans}->union(Sequence{ ans2 }))->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a=int(input()) print(math.factorial(a)%(10**9+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (MathLib.factorial(a) mod ((10)->pow(9) + 7))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fibWord(n): Sn_1="0" Sn="01" tmp="" for i in range(2,n+1): tmp=Sn Sn+=Sn_1 Sn_1=tmp return Sn n=6 print(fibWord(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 6 ; execute (fibWord(n))->display(); operation fibWord(n : OclAny) : OclAny pre: true post: true activity: var Sn skip : String := "0" ; var Sn : String := "01" ; var tmp : String := "" ; for i : Integer.subrange(2, n + 1-1) do ( tmp := Sn ; Sn := Sn + Sn tmp := Sn ; Sn tmp := Sn := tmp) ; return Sn; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def xor_pair_sum(ar,n): total=0 for i in range(n): for j in range(n): total=total ^(ar[i]+ar[j]) return total if __name__=="__main__" : data=[1,2,3] print(xor_pair_sum(data,len(data))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var data : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; execute (xor_pair_sum(data, (data)->size()))->display() ) else skip; operation xor_pair_sum(ar : OclAny, n : OclAny) : OclAny pre: true post: true activity: var total : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( total := MathLib.bitwiseXor(total, (ar[i+1] + ar[j+1])))) ; return total; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=1000000007 def power(x,y,p): res=1 x=x % p while(y>0): if(y & 1): res=(res*x)% p y=y>>1 x=(x*x)% p return res def findCount(N): count=power(2,N,mod) return count if __name__=='__main__' : N=25 print(findCount(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : int := 1000000007 ; skip ; skip ; if __name__ = '__main__' then ( N := 25 ; execute (findCount(N))->display() ) else skip; operation power(x : OclAny, y : OclAny, p : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; x := x mod p ; while (y > 0) do ( if (MathLib.bitwiseAnd(y, 1)) then ( res := (res * x) mod p ) else skip ; y := y /(2->pow(1)) ; x := (x * x) mod p) ; return res; operation findCount(N : OclAny) : OclAny pre: true post: true activity: var count : OclAny := power(2, N, mod) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,a,b=[int(i)for i in input().split()] p=[i for i in range(1,n+1)] if a+b+2>n or abs(a-b)>1 : print(-1) continue if b>a : p=[n-i+1 for i in p] for i in range(1,min(a,b)*2+1,2): p[i],p[i+1]=p[i+1],p[i] if a!=b : p[-2],p[-1]=p[-1],p[-2] print(' '.join([str(i)for i in p])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var p : Sequence := Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | (i)) ; if (a + b + 2->compareTo(n)) > 0 or (a - b)->abs() > 1 then ( execute (-1)->display() ; continue ) else skip ; if (b->compareTo(a)) > 0 then ( p := p->select(i | true)->collect(i | (n - i + 1)) ) else skip ; for i : Integer.subrange(1, Set{a, b}->min() * 2 + 1-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( var p[i+1] : OclAny := null; var p[i + 1+1] : OclAny := null; Sequence{p[i+1],p[i + 1+1]} := Sequence{p[i + 1+1],p[i+1]}) ; if a /= b then ( var p->front()->last() : OclAny := null; var p->last() : OclAny := null; Sequence{p->front()->last(),p->last()} := Sequence{p->last(),p->front()->last()} ) else skip ; execute (StringLib.sumStringsWithSeparator((p->select(i | true)->collect(i | (("" + ((i)))))), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,a,b=map(int,input().split()) arr=[x for x in range(1,n+1)] if(a+b)>(n-2)or abs(a-b)>1 : print(-1) elif a==b : ar=[] m=a+b+2 for i in range(n,m,-1): ar.append(i) for i in range(2,m+1,2): ar.append(i) ar.append(i-1) print(*ar) elif a==b-1 : for i in range(0,2*b,2): arr[i],arr[i+1]=arr[i+1],arr[i] print(*arr) elif a==b+1 : for i in range(n-1,n-2*a,-2): arr[i],arr[i-1]=arr[i-1],arr[i] print(*arr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := Integer.subrange(1, n + 1-1)->select(x | true)->collect(x | (x)) ; if ((a + b)->compareTo((n - 2))) > 0 or (a - b)->abs() > 1 then ( execute (-1)->display() ) else (if a = b then ( var ar : Sequence := Sequence{} ; var m : OclAny := a + b + 2 ; for i : Integer.subrange(m + 1, n)->reverse() do ( execute ((i) : ar)) ; for i : Integer.subrange(2, m + 1-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( execute ((i) : ar) ; execute ((i - 1) : ar)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ar))))))))->display() ) else (if a = b - 1 then ( for i : Integer.subrange(0, 2 * b-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( var arr[i+1] : OclAny := null; var arr[i + 1+1] : OclAny := null; Sequence{arr[i+1],arr[i + 1+1]} := Sequence{arr[i + 1+1],arr[i+1]}) ; execute ((argument * (test (logical_test (comparison (expr (atom (name arr))))))))->display() ) else (if a = b + 1 then ( for i : Integer.subrange(n - 1, n - 2 * a-1)->select( $x | ($x - n - 1) mod -2 = 0 ) do ( var arr[i+1] : OclAny := null; var arr[i - 1+1] : OclAny := null; Sequence{arr[i+1],arr[i - 1+1]} := Sequence{arr[i - 1+1],arr[i+1]}) ; execute ((argument * (test (logical_test (comparison (expr (atom (name arr))))))))->display() ) else skip ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: n,m,k=map(int,s.split()); c=n*n-n>>1 ; print('NYOE S'[(n-212>m % c): : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ); var c : int := n * n - n /(2->pow(1)); execute ('NYOE S'(subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 2)))))) < (comparison (expr (atom (name m))))) <= (comparison (expr (atom (name c)))))))) ))) & (expr (atom ( (testlist_comp (test (logical_test (logical_test (logical_test (comparison (comparison (comparison (expr (atom (name m)))) > (comparison (expr (atom (number (integer 1)))))) < (comparison (expr (expr (atom (name k))) - (expr (atom (number (integer 2)))))))) or (logical_test (comparison (comparison (comparison (expr (atom (name n)))) < (comparison (expr (atom (number (integer 2)))))) < (comparison (expr (expr (atom (name k))) + (expr (atom (number (integer 1))))))))) or (logical_test (comparison (comparison (comparison (expr (atom (name k)))) > (comparison (expr (atom (number (integer 2)))))) > (comparison (expr (expr (atom (name m))) % (expr (atom (name c)))))))))) ))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printPattern(n): for i in range(1,n+1): for j in range(i,n): print("\t",end="") t=i for k in range(1,i+1): print(t,"\t","\t",end="") t=t+n-k print() n=6 printPattern(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 6 ; printPattern(n); operation printPattern(n : OclAny) pre: true post: true activity: for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(i, n-1) do ( execute ("\t")->display()) ; var t : OclAny := i ; for k : Integer.subrange(1, i + 1-1) do ( execute (t)->display() ; t := t + n - k) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,a,b=map(int,input().split()) if abs(b-a)>1 or a+b>n-2 : print(-1) else : k=0 ans=list(range(1,n+1)) if a>b : ans=ans[: :-1] elif a==b : k=1 for _ in range(max(a,b)): ans[k+1],ans[k]=ans[k],ans[k+1] k=k+2 for j in ans : print(j,end=' ') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (b - a)->abs() > 1 or (a + b->compareTo(n - 2)) > 0 then ( execute (-1)->display() ) else ( var k : int := 0 ; var ans : Sequence := (Integer.subrange(1, n + 1-1)) ; if (a->compareTo(b)) > 0 then ( ans := ans(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ) else (if a = b then ( k := 1 ) else skip) ; for _anon : Integer.subrange(0, Set{a, b}->max()-1) do ( var ans[k + 1+1] : OclAny := null; var ans[k+1] : OclAny := null; Sequence{ans[k + 1+1],ans[k+1]} := Sequence{ans[k+1],ans[k + 1+1]} ; k := k + 2) ; for j : ans do ( execute (j)->display()) ; execute (->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil def perm(l1,a,b): perm=[] for i in range(len(l1)): if i % 2==0 : perm.append(l1.pop(0)) else : perm.append(l1.pop()) return perm tests=int(input()) for t in range(tests): n,a,b=list(map(int,input().split())) output="" if(a==b==0): for i in range(n): output+=str(i+1)+" " print(output) continue if a+b>n-2 : print(-1) continue if abs(a-b)<=1 : if a>=b : l1=list(range(n-a-b-1,n+1)) l2=list(range(1,n-a-b-1)) out=perm(l1,a,b) p=l2+out else : l1=list(range(n-a-b-1,n+1)) l2=list(range(1,n-a-b-1)) out=perm(l1,b,a) p=l2+out for i in range(n): p[i]=n-p[i]+1 print(' '.join(str(pi)for pi in p)) continue else : print(-1) continue ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var tests : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(0, tests-1) do ( var n : OclAny := null; Sequence{n,a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var output : String := "" ; if (a = b & (b == 0)) then ( for i : Integer.subrange(0, n-1) do ( output := output + ("" + ((i + 1))) + " ") ; execute (output)->display() ; continue ) else skip ; if (a + b->compareTo(n - 2)) > 0 then ( execute (-1)->display() ; continue ) else skip ; if (a - b)->abs() <= 1 then ( if (a->compareTo(b)) >= 0 then ( l1 := (Integer.subrange(n - a - b - 1, n + 1-1)) ; var l2 : Sequence := (Integer.subrange(1, n - a - b - 1-1)) ; var out : OclAny := perm(l1, a, b) ; var p : Sequence := l2->union(out) ) else ( l1 := (Integer.subrange(n - a - b - 1, n + 1-1)) ; l2 := (Integer.subrange(1, n - a - b - 1-1)) ; out := perm(l1, b, a) ; p := l2->union(out) ; for i : Integer.subrange(0, n-1) do ( p[i+1] := n - p[i+1] + 1) ) ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name pi)))))))) ))))))) (comp_for for (exprlist (expr (atom (name pi)))) in (logical_test (comparison (expr (atom (name p)))))))), ' '))->display() ; continue ) else ( execute (-1)->display() ; continue )); operation perm(l1 : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var perm : Sequence := Sequence{} ; for i : Integer.subrange(0, (l1)->size()-1) do ( if i mod 2 = 0 then ( execute ((l1->at(0`firstArg+1)) : perm) ) else ( execute ((l1->last()) : perm) )) ; return perm; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_last_two_digit(N): if N<=10 : ans=0 fac=1 for i in range(1,N+1): fac=fac*i ans+=fac ans=ans % 100 return ans else : return 13 N=1 for N in range(1,11): print("For N=",N,": ",get_last_two_digit(N),sep=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 1 ; for N : Integer.subrange(1, 11-1) do ( execute ("For N=")->display()); operation get_last_two_digit(N : OclAny) : OclAny pre: true post: true activity: if N <= 10 then ( var ans : int := 0 ; var fac : int := 1 ; for i : Integer.subrange(1, N + 1-1) do ( fac := fac * i ; ans := ans + fac) ; ans := ans mod 100 ; return ans ) else ( return 13 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,time start_time=time.time() try : if len(sys.argv)>1 : inname=sys.argv[1] else : inname=input("Enter input filename: ") assert inname.endswith('.in') outname=inname.replace('.in','.out') with open(inname)as fin : with open(outname,'w')as fout : num_cases=int(fin.readline()) for case_idx in range(1,1+num_cases): if time.time()>=start_time+5 : print("[==Case %d of %d==]" %(case_idx,num_cases)) N,pD,pG=[int(x)for x in fin.readline().split()] answer=True N=min(N,100) if pG==100 and pD!=100 : answer=False if pG==0 and pD!=0 : answer=False if all((pD*D)% 100 for D in range(1,1+N)): answer=False print("Case #{}:{}".format(case_idx,'Possible' if answer else 'Broken'),file=fout) except : import traceback print("Exception caught:",file=sys.stderr) print('-'*60,file=sys.stderr) traceback.print_exc(file=sys.stderr) print('-'*60,file=sys.stderr) input("Press Enter to close") else : total_time=time.time()-start_time print("Completed in %.1f seconds" % total_time,file=sys.stderr) time.sleep(3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var start_time : OclAny := time.time() ; try ( if ((trailer . (name argv)))->size() > 1 then ( var inname : (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) := (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) ) else ( inname := (OclFile["System.in"]).readLine("Enter input filename: ") ) ; assert inname->hasSuffix('.in') do "assertion failed" ; var outname : String := inname.replace('.in', '.out') ; try (var fin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(inname)); try (var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(outname)); var num_cases : int := ("" + ((fin.readLine())))->toInteger() ; for case_idx : Integer.subrange(1, 1 + num_cases-1) do ( if (time.time()->compareTo(start_time + 5)) >= 0 then ( execute (StringLib.format("[==Case %d of %d==]",Sequence{case_idx, num_cases}))->display() ) else skip ; var N : OclAny := null; var pD : OclAny := null; var pG : OclAny := null; Sequence{N,pD,pG} := fin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var answer : boolean := true ; var N : OclAny := Set{N, 100}->min() ; if pG = 100 & pD /= 100 then ( answer := false ) else skip ; if pG = 0 & pD /= 0 then ( answer := false ) else skip ; if ((argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name pD))) * (expr (atom (name D)))))))) ))) % (expr (atom (number (integer 100)))))))) (comp_for for (exprlist (expr (atom (name D)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) + (expr (atom (name N))))))))) )))))))))->forAll( _x | _x = true ) then ( answer := false ) else skip ; execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{case_idx, if answer then 'Possible' else 'Broken' endif}))->display())) catch (_e : OclException) do skip) catch (_e : OclException) do skip) catch (_e : OclException) do ( skip ; execute ("Exception caught:")->display() ; execute (StringLib.nCopies('-', 60))->display() ; traceback.print_exc((argument (test (logical_test (comparison (expr (atom (name file)))))) = (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stderr)))))))) ; execute (StringLib.nCopies('-', 60))->display() ; input("Press Enter to close")) else ( var total_time : double := time.time() - start_time ; execute (StringLib.format("Completed in %.1f seconds",total_time))->display() ; timeOclProcess.sleepSeconds(3) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def simp(n): j=100 k=n if n % 4==0 : j=j/4 k=k/4 elif n % 2==0 : j=j/2 k=k/2 if n % 25==0 : j=j/25 k=k/25 elif n % 5==0 : j=j/5 k=k/5 return(k,j) def works(maxD,pd,pg): (numd,dend)=simp(pd) (numg,deng)=simp(pg) if dend>maxD : return False if(pg==0)and(pd!=0): return False if(pg==100)and(pd!=100): return False return True def run(): f=open("input.in") g=open("out.txt",'w') num=int(f.readline()) for i in range(num): g.write("Case #%d: " %(i+1)) [maxD,pd,pg]=map(int,f.readline().split()) if works(maxD,pd,pg): g.write("Possible\n") else : g.write("Broken\n") f.close() g.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; Sequence{maxD}->union(Sequence{pd}->union(Sequence{ pg })) := (f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation simp(n : OclAny) : OclAny pre: true post: true activity: var j : int := 100 ; var k : OclAny := n ; if n mod 4 = 0 then ( j := j / 4 ; k := k / 4 ) else (if n mod 2 = 0 then ( j := j / 2 ; k := k / 2 ) else skip) ; if n mod 25 = 0 then ( j := j / 25 ; k := k / 25 ) else (if n mod 5 = 0 then ( j := j / 5 ; k := k / 5 ) else skip) ; return Sequence{k, j}; operation works(maxD : OclAny, pd : OclAny, pg : OclAny) pre: true post: true activity: ; var Sequence{numd, dend} : OclAny := simp(pd) ; var Sequence{numg, deng} : OclAny := simp(pg) ; if (dend->compareTo(maxD)) > 0 then ( return false ) else skip ; if (pg = 0) & (pd /= 0) then ( return false ) else skip ; if (pg = 100) & (pd /= 100) then ( return false ) else skip ; return true; operation run() pre: true post: true activity: var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("input.in")) ; var g : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("out.txt")) ; var num : int := ("" + ((f.readLine())))->toInteger() ; for i : Integer.subrange(0, num-1) do ( g.write(StringLib.format("Case #%d: ",(i + 1)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inFile=open("intpu1.txt","r") outFile=open("output1.txt","w") def solve1(NN,Pd,Pg): if Pd==100 and Pg==100 : return "Possible" if Pd==0 and Pg==0 : return "Possible" d=1 while d<=NN : if(d*Pd)% 100==0 : if Pg<100 and Pg>0 : print(NN,Pd,Pg) return "Possible" break ; d+=1 return "Broken" ; N=int(inFile.readline()) cnt=0 for line in inFile : cnt+=1 llLine=line.split() NN=int(llLine[0]) Pd=int(llLine[1]) Pg=int(llLine[2]) result=solve1(NN,Pd,Pg) resStr="Case #"+str(cnt)+": " resStr=resStr+result+"\n" print(resStr) outFile.write(resStr) def gcd(a,b): while a : a,b=b % a,a return b ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inFile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("intpu1.txt")) ; var outFile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("output1.txt")) ; skip ; var N : int := ("" + ((inFile.readLine())))->toInteger() ; var cnt : int := 0 ; for line : inFile do ( cnt := cnt + 1 ; var llLine : OclAny := line.split() ; NN := ("" + ((llLine->first())))->toInteger() ; Pd := ("" + ((llLine[1+1])))->toInteger() ; Pg := ("" + ((llLine[2+1])))->toInteger() ; var result : OclAny := solve1(NN, Pd, Pg) ; var resStr : String := "Case #" + ("" + ((cnt))) + ": " ; resStr := resStr + result + "\n" ; execute (resStr)->display() ; outFile.write(resStr)) ; skip; operation solve1(NN : OclAny, Pd : OclAny, Pg : OclAny) : OclAny pre: true post: true activity: if Pd = 100 & Pg = 100 then ( return "Possible" ) else skip ; if Pd = 0 & Pg = 0 then ( return "Possible" ) else skip ; var d : int := 1 ; while (d->compareTo(NN)) <= 0 do ( if (d * Pd) mod 100 = 0 then ( if Pg < 100 & Pg > 0 then ( execute (NN)->display() ; return "Possible" ; break; ) else skip ) else skip ; d := d + 1) ; return "Broken";; operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: while a do ( Sequence{a,b} := Sequence{b mod a,a}) ; return b; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import gcd name="A-large" f_in=open(name+'.in',"r") f_out=open(name+'.out','w') T=int(f_in.readline()) for i in range(T): print(i) N,Pd,Pg=[int(x)for x in(f_in.readline().split())] if(Pg==100 and Pd!=100): f_out.write("Case #"+str(i+1)+": "+str("Broken")+"\n") elif(Pg==100): f_out.write("Case #"+str(i+1)+": "+str("Possible")+"\n") elif(Pg==0 and Pd!=0): f_out.write("Case #"+str(i+1)+": "+str("Broken")+"\n") elif(Pg==0): f_out.write("Case #"+str(i+1)+": "+str("Possible")+"\n") elif(Pd==0): f_out.write("Case #"+str(i+1)+": "+str("Possible")+"\n") elif(Pd==100): f_out.write("Case #"+str(i+1)+": "+str("Possible")+"\n") else : ret=False g1=max(100//gcd(Pd,100),100//gcd(100-Pd,100)) print(g1,N) if(g1<=N): f_out.write("Case #"+str(i+1)+": "+str("Possible")+"\n") else : f_out.write("Case #"+str(i+1)+": "+str("Broken")+"\n") f_in.close() f_out.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var name : String := "A-large" ; var f_in : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(name + '.in')) ; var f_out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(name + '.out')) ; var T : int := ("" + ((f_in.readLine())))->toInteger() ; for i : Integer.subrange(0, T-1) do ( execute (i)->display() ; var N : OclAny := null; var Pd : OclAny := null; var Pg : OclAny := null; Sequence{N,Pd,Pg} := (f_in.readLine().split())->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if (Pg = 100 & Pd /= 100) then ( f_out.write("Case #" + ("" + ((i + 1))) + ": " + ("" + (("Broken"))) + "\n") ) else (if (Pg = 100) then ( f_out.write("Case #" + ("" + ((i + 1))) + ": " + ("" + (("Possible"))) + "\n") ) else (if (Pg = 0 & Pd /= 0) then ( f_out.write("Case #" + ("" + ((i + 1))) + ": " + ("" + (("Broken"))) + "\n") ) else (if (Pg = 0) then ( f_out.write("Case #" + ("" + ((i + 1))) + ": " + ("" + (("Possible"))) + "\n") ) else (if (Pd = 0) then ( f_out.write("Case #" + ("" + ((i + 1))) + ": " + ("" + (("Possible"))) + "\n") ) else (if (Pd = 100) then ( f_out.write("Case #" + ("" + ((i + 1))) + ": " + ("" + (("Possible"))) + "\n") ) else ( var ret : boolean := false ; var g1 : OclAny := Set{100 div gcd(Pd, 100), 100 div gcd(100 - Pd, 100)}->max() ; execute (g1)->display() ; if ((g1->compareTo(N)) <= 0) then ( f_out.write("Case #" + ("" + ((i + 1))) + ": " + ("" + (("Possible"))) + "\n") ) else ( f_out.write("Case #" + ("" + ((i + 1))) + ": " + ("" + (("Broken"))) + "\n") ) ) ) ) ) ) ) ) ; f_in.closeFile() ; f_out.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import* def yf(x,y): t=gcd(x,y) return x/t,y/t def ok(n,pd,pg): w1,d=yf(pd,100) if d>n : return False if pg==100 : return pd==100 if pg==0 : return pd==0 return True T=int(input()) for tt in range(1,T+1): line=input().split() n=int(line[0]) pd=int(line[1]) pg=int(line[2]) if ok(n,pd,pg): res="Possible" else : res="Broken" print("Case #%d: %s" %(tt,res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for tt : Integer.subrange(1, T + 1-1) do ( var line : OclAny := input().split() ; n := ("" + ((line->first())))->toInteger() ; pd := ("" + ((line[1+1])))->toInteger() ; pg := ("" + ((line[2+1])))->toInteger() ; if ok(n, pd, pg) then ( var res : String := "Possible" ) else ( res := "Broken" ) ; execute (StringLib.format("Case #%d: %s",Sequence{tt, res}))->display()); operation yf(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var t : OclAny := gcd(x, y) ; return x / t, y / t; operation ok(n : OclAny, pd : OclAny, pg : OclAny) : OclAny pre: true post: true activity: var w1 : OclAny := null; var d : OclAny := null; Sequence{w1,d} := yf(pd, 100) ; if (d->compareTo(n)) > 0 then ( return false ) else skip ; if pg = 100 then ( return pd = 100 ) else skip ; if pg = 0 then ( return pd = 0 ) else skip ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* from collections import* import math,os,sys,heapq,bisect,random from functools import lru_cache from itertools import* def inp(): return sys.stdin.readline().rstrip("\n") def out(var): sys.stdout.write(str(var)) def inpu(): return int(inp()) def lis(): return list(map(int,inp().split())) def stringlis(): return list(map(str,inp().split())) def sep(): return map(int,inp().split()) def strsep(): return map(str,inp().split()) def fsep(): return map(float,inp().split()) M,M1=1000000007,998244353 def main(): how_much_noob_I_am=1 how_much_noob_I_am=inpu() for case in range(how_much_noob_I_am): n,x=sep() flag=False headshot=False attack=[] l=[] for i in range(n): d,h=sep() if d>=x : headshot=True if d>h : flag=True attack.append(d) l.append([d,h]) if headshot : print(1) continue if not flag : print(-1) continue l.sort(key=lambda x :(x[0]-x[1])) max1=max(attack) at,tot=l[-1][0],l[-1][1] ans=((x-max1)+(at-tot-1))//(at-tot) print(ans+1) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var M : OclAny := null; var M1 : OclAny := null; Sequence{M,M1} := Sequence{1000000007,998244353} ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation inp() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip("\n"); operation out(var : OclAny) pre: true post: true activity: (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name var)))))))) ))))))))) )))); operation inpu() : OclAny pre: true post: true activity: return ("" + ((inp())))->toInteger(); operation lis() : OclAny pre: true post: true activity: return ((inp().split())->collect( _x | (OclType["int"])->apply(_x) )); operation stringlis() : OclAny pre: true post: true activity: return ((inp().split())->collect( _x | (OclType["String"])->apply(_x) )); operation sep() : OclAny pre: true post: true activity: return (inp().split())->collect( _x | (OclType["int"])->apply(_x) ); operation strsep() : OclAny pre: true post: true activity: return (inp().split())->collect( _x | (OclType["String"])->apply(_x) ); operation fsep() : OclAny pre: true post: true activity: return (inp().split())->collect( _x | (OclType["double"])->apply(_x) ); operation main() pre: true post: true activity: var how_much_noob_I_am : int := 1 ; how_much_noob_I_am := inpu() ; for case : Integer.subrange(0, how_much_noob_I_am-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := sep() ; var flag : boolean := false ; var headshot : boolean := false ; var attack : Sequence := Sequence{} ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var d : OclAny := null; var h : OclAny := null; Sequence{d,h} := sep() ; if (d->compareTo(x)) >= 0 then ( headshot := true ) else skip ; if (d->compareTo(h)) > 0 then ( flag := true ) else skip ; execute ((d) : attack) ; execute ((Sequence{d}->union(Sequence{ h })) : l)) ; if headshot then ( execute (1)->display() ; continue ) else skip ; if not(flag) then ( execute (-1)->display() ; continue ) else skip ; l := l->sort() ; var max1 : OclAny := (attack)->max() ; var at : OclAny := null; var tot : OclAny := null; Sequence{at,tot} := Sequence{l->last()->first(),l->last()[1+1]} ; var ans : int := ((x - max1) + (at - tot - 1)) div (at - tot) ; execute (ans + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,heapq,queue from functools import cmp_to_key fast_input=sys.stdin.readline for _ in range(int(fast_input())): n,x=map(int,fast_input().split()) max_in_one_blow=0 Dmax=0 for _ in range(n): d,h=map(int,fast_input().split()) max_in_one_blow=max(max_in_one_blow,d-h) Dmax=max(Dmax,d) if Dmax>=x : print(1) elif max_in_one_blow==0 : print(-1) else : r=math.ceil((x-Dmax)/max_in_one_blow) if r*max_in_one_blow==x : print(r) else : print(r+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var fast_input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + ((fast_input())))->toInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (fast_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var max_in_one_blow : int := 0 ; var Dmax : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var d : OclAny := null; var h : OclAny := null; Sequence{d,h} := (fast_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; max_in_one_blow := Set{max_in_one_blow, d - h}->max() ; Dmax := Set{Dmax, d}->max()) ; if (Dmax->compareTo(x)) >= 0 then ( execute (1)->display() ) else (if max_in_one_blow = 0 then ( execute (-1)->display() ) else ( var r : double := ((x - Dmax) / max_in_one_blow)->ceil() ; if r * max_in_one_blow = x then ( execute (r)->display() ) else ( execute (r + 1)->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,x=map(int,input().split()) c=0 d=0 for __ in range(n): a,b=map(int,input().split()) d=max(d,a-b) c=max(c,a) x-=c ans=1 if x>0 and d<=0 : print(-1) elif x>0 : if x % d==0 : ans+=x//d else : ans+=x//d+1 print(ans) else : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : int := 0 ; var d : int := 0 ; for __ : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; d := Set{d, a - b}->max() ; c := Set{c, a}->max()) ; x := x - c ; var ans : int := 1 ; if x > 0 & d <= 0 then ( execute (-1)->display() ) else (if x > 0 then ( if x mod d = 0 then ( ans := ans + x div d ) else ( ans := ans + x div d + 1 ) ; execute (ans)->display() ) else ( execute (ans)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Point : def __init__(self,x,y): self.x=x self.y=y def doOverlap(l1,r1,l2,r2): if(l1.x>=r2.x or l2.x>=r1.x): return False if(l1.y<=r2.y or l2.y<=r1.y): return False return True if __name__=="__main__" : l1=Point(0,10) r1=Point(10,0) l2=Point(5,5) r2=Point(15,0) if(doOverlap(l1,r1,l2,r2)): print("Rectangles Overlap") else : print("Rectangles Don't Overlap") ------------------------------------------------------------ OCL File: --------- class Point { static operation newPoint() : Point pre: true post: Point->exists( _x | result = _x ); attribute x : OclAny := x; attribute y : OclAny := y; operation initialise(x : OclAny,y : OclAny) : Point pre: true post: true activity: self.x := x ; self.y := y; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( l1 := (Point.newPoint()).initialise(0, 10) ; r1 := (Point.newPoint()).initialise(10, 0) ; l2 := (Point.newPoint()).initialise(5, 5) ; r2 := (Point.newPoint()).initialise(15, 0) ; if (doOverlap(l1, r1, l2, r2)) then ( execute ("Rectangles Overlap")->display() ) else ( execute ("Rectangles Don't Overlap")->display() ) ) else skip; operation doOverlap(l1 : OclAny, r1 : OclAny, l2 : OclAny, r2 : OclAny) : OclAny pre: true post: true activity: if ((l1.x->compareTo(r2.x)) >= 0 or (l2.x->compareTo(r1.x)) >= 0) then ( return false ) else skip ; if ((l1.y->compareTo(r2.y)) <= 0 or (l2.y->compareTo(r1.y)) <= 0) then ( return false ) else skip ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline readall=sys.stdin.read ns=lambda : readline().rstrip() ni=lambda : int(readline().rstrip()) nm=lambda : map(int,readline().split()) nl=lambda : list(map(int,readline().split())) prn=lambda x : print(*x,sep='\n') def solve(): INT_BITS=64 n=ni() a=nl()[: :-1] s=ns()[: :-1] lis=[0]*64 for i in range(n): if s[i]=='1' : c=a[i] for x in lis[: :-1]: if x==0 : continue if c &(1<<(x.bit_length()-1)): c ^=x if c : print(1) return else : c=a[i] for x in lis[: :-1]: if x==0 : continue if c &(1<<(x.bit_length()-1)): c ^=x if c : lis[c.bit_length()-1]=c print(0) return T=ni() for _ in range(T): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var readall : OclAny := (OclFile["System.in"]).read ; var ns : Function := lambda $$ : OclAny in (readline().rstrip()) ; var ni : Function := lambda $$ : OclAny in (("" + ((readline().rstrip())))->toInteger()) ; var nm : Function := lambda $$ : OclAny in ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var nl : Function := lambda $$ : OclAny in (((readline().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var prn : Function := lambda x : OclAny in (((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ; skip ; var T : OclAny := ni->apply() ; for _anon : Integer.subrange(0, T-1) do ( solve()); operation solve() pre: true post: true activity: var INT_BITS : int := 64 ; var n : OclAny := ni->apply() ; var a : OclAny := nl->apply()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var s : OclAny := ns->apply()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var lis : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 64) ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = '1' then ( var c : OclAny := a[i+1] ; for x : lis(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if x = 0 then ( continue ) else skip ; if MathLib.bitwiseAnd(c, (1 * (2->pow((x.bit_length() - 1))))) then ( c := c xor x ) else skip) ; if c then ( execute (1)->display() ; return ) else skip ) else ( c := a[i+1] ; for x : lis(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if x = 0 then ( continue ) else skip ; if MathLib.bitwiseAnd(c, (1 * (2->pow((x.bit_length() - 1))))) then ( c := c xor x ) else skip) ; if c then ( lis[c.bit_length() - 1+1] := c ) else skip )) ; execute (0)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() s=int(n,2) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var s : int := ("" + ((n, 2)))->toInteger() ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def xor_gauss_jordan(A): cnt_row=len(A) cnt_col=len(bin(max(A))[2 : :]) rank=0 for col in range(cnt_col): pivot=-1 for row in range(rank,cnt_row): if A[row]& 2**(cnt_col-col-1): pivot=row break if pivot==-1 : continue A[pivot],A[rank]=A[rank],A[pivot] A_rank=A[rank] for row in range(cnt_row): if row!=rank and A[row]& 2**(cnt_col-col-1): A[row]^=A[rank] rank+=1 return A t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) s=input() hand=[0] flag=False for i in range(n)[: :-1]: val=a[i] if s[i]=="1" : hand.sort(reverse=True) for num in hand : if val.bit_length()==num.bit_length(): val ^=num if val!=0 : flag=True else : hand.append(val) hand=xor_gauss_jordan(hand) if flag : print(1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : String := (OclFile["System.in"]).readLine() ; var hand : Sequence := Sequence{ 0 } ; var flag : boolean := false ; for i : range(n)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( var val : OclAny := a[i+1] ; if s[i+1] = "1" then ( hand := hand->sort() ; for num : hand do ( if val.bit_length() = num.bit_length() then ( val := val xor num ) else skip) ; if val /= 0 then ( flag := true ) else skip ) else ( execute ((val) : hand) ; hand := xor_gauss_jordan(hand) )) ; if flag then ( execute (1)->display() ) else ( execute (0)->display() )); operation xor_gauss_jordan(A : OclAny) : OclAny pre: true post: true activity: var cnt_row : int := (A)->size() ; var cnt_col : int := (bin((A)->max())(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop :)))->size() ; var rank : int := 0 ; for col : Integer.subrange(0, cnt_col-1) do ( var pivot : int := -1 ; for row : Integer.subrange(rank, cnt_row-1) do ( if MathLib.bitwiseAnd(A[row+1], (2)->pow((cnt_col - col - 1))) then ( pivot := row ; break ) else skip) ; if pivot = -1 then ( continue ) else skip ; var A[pivot+1] : OclAny := null; var A[rank+1] : OclAny := null; Sequence{A[pivot+1],A[rank+1]} := Sequence{A[rank+1],A[pivot+1]} ; var A_rank : OclAny := A[rank+1] ; for row : Integer.subrange(0, cnt_row-1) do ( if row /= rank & MathLib.bitwiseAnd(A[row+1], (2)->pow((cnt_col - col - 1))) then ( A[row+1] := A[row+1] xor A[rank+1] ) else skip) ; rank := rank + 1) ; return A; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline class BaseXor : def __init__(self): self.size=0 self.base=[] def base_calculate(self,x,b): return min(x,x ^ b) def make_base(self,x): for b in self.base : x=self.base_calculate(x,b) return x def change_base(self,x): for i in range(self.size): self.base[i]=self.base_calculate(self.base[i],x) def add_base(self,x): x=self.make_base(x) if x==0 : return False self.change_base(x) self.base.append(x) self.base.sort() self.size+=1 return True def judge_linearly_dependent(self,x): for b in self.base : x=self.base_calculate(x,b) res=True if x else False return res def solve(n,a,s): base=BaseXor() judge=False for i in range(n-1,-1,-1): x=s[i] if x=="0" : base.add_base(a[i]) else : judge=base.judge_linearly_dependent(a[i]) if judge : break res=1 if judge else 0 return res def main(): t=int(input()) ans=[0]*t for i in range(t): n=int(input()) a=list(map(int,input().split())) s=input() res=solve(n,a,s) ans[i]=res print(*ans,sep="\n") if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class BaseXor { static operation newBaseXor() : BaseXor pre: true post: BaseXor->exists( _x | result = _x ); attribute size : int := 0; attribute base : Sequence := Sequence{}; operation initialise() : BaseXor pre: true post: true activity: self.size := 0 ; self.base := Sequence{}; return self; operation base_calculate(x : OclAny,b : OclAny) : OclAny pre: true post: true activity: return Set{x, MathLib.bitwiseXor(x, b)}->min(); operation make_base(x : OclAny) : OclAny pre: true post: true activity: for b : self.base do ( x := self.base_calculate(x, b)) ; return x; operation change_base(x : OclAny) pre: true post: true activity: for i : Integer.subrange(0, self.size-1) do ( self.base[i+1] := self.base_calculate(self.base[i+1], x)); operation add_base(x : OclAny) : OclAny pre: true post: true activity: x := self.make_base(x) ; if x = 0 then ( return false ) else skip ; self.change_base(x) ; (expr (atom (name self)) (trailer . (name base)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) ; (expr (atom (name self)) (trailer . (name base)) (trailer . (name sort) (arguments ( )))) ; self.size := self.size + 1 ; return true; operation judge_linearly_dependent(x : OclAny) : OclAny pre: true post: true activity: for b : self.base do ( x := self.base_calculate(x, b)) ; var res : boolean := if x then true else false endif ; return res; } class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation solve(n : OclAny, a : OclAny, s : OclAny) : OclAny pre: true post: true activity: var base : BaseXor := (BaseXor.newBaseXor()).initialise() ; var judge : boolean := false ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( x := s[i+1] ; if x = "0" then ( base.add_base(a[i+1]) ) else ( judge := base.judge_linearly_dependent(a[i+1]) ; if judge then ( break ) else skip )) ; res := if judge then 1 else 0 endif ; return res; operation main() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, t) ; for i : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; s := (OclFile["System.in"]).readLine() ; res := solve(n, a, s) ; ans[i+1] := res) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(*args : str)->str : t=int(args[0]) ret=[] for i in range(1,3*t+1,3): n=int(args[i]) A=tuple(map(int,args[i+1].split())) S=tuple(map(int,tuple(args[i+2]))) ans=False dp=[0]*(max(A).bit_length()+1) for a,s in reversed(tuple(zip(A,S))): m=a.bit_length() if s==0 : while 0display() ) else skip; operation solve(args : String : Sequence(OclAny)) : String pre: true post: true activity: (args * (named_parameter (name args) : (test (logical_test (comparison (expr (atom (name str)))))))) var t : int := ("" + ((args->first())))->toInteger() ; var ret : Sequence := Sequence{} ; for i : Integer.subrange(1, 3 * t + 1-1)->select( $x | ($x - 1) mod 3 = 0 ) do ( var n : int := ("" + ((args[i+1])))->toInteger() ; var A : Sequence := ((args[i + 1+1].split())->collect( _x | (OclType["int"])->apply(_x) )) ; var S : Sequence := (((args[i + 2+1]))->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : boolean := false ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (max(A).bit_length() + 1)) ; for _tuple : ((Integer.subrange(1, A->size())->collect( _indx | Sequence{A->at(_indx), S->at(_indx)} )))->reverse() do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); var m : OclAny := a.bit_length() ; if s = 0 then ( while 0 < a & 0 < dp[m+1] do ( a := a xor dp[m+1] ; m := a.bit_length()) ; if 0 < a then ( dp[m+1] := a ) else skip ) else (if s = 1 then ( while 0 < a do ( if 0 < dp[m+1] then ( a := a xor dp[m+1] ; m := a.bit_length() ) else ( ans := true ; break )) ) else skip)) ; execute ((1 * ans) : ret)) ; return StringLib.sumStringsWithSeparator(((ret)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input n=int for i in range(n(input())): I(); t=[]; x=0 for i,j in zip(map(n,I().split()[: :-1]),I()[: :-1]): for k in t : i ^=k*(i ^ k0)& j print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; var n : int := OclType["int"] ; for i : Integer.subrange(0, n((OclFile["System.in"]).readLine())-1) do ( I(); var t : Sequence := Sequence{}; var x : int := 0 ; for _tuple : Integer.subrange(1, (I().split()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->collect( _x | (n)->apply(_x) )->size())->collect( _indx | Sequence{(I().split()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->collect( _x | (n)->apply(_x) )->at(_indx), I()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); for k : t do ( i := i xor k * ((MathLib.bitwiseXor(i, k)->compareTo(i)) < 0)) ; var j : OclAny := n(j); execute ((i * (MathLib.bitwiseXor(j, 1))) : t); x := x or MathLib.bitwiseAnd((i > 0), j)) ; execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def checkPerfectcube(n): d=int(n**(1/3)); if(d*d*d==n): return True ; return False ; def smallestPerfectCube(a,n): mini=sys.maxsize ; for i in range(n): if(checkPerfectcube(a[i])): mini=min(a[i],mini); return mini ; if __name__=="__main__" : a=[16,8,25,2,3,10]; n=len(a); print(smallestPerfectCube(a,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( a := Sequence{16}->union(Sequence{8}->union(Sequence{25}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 10 }))))); ; n := (a)->size(); ; execute (smallestPerfectCube(a, n))->display(); ) else skip; operation checkPerfectcube(n : OclAny) pre: true post: true activity: var d : int := ("" + (((n)->pow((1 / 3)))))->toInteger(); ; if (d * d * d = n) then ( return true; ) else skip ; return false;; operation smallestPerfectCube(a : OclAny, n : OclAny) pre: true post: true activity: var mini : (trailer . (name maxsize)) := (trailer . (name maxsize)); ; for i : Integer.subrange(0, n-1) do ( if (checkPerfectcube(a[i+1])) then ( mini := Set{a[i+1], mini}->min(); ) else skip) ; return mini;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pairwiseProduct(arr,n): prod=1 for i in range(n-1): prod=arr[i]*arr[i+1] print(prod,end=" ") if __name__=="__main__" : arr=[4,10,15,5,6] n=len(arr) pairwiseProduct(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{4}->union(Sequence{10}->union(Sequence{15}->union(Sequence{5}->union(Sequence{ 6 })))) ; n := (arr)->size() ; pairwiseProduct(arr, n) ) else skip; operation pairwiseProduct(arr : OclAny, n : OclAny) pre: true post: true activity: var prod : int := 1 ; for i : Integer.subrange(0, n - 1-1) do ( prod := arr[i+1] * arr[i + 1+1] ; execute (prod)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() ans=999 for i in range(len(s)-2): w=int(s[i : i+3]) ans=min(ans,abs(753-w)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var ans : int := 999 ; for i : Integer.subrange(0, (s)->size() - 2-1) do ( var w : int := ("" + ((s.subrange(i+1, i + 3))))->toInteger() ; ans := Set{ans, (753 - w)->abs()}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(map(int,input())) print(min(abs(s[i+2]+s[i+1]*10+s[i]*100-753)for i in range(len(s)-2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := (((OclFile["System.in"]).readLine())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (((argument (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 2)))))))))) ]))) + (expr (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))) * (expr (atom (number (integer 10)))))) + (expr (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) * (expr (atom (number (integer 100)))))) - (expr (atom (number (integer 753)))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))) - (expr (atom (number (integer 2)))))))))) )))))))))->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() N=len(S) D=[] for i in range(0,N-2): D.append(S[i : i+3]) E=[] for j in range(N-2): n=abs(753-int(D[j])) E.append(n) ans=min(E) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var N : int := (S)->size() ; var D : Sequence := Sequence{} ; for i : Integer.subrange(0, N - 2-1) do ( execute ((S.subrange(i+1, i + 3)) : D)) ; var E : Sequence := Sequence{} ; for j : Integer.subrange(0, N - 2-1) do ( var n : double := (753 - ("" + ((D[j+1])))->toInteger())->abs() ; execute ((n) : E)) ; var ans : OclAny := (E)->min() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=3 C=3 MAX_K=1000 def pathCountDPRecDP(mat,m,n,k): if m<0 or n<0 : return 0 elif m==0 and n==0 : return k==mat[m][n] if(dp[m][n][k]!=-1): return dp[m][n][k] dp[m][n][k]=(pathCountDPRecDP(mat,m-1,n,k-mat[m][n])+pathCountDPRecDP(mat,m,n-1,k-mat[m][n])) return dp[m][n][k] def pathCountDP(mat,k): return pathCountDPRecDP(mat,R-1,C-1,k) k=12 dp=[[[-1 for col in range(MAX_K)]for col in range(C)]for row in range(R)] mat=[[1,2,3],[4,6,5],[3,2,1]] print(pathCountDP(mat,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : int := 3 ; var C : int := 3 ; var MAX_K : int := 1000 ; skip ; skip ; k := 12 ; var dp : Sequence := Integer.subrange(0, R-1)->select(row | true)->collect(row | (Integer.subrange(0, C-1)->select(col | true)->collect(col | (Integer.subrange(0, MAX_K-1)->select(col | true)->collect(col | (-1)))))) ; mat := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{Sequence{4}->union(Sequence{6}->union(Sequence{ 5 }))}->union(Sequence{ Sequence{3}->union(Sequence{2}->union(Sequence{ 1 })) })) ; execute (pathCountDP(mat, k))->display(); operation pathCountDPRecDP(mat : OclAny, m : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if m < 0 or n < 0 then ( return 0 ) else (if m = 0 & n = 0 then ( return k = mat[m+1][n+1] ) else skip) ; if (dp[m+1][n+1][k+1] /= -1) then ( return dp[m+1][n+1][k+1] ) else skip ; dp[m+1][n+1][k+1] := (pathCountDPRecDP(mat, m - 1, n, k - mat[m+1][n+1]) + pathCountDPRecDP(mat, m, n - 1, k - mat[m+1][n+1])) ; return dp[m+1][n+1][k+1]; operation pathCountDP(mat : OclAny, k : OclAny) : OclAny pre: true post: true activity: return pathCountDPRecDP(mat, R - 1, C - 1, k); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil,floor def isPossible(x,y,z): a=x*x+y*y+z*z a=round(a,8) if(ceil(a)==1 & floor(a)==1): return True return False if __name__=="__main__" : l=0.70710678 m=0.5 n=0.5 if(isPossible(l,m,n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var l : double := 0.70710678 ; var m : double := 0.5 ; var n : double := 0.5 ; if (isPossible(l, m, n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isPossible(x : OclAny, y : OclAny, z : OclAny) : OclAny pre: true post: true activity: var a : double := x * x + y * y + z * z ; a := MathLib.roundN(a, 8) ; if (ceil(a) = MathLib.bitwiseAnd(1, floor(a)) & (MathLib.bitwiseAnd(1, floor(a)) == 1)) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from bisect import* from collections import* from copy import deepcopy from datetime import* from heapq import* from itertools import* from operator import* from pprint import* sys.setrecursionlimit(10**8) input=sys.stdin.readline def main(): S=input().rstrip() N=len(S) ans=float('inf') for i in range(N-2): num=int(S[i : i+3]) ans=min(ans,abs(753-num)) print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var S : OclAny := input().rstrip() ; var N : int := (S)->size() ; var ans : double := ("" + (('inf')))->toReal() ; for i : Integer.subrange(0, N - 2-1) do ( var num : int := ("" + ((S.subrange(i+1, i + 3))))->toInteger() ; ans := Set{ans, (753 - num)->abs()}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() xx=753 ans=10**10 for i in range(len(s)-2): ans=min(ans,abs(xx-int(s[i : i+3]))) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var xx : int := 753 ; var ans : double := (10)->pow(10) ; for i : Integer.subrange(0, (s)->size() - 2-1) do ( ans := Set{ans, (xx - ("" + ((s.subrange(i+1, i + 3))))->toInteger())->abs()}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- P=1 R=1 T=1 SI=(P*R*T)/100 print("simple interest is",SI) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var P : int := 1 ; var R : int := 1 ; var T : int := 1 ; var SI : double := (P * R * T) / 100 ; execute ("simple interest is")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- M=pow(10,9)+7 def pow_mod(a,n,m): res=1 while n>0 : if n % 2==1 : res=(res*a)% m a=(a*a)% m n=n//2 return res def combi_mod(p,q,m): numerator,denominator=1,1 for i in range(1,q+1): numerator*=(p-i+1) numerator %=m denominator*=i denominator %=m return numerator*pow_mod(denominator,m-2,m)% m n,a,b=list(map(int,input().split())) res=pow_mod(2,n,M)-1 res-=combi_mod(n,a,M) if res<0 : res+=M res-=combi_mod(n,b,M) if res<0 : res+=M print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var M : double := (10)->pow(9) + 7 ; skip ; skip ; var b : OclAny := null; Sequence{n,a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; res := pow_mod(2, n, M) - 1 ; res := res - combi_mod(n, a, M) ; if res < 0 then ( res := res + M ) else skip ; res := res - combi_mod(n, b, M) ; if res < 0 then ( res := res + M ) else skip ; execute (res)->display(); operation pow_mod(a : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; while n > 0 do ( if n mod 2 = 1 then ( res := (res * a) mod m ) else skip ; a := (a * a) mod m ; n := n div 2) ; return res; operation combi_mod(p : OclAny, q : OclAny, m : OclAny) : OclAny pre: true post: true activity: var numerator : OclAny := null; var denominator : OclAny := null; Sequence{numerator,denominator} := Sequence{1,1} ; for i : Integer.subrange(1, q + 1-1) do ( numerator := numerator * (p - i + 1) ; numerator := numerator mod m ; denominator := denominator * i ; denominator := denominator mod m) ; return numerator * pow_mod(denominator, m - 2, m) mod m; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=[int(x)for x in input().split()] INF=(10**9+7) def c(n,r,p): r=min(r,n-r) numer=1 denom=1 for i in range(1,r+1): numer=numer*(n+1-i)% p denom=denom*i % p return numer*pow(denom,p-2,p)% p ans=pow(2,n,INF)-1-c(n,a,INF)-c(n,b,INF) while ans<0 : ans+=INF print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var INF : double := ((10)->pow(9) + 7) ; skip ; var ans : double := (2)->pow(n) - 1 - c(n, a, INF) - c(n, b, INF) ; while ans < 0 do ( ans := ans + INF) ; execute (ans)->display(); operation c(n : OclAny, r : OclAny, p : OclAny) : OclAny pre: true post: true activity: r := Set{r, n - r}->min() ; var numer : int := 1 ; var denom : int := 1 ; for i : Integer.subrange(1, r + 1-1) do ( numer := numer * (n + 1 - i) mod p ; denom := denom * i mod p) ; return numer * (denom)->pow(p - 2) mod p; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import factorial n,a,b=map(int,input().split()) MOD=10**9+7 xa=1 xb=1 k1=pow(2,n,MOD) A=pow(factorial(a),MOD-2,MOD) B=pow(factorial(b),MOD-2,MOD) for i in range(a): xa=xa*(n-i)% MOD for j in range(b): xb=xb*(n-j)% MOD ans=(k1-(A*xa)-(B*xb)-1)% MOD print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var MOD : double := (10)->pow(9) + 7 ; var xa : int := 1 ; var xb : int := 1 ; var k1 : double := (2)->pow(n) ; var A : double := (factorial(a))->pow(MOD - 2) ; var B : double := (factorial(b))->pow(MOD - 2) ; for i : Integer.subrange(0, a-1) do ( xa := xa * (n - i) mod MOD) ; for j : Integer.subrange(0, b-1) do ( xb := xb * (n - j) mod MOD) ; var ans : int := (k1 - (A * xa) - (B * xb) - 1) mod MOD ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pow_k(x,n): MOD=10**9+7 if n==0 : return 1 K=1 while n>1 : if n % 2!=0 : K*=x K %=MOD x*=x x %=MOD n//=2 return K*x def cmb(n,r): MOD=10**9+7 if n-r1 : offset=(n-r)% p for k in range(p-1,r,p): numerator[k-offset]/=pivot denominator[k]/=pivot result=1 for k in range(r): if numerator[k]>1 : result*=int(numerator[k]) result %=MOD return result n,a,b=map(int,input().split()) MOD=10**9+7 ans=pow_k(2,n)-1 print((ans-cmb(n,a)-cmb(n,b))% MOD) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; MOD := (10)->pow(9) + 7 ; var ans : double := pow_k(2, n) - 1 ; execute ((ans - cmb(n, a) - cmb(n, b)) mod MOD)->display(); operation pow_k(x : OclAny, n : OclAny) : OclAny pre: true post: true activity: var MOD : double := (10)->pow(9) + 7 ; if n = 0 then ( return 1 ) else skip ; var K : int := 1 ; while n > 1 do ( if n mod 2 /= 0 then ( K := K * x ; K := K mod MOD ) else skip ; x := x * x ; x := x mod MOD ; n := n div 2) ; return K * x; operation cmb(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: MOD := (10)->pow(9) + 7 ; if (n - r->compareTo(r)) < 0 then ( r := n - r ) else skip ; if r = 0 then ( return 1 ) else skip ; if r = 1 then ( return n ) else skip ; var numerator : Sequence := Integer.subrange(0, r-1)->select(k | true)->collect(k | (n - r + k + 1)) ; var denominator : Sequence := Integer.subrange(0, r-1)->select(k | true)->collect(k | (k + 1)) ; for p : Integer.subrange(2, r + 1-1) do ( var pivot : OclAny := denominator[p - 1+1] ; if pivot > 1 then ( var offset : int := (n - r) mod p ; for k : Integer.subrange(p - 1, r-1)->select( $x | ($x - p - 1) mod p = 0 ) do ( numerator[k - offset+1] := numerator[k - offset+1] / pivot ; denominator[k+1] := denominator[k+1] / pivot) ) else skip) ; var result : int := 1 ; for k : Integer.subrange(0, r-1) do ( if numerator[k+1] > 1 then ( result := result * ("" + ((numerator[k+1])))->toInteger() ; result := result mod MOD ) else skip) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def d_bouquet(MOD=10**9+7): from functools import reduce N,A,B=[int(i)for i in input().split()] def comb(m,r): numerator=reduce(lambda x,y : x*y % MOD,range(m,m-r,-1)) denominator=reduce(lambda x,y : x*y % MOD,range(1,r+1)) return(numerator*pow(denominator,MOD-2,MOD))% MOD return(pow(2,N,MOD)-1-(comb(N,A)+comb(N,B)))% MOD print(d_bouquet()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (d_bouquet())->display(); operation d_bouquet(MOD : OclAny) : OclAny pre: true post: true activity: if MOD->oclIsUndefined() then MOD := (10)->pow(9) + 7 else skip; skip ; var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{N,A,B} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; skip ; return ((2)->pow(N) - 1 - (comb(N, A) + comb(N, B))) mod MOD; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=map(int,input().split()) list1=[int(i)for i in input().split()] count=0 for i in range(n): for j in range(n): if i!=j and abs(list1[i]-list1[j])<=d : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var list1 : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if i /= j & ((list1[i+1] - list1[j+1])->abs()->compareTo(d)) <= 0 then ( count := count + 1 ) else skip)) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import* from decimal import* def _input(): return map(int,input().split()) def _list(): return list(map(int,input().split())) def solves(): n,m=_input() a=sorted(_list()) ans=0 for i in range(n): for j in range(i+1,n): if(a[j]-a[i]>m): break else : ans+=2 print(ans) t=1 for _ in range(0,t): solves() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solves()); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation _list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation solves() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := _input() ; var a : Sequence := _list()->sort() ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if ((a[j+1] - a[i+1]->compareTo(m)) > 0) then ( break ) else ( ans := ans + 2 ))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000000 MOD=10**9+7 result=[0 for i in range(MAX+1)] fact=[0 for i in range(MAX+1)] def preCompute(): fact[0]=1 result[0]=1 for i in range(1,MAX+1): fact[i]=((fact[i-1]% MOD)*i)% MOD result[i]=((result[i-1]% MOD)*(fact[i]% MOD))% MOD def performQueries(q,n): preCompute() for i in range(n): print(result[q[i]]) q=[4,5] n=len(q) performQueries(q,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1000000 ; var MOD : double := (10)->pow(9) + 7 ; var result : Sequence := Integer.subrange(0, MAX + 1-1)->select(i | true)->collect(i | (0)) ; var fact : Sequence := Integer.subrange(0, MAX + 1-1)->select(i | true)->collect(i | (0)) ; skip ; skip ; q := Sequence{4}->union(Sequence{ 5 }) ; n := (q)->size() ; performQueries(q, n); operation preCompute() pre: true post: true activity: fact->first() := 1 ; result->first() := 1 ; for i : Integer.subrange(1, MAX + 1-1) do ( fact[i+1] := ((fact[i - 1+1] mod MOD) * i) mod MOD ; result[i+1] := ((result[i - 1+1] mod MOD) * (fact[i+1] mod MOD)) mod MOD); operation performQueries(q : OclAny, n : OclAny) pre: true post: true activity: preCompute() ; for i : Integer.subrange(0, n-1) do ( execute (result[q[i+1]+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Move(a,x,b): if((((b-a)% x==0)or((b-a-1)% x==0)and a+1!=b)and b>=a): return True return False if __name__=="__main__" : a=3 x=2 b=7 if(Move(a,x,b)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := 3 ; x := 2 ; b := 7 ; if (Move(a, x, b)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation Move(a : OclAny, x : OclAny, b : OclAny) : OclAny pre: true post: true activity: if ((((b - a) mod x = 0) or ((b - a - 1) mod x = 0) & a + 1 /= b) & (b->compareTo(a)) >= 0) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,d=map(int,input().split()) b=list(map(int,input().split())) c=0 for i in range(a): for j in range(a): if abs(b[i]-b[j])<=d and i!=j : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var d : OclAny := null; Sequence{a,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; for i : Integer.subrange(0, a-1) do ( for j : Integer.subrange(0, a-1) do ( if ((b[i+1] - b[j+1])->abs()->compareTo(d)) <= 0 & i /= j then ( c := c + 1 ) else skip)) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=input().split() n=int(n) d=int(d) a=list(input().split()) a=[int(i)for i in a] ans=0 for i in range(0,n): for j in range(0,n): if i!=j and abs(a[i]-a[j])<=d : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var d : int := ("" + ((d)))->toInteger() ; var a : Sequence := (input().split()) ; a := a->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if i /= j & ((a[i+1] - a[j+1])->abs()->compareTo(d)) <= 0 then ( ans := ans + 1 ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sol,d=map(int,input().split()) heights=[int(height)for height in input().split()] heights.sort() result=0 for i in range(len(heights)-1): h=heights[i] j=i+1 h2=heights[j] mod=h2-h if mod<0 : mod*=-1 while(mod<=d): result+=1 j+=1 if jcollect( _x | (OclType["int"])->apply(_x) ) ; var heights : Sequence := input().split()->select(height | true)->collect(height | (("" + ((height)))->toInteger())) ; heights := heights->sort() ; var result : int := 0 ; for i : Integer.subrange(0, (heights)->size() - 1-1) do ( var h : OclAny := heights[i+1] ; var j : OclAny := i + 1 ; var h2 : OclAny := heights[j+1] ; var mod : double := h2 - h ; if mod < 0 then ( mod := mod * -1 ) else skip ; while ((mod->compareTo(d)) <= 0) do ( result := result + 1 ; j := j + 1 ; if (j->compareTo((heights)->size())) < 0 then ( h2 := heights[j+1] ; mod := h2 - h ) else ( break ))) ; execute (2 * (result))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkDivisibility(num): length=len(num) if(length==1 and num[0]=='0'): return True if(length % 3==1): num=str(num)+"00" length+=2 elif(length % 3==2): num=str(num)+"0" length+=1 sum=0 p=1 for i in range(length-1,-1,-1): group=0 group+=ord(num[i])-ord('0') i-=1 group+=(ord(num[i])-ord('0'))*10 i-=1 group+=(ord(num[i])-ord('0'))*100 sum=sum+group*p p*=(-1) sum=abs(sum) return(sum % 13==0) if __name__=="__main__" : number="83959092724" if(checkDivisibility(number)): print(number,"is divisible by 13.") else : print(number,"is not divisibe by 13.") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var number : String := "83959092724" ; if (checkDivisibility(number)) then ( execute (number)->display() ) else ( execute (number)->display() ) ) else skip; operation checkDivisibility(num : OclAny) : OclAny pre: true post: true activity: var length : int := (num)->size() ; if (length = 1 & num->first() = '0') then ( return true ) else skip ; if (length mod 3 = 1) then ( num := ("" + ((num))) + "00" ; length := length + 2 ) else (if (length mod 3 = 2) then ( num := ("" + ((num))) + "0" ; length := length + 1 ) else skip) ; var sum : int := 0 ; var p : int := 1 ; for i : Integer.subrange(-1 + 1, length - 1)->reverse() do ( var group : int := 0 ; group := group + (num[i+1])->char2byte() - ('0')->char2byte() ; i := i - 1 ; group := group + ((num[i+1])->char2byte() - ('0')->char2byte()) * 10 ; i := i - 1 ; group := group + ((num[i+1])->char2byte() - ('0')->char2byte()) * 100 ; sum := sum + group * p ; p := p * (-1)) ; sum := (sum)->abs() ; return (sum mod 13 = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isOverflow(a,b): if(a==0 or b==0): return False result=a*b if(result>=9223372036854775807 or result<=-9223372036854775808): result=0 if(a==(result//b)): print(result//b) return False else : return True if __name__=="__main__" : a=10000000000 b=-10000000000 if(isOverflow(a,b)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := 10000000000 ; b := -10000000000 ; if (isOverflow(a, b)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isOverflow(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0 or b = 0) then ( return false ) else skip ; var result : double := a * b ; if (result >= 9223372036854775807 or result <= -9223372036854775808) then ( result := 0 ) else skip ; if (a = (result div b)) then ( execute (result div b)->display() ; return false ) else ( return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b=map(int,input().split()) b=b+1 print('YES' if a % b>=b/2 else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : OclAny := b + 1 ; execute (if (a mod b->compareTo(b / 2)) >= 0 then 'YES' else 'NO' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: l,r=map(int,s.split()); print('YNEOS'[r>=2*l : : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ); execute ('YNEOS'(subscript (test (logical_test (comparison (comparison (expr (atom (name r)))) >= (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name l)))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def solve(): l,r=map(int,input().split()) return "YES" if r<2*l else "NO" for _ in range(int(input())): print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (solve())->display()); operation solve() : OclAny pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; return if (r->compareTo(2 * l)) < 0 then "YES" else "NO" endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b=map(int,input().split()) if a==b or a %(b+1)>=(b+1)/2 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = b or (a mod (b + 1)->compareTo((b + 1) / 2)) >= 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re _=int(input()) xs=re.findall("x{3,}",input()) print(len("".join(xs))-2*len(xs)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var _anon : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var xs : Sequence(String) := ((OclFile["System.in"]).readLine())->allMatches("x{3,}") ; execute ((StringLib.sumStringsWithSeparator((xs), ""))->size() - 2 * (xs)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): l,r=map(int,input().split(' ')) if l*2>r : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; if (l * 2->compareTo(r)) > 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def even_or_odd(N): l=len(N) if(N[l-1]=='0' or N[l-1]=='2' or N[l-1]=='4' or N[l-1]=='6' or N[l-1]=='8' or N[l-1]=='A' or N[l-1]=='C' or N[l-1]=='E'): return("Even") else : return("Odd") N="AB3454D" print(even_or_odd(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := "AB3454D" ; execute (even_or_odd(N))->display(); operation even_or_odd(N : OclAny) : OclAny pre: true post: true activity: var l : int := (N)->size() ; if (N[l - 1+1] = '0' or N[l - 1+1] = '2' or N[l - 1+1] = '4' or N[l - 1+1] = '6' or N[l - 1+1] = '8' or N[l - 1+1] = 'A' or N[l - 1+1] = 'C' or N[l - 1+1] = 'E') then ( return ("Even") ) else ( return ("Odd") ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : x=int(input()) if x==0 : break c=0 while True : if x==1 : break elif x % 2==0 : x=x//2 else : x=x*3+1 c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if x = 0 then ( break ) else skip ; var c : int := 0 ; while true do ( if x = 1 then ( break ) else (if x mod 2 = 0 then ( x := x div 2 ) else ( x := x * 3 + 1 ) ) ; c := c + 1) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def main(args): while True : n=int(input()) if n==0 : break count=0 while n!=1 : if n % 2==0 : n//=2 else : n*=3 n+=1 count+=1 print(count) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation main(args : OclAny) pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var count : int := 0 ; while n /= 1 do ( if n mod 2 = 0 then ( n := n div 2 ) else ( n := n * 3 ; n := n + 1 ) ; count := count + 1) ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def process(n,x): if n!=1 : if n % 2==0 : x+=1 return process(n//2,x) else : x+=1 return process(n*3+1,x) else : return x while True : n=int(input()) if n==0 : break print(process(n,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; execute (process(n, 0))->display()); operation process(n : OclAny, x : OclAny) : OclAny pre: true post: true activity: if n /= 1 then ( if n mod 2 = 0 then ( x := x + 1 ; return process(n div 2, x) ) else ( x := x + 1 ; return process(n * 3 + 1, x) ) ) else ( return x ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def collatz(n): i=0 while n!=1 : if n % 2==0 : n=n/2 i=i+1 else : n=3*n+1 i=i+1 return(i) while True : n=int(input()) if n==0 : break print(collatz(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; execute (collatz(n))->display()); operation collatz(n : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; while n /= 1 do ( if n mod 2 = 0 then ( n := n / 2 ; i := i + 1 ) else ( n := 3 * n + 1 ; i := i + 1 )) ; return (i); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break count=0 while True : if n==1 : break if n % 2==0 : n=int(n/2) count+=1 continue if n % 2==1 : n=int(3*n+1) count+=1 continue if n==1 : break print(count) continue ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var count : int := 0 ; while true do ( if n = 1 then ( break ) else skip ; if n mod 2 = 0 then ( n := ("" + ((n / 2)))->toInteger() ; count := count + 1 ; continue ) else skip ; if n mod 2 = 1 then ( n := ("" + ((3 * n + 1)))->toInteger() ; count := count + 1 ; continue ) else skip ; if n = 1 then ( break ) else skip) ; execute (count)->display() ; continue); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import* from decimal import* import sys def _input(): return map(int,input().split()) def _lst(): return list(map(int,input().split())) def _int(): return int(input()) a=[0]*10001 def solves(): x,y,z=_input() if(x>y and y+zselect( $x | ($x - i * 2) mod i = 0 ) do ( a[j+1] := 1) ) else skip) ; for _anon : Integer.subrange(0, t-1) do ( solves()); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation _lst() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation _int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation solves() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := _input() ; if ((x->compareTo(y)) > 0 & (y + z->compareTo(x)) < 0) then ( execute ('+')->display() ) else (if ((x->compareTo(y)) < 0 & (x + z->compareTo(y)) < 0) then ( execute ('-')->display() ) else (if x = y & x + z = y & y + z = x then ( execute (0)->display() ) else ( execute ("?")->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): linea=input() a,b,c=linea.split(' ') a=int(a) b=int(b) c=int(c) if not a and not b and not c : print(0) return if not c and a==b : print(0) return if a>b+c : print('+') else : if b>a+c : print('-') else : print('?') main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var linea : String := (OclFile["System.in"]).readLine() ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := linea.split(' ') ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; var c : int := ("" + ((c)))->toInteger() ; if not(a) & not(b) & not(c) then ( execute (0)->display() ; return ) else skip ; if not(c) & a = b then ( execute (0)->display() ; return ) else skip ; if (a->compareTo(b + c)) > 0 then ( execute ('+')->display() ) else ( if (b->compareTo(a + c)) > 0 then ( execute ('-')->display() ) else ( execute ('?')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y,z=map(int,input().split()) if x==y and z==0 : print(0) elif x==y and z!=0 : print('?') elif x>y and z==0 : print('+') elif x>y and z!=0 : if y+z>=x : print('?') else : print('+') elif x=y : print('?') else : print('-') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x = y & z = 0 then ( execute (0)->display() ) else (if x = y & z /= 0 then ( execute ('?')->display() ) else (if (x->compareTo(y)) > 0 & z = 0 then ( execute ('+')->display() ) else (if (x->compareTo(y)) > 0 & z /= 0 then ( if (y + z->compareTo(x)) >= 0 then ( execute ('?')->display() ) else ( execute ('+')->display() ) ) else (if (x->compareTo(y)) < 0 & z = 0 then ( execute ('-')->display() ) else (if (x->compareTo(y)) < 0 & z /= 0 then ( if (x + z->compareTo(y)) >= 0 then ( execute ('?')->display() ) else ( execute ('-')->display() ) ) else skip ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=sorted([int(i)for i in input().split()]) sum=a[-1] neg=0 for i in range(1,n): val=neg+i*(a[i]-a[i-1]) sum-=val neg=val print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))->sort() ; var sum : OclAny := a->last() ; var neg : int := 0 ; for i : Integer.subrange(1, n-1) do ( var val : int := neg + i * (a[i+1] - a[i - 1+1]) ; sum := sum - val ; neg := val) ; execute (sum)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y,z=map(int,input().split()) c=z+abs(x-y)and '?' print(f'{c}+-'[(x>y+z)+2*(y>x+z)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : boolean := z + (x - y)->abs() & '?' ; execute (StringLib.formattedString('{c}+-')->select(((x->compareTo(y + z)) > 0) + 2 * ((y->compareTo(x + z)) > 0)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline x,y,z=map(int,input().split()) if x+z>y and x>y+z : ans="+" elif x+zcollect( _x | (OclType["int"])->apply(_x) ) ; if (x + z->compareTo(y)) > 0 & (x->compareTo(y + z)) > 0 then ( var ans : String := "+" ) else (if (x + z->compareTo(y)) < 0 & (x->compareTo(y + z)) < 0 then ( ans := "-" ) else (if x + z = y & x = y + z then ( ans := "0" ) else ( ans := "?" ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re for i in range(int(input())): s=input().replace("","") print(re.sub(r'0.','',''.join([i+j for(i,j)in zip(str(10000+eval('+'.join([i[0]+{'m' : '*1000','c' : '*100','x' : '*10','i' : ''}[i[1]]for i in['1'+i for i in ''.join(re.split(r'\d\w',s))]+re.findall(r'\d\w',s)])))[1 :],list('mcxi'))]).replace('1',''))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : OclAny := input().replace("", "") ; execute ((''.join(Integer.subrange(1, OclType["String"](10000 + null)->tail()->size())->collect( _indx | Sequence{OclType["String"](10000 + null)->tail()->at(_indx), ('mcxi')->characters()->at(_indx)} )->select(Sequence{i, j} | true)->collect(Sequence{i, j} | (i + j))).replace('1', '')).replaceAllMatches(StringLib.rawString('0.'), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def match_words(dictionary,sentence,n,m): mp=dict() for i in range(n): mp[dictionary[i]]=mp.get(dictionary[i],0)+1 for i in range(m): if(mp[sentence[i]]): mp[sentence[i]]-=1 else : return False return True dictionary=["find","a","geeks","all","for","on","geeks","answers","inter"] n=len(dictionary) sentence=["find","all","answers","on","geeks","for","geeks"] m=len(sentence) if(match_words(dictionary,sentence,n,m)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; dictionary := Sequence{"find"}->union(Sequence{"a"}->union(Sequence{"geeks"}->union(Sequence{"all"}->union(Sequence{"for"}->union(Sequence{"on"}->union(Sequence{"geeks"}->union(Sequence{"answers"}->union(Sequence{ "inter" })))))))) ; n := (dictionary)->size() ; sentence := Sequence{"find"}->union(Sequence{"all"}->union(Sequence{"answers"}->union(Sequence{"on"}->union(Sequence{"geeks"}->union(Sequence{"for"}->union(Sequence{ "geeks" })))))) ; m := (sentence)->size() ; if (match_words(dictionary, sentence, n, m)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); operation match_words(dictionary : OclAny, sentence : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var mp : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( mp[dictionary[i+1]+1] := mp.get(dictionary[i+1], 0) + 1) ; for i : Integer.subrange(0, m-1) do ( if (mp[sentence[i+1]+1]) then ( mp[sentence[i+1]+1] := mp[sentence[i+1]+1] - 1 ) else ( return false )) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class LargerNumKey(str): def __lt__(x,y): return x+y>y+x class Solution : def largestNumber(self,nums): largest_num=''.join(sorted(map(str,nums),key=LargerNumKey)) return '0' if largest_num[0]=='0' else largest_num ------------------------------------------------------------ OCL File: --------- class LargerNumKey extends OclType["String"] { static operation newLargerNumKey() : LargerNumKey pre: true post: LargerNumKey->exists( _x | result = _x ); operation __lt__(x : OclAny , y : OclAny) : OclAny pre: true post: true activity: return (x + y->compareTo(y + x)) > 0; } class Solution { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation largestNumber(nums : OclAny) : OclAny pre: true post: true activity: var largest_num : String := StringLib.sumStringsWithSeparator(((nums)->collect( _x | (OclType["String"])->apply(_x) )->sortedBy($x | (LargerNumKey)->apply($x))), '') ; return if largest_num->first() = '0' then '0' else largest_num endif; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- PI=3.14159265 def area_cicumscribed(c): return(c*c*(PI/4)) c=8.0 print(area_cicumscribed(c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var PI : double := 3.14159265 ; skip ; c := 8.0 ; execute (area_cicumscribed(c))->display(); operation area_cicumscribed(c : OclAny) : OclAny pre: true post: true activity: return (c * c * (PI / 4)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isValidSeq(a,n): nodes=n+2 ; for i in range(n): if(a[i]<1 or a[i]>nodes): return False ; return True ; if __name__=="__main__" : a=[4,1,3,4]; n=len(a); if(isValidSeq(a,n)): print("Valid"); else : print("Invalid"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{4}->union(Sequence{1}->union(Sequence{3}->union(Sequence{ 4 }))); ; n := (a)->size(); ; if (isValidSeq(a, n)) then ( execute ("Valid")->display(); ) else ( execute ("Invalid")->display(); ) ) else skip; operation isValidSeq(a : OclAny, n : OclAny) pre: true post: true activity: var nodes : OclAny := n + 2; ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] < 1 or (a[i+1]->compareTo(nodes)) > 0) then ( return false; ) else skip) ; return true;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minMaxValues(arr,n,m): sum=0 INF=1000000000 MAX=50 for i in range(0,(n+m)): sum+=arr[i] arr[i]+=50 dp=[[0 for x in range(MAX*MAX+1)]for y in range(MAX+1)] dp[0][0]=1 for i in range(0,(n+m)): for k in range(min(n,i+1),0,-1): for j in range(0,MAX*MAX+1): if(dp[k-1][j]): dp[k][j+arr[i]]=1 max_value=-1*INF min_value=INF for i in range(0,MAX*MAX+1): if(dp[n][i]): temp=i-50*n max_value=max(max_value,temp*(sum-temp)) min_value=min(min_value,temp*(sum-temp)) print("Maximum Value:{}\nMinimum Value:{}".format(max_value,min_value)) n=2 m=2 arr=[1,2,3,4] minMaxValues(arr,n,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 2 ; m := 2 ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))) ; minMaxValues(arr, n, m); operation minMaxValues(arr : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: var sum : int := 0 ; var INF : int := 1000000000 ; var MAX : int := 50 ; for i : Integer.subrange(0, (n + m)-1) do ( sum := sum + arr[i+1] ; arr[i+1] := arr[i+1] + 50) ; var dp : Sequence := Integer.subrange(0, MAX + 1-1)->select(y | true)->collect(y | (Integer.subrange(0, MAX * MAX + 1-1)->select(x | true)->collect(x | (0)))) ; dp->first()->first() := 1 ; for i : Integer.subrange(0, (n + m)-1) do ( for k : Integer.subrange(0 + 1, Set{n, i + 1}->min())->reverse() do ( for j : Integer.subrange(0, MAX * MAX + 1-1) do ( if (dp[k - 1+1][j+1]) then ( dp[k+1][j + arr[i+1]+1] := 1 ) else skip))) ; var max_value : int := -1 * INF ; var min_value : int := INF ; for i : Integer.subrange(0, MAX * MAX + 1-1) do ( if (dp[n+1][i+1]) then ( var temp : double := i - 50 * n ; max_value := Set{max_value, temp * (sum - temp)}->max() ; min_value := Set{min_value, temp * (sum - temp)}->min() ) else skip) ; execute (StringLib.interpolateStrings("Maximum Value:{}\nMinimum Value:{}", Sequence{max_value, min_value}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reverse(k): s=[] token=k.split() for word in token : s.append(word); while(len(s)): print(s.pop(),end=" "); if __name__=="__main__" : k="geeks for geeks" ; reverse(k); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( k := "geeks for geeks"; ; reverse(k); ) else skip; operation reverse(k : OclAny) pre: true post: true activity: var s : Sequence := Sequence{} ; var token : OclAny := k.split() ; for word : token do ( execute ((word) : s);) ; while ((s)->size()) do ( execute (s->last())->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def divisorSum(n): sum=0 for i in range(1,n+1): j=1 while j*j<=i : if i % j==0 : if i/j==j : sum+=j else : sum+=j+i/j j=j+1 return int(sum) n=4 print(divisorSum(n)) n=5 print(divisorSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute (divisorSum(n))->display() ; n := 5 ; execute (divisorSum(n))->display(); operation divisorSum(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( var j : int := 1 ; while (j * j->compareTo(i)) <= 0 do ( if i mod j = 0 then ( if i / j = j then ( sum := sum + j ) else ( sum := sum + j + i / j ) ) else skip ; j := j + 1)) ; return ("" + ((sum)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math t=int(input()) for i in range(0,t): n,k=input().split(" ") n=int(n) k=int(k) time=len(bin(k)[2 :]) if(n==1): print(0) elif(k==1): print(n-1) elif(n==2**(time-1)): print(time-1) elif n<=2**(time): print(time) else : if((n-2**time)% k)!=0 : print(time+(-1*(n-2**time)//k*-1)) else : print(time+(-1*(n-2**time)//k*-1)) 2 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split(" ") ; var n : int := ("" + ((n)))->toInteger() ; var k : int := ("" + ((k)))->toInteger() ; var time : int := (bin(k).subrange(2+1))->size() ; if (n = 1) then ( execute (0)->display() ) else (if (k = 1) then ( execute (n - 1)->display() ) else (if (n = (2)->pow((time - 1))) then ( execute (time - 1)->display() ) else (if (n->compareTo((2)->pow((time)))) <= 0 then ( execute (time)->display() ) else ( if ((n - (2)->pow(time)) mod k) /= 0 then ( execute (time + (-1 * (n - (2)->pow(time)) div k * -1))->display() ) else ( execute (time + (-1 * (n - (2)->pow(time)) div k * -1))->display() ) ; ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ans(d): n=len(d) d.sort() a=d[n-1] for j in range(1,n+1): a+=d[j-1]*(n-2*j+1) return a t=int(input()) for i in range(t): input() print(ans(list(map(int,input().split())))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( input() ; execute (ans(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))->display()); operation ans(d : OclAny) : OclAny pre: true post: true activity: var n : int := (d)->size() ; d := d->sort() ; var a : OclAny := d[n - 1+1] ; for j : Integer.subrange(1, n + 1-1) do ( a := a + d[j - 1+1] * (n - 2 * j + 1)) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100 def allones(s,n): co=0 for i in s : co+=1 if i=='1' else 0 return co==n def findlength(arr,s,n,ind,st,dp): if ind>=n : return 0 if dp[ind][st]!=-1 : return dp[ind][st] if not st : dp[ind][st]=max(arr[ind]+findlength(arr,s,n,ind+1,1,dp),(findlength(arr,s,n,ind+1,0,dp))) else : dp[ind][st]=max(arr[ind]+findlength(arr,s,n,ind+1,1,dp),0) return dp[ind][st] def maxLen(s,n): if allones(s,n): return-1 arr=[0]*MAX for i in range(n): arr[i]=1 if s[i]=='0' else-1 dp=[[-1]*3 for _ in range(MAX)] return findlength(arr,s,n,0,0,dp) s="11000010001" n=11 print(maxLen(s,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 100 ; skip ; skip ; skip ; s := "11000010001" ; n := 11 ; execute (maxLen(s, n))->display(); operation allones(s : OclAny, n : OclAny) : OclAny pre: true post: true activity: var co : int := 0 ; for i : s do ( co := co + if i = '1' then 1 else 0 endif) ; return co = n; operation findlength(arr : OclAny, s : OclAny, n : OclAny, ind : OclAny, st : OclAny, dp : OclAny) : OclAny pre: true post: true activity: if (ind->compareTo(n)) >= 0 then ( return 0 ) else skip ; if dp[ind+1][st+1] /= -1 then ( return dp[ind+1][st+1] ) else skip ; if not(st) then ( dp[ind+1][st+1] := Set{arr[ind+1] + findlength(arr, s, n, ind + 1, 1, dp), (findlength(arr, s, n, ind + 1, 0, dp))}->max() ) else ( dp[ind+1][st+1] := Set{arr[ind+1] + findlength(arr, s, n, ind + 1, 1, dp), 0}->max() ) ; return dp[ind+1][st+1]; operation maxLen(s : OclAny, n : OclAny) : OclAny pre: true post: true activity: if allones(s, n) then ( return -1 ) else skip ; arr := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX) ; for i : Integer.subrange(0, n-1) do ( arr[i+1] := if s[i+1] = '0' then 1 else -1 endif) ; dp := Integer.subrange(0, MAX-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ -1 }, 3))) ; return findlength(arr, s, n, 0, 0, dp); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import functools as ft prime=[0 for i in range(100001)] def SieveOfEratosthenes(): prime[0]=0 prime[1]=0 for p in range(2,100002): if p*p>100001 : break if(prime[p]==0): prime[p]+=1 for i in range(2*p,100001,p): prime[i]+=1 def sortArr(arr,n): v=[] for i in range(n): v.append([arr[i],prime[arr[i]]]) v.sort(key=lambda x : x[1]) for i in range(n): print(v[i][0],end=" ") print() SieveOfEratosthenes() arr=[30,2,1024,210,3,6] n=len(arr) sortArr(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var prime : Sequence := Integer.subrange(0, 100001-1)->select(i | true)->collect(i | (0)) ; skip ; skip ; SieveOfEratosthenes() ; arr := Sequence{30}->union(Sequence{2}->union(Sequence{1024}->union(Sequence{210}->union(Sequence{3}->union(Sequence{ 6 }))))) ; n := (arr)->size() ; sortArr(arr, n); operation SieveOfEratosthenes() pre: true post: true activity: prime->first() := 0 ; prime[1+1] := 0 ; for p : Integer.subrange(2, 100002-1) do ( if p * p > 100001 then ( break ) else skip ; if (prime[p+1] = 0) then ( prime[p+1] := prime[p+1] + 1 ; for i : Integer.subrange(2 * p, 100001-1)->select( $x | ($x - 2 * p) mod p = 0 ) do ( prime[i+1] := prime[i+1] + 1) ) else skip); operation sortArr(arr : OclAny, n : OclAny) pre: true post: true activity: var v : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((Sequence{arr[i+1]}->union(Sequence{ prime[arr[i+1]+1] })) : v)) ; v := v->sort() ; for i : Integer.subrange(0, n-1) do ( execute (v[i+1]->first())->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSum(N): ans=0 for i in range(1,N+1): for j in range(1,N+1): ans+=i//j return ans N=2 print(findSum(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 2 ; execute (findSum(N))->display(); operation findSum(N : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(1, N + 1-1) do ( for j : Integer.subrange(1, N + 1-1) do ( ans := ans + i div j)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re ;[print(re.sub(r'0.','',''.join([str(10000+sum([eval(i[0]+'0'*'ixcm'.find(i[1]))for i in['1'+i for i in ''.join(re.split(r'\d\w',s))]+re.findall(r'\d\w',s)]))[i]+'1mcxi'[i]for i in range(5)]).replace('1','')))for s in[input().replace("","")for i in range(int(input()))]] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def nonPrimeSum(arr,n): max_val=max(arr) prime=[True]*(max_val+1) prime[0]=False prime[1]=False for p in range(2,int(sqrt(max_val))+1): if(prime[p]==True): for i in range(p*2,max_val+1,p): prime[i]=False sum=0 for i in range(0,n): if(not prime[arr[i]]): sum+=arr[i] return sum if __name__=="__main__" : arr=[1,3,7,4,9,8] n=len(arr) print(nonPrimeSum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{3}->union(Sequence{7}->union(Sequence{4}->union(Sequence{9}->union(Sequence{ 8 }))))) ; n := (arr)->size() ; execute (nonPrimeSum(arr, n))->display() ) else skip; operation nonPrimeSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var max_val : OclAny := (arr)->max() ; var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (max_val + 1)) ; prime->first() := false ; prime[1+1] := false ; for p : Integer.subrange(2, ("" + ((sqrt(max_val))))->toInteger() + 1-1) do ( if (prime[p+1] = true) then ( for i : Integer.subrange(p * 2, max_val + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip) ; var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (not(prime[arr[i+1]+1])) then ( sum := sum + arr[i+1] ) else skip) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def interchangeFirstLast(mat,n,m): rows=n for i in range(n): t=mat[0][i] mat[0][i]=mat[rows-1][i] mat[rows-1][i]=t mat=[[8,9,7,6],[4,7,6,5],[3,2,1,8],[9,9,7,7]] n=4 m=4 interchangeFirstLast(mat,n,m) for i in range(n): for j in range(m): print(mat[i][j],end=" ") print("\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; mat := Sequence{Sequence{8}->union(Sequence{9}->union(Sequence{7}->union(Sequence{ 6 })))}->union(Sequence{Sequence{4}->union(Sequence{7}->union(Sequence{6}->union(Sequence{ 5 })))}->union(Sequence{Sequence{3}->union(Sequence{2}->union(Sequence{1}->union(Sequence{ 8 })))}->union(Sequence{ Sequence{9}->union(Sequence{9}->union(Sequence{7}->union(Sequence{ 7 }))) }))) ; n := 4 ; m := 4 ; interchangeFirstLast(mat, n, m) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( execute (mat[i+1][j+1])->display()) ; execute ("\n")->display()); operation interchangeFirstLast(mat : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: var rows : OclAny := n ; for i : Integer.subrange(0, n-1) do ( var t : OclAny := mat->first()[i+1] ; mat->first()[i+1] := mat[rows - 1+1][i+1] ; mat[rows - 1+1][i+1] := t); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) d=e=-(-b//a)*a c=0 while d>=b : d-=b c+=1 while d>=a : d-=a c+=1 c+=d if c>e//a : print(e) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : OclAny := -(-b div a) * a; var e : double := -(-b div a) * a ; var c : int := 0 ; while (d->compareTo(b)) >= 0 do ( d := d - b ; c := c + 1) ; while (d->compareTo(a)) >= 0 do ( d := d - a ; c := c + 1) ; c := c + d ; if (c->compareTo(e div a)) > 0 then ( execute (e)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from operator import itemgetter from fractions import gcd from math import ceil,floor,sqrt from copy import deepcopy from collections import Counter,deque import heapq from functools import reduce sys.setrecursionlimit(200000) input=sys.stdin.readline def ii(): return int(input()) def mi(): return map(int,input().rstrip().split()) def lmi(): return list(map(int,input().rstrip().split())) def li(): return list(input().rstrip()) def debug(*args,sep=" ",end="\n"): print("debug:",*args,file=sys.stderr,sep=sep,end=end)if not __debug__ else None def exit(*arg): print(*arg); sys.exit() def main(): A,B=mi() if B>(A-1)**2 : print(-1) sys.exit() if B %(A-1)==0 : print(A*ceil(B/A)) else : a=B//(A-1) b=B %(A-1) if atoInteger(); operation mi() : OclAny pre: true post: true activity: return (input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ); operation lmi() : OclAny pre: true post: true activity: return ((input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )); operation li() : OclAny pre: true post: true activity: return (input().rstrip()); operation debug(args : OclAny : Sequence(OclAny), sep : String, end : String) pre: true post: true activity: (args * (named_parameter (name args))) if sep->oclIsUndefined() then sep := " " else skip; if end->oclIsUndefined() then end := "\n" else skip; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "debug:")))))) , (argument * (test (logical_test (comparison (expr (atom (name args))))))) , (argument (test (logical_test (comparison (expr (atom (name file)))))) = (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stderr))))))) , (argument (test (logical_test (comparison (expr (atom (name sep)))))) = (test (logical_test (comparison (expr (atom (name sep))))))) , (argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom (name end)))))))) )))))) if (logical_test not (logical_test (comparison (expr (atom (name __debug__)))))) else (test (logical_test (comparison (expr (atom None)))))); operation exit(arg : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name arg))) execute ((argument * (test (logical_test (comparison (expr (atom (name arg))))))))->display(); sys.exit(); operation main() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := mi() ; if (B->compareTo(((A - 1))->pow(2))) > 0 then ( execute (-1)->display() ; sys.exit() ) else skip ; if B mod (A - 1) = 0 then ( execute (A * ceil(B / A))->display() ) else ( var a : int := B div (A - 1) ; var b : int := B mod (A - 1) ; if (a->compareTo(b)) < 0 then ( execute (A * ceil(B / A))->display() ) else ( execute (-1)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil,floor A,B=map(int,input().split()) ans=10**10 for b in range(1,A+1): a=ceil(b*B/A) c=a*A-b*B if b+c>a>0 : ans=min(ans,a*A) if ans==10**10 : ans=-1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : double := (10)->pow(10) ; for b : Integer.subrange(1, A + 1-1) do ( var a : OclAny := ceil(b * B / A) ; var c : double := a * A - b * B ; if (b + c->compareTo(a)) > 0 & (a > 0) then ( ans := Set{ans, a * A}->min() ) else skip) ; if ans = (10)->pow(10) then ( ans := -1 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def inpl(): return list(map(int,input().split())) A,B=inpl() def calca(x): return x//A+x % A X=-(-B//A)*A Y=calca(X-X//B*B)+X//B if-(-B//A)compareTo(Y)) < 0 then ( execute (X)->display() ) else ( execute (-1)->display() ); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation calca(x : OclAny) : OclAny pre: true post: true activity: return x div A + x mod A; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for g in range(int(input())): n=int(input()); l=sorted(list(map(int,input().split()))); f=0 ; k=0 for i in range(2,n): k+=l[i-2]; f-=(l[i]*(i-1)); f+=k print(f) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for g : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort(); var f : int := 0; var k : int := 0 ; for i : Integer.subrange(2, n-1) do ( k := k + l[i - 2+1]; f := f - (l[i+1] * (i - 1)); f := f + k) ; execute (f)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): a,b=map(int,input().split()) if max((b-1+a-2)//(a-1),(b+a-1)//a)<(a+b)/a : print(max((b-1+a-2)//(a-1),(b+a-1)//a)*a) else : print(-1) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (Set{(b - 1 + a - 2) div (a - 1), (b + a - 1) div a}->max()->compareTo((a + b) / a)) < 0 then ( execute (Set{(b - 1 + a - 2) div (a - 1), (b + a - 1) div a}->max() * a)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution : def isOneBitCharacter(self,bits : List[int])->bool : pos=0 while posexists( _x | result = _x ); operation isOneBitCharacter(bits : List[OclType["int"]+1]) : boolean pre: true post: true activity: var pos : int := 0 ; while (pos->compareTo((bits)->size() - 1)) < 0 do ( pos := pos + bits[pos+1] + 1) ; return pos = (bits)->size() - 1; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(low,high,T): while low<=high : mid=int((low+high)/2) if(mid*(mid+1))==T : return mid if(mid>0 and(mid*(mid+1))>T and(mid*(mid-1))<=T): return mid-1 if(mid*(mid+1))>T : high=mid-1 ; else : low=mid+1 return-1 T=15 ans=solve(1,T,2*T) if ans!=-1 : ans-=1 print("Number of stair steps=",ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; T := 15 ; var ans : OclAny := solve(1, T, 2 * T) ; if ans /= -1 then ( ans := ans - 1 ) else skip ; execute ("Number of stair steps=")->display(); operation solve(low : OclAny, high : OclAny, T : OclAny) : OclAny pre: true post: true activity: while (low->compareTo(high)) <= 0 do ( var mid : int := ("" + (((low + high) / 2)))->toInteger() ; if (mid * (mid + 1)) = T then ( return mid ) else skip ; if (mid > 0 & ((mid * (mid + 1))->compareTo(T)) > 0 & ((mid * (mid - 1))->compareTo(T)) <= 0) then ( return mid - 1 ) else skip ; if ((mid * (mid + 1))->compareTo(T)) > 0 then ( high := mid - 1; ) else ( low := mid + 1 )) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def MaximumHeight(a,n): result=1 for i in range(1,n): y=(i*(i+1))/2 if(yunion(Sequence{100}->union(Sequence{20}->union(Sequence{ 30 }))) ; n := (arr)->size() ; execute (MaximumHeight(arr, n))->display(); operation MaximumHeight(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var result : int := 1 ; for i : Integer.subrange(1, n-1) do ( var y : double := (i * (i + 1)) / 2 ; if ((y->compareTo(n)) < 0) then ( result := i ) else ( break )) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def m_i(l): stack=1 ans=0 l=list(l) for i in l : if i=='m' : ans+=stack*1000 stack=1 elif i=='c' : ans+=stack*100 stack=1 elif i=='x' : ans+=stack*10 stack=1 elif i=='i' : ans+=stack stack=1 else : stack=int(i) return ans def i_m(l): ans=[] a=l//1000 if a==1 : ans.append('m') elif a!=0 : ans.append(str(a)) ans.append('m') l-=a*1000 a=l//100 if a==1 : ans.append('c') elif a!=0 : ans.append(str(a)) ans.append('c') l-=a*100 a=l//10 if a==1 : ans.append('x') elif a!=0 : ans.append(str(a)) ans.append('x') a=l-a*10 if a==1 : ans.append('i') elif a!=0 : ans.append(str(a)) ans.append('i') ans=''.join(ans) return ans n=int(input()) for i in range(n): a,b=input().split() ans=m_i(a)+m_i(b) print(i_m(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var b : OclAny := null; Sequence{a,b} := input().split() ; ans := m_i(a) + m_i(b) ; execute (i_m(ans))->display()); operation m_i(l : OclAny) : OclAny pre: true post: true activity: var stack : int := 1 ; var ans : int := 0 ; l := (l) ; for i : l do ( if i = 'm' then ( ans := ans + stack * 1000 ; stack := 1 ) else (if i = 'c' then ( ans := ans + stack * 100 ; stack := 1 ) else (if i = 'x' then ( ans := ans + stack * 10 ; stack := 1 ) else (if i = 'i' then ( ans := ans + stack ; stack := 1 ) else ( stack := ("" + ((i)))->toInteger() ) ) ) ) ) ; return ans; operation i_m(l : OclAny) : OclAny pre: true post: true activity: ans := Sequence{} ; var a : int := l div 1000 ; if a = 1 then ( execute (('m') : ans) ) else (if a /= 0 then ( execute ((("" + ((a)))) : ans) ; execute (('m') : ans) ) else skip) ; l := l - a * 1000 ; a := l div 100 ; if a = 1 then ( execute (('c') : ans) ) else (if a /= 0 then ( execute ((("" + ((a)))) : ans) ; execute (('c') : ans) ) else skip) ; l := l - a * 100 ; a := l div 10 ; if a = 1 then ( execute (('x') : ans) ) else (if a /= 0 then ( execute ((("" + ((a)))) : ans) ; execute (('x') : ans) ) else skip) ; a := l - a * 10 ; if a = 1 then ( execute (('i') : ans) ) else (if a /= 0 then ( execute ((("" + ((a)))) : ans) ; execute (('i') : ans) ) else skip) ; ans := StringLib.sumStringsWithSeparator((ans), '') ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect class Bit : def __init__(self,n): self.size=n self.tree=[0]*(n+1) def sum(self,i): s=0 while i>0 : s+=self.tree[i] i-=i &-i return s def add(self,i,x): while i<=self.size : self.tree[i]+=x i+=i &-i N,D,A=map(int,input().split()) XH=sorted([list(map(int,input().split()))for _ in range(N)],key=lambda x : x[0]) X=[XH[i][0]for i in range(N)] X_right=[bisect.bisect_right(X,XH[i][0]+2*D)for i in range(N)] ans=0 bomb_damage=Bit(N+1) for i in range(N): damage=bomb_damage.sum(i+1) if XH[i][1]-damage>0 : n_bomb=-(-(XH[i][1]-damage)//A) ans+=n_bomb bomb_damage.add(i+1,n_bomb*A) bomb_damage.add(X_right[i]+1,-n_bomb*A) print(ans) ------------------------------------------------------------ OCL File: --------- class Bit { static operation newBit() : Bit pre: true post: Bit->exists( _x | result = _x ); attribute size : OclAny := n; attribute tree : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); operation initialise(n : OclAny) : Bit pre: true post: true activity: self.size := n ; self.tree := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); return self; operation sum(i : OclAny) : OclAny pre: true post: true activity: var s : int := 0 ; while i > 0 do ( s := s + self.tree[i+1] ; i := i - MathLib.bitwiseAnd(i, -i)) ; return s; operation add(i : OclAny,x : OclAny) pre: true post: true activity: while (i->compareTo(self.size)) <= 0 do ( self.tree[i+1] := self.tree[i+1] + x ; i := i + MathLib.bitwiseAnd(i, -i)); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := null; var D : OclAny := null; var A : OclAny := null; Sequence{N,D,A} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var XH : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))->sortedBy($x | (lambda x : OclAny in (x->first()))->apply($x)) ; var X : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (XH[i+1]->first())) ; var X_right : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (bisect.bisect_right(X, XH[i+1]->first() + 2 * D))) ; var ans : int := 0 ; var bomb_damage : Bit := (Bit.newBit()).initialise(N + 1) ; for i : Integer.subrange(0, N-1) do ( var damage : OclAny := bomb_damage.sum(i + 1) ; if XH[i+1][1+1] - damage > 0 then ( var n_bomb : int := -(-(XH[i+1][1+1] - damage) div A) ; ans := ans + n_bomb ; execute ((i + 1, n_bomb * A) : bomb_damage) ; execute ((X_right[i+1] + 1, -n_bomb * A) : bomb_damage) ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numba_compile(numba_config): import os,sys if sys.argv[-1]=="ONLINE_JUDGE" : from numba import njit from numba.pycc import CC cc=CC("my_module") for func,signature in numba_config : vars()[func.__name__]=njit(signature)(func) cc.export(func.__name__,signature)(func) cc.compile() exit() elif os.name=="posix" : exec(f"from my_module import{','.join(func.__name__ for func,_ in numba_config)}") for func,_ in numba_config : globals()[func.__name__]=vars()[func.__name__] else : from numba import njit for func,signature in numba_config : globals()[func.__name__]=njit(signature,cache=True)(func) print("compiled!",file=sys.stderr) import numpy as np def solve(N,D,A,XH): q=[] idx_q=0 I=XH[:,0].argsort() XH=XH[I] XH[:,1]=-(-XH[:,1]//A) d=0 ans=0 for i in range(N): x,h=XH[i] while idx_qunion(Sequence{ "i8(i8,i8,i8,i8[:,:])" }) }) ; skip ; skip ; main(); operation numba_compile(numba_config : OclAny) pre: true post: true activity: skip ; if (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) = "ONLINE_JUDGE" then ( skip ; skip ; var cc : OclAny := CC("my_module") ; for _tuple : numba_config do (var _indx : int := 1; var func : OclAny := _tuple->at(_indx); _indx := _indx + 1; var signature : OclAny := _tuple->at(_indx); vars()[func.__name__+1] := njit(signature)(func) ; (expr (atom (name cc)) (trailer . (name export) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name func)) (trailer . (name __name__))))))) , (argument (test (logical_test (comparison (expr (atom (name signature)))))))) ))) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name func)))))))) ))))) ; cc.compile() ; exit() ) else (if os.name = "posix" then ( ; for _tuple : numba_config do (var _indx : int := 1; var func : OclAny := _tuple->at(_indx); _indx := _indx + 1; var _anon : OclAny := _tuple->at(_indx); globals()[func.__name__+1] := vars()[func.__name__+1]) ) else ( skip ; for _tuple : numba_config do (var _indx : int := 1; var func : OclAny := _tuple->at(_indx); _indx := _indx + 1; var signature : OclAny := _tuple->at(_indx); globals()[func.__name__+1] := njit(signature, (argument (test (logical_test (comparison (expr (atom (name cache)))))) = (test (logical_test (comparison (expr (atom (name True))))))))(func)) ; execute ("compiled!")->display() ) ) ; operation solve(N : OclAny, D : OclAny, A : OclAny, XH : OclAny) : OclAny pre: true post: true activity: var q : Sequence := Sequence{} ; var idx_q : int := 0 ; var I : OclAny := XH->collect( _r | _r->first() ).argsort() ; XH := XH[I+1] ; XH->collect( _r | _r[1+1] ) := -(-XH->collect( _r | _r[1+1] ) div A) ; var d : int := 0 ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( var x : OclAny := null; var h : OclAny := null; Sequence{x,h} := XH[i+1] ; while (idx_q->compareTo((q)->size())) < 0 & (q[idx_q+1]->first()->compareTo(x)) <= 0 do ( d := d - q[idx_q+1][1+1] ; idx_q := idx_q + 1) ; if (d->compareTo(h)) < 0 then ( execute ((Sequence{x + D * 2 + 1, h - d}) : q) ; ans := ans + h - d ; d := h ) else skip) ; return ans; operation main() pre: true post: true activity: Sequence{N,D,A} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; XH := np.array(sys.stdin.readAll().split(), (argument (test (logical_test (comparison (expr (atom (name dtype)))))) = (test (logical_test (comparison (expr (atom (name np)) (trailer . (name int64)))))))).reshape(N, 2) ; ans := solve(N, D, A, XH) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import* import heapq import math import bisect from itertools import permutations,accumulate,combinations,product from fractions import gcd def input(): return sys.stdin.readline()[:-1] mod=10**9+7 n,d,a=map(int,input().split()) xh=[list(map(int,input().split()))for i in range(n)] xh.sort() r,tama=[float('inf')]*n,[0]*(n+1) for i in range(n): x,h=xh[i] tmpr=bisect.bisect_left(r,x) h-=(tama[i]-tama[tmpr])*a tmp=0 if h>0 : tmp=math.ceil(h/a) tama[i+1]=tmp tama[i+1]+=tama[i] r[i]=x+2*d print(tama[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; var n : OclAny := null; var d : OclAny := null; var a : OclAny := null; Sequence{n,d,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var xh : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; xh := xh->sort() ; var r : OclAny := null; var tama : OclAny := null; Sequence{r,tama} := Sequence{MatrixLib.elementwiseMult(Sequence{ ("" + (('inf')))->toReal() }, n),MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1))} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var h : OclAny := null; Sequence{x,h} := xh[i+1] ; var tmpr : OclAny := bisect.bisect_left(r, x) ; h := h - (tama[i+1] - tama[tmpr+1]) * a ; var tmp : int := 0 ; if h > 0 then ( tmp := (h / a)->ceil() ) else skip ; tama[i + 1+1] := tmp ; tama[i + 1+1] := tama[i + 1+1] + tama[i+1] ; r[i+1] := x + 2 * d) ; execute (tama->last())->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np i8=np.int64 def solve(X,H,D): xi=np.empty_like(X) hi=np.empty_like(H) p=0 N=X.shape[0] for i in range(1,N): if X[i]>X[i-1]: xi[p]=X[i-1] hi[p]=H[i-1] p+=1 xi[p]=X[N-1] hi[p]=H[N-1] p+=1 area=2*D res=0 sum_right=0 sum_left=0 left=0 for i in range(p): while xi[i]-xi[left]>area : sum_left+=hi[left] left+=1 x=hi[i]-(sum_right-sum_left) if x>0 : res+=x sum_right+=x hi[i]=x else : hi[i]=0 return res def main(X,H,D,A): arg=np.lexsort((H,X)) X=X[arg] H=H[arg] H=(H-1)//A+1 print(solve(X,H,D)) if __name__=='__main__' : stdin=np.fromstring(open(0).read(),np.int64,sep=' ') N,D,A=stdin[: 3] XH=stdin[3 :].reshape((-1,2)).T ans=main(XH[0],XH[1],D,A) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var i8 : (trailer . (name int64)) := ; skip ; skip ; if __name__ = '__main__' then ( var stdin : Sequence := ; Sequence{N,D,A} := stdin.subrange(1,3) ; var XH : OclAny := stdin.subrange(3+1).reshape(Sequence{-1, 2}).T ; var ans : OclAny := main(XH->first(), XH[1+1], D, A) ) else skip; operation solve(X : OclAny, H : OclAny, D : OclAny) : OclAny pre: true post: true activity: var xi : Sequence := MatrixLib.singleValueMatrix(MatrixLib.shape(X), 0.0) ; var hi : Sequence := MatrixLib.singleValueMatrix(MatrixLib.shape(H), 0.0) ; var p : int := 0 ; var N : OclAny := X.shape->first() ; for i : Integer.subrange(1, N-1) do ( if (X[i+1]->compareTo(X[i - 1+1])) > 0 then ( xi[p+1] := X[i - 1+1] ; hi[p+1] := H[i - 1+1] ; p := p + 1 ) else skip) ; xi[p+1] := X[N - 1+1] ; hi[p+1] := H[N - 1+1] ; p := p + 1 ; var area : double := 2 * D ; var res : int := 0 ; var sum_right : int := 0 ; var sum_left : int := 0 ; var left : int := 0 ; for i : Integer.subrange(0, p-1) do ( while (xi[i+1] - xi[left+1]->compareTo(area)) > 0 do ( sum_left := sum_left + hi[left+1] ; left := left + 1) ; var x : double := hi[i+1] - (sum_right - sum_left) ; if x > 0 then ( res := res + x ; sum_right := sum_right + x ; hi[i+1] := x ) else ( hi[i+1] := 0 )) ; return res; operation main(X : OclAny, H : OclAny, D : OclAny, A : OclAny) pre: true post: true activity: var arg : (trailer . (name lexsort) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name H)))))) , (test (logical_test (comparison (expr (atom (name X))))))) )))))))) ))) := ; X := X[arg+1] ; H := H[arg+1] ; H := (H - 1) div A + 1 ; execute (solve(X, H, D))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heappush,heappop n,d,a=map(int,input().split()) actions=[] for _ in range(n): x,h=map(int,input().split()) heappush(actions,(x,0,(h+a-1)//a)) cnt=0 bomb=0 current_bomb=0 while cntcollect( _x | (OclType["int"])->apply(_x) ) ; var actions : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var h : OclAny := null; Sequence{x,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; heappush(actions, Sequence{x, 0, (h + a - 1) div a})) ; var cnt : int := 0 ; var bomb : int := 0 ; var current_bomb : int := 0 ; while (cnt->compareTo(n)) < 0 do ( var a : OclAny := null; var c : OclAny := null; var b : OclAny := null; Sequence{a,c,b} := heappop(actions) ; if c then ( current_bomb := current_bomb - b ; continue ) else ( var HP : OclAny := b ; if (HP->compareTo(current_bomb)) <= 0 then ( cnt := cnt + 1 ; continue ) else ( HP := HP - current_bomb ; cnt := cnt + 1 ; current_bomb := current_bomb + HP ; bomb := bomb + HP ; heappush(actions, Sequence{a + 2 * d, 1, HP}) ) )) ; execute (bomb)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for g in range(int(input())): n=int(input()); l=sorted(list(map(int,input().split()))); f=0 ; k=0 for i in range(2,n): k+=l[i-2]; f-=(l[i]*(i-1)); f+=k print(f) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for g : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort(); var f : int := 0; var k : int := 0 ; for i : Integer.subrange(2, n-1) do ( k := k + l[i - 2+1]; f := f - (l[i+1] * (i - 1)); f := f + k) ; execute (f)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def sumOfLeftLeaves(self,root): stack=[root] res=0 while len(stack)>0 : curr=stack.pop(0) if curr is not None : if curr.left is not None : if curr.left.left is None and curr.left.right is None : res+=curr.left.val stack.insert(0,curr.right) stack.insert(0,curr.left) return res ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation sumOfLeftLeaves(root : OclAny) : OclAny pre: true post: true activity: var stack : Sequence := Sequence{ root } ; var res : int := 0 ; while (stack)->size() > 0 do ( var curr : OclAny := stack->at(0`firstArg+1) ; stack := stack->excludingAt(0+1) ; if not(curr <>= null) then ( if not(curr.left <>= null) then ( if curr.left.left <>= null & curr.left.right <>= null then ( res := res + curr.left.val ) else skip ) else skip ; stack := stack.insertAt(0+1, curr.right) ; stack := stack.insertAt(0+1, curr.left) ) else skip) ; return res; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) s=sum(l) k=s % n print(k*(n-k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : OclAny := (l)->sum() ; var k : int := s mod n ; execute (k * (n - k))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=[int(i)for i in input().split()] s=sum(a) print(s % n*(n-s % n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var s : OclAny := (a)->sum() ; execute (s mod n * (n - s mod n))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(0,t): n=int(input()) a=input().split() c=[] for j in range(0,len(a)): c.append(int(a[j])) u=sum(c)% len(c) print(u*(len(c)-u)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := input().split() ; var c : Sequence := Sequence{} ; for j : Integer.subrange(0, (a)->size()-1) do ( execute ((("" + ((a[j+1])))->toInteger()) : c)) ; var u : int := (c)->sum() mod (c)->size() ; execute (u * ((c)->size() - u))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tests=int(input()) for test in range(tests): len=int(input()) a=input().split() sum=0 for i in a : sum+=int(i) r=sum % len print(r*(len-r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var tests : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for test : Integer.subrange(0, tests-1) do ( var len : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := input().split() ; var sum : int := 0 ; for i : a do ( sum := sum + ("" + ((i)))->toInteger()) ; var r : int := sum mod len ; execute (r * (len - r))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**5) def L(): return[x for x in input().split()] def LI(): return[int(x)for x in input().split()] def LF(): return[float(x)for x in input().split()] def LI_(): return[-1*int(x)for x in input().split()] def II(): return int(input()) def IF(): return float(input()) def LM(func,n): return[[func(x)for x in input().split()]for i in range(n)] mod=1000000007 inf=float('INF') dic={"m" : 1000,"c" : 100,"x" : 10,"i" : 1} def MCXI(S): ret=0 for d in "mcxi" : i=S.find(d) if i>=1 and "2"<=S[i-1]<="9" : ret+=int(S[i-1])*dic[d] elif i>=0 : ret+=dic[d] return ret def mcxi(n): S="" for d in "ixcm" : if n % 10==1 : S+=d elif n % 10>1 : S+=d S+=str(n % 10) n//=10 return S[: :-1] n=II() for i in range(n): a,b=L() a=MCXI(a) b=MCXI(b) print(mcxi(a+b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(5)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : int := 1000000007 ; var Math_PINFINITY : double := ("" + (('INF')))->toReal() ; var dic : Map := Map{ "m" |-> 1000 }->union(Map{ "c" |-> 100 }->union(Map{ "x" |-> 10 }->union(Map{ "i" |-> 1 }))) ; skip ; skip ; n := II() ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := L() ; var a : OclAny := MCXI(a) ; var b : OclAny := MCXI(b) ; execute (mcxi(a + b))->display()); operation L() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (x)); operation LI() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LF() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LI_() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (-1 * ("" + ((x)))->toInteger())); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation IF() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation LM(func : OclAny, n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (input().split()->select(x | true)->collect(x | (func(x))))); operation MCXI(S : OclAny) : OclAny pre: true post: true activity: var ret : int := 0 ; for d : "mcxi"->characters() do ( var i : int := S->indexOf(d) - 1 ; if i >= 1 & "2" <= S[i - 1+1] & (S[i - 1+1] <= "9") then ( ret := ret + ("" + ((S[i - 1+1])))->toInteger() * dic[d+1] ) else (if i >= 0 then ( ret := ret + dic[d+1] ) else skip)) ; return ret; operation mcxi(n : OclAny) : OclAny pre: true post: true activity: S := "" ; for d : "ixcm"->characters() do ( if n mod 10 = 1 then ( S := S + d ) else (if n mod 10 > 1 then ( S := S + d ; S := S + ("" + ((n mod 10))) ) else skip) ; n := n div 10) ; return S(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for i in range(T): n=int(input()) L=input().split() s=0 for j in range(n): s=s+int(L[j]) print((s % n)*((n)-(s % n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, T-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var L : OclAny := input().split() ; var s : int := 0 ; for j : Integer.subrange(0, n-1) do ( s := s + ("" + ((L[j+1])))->toInteger()) ; execute ((s mod n) * ((n) - (s mod n)))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) p=[] total=0 for i in range(N): p.append(int(input())) p=sorted(p) for i in range(N): total+=p[i] print(int(total-p[N-1]/2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := Sequence{} ; var total : int := 0 ; for i : Integer.subrange(0, N-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : p)) ; p := p->sort() ; for i : Integer.subrange(0, N-1) do ( total := total + p[i+1]) ; execute (("" + ((total - p[N - 1+1] / 2)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heappush,heappop class Solver(object): def __init__(self): self.n=int(input()) self.items=list() for _ in range(self.n): heappush(self.items,int(input())) def solve(self): total=0 for _ in range(self.n-1): total+=heappop(self.items) total+=heappop(self.items)/2 print(int(total)) if __name__=="__main__" : s=Solver() s.solve() ------------------------------------------------------------ OCL File: --------- class Solver extends object { static operation newSolver() : Solver pre: true post: Solver->exists( _x | result = _x ); attribute n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); attribute items : Sequence := (); operation initialise() : pre: true post: true activity: self.n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; self.items := () ; for _anon : Integer.subrange(0, self.n-1) do ( heappush(self.items, ("" + (((OclFile["System.in"]).readLine())))->toInteger())); return self; operation solve() pre: true post: true activity: var total : int := 0 ; for _anon : Integer.subrange(0, self.n - 1-1) do ( total := total + heappop(self.items)) ; total := total + heappop(self.items) / 2 ; execute (("" + ((total)))->toInteger())->display(); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var s : Solver := (Solver.newSolver()).initialise() ; s.solve() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.read readline=sys.stdin.buffer.readline INF=float('inf') def main(): N=int(readline()) total=0 maximum=0 for _ in range(N): p=int(readline()) total+=p maximum=max(maximum,p) ans=total-maximum//2 print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := (OclFile["System.in"]).read ; var readline : OclAny := sys.stdin.buffer.readline ; var INF : double := ("" + (('inf')))->toReal() ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : int := ("" + ((readline())))->toInteger() ; var total : int := 0 ; var maximum : int := 0 ; for _anon : Integer.subrange(0, N-1) do ( var p : int := ("" + ((readline())))->toInteger() ; total := total + p ; maximum := Set{maximum, p}->max()) ; var ans : double := total - maximum div 2 ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate def solve(): n=int(input()) *d,=map(int,input().split()) d.sort() ans=0 *prefix,=accumulate(d) for i in range(2,n): ans-=d[i]*(i-1)-prefix[i-2] print(ans) if __name__=="__main__" : for _ in range(int(input())): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; (testlist_star_expr (star_expr * (expr (atom (name d)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name d)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p=[int(input())for _ in range(int(input()))] print(sum(p)-max(p)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : Sequence := Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; execute ((p)->sum() - (p)->max() div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- banig=[] for x in range(int(input())): banig.append(int(input())) sum=0 big=max(banig) banig.remove(big) summation=0 for e in banig : summation+=e print(summation+int(big/2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var banig : Sequence := Sequence{} ; for x : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : banig)) ; var sum : int := 0 ; var big : OclAny := (banig)->max() ; execute ((big) /: banig) ; var summation : int := 0 ; for e : banig do ( summation := summation + e) ; execute (summation + ("" + ((big / 2)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getOddOccurrence(arr,size): Hash=dict() for i in range(size): Hash[arr[i]]=Hash.get(arr[i],0)+1 ; for i in Hash : if(Hash[i]% 2!=0): return i return-1 arr=[2,3,5,4,5,2,4,3,5,2,4,4,2] n=len(arr) print(getOddOccurrence(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{4}->union(Sequence{5}->union(Sequence{2}->union(Sequence{4}->union(Sequence{3}->union(Sequence{5}->union(Sequence{2}->union(Sequence{4}->union(Sequence{4}->union(Sequence{ 2 })))))))))))) ; var n : int := (arr)->size() ; execute (getOddOccurrence(arr, n))->display(); operation getOddOccurrence(arr : OclAny, size : OclAny) : OclAny pre: true post: true activity: var Hash : Map := (arguments ( )) ; for i : Integer.subrange(0, size-1) do ( Hash[arr[i+1]+1] := Hash.get(arr[i+1], 0) + 1;) ; for i : Hash->keys() do ( if (Hash[i+1] mod 2 /= 0) then ( return i ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfDigits(n): Sum=0 while(n!=0): Sum=Sum+n % 10 n=n//10 return Sum def countTheNumbers(l,r,y): count=0 for i in range(l,r+1): if(sumOfDigits(i)==y): count+=1 return count l,r,y=0,10,1 print(countTheNumbers(l,r,y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{l,r,y} := Sequence{0,10,1} ; execute (countTheNumbers(l, r, y))->display(); operation sumOfDigits(n : OclAny) : OclAny pre: true post: true activity: var Sum : int := 0 ; while (n /= 0) do ( Sum := Sum + n mod 10 ; n := n div 10) ; return Sum; operation countTheNumbers(l : OclAny, r : OclAny, y : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(l, r + 1-1) do ( if (sumOfDigits(i) = y) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a,b=map(int,input().split()) c=list(map(int,input().split())) c.sort() val=c[len(c)//2] ans=0 if b>val : for i in range(len(c)//2,len(c)): if b<=c[i]: break ans+=b-c[i] elif b=c[i]: break ans+=c[i]-b print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; c := c->sort() ; var val : OclAny := c[(c)->size() div 2+1] ; var ans : int := 0 ; if (b->compareTo(val)) > 0 then ( for i : Integer.subrange((c)->size() div 2, (c)->size()-1) do ( if (b->compareTo(c[i+1])) <= 0 then ( break ) else skip ; ans := ans + b - c[i+1]) ) else (if (b->compareTo(val)) < 0 then ( for i : Integer.subrange(-1 + 1, (c)->size() div 2)->reverse() do ( if (b->compareTo(c[i+1])) >= 0 then ( break ) else skip ; ans := ans + c[i+1] - b) ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,s=map(int,input().split()) a=list(map(int,input().split())) a.sort() c=0 if s==a[n//2]: print(0) elif ss : c+=a[i]-s print(c) elif s>a[n//2]: for i in range(n//2,n): if a[i]collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var c : int := 0 ; if s = a[n div 2+1] then ( execute (0)->display() ) else (if (s->compareTo(a[n div 2+1])) < 0 then ( for i : Integer.subrange(0, n div 2 + 1-1) do ( if (a[i+1]->compareTo(s)) > 0 then ( c := c + a[i+1] - s ) else skip) ; execute (c)->display() ) else (if (s->compareTo(a[n div 2+1])) > 0 then ( for i : Integer.subrange(n div 2, n-1) do ( if (a[i+1]->compareTo(s)) < 0 then ( c := c + s - a[i+1] ) else skip) ; execute (c)->display() ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get10(x): ans=0 alphabet={'m' : 1000,'c' : 100,'x' : 10,'i' : 1} i=0 while i0 : ans.append(str(temp)+'i') temp=temp//10 return ''.join(ans) n=int(input()) for _ in range(n): x,y=input().split(' ') temp=get10(x)+get10(y) print(getN(temp)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var y : OclAny := null; Sequence{x,y} := input().split(' ') ; temp := get10(x) + get10(y) ; execute (getN(temp))->display()); operation get10(x : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; var alphabet : Map := Map{ 'm' |-> 1000 }->union(Map{ 'c' |-> 100 }->union(Map{ 'x' |-> 10 }->union(Map{ 'i' |-> 1 }))) ; var i : int := 0 ; while (i->compareTo((x)->size())) < 0 do ( if not((alphabet)->includes(x[i+1])) then ( ans := ans + ("" + ((x[i+1])))->toInteger() * alphabet[x[i + 1+1]+1] ; i := i + 2 ) else (if (alphabet)->includes(x[i+1]) then ( ans := ans + alphabet[x[i+1]+1] ; i := i + 1 ) else skip)) ; return ans; operation getN(x : OclAny) : OclAny pre: true post: true activity: ans := Sequence{} ; var temp : OclAny := x ; while temp /= 0 do ( if temp div 1000 then ( if temp div 1000 = 1 then ( execute (('m') : ans) ) else ( execute ((("" + ((temp div 1000))) + 'm') : ans) ) ; temp := temp mod 1000 ) else (if temp div 100 then ( if temp div 100 = 1 then ( execute (('c') : ans) ) else ( execute ((("" + ((temp div 100))) + 'c') : ans) ) ; temp := temp mod 100 ) else (if temp div 10 then ( if temp div 10 = 1 then ( execute (('x') : ans) ) else ( execute ((("" + ((temp div 10))) + 'x') : ans) ) ; temp := temp mod 10 ) else ( if temp = 1 then ( execute (('i') : ans) ) else (if temp > 0 then ( execute ((("" + ((temp))) + 'i') : ans) ) else skip) ; temp := temp div 10 ) ) ) ) ; return StringLib.sumStringsWithSeparator((ans), ''); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout def main(): n,s=map(int,stdin.readline().split()) a=list(map(int,stdin.readline().split())) a.sort() operations=0 m=n//2 if a[m]=0 and a[m]>s : operations+=a[m]-s m-=1 stdout.write(str(operations)+"\n") main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var operations : int := 0 ; var m : int := n div 2 ; if (a[m+1]->compareTo(s)) < 0 then ( while (m->compareTo((a)->size())) < 0 & (a[m+1]->compareTo(s)) < 0 do ( operations := operations + s - a[m+1] ; m := m + 1) ) else ( while m >= 0 & (a[m+1]->compareTo(s)) > 0 do ( operations := operations + a[m+1] - s ; m := m - 1) ) ; stdout.write(("" + ((operations))) + "\n"); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil n,s=[int(i)for i in input().split()] a=sorted([int(i)for i in input().split()]) k=a[ceil(n/2)-1] ans=0 if s==k : ans=0 elif s>k : for i in range(n-1,-1,-1): if a[i]=k : ans+=abs(s-a[i]) if i==ceil(n/2)-1 : break else : for i in range(n): if a[i]>s and a[i]<=k : ans+=abs(s-a[i]) if i==ceil(n/2)-1 : break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))->sort() ; var k : OclAny := a[ceil(n / 2) - 1+1] ; var ans : int := 0 ; if s = k then ( ans := 0 ) else (if (s->compareTo(k)) > 0 then ( for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (a[i+1]->compareTo(s)) < 0 & (a[i+1]->compareTo(k)) >= 0 then ( ans := ans + (s - a[i+1])->abs() ) else skip ; if i = ceil(n / 2) - 1 then ( break ) else skip) ) else ( for i : Integer.subrange(0, n-1) do ( if (a[i+1]->compareTo(s)) > 0 & (a[i+1]->compareTo(k)) <= 0 then ( ans := ans + (s - a[i+1])->abs() ) else skip ; if i = ceil(n / 2) - 1 then ( break ) else skip) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : matrix=[[0 for i in range(5)]for j in range(5)] x,size=0,5 ; for row_index in range(size): for column_index in range(size): x+=1 ; matrix[row_index][column_index]=x ; print("The matrix is"); for row_index in range(size): for column_index in range(size): print(matrix[row_index][column_index],end="\t"); print(""); print("\nMain diagonal elements are:"); for row_index in range(size): for column_index in range(size): if(row_index==column_index): print(matrix[row_index][column_index],end="\t"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var matrix : Sequence := Integer.subrange(0, 5-1)->select(j | true)->collect(j | (Integer.subrange(0, 5-1)->select(i | true)->collect(i | (0)))) ; var x : OclAny := null; var size : OclAny := null; Sequence{x,size} := Sequence{0,5}; ; for row_index : Integer.subrange(0, size-1) do ( for column_index : Integer.subrange(0, size-1) do ( x := x + 1; ; matrix[row_index+1][column_index+1] := x;)) ; execute ("The matrix is")->display(); ; for row_index : Integer.subrange(0, size-1) do ( for column_index : Integer.subrange(0, size-1) do ( execute (matrix[row_index+1][column_index+1])->display();) ; execute ("")->display();) ; execute ("\nMain diagonal elements are:")->display(); ; for row_index : Integer.subrange(0, size-1) do ( for column_index : Integer.subrange(0, size-1) do ( if (row_index = column_index) then ( execute (matrix[row_index+1][column_index+1])->display(); ) else skip)) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys for s in sys.stdin : A=map(int,s.split()) x=20-A[0]-A[1] f=3 for e in A : if x=4] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for s : OclFile["System.in"] do ( var A : Sequence := (s.split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : double := 20 - A->first() - A[1+1] ; var f : int := 3 ; for e : A do ( if (x->compareTo(e)) < 0 then ( f := f - 1 ) else skip) ; (expr (atom print) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom "NO")))))) , (subscript (test (logical_test (comparison (expr (atom "YES"))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (comparison (expr (expr (atom (name x))) - (expr (atom (name f))))) >= (comparison (expr (atom (number (integer 4)))))))))) ])))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : matrix=[[0 for i in range(5)]for j in range(5)]; row_index,column_index,x,size=0,0,0,5 ; for row_index in range(size): for column_index in range(size): x+=1 ; matrix[row_index][column_index]=x ; print("The matrix is"); for row_index in range(size): for column_index in range(size): print(matrix[row_index][column_index],end="\t"); print(""); print("\nElements above Main diagonal elements are:"); for row_index in range(size): for column_index in range(size): if(row_indexselect(j | true)->collect(j | (Integer.subrange(0, 5-1)->select(i | true)->collect(i | (0)))); ; var row_index : OclAny := null; var column_index : OclAny := null; var x : OclAny := null; var size : OclAny := null; Sequence{row_index,column_index,x,size} := Sequence{0,0,0,5}; ; for row_index : Integer.subrange(0, size-1) do ( for column_index : Integer.subrange(0, size-1) do ( x := x + 1; ; matrix[row_index+1][column_index+1] := x;)) ; execute ("The matrix is")->display(); ; for row_index : Integer.subrange(0, size-1) do ( for column_index : Integer.subrange(0, size-1) do ( execute (matrix[row_index+1][column_index+1])->display();) ; execute ("")->display();) ; execute ("\nElements above Main diagonal elements are:")->display(); ; for row_index : Integer.subrange(0, size-1) do ( for column_index : Integer.subrange(0, size-1) do ( if ((row_index->compareTo(column_index)) < 0) then ( execute (matrix[row_index+1][column_index+1])->display(); ) else skip)) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : matrix=[[0 for i in range(5)]for j in range(5)] row_index,column_index,x,size=0,0,0,5 ; for row_index in range(size): for column_index in range(size): x+=1 ; matrix[row_index][column_index]=x ; print("The matrix is"); for row_index in range(size): for column_index in range(size): print(matrix[row_index][column_index],end="\t"); print(""); print("\nCorner Elements are:"); for row_index in range(size): for column_index in range(size): if((row_index==0 or row_index==size-1)and(column_index==0 or column_index==size-1)): print(matrix[row_index][column_index],end="\t"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var matrix : Sequence := Integer.subrange(0, 5-1)->select(j | true)->collect(j | (Integer.subrange(0, 5-1)->select(i | true)->collect(i | (0)))) ; var row_index : OclAny := null; var column_index : OclAny := null; var x : OclAny := null; var size : OclAny := null; Sequence{row_index,column_index,x,size} := Sequence{0,0,0,5}; ; for row_index : Integer.subrange(0, size-1) do ( for column_index : Integer.subrange(0, size-1) do ( x := x + 1; ; matrix[row_index+1][column_index+1] := x;)) ; execute ("The matrix is")->display(); ; for row_index : Integer.subrange(0, size-1) do ( for column_index : Integer.subrange(0, size-1) do ( execute (matrix[row_index+1][column_index+1])->display();) ; execute ("")->display();) ; execute ("\nCorner Elements are:")->display(); ; for row_index : Integer.subrange(0, size-1) do ( for column_index : Integer.subrange(0, size-1) do ( if ((row_index = 0 or row_index = size - 1) & (column_index = 0 or column_index = size - 1)) then ( execute (matrix[row_index+1][column_index+1])->display(); ) else skip)) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : matrix=[[0 for i in range(5)]for j in range(5)] row_index,column_index,x,size=0,0,0,5 ; for row_index in range(size): for column_index in range(size): x+=1 ; matrix[row_index][column_index]=x ; print("The matrix is"); for row_index in range(size): for column_index in range(size): print(matrix[row_index][column_index],end="\t"); print(""); print("\nElements below Secondary diagonal are:"); for row_index in range(size): for column_index in range(size): if((row_index+column_index)>size-1): print(matrix[row_index][column_index],end=","); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var matrix : Sequence := Integer.subrange(0, 5-1)->select(j | true)->collect(j | (Integer.subrange(0, 5-1)->select(i | true)->collect(i | (0)))) ) else skip ; var row_index : OclAny := null; var column_index : OclAny := null; var x : OclAny := null; var size : OclAny := null; Sequence{row_index,column_index,x,size} := Sequence{0,0,0,5}; ; for row_index : Integer.subrange(0, size-1) do ( for column_index : Integer.subrange(0, size-1) do ( x := x + 1; ; matrix[row_index+1][column_index+1] := x;)) ; execute ("The matrix is")->display(); ; for row_index : Integer.subrange(0, size-1) do ( for column_index : Integer.subrange(0, size-1) do ( execute (matrix[row_index+1][column_index+1])->display();) ; execute ("")->display();) ; execute ("\nElements below Secondary diagonal are:")->display(); ; for row_index : Integer.subrange(0, size-1) do ( for column_index : Integer.subrange(0, size-1) do ( if (((row_index + column_index)->compareTo(size - 1)) > 0) then ( execute (matrix[row_index+1][column_index+1])->display(); ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : matrix=[[0 for i in range(5)]for j in range(5)]; row_index,column_index,x,size=0,0,0,5 ; for row_index in range(size): for column_index in range(size): x+=1 ; matrix[row_index][column_index]+=x ; print("The matrix is"); for row_index in range(size): for column_index in range(size): print(matrix[row_index][column_index],end="\t"); print(""); print("\nElements above Secondary diagonal are:"); for row_index in range(size): for column_index in range(size): if((row_index+column_index)select(j | true)->collect(j | (Integer.subrange(0, 5-1)->select(i | true)->collect(i | (0)))); ; var row_index : OclAny := null; var column_index : OclAny := null; var x : OclAny := null; var size : OclAny := null; Sequence{row_index,column_index,x,size} := Sequence{0,0,0,5}; ; for row_index : Integer.subrange(0, size-1) do ( for column_index : Integer.subrange(0, size-1) do ( x := x + 1; ; matrix[row_index+1][column_index+1] := matrix[row_index+1][column_index+1] + x;)) ; execute ("The matrix is")->display(); ; for row_index : Integer.subrange(0, size-1) do ( for column_index : Integer.subrange(0, size-1) do ( execute (matrix[row_index+1][column_index+1])->display();) ; execute ("")->display();) ; execute ("\nElements above Secondary diagonal are:")->display(); ; for row_index : Integer.subrange(0, size-1) do ( for column_index : Integer.subrange(0, size-1) do ( if (((row_index + column_index)->compareTo(size - 1)) < 0) then ( execute (matrix[row_index+1][column_index+1])->display(); ) else skip)) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys rd=sys.stdin.readline n=int(rd()) lis=[[]for i in range(n+1)] isleaf=[1]*(n+1) for _ in range(n-1): i=int(rd()) lis[i].append(_+2) isleaf[i]=0 ans="YES" for i in range(1,n+1): count=0 if not isleaf[i]: for j in lis[i]: if isleaf[j]: count+=1 if count<3 : ans="NO" break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var rd : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + ((rd())))->toInteger() ; var lis : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Sequence{})) ; var isleaf : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ; for _anon : Integer.subrange(0, n - 1-1) do ( var i : int := ("" + ((rd())))->toInteger() ; (expr (atom (name lis)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name _))) + (expr (atom (number (integer 2)))))))))) )))) ; isleaf[i+1] := 0) ; var ans : String := "YES" ; for i : Integer.subrange(1, n + 1-1) do ( var count : int := 0 ; if not(isleaf[i+1]) then ( for j : lis[i+1] do ( if isleaf[j+1] then ( count := count + 1 ) else skip) ; if count < 3 then ( ans := "NO" ; break ) else skip ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import os from collections import Counter,defaultdict,deque from heapq import heapify,heappush,heappop from functools import lru_cache from math import floor,ceil,sqrt,gcd from string import ascii_lowercase from bisect import bisect_left,bisect,bisect_right def __perform_setup__(): INPUT_FILE_PATH="./code/input.txt" OUTPUT_FILE_PATH="./code/output.txt" sys.stdin=open(INPUT_FILE_PATH,'r') sys.stdout=open(OUTPUT_FILE_PATH,'w') if "MY_COMPETITIVE_PROGRAMMING_VARIABLE" in os.environ : __perform_setup__() def read(): return input().strip() def read_int(): return int(read()) def read_str_list(): return read().split() def read_numeric_list(): return list(map(int,read_str_list())) def solve(N,graph): res=True def dfs(curr): nonlocal res ans=0 for child in graph[curr]: if len(graph[child])==0 : ans+=1 dfs(child) if len(graph[curr])>0 and ans<3 : res=False return ans dfs(1) return "Yes" if res else "No" N=read_int() graph=defaultdict(list) for i in range(2,N+1): p=read_int() graph[p].append(i) print(solve(N,graph)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute res : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if (os.environ)->includes("MY_COMPETITIVE_PROGRAMMING_VARIABLE") then ( __perform_setup__() ) else skip ; skip ; skip ; skip ; skip ; skip ; N := read_int() ; graph := defaultdict(OclType["Sequence"]) ; for i : Integer.subrange(2, N + 1-1) do ( var p : OclAny := read_int() ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name p)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; execute (solve(N, graph))->display(); operation __perform_setup__() pre: true post: true activity: var INPUT_FILE_PATH : String := "./code/input.txt" ; var OUTPUT_FILE_PATH : String := "./code/output.txt" ; OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile(INPUT_FILE_PATH)) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile(OUTPUT_FILE_PATH)); operation read() : OclAny pre: true post: true activity: return input()->trim(); operation read_int() : OclAny pre: true post: true activity: return ("" + ((read())))->toInteger(); operation read_str_list() : OclAny pre: true post: true activity: return read().split(); operation read_numeric_list() : OclAny pre: true post: true activity: return ((read_str_list())->collect( _x | (OclType["int"])->apply(_x) )); operation solve(N : OclAny, graph : OclAny) : OclAny pre: true post: true activity: var res : boolean := true ; skip ; dfs(1) ; return if res then "Yes" else "No" endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict n=int(input()) graph=defaultdict(list) for i in range(1,n): node=int(input()) graph[node].append(i+1) count=[0] visited=[False]*(n+1) count=[0]*(n+1) def dfs(node): if node not in graph : return 1 visited[node]=True for nxt_node in graph[node]: if not visited[nxt_node]: count[node]+=dfs(nxt_node) return 0 dfs(1) for k,v in graph.items(): if count[k]<3 : print('No') exit() print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var graph : OclAny := defaultdict(OclType["Sequence"]) ; for i : Integer.subrange(1, n-1) do ( var node : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name node)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ))))) ; var count : Sequence := Sequence{ 0 } ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (n + 1)) ; count := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; skip ; dfs(1) ; for _tuple : graph->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if count[k+1] < 3 then ( execute ('No')->display() ; exit() ) else skip) ; execute ('Yes')->display(); operation dfs(node : OclAny) : OclAny pre: true post: true activity: if (graph)->excludes(node) then ( return 1 ) else skip ; visited[node+1] := true ; for nxt_node : graph[node+1] do ( if not(visited[nxt_node+1]) then ( count[node+1] := count[node+1] + dfs(nxt_node) ) else skip) ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline for _ in range(int(input())): n,m,k=[int(i)for i in input().split()] k-=2 if k<0 : print("NO") elif k==0 : if n==1 and m==0 : print("YES") else : print("NO") elif k==1 : if m==(n*(n-1))//2 : print("YES") else : print("NO") else : if m<=(n*(n-1))//2 and m>=(n-1): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; k := k - 2 ; if k < 0 then ( execute ("NO")->display() ) else (if k = 0 then ( if n = 1 & m = 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else (if k = 1 then ( if m = (n * (n - 1)) div 2 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else ( if (m->compareTo((n * (n - 1)) div 2)) <= 0 & (m->compareTo((n - 1))) >= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque import sys fin=sys.stdin T=int(fin.readline()) for case in range(1,T+1): N=int(fin.readline()) vines=[] for i in range(N): di,li=map(int,fin.readline().split()) vines.append((di,li)) D=int(fin.readline()) vines.append((D,0)) queue=deque([(vines[0][0],vines[0][0]*2)]) for d,l in vines[1 :]: while queue and queue[0][1]queue[-1][1]: queue.append((d,p)) success=bool(queue) print("Case #%d: %s" %(case,success and "YES" or "NO")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var fin : OclFile := OclFile["System.in"] ; var T : int := ("" + ((fin.readLine())))->toInteger() ; for case : Integer.subrange(1, T + 1-1) do ( var N : int := ("" + ((fin.readLine())))->toInteger() ; var vines : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var di : OclAny := null; var li : OclAny := null; Sequence{di,li} := (fin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{di, li}) : vines)) ; var D : int := ("" + ((fin.readLine())))->toInteger() ; execute ((Sequence{D, 0}) : vines) ; var queue : Sequence := (Sequence{ Sequence{vines->first()->first(), vines->first()->first() * 2} }) ; for _tuple : vines->tail() do (var _indx : int := 1; var d : OclAny := _tuple->at(_indx); _indx := _indx + 1; var l : OclAny := _tuple->at(_indx); while queue & (queue->first()[1+1]->compareTo(d)) < 0 do ( queue := queue->tail()) ; if not(queue) then ( break ) else skip ; var distance : OclAny := Set{l, d - queue->first()->first()}->min() ; var p : OclAny := d + distance ; if (p->compareTo(queue->last()[1+1])) > 0 then ( execute ((Sequence{d, p}) : queue) ) else skip) ; var success : boolean := (queue)->toBoolean() ; execute (StringLib.format("Case #%d: %s",Sequence{case, success & "YES" or "NO"}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans='Yes' g=[[]for i in range(n+1)] for i in range(2,n+1): x=int(input()) g[x].append(i) mark=[False]*(n+1) for i in range(1,n+1): if len(g[i])==0 : mark[i]=True for v in range(1,n+1): if not mark[v]: count=0 for u in g[v]: if mark[u]: count+=1 if count<3 : ans='No' print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : String := 'Yes' ; var g : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(2, n + 1-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var mark : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (n + 1)) ; for i : Integer.subrange(1, n + 1-1) do ( if (g[i+1])->size() = 0 then ( mark[i+1] := true ) else skip) ; for v : Integer.subrange(1, n + 1-1) do ( if not(mark[v+1]) then ( var count : int := 0 ; for u : g[v+1] do ( if mark[u+1] then ( count := count + 1 ) else skip) ; if count < 3 then ( ans := 'No' ) else skip ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while(1): try : c1,c2,c3=[int(i)for i in input().split()] tot=[i for i in range(1,11)] tot.remove(c1); tot.remove(c2),tot.remove(c3) tot=[i+c1+c2 for i in tot] count=[1 if i<=20 else 0 for i in tot] if sum(count)>3 : print("YES") else : print("NO") except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while (1) do ( try ( var c1 : OclAny := null; var c2 : OclAny := null; var c3 : OclAny := null; Sequence{c1,c2,c3} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var tot : Sequence := Integer.subrange(1, 11-1)->select(i | true)->collect(i | (i)) ; execute ((c1) /: tot); tot->excludingFirst(c2) ; execute ((c3) /: tot) ; tot := tot->select(i | true)->collect(i | (i + c1 + c2)) ; var count : Sequence := tot->select(i | true)->collect(i | (if i <= 20 then 1 else 0 endif)) ; if (count)->sum() > 3 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout def read_list(): return[int(x)for x in stdin.readline().split()] def read_list_str(): return[x for x in stdin.readline().split()] def readmv(): return map(int,stdin.readline().split()) def readv(): return int(stdin.readline()) def printSol(test_case,x): ans_to_print='' if type(x)==list : for el in x : ans_to_print+=f'{el}' if type(x)==int or type(x)==float : ans_to_print=str(x) stdout.write(f'Case #{test_case+1}: '+ans_to_print+f'\n') def read(): return stdin.readline().strip() def isLeaf(adj): if not len(adj): return 1 return 0 def solve(tree,ind): if len(tree[ind])==0 : return 1 cnt=0 for node in tree[ind]: if not len(tree[node]): cnt+=1 if cnt>=3 : return 1 return 0 def main(): n=readv() tree=[[]for _ in range(n)] for i in range(n-1): x=readv() tree[x-1].append(i+1) for i in range(n): if not solve(tree,i): stdout.write('NO') return stdout.write('YES') main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; main(); operation read_list() : OclAny pre: true post: true activity: return stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation read_list_str() : OclAny pre: true post: true activity: return stdin.readLine().split()->select(x | true)->collect(x | (x)); operation readmv() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation readv() : OclAny pre: true post: true activity: return ("" + ((stdin.readLine())))->toInteger(); operation printSol(test_case : OclAny, x : OclAny) pre: true post: true activity: var ans_to_print : String := '' ; if (x)->oclType() = OclType["Sequence"] then ( for el : x do ( ans_to_print := ans_to_print + StringLib.formattedString('{el}')) ) else skip ; if (x)->oclType() = OclType["int"] or (x)->oclType() = OclType["double"] then ( ans_to_print := ("" + ((x))) ) else skip ; stdout.write(StringLib.formattedString('Case #{test_case+1}: ') + ans_to_print + StringLib.formattedString(' ')); operation read() : OclAny pre: true post: true activity: return stdin.readLine()->trim(); operation isLeaf(adj : OclAny) : OclAny pre: true post: true activity: if not((adj)->size()) then ( return 1 ) else skip ; return 0; operation solve(tree : OclAny, ind : OclAny) : OclAny pre: true post: true activity: if (tree[ind+1])->size() = 0 then ( return 1 ) else skip ; var cnt : int := 0 ; for node : tree[ind+1] do ( if not((tree[node+1])->size()) then ( cnt := cnt + 1 ) else skip ; if cnt >= 3 then ( return 1 ) else skip) ; return 0; operation main() pre: true post: true activity: var n : OclAny := readv() ; tree := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, n - 1-1) do ( x := readv() ; (expr (atom (name tree)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ))))) ; for i : Integer.subrange(0, n-1) do ( if not(solve(tree, i)) then ( stdout.write('NO') ; return ) else skip) ; stdout.write('YES'); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque,defaultdict,Counter from heapq import heappush,heappop,heapify from math import inf,sqrt,ceil from functools import lru_cache from itertools import accumulate,combinations,permutations,product from typing import List from bisect import bisect_left,bisect_right import sys input=lambda : sys.stdin.readline().strip('\n') mis=lambda : map(int,input().split()) ii=lambda : int(input()) T=ii() for _ in range(T): N,G,B=mis() m=(N+1)//2 ans=(m-1)//G*(G+B)+(m % G if m % G else G) print(max(N,ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine()->trim()) ; var mis : Function := lambda $$ : OclAny in ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ii : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var T : OclAny := ii->apply() ; for _anon : Integer.subrange(0, T-1) do ( var N : OclAny := null; var G : OclAny := null; var B : OclAny := null; Sequence{N,G,B} := mis->apply() ; var m : int := (N + 1) div 2 ; var ans : double := (m - 1) div G * (G + B) + (if m mod G then m mod G else G endif) ; execute (Set{N, ans}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for h in range(T): n,g,b=map(int,input().split()) if n<=g : print(n) elif g>=b : print(n) elif b>g : k=(n+1)//2 h=k//g alpha=(h-1)*b+h*g if(k % g)!=0 : alpha=alpha+b+(k % g) print(max(n,alpha)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for h : Integer.subrange(0, T-1) do ( var n : OclAny := null; var g : OclAny := null; var b : OclAny := null; Sequence{n,g,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (n->compareTo(g)) <= 0 then ( execute (n)->display() ) else (if (g->compareTo(b)) >= 0 then ( execute (n)->display() ) else (if (b->compareTo(g)) > 0 then ( var k : int := (n + 1) div 2 ; var h : int := k div g ; var alpha : double := (h - 1) * b + h * g ; if (k mod g) /= 0 then ( alpha := alpha + b + (k mod g) ) else skip ; execute (Set{n, alpha}->max())->display() ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for _ in range(int(input())): (n,g,b)=tuple(map(int,input().split())) h=math.ceil(n/2) l=math.ceil(h/g) cum=l*g+(l-1)*b cum1=(g+b)*(l-1) if cumtoInteger()-1) do ( ; var Sequence{n, g, b} : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var h : double := (n / 2)->ceil() ; var l : double := (h / g)->ceil() ; var cum : double := l * g + (l - 1) * b ; var cum1 : double := (g + b) * (l - 1) ; if (cum->compareTo(n)) < 0 then ( execute (n)->display() ) else ( execute (Set{n, cum1 + h - g * (l - 1)}->max())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n,g,b=map(int,input().split()) req=(n+1)//2 tot=req//g*(b+g) tot+=(-b if req % g==0 else req % g) print(max(n,tot)) for _ in range(int(input())): solve(); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve();); operation solve() pre: true post: true activity: var n : OclAny := null; var g : OclAny := null; var b : OclAny := null; Sequence{n,g,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var req : int := (n + 1) div 2 ; var tot : double := req div g * (b + g) ; tot := tot + (if req mod g = 0 then -b else req mod g endif) ; execute (Set{n, tot}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.readline write=sys.stdout.write def solve(): n,g,b=map(int,read().split()) req=(n+1)//2 tot=req//g*(b+g) tot+=(-b if req % g==0 else req % g) write(str(max(n,tot))+'\n') for _ in range(int(read())): solve(); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := (OclFile["System.in"]).readline ; var write : OclAny := (OclFile["System.out"]).write ; skip ; for _anon : Integer.subrange(0, ("" + ((read())))->toInteger()-1) do ( solve();); operation solve() pre: true post: true activity: var n : OclAny := null; var g : OclAny := null; var b : OclAny := null; Sequence{n,g,b} := (read().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var req : int := (n + 1) div 2 ; var tot : double := req div g * (b + g) ; tot := tot + (if req mod g = 0 then -b else req mod g endif) ; write(("" + ((Set{n, tot}->max()))) + ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSeries(num,first,sec): print("{}{}".format(first,sec),end="") counter=0 while(counterdisplay() ; var counter : int := 0 ; while ((counter->compareTo(num - 2)) < 0) do ( var sum : OclAny := first + sec ; execute (StringLib.interpolateStrings("{}", Sequence{sum}))->display() ; first := sec ; sec := sum ; counter := counter + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def findDigitsInFactorial(n): if(n<0): return 0 if(n<=1): return 1 M_E=2.7182818284590452354 M_PI=3.14159265358979323846 x=((n*math.log10(n/M_E)+math.log10(2*M_PI*n)/2.0)) return int(math.floor(x)+1) def findNum(n): low=0 hi=2*n if(n<=0): return-1 if(findDigitsInFactorial(low)==n): return int(round(low)) while(low<=hi): mid=int((low+hi)/2) if((findDigitsInFactorial(mid)>=n and findDigitsInFactorial(mid-1)display(); ; execute (findNum(2))->display(); ; execute (findNum(5))->display(); ; execute (findNum(24))->display(); ; execute (findNum(100))->display(); ; execute (findNum(1221))->display(); ) else skip; operation findDigitsInFactorial(n : OclAny) : OclAny pre: true post: true activity: if (n < 0) then ( return 0 ) else skip ; if (n <= 1) then ( return 1 ) else skip ; var M_E : double := 2.7182818284590452354 ; var M_PI : double := 3.14159265358979323846 ; var x : double := ((n * (n / M_E)->log10() + (2 * M_PI * n)->log10() / 2.0)) ; return ("" + (((x)->floor() + 1)))->toInteger(); operation findNum(n : OclAny) : OclAny pre: true post: true activity: var low : int := 0 ; var hi : double := 2 * n ; if (n <= 0) then ( return -1 ) else skip ; if (findDigitsInFactorial(low) = n) then ( return ("" + (((low)->round())))->toInteger() ) else skip ; while ((low->compareTo(hi)) <= 0) do ( var mid : int := ("" + (((low + hi) / 2)))->toInteger() ; if (((findDigitsInFactorial(mid)->compareTo(n)) >= 0 & (findDigitsInFactorial(mid - 1)->compareTo(n)) < 0)) then ( return ("" + (((mid)->round())))->toInteger() ) else (if ((findDigitsInFactorial(mid)->compareTo(n)) < 0) then ( low := mid + 1 ) else ( hi := mid - 1 ) ) ) ; return ("" + (((low)->round())))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sortSquares(arr,n): K=0 for K in range(n): if(arr[K]>=0): break i=K-1 j=K ind=0 temp=[0]*n while(i>=0 and j=0): temp[ind]=arr[i]*arr[i] i-=1 ind+=1 while(junion(Sequence{-3}->union(Sequence{-1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 5 }))))) ; n := (arr)->size() ; execute ("Before sort ")->display() ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()) ; sortSquares(arr, n) ; execute ("\nAfter Sort ")->display() ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); operation sortSquares(arr : OclAny, n : OclAny) pre: true post: true activity: var K : int := 0 ; for K : Integer.subrange(0, n-1) do ( if (arr[K+1] >= 0) then ( break ) else skip) ; var i : double := K - 1 ; var j : int := K ; var ind : int := 0 ; var temp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; while (i >= 0 & (j->compareTo(n)) < 0) do ( if ((arr[i+1] * arr[i+1]->compareTo(arr[j+1] * arr[j+1])) < 0) then ( temp[ind+1] := arr[i+1] * arr[i+1] ; i := i - 1 ) else ( temp[ind+1] := arr[j+1] * arr[j+1] ; j := j + 1 ) ; ind := ind + 1) ; while (i >= 0) do ( temp[ind+1] := arr[i+1] * arr[i+1] ; i := i - 1 ; ind := ind + 1) ; while ((j->compareTo(n)) < 0) do ( temp[ind+1] := arr[j+1] * arr[j+1] ; j := j + 1 ; ind := ind + 1) ; for i : Integer.subrange(0, n-1) do ( arr[i+1] := temp[i+1]); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=open("data.txt",'r') g=open("data1.txt",'w') line=f.readline() t=int(line) for i in range(1,t+1): line=f.readline() n=int(line) vines=[] for j in range(n): line=f.readline() integers=[int(x)for x in line.split()] vines.append(integers) line=f.readline() d=int(line) vines.append([d,0]) reachable=dict() reachable[0]=vines[0][0] for j in range(1,n+1): reachable[j]=-1 for j in range(n): hook=vines[j][0] hang=reachable[j] for k in range(j+1,n+1): if(vines[k][0]-hook)>hang : break reachable[k]=max(reachable[k],min(vines[k][1],(vines[k][0]-hook))) if reachable[n]>-1 : result="YES" else : result="NO" string="Case #"+str(i)+": "+result+'\n' g.write(string) f.close() g.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("data.txt")) ; var g : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("data1.txt")) ; var line : String := f.readLine() ; var t : int := ("" + ((line)))->toInteger() ; for i : Integer.subrange(1, t + 1-1) do ( line := f.readLine() ; var n : int := ("" + ((line)))->toInteger() ; var vines : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( line := f.readLine() ; var integers : Sequence := line.split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((integers) : vines)) ; line := f.readLine() ; var d : int := ("" + ((line)))->toInteger() ; execute ((Sequence{d}->union(Sequence{ 0 })) : vines) ; var reachable : Map := (arguments ( )) ; reachable->first() := vines->first()->first() ; for j : Integer.subrange(1, n + 1-1) do ( reachable[j+1] := -1) ; for j : Integer.subrange(0, n-1) do ( var hook : OclAny := vines[j+1]->first() ; var hang : OclAny := reachable[j+1] ; for k : Integer.subrange(j + 1, n + 1-1) do ( if ((vines[k+1]->first() - hook)->compareTo(hang)) > 0 then ( break ) else skip ; reachable[k+1] := Set{reachable[k+1], Set{vines[k+1][1+1], (vines[k+1]->first() - hook)}->min()}->max())) ; if reachable[n+1] > -1 then ( var result : String := "YES" ) else ( result := "NO" ) ; var string : String := "Case #" + ("" + ((i))) + ": " + result + ' ' ; g.write(string)) ; f.closeFile() ; g.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import(division,absolute_import,print_function,unicode_literals) from sys import stdin for line in stdin : c=[int(s)for s in line.split()] cards=[i for i in range(1,11)if i not in c] c1c2=c[0]+c[1] e=sum(int(i+c1c2<=20)for i in cards) print('YES' if e>3 else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for line : stdin do ( var c : Sequence := line.split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; var cards : Sequence := Integer.subrange(1, 11-1)->select(i | (c)->excludes(i))->collect(i | (i)) ; var c1c2 : OclAny := c->first() + c[1+1] ; var e : OclAny := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (comparison (expr (expr (atom (name i))) + (expr (atom (name c1c2))))) <= (comparison (expr (atom (number (integer 20)))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name cards))))))))->sum() ; execute (if e > 3 then 'YES' else 'NO' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxProduct(arr,n): if n<3 : return-1 arr.sort() return max(arr[0]*arr[1]*arr[n-1],arr[n-1]*arr[n-2]*arr[n-3]) if __name__=="__main__" : arr=[-10,-3,5,6,-20] n=len(arr) _max=maxProduct(arr,n) if _max==-1 : print("No Triplet Exists") else : print("Maximum product is",_max) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{-10}->union(Sequence{-3}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ -20 })))) ; n := (arr)->size() ; var _max : OclAny := maxProduct(arr, n) ; if _max = -1 then ( execute ("No Triplet Exists")->display() ) else ( execute ("Maximum product is")->display() ) ) else skip; operation maxProduct(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: if n < 3 then ( return -1 ) else skip ; arr := arr->sort() ; return Set{arr->first() * arr[1+1] * arr[n - 1+1], arr[n - 1+1] * arr[n - 2+1] * arr[n - 3+1]}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countDigits(n): c=0 while(n!=0): c+=1 n=int(n/10) return c def isDeserium(x): temp=x p=countDigits(x) sum=0 while(x!=0): digit=int(x % 10) sum+=pow(digit,p) p-=1 x=int(x/10) return(sum==temp) x=135 if(isDeserium(x)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; x := 135 ; if (isDeserium(x)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation countDigits(n : OclAny) : OclAny pre: true post: true activity: var c : int := 0 ; while (n /= 0) do ( c := c + 1 ; n := ("" + ((n / 10)))->toInteger()) ; return c; operation isDeserium(x : OclAny) : OclAny pre: true post: true activity: var temp : OclAny := x ; var p : OclAny := countDigits(x) ; var sum : int := 0 ; while (x /= 0) do ( var digit : int := ("" + ((x mod 10)))->toInteger() ; sum := sum + (digit)->pow(p) ; p := p - 1 ; x := ("" + ((x / 10)))->toInteger()) ; return (sum = temp); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def getMinimumSum(arr,n): fMin=sys.maxsize ; sMin=sys.maxsize ; tMin=sys.maxsize ; for i in range(n): if(arr[i]union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{-1}->union(Sequence{5}->union(Sequence{ -2 }))))))); ; n := (arr)->size(); ; execute (getMinimumSum(arr, n))->display(); ) else skip; operation getMinimumSum(arr : OclAny, n : OclAny) pre: true post: true activity: var fMin : (trailer . (name maxsize)) := (trailer . (name maxsize)); ; var sMin : (trailer . (name maxsize)) := (trailer . (name maxsize)); ; var tMin : (trailer . (name maxsize)) := (trailer . (name maxsize)); ; for i : Integer.subrange(0, n-1) do ( if ((arr[i+1]->compareTo(fMin)) < 0) then ( tMin := sMin; ; sMin := fMin; ; fMin := arr[i+1]; ) else (if ((arr[i+1]->compareTo(sMin)) < 0) then ( tMin := sMin; ; sMin := arr[i+1]; ) else (if ((arr[i+1]->compareTo(tMin)) < 0) then ( tMin := arr[i+1]; ) else skip ) ) ) ; return (fMin + sMin + tMin);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gen(n): if n==0 : return 0 elif n==1 : return 1 elif n % 2==0 : return 4*gen(n//2) elif n % 2==1 : return 4*gen(n//2)+1 def moserDeBruijn(n): for i in range(n): print(gen(i),end=" ") n=15 print("First",n,"terms of ","Moser-de Brujn Sequence:") moserDeBruijn(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 15 ; execute ("First")->display() ; moserDeBruijn(n); operation gen(n : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( return 0 ) else (if n = 1 then ( return 1 ) else (if n mod 2 = 0 then ( return 4 * gen(n div 2) ) else (if n mod 2 = 1 then ( return 4 * gen(n div 2) + 1 ) else skip ) ) ) ; operation moserDeBruijn(n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (gen(i))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def s(): import sys r=sys.stdin.readline for e in iter(r,'0 0\n'): N,M=map(int,e.split()) k,p=1,0 S=[int(r())for _ in[0]*N] for d in[int(r())for _ in[0]*M]: p+=d if N<=p+d else d+S[p+d] if N<=p+1 : break k+=1 print(k) if '__main__'==__name__ : s() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if '__main__' = __name__ then ( s() ) else skip; operation s() pre: true post: true activity: skip ; var r : OclAny := (OclFile["System.in"]).readline ; for e : OclIterator.newOclIterator_Sequence(r, '0 0 ') do ( var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (e.split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : OclAny := null; var p : OclAny := null; Sequence{k,p} := Sequence{1,0} ; var S : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N)->select(_anon | true)->collect(_anon | (("" + ((r())))->toInteger())) ; for d : MatrixLib.elementwiseMult(Sequence{ 0 }, M)->select(_anon | true)->collect(_anon | (("" + ((r())))->toInteger())) do ( p := p + if (N->compareTo(p + d)) <= 0 then d else d + S[p + d+1] endif ; if (N->compareTo(p + 1)) <= 0 then ( break ) else skip ; k := k + 1) ; execute (k)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): while True : N,M=map(int,input().split()) if not N : return order=[int(input())for _ in range(N)] draw=[int(input())for _ in range(M)] p=0 ans=0 for i in range(M): p+=draw[i] if p>=N-1 : ans=i+1 break p+=order[p] if p>=N-1 : ans=i+1 break print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: while true do ( var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if not(N) then ( return ) else skip ; var order : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var draw : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var p : int := 0 ; var ans : int := 0 ; for i : Integer.subrange(0, M-1) do ( p := p + draw[i+1] ; if (p->compareTo(N - 1)) >= 0 then ( ans := i + 1 ; break ) else skip ; p := p + order[p+1] ; if (p->compareTo(N - 1)) >= 0 then ( ans := i + 1 ; break ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,m=map(int,input().split()) if n==0 : break mapp=[] for _ in range(n): mapp.append(int(input())) mas=0 ans=0 for dice in range(m): mas+=int(input()) if mas>=n-1 and ans==0 : ans=dice+1 if mas=n-1 and ans==0 : ans=dice+1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var mapp : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : mapp)) ; var mas : int := 0 ; var ans : int := 0 ; for dice : Integer.subrange(0, m-1) do ( mas := mas + ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (mas->compareTo(n - 1)) >= 0 & ans = 0 then ( ans := dice + 1 ) else skip ; if (mas->compareTo(n - 1)) < 0 then ( mas := mas + mapp[mas+1] ) else skip ; if (mas->compareTo(n - 1)) >= 0 & ans = 0 then ( ans := dice + 1 ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,m=[int(s)for s in input().split(" ")] if n==m==0 : break map_=[int(input())for i in range(n)] dice=[int(input())for i in range(m)] pos=0 for i in range(m): pos+=dice[i] try : pos+=map_[pos] except : pass if pos>=n-1 : print(i+1) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split(" ")->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; if n = m & (m == 0) then ( break ) else skip ; var map_ : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var dice : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var pos : int := 0 ; for i : Integer.subrange(0, m-1) do ( pos := pos + dice[i+1] ; try ( pos := pos + map_[pos+1]) catch (_e : OclException) do ( skip) ; if (pos->compareTo(n - 1)) >= 0 then ( execute (i + 1)->display() ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for e in iter(input,'0 0'): N,M=map(int,e.split()) S=[int(input())for _ in[0]*N] p=b=1 for i in range(M): d=int(input()) p+=d if N<=p : if b : print(-~ i); b=0 continue p+=S[~-p] if(N<=p)*b : print(-~ i); b=0 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for e : OclIterator.newOclIterator_Sequence(input, '0 0') do ( var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (e.split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var p : OclAny := 1; var b : int := 1 ; for i : Integer.subrange(0, M-1) do ( var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; p := p + d ; if (N->compareTo(p)) <= 0 then ( if b then ( execute (-MathLib.bitwiseNot(i))->display(); b := 0 ) else skip ; continue ) else skip ; p := p + S[MathLib.bitwiseNot(-p)+1] ; if ((N->compareTo(p)) <= 0) * b then ( execute (-MathLib.bitwiseNot(i))->display(); b := 0 ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMostOccurringChar(string): hash=[0]*26 ; for i in range(len(string)): for j in range(len(string[i])): hash[ord(string[i][j])-ord('a')]+=1 ; max=0 ; for i in range(26): max=i if hash[i]>hash[max]else max ; print((chr)(max+97)); if __name__=="__main__" : string=[]; string.append("animal"); string.append("zebra"); string.append("lion"); string.append("giraffe"); findMostOccurringChar(string); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( string := Sequence{}; ; execute (("animal") : string); ; execute (("zebra") : string); ; execute (("lion") : string); ; execute (("giraffe") : string); ; findMostOccurringChar(string); ) else skip; operation findMostOccurringChar(string : OclAny) pre: true post: true activity: var hash : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26); ; for i : Integer.subrange(0, (string)->size()-1) do ( for j : Integer.subrange(0, (string[i+1])->size()-1) do ( hash[(string[i+1][j+1])->char2byte() - ('a')->char2byte()+1] := hash[(string[i+1][j+1])->char2byte() - ('a')->char2byte()+1] + 1;)) ; var max : int := 0; ; for i : Integer.subrange(0, 26-1) do ( max := if (hash[i+1]->compareTo(hash[max+1])) > 0 then i else max endif;) ; execute ((chr)(max + 97))->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def judge(c1,c2,c3): num=[i for i in range(1,11)if i!=c1 or i!=c2 or i!=c3] if c1+c2<=14 : return True elif c1+c2>=17 : return False tmp=0 for x in range(20-c1-c2,0,-1): if x in num : tmp+=1 if tmp>=4 : return True return False while True : try : c1,c2,c3=map(int,input().split()) except EOFError : break if judge(c1,c2,c3)==True : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( try ( Sequence{c1,c2,c3} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))) ; if judge(c1, c2, c3) = true then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); operation judge(c1 : OclAny, c2 : OclAny, c3 : OclAny) : OclAny pre: true post: true activity: var num : Sequence := Integer.subrange(1, 11-1)->select(i | i /= c1 or i /= c2 or i /= c3)->collect(i | (i)) ; if c1 + c2 <= 14 then ( return true ) else (if c1 + c2 >= 17 then ( return false ) else skip) ; var tmp : int := 0 ; for x : Integer.subrange(0 + 1, 20 - c1 - c2)->reverse() do ( if (num)->includes(x) then ( tmp := tmp + 1 ) else skip ; if tmp >= 4 then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- testCount=int(raw_input()) for testIndex in range(testCount): ans="Case #"+str(testIndex+1)+": " n=int(raw_input()) v=[] for i in range(n): v+=[[int(x)for x in raw_input().split(" ")]] g=int(raw_input()) p=[0]*n p[0]=v[0][0] res=False for i in range(n): if p[i]+v[i][0]>=g : res=True break for j in range(i+1,n): if p[i]+v[i][0]toInteger() ; for testIndex : Integer.subrange(0, testCount-1) do ( var ans : String := "Case #" + ("" + ((testIndex + 1))) + ": " ; var n : int := ("" + ((raw_input())))->toInteger() ; var v : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( v := v + Sequence{ raw_input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) }) ; var g : int := ("" + ((raw_input())))->toInteger() ; var p : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; p->first() := v->first()->first() ; var res : boolean := false ; for i : Integer.subrange(0, n-1) do ( if (p[i+1] + v[i+1]->first()->compareTo(g)) >= 0 then ( res := true ; break ) else skip ; for j : Integer.subrange(i + 1, n-1) do ( if (p[i+1] + v[i+1]->first()->compareTo(v[j+1]->first())) < 0 then ( break ) else ( var pp : OclAny := Set{v[j+1][1+1], v[j+1]->first() - v[i+1]->first()}->min() ; p[j+1] := Set{p[j+1], pp}->max() ))) ; if res then ( ans := ans + "YES" ) else ( ans := ans + "NO" ) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def val(c): if c>='0' and c<='9' : return ord(c)-ord('0') else : return ord(c)-ord('A')+10 ; def toDeci(str,base): llen=len(str) power=1 num=0 for i in range(llen-1,-1,-1): if val(str[i])>=base : print('Invalid Number') return-1 num+=val(str[i])*power power=power*base return num strr="11A" base=16 print('Decimal equivalent of',strr,'in base',base,'is',toDeci(strr,base)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var strr : String := "11A" ; base := 16 ; execute ('Decimal equivalent of')->display(); operation val(c : OclAny) : OclAny pre: true post: true activity: if c >= '0' & c <= '9' then ( return (c)->char2byte() - ('0')->char2byte() ) else ( return (c)->char2byte() - ('A')->char2byte() + 10; ); operation toDeci(OclType["String"] : OclAny, base : OclAny) : OclAny pre: true post: true activity: var llen : int := (OclType["String"])->size() ; var power : int := 1 ; var num : int := 0 ; for i : Integer.subrange(-1 + 1, llen - 1)->reverse() do ( if (val(("" + ([i+1])))->compareTo(base)) >= 0 then ( execute ('Invalid Number')->display() ; return -1 ) else skip ; num := num + val(("" + ([i+1]))) * power ; power := power * base) ; return num; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math pi=math.pi def volume(r): vol=(4/3)*pi*r*r*r return vol def surfacearea(r): sur_ar=4*pi*r*r return sur_ar radius=float(12) print("Volume Of Sphere : ",volume(radius)) print("Surface Area Of Sphere : ",surfacearea(radius)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var pi : OclAny := ; skip ; skip ; var radius : double := ("" + ((12)))->toReal() ; execute ("Volume Of Sphere : ")->display() ; execute ("Surface Area Of Sphere : ")->display(); operation volume(r : OclAny) : OclAny pre: true post: true activity: var vol : double := (4 / 3) * pi * r * r * r ; return vol; operation surfacearea(r : OclAny) : OclAny pre: true post: true activity: var sur_ar : double := 4 * pi * r * r ; return sur_ar; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count(arr,n,k): arr.sort(); cnt=0 ; i=0 ; j=1 ; while(iunion(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))); ; n := (arr)->size(); ; k := 2; ; execute (count(arr, n, k))->display(); ) else skip; operation count(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: arr := arr->sort(); ; var cnt : int := 0; ; var i : int := 0; var j : int := 1; ; while ((i->compareTo(n)) < 0 & (j->compareTo(n)) < 0) do ( if (j->compareTo(i)) <= 0 then ( j := i + 1 ) else ( j := j ) ; while ((j->compareTo(n)) < 0 & ((arr[j+1] - arr[i+1])->compareTo(k)) < 0) do ( j := j + 1;) ; cnt := cnt + (n - j); ; i := i + 1;) ; return cnt;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,p=[int(k)for k in input().split()] a,b=[],[] w=[] for j in range(n): x=[int(k)for k in input().split()] w.append(x) a.append(x[0]) b.append(x[1]) w.sort() if p>=sum(a): print(-1) else : l,r=0.0,float(100_000_000_000.7) j=0 while r-l>1 : m=(l+r)/2 eta=p*m for k in range(n): eta-=max(0,a[k]*(m//1)+a[k]*(m % 1)-b[k]) if eta<=0 : r=m+(1/(j+1)) else : l=m-(1/(j+1)) j+=1 for j in range(100): m=(int(l)+int(r))/2+(l % 1+r % 1)/2 eta=p*m for k in range(n): eta-=max(0,a[k]*m-b[k]) if eta<=0 : r=m else : l=m print((int(l)+int(r))/2+(l % 1+r % 1)/2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger())) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{Sequence{},Sequence{}} ; var w : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( var x : Sequence := input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger())) ; execute ((x) : w) ; execute ((x->first()) : a) ; execute ((x[1+1]) : b)) ; w := w->sort() ; if (p->compareTo((a)->sum())) >= 0 then ( execute (-1)->display() ) else ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := testlist_star_expr ; (testlist_star_expr 0.0 ,)(stmt (simple_stmt (small_stmt (testlist_star_expr float)) ( )) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 100)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name _000_000_000))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number .7)))))))))))) ; var j : int := 0 ; while r - l > 1 do ( var m : double := (l + r) / 2 ; var eta : double := p * m ; for k : Integer.subrange(0, n-1) do ( eta := eta - Set{0, a[k+1] * (m div 1) + a[k+1] * (m mod 1) - b[k+1]}->max()) ; if eta <= 0 then ( var r : OclAny := m + (1 / (j + 1)) ) else ( var l : double := m - (1 / (j + 1)) ) ; j := j + 1) ; for j : Integer.subrange(0, 100-1) do ( m := (("" + ((l)))->toInteger() + ("" + ((r)))->toInteger()) / 2 + (l mod 1 + r mod 1) / 2 ; eta := p * m ; for k : Integer.subrange(0, n-1) do ( eta := eta - Set{0, a[k+1] * m - b[k+1]}->max()) ; if eta <= 0 then ( r := m ) else ( l := m )) ; execute ((("" + ((l)))->toInteger() + ("" + ((r)))->toInteger()) / 2 + (l mod 1 + r mod 1) / 2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import inf n,p=[int(x)for x in input().split()] l=[] for i in range(n): a,b=[int(x)for x in input().split()] l.append((a,b,b/a)) l.sort(key=lambda x : x[2]) asum=0 bsum=0 sumt=0 for i in range(n): a0,b0,_=l[i] c1=inf if i==n-1 else l[i+1][2] asum+=a0 bsum+=b0 dp=asum-p if dp>0 : t=bsum/dp if tselect(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((Sequence{a, b, b / a}) : l)) ; l := l->sort() ; var asum : int := 0 ; var bsum : int := 0 ; var sumt : int := 0 ; for i : Integer.subrange(0, n-1) do ( var a0 : OclAny := null; var b0 : OclAny := null; var _anon : OclAny := null; Sequence{a0,b0,_anon} := l[i+1] ; var c1 : double := if i = n - 1 then Math_PINFINITY else l[i + 1+1][2+1] endif ; asum := asum + a0 ; bsum := bsum + b0 ; var dp : double := asum - p ; if dp > 0 then ( var t : double := bsum / dp ; if (t->compareTo(c1)) < 0 then ( execute (t)->display() ; exit() ) else skip ) else skip) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=lambda : map(int,input().split()) n,p=f() s=[0]*n x,y=-p,0 for i in range(n): a,b=f() x+=a y+=b s[i]=(a,b) s.sort(key=lambda q : q[0]/q[1]) for a,b in s : if b*x>a*y : x-=a y-=b print(y/x if x>0 else-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := f->apply() ; var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{-p,0} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := f->apply() ; x := x + a ; y := y + b ; s[i+1] := Sequence{a, b}) ; s := s->sort() ; for _tuple : s do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if (b * x->compareTo(a * y)) > 0 then ( x := x - a ; y := y - b ) else skip) ; execute (if x > 0 then y / x else -1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,p=map(int,input().split()) a=[0]*n b=[0]*n for i in range(n): a[i],b[i]=map(int,input().split()) s=sum(a) if s<=p : print(-1) exit() t=[b[i]/a[i]for i in range(n)] INF=10**10+1 l=0 r=INF while r-l>10**(-5): x=l+(r-l)/2 use=0 for i in range(n): use+=max(x*a[i]-b[i],0) if use/x<=p : l=x else : r=x print(l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( var a[i+1] : OclAny := null; var b[i+1] : OclAny := null; Sequence{a[i+1],b[i+1]} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : OclAny := (a)->sum() ; if (s->compareTo(p)) <= 0 then ( execute (-1)->display() ; exit() ) else skip ; var t : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (b[i+1] / a[i+1])) ; var INF : double := (10)->pow(10) + 1 ; var l : int := 0 ; var r : OclAny := INF ; while (r - l->compareTo((10)->pow((-5)))) > 0 do ( var x : int := l + (r - l) / 2 ; var use : int := 0 ; for i : Integer.subrange(0, n-1) do ( use := use + Set{x * a[i+1] - b[i+1], 0}->max()) ; if (use / x->compareTo(p)) <= 0 then ( l := x ) else ( r := x )) ; execute (l)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,p=[int(k)for k in input().split()] a,b=[],[] w=[] for j in range(n): x=[int(k)for k in input().split()] w.append(x) a.append(x[0]) b.append(x[1]) w.sort() if p>=sum(a): print(-1) else : l,r=0.0,float(100_000_000_000.7) j=0 while r-l>1 : m=(l+r)/2 eta=p*m for k in range(n): eta-=max(0,a[k]*(m//1)+a[k]*(m % 1)-b[k]) if eta<=0 : r=m+(1/(j+1)) else : l=m-(1/(j+1)) j+=1 for j in range(100): m=(int(l)+int(r))/2+(l % 1+r % 1)/2 eta=p*m for k in range(n): eta-=max(0,a[k]*m-b[k]) if eta<=0 : r=m else : l=m print((int(l)+int(r))/2+(l % 1+r % 1)/2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger())) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{Sequence{},Sequence{}} ; var w : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( var x : Sequence := input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger())) ; execute ((x) : w) ; execute ((x->first()) : a) ; execute ((x[1+1]) : b)) ; w := w->sort() ; if (p->compareTo((a)->sum())) >= 0 then ( execute (-1)->display() ) else ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := testlist_star_expr ; (testlist_star_expr 0.0 ,)(stmt (simple_stmt (small_stmt (testlist_star_expr float)) ( )) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 100)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name _000_000_000))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number .7)))))))))))) ; var j : int := 0 ; while r - l > 1 do ( var m : double := (l + r) / 2 ; var eta : double := p * m ; for k : Integer.subrange(0, n-1) do ( eta := eta - Set{0, a[k+1] * (m div 1) + a[k+1] * (m mod 1) - b[k+1]}->max()) ; if eta <= 0 then ( var r : OclAny := m + (1 / (j + 1)) ) else ( var l : double := m - (1 / (j + 1)) ) ; j := j + 1) ; for j : Integer.subrange(0, 100-1) do ( m := (("" + ((l)))->toInteger() + ("" + ((r)))->toInteger()) / 2 + (l mod 1 + r mod 1) / 2 ; eta := p * m ; for k : Integer.subrange(0, n-1) do ( eta := eta - Set{0, a[k+1] * m - b[k+1]}->max()) ; if eta <= 0 then ( r := m ) else ( l := m )) ; execute ((("" + ((l)))->toInteger() + ("" + ((r)))->toInteger()) / 2 + (l mod 1 + r mod 1) / 2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import os import random import re import sys from math import gcd from math import sqrt from collections import Counter a,b,c=list(map(int,input().split())) n=int(input()) arr=list(map(int,input().split())) li=[] for i in arr : if bcollect( _x | (OclType["int"])->apply(_x) )) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var li : Sequence := Sequence{} ; for i : arr do ( if (b->compareTo(i)) < 0 & (i < c) then ( execute ((i) : li) ) else skip) ; execute ((li)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def shu(j): t=list(set((range(1,11)))-set(j)) if sum([1 for i in t if sum(j[: 2])+i<=20])/len(t)>0.5 : return "YES" else : return "NO" [print(shu(i))for i in[list(map(int,l.split()))for l in sys.stdin]] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; ; operation shu(j : OclAny) : OclAny pre: true post: true activity: var t : Sequence := (Set{}->union(((Integer.subrange(1, 11-1)))) - Set{}->union((j))) ; if (t->select(i | (j.subrange(1,2))->sum() + i <= 20)->collect(i | (1)))->sum() / (t)->size() > 0.5 then ( return "YES" ) else ( return "NO" ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys import itertools import fractions if __name__=='__main__' : wtf=sys.stdin.read() wtf=wtf.strip().split('\n') a,b,c=map(int,wtf[0].split()) n=int(wtf[1]) X=list(map(int,wtf[2].split())) S=dict() for i,v in enumerate(X): if v not in S : S[v]=[i+1] else : S[v].append(i+1) Sa=sorted([k for k in S.keys()if k>b and ktrim().split(' ') ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (wtf->first().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : int := ("" + ((wtf[1+1])))->toInteger() ; var X : Sequence := ((wtf[2+1].split())->collect( _x | (OclType["int"])->apply(_x) )) ; var S : Map := (arguments ( )) ; for _tuple : Integer.subrange(1, (X)->size())->collect( _indx | Sequence{_indx-1, (X)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if (S)->excludes(v) then ( S[v+1] := Sequence{ i + 1 } ) else ( (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) )))) )) ; var Sa : Sequence := S.keys()->select(k | (k->compareTo(b)) > 0 & (k->compareTo(c)) < 0)->collect(k | (k))->sort() ; var ans : int := 0 ; for s : Sa do ( ans := ans + (S[s+1])->size()) ; execute (ans)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def get_ints(): for line in sys.stdin : for word in line.split(): yield int(word) return ints=get_ints() def get_floats(): for line in sys.stdin : for word in line.split(): yield float(word) return floats=get_floats() def up(a): i=1 while idisplay() ) else ( execute ("Case #")->display() )); operation get_ints(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; for line : OclFile["System.in"] do ( for word : line.split() do ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return ("" + ((word)))->toInteger())) ; return; operation get_floats(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; for line : OclFile["System.in"] do ( for word : line.split() do ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return ("" + ((word)))->toReal())) ; return; operation up(a : OclAny) : OclAny pre: true post: true activity: var i : int := 1 ; while (i->compareTo(a)) < 0 do ( i := i * 2) ; return 2 * i; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import fileinput def main(): f=fileinput.input() line=next(f) c=line.split(" ") l=int(c[1]) r=int(c[2]) line=next(f) n=int(line) line=next(f) count=0 for s in line.split(" "): a=int(s) if a>l and atoInteger() ; var r : int := ("" + ((c[2+1])))->toInteger() ; line := (f).next() ; var n : int := ("" + ((line)))->toInteger() ; line := (f).next() ; var count : int := 0 ; for s : line.split(" ") do ( var a : int := ("" + ((s)))->toInteger() ; if (a->compareTo(l)) > 0 & (a->compareTo(r)) < 0 then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (position_of_oleg,position_of_first_security_guard,position_of_second_security_guard)=map(int,input().split(' ')) number_of_banknotes=int(input()) banknote_locations=list(map(int,input().split(' '))) potential_banknotes=0 if position_of_olegposition_of_second_security_guard : for location in banknote_locations : if location>position_of_second_security_guard : potential_banknotes+=1 print(potential_banknotes) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{position_of_oleg, position_of_first_security_guard, position_of_second_security_guard} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var number_of_banknotes : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var banknote_locations : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var potential_banknotes : int := 0 ; if (position_of_oleg->compareTo(position_of_first_security_guard)) < 0 then ( for location : banknote_locations do ( if (location->compareTo(position_of_first_security_guard)) < 0 then ( potential_banknotes := potential_banknotes + 1 ) else skip) ) else (if (position_of_first_security_guard->compareTo(position_of_oleg)) < 0 & (position_of_oleg < position_of_second_security_guard) then ( for location : banknote_locations do ( if (position_of_first_security_guard->compareTo(location)) < 0 & (location < position_of_second_security_guard) then ( potential_banknotes := potential_banknotes + 1 ) else skip) ) else (if (position_of_oleg->compareTo(position_of_second_security_guard)) > 0 then ( for location : banknote_locations do ( if (location->compareTo(position_of_second_security_guard)) > 0 then ( potential_banknotes := potential_banknotes + 1 ) else skip) ) else skip ) ) ; execute (potential_banknotes)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) n=int(input()) a=list(map(int,input().split())) ans=0 for i in a : if i>b and icollect( _x | (OclType["int"])->apply(_x) ) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : a do ( if (i->compareTo(b)) > 0 & (i->compareTo(c)) < 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() if "a" in a and "b" in a and "c" in a : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; if (a)->characters()->includes("a") & (a)->characters()->includes("b") & (a)->characters()->includes("c") then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print('Yes' if len(set(input()))==3 else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (if (Set{}->union(((OclFile["System.in"]).readLine())))->size() = 3 then 'Yes' else 'No' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() alpha=[0,0,0] for i in range(len(s)): if s[i]=='a' : alpha[0]+=1 elif s[i]=='b' : alpha[1]+=1 else : alpha[2]+=1 flag=0 for i in range(3): if alpha[i]!=1 : flag=1 if flag==0 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var alpha : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = 'a' then ( alpha->first() := alpha->first() + 1 ) else (if s[i+1] = 'b' then ( alpha[1+1] := alpha[1+1] + 1 ) else ( alpha[2+1] := alpha[2+1] + 1 ) ) ) ; var flag : int := 0 ; for i : Integer.subrange(0, 3-1) do ( if alpha[i+1] /= 1 then ( flag := 1 ) else skip) ; if flag = 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() t='abc' isNotFind=True if len(s)!=3 : isNotFind=False for u in t : if s.find(u)<0 : isNotFind=False break if isNotFind : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var t : String := 'abc' ; var isNotFind : boolean := true ; if (s)->size() /= 3 then ( isNotFind := false ) else skip ; for u : t->characters() do ( if s->indexOf(u) - 1 < 0 then ( isNotFind := false ; break ) else skip) ; if isNotFind then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=str(input()) a=s.count('a') b=s.count('b') c=s.count('c') print('Yes' if a==1 and b==1 and c==1 else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; var a : int := s->count('a') ; var b : int := s->count('b') ; var c : int := s->count('c') ; execute (if a = 1 & b = 1 & c = 1 then 'Yes' else 'No' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=[int(i)for i in input().split()] mas=[int(i)for i in input().split()] ans=0 for i in range(1,n): if mas[i]<=mas[i-1]: ans1=(mas[i-1]-mas[i])//d+1 ans+=ans1 mas[i]+=ans1*d print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var mas : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : int := 0 ; for i : Integer.subrange(1, n-1) do ( if (mas[i+1]->compareTo(mas[i - 1+1])) <= 0 then ( var ans1 : int := (mas[i - 1+1] - mas[i+1]) div d + 1 ; ans := ans + ans1 ; mas[i+1] := mas[i+1] + ans1 * d ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(i)for i in input().split()] A=sorted(a) for i in range(n-1,-1,-1): for j in range(i): if a[j]>a[j+1]: a[j],a[j+1]=a[j+1],a[j] print(j+1,j+2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var A : Sequence := a->sort() ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( for j : Integer.subrange(0, i-1) do ( if (a[j+1]->compareTo(a[j + 1+1])) > 0 then ( var a[j+1] : OclAny := null; var a[j + 1+1] : OclAny := null; Sequence{a[j+1],a[j + 1+1]} := Sequence{a[j + 1+1],a[j+1]} ; execute (j + 1)->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) for i in range(n-1,0,-1): for j in range(i): if arr[j]>arr[j+1]: arr[j],arr[j+1]=arr[j+1],arr[j] print(j+1,j+2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( for j : Integer.subrange(0, i-1) do ( if (arr[j+1]->compareTo(arr[j + 1+1])) > 0 then ( var arr[j+1] : OclAny := null; var arr[j + 1+1] : OclAny := null; Sequence{arr[j+1],arr[j + 1+1]} := Sequence{arr[j + 1+1],arr[j+1]} ; execute (j + 1)->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import heapq def case(): N=int(sys.stdin.readline()) vines=[] for i in range(0,N): vines.append([int(x)for x in sys.stdin.readline().split()]) D=int(sys.stdin.readline()) vines.append([D,0]) reach=[-1 for i in range(0,N+1)] reach[0]=vines[0][0] for i in range(0,N+1): for j in range(i+1,N+1): if vines[j][0]>vines[i][0]+reach[i]: break r=min(vines[j][1],vines[j][0]-vines[i][0]) if r>reach[j]: reach[j]=r if reach[N]!=-1 : return "YES" return "NO" T=int(sys.stdin.readline()) for i in range(1,T+1): r=case() print("Case #%s: %s" %(i,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(1, T + 1-1) do ( r := case() ; execute (StringLib.format("Case #%s: %s",Sequence{i, r}))->display()); operation case() : OclAny pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var vines : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute ((sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) : vines)) ; var D : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((Sequence{D}->union(Sequence{ 0 })) : vines) ; var reach : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (-1)) ; reach->first() := vines->first()->first() ; for i : Integer.subrange(0, N + 1-1) do ( for j : Integer.subrange(i + 1, N + 1-1) do ( if (vines[j+1]->first()->compareTo(vines[i+1]->first() + reach[i+1])) > 0 then ( break ) else skip ; var r : OclAny := Set{vines[j+1][1+1], vines[j+1]->first() - vines[i+1]->first()}->min() ; if (r->compareTo(reach[j+1])) > 0 then ( reach[j+1] := r ) else skip)) ; if reach[N+1] /= -1 then ( return "YES" ) else skip ; return "NO"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) w=list(map(int,input().split())) for i in range(n): m=w.index(min(w)) for _ in range(m): print(m+i-_,m+i+1-_) w=w[: m]+w[m+1 :] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( var m : int := w->indexOf((w)->min()) - 1 ; for _anon : Integer.subrange(0, m-1) do ( execute (m + i - _anon)->display()) ; w := w.subrange(1,m) + w.subrange(m + 1+1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) for i in reversed(range(n)): for j in range(i): if a[j]>a[j+1]: a[j],a[j+1]=a[j+1],a[j] print(j+1,j+2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : (Integer.subrange(0, n-1))->reverse() do ( for j : Integer.subrange(0, i-1) do ( if (a[j+1]->compareTo(a[j + 1+1])) > 0 then ( var a[j+1] : OclAny := null; var a[j + 1+1] : OclAny := null; Sequence{a[j+1],a[j + 1+1]} := Sequence{a[j + 1+1],a[j+1]} ; execute (j + 1)->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000000 prime=[True for i in range(MAX+1)] def sieve(): prime[0],prime[1]=False,False for p in range(2,MAX+1): if p*p>MAX : break if(prime[p]==True): for i in range(2*p,MAX+1,p): prime[i]=False def distinctSum(arr1,arr2,m,n): sieve() sumSet=dict() for i in range(m): for j in range(n): if(prime[arr1[i]]and prime[arr2[j]]): sumSet[arr1[i]+arr2[j]]=1 return len(sumSet) arr1=[2,3] arr2=[2,2,4,7] m=len(arr1) n=len(arr2) print(distinctSum(arr1,arr2,m,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1000000 ; var prime : Sequence := Integer.subrange(0, MAX + 1-1)->select(i | true)->collect(i | (true)) ; skip ; skip ; arr1 := Sequence{2}->union(Sequence{ 3 }) ; arr2 := Sequence{2}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 7 }))) ; m := (arr1)->size() ; n := (arr2)->size() ; execute (distinctSum(arr1, arr2, m, n))->display(); operation sieve() pre: true post: true activity: var prime->first() : OclAny := null; var prime[1+1] : OclAny := null; Sequence{prime->first(),prime[1+1]} := Sequence{false,false} ; for p : Integer.subrange(2, MAX + 1-1) do ( if (p * p->compareTo(MAX)) > 0 then ( break ) else skip ; if (prime[p+1] = true) then ( for i : Integer.subrange(2 * p, MAX + 1-1)->select( $x | ($x - 2 * p) mod p = 0 ) do ( prime[i+1] := false) ) else skip); operation distinctSum(arr1 : OclAny, arr2 : OclAny, m : OclAny, n : OclAny) : OclAny pre: true post: true activity: sieve() ; var sumSet : Map := (arguments ( )) ; for i : Integer.subrange(0, m-1) do ( for j : Integer.subrange(0, n-1) do ( if (prime[arr1[i+1]+1] & prime[arr2[j+1]+1]) then ( sumSet[arr1[i+1] + arr2[j+1]+1] := 1 ) else skip)) ; return (sumSet)->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tt=int(input()) for t in range(tt): n,m=input().split() n,m=int(n),int(m) used=[False]*(n+1) for r in range(m): a,b,c=input().split() a,b,c=int(a),int(b),int(c) used[b]=True root=0 for r in range(1,n+1): if not used[r]: root=r break for r in range(1,n+1): if r!=root : print(root,r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var tt : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(0, tt-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split() ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{("" + ((n)))->toInteger(),("" + ((m)))->toInteger()} ; var used : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (n + 1)) ; for r : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := input().split() ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{("" + ((a)))->toInteger(),("" + ((b)))->toInteger(),("" + ((c)))->toInteger()} ; used[b+1] := true) ; var root : int := 0 ; for r : Integer.subrange(1, n + 1-1) do ( if not(used[r+1]) then ( root := r ; break ) else skip) ; for r : Integer.subrange(1, n + 1-1) do ( if r /= root then ( execute (root)->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n,m=map(int,input().split()) d=[0]*n for i in range(m): a,b,c=map(int,input().split()) d[b-1]=1 for i in range(n): if d[i]==0 : for j in range(n): if j!=i : print(i+1,j+1) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; d[b - 1+1] := 1) ; for i : Integer.subrange(0, n-1) do ( if d[i+1] = 0 then ( for j : Integer.subrange(0, n-1) do ( if j /= i then ( execute (i + 1)->display() ) else skip) ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for w in range(0,int(input())): [n,m]=[int(x)for x in input().split()] used=[0]*n for l in range(m): used[int(input().split()[1])-1]=1 center=used.index(0)+1 for i in range(1,n+1): if i!=center : print(i,center) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for w : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( ; Sequence{n}->union(Sequence{ m }) := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var used : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for l : Integer.subrange(0, m-1) do ( used[("" + ((input().split()[1+1])))->toInteger() - 1+1] := 1) ; var center : int := used->indexOf(0) - 1 + 1 ; for i : Integer.subrange(1, n + 1-1) do ( if i /= center then ( execute (i)->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def bfs(s): q,k=[s],0 visit=[0]*(n+1) visit[s]=1 child=[[]for _ in range(n+1)] while len(q)^ k : i=q[k] for j in G[i]: if not visit[j]: q.append(j) visit[j]=1 child[i].append(j) k+=1 return q,child n=int(input()) mod=998244353 l=n+5 fact=[1]*(l+1) for i in range(1,l+1): fact[i]=i*fact[i-1]% mod G=[[]for _ in range(n+1)] for _ in range(n-1): u,v=map(int,input().split()) G[u].append(v) G[v].append(u) p,child=bfs(1) dp=[1]*(n+1) for i in reversed(p): c=fact[len(child[i])+1] for j in child[i]: c*=dp[j] c %=mod dp[i]=c ans=dp[1]*pow(len(child[1])+1,mod-2,mod)% mod*n % mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mod : int := 998244353 ; var l : int := n + 5 ; var fact : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (l + 1)) ; for i : Integer.subrange(1, l + 1-1) do ( fact[i+1] := i * fact[i - 1+1] mod mod) ; var G : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, n - 1-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)))))))) ))))) ; var p : OclAny := null; Sequence{p,child} := bfs(1) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ; for i : (p)->reverse() do ( var c : OclAny := fact[(child[i+1])->size() + 1+1] ; for j : child[i+1] do ( c := c * dp[j+1] ; c := c mod mod) ; dp[i+1] := c) ; var ans : int := dp[1+1] * ((child[1+1])->size() + 1)->pow(mod - 2) mod mod * n mod mod ; execute (ans)->display(); operation bfs(s : OclAny) : OclAny pre: true post: true activity: var q : OclAny := null; var k : OclAny := null; Sequence{q,k} := Sequence{Sequence{ s },0} ; var visit : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; visit[s+1] := 1 ; var child : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; while MathLib.bitwiseXor((q)->size(), k) do ( var i : OclAny := q[k+1] ; for j : G[i+1] do ( if not(visit[j+1]) then ( execute ((j) : q) ; visit[j+1] := 1 ; (expr (atom (name child)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) ) else skip) ; k := k + 1) ; return q, child; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math t=int(input()) for i in range(0,t): n,k=[int(x)for x in input().split()] count=1 time=0 no_of_data_comp=1 if n>=k : time=len(bin(k)[2 :]) no_of_data_comp=2**(time) left=n-no_of_data_comp if left % k==0 : time+=(left//k) else : time+=(left//k)+1 print(time) else : time=len(bin(n)[2 :]) print(time) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var count : int := 1 ; var time : int := 0 ; var no_of_data_comp : int := 1 ; if (n->compareTo(k)) >= 0 then ( time := (bin(k).subrange(2+1))->size() ; no_of_data_comp := (2)->pow((time)) ; var left : double := n - no_of_data_comp ; if left mod k = 0 then ( time := time + (left div k) ) else ( time := time + (left div k) + 1 ) ; execute (time)->display() ) else ( time := (bin(n).subrange(2+1))->size() ; execute (time)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=[*input()] d=0 for i in range(n-2): if m[i]==m[i+1]==m[i+2]=='x' : d+=1 print(d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : Sequence := (OclFile["System.in"]).readLine() ; var d : int := 0 ; for i : Integer.subrange(0, n - 2-1) do ( if m[i+1] = m[i + 1+1] & (m[i + 1+1] == m[i + 2+1]) & (m[i + 2+1] == 'x') then ( d := d + 1 ) else skip) ; execute (d)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.buffer.readline mod=998244353 ans=1 n=int(input()) adj=[0]*(n+1) for i in range(n-1): a,b=map(int,input().split()) adj[a]+=1 adj[b]+=1 fact=[1]*(n) for i in range(2,n): fact[i]=(fact[i-1]*i)% mod for i in adj[1 :]: ans=(ans*fact[i])% mod print((n*ans)% mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := sys.stdin.buffer.readline ; var mod : int := 998244353 ; var ans : int := 1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var adj : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(0, n - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; adj[a+1] := adj[a+1] + 1 ; adj[b+1] := adj[b+1] + 1) ; var fact : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n)) ; for i : Integer.subrange(2, n-1) do ( fact[i+1] := (fact[i - 1+1] * i) mod mod) ; for i : adj->tail() do ( ans := (ans * fact[i+1]) mod mod) ; execute ((n * ans) mod mod)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() n=int(input()) exec('b=['+n*'input(),'+']') c=[*zip(*b)] print('NYOE S'[s in b or(s[0]in c[1]and s[1]in c[0]): : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (expr (expr (expr (atom 'b=[')) + (expr (expr (atom (name n))) * (expr (atom 'input(),')))) + (expr (atom ']'))) ; var c : Sequence := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name b)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name b)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name b)))))))`third->at(_indx)} ) ; execute ('NYOE S'(subscript (test (logical_test (logical_test (comparison (comparison (expr (atom (name s)))) in (comparison (expr (atom (name b)))))) or (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) in (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))) and (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) in (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))))) ))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- key=input() k=int(input()) words=[] for _ in range(k): words.append(input()) for i in range(k): for j in range(k): if key in(words[i]+words[j]): print('YES') exit(0) print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var key : String := (OclFile["System.in"]).readLine() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var words : Sequence := Sequence{} ; for _anon : Integer.subrange(0, k-1) do ( execute (((OclFile["System.in"]).readLine()) : words)) ; for i : Integer.subrange(0, k-1) do ( for j : Integer.subrange(0, k-1) do ( if ((words[i+1] + words[j+1]))->includes(key) then ( execute ('YES')->display() ; exit(0) ) else skip)) ; execute ('NO')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPalindrome(num): s=str(num) low=0 high=len(s)-1 while(lowdisplay() ) else ( execute ("No")->display() ); operation isPalindrome(num : OclAny) : OclAny pre: true post: true activity: var s : String := ("" + ((num))) ; var low : int := 0 ; var high : double := (s)->size() - 1 ; while ((low->compareTo(high)) < 0) do ( if (s[low+1] /= s[high+1]) then ( return false ) else skip ; low := low + 1 ; high := high - 1) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p=input() n=int(input()) ss=set() for _ in range(n): s=input() ss.add(s) l=list(ss) if p in l or("".join(reversed(sorted(p)))in l): print("YES") exit() else : for i in range(len(l)): for j in range(i,len(l)): if(p[0]==l[i][1]and p[1]==l[j][0])or(p[0]==l[j][1]and p[1]==l[i][0]): print("YES") exit() print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : String := (OclFile["System.in"]).readLine() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ss : Set := Set{}->union(()) ; for _anon : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; execute ((s) : ss)) ; var l : Sequence := (ss) ; if (l)->includes(p) or ((l)->includes(StringLib.sumStringsWithSeparator(((p->sort())->reverse()), ""))) then ( execute ("YES")->display() ; exit() ) else ( for i : Integer.subrange(0, (l)->size()-1) do ( for j : Integer.subrange(i, (l)->size()-1) do ( if (p->first() = l[i+1][1+1] & p[1+1] = l[j+1]->first()) or (p->first() = l[j+1][1+1] & p[1+1] = l[i+1]->first()) then ( execute ("YES")->display() ; exit() ) else skip)) ) ; execute ("NO")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() n=int(input()) exec('b=['+n*'input(),'+']') c=[*zip(*b)] print('NYOE S'[s in b or(s[0]in c[1]and s[1]in c[0]): : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (expr (expr (expr (atom 'b=[')) + (expr (expr (atom (name n))) * (expr (atom 'input(),')))) + (expr (atom ']'))) ; var c : Sequence := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name b)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name b)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name b)))))))`third->at(_indx)} ) ; execute ('NYOE S'(subscript (test (logical_test (logical_test (comparison (comparison (expr (atom (name s)))) in (comparison (expr (atom (name b)))))) or (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) in (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))) and (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) in (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))))) ))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() n=int(input()) exec('b=['+n*'input(),'+']') c=[*zip(*b)] print('NYOE S'[s in b or(s[0]in c[1]and s[1]in c[0]): : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (expr (expr (expr (atom 'b=[')) + (expr (expr (atom (name n))) * (expr (atom 'input(),')))) + (expr (atom ']'))) ; var c : Sequence := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name b)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name b)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name b)))))))`third->at(_indx)} ) ; execute ('NYOE S'(subscript (test (logical_test (logical_test (comparison (comparison (expr (atom (name s)))) in (comparison (expr (atom (name b)))))) or (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) in (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))) and (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) in (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))))) ))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(x)for x in input().split()] a.append(0) b=0 for i in range(0,n+1): if a[i]<0 : print("NO") b=1 break else : if a[i]% 2==0 : a[i]=0 else : a[i]=0 a[i+1]-=1 if b==0 : sum=0 for j in range(0,n): sum+=a[j] if sum==0 : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((0) : a) ; var b : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( if a[i+1] < 0 then ( execute ("NO")->display() ; b := 1 ; break ) else ( if a[i+1] mod 2 = 0 then ( a[i+1] := 0 ) else ( a[i+1] := 0 ; a[i + 1+1] := a[i + 1+1] - 1 ) )) ; if b = 0 then ( var sum : int := 0 ; for j : Integer.subrange(0, n-1) do ( sum := sum + a[j+1]) ; if sum = 0 then ( execute ("YES")->display() ) else skip ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) b=input().split(" ") k=0 a=[0] for i in range(0,n): a.append(int(b[i])) for i in range(1,n): if((a[i]-k)& 1): k=1 else : k=0 if(a[i]==0 and k!=0): print("NO\n") return if((a[n]-k)& 1): print("NO\n") else : print("YES\n") if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : OclAny := input().split(" ") ; var k : int := 0 ; var a : Sequence := Sequence{ 0 } ; for i : Integer.subrange(0, n-1) do ( execute ((("" + ((b[i+1])))->toInteger()) : a)) ; for i : Integer.subrange(1, n-1) do ( if (MathLib.bitwiseAnd((a[i+1] - k), 1)) then ( k := 1 ) else ( k := 0 ) ; if (a[i+1] = 0 & k /= 0) then ( execute ("NO\n")->display() ; return ) else skip) ; if (MathLib.bitwiseAnd((a[n+1] - k), 1)) then ( execute ("NO\n")->display() ) else ( execute ("YES\n")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) w=list(map(int,input().split())) ans='YES' for i in range(n-1): if w[i]% 2 : if w[i+1]==0 : ans="NO" break else : w[i+1]+=1 if w[-1]% 2 : ans="NO" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : String := 'YES' ; for i : Integer.subrange(0, n - 1-1) do ( if w[i+1] mod 2 then ( if w[i + 1+1] = 0 then ( ans := "NO" ; break ) else ( w[i + 1+1] := w[i + 1+1] + 1 ) ) else skip) ; if w->last() mod 2 then ( ans := "NO" ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def segregate(arr,size): j=0 for i in range(size): if(arr[i]<=0): arr[i],arr[j]=arr[j],arr[i] j+=1 return j def findMissingPositive(arr,size): for i in range(size): if(abs(arr[i])-10): arr[abs(arr[i])-1]=-arr[abs(arr[i])-1] for i in range(size): if(arr[i]>0): return i+1 return size+1 def findMissing(arr,size): shift=segregate(arr,size) return findMissingPositive(arr[shift :],size-shift) arr=[0,10,2,-10,-20] arr_size=len(arr) missing=findMissing(arr,arr_size) print("The smallest positive missing number is ",missing) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; arr := Sequence{0}->union(Sequence{10}->union(Sequence{2}->union(Sequence{-10}->union(Sequence{ -20 })))) ; var arr_size : int := (arr)->size() ; var missing : OclAny := findMissing(arr, arr_size) ; execute ("The smallest positive missing number is ")->display(); operation segregate(arr : OclAny, size : OclAny) : OclAny pre: true post: true activity: var j : int := 0 ; for i : Integer.subrange(0, size-1) do ( if (arr[i+1] <= 0) then ( var arr[i+1] : OclAny := null; var arr[j+1] : OclAny := null; Sequence{arr[i+1],arr[j+1]} := Sequence{arr[j+1],arr[i+1]} ; j := j + 1 ) else skip) ; return j; operation findMissingPositive(arr : OclAny, size : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, size-1) do ( if (((arr[i+1])->abs() - 1->compareTo(size)) < 0 & arr[(arr[i+1])->abs() - 1+1] > 0) then ( arr[(arr[i+1])->abs() - 1+1] := -arr[(arr[i+1])->abs() - 1+1] ) else skip) ; for i : Integer.subrange(0, size-1) do ( if (arr[i+1] > 0) then ( return i + 1 ) else skip) ; return size + 1; operation findMissing(arr : OclAny, size : OclAny) : OclAny pre: true post: true activity: var shift : OclAny := segregate(arr, size) ; return findMissingPositive(arr.subrange(shift+1), size - shift); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input I() a=0 for x in map(int,I().split()): x-=a ; a=x % 2 if x<0 : break print('YNEOS'[a : : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; I() ; var a : int := 0 ; for x : (I().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( x := x - a; a := x mod 2 ; if x < 0 then ( break ) else skip) ; execute ('YNEOS'(subscript (test (logical_test (comparison (expr (atom (name a)))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) for i in range(n-1): if a[i]<0 : print("NO") break a[i+1]-=a[i]% 2 else : print("YES" if a[-1]% 2==0 else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) < (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) % (expr (atom (number (integer 2)))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES")))) if (logical_test (comparison (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 0))))))) else (test (logical_test (comparison (expr (atom "NO")))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() n=int(input()) my_list=list() my_set=set() for elem in s : if elem not in my_set : my_list.append([elem,1]) my_set.add(elem) else : ind=0 while indmax_ : max_=m my_index=i help_list[my_index]+=1 ind+=1 max_=0 s="" for i,elem in enumerate(help_list): s+=elem*my_list[i][0] m=my_list[i][1]//help_list[i] if my_list[i][1]% help_list[i]!=0 : m+=1 if m>max_ : max_=m print(max_) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var my_list : Sequence := () ; var my_set : Set := Set{}->union(()) ; for elem : s->characters() do ( if (my_set)->excludes(elem) then ( execute ((Sequence{elem}->union(Sequence{ 1 })) : my_list) ; execute ((elem) : my_set) ) else ( var ind : int := 0 ; while (ind->compareTo((my_list)->size())) < 0 do ( if elem = my_list[ind+1]->first() then ( break ) else skip ; ind := ind + 1) ; my_list[ind+1][1+1] := my_list[ind+1][1+1] + 1 )) ; var help_list : Sequence := Integer.subrange(0, (my_list)->size()-1)->select(i | true)->collect(i | (1)) ; var max_ : int := 0 ; var r : double := n - (my_list)->size() ; if (n->compareTo((my_list)->size())) < 0 then ( execute (-1)->display() ) else ( ind := 0 ; while (ind->compareTo(r)) < 0 do ( max_ := 0 ; for _tuple : Integer.subrange(1, (help_list)->size())->collect( _indx | Sequence{_indx-1, (help_list)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var elem : OclAny := _tuple->at(_indx); var m : int := my_list[i+1][1+1] div help_list[i+1] ; if my_list[i+1][1+1] mod help_list[i+1] /= 0 then ( m := m + 1 ) else skip ; if (m->compareTo(max_)) > 0 then ( max_ := m ; var my_index : OclAny := i ) else skip) ; help_list[my_index+1] := help_list[my_index+1] + 1 ; ind := ind + 1) ; max_ := 0 ; s := "" ; for _tuple : Integer.subrange(1, (help_list)->size())->collect( _indx | Sequence{_indx-1, (help_list)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var elem : OclAny := _tuple->at(_indx); s := s + elem * my_list[i+1]->first() ; m := my_list[i+1][1+1] div help_list[i+1] ; if my_list[i+1][1+1] mod help_list[i+1] /= 0 then ( m := m + 1 ) else skip ; if (m->compareTo(max_)) > 0 then ( max_ := m ) else skip) ; execute (max_)->display() ; execute (s)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter,defaultdict from itertools import accumulate R=lambda : map(int,input().split()) s=input() n=int(input()) if len(Counter(s))>n : print(-1) exit(0) l,r=1,1000 while ln : l=mid+1 else : r=mid print(l) res=''.join(c*((cnt+l-1)//l)for c,cnt in Counter(s).items()) print(res+'a'*(n-len(res))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : String := (OclFile["System.in"]).readLine() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if ((Counter(s))->size()->compareTo(n)) > 0 then ( execute (-1)->display() ; exit(0) ) else skip ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{1,1000} ; while (l->compareTo(r)) < 0 do ( var mid : int := (l + r) div 2 ; var lenreq : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name cnt))) + (expr (atom (name mid)))) - (expr (atom (number (integer 1))))))))) ))) // (expr (atom (name mid))))))) (comp_for for (exprlist (expr (atom (name c))) , (expr (atom (name cnt)))) in (logical_test (comparison (expr (atom (name Counter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))) (trailer . (name items) (arguments ( )))))))))->sum() ; if (lenreq->compareTo(n)) > 0 then ( var l : int := mid + 1 ) else ( var r : int := mid )) ; execute (l)->display() ; var res : String := StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (expr (atom (name c))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name cnt))) + (expr (atom (name l)))) - (expr (atom (number (integer 1))))))))) ))) // (expr (atom (name l)))))))) ))))))) (comp_for for (exprlist (expr (atom (name c))) , (expr (atom (name cnt)))) in (logical_test (comparison (expr (atom (name Counter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))) (trailer . (name items) (arguments ( ))))))))), '') ; execute (res + StringLib.nCopies('a', (n - (res)->size())))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def squareDigitSum(num): lengthN=len(num) result=(lengthN//9)*81+(lengthN % 9)**2 return result if __name__=="__main__" : N="1111" print(squareDigitSum(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var N : String := "1111" ; execute (squareDigitSum(N))->display() ) else skip; operation squareDigitSum(num : OclAny) : OclAny pre: true post: true activity: var lengthN : int := (num)->size() ; var result : int := (lengthN div 9) * 81 + ((lengthN mod 9))->pow(2) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() n=int(input()) import math my_dict={} for l in s : if l in my_dict : my_dict[l]+=1 else : my_dict[l]=1 for i in range(1,2000): good=0 for key,num in my_dict.items(): good+=(num+i-1)//i if good<=n : print(i) s='' for key,num in my_dict.items(): s+=key*((num+i-1)//i) if len(s)toInteger() ; skip ; var my_dict : OclAny := Set{} ; for l : s->characters() do ( if (my_dict)->includes(l) then ( my_dict[l+1] := my_dict[l+1] + 1 ) else ( my_dict[l+1] := 1 )) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2000))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name good)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name key))) , (expr (atom (name num)))) in (testlist (test (logical_test (comparison (expr (atom (name my_dict)) (trailer . (name items) (arguments ( )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name good)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name num))) + (expr (atom (name i)))) - (expr (atom (number (integer 1))))))))) ))) // (expr (atom (name i))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name good)))) <= (comparison (expr (atom (name n))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom ''))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name key))) , (expr (atom (name num)))) in (testlist (test (logical_test (comparison (expr (atom (name my_dict)) (trailer . (name items) (arguments ( )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name key))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name num))) + (expr (atom (name i)))) - (expr (atom (number (integer 1))))))))) ))) // (expr (atom (name i)))))))) ))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))) < (comparison (expr (atom (name n))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom 'a')) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))))) ))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter from math import ceil s=input() n=int(input()) counter_str=Counter(s) def get_sticker_len(list_num,counter : dict): alpha_per_sticker=[ceil(count/list_num)for alpha,count in counter.items()] sticker_len=sum(alpha_per_sticker) return sticker_len def get_sticker(list_num,counter): alphas=[alpha*ceil(count/list_num)for alpha,count in counter.items()] sticker=''.join(alphas) sticker+=s[0]*(n-len(sticker)) return sticker def is_sticker_with_cur_list_num_fitted(list_num): true_len=get_sticker_len(list_num,counter_str) return int(true_len<=n) def bin_search(f,l,r): while l+1toInteger() ; var counter_str : OclAny := Counter(s) ; skip ; skip ; skip ; skip ; var ans : OclAny := bin_search(is_sticker_with_cur_list_num_fitted, 0, (s)->size() + 1) ; if ans = (s)->size() + 1 then ( execute (-1)->display() ) else ( execute (ans)->display() ; execute (get_sticker(ans, counter_str))->display() ); operation get_sticker_len(list_num : OclAny, counter : Map(String,OclAny)) : OclAny pre: true post: true activity: var alpha_per_sticker : Sequence := counter->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->select(_tuple | true)->collect(_tuple | let alpha : OclAny = _tuple->at(1) in let count : OclAny = _tuple->at(2) in (ceil(count / list_num))) ; var sticker_len : OclAny := (alpha_per_sticker)->sum() ; return sticker_len; operation get_sticker(list_num : OclAny, counter : OclAny) : OclAny pre: true post: true activity: var alphas : Sequence := counter->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->select(_tuple | true)->collect(_tuple | let alpha : OclAny = _tuple->at(1) in let count : OclAny = _tuple->at(2) in (alpha * ceil(count / list_num))) ; var sticker : String := StringLib.sumStringsWithSeparator((alphas), '') ; sticker := sticker + s->first() * (n - (sticker)->size()) ; return sticker; operation is_sticker_with_cur_list_num_fitted(list_num : OclAny) : OclAny pre: true post: true activity: var true_len : OclAny := get_sticker_len(list_num, counter_str) ; return ("" + (((true_len->compareTo(n)) <= 0)))->toInteger(); operation bin_search(f : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: while (l + 1->compareTo(r)) < 0 do ( var mid : int := (l + r) div 2 ; if f(mid) = 0 then ( l := mid ) else ( r := mid )) ; return r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isOperand(x): return((x>='a' and x<='z')or(x>='A' and x<='Z')) def getInfix(exp): s=[] for i in exp : if(isOperand(i)): s.insert(0,i) else : op1=s[0] s.pop(0) op2=s[0] s.pop(0) s.insert(0,"("+op2+i+op1+")") return s[0] if __name__=='__main__' : exp="ab*c+" print(getInfix(exp.strip())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( exp := "ab*c+" ; execute (getInfix(exp->trim()))->display() ) else skip; operation isOperand(x : OclAny) : OclAny pre: true post: true activity: return ((x >= 'a' & x <= 'z') or (x >= 'A' & x <= 'Z')); operation getInfix(exp : OclAny) : OclAny pre: true post: true activity: var s : Sequence := Sequence{} ; for i : exp do ( if (isOperand(i)) then ( s := s.insertAt(0+1, i) ) else ( var op1 : OclAny := s->first() ; s := s->excludingAt(0+1) ; var op2 : OclAny := s->first() ; s := s->excludingAt(0+1) ; s := s.insertAt(0+1, "(" + op2 + i + op1 + ")") )) ; return s->first(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- L=['SUN','MON','TUE','WED','THU','FRI','SAT'] S=str(input()) N=L.index(S) if N==0 : print(7) else : print(7-N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var L : Sequence := Sequence{'SUN'}->union(Sequence{'MON'}->union(Sequence{'TUE'}->union(Sequence{'WED'}->union(Sequence{'THU'}->union(Sequence{'FRI'}->union(Sequence{ 'SAT' })))))) ; var S : String := ("" + (((OclFile["System.in"]).readLine()))) ; var N : int := L->indexOf(S) - 1 ; if N = 0 then ( execute (7)->display() ) else ( execute (7 - N)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin ni=lambda : int(ns()) na=lambda : list(map(int,stdin.readline().split())) ns=lambda : stdin.readline().rstrip() s=input() li=['SUN','MON','TUE','WED','THU','FRI','SAT'] print(7-li.index(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stdin : OclFile := OclFile["System.in"] ; var ni : Function := lambda $$ : OclAny in (("" + ((ns())))->toInteger()) ; var na : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ns : Function := lambda $$ : OclAny in (stdin.readLine().rstrip()) ; var s : String := (OclFile["System.in"]).readLine() ; var li : Sequence := Sequence{'SUN'}->union(Sequence{'MON'}->union(Sequence{'TUE'}->union(Sequence{'WED'}->union(Sequence{'THU'}->union(Sequence{'FRI'}->union(Sequence{ 'SAT' })))))) ; execute (7 - li->indexOf(s) - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(chr(ord(input())+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((((OclFile["System.in"]).readLine())->char2byte() + 1)->byte2char())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x={"SAT" : 1,"FRI" : 2,"THU" : 3,"WED" : 4,"TUE" : 5,"MON" : 6,"SUN" : 7} day=input().strip() print(x[day]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : Map := Map{ "SAT" |-> 1 }->union(Map{ "FRI" |-> 2 }->union(Map{ "THU" |-> 3 }->union(Map{ "WED" |-> 4 }->union(Map{ "TUE" |-> 5 }->union(Map{ "MON" |-> 6 }->union(Map{ "SUN" |-> 7 })))))) ; var day : OclAny := input()->trim() ; execute (x[day+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() res=-1 if s=="SUN" : res=7 if s=="MON" : res=6 if s=="TUE" : res=5 if s=="WED" : res=4 if s=="THU" : res=3 if s=="FRI" : res=2 if s=="SAT" : res=1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var res : int := -1 ; if s = "SUN" then ( res := 7 ) else skip ; if s = "MON" then ( res := 6 ) else skip ; if s = "TUE" then ( res := 5 ) else skip ; if s = "WED" then ( res := 4 ) else skip ; if s = "THU" then ( res := 3 ) else skip ; if s = "FRI" then ( res := 2 ) else skip ; if s = "SAT" then ( res := 1 ) else skip ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=str(input()) if S=='SAT' : print(1) elif S=='FRI' : print(2) elif S=='THU' : print(3) elif S=='WED' : print(4) elif S=='TUE' : print(5) elif S=='MON' : print(6) elif S=='SUN' : print(7) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := ("" + (((OclFile["System.in"]).readLine()))) ; if S = 'SAT' then ( execute (1)->display() ) else (if S = 'FRI' then ( execute (2)->display() ) else (if S = 'THU' then ( execute (3)->display() ) else (if S = 'WED' then ( execute (4)->display() ) else (if S = 'TUE' then ( execute (5)->display() ) else (if S = 'MON' then ( execute (6)->display() ) else (if S = 'SUN' then ( execute (7)->display() ) else skip ) ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def prevNum(string,n): index=-1 for i in range(n-2,-1,-1): if int(string[i])>int(string[i+1]): index=i break smallGreatDgt=-1 for i in range(n-1,index,-1): if(smallGreatDgt==-1 and int(string[i])-1 and int(string[i])>=int(string[smallGreatDgt])and int(string[i])reverse() do ( if (("" + ((string[i+1])))->toInteger()->compareTo(("" + ((string[i + 1+1])))->toInteger())) > 0 then ( index := i ; break ) else skip) ; var smallGreatDgt : int := -1 ; for i : Integer.subrange(index + 1, n - 1)->reverse() do ( if (smallGreatDgt = -1 & (("" + ((string[i+1])))->toInteger()->compareTo(("" + ((string[index+1])))->toInteger())) < 0) then ( smallGreatDgt := i ) else (if (index > -1 & (("" + ((string[i+1])))->toInteger()->compareTo(("" + ((string[smallGreatDgt+1])))->toInteger())) >= 0 & (("" + ((string[i+1])))->toInteger()->compareTo(("" + ((string[index+1])))->toInteger())) < 0) then ( smallGreatDgt := i ) else skip)) ; if index = -1 then ( return StringLib.sumStringsWithSeparator(("-1"), "") ) else ( suite ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isOperand(c): return(c>='0' and c<='9'); def value(c): return ord(c)-ord('0'); def evaluate(exp): len1=len(exp); if(len1==0): return-1 ; res=value(exp[0]); for i in range(1,len1,2): opr=exp[i]; opd=exp[i+1]; if(isOperand(opd)==False): return-1 ; if(opr=='+'): res+=value(opd); elif(opr=='-'): res-=int(value(opd)); elif(opr=='*'): res*=int(value(opd)); elif(opr=='/'): res/=int(value(opd)); else : return-1 ; return res ; expr1="1+2*5+3" ; res=evaluate(expr1); print(expr1,"is Invalid")if(res==-1)else print("Value of",expr1,"is",res); expr2="1+2*3" ; res=evaluate(expr2); print(expr2,"is Invalid")if(res==-1)else print("Value of",expr2,"is",res); expr3="4-2+6*3" ; res=evaluate(expr3); print(expr3,"is Invalid")if(res==-1)else print("Value of",expr3,"is",res); expr4="1++2" ; res=evaluate(expr4); print(expr4,"is Invalid")if(res==-1)else print("Value of",expr4,"is",res); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var expr1 : String := "1+2*5+3"; ; res := evaluate(expr1); ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name expr1))))))) , (argument (test (logical_test (comparison (expr (atom "is Invalid"))))))) )))))) if (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name res)))) == (comparison (expr (atom - (number (integer 1))))))))) ))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Value of")))))) , (argument (test (logical_test (comparison (expr (atom (name expr1))))))) , (argument (test (logical_test (comparison (expr (atom "is")))))) , (argument (test (logical_test (comparison (expr (atom (name res)))))))) )))))))); ; var expr2 : String := "1+2*3"; ; res := evaluate(expr2); ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name expr2))))))) , (argument (test (logical_test (comparison (expr (atom "is Invalid"))))))) )))))) if (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name res)))) == (comparison (expr (atom - (number (integer 1))))))))) ))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Value of")))))) , (argument (test (logical_test (comparison (expr (atom (name expr2))))))) , (argument (test (logical_test (comparison (expr (atom "is")))))) , (argument (test (logical_test (comparison (expr (atom (name res)))))))) )))))))); ; var expr3 : String := "4-2+6*3"; ; res := evaluate(expr3); ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name expr3))))))) , (argument (test (logical_test (comparison (expr (atom "is Invalid"))))))) )))))) if (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name res)))) == (comparison (expr (atom - (number (integer 1))))))))) ))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Value of")))))) , (argument (test (logical_test (comparison (expr (atom (name expr3))))))) , (argument (test (logical_test (comparison (expr (atom "is")))))) , (argument (test (logical_test (comparison (expr (atom (name res)))))))) )))))))); ; var expr4 : String := "1++2"; ; res := evaluate(expr4); ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name expr4))))))) , (argument (test (logical_test (comparison (expr (atom "is Invalid"))))))) )))))) if (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name res)))) == (comparison (expr (atom - (number (integer 1))))))))) ))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Value of")))))) , (argument (test (logical_test (comparison (expr (atom (name expr4))))))) , (argument (test (logical_test (comparison (expr (atom "is")))))) , (argument (test (logical_test (comparison (expr (atom (name res)))))))) ))))))));; operation isOperand(c : OclAny) pre: true post: true activity: return (c >= '0' & c <= '9');; operation value(c : OclAny) pre: true post: true activity: return (c)->char2byte() - ('0')->char2byte();; operation evaluate(exp : OclAny) pre: true post: true activity: var len1 : int := (exp)->size(); ; if (len1 = 0) then ( return -1; ) else skip ; var res : OclAny := value(exp->first()); ; for i : Integer.subrange(1, len1-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( var opr : OclAny := exp[i+1]; ; var opd : OclAny := exp[i + 1+1]; ; if (isOperand(opd) = false) then ( return -1; ) else skip ; if (opr = '+') then ( res := res + value(opd); ) else (if (opr = '-') then ( res := res - ("" + ((value(opd))))->toInteger(); ) else (if (opr = '*') then ( res := res * ("" + ((value(opd))))->toInteger(); ) else (if (opr = '/') then ( res := res / ("" + ((value(opd))))->toInteger(); ) else ( return -1; ) ) ) ) ) ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumFirst(a,n): mp={i : 0 for i in range(7)} suf=0 i=n-1 while(i>=0): suf+=a[i] mp[suf]=i i-=1 pre=0 maxi=-1 for i in range(n): pre+=a[i] if(mp[pre]>i): if(pre>maxi): maxi=pre if(maxi==-1): return 0 else : return maxi if __name__=='__main__' : a=[1,3,2,1,4] n=len(a) print(sumFirst(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := Sequence{1}->union(Sequence{3}->union(Sequence{2}->union(Sequence{1}->union(Sequence{ 4 })))) ; n := (a)->size() ; execute (sumFirst(a, n))->display() ) else skip; operation sumFirst(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var mp : Map := Integer.subrange(0, 7-1)->select(i | true)->collect(i | Map{i |-> 0})->unionAll() ; var suf : int := 0 ; var i : double := n - 1 ; while (i >= 0) do ( suf := suf + a[i+1] ; mp[suf+1] := i ; i := i - 1) ; var pre : int := 0 ; var maxi : int := -1 ; for i : Integer.subrange(0, n-1) do ( pre := pre + a[i+1] ; if ((mp[pre+1]->compareTo(i)) > 0) then ( if ((pre->compareTo(maxi)) > 0) then ( maxi := pre ) else skip ) else skip) ; if (maxi = -1) then ( return 0 ) else ( return maxi ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def war(n,k): n=[float(block)for block in n.split(" ")] k=[float(block)for block in k.split(" ")] points=0 n=reversed(sorted(n)) for nblock in n : if nblock>max(k): points+=1 k.remove(min(k)) else : k.remove(min([block for block in k if block>nblock])) return str(points) def dwar(n,k): n=[float(block)for block in n.split(" ")] k=[float(block)for block in k.split(" ")] points=0 n=sorted(n) for nblock in n : if nblock>min(k): points+=1 k.remove(min(k)) else : k.remove(max(k)) return str(points) input_text=open("input.in") lines=input_text.readlines() input_text.close() with open("output","a")as outputfile : for num in range(0,int(lines[0])): outputfile.write("Case #"+str(num+1)+": "+dwar(lines[num*3+2],lines[num*3+3])+" "+war(lines[num*3+2],lines[num*3+3])+"\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input_text : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("input.in")) ; var lines : OclAny := input_text.readlines() ; input_text.closeFile() ; try (var outputfile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("output")); for num : Integer.subrange(0, ("" + ((lines->first())))->toInteger()-1) do ( outputfile.write("Case #" + ("" + ((num + 1))) + ": " + dwar(lines[num * 3 + 2+1], lines[num * 3 + 3+1]) + " " + war(lines[num * 3 + 2+1], lines[num * 3 + 3+1]) + "\n"))) catch (_e : OclException) do skip; operation war(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: n := n.split(" ")->select(block | true)->collect(block | (("" + ((block)))->toReal())) ; k := k.split(" ")->select(block | true)->collect(block | (("" + ((block)))->toReal())) ; var points : int := 0 ; n := (n->sort())->reverse() ; for nblock : n do ( if (nblock->compareTo((k)->max())) > 0 then ( points := points + 1 ; execute (((k)->min()) /: k) ) else ( execute (((k->select(block | (block->compareTo(nblock)) > 0)->collect(block | (block)))->min()) /: k) )) ; return ("" + ((points))); operation dwar(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: n := n.split(" ")->select(block | true)->collect(block | (("" + ((block)))->toReal())) ; k := k.split(" ")->select(block | true)->collect(block | (("" + ((block)))->toReal())) ; points := 0 ; n := n->sort() ; for nblock : n do ( if (nblock->compareTo((k)->min())) > 0 then ( points := points + 1 ; execute (((k)->min()) /: k) ) else ( execute (((k)->max()) /: k) )) ; return ("" + ((points))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import* from sys import argv,stdin,stdout,stderr Case=namedtuple('Case','naomi,ken') def readcase(f): blocks=int(next(f)) naomi=sorted(readfloats(f)) ken=sorted(readfloats(f)) assert blocks==len(ken)==len(naomi) return Case(naomi,ken) def solvecase(case): naomi,ken=case return '%d %d' %(liewar(ken=ken,naomi=naomi),war(ken=ken,naomi=naomi)) def war(ken,naomi): kenwins=0 kencursor=0 for nweight in naomi : while kencursornweight : kenwins+=1 kencursor+=1 break else : kencursor+=1 else : break return len(ken)-kenwins def liewar(ken,naomi): return len(ken)-war(naomi,ken) def readfloats(f): return list(map(float,next(f).split(' '))) def main(): with open(argv[1])as f,open(argv[2],'w')as out : cases=int(next(f)) for case in range(1,cases+1): print('Case #%d: %s' %(case,solvecase(readcase(f))),file=out) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var Case : OclAny := namedtuple('Case', 'naomi,ken') ; skip ; skip ; skip ; skip ; skip ; skip ; main(); operation readcase(f : OclAny) : OclAny pre: true post: true activity: var blocks : int := ("" + (((f).next())))->toInteger() ; var naomi : Sequence := readfloats(f)->sort() ; var ken : Sequence := readfloats(f)->sort() ; assert blocks = (ken)->size() & ((ken)->size() == (naomi)->size()) do "assertion failed" ; return Case(naomi, ken); operation solvecase(case : OclAny) : OclAny pre: true post: true activity: Sequence{naomi,ken} := case ; return StringLib.format('%d %d',Sequence{liewar((argument (test (logical_test (comparison (expr (atom (name ken)))))) = (test (logical_test (comparison (expr (atom (name ken))))))), (argument (test (logical_test (comparison (expr (atom (name naomi)))))) = (test (logical_test (comparison (expr (atom (name naomi)))))))), war((argument (test (logical_test (comparison (expr (atom (name ken)))))) = (test (logical_test (comparison (expr (atom (name ken))))))), (argument (test (logical_test (comparison (expr (atom (name naomi)))))) = (test (logical_test (comparison (expr (atom (name naomi))))))))}); operation war(ken : OclAny, naomi : OclAny) : OclAny pre: true post: true activity: var kenwins : int := 0 ; var kencursor : int := 0 ; for nweight : naomi do ((compound_stmt while (test (logical_test (comparison (comparison (expr (atom (name kencursor)))) < (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ken)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name ken)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name kencursor)))))))) ])))) > (comparison (expr (atom (name nweight))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name kenwins)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name kencursor)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt break)))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name kencursor)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt break))))))) ; return (ken)->size() - kenwins; operation liewar(ken : OclAny, naomi : OclAny) : OclAny pre: true post: true activity: return (ken)->size() - war(naomi, ken); operation readfloats(f : OclAny) : OclAny pre: true post: true activity: return ((next(f).split(' '))->collect( _x | (OclType["double"])->apply(_x) )); operation main() pre: true post: true activity: try (var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(argv[1+1])); var out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(argv[2+1])); var cases : int := ("" + (((f).next())))->toInteger() ; for case : Integer.subrange(1, cases + 1-1) do ( execute (StringLib.format('Case #%d: %s',Sequence{case, solvecase(readcase(f))}))->display())) catch (_e : OclException) do skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import itertools from operator import itemgetter import bisect import math import copy from fractions import gcd from utilities import* sys.setrecursionlimit(1000) Prep=[] def preprocess(): return None def readinput(Input): N=Input.readint() Naomi=Input.readfloats() Ken=Input.readfloats() Naomi.sort(reverse=True) Ken.sort(reverse=True) return Naomi,Ken def solve(Problem,Prep): Naomi,Ken=Problem if len(Naomi)==1 : if Naomi[0]>Ken[0]: return "1 1" else : return "0 0" N=Naomi[:] K=Ken[:] wins_fair=0 for i in range(len(N)): n=N.pop(0) if nsort() ; Ken := Ken->sort() ; return Naomi, Ken; operation solve(Problem : OclAny, Prep : OclAny) : OclAny pre: true post: true activity: Sequence{Naomi,Ken} := Problem ; if (Naomi)->size() = 1 then ( if (Naomi->first()->compareTo(Ken->first())) > 0 then ( return "1 1" ) else ( return "0 0" ) ) else skip ; N := Naomi ; var K : Sequence := Ken ; var wins_fair : int := 0 ; for i : Integer.subrange(0, (N)->size()-1) do ( var n : OclAny := N->at(0`firstArg+1) ; N := N->excludingAt(0+1) ; if (n->compareTo(K->first())) < 0 then ( K := K->excludingAt(0+1) ; continue ) else ( K := K->front() ; wins_fair := wins_fair + 1 )) ; N := Naomi ; K := Ken ; var wins_unfair : int := 0 ; for i : Integer.subrange(0, (N)->size()-1) do ( if (N->last()->compareTo(K->last())) < 0 then ( N := N->front() ; K := K->excludingAt(0+1) ) else ( N := N->front() ; K := K->front() ; wins_unfair := wins_unfair + 1 ; continue )) ; return ("" + ((wins_unfair))) + " " + ("" + ((wins_fair))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inputFile=open('D-large.in','r') lines=inputFile.readlines() inputFile.close() outputFile=open('D-large.out','w') numTests=int(lines[0]) def scoreWar(naomiNums,kenNums): naomiInd=0 kenInd=0 while naomiIndfirst())))->toInteger() ; skip ; skip ; for i : Integer.subrange(1, numTests + 1-1) do ( naomiNums := (lines[3 * i - 1+1].split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toReal()))->apply(_x) ) ; kenNums := (lines[3 * i+1].split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toReal()))->apply(_x) ) ; naomiNums := naomiNums->sort() ; kenNums := kenNums->sort() ; var deceitScore : OclAny := scoreDeceit(naomiNums, kenNums) ; var warScore : OclAny := scoreWar(naomiNums, kenNums) ; outputFile.write('Case #' + ("" + ((i))) + ': ' + ("" + ((deceitScore))) + ' ' + ("" + ((warScore))) + ' ')) ; outputFile.closeFile(); operation scoreWar(naomiNums : OclAny, kenNums : OclAny) : OclAny pre: true post: true activity: var naomiInd : int := 0 ; var kenInd : int := 0 ; while (naomiInd->compareTo((naomiNums)->size())) < 0 do ( var naomiPlay : OclAny := naomiNums[naomiInd+1] ; while (kenInd->compareTo((kenNums)->size())) < 0 & (kenNums[kenInd+1]->compareTo(naomiPlay)) < 0 do ( kenInd := kenInd + 1) ; if kenInd = (kenNums)->size() then ( break ) else skip ; naomiInd := naomiInd + 1 ; kenInd := kenInd + 1) ; return (naomiNums)->size() - naomiInd; operation scoreDeceit(naomiNums : OclAny, kenNums : OclAny) : OclAny pre: true post: true activity: naomiInd := 0 ; kenInd := 0 ; while (kenInd->compareTo((kenNums)->size())) < 0 do ( var kenPlay : OclAny := kenNums[kenInd+1] ; while (naomiInd->compareTo((naomiNums)->size())) < 0 & (naomiNums[naomiInd+1]->compareTo(kenPlay)) < 0 do ( naomiInd := naomiInd + 1) ; if naomiInd = (naomiNums)->size() then ( break ) else skip ; naomiInd := naomiInd + 1 ; kenInd := kenInd + 1) ; return kenInd; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math debug=False def log(text): if debug : print(text) def parse_input(lines_as_string=None): global debug lines=[] if lines_as_string is None : debug=False lines.append(input()) else : debug=True lines=[e for e in lines_as_string.split("\n")][1 :-1] c=[e for e in lines[0].split(" ")][0] return(c,) def solve(c): a="abcdefghijklmnopqrstuvwxyz" i=a.index(c) return a[i+1] def main(): result=solve(*parse_input()) if isinstance(result,list): for r in result : print("%s" % r,sep='') else : print("%s" % result,sep='') if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute debug : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; var debug : boolean := false ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation log(text : OclAny) pre: true post: true activity: if debug then ( execute (text)->display() ) else skip; operation parse_input(lines_as_string : OclAny) : OclAny pre: true post: true activity: if lines_as_string->oclIsUndefined() then lines_as_string := null else skip; skip ; var lines : Sequence := Sequence{} ; if lines_as_string <>= null then ( debug := false ; execute (((OclFile["System.in"]).readLine()) : lines) ) else ( debug := true ; lines := lines_as_string.split("\n")->select(e | true)->collect(e | (e)).subrange(1+1, -1) ) ; var c : OclAny := lines->first().split(" ")->select(e | true)->collect(e | (e))->first() ; return Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name c)))))) ,)}; operation solve(c : OclAny) : OclAny pre: true post: true activity: var a : String := "abcdefghijklmnopqrstuvwxyz" ; var i : int := a->indexOf(c) - 1 ; return a[i + 1+1]; operation main() pre: true post: true activity: var result : OclAny := solve((argument * (test (logical_test (comparison (expr (atom (name parse_input)) (trailer (arguments ( ))))))))) ; if (OclType["Sequence"]).isInstance(result) then ( for r : result do ( execute (StringLib.format("%s",r))->display()) ) else ( execute (StringLib.format("%s",result))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np import math input_file_name='./D-large.in' output_file_name='./D-large.out' if __name__=='__main__' : input_file=open(input_file_name,'r') output_file=open(output_file_name,'w') file_line=input_file.readline() file_line=file_line.replace('\n','') num_cases=int(file_line) case_num=1 while True : file_line=input_file.readline() if file_line=='' or file_line=='\n' : input_file.close() break file_line=file_line.replace('\n','') N=int(file_line) file_line=input_file.readline() N_list=map(float,file_line.split()) file_line=input_file.readline() K_list=map(float,file_line.split()) N_list.sort() K_list.sort() N_index=0 K_index=0 ken_wins=0 while True : if N_index==N or K_index==N : break if K_list[K_index]>N_list[N_index]: ken_wins+=1 N_index+=1 K_index+=1 else : K_index+=1 fair_wins=N-ken_wins N_index=0 K_index=0 cheat_wins=0 while True : if N_index==N or K_index==N : break if N_list[N_index]>K_list[K_index]: cheat_wins+=1 N_index+=1 K_index+=1 else : N_index+=1 output_file.write('Case #'+str(case_num)+': '+str(cheat_wins)+' '+str(fair_wins)+'\n') print(case_num) case_num+=1 output_file.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input_file_name : String := './D-large.in' ; var output_file_name : String := './D-large.out' ; if __name__ = '__main__' then ( var input_file : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(input_file_name)) ; var output_file : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(output_file_name)) ; var file_line : String := input_file.readLine() ; file_line := file_line.replace(' ', '') ; var num_cases : int := ("" + ((file_line)))->toInteger() ; var case_num : int := 1 ; while true do ( file_line := input_file.readLine() ; if file_line = '' or file_line = ' ' then ( input_file.closeFile() ; break ) else skip ; file_line := file_line.replace(' ', '') ; var N : int := ("" + ((file_line)))->toInteger() ; file_line := input_file.readLine() ; var N_list : Sequence := (file_line.split())->collect( _x | (OclType["double"])->apply(_x) ) ; file_line := input_file.readLine() ; var K_list : Sequence := (file_line.split())->collect( _x | (OclType["double"])->apply(_x) ) ; N_list := N_list->sort() ; K_list := K_list->sort() ; var N_index : int := 0 ; var K_index : int := 0 ; var ken_wins : int := 0 ; while true do ( if N_index = N or K_index = N then ( break ) else skip ; if (K_list[K_index+1]->compareTo(N_list[N_index+1])) > 0 then ( ken_wins := ken_wins + 1 ; N_index := N_index + 1 ; K_index := K_index + 1 ) else ( K_index := K_index + 1 )) ; var fair_wins : double := N - ken_wins ; N_index := 0 ; K_index := 0 ; var cheat_wins : int := 0 ; while true do ( if N_index = N or K_index = N then ( break ) else skip ; if (N_list[N_index+1]->compareTo(K_list[K_index+1])) > 0 then ( cheat_wins := cheat_wins + 1 ; N_index := N_index + 1 ; K_index := K_index + 1 ) else ( N_index := N_index + 1 )) ; output_file.write('Case #' + ("" + ((case_num))) + ': ' + ("" + ((cheat_wins))) + ' ' + ("" + ((fair_wins))) + ' ') ; execute (case_num)->display() ; case_num := case_num + 1) ; output_file.closeFile() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict N,p=map(int,input().split()) S=input() S=S[: :-1] d=defaultdict(lambda : 0) r=0 for i in range(N): r+=int(S[i])*pow(10,i,p) r %=p d[r]+=1 ans=0 for r in d : ans+=d[r]*(d[r]-1)//2 ans+=d[0] if p==2 or p==5 : S=S[: :-1] ans=0 for i in range(N): if int(S[i])% p==0 : ans+=i+1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var p : OclAny := null; Sequence{N,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : String := (OclFile["System.in"]).readLine() ; S := S(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var d : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; var r : int := 0 ; for i : Integer.subrange(0, N-1) do ( r := r + ("" + ((S[i+1])))->toInteger() * (10)->pow(i) ; r := r mod p ; d[r+1] := d[r+1] + 1) ; var ans : int := 0 ; for r : d do ( ans := ans + d[r+1] * (d[r+1] - 1) div 2) ; ans := ans + d->first() ; if p = 2 or p = 5 then ( S := S(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; ans := 0 ; for i : Integer.subrange(0, N-1) do ( if ("" + ((S[i+1])))->toInteger() mod p = 0 then ( ans := ans + i + 1 ) else skip) ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,p=list(map(int,input().split())) S=input() if p==2 or p==5 : ans=0 for i,s in enumerate(S): if int(s)% p==0 : ans+=i+1 print(ans) exit() def MS(i,s,pre): return(int(s)*i+pre)% p M=[0]*p M[0]=1 i=1 pre=0 for s in S[: :-1]: pre=MS(i,int(s),pre) M[pre]+=1 i=i*10 % p ans=sum(map(lambda m :(m*(m-1))//2,M)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var S : String := (OclFile["System.in"]).readLine() ; if p = 2 or p = 5 then ( var ans : int := 0 ; for _tuple : Integer.subrange(1, (S)->size())->collect( _indx | Sequence{_indx-1, (S)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); if ("" + ((s)))->toInteger() mod p = 0 then ( ans := ans + i + 1 ) else skip) ; execute (ans)->display() ; exit() ) else skip ; skip ; var M : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, p) ; M->first() := 1 ; i := 1 ; pre := 0 ; for s : S(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( pre := MS(i, ("" + ((s)))->toInteger(), pre) ; M[pre+1] := M[pre+1] + 1 ; i := i * 10 mod p) ; ans := ((M)->collect( _x | (lambda m : OclAny in ((m * (m - 1)) div 2))->apply(_x) ))->sum() ; execute (ans)->display(); operation MS(i : OclAny, s : OclAny, pre : OclAny) : OclAny pre: true post: true activity: return (("" + ((s)))->toInteger() * i + pre) mod p; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(2147483647) INF=1<<60 MOD=10**9+7 input=lambda : sys.stdin.readline().rstrip() from collections import Counter def resolve(): n,p=map(int,input().split()) S=input() if p==2 or p==5 : res=0 for i,c in enumerate(S,1): if int(c)% p==0 : res+=i print(res) return res=0 now=0 counter=Counter() counter[0]=1 for i in range(n): now=(10*now+int(S[i]))% p k=now*pow(10,(p-2)*i,p)% p res+=counter[k] counter[k]+=1 print(res) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(2147483647) ; var INF : int := 1 * (2->pow(60)) ; var MOD : double := (10)->pow(9) + 7 ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; skip ; skip ; resolve(); operation resolve() pre: true post: true activity: var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : String := (OclFile["System.in"]).readLine() ; if p = 2 or p = 5 then ( var res : int := 0 ; for _tuple : Integer.subrange(1, (S, 1)->size())->collect( _indx | Sequence{_indx-1, (S, 1)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if ("" + ((c)))->toInteger() mod p = 0 then ( res := res + i ) else skip) ; execute (res)->display() ; return ) else skip ; res := 0 ; var now : int := 0 ; var counter : OclAny := Counter() ; counter->first() := 1 ; for i : Integer.subrange(0, n-1) do ( now := (10 * now + ("" + ((S[i+1])))->toInteger()) mod p ; var k : int := now * (10)->pow((p - 2) * i) mod p ; res := res + counter[k+1] ; counter[k+1] := counter[k+1] + 1) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import groupby n,p=map(int,input().split()) s=[int(i)for i in input()] if p==2 or p==5 : ans=0 for i in range(n-1,-1,-1): if s[i]% p==0 : ans+=(i+1) exit(print(ans)) S=[0]*(n+1) po=[1]*(n+1) for i in range(n): po[i+1]=po[i]*10 po[i+1]%=p for i in range(n-1,-1,-1): S[i]=S[i+1]+s[i]*po[n-1-i] S[i]%=p t=[[S[i],i]for i in range(n+1)] t.sort() u=[[i[1]for i in sorted(list(group))]for key,group in groupby(t,key=lambda x : x[0])] ans=0 for v in u : ans+=(len(v))*(len(v)-1)//2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := (OclFile["System.in"]).readLine()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if p = 2 or p = 5 then ( var ans : int := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if s[i+1] mod p = 0 then ( ans := ans + (i + 1) ) else skip) ; exit((ans)->display()) ) else skip ; var S : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var po : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ; for i : Integer.subrange(0, n-1) do ( po[i + 1+1] := po[i+1] * 10 ; po[i + 1+1] := po[i + 1+1] mod p) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( S[i+1] := S[i + 1+1] + s[i+1] * po[n - 1 - i+1] ; S[i+1] := S[i+1] mod p) ; var t : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Sequence{S[i+1]}->union(Sequence{ i }))) ; t := t->sort() ; var u : Sequence := groupby(t, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))))->select(_tuple | true)->collect(_tuple | let key : OclAny = _tuple->at(1) in let group : OclAny = _tuple->at(2) in ((group)->sort()->select(i | true)->collect(i | (i[1+1])))) ; ans := 0 ; for v : u do ( ans := ans + ((v)->size()) * ((v)->size() - 1) div 2) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import defaultdict sys.setrecursionlimit(10**7) rl=sys.stdin.readline def solve(): N,P=map(int,rl().split()) S=input() ans=0 if P==2 or P==5 : for i in range(N-1,-1,-1): si=int(S[i]) if si % P==0 : ans+=i+1 else : cum=[0] t=1 for i in range(N-1,-1,-1): cum.append(int(S[i])*t % P) t=t*10 % P for i in range(N): cum[i+1]=(cum[i+1]+cum[i])% P counter=defaultdict(int) for val in cum : ans+=counter[val] counter[val]+=1 print(ans) if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; var rl : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var N : OclAny := null; var P : OclAny := null; Sequence{N,P} := (rl().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; if P = 2 or P = 5 then ( for i : Integer.subrange(-1 + 1, N - 1)->reverse() do ( var si : int := ("" + ((S[i+1])))->toInteger() ; if si mod P = 0 then ( ans := ans + i + 1 ) else skip) ) else ( var cum : Sequence := Sequence{ 0 } ; var t : int := 1 ; for i : Integer.subrange(-1 + 1, N - 1)->reverse() do ( execute ((("" + ((S[i+1])))->toInteger() * t mod P) : cum) ; t := t * 10 mod P) ; for i : Integer.subrange(0, N-1) do ( cum[i + 1+1] := (cum[i + 1+1] + cum[i+1]) mod P) ; var counter : OclAny := defaultdict(OclType["int"]) ; for val : cum do ( ans := ans + counter[val+1] ; counter[val+1] := counter[val+1] + 1) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printPascal(n : int): arr=[[0 for x in range(n)]for y in range(n)] for line in range(0,n): for i in range(0,line+1): if(i is 0 or i is line): arr[line][i]=1 print(arr[line][i],end="") else : arr[line][i]=(arr[line-1][i-1]+arr[line-1][i]) print(arr[line][i],end="") print("\n",end="") n=5 printPascal(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := 5 ; printPascal(n); operation printPascal(n : int) pre: true post: true activity: var arr : Sequence := Integer.subrange(0, n-1)->select(y | true)->collect(y | (Integer.subrange(0, n-1)->select(x | true)->collect(x | (0)))) ; for line : Integer.subrange(0, n-1) do ( for i : Integer.subrange(0, line + 1-1) do ( if (i <>= 0 or i <>= line) then ( arr[line+1][i+1] := 1 ; execute (arr[line+1][i+1])->display() ) else ( arr[line+1][i+1] := (arr[line - 1+1][i - 1+1] + arr[line - 1+1][i+1]) ; execute (arr[line+1][i+1])->display() )) ; execute ("\n")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,data): self.data=data self.next=None class LinkedList : def __init__(self): self.head=None def Circular(head): if head==None : return True node=head.next i=0 while((node is not None)and(node is not head)): i=i+1 node=node.next return(node==head) if __name__=='__main__' : llist=LinkedList() llist.head=Node(1) second=Node(2) third=Node(3) fourth=Node(4) llist.head.next=second ; second.next=third ; third.next=fourth if(Circular(llist.head)): print('Yes') else : print('No') fourth.next=llist.head if(Circular(llist.head)): print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.next := null; return self; } class LinkedList { static operation newLinkedList() : LinkedList pre: true post: LinkedList->exists( _x | result = _x ); attribute head : OclAny := null; operation initialise() : LinkedList pre: true post: true activity: self.head := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( var llist : LinkedList := (LinkedList.newLinkedList()).initialise() ; llist.head := (Node.newNode()).initialise(1) ; var second : Node := (Node.newNode()).initialise(2) ; var third : Node := (Node.newNode()).initialise(3) ; var fourth : Node := (Node.newNode()).initialise(4) ; llist.head.next := second; ; second.next := third; ; third.next := fourth ; if (Circular(llist.head)) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ) ; fourth.next := llist.head ; if (Circular(llist.head)) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ) ) else skip; operation Circular(head : OclAny) : OclAny pre: true post: true activity: if head = null then ( return true ) else skip ; var node : OclAny := head.next ; var i : int := 0 ; while ((not(node <>= null)) & (not(node <>= head))) do ( i := i + 1 ; node := node.next) ; return (node = head); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countOdd(arr,n): odd=0 ; for i in range(0,n): if(arr[i]% 2==1): odd=odd+1 ; return odd ; def countValidPairs(arr,n): odd=countOdd(arr,n); return(odd*(odd-1))/2 ; arr=[1,2,3,4,5]; n=len(arr); print(int(countValidPairs(arr,n))); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))); ; n := (arr)->size(); ; execute (("" + ((countValidPairs(arr, n))))->toInteger())->display();; operation countOdd(arr : OclAny, n : OclAny) pre: true post: true activity: var odd : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] mod 2 = 1) then ( odd := odd + 1; ) else skip) ; return odd;; operation countValidPairs(arr : OclAny, n : OclAny) pre: true post: true activity: odd := countOdd(arr, n); ; return (odd * (odd - 1)) / 2;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): a,b,n,s=map(int,input().split()) print('YES')if n*min(s//n,a)+b>=s else print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var n : OclAny := null; var s : OclAny := null; Sequence{a,b,n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))) if (logical_test (comparison (comparison (expr (expr (expr (atom (name n))) * (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name s))) // (expr (atom (name n)))))))) , (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) + (expr (atom (name b))))) >= (comparison (expr (atom (name s)))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) ))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- abc=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] val=[i for i in range(len(abc))] dic=dict(zip(abc,val)) C=input() keys=[k for k,v in dic.items()if v==dic[C]+1] print(keys[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var abc : Sequence := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{'c'}->union(Sequence{'d'}->union(Sequence{'e'}->union(Sequence{'f'}->union(Sequence{'g'}->union(Sequence{'h'}->union(Sequence{'i'}->union(Sequence{'j'}->union(Sequence{'k'}->union(Sequence{'l'}->union(Sequence{'m'}->union(Sequence{'n'}->union(Sequence{'o'}->union(Sequence{'p'}->union(Sequence{'q'}->union(Sequence{'r'}->union(Sequence{'s'}->union(Sequence{'t'}->union(Sequence{'u'}->union(Sequence{'v'}->union(Sequence{'w'}->union(Sequence{'x'}->union(Sequence{'y'}->union(Sequence{ 'z' }))))))))))))))))))))))))) ; var val : Sequence := Integer.subrange(0, (abc)->size()-1)->select(i | true)->collect(i | (i)) ; var dic : Map := ((expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name abc))))))) , (argument (test (logical_test (comparison (expr (atom (name val)))))))) ))))) ; var C : String := (OclFile["System.in"]).readLine() ; var keys : Sequence := dic->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->select(_tuple | let k : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in v = dic->at(C) + 1)->collect(_tuple | let k : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in (k)) ; execute (keys->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a,b,n,S=map(int,input().split()) x_1=S//n x_2=S//n+1 if(a*n+b)toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var n : OclAny := null; var S : OclAny := null; Sequence{a,b,n,S} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x var a : OclAny := null; var b : OclAny := null; var n : OclAny := null; var S : OclAny := null; Sequence{a,b,n,S} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) : int := S div n ; var x:= S div n + 1 : int := S div n + 1 ; if ((a * n + b)->compareTo(S)) < 0 then ( execute ("NO")->display() ) else ( var dif : double := S - x var a : OclAny := null; var b : OclAny := null; var n : OclAny := null; var S : OclAny := null; Sequence{a,b,n,S} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) * n ; if ((dif->compareTo(b)) <= 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): a,b,n,s=map(int,input().split()) if a*n+b=c : if b>=r : print("YES") else : print("NO") return if b>=(s-a*n): print("YES") else : print("NO") q=int(input()) for i in range(q): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( solve()); operation solve() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var n : OclAny := null; var s : OclAny := null; Sequence{a,b,n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a * n + b->compareTo(s)) < 0 then ( execute ("NO")->display() ; return ) else skip ; var c : int := s div n ; var r : int := s mod n ; if (a->compareTo(c)) >= 0 then ( if (b->compareTo(r)) >= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ; return ) else skip ; if (b->compareTo((s - a * n))) >= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) for x in range(q): a,b,n,S=map(int,input().split()) c=S//n if c>a : d=S-n*a if d<=b : print("YES") else : print("NO") else : d=S-n*c if d<=b : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for x : Integer.subrange(0, q-1) do ( var a : OclAny := null; var b : OclAny := null; var n : OclAny := null; var S : OclAny := null; Sequence{a,b,n,S} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : int := S div n ; if (c->compareTo(a)) > 0 then ( var d : double := S - n * a ; if (d->compareTo(b)) <= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else ( d := S - n * c ; if (d->compareTo(b)) <= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): a,b,n,s=map(int,input().split()) d=s//n p=n*min(d,a) i=p+b print('YES')if i>=s else print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var n : OclAny := null; var s : OclAny := null; Sequence{a,b,n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : int := s div n ; var p : double := n * Set{d, a}->min() ; var i : OclAny := p + b ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))) if (logical_test (comparison (comparison (expr (atom (name i)))) >= (comparison (expr (atom (name s)))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) ))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* for i in range(int(input())): n=int(input()) a=list(map(int,input().split())) for j in range(n): p=sqrt(a[j]) q=floor(p) if p-q>0.000001 : print('YES') break else : continue else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name p)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sqrt)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name q)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name floor)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p)))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name p))) - (expr (atom (name q))))) > (comparison (expr (atom (number 0.000001))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))) (else_clause else : (suite (stmt (simple_stmt (small_stmt continue)))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in ' '*int(input()): n,x=int(input()),list(map(int,input().split())) c="NO" for i in range(n): if x[i]**(1/2)!=int(x[i]**(1/2))+0.0 : c='YES' break else : continue print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : StringLib.nCopies(' ', ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),((input().split())->collect( _x | (OclType["int"])->apply(_x) ))} ; var c : String := "NO" ; for i : Integer.subrange(0, n-1) do ( if (x[i+1])->pow((1 / 2)) /= ("" + (((x[i+1])->pow((1 / 2)))))->toInteger() + 0.0 then ( c := 'YES' ; break ) else ( continue )) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in ' '*int(input()): n,x,c=int(input()),list(map(int,input().split())),'NO' for i in range(n): if x[i]**(1/2)!=int(x[i]**(1/2))+0.0 : c='YES' ; break else : continue print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : StringLib.nCopies(' ', ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var n : OclAny := null; var x : OclAny := null; var c : OclAny := null; Sequence{n,x,c} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),((input().split())->collect( _x | (OclType["int"])->apply(_x) )),'NO'} ; for i : Integer.subrange(0, n-1) do ( if (x[i+1])->pow((1 / 2)) /= ("" + (((x[i+1])->pow((1 / 2)))))->toInteger() + 0.0 then ( var c : String := 'YES'; break ) else ( continue )) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkTriangularSumRepresentation(n): tri=list(); i=1 ; while(1): x=i*(i+1)//2 ; if(x>=n): break ; tri.append(x); i+=1 ; for tm in tri : if n-tm in tri : return True ; return False ; if __name__=="__main__" : n=24 ; if checkTriangularSumRepresentation(n): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 24; ; if checkTriangularSumRepresentation(n) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation checkTriangularSumRepresentation(n : OclAny) pre: true post: true activity: var tri : Sequence := (); ; var i : int := 1; ; while (1) do ( var x : int := i * (i + 1) div 2; ; if ((x->compareTo(n)) >= 0) then ( break; ) else skip ; execute ((x) : tri); ; i := i + 1;) ; for tm : tri do ( if (tri)->includes(n - tm) then ( return true; ) else skip) ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x=int(input()); l=list(map(int,input().split())); p='NO' for i in l : if i**0.5!=int(i**0.5): p='YES' ; break print(p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); var p : String := 'NO' ; for i : l do ( if (i)->pow(0.5) /= ("" + (((i)->pow(0.5))))->toInteger() then ( p := 'YES'; break ) else skip) ; execute (p)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: print('YNEOS'[all(x==int(x**.5)**2 for x in map(int,s.split())): : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( execute ('YNEOS'(subscript (test (logical_test (comparison (expr (atom (name all)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (comparison (expr (atom (name x)))) == (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) ** (expr (atom (number .5))))))))) )))) ** (expr (atom (number (integer 2))))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name s)) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- C=str(input()) result="" Alfa=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"] result=Alfa[Alfa.index(C)+1] print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var C : String := ("" + (((OclFile["System.in"]).readLine()))) ; var result : String := "" ; var Alfa : Sequence := Sequence{"a"}->union(Sequence{"b"}->union(Sequence{"c"}->union(Sequence{"d"}->union(Sequence{"e"}->union(Sequence{"f"}->union(Sequence{"g"}->union(Sequence{"h"}->union(Sequence{"i"}->union(Sequence{"j"}->union(Sequence{"k"}->union(Sequence{"l"}->union(Sequence{"m"}->union(Sequence{"n"}->union(Sequence{"o"}->union(Sequence{"p"}->union(Sequence{"q"}->union(Sequence{"r"}->union(Sequence{"s"}->union(Sequence{"t"}->union(Sequence{"u"}->union(Sequence{"v"}->union(Sequence{"w"}->union(Sequence{"x"}->union(Sequence{"y"}->union(Sequence{ "z" }))))))))))))))))))))))))) ; result := Alfa[Alfa->indexOf(C) - 1 + 1+1] ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isArmstrong(x,n): sum1=0 temp=x while temp>0 : digit=temp % 10 sum1+=digit**n temp//=10 return sum1==x def CalculateXORandOR(n): CalculateXOR=0 CalculateOR=0 start=10**(n-1) end=(10**n)-1 for i in range(start,end+1): if(isArmstrong(i,n)): CalculateXOR=CalculateXOR ^ i CalculateOR=CalculateOR | i print("XOR=",CalculateXOR) print("OR=",CalculateOR) if __name__=="__main__" : n=4 ; CalculateXORandOR(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 4; ; CalculateXORandOR(n); ) else skip; operation isArmstrong(x : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sum1 : int := 0 ; var temp : OclAny := x ; while temp > 0 do ( var digit : int := temp mod 10 ; sum1 := sum1 + (digit)->pow(n) ; temp := temp div 10) ; return sum1 = x; operation CalculateXORandOR(n : OclAny) pre: true post: true activity: var CalculateXOR : int := 0 ; var CalculateOR : int := 0 ; var start : double := (10)->pow((n - 1)) ; var end : double := ((10)->pow(n)) - 1 ; for i : Integer.subrange(start, end + 1-1) do ( if (isArmstrong(i, n)) then ( CalculateXOR := MathLib.bitwiseXor(CalculateXOR, i) ; CalculateOR := MathLib.bitwiseOr(CalculateOR, i) ) else skip) ; execute ("XOR=")->display() ; execute ("OR=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=[] ans=0 def subsetSum(i,curr): global ans,c if(i==len(c)): ans+=curr return subsetSum(i+1,curr+c[i]) subsetSum(i+1,curr) def subsetGen(arr,i,n): global ans,c if(i==n): subsetSum(0,0) return subsetGen(arr,i+1,n) c.append(arr[i]) subsetGen(arr,i+1,n) del c[-1] arr=[1,1] n=len(arr) subsetGen(arr,0,n) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute ans : OclAny; attribute c : OclAny; attribute ans : OclAny; attribute c : OclAny; operation initialise() pre: true post: true activity: var c : Sequence := Sequence{} ; var ans : int := 0 ; skip ; skip ; arr := Sequence{1}->union(Sequence{ 1 }) ; n := (arr)->size() ; subsetGen(arr, 0, n) ; execute (ans)->display(); operation subsetSum(i : OclAny, curr : OclAny) pre: true post: true activity: skip; skip ; if (i = (c)->size()) then ( ans := ans + curr ; return ) else skip ; subsetSum(i + 1, curr + c[i+1]) ; subsetSum(i + 1, curr); operation subsetGen(arr : OclAny, i : OclAny, n : OclAny) pre: true post: true activity: skip; skip ; if (i = n) then ( subsetSum(0, 0) ; return ) else skip ; subsetGen(arr, i + 1, n) ; execute ((arr[i+1]) : c) ; subsetGen(arr, i + 1, n) ; execute (c->last())->isDeleted(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- new_login={input().lower().replace("l","1").replace("i","1").replace("o","0")} n=int(input()) logins={input().lower().replace("l","1").replace("i","1").replace("o","0")for _ in range(n)} if new_login & logins : print("No") else : print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var new_login : Set := Set{ input()->toLowerCase().replace("l", "1").replace("i", "1").replace("o", "0") } ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var logins : Set := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | input()->toLowerCase().replace("l", "1").replace("i", "1").replace("o", "0"))->asSet() ; if MathLib.bitwiseAnd(new_login, logins) then ( execute ("No")->display() ) else ( execute ("Yes")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline s=input()[:-1] x=len(s) for _ in range(int(input())): w=input()[:-1] y=len(w) if y!=x : continue else : d=0 for i in range(x): if s[i]==w[i]: continue else : if(s[i].upper()=='O' and w[i]=='0')or(s[i]=='0' and w[i].upper()=='O'): continue elif(s[i].lower()=='l' and w[i]=='1')or(s[i].lower()=='l' and w[i].upper()=='I')or(s[i].upper()=='I' and w[i]=='1')or(s[i]=='1' and w[i].lower()=='l')or(s[i].upper()=='I' and w[i].lower()=='l')or(s[i]=='1' and w[i].upper()=='I'): continue elif s[i].lower()==w[i].lower(): continue else : d=1 if d==0 : print('No') break else : print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var s : OclAny := input()->front() ; var x : int := (s)->size() ; (compound_stmt for (exprlist (expr (atom (name _)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name w)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name y)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name w)))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name y)))) != (comparison (expr (atom (name x))))))) : (suite (stmt (simple_stmt (small_stmt continue)))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt continue)))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name upper) (arguments ( ))))) == (comparison (expr (atom 'O'))))) and (logical_test (comparison (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom '0')))))))) ))))) or (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom '0'))))) and (logical_test (comparison (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name upper) (arguments ( ))))) == (comparison (expr (atom 'O')))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt continue)))) (elif_clause elif (test (logical_test (logical_test (logical_test (logical_test (logical_test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name lower) (arguments ( ))))) == (comparison (expr (atom 'l'))))) and (logical_test (comparison (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom '1')))))))) ))))) or (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name lower) (arguments ( ))))) == (comparison (expr (atom 'l'))))) and (logical_test (comparison (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name upper) (arguments ( ))))) == (comparison (expr (atom 'I')))))))) )))))) or (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name upper) (arguments ( ))))) == (comparison (expr (atom 'I'))))) and (logical_test (comparison (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom '1')))))))) )))))) or (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom '1'))))) and (logical_test (comparison (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name lower) (arguments ( ))))) == (comparison (expr (atom 'l')))))))) )))))) or (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name upper) (arguments ( ))))) == (comparison (expr (atom 'I'))))) and (logical_test (comparison (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name lower) (arguments ( ))))) == (comparison (expr (atom 'l')))))))) )))))) or (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom '1'))))) and (logical_test (comparison (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name upper) (arguments ( ))))) == (comparison (expr (atom 'I')))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt continue))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name lower) (arguments ( ))))) == (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name lower) (arguments ( )))))))) : (suite (stmt (simple_stmt (small_stmt continue))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name d)))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'No'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'Yes'))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def hashing(string): return string.lower().replace('o','0').replace('l','1').replace('i','1') login=hashing(input()) N=int(input()) for i in range(N): data=hashing(input()) if data==login : print('No') break else : print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var login : OclAny := hashing((OclFile["System.in"]).readLine()) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name data)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name hashing)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name data)))) == (comparison (expr (atom (name login))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'No'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'Yes'))))))) ))))))))))))))); operation hashing(string : OclAny) : OclAny pre: true post: true activity: return string->toLowerCase().replace('o', '0').replace('l', '1').replace('i', '1'); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=input() f=lambda x : x.lower().replace('0','o').replace('1','l').replace('i','l') print(['Yes','No'][f(l)in map(f,[input()for r in range(int(input()))])]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : String := (OclFile["System.in"]).readLine() ; var f : Function := lambda x : OclAny in (x->toLowerCase().replace('0', 'o').replace('1', 'l').replace('i', 'l')) ; execute (Sequence{'Yes'}->union(Sequence{ 'No' })->select(((Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1)->select(r | true)->collect(r | ((OclFile["System.in"]).readLine())))->collect( _x | (f)->apply(_x) ))->includes(f->apply(l))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- table=str.maketrans({'A' : 'a','B' : 'b','C' : 'c','D' : 'd','E' : 'e','F' : 'f','G' : 'g','H' : 'h','J' : 'j','K' : 'k','M' : 'm','N' : 'n','O' : 'o','P' : 'p','Q' : 'q','R' : 'r','S' : 's','T' : 't','U' : 'u','V' : 'v','W' : 'w','X' : 'x','Y' : 'y','Z' : 'z',"0" : "o","L" : "1","l" : "1","I" : "1","i" : "1"}) print("No" if{input().translate(table)}&{input().translate(table)for _ in range(int(input()))}else "Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var table : String := ("" + (.maketrans(Map{ 'A' |-> 'a' }->union(Map{ 'B' |-> 'b' }->union(Map{ 'C' |-> 'c' }->union(Map{ 'D' |-> 'd' }->union(Map{ 'E' |-> 'e' }->union(Map{ 'F' |-> 'f' }->union(Map{ 'G' |-> 'g' }->union(Map{ 'H' |-> 'h' }->union(Map{ 'J' |-> 'j' }->union(Map{ 'K' |-> 'k' }->union(Map{ 'M' |-> 'm' }->union(Map{ 'N' |-> 'n' }->union(Map{ 'O' |-> 'o' }->union(Map{ 'P' |-> 'p' }->union(Map{ 'Q' |-> 'q' }->union(Map{ 'R' |-> 'r' }->union(Map{ 'S' |-> 's' }->union(Map{ 'T' |-> 't' }->union(Map{ 'U' |-> 'u' }->union(Map{ 'V' |-> 'v' }->union(Map{ 'W' |-> 'w' }->union(Map{ 'X' |-> 'x' }->union(Map{ 'Y' |-> 'y' }->union(Map{ 'Z' |-> 'z' }->union(Map{ "0" |-> "o" }->union(Map{ "L" |-> "1" }->union(Map{ "l" |-> "1" }->union(Map{ "I" |-> "1" }->union(Map{ "i" |-> "1" }))))))))))))))))))))))))))))))) ; execute (if MathLib.bitwiseAnd(Set{ input().translate(table) }, Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1)->select(_anon | true)->collect(_anon | input().translate(table))->asSet()) then "No" else "Yes" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isVowel(x): if(x=='a' or x=='e' or x=='i' or x=='o' or x=='u'): return True else : return False def updateSandwichedVowels(a): n=len(a) updatedString="" for i in range(0,n,1): if(i==0 or i==n-1): updatedString+=a[i] continue if(isVowel(a[i])==True and isVowel(a[i-1])==False and isVowel(a[i+1])==False): continue updatedString+=a[i] return updatedString if __name__=='__main__' : str="geeksforgeeks" updatedString=updateSandwichedVowels(str) print(updatedString) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var OclType["String"] : String := "geeksforgeeks" ; updatedString := updateSandwichedVowels(OclType["String"]) ; execute (updatedString)->display() ) else skip; operation isVowel(x : OclAny) : OclAny pre: true post: true activity: if (x = 'a' or x = 'e' or x = 'i' or x = 'o' or x = 'u') then ( return true ) else ( return false ); operation updateSandwichedVowels(a : OclAny) : OclAny pre: true post: true activity: var n : int := (a)->size() ; var updatedString : String := "" ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (i = 0 or i = n - 1) then ( updatedString := updatedString + a[i+1] ; continue ) else skip ; if (isVowel(a[i+1]) = true & isVowel(a[i - 1+1]) = false & isVowel(a[i + 1+1]) = false) then ( continue ) else skip ; updatedString := updatedString + a[i+1]) ; return updatedString; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : t-=1 n,m,k=map(int,input().split()) edge=False if m==(n*(n-1)//2): edge=1 elif m==n-1 : edge=2 elif m>n-1 and m<(n*(n-1))//2 : edge=2 if not edge : print("NO") elif n==1 and k>1 : print("YES") elif edgetoInteger() ; while t > 0 do ( t := t - 1 ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var edge : boolean := false ; if m = (n * (n - 1) div 2) then ( edge := 1 ) else (if m = n - 1 then ( edge := 2 ) else (if (m->compareTo(n - 1)) > 0 & (m->compareTo((n * (n - 1)) div 2)) < 0 then ( edge := 2 ) else skip ) ) ; if not(edge) then ( execute ("NO")->display() ) else (if n = 1 & k > 1 then ( execute ("YES")->display() ) else (if (edge->compareTo(k - 1)) < 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxFraction(first,sec): a=first[0]; b=first[1] c=sec[0]; d=sec[1] Y=a*d-b*c return first if Y else sec first=(3,2) sec=(3,4) res=maxFraction(first,sec) print(str(res[0])+"/"+str(res[1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; first := Sequence{3, 2} ; sec := Sequence{3, 4} ; var res : OclAny := maxFraction(first, sec) ; execute (("" + ((res->first()))) + "/" + ("" + ((res[1+1]))))->display(); operation maxFraction(first : OclAny, sec : OclAny) : OclAny pre: true post: true activity: var a : OclAny := first->first(); var b : OclAny := first[1+1] ; var c : OclAny := sec->first(); var d : OclAny := sec[1+1] ; var Y : double := a * d - b * c ; return if Y then first else sec endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import decimal def input(): return sys.stdin.readline().strip() def main(): c=input() a="abcdefghijklmnopqrstuvwxyz" for i in range(25): if a[i]==c : print(a[i+1]) return main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; main(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation main() pre: true post: true activity: var c : String := (OclFile["System.in"]).readLine() ; var a : String := "abcdefghijklmnopqrstuvwxyz" ; for i : Integer.subrange(0, 25-1) do ( if a[i+1] = c then ( execute (a[i + 1+1])->display() ; return ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculateDifference(arr,n): max_val=max(arr) prime=[True for i in range(max_val+1)] prime[0]=False prime[1]=False for p in range(2,max_val+1): if p*p>max_val+1 : break if(prime[p]==True): for i in range(2*p,max_val+1,p): prime[i]=False X1=1 X2=1 for i in range(n): if(prime[arr[i]]): X1 ^=arr[i] elif(arr[i]!=1): X2 ^=arr[i] return abs(X1-X2) arr=[1,3,5,10,15,7] n=len(arr) print(calculateDifference(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{10}->union(Sequence{15}->union(Sequence{ 7 }))))) ; n := (arr)->size() ; execute (calculateDifference(arr, n))->display(); operation calculateDifference(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var max_val : OclAny := (arr)->max() ; var prime : Sequence := Integer.subrange(0, max_val + 1-1)->select(i | true)->collect(i | (true)) ; prime->first() := false ; prime[1+1] := false ; for p : Integer.subrange(2, max_val + 1-1) do ( if (p * p->compareTo(max_val + 1)) > 0 then ( break ) else skip ; if (prime[p+1] = true) then ( for i : Integer.subrange(2 * p, max_val + 1-1)->select( $x | ($x - 2 * p) mod p = 0 ) do ( prime[i+1] := false) ) else skip) ; var X1 : int := 1 ; var X2 : int := 1 ; for i : Integer.subrange(0, n-1) do ( if (prime[arr[i+1]+1]) then ( X1 := X1 xor arr[i+1] ) else (if (arr[i+1] /= 1) then ( X2 := X2 xor arr[i+1] ) else skip)) ; return (X1 - X2)->abs(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from contextlib import nullcontext import os,sys,io,math from tokenize import Triple from math import* I=lambda :[*map(int,sys.stdin.readline().split())] IS=lambda : input() IN=lambda : int(input()) IF=lambda : float(input()) n,a,x,b,y=map(int,input().split()) a-=1 b-=1 x-=1 y-=1 f=1 while True : if a==b : print("YES") f=0 break if a==x or b==y : break a=(a+1)% n b=(b-1+n)% n if f : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var I : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var IS : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var IN : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var IF : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toReal()) ; var n : OclAny := null; var a : OclAny := null; var x : OclAny := null; var b : OclAny := null; var y : OclAny := null; Sequence{n,a,x,b,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := a - 1 ; b := b - 1 ; x := x - 1 ; y := y - 1 ; var f : int := 1 ; while true do ( if a = b then ( execute ("YES")->display() ; f := 0 ; break ) else skip ; if a = x or b = y then ( break ) else skip ; var a : int := (a + 1) mod n ; var b : int := (b - 1 + n) mod n) ; if f then ( execute ("NO")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,x,b,y=map(int,input().split()) for i in range(n): a=(a+1) if a==n+1 : a=1 b=(b-1) if b==0 : b=n if a==b : print("YES") break if a==x or b==y : print("NO") break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var x : OclAny := null; var b : OclAny := null; var y : OclAny := null; Sequence{n,a,x,b,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := (a + 1) ; if a = n + 1 then ( a := 1 ) else skip ; var b : double := (b - 1) ; if b = 0 then ( b := n ) else skip ; if a = b then ( execute ("YES")->display() ; break ) else skip ; if a = x or b = y then ( execute ("NO")->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,x,b,y=map(int,input().split()) while(n>100)or(n<4)or(a<1)or(x<1)or(b<1)or(y<1)or(a>n)or(x>n)or(b>n)or(y>n): n,a,x,b,y=map(int,input().split()) if(a==b): print("YES") else : for i in range(n): if(a+1==n+1): a=1 else : a=a+1 if(b-1==0): b=n else : b=b-1 if(a==b): print("YES") break elif(a==x)or(b==y): print("NO") break elif(a!=b): continue ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var x : OclAny := null; var b : OclAny := null; var y : OclAny := null; Sequence{n,a,x,b,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; while (n > 100) or (n < 4) or (a < 1) or (x < 1) or (b < 1) or (y < 1) or ((a->compareTo(n)) > 0) or ((x->compareTo(n)) > 0) or ((b->compareTo(n)) > 0) or ((y->compareTo(n)) > 0) do ( var n : OclAny := null; var a : OclAny := null; var x : OclAny := null; var b : OclAny := null; var y : OclAny := null; Sequence{n,a,x,b,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (a = b) then ( execute ("YES")->display() ) else ( for i : Integer.subrange(0, n-1) do ( if (a + 1 = n + 1) then ( var a : int := 1 ) else ( a := a + 1 ) ; if (b - 1 = 0) then ( var b : OclAny := n ) else ( b := b - 1 ) ; if (a = b) then ( execute ("YES")->display() ; break ) else (if (a = x) or (b = y) then ( execute ("NO")->display() ; break ) else (if (a /= b) then ( continue ) else skip ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,x,b,y=map(int,input().split()) t=2*min((x-a)% n,(b-y)% n) d=(b-a)% n print("YNEOS"[(n % 2<1 or d+n>t if d % 2 else d>t): : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var x : OclAny := null; var b : OclAny := null; var y : OclAny := null; Sequence{n,a,x,b,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : double := 2 * Set{(x - a) mod n, (b - y) mod n}->min() ; var d : int := (b - a) mod n ; execute ("YNEOS"(subscript (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (expr (atom (name n))) % (expr (atom (number (integer 2)))))) < (comparison (expr (atom (number (integer 1))))))) or (logical_test (comparison (comparison (expr (expr (atom (name d))) + (expr (atom (name n))))) > (comparison (expr (atom (name t))))))) if (logical_test (comparison (expr (expr (atom (name d))) % (expr (atom (number (integer 2))))))) else (test (logical_test (comparison (comparison (expr (atom (name d)))) > (comparison (expr (atom (name t))))))))) )))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,x,b,y=map(int,input().split()) meet=0 df1=x-a if acollect( _x | (OclType["int"])->apply(_x) ) ; var meet : int := 0 ; var df1 : double := if (a->compareTo(x)) < 0 then x - a else (n + x) - a endif ; var df2 : double := if (y->compareTo(b)) < 0 then b - y else (n + b) - y endif ; var mini : OclAny := Set{df1, df2}->min() ; for i : Integer.subrange(0, mini + 1-1) do ( if a = b then ( meet := 1 ; break ) else skip ; var a : OclAny := if a /= n then a + 1 else 1 endif ; var b : double := if b /= 1 then b - 1 else n endif) ; if meet = 1 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPrime(n): if(n<=1): return False if(n<=3): return True if(n % 2==0 or n % 3==0): return False i=5 while(i*i<=n): if(n % i==0 or n %(i+2)==0): return False i+=6 return True def findSmallest(N): if(N==0): return 2 if(N==1): return 1 prime,counter=N,0 found=False while(not found): if(isPrime(prime)): found=True else : prime+=1 counter+=1 return counter if __name__=="__main__" : N=10 print(findSmallest(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( N := 10 ; execute (findSmallest(N))->display() ) else skip; operation isPrime(n : OclAny) : OclAny pre: true post: true activity: if (n <= 1) then ( return false ) else skip ; if (n <= 3) then ( return true ) else skip ; if (n mod 2 = 0 or n mod 3 = 0) then ( return false ) else skip ; var i : int := 5 ; while ((i * i->compareTo(n)) <= 0) do ( if (n mod i = 0 or n mod (i + 2) = 0) then ( return false ) else skip ; i := i + 6) ; return true; operation findSmallest(N : OclAny) : OclAny pre: true post: true activity: if (N = 0) then ( return 2 ) else skip ; if (N = 1) then ( return 1 ) else skip ; var prime : OclAny := null; var counter : OclAny := null; Sequence{prime,counter} := Sequence{N,0} ; var found : boolean := false ; while (not(found)) do ( if (isPrime(prime)) then ( found := true ) else ( prime := prime + 1 ; counter := counter + 1 )) ; return counter; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPowerOfTwo(n): return(True if(n>0 and((n &(n-1))>0))else False); def findPosition(n): if(isPowerOfTwo(n)==True): return-1 ; i=1 ; pos=1 ; while((i & n)==0): i=i<<1 ; pos+=1 ; return pos ; n=16 ; pos=findPosition(n); if(pos==-1): print("n=",n,",Invalid number"); else : print("n=",n,",Position ",pos); n=12 ; pos=findPosition(n); if(pos==-1): print("n=",n,",Invalid number"); else : print("n=",n,",Position ",pos); n=128 ; pos=findPosition(n); if(pos==-1): print("n=",n,",Invalid number"); else : print("n=",n,",Position ",pos); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 16; ; pos := findPosition(n); ; if (pos = -1) then ( execute ("n=")->display(); ) else ( execute ("n=")->display(); ) ; n := 12; ; pos := findPosition(n); ; if (pos = -1) then ( execute ("n=")->display(); ) else ( execute ("n=")->display(); ) ; n := 128; ; pos := findPosition(n); ; if (pos = -1) then ( execute ("n=")->display(); ) else ( execute ("n=")->display(); ); operation isPowerOfTwo(n : OclAny) pre: true post: true activity: return (if (n > 0 & ((MathLib.bitwiseAnd(n, (n - 1))) > 0)) then true else false endif);; operation findPosition(n : OclAny) pre: true post: true activity: if (isPowerOfTwo(n) = true) then ( return -1; ) else skip ; var i : int := 1; ; var pos : int := 1; ; while ((MathLib.bitwiseAnd(i, n)) = 0) do ( i := i * (2->pow(1)); ; pos := pos + 1;) ; return pos;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def canPlace(a,n,p,sep): prisoners_placed=1 last_prisoner_placed=a[0] for i in range(1,n): current_cell=a[i] if(current_cell-last_prisoner_placed>=sep): prisoners_placed+=1 last_prisoner_placed=current_cell if(prisoners_placed==p): return True return False def maxDistance(cell,n,p): cell=sorted(cell) start=0 end=cell[n-1]-cell[0] ans=0 while(start<=end): mid=start+((end-start)//2) if(canPlace(cell,n,p,mid)): ans=mid start=mid+1 else : end=mid-1 return ans cell=[1,2,8,4,9] n=len(cell) p=3 print(maxDistance(cell,n,p)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; cell := Sequence{1}->union(Sequence{2}->union(Sequence{8}->union(Sequence{4}->union(Sequence{ 9 })))) ; n := (cell)->size() ; p := 3 ; execute (maxDistance(cell, n, p))->display(); operation canPlace(a : OclAny, n : OclAny, p : OclAny, sep : OclAny) : OclAny pre: true post: true activity: var prisoners_placed : int := 1 ; var last_prisoner_placed : OclAny := a->first() ; for i : Integer.subrange(1, n-1) do ( var current_cell : OclAny := a[i+1] ; if ((current_cell - last_prisoner_placed->compareTo(sep)) >= 0) then ( prisoners_placed := prisoners_placed + 1 ; last_prisoner_placed := current_cell ; if (prisoners_placed = p) then ( return true ) else skip ) else skip) ; return false; operation maxDistance(cell : OclAny, n : OclAny, p : OclAny) : OclAny pre: true post: true activity: cell := cell->sort() ; var start : int := 0 ; var end : double := cell[n - 1+1] - cell->first() ; var ans : int := 0 ; while ((start->compareTo(end)) <= 0) do ( var mid : int := start + ((end - start) div 2) ; if (canPlace(cell, n, p, mid)) then ( ans := mid ; start := mid + 1 ) else ( end := mid - 1 )) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sum_of_series(n): result=0 if(n % 2==0): result=-(n*(n+1))//2 else : result=(n*(n+1))//2 return result if __name__=="__main__" : n=3 print(sum_of_series(n)) n=10 print(sum_of_series(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 3 ; execute (sum_of_series(n))->display() ; n := 10 ; execute (sum_of_series(n))->display() ) else skip; operation sum_of_series(n : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; if (n mod 2 = 0) then ( result := -(n * (n + 1)) div 2 ) else ( result := (n * (n + 1)) div 2 ) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=1000000007 def digitNumber(n): if(n==0): return 1 if(n==1): return 9 if(n % 2!=0): temp=digitNumber((n-1)//2)% mod return(9*(temp*temp)% mod)% mod else : temp=digitNumber(n//2)% mod return(temp*temp)% mod def countExcluding(n,d): if(d==0): return(9*digitNumber(n-1))% mod else : return(8*digitNumber(n-1))% mod d=9 n=3 print(countExcluding(n,d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : int := 1000000007 ; skip ; skip ; d := 9 ; n := 3 ; execute (countExcluding(n, d))->display(); operation digitNumber(n : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return 1 ) else skip ; if (n = 1) then ( return 9 ) else skip ; if (n mod 2 /= 0) then ( var temp : int := digitNumber((n - 1) div 2) mod mod ; return (9 * (temp * temp) mod mod) mod mod ) else ( temp := digitNumber(n div 2) mod mod ; return (temp * temp) mod mod ); operation countExcluding(n : OclAny, d : OclAny) : OclAny pre: true post: true activity: if (d = 0) then ( return (9 * digitNumber(n - 1)) mod mod ) else ( return (8 * digitNumber(n - 1)) mod mod ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): N=5 TWO_POW_N=2**N MASK=TWO_POW_N-1 def check_arrangement(digits): seen=set() digits |=digits<>i)& MASK) return len(seen)==TWO_POW_N start=2**(TWO_POW_N-N-1)+1 end=2**(TWO_POW_N-N) ans=sum(i for i in range(start,end,2)if check_arrangement(i)) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var N : int := 5 ; var TWO_POW_N : double := (2)->pow(N) ; var MASK : double := TWO_POW_N - 1 ; skip ; var start : double := (2)->pow((TWO_POW_N - N - 1)) + 1 ; var end : double := (2)->pow((TWO_POW_N - N)) ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name start))))))) , (argument (test (logical_test (comparison (expr (atom (name end))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (atom (name check_arrangement)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))))->sum() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find_max(A,N,K): Count=dict() for i in range(K-1): Count[A[i]]=Count.get(A[i],0)+1 Myset=dict() for x in Count : if(Count[x]==1): Myset[x]=1 for i in range(K-1,N): Count[A[i]]=Count.get(A[i],0)+1 if(Count[A[i]]==1): Myset[A[i]]=1 else : del Myset[A[i]] if(len(Myset)==0): print("Nothing") else : maxm=-10**9 for i in Myset : maxm=max(i,maxm) print(maxm) x=A[i-K+1] if x in Count.keys(): Count[x]-=1 if(Count[x]==1): Myset[x]=1 if(Count[x]==0): del Myset[x] a=[1,2,2,3,3] n=len(a) k=3 find_max(a,n,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 3 })))) ; var n : int := (a)->size() ; var k : int := 3 ; find_max(a, n, k); operation find_max(A : OclAny, N : OclAny, K : OclAny) pre: true post: true activity: var Count : Map := (arguments ( )) ; for i : Integer.subrange(0, K - 1-1) do ( Count[A[i+1]+1] := Count.get(A[i+1], 0) + 1) ; var Myset : Map := (arguments ( )) ; for x : Count->keys() do ( if (Count[x+1] = 1) then ( Myset[x+1] := 1 ) else skip) ; for i : Integer.subrange(K - 1, N-1) do ( Count[A[i+1]+1] := Count.get(A[i+1], 0) + 1 ; if (Count[A[i+1]+1] = 1) then ( Myset[A[i+1]+1] := 1 ) else ( execute (Myset[A[i+1]+1])->isDeleted() ) ; if ((Myset)->size() = 0) then ( execute ("Nothing")->display() ) else ( var maxm : double := (-10)->pow(9) ; for i : Myset->keys() do ( maxm := Set{i, maxm}->max()) ; execute (maxm)->display() ) ; var x : OclAny := A[i - K + 1+1] ; if (Count.keys())->includes(x) then ( Count[x+1] := Count[x+1] - 1 ; if (Count[x+1] = 1) then ( Myset[x+1] := 1 ) else skip ; if (Count[x+1] = 0) then ( execute (Myset[x+1])->isDeleted() ) else skip ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B,C,X=[int(input())for i in range(4)] ans=0 for a in range(A+1): for b in range(B+1): for c in range(C+1): if a*500+b*100+c*50==X : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var X : OclAny := null; Sequence{A,B,C,X} := Integer.subrange(0, 4-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var ans : int := 0 ; for a : Integer.subrange(0, A + 1-1) do ( for b : Integer.subrange(0, B + 1-1) do ( for c : Integer.subrange(0, C + 1-1) do ( if a * 500 + b * 100 + c * 50 = X then ( ans := ans + 1 ) else skip))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a_coins=int(input()) b_coins=int(input()) c_coins=int(input()) x_num=int(input()) def money_match(a,b,c): money=500*a+100*b+50*c if money==x_num : return 1 else : return 0 cnt=0 for a in range(a_coins+1): for b in range(b_coins+1): for c in range(c_coins+1): if money_match(a,b,c)==1 : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a_coins : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b_coins : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c_coins : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x_num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; var cnt : int := 0 ; for a : Integer.subrange(0, a_coins + 1-1) do ( for b : Integer.subrange(0, b_coins + 1-1) do ( for c : Integer.subrange(0, c_coins + 1-1) do ( if money_match(a, b, c) = 1 then ( cnt := cnt + 1 ) else skip))) ; execute (cnt)->display(); operation money_match(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: var money : double := 500 * a + 100 * b + 50 * c ; if money = x_num then ( return 1 ) else ( return 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A=int(input()) B=int(input()) C=int(input()) X=int(input()) L=[] a=0 b=0 c=0 count=0 for i in range((X//500)+1): a=i for j in range(((X-500*i)//100)+1): b=j c=int((X-500*a-100*b)/50) L.append([a,b,c]) for i in L : if i[0]<=A and i[1]<=B and i[2]<=C : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var C : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var X : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var L : Sequence := Sequence{} ; var a : int := 0 ; var b : int := 0 ; var c : int := 0 ; var count : int := 0 ; for i : Integer.subrange(0, (X div 500) + 1-1) do ( a := i ; for j : Integer.subrange(0, ((X - 500 * i) div 100) + 1-1) do ( b := j ; c := ("" + (((X - 500 * a - 100 * b) / 50)))->toInteger() ; execute ((Sequence{a}->union(Sequence{b}->union(Sequence{ c }))) : L))) ; for i : L do ( if (i->first()->compareTo(A)) <= 0 & (i[1+1]->compareTo(B)) <= 0 & (i[2+1]->compareTo(C)) <= 0 then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,x=[int(input())for _ in range(4)] print([500*x+100*y+50*z for z in range(c+1)for y in range(b+1)for x in range(a+1)].count(x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var x : OclAny := null; Sequence{a,b,c,x} := Integer.subrange(0, 4-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; execute (Integer.subrange(0, c + 1-1)->select(z; y : Integer.subrange(0, b + 1-1); x : Integer.subrange(0, a + 1-1) | true)->collect(z; y : Integer.subrange(0, b + 1-1); x : Integer.subrange(0, a + 1-1) | (500 * x + 100 * y + 50 * z))->count(x))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys a=int(sys.stdin.readline().strip()) b=int(sys.stdin.readline().strip()) c=int(sys.stdin.readline().strip()) x=int(sys.stdin.readline().strip()) ans=0 for i in range(a+1): for j in range(b+1): for k in range(c+1): if i*500+j*100+k*50==x : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : int := ("" + ((sys.stdin.readLine()->trim())))->toInteger() ; var b : int := ("" + ((sys.stdin.readLine()->trim())))->toInteger() ; var c : int := ("" + ((sys.stdin.readLine()->trim())))->toInteger() ; var x : int := ("" + ((sys.stdin.readLine()->trim())))->toInteger() ; var ans : int := 0 ; for i : Integer.subrange(0, a + 1-1) do ( for j : Integer.subrange(0, b + 1-1) do ( for k : Integer.subrange(0, c + 1-1) do ( if i * 500 + j * 100 + k * 50 = x then ( ans := ans + 1 ) else skip))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pushZerosToEnd(arr,n): count=0 for i in range(n): if arr[i]!=0 : arr[count]=arr[i] count+=1 while countunion(Sequence{9}->union(Sequence{8}->union(Sequence{4}->union(Sequence{0}->union(Sequence{0}->union(Sequence{2}->union(Sequence{7}->union(Sequence{0}->union(Sequence{6}->union(Sequence{0}->union(Sequence{ 9 }))))))))))) ; n := (arr)->size() ; pushZerosToEnd(arr, n) ; execute ("Array after pushing all zeros to end of array:")->display() ; execute (arr)->display(); operation pushZerosToEnd(arr : OclAny, n : OclAny) pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] /= 0 then ( arr[count+1] := arr[i+1] ; count := count + 1 ) else skip) ; while (count->compareTo(n)) < 0 do ( arr[count+1] := 0 ; count := count + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rotate(arr,n): x=arr[n-1] for i in range(n-1,0,-1): arr[i]=arr[i-1]; arr[0]=x ; arr=[1,2,3,4,5] n=len(arr) print("Given array is") for i in range(0,n): print(arr[i],end=' ') rotate(arr,n) print("\nRotated array is") for i in range(0,n): print(arr[i],end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ; n := (arr)->size() ; execute ("Given array is")->display() ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()) ; rotate(arr, n) ; execute ("\nRotated array is")->display() ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); operation rotate(arr : OclAny, n : OclAny) pre: true post: true activity: var x : OclAny := arr[n - 1+1] ; for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( arr[i+1] := arr[i - 1+1];) ; arr->first() := x;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : d=int(input()) l=600//d D=[] for i in range(l-1): D.append(((len(D)+1)**2)*d**3) print(sum(D)) except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : int := 600 div d ; var D : Sequence := Sequence{} ; for i : Integer.subrange(0, l - 1-1) do ( execute ((((((D)->size() + 1))->pow(2)) * (d)->pow(3)) : D)) ; execute ((D)->sum())->display()) catch (_e : OclException) do ( break) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) a=list(map(int,input().split())) if a[0]+a[1]>a[-1]: print(-1) else : print(1,2,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (a->first() + a[1+1]->compareTo(a->last())) > 0 then ( execute (-1)->display() ) else ( execute (1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math as mas for t in sys.stdin : i=int(t) sum=0 for j in range(0,600,i): sum+=i*j*j print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for t : OclFile["System.in"] do ( var i : int := ("" + ((t)))->toInteger() ; var sum : int := 0 ; for j : Integer.subrange(0, 600-1)->select( $x | ($x - 0) mod i = 0 ) do ( sum := sum + i * j * j) ; execute (sum)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque k=int(input()) d=deque([1,2,3,4,5,6,7,8,9]) for i in range(k): 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(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Sequence := (Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 9 }))))))))) ; for i : Integer.subrange(0, k-1) do ( var x : OclAny := d->first() ; d := d->tail() ; if x mod 10 /= 0 then ( execute ((10 * x + x mod 10 - 1) : d) ) else skip ; execute ((10 * x + x mod 10) : d) ; if x mod 10 /= 9 then ( execute ((10 * x + x mod 10 + 1) : d) ) else skip) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math def area(d,sum1,i): while i<=((600//d)-1): sum1=sum1+d*i*i*d*d i=i+1 return sum1 try : while True : d=int(input()) sum0=0 i=1 area_new=area(d,sum0,i) print(round(area_new)) except EOFError : pass ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; try ( while true do ( d := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sum0 : int := 0 ; i := 1 ; var area_new : OclAny := area(d, sum0, i) ; execute ((area_new)->round())->display())) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt pass))))); operation area(d : OclAny, sum1 : OclAny, i : OclAny) : OclAny pre: true post: true activity: while (i->compareTo(((600 div d) - 1))) <= 0 do ( sum1 := sum1 + d * i * i * d * d ; i := i + 1) ; return sum1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while(1): try : d=int(input()) except : break s=0 w=d while d<600 : h=d*d s+=h*w d+=w print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while (1) do ( try ( var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) catch (_e : OclException) do ( break) ; var s : int := 0 ; var w : int := d ; while d < 600 do ( var h : int := d * d ; s := s + h * w ; d := d + w) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- X=600 while True : try : d=int(input()) result=0 for i in range(d,X,d): result+=(i*i)*d print(result) except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var X : int := 600 ; while true do ( try ( var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var result : int := 0 ; for i : Integer.subrange(d, X-1)->select( $x | ($x - d) mod d = 0 ) do ( result := result + (i * i) * d) ; execute (result)->display()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPalindrome(str,l,r): while(ldisplay() ) else skip; operation isPalindrome(OclType["String"] : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: while ((l->compareTo(r)) < 0) do ( if (("" + ([l+1])) /= ("" + ([r+1]))) then ( return false ) else skip ; l := l + 1 ; r := r - 1) ; return true; operation CyclicShifts(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var n : int := (OclType["String"])->size() ; var left : int := 0 ; var right : double := n - 1 ; OclType["String"] := OclType["String"] + OclType["String"] ; var cnt : int := 0 ; while ((right->compareTo(2 * n - 1)) < 0) do ( if (isPalindrome(OclType["String"], left, right)) then ( break ) else skip ; cnt := cnt + 1 ; left := left + 1 ; right := right + 1) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNumbers(N): ans='7'*(N-1) even=ans+'6' ; odd=ans+'7' ; print("Even : ",even); print("Odd : ",odd); if __name__=="__main__" : n=4 ; findNumbers(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var n : int := 4; ; findNumbers(n); ) else skip; operation findNumbers(N : OclAny) pre: true post: true activity: var ans : String := StringLib.nCopies('7', (N - 1)) ; var even : String := ans + '6'; ; var odd : String := ans + '7'; ; execute ("Even : ")->display(); ; execute ("Odd : ")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) spyke=list(map(int,input().split())) d={} for x in spyke : if x in d : d[x]+=1 elif x!=0 : d[x]=1 count=0 flag=True for x in d.values(): if x==2 : count+=1 elif x>=3 : print(-1) flag=False break if flag : print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var spyke : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := Set{} ; for x : spyke do ( if (d)->includes(x) then ( d[x+1] := d[x+1] + 1 ) else (if x /= 0 then ( d[x+1] := 1 ) else skip)) ; var count : int := 0 ; var flag : boolean := true ; for x : d.values() do ( if x = 2 then ( count := count + 1 ) else (if x >= 3 then ( execute (-1)->display() ; flag := false ; break ) else skip)) ; if flag then ( execute (count)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict n=int(input()) s=list(map(int,input().split())) d=defaultdict(int) for i in s : d[i]+=1 d[0]=0 if len(list(filter(lambda x : x>2,d.values())))>0 : print(-1) else : print(len(list(filter(lambda x : x==2,d.values())))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := defaultdict(OclType["int"]) ; for i : s do ( d[i+1] := d[i+1] + 1) ; d->first() := 0 ; if (((d.values())->select( _x | (lambda x : OclAny in (x > 2))->apply(_x) = true )))->size() > 0 then ( execute (-1)->display() ) else ( execute ((((d.values())->select( _x | (lambda x : OclAny in (x = 2))->apply(_x) = true )))->size())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import* from decimal import* from collections import* import sys from typing import Collection from warnings import filters def _input(): return map(int,input().split()) def _list(): return list(map(int,input().split())) def _int(): return int(input()) def solves(): n=_int() lst=_list() lst=list(filter(lambda x : x>0,lst)) c=list(Counter(lst).values()) if any([i>2 for i in c]): print(-1) else : print(c.count(2)) t=1 for _ in range(0,t): solves() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solves()); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation _list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation _int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation solves() pre: true post: true activity: var n : OclAny := _int() ; var lst : OclAny := _list() ; lst := ((lst)->select( _x | (lambda x : OclAny in (x > 0))->apply(_x) = true )) ; var c : Sequence := (Counter(lst).values()) ; if (c->select(i | true)->collect(i | (i > 2)))->exists( _x | _x = true ) then ( execute (-1)->display() ) else ( execute (c->count(2))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) if a[0]+a[1]>a[-1]: print(-1) else : print(1,2,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (a->first() + a[1+1]->compareTo(a->last())) > 0 then ( execute (-1)->display() ) else ( execute (1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=list(map(int,input().split())) c=0 for x in b : if b.count(x)==2 and x>0 : c+=0.5 elif b.count(x)>2 and x>0 : c=-1 break print(int(c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; for x : b do ( if b->count(x) = 2 & x > 0 then ( c := c + 0.5 ) else (if b->count(x) > 2 & x > 0 then ( c := -1 ; break ) else skip)) ; execute (("" + ((c)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n,a=int(input()),(int(i)for i in input().split()) c=Counter(i for i in a if i>0) res=sum(v==2 for _,v in c.items()) res=res if all(v<=2 for _,v in c.items())else-1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))}} ; var c : OclAny := Counter((argument (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name a))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name i)))) > (comparison (expr (atom (number (integer 0)))))))))))) ; var res : OclAny := ((argument (test (logical_test (comparison (comparison (expr (atom (name v)))) == (comparison (expr (atom (number (integer 2)))))))) (comp_for for (exprlist (expr (atom (name _))) , (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name c)) (trailer . (name items) (arguments ( )))))))))->sum() ; res := if ((argument (test (logical_test (comparison (comparison (expr (atom (name v)))) <= (comparison (expr (atom (number (integer 2)))))))) (comp_for for (exprlist (expr (atom (name _))) , (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name c)) (trailer . (name items) (arguments ( )))))))))->forAll( _x | _x = true ) then res else -1 endif ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- K=int(input()) dp=[[str(i)]for i in range(1,10)] count=9 ansFlag=False while(True): if K<=9 : break for i in range(9): numList=dp[i] newNumList=[] for n in numList : lastNum=n[-1] if int(lastNum)>=1 : newNum1=str(n)+str(int(lastNum)-1) count+=1 newNumList.append(newNum1) if count==K : ansFlag=True break newNum2=str(n)+str(int(lastNum)) count+=1 newNumList.append(newNum2) if count==K : ansFlag=True break if int(lastNum)<=8 : newNum3=str(n)+str(int(lastNum)+1) count+=1 newNumList.append(newNum3) if count==K : ansFlag=True break if ansFlag : break dp[i]=newNumList if ansFlag : break ans=K if K>=10 : ans=newNumList[-1] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var dp : Sequence := Integer.subrange(1, 10-1)->select(i | true)->collect(i | (Sequence{ ("" + ((i))) })) ; var count : int := 9 ; var ansFlag : boolean := false ; while (true) do ( if K <= 9 then ( break ) else skip ; for i : Integer.subrange(0, 9-1) do ( var numList : OclAny := dp[i+1] ; var newNumList : Sequence := Sequence{} ; for n : numList do ( var lastNum : OclAny := n->last() ; if ("" + ((lastNum)))->toInteger() >= 1 then ( var newNum1 : String := ("" + ((n))) + ("" + ((("" + ((lastNum)))->toInteger() - 1))) ; count := count + 1 ; execute ((newNum1) : newNumList) ; if count = K then ( ansFlag := true ; break ) else skip ) else skip ; var newNum2 : String := ("" + ((n))) + ("" + ((("" + ((lastNum)))->toInteger()))) ; count := count + 1 ; execute ((newNum2) : newNumList) ; if count = K then ( ansFlag := true ; break ) else skip ; if ("" + ((lastNum)))->toInteger() <= 8 then ( var newNum3 : String := ("" + ((n))) + ("" + ((("" + ((lastNum)))->toInteger() + 1))) ; count := count + 1 ; execute ((newNum3) : newNumList) ; if count = K then ( ansFlag := true ; break ) else skip ) else skip) ; if ansFlag then ( break ) else skip ; dp[i+1] := newNumList) ; if ansFlag then ( break ) else skip) ; var ans : int := K ; if K >= 10 then ( ans := newNumList->last() ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CountPairs(arr,n): twoCount=0 twoGrCount=0 for i in range(0,n): if(arr[i]==2): twoCount+=1 elif(arr[i]>2): twoGrCount+=1 return((twoCount*twoGrCount)+(twoGrCount*(twoGrCount-1))/2) arr=[3,4,5] n=len(arr) print(CountPairs(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })) ; n := (arr)->size() ; execute (CountPairs(arr, n))->display(); operation CountPairs(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var twoCount : int := 0 ; var twoGrCount : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] = 2) then ( twoCount := twoCount + 1 ) else (if (arr[i+1] > 2) then ( twoGrCount := twoGrCount + 1 ) else skip)) ; return ((twoCount * twoGrCount) + (twoGrCount * (twoGrCount - 1)) / 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) arr=list(map(int,input().split())) f=-1 t=0 for i in range(n): if arr[i]>0 : f=i break if f==n-1 or f==-1 : print(0) continue ans=0 for i in range(f,n-1): if arr[i]>0 : ans+=arr[i] else : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var f : int := -1 ; var t : int := 0 ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] > 0 then ( f := i ; break ) else skip) ; if f = n - 1 or f = -1 then ( execute (0)->display() ; continue ) else skip ; var ans : int := 0 ; for i : Integer.subrange(f, n - 1-1) do ( if arr[i+1] > 0 then ( ans := ans + arr[i+1] ) else ( ans := ans + 1 )) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input().strip()) def check(a,n): re=0 for i in range(n-1): if a[i]!=0 : a=a[i : n-1] break if(len(a)==n): return 0 for i in range(len(a)): if a[i]!=0 : re+=a[i] elif a[i]==0 : re+=1 return re for _ in range(t): n=int(input().strip()) a=list(map(int,input().split(' '))) print(check(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + ((input()->trim())))->toInteger() ; skip ; for _anon : Integer.subrange(0, t-1) do ( n := ("" + ((input()->trim())))->toInteger() ; a := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; execute (check(a, n))->display()); operation check(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var re : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if a[i+1] /= 0 then ( a := a.subrange(i+1, n - 1) ; break ) else skip) ; if ((a)->size() = n) then ( return 0 ) else skip ; for i : Integer.subrange(0, (a)->size()-1) do ( if a[i+1] /= 0 then ( re := re + a[i+1] ) else (if a[i+1] = 0 then ( re := re + 1 ) else skip)) ; return re; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,A): res=0 B=[] for i,a in enumerate(A[: n-1]): if a==0 : B.append(i) ind=0 while indsize())->collect( _indx | Sequence{_indx-1, (A.subrange(1,n - 1))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); if a = 0 then ( execute ((i) : B) ) else skip) ; var ind : int := 0 ; while (ind->compareTo(n)) < 0 & not(A[ind+1]) do ( ind := ind + 1) ; for b : B do ( while (ind->compareTo(n)) < 0 & not(A[ind+1]) do ( ind := ind + 1) ; if (b->compareTo(ind)) < 0 then ( continue ) else skip ; res := res + 1 ; A[b+1] := A[b+1] + 1 ; A[ind+1] := A[ind+1] - 1) ; return res + (A.subrange(1,n - 1))->sum(); operation main() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, t) ; for i : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; A := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; ans[i+1] := solve(n, A)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) arr=list(map(int,input().split())) sum=0 k=None for i in range(n-1): if arr[i]>0 : k=i break if k==None : print(0) continue for i in range(k,n-1): if arr[i]>0 : sum+=arr[i] else : sum+=1 print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sum : int := 0 ; var k : OclAny := null ; for i : Integer.subrange(0, n - 1-1) do ( if arr[i+1] > 0 then ( k := i ; break ) else skip) ; if k = null then ( execute (0)->display() ; continue ) else skip ; for i : Integer.subrange(k, n - 1-1) do ( if arr[i+1] > 0 then ( sum := sum + arr[i+1] ) else ( sum := sum + 1 )) ; execute (sum)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : t-=1 a=int(input()) h=[int(x)for x in input().split()] past=False ans=int(0) all=int(0) for i in range(len(h)-1): if h[i]==0 : if past : ans+=1 else : past=True all+=h[i] print(ans+all) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( t := t - 1 ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var h : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var past : boolean := false ; var ans : int := ("" + ((0)))->toInteger() ; var all : int := ("" + ((0)))->toInteger() ; for i : Integer.subrange(0, (h)->size() - 1-1) do ( if h[i+1] = 0 then ( if past then ( ans := ans + 1 ) else skip ) else ( past := true ; all := all + h[i+1] )) ; execute (ans + all)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def getFirstSetBitPos(n): return math.log2(n &-n)+1 n=12 print(int(getFirstSetBitPos(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 12 ; execute (("" + ((getFirstSetBitPos(n))))->toInteger())->display(); operation getFirstSetBitPos(n : OclAny) : OclAny pre: true post: true activity: return + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def solve(): n,k=[int(i)for i in input().split(' ')] s=0 t=1 while ttoInteger()-1) do ( solve()); operation solve() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split(' ')->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var s : int := 0 ; var t : int := 1 ; while (t->compareTo(n)) < 0 & (t->compareTo(k)) < 0 do ( t := t * 2 ; s := s + 1) ; execute (s + (n - t + k - 1) div k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n1=int(input()) list_n=[] list1=[] for i in range(n1): list_n.append(int(input())) x=input().split() temp=[] for j in x : temp.append(int(j)) list1.append(temp) k=0 b1=False while b1==False : if k==len(list1): break ref=list1[k] first=1 second=2 total_1=ref[0]+ref[1] index_third=[i for i,x in enumerate(ref)if x>=total_1] if len(index_third)==0 : print(-1) k+=1 continue print(first,second,index_third[0]+1) k+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var list_n : Sequence := Sequence{} ; var list1 : Sequence := Sequence{} ; for i : Integer.subrange(0, n1-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : list_n) ; var x : OclAny := input().split() ; var temp : Sequence := Sequence{} ; for j : x do ( execute ((("" + ((j)))->toInteger()) : temp)) ; execute ((temp) : list1)) ; var k : int := 0 ; var b1 : boolean := false ; while b1 = false do ( if k = (list1)->size() then ( break ) else skip ; var ref : OclAny := list1[k+1] ; var first : int := 1 ; var second : int := 2 ; var total if k = (list1)->size() then ( break ) else skip : OclAny := ref->first() + ref[1+1] ; var index_third : Sequence := Integer.subrange(1, (ref)->size())->collect( _indx | Sequence{_indx-1, (ref)->at(_indx)} )->select(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in (x->compareTo(totali, x)) >= 0)->collect(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in (i)) ; if (index_third)->size() = 0 then ( execute (-1)->display() ; k := k + 1 ; continue ) else skip ; execute (first)->display() ; k := k + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get(): return list(map(int,input().split())) def intput(): return int(input()) def check(x): b=0 for i in x : if(i==')'): b-=1 else : b+=1 if(b<0): break return b==0 def main(): prem=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199] for _ in range(intput()): n=intput() if(n!=2): ans=[[0 for _ in range(n)]for _ in range(n)] for i in range(0,n-2): ans[i][n-1]=1 ans[i][n-2]=1 ans[n-1][i]=1 ans[n-2][i]=1 for i in prem : if(i>=n-2): if(i-n+2 not in prem): ans[n-1][n-1]=i-n+2 ans[n-2][n-2]=i-n+2 break for row in ans : print(*row) else : print("1 1") print("1 1") main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; main(); operation get() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation intput() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation check(x : OclAny) : OclAny pre: true post: true activity: var b : int := 0 ; for i : x do ( if (i = ')') then ( b := b - 1 ) else ( b := b + 1 ) ; if (b < 0) then ( break ) else skip) ; return b = 0; operation main() pre: true post: true activity: var prem : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{11}->union(Sequence{13}->union(Sequence{17}->union(Sequence{19}->union(Sequence{23}->union(Sequence{29}->union(Sequence{31}->union(Sequence{37}->union(Sequence{41}->union(Sequence{43}->union(Sequence{47}->union(Sequence{53}->union(Sequence{59}->union(Sequence{61}->union(Sequence{67}->union(Sequence{71}->union(Sequence{73}->union(Sequence{79}->union(Sequence{83}->union(Sequence{89}->union(Sequence{97}->union(Sequence{101}->union(Sequence{103}->union(Sequence{107}->union(Sequence{109}->union(Sequence{113}->union(Sequence{127}->union(Sequence{131}->union(Sequence{137}->union(Sequence{139}->union(Sequence{149}->union(Sequence{151}->union(Sequence{157}->union(Sequence{163}->union(Sequence{167}->union(Sequence{173}->union(Sequence{179}->union(Sequence{181}->union(Sequence{191}->union(Sequence{193}->union(Sequence{197}->union(Sequence{ 199 }))))))))))))))))))))))))))))))))))))))))))))) ; for _anon : Integer.subrange(0, intput()-1) do ( var n : OclAny := intput() ; if (n /= 2) then ( var ans : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)))) ; for i : Integer.subrange(0, n - 2-1) do ( ans[i+1][n - 1+1] := 1 ; ans[i+1][n - 2+1] := 1 ; ans[n - 1+1][i+1] := 1 ; ans[n - 2+1][i+1] := 1) ; for i : prem do ( if ((i->compareTo(n - 2)) >= 0) then ( if ((prem)->excludes(i - n + 2)) then ( ans[n - 1+1][n - 1+1] := i - n + 2 ; ans[n - 2+1][n - 2+1] := i - n + 2 ; break ) else skip ) else skip) ; for row : ans do ( execute ((argument * (test (logical_test (comparison (expr (atom (name row))))))))->display()) ) else ( execute ("1 1")->display() ; execute ("1 1")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: r=1,1,*[0]*(int(s)-2) for _ in r : print(*r); r=r[1 :]+r[: 1] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var r : OclAny := 1,1,MatrixLib.elementwiseMult(Sequence{ 0 }, (("" + ((s)))->toInteger() - 2)) ; for _anon : r do ( execute ((argument * (test (logical_test (comparison (expr (atom (name r))))))))->display(); r := r->tail() + r.subrange(1,1))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def isprime(t): for i in range(2,int(math.sqrt(t))+1): if t % i==0 : return False return True def hi(t): r=1 while(True): if not(isprime(r)): if(isprime(((t-1)*(t))+r)): return r r+=1 for _ in range(int(input())): n=int(input()) if n==1 : print(1) elif isprime(n): for i in range(n): for j in range(n): print(1,end=' ') print() else : x=hi(n) for i in range(n): for j in range(n): if i==j : print(x,end=' ') else : print(n,end=' ') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (1)->display() ) else (if isprime(n) then ( for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( execute (1)->display()) ; execute (->display()) ) else ( var x : OclAny := hi(n) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if i = j then ( execute (x)->display() ) else ( execute (n)->display() )) ; execute (->display()) ) ) ); operation isprime(t : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(2, ("" + (((t)->sqrt())))->toInteger() + 1-1) do ( if t mod i = 0 then ( return false ) else skip) ; return true; operation hi(t : OclAny) : OclAny pre: true post: true activity: var r : int := 1 ; while (true) do ( if not((isprime(r))) then ( if (isprime(((t - 1) * (t)) + r)) then ( return r ) else skip ) else skip ; r := r + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): k=int(input()) d=dict() order=0 find=False for n_digit in range(1,20): if n_digit==1 : for i in range(10): d[(n_digit,i)]=1 else : for i in range(10): d[(n_digit,i)]=d[(n_digit-1,i)] if i>=1 : d[(n_digit,i)]+=d[(n_digit-1,i-1)] if i<=8 : d[(n_digit,i)]+=d[(n_digit-1,i+1)] for i in range(1,10): if order+d[(n_digit,i)]toInteger() ; var d : Map := (arguments ( )) ; var order : int := 0 ; var find : boolean := false ; for n_digit : Integer.subrange(1, 20-1) do ( if n_digit = 1 then ( for i : Integer.subrange(0, 10-1) do ( d[Sequence{n_digit, i}+1] := 1) ) else ( for i : Integer.subrange(0, 10-1) do ( d[Sequence{n_digit, i}+1] := d[Sequence{n_digit - 1, i}+1] ; if i >= 1 then ( d[Sequence{n_digit, i}+1] := d[Sequence{n_digit, i}+1] + d[Sequence{n_digit - 1, i - 1}+1] ) else skip ; if i <= 8 then ( d[Sequence{n_digit, i}+1] := d[Sequence{n_digit, i}+1] + d[Sequence{n_digit - 1, i + 1}+1] ) else skip) ) ; for i : Integer.subrange(1, 10-1) do ( if (order + d[Sequence{n_digit, i}+1]->compareTo(k)) < 0 then ( order := order + d[Sequence{n_digit, i}+1] ) else ( find := true ) ; if find then ( break ) else skip) ; if find then ( break ) else skip) ; var ans : Sequence := () ; execute ((i) : ans) ; for digit : Integer.subrange(0 + 1, n_digit - 1)->reverse() do ( for j : Integer.subrange(i - 1, i + 2-1) do ( if 0 <= j & (j <= 9) then ( if (order + d[Sequence{digit, j}+1]->compareTo(k)) < 0 then ( order := order + d[Sequence{digit, j}+1] ) else ( execute ((j) : ans) ; var i : OclAny := j ; break ) ) else skip)) ; execute (StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- iter=int(input()) for _ in range(iter): n=int(input()) s="1 "*(n-2) if((107-n+2)% 2): s+="1 " s+=str(107-n+1)+" " else : s+="4 " s+=str(107-n-2)+" " for i in range(0,2*n,2): print(s[i :]+s[: i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var iter : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, iter-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := StringLib.nCopies("1 ", (n - 2)) ; if ((107 - n + 2) mod 2) then ( s := s + "1 " ; s := s + ("" + ((107 - n + 1))) + " " ) else ( s := s + "4 " ; s := s + ("" + ((107 - n - 2))) + " " ) ; for i : Integer.subrange(0, 2 * n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( execute (s.subrange(i+1) + s.subrange(1,i))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout T=int(stdin.readline()) for i in range(T): N=int(stdin.readline()) GRID=[] for j in range(N): G=[] for k in range(N): if k==j or(j+k)==(N-1): G.append(1) else : G.append(0) GRID.append(G) if N % 2!=0 : GRID[N//2][N//2-1]=1 ; GRID[N//2][N//2+1]=1 ; GRID[N//2-1][N//2]=1 ; GRID[N//2+1][N//2]=1 ; for j in range(N): print(*GRID[j]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var T : int := ("" + ((stdin.readLine())))->toInteger() ; for i : Integer.subrange(0, T-1) do ( var N : int := ("" + ((stdin.readLine())))->toInteger() ; var GRID : Sequence := Sequence{} ; for j : Integer.subrange(0, N-1) do ( var G : Sequence := Sequence{} ; for k : Integer.subrange(0, N-1) do ( if k = j or (j + k) = (N - 1) then ( execute ((1) : G) ) else ( execute ((0) : G) )) ; execute ((G) : GRID)) ; if N mod 2 /= 0 then ( GRID[N div 2+1][N div 2 - 1+1] := 1; GRID[N div 2+1][N div 2 + 1+1] := 1; ; GRID[N div 2 - 1+1][N div 2+1] := 1; GRID[N div 2 + 1+1][N div 2+1] := 1; ) else skip ; for j : Integer.subrange(0, N-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name GRID)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countX(n): binary="{0:b}".format(n) count=0 for i in range(len(binary)): if(binary[i]=='1'): count+=1 answer=int(pow(2,count)) return answer if __name__=="__main__" : n=5 answer=countX(n) print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 5 ; answer := countX(n) ; execute (answer)->display() ) else skip; operation countX(n : OclAny) : OclAny pre: true post: true activity: var binary : String := StringLib.interpolateStrings("{0:b}", Sequence{n}) ; var count : int := 0 ; for i : Integer.subrange(0, (binary)->size()-1) do ( if (binary[i+1] = '1') then ( count := count + 1 ) else skip) ; var answer : int := ("" + (((2)->pow(count))))->toInteger() ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- st=input() ans=(len(st)+1)*25 print(ans+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var st : String := (OclFile["System.in"]).readLine() ; var ans : int := ((st)->size() + 1) * 25 ; execute (ans + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(len(input())*25+26) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (((OclFile["System.in"]).readLine())->size() * 25 + 26)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() num=51 print((len(s)-1)*25+num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var num : int := 51 ; execute (((s)->size() - 1) * 25 + num)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : x=input() if x=="0" : break a=0 b=0 for i in range(1,len(x)): if x[i]=="A" : a+=1 else : b+=1 if a>b : a+=1 else : b+=1 print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var x : String := (OclFile["System.in"]).readLine() ; if x = "0" then ( break ) else skip ; var a : int := 0 ; var b : int := 0 ; for i : Integer.subrange(1, (x)->size()-1) do ( if x[i+1] = "A" then ( a := a + 1 ) else ( b := b + 1 )) ; if (a->compareTo(b)) > 0 then ( a := a + 1 ) else ( b := b + 1 ) ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() print((26*(len(s)+1))-len(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; execute ((26 * ((s)->size() + 1)) - (s)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() print(len(a)*25+26) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; execute ((a)->size() * 25 + 26)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cntWays(arr,n): if(n==1): return 0 ; tot_sum=0 ; sum=0 ; ans=0 ; for i in range(0,n): tot_sum+=arr[i]; for i in range(0,n-1): sum+=arr[i]; if(sum==tot_sum/2): ans+=1 ; return ans ; arr=[1,-1,1,-1,1,-1]; n=len(arr); print(cntWays(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{-1}->union(Sequence{1}->union(Sequence{-1}->union(Sequence{1}->union(Sequence{ -1 }))))); ; n := (arr)->size(); ; execute (cntWays(arr, n))->display();; operation cntWays(arr : OclAny, n : OclAny) pre: true post: true activity: if (n = 1) then ( return 0; ) else skip ; var tot_sum : int := 0; var sum : int := 0; var ans : int := 0; ; for i : Integer.subrange(0, n-1) do ( tot_sum := tot_sum + arr[i+1];) ; for i : Integer.subrange(0, n - 1-1) do ( sum := sum + arr[i+1]; ; if (sum = tot_sum / 2) then ( ans := ans + 1; ) else skip) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minNumber(a,n,x): l=0 h=0 e=0 for i in range(n): if a[i]==x : e+=1 elif a[i]>x : h+=1 elif a[i]h : ans=l-h elif lunion(Sequence{20}->union(Sequence{ 30 })) ; n := (a)->size() ; execute (minNumber(a, n, x))->display(); operation minNumber(a : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: var l : int := 0 ; var h : int := 0 ; var e : int := 0 ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = x then ( e := e + 1 ) else (if (a[i+1]->compareTo(x)) > 0 then ( h := h + 1 ) else (if (a[i+1]->compareTo(x)) < 0 then ( l := l + 1 ) else skip ) ) ) ; var ans : int := 0; ; if (l->compareTo(h)) > 0 then ( ans := l - h ) else (if (l->compareTo(h)) < 0 then ( ans := h - l - 1; ) else skip) ; return ans + 1 - e; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) lunlun=[None for _ in range(100)] lunlun[0]=(1,2,3,4,5,6,7,8,9) for i in range(0,10): tmp=[] for j in lunlun[i]: s=j % 10 if s==0 : tmp+=j*10+0, tmp+=j*10+1, elif s==9 : tmp+=j*10+8, tmp+=j*10+9, else : tmp+=j*10+s-1, tmp+=j*10+s, tmp+=j*10+s+1, lunlun[i+1]=tuple(tmp) L=[] for i in range(0,10): for j in lunlun[i]: L+=j, print(L[k-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lunlun : Sequence := Integer.subrange(0, 100-1)->select(_anon | true)->collect(_anon | (null)) ; lunlun->first() := Sequence{1, 2, 3, 4, 5, 6, 7, 8, 9} ; for i : Integer.subrange(0, 10-1) do ( var tmp : Sequence := Sequence{} ; for j : lunlun[i+1] do ( var s : int := j mod 10 ; if s = 0 then ( tmp := tmp + (testlist (test (logical_test (comparison (expr (expr (expr (atom (name j))) * (expr (atom (number (integer 10))))) + (expr (atom (number (integer 0)))))))) ,) ; tmp := tmp + (testlist (test (logical_test (comparison (expr (expr (expr (atom (name j))) * (expr (atom (number (integer 10))))) + (expr (atom (number (integer 1)))))))) ,) ) else (if s = 9 then ( tmp := tmp + (testlist (test (logical_test (comparison (expr (expr (expr (atom (name j))) * (expr (atom (number (integer 10))))) + (expr (atom (number (integer 8)))))))) ,) ; tmp := tmp + (testlist (test (logical_test (comparison (expr (expr (expr (atom (name j))) * (expr (atom (number (integer 10))))) + (expr (atom (number (integer 9)))))))) ,) ) else ( tmp := tmp + (testlist (test (logical_test (comparison (expr (expr (expr (expr (atom (name j))) * (expr (atom (number (integer 10))))) + (expr (atom (name s)))) - (expr (atom (number (integer 1)))))))) ,) ; tmp := tmp + (testlist (test (logical_test (comparison (expr (expr (expr (atom (name j))) * (expr (atom (number (integer 10))))) + (expr (atom (name s))))))) ,) ; tmp := tmp + (testlist (test (logical_test (comparison (expr (expr (expr (expr (atom (name j))) * (expr (atom (number (integer 10))))) + (expr (atom (name s)))) + (expr (atom (number (integer 1)))))))) ,) ) ) ) ; lunlun[i + 1+1] := (tmp)) ; var L : Sequence := Sequence{} ; for i : Integer.subrange(0, 10-1) do ( for j : lunlun[i+1] do ( L := L + (testlist (test (logical_test (comparison (expr (atom (name j)))))) ,))) ; execute (L[k - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isSquarePossible(arr,n,l): cnt=0 for i in range(n): if arr[i]>=l : cnt+=1 if cnt>=l : return True return False def maxArea(arr,n): l,r=0,n len=0 while l<=r : m=l+((r-l)//2) if isSquarePossible(arr,n,m): len=m l=m+1 else : r=m-1 return(len*len) arr=[1,3,4,5,5] n=len(arr) print(maxArea(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{1}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 5 })))) ; n := (arr)->size() ; execute (maxArea(arr, n))->display(); operation isSquarePossible(arr : OclAny, n : OclAny, l : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1]->compareTo(l)) >= 0 then ( cnt := cnt + 1 ) else skip ; if (cnt->compareTo(l)) >= 0 then ( return true ) else skip) ; return false; operation maxArea(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var r : OclAny := null; Sequence{l,r} := Sequence{0,n} ; var len : int := 0 ; while (l->compareTo(r)) <= 0 do ( var m : OclAny := l + ((r - l) div 2) ; if isSquarePossible(arr, n, m) then ( len := m ; l := m + 1 ) else ( var r : double := m - 1 )) ; return (len * len); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printLargestString(s,l,r): freq=[0]*26 l-=1 r-=1 for i in range(min(l,r),max(l,r)+1): freq[ord(s[i])-ord('a')]+=1 ans="" for i in range(25,-1,-1): while(freq[i]): ans+=chr(ord('a')+i) freq[i]-=1 return ans if __name__=="__main__" : s="striver" l=3 r=5 print(printLargestString(s,l,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "striver" ; l := 3 ; r := 5 ; execute (printLargestString(s, l, r))->display() ) else skip; operation printLargestString(s : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; l := l - 1 ; r := r - 1 ; for i : Integer.subrange(Set{l, r}->min(), Set{l, r}->max() + 1-1) do ( freq[(s[i+1])->char2byte() - ('a')->char2byte()+1] := freq[(s[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; var ans : String := "" ; for i : Integer.subrange(-1 + 1, 25)->reverse() do ( while (freq[i+1]) do ( ans := ans + (('a')->char2byte() + i)->byte2char() ; freq[i+1] := freq[i+1] - 1)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(i)for i in input().split()] s,e=1,n ans=1 for i in range(m): t=input().split() if "right" in t : s=max(s,int(t[-1])+1) else : e=min(e,int(t[-1])-1) if s>e : ans=0 ; break if ans : print(e-s+1) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var s : OclAny := null; var e : OclAny := null; Sequence{s,e} := Sequence{1,n} ; var ans : int := 1 ; for i : Integer.subrange(0, m-1) do ( var t : OclAny := input().split() ; if (t)->includes("right") then ( var s : OclAny := Set{s, ("" + ((t->last())))->toInteger() + 1}->max() ) else ( var e : OclAny := Set{e, ("" + ((t->last())))->toInteger() - 1}->min() ) ; if (s->compareTo(e)) > 0 then ( ans := 0; break ) else skip) ; if ans then ( execute (e - s + 1)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import collections import copy import enum import functools import heapq import itertools import math import random import re import sys import time import string from typing import List sys.setrecursionlimit(3001) input=sys.stdin.readline n,m=map(int,input().split()) l=1 r=n for _ in range(m): ss=input().split() if ss[2]=="left" : r=min(r,int(ss[4])-1) else : l=max(l,int(ss[4])+1) if rcollect( _x | (OclType["int"])->apply(_x) ) ; var l : int := 1 ; var r : OclAny := n ; for _anon : Integer.subrange(0, m-1) do ( var ss : OclAny := input().split() ; if ss[2+1] = "left" then ( r := Set{r, ("" + ((ss[4+1])))->toInteger() - 1}->min() ) else ( l := Set{l, ("" + ((ss[4+1])))->toInteger() + 1}->max() )) ; if (r->compareTo(l)) < 0 then ( execute (-1)->display() ) else ( execute (r - l + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=[int(i)for i in input().split()] i=1 j=n for c in range(k): m=input().strip() if('left' in m): x=int(m[15 :]) j=min(j,x-1) elif('right' in m): y=int(m[15 :]) i=max(i,y+1) if((j-i+1)<=0): print('-1') else : print(j-i+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var i : int := 1 ; var j : OclAny := n ; for c : Integer.subrange(0, k-1) do ( var m : OclAny := input()->trim() ; if ((m)->includes('left')) then ( var x : int := ("" + ((m.subrange(15+1))))->toInteger() ; j := Set{j, x - 1}->min() ) else (if ((m)->includes('right')) then ( var y : int := ("" + ((m.subrange(15+1))))->toInteger() ; i := Set{i, y + 1}->max() ) else skip)) ; if ((j - i + 1) <= 0) then ( execute ('-1')->display() ) else ( execute (j - i + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,arr): if arr[0]+arr[1]>arr[n-1]: return-1 else : return "1 2 "+str(n) if __name__=='__main__' : t=int(input()) for i in range(0,t): n=int(input()) arr=list(map(int,input().rstrip().split(" "))) print(solve(n,arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; arr := ((input().rstrip().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; execute (solve(n, arr))->display()) ) else skip; operation solve(n : OclAny, arr : OclAny) : OclAny pre: true post: true activity: if (arr->first() + arr[1+1]->compareTo(arr[n - 1+1])) > 0 then ( return -1 ) else ( return "1 2 " + ("" + ((n))) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* def merge(l1,r1,l2,r2): if r1collect( _x | (OclType["int"])->apply(_x) ) ; var L : int := 1; var R : OclAny := n ; var ok : boolean := true ; for mm : Integer.subrange(0, m-1) do ( var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; var l : int := 0; var r : int := 0 ; if s[7+1] = 'l' then ( l := 1; r := ("" + ((s.subrange(15+1))))->toInteger() - 1 ) else skip ; if s[7+1] = 'r' then ( l := ("" + ((s.subrange(16+1))))->toInteger() + 1; r := n ) else skip ; if (r->compareTo(l)) < 0 then ( ok := false ; break ) else skip ; Sequence{L,R} := merge(L, R, l, r) ; if L = -1 then ( ok := false ; break ) else skip) ; execute (if ok then R - L + 1 else "-1" endif)->display(); operation merge(l1 : OclAny, r1 : OclAny, l2 : OclAny, r2 : OclAny) : OclAny pre: true post: true activity: if (r1->compareTo(l2)) < 0 then ( return -1, -1 ) else skip ; if (r2->compareTo(l1)) < 0 then ( return -1, -1 ) else skip ; return Set{l1, l2}->max(), Set{r1, r2}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) left,right=list(),list() left.append(n+1) right.append(0) for _ in range(m): s=input() idx=int(s.split()[4]) if s[7]=='l' : left.append(idx) else : right.append(idx) left.sort() right.sort() res=left[0]-right[-1]-1 if res<=0 : res=-1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var left : OclAny := null; var right : OclAny := null; Sequence{left,right} := Sequence{(),()} ; execute ((n + 1) : left) ; execute ((0) : right) ; for _anon : Integer.subrange(0, m-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var idx : int := ("" + ((s.split()[4+1])))->toInteger() ; if s[7+1] = 'l' then ( execute ((idx) : left) ) else ( execute ((idx) : right) )) ; left := left->sort() ; right := right->sort() ; var res : double := left->first() - right->last() - 1 ; if res <= 0 then ( res := -1 ) else skip ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) a=[len(i)for i in input().replace('','').split('0')if len(i)>0] b=[len(i)for i in input().replace('','').split('0')if len(i)>0] d=[(i,k//i)for i in range(1,int(k**0.5)+1)if k % i==0] d+=[(j,i)for i,j in d if i!=j] c=0 for x,y in d : c+=sum(i-x+1 for i in a if x<=i)*sum(j-y+1 for j in b if y<=j) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := input().replace('', '').split('0')->select(i | (i)->size() > 0)->collect(i | ((i)->size())) ; var b : Sequence := input().replace('', '').split('0')->select(i | (i)->size() > 0)->collect(i | ((i)->size())) ; var d : Sequence := Integer.subrange(1, ("" + (((k)->pow(0.5))))->toInteger() + 1-1)->select(i | k mod i = 0)->collect(i | (Sequence{i, k div i})) ; d := d + d->select(_tuple | let i : OclAny = _tuple->at(1) in let j : OclAny = _tuple->at(2) in i /= j)->collect(_tuple | let i : OclAny = _tuple->at(1) in let j : OclAny = _tuple->at(2) in (Sequence{j, i})) ; var c : int := 0 ; for _tuple : d do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); c := c + ((argument (test (logical_test (comparison (expr (expr (expr (atom (name i))) - (expr (atom (name x)))) + (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name a))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name x)))) <= (comparison (expr (atom (name i)))))))))))->sum() * ((argument (test (logical_test (comparison (expr (expr (expr (atom (name j))) - (expr (atom (name y)))) + (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name b))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name y)))) <= (comparison (expr (atom (name j)))))))))))->sum()) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def func(): n,m,k=map(int,input().strip().split()) a=list(map(int,input().strip().split())) b=list(map(int,input().strip().split())) print(sub_matrix(a,b,n,m,k)) def sub_matrix(nums_a,nums_b,n,m,target): def get_len_freq(nums): nums_size=len(nums) len_freq=[0 for _ in range(nums_size+2)] cur_len=0 for i in range(nums_size): if nums[i]==1 : cur_len+=1 len_freq[1]+=1 len_freq[cur_len+1]-=1 else : cur_len=0 for i in range(1,nums_size+1): len_freq[i]+=len_freq[i-1] return len_freq len_freq_a=get_len_freq(nums_a) len_freq_b=get_len_freq(nums_b) res=0 for x in range(1,n+1): if target % x!=0 : continue y=target//x if y>m : continue res+=len_freq_a[x]*len_freq_b[y] return res if __name__=="__main__" : func() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( func() ) else skip; operation func() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (sub_matrix(a, b, n, m, k))->display(); operation sub_matrix(nums_a : OclAny, nums_b : OclAny, n : OclAny, m : OclAny, target : OclAny) : OclAny pre: true post: true activity: skip ; var len_freq_a : OclAny := get_len_freq(nums_a) ; var len_freq_b : OclAny := get_len_freq(nums_b) ; var res : int := 0 ; for x : Integer.subrange(1, n + 1-1) do ( if target mod x /= 0 then ( continue ) else skip ; var y : int := target div x ; if (y->compareTo(m)) > 0 then ( continue ) else skip ; res := res + len_freq_a[x+1] * len_freq_b[y+1]) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def func(arr,length,source): count=0 for temp_i in range(length): if source[temp_i]==1 : count+=1 else : arr.append(count) count=0 else : arr.append(count) n,m,k=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) height=[] weight=[] rem=[] result=0 func(height,n,a) func(weight,m,b) for i in range(1,int(k**0.5)+1): if k % i==0 : rem.append((i,k//i)) if i!=k//i : rem.append((k//i,i)) for i in range(len(rem)): l_h=0 l_w=0 for j in range(len(height)): if height[j]>=rem[i][0]: l_h+=height[j]-rem[i][0]+1 for g in range(len(weight)): if weight[g]>=rem[i][1]: l_w+=weight[g]-rem[i][1]+1 result+=l_h*l_w print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var height : Sequence := Sequence{} ; var weight : Sequence := Sequence{} ; var rem : Sequence := Sequence{} ; var result : int := 0 ; func(height, n, a) ; func(weight, m, b) ; for i : Integer.subrange(1, ("" + (((k)->pow(0.5))))->toInteger() + 1-1) do ( if k mod i = 0 then ( execute ((Sequence{i, k div i}) : rem) ; if i /= k div i then ( execute ((Sequence{k div i, i}) : rem) ) else skip ) else skip) ; for i : Integer.subrange(0, (rem)->size()-1) do ( var l_h : int := 0 ; var l_w : int := 0 ; for j : Integer.subrange(0, (height)->size()-1) do ( if (height[j+1]->compareTo(rem[i+1]->first())) >= 0 then ( l_h := l_h + height[j+1] - rem[i+1]->first() + 1 ) else skip) ; for g : Integer.subrange(0, (weight)->size()-1) do ( if (weight[g+1]->compareTo(rem[i+1][1+1])) >= 0 then ( l_w := l_w + weight[g+1] - rem[i+1][1+1] + 1 ) else skip) ; result := result + l_h * l_w) ; execute (result)->display(); operation func(arr : OclAny, length : OclAny, source : OclAny) pre: true post: true activity: var count : int := 0 ; (compound_stmt for (exprlist (expr (atom (name temp_i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name length)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name source)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name temp_i)))))))) ])))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name count)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name arr)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name count)))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name count)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name arr)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name count)))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque k=int(input()) l=["1","2","3","4","5","6","7","8","9"] m=["1","2","3","4","5","6","7","8","9"] queue=deque(["1","2","3","4","5","6","7","8","9"]) while len(l)toInteger() ; var l : Sequence := Sequence{"1"}->union(Sequence{"2"}->union(Sequence{"3"}->union(Sequence{"4"}->union(Sequence{"5"}->union(Sequence{"6"}->union(Sequence{"7"}->union(Sequence{"8"}->union(Sequence{ "9" })))))))) ; var m : Sequence := Sequence{"1"}->union(Sequence{"2"}->union(Sequence{"3"}->union(Sequence{"4"}->union(Sequence{"5"}->union(Sequence{"6"}->union(Sequence{"7"}->union(Sequence{"8"}->union(Sequence{ "9" })))))))) ; var queue : Sequence := (Sequence{"1"}->union(Sequence{"2"}->union(Sequence{"3"}->union(Sequence{"4"}->union(Sequence{"5"}->union(Sequence{"6"}->union(Sequence{"7"}->union(Sequence{"8"}->union(Sequence{ "9" }))))))))) ; while ((l)->size()->compareTo(k + 1)) < 0 do ( var i : OclAny := queue->first() ; queue := queue->tail() ; if i->last() = "0" then ( execute ((i + "0") : l) ; execute ((i + "1") : l) ; execute ((i + "0") : queue) ; execute ((i + "1") : queue) ) else (if i->last() = "9" then ( execute ((i + "8") : l) ; execute ((i + "9") : l) ; execute ((i + "8") : queue) ; execute ((i + "9") : queue) ) else ( execute ((i + ("" + ((("" + ((i->last())))->toInteger() - 1)))) : l) ; execute ((i + ("" + ((("" + ((i->last())))->toInteger())))) : l) ; execute ((i + ("" + ((("" + ((i->last())))->toInteger() + 1)))) : l) ; execute ((i + ("" + ((("" + ((i->last())))->toInteger() - 1)))) : queue) ; execute ((i + ("" + ((("" + ((i->last())))->toInteger())))) : queue) ; execute ((i + ("" + ((("" + ((i->last())))->toInteger() + 1)))) : queue) ) ) ) ; execute (l[k - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def divisor(i): s=[] for j in range(1,int(i**(1/2))+1): if i % j==0 : s.append(i//j) s.append(j) return sorted(set(s)) n,m,k=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) cnt1=defaultdict(lambda : 0) cnt2=defaultdict(lambda : 0) c=0 for i in a : if i : c+=1 elif c : cnt1[c]+=1 c=0 if c : cnt1[c]+=1 c=0 for i in b : if i : c+=1 elif c : cnt2[c]+=1 c=0 if c : cnt2[c]+=1 x=[(i,cnt1[i])for i in cnt1] y=[(i,cnt2[i])for i in cnt2] ans=0 s=divisor(k) for u in s : v=k//u if ncollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt1 : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; var cnt2 : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; var c : int := 0 ; for i : a do ( if i then ( c := c + 1 ) else (if c then ( cnt1[c+1] := cnt1[c+1] + 1 ; c := 0 ) else skip)) ; if c then ( cnt1[c+1] := cnt1[c+1] + 1 ; c := 0 ) else skip ; for i : b do ( if i then ( c := c + 1 ) else (if c then ( cnt2[c+1] := cnt2[c+1] + 1 ; c := 0 ) else skip)) ; if c then ( cnt2[c+1] := cnt2[c+1] + 1 ) else skip ; var x : Sequence := cnt1->select(i | true)->collect(i | (Sequence{i, cnt1[i+1]})) ; var y : Sequence := cnt2->select(i | true)->collect(i | (Sequence{i, cnt2[i+1]})) ; var ans : int := 0 ; s := divisor(k) ; for u : s do ( var v : int := k div u ; if (n->compareTo(u)) < 0 or (m->compareTo(v)) < 0 then ( continue ) else skip ; var c1 : OclAny := null; var c2 : OclAny := null; Sequence{c1,c2} := Sequence{0,0} ; for _tuple : x do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); c1 := c1 + Set{i - u + 1, 0}->max() * j) ; for _tuple : y do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); c2 := c2 + Set{i - v + 1, 0}->max() * j) ; ans := ans + c1 * c2) ; execute (ans)->display(); operation divisor(i : OclAny) : OclAny pre: true post: true activity: var s : Sequence := Sequence{} ; for j : Integer.subrange(1, ("" + (((i)->pow((1 / 2)))))->toInteger() + 1-1) do ( if i mod j = 0 then ( execute ((i div j) : s) ; execute ((j) : s) ) else skip) ; return Set{}->union((s))->sort(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dx=(-1,0,1,0) dy=(0,1,0,-1) while True : n=int(input()) if n==0 : break x=list() y=list() x.append(0) y.append(0) for i in range(n-1): k,d=map(int,input().split()) x.append(x[k]+dx[d]) y.append(y[k]+dy[d]) print(max(x)-min(x)+1,max(y)-min(y)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dx : OclAny := Sequence{-1, 0, 1, 0} ; var dy : OclAny := Sequence{0, 1, 0, -1} ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var x : Sequence := () ; var y : Sequence := () ; execute ((0) : x) ; execute ((0) : y) ; for i : Integer.subrange(0, n - 1-1) do ( var k : OclAny := null; var d : OclAny := null; Sequence{k,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((x[k+1] + dx[d+1]) : x) ; execute ((y[k+1] + dy[d+1]) : y)) ; execute ((x)->max() - (x)->min() + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(N,nd): dire=[(0,-1),(-1,0),(0,1),(1,0)] table=[[0]*(2*N+1)for i in range(2*N+1)] table[N][N]=1 position=[None]*N position[0]=(N,N) for i,ndi in enumerate(nd,start=1): n,d=ndi y,x=position[n] ny,nx=y+dire[d][0],x+dire[d][1] table[ny][nx]=1 position[i]=(ny,nx) left,right,top,bottom=2*N,0,2*N,0 for i in range(2*N): for j in range(2*N): if(table[i][j]): left=min(left,j) right=max(right,j) top=min(top,i) bottom=max(bottom,i) return(right-left+1,bottom-top+1) def main(): ans=[] while True : N=int(input()) if(not N): break nd=[list(map(int,input().split()))for i in range(N-1)] ans.append(solve(N,nd)) for i in ans : print(*i) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation solve(N : OclAny, nd : OclAny) : OclAny pre: true post: true activity: var dire : Sequence := Sequence{Sequence{0, -1}}->union(Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{ Sequence{1, 0} }))) ; var table : Sequence := Integer.subrange(0, 2 * N + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * N + 1)))) ; table[N+1][N+1] := 1 ; var position : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, N) ; position->first() := Sequence{N, N} ; for _tuple : Integer.subrange(1, (nd, (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->size())->collect( _indx | Sequence{_indx-1, (nd, (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var ndi : OclAny := _tuple->at(_indx); var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := ndi ; var y : OclAny := null; var x : OclAny := null; Sequence{y,x} := position[n+1] ; var ny : OclAny := null; var nx : OclAny := null; Sequence{ny,nx} := Sequence{y + dire[d+1]->first(),x + dire[d+1][1+1]} ; table[ny+1][nx+1] := 1 ; position[i+1] := Sequence{ny, nx}) ; var left : OclAny := null; var right : OclAny := null; var top : OclAny := null; var bottom : OclAny := null; Sequence{left,right,top,bottom} := Sequence{2 * N,0,2 * N,0} ; for i : Integer.subrange(0, 2 * N-1) do ( for j : Integer.subrange(0, 2 * N-1) do ( if (table[i+1][j+1]) then ( var left : OclAny := Set{left, j}->min() ; var right : OclAny := Set{right, j}->max() ; var top : OclAny := Set{top, i}->min() ; var bottom : OclAny := Set{bottom, i}->max() ) else skip)) ; return Sequence{right - left + 1, bottom - top + 1}; operation main() pre: true post: true activity: var ans : Sequence := Sequence{} ; while true do ( N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (not(N)) then ( break ) else skip ; nd := Integer.subrange(0, N - 1-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; execute ((solve(N, nd)) : ans)) ; for i : ans do ( execute ((argument * (test (logical_test (comparison (expr (atom (name i))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : N=int(input()) if N==0 : break max_h=0 min_h=0 max_w=0 min_w=0 data=[(0,0)] for _ in range(N-1): n,d=list(map(int,input().split())) if d==0 : current=(data[n][0]-1,data[n][1]) if d==1 : current=(data[n][0],data[n][1]-1) if d==2 : current=(data[n][0]+1,data[n][1]) if d==3 : current=(data[n][0],data[n][1]+1) if max_hcurrent[1]: min_h=current[1] if max_wcurrent[0]: min_w=current[0] data.append(current) print(abs(max_w-min_w)+1,abs(max_h-min_h)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var max_h : int := 0 ; var min_h : int := 0 ; var max_w : int := 0 ; var min_w : int := 0 ; var data : Sequence := Sequence{ Sequence{0, 0} } ; for _anon : Integer.subrange(0, N - 1-1) do ( var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if d = 0 then ( var current : OclAny := Sequence{data[n+1]->first() - 1, data[n+1][1+1]} ) else skip ; if d = 1 then ( current := Sequence{data[n+1]->first(), data[n+1][1+1] - 1} ) else skip ; if d = 2 then ( current := Sequence{data[n+1]->first() + 1, data[n+1][1+1]} ) else skip ; if d = 3 then ( current := Sequence{data[n+1]->first(), data[n+1][1+1] + 1} ) else skip ; if (max_h->compareTo(current[1+1])) < 0 then ( max_h := current[1+1] ) else skip ; if (min_h->compareTo(current[1+1])) > 0 then ( min_h := current[1+1] ) else skip ; if (max_w->compareTo(current->first())) < 0 then ( max_w := current->first() ) else skip ; if (min_w->compareTo(current->first())) > 0 then ( min_w := current->first() ) else skip ; execute ((current) : data)) ; execute ((max_w - min_w)->abs() + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: x,y,*a,z=map(int,s.split()); print(*([1,2,len(a)+3],[-1])[x+y>z]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var x : OclAny := null; var y : OclAny := null; var a : OclAny := null; var z : OclAny := null; Sequence{x,y,a,z} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ); execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1))))))) , (test (logical_test (comparison (expr (atom (number (integer 2))))))) , (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))) + (expr (atom (number (integer 3))))))))) ]))))) , (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom - (number (integer 1)))))))) ])))))) )) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (comparison (expr (expr (atom (name x))) + (expr (atom (name y))))) > (comparison (expr (atom (name z))))))))) ]))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(): dx=(-1,0,1,0,) dy=(0,-1,0,1,) while 1 : N=int(sys.stdin.readline().rstrip()) if N==0 : return pos=[None]*N pos[0]=(0,0) top=0 btm=0 left=0 right=0 for i in range(N-1): ni,di=map(int,sys.stdin.readline().split()) x,y=pos[ni] x+=dx[di] y+=dy[di] pos[i+1]=(x,y) top=max(top,y) btm=min(btm,y) left=min(left,x) right=max(right,x) print(right-left+1,top-btm+1) if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var dx : OclAny := Sequence{-1, 0, 1, (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) ,)} ; var dy : OclAny := Sequence{0, -1, 0, (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1))))))) ,)} ; while 1 do ( var N : int := ("" + ((sys.stdin.readLine().rstrip())))->toInteger() ; if N = 0 then ( return ) else skip ; var pos : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, N) ; pos->first() := Sequence{0, 0} ; var top : int := 0 ; var btm : int := 0 ; var left : int := 0 ; var right : int := 0 ; for i : Integer.subrange(0, N - 1-1) do ( var ni : OclAny := null; var di : OclAny := null; Sequence{ni,di} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := pos[ni+1] ; x := x + dx[di+1] ; y := y + dy[di+1] ; pos[i + 1+1] := Sequence{x, y} ; top := Set{top, y}->max() ; btm := Set{btm, y}->min() ; left := Set{left, x}->min() ; right := Set{right, x}->max()) ; execute (right - left + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- move=[[-1,0],[0,1],[1,0],[0,-1]] def main(n): field=[(0,0)] for _ in range(n-1): ni,di=map(int,input().split()) field.append((field[ni][0]+move[di][0],field[ni][1]+move[di][1])) minx=field[0][0] maxx=field[0][0] miny=field[0][1] maxy=field[0][1] for fx,fy in field : minx=min(minx,fx) maxx=max(maxx,fx) miny=min(miny,fy) maxy=max(maxy,fy) print(maxx-minx+1,maxy-miny+1) while 1 : n=int(input()) if n==0 : break main(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var move : Sequence := Sequence{Sequence{-1}->union(Sequence{ 0 })}->union(Sequence{Sequence{0}->union(Sequence{ 1 })}->union(Sequence{Sequence{1}->union(Sequence{ 0 })}->union(Sequence{ Sequence{0}->union(Sequence{ -1 }) }))) ; skip ; while 1 do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; main(n)); operation main(n : OclAny) pre: true post: true activity: var field : Sequence := Sequence{ Sequence{0, 0} } ; for _anon : Integer.subrange(0, n - 1-1) do ( var ni : OclAny := null; var di : OclAny := null; Sequence{ni,di} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{field[ni+1]->first() + move[di+1]->first(), field[ni+1][1+1] + move[di+1][1+1]}) : field)) ; var minx : OclAny := field->first()->first() ; var maxx : OclAny := field->first()->first() ; var miny : OclAny := field->first()[1+1] ; var maxy : OclAny := field->first()[1+1] ; for _tuple : field do (var _indx : int := 1; var fx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var fy : OclAny := _tuple->at(_indx); minx := Set{minx, fx}->min() ; maxx := Set{maxx, fx}->max() ; miny := Set{miny, fy}->min() ; maxy := Set{maxy, fy}->max()) ; execute (maxx - minx + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for x in range(t): n=int(input()) a=list(map(int,input().split())) if n>1 : g=max(a) a.pop(a.index(max(a))) if g-max(a)>1 : print('NO') else : print('YES') else : if a[0]==1 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for x : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n > 1 then ( var g : OclAny := (a)->max() ; a := a->excludingAt(a->indexOf((a)->max()) - 1+1) ; if g - (a)->max() > 1 then ( execute ('NO')->display() ) else ( execute ('YES')->display() ) ) else ( if a->first() = 1 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for x in range(n): t=int(input()) a=list(map(int,input().split())) a.sort(reverse=1) if len(a)==1 and a[0]>1 : print('NO') elif len(a)==1 and a[0]<=1 : print('YES') elif a[0]-a[1]>=2 : print('NO') else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for x : Integer.subrange(0, n-1) do ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; if (a)->size() = 1 & a->first() > 1 then ( execute ('NO')->display() ) else (if (a)->size() = 1 & a->first() <= 1 then ( execute ('YES')->display() ) else (if a->first() - a[1+1] >= 2 then ( execute ('NO')->display() ) else ( execute ('YES')->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): s=int(input()) s1=[int(i)for i in input().split()] s1.append(0) s1.sort() print('YNEOS'[(s1[-1]-s1[-2])>1 : : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s1 : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute ((0) : s1) ; s1 := s1->sort() ; execute ('YNEOS'(subscript (test (logical_test (comparison (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name s1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))) - (expr (atom (name s1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 2))))))))) ])))))))) )))) > (comparison (expr (atom (number (integer 1)))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) lis=list(map(int,input().split())) if n==1 : if lis[0]>1 : print("no") else : print('YES') continue lis.sort() a,b=lis[-1],lis[-2] if a==b or a==b+1 : print('yes') else : print('no') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lis : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = 1 then ( if lis->first() > 1 then ( execute ("no")->display() ) else ( execute ('YES')->display() ) ; continue ) else skip ; lis := lis->sort() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{lis->last(),lis->front()->last()} ; if a = b or a = b + 1 then ( execute ('yes')->display() ) else ( execute ('no')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def divisibleBy20(num): lastTwoDigits=int(num[-2 :]) return((lastTwoDigits % 5==0 and lastTwoDigits % 4==0)) num="63284689320" if(divisibleBy20(num)==True): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; num := "63284689320" ; if (divisibleBy20(num) = true) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation divisibleBy20(num : OclAny) : OclAny pre: true post: true activity: var lastTwoDigits : int := ("" + ((num.subrange(-2+1))))->toInteger() ; return ((lastTwoDigits mod 5 = 0 & lastTwoDigits mod 4 = 0)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) lis=list(map(int,input().split())) if n==1 : if lis[0]>1 : print("no") else : print('YES') continue lis.sort() a,b=lis[-1],lis[-2] if a-b<=1 : print('yes') else : print('no') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lis : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = 1 then ( if lis->first() > 1 then ( execute ("no")->display() ) else ( execute ('YES')->display() ) ; continue ) else skip ; lis := lis->sort() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{lis->last(),lis->front()->last()} ; if a - b <= 1 then ( execute ('yes')->display() ) else ( execute ('no')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def sortArrayByParityII(self,A): odd=1 for i in xrange(0,len(A),2): if A[i]% 2 : while A[odd]% 2 : odd+=2 A[i],A[odd]=A[odd],A[i] return A ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation sortArrayByParityII(A : OclAny) : OclAny pre: true post: true activity: var odd : int := 1 ; for i : xrange(0, (A)->size(), 2) do ( if A[i+1] mod 2 then ( while A[odd+1] mod 2 do ( odd := odd + 2) ; var A[i+1] : OclAny := null; var A[odd+1] : OclAny := null; Sequence{A[i+1],A[odd+1]} := Sequence{A[odd+1],A[i+1]} ) else skip) ; return A; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : (a,b)=map(int,input().split()) if a==0 and b==0 : break if a>b : a,b=b,a print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( ; var Sequence{a, b} : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 0 & b = 0 then ( break ) else skip ; if (a->compareTo(b)) > 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a} ) else skip ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def convert12(str): h1=ord(str[0])-ord('0'); h2=ord(str[1])-ord('0'); hh=h1*10+h2 ; Meridien="" ; if(hh<12): Meridien="AM" ; else : Meridien="PM" ; hh %=12 ; if(hh==0): print("12",end=""); for i in range(2,8): print(str[i],end=""); else : print(hh,end=""); for i in range(2,8): print(str[i],end=""); print(" "+Meridien); if __name__=='__main__' : str="17:35:20" ; convert12(str); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( OclType["String"] := "17:35:20"; ; convert12(OclType["String"]); ) else skip; operation convert12(OclType["String"] : OclAny) pre: true post: true activity: var h1 : double := (("" + (->first())))->char2byte() - ('0')->char2byte(); ; var h2 : double := (("" + ([1+1])))->char2byte() - ('0')->char2byte(); ; var hh : double := h1 * 10 + h2; ; var Meridien : String := ""; ; if (hh < 12) then ( Meridien := "AM"; ) else ( Meridien := "PM"; ) ; hh := hh mod 12; ; if (hh = 0) then ( execute ("12")->display(); ; for i : Integer.subrange(2, 8-1) do ( execute (("" + ([i+1])))->display();) ) else ( execute (hh)->display(); ; for i : Integer.subrange(2, 8-1) do ( execute (("" + ([i+1])))->display();) ) ; execute (" " + Meridien)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : x,y=sorted(map(int,input().split(" "))) if x==0 and y==0 : break print(x,y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )->sort() ; if x = 0 & y = 0 then ( break ) else skip ; execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : str_line=input().strip().split(" ") if str_line==["0","0"]: break else : int_line=list(map(int,str_line)) int_line.sort() str_line=list(map(str,int_line)) print(" ".join(str_line)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var str_line : OclAny := input()->trim().split(" ") ; if str_line = Sequence{"0"}->union(Sequence{ "0" }) then ( break ) else ( var int_line : Sequence := ((str_line)->collect( _x | (OclType["int"])->apply(_x) )) ; int_line := int_line->sort() ; str_line := ((int_line)->collect( _x | (OclType["String"])->apply(_x) )) ; execute (StringLib.sumStringsWithSeparator((str_line), " "))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : tmp=list(map(int,input().split())) if tmp[0]==0 and tmp[1]==0 : break tmp.sort() print(' '.join(map(str,tmp))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var tmp : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if tmp->first() = 0 & tmp[1+1] = 0 then ( break ) else skip ; tmp := tmp->sort() ; execute (StringLib.sumStringsWithSeparator(((tmp)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : x,y=map(int,input().split(' ')) if x==0 and y==0 : break if xcollect( _x | (OclType["int"])->apply(_x) ) ; if x = 0 & y = 0 then ( break ) else skip ; if (x->compareTo(y)) < 0 then ( execute (x)->display() ) else ( execute (y)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def is_solved(nums): keys=set(nums) for key in keys : if nums.count(key)>=2 : tmp=nums[:] tmp.remove(key) tmp.remove(key) for key in keys : key_count=tmp.count(key) if key_count==4 : if key+1 in tmp and key+2 in tmp : for _ in range(4): tmp.remove(key) tmp.remove(key+1) tmp.remove(key+2) elif key_count==3 : for _ in range(3): tmp.remove(key) elif tmp.count(key+1)>=key_count and tmp.count(key+2)>=key_count : for _ in range(key_count): tmp.remove(key) tmp.remove(key+1) tmp.remove(key+2) if tmp==[]: return True return False while True : try : puzzle=list(map(int,list(input()))) ans=[] for i in range(1,10): if puzzle.count(i)<=3 and is_solved(puzzle+[i]): ans.append(i) if ans : print(*ans) else : print(0) except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( try ( var puzzle : Sequence := ((((OclFile["System.in"]).readLine())->characters())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(1, 10-1) do ( if puzzle->count(i) <= 3 & is_solved(puzzle->union(Sequence{ i })) then ( execute ((i) : ans) ) else skip) ; if ans then ( execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ) else ( execute (0)->display() )) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); operation is_solved(nums : OclAny) : OclAny pre: true post: true activity: var keys : Set := Set{}->union((nums)) ; for key : keys do ( if nums->count(key) >= 2 then ( var tmp : Sequence := nums ; execute ((key) /: tmp) ; execute ((key) /: tmp) ; for key : keys do ( var key_count : int := tmp->count(key) ; if key_count = 4 then ( if (tmp)->includes(key + 1) & (tmp)->includes(key + 2) then ( for _anon : Integer.subrange(0, 4-1) do ( execute ((key) /: tmp)) ; execute ((key + 1) /: tmp) ; execute ((key + 2) /: tmp) ) else skip ) else (if key_count = 3 then ( for _anon : Integer.subrange(0, 3-1) do ( execute ((key) /: tmp)) ) else (if (tmp->count(key + 1)->compareTo(key_count)) >= 0 & (tmp->count(key + 2)->compareTo(key_count)) >= 0 then ( for _anon : Integer.subrange(0, key_count-1) do ( execute ((key) /: tmp) ; execute ((key + 1) /: tmp) ; execute ((key + 2) /: tmp)) ) else skip ) ) ) ; if tmp = Sequence{} then ( return true ) else skip ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def p(c,l,b): for i in l : c[i]+=[-1,1][b] def f(c): if sum(c)in c : return 1 if 5 in c : return 0 if 4 in c : k=c.index(4); c[k]-=3 if f(c): return 1 c[k]+=3 if 3 in c : k=c.index(3); c[k]-=3 if f(c): return 1 c[k]+=3 for i in range(7): if c[i]and c[i+1]and c[i+2]: p(c,[i,i+1,i+2],0) if f(c): return 1 p(c,[i,i+1,i+2],1) n='123456789' for e in sys.stdin : e=list(e) a=[i for i in n if f([(e+[i]).count(j)for j in n])] if a : print(*a) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var n : String := '123456789' ; for e : OclFile["System.in"] do ( var e : Sequence := (e) ; var a : Sequence := n->characters()->select(i | f(n->characters()->select(j | true)->collect(j | ((e->union(Sequence{ i }))->count(j)))))->collect(i | (i)) ; if a then ( execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display() ) else ( execute (0)->display() )); operation p(c : OclAny, l : OclAny, b : OclAny) pre: true post: true activity: for i : l do ( c[i+1] := c[i+1] + Sequence{-1}->union(Sequence{ 1 })[b+1]); operation f(c : OclAny) : OclAny pre: true post: true activity: if (c)->includes((c)->sum()) then ( return 1 ) else skip ; if (c)->includes(5) then ( return 0 ) else skip ; if (c)->includes(4) then ( var k : int := c->indexOf(4) - 1; c[k+1] := c[k+1] - 3 ; if f(c) then ( return 1 ) else skip ; c[k+1] := c[k+1] + 3 ) else skip ; if (c)->includes(3) then ( k := c->indexOf(3) - 1; c[k+1] := c[k+1] - 3 ; if f(c) then ( return 1 ) else skip ; c[k+1] := c[k+1] + 3 ) else skip ; for i : Integer.subrange(0, 7-1) do ( if c[i+1] & c[i + 1+1] & c[i + 2+1] then ( p(c, Sequence{i}->union(Sequence{i + 1}->union(Sequence{ i + 2 })), 0) ; if f(c) then ( return 1 ) else skip ; p(c, Sequence{i}->union(Sequence{i + 1}->union(Sequence{ i + 2 })), 1) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def dfs(hand,count): if count<1 : return True for i,n in enumerate(hand[1 :],start=1): if n==0 : continue if n>=3 : c_hand=hand[:] c_hand[i]-=3 res=dfs(c_hand[:],count-1) if res : return True if i>7 : return False if hand[i+1]>=1 and hand[i+2]>=1 : c_hand=hand[:] c_hand[i]-=1 c_hand[i+1]-=1 c_hand[i+2]-=1 res=dfs(c_hand[:],count-1) if res : return True else : return False def solve(data): ans=[] for tsumo in range(1,10): my_hand=data[:] my_hand.append(tsumo) remaining=[0]*10 for n in my_hand : remaining[n]+=1 if max(remaining)>4 : continue for i,atama in enumerate(remaining[1 :],start=1): if atama>=2 : c_remaining=remaining[:] c_remaining[i]-=2 res=dfs(c_remaining[:],4) if res : ans.append(tsumo) break return ans def main(args): for line in sys.stdin : data=list(map(int,list(line.strip()))) result=solve(data) if len(result)>0 : print(*result) else : print(0) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation dfs(hand : OclAny, count : OclAny) : OclAny pre: true post: true activity: if count < 1 then ( return true ) else skip ; for _tuple : Integer.subrange(1, (hand->tail(), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->size())->collect( _indx | Sequence{_indx-1, (hand->tail(), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var n : OclAny := _tuple->at(_indx); if n = 0 then ( continue ) else skip ; if n >= 3 then ( var c_hand : Sequence := hand ; c_hand[i+1] := c_hand[i+1] - 3 ; var res : OclAny := dfs(c_hand, count - 1) ; if res then ( return true ) else skip ) else skip ; if i > 7 then ( return false ) else skip ; if hand[i + 1+1] >= 1 & hand[i + 2+1] >= 1 then ( c_hand := hand ; c_hand[i+1] := c_hand[i+1] - 1 ; c_hand[i + 1+1] := c_hand[i + 1+1] - 1 ; c_hand[i + 2+1] := c_hand[i + 2+1] - 1 ; res := dfs(c_hand, count - 1) ; if res then ( return true ) else skip ) else ( return false )); operation solve(data : OclAny) : OclAny pre: true post: true activity: var ans : Sequence := Sequence{} ; for tsumo : Integer.subrange(1, 10-1) do ( var my_hand : Sequence := data ; execute ((tsumo) : my_hand) ; var remaining : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; for n : my_hand do ( remaining[n+1] := remaining[n+1] + 1) ; if (remaining)->max() > 4 then ( continue ) else skip ; for _tuple : Integer.subrange(1, (remaining->tail(), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->size())->collect( _indx | Sequence{_indx-1, (remaining->tail(), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var atama : OclAny := _tuple->at(_indx); if atama >= 2 then ( var c_remaining : Sequence := remaining ; c_remaining[i+1] := c_remaining[i+1] - 2 ; res := dfs(c_remaining, 4) ; if res then ( execute ((tsumo) : ans) ; break ) else skip ) else skip)) ; return ans; operation main(args : OclAny) pre: true post: true activity: for line : OclFile["System.in"] do ( data := (((line->trim())->characters())->collect( _x | (OclType["int"])->apply(_x) )) ; var result : OclAny := solve(data) ; if (result)->size() > 0 then ( execute ((argument * (test (logical_test (comparison (expr (atom (name result))))))))->display() ) else ( execute (0)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t,s=map(int,raw_input().split()) ab=[map(int,raw_input().split())for _ in xrange(n)] dp=[[0]*(t+1)for _ in xrange(n+1)] for i in xrange(n): for j in xrange(1,t+1): if jcollect( _x | (OclType["int"])->apply(_x) ) ; var ab : Sequence := xrange(n)->select(_anon | true)->collect(_anon | ((raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var dp : Sequence := xrange(n + 1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (t + 1)))) ; for i : xrange(n) do ( for j : xrange(1, t + 1) do ( if (j->compareTo(ab[i+1][1+1])) < 0 or (j - ab[i+1][1+1]->compareTo(s)) < 0 & (s < j) then ( dp[i + 1+1][j+1] := dp[i+1][j+1] ; continue ) else skip ; dp[i + 1+1][j+1] := Set{dp[i+1][j+1], dp[i+1][j - ab[i+1][1+1]+1] + ab[i+1]->first()}->max())) ; execute ((dp[n+1])->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Solve(c,s): if s : if max(c)>4 : return False for i in range(9): if c[i]>=2 : cc=c[:] cc[i]-=2 if Solve(cc,False): return True else : check=0 for i in range(4): check+=c.count(3*i) if check==9 : return True else : for i in range(7): if c[i]>=1 : cc=c[:] isneg=False for j in range(3): cc[i+j]-=1 if cc[i+j]<0 : isneg=True break if isneg==False and Solve(cc,False): return True _in="" while True : ans=[] try : _in=input() except EOFError : break for i in range(9): l=(_in+str(i+1))[: : 1] count=[l.count(str(j+1))for j in range(9)] if Solve(count,True): ans.append(str(i+1)) print(0 if len(ans)==0 else " ".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var _in : String := "" ; while true do ( var ans : Sequence := Sequence{} ; try ( _in := (OclFile["System.in"]).readLine()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (simple_stmt (small_stmt break)))) ; for i : Integer.subrange(0, 9-1) do ( var l : OclAny := (_in + ("" + ((i + 1))))(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ; var count : Sequence := Integer.subrange(0, 9-1)->select(j | true)->collect(j | (l->count(("" + ((j + 1)))))) ; if Solve(count, true) then ( execute ((("" + ((i + 1)))) : ans) ) else skip) ; execute (if (ans)->size() = 0 then 0 else StringLib.sumStringsWithSeparator((ans), " ") endif)->display()); operation Solve(c : OclAny, s : OclAny) : OclAny pre: true post: true activity: if s then ( if (c)->max() > 4 then ( return false ) else skip ; for i : Integer.subrange(0, 9-1) do ( if c[i+1] >= 2 then ( var cc : Sequence := c ; cc[i+1] := cc[i+1] - 2 ; if Solve(cc, false) then ( return true ) else skip ) else skip) ) else ( var check : int := 0 ; for i : Integer.subrange(0, 4-1) do ( check := check + c->count(3 * i)) ; if check = 9 then ( return true ) else ( for i : Integer.subrange(0, 7-1) do ( if c[i+1] >= 1 then ( cc := c ; var isneg : boolean := false ; for j : Integer.subrange(0, 3-1) do ( cc[i + j+1] := cc[i + j+1] - 1 ; if cc[i + j+1] < 0 then ( isneg := true ; break ) else skip) ; if isneg = false & Solve(cc, false) then ( return true ) else skip ) else skip) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import(division,absolute_import,print_function,unicode_literals) from sys import stdin def solve(L): m=min(L) cnt=L.count(m) if cnt>4 : return False for _ in xrange(cnt): L.remove(m) if cnt in(1,4): if not L.count(m+1)or not L.count(m+2): return False L.remove(m+1) L.remove(m+2) elif cnt==2 : if L.count(m+1)<2 or L.count(m+2)<2 : return False L.remove(m+1) L.remove(m+1) L.remove(m+2) L.remove(m+2) return True if not len(L)else solve(L) for line in stdin : data=[int(s)for s in line.strip()] data.append(0) answers=[] for i in xrange(1,10): data[-1]=i if data.count(i)>4 : continue for pair in xrange(1,10): if data.count(pair)<2 : continue L=data[:] L.remove(pair) L.remove(pair) if solve(L): answers.append(str(i)) break print(' '.join(answers)if answers else '0') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; for line : stdin do ( var data : Sequence := line->trim()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; execute ((0) : data) ; var answers : Sequence := Sequence{} ; for i : xrange(1, 10) do ( data->last() := i ; if data->count(i) > 4 then ( continue ) else skip ; for pair : xrange(1, 10) do ( if data->count(pair) < 2 then ( continue ) else skip ; L := data ; execute ((pair) /: L) ; execute ((pair) /: L) ; if solve(L) then ( execute ((("" + ((i)))) : answers) ; break ) else skip)) ; execute (if answers then StringLib.sumStringsWithSeparator((answers), ' ') else '0' endif)->display()); operation solve(L : OclAny) : OclAny pre: true post: true activity: var m : OclAny := (L)->min() ; var cnt : int := L->count(m) ; if cnt > 4 then ( return false ) else skip ; for _anon : xrange(cnt) do ( execute ((m) /: L)) ; if (Sequence{1, 4})->includes(cnt) then ( if not(L->count(m + 1)) or not(L->count(m + 2)) then ( return false ) else skip ; execute ((m + 1) /: L) ; execute ((m + 2) /: L) ) else (if cnt = 2 then ( if L->count(m + 1) < 2 or L->count(m + 2) < 2 then ( return false ) else skip ; execute ((m + 1) /: L) ; execute ((m + 1) /: L) ; execute ((m + 2) /: L) ; execute ((m + 2) /: L) ) else skip) ; return if not((L)->size()) then true else solve(L) endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(s,k): for i in range(0,len(s)): if(s[i]!=s[i % k]): return False return True def countCommonDivisors(a,b): ct=0 n=len(a) m=len(b) for i in range(1,min(n,m)+1): if(n % i==0 and m % i==0): if(a[0 : i]==b[0 : i]): if(check(a,i)and check(b,i)): ct=ct+1 return ct a="xaxa" b="xaxaxaxa" print(countCommonDivisors(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := "xaxa" ; b := "xaxaxaxa" ; execute (countCommonDivisors(a, b))->display(); operation check(s : OclAny, k : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, (s)->size()-1) do ( if (s[i+1] /= s[i mod k+1]) then ( return false ) else skip) ; return true; operation countCommonDivisors(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var ct : int := 0 ; var n : int := (a)->size() ; var m : int := (b)->size() ; for i : Integer.subrange(1, Set{n, m}->min() + 1-1) do ( if (n mod i = 0 & m mod i = 0) then ( if (a.subrange(0+1, i) = b.subrange(0+1, i)) then ( if (check(a, i) & check(b, i)) then ( ct := ct + 1 ) else skip ) else skip ) else skip) ; return ct; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=int(input()) ch=input() a=ch.count("UR") if(a>1): ch=ch.replace("UR","") else : ch=ch.replace("UR","") b=ch.count("RU") print(l-a-b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ch : String := (OclFile["System.in"]).readLine() ; var a : int := ch->count("UR") ; if (a > 1) then ( ch := ch.replace("UR", "") ) else ( ch := ch.replace("UR", "") ) ; var b : int := ch->count("RU") ; execute (l - a - b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) o=input() x=0 y=0 while ytoInteger() ; var o : String := (OclFile["System.in"]).readLine() ; var x : int := 0 ; var y : int := 0 ; while (y->compareTo(n - 1)) < 0 do ( if o[y+1] /= o[y + 1+1] then ( x := x + 1 ; y := y + 1 ) else skip ; y := y + 1) ; execute (n - x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() g=n list1=[0 for i in range(n)] for i in range(n-1): if((s[i]=='U' and s[i+1]=='R')or(s[i]=='R' and s[i+1]=='U'))and list1[i]==0 : list1[i+1]=1 g-=1 print(g) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var g : int := n ; var list1 : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n - 1-1) do ( if ((s[i+1] = 'U' & s[i + 1+1] = 'R') or (s[i+1] = 'R' & s[i + 1+1] = 'U')) & list1[i+1] = 0 then ( list1[i + 1+1] := 1 ; g := g - 1 ) else skip) ; execute (g)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import os import random import re import sys from math import gcd from math import sqrt from collections import Counter n=int(input()) s=input() ans=0 i=0 while(i<=n-2): if s[i]!=s[i+1]: ans+=1 i+=2 else : i+=1 print(n-ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; var i : int := 0 ; while ((i->compareTo(n - 2)) <= 0) do ( if s[i+1] /= s[i + 1+1] then ( ans := ans + 1 ; i := i + 2 ) else ( i := i + 1 )) ; execute (n - ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=int(input()) ch=input() a=ch.count("UR") ch=ch.replace("UR","") b=ch.count("RU") print(l-a-b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ch : String := (OclFile["System.in"]).readLine() ; var a : int := ch->count("UR") ; ch := ch.replace("UR", "") ; var b : int := ch->count("RU") ; execute (l - a - b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=100005 phi=[0]*N S=[0]*N def computeTotient(): for i in range(1,N): phi[i]=i for p in range(2,N): if(phi[p]==p): phi[p]=p-1 for i in range(2*p,N,p): phi[i]=(phi[i]//p)*(p-1) def CoPrimes(): computeTotient() for i in range(1,N): S[i]=S[i-1]+phi[i] if __name__=="__main__" : CoPrimes() q=[3,4] n=len(q) for i in range(n): print("Number of unordered coprime\n"+"pairs of integers from 1 to ",q[i]," are ",S[q[i]]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 100005 ; var phi : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var S : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; skip ; skip ; if __name__ = "__main__" then ( CoPrimes() ; var q : Sequence := Sequence{3}->union(Sequence{ 4 }) ; var n : int := (q)->size() ; for i : Integer.subrange(0, n-1) do ( execute ("Number of unordered coprime\n" + "pairs of integers from 1 to ")->display()) ) else skip; operation computeTotient() pre: true post: true activity: for i : Integer.subrange(1, N-1) do ( phi[i+1] := i) ; for p : Integer.subrange(2, N-1) do ( if (phi[p+1] = p) then ( phi[p+1] := p - 1 ; for i : Integer.subrange(2 * p, N-1)->select( $x | ($x - 2 * p) mod p = 0 ) do ( phi[i+1] := (phi[i+1] div p) * (p - 1)) ) else skip); operation CoPrimes() pre: true post: true activity: computeTotient() ; for i : Integer.subrange(1, N-1) do ( S[i+1] := S[i - 1+1] + phi[i+1]); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- o={} for _ in range(int(input())): p,m=input().split(); o[p]=o.get(p,0)+int(m) k=sorted([(len(x),x)for x in list(o.keys())]) for _,i in k : print(i,o[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var o : OclAny := Set{} ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var p : OclAny := null; var m : OclAny := null; Sequence{p,m} := input().split(); o[p+1] := o.get(p, 0) + ("" + ((m)))->toInteger()) ; var k : Sequence := (o.keys())->select(x | true)->collect(x | (Sequence{(x)->size(), x}))->sort() ; for _tuple : k do (var _indx : int := 1; var _anon : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : num_of_orders=int(input()) data=[] for d in range(num_of_orders): data.append(tuple(input().split(' '))) orders=dict() for p_name,p_count in data : if p_name in orders : orders[p_name]+=int(p_count) else : orders[p_name]=int(p_count) results=[] for k,v in orders.items(): results.append(tuple([k,v])) results.sort(key=lambda x :(len(x[0]),x[0])) for r in results : print('{0}{1}'.format(r[0],r[1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var num_of_orders : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var data : Sequence := Sequence{} ; for d : Integer.subrange(0, num_of_orders-1) do ( execute (((input().split(' '))) : data)) ; var orders : Map := (arguments ( )) ; for _tuple : data do (var _indx : int := 1; var p_name : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p_count : OclAny := _tuple->at(_indx); if (orders)->includes(p_name) then ( orders[p_name+1] := orders[p_name+1] + ("" + ((p_count)))->toInteger() ) else ( orders[p_name+1] := ("" + ((p_count)))->toInteger() )) ; var results : Sequence := Sequence{} ; for _tuple : orders->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); execute (((Sequence{k}->union(Sequence{ v }))) : results)) ; results := results->sort() ; for r : results do ( execute (StringLib.interpolateStrings('{0}{1}', Sequence{r->first(), r[1+1]}))->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): N,T,S=map(int,input().split()) a=[tuple(map(int,input().split()))for _ in[0]*N] dp={0 : 0} for fun,time in a : for _t,_f in dp.copy().items(): new_time=_t+time new_fun=fun+_f if _tdp[new_time]): dp[new_time]=new_fun print(max(dp.values())) if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( solve() ) else skip; operation solve() pre: true post: true activity: var N : OclAny := null; var T : OclAny := null; var S : OclAny := null; Sequence{N,T,S} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var dp : Map := Map{ 0 |-> 0 } ; for _tuple : a do (var _indx : int := 1; var fun : OclAny := _tuple->at(_indx); _indx := _indx + 1; var time : OclAny := _tuple->at(_indx); for _tuple : dp->copy()->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var _t : OclAny := _tuple->at(_indx); _indx := _indx + 1; var _f : OclAny := _tuple->at(_indx); var new_time : OclAny := _t + time ; var new_fun : OclAny := fun + _f ; if (_t->compareTo(S)) < 0 & (S < new_time) then ( new_time := S + time ) else skip ; if (new_time->compareTo(T)) <= 0 & ((dp)->excludes(new_time) or (new_fun->compareTo(dp[new_time+1])) > 0) then ( dp[new_time+1] := new_fun ) else skip)) ; execute ((dp.values())->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- data={} for _ in range(int(input())): p,n=input().split(); data[p]=data.get(p,0)+int(n) k=sorted([[len(a),a]for a in data.keys()]) for _,i in k : print(i,data[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var data : OclAny := Set{} ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var p : OclAny := null; var n : OclAny := null; Sequence{p,n} := input().split(); ; data[p+1] := data.get(p, 0) + ("" + ((n)))->toInteger()) ; var k : Sequence := data.keys()->select(a | true)->collect(a | (Sequence{(a)->size()}->union(Sequence{ a })))->sort() ; for _tuple : k do (var _indx : int := 1; var _anon : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printknapSack(W,wt,val,n): K=[[0 for w in range(W+1)]for i in range(n+1)] for i in range(n+1): for w in range(W+1): if i==0 or w==0 : K[i][w]=0 elif wt[i-1]<=w : K[i][w]=max(val[i-1]+K[i-1][w-wt[i-1]],K[i-1][w]) else : K[i][w]=K[i-1][w] res=K[n][W] print(res) w=W for i in range(n,0,-1): if res<=0 : break if res==K[i-1][w]: continue else : print(wt[i-1]) res=res-val[i-1] w=w-wt[i-1] val=[60,100,120] wt=[10,20,30] W=50 n=len(val) printknapSack(W,wt,val,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; val := Sequence{60}->union(Sequence{100}->union(Sequence{ 120 })) ; wt := Sequence{10}->union(Sequence{20}->union(Sequence{ 30 })) ; W := 50 ; n := (val)->size() ; printknapSack(W, wt, val, n); operation printknapSack(W : OclAny, wt : OclAny, val : OclAny, n : OclAny) pre: true post: true activity: var K : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, W + 1-1)->select(w | true)->collect(w | (0)))) ; for i : Integer.subrange(0, n + 1-1) do ( for w : Integer.subrange(0, W + 1-1) do ( if i = 0 or w = 0 then ( K[i+1][w+1] := 0 ) else (if (wt[i - 1+1]->compareTo(w)) <= 0 then ( K[i+1][w+1] := Set{val[i - 1+1] + K[i - 1+1][w - wt[i - 1+1]+1], K[i - 1+1][w+1]}->max() ) else ( K[i+1][w+1] := K[i - 1+1][w+1] ) ) )) ; var res : OclAny := K[n+1][W+1] ; execute (res)->display() ; var w : OclAny := W ; for i : Integer.subrange(0 + 1, n)->reverse() do ( if res <= 0 then ( break ) else skip ; if res = K[i - 1+1][w+1] then ( continue ) else ( execute (wt[i - 1+1])->display() ; res := res - val[i - 1+1] ; w := w - wt[i - 1+1] )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d={} for _ in[0]*int(input()): k,v=input().split() d[k]=d.get(k,0)+int(v) for k in sorted(d,key=lambda x :(sum(27**i*(ord(k)-64)for i,k in enumerate(x[: :-1])),x)): print(k,d[k]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : OclAny := Set{} ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var k : OclAny := null; var v : OclAny := null; Sequence{k,v} := input().split() ; d[k+1] := d.get(k, 0) + ("" + ((v)))->toInteger()) ; for k : d->sortedBy($x | (lambda x : OclAny in (Sequence{((argument (test (logical_test (comparison (expr (expr (expr (atom (number (integer 27)))) ** (expr (atom (name i)))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name ord)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name k)))))))) )))) - (expr (atom (number (integer 64))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name k)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ])))))))) )))))))))->sum(), x}))->apply($x)) do ( execute (k)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) namelist=[] numlist=[] lenlist=[] for _ in range(n): name,num=map(str,input().split()) if name in namelist : numlist[namelist.index(name)]+=int(num) else : namelist.append(name) numlist.append(int(num)) lenlist.append(len(name)) data=[] for name,num,l in zip(namelist,numlist,lenlist): data.append([name,num,l]) data=sorted(data,key=lambda x :(x[2],x[0])) for d in data : print(d[0],d[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var namelist : Sequence := Sequence{} ; var numlist : Sequence := Sequence{} ; var lenlist : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var name : OclAny := null; var num : OclAny := null; Sequence{name,num} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; if (namelist)->includes(name) then ( numlist[namelist->indexOf(name) - 1+1] := numlist[namelist->indexOf(name) - 1+1] + ("" + ((num)))->toInteger() ) else ( execute ((name) : namelist) ; execute ((("" + ((num)))->toInteger()) : numlist) ; execute (((name)->size()) : lenlist) )) ; var data : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, namelist->size())->collect( _indx | Sequence{namelist->at(_indx), numlist->at(_indx)} ) do (var _indx : int := 1; var name : OclAny := _tuple->at(_indx); _indx := _indx + 1; var num : OclAny := _tuple->at(_indx); _indx := _indx + 1; var l : OclAny := _tuple->at(_indx); execute ((Sequence{name}->union(Sequence{num}->union(Sequence{ l }))) : data)) ; data := data->sortedBy($x | (lambda x : OclAny in (Sequence{x[2+1], x->first()}))->apply($x)) ; for d : data do ( execute (d->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(i)for i in input().split()] a.sort() res=(a[2*n-1]-a[n])*(a[n-1]-a[0]) for i in range(1,n): x=(a[2*n-1]-a[0])*(a[i+n-1]-a[i]) if xtoInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; a := a->sort() ; var res : double := (a[2 * n - 1+1] - a[n+1]) * (a[n - 1+1] - a->first()) ; for i : Integer.subrange(1, n-1) do ( var x : double := (a[2 * n - 1+1] - a->first()) * (a[i + n - 1+1] - a[i+1]) ; if (x->compareTo(res)) < 0 then ( res := x ) else skip) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=sorted(map(int,input().split())) print(min([(a[n-1]-a[0])*(a[-1]-a[n])]+[(a[-1]-a[0])*(a[i+n-1]-a[i])for i in range(n)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; execute ((Sequence{ (a[n - 1+1] - a->first()) * (a->last() - a[n+1]) }->union(Integer.subrange(0, n-1)->select(i | true)->collect(i | ((a->last() - a->first()) * (a[i + n - 1+1] - a[i+1])))))->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) a.sort() res=(a[n-1]-a[0])*(a[2*n-1]-a[n]) x=max(a) y=min(a) for i in range(1,n+1): res=min(res,(x-y)*(a[i+n-1]-a[i])) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var res : double := (a[n - 1+1] - a->first()) * (a[2 * n - 1+1] - a[n+1]) ; var x : OclAny := (a)->max() ; var y : OclAny := (a)->min() ; for i : Integer.subrange(1, n + 1-1) do ( res := Set{res, (x - y) * (a[i + n - 1+1] - a[i+1])}->min()) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_points=int(input()) coords=[int(x)for x in input().split()] coords.sort() width=coords[num_points-1]-coords[0] height=coords[-1]-coords[num_points] area1=width*height width2=min(coords[i+num_points-1]-coords[i]for i in range(num_points+1)) height2=coords[-1]-coords[0] area2=width2*height2 area=min(area1,area2) print(area) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_points : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var coords : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; coords := coords->sort() ; var width : double := coords[num_points - 1+1] - coords->first() ; var height : double := coords->last() - coords[num_points+1] ; var area1 : double := width * height ; var width2 : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name coords)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name i))) + (expr (atom (name num_points)))) - (expr (atom (number (integer 1)))))))))) ]))) - (expr (atom (name coords)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name num_points))) + (expr (atom (number (integer 1)))))))))) )))))))))->min() ; var height2 : double := coords->last() - coords->first() ; var area2 : double := width2 * height2 ; var area : OclAny := Set{area1, area2}->min() ; execute (area)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def read_input(input_path=None): if input_path is None : f=sys.stdin else : f=open(input_path,'r') n=int(f.readline()) coordinates=list(map(int,f.readline().split())) return n,coordinates def sol(n,coordinates): a=sorted(coordinates) s=(a[len(a)//2-1]-a[0])*(a[-1]-a[len(a)//2]) s1=s delta_x=a[-1]-a[0] for i in range(1,n): s1=min(s1,delta_x*(a[i+len(a)//2-1]-a[i])) return[f"{s1}"] def solve(input_path=None): return sol(*read_input(input_path)) def main(): for line in sol(*read_input()): print(f"{line}") if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation read_input(input_path : OclAny) : OclAny pre: true post: true activity: if input_path->oclIsUndefined() then input_path := null else skip; if input_path <>= null then ( var f : OclFile := OclFile["System.in"] ) else ( f := OclFile.newOclFile_Write(OclFile.newOclFile(input_path)) ) ; var n : int := ("" + ((f.readLine())))->toInteger() ; var coordinates : Sequence := ((f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; return n, coordinates; operation sol(n : OclAny, coordinates : OclAny) : OclAny pre: true post: true activity: var a : Sequence := coordinates->sort() ; var s : double := (a[(a)->size() div 2 - 1+1] - a->first()) * (a->last() - a[(a)->size() div 2+1]) ; var s1 : OclAny := s ; var delta_x : double := a->last() - a->first() ; for i : Integer.subrange(1, n-1) do ( s1 := Set{s1, delta_x * (a[i + (a)->size() div 2 - 1+1] - a[i+1])}->min()) ; return Sequence{ StringLib.formattedString("{s1}") }; operation solve(input_path : OclAny) : OclAny pre: true post: true activity: if input_path->oclIsUndefined() then input_path := null else skip; return sol((argument * (test (logical_test (comparison (expr (atom (name read_input)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input_path)))))))) ))))))))); operation main() pre: true post: true activity: for line : sol((argument * (test (logical_test (comparison (expr (atom (name read_input)) (trailer (arguments ( ))))))))) do ( execute (StringLib.formattedString("{line}"))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from os import path from sys import stdin,stdout inp=lambda : int(input()) strng=lambda : input().strip() jn=lambda x,l : x.join(map(str,l)) strl=lambda : list(input().strip()) mul=lambda : map(int,input().strip().split()) mulf=lambda : map(float,input().strip().split()) seq=lambda : list(map(int,input().strip().split())) ceil=lambda x : int(x)if(x==int(x))else int(x)+1 ceildiv=lambda x,d : x//d if(x % d==0)else x//d+1 flush=lambda : stdout.flush() stdstr=lambda : stdin.readline() stdint=lambda : int(stdin.readline()) stdpr=lambda x : stdout.write(str(x)) if(path.exists('input.txt')): sys.stdin=open("input.txt","r") sys.stdout=open("output.txt","w") def solve(): n=inp() for i in range(12): if(n>=0 and n % 11==0): print("YES") break n-=111 else : print("NO") for _ in range(int(input())): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var strng : Function := lambda $$ : OclAny in (input()->trim()) ; var jn : Function := lambda x : OclAny, l : OclAny in (StringLib.sumStringsWithSeparator(((l)->collect( _x | (OclType["String"])->apply(_x) )), x)) ; var strl : Function := lambda $$ : OclAny in ((input()->trim())) ; var mul : Function := lambda $$ : OclAny in ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mulf : Function := lambda $$ : OclAny in ((input()->trim().split())->collect( _x | (OclType["double"])->apply(_x) )) ; var seq : Function := lambda $$ : OclAny in (((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ceil : Function := lambda x : OclAny in (if (x = ("" + ((x)))->toInteger()) then ("" + ((x)))->toInteger() else ("" + ((x)))->toInteger() + 1 endif) ; var ceildiv : Function := lambda x : OclAny, d : OclAny in (if (x mod d = 0) then x div d else x div d + 1 endif) ; var flush : Function := lambda $$ : OclAny in (stdout.flush()) ; var stdstr : Function := lambda $$ : OclAny in (stdin.readLine()) ; var stdint : Function := lambda $$ : OclAny in (("" + ((stdin.readLine())))->toInteger()) ; var stdpr : Function := lambda x : OclAny in (stdout.write(("" + ((x))))) ; if (path.exists('input.txt')) then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ) else skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve()); operation solve() pre: true post: true activity: var n : OclAny := inp->apply() ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 12))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom (name n)))) >= (comparison (expr (atom (number (integer 0))))))) and (logical_test (comparison (comparison (expr (expr (atom (name n))) % (expr (atom (number (integer 11)))))) == (comparison (expr (atom (number (integer 0)))))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name n)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 111))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- [(lambda n : print("YES" if(n>=111*(n % 11))else "NO"))(int(input()))for _ in range(int(input()))] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : t-=1 n,m,k=map(int,input().split()) edge=False if m==(n*(n-1)//2): edge=1 elif m==n-1 : edge=2 elif m>n-1 and m<(n*(n-1))//2 : edge=2 if not edge : print("NO") elif n==1 and k>1 : print("YES") elif edgetoInteger() ; while t > 0 do ( t := t - 1 ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var edge : boolean := false ; if m = (n * (n - 1) div 2) then ( edge := 1 ) else (if m = n - 1 then ( edge := 2 ) else (if (m->compareTo(n - 1)) > 0 & (m->compareTo((n * (n - 1)) div 2)) < 0 then ( edge := 2 ) else skip ) ) ; if not(edge) then ( execute ("NO")->display() ) else (if n = 1 & k > 1 then ( execute ("YES")->display() ) else (if (edge->compareTo(k - 1)) < 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) q=[] count=0 for i in range(n): a=input().split() q.append(a) for j in q : for k in q : if k==j : continue elif j[0]==k[len(k)-1]: count+=1 else : continue print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var q : Sequence := Sequence{} ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := input().split() ; execute ((a) : q)) ; for j : q do ( for k : q do ( if k = j then ( continue ) else (if j->first() = k[(k)->size() - 1+1] then ( count := count + 1 ) else ( continue ) ) )) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,t,s=map(int,input().split()) A=[] B=[] for _ in range(n): a,b=map(int,input().split()) A.append(a) B.append(b) dp=[[0]*(t+1)for _ in range(n+1)] for x in range(n): bx=B[x] ax=A[x] dpx=dp[x] dpx1=dp[x+1] for y in range(1,t+1): if 0<=y-bx and(not(y-bxcollect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := Sequence{} ; var B : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a) : A) ; execute ((b) : B)) ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (t + 1)))) ; for x : Integer.subrange(0, n-1) do ( var bx : OclAny := B[x+1] ; var ax : OclAny := A[x+1] ; var dpx : OclAny := dp[x+1] ; var dpx1 : OclAny := dp[x + 1+1] ; for y : Integer.subrange(1, t + 1-1) do ( if 0 <= y - bx & (not(((y - bx->compareTo(s)) < 0 & (s < y)))) then ( dpx1[y+1] := Set{dpx[y+1], dpx1[y - 1+1], dpx[y - bx+1] + ax}->max() ) else ( dpx1[y+1] := Set{dpx[y+1], dpx1[y - 1+1]}->max() ))) ; execute (dp[n+1][t+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) if n>=111*(n % 11): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n->compareTo(111 * (n mod 11))) >= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) if n>=((n % 11)*111): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n->compareTo(((n mod 11) * 111))) >= 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) if n>1099 : print("YES") else : if n>=111*(n % 11): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n > 1099 then ( execute ("YES")->display() ) else ( if (n->compareTo(111 * (n mod 11))) >= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from audioop import reverse from cmath import* from dataclasses import dataclass from decimal import* def solves(): n=list(input()) s=reversed(n) if(s==n): print(n) else : n=''.join(n) s=''.join(s) print(n+s) t=1 for _ in range(0,t): solves() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solves()); operation solves() pre: true post: true activity: var n : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var s : Sequence := (n)->reverse() ; if (s = n) then ( execute (n)->display() ) else ( n := StringLib.sumStringsWithSeparator((n), '') ; s := StringLib.sumStringsWithSeparator((s), '') ; execute (n->union(s))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() print(s+s[: :-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; execute (s + s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=input() print(l+l[: :-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : String := (OclFile["System.in"]).readLine() ; execute (l + l(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() print(s+s[: :-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; execute (s + s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() print(s,end='') print(s[: :-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; execute (s)->display() ; execute (s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) nlist=[] mlist=[] t=True for i in range(num): list1=list(map(int,input().split())) k=list1[0] n=0 while t==True : n=n+1 if(k % list1[n])==0 : o=0 mlist.append(o) elif(k-list1[n])>0 : i=1 r=k//list1[n] i=list1[n]*(r+1) h=k-i o=h o=int(o) o=abs(o) mlist.append(o) if(k-list1[n])<0 : o=k-list1[n] o=abs(o) mlist.append(o) if n==3 : break m=min(mlist) nlist.append(m) mlist=[] print(*nlist,sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nlist : Sequence := Sequence{} ; var mlist : Sequence := Sequence{} ; var t : boolean := true ; for i : Integer.subrange(0, num-1) do ( var list1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k : OclAny := list1->first() ; var n : int := 0 ; while t = true do ( n := n + 1 ; if (k mod list1[n+1]) = 0 then ( var o : int := 0 ; execute ((o) : mlist) ) else (if (k - list1[n+1]) > 0 then ( var i : int := 1 ; var r : int := k div list1[n+1] ; i := list1[n+1] * (r + 1) ; var h : double := k - i ; o := h ; o := ("" + ((o)))->toInteger() ; o := (o)->abs() ; execute ((o) : mlist) ) else skip) ; if (k - list1[n+1]) < 0 then ( o := k - list1[n+1] ; o := (o)->abs() ; execute ((o) : mlist) ) else skip ; if n = 3 then ( break ) else skip) ; var m : OclAny := (mlist)->min() ; execute ((m) : nlist) ; mlist := Sequence{}) ; execute ((argument * (test (logical_test (comparison (expr (atom (name nlist))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) counter=0 ans=0 uniforms=[] while(countertoInteger() ; var counter : int := 0 ; var ans : int := 0 ; var uniforms : Sequence := Sequence{} ; while ((counter->compareTo(n)) < 0) do ( execute ((input().split()) : uniforms) ; counter := counter + 1) ; var i : int := 0 ; while ((i->compareTo(n)) < 0) do ( for x : uniforms do ( if uniforms[i+1]->first() = x[1+1] then ( ans := ans + 1 ) else skip) ; i := i + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): r,a,b,c=list(map(int,input().split())) x=a-r % a y=b-r % b z=c-r % c if r % a==0 or r % b==0 or r % c==0 : print(0) else : print(min(x,min(y,z))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var r : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{r,a,b,c} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : double := a - r mod a ; var y : double := b - r mod b ; var z : double := c - r mod c ; if r mod a = 0 or r mod b = 0 or r mod c = 0 then ( execute (0)->display() ) else ( execute (Set{x, Set{y, z}->min()}->min())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): N,T,S=map(int,input().split()) a=[tuple(map(int,input().split()))for _ in[0]*N] dp=[float("-inf")]*(T+1) dp[0]=0 for fun,mise_time in a : for prev_time,from_fun,to_fun in zip(range(T-mise_time,-1,-1),dp[T-mise_time : :-1],dp[: :-1]): new_time=prev_time+mise_time new_fun=fun+from_fun if prev_timeT : continue to_fun=dp[new_time] if new_fun>to_fun : dp[new_time]=new_fun print(max(dp)) if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( solve() ) else skip; operation solve() pre: true post: true activity: var N : OclAny := null; var T : OclAny := null; var S : OclAny := null; Sequence{N,T,S} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (("-inf")))->toReal() }, (T + 1)) ; dp->first() := 0 ; for _tuple : a do (var _indx : int := 1; var fun : OclAny := _tuple->at(_indx); _indx := _indx + 1; var mise_time : OclAny := _tuple->at(_indx); for _tuple : Integer.subrange(1, Integer.subrange(-1 + 1, T - mise_time)->reverse()->size())->collect( _indx | Sequence{Integer.subrange(-1 + 1, T - mise_time)->reverse()->at(_indx), dp(subscript (test (logical_test (comparison (expr (expr (atom (name T))) - (expr (atom (name mise_time))))))) : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->at(_indx)} ) do (var _indx : int := 1; var prev_time : OclAny := _tuple->at(_indx); _indx := _indx + 1; var from_fun : OclAny := _tuple->at(_indx); _indx := _indx + 1; var to_fun : OclAny := _tuple->at(_indx); var new_time : OclAny := prev_time + mise_time ; var new_fun : OclAny := fun + from_fun ; if (prev_time->compareTo(S)) < 0 & (S < new_time) then ( new_time := S + mise_time ; if (new_time->compareTo(T)) > 0 then ( continue ) else skip ; var to_fun : OclAny := dp[new_time+1] ) else skip ; if (new_fun->compareTo(to_fun)) > 0 then ( dp[new_time+1] := new_fun ) else skip)) ; execute ((dp)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for _ in range(n): p,a,b,c=map(int,input().split()) if(p % a==0 or p % b==0 or p % c==0): print(0) else : print(min(abs(p % a-a),abs(p % b-b),abs(p % c-c))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var p : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{p,a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (p mod a = 0 or p mod b = 0 or p mod c = 0) then ( execute (0)->display() ) else ( execute (Set{(p mod a - a)->abs(), (p mod b - b)->abs(), (p mod c - c)->abs()}->min())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): p,a,b,c=map(int,input().split()) if p % a==0 or p % b==0 or p % c==0 : print(0) else : res=min(abs(a-p % a),abs(b-p % b),abs(c-p % c)) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var p : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{p,a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if p mod a = 0 or p mod b = 0 or p mod c = 0 then ( execute (0)->display() ) else ( var res : OclAny := Set{(a - p mod a)->abs(), (b - p mod b)->abs(), (c - p mod c)->abs()}->min() ; execute (res)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) for i in range(n): p,a,b,c=list(map(int,input().split())) x=min((a-p % a)% a,(b-p % b)% b,(c-p % c)% c) print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var p : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{p,a,b,c} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := Set{(a - p mod a) mod a, (b - p mod b) mod b, (c - p mod c) mod c}->min() ; execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in[0]*int(input()): n,k=map(int,input().split()); print(''.join(chr(97+i % k)for i in range(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name chr)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (number (integer 97)))) + (expr (expr (atom (name i))) % (expr (atom (name k)))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): L,A=list(map(int,input().split())) string=["a",'b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] per=L % A div=L//A ANS=(((string[: A :])*div)+string[: per :]) s='' for i in ANS : s+=i print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var L : OclAny := null; var A : OclAny := null; Sequence{L,A} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var string : Sequence := Sequence{"a"}->union(Sequence{'b'}->union(Sequence{'c'}->union(Sequence{'d'}->union(Sequence{'e'}->union(Sequence{'f'}->union(Sequence{'g'}->union(Sequence{'h'}->union(Sequence{'i'}->union(Sequence{'j'}->union(Sequence{'k'}->union(Sequence{'l'}->union(Sequence{'m'}->union(Sequence{'n'}->union(Sequence{'o'}->union(Sequence{'p'}->union(Sequence{'q'}->union(Sequence{'r'}->union(Sequence{'s'}->union(Sequence{'t'}->union(Sequence{'u'}->union(Sequence{'v'}->union(Sequence{'w'}->union(Sequence{'x'}->union(Sequence{'y'}->union(Sequence{ 'z' }))))))))))))))))))))))))) ; var per : int := L mod A ; var div : int := L div A ; var ANS : double := (((string(subscript : (test (logical_test (comparison (expr (atom (name A)))))) (sliceop :))) * div) + string(subscript : (test (logical_test (comparison (expr (atom (name per)))))) (sliceop :))) ; var s : String := '' ; for i : ANS do ( s := s + i) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in[0]*int(input()): n,k=map(int,input().split()); print(''.join(chr(97+i % k)for i in range(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name chr)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (number (integer 97)))) + (expr (expr (atom (name i))) % (expr (atom (name k)))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) s="" for i in range(k): s+=chr(ord("a")+i)*(n//k) s+="a"*(n % k) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := "" ; for i : Integer.subrange(0, k-1) do ( s := s + (("a")->char2byte() + i)->byte2char() * (n div k)) ; s := s + StringLib.nCopies("a", (n mod k)) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil if __name__=="__main__" : for _ in range(int(input())): alphabet="abcdefghijklmnopqrstuvwxyz" n,k=map(int,input().split()) max_freq=ceil(n/k) alphabet=alphabet[: k] s=alphabet[0]*max_freq if len(s)==n : print(s) else : alphabet=alphabet[1 :] i=0 while True : if len(s)==n : break if i==len(alphabet): i=0 s+=alphabet[i] i+=1 print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var alphabet : String := "abcdefghijklmnopqrstuvwxyz" ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var max_freq : OclAny := ceil(n / k) ; alphabet := alphabet.subrange(1,k) ; var s : double := alphabet->first() * max_freq ; if (s)->size() = n then ( execute (s)->display() ) else ( alphabet := alphabet->tail() ; var i : int := 0 ; while true do ( if (s)->size() = n then ( break ) else skip ; if i = (alphabet)->size() then ( i := 0 ) else skip ; s := s + alphabet[i+1] ; i := i + 1) ; execute (s)->display() )) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- home=[] guest=[] res=0 for _ in range(int(input())): team=input().split() home.append(team[0]) guest.append(team[1]) for i in home : for j in guest : if i==j : res+=1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var home : Sequence := Sequence{} ; var guest : Sequence := Sequence{} ; var res : int := 0 ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var team : OclAny := input().split() ; execute ((team->first()) : home) ; execute ((team[1+1]) : guest)) ; for i : home do ( for j : guest do ( if i = j then ( res := res + 1 ) else skip)) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(a==0): return b return gcd(b % a,a) def reduceB(a,b): mod=0 for i in range(0,len(b)): mod=(mod*10+ord(b[i]))% a return mod def gcdLarge(a,b): num=reduceB(a,b) return gcd(a,num) a=1221 b="1234567891011121314151617181920212223242526272829" if a==0 : print(b) else : print(gcdLarge(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; a := 1221 ; b := "1234567891011121314151617181920212223242526272829" ; if a = 0 then ( execute (b)->display() ) else ( execute (gcdLarge(a, b))->display() ); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0) then ( return b ) else skip ; return gcd(b mod a, a); operation reduceB(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var mod : int := 0 ; for i : Integer.subrange(0, (b)->size()-1) do ( mod := (mod * 10 + (b[i+1])->char2byte()) mod a) ; return mod; operation gcdLarge(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var num : OclAny := reduceB(a, b) ; return gcd(a, num); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=[int(x)for x in input().split()] se=[] c=sum(A)-N*(N+1)/2 for i in range(len(A)): if A[i]==c : se.append(i) l=se[0] r=se[1] mod=10**9+7 factorial=[1] inverse=[1] for i in range(1,N+2): factorial.append(factorial[-1]*i % mod) inverse.append((pow(factorial[i],mod-2,mod))) def nCr(n,r): if ntoInteger() ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var se : Sequence := Sequence{} ; var c : double := (A)->sum() - N * (N + 1) / 2 ; for i : Integer.subrange(0, (A)->size()-1) do ( if A[i+1] = c then ( execute ((i) : se) ) else skip) ; var l : OclAny := se->first() ; var r : OclAny := se[1+1] ; var mod : double := (10)->pow(9) + 7 ; var factorial : Sequence := Sequence{ 1 } ; var inverse : Sequence := Sequence{ 1 } ; for i : Integer.subrange(1, N + 2-1) do ( execute ((factorial->last() * i mod mod) : factorial) ; execute ((((factorial[i+1])->pow(mod - 2))) : inverse)) ; skip ; execute (N)->display() ; for i : Integer.subrange(2, N + 2-1) do ( execute (("" + ((nCr(N + 1, i) - nCr(l + N - r, i - 1))))->toInteger() mod mod)->display()); operation nCr(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: if (n->compareTo(r)) < 0 or n = 0 or r = 0 then ( return 0 ) else skip ; return factorial[n+1] * inverse[r+1] * inverse[n - r+1] mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t,s=map(int,raw_input().split()) ab=[map(int,raw_input().split())for _ in xrange(n)] dp=[[0]*(t+1)for _ in xrange(n+1)] for i in xrange(n): for j in xrange(1,t+1): if jcollect( _x | (OclType["int"])->apply(_x) ) ; var ab : Sequence := xrange(n)->select(_anon | true)->collect(_anon | ((raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var dp : Sequence := xrange(n + 1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (t + 1)))) ; for i : xrange(n) do ( for j : xrange(1, t + 1) do ( if (j->compareTo(ab[i+1][1+1])) < 0 then ( dp[i + 1+1][j+1] := dp[i+1][j+1] ; continue ) else skip ; if (j - ab[i+1][1+1]->compareTo(s)) < 0 & (s < j) then ( dp[i + 1+1][j+1] := Set{dp[i+1][j+1], dp[i + 1+1][j - 1+1]}->max() ; continue ) else skip ; dp[i + 1+1][j+1] := Set{dp[i+1][j+1], dp[i+1][j - ab[i+1][1+1]+1] + ab[i+1]->first()}->max())) ; execute (dp[n+1][t+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import queue import bisect from collections import deque,defaultdict import heapq as hpq from sys import stdin,setrecursionlimit ipt=stdin.readline setrecursionlimit(10**7) mod=10**9+7 dir=[(-1,0),(1,0),(0,-1),(0,1)] alp="abcdefghijklmnopqrstuvwxyz" def main(): n=int(ipt()) a=[int(i)for i in ipt().split()] pi=[-1]*(n+1) x1=0 x2=0 for i,ai in enumerate(a): if pi[ai]==-1 : pi[ai]=i else : x1=pi[ai] x2=n-i break xt=x1+x2 N=n+1 g1=[1,1] g2=[1,1] inverse=[0,1] def cmb(n,r,mod=(10**9+7)): if r<0 or r>n : return 0 r=min(r,n-r) return g1[n]*g2[r]*g2[n-r]% mod for i in range(2,N+1): g1.append((g1[-1]*i)% mod) inverse.append((-inverse[mod % i]*(mod//i))% mod) g2.append((g2[-1]*inverse[-1])% mod) for i in range(1,n+2): print((cmb(n+1,i)-cmb(xt,i-1))% mod) return None if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var ipt : OclAny := stdin.readline ; setrecursionlimit((10)->pow(7)) ; var mod : double := (10)->pow(9) + 7 ; var dir : Sequence := Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{0, -1}}->union(Sequence{ Sequence{0, 1} }))) ; var alp : String := "abcdefghijklmnopqrstuvwxyz" ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() : OclAny pre: true post: true activity: var n : int := ("" + ((ipt())))->toInteger() ; var a : Sequence := ipt().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var pi : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (n + 1)) ; var x1 : int := 0 ; var x2 : int := 0 ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var ai : OclAny := _tuple->at(_indx); if pi[ai+1] = -1 then ( pi[ai+1] := i ) else ( x1 := pi[ai+1] ; x2 := n - i ; break )) ; var xt : int := x1 + x2 ; var N : int := n + 1 ; var g1 : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var g2 : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var inverse : Sequence := Sequence{0}->union(Sequence{ 1 }) ; skip ; for i : Integer.subrange(2, N + 1-1) do ( execute (((g1->last() * i) mod mod) : g1) ; execute (((-inverse[mod mod i+1] * (mod div i)) mod mod) : inverse) ; execute (((g2->last() * inverse->last()) mod mod) : g2)) ; for i : Integer.subrange(1, n + 2-1) do ( execute ((cmb(n + 1, i) - cmb(xt, i - 1)) mod mod)->display()) ; return null; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Calc : def __init__(self,max_value,mod): fact=[-1]*(max_value+1) fact[0]=1 fact[1]=1 for x in range(2,max_value+1): fact[x]=x*fact[x-1]% mod invs=[-1]*(max_value+1) invs[max_value]=pow(fact[max_value],mod-2,mod) for x in range(max_value-1,0,-1): invs[x]=invs[x+1]*(x+1)% mod self.fact=fact self.invs=invs self.mod=mod def combination(self,n,r): if n-rexists( _x | result = _x ); attribute fact : Sequence := fact; attribute invs : Sequence := invs; attribute mod : OclAny := mod; operation initialise(max_value : OclAny,mod : OclAny) : Calc pre: true post: true activity: var fact : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (max_value + 1)) ; fact->first() := 1 ; fact[1+1] := 1 ; for x : Integer.subrange(2, max_value + 1-1) do ( fact[x+1] := x * fact[x - 1+1] mod mod) ; var invs : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (max_value + 1)) ; invs[max_value+1] := (fact[max_value+1])->pow(mod - 2) ; for x : Integer.subrange(0 + 1, max_value - 1)->reverse() do ( invs[x+1] := invs[x + 1+1] * (x + 1) mod mod) ; self.fact := fact ; self.invs := invs ; self.mod := mod; return self; operation combination(n : OclAny,r : OclAny) : OclAny pre: true post: true activity: if (n - r->compareTo(r)) < 0 then ( return self.combination(n, n - r) ) else skip ; if r < 0 then ( return 0 ) else skip ; if r = 0 then ( return 1 ) else skip ; if r = 1 then ( return n ) else skip ; return self.fact[n+1] * self.invs[r+1] * self.invs[n - r+1] mod self.mod; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; (testlist_star_expr (star_expr * (expr (atom (name A)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name A)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation main() pre: true post: true activity: var MOD : double := (10)->pow(9) + 7 ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=10**9+7 def prepare(n): global MOD modFacts=[0]*(n+1) modFacts[0]=1 for i in range(n): modFacts[i+1]=(modFacts[i]*(i+1))% MOD invs=[1]*(n+1) invs[n]=pow(modFacts[n],MOD-2,MOD) for i in range(n,1,-1): invs[i-1]=(invs[i]*i)% MOD return modFacts,invs N=int(input()) place=[0]*N A=list(map(int,input().split())) for i,s in enumerate(A): if place[s-1]==0 : place[s-1]=i+1 else : a=place[s-1] b=i+1 break modFacts,invs=prepare(N+1) cnt=pow(2,N+1,MOD)-1 cnt-=pow(2,a-1,MOD)*pow(2,N+1-b,MOD) la=a-1 rb=N+1-b t=la+rb for k in range(1,N+2): cnt=(modFacts[N+1]*invs[k]*invs[N+1-k])% MOD if t>=k-1 : cnt-=(modFacts[t]*invs[k-1]*invs[t-(k-1)]) print(cnt % MOD) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute MOD : OclAny; operation initialise() pre: true post: true activity: var MOD : double := (10)->pow(9) + 7 ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var place : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); if place[s - 1+1] = 0 then ( place[s - 1+1] := i + 1 ) else ( var a : OclAny := place[s - 1+1] ; var b : OclAny := i + 1 ; break )) ; Sequence{modFacts,invs} := prepare(N + 1) ; var cnt : double := (2)->pow(N + 1) - 1 ; cnt := cnt - (2)->pow(a - 1) * (2)->pow(N + 1 - b) ; var la : double := a - 1 ; var rb : double := N + 1 - b ; var t : OclAny := la + rb ; for k : Integer.subrange(1, N + 2-1) do ( cnt := (modFacts[N + 1+1] * invs[k+1] * invs[N + 1 - k+1]) mod MOD ; if (t->compareTo(k - 1)) >= 0 then ( cnt := cnt - (modFacts[t+1] * invs[k - 1+1] * invs[t - (k - 1)+1]) ) else skip ; execute (cnt mod MOD)->display()); operation prepare(n : OclAny) : OclAny pre: true post: true activity: skip ; var modFacts : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; modFacts->first() := 1 ; for i : Integer.subrange(0, n-1) do ( modFacts[i + 1+1] := (modFacts[i+1] * (i + 1)) mod MOD) ; var invs : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ; invs[n+1] := (modFacts[n+1])->pow(MOD - 2) ; for i : Integer.subrange(1 + 1, n)->reverse() do ( invs[i - 1+1] := (invs[i+1] * i) mod MOD) ; return modFacts, invs; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) a=list(map(int,input().split())) table=[-1]*(N+1) d=[0,0] mod=10**9+7 class Factorial : def __init__(self,n,mod): self.f=[1] for i in range(1,n+1): self.f.append(self.f[-1]*i % mod) self.i=[pow(self.f[-1],mod-2,mod)] for i in range(1,n+1)[: :-1]: self.i.append(self.i[-1]*i % mod) self.i.reverse() def factorial(self,i): return self.f[i] def ifactorial(self,i): return self.i[i] def combi(self,n,k): return self.f[n]*self.i[n-k]% mod*self.i[k]% mod f=Factorial(N+1,mod) for i in range(N+1): if table[a[i]]!=-1 : d=[table[a[i]],i] break table[a[i]]=i for i in range(1,N+2): x=f.combi(N+1,i) w=0 if N+d[0]-d[1]>=i-1 : w=f.combi(d[0]+N-d[1],i-1) print((x-w)% mod) ------------------------------------------------------------ OCL File: --------- class Factorial { static operation newFactorial() : Factorial pre: true post: Factorial->exists( _x | result = _x ); attribute f : Sequence := Sequence{ 1 }; attribute i : Sequence := Sequence{ (self.f->last())->pow(mod - 2) }; operation initialise(n : OclAny,mod : OclAny) : Factorial pre: true post: true activity: self.f := Sequence{ 1 } ; for i : Integer.subrange(1, n + 1-1) do ((expr (atom (name self)) (trailer . (name f)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name self)) (trailer . (name f) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))) * (expr (atom (name i)))) % (expr (atom (name mod))))))))) ))))) ; self.i := Sequence{ (self.f->last())->pow(mod - 2) } ; for i : range(1, n + 1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ((expr (atom (name self)) (trailer . (name i)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name self)) (trailer . (name i) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))) * (expr (atom (name i)))) % (expr (atom (name mod))))))))) ))))) ; (expr (atom (name self)) (trailer . (name i)) (trailer . (name reverse) (arguments ( )))); return self; operation factorial(i : OclAny) : OclAny pre: true post: true activity: return self.f[i+1]; operation ifactorial(i : OclAny) : OclAny pre: true post: true activity: return self.i[i+1]; operation combi(n : OclAny,k : OclAny) : OclAny pre: true post: true activity: return self.f[n+1] * self.i[n - k+1] mod mod * self.i[k+1] mod mod; } class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var table : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (N + 1)) ; var d : Sequence := Sequence{0}->union(Sequence{ 0 }) ; var mod : double := (10)->pow(9) + 7 ; skip ; var f : Factorial := (Factorial.newFactorial()).initialise(N + 1, mod) ; for i : Integer.subrange(0, N + 1-1) do ( if table[a[i+1]+1] /= -1 then ( d := Sequence{table[a[i+1]+1]}->union(Sequence{ i }) ; break ) else skip ; table[a[i+1]+1] := i) ; for i : Integer.subrange(1, N + 2-1) do ( var x : String := f.combi(N + 1, i) ; var w : int := 0 ; if (N + d->first() - d[1+1]->compareTo(i - 1)) >= 0 then ( w := f.combi(d->first() + N - d[1+1], i - 1) ) else skip ; execute ((x - w) mod mod)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a,b=map(int,input().split()) t=[] ans=1 i=2 n=b while i*i<=n : if n % i==0 : t.append(i) n//=i else : i=i+1 t.append(n) for i in t : k=a while k % b==0 : k//=i ans=max(ans,k) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : Sequence := Sequence{} ; var ans : int := 1 ; var i : int := 2 ; var n : OclAny := b ; while (i * i->compareTo(n)) <= 0 do ( if n mod i = 0 then ( execute ((i) : t) ; n := n div i ) else ( i := i + 1 )) ; execute ((n) : t) ; for i : t do ( var k : OclAny := a ; while k mod b = 0 do ( k := k div i) ; ans := Set{ans, k}->max()) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import io import os from collections import Counter,defaultdict,deque from math import gcd def primeFactors(n): assert n>=1 factors=Counter() while n % 2==0 : factors[2]+=1 n//=2 x=3 while x*x<=n : while n % x==0 : factors[x]+=1 n//=x x+=2 if n!=1 : factors[n]+=1 return factors def solve(P,Q): g=gcd(P,Q) if g!=Q : return P else : best=float("inf") factors=primeFactors(Q) for k,v in factors.items(): k2=P v2=0 while k2 % k==0 : k2//=k v2+=1 best=min(best,k**(v2-v+1)) return P//best if __name__=="__main__" : input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline TC=int(input()) for tc in range(1,TC+1): P,Q=[int(x)for x in input().split()] ans=solve(P,Q) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( var input : OclAny := io.BytesIO(os.readAll()).readline ; var TC : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for tc : Integer.subrange(1, TC + 1-1) do ( Sequence{P,Q} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : OclAny := solve(P, Q) ; execute (ans)->display()) ) else skip; operation primeFactors(n : OclAny) : OclAny pre: true post: true activity: assert n >= 1 do "assertion failed" ; var factors : OclAny := Counter() ; while n mod 2 = 0 do ( factors[2+1] := factors[2+1] + 1 ; n := n div 2) ; var x : int := 3 ; while (x * x->compareTo(n)) <= 0 do ( while n mod x = 0 do ( factors[x+1] := factors[x+1] + 1 ; n := n div x) ; x := x + 2) ; if n /= 1 then ( factors[n+1] := factors[n+1] + 1 ) else skip ; return factors; operation solve(P : OclAny, Q : OclAny) : OclAny pre: true post: true activity: var g : OclAny := gcd(P, Q) ; if g /= Q then ( return P ) else ( var best : double := ("" + (("inf")))->toReal() ; factors := primeFactors(Q) ; for _tuple : factors->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); var k2 : OclAny := P ; var v2 : int := 0 ; while k2 mod k = 0 do ( k2 := k2 div k ; v2 := v2 + 1) ; best := Set{best, (k)->pow((v2 - v + 1))}->min()) ; return P div best ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def how_many_of_this_factor(p,factor): total=0 while p % factor==0 : p//=factor total+=1 return total def add_factor(factors,factor): if factor not in factors : factors[factor]=1 else : factors[factor]+=1 def factorize(n): factors={} if n==3 : return{3 : 1} while n % 2==0 : add_factor(factors,2) n//=2 z=3 ; hi=int(n**0.5) while z<=hi : got_one=False while n % z==0 : got_one=True n//=z add_factor(factors,z) if got_one : hi=int(n**0.5) z+=2 if hi!=1 or n==3 : add_factor(factors,n) return factors def solve(p,q): if p % q!=0 : return p factors=factorize(q) m=p for factor in factors : p_has=how_many_of_this_factor(p,factor) q_has=factors[factor] toss=p_has-(q_has-1) m=min(m,factor**toss) return p//m def main(): t=int(input()) for _ in range(t): p,q=map(int,input().split()) print(solve(p,q)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; main(); operation how_many_of_this_factor(p : OclAny, factor : OclAny) : OclAny pre: true post: true activity: var total : int := 0 ; while p mod factor = 0 do ( p := p div factor ; total := total + 1) ; return total; operation add_factor(factors : OclAny, factor : OclAny) pre: true post: true activity: if (factors)->excludes(factor) then ( factors[factor+1] := 1 ) else ( factors[factor+1] := factors[factor+1] + 1 ); operation factorize(n : OclAny) : OclAny pre: true post: true activity: factors := Set{} ; if n = 3 then ( return Map{ 3 |-> 1 } ) else skip ; while n mod 2 = 0 do ( add_factor(factors, 2) ; n := n div 2) ; var z : int := 3; var hi : int := ("" + (((n)->pow(0.5))))->toInteger() ; while (z->compareTo(hi)) <= 0 do ( var got_one : boolean := false ; while n mod z = 0 do ( got_one := true ; n := n div z ; add_factor(factors, z)) ; if got_one then ( hi := ("" + (((n)->pow(0.5))))->toInteger() ) else skip ; z := z + 2) ; if hi /= 1 or n = 3 then ( add_factor(factors, n) ) else skip ; return factors; operation solve(p : OclAny, q : OclAny) : OclAny pre: true post: true activity: if p mod q /= 0 then ( return p ) else skip ; factors := factorize(q) ; var m : OclAny := p ; for factor : factors do ( var p_has : OclAny := how_many_of_this_factor(p, factor) ; var q_has : OclAny := factors[factor+1] ; var toss : double := p_has - (q_has - 1) ; m := Set{m, (factor)->pow(toss)}->min()) ; return p div m; operation main() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( Sequence{p,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (solve(p, q))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : t,(n,m)=[0],map(int,input().split()) if n==m==0 : break if n : t+=map(int,input().split()) if m : t+=map(int,input().split()) t.sort() print(max(t[i+1]-t[i]for i in range(n+m))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var t : OclAny := null; var Sequence{n, m} : OclAny := null; Sequence{t,Sequence{n, m}} := Sequence{Sequence{ 0 },(input().split())->collect( _x | (OclType["int"])->apply(_x) )} ; if n = m & (m == 0) then ( break ) else skip ; if n then ( t := t + (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ) else skip ; if m then ( t := t + (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ) else skip ; t := t->sort() ; execute (((argument (test (logical_test (comparison (expr (expr (atom (name t)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))) - (expr (atom (name t)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (name m))))))))) )))))))))->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(0,int(input())): m,M=map(int,input().split()) t=0 while m!=0 and M!=0 : m,M=sorted([m,M]) v=(M//m) M=M-(v*m) t+=v print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var m : OclAny := null; var M : OclAny := null; Sequence{m,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : int := 0 ; while m /= 0 & M /= 0 do ( var m : OclAny := null; var M : OclAny := null; Sequence{m,M} := Sequence{m}->union(Sequence{ M })->sort() ; var v : int := (M div m) ; var M : double := M - (v * m) ; t := t + v) ; execute (t)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input("")) switched=0 home_uniforms_teams=[] guest_uniforms_teams=[] for i in range(n): home,guest=input().split() home_uniforms_teams.append(home) guest_uniforms_teams.append(guest) for home_team in home_uniforms_teams : for guest_team_uniform in guest_uniforms_teams : if home_team==guest_team_uniform : switched+=1 print(switched) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine(""))))->toInteger() ; var switched : int := 0 ; var home_uniforms_teams : Sequence := Sequence{} ; var guest_uniforms_teams : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var home : OclAny := null; var guest : OclAny := null; Sequence{home,guest} := input().split() ; execute ((home) : home_uniforms_teams) ; execute ((guest) : guest_uniforms_teams)) ; for home_team : home_uniforms_teams do ( for guest_team_uniform : guest_uniforms_teams do ( if home_team = guest_team_uniform then ( switched := switched + 1 ) else skip)) ; execute (switched)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys input=sys.stdin.readline for _ in range(int(input())): p,q=map(int,input().split()) if(p % q!=0): print(p) continue lst=[] for i in range(1,math.ceil(math.sqrt(q))+1): if(q % i==0): lst.append(i) lst.append(q//i) lst=list(set(lst)) lst.sort() ans=0 for i in range(1,len(lst)): x=p while(x % q==0): x=x//lst[i] ans=max(ans,x) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (p mod q /= 0) then ( execute (p)->display() ; continue ) else skip ; var lst : Sequence := Sequence{} ; for i : Integer.subrange(1, ((q)->sqrt())->ceil() + 1-1) do ( if (q mod i = 0) then ( execute ((i) : lst) ; execute ((q div i) : lst) ) else skip) ; lst := (Set{}->union((lst))) ; lst := lst->sort() ; var ans : int := 0 ; for i : Integer.subrange(1, (lst)->size()-1) do ( var x : OclAny := p ; while (x mod q = 0) do ( x := x div lst[i+1]) ; ans := Set{ans, x}->max()) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: p,q=map(int,s.split()) l=[]; j=2 ; a=q while(j*j<=a): if a % j==0 : l+=[j] while(a % j==0): a//=j j+=1 if a>1 : l+=[a]; a=1 for j in l : k=p while(k % q==0): k//=j a=max(k,a) print(a) num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := Sequence{}; var j : int := 2; var a : OclAny := q ; while ((j * j->compareTo(a)) <= 0) do ( if a mod j = 0 then ( l := l + Sequence{ j } ; while (a mod j = 0) do ( a := a div j) ) else skip ; j := j + 1) ; if a > 1 then ( l := l + Sequence{ a }; a := 1 ) else skip ; for j : l do ( var k : OclAny := p ; while (k mod q = 0) do ( k := k div j) ; a := Set{k, a}->max()) ; execute (a)->display()) ; var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def examA(): N=I() B=LI() ans=[0]*N flag=False for i in range(N-1,-1,-1): for j in range(i,-1,-1): if j+1==B[j]: ans[i]=B[j] del B[j] break if ans[i]==0 : print("-1") flag=True break if not flag : for v in ans : print(v) from string import digits import sys,copy,bisect,itertools,math from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() mod=10**9+7 inf=float('inf') examA() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; examA(); operation examA() pre: true post: true activity: var N : OclAny := I() ; var B : OclAny := LI() ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var flag : boolean := false ; for i : Integer.subrange(-1 + 1, N - 1)->reverse() do ( for j : Integer.subrange(-1 + 1, i)->reverse() do ( if j + 1 = B[j+1] then ( ans[i+1] := B[j+1] ; execute (B[j+1])->isDeleted() ; break ) else skip) ; if ans[i+1] = 0 then ( execute ("-1")->display() ; flag := true ; break ) else skip) ; if not(flag) then ( for v : ans do ( execute (v)->display()) ) else skip; operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation SI() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque import itertools as it import sys import math def func(): N=int(input()) A=list(map(int,input().split())) P=[[(A[0],0),(0,0)]for i in range(2**N)] for i in range(1,2**N): if(A[i],i)>P[i][0]: P[i][1]=P[i][0] P[i][0]=(A[i],i) elif(A[i],i)>P[i][1]: P[i][1]=(A[i],i) for j in range(N): if(i &(1<P[index][0]: P[index][1]=P[index][0] P[index][0]=P[i][k] elif P[i][k]>P[index][1]and P[i][k]!=P[index][0]: P[index][1]=P[i][k] ans=0 for i in range(1,2**N): ans=max(ans,P[i][0][0]+P[i][1][0]) print(ans) func() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; func(); operation func() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var P : Sequence := Integer.subrange(0, (2)->pow(N)-1)->select(i | true)->collect(i | (Sequence{Sequence{A->first(), 0}}->union(Sequence{ Sequence{0, 0} }))) ; for i : Integer.subrange(1, (2)->pow(N)-1) do ( if (Sequence{A[i+1], i}->compareTo(P[i+1]->first())) > 0 then ( P[i+1][1+1] := P[i+1]->first() ; P[i+1]->first() := Sequence{A[i+1], i} ) else (if (Sequence{A[i+1], i}->compareTo(P[i+1][1+1])) > 0 then ( P[i+1][1+1] := Sequence{A[i+1], i} ) else skip) ; for j : Integer.subrange(0, N-1) do ( if (MathLib.bitwiseAnd(i, (1 * (2->pow(j))))) = 0 then ( var index : OclAny := i + (1 * (2->pow(j))) ; for k : Integer.subrange(0, 2-1) do ( if (P[i+1][k+1]->compareTo(P[index+1]->first())) > 0 then ( P[index+1][1+1] := P[index+1]->first() ; P[index+1]->first() := P[i+1][k+1] ) else (if (P[i+1][k+1]->compareTo(P[index+1][1+1])) > 0 & P[i+1][k+1] /= P[index+1]->first() then ( P[index+1][1+1] := P[i+1][k+1] ) else skip)) ) else skip)) ; var ans : int := 0 ; for i : Integer.subrange(1, (2)->pow(N)-1) do ( ans := Set{ans, P[i+1]->first()->first() + P[i+1][1+1]->first()}->max() ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) L=list(map(int,input().split())) li=[] a=0 while a<=101 : for i in range(len(L)-1,-1,-1): if i==L[i]-1 : li.append(L[i]) L.pop(i) break a+=1 if len(L)>0 : print(-1) else : li=li[: :-1] for i in range(len(li)): print(li[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var L : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var li : Sequence := Sequence{} ; var a : int := 0 ; while a <= 101 do ( for i : Integer.subrange(-1 + 1, (L)->size() - 1)->reverse() do ( if i = L[i+1] - 1 then ( execute ((L[i+1]) : li) ; L := L->excludingAt(i+1) ; break ) else skip) ; a := a + 1) ; if (L)->size() > 0 then ( execute (-1)->display() ) else ( li := li(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; for i : Integer.subrange(0, (li)->size()-1) do ( execute (li[i+1])->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return[int(x)for x in input().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(input()) def pf(s): return print(s,flush=True) N=I() b=LI() result=[] while True : for i in range(1,len(b)+1): if b[-i]==len(b)-i+1 : result.append(b[-i]) b.pop(-i) break else : if not b : break print(-1) exit() for i in result[: :-1]: print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : double := (10)->pow(9) + 7 ; var dd : Sequence := Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{ Sequence{0, -1} }))) ; var ddn : Sequence := Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{-1, 1}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{1, 1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{1, -1}}->union(Sequence{Sequence{0, -1}}->union(Sequence{ Sequence{-1, -1} }))))))) ; skip ; skip ; skip ; skip ; skip ; skip ; var N : OclAny := I() ; var b : OclAny := LI() ; var result : Sequence := Sequence{} ; while true do ((compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr - (expr (atom (name i))))))))) ])))) == (comparison (expr (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) - (expr (atom (name i)))) + (expr (atom (number (integer 1))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name result)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr - (expr (atom (name i))))))))) ])))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)) (trailer . (name pop) (arguments ( (arglist (argument (test (logical_test (comparison (expr - (expr (atom (name i))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test not (logical_test (comparison (expr (atom (name b))))))) : (suite (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name exit)) (trailer (arguments ( )))))))))))))))) ; for i : result(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( execute (i)->display()); operation LI() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import copy import heapq import math import sys from collections import* from functools import lru_cache from itertools import accumulate,combinations,permutations,product def input(): return sys.stdin.readline()[:-1] def ruiseki(lst): return[0]+list(accumulate(lst)) sys.setrecursionlimit(5000000) mod=pow(10,9)+7 al=[chr(ord('a')+i)for i in range(26)] direction=[[1,0],[0,1],[-1,0],[0,-1]] n=int(input()) b=list(map(int,input().split())) anslst=[] while b : for i in range(len(b))[: :-1]: if b[i]==i+1 : anslst.append(b[i]) b.pop(i) break else : print(-1) quit() for i in range(n): print(anslst[-1-i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(5000000) ; var mod : double := (10)->pow(9) + 7 ; var al : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | ((('a')->char2byte() + i)->byte2char())) ; var direction : Sequence := Sequence{Sequence{1}->union(Sequence{ 0 })}->union(Sequence{Sequence{0}->union(Sequence{ 1 })}->union(Sequence{Sequence{-1}->union(Sequence{ 0 })}->union(Sequence{ Sequence{0}->union(Sequence{ -1 }) }))) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var anslst : Sequence := Sequence{} ; while b do ((compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) ))))))))) ))) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ]))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name anslst)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)) (trailer . (name pop) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name quit)) (trailer (arguments ( )))))))))))))))) ; for i : Integer.subrange(0, n-1) do ( execute (anslst->reverse()->at(-(-1 - i)))->display()); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation ruiseki(lst : OclAny) : OclAny pre: true post: true activity: return Sequence{ 0 }->union((accumulate(lst))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement from collections import deque,defaultdict,Counter from bisect import bisect_left,bisect_right from operator import itemgetter from heapq import heapify,heappop,heappush from queue import Queue,LifoQueue,PriorityQueue from copy import deepcopy from time import time from functools import reduce import string import sys sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(MAP()) n=INT() b=LIST() ans=deque() while b : m=len(b) for i in range(m-1,-1,-1): if b[i]==i+1 : ans.appendleft(b.pop(i)) break else : print(-1) exit() for x in ans : print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; skip ; skip ; skip ; var n : OclAny := INT() ; var b : OclAny := LIST() ; var ans : Sequence := () ; while b do ( var m : int := (b)->size() ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name m))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom - (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)) (trailer . (name appendleft) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)) (trailer . (name pop) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name exit)) (trailer (arguments ( )))))))))))))))) ; for x : ans do ( execute (x)->display()); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return (MAP()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys import itertools import fractions if __name__=='__main__' : wtf=sys.stdin.read() wtf=wtf.strip().split('\n') n=int(wtf[0]) d=dict() for s in wtf[1 :]: if s[0]in d : d[s[0]]+=1 else : d[s[0]]=1 ans=0 for k,v in d.items(): if v>=2 : q=math.ceil(v/2) r=v-q ans+=math.comb(q,2) ans+=math.comb(r,2) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var wtf : String := (OclFile["System.in"]).readAll() ; wtf := wtf->trim().split(' ') ; var n : int := ("" + ((wtf->first())))->toInteger() ; var d : Map := (arguments ( )) ; for s : wtf->tail() do ( if (d)->includes(s->first()) then ( d[s->first()+1] := d[s->first()+1] + 1 ) else ( d[s->first()+1] := 1 )) ; var ans : int := 0 ; for _tuple : d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if v >= 2 then ( var q : double := (v / 2)->ceil() ; var r : double := v - q ; ans := ans + MathLib.combinatorial(q, 2) ; ans := ans + MathLib.combinatorial(r, 2) ) else skip) ; execute (ans)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- std=int(input()) array=[] for i in range(0,std): aux=str(input()) array.append(aux) array.sort() letters=[0] position=0 previous=array[0][0] for k in array : current=k[0] if(current!=previous): new=1 letters.append(new) position=position+1 previous=current else : letters[position]=letters[position]+1 result=0 for k in letters : if k>1 : cl1=k-int(k/2) cl2=int(k/2) result=result+(cl1*(cl1-1)/2)+(cl2*(cl2-1)/2) print(int(result)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var std : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var array : Sequence := Sequence{} ; for i : Integer.subrange(0, std-1) do ( var aux : String := ("" + (((OclFile["System.in"]).readLine()))) ; execute ((aux) : array)) ; array := array->sort() ; var letters : Sequence := Sequence{ 0 } ; var position : int := 0 ; var previous : OclAny := array->first()->first() ; for k : array do ( var current : OclAny := k->first() ; if (current /= previous) then ( var new : int := 1 ; execute ((new) : letters) ; position := position + 1 ; previous := current ) else ( letters[position+1] := letters[position+1] + 1 )) ; var result : int := 0 ; for k : letters do ( if k > 1 then ( var cl1 : double := k - ("" + ((k / 2)))->toInteger() ; var cl2 : int := ("" + ((k / 2)))->toInteger() ; result := result + (cl1 * (cl1 - 1) / 2) + (cl2 * (cl2 - 1) / 2) ) else skip) ; execute (("" + ((result)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) host=[] guest=[] clothes=0 for i in range(n): h,g=[int(x)for x in input().split(' ')] host.append(h) guest.append(g) for h in host : if h in guest : clothes+=guest.count(h) print(clothes) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var host : Sequence := Sequence{} ; var guest : Sequence := Sequence{} ; var clothes : int := 0 ; for i : Integer.subrange(0, n-1) do ( var h : OclAny := null; var g : OclAny := null; Sequence{h,g} := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((h) : host) ; execute ((g) : guest)) ; for h : host do ( if (guest)->includes(h) then ( clothes := clothes + guest->count(h) ) else skip) ; execute (clothes)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pares(n): return n*(n-1)/2 n=int(input()) alpha=[0 for _ in range(26)] for i in range(n): alpha[ord((input())[0])-97]+=1 total=0 for letter in alpha : if letter!=0 : if letter//2!=letter/2 : total+=pares(letter//2)+pares(letter//2+1) else : total+=2*pares(letter//2) print(int(total)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var alpha : Sequence := Integer.subrange(0, 26-1)->select(_anon | true)->collect(_anon | (0)) ; for i : Integer.subrange(0, n-1) do ( alpha[(((OclFile["System.in"]).readLine())->first())->char2byte() - 97+1] := alpha[(((OclFile["System.in"]).readLine())->first())->char2byte() - 97+1] + 1) ; var total : int := 0 ; for letter : alpha do ( if letter /= 0 then ( if letter div 2 /= letter / 2 then ( total := total + pares(letter div 2) + pares(letter div 2 + 1) ) else ( total := total + 2 * pares(letter div 2) ) ) else skip) ; execute (("" + ((total)))->toInteger())->display(); operation pares(n : OclAny) : OclAny pre: true post: true activity: return n * (n - 1) / 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil,comb n=int(input()) c=[0]*255 s=[] for i in range(n): name=str(input()) s.append(name) c[ord(name[0])]+=1 c=list(filter(lambda x : x!=0,c)) cp=0 for ci in c : if ci>2 : ni=ceil(ci/2) cp+=comb(ni,2) cp+=comb(ci-ni,2) print(cp) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 255) ; var s : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var name : String := ("" + (((OclFile["System.in"]).readLine()))) ; execute ((name) : s) ; c[(name->first())->char2byte()+1] := c[(name->first())->char2byte()+1] + 1) ; c := ((c)->select( _x | (lambda x : OclAny in (x /= 0))->apply(_x) = true )) ; var cp : int := 0 ; for ci : c do ( if ci > 2 then ( var ni : OclAny := ceil(ci / 2) ; cp := cp + comb(ni, 2) ; cp := cp + comb(ci - ni, 2) ) else skip) ; execute (cp)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from operator import mul from fractions import Fraction from functools import reduce from math import floor,ceil def silent_classroom(): n=int(input()) estudantes={} for _ in range(n): nome=input() try : estudantes[nome[0]]+=1 except : estudantes[nome[0]]=1 sala_1,sala_2=0,0 for inicial in estudantes : numero_iniciais=estudantes[inicial] if(numero_iniciais>2): if(sala_1toInteger() ; var estudantes : OclAny := Set{} ; for _anon : Integer.subrange(0, n-1) do ( var nome : String := (OclFile["System.in"]).readLine() ; try ( estudantes[nome->first()+1] := estudantes[nome->first()+1] + 1) catch (_e : OclException) do ( estudantes[nome->first()+1] := 1) ) ; var salasala var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(),sala:= 0,0 : OclAny := null; var sala:= 0,0 : OclAny := null; Sequence{sala var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(),sala:= 0,0} := Sequence{0,0} ; for inicial : estudantes do ( var numero_iniciais : OclAny := estudantes[inicial+1] ; if (numero_iniciais > 2) then ( if ((sala var numero_iniciais : OclAny := estudantes[inicial+1]->compareTo(sala sala var numero_iniciais : OclAny := estudantes[inicial+1] := sala var numero_iniciais : OclAny := estudantes[inicial+1] + comb(ceil(numero_iniciais / 2), 2) ; sala + comb(floor(numero_iniciais / 2), 2) := sala + comb(floor(numero_iniciais / 2), 2) + comb(floor(numero_iniciais / 2), 2))) < 0) then ( sala var numero_iniciais : OclAny := estudantes[inicial+1] := sala var numero_iniciais : OclAny := estudantes[inicial+1] + comb(ceil(numero_iniciais / 2), 2) ; sala + comb(floor(numero_iniciais / 2), 2) := sala + comb(floor(numero_iniciais / 2), 2) + comb(floor(numero_iniciais / 2), 2) ) else ( sala + comb(ceil(numero_iniciais / 2), 2) := sala + comb(ceil(numero_iniciais / 2), 2) + comb(ceil(numero_iniciais / 2), 2) ; sala sala + comb(ceil(numero_iniciais / 2), 2) := sala + comb(ceil(numero_iniciais / 2), 2) + comb(ceil(numero_iniciais / 2), 2) := sala sala + comb(ceil(numero_iniciais / 2), 2) := sala + comb(ceil(numero_iniciais / 2), 2) + comb(ceil(numero_iniciais / 2), 2) + comb(floor(numero_iniciais / 2), 2) ) ) else skip) ; execute (salasala(sala(sala(salasala(sala(sala(salasala(sala(sala(salasala(sala(sala(salasala(sala(sala(salasala(sala(sala(salasala(sala(sala var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() + sala_2) + sala_2) + sala_2 + sala_2)->display() + sala_2) + sala_2) + sala_2 + sala_2)->display() + sala_2) + sala_2) + sala_2 + sala_2)->display() + sala_2) + sala_2) + sala_2 + sala_2)->display() + sala_2) + sala_2) + sala_2 + sala_2)->display() + sala_2) + sala_2) + sala_2 + sala_2)->display() + sala_2) + sala_2) + sala_2 + sala_2)->display(); operation comb(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: return ("" + ((reduce(mul, Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name Fraction)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (name i)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name k)))))))) ))))))))}, 1))))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findLen(arr,n,m): filter=[]; for i in range(n): if((arr[i]& m)==m): filter.append(arr[i]); if(len(filter)==0): return 0 ; c_and=filter[0]; for i in range(1,len(filter)): c_and &=filter[i]; if(c_and==m): return len(filter); if __name__=="__main__" : arr=[7,3,3,1,3]; n=len(arr); m=3 ; print(findLen(arr,n,m)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{7}->union(Sequence{3}->union(Sequence{3}->union(Sequence{1}->union(Sequence{ 3 })))); ; n := (arr)->size(); ; m := 3; ; execute (findLen(arr, n, m))->display(); ) else skip; operation findLen(arr : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: var filter : Sequence := Sequence{}; ; for i : Integer.subrange(0, n-1) do ( if ((MathLib.bitwiseAnd(arr[i+1], m)) = m) then ( execute ((arr[i+1]) : filter); ) else skip) ; if ((filter)->size() = 0) then ( return 0; ) else skip ; var c_and : Sequence := (->first()`third)->select( _x | (->first())->apply(_x) = true ); ; for i : Integer.subrange(1, (filter)->size()-1) do ( c_and := c_and & ([i+1]`third)->select( _x | ([i+1])->apply(_x) = true );) ; if (c_and = m) then ( return (filter)->size(); ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import sys if os.getenv("LOCAL"): sys.stdin=open("_in.txt","r") sys.setrecursionlimit(10**9) INF=float("inf") IINF=10**18 MOD=10**9+7 def cummax(it,first=-float('inf')): cm=first ret=[] for v in it : cm=max(v,cm) ret.append(cm) return ret N=int(sys.stdin.buffer.readline()) A=list(map(int,sys.stdin.buffer.readline().split())) SIZE=2**N dp=[None]*SIZE for k in range(1,SIZE): dp[k]=list(sorted([(A[0],0),(A[k],k)])) for k in range(1,SIZE): mask=k while maskb2 : dp[next_k]=dp[k] elif b1>a2 : pass elif a2>b2 : dp[next_k]=b2,a2 elif b2>a2 : dp[next_k]=a2,b2 ans=[0]*SIZE for k in range(1,SIZE): (a1,_),(a2,_)=dp[k] ans[k]=a1+a2 ans=cummax(ans[1 :]) print(*ans,sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if os.getenv("LOCAL") then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("_in.txt")) ) else skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (("inf")))->toReal() ; var IINF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; skip ; var N : int := ("" + ((sys.stdin.buffer.readLine())))->toInteger() ; var A : Sequence := ((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var SIZE : double := (2)->pow(N) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, SIZE) ; for k : Integer.subrange(1, SIZE-1) do ( dp[k+1] := (Sequence{Sequence{A->first(), 0}}->union(Sequence{ Sequence{A[k+1], k} })->sort())) ; for k : Integer.subrange(1, SIZE-1) do ( var mask : OclAny := k ; while (mask->compareTo(SIZE - 1)) < 0 do ( var next_k : int := MathLib.bitwiseOr((mask + 1), k) ; mask := mask or next_k ; var a1 : OclAny := null; var a2 : OclAny := null; Sequence{a1,a2} := dp[k+1] ; var b1 : OclAny := null; var b2 : OclAny := null; Sequence{b1,b2} := dp[next_k+1] ; if (a1->compareTo(b2)) > 0 then ( dp[next_k+1] := dp[k+1] ) else (if (b1->compareTo(a2)) > 0 then ( skip ) else (if (a2->compareTo(b2)) > 0 then ( dp[next_k+1] := b2,a2 ) else (if (b2->compareTo(a2)) > 0 then ( dp[next_k+1] := a2,b2 ) else skip ) ) ) )) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, SIZE) ; for k : Integer.subrange(1, SIZE-1) do ( ; var Sequence{a1, _anon} : OclAny := null; var Sequence{a2, _anon} : OclAny := null; Sequence{Sequence{a1, _anon},Sequence{a2, _anon}} := dp[k+1] ; ans[k+1] := a1 + a2) ; ans := cummax(ans->tail()) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); operation cummax(it : OclAny, first : OclAny) : OclAny pre: true post: true activity: if first->oclIsUndefined() then first := -("" + (('inf')))->toReal() else skip; var cm : OclAny := first ; var ret : Sequence := Sequence{} ; for v : it do ( cm := Set{v, cm}->max() ; execute ((cm) : ret)) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def setBits(n): count=0 while(n): n=n &(n-1) count+=1 return count def countPairs(a,n): count=0 for i in range(0,n-1,1): setbits_x=setBits(a[i]) for j in range(i+1,n,1): setbits_y=setBits(a[j]) setbits_xor_xy=setBits(a[i]^ a[j]); if(setbits_x+setbits_y==setbits_xor_xy): count+=1 return count if __name__=='__main__' : a=[2,3,4,5,6] n=len(a) print(countPairs(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( a := Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 })))) ; n := (a)->size() ; execute (countPairs(a, n))->display() ) else skip; operation setBits(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while (n) do ( n := MathLib.bitwiseAnd(n, (n - 1)) ; count := count + 1) ; return count; operation countPairs(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: count := 0 ; for i : Integer.subrange(0, n - 1-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( var setbits_x : OclAny := setBits(a[i+1]) ; for j : Integer.subrange(i + 1, n-1)->select( $x | ($x - i + 1) mod 1 = 0 ) do ( var setbits_y : OclAny := setBits(a[j+1]) ; var setbits_xor_xy : OclAny := setBits(MathLib.bitwiseXor(a[i+1], a[j+1])); ; if (setbits_x + setbits_y = setbits_xor_xy) then ( count := count + 1 ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- X=int(input()) for i in range(-1000,1001): for j in range(-1000,1001): if i**5-j**5==X : print(i,j) exit() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var X : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(-1000, 1001-1) do ( for j : Integer.subrange(-1000, 1001-1) do ( if (i)->pow(5) - (j)->pow(5) = X then ( execute (i)->display() ; exit() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calc(n): x=1<<(n.bit_length()+4)//5 y=(4*x+n//(x**4))//5 while y0 and calc(n)**5==n else 0 X=int(input()) for i in range(1<<10): a=f(X+i**5) if a : print(a,i) break a=f(X-i**5) if a : print(a,-i) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var X : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, 1 * (2->pow(10))-1) do ( var a : String := f(X + (i)->pow(5)) ; if a then ( execute (a)->display() ; break ) else skip ; a := f(X - (i)->pow(5)) ; if a then ( execute (a)->display() ; break ) else skip); operation calc(n : OclAny) : OclAny pre: true post: true activity: var x : int := 1 * (2->pow((n.bit_length() + 4) div 5)) ; var y : int := (4 * x + n div ((x)->pow(4))) div 5 ; while (y->compareTo(x)) < 0 do ( x := y ; y := (4 * x + n div ((x)->pow(4))) div 5) ; return x; operation f(n : OclAny) : OclAny pre: true post: true activity: return if n > 0 & (calc(n))->pow(5) = n then calc(n) else 0 endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys readline=sys.stdin.readline def main(): x=int(readline().rstrip()) a,b,c=0,0,1 while a<1000 : k=a**5-x c=1 if k>=0 else-1 b=abs(k)**0.2 if int(b)**5==abs(k): print(a,c*abs(int(b))) return a+=1 if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var readline : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var x : int := ("" + ((readline().rstrip())))->toInteger() ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{0,0,1} ; while a < 1000 do ( var k : double := (a)->pow(5) - x ; var c : int := if k >= 0 then 1 else -1 endif ; var b : double := ((k)->abs())->pow(0.2) ; if (("" + ((b)))->toInteger())->pow(5) = (k)->abs() then ( execute (a)->display() ; return ) else skip ; a := a + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools import numpy as np X=int(input()) maxs=int(X**(1/5)) l=np.arange(-126,127) comb=np.array(list(itertools.combinations_with_replacement(l,2))) sum1=comb[:,0]**5-comb[:,1]**5 sum2=comb[:,1]**5-comb[:,0]**5 if len(np.where(sum1==X)[0])!=0 : result1=np.where(sum1==X)[0][0] print(comb[result1][0],comb[result1][1]) else : result2=np.where(sum2==X)[0][0] print(comb[result2][1],comb[result2][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var X : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var maxs : int := ("" + (((X)->pow((1 / 5)))))->toInteger() ; var l : Sequence := MathLib.numericRange(-126, 127, 1) ; var comb : Sequence := ((itertools.combinations_with_replacement(l, 2))) ; var sum1 : double := (comb->collect( _r | _r->first() ))->pow(5) - (comb->collect( _r | _r[1+1] ))->pow(5) ; var sum2 : double := (comb->collect( _r | _r[1+1] ))->pow(5) - (comb->collect( _r | _r->first() ))->pow(5) ; if (np.where(sum1 = X)->first())->size() /= 0 then ( var result1 : OclAny := np.where(sum1 = X)->first()->first() ; execute (comb[result1+1]->first())->display() ) else ( var result2 : OclAny := np.where(sum2 = X)->first()->first() ; execute (comb[result2+1][1+1])->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def main(args): while True : data=input().strip() if data[0]=='0' : break data=data[1 :] score_A=data.count('A') score_B=data.count('B') if score_A>score_B : score_A+=1 else : score_B+=1 print('{}{}'.format(score_A,score_B)) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation main(args : OclAny) pre: true post: true activity: while true do ( var data : OclAny := input()->trim() ; if data->first() = '0' then ( break ) else skip ; data := data->tail() ; var score_A : int := data->count('A') ; var score_B : int := data->count('B') ; if (score_A->compareTo(score_B)) > 0 then ( score_A := score_A + 1 ) else ( score_B := score_B + 1 ) ; execute (StringLib.interpolateStrings('{}{}', Sequence{score_A, score_B}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect x=int(input()) T=[0]*((10**4)+1) for i in range(0,(10**4)+1): T[i]=i**5 for i in range(len(T)): index=bisect.bisect_left(T,x+T[i]) if index==len(T): break if T[index]==x+T[i]: print(' '.join(map(str,[index,i]))) exit(0) for i in range(len(T)): index=bisect.bisect_left(T,x-T[i]) if index==len(T): break if T[index]==x-T[i]: print(' '.join(map(str,[index,-i]))) exit(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var T : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (((10)->pow(4)) + 1)) ; for i : Integer.subrange(0, ((10)->pow(4)) + 1-1) do ( T[i+1] := (i)->pow(5)) ; for i : Integer.subrange(0, (T)->size()-1) do ( var index : OclAny := bisect.bisect_left(T, x + T[i+1]) ; if index = (T)->size() then ( break ) else skip ; if T[index+1] = x + T[i+1] then ( execute (StringLib.sumStringsWithSeparator(((Sequence{index}->union(Sequence{ i }))->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ; exit(0) ) else skip) ; for i : Integer.subrange(0, (T)->size()-1) do ( index := bisect.bisect_left(T, x - T[i+1]) ; if index = (T)->size() then ( break ) else skip ; if T[index+1] = x - T[i+1] then ( execute (StringLib.sumStringsWithSeparator(((Sequence{index}->union(Sequence{ -i }))->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ; exit(0) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def findNumbers(arr,n): sumN=(n*(n+1))/2 ; sumSqN=(n*(n+1)*(2*n+1))/6 ; sum=0 ; sumSq=0 ; for i in range(0,n): sum=sum+arr[i]; sumSq=sumSq+(math.pow(arr[i],2)); B=(((sumSq-sumSqN)/(sum-sumN))+sumN-sum)/2 ; A=sum-sumN+B ; print("A=",int(A)); print("B=",int(B)); arr=[1,2,2,3,4]; n=len(arr); findNumbers(arr,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })))); ; n := (arr)->size(); ; findNumbers(arr, n);; operation findNumbers(arr : OclAny, n : OclAny) pre: true post: true activity: var sumN : double := (n * (n + 1)) / 2; ; var sumSqN : double := (n * (n + 1) * (2 * n + 1)) / 6; ; var sum : int := 0; ; var sumSq : int := 0; ; for i : Integer.subrange(0, n-1) do ( sum := sum + arr[i+1]; ; sumSq := sumSq + ((arr[i+1])->pow(2));) ; var B : double := (((sumSq - sumSqN) / (sum - sumN)) + sumN - sum) / 2; ; var A : double := sum - sumN + B; ; execute ("A=")->display(); ; execute ("B=")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) for i in range(a): n,k=map(int,input().split()) str=input() b=True for j in range(n//2): if str[j]!=str[n-1-j]: b=False break if b : print(1) else : if k==0 : print(1) else : print(2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, a-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var OclType["String"] : String := (OclFile["System.in"]).readLine() ; var b : boolean := true ; for j : Integer.subrange(0, n div 2-1) do ( if ("" + ([j+1])) /= ("" + ([n - 1 - j+1])) then ( b := false ; break ) else skip) ; if b then ( execute (1)->display() ) else ( if k = 0 then ( execute (1)->display() ) else ( execute (2)->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- iter=int(input()) for _ in range(iter): n,k=list(map(int,input().split(' '))) s=input() ans=0 if(s==s[: :-1]): ans=1 else : ans=2 if(k==0): ans=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var iter : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, iter-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var s : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; if (s = s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) then ( ans := 1 ) else ( ans := 2 ) ; if (k = 0) then ( ans := 1 ) else skip ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) s=input() if k==0 : print(1) else : if s==s[: :-1]: print(1) else : print(2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; if k = 0 then ( execute (1)->display() ) else ( if s = s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( execute (1)->display() ) else ( execute (2)->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=list(map(int,input().split())) M=2**N ans=[0]*M max_list=[0]*M for i in range(1,M): cand=[i] ans_cand=[] ibin=bin(i)[2 :].zfill(N) for j in range(N): if ibin[j]=='1' : cand.append(max_list[i-2**(N-j-1)]) ans_cand.append(ans[i-2**(N-j-1)]) cand_set=sorted(list(set(cand))) max1=0 max2=0 for c in cand_set : Ac=A[c] if Ac>=max1 : max2=max1 max1=Ac max_idx=c elif Ac>max2 : max2=Ac ans_cand.append(max1+max2) ans_cand.append(ans[i-1]) max_list[i]=max_idx ans[i]=max(ans_cand) print(ans[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var M : double := (2)->pow(N) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, M) ; var max_list : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, M) ; for i : Integer.subrange(1, M-1) do ( var cand : Sequence := Sequence{ i } ; var ans_cand : Sequence := Sequence{} ; var ibin : OclAny := bin(i).subrange(2+1).zfill(N) ; for j : Integer.subrange(0, N-1) do ( if ibin[j+1] = '1' then ( execute ((max_list[i - (2)->pow((N - j - 1))+1]) : cand) ; execute ((ans[i - (2)->pow((N - j - 1))+1]) : ans_cand) ) else skip) ; var cand_set : Sequence := (Set{}->union((cand)))->sort() ; var max1 : int := 0 ; var max2 : int := 0 ; for c : cand_set do ( var Ac : OclAny := A[c+1] ; if (Ac->compareTo(max1)) >= 0 then ( max2 := max1 ; max1 := Ac ; var max_idx : OclAny := c ) else (if (Ac->compareTo(max2)) > 0 then ( max2 := Ac ) else skip)) ; execute ((max1 + max2) : ans_cand) ; execute ((ans[i - 1+1]) : ans_cand) ; max_list[i+1] := max_idx ; ans[i+1] := (ans_cand)->max() ; execute (ans[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input exec(int(I())*"k=I()[-2:];s=I();print(2-(s==s[::-1]or' 1'>k));") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name I)) (trailer (arguments ( ))))))))) )))) * (expr (atom "k=I()[-2:];s=I();print(2-(s==s[::-1]or' 1'>k));"))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): DIGITS=100 increasing=eulerlib.binomial(DIGITS+9,9)-1 decreasing=eulerlib.binomial(DIGITS+10,10)-(DIGITS+1) flat=DIGITS*9 ans=increasing+decreasing-flat return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var DIGITS : int := 100 ; var increasing : double := eulerlib.binomial(DIGITS + 9, 9) - 1 ; var decreasing : double := eulerlib.binomial(DIGITS + 10, 10) - (DIGITS + 1) ; var flat : int := DIGITS * 9 ; var ans : double := increasing + decreasing - flat ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def maxSum(arr1,arr2,n): initialParity,finalParity=0,0 sum=0 minPositive=sys.maxsize maxNegative=-sys.maxsize-1 for i in range(n): initialParity+=arr2[i]; if(arr1[i]>=0): finalParity+=1 sum+=arr1[i] minPositive=min(minPositive,arr1[i]) else : maxNegative=max(maxNegative,arr1[i]) if(initialParity % 2==finalParity % 2): return sum else : if(minPositive+maxNegative>=0): return sum+maxNegative else : return sum-minPositive arr1=[2,-4,5,3] arr2=[0,1,0,1] n=len(arr1) print(maxSum(arr1,arr2,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr1 := Sequence{2}->union(Sequence{-4}->union(Sequence{5}->union(Sequence{ 3 }))) ; arr2 := Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 1 }))) ; n := (arr1)->size() ; execute (maxSum(arr1, arr2, n))->display(); operation maxSum(arr1 : OclAny, arr2 : OclAny, n : OclAny) : OclAny pre: true post: true activity: var initialParity : OclAny := null; var finalParity : OclAny := null; Sequence{initialParity,finalParity} := Sequence{0,0} ; var sum : int := 0 ; var minPositive : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; var maxNegative : double := -(trailer . (name maxsize)) - 1 ; for i : Integer.subrange(0, n-1) do ( initialParity := initialParity + arr2[i+1]; ; if (arr1[i+1] >= 0) then ( finalParity := finalParity + 1 ; sum := sum + arr1[i+1] ; minPositive := Set{minPositive, arr1[i+1]}->min() ) else ( maxNegative := Set{maxNegative, arr1[i+1]}->max() )) ; if (initialParity mod 2 = finalParity mod 2) then ( return sum ) else ( if (minPositive + maxNegative >= 0) then ( return sum + maxNegative ) else ( return sum - minPositive ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k,t=map(int,input().split()) wasted,wanted=[],[] dic={1 : "Carrots",2 : "Kiwis",0 : "Grapes"} for i in range(k+t): if k : a,b=map(int,input().split()) wasted.append([a,b]); k-=1 else : i,j=map(int,input().split()) wanted.append([i,j]) shift=0 ; wasted.sort() for cell in wanted : if cell in wasted : print("Waste") else : for ele in wasted : if ele[0]collect( _x | (OclType["int"])->apply(_x) ) ; var wasted : OclAny := null; var wanted : OclAny := null; Sequence{wasted,wanted} := Sequence{Sequence{},Sequence{}} ; var dic : Map := Map{ 1 |-> "Carrots" }->union(Map{ 2 |-> "Kiwis" }->union(Map{ 0 |-> "Grapes" })) ; for i : Integer.subrange(0, k + t-1) do ( if k then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a}->union(Sequence{ b })) : wasted); k := k - 1 ) else ( var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{i}->union(Sequence{ j })) : wanted) )) ; var shift : int := 0; wasted := wasted->sort() ; for cell : wanted do ( if (wasted)->includes(cell) then ( execute ("Waste")->display() ) else ( for ele : wasted do ( if (ele->first()->compareTo(cell->first())) < 0 then ( shift := shift + 1 ) else (if ele->first() = cell->first() & (ele[1+1]->compareTo(cell[1+1])) < 0 then ( shift := shift + 1 ) else ( break ) ) ) ; execute (dic[(cell[1+1] + ((cell->first() - 1) * m) - shift) mod 3+1])->display() ; shift := 0 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def indexedSequentialSearch(arr,n,k): elements=[0]*20 indices=[0]*20 j,ind=0,0 for i in range(0,n,3): elements[ind]=arr[i] indices[ind]=i ind+=1 if kunion(Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{ 10 })))) ; n := (arr)->size() ; k := 8 ; indexedSequentialSearch(arr, n, k) ) else skip; operation indexedSequentialSearch(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var elements : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 20) ; var indices : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 20) ; var j : OclAny := null; var ind : OclAny := null; Sequence{j,ind} := Sequence{0,0} ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 3 = 0 ) do ( elements[ind+1] := arr[i+1] ; indices[ind+1] := i ; ind := ind + 1) ; if (k->compareTo(elements->first())) < 0 then ( execute ("Not found")->display() ; exit(0) ) else ( for i : Integer.subrange(1, ind + 1-1) do ( if (k->compareTo(elements[i+1])) < 0 then ( var start : OclAny := indices[i - 1+1] ; var end : OclAny := indices[i+1] ; break ) else skip) ) ; for i : Integer.subrange(start, end + 1-1) do ( if k = arr[i+1] then ( var j : int := 1 ; break ) else skip) ; if j = 1 then ( execute ("Found at index")->display() ) else ( execute ("Not found")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- FRUITS=['Carrots','Kiwis','Grapes'] rn,cn,wn,qn=map(int,input().split()) waste_locations=[] for _ in range(wn): r,c=map(int,input().split()) order=(r-1)*cn+c-1 waste_locations.append(order) for _ in range(qn): r,c=map(int,input().split()) fruit_order=(r-1)*cn+c-1 if fruit_order in waste_locations : print("Waste") else : previous_waste=0 for location in waste_locations : if locationunion(Sequence{'Kiwis'}->union(Sequence{ 'Grapes' })) ; var rn : OclAny := null; var cn : OclAny := null; var wn : OclAny := null; var qn : OclAny := null; Sequence{rn,cn,wn,qn} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var waste_locations : Sequence := Sequence{} ; for _anon : Integer.subrange(0, wn-1) do ( var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var order : double := (r - 1) * cn + c - 1 ; execute ((order) : waste_locations)) ; for _anon : Integer.subrange(0, qn-1) do ( var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var fruit_order : double := (r - 1) * cn + c - 1 ; if (waste_locations)->includes(fruit_order) then ( execute ("Waste")->display() ) else ( var previous_waste : int := 0 ; for location : waste_locations do ( if (location->compareTo(fruit_order)) < 0 then ( previous_waste := previous_waste + 1 ) else skip) ; execute (FRUITS[(fruit_order - previous_waste) mod 3+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- FRUITS=['Carrots','Kiwis','Grapes'] rn,cn,wn,qn=map(int,input().split()) waste_locations=[] for _ in range(wn): r,c=map(int,input().split()) waste_location=(r-1)*cn+c-1 waste_locations.append(waste_location) for _ in range(qn): r,c=map(int,input().split()) fruit_location=(r-1)*cn+c-1 if fruit_location not in waste_locations : previous_waste=len([1 for loc in waste_locations if locunion(Sequence{'Kiwis'}->union(Sequence{ 'Grapes' })) ; var rn : OclAny := null; var cn : OclAny := null; var wn : OclAny := null; var qn : OclAny := null; Sequence{rn,cn,wn,qn} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var waste_locations : Sequence := Sequence{} ; for _anon : Integer.subrange(0, wn-1) do ( var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var waste_location : double := (r - 1) * cn + c - 1 ; execute ((waste_location) : waste_locations)) ; for _anon : Integer.subrange(0, qn-1) do ( var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var fruit_location : double := (r - 1) * cn + c - 1 ; if (waste_locations)->excludes(fruit_location) then ( var previous_waste : int := (waste_locations->select(loc | (loc->compareTo(fruit_location)) < 0)->collect(loc | (1)))->size() ; execute (FRUITS[(fruit_location - previous_waste) mod 3+1])->display() ) else ( execute ("Waste")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k,t=map(int,input().split()) waste=[] plants=["Carrots","Kiwis","Grapes"] for i in range(k): a,b=map(int,input().split()) waste.append([a,b]) waste=sorted(waste) for i in range(t): y_cord,x_cord=map(int,input().split()) displacement=0 prev=-1 if[y_cord,x_cord]in waste : print("Waste") else : for j in waste : if(j[1]>x_cord and j[0]==y_cord)or(j[0]>y_cord): break displacement+=1 prev=j[1] value=(y_cord-1)*(m)+x_cord value-=displacement print(plants[(value-1)% 3]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; var t : OclAny := null; Sequence{n,m,k,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var waste : Sequence := Sequence{} ; var plants : Sequence := Sequence{"Carrots"}->union(Sequence{"Kiwis"}->union(Sequence{ "Grapes" })) ; for i : Integer.subrange(0, k-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a}->union(Sequence{ b })) : waste)) ; waste := waste->sort() ; for i : Integer.subrange(0, t-1) do ( var y_cord : OclAny := null; var x_cord : OclAny := null; Sequence{y_cord,x_cord} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var displacement : int := 0 ; var prev : int := -1 ; if (waste)->includes(Sequence{y_cord}->union(Sequence{ x_cord })) then ( execute ("Waste")->display() ) else ( for j : waste do ( if ((j[1+1]->compareTo(x_cord)) > 0 & j->first() = y_cord) or ((j->first()->compareTo(y_cord)) > 0) then ( break ) else skip ; displacement := displacement + 1 ; prev := j[1+1]) ; var value : double := (y_cord - 1) * (m) + x_cord ; value := value - displacement ; execute (plants[(value - 1) mod 3+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- L={"" : "101","'" : "000000","," : "000011","-" : "10010001","." : "010001","?" : "000001","A" : "100101","B" : "10011010","C" : "0101","D" : "0001","E" : "110","F" : "01001","G" : "10011011","H" : "010000","I" : "0111","J" : "10011000","K" : "0110","L" : "00100","M" : "10011001","N" : "10011110","O" : "00101","P" : "111","Q" : "10011111","R" : "1000","S" : "00110","T" : "00111","U" : "10011100","V" : "10011101","W" : "000010","X" : "10010010","Y" : "10010011","Z" : "10010000"} M={"00000" : "A","00001" : "B","00010" : "C","00011" : "D","00100" : "E","00101" : "F","00110" : "G","00111" : "H","01000" : "I","01001" : "J","01010" : "K","01011" : "L","01100" : "M","01101" : "N","01110" : "O","01111" : "P","10000" : "Q","10001" : "R","10010" : "S","10011" : "T","10100" : "U","10101" : "V","10110" : "W","10111" : "X","11000" : "Y","11001" : "Z","11010" : "","11011" : ".","11100" : ",","11101" : "-","11110" : "'","11111" : "?"} while True : try : s=input() except : break t="" for i in s : t+=L[i] t+="0"*((-len(t))% 5) o="" for i in range(len(t)//5): u=t[i*5 : i*5+5] o+=M[u] print(o) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var L : Map := Map{ "" |-> "101" }->union(Map{ "'" |-> "000000" }->union(Map{ "," |-> "000011" }->union(Map{ "-" |-> "10010001" }->union(Map{ "." |-> "010001" }->union(Map{ "?" |-> "000001" }->union(Map{ "A" |-> "100101" }->union(Map{ "B" |-> "10011010" }->union(Map{ "C" |-> "0101" }->union(Map{ "D" |-> "0001" }->union(Map{ "E" |-> "110" }->union(Map{ "F" |-> "01001" }->union(Map{ "G" |-> "10011011" }->union(Map{ "H" |-> "010000" }->union(Map{ "I" |-> "0111" }->union(Map{ "J" |-> "10011000" }->union(Map{ "K" |-> "0110" }->union(Map{ "L" |-> "00100" }->union(Map{ "M" |-> "10011001" }->union(Map{ "N" |-> "10011110" }->union(Map{ "O" |-> "00101" }->union(Map{ "P" |-> "111" }->union(Map{ "Q" |-> "10011111" }->union(Map{ "R" |-> "1000" }->union(Map{ "S" |-> "00110" }->union(Map{ "T" |-> "00111" }->union(Map{ "U" |-> "10011100" }->union(Map{ "V" |-> "10011101" }->union(Map{ "W" |-> "000010" }->union(Map{ "X" |-> "10010010" }->union(Map{ "Y" |-> "10010011" }->union(Map{ "Z" |-> "10010000" }))))))))))))))))))))))))))))))) ; var M : Map := Map{ "00000" |-> "A" }->union(Map{ "00001" |-> "B" }->union(Map{ "00010" |-> "C" }->union(Map{ "00011" |-> "D" }->union(Map{ "00100" |-> "E" }->union(Map{ "00101" |-> "F" }->union(Map{ "00110" |-> "G" }->union(Map{ "00111" |-> "H" }->union(Map{ "01000" |-> "I" }->union(Map{ "01001" |-> "J" }->union(Map{ "01010" |-> "K" }->union(Map{ "01011" |-> "L" }->union(Map{ "01100" |-> "M" }->union(Map{ "01101" |-> "N" }->union(Map{ "01110" |-> "O" }->union(Map{ "01111" |-> "P" }->union(Map{ "10000" |-> "Q" }->union(Map{ "10001" |-> "R" }->union(Map{ "10010" |-> "S" }->union(Map{ "10011" |-> "T" }->union(Map{ "10100" |-> "U" }->union(Map{ "10101" |-> "V" }->union(Map{ "10110" |-> "W" }->union(Map{ "10111" |-> "X" }->union(Map{ "11000" |-> "Y" }->union(Map{ "11001" |-> "Z" }->union(Map{ "11010" |-> "" }->union(Map{ "11011" |-> "." }->union(Map{ "11100" |-> "," }->union(Map{ "11101" |-> "-" }->union(Map{ "11110" |-> "'" }->union(Map{ "11111" |-> "?" }))))))))))))))))))))))))))))))) ; while true do ( try ( var s : String := (OclFile["System.in"]).readLine()) catch (_e : OclException) do ( break) ; var t : String := "" ; for i : s->characters() do ( t := t + L[i+1]) ; t := t + StringLib.nCopies("0", ((-(t)->size()) mod 5)) ; var o : String := "" ; for i : Integer.subrange(0, (t)->size() div 5-1) do ( var u : OclAny := t.subrange(i * 5+1, i * 5 + 5) ; o := o + M[u+1]) ; execute (o)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import(division,absolute_import,print_function,unicode_literals) from sys import stdin import io d1={'' : '101',"'" : '000000',',' : '000011','-' : '10010001','.' : '010001','?' : '000001','A' : '100101','B' : '10011010','C' : '0101','D' : '0001','E' : '110','F' : '01001','G' : '10011011','H' : '010000','I' : '0111','J' : '10011000','K' : '0110','L' : '00100','M' : '10011001','N' : '10011110','O' : '00101','P' : '111','Q' : '10011111','R' : '1000','S' : '00110','T' : '00111','U' : '10011100','V' : '10011101','W' : '000010','X' : '10010010','Y' : '10010011','Z' : '10010000'} d2={n : chr(n+ord('A'))for n in range(26)} d2.update(zip(range(26,32),".,-'?")) for line in stdin : stream=io.StringIO() stream.write(''.join(d1[c]for c in line.rstrip('\n'))) stream.seek(0) c=stream.read(5) while c : print(d2[int(c.ljust(5,'0'),2)],end='') c=stream.read(5) print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var d1 : Map := Map{ '' |-> '101' }->union(Map{ "'" |-> '000000' }->union(Map{ ',' |-> '000011' }->union(Map{ '-' |-> '10010001' }->union(Map{ '.' |-> '010001' }->union(Map{ '?' |-> '000001' }->union(Map{ 'A' |-> '100101' }->union(Map{ 'B' |-> '10011010' }->union(Map{ 'C' |-> '0101' }->union(Map{ 'D' |-> '0001' }->union(Map{ 'E' |-> '110' }->union(Map{ 'F' |-> '01001' }->union(Map{ 'G' |-> '10011011' }->union(Map{ 'H' |-> '010000' }->union(Map{ 'I' |-> '0111' }->union(Map{ 'J' |-> '10011000' }->union(Map{ 'K' |-> '0110' }->union(Map{ 'L' |-> '00100' }->union(Map{ 'M' |-> '10011001' }->union(Map{ 'N' |-> '10011110' }->union(Map{ 'O' |-> '00101' }->union(Map{ 'P' |-> '111' }->union(Map{ 'Q' |-> '10011111' }->union(Map{ 'R' |-> '1000' }->union(Map{ 'S' |-> '00110' }->union(Map{ 'T' |-> '00111' }->union(Map{ 'U' |-> '10011100' }->union(Map{ 'V' |-> '10011101' }->union(Map{ 'W' |-> '000010' }->union(Map{ 'X' |-> '10010010' }->union(Map{ 'Y' |-> '10010011' }->union(Map{ 'Z' |-> '10010000' }))))))))))))))))))))))))))))))) ; var d2 : Map := Integer.subrange(0, 26-1)->select(n | true)->collect(n | Map{n |-> (n + ('A')->char2byte())->byte2char()})->unionAll() ; execute ((Integer.subrange(1, Integer.subrange(26, 32-1)->size())->collect( _indx | Sequence{Integer.subrange(26, 32-1)->at(_indx), ".,-'?"->at(_indx)} )) <: d2) ; for line : stdin do ( var stream : OclAny := io.StringIO() ; stream.write(StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name d1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name c)))))))) ])))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name line)) (trailer . (name rstrip) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ' '))))))) ))))))))), '')) ; stream.setPosition(0) ; var c : String := stream.readAll() ; while c do ( execute (d2[("" + ((StringLib.padRightWithInto(c, '0', 5), 2)))->toInteger()+1])->display() ; c := stream.readAll()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : try : s=input() s_r="" c1=["","'",",","-",".","?","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"] c2=["101","000000","000011","10010001","010001","000001","100101","10011010","0101","0001","110","01001","10011011","010000","0111","10011000","0110","00100","10011001","10011110","00101","111","10011111","1000","00110","00111","10011100","10011101","000010","10010010","10010011","10010000"] c3=["",".",",","-","'","?"] for i in s : s_r+=c2[c1.index(i)] while len(s_r)% 5>0 : s_r+="0" ans="" for i in range(len(s_r)//5): s_r_n=int(s_r[: 5],2) if s_r_n<26 : ans+=chr(65+s_r_n) else : ans+=c3[s_r_n-26] s_r=s_r[5 :] print(ans) except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( try ( var s : String := (OclFile["System.in"]).readLine() ; var s_r : String := "" ; var c1 : Sequence := Sequence{""}->union(Sequence{"'"}->union(Sequence{","}->union(Sequence{"-"}->union(Sequence{"."}->union(Sequence{"?"}->union(Sequence{"A"}->union(Sequence{"B"}->union(Sequence{"C"}->union(Sequence{"D"}->union(Sequence{"E"}->union(Sequence{"F"}->union(Sequence{"G"}->union(Sequence{"H"}->union(Sequence{"I"}->union(Sequence{"J"}->union(Sequence{"K"}->union(Sequence{"L"}->union(Sequence{"M"}->union(Sequence{"N"}->union(Sequence{"O"}->union(Sequence{"P"}->union(Sequence{"Q"}->union(Sequence{"R"}->union(Sequence{"S"}->union(Sequence{"T"}->union(Sequence{"U"}->union(Sequence{"V"}->union(Sequence{"W"}->union(Sequence{"X"}->union(Sequence{"Y"}->union(Sequence{ "Z" }))))))))))))))))))))))))))))))) ; var c2 : Sequence := Sequence{"101"}->union(Sequence{"000000"}->union(Sequence{"000011"}->union(Sequence{"10010001"}->union(Sequence{"010001"}->union(Sequence{"000001"}->union(Sequence{"100101"}->union(Sequence{"10011010"}->union(Sequence{"0101"}->union(Sequence{"0001"}->union(Sequence{"110"}->union(Sequence{"01001"}->union(Sequence{"10011011"}->union(Sequence{"010000"}->union(Sequence{"0111"}->union(Sequence{"10011000"}->union(Sequence{"0110"}->union(Sequence{"00100"}->union(Sequence{"10011001"}->union(Sequence{"10011110"}->union(Sequence{"00101"}->union(Sequence{"111"}->union(Sequence{"10011111"}->union(Sequence{"1000"}->union(Sequence{"00110"}->union(Sequence{"00111"}->union(Sequence{"10011100"}->union(Sequence{"10011101"}->union(Sequence{"000010"}->union(Sequence{"10010010"}->union(Sequence{"10010011"}->union(Sequence{ "10010000" }))))))))))))))))))))))))))))))) ; var c3 : Sequence := Sequence{""}->union(Sequence{"."}->union(Sequence{","}->union(Sequence{"-"}->union(Sequence{"'"}->union(Sequence{ "?" }))))) ; for i : s->characters() do ( s_r := s_r + c2[c1->indexOf(i) - 1+1]) ; while (s_r)->size() mod 5 > 0 do ( s_r := s_r + "0") ; var ans : String := "" ; for i : Integer.subrange(0, (s_r)->size() div 5-1) do ( var s_r_n : int := ("" + ((s_r.subrange(1,5), 2)))->toInteger() ; if s_r_n < 26 then ( ans := ans + (65 + s_r_n)->byte2char() ) else ( ans := ans + c3[s_r_n - 26+1] ) ; s_r := s_r.subrange(5+1)) ; execute (ans)->display()) catch (_e : OclException) do ( break) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def merge(x,y,z,w): P=[x,y,z,w] P.sort() return P[-1],P[-2] def main(): N=int(input()) a=list(map(int,input().split())) dp=[0]*(2*(N+1)*((1<union(Sequence{y}->union(Sequence{z}->union(Sequence{ w }))) ; P := P->sort() ; return P->last(), P->front()->last(); operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * (N + 1) * ((1 * (2->pow(N)))))) ; skip ; for i : Integer.subrange(0, 1 * (2->pow(N))-1) do ( dp[calc(i, 0, 0)+1] := a[i+1]) ; for j : Integer.subrange(1, N + 1-1) do ( for i : Integer.subrange(0, 1 * (2->pow(N))-1) do ( x := calc(i, j, 0) ; y := calc(MathLib.bitwiseAnd(i, MathLib.bitwiseNot((1 * (2->pow((j - 1)))))), j - 1, 0) ; if (MathLib.bitwiseAnd(i, (1 * (2->pow((j - 1)))))) then ( var dp[x+1] : OclAny := null; var dp[x + N + 1+1] : OclAny := null; Sequence{dp[x+1],dp[x + N + 1+1]} := merge(dp[y+1], dp[y + N + 1+1], dp[x - 1+1], dp[x + N+1]) ) else ( var dp[x+1] : OclAny := null; var dp[x + N + 1+1] : OclAny := null; Sequence{dp[x+1],dp[x + N + 1+1]} := Sequence{dp[x - 1+1],dp[x + N+1]} ))) ; var result : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (1 * (2->pow(N)))) ; for k : Integer.subrange(1, 1 * (2->pow(N))-1) do ( result[k+1] := Set{result[k - 1+1], dp[calc(k, N, 0)+1] + dp[calc(k, N, 1)+1]}->max() ; execute (result[k+1])->display()) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def main(args): encoder={'' : '101',"'" : '000000',',' : '000011','-' : '10010001','.' : '010001','?' : '000001','A' : '100101','B' : '10011010','C' : '0101','D' : '0001','E' : '110','F' : '01001','G' : '10011011','H' : '010000','I' : '0111','J' : '10011000','K' : '0110','L' : '00100','M' : '10011001','N' : '10011110','O' : '00101','P' : '111','Q' : '10011111','R' : '1000','S' : '00110','T' : '00111','U' : '10011100','V' : '10011101','W' : '000010','X' : '10010010','Y' : '10010011','Z' : '10010000'} decoder={'00000' : 'A','00001' : 'B','00010' : 'C','00011' : 'D','00100' : 'E','00101' : 'F','00110' : 'G','00111' : 'H','01000' : 'I','01001' : 'J','01010' : 'K','01011' : 'L','01100' : 'M','01101' : 'N','01110' : 'O','01111' : 'P','10000' : 'Q','10001' : 'R','10010' : 'S','10011' : 'T','10100' : 'U','10101' : 'V','10110' : 'W','10111' : 'X','11000' : 'Y','11001' : 'Z','11010' : '','11011' : '.','11100' : ',','11101' : '-','11110' : "'",'11111' : '?'} for line in sys.stdin : txt=line.strip('\n') ans='' for c in txt : ans+=encoder[c] if len(ans)% 5!=0 : ans+='0'*(5-len(ans)% 5) result='' while ans : temp=ans[: 5] result+=decoder[temp] ans=ans[5 :] print(result) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation main(args : OclAny) pre: true post: true activity: var encoder : Map := Map{ '' |-> '101' }->union(Map{ "'" |-> '000000' }->union(Map{ ',' |-> '000011' }->union(Map{ '-' |-> '10010001' }->union(Map{ '.' |-> '010001' }->union(Map{ '?' |-> '000001' }->union(Map{ 'A' |-> '100101' }->union(Map{ 'B' |-> '10011010' }->union(Map{ 'C' |-> '0101' }->union(Map{ 'D' |-> '0001' }->union(Map{ 'E' |-> '110' }->union(Map{ 'F' |-> '01001' }->union(Map{ 'G' |-> '10011011' }->union(Map{ 'H' |-> '010000' }->union(Map{ 'I' |-> '0111' }->union(Map{ 'J' |-> '10011000' }->union(Map{ 'K' |-> '0110' }->union(Map{ 'L' |-> '00100' }->union(Map{ 'M' |-> '10011001' }->union(Map{ 'N' |-> '10011110' }->union(Map{ 'O' |-> '00101' }->union(Map{ 'P' |-> '111' }->union(Map{ 'Q' |-> '10011111' }->union(Map{ 'R' |-> '1000' }->union(Map{ 'S' |-> '00110' }->union(Map{ 'T' |-> '00111' }->union(Map{ 'U' |-> '10011100' }->union(Map{ 'V' |-> '10011101' }->union(Map{ 'W' |-> '000010' }->union(Map{ 'X' |-> '10010010' }->union(Map{ 'Y' |-> '10010011' }->union(Map{ 'Z' |-> '10010000' }))))))))))))))))))))))))))))))) ; var decoder : Map := Map{ '00000' |-> 'A' }->union(Map{ '00001' |-> 'B' }->union(Map{ '00010' |-> 'C' }->union(Map{ '00011' |-> 'D' }->union(Map{ '00100' |-> 'E' }->union(Map{ '00101' |-> 'F' }->union(Map{ '00110' |-> 'G' }->union(Map{ '00111' |-> 'H' }->union(Map{ '01000' |-> 'I' }->union(Map{ '01001' |-> 'J' }->union(Map{ '01010' |-> 'K' }->union(Map{ '01011' |-> 'L' }->union(Map{ '01100' |-> 'M' }->union(Map{ '01101' |-> 'N' }->union(Map{ '01110' |-> 'O' }->union(Map{ '01111' |-> 'P' }->union(Map{ '10000' |-> 'Q' }->union(Map{ '10001' |-> 'R' }->union(Map{ '10010' |-> 'S' }->union(Map{ '10011' |-> 'T' }->union(Map{ '10100' |-> 'U' }->union(Map{ '10101' |-> 'V' }->union(Map{ '10110' |-> 'W' }->union(Map{ '10111' |-> 'X' }->union(Map{ '11000' |-> 'Y' }->union(Map{ '11001' |-> 'Z' }->union(Map{ '11010' |-> '' }->union(Map{ '11011' |-> '.' }->union(Map{ '11100' |-> ',' }->union(Map{ '11101' |-> '-' }->union(Map{ '11110' |-> "'" }->union(Map{ '11111' |-> '?' }))))))))))))))))))))))))))))))) ; for line : OclFile["System.in"] do ( var txt : String := line->trim() ; var ans : String := '' ; for c : txt->characters() do ( ans := ans + encoder[c+1]) ; if (ans)->size() mod 5 /= 0 then ( ans := ans + StringLib.nCopies('0', (5 - (ans)->size() mod 5)) ) else skip ; var result : String := '' ; while ans do ( var temp : OclAny := ans.subrange(1,5) ; result := result + decoder[temp+1] ; ans := ans.subrange(5+1)) ; execute (result)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- chA={'' : '101',"'" : '000000',',' : '000011','-' : '10010001','.' : '010001','?' : '000001','A' : '100101','B' : '10011010','C' : '0101','D' : '0001','E' : '110','F' : '01001','G' : '10011011','H' : '010000','I' : '0111','J' : '10011000','K' : '0110','L' : '00100','M' : '10011001','N' : '10011110','O' : '00101','P' : '111','Q' : '10011111','R' : '1000','S' : '00110','T' : '00111','U' : '10011100','V' : '10011101','W' : '000010','X' : '10010010','Y' : '10010011','Z' : '10010000'} chB={'00000' : 'A','00001' : 'B','00010' : 'C','00011' : 'D','00100' : 'E','00101' : 'F','00110' : 'G','00111' : 'H','01000' : 'I','01001' : 'J','01010' : 'K','01011' : 'L','01100' : 'M','01101' : 'N','01110' : 'O','01111' : 'P','10000' : 'Q','10001' : 'R','10010' : 'S','10011' : 'T','10100' : 'U','10101' : 'V','10110' : 'W','10111' : 'X','11000' : 'Y','11001' : 'Z','11010' : '','11011' : '.','11100' : ',','11101' : '-','11110' : "'",'11111' : '?'} while True : try : s=input() except EOFError : break chlst='' numlst=[] anslst='' for i in s : if i=='\\' : chlst=chlst+chA[''] else : chlst=chlst+chA[i] if len(chlst)% 5!=0 : for k in range(5-(len(chlst)% 5)): chlst+='0' for j in range(len(chlst)//5): numlst.append(chlst[5*j : 5*j+5]) for l in numlst : anslst=anslst+chB[l] print(anslst) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var chA : Map := Map{ '' |-> '101' }->union(Map{ "'" |-> '000000' }->union(Map{ ',' |-> '000011' }->union(Map{ '-' |-> '10010001' }->union(Map{ '.' |-> '010001' }->union(Map{ '?' |-> '000001' }->union(Map{ 'A' |-> '100101' }->union(Map{ 'B' |-> '10011010' }->union(Map{ 'C' |-> '0101' }->union(Map{ 'D' |-> '0001' }->union(Map{ 'E' |-> '110' }->union(Map{ 'F' |-> '01001' }->union(Map{ 'G' |-> '10011011' }->union(Map{ 'H' |-> '010000' }->union(Map{ 'I' |-> '0111' }->union(Map{ 'J' |-> '10011000' }->union(Map{ 'K' |-> '0110' }->union(Map{ 'L' |-> '00100' }->union(Map{ 'M' |-> '10011001' }->union(Map{ 'N' |-> '10011110' }->union(Map{ 'O' |-> '00101' }->union(Map{ 'P' |-> '111' }->union(Map{ 'Q' |-> '10011111' }->union(Map{ 'R' |-> '1000' }->union(Map{ 'S' |-> '00110' }->union(Map{ 'T' |-> '00111' }->union(Map{ 'U' |-> '10011100' }->union(Map{ 'V' |-> '10011101' }->union(Map{ 'W' |-> '000010' }->union(Map{ 'X' |-> '10010010' }->union(Map{ 'Y' |-> '10010011' }->union(Map{ 'Z' |-> '10010000' }))))))))))))))))))))))))))))))) ; var chB : Map := Map{ '00000' |-> 'A' }->union(Map{ '00001' |-> 'B' }->union(Map{ '00010' |-> 'C' }->union(Map{ '00011' |-> 'D' }->union(Map{ '00100' |-> 'E' }->union(Map{ '00101' |-> 'F' }->union(Map{ '00110' |-> 'G' }->union(Map{ '00111' |-> 'H' }->union(Map{ '01000' |-> 'I' }->union(Map{ '01001' |-> 'J' }->union(Map{ '01010' |-> 'K' }->union(Map{ '01011' |-> 'L' }->union(Map{ '01100' |-> 'M' }->union(Map{ '01101' |-> 'N' }->union(Map{ '01110' |-> 'O' }->union(Map{ '01111' |-> 'P' }->union(Map{ '10000' |-> 'Q' }->union(Map{ '10001' |-> 'R' }->union(Map{ '10010' |-> 'S' }->union(Map{ '10011' |-> 'T' }->union(Map{ '10100' |-> 'U' }->union(Map{ '10101' |-> 'V' }->union(Map{ '10110' |-> 'W' }->union(Map{ '10111' |-> 'X' }->union(Map{ '11000' |-> 'Y' }->union(Map{ '11001' |-> 'Z' }->union(Map{ '11010' |-> '' }->union(Map{ '11011' |-> '.' }->union(Map{ '11100' |-> ',' }->union(Map{ '11101' |-> '-' }->union(Map{ '11110' |-> "'" }->union(Map{ '11111' |-> '?' }))))))))))))))))))))))))))))))) ; while true do ( try ( var s : String := (OclFile["System.in"]).readLine()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))) ; var chlst : String := '' ; var numlst : Sequence := Sequence{} ; var anslst : String := '' ; for i : s->characters() do ( if i = '\\' then ( chlst := chlst + chA->at('') ) else ( chlst := chlst + chA[i+1] )) ; if (chlst)->size() mod 5 /= 0 then ( for k : Integer.subrange(0, 5 - ((chlst)->size() mod 5)-1) do ( chlst := chlst + '0') ) else skip ; for j : Integer.subrange(0, (chlst)->size() div 5-1) do ( execute ((chlst.subrange(5 * j+1, 5 * j + 5)) : numlst)) ; for l : numlst do ( anslst := anslst + chB[l+1]) ; execute (anslst)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) print(n) print(*[i for i in range(1,n+1)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) )))))))) ])))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def larrgestPalindrome(n): upper_limit=0 for i in range(1,n+1): upper_limit=upper_limit*10 upper_limit=upper_limit+9 lower_limit=1+upper_limit//10 max_product=0 for i in range(upper_limit,lower_limit-1,-1): for j in range(i,lower_limit-1,-1): product=i*j if(productmax_product): max_product=product return max_product n=2 print(larrgestPalindrome(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 2 ; execute (larrgestPalindrome(n))->display(); operation larrgestPalindrome(n : OclAny) : OclAny pre: true post: true activity: var upper_limit : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( upper_limit := upper_limit * 10 ; upper_limit := upper_limit + 9) ; var lower_limit : int := 1 + upper_limit div 10 ; var max_product : int := 0 ; for i : Integer.subrange(lower_limit - 1 + 1, upper_limit)->reverse() do ( for j : Integer.subrange(lower_limit - 1 + 1, i)->reverse() do ( var product : double := i * j ; if ((product->compareTo(max_product)) < 0) then ( break ) else skip ; var number : OclAny := product ; var reverse : int := 0 ; while (number /= 0) do ( reverse := reverse * 10 + number mod 10 ; number := number div 10) ; if (product = reverse & (product->compareTo(max_product)) > 0) then ( max_product := product ) else skip)) ; return max_product; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import* from math import* from decimal import* from collections import* import numbers from operator import index import sys def _input(): return map(int,input().split()) def _list(): return list(map(int,input().split())) def _int(): return int(input()) def solves(): n=int(input()) print(n) for i in range(1,n+1): print(i,end=' ') print() t=1 t=int(input()) for _ in range(0,t): solves() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var t : int := 1 ; t := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( solves()); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation _list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation _int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation solves() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n)->display() ; for i : Integer.subrange(1, n + 1-1) do ( execute (i)->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : t-=1 n=int(input()) print(n) a=[] for i in range(1,n+1): a.append(i) for i in a : print(i,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( t := t - 1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n)->display() ; var a : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( execute ((i) : a)) ; for i : a do ( execute (i)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : t-=1 n=int(input()) print(n) a=[] for i in range(1,n+1): a.append(i) for i in a[:-1]: print(i,end=' ') print(a[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( t := t - 1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n)->display() ; var a : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( execute ((i) : a)) ; for i : a->front() do ( execute (i)->display()) ; execute (a->last())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) res=(i+1 for i in range(n)) print(n) print(*res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))} ; execute (n)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Word : def __init__(self,word,cnt): self.word=word self.cnt=cnt def __lt__(self,other): if self.cnt==other.cnt : return self.wordother.cnt while True : N=int(input()) if N==0 : break str=[] for l in range(N): str.extend(input().split()) str.sort() k=input() words=[] for i in range(len(str)): if str[i][0]==k : if len(words)>0 and words[-1].word==str[i]: words[-1].cnt=words[-1].cnt+1 else : t=Word(str[i],1) words.append(t) if len(words)==0 : print("NA") elif len(words)<5 : words.sort() for i in range(len(words)-1): print(words[i].word,end=" ") print(words[-1].word) else : words.sort() for i in range(4): print(words[i].word,end=" ") print(words[4].word) ------------------------------------------------------------ OCL File: --------- class Word { static operation newWord() : Word pre: true post: Word->exists( _x | result = _x ); attribute word : OclAny := word; attribute cnt : OclAny := cnt; operation initialise(word : OclAny,cnt : OclAny) : Word pre: true post: true activity: self.word := word ; self.cnt := cnt; return self; operation __lt__(other : OclAny) : OclAny pre: true post: true activity: if self.cnt = other.cnt then ( return (self.word->compareTo(other.word)) < 0 ) else ( return (self.cnt->compareTo(other.cnt)) > 0 ); } class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var OclType["String"] : Sequence := Sequence{} ; for l : Integer.subrange(0, N-1) do ( OclType["String"] := OclType["String"]->union(input().split())) ; OclType["String"] := OclType["String"]->sort() ; var k : String := (OclFile["System.in"]).readLine() ; var words : Sequence := Sequence{} ; for i : Integer.subrange(0, (OclType["String"])->size()-1) do ( if OclType["String"][i+1]->first() = k then ( if (words)->size() > 0 & words->last().word = ("" + ([i+1])) then ( words->last().cnt := words->last().cnt + 1 ) else ( var t : Word := (Word.newWord()).initialise(("" + ([i+1])), 1) ; execute ((t) : words) ) ) else skip) ; if (words)->size() = 0 then ( execute ("NA")->display() ) else (if (words)->size() < 5 then ( words := words->sort() ; for i : Integer.subrange(0, (words)->size() - 1-1) do ( execute (words[i+1].word)->display()) ; execute (words->last().word)->display() ) else ( words := words->sort() ; for i : Integer.subrange(0, 4-1) do ( execute (words[i+1].word)->display()) ; execute (words[4+1].word)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy BIG_NUM=2000000000 HUGE_NUM=99999999999999999 MOD=1000000007 EPS=0.000000001 sys.setrecursionlimit(100000) class Info : def __init__(self,arg_word,arg_count): self.word=arg_word self.count=arg_count def __lt__(self,another): if self.count!=another.count : return self.count>another.count else : return self.wordexists( _x | result = _x ); attribute word : OclAny := arg_word; attribute count : OclAny := arg_count; operation initialise(arg_word : OclAny,arg_count : OclAny) : Info pre: true post: true activity: self.word := arg_word ; self.count := arg_count; return self; operation __lt__(another : OclAny) : OclAny pre: true post: true activity: if self.count /= another.count then ( return (self.count->compareTo(another.count)) > 0 ) else ( return (self.word->compareTo(another.word)) < 0 ); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var HUGE_NUM : int := 99999999999999999 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; sys.setrecursionlimit(100000) ; skip ; while true do ( var num_row : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if num_row = 0 then ( break ) else skip ; var DICT : OclAny := Set{} ; var rev_DICT : OclAny := Set{} ; var COUNT : OclAny := Set{} ; var num_words : int := 0 ; for _anon : Integer.subrange(0, num_row-1) do ( var words : OclAny := input().split() ; for i : Integer.subrange(0, (words)->size()-1) do ( if (DICT)->includes(words[i+1]) then ( COUNT[DICT[words[i+1]+1]+1] := COUNT[DICT[words[i+1]+1]+1] + 1 ) else ( DICT[words[i+1]+1] := num_words ; rev_DICT[num_words+1] := words[i+1] ; num_words := num_words + 1 ; COUNT[DICT[words[i+1]+1]+1] := 1 ))) ; var head_word : String := ("" + (((OclFile["System.in"]).readLine()))) ; var table : Sequence := Sequence{} ; for i : Integer.subrange(0, num_words-1) do ( var word : OclAny := rev_DICT[i+1] ; if word->first() /= head_word then ( continue ) else skip ; execute (((Info.newInfo()).initialise(word, COUNT[DICT[word+1]+1])) : table)) ; if (table)->size() = 0 then ( execute ("NA")->display() ; continue ) else skip ; table := table->sort() ; execute (StringLib.format("%s",(table->first().word)))->display() ; for i : Integer.subrange(1, Set{5, (table)->size()}->min()-1) do ( execute (StringLib.format(" %s",(table[i+1].word)))->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import string import operator from collections import Counter f=sys.stdin while True : n=int(f.readline()) if n==0 : break counters={c : Counter()for c in string.ascii_lowercase} for i in range(n): for word in f.readline().strip().split(): counters[word[0]].update([word]) c=f.readline().strip() candidate=counters[c].most_common() candidate.sort(key=operator.itemgetter(0)) candidate.sort(key=operator.itemgetter(1),reverse=True) candidate=[word for word,count in candidate[: 5]] if len(candidate)==0 : print('NA') else : print(*candidate) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var f : OclFile := OclFile["System.in"] ; while true do ( var n : int := ("" + ((f.readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var counters : Map := string.ascii_lowercase->select(c | true)->collect(c | Map{c |-> Counter()})->unionAll() ; for i : Integer.subrange(0, n-1) do ( for word : f.readLine()->trim().split() do ((expr (atom (name counters)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name word)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])) (trailer . (name update) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name word))))))) ]))))))) )))))) ; var c : OclAny := f.readLine()->trim() ; var candidate : OclAny := counters[c+1].most_common() ; candidate := candidate->sort() ; candidate := candidate->sort() ; candidate := candidate.subrange(1,5)->select(_tuple | true)->collect(_tuple | let word : OclAny = _tuple->at(1) in let count : OclAny = _tuple->at(2) in (word)) ; if (candidate)->size() = 0 then ( execute ('NA')->display() ) else ( execute ((argument * (test (logical_test (comparison (expr (atom (name candidate))))))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(i)for i in input().split()] dp=[[x,0]for x in range(0,len(a))] def ins(x,i): if x in dp[i]: return if dp[i][0]!=x and a[dp[i][0]]toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var dp : Sequence := Integer.subrange(0, (a)->size()-1)->select(x | true)->collect(x | (Sequence{x}->union(Sequence{ 0 }))) ; skip ; skip ; for i : Integer.subrange(0, (a)->size()-1) do ( for j : Integer.subrange(0, n-1) do ( if MathLib.bitwiseAnd(i, (1 * (2->pow(j)))) = 0 then ( mix(i, MathLib.bitwiseOr(i, (1 * (2->pow(j))))) ) else skip)) ; var ans : int := 0 ; for i : Integer.subrange(1, (a)->size()-1) do ( var u : OclAny := a[dp[i+1]->first()+1] + a[dp[i+1][1+1]+1] ; ans := Set{ans, u}->max() ; execute (ans)->display()); operation ins(x : OclAny, i : OclAny) pre: true post: true activity: if (dp[i+1])->includes(x) then ( return ) else skip ; if dp[i+1]->first() /= x & (a[dp[i+1]->first()+1]->compareTo(a[x+1])) < 0 then ( dp[i+1][1+1] := dp[i+1]->first() ; dp[i+1]->first() := x ) else (if dp[i+1][1+1] /= x & (a[dp[i+1][1+1]+1]->compareTo(a[x+1])) < 0 then ( dp[i+1][1+1] := x ) else skip); operation mix(i : OclAny, j : OclAny) pre: true post: true activity: ins(dp[i+1]->first(), j) ; ins(dp[i+1][1+1], j); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if n==0 : break idx,dict={},{} for i in range(n): for j in list(input().split()): if j in dict : dict[j]+=1 else : dict[j]=1 if j[0]not in idx : idx[j[0]]=[] idx[j[0]].append(j) k=input() if k not in idx : print("NA") else : a,ans=[],[] for j in idx[k]: a.append((j,dict[j])) a.sort(key=lambda x :(-x[1],x[0])) w=min(len(a),5) for j in range(w): ans.append(a[j][0]) print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var idx : OclAny := null; var OclType["Map"] : OclAny := null; Sequence{idx,OclType["Map"]} := Sequence{Set{},Set{}} ; for i : Integer.subrange(0, n-1) do ( for j : (input().split()) do ( if (OclType["Map"])->includes(j) then ( (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]) := (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]) + 1 ) else ( (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]) := 1 ; if (idx)->excludes(j->first()) then ( idx[j->first()+1] := Sequence{} ) else skip ; (expr (atom (name idx)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) ))) ; var k : String := (OclFile["System.in"]).readLine() ; if (idx)->excludes(k) then ( execute ("NA")->display() ) else ( var a : OclAny := null; var ans : OclAny := null; Sequence{a,ans} := Sequence{Sequence{},Sequence{}} ; for j : idx->at(k) do ( execute ((Sequence{j, (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])}) : a)) ; a := a->sort() ; var w : OclAny := Set{(a)->size(), 5}->min() ; for j : Integer.subrange(0, w-1) do ( execute ((a[j+1]->first()) : ans)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from string import ascii_lowercase from collections import defaultdict def solve(n): d={ch : defaultdict(int)for ch in ascii_lowercase} for _ in range(n): for word in input().split(): d[word[0]][word]+=1 k=input() return[a for _,a in sorted([(-v,k)for k,v in d[k].items()])[: 5]]if d[k]else['NA'] def main(args): while True : n=int(input()) if n==0 : break ans=solve(n) print(*ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(n : OclAny) : OclAny pre: true post: true activity: var d : Map := ascii_lowercase->select(ch | true)->collect(ch | Map{ch |-> defaultdict(OclType["int"])})->unionAll() ; for _anon : Integer.subrange(0, n-1) do ( for word : input().split() do ( d[word->first()+1][word+1] := d[word->first()+1][word+1] + 1)) ; var k : String := (OclFile["System.in"]).readLine() ; return if d->at(k) then sorted(d->at(k)->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->select(_tuple | true)->collect(_tuple | let k : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in (Sequence{-v, k}))).subrange(1,5)->select(_tuple | true)->collect(_tuple | let _anon : OclAny = _tuple->at(1) in let a : OclAny = _tuple->at(2) in (a)) else Sequence{ 'NA' } endif; operation main(args : OclAny) pre: true post: true activity: while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var ans : OclAny := solve(n) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect n=int(input()) seq=[int(input())for _ in range(n)] dp=[seq[0]] for num in seq : if num>dp[-1]: dp.append(num) else : dp[bisect.bisect_left(dp,num)]=num print(len(dp)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var seq : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var dp : Sequence := Sequence{ seq->first() } ; for num : seq do ( if (num->compareTo(dp->last())) > 0 then ( execute ((num) : dp) ) else ( dp[bisect.bisect_left(dp, num)+1] := num )) ; execute ((dp)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def countNumbers(X,Y,N): divisibleByX=int(N/X) divisibleByY=int(N/Y) LCM=int((X*Y)/gcd(X,Y)) divisibleByLCM=int(N/LCM) divisibleByXorY=(divisibleByX+divisibleByY-divisibleByLCM) divisibleByXnotY=(divisibleByXorY-divisibleByY) return divisibleByXnotY if __name__=='__main__' : X=2 Y=3 N=10 print(countNumbers(X,Y,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( X := 2 ; Y := 3 ; N := 10 ; execute (countNumbers(X, Y, N))->display() ) else skip; operation countNumbers(X : OclAny, Y : OclAny, N : OclAny) : OclAny pre: true post: true activity: var divisibleByX : int := ("" + ((N / X)))->toInteger() ; var divisibleByY : int := ("" + ((N / Y)))->toInteger() ; var LCM : int := ("" + (((X * Y) / gcd(X, Y))))->toInteger() ; var divisibleByLCM : int := ("" + ((N / LCM)))->toInteger() ; var divisibleByXorY : double := (divisibleByX + divisibleByY - divisibleByLCM) ; var divisibleByXnotY : double := (divisibleByXorY - divisibleByY) ; return divisibleByXnotY; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=0 s=0 while 1 : n,s=map(int,input().split()) if not n and not s : break ans=0 for t in range(1024): tt=t su=0 cnt=0 for i in range(10): if tt % 2 : su+=i cnt+=1 tt//=2 if cnt==n and su==s : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := 0 ; var s : int := 0 ; while 1 do ( Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if not(n) & not(s) then ( break ) else skip ; var ans : int := 0 ; for t : Integer.subrange(0, 1024-1) do ( var tt : OclAny := t ; var su : int := 0 ; var cnt : int := 0 ; for i : Integer.subrange(0, 10-1) do ( if tt mod 2 then ( su := su + i ; cnt := cnt + 1 ) else skip ; tt := tt div 2) ; if cnt = n & su = s then ( ans := ans + 1 ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def decSum(n,sm,mn): if mn+n>10 : return 0 elif sum(range(mn,mn+n))>sm or sum(range(10-n,10))=10 else sm): a+=decSum(n-1,sm-i,i+1) return a while True : n,sm=map(int,input().split()) if n==0 : break print(decSum(n,sm,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( Sequence{n,sm} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; execute (decSum(n, sm, 0))->display()); operation decSum(n : OclAny, sm : OclAny, mn : OclAny) : OclAny pre: true post: true activity: if mn + n > 10 then ( return 0 ) else (if ((Integer.subrange(mn, mn + n-1))->sum()->compareTo(sm)) > 0 or ((Integer.subrange(10 - n, 10-1))->sum()->compareTo(sm)) < 0 then ( return 0 ) else (if n = 1 then ( return 1 ) else ( var a : int := 0 ; for i : Integer.subrange(mn, if sm >= 10 then 10 else sm endif-1) do ( a := a + decSum(n - 1, sm - i, i + 1)) ; return a ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def choice(pos,num): global ans if pos==n : if len(set(l))!=n : return check=sum(l) if check==s : if set(l)not in save : save.append(set(l)) ans+=1 return if num==10 : return l[pos]=num choice(pos+1,num+1) choice(pos,num+1) number=[0,1,2,3,4,5,6,7,8,9] n,s=map(int,input().split()) while n!=0 : l=[0]*n save=[] ans=0 choice(0,0) print(ans) n,s=map(int,input().split()) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute ans : OclAny; operation initialise() pre: true post: true activity: skip ; var number : Sequence := Sequence{0}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 9 }))))))))) ; var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; while n /= 0 do ( var l : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var save : Sequence := Sequence{} ; ans := 0 ; choice(0, 0) ; execute (ans)->display() ; var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation choice(pos : OclAny, num : OclAny) pre: true post: true activity: skip ; if pos = n then ( if (Set{}->union((l)))->size() /= n then ( return ) else skip ; var check : OclAny := (l)->sum() ; if check = s then ( if (save)->excludes(Set{}->union((l))) then ( execute ((Set{}->union((l))) : save) ; ans := ans + 1 ) else skip ) else skip ; return ) else skip ; if num = 10 then ( return ) else skip ; l[pos+1] := num ; choice(pos + 1, num + 1) ; choice(pos, num + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy BIG_NUM=2000000000 HUGE_NUM=99999999999999999 MOD=1000000007 EPS=0.000000001 sys.setrecursionlimit(100000) dp=[[0]*101 for _ in range(10)] dp[0][0]=1 for i in range(0,10): for num in range(9,0,-1): for tmp_sum in range(i,101): dp[num][tmp_sum]+=dp[num-1][tmp_sum-i] while True : N,S=map(int,input().split()) if N==0 and S==0 : break print("%d" %(dp[N][S])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var HUGE_NUM : int := 99999999999999999 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; sys.setrecursionlimit(100000) ; var dp : Sequence := Integer.subrange(0, 10-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 101))) ; dp->first()->first() := 1 ; for i : Integer.subrange(0, 10-1) do ( for num : Integer.subrange(0 + 1, 9)->reverse() do ( for tmp_sum : Integer.subrange(i, 101-1) do ( dp[num+1][tmp_sum+1] := dp[num+1][tmp_sum+1] + dp[num - 1+1][tmp_sum - i+1]))) ; while true do ( var N : OclAny := null; var S : OclAny := null; Sequence{N,S} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if N = 0 & S = 0 then ( break ) else skip ; execute (StringLib.format("%d",(dp[N+1][S+1])))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import itertools for line in sys.stdin : (n,s)=map(int,line.split(" ")) if n==0 and s==0 : break cnt=0 for v in itertools.combinations(range(10),n): cnt+=sum(v)is s print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for line : OclFile["System.in"] do ( ; var Sequence{n, s} : Sequence := (line.split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 & s = 0 then ( break ) else skip ; var cnt : int := 0 ; for v : itertools.combinations(Integer.subrange(0, 10-1), n) do ( cnt := cnt + (v)->sum() <>= s) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100 INF=1<<21 WHITE=0 GRAY=1 BLACK=2 n=int(input()) M=[list(map(int,input().split()))for i in range(n)] for i in range(n): for j in range(n): if M[i][j]==-1 : M[i][j]=INF d=[INF for i in range(n)] p=[-1 for i in range(n)] color=[WHITE for i in range(n)] def prim(): global M,d,p,color d[0]=0 while(1): minv,u=INF,-1 for i in range(n): if minv>d[i]and color[i]!=BLACK : u=i minv=d[i] if u==-1 : break color[u]=BLACK for v in range(n): if color[v]!=BLACK and M[u][v]!=INF : if d[v]>M[u][v]: d[v],p[v],color[v]=M[u][v],u,GRAY return sum([M[i][p[i]]for i in range(n)if p[i]!=-1]) print(prim()) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute M : OclAny; attribute d : OclAny; attribute p : OclAny; attribute color : OclAny; operation initialise() pre: true post: true activity: var MAX : int := 100 ; var INF : int := 1 * (2->pow(21)) ; var WHITE : int := 0 ; var GRAY : int := 1 ; var BLACK : int := 2 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var M : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if M[i+1][j+1] = -1 then ( M[i+1][j+1] := INF ) else skip)) ; var d : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (INF)) ; var p : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (-1)) ; var color : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (WHITE)) ; skip ; execute (prim())->display(); operation prim() : OclAny pre: true post: true activity: skip; skip; skip; skip ; d->first() := 0 ; while (1) do ( var minv : OclAny := null; var u : OclAny := null; Sequence{minv,u} := Sequence{INF,-1} ; for i : Integer.subrange(0, n-1) do ( if (minv->compareTo(d[i+1])) > 0 & color[i+1] /= BLACK then ( var u : OclAny := i ; var minv : OclAny := d[i+1] ) else skip) ; if u = -1 then ( break ) else skip ; color[u+1] := BLACK ; for v : Integer.subrange(0, n-1) do ( if color[v+1] /= BLACK & M[u+1][v+1] /= INF then ( if (d[v+1]->compareTo(M[u+1][v+1])) > 0 then ( var d[v+1] : OclAny := null; var p[v+1] : OclAny := null; var color[v+1] : OclAny := null; Sequence{d[v+1],p[v+1],color[v+1]} := Sequence{M[u+1][v+1],u,GRAY} ) else skip ) else skip)) ; return (Integer.subrange(0, n-1)->select(i | p[i+1] /= -1)->collect(i | (M[i+1][p[i+1]+1])))->sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) M=[] for n in range(N): input_temp=list(map(int,input().split())) M.append(input_temp) color=['white']*N d=[10**10]*N p=[-1]*N d[0]=0 p[0]=-1 while True : mincost=10**10 for i in range(N): if color[i]!='BLACK' and d[i]toInteger() ; var M : Sequence := Sequence{} ; for n : Integer.subrange(0, N-1) do ( var input_temp : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((input_temp) : M)) ; var color : Sequence := MatrixLib.elementwiseMult(Sequence{ 'white' }, N) ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ (10)->pow(10) }, N) ; var p : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, N) ; d->first() := 0 ; p->first() := -1 ; while true do ( var mincost : double := (10)->pow(10) ; for i : Integer.subrange(0, N-1) do ( if color[i+1] /= 'BLACK' & (d[i+1]->compareTo(mincost)) < 0 then ( mincost := d[i+1] ; var u : OclAny := i ) else skip) ; if mincost = (10)->pow(10) then ( break ) else skip ; color[u+1] := 'BLACK' ; for v : Integer.subrange(0, N-1) do ( if color[v+1] /= 'BLACK' & M[u+1][v+1] /= -1 then ( if (M[u+1][v+1]->compareTo(d[v+1])) < 0 then ( d[v+1] := M[u+1][v+1] ; p[v+1] := u ; color[v+1] := 'GRAY' ) else skip ) else skip)) ; execute ((d)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left as bl from itertools import accumulate h,w=map(int,input().split()) aList=sorted(map(int,input().split())) bList=list(map(int,input().split())) acc=[0]+list(accumulate(aList)) aList.insert(0,-1) ans=0 for b in bList : index=bl(aList,b) ans+=acc[index-1]+(h-index+1)*b print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var aList : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var bList : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var acc : Sequence := Sequence{ 0 }->union((accumulate(aList))) ; aList := aList.insertAt(0+1, -1) ; var ans : int := 0 ; for b : bList do ( var index : OclAny := bl(aList, b) ; ans := ans + acc[index - 1+1] + (h - index + 1) * b) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class UnionFind : def __init__(self,N): self.N=N self.parent=list(range(N)) def root(self,x): path_to_root=[] while self.parent[x]!=x : path_to_root.append(x) x=self.parent[x] for node in path_to_root : self.parent[node]=x return x def same(self,x,y): return self.root(x)==self.root(y) def unite(self,x,y): self.parent[self.root(x)]=self.root(y) def __str__(self): groups={} for x in range(self.N): root=self.root(x) if root in groups.keys(): groups[root].append(x) else : groups[root]=[x] result="" for root in groups.keys(): result+=str(groups[root])+"\n" return result def kruskal(num_vertices,edges): total_weight=0 edges.sort(key=lambda e : e[2]) u=UnionFind(num_vertices) for e in edges : x=e[0] y=e[1] weight=e[2] if u.same(x,y): continue u.unite(x,y) total_weight+=weight return total_weight n=int(input()) edges=[] for i in range(n): row=list(map(int,input().split())) for j in range(i,n): if row[j]!=-1 : edges.append([i,j,row[j]]) print(kruskal(n,edges)) ------------------------------------------------------------ OCL File: --------- class UnionFind { static operation newUnionFind() : UnionFind pre: true post: UnionFind->exists( _x | result = _x ); attribute N : OclAny := N; attribute parent : Sequence := (Integer.subrange(0, N-1)); operation initialise(N : OclAny) : UnionFind pre: true post: true activity: self.N := N ; self.parent := (Integer.subrange(0, N-1)); return self; operation root(x : OclAny) : OclAny pre: true post: true activity: var path_to_root : Sequence := Sequence{} ; while self.parent[x+1] /= x do ( execute ((x) : path_to_root) ; x := self.parent[x+1]) ; for node : path_to_root do ( self.parent[node+1] := x) ; return x; operation same(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: return self.root(x) = self.root(y); operation unite(x : OclAny,y : OclAny) pre: true post: true activity: self.parent[self.root(x)+1] := self.root(y); operation __str__() : OclAny pre: true post: true activity: var groups : OclAny := Set{} ; for x : Integer.subrange(0, self.N-1) do ( var root : OclAny := self.root(x) ; if (groups.keys())->includes(root) then ( (expr (atom (name groups)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name root)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) ) else ( groups[root+1] := Sequence{ x } )) ; var result : String := "" ; for root : groups.keys() do ( result := result + ("" + ((groups[root+1]))) + "\n") ; return result; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; edges := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var row : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(i, n-1) do ( if row[j+1] /= -1 then ( execute ((Sequence{i}->union(Sequence{j}->union(Sequence{ row[j+1] }))) : edges) ) else skip)) ; execute (kruskal(n, edges))->display(); operation kruskal(num_vertices : OclAny, edges : OclAny) : OclAny pre: true post: true activity: var total_weight : int := 0 ; edges := edges->sort() ; var u : UnionFind := (UnionFind.newUnionFind()).initialise(num_vertices) ; for e : edges do ( x := e->first() ; y := e[1+1] ; var weight : OclAny := e[2+1] ; if u.same(x, y) then ( continue ) else skip ; u.unite(x, y) ; total_weight := total_weight + weight) ; return total_weight; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) from bisect import* from collections import* from heapq import* int1=lambda x : int(x)-1 p2D=lambda x : print(*x,sep="\n") def II(): return int(sys.stdin.readline()) def SI(): return sys.stdin.readline()[:-1] def MI(): return map(int,sys.stdin.readline().split()) def MI1(): return map(int1,sys.stdin.readline().split()) def MF(): return map(float,sys.stdin.readline().split()) def LI(): return list(map(int,sys.stdin.readline().split())) def LI1(): return list(map(int1,sys.stdin.readline().split())) def LF(): return list(map(float,sys.stdin.readline().split())) def LLI(rows_number): return[LI()for _ in range(rows_number)] dij=[(0,1),(1,0),(0,-1),(-1,0)] def main(): n=II() lis=[] for _ in range(n): a=II() i=bisect_left(lis,a) if i==len(lis): lis.append(a) else : lis[i]=a print(len(lis)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; skip ; skip ; skip ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; var p2D : Function := lambda x : OclAny in (((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var dij : Sequence := Sequence{Sequence{0, 1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{0, -1}}->union(Sequence{ Sequence{-1, 0} }))) ; skip ; main(); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation SI() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation MI1() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (int1)->apply(_x) ); operation MF() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LI1() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (int1)->apply(_x) )); operation LF() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) )); operation LLI(rows_number : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows_number-1)->select(_anon | true)->collect(_anon | (LI())); operation main() pre: true post: true activity: var n : OclAny := II() ; var lis : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := II() ; var i : OclAny := bisect_left(lis, a) ; if i = (lis)->size() then ( execute ((a) : lis) ) else ( lis[i+1] := a )) ; execute ((lis)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq def make_adj_list(v): adj_list=[[-1 for i in range(v)]for j in range(v)] return adj_list def prim(adj_list,v,s): min_d=0 heap=[] used=[] for i in range(v): used.append(False) used[s]=True for i in range(v): if adj_list[s][i]!=-1 : heapq.heappush(heap,(adj_list[s][i],i)) while len(heap)!=0 : cost,to=heapq.heappop(heap) if used[to]: continue min_d+=cost used[to]=True for i in range(v): if adj_list[to][i]!=-1 : heapq.heappush(heap,(adj_list[to][i],i)) return min_d def main(): v=int(input()) adj_list=make_adj_list(v) for i in range(v): adj_list[i]=[int(j)for j in input().split()] min_d=prim(adj_list,v,0) print(min_d) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation make_adj_list(v : OclAny) : OclAny pre: true post: true activity: var adj_list : Sequence := Integer.subrange(0, v-1)->select(j | true)->collect(j | (Integer.subrange(0, v-1)->select(i | true)->collect(i | (-1)))) ; return adj_list; operation prim(adj_list : OclAny, v : OclAny, s : OclAny) : OclAny pre: true post: true activity: var min_d : int := 0 ; var heap : Sequence := Sequence{} ; var used : Sequence := Sequence{} ; for i : Integer.subrange(0, v-1) do ( execute ((false) : used)) ; used[s+1] := true ; for i : Integer.subrange(0, v-1) do ( if adj_list[s+1][i+1] /= -1 then ( heapq.heappush(heap, Sequence{adj_list[s+1][i+1], i}) ) else skip) ; while (heap)->size() /= 0 do ( var cost : OclAny := null; var to : OclAny := null; Sequence{cost,to} := heapq.heappop(heap) ; if used[to+1] then ( continue ) else skip ; min_d := min_d + cost ; used[to+1] := true ; for i : Integer.subrange(0, v-1) do ( if adj_list[to+1][i+1] /= -1 then ( heapq.heappush(heap, Sequence{adj_list[to+1][i+1], i}) ) else skip)) ; return min_d; operation main() pre: true post: true activity: v := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; adj_list := make_adj_list(v) ; for i : Integer.subrange(0, v-1) do ( adj_list[i+1] := input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger()))) ; min_d := prim(adj_list, v, 0) ; execute (min_d)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import defaultdict def push_vertex(vtx : int,queue : list,weights : dict,done : dict): queue.extend(weights[vtx]) done[vtx]=True [queue.remove(x)for x in queue[:]if done[x[0]]] del weights[vtx] queue.sort(key=lambda x : x[1],reverse=True) return def main(): n=int(input()) weights=defaultdict(list) for i in range(n): for idx,weight in enumerate(input().split()): if weight!='-1' : weights[i+1].append((idx+1,int(weight))) done={} for i in weights.keys(): done[i]=False mst_weights=0 queue=[] vtx=[*weights][0] push_vertex(vtx,queue,weights,done) while len(weights)!=0 : new_vtx,new_vtx_weight=queue.pop() mst_weights+=new_vtx_weight push_vertex(new_vtx,queue,weights,done) print(mst_weights) return main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; ; operation push_vertex(vtx : int, queue : Sequence(OclAny), weights : Map(String,OclAny), done : Map(String,OclAny)) pre: true post: true activity: queue := queue->union(weights[vtx+1]) ; done[vtx+1] := true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def getnext(gen,type): try : l=gen.next().strip("\n") return type(l) except StopIteration : return None def getSpeeds(n,A,X,Y,Z): signs=[] m=len(A) for i in range(n): signs.append(A[i % m]) A[i % m]=(X*A[i % m]+Y*(i+1))% Z return signs if __name__=="__main__" : infile=open(sys.argv[1],'r') reader=infile.xreadlines() outfile=open(sys.argv[1]+'-output','w') nCases=getnext(reader,int) for case in range(nCases): line=[int(i)for i in getnext(reader,str).split(" ")] numSigns=line[0] arraySize=line[1] X=line[2] Y=line[3] Z=line[4] A=[] for l in range(arraySize): A.append(getnext(reader,int)) speeds=getSpeeds(numSigns,A,X,Y,Z) speeds.reverse() sinc=[0]*len(speeds) sinc[0]=1 for s in range(1,len(speeds)): sinc[s]=1+sum(sinc[j]for j in range(s)if speeds[j]>speeds[s]) outfile.write("Case #%d: %d\n" %(case+1,sum(sinc)% 1000000007)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( var infile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) ; var reader : OclAny := infile.xreadlines() ; var outfile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) + '-output')) ; var nCases : OclAny := getnext(reader, OclType["int"]) ; for case : Integer.subrange(0, nCases-1) do ( var line : Sequence := getnext(reader, OclType["String"]).split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var numSigns : OclAny := line->first() ; var arraySize : OclAny := line[1+1] ; X := line[2+1] ; Y := line[3+1] ; Z := line[4+1] ; A := Sequence{} ; for l : Integer.subrange(0, arraySize-1) do ( execute ((getnext(reader, OclType["int"])) : A)) ; var speeds : OclAny := getSpeeds(numSigns, A, X, Y, Z) ; speeds := speeds->reverse() ; var sinc : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (speeds)->size()) ; sinc->first() := 1 ; for s : Integer.subrange(1, (speeds)->size()-1) do ( sinc[s+1] := 1 + ((argument (test (logical_test (comparison (expr (atom (name sinc)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name speeds)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) > (comparison (expr (atom (name speeds)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])))))))))))->sum()) ; outfile.write(StringLib.format("Case #%d: %d\n",Sequence{case + 1, (sinc)->sum() mod 1000000007}))) ) else skip; operation getnext(gen : OclAny, type : OclAny) : OclAny pre: true post: true activity: try ( var l : OclAny := gen.next()->trim() ; return (l)->oclType()) (except_clause except (test (logical_test (comparison (expr (atom (name StopIteration)))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom None))))))))))); operation getSpeeds(n : OclAny, A : OclAny, X : OclAny, Y : OclAny, Z : OclAny) : OclAny pre: true post: true activity: var signs : Sequence := Sequence{} ; var m : int := (A)->size() ; for i : Integer.subrange(0, n-1) do ( execute ((A[i mod m+1]) : signs) ; A[i mod m+1] := (X * A[i mod m+1] + Y * (i + 1)) mod Z) ; return signs; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) numbers=list(map(int,input().split())) numbers.sort() print(' '.join(map(str,numbers))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var numbers : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; numbers := numbers->sort() ; execute (StringLib.sumStringsWithSeparator(((numbers)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import random def qui(l): num=len(l) if num<=1 : return l piv=random.randrange(0,len(l)) piv2=random.randrange(0,len(l)) piv3=random.randrange(0,len(l)) if(l[piv]>l[piv2])and(l[piv2]>l[piv3]): piv=piv2 elif(l[piv]>l[piv3])and(l[piv3]>l[piv2]): piv=piv3 elif(l[piv]l[i]: mini.append(l[i]) elif l[piv]<=l[i]: maxi.append(l[i]) mini=qui(mini) maxi=qui(maxi) return mini+middlei+maxi input() list1=input().split(" ") for i in range(0,len(list1)): list1[i]=int(list1[i]) result=qui(list1) print(' '.join(map(str,result))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; input() ; var list1 : OclAny := input().split(" ") ; for i : Integer.subrange(0, (list1)->size()-1) do ( list1[i+1] := ("" + ((list1[i+1])))->toInteger()) ; var result : OclAny := qui(list1) ; execute (StringLib.sumStringsWithSeparator(((result)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); operation qui(l : OclAny) : OclAny pre: true post: true activity: var num : int := (l)->size() ; if num <= 1 then ( return l ) else skip ; var piv : int := (OclRandom.defaultInstanceOclRandom()).nextInt(0, (l)->size()) ; var piv2 : int := (OclRandom.defaultInstanceOclRandom()).nextInt(0, (l)->size()) ; var piv3 : int := (OclRandom.defaultInstanceOclRandom()).nextInt(0, (l)->size()) ; if ((l[piv+1]->compareTo(l[piv2+1])) > 0) & ((l[piv2+1]->compareTo(l[piv3+1])) > 0) then ( piv := piv2 ) else (if ((l[piv+1]->compareTo(l[piv3+1])) > 0) & ((l[piv3+1]->compareTo(l[piv2+1])) > 0) then ( piv := piv3 ) else (if ((l[piv+1]->compareTo(l[piv2+1])) < 0) & ((l[piv2+1]->compareTo(l[piv3+1])) < 0) then ( piv := piv2 ) else (if ((l[piv+1]->compareTo(l[piv3+1])) < 0) & ((l[piv3+1]->compareTo(l[piv2+1])) < 0) then ( piv := piv3 ) else ( skip ) ) ) ) ; var mini : Sequence := Sequence{} ; var middlei : Sequence := Sequence{} ; var maxi : Sequence := Sequence{} ; for i : Integer.subrange(0, (l)->size()-1) do ( if l[i+1] = l[piv+1] then ( execute ((l[i+1]) : middlei) ) else (if (l[piv+1]->compareTo(l[i+1])) > 0 then ( execute ((l[i+1]) : mini) ) else (if (l[piv+1]->compareTo(l[i+1])) <= 0 then ( execute ((l[i+1]) : maxi) ) else skip ) ) ) ; mini := qui(mini) ; maxi := qui(maxi) ; return mini->union(middlei)->union(maxi); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) array=[int(i)for i in input().split()] array.sort() for i in range(n): if i==n-1 : print(array[i]) else : print(array[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var array : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; array := array->sort() ; for i : Integer.subrange(0, n-1) do ( if i = n - 1 then ( execute (array[i+1])->display() ) else ( execute (array[i+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() print(' '.join(sorted(raw_input().split(),key=int))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; execute (StringLib.sumStringsWithSeparator((raw_input().split()->sortedBy($x | (OclType["int"])->apply($x))), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lists=list(map(int,input().split())) lists.sort() for i in range(n-1): print(lists[i],end=' ') print(lists[n-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lists : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; lists := lists->sort() ; for i : Integer.subrange(0, n - 1-1) do ( execute (lists[i+1])->display()) ; execute (lists[n - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w,n=map(int,input().split()) coord=[list(map(int,input().split()))for i in range(n)] num={} for i in range(n): for j,k in[[0,0],[0,1],[0,-1],[1,0],[1,1],[1,-1],[-1,0],[-1,1],[-1,-1]]: if not(2<=coord[i][0]+j<=h-1)or not(2<=coord[i][1]+k<=w-1): continue if not coord[i][0]+j in num : num[coord[i][0]+j]={} if not coord[i][1]+k in num[coord[i][0]+j]: num[coord[i][0]+j][coord[i][1]+k]=1 else : num[coord[i][0]+j][coord[i][1]+k]+=1 ans=[0]*10 for i in num : for value in num[i].values(): ans[value]+=1 print((h-2)*(w-2)-sum(ans)) for i in range(1,10): print(ans[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; var n : OclAny := null; Sequence{h,w,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var coord : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var num : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( for _tuple : Sequence{Sequence{0}->union(Sequence{ 0 })}->union(Sequence{Sequence{0}->union(Sequence{ 1 })}->union(Sequence{Sequence{0}->union(Sequence{ -1 })}->union(Sequence{Sequence{1}->union(Sequence{ 0 })}->union(Sequence{Sequence{1}->union(Sequence{ 1 })}->union(Sequence{Sequence{1}->union(Sequence{ -1 })}->union(Sequence{Sequence{-1}->union(Sequence{ 0 })}->union(Sequence{Sequence{-1}->union(Sequence{ 1 })}->union(Sequence{ Sequence{-1}->union(Sequence{ -1 }) })))))))) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var k : OclAny := _tuple->at(_indx); if not((2 <= coord[i+1]->first() + j & (coord[i+1]->first() + j <= h - 1))) or not((2 <= coord[i+1][1+1] + k & (coord[i+1][1+1] + k <= w - 1))) then ( continue ) else skip ; if not((num)->includes(coord[i+1]->first() + j)) then ( num[coord[i+1]->first() + j+1] := Set{} ) else skip ; if not((num[coord[i+1]->first() + j+1])->includes(coord[i+1][1+1] + k)) then ( num[coord[i+1]->first() + j+1][coord[i+1][1+1] + k+1] := 1 ) else ( num[coord[i+1]->first() + j+1][coord[i+1][1+1] + k+1] := num[coord[i+1]->first() + j+1][coord[i+1][1+1] + k+1] + 1 ))) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; for i : num do ( for value : num[i+1].values() do ( ans[value+1] := ans[value+1] + 1)) ; execute ((h - 2) * (w - 2) - (ans)->sum())->display() ; for i : Integer.subrange(1, 10-1) do ( execute (ans[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d,h=map(int,input().split()) if d>2*h or(d==1 and n>2): print(-1) elif d==h : for i in range(1,d+1): print(i,i+1) for i in range(d+2,n+1): print(2,i) else : for i in range(2,h+2): print(i-1,i) print(1,h+2) for i in range(h+3,d+2): print(i-1,i) for i in range(d+2,n+1): print(1,i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; var h : OclAny := null; Sequence{n,d,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (d->compareTo(2 * h)) > 0 or (d = 1 & n > 2) then ( execute (-1)->display() ) else (if d = h then ( for i : Integer.subrange(1, d + 1-1) do ( execute (i)->display()) ; for i : Integer.subrange(d + 2, n + 1-1) do ( execute (2)->display()) ) else ( for i : Integer.subrange(2, h + 2-1) do ( execute (i - 1)->display()) ; execute (1)->display() ; for i : Integer.subrange(h + 3, d + 2-1) do ( execute (i - 1)->display()) ; for i : Integer.subrange(d + 2, n + 1-1) do ( execute (1)->display()) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): from bisect import bisect_left n,*A=map(int,open(0).read().split()) length=0 lis=[] for a in A : i=bisect_left(lis,a) if i==length : lis.append(a) length+=1 else : lis[i]=a print(length) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: skip ; var n : OclAny := null; var A : OclAny := null; Sequence{n,A} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var length : int := 0 ; var lis : Sequence := Sequence{} ; for a : A do ( var i : OclAny := bisect_left(lis, a) ; if i = length then ( execute ((a) : lis) ; length := length + 1 ) else ( lis[i+1] := a )) ; execute (length)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import Counter sr=lambda : sys.stdin.readline().rstrip() ir=lambda : int(sr()) lr=lambda : list(map(int,sr().split())) H,W,N=lr() pairs=[] for _ in range(N): a,b=lr() a-=1 ; b-=1 for dh in[-2,-1,0]: if a+dh<0 or a+dh>H-3 : continue for dw in[-2,-1,0]: if b+dw<0 or b+dw>W-3 : continue pairs.append((a+dh,b+dw)) counter=Counter(pairs) answer=[0]*10 counter2=Counter(counter.values()) for k,v in counter2.items(): answer[k]=v answer[0]=(H-2)*(W-2)-sum(answer) print('\n'.join(map(str,answer))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var sr : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var ir : Function := lambda $$ : OclAny in (("" + ((sr->apply())))->toInteger()) ; var lr : Function := lambda $$ : OclAny in (((sr->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var H : OclAny := null; var W : OclAny := null; var N : OclAny := null; Sequence{H,W,N} := lr->apply() ; var pairs : Sequence := Sequence{} ; for _anon : Integer.subrange(0, N-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := lr->apply() ; a := a - 1; b := b - 1 ; for dh : Sequence{-2}->union(Sequence{-1}->union(Sequence{ 0 })) do ( if a + dh < 0 or (a + dh->compareTo(H - 3)) > 0 then ( continue ) else skip ; for dw : Sequence{-2}->union(Sequence{-1}->union(Sequence{ 0 })) do ( if b + dw < 0 or (b + dw->compareTo(W - 3)) > 0 then ( continue ) else skip ; execute ((Sequence{a + dh, b + dw}) : pairs)))) ; var counter : OclAny := Counter(pairs) ; var answer : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; var counter2 : OclAny := Counter(counter.values()) ; for _tuple : counter2->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); answer[k+1] := v) ; answer->first() := (H - 2) * (W - 2) - (answer)->sum() ; execute (StringLib.sumStringsWithSeparator(((answer)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w,n=map(int,input().split()) ls=[] while True : try : ls.append(tuple(map(int,input().split()))) except EOFError : break check={} count={0 :(h-2)*(w-2)} for i in range(1,10): count[i]=0 for tup in ls : for i in range(-2,1): for j in range(-2,1): if(tup[0]+i>0 and tup[0]+i0 and tup[1]+jcollect( _x | (OclType["int"])->apply(_x) ) ; var ls : Sequence := Sequence{} ; while true do ( try ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : ls)) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (simple_stmt (small_stmt break))))) ; var check : OclAny := Set{} ; var count : Map := Map{ 0 |-> (h - 2) * (w - 2) } ; for i : Integer.subrange(1, 10-1) do ( count[i+1] := 0) ; for tup : ls do ( for i : Integer.subrange(-2, 1-1) do ( for j : Integer.subrange(-2, 1-1) do ( if (tup->first() + i > 0 & (tup->first() + i->compareTo(h - 1)) < 0 & tup[1+1] + j > 0 & (tup[1+1] + j->compareTo(w - 1)) < 0) then ( try ( check[Sequence{tup->first() + i, tup[1+1] + j}+1] := check[Sequence{tup->first() + i, tup[1+1] + j}+1] + 1) (except_clause except (test (logical_test (comparison (expr (atom (name KeyError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name check)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name tup)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) + (expr (atom (name i))))))) , (test (logical_test (comparison (expr (expr (atom (name tup)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) + (expr (atom (name j)))))))) )))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) ; var index : OclAny := check[Sequence{tup->first() + i, tup[1+1] + j}+1] ; count[index+1] := count[index+1] + 1 ; count[index - 1+1] := count[index - 1+1] - 1 ) else skip))) ; for i : Integer.subrange(0, 10-1) do ( execute (StringLib.interpolateStrings("{}", Sequence{count[i+1]}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): from sys import stdin input=stdin.readline h,w,n=map(int,input().split()) ab=[list(map(int,input().split()))for _ in[0]*n] ans=[0]*10 d={} for a,b in ab : for j in range(-1,2): for k in range(-1,2): d[(a+j,b+k)]=d.get((a+j,b+k),0)+1 for(i,j),k in d.items(): if 2<=icollect( _x | (OclType["int"])->apply(_x) ) ; var ab : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; var d : OclAny := Set{} ; for _tuple : ab do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); for j : Integer.subrange(-1, 2-1) do ( for k : Integer.subrange(-1, 2-1) do ( d[Sequence{a + j, b + k}+1] := d.get(Sequence{a + j, b + k}, 0) + 1))) ; for _tuple : d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var Sequence{i, j} : OclAny := _tuple->at(_indx); _indx := _indx + 1; var k : OclAny := _tuple->at(_indx); if 2 <= i & (i < h) & 2 <= j & (j < w) then ( ans[k+1] := ans[k+1] + 1 ) else skip) ; execute ((h - 2) * (w - 2) - (ans)->sum())->display() ; for i : ans->tail() do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict as dd H,W,N=map(int,input().split()) ab=[tuple(map(int,input().split()))for _ in range(N)] tpl=[(-1,-1),(-1,0),(-1,1),(0,-1),(0,0),(0,1),(1,-1),(1,0),(1,1)] edge_WtoB=dd(int) edge_BtoB=dd(int) node_B=set(ab) res=dd(int) for a,b in ab : for s,t in tpl : tgt=(a+s,b+t) if tgt in node_B : if not(1collect( _x | (OclType["int"])->apply(_x) ) ; var ab : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var tpl : Sequence := Sequence{Sequence{-1, -1}}->union(Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{-1, 1}}->union(Sequence{Sequence{0, -1}}->union(Sequence{Sequence{0, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{1, -1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{ Sequence{1, 1} })))))))) ; var edge_WtoB : OclAny := dd(OclType["int"]) ; var edge_BtoB : OclAny := dd(OclType["int"]) ; var node_B : Set := Set{}->union((ab)) ; var res : OclAny := dd(OclType["int"]) ; for _tuple : ab do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); for _tuple : tpl do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); var tgt : OclAny := Sequence{a + s, b + t} ; if (node_B)->includes(tgt) then ( if not((1 < a & (a < H) & 1 < b & (b < W))) then ( continue ) else skip ; edge_BtoB[Sequence{a, b}+1] := edge_BtoB[Sequence{a, b}+1] + 1 ) else ( if not((1 < a + s & (a + s < H) & 1 < b + t & (b + t < W))) then ( continue ) else skip ; edge_WtoB[tgt+1] := edge_WtoB[tgt+1] + 1 ))) ; for val : edge_WtoB.values() do ( res[val+1] := res[val+1] + 1) ; for val : edge_BtoB.values() do ( res[val+1] := res[val+1] + 1) ; var zero : double := (H - 2) * (W - 2) ; for j : Integer.subrange(1, 10-1) do ( zero := zero - res[j+1]) ; res->first() := zero ; for j : Integer.subrange(0, 10-1) do ( execute (res[j+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,sys,io,math from tokenize import Triple from math import* I=lambda :[*map(int,sys.stdin.readline().split())] IS=lambda : input() IN=lambda : int(input()) IF=lambda : float(input()) n=IN() s=IS() a=0 f=0 i=0 for c in s : if c=='A' : a+=1 elif c=='F' : f+=1 else : i+=1 if i==0 : print(a) elif i==1 : print(1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var I : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var IS : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var IN : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var IF : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toReal()) ; var n : OclAny := IN->apply() ; var s : OclAny := IS->apply() ; var a : int := 0 ; var f : int := 0 ; var i : int := 0 ; for c : s do ( if c = 'A' then ( a := a + 1 ) else (if c = 'F' then ( f := f + 1 ) else ( i := i + 1 ) ) ) ; if i = 0 then ( execute (a)->display() ) else (if i = 1 then ( execute (1)->display() ) else ( execute (0)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() I=s.count("I") if(I>1): print("0") elif(I==1): print("1") else : print(s.count("A")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var I : int := s->count("I") ; if (I > 1) then ( execute ("0")->display() ) else (if (I = 1) then ( execute ("1")->display() ) else ( execute (s->count("A"))->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) s=input()[:-1] x=s.count('I') print(1 if x==1 else 0 if x>1 else s.count('A')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := input()->front() ; var x : int := s->count('I') ; execute (if x = 1 then 1 else if x > 1 then 0 else s->count('A') endif endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() n=int(input()) s=input() res=[s.count('A'),1,0] print(res[min(s.count('I'),2)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var res : Sequence := Sequence{s->count('A')}->union(Sequence{1}->union(Sequence{ 0 })) ; execute (res[Set{s->count('I'), 2}->min()+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) st=input() index_dict={} count=0 count_a,count_f,count_i=0,0,0 for i in range(len(st)): if st[i]=='A' : count_a+=1 elif st[i]=='F' : count_f+=1 else : count_i+=1 for i in range(len(st)): if st[i]=='A' : if not(count_i): count+=1 elif st[i]=='I' : if not(count_i-1): count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var st : String := (OclFile["System.in"]).readLine() ; var index_dict : OclAny := Set{} ; var count : int := 0 ; var count_a : OclAny := null; var count_f : OclAny := null; var count_i : OclAny := null; Sequence{count_a,count_f,count_i} := Sequence{0,0,0} ; for i : Integer.subrange(0, (st)->size()-1) do ( if st[i+1] = 'A' then ( count_a := count_a + 1 ) else (if st[i+1] = 'F' then ( count_f := count_f + 1 ) else ( count_i := count_i + 1 ) ) ) ; for i : Integer.subrange(0, (st)->size()-1) do ( if st[i+1] = 'A' then ( if not((count_i)) then ( count := count + 1 ) else skip ) else (if st[i+1] = 'I' then ( if not((count_i - 1)) then ( count := count + 1 ) else skip ) else skip)) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline A,B=[],[] for S in readline().rstrip().split(","): for s in S.split(";"): le=len(s) if s=="0" or le>=1 and all(48<=ord(s[i])<58 for i in range(le))and s[0]!="0" : A.append(s) else : B.append(s) if A : A='"'+",".join(A)+'"' else : A="-" if B : B='"'+",".join(B)+'"' else : B="-" print(A) print(B) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := Sequence{Sequence{},Sequence{}} ; for S : readline().rstrip().split(",") do ( for s : S.split(";") do ( var le : int := (s)->size() ; if s = "0" or le >= 1 & ((argument (test (logical_test (comparison (comparison (comparison (expr (atom (number (integer 48))))) <= (comparison (expr (atom (name ord)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))))) < (comparison (expr (atom (number (integer 58)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name le)))))))) )))))))))->forAll( _x | _x = true ) & s->first() /= "0" then ( execute ((s) : A) ) else ( execute ((s) : B) ))) ; if A then ( var A : String := '"' + StringLib.sumStringsWithSeparator((A), ",") + '"' ) else ( A := "-" ) ; if B then ( var B : String := '"' + StringLib.sumStringsWithSeparator((B), ",") + '"' ) else ( B := "-" ) ; execute (A)->display() ; execute (B)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) A=[] for _ in range(n): A.append(int(input())) dp=[0 for _ in range(n)] dp[0]=A[0] len=1 def CeilIndex(A,l,r,key): while r-l>1 : m=(l+r)//2 if A[m]>=key : r=m else : l=m return r for i in range(1,n): if A[i]dp[len-1]: dp[len]=A[i] len+=1 else : dp[CeilIndex(dp,-1,len-1,A[i])]=A[i] print(len) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : A)) ; var dp : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)) ; dp->first() := A->first() ; var len : int := 1 ; skip ; for i : Integer.subrange(1, n-1) do ( if (A[i+1]->compareTo(dp->first())) < 0 then ( dp->first() := A[i+1] ) else (if (A[i+1]->compareTo(dp[len - 1+1])) > 0 then ( dp[len+1] := A[i+1] ; len := len + 1 ) else ( dp[CeilIndex(dp, -1, len - 1, A[i+1])+1] := A[i+1] ) ) ) ; execute (len)->display(); operation CeilIndex(A : OclAny, l : OclAny, r : OclAny, key : OclAny) : OclAny pre: true post: true activity: while r - l > 1 do ( var m : int := (l + r) div 2 ; if (A[m+1]->compareTo(key)) >= 0 then ( r := m ) else ( l := m )) ; return r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,m,k): x=n*(n-1)//2 if mx : return "NO" elif n==1 : d=0 elif m==x : d=1 else : d=2 if dtoInteger() ; for i : Integer.subrange(0, n-1) do ( Sequence{n,m,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : OclAny := solve(n, m, k) ; execute (res)->display()); operation solve(n : OclAny, m : OclAny, k : OclAny) : OclAny pre: true post: true activity: var x : int := n * (n - 1) div 2 ; if (m->compareTo(n - 1)) < 0 then ( return "NO" ) else (if (m->compareTo(x)) > 0 then ( return "NO" ) else (if n = 1 then ( var d : int := 0 ) else (if m = x then ( d := 1 ) else ( d := 2 ) ) ) ) ; if (d->compareTo(k - 1)) < 0 then ( return "YES" ) else ( return "NO" ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n,d,h=list(map(int,input().split())) if d==1 and h==1 and n!=2 : print(-1) sys.exit(0); if h=num : print(1,h+2) num+=1 if num==n : sys.exit() for i in range(h+2,d+1): print(i,i+1) num+=1 if num==n : sys.exit() while numcollect( _x | (OclType["int"])->apply(_x) )) ; if d = 1 & h = 1 & n /= 2 then ( execute (-1)->display() ; sys.exit(0); ) else skip ; if (h->compareTo(d div 2 + d mod 2)) < 0 then ( execute (-1)->display() ; sys.exit(0) ) else skip ; var num : int := 1 ; for i : Integer.subrange(1, h + 1-1) do ( execute (i)->display() ; num := num + 1) ; if num = n then ( sys.exit() ) else skip ; if (d->compareTo(num)) >= 0 then ( execute (1)->display() ; num := num + 1 ) else skip ; if num = n then ( sys.exit() ) else skip ; for i : Integer.subrange(h + 2, d + 1-1) do ( execute (i)->display() ; num := num + 1) ; if num = n then ( sys.exit() ) else skip ; while (num->compareTo(n)) < 0 do ( execute (h)->display() ; num := num + 1;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solution(): s=input() a=[] b=[] txt='' i=0 flag=False while i=2 and txt[0]=='0'): b.append(txt) else : try : n=int(txt) a.append(txt) except ValueError : b.append(txt) txt='' else : txt+=s[i] if i==len(s)-1 : flag=True continue i+=1 if s[-1]==',' or s[-1]==';' : b.append('') if len(a)==0 : print(chr(45)) else : a=','.join(a) print(f'"{a}"') if len(b)==0 : print(chr(45)) else : b=','.join(b) print(f'"{b}"') solution() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solution(); operation solution() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var a : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; var txt : String := '' ; var i : int := 0 ; var flag : boolean := false ; while (i->compareTo((s)->size())) < 0 do ( if (s[i+1])->char2byte() = 44 or (s[i+1])->char2byte() = 59 or flag then ( if txt = '' then ( execute (('') : b) ) else ( if txt = '1.0' or ((txt)->size() >= 2 & txt->first() = '0') then ( execute ((txt) : b) ) else ( try ( var n : int := ("" + ((txt)))->toInteger() ; execute ((txt) : a)) (except_clause except (test (logical_test (comparison (expr (atom (name ValueError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name txt)))))))) )))))))))))))) ) ; txt := '' ) ) else ( txt := txt + s[i+1] ; if i = (s)->size() - 1 then ( flag := true ; continue ) else skip ) ; i := i + 1) ; if s->last() = ',' or s->last() = ';' then ( execute (('') : b) ) else skip ; if (a)->size() = 0 then ( execute ((45)->byte2char())->display() ) else ( a := StringLib.sumStringsWithSeparator((a), ',') ; execute (StringLib.formattedString('"{a}"'))->display() ) ; if (b)->size() = 0 then ( execute ((45)->byte2char())->display() ) else ( b := StringLib.sumStringsWithSeparator((b), ',') ; execute (StringLib.formattedString('"{b}"'))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() s=s.replace(";","%") s=s.replace(",","%") s=s.split("%") a,b,c="","","" for x in s : if x.isdigit()==True : if len(x)>1 and x[0]=="0" : b=b+","+x else : if "." in x : b=b+","+x else : a=a+","+x else : b=b+","+x if a!="" : a=a.replace(",","",1) print('"'+a+'"') else : print("-") if b!="" : b=b.replace(",","",1) print('"'+b+'"') else : print("-") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; s := s.replace(";", "%") ; s := s.replace(",", "%") ; s := s.split("%") ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{"","",""} ; for x : s->characters() do ( if x->matches("[0-9]*") = true then ( if (x)->size() > 1 & x->first() = "0" then ( var b : OclAny := b + "," + x ) else ( if (x)->includes(".") then ( b := b + "," + x ) else ( var a : OclAny := a + "," + x ) ) ) else ( b := b + "," + x )) ; if a /= "" then ( a := a.replace(",", "", 1) ; execute ('"' + a + '"')->display() ) else ( execute ("-")->display() ) ; if b /= "" then ( b := b.replace(",", "", 1) ; execute ('"' + b + '"')->display() ) else ( execute ("-")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() q=[] z='' for i in s : if i in[',',';']: q.append(z) z='' else : z+=i q.append(z) a,b=[],[] for i in q : if len(i)>0 and((i=='0')or(i[0]!='0' and i.isdigit())): a.append(i) else : b.append(i) if a!=[]: print('"'+','.join(a)+'"') else : print('-') if b!=[]: print('"'+','.join(b)+'"') else : print('-') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var q : Sequence := Sequence{} ; var z : String := '' ; for i : s->characters() do ( if (Sequence{','}->union(Sequence{ ';' }))->includes(i) then ( execute ((z) : q) ; z := '' ) else ( z := z + i )) ; execute ((z) : q) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{Sequence{},Sequence{}} ; for i : q do ( if (i)->size() > 0 & ((i = '0') or (i->first() /= '0' & i->matches("[0-9]*"))) then ( execute ((i) : a) ) else ( execute ((i) : b) )) ; if a /= Sequence{} then ( execute ('"' + StringLib.sumStringsWithSeparator((a), ',') + '"')->display() ) else ( execute ('-')->display() ) ; if b /= Sequence{} then ( execute ('"' + StringLib.sumStringsWithSeparator((b), ',') + '"')->display() ) else ( execute ('-')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() l=[] s1='' for i in s : if i in[',',';']: l.append(s1) s1='' else : s1+=i l.append(s1) a,b=[],[] for i in l : if len(i)>0 and((i=='0')or(i[0]!='0' and i.isdigit())): a.append(i) else : b.append(i) if a!=[]: print('"'+','.join(a)+'"') else : print('-') if b!=[]: print('"'+','.join(b)+'"') else : print('-') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var l : Sequence := Sequence{} ; var s1 : String := '' ; for i : s->characters() do ( if (Sequence{','}->union(Sequence{ ';' }))->includes(i) then ( execute ((s1) : l) ; s1 := '' ) else ( s1 := s1 + i )) ; execute ((s1) : l) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{Sequence{},Sequence{}} ; for i : l do ( if (i)->size() > 0 & ((i = '0') or (i->first() /= '0' & i->matches("[0-9]*"))) then ( execute ((i) : a) ) else ( execute ((i) : b) )) ; if a /= Sequence{} then ( execute ('"' + StringLib.sumStringsWithSeparator((a), ',') + '"')->display() ) else ( execute ('-')->display() ) ; if b /= Sequence{} then ( execute ('"' + StringLib.sumStringsWithSeparator((b), ',') + '"')->display() ) else ( execute ('-')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100 def largestInColumn(mat,rows,cols): for i in range(cols): maxm=mat[0][i] for j in range(rows): if mat[j][i]>maxm : maxm=mat[j][i] print(maxm) n,m=4,4 mat=[[3,4,1,8],[1,4,9,11],[76,34,21,1],[2,1,4,5]] largestInColumn(mat,n,m); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 100 ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{4,4} ; mat := Sequence{Sequence{3}->union(Sequence{4}->union(Sequence{1}->union(Sequence{ 8 })))}->union(Sequence{Sequence{1}->union(Sequence{4}->union(Sequence{9}->union(Sequence{ 11 })))}->union(Sequence{Sequence{76}->union(Sequence{34}->union(Sequence{21}->union(Sequence{ 1 })))}->union(Sequence{ Sequence{2}->union(Sequence{1}->union(Sequence{4}->union(Sequence{ 5 }))) }))) ; largestInColumn(mat, n, m);; operation largestInColumn(mat : OclAny, rows : OclAny, cols : OclAny) pre: true post: true activity: for i : Integer.subrange(0, cols-1) do ( var maxm : OclAny := mat->first()[i+1] ; for j : Integer.subrange(0, rows-1) do ( if (mat[j+1][i+1]->compareTo(maxm)) > 0 then ( maxm := mat[j+1][i+1] ) else skip) ; execute (maxm)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countDigit(n): temp=n sum=0 product=1 while(temp!=0): d=temp % 10 temp//=10 if(d>0 and n % d==0): sum+=d product*=d print("Sum=",sum) print("Product=",product) if __name__=='__main__' : n=1012 countDigit(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 1012 ; countDigit(n) ) else skip; operation countDigit(n : OclAny) pre: true post: true activity: var temp : OclAny := n ; var sum : int := 0 ; var product : int := 1 ; while (temp /= 0) do ( var d : int := temp mod 10 ; temp := temp div 10 ; if (d > 0 & n mod d = 0) then ( sum := sum + d ; product := product * d ) else skip) ; execute ("Sum=")->display() ; execute ("Product=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minCost(s): alphabets=[False for i in range(26)] for i in range(len(s)): alphabets[ord(s[i])-97]=True count=0 for i in range(26): if(alphabets[i]): count+=1 return count if __name__=='__main__' : s="geeksforgeeks" print("Total cost to construct",s,"is",minCost(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( s := "geeksforgeeks" ; execute ("Total cost to construct")->display() ) else skip; operation minCost(s : OclAny) : OclAny pre: true post: true activity: var alphabets : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | (false)) ; for i : Integer.subrange(0, (s)->size()-1) do ( alphabets[(s[i+1])->char2byte() - 97+1] := true) ; var count : int := 0 ; for i : Integer.subrange(0, 26-1) do ( if (alphabets[i+1]) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,L,a=input().split() n=int(n) L=int(L) a=int(a) h=[] if(n<=0): print(math.floor(L/a)) else : for i in range(n): t,l=input().split() h.append((int(t),int(l))) first=math.floor(h[0][0]/a) middle=0 for i in range(n-1): mid=h[i+1][0]-(h[i][0]+h[i][1]) middle+=math.floor(mid/a) last=math.floor((L-(h[len(h)-1][0]+h[len(h)-1][1]))/a) print(first+middle+last) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var L : OclAny := null; var a : OclAny := null; Sequence{n,L,a} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var L : int := ("" + ((L)))->toInteger() ; var a : int := ("" + ((a)))->toInteger() ; var h : Sequence := Sequence{} ; if (n <= 0) then ( execute ((L / a)->floor())->display() ) else ( for i : Integer.subrange(0, n-1) do ( var t : OclAny := null; var l : OclAny := null; Sequence{t,l} := input().split() ; execute ((Sequence{("" + ((t)))->toInteger(), ("" + ((l)))->toInteger()}) : h)) ; var first : double := (h->first()->first() / a)->floor() ; var middle : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( var mid : double := h[i + 1+1]->first() - (h[i+1]->first() + h[i+1][1+1]) ; middle := middle + (mid / a)->floor()) ; var last : double := ((L - (h[(h)->size() - 1+1]->first() + h[(h)->size() - 1+1][1+1])) / a)->floor() ; execute (first + middle + last)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import bisect def input(): return sys.stdin.readline() def lis(n,A): L=[0 for i in range(n+1)] L[0]=A[0] length=1 for i in range(1,n): if L[length-1]toInteger() ; A := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; execute (lis(n, A))->display() ) else skip; operation input() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation lis(n : OclAny, A : OclAny) : OclAny pre: true post: true activity: var L : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; L->first() := A->first() ; var length : int := 1 ; for i : Integer.subrange(1, n-1) do ( if (L[length - 1+1]->compareTo(A[i+1])) < 0 then ( L[length+1] := A[i+1] ; length := length + 1 ) else ( var index : OclAny := bisect.bisect_left(L, A[i+1], 0, length) ; L[index+1] := A[i+1] )) ; return length; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from time import ctime n_L_a=input().split() n=int(n_L_a[0]) n_count=0 L=int(n_L_a[1]) a=int(n_L_a[2]) breaks=0 c_time=0 while(c_time<=L): if(n_countfirst())))->toInteger() ; var n_count : int := 0 ; var L : int := ("" + ((n_L_a[1+1])))->toInteger() ; var a : int := ("" + ((n_L_a[2+1])))->toInteger() ; var breaks : int := 0 ; var c_time : int := 0 ; while ((c_time->compareTo(L)) <= 0) do ( if ((n_count->compareTo(n)) < 0) then ( n_count := n_count + 1 ) else ( break ) ; var cust : OclAny := input().split() ; var pot_time : double := ("" + ((cust->first())))->toInteger() - c_time ; breaks := breaks + pot_time div a ; c_time := ("" + ((cust->first())))->toInteger() + ("" + ((cust[1+1])))->toInteger()) ; breaks := breaks + (L - c_time) div a ; execute (breaks)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inp=[int(x)for x in input().split()] n,L,a=inp[0],inp[1],inp[2] start=0 res=0 for i in range(n): inp2=[int(y)for y in input().split()] t,l=inp2[0],inp2[1] res+=((t-start)//a) start=t+l res+=((L-start)//a) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inp : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var n : OclAny := null; var L : OclAny := null; var a : OclAny := null; Sequence{n,L,a} := Sequence{inp->first(),inp[1+1],inp[2+1]} ; var start : int := 0 ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( var inp2 : Sequence := input().split()->select(y | true)->collect(y | (("" + ((y)))->toInteger())) ; var t : OclAny := null; var l : OclAny := null; Sequence{t,l} := Sequence{inp2->first(),inp2[1+1]} ; res := res + ((t - start) div a) ; start := t + l) ; res := res + ((L - start) div a) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d,h=map(int,input().split()) if d>2*h or(h==0 and n>1)or(d==1 and n>2): print(-1) else : fr=2 for i in range(h): print('{}{}'.format(fr-1,fr)) fr+=1 if d==h : while fr<=n : print('2{}'.format(fr)) fr+=1 else : last,next=1,h+2 for i in range(d-h): print('{}{}'.format(last,next)) last,next=next,next+1 while next<=n : print('1{}'.format(next)) next+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; var h : OclAny := null; Sequence{n,d,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (d->compareTo(2 * h)) > 0 or (h = 0 & n > 1) or (d = 1 & n > 2) then ( execute (-1)->display() ) else ( var fr : int := 2 ; for i : Integer.subrange(0, h-1) do ( execute (StringLib.interpolateStrings('{}{}', Sequence{fr - 1, fr}))->display() ; fr := fr + 1) ; if d = h then ( while (fr->compareTo(n)) <= 0 do ( execute (StringLib.interpolateStrings('2{}', Sequence{fr}))->display() ; fr := fr + 1) ) else ( var last : OclAny := null; var next : OclAny := null; Sequence{last,next} := Sequence{1,h + 2} ; for i : Integer.subrange(0, d - h-1) do ( execute (StringLib.interpolateStrings('{}{}', Sequence{last, next}))->display() ; var last : OclAny := null; var next : OclAny := null; Sequence{last,next} := Sequence{next,next + 1}) ; while (next->compareTo(n)) <= 0 do ( execute (StringLib.interpolateStrings('1{}', Sequence{next}))->display() ; next := next + 1) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=str(input()).split() customers,totalminutes,breaklength=int(a[0]),int(a[1]),int(a[2]) count=0 time=0 if a : for i in range(customers): j=str(input()).split() t,l=int(j[0]),int(j[1]) count+=(t-time)//breaklength time=t+l count+=(totalminutes-time)//breaklength else : count=totalminutes//breaklength print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := OclType["String"]((OclFile["System.in"]).readLine()).split() ; var customers : OclAny := null; var totalminutes : OclAny := null; var breaklength : OclAny := null; Sequence{customers,totalminutes,breaklength} := Sequence{("" + ((a->first())))->toInteger(),("" + ((a[1+1])))->toInteger(),("" + ((a[2+1])))->toInteger()} ; var count : int := 0 ; var time : int := 0 ; if a then ( for i : Integer.subrange(0, customers-1) do ( var j : OclAny := OclType["String"]((OclFile["System.in"]).readLine()).split() ; var t : OclAny := null; var l : OclAny := null; Sequence{t,l} := Sequence{("" + ((j->first())))->toInteger(),("" + ((j[1+1])))->toInteger()} ; count := count + (t - time) div breaklength ; time := t + l) ; count := count + (totalminutes - time) div breaklength ) else ( count := totalminutes div breaklength ) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=str(input()).split() customers,totalminutes,breaklength=int(a[0]),int(a[1]),int(a[2]) count=0 time=0 if a : for i in range(customers): j=str(input()).split() t,l=int(j[0]),int(j[1]) count+=(t-time)//breaklength time=t+l count+=(totalminutes-time)//breaklength else : count=totalminutes//breaklength print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := OclType["String"]((OclFile["System.in"]).readLine()).split() ; var customers : OclAny := null; var totalminutes : OclAny := null; var breaklength : OclAny := null; Sequence{customers,totalminutes,breaklength} := Sequence{("" + ((a->first())))->toInteger(),("" + ((a[1+1])))->toInteger(),("" + ((a[2+1])))->toInteger()} ; var count : int := 0 ; var time : int := 0 ; if a then ( for i : Integer.subrange(0, customers-1) do ( var j : OclAny := OclType["String"]((OclFile["System.in"]).readLine()).split() ; var t : OclAny := null; var l : OclAny := null; Sequence{t,l} := Sequence{("" + ((j->first())))->toInteger(),("" + ((j[1+1])))->toInteger()} ; count := count + (t - time) div breaklength ; time := t + l) ; count := count + (totalminutes - time) div breaklength ) else ( count := totalminutes div breaklength ) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=int(input()) for i in range(S): A=input() N="" B=sorted(set(A)) for j in B : if A.count(j)>2*A.count(j+j): N+=j print(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, S-1) do ( var A : String := (OclFile["System.in"]).readLine() ; var N : String := "" ; var B : Sequence := Set{}->union((A))->sort() ; for j : B do ( if (A->count(j)->compareTo(2 * A->count(j + j))) > 0 then ( N := N + j ) else skip) ; execute (N)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for p in range(n): l=[] s=str(input()) if len(s)==1 : print(s) elif len(s)==2 : if(s[0]!=s[1]): print(s) else : print() else : i=0 while itoInteger() ; for p : Integer.subrange(0, n-1) do ( var l : Sequence := Sequence{} ; var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; if (s)->size() = 1 then ( execute (s)->display() ) else (if (s)->size() = 2 then ( if (s->first() /= s[1+1]) then ( execute (s)->display() ) else ( execute (->display() ) ) else ( var i : int := 0 ; while (i->compareTo((s)->size())) < 0 do ( if i = (s)->size() - 1 then ( if (l)->excludes(s[i+1]) then ( execute ((s[i+1]) : l) ) else skip ) else (if s[i+1] /= s[i + 1+1] then ( if (l)->excludes(s[i+1]) then ( execute ((s[i+1]) : l) ) else skip ) else ( i := i + 1 ) ) ; i := i + 1) ; l := l->sort() ; for j : Integer.subrange(0, (l)->size()-1) do ( execute (l[j+1])->display()) ; execute (->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): word=input() curr=word[0] count=1 out=[] for j in range(1,len(word)): if curr==word[j]: count+=1 else : if count % 2==1 and curr not in out : out.append(curr) curr=word[j] count=1 if count % 2==1 and word[-1]not in out : out.append(word[-1]) out.sort() print(''.join(out)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var word : String := (OclFile["System.in"]).readLine() ; var curr : OclAny := word->first() ; var count : int := 1 ; var out : Sequence := Sequence{} ; for j : Integer.subrange(1, (word)->size()-1) do ( if curr = word[j+1] then ( count := count + 1 ) else ( if count mod 2 = 1 & (out)->excludes(curr) then ( execute ((curr) : out) ) else skip ; curr := word[j+1] ; count := 1 )) ; if count mod 2 = 1 & (out)->excludes(word->last()) then ( execute ((word->last()) : out) ) else skip ; out := out->sort() ; execute (StringLib.sumStringsWithSeparator((out), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- string_number=int(input()) string_list=[str(input())for i in range(string_number)] r=0 answer_set=set() for string in string_list : r=0 while r in range(len(string)): if r==len(string)-1 or string[r]!=string[r+1]: answer_set.add(string[r]) r+=1 else : r+=2 print("".join(sorted(list((answer_set))))) answer_set.clear() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var string_number : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var string_list : Sequence := Integer.subrange(0, string_number-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine()))))) ; var r : int := 0 ; var answer_set : Set := Set{}->union(()) ; for string : string_list do ( r := 0 ; while (Integer.subrange(0, (string)->size()-1))->includes(r) do ( if r = (string)->size() - 1 or string[r+1] /= string[r + 1+1] then ( execute ((string[r+1]) : answer_set) ; r := r + 1 ) else ( r := r + 2 )) ; execute (StringLib.sumStringsWithSeparator((((answer_set))->sort()), ""))->display() ; execute (answer_set /<: answer_set)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): string=input() left=0 right=1 res=[] while righttoInteger()-1) do ( var string : String := (OclFile["System.in"]).readLine() ; var left : int := 0 ; var right : int := 1 ; var res : Sequence := Sequence{} ; while (right->compareTo((string)->size())) < 0 do ( if string[right+1] = string[left+1] then ( left := left + 2 ; right := right + 2 ) else ( if (res)->excludes(string[left+1]) then ( execute ((string[left+1]) : res) ) else skip ; left := left + 1 ; right := right + 1 )) ; if left = (string)->size() - 1 then ( if (res)->excludes(string[left+1]) then ( execute ((string[left+1]) : res) ) else skip ) else skip ; res := res->sort() ; execute (StringLib.sumStringsWithSeparator((res), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def GCD(a,b): while a % b!=0 : a,b=b,a % b return b def LCM(a,b): return a*b//GCD(a,b) l=input().split(' ') x,y,a,b=int(l[0]),int(l[1]),int(l[2]),int(l[3]) lcm=LCM(x,y) print(b//lcm-(a-1)//lcm) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var l : OclAny := input().split(' ') ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y,a,b} := Sequence{("" + ((l->first())))->toInteger(),("" + ((l[1+1])))->toInteger(),("" + ((l[2+1])))->toInteger(),("" + ((l[3+1])))->toInteger()} ; var lcm : OclAny := LCM(x, y) ; execute (b div lcm - (a - 1) div lcm)->display(); operation GCD(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: while a mod b /= 0 do ( Sequence{a,b} := Sequence{b,a mod b}) ; return b; operation LCM(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a * b div GCD(a, b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): a,b,c=map(int,input().split()) ans=0 if a>0 : a-=1 ans+=1 if b>0 : b-=1 ans+=1 if c>0 : c-=1 ans+=1 cDown=False if c>1 : if c>0 and b>0 : c-=1 b-=1 ans+=1 cDown=True if a>0 and b>0 : a-=1 b-=1 ans+=1 if c>0 and b>0 and not cDown : c-=1 b-=1 ans+=1 if a>0 and c>0 : a-=1 c-=1 ans+=1 if a>0 and b>0 and c>0 : ans+=1 print(str(min(7,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; if a > 0 then ( a := a - 1 ; ans := ans + 1 ) else skip ; if b > 0 then ( b := b - 1 ; ans := ans + 1 ) else skip ; if c > 0 then ( c := c - 1 ; ans := ans + 1 ) else skip ; var cDown : boolean := false ; if c > 1 then ( if c > 0 & b > 0 then ( c := c - 1 ; b := b - 1 ; ans := ans + 1 ; cDown := true ) else skip ) else skip ; if a > 0 & b > 0 then ( a := a - 1 ; b := b - 1 ; ans := ans + 1 ) else skip ; if c > 0 & b > 0 & not(cDown) then ( c := c - 1 ; b := b - 1 ; ans := ans + 1 ) else skip ; if a > 0 & c > 0 then ( a := a - 1 ; c := c - 1 ; ans := ans + 1 ) else skip ; if a > 0 & b > 0 & c > 0 then ( ans := ans + 1 ) else skip ; execute (("" + ((Set{7, ans}->min()))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w,h=map(int,input().split()) u1,d1=map(int,input().split()) u2,d2=map(int,input().split()) while h : w+=h if h==d1 : w=max(0,w-u1) if h==d2 : w=max(0,w-u2) h-=1 print(w) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var u1 : OclAny := null; var d1 : OclAny := null; Sequence{u1,d1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var u2 : OclAny := null; var d2 : OclAny := null; Sequence{u2,d2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; while h do ( w := w + h ; if h = d1 then ( var w : OclAny := Set{0, w - u1}->max() ) else skip ; if h = d2 then ( w := Set{0, w - u2}->max() ) else skip ; h := h - 1) ; execute (w)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=lambda : map(int,input().split()) w,h=i(); a,b=i(); c,d=i() while h : w=max(0,w+h-[[0,a][h==b],c][h==d]); h-=1 print(w) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := i->apply(); var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := i->apply(); var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := i->apply() ; while h do ( var w : OclAny := Set{0, w + h - Sequence{Sequence{0}->union(Sequence{ a })->select(h = b)}->union(Sequence{ c })->select(h = d)}->max(); h := h - 1) ; execute (w)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input().split() b=input().split() c=input().split() w,h=int(a[0]),int(a[1]) u1,d1=b[0],b[1] u2,d2=c[0],c[1] arr={d1 : u1,d2 : u2} MAX=int(arr[str(max(int(d1),int(d2)))]) MIN=int(arr[str(min(int(d1),int(d2)))]) flag=1 while h>0 : w+=h if h==max(int(d1),int(d2))and flag==1 : w-=MAX if w<0 : w=0 flag=0 if h==min(int(d1),int(d2))and flag==0 : w-=MIN if w<0 : w=0 h-=1 print(w) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := input().split() ; var b : OclAny := input().split() ; var c : OclAny := input().split() ; var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := Sequence{("" + ((a->first())))->toInteger(),("" + ((a[1+1])))->toInteger()} ; var u1 : OclAny := null; var d1 : OclAny := null; Sequence{u1,d1} := Sequence{b->first(),b[1+1]} ; var u2 : OclAny := null; var d2 : OclAny := null; Sequence{u2,d2} := Sequence{c->first(),c[1+1]} ; var arr : Map := Map{ d1 |-> u1 }->union(Map{ d2 |-> u2 }) ; var MAX : int := ("" + ((arr[("" + ((Set{("" + ((d1)))->toInteger(), ("" + ((d2)))->toInteger()}->max())))+1])))->toInteger() ; var MIN : int := ("" + ((arr[("" + ((Set{("" + ((d1)))->toInteger(), ("" + ((d2)))->toInteger()}->min())))+1])))->toInteger() ; var flag : int := 1 ; while h > 0 do ( w := w + h ; if h = Set{("" + ((d1)))->toInteger(), ("" + ((d2)))->toInteger()}->max() & flag = 1 then ( w := w - MAX ; if w < 0 then ( var w : int := 0 ) else skip ; flag := 0 ) else skip ; if h = Set{("" + ((d1)))->toInteger(), ("" + ((d2)))->toInteger()}->min() & flag = 0 then ( w := w - MIN ; if w < 0 then ( w := 0 ) else skip ) else skip ; h := h - 1) ; execute (w)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- Read=lambda : map(int,input().split()) def solve(): if 2*hh+1 : if d==1 : return False while now<=n : L.append((2,now)) now+=1 else : while now<=n : L.append((1,now)) for _ in range(remain-1): if now==n : break L.append((now,now+1)) now+=1 now+=1 for x,y in L : print(x,y) return True if __name__=='__main__' : while True : try : n,d,h=Read() except : break if not solve(): print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Read : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; if __name__ = '__main__' then ( while true do ( try ( var n : OclAny := null; var d : OclAny := null; var h : OclAny := null; Sequence{n,d,h} := Read->apply()) catch (_e : OclException) do ( break) ; if not(solve()) then ( execute (-1)->display() ) else skip) ) else skip; operation solve() : OclAny pre: true post: true activity: if (2 * h->compareTo(d)) < 0 then ( return false ) else skip ; var L : Sequence := Sequence{} ; for i : Integer.subrange(1, h + 1-1) do ( execute ((Sequence{i, i + 1}) : L)) ; var remain : double := d - h ; var now : OclAny := h + 2 ; if not(remain) & (n->compareTo(h + 1)) > 0 then ( if d = 1 then ( return false ) else skip ; while (now->compareTo(n)) <= 0 do ( execute ((Sequence{2, now}) : L) ; now := now + 1) ) else ( while (now->compareTo(n)) <= 0 do ( execute ((Sequence{1, now}) : L) ; for _anon : Integer.subrange(0, remain - 1-1) do ( if now = n then ( break ) else skip ; execute ((Sequence{now, now + 1}) : L) ; now := now + 1) ; now := now + 1) ) ; for _tuple : L do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); execute (x)->display()) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w,h=(int(i)for i in input().split()) u1,d1=(int(i)for i in input().split()) u2,d2=(int(i)for i in input().split()) while h>0 : w+=h if h==d1 : w=max(w-u1,0) if h==d2 : w=max(w-u2,0) h-=1 print(w) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var u1 : OclAny := null; var d1 : OclAny := null; Sequence{u1,d1} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var u2 : OclAny := null; var d2 : OclAny := null; Sequence{u2,d2} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; while h > 0 do ( w := w + h ; if h = d1 then ( var w : OclAny := Set{w - u1, 0}->max() ) else skip ; if h = d2 then ( w := Set{w - u2, 0}->max() ) else skip ; h := h - 1) ; execute (w)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect n=int(input()) al=list(map(int,input().split())) bl=list(map(int,input().split())) cl=list(map(int,input().split())) al.sort() bl.sort() cl.sort() ans=0 tmp1=[n]*n tmp2=[n]*n for i in range(n): j=bisect.bisect_left(al,bl[i]) tmp1[i]=j for i in range(n): j=bisect.bisect_right(cl,bl[i]) tmp2[i]=n-j for i in range(n): ans+=tmp1[i]*tmp2[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var al : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var bl : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cl : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; al := al->sort() ; bl := bl->sort() ; cl := cl->sort() ; var ans : int := 0 ; var tmp1 : Sequence := MatrixLib.elementwiseMult(Sequence{ n }, n) ; var tmp2 : Sequence := MatrixLib.elementwiseMult(Sequence{ n }, n) ; for i : Integer.subrange(0, n-1) do ( var j : OclAny := bisect.bisect_left(al, bl[i+1]) ; tmp1[i+1] := j) ; for i : Integer.subrange(0, n-1) do ( j := bisect.bisect_right(cl, bl[i+1]) ; tmp2[i+1] := n - j) ; for i : Integer.subrange(0, n-1) do ( ans := ans + tmp1[i+1] * tmp2[i+1]) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int,sys.stdin.readline().rstrip())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def LS2(): return list(sys.stdin.readline().rstrip()) N=I() A,B,C=LI(),LI(),LI() A.sort() C.sort() from bisect import bisect_left,bisect_right ans=0 for i in range(N): b=B[i] ans+=bisect_left(A,b)*(N-bisect_right(C,b)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var N : OclAny := I() ; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{A,B,C} := Sequence{LI(),LI(),LI()} ; A := A->sort() ; C := C->sort() ; skip ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( var b : OclAny := B[i+1] ; ans := ans + bisect_left(A, b) * (N - bisect_right(C, b))) ; execute (ans)->display(); operation I() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.readLine().rstrip())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LI2() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().rstrip())->collect( _x | (OclType["int"])->apply(_x) )); operation S() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation LS() : OclAny pre: true post: true activity: return (sys.stdin.readLine().rstrip().split()); operation LS2() : OclAny pre: true post: true activity: return (sys.stdin.readLine().rstrip()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A,B,C=[list(map(int,input().split()))for _ in range(3)] for x in[A,B,C]: x.sort() def bsr(a,v,lo=0,hi=None): if hi==None : hi=len(a)-1 while lo<=hi : mid=(lo+hi)//2 if vtoInteger() ; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{A,B,C} := Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for x : Sequence{A}->union(Sequence{B}->union(Sequence{ C })) do ( x := x->sort()) ; skip ; var bt : Sequence := Sequence{} ; for b : B do ( bt := bt + Sequence{ Set{0, (N - bsr(C, b))}->max() }) ; for i : Integer.subrange(-1 + 1, (B)->size() - 2)->reverse() do ( bt[i+1] := bt[i+1] + bt[i + 1+1]) ; var r : int := 0 ; for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1; var ai : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); var bif : OclAny := bsr(B, a) ; if (bif->compareTo(N)) < 0 then ( r := r + bt[bif+1] ) else skip) ; execute (r)->display(); operation bsr(a : OclAny, v : OclAny, lo : int, hi : OclAny) : OclAny pre: true post: true activity: if lo->oclIsUndefined() then lo := 0 else skip; if hi->oclIsUndefined() then hi := null else skip; if hi = null then ( hi := (a)->size() - 1 ) else skip ; while (lo->compareTo(hi)) <= 0 do ( var mid : int := (lo + hi) div 2 ; if (v->compareTo(a[mid+1])) < 0 then ( hi := mid - 1 ) else ( lo := mid + 1 )) ; return lo; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify import sys,bisect,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod=10**9+7 INF=float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int,sys.stdin.readline().split())) n=inp() a=inpl() b=inpl() c=inpl() a.sort() b.sort() c.sort() lb=[0]*n res=0 for i in range(n): tmp=bisect.bisect_right(b,a[i]) if tmp==n : continue lb[tmp]+=1 llb=list(itertools.accumulate(lb)) rr=[0]*n for i in range(n): tmp=bisect.bisect_right(c,b[i]) if tmp==n : continue rr[tmp]+=llb[i] print(sum(list(itertools.accumulate(rr)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; var mod : double := (10)->pow(9) + 7 ; var INF : double := ("" + (('inf')))->toReal() ; skip ; skip ; var n : OclAny := inp() ; var a : OclAny := inpl() ; var b : OclAny := inpl() ; var c : OclAny := inpl() ; a := a->sort() ; b := b->sort() ; c := c->sort() ; var lb : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( var tmp : OclAny := bisect.bisect_right(b, a[i+1]) ; if tmp = n then ( continue ) else skip ; lb[tmp+1] := lb[tmp+1] + 1) ; var llb : Sequence := (itertools.accumulate(lb)) ; var rr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( tmp := bisect.bisect_right(c, b[i+1]) ; if tmp = n then ( continue ) else skip ; rr[tmp+1] := rr[tmp+1] + llb[i+1]) ; execute (((itertools.accumulate(rr)))->sum())->display(); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inpl() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) list_a=list(map(int,input().split())) list_b=list(map(int,input().split())) list_c=list(map(int,input().split())) list_a.sort() list_b.sort() list_c.sort() list_a.append(10**10) list_b.append(10**10) list_c.append(10**10) list_memo=[] i=0 j=0 k=0 start=0 list_ans=[] a_count=0 while ktoInteger() ; var list_a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var list_b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var list_c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; list_a := list_a->sort() ; list_b := list_b->sort() ; list_c := list_c->sort() ; execute (((10)->pow(10)) : list_a) ; execute (((10)->pow(10)) : list_b) ; execute (((10)->pow(10)) : list_c) ; var list_memo : Sequence := Sequence{} ; var i : int := 0 ; var j : int := 0 ; var k : int := 0 ; var start : int := 0 ; var list_ans : Sequence := Sequence{} ; var a_count : int := 0 ; while (k->compareTo(n)) < 0 do ( if list_c[k+1] = Set{list_a[i+1], list_b[j+1], list_c[k+1]}->min() then ( execute ((0) : list_memo) ; list_memo->last() := (list_memo.subrange(start+1, -1))->sum() ; execute ((list_memo->last()) : list_ans) ; start := (list_memo)->size() - 1 ; k := k + 1 ) else (if list_b[j+1] = Set{list_a[i+1], list_b[j+1], list_c[k+1]}->min() then ( execute ((a_count) : list_memo) ; j := j + 1 ) else ( execute ((0) : list_memo) ; a_count := a_count + 1 ; i := i + 1 ) ) ) ; execute ((list_ans)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) def brute(ind,su=[0,0,0],co=0): global ma if ind==7 : if su[0]<=a and su[1]<=b and su[2]<=c : ma=max(ma,co) return brute(ind+1,[su[i]+aa[ind][i]for i in range(3)],co+1) brute(ind+1,su,co) for i in range(t): a,b,c=list(map(int,input().split())) ma=0 aa=[[1,1,1],[1,1,0],[1,0,0],[1,0,1],[0,1,1],[0,1,0],[0,0,1]] brute(0) print(ma) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute ma : OclAny; operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; ma := 0 ; var aa : Sequence := Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))}->union(Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{ 0 }))}->union(Sequence{Sequence{1}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{Sequence{1}->union(Sequence{0}->union(Sequence{ 1 }))}->union(Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{ 1 }))}->union(Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{ 0 }))}->union(Sequence{ Sequence{0}->union(Sequence{0}->union(Sequence{ 1 })) })))))) ; brute(0) ; execute (ma)->display()); operation brute(ind : OclAny, su : OclAny, co : int) pre: true post: true activity: if su->oclIsUndefined() then su := Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) else skip; if co->oclIsUndefined() then co := 0 else skip; skip ; if ind = 7 then ( if (su->first()->compareTo(a)) <= 0 & (su[1+1]->compareTo(b)) <= 0 & (su[2+1]->compareTo(c)) <= 0 then ( ma := Set{ma, co}->max() ) else skip ; return ) else skip ; brute(ind + 1, Integer.subrange(0, 3-1)->select(i | true)->collect(i | (su[i+1] + aa[ind+1][i+1])), co + 1) ; brute(ind + 1, su, co); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import pow def countDigits(num): cnt=0 while(num>0): cnt+=1 num//=10 return cnt def sumFromStart(num,n,rem): num//=pow(10,rem) sum=0 while(num>0): sum+=(num % 10) num//=10 return sum def sumFromEnd(num,n): sum=0 for i in range(n): sum+=(num % 10) num//=10 return sum def getAverage(n,k,l): totalDigits=countDigits(n) if(totalDigits<(k+l)): return-1 sum1=sumFromEnd(n,l) sum2=sumFromStart(n,k,totalDigits-k) return(sum1+sum2)/(k+l) if __name__=='__main__' : n=123456 k=2 l=3 print(getAverage(n,k,l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( n := 123456 ; k := 2 ; l := 3 ; execute (getAverage(n, k, l))->display() ) else skip; operation countDigits(num : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; while (num > 0) do ( cnt := cnt + 1 ; num := num div 10) ; return cnt; operation sumFromStart(num : OclAny, n : OclAny, rem : OclAny) : OclAny pre: true post: true activity: num := num div (10)->pow(rem) ; var sum : int := 0 ; while (num > 0) do ( sum := sum + (num mod 10) ; num := num div 10) ; return sum; operation sumFromEnd(num : OclAny, n : OclAny) : OclAny pre: true post: true activity: sum := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + (num mod 10) ; num := num div 10) ; return sum; operation getAverage(n : OclAny, k : OclAny, l : OclAny) : OclAny pre: true post: true activity: var totalDigits : OclAny := countDigits(n) ; if ((totalDigits->compareTo((k + l))) < 0) then ( return -1 ) else skip ; var sum1 : OclAny := sumFromEnd(n, l) ; var sum2 : OclAny := sumFromStart(n, k, totalDigits - k) ; return (sum1 + sum2) / (k + l); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def term(n): d=2 a1=0 An=a1+(n-1)*d An=An**3 return An ; n=5 print(term(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; execute (term(n))->display(); operation term(n : OclAny) pre: true post: true activity: var d : int := 2 ; var a1 : int := 0 ; var An : int := a1 + (n - 1) * d ; An := (An)->pow(3) ; return An;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W=map(int,input().split()) a=[[-1]*(W+2)for _ in range(H+2)] odd_count=0 for i in range(1,H+1): tmp=list(map(int,input().split())) for j in range(1,W+1): a[i][j]=tmp[j-1] odd_count+=int(a[i][j]% 2==1) moves=[] routes=[] for h in range(1,H+1): tmp=[] for w in range(1,W+1): tmp.append((h,w)) if h % 2==1 : routes+=tmp else : routes+=tmp[: :-1] is_carrying=0 for i,(h,w)in enumerate(routes): if i==H*W-1 : break if odd_count==1 : break if a[h][w]% 2==1 and not is_carrying : tmp=(h,w) is_carrying=1 moves.append((h,w,routes[i+1][0],routes[i+1][1])) elif a[h][w]% 2==1 and is_carrying : is_carrying=0 odd_count-=2 elif a[h][w]% 2==0 and is_carrying : moves.append((h,w,routes[i+1][0],routes[i+1][1])) print(len(moves)) for move in moves : print(*move) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, H + 2-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ -1 }, (W + 2)))) ; var odd_count : int := 0 ; for i : Integer.subrange(1, H + 1-1) do ( var tmp : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(1, W + 1-1) do ( a[i+1][j+1] := tmp[j - 1+1] ; odd_count := odd_count + ("" + ((a[i+1][j+1] mod 2 = 1)))->toInteger())) ; var moves : Sequence := Sequence{} ; var routes : Sequence := Sequence{} ; for h : Integer.subrange(1, H + 1-1) do ( tmp := Sequence{} ; for w : Integer.subrange(1, W + 1-1) do ( execute ((Sequence{h, w}) : tmp)) ; if h mod 2 = 1 then ( routes := routes + tmp ) else ( routes := routes + tmp(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )) ; var is_carrying : int := 0 ; for _tuple : Integer.subrange(1, (routes)->size())->collect( _indx | Sequence{_indx-1, (routes)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{h, w} : OclAny := _tuple->at(_indx); if i = H * W - 1 then ( break ) else skip ; if odd_count = 1 then ( break ) else skip ; if a[h+1][w+1] mod 2 = 1 & not(is_carrying) then ( tmp := Sequence{h, w} ; is_carrying := 1 ; execute ((Sequence{h, w, routes[i + 1+1]->first(), routes[i + 1+1][1+1]}) : moves) ) else (if a[h+1][w+1] mod 2 = 1 & is_carrying then ( is_carrying := 0 ; odd_count := odd_count - 2 ) else (if a[h+1][w+1] mod 2 = 0 & is_carrying then ( execute ((Sequence{h, w, routes[i + 1+1]->first(), routes[i + 1+1][1+1]}) : moves) ) else skip ) ) ) ; execute ((moves)->size())->display() ; for move : moves do ( execute ((argument * (test (logical_test (comparison (expr (atom (name move))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=lambda :[*map(int,input().split())] h,w=f() g=[f()for _ in range(h)] a=[] for x in range(h): for y in range(w): if g[x][y]% 2 and(x+1)*(y+1)collect( _x | (OclType["int"])->apply(_x) )) ; var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := f->apply() ; var g : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (f->apply())) ; var a : Sequence := Sequence{} ; for x : Integer.subrange(0, h-1) do ( for y : Integer.subrange(0, w-1) do ( if g[x+1][y+1] mod 2 & ((x + 1) * (y + 1)->compareTo(h * w)) < 0 then ( (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name t))))))) ))))) : (suite = (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name y))) + (expr (atom (number (integer 1)))))))))))) <))) ; var w : OclAny := x ) (elif_clause elif (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name s))))))) ))))) : (suite = (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (number (integer 1)))))))))))) <))) else skip) ; var h : OclAny := y ; g[x+1][y+1] := g[x+1][y+1] - 1 ; g[s+1][t+1] := g[s+1][t+1] + 1 ; a := a + Sequence{ Sequence{x + 1, y + 1, s + 1, t + 1} })); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d,h=map(int,input().split()) if((n>2 and d==1)or 2*hcollect( _x | (OclType["int"])->apply(_x) ) ; if ((n > 2 & d = 1) or (2 * h->compareTo(d)) < 0) then ( exit((-1)->display()) ) else skip ; for i : Integer.subrange(0, h-1) do ( execute (i + 1)->display()) ; if (d /= h) then ( execute (1)->display() ; for i : Integer.subrange(0, d - h - 1-1) do ( execute (i + h + 2)->display()) ) else skip ; for i : Integer.subrange(0, n - d - 1-1) do ( execute (1 + (d = h))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import itertools import time import math import heapq from collections import defaultdict sys.setrecursionlimit(10**7) INF=10**18 MOD=10**9+7 read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines H,W=map(int,input().split()) A=[list(map(int,input().split()))for _ in range(H)] path=[] for i in range(H): if i % 2==0 : for j in range(W): x=(i,j) path.append(x) else : for j in range(W-1,-1,-1): x=(i,j) path.append(x) ans=[] for i in range(len(path)-1): p=path[i] p2=path[i+1] if A[p[0]][p[1]]% 2!=0 : A[p2[0]][p2[1]]+=1 ans.append((p[0]+1,p[1]+1,p2[0]+1,p2[1]+1)) print(len(ans)) for a in ans : print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; var INF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var path : Sequence := Sequence{} ; for i : Integer.subrange(0, H-1) do ( if i mod 2 = 0 then ( for j : Integer.subrange(0, W-1) do ( var x : OclAny := Sequence{i, j} ; execute ((x) : path)) ) else ( for j : Integer.subrange(-1 + 1, W - 1)->reverse() do ( x := Sequence{i, j} ; execute ((x) : path)) )) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, (path)->size() - 1-1) do ( var p : OclAny := path[i+1] ; var p2 : OclAny := path[i + 1+1] ; if A[p->first()+1][p[1+1]+1] mod 2 /= 0 then ( A[p2->first()+1][p2[1+1]+1] := A[p2->first()+1][p2[1+1]+1] + 1 ; execute ((Sequence{p->first() + 1, p[1+1] + 1, p2->first() + 1, p2[1+1] + 1}) : ans) ) else skip) ; execute ((ans)->size())->display() ; for a : ans do ( execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from collections import* H,W=map(int,input().split()) a=[list(map(int,input().split()))for _ in range(H)] ans=[] flag=False for i in range(H): if i % 2==0 : for j in range(W): if a[i][j]% 2==1 : if flag : ans.append((pi,pj,i,j)) flag=False else : flag=True else : if flag : ans.append((pi,pj,i,j)) pi,pj=i,j else : for j in range(W-1,-1,-1): if a[i][j]% 2==1 : if flag : ans.append((pi,pj,i,j)) flag=False else : flag=True else : if flag : ans.append((pi,pj,i,j)) pi,pj=i,j print(len(ans)) for a,b,c,d in ans : print(a+1,b+1,c+1,d+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ans : Sequence := Sequence{} ; var flag : boolean := false ; for i : Integer.subrange(0, H-1) do ( if i mod 2 = 0 then ( for j : Integer.subrange(0, W-1) do ( if a[i+1][j+1] mod 2 = 1 then ( if flag then ( execute ((Sequence{pi, pj, i, j}) : ans) ; flag := false ) else ( flag := true ) ) else ( if flag then ( execute ((Sequence{pi, pj, i, j}) : ans) ) else skip ) ; var pi : OclAny := null; var pj : OclAny := null; Sequence{pi,pj} := Sequence{i,j}) ) else ( for j : Integer.subrange(-1 + 1, W - 1)->reverse() do ( if a[i+1][j+1] mod 2 = 1 then ( if flag then ( execute ((Sequence{pi, pj, i, j}) : ans) ; flag := false ) else ( flag := true ) ) else ( if flag then ( execute ((Sequence{pi, pj, i, j}) : ans) ) else skip ) ; var pi : OclAny := null; var pj : OclAny := null; Sequence{pi,pj} := Sequence{i,j}) )) ; execute ((ans)->size())->display() ; for _tuple : ans do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); execute (MatrixLib.elementwiseAdd(a, 1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(): input=sys.stdin.readline H,W=map(int,input().split()) M=[list(map(int,input().split()))for _ in range(H)] count=0 manup=[] for y in range(H): for x in range(W): if M[y][x]% 2==1 : if x<(W-1): count+=1 manup.append([y+1,x+1,y+1,x+2]) M[y][x+1]+=1 elif y0 : for m in manup : print('{}{}{}{}'.format(m[0],m[1],m[2],m[3])) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var input : OclAny := (OclFile["System.in"]).readline ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var M : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var count : int := 0 ; var manup : Sequence := Sequence{} ; for y : Integer.subrange(0, H-1) do ( for x : Integer.subrange(0, W-1) do ( if M[y+1][x+1] mod 2 = 1 then ( if (x->compareTo((W - 1))) < 0 then ( count := count + 1 ; execute ((Sequence{y + 1}->union(Sequence{x + 1}->union(Sequence{y + 1}->union(Sequence{ x + 2 })))) : manup) ; M[y+1][x + 1+1] := M[y+1][x + 1+1] + 1 ) else (if (y->compareTo(H - 1)) < 0 then ( count := count + 1 ; execute ((Sequence{y + 1}->union(Sequence{x + 1}->union(Sequence{y + 2}->union(Sequence{ x + 1 })))) : manup) ; M[y + 1+1][x+1] := M[y + 1+1][x+1] + 1 ) else ( continue ) ) ) else skip)) ; execute (count)->display() ; if count > 0 then ( for m : manup do ( execute (StringLib.interpolateStrings('{}{}{}{}', Sequence{m->first(), m[1+1], m[2+1], m[3+1]}))->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(sum(i-jsum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) times=0 for i in range(1,n+1): for j in range(i,n+1): if i<=j and j<=i ^ j and i ^ j<=n : if itoInteger() ; var times : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(i, n + 1-1) do ( if (i->compareTo(j)) <= 0 & (j->compareTo(MathLib.bitwiseXor(i, j))) <= 0 & (MathLib.bitwiseXor(i, j)->compareTo(n)) <= 0 then ( if (i->compareTo(MathLib.bitwiseXor(i, j + j))) < 0 & (j->compareTo(MathLib.bitwiseXor(i, j + i))) < 0 & (MathLib.bitwiseXor(i, j)->compareTo(i + j)) < 0 then ( times := times + 1 ) else skip ) else skip)) ; execute (times)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for pratyush in range(int(input())): a,b,c=map(int,input().split()) k=0 while(k<7): if(a!=0): k,a=k+1,a-1 if(b!=0): k,b=k+1,b-1 if(c!=0): k,c=k+1,c-1 if((a==0 and b==0)or(c==0 and b==0)or(a==0 and c==0)or(a==0 and b==0 and c==0)): break if(a==0 or b==0 or c==0): k,a,b,c=k+1,0,0,0 break if(a==1 and b==1 and c==1): k,a,b,c=k+1,0,0,0 break if(a==1 or b==1 or c==1): k,a,b,c=k+2,0,0,0 break if(a==2 and b>=2 and c>=2)or(c>=2 and b==2 and a>=2)or(c==2 and a>=2 and b>=2): k,a,b,c=k+3,0,0,0 break if(a>=2 and b>=2 and c>=2): k,a,b,c=k+4,0,0,0 break print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for pratyush : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : int := 0 ; while (k < 7) do ( if (a /= 0) then ( var a : OclAny := null; Sequence{k,a} := Sequence{k + 1,a - 1} ) else skip ; if (b /= 0) then ( var b : OclAny := null; Sequence{k,b} := Sequence{k + 1,b - 1} ) else skip ; if (c /= 0) then ( var c : OclAny := null; Sequence{k,c} := Sequence{k + 1,c - 1} ) else skip ; if ((a = 0 & b = 0) or (c = 0 & b = 0) or (a = 0 & c = 0) or (a = 0 & b = 0 & c = 0)) then ( break ) else skip ; if (a = 0 or b = 0 or c = 0) then ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{k,a,b,c} := Sequence{k + 1,0,0,0} ; break ) else skip ; if (a = 1 & b = 1 & c = 1) then ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{k,a,b,c} := Sequence{k + 1,0,0,0} ; break ) else skip ; if (a = 1 or b = 1 or c = 1) then ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{k,a,b,c} := Sequence{k + 2,0,0,0} ; break ) else skip ; if (a = 2 & b >= 2 & c >= 2) or (c >= 2 & b = 2 & a >= 2) or (c = 2 & a >= 2 & b >= 2) then ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{k,a,b,c} := Sequence{k + 3,0,0,0} ; break ) else skip ; if (a >= 2 & b >= 2 & c >= 2) then ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{k,a,b,c} := Sequence{k + 4,0,0,0} ; break ) else skip) ; execute (k)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def func(): n=int(input()) count=0 for a in range(1,n+1): for b in range(a,n+1): c=a ^ b if a+b>c and b<=c<=n : count+=1 print(count) if __name__=='__main__' : func() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( func() ) else skip; operation func() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := 0 ; for a : Integer.subrange(1, n + 1-1) do ( for b : Integer.subrange(a, n + 1-1) do ( var c : int := MathLib.bitwiseXor(a, b) ; if (a + b->compareTo(c)) > 0 & (b->compareTo(c)) <= 0 & (c <= n) then ( count := count + 1 ) else skip)) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) count=0 for a in range(1,n+1): for b in range(1,n+1): if a!=b : c=a ^ b if c<=n and a+b>c and b+c>a and c+a>b : count+=1 print(count//6) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := 0 ; for a : Integer.subrange(1, n + 1-1) do ( for b : Integer.subrange(1, n + 1-1) do ( if a /= b then ( var c : int := MathLib.bitwiseXor(a, b) ; if (c->compareTo(n)) <= 0 & (a + b->compareTo(c)) > 0 & (b + c->compareTo(a)) > 0 & (c + a->compareTo(b)) > 0 then ( count := count + 1 ) else skip ) else skip)) ; execute (count div 6)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(s): zeroes=0 ones=0 for c in s : if c=='0' : zeroes+=1 else : ones+=1 if zeroes!=ones : print(1) print(s) else : print(2) print(f'{s[0]}{s[1:]}') n=input() s=input() solve(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : String := (OclFile["System.in"]).readLine() ; s := (OclFile["System.in"]).readLine() ; solve(s); operation solve(s : OclAny) pre: true post: true activity: var zeroes : int := 0 ; var ones : int := 0 ; for c : s do ( if c = '0' then ( zeroes := zeroes + 1 ) else ( ones := ones + 1 )) ; if zeroes /= ones then ( execute (1)->display() ; execute (s)->display() ) else ( execute (2)->display() ; execute (StringLib.formattedString('{s[0]}{s[1:]}'))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() s=input() count_1=0 count_0=0 for i in s : if i=="1" : count_1+=1 else : count_0+=1 if count_1==count_0 : print(2) print(s[0]+" "+s[1 :]) else : print(1) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var s : String := (OclFile["System.in"]).readLine() ; var count var n : String := (OclFile["System.in"]).readLine() : int := 0 ; var count_0 : int := 0 ; for i : s->characters() do ( if i = "1" then ( count var n : String := (OclFile["System.in"]).readLine() := count var n : String := (OclFile["System.in"]).readLine() + 1 ) else ( count_0 := count_0 + 1 )) ; if count var n : String := (OclFile["System.in"]).readLine() = count_0 then ( execute (2)->display() ; execute (s->first() + " " + s->tail())->display() ) else ( execute (1)->display() ; execute (s)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() if s.count('1')==s.count('0'): print(2) print(s[0]+' '+s[1 :]) else : print(1) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; if s->count('1') = s->count('0') then ( execute (2)->display() ; execute (s->first() + ' ' + s->tail())->display() ) else ( execute (1)->display() ; execute (s)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys a=[] mx=0 while True : try : i=input() start=0 end=len(i)-1 while i and i[start]=='' : start+=1 while i and i[end]=='' : end-=1 mx=max(mx,end-start+1) a.append(i[start : end+1]) except : break print('*'*(mx+2)) c=0 for i in a : print('*',end='') if(mx-len(i))% 2==0 : print(''*((mx-len(i))//2),end='') print(i,end='') print(''*((mx-len(i))//2),end='') elif(mx-len(i))% 2!=0 and c % 2==0 : print(''*((mx-len(i))//2),end='') print(i,end='') print(''*(((mx-len(i))-((mx-len(i))//2))),end='') c+=1 elif(mx-len(i))% 2!=0 and c % 2==1 : print(''*(((mx-len(i))-((mx-len(i))//2))),end='') print(i,end='') print(''*((mx-len(i))//2),end='') c+=1 print('*') print('*'*(mx+2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : Sequence := Sequence{} ; var mx : int := 0 ; while true do ( try ( var i : String := (OclFile["System.in"]).readLine() ; var start : int := 0 ; var end : double := (i)->size() - 1 ; while if i = "" then i else i[start+1] = '' endif do ( start := start + 1) ; while if i = "" then i else i[end+1] = '' endif do ( end := end - 1) ; mx := Set{mx, end - start + 1}->max() ; execute ((i.subrange(start+1, end + 1)) : a)) catch (_e : OclException) do ( break) ) ; execute (StringLib.nCopies('*', (mx + 2)))->display() ; var c : int := 0 ; for i : a do ( execute ('*')->display() ; if (mx - (i)->size()) mod 2 = 0 then ( execute (StringLib.nCopies('', ((mx - (i)->size()) div 2)))->display() ; execute (i)->display() ; execute (StringLib.nCopies('', ((mx - (i)->size()) div 2)))->display() ) else (if (mx - (i)->size()) mod 2 /= 0 & c mod 2 = 0 then ( execute (StringLib.nCopies('', ((mx - (i)->size()) div 2)))->display() ; execute (i)->display() ; execute (StringLib.nCopies('', (((mx - (i)->size()) - ((mx - (i)->size()) div 2)))))->display() ; c := c + 1 ) else (if (mx - (i)->size()) mod 2 /= 0 & c mod 2 = 1 then ( execute (StringLib.nCopies('', (((mx - (i)->size()) - ((mx - (i)->size()) div 2)))))->display() ; execute (i)->display() ; execute (StringLib.nCopies('', ((mx - (i)->size()) div 2)))->display() ; c := c + 1 ) else skip ) ) ; execute ('*')->display()) ; execute (StringLib.nCopies('*', (mx + 2)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(s): zeroes=s.count('0') ones=s.count('1') if zeroes!=ones : print(1) print(s) else : print(2) print(f'{s[0]}{s[1:]}') n=input() s=input() solve(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : String := (OclFile["System.in"]).readLine() ; s := (OclFile["System.in"]).readLine() ; solve(s); operation solve(s : OclAny) pre: true post: true activity: var zeroes : int := s->count('0') ; var ones : int := s->count('1') ; if zeroes /= ones then ( execute (1)->display() ; execute (s)->display() ) else ( execute (2)->display() ; execute (StringLib.formattedString('{s[0]}{s[1:]}'))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(s): zeroes=0 ones=0 for c in s : if c=='0' : zeroes+=1 else : ones+=1 if zeroes!=ones : print(1) print(s) else : print(2) print(f'{s[0]}{s[1:]}') n=input() s=input() solve(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : String := (OclFile["System.in"]).readLine() ; s := (OclFile["System.in"]).readLine() ; solve(s); operation solve(s : OclAny) pre: true post: true activity: var zeroes : int := 0 ; var ones : int := 0 ; for c : s do ( if c = '0' then ( zeroes := zeroes + 1 ) else ( ones := ones + 1 )) ; if zeroes /= ones then ( execute (1)->display() ; execute (s)->display() ) else ( execute (2)->display() ; execute (StringLib.formattedString('{s[0]}{s[1:]}'))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printGP(a,r,n): for i in range(0,n): curr_term=a*pow(r,i) print(curr_term,end=" ") a=2 r=3 n=5 printGP(a,r,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 2 ; r := 3 ; n := 5 ; printGP(a, r, n); operation printGP(a : OclAny, r : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( var curr_term : double := a * (r)->pow(i) ; execute (curr_term)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def midpoint(x1,x2,y1,y2): print((x1+x2)//2,",",(y1+y2)//2) x1,y1,x2,y2=-1,2,3,-6 midpoint(x1,x2,y1,y2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{x1,y1,x2,y2} := Sequence{-1,2,3,-6} ; midpoint(x1, x2, y1, y2); operation midpoint(x1 : OclAny, x2 : OclAny, y1 : OclAny, y2 : OclAny) pre: true post: true activity: execute ((x1 + x2) div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- L=[] A=0 B=0 try : while True : M=str(input()) L.append(M) except EOFError : pass N=len(L) L.remove(L[N-1]) N=len(L) for i in range(N): P=list(L[i]) P.remove(P[0]) if i==N-1 or i//3==0 : A=P.count('A') B=P.count('B') if A>B : A+=1 else : B+=1 print(A,B) else : A=P.count('A') B=P.count('B') Q=list(L[i+1]) if Q[0]=='A' : A+=1 else : B+=1 print(A,B) i+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var L : Sequence := Sequence{} ; var A : int := 0 ; var B : int := 0 ; try ( while true do ( var M : String := ("" + (((OclFile["System.in"]).readLine()))) ; execute ((M) : L))) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt pass))))) ; var N : int := (L)->size() ; execute ((L[N - 1+1]) /: L) ; N := (L)->size() ; for i : Integer.subrange(0, N-1) do ( var P : Sequence := (L[i+1]) ; execute ((P->first()) /: P) ; if i = N - 1 or i div 3 = 0 then ( A := P->count('A') ; B := P->count('B') ; if (A->compareTo(B)) > 0 then ( A := A + 1 ) else ( B := B + 1 ) ; execute (A)->display() ) else ( A := P->count('A') ; B := P->count('B') ; var Q : Sequence := (L[i + 1+1]) ; if Q->first() = 'A' then ( A := A + 1 ) else ( B := B + 1 ) ; execute (A)->display() ) ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ceilSearch(arr,low,high,x): if x<=arr[low]: return low if x>arr[high]: return-1 mid=(low+high)/2 ; if arr[mid]==x : return mid elif arr[mid]=low and x>arr[mid-1]: return mid else : return ceilSearch(arr,low,mid-1,x) arr=[1,2,8,10,10,12,19] n=len(arr) x=20 index=ceilSearch(arr,0,n-1,x); if index==-1 : print("Ceiling of %d doesn't exist in array " % x) else : print("ceiling of %d is %d" %(x,arr[index])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{8}->union(Sequence{10}->union(Sequence{10}->union(Sequence{12}->union(Sequence{ 19 })))))) ; var n : int := (arr)->size() ; x := 20 ; var index : OclAny := ceilSearch(arr, 0, n - 1, x); ; if index = -1 then ( execute (StringLib.format("Ceiling of %d doesn't exist in array ",x))->display() ) else ( execute (StringLib.format("ceiling of %d is %d",Sequence{x, arr[index+1]}))->display() ); operation ceilSearch(arr : OclAny, low : OclAny, high : OclAny, x : OclAny) : OclAny pre: true post: true activity: if (x->compareTo(arr[low+1])) <= 0 then ( return low ) else skip ; if (x->compareTo(arr[high+1])) > 0 then ( return -1 ) else skip ; var mid : double := (low + high) / 2; ; if arr[mid+1] = x then ( return mid ) else (if (arr[mid+1]->compareTo(x)) < 0 then ( if (mid + 1->compareTo(high)) <= 0 & (x->compareTo(arr[mid + 1+1])) <= 0 then ( return mid + 1 ) else ( return ceilSearch(arr, mid + 1, high, x) ) ) else ( if (mid - 1->compareTo(low)) >= 0 & (x->compareTo(arr[mid - 1+1])) > 0 then ( return mid ) else ( return ceilSearch(arr, low, mid - 1, x) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def R(): return map(int,next(sys.stdin).split()) t,=R() while t : t-=1 n,x=R() *a,=R() print('YNEOS'[a[-x : x]!=sorted(a)[-x : x]: : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := R() ; while t do ( t := t - 1 ; var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := R()) ; (testlist_star_expr (star_expr * (expr (atom (name a)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name a)))) ,)} := R(); operation R() : OclAny pre: true post: true activity: return (next(OclFile["System.in"]).split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n,x=map(int,input().split()) w=list(map(int,input().split())) if 2*x<=n : print("YES") else : d=sorted(w) s1=w[n-x : x] s2=sorted(s1) if s1==s2==d[n-x : x]: print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (2 * x->compareTo(n)) <= 0 then ( execute ("YES")->display() ) else ( var d : Sequence := w->sort() ; var s1 : OclAny := w.subrange(n - x+1, x) ; var s2 : Sequence := s1->sort() ; if s1 = s2 & (s2 == d.subrange(n - x+1, x)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as m inp=[] for a in range(0,int(input())): inp.append([[int(x)for x in input().split()],[int(x)for x in input().split()]]) def logic(n,x,arr): if 2*x<=n : return 'YES' a=sorted(arr) for j in range(n-x,x): if a[j]!=arr[j]: return 'NO' return 'YES' for t in inp : [n,x]=t[0] arr=t[1] print(logic(n,x,arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var inp : Sequence := Sequence{} ; for a : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute ((Sequence{input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))}->union(Sequence{ input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) })) : inp)) ; skip ; for t : inp do ( ; Sequence{n}->union(Sequence{ x }) := t->first() ; arr := t[1+1] ; execute (logic(n, x, arr))->display()); operation logic(n : OclAny, x : OclAny, arr : OclAny) : OclAny pre: true post: true activity: if (2 * x->compareTo(n)) <= 0 then ( return 'YES' ) else skip ; var a : Sequence := arr->sort() ; for j : Integer.subrange(n - x, x-1) do ( if a[j+1] /= arr[j+1] then ( return 'NO' ) else skip) ; return 'YES'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque import copy import heapq from math import sqrt import operator from operator import itemgetter import sys inf_var=0 if inf_var==1 : inf=open('input.txt','r') else : inf=sys.stdin input=inf.readline def read_one_int(): return int(input().rstrip('\n')) def read_one_float(): return float(input().rstrip('\n')) def read_list_of_ints(): res=[int(val)for val in(input().rstrip('\n')).split(' ')] return res def read_list_of_floats(): res=[float(val)for val in(input().rstrip('\n')).split(' ')] return res def read_list_of_ints_zero(): return[int(val)-1 for val in(input().rstrip('\n')).split()] def read_str(): return input().rstrip() def can_sort(a,x): can_swap=[False]*len(a) l=0 r=l+x while rtoInteger(); operation read_one_float() : OclAny pre: true post: true activity: return ("" + ((input().rstrip(' '))))->toReal(); operation read_list_of_ints() : OclAny pre: true post: true activity: var res : Sequence := (input().rstrip(' ')).split(' ')->select(val | true)->collect(val | (("" + ((val)))->toInteger())) ; return res; operation read_list_of_floats() : OclAny pre: true post: true activity: res := (input().rstrip(' ')).split(' ')->select(val | true)->collect(val | (("" + ((val)))->toReal())) ; return res; operation read_list_of_ints_zero() : OclAny pre: true post: true activity: return (input().rstrip(' ')).split()->select(val | true)->collect(val | (("" + ((val)))->toInteger() - 1)); operation read_str() : OclAny pre: true post: true activity: return input().rstrip(); operation can_sort(a : OclAny, x : OclAny) : OclAny pre: true post: true activity: var can_swap : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (a)->size()) ; var l : int := 0 ; var r : int := l + x ; while (r->compareTo((a)->size())) < 0 do ( can_swap[l+1] := true ; can_swap[r+1] := true ; l := l + 1 ; r := r + 1) ; var sorted_a : Sequence := a->sort() ; for i : Integer.subrange(0, (a)->size()-1) do ( if not(can_swap[i+1]) & sorted_a[i+1] /= a[i+1] then ( return 'NO' ) else skip) ; return 'YES'; operation main() pre: true post: true activity: var test : OclAny := read_one_int() ; for _anon : Integer.subrange(0, test-1) do ( var n : OclAny := null; Sequence{n,x} := read_list_of_ints() ; a := read_list_of_ints() ; res := can_sort(a, x) ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.buffer.readline def func(): b=sorted(a) perfect=dict() original=dict() for i in range(n): perfect[i]=b[i] original[i]=a[i] for i in range(n): if perfect[i]!=original[i]: if i-x<0 and i+x>n-1 : print('NO') return print('YES') for _ in range(int(input())): n,x=map(int,input().split()) a=list(map(int,input().split())) func() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.buffer.readline ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; func()); operation func() pre: true post: true activity: var b : Sequence := a->sort() ; var perfect : Map := (arguments ( )) ; var original : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( perfect[i+1] := b[i+1] ; original[i+1] := a[i+1]) ; for i : Integer.subrange(0, n-1) do ( if perfect[i+1] /= original[i+1] then ( if i - x < 0 & (i + x->compareTo(n - 1)) > 0 then ( execute ('NO')->display() ; return ) else skip ) else skip) ; execute ('YES')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import fileinput m=[] l=[] c=1 for line in fileinput.input(): m.append(line[:-1]) l.append(len(line)-1) r=max(l) print('*'*(r+2)) for i in range(0,len(m)): s1=' '*((r-l[i])//2) s2=' '*(r-len(s1)-l[i]) if(r-l[i])% 2==1 and c % 2==1 : print('*'+s1+m[i]+s2+'*') c+=1 elif(r-l[i])% 2==1 and c % 2==0 : print('*'+s2+m[i]+s1+'*') c+=1 else : print('*'+s1+m[i]+s2+'*') print('*'*(r+2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var m : Sequence := Sequence{} ; var l : Sequence := Sequence{} ; var c : int := 1 ; for line : fileinput.input() do ( execute ((line->front()) : m) ; execute (((line)->size() - 1) : l)) ; var r : OclAny := (l)->max() ; execute (StringLib.nCopies('*', (r + 2)))->display() ; for i : Integer.subrange(0, (m)->size()-1) do ( var s1 : String := StringLib.nCopies(' ', ((r - l[i+1]) div 2)) ; var s2 : String := StringLib.nCopies(' ', (r - (s1)->size() - l[i+1])) ; if (r - l[i+1]) mod 2 = 1 & c mod 2 = 1 then ( execute ('*' + s1 + m[i+1] + s2 + '*')->display() ; c := c + 1 ) else (if (r - l[i+1]) mod 2 = 1 & c mod 2 = 0 then ( execute ('*' + s2 + m[i+1] + s1 + '*')->display() ; c := c + 1 ) else ( execute ('*' + s1 + m[i+1] + s2 + '*')->display() ) ) ) ; execute (StringLib.nCopies('*', (r + 2)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): LIMIT=10000000 possible=set() primes=eulerlib.list_primes(LIMIT//2) end=eulerlib.sqrt(LIMIT) for i in range(len(primes)): p=primes[i] if p>end : break for j in range(i+1,len(primes)): q=primes[j] lcm=p*q if lcm>LIMIT : break multlimit=LIMIT//lcm multiplier=1 while multiplier*p<=multlimit : multiplier*=p maxmult=multiplier while multiplier % p==0 : multiplier//=p while multiplier*q<=multlimit : multiplier*=q maxmult=max(multiplier,maxmult) possible.add(maxmult*lcm) ans=sum(possible) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LIMIT : int := 10000000 ; var possible : Set := Set{}->union(()) ; var primes : OclAny := eulerlib.list_primes(LIMIT div 2) ; var end : double := eulerlib.sqrt(LIMIT) ; for i : Integer.subrange(0, (primes)->size()-1) do ( var p : OclAny := primes[i+1] ; if (p->compareTo(end)) > 0 then ( break ) else skip ; for j : Integer.subrange(i + 1, (primes)->size()-1) do ( var q : OclAny := primes[j+1] ; var lcm : double := p * q ; if (lcm->compareTo(LIMIT)) > 0 then ( break ) else skip ; var multlimit : int := LIMIT div lcm ; var multiplier : int := 1 ; while (multiplier * p->compareTo(multlimit)) <= 0 do ( multiplier := multiplier * p) ; var maxmult : int := multiplier ; while multiplier mod p = 0 do ( multiplier := multiplier div p ; while (multiplier * q->compareTo(multlimit)) <= 0 do ( multiplier := multiplier * q) ; maxmult := Set{multiplier, maxmult}->max()) ; execute ((maxmult * lcm) : possible))) ; var ans : OclAny := (possible)->sum() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=tuple(map(int,input().split(" "))) hs=tuple(map(int,input().split(" "))) enables=[h for h in hs if h>=K] print(len(enables)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var hs : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var enables : Sequence := hs->select(h | (h->compareTo(K)) >= 0)->collect(h | (h)) ; execute ((enables)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import os import math import string import collections ii=lambda : int(sys.stdin.buffer.readline().rstrip()) il=lambda : list(map(int,sys.stdin.buffer.readline().split())) fl=lambda : list(map(float,sys.stdin.buffer.readline().split())) iln=lambda n :[int(sys.stdin.buffer.readline().rstrip())for _ in range(n)] iss=lambda : sys.stdin.buffer.readline().decode().rstrip() sl=lambda : list(map(str,sys.stdin.buffer.readline().decode().split())) isn=lambda n :[sys.stdin.buffer.readline().decode().rstrip()for _ in range(n)] lcm=lambda x,y : x*y/math.gcd(x,y) MOD=10**9+7 MAX=float('inf') def main(): if os.getenv("LOCAL"): sys.stdin=open("input.txt","r") N,K=il() H=il() ret=0 for h in H : if h>=K : ret+=1 print(ret) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var ii : Function := lambda $$ : OclAny in (("" + ((sys.stdin.buffer.readLine().rstrip())))->toInteger()) ; var il : Function := lambda $$ : OclAny in (((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var fl : Function := lambda $$ : OclAny in (((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ))) ; var iln : Function := lambda n : OclAny in (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + ((sys.stdin.buffer.readLine().rstrip())))->toInteger()))) ; var iss : Function := lambda $$ : OclAny in (sys.stdin.buffer.readLine().decode().rstrip()) ; var sl : Function := lambda $$ : OclAny in (((sys.stdin.buffer.readLine().decode().split())->collect( _x | (OclType["String"])->apply(_x) ))) ; var isn : Function := lambda n : OclAny in (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (sys.stdin.buffer.readLine().decode().rstrip()))) ; var lcm : Function := lambda x : OclAny, y : OclAny in (x * y / (x)->gcd(y)) ; var MOD : double := (10)->pow(9) + 7 ; var MAX : double := ("" + (('inf')))->toReal() ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: if os.getenv("LOCAL") then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ) else skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := il->apply() ; var H : OclAny := il->apply() ; var ret : int := 0 ; for h : H do ( if (h->compareTo(K)) >= 0 then ( ret := ret + 1 ) else skip) ; execute (ret)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a=list(map(int,input().split(' '))) ans=0 a.sort(reverse=True) if a[0]>0 : ans+=1 a[0]-=1 if a[1]>0 : ans+=1 a[1]-=1 if a[2]>0 : ans+=1 a[2]-=1 if a[0]>0 and a[1]>0 : ans+=1 a[0]-=1 a[1]-=1 if a[1]>0 and a[2]>0 : ans+=1 a[1]-=1 a[2]-=1 if a[0]>0 and a[2]>0 : ans+=1 a[0]-=1 a[2]-=1 if a[0]>0 and a[1]>0 and a[2]>0 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; a := a->sort() ; if a->first() > 0 then ( ans := ans + 1 ; a->first() := a->first() - 1 ) else skip ; if a[1+1] > 0 then ( ans := ans + 1 ; a[1+1] := a[1+1] - 1 ) else skip ; if a[2+1] > 0 then ( ans := ans + 1 ; a[2+1] := a[2+1] - 1 ) else skip ; if a->first() > 0 & a[1+1] > 0 then ( ans := ans + 1 ; a->first() := a->first() - 1 ; a[1+1] := a[1+1] - 1 ) else skip ; if a[1+1] > 0 & a[2+1] > 0 then ( ans := ans + 1 ; a[1+1] := a[1+1] - 1 ; a[2+1] := a[2+1] - 1 ) else skip ; if a->first() > 0 & a[2+1] > 0 then ( ans := ans + 1 ; a->first() := a->first() - 1 ; a[2+1] := a[2+1] - 1 ) else skip ; if a->first() > 0 & a[1+1] > 0 & a[2+1] > 0 then ( ans := ans + 1 ) else skip ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np N,K=map(int,input().split()) h=np.array(list(map(int,input().split()))) print(np.count_nonzero(h>=K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h : Sequence := (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; execute ()->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from enum import Enum from queue import Queue import numpy as np import collections import bisect import sys import math from scipy.sparse.csgraph import floyd_warshall 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) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( if (h[i+1]->compareTo(K)) >= 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import heapq import math import fractions import bisect import itertools from collections import Counter from collections import deque from operator import itemgetter def input(): return sys.stdin.readline().strip() def mp(): return map(int,input().split()) def lmp(): return list(map(int,input().split())) n,k=mp() h=lmp() ans=0 for i in range(n): if h[i]>=k : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := mp() ; var h : OclAny := lmp() ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (h[i+1]->compareTo(k)) >= 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation mp() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation lmp() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isVowel(c): vowel="aeiou" for i in range(len(vowel)): if(vowel[i]==c): return True return False def printRLE(str,typed): n=len(str) m=len(typed) j=0 for i in range(n): if str[i]!=typed[j]: return False if isVowel(str[i])==False : j=j+1 continue count1=1 while(icount2 : return False return True name="alex" typed="aaalaeex" if(printRLE(name,typed)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var name : String := "alex" ; typed := "aaalaeex" ; if (printRLE(name, typed)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isVowel(c : OclAny) : OclAny pre: true post: true activity: var vowel : String := "aeiou" ; for i : Integer.subrange(0, (vowel)->size()-1) do ( if (vowel[i+1] = c) then ( return true ) else skip) ; return false; operation printRLE(OclType["String"] : OclAny, typed : OclAny) : OclAny pre: true post: true activity: var n : int := (OclType["String"])->size() ; var m : int := (typed)->size() ; var j : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ("" + ([i+1])) /= typed[j+1] then ( return false ) else skip ; if isVowel(("" + ([i+1]))) = false then ( j := j + 1 ; continue ) else skip ; var count1 : int := 1 ; while ((i->compareTo(n - 1)) < 0 & (("" + ([i+1])) = ("" + ([i + 1+1])))) do ( count1 := count1 + 1 ; var i : OclAny := i + 1) ; var count2 : int := 1 ; while ((j->compareTo(m - 1)) < 0 & typed[j+1] = ("" + ([i+1]))) do ( count2 := count2 + 1 ; j := j + 1) ; if (count1->compareTo(count2)) > 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=2 def isVowel(ch): return(ch=='a' or ch=='e' or ch=='i' or ch=='o' or ch=='u') def performQueries(str1,len1,queries,q): pre=[0 for i in range(len1)] if(isVowel(str1[0])): pre[0]=1 else : pre[0]=0 for i in range(0,len1,1): if(isVowel(str1[i])): pre[i]=1+pre[i-1] else : pre[i]=pre[i-1] for i in range(q): if(queries[i][0]==0): print(pre[queries[i][1]]) else : print(pre[queries[i][1]]-pre[queries[i][0]-1]) if __name__=='__main__' : str1="geeksforgeeks" len1=len(str1) queries=[[1,3],[2,4],[1,9]] q=len(queries) performQueries(str1,len1,queries,q) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 2 ; skip ; skip ; if __name__ = '__main__' then ( str1 := "geeksforgeeks" ; len1 := (str1)->size() ; queries := Sequence{Sequence{1}->union(Sequence{ 3 })}->union(Sequence{Sequence{2}->union(Sequence{ 4 })}->union(Sequence{ Sequence{1}->union(Sequence{ 9 }) })) ; q := (queries)->size() ; performQueries(str1, len1, queries, q) ) else skip; operation isVowel(ch : OclAny) : OclAny pre: true post: true activity: return (ch = 'a' or ch = 'e' or ch = 'i' or ch = 'o' or ch = 'u'); operation performQueries(str1 : OclAny, len1 : OclAny, queries : OclAny, q : OclAny) pre: true post: true activity: var pre : Sequence := Integer.subrange(0, len1-1)->select(i | true)->collect(i | (0)) ; if (isVowel(str1->first())) then ( pre->first() := 1 ) else ( pre->first() := 0 ) ; for i : Integer.subrange(0, len1-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (isVowel(str1[i+1])) then ( pre[i+1] := 1 + pre[i - 1+1] ) else ( pre[i+1] := pre[i - 1+1] )) ; for i : Integer.subrange(0, q-1) do ( if (queries[i+1]->first() = 0) then ( execute (pre[queries[i+1][1+1]+1])->display() ) else ( execute (pre[queries[i+1][1+1]+1] - pre[queries[i+1]->first() - 1+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_CHAR=26 def arekAnagrams(str1,str2,k): n=len(str1) if(len(str2)!=n): return False count1=[0]*MAX_CHAR count2=[0]*MAX_CHAR for i in range(n): count1[ord(str1[i])-ord('a')]+=1 for i in range(n): count2[ord(str2[i])-ord('a')]+=1 count=0 for i in range(MAX_CHAR): if(count1[i]>count2[i]): count=count+abs(count1[i]-count2[i]) return(count<=k) if __name__=='__main__' : str1="anagram" str2="grammar" k=2 if(arekAnagrams(str1,str2,k)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_CHAR : int := 26 ; skip ; if __name__ = '__main__' then ( str1 := "anagram" ; str2 := "grammar" ; k := 2 ; if (arekAnagrams(str1, str2, k)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation arekAnagrams(str1 : OclAny, str2 : OclAny, k : OclAny) : OclAny pre: true post: true activity: var n : int := (str1)->size() ; if ((str2)->size() /= n) then ( return false ) else skip ; var count1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX_CHAR) ; var count2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX_CHAR) ; for i : Integer.subrange(0, n-1) do ( count1[(str1[i+1])->char2byte() - ('a')->char2byte()+1] := count1[(str1[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; for i : Integer.subrange(0, n-1) do ( count2[(str2[i+1])->char2byte() - ('a')->char2byte()+1] := count2[(str2[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; var count : int := 0 ; for i : Integer.subrange(0, MAX_CHAR-1) do ( if ((count1[i+1]->compareTo(count2[i+1])) > 0) then ( count := count + (count1[i+1] - count2[i+1])->abs() ) else skip) ; return ((count->compareTo(k)) <= 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CountSwap(s,n): s=list(s) count=0 ans=True for i in range(n//2): left=i right=n-left-1 while leftcompareTo(right)) < 0 do ( if s[left+1] = s[right+1] then ( break ) else ( right := right - 1 )) ; if left = right then ( ans := false ; break ) else ( for j : Integer.subrange(right, n - left - 1-1) do (suite) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(): lines=sys.stdin.readlines() lines=[line.strip()for line in lines] maxlen=max(len(line)for line in lines) print('*'*(maxlen+2)) left=True for line in lines : space=maxlen-len(line) if space % 2==0 : lpad=rpad=space//2 elif left : lpad=space//2 rpad=space-lpad left=False else : rpad=space//2 lpad=space-rpad left=True print('*'+' '*lpad+line+' '*rpad+'*') print('*'*(maxlen+2)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: var lines : OclAny := (OclFile["System.in"]).readlines() ; lines := lines->select(line | true)->collect(line | (line->trim())) ; var maxlen : OclAny := ((argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name line)))))))) ))))))) (comp_for for (exprlist (expr (atom (name line)))) in (logical_test (comparison (expr (atom (name lines))))))))->max() ; execute (StringLib.nCopies('*', (maxlen + 2)))->display() ; var left : boolean := true ; for line : lines do ( var space : double := maxlen - (line)->size() ; if space mod 2 = 0 then ( var lpad : OclAny := space div 2; var rpad : int := space div 2 ) else (if left then ( lpad := space div 2 ; rpad := space - lpad ; left := false ) else ( rpad := space div 2 ; lpad := space - rpad ; left := true ) ) ; execute ('*' + StringLib.nCopies(' ', lpad) + line + StringLib.nCopies(' ', rpad) + '*')->display()) ; execute (StringLib.nCopies('*', (maxlen + 2)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def countSC(N): res=(int(math.sqrt(N))+int(N**(1/3))-int(math.sqrt(N**(1/3)))) return res N=20 print("Number of squares and cubes is",countSC(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; N := 20 ; execute ("Number of squares and cubes is")->display(); operation countSC(N : OclAny) : OclAny pre: true post: true activity: var res : double := (("" + (((N)->sqrt())))->toInteger() + ("" + (((N)->pow((1 / 3)))))->toInteger() - ("" + ((((N)->pow((1 / 3)))->sqrt())))->toInteger()) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def lucas_sequence(s,n): m=defaultdict(lambda : 0) for i in range(0,n): m[s[i]]+=1 v1,v2=[],[] for it in m : v1.append(m[it]) v1.sort() if v1[0]==1 and v1[1]==2 : v1[0],v1[1]=2,1 else : return "NO" a,b=2,1 v2.append(a) v2.append(b) for i in range(0,len(v1)-2): v2.append(a+b) a,b=b,a+b flag=1 for i in range(0,len(v1)): if v1[i]!=v2[i]: flag=0 break if flag==1 : return "YES" else : return "NO" if __name__=="__main__" : s="oooeeeeqkk" n=len(s) print(lucas_sequence(s,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( s := "oooeeeeqkk" ; n := (s)->size() ; execute (lucas_sequence(s, n))->display() ) else skip; operation lucas_sequence(s : OclAny, n : OclAny) : OclAny pre: true post: true activity: var m : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; for i : Integer.subrange(0, n-1) do ( m[s[i+1]+1] := m[s[i+1]+1] + 1) ; var v1 : OclAny := null; var v2 : OclAny := null; Sequence{v1,v2} := Sequence{Sequence{},Sequence{}} ; for it : m do ( execute ((m[it+1]) : v1)) ; v1 := v1->sort() ; if v1->first() = 1 & v1[1+1] = 2 then ( var v1->first() : OclAny := null; var v1[1+1] : OclAny := null; Sequence{v1->first(),v1[1+1]} := Sequence{2,1} ) else ( return "NO" ) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{2,1} ; execute ((a) : v2) ; execute ((b) : v2) ; for i : Integer.subrange(0, (v1)->size() - 2-1) do ( execute ((a + b) : v2) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a + b}) ; var flag : int := 1 ; for i : Integer.subrange(0, (v1)->size()-1) do ( if v1[i+1] /= v2[i+1] then ( flag := 0 ; break ) else skip) ; if flag = 1 then ( return "YES" ) else ( return "NO" ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect l='001 011 022 122 223 333 444'.split() for _ in range(int(input())): print(bisect(l,'{}{}{}'.format(*sorted(min(int(s),4)for s in input().split())))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var l : OclAny := '001 011 022 122 223 333 444'.split() ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (bisect(l, StringLib.interpolateStrings('{}{}{}', Sequence{(argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 4))))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))})))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findRepeatFirstN2(s): p=-1 for i in range(len(s)): for j in range(i+1,len(s)): if(s[i]==s[j]): p=i break if(p!=-1): break return p if __name__=="__main__" : str="geeksforgeeks" pos=findRepeatFirstN2(str) if(pos==-1): print("Not found") else : print(str[pos]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var OclType["String"] : String := "geeksforgeeks" ; var pos : OclAny := findRepeatFirstN2(OclType["String"]) ; if (pos = -1) then ( execute ("Not found")->display() ) else ( execute (("" + ([pos+1])))->display() ) ) else skip; operation findRepeatFirstN2(s : OclAny) : OclAny pre: true post: true activity: var p : int := -1 ; for i : Integer.subrange(0, (s)->size()-1) do ( for j : Integer.subrange(i + 1, (s)->size()-1) do ( if (s[i+1] = s[j+1]) then ( p := i ; break ) else skip) ; if (p /= -1) then ( break ) else skip) ; return p; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def relativeComplement(arr1,arr2,n,m): i=0 j=0 while(iarr2[j]): j+=1 elif(arr1[i]==arr2[j]): i+=1 j+=1 while(iunion(Sequence{6}->union(Sequence{10}->union(Sequence{12}->union(Sequence{ 15 })))) ; arr2 := Sequence{1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{10}->union(Sequence{ 16 })))) ; n := (arr1)->size() ; m := (arr2)->size() ; relativeComplement(arr1, arr2, n, m); operation relativeComplement(arr1 : OclAny, arr2 : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: var i : int := 0 ; var j : int := 0 ; while ((i->compareTo(n)) < 0 & (j->compareTo(m)) < 0) do ( if ((arr1[i+1]->compareTo(arr2[j+1])) < 0) then ( execute (arr1[i+1])->display() ; i := i + 1 ) else (if ((arr1[i+1]->compareTo(arr2[j+1])) > 0) then ( j := j + 1 ) else (if (arr1[i+1] = arr2[j+1]) then ( i := i + 1 ; j := j + 1 ) else skip ) ) ) ; while ((i->compareTo(n)) < 0) do ( execute (arr1[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def lengthOfLongestSubstring(self,s): charMap={} for i in range(256): charMap[i]=-1 ls=len(s) i=max_len=0 for j in range(ls): if charMap[ord(s[j])]>=i : i=charMap[ord(s[j])]+1 charMap[ord(s[j])]=j max_len=max(max_len,j-i+1) return max_len ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation lengthOfLongestSubstring(s : OclAny) : OclAny pre: true post: true activity: var charMap : OclAny := Set{} ; for i : Integer.subrange(0, 256-1) do ( charMap[i+1] := -1) ; var ls : int := (s)->size() ; var i : OclAny := 0; var max_len : int := 0 ; for j : Integer.subrange(0, ls-1) do ( if (charMap[(s[j+1])->char2byte()+1]->compareTo(i)) >= 0 then ( i := charMap[(s[j+1])->char2byte()+1] + 1 ) else skip ; charMap[(s[j+1])->char2byte()+1] := j ; max_len := Set{max_len, j - i + 1}->max()) ; return max_len; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from typing import List,Tuple def smallest_m_divisible(t : int,testcases : List[Tuple[int,int,List[int]]])->List[int]: answer=[] for n,m,arr in testcases : mod={} for x in arr : r=x % m if r in mod : mod[r]+=1 else : mod[r]=1 ct=0 if 0 in mod : ct+=1 mod.pop(0) for x in mod : y=m-x if x==y : ct+=1 continue if mod[x]!=0 : a=mod[x] if y in mod : b=mod[y] ct+=1+max(0,abs(a-b)-1) mod[y]=0 else : ct+=a mod[x]=0 answer.append(ct) return answer t=int(input()) a=[] for i in range(t): n,m=map(int,input().split()) b=[int(_)for _ in input().split()] a.append((n,m,b)) c=smallest_m_divisible(t,a) for i in c : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := Sequence{} ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; b := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; execute ((Sequence{n, m, b}) : a)) ; var c : OclAny := smallest_m_divisible(t, a) ; for i : c do ( execute (i)->display()); operation smallest_m_divisible(t : int, testcases : List[Tuple[OclType["int"]+1][OclType["int"]+1][List[OclType["int"]+1]+1]+1]) : OclAny pre: true post: true activity: var answer : Sequence := Sequence{} ; for _tuple : testcases do (var _indx : int := 1; var n : OclAny := _tuple->at(_indx); _indx := _indx + 1; var m : OclAny := _tuple->at(_indx); _indx := _indx + 1; var arr : OclAny := _tuple->at(_indx); var mod : OclAny := Set{} ; for x : arr do ( var r : int := x mod m ; if (mod)->includes(r) then ( mod[r+1] := mod[r+1] + 1 ) else ( mod[r+1] := 1 )) ; var ct : int := 0 ; if (mod)->includes(0) then ( ct := ct + 1 ; mod := mod->excludingAt(0+1) ) else skip ; for x : mod do ( var y : double := m - x ; if x = y then ( ct := ct + 1 ; continue ) else skip ; if mod[x+1] /= 0 then ( var a : OclAny := mod[x+1] ; if (mod)->includes(y) then ( var b : OclAny := mod[y+1] ; ct := ct + 1 + Set{0, (a - b)->abs() - 1}->max() ; mod[y+1] := 0 ) else ( ct := ct + a ) ) else skip ; mod[x+1] := 0) ; execute ((ct) : answer)) ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline t=int(input()) for _ in range(t): n,m=map(int,input().split()) ar=list(map(int,input().split())) mods=[0]*(10**5) for x in range(n): mods[ar[x]% m]+=1 i=1 j=m-1 s=0 if mods[0]>0 : s+=1 while i0 : s+=1 print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ar : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mods : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((10)->pow(5))) ; for x : Integer.subrange(0, n-1) do ( mods[ar[x+1] mod m+1] := mods[ar[x+1] mod m+1] + 1) ; var i : int := 1 ; var j : double := m - 1 ; var s : int := 0 ; if mods->first() > 0 then ( s := s + 1 ) else skip ; while (i->compareTo(j)) < 0 do ( if i + j = m then ( if Set{mods[i+1], mods[j+1]}->min() then ( var k : OclAny := Set{mods[i+1], mods[j+1]}->min() ; mods[i+1] := mods[i+1] - k ; mods[j+1] := mods[j+1] - k ; s := s + 1 ; if mods[i+1] or mods[j+1] then ( s := s + Set{mods[i+1], mods[j+1]}->max() - 1 ) else skip ) else ( s := s + Set{mods[i+1], mods[j+1]}->max() ) ) else skip ; i := i + 1 ; j := j - 1) ; if m mod 2 = 0 & mods[m div 2+1] > 0 then ( s := s + 1 ) else skip ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=map(int,input().split()) a=list(map(int,input().split())) d={} for i in a : if(i % m in d): d[i % m]+=1 else : d[i % m]=1 cnt=0 for i in d : if(d[i]==0): continue if(i==0): cnt+=1 d[i]=0 if(m-i in d and d[m-i]!=0): if(m % 2==0 and i==m//2): cnt+=1 d[i]=0 else : if(abs(d[i]-d[m-i])<=1): cnt+=1 d[i]=0 d[m-i]=0 else : x=min(d[i],d[m-i]) if(d[i]==x): d[i]=0 d[m-i]-=x+1 cnt+=1 else : d[m-i]=0 d[i]-=x+1 cnt+=1 for i in d : cnt+=d[i] print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := Set{} ; for i : a do ( if ((d)->includes(i mod m)) then ( d[i mod m+1] := d[i mod m+1] + 1 ) else ( d[i mod m+1] := 1 )) ; var cnt : int := 0 ; for i : d do ( if (d[i+1] = 0) then ( continue ) else skip ; if (i = 0) then ( cnt := cnt + 1 ; d[i+1] := 0 ) else skip ; if ((d)->includes(m - i) & d[m - i+1] /= 0) then ( if (m mod 2 = 0 & i = m div 2) then ( cnt := cnt + 1 ; d[i+1] := 0 ) else ( if ((d[i+1] - d[m - i+1])->abs() <= 1) then ( cnt := cnt + 1 ; d[i+1] := 0 ; d[m - i+1] := 0 ) else ( var x : OclAny := Set{d[i+1], d[m - i+1]}->min() ; if (d[i+1] = x) then ( d[i+1] := 0 ; d[m - i+1] := d[m - i+1] - x + 1 ; cnt := cnt + 1 ) else ( d[m - i+1] := 0 ; d[i+1] := d[i+1] - x + 1 ; cnt := cnt + 1 ) ) ) ) else skip) ; for i : d do ( cnt := cnt + d[i+1]) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for pratyush in range(int(input())): n,m=map(int,input().split()) a=list(map(int,input().split())) f,c=[],0 for i in range(m): f.append(0) for i in range(n): f[a[i]% m]+=1 for i in range((m//2)+1): if f[i]>0 : if i==0 or(m % 2==0 and i==m/2): c+=1 else : x=max(f[i],f[m-i])-min(f[i],f[m-i]) if x<=1 : c+=1 else : c+=1+(x-1) elif i!=0 and f[i]==0 and f[m-i]>0 : c+=f[m-i] print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for pratyush : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var f : OclAny := null; var c : OclAny := null; Sequence{f,c} := Sequence{Sequence{},0} ; for i : Integer.subrange(0, m-1) do ( execute ((0) : f)) ; for i : Integer.subrange(0, n-1) do ( f[a[i+1] mod m+1] := f[a[i+1] mod m+1] + 1) ; for i : Integer.subrange(0, (m div 2) + 1-1) do ( if f[i+1] > 0 then ( if i = 0 or (m mod 2 = 0 & i = m / 2) then ( c := c + 1 ) else ( var x : double := Set{f[i+1], f[m - i+1]}->max() - Set{f[i+1], f[m - i+1]}->min() ; if x <= 1 then ( c := c + 1 ) else ( c := c + 1 + (x - 1) ) ) ) else (if i /= 0 & f[i+1] = 0 & f[m - i+1] > 0 then ( c := c + f[m - i+1] ) else skip)) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=[int(x)for x in input().split(' ')] a=[int(x)for x in input().split(' ')] cnt=[0]*m for v in a : cnt[v % m]+=1 ans=0 if cnt[0]>=1 : ans+=1 for i in range(1,m): if cnt[i]==0 : continue if cnt[i]>=1 and cnt[m-i]>=1 : if cnt[i]==cnt[m-i]: ans+=1 else : max_v=max(cnt[i],cnt[m-i]) min_v=min(cnt[i],cnt[m-i]) if max_v==min_v+1 : ans+=1 else : ans+=max_v-min_v cnt[i]=0 cnt[m-i]=0 else : ans+=cnt[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a : Sequence := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; for v : a do ( cnt[v mod m+1] := cnt[v mod m+1] + 1) ; var ans : int := 0 ; if cnt->first() >= 1 then ( ans := ans + 1 ) else skip ; for i : Integer.subrange(1, m-1) do ( if cnt[i+1] = 0 then ( continue ) else skip ; if cnt[i+1] >= 1 & cnt[m - i+1] >= 1 then ( if cnt[i+1] = cnt[m - i+1] then ( ans := ans + 1 ) else ( var max_v : OclAny := Set{cnt[i+1], cnt[m - i+1]}->max() ; var min_v : OclAny := Set{cnt[i+1], cnt[m - i+1]}->min() ; if max_v = min_v + 1 then ( ans := ans + 1 ) else ( ans := ans + max_v - min_v ) ) ; cnt[i+1] := 0 ; cnt[m - i+1] := 0 ) else ( ans := ans + cnt[i+1] )) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys lis=[] try : while(True): i=input() lis.append(i.strip('\n')) except EOFError : pass max_len=max([len(x)for x in lis]) print('*'*(max_len+2)) cur=0 for i in lis : left_spaces=max_len-len(i) left=left_spaces//2 if(left_spaces % 2==1): left+=cur cur=(cur+1)% 2 right=left_spaces-left print('*'+' '*left+i+' '*right+'*') print('*'*(max_len+2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var lis : Sequence := Sequence{} ; try ( while (true) do ( var i : String := (OclFile["System.in"]).readLine() ; execute ((i->trim()) : lis))) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt pass))))) ; var max_len : OclAny := (lis->select(x | true)->collect(x | ((x)->size())))->max() ; execute (StringLib.nCopies('*', (max_len + 2)))->display() ; var cur : int := 0 ; for i : lis do ( var left_spaces : double := max_len - (i)->size() ; var left : int := left_spaces div 2 ; if (left_spaces mod 2 = 1) then ( left := left + cur ; cur := (cur + 1) mod 2 ) else skip ; var right : double := left_spaces - left ; execute ('*' + StringLib.nCopies(' ', left) + i + StringLib.nCopies(' ', right) + '*')->display()) ; execute (StringLib.nCopies('*', (max_len + 2)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- NMK=list(map(int,input().split(' '))) N=NMK[0] M=NMK[1] K=NMK[2] input_list=list(map(int,input().split(' '))) input_list.sort(reverse=True) sum=0 sum+=(input_list[0]*K+input_list[1])*(M//(K+1)) sum+=(input_list[0]*(M %(K+1))) print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var NMK : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var N : OclAny := NMK->first() ; var M : OclAny := NMK[1+1] ; var K : OclAny := NMK[2+1] ; var input_list : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; input_list := input_list->sort() ; var sum : int := 0 ; sum := sum + (input_list->first() * K + input_list[1+1]) * (M div (K + 1)) ; sum := sum + (input_list->first() * (M mod (K + 1))) ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) diff=[abs(arr[i]-arr[i+1])for i in range(n-1)] dp=[[0,0,0]for _ in range(n-1)] dp[0][1]=diff[0] for i in range(1,n-1): dp[i][0]=max(dp[i-1][0],dp[i-1][1],dp[i-1][2]) dp[i][1]=max(dp[i-1][2]+diff[i],diff[i]) dp[i][2]=dp[i-1][1]-diff[i] print(max(dp[n-2][0],dp[n-2][1],dp[n-2][2])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var diff : Sequence := Integer.subrange(0, n - 1-1)->select(i | true)->collect(i | ((arr[i+1] - arr[i + 1+1])->abs())) ; var dp : Sequence := Integer.subrange(0, n - 1-1)->select(_anon | true)->collect(_anon | (Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))) ; dp->first()[1+1] := diff->first() ; for i : Integer.subrange(1, n - 1-1) do ( dp[i+1]->first() := Set{dp[i - 1+1]->first(), dp[i - 1+1][1+1], dp[i - 1+1][2+1]}->max() ; dp[i+1][1+1] := Set{dp[i - 1+1][2+1] + diff[i+1], diff[i+1]}->max() ; dp[i+1][2+1] := dp[i - 1+1][1+1] - diff[i+1]) ; execute (Set{dp[n - 2+1]->first(), dp[n - 2+1][1+1], dp[n - 2+1][2+1]}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) emotes=list(map(int,input().split())) maxhappy=max(emotes) maxindex=emotes.index(max(emotes)) emotes.pop(maxindex) maxhappy2=max(emotes) val=(m//(k+1)) print(maxhappy*(m-val)+maxhappy2*val) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var emotes : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var maxhappy : OclAny := (emotes)->max() ; var maxindex : int := emotes->indexOf((emotes)->max()) - 1 ; emotes := emotes->excludingAt(maxindex+1) ; var maxhappy2 : OclAny := (emotes)->max() ; var val : int := (m div (k + 1)) ; execute (maxhappy * (m - val) + maxhappy2 * val)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=input().split() n=int(n) m=int(m) k=int(k) result=0 numbers=input().split() numbers=[int(i)for i in numbers] if numbers.sort()!=None : numbers=numbers.sort() max_num=numbers[len(numbers)-1] sec_max=numbers[len(numbers)-2] numberOfSingle=m//(k+1) result=numberOfSingle*sec_max+(m-numberOfSingle)*max_num print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var m : int := ("" + ((m)))->toInteger() ; var k : int := ("" + ((k)))->toInteger() ; var result : int := 0 ; var numbers : OclAny := input().split() ; numbers := numbers->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if numbers->sort() /= null then ( numbers := numbers->sort() ) else skip ; var max_num : OclAny := numbers[(numbers)->size() - 1+1] ; var sec_max : OclAny := numbers[(numbers)->size() - 2+1] ; var numberOfSingle : int := m div (k + 1) ; result := numberOfSingle * sec_max + (m - numberOfSingle) * max_num ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=input().split() emotes=list(map(int,input().split())) m=int(m) k=int(k) emotes.sort() biggest=emotes[-1] second=emotes[-2] total=0 count=0 p=m//(k+1) z=m %(k+1) sum=(k*biggest+second)*p+z*biggest print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := input().split() ; var emotes : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + ((m)))->toInteger() ; var k : int := ("" + ((k)))->toInteger() ; emotes := emotes->sort() ; var biggest : OclAny := emotes->last() ; var second : OclAny := emotes->front()->last() ; var total : int := 0 ; var count : int := 0 ; var p : int := m div (k + 1) ; var z : int := m mod (k + 1) ; var sum : double := (k * biggest + second) * p + z * biggest ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import floor n,m,k=input().split() n=int(n) m=int(m) k=int(k) num=input().split() list1=list(map(int,num)) max1=max(list1) list1.remove(max1) max2=max(list1) ans=(m %(k+1))*max1+floor(m/(k+1))*(max1*k+max2) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var m : int := ("" + ((m)))->toInteger() ; var k : int := ("" + ((k)))->toInteger() ; var num : OclAny := input().split() ; var list1 : Sequence := ((num)->collect( _x | (OclType["int"])->apply(_x) )) ; var max1 : OclAny := (list1)->max() ; execute ((max1) /: list1) ; var max2 : OclAny := (list1)->max() ; var ans : double := (m mod (k + 1)) * max1 + floor(m / (k + 1)) * (max1 * k + max2) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def floatError(no): sum=0.0 for i in range(10): sum=sum+no return sum if __name__=='__main__' : print(floatError(0.1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( execute (floatError(0.1))->display() ) else skip; operation floatError(no : OclAny) : OclAny pre: true post: true activity: var sum : double := 0.0 ; for i : Integer.subrange(0, 10-1) do ( sum := sum + no) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def oddFib(n): n=(3*n+1)//2 a=-1 b=1 c=0 for i in range(1,n+1): c=a+b a=b b=c return c n=4 print(oddFib(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute (oddFib(n))->display(); operation oddFib(n : OclAny) : OclAny pre: true post: true activity: n := (3 * n + 1) div 2 ; var a : int := -1 ; var b : int := 1 ; var c : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( c := a + b ; a := b ; b := c) ; return c; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) while n : h,m=map(int,input().split(":")) s=l=float(0.0) l=m*6.0 s=30.0*(h+(m/60.0)) if l180.0 : d=360-l+s else : d=l-s if d<30 : print("alert") elif d<90 : print("warning") else : print("safe") n-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while n do ( var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := (input().split(":"))->collect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := ("" + ((0.0)))->toReal(); var l : double := ("" + ((0.0)))->toReal() ; l := m * 6.0 ; s := 30.0 * (h + (m / 60.0)) ; if (l->compareTo(s)) < 0 then ( Sequence{l,s} := Sequence{s,l} ) else skip ; if l - s > 180.0 then ( var d : double := 360 - l + s ) else ( d := l - s ) ; if d < 30 then ( execute ("alert")->display() ) else (if d < 90 then ( execute ("warning")->display() ) else ( execute ("safe")->display() ) ) ; n := n - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin from math import sqrt,acos,cos,sin,radians,degrees input=stdin.readline def solve(time): short_hand_angle=time[1]*-6+90 x_s=cos(radians(short_hand_angle)) y_s=sin(radians(short_hand_angle)) long_hand_angle=(time[0]*60+time[1])/(12*60)*-360+90 x_l=cos(radians(long_hand_angle)) y_l=sin(radians(long_hand_angle)) c=(x_s*x_l+y_s*y_l)/(sqrt(x_s**2+y_s**2)*sqrt(x_l**2+y_l**2)) ans=degrees(acos(c)) if ans<30 : return 'alert' elif ans>=90 : return 'safe' else : return 'warning' def main(args): n=int(input()) for _ in range(n): time=[int(x)for x in input().split(':')] result=solve(time) print(result) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(time : OclAny) : OclAny pre: true post: true activity: var short_hand_angle : double := time[1+1] * -6 + 90 ; var x_s : OclAny := cos(radians(short_hand_angle)) ; var y_s : OclAny := sin(radians(short_hand_angle)) ; var long_hand_angle : double := (time->first() * 60 + time[1+1]) / (12 * 60) * -360 + 90 ; var x_l : OclAny := cos(radians(long_hand_angle)) ; var y_l : OclAny := sin(radians(long_hand_angle)) ; var c : double := (x_s * x_l + y_s * y_l) / (sqrt((x_s)->pow(2) + (y_s)->pow(2)) * sqrt((x_l)->pow(2) + (y_l)->pow(2))) ; var ans : OclAny := degrees(acos(c)) ; if ans < 30 then ( return 'alert' ) else (if ans >= 90 then ( return 'safe' ) else ( return 'warning' ) ) ; operation main(args : OclAny) pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( time := input().split(':')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var result : OclAny := solve(time) ; execute (result)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math N=int(input()) for l in range(N): s=input() hh=int(s[0 : 2]) mm=int(s[3 : 5]) deg2=6*mm deg1=30*hh+deg2/12 d=abs(deg1-deg2) if d<30 or 330toInteger() ; for l : Integer.subrange(0, N-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var hh : int := ("" + ((s.subrange(0+1, 2))))->toInteger() ; var mm : int := ("" + ((s.subrange(3+1, 5))))->toInteger() ; var deg2 : int := 6 * mm ; var deg1 : int := 30 * hh + deg2 / 12 ; var d : double := (deg1 - deg2)->abs() ; if d < 30 or 330 < d then ( execute ("alert")->display() ) else (if 90 <= d & d <= 270 then ( execute ("safe")->display() ) else ( execute ("warning")->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys a=[] for line in sys.stdin : a+=[line.rstrip('\n')] m=max([len(i)for i in a]) n=False for i,j in enumerate(a): if i==0 : print("*"*(m+2)) if(len(j)% 2==0 and m % 2==0)or(len(j)% 2==1 and m % 2==1): l=(m-len(j))//2 print('*'+' '*l+j+' '*l+'*') else : l=(m-len(j))//2 if n : print('*'+' '*l+' '+j+' '*l+'*') else : print('*'+' '*l+j+' '+' '*l+'*') n=not n if i==len(a)-1 : print("*"*(m+2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : Sequence := Sequence{} ; for line : OclFile["System.in"] do ( a := a + Sequence{ line.rstrip(' ') }) ; var m : OclAny := (a->select(i | true)->collect(i | ((i)->size())))->max() ; var n : boolean := false ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if i = 0 then ( execute (StringLib.nCopies("*", (m + 2)))->display() ) else skip ; if ((j)->size() mod 2 = 0 & m mod 2 = 0) or ((j)->size() mod 2 = 1 & m mod 2 = 1) then ( var l : int := (m - (j)->size()) div 2 ; execute ('*' + StringLib.nCopies(' ', l) + j + StringLib.nCopies(' ', l) + '*')->display() ) else ( l := (m - (j)->size()) div 2 ; if n then ( execute ('*' + StringLib.nCopies(' ', l) + ' ' + j + StringLib.nCopies(' ', l) + '*')->display() ) else ( execute ('*' + StringLib.nCopies(' ', l) + j + ' ' + StringLib.nCopies(' ', l) + '*')->display() ) ; n := not(n) ) ; if i = (a)->size() - 1 then ( execute (StringLib.nCopies("*", (m + 2)))->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) *a,=map(int,input().split()) l=[abs(a[i]-a[i-1])for i in range(1,n)] ans=0 x=y=0 for i in range(n-1): t=[l[i],-l[i]][i % 2] x+=t y-=t ans=max(ans,x,y) x=max(x,0) y=max(y,0) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (testlist_star_expr (star_expr * (expr (atom (name a)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name a)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := Integer.subrange(1, n-1)->select(i | true)->collect(i | ((a[i+1] - a[i - 1+1])->abs())) ; var ans : int := 0 ; var x : OclAny := 0; var y : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( var t : OclAny := Sequence{l[i+1]}->union(Sequence{ -l[i+1] })[i mod 2+1] ; x := x + t ; y := y - t ; ans := Set{ans, x, y}->max() ; x := Set{x, 0}->max() ; y := Set{y, 0}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): hour,minute=[int(item)for item in input().split(":")] angle1=hour*5*6+minute*0.5 angle2=minute*6 subtract=min(abs(angle1-angle2),360-abs(angle1-angle2)) if subtract<30.0 : print("alert") elif 90.0<=subtract : print("safe") else : print("warning") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var hour : OclAny := null; var minute : OclAny := null; Sequence{hour,minute} := input().split(":")->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; var angle1 : double := hour * 5 * 6 + minute * 0.5 ; var angle2 : double := minute * 6 ; var subtract : OclAny := Set{(angle1 - angle2)->abs(), 360 - (angle1 - angle2)->abs()}->min() ; if subtract < 30.0 then ( execute ("alert")->display() ) else (if 90.0 <= subtract then ( execute ("safe")->display() ) else ( execute ("warning")->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): h,m=list(map(int,input().split(':'))) H,M=(30*h+(m//2))*2,(6*m)*2 if(m & 1)==1 : H+=1 a=H-M if a<0 : a=-a a2=720-a if a2=180 and a<=360 : print("safe") else : print("warning") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := ((input().split(':'))->collect( _x | (OclType["int"])->apply(_x) )) ; var H : OclAny := null; var M : OclAny := null; Sequence{H,M} := Sequence{(30 * h + (m div 2)) * 2,(6 * m) * 2} ; if (MathLib.bitwiseAnd(m, 1)) = 1 then ( H := H + 1 ) else skip ; var a : double := H - M ; if a < 0 then ( a := -a ) else skip ; var a2 : double := 720 - a ; if (a2->compareTo(a)) < 0 then ( a := a2 ) else skip ; if a < 60 then ( execute ("alert")->display() ) else (if a >= 180 & a <= 360 then ( execute ("safe")->display() ) else ( execute ("warning")->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isTriangular(num): if(num<0): return False sum,n=0,1 while(sum<=num): sum=sum+n if(sum==num): return True n+=1 return False n=55 if(isTriangular(n)): print("The number is a triangular number") else : print("The number is NOT a triangular number") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := 55 ; if (isTriangular(n)) then ( execute ("The number is a triangular number")->display() ) else ( execute ("The number is NOT a triangular number")->display() ); operation isTriangular(num : OclAny) : OclAny pre: true post: true activity: if (num < 0) then ( return false ) else skip ; var sum : OclAny := null; var n : OclAny := null; Sequence{sum,n} := Sequence{0,1} ; while ((sum->compareTo(num)) <= 0) do ( var sum : OclAny := sum + n ; if (sum = num) then ( return true ) else skip ; n := n + 1) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfTheSeries(n): sum_n=int((n*(n+1)/2)); sum_sq_n=int((n*(n+1)/2)*(2*n+1)/3) return(sum_n+sum_sq_n); n=5 ans=sumOfTheSeries(n) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; var ans : OclAny := sumOfTheSeries(n) ; execute (ans)->display(); operation sumOfTheSeries(n : OclAny) pre: true post: true activity: var sum_n : int := ("" + (((n * (n + 1) / 2))))->toInteger(); ; var sum_sq_n : int := ("" + (((n * (n + 1) / 2) * (2 * n + 1) / 3)))->toInteger() ; return (sum_n + sum_sq_n);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findDistinctOddsumm(n,k): if((k*k)<=n and(n+k)% 2==0): val=1 summ=0 for i in range(1,k): print(val,end=" ") summ+=val val+=2 print(n-summ) else : print("NO") n=100 k=4 findDistinctOddsumm(n,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 100 ; k := 4 ; findDistinctOddsumm(n, k); operation findDistinctOddsumm(n : OclAny, k : OclAny) pre: true post: true activity: if (((k * k)->compareTo(n)) <= 0 & (n + k) mod 2 = 0) then ( var val : int := 1 ; var summ : int := 0 ; for i : Integer.subrange(1, k-1) do ( execute (val)->display() ; summ := summ + val ; val := val + 2) ; execute (n - summ)->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) print(n,end=" ") for i in range(n-1): print(i+1,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n)->display() ; for i : Integer.subrange(0, n - 1-1) do ( execute (i + 1)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for x in range(t): a=int(input()) c=[] for x in range(1,a+1): c.append(x) print(*c[a//2 : a],*c[0 : a//2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for x : Integer.subrange(0, t-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : Sequence := Sequence{} ; for x : Integer.subrange(1, a + 1-1) do ( execute ((x) : c)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name a))) // (expr (atom (number (integer 2)))))))) : (test (logical_test (comparison (expr (atom (name a)))))))) ]))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) for x in range(a): b=int(input()) c=[] for x in range(b,0,-1): c.append(x) if b % 2==0 : print(*c) else : c[b//2],c[b//2-1]=c[b//2-1],c[b//2] print(*c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for x : Integer.subrange(0, a-1) do ( var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : Sequence := Sequence{} ; for x : Integer.subrange(0 + 1, b)->reverse() do ( execute ((x) : c)) ; if b mod 2 = 0 then ( execute ((argument * (test (logical_test (comparison (expr (atom (name c))))))))->display() ) else ( var c[b div 2+1] : OclAny := null; var c[b div 2 - 1+1] : OclAny := null; Sequence{c[b div 2+1],c[b div 2 - 1+1]} := Sequence{c[b div 2 - 1+1],c[b div 2+1]} ; execute ((argument * (test (logical_test (comparison (expr (atom (name c))))))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=eval(input()) for i in range(t): n=eval(input()) output_list=[] k=1 p=n for j in range(0,n): if jcompareTo(("" + ((n / 2)))->toInteger())) < 0 then ( execute ((StringLib.formattedString("{p}")) : output_list) ; p := p - 1 ) else ( execute ((StringLib.formattedString("{k}")) : output_list) ; k := k + 1 )) ; execute (StringLib.sumStringsWithSeparator((output_list), " "))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getint(): return[int(i)for i in input().split()] def get(): return int(input()) for _ in range(int(input())): n=get() ans=[n] for i in range(1,n): ans.append(i) print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := get() ; var ans : Sequence := Sequence{ n } ; for i : Integer.subrange(1, n-1) do ( execute ((i) : ans)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()); operation getint() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation get() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys inf=float("inf") mod=1000000007 def get_array(): return list(map(int,sys.stdin.readline().split())) def get_ints(): return map(int,sys.stdin.readline().split()) def input(): return sys.stdin.readline() def main(): n=int(input()) arr=get_array() ans=0 prefix_odd=[0]*n for i in range(n-1): prefix_odd[i]=abs(arr[i+1]-arr[i])*pow(-1,i) prefix_even=[0]*n for i in range(n-1): prefix_even[i]=abs(arr[i+1]-arr[i])*pow(-1,i+1) curr_mx,mx=prefix_odd[0],prefix_odd[0] for i in range(1,n): curr_mx=max(prefix_odd[i],prefix_odd[i]+curr_mx) mx=max(curr_mx,mx) curr_mx=prefix_even[0] for i in range(1,n): curr_mx=max(prefix_even[i],prefix_even[i]+curr_mx) mx=max(curr_mx,mx) print(mx) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var Math_PINFINITY : double := ("" + (("inf")))->toReal() ; var mod : int := 1000000007 ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation get_array() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation get_ints() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation input() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : OclAny := get_array() ; var ans : int := 0 ; var prefix_odd : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n - 1-1) do ( prefix_odd[i+1] := (arr[i + 1+1] - arr[i+1])->abs() * (-1)->pow(i)) ; var prefix_even : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n - 1-1) do ( prefix_even[i+1] := (arr[i + 1+1] - arr[i+1])->abs() * (-1)->pow(i + 1)) ; var curr_mx : OclAny := null; var mx : OclAny := null; Sequence{curr_mx,mx} := Sequence{prefix_odd->first(),prefix_odd->first()} ; for i : Integer.subrange(1, n-1) do ( var curr_mx : OclAny := Set{prefix_odd[i+1], prefix_odd[i+1] + curr_mx}->max() ; var mx : OclAny := Set{curr_mx, mx}->max()) ; curr_mx := prefix_even->first() ; for i : Integer.subrange(1, n-1) do ( curr_mx := Set{prefix_even[i+1], prefix_even[i+1] + curr_mx}->max() ; mx := Set{curr_mx, mx}->max()) ; execute (mx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys BASE=[1.1,0.6,0.2,0.0] COUNT=len(BASE) def eye_test(num): for index,parameter in enumerate(BASE): if parameter<=num : return index left_counter=[0]*COUNT right_counter=[0]*COUNT for line in sys.stdin : left,right=[float(item)for item in line[:-1].split(" ")] left_eye,right_eye=eye_test(left),eye_test(right) left_counter[left_eye]+=1 right_counter[right_eye]+=1 for item1,item2 in zip(left_counter,right_counter): print(item1,item2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var BASE : Sequence := Sequence{1.1}->union(Sequence{0.6}->union(Sequence{0.2}->union(Sequence{ 0.0 }))) ; var COUNT : int := (BASE)->size() ; skip ; var left_counter : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, COUNT) ; var right_counter : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, COUNT) ; for line : OclFile["System.in"] do ( var left : OclAny := null; var right : OclAny := null; Sequence{left,right} := line->front().split(" ")->select(item | true)->collect(item | (("" + ((item)))->toReal())) ; var left_eye : OclAny := null; var right_eye : OclAny := null; Sequence{left_eye,right_eye} := Sequence{eye_test(left),eye_test(right)} ; left_counter[left_eye+1] := left_counter[left_eye+1] + 1 ; right_counter[right_eye+1] := right_counter[right_eye+1] + 1) ; for _tuple : Integer.subrange(1, left_counter->size())->collect( _indx | Sequence{left_counter->at(_indx), right_counter->at(_indx)} ) do (var _indx : int := 1; var item1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var item2 : OclAny := _tuple->at(_indx); execute (item1)->display()); operation eye_test(num : OclAny) : OclAny pre: true post: true activity: for _tuple : Integer.subrange(1, (BASE)->size())->collect( _indx | Sequence{_indx-1, (BASE)->at(_indx)} ) do (var _indx : int := 1; var index : OclAny := _tuple->at(_indx); _indx := _indx + 1; var parameter : OclAny := _tuple->at(_indx); if (parameter->compareTo(num)) <= 0 then ( return index ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(s,K): for ch in range(0,26): c=chr(97+ch) last=-1 found=True for i in range(0,K): if s[i]==c : last=i if last==-1 : continue for i in range(K,len(s)): if s[i]==c : last=i if last<=(i-K): found=False break if found : return 1 return 0 def binarySearch(s): low,high,ans=1,len(s),None while low<=high : mid=(high+low)>>1 if check(s,mid): ans,high=mid,mid-1 else : low=mid+1 return ans if __name__=="__main__" : s="abcde" print(binarySearch(s)) s="aaaa" print(binarySearch(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( s := "abcde" ; execute (binarySearch(s))->display() ; s := "aaaa" ; execute (binarySearch(s))->display() ) else skip; operation check(s : OclAny, K : OclAny) : OclAny pre: true post: true activity: for ch : Integer.subrange(0, 26-1) do ( var c : String := (97 + ch)->byte2char() ; var last : int := -1 ; var found : boolean := true ; for i : Integer.subrange(0, K-1) do ( if s[i+1] = c then ( last := i ) else skip) ; if last = -1 then ( continue ) else skip ; for i : Integer.subrange(K, (s)->size()-1) do ( if s[i+1] = c then ( last := i ) else skip ; if (last->compareTo((i - K))) <= 0 then ( found := false ; break ) else skip) ; if found then ( return 1 ) else skip) ; return 0; operation binarySearch(s : OclAny) : OclAny pre: true post: true activity: var low : OclAny := null; var high : OclAny := null; var ans : OclAny := null; Sequence{low,high,ans} := Sequence{1,(s)->size(),null} ; while (low->compareTo(high)) <= 0 do ( var mid : int := (high + low) /(2->pow(1)) ; if check(s, mid) then ( var ans : OclAny := null; var high : OclAny := null; Sequence{ans,high} := Sequence{mid,mid - 1} ) else ( var low : int := mid + 1 )) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque,Counter,defaultdict from itertools import chain,combinations import json import bisect import sys import math import bisect from functools import lru_cache sys.setrecursionlimit(10**8) M=10**9+7 INF=10**17 def main(): N=int(input()) A=[int(a)for a in input().split()] @ lru_cache(None) def f(i,j): if i<0 or j<0 : return-INF if i==0 : return-INF if abs(j-i//2-1)>=2 : return-INF if j==0 : return 0 if j==1 : return max(A[: i]) return max(A[i-1]+f(i-2,j-1),f(i-1,j)) print(f(N,math.floor(N/2))) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; var M : double := (10)->pow(9) + 7 ; var INF : double := (10)->pow(17) ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; (compound_stmt (decorator @ (dotted_name (name lru_cache)) ( (arglist (argument (test (logical_test (comparison (expr (atom None))))))) )) (funcdef def (name f) ( (typedargslist (def_parameters (def_parameter (named_parameter (name i))) , (def_parameter (named_parameter (name j))))) ) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name i)))) < (comparison (expr (atom (number (integer 0))))))) or (logical_test (comparison (comparison (expr (atom (name j)))) < (comparison (expr (atom (number (integer 0))))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr - (expr (atom (name INF)))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name i)))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr - (expr (atom (name INF)))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name j))) - (expr (expr (atom (name i))) // (expr (atom (number (integer 2)))))) - (expr (atom (number (integer 1)))))))))) ))))) >= (comparison (expr (atom (number (integer 2)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr - (expr (atom (name INF)))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name j)))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name j)))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))) + (expr (atom (name f)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name j))) - (expr (atom (number (integer 1)))))))))) ))))))))) , (argument (test (logical_test (comparison (expr (atom (name f)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name j)))))))) ))))))))) )))))))))))))) ; execute (f(N, (N / 2)->floor()))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[0]+list(map(int,input().split())) dp=[[0]*2 for _ in range(n+1)] dp[1][1]=a[1] dp[2][1]=max(a[1],a[2]) for i in range(3,n+1): if i % 2==1 : dp[i][0]=max(dp[i-1][1],dp[i-2][0]+a[i]) dp[i][1]=dp[i-2][1]+a[i] else : dp[i][0]=max(dp[i-1][0],dp[i-2][0]+a[i]) dp[i][1]=max(dp[i-1][1],dp[i-2][1]+a[i]) if n % 2==1 : print(dp[-1][0]) else : print(dp[-1][1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 2))) ; dp[1+1][1+1] := a[1+1] ; dp[2+1][1+1] := Set{a[1+1], a[2+1]}->max() ; for i : Integer.subrange(3, n + 1-1) do ( if i mod 2 = 1 then ( dp[i+1]->first() := Set{dp[i - 1+1][1+1], dp[i - 2+1]->first() + a[i+1]}->max() ; dp[i+1][1+1] := dp[i - 2+1][1+1] + a[i+1] ) else ( dp[i+1]->first() := Set{dp[i - 1+1]->first(), dp[i - 2+1]->first() + a[i+1]}->max() ; dp[i+1][1+1] := Set{dp[i - 1+1][1+1], dp[i - 2+1][1+1] + a[i+1]}->max() )) ; if n mod 2 = 1 then ( execute (dp->last()->first())->display() ) else ( execute (dp->last()[1+1])->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**7) from pprint import pprint as pp from pprint import pformat as pf import math import bisect class Solver : def __init__(self,n,a_s): self.n=n self.a_s=a_s self.extra=1 if self.n % 2==0 else 2 self.dp=self.prepare_dp() def prepare_dp(self): dp=[None]*(self.n+1) for i,_ in enumerate(dp): dp[i]=[-1*math.inf]*(1+self.extra) dp[0][0]=0 return dp def run(self): extra=1+self.n % 2 for i,a in enumerate(self.a_s): for j in range(self.extra): self.dp[i+1][j+1]=self.dp[i][j] for j in range(self.extra+1): v=self.dp[i][j] if(i+j)% 2==0 : v+=a self.dp[i+1][j]=max(self.dp[i+1][j],v) return self.dp[n][extra] if __name__=='__main__' : n=int(input()) a_s=list(map(int,input().split())) ans=Solver(n,a_s).run() print(ans) ------------------------------------------------------------ OCL File: --------- class Solver { static operation newSolver() : Solver pre: true post: Solver->exists( _x | result = _x ); attribute n : OclAny := n; attribute a_s : OclAny := a_s; attribute extra : int := if self.n mod 2 = 0 then 1 else 2 endif; attribute dp : OclAny := self.prepare_dp(); operation initialise(n : OclAny,a_s : OclAny) : Solver pre: true post: true activity: self.n := n ; self.a_s := a_s ; self.extra := if self.n mod 2 = 0 then 1 else 2 endif ; self.dp := self.prepare_dp(); return self; operation prepare_dp() : OclAny pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (self.n + 1)) ; for _tuple : Integer.subrange(1, (dp)->size())->collect( _indx | Sequence{_indx-1, (dp)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var _anon : OclAny := _tuple->at(_indx); dp[i+1] := MatrixLib.elementwiseMult(Sequence{ -1 * }, (1 + self.extra))) ; dp->first()->first() := 0 ; return dp; operation run() : OclAny pre: true post: true activity: var extra : int := 1 + self.n mod 2 ; for _tuple : Integer.subrange(1, (self.a_s)->size())->collect( _indx | Sequence{_indx-1, (self.a_s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); for j : Integer.subrange(0, self.extra-1) do ( self.dp[i + 1+1][j + 1+1] := self.dp[i+1][j+1]) ; for j : Integer.subrange(0, self.extra + 1-1) do ( var v : OclAny := self.dp[i+1][j+1] ; if (i + j) mod 2 = 0 then ( v := v + a ) else skip ; self.dp[i + 1+1][j+1] := Set{self.dp[i + 1+1][j+1], v}->max())) ; return self.dp[n+1][extra+1]; } class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a_s := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : OclAny := Solver(n, a_s)(OclProcess.newOclProcess(, "")).start() ; execute (ans)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate def solve_odd(n,aaa): INF=10**18 p0,p1,p2,a0,a1,a2=INF,INF,INF,INF,INF,0 for a in aaa : n2=min(INF,p2+a) n1=min(INF,a2+a,p1+a) n0=min(INF,a1+a,p0+a) p0,p1,p2,a0,a1,a2=a0,a1,a2,n0,n1,n2 return sum(aaa)-min(p0,a1) def solve_even(n,aaa): fwd=[0]+list(accumulate(aaa[: : 2])) bwd=[0]+list(accumulate(aaa[: :-2])) bwd.reverse() return max(f+b for f,b in zip(fwd,bwd)) n=int(input()) aaa=list(map(int,input().split())) if n % 2==0 : print(solve_even(n,aaa)) else : print(solve_odd(n,aaa)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; aaa := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n mod 2 = 0 then ( execute (solve_even(n, aaa))->display() ) else ( execute (solve_odd(n, aaa))->display() ); operation solve_odd(n : OclAny, aaa : OclAny) : OclAny pre: true post: true activity: var INF : double := (10)->pow(18) ; var p0 : OclAny := null; var p1 : OclAny := null; var p2 : OclAny := null; var a0 : OclAny := null; var a1 : OclAny := null; var a2 : OclAny := null; Sequence{p0,p1,p2,a0,a1,a2} := Sequence{INF,INF,INF,INF,INF,0} ; for a : aaa do ( var n2 : OclAny := Set{INF, p2 + a}->min() ; var n1 : OclAny := Set{INF, a2 + a, p1 + a}->min() ; var n0 : OclAny := Set{INF, a1 + a, p0 + a}->min() ; var p0 : OclAny := null; var p1 : OclAny := null; var p2 : OclAny := null; var a0 : OclAny := null; var a1 : OclAny := null; var a2 : OclAny := null; Sequence{p0,p1,p2,a0,a1,a2} := Sequence{a0,a1,a2,n0,n1,n2}) ; return (aaa)->sum() - Set{p0, a1}->min(); operation solve_even(n : OclAny, aaa : OclAny) : OclAny pre: true post: true activity: var fwd : Sequence := Sequence{ 0 }->union((accumulate(aaa(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))))) ; var bwd : Sequence := Sequence{ 0 }->union((accumulate(aaa(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 2)))))))))))) ; bwd := bwd->reverse() ; return ((argument (test (logical_test (comparison (expr (expr (atom (name f))) + (expr (atom (name b))))))) (comp_for for (exprlist (expr (atom (name f))) , (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name fwd))))))) , (argument (test (logical_test (comparison (expr (atom (name bwd)))))))) )))))))))->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda : sys.stdin.readline().rstrip() YesNo=lambda b : print('Yes' if b else 'No') YESNO=lambda b : print('YES' if b else 'NO') def main(): N=int(input()) A=list(map(int,input().split())) dp=[[-INF]*3 for _ in range(N+10)] dp[0][0]=0 for i in range(N+1): for j in range(3): if j+1<3 : dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]) if ipow(9)) ; var INF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var YesNo : Function := lambda b : OclAny in ((if b then 'Yes' else 'No' endif)->display()) ; var YESNO : Function := lambda b : OclAny in ((if b then 'YES' else 'NO' endif)->display()) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dp : Sequence := Integer.subrange(0, N + 10-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ -INF }, 3))) ; dp->first()->first() := 0 ; for i : Integer.subrange(0, N + 1-1) do ( for j : Integer.subrange(0, 3-1) do ( if j + 1 < 3 then ( dp[i + 1+1][j + 1+1] := Set{dp[i + 1+1][j + 1+1], dp[i+1][j+1]}->max() ) else skip ; if (i->compareTo(N)) < 0 then ( dp[i + 2+1][j+1] := Set{dp[i + 2+1][j+1], dp[i+1][j+1] + A[i+1]}->max() ) else skip)) ; if N mod 2 then ( execute (dp[N + 1+1][2+1])->display() ) else ( execute (dp[N + 1+1][1+1])->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) d,x=map(int,input().split()) res=x for i in range(n): a=int(input()) res+=(d-1)//a+1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : OclAny := null; var x : OclAny := null; Sequence{d,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var res : OclAny := x ; for i : Integer.subrange(0, n-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; res := res + (d - 1) div a + 1) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import copy N=int(input()) a=[int(c)for c in input().split()] D=a[0] X=a[1] a=[int(input())for i in range(N)] choco=0 for i in range(N): cnt=0 while cnt*a[i]+1<=D : choco+=1 cnt+=1 print(choco+X) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(c | true)->collect(c | (("" + ((c)))->toInteger())) ; var D : OclAny := a->first() ; var X : OclAny := a[1+1] ; a := Integer.subrange(0, N-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var choco : int := 0 ; for i : Integer.subrange(0, N-1) do ( var cnt : int := 0 ; while (cnt * a[i+1] + 1->compareTo(D)) <= 0 do ( choco := choco + 1 ; cnt := cnt + 1)) ; execute (choco + X)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import ceil def input(): return sys.stdin.readline().strip() def main(): N=int(input()) D,X=map(int,input().split()) A=[int(input())for _ in range(N)] choco=X for a in A : choco+=ceil(D/a) print(choco) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var D : OclAny := null; var X : OclAny := null; Sequence{D,X} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var choco : OclAny := X ; for a : A do ( choco := choco + ceil(D / a)) ; execute (choco)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) b=[abs(a[i]-a[i+1])for i in range(n-1)] p,q,r=0,0,0 for i in b : _p=max(0,q+i) _q=max(0,p-i) p,q=_p,_q r=max(p,q,r) print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := Integer.subrange(0, n - 1-1)->select(i | true)->collect(i | ((a[i+1] - a[i + 1+1])->abs())) ; var p : OclAny := null; var q : OclAny := null; var r : OclAny := null; Sequence{p,q,r} := Sequence{0,0,0} ; for i : b do ( var _p : OclAny := Set{0, q + i}->max() ; var _q : OclAny := Set{0, p - i}->max() ; var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := Sequence{_p,_q} ; var r : OclAny := Set{p, q, r}->max()) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() n=int(n) d,x=input().split(" ") d=int(d) x=int(x) a_list=list() for _ in range(n): a=input() a_list.append(int(a)) cookie=0 for a in a_list : for i in range(1000): day=(a*i)+1 if day>d : break else : cookie+=1 print(cookie+x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; n := ("" + ((n)))->toInteger() ; var d : OclAny := null; var x : OclAny := null; Sequence{d,x} := input().split(" ") ; var d : int := ("" + ((d)))->toInteger() ; var x : int := ("" + ((x)))->toInteger() ; var a_list : Sequence := () ; for _anon : Integer.subrange(0, n-1) do ( var a : String := (OclFile["System.in"]).readLine() ; execute ((("" + ((a)))->toInteger()) : a_list)) ; var cookie : int := 0 ; for a : a_list do ( for i : Integer.subrange(0, 1000-1) do ( var day : String := (StringLib.nCopies(a, i)) + 1 ; if day > d then ( break ) else ( cookie := cookie + 1 ))) ; execute (cookie + x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pairWithEqualSum(A,n): mp={} for i in range(n): for j in range(i+1,n): if A[i]+A[j]in mp : mp[A[i]+A[j]].append((A[i],A[j])) else : mp[A[i]+A[j]]=[(A[i],A[j])] for itr in mp : if len(mp[itr])>1 : print("Pairs : ",end="") for i in range(0,len(mp[itr])): print("(",mp[itr][i][0],",",mp[itr][i][1],")",end=" ") print("have sum :",itr) if __name__=="__main__" : A=[6,4,12,10,22,54,32,42,21,11,8,2] n=len(A) pairWithEqualSum(A,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( A := Sequence{6}->union(Sequence{4}->union(Sequence{12}->union(Sequence{10}->union(Sequence{22}->union(Sequence{54}->union(Sequence{32}->union(Sequence{42}->union(Sequence{21}->union(Sequence{11}->union(Sequence{8}->union(Sequence{ 2 }))))))))))) ; n := (A)->size() ; pairWithEqualSum(A, n) ) else skip; operation pairWithEqualSum(A : OclAny, n : OclAny) pre: true post: true activity: var mp : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if (mp)->includes(A[i+1] + A[j+1]) then ( (expr (atom (name mp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))) , (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))) )))))))) )))) ) else ( mp[A[i+1] + A[j+1]+1] := Sequence{ Sequence{A[i+1], A[j+1]} } ))) ; for itr : mp do ( if (mp[itr+1])->size() > 1 then ( execute ("Pairs : ")->display() ; for i : Integer.subrange(0, (mp[itr+1])->size()-1) do ( execute ("(")->display()) ; execute ("have sum :")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(a): if a>1.0 : return 0 elif a>0.5 : return 1 elif a>0.1 : return 2 else : return 3 b=[0]*8 while 1 : try : l,r=map(float,input().split()) except : break b[f(l)]+=1 b[4+f(r)]+=1 for i in range(4): print(b[i],b[4+i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 8) ; while 1 do ( try ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["double"])->apply(_x) )) catch (_e : OclException) do ( break) ; b[f(l)+1] := b[f(l)+1] + 1 ; b[4 + f(r)+1] := b[4 + f(r)+1] + 1) ; for i : Integer.subrange(0, 4-1) do ( execute (b[i+1])->display()); operation f(a : OclAny) : OclAny pre: true post: true activity: if a > 1.0 then ( return 0 ) else (if a > 0.5 then ( return 1 ) else (if a > 0.1 then ( return 2 ) else ( return 3 ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) D,X=map(int,input().split()) print(sum(1+~-D//int(input())for i in range(N))+X) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var D : OclAny := null; var X : OclAny := null; Sequence{D,X} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (((argument (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) + (expr (expr ~ (expr - (expr (atom (name D))))) // (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))))->sum() + X)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def maxPrimefactorNum(N): arr=[0 for i in range(N+5)] for i in range(2,int(sqrt(N))+1,1): if(arr[i]==0): for j in range(2*i,N+1,i): arr[j]+=1 arr[i]=1 maxval=0 maxint=1 for i in range(1,N+1,1): if(arr[i]>maxval): maxval=arr[i] maxint=i return maxint if __name__=='__main__' : N=40 print(maxPrimefactorNum(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( N := 40 ; execute (maxPrimefactorNum(N))->display() ) else skip; operation maxPrimefactorNum(N : OclAny) : OclAny pre: true post: true activity: var arr : Sequence := Integer.subrange(0, N + 5-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(2, ("" + ((sqrt(N))))->toInteger() + 1-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (arr[i+1] = 0) then ( for j : Integer.subrange(2 * i, N + 1-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ( arr[j+1] := arr[j+1] + 1) ) else skip ; arr[i+1] := 1) ; var maxval : int := 0 ; var maxint : int := 1 ; for i : Integer.subrange(1, N + 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if ((arr[i+1]->compareTo(maxval)) > 0) then ( maxval := arr[i+1] ; maxint := i ) else skip) ; return maxint; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getPerfectcubes(n): perfectcubes=[]; current=1 ; i=1 ; while(current<=n): perfectcubes.append(current); i+=1 ; current=int(pow(i,3)); return perfectcubes ; def maxPairSum(arr): n=len(arr); max=0 ; secondMax=0 ; if(arr[0]>arr[1]): max=arr[0]; secondMax=arr[1]; else : max=arr[1]; secondMax=arr[0]; for i in range(2,n): if(arr[i]>max): secondMax=max ; max=arr[i]; elif(arr[i]>secondMax): secondMax=arr[i]; return(max+secondMax); def countPairsWith(n,perfectcubes,nums): count=0 ; for i in range(len(perfectcubes)): temp=perfectcubes[i]-n ; if(temp>n and(temp in nums)): count+=1 ; return count ; def countPairs(arr): n=len(arr); max=maxPairSum(arr); perfectcubes=getPerfectcubes(max); nums=[]; for i in range(n): nums.append(arr[i]); count=0 ; for i in range(n): count+=countPairsWith(arr[i],perfectcubes,nums); return count ; arr=[2,6,18,9,999,1]; print(countPairs(arr)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; arr := Sequence{2}->union(Sequence{6}->union(Sequence{18}->union(Sequence{9}->union(Sequence{999}->union(Sequence{ 1 }))))); ; execute (countPairs(arr))->display();; operation getPerfectcubes(n : OclAny) pre: true post: true activity: var perfectcubes : Sequence := Sequence{}; ; var current : int := 1; ; var i : int := 1; ; while ((current->compareTo(n)) <= 0) do ( execute ((current) : perfectcubes); ; i := i + 1; ; current := ("" + (((i)->pow(3))))->toInteger();) ; return perfectcubes;; operation maxPairSum(arr : OclAny) pre: true post: true activity: n := (arr)->size(); ; var max : int := 0; ; var secondMax : int := 0; ; if ((arr->first()->compareTo(arr[1+1])) > 0) then ( max := arr->first(); ; secondMax := arr[1+1]; ) else ( max := arr[1+1]; ; secondMax := arr->first(); ) ; for i : Integer.subrange(2, n-1) do ( if ((arr[i+1]->compareTo(max)) > 0) then ( secondMax := max; ; max := arr[i+1]; ) else (if ((arr[i+1]->compareTo(secondMax)) > 0) then ( secondMax := arr[i+1]; ) else skip)) ; return (max + secondMax);; operation countPairsWith(n : OclAny, perfectcubes : OclAny, nums : OclAny) pre: true post: true activity: var count : int := 0; ; for i : Integer.subrange(0, (perfectcubes)->size()-1) do ( var temp : double := perfectcubes[i+1] - n; ; if ((temp->compareTo(n)) > 0 & ((nums)->includes(temp))) then ( count := count + 1; ) else skip) ; return count;; operation countPairs(arr : OclAny) pre: true post: true activity: n := (arr)->size(); ; max := maxPairSum(arr); ; perfectcubes := getPerfectcubes(max); ; nums := Sequence{}; ; for i : Integer.subrange(0, n-1) do ( execute ((arr[i+1]) : nums);) ; count := 0; ; for i : Integer.subrange(0, n-1) do ( count := count + countPairsWith(arr[i+1], perfectcubes, nums);) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) d={i :[]for i in range(n)} for i in range(n): s=str(input()) for j in range(n): if s[j]=='1' : d[i].append(j) def ss(node): v[node]=1 pos.append(node) for child in d[node]: if v[child]==0 : ss(child) v=[0 for _ in range(n)] for i in range(n): if v[i]==0 : pos=[] ss(i) t=[] for ind in pos : t.append(l[ind]) t=sorted(t) pos=sorted(pos) for a in range(len(t)): l[pos[a]]=t[a] print(*l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : Map := Integer.subrange(0, n-1)->select(i | true)->collect(i | Map{i |-> Sequence{}})->unionAll() ; for i : Integer.subrange(0, n-1) do ( var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; for j : Integer.subrange(0, n-1) do ( if s[j+1] = '1' then ( (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) ) else skip)) ; skip ; var v : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)) ; for i : Integer.subrange(0, n-1) do ( if v[i+1] = 0 then ( var pos : Sequence := Sequence{} ; ss(i) ; var t : Sequence := Sequence{} ; for ind : pos do ( execute ((l[ind+1]) : t)) ; t := t->sort() ; pos := pos->sort() ; for a : Integer.subrange(0, (t)->size()-1) do ( l[pos[a+1]+1] := t[a+1]) ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name l))))))))->display(); operation ss(node : OclAny) pre: true post: true activity: v[node+1] := 1 ; execute ((node) : pos) ; for child : d[node+1] do ( if v[child+1] = 0 then ( ss(child) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) graph=[[]for _ in range(n)] for i in range(n): s=input() for j in range(n): if s[j]=='1' : graph[i].append(j) graph[j].append(i) vis=[False]*n index=[] value=[] def dfs(i): vis[i]=True index.append(i) value.append(a[i]) for g in graph[i]: if not vis[g]: dfs(g) for i in range(n): if not vis[i]: dfs(i) value.sort() index.sort() for j in range(len(value)): a[index[j]]=value[j] value=[] index=[] print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var graph : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; for j : Integer.subrange(0, n-1) do ( if s[j+1] = '1' then ( (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ) else skip)) ; var vis : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ; var index : Sequence := Sequence{} ; var value : Sequence := Sequence{} ; skip ; for i : Integer.subrange(0, n-1) do ( if not(vis[i+1]) then ( dfs(i) ; value := value->sort() ; index := index->sort() ; for j : Integer.subrange(0, (value)->size()-1) do ( a[index[j+1]+1] := value[j+1]) ; value := Sequence{} ; index := Sequence{} ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display(); operation dfs(i : OclAny) pre: true post: true activity: vis[i+1] := true ; execute ((i) : index) ; execute ((a[i+1]) : value) ; for g : graph[i+1] do ( if not(vis[g+1]) then ( dfs(g) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class DSU : def __init__(self,n): self.dsu=[i for i in range(n)] self.weights=[0]*n def find(self,u): if u==self.dsu[u]: return u self.dsu[u]=self.find(self.dsu[u]) return self.dsu[u] def union(self,u,v): u=self.find(u) v=self.find(v) if u!=v : if self.weights[u]exists( _x | result = _x ); attribute dsu : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)); attribute weights : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); operation initialise(n : OclAny) : DSU pre: true post: true activity: self.dsu := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)) ; self.weights := MatrixLib.elementwiseMult(Sequence{ 0 }, n); return self; operation find(u : OclAny) : OclAny pre: true post: true activity: if u = self.dsu[u+1] then ( return u ) else skip ; self.dsu[u+1] := self->indexOf(self.dsu[u+1]) - 1 ; return self.dsu[u+1]; operation union(u : OclAny,v : OclAny) pre: true post: true activity: u := self->indexOf(u) - 1 ; v := self->indexOf(v) - 1 ; if u /= v then ( if (self.weights[u+1]->compareTo(self.weights[v+1])) < 0 then ( Sequence{u,v} := Sequence{v,u} ) else skip ; self.dsu[v+1] := u ; if self.weights[u+1] = self.weights[v+1] then ( self.weights[u+1] := self.weights[u+1] + 1 ) else skip ) else skip; } class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var dsu : DSU := (DSU.newDSU()).initialise(n) ; for i : Integer.subrange(0, n-1) do ( var line : String := (OclFile["System.in"]).readLine() ; for j : Integer.subrange(0, n-1) do ( if line[j+1] = '1' then ( dsu.union(i, j) ) else skip)) ; var components : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var par : int := dsu->indexOf(i) - 1 ; if (components)->excludes(par) then ( components[par+1] := Sequence{} ) else skip ; (expr (atom (name components)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name par)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; for comp : components do ( var arr : Sequence := components[comp+1]->select(a | true)->collect(a | (p[a+1])) ; arr := arr->sort() ; for _tuple : Integer.subrange(1, (components[comp+1])->size())->collect( _indx | Sequence{_indx-1, (components[comp+1])->at(_indx)} ) do (var _indx : int := 1; var idx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); p[a+1] := arr[idx+1])) ; execute (StringLib.sumStringsWithSeparator((p->select(x | true)->collect(x | (("" + ((x)))))), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- par=[0]*310 rank=[0]*310 def init_union_find(V): for i in range(V): par[i]=i rank[i]=0 def find(x): if par[x]==x : return x else : par[x]=find(par[x]) return par[x] def unite(x,y): x=find(x) y=find(y) if x==y : return if rank[x]p[j]and find(i)==find(j): p[i],p[j]=p[j],p[i] print(" ".join(map(str,p))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var par : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 310) ; var rank : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 310) ; skip ; skip ; skip ; skip ; init_union_find(310) ; var edge : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 310) ; var node : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 310) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var uv : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; for j : Integer.subrange(0, N-1) do ( if s[j+1] = '1' then ( execute ((Sequence{i}->union(Sequence{ j })) : uv) ) else skip)) ; for _tuple : uv do (var _indx : int := 1; var u : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); unite(u, v)) ; var OclType["Sequence"] : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 310) ; for i : Integer.subrange(0, (p)->size()-1) do ( for j : Integer.subrange(i + 1, (p)->size()-1) do ( if (p[i+1]->compareTo(p[j+1])) > 0 & find(i) = find(j) then ( var p[i+1] : OclAny := null; var p[j+1] : OclAny := null; Sequence{p[i+1],p[j+1]} := Sequence{p[j+1],p[i+1]} ) else skip)) ; execute (StringLib.sumStringsWithSeparator(((p)->collect( _x | (OclType["String"])->apply(_x) )), " "))->display(); operation init_union_find(V : OclAny) pre: true post: true activity: for i : Integer.subrange(0, V-1) do ( par[i+1] := i ; rank[i+1] := 0); operation find(x : OclAny) : OclAny pre: true post: true activity: if par[x+1] = x then ( return x ) else ( par[x+1] := find(par[x+1]) ; return par[x+1] ); operation unite(x : OclAny, y : OclAny) pre: true post: true activity: x := find(x) ; y := find(y) ; if x = y then ( return ) else skip ; if (rank[x+1]->compareTo(rank[y+1])) < 0 then ( par[x+1] := y ) else ( par[y+1] := x ; if (rank[x+1] = rank[y+1]) then ( rank[x+1] := rank[x+1] + 1 ) else skip ); operation same(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return find(x) = find(y); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- z=[int(i)for i in input().split()] x,y,a,b=z[0],z[1],z[2],z[3] def gcd(x,y): for i in range(1,y+1): if(x*i)% y==0 : return x*i print(int(b//(gcd(x,y))-a//(gcd(x,y))+(a %(gcd(x,y))==0))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var z : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var x : OclAny := null; var y : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{x,y,a,b} := Sequence{z->first(),z[1+1],z[2+1],z[3+1]} ; skip ; execute (("" + ((b div (gcd(x, y)) - a div (gcd(x, y)) + (a mod (gcd(x, y)) = 0))))->toInteger())->display(); operation gcd(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(1, y + 1-1) do ( if (x * i) mod y = 0 then ( return x * i ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[*map(int,input().split())] s=[abs(a[i]-a[i+1])for i in range(n-1)] x=y=ans=0 for i in s : x1=max(y+i,0) y1=max(x-i,0) x,y,ans=x1,y1,max(x1,y1,ans) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := Integer.subrange(0, n - 1-1)->select(i | true)->collect(i | ((a[i+1] - a[i + 1+1])->abs())) ; x := x(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name y)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for i : s do ( var x1 : OclAny := Set{y + i, 0}->max() ; var y1 : OclAny := Set{x - i, 0}->max() ; var x : OclAny := null; var y : OclAny := null; var ans : OclAny := null; Sequence{x,y,ans} := Sequence{x1,y1,Set{x1, y1, ans}->max()}) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def heptdiagonal(a): if(a<0): return-1 d=1.802*a return round(d,3) if __name__=="__main__" : a=6 print(heptdiagonal(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := 6 ; execute (heptdiagonal(a))->display() ) else skip; operation heptdiagonal(a : OclAny) : OclAny pre: true post: true activity: if (a < 0) then ( return -1 ) else skip ; var d : double := 1.802 * a ; return MathLib.roundN(d, 3); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def decdiagonal(a): if(a<0): return-1 d=1.902*a return d if __name__=="__main__" : a=9 print(decdiagonal(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := 9 ; execute (decdiagonal(a))->display() ) else skip; operation decdiagonal(a : OclAny) : OclAny pre: true post: true activity: if (a < 0) then ( return -1 ) else skip ; var d : double := 1.902 * a ; return d; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left as bl from math import pi fx=1 fy=1 x1,y1,x2,y2=map(int,input().split()) if x1>x2 : fx=-1 if y1>y2 : fy=-1 N=int(input()) inf=10**9 f=[list(map(int,input().split()))for _ in range(N)] f=[[p[0]*fx,p[1]*fy]for p in f if(min(x1,x2)<=p[0]<=max(x1,x2)and min(y1,y2)<=p[1]<=max(y1,y2))] f.sort(key=lambda x :(x[0],-x[1])) lis=[inf]*N lislen=0 for i in range(len(f)): t=f[i][1] ind=bl(lis,t) lis[ind]=t lislen=max(lislen,ind+1) if lislen==min(abs(x2-x1),abs(y2-y1))+1 : print((abs(x2-x1)+abs(y2-y1))*100-20*lislen+10*pi+5*pi*max(lislen-1,0)) else : print((abs(x2-x1)+abs(y2-y1))*100-20*lislen+5*pi*lislen) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var fx : int := 1 ; var fy : int := 1 ; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (x1->compareTo(x2)) > 0 then ( fx := -1 ) else skip ; if (y1->compareTo(y2)) > 0 then ( fy := -1 ) else skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var Math_PINFINITY : double := (10)->pow(9) ; var f : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; f := f->select(p | ((Set{x1, x2}->min()->compareTo(p->first())) <= 0 & (p->first() <= Set{x1, x2}->max()) & (Set{y1, y2}->min()->compareTo(p[1+1])) <= 0 & (p[1+1] <= Set{y1, y2}->max())))->collect(p | (Sequence{p->first() * fx}->union(Sequence{ p[1+1] * fy }))) ; f := f->sort() ; var lis : Sequence := MatrixLib.elementwiseMult(Sequence{ Math_PINFINITY }, N) ; var lislen : int := 0 ; for i : Integer.subrange(0, (f)->size()-1) do ( var t : OclAny := f[i+1][1+1] ; var ind : OclAny := bl(lis, t) ; lis[ind+1] := t ; lislen := Set{lislen, ind + 1}->max()) ; if lislen = Set{(x2 - x1)->abs(), (y2 - y1)->abs()}->min() + 1 then ( execute (((x2 - x1)->abs() + (y2 - y1)->abs()) * 100 - 20 * lislen + 10 * pi + 5 * pi * Set{lislen - 1, 0}->max())->display() ) else ( execute (((x2 - x1)->abs() + (y2 - y1)->abs()) * 100 - 20 * lislen + 5 * pi * lislen)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math al=0 bl=0 cl=0 dl=0 ar=0 br=0 cr=0 dr=0 try : while True : l,r=map(float,input().split()) if(l>=1.1): al=al+1 elif(l>=0.6 and l<1.1): bl=bl+1 elif(l>=0.2 and l<0.6): cl=cl+1 else : dl=dl+1 if(r>=1.1): ar=ar+1 elif(r>=0.6 and r<1.1): br=br+1 elif(r>=0.2 and r<0.6): cr=cr+1 else : dr=dr+1 except EOFError : pass print(str(al)+' '+str(ar)) print(str(bl)+' '+str(br)) print(str(cl)+' '+str(cr)) print(str(dl)+' '+str(dr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var al : int := 0 ; var bl : int := 0 ; var cl : int := 0 ; var dl : int := 0 ; var ar : int := 0 ; var br : int := 0 ; var cr : int := 0 ; var dr : int := 0 ; try ( while true do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; if (l >= 1.1) then ( al := al + 1 ) else (if (l >= 0.6 & l < 1.1) then ( bl := bl + 1 ) else (if (l >= 0.2 & l < 0.6) then ( cl := cl + 1 ) else ( dl := dl + 1 ) ) ) ; if (r >= 1.1) then ( ar := ar + 1 ) else (if (r >= 0.6 & r < 1.1) then ( br := br + 1 ) else (if (r >= 0.2 & r < 0.6) then ( cr := cr + 1 ) else ( dr := dr + 1 ) ) ) )) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt pass))))) ; execute (("" + ((al))) + ' ' + ("" + ((ar))))->display() ; execute (("" + ((bl))) + ' ' + ("" + ((br))))->display() ; execute (("" + ((cl))) + ' ' + ("" + ((cr))))->display() ; execute (("" + ((dl))) + ' ' + ("" + ((dr))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda : sys.stdin.readline().rstrip() from math import pi from bisect import bisect_left def resolve(): x1,y1,x2,y2=map(int,input().split()) if(x1>x2): x1,y1,x2,y2=x2,y2,x1,y1 trans=False if(y1>y2): y1,y2=-y1,-y2 trans=True n=int(input()) XY=[] for i in range(n): x,y=map(int,input().split()) if(trans): y=-y if(x1<=x<=x2 and y1<=y<=y2): XY.append((x,y)) d=(x2-x1)+(y2-y1) d*=100 l=min(x2-x1,y2-y1) XY.sort() C=[INF]*(n+1) for x,y in XY : i=bisect_left(C,y) C[i]=y k=C.index(INF) if(k>l): d-=(k-1)*(20-5*pi) d+=10*pi-20 else : d-=k*(20-5*pi) print(d) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(2147483647) ; var INF : double := ("" + (("inf")))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; skip ; skip ; skip ; resolve(); operation resolve() pre: true post: true activity: var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if ((x1->compareTo(x2)) > 0) then ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := Sequence{x2,y2,x1,y1} ) else skip ; var trans : boolean := false ; if ((y1->compareTo(y2)) > 0) then ( var y1 : OclAny := null; var y2 : OclAny := null; Sequence{y1,y2} := Sequence{-y1,-y2} ; trans := true ) else skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var XY : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (trans) then ( var y : OclAny := -y ) else skip ; if ((x1->compareTo(x)) <= 0 & (x <= x2) & (y1->compareTo(y)) <= 0 & (y <= y2)) then ( execute ((Sequence{x, y}) : XY) ) else skip) ; var d : double := (x2 - x1) + (y2 - y1) ; d := d * 100 ; var l : OclAny := Set{x2 - x1, y2 - y1}->min() ; XY := XY->sort() ; var C : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, (n + 1)) ; for _tuple : XY do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); var i : OclAny := bisect_left(C, y) ; C[i+1] := y) ; var k : int := C->indexOf(INF) - 1 ; if ((k->compareTo(l)) > 0) then ( d := d - (k - 1) * (20 - 5 * pi) ; d := d + 10 * pi - 20 ) else ( d := d - k * (20 - 5 * pi) ) ; execute (d)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def LIS(N,a): res=0 dp=[1]*N for i in range(N): for j in range(i): if XY[j][0]x1)-1 ysgn=2*(y2>y1)-1 XY=[] for i in range(N): x,y=map(int,input().split()) if(x-x1)*(x-x2)<=0 and(y-y1)*(y-y2)<=0 : XY+=[[xsgn*(x-x1),ysgn*(y-y1)]] N=len(XY) short=20-5*math.pi long=10*math.pi-20 straight=100*(W+H) from bisect import bisect XY.sort() XY=[y for x,y in XY] dp=[H+1]*len(XY) for i,f in enumerate(XY): dp[bisect(dp,f)]=f fountain=bisect(dp,H) if fountaincollect( _x | (OclType["int"])->apply(_x) ) ; N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var W : double := (x2 - x1)->abs() ; var H : double := (y2 - y1)->abs() ; var xsgn : double := 2 * ((x2->compareTo(x1)) > 0) - 1 ; var ysgn : double := 2 * ((y2->compareTo(y1)) > 0) - 1 ; var XY : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (x - x1) * (x - x2) <= 0 & (y - y1) * (y - y2) <= 0 then ( XY := XY + Sequence{ Sequence{xsgn * (x - x1)}->union(Sequence{ ysgn * (y - y1) }) } ) else skip) ; N := (XY)->size() ; var short : double := 20 - 5 * ; var long : double := 10 * - 20 ; var straight : double := 100 * (W + H) ; skip ; XY := XY->sort() ; XY := XY->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (y)) ; dp := MatrixLib.elementwiseMult(Sequence{ H + 1 }, (XY)->size()) ; for _tuple : Integer.subrange(1, (XY)->size())->collect( _indx | Sequence{_indx-1, (XY)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var f : OclAny := _tuple->at(_indx); dp[bisect(dp, f)+1] := f) ; var fountain : OclAny := bisect(dp, H) ; if (fountain->compareTo(Set{W, H}->min() + 1)) < 0 then ( execute (straight - short * fountain)->display() ) else ( execute (straight - short * (fountain - 1) + long)->display() ); operation LIS(N : OclAny, a : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, N) ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, i-1) do ( if (XY[j+1]->first()->compareTo(XY[i+1]->first())) < 0 & (XY[j+1][1+1]->compareTo(XY[i+1][1+1])) < 0 then ( dp[i+1] := Set{dp[i+1], dp[j+1] + 1}->max() ) else skip) ; res := Set{res, dp[i+1]}->max()) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import numpy as np read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines def longest_increasing_subsequence(seq): side='left' N=len(seq) INF=10**18 dp=np.full_like(seq,INF) for x in seq : i=np.searchsorted(dp,x,side) dp[i]=x return np.searchsorted(dp,INF-1,side) if sys.argv[-1]=='ONLINE_JUDGE' : import numba from numba.pycc import CC i8=numba.from_dtype(np.int64) signature=(i8[:],) cc=CC('my_module') cc.export('longest_increasing_subsequence',signature)(longest_increasing_subsequence) cc.compile() from my_module import longest_increasing_subsequence x1,y1,x2,y2=map(int,readline().split()) N=int(readline()) XY=np.array(read().split(),np.int64) X=XY[: : 2] Y=XY[1 : : 2] if x1>x2 : x1,x2=x2,x1 y1,y2=y2,y1 if y1>y2 : y1,y2=-y1,-y2 Y=-Y X-=x1 Y-=y1 x=x2-x1 y=y2-y1 cond=(X>=0)&(X<=x)&(Y>=0)&(Y<=y) X=X[cond] Y=Y[cond] ind=np.argsort(X) X=X[ind] Y=Y[ind] n=longest_increasing_subsequence(Y) answer=x+y answer-=(0.2-0.1*np.pi/2)*n if n==min(x,y)+1 : answer+=0.1*np.pi/2 answer*=100 print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; skip ; if (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) = 'ONLINE_JUDGE' then ( skip ; skip ; var i8 : OclAny := numba.from_dtype() ; var signature : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name i8)) (trailer (arguments [ (subscriptlist (subscript :)) ])))))) ,)} ; var cc : OclAny := CC('my_module') ; (expr (atom (name cc)) (trailer . (name export) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'longest_increasing_subsequence')))))) , (argument (test (logical_test (comparison (expr (atom (name signature)))))))) ))) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name longest_increasing_subsequence)))))))) )))) ; cc.compile() ) else skip ; skip ; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; N := ("" + ((readline())))->toInteger() ; var XY : Sequence := (read().split(), ) ; var X : OclAny := XY(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ; var Y : OclAny := XY(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ; if (x1->compareTo(x2)) > 0 then ( var x1 : OclAny := null; var x2 : OclAny := null; Sequence{x1,x2} := Sequence{x2,x1} ; var y1 : OclAny := null; var y2 : OclAny := null; Sequence{y1,y2} := Sequence{y2,y1} ) else skip ; if (y1->compareTo(y2)) > 0 then ( var y1 : OclAny := null; var y2 : OclAny := null; Sequence{y1,y2} := Sequence{-y1,-y2} ; Y := -Y ) else skip ; X := X - x1 ; Y := Y - y1 ; var x : double := x2 - x1 ; var y : double := y2 - y1 ; var cond : int := MathLib.bitwiseAnd(MathLib.bitwiseAnd(MathLib.bitwiseAnd((X >= 0), ((X->compareTo(x)) <= 0)), (Y >= 0)), ((Y->compareTo(y)) <= 0)) ; X := X[cond+1] ; Y := Y[cond+1] ; var ind : (trailer . (name argsort) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name X)))))))) ))) := ; X := X[ind+1] ; Y := Y[ind+1] ; var n : OclAny := longest_increasing_subsequence(Y) ; var answer : OclAny := x + y ; answer := answer - (0.2 - 0.1 * MathLib.piValue() / 2) * n ; if n = Set{x, y}->min() + 1 then ( answer := answer + 0.1 * MathLib.piValue() / 2 ) else skip ; answer := answer * 100 ; execute (answer)->display(); operation longest_increasing_subsequence(seq : OclAny) : OclAny pre: true post: true activity: var side : String := 'left' ; var N : int := (seq)->size() ; var INF : double := (10)->pow(18) ; var dp : Sequence := MatrixLib.singleValueMatrix(MatrixLib.shape(seq), INF) ; for x : seq do ( var i : (trailer . (name searchsorted) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name dp))))))) , (argument (test (logical_test (comparison (expr (atom (name x))))))) , (argument (test (logical_test (comparison (expr (atom (name side)))))))) ))) := ; dp[i+1] := x) ; return ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import bisect input=sys.stdin.readline pi=3.1415926535897938 x1,y1,x2,y2=[int(v)for v in input().split()] if x1>x2 : x1,x2=x2,x1 y1,y2=y2,y1 ans=100*(abs(x2-x1)+abs(y2-y1)) d=-1 if y1>y2 else 1 xmax,xmin=max(x1,x2),min(x1,x2) ymax,ymin=max(y1,y2),min(y1,y2) n=int(input()) fountains=[] for i in range(n): x,y=[int(v)for v in input().split()] if xmin<=x<=xmax and ymin<=y<=ymax : fountains.append([x,y]) if x1==x2 or y1==y2 : if len(fountains)==1 : ans+=10*pi-20 else : fountains.sort() fountains=[-10**9]+[i[1]*d for i in fountains] m=len(fountains) lis_list=[10**9 for i in range(m)] for i in fountains : a=bisect.bisect_left(lis_list,i) lis_list[a]=i k=-1 for i in lis_list : if i!=10**9 : k+=1 if xmax-xmin+1==k or ymax-ymin+1==k : ans-=(k-1)*(20-5*pi) ans+=10*pi-20 else : ans-=k*(20-5*pi) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var pi : double := 3.1415926535897938 ; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := input().split()->select(v | true)->collect(v | (("" + ((v)))->toInteger())) ; if (x1->compareTo(x2)) > 0 then ( var x1 : OclAny := null; var x2 : OclAny := null; Sequence{x1,x2} := Sequence{x2,x1} ; var y1 : OclAny := null; var y2 : OclAny := null; Sequence{y1,y2} := Sequence{y2,y1} ) else skip ; var ans : double := 100 * ((x2 - x1)->abs() + (y2 - y1)->abs()) ; var d : int := if (y1->compareTo(y2)) > 0 then -1 else 1 endif ; var xmax : OclAny := null; var xmin : OclAny := null; Sequence{xmax,xmin} := Sequence{Set{x1, x2}->max(),Set{x1, x2}->min()} ; var ymax : OclAny := null; var ymin : OclAny := null; Sequence{ymax,ymin} := Sequence{Set{y1, y2}->max(),Set{y1, y2}->min()} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var fountains : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := input().split()->select(v | true)->collect(v | (("" + ((v)))->toInteger())) ; if (xmin->compareTo(x)) <= 0 & (x <= xmax) & (ymin->compareTo(y)) <= 0 & (y <= ymax) then ( execute ((Sequence{x}->union(Sequence{ y })) : fountains) ) else skip) ; if x1 = x2 or y1 = y2 then ( if (fountains)->size() = 1 then ( ans := ans + 10 * pi - 20 ) else skip ) else ( fountains := fountains->sort() ; fountains := Sequence{ (-10)->pow(9) }->union(fountains->select(i | true)->collect(i | (i[1+1] * d))) ; var m : int := (fountains)->size() ; var lis_list : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | ((10)->pow(9))) ; for i : fountains do ( var a : OclAny := bisect.bisect_left(lis_list, i) ; lis_list[a+1] := i) ; var k : int := -1 ; for i : lis_list do ( if i /= (10)->pow(9) then ( k := k + 1 ) else skip) ; if xmax - xmin + 1 = k or ymax - ymin + 1 = k then ( ans := ans - (k - 1) * (20 - 5 * pi) ; ans := ans + 10 * pi - 20 ) else ( ans := ans - k * (20 - 5 * pi) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def convert(n,a,b): l=[0]*n for i in range(n): if(a[i]!=b[i]): l[i]=1 cc=0 vl=0 for i in range(n): if(l[i]==0): if(vl!=0): cc+=1 vl=0 else : vl+=1 if(vl!=0): cc+=1 print(cc) a="101010" b="110011" n=len(a) convert(n,a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := "101010" ; b := "110011" ; n := (a)->size() ; convert(n, a, b); operation convert(n : OclAny, a : OclAny, b : OclAny) pre: true post: true activity: var l : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] /= b[i+1]) then ( l[i+1] := 1 ) else skip) ; var cc : int := 0 ; var vl : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (l[i+1] = 0) then ( if (vl /= 0) then ( cc := cc + 1 ) else skip ; vl := 0 ) else ( vl := vl + 1 )) ; if (vl /= 0) then ( cc := cc + 1 ) else skip ; execute (cc)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=[list(input())for _ in range(3)] p=1 while True : if len(s[p-1])==0 : break c=s[p-1].pop(0) if c=='a' : p=1 elif c=='b' : p=2 else : p=3 if p==1 : print('A') elif p==2 : print('B') elif p==3 : print('C') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (((OclFile["System.in"]).readLine())->characters())) ; var p : int := 1 ; while true do ( if (s[p - 1+1])->size() = 0 then ( break ) else skip ; var c : OclAny := s[p - 1+1]->at(0`firstArg+1) ; if c = 'a' then ( p := 1 ) else (if c = 'b' then ( p := 2 ) else ( p := 3 ) ) ) ; if p = 1 then ( execute ('A')->display() ) else (if p = 2 then ( execute ('B')->display() ) else (if p = 3 then ( execute ('C')->display() ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): a=[] n,k=map(int,input().split()) if n=k*2 : print('YES') for j in range(k-1): a.append(2) a.append(n-sum(a)) print(*a) else : for j in range(k-1): a.append(1) a.append(n-sum(a)) print('YES') print(*a) if n % 2!=0 and k % 2!=0 : for j in range(k-1): a.append(1) a.append(n-sum(a)) print('YES') print(*a) if n % 2==0 and k % 2!=0 : if n>=k*2 : for j in range(k-1): a.append(2) a.append(n-sum(a)) print('YES') print(*a) else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : Sequence := Sequence{} ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (n->compareTo(k)) < 0 then ( execute ('NO')->display() ; continue ) else skip ; if n mod 2 /= 0 & k mod 2 = 0 then ( execute ('NO')->display() ; continue ) else skip ; if n mod 2 = 0 & k mod 2 = 0 then ( if (n->compareTo(k * 2)) >= 0 then ( execute ('YES')->display() ; for j : Integer.subrange(0, k - 1-1) do ( execute ((2) : a)) ; execute ((n - (a)->sum()) : a) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display() ) else ( for j : Integer.subrange(0, k - 1-1) do ( execute ((1) : a)) ; execute ((n - (a)->sum()) : a) ; execute ('YES')->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display() ) ) else skip ; if n mod 2 /= 0 & k mod 2 /= 0 then ( for j : Integer.subrange(0, k - 1-1) do ( execute ((1) : a)) ; execute ((n - (a)->sum()) : a) ; execute ('YES')->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display() ) else skip ; if n mod 2 = 0 & k mod 2 /= 0 then ( if (n->compareTo(k * 2)) >= 0 then ( for j : Integer.subrange(0, k - 1-1) do ( execute ((2) : a)) ; execute ((n - (a)->sum()) : a) ; execute ('YES')->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display() ) else ( execute ('NO')->display() ) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- SA=input() SB=input() SC=input() a,b,c=0,0,0 turnc="a" while a<=len(SA)and b<=len(SB)and c<=len(SC): if turnc=="a" : if a==len(SA): print("A") exit(0) turnc=SA[a] a+=1 elif turnc=="b" : if b==len(SB): print("B") exit(0) turnc=SB[b] b+=1 else : if c==len(SC): print("C") exit(0) turnc=SC[c] c+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var SA : String := (OclFile["System.in"]).readLine() ; var SB : String := (OclFile["System.in"]).readLine() ; var SC : String := (OclFile["System.in"]).readLine() ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{0,0,0} ; var turnc : String := "a" ; while (a->compareTo((SA)->size())) <= 0 & (b->compareTo((SB)->size())) <= 0 & (c->compareTo((SC)->size())) <= 0 do ( if turnc = "a" then ( if a = (SA)->size() then ( execute ("A")->display() ; exit(0) ) else skip ; turnc := SA[a+1] ; a := a + 1 ) else (if turnc = "b" then ( if b = (SB)->size() then ( execute ("B")->display() ; exit(0) ) else skip ; turnc := SB[b+1] ; b := b + 1 ) else ( if c = (SC)->size() then ( execute ("C")->display() ; exit(0) ) else skip ; turnc := SC[c+1] ; c := c + 1 ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sa=str(input()) sb=str(input()) sc=str(input()) sa_len=len(sa) sb_len=len(sb) sc_len=len(sc) sa_turn=1 sb_turn=0 sc_turn=0 sa_pl=0 sb_pl=0 sc_pl=0 while True : if sa_turn==1 : if sa_len==sa_pl : print("A") break elif sa[sa_pl]=="a" : sa_pl+=1 elif sa[sa_pl]=="b" : sa_turn=0 sb_turn=1 sa_pl+=1 elif sa[sa_pl]=="c" : sa_turn=0 sc_turn=1 sa_pl+=1 elif sb_turn==1 : if sb_len==sb_pl : print("B") break elif sb[sb_pl]=="b" : sb_pl+=1 elif sb[sb_pl]=="a" : sb_turn=0 sa_turn=1 sb_pl+=1 elif sb[sb_pl]=="c" : sb_turn=0 sc_turn=1 sb_pl+=1 elif sc_turn==1 : if sc_len==sc_pl : print("C") break elif sc[sc_pl]=="c" : sc_pl+=1 elif sc[sc_pl]=="b" : sc_turn=0 sb_turn=1 sc_pl+=1 elif sc[sc_pl]=="a" : sc_turn=0 sa_turn=1 sc_pl+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sa : String := ("" + (((OclFile["System.in"]).readLine()))) ; var sb : String := ("" + (((OclFile["System.in"]).readLine()))) ; var sc : String := ("" + (((OclFile["System.in"]).readLine()))) ; var sa_len : int := (sa)->size() ; var sb_len : int := (sb)->size() ; var sc_len : int := (sc)->size() ; var sa_turn : int := 1 ; var sb_turn : int := 0 ; var sc_turn : int := 0 ; var sa_pl : int := 0 ; var sb_pl : int := 0 ; var sc_pl : int := 0 ; while true do ( if sa_turn = 1 then ( if sa_len = sa_pl then ( execute ("A")->display() ; break ) else (if sa[sa_pl+1] = "a" then ( sa_pl := sa_pl + 1 ) else (if sa[sa_pl+1] = "b" then ( sa_turn := 0 ; sb_turn := 1 ; sa_pl := sa_pl + 1 ) else (if sa[sa_pl+1] = "c" then ( sa_turn := 0 ; sc_turn := 1 ; sa_pl := sa_pl + 1 ) else skip ) ) ) ) else (if sb_turn = 1 then ( if sb_len = sb_pl then ( execute ("B")->display() ; break ) else (if sb[sb_pl+1] = "b" then ( sb_pl := sb_pl + 1 ) else (if sb[sb_pl+1] = "a" then ( sb_turn := 0 ; sa_turn := 1 ; sb_pl := sb_pl + 1 ) else (if sb[sb_pl+1] = "c" then ( sb_turn := 0 ; sc_turn := 1 ; sb_pl := sb_pl + 1 ) else skip ) ) ) ) else (if sc_turn = 1 then ( if sc_len = sc_pl then ( execute ("C")->display() ; break ) else (if sc[sc_pl+1] = "c" then ( sc_pl := sc_pl + 1 ) else (if sc[sc_pl+1] = "b" then ( sc_turn := 0 ; sb_turn := 1 ; sc_pl := sc_pl + 1 ) else (if sc[sc_pl+1] = "a" then ( sc_turn := 0 ; sa_turn := 1 ; sc_pl := sc_pl + 1 ) else skip ) ) ) ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s_a=input() s_b=input() s_c=input() next_=s_a[0] s_a=s_a[1 :] for i in range(100**3): if next_=='a' : if s_a=='' : print('A') break next_=s_a[0] s_a=s_a[1 :] elif next_=='b' : if s_b=='' : print('B') break next_=s_b[0] s_b=s_b[1 :] else : if s_c=='' : print('C') break next_=s_c[0] s_c=s_c[1 :] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s_a : String := (OclFile["System.in"]).readLine() ; var s_b : String := (OclFile["System.in"]).readLine() ; var s_c : String := (OclFile["System.in"]).readLine() ; var next_ : OclAny := s_a->first() ; s_a := s_a->tail() ; for i : Integer.subrange(0, (100)->pow(3)-1) do ( if next_ = 'a' then ( if s_a = '' then ( execute ('A')->display() ; break ) else skip ; next_ := s_a->first() ; s_a := s_a->tail() ) else (if next_ = 'b' then ( if s_b = '' then ( execute ('B')->display() ; break ) else skip ; next_ := s_b->first() ; s_b := s_b->tail() ) else ( if s_c = '' then ( execute ('C')->display() ; break ) else skip ; next_ := s_c->first() ; s_c := s_c->tail() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=[list(input())for _ in range(3)] member=['a','b','c'] ans=['A','B','C'] player=0 cnt=0 for i in range(len(S)): cnt+=len(S[i]) for i in range(cnt): if len(S[player])==0 : print(ans[player]) exit() player=member.index(S[player].pop(0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : Sequence := Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (((OclFile["System.in"]).readLine())->characters())) ; var member : Sequence := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{ 'c' })) ; var ans : Sequence := Sequence{'A'}->union(Sequence{'B'}->union(Sequence{ 'C' })) ; var player : int := 0 ; var cnt : int := 0 ; for i : Integer.subrange(0, (S)->size()-1) do ( cnt := cnt + (S[i+1])->size()) ; for i : Integer.subrange(0, cnt-1) do ( if (S[player+1])->size() = 0 then ( execute (ans[player+1])->display() ; exit() ) else skip ; player := member->indexOf(S[player+1]->at(0`firstArg+1)) - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- la,lb,lc,ld=0,0,0,0 ra,rb,rc,rd=0,0,0,0 while True : try : n=input() except : break l,r=map(float,n.split()) if 1.1<=l : la+=1 elif 0.6<=l<1.1 : lb+=1 elif 0.2<=l<0.6 : lc+=1 elif l<0.2 : ld+=1 if 1.1<=r : ra+=1 elif 0.6<=r<1.1 : rb+=1 elif 0.2<=r<0.6 : rc+=1 elif r<0.2 : rd+=1 print(la,ra) print(lb,rb) print(lc,rc) print(ld,rd) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var la : OclAny := null; var lb : OclAny := null; var lc : OclAny := null; var ld : OclAny := null; Sequence{la,lb,lc,ld} := Sequence{0,0,0,0} ; var ra : OclAny := null; var rb : OclAny := null; var rc : OclAny := null; var rd : OclAny := null; Sequence{ra,rb,rc,rd} := Sequence{0,0,0,0} ; while true do ( try ( var n : String := (OclFile["System.in"]).readLine()) catch (_e : OclException) do ( break) ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (n.split())->collect( _x | (OclType["double"])->apply(_x) ) ; if 1.1 <= l then ( la := la + 1 ) else (if 0.6 <= l & (l < 1.1) then ( lb := lb + 1 ) else (if 0.2 <= l & (l < 0.6) then ( lc := lc + 1 ) else (if l < 0.2 then ( ld := ld + 1 ) else skip ) ) ) ; if 1.1 <= r then ( ra := ra + 1 ) else (if 0.6 <= r & (r < 1.1) then ( rb := rb + 1 ) else (if 0.2 <= r & (r < 0.6) then ( rc := rc + 1 ) else (if r < 0.2 then ( rd := rd + 1 ) else skip ) ) ) ) ; execute (la)->display() ; execute (lb)->display() ; execute (lc)->display() ; execute (ld)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=3 C=4 def gcd(a,b): if(b==0): return a return gcd(b,a % b) def replacematrix(mat,n,m): rgcd=[0]*R cgcd=[0]*C for i in range(n): for j in range(m): rgcd[i]=gcd(rgcd[i],mat[i][j]) cgcd[j]=gcd(cgcd[j],mat[i][j]) for i in range(n): for j in range(m): mat[i][j]=max(rgcd[i],cgcd[j]) if __name__=="__main__" : m=[[1,2,3,3],[4,5,6,6],[7,8,9,9]] replacematrix(m,R,C) for i in range(R): for j in range(C): print(m[i][j],end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : int := 3 ; var C : int := 4 ; skip ; skip ; if __name__ = "__main__" then ( m := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 3 })))}->union(Sequence{Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 6 })))}->union(Sequence{ Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{ 9 }))) })) ; replacematrix(m, R, C) ; for i : Integer.subrange(0, R-1) do ( for j : Integer.subrange(0, C-1) do ( execute (m[i+1][j+1])->display()) ; execute (->display()) ) else skip; operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (b = 0) then ( return a ) else skip ; return gcd(b, a mod b); operation replacematrix(mat : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: var rgcd : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, R) ; var cgcd : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, C) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( rgcd[i+1] := gcd(rgcd[i+1], mat[i+1][j+1]) ; cgcd[j+1] := gcd(cgcd[j+1], mat[i+1][j+1]))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( mat[i+1][j+1] := Set{rgcd[i+1], cgcd[j+1]}->max())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) p1,p2,p3=a[0],b[0],c[0] n-=p1+p2+p3 a[1]=a[1]-a[0] b[1]=b[1]-b[0] c[1]=c[1]-c[0] if a[1]>n : p1+=n n=0 else : p1+=a[1] n-=a[1] if b[1]>n : p2+=n n=0 else : p2+=b[1] n-=b[1] if c[1]>n : p3+=n n=0 else : p3+=c[1] n-=c[1] print(p1,p2,p3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var p1 : OclAny := null; var p2 : OclAny := null; var p3 : OclAny := null; Sequence{p1,p2,p3} := Sequence{a->first(),b->first(),c->first()} ; n := n - p1 + p2 + p3 ; a[1+1] := a[1+1] - a->first() ; b[1+1] := b[1+1] - b->first() ; c[1+1] := c[1+1] - c->first() ; if (a[1+1]->compareTo(n)) > 0 then ( p1 := p1 + n ; n := 0 ) else ( p1 := p1 + a[1+1] ; n := n - a[1+1] ) ; if (b[1+1]->compareTo(n)) > 0 then ( p2 := p2 + n ; n := 0 ) else ( p2 := p2 + b[1+1] ; n := n - b[1+1] ) ; if (c[1+1]->compareTo(n)) > 0 then ( p3 := p3 + n ; n := 0 ) else ( p3 := p3 + c[1+1] ; n := n - c[1+1] ) ; execute (p1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) d1=list(map(int,input().split())) d2=list(map(int,input().split())) d3=list(map(int,input().split())) choose1=min(n-d2[0]-d3[0],d1[1]) choose2=min(n-choose1-d3[0],d2[1]) choose3=n-choose1-choose2 print(choose1,choose2,choose3,sep=' ') if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d3 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var choose1 : OclAny := Set{n - d2->first() - d3->first(), d1[1+1]}->min() ; var choose2 : OclAny := Set{n - choose1 - d3->first(), d2[1+1]}->min() ; var choose3 : double := n - choose1 - choose2 ; execute (choose1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) a1,b1=map(int,input().split()) a2,b2=map(int,input().split()) a3,b3=map(int,input().split()) d=[a1,a2,a3] n-=sum(d) while n : d[0]+=min(b1-a1,n) n-=min(b1-a1,n) if n==0 : break else : d[1]+=min(b2-a2,n) n-=min(b2-a2,n) if n==0 : break else : d[2]+=min(b3-a3,n) n-=min(b3-a3,n) print(*d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a1 : OclAny := null; var b1 : OclAny := null; Sequence{a1,b1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a2 : OclAny := null; var b2 : OclAny := null; Sequence{a2,b2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a3 : OclAny := null; var b3 : OclAny := null; Sequence{a3,b3} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := Sequence{a1}->union(Sequence{a2}->union(Sequence{ a3 })) ; n := n - (d)->sum() ; while n do ( d->first() := d->first() + Set{b1 - a1, n}->min() ; n := n - Set{b1 - a1, n}->min() ; if n = 0 then ( break ) else ( d[1+1] := d[1+1] + Set{b2 - a2, n}->min() ; n := n - Set{b2 - a2, n}->min() ; if n = 0 then ( break ) else ( d[2+1] := d[2+1] + Set{b3 - a3, n}->min() ; n := n - Set{b3 - a3, n}->min() ) )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name d))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) a1,b1=map(int,input().split()) a2,b2=map(int,input().split()) a3,b3=map(int,input().split()) d=[a1,a2,a3] n-=sum(d) while n : d[0]+=min(b1-a1,n) n-=min(b1-a1,n) if n==0 : break else : d[1]+=min(b2-a2,n) n-=min(b2-a2,n) if n==0 : break else : d[2]+=min(b3-a3,n) n-=min(b3-a3,n) print(*d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a1 : OclAny := null; var b1 : OclAny := null; Sequence{a1,b1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a2 : OclAny := null; var b2 : OclAny := null; Sequence{a2,b2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a3 : OclAny := null; var b3 : OclAny := null; Sequence{a3,b3} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := Sequence{a1}->union(Sequence{a2}->union(Sequence{ a3 })) ; n := n - (d)->sum() ; while n do ( d->first() := d->first() + Set{b1 - a1, n}->min() ; n := n - Set{b1 - a1, n}->min() ; if n = 0 then ( break ) else ( d[1+1] := d[1+1] + Set{b2 - a2, n}->min() ; n := n - Set{b2 - a2, n}->min() ; if n = 0 then ( break ) else ( d[2+1] := d[2+1] + Set{b3 - a3, n}->min() ; n := n - Set{b3 - a3, n}->min() ) )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name d))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil t=int(input()) for i in range(t): ch=input() t=ch.split() n=int(t[0]) k=int(t[1]) t=[] if k==1 : print('YES\n',n) elif n==k : print('YES\n',' '.join(['1' for i in range(k)])) elif((n-((k-1)*2))% 2==0 and(n-((k-1)*2)>0)): for i in range(k-1): t.append('2') t.append(str(n-((k-1)*2))) print('YES\n',' '.join(t)) elif((n-(k-1))% 2==1 and(n-(k-1))>0): for i in range(k-1): t.append('1') t.append(str(n-(k-1))) print('YES\n',' '.join(t)) else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var ch : String := (OclFile["System.in"]).readLine() ; t := ch.split() ; var n : int := ("" + ((t->first())))->toInteger() ; var k : int := ("" + ((t[1+1])))->toInteger() ; t := Sequence{} ; if k = 1 then ( execute ('YES ')->display() ) else (if n = k then ( execute ('YES ')->display() ) else (if ((n - ((k - 1) * 2)) mod 2 = 0 & (n - ((k - 1) * 2) > 0)) then ( for i : Integer.subrange(0, k - 1-1) do ( execute (('2') : t)) ; execute ((("" + ((n - ((k - 1) * 2))))) : t) ; execute ('YES ')->display() ) else (if ((n - (k - 1)) mod 2 = 1 & (n - (k - 1)) > 0) then ( for i : Integer.subrange(0, k - 1-1) do ( execute (('1') : t)) ; execute ((("" + ((n - (k - 1))))) : t) ; execute ('YES ')->display() ) else ( execute ('NO')->display() ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a1,b1=map(int,input().split()) a2,b2=map(int,input().split()) a3,b3=map(int,input().split()) p=a1 q=a2 r=a3 if(n-a1-a2-a3)>(b1-a1): p=b1 if n-b1-a2-a3>b2-a2 : q=b2 r=n-b1-b2 else : q=a2+n-b1-a2-a3 else : p=a1+n-a1-a2-a3 print(p,q,r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a1 : OclAny := null; var b1 : OclAny := null; Sequence{a1,b1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a2 : OclAny := null; var b2 : OclAny := null; Sequence{a2,b2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a3 : OclAny := null; var b3 : OclAny := null; Sequence{a3,b3} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : OclAny := a1 ; var q : OclAny := a2 ; var r : OclAny := a3 ; if ((n - a1 - a2 - a3)->compareTo((b1 - a1))) > 0 then ( p := b1 ; if (n - b1 - a2 - a3->compareTo(b2 - a2)) > 0 then ( q := b2 ; r := n - b1 - b2 ) else ( q := a2 + n - b1 - a2 - a3 ) ) else ( p := a1 + n - a1 - a2 - a3 ) ; execute (p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=dict() b=dict() for i in range(int(input())): e,y=map(int,input().split()) a[e]=y for i in range(int(input())): e,y=map(int,input().split()) b[e]=y s=dict() for i in a : if i in b : s[i]=max(a[i],b[i]) else : s[i]=a[i] for i in b : if i in a : s[i]=max(a[i],b[i]) else : s[i]=b[i] s1=0 for i in s : s1+=s[i] print(s1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Map := (arguments ( )) ; var b : Map := (arguments ( )) ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var e : OclAny := null; var y : OclAny := null; Sequence{e,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a[e+1] := y) ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var e : OclAny := null; var y : OclAny := null; Sequence{e,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; b[e+1] := y) ; var s : Map := (arguments ( )) ; for i : a->keys() do ( if (b)->includes(i) then ( s[i+1] := Set{a[i+1], b[i+1]}->max() ) else ( s[i+1] := a[i+1] )) ; for i : b->keys() do ( if (a)->includes(i) then ( s[i+1] := Set{a[i+1], b[i+1]}->max() ) else ( s[i+1] := b[i+1] )) ; var s1 : int := 0 ; for i : s->keys() do ( s1 := s1 + s[i+1]) ; execute (s1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m={} for _ in range(2): for i in range(int(input())): a,b=map(int,input().split()) m[a]=max(m.get(a,-1),b) print(sum(m.values())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := Set{} ; for _anon : Integer.subrange(0, 2-1) do ( for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; m[a+1] := Set{m.get(a, -1), b}->max())) ; execute ((m.values())->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) m={} for _ in range(2): for i in range(int(input())): a,b=map(int,input().split()) m[a]=max(m.get(a,0),b) print(sum(m.values())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : OclAny := Set{} ; for _anon : Integer.subrange(0, 2-1) do ( for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; m[a+1] := Set{m.get(a, 0), b}->max())) ; execute ((m.values())->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lst=[] elements_ChemForces=int(input()) for i in range(elements_ChemForces): (a,x)=map(int,input().split(' ')) lst.append([a,x]) elements_TopChemist=int(input()) for j in range(elements_TopChemist): (b,x)=map(int,input().split(' ')) lst.append([b,x]) lst.sort() lst.append([0,0]) max_income=0 k=0 while ktoInteger() ; for i : Integer.subrange(0, elements_ChemForces-1) do ( ; var Sequence{a, x} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a}->union(Sequence{ x })) : lst)) ; var elements_TopChemist : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, elements_TopChemist-1) do ( ; var Sequence{b, x} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{b}->union(Sequence{ x })) : lst)) ; lst := lst->sort() ; execute ((Sequence{0}->union(Sequence{ 0 })) : lst) ; var max_income : int := 0 ; var k : int := 0 ; while (k->compareTo((lst)->size() - 1)) < 0 do ( if lst[k+1]->first() = lst[k + 1+1]->first() then ( max_income := max_income + Set{lst[k+1][1+1], lst[k + 1+1][1+1]}->max() ; k := k + 1 ) else ( max_income := max_income + lst[k+1][1+1] ) ; k := k + 1) ; execute (max_income)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin from collections import defaultdict input=stdin.readline def process_data(result,rank): if result>=1.1 : rank['A']+=1 elif result>=0.6 : rank['B']+=1 elif result>=0.2 : rank['C']+=1 else : rank['D']+=1 def main(args): left_rank=defaultdict(int) right_rank=defaultdict(int) for line in sys.stdin : l,r=map(float,line.split()) process_data(l,left_rank) process_data(r,right_rank) print('{}{}'.format(left_rank['A'],right_rank['A'])) print('{}{}'.format(left_rank['B'],right_rank['B'])) print('{}{}'.format(left_rank['C'],right_rank['C'])) print('{}{}'.format(left_rank['D'],right_rank['D'])) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation process_data(result : OclAny, rank : OclAny) pre: true post: true activity: if result >= 1.1 then ( rank->at('A') := rank->at('A') + 1 ) else (if result >= 0.6 then ( rank->at('B') := rank->at('B') + 1 ) else (if result >= 0.2 then ( rank->at('C') := rank->at('C') + 1 ) else ( rank->at('D') := rank->at('D') + 1 ) ) ) ; operation main(args : OclAny) pre: true post: true activity: var left_rank : OclAny := defaultdict(OclType["int"]) ; var right_rank : OclAny := defaultdict(OclType["int"]) ; for line : OclFile["System.in"] do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (line.split())->collect( _x | (OclType["double"])->apply(_x) ) ; process_data(l, left_rank) ; process_data(r, right_rank)) ; execute (StringLib.interpolateStrings('{}{}', Sequence{left_rank->at('A'), right_rank->at('A')}))->display() ; execute (StringLib.interpolateStrings('{}{}', Sequence{left_rank->at('B'), right_rank->at('B')}))->display() ; execute (StringLib.interpolateStrings('{}{}', Sequence{left_rank->at('C'), right_rank->at('C')}))->display() ; execute (StringLib.interpolateStrings('{}{}', Sequence{left_rank->at('D'), right_rank->at('D')}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) c=dict() sum=0 for i in range(n): a,cst=map(int,input().split()) c[a]=[cst,0] m=int(input()) for i in range(m): a,cst=map(int,input().split()) if a not in c : c[a]=[0,0] c[a][1]=cst for i in c : sum+=max(c[i][0],c[i][1]) print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : Map := (arguments ( )) ; var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var cst : OclAny := null; Sequence{a,cst} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; c[a+1] := Sequence{cst}->union(Sequence{ 0 })) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var cst : OclAny := null; Sequence{a,cst} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (c)->excludes(a) then ( c[a+1] := Sequence{0}->union(Sequence{ 0 }) ) else skip ; c[a+1][1+1] := cst) ; for i : c->keys() do ( sum := sum + Set{c[i+1]->first(), c[i+1][1+1]}->max()) ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def kPrimeFactor(n,k): while(n % 2==0): k=k-1 n=n/2 if(k==0): return 2 i=3 while i<=math.sqrt(n): while(n % i==0): if(k==1): return i k=k-1 n=n/i i=i+2 if(n>2 and k==1): return n return-1 n=12 k=3 print(kPrimeFactor(n,k)) n=14 k=3 print(kPrimeFactor(n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 12 ; k := 3 ; execute (kPrimeFactor(n, k))->display() ; n := 14 ; k := 3 ; execute (kPrimeFactor(n, k))->display(); operation kPrimeFactor(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: while (n mod 2 = 0) do ( k := k - 1 ; n := n / 2 ; if (k = 0) then ( return 2 ) else skip) ; var i : int := 3 ; while (i->compareTo((n)->sqrt())) <= 0 do ( while (n mod i = 0) do ( if (k = 1) then ( return i ) else skip ; k := k - 1 ; n := n / i) ; i := i + 2) ; if (n > 2 & k = 1) then ( return n ) else skip ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) print(*((m+1)//2+(1-2*((m-1+i % m)% 2))*((1+i % m)//2)for i in range(n)),sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name m))) + (expr (atom (number (integer 1))))))))) ))) // (expr (atom (number (integer 2))))) + (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) - (expr (expr (atom (number (integer 2)))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name m))) - (expr (atom (number (integer 1))))) + (expr (expr (atom (name i))) % (expr (atom (name m))))))))) ))) % (expr (atom (number (integer 2))))))))) ))))))))) ))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) + (expr (expr (atom (name i))) % (expr (atom (name m))))))))) ))) // (expr (atom (number (integer 2))))))))) )))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) ))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=tuple([int(x)for x in input().split(" ")]) baskets=[(abs((m+1)/2-i),i,0)for i in range(1,m+1)] baskets.sort() for i in range(1,n+1): j=(i-1)%(m) d_to_center,basket_index,n_balls=baskets[j] baskets[j]=(d_to_center,basket_index,n_balls+1) print(basket_index) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) ; var baskets : Sequence := Integer.subrange(1, m + 1-1)->select(i | true)->collect(i | (Sequence{((m + 1) / 2 - i)->abs(), i, 0})) ; baskets := baskets->sort() ; for i : Integer.subrange(1, n + 1-1) do ( var j : int := (i - 1) mod (m) ; var d_to_center : OclAny := null; var basket_index : OclAny := null; var n_balls : OclAny := null; Sequence{d_to_center,basket_index,n_balls} := baskets[j+1] ; baskets[j+1] := Sequence{d_to_center, basket_index, n_balls + 1} ; execute (basket_index)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) if n0 : print('YES') s=str(b+2)+' 2'*(k-1) print(s) else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (n->compareTo(k)) < 0 then ( execute ('NO')->display() ) else (if n mod k = 0 then ( var s : double := (("" + ((n div k))) + ' ') * k ; execute ('YES')->display() ; execute (s->front())->display() ) else ( var a : double := n - k ; var b : double := n - 2 * k ; if a mod 2 = 0 then ( execute ('YES')->display() ; s := ("" + ((a + 1))) + StringLib.nCopies(' 1', (k - 1)) ; execute (s)->display() ) else (if b mod 2 = 0 & b > 0 then ( execute ('YES')->display() ; s := ("" + ((b + 2))) + StringLib.nCopies(' 2', (k - 1)) ; execute (s)->display() ) else ( execute ('NO')->display() ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : input=input().split(' ') n=int(input[0]) m=int(input[1]) for i in range(n): if(m+(i % m))% 2 : print(int((m+1+(i % m))/2)) else : print(int((m-(i % m))/2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var input : OclAny := input().split(' ') ; var n : int := ("" + (((OclFile["System.in"]).readLine->first())))->toInteger() ; var m : int := ("" + (((OclFile["System.in"]).readLine[1+1])))->toInteger() ; for i : Integer.subrange(0, n-1) do ( if (m + (i mod m)) mod 2 then ( execute (("" + (((m + 1 + (i mod m)) / 2)))->toInteger())->display() ) else ( execute (("" + (((m - (i mod m)) / 2)))->toInteger())->display() )) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- data=input().split(" ") bal,bas=map(int,data) for i in range(bal): if(bas+i % bas)% 2==0 : print(int((bas-(i % bas))/2)) else : print(int((bas+i % bas+1)/2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var data : OclAny := input().split(" ") ; var bal : OclAny := null; var bas : OclAny := null; Sequence{bal,bas} := (data)->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, bal-1) do ( if (bas + i mod bas) mod 2 = 0 then ( execute (("" + (((bas - (i mod bas)) / 2)))->toInteger())->display() ) else ( execute (("" + (((bas + i mod bas + 1) / 2)))->toInteger())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : n,m=map(int,input().split()) if m==1 : for i in range(n): print(1) elif m==2 : for i in range(n): if i % 2==0 : print(1) else : print(2) else : for i in range(n): k=i % m if(m+k)% 2 : resp=int((m+1+k)/2) else : resp=int((m-k)/2) print(resp) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if m = 1 then ( for i : Integer.subrange(0, n-1) do ( execute (1)->display()) ) else (if m = 2 then ( for i : Integer.subrange(0, n-1) do ( if i mod 2 = 0 then ( execute (1)->display() ) else ( execute (2)->display() )) ) else ( for i : Integer.subrange(0, n-1) do ( var k : int := i mod m ; if (m + k) mod 2 then ( var resp : int := ("" + (((m + 1 + k) / 2)))->toInteger() ) else ( resp := ("" + (((m - k) / 2)))->toInteger() ) ; execute (resp)->display()) ) ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() ans=len(s)-len(set(s)) if ans<=26-len(set(s)): print(ans) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var ans : double := (s)->size() - (Set{}->union((s)))->size() ; if (ans->compareTo(26 - (Set{}->union((s)))->size())) <= 0 then ( execute (ans)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict d=defaultdict(int) n=int(input()) c=input() if n>26 : print(-1) else : for char in c : d[char]+=1 tot=0 for i in d.values(): tot+=(i-1) print(tot) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var d : OclAny := defaultdict(OclType["int"]) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : String := (OclFile["System.in"]).readLine() ; if n > 26 then ( execute (-1)->display() ) else ( for char : c->characters() do ( d[char+1] := d[char+1] + 1) ; var tot : int := 0 ; for i : d.values() do ( tot := tot + (i - 1)) ; execute (tot)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() if n>26 : print(-1) else : a=[0]*30 for x in s : a[ord(x)-97]+=1 ans=0 for x in a : if x : ans+=x-1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; if n > 26 then ( execute (-1)->display() ) else ( var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 30) ; for x : s->characters() do ( a[(x)->char2byte() - 97+1] := a[(x)->char2byte() - 97+1] + 1) ; var ans : int := 0 ; for x : a do ( if x then ( ans := ans + x - 1 ) else skip) ; execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxDifference(arr,N,k): S=0 S1=0 max_difference=0 for i in range(N): S+=arr[i] arr.sort(reverse=True) M=max(k,N-k) for i in range(M): S1+=arr[i] max_difference=S1-(S-S1) return max_difference arr=[8,4,5,2,10] N=len(arr) k=2 print(maxDifference(arr,N,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{8}->union(Sequence{4}->union(Sequence{5}->union(Sequence{2}->union(Sequence{ 10 })))) ; N := (arr)->size() ; k := 2 ; execute (maxDifference(arr, N, k))->display(); operation maxDifference(arr : OclAny, N : OclAny, k : OclAny) : OclAny pre: true post: true activity: var S : int := 0 ; var S1 : int := 0 ; var max_difference : int := 0 ; for i : Integer.subrange(0, N-1) do ( S := S + arr[i+1]) ; arr := arr->sort() ; var M : OclAny := Set{k, N - k}->max() ; for i : Integer.subrange(0, M-1) do ( S1 := S1 + arr[i+1]) ; max_difference := S1 - (S - S1) ; return max_difference; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) y=input() l=[] rl=[] rrl=[] for i in y : l.append(i) for i in l : if not i in rrl : rl.append(l.count(i)) rrl.append(i) if sum(rl)>26 : print(-1) else : print(sum(rl)-len(rl)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var y : String := (OclFile["System.in"]).readLine() ; var l : Sequence := Sequence{} ; var rl : Sequence := Sequence{} ; var rrl : Sequence := Sequence{} ; for i : y->characters() do ( execute ((i) : l)) ; for i : l do ( if not((rrl)->includes(i)) then ( execute ((l->count(i)) : rl) ) else skip ; execute ((i) : rrl)) ; if (rl)->sum() > 26 then ( execute (-1)->display() ) else ( execute ((rl)->sum() - (rl)->size())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() d={} for i in s : if i in d : d[i]+=1 else : d[i]=1 count=0 for i in d : if d[i]>=2 : count+=d[i]-1 if n>26 : print(-1) else : print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var d : OclAny := Set{} ; for i : s->characters() do ( if (d)->includes(i) then ( d[i+1] := d[i+1] + 1 ) else ( d[i+1] := 1 )) ; var count : int := 0 ; for i : d do ( if d[i+1] >= 2 then ( count := count + d[i+1] - 1 ) else skip) ; if n > 26 then ( execute (-1)->display() ) else ( execute (count)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- book=[] while True : try : A=list(input().split()) except EOFError : break new_word="ON" for i in range(len(book)): if A[0]in book[i]: book[i].append(A[1]) new_word="OFF" if new_word=="ON" : book.append([A[0],A[1]]) book.sort() for i in range(len(book)): print(book[i][0]) page=list(int(book[i][j])for j in range(1,len(book[i]))) print(*sorted(page)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var book : Sequence := Sequence{} ; while true do ( try ( var A : Sequence := (input().split())) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))) ; var new_word : String := "ON" ; for i : Integer.subrange(0, (book)->size()-1) do ( if (book[i+1])->includes(A->first()) then ( (expr (atom (name book)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))) ; new_word := "OFF" ) else skip) ; if new_word = "ON" then ( execute ((Sequence{A->first()}->union(Sequence{ A[1+1] })) : book) ) else skip) ; book := book->sort() ; for i : Integer.subrange(0, (book)->size()-1) do ( execute (book[i+1]->first())->display() ; var page : Sequence := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name book)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) ))))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name book)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))))))) ))))))))) ; execute ((argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name page)))))))) )))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n1=input() if n1=="0" : break n2=input() n3=input() l1=len(n1) l2=len(n2) l3=len(n3) if n1=="0" : break else : a1=n1.count("A",1) b1=n1.count("B",1) if n2[: 1]=="A" : a1+=1 if n2[: 1]=="B" : b1+=1 print(a1,b1) a2=n2.count("A",1) b2=n2.count("B",1) if n3[: 1]=="A" : a2+=1 if n3[: 1]=="B" : b2+=1 print(a2,b2) a3=n3.count("A",1) b3=n3.count("B",1) if a3>b3 : a3+=1 if a3size() ; var l2 : int := (n2)->size() ; var l3 : int := (n3)->size() ; if n1 = "0" then ( break ) else ( var a1 : int := n1->count("A", 1) ; var b1 : int := n1->count("B", 1) ; if n2.subrange(1,1) = "A" then ( a1 := a1 + 1 ) else skip ; if n2.subrange(1,1) = "B" then ( b1 := b1 + 1 ) else skip ; execute (a1)->display() ; var a2 : int := n2->count("A", 1) ; var b2 : int := n2->count("B", 1) ; if n3.subrange(1,1) = "A" then ( a2 := a2 + 1 ) else skip ; if n3.subrange(1,1) = "B" then ( b2 := b2 + 1 ) else skip ; execute (a2)->display() ; var a3 : int := n3->count("A", 1) ; var b3 : int := n3->count("B", 1) ; if (a3->compareTo(b3)) > 0 then ( a3 := a3 + 1 ) else skip ; if (a3->compareTo(b3)) < 0 then ( b3 := b3 + 1 ) else skip ; execute (a3)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys l=[i.split()for i in sys.stdin] d={} for i in l : if i[0]not in d : d[i[0]]=[i[1]] else : d[i[0]].append(i[1]) for i in sorted(d.keys()): print(i) d[i]=list(map(int,d[i])) print(" ".join(map(str,sorted(d[i])))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var l : Sequence := OclFile["System.in"]->select(i | true)->collect(i | (i.split())) ; var d : OclAny := Set{} ; for i : l do ( if (d)->excludes(i->first()) then ( d[i->first()+1] := Sequence{ i[1+1] } ) else ( (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))) )) ; for i : d.keys()->sort() do ( execute (i)->display() ; d[i+1] := ((d[i+1])->collect( _x | (OclType["int"])->apply(_x) )) ; execute (StringLib.sumStringsWithSeparator(((d[i+1]->sort())->collect( _x | (OclType["String"])->apply(_x) )), " "))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- key_list=[] page_list=[] while 1 : try : key,page=map(str,input().split()) if key in key_list : page_list[key_list.index(key)].append(int(page)) else : key_list.append(key) page_list.append([int(page)]) except : break key_list_sort=key_list[:] key_list_sort.sort() for i in key_list_sort : print(i) ans=page_list[key_list.index(i)][:] ans.sort() print(' '.join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var key_list : Sequence := Sequence{} ; var page_list : Sequence := Sequence{} ; while 1 do ( try ( var key : OclAny := null; var page : OclAny := null; Sequence{key,page} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; if (key_list)->includes(key) then ( (expr (atom (name page_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name key_list)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name key)))))))) ))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name page)))))))) ))))))))) )))) ) else ( execute ((key) : key_list) ; execute ((Sequence{ ("" + ((page)))->toInteger() }) : page_list) )) catch (_e : OclException) do ( break) ) ; var key_list_sort : Sequence := key_list ; key_list_sort := key_list_sort->sort() ; for i : key_list_sort do ( execute (i)->display() ; var ans : OclAny := page_list[key_list->indexOf(i) - 1+1] ; ans := ans->sort() ; execute (StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- D={} for line in open(0).readlines(): w,p=line.split() D.setdefault(w,[]).append(int(p)) for k,v in sorted(D.items()): print(k) print(*sorted(v)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var D : OclAny := Set{} ; for line : open(0).readlines() do ( var w : OclAny := null; var p : OclAny := null; Sequence{w,p} := line.split() ; (expr (atom (name D)) (trailer . (name setdefault) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name w))))))) , (argument (test (logical_test (comparison (expr (atom [ ]))))))) ))) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p)))))))) ))))))))) ))))) ; for _tuple : D->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sort() do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); execute (k)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys d={} for e in sys.stdin : k,v=e.split() if k in d : d[k]+=[int(v)] else : d[k]=[int(v)] for k in sorted(d): print(k) print(*sorted(d[k])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var d : OclAny := Set{} ; for e : OclFile["System.in"] do ( var k : OclAny := null; var v : OclAny := null; Sequence{k,v} := e.split() ; if (d)->includes(k) then ( d[k+1] := d[k+1] + Sequence{ ("" + ((v)))->toInteger() } ) else ( d[k+1] := Sequence{ ("" + ((v)))->toInteger() } )) ; for k : d->sort() do ( execute (k)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])))))))) )))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline import heapq while True : s,d=map(int,input().split()) if s==0 : break visited=[0]*100 Q=[] to=[[]for i in range(100)] for i in range(s): visited[i]=1 c=list(map(int,input().split())) for j in range(d): if c[j]>0 : heapq.heappush(Q,(c[j],i,s+j)) for i in range(d-1): c=list(map(int,input().split())) for j in range(i+1,d): if c[j-i-1]>0 : to[s+i].append((s+j,c[j-i-1])) to[s+j].append((s+i,c[j-i-1])) ans=k=0 while kcollect( _x | (OclType["int"])->apply(_x) ) ; if s = 0 then ( break ) else skip ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100) ; var Q : Sequence := Sequence{} ; var to : Sequence := Integer.subrange(0, 100-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, s-1) do ( visited[i+1] := 1 ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, d-1) do ( if c[j+1] > 0 then ( heapq.heappush(Q, Sequence{c[j+1], i, s + j}) ) else skip)) ; for i : Integer.subrange(0, d - 1-1) do ( c := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(i + 1, d-1) do ( if c[j - i - 1+1] > 0 then ( (expr (atom (name to)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name s))) + (expr (atom (name i))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name s))) + (expr (atom (name j))))))) , (test (logical_test (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name j))) - (expr (atom (name i)))) - (expr (atom (number (integer 1)))))))))) ]))))))) )))))))) )))) ; (expr (atom (name to)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name s))) + (expr (atom (name j))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name s))) + (expr (atom (name i))))))) , (test (logical_test (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name j))) - (expr (atom (name i)))) - (expr (atom (number (integer 1)))))))))) ]))))))) )))))))) )))) ) else skip)) ; var ans : OclAny := 0; var k : int := 0 ; while (k->compareTo(d)) < 0 do ( while true do ( var a : OclAny := null; var b : OclAny := null; Sequence{c,a,b} := heapq.heappop(Q) ; if visited[a+1] = 0 or visited[b+1] = 0 then ( break ) else skip) ; Sequence{ans,k} := Sequence{ans->union(c),k + 1} ; if visited[a+1] then ( var a : OclAny := b ) else skip ; visited[a+1] := 1; ; for _tuple : to[a+1] do (var _indx : int := 1; var e : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if visited[e+1] = 0 then ( heapq.heappush(Q, Sequence{c, a, e}) ) else skip)) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while(1): s,d=[int(x)for x in input().split()] A=[999 for x in range(d)] if s==0 : break for j in range(s): l=[int(x)for x in input().split()] for i in range(d): if l[i]!=0 : A[i]=min(A[i],l[i]) B=[[999 for x in range(d)]for y in range(d)] for j in range(d-1): l=[int(x)for x in input().split()] for i in range(d-1-j): if l[i]!=0 : B[j][i+j+1]=l[i] B[i+j+1][j]=l[i] notevaled=[1 for x in range(d)] ans=0 for i in range(d): mini=A.index(min(A)) ans+=A[mini] notevaled[mini]=0 A[mini]=999 for x in range(d): if notevaled[x]: A[x]=min(A[x],B[mini][x]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while (1) do ( var s : OclAny := null; var d : OclAny := null; Sequence{s,d} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var A : Sequence := Integer.subrange(0, d-1)->select(x | true)->collect(x | (999)) ; if s = 0 then ( break ) else skip ; for j : Integer.subrange(0, s-1) do ( var l : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for i : Integer.subrange(0, d-1) do ( if l[i+1] /= 0 then ( A[i+1] := Set{A[i+1], l[i+1]}->min() ) else skip)) ; var B : Sequence := Integer.subrange(0, d-1)->select(y | true)->collect(y | (Integer.subrange(0, d-1)->select(x | true)->collect(x | (999)))) ; for j : Integer.subrange(0, d - 1-1) do ( l := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for i : Integer.subrange(0, d - 1 - j-1) do ( if l[i+1] /= 0 then ( B[j+1][i + j + 1+1] := l[i+1] ; B[i + j + 1+1][j+1] := l[i+1] ) else skip)) ; var notevaled : Sequence := Integer.subrange(0, d-1)->select(x | true)->collect(x | (1)) ; var ans : int := 0 ; for i : Integer.subrange(0, d-1) do ( var mini : int := A->indexOf((A)->min()) - 1 ; ans := ans + A[mini+1] ; notevaled[mini+1] := 0 ; A[mini+1] := 999 ; for x : Integer.subrange(0, d-1) do ( if notevaled[x+1] then ( A[x+1] := Set{A[x+1], B[mini+1][x+1]}->min() ) else skip)) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countNumbers(l,r): return((r//6)-(l-1)//6); if __name__=="__main__" : l=1000 ; r=6000 ; print(countNumbers(l,r)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( l := 1000; r := 6000; ; execute (countNumbers(l, r))->display(); ) else skip; operation countNumbers(l : OclAny, r : OclAny) pre: true post: true activity: return ((r div 6) - (l - 1) div 6);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count4Divisibiles(arr,n): freq=[0,0,0,0] for i in range(n): freq[arr[i]% 4]+=1 ans=freq[0]*(freq[0]-1)/2 ans+=freq[2]*(freq[2]-1)/2 ans+=freq[1]*freq[3] return int(ans) arr=[2,2,1,7,5] n=len(arr) print(count4Divisibiles(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{2}->union(Sequence{1}->union(Sequence{7}->union(Sequence{ 5 })))) ; n := (arr)->size() ; execute (count4Divisibiles(arr, n))->display(); operation count4Divisibiles(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var freq : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))) ; for i : Integer.subrange(0, n-1) do ( freq[arr[i+1] mod 4+1] := freq[arr[i+1] mod 4+1] + 1) ; var ans : double := freq->first() * (freq->first() - 1) / 2 ; ans := ans + freq[2+1] * (freq[2+1] - 1) / 2 ; ans := ans + freq[1+1] * freq[3+1] ; return ("" + ((ans)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find_greatest_divisor(l,r): if(l==r): return l ; return 1 ; l=2 ; r=12 ; print(find_greatest_divisor(l,r)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; l := 2; ; r := 12; ; execute (find_greatest_divisor(l, r))->display();; operation find_greatest_divisor(l : OclAny, r : OclAny) pre: true post: true activity: if (l = r) then ( return l; ) else skip ; return 1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSumPairs(a,n): mpp={i : 0 for i in range(21)} for i in range(n-1): for j in range(i+1,n,1): mpp[a[i]+a[j]]+=1 occur=0 for key,value in mpp.items(): if(value>occur): occur=value for key,value in mpp.items(): if(value==occur): print(key) if __name__=='__main__' : a=[1,8,3,11,4,9,2,7] n=len(a) findSumPairs(a,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := Sequence{1}->union(Sequence{8}->union(Sequence{3}->union(Sequence{11}->union(Sequence{4}->union(Sequence{9}->union(Sequence{2}->union(Sequence{ 7 }))))))) ; n := (a)->size() ; findSumPairs(a, n) ) else skip; operation findSumPairs(a : OclAny, n : OclAny) pre: true post: true activity: var mpp : Map := Integer.subrange(0, 21-1)->select(i | true)->collect(i | Map{i |-> 0})->unionAll() ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(i + 1, n-1)->select( $x | ($x - i + 1) mod 1 = 0 ) do ( mpp[a[i+1] + a[j+1]+1] := mpp[a[i+1] + a[j+1]+1] + 1)) ; var occur : int := 0 ; for _tuple : mpp->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); if ((value->compareTo(occur)) > 0) then ( occur := value ) else skip) ; for _tuple : mpp->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); if (value = occur) then ( execute (key)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n,k=list(map(int,input().split(" "))) a=0 if n % 2==0 and k % 2==1 : a=2 ; else : a=1 ; l2=[] l2+=[a]*(k-1) c=n-sum(l2) if c>0 and c % 2==a % 2 : print("YES") print(*l2,c) else : print("NO") for _ in range(int(input())): solve(); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve();); operation solve() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var a : int := 0 ; if n mod 2 = 0 & k mod 2 = 1 then ( a := 2; ) else ( a := 1; ) ; var l2 : Sequence := Sequence{} ; l2 := l2 + MatrixLib.elementwiseMult(Sequence{ a }, (k - 1)) ; var c : double := n - (l2)->sum() ; if c > 0 & c mod 2 = a mod 2 then ( execute ("YES")->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name l2))))))))->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def twoParts(string): flag=0 ; a="" ; for i in range(len(string)): if(string[i]=='4'): string[i]='3' ; a+='1' ; flag=1 ; elif(flag): a+='0' ; string="".join(string); print(string,a); if __name__=="__main__" : string="9441" ; twoParts(list(string)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( string := "9441"; ; twoParts((string)->characters()); ) else skip; operation twoParts(string : OclAny) pre: true post: true activity: var flag : int := 0; ; var a : String := ""; ; for i : Integer.subrange(0, (string)->size()-1) do ( if (string[i+1] = '4') then ( string[i+1] := '3'; ; a := a + '1'; ; flag := 1; ) else (if (flag) then ( a := a + '0'; ) else skip)) ; string := StringLib.sumStringsWithSeparator((string), ""); ; execute (string)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(sum(list(map(int,input().split())))-n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->sum() - n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) m=a[0] def gcd(a,b): if atoInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : OclAny := a->first() ; skip ; skip ; for i : Integer.subrange(0, n-1) do ( m := lcm(m, a[i+1])) ; m := m - 1 ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( ans := ans + m mod a[i+1]) ; execute (ans)->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a->compareTo(b)) < 0 then ( Sequence{a,b} := Sequence{b,a} ) else skip ; if b = 0 then ( return a ) else skip ; var c : int := a mod b ; return gcd(b, c); operation lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (MatrixLib.elementwiseMult(a, b)) div gcd(a, b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def myAnswer(N : int,A : list)->int : return sum(A)-N def modelAnswer(): tmp=1 def main(): N=int(input()) A=list(map(int,input().split())) print(myAnswer(N,A[:])) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation myAnswer(N : int, A : Sequence(OclAny)) : int pre: true post: true activity: return (A)->sum() - N; operation modelAnswer() pre: true post: true activity: var tmp : int := 1; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (myAnswer(N, A))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools import collections def getint(): return int(input()) def getints(): return list(map(int,input().split())) n=getint() a=getints() res=sum(a)-len(a) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var n : OclAny := getint() ; var a : OclAny := getints() ; var res : double := (a)->sum() - (a)->size() ; execute (res)->display(); operation getint() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation getints() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import gcd N=int(input()) A=list(map(int,input().split())) L=A[0] for a in A : L=L*a//gcd(L,a) res=0 for a in A : res+=(L-1)% a print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var L : OclAny := A->first() ; for a : A do ( L := L * a div gcd(L, a)) ; var res : int := 0 ; for a : A do ( res := res + (L - 1) mod a) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countMoves(n): ct=0 for i in range(1,n+1): ct+=i*(n-i) ct+=n return ct if __name__=="__main__" : n=3 print(countMoves(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 3 ; execute (countMoves(n))->display() ) else skip; operation countMoves(n : OclAny) : OclAny pre: true post: true activity: var ct : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( ct := ct + i * (n - i)) ; ct := ct + n ; return ct; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gouldSequence(n): for row_num in range(1,n): count=1 c=1 for i in range(1,row_num): c=c*(row_num-i)/i if(c % 2==1): count+=1 print(count,end=" ") n=16 ; gouldSequence(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 16; ; gouldSequence(n); operation gouldSequence(n : OclAny) pre: true post: true activity: for row_num : Integer.subrange(1, n-1) do ( var count : int := 1 ; var c : int := 1 ; for i : Integer.subrange(1, row_num-1) do ( c := c * (row_num - i) / i ; if (c mod 2 = 1) then ( count := count + 1 ) else skip) ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) info=[list(map(int,input().split()))for i in range(n)] for i in range(n): x,y=info[i] info[i]=(math.atan2(y,x),x,y) info=sorted(info) info=info+info ans=0 for i in range(n): x,y=0,0 for j in range(i,i+n): _,xp,yp=info[j] x+=xp y+=yp ans=max(ans,(x**2+y**2)**0.5) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var info : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := info[i+1] ; info[i+1] := Sequence{, x, y}) ; info := info->sort() ; info := info->union(info) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{0,0} ; for j : Integer.subrange(i, i + n-1) do ( var _anon : OclAny := null; var xp : OclAny := null; var yp : OclAny := null; Sequence{_anon,xp,yp} := info[j+1] ; x := x + xp ; y := y + yp ; ans := Set{ans, (((x)->pow(2) + (y)->pow(2)))->pow(0.5)}->max())) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) direction=input() distance=[int(x)for x in input().split()] tuples=list(zip(direction,distance)) idx,minDist=0,2**31-1 while idx+1toInteger() ; var direction : String := (OclFile["System.in"]).readLine() ; var distance : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var tuples : Sequence := (Integer.subrange(1, direction->size())->collect( _indx | Sequence{direction->at(_indx), distance->at(_indx)} )) ; var idx : OclAny := null; var minDist : OclAny := null; Sequence{idx,minDist} := Sequence{0,(2)->pow(31) - 1} ; while (idx + 1->compareTo((tuples)->size())) < 0 do ( if tuples[idx+1]->first() = "R" & tuples[idx + 1+1]->first() = "L" then ( var minDist : OclAny := Set{minDist, (tuples[idx + 1+1][1+1] - tuples[idx+1][1+1]) div 2}->min() ) else skip ; idx := idx + 1) ; if minDist = (2)->pow(31) - 1 then ( execute (-1)->display() ) else ( execute (minDist)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) def solve(): n,k=map(int,input().split()) odd=["1"]*(k-1) even=["2"]*(k-1) if n-(k-1)>0 and(n-(k-1))% 2==1 : print("YES") print(' '.join(odd),n-(k-1)) elif n-2*(k-1)>0 and(n-2*(k-1))% 2==0 : print("YES") print(' '.join(even),n-2*(k-1)) else : print("NO") def yes(t): for _ in range(t): solve() yes(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; skip ; yes(t); operation solve() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var odd : Sequence := MatrixLib.elementwiseMult(Sequence{ "1" }, (k - 1)) ; var even : Sequence := MatrixLib.elementwiseMult(Sequence{ "2" }, (k - 1)) ; if n - (k - 1) > 0 & (n - (k - 1)) mod 2 = 1 then ( execute ("YES")->display() ; execute (StringLib.sumStringsWithSeparator((odd), ' '))->display() ) else (if n - 2 * (k - 1) > 0 & (n - 2 * (k - 1)) mod 2 = 0 then ( execute ("YES")->display() ; execute (StringLib.sumStringsWithSeparator((even), ' '))->display() ) else ( execute ("NO")->display() ) ) ; operation yes(t : OclAny) pre: true post: true activity: for _anon : Integer.subrange(0, t-1) do ( solve()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=str(input())+'m' a=[int(i)for i in input().split()] a.append(1000000000000000) if "RL" not in s : print(-1) exit() res=1000000000000000 for i in range(n): if(s[i]=="R" and s[i+1]=="L")and((a[i+1]-a[i])//2toInteger() ; var s : String := ("" + (((OclFile["System.in"]).readLine()))) + 'm' ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute ((1000000000000000) : a) ; if (s)->characters()->excludes("RL") then ( execute (-1)->display() ; exit() ) else skip ; var res : int := 1000000000000000 ; for i : Integer.subrange(0, n-1) do ( if (s[i+1] = "R" & s[i + 1+1] = "L") & (((a[i + 1+1] - a[i+1]) div 2->compareTo(res)) < 0) then ( res := (a[i + 1+1] - a[i+1]) div 2 ) else skip) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) Dir=list(map(str,input())) pos=list(map(int,input().split())) coll=[] for i in range(num-1): if Dir[i]=="R" and Dir[i+1]=="L" : coll.append((pos[i+1]-pos[i])//2) if len(coll)==0 : print("-1") else : print(min(coll)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var Dir : Sequence := (((OclFile["System.in"]).readLine())->collect( _x | (OclType["String"])->apply(_x) )) ; var pos : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var coll : Sequence := Sequence{} ; for i : Integer.subrange(0, num - 1-1) do ( if Dir[i+1] = "R" & Dir[i + 1+1] = "L" then ( execute (((pos[i + 1+1] - pos[i+1]) div 2) : coll) ) else skip) ; if (coll)->size() = 0 then ( execute ("-1")->display() ) else ( execute ((coll)->min())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def print(*args,end='\n',sep=' ')->None : sys.stdout.write(sep.join(map(str,args))+end) def Solve(): n=int(input()) dir=list(input().strip()) met=list(map(int,input().split())) ans=set() e=True for i in range(n-1): x1,y1=dir[i],met[i] x2,y2=dir[i+1],met[i+1] if x1=="R" and x2=="L" and y1 (test (logical_test (comparison (expr (atom None))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name sep)) (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name args)))))))) ))))))))) )))) + (expr (atom (name end))))))))) )))))))))))))) operation Solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var dir : Sequence := (input()->trim()) ; var met : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : Set := Set{}->union(()) ; var e : boolean := true ; for i : Integer.subrange(0, n - 1-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := Sequence{dir[i+1],met[i+1]} ; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x2,y2} := Sequence{dir[i + 1+1],met[i + 1+1]} ; if x1 = "R" & x2 = "L" & (y1->compareTo(y2)) < 0 then ( execute (((y2 - y1) / 2) : ans) ; e := false ) else skip) ; if e then ( execute (-1)->display() ; return ) else skip ; execute (("" + (((ans)->min())))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=list(input()) c=list(map(int,input().split())) x=0 ; for i in range(n-1): if(s[i]=='R' and s[i+1]=='L'): v=int((c[i+1]-c[i])/2) if(x==0): x=v elif(x>v): x=v if(x==0): print(-1) else : print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : int := 0; ; for i : Integer.subrange(0, n - 1-1) do ( if (s[i+1] = 'R' & s[i + 1+1] = 'L') then ( var v : int := ("" + (((c[i + 1+1] - c[i+1]) / 2)))->toInteger() ; if (x = 0) then ( x := v ) else (if ((x->compareTo(v)) > 0) then ( x := v ) else skip) ) else skip) ; if (x = 0) then ( execute (-1)->display() ) else ( execute (x)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) lists=[] for i in range(M): lists.append(list(map(int,input().split()))+[i]) lists.sort(key=lambda x : x[1]) lists.sort(key=lambda x : x[0]) bef=0 state=0 retstr='' triple=[] for i in lists : if(i[0]!=bef): bef=i[0] state=1 triple.append([i[0],i[1],i[2],str(i[0]).rjust(6,'0')+str(state).rjust(6,'0')]) else : state+=1 triple.append([i[0],i[1],i[2],str(i[0]).rjust(6,'0')+str(state).rjust(6,'0')]) triple.sort(key=lambda x : x[2]) for i in triple : print(i[3]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lists : Sequence := Sequence{} ; for i : Integer.subrange(0, M-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->union(Sequence{ i })) : lists)) ; lists := lists->sort() ; lists := lists->sort() ; var bef : int := 0 ; var state : int := 0 ; var retstr : String := '' ; var triple : Sequence := Sequence{} ; for i : lists do ( if (i->first() /= bef) then ( bef := i->first() ; state := 1 ; execute ((Sequence{i->first()}->union(Sequence{i[1+1]}->union(Sequence{i[2+1]}->union(Sequence{ OclType["String"](i->first()).rjust(6, '0') + OclType["String"](state).rjust(6, '0') })))) : triple) ) else ( state := state + 1 ; execute ((Sequence{i->first()}->union(Sequence{i[1+1]}->union(Sequence{i[2+1]}->union(Sequence{ OclType["String"](i->first()).rjust(6, '0') + OclType["String"](state).rjust(6, '0') })))) : triple) )) ; triple := triple->sort() ; for i : triple do ( execute (i[3+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np N,M=map(int,input().split()) p_dict={} p=[0 for i in range(M)] y=[0 for i in range(M)] i_in_p=[0 for i in range(M)] for i in range(M): p[i],y[i]=map(int,input().split()) if p[i]not in p_dict : i_in_p[i]=0 p_dict[p[i]]=[y[i]] continue i_in_p[i]=len(p_dict[p[i]]) p_dict[p[i]].append(y[i]) for key in p_dict.keys(): p_dict[key]=np.array(p_dict[key]).argsort().argsort()+1 for i in range(M): print('{:06d}{:06d}'.format(p[i],p_dict[p[i]][i_in_p[i]])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p_dict : OclAny := Set{} ; var p : Sequence := Integer.subrange(0, M-1)->select(i | true)->collect(i | (0)) ; var y : Sequence := Integer.subrange(0, M-1)->select(i | true)->collect(i | (0)) ; var i_in_p : Sequence := Integer.subrange(0, M-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, M-1) do ( var p[i+1] : OclAny := null; var y[i+1] : OclAny := null; Sequence{p[i+1],y[i+1]} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (p_dict)->excludes(p[i+1]) then ( i_in_p[i+1] := 0 ; p_dict[p[i+1]+1] := Sequence{ y[i+1] } ; continue ) else skip ; i_in_p[i+1] := (p_dict[p[i+1]+1])->size() ; (expr (atom (name p_dict)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))) ; for key : p_dict.keys() do ( p_dict[key+1] := np.array(p_dict[key+1]).argsort().argsort() + 1) ; for i : Integer.subrange(0, M-1) do ( execute (StringLib.interpolateStrings('{:06d}{:06d}', Sequence{p[i+1], p_dict[p[i+1]+1][i_in_p[i+1]+1]}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): import bisect n,m,*py=map(int,open(0).read().split()) d=[[]for _ in range(n+1)] for i,j in zip(*[iter(py)]*2): d[i].append(j) for i in d : i.sort() ans='' for i,j in zip(*[iter(py)]*2): k=bisect.bisect_right(d[i],j) id=str(i).zfill(6)+str(k).zfill(6) ans+=id+'\n' print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; var py : OclAny := null; Sequence{n,m,py} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _tuple : Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name py)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name py)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name py)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))`third->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) ))))) ; for i : d do ( i := i->sort()) ; var ans : String := '' ; for _tuple : Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name py)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name py)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name py)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))`third->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); var k : OclAny := bisect.bisect_right(d[i+1], j) ; var id : OclAny := OclType["String"](i).zfill(6) + OclType["String"](k).zfill(6) ; ans := ans + id + ' ') ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from operator import itemgetter n,m=map(int,input().split()) yp=[] for i in range(m): p_,y_=map(int,input().split()) yp.append([y_,p_,i+1]) py=sorted(yp) ken=[0]*n res=[] for i in range(m): ken[py[i][1]-1]+=1 p,q,r=py[i][1],ken[py[i][1]-1],py[i][2] res.append([p,q,r]) res.sort(key=itemgetter(2)) for i in range(m): ans1=[0]*(6-len(str(res[i][0]))) ans1.append(res[i][0]) ans2=[0]*(6-len(str(res[i][1]))) ans2.append(res[i][1]) print(*ans1,*ans2,sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var yp : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var p_ : OclAny := null; var y_ : OclAny := null; Sequence{p_,y_} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{y_}->union(Sequence{p_}->union(Sequence{ i + 1 }))) : yp)) ; var py : Sequence := yp->sort() ; var ken : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var res : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( ken[py[i+1][1+1] - 1+1] := ken[py[i+1][1+1] - 1+1] + 1 ; var p : OclAny := null; var q : OclAny := null; var r : OclAny := null; Sequence{p,q,r} := Sequence{py[i+1][1+1],ken[py[i+1][1+1] - 1+1],py[i+1][2+1]} ; execute ((Sequence{p}->union(Sequence{q}->union(Sequence{ r }))) : res)) ; res := res->sort() ; for i : Integer.subrange(0, m-1) do ( var ans1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (6 - (("" + ((res[i+1]->first()))))->size())) ; execute ((res[i+1]->first()) : ans1) ; var ans2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (6 - (("" + ((res[i+1][1+1]))))->size())) ; execute ((res[i+1][1+1]) : ans2) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans1))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(item)for item in input().split()] ids,ps,ys=[],[],[] for i in range(m): p,y=[int(item)for item in input().split()] ids.append(i) ps.append(p) ys.append(y) city_num=[0]*(n+1) ids,ps,ys=zip(*sorted(zip(ids,ps,ys),key=lambda x : x[2])) names=[] for p in ps : city_num[p]+=1 names.append("{0:06d}".format(p)+"{0:06d}".format(city_num[p])) names,_=zip(*sorted(zip(names,ids),key=lambda x : x[1])) for name in names : print(name) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; var ids : OclAny := null; var ps : OclAny := null; var ys : OclAny := null; Sequence{ids,ps,ys} := Sequence{Sequence{},Sequence{},Sequence{}} ; for i : Integer.subrange(0, m-1) do ( var p : OclAny := null; var y : OclAny := null; Sequence{p,y} := input().split()->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; execute ((i) : ids) ; execute ((p) : ps) ; execute ((y) : ys)) ; var city_num : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var ids : OclAny := null; var ps : OclAny := null; var ys : OclAny := null; Sequence{ids,ps,ys} := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ids))))))) , (argument (test (logical_test (comparison (expr (atom (name ps))))))) , (argument (test (logical_test (comparison (expr (atom (name ys)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ]))))))))) ))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ids))))))) , (argument (test (logical_test (comparison (expr (atom (name ps))))))) , (argument (test (logical_test (comparison (expr (atom (name ys)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ]))))))))) ))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ids))))))) , (argument (test (logical_test (comparison (expr (atom (name ps))))))) , (argument (test (logical_test (comparison (expr (atom (name ys)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ]))))))))) ))))))))`third->at(_indx)} ) ; var names : Sequence := Sequence{} ; for p : ps do ( city_num[p+1] := city_num[p+1] + 1 ; execute ((StringLib.interpolateStrings("{0:06d}", Sequence{p}) + StringLib.interpolateStrings("{0:06d}", Sequence{city_num[p+1]})) : names)) ; var _anon : OclAny := null; Sequence{names,_anon} := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name names))))))) , (argument (test (logical_test (comparison (expr (atom (name ids)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))))) ))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name names))))))) , (argument (test (logical_test (comparison (expr (atom (name ids)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))))) ))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name names))))))) , (argument (test (logical_test (comparison (expr (atom (name ids)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))))) ))))))))`third->at(_indx)} ) ; for name : names do ( execute (name)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- 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(100000) input=sys.stdin.readline 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(N,XY): SXY=[(math.atan2(y,x),x,y)for x,y in XY] SXY.sort() ans=0 for i in range(N): cx=0 cy=0 for j in range(N): _,x,y=SXY[i-j] cx+=x cy+=y ans=max(ans,cx**2+cy**2) return math.sqrt(ans) def main(): N=read_int() XY=[read_int_n()for _ in range(N)] print("%.100f" % slv(N,XY)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(100000) ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; (compound_stmt (decorator @ (dotted_name (name mt))) (funcdef def (name slv) ( (typedargslist (def_parameters (def_parameter (named_parameter (name N))) , (def_parameter (named_parameter (name XY))))) ) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name SXY)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name math)) (trailer . (name atan2) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y))))))) , (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) , (test (logical_test (comparison (expr (atom (name x)))))) , (test (logical_test (comparison (expr (atom (name y))))))) )))))) (comp_for for (exprlist (expr (atom (name x))) , (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name XY))))))) ]))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name SXY)) (trailer . (name sort) (arguments ( )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cx)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cy)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name _)))))) , (test (logical_test (comparison (expr (atom (name x)))))) , (test (logical_test (comparison (expr (atom (name y))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name SXY)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (name j))))))))) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cx)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name x))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cy)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name y))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans))))))) , (argument (test (logical_test (comparison (expr (expr (expr (atom (name cx))) ** (expr (atom (number (integer 2))))) + (expr (expr (atom (name cy))) ** (expr (atom (number (integer 2))))))))))) ))))))))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name math)) (trailer . (name sqrt) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) )))))))))))))) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation read_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation read_int_n() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation read_float() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation read_float_n() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["double"])->apply(_x) )); operation read_str() : OclAny pre: true post: true activity: return input()->trim(); operation read_str_n() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["String"])->apply(_x) )); operation error_print(args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) execute ((argument * (test (logical_test (comparison (expr (atom (name args))))))))->display(); operation mt(f : OclAny) : OclAny pre: true post: true activity: skip ; skip ; return wrap; operation main() pre: true post: true activity: var N : OclAny := read_int() ; var XY : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (read_int_n())) ; execute (StringLib.format("%.100f",slv(N, XY)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maximumXor(arr : list,n : int)->int : sForward,sBackward=[],[] ans=-1 for i in range(n): while len(sForward)>0 and arr[i]0 and arr[n-i-1]union(Sequence{1}->union(Sequence{ 2 })) ; var n : int := (arr)->size() ; execute (maximumXor(arr, n))->display() ) else skip; operation maximumXor(arr : Sequence(OclAny), n : int) : int pre: true post: true activity: var sForward : OclAny := null; var sBackward : OclAny := null; Sequence{sForward,sBackward} := Sequence{Sequence{},Sequence{}} ; var ans : int := -1 ; for i : Integer.subrange(0, n-1) do ( while (sForward)->size() > 0 & (arr[i+1]->compareTo(arr[sForward->last()+1])) < 0 do ( ans := Set{ans, MathLib.bitwiseXor(arr[i+1], arr[sForward->last()+1])}->max() ; sForward := sForward->front()) ; execute ((i) : sForward) ; while (sBackward)->size() > 0 & (arr[n - i - 1+1]->compareTo(arr[sBackward->last()+1])) < 0 do ( ans := Set{ans, MathLib.bitwiseXor(arr[n - i - 1+1], arr[sBackward->last()+1])}->max() ; sBackward := sBackward->front()) ; execute ((n - i - 1) : sBackward)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans=[2,3,4,5,12,30,31,35,43,46,52,64,86] a=int(input()) print('YES' if a in ans else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ans : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{12}->union(Sequence{30}->union(Sequence{31}->union(Sequence{35}->union(Sequence{43}->union(Sequence{46}->union(Sequence{52}->union(Sequence{64}->union(Sequence{ 86 })))))))))))) ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (if (ans)->includes(a) then 'YES' else 'NO' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline t=1 for _ in range(t): n=int(input()) l=[1,7,9,10,11,13,14,15,16,17,18,19] flag=1 d=n//10 if d==2 or d==7 or d==9 : flag=0 if n in l : flag=0 n %=10 if n in l : flag=0 if flag : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{1}->union(Sequence{7}->union(Sequence{9}->union(Sequence{10}->union(Sequence{11}->union(Sequence{13}->union(Sequence{14}->union(Sequence{15}->union(Sequence{16}->union(Sequence{17}->union(Sequence{18}->union(Sequence{ 19 }))))))))))) ; var flag : int := 1 ; var d : int := n div 10 ; if d = 2 or d = 7 or d = 9 then ( flag := 0 ) else skip ; if (l)->includes(n) then ( flag := 0 ) else skip ; n := n mod 10 ; if (l)->includes(n) then ( flag := 0 ) else skip ; if flag then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n in(5,46,2,3,4,12,30,35,43,52,64,86): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (Sequence{5, 46, 2, 3, 4, 12, 30, 35, 43, 52, 64, 86})->includes(n) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,bisect,heapq,random,sys,itertools input=sys.stdin.readline ints=lambda : list(map(int,input().split())) def yn(condition): if condition : print("YES") else : print("NO") p=10**9+7 n,=ints() a=[1,7,9,10,11]+list(range(13,30))+[31,37,39,41,47,49,51,57,59,61,67,69,81,87,89]+list(range(70,80))+list(range(90,100)) if n in a : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var ints : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; skip ; var p : double := (10)->pow(9) + 7 ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,)} := ints->apply() ; var a : Sequence := Sequence{1}->union(Sequence{7}->union(Sequence{9}->union(Sequence{10}->union(Sequence{ 11 }))))->union((Integer.subrange(13, 30-1)))->union(Sequence{31}->union(Sequence{37}->union(Sequence{39}->union(Sequence{41}->union(Sequence{47}->union(Sequence{49}->union(Sequence{51}->union(Sequence{57}->union(Sequence{59}->union(Sequence{61}->union(Sequence{67}->union(Sequence{69}->union(Sequence{81}->union(Sequence{87}->union(Sequence{ 89 })))))))))))))))->union((Integer.subrange(70, 80-1)))->union((Integer.subrange(90, 100-1))) ; if (a)->includes(n) then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); operation yn(condition : OclAny) pre: true post: true activity: if condition then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() p={1,7,9,10,11,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,31,37,39,41,47,49,51,57,59,61,67,69,70,71,72,73,74,75,76,77,78,79,81,87,89,90,91,92,93,94,95,96,97,98,99} if int(n)in p : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var p : Set := Set{1}->union(Set{7}->union(Set{9}->union(Set{10}->union(Set{11}->union(Set{13}->union(Set{14}->union(Set{15}->union(Set{16}->union(Set{17}->union(Set{18}->union(Set{19}->union(Set{20}->union(Set{21}->union(Set{22}->union(Set{23}->union(Set{24}->union(Set{25}->union(Set{26}->union(Set{27}->union(Set{28}->union(Set{29}->union(Set{31}->union(Set{37}->union(Set{39}->union(Set{41}->union(Set{47}->union(Set{49}->union(Set{51}->union(Set{57}->union(Set{59}->union(Set{61}->union(Set{67}->union(Set{69}->union(Set{70}->union(Set{71}->union(Set{72}->union(Set{73}->union(Set{74}->union(Set{75}->union(Set{76}->union(Set{77}->union(Set{78}->union(Set{79}->union(Set{81}->union(Set{87}->union(Set{89}->union(Set{90}->union(Set{91}->union(Set{92}->union(Set{93}->union(Set{94}->union(Set{95}->union(Set{96}->union(Set{97}->union(Set{98}->union(Set{ 99 })))))))))))))))))))))))))))))))))))))))))))))))))))))))) ; if (p)->includes(("" + ((n)))->toInteger()) then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): ans=sum(i for i in range(1,10000)if has_pandigital_product(i)) return str(ans) def has_pandigital_product(n): for i in range(1,eulerlib.sqrt(n)+1): if n % i==0 : temp=str(n)+str(i)+str(n//i) if "".join(sorted(temp))=="123456789" : return True return False if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 10000))))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (atom (name has_pandigital_product)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))))->sum() ; return ("" + ((ans))); operation has_pandigital_product(n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(1, eulerlib.sqrt(n) + 1-1) do ( if n mod i = 0 then ( var temp : String := ("" + ((n))) + ("" + ((i))) + ("" + ((n div i))) ; if StringLib.sumStringsWithSeparator((temp->sort()), "") = "123456789" then ( return true ) else skip ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,data): self.data=data self.left=None self.right=None def specific_level_order_traversal(root): q=[] s=[] q.append(root) sz=0 while(len(q)>0): v=[] sz=len(q) i=0 while(i0): v=s[-1] s.pop() i=0 j=len(v)-1 while(iexists( _x | result = _x ); attribute data : OclAny := data; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.left := null ; self.right := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; root := (Node.newNode()).initialise(1) ; root.left := (Node.newNode()).initialise(2) ; root.right := (Node.newNode()).initialise(3) ; execute ("Specific Level Order traversal of binary tree is")->display() ; specific_level_order_traversal(root); operation specific_level_order_traversal(root : OclAny) pre: true post: true activity: var q : Sequence := Sequence{} ; var s : Sequence := Sequence{} ; execute ((root) : q) ; var sz : int := 0 ; while ((q)->size() > 0) do ( var v : Sequence := Sequence{} ; sz := (q)->size() ; var i : int := 0 ; while ((i->compareTo(sz)) < 0) do ( var temp : OclAny := q->first() ; q := q->excludingAt(0+1) ; execute ((temp.data) : v) ; if (temp.left /= null) then ( execute ((temp.left) : q) ) else skip ; if (temp.right /= null) then ( execute ((temp.right) : q) ) else skip ; i := i + 1) ; execute ((v) : s)) ; while ((s)->size() > 0) do ( v := s->last() ; s := s->front() ; i := 0 ; var j : double := (v)->size() - 1 ; while ((i->compareTo(j)) < 0) do ( execute (v[i+1])->display() ; j := j - 1 ; i := i + 1)) ; execute (root.data)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=10**9+7 n=int(input()) if n==1 : print(1) else : dp=[0 for _ in range(n+1)] dp[0],dp[1],dp[2]=1,1,1 cum=[0 for _ in range(n+1)] cum[0],cum[1],cum[2]=1,2,3 for i in range(3,n+1): dp[i]=(dp[i-1]+cum[i-3])% MOD cum[i]=(cum[i-1]+dp[i])% MOD ans=cum[n-2]*(n-1)*(n-1)+dp[n-1]*(n-1)+cum[n-2]*(n-1)+1 print(ans % MOD) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : double := (10)->pow(9) + 7 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (1)->display() ) else ( var dp : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (0)) ; var dp->first() : OclAny := null; var dp[1+1] : OclAny := null; var dp[2+1] : OclAny := null; Sequence{dp->first(),dp[1+1],dp[2+1]} := Sequence{1,1,1} ; var cum : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (0)) ; var cum->first() : OclAny := null; var cum[1+1] : OclAny := null; var cum[2+1] : OclAny := null; Sequence{cum->first(),cum[1+1],cum[2+1]} := Sequence{1,2,3} ; for i : Integer.subrange(3, n + 1-1) do ( dp[i+1] := (dp[i - 1+1] + cum[i - 3+1]) mod MOD ; cum[i+1] := (cum[i - 1+1] + dp[i+1]) mod MOD) ; var ans : double := cum[n - 2+1] * (n - 1) * (n - 1) + dp[n - 1+1] * (n - 1) + cum[n - 2+1] * (n - 1) + 1 ; execute (ans mod MOD)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.read readline=sys.stdin.readline def get(i): if i<=0 : return 1 else : return a[i] n,=map(int,readline().split()) MOD=10**9+7 a=[1,n,n*n] for i in range(3,n+1): res=-get(i-n-2)+get(i-3)-get(i-2)+2*get(i-1) a.append(res % MOD) print(a[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := (OclFile["System.in"]).read ; var readline : OclAny := (OclFile["System.in"]).readline ; skip ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,)} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var MOD : double := (10)->pow(9) + 7 ; var a : Sequence := Sequence{1}->union(Sequence{n}->union(Sequence{ n * n })) ; for i : Integer.subrange(3, n + 1-1) do ( var res : double := -get(i - n - 2) + get(i - 3) - get(i - 2) + 2 * get(i - 1) ; execute ((res mod MOD) : a)) ; execute (a->last())->display(); operation get(i : OclAny) : OclAny pre: true post: true activity: if i <= 0 then ( return 1 ) else ( return a[i+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import queue from collections import deque,defaultdict import heapq as hpq from sys import stdin,setrecursionlimit ipt=stdin.readline setrecursionlimit(10**7) def main(): n=int(ipt()) mod=10**9+7 a=[n,n*n % mod] sa=[0,0] for i in range(2,n): a.append((a[-1]+sa[-1]+(n-i+1)*n % mod)% mod) sa.append((sa[-1]+a[i-2]+n-1)% mod) print(a[-1]) return if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var ipt : OclAny := stdin.readline ; setrecursionlimit((10)->pow(7)) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + ((ipt())))->toInteger() ; var mod : double := (10)->pow(9) + 7 ; var a : Sequence := Sequence{n}->union(Sequence{ n * n mod mod }) ; var sa : Sequence := Sequence{0}->union(Sequence{ 0 }) ; for i : Integer.subrange(2, n-1) do ( execute (((a->last() + sa->last() + (n - i + 1) * n mod mod) mod mod) : a) ; execute (((sa->last() + a[i - 2+1] + n - 1) mod mod) : sa)) ; execute (a->last())->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def decToHexa(n): hexaDeciNum=['0']*100 ; i=0 ; while(n!=0): temp=0 ; temp=n % 16 ; if(temp<10): hexaDeciNum[i]=chr(temp+48); i=i+1 ; else : hexaDeciNum[i]=chr(temp+55); i=i+1 ; n=int(n/16); j=i-1 ; while(j>=0): print((hexaDeciNum[j]),end=""); j=j-1 ; n=2545 ; decToHexa(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 2545; ; decToHexa(n);; operation decToHexa(n : OclAny) pre: true post: true activity: var hexaDeciNum : Sequence := MatrixLib.elementwiseMult(Sequence{ '0' }, 100); ; var i : int := 0; ; while (n /= 0) do ( var temp : int := 0; ; temp := n mod 16; ; if (temp < 10) then ( hexaDeciNum[i+1] := (temp + 48)->byte2char(); ; i := i + 1; ) else ( hexaDeciNum[i+1] := (temp + 55)->byte2char(); ; i := i + 1; ) ; n := ("" + ((n / 16)))->toInteger();) ; var j : double := i - 1; ; while (j >= 0) do ( execute ((hexaDeciNum[j+1]))->display(); ; j := j - 1;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) readline=sys.stdin.readline from math import atan2,pi from bisect import* n=int(input()) ans=0 txy=[] for _ in range(n): x,y=[int(i)for i in readline().split()] ans=max(ans,x*x+y*y) txy.append((atan2(y,x),x,y)) txy.append((atan2(y,x)+2*pi,x,y)) txy.sort() N=100000 a=2*pi/N id1=id2=0 for i in range(N): r=i*a nid1=bisect(txy,(r,0,0)) nid2=bisect(txy,(r+pi,0,0)) if id1==nid1 and id2==nid2 : continue id1,id2=nid1,nid2 rx=ry=0 for t,x,y in txy[id1 : id2]: rx+=x ry+=y ans=max(ans,rx*rx+ry*ry) print(ans**0.5) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; var readline : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; var txy : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := readline().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; ans := Set{ans, x * x + y * y}->max() ; execute ((Sequence{atan2(y, x), x, y}) : txy) ; execute ((Sequence{atan2(y, x) + 2 * pi, x, y}) : txy)) ; txy := txy->sort() ; var N : int := 100000 ; var a : double := 2 * pi / N ; var id1 : OclAny := 0; var id2 : int := 0 ; for i : Integer.subrange(0, N-1) do ( var r : double := i * a ; var nid1 : OclAny := bisect(txy, Sequence{r, 0, 0}) ; var nid2 : OclAny := bisect(txy, Sequence{r + pi, 0, 0}) ; if id1 = nid1 & id2 = nid2 then ( continue ) else skip ; Sequence{id1,id2} := Sequence{nid1,nid2} ; var rx : OclAny := 0; var ry : int := 0 ; for _tuple : txy.subrange(id1+1, id2) do (var _indx : int := 1; var t : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); rx := rx + x ; ry := ry + y) ; ans := Set{ans, rx * rx + ry * ry}->max()) ; execute ((ans)->pow(0.5))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys mod=10**9+7 def solve(): n=int(input()) if n==1 : print(1) return dp=[0]*(n+1) dp[1]=n % mod dp[2]=n**2 % mod acc=[0]*(n+1) acc[1]=dp[1]% mod acc[2]=(dp[1]+dp[2])% mod for k in range(3,n+1): dp[k]=(dp[k-1]+(n-1)**2+acc[k-3]+n-k+2)% mod acc[k]=(acc[k-1]+dp[k])% mod ans=dp[n] print(ans) def debug(x,table): for name,val in table.items(): if x is val : print('DEBUG:{}->{}'.format(name,val),file=sys.stderr) return None if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (1)->display() ; return ) else skip ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; dp[1+1] := n mod mod ; dp[2+1] := (n)->pow(2) mod mod ; var acc : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; acc[1+1] := dp[1+1] mod mod ; acc[2+1] := (dp[1+1] + dp[2+1]) mod mod ; for k : Integer.subrange(3, n + 1-1) do ( dp[k+1] := (dp[k - 1+1] + ((n - 1))->pow(2) + acc[k - 3+1] + n - k + 2) mod mod ; acc[k+1] := (acc[k - 1+1] + dp[k+1]) mod mod) ; var ans : OclAny := dp[n+1] ; execute (ans)->display(); operation debug(x : OclAny, table : OclAny) : OclAny pre: true post: true activity: for _tuple : table->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var name : OclAny := _tuple->at(_indx); _indx := _indx + 1; var val : OclAny := _tuple->at(_indx); if x <>= val then ( execute (StringLib.interpolateStrings('DEBUG:{}->{}', Sequence{name, val}))->display() ; return null ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()); a,b,c,p=1,1,n,n-1 for i in range(n-1): p+=a-1 ; a,b,c=b,c,((n-1)**2+p+c)%(10**9+7) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var p : OclAny := null; Sequence{a,b,c,p} := Sequence{1,1,n,n - 1} ; for i : Integer.subrange(0, n - 1-1) do ( p := p + a - 1; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{b,c,(((n - 1))->pow(2) + p + c) mod ((10)->pow(9) + 7)}) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def startingPoint(Length,Speed1,Speed2): result1=0 result2=0 time1=Length//Speed1 time2=Length//Speed2 result1=gcd(time1,time2) result2=time1*time2//(result1) return result2 def firstTime(Length,Speed1,Speed2): result=0 relativeSpeed=abs(Speed1-Speed2) result=Length/relativeSpeed return result if __name__=="__main__" : L=30 S1=5 S2=2 first_Time=firstTime(L,S1,S2) starting_Point=startingPoint(L,S1,S2) print("Met first time after",first_Time,"hrs") print("Met at starting point after",starting_Point,"hrs") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( var L : int := 30 ; var S1 : int := 5 ; var S2 : int := 2 ; var first_Time : OclAny := firstTime(L, S1, S2) ; var starting_Point : OclAny := startingPoint(L, S1, S2) ; execute ("Met first time after")->display() ; execute ("Met at starting point after")->display() ) else skip; operation startingPoint(Length : OclAny, Speed1 : OclAny, Speed2 : OclAny) : OclAny pre: true post: true activity: var result1 : int := 0 ; var result2 : int := 0 ; var time1 : int := Length div Speed1 ; var time2 : int := Length div Speed2 ; result1 := gcd(time1, time2) ; result2 := time1 * time2 div (result1) ; return result2; operation firstTime(Length : OclAny, Speed1 : OclAny, Speed2 : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; var relativeSpeed : double := (Speed1 - Speed2)->abs() ; result := Length / relativeSpeed ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def alphabetPattern(N): left,middle,right=0,N-1,N+1 for row in range(0,2*N-1): if rowcompareTo(N)) < 0 then ( left := left + 1 ; execute (left)->display() ) else ( left := left - 1 ; execute (left)->display() ) ; for col : Integer.subrange(1, N - 1-1) do ( if row /= N - 1 then ( execute ("")->display() ) else ( execute ("" + ("" + ((middle))))->display() ; middle := middle - 1 )) ; if (row->compareTo(N)) < 0 then ( right := right - 1 ; execute ("" + ("" + ((right))))->display() ) else ( right := right + 1 ; execute ("" + ("" + ((right))))->display() ) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def segregate0and1(arr,n): count=0 for i in range(0,n): if(arr[i]==0): count=count+1 for i in range(0,count): arr[i]=0 for i in range(count,n): arr[i]=1 def print_arr(arr,n): print("Array after segregation is ",end="") for i in range(0,n): print(arr[i],end=" ") arr=[0,1,0,1,1,1] n=len(arr) segregate0and1(arr,n) print_arr(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))))) ; n := (arr)->size() ; segregate0and1(arr, n) ; print_arr(arr, n); operation segregate0and1(arr : OclAny, n : OclAny) pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] = 0) then ( count := count + 1 ) else skip) ; for i : Integer.subrange(0, count-1) do ( arr[i+1] := 0) ; for i : Integer.subrange(count, n-1) do ( arr[i+1] := 1); operation print_arr(arr : OclAny, n : OclAny) pre: true post: true activity: execute ("Array after segregation is ")->display() ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getValue(n): i=0 ; k=1 ; while(idisplay(); ; n := 1025; ; execute (getValue(n))->display();; operation getValue(n : OclAny) pre: true post: true activity: var i : int := 0; ; var k : int := 1; ; while ((i->compareTo(n)) < 0) do ( i := i + k; ; k := k * 2;) ; return ("" + ((k / 2)))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) P=[(0,0,0)] for i in range(N): t,x,y=map(int,input().split()) P.append((t,x,y)) T=[0]*N dist=[0]*N for i in range(N): T[i]=P[i+1][0]-P[i][0] dist[i]=abs(P[i+1][1]-P[i][1])+abs(P[i+1][2]-P[i][2]) ans=1 for i in range(N): if dist[i]>T[i]: ans=0 else : m=T[i]-dist[i] if m % 2==0 : pass else : ans=0 if ans==0 : break print("Yes" if ans==1 else "No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var P : Sequence := Sequence{ Sequence{0, 0, 0} } ; for i : Integer.subrange(0, N-1) do ( var t : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{t,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{t, x, y}) : P)) ; var T : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var dist : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for i : Integer.subrange(0, N-1) do ( T[i+1] := P[i + 1+1]->first() - P[i+1]->first() ; dist[i+1] := (P[i + 1+1][1+1] - P[i+1][1+1])->abs() + (P[i + 1+1][2+1] - P[i+1][2+1])->abs()) ; var ans : int := 1 ; for i : Integer.subrange(0, N-1) do ( if (dist[i+1]->compareTo(T[i+1])) > 0 then ( ans := 0 ) else ( var m : double := T[i+1] - dist[i+1] ; if m mod 2 = 0 then ( skip ) else ( ans := 0 ) ) ; if ans = 0 then ( break ) else skip) ; execute (if ans = 1 then "Yes" else "No" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in[0]*int(input()): t,x,y=map(int,input().split()) if(t+x+y)% 2+(ttoInteger()) do ( var t : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{t,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (t + x + y) mod 2 + ((t->compareTo(x + y)) < 0) then ( execute ("No")->display(); exit() ) else skip) ; execute ("Yes")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) txy=[list(map(int,input().split()))for _ in range(n)] if abs(txy[0][1])+abs(txy[0][2])>abs(txy[0][0])or(txy[0][0]+txy[0][1]-txy[0][2])% 2!=0 : print('No') exit() for i in range(1,n): dx,dy,dt=txy[i][1]-txy[i-1][1],txy[i][2]-txy[i-1][2],txy[i][0]-txy[i-1][0] if abs(dx)+abs(dy)>abs(dt)or(dx+dy-dt)% 2!=0 : print('No') exit() print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var txy : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; if ((txy->first()[1+1])->abs() + (txy->first()[2+1])->abs()->compareTo((txy->first()->first())->abs())) > 0 or (txy->first()->first() + txy->first()[1+1] - txy->first()[2+1]) mod 2 /= 0 then ( execute ('No')->display() ; exit() ) else skip ; for i : Integer.subrange(1, n-1) do ( var dx : OclAny := null; var dy : OclAny := null; var dt : OclAny := null; Sequence{dx,dy,dt} := Sequence{txy[i+1][1+1] - txy[i - 1+1][1+1],txy[i+1][2+1] - txy[i - 1+1][2+1],txy[i+1]->first() - txy[i - 1+1]->first()} ; if ((dx)->abs() + (dy)->abs()->compareTo((dt)->abs())) > 0 or (dx + dy - dt) mod 2 /= 0 then ( execute ('No')->display() ; exit() ) else skip) ; execute ('Yes')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=list(map(int,input().split())) C=[0]*(10**5) for ai in A : C[ai]+=1 ans=0 for i in range(10**5-2): ans=max(C[i]+C[i+1]+C[i+2],ans) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var C : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((10)->pow(5))) ; for ai : A do ( C[ai+1] := C[ai+1] + 1) ; var ans : int := 0 ; for i : Integer.subrange(0, (10)->pow(5) - 2-1) do ( ans := Set{C[i+1] + C[i + 1+1] + C[i + 2+1], ans}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) t_0,x_0,y_0=0,0,0 for n in range(N): t_1,x_1,y_1=[int(txyz)for txyz in input().split()] d_01=abs(x_1-x_0)+abs(y_1-y_0) dt=t_1-t_0 if dttoInteger() ; var t_0 : OclAny := null; var x_0 : OclAny := null; var y_0 : OclAny := null; Sequence{t_0,x_0,y_0} := Sequence{0,0,0} ; (compound_stmt for (exprlist (expr (atom (name n)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name t var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger())))))) , (test (logical_test (comparison (expr (atom (name x var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger())))))) , (test (logical_test (comparison (expr (atom (name y var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name txyz)))))))) ))))))) (comp_for for (exprlist (expr (atom (name txyz)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( )))))))) ]))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d_01)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()))) - (expr (atom (name x_0))))))))) )))) + (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name y var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()))) - (expr (atom (name y_0))))))))) )))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dt)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name t var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()))) - (expr (atom (name t_0))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name dt)))) < (comparison (expr (atom (name d_01))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "No"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name t_d)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name dt))) - (expr (atom (name d_01))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name t_d))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name t_0)))))) , (test (logical_test (comparison (expr (atom (name x_0)))))) , (test (logical_test (comparison (expr (atom (name y_0))))))) (assign_part = (testlist_star_expr (test (logical_test (comparison (expr (atom (name t var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger())))))) , (test (logical_test (comparison (expr (atom (name x var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger())))))) , (test (logical_test (comparison (expr (atom (name y var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger())))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "No"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Yes"))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- L=10**10 N=int(input()) x,y=zip(*(map(int,input().split())for _ in range(N))) result=0 for i in range(N): for b in[-1,1]: for s,t in[(y[i],-x[i]),(-y[i],x[i])]: s,t=L*s-b*t,b*s+L*t X=0 Y=0 for j in range(N): if x[j]*s+y[j]*t>0 : X+=x[j] Y+=y[j] result=max(result,(X**2+Y**2)**0.5) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var L : double := (10)->pow(10) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))) )))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))) )))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))) )))))))`third->at(_indx)} ) ; var result : int := 0 ; for i : Integer.subrange(0, N-1) do ( for b : Sequence{-1}->union(Sequence{ 1 }) do ( for _tuple : Sequence{Sequence{y[i+1], -x[i+1]}}->union(Sequence{ Sequence{-y[i+1], x[i+1]} }) do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := Sequence{L * s - b * t,b * s + L * t} ; var X : int := 0 ; var Y : int := 0 ; for j : Integer.subrange(0, N-1) do ( if x[j+1] * s + y[j+1] * t > 0 then ( X := X + x[j+1] ; Y := Y + y[j+1] ) else skip) ; result := Set{result, (((X)->pow(2) + (Y)->pow(2)))->pow(0.5)}->max()))) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def traveling(n,m): t=range(1,n+1) for i in t : tdif=m[i][0]-m[i-1][0] xydif=abs(m[i][1]-m[i-1][1])+abs(m[i][2]-m[i-1][2]) if tdiftoInteger() ; var deer : Sequence := Sequence{ Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) }->union(Integer.subrange(0, N-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))) ; execute (traveling(N, deer))->display(); operation traveling(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var t : Sequence := Integer.subrange(1, n + 1-1) ; for i : t do ( var tdif : double := m[i+1]->first() - m[i - 1+1]->first() ; var xydif : double := (m[i+1][1+1] - m[i - 1+1][1+1])->abs() + (m[i+1][2+1] - m[i - 1+1][2+1])->abs() ; if (tdif->compareTo(xydif)) < 0 then ( return 'No' ) else ( if tdif mod 2 /= xydif mod 2 then ( return 'No' ) else skip )) ; return 'Yes'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys MAX=26 ; def maxSubStr(str1,len1,str2,len2): if(len1>len2): return 0 ; freq1=[0]*MAX ; for i in range(len1): freq1[ord(str1[i])-ord('a')]+=1 ; freq2=[0]*MAX ; for i in range(len2): freq2[ord(str2[i])-ord('a')]+=1 ; minPoss=sys.maxsize ; for i in range(MAX): if(freq1[i]==0): continue ; if(freq1[i]>freq2[i]): return 0 ; minPoss=min(minPoss,freq2[i]/freq1[i]); return int(minPoss); str1="geeks" ; str2="gskefrgoekees" ; len1=len(str1); len2=len(str2); print(maxSubStr(str1,len1,str2,len2)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MAX : int := 26; ; skip ; str1 := "geeks"; str2 := "gskefrgoekees"; ; len1 := (str1)->size(); ; len2 := (str2)->size(); ; execute (maxSubStr(str1, len1, str2, len2))->display();; operation maxSubStr(str1 : OclAny, len1 : OclAny, str2 : OclAny, len2 : OclAny) pre: true post: true activity: if ((len1->compareTo(len2)) > 0) then ( return 0; ) else skip ; var freq1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX); ; for i : Integer.subrange(0, len1-1) do ( freq1[(str1[i+1])->char2byte() - ('a')->char2byte()+1] := freq1[(str1[i+1])->char2byte() - ('a')->char2byte()+1] + 1;) ; var freq2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX); ; for i : Integer.subrange(0, len2-1) do ( freq2[(str2[i+1])->char2byte() - ('a')->char2byte()+1] := freq2[(str2[i+1])->char2byte() - ('a')->char2byte()+1] + 1;) ; var minPoss : (trailer . (name maxsize)) := (trailer . (name maxsize)); ; for i : Integer.subrange(0, MAX-1) do ( if (freq1[i+1] = 0) then ( continue; ) else skip ; if ((freq1[i+1]->compareTo(freq2[i+1])) > 0) then ( return 0; ) else skip ; minPoss := Set{minPoss, freq2[i+1] / freq1[i+1]}->min();) ; return ("" + ((minPoss)))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n,r=map(int,input().split()) if n==0 : break a=[n-i for i in range(n)] for i in range(r): p,c=map(int,input().split()) a=a[p-1 : p-1+c]+a[: p-1]+a[p-1+c :] print(a[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : OclAny := null; var r : OclAny := null; Sequence{n,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (n - i)) ; for i : Integer.subrange(0, r-1) do ( var p : OclAny := null; var c : OclAny := null; Sequence{p,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := a.subrange(p - 1+1, p - 1 + c) + a.subrange(1,p - 1) + a.subrange(p - 1 + c+1)) ; execute (a->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cond=[int(n)for n in input().split(" ")] while True : case=[] cards=[n for n in range(1,cond[0]+1)] cards.sort(reverse=True) for c in range(cond[1]): case=[int(n)for n in input().split(" ")] case[0]-=1 disp=cards[case[0]: case[0]+case[1]] cards[case[1]: case[0]+case[1]]=cards[0 : case[0]] cards[0 : case[1]]=disp else : print(cards[0]) cond=[int(n)for n in input().split(" ")] if cond[0]==0 and cond[1]==0 : break else : continue ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cond : Sequence := input().split(" ")->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; while true do ( var case : Sequence := Sequence{} ; var cards : Sequence := Integer.subrange(1, cond->first() + 1-1)->select(n | true)->collect(n | (n)) ; cards := cards->sort() ; (compound_stmt for (exprlist (expr (atom (name c)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name cond)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name case)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " "))))))) )))))))) ]))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name case)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name disp)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cards)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name case)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))) : (test (logical_test (comparison (expr (expr (atom (name case)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) + (expr (atom (name case)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))))) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cards)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name case)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))) : (test (logical_test (comparison (expr (expr (atom (name case)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) + (expr (atom (name case)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cards)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))) : (test (logical_test (comparison (expr (atom (name case)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cards)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))) : (test (logical_test (comparison (expr (atom (name case)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name disp))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name cards)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cond)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " "))))))) )))))))) ]))))))))))) (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name cond)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) == (comparison (expr (atom (number (integer 0))))))) and (logical_test (comparison (comparison (expr (atom (name cond)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) == (comparison (expr (atom (number (integer 0))))))))) : (suite (stmt (simple_stmt (small_stmt break)))) (else_clause else : (suite (stmt (simple_stmt (small_stmt continue))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Deck : def __init__(self,card_num): self.deck_list=self.make_deck(card_num) def make_deck(self,card_num): deck_list=[None]*card_num order=0 for i in reversed(range(1,card_num+1)): deck_list[order]=i order+=1 return deck_list def shuffled(self,cut_pos1,cut_pos2): above_card=self.deck_list[0 : cut_pos1] below_card=self.deck_list[cut_pos1 : cut_pos2] remain_card=self.deck_list[cut_pos2 :] self.deck_list=below_card+above_card+remain_card def get_two_int(): two_int=input().split() for i in range(2): two_int[i]=int(two_int[i]) return two_int if __name__=="__main__" : while True : card_num,shuffle_num=get_two_int() if card_num==shuffle_num==0 : break deck=Deck(card_num) for i in range(shuffle_num): c,p=get_two_int() cut_pos1=c-1 cut_pos2=c-1+p deck.shuffled(cut_pos1,cut_pos2) print(deck.deck_list[0]) ------------------------------------------------------------ OCL File: --------- class Deck { static operation newDeck() : Deck pre: true post: Deck->exists( _x | result = _x ); attribute deck_list : OclAny := self.make_deck(card_num); operation initialise(card_num : OclAny) : Deck pre: true post: true activity: self.deck_list := self.make_deck(card_num); return self; operation make_deck(card_num : OclAny) : OclAny pre: true post: true activity: var deck_list : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, card_num) ; var order : int := 0 ; for i : (Integer.subrange(1, card_num + 1-1))->reverse() do ( deck_list[order+1] := i ; order := order + 1) ; return deck_list; operation shuffled(cut_pos1 : OclAny,cut_pos2 : OclAny) pre: true post: true activity: var above_card : OclAny := self.deck_list.subrange(0+1, cut_pos1) ; var below_card : OclAny := self.deck_list.subrange(cut_pos1+1, cut_pos2) ; var remain_card : OclAny := self.deck_list.subrange(cut_pos2+1) ; self.deck_list := below_card + above_card + remain_card; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( while true do ( var shuffle_num : OclAny := null; Sequence{card_num,shuffle_num} := get_two_int() ; if card_num = shuffle_num & (shuffle_num == 0) then ( break ) else skip ; var deck : Deck := (Deck.newDeck()).initialise(card_num) ; for i : Integer.subrange(0, shuffle_num-1) do ( var c : OclAny := null; var p : OclAny := null; Sequence{c,p} := get_two_int() ; cut_pos1 := c - 1 ; cut_pos2 := c - 1 + p ; deck.shuffled(cut_pos1, cut_pos2)) ; execute (deck.deck_list->first())->display()) ) else skip; operation get_two_int() : OclAny pre: true post: true activity: var two_int : OclAny := input().split() ; for i : Integer.subrange(0, 2-1) do ( two_int[i+1] := ("" + ((two_int[i+1])))->toInteger()) ; return two_int; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy def solve(): while(True): n,r=map(int,input().split()) beforelist=[i for i in range(n,0,-1)] afterlist=copy.deepcopy(beforelist) if n==0 and r==0 : break for _ in range(r): p,c=map(int,input().split()) j=0 for i in range(p-1,p-1+c): afterlist[j]=copy.deepcopy(beforelist[i]) j+=1 for i in range(0,p-1): afterlist[j]=copy.deepcopy(beforelist[i]) j+=1 beforelist=copy.deepcopy(afterlist) print(beforelist[0]) if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: while (true) do ( var n : OclAny := null; var r : OclAny := null; Sequence{n,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var beforelist : Sequence := Integer.subrange(0 + 1, n)->reverse()->select(i | true)->collect(i | (i)) ; var afterlist : OclAny := copy.deepcopy(beforelist) ; if n = 0 & r = 0 then ( break ) else skip ; for _anon : Integer.subrange(0, r-1) do ( var p : OclAny := null; var c : OclAny := null; Sequence{p,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var j : int := 0 ; for i : Integer.subrange(p - 1, p - 1 + c-1) do ( afterlist[j+1] := copy.deepcopy(beforelist[i+1]) ; j := j + 1) ; for i : Integer.subrange(0, p - 1-1) do ( afterlist[j+1] := copy.deepcopy(beforelist[i+1]) ; j := j + 1) ; beforelist := copy.deepcopy(afterlist)) ; execute (beforelist->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,r=list(map(lambda x : int(x),input().split(" "))) if n==0 and r==0 : break cards=[i for i in range(1,n+1)] cards=cards[: :-1] for i in range(r): p,c=list(map(lambda x : int(x),input().split(" "))) p-=1 cards=cards[p : p+c]+cards[0 : p]+cards[p+c :] print(cards[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var r : OclAny := null; Sequence{n,r} := ((input().split(" "))->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) )) ; if n = 0 & r = 0 then ( break ) else skip ; var cards : Sequence := Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | (i)) ; cards := cards(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; for i : Integer.subrange(0, r-1) do ( var p : OclAny := null; var c : OclAny := null; Sequence{p,c} := ((input().split(" "))->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) )) ; p := p - 1 ; cards := cards.subrange(p+1, p + c) + cards.subrange(0+1, p) + cards.subrange(p + c+1)) ; execute (cards->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import log2 ; def invertBits(num): x=log2(num)+1 ; for i in range(int(x)): num=(num ^(1<union(Sequence{7}->union(Sequence{1}->union(Sequence{ 99 }))); ; arr2 := Sequence{5}->union(Sequence{1}->union(Sequence{28}->union(Sequence{ 20 }))); ; n := (arr1)->size(); ; m := (arr2)->size(); ; execute (totalPairs(arr1, arr2, n, m))->display(); ) else skip; operation invertBits(num : OclAny) pre: true post: true activity: var x : OclAny := log2(num) + 1; ; for i : Integer.subrange(0, ("" + ((x)))->toInteger()-1) do ( num := (MathLib.bitwiseXor(num, (1 * (2->pow(i)))));) ; return num;; operation totalPairs(arr1 : OclAny, arr2 : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: var s1 : OclAny := null; var s2 : OclAny := null; Sequence{s1,s2} := Sequence{Set{}->union(()),Set{}->union(())}; ; for i : Integer.subrange(0, m-1) do ( execute ((arr2[i+1]) : s2);) ; var count : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (s1)->excludes(arr1[i+1]) then ( if (s2)->includes(invertBits(arr1[i+1])) then ( count := count + 1; ; execute ((arr1[i+1]) : s1); ) else skip ) else skip) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y,a,b=input().split() x=int(x) y=int(y) a=int(a) b=int(b) p=0 if(x>y): temp=x x=y y=temp i=y while(i>0): if(x % i==0 and y % i==0): p=(x*y)//i break i-=1 for i in range(a,b+1): if(i % p==0): q=i r=1 break else : q=a r=0 print(b//p-q//p+r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{x,y,a,b} := input().split() ; var x : int := ("" + ((x)))->toInteger() ; var y : int := ("" + ((y)))->toInteger() ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; var p : int := 0 ; if ((x->compareTo(y)) > 0) then ( var temp : int := x ; x := y ; y := temp ) else skip ; var i : int := y ; while (i > 0) do ( if (x mod i = 0 & y mod i = 0) then ( p := (x * y) div i ; break ) else skip ; i := i - 1) ; for i : Integer.subrange(a, b + 1-1) do ( if (i mod p = 0) then ( var q : int := i ; var r : int := 1 ; break ) else ( q := a ; r := 0 )) ; execute (b div p - q div p + r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np from collections import Counter n=int(input()) a=np.array(list(map(int,input().split()))) b=a+1 c=a-1 d=np.concatenate((a,b,c)) e=Counter(d) print(e.most_common()[0][1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var b : Sequence := MatrixLib.elementwiseAdd(a, 1) ; var c : double := a - 1 ; var d : (trailer . (name concatenate) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name b)))))) , (test (logical_test (comparison (expr (atom (name c))))))) )))))))) ))) := ; var e : OclAny := Counter(d) ; execute (e.most_common()->first()[1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) s=input()+'$' if "2020" in[s[: i]+s[-5+i :-1]for i in range(5)]: print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() + '$' ; if (Integer.subrange(0, 5-1)->select(i | true)->collect(i | (s.subrange(1,i) + s.subrange(-5 + i+1, -1))))->includes("2020") then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) s=input() if s[0]+s[-3 :]=="2020" or s[: 2]+s[-2 :]=="2020" or s[: 3]+s[-1 :]=="2020" or s[: 4]=="2020" or s[-4 :]=="2020" : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; if s->first() + s.subrange(-3+1) = "2020" or s.subrange(1,2) + s.subrange(-2+1) = "2020" or s.subrange(1,3) + s.subrange(-1+1) = "2020" or s.subrange(1,4) = "2020" or s.subrange(-4+1) = "2020" then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def missingNumber(self,nums): res=len(nums) for i,v in enumerate(nums): res ^=i res ^=v return res ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation missingNumber(nums : OclAny) : OclAny pre: true post: true activity: var res : int := (nums)->size() ; for _tuple : Integer.subrange(1, (nums)->size())->collect( _indx | Sequence{_indx-1, (nums)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); res := res xor i ; res := res xor v) ; return res; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline sys.setrecursionlimit(10**7) import numpy as np N=int(input()) X,Y=np.array([input().split()for _ in range(N)],dtype=np.int64).T zero=(X==0)&(Y==0) if(zero.all()): print(0) exit() X=X[~ zero] Y=Y[~ zero] N=len(X) angle=np.arctan2(Y,X) i=angle.argsort() X=X[i]; Y=Y[i]; angle=angle[i]; X=np.concatenate([X,X]) Y=np.concatenate([Y,Y]) angle=np.concatenate([angle,angle+2*np.pi]) Xcum=X.cumsum() Ycum=Y.cumsum() items=np.arange(1,N+1)[None,:] L=np.arange(N)[:,None] dx=Xcum[L+items-1]-Xcum[L]+X[L] dy=Ycum[L+items-1]-Ycum[L]+Y[L] answer=(dx*dx+dy*dy).max()**.5 print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit((10)->pow(7)) ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var X : OclAny := null; var Y : OclAny := null; Sequence{X,Y} := np.array(Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (input().split())), (argument (test (logical_test (comparison (expr (atom (name dtype)))))) = (test (logical_test (comparison (expr (atom (name np)) (trailer . (name int64)))))))).T ; var zero : int := MathLib.bitwiseAnd((X = 0), (Y = 0)) ; if (zero.all()) then ( execute (0)->display() ; exit() ) else skip ; var X : OclAny := X[MathLib.bitwiseNot(zero)+1] ; var Y : OclAny := Y[MathLib.bitwiseNot(zero)+1] ; N := (X)->size() ; var angle : (trailer . (name arctan2) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name Y))))))) , (argument (test (logical_test (comparison (expr (atom (name X)))))))) ))) := ; var i : OclAny := angle.argsort() ; X := X[i+1]; Y := Y[i+1]; angle := angle[i+1]; ; X := ; Y := ; angle := ; var Xcum : OclAny := X.cumsum() ; var Ycum : OclAny := Y.cumsum() ; var items : OclAny := np.arange(1, N + 1)[null+1] ; var L : OclAny := np.arange(N)->collect( _r | _r[null+1] ) ; var dx : double := Xcum[L + items - 1+1] - Xcum[L+1] + X[L+1] ; var dy : double := Ycum[L + items - 1+1] - Ycum[L+1] + Y[L+1] ; var answer : double := ((dx * dx + dy * dy)->max())->pow(.5) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while(t>0): t-=1 n=int(input()) s=input() res="NO" for i in range(5): if(s[: i]+s[n-(4-i):]=="2020"): res="YES" print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (t > 0) do ( t := t - 1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var res : String := "NO" ; for i : Integer.subrange(0, 5-1) do ( if (s.subrange(1,i) + s.subrange(n - (4 - i)+1) = "2020") then ( res := "YES" ) else skip) ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(s): if s[0 : 4]=="2020" : return True if s[len(s)-4 : len(s)]=="2020" : return True if s[0]=="2" and s[len(s)-3 : len(s)]=='020' : return True if s[0 : 2]=="20" and s[len(s)-2 : len(s)]=="20" : return True if s[0 : 3]=="202" and s[len(s)-1]=='0' : return True return False t=int(input()) for i in range(t): input() if solve(input()): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( input() ; if solve((OclFile["System.in"]).readLine()) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); operation solve(s : OclAny) : OclAny pre: true post: true activity: if s.subrange(0+1, 4) = "2020" then ( return true ) else skip ; if s.subrange((s)->size() - 4+1, (s)->size()) = "2020" then ( return true ) else skip ; if s->first() = "2" & s.subrange((s)->size() - 3+1, (s)->size()) = '020' then ( return true ) else skip ; if s.subrange(0+1, 2) = "20" & s.subrange((s)->size() - 2+1, (s)->size()) = "20" then ( return true ) else skip ; if s.subrange(0+1, 3) = "202" & s[(s)->size() - 1+1] = '0' then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : t-=1 l=input() s=input() k=False if s[0]=='2' and s[1]=='0' and s[2]=='2' and s[3]=='0' : k=True if s[0]=='2' and s[1]=='0' and s[2]=='2' and s[-1]=='0' : k=True if s[0]=='2' and s[1]=='0' and s[-2]=='2' and s[-1]=='0' : k=True if s[0]=='2' and s[-3]=='0' and s[-2]=='2' and s[-1]=='0' : k=True if s[-4]=='2' and s[-3]=='0' and s[-2]=='2' and s[-1]=='0' : k=True if k==True : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( t := t - 1 ; var l : String := (OclFile["System.in"]).readLine() ; var s : String := (OclFile["System.in"]).readLine() ; var k : boolean := false ; if s->first() = '2' & s[1+1] = '0' & s[2+1] = '2' & s[3+1] = '0' then ( k := true ) else skip ; if s->first() = '2' & s[1+1] = '0' & s[2+1] = '2' & s->last() = '0' then ( k := true ) else skip ; if s->first() = '2' & s[1+1] = '0' & s->front()->last() = '2' & s->last() = '0' then ( k := true ) else skip ; if s->first() = '2' & s->reverse()->at(-(-3)) = '0' & s->front()->last() = '2' & s->last() = '0' then ( k := true ) else skip ; if s->reverse()->at(-(-4)) = '2' & s->reverse()->at(-(-3)) = '0' & s->front()->last() = '2' & s->last() = '0' then ( k := true ) else skip ; if k = true then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): MOD=10**10 ans=sum(pow(i,i,MOD)for i in range(1,1001))% MOD return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var MOD : double := (10)->pow(10) ; var ans : int := ((argument (test (logical_test (comparison (expr (atom (name pow)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (name MOD)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1001))))))))) )))))))))->sum() mod MOD ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isSlopeGood(slope,arr,n): setOfLines=dict() for i in range(n): setOfLines[arr[i]-slope*(i)]=1 return len(setOfLines)==2 def checkForParallel(arr,n): slope1=isSlopeGood(arr[1]-arr[0],arr,n) slope2=isSlopeGood(arr[2]-arr[1],arr,n) slope3=isSlopeGood((arr[2]-arr[0])//2,arr,n) return(slope1 or slope2 or slope3) arr=[1,6,3,8,5] n=len(arr) if checkForParallel(arr,n): print(1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{1}->union(Sequence{6}->union(Sequence{3}->union(Sequence{8}->union(Sequence{ 5 })))) ; n := (arr)->size() ; if checkForParallel(arr, n) then ( execute (1)->display() ) else ( execute (0)->display() ); operation isSlopeGood(slope : OclAny, arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var setOfLines : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( setOfLines[arr[i+1] - slope * (i)+1] := 1) ; return (setOfLines)->size() = 2; operation checkForParallel(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var slope1 : OclAny := isSlopeGood(arr[1+1] - arr->first(), arr, n) ; var slope2 : OclAny := isSlopeGood(arr[2+1] - arr[1+1], arr, n) ; var slope3 : OclAny := isSlopeGood((arr[2+1] - arr->first()) div 2, arr, n) ; return (slope1 or slope2 or slope3); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,bisect,math,itertools,string,queue,copy mod=10**9+7 def inp(): return int(input()) def inpm(): return map(int,input().split()) def inpl(): return list(map(int,input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(input())for _ in range(n)) def inplL(n): return[list(input())for _ in range(n)] def inplT(n): return[tuple(input())for _ in range(n)] def inpll(n): return[list(map(int,input().split()))for _ in range(n)] def inplls(n): return sorted([list(map(int,input().split()))for _ in range(n)]) l=[] n=inp() for i in range(1,n+1): r=input().split() s=r[0] p=int(r[1]) l.append([i,s,p]) ans=sorted(l,key=lambda x :(x[1],-x[2])) for t in ans : print(t[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var l : Sequence := Sequence{} ; n := inp() ; for i : Integer.subrange(1, n + 1-1) do ( var r : OclAny := input().split() ; var s : String := r->first() ; var p : int := ("" + ((r[1+1])))->toInteger() ; execute ((Sequence{i}->union(Sequence{s}->union(Sequence{ p }))) : l)) ; var ans : Sequence := l->sortedBy($x | (lambda x : OclAny in (Sequence{x[1+1], -x[2+1]}))->apply($x)) ; for t : ans do ( execute (t->first())->display()); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inpm() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inpls() : OclAny pre: true post: true activity: return (input().split()); operation inplm(n : OclAny) : OclAny pre: true post: true activity: return ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))); operation inplL(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((OclFile["System.in"]).readLine())->characters())); operation inplT(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((OclFile["System.in"]).readLine()))); operation inpll(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))); operation inplls(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))->sort(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) alist=[int(i)for i in input().split()] adict={} for i in alist : if str(i)in adict : adict[str(i)]+=1 else : adict[str(i)]=1 if str(i-1)in adict : adict[str(i-1)]+=1 else : adict[str(i-1)]=1 if str(i+1)in adict : adict[str(i+1)]+=1 else : adict[str(i+1)]=1 print(max(adict.values())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var alist : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var adict : OclAny := Set{} ; for i : alist do ( if (adict)->includes(("" + ((i)))) then ( adict[("" + ((i)))+1] := adict[("" + ((i)))+1] + 1 ) else ( adict[("" + ((i)))+1] := 1 ) ; if (adict)->includes(("" + ((i - 1)))) then ( adict[("" + ((i - 1)))+1] := adict[("" + ((i - 1)))+1] + 1 ) else ( adict[("" + ((i - 1)))+1] := 1 ) ; if (adict)->includes(("" + ((i + 1)))) then ( adict[("" + ((i + 1)))+1] := adict[("" + ((i + 1)))+1] + 1 ) else ( adict[("" + ((i + 1)))+1] := 1 )) ; execute ((adict.values())->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=[] for i in range(n): s,p=input().rstrip().split() x.append((s,100-int(p),i+1)) x=sorted(x) for xx in x : print(xx[2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var s : OclAny := null; var p : OclAny := null; Sequence{s,p} := input().rstrip().split() ; execute ((Sequence{s, 100 - ("" + ((p)))->toInteger(), i + 1}) : x)) ; x := x->sort() ; for xx : x do ( execute (xx[2+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from operator import itemgetter sp=[] for i in range(int(input())): t=list(input().split()) t[1]=100-int(t[1]) t.append(i+1) sp.append(t) sp=sorted(sp,key=itemgetter(0,1)) print('\n'.join([str(i[2])for i in sp])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var sp : Sequence := Sequence{} ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var t : Sequence := (input().split()) ; t[1+1] := 100 - ("" + ((t[1+1])))->toInteger() ; execute ((i + 1) : t) ; execute ((t) : sp)) ; sp := sp->sortedBy($x | (itemgetter(0, 1))->apply($x)) ; execute (StringLib.sumStringsWithSeparator((sp->select(i | true)->collect(i | (("" + ((i[2+1])))))), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def myop1(e): return e[1] def myop2(e): return e[0] t=int(input()) l=[] d={} for _ in range(t): s,n=input().split(' ') n=int(n) l.append((s,n)) k=[i for i in l] l.sort(reverse=True,key=myop1) l.sort(key=myop2) for i in range(len(l)): d[k[i]]=i for i in l : print(str(d[i]+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; var d : OclAny := Set{} ; for _anon : Integer.subrange(0, t-1) do ( var s : OclAny := null; var n : OclAny := null; Sequence{s,n} := input().split(' ') ; var n : int := ("" + ((n)))->toInteger() ; execute ((Sequence{s, n}) : l)) ; var k : Sequence := l->select(i | true)->collect(i | (i)) ; l := l->sort() ; l := l->sort() ; for i : Integer.subrange(0, (l)->size()-1) do ( d[k[i+1]+1] := i) ; for i : l do ( execute (("" + ((d[i+1] + 1))))->display()); operation myop1(e : OclAny) : OclAny pre: true post: true activity: return e[1+1]; operation myop2(e : OclAny) : OclAny pre: true post: true activity: return e->first(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) SP=[input().split()for _ in range(N)] plist=[] spm={} for s,p in SP : plist+=[int(p)] if not s in spm : spm[s]=[int(p)] else : spm[s]+=[int(p)] spl=[] for m in sorted(spm): for p in sorted(spm[m])[: :-1]: spl+=[p] for p in spl : print(plist.index(p)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var SP : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (input().split())) ; var plist : Sequence := Sequence{} ; var spm : OclAny := Set{} ; for _tuple : SP do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p : OclAny := _tuple->at(_indx); plist := plist + Sequence{ ("" + ((p)))->toInteger() } ; if not((spm)->includes(s)) then ( spm[s+1] := Sequence{ ("" + ((p)))->toInteger() } ) else ( spm[s+1] := spm[s+1] + Sequence{ ("" + ((p)))->toInteger() } )) ; var spl : Sequence := Sequence{} ; for m : spm->sort() do ( for p : sorted(spm[m+1])(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( spl := spl + Sequence{ p })) ; for p : spl do ( execute (plist->indexOf(p) - 1 + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def topKFrequent(self,words,k): count=collections.Counter(words) heap=[(-freq,word)for word,freq in count.items()] heapq.heapify(heap) return[heapq.heappop(heap)[1]for _ in xrange(k)] ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation topKFrequent(words : OclAny,k : OclAny) : OclAny pre: true post: true activity: var count : OclAny := .Counter(words) ; var heap : Sequence := count->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->select(_tuple | true)->collect(_tuple | let word : OclAny = _tuple->at(1) in let freq : OclAny = _tuple->at(2) in (Sequence{-freq, word})) ; heapq.heapify(heap) ; return xrange(k)->select(_anon | true)->collect(_anon | (heapq.heappop(heap)[1+1])); } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxEdges(N): edges=0 ; edges=(N*N)//4 ; return edges ; if __name__=="__main__" : N=5 ; print(maxEdges(N)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := 5; ; execute (maxEdges(N))->display(); ) else skip; operation maxEdges(N : OclAny) pre: true post: true activity: var edges : int := 0; ; edges := (N * N) div 4; ; return edges;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkIfStartsWithVowels(string): if(not(string[0]=='A' or string[0]=='a' or string[0]=='E' or string[0]=='e' or string[0]=='I' or string[0]=='i' or string[0]=='O' or string[0]=='o' or string[0]=='U' or string[0]=='u')): return 1 ; else : return 0 ; def check(string): if(checkIfStartsWithVowels(string)): print("Not Accepted"); else : print("Accepted"); if __name__=="__main__" : string="animal" ; check(string); string="zebra" ; check(string); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( string := "animal"; ; check(string); ; string := "zebra"; ; check(string); ) else skip; operation checkIfStartsWithVowels(string : OclAny) pre: true post: true activity: if (not((string->first() = 'A' or string->first() = 'a' or string->first() = 'E' or string->first() = 'e' or string->first() = 'I' or string->first() = 'i' or string->first() = 'O' or string->first() = 'o' or string->first() = 'U' or string->first() = 'u'))) then ( return 1; ) else ( return 0; ); operation check(string : OclAny) pre: true post: true activity: if (checkIfStartsWithVowels(string)) then ( execute ("Not Accepted")->display(); ) else ( execute ("Accepted")->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minSum(arr,n): MAX=10 freq=[0]*MAX for i in range(n): freq[arr[i]]+=1 k=0 for i in range(MAX): for j in range(0,freq[i]): arr[k]=i k+=1 num1=0 num2=0 for i in range(n): if i % 2==0 : num1=num1*MAX+arr[i] else : num2=num2*MAX+arr[i] return num1+num2 arr=[6,8,4,5,2,3] n=len(arr); print(minSum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{6}->union(Sequence{8}->union(Sequence{4}->union(Sequence{5}->union(Sequence{2}->union(Sequence{ 3 }))))) ; n := (arr)->size(); ; execute (minSum(arr, n))->display(); operation minSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var MAX : int := 10 ; var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX) ; for i : Integer.subrange(0, n-1) do ( freq[arr[i+1]+1] := freq[arr[i+1]+1] + 1) ; var k : int := 0 ; for i : Integer.subrange(0, MAX-1) do ( for j : Integer.subrange(0, freq[i+1]-1) do ( arr[k+1] := i ; k := k + 1)) ; var num1 : int := 0 ; var num2 : int := 0 ; for i : Integer.subrange(0, n-1) do ( if i mod 2 = 0 then ( num1 := num1 * MAX + arr[i+1] ) else ( num2 := num2 * MAX + arr[i+1] )) ; return num1 + num2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n): ans=0 mp={} while(n>=10): s=str(n) next=-1 for i in range(1,len(s)): next=max(next,int(s[0 : i])*int(s[i :])) if next in mp : ans=-1 break mp[next]=True n=next ans+=1 return ans def main(): q=int(input()) for i in range(q): n=int(input()) print(solve(n)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation solve(n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; var mp : OclAny := Set{} ; while (n >= 10) do ( var s : String := ("" + ((n))) ; var next : int := -1 ; for i : Integer.subrange(1, (s)->size()-1) do ( next := Set{next, ("" + ((s.subrange(0+1, i))))->toInteger() * ("" + ((s.subrange(i+1))))->toInteger()}->max()) ; if (mp)->includes(next) then ( ans := -1 ; break ) else skip ; mp[next+1] := true ; n := next ; ans := ans + 1) ; return ans; operation main() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (solve(n))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] q=I() qi=0 while qi1 : r+=1 t=0 for i in range(1,len(n)): u=int(n[: i])*int(n[i :]) if tpow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; var q : OclAny := I() ; var qi : int := 0 ; while (qi->compareTo(q)) < 0 do ( qi := qi + 1 ; var n : OclAny := S() ; var r : int := 0 ; while (n)->size() > 1 do ( r := r + 1 ; var t : int := 0 ; for i : Integer.subrange(1, (n)->size()-1) do ( var u : int := ("" + ((n.subrange(1,i))))->toInteger() * ("" + ((n.subrange(i+1))))->toInteger() ; if (t->compareTo(u)) < 0 then ( t := u ) else skip) ; n := ("" + ((t)))) ; execute ((r) : rr)) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cnt=[0]*100002 input() for x in map(int,input().split()): cnt[x]+=1 cnt[x+1]+=1 cnt[x+2]+=1 print(max(cnt)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100002) ; input() ; for x : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( cnt[x+1] := cnt[x+1] + 1 ; cnt[x + 1+1] := cnt[x + 1+1] + 1 ; cnt[x + 2+1] := cnt[x + 2+1] + 1) ; execute ((cnt)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math Q=sys.stdin.readline() for _ in range(int(Q)): cnt=0 N=int(sys.stdin.readline()) if N!=0 : digLeng=int(math.log10(N))+1 else : digLeng=1 while digLeng>1 : Nmax=0 for dig in range(digLeng): lNum=N//int(math.pow(10,dig)) rNum=N % int(math.pow(10,dig)) Nmax=max(Nmax,lNum*rNum) N=Nmax cnt+=1 if N!=0 : digLeng=int(math.log10(N))+1 else : digLeng=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var Q : String := (OclFile["System.in"]).readLine() ; for _anon : Integer.subrange(0, ("" + ((Q)))->toInteger()-1) do ( var cnt : int := 0 ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N /= 0 then ( var digLeng : int := ("" + (((N)->log10())))->toInteger() + 1 ) else ( digLeng := 1 ) ; while digLeng > 1 do ( var Nmax : int := 0 ; for dig : Integer.subrange(0, digLeng-1) do ( var lNum : int := N div ("" + (((10)->pow(dig))))->toInteger() ; var rNum : int := N mod ("" + (((10)->pow(dig))))->toInteger() ; Nmax := Set{Nmax, lNum * rNum}->max()) ; N := Nmax ; cnt := cnt + 1 ; if N /= 0 then ( digLeng := ("" + (((N)->log10())))->toInteger() + 1 ) else ( digLeng := 1 )) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- Q=int(input()) N=[input()for i in range(0,Q)] integer=lambda x : int(x)if x!='' else 0 for n in N : ans='0' if int(n)//10==0 else str(n) count=0 while int(ans)//10>0 : count+=1 tmp=0 for i in range(1,len(ans)): tmp=max(tmp,integer(ans[: i])*integer(ans[i :])) ans=str(tmp) else : print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var N : Sequence := Integer.subrange(0, Q-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var integer : Function := lambda x : OclAny in (if x /= '' then ("" + ((x)))->toInteger() else 0 endif) ; for n : N do ( var ans : String := if ("" + ((n)))->toInteger() div 10 = 0 then '0' else ("" + ((n))) endif ; var count : int := 0 ; (compound_stmt while (test (logical_test (comparison (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) )))) // (expr (atom (number (integer 10)))))) > (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name count)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name tmp)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name tmp)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name tmp))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name integer)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))) * (expr (atom (name integer)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))) :)) ])))))))) )))))))))) )))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name tmp)))))))) )))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name count)))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import reduce g=lambda x,y : x*y cv=lambda s : str(max([reduce(g,list(map(int,[s[: i],s[i :]])))for i in range(1,len(s))])) for _ in range(int(input())): c=0 n=input() s=set() while 1 : if len(n)==1 : break if n in s : c=-1 break s.add(n) n=cv(n) c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var g : Function := lambda x : OclAny, y : OclAny in (x * y) ; var cv : Function := lambda s : OclAny in (("" + (((Integer.subrange(1, (s)->size()-1)->select(i | true)->collect(i | (reduce(g, ((Sequence{s.subrange(1,i)}->union(Sequence{ s.subrange(i+1) }))->collect( _x | (OclType["int"])->apply(_x) ))))))->max())))) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var c : int := 0 ; var n : String := (OclFile["System.in"]).readLine() ; var s : Set := Set{}->union(()) ; while 1 do ( if (n)->size() = 1 then ( break ) else skip ; if (s)->includes(n) then ( c := -1 ; break ) else skip ; execute ((n) : s) ; n := cv->apply(n) ; c := c + 1) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N,M=map(int,input().split()) if 1collect( _x | (OclType["int"])->apply(_x) ) ; if 1 < N then ( N := N - 2 ) else skip ; if 1 < M then ( M := M - 2 ) else skip ; execute (N * M)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def read_input(): n,m=map(int,input().split()) return n,m def submit(): n,m=read_input() short_side=min(n,m) long_side=max(n,m) if short_side==1 : if long_side==1 : print(1) else : print(long_side-2) else : corners=4 sides=2*(short_side-2)+2*(long_side-2) insides=n*m-corners-sides print(insides) if __name__=='__main__' : submit() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( submit() ) else skip; operation read_input() : OclAny pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; return n, m; operation submit() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := read_input() ; var short_side : OclAny := Set{n, m}->min() ; var long_side : OclAny := Set{n, m}->max() ; if short_side = 1 then ( if long_side = 1 then ( execute (1)->display() ) else ( execute (long_side - 2)->display() ) ) else ( var corners : int := 4 ; var sides : double := 2 * (short_side - 2) + 2 * (long_side - 2) ; var insides : double := n * m - corners - sides ; execute (insides)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N,X=map(int,input().split()) ans=f(N,X) print(ans) def layers(N): layer=[0]*(N+1) layer[0]=1 p_layer=[0]*(N+1) p_layer[0]=1 for i in range(1,N+1): layer[i]=1+layer[i-1]+1+layer[i-1]+1 p_layer[i]=p_layer[i-1]+1+p_layer[i-1] return layer,p_layer def f(N,X): layer,p_layer=layers(N) def patty(N,X): if N<=0 : return 0 ans=0 if X>=1 : X-=1 if X>=layer[N-1]: X-=layer[N-1] ans+=p_layer[N-1] if X>=1 : X-=1 ans+=1 if X>=layer[N-1]: X-=layer[N-1] ans+=p_layer[N-1] else : ans+=patty(N-1,X) else : ans+=patty(N-1,X) return ans ans=patty(N,X) return ans if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var X : OclAny := null; Sequence{N,X} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : String := f(N, X) ; execute (ans)->display(); operation layers(N : OclAny) : OclAny pre: true post: true activity: var layer : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; layer->first() := 1 ; var p_layer : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; p_layer->first() := 1 ; for i : Integer.subrange(1, N + 1-1) do ( layer[i+1] := 1 + layer[i - 1+1] + 1 + layer[i - 1+1] + 1 ; p_layer[i+1] := p_layer[i - 1+1] + 1 + p_layer[i - 1+1]) ; return layer, p_layer; operation f(N : OclAny, X : OclAny) : OclAny pre: true post: true activity: Sequence{layer,p_layer} := layers(N) ; skip ; ans := patty(N, X) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) if a>1 and b>1 : print((a-2)*(b-2)) elif a==1 and b==1 : print(1) else : print(max(a,b)-2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a > 1 & b > 1 then ( execute ((a - 2) * (b - 2))->display() ) else (if a = 1 & b = 1 then ( execute (1)->display() ) else ( execute (Set{a, b}->max() - 2)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=list(map(int,input().split())) print(abs((n-2)*(m-2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (((n - 2) * (m - 2))->abs())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(x)for x in input().split()] if n==m==1 : print(1) elif n==1 or m==1 : print(max(n,m)-2) elif n==2 or m==2 : print(0) else : print((n*m)-(n*2+m*2-4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if n = m & (m == 1) then ( execute (1)->display() ) else (if n = 1 or m = 1 then ( execute (Set{n, m}->max() - 2)->display() ) else (if n = 2 or m = 2 then ( execute (0)->display() ) else ( execute ((n * m) - (n * 2 + m * 2 - 4))->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import random def printArray(stream,n): for i in range(n): print(stream[i],end=" "); print(); def selectKItems(stream,n,k): i=0 ; reservoir=[0]*k ; for i in range(k): reservoir[i]=stream[i]; while(iunion(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{10}->union(Sequence{11}->union(Sequence{ 12 }))))))))))); ; n := (stream)->size(); ; k := 5; ; selectKItems(stream, n, k); ) else skip; operation printArray(stream : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (stream[i+1])->display();) ; execute (->display();; operation selectKItems(stream : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var i : int := 0; ; var reservoir : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, k); ; for i : Integer.subrange(0, k-1) do ( reservoir[i+1] := stream[i+1];) ; while ((i->compareTo(n)) < 0) do ( var j : int := (OclRandom.defaultInstanceOclRandom()).nextInt(i + 1); ; if ((j->compareTo(k)) < 0) then ( reservoir[j+1] := stream[i+1]; ) else skip ; i := i + 1;) ; execute ("Following are k randomly selected items")->display(); ; printArray(reservoir, k);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def main(): _=int(input()) d=defaultdict(lambda : 0) for a in[int(i)for i in input().split()]: d[a-1]+=1 d[a]+=1 d[a+1]+=1 print(sorted(d.items(),key=lambda x : x[1],reverse=True)[0][1]) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var _anon : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; for a : input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) do ( d[a - 1+1] := d[a - 1+1] + 1 ; d[a+1] := d[a+1] + 1 ; d[a + 1+1] := d[a + 1+1] + 1) ; execute (sorted(d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))), (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True))))))))->first()[1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CenteredDodecahedral_num(n): return(2*n+1)*(5*n*n+5*n+1) if __name__=='__main__' : n=3 print(n,"rd centered dodecahedral number: ",CenteredDodecahedral_num(n)) n=10 print(n,"th centered dodecahedral number : ",CenteredDodecahedral_num(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 3 ; execute (n)->display() ; n := 10 ; execute (n)->display() ) else skip; operation CenteredDodecahedral_num(n : OclAny) : OclAny pre: true post: true activity: return (2 * n + 1) * (5 * n * n + 5 * n + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() n=int(n) a=input().split() a=[int(aa)for aa in a] ans=10000000000000000 l=-100000000000 r=100000000000 for count in range(100): mid1=1*(r-l)//3+l mid2=2*(r-l)//3+l temp1=0 temp2=0 for i in range(n): temp1+=abs(a[i]-(mid1+i+1)) temp2+=abs(a[i]-(mid2+i+1)) if temp1toInteger() ; var a : OclAny := input().split() ; a := a->select(aa | true)->collect(aa | (("" + ((aa)))->toInteger())) ; var ans : int := 10000000000000000 ; var l : int := -100000000000 ; var r : int := 100000000000 ; for count : Integer.subrange(0, 100-1) do ( var mid1 : int := 1 * (r - l) div 3 + l ; var mid2 : int := 2 * (r - l) div 3 + l ; var temp1 : int := 0 ; var temp2 : int := 0 ; for i : Integer.subrange(0, n-1) do ( temp1 := temp1 + (a[i+1] - (mid1 + i + 1))->abs() ; temp2 := temp2 + (a[i+1] - (mid2 + i + 1))->abs()) ; if (temp1->compareTo(temp2)) < 0 then ( r := mid2 ) else ( l := mid1 )) ; for b : Integer.subrange(l, r + 1-1) do ( var temp : int := 0 ; for i : Integer.subrange(0, n-1) do ( temp := temp + (a[i+1] - (b + i + 1))->abs()) ; ans := Set{ans, temp}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from statistics import median def main(): N=int(input()) strs=input() As=[int(num)for num in strs.split()] nums=[a-i for i,a in enumerate(As,1)] m=int(median(nums)) print(sum([abs(a-m)for a in nums])) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var strs : String := (OclFile["System.in"]).readLine() ; var As : Sequence := strs.split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var nums : Sequence := Integer.subrange(1, (As, 1)->size())->collect( _indx | Sequence{_indx-1, (As, 1)->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let a : OclAny = _tuple->at(2) in (a - i)) ; var m : int := ("" + ((median(nums))))->toInteger() ; execute ((nums->select(a | true)->collect(a | ((a - m)->abs())))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,*a=map(int,open(0).read().split()) s=[a-i-1 for i,a in enumerate(a)] b=sorted(s)[n//2] print(sum(abs(s-b)for s in s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let a : OclAny = _tuple->at(2) in (a - i - 1)) ; var b : OclAny := sorted(s)[n div 2+1] ; execute (((argument (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name s))) - (expr (atom (name b))))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name s))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) b=[0] c=[0] d=[0] e=[0] count=0 count2=0 count3=0 count4=0 for i in range(n): a[i]-=i a.sort() for i in range(n-1): count+=a[i+1]-a[i] count3+=a[n-i-1]-a[n-i-2] b.append(count) d.append(count3) for i in range(n-1): count2+=b[i+1] count4+=d[i+1] c.append(count2) e.append(count4) ans=10**18 for i in range(n): ans=min(ans,c[-1]-c[i]-b[i]*(n-i-1)+e[-1]-e[n-i-1]-d[n-i-1]*i) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := Sequence{ 0 } ; var c : Sequence := Sequence{ 0 } ; var d : Sequence := Sequence{ 0 } ; var e : Sequence := Sequence{ 0 } ; var count : int := 0 ; var count2 : int := 0 ; var count3 : int := 0 ; var count4 : int := 0 ; for i : Integer.subrange(0, n-1) do ( a[i+1] := a[i+1] - i) ; a := a->sort() ; for i : Integer.subrange(0, n - 1-1) do ( count := count + a[i + 1+1] - a[i+1] ; count3 := count3 + a[n - i - 1+1] - a[n - i - 2+1] ; execute ((count) : b) ; execute ((count3) : d)) ; for i : Integer.subrange(0, n - 1-1) do ( count2 := count2 + b[i + 1+1] ; count4 := count4 + d[i + 1+1] ; execute ((count2) : c) ; execute ((count4) : e)) ; var ans : double := (10)->pow(18) ; for i : Integer.subrange(0, n-1) do ( ans := Set{ans, c->last() - c[i+1] - b[i+1] * (n - i - 1) + e->last() - e[n - i - 1+1] - d[n - i - 1+1] * i}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import statistics NN=int(input()) AA=list(map(int,input().split())) BB=[0]*NN for nn in range(1,NN+1): BB[nn-1]=AA[nn-1]-nn MBB=statistics.median(BB) CC=list(map(lambda x : x-MBB,BB)) ACC=list(map(lambda x : abs(x),CC)) ANS=sum(ACC) print(int(ANS)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var NN : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var AA : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var BB : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, NN) ; for nn : Integer.subrange(1, NN + 1-1) do ( BB[nn - 1+1] := AA[nn - 1+1] - nn) ; var MBB : double := statistics.median(BB) ; var CC : Sequence := ((BB)->collect( _x | (lambda x : OclAny in (x - MBB))->apply(_x) )) ; var ACC : Sequence := ((CC)->collect( _x | (lambda x : OclAny in ((x)->abs()))->apply(_x) )) ; var ANS : OclAny := (ACC)->sum() ; execute (("" + ((ANS)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=[int(item)for item in input().split()] p_num=[] pb_num=[] for i in range(n+1): if i==0 : p_num.append(1) pb_num.append(1) else : p_num.append(p_num[-1]*2+1) pb_num.append(pb_num[-1]*2+3) def get_p_num(n,x): if n==0 and x==1 : return 1 if x==1 : return 0 elif x<(pb_num[n]+1)//2 : return get_p_num(n-1,x-1) elif x==(pb_num[n]+1)//2 : return p_num[n-1]+1 elif xselect(item | true)->collect(item | (("" + ((item)))->toInteger())) ; var p_num : Sequence := Sequence{} ; var pb_num : Sequence := Sequence{} ; for i : Integer.subrange(0, n + 1-1) do ( if i = 0 then ( execute ((1) : p_num) ; execute ((1) : pb_num) ) else ( execute ((p_num->last() * 2 + 1) : p_num) ; execute ((pb_num->last() * 2 + 3) : pb_num) )) ; skip ; execute (get_p_num(n, x))->display(); operation get_p_num(n : OclAny, x : OclAny) : OclAny pre: true post: true activity: if n = 0 & x = 1 then ( return 1 ) else skip ; if x = 1 then ( return 0 ) else (if (x->compareTo((pb_num[n+1] + 1) div 2)) < 0 then ( return get_p_num(n - 1, x - 1) ) else (if x = (pb_num[n+1] + 1) div 2 then ( return p_num[n - 1+1] + 1 ) else (if (x->compareTo(pb_num[n+1])) < 0 then ( return p_num[n - 1+1] + 1 + get_p_num(n - 1, x - pb_num[n - 1+1] - 2) ) else ( return p_num[n - 1+1] * 2 + 1 ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,input().split()) binom=[[1 if j==0 else 0 for j in range(K+1)]for i in range(N+1)] for i in range(1,N+1): for j in range(1,K+1): binom[i][j]=binom[i-1][j-1]+binom[i-1][j] for i in range(1,K+1): print(binom[K-1][i-1]*binom[N-K+1][i]%(10**9+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var binom : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, K + 1-1)->select(j | true)->collect(j | (if j = 0 then 1 else 0 endif)))) ; for i : Integer.subrange(1, N + 1-1) do ( for j : Integer.subrange(1, K + 1-1) do ( binom[i+1][j+1] := binom[i - 1+1][j - 1+1] + binom[i - 1+1][j+1])) ; for i : Integer.subrange(1, K + 1-1) do ( execute (binom[K - 1+1][i - 1+1] * binom[N - K + 1+1][i+1] mod ((10)->pow(9) + 7))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys MOD=10**9+7 def sinput(): return sys.stdin.readline().strip() def iinput(): return int(sinput()) def imap(): return map(int,sinput().split()) def fmap(): return map(float,sinput().split()) def iarr(n=0): if n : return[0 for _ in range(n)] else : return list(imap()) def farr(): return list(fmap()) def sarr(n=0): if n : return["" for _ in range(n)] else : return sinput().split() def barr(n): return[False for _ in range(n)] def adj(n): return[[]for _ in range(n)] def inv(a): return pow(a,MOD-2,MOD) def comb(n,r): ans=1 for i in range(r): ans*=n-i ; ans*=inv(r-i); ans %=MOD return ans n,k=imap() ans=n-k+1 print(ans) for i in range(2,k+1): ans*=(n-k-i+2)*(k-i+1)*inv(i)*inv(i-1) print(ans % MOD) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var k : OclAny := null; Sequence{n,k} := imap() ; ans := n - k + 1 ; execute (ans)->display() ; for i : Integer.subrange(2, k + 1-1) do ( ans := ans * (n - k - i + 2) * (k - i + 1) * inv(i) * inv(i - 1) ; execute (ans mod MOD)->display()); operation sinput() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation iinput() : OclAny pre: true post: true activity: return ("" + ((sinput())))->toInteger(); operation imap() : OclAny pre: true post: true activity: return (sinput().split())->collect( _x | (OclType["int"])->apply(_x) ); operation fmap() : OclAny pre: true post: true activity: return (sinput().split())->collect( _x | (OclType["double"])->apply(_x) ); operation iarr(n : int) : OclAny pre: true post: true activity: if n->oclIsUndefined() then n := 0 else skip; if n then ( return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)) ) else ( return (imap()) ); operation farr() : OclAny pre: true post: true activity: return (fmap()); operation sarr(n : int) : OclAny pre: true post: true activity: if n->oclIsUndefined() then n := 0 else skip; if n then ( return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ("")) ) else ( return sinput().split() ); operation barr(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (false)); operation adj(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})); operation inv(a : OclAny) : OclAny pre: true post: true activity: return (a)->pow(MOD - 2); operation comb(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: var ans : int := 1 ; for i : Integer.subrange(0, r-1) do ( ans := ans * n - i; ans := ans * inv(r - i); ans := ans mod MOD) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cmb(n,r,mod): if(r<0 or r>n): return 0 r=min(r,n-r) return g1[n]*g2[r]*g2[n-r]% mod n,k=[int(_)for _ in input().split()] mod=10**9+7 N=n g1=[1,1] g2=[1,1] inverse=[0,1] for i in range(2,N+1): g1.append((g1[-1]*i)% mod) inverse.append((-inverse[mod % i]*(mod//i))% mod) g2.append((g2[-1]*inverse[-1])% mod) for i in range(1,k+1): ans=(cmb(k-1,i-1,mod)*cmb(n-k+1,i,mod))% mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var k : OclAny := null; Sequence{n,k} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; mod := (10)->pow(9) + 7 ; var N : OclAny := n ; var g1 : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var g2 : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var inverse : Sequence := Sequence{0}->union(Sequence{ 1 }) ; for i : Integer.subrange(2, N + 1-1) do ( execute (((g1->last() * i) mod mod) : g1) ; execute (((-inverse[mod mod i+1] * (mod div i)) mod mod) : inverse) ; execute (((g2->last() * inverse->last()) mod mod) : g2)) ; for i : Integer.subrange(1, k + 1-1) do ( var ans : int := (cmb(k - 1, i - 1, mod) * cmb(n - k + 1, i, mod)) mod mod ; execute (ans)->display()); operation cmb(n : OclAny, r : OclAny, mod : OclAny) : OclAny pre: true post: true activity: if (r < 0 or (r->compareTo(n)) > 0) then ( return 0 ) else skip ; r := Set{r, n - r}->min() ; return g1[n+1] * g2[r+1] * g2[n - r+1] mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : h,w=map(int,input().split()) if h==w==0 : break mp={} for r in range(h): s=input() for c in range(w): mp[s[c]]=[r,c] s=input() now=[0,0] ans=0 for i in range(len(s)): to=mp[s[i]] ans+=abs(now[0]-to[0])+abs(now[1]-to[1])+1 now=to print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if h = w & (w == 0) then ( break ) else skip ; var mp : OclAny := Set{} ; for r : Integer.subrange(0, h-1) do ( var s : String := (OclFile["System.in"]).readLine() ; for c : Integer.subrange(0, w-1) do ( mp[s[c+1]+1] := Sequence{r}->union(Sequence{ c }))) ; s := (OclFile["System.in"]).readLine() ; var now : Sequence := Sequence{0}->union(Sequence{ 0 }) ; var ans : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( var to : OclAny := mp[s[i+1]+1] ; ans := ans + (now->first() - to->first())->abs() + (now[1+1] - to[1+1])->abs() + 1 ; now := to) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import factorial import sys input=sys.stdin.readline class AtCoder : def main(self): N,K=map(int,input().split()) M=N-K for i in range(1,K+1): if M+1exists( _x | result = _x ); operation main() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var M : double := N - K ; for i : Integer.subrange(1, K + 1-1) do ( if (M + 1->compareTo(i)) < 0 then ( execute (0)->display() ) else ( var a : OclAny := self.combinations_count(M + 1, i) ; var b : OclAny := self.grouping_0_ng(K, i) ; execute ((b * a) mod ((10)->pow(9) + 7))->display() )); operation combinations_count(n : OclAny,r : OclAny) : OclAny pre: true post: true activity: n := n ; return factorial(n) div (factorial(n - r) * factorial(r)); operation grouping_0_ng(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: return self.groupint_0_ok(x - y, y); operation groupint_0_ok(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: return self.combinations_count(x + y - 1, y - 1); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = '__main__' then ( (expr (atom (name AtCoder)) (trailer (arguments ( ))) (trailer . (name main) (arguments ( )))) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from operator import mul from functools import reduce from functools import lru_cache @ lru_cache(maxsize=1000) def cmb(n,r): r=min(n-r,r) if r==0 : return 1 over=reduce(mul,range(n,n-r,-1)) under=reduce(mul,range(1,r+1)) return over//under N,K=map(int,input().split()) R=N-K print(R+1) for i in range(2,K+1): if R+1collect( _x | (OclType["int"])->apply(_x) ) ; var R : double := N - K ; execute (R + 1)->display() ; for i : Integer.subrange(2, K + 1-1) do ( if (R + 1->compareTo(i)) < 0 then ( execute (0)->display() ; continue ) else skip ; var tmp : OclAny := cmb(R + 1, i) ; var tmp2 : OclAny := cmb(K - 1, K - i) ; execute ((tmp mod ((10)->pow(9) + 7) * tmp2 mod ((10)->pow(9) + 7)) mod ((10)->pow(9) + 7))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def minPerimeter(n): l=math.sqrt(n) sq=l*l if(sq==n): return l*4 else : row=n/l perimeter=2*(l+row) if(n % l!=0): perimeter+=2 return perimeter n=10 print(int(minPerimeter(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 10 ; execute (("" + ((minPerimeter(n))))->toInteger())->display(); operation minPerimeter(n : OclAny) : OclAny pre: true post: true activity: var l : double := (n)->sqrt() ; var sq : double := l * l ; if (sq = n) then ( return l * 4 ) else ( var row : double := n / l ; var perimeter : double := 2 * (l + row) ; if (n mod l /= 0) then ( perimeter := perimeter + 2 ) else skip ; return perimeter ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self): self.key=0 self.left=None self.right=None def newNode(key : int)->Node : temp=Node() temp.key=key temp.left=None temp.right=None return temp def inorder(root : Node): if root is not None : inorder(root.left) print(root.key,end=" ") inorder(root.right) def createTree(parent : list,n : int)->Node : m=dict() root=Node() for i in range(n): if i not in m : temp=newNode(i) m[i]=temp if parent[i]==-1 : root=m[i] elif parent[i]not in m : temp=newNode(parent[i]) temp.left=m[i] m[parent[i]]=temp else : if m[parent[i]].left is None : m[parent[i]].left=m[i] else : m[parent[i]].right=m[i] return root if __name__=="__main__" : parent=[-1,0,0,1,1,3,5] n=len(parent) root=createTree(parent,n) print("Inorder Traversal of constructed tree") inorder(root) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute key : int := 0; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise() : Node pre: true post: true activity: self.key := 0 ; self.left := null ; self.right := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( var parent : Sequence := Sequence{-1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{3}->union(Sequence{ 5 })))))) ; var n : int := (parent)->size() ; root := createTree(parent, n) ; execute ("Inorder Traversal of constructed tree")->display() ; inorder(root) ) else skip; operation newNode(key : int) : OclAny pre: true post: true activity: var temp : Node := (Node.newNode()).initialise() ; temp.key := key ; temp.left := null ; temp.right := null ; return temp; operation inorder(root : Node) pre: true post: true activity: if not(root <>= null) then ( inorder(root.left) ; execute (root.key)->display() ; inorder(root.right) ) else skip; operation createTree(parent : Sequence(OclAny), n : int) : OclAny pre: true post: true activity: var m : Map := (arguments ( )) ; var root : Node := (Node.newNode()).initialise() ; for i : Integer.subrange(0, n-1) do ( if (m)->excludes(i) then ( temp := newNode(i) ; m[i+1] := temp ) else skip ; if parent[i+1] = -1 then ( root := m[i+1] ) else (if (m)->excludes(parent[i+1]) then ( temp := newNode(parent[i+1]) ; temp.left := m[i+1] ; m[parent[i+1]+1] := temp ) else ( if m[parent[i+1]+1].left <>= null then ( m[parent[i+1]+1].left := m[i+1] ) else ( m[parent[i+1]+1].right := m[i+1] ) ) ) ) ; return root; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=sorted(list(map(int,input().split()))) t=int(input()) result=0 for x in range(n): for y in range(n): if abs(l[x]-l[y])<=t : result=max(result,(y-x)+1) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var result : int := 0 ; for x : Integer.subrange(0, n-1) do ( for y : Integer.subrange(0, n-1) do ( if ((l[x+1] - l[y+1])->abs()->compareTo(t)) <= 0 then ( result := Set{result, (y - x) + 1}->max() ) else skip)) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(x)for x in str(input()).split()] t=int(input()) count=0 cnt=0 c=0 a.sort() for i in range(n): c=a[i]+t j=i while j=a[j]: count+=1 j+=1 if cnttoInteger() ; var a : Sequence := OclType["String"]((OclFile["System.in"]).readLine()).split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := 0 ; var cnt : int := 0 ; var c : int := 0 ; a := a->sort() ; for i : Integer.subrange(0, n-1) do ( c := a[i+1] + t ; var j : OclAny := i ; while (j->compareTo((a)->size())) < 0 & (c->compareTo(a[j+1])) >= 0 do ( count := count + 1 ; j := j + 1) ; if (cnt->compareTo(count)) < 0 then ( cnt := count ) else skip ; count := 0) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(arr,k,T): pass def solve1(n,arr,T): dp=[0]*1001 for i in arr : for j in range(i,max(i-T-1,-1),-1): dp[j]+=1 ans=max(range(1001),key=dp.__getitem__) return dp[ans] def solve(n,ans,T): l=0 r=n ans=0 while l<=r : mid=l+(r-l)//2 if check(arr,mid,T): l=mid+1 ans=mid else : r=mid-1 return ans if __name__=="__main__" : n=int(input()) arr=list(map(int,input().rstrip().split())) T=int(input()) ans=solve1(n,arr,T) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; arr := ((input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; T := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; ans := solve1(n, arr, T) ; execute (ans)->display() ) else skip; operation check(arr : OclAny, k : OclAny, T : OclAny) pre: true post: true activity: skip; operation solve1(n : OclAny, arr : OclAny, T : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 1001) ; for i : arr do ( for j : Integer.subrange(Set{i - T - 1, -1}->max() + 1, i)->reverse() do ( dp[j+1] := dp[j+1] + 1)) ; var ans : OclAny := Set{Integer.subrange(0, 1001-1), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name dp)) (trailer . (name __getitem__)))))))}->max() ; return dp[ans+1]; operation solve(n : OclAny, ans : OclAny, T : OclAny) : OclAny pre: true post: true activity: var l : int := 0 ; var r : OclAny := n ; ans := 0 ; while (l->compareTo(r)) <= 0 do ( var mid : int := l + (r - l) div 2 ; if check(arr, mid, T) then ( l := mid + 1 ; ans := mid ) else ( r := mid - 1 )) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,tan,asin,acos,atan,radians,degrees,log2,gcd from itertools import accumulate,permutations,combinations,combinations_with_replacement,product,groupby from operator import itemgetter,mul from copy import deepcopy from string import ascii_lowercase,ascii_uppercase,digits from bisect import bisect,bisect_left,insort,insort_left from heapq import heappush,heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) def ZIP(n): return zip(*(MAP()for _ in range(n))) sys.setrecursionlimit(10**9) INF=float('inf') mod=10**9+7 from decimal import* N,X=MAP() p=[0]*(N+1) p[0]=1 q=[0]*(N+1) q[0]=1 for i in range(1,N+1): p[i]=2*p[i-1]+1 q[i]=2*q[i-1]+3 ans=0 i=N while 0pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; skip ; var N : OclAny := null; var X : OclAny := null; Sequence{N,X} := MAP() ; var p : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; p->first() := 1 ; var q : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; q->first() := 1 ; for i : Integer.subrange(1, N + 1-1) do ( p[i+1] := 2 * p[i - 1+1] + 1 ; q[i+1] := 2 * q[i - 1+1] + 3) ; var ans : int := 0 ; var i : OclAny := N ; while 0 < X do ( while 0 < X & (X < q[i+1]) do ( i := i - 1 ; X := X - 1) ; if 0 < X then ( X := X - q[i+1] ; ans := ans + p[i+1] ) else skip ; if 0 < X then ( X := X - 1 ; ans := ans + 1 ) else skip) ; execute (ans)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ZIP(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))`third->at(_indx)} ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) n=int(input()) arr=sorted(R()) gap=int(input()) j=0 res=0 for i in range(n): while arr[i]-arr[j]>gap : j+=1 res=max(res,i-j+1) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := R->apply()->sort() ; var gap : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var j : int := 0 ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( while (arr[i+1] - arr[j+1]->compareTo(gap)) > 0 do ( j := j + 1) ; res := Set{res, i - j + 1}->max()) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=list(map(int,input().split())) t=int(input()) p.sort() ans=0 i=0 for j in range(n): while p[j]-p[i]>t : i=i+1 ans=max(ans,j-i+1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; p := p->sort() ; var ans : int := 0 ; var i : int := 0 ; for j : Integer.subrange(0, n-1) do ( while (p[j+1] - p[i+1]->compareTo(t)) > 0 do ( i := i + 1) ; ans := Set{ans, j - i + 1}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def judge(r): pa=pb=0 for c in r[1 :]: if c=="A" : pa+=1 else : pb+=1 if patail() do ( if c = "A" then ( pa := pa + 1 ) else ( pb := pb + 1 )) ; if (pa->compareTo(pb)) < 0 then ( execute (pa)->display() ) else ( execute (pa + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- pref=[0]*100001 def checkArmstrong(x): n=len(str(x)) sum1=0 temp=x while temp>0 : digit=temp % 10 sum1+=digit**n temp//=10 if sum1==x : return x return 0 def preCompute(): for i in range(1,100001): pref[i]=pref[i-1]+checkArmstrong(i) def printSum(L,R): print(pref[R]-pref[L-1]) def printSumarmstrong(arr,Q): preCompute() for i in range(Q): printSum(arr[i][0],arr[i][1]) Q=2 arr=[[1,13],[121,211]] printSumarmstrong(arr,Q) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var pref : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100001) ; skip ; skip ; skip ; skip ; Q := 2 ; arr := Sequence{Sequence{1}->union(Sequence{ 13 })}->union(Sequence{ Sequence{121}->union(Sequence{ 211 }) }) ; printSumarmstrong(arr, Q); operation checkArmstrong(x : OclAny) : OclAny pre: true post: true activity: var n : int := (("" + ((x))))->size() ; var sum1 : int := 0 ; var temp : OclAny := x ; while temp > 0 do ( var digit : int := temp mod 10 ; sum1 := sum1 + (digit)->pow(n) ; temp := temp div 10) ; if sum1 = x then ( return x ) else skip ; return 0; operation preCompute() pre: true post: true activity: for i : Integer.subrange(1, 100001-1) do ( pref[i+1] := pref[i - 1+1] + checkArmstrong(i)); operation printSum(L : OclAny, R : OclAny) pre: true post: true activity: execute (pref[R+1] - pref[L - 1+1])->display(); operation printSumarmstrong(arr : OclAny, Q : OclAny) pre: true post: true activity: preCompute() ; for i : Integer.subrange(0, Q-1) do ( printSum(arr[i+1]->first(), arr[i+1][1+1])); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,v=map(int,input().split()) arr=list(map(int,input().strip().split()))[: n] brr=list(map(int,input().strip().split()))[: n] mn=10000000000000 for i in range(n): mn=min(mn,brr[i]/arr[i]) sum=0 for i in range(n): sum=sum+arr[i]*mn if sum>v : print(v) else : print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var v : OclAny := null; Sequence{n,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : OclAny := OclType["Sequence"]((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ; var brr : OclAny := OclType["Sequence"]((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ; var mn : int := 10000000000000 ; for i : Integer.subrange(0, n-1) do ( mn := Set{mn, brr[i+1] / arr[i+1]}->min()) ; var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + arr[i+1] * mn) ; if (sum->compareTo(v)) > 0 then ( execute (v)->display() ) else ( execute (sum)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,v=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) e=sum(a) l=0 ; r=v eps=10**(-9) while r-l>eps : m=(r+l)/2 for i in range(n): if a[i]*m/e>b[i]: r=m break else : l=m print("%.8f" % r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var v : OclAny := null; Sequence{n,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var e : OclAny := (a)->sum() ; var l : int := 0; var r : OclAny := v ; var eps : double := (10)->pow((-9)) ; while (r - l->compareTo(eps)) > 0 do ( var m : double := (r + l) / 2 ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) * (expr (atom (name m)))) / (expr (atom (name e))))) > (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name r)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name m)))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name m)))))))))))))))) ; execute (StringLib.format("%.8f",r))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input().split() n=int(I[0]) V=int(I[1]) a=input().split() b=input().split() s=0 for i in a : s+=int(i) xmax=V/s mi=101 for i in range(n): if int(b[i])/int(a[i])=xmax : x=xmax else : x=mi print(format(x*s,".6f")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input().split() ; var n : int := ("" + ((I->first())))->toInteger() ; var V : int := ("" + ((I[1+1])))->toInteger() ; var a : OclAny := input().split() ; var b : OclAny := input().split() ; var s : int := 0 ; for i : a do ( s := s + ("" + ((i)))->toInteger()) ; var xmax : double := V / s ; var mi : int := 101 ; for i : Integer.subrange(0, n-1) do ( if (("" + ((b[i+1])))->toInteger() / ("" + ((a[i+1])))->toInteger()->compareTo(mi)) < 0 then ( mi := ("" + ((b[i+1])))->toInteger() / ("" + ((a[i+1])))->toInteger() ) else skip) ; if (mi->compareTo(xmax)) >= 0 then ( var x : OclAny := xmax ) else ( x := mi ) ; execute ((x * s + ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,V=list(map(float,input().split(" "))) a=list(map(int,input().split(" "))) b=list(map(float,input().split(" "))) minB=min(b) if minB==0 : print(0) else : x=b[0]/a[0] for i,j in enumerate(a): if x>b[i]/a[i]: x=b[i]/a[i] output=sum(a)*x print(min(output,V)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var V : OclAny := null; Sequence{n,V} := ((input().split(" "))->collect( _x | (OclType["double"])->apply(_x) )) ; var a : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split(" "))->collect( _x | (OclType["double"])->apply(_x) )) ; var minB : OclAny := (b)->min() ; if minB = 0 then ( execute (0)->display() ) else ( var x : double := b->first() / a->first() ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if (x->compareTo(b[i+1] / a[i+1])) > 0 then ( x := b[i+1] / a[i+1] ) else skip) ; var output : double := (a)->sum() * x ; execute (Set{output, V}->min())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,v=map(int,input().split()) arr=list(map(int,input().strip().split()))[: n] brr=list(map(int,input().strip().split()))[: n] mn=10000000000000 for i in range(n): mn=min(mn,brr[i]/arr[i]) sum=0 for i in range(n): sum=sum+arr[i]*mn if sum>v : print(v) else : print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var v : OclAny := null; Sequence{n,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : OclAny := OclType["Sequence"]((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ; var brr : OclAny := OclType["Sequence"]((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ; var mn : int := 10000000000000 ; for i : Integer.subrange(0, n-1) do ( mn := Set{mn, brr[i+1] / arr[i+1]}->min()) ; var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + arr[i+1] * mn) ; if (sum->compareTo(v)) > 0 then ( execute (v)->display() ) else ( execute (sum)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def checkPrime(number): if(len(number)==0): return True num=int(number) for i in range(2,int(sqrt(num))+1,1): if((num % i)==0): return False return True def splitIntoPrimes(number): numLen=len(number) splitDP=[-1 for i in range(numLen+1)] for i in range(1,numLen+1,1): if(i<=6 and checkPrime(number[0 : i])): splitDP[i]=1 if(splitDP[i]!=-1): j=1 while(j<=6 and i+j<=numLen): if(checkPrime(number[i : i+j])): if(splitDP[i+j]==-1): splitDP[i+j]=1+splitDP[i] else : splitDP[i+j]=min(splitDP[i+j],1+splitDP[i]) j+=1 return splitDP[numLen] if __name__=='__main__' : print(splitIntoPrimes("13499315")) print(splitIntoPrimes("43")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( execute (splitIntoPrimes("13499315"))->display() ; execute (splitIntoPrimes("43"))->display() ) else skip; operation checkPrime(number : OclAny) : OclAny pre: true post: true activity: if ((number)->size() = 0) then ( return true ) else skip ; var num : int := ("" + ((number)))->toInteger() ; for i : Integer.subrange(2, ("" + ((sqrt(num))))->toInteger() + 1-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if ((num mod i) = 0) then ( return false ) else skip) ; return true; operation splitIntoPrimes(number : OclAny) : OclAny pre: true post: true activity: var numLen : int := (number)->size() ; var splitDP : Sequence := Integer.subrange(0, numLen + 1-1)->select(i | true)->collect(i | (-1)) ; for i : Integer.subrange(1, numLen + 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if (i <= 6 & checkPrime(number.subrange(0+1, i))) then ( splitDP[i+1] := 1 ) else skip ; if (splitDP[i+1] /= -1) then ( var j : int := 1 ; while (j <= 6 & (i + j->compareTo(numLen)) <= 0) do ( if (checkPrime(number.subrange(i+1, i + j))) then ( if (splitDP[i + j+1] = -1) then ( splitDP[i + j+1] := 1 + splitDP[i+1] ) else ( splitDP[i + j+1] := Set{splitDP[i + j+1], 1 + splitDP[i+1]}->min() ) ) else skip ; j := j + 1) ) else skip) ; return splitDP[numLen+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def squareFree(n): cnt=0 ; i=1 ; while(True): isSqFree=True ; j=2 ; while(j*j<=i): if(i %(j*j)==0): isSqFree=False ; break ; j+=1 ; if(isSqFree==True): cnt+=1 ; if(cnt==n): return i ; i+=1 ; return 0 ; n=10 ; print(squareFree(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 10; ; execute (squareFree(n))->display();; operation squareFree(n : OclAny) pre: true post: true activity: var cnt : int := 0; ; var i : int := 1; ; while (true) do ( var isSqFree : boolean := true; ; var j : int := 2; ; while ((j * j->compareTo(i)) <= 0) do ( if (i mod (j * j) = 0) then ( isSqFree := false; ; break; ) else skip ; j := j + 1;) ; if (isSqFree = true) then ( cnt := cnt + 1; ; if (cnt = n) then ( return i; ) else skip ) else skip ; i := i + 1;) ; return 0;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count_b(n): return 2**(n+2)-3 def count_p(n): return 2**(n+1)-1 def solve(n,x): if x<=0 : return 0 if n==0 : return 1 b=count_b(n-1) if x<(b+1): return solve(n-1,x-1) return count_p(n-1)+(1 if x>=(b+2)else 0)+solve(n-1,x-b-2) def main(): n,x=list(map(int,input().split())) print(solve(n,x)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation count_b(n : OclAny) : OclAny pre: true post: true activity: return (2)->pow((n + 2)) - 3; operation count_p(n : OclAny) : OclAny pre: true post: true activity: return (2)->pow((n + 1)) - 1; operation solve(n : OclAny, x : OclAny) : OclAny pre: true post: true activity: if x <= 0 then ( return 0 ) else skip ; if n = 0 then ( return 1 ) else skip ; var b : OclAny := count_b(n - 1) ; if (x->compareTo((b + 1))) < 0 then ( return solve(n - 1, x - 1) ) else skip ; return count_p(n - 1) + (if (x->compareTo((b + 2))) >= 0 then 1 else 0 endif) + solve(n - 1, x - b - 2); operation main() pre: true post: true activity: Sequence{n,x} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (solve(n, x))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def validate(n): for i in range(10): temp=n ; count=0 ; while(temp): if(temp % 10==i): count+=1 ; if(count>i): return-1 ; temp//=10 ; return 1 ; n=1552793 ; geek="True" if validate(n)else "False" ; print(geek); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 1552793; ; var geek : String := if validate(n) then "True" else "False" endif; ; execute (geek)->display();; operation validate(n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, 10-1) do ( var temp : OclAny := n; ; var count : int := 0; ; while (temp) do ( if (temp mod 10 = i) then ( count := count + 1; ) else skip ; if ((count->compareTo(i)) > 0) then ( return -1; ) else skip ; temp := temp div 10;)) ; return 1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : H,W=map(int,input().split()) if H==0 : break P={} for i in range(H): r=input() for j,c in enumerate(r): P[c]=(i,j) S=input() ans=len(S) px=0 ; py=0 for c in S : x,y=P[c] ans+=abs(x-px)+abs(y-py) px=x ; py=y print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if H = 0 then ( break ) else skip ; var P : OclAny := Set{} ; for i : Integer.subrange(0, H-1) do ( var r : String := (OclFile["System.in"]).readLine() ; for _tuple : Integer.subrange(1, (r)->size())->collect( _indx | Sequence{_indx-1, (r)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); P[c+1] := Sequence{i, j})) ; var S : String := (OclFile["System.in"]).readLine() ; var ans : int := (S)->size() ; var px : int := 0; var py : int := 0 ; for c : S->characters() do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := P[c+1] ; ans := ans + (x - px)->abs() + (y - py)->abs() ; px := x; py := y) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sackRace(p1,s1,p2,s2): return((s1>s2 and(p2-p1)%(s1-s2)==0)or(s2>s1 and(p1-p2)%(s2-s1)==0)) p1=4 s1=4 p2=8 s2=2 if(sackRace(p1,s1,p2,s2)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; p1 := 4 ; s1 := 4 ; p2 := 8 ; s2 := 2 ; if (sackRace(p1, s1, p2, s2)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation sackRace(p1 : OclAny, s1 : OclAny, p2 : OclAny, s2 : OclAny) : OclAny pre: true post: true activity: return (((s1->compareTo(s2)) > 0 & (p2 - p1) mod (s1 - s2) = 0) or ((s2->compareTo(s1)) > 0 & (p1 - p2) mod (s2 - s1) = 0)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,Q=map(int,input().split()) b_num=2**(n-1).bit_length() mx=10**9 segl=[mx]*2*b_num def update(k,x): k+=b_num-1 segl[k]=x while k+1 : k=(k-1)//2 segl[k]=min(segl[k*2+1],segl[k*2+2]) if __name__=='__main__' : xs=[] for i in range(n): s,t,x=map(int,input().split()) xs+=[(s-x,True,x,i),(t-x,False,x,i)] qs=[] for _ in range(Q): qs.append(int(input())) xs.sort(key=lambda x : x[0]) j=0 for x in xs : while Q-j : if qs[j]collect( _x | (OclType["int"])->apply(_x) ) ; var b_num : double := (2)->pow((n - 1).bit_length()) ; var mx : double := (10)->pow(9) ; var segl : Sequence := MatrixLib.elementwiseMult(MatrixLib.elementwiseMult(Sequence{ mx }, 2), b_num) ; skip ; if __name__ = '__main__' then ( var xs : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var s : OclAny := null; var t : OclAny := null; Sequence{s,t,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; xs := xs + Sequence{Sequence{s - x, true, x, i}}->union(Sequence{ Sequence{t - x, false, x, i} })) ; var qs : Sequence := Sequence{} ; for _anon : Integer.subrange(0, Q-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : qs)) ; xs := xs->sort() ; var j : int := 0 ; for x : xs do ( while Q - j do ( if (qs[j+1]->compareTo(x->first())) < 0 then ( execute (if segl->first() /= mx then segl->first() else -1 endif)->display() ; j := j + 1 ; continue ) else skip ; break) ; update(x[3+1], if x[1+1] then x[2+1] else mx endif)) ; while Q - j do ( execute (-1)->display() ; j := j + 1) ) else skip; operation update(k : OclAny, x : OclAny) pre: true post: true activity: k := k + b_num - 1 ; segl[k+1] := x ; while k + 1 do ( k := (k - 1) div 2 ; segl[k+1] := Set{segl[k * 2 + 1+1], segl[k * 2 + 2+1]}->min()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**7) INF=10**18 MOD=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LLI(): return[int(x)for x in sys.stdin.readlines()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return input() from bisect import bisect_left def main(): N,Q=LI() XST=[] for _ in range(N): s,t,x=LI() XST.append([x,s,t]) XST.sort() D=LLI() ans=[-1]*Q nexts=[-1]*Q for x,s,t in XST : i=bisect_left(D,s-x) end=bisect_left(D,t-x) to=end while topow(7)) ; var INF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; main(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LLI() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readlines()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation SI() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation main() pre: true post: true activity: var N : OclAny := null; var Q : OclAny := null; Sequence{N,Q} := LI() ; var XST : Sequence := Sequence{} ; for _anon : Integer.subrange(0, N-1) do ( var s : OclAny := null; var t : OclAny := null; var x : OclAny := null; Sequence{s,t,x} := LI() ; execute ((Sequence{x}->union(Sequence{s}->union(Sequence{ t }))) : XST)) ; XST := XST->sort() ; var D : OclAny := LLI() ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, Q) ; var nexts : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, Q) ; for _tuple : XST do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); var i : OclAny := bisect_left(D, s - x) ; var end : OclAny := bisect_left(D, t - x) ; var to : OclAny := end ; while (to->compareTo(Q)) < 0 & nexts[to+1] /= -1 do ( to := nexts[to+1]) ; while (i->compareTo(end)) < 0 do ( if nexts[i+1] = -1 then ( ans[i+1] := x ; nexts[i+1] := to ; i := i + 1 ) else ( i := nexts[i+1] ))) ; for y : ans do ( execute (y)->display()) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,itertools,collections,bisect input=lambda : sys.stdin.buffer.readline().rstrip().decode('utf-8') from heapq import heappush,heappop n,q=map(int,input().split()) STX=[tuple(map(int,input().split()))for i in range(n)] D=[int(input())for i in range(q)] event=[] for si,ti,xi in STX : event.append((si-xi,0,xi)) event.append((ti-xi,-1,xi)) for di in D : event.append((di,1,di)) event.sort() hq=[]; S=set() for time,query,number in event : if query==0 : heappush(hq,number) S.add(number) elif query==-1 : S.remove(number) else : while hq and hq[0]not in S : heappop(hq) if not hq : print(-1) else : print(hq[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.buffer.readLine().rstrip().decode('utf-8')) ; skip ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var STX : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var D : Sequence := Integer.subrange(0, q-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var event : Sequence := Sequence{} ; for _tuple : STX do (var _indx : int := 1; var si : OclAny := _tuple->at(_indx); _indx := _indx + 1; var ti : OclAny := _tuple->at(_indx); _indx := _indx + 1; var xi : OclAny := _tuple->at(_indx); execute ((Sequence{si - xi, 0, xi}) : event) ; execute ((Sequence{ti - xi, -1, xi}) : event)) ; for di : D do ( execute ((Sequence{di, 1, di}) : event)) ; event := event->sort() ; var hq : Sequence := Sequence{}; var S : Set := Set{}->union(()) ; for _tuple : event do (var _indx : int := 1; var time : OclAny := _tuple->at(_indx); _indx := _indx + 1; var query : OclAny := _tuple->at(_indx); _indx := _indx + 1; var number : OclAny := _tuple->at(_indx); if query = 0 then ( heappush(hq, number) ; execute ((number) : S) ) else (if query = -1 then ( execute ((number) /: S) ) else ( while hq & (S)->excludes(hq->first()) do ( heappop(hq)) ; if not(hq) then ( execute (-1)->display() ) else ( execute (hq->first())->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heappush,heappop import sys,os from __pypy__ import builders readline=sys.stdin.readline N,Q=map(int,readline().split()) qs=[0]*N for i in range(N): s,t,x=map(int,readline().split()) qs[i]=(s-x,t-x,x) qs.sort() b=builders.StringBuilder(Q*11) que=[] D=[int(readline())for i in range(Q)] j=0 for d in D : while jcollect( _x | (OclType["int"])->apply(_x) ) ; var qs : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for i : Integer.subrange(0, N-1) do ( var s : OclAny := null; var t : OclAny := null; var x : OclAny := null; Sequence{s,t,x} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; qs[i+1] := Sequence{s - x, t - x, x}) ; qs := qs->sort() ; var b : OclAny := builders.StringBuilder(Q * 11) ; var que : Sequence := Sequence{} ; var D : Sequence := Integer.subrange(0, Q-1)->select(i | true)->collect(i | (("" + ((readline())))->toInteger())) ; var j : int := 0 ; for d : D do ( while (j->compareTo(N)) < 0 & (qs[j+1]->first()->compareTo(d)) <= 0 do ( var s : OclAny := null; var t : OclAny := null; var x : OclAny := null; Sequence{s,t,x} := qs[j+1] ; heappush(que, Sequence{x, t}) ; j := j + 1) ; while que & (que->first()[1+1]->compareTo(d)) <= 0 do ( heappop(que)) ; if que then ( execute ((StringLib.format("%d\n",que->first()->first())) : b) ) else ( execute (("-1\n") : b) )) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)) (trailer . (name build) (arguments ( ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left n,q=map(int,input().split()) stx=[list(map(int,input().split()))for _ in range(n)] d=[int(input())for _ in range(q)] INF=10**9+1 stx.sort(key=lambda x : x[2]) nxt=[-1]*q ans=[-1]*q for s,t,x in stx : l=bisect_left(d,s-x) r=bisect_left(d,t-x) while lcollect( _x | (OclType["int"])->apply(_x) ) ; var stx : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var d : Sequence := Integer.subrange(0, q-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var INF : double := (10)->pow(9) + 1 ; stx := stx->sort() ; var nxt : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, q) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, q) ; for _tuple : stx do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); var l : OclAny := bisect_left(d, s - x) ; var r : OclAny := bisect_left(d, t - x) ; while (l->compareTo(r)) < 0 do ( if nxt[l+1] = -1 then ( ans[l+1] := x ; nxt[l+1] := r ; l := l + 1 ) else ( l := nxt[l+1] ))) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxAmount(M,N,seats): q=[] for i in range(M): q.append(seats[i]) ticketSold=0 ans=0 q.sort(reverse=True) while(ticketSold0): ans=ans+q[0] temp=q[0] q=q[1 :] q.append(temp-1) q.sort(reverse=True) ticketSold+=1 return ans if __name__=='__main__' : seats=[1,2,4] M=len(seats) N=3 print(maxAmount(N,M,seats)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( seats := Sequence{1}->union(Sequence{2}->union(Sequence{ 4 })) ; M := (seats)->size() ; N := 3 ; execute (maxAmount(N, M, seats))->display() ) else skip; operation maxAmount(M : OclAny, N : OclAny, seats : OclAny) : OclAny pre: true post: true activity: var q : Sequence := Sequence{} ; for i : Integer.subrange(0, M-1) do ( execute ((seats[i+1]) : q)) ; var ticketSold : int := 0 ; var ans : int := 0 ; q := q->sort() ; while ((ticketSold->compareTo(N)) < 0 & q->first() > 0) do ( ans := ans + q->first() ; var temp : OclAny := q->first() ; q := q->tail() ; execute ((temp - 1) : q) ; q := q->sort() ; ticketSold := ticketSold + 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def checkBit(pattern,arr,n): count=0 for i in range(n): if((pattern & arr[i])==pattern): count+=1 return count def largest(arr,n): v=arr v.append(2**31-1) n=n+1 res=0 for bit in range(31,-1,-1): count=checkBit(res |(1<apply(_x) ) ; var Z : Sequence := Sequence{ 0 }->union(Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | ((2)->pow((i + 2)) - 3))) ; var B : Sequence := Sequence{ 0 }->union(Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | ((2)->pow((i + 1)) - 2))) ; var P : Sequence := Sequence{ 0 }->union(Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | ((2)->pow((i + 1)) - 1))) ; var ans : int := 0 ; skip ; arg(N + 1, X) ; execute (ans)->display(); operation arg(l : OclAny, i : OclAny) : OclAny pre: true post: true activity: skip ; if l /= 0 then ( if (Z[l+1] / 2 + 1 / 2->compareTo(i)) < 0 then ( ans := ans + (1 + P[l - 1+1]) ; return arg(l - 1, i - ((Z[l+1] - 1) / 2 + 1)) ) else (if (Z[l+1] / 2 + 1 / 2->compareTo(i)) > 0 then ( return arg(l - 1, i - 1) ) else ( ans := ans + P[l - 1+1] + 1 ) ) ) else ( skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,re,sys,operator from collections import Counter,deque from operator import itemgetter from itertools import accumulate,combinations,groupby from sys import stdin,setrecursionlimit from copy import deepcopy import heapq setrecursionlimit(10**6) while 1 : h,w=map(int,stdin.readline().rstrip().split()) if(h,w)==(0,0): break a=[stdin.readline().rstrip()for _ in range(h)] s=input() nx,ny=0,0 o=0 cnt=0 for i in s : nh=0 for j in range(h): if i in a[j]: o=a[j].index(i) cnt+=(abs(nx-o)+abs(ny-nh)+1) break else : nh+=1 nx,ny=o,nh print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; setrecursionlimit((10)->pow(6)) ; while 1 do ( var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if Sequence{h, w} = Sequence{0, 0} then ( break ) else skip ; var a : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (stdin.readLine().rstrip())) ; var s : String := (OclFile["System.in"]).readLine() ; var nx : OclAny := null; var ny : OclAny := null; Sequence{nx,ny} := Sequence{0,0} ; var o : int := 0 ; var cnt : int := 0 ; for i : s->characters() do ( var nh : int := 0 ; for j : Integer.subrange(0, h-1) do ( if (a[j+1])->includes(i) then ( o := a[j+1]->indexOf(i) - 1 ; cnt := cnt + ((nx - o)->abs() + (ny - nh)->abs() + 1) ; break ) else ( nh := nh + 1 )) ; var nx : OclAny := null; var ny : OclAny := null; Sequence{nx,ny} := Sequence{o,nh}) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxDiff(arr,n): diff=[0]*(n-1) for i in range(0,n-1): diff[i]=arr[i+1]-arr[i] max_diff=diff[0] for i in range(1,n-1): if(diff[i-1]>0): diff[i]+=diff[i-1] if(max_diffunion(Sequence{2}->union(Sequence{6}->union(Sequence{3}->union(Sequence{ 100 })))) ; var size : int := (arr)->size() ; execute ("Maximum difference is")->display(); operation maxDiff(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var diff : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n - 1)) ; for i : Integer.subrange(0, n - 1-1) do ( diff[i+1] := arr[i + 1+1] - arr[i+1]) ; var max_diff : OclAny := diff->first() ; for i : Integer.subrange(1, n - 1-1) do ( if (diff[i - 1+1] > 0) then ( diff[i+1] := diff[i+1] + diff[i - 1+1] ) else skip ; if ((max_diff->compareTo(diff[i+1])) < 0) then ( max_diff := diff[i+1] ) else skip) ; return max_diff; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def y(x): return(1/(1+x*x)) def trapezoidal(a,b,n): h=(b-a)/n s=(y(a)+y(b)) i=1 while idisplay(); operation y(x : OclAny) : OclAny pre: true post: true activity: return (1 / (1 + x * x)); operation trapezoidal(a : OclAny, b : OclAny, n : OclAny) : OclAny pre: true post: true activity: var h : double := (b - a) / n ; var s : OclAny := (y(a) + y(b)) ; var i : int := 1 ; while (i->compareTo(n)) < 0 do ( s := s + 2 * y(a + i * h) ; i := i + 1) ; return ((h / 2) * s); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from string import digits,ascii_uppercase def parse(S): S+="$" cur=0 res=[] def expr(): nonlocal cur R=[]; l=0 while 1 : c=S[cur] if c in digits : v=number() if S[cur]=='(' : cur+=1 R0,l0=expr() cur+=1 l+=v*l0 R.append((v,l0,R0)) else : c=S[cur] cur+=1 l+=v R.append((v,1,[c])) elif c in ascii_uppercase : cur+=1 l+=1 R.append(c) else : break return R,l def number(): nonlocal cur v=0 while 1 : c=S[cur] if c not in digits : break v=10*v+int(c) cur+=1 return v R,l=expr() return R,l def solve(res,x): R,l=res if l<=x : return "0" cur=R while 1 : for data in cur : if isinstance(data,str): if x==0 : return data x-=1 else : v,l,R=data if xtoInteger() ; Sequence{R,l} := parse(S); res := parse(S) ; if (l->compareTo(x)) <= 0 then ( execute ("0")->display() ; continue ) else skip ; execute (solve(res, x))->display()); operation parse(S : OclAny) : OclAny pre: true post: true activity: S := S + "$" ; var cur : int := 0 ; var res : Sequence := Sequence{} ; skip ; skip ; Sequence{R,l} := expr() ; return R, l; operation solve(res : OclAny, x : OclAny) : OclAny pre: true post: true activity: Sequence{R,l} := res ; if (l->compareTo(x)) <= 0 then ( return "0" ) else skip ; cur := R ; while 1 do ( for data : cur do ( if (OclType["String"]).isInstance(data) then ( if x = 0 then ( return data ) else skip ; x := x - 1 ) else ( Sequence{v,l,R} := data ; if (x->compareTo(v * l)) < 0 then ( cur := R ; x := x mod l ; break ) else skip ; x := x - v * l ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def uncompress(text,L): newText='' pos=0 while True : if len(newText)>L : break if pos>=len(text): break if text[pos].isdigit(): endDigit=getEndDigit(text,pos) num=int(text[pos : endDigit]) if text[endDigit]=='(' : endPar=getEndParenthesis(text,endDigit) insideText=uncompress(text[endDigit+1 : endPar-1],L-len(newText)) for _ in range(num): newText+=insideText if len(newText)>L : break pos=endPar else : newText+=(text[endDigit]*num) pos=endDigit+1 else : newText+=text[pos] pos+=1 return newText def getEndParenthesis(text,pos): count=0 while True : if text[pos]=='(' : count+=1 elif text[pos]==')' : count-=1 if count==0 : return pos+1 pos+=1 def getEndDigit(text,pos): while True : if not text[pos].isdigit(): return pos pos+=1 if __name__=='__main__' : while True : text,idx=input().strip().split() if text=='0' and idx=='0' : break text=uncompress(text,int(idx)) print(text[int(idx)]if len(text)>int(idx)else 0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( while true do ( var idx : OclAny := null; Sequence{text,idx} := input()->trim().split() ; if text = '0' & idx = '0' then ( break ) else skip ; text := uncompress(text, ("" + ((idx)))->toInteger()) ; execute (if ((text)->size()->compareTo(("" + ((idx)))->toInteger())) > 0 then text[("" + ((idx)))->toInteger()+1] else 0 endif)->display()) ) else skip; operation uncompress(text : OclAny, L : OclAny) : OclAny pre: true post: true activity: var newText : String := '' ; var pos : int := 0 ; while true do ( if ((newText)->size()->compareTo(L)) > 0 then ( break ) else skip ; if (pos->compareTo((text)->size())) >= 0 then ( break ) else skip ; if text[pos+1]->matches("[0-9]*") then ( var endDigit : OclAny := getEndDigit(text, pos) ; var num : int := ("" + ((text.subrange(pos+1, endDigit))))->toInteger() ; if text[endDigit+1] = '(' then ( var endPar : OclAny := getEndParenthesis(text, endDigit) ; var insideText : OclAny := uncompress(text.subrange(endDigit + 1+1, endPar - 1), L - (newText)->size()) ; for _anon : Integer.subrange(0, num-1) do ( newText := newText + insideText ; if ((newText)->size()->compareTo(L)) > 0 then ( break ) else skip) ; pos := endPar ) else ( newText := newText + (text[endDigit+1] * num) ; pos := endDigit + 1 ) ) else ( newText := newText + text[pos+1] ; pos := pos + 1 )) ; return newText; operation getEndParenthesis(text : OclAny, pos : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while true do ( if text[pos+1] = '(' then ( count := count + 1 ) else (if text[pos+1] = ')' then ( count := count - 1 ) else skip) ; if count = 0 then ( return pos + 1 ) else skip ; pos := pos + 1); operation getEndDigit(text : OclAny, pos : OclAny) : OclAny pre: true post: true activity: while true do ( if not(text[pos+1]->matches("[0-9]*")) then ( return pos ) else skip ; pos := pos + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): def pearser(s,n): if s=="" : return "" i=0 while 1 : if not s[i].isdigit(): break i+=1 if i==0 : r=pearser(s[i+1 :],n-1) return s[0]+r if s[i]=="(" : r=Parentp(s[i :],n,int(s[: i])) else : r=s[i]*int(s[: i]) if len(r)>=n : return r[: n] r+=pearser(s[i+1 :],n-len(r)) return r def Parentp(s,n,p): if s=="" : return "" b=0 c=0 i=0 while 1 : if s[i]=="(" : c+=1 if s[i]==")" : c-=1 if c==0 : break i+=1 r=pearser(s[b+1 : i],n) l=len(r) if l*p>=n : r=r*(n//l+1) return r[: n] r=r*p r+=pearser(s[i+1 :],n-len(r)) return r def m(s,n): n=int(n) r=pearser(s,n+1) if len(r)<=n : print(0) return print(r[n]) while 1 : s,n=map(str,input().split()) if s==n=="0" : break m(s,n) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: skip ; skip ; skip ; while 1 do ( Sequence{s,n} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; if s = n & (n == "0") then ( break ) else skip ; m(s, n)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def middleNode(self,head): fast=slow=head while fast and fast.next : slow=slow.next fast=fast.next.next return slow ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation middleNode(head : OclAny) : OclAny pre: true post: true activity: var fast : OclAny := head; var slow : OclAny := head ; while fast & fast.next do ( slow := slow.next ; fast := fast.next.next) ; return slow; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def balancedString(str): count,i=0,0 n=len(str) for i in range(n): if(str[i]=='('): print(str[i],end="") count+=1 elif(str[i]==')' and count!=0): print(str[i],end="") count-=1 elif(str[i]!=')'): print(str[i],end="") if(count!=0): for i in range(count): print(")",end="") if __name__=='__main__' : str="gau)ra)v(ku(mar(rajput))" balancedString(str) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( OclType["String"] := "gau)ra)v(ku(mar(rajput))" ; balancedString(OclType["String"]) ) else skip; operation balancedString(OclType["String"] : OclAny) pre: true post: true activity: var count : OclAny := null; var i : OclAny := null; Sequence{count,i} := Sequence{0,0} ; var n : int := (OclType["String"])->size() ; for i : Integer.subrange(0, n-1) do ( if (("" + ([i+1])) = '(') then ( execute (("" + ([i+1])))->display() ; count := count + 1 ) else (if (("" + ([i+1])) = ')' & count /= 0) then ( execute (("" + ([i+1])))->display() ; count := count - 1 ) else (if (("" + ([i+1])) /= ')') then ( execute (("" + ([i+1])))->display() ) else skip ) ) ) ; if (count /= 0) then ( for i : Integer.subrange(0, count-1) do ( execute (")")->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100 def binomialCoeff(n,C): C[0]=1 for i in range(1,n+1): for j in range(min(i,n),-1,-1): C[j]=C[j]+C[j-1] def summation(n): C=[0]*MAX binomialCoeff(n,C) sum=0 for i in range(n+1): sum+=(i*C[i]) return sum if __name__=="__main__" : n=2 print(summation(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 100 ; skip ; skip ; if __name__ = "__main__" then ( n := 2 ; execute (summation(n))->display() ) else skip; operation binomialCoeff(n : OclAny, C : OclAny) pre: true post: true activity: C->first() := 1 ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(-1 + 1, Set{i, n}->min())->reverse() do ( C[j+1] := C[j+1] + C[j - 1+1])); operation summation(n : OclAny) : OclAny pre: true post: true activity: C := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX) ; binomialCoeff(n, C) ; var sum : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( sum := sum + (i * C[i+1])) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100 ; def binomialCoeff(C,n): C[0]=1 ; for i in range(1,n+1): for j in range(min(i,n),0,-1): C[j]=C[j]+C[j-1]; return C ; def sumOfproduct(n): sum=0 ; C=[0]*MAX ; C=binomialCoeff(C,n); for i in range(n+1): sum+=C[i]*C[i+1]; return sum ; n=3 ; print(sumOfproduct(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 100; ; skip ; skip ; n := 3; ; execute (sumOfproduct(n))->display();; operation binomialCoeff(C : OclAny, n : OclAny) pre: true post: true activity: C->first() := 1; ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(0 + 1, Set{i, n}->min())->reverse() do ( C[j+1] := C[j+1] + C[j - 1+1];)) ; return C;; operation sumOfproduct(n : OclAny) pre: true post: true activity: var sum : int := 0; ; C := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX); ; C := binomialCoeff(C, n); ; for i : Integer.subrange(0, n + 1-1) do ( sum := sum + C[i+1] * C[i + 1+1];) ; return sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minimumCost(cost,n): dp=[None]*n if n==1 : return cost[0] dp[0]=cost[0] dp[1]=cost[1] for i in range(2,n): dp[i]=min(dp[i-1],dp[i-2])+cost[i] return min(dp[n-2],dp[n-1]) if __name__=="__main__" : a=[16,19,10,12,18] n=len(a) print(minimumCost(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var a : Sequence := Sequence{16}->union(Sequence{19}->union(Sequence{10}->union(Sequence{12}->union(Sequence{ 18 })))) ; n := (a)->size() ; execute (minimumCost(a, n))->display() ) else skip; operation minimumCost(cost : OclAny, n : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; if n = 1 then ( return cost->first() ) else skip ; dp->first() := cost->first() ; dp[1+1] := cost[1+1] ; for i : Integer.subrange(2, n-1) do ( dp[i+1] := Set{dp[i - 1+1], dp[i - 2+1]}->min() + cost[i+1]) ; return Set{dp[n - 2+1], dp[n - 1+1]}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import array from fractions import Fraction import functools import itertools import math import os import sys def main(): while True : H,W=read_ints() if(H,W)==(0,0): break R=[inp()for _ in range(H)] S=inp() print(solve(H,W,R,S)) def solve(H,W,R,S): pos_map={} for y in range(H): for x in range(W): c=R[y][x] if c!='_' : pos_map[c]=(x,y) ans=0 cx=0 cy=0 for c in S : x,y=pos_map[c] ans+=abs(x-cx)+abs(y-cy)+1 cx,cy=x,y return ans DEBUG='DEBUG' in os.environ def inp(): return sys.stdin.readline().rstrip() def read_int(): return int(inp()) def read_ints(): return[int(e)for e in inp().split()] def dprint(*value,sep=' ',end='\n'): if DEBUG : print(*value,sep=sep,end=end) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var DEBUG : boolean := (os.environ)->includes('DEBUG') ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: while true do ( var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := read_ints() ; if Sequence{H, W} = Sequence{0, 0} then ( break ) else skip ; var R : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (inp())) ; var S : OclAny := inp() ; execute (solve(H, W, R, S))->display()); operation solve(H : OclAny, W : OclAny, R : OclAny, S : OclAny) : OclAny pre: true post: true activity: var pos_map : OclAny := Set{} ; for y : Integer.subrange(0, H-1) do ( for x : Integer.subrange(0, W-1) do ( var c : OclAny := R[y+1][x+1] ; if c /= '_' then ( pos_map[c+1] := Sequence{x, y} ) else skip)) ; var ans : int := 0 ; var cx : int := 0 ; var cy : int := 0 ; for c : S do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := pos_map[c+1] ; ans := ans + (x - cx)->abs() + (y - cy)->abs() + 1 ; Sequence{cx,cy} := Sequence{x,y}) ; return ans; operation inp() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation read_int() : OclAny pre: true post: true activity: return ("" + ((inp())))->toInteger(); operation read_ints() : OclAny pre: true post: true activity: return inp().split()->select(e | true)->collect(e | (("" + ((e)))->toInteger())); operation dprint(value : OclAny : Sequence(OclAny), sep : String, end : String) pre: true post: true activity: (args * (named_parameter (name value))) if sep->oclIsUndefined() then sep := ' ' else skip; if end->oclIsUndefined() then end := ' ' else skip; if DEBUG then ( execute ((argument * (test (logical_test (comparison (expr (atom (name value))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cntSubsets(arr,n): max=pow(2,n) result=0 for i in range(max): counter=i if(counter &(counter>>1)): continue result+=1 return result arr=[3,5,7] n=len(arr) print(cntSubsets(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{3}->union(Sequence{5}->union(Sequence{ 7 })) ; n := (arr)->size() ; execute (cntSubsets(arr, n))->display(); operation cntSubsets(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var max : double := (2)->pow(n) ; var result : int := 0 ; for i : Integer.subrange(0, max-1) do ( var counter : OclAny := i ; if (MathLib.bitwiseAnd(counter, (counter /(2->pow(1))))) then ( continue ) else skip ; result := result + 1) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def cyl(r,h): if(r<0 and h<0): return-1 R=(2*r)/3 H=(2*h)/3 V=3.14*math.pow(R,2)*H return V r=4 ; h=8 ; print(cyl(r,h),"\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; r := 4; h := 8; ; execute (cyl(r, h))->display(); operation cyl(r : OclAny, h : OclAny) : OclAny pre: true post: true activity: if (r < 0 & h < 0) then ( return -1 ) else skip ; var R : double := (2 * r) / 3 ; var H : double := (2 * h) / 3 ; var V : double := 3.14 * (R)->pow(2) * H ; return V; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=input().split(" ") n=int(n) x=int(x) count=0 for i in range(1,n+1): if x % i==0 and x//i<=n : if i==1 and x<=n : count+=1 elif i>1 : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := input().split(" ") ; var n : int := ("" + ((n)))->toInteger() ; var x : int := ("" + ((x)))->toInteger() ; var count : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( if x mod i = 0 & (x div i->compareTo(n)) <= 0 then ( if i = 1 & (x->compareTo(n)) <= 0 then ( count := count + 1 ) else (if i > 1 then ( count := count + 1 ) else skip) ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=map(int,input().split()) i=1 d=[] count=0 while i*i<=x : if x % i==0 : if i==x//i and i<=n : count+=1 else : if max(i,x//i)<=n : count+=2 i+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var i : int := 1 ; var d : Sequence := Sequence{} ; var count : int := 0 ; while (i * i->compareTo(x)) <= 0 do ( if x mod i = 0 then ( if i = x div i & (i->compareTo(n)) <= 0 then ( count := count + 1 ) else ( if (Set{i, x div i}->max()->compareTo(n)) <= 0 then ( count := count + 2 ) else skip ) ) else skip ; i := i + 1) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=map(int,input().split()) print(sum((x % i==0 and x/i<=n)for i in range(1,n+1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (((argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (expr (atom (name x))) % (expr (atom (name i))))) == (comparison (expr (atom (number (integer 0))))))) and (logical_test (comparison (comparison (expr (expr (atom (name x))) / (expr (atom (name i))))) <= (comparison (expr (atom (name n))))))))) )))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) )))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,ch=map(int,input().split()) k=0 delit=[] for i in range(1,n+1): if ch % i==0 : delit.append(i) for i in delit : for j in delit : if i*j==ch : k+=1 print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var ch : OclAny := null; Sequence{n,ch} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : int := 0 ; var delit : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( if ch mod i = 0 then ( execute ((i) : delit) ) else skip) ; for i : delit do ( for j : delit do ( if i * j = ch then ( k := k + 1 ) else skip)) ; execute (k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=map(int,input().split()) k=0 i=1 while i*i<=x : if x % i==0 and i<=n and x//i<=n : if i!=x//i : k+=2 else : k+=1 i+=1 print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : int := 0 ; var i : int := 1 ; while (i * i->compareTo(x)) <= 0 do ( if x mod i = 0 & (i->compareTo(n)) <= 0 & (x div i->compareTo(n)) <= 0 then ( if i /= x div i then ( k := k + 2 ) else ( k := k + 1 ) ) else skip ; i := i + 1) ; execute (k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) A=set(map(int,input().split())) B=set(map(int,input().split())) AandB=sorted(A & B) AorB=sorted(A | B) print(len(AandB),len(AorB)) for x in AandB : print(x) for x in AorB : print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var B : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var AandB : Sequence := MathLib.bitwiseAnd(A, B)->sort() ; var AorB : Sequence := MathLib.bitwiseOr(A, B)->sort() ; execute ((AandB)->size())->display() ; for x : AandB do ( execute (x)->display()) ; for x : AorB do ( execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict from heapq import heappush,heappop import sys import math import bisect import random def LI(): return list(map(int,sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return list(map(list,sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l=[None for i in range(n)] for i in range(n): l[i]=I() return l def LIR(n): l=[None for i in range(n)] for i in range(n): l[i]=LI() return l def SR(n): l=[None for i in range(n)] for i in range(n): l[i]=S() return l def LSR(n): l=[None for i in range(n)] for i in range(n): l[i]=SR() return l mod=1000000007 n,m=LI() a=LI() b=LI() li=list(set(a)| set(b)) li2=list(set(a)& set(b)) li.sort() li2.sort() print(len(li2),len(li)) for i in li2 : print(i) for i in li : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : int := 1000000007 ; var m : OclAny := null; Sequence{n,m} := LI() ; var a : OclAny := LI() ; var b : OclAny := LI() ; var li : Sequence := (MathLib.bitwiseOr(Set{}->union((a)), Set{}->union((b)))) ; var li2 : Sequence := (MathLib.bitwiseAnd(Set{}->union((a)), Set{}->union((b)))) ; li := li->sort() ; li2 := li2->sort() ; execute ((li2)->size())->display() ; for i : li2 do ( execute (i)->display()) ; for i : li do ( execute (i)->display()); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["Sequence"])->apply(_x) )); operation S() : OclAny pre: true post: true activity: return OclType["Sequence"]((OclFile["System.in"]).readLine())->front(); operation IR(n : OclAny) : OclAny pre: true post: true activity: var l : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; for i : Integer.subrange(0, n-1) do ( l[i+1] := I()) ; return l; operation LIR(n : OclAny) : OclAny pre: true post: true activity: l := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; for i : Integer.subrange(0, n-1) do ( l[i+1] := LI()) ; return l; operation SR(n : OclAny) : OclAny pre: true post: true activity: l := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; for i : Integer.subrange(0, n-1) do ( l[i+1] := S()) ; return l; operation LSR(n : OclAny) : OclAny pre: true post: true activity: l := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; for i : Integer.subrange(0, n-1) do ( l[i+1] := SR()) ; return l; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=list(map(int,input().split()))+[1000000001] b=list(map(int,input().split()))+[1000000001] andlis=[] orlis=[] cura=0 curb=0 for _ in range(n+m): if a[cura]>b[curb]: orlis.append(b[curb]) curb+=1 elif a[cura]==b[curb]: andlis.append(a[cura]) cura+=1 elif a[cura]collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->union(Sequence{ 1000000001 }) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->union(Sequence{ 1000000001 }) ; var andlis : Sequence := Sequence{} ; var orlis : Sequence := Sequence{} ; var cura : int := 0 ; var curb : int := 0 ; for _anon : Integer.subrange(0, n + m-1) do ( if (a[cura+1]->compareTo(b[curb+1])) > 0 then ( execute ((b[curb+1]) : orlis) ; curb := curb + 1 ) else (if a[cura+1] = b[curb+1] then ( execute ((a[cura+1]) : andlis) ; cura := cura + 1 ) else (if (a[cura+1]->compareTo(b[curb+1])) < 0 then ( execute ((a[cura+1]) : orlis) ; cura := cura + 1 ) else skip ) ) ) ; execute ((andlis)->size())->display() ; for i : andlis do ( execute (i)->display()) ; for i : orlis do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline while True : rr=[] h,w=map(int,input().split()) if h==w==0 : break else : for i in range(h): r=input().rstrip() rr.append(r) s=input().rstrip() ans=0 now=[0,0] for i in range(len(s)): for j in range(h): for k in range(w): if rr[j][k]==s[i]: ans+=abs(now[0]-j)+abs(now[1]-k) now=[j,k] print(ans+len(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; while true do ( var rr : Sequence := Sequence{} ; var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if h = w & (w == 0) then ( break ) else ( for i : Integer.subrange(0, h-1) do ( var r : OclAny := input().rstrip() ; execute ((r) : rr)) ; var s : OclAny := input().rstrip() ; var ans : int := 0 ; var now : Sequence := Sequence{0}->union(Sequence{ 0 }) ; for i : Integer.subrange(0, (s)->size()-1) do ( for j : Integer.subrange(0, h-1) do ( for k : Integer.subrange(0, w-1) do ( if rr[j+1][k+1] = s[i+1] then ( ans := ans + (now->first() - j)->abs() + (now[1+1] - k)->abs() ; now := Sequence{j}->union(Sequence{ k }) ) else skip))) ; execute (ans + (s)->size())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(int(1e7)) from collections import deque def inpl(): return list(map(int,input().split())) input() A=set(inpl()) B=set(inpl()) ands=sorted(A & B) ors=sorted(A | B) print(len(ands),len(ors)) if len(ands): print(*ands,sep="\n") if len(ors): print(*ors,sep="\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(("" + ((("1e7")->toReal())))->toInteger()) ; skip ; skip ; input() ; var A : Set := Set{}->union((inpl())) ; var B : Set := Set{}->union((inpl())) ; var ands : Sequence := MathLib.bitwiseAnd(A, B)->sort() ; var ors : Sequence := MathLib.bitwiseOr(A, B)->sort() ; execute ((ands)->size())->display() ; if (ands)->size() then ( execute ((argument * (test (logical_test (comparison (expr (atom (name ands))))))))->display() ) else skip ; if (ors)->size() then ( execute ((argument * (test (logical_test (comparison (expr (atom (name ors))))))))->display() ) else skip; operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) w=[] b=[] r=[] for i in range(n): s=input() w.append(m-s.count("W")) b.append(m-s.count("B")) r.append(m-s.count("R")) ans=3000 for i in range(1,n-1): for j in range(i,n-1): ans=min(ans,sum(w[: i])+sum(b[i : j+1])+sum(r[j+1 :])) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; var r : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; execute ((m - s->count("W")) : w) ; execute ((m - s->count("B")) : b) ; execute ((m - s->count("R")) : r)) ; var ans : int := 3000 ; for i : Integer.subrange(1, n - 1-1) do ( for j : Integer.subrange(i, n - 1-1) do ( ans := Set{ans, (w.subrange(1,i))->sum() + (b.subrange(i+1, j + 1))->sum() + (r.subrange(j + 1+1))->sum()}->min())) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,m=list(map(int,input().split())) A=list(map(int,input().split())) A=set(A) B=list(map(int,input().split())) B=set(B) intersection=A & B union=A | B print(len(intersection),len(union)) for i in sorted(list(intersection)): print(i) for u in sorted(list(union)): print(u) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; A := Set{}->union((A)) ; var B : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; B := Set{}->union((B)) ; var intersection : int := MathLib.bitwiseAnd(A, B) ; var union : int := MathLib.bitwiseOr(A, B) ; execute ((intersection)->size())->display() ; for i : (intersection)->sort() do ( execute (i)->display()) ; for u : (union)->sort() do ( execute (u)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def prime(n): for i in range(2,int(sqrt(n))+1): if n % i==0 : return False return True for i in range(int(input())): a,b=map(int,input().split()) if a-b>1 : print("NO") else : if prime(a+b): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a - b > 1 then ( execute ("NO")->display() ) else ( if prime(a + b) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) )); operation prime(n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(2, ("" + ((sqrt(n))))->toInteger() + 1-1) do ( if n mod i = 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def prime(number): for i in range(2,int(sqrt(number))+1): if number % i==0 : return False return True def squares(lst): a=list() for elem in lst : if elem[0]!=elem[1]+1 : a.append("NO") elif not prime(elem[0]+elem[1]): a.append("NO") else : a.append("YES") return a n=int(input()) b=list() for i in range(n): z=[int(j)for j in input().split()] b.append(z) print(*squares(b),sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := () ; for i : Integer.subrange(0, n-1) do ( var z : Sequence := input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; execute ((z) : b)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name squares)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))))))))->display(); operation prime(number : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(2, ("" + ((sqrt(number))))->toInteger() + 1-1) do ( if number mod i = 0 then ( return false ) else skip) ; return true; operation squares(lst : OclAny) : OclAny pre: true post: true activity: var a : Sequence := () ; for elem : lst do ( if elem->first() /= elem[1+1] + 1 then ( execute (("NO") : a) ) else (if not(prime(elem->first() + elem[1+1])) then ( execute (("NO") : a) ) else ( execute (("YES") : a) ) ) ) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): a,b=map(int,input().split()) if a-b==1 : c=a+b for d in range(2,int(c**0.5)+1): if c % d==0 : print("NO") break else : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a - b = 1 then ( var c : OclAny := a + b ; (compound_stmt for (exprlist (expr (atom (name d)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name c))) ** (expr (atom (number 0.5))))))))) )))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name c))) % (expr (atom (name d))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) ))))))))))))))) ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def find(x): if(x % 2==0 or x==1): return 0 else : root=int(math.sqrt(x)) for i in range(3,root+1,2): if(x % i==0): return 0 return 1 t=int(input()) for i in range(t): tmp=input().split() if(find(int(tmp[0])+int(tmp[1]))and int(tmp[0])==int(tmp[1])+1): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var tmp : OclAny := input().split() ; if (find(("" + ((tmp->first())))->toInteger() + ("" + ((tmp[1+1])))->toInteger()) & ("" + ((tmp->first())))->toInteger() = ("" + ((tmp[1+1])))->toInteger() + 1) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); operation find(x : OclAny) : OclAny pre: true post: true activity: if (x mod 2 = 0 or x = 1) then ( return 0 ) else ( var root : int := ("" + (((x)->sqrt())))->toInteger() ; for i : Integer.subrange(3, root + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if (x mod i = 0) then ( return 0 ) else skip) ) ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math t=int(input()) def IsPrime(x): k=int(math.sqrt(x)+1) for i in range(2,k): if((x % i)==0): return 0 return 1 for T in range(t): a,b=map(int,input().split()) if atoInteger() ; skip ; for T : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(b)) < 0 then ( swap(a, b) ) else skip ; if ((a - b) /= 1) then ( execute ("NO")->display() ) else ( if (IsPrime(a + b)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) )); operation IsPrime(x : OclAny) : OclAny pre: true post: true activity: var k : int := ("" + (((x)->sqrt() + 1)))->toInteger() ; for i : Integer.subrange(2, k-1) do ( if ((x mod i) = 0) then ( return 0 ) else skip) ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) S1,S2=input(),input() A=[] cur=0 while curtoInteger() ; var S1 : OclAny := null; var S2 : OclAny := null; Sequence{S1,S2} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine()} ; var A : Sequence := Sequence{} ; var cur : int := 0 ; while (cur->compareTo(N)) < 0 do ( if S1[cur+1] = S2[cur+1] then ( execute (("X") : A) ; cur := cur + 1 ) else ( execute (("Y") : A) ; cur := cur + 2 )) ; var ans : int := if A->first() = "X" then 3 else 6 endif ; for i : Integer.subrange(1, (A)->size()-1) do ( if A[i - 1+1] = "X" then ( ans := ans * 2 ) else (if A[i+1] = "Y" then ( ans := ans * 3 ) else skip) ; ans := ans mod 1000000007) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from collections import defaultdict sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod=10**9+7 def I(): return int(input()) def LI(): return list(map(int,input().split())) def LIR(row,col): if row<=0 : return[[]for _ in range(col)] elif col==1 : return[I()for _ in range(row)] else : read_all=[LI()for _ in range(row)] return map(list,zip(*read_all)) N=I() S1=list(input()) S2=list(input()) if S1[0]==S2[0]: ans=3 start=1 else : ans=6 start=2 i=start while i<=N-1 : if S1[i]==S2[i]: if S1[i-1]==S2[i-1]: ans*=2 ans %=mod i+=1 else : if S1[i-1]==S2[i-1]: ans*=2 ans %=mod else : ans*=3 ans %=mod i+=2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; var N : OclAny := I() ; var S1 : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var S2 : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if S1->first() = S2->first() then ( var ans : int := 3 ; var start : int := 1 ) else ( ans := 6 ; start := 2 ) ; var i : int := start ; while (i->compareTo(N - 1)) <= 0 do ( if S1[i+1] = S2[i+1] then ( if S1[i - 1+1] = S2[i - 1+1] then ( ans := ans * 2 ; ans := ans mod mod ) else skip ; i := i + 1 ) else ( if S1[i - 1+1] = S2[i - 1+1] then ( ans := ans * 2 ; ans := ans mod mod ) else ( ans := ans * 3 ; ans := ans mod mod ) ; i := i + 2 )) ; execute (ans)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LIR(row : OclAny, col : OclAny) : OclAny pre: true post: true activity: if row <= 0 then ( return Integer.subrange(0, col-1)->select(_anon | true)->collect(_anon | (Sequence{})) ) else (if col = 1 then ( return Integer.subrange(0, row-1)->select(_anon | true)->collect(_anon | (I())) ) else ( var read_all : Sequence := Integer.subrange(0, row-1)->select(_anon | true)->collect(_anon | (LI())) ; return (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name read_all)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name read_all)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name read_all)))))))`third->at(_indx)} ))->collect( _x | (OclType["Sequence"])->apply(_x) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from math import gcd x,y,a,b=map(int,input().split()) c=(x*y)//gcd(x,y) a=(a-1)//c b=b//c print(b-a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var x : OclAny := null; var y : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{x,y,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : int := (x * y) div gcd(x, y) ; var a : int := (a - 1) div c ; var b : int := b div c ; execute (b - a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools import math import fractions import functools import copy n=int(input()) if n==1 : print("Hello World") else : a=int(input()) b=int(input()) print(a+b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute ("Hello World")->display() ) else ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (a + b)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=int(1e9)+7 def main(): buf=input() N=int(buf) S=[] for i in range(2): buf=input() S.append(buf) last_pattern=None combination=1 point=0 while pointtoReal())))->toInteger() + 7 ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var buf : String := (OclFile["System.in"]).readLine() ; var N : int := ("" + ((buf)))->toInteger() ; var S : Sequence := Sequence{} ; for i : Integer.subrange(0, 2-1) do ( buf := (OclFile["System.in"]).readLine() ; execute ((buf) : S)) ; var last_pattern : OclAny := null ; var combination : int := 1 ; var point : int := 0 ; while (point->compareTo(N)) < 0 do ( if S->first()[point+1] = S[1+1][point+1] then ( if last_pattern <>= null then ( combination := combination * 3 ) else (if last_pattern = 1 then ( combination := combination * 2 ) else ( combination := combination * 1 ) ) ; last_pattern := 1 ; point := point + 1 ) else ( if last_pattern <>= null then ( combination := combination * 6 ) else (if last_pattern = 1 then ( combination := combination * 2 ) else ( combination := combination * 3 ) ) ; last_pattern := 2 ; point := point + 2 ) ; combination := combination mod MOD) ; execute (combination)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np def getInput(): separator=' ' ret_array=[] while True : try : row=input().split(sep=separator) ret_array.append(row) except EOFError : break return ret_array g=getInput() N=np.int32(g[0][0]) ls=0 cs=None l=[] i=0 hoge=[] try : while True : hoge.append(g[2][0][i]) if g[1][0][i]==g[2][0][i]: cs=2 i+=1 else : cs=1 i+=2 if ls==0 : if cs==1 : l.append(6) else : l.append(3) elif ls==1 : if cs==1 : l.append(3) else : l.append(1) else : l.append(2) ls=cs except IndexError : print(np.mod(np.prod(np.array(l,dtype=np.int32)),1000000007)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var g : OclAny := getInput() ; var N : (trailer . (name int32) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))) := ; var ls : int := 0 ; var cs : OclAny := null ; var l : Sequence := Sequence{} ; var i : int := 0 ; var hoge : Sequence := Sequence{} ; try ( while true do ( execute ((g[2+1]->first()[i+1]) : hoge) ; if g[1+1]->first()[i+1] = g[2+1]->first()[i+1] then ( cs := 2 ; i := i + 1 ) else ( cs := 1 ; i := i + 2 ) ; if ls = 0 then ( if cs = 1 then ( execute ((6) : l) ) else ( execute ((3) : l) ) ) else (if ls = 1 then ( if cs = 1 then ( execute ((3) : l) ) else ( execute ((1) : l) ) ) else ( execute ((2) : l) ) ) ; ls := cs)) (except_clause except (test (logical_test (comparison (expr (atom (name IndexError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name np)) (trailer . (name mod) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name np)) (trailer . (name prod) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name np)) (trailer . (name array) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l))))))) , (argument (test (logical_test (comparison (expr (atom (name dtype)))))) = (test (logical_test (comparison (expr (atom (name np)) (trailer . (name int32)))))))) ))))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1000000007))))))))) ))))))))) )))))))))))))); operation getInput() : OclAny pre: true post: true activity: var separator : String := ' ' ; var ret_array : Sequence := Sequence{} ; while true do ( try ( var row : OclAny := input().split((argument (test (logical_test (comparison (expr (atom (name sep)))))) = (test (logical_test (comparison (expr (atom (name separator)))))))) ; execute ((row) : ret_array)) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))) ; return ret_array; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def differ(i,ss): tos=["W","B","R"] count=0 for j in ss : if(j!=tos[i]): count+=1 return count [n,m]=list(map(int,input().split())) ls=[] for i in range(n): ls.append(input()) dp=[[0 for i in range(50)]for i in range(3)] dp[0][0]=differ(0,ls[0]) for i in range(3): for j in range(n): if j==0 : if i==0 : dp[i][j]=differ(0,ls[0]) else : dp[i][j]=100000 elif i==0 : dp[i][j]=dp[i][j-1]+differ(i,ls[j]) else : dp[i][j]=min(dp[i-1][j-1]+differ(i,ls[j]),dp[i][j-1]+differ(i,ls[j])) print(dp[2][n-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{n}->union(Sequence{ m }) := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ls : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : ls)) ; var dp : Sequence := Integer.subrange(0, 3-1)->select(i | true)->collect(i | (Integer.subrange(0, 50-1)->select(i | true)->collect(i | (0)))) ; dp->first()->first() := differ(0, ls->first()) ; for i : Integer.subrange(0, 3-1) do ( for j : Integer.subrange(0, n-1) do ( if j = 0 then ( if i = 0 then ( dp[i+1][j+1] := differ(0, ls->first()) ) else ( dp[i+1][j+1] := 100000 ) ) else (if i = 0 then ( dp[i+1][j+1] := dp[i+1][j - 1+1] + differ(i, ls[j+1]) ) else ( dp[i+1][j+1] := Set{dp[i - 1+1][j - 1+1] + differ(i, ls[j+1]), dp[i+1][j - 1+1] + differ(i, ls[j+1])}->min() ) ) )) ; execute (dp[2+1][n - 1+1])->display(); operation differ(i : OclAny, ss : OclAny) : OclAny pre: true post: true activity: var tos : Sequence := Sequence{"W"}->union(Sequence{"B"}->union(Sequence{ "R" })) ; var count : int := 0 ; for j : ss do ( if (j /= tos[i+1]) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s1=str(input()) s2=str(input()) mod=10**9+7 ans=1 flag=False for i in range(n): if s1[i]==s2[i]: if i==0 : ans*=3 else : if flag : ans*=2 else : ans*=1 flag=True else : if i==n-1 : continue else : if s1[i]==s1[i+1]and s2[i]==s2[i+1]: if i==0 : ans*=6 else : if flag : ans*=2 else : ans*=3 else : continue flag=False ans %=mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s1 : String := ("" + (((OclFile["System.in"]).readLine()))) ; var s2 : String := ("" + (((OclFile["System.in"]).readLine()))) ; var mod : double := (10)->pow(9) + 7 ; var ans : int := 1 ; var flag : boolean := false ; for i : Integer.subrange(0, n-1) do ( if s1[i+1] = s2[i+1] then ( if i = 0 then ( ans := ans * 3 ) else ( if flag then ( ans := ans * 2 ) else ( ans := ans * 1 ) ) ; flag := true ) else ( if i = n - 1 then ( continue ) else ( if s1[i+1] = s1[i + 1+1] & s2[i+1] = s2[i + 1+1] then ( if i = 0 then ( ans := ans * 6 ) else ( if flag then ( ans := ans * 2 ) else ( ans := ans * 3 ) ) ) else ( continue ) ) ; flag := false ) ; ans := ans mod mod) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) c=[0]*3 for i in a : c[i % 3]+=1 if(c[1]| c[2])==0 : ans=1 else : ans,n=c[0],n-c[0] if n<=3 : ans+=n else : t=max(-3,min(3,c[1]-c[2])) if t>0 : ans+=2*c[2]+t else : ans+=2*c[1]-t print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 3) ; for i : a do ( c[i mod 3+1] := c[i mod 3+1] + 1) ; if (MathLib.bitwiseOr(c[1+1], c[2+1])) = 0 then ( var ans : int := 1 ) else ( Sequence{ans,n} := Sequence{c->first(),n - c->first()} ; if n <= 3 then ( ans := ans + n ) else ( var t : OclAny := Set{-3, Set{3, c[1+1] - c[2+1]}->min()}->max() ; if t > 0 then ( ans := ans + 2 * c[2+1] + t ) else ( ans := ans + 2 * c[1+1] - t ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() An=[int(x)for x in input().split()] mod0=0 mod1=0 mod2=0 for x in An : if x % 3==0 : mod0+=1 if x % 3==1 : mod1+=1 if x % 3==2 : mod2+=1 if mod1==0 and mod2==0 : print("1") elif abs(mod1-mod2)<=3 : print((mod0+mod1+mod2)) else : if mod1>mod2 : print((mod0+mod2+mod2+3)) if mod1select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var mod0 : int := 0 ; var mod1 : int := 0 ; var mod2 : int := 0 ; for x : An do ( if x mod 3 = 0 then ( mod0 := mod0 + 1 ) else skip ; if x mod 3 = 1 then ( mod1 := mod1 + 1 ) else skip ; if x mod 3 = 2 then ( mod2 := mod2 + 1 ) else skip) ; if mod1 = 0 & mod2 = 0 then ( execute ("1")->display() ) else (if (mod1 - mod2)->abs() <= 3 then ( execute ((mod0 + mod1 + mod2))->display() ) else ( if (mod1->compareTo(mod2)) > 0 then ( execute ((mod0 + mod2 + mod2 + 3))->display() ) else skip ; if (mod1->compareTo(mod2)) < 0 then ( execute ((mod0 + mod1 + mod1 + 3))->display() ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) alst=list(map(int,input().split())) mod_cnt=[0,0,0] for a in alst : mod_cnt[a % 3]+=1 if mod_cnt[1]==0 and mod_cnt[2]==0 : print(1) elif mod_cnt[1]==mod_cnt[2]: print(mod_cnt[0]+mod_cnt[1]+mod_cnt[2]) elif mod_cnt[1]mod_cnt[2]: print(mod_cnt[0]+min(mod_cnt[1],mod_cnt[2]+3)+mod_cnt[2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var alst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mod_cnt : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) ; for a : alst do ( mod_cnt[a mod 3+1] := mod_cnt[a mod 3+1] + 1) ; if mod_cnt[1+1] = 0 & mod_cnt[2+1] = 0 then ( execute (1)->display() ) else (if mod_cnt[1+1] = mod_cnt[2+1] then ( execute (mod_cnt->first() + mod_cnt[1+1] + mod_cnt[2+1])->display() ) else (if (mod_cnt[1+1]->compareTo(mod_cnt[2+1])) < 0 then ( execute (mod_cnt->first() + mod_cnt[1+1] + Set{mod_cnt[1+1] + 3, mod_cnt[2+1]}->min())->display() ) else (if (mod_cnt[1+1]->compareTo(mod_cnt[2+1])) > 0 then ( execute (mod_cnt->first() + Set{mod_cnt[1+1], mod_cnt[2+1] + 3}->min() + mod_cnt[2+1])->display() ) else skip ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(b==0): return a else : return gcd(b,a % b) def isDivisible(x,y): if(y==1): return 1 z=gcd(x,y); if(z==1): return false ; return isDivisible(x,y/z); x=18 y=12 if(isDivisible(x,y)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; x := 18 ; y := 12 ; if (isDivisible(x, y)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (b = 0) then ( return a ) else ( return gcd(b, a mod b) ); operation isDivisible(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (y = 1) then ( return 1 ) else skip ; var z : OclAny := gcd(x, y); ; if (z = 1) then ( return false; ) else skip ; return isDivisible(x, y / z);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthTerm(N): nth=0 ; first_term=4 ; pi=1 ; po=1 ; n=N ; while(n>1): pi*=n-1 ; n-=1 ; po*=2 ; nth=(first_term*pi)//po ; return nth ; if __name__=="__main__" : N=5 ; print(nthTerm(N)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := 5; ; execute (nthTerm(N))->display(); ) else skip; operation nthTerm(N : OclAny) pre: true post: true activity: var nth : int := 0; var first_term : int := 4; ; var pi : int := 1; var po : int := 1; ; var n : OclAny := N; ; while (n > 1) do ( pi := pi * n - 1; ; n := n - 1; ; po := po * 2;) ; nth := (first_term * pi) div po; ; return nth;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil,floor def sum(N,X,Y): S1=floor(floor(N/X)*floor(2*X+floor(N/X-1)*X)/2) S2=floor(floor(N/Y))*floor(2*Y+floor(N/Y-1)*Y)/2 S3=floor(floor(N/(X*Y)))*floor(2*(X*Y)+floor(N/(X*Y)-1)*(X*Y))/2 return S1+S2-S3 if __name__=='__main__' : N=14 X=3 Y=5 print(int(sum(N,X,Y))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( N := 14 ; X := 3 ; Y := 5 ; execute (("" + (((N, X, Y)->sum())))->toInteger())->display() ) else skip; operation sum(N : OclAny, X : OclAny, Y : OclAny) : OclAny pre: true post: true activity: var S1 : OclAny := floor(floor(N / X) * floor(2 * X + floor(N / X - 1) * X) / 2) ; var S2 : double := floor(floor(N / Y)) * floor(2 * Y + floor(N / Y - 1) * Y) / 2 ; var S3 : double := floor(floor(N / (X * Y))) * floor(2 * (X * Y) + floor(N / (X * Y) - 1) * (X * Y)) / 2 ; return S1 + S2 - S3; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ABC_112_A(): N=int(input()) if N==2 : A=int(input()) B=int(input()) print(A+B) else : print('Hello World') if __name__=='__main__' : ABC_112_A() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( ABCABCABCABCABCABCABC skip12_A()12_A()12_A()12_A()12_A()12_A()12_A() ) else skip; operation ABC skip12_A() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 2 then ( var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (A + B)->display() ) else ( execute ('Hello World')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isUnary(n): if(n==1 or n==7): return True elif(int(n/10)==0): return False sum=0 while(n!=0): x=n % 10 sum=sum+x*x n=int(n/10) return isUnary(sum) def countUnary(a,b): count=0 for i in range(a,b+1,1): if(isUnary(i)==1): count+=1 return count if __name__=='__main__' : a=1000 b=1099 print(countUnary(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( a := 1000 ; b := 1099 ; execute (countUnary(a, b))->display() ) else skip; operation isUnary(n : OclAny) : OclAny pre: true post: true activity: if (n = 1 or n = 7) then ( return true ) else (if (("" + ((n / 10)))->toInteger() = 0) then ( return false ) else skip) ; var sum : int := 0 ; while (n /= 0) do ( var x : int := n mod 10 ; sum := sum + x * x ; n := ("" + ((n / 10)))->toInteger()) ; return isUnary(sum); operation countUnary(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(a, b + 1-1)->select( $x | ($x - a) mod 1 = 0 ) do ( if (isUnary(i) = 1) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findLength(str): n=len(str) maxlen=0 for i in range(0,n): for j in range(i+1,n,2): length=j-i+1 leftsum=0 rightsum=0 for k in range(0,int(length/2)): leftsum+=(int(str[i+k])-int('0')) rightsum+=(int(str[i+k+int(length/2)])-int('0')) if(leftsum==rightsum and maxlendisplay(); operation findLength(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var n : int := (OclType["String"])->size() ; var maxlen : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1)->select( $x | ($x - i + 1) mod 2 = 0 ) do ( var length : double := j - i + 1 ; var leftsum : int := 0 ; var rightsum : int := 0 ; for k : Integer.subrange(0, ("" + ((length / 2)))->toInteger()-1) do ( leftsum := leftsum + (("" + ((("" + ([i + k+1])))))->toInteger() - ("" + (('0')))->toInteger()) ; rightsum := rightsum + (("" + ((("" + ([i + k + ("" + ((length / 2)))->toInteger()+1])))))->toInteger() - ("" + (('0')))->toInteger())) ; if (leftsum = rightsum & (maxlen->compareTo(length)) < 0) then ( maxlen := length ) else skip)) ; return maxlen; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findFirstAndLast(arr,n,x): first=-1 last=-1 for i in range(0,n): if(x!=arr[i]): continue if(first==-1): first=i last=i if(first!=-1): print("First Occurrence=",first," \nLast Occurrence=",last) else : print("Not Found") arr=[1,2,2,2,2,3,4,7,8,8] n=len(arr) x=8 findFirstAndLast(arr,n,x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 8 }))))))))) ; n := (arr)->size() ; x := 8 ; findFirstAndLast(arr, n, x); operation findFirstAndLast(arr : OclAny, n : OclAny, x : OclAny) pre: true post: true activity: var first : int := -1 ; var last : int := -1 ; for i : Integer.subrange(0, n-1) do ( if (x /= arr[i+1]) then ( continue ) else skip ; if (first = -1) then ( first := i ) else skip ; last := i) ; if (first /= -1) then ( execute ("First Occurrence=")->display() ) else ( execute ("Not Found")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countZeros(x): n=32 ; y=x>>16 ; if(y!=0): n=n-16 ; x=y ; y=x>>8 ; if(y!=0): n=n-8 ; x=y ; y=x>>4 ; if(y!=0): n=n-4 ; x=y ; y=x>>2 ; if(y!=0): n=n-2 ; x=y ; y=x>>1 ; if(y!=0): return n-2 ; return n-x ; def main(): x=101 ; print(countZeros(x)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation countZeros(x : OclAny) pre: true post: true activity: var n : int := 32; ; var y : int := x /(2->pow(16)); ; if (y /= 0) then ( n := n - 16; ; x := y; ) else skip ; y := x /(2->pow(8)); ; if (y /= 0) then ( n := n - 8; ; x := y; ) else skip ; y := x /(2->pow(4)); ; if (y /= 0) then ( n := n - 4; ; x := y; ) else skip ; y := x /(2->pow(2)); ; if (y /= 0) then ( n := n - 2; ; x := y; ) else skip ; y := x /(2->pow(1)); ; if (y /= 0) then ( return n - 2; ) else skip ; return n - x;; operation main() pre: true post: true activity: x := 101; ; execute (countZeros(x))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math class Node : def __init__(self,data): self.data=data self.next=None def insertNode(start,value): if(start==None): new_node=Node(value) new_node.data=value new_node.next=new_node new_node.prev=new_node start=new_node return new_node last=start.prev new_node=Node(value) new_node.data=value new_node.next=start (start).prev=new_node new_node.prev=last last.next=new_node return start def displayList(start): temp=start while(temp.next!=start): print(temp.data,end="") temp=temp.next print(temp.data) def searchList(start,search): temp=start count=0 flag=0 value=0 if(temp==None): return-1 else : while(temp.next!=start): count=count+1 if(temp.data==search): flag=1 count=count-1 break temp=temp.next if(temp.data==search): count=count+1 flag=1 if(flag==1): print(search,"found at location ",count) else : print(search," not found") return-1 if __name__=='__main__' : start=None start=insertNode(start,4) start=insertNode(start,5) start=insertNode(start,7) start=insertNode(start,8) start=insertNode(start,6) print("Created circular doubly linked list is: ",end="") displayList(start) searchList(start,5) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.next := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; (start).prev := new_node; operation insertNode(start : OclAny, value : OclAny) : OclAny pre: true post: true activity: if (start = null) then ( var new_node : Node := (Node.newNode()).initialise(value) ; new_node.data := value ; new_node.next := new_node ; new_node.prev := new_node ; start := new_node ; return new_node ) else skip ; var last : OclAny := start.prev ; new_node := (Node.newNode()).initialise(value) ; new_node.data := value ; new_node.next := start; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w=[int(s)for s in input().split(" ")] flag=[input()for i in range(h)] mincnt=1145141919810 for i in range(1,h-1): for j in range(1,h-i): cnt=0 wr=flag[: i] br=flag[i : i+j] rr=flag[i+j :] for l in wr : for c in l : if c!='W' : cnt+=1 for l in br : for c in l : if c!='B' : cnt+=1 for l in rr : for c in l : if c!='R' : cnt+=1 if cntselect(s | true)->collect(s | (("" + ((s)))->toInteger())) ; var flag : Sequence := Integer.subrange(0, h-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var mincnt : int := 1145141919810 ; for i : Integer.subrange(1, h - 1-1) do ( for j : Integer.subrange(1, h - i-1) do ( var cnt : int := 0 ; var wr : OclAny := flag.subrange(1,i) ; var br : OclAny := flag.subrange(i+1, i + j) ; var rr : OclAny := flag.subrange(i + j+1) ; for l : wr do ( for c : l do ( if c /= 'W' then ( cnt := cnt + 1 ) else skip)) ; for l : br do ( for c : l do ( if c /= 'B' then ( cnt := cnt + 1 ) else skip)) ; for l : rr do ( for c : l do ( if c /= 'R' then ( cnt := cnt + 1 ) else skip)) ; if (cnt->compareTo(mincnt)) < 0 then ( mincnt := cnt ) else skip)) ; execute (mincnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : n=3 a=[1,2,3] i=0 sum=0 for i in range(n): sum+=a[i] x=sum//n if(x*n==sum): print(x) else : print("-1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var n : int := 3 ; var a : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; var i : int := 0 ; var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + a[i+1]) ; var x : int := sum div n ; if (x * n = sum) then ( execute (x)->display() ) else ( execute ("-1")->display() ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def squareArea(l,b,h): if l<0 or b<0 or h<0 : return-1 a=(l*b)/(l+b) return a*a if __name__=="__main__" : l,b,h=5,12,13 print(round(squareArea(l,b,h),4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{l,b,h} := Sequence{5,12,13} ; execute (MathLib.roundN(squareArea(l, b, h), 4))->display() ) else skip; operation squareArea(l : OclAny, b : OclAny, h : OclAny) : OclAny pre: true post: true activity: if l < 0 or b < 0 or h < 0 then ( return -1 ) else skip ; var a : double := (l * b) / (l + b) ; return a * a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findWays(m,n,x): table=[[0]*(x+1)for i in range(n+1)] for j in range(1,min(m+1,x+1)): table[1][j]=1 for i in range(2,n+1): for j in range(1,x+1): for k in range(1,min(m+1,j)): table[i][j]+=table[i-1][j-k] return table[-1][-1] print(findWays(4,2,1)) print(findWays(2,2,3)) print(findWays(6,3,8)) print(findWays(4,2,5)) print(findWays(4,3,5)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (findWays(4, 2, 1))->display() ; execute (findWays(2, 2, 3))->display() ; execute (findWays(6, 3, 8))->display() ; execute (findWays(4, 2, 5))->display() ; execute (findWays(4, 3, 5))->display(); operation findWays(m : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: var table : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (x + 1)))) ; for j : Integer.subrange(1, Set{m + 1, x + 1}->min()-1) do ( table[1+1][j+1] := 1) ; for i : Integer.subrange(2, n + 1-1) do ( for j : Integer.subrange(1, x + 1-1) do ( for k : Integer.subrange(1, Set{m + 1, j}->min()-1) do ( table[i+1][j+1] := table[i+1][j+1] + table[i - 1+1][j - k+1]))) ; return table->last()->last(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000,10**9)) write=lambda x : sys.stdout.write(x+"\n") s=input() k=int(input()) n=len(s) l=[] for i in range(5): l.extend([s[ii :(ii+i+1)]for ii in range(n-i)]) l=list(set(l)) l.sort() ans=l[k-1] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; sys.setrecursionlimit(Set{1000, (10)->pow(9)}->max()) ; var write : Function := lambda x : OclAny in ((OclFile["System.out"]).write(x + "\n")) ; var s : String := (OclFile["System.in"]).readLine() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := (s)->size() ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, 5-1) do ( l := l->union(Integer.subrange(0, n - i-1)->select(ii | true)->collect(ii | (s.subrange(ii+1, (ii + i + 1)))))) ; l := (Set{}->union((l))) ; l := l->sort() ; var ans : OclAny := l[k - 1+1] ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def resolve(): N=int(input()) if N==1 : print("Hello World") return A=int(input()) B=int(input()) print(A+B) if '__main__'==__name__ : resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if '__main__' = __name__ then ( resolve() ) else skip; operation resolve() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 1 then ( execute ("Hello World")->display() ; return ) else skip ; var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (A + B)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() k=int(input()) n=len(s) sublst=[sorted(list(set([s[i]for i in range(n)])))] ret=[] def dfs(l,i): if len(sublst)0 : sublst.append(sorted(list(set([s[i : i+l+1]for i in range(n-l)])))) ret.append(sublst[l-1][i]) if len(ret)>=k : return if l<=n-1 : for j in range(len(sublst[l])): if sublst[l][j][:-1]==sublst[l-1][i]: dfs(l+1,j) if l==1 and len(sublst[0])>i+1 : dfs(1,i+1) dfs(1,0) print(ret[k-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := (s)->size() ; var sublst : Sequence := Sequence{ (Set{}->union((Integer.subrange(0, n-1)->select(i | true)->collect(i | (s[i+1])))))->sort() } ; var ret : Sequence := Sequence{} ; skip ; dfs(1, 0) ; execute (ret[k - 1+1])->display(); operation dfs(l : OclAny, i : OclAny) pre: true post: true activity: if ((sublst)->size()->compareTo(l + 1)) < 0 & n - l > 0 then ( execute (((Set{}->union((Integer.subrange(0, n - l-1)->select(i | true)->collect(i | (s.subrange(i+1, i + l + 1))))))->sort()) : sublst) ) else skip ; execute ((sublst[l - 1+1][i+1]) : ret) ; if ((ret)->size()->compareTo(k)) >= 0 then ( return ) else skip ; if (l->compareTo(n - 1)) <= 0 then ( for j : Integer.subrange(0, (sublst[l+1])->size()-1) do ( if sublst[l+1][j+1]->front() = sublst[l - 1+1][i+1] then ( dfs(l + 1, j) ) else skip) ) else skip ; if l = 1 & ((sublst->first())->size()->compareTo(i + 1)) > 0 then ( dfs(1, i + 1) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from copy import deepcopy import itertools def read(): return int(input()) def readmap(): return map(int,input().split()) def readlist(): return list(map(int,input().split())) S=input() K=read() substring=set() for k in range(1,min(K,len(S))+1): for i in range(len(S)-k+1): substring.add(S[i : i+k]) sub=sorted(list(substring)) print(sub[K-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var S : String := (OclFile["System.in"]).readLine() ; var K : OclAny := read() ; var substring : Set := Set{}->union(()) ; for k : Integer.subrange(1, Set{K, (S)->size()}->min() + 1-1) do ( for i : Integer.subrange(0, (S)->size() - k + 1-1) do ( execute ((S.subrange(i+1, i + k)) : substring))) ; var sub : Sequence := (substring)->sort() ; execute (sub[K - 1+1])->display(); operation read() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation readmap() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation readlist() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() k=int(input()) a=sorted(set(s))[: 5] if len(s)>=2 : b=sorted(set([s[i : i+2]for i in range(len(s)-1)]))[: 5] a.extend(b) if len(s)>=3 : c=sorted(set([s[i : i+3]for i in range(len(s)-2)]))[: 5] a.extend(c) if len(s)>=4 : d=sorted(set([s[i : i+4]for i in range(len(s)-3)]))[: 5] a.extend(d) if len(s)>=5 : e=sorted(set([s[i : i+5]for i in range(len(s)-4)]))[: 5] a.extend(e) print(sorted(a)[k-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := sorted(Set{}->union((s))).subrange(1,5) ; if (s)->size() >= 2 then ( var b : OclAny := sorted(Set{}->union((Integer.subrange(0, (s)->size() - 1-1)->select(i | true)->collect(i | (s.subrange(i+1, i + 2)))))).subrange(1,5) ; a := a->union(b) ) else skip ; if (s)->size() >= 3 then ( var c : OclAny := sorted(Set{}->union((Integer.subrange(0, (s)->size() - 2-1)->select(i | true)->collect(i | (s.subrange(i+1, i + 3)))))).subrange(1,5) ; a := a->union(c) ) else skip ; if (s)->size() >= 4 then ( var d : OclAny := sorted(Set{}->union((Integer.subrange(0, (s)->size() - 3-1)->select(i | true)->collect(i | (s.subrange(i+1, i + 4)))))).subrange(1,5) ; a := a->union(d) ) else skip ; if (s)->size() >= 5 then ( var e : OclAny := sorted(Set{}->union((Integer.subrange(0, (s)->size() - 4-1)->select(i | true)->collect(i | (s.subrange(i+1, i + 5)))))).subrange(1,5) ; a := a->union(e) ) else skip ; execute (sorted(a)[k - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout s=stdin.readline().strip() k=int(stdin.readline()) challengers=[] for i in range(len(s)): cur='' for j in range(i,min(i+5,len(s))): cur+=s[j] challengers.append(cur) challengers.sort() for i in range(len(challengers)): if not i or challengers[i-1]!=challengers[i]: k-=1 if not k : stdout.write(challengers[i]) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : OclAny := stdin.readLine()->trim() ; var k : int := ("" + ((stdin.readLine())))->toInteger() ; var challengers : Sequence := Sequence{} ; for i : Integer.subrange(0, (s)->size()-1) do ( var cur : String := '' ; for j : Integer.subrange(i, Set{i + 5, (s)->size()}->min()-1) do ( cur := cur + s[j+1] ; execute ((cur) : challengers))) ; challengers := challengers->sort() ; for i : Integer.subrange(0, (challengers)->size()-1) do ( if not(i) or challengers[i - 1+1] /= challengers[i+1] then ( k := k - 1 ) else skip ; if not(k) then ( stdout.write(challengers[i+1]) ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=3 M=7 def printOriginalMatrix(a,b,mat): for i in range(N): for j in range(M): if(mat[i][j]==1): print(min(a[i],b[j]),end=" "); else : print(0,end=" "); print() if __name__=="__main__" : a=[2,1,3] b=[2,3,0,0,2,0,1] mat=[[1,0,0,0,1,0,0],[0,0,0,0,0,0,1],[1,1,0,0,0,0,0]]; printOriginalMatrix(a,b,mat); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 3 ; var M : int := 7 ; skip ; if __name__ = "__main__" then ( a := Sequence{2}->union(Sequence{1}->union(Sequence{ 3 })) ; b := Sequence{2}->union(Sequence{3}->union(Sequence{0}->union(Sequence{0}->union(Sequence{2}->union(Sequence{0}->union(Sequence{ 1 })))))) ; mat := Sequence{Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 0 }))))))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 1 }))))))}->union(Sequence{ Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))))) })); ; printOriginalMatrix(a, b, mat); ) else skip; operation printOriginalMatrix(a : OclAny, b : OclAny, mat : OclAny) pre: true post: true activity: for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, M-1) do ( if (mat[i+1][j+1] = 1) then ( execute (Set{a[i+1], b[j+1]}->min())->display(); ) else ( execute (0)->display(); )) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printPattern(n): for i in range(1,n+1): for j in range(1,2*n): if(j==(n-i+1)or j==(n+i-1)): print("*",end="") elif((i>=4 and i<=n-4)and(j==n-i+4 or j==n+i-4)): print("*",end="") elif(i==n or(i==n-4 and j>=n-(n-2*4)and j<=n+n-2*4)): print("*",end="") else : print(""+"",end="") print() N=9 printPattern(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 9 ; printPattern(N); operation printPattern(n : OclAny) pre: true post: true activity: for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, 2 * n-1) do ( if (j = (n - i + 1) or j = (n + i - 1)) then ( execute ("*")->display() ) else (if ((i >= 4 & (i->compareTo(n - 4)) <= 0) & (j = n - i + 4 or j = n + i - 4)) then ( execute ("*")->display() ) else (if (i = n or (i = n - 4 & (j->compareTo(n - (n - 2 * 4))) >= 0 & (j->compareTo(n + n - 2 * 4)) <= 0)) then ( execute ("*")->display() ) else ( execute ("" + "")->display() ) ) ) ) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getPaintCount(string,color): return len(string)-string.count(color) N,M=map(int,input().split()) A=[] cnt=0 for i in range(N): s=input().strip() if i==0 : cnt+=getPaintCount(s,'W') elif i==N-1 : cnt+=getPaintCount(s,'R') else : A.append(s) B=[] for w in range(0,N-1): for b in range(1,N-w): r=N-2-w-b if r>=0 : B.append([w,b,N-2-w-b]) minmin=2500 cnt2=0 for b in B : for i in range(len(A)): if icollect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := Sequence{} ; var cnt : int := 0 ; for i : Integer.subrange(0, N-1) do ( var s : OclAny := input()->trim() ; if i = 0 then ( cnt := cnt + getPaintCount(s, 'W') ) else (if i = N - 1 then ( cnt := cnt + getPaintCount(s, 'R') ) else ( execute ((s) : A) ) ) ) ; var B : Sequence := Sequence{} ; for w : Integer.subrange(0, N - 1-1) do ( for b : Integer.subrange(1, N - w-1) do ( var r : double := N - 2 - w - b ; if r >= 0 then ( execute ((Sequence{w}->union(Sequence{b}->union(Sequence{ N - 2 - w - b }))) : B) ) else skip)) ; var minmin : int := 2500 ; var cnt2 : int := 0 ; for b : B do ( for i : Integer.subrange(0, (A)->size()-1) do ( if (i->compareTo(b->first())) < 0 then ( cnt2 := cnt2 + getPaintCount(A[i+1], 'W') ) else (if (b->first()->compareTo(i)) <= 0 & (i < b->first() + b[1+1]) then ( cnt2 := cnt2 + getPaintCount(A[i+1], 'B') ) else (if (b->first() + b[1+1]->compareTo(i)) <= 0 & (i < b->first() + b[1+1] + b[2+1]) then ( cnt2 := cnt2 + getPaintCount(A[i+1], 'R') ) else skip ) ) ) ; if (cnt2->compareTo(minmin)) < 0 then ( minmin := cnt2 ) else skip ; cnt2 := 0) ; execute (cnt + minmin)->display(); operation getPaintCount(string : OclAny, color : OclAny) : OclAny pre: true post: true activity: return (string)->size() - string->count(color); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break else : A=[0]*(n+10) A[0]=1 A[1]=1 A[2]=2 if n==1 : print(1) elif n==2 : print(1) else : for i in range(3,(n+1)): A[i]=A[i-1]+A[i-2]+A[i-3] print((A[n])//3650+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else ( var A : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 10)) ; A->first() := 1 ; A[1+1] := 1 ; A[2+1] := 2 ; if n = 1 then ( execute (1)->display() ) else (if n = 2 then ( execute (1)->display() ) else ( for i : Integer.subrange(3, (n + 1)-1) do ( A[i+1] := A[i - 1+1] + A[i - 2+1] + A[i - 3+1]) ; execute ((A[n+1]) div 3650 + 1)->display() ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def stairs(N): dp=[0]*(N+5) dp[0]=1 for i in range(N+1): dp[i+1]+=dp[i] dp[i+2]+=dp[i] dp[i+3]+=dp[i] d,v=divmod(dp[N],10) days=d+1 if v else d d,v=divmod(days,365) years=d+1 if v else d print(years) while True : N=int(input()) if N==0 : exit() stairs(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( exit() ) else skip ; stairs(N)); operation stairs(N : OclAny) pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 5)) ; dp->first() := 1 ; for i : Integer.subrange(0, N + 1-1) do ( dp[i + 1+1] := dp[i + 1+1] + dp[i+1] ; dp[i + 2+1] := dp[i + 2+1] + dp[i+1] ; dp[i + 3+1] := dp[i + 3+1] + dp[i+1]) ; var d : OclAny := null; var v : OclAny := null; Sequence{d,v} := Sequence{(dp[N+1] div 10), (dp[N+1] mod 10)} ; var days : OclAny := if v then d + 1 else d endif ; var d : OclAny := null; var v : OclAny := null; Sequence{d,v} := Sequence{(days div 365), (days mod 365)} ; var years : OclAny := if v then d + 1 else d endif ; execute (years)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import division,print_function try : input=raw_input except NameError : pass memo=[0]*31 def solve(x): if memo[x]==0 : if x>0 : memo[x]=solve(x-1)+solve(x-2)+solve(x-3) return memo[x] elif x==0 : memo[x]=1 return 1 else : return 0 else : return memo[x] def main(): while True : inp=int(input()) if inp==0 : break print((solve(inp)-1)//3650+1) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; try ( var input : OclAny := raw_input) (except_clause except (test (logical_test (comparison (expr (atom (name NameError)))))) : (suite (stmt (simple_stmt (small_stmt pass))))) ; var memo : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 31) ; skip ; skip ; main(); operation solve(x : OclAny) : OclAny pre: true post: true activity: if memo[x+1] = 0 then ( if x > 0 then ( memo[x+1] := solve(x - 1) + solve(x - 2) + solve(x - 3) ; return memo[x+1] ) else (if x = 0 then ( memo[x+1] := 1 ; return 1 ) else ( return 0 ) ) ) else ( return memo[x+1] ); operation main() pre: true post: true activity: while true do ( var inp : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if inp = 0 then ( break ) else skip ; execute ((solve(inp) - 1) div 3650 + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==1 : print("Hello World") else : print(sum([int(input())for i in range(2)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute ("Hello World")->display() ) else ( execute ((Integer.subrange(0, 2-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())))->sum())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- steps=[] step=int(input()) while step!=0 : steps.append(step) step=int(input()) max_step=max(steps) nums=[1,2,4]+[0 for _ in range(3,max_step)] for i in range(3,max_step): nums[i]=nums[i-1]+nums[i-2]+nums[i-3] for step in steps : year_minus=nums[step-1]//-3650 print(str(-year_minus)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var steps : Sequence := Sequence{} ; var step : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while step /= 0 do ( execute ((step) : steps) ; step := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var max_step : OclAny := (steps)->max() ; var nums : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{ 4 }))->union(Integer.subrange(3, max_step-1)->select(_anon | true)->collect(_anon | (0))) ; for i : Integer.subrange(3, max_step-1) do ( nums[i+1] := nums[i - 1+1] + nums[i - 2+1] + nums[i - 3+1]) ; for step : steps do ( var year_minus : int := nums[step - 1+1] div -3650 ; execute (("" + ((-year_minus))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nob(n): nob_h=[n+1] for i in range(n+1): if i==0 or i==1 : nob_h.append(1) elif i==2 : nob_h.append(2) elif i>2 : nob_h.append(nob_h[i]+nob_h[i-1]+nob_h[i-2]) days=int(nob_h[n+1]/10) year=int(days/365)+1 print(year) n=[] while True : i=input() if i=="0" : break n.append(i) for i in range(len(n)): nob(int(n[i])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := Sequence{} ; while true do ( var i : String := (OclFile["System.in"]).readLine() ; if i = "0" then ( break ) else skip ; execute ((i) : n)) ; for i : Integer.subrange(0, (n)->size()-1) do ( nob(("" + ((n->at(i))))->toInteger())); operation nob(n : OclAny) pre: true post: true activity: var nob_h : Sequence := Sequence{ n + 1 } ; for i : Integer.subrange(0, n + 1-1) do ( if i = 0 or i = 1 then ( execute ((1) : nob_h) ) else (if i = 2 then ( execute ((2) : nob_h) ) else (if i > 2 then ( execute ((nob_h[i+1] + nob_h[i - 1+1] + nob_h[i - 2+1]) : nob_h) ) else skip ) ) ) ; var days : int := ("" + ((nob_h[n + 1+1] / 10)))->toInteger() ; var year : int := ("" + ((days / 365)))->toInteger() + 1 ; execute (year)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=10 y=5 x=x*y y=x//y ; x=x//y ; print("After Swapping: x=",x," y=",y); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 10 ; var y : int := 5 ; x := x * y ; y := x div y; ; x := x div y; ; execute ("After Swapping: x=")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- M,N=map(int,input().split()) K=int(input()) P=['_'*(N+1)for _ in range(M+1)] for mi in range(1,M+1): P[mi]='_'+input() J=[[0 for _ in range(N+1)]for _ in range(M+1)] O=[[0 for _ in range(N+1)]for _ in range(M+1)] I=[[0 for _ in range(N+1)]for _ in range(M+1)] for i in range(1,M+1): ji,oi,ii=0,0,0 for j in range(1,N+1): ji+=P[i][j]=='J' oi+=P[i][j]=='O' ii+=P[i][j]=='I' J[i][j]=J[i-1][j]+ji O[i][j]=O[i-1][j]+oi I[i][j]=I[i-1][j]+ii def cum(mat,a,b,c,d): a-=1 b-=1 return mat[a][b]+mat[c][d]-mat[a][d]-mat[c][b] for k in range(K): a,b,c,d=map(int,input().split()) j=cum(J,a,b,c,d) o=cum(O,a,b,c,d) i=cum(I,a,b,c,d) print(j,o,i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var M : OclAny := null; var N : OclAny := null; Sequence{M,N} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var P : Sequence := Integer.subrange(0, M + 1-1)->select(_anon | true)->collect(_anon | (StringLib.nCopies('_', (N + 1)))) ; for mi : Integer.subrange(1, M + 1-1) do ( P[mi+1] := '_' + (OclFile["System.in"]).readLine()) ; var J : Sequence := Integer.subrange(0, M + 1-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (0)))) ; var O : Sequence := Integer.subrange(0, M + 1-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (0)))) ; var I : Sequence := Integer.subrange(0, M + 1-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (0)))) ; for i : Integer.subrange(1, M + 1-1) do ( var ji : OclAny := null; var oi : OclAny := null; var ii : OclAny := null; Sequence{ji,oi,ii} := Sequence{0,0,0} ; for j : Integer.subrange(1, N + 1-1) do ( ji := ji + P[i+1][j+1] = 'J' ; oi := oi + P[i+1][j+1] = 'O' ; ii := ii + P[i+1][j+1] = 'I' ; J[i+1][j+1] := J[i - 1+1][j+1] + ji ; O[i+1][j+1] := O[i - 1+1][j+1] + oi ; I[i+1][j+1] := I[i - 1+1][j+1] + ii)) ; skip ; for k : Integer.subrange(0, K-1) do ( Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var j : OclAny := cum(J, a, b, c, d) ; var o : OclAny := cum(O, a, b, c, d) ; var i : OclAny := cum(I, a, b, c, d) ; execute (j)->display()); operation cum(mat : OclAny, a : OclAny, b : OclAny, c : OclAny, d : OclAny) : OclAny pre: true post: true activity: a := a - 1 ; b := b - 1 ; return mat[a+1][b+1] + mat[c+1][d+1] - mat[a+1][d+1] - mat[c+1][b+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): m,n=map(int,input().split()) k=int(input()) mp=[input()for i in range(m)] dp=[[[0]*3 for j in range(n+1)]for i in range(m+1)] dic={"J" : 0,"O" : 1,"I" : 2} for i in range(1,m+1): dpi=dp[i] dpi_1=dp[i-1] for j in range(1,n+1): dpij=dpi[j] dpij_1=dpi[j-1] dpi_1j=dpi_1[j] dpi_1j_1=dpi_1[j-1] for p in range(3): dpij[p]=dpij_1[p]+dpi_1j[p]-dpi_1j_1[p] dpij[dic[mp[i-1][j-1]]]+=1 ans="" for i in range(k): x1,y1,x2,y2=map(int,input().split()) dpx2=dp[x2] dpx1=dp[x1-1] dpx2y2=dpx2[y2] dpx2y1=dpx2[y1-1] dpx1y2=dpx1[y2] dpx1y1=dpx1[y1-1] ans+=str(dpx2y2[0]-dpx1y2[0]-dpx2y1[0]+dpx1y1[0])+" "+str(dpx2y2[1]-dpx1y2[1]-dpx2y1[1]+dpx1y1[1])+" "+str(dpx2y2[2]-dpx1y2[2]-dpx2y1[2]+dpx1y1[2])+"\n" ans=ans.rstrip() print(ans) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mp : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var dp : Sequence := Integer.subrange(0, m + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (MatrixLib.elementwiseMult(Sequence{ 0 }, 3))))) ; var dic : Map := Map{ "J" |-> 0 }->union(Map{ "O" |-> 1 }->union(Map{ "I" |-> 2 })) ; for i : Integer.subrange(1, m + 1-1) do ( var dpi : OclAny := dp[i+1] ; var dpi var dpi : OclAny := dp[i+1] : OclAny := dp[i - 1+1] ; for j : Integer.subrange(1, n + 1-1) do ( var dpij : OclAny := dpi[j+1] ; var dpij var dpij : OclAny := dpi[j+1] : OclAny := dpi[j - 1+1] ; var dpi var dpij : OclAny := dpi[j+1]j : OclAny := dpi var dpij : OclAny := dpi[j+1][j+1] ; var dpi var dpij : OclAny := dpi[j+1]j var dpij : OclAny := dpi[j+1] : OclAny := dpi var dpij : OclAny := dpi[j+1][j - 1+1] ; for p : Integer.subrange(0, 3-1) do ( dpij[p+1] := dpij var dpij : OclAny := dpi[j+1][p+1] + dpi var dpij : OclAny := dpi[j+1]j[p+1] - dpi var dpij : OclAny := dpi[j+1]j var dpij : OclAny := dpi[j+1][p+1]) ; dpij[dic[mp[i - 1+1][j - 1+1]+1]+1] := dpij[dic[mp[i - 1+1][j - 1+1]+1]+1] + 1)) ; var ans : String := "" ; for i : Integer.subrange(0, k-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dpx2 : OclAny := dp[x2+1] ; var dpx1 : OclAny := dp[x1 - 1+1] ; var dpx2y2 : OclAny := dpx2[y2+1] ; var dpx2y1 : OclAny := dpx2[y1 - 1+1] ; var dpx1y2 : OclAny := dpx1[y2+1] ; var dpx1y1 : OclAny := dpx1[y1 - 1+1] ; ans := ans + ("" + ((dpx2y2->first() - dpx1y2->first() - dpx2y1->first() + dpx1y1->first()))) + " " + ("" + ((dpx2y2[1+1] - dpx1y2[1+1] - dpx2y1[1+1] + dpx1y1[1+1]))) + " " + ("" + ((dpx2y2[2+1] - dpx1y2[2+1] - dpx2y1[2+1] + dpx1y1[2+1]))) + "\n") ; ans := StringLib.rightTrim(ans) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.readline().strip() m,n=map(int,input().split()) k=int(input()) joi=dict() joi["J"]=0 joi["O"]=1 joi["I"]=2 mnj=[[0]*(n+1)for i in range(m+1)] mno=[[0]*(n+1)for i in range(m+1)] mni=[[0]*(n+1)for i in range(m+1)] for i in range(1,m+1): mns=input() mnii=[0]*3 for ii in range(1,n+1): mnii[joi[mns[ii-1]]]+=1 mnj[i][ii]=mnj[i-1][ii]+mnii[0] mno[i][ii]=mno[i-1][ii]+mnii[1] mni[i][ii]=mni[i-1][ii]+mnii[2] s=[0]*3 for j in range(k): aj,bj,cj,dj=map(int,input().split()) aj-=1 bj-=1 sj=mnj[cj][dj]-mnj[aj][dj]-mnj[cj][bj]+mnj[aj][bj] so=mno[cj][dj]-mno[aj][dj]-mno[cj][bj]+mno[aj][bj] si=mni[cj][dj]-mni[aj][dj]-mni[cj][bj]+mni[aj][bj] print(sj,so,si) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var joi : Map := (arguments ( )) ; joi->at("J") := 0 ; joi->at("O") := 1 ; joi->at("I") := 2 ; var mnj : Sequence := Integer.subrange(0, m + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)))) ; var mno : Sequence := Integer.subrange(0, m + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)))) ; var mni : Sequence := Integer.subrange(0, m + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)))) ; for i : Integer.subrange(1, m + 1-1) do ( var mns : String := (OclFile["System.in"]).readLine() ; var mnii : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 3) ; for ii : Integer.subrange(1, n + 1-1) do ( mnii[joi[mns[ii - 1+1]+1]+1] := mnii[joi[mns[ii - 1+1]+1]+1] + 1 ; mnj[i+1][ii+1] := mnj[i - 1+1][ii+1] + mnii->first() ; mno[i+1][ii+1] := mno[i - 1+1][ii+1] + mnii[1+1] ; mni[i+1][ii+1] := mni[i - 1+1][ii+1] + mnii[2+1])) ; var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 3) ; for j : Integer.subrange(0, k-1) do ( var aj : OclAny := null; var bj : OclAny := null; var cj : OclAny := null; var dj : OclAny := null; Sequence{aj,bj,cj,dj} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; aj := aj - 1 ; bj := bj - 1 ; var sj : double := mnj[cj+1][dj+1] - mnj[aj+1][dj+1] - mnj[cj+1][bj+1] + mnj[aj+1][bj+1] ; var so : double := mno[cj+1][dj+1] - mno[aj+1][dj+1] - mno[cj+1][bj+1] + mno[aj+1][bj+1] ; var si : double := mni[cj+1][dj+1] - mni[aj+1][dj+1] - mni[cj+1][bj+1] + mni[aj+1][bj+1] ; execute (sj)->display()); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- M,N=list(map(int,input().split())) q=int(input()) Map=[] for i in range(M): Map.append(input()) def get_slide_sum(Map,kw): l=[] for r in range(M): tmp=[] for c in range(N): ll=0 if c==0 else tmp[c-1] ul=0 if r==0 or c==0 else l[r-1][c-1] ur=0 if r==0 else l[r-1][c] count=ll+ur-ul if Map[r][c]==kw : count+=1 tmp.append(count) l.append(tmp) return l J=get_slide_sum(Map,'J') O=get_slide_sum(Map,'O') I=get_slide_sum(Map,'I') def get_sum(inp,L): a,b,c,d=list(map(int,inp.split())) ll=0 if a==1 else L[a-2][d-1] ul=0 if a==1 or b==1 else L[a-2][b-2] ur=0 if b==1 else L[c-1][b-2] return L[c-1][d-1]-ll-ur+ul for i in range(q): inp=input() print(get_sum(inp,J),get_sum(inp,O),get_sum(inp,I)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var M : OclAny := null; var N : OclAny := null; Sequence{M,N} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var Map : Sequence := Sequence{} ; for i : Integer.subrange(0, M-1) do ( execute (((OclFile["System.in"]).readLine()) : Map)) ; skip ; var J : OclAny := get_slide_sum(Map, 'J') ; var O : OclAny := get_slide_sum(Map, 'O') ; var I : OclAny := get_slide_sum(Map, 'I') ; skip ; for i : Integer.subrange(0, q-1) do ( inp := (OclFile["System.in"]).readLine() ; execute (get_sum(inp, J))->display()); operation get_slide_sum(Map : OclAny, kw : OclAny) : OclAny pre: true post: true activity: var l : Sequence := Sequence{} ; for r : Integer.subrange(0, M-1) do ( var tmp : Sequence := Sequence{} ; for c : Integer.subrange(0, N-1) do ( var ll : int := if c = 0 then 0 else tmp[c - 1+1] endif ; var ul : int := if r = 0 or c = 0 then 0 else l[r - 1+1][c - 1+1] endif ; var ur : int := if r = 0 then 0 else l[r - 1+1][c+1] endif ; var count : double := ll + ur - ul ; if Map[r+1][c+1] = kw then ( count := count + 1 ) else skip ; execute ((count) : tmp)) ; execute ((tmp) : l)) ; return l; operation get_sum(inp : OclAny, L : OclAny) : OclAny pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := ((inp.split())->collect( _x | (OclType["int"])->apply(_x) )) ; ll := if a = 1 then 0 else L[a - 2+1][d - 1+1] endif ; ul := if a = 1 or b = 1 then 0 else L[a - 2+1][b - 2+1] endif ; ur := if b = 1 then 0 else L[c - 1+1][b - 2+1] endif ; return L[c - 1+1][d - 1+1] - ll - ur + ul; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=list(map(int,input().split(' '))) colors=[] for i in range(N): row=list(input()) row_color=[0,0,0] for c in row : if c=='W' : row_color[0]+=1 elif c=='B' : row_color[1]+=1 elif c=='R' : row_color[2]+=1 colors.append(row_color) min_diff=float('inf') for blue_top in range(1,N-1): for red_top in range(blue_top+1,N): diff=0 for i in range(N): if icollect( _x | (OclType["int"])->apply(_x) )) ; var colors : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var row : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var row_color : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) ; for c : row do ( if c = 'W' then ( row_color->first() := row_color->first() + 1 ) else (if c = 'B' then ( row_color[1+1] := row_color[1+1] + 1 ) else (if c = 'R' then ( row_color[2+1] := row_color[2+1] + 1 ) else skip ) ) ) ; execute ((row_color) : colors)) ; var min_diff : double := ("" + (('inf')))->toReal() ; for blue_top : Integer.subrange(1, N - 1-1) do ( for red_top : Integer.subrange(blue_top + 1, N-1) do ( var diff : int := 0 ; for i : Integer.subrange(0, N-1) do ( if (i->compareTo(blue_top)) < 0 then ( diff := diff + colors[i+1][1+1] + colors[i+1][2+1] ) else (if (i->compareTo(red_top)) < 0 then ( diff := diff + colors[i+1]->first() + colors[i+1][2+1] ) else ( diff := diff + colors[i+1]->first() + colors[i+1][1+1] ) ) ) ; if (diff->compareTo(min_diff)) < 0 then ( min_diff := diff ) else skip)) ; execute (min_diff)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys H,W=map(int,input().split()) K=int(input()) cumsum=[[0]*(W+1)for _ in[0]*(H+1)] d1,d2=10**12,10**6 for y,_up in enumerate(cumsum[:-1],start=1): acc=0 for x,(up,c)in enumerate(zip(_up[1 :],sys.stdin.readline()),start=1): if c=="J" : acc+=d1 elif c=="O" : acc+=d2 else : acc+=1 cumsum[y][x]=acc+up ans=[] append=ans.append for y1,x1,y2,x2 in(map(int,l.split())for l in sys.stdin): x1-=1 y1-=1 v=cumsum[y2][x2]-cumsum[y1][x2]-cumsum[y2][x1]+cumsum[y1][x1] append("%d %d %d" %(v//d1,v % d1//d2,v % d2)) print(*ans,sep="\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cumsum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (H + 1))->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (W + 1)))) ; var d1 : OclAny := null; var d2 : OclAny := null; Sequence{d1,d2} := Sequence{(10)->pow(12),(10)->pow(6)} ; for _tuple : Integer.subrange(1, (cumsum->front(), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->size())->collect( _indx | Sequence{_indx-1, (cumsum->front(), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->at(_indx)} ) do (var _indx : int := 1; var y : OclAny := _tuple->at(_indx); _indx := _indx + 1; var _up : OclAny := _tuple->at(_indx); var acc : int := 0 ; for _tuple : Integer.subrange(1, (Integer.subrange(1, _up->tail()->size())->collect( _indx | Sequence{_up->tail()->at(_indx), (OclFile["System.in"]).readLine()->at(_indx)} ), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(1, _up->tail()->size())->collect( _indx | Sequence{_up->tail()->at(_indx), (OclFile["System.in"]).readLine()->at(_indx)} ), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{up, c} : OclAny := _tuple->at(_indx); if c = "J" then ( acc := acc + d1 ) else (if c = "O" then ( acc := acc + d2 ) else ( acc := acc + 1 ) ) ; cumsum[y+1][x+1] := acc + up)) ; var ans : Sequence := Sequence{} ; var append : OclAny := ans.append ; for _tuple : Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name l)) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name l)))) in (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin)))))))} do (var _indx : int := 1; var y1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y2 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x2 : OclAny := _tuple->at(_indx); x1 := x1 - 1 ; y1 := y1 - 1 ; var v : double := cumsum[y2+1][x2+1] - cumsum[y1+1][x2+1] - cumsum[y2+1][x1+1] + cumsum[y1+1][x1+1] ; append(StringLib.format("%d %d %d",Sequence{v div d1, v mod d1 div d2, v mod d2}))) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : N,W=map(int,input().split()) if not N : break s=list(sorted([int(input())for i in range(N)])) m=s[-1]//W+1 ss=[0]*m for c in s : ss[c//W]+=1 unit=max(ss) a=0 for i,c in enumerate(ss): a+=(1-i/(m-1))*(c/unit) print(a+0.01) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var N : OclAny := null; var W : OclAny := null; Sequence{N,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if not(N) then ( break ) else skip ; var s : Sequence := (Integer.subrange(0, N-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))->sort()) ; var m : int := s->last() div W + 1 ; var ss : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; for c : s do ( ss[c div W+1] := ss[c div W+1] + 1) ; var unit : OclAny := (ss)->max() ; var a : int := 0 ; for _tuple : Integer.subrange(1, (ss)->size())->collect( _indx | Sequence{_indx-1, (ss)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); a := a + (1 - i / (m - 1)) * (c / unit)) ; execute (a + 0.01)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- age=int(input()) if age==1 : print('Hello World') else : a,b=[int(input())for i in range(2)] print(a+b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var age : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if age = 1 then ( execute ('Hello World')->display() ) else ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Integer.subrange(0, 2-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; execute (a + b)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] while True : n,w=LI() if n==0 : break a=[I()for _ in range(n)] ma=max(a) l=(ma//w+1) b=[0]*l for c in a : b[c//w]+=1 h=max(b) r=0.01 for i in range(l): bi=b[i] d=(l-i-1)/(l-1) r+=d*bi/h rr.append(r) return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var n : OclAny := null; var w : OclAny := null; Sequence{n,w} := LI() ; if n = 0 then ( break ) else skip ; var a : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (I())) ; var ma : OclAny := (a)->max() ; var l : int := (ma div w + 1) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, l) ; for c : a do ( b[c div w+1] := b[c div w+1] + 1) ; var h : OclAny := (b)->max() ; var r : double := 0.01 ; for i : Integer.subrange(0, l-1) do ( var bi : OclAny := b[i+1] ; var d : double := (l - i - 1) / (l - 1) ; r := r + d * bi / h) ; execute ((r) : rr)) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,w=map(int,input().split()) if n is 0 and w is 0 : break l=[int(input())for i in range(n)] max_num=0 for i in range(n): max_num=max(max_num,l[i]) hist_size=int((max_num/w)+1) hist=[0.0]*int(hist_size) for i in range(n): hist[int(l[i]/w)]+=1 max_height=0 for i in range(hist_size): max_height=max(max_height,hist[i]) ans=0.0 for i in range(hist_size-1): ans+=hist[i]/max_height*(hist_size-1-i)/(hist_size-1) ans+=0.01 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var w : OclAny := null; Sequence{n,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n <>= 0 & w <>= 0 then ( break ) else skip ; var l : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var max_num : int := 0 ; for i : Integer.subrange(0, n-1) do ( max_num := Set{max_num, l[i+1]}->max()) ; var hist_size : int := ("" + (((max_num / w) + 1)))->toInteger() ; var hist : Sequence := MatrixLib.elementwiseMult(Sequence{ 0.0 }, ("" + ((hist_size)))->toInteger()) ; for i : Integer.subrange(0, n-1) do ( hist[("" + ((l[i+1] / w)))->toInteger()+1] := hist[("" + ((l[i+1] / w)))->toInteger()+1] + 1) ; var max_height : int := 0 ; for i : Integer.subrange(0, hist_size-1) do ( max_height := Set{max_height, hist[i+1]}->max()) ; var ans : double := 0.0 ; for i : Integer.subrange(0, hist_size - 1-1) do ( ans := ans + hist[i+1] / max_height * (hist_size - 1 - i) / (hist_size - 1)) ; ans := ans + 0.01 ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n,w=map(int,input().split()) if n==w==0 : break a=[0]*100 s=h=int(0) while n : b=int(input()) a[b//w]+=1 s=max(s,b//w) h=max(h,a[b//w]) n-=1 ans=0.01 for i in range(int(s)+1): ans+=a[i]/h*(s-i)/s print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : OclAny := null; var w : OclAny := null; Sequence{n,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = w & (w == 0) then ( break ) else skip ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100) ; var s : OclAny := ("" + ((0)))->toInteger(); var h : int := ("" + ((0)))->toInteger() ; while n do ( var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a[b div w+1] := a[b div w+1] + 1 ; s := Set{s, b div w}->max() ; h := Set{h, a[b div w+1]}->max() ; n := n - 1) ; var ans : double := 0.01 ; for i : Integer.subrange(0, ("" + ((s)))->toInteger() + 1-1) do ( ans := ans + a[i+1] / h * (s - i) / s) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n,w=map(int,input().split()) if n==0 : break dic={} mx=-1 max_section=-1 for i in range(1+100//w): dic[i]=0 for i in range(n): x=int(input()) dic[x//w]+=1 mx=max(mx,dic[x//w]) max_section=max(max_section,x//w) ans=0 for i in range(1+100//w): ans+=(dic[i]/mx)*(1-i*(1/(max_section))) print(ans+0.01) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : OclAny := null; var w : OclAny := null; Sequence{n,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var dic : OclAny := Set{} ; var mx : int := -1 ; var max_section : int := -1 ; for i : Integer.subrange(0, 1 + 100 div w-1) do ( dic[i+1] := 0) ; for i : Integer.subrange(0, n-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; dic[x div w+1] := dic[x div w+1] + 1 ; mx := Set{mx, dic[x div w+1]}->max() ; max_section := Set{max_section, x div w}->max()) ; var ans : int := 0 ; for i : Integer.subrange(0, 1 + 100 div w-1) do ( ans := ans + (dic[i+1] / mx) * (1 - i * (1 / (max_section)))) ; execute (ans + 0.01)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt MAX=1000000 prime=[True]*MAX def SieveOfEratosthenes(): for p in range(2,int(sqrt(MAX))+1): if(prime[p]): for i in range(p*p,MAX,p): prime[i]=False ; def sumPrime(k): SieveOfEratosthenes(); v=[]; for i in range(2,MAX): if(prime[i]): v.append(i); sum=0 ; skip=(k*(k-1))//2 ; while(k>0): sum+=v[skip]; skip+=1 ; k-=1 ; return sum ; if __name__=="__main__" : k=3 ; print(sumPrime(k)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MAX : int := 1000000 ; var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, MAX) ; skip ; skip ; if __name__ = "__main__" then ( k := 3; ; execute (sumPrime(k))->display(); ) else skip; operation SieveOfEratosthenes() pre: true post: true activity: for p : Integer.subrange(2, ("" + ((sqrt(MAX))))->toInteger() + 1-1) do ( if (prime[p+1]) then ( for i : Integer.subrange(p * p, MAX-1)->select( $x | ($x - p * p) mod p = 0 ) do ( prime[i+1] := false;) ) else skip); operation sumPrime(k : OclAny) pre: true post: true activity: SieveOfEratosthenes(); ; var v : Sequence := Sequence{}; ; for i : Integer.subrange(2, MAX-1) do ( if (prime[i+1]) then ( execute ((i) : v); ) else skip) ; var sum : int := 0; ; var skip : int := (k * (k - 1)) div 2; ; while (k > 0) do ( sum := sum + v[skip+1]; ; skip := skip + 1; ; k := k - 1;) ; return sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while(t>0): n=int(input()) l=list(map(int,input().strip().split()))[: n] a=[] l1=0 r=0 f=0 for i in range(len(l)): l1+=l[i] r+=l[n-i-1] if(l1<=0 or r<=0): f=1 break if(f==0): print("YES") else : print("NO") t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (t > 0) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : OclAny := OclType["Sequence"]((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ; var a : Sequence := Sequence{} ; var l1 : int := 0 ; var r : int := 0 ; var f : int := 0 ; for i : Integer.subrange(0, (l)->size()-1) do ( l1 := l1 + l[i+1] ; r := r + l[n - i - 1+1] ; if (l1 <= 0 or r <= 0) then ( f := 1 ; break ) else skip) ; if (f = 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) l=list(map(int,input().split())) a=0 for i in l : a+=i if a<=0 : print("NO") return a=0 for i in l[: :-1]: a+=i if a<=0 : print("NO") return print("YES") for _ in range(int(input())): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve()); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : int := 0 ; for i : l do ( a := a + i ; if a <= 0 then ( execute ("NO")->display() ; return ) else skip) ; a := 0 ; for i : l(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( a := a + i ; if a <= 0 then ( execute ("NO")->display() ; return ) else skip) ; execute ("YES")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(A): s=sum(A) l=0 r=0 curr=0 gmax=float('-INF') for i in range(len(A)): if curr+A[i]>A[i]: curr+=A[i] else : l=i curr=A[i] if curr>gmax : r=i gmax=max(gmax,curr) if s>gmax : return "YES" if s==gmax : if l==0 and r==len(A)-1 : return "YES" else : return "NO" return "NO" t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split()))[: n] print(solve(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ; execute (solve(a))->display()); operation solve(A : OclAny) : OclAny pre: true post: true activity: var s : OclAny := (A)->sum() ; var l : int := 0 ; var r : int := 0 ; var curr : int := 0 ; var gmax : double := ("" + (('-INF')))->toReal() ; for i : Integer.subrange(0, (A)->size()-1) do ( if (curr + A[i+1]->compareTo(A[i+1])) > 0 then ( curr := curr + A[i+1] ) else ( l := i ; curr := A[i+1] ) ; if (curr->compareTo(gmax)) > 0 then ( r := i ) else skip ; gmax := Set{gmax, curr}->max()) ; if (s->compareTo(gmax)) > 0 then ( return "YES" ) else skip ; if s = gmax then ( if l = 0 & r = (A)->size() - 1 then ( return "YES" ) else ( return "NO" ) ) else skip ; return "NO"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printPermutation(N,K): res=list(); l,r,flag=1,N,0 for i in range(K): if flag==False : res.append(l) l+=1 else : res.append(r); r-=1 ; flag=flag ^ 1 ; if flag==False : for i in range(r,2,-1): res.append(i) else : for i in range(l,r): res.append(i) for i in res : print(i,end=" ") N,K=10,4 printPermutation(N,K) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{N,K} := Sequence{10,4} ; printPermutation(N, K); operation printPermutation(N : OclAny, K : OclAny) pre: true post: true activity: var res : Sequence := (); ; var l : OclAny := null; var r : OclAny := null; var flag : OclAny := null; Sequence{l,r,flag} := Sequence{1,N,0} ; for i : Integer.subrange(0, K-1) do ( if flag = false then ( execute ((l) : res) ; l := l + 1 ) else ( execute ((r) : res); ; r := r - 1; ) ; var flag : int := MathLib.bitwiseXor(flag, 1);) ; if flag = false then ( for i : Integer.subrange(2 + 1, r)->reverse() do ( execute ((i) : res)) ) else ( for i : Integer.subrange(l, r-1) do ( execute ((i) : res)) ) ; for i : res do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque,Counter from math import* import sys import random from bisect import* from functools import reduce from sys import stdin from heapq import* import copy input=lambda : sys.stdin.readline().rstrip() def fin(arr): s=0 i=0 while i=0 : s+=arr[i] if s<=0 : return False i-=1 return True for _ in range(int(input())): n=int(input()) arr=list(map(int,input().split())) print("YES" if fin(arr)==True else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; arr := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (if fin(arr) = true then "YES" else "NO" endif)->display()); operation fin(arr : OclAny) : OclAny pre: true post: true activity: var s : int := 0 ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( s := s + arr[i+1] ; if s <= 0 then ( return false ) else skip ; i := i + 1) ; i := (arr)->size() - 1 ; s := 0 ; while i >= 0 do ( s := s + arr[i+1] ; if s <= 0 then ( return false ) else skip ; i := i - 1) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def extractMaximum(ss): num,res=0,0 for i in range(len(ss)): if ss[i]>="0" and ss[i]<="9" : num=num*10+int(int(ss[i])-0) else : res=max(res,num) num=0 return max(res,num) ss="100klh564abc365bg" print(extractMaximum(ss)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; ss := "100klh564abc365bg" ; execute (extractMaximum(ss))->display(); operation extractMaximum(ss : OclAny) : OclAny pre: true post: true activity: var num : OclAny := null; var res : OclAny := null; Sequence{num,res} := Sequence{0,0} ; for i : Integer.subrange(0, (ss)->size()-1) do ( if ss[i+1] >= "0" & ss[i+1] <= "9" then ( var num : double := num * 10 + ("" + ((("" + ((ss[i+1])))->toInteger() - 0)))->toInteger() ) else ( var res : OclAny := Set{res, num}->max() ; num := 0 )) ; return Set{res, num}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) l=list(map(int,input().split())) s=sum(l) k=0 f=True for i in range(n-1): k=k+l[i] if k<=0 or k>=s : f=False print("NO") break if f : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : OclAny := (l)->sum() ; var k : int := 0 ; var f : boolean := true ; for i : Integer.subrange(0, n - 1-1) do ( k := k + l[i+1] ; if k <= 0 or (k->compareTo(s)) >= 0 then ( f := false ; execute ("NO")->display() ; break ) else skip) ; if f then ( execute ("YES")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000005 prime=[True for i in range(MAX)] def seive(N): prime[0],prime[1]=False,False for i in range(2,N+1): if(prime[i]): for j in range(2,N+1): if(i*j>N): break prime[i*j]=False def countLogNeeded(N): count=0 seive(N) for i in range(1,N+1): if(prime[i]): count=count+1 return count if __name__=='__main__' : N=6 print(countLogNeeded(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1000005 ; var prime : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (true)) ; skip ; skip ; if __name__ = '__main__' then ( N := 6 ; execute (countLogNeeded(N))->display() ) else skip; operation seive(N : OclAny) pre: true post: true activity: var prime->first() : OclAny := null; var prime[1+1] : OclAny := null; Sequence{prime->first(),prime[1+1]} := Sequence{false,false} ; for i : Integer.subrange(2, N + 1-1) do ( if (prime[i+1]) then ( for j : Integer.subrange(2, N + 1-1) do ( if ((i * j->compareTo(N)) > 0) then ( break ) else skip ; prime[i * j+1] := false) ) else skip); operation countLogNeeded(N : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; seive(N) ; for i : Integer.subrange(1, N + 1-1) do ( if (prime[i+1]) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=str(input()) k="aieou" m="02468" h=0 for i in range(0,len(x)): p=x[i] if p.isdigit(): j=int(p) if j % 2!=0 : h+=1 if(k.find(x[i])size()-1) do ( var p : OclAny := x[i+1] ; if p->matches("[0-9]*") then ( var j : int := ("" + ((p)))->toInteger() ; if j mod 2 /= 0 then ( h := h + 1 ) else skip ) else skip ; if ((k->indexOf(x[i+1]) - 1->compareTo((k)->size())) < 0 & k->indexOf(x[i+1]) - 1 /= -1) then ( h := h + 1 ) else skip) ; execute (h)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def need_flip(card): verifications=set({'a','e','i','o','u','1','3','5','7','9'}) return card in verifications flips=0 for card in input(): if need_flip(card): flips+=1 print(flips) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var flips : int := 0 ; for card : (OclFile["System.in"]).readLine() do ( if need_flip(card) then ( flips := flips + 1 ) else skip) ; execute (flips)->display(); operation need_flip(card : OclAny) : OclAny pre: true post: true activity: var verifications : Set := Set{}->union((Set{'a'}->union(Set{'e'}->union(Set{'i'}->union(Set{'o'}->union(Set{'u'}->union(Set{'1'}->union(Set{'3'}->union(Set{'5'}->union(Set{'7'}->union(Set{ '9' }))))))))))) ; return (verifications)->includes(card); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- entrada=str(input()) viradas=0 vogais=['a','e','i','o','u'] impares=['1','3','5','7','9'] for i in range(len(entrada)): if(entrada[i]in vogais)or(entrada[i]in impares): viradas+=1 print(viradas) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var entrada : String := ("" + (((OclFile["System.in"]).readLine()))) ; var viradas : int := 0 ; var vogais : Sequence := Sequence{'a'}->union(Sequence{'e'}->union(Sequence{'i'}->union(Sequence{'o'}->union(Sequence{ 'u' })))) ; var impares : Sequence := Sequence{'1'}->union(Sequence{'3'}->union(Sequence{'5'}->union(Sequence{'7'}->union(Sequence{ '9' })))) ; for i : Integer.subrange(0, (entrada)->size()-1) do ( if ((vogais)->includes(entrada[i+1])) or ((impares)->includes(entrada[i+1])) then ( viradas := viradas + 1 ) else skip) ; execute (viradas)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numbers='13579' vowels='aeiou' count=0 cards=input() for card in cards : if card in vowels or card in numbers : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var numbers : String := '13579' ; var vowels : String := 'aeiou' ; var count : int := 0 ; var cards : String := (OclFile["System.in"]).readLine() ; for card : cards->characters() do ( if (vowels)->characters()->includes(card) or (numbers)->characters()->includes(card) then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import os import random import re import sys from math import gcd from math import sqrt from collections import Counter s=input() li=[] st=0 count=0 p=[] t='aeiou13579' for i in s : if i in t : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var s : String := (OclFile["System.in"]).readLine() ; var li : Sequence := Sequence{} ; var st : int := 0 ; var count : int := 0 ; var p : Sequence := Sequence{} ; var t : String := 'aeiou13579' ; for i : s->characters() do ( if (t)->characters()->includes(i) then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq n=int(input()) INF=2147483647 G=[[]for i in range(n)] check,dist=[0 for i in range(n)],[INF for i in range(n)] def dijkstra(s): dist[s],pq=0,[] heapq.heappush(pq,(0,s)) while len(pq)!=0 : u=heapq.heappop(pq) check[u[1]]=2 if dist[u[1]]toInteger() ; var INF : int := 2147483647 ; var G : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; var check : OclAny := null; var dist : OclAny := null; Sequence{check,dist} := Sequence{Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)),Integer.subrange(0, n-1)->select(i | true)->collect(i | (INF))} ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation dijkstra(s : OclAny) pre: true post: true activity: var dist[s+1] : OclAny := null; var pq : OclAny := null; Sequence{dist[s+1],pq} := Sequence{0,Sequence{}} ; heapq.heappush(pq, Sequence{0, s}) ; while (pq)->size() /= 0 do ( var u : OclAny := heapq.heappop(pq) ; check[u[1+1]+1] := 2 ; if (dist[u[1+1]+1]->compareTo(u->first())) < 0 then ( continue ) else skip ; for v : G[u[1+1]+1] do ( if check[v->first()+1] /= 2 then ( if (dist[u[1+1]+1] + v[1+1]->compareTo(dist[v->first()+1])) < 0 then ( var dist[v->first()+1] : OclAny := null; var check[v->first()+1] : OclAny := null; Sequence{dist[v->first()+1],check[v->first()+1]} := Sequence{dist[u[1+1]+1] + v[1+1],1} ; heapq.heappush(pq, Sequence{dist[v->first()+1], v->first()}) ) else skip ) else skip)); operation main() pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( var data : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, data[1+1]-1) do ((expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name data)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name data)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 1))))))))) ))))))))) ])))))) , (test (logical_test (comparison (expr (atom (name data)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (number (integer 2)))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 1))))))))) )))) + (expr (atom (number (integer 1)))))))))) ]))))))) )))))))) )))))) ; dijkstra(0) ; for i : Integer.subrange(0, n-1) do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import heapq as hp WHITE,GRAY,BLACK=0,1,2 D_MAX=int(5e10+1) def generate_adj_table(v_table): for each in v_table : v_index,v_adj_length,*v_adj_list=map(int,each) assert len(v_adj_list)==v_adj_length*2 for pair in zip(v_adj_list[: : 2],v_adj_list[1 : : 2]): init_adj_table[v_index][pair[0]]=pair[1] return init_adj_table def dijkstra_path_heap(): path_list[init_vertex]=0 path_heap=[] hp.heappush(path_heap,(0,init_vertex)) while len(path_heap)>=1 : current_vertex=hp.heappop(path_heap)[1] color[current_vertex]=BLACK for adj_vertex,adj_weight in adj_table[current_vertex].items(): if color[adj_vertex]is not BLACK : alt_path=path_list[current_vertex]+adj_weight if alt_pathtoReal() + 1)))->toInteger() ; skip ; skip ; if __name__ = '__main__' then ( var _input : OclAny := (OclFile["System.in"]).readlines() ; var vertices_num : int := ("" + ((_input->first())))->toInteger() ; var init_vertices_table : Sequence := (_input->tail())->collect( _x | (lambda x : OclAny in (x.split()))->apply(_x) ) ; var parent_list : OclAny := null; var path_list : OclAny := null; Sequence{parent_list,path_list} := Sequence{MatrixLib.elementwiseMult(Sequence{ -1 }, vertices_num),MatrixLib.elementwiseMult(Sequence{ D_MAX }, vertices_num)} ; var color : Sequence := MatrixLib.elementwiseMult(Sequence{ WHITE }, vertices_num) ; var init_adj_table : Sequence := ((argument (test (logical_test (comparison (expr (atom (name dict)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name vertices_num)))))))) ))))))))) ; var init_vertex : int := 0 ; var adj_table : OclAny := generate_adj_table(init_vertices_table) ; var ans : OclAny := dijkstra_path_heap() ; for _tuple : Integer.subrange(1, (ans)->size())->collect( _indx | Sequence{_indx-1, (ans)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); execute (i)->display()) ) else skip; operation generate_adj_table(v_table : OclAny) : OclAny pre: true post: true activity: for each : v_table do ( var v_index : OclAny := null; var v_adj_length : OclAny := null; var v_adj_list : OclAny := null; Sequence{v_index,v_adj_length,v_adj_list} := (each)->collect( _x | (OclType["int"])->apply(_x) ) ; assert (v_adj_list)->size() = v_adj_length * 2 do "assertion failed" ; for pair : Integer.subrange(1, v_adj_list(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{v_adj_list(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->at(_indx), v_adj_list(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->at(_indx)} ) do ( init_adj_table[v_index+1][pair->first()+1] := pair[1+1])) ; return init_adj_table; operation dijkstra_path_heap() : OclAny pre: true post: true activity: path_list[init_vertex+1] := 0 ; var path_heap : Sequence := Sequence{} ; hp.heappush(path_heap, Sequence{0, init_vertex}) ; while (path_heap)->size() >= 1 do ( var current_vertex : OclAny := hp.heappop(path_heap)[1+1] ; color[current_vertex+1] := BLACK ; for _tuple : adj_table[current_vertex+1]->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var adj_vertex : OclAny := _tuple->at(_indx); _indx := _indx + 1; var adj_weight : OclAny := _tuple->at(_indx); if not(color[adj_vertex+1] <>= BLACK) then ( var alt_path : OclAny := path_list[current_vertex+1] + adj_weight ; if (alt_path->compareTo(path_list[adj_vertex+1])) < 0 then ( path_list[adj_vertex+1] := alt_path ; hp.heappush(path_heap, Sequence{alt_path, adj_vertex}) ; parent_list[adj_vertex+1] := current_vertex ; color[adj_vertex+1] := GRAY ) else skip ) else skip)) ; return path_list; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R,B,W,G=map(int,input().split()) print(R+B+W+G) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : OclAny := null; var B : OclAny := null; var W : OclAny := null; var G : OclAny := null; Sequence{R,B,W,G} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (R + B + W + G)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fact(N): product=1 for i in range(1,N+1): product=product*i return product def nthTerm(N): return(N*N)*fact(N) if __name__=="__main__" : N=4 print(nthTerm(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( N := 4 ; execute (nthTerm(N))->display() ) else skip; operation fact(N : OclAny) : OclAny pre: true post: true activity: var product : int := 1 ; for i : Integer.subrange(1, N + 1-1) do ( product := product * i) ; return product; operation nthTerm(N : OclAny) : OclAny pre: true post: true activity: return (N * N) * fact(N); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy from test.support import _MemoryWatchdog BIG_NUM=2000000000 HUGE_NUM=99999999999999999 MOD=1000000007 EPS=0.000000001 sys.setrecursionlimit(100000) class Edge : def __init__(self,arg_to,arg_dist): self.to=arg_to self.dist=arg_dist class Info : def __init__(self,arg_node_id,arg_sum_dist): self.node_id=arg_node_id self.sum_dist=arg_sum_dist def __lt__(self,another): return self.sum_dist0 : info=heappop(Q) if info.sum_dist>min_dist[info.node_id]: continue for e in G[info.node_id]: if min_dist[e.to]>info.sum_dist+e.dist : min_dist[e.to]=info.sum_dist+e.dist heappush(Q,Info(e.to,min_dist[e.to])) for i in range(V): print("%d %d" %(i,min_dist[i])) ------------------------------------------------------------ OCL File: --------- class Edge { static operation newEdge() : Edge pre: true post: Edge->exists( _x | result = _x ); attribute to : OclAny := arg_to; attribute dist : OclAny := arg_dist; operation initialise(arg_to : OclAny,arg_dist : OclAny) : Edge pre: true post: true activity: self.to := arg_to ; self.dist := arg_dist; return self; } class Info { static operation newInfo() : Info pre: true post: Info->exists( _x | result = _x ); attribute node_id : OclAny := arg_node_id; attribute sum_dist : OclAny := arg_sum_dist; operation initialise(arg_node_id : OclAny,arg_sum_dist : OclAny) : Info pre: true post: true activity: self.node_id := arg_node_id ; self.sum_dist := arg_sum_dist; return self; operation __lt__(another : OclAny) : OclAny pre: true post: true activity: return (self.sum_dist->compareTo(another.sum_dist)) < 0; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var HUGE_NUM : int := 99999999999999999 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; sys.setrecursionlimit(100000) ; skip ; skip ; var V : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var G : Sequence := Integer.subrange(0, V-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var min_dist : Sequence := MatrixLib.elementwiseMult(Sequence{ BIG_NUM }, V) ; for _anon : Integer.subrange(0, V-1) do ( var node_id : OclAny := null; var num_adj : OclAny := null; var tmp_array : OclAny := null; Sequence{node_id,num_adj,tmp_array} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, (tmp_array)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do ((expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name node_id)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name Edge)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name tmp_array)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name tmp_array)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])))))))) ))))))))) )))))) ; min_dist->first() := 0 ; var Q : Sequence := Sequence{} ; heappush(Q, (Info.newInfo()).initialise(0, 0)) ; while (Q)->size() > 0 do ( var info : OclAny := heappop(Q) ; if (info.sum_dist->compareTo(min_dist[info.node_id+1])) > 0 then ( continue ) else skip ; for e : G[info.node_id+1] do ( if (min_dist[e.to+1]->compareTo(info.sum_dist + e.dist)) > 0 then ( min_dist[e.to+1] := info.sum_dist + e.dist ; heappush(Q, (Info.newInfo()).initialise(e.to, min_dist[e.to+1])) ) else skip)) ; for i : Integer.subrange(0, V-1) do ( execute (StringLib.format("%d %d",Sequence{i, min_dist[i+1]}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import queue INFTY=1<<21 def dijkstra(n,EdgeMatrix,start): NodeList=queue.PriorityQueue() Distance=[INFTY]*n used=[False]*n Distance[start]=0 used[start]=True LastNode=start count=1 while countDistance[LastNode]+Edge[1]: Distance[Edge[0]]=Distance[LastNode]+Edge[1] NodeList.put([Distance[Edge[0]],Edge[0]]) while True : minNode=NodeList.get() if used[minNode[1]]==False : break LastNode=minNode[1] used[minNode[1]]=True count+=1 return Distance n=int(input()) EdgeMatrix=[[]for i in range(n)] for i in range(n): l=(list(map(int,input().split()))) for j in range(l[1]): EdgeMatrix[l[0]].append([l[2*j+2],l[2*j+3]]) Distance=dijkstra(n,EdgeMatrix,0) for node,distance in enumerate(Distance): print(node,distance) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var INFTY : int := 1 * (2->pow(21)) ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; EdgeMatrix := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, n-1) do ( var l : Sequence := (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; for j : Integer.subrange(0, l[1+1]-1) do ((expr (atom (name EdgeMatrix)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (number (integer 2)))) * (expr (atom (name j)))) + (expr (atom (number (integer 2)))))))))) ])))))) , (test (logical_test (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (number (integer 2)))) * (expr (atom (name j)))) + (expr (atom (number (integer 3)))))))))) ]))))))) ]))))))) )))))) ; Distance := dijkstra(n, EdgeMatrix, 0) ; for _tuple : Integer.subrange(1, (Distance)->size())->collect( _indx | Sequence{_indx-1, (Distance)->at(_indx)} ) do (var _indx : int := 1; var node : OclAny := _tuple->at(_indx); _indx := _indx + 1; var distance : OclAny := _tuple->at(_indx); execute (node)->display()); operation dijkstra(n : OclAny, EdgeMatrix : OclAny, start : OclAny) : OclAny pre: true post: true activity: var NodeList : OclAny := queue.PriorityQueue() ; var Distance : Sequence := MatrixLib.elementwiseMult(Sequence{ INFTY }, n) ; var used : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ; Distance[start+1] := 0 ; used[start+1] := true ; var LastNode : OclAny := start ; var count : int := 1 ; while (count->compareTo(n)) < 0 do ( for i : Integer.subrange(0, (EdgeMatrix[LastNode+1])->size()-1) do ( var Edge : OclAny := EdgeMatrix[LastNode+1][i+1] ; if used[Edge->first()+1] = false & (Distance[Edge->first()+1]->compareTo(Distance[LastNode+1] + Edge[1+1])) > 0 then ( Distance[Edge->first()+1] := Distance[LastNode+1] + Edge[1+1] ; NodeList.put(Sequence{Distance[Edge->first()+1]}->union(Sequence{ Edge->first() })) ) else skip) ; while true do ( var minNode : OclAny := NodeList.get() ; if used[minNode[1+1]+1] = false then ( break ) else skip) ; LastNode := minNode[1+1] ; used[minNode[1+1]+1] := true ; count := count + 1) ; return Distance; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heappop,heappush def dijkstra(s): dp[s]=0 hq=[] used[s]=0 for i in cost[s]: heappush(hq,i) while hq : minv=heappop(hq) if used[minv[1]]==0 : continue v=minv[1] dp[v]=minv[0] used[v]=0 for i in cost[v]: if used[i[1]]: heappush(hq,[i[0]+dp[v],i[1]]) return INF=10**18 n=int(input()) cost=[[]for _ in range(n)] used=[1]*n dp=[INF]*n for i in range(n): lst=list(map(int,input().split())) for j in range(lst[1]): v,c=lst[2+(2*j)],lst[3+(2*j)] cost[lst[0]].append([c,v]) dijkstra(0) for i in range(n): print(i,dp[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var INF : double := (10)->pow(18) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cost : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var used : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, n) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, n) ; for i : Integer.subrange(0, n-1) do ( var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, lst[1+1]-1) do ( var c : OclAny := null; Sequence{v,c} := Sequence{lst[2 + (2 * j)+1],lst[3 + (2 * j)+1]} ; (expr (atom (name cost)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name c)))))) , (test (logical_test (comparison (expr (atom (name v))))))) ]))))))) )))))) ; dijkstra(0) ; for i : Integer.subrange(0, n-1) do ( execute (i)->display()); operation dijkstra(s : OclAny) pre: true post: true activity: dp[s+1] := 0 ; var hq : Sequence := Sequence{} ; used[s+1] := 0 ; for i : cost[s+1] do ( heappush(hq, i)) ; while hq do ( var minv : OclAny := heappop(hq) ; if used[minv[1+1]+1] = 0 then ( continue ) else skip ; var v : OclAny := minv[1+1] ; dp[v+1] := minv->first() ; used[v+1] := 0 ; for i : cost[v+1] do ( if used[i[1+1]+1] then ( heappush(hq, Sequence{i->first() + dp[v+1]}->union(Sequence{ i[1+1] })) ) else skip)) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input('')) s=input('') l=[] m=[] c=0 k=s.split() for i in k : c=0 l=[] for j in range(len(i)): if ord(i[j])>=65 and ord(i[j])<=90 : c+=1 l.append(c) m.append(sum(l)) print(max(m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; var s : String := (OclFile["System.in"]).readLine('') ; var l : Sequence := Sequence{} ; var m : Sequence := Sequence{} ; var c : int := 0 ; var k : OclAny := s.split() ; for i : k do ( c := 0 ; l := Sequence{} ; for j : Integer.subrange(0, (i)->size()-1) do ( if (i[j+1])->char2byte() >= 65 & (i[j+1])->char2byte() <= 90 then ( c := c + 1 ) else skip) ; execute ((c) : l) ; execute (((l)->sum()) : m)) ; execute ((m)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import bisect import itertools import random import re def main(): n=int(input()) A=list(input().split()) B=[] for a in A : val=0 for c in a : if c.isupper(): val+=1 B.append(val) print(max(B)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := (input().split()) ; var B : Sequence := Sequence{} ; for a : A do ( var val : int := 0 ; for c : a do ( if c->matches("[A-Z ]*") then ( val := val + 1 ) else skip) ; execute ((val) : B)) ; execute ((B)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) s=input() h=[] for i in s.split(): h.append(len([j for j in i if j in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'])) print(max(h)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var h : Sequence := Sequence{} ; for i : s.split() do ( execute (((i->select(j | ('ABCDEFGHIJKLMNOPQRSTUVWXYZ')->characters()->includes(j))->collect(j | (j)))->size()) : h)) ; execute ((h)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input().split() m=0 for x in s : p=len([y for y in x if y>='A' and y<='Z']) if(p>m): m=p print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := input().split() ; var m : int := 0 ; for x : s do ( var p : int := (x->select(y | y >= 'A' & y <= 'Z')->collect(y | (y)))->size() ; if ((p->compareTo(m)) > 0) then ( m := p ) else skip) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) text=input() vol_text=0 for word in text.split(" "): vol_word=0 for ch in word : if ch>='A' and ch<='Z' : vol_word+=1 vol_text=max(vol_word,vol_text) print(vol_text) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var text : String := (OclFile["System.in"]).readLine() ; var vol_text : int := 0 ; for word : text.split(" ") do ( var vol_word : int := 0 ; for ch : word do ( if ch >= 'A' & ch <= 'Z' then ( vol_word := vol_word + 1 ) else skip) ; vol_text := Set{vol_word, vol_text}->max()) ; execute (vol_text)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,b): i=0 j=n-1 ans=[] while i0 : n=int(input()) b=[int(x)for x in input().split()] print(*solve(n,b),sep=' ') t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; b := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((argument * (test (logical_test (comparison (expr (atom (name solve)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n))))))) , (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))))))))->display() ; t := t - 1); operation solve(n : OclAny, b : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; var j : double := n - 1 ; var ans : Sequence := Sequence{} ; while (i->compareTo(j)) < 0 do ( execute ((b[i+1]) : ans) ; execute ((b[j+1]) : ans) ; i := i + 1 ; j := j - 1) ; if n mod 2 = 1 then ( execute ((b[i+1]) : ans) ) else skip ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a=int(input()) n=[int(i)for i in input().split()] s=[n.pop(0)] while n : s.append(n.pop(-1)) if n : s.append(n.pop(0)) print(*s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var s : Sequence := Sequence{ n->at(0`firstArg+1) } ; while n do ( execute ((n->at((atom - (number (integer 1)))+1)) : s) ; if n then ( execute ((n->at(0`firstArg+1)) : s) ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name s))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- max=50009 def find_Indices(arr,n): sum=[0 for i in range(max)] k=0 for i in range(1,n+1): sum[i]=sum[i-1]+arr[k]; k+=1 ans=-(1e15) index_1=index_2=index_3=-1 for l in range(n+1): index=0 vmin=(1e15) for r in range(l,n+1): if(sum[r]ans): ans=sum[l]+sum[r]-vmin index_1=l index_2=index index_3=r print(index_1," ",index_2," ",index_3) arr=[-1,2,3] n=len(arr) find_Indices(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var max : int := 50009 ; skip ; arr := Sequence{-1}->union(Sequence{2}->union(Sequence{ 3 })) ; n := (arr)->size() ; find_Indices(arr, n); operation find_Indices(arr : OclAny, n : OclAny) pre: true post: true activity: var sum : Sequence := Integer.subrange(0, max-1)->select(i | true)->collect(i | (0)) ; var k : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( [i+1]->sum() := [i - 1+1]->sum() + arr[k+1]; ; k := k + 1) ; var ans : double := -(("1e15")->toReal()) ; index var sum : Sequence := Integer.subrange(0, max-1)->select(i | true)->collect(i | (0)) := index var sum : Sequence := Integer.subrange(0, max-1)->select(i | true)->collect(i | (0))(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name index_2)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name index_3)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ; for l : Integer.subrange(0, n + 1-1) do ( var index : int := 0 ; var vmin : double := (("1e15")->toReal()) ; for r : Integer.subrange(l, n + 1-1) do ( if (([r+1]->sum()->compareTo(vmin)) < 0) then ( vmin := [r+1]->sum() ; index := r ) else skip ; if (([l+1]->sum() + [r+1]->sum() - vmin->compareTo(ans)) > 0) then ( ans := [l+1]->sum() + [r+1]->sum() - vmin ; var index ans := [l+1]->sum() + [r+1]->sum() - vmin : OclAny := l ; var index:= index : int := index ; var index_3 : OclAny := r ) else skip)) ; execute (indexindex(index(index(indexindex(index(index(indexindex(index(index(indexindex(index(index(indexindex(index(index(indexindex(index(index(indexindex(index(index var sum : Sequence := Integer.subrange(0, max-1)->select(i | true)->collect(i | (0)), " ", index_2, " ", index_3), " ", index_2, " ", index_3), " ", index_2, " ", index_3)->display(), " ", index_2, " ", index_3), " ", index_2, " ", index_3), " ", index_2, " ", index_3)->display(), " ", index_2, " ", index_3), " ", index_2, " ", index_3), " ", index_2, " ", index_3)->display(), " ", index_2, " ", index_3), " ", index_2, " ", index_3), " ", index_2, " ", index_3)->display(), " ", index_2, " ", index_3), " ", index_2, " ", index_3), " ", index_2, " ", index_3)->display(), " ", index_2, " ", index_3), " ", index_2, " ", index_3), " ", index_2, " ", index_3)->display(), " ", index_2, " ", index_3), " ", index_2, " ", index_3), " ", index_2, " ", index_3)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() list=x.split() sum=0 for i in list : sum+=int(i) print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := (OclFile["System.in"]).readLine() ; var OclType["Sequence"] : OclAny := x.split() ; var sum : int := 0 ; for i : OclType["Sequence"] do ( sum := sum + ("" + ((i)))->toInteger()) ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): g=int(input()) k=input().split() x="" l=[] t=0 while g>0 : if len(x)% 2==0 : l.append(k[t]) else : l.append(k[-t-1]) t+=1 g-=1 x+=str(1) print(' '.join(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var g : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : OclAny := input().split() ; var x : String := "" ; var l : Sequence := Sequence{} ; var t : int := 0 ; while g > 0 do ( if (x)->size() mod 2 = 0 then ( execute ((k[t+1]) : l) ) else ( execute ((k->reverse()->at(-(-t - 1))) : l) ; t := t + 1 ) ; g := g - 1 ; x := x + ("" + ((1)))) ; execute (StringLib.sumStringsWithSeparator((l), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().strip() for _ in ' '*int(input()): n=int(input()) a=list(map(int,input().split())) left=a[: :-1] count=[] ans=[] for i in range(n): count.append(a[i]) count.append(left[i]) if n % 2==0 : for i in range(n): ans.append(count[i]) else : for i in range(n+1): ans.append(count[i]) if len(ans)==n : print(*ans) else : ans2=[] for i in range(n): ans2.append(ans[i]) print(*ans2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine()->trim()) ; for _anon : StringLib.nCopies(' ', ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var left : OclAny := a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var count : Sequence := Sequence{} ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((a[i+1]) : count) ; execute ((left[i+1]) : count)) ; if n mod 2 = 0 then ( for i : Integer.subrange(0, n-1) do ( execute ((count[i+1]) : ans)) ) else ( for i : Integer.subrange(0, n + 1-1) do ( execute ((count[i+1]) : ans)) ) ; if (ans)->size() = n then ( execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ) else ( var ans2 : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((ans[i+1]) : ans2)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans2))))))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: a=s.split(); n=len(a)-1 ; i=0 while 2*i<=n : print(a[i],('',a[~ i])[2*isize() - 1; var i : int := 0 ; while (2 * i->compareTo(n)) <= 0 do ( execute (a[i+1])->display(); i := i + 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() x,y=map(int,input().split()) x_axis=1<<8000 y_axis=1<<8000 first=True axis=0 count=0 for s in S : if s=='T' : if axis==0 : if first : x_axis=x_axis<>count) else : y_axis=(y_axis<>count) axis=1-axis first=False count=0 else : count+=1 if count : if axis==0 : if first : x_axis=x_axis<>count) else : y_axis=(y_axis<>count) if(x_axis>>(8000+x))& 1 and(y_axis>>(8000+y))& 1 : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x_axis : int := 1 * (2->pow(8000)) ; var y_axis : int := 1 * (2->pow(8000)) ; var first : boolean := true ; var axis : int := 0 ; var count : int := 0 ; for s : S->characters() do ( if s = 'T' then ( if axis = 0 then ( if first then ( x_axis := x_axis * (2->pow(count)) ) else ( x_axis := MathLib.bitwiseOr((x_axis * (2->pow(count))), (x_axis /(2->pow(count)))) ) ) else ( y_axis := MathLib.bitwiseOr((y_axis * (2->pow(count))), (y_axis /(2->pow(count)))) ) ; axis := 1 - axis ; first := false ; count := 0 ) else ( count := count + 1 )) ; if count then ( if axis = 0 then ( if first then ( x_axis := x_axis * (2->pow(count)) ) else ( x_axis := MathLib.bitwiseOr((x_axis * (2->pow(count))), (x_axis /(2->pow(count)))) ) ) else ( y_axis := MathLib.bitwiseOr((y_axis * (2->pow(count))), (y_axis /(2->pow(count)))) ) ) else skip ; if MathLib.bitwiseAnd((x_axis /(2->pow((8000 + x)))), 1) & MathLib.bitwiseAnd((y_axis /(2->pow((8000 + y)))), 1) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() x,y=[int(v)for v in input().split()] f_length_list=list(map(len,s.split("T"))) x_point_set=set([0]) y_point_set=set([0]) for i,v in enumerate(f_length_list): new_point_set=set([]) if i % 2==0 : if i==0 : new_point_set.add(v) else : for j in x_point_set : new_point_set.add(j+v) new_point_set.add(j-v) x_point_set=new_point_set elif i % 2!=0 : for j in y_point_set : new_point_set.add(j+v) new_point_set.add(j-v) y_point_set=new_point_set if x in x_point_set and y in y_point_set : ans="Yes" else : ans="No" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := input().split()->select(v | true)->collect(v | (("" + ((v)))->toInteger())) ; var f_length_list : Sequence := ((s.split("T"))->collect( _x | (len)->apply(_x) )) ; var x_point_set : Set := Set{}->union((Sequence{ 0 })) ; var y_point_set : Set := Set{}->union((Sequence{ 0 })) ; for _tuple : Integer.subrange(1, (f_length_list)->size())->collect( _indx | Sequence{_indx-1, (f_length_list)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); var new_point_set : Set := Set{}->union((Sequence{})) ; if i mod 2 = 0 then ( if i = 0 then ( execute ((v) : new_point_set) ) else ( for j : x_point_set do ( execute ((j + v) : new_point_set) ; execute ((j - v) : new_point_set)) ) ; x_point_set := new_point_set ) else (if i mod 2 /= 0 then ( for j : y_point_set do ( execute ((j + v) : new_point_set) ; execute ((j - v) : new_point_set)) ; y_point_set := new_point_set ) else skip)) ; if (x_point_set)->includes(x) & (y_point_set)->includes(y) then ( var ans : String := "Yes" ) else ( ans := "No" ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import* from fractions import gcd from functools import* from itertools import* from operator import mul from bisect import* from heapq import* from math import factorial from copy import deepcopy import sys sys.setrecursionlimit(10**6) def main(): *s,=map(len,input().split("T")) x,y=map(int,input().split()) start=s[0] n=s[2 : : 2] m=s[1 : : 2] dx={start} dy={0} for i in n : dx={r+j for j in dx for r in{-i,i}} for i in m : dy={r+j for j in dy for r in{-i,i}} if x in dx and y in dy : print("Yes") else : print("No") if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(6)) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: ; (testlist_star_expr (star_expr * (expr (atom (name s)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name s)))) ,)} := (input().split("T"))->collect( _x | (len)->apply(_x) ) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var start : OclAny := s->first() ; var n : OclAny := s(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ; var m : OclAny := s(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ; var dx : Set := Set{ start } ; var dy : Set := Set{ 0 } ; for i : n do ( dx := dx->select(j; r : Set{-i}->union(Set{ i }) | true)->collect(j; r : Set{-i}->union(Set{ i }) | r + j)->asSet()) ; for i : m do ( dy := dy->select(j; r : Set{-i}->union(Set{ i }) | true)->collect(j; r : Set{-i}->union(Set{ i }) | r + j)->asSet()) ; if (dx)->includes(x) & (dy)->includes(y) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys s=input() n=len(s) x,y=map(int,input().split()) lst=list(s.split("T")) if len(lst)==1 : if x==len(s)and y==0 : print("Yes") else : print("No") sys.exit() v=[0]*(2*n+1) u=[0]*(2*n+1) a=len(lst[0]) b=len(lst[1]) v[n+a]=1 u[n+b]=1 u[n-b]=1 for i in range(2,len(lst)): l=len(lst[i]) if i % 2==0 : h=[0]*(2*n+1) for i in range(2*n+1): if i-l>=0 : if v[i-l]==1 : h[i]=1 if i+l<=2*n : if v[i+l]==1 : h[i]=1 v=h else : h=[0]*(2*n+1) for i in range(2*n+1): if i-l>=0 : if u[i-l]==1 : h[i]=1 if i+l<=2*n : if u[i+l]==1 : h[i]=1 u=h if v[n+x]==1 and u[n+y]==1 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : String := (OclFile["System.in"]).readLine() ; var n : int := (s)->size() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lst : Sequence := (s.split("T")) ; if (lst)->size() = 1 then ( if x = (s)->size() & y = 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ; sys.exit() ) else skip ; var v : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * n + 1)) ; var u : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * n + 1)) ; var a : int := (lst->first())->size() ; var b : int := (lst[1+1])->size() ; v[n + a+1] := 1 ; u[n + b+1] := 1 ; u[n - b+1] := 1 ; for i : Integer.subrange(2, (lst)->size()-1) do ( var l : int := (lst[i+1])->size() ; if i mod 2 = 0 then ( var h : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * n + 1)) ; for i : Integer.subrange(0, 2 * n + 1-1) do ( if i - l >= 0 then ( if v[i - l+1] = 1 then ( h[i+1] := 1 ) else skip ) else skip ; if (i + l->compareTo(2 * n)) <= 0 then ( if v[i + l+1] = 1 then ( h[i+1] := 1 ) else skip ) else skip) ; v := h ) else ( h := MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * n + 1)) ; for i : Integer.subrange(0, 2 * n + 1-1) do ( if i - l >= 0 then ( if u[i - l+1] = 1 then ( h[i+1] := 1 ) else skip ) else skip ; if (i + l->compareTo(2 * n)) <= 0 then ( if u[i + l+1] = 1 then ( h[i+1] := 1 ) else skip ) else skip) ; u := h )) ; if v[n + x+1] = 1 & u[n + y+1] = 1 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin sys.setrecursionlimit(10**5) def li(): return map(int,stdin.readline().split()) def li_(): return map(lambda x : int(x)-1,stdin.readline().split()) def lf(): return map(float,stdin.readline().split()) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) s=ns() x,y=li() command=s.split("T") ud=set() lr=set() lr.add(len(command[0])) ud.add(0) for i,cm in enumerate(command[1 :]): if i % 2==1 : new_lr=set() for element in lr : new_lr.add(element+len(cm)) new_lr.add(element-len(cm)) lr=new_lr else : new_ud=set() for element in ud : new_ud.add(element+len(cm)) new_ud.add(element-len(cm)) ud=new_ud if(x in lr)and(y in ud): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stdin : OclFile := OclFile["System.in"] ; sys.setrecursionlimit((10)->pow(5)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var s : OclAny := ns() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := li() ; var command : OclAny := s.split("T") ; var ud : Set := Set{}->union(()) ; var lr : Set := Set{}->union(()) ; execute (((command->first())->size()) : lr) ; execute ((0) : ud) ; for _tuple : Integer.subrange(1, (command->tail())->size())->collect( _indx | Sequence{_indx-1, (command->tail())->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var cm : OclAny := _tuple->at(_indx); if i mod 2 = 1 then ( var new_lr : Set := Set{}->union(()) ; for element : lr do ( execute ((element + (cm)->size()) : new_lr) ; execute ((element - (cm)->size()) : new_lr)) ; lr := new_lr ) else ( var new_ud : Set := Set{}->union(()) ; for element : ud do ( execute ((element + (cm)->size()) : new_ud) ; execute ((element - (cm)->size()) : new_ud)) ; ud := new_ud )) ; if ((lr)->includes(x)) & ((ud)->includes(y)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation li() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation li_() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ); operation lf() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ); operation ls() : OclAny pre: true post: true activity: return stdin.readLine().split(); operation ns() : OclAny pre: true post: true activity: return stdin.readLine().rstrip(); operation lc() : OclAny pre: true post: true activity: return (ns()); operation ni() : OclAny pre: true post: true activity: return ("" + ((stdin.readLine())))->toInteger(); operation nf() : OclAny pre: true post: true activity: return ("" + ((stdin.readLine())))->toReal(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left while True : N,Q=map(int,input().split(' ')) if N==0 : break era={} years=[] for _ in range(N): name,j,w=input().split(' ') j,w=int(j),int(w) era[w]=(name,j) years.append(w) years.sort() for _ in range(Q): q=int(input()) i=bisect_left(years,q) if i>=len(years): print('Unknown') continue y=years[i] name,length=era[y] if q-y+length<=0 : print('Unknown') else : print(name+' '+str(q-y+length)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var N : OclAny := null; var Q : OclAny := null; Sequence{N,Q} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; if N = 0 then ( break ) else skip ; var era : OclAny := Set{} ; var years : Sequence := Sequence{} ; for _anon : Integer.subrange(0, N-1) do ( var name : OclAny := null; var j : OclAny := null; var w : OclAny := null; Sequence{name,j,w} := input().split(' ') ; var j : OclAny := null; var w : OclAny := null; Sequence{j,w} := Sequence{("" + ((j)))->toInteger(),("" + ((w)))->toInteger()} ; era[w+1] := Sequence{name, j} ; execute ((w) : years)) ; years := years->sort() ; for _anon : Integer.subrange(0, Q-1) do ( var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : OclAny := bisect_left(years, q) ; if (i->compareTo((years)->size())) >= 0 then ( execute ('Unknown')->display() ; continue ) else skip ; var y : OclAny := years[i+1] ; var name : OclAny := null; var length : OclAny := null; Sequence{name,length} := era[y+1] ; if q - y + length <= 0 then ( execute ('Unknown')->display() ) else ( execute (name + ' ' + ("" + ((q - y + length))))->display() ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printElements(arr,n): for i in range(1,n-1,1): if(arr[i]>arr[i-1]and arr[i]>arr[i+1]): print(arr[i],end=" ") if __name__=='__main__' : arr=[2,3,1,5,4,9,8,7,5] n=len(arr) printElements(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{2}->union(Sequence{3}->union(Sequence{1}->union(Sequence{5}->union(Sequence{4}->union(Sequence{9}->union(Sequence{8}->union(Sequence{7}->union(Sequence{ 5 })))))))) ; n := (arr)->size() ; printElements(arr, n) ) else skip; operation printElements(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(1, n - 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if ((arr[i+1]->compareTo(arr[i - 1+1])) > 0 & (arr[i+1]->compareTo(arr[i + 1+1])) > 0) then ( execute (arr[i+1])->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] dd=[(1,1),(1,0),(0,1),(0,-1),(-1,0),(-1,-1)] while True : n,q=LI() if n==0 and q==0 : break a=[LS()for _ in range(n)] a=[[_[0],int(_[1]),int(_[2])]for _ in a] b=[I()for _ in range(q)] for c in b : r='Unknown' for l,e,w in a : if w-epow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; var dd : Sequence := Sequence{Sequence{1, 1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{0, -1}}->union(Sequence{Sequence{-1, 0}}->union(Sequence{ Sequence{-1, -1} }))))) ; while true do ( var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := LI() ; if n = 0 & q = 0 then ( break ) else skip ; var a : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LS())) ; a := a->select(_anon | true)->collect(_anon | (Sequence{_anon->first()}->union(Sequence{("" + ((_anon[1+1])))->toInteger()}->union(Sequence{ ("" + ((_anon[2+1])))->toInteger() })))) ; var b : Sequence := Integer.subrange(0, q-1)->select(_anon | true)->collect(_anon | (I())) ; for c : b do ( var r : String := 'Unknown' ; for _tuple : a do (var _indx : int := 1; var l : OclAny := _tuple->at(_indx); _indx := _indx + 1; var e : OclAny := _tuple->at(_indx); _indx := _indx + 1; var w : OclAny := _tuple->at(_indx); if (w - e->compareTo(c)) < 0 & (c <= w) then ( r := StringLib.interpolateStrings('{}{}', Sequence{l, e - w + c}) ) else skip) ; execute ((r) : rr))) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(sum([int(i)for i in input().split()])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,m=map(int,input().split()) if n==0 and m==0 : break hajime={} owari={} for _ in range(n): a,b,c=input().split() hajime[a]=int(c)-int(b) owari[a]=int(c) for _ in range(m): year=int(input()) for a in hajime : flag=True if hajime[a]collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 & m = 0 then ( break ) else skip ; var hajime : OclAny := Set{} ; var owari : OclAny := Set{} ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := input().split() ; hajime[a+1] := ("" + ((c)))->toInteger() - ("" + ((b)))->toInteger() ; owari[a+1] := ("" + ((c)))->toInteger()) ; for _anon : Integer.subrange(0, m-1) do ( var year : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for a : hajime do ( var flag : boolean := true ; if (hajime[a+1]->compareTo(year)) < 0 & (year->compareTo(owari[a+1])) <= 0 then ( flag := false ; execute (a)->display() ; break ) else skip) ; if flag then ( execute ("Unknown")->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inputnum,outputnum=(int(n)for n in input().split(' ')) while True : data={} for i in range(inputnum): temp=input().split(' ') data[temp[0]]=[int(temp[2])-int(temp[1])+1,int(temp[2])] for o in range(outputnum): targ=int(input()) for k,v in data.items(): if v[0]<=targ<=v[1]: print(k+' '+str(targ-v[0]+1)) break else : print("Unknown") inputnum,outputnum=(int(n)for n in input().split(' ')) if inputnum==outputnum==0 : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inputnum : OclAny := null; var outputnum : OclAny := null; Sequence{inputnum,outputnum} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ' '))))))) ))))))))} ; while true do ( var data : OclAny := Set{} ; for i : Integer.subrange(0, inputnum-1) do ( var temp : OclAny := input().split(' ') ; data[temp->first()+1] := Sequence{("" + ((temp[2+1])))->toInteger() - ("" + ((temp[1+1])))->toInteger() + 1}->union(Sequence{ ("" + ((temp[2+1])))->toInteger() })) ; for o : Integer.subrange(0, outputnum-1) do ( var targ : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (compound_stmt for (exprlist (expr (atom (name k))) , (expr (atom (name v)))) in (testlist (test (logical_test (comparison (expr (atom (name data)) (trailer . (name items) (arguments ( )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (comparison (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) <= (comparison (expr (atom (name targ))))) <= (comparison (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name k))) + (expr (atom ' '))) + (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name targ))) - (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) + (expr (atom (number (integer 1)))))))))) )))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Unknown"))))))) )))))))))))))))) ; var inputnum : OclAny := null; var outputnum : OclAny := null; Sequence{inputnum,outputnum} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ' '))))))) ))))))))} ; if inputnum = outputnum & (outputnum == 0) then ( break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10000000) MOD=10**9+7 INF=10**15 def solve(N,Q): era=[] for _ in range(N): X=input().split() name=X[0] y=int(X[1]) w=int(X[2]) era.append((w-y+1,w,name)) for _ in range(Q): flag=False y=int(input()) for a,b,c in era : if a<=y<=b : flag=True ans=(c,y-a+1) break if flag : print(*ans) else : print('Unknown') def main(): while True : N,Q=map(int,input().split()) if N==0 : return solve(N,Q) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(10000000) ; var MOD : double := (10)->pow(9) + 7 ; var INF : double := (10)->pow(15) ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(N : OclAny, Q : OclAny) pre: true post: true activity: var era : Sequence := Sequence{} ; for _anon : Integer.subrange(0, N-1) do ( var X : OclAny := input().split() ; var name : OclAny := X->first() ; var y : int := ("" + ((X[1+1])))->toInteger() ; var w : int := ("" + ((X[2+1])))->toInteger() ; execute ((Sequence{w - y + 1, w, name}) : era)) ; for _anon : Integer.subrange(0, Q-1) do ( var flag : boolean := false ; y := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _tuple : era do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if (a->compareTo(y)) <= 0 & (y <= b) then ( flag := true ; var ans : OclAny := Sequence{c, y - a + 1} ; break ) else skip) ; if flag then ( execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ) else ( execute ('Unknown')->display() )); operation main() pre: true post: true activity: while true do ( Sequence{N,Q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if N = 0 then ( return ) else skip ; solve(N, Q)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def max_bitwise_or(L,R): v1=[] v2=[] v3=[] z=0 i=0 ans=0 cnt=1 while(L>0): v1.append(L % 2) L=L//2 while(R>0): v2.append(R % 2) R=R//2 while(len(v1)!=len(v2)): v1.append(0) for i in range(len(v2)-1,-1,-1): if(v2[i]==1 and v1[i]==0 and z==0): z=1 continue if(z==1): v1[i]=1 for i in range(len(v2)): v3.append(v2[i]| v1[i]) for i in range(len(v2)): if(v3[i]==1): ans+=cnt cnt*=2 return ans L=10 R=20 print(max_bitwise_or(L,R)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; L := 10 ; R := 20 ; execute (max_bitwise_or(L, R))->display(); operation max_bitwise_or(L : OclAny, R : OclAny) : OclAny pre: true post: true activity: var v1 : Sequence := Sequence{} ; var v2 : Sequence := Sequence{} ; var v3 : Sequence := Sequence{} ; var z : int := 0 ; var i : int := 0 ; var ans : int := 0 ; var cnt : int := 1 ; while (L > 0) do ( execute ((L mod 2) : v1) ; L := L div 2) ; while (R > 0) do ( execute ((R mod 2) : v2) ; R := R div 2) ; while ((v1)->size() /= (v2)->size()) do ( execute ((0) : v1)) ; for i : Integer.subrange(-1 + 1, (v2)->size() - 1)->reverse() do ( if (v2[i+1] = 1 & v1[i+1] = 0 & z = 0) then ( z := 1 ; continue ) else skip ; if (z = 1) then ( v1[i+1] := 1 ) else skip) ; for i : Integer.subrange(0, (v2)->size()-1) do ( execute ((MathLib.bitwiseOr(v2[i+1], v1[i+1])) : v3)) ; for i : Integer.subrange(0, (v2)->size()-1) do ( if (v3[i+1] = 1) then ( ans := ans + cnt ) else skip ; cnt := cnt * 2) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isDivBy9(n): if(n==0 or n==9): return True if(n<9): return False return isDivBy9((int)(n>>3)-(int)(n & 7)) for i in range(100): if(isDivBy9(i)): print(i,"",end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, 100-1) do ( if (isDivBy9(i)) then ( execute (i)->display() ) else skip); operation isDivBy9(n : OclAny) : OclAny pre: true post: true activity: if (n = 0 or n = 9) then ( return true ) else skip ; if (n < 9) then ( return false ) else skip ; return isDivBy9((OclType["int"])(n /(2->pow(3))) - (OclType["int"])(MathLib.bitwiseAnd(n, 7))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pattern(n): for i in range(1,n*2+1): print(end="") print("0") for i in range(1,n*2): if(in): for j in range(n-(i-n)+1): print(j,end="") for j in range((n-(i-n))-1,-1,-1): print(j,end="") else : for j in range(n+1): print(j,end="") for j in range(n-1,-1,-1): print(j,end="") print() for i in range(1,n*2+1): print(end="") print("0",end="") n=4 ; pattern(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4; ; pattern(n);; operation pattern(n : OclAny) pre: true post: true activity: for i : Integer.subrange(1, n * 2 + 1-1) do ( execute ((argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom "")))))))->display()) ; execute ("0")->display() ; for i : Integer.subrange(1, n * 2-1) do ( if ((i->compareTo(n)) < 0) then ( for j : Integer.subrange(1, (n - i) * 2 + 1-1) do ( execute ((argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom "")))))))->display()) ) else ( for j : Integer.subrange(1, (i mod n) * 2 + 1-1) do ( execute ((argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom "")))))))->display()) ) ; if ((i->compareTo(n)) < 0) then ( for j : Integer.subrange(0, i mod n + 1-1) do ( execute (j)->display()) ; for j : Integer.subrange(-1 + 1, i mod n - 1)->reverse() do ( execute (j)->display()) ) else (if ((i->compareTo(n)) > 0) then ( for j : Integer.subrange(0, n - (i - n) + 1-1) do ( execute (j)->display()) ; for j : Integer.subrange(-1 + 1, (n - (i - n)) - 1)->reverse() do ( execute (j)->display()) ) else ( for j : Integer.subrange(0, n + 1-1) do ( execute (j)->display()) ; for j : Integer.subrange(-1 + 1, n - 1)->reverse() do ( execute (j)->display()) ) ) ; execute (->display()) ; for i : Integer.subrange(1, n * 2 + 1-1) do ( execute ((argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom "")))))))->display()) ; execute ("0")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPowerOfTwo(n): if(n==0): return False while(n!=1): if(n % 2!=0): return False n=n//2 return True if(isPowerOfTwo(31)): print('Yes') else : print('No') if(isPowerOfTwo(64)): print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if (isPowerOfTwo(31)) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ) ; if (isPowerOfTwo(64)) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); operation isPowerOfTwo(n : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return false ) else skip ; while (n /= 1) do ( if (n mod 2 /= 0) then ( return false ) else skip ; n := n div 2) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) dic={} for i in range(T): S=input() if S in dic : dic[S]+=1 else : dic[S]=1 if dic[S]>1 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var dic : OclAny := Set{} ; for i : Integer.subrange(0, T-1) do ( var S : String := (OclFile["System.in"]).readLine() ; if (dic)->includes(S) then ( dic->at(S) := dic->at(S) + 1 ) else ( dic->at(S) := 1 ) ; if dic->at(S) > 1 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def valueofX(ar,n): summ=sum(ar) if(summ % n==0): return summ//n else : A=summ//n B=summ//n+1 ValueA=0 ValueB=0 for i in range(n): ValueA+=(ar[i]-A)*(ar[i]-A) ValueB+=(ar[i]-B)*(ar[i]-B) if(ValueAunion(Sequence{9}->union(Sequence{1}->union(Sequence{6}->union(Sequence{1}->union(Sequence{3}->union(Sequence{ 7 })))))) ; execute (valueofX(arr, n))->display(); operation valueofX(ar : OclAny, n : OclAny) : OclAny pre: true post: true activity: var summ : OclAny := (ar)->sum() ; if (summ mod n = 0) then ( return summ div n ) else ( var A : int := summ div n ; var B : int := summ div n + 1 ; var ValueA : int := 0 ; var ValueB : int := 0 ; for i : Integer.subrange(0, n-1) do ( ValueA := ValueA + (ar[i+1] - A) * (ar[i+1] - A) ; ValueB := ValueB + (ar[i+1] - B) * (ar[i+1] - B)) ; if ((ValueA->compareTo(ValueB)) < 0) then ( return A ) else ( return B ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[] for i in range(n): s=input() if s not in l : print("NO") l.append(s) else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if (l)->excludes(s) then ( execute ("NO")->display() ; execute ((s) : l) ) else ( execute ("YES")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=int(input()) d=[] for i in range(m): n=input() if n not in d : d.append(n) print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var n : String := (OclFile["System.in"]).readLine() ; if (d)->excludes(n) then ( execute ((n) : d) ; execute ("NO")->display() ) else ( execute ("YES")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def inu(r,b,w,g): return r+b+w+g r,b,w,g=map(int,input().split()) print(inu(r,b,w,g)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{r,b,w,g} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (inu(r, b, w, g))->display(); operation inu(r : OclAny, b : OclAny, w : OclAny, g : OclAny) : OclAny pre: true post: true activity: return r + b + w + g; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) l=[] for i in range(t): n=input() if n not in l : l.append(n) print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( var n : String := (OclFile["System.in"]).readLine() ; if (l)->excludes(n) then ( execute ((n) : l) ; execute ("NO")->display() ) else ( execute ("YES")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[] for i in range(n): a=input() l.append(a) for i in range(len(l)): b=l[: i] if l[i]in b : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : String := (OclFile["System.in"]).readLine() ; execute ((a) : l)) ; for i : Integer.subrange(0, (l)->size()-1) do ( var b : OclAny := l.subrange(1,i) ; if (b)->includes(l[i+1]) then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def surfaceArea(a,b,h): return 5*a*b+5*b*h def volume(b,h): return(5*b*h)/2 if __name__=='__main__' : a=5 b=3 h=7 print("surface area=",surfaceArea(a,b,h),",","volume=",volume(b,h)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( a := 5 ; b := 3 ; h := 7 ; execute ("surface area=")->display() ) else skip; operation surfaceArea(a : OclAny, b : OclAny, h : OclAny) : OclAny pre: true post: true activity: return 5 * a * b + 5 * b * h; operation volume(b : OclAny, h : OclAny) : OclAny pre: true post: true activity: return (5 * b * h) / 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() index={} for i in range(n): try : index[s[i]].append(i) except : index[s[i]]=[i] for _ in range(int(input())): s1=input() ans=0 newind={} for i in s1 : try : newind[i]+=1 except : newind[i]=0 ans=max(ans,index[i][newind[i]]) print(ans+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var index : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( try ((expr (atom (name index)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) catch (_e : OclException) do ( index[s[i+1]+1] := Sequence{ i }) ) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s1 : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; var newind : OclAny := Set{} ; for i : s1->characters() do ( try ( newind[i+1] := newind[i+1] + 1) catch (_e : OclException) do ( newind[i+1] := 0) ; ans := Set{ans, index[i+1][newind[i+1]+1]}->max()) ; execute (ans + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter import string def solve(): l=int(input()) base_string=input() d={x :[]for x in string.ascii_lowercase} for idx,char in enumerate(base_string): d[char].append(idx) q=int(input()) for _ in range(q): qs=input() pref_size=0 counts=Counter(qs) vis=[False for _ in range(26)] for char in qs : idx=ord(char)-ord('a') if not vis[idx]: vis[idx]=True pref_size=max(pref_size,d[char][counts[char]-1]) print(pref_size+1) def main(): solve() if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve() pre: true post: true activity: var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var base_string : String := (OclFile["System.in"]).readLine() ; var d : Map := string.ascii_lowercase->select(x | true)->collect(x | Map{x |-> Sequence{}})->unionAll() ; for _tuple : Integer.subrange(1, (base_string)->size())->collect( _indx | Sequence{_indx-1, (base_string)->at(_indx)} ) do (var _indx : int := 1; var idx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var char : OclAny := _tuple->at(_indx); (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name char)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name idx)))))))) ))))) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( var qs : String := (OclFile["System.in"]).readLine() ; var pref_size : int := 0 ; var counts : OclAny := Counter(qs) ; var vis : Sequence := Integer.subrange(0, 26-1)->select(_anon | true)->collect(_anon | (false)) ; for char : qs->characters() do ( var idx : double := (char)->char2byte() - ('a')->char2byte() ; if not(vis[idx+1]) then ( vis[idx+1] := true ; pref_size := Set{pref_size, d[char+1][counts[char+1] - 1+1]}->max() ) else skip) ; execute (pref_size + 1)->display()); operation main() pre: true post: true activity: solve(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter for _ in range(1): n=int(input()) l=input() z=[0]*26 pos=[[]for i in range(26)] for i in range(n): x=ord(l[i])-97 pos[x].append(i) z[x]+=1 for k in range(int(input())): t=input() z1=[0]*26 for i in range(len(t)): x=ord(t[i])-97 z1[x]+=1 ans=0 for i in range(26): t=min(z[i],z1[i])-1 if(t>=0): ans=max(ans,pos[i][t]+1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, 1-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : String := (OclFile["System.in"]).readLine() ; var z : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; var pos : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, n-1) do ( var x : double := (l[i+1])->char2byte() - 97 ; (expr (atom (name pos)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ; z[x+1] := z[x+1] + 1) ; for k : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var t : String := (OclFile["System.in"]).readLine() ; var z1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for i : Integer.subrange(0, (t)->size()-1) do ( x := (t[i+1])->char2byte() - 97 ; z1[x+1] := z1[x+1] + 1) ; var ans : int := 0 ; for i : Integer.subrange(0, 26-1) do ( t := Set{z[i+1], z1[i+1]}->min() - 1 ; if (t >= 0) then ( ans := Set{ans, pos[i+1]->at(t) + 1}->max() ) else skip) ; execute (ans)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=list(input()) m={} for i in range(n): try : m[s[i]].append(i) except : m[s[i]]=[i] for t in range(int(input())): st=input() maxind=0 m1={} for i in st : try : m1[i]+=1 except : m1[i]=0 maxind=max(m[i][m1[i]],maxind) print(maxind+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var m : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( try ((expr (atom (name m)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) catch (_e : OclException) do ( m[s[i+1]+1] := Sequence{ i }) ) ; for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var st : String := (OclFile["System.in"]).readLine() ; var maxind : int := 0 ; var m1 : OclAny := Set{} ; for i : st->characters() do ( try ( m1[i+1] := m1[i+1] + 1) catch (_e : OclException) do ( m1[i+1] := 0) ; maxind := Set{m[i+1][m1[i+1]+1], maxind}->max()) ; execute (maxind + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def G(a,b): while a % b!=0 : a,b=b,a % b return b def L(a,b): return a*b//G(a,b) l=input().split(' ') x,y,a,b=int(l[0]),int(l[1]),int(l[2]),int(l[3]) lcm=L(x,y) print(b//lcm-(a-1)//lcm) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var l : OclAny := input().split(' ') ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y,a,b} := Sequence{("" + ((l->first())))->toInteger(),("" + ((l[1+1])))->toInteger(),("" + ((l[2+1])))->toInteger(),("" + ((l[3+1])))->toInteger()} ; var lcm : OclAny := L(x, y) ; execute (b div lcm - (a - 1) div lcm)->display(); operation G(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: while a mod b /= 0 do ( Sequence{a,b} := Sequence{b,a mod b}) ; return b; operation L(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a * b div G(a, b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x,y=map(int,input().split()) z=list(map(int,input().split())) a=0 for i in range(y): c=0 for j in z : if j &(1<(x-c): a+=1<toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var z : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : int := 0 ; for i : Integer.subrange(0, y-1) do ( var c : int := 0 ; for j : z do ( if MathLib.bitwiseAnd(j, (1 * (2->pow(i)))) then ( c := c + 1 ) else skip) ; if (c->compareTo((x - c))) > 0 then ( a := a + 1 * (2->pow(i)) ) else skip) ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from collections import defaultdict n=int(input()) s=input()[:-1] d=defaultdict(list) for i in range(n): d[s[i]].append(i) for _ in range(int(input())): s1=input()[:-1] d1=defaultdict(int) for i in s1 : d1[i]+=1 c=0 for i in d1 : c=max(c,d[i][d1[i]-1]) print(c+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := input()->front() ; var d : OclAny := defaultdict(OclType["Sequence"]) ; for i : Integer.subrange(0, n-1) do ((expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s1 : OclAny := input()->front() ; var d1 : OclAny := defaultdict(OclType["int"]) ; for i : s1 do ( d1[i+1] := d1[i+1] + 1) ; var c : int := 0 ; for i : d1 do ( c := Set{c, d[i+1][d1[i+1] - 1+1]}->max()) ; execute (c + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- b=0 for i in range(10): a=int(input()) b+=a print(b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var b : int := 0 ; for i : Integer.subrange(0, 10-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; b := b + a) ; execute (b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) c=int(input()) d=int(input()) e=int(input()) f=int(input()) g=int(input()) h=int(input()) i=int(input()) j=int(input()) print(a+b+c+d+e+f+g+h+i+j) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var e : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var f : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var g : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var h : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var j : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (a + b + c + d + e + f + g + h + i + j)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R,B,W,G=map(int,input().split()) def inu(R,B,W,G): INU=R+B+W+G return INU print(inu(R,B,W,G)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : OclAny := null; var B : OclAny := null; var W : OclAny := null; var G : OclAny := null; Sequence{R,B,W,G} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; execute (inu(R, B, W, G))->display(); operation inu(R : OclAny, B : OclAny, W : OclAny, G : OclAny) : OclAny pre: true post: true activity: var INU : OclAny := R + B + W + G ; return INU; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- count=0 sum=0 while(True): count+=1 a=int(input()) sum=sum+a if(count==10): print(sum) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var count : int := 0 ; var sum : int := 0 ; while (true) do ( count := count + 1 ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; sum := sum + a ; if (count = 10) then ( execute (sum)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=[int(input())for i in range(10)] print(sum(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := Integer.subrange(0, 10-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; execute ((s)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=0 sum=0 while True : if i==10 : break n=int(input()) sum=sum+n i+=1 print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : int := 0 ; var sum : int := 0 ; while true do ( if i = 10 then ( break ) else skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; sum := sum + n ; i := i + 1) ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) def fact(n): if n==1 or n==0 : return 1 else : return n*fact(n-1) if n % 2==1 : print(0) continue else : res=fact(n//2) res=(res**2)% 998244353 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; if n mod 2 = 1 then ( execute (0)->display() ; continue ) else ( var res : OclAny := fact(n div 2) ; res := ((res)->pow(2)) mod 998244353 ; execute (res)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math modulo=998244353 def mult(a,b): return((a % modulo)*(b % modulo))% modulo for _ in range(int(input())): n=int(input()) if n % 2!=0 : print(0) else : print(mult(math.factorial(n//2),math.factorial(n//2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var modulo : int := 998244353 ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 /= 0 then ( execute (0)->display() ) else ( execute (mult(MathLib.factorial(n div 2), MathLib.factorial(n div 2)))->display() )); operation mult(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return ((a mod modulo) * (b mod modulo)) mod modulo; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while(t>0): n=int(input()) if n % 2==1 : print(0) t-=1 continue ans=1 for i in range(1,int(n/2)+1): ans*=i ans %=998244353 for i in range(1,int(n/2)+1): ans*=i ans %=998244353 print(ans) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (t > 0) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 1 then ( execute (0)->display() ; t := t - 1 ; continue ) else skip ; var ans : int := 1 ; for i : Integer.subrange(1, ("" + ((n / 2)))->toInteger() + 1-1) do ( ans := ans * i ; ans := ans mod 998244353) ; for i : Integer.subrange(1, ("" + ((n / 2)))->toInteger() + 1-1) do ( ans := ans * i ; ans := ans mod 998244353) ; execute (ans)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import* from decimal import* from opcode import HAVE_ARGUMENT import sys from tkinter import N input_=sys.stdin.readline def _input(): return map(int,input().split()) def _list(): return list(map(int,input().split())) def solves(): n,m=_input() a=_list() ans=0 for j in range(0,m): cnt=0 for k in range(0,n): if(a[k]>>j & 1)==1 : cnt+=1 if cnt>n//2 : ans |=1<toInteger() ; for _anon : Integer.subrange(0, t-1) do ( solves()); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation _list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation solves() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := _input() ; var a : OclAny := _list() ; var ans : int := 0 ; for j : Integer.subrange(0, m-1) do ( var cnt : int := 0 ; for k : Integer.subrange(0, n-1) do ( if (MathLib.bitwiseAnd(a[k+1] /(2->pow(j)), 1)) = 1 then ( cnt := cnt + 1 ) else skip) ; if (cnt->compareTo(n div 2)) > 0 then ( ans := ans or 1 * (2->pow(j)) ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solution(n): if n % 2!=0 : print(0) return rem=998244353 ans=1 n=n//2 while n : ans=((ans % rem)*(n % rem)*(n % rem))% rem n-=1 print(ans) t=int(input()) while t : n=int(input()) solution(n) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; solution(n) ; t := t - 1); operation solution(n : OclAny) pre: true post: true activity: if n mod 2 /= 0 then ( execute (0)->display() ; return ) else skip ; var rem : int := 998244353 ; var ans : int := 1 ; n := n div 2 ; while n do ( ans := ((ans mod rem) * (n mod rem) * (n mod rem)) mod rem ; n := n - 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for _ in range(int(input())): n=int(input()) if n % 2==0 : print((math.factorial(n//2)**2)% 998244353) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( execute (((MathLib.factorial(n div 2))->pow(2)) mod 998244353)->display() ) else ( execute (0)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def shortestDist(graph): global INF dist=[0]*N dist[N-1]=0 for i in range(N-2,-1,-1): dist[i]=INF for j in range(N): if graph[i][j]==INF : continue dist[i]=min(dist[i],graph[i][j]+dist[j]) return dist[0] N=8 INF=999999999999 graph=[[INF,1,2,5,INF,INF,INF,INF],[INF,INF,INF,INF,4,11,INF,INF],[INF,INF,INF,INF,9,5,16,INF],[INF,INF,INF,INF,INF,INF,2,INF],[INF,INF,INF,INF,INF,INF,INF,18],[INF,INF,INF,INF,INF,INF,INF,13],[INF,INF,INF,INF,INF,INF,INF,2]] print(shortestDist(graph)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute INF : OclAny; operation initialise() pre: true post: true activity: skip ; var N : int := 8 ; INF := 999999999999 ; graph := Sequence{Sequence{INF}->union(Sequence{1}->union(Sequence{2}->union(Sequence{5}->union(Sequence{INF}->union(Sequence{INF}->union(Sequence{INF}->union(Sequence{ INF })))))))}->union(Sequence{Sequence{INF}->union(Sequence{INF}->union(Sequence{INF}->union(Sequence{INF}->union(Sequence{4}->union(Sequence{11}->union(Sequence{INF}->union(Sequence{ INF })))))))}->union(Sequence{Sequence{INF}->union(Sequence{INF}->union(Sequence{INF}->union(Sequence{INF}->union(Sequence{9}->union(Sequence{5}->union(Sequence{16}->union(Sequence{ INF })))))))}->union(Sequence{Sequence{INF}->union(Sequence{INF}->union(Sequence{INF}->union(Sequence{INF}->union(Sequence{INF}->union(Sequence{INF}->union(Sequence{2}->union(Sequence{ INF })))))))}->union(Sequence{Sequence{INF}->union(Sequence{INF}->union(Sequence{INF}->union(Sequence{INF}->union(Sequence{INF}->union(Sequence{INF}->union(Sequence{INF}->union(Sequence{ 18 })))))))}->union(Sequence{Sequence{INF}->union(Sequence{INF}->union(Sequence{INF}->union(Sequence{INF}->union(Sequence{INF}->union(Sequence{INF}->union(Sequence{INF}->union(Sequence{ 13 })))))))}->union(Sequence{ Sequence{INF}->union(Sequence{INF}->union(Sequence{INF}->union(Sequence{INF}->union(Sequence{INF}->union(Sequence{INF}->union(Sequence{INF}->union(Sequence{ 2 }))))))) })))))) ; execute (shortestDist(graph))->display(); operation shortestDist(graph : OclAny) : OclAny pre: true post: true activity: skip ; var dist : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; dist[N - 1+1] := 0 ; for i : Integer.subrange(-1 + 1, N - 2)->reverse() do ( dist[i+1] := INF ; for j : Integer.subrange(0, N-1) do ( if graph[i+1][j+1] = INF then ( continue ) else skip ; dist[i+1] := Set{dist[i+1], graph[i+1][j+1] + dist[j+1]}->min())) ; return dist->first(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- arr1=list(map(int,input().split())) arr2=list(map(int,input().split())) arr3=list(map(int,input().split())) arr=[] res=0 while(1): for i in range(0,arr1[1]): col=[] for j in arr2 : if i-j<=0 : col.append(abs(i-j)) else : col.append(arr1[1]-(i-j)) col.sort() arr3.sort() if col==arr3 : res=1 print("YES") break if i==arr1[1]-1 : res=1 print("NO") break if res==1 : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var arr1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var arr2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var arr3 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var arr : Sequence := Sequence{} ; var res : int := 0 ; while (1) do ( for i : Integer.subrange(0, arr1[1+1]-1) do ( var col : Sequence := Sequence{} ; for j : arr2 do ( if i - j <= 0 then ( execute (((i - j)->abs()) : col) ) else ( execute ((arr1[1+1] - (i - j)) : col) )) ; col := col->sort() ; arr3 := arr3->sort() ; if col = arr3 then ( res := 1 ; execute ("YES")->display() ; break ) else skip ; if i = arr1[1+1] - 1 then ( res := 1 ; execute ("NO")->display() ; break ) else skip) ; if res = 1 then ( break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def atMostK(arr,n,k): count=0 left=0 right=0 map={} while(rightk): if arr[left]not in map : map[arr[left]]=0 map[arr[left]]-=1 if map[arr[left]]==0 : del map[arr[left]] left+=1 count+=right-left+1 right+=1 return count def exactlyK(arr,n,k): return(atMostK(arr,n,k)-atMostK(arr,n,k-1)) if __name__=="__main__" : arr=[2,1,2,1,6] n=len(arr) k=2 print(exactlyK(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{2}->union(Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{ 6 })))) ; n := (arr)->size() ; k := 2 ; execute (exactlyK(arr, n, k))->display() ) else skip; operation atMostK(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var left : int := 0 ; var right : int := 0 ; var map : OclAny := Set{} ; while ((right->compareTo(n)) < 0) do ( if (map)->excludes(arr[right+1]) then ( ([arr[right+1]+1]`third)->collect( _x | ([arr[right+1]+1])->apply(_x) ) := 0 ) else skip ; ([arr[right+1]+1]`third)->collect( _x | ([arr[right+1]+1])->apply(_x) ) := ([arr[right+1]+1]`third)->collect( _x | ([arr[right+1]+1])->apply(_x) ) + 1 ; while (((map)->size()->compareTo(k)) > 0) do ( if (map)->excludes(arr[left+1]) then ( ([arr[left+1]+1]`third)->collect( _x | ([arr[left+1]+1])->apply(_x) ) := 0 ) else skip ; ([arr[left+1]+1]`third)->collect( _x | ([arr[left+1]+1])->apply(_x) ) := ([arr[left+1]+1]`third)->collect( _x | ([arr[left+1]+1])->apply(_x) ) - 1 ; if ([arr[left+1]+1]`third)->collect( _x | ([arr[left+1]+1])->apply(_x) ) = 0 then ( execute (([arr[left+1]+1]`third)->collect( _x | ([arr[left+1]+1])->apply(_x) ))->isDeleted() ) else skip ; left := left + 1) ; count := count + right - left + 1 ; right := right + 1) ; return count; operation exactlyK(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: return (atMostK(arr, n, k) - atMostK(arr, n, k - 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- nl=[int(k)for k in input().split()] n=nl[0] L=nl[1] a=[int(k)for k in input().split()] b=[int(k)for k in input().split()] fl=0 for dL in range(0,L): flg=0 for i in range(0,n): b[i]=(b[i]+1)% L for k in range(0,L): t=b[0] flag=0 for i in range(1,n): b[i-1]=b[i] b[n-1]=t for i in range(0,n): if a[i]!=b[i]: flag=1 break if not flag : flg=1 break if flg : fl=1 break if fl : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var nl : Sequence := input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger())) ; var n : OclAny := nl->first() ; var L : OclAny := nl[1+1] ; var a : Sequence := input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger())) ; var b : Sequence := input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger())) ; var fl : int := 0 ; for dL : Integer.subrange(0, L-1) do ( var flg : int := 0 ; for i : Integer.subrange(0, n-1) do ( b[i+1] := (b[i+1] + 1) mod L) ; for k : Integer.subrange(0, L-1) do ( var t : OclAny := b->first() ; var flag : int := 0 ; for i : Integer.subrange(1, n-1) do ( b[i - 1+1] := b[i+1]) ; b[n - 1+1] := t ; for i : Integer.subrange(0, n-1) do ( if a[i+1] /= b[i+1] then ( flag := 1 ; break ) else skip) ; if not(flag) then ( flg := 1 ; break ) else skip) ; if flg then ( fl := 1 ; break ) else skip) ; if fl then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- arr=list(map(int,input().rstrip().split())) brr=list(map(int,input().rstrip().split())) crr=list(map(int,input().rstrip().split())) n=arr[0] l=arr[1] db=[] dc=[] for i in range(1,n): db.append(brr[i]-brr[i-1]) dc.append(crr[i]-crr[i-1]) db.append((l-1-brr[n-1])+brr[0]+1) dc.append((l-1-crr[n-1])+crr[0]+1) flag=0 for i in range(n): if(db==dc): flag=1 break cc=db[0] db.pop(0) db.append(cc) if(flag==1): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var arr : Sequence := ((input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var brr : Sequence := ((input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var crr : Sequence := ((input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := arr->first() ; var l : OclAny := arr[1+1] ; var db : Sequence := Sequence{} ; var dc : Sequence := Sequence{} ; for i : Integer.subrange(1, n-1) do ( execute ((brr[i+1] - brr[i - 1+1]) : db) ; execute ((crr[i+1] - crr[i - 1+1]) : dc)) ; execute (((l - 1 - brr[n - 1+1]) + brr->first() + 1) : db) ; execute (((l - 1 - crr[n - 1+1]) + crr->first() + 1) : dc) ; var flag : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (db = dc) then ( flag := 1 ; break ) else skip ; var cc : OclAny := db->first() ; db := db->excludingAt(0+1) ; execute ((cc) : db)) ; if (flag = 1) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,l=map(int,input().split()) k=list(map(int,input().split())) s=list(map(int,input().split())) flag=0 for i in range(n): for j in range(l+1): count=0 i1,i2=i,0 while i2collect( _x | (OclType["int"])->apply(_x) ) ; var k : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var flag : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, l + 1-1) do ( var count : int := 0 ; var i1 : OclAny := null; var i2 : OclAny := null; Sequence{i1,i2} := Sequence{i,0} ; while (i2->compareTo(n)) < 0 do ( if (s[i1 mod n+1] + j) mod l = k[i2+1] then ( count := count + 1 ) else ( break ) ; i1 := i1 + 1 ; i2 := i2 + 1) ; if count = n then ( flag := 1 ; break ) else skip) ; if flag = 1 then ( break ) else skip) ; if flag = 1 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maximum(x,y): return((x+y+abs(x-y))//2) def minimum(x,y): return((x+y-abs(x-y))//2) x=99 y=18 print("Maximum:",maximum(x,y)) print("Minimum:",minimum(x,y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; x := 99 ; y := 18 ; execute ("Maximum:")->display() ; execute ("Minimum:")->display(); operation maximum(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return ((x + y + (x - y)->abs()) div 2); operation minimum(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return ((x + y - (x - y)->abs()) div 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def u_cal(u,n): temp=u ; for i in range(1,n): temp=temp*(u-i); return temp ; def fact(n): f=1 ; for i in range(2,n+1): f*=i ; return f ; n=4 ; x=[45,50,55,60]; y=[[0 for i in range(n)]for j in range(n)]; y[0][0]=0.7071 ; y[1][0]=0.7660 ; y[2][0]=0.8192 ; y[3][0]=0.8660 ; for i in range(1,n): for j in range(n-i): y[j][i]=y[j+1][i-1]-y[j][i-1]; for i in range(n): print(x[i],end="\t"); for j in range(n-i): print(y[i][j],end="\t"); print(""); value=52 ; sum=y[0][0]; u=(value-x[0])/(x[1]-x[0]); for i in range(1,n): sum=sum+(u_cal(u,i)*y[0][i])/fact(i); print("\nValue at",value,"is",round(sum,6)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 4; ; var x : Sequence := Sequence{45}->union(Sequence{50}->union(Sequence{55}->union(Sequence{ 60 }))); ; var y : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)))); ; y->first()->first() := 0.7071; ; y[1+1]->first() := 0.7660; ; y[2+1]->first() := 0.8192; ; y[3+1]->first() := 0.8660; ; for i : Integer.subrange(1, n-1) do ( for j : Integer.subrange(0, n - i-1) do ( y[j+1][i+1] := y[j + 1+1][i - 1+1] - y[j+1][i - 1+1];)) ; for i : Integer.subrange(0, n-1) do ( execute (x[i+1])->display(); ; for j : Integer.subrange(0, n - i-1) do ( execute (y[i+1][j+1])->display();) ; execute ("")->display();) ; var value : int := 52; ; var sum : OclAny := y->first()->first(); ; u := (value - x->first()) / (x[1+1] - x->first()); ; for i : Integer.subrange(1, n-1) do ( sum := sum + (u_cal(u, i) * y->first()[i+1]) / fact(i);) ; execute ("\nValue at")->display();; operation u_cal(u : OclAny, n : OclAny) pre: true post: true activity: var temp : OclAny := u; ; for i : Integer.subrange(1, n-1) do ( temp := temp * (u - i);) ; return temp;; operation fact(n : OclAny) pre: true post: true activity: var f : int := 1; ; for i : Integer.subrange(2, n + 1-1) do ( f := f * i;) ; return f;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : n,l=map(int,input().split(" ")) arr=list(map(int,input().split())) oneCount=0 res='' for i in range(l): oneCount=0 for j in range(n): if(arr[j]>>i)& 1==1 : oneCount+=1 if oneCount>n/2 : res='1'+res else : res='0'+res print(int(res,2)) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( var n : OclAny := null; var l : OclAny := null; Sequence{n,l} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var oneCount : int := 0 ; var res : String := '' ; for i : Integer.subrange(0, l-1) do ( oneCount := 0 ; for j : Integer.subrange(0, n-1) do ( if MathLib.bitwiseAnd((arr[j+1] /(2->pow(i))), 1) = 1 then ( oneCount := oneCount + 1 ) else skip) ; if (oneCount->compareTo(n / 2)) > 0 then ( res := '1' + res ) else ( res := '0' + res )) ; execute (("" + ((res, 2)))->toInteger())->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class GfG : def __init__(self): self.MAX=10 self.arr=[0]*self.MAX self.no=0 def breakLine(self): print("\n------------------------------------------------") def canPlace(self,k,i): for j in range(1,k): if(self.arr[j]==i or(abs(self.arr[j]-i)==abs(j-k))): return False return True def display(self,n): self.breakLine() self.no+=1 print("Arrangement No.",self.no,end=" ") self.breakLine() for i in range(1,n+1): for j in range(1,n+1): if self.arr[i]!=j : print("\t_",end=" ") else : print("\tQ",end=" ") print() self.breakLine() def nQueens(self,k,n): for i in range(1,n+1): if self.canPlace(k,i): self.arr[k]=i if k==n : self.display(n) else : self.nQueens(k+1,n) if __name__=='__main__' : n=4 obj=GfG() obj.nQueens(1,n) ------------------------------------------------------------ OCL File: --------- class GfG { static operation newGfG() : GfG pre: true post: GfG->exists( _x | result = _x ); attribute MAX : int := 10; attribute arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, self.MAX); attribute no : int := 0; operation initialise() : GfG pre: true post: true activity: self.MAX := 10 ; self.arr := MatrixLib.elementwiseMult(Sequence{ 0 }, self.MAX) ; self.no := 0; return self; operation breakLine() pre: true post: true activity: execute ("\n------------------------------------------------")->display(); operation canPlace(k : OclAny,i : OclAny) : OclAny pre: true post: true activity: for j : Integer.subrange(1, k-1) do ( if (self.arr[j+1] = i or ((self.arr[j+1] - i)->abs() = (j - k)->abs())) then ( return false ) else skip) ; return true; operation display(n : OclAny) pre: true post: true activity: self.breakLine() ; self.no := self.no + 1 ; execute ("Arrangement No.")->display() ; self.breakLine() ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, n + 1-1) do ( if self.arr[i+1] /= j then ( execute ("\t_")->display() ) else ( execute ("\tQ")->display() )) ; execute (->display()) ; self.breakLine(); operation nQueens(k : OclAny,n : OclAny) pre: true post: true activity: for i : Integer.subrange(1, n + 1-1) do ( if self.canPlace(k, i) then ( self.arr[k+1] := i ; if k = n then ( self.display(n) ) else ( self.nQueens(k + 1, n) ) ) else skip); } class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 4 ; var obj : GfG := (GfG.newGfG()).initialise() ; obj.nQueens(1, n) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque,defaultdict,Counter from heapq import heappush,heappop,heapify from math import inf,sqrt,ceil,log2 from functools import lru_cache from itertools import accumulate,combinations,permutations,product from typing import List from bisect import bisect_left,bisect_right import sys import string input=lambda : sys.stdin.readline().strip('\n') mis=lambda : map(int,input().split()) ii=lambda : int(input()) T=ii() for _ in range(T): N=ii() S=input() strs=[] for k in range(1,N+1): if(N-k+1)% 2==0 : strs.append((S[k-1 :]+S[: k-1],k)) else : strs.append((S[k-1 :]+S[: k-1][: :-1],k)) strs.sort() print(strs[0][0]) print(strs[0][1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine()->trim()) ; var mis : Function := lambda $$ : OclAny in ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ii : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var T : OclAny := ii->apply() ; for _anon : Integer.subrange(0, T-1) do ( var N : OclAny := ii->apply() ; var S : String := (OclFile["System.in"]).readLine() ; var strs : Sequence := Sequence{} ; for k : Integer.subrange(1, N + 1-1) do ( if (N - k + 1) mod 2 = 0 then ( execute ((Sequence{S.subrange(k - 1+1) + S.subrange(1,k - 1), k}) : strs) ) else ( execute ((Sequence{S.subrange(k - 1+1) + S.subrange(1,k - 1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))), k}) : strs) )) ; strs := strs->sort() ; execute (strs->first()->first())->display() ; execute (strs->first()[1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline t=int(input()) ans=[] for _ in range(t): n=int(input()) s=list(input().rstrip()) k=1 ans0="".join(s) for i in range(2,n+1): s0=[] for j in range(i-1,n): s0.append(s[j]) if(n-i)% 2 : for j in range(i-1): s0.append(s[j]) else : for j in range(i-2,-1,-1): s0.append(s[j]) s0="".join(s0) if ans0>s0 : k=i ans0=s0 ans.append(ans0) ans.append(str(k)) sys.stdout.write("\n".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := (input().rstrip()) ; var k : int := 1 ; var ans0 : String := StringLib.sumStringsWithSeparator((s), "") ; for i : Integer.subrange(2, n + 1-1) do ( var s0 : Sequence := Sequence{} ; for j : Integer.subrange(i - 1, n-1) do ( execute ((s[j+1]) : s0)) ; if (n - i) mod 2 then ( for j : Integer.subrange(0, i - 1-1) do ( execute ((s[j+1]) : s0)) ) else ( for j : Integer.subrange(-1 + 1, i - 2)->reverse() do ( execute ((s[j+1]) : s0)) ) ; s0 := StringLib.sumStringsWithSeparator((s0), "") ; if ans0 > s0 then ( k := i ; ans0 := s0 ) else skip) ; execute ((ans0) : ans) ; execute ((("" + ((k)))) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) s=input() dic={} ans=[] for j in range(1,n+1): if n % 2==0 : if j % 2!=0 : a=s[j-1 :] b=s[: j-1] s1=a+b ans.append((s1,j)) else : a=s[j-1 :] b=s[: j-1][: :-1] s1=a+b ans.append((s1,j)) else : if j % 2==0 : a=s[j-1 :] b=s[: j-1] s1=a+b ans.append((s1,j)) else : a=s[j-1 :] b=s[: j-1][: :-1] s1=a+b ans.append((s1,j)) for j in ans : dic[j[0]]=[] for j in ans : dic[j[0]].append(j[1]) ans1=[] for j in ans : ans1.append(j[0]) ans1.sort() ele=ans1[0] mi=min(dic[ele]) print(ele) print(mi) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var dic : OclAny := Set{} ; var ans : Sequence := Sequence{} ; for j : Integer.subrange(1, n + 1-1) do ( if n mod 2 = 0 then ( if j mod 2 /= 0 then ( var a : OclAny := s.subrange(j - 1+1) ; var b : OclAny := s.subrange(1,j - 1) ; var s1 : OclAny := a + b ; execute ((Sequence{s1, j}) : ans) ) else ( a := s.subrange(j - 1+1) ; b := s.subrange(1,j - 1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; s1 := a + b ; execute ((Sequence{s1, j}) : ans) ) ) else ( if j mod 2 = 0 then ( a := s.subrange(j - 1+1) ; b := s.subrange(1,j - 1) ; s1 := a + b ; execute ((Sequence{s1, j}) : ans) ) else ( a := s.subrange(j - 1+1) ; b := s.subrange(1,j - 1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; s1 := a + b ; execute ((Sequence{s1, j}) : ans) ) )) ; for j : ans do ( dic[j->first()+1] := Sequence{}) ; for j : ans do ((expr (atom (name dic)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ))))) ; var ans1 : Sequence := Sequence{} ; for j : ans do ( execute ((j->first()) : ans1)) ; ans1 := ans1->sort() ; var ele : OclAny := ans1->first() ; var mi : OclAny := (dic[ele+1])->min() ; execute (ele)->display() ; execute (mi)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import string from sys import stdin input=stdin.readline read=lambda : map(lambda s : int(s),input().strip().split()) readi=lambda : int(input()) from collections import defaultdict,Counter from bisect import bisect_left as bl,bisect_right as br from random import randint from math import gcd,ceil RANDOM=randint(1,10**9) class Wrapper(int): def __hash__(self): return super(Wrapper,self).__hash__()^ RANDOM def gen(s,k): i=0 if(len(s)-k)% 2==0 : return s[k :]+s[: k] else : return s[k :]+s[: k][: :-1] return s for _ in range(readi()): n=readi() s=input().strip() if n==1 : print(s,1,sep="\n") continue ind=[] mn=min(s) for id,i in enumerate(s): if i==mn : ind.append(id) ans="z"*n k=None for i in ind : t=gen(s,i) if texists( _x | result = _x ); operation __hash__() : OclAny pre: true post: true activity: return MathLib.bitwiseXor(super(Wrapper, self).__hash__(), RANDOM); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; var read : Function := lambda $$ : OclAny in ((input()->trim().split())->collect( _x | (lambda s : OclAny in (("" + ((s)))->toInteger()))->apply(_x) )) ; var readi : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; skip ; skip ; skip ; skip ; var RANDOM : OclAny := randint(1, (10)->pow(9)) ; skip ; skip ; for _anon : Integer.subrange(0, readi->apply()-1) do ( var n : OclAny := readi->apply() ; s := input()->trim() ; if n = 1 then ( execute (s)->display() ; continue ) else skip ; var ind : Sequence := Sequence{} ; var mn : OclAny := (s)->min() ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var id : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); if i = mn then ( execute ((id) : ind) ) else skip) ; var ans : String := StringLib.nCopies("z", n) ; k := null ; for i : ind do ( var t : OclAny := gen(s, i) ; if t < ans then ( ans := t ; k := i ) else skip) ; execute (ans)->display()); operation gen(s : OclAny, k : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; if ((s)->size() - k) mod 2 = 0 then ( return s.subrange(k+1) + s.subrange(1,k) ) else ( return s.subrange(k+1) + s.subrange(1,k)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ) ; return s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Race(B,C): result=0 ; result=((C*100)//B) return 100-result if __name__=="__main__" : B=10 C=28 B=100-B ; C=100-C ; print(str(Race(B,C))+" meters") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( B := 10 ; C := 28 ; B := 100 - B; ; C := 100 - C; ; execute (("" + ((Race(B, C)))) + " meters")->display() ) else skip; operation Race(B : OclAny, C : OclAny) : OclAny pre: true post: true activity: var result : int := 0; ; result := ((C * 100) div B) ; return 100 - result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def tidyNum(str,len): for i in range(len-2,-1,-1): if(str[i]>str[i+1]): str[i]-=1 for j in range(i+1,len): str[j]=9 return str str=[1,1,3,3,3,4,4,5,5,3,8] len=len(str) num=tidyNum(str,len) for i in range(0,len): print(str[i],end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclType["String"] := Sequence{1}->union(Sequence{1}->union(Sequence{3}->union(Sequence{3}->union(Sequence{3}->union(Sequence{4}->union(Sequence{4}->union(Sequence{5}->union(Sequence{5}->union(Sequence{3}->union(Sequence{ 8 })))))))))) ; len := (OclType["String"])->size() ; var num : OclAny := tidyNum(OclType["String"], len) ; for i : Integer.subrange(0, len-1) do ( execute (("" + ([i+1])))->display()); operation tidyNum(OclType["String"] : OclAny, len : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(-1 + 1, len - 2)->reverse() do ( if ((("" + ([i+1]))->compareTo(("" + ([i + 1+1])))) > 0) then ( ("" + ([i+1])) := ("" + ([i+1])) - 1 ; for j : Integer.subrange(i + 1, len-1) do ( ("" + ([j+1])) := 9) ) else skip) ; return OclType["String"]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from audioop import reverse from sys import stdin,stdout import sys def get_ints(): return map(int,sys.stdin.readline().strip().split()) def get_arr(): return list(map(int,sys.stdin.readline().strip().split())) def get_string(): return sys.stdin.readline().strip() t=int(input()) while t : t-=1 n=int(input()) s=get_string() s1=s s2=s ans=0 for i in range(0,n): if(n-i)% 2==0 : s3=s1[0 : i] s4=s[i : n]+s3 if s4toInteger() ; while t do ( t := t - 1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := get_string() ; var s1 : OclAny := s ; var s2 : OclAny := s ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (n - i) mod 2 = 0 then ( var s3 : OclAny := s1.subrange(0+1, i) ; var s4 : OclAny := s.subrange(i+1, n) + s3 ; if (s4->compareTo(s2)) < 0 then ( ans := i ) else skip ; s2 := Set{s2, s4}->min() ) else ( s3 := s1.subrange(0+1, i) ; s4 := s.subrange(i+1, n) + s3(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; if (s4->compareTo(s2)) < 0 then ( ans := i ) else skip ; s2 := Set{s2, s4}->min() )) ; execute (s2)->display() ; execute (ans + 1)->display()); operation get_ints() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ); operation get_arr() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation get_string() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- K=int(input()) if K<=500 : print(K) for i in range(1,K+1): print((str(i)+" ")*K) else : KUP=((K+1)//2+3)//4*4 print(KUP) ANS=[[0]*KUP for i in range(KUP)] begin=0 for i in range(KUP): for j in range(KUP): if i % 2==0 : ANS[i][(j+begin)% KUP]=j+1 else : ANS[i][(j+begin)% KUP]=j+1+KUP begin+=1 for i in range(KUP*2-K): for j in range(KUP): for l in range(KUP): if ANS[j][l]==KUP*2-i : ANS[j][l]=KUP*2-i-KUP for ans in ANS : print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if K <= 500 then ( execute (K)->display() ; for i : Integer.subrange(1, K + 1-1) do ( execute ((("" + ((i))) + " ") * K)->display()) ) else ( var KUP : int := ((K + 1) div 2 + 3) div 4 * 4 ; execute (KUP)->display() ; var ANS : Sequence := Integer.subrange(0, KUP-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, KUP))) ; var begin : int := 0 ; for i : Integer.subrange(0, KUP-1) do ( for j : Integer.subrange(0, KUP-1) do ( if i mod 2 = 0 then ( ANS[i+1][(j + begin) mod KUP+1] := j + 1 ) else ( ANS[i+1][(j + begin) mod KUP+1] := j + 1 + KUP )) ; begin := begin + 1) ; for i : Integer.subrange(0, KUP * 2 - K-1) do ( for j : Integer.subrange(0, KUP-1) do ( for l : Integer.subrange(0, KUP-1) do ( if ANS[j+1][l+1] = KUP * 2 - i then ( ANS[j+1][l+1] := KUP * 2 - i - KUP ) else skip))) ; for ans : ANS do ( execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(k): if k==1 : print(1) print(1) return n=((k-1)//4+1)*2 ans=[[0]*n for _ in[0]*n] dub=2*(k-n) for m in range(n*2): l=m+1 if mtoInteger() ; solve(k); operation solve(k : OclAny) pre: true post: true activity: if k = 1 then ( execute (1)->display() ; execute (1)->display() ; return ) else skip ; var n : int := ((k - 1) div 4 + 1) * 2 ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, n))) ; var dub : double := 2 * (k - n) ; for m : Integer.subrange(0, n * 2-1) do ( var l : OclAny := if (m->compareTo(dub)) < 0 then m + 1 else dub + (m - dub) div 2 + 1 endif ; var i : int := m mod 2 ; var j : int := (m div 2 + m mod 2) mod n ; for _anon : Integer.subrange(0, n div 2-1) do ( ans[i+1][j+1] := l ; i := (i + 2) mod n ; j := (j + 2) mod n)) ; execute (n)->display() ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom ' ') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name row)))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name row)))) in (logical_test (comparison (expr (atom (name ans)))))))), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(input()) del s[-1] for i in range(1,len(s)): if len(s)% 2==1 : del s[-1] else : if s[: int(len(s)/2)]==s[int(len(s)/2):]: print(len(s)) exit() else : del s[-1] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; execute (s->last())->isDeleted() ; for i : Integer.subrange(1, (s)->size()-1) do ( if (s)->size() mod 2 = 1 then ( execute (s->last())->isDeleted() ) else ( if s.subrange(1,("" + (((s)->size() / 2)))->toInteger()) = s.subrange(("" + (((s)->size() / 2)))->toInteger()+1) then ( execute ((s)->size())->display() ; exit() ) else ( execute (s->last())->isDeleted() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline import numpy as np K=int(input()) L=(K+(-K)% 4)//2 x=np.arange(L) grid=(x[:,None]+x[None,:])% L+1 grid[: : 2][grid[: : 2]<=K-L]+=L if K==1 : grid[:]=1 print(L) print('\n'.join(' '.join(row)for row in grid.astype(str))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var L : int := (K + (-K) mod 4) div 2 ; var x : Sequence := MathLib.numericRange(0, (L), 1) ; var grid : int := (x->collect( _r | _r[null+1] )->union(x[null+1])) mod L + 1 ; grid(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->select((grid(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->compareTo(K - L)) <= 0) := grid(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->select((grid(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->compareTo(K - L)) <= 0) + L ; if K = 1 then ( grid := 1 ) else skip ; execute (L)->display() ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom ' ') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name row)))))))) ))))))) (comp_for for (exprlist (expr (atom (name row)))) in (logical_test (comparison (expr (atom (name grid)) (trailer . (name astype) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)))))))) ))))))))), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- K=int(input()) n=0 n1=0 n2=0 n3=0 n4=0 n5=0 if K<=499 : n=K mat=[[0 for n1 in range(K)]for n2 in range(K)] for n1 in range(K): for n2 in range(K-n1): mat[n1][n1+n2]=n2+1 for n1 in range(K): for n2 in range(n1): mat[n1][n2]=K+n2-n1+1 else : n=500 mat=[[0 for n1 in range(500)]for n2 in range(500)] for n1 in range(500): for n2 in range(500-n1): mat[n1][n1+n2]=n2+1 for n1 in range(500): for n2 in range(n1): mat[n1][n2]=500+n2-n1+1 for n2 in range(K-500): for n1 in range(250): kari=n1*2+n2 if kari>=500 : kari=kari-500 mat[n1*2][kari]=n2+501 print(n) if K<=500 : out="" for n1 in range(K): out="" for n2 in range(K): out=out+""+str(mat[n1][n2]) print(out) else : out="" for n1 in range(500): out="" for n2 in range(500): out=out+""+str(mat[n1][n2]) print(out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := 0 ; var n1 : int := 0 ; var n2 : int := 0 ; var n3 : int := 0 ; var n4 : int := 0 ; var n5 : int := 0 ; if K <= 499 then ( n := K ; var mat : Sequence := Integer.subrange(0, K-1)->select(n2 | true)->collect(n2 | (Integer.subrange(0, K-1)->select(n1 | true)->collect(n1 | (0)))) ; for n1 : Integer.subrange(0, K-1) do ( for n2 : Integer.subrange(0, K - n1-1) do ( mat[n1+1][n1 + n2+1] := n2 + 1)) ; for n1 : Integer.subrange(0, K-1) do ( for n2 : Integer.subrange(0, n1-1) do ( mat[n1+1][n2+1] := K + n2 - n1 + 1)) ) else ( n := 500 ; mat := Integer.subrange(0, 500-1)->select(n2 | true)->collect(n2 | (Integer.subrange(0, 500-1)->select(n1 | true)->collect(n1 | (0)))) ; for n1 : Integer.subrange(0, 500-1) do ( for n2 : Integer.subrange(0, 500 - n1-1) do ( mat[n1+1][n1 + n2+1] := n2 + 1)) ; for n1 : Integer.subrange(0, 500-1) do ( for n2 : Integer.subrange(0, n1-1) do ( mat[n1+1][n2+1] := 500 + n2 - n1 + 1)) ; for n2 : Integer.subrange(0, K - 500-1) do ( for n1 : Integer.subrange(0, 250-1) do ( var kari : int := n1 * 2 + n2 ; if kari >= 500 then ( kari := kari - 500 ) else skip ; mat[n1 * 2+1][kari+1] := n2 + 501)) ) ; execute (n)->display() ; if K <= 500 then ( var out : String := "" ; for n1 : Integer.subrange(0, K-1) do ( out := "" ; for n2 : Integer.subrange(0, K-1) do ( out := out + "" + ("" + ((mat[n1+1][n2+1])))) ; execute (out)->display()) ) else ( out := "" ; for n1 : Integer.subrange(0, 500-1) do ( out := "" ; for n2 : Integer.subrange(0, 500-1) do ( out := out + "" + ("" + ((mat[n1+1][n2+1])))) ; execute (out)->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- K=int(input()) if K==1 : print(1) print(1) exit() N=2*((K+3)//4) ans=[[0]*N for i in range(N)] for i in range(N): for j in range(N): ans[i][j]=(i+j)% N+1 if i % 2 and ans[i][j]+N<=K : ans[i][j]+=N print(N) for row in ans : print(*row) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if K = 1 then ( execute (1)->display() ; execute (1)->display() ; exit() ) else skip ; var N : int := 2 * ((K + 3) div 4) ; var ans : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, N))) ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( ans[i+1][j+1] := (i + j) mod N + 1 ; if i mod 2 & (ans[i+1][j+1] + N->compareTo(K)) <= 0 then ( ans[i+1][j+1] := ans[i+1][j+1] + N ) else skip)) ; execute (N)->display() ; for row : ans do ( execute ((argument * (test (logical_test (comparison (expr (atom (name row))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) a=list(map(int,input().split())) def cond(n): L=(0,-1) for i in range(1,N): if a[i]>=n and a[i-1]>=n : L=(i,1) elif a[i]=n and a[i+1]>=n : R=(i,1) elif a[i]=n elif L[1]==-1 : return R[1]==1 elif R[1]==-1 : return L[1]==1 elif L[1]==R[1]: return R[1]==1 else : if L[1]==0 : return N-1-L[0]>R[0]-(N-1) else : return N-1-L[0]1 : test=(end+start)//2 if cond(test): start=test else : end=test if cond(end): print(end) else : print(start) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; var start : int := 1 ; var end : double := 2 * N - 1 ; while end - start > 1 do ( var test : int := (end + start) div 2 ; if cond(test) then ( start := test ) else ( end := test )) ; if cond(end) then ( execute (end)->display() ) else ( execute (start)->display() ); operation cond(n : OclAny) : OclAny pre: true post: true activity: var L : OclAny := Sequence{0, -1} ; for i : Integer.subrange(1, N-1) do ( if (a[i+1]->compareTo(n)) >= 0 & (a[i - 1+1]->compareTo(n)) >= 0 then ( L := Sequence{i, 1} ) else (if (a[i+1]->compareTo(n)) < 0 & (a[i - 1+1]->compareTo(n)) < 0 then ( L := Sequence{i, 0} ) else skip)) ; var R : OclAny := Sequence{2 * N - 1, -1} ; for i : Integer.subrange(N - 2 + 1, 2 * N - 3)->reverse() do ( if (a[i+1]->compareTo(n)) >= 0 & (a[i + 1+1]->compareTo(n)) >= 0 then ( R := Sequence{i, 1} ) else (if (a[i+1]->compareTo(n)) < 0 & (a[i + 1+1]->compareTo(n)) < 0 then ( R := Sequence{i, 0} ) else skip)) ; if L[1+1] = -1 & R[1+1] = -1 then ( return (a->first()->compareTo(n)) >= 0 ) else (if L[1+1] = -1 then ( return R[1+1] = 1 ) else (if R[1+1] = -1 then ( return L[1+1] = 1 ) else (if L[1+1] = R[1+1] then ( return R[1+1] = 1 ) else ( if L[1+1] = 0 then ( return (N - 1 - L->first()->compareTo(R->first() - (N - 1))) > 0 ) else ( return (N - 1 - L->first()->compareTo(R->first() - (N - 1))) < 0 ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline readlines=sys.stdin.readlines import numpy as np N=int(readline()) A=np.array(readline().split(),np.int32) def test(x): B=(A>=x) flag=np.zeros(N+N-1,np.bool) flag[:-1]=(B[:-1]==B[1 :]) x=np.where(flag[: N])[0] L=x.max()+1 if len(x)>=1 else 0 x=np.where(flag[N-1 :-1])[0] R=x.min()+N-1 if len(x)>=1 else N+N-2 if(N-1)-L>R-(N-1): return B[R] else : return B[L] left=0 right=N+N+10 while left+1toInteger() ; var A : Sequence := (readline().split(), ) ; skip ; var left : int := 0 ; var right : int := N + N + 10 ; while (left + 1->compareTo(right)) < 0 do ( var mid : int := (left + right) div 2 ; if test(mid) then ( left := mid ) else ( right := mid )) ; var answer : int := left ; execute (answer)->display(); operation test(x : OclAny) : OclAny pre: true post: true activity: var B : boolean := ((A->compareTo(x)) >= 0) ; var flag : Sequence := MatrixLib.singleValueMatrix(N + N - 1, 0.0) ; flag->front() := (B->front() = B->tail()) ; x := np.where(flag.subrange(1,N))->first() ; var L : double := if (x)->size() >= 1 then x->max() + 1 else 0 endif ; x := np.where(flag.subrange(N - 1+1, -1))->first() ; var R : double := if (x)->size() >= 1 then x->min() + N - 1 else N + N - 2 endif ; if ((N - 1) - L->compareTo(R - (N - 1))) > 0 then ( return B[R+1] ) else ( return B[L+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) a=[0]+list(map(int,input().split())) def check(n): b=[False]*(len(a)) for i in range(1,len(a)): if a[i]>=n : b[i]=True else : b[i]=False r=int(1e9) l=int(1e9) rb=b[N] lb=b[N] for i in range(1,N): if lb==b[N-i]: l=i break else : lb=b[N-i] for i in range(1,N): if rb==b[N+i]: r=i break else : rb=b[N+i] if r==int(1e9)and l==int(1e9): if N % 2==1 : return b[N] else : return not b[N] else : if rtoInteger() ; var a : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; skip ; skip ; execute (binarySearch(2, 2 * N - 2))->display(); operation check(n : OclAny) : OclAny pre: true post: true activity: var b : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, ((a)->size())) ; for i : Integer.subrange(1, (a)->size()-1) do ( if (a[i+1]->compareTo(n)) >= 0 then ( b[i+1] := true ) else ( b[i+1] := false )) ; var r : int := ("" + ((("1e9")->toReal())))->toInteger() ; var l : int := ("" + ((("1e9")->toReal())))->toInteger() ; var rb : OclAny := b[N+1] ; var lb : OclAny := b[N+1] ; for i : Integer.subrange(1, N-1) do ( if lb = b[N - i+1] then ( l := i ; break ) else ( lb := b[N - i+1] )) ; for i : Integer.subrange(1, N-1) do ( if rb = b[N + i+1] then ( r := i ; break ) else ( rb := b[N + i+1] )) ; if r = ("" + ((("1e9")->toReal())))->toInteger() & l = ("" + ((("1e9")->toReal())))->toInteger() then ( if N mod 2 = 1 then ( return b[N+1] ) else ( return not(b[N+1]) ) ) else ( if (r->compareTo(l)) < 0 then ( return rb ) else ( return lb ) ); operation binarySearch(small : OclAny, big : OclAny) : OclAny pre: true post: true activity: var mid : int := (big + small) div 2 ; if big - small <= 1 then ( if check(small) then ( return small ) else ( return big ) ) else ( if not(check(mid)) then ( return binarySearch(small, mid) ) else ( return binarySearch(mid, big) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) A=list(map(int,input().split())) l=1 r=2*n while l=mid) C.append(0) for i in range(1,2*n-1): if B[i-1]==B[i]: C[i]=1 for i in range(0,2*n-2): if B[i+1]==B[i]: C[i]=1 mi=2*n ans=False for i in range(0,2*n-1): if C[i]==1 : if abs(i-n+1)toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : int := 1 ; var r : int := 2 * n ; while (l->compareTo(r - 1)) < 0 do ( var mid : int := (l + r) div 2 ; var B : Sequence := Sequence{} ; var C : Sequence := Sequence{} ; for i : Integer.subrange(0, 2 * n - 1-1) do ( execute (((A[i+1]->compareTo(mid)) >= 0) : B) ; execute ((0) : C)) ; for i : Integer.subrange(1, 2 * n - 1-1) do ( if B[i - 1+1] = B[i+1] then ( C[i+1] := 1 ) else skip) ; for i : Integer.subrange(0, 2 * n - 2-1) do ( if B[i + 1+1] = B[i+1] then ( C[i+1] := 1 ) else skip) ; var mi : int := 2 * n ; var ans : boolean := false ; for i : Integer.subrange(0, 2 * n - 1-1) do ( if C[i+1] = 1 then ( if ((i - n + 1)->abs()->compareTo(mi)) < 0 then ( mi := (i - n + 1)->abs() ; ans := B[i+1] ) else skip ) else skip) ; if mi = 2 * n then ( ans := MathLib.bitwiseXor(((n + 1) mod 2), B[n - 1+1]) ) else skip ; if ans = true then ( l := mid ) else ( r := mid )) ; execute (l)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class ListNode(object): def __init__(self,x): self.val=x self.next=None class Solution(object): def addTwoNumbers(self,l1,l2): carry=0 head=curr=ListNode(0) while l1 or l2 : val=carry if l1 : val+=l1.val l1=l1.next if l2 : val+=l2.val l2=l2.next curr.next=ListNode(val % 10) curr=curr.next carry=val/10 if carry>0 : curr.next=ListNode(carry) return head.next ------------------------------------------------------------ OCL File: --------- class ListNode extends object { static operation newListNode() : ListNode pre: true post: ListNode->exists( _x | result = _x ); attribute val : OclAny := x; attribute next : OclAny := null; operation initialise(x : OclAny) : pre: true post: true activity: self.val := x ; self.next := null; return self; } class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation addTwoNumbers(l1 : OclAny,l2 : OclAny) : OclAny pre: true post: true activity: var carry : int := 0 ; var head : OclAny := (ListNode.newListNode()).initialise(0); var curr : ListNode := (ListNode.newListNode()).initialise(0) ; while l1 or l2 do ( var val : int := carry ; if l1 then ( val := val + l1.val ; l1 := l1.next ) else skip ; if l2 then ( val := val + l2.val ; l2 := l2.next ) else skip ; curr.next := (ListNode.newListNode()).initialise(val mod 10) ; curr := curr.next ; carry := val / 10) ; if carry > 0 then ( curr.next := (ListNode.newListNode()).initialise(carry) ) else skip ; return head.next; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) def check(mid): if a[n-1]>=mid and(a[n-2]>=mid or a[n]>=mid): return True elif a[n-1]0 : if(a[l]=mid else : return a[r]>=mid ok=0 ng=n*2 while ng-ok>1 : mid=(ok+ng)//2 if check(mid): ok=mid else : ng=mid print(ok) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; var ok : int := 0 ; var ng : int := n * 2 ; while ng - ok > 1 do ( mid := (ok + ng) div 2 ; if check(mid) then ( ok := mid ) else ( ng := mid )) ; execute (ok)->display(); operation check(mid : OclAny) : OclAny pre: true post: true activity: if (a[n - 1+1]->compareTo(mid)) >= 0 & ((a[n - 2+1]->compareTo(mid)) >= 0 or (a[n+1]->compareTo(mid)) >= 0) then ( return true ) else (if (a[n - 1+1]->compareTo(mid)) < 0 & ((a[n - 2+1]->compareTo(mid)) < 0 or (a[n+1]->compareTo(mid)) < 0) then ( return false ) else skip) ; var l : double := n - 1 ; while l > 0 do ( if MathLib.bitwiseXor(((a[l+1]->compareTo(mid)) < 0), ((a[l - 1+1]->compareTo(mid)) < 0)) then ( l := l - 1 ) else ( break )) ; var r : double := n - 1 ; while (r->compareTo(n * 2 - 2)) < 0 do ( if MathLib.bitwiseXor(((a[r+1]->compareTo(mid)) < 0), ((a[r + 1+1]->compareTo(mid)) < 0)) then ( r := r + 1 ) else ( break )) ; if l = 0 & r = n * 2 - 1 then ( return (MathLib.bitwiseXor((MathLib.bitwiseAnd(n, 1)), ((a[n - 1+1]->compareTo(mid)) < 0)))->toBoolean() ) else skip ; if ((n - 1 - l)->abs()->compareTo((n - 1 - r)->abs())) < 0 then ( return (a[l+1]->compareTo(mid)) >= 0 ) else ( return (a[r+1]->compareTo(mid)) >= 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countRotations(arr,n): min=arr[0] for i in range(0,n): if(min>arr[i]): min=arr[i] min_index=i return min_index ; arr=[15,18,2,3,6,12] n=len(arr) print(countRotations(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{15}->union(Sequence{18}->union(Sequence{2}->union(Sequence{3}->union(Sequence{6}->union(Sequence{ 12 }))))) ; n := (arr)->size() ; execute (countRotations(arr, n))->display(); operation countRotations(arr : OclAny, n : OclAny) pre: true post: true activity: var min : OclAny := arr->first() ; for i : Integer.subrange(0, n-1) do ( if ((min->compareTo(arr[i+1])) > 0) then ( min := arr[i+1] ; var min_index : OclAny := i ) else skip) ; return min_index;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() length=0 if len(s)% 2==0 : length=len(s)//2-1 else : length=len(s)//2 top=-1 for i in range(length): flag=True for j in range(i): if s[j]!=s[i+j+1]: flag=False if flag : top=(i+1)*2 print(top) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var length : int := 0 ; if (s)->size() mod 2 = 0 then ( length := (s)->size() div 2 - 1 ) else ( length := (s)->size() div 2 ) ; var top : int := -1 ; for i : Integer.subrange(0, length-1) do ( var flag : boolean := true ; for j : Integer.subrange(0, i-1) do ( if s[j+1] /= s[i + j + 1+1] then ( flag := false ) else skip) ; if flag then ( top := (i + 1) * 2 ) else skip) ; execute (top)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countRec(n,sum): if(n==0): return(sum==0) if(sum==0): return 1 ans=0 for i in range(0,10): if(sum-i>=0): ans=ans+countRec(n-1,sum-i) return ans def finalCount(n,sum): ans=0 for i in range(1,10): if(sum-i>=0): ans=ans+countRec(n-1,sum-i) return ans n=2 sum=5 print(finalCount(n,sum)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 2 ; sum := 5 ; execute (finalCount(n, sum))->display(); operation countRec(n : OclAny, sum : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return (sum = 0) ) else skip ; if (sum = 0) then ( return 1 ) else skip ; var ans : int := 0 ; for i : Integer.subrange(0, 10-1) do ( if (sum - i >= 0) then ( ans := ans + countRec(n - 1, sum - i) ) else skip) ; return ans; operation finalCount(n : OclAny, sum : OclAny) : OclAny pre: true post: true activity: ans := 0 ; for i : Integer.subrange(1, 10-1) do ( if (sum - i >= 0) then ( ans := ans + countRec(n - 1, sum - i) ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lookup=[[-1 for i in range(501)]for i in range(101)] def countRec(n,Sum): if(n==0): return Sum==0 if(lookup[n][Sum]!=-1): return lookup[n][Sum] ans=0 for i in range(10): if(Sum-i>=0): ans+=countRec(n-1,Sum-i) lookup[n][Sum]=ans return lookup[n][Sum] def finalCount(n,Sum): ans=0 for i in range(1,10): if(Sum-i>=0): ans+=countRec(n-1,Sum-i) return ans n,Sum=3,5 print(finalCount(n,Sum)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lookup : Sequence := Integer.subrange(0, 101-1)->select(i | true)->collect(i | (Integer.subrange(0, 501-1)->select(i | true)->collect(i | (-1)))) ; skip ; skip ; Sequence{n,Sum} := Sequence{3,5} ; execute (finalCount(n, Sum))->display(); operation countRec(n : OclAny, Sum : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return Sum = 0 ) else skip ; if (lookup[n+1][Sum+1] /= -1) then ( return lookup[n+1][Sum+1] ) else skip ; var ans : int := 0 ; for i : Integer.subrange(0, 10-1) do ( if (Sum - i >= 0) then ( ans := ans + countRec(n - 1, Sum - i) ) else skip) ; lookup[n+1][Sum+1] := ans ; return lookup[n+1][Sum+1]; operation finalCount(n : OclAny, Sum : OclAny) : OclAny pre: true post: true activity: ans := 0 ; for i : Integer.subrange(1, 10-1) do ( if (Sum - i >= 0) then ( ans := ans + countRec(n - 1, Sum - i) ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countIndices(arr,n): cnt=0 ; max=0 ; for i in range(n): if(maxunion(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))); ; n := (arr)->size(); ; execute (countIndices(arr, n))->display(); ) else skip; operation countIndices(arr : OclAny, n : OclAny) pre: true post: true activity: var cnt : int := 0; ; var max : int := 0; ; for i : Integer.subrange(0, n-1) do ( if ((max->compareTo(arr[i+1])) < 0) then ( max := arr[i+1]; ; cnt := cnt + 1; ) else skip) ; return cnt;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def slopeOfNum(num,n): slope=0 for i in range(1,n-1): if(num[i]>num[i-1]and num[i]>num[i+1]): slope+=1 elif(num[i]size() ; execute ("Slpoe=")->display() ) else skip; operation slopeOfNum(num : OclAny, n : OclAny) : OclAny pre: true post: true activity: var slope : int := 0 ; for i : Integer.subrange(1, n - 1-1) do ( if ((num[i+1]->compareTo(num[i - 1+1])) > 0 & (num[i+1]->compareTo(num[i + 1+1])) > 0) then ( slope := slope + 1 ) else (if ((num[i+1]->compareTo(num[i - 1+1])) < 0 & (num[i+1]->compareTo(num[i + 1+1])) < 0) then ( slope := slope + 1 ) else skip)) ; return slope; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNth(N): b=14 for i in range(2,N+1): if(i % 2==0): b=b*2 else : b=b-8 return b N=6 print(findNth(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 6 ; execute (findNth(N))->display(); operation findNth(N : OclAny) : OclAny pre: true post: true activity: var b : int := 14 ; for i : Integer.subrange(2, N + 1-1) do ( if (i mod 2 = 0) then ( b := b * 2 ) else ( b := b - 8 )) ; return b; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binarySearchCount(arr,n,key): left=0 right=n mid=0 while(leftkey): right=mid else : left=mid+1 while(mid>-1 and arr[mid]>key): mid-=1 return mid+1 arr=[1,2,4,5,8,10] key=11 n=len(arr) print(binarySearchCount(arr,n,key)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{5}->union(Sequence{8}->union(Sequence{ 10 }))))) ; key := 11 ; n := (arr)->size() ; execute (binarySearchCount(arr, n, key))->display(); operation binarySearchCount(arr : OclAny, n : OclAny, key : OclAny) : OclAny pre: true post: true activity: var left : int := 0 ; var right : OclAny := n ; var mid : int := 0 ; while ((left->compareTo(right)) < 0) do ( mid := (right + left) div 2 ; if (arr[mid+1] = key) then ( while ((mid + 1->compareTo(n)) < 0 & arr[mid + 1+1] = key) do ( mid := mid + 1) ; break ) else (if ((arr[mid+1]->compareTo(key)) > 0) then ( right := mid ) else ( left := mid + 1 ) ) ) ; while (mid > -1 & (arr[mid+1]->compareTo(key)) > 0) do ( mid := mid - 1) ; return mid + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPowerOfTwo(x): return(x and(not(x &(x-1)))) def Count_pairs(a,n): count=0 for i in range(n): if isPowerOfTwo(a[i]): count+=1 ans=(count*(count-1))/2 print(ans) if __name__=="__main__" : a=[2,5,8,16,128] n=len(a) Count_pairs(a,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( a := Sequence{2}->union(Sequence{5}->union(Sequence{8}->union(Sequence{16}->union(Sequence{ 128 })))) ; n := (a)->size() ; Count_pairs(a, n) ) else skip; operation isPowerOfTwo(x : OclAny) : OclAny pre: true post: true activity: return (x & (not((MathLib.bitwiseAnd(x, (x - 1)))))); operation Count_pairs(a : OclAny, n : OclAny) pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( if isPowerOfTwo(a[i+1]) then ( count := count + 1 ) else skip) ; var ans : double := (count * (count - 1)) / 2 ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) t="{0:b}".format(n) one=t.count("1") print(2**one) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; t := StringLib.interpolateStrings("{0:b}", Sequence{n}) ; var one : int := t->count("1") ; execute ((2)->pow(one))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function import sys word=raw_input().strip().lower() cnt=0 for line in sys.stdin : if line.startswith('END_OF_TEXT'): break cnt+=line.lower().split().count(word) print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var word : OclAny := raw_input()->trim()->toLowerCase() ; var cnt : int := 0 ; for line : OclFile["System.in"] do ( if line->hasPrefix('END_OF_TEXT') then ( break ) else skip ; cnt := cnt + line->toLowerCase().split()->count(word)) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): a=bin(int(input()))[2 :] print(2**(a.count('1'))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := bin(("" + (((OclFile["System.in"]).readLine())))->toInteger()).subrange(2+1) ; execute ((2)->pow((a->count('1'))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() n=len(s) if n % 2==1 : n-=1 for i in range(n-2,0,-2): if s[: i//2]==s[i//2 : i]: print(i) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var n : int := (s)->size() ; if n mod 2 = 1 then ( n := n - 1 ) else skip ; for i : Integer.subrange(n - 2, 0-1)->select( $x | ($x - n - 2) mod -2 = 0 ) do ( if s.subrange(1,i div 2) = s.subrange(i div 2+1, i) then ( execute (i)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t=int(input()) ans=[] pow2=[1] for _ in range(30): pow2.append(2*pow2[-1]) for _ in range(t): a=int(input()) c=0 for i in pow2 : if i & a : c+=1 ans0=pow2[c] ans.append(ans0) sys.stdout.write("\n".join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; var pow2 : Sequence := Sequence{ 1 } ; for _anon : Integer.subrange(0, 30-1) do ( execute ((2 * pow2->last()) : pow2)) ; for _anon : Integer.subrange(0, t-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := 0 ; for i : pow2 do ( if MathLib.bitwiseAnd(i, a) then ( c := c + 1 ) else skip) ; var ans0 : OclAny := pow2[c+1] ; execute ((ans0) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def math_mag(): t=int(input()) numbers=[] for i in range(t): numbers.append(int(input())) for a in numbers : if a==0 : print(1) elif a==1 or a==2 : print(2) else : a=bin(a) y=0 for s in a : if s=='1' : y+=1 print(2**y) math_mag() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; math_mag(); operation math_mag() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var numbers : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : numbers)) ; for a : numbers do ( if a = 0 then ( execute (1)->display() ) else (if a = 1 or a = 2 then ( execute (2)->display() ) else ( var a : OclAny := bin(a) ; var y : int := 0 ; for s : a do ( if s = '1' then ( y := y + 1 ) else skip) ; execute ((2)->pow(y))->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a,b,C=map(int,raw_input().split()) C=C/180.0*math.pi S=(float)(0.5*a*b*math.sin(C)) L=(float)(a+b+math.sqrt(a**2+b**2-2*a*b*math.cos(C))) h=(float)(b*math.sin(C)) print("{0:.8f}{1:.8f}{2:.8f}").format(S,L,h) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; var C : OclAny := null; Sequence{a,b,C} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var C : double := C / 180.0 * ; var S : OclAny := (OclType["double"])(0.5 * a * b * (C)->sin()) ; var L : OclAny := (OclType["double"])(a + b + ((a)->pow(2) + (b)->pow(2) - 2 * a * b * )->sqrt()) ; var h : OclAny := (OclType["double"])(b * (C)->sin()) ; (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "{0:.8f}{1:.8f}{2:.8f}"))))))) ))) (trailer . (name format) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name S))))))) , (argument (test (logical_test (comparison (expr (atom (name L))))))) , (argument (test (logical_test (comparison (expr (atom (name h)))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a,b,deg=map(float,input().split()) rad=deg*math.pi/180 c=(a**2+b**2-2*a*b*math.cos(rad))**0.5 area=a*b*math.sin(rad)/2.0 perimeter=a+b+c h=2*area/a print("%.6f\n%.6f\n%.6f\n" %(area,perimeter,h)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; var deg : OclAny := null; Sequence{a,b,deg} := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; var rad : double := deg * / 180 ; var c : double := (((a)->pow(2) + (b)->pow(2) - 2 * a * b * ))->pow(0.5) ; var area : double := a * b * (rad)->sin() / 2.0 ; var perimeter : OclAny := a + b + c ; var h : double := 2 * area / a ; execute (StringLib.format("%.6f\n%.6f\n%.6f\n",Sequence{area, perimeter, h}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a,b,c=map(int,input().split()) sinc=math.sin(math.radians(c)) cosc=math.cos(math.radians(c)) S=a*b*sinc/2 L=a+b+math.sqrt(a**2+b**2-2*a*b*cosc) h=b*sinc print("%.4f" %(S)) print("%.4f" %(L)) print("%.4f" %(h)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sinc : double := ()->sin() ; var cosc : OclAny := ; var S : double := a * b * sinc / 2 ; var L : OclAny := a + b + ((a)->pow(2) + (b)->pow(2) - 2 * a * b * cosc)->sqrt() ; var h : double := b * sinc ; execute (StringLib.format("%.4f",(S)))->display() ; execute (StringLib.format("%.4f",(L)))->display() ; execute (StringLib.format("%.4f",(h)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math (a,b,C)=map(float,input().split()) C=math.radians(C) c=math.sqrt(a*a+b*b-2*a*b*math.cos(C)) S=a*b*math.sin(C)/2 L=a+b+c h=b*math.sin(C) S=format(S,'.8f') L=format(L,'.8f') h=format(h,'.8f') print(S,L,h,sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var Sequence{a, b, C} : Sequence := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; var C : OclAny := ; var c : double := (a * a + b * b - 2 * a * b * )->sqrt() ; var S : double := a * b * (C)->sin() / 2 ; var L : OclAny := a + b + c ; var h : double := b * (C)->sin() ; S := (S + "") ; L := (L + "") ; h := (h + "") ; execute (S)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math numbers=input().strip().split() numbers=list(map(float,numbers)) a=numbers[0] b=numbers[1] rad=numbers[2]/180*math.pi h=b*math.sin(rad) S=a*h/2 c=math.sqrt(a**2+b**2-2*a*b*math.cos(rad)) L=a+b+c print("%.5f %.5f %.5f" %(S,L,h)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var numbers : OclAny := input()->trim().split() ; numbers := ((numbers)->collect( _x | (OclType["double"])->apply(_x) )) ; var a : OclAny := numbers->first() ; var b : OclAny := numbers[1+1] ; var rad : double := numbers[2+1] / 180 * ; var h : double := b * (rad)->sin() ; var S : double := a * h / 2 ; var c : double := ((a)->pow(2) + (b)->pow(2) - 2 * a * b * )->sqrt() ; var L : OclAny := a + b + c ; execute (StringLib.format("%.5f %.5f %.5f",Sequence{S, L, h}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=list(map(int,input().split())) q=sorted(p) ans=0 for i in range(n): if p[i]!=q[i]: ans+=1 if(ans<=2): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : Sequence := p->sort() ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if p[i+1] /= q[i+1] then ( ans := ans + 1 ) else skip) ; if (ans <= 2) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(input()) p=list(map(int,input().split())) def check(ls): for i in range(len(ls)-1): if ls[i]>ls[i+1]: return False return True for i in range(n): for j in range(i,n): p[i],p[j]=p[j],p[i] if check(p): print('YES') sys.exit() p[j],p[i]=p[i],p[j] print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i, n-1) do ( var p[i+1] : OclAny := null; var p[j+1] : OclAny := null; Sequence{p[i+1],p[j+1]} := Sequence{p[j+1],p[i+1]} ; if check(p) then ( execute ('YES')->display() ; sys.exit() ) else skip ; var p[j+1] : OclAny := null; var p[i+1] : OclAny := null; Sequence{p[j+1],p[i+1]} := Sequence{p[i+1],p[j+1]})) ; execute ('NO')->display(); operation check(ls : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, (ls)->size() - 1-1) do ( if (ls[i+1]->compareTo(ls[i + 1+1])) > 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : W=input().lower() sentence_list=[] while True : word_line=input().split() if 'END_OF_TEXT' in word_line : sentence_end=word_line.index('END_OF_TEXT') sentence_list.extend(word_line[: sentence_end]) break sentence_list.extend(word_line) sentence_list=[x.lower()for x in sentence_list] words_appearance=sentence_list.count(W) print(words_appearance) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var W : OclAny := input()->toLowerCase() ; var sentence_list : Sequence := Sequence{} ; while true do ( var word_line : OclAny := input().split() ; if (word_line)->includes('END_OF_TEXT') then ( var sentence_end : int := word_line->indexOf('END_OF_TEXT') - 1 ; sentence_list := sentence_list->union(word_line.subrange(1,sentence_end)) ; break ) else skip ; sentence_list := sentence_list->union(word_line)) ; sentence_list := sentence_list->select(x | true)->collect(x | (x->toLowerCase())) ; var words_appearance : int := sentence_list->count(W) ; execute (words_appearance)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): s=input() for i in range(2,len(s)): ed=len(s)-i mid=ed//2 if s[: mid]==s[mid : ed]: print(len(s[: ed])) return if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(2, (s)->size()-1) do ( var ed : double := (s)->size() - i ; var mid : int := ed div 2 ; if s.subrange(1,mid) = s.subrange(mid+1, ed) then ( execute ((s.subrange(1,ed))->size())->display() ; return ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input(); print("YNEOS"[len([1 for i,q in enumerate(map(int,input().split()),1)if q!=i])>2 : : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input(); execute ("YNEOS"(subscript (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name q)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name q)))) != (comparison (expr (atom (name i)))))))))) ]))))))) ))))) > (comparison (expr (atom (number (integer 2)))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_lines=int(input()) if num_lines<2 or num_lines>50 : print('Illegal') exit() a=list(map(int,input().split(" "))) x=[] j=0 f=False for i in range(num_lines): if((i==0 or a[i]>=a[i-1])and(i==num_lines-1 or a[i]<=a[i+1])): continue else : x.append(i) j+=1 if j>0 and j<=4 and j!=1 : p=a[x[0]] a[x[0]]=a[x[j-1]] a[x[j-1]]=p for k in range(j): i=x[k] if((i==0 or a[i]>=a[i-1])and(i==num_lines-1 or a[i]<=a[i+1])): continue else : f=True break elif j!=0 : f=True if f : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_lines : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if num_lines < 2 or num_lines > 50 then ( execute ('Illegal')->display() ; exit() ) else skip ; var a : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var x : Sequence := Sequence{} ; var j : int := 0 ; var f : boolean := false ; for i : Integer.subrange(0, num_lines-1) do ( if ((i = 0 or (a[i+1]->compareTo(a[i - 1+1])) >= 0) & (i = num_lines - 1 or (a[i+1]->compareTo(a[i + 1+1])) <= 0)) then ( continue ) else ( execute ((i) : x) ; j := j + 1 )) ; if j > 0 & j <= 4 & j /= 1 then ( var p : OclAny := a[x->first()+1] ; a[x->first()+1] := a[x[j - 1+1]+1] ; a[x[j - 1+1]+1] := p ; for k : Integer.subrange(0, j-1) do ( var i : OclAny := x[k+1] ; if ((i = 0 or (a[i+1]->compareTo(a[i - 1+1])) >= 0) & (i = num_lines - 1 or (a[i+1]->compareTo(a[i + 1+1])) <= 0)) then ( continue ) else ( f := true ; break )) ) else (if j /= 0 then ( f := true ) else skip) ; if f then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=[int(x)for x in input().split()] right=[int(x+1)for x in range(n)] diff=0 for i in range(n): if p[i]!=right[i]: diff+=1 if diff in(0,2): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var right : Sequence := Integer.subrange(0, n-1)->select(x | true)->collect(x | (("" + ((x + 1)))->toInteger())) ; var diff : int := 0 ; for i : Integer.subrange(0, n-1) do ( if p[i+1] /= right[i+1] then ( diff := diff + 1 ) else skip) ; if (Sequence{0, 2})->includes(diff) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys N=3 M=3 def sumMaxOccuring(arr): mp=dict() for i in range(N): for j in range(M): if arr[i][j]in mp : mp[arr[i][j]]+=1 else : mp[arr[i][j]]=1 s=0 maxFreq=-sys.maxsize for i in mp : if mp[i]>maxFreq : maxFreq=mp[i] for i in mp : if mp[i]==maxFreq : s+=i*mp[i] return s if __name__=="__main__" : mat=[[1,2,3],[1,3,2],[1,5,6]] print(sumMaxOccuring(mat)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 3 ; var M : int := 3 ; skip ; if __name__ = "__main__" then ( var mat : Sequence := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{Sequence{1}->union(Sequence{3}->union(Sequence{ 2 }))}->union(Sequence{ Sequence{1}->union(Sequence{5}->union(Sequence{ 6 })) })) ; execute (sumMaxOccuring(mat))->display() ) else skip; operation sumMaxOccuring(arr : OclAny) : OclAny pre: true post: true activity: var mp : Map := (arguments ( )) ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, M-1) do ( if (mp)->includes(arr[i+1][j+1]) then ( mp[arr[i+1][j+1]+1] := mp[arr[i+1][j+1]+1] + 1 ) else ( mp[arr[i+1][j+1]+1] := 1 ))) ; var s : int := 0 ; var maxFreq : (trailer . (name maxsize)) := -(trailer . (name maxsize)) ; for i : mp->keys() do ( if (mp[i+1]->compareTo(maxFreq)) > 0 then ( maxFreq := mp[i+1] ) else skip) ; for i : mp->keys() do ( if mp[i+1] = maxFreq then ( s := s + i * mp[i+1] ) else skip) ; return s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOddOccurring(mat): mp={} n,m=len(mat),len(mat[0]) for i in range(n): for j in range(m): if mat[i][j]in mp : mp[mat[i][j]]=mp.get(mat[i][j])+1 else : mp[mat[i][j]]=1 _sum=0 for i in range(n): for j in range(m): if mp.get(mat[i][j])% 2==1 : _sum+=mat[i][j] return _sum if __name__=='__main__' : mat=[[1,2,3],[1,3,2],[1,5,6]] print(sumOddOccurring(mat)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( mat := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{Sequence{1}->union(Sequence{3}->union(Sequence{ 2 }))}->union(Sequence{ Sequence{1}->union(Sequence{5}->union(Sequence{ 6 })) })) ; execute (sumOddOccurring(mat))->display() ) else skip; operation sumOddOccurring(mat : OclAny) : OclAny pre: true post: true activity: var mp : OclAny := Set{} ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{(mat)->size(),(mat->first())->size()} ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if (mp)->includes(mat[i+1][j+1]) then ( mp[mat[i+1][j+1]+1] := mp.get(mat[i+1][j+1]) + 1 ) else ( mp[mat[i+1][j+1]+1] := 1 ))) ; var _sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if mp.get(mat[i+1][j+1]) mod 2 = 1 then ( _sum := _sum + mat[i+1][j+1] ) else skip)) ; return _sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def SumOfDigits(str,n): sum=0 for i in range(0,n): sum+=int(ord(str[i])-ord('0')) return sum def Divisible(str,n): if((SumOfDigits(str,n)% 3==0 and str[n-1]=='0')): return True return False if __name__=="__main__" : str="263730746028908374890" n=len(str) if(Divisible(str,n)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( OclType["String"] := "263730746028908374890" ; n := (OclType["String"])->size() ; if (Divisible(OclType["String"], n)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; operation SumOfDigits(OclType["String"] : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + ("" + (((("" + ([i+1])))->char2byte() - ('0')->char2byte())))->toInteger()) ; return sum; operation Divisible(OclType["String"] : OclAny, n : OclAny) : OclAny pre: true post: true activity: if ((SumOfDigits(OclType["String"], n) mod 3 = 0 & ("" + ([n - 1+1])) = '0')) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) d=list(map(int,input().split())) a,b=map(int,input().split()) d.insert(0,0) ans=0 while a!=b : ans+=d[a] a+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; d := d.insertAt(0+1, 0) ; var ans : int := 0 ; while a /= b do ( ans := ans + d[a+1] ; a := a + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ranks=int(input()) dur=[int(time)for time in input().split()] a,b=map(int,input().split()) result=0 for i in range(a-1,b-1): result+=dur[i] print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ranks : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var dur : Sequence := input().split()->select(time | true)->collect(time | (("" + ((time)))->toInteger())) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var result : int := 0 ; for i : Integer.subrange(a - 1, b - 1-1) do ( result := result + dur[i+1]) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tmp=int(input()) lst=[0]+list(map(int,input().split())) toreach,ans=list(map(int,input().split())),0 for i in range(toreach[0],toreach[-1]): ans+=lst[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var tmp : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var toreach : OclAny := null; var ans : OclAny := null; Sequence{toreach,ans} := Sequence{((input().split())->collect( _x | (OclType["int"])->apply(_x) )),0} ; for i : Integer.subrange(toreach->first(), toreach->last()-1) do ( ans := ans + lst[i+1]) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- hightest=int(input()) rate=input() start_end=input() start_end=start_end.split() rate=rate.split() result=0 for i in range(int(start_end[0])-1,int(start_end[1])-1): result+=int(rate[i]) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var hightest : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var rate : String := (OclFile["System.in"]).readLine() ; var start_end : String := (OclFile["System.in"]).readLine() ; start_end := start_end.split() ; rate := rate.split() ; var result : int := 0 ; for i : Integer.subrange(("" + ((start_end->first())))->toInteger() - 1, ("" + ((start_end[1+1])))->toInteger() - 1-1) do ( result := result + ("" + ((rate[i+1])))->toInteger()) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def longestSubArray(arr,n): isZeroPresent=False for i in range(0,n): if(arr[i]==0): isZeroPresent=True break if(isZeroPresent): return n return 0 arr=[1,2,3,0,1,2,0] n=len(arr) print(longestSubArray(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{0}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 0 })))))) ; n := (arr)->size() ; execute (longestSubArray(arr, n))->display(); operation longestSubArray(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var isZeroPresent : boolean := false ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] = 0) then ( isZeroPresent := true ; break ) else skip) ; if (isZeroPresent) then ( return n ) else skip ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- search_word=input().strip().lower() count=0 while True : line=input().strip().split(" ") if line[0]=="END_OF_TEXT" : break else : for word in line : if word.lower()==search_word : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var search_word : OclAny := input()->trim()->toLowerCase() ; var count : int := 0 ; while true do ( var line : OclAny := input()->trim().split(" ") ; if line->first() = "END_OF_TEXT" then ( break ) else ( for word : line do ( if word->toLowerCase() = search_word then ( count := count + 1 ) else skip) )) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : n=input() d=list(map(int,input().split())) a,b=map(int,input().split()) print(sum(d[a-1 : b-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var n : String := (OclFile["System.in"]).readLine() ; var d : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((d.subrange(a - 1+1, b - 1))->sum())->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) A=list(map(int,input().split())) def merge(A,left,mid,right): global count L=A[left : mid]+[math.inf] R=A[mid : right]+[math.inf] i,j=0,0 for k in range(left,right): if L[i]toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; skip ; count := 0 ; mergeSort(A, 0, n) ; execute (count)->display(); operation merge(A : OclAny, left : OclAny, mid : OclAny, right : OclAny) pre: true post: true activity: skip ; var L : OclAny := A.subrange(left+1, mid)->union(Sequence{ }) ; var R : OclAny := A.subrange(mid+1, right)->union(Sequence{ }) ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,0} ; for k : Integer.subrange(left, right-1) do ( if (L[i+1]->compareTo(R[j+1])) < 0 then ( A[k+1] := L[i+1] ; i := i + 1 ) else ( A[k+1] := R[j+1] ; j := j + 1 ; count := count + (L)->size() - 1 - i )); operation mergeSort(A : OclAny, left : OclAny, right : OclAny) pre: true post: true activity: if (left + 1->compareTo(right)) < 0 then ( mid := (left + right) div 2 ; mergeSort(A, left, mid) ; mergeSort(A, mid, right) ; merge(A, left, mid, right) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict import sys input=sys.stdin.readline class FenwickTree : def __init__(self,n): self.size=n self.tree=[0]*(n+100) def add(self,i,x): i=i+1 while i<=self.size+1 : self.tree[i]+=x i+=i &-i return def sum(self,i): i=i+1 _sum=0 while i>0 : _sum+=self.tree[i] i-=i &-i return _sum def solve(n,A): ans=0 bit=FenwickTree(n) B=sorted(A) d=defaultdict(int) for i in range(n): d[B[i]]=i for i in range(n): t=A[i] ind=d[t]+1 ans+=i-bit.sum(ind) bit.add(ind,1) return ans def main(): n=int(input().strip()) A=[int(i)for i in input().strip().split()] ans=solve(n,A) print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FenwickTree { static operation newFenwickTree() : FenwickTree pre: true post: FenwickTree->exists( _x | result = _x ); attribute size : OclAny := n; attribute tree : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 100)); operation initialise(n : OclAny) : FenwickTree pre: true post: true activity: self.size := n ; self.tree := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 100)); return self; operation add(i : OclAny,x : OclAny) pre: true post: true activity: i := i + 1 ; while (i->compareTo(self.size + 1)) <= 0 do ( self.tree[i+1] := self.tree[i+1] + x ; i := i + MathLib.bitwiseAnd(i, -i)) ; return; operation sum(i : OclAny) : OclAny pre: true post: true activity: i := i + 1 ; var _sum : int := 0 ; while i > 0 do ( _sum := _sum + self.tree[i+1] ; i := i - MathLib.bitwiseAnd(i, -i)) ; return _sum; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation solve(n : OclAny, A : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; var bit : FenwickTree := (FenwickTree.newFenwickTree()).initialise(n) ; var B : Sequence := A->sort() ; var d : OclAny := defaultdict(OclType["int"]) ; for i : Integer.subrange(0, n-1) do ( d[B[i+1]+1] := i) ; for i : Integer.subrange(0, n-1) do ( var t : OclAny := A[i+1] ; var ind : OclAny := d[t+1] + 1 ; ans := ans + i - bit.sum(ind) ; execute ((ind, 1) : bit)) ; return ans; operation main() pre: true post: true activity: n := ("" + ((input()->trim())))->toInteger() ; A := input()->trim().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; ans := solve(n, A) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cnt=0 def merge_sort(S): l=len(S) mid=int(l/2) Left=S[0 : mid] Right=S[(mid): l] global cnt if l>=2 : merge_sort(Left)and merge_sort(Right) Left.append(float('inf')) Right.append(float('inf')) p=0 q=0 for i in range(l): if Left[p]1 and len(Left)-1>=p and Left[p]!=float('inf'): cnt+=len(Left)-p-1 return S n=int(input()) A=list(map(int,input().split())) merge_sort(A) print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute cnt : OclAny; operation initialise() pre: true post: true activity: var cnt : int := 0 ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; merge_sort(A) ; execute (cnt)->display(); operation merge_sort(S : OclAny) : OclAny pre: true post: true activity: var l : int := (S)->size() ; var mid : int := ("" + ((l / 2)))->toInteger() ; var Left : OclAny := S.subrange(0+1, mid) ; var Right : OclAny := S.subrange((mid)+1, l) ; skip ; if l >= 2 then ( (logical_test (logical_test (comparison (expr (atom (name merge_sort)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name Left)))))))) )))))) and (logical_test (comparison (expr (atom (name merge_sort)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name Right)))))))) ))))))) ) else skip ; execute ((("" + (('inf')))->toReal()) : Left) ; execute ((("" + (('inf')))->toReal()) : Right) ; var p : int := 0 ; var q : int := 0 ; for i : Integer.subrange(0, l-1) do ( if (Left[p+1]->compareTo(Right[q+1])) < 0 then ( S[i+1] := Left[p+1] ; p := p + 1 ) else ( S[i+1] := Right[q+1] ; q := q + 1 ; if l > 1 & ((Left)->size() - 1->compareTo(p)) >= 0 & Left[p+1] /= ("" + (('inf')))->toReal() then ( cnt := cnt + (Left)->size() - p - 1 ) else skip )) ; return S; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) A=[(i+1,int(j))for i,j in enumerate(input().split())] A.sort(key=lambda x :-x[1]) class BIT : def __init__(self,n): self.data=[0]*(n+1) def add(self,i,x): while i<=n : self.data[i]+=x i+=i &-i def get(self,i): s=0 while i : s+=self.data[i] i-=i &-i return s b=BIT(n) ans=0 for i,j in A : ans+=b.get(i) b.add(i,1) print(ans) ------------------------------------------------------------ OCL File: --------- class BIT { static operation newBIT() : BIT pre: true post: BIT->exists( _x | result = _x ); attribute data : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); operation initialise(n : OclAny) : BIT pre: true post: true activity: self.data := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); return self; operation add(i : OclAny,x : OclAny) pre: true post: true activity: while (i->compareTo(n)) <= 0 do ( self.data[i+1] := self.data[i+1] + x ; i := i + MathLib.bitwiseAnd(i, -i)); operation get(i : OclAny) : OclAny pre: true post: true activity: var s : int := 0 ; while i do ( s := s + self.data[i+1] ; i := i - MathLib.bitwiseAnd(i, -i)) ; return s; } class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := Integer.subrange(1, (input().split())->size())->collect( _indx | Sequence{_indx-1, (input().split())->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let j : OclAny = _tuple->at(2) in (Sequence{i + 1, ("" + ((j)))->toInteger()})) ; A := A->sort() ; skip ; var b : BIT := (BIT.newBIT()).initialise(n) ; var ans : int := 0 ; for _tuple : A do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); ans := ans + b.get(i) ; execute ((i, 1) : b)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def mergeSort(A,left,right): middle=(left+right)//2 if left+1collect( _x | (OclType["int"])->apply(_x) )) ; mergeSort(A, 0, (A)->size()) ; execute (count)->display(); operation mergeSort(A : OclAny, left : OclAny, right : OclAny) pre: true post: true activity: var middle : int := (left + right) div 2 ; if (left + 1->compareTo(right)) < 0 then ( mergeSort(A, left, middle) ; mergeSort(A, middle, right) ; merge(A, left, right, middle) ) else skip; operation merge(A : OclAny, left : OclAny, right : OclAny, middle : OclAny) pre: true post: true activity: skip ; var L : Sequence := (A.subrange(left+1, middle)) ; var R : Sequence := (A.subrange(middle+1, right)) ; execute ((("" + (("inf")))->toReal()) : L) ; execute ((("" + (("inf")))->toReal()) : R) ; for i : Integer.subrange(left, right-1) do ( if (L->first()->compareTo(R->first())) < 0 then ( A[i+1] := L->first() ; L := L->tail() ) else ( A[i+1] := R->first() ; R := R->tail() ; count := count + (L)->size() - 1 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys r=sys.stdin.readline def s(): def b(M,x,y,n=1): M[x][y]=0 ; a=n if M[x-1][y]: a=max(a,b(M,x-1,y,n+1)) if M[x][y-1]: a=max(a,b(M,x,y-1,n+1)) if M[x+1][y]: a=max(a,b(M,x+1,y,n+1)) if M[x][y+1]: a=max(a,b(M,x,y+1,n+1)) M[x][y]=1 return a for e in iter(r,'0\n'): n,m=int(e),int(r()) P=[[0]*(n+2)for _ in[0]*(m+2)] for i in range(m): P[i+1][1 :-1]=map(int,r().split()) print(max(b(P,i,j)for i in range(1,m+1)for j in range(1,n+1)if P[i][j])) if '__main__'==__name__ : s() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var r : OclAny := (OclFile["System.in"]).readline ; skip ; if '__main__' = __name__ then ( s() ) else skip; operation s() pre: true post: true activity: skip ; for e : OclIterator.newOclIterator_Sequence(r, '0 ') do ( var m : OclAny := null; Sequence{n,m} := Sequence{("" + ((e)))->toInteger(),("" + ((r())))->toInteger()} ; var P : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (m + 2))->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 2)))) ; for i : Integer.subrange(0, m-1) do ( P[i + 1+1].subrange(1+1, -1) := (r().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (((argument (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name P))))))) , (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (name j)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name m))) + (expr (atom (number (integer 1)))))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (atom (name P)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))))))))->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): while True : m,n=int(input()),int(input()) if not m : break ices=[[0]+list(map(int,input().split()))+[0]for _ in range(n)] ices.insert(0,[0]*(m+2),) ices.append([0]*(m+2)) def bfs(x,y,imap,acc): imap[x][y]=0 acc+=1 a=b=c=d=0 if imap[x-1][y]: a=bfs(x-1,y,imap,acc) if imap[x+1][y]: b=bfs(x+1,y,imap,acc) if imap[x][y-1]: c=bfs(x,y-1,imap,acc) if imap[x][y+1]: d=bfs(x,y+1,imap,acc) imap[x][y]=1 return max(acc,a,b,c,d) ans=0 for x in range(1,n+1): for y in range(1,m+1): if ices[x][y]: a=bfs(x,y,ices,0) if anstoInteger(),("" + (((OclFile["System.in"]).readLine())))->toInteger()} ; if not(m) then ( break ) else skip ; var ices : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->union(Sequence{ 0 }))) ; ices := ices.insertAt(0+1, (lastArg (argument (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name m))) + (expr (atom (number (integer 2))))))))) )))))))) ,)) ; execute ((MatrixLib.elementwiseMult(Sequence{ 0 }, (m + 2))) : ices) ; skip ; var ans : int := 0 ; for x : Integer.subrange(1, n + 1-1) do ( for y : Integer.subrange(1, m + 1-1) do ( if ices[x+1][y+1] then ( a := bfs(x, y, ices, 0) ; if (ans->compareTo(a)) < 0 then ( ans := a ) else skip ) else skip)) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,n,mat,tmp=0,0,0,0 ans=0 printer=[] dx=[0,0,-1,1] dy=[1,-1,0,0] def main(): while True : global m,n,mat,tmp,printer,ans ans=0 m,n=[int(input())for _ in range(2)] if m==n==0 : break mat=[list(map(int,input().split()))for _ in range(n)] for i in range(n): for j in range(m): if mat[i][j]==1 : dfs(i,j,mat,0) printer.append(ans) for i in range(len(printer)): print(printer[i]) def dfs(i,j,mat,c): global dx,dy,ans mat[i][j]=0 c+=1 for k in range(4): if(0<=i+dy[k]<=n-1)and(0<=j+dx[k]<=m-1): if mat[i+dy[k]][j+dx[k]]==1 : dfs(i+dy[k],j+dx[k],mat,c) mat[i][j]=1 ans=max(ans,c) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute m : OclAny; attribute n : OclAny; attribute mat : OclAny; attribute tmp : OclAny; attribute printer : OclAny; attribute ans : OclAny; attribute dx : OclAny; attribute dy : OclAny; attribute ans : OclAny; operation initialise() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; var mat : OclAny := null; var tmp : OclAny := null; Sequence{m,n,mat,tmp} := Sequence{0,0,0,0} ; var ans : int := 0 ; var printer : Sequence := Sequence{} ; var dx : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{ 1 }))) ; var dy : Sequence := Sequence{1}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{ 0 }))) ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: while true do ( skip; skip; skip; skip; skip; skip ; ans := 0 ; Sequence{m,n} := Integer.subrange(0, 2-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; if m = n & (n == 0) then ( break ) else skip ; mat := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if mat[i+1][j+1] = 1 then ( dfs(i, j, mat, 0) ) else skip)) ; execute ((ans) : printer)) ; for i : Integer.subrange(0, (printer)->size()-1) do ( execute (printer[i+1])->display()); operation dfs(i : OclAny, j : OclAny, mat : OclAny, c : OclAny) pre: true post: true activity: skip; skip; skip ; mat[i+1][j+1] := 0 ; c := c + 1 ; for k : Integer.subrange(0, 4-1) do ( if (0 <= i + dy[k+1] & (i + dy[k+1] <= n - 1)) & (0 <= j + dx[k+1] & (j + dx[k+1] <= m - 1)) then ( if mat[i + dy[k+1]+1][j + dx[k+1]+1] = 1 then ( dfs(i + dy[k+1], j + dx[k+1], mat, c) ) else skip ) else skip) ; mat[i+1][j+1] := 1 ; ans := Set{ans, c}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math s=list(input()) for i in range(len(s)): s.pop() n=math.ceil(len(s)/2) if s[: n]==s[n :]: print(len(s)) sys.exit() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; for i : Integer.subrange(0, (s)->size()-1) do ( s := s->front() ; var n : double := ((s)->size() / 2)->ceil() ; if s.subrange(1,n) = s.subrange(n+1) then ( execute ((s)->size())->display() ; sys.exit() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : m=int(input()) n=int(input()) if m==n==0 : exit() graph=[] for _ in range(n): graph.append(list(map(int,input().split()))) res=0 def dfs(r,c,ice): global res ice+=1 graph[r][c]=0 for x,y in[(0,1),(1,0),(0,-1),(-1,0)]: nr,nc=r+x,c+y if nr<0 or nc<0 or nr>=n or nc>=m : continue if graph[nr][nc]==1 : dfs(nr,nc,ice) else : graph[r][c]=1 res=max(res,ice) for i in range(n): for j in range(m): if graph[i][j]==1 : dfs(i,j,0) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute res : OclAny; operation initialise() pre: true post: true activity: while true do ( var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if m = n & (n == 0) then ( exit() ) else skip ; var graph : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : graph)) ; var res : int := 0 ; skip ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if graph[i+1][j+1] = 1 then ( dfs(i, j, 0) ) else skip)) ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w=input().strip().lower() text=[] while True : t=input().strip() if t=='END_OF_TEXT' : break text+=t.lower().split() print(text.count(w)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : OclAny := input()->trim()->toLowerCase() ; var text : Sequence := Sequence{} ; while true do ( var t : OclAny := input()->trim() ; if t = 'END_OF_TEXT' then ( break ) else skip ; text := text + t->toLowerCase().split()) ; execute (text->count(w))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def b(M,x,y,n=1): M[x][y]='0' ; t=[] if '1'==M[x-1][y]: t+=[b(M,x-1,y,n+1)] if '1'==M[x][y-1]: t+=[b(M,x,y-1,n+1)] if '1'==M[x+1][y]: t+=[b(M,x+1,y,n+1)] if '1'==M[x][y+1]: t+=[b(M,x,y+1,n+1)] M[x][y]='1' return max([n]+t) for e in iter(input,'0'): n,m=int(e),int(input()) P=[['0']*(n+2)for _ in[0]*(m+2)] for i in range(m): P[i+1][1 :-1]=input().split() print(max(b(P,i,j)for i in range(1,m+1)for j in range(1,n+1)if '1'==P[i][j])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for e : OclIterator.newOclIterator_Sequence(input, '0') do ( var m : OclAny := null; Sequence{n,m} := Sequence{("" + ((e)))->toInteger(),("" + (((OclFile["System.in"]).readLine())))->toInteger()} ; var P : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (m + 2))->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ '0' }, (n + 2)))) ; for i : Integer.subrange(0, m-1) do ( P[i + 1+1].subrange(1+1, -1) := input().split()) ; execute (((argument (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name P))))))) , (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (name j)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name m))) + (expr (atom (number (integer 1)))))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom '1'))) == (comparison (expr (atom (name P)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))))))))->max())->display()); operation b(M : OclAny, x : OclAny, y : OclAny, n : int) : OclAny pre: true post: true activity: if n->oclIsUndefined() then n := 1 else skip; M[x+1][y+1] := '0'; var t : Sequence := Sequence{} ; if '1' = M[x - 1+1][y+1] then ( t := t + Sequence{ b(M, x - 1, y, n + 1) } ) else skip ; if '1' = M[x+1][y - 1+1] then ( t := t + Sequence{ b(M, x, y - 1, n + 1) } ) else skip ; if '1' = M[x + 1+1][y+1] then ( t := t + Sequence{ b(M, x + 1, y, n + 1) } ) else skip ; if '1' = M[x+1][y + 1+1] then ( t := t + Sequence{ b(M, x, y + 1, n + 1) } ) else skip ; M[x+1][y+1] := '1' ; return (Sequence{ n }->union(t))->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- try : while True : n,k=map(int,input().split()) if n+k==0 : break l=[] for i in range(n): l.append(int(input())) s1=0 for i in range(k): s1+=l[i] ma=0 s2=0 for j in range(n-k): s2=s1-l[j]+l[j+k] if s2>ma : ma=s2 s1=s2 print(ma) except EOFError : pass ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: try ( while true do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n + k = 0 then ( break ) else skip ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : l)) ; var s1 : int := 0 ; for i : Integer.subrange(0, k-1) do ( s1 := s1 + l[i+1]) ; var ma : int := 0 ; var s2 : int := 0 ; for j : Integer.subrange(0, n - k-1) do ( s2 := s1 - l[j+1] + l[j + k+1] ; if (s2->compareTo(ma)) > 0 then ( ma := s2 ) else skip ; s1 := s2) ; execute (ma)->display())) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt pass))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def shak(n,k): a=[int(input())for _ in range(n)] l,r=0,k res=0 cnt=sum(a[l : r]) while rcollect( _x | (OclType["int"])->apply(_x) ) ; if n = k & (k == 0) then ( exit() ) else skip ; shak(n, k)); operation shak(n : OclAny, k : OclAny) pre: true post: true activity: var a : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,k} ; var res : int := 0 ; var cnt : OclAny := (a.subrange(l+1, r))->sum() ; while (r->compareTo(n)) < 0 do ( res := Set{res, cnt}->max() ; cnt := cnt + a[r+1] - a[l+1] ; r := r + 1 ; l := l + 1) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : a,b=map(int,input().split()) if a==0 and b==0 : break s=[int(input())for _ in range(a)] S=sum(s[0 : b]) ss=[S] for i in range(b,a): S=S+s[i]-s[i-b] ss.append(S) print(max(ss)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 0 & b = 0 then ( break ) else skip ; var s : Sequence := Integer.subrange(0, a-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var S : OclAny := (s.subrange(0+1, b))->sum() ; var ss : Sequence := Sequence{ S } ; for i : Integer.subrange(b, a-1) do ( S := S + s[i+1] - s[i - b+1] ; execute ((S) : ss)) ; execute ((ss)->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,k=[int(x)for x in input().split()] if n==0 and k==0 : break a=[int(input())for i in range(n)] s=sum(a[0 : k]) max=s for i in range(k,n): s=s+a[i]-a[i-k] if s>max : max=s print(max) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if n = 0 & k = 0 then ( break ) else skip ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var s : OclAny := (a.subrange(0+1, k))->sum() ; var max : OclAny := s ; for i : Integer.subrange(k, n-1) do ( s := s + a[i+1] - a[i - k+1] ; if (s->compareTo(max)) > 0 then ( max := s ) else skip) ; execute (max)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin from collections import deque input=stdin.readline def main(args): while True : n,k=map(int,input().split()) if n==0 and k==0 : break d=deque([int(input())for _ in range(k)]) sum_value=sum(d) maximum_sum=sum_value for _ in range(n-k): v=int(input()) o=d.popleft() sum_value=sum_value-o+v if sum_value>maximum_sum : maximum_sum=sum_value d.append(v) print(maximum_sum) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := stdin.readline ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation main(args : OclAny) pre: true post: true activity: while true do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 & k = 0 then ( break ) else skip ; var d : Sequence := (Integer.subrange(0, k-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))) ; var sum_value : OclAny := (d)->sum() ; var maximum_sum : OclAny := sum_value ; for _anon : Integer.subrange(0, n - k-1) do ( var v : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var o : OclAny := d->first() ; d := d->tail() ; sum_value := sum_value - o + v ; if (sum_value->compareTo(maximum_sum)) > 0 then ( maximum_sum := sum_value ) else skip ; execute ((v) : d)) ; execute (maximum_sum)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countDivisibleSubseq(str,n): l=len(str) dp=[[0 for x in range(l)]for y in range(n)] dp[0][(ord(str[0])-ord('0'))% n]+=1 for i in range(1,l): dp[i][(ord(str[i])-ord('0'))% n]+=1 for j in range(n): dp[i][j]+=dp[i-1][j] dp[i][(j*10+(ord(str[i])-ord('0')))% n]+=dp[i-1][j] return dp[l-1][0] if __name__=="__main__" : str="1234" n=4 print(countDivisibleSubseq(str,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( OclType["String"] := "1234" ; n := 4 ; execute (countDivisibleSubseq(OclType["String"], n))->display() ) else skip; operation countDivisibleSubseq(OclType["String"] : OclAny, n : OclAny) : OclAny pre: true post: true activity: var l : int := (OclType["String"])->size() ; var dp : Sequence := Integer.subrange(0, n-1)->select(y | true)->collect(y | (Integer.subrange(0, l-1)->select(x | true)->collect(x | (0)))) ; dp->first()[((("" + (->first())))->char2byte() - ('0')->char2byte()) mod n+1] := dp->first()[((("" + (->first())))->char2byte() - ('0')->char2byte()) mod n+1] + 1 ; for i : Integer.subrange(1, l-1) do ( dp[i+1][((("" + ([i+1])))->char2byte() - ('0')->char2byte()) mod n+1] := dp[i+1][((("" + ([i+1])))->char2byte() - ('0')->char2byte()) mod n+1] + 1 ; for j : Integer.subrange(0, n-1) do ( dp[i+1][j+1] := dp[i+1][j+1] + dp[i - 1+1][j+1] ; dp[i+1][(j * 10 + ((("" + ([i+1])))->char2byte() - ('0')->char2byte())) mod n+1] := dp[i+1][(j * 10 + ((("" + ([i+1])))->char2byte() - ('0')->char2byte())) mod n+1] + dp[i - 1+1][j+1])) ; return dp[l - 1+1]->first(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printWellOrdered(number,x,k): if(k==0): print(number,end=" ") return for i in range((x+1),10): printWellOrdered(number*10+i,i,k-1) def generateWellOrdered(k): printWellOrdered(0,0,k) if __name__=="__main__" : k=3 generateWellOrdered(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( k := 3 ; generateWellOrdered(k) ) else skip; operation printWellOrdered(number : OclAny, x : OclAny, k : OclAny) pre: true post: true activity: if (k = 0) then ( execute (number)->display() ; return ) else skip ; for i : Integer.subrange((x + 1), 10-1) do ( printWellOrdered(number * 10 + i, i, k - 1)); operation generateWellOrdered(k : OclAny) pre: true post: true activity: printWellOrdered(0, 0, k); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNth(n): count=0 ; curr=19 ; while(True): sum=0 ; x=curr ; while(x>0): sum=sum+x % 10 ; x=int(x/10); if(sum==10): count+=1 ; if(count==n): return curr ; curr+=9 ; return-1 ; print(findNth(5)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (findNth(5))->display();; operation findNth(n : OclAny) pre: true post: true activity: var count : int := 0; ; var curr : int := 19; ; while (true) do ( var sum : int := 0; ; var x : int := curr; ; while (x > 0) do ( sum := sum + x mod 10; ; x := ("" + ((x / 10)))->toInteger();) ; if (sum = 10) then ( count := count + 1; ) else skip ; if (count = n) then ( return curr; ) else skip ; curr := curr + 9;) ; return -1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inputstring=input() inputs=inputstring.split() n=int(inputs[0]) k=int(inputs[1]) a=0.5 b=1.5 c=-(n+k) firstval=int((-b+(b**2-(4*a*c))**0.5)/(2*a)) secondval=int((-b-(b**2-(4*a*c))**0.5)/(2*a)) if firstval>=0 : numberoftimesadded=firstval else : numberoftimesadded=secondval numberoftimeseaten=n-numberoftimesadded print(numberoftimeseaten) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inputstring : String := (OclFile["System.in"]).readLine() ; var inputs : OclAny := inputstring.split() ; var n : int := ("" + ((inputs->first())))->toInteger() ; var k : int := ("" + ((inputs[1+1])))->toInteger() ; var a : double := 0.5 ; var b : double := 1.5 ; var c : int := -(n + k) ; var firstval : int := ("" + (((-b + (((b)->pow(2) - (4 * a * c)))->pow(0.5)) / (2 * a))))->toInteger() ; var secondval : int := ("" + (((-b - (((b)->pow(2) - (4 * a * c)))->pow(0.5)) / (2 * a))))->toInteger() ; if firstval >= 0 then ( var numberoftimesadded : int := firstval ) else ( numberoftimesadded := secondval ) ; var numberoftimeseaten : double := n - numberoftimesadded ; execute (numberoftimeseaten)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=[int(x)for x in input().split()] l,r=0,n while(l<=r): m=(l+r)//2 t=(n-m)**2+n-3*m if t==2*k : print(m) exit() if t<2*k : r=m-1 elif t>2*k : l=m+1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,n} ; while ((l->compareTo(r)) <= 0) do ( var m : int := (l + r) div 2 ; var t : double := ((n - m))->pow(2) + n - 3 * m ; if t = 2 * k then ( execute (m)->display() ; exit() ) else skip ; if (t->compareTo(2 * k)) < 0 then ( var r : double := m - 1 ) else (if (t->compareTo(2 * k)) > 0 then ( var l : int := m + 1 ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cou=0 i=input().lower() while True : j=[] j=input().split() if j[0]=="END_OF_TEXT" : break k=[x.lower()for x in j] cou+=k.count(i) print(cou) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cou : int := 0 ; var i : OclAny := input()->toLowerCase() ; while true do ( var j : Sequence := Sequence{} ; j := input().split() ; if j->first() = "END_OF_TEXT" then ( break ) else skip ; var k : Sequence := j->select(x | true)->collect(x | (x->toLowerCase())) ; cou := cou + k->count(i)) ; execute (cou)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) def ser(k,low,high): x=((high+low)//2) c=x*(x+1)//2-(n-x) if(c==k): print(n-x) elif c>k : ser(k,low,x) else : ser(k,x,high) ser(k,1,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; ser(k, 1, n); operation ser(k : OclAny, low : OclAny, high : OclAny) pre: true post: true activity: var x : int := ((high + low) div 2) ; var c : double := x * (x + 1) div 2 - (n - x) ; if (c = k) then ( execute (n - x)->display() ) else (if (c->compareTo(k)) > 0 then ( ser(k, low, x) ) else ( ser(k, x, high) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) d=(9+8*(n+k))**0.5 print(round(n-(-1.5+d/2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : double := ((9 + 8 * (n + k)))->pow(0.5) ; execute ((n - (-1.5 + d / 2))->round())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline a,b=map(int,input().split()) s=int((2*(a+b)+9/4)**0.5-3/2) print(a-s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : int := ("" + ((((2 * (a + b) + 9 / 4))->pow(0.5) - 3 / 2)))->toInteger() ; execute (a - s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) S=list(map(int,input().split())) q=int(input()) T=list(map(int,input().split())) ans=0 for i in T : if i in S : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var T : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : T do ( if (S)->includes(i) then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n1=int(input()) s1=set(map(int,input().strip().split())) n2=int(input()) s2=set(map(int,input().strip().split())) print(len(s1 & s2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s1 : Set := Set{}->union(((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var n2 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s2 : Set := Set{}->union(((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; execute ((MathLib.bitwiseAnd(s1, s2))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def search(l,r): counter=0 ; j=0 ; while jcollect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) )) ; input() ; var list2 : Sequence := ((input().split(' '))->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) )) ; var ans : OclAny := search(list1, list2) ; execute (ans)->display(); operation search(l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var counter : int := 0; ; var j : int := 0; ; while (j->compareTo((r)->size())) < 0 do ( for i : Integer.subrange(0, (l)->size()-1) do ( if r[j+1] = l[i+1] then ( counter := counter + 1 ; break ) else skip) ; j := j + 1) ; return counter; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function raw_input() s1=set(raw_input().split()) raw_input() s2=set(raw_input().split()) print(len(s1 & s2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; raw_input() ; var s1 : Set := Set{}->union((raw_input().split())) ; raw_input() ; var s2 : Set := Set{}->union((raw_input().split())) ; execute ((MathLib.bitwiseAnd(s1, s2))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minRemove(arr,n): LIS=[0 for i in range(n)] len=0 for i in range(n): LIS[i]=1 for i in range(1,n): for j in range(i): if(arr[i]>arr[j]and(i-j)<=(arr[i]-arr[j])): LIS[i]=max(LIS[i],LIS[j]+1) len=max(len,LIS[i]) return(n-len) arr=[1,2,6,5,4] n=len(arr) print(minRemove(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{6}->union(Sequence{5}->union(Sequence{ 4 })))) ; n := (arr)->size() ; execute (minRemove(arr, n))->display(); operation minRemove(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var LIS : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var len : int := 0 ; for i : Integer.subrange(0, n-1) do ( LIS[i+1] := 1) ; for i : Integer.subrange(1, n-1) do ( for j : Integer.subrange(0, i-1) do ( if ((arr[i+1]->compareTo(arr[j+1])) > 0 & ((i - j)->compareTo((arr[i+1] - arr[j+1]))) <= 0) then ( LIS[i+1] := Set{LIS[i+1], LIS[j+1] + 1}->max() ) else skip) ; len := Set{len, LIS[i+1]}->max()) ; return (n - len); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools def findNth(n): count=0 for curr in itertools.count(): sum=0 x=curr while(x): sum=sum+x % 10 x=x//10 if(sum==10): count=count+1 if(count==n): return curr return-1 if __name__=='__main__' : print(findNth(5)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( execute (findNth(5))->display() ) else skip; operation findNth(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for curr : itertools->count() do ( var sum : int := 0 ; var x : OclAny := curr ; while (x) do ( sum := sum + x mod 10 ; x := x div 10) ; if (sum = 10) then ( count := count + 1 ) else skip ; if (count = n) then ( return curr ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() s={int(i)for i in input().split()} q=input() t={int(i)for i in input().split()} print(len(s & t)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var s : Set := input().split()->select(i | true)->collect(i | ("" + ((i)))->toInteger())->asSet() ; var q : String := (OclFile["System.in"]).readLine() ; var t : Set := input().split()->select(i | true)->collect(i | ("" + ((i)))->toInteger())->asSet() ; execute ((MathLib.bitwiseAnd(s, t))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=map(int,input().split()) lst=[input()for i in range(n)] print(lst[-1].count('D')+sum(i[-1]=='R' for i in lst)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lst : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; execute (lst->last()->count('D') + ((argument (test (logical_test (comparison (comparison (expr (atom (name i)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))) == (comparison (expr (atom 'R')))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name lst))))))))->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n,m=[int(i)for i in input().split()] ans=0 for i in range(n): a=input() if i==n-1 : ans+=a.count("D") if a[-1]=="R" : ans+=1 return ans t=int(input()) ans=[] while t : ans.append(str(solve())) t-=1 print("\n".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; ans := Sequence{} ; while t do ( execute ((("" + ((solve())))) : ans) ; t := t - 1) ; execute (StringLib.sumStringsWithSeparator((ans), "\n"))->display(); operation solve() : OclAny pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var a : String := (OclFile["System.in"]).readLine() ; if i = n - 1 then ( ans := ans + a->count("D") ) else skip ; if a->last() = "R" then ( ans := ans + 1 ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=input().split() n=int(n) k=int(k) a=input() l=a.split() team=[] position_team=[] for i in range(len(l)): l[i]=int(l[i]) if l[i]not in team : team.append(l[i]) position_team.append(i+1) if len(team)>=k : print("YES") for i in range(k): print(position_team[i],end=" ") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var k : int := ("" + ((k)))->toInteger() ; var a : String := (OclFile["System.in"]).readLine() ; var l : OclAny := a.split() ; var team : Sequence := Sequence{} ; var position_team : Sequence := Sequence{} ; for i : Integer.subrange(0, (l)->size()-1) do ( l[i+1] := ("" + ((l[i+1])))->toInteger() ; if (team)->excludes(l[i+1]) then ( execute ((l[i+1]) : team) ; execute ((i + 1) : position_team) ) else skip) ; if ((team)->size()->compareTo(k)) >= 0 then ( execute ("YES")->display() ; for i : Integer.subrange(0, k-1) do ( execute (position_team[i+1])->display()) ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,m,grid): to_be_changed=0 for i in range(0,m): if grid[n-1][i]=='D' : to_be_changed+=1 for j in range(0,n): if grid[j][m-1]=='R' : to_be_changed+=1 return to_be_changed if __name__=="__main__" : t=int(input()) for i in range(0,t): n,m=map(int,input().split()) grid=list() for j in range(0,n): row=input() grid.append(row) print((solve(n,m,grid))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; grid := () ; for j : Integer.subrange(0, n-1) do ( var row : String := (OclFile["System.in"]).readLine() ; execute ((row) : grid)) ; execute ((solve(n, m, grid)))->display()) ) else skip; operation solve(n : OclAny, m : OclAny, grid : OclAny) : OclAny pre: true post: true activity: var to_be_changed : int := 0 ; for i : Integer.subrange(0, m-1) do ( if grid[n - 1+1][i+1] = 'D' then ( to_be_changed := to_be_changed + 1 ) else skip) ; for j : Integer.subrange(0, n-1) do ( if grid[j+1][m - 1+1] = 'R' then ( to_be_changed := to_be_changed + 1 ) else skip) ; return to_be_changed; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) for i in range(num): arr=input() arr=arr.split(" ") n=int(arr[0]) m=int(arr[1]) count=0 for j in range(n): text=input() if j!=n-1 : if text[m-1]!="D" : count+=1 else : for k in range(m-1): if text[k]!="R" : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, num-1) do ( var arr : String := (OclFile["System.in"]).readLine() ; arr := arr.split(" ") ; var n : int := ("" + ((arr->first())))->toInteger() ; var m : int := ("" + ((arr[1+1])))->toInteger() ; var count : int := 0 ; for j : Integer.subrange(0, n-1) do ( var text : String := (OclFile["System.in"]).readLine() ; if j /= n - 1 then ( if text[m - 1+1] /= "D" then ( count := count + 1 ) else skip ) else ( for k : Integer.subrange(0, m - 1-1) do ( if text[k+1] /= "R" then ( count := count + 1 ) else skip) )) ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=map(int,input().split()) lst=[input()for i in range(n)] print(lst[-1].count('D')+sum(i[-1]=='R' for i in lst)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lst : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; execute (lst->last()->count('D') + ((argument (test (logical_test (comparison (comparison (expr (atom (name i)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))) == (comparison (expr (atom 'R')))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name lst))))))))->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def replace0with5(number): number+=calculateAddedValue(number) return number def calculateAddedValue(number): result=0 decimalPlace=1 if(number==0): result+=(5*decimalPlace) while(number>0): if(number % 10==0): result+=(5*decimalPlace) number//=10 decimalPlace*=10 return result print(replace0with5(1020)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; execute (replace0with5(1020))->display(); operation replace0with5(number : OclAny) : OclAny pre: true post: true activity: number := number + calculateAddedValue(number) ; return number; operation calculateAddedValue(number : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; var decimalPlace : int := 1 ; if (number = 0) then ( result := result + (5 * decimalPlace) ) else skip ; while (number > 0) do ( if (number mod 10 = 0) then ( result := result + (5 * decimalPlace) ) else skip ; number := number div 10 ; decimalPlace := decimalPlace * 10) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def power(x,y,p): res=1 x=x % p while(y>0): if(y & 1): res=(res*x)% p y=y>>1 x=(x*x)% p return res def numberOfDigits(x): i=0 while(x): x//=10 i+=1 return i def printLastKDigits(a,b,k): print("Last "+str(k)+" digits of "+str(a)+"^"+str(b),end="=") temp=1 for i in range(1,k+1): temp*=10 temp=power(a,b,temp) for i in range(k-numberOfDigits(temp)): print("0") if(temp): print(temp) if __name__=="__main__" : a=11 b=3 k=2 printLastKDigits(a,b,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( a := 11 ; b := 3 ; k := 2 ; printLastKDigits(a, b, k) ) else skip; operation power(x : OclAny, y : OclAny, p : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; x := x mod p ; while (y > 0) do ( if (MathLib.bitwiseAnd(y, 1)) then ( res := (res * x) mod p ) else skip ; y := y /(2->pow(1)) ; x := (x * x) mod p) ; return res; operation numberOfDigits(x : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; while (x) do ( x := x div 10 ; i := i + 1) ; return i; operation printLastKDigits(a : OclAny, b : OclAny, k : OclAny) pre: true post: true activity: execute ("Last " + ("" + ((k))) + " digits of " + ("" + ((a))) + "^" + ("" + ((b))))->display() ; var temp : int := 1 ; for i : Integer.subrange(1, k + 1-1) do ( temp := temp * 10) ; temp := power(a, b, temp) ; for i : Integer.subrange(0, k - numberOfDigits(temp)-1) do ( execute ("0")->display()) ; if (temp) then ( execute (temp)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=26 ; def minOperation(str,len): first,last=[0]*MAX,[0]*MAX ; for i in range(MAX): first[i]=-1 ; last[i]=-1 ; for i in range(len): index=(ord(str[i])-ord('a')); if(first[index]==-1): first[index]=i ; last[index]=i ; minOp=-1 ; for i in range(MAX): if(first[i]==-1 or first[i]==last[i]): continue ; cnt=len-(last[i]-first[i]+1); if(minOp==-1 or cntsize(); ; execute (minOperation(OclType["String"], len))->display();; operation minOperation(OclType["String"] : OclAny, len : OclAny) pre: true post: true activity: var first : OclAny := null; var last : OclAny := null; Sequence{first,last} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, MAX),MatrixLib.elementwiseMult(Sequence{ 0 }, MAX)}; ; for i : Integer.subrange(0, MAX-1) do ( first[i+1] := -1; ; last[i+1] := -1;) ; for i : Integer.subrange(0, len-1) do ( var index : double := ((("" + ([i+1])))->char2byte() - ('a')->char2byte()); ; if (first[index+1] = -1) then ( first[index+1] := i; ) else skip ; last[index+1] := i;) ; var minOp : int := -1; ; for i : Integer.subrange(0, MAX-1) do ( if (first[i+1] = -1 or first[i+1] = last[i+1]) then ( continue; ) else skip ; var cnt : double := len - (last[i+1] - first[i+1] + 1); ; if (minOp = -1 or (cnt->compareTo(minOp)) < 0) then ( minOp := cnt; ) else skip) ; return minOp;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countNumber(N,S): countElements=0 ; currentSum=0 currSum=0 ; while(currSum<=S): currSum+=N ; N=N-1 ; countElements=countElements+1 ; return countElements ; N=5 ; S=11 ; count=countNumber(N,S); print(count); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 5; ; S := 11; ; var count : OclAny := countNumber(N, S); ; execute (count)->display();; operation countNumber(N : OclAny, S : OclAny) pre: true post: true activity: var countElements : int := 0; ; var currentSum : int := 0 ; var currSum : int := 0; ; while ((currSum->compareTo(S)) <= 0) do ( currSum := currSum + N; ; N := N - 1; ; countElements := countElements + 1;) ; return countElements;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() x=s.count("R")-s.count("L") y=s.count("U")-s.count("D") if x % 2==0 and y % 2==0 or x % 2!=0 and y % 2!=0 : print((abs(x)+abs(y))//2) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var x : double := s->count("R") - s->count("L") ; var y : double := s->count("U") - s->count("D") ; if x mod 2 = 0 & y mod 2 = 0 or x mod 2 /= 0 & y mod 2 /= 0 then ( execute (((x)->abs() + (y)->abs()) div 2)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() x,y=0,0 for i in s : if i=='L' : x+=1 elif i=='R' : x-=1 elif i=='U' : y+=1 else : y-=1 if(abs(x)+abs(y))% 2!=0 : print(-1) else : print((abs(x)+abs(y))//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{0,0} ; for i : s->characters() do ( if i = 'L' then ( x := x + 1 ) else (if i = 'R' then ( x := x - 1 ) else (if i = 'U' then ( y := y + 1 ) else ( y := y - 1 ) ) ) ) ; if ((x)->abs() + (y)->abs()) mod 2 /= 0 then ( execute (-1)->display() ) else ( execute (((x)->abs() + (y)->abs()) div 2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() C=str.count a=abs(C(s,'R')-C(s,'L'))+abs(C(s,'U')-C(s,'D')) print([-1,a//2][a % 2==0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var C : String := ("" + (.count)) ; var a : double := (C(s, 'R') - C(s, 'L'))->abs() + (C(s, 'U') - C(s, 'D'))->abs() ; execute (Sequence{-1}->union(Sequence{ a div 2 })->select(a mod 2 = 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,x,y=input(),0,0 if(len(a)% 2==1): print(-1) else : for i in a : if i=='U' : y+=1 elif i=='D' : y-=1 elif i=='L' : x-=1 elif i=='R' : x+=1 print(int((abs(x)+abs(y))/2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{a,x,y} := Sequence{(OclFile["System.in"]).readLine(),0,0} ; if ((a)->size() mod 2 = 1) then ( execute (-1)->display() ) else ( for i : a do ( if i = 'U' then ( y := y + 1 ) else (if i = 'D' then ( y := y - 1 ) else (if i = 'L' then ( x := x - 1 ) else (if i = 'R' then ( x := x + 1 ) else skip ) ) ) ) ; execute (("" + ((((x)->abs() + (y)->abs()) / 2)))->toInteger())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=input().split() n=int(n); k=int(k) a=input() l=a.split() team=[]; pos_team=[] for i in range(len(l)): l[i]=int(l[i]) if l[i]not in team : team.append(l[i]) pos_team.append(i+1) if len(team)>=k : print("YES") for i in range(k): print(pos_team[i],end=" ") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split() ; var n : int := ("" + ((n)))->toInteger(); var k : int := ("" + ((k)))->toInteger() ; var a : String := (OclFile["System.in"]).readLine() ; var l : OclAny := a.split() ; var team : Sequence := Sequence{}; var pos_team : Sequence := Sequence{} ; for i : Integer.subrange(0, (l)->size()-1) do ( l[i+1] := ("" + ((l[i+1])))->toInteger() ; if (team)->excludes(l[i+1]) then ( execute ((l[i+1]) : team) ; execute ((i + 1) : pos_team) ) else skip) ; if ((team)->size()->compareTo(k)) >= 0 then ( execute ("YES")->display() ; for i : Integer.subrange(0, k-1) do ( execute (pos_team[i+1])->display()) ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): data=input() size=len(data) if size % 2 : print(-1) else : flat={'L' : 0,'R' : 0,'U' : 0,'D' : 0} for i in range(size): flat[data[i]]+=1 LR=(abs(flat['L']-flat['R'])>>1) UD=(abs(flat['U']-flat['D'])>>1) if abs(flat['L']-flat['R'])& 1==0 : print(LR+UD) else : print(LR+UD+1) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var data : String := (OclFile["System.in"]).readLine() ; var size : int := (data)->size() ; if size mod 2 then ( execute (-1)->display() ) else ( var flat : Map := Map{ 'L' |-> 0 }->union(Map{ 'R' |-> 0 }->union(Map{ 'U' |-> 0 }->union(Map{ 'D' |-> 0 }))) ; for i : Integer.subrange(0, size-1) do ( flat[data[i+1]+1] := flat[data[i+1]+1] + 1) ; var LR : int := ((flat->at('L') - flat->at('R'))->abs() /(2->pow(1))) ; var UD : int := ((flat->at('U') - flat->at('D'))->abs() /(2->pow(1))) ; if MathLib.bitwiseAnd((flat->at('L') - flat->at('R'))->abs(), 1) = 0 then ( execute (LR + UD)->display() ) else ( execute (LR + UD + 1)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): s="".join(str(i)for i in range(1,1000000)) ans=1 for i in range(7): ans*=int(s[10**i-1]) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var s : String := StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1000000))))))))) ))))))))), "") ; var ans : int := 1 ; for i : Integer.subrange(0, 7-1) do ( ans := ans * ("" + ((s[(10)->pow(i) - 1+1])))->toInteger()) ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline a,b,c,n=map(int,input().split()) if min(a,b)0 else-1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var n : OclAny := null; Sequence{a,b,c,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (Set{a, b}->min()->compareTo(c)) < 0 then ( var ans : int := -1 ) else ( var x : double := n - (a + b - c) ; ans := if x > 0 then x else -1 endif ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,n=map(int,input().split()) if n-a-b+c<=0 or acollect( _x | (OclType["int"])->apply(_x) ) ; if n - a - b + c <= 0 or (a->compareTo(c)) < 0 or (b->compareTo(c)) < 0 then ( execute (-1)->display() ) else ( execute (n - a - b + c)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (A,B,C,N)=map(int,input().split(' ')) students_who_passed_exam=A+B-C if students_who_passed_exam>=N or C>A or C>B : print('-1') else : print(N-students_who_passed_exam) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{A, B, C, N} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var students_who_passed_exam : double := A + B - C ; if (students_who_passed_exam->compareTo(N)) >= 0 or (C->compareTo(A)) > 0 or (C->compareTo(B)) > 0 then ( execute ('-1')->display() ) else ( execute (N - students_who_passed_exam)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def strrmatch(strr,pattern,n,m): if(m==0): return(n==0) lookup=[[False for i in range(m+1)]for j in range(n+1)] lookup[0][0]=True for j in range(1,m+1): if(pattern[j-1]=='*'): lookup[0][j]=lookup[0][j-1] for i in range(1,n+1): for j in range(1,m+1): if(pattern[j-1]=='*'): lookup[i][j]=lookup[i][j-1]or lookup[i-1][j] elif(pattern[j-1]=='?' or strr[i-1]==pattern[j-1]): lookup[i][j]=lookup[i-1][j-1] else : lookup[i][j]=False return lookup[n][m] strr="baaabab" pattern="*****ba*****ab" if(strrmatch(strr,pattern,len(strr),len(pattern))): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; strr := "baaabab" ; pattern := "*****ba*****ab" ; if (strrmatch(strr, pattern, (strr)->size(), (pattern)->size())) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation strrmatch(strr : OclAny, pattern : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: if (m = 0) then ( return (n = 0) ) else skip ; var lookup : Sequence := Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, m + 1-1)->select(i | true)->collect(i | (false)))) ; lookup->first()->first() := true ; for j : Integer.subrange(1, m + 1-1) do ( if (pattern[j - 1+1] = '*') then ( lookup->first()[j+1] := lookup->first()[j - 1+1] ) else skip) ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, m + 1-1) do ( if (pattern[j - 1+1] = '*') then ( lookup[i+1][j+1] := lookup[i+1][j - 1+1] or lookup[i - 1+1][j+1] ) else (if (pattern[j - 1+1] = '?' or strr[i - 1+1] = pattern[j - 1+1]) then ( lookup[i+1][j+1] := lookup[i - 1+1][j - 1+1] ) else ( lookup[i+1][j+1] := false ) ) )) ; return lookup[n+1][m+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() a,b,c,n=list(map(int,input().split())) x=a+b-c print(n-x if c<=a and c<=b and xtoInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var n : OclAny := null; Sequence{a,b,c,n} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : double := a + b - c ; execute (if (c->compareTo(a)) <= 0 & (c->compareTo(b)) <= 0 & (x->compareTo(n)) < 0 then n - x else -1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,n=list(int(i)for i in input().split()) def fun(a,b,c,n): ans=a+b-c if a==0 and b==0 and c==0 : if n>0 : print(n) else : print(-1) return if(c>a or c>b): print(-1) return if(a>=n or b>=n or c>=n or ans<=0): print(-1) return if n-ans<=0 : print(-1) else : print(n-ans) fun(a,b,c,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var n : OclAny := null; Sequence{a,b,c,n} := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ; skip ; fun(a, b, c, n); operation fun(a : OclAny, b : OclAny, c : OclAny, n : OclAny) pre: true post: true activity: var ans : double := a + b - c ; if a = 0 & b = 0 & c = 0 then ( if n > 0 then ( execute (n)->display() ) else ( execute (-1)->display() ) ; return ) else skip ; if ((c->compareTo(a)) > 0 or (c->compareTo(b)) > 0) then ( execute (-1)->display() ; return ) else skip ; if ((a->compareTo(n)) >= 0 or (b->compareTo(n)) >= 0 or (c->compareTo(n)) >= 0 or ans <= 0) then ( execute (-1)->display() ; return ) else skip ; if n - ans <= 0 then ( execute (-1)->display() ) else ( execute (n - ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- user=input().split(' ') k=int(user[0]) a=int(user[1]) b=int(user[2]) v=int(user[3]) initial=a divs=b boxes=0 while initial>0 : if b>=k : while divs>0 : divs-=k-1 if k>divs>0 : initial-=(divs+1)*v else : initial-=k*v if initial<=0 : break boxes+=1 initial-=v boxes+=1 else : first=initial first-=v*(b+1) boxes+=1 while first>0 : first-=v boxes+=1 break print(boxes) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var user : OclAny := input().split(' ') ; var k : int := ("" + ((user->first())))->toInteger() ; var a : int := ("" + ((user[1+1])))->toInteger() ; var b : int := ("" + ((user[2+1])))->toInteger() ; var v : int := ("" + ((user[3+1])))->toInteger() ; var initial : int := a ; var divs : int := b ; var boxes : int := 0 ; while initial > 0 do ( if (b->compareTo(k)) >= 0 then ( while divs > 0 do ( divs := divs - k - 1 ; if (k->compareTo(divs)) > 0 & (divs > 0) then ( initial := initial - (divs + 1) * v ) else ( initial := initial - k * v ) ; if initial <= 0 then ( break ) else skip ; boxes := boxes + 1) ; initial := initial - v ; boxes := boxes + 1 ) else ( var first : int := initial ; first := first - v * (b + 1) ; boxes := boxes + 1 ; while first > 0 do ( first := first - v ; boxes := boxes + 1) ; break )) ; execute (boxes)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k,a,b,v=map(int,input().split()) for i in range(1,1001): n=min(k*i,b+i) if v*n>=a : print(i) exit() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : OclAny := null; var a : OclAny := null; var b : OclAny := null; var v : OclAny := null; Sequence{k,a,b,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(1, 1001-1) do ( var n : OclAny := Set{k * i, b + i}->min() ; if (v * n->compareTo(a)) >= 0 then ( execute (i)->display() ; exit() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline k,a,b,v=map(int,input().split()) x=b//(k-1) y=b %(k-1) c=a//(v*k) d=a-(v*k)*min(c,x) e=(y+1)*v ans=min(c,x)if d<=0 else min(c,x)+1 if 0collect( _x | (OclType["int"])->apply(_x) ) ; var x : int := b div (k - 1) ; var y : int := b mod (k - 1) ; var c : int := a div (v * k) ; var d : double := a - (v * k) * Set{c, x}->min() ; var e : double := (y + 1) * v ; var ans : OclAny := if d <= 0 then Set{c, x}->min() else if 0 < d & (d <= e) then Set{c, x}->min() + 1 else Set{c, x}->min() + 1 + ((d - e) - 1 + v) div v endif endif ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=input().split() n=int(n); k=int(k) a=input() l=a.split() team=[]; pos_team=[] for i in range(len(l)): if l[i]not in team : team.append(l[i]) pos_team.append(i+1) if len(team)>=k : print("YES") for i in range(k): print(pos_team[i],end=" ") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split() ; var n : int := ("" + ((n)))->toInteger(); var k : int := ("" + ((k)))->toInteger() ; var a : String := (OclFile["System.in"]).readLine() ; var l : OclAny := a.split() ; var team : Sequence := Sequence{}; var pos_team : Sequence := Sequence{} ; for i : Integer.subrange(0, (l)->size()-1) do ( if (team)->excludes(l[i+1]) then ( execute ((l[i+1]) : team) ; execute ((i + 1) : pos_team) ) else skip) ; if ((team)->size()->compareTo(k)) >= 0 then ( execute ("YES")->display() ; for i : Integer.subrange(0, k-1) do ( execute (pos_team[i+1])->display()) ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k,a,b,v=map(int,input().split()); o=0 while(a>0): o+=1 ; a-=v*min(b+1,k); b-=min(b,k-1) print(o) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : OclAny := null; var a : OclAny := null; var b : OclAny := null; var v : OclAny := null; Sequence{k,a,b,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var o : int := 0 ; while (a > 0) do ( o := o + 1; a := a - v * Set{b + 1, k}->min(); b := b - Set{b, k - 1}->min()) ; execute (o)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import heapq import sys import math import itertools import bisect from io import BytesIO,IOBase import os def values(): return tuple(map(int,sys.stdin.readline().split())) def inlst(): return[int(i)for i in sys.stdin.readline().split()] def inp(): return int(sys.stdin.readline()) def inpstr(): return sys.stdin.readline().strip() def words(): return[i for i in sys.stdin.readline().split()] def chars(): return list(sys.stdin.readline().strip()) def solve(): k,nut,b,v=values() req=math.ceil(nut/v) now=0 tot=0 while b>0 and now=req : print(tot) else : print(tot+req-now) if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation values() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inlst() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inpstr() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation words() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(i | true)->collect(i | (i)); operation chars() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim()); operation solve() pre: true post: true activity: var k : OclAny := null; var nut : OclAny := null; var b : OclAny := null; var v : OclAny := null; Sequence{k,nut,b,v} := values() ; var req : double := (nut / v)->ceil() ; var now : int := 0 ; var tot : int := 0 ; while b > 0 & (now->compareTo(req)) < 0 do ( var m : OclAny := Set{k, b + 1}->min() ; now := now + m ; b := b - m - 1 ; tot := tot + 1) ; if (now->compareTo(req)) >= 0 then ( execute (tot)->display() ) else ( execute (tot + req - now)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c,u,v,a,l=map(int,input().split()) t=1 c-=u while c>0 : t+=1 u=min(v,u+a) c-=u-l print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : OclAny := null; var u : OclAny := null; var v : OclAny := null; var a : OclAny := null; var l : OclAny := null; Sequence{c,u,v,a,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : int := 1 ; c := c - u ; while c > 0 do ( t := t + 1 ; var u : OclAny := Set{v, u + a}->min() ; c := c - u - l) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c,vo,v1,a,l=map(int,input().split()) t=0 x=vo while c>0 : if x>v1 : x=v1 if t==0 : c-=x t+=1 x+=a else : c-=x-l t+=1 x+=a print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : OclAny := null; var vo : OclAny := null; var v1 : OclAny := null; var a : OclAny := null; var l : OclAny := null; Sequence{c,vo,v1,a,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : int := 0 ; var x : OclAny := vo ; while c > 0 do ( if (x->compareTo(v1)) > 0 then ( x := v1 ) else skip ; if t = 0 then ( c := c - x ; t := t + 1 ; x := x + a ) else ( c := c - x - l ; t := t + 1 ; x := x + a )) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(n): a=set() i=2 while i*i<=n : while n % i==0 : a.add(i) n//=i i+=1 if n>1 : a.add(n) return a while 1 : a,b=map(int,input().split()) if(a | b)==0 : break a,b=f(a),f(b) print("a" if 2*max(a)-sum(a)>2*max(b)-sum(b)else "b") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while 1 do ( var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (MathLib.bitwiseOr(a, b)) = 0 then ( break ) else skip ; var b : OclAny := null; Sequence{a,b} := Sequence{f(a),f(b)} ; execute (if (2 * (a)->max() - (a)->sum()->compareTo(2 * (b)->max() - (b)->sum())) > 0 then "a" else "b" endif)->display()); operation f(n : OclAny) : OclAny pre: true post: true activity: var a : Set := Set{}->union(()) ; var i : int := 2 ; while (i * i->compareTo(n)) <= 0 do ( while n mod i = 0 do ( execute ((i) : a) ; n := n div i) ; i := i + 1) ; if n > 1 then ( execute ((n) : a) ) else skip ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c,v0,v1,a,l=map(int,input().split()) suma=v0 rj=1 tr=v0+a while sumacollect( _x | (OclType["int"])->apply(_x) ) ; var suma : OclAny := v0 ; var rj : int := 1 ; var tr : OclAny := v0 + a ; while (suma->compareTo(c)) < 0 do ( suma := suma + Set{v1, tr}->min() ; suma := suma - l ; tr := tr + a ; rj := rj + 1) ; execute (rj)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c,v0,v1,a,l=map(int,input().split(" ")) have=0 read=0 count=0 have=read=v0 while(havecollect( _x | (OclType["int"])->apply(_x) ) ; var have : int := 0 ; var read : int := 0 ; var count : int := 0 ; have := v0; read := v0 ; while ((have->compareTo(c)) < 0) do ( read := Set{v1, read + a}->min() ; have := have + read - l ; count := count + 1) ; execute (count + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math (length,initial_speed,maximum_speed,acceleration,rereading)=map(int,input().split(' ')) days=0 total_read_pages=0 while total_read_pages0 : if 1collect( _x | (OclType["int"])->apply(_x) ) ; var days : int := 0 ; var total_read_pages : int := 0 ; while (total_read_pages->compareTo(length)) < 0 do ( days := days + 1 ; if days = 1 then ( total_read_pages := total_read_pages + initial_speed ) else ( if acceleration > 0 then ( if 1 < days & (days <= ((maximum_speed - initial_speed) / acceleration)->ceil()) then ( var current_speed : OclAny := initial_speed + acceleration * (days - 1) ; total_read_pages := total_read_pages + current_speed - rereading ) else ( total_read_pages := total_read_pages + maximum_speed - rereading ) ) else ( total_read_pages := total_read_pages + initial_speed - rereading ) )) ; execute (days)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isDivisibleBy25(st): n=len(st) if(n==1): return False return((int)(st[n-1])==0 and((int)(st[n-2])==0)or((int)(st[n-2])*10+(int)(st[n-1])% 25==0)) st="76955" if(isDivisibleBy25(st)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; st := "76955" ; if (isDivisibleBy25(st)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isDivisibleBy25(st : OclAny) : OclAny pre: true post: true activity: var n : int := (st)->size() ; if (n = 1) then ( return false ) else skip ; return ((OclType["int"])(st[n - 1+1]) = 0 & ((OclType["int"])(st[n - 2+1]) = 0) or ((OclType["int"])(st[n - 2+1]) * 10 + (OclType["int"])(st[n - 1+1]) mod 25 = 0)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printPair(g,l): n=g*l ; for i in range(1,n+1): if(n % i==0): first=i ; second=n//i ; gcd=__gcd(first,second); if(gcd==g and l % first==0 and l % second==0): print(first," ",second); return ; def __gcd(a,b): if(b==0): return a ; else : return __gcd(b,a % b); g=3 ; l=12 ; printPair(g,l); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; g := 3; ; l := 12; ; printPair(g, l);; operation printPair(g : OclAny, l : OclAny) : OclAny pre: true post: true activity: var n : double := g * l; ; for i : Integer.subrange(1, n + 1-1) do ( if (n mod i = 0) then ( var first : OclAny := i; ; var second : int := n div i; ; var gcd : OclAny := __gcd(first, second); ; if (gcd = g & l mod first = 0 & l mod second = 0) then ( execute (first)->display(); ; return; ) else skip ) else skip); operation __gcd(a : OclAny, b : OclAny) pre: true post: true activity: if (b = 0) then ( return a; ) else ( return __gcd(b, a mod b); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def processQueries(Q,m,n): a=[0]*(m+1); pos=[0]*(m+1); for i in range(1,m+1): a[i-1]=i ; pos[i]=i-1 ; ans=[]; for i in range(n): q=Q[i]; p=pos[q]; ans.append(p); for i in range(p,0,-1): a[i],a[i-1]=a[i-1],a[i]; pos[a[i]]=i ; pos[a[0]]=0 ; return ans ; if __name__=="__main__" : Q=[3,1,2,1]; n=len(Q); m=5 ; ans=[]; ans=processQueries(Q,m,n); for i in range(len(ans)): print(ans[i],end=" "); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Q := Sequence{3}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 1 }))); ; n := (Q)->size(); ; m := 5; ; ans := Sequence{}; ; ans := processQueries(Q, m, n); ; for i : Integer.subrange(0, (ans)->size()-1) do ( execute (ans[i+1])->display();) ) else skip; operation processQueries(Q : OclAny, m : OclAny, n : OclAny) pre: true post: true activity: var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (m + 1)); var pos : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (m + 1)); ; for i : Integer.subrange(1, m + 1-1) do ( a[i - 1+1] := i; ; pos[i+1] := i - 1;) ; var ans : Sequence := Sequence{}; ; for i : Integer.subrange(0, n-1) do ( var q : OclAny := Q[i+1]; ; var p : OclAny := pos[q+1]; ; execute ((p) : ans); ; for i : Integer.subrange(0 + 1, p)->reverse() do ( var a[i+1] : OclAny := null; var a[i - 1+1] : OclAny := null; Sequence{a[i+1],a[i - 1+1]} := Sequence{a[i - 1+1],a[i+1]}; ; pos[a[i+1]+1] := i;) ; pos[a->first()+1] := 0;) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minPower(n,x): if(x==1): return n ans=0 while(n>0): ans+=(n % x) n//=x return ans n=5 x=3 print(minPower(n,x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; x := 3 ; execute (minPower(n, x))->display(); operation minPower(n : OclAny, x : OclAny) : OclAny pre: true post: true activity: if (x = 1) then ( return n ) else skip ; var ans : int := 0 ; while (n > 0) do ( ans := ans + (n mod x) ; n := n div x) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=input().split() n=int(n); k=int(k) a=input() l=a.split() team=[]; pos_team=[] for i in range(len(l)): l[i]=int(l[i]) if l[i]not in team : team.append(l[i]) pos_team.append(i+1) if len(team)>=k : print("YES") for i in range(k): print(pos_team[i],end=" ") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split() ; var n : int := ("" + ((n)))->toInteger(); var k : int := ("" + ((k)))->toInteger() ; var a : String := (OclFile["System.in"]).readLine() ; var l : OclAny := a.split() ; var team : Sequence := Sequence{}; var pos_team : Sequence := Sequence{} ; for i : Integer.subrange(0, (l)->size()-1) do ( l[i+1] := ("" + ((l[i+1])))->toInteger() ; if (team)->excludes(l[i+1]) then ( execute ((l[i+1]) : team) ; execute ((i + 1) : pos_team) ) else skip) ; if ((team)->size()->compareTo(k)) >= 0 then ( execute ("YES")->display() ; for i : Integer.subrange(0, k-1) do ( execute (pos_team[i+1])->display()) ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,l=map(int,input().split()) all_taste=0 taste_list=list() for i in range(n): taste=l+(i+1)-1 taste_list.append(taste) all_taste+=taste www=float("inf") for i in range(n): if abs(taste_list[i])collect( _x | (OclType["int"])->apply(_x) ) ; var all_taste : int := 0 ; var taste_list : Sequence := () ; for i : Integer.subrange(0, n-1) do ( var taste : double := l + (i + 1) - 1 ; execute ((taste) : taste_list) ; all_taste := all_taste + taste) ; var www : double := ("" + (("inf")))->toReal() ; for i : Integer.subrange(0, n-1) do ( if ((taste_list[i+1])->abs()->compareTo(www)) < 0 then ( www := (taste_list[i+1])->abs() ; var ind : OclAny := i ) else skip) ; var ans : double := all_taste - taste_list[ind+1] ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,L=[int(x)for x in input().split()] mini=-111 data=[i for i in range(L,L+N)] for i in data : if abs(i)select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var mini : int := -111 ; var data : Sequence := Integer.subrange(L, L + N-1)->select(i | true)->collect(i | (i)) ; for i : data do ( if ((i)->abs()->compareTo((mini)->abs())) < 0 then ( mini := i ) else skip ; if i = 0 then ( break ) else skip) ; execute ((data)->sum() - mini)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def prime(a): prime=[] for p in range(2,a+1): if a % p==0 : prime.append(p) while a % p==0 : a/=p return prime def keynumber(prime): sum=0 for i in range(len(prime)-1): sum+=prime[i] key=prime[-1]-sum return key while 1 : ab=raw_input().split() a=int(ab[0]) b=int(ab[1]) if a==0 and b==0 : break pa=prime(a) pb=prime(b) ka=keynumber(pa) kb=keynumber(pb) if ka>kb : print('a') else : print('b') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while 1 do ( var ab : OclAny := raw_input().split() ; a := ("" + ((ab->first())))->toInteger() ; var b : int := ("" + ((ab[1+1])))->toInteger() ; if a = 0 & b = 0 then ( break ) else skip ; var pa : OclAny := prime(a) ; var pb : OclAny := prime(b) ; var ka : OclAny := keynumber(pa) ; var kb : OclAny := keynumber(pb) ; if (ka->compareTo(kb)) > 0 then ( execute ('a')->display() ) else ( execute ('b')->display() )); operation prime(a : OclAny) : OclAny pre: true post: true activity: var prime : Sequence := Sequence{} ; for p : Integer.subrange(2, a + 1-1) do ( if a mod p = 0 then ( execute ((p) : prime) ; while a mod p = 0 do ( a := a / p) ) else skip) ; return prime; operation keynumber(prime : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, (prime)->size() - 1-1) do ( sum := sum + prime[i+1]) ; var key : double := prime->last() - sum ; return key; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,l=list(map(int,input().split())) if l>0 : print(int((2+n)*(n-1)/2+(l-1)*(n-1))) elif(l*-1)collect( _x | (OclType["int"])->apply(_x) )) ; if l > 0 then ( execute (("" + (((2 + n) * (n - 1) / 2 + (l - 1) * (n - 1))))->toInteger())->display() ) else (if ((l * -1)->compareTo(n)) < 0 then ( execute (("" + (((1 + n) * (n - 0) / 2 + (l - 1) * (n - 0))))->toInteger())->display() ) else ( execute (("" + (((1 + n - 1) * (n - 1) / 2 + (l - 1) * (n - 1))))->toInteger())->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline N,L=map(int,input().split()) s=0 ; m=100000 for i in range(1,N+1): s+=L+i-1 m=m if abs(L+i-1)>=m else abs(L+i-1) print(s-m if s>0 else s+m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var N : OclAny := null; var L : OclAny := null; Sequence{N,L} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : int := 0; var m : int := 100000 ; for i : Integer.subrange(1, N + 1-1) do ( s := s + L + i - 1 ; m := if ((L + i - 1)->abs()->compareTo(m)) >= 0 then m else (L + i - 1)->abs() endif) ; execute (if s > 0 then s - m else s + m endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,l=map(int,input().split()) List1=[] List2=[] for i in range(n): L=l+i L_abs=abs(L) List1.append(L) List2.append(L_abs) if min(List2)in List1 : List1.remove(min(List2)) elif-min(List2)in List1 : List1.remove(-min(List2)) print(sum(List1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; Sequence{n,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var List1 : Sequence := Sequence{} ; var List2 : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var L : OclAny := l + i ; var L_abs : double := (L)->abs() ; execute ((L) : List1) ; execute ((L_abs) : List2)) ; if (List1)->includes((List2)->min()) then ( execute (((List2)->min()) /: List1) ) else (if (List1)->includes(-(List2)->min()) then ( execute ((-(List2)->min()) /: List1) ) else skip) ; execute ((List1)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printAllAPTriplets(arr,n): for i in range(1,n-1): j=i-1 k=i+1 while(j>=0 and kunion(Sequence{6}->union(Sequence{9}->union(Sequence{12}->union(Sequence{17}->union(Sequence{22}->union(Sequence{31}->union(Sequence{32}->union(Sequence{35}->union(Sequence{ 42 }))))))))) ; n := (arr)->size() ; printAllAPTriplets(arr, n); operation printAllAPTriplets(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(1, n - 1-1) do ( var j : double := i - 1 ; var k : OclAny := i + 1 ; while (j >= 0 & (k->compareTo(n)) < 0) do ( if (arr[j+1] + arr[k+1] = 2 * arr[i+1]) then ( execute (arr[j+1])->display() ; k := k + 1 ; j := j - 1 ) else (if ((arr[j+1] + arr[k+1]->compareTo(2 * arr[i+1])) < 0) then ( k := k + 1 ) else ( j := j - 1 ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minSum(arr,n): sm=arr[0] for i in range(1,n): if arr[i]==arr[i-1]: j=i while junion(Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 6 })))) ; n := (arr)->size() ; execute (minSum(arr, n))->display(); operation minSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sm : OclAny := arr->first() ; for i : Integer.subrange(1, n-1) do ( if arr[i+1] = arr[i - 1+1] then ( var j : OclAny := i ; while (j->compareTo(n)) < 0 & (arr[j+1]->compareTo(arr[j - 1+1])) <= 0 do ( arr[j+1] := arr[j+1] + 1 ; j := j + 1) ) else skip ; sm := sm + arr[i+1]) ; return sm; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findTriplets(arr,n,sum): for i in range(0,n-2): for j in range(i+1,n-1): for k in range(j+1,n): if(arr[i]+arr[j]+arr[k]==sum): print(arr[i],"",arr[j],"",arr[k],sep="") arr=[0,-1,2,-3,1] n=len(arr) findTriplets(arr,n,-2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{0}->union(Sequence{-1}->union(Sequence{2}->union(Sequence{-3}->union(Sequence{ 1 })))) ; n := (arr)->size() ; findTriplets(arr, n, -2); operation findTriplets(arr : OclAny, n : OclAny, sum : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n - 2-1) do ( for j : Integer.subrange(i + 1, n - 1-1) do ( for k : Integer.subrange(j + 1, n-1) do ( if (arr[i+1] + arr[j+1] + arr[k+1] = sum) then ( execute (arr[i+1])->display() ) else skip))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tc=int(input()) for _ in range(tc): W,H=map(int,input().split()) x1,y1,x2,y2=(map(int,input().split())) w,h=(map(int,input().split())) if x2-x1+w<=W or y2-y1+h<=H : ans=[] if x2-x1+w<=W : var=0 var1=0 if x1<=w : var=w-x1 if W-x2<=w : var1=w-(W-x2) ans.append(float(min(var,var1))) if y2-y1+h<=H : var=0 var1=0 if y1<=h : var=h-y1 if H-y2<=h : var1=h-(H-y2) ans.append(float(min(var,var1))) print(min(ans)) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var tc : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, tc-1) do ( var W : OclAny := null; var H : OclAny := null; Sequence{W,H} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (x2 - x1 + w->compareTo(W)) <= 0 or (y2 - y1 + h->compareTo(H)) <= 0 then ( var ans : Sequence := Sequence{} ; if (x2 - x1 + w->compareTo(W)) <= 0 then ( var var : int := 0 ; var var1 : int := 0 ; if (x1->compareTo(w)) <= 0 then ( var := w - x1 ) else skip ; if (W - x2->compareTo(w)) <= 0 then ( var1 := w - (W - x2) ) else skip ; execute ((("" + ((Set{var, var1}->min())))->toReal()) : ans) ) else skip ; if (y2 - y1 + h->compareTo(H)) <= 0 then ( var := 0 ; var1 := 0 ; if (y1->compareTo(h)) <= 0 then ( var := h - y1 ) else skip ; if (H - y2->compareTo(h)) <= 0 then ( var1 := h - (H - y2) ) else skip ; execute ((("" + ((Set{var, var1}->min())))->toReal()) : ans) ) else skip ; execute ((ans)->min())->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minimal_move(room,tb1,tb2): W=room[0] H=room[1] w=tb2[0] h=tb2[1] x1=tb1[0] y1=tb1[1] x2=tb1[2] y2=tb1[3] ww=x2-x1 hh=y2-y1 ans=10**9 if ww+w>W and hh+h>H : return-1 if ww+w<=W : ans=min(w-x1,x2-(W-w)) if hh+h<=H : ans=min(y2-(H-h),h-y1,ans) if ans<0 : ans=0 return ans num=int(input().strip()) for i in range(num): room=list(map(int,input().strip().split())) tb1=list(map(int,input().strip().split())) tb2=list(map(int,input().strip().split())) print(minimal_move(room,tb1,tb2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var num : int := ("" + ((input()->trim())))->toInteger() ; for i : Integer.subrange(0, num-1) do ( room := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; tb1 := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; tb2 := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (minimal_move(room, tb1, tb2))->display()); operation minimal_move(room : OclAny, tb1 : OclAny, tb2 : OclAny) : OclAny pre: true post: true activity: var W : OclAny := room->first() ; var H : OclAny := room[1+1] ; var w : OclAny := tb2->first() ; var h : OclAny := tb2[1+1] ; var x1 : OclAny := tb1->first() ; var y1 : OclAny := tb1[1+1] ; var x2 : OclAny := tb1[2+1] ; var y2 : OclAny := tb1[3+1] ; var ww : double := x2 - x1 ; var hh : double := y2 - y1 ; var ans : double := (10)->pow(9) ; if (ww + w->compareTo(W)) > 0 & (hh + h->compareTo(H)) > 0 then ( return -1 ) else skip ; if (ww + w->compareTo(W)) <= 0 then ( ans := Set{w - x1, x2 - (W - w)}->min() ) else skip ; if (hh + h->compareTo(H)) <= 0 then ( ans := Set{y2 - (H - h), h - y1, ans}->min() ) else skip ; if ans < 0 then ( ans := 0 ) else skip ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=input().split() n=int(n); k=int(k) a=input() l=a.split() team=[]; pos_team=[] for i in range(len(l)): l[i]=int(l[i]) if l[i]not in team : team.append(l[i]) pos_team.append(i+1) if len(team)>=k : print("YES") for i in range(k): print(pos_team[i],end=" ") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split() ; var n : int := ("" + ((n)))->toInteger(); var k : int := ("" + ((k)))->toInteger() ; var a : String := (OclFile["System.in"]).readLine() ; var l : OclAny := a.split() ; var team : Sequence := Sequence{}; var pos_team : Sequence := Sequence{} ; for i : Integer.subrange(0, (l)->size()-1) do ( l[i+1] := ("" + ((l[i+1])))->toInteger() ; if (team)->excludes(l[i+1]) then ( execute ((l[i+1]) : team) ; execute ((i + 1) : pos_team) ) else skip) ; if ((team)->size()->compareTo(k)) >= 0 then ( execute ("YES")->display() ; for i : Integer.subrange(0, k-1) do ( execute (pos_team[i+1])->display()) ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tests=int(input()) for i in range(tests): space=list(map(int,input().split())) table1=list(map(int,input().split())) table2=list(map(int,input().split())) tb1szx=table1[2]-table1[0] tb1szy=table1[3]-table1[1] lowest=float('inf') if(tb1szx+table2[0]<=space[0]): lowest=min(max(0,table2[0]-table1[0]),max(0,table1[2]-(space[0]-table2[0]))) if(tb1szy+table2[1]<=space[1]): lowest=min(lowest,max(0,table2[1]-table1[1]),max(0,table1[3]-(space[1]-table2[1]))) print(lowest if lowesttoInteger() ; for i : Integer.subrange(0, tests-1) do ( var space : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var table1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var table2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var tb1szx : double := table1[2+1] - table1->first() ; var tb1szy : double := table1[3+1] - table1[1+1] ; var lowest : double := ("" + (('inf')))->toReal() ; if ((tb1szx + table2->first()->compareTo(space->first())) <= 0) then ( lowest := Set{Set{0, table2->first() - table1->first()}->max(), Set{0, table1[2+1] - (space->first() - table2->first())}->max()}->min() ) else skip ; if ((tb1szy + table2[1+1]->compareTo(space[1+1])) <= 0) then ( lowest := Set{lowest, Set{0, table2[1+1] - table1[1+1]}->max(), Set{0, table1[3+1] - (space[1+1] - table2[1+1])}->max()}->min() ) else skip ; execute (if (lowest->compareTo(("" + (('inf')))->toReal())) < 0 then lowest else -1 endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def Soinsu(a,b): global soin while True : if a % b==0 : soin.append(b) if a/b==1 : break else : Soinsu(a/b,b) break else : b+=1 if math.sqrt(a)y_door : print("a") else : print("b") ------------------------------------------------------------ OCL File: --------- class FromPython { attribute soin : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; while true do ( var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x = 0 & y = 0 then ( break ) else skip ; soin := Sequence{} ; var x_door : OclAny := calc(Soinsu(x, 2)) ; soin := Sequence{} ; var y_door : OclAny := calc(Soinsu(y, 2)) ; if (x_door->compareTo(y_door)) > 0 then ( execute ("a")->display() ) else ( execute ("b")->display() )); operation Soinsu(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: skip ; while true do ( if a mod b = 0 then ( execute ((b) : soin) ; if a / b = 1 then ( break ) else ( Soinsu(a / b, b) ; break ) ) else ( b := b + 1 ; if ((a)->sqrt()->compareTo(b)) < 0 then ( execute ((("" + ((a)))->toInteger()) : soin) ; break ) else skip )) ; return soin; operation calc(x : OclAny) : OclAny pre: true post: true activity: x := (Set{}->union((x))) ; x := x->sort() ; if (x)->size() = 1 then ( return x->first() ) else ( return x->first() - (x->tail())->sum() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import heapq import collections def main(): num_cases=int(input()) for i in range(num_cases): W,H=(map(int,input().split())) x1,y1,x2,y2=(map(int,input().split())) w,h=(map(int,input().split())) answer=float("inf") if(x2-x1)+w<=W : d_left,d_right=x1,W-x2 aux1=max(0,min(w-d_left,w-d_right)) answer=min(answer,aux1) if(y2-y1)+h<=H : d_bot,d_top=y1,H-y2 aux2=max(0,min(h-d_bot,h-d_top)) answer=min(answer,aux2) if answer==float("inf"): answer=-1 print(answer) else : print("{0:.8f}".format(answer)) return if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var num_cases : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, num_cases-1) do ( var W : OclAny := null; var H : OclAny := null; Sequence{W,H} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var answer : double := ("" + (("inf")))->toReal() ; if ((x2 - x1) + w->compareTo(W)) <= 0 then ( var d_left : OclAny := null; var d_right : OclAny := null; Sequence{d_left,d_right} := Sequence{x1,W - x2} ; var aux1 : OclAny := Set{0, Set{w - d_left, w - d_right}->min()}->max() ; answer := Set{answer, aux1}->min() ) else skip ; if ((y2 - y1) + h->compareTo(H)) <= 0 then ( var d_bot : OclAny := null; var d_top : OclAny := null; Sequence{d_bot,d_top} := Sequence{y1,H - y2} ; var aux2 : OclAny := Set{0, Set{h - d_bot, h - d_top}->min()}->max() ; answer := Set{answer, aux2}->min() ) else skip ; if answer = ("" + (("inf")))->toReal() then ( answer := -1 ; execute (answer)->display() ) else ( execute (StringLib.interpolateStrings("{0:.8f}", Sequence{answer}))->display() )) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(): dp=[[0]*(W+1)for _ in range(H+1)] for i in range(H): for j in range(W): if not int(carpet_info[i][j]): dp[i+1][j+1]=min(dp[i][j],dp[i][j+1],dp[i+1][j])+1 max_width=max(map(max,dp)) return pow(max_width,2) if __name__=='__main__' : _input=sys.stdin.readlines() H,W=map(int,_input[0].split()) carpet_info=list(map(lambda x : x.split(),_input[1 :])) print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var _input : OclAny := (OclFile["System.in"]).readlines() ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (_input->first().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var carpet_info : Sequence := ((_input->tail())->collect( _x | (lambda x : OclAny in (x.split()))->apply(_x) )) ; execute (solve())->display() ) else skip; operation solve() : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, H + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (W + 1)))) ; for i : Integer.subrange(0, H-1) do ( for j : Integer.subrange(0, W-1) do ( if not(("" + ((carpet_info[i+1][j+1])))->toInteger()) then ( dp[i + 1+1][j + 1+1] := Set{dp[i+1][j+1], dp[i+1][j + 1+1], dp[i + 1+1][j+1]}->min() + 1 ) else skip)) ; var max_width : OclAny := ((dp)->collect( _x | (max)->apply(_x) ))->max() ; return (max_width)->pow(2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W=[int(_)for _ in input().split()] HW=[[0]*W for _ in range(H)] for i in range(H): c=0 for j in[int(_)for _ in input().split()]: if j==1 : HW[i][c]=1 c+=1 dp=[[0]*W for _ in range(H)] for j in range(W): if HW[0][j]==0 : dp[0][j]=1 else : dp[0][j]=0 for i in range(H): if HW[i][0]==0 : dp[i][0]=1 else : dp[i][0]=0 for i in range(1,H): for j in range(1,W): if HW[i][j]==1 : dp[i][j]=0 else : dp[i][j]=min(dp[i-1][j],dp[i-1][j-1],dp[i][j-1])+1 ans=0 for i in range(H): for j in range(W): ans=max(ans,dp[i][j]) print(ans*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var HW : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, W))) ; for i : Integer.subrange(0, H-1) do ( var c : int := 0 ; for j : input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) do ( if j = 1 then ( HW[i+1][c+1] := 1 ) else skip ; c := c + 1)) ; var dp : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, W))) ; for j : Integer.subrange(0, W-1) do ( if HW->first()[j+1] = 0 then ( dp->first()[j+1] := 1 ) else ( dp->first()[j+1] := 0 )) ; for i : Integer.subrange(0, H-1) do ( if HW[i+1]->first() = 0 then ( dp[i+1]->first() := 1 ) else ( dp[i+1]->first() := 0 )) ; for i : Integer.subrange(1, H-1) do ( for j : Integer.subrange(1, W-1) do ( if HW[i+1][j+1] = 1 then ( dp[i+1][j+1] := 0 ) else ( dp[i+1][j+1] := Set{dp[i - 1+1][j+1], dp[i - 1+1][j - 1+1], dp[i+1][j - 1+1]}->min() + 1 ))) ; var ans : int := 0 ; for i : Integer.subrange(0, H-1) do ( for j : Integer.subrange(0, W-1) do ( ans := Set{ans, dp[i+1][j+1]}->max())) ; execute (ans * ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import product H,W=tuple(map(int,input().split())) C=[tuple(map(int,input().split()))for _ in range(H)] S=[[1]*W for _ in range(H)] for h,w in product(range(H),range(W)): if C[h][w]==1 : S[h][w]=0 for h,w in product(range(1,H),range(1,W)): if S[h][w]: S[h][w]=min(S[h-1][w-1],S[h-1][w],S[h][w-1])+1 result=0 for sh in S : result=max(max(sh),result) print(result**2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var C : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var S : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 1 }, W))) ; for _tuple : product(Integer.subrange(0, H-1), Integer.subrange(0, W-1)) do (var _indx : int := 1; var h : OclAny := _tuple->at(_indx); _indx := _indx + 1; var w : OclAny := _tuple->at(_indx); if C[h+1][w+1] = 1 then ( S[h+1][w+1] := 0 ) else skip) ; for _tuple : product(Integer.subrange(1, H-1), Integer.subrange(1, W-1)) do (var _indx : int := 1; var h : OclAny := _tuple->at(_indx); _indx := _indx + 1; var w : OclAny := _tuple->at(_indx); if S[h+1][w+1] then ( S[h+1][w+1] := Set{S[h - 1+1][w - 1+1], S[h - 1+1][w+1], S[h+1][w - 1+1]}->min() + 1 ) else skip) ; var result : int := 0 ; for sh : S do ( result := Set{(sh)->max(), result}->max()) ; execute ((result)->pow(2))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import collections import bisect import itertools import fractions import copy import decimal import queue sys.setrecursionlimit(10000001) INF=10**16 MOD=10**9+7 ni=lambda : int(sys.stdin.readline()) ns=lambda : map(int,sys.stdin.readline().split()) na=lambda : list(map(int,sys.stdin.readline().split())) eps=10**(-9) def main(): h,w=ns() mat=[na()for _ in range(h)] dp=[[0 for _ in range(w)]for __ in range(h)] ans=0 for i in range(h): for j in range(w): if mat[i][j]: continue if mat[i][j]==0 : dp[i][j]=1 if i>0 and j>0 : dp[i][j]=min(dp[i-1][j-1],dp[i-1][j],dp[i][j-1])+1 ans=max(ans,dp[i][j]) print(ans**2) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(10000001) ; var INF : double := (10)->pow(16) ; var MOD : double := (10)->pow(9) + 7 ; var ni : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var ns : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var na : Function := lambda $$ : OclAny in (((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var eps : double := (10)->pow((-9)) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := ns->apply() ; var mat : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (na->apply())) ; var dp : Sequence := Integer.subrange(0, h-1)->select(__ | true)->collect(__ | (Integer.subrange(0, w-1)->select(_anon | true)->collect(_anon | (0)))) ; var ans : int := 0 ; for i : Integer.subrange(0, h-1) do ( for j : Integer.subrange(0, w-1) do ( if mat[i+1][j+1] then ( continue ) else skip ; if mat[i+1][j+1] = 0 then ( dp[i+1][j+1] := 1 ) else skip ; if i > 0 & j > 0 then ( dp[i+1][j+1] := Set{dp[i - 1+1][j - 1+1], dp[i - 1+1][j+1], dp[i+1][j - 1+1]}->min() + 1 ) else skip ; ans := Set{ans, dp[i+1][j+1]}->max())) ; execute ((ans)->pow(2))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin readline=stdin.readline h,w=map(int,readline().split()) dp=[list(map(int,readline().split()))for _ in range(h)] for i in range(h): for j in range(w): dp[i][j]^=1 for i in range(1,h): for j in range(1,w): if dp[i][j]: dp[i][j]=1+min(dp[i-1][j-1],dp[i-1][j],dp[i][j-1]) print(max(y for x in dp for y in x)**2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := stdin.readline ; var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dp : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (((readline().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for i : Integer.subrange(0, h-1) do ( for j : Integer.subrange(0, w-1) do ( dp[i+1][j+1] := dp[i+1][j+1] xor 1)) ; for i : Integer.subrange(1, h-1) do ( for j : Integer.subrange(1, w-1) do ( if dp[i+1][j+1] then ( dp[i+1][j+1] := 1 + Set{dp[i - 1+1][j - 1+1], dp[i - 1+1][j+1], dp[i+1][j - 1+1]}->min() ) else skip)) ; execute ((((argument (test (logical_test (comparison (expr (atom (name y)))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name dp))))) (comp_iter (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name x))))))))))->max())->pow(2))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,floor pref=[0]*100010 ; def isPerfectSquare(x): sr=sqrt(x); rslt=x if(sr-floor(sr)==0)else 0 ; return rslt ; def compute(): for i in range(1,100001): pref[i]=pref[i-1]+isPerfectSquare(i); def printSum(L,R): sum=pref[R]-pref[L-1]; print(sum,end=" "); if __name__=="__main__" : compute(); Q=4 ; arr=[[1,10],[1,100],[2,25],[4,50]]; for i in range(Q): printSum(arr[i][0],arr[i][1]); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var pref : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100010); ; skip ; skip ; skip ; if __name__ = "__main__" then ( compute(); ; var Q : int := 4; ; var arr : Sequence := Sequence{Sequence{1}->union(Sequence{ 10 })}->union(Sequence{Sequence{1}->union(Sequence{ 100 })}->union(Sequence{Sequence{2}->union(Sequence{ 25 })}->union(Sequence{ Sequence{4}->union(Sequence{ 50 }) }))); ; for i : Integer.subrange(0, Q-1) do ( printSum(arr[i+1]->first(), arr[i+1][1+1]);) ) else skip; operation isPerfectSquare(x : OclAny) pre: true post: true activity: var sr : OclAny := sqrt(x); ; var rslt : OclAny := if (sr - floor(sr) = 0) then x else 0 endif; ; return rslt;; operation compute() pre: true post: true activity: for i : Integer.subrange(1, 100001-1) do ( pref[i+1] := pref[i - 1+1] + isPerfectSquare(i);); operation printSum(L : OclAny, R : OclAny) pre: true post: true activity: var sum : double := pref[R+1] - pref[L - 1+1]; ; execute (sum)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys inf=1<<30 def solve(): while 1 : n,m,a=map(int,sys.stdin.readline().split()) if n==m==a==0 : return amida=[tuple(map(int,sys.stdin.readline().split()))for i in range(m)] amida.sort() while amida : h,p,q=amida.pop() if p==a : a=q elif q==a : a=p print(a) if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var Math_PINFINITY : int := 1 * (2->pow(30)) ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: while 1 do ( var n : OclAny := null; var m : OclAny := null; var a : OclAny := null; Sequence{n,m,a} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = m & (m == a) & (a == 0) then ( return ) else skip ; var amida : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; amida := amida->sort() ; while amida do ( var h : OclAny := null; var p : OclAny := null; var q : OclAny := null; Sequence{h,p,q} := amida->last() ; amida := amida->front() ; if p = a then ( var a : OclAny := q ) else (if q = a then ( a := p ) else skip)) ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,m,a=map(int,input().split()) if n==0 and m==0 and a==0 : break branch=[[0 for _ in range(1001)]for _ in range(n+1)] for i in range(m): h,p,q=map(int,input().split()) branch[p][h]=q branch[q][h]=p cur=a for i in range(1000,0,-1): if branch[cur][i]: cur=branch[cur][i] print(cur) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var m : OclAny := null; var a : OclAny := null; Sequence{n,m,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 & m = 0 & a = 0 then ( break ) else skip ; var branch : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, 1001-1)->select(_anon | true)->collect(_anon | (0)))) ; for i : Integer.subrange(0, m-1) do ( var h : OclAny := null; var p : OclAny := null; var q : OclAny := null; Sequence{h,p,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; branch[p+1][h+1] := q ; branch[q+1][h+1] := p) ; var cur : OclAny := a ; for i : Integer.subrange(0 + 1, 1000)->reverse() do ( if branch[cur+1][i+1] then ( cur := branch[cur+1][i+1] ) else skip) ; execute (cur)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(x): if x==2 : return 1 if x<2 or x % 2==0 : return 0 i=3 while i<=x**(1/2): if x % i==0 : return 0 i+=2 return 1 while True : n=int(input()) if n==0 : break else : a=0 for i in range(2,n//2+1): m=n-i if f(m)==1 and f(i)==1 : a+=1 print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else ( var a : int := 0 ; for i : Integer.subrange(2, n div 2 + 1-1) do ( var m : double := n - i ; if f(m) = 1 & f(i) = 1 then ( a := a + 1 ) else skip) ; execute (a)->display() )); operation f(x : OclAny) : OclAny pre: true post: true activity: if x = 2 then ( return 1 ) else skip ; if x < 2 or x mod 2 = 0 then ( return 0 ) else skip ; var i : int := 3 ; while (i->compareTo((x)->pow((1 / 2)))) <= 0 do ( if x mod i = 0 then ( return 0 ) else skip ; i := i + 2) ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nCr(n,r): fac=list() fac.append(1) for i in range(1,n+1): fac.append(fac[i-1]*i) ans=fac[n]/(fac[n-r]*fac[r]) return ans n=3 k=3 ans=nCr(n+k-1,k)+nCr(k-1,n-1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3 ; var k : int := 3 ; ans := nCr(n + k - 1, k) + nCr(k - 1, n - 1) ; execute (ans)->display(); operation nCr(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: var fac : Sequence := () ; execute ((1) : fac) ; for i : Integer.subrange(1, n + 1-1) do ( execute ((fac[i - 1+1] * i) : fac)) ; var ans : double := fac[n+1] / (fac[n - r+1] * fac[r+1]) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- currentPlace=[] array=[] height=0 start=0 abs_len=0 def get_input(): array=[] N=[] while True : try : str1,str2,str3=input().split() int1,int2,int3=int(str1),int(str2),int(str3) if int1==0 and int2==0 and int3==0 : break yield[int1,int2,int3] except EOFError : break if __name__=='__main__' : array_total=list(get_input()) while True : height=array_total[start][1] who=array_total[start][2] array=array_total[start : start+height+1] currentPlace=[height,who] del array[0] array.sort(key=lambda x : x[0],reverse=True) for i in range(len(array)): currentPlace[0]=int(array[i][0]) if(int(array[i][0])==currentPlace[0]and(int(array[i][1])==currentPlace[1]or int(array[i][2])==currentPlace[1])): if int(array[i][1])==currentPlace[1]: currentPlace[1]=int(array[i][2]) else : currentPlace[1]=int(array[i][1]) print(currentPlace[1]) start=start+height+1 abs_len=abs_len+height+1 del array[:] if abs_len+1>len(array_total): break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var currentPlace : Sequence := Sequence{} ; var array : Sequence := Sequence{} ; var height : int := 0 ; var start : int := 0 ; var abs_len : int := 0 ; skip ; if __name__ = '__main__' then ( var array_total : Sequence := (OclIterator.newOclIterator_Function(lambda _i : int in self.get_input(_i))) ; while true do ( height := array_total[start+1][1+1] ; var who : OclAny := array_total[start+1][2+1] ; array := array_total.subrange(start+1, start + height + 1) ; currentPlace := Sequence{height}->union(Sequence{ who }) ; execute (array->first())->isDeleted() ; array := array->sort() ; for i : Integer.subrange(0, (array)->size()-1) do ( currentPlace->first() := ("" + ((array[i+1]->first())))->toInteger() ; if (("" + ((array[i+1]->first())))->toInteger() = currentPlace->first() & (("" + ((array[i+1][1+1])))->toInteger() = currentPlace[1+1] or ("" + ((array[i+1][2+1])))->toInteger() = currentPlace[1+1])) then ( if ("" + ((array[i+1][1+1])))->toInteger() = currentPlace[1+1] then ( currentPlace[1+1] := ("" + ((array[i+1][2+1])))->toInteger() ) else ( currentPlace[1+1] := ("" + ((array[i+1][1+1])))->toInteger() ) ) else skip) ; execute (currentPlace[1+1])->display() ; start := start + height + 1 ; abs_len := abs_len + height + 1 ; execute (array)->isDeleted() ; if (abs_len + 1->compareTo((array_total)->size())) > 0 then ( break ) else skip) ) else skip; operation get_input(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; array := Sequence{} ; var N : Sequence := Sequence{} ; while true do ( try ( var str1 : OclAny := null; var str2 : OclAny := null; var str3 : OclAny := null; Sequence{str1,str2,str3} := input().split() ; var int1 : OclAny := null; var int2 : OclAny := null; var int3 : OclAny := null; Sequence{int1,int2,int3} := Sequence{("" + ((str1)))->toInteger(),("" + ((str2)))->toInteger(),("" + ((str3)))->toInteger()} ; if int1 = 0 & int2 = 0 & int3 = 0 then ( break ) else skip ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return Sequence{int1}->union(Sequence{int2}->union(Sequence{ int3 }))) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from heapq import heappush,heappop import sys import math import bisect import random def LI(): return[int(x)for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return[list(x)for x in sys.stdin.readline().split()] def S(): return list(sys.stdin.readline())[:-1] def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] sys.setrecursionlimit(1000000) mod=1000000007 def solve(n,m,a): if m==0 : print(a) return l=LIR(m) l.sort(key=lambda x :-x[0]) x=l[0][0] for h,p,q in l : if xselect(x | true)->collect(x | (("" + ((x)))->toInteger())); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | ((x))); operation S() : OclAny pre: true post: true activity: return OclType["Sequence"]((OclFile["System.in"]).readLine())->front(); operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation solve(n : OclAny, m : OclAny, a : OclAny) pre: true post: true activity: if m = 0 then ( execute (a)->display() ; return ) else skip ; var l : OclAny := LIR(m) ; l := l->sort() ; var x : OclAny := l->first()->first() ; for _tuple : l do (var _indx : int := 1; var h : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p : OclAny := _tuple->at(_indx); _indx := _indx + 1; var q : OclAny := _tuple->at(_indx); if (x->compareTo(h)) < 0 then ( continue ) else skip ; if p = a then ( x := h - 1 ; a := q ) else (if q = a then ( x := h - 1 ; a := p ) else skip)) ; execute (a)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- horizontalLineList=[] while True : n,m,a=list(map(int,input().split())) if n==m==a==0 : break current=a horizontalLineList.clear() for _ in range(m): h,p,q=list(map(int,input().split())) horizontalLineList.append([h,p,q]) horizontalLineList.sort(key=lambda x : x[0]) targetHeight=1000+1 moved=False while horizontalLineList : h,p,q=horizontalLineList.pop() if(targetHeight==h)and moved : continue elif targetHeight!=h : targetHeight=h moved=False if p==current : current=q moved=True elif q==current : current=p moved=True print(current) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var horizontalLineList : Sequence := Sequence{} ; while true do ( var n : OclAny := null; var m : OclAny := null; var a : OclAny := null; Sequence{n,m,a} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = m & (m == a) & (a == 0) then ( break ) else skip ; var current : OclAny := a ; execute (horizontalLineList /<: horizontalLineList) ; for _anon : Integer.subrange(0, m-1) do ( var h : OclAny := null; var p : OclAny := null; var q : OclAny := null; Sequence{h,p,q} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((Sequence{h}->union(Sequence{p}->union(Sequence{ q }))) : horizontalLineList)) ; horizontalLineList := horizontalLineList->sort() ; var targetHeight : int := 1000 + 1 ; var moved : boolean := false ; while horizontalLineList do ( var h : OclAny := null; var p : OclAny := null; var q : OclAny := null; Sequence{h,p,q} := horizontalLineList->last() ; horizontalLineList := horizontalLineList->front() ; if (targetHeight = h) & moved then ( continue ) else (if targetHeight /= h then ( targetHeight := h ; moved := false ) else skip) ; if p = current then ( current := q ; moved := true ) else (if q = current then ( current := p ; moved := true ) else skip)) ; execute (current)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=1000005 def isPrime(n): if n<=1 : return False if n<=3 : return True if n % 2==0 or n % 3==0 : return False i=5 while i*i<=n : if(n % i==0 or n %(i+2)==0): return False i=i+6 return True def SumOfPrimeDivisors(n): sum=0 for i in range(1,n+1): if n % i==0 : if isPrime(i): sum+=i return sum n=60 print("Sum of prime divisors of 60 is "+str(SumOfPrimeDivisors(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 1000005 ; skip ; skip ; n := 60 ; execute ("Sum of prime divisors of 60 is " + ("" + ((SumOfPrimeDivisors(n)))))->display(); operation isPrime(n : OclAny) : OclAny pre: true post: true activity: if n <= 1 then ( return false ) else skip ; if n <= 3 then ( return true ) else skip ; if n mod 2 = 0 or n mod 3 = 0 then ( return false ) else skip ; var i : int := 5 ; while (i * i->compareTo(n)) <= 0 do ( if (n mod i = 0 or n mod (i + 2) = 0) then ( return false ) else skip ; i := i + 6) ; return true; operation SumOfPrimeDivisors(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( if n mod i = 0 then ( if isPrime(i) then ( sum := sum + i ) else skip ) else skip) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INT_BITS=32 def leftRotate(n,d): return(n<>(INT_BITS-d)) def rightRotate(n,d): return(n>>d)|(n<<(INT_BITS-d))& 0xFFFFFFFF n=16 d=2 print("Left Rotation of",n,"by",d,"is",end=" ") print(leftRotate(n,d)) print("Right Rotation of",n,"by",d,"is",end=" ") print(rightRotate(n,d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INT_BITS : int := 32 ; skip ; skip ; n := 16 ; d := 2 ; execute ("Left Rotation of")->display() ; execute (leftRotate(n, d))->display() ; execute ("Right Rotation of")->display() ; execute (rightRotate(n, d))->display(); operation leftRotate(n : OclAny, d : OclAny) : OclAny pre: true post: true activity: return MathLib.bitwiseOr((n * (2->pow(d))), (n /(2->pow((INT_BITS - d))))); operation rightRotate(n : OclAny, d : OclAny) : OclAny pre: true post: true activity: return MathLib.bitwiseOr((n /(2->pow(d))), MathLib.bitwiseAnd((n * (2->pow((INT_BITS - d)))), 0xFFFFFFFF)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() n=n.replace("7","1") n=n.replace("4","0") print(sum(2**i for i in range(1,len(n)))+int(n,2)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; n := n.replace("7", "1") ; n := n.replace("4", "0") ; execute (((argument (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) ** (expr (atom (name i))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))) )))))))))->sum() + ("" + ((n, 2)))->toInteger() + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input(); lenth=len(n); arr=[]; index=0 for i in range(lenth): index+=2**i def lucky(str1="",c=0): if c==lenth : arr.append(str1) return lucky(str1+"4",c+1) lucky(str1+"7",c+1) lucky() print(index+arr.index(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine(); var lenth : int := (n)->size(); var arr : Sequence := Sequence{}; var index : int := 0 ; for i : Integer.subrange(0, lenth-1) do ( index := index + (2)->pow(i)) ; skip ; lucky() ; execute (index + arr->indexOf(n) - 1)->display(); operation lucky(str1 : String, c : int) pre: true post: true activity: if str1->oclIsUndefined() then str1 := "" else skip; if c->oclIsUndefined() then c := 0 else skip; if c = lenth then ( execute ((str1) : arr) ; return ) else skip ; lucky(str1 + "4", c + 1) ; lucky(str1 + "7", c + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input().strip(); lenth=len(n); arr=[]; index=0 for i in range(lenth): index+=2**i def lucky(str1="",c=0): if c==lenth : arr.append(str1) return lucky(str1+"4",c+1) lucky(str1+"7",c+1) lucky() print(index+arr.index(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := input()->trim(); var lenth : int := (n)->size(); var arr : Sequence := Sequence{}; var index : int := 0 ; for i : Integer.subrange(0, lenth-1) do ( index := index + (2)->pow(i)) ; skip ; lucky() ; execute (index + arr->indexOf(n) - 1)->display(); operation lucky(str1 : String, c : int) pre: true post: true activity: if str1->oclIsUndefined() then str1 := "" else skip; if c->oclIsUndefined() then c := 0 else skip; if c = lenth then ( execute ((str1) : arr) ; return ) else skip ; lucky(str1 + "4", c + 1) ; lucky(str1 + "7", c + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import product n=input() ans=sum(2**i for i in range(len(n)-1,0,-1)) for i,item in enumerate(product([4,7],repeat=len(n))): if ''.join(map(str,item))==n : print(ans+i+1) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : String := (OclFile["System.in"]).readLine() ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) ** (expr (atom (name i))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))->sum() ; for _tuple : Integer.subrange(1, (product(Sequence{4}->union(Sequence{ 7 }), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))))->size())->collect( _indx | Sequence{_indx-1, (product(Sequence{4}->union(Sequence{ 7 }), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var item : OclAny := _tuple->at(_indx); if StringLib.sumStringsWithSeparator(((item)->collect( _x | (OclType["String"])->apply(_x) )), '') = n then ( execute (ans + i + 1)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import product n=input() ans=sum(2**i for i in range(1,len(n))) for i,item in enumerate(product(["4","7"],repeat=len(n))): if item==tuple(n): print(ans+i+1) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : String := (OclFile["System.in"]).readLine() ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) ** (expr (atom (name i))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))) )))))))))->sum() ; for _tuple : Integer.subrange(1, (product(Sequence{"4"}->union(Sequence{ "7" }), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))))->size())->collect( _indx | Sequence{_indx-1, (product(Sequence{"4"}->union(Sequence{ "7" }), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var item : OclAny := _tuple->at(_indx); if item = (n) then ( execute (ans + i + 1)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) mx=max(a) hf=0 for x in a : if abs(mx-2*hf)>abs(mx-2*x): hf=x print(mx,hf) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mx : OclAny := (a)->max() ; var hf : int := 0 ; for x : a do ( if ((mx - 2 * hf)->abs()->compareTo((mx - 2 * x)->abs())) > 0 then ( hf := x ) else skip) ; execute (mx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math Q_MAX=2<<15 def primes(n): p=[True]*(n+1) p[0]=p[1]=False for i in range(2,int(math.sqrt(n+1))): if p[i]: for j in range(i*2,n+1,i): p[j]=False return p P=[i for i,x in enumerate(primes(Q_MAX))if x] while True : q=int(input()) if q==0 : break count=0 for p in P : if p>q/2 : break if q-p in P : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var Q_MAX : int := 2 * (2->pow(15)) ; skip ; var P : Sequence := Integer.subrange(1, (primes(Q_MAX))->size())->collect( _indx | Sequence{_indx-1, (primes(Q_MAX))->at(_indx)} )->select(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in x)->collect(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in (i)) ; while true do ( var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if q = 0 then ( break ) else skip ; var count : int := 0 ; for p : P do ( if (p->compareTo(q / 2)) > 0 then ( break ) else skip ; if (P)->includes(q - p) then ( count := count + 1 ) else skip) ; execute (count)->display()); operation primes(n : OclAny) : OclAny pre: true post: true activity: var p : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (n + 1)) ; p->first() := false; var p[1+1] : boolean := false ; for i : Integer.subrange(2, ("" + (((n + 1)->sqrt())))->toInteger()-1) do ( if p[i+1] then ( for j : Integer.subrange(i * 2, n + 1-1)->select( $x | ($x - i * 2) mod i = 0 ) do ( p[j+1] := false) ) else skip) ; return p; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printVector(v,i): for j in range(i,len(v)): print(v[j],end=" ") print() class newNode : def __init__(self,key): self.data=key self.left=None self.right=None def printKPathUtil(root,path,k): if(not root): return path.append(root.data) printKPathUtil(root.left,path,k) printKPathUtil(root.right,path,k) f=0 for j in range(len(path)-1,-1,-1): f+=path[j] if(f==k): printVector(path,j) path.pop(-1) def printKPath(root,k): path=[] printKPathUtil(root,path,k) if __name__=='__main__' : root=newNode(1) root.left=newNode(3) root.left.left=newNode(2) root.left.right=newNode(1) root.left.right.left=newNode(1) root.right=newNode(-1) root.right.left=newNode(4) root.right.left.left=newNode(1) root.right.left.right=newNode(2) root.right.right=newNode(5) root.right.right.right=newNode(2) k=5 printKPath(root,k) ------------------------------------------------------------ OCL File: --------- class newNode { static operation newnewNode() : newNode pre: true post: newNode->exists( _x | result = _x ); attribute data : OclAny := key; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(key : OclAny) : newNode pre: true post: true activity: self.data := key ; self.left := null ; self.right := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( root := (newNode.newnewNode()).initialise(1) ; root.left := (newNode.newnewNode()).initialise(3) ; root.left.left := (newNode.newnewNode()).initialise(2) ; root.left.right := (newNode.newnewNode()).initialise(1) ; root.left.right.left := (newNode.newnewNode()).initialise(1) ; root.right := (newNode.newnewNode()).initialise(-1) ; root.right.left := (newNode.newnewNode()).initialise(4) ; root.right.left.left := (newNode.newnewNode()).initialise(1) ; root.right.left.right := (newNode.newnewNode()).initialise(2) ; root.right.right := (newNode.newnewNode()).initialise(5) ; root.right.right.right := (newNode.newnewNode()).initialise(2) ; k := 5 ; printKPath(root, k) ) else skip; operation printVector(v : OclAny, i : OclAny) pre: true post: true activity: for j : Integer.subrange(i, (v)->size()-1) do ( execute (v[j+1])->display()) ; execute (->display(); operation printKPathUtil(root : OclAny, path : OclAny, k : OclAny) pre: true post: true activity: if (not(root)) then ( return ) else skip ; execute ((root.data) : path) ; printKPathUtil(root.left, path, k) ; printKPathUtil(root.right, path, k) ; var f : int := 0 ; for j : Integer.subrange(-1 + 1, (path)->size() - 1)->reverse() do ( f := f + path[j+1] ; if (f = k) then ( printVector(path, j) ) else skip) ; path := path->excludingAt(-1+1); operation printKPath(root : OclAny, k : OclAny) pre: true post: true activity: path := Sequence{} ; printKPathUtil(root, path, k); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def triangle(n): k=2*n-2 ; ch=1 ; for i in range(n): for j in range(k): print("",end=""); k=k-1 ; for j in range(i+1): print(ch,end=""); ch+=1 ; print() def maxHeight(n): ans=(sqrt(1+8.0*n)-1)//2 ; return int(ans); if __name__=="__main__" : N=9 ; triangle(maxHeight(N)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( var N : int := 9; ; triangle(maxHeight(N)); ) else skip; operation triangle(n : OclAny) pre: true post: true activity: var k : double := 2 * n - 2; ; var ch : int := 1; ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, k-1) do ( execute ("")->display();) ; k := k - 1; ; for j : Integer.subrange(0, i + 1-1) do ( execute (ch)->display(); ; ch := ch + 1;) ; execute (->display()); operation maxHeight(n : OclAny) pre: true post: true activity: var ans : int := (sqrt(1 + 8.0 * n) - 1) div 2; ; return ("" + ((ans)))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math I=input exec(int(I())*'d=math.gcd(n:=len(s:=I()),m:=len(t:=I()));print((r:=m//d*s,-1)[r!=n//d*t]);') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var I : OclAny := input ; (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name I)) (trailer (arguments ( ))))))))) )))) * (expr (atom 'd=math.gcd(n:=len(s:=I()),m:=len(t:=I()));print((r:=m//d*s,-1)[r!=n//d*t]);'))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if a==0 : return b else : return gcd(b % a,a) def lcd(a,b): return(a*b)//gcd(a,b) t=int(input()) for _ in range(t): s1,s2=input(),input() l1,l2=len(s1),len(s2) if l1 % l2==0 and s1==s2*(l1//l2): print(s1) elif l2 % l1==0 and s2==s1*(l2//l1): print(s2) elif s1*(lcd(l1,l2)//l1)==s2*(lcd(l1,l2)//l2): print(s1*(lcd(l1,l2)//l1)) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var s1 : OclAny := null; var s2 : OclAny := null; Sequence{s1,s2} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine()} ; var l1 : OclAny := null; var l2 : OclAny := null; Sequence{l1,l2} := Sequence{(s1)->size(),(s2)->size()} ; if l1 mod l2 = 0 & s1 = s2 * (l1 div l2) then ( execute (s1)->display() ) else (if l2 mod l1 = 0 & s2 = s1 * (l2 div l1) then ( execute (s2)->display() ) else (if s1 * (lcd(l1, l2) div l1) = s2 * (lcd(l1, l2) div l2) then ( execute (s1 * (lcd(l1, l2) div l1))->display() ) else ( execute (-1)->display() ) ) ) ); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a = 0 then ( return b ) else ( return gcd(b mod a, a) ); operation lcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a * b) div gcd(a, b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import random def solve(): t=input() s=input() for i in range(1,50): for j in range(1,50): if(s*i==j*t): print(s*i) return print(-1) t=int(input()) for i in range(t): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; t := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( solve()); operation solve() pre: true post: true activity: var t : String := (OclFile["System.in"]).readLine() ; var s : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(1, 50-1) do ( for j : Integer.subrange(1, 50-1) do ( if (StringLib.nCopies(s, i) = j * t) then ( execute (StringLib.nCopies(s, i))->display() ; return ) else skip)) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) for _ in range(q): s=input() t=input() for i in range(1,len(s)+1): if len(s)% i==0 : if s==s[: i]*(len(s)//i): pat_s,count_s=s[: i],len(s)//i break for i in range(1,len(t)+1): if len(t)% i==0 : if t==t[: i]*(len(t)//i): pat_t,count_t=t[: i],len(t)//i break if pat_s!=pat_t : print(-1) else : a,b=count_s,count_t while b : a,b=b,a % b print(pat_s*(count_s*count_t//a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(1, (s)->size() + 1-1) do ( if (s)->size() mod i = 0 then ( if s = s.subrange(1,i) * ((s)->size() div i) then ( var pat_s : OclAny := null; var count_s : OclAny := null; Sequence{pat_s,count_s} := Sequence{s.subrange(1,i),(s)->size() div i} ; break ) else skip ) else skip) ; for i : Integer.subrange(1, (t)->size() + 1-1) do ( if (t)->size() mod i = 0 then ( if t = t.subrange(1,i) * ((t)->size() div i) then ( var pat_t : OclAny := null; var count_t : OclAny := null; Sequence{pat_t,count_t} := Sequence{t.subrange(1,i),(t)->size() div i} ; break ) else skip ) else skip) ; if pat_s /= pat_t then ( execute (-1)->display() ) else ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{count_s,count_t} ; while b do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a mod b}) ; execute (pat_s * (count_s * count_t div a))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd for _ in range(int(input())): s=input() t=input() lcm=len(s)*len(t)//gcd(len(s),len(t)) print(t*(lcm//len(t))if t*(lcm//len(t))==s*(lcm//len(s))else-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var lcm : int := (s)->size() * (t)->size() div gcd((s)->size(), (t)->size()) ; execute (if StringLib.nCopies(t, (lcm div (t)->size())) = StringLib.nCopies(s, (lcm div (s)->size())) then StringLib.nCopies(t, (lcm div (t)->size())) else -1 endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): n,k=map(int,input().split()) arr=list(map(int,input().split())) if(max(arr)-min(arr))>k : return print("NO") print("YES") mx=max(arr) model=[i for i in range(1,k+1)]*(mx//k+1) for val in arr : print(" ".join(map(str,model[: val]))) def main(): t=1 for _ in range(t): solution() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; main(); operation solution() : OclAny pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (((arr)->max() - (arr)->min())->compareTo(k)) > 0 then ( return ("NO")->display() ) else skip ; execute ("YES")->display() ; var mx : OclAny := (arr)->max() ; var model : Sequence := MatrixLib.elementwiseMult(Integer.subrange(1, k + 1-1)->select(i | true)->collect(i | (i)), (mx div k + 1)) ; for val : arr do ( execute (StringLib.sumStringsWithSeparator(((model.subrange(1,val))->collect( _x | (OclType["String"])->apply(_x) )), " "))->display()); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,k=map(int,input().split()) L=list(map(int,input().split())) m=min(L) M=max(L) if(m+k)<(M): print('NO') else : print("YES") L1=[] for i in range(n): A=[1 for i in range(1,m+1)] for j in range(1,L[i]-m+1): A.append(j) L1.append(A) A=[] for i in range(n): print(*L1[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var L : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : OclAny := (L)->min() ; var M : OclAny := (L)->max() ; if ((m + k)->compareTo((M))) < 0 then ( execute ('NO')->display() ) else ( execute ("YES")->display() ; var L1 : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var A : Sequence := Integer.subrange(1, m + 1-1)->select(i | true)->collect(i | (1)) ; for j : Integer.subrange(1, L[i+1] - m + 1-1) do ( execute ((j) : A)) ; execute ((A) : L1) ; A := Sequence{}) ; for i : Integer.subrange(0, n-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name L1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): k,x=map(int,input().split()) print((k-1)*9+x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var k : OclAny := null; var x : OclAny := null; Sequence{k,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((k - 1) * 9 + x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input().split() (n,k)=(int(i)for i in s) s=input().split() a=[int(i)for i in s] min_a=min(a) max_a=max(a) if(abs(min_a-max_a)>k): print('NO') else : print('YES') for i in range(n): p=[(j % k)+1 for j in range(1,a[i]+1)] for j in range(len(p)): print(p[j],end=' ') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := input().split() ; var Sequence{n, k} : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name s)))))))} ; s := input().split() ; var a : Sequence := s->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var min_a : OclAny := (a)->min() ; var max_a : OclAny := (a)->max() ; if (((min_a - max_a)->abs()->compareTo(k)) > 0) then ( execute ('NO')->display() ) else ( execute ('YES')->display() ; for i : Integer.subrange(0, n-1) do ( var p : Sequence := Integer.subrange(1, a[i+1] + 1-1)->select(j | true)->collect(j | ((j mod k) + 1)) ; for j : Integer.subrange(0, (p)->size()-1) do ( execute (p[j+1])->display()) ; execute (->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import takewhile primes=[0,0]+[1]*(2**15) for i in range(2,182): if primes[i]: for j in range(i*i,2**15+2,i): primes[j]=0 while True : n=int(input()) if n==0 : break prime_values=[i for i in range(len(primes[: n]))if primes[i]] print(sum(n-p1 in prime_values for p1 in takewhile(lambda x : xunion(Sequence{ 0 })->union(MatrixLib.elementwiseMult(Sequence{ 1 }, ((2)->pow(15)))) ; for i : Integer.subrange(2, 182-1) do ( if primes[i+1] then ( for j : Integer.subrange(i * i, (2)->pow(15) + 2-1)->select( $x | ($x - i * i) mod i = 0 ) do ( primes[j+1] := 0) ) else skip) ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var prime_values : Sequence := Integer.subrange(0, (primes.subrange(1,n))->size()-1)->select(i | primes[i+1])->collect(i | (i)) ; execute (((argument (test (logical_test (comparison (comparison (expr (expr (atom (name n))) - (expr (atom (name p1))))) in (comparison (expr (atom (name prime_values))))))) (comp_for for (exprlist (expr (atom (name p1)))) in (logical_test (comparison (expr (atom (name takewhile)) (trailer (arguments ( (arglist (argument (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (comparison (expr (atom (name x)))) < (comparison (expr (expr (expr (atom (name n))) // (expr (atom (number (integer 2))))) + (expr (atom (number (integer 1))))))))))) , (argument (test (logical_test (comparison (expr (atom (name prime_values)))))))) )))))))))->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=list(map(int,input().split())) l=list(map(int,input().split())) maxi=max(l) mini=min(l) rep=max(0,maxi-k) if minicollect( _x | (OclType["int"])->apply(_x) )) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var maxi : OclAny := (l)->max() ; var mini : OclAny := (l)->min() ; var rep : OclAny := Set{0, maxi - k}->max() ; if (mini->compareTo(rep)) < 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; for i : l do ( var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, Set{mini + 1, i}->min()) ; var add : int := 2 ; for j : Integer.subrange(0, i - mini - 1-1) do ( execute ((add) : ans) ; add := add + 1) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sieve(prime,n): p=2 while p*p<=n : if(prime[p]==False): for i in range(p*2,n,p): prime[i]=True p+=1 def maxDigitInPrimes(L,R): prime=[0]*(R+1) sieve(prime,R) freq=[0]*10 for i in range(L,R+1): if(not prime[i]): p=i while(p): freq[p % 10]+=1 p//=10 max=freq[0] ans=0 for j in range(1,10): if(max<=freq[j]): max=freq[j] ans=j return ans if __name__=="__main__" : L=1 R=20 print(maxDigitInPrimes(L,R)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( L := 1 ; R := 20 ; execute (maxDigitInPrimes(L, R))->display() ) else skip; operation sieve(prime : OclAny, n : OclAny) pre: true post: true activity: var p : int := 2 ; while (p * p->compareTo(n)) <= 0 do ( if (prime[p+1] = false) then ( for i : Integer.subrange(p * 2, n-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := true) ) else skip ; p := p + 1); operation maxDigitInPrimes(L : OclAny, R : OclAny) : OclAny pre: true post: true activity: prime := MatrixLib.elementwiseMult(Sequence{ 0 }, (R + 1)) ; sieve(prime, R) ; var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; for i : Integer.subrange(L, R + 1-1) do ( if (not(prime[i+1])) then ( p := i ; while (p) do ( freq[p mod 10+1] := freq[p mod 10+1] + 1 ; p := p div 10) ) else skip) ; var max : OclAny := freq->first() ; var ans : int := 0 ; for j : Integer.subrange(1, 10-1) do ( if ((max->compareTo(freq[j+1])) <= 0) then ( max := freq[j+1] ; ans := j ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(0,t): n=int(input()) lista=[i+1 for i in range(1,n+1)] lista[-1]=1 for n in lista : print(n,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lista : Sequence := Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | (i + 1)) ; lista->last() := 1 ; for n : lista do ( execute (n)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for n in[*open(0)][1 :]: print(n,*range(1,int(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for n : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( execute (n)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) if n==1 : print(1) else : if n % 2 : print(2,3,1,end=" ") for x in range(4,n+1,2): print(x+1,x,end=" ") print() else : for x in range(1,n+1,2): print(x+1,x,end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (1)->display() ) else ( if n mod 2 then ( execute (2)->display() ; for x : Integer.subrange(4, n + 1-1)->select( $x | ($x - 4) mod 2 = 0 ) do ( execute (x + 1)->display()) ; execute (->display() ) else ( for x : Integer.subrange(1, n + 1-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( execute (x + 1)->display()) ; execute (->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) res=[1+(i+1)% n for i in range(n)] print(*res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (1 + (i + 1) mod n)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) print(n,end=' ') for i in range(1,n): print(i,end=' ') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n)->display() ; for i : Integer.subrange(1, n-1) do ( execute (i)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isequal(str): n=len(str) num=0 x=1 i=n-1 for i in range(n-1,-1,-1): if('0'<=str[i]and str[i]<='9'): num=(ord(str[i])-ord('0'))*x+num x=x*10 if(num>=n): return false else : break return num==i+1 if __name__=="__main__" : str="geeksforgeeks13" print("Yes")if isequal(str)else print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( OclType["String"] := "geeksforgeeks13" ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Yes"))))))) )))))) if (logical_test (comparison (expr (atom (name isequal)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)))))))) )))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "No"))))))) )))))))) ) else skip; operation isequal(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var n : int := (OclType["String"])->size() ; var num : int := 0 ; var x : int := 1 ; var i : double := n - 1 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if ('0' <= ("" + ([i+1])) & ("" + ([i+1])) <= '9') then ( num := ((("" + ([i+1])))->char2byte() - ('0')->char2byte()) * x + num ; x := x * 10 ; if ((num->compareTo(n)) >= 0) then ( return false ) else skip ) else ( break )) ; return num = i + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import bisect def solve(n : int,a : "List[int]"): if n==2 : print(*sorted(a,reverse=True)) return a.sort() max_a=a[-1] if max_a % 2==1 : searchValue=max_a//2+1 else : searchValue=max_a//2 index=bisect.bisect_left(a,searchValue) if abs(max_a/2-a[index])>abs(max_a/2-a[index-1]): print(max_a,a[index-1]) else : print(max_a,a[index]) return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() n=int(next(tokens)) a=[int(next(tokens))for _ in range(n)] solve(n,a) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(n : int, a : "List[int]") pre: true post: true activity: if n = 2 then ( execute ((argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) )))))))))->display() ; return ) else skip ; a := a->sort() ; var max_a : OclAny := a->last() ; if max_a mod 2 = 1 then ( var searchValue : int := max_a div 2 + 1 ) else ( searchValue := max_a div 2 ) ; var index : OclAny := bisect.bisect_left(a, searchValue) ; if ((max_a / 2 - a[index+1])->abs()->compareTo((max_a / 2 - a[index - 1+1])->abs())) > 0 then ( execute (max_a)->display() ) else ( execute (max_a)->display() ) ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var n : int := ("" + (((tokens).next())))->toInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((tokens).next())))->toInteger())) ; solve(n, a); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def decToBin(n): if(n==0): return "0" ; bin="" ; while(n>0): if(n & 1==0): bin='0'+bin ; else : bin='1'+bin ; n=n>>1 ; return bin ; n=38 ; print(decToBin(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 38; ; execute (decToBin(n))->display();; operation decToBin(n : OclAny) pre: true post: true activity: if (n = 0) then ( return "0"; ) else skip ; var bin : String := ""; ; while (n > 0) do ( if (MathLib.bitwiseAnd(n, 1) = 0) then ( bin := '0' + bin; ) else ( bin := '1' + bin; ) ; n := n /(2->pow(1));) ; return bin;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def tower(n,sourcePole,destinationPole,auxiliaryPole): if(0==n): return tower(n-1,sourcePole,auxiliaryPole,destinationPole) print("Move the disk",sourcePole,"from",sourcePole,"to",destinationPole) tower(n-1,auxiliaryPole,destinationPole,sourcePole) tower(3,'S','D','A') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; tower(3, 'S', 'D', 'A'); operation tower(n : OclAny, sourcePole : OclAny, destinationPole : OclAny, auxiliaryPole : OclAny) pre: true post: true activity: if (0 = n) then ( return ) else skip ; tower(n - 1, sourcePole, auxiliaryPole, destinationPole) ; execute ("Move the disk")->display() ; tower(n - 1, auxiliaryPole, destinationPole, sourcePole); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as m def prime(n): if n<=1 : return False for i in range(2,int(m.sqrt(n))+1): if n % i==0 : return False return True def Goldbach(n): x=[] c=0 for i in range(n+1): if prime(i): x.append(i) for j in x : for k in x : if j>k : pass elif j+k==n : c+=1 else : pass print(c) while 1 : n=int(input()) if n==0 : break Goldbach(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; while 1 do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; Goldbach(n)); operation prime(n : OclAny) : OclAny pre: true post: true activity: if n <= 1 then ( return false ) else skip ; for i : Integer.subrange(2, ("" + ((m.sqrt(n))))->toInteger() + 1-1) do ( if n mod i = 0 then ( return false ) else skip) ; return true; operation Goldbach(n : OclAny) pre: true post: true activity: var x : Sequence := Sequence{} ; var c : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( if prime(i) then ( execute ((i) : x) ) else skip) ; for j : x do ( for k : x do ( if (j->compareTo(k)) > 0 then ( skip ) else (if j + k = n then ( c := c + 1 ) else ( skip ) ) )) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def maxPeople(p): tmp=0 ; count=0 ; for i in range(1,int(sqrt(p))+1): tmp=tmp+(i*i); if(tmp<=p): count+=1 ; else : break ; return count ; if __name__=="__main__" : p=14 ; print(maxPeople(p)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( p := 14; ; execute (maxPeople(p))->display(); ) else skip; operation maxPeople(p : OclAny) pre: true post: true activity: var tmp : int := 0; var count : int := 0; ; for i : Integer.subrange(1, ("" + ((sqrt(p))))->toInteger() + 1-1) do ( tmp := tmp + (i * i); ; if ((tmp->compareTo(p)) <= 0) then ( count := count + 1; ) else ( break; )) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxLenSub(arr,n): mls=[] max=0 for i in range(n): mls.append(1) for i in range(n): for j in range(i): if(abs(arr[i]-arr[j])<=1 and mls[i]first() } ; for i : Integer.subrange(1, (s)->size()-1) do ( if t & s[i+1] = t->last() then ( t := t->front() ) else ( execute ((s[i+1]) : t) )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name t))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b={} b[0]=a[0] for i in range(1,len(a)): j=len(b) b[j]=a[i] if len(b)>1 : if b[j]==b[j-1]: b.pop(j) b.pop(j-1) rez='' for i,x in enumerate(b): rez+=b[x] print(rez) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : OclAny := Set{} ; b->first() := a->first() ; for i : Integer.subrange(1, (a)->size()-1) do ( var j : int := (b)->size() ; b[j+1] := a[i+1] ; if (b)->size() > 1 then ( if b[j+1] = b[j - 1+1] then ( b := b->excludingAt(j+1) ; b := b->excludingAt(j - 1+1) ) else skip ) else skip) ; var rez : String := '' ; for _tuple : Integer.subrange(1, (b)->size())->collect( _indx | Sequence{_indx-1, (b)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); rez := rez + b[x+1]) ; execute (rez)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() stack=[] for i in n : try : if i!=stack[-1]: stack.append(i) else : stack.pop() except : stack.append(i) print(''.join(stack)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var stack : Sequence := Sequence{} ; for i : n->characters() do ( try ( if i /= stack->last() then ( execute ((i) : stack) ) else ( stack := stack->front() )) catch (_e : OclException) do ( execute ((i) : stack)) ) ; execute (StringLib.sumStringsWithSeparator((stack), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=[] for c in input(): if len(s)<1 : s.append(c) elif c==s[-1]: s.pop() else : s.append(c) print(''.join(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := Sequence{} ; for c : (OclFile["System.in"]).readLine() do ( if (s)->size() < 1 then ( execute ((c) : s) ) else (if c = s->last() then ( s := s->front() ) else ( execute ((c) : s) ) ) ) ; execute (StringLib.sumStringsWithSeparator((s), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def print_max(a,n,k): max_upto=[0 for i in range(n)] s=[] s.append(0) for i in range(1,n): while(len(s)>0 and a[s[-1]]0): max_upto[s[-1]]=n-1 del s[-1] j=0 for i in range(n-k+1): while(junion(Sequence{7}->union(Sequence{2}->union(Sequence{4}->union(Sequence{6}->union(Sequence{8}->union(Sequence{2}->union(Sequence{1}->union(Sequence{ 5 })))))))) ; n := (a)->size() ; k := 3 ; print_max(a, n, k); operation print_max(a : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var max_upto : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var s : Sequence := Sequence{} ; execute ((0) : s) ; for i : Integer.subrange(1, n-1) do ( while ((s)->size() > 0 & (a[s->last()+1]->compareTo(a[i+1])) < 0) do ( max_upto[s->last()+1] := i - 1 ; execute (s->last())->isDeleted()) ; execute ((i) : s)) ; while ((s)->size() > 0) do ( max_upto[s->last()+1] := n - 1 ; execute (s->last())->isDeleted()) ; var j : int := 0 ; for i : Integer.subrange(0, n - k + 1-1) do ( while ((j->compareTo(i)) < 0 or (max_upto[j+1]->compareTo(i + k - 1)) < 0) do ( j := j + 1) ; execute (a[j+1])->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from operator import mul from functools import reduce import bisect def cmb(n,r): r=min(n-r,r) if r==0 : return 1 over=reduce(mul,range(n,n-r,-1)) under=reduce(mul,range(1,r+1)) return over//under N=int(input()) A=sorted(list(map(int,input().split()))) maxA=max(A) A.remove(maxA) idx=bisect.bisect(A,maxA//2) if idx==len(A): print(maxA,A[-1]) elif idx==0 : print(maxA,idx) else : if abs(maxA//2-A[idx])>abs(maxA//2-A[idx-1]): print(maxA,A[idx-1]) else : print(maxA,A[idx]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var maxA : OclAny := (A)->max() ; execute ((maxA) /: A) ; var idx : OclAny := bisect.bisect(A, maxA div 2) ; if idx = (A)->size() then ( execute (maxA)->display() ) else (if idx = 0 then ( execute (maxA)->display() ) else ( if ((maxA div 2 - A[idx+1])->abs()->compareTo((maxA div 2 - A[idx - 1+1])->abs())) > 0 then ( execute (maxA)->display() ) else ( execute (maxA)->display() ) ) ) ; operation cmb(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: r := Set{n - r, r}->min() ; if r = 0 then ( return 1 ) else skip ; var over : OclAny := reduce(mul, Integer.subrange(n - r + 1, n)->reverse()) ; var under : OclAny := reduce(mul, Integer.subrange(1, r + 1-1)) ; return over div under; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s,stk=input(),[] stk.append(s[0]) for i in range(1,len(s)): if stk and s[i]==stk[-1]: stk.pop() else : stk.append(s[i]) print(*stk,sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := null; var stk : OclAny := null; Sequence{s,stk} := Sequence{(OclFile["System.in"]).readLine(),Sequence{}} ; execute ((s->first()) : stk) ; for i : Integer.subrange(1, (s)->size()-1) do ( if stk & s[i+1] = stk->last() then ( stk := stk->front() ) else ( execute ((s[i+1]) : stk) )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name stk))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) while True : op=input().strip() if op=='=' : break b=int(input()) if op=='+' : a+=b elif op=='-' : a-=b elif op=='*' : a*=b else : a//=b print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while true do ( var op : OclAny := input()->trim() ; if op = '=' then ( break ) else skip ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if op = '+' then ( a := a + b ) else (if op = '-' then ( a := a - b ) else (if op = '*' then ( a := a * b ) else ( a := a div b ) ) ) ) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- oper=True po="" result=int(input()) while True : if oper : po=input() if po=="=" : break oper=False else : inp=int(input()) if po=="+" : result+=inp elif po=="-" : result-=inp elif po=="*" : result*=inp elif po=="/" : result//=inp oper=True print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var oper : boolean := true ; var po : String := "" ; var result : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while true do ( if oper then ( po := (OclFile["System.in"]).readLine() ; if po = "=" then ( break ) else skip ; oper := false ) else ( var inp : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if po = "+" then ( result := result + inp ) else (if po = "-" then ( result := result - inp ) else (if po = "*" then ( result := result * inp ) else (if po = "/" then ( result := result div inp ) else skip ) ) ) ; oper := true )) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools def primes(n): is_prime=[True]*(n+1) is_prime[0]=False is_prime[1]=False for i in range(2,int(n**0.5)+1): if not is_prime[i]: continue for j in range(i*2,n+1,i): is_prime[j]=False return[i for i in range(n+1)if is_prime[i]] while True : a=int(input()) if a==0 : break s=primes(a) c=0 for r in itertools.combinations(s,2): if r[0]+r[1]==a : c+=1 if a/2 in s : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if a = 0 then ( break ) else skip ; var s : OclAny := primes(a) ; var c : int := 0 ; for r : itertools.combinations(s, 2) do ( if r->first() + r[1+1] = a then ( c := c + 1 ) else skip) ; if (s)->includes(a / 2) then ( c := c + 1 ) else skip ; execute (c)->display()); operation primes(n : OclAny) : OclAny pre: true post: true activity: var is_prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (n + 1)) ; is_prime->first() := false ; is_prime[1+1] := false ; for i : Integer.subrange(2, ("" + (((n)->pow(0.5))))->toInteger() + 1-1) do ( if not(is_prime[i+1]) then ( continue ) else skip ; for j : Integer.subrange(i * 2, n + 1-1)->select( $x | ($x - i * 2) mod i = 0 ) do ( is_prime[j+1] := false)) ; return Integer.subrange(0, n + 1-1)->select(i | is_prime[i+1])->collect(i | (i)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : opcode=[] operand=[] while True : data=input() if data=='=' : break elif data in '+-*/' : opcode.append(data) else : if len(operand)==0 : operand.append(int(data)) else : op=opcode.pop() operand1=operand.pop() operand2=int(data) if op=='+' : operand.append(operand1+operand2) elif op=='-' : operand.append(operand1-operand2) elif op=='*' : operand.append(operand1*operand2) elif op=='/' : operand.append(operand1//operand2) print('{0}'.format(operand.pop())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var opcode : Sequence := Sequence{} ; var operand : Sequence := Sequence{} ; while true do ( var data : String := (OclFile["System.in"]).readLine() ; if data = '=' then ( break ) else (if ('+-*/')->characters()->includes(data) then ( execute ((data) : opcode) ) else ( if (operand)->size() = 0 then ( execute ((("" + ((data)))->toInteger()) : operand) ) else ( var op : OclAny := opcode->last() ; opcode := opcode->front() ; var operand1 : OclAny := operand->last() ; operand := operand->front() ; var operand2 : int := ("" + ((data)))->toInteger() ; if op = '+' then ( execute ((operand1 + operand2) : operand) ) else (if op = '-' then ( execute ((operand1 - operand2) : operand) ) else (if op = '*' then ( execute ((operand1 * operand2) : operand) ) else (if op = '/' then ( execute ((operand1 div operand2) : operand) ) else skip ) ) ) ) ) ) ) ; execute (StringLib.interpolateStrings('{0}', Sequence{operand->last()}))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) while True : s=input() if s=="-" : n-=int(input()) elif s=="+" : n+=int(input()) elif s=="*" : n*=int(input()) elif s=="/" : n=int(n/int(input())) else : print(n) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while true do ( var s : String := (OclFile["System.in"]).readLine() ; if s = "-" then ( n := n - ("" + (((OclFile["System.in"]).readLine())))->toInteger() ) else (if s = "+" then ( n := n + ("" + (((OclFile["System.in"]).readLine())))->toInteger() ) else (if s = "*" then ( n := n * ("" + (((OclFile["System.in"]).readLine())))->toInteger() ) else (if s = "/" then ( n := ("" + ((n / ("" + (((OclFile["System.in"]).readLine())))->toInteger())))->toInteger() ) else ( execute (n)->display() ; break ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=[] while True : s=input() if s=="=" : break c.append(s) ans=int(c[0]) for i in range(2,len(c),2): o,v=c[i-1],int(c[i]) if o=="+" : ans+=v elif o=="-" : ans-=v elif o=="/" : ans=ans//v else : ans*=v print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : Sequence := Sequence{} ; while true do ( var s : String := (OclFile["System.in"]).readLine() ; if s = "=" then ( break ) else skip ; execute ((s) : c)) ; var ans : int := ("" + ((c->first())))->toInteger() ; for i : Integer.subrange(2, (c)->size()-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( var o : OclAny := null; var v : OclAny := null; Sequence{o,v} := Sequence{c[i - 1+1],("" + ((c[i+1])))->toInteger()} ; if o = "+" then ( ans := ans + v ) else (if o = "-" then ( ans := ans - v ) else (if o = "/" then ( ans := ans div v ) else ( ans := ans * v ) ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def anglequichord(z): print("The angle is ",z," degrees") if __name__=="__main__" : z=48 anglequichord(z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( z := 48 ; anglequichord(z) ) else skip; operation anglequichord(z : OclAny) pre: true post: true activity: execute ("The angle is ")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l,k=map(int,input().split()) dp=[[0,0]for i in range(l+1)] dp[1][0]=1 if k<=l : dp[k][0]=1 for h in range(1,l): dp[h+1][0]+=dp[h][1] dp[h+1][1]+=dp[h][0] if h+k<=l : dp[h+k][1]+=dp[h][0] ans=0 for b,w in dp : ans+=b print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := null; var k : OclAny := null; Sequence{l,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dp : Sequence := Integer.subrange(0, l + 1-1)->select(i | true)->collect(i | (Sequence{0}->union(Sequence{ 0 }))) ; dp[1+1]->first() := 1 ; if (k->compareTo(l)) <= 0 then ( dp[k+1]->first() := 1 ) else skip ; for h : Integer.subrange(1, l-1) do ( dp[h + 1+1]->first() := dp[h + 1+1]->first() + dp[h+1][1+1] ; dp[h + 1+1][1+1] := dp[h + 1+1][1+1] + dp[h+1]->first() ; if (h + k->compareTo(l)) <= 0 then ( dp[h + k+1][1+1] := dp[h + k+1][1+1] + dp[h+1]->first() ) else skip) ; var ans : int := 0 ; for _tuple : dp do (var _indx : int := 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var w : OclAny := _tuple->at(_indx); ans := ans + b) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l,k=map(int,input().split()) memo={(l,0): 1,(l,1): 0} def dfs(cur,dark): if(cur,dark)in memo : return memo[cur,dark] res=dfs(cur+1,dark ^ 1)+(dark ^ 1) if dark and cur+k<=l : res+=dfs(cur+k,dark ^ 1) memo[cur,dark]=res return res print(dfs(0,1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := null; var k : OclAny := null; Sequence{l,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var memo : Map := Map{ Sequence{l, 0} |-> 1 }->union(Map{ Sequence{l, 1} |-> 0 }) ; skip ; execute (dfs(0, 1))->display(); operation dfs(cur : OclAny, dark : OclAny) : OclAny pre: true post: true activity: if (memo)->includes(Sequence{cur, dark}) then ( return memo[cur+1][dark+1] ) else skip ; var res : OclAny := dfs(cur + 1, MathLib.bitwiseXor(dark, 1)) + (MathLib.bitwiseXor(dark, 1)) ; if dark & (cur + k->compareTo(l)) <= 0 then ( res := res + dfs(cur + k, MathLib.bitwiseXor(dark, 1)) ) else skip ; memo[cur+1][dark+1] := res ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline N=int(readline()) A=list(map(int,readline().split())) A=sorted(A,reverse=True) one=A[0] diff=one ans=-1 for i in range(1,len(A)): if abs(one/2-A[i])toInteger() ; var A : Sequence := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ; A := A->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var one : OclAny := A->first() ; var diff : OclAny := one ; var ans : int := -1 ; for i : Integer.subrange(1, (A)->size()-1) do ( if ((one / 2 - A[i+1])->abs()->compareTo(diff)) < 0 then ( diff := (one / 2 - A[i+1])->abs() ; ans := A[i+1] ) else skip) ; execute (one)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l,k=[int(i)for i in input().split()] INIT=0 tableB=[INIT]*110 tableW=[INIT]*110 tableW[0]=1 for i in range(1,l+1): tableB[i]+=tableW[i-1] if i-k>=0 : tableB[i]+=tableW[i-k] tableW[i+1]=tableB[i] print(sum(tableB)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := null; var k : OclAny := null; Sequence{l,k} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var INIT : int := 0 ; var tableB : Sequence := MatrixLib.elementwiseMult(Sequence{ INIT }, 110) ; var tableW : Sequence := MatrixLib.elementwiseMult(Sequence{ INIT }, 110) ; tableW->first() := 1 ; for i : Integer.subrange(1, l + 1-1) do ( tableB[i+1] := tableB[i+1] + tableW[i - 1+1] ; if i - k >= 0 then ( tableB[i+1] := tableB[i+1] + tableW[i - k+1] ) else skip ; tableW[i + 1+1] := tableB[i+1]) ; execute ((tableB)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import lru_cache l,k=map(int,input().split()) @ lru_cache() def rec(i,isBlack): if i<0 : return 0 if i==0 : return 1 if not isBlack else 0 if isBlack : return rec(i-1,False)+rec(i-k,False) else : return rec(i-1,True) ans=sum(rec(i,True)for i in range(1,l+1)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var l : OclAny := null; var k : OclAny := null; Sequence{l,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (compound_stmt (decorator @ (dotted_name (name lru_cache)) ( )) (funcdef def (name rec) ( (typedargslist (def_parameters (def_parameter (named_parameter (name i))) , (def_parameter (named_parameter (name isBlack))))) ) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name i)))) < (comparison (expr (atom (number (integer 0)))))))) : (suite (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name i)))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))) if (logical_test not (logical_test (comparison (expr (atom (name isBlack)))))) else (test (logical_test (comparison (expr (atom (number (integer 0)))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name isBlack)))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (expr (atom (name rec)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name False)))))))) )))) + (expr (atom (name rec)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (name k)))))))) , (argument (test (logical_test (comparison (expr (atom (name False)))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name rec)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name True)))))))) )))))))))))))))))) ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name rec)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (name True)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name l))) + (expr (atom (number (integer 1)))))))))) )))))))))->sum() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import sys def main(): L,K=read_ints() print(solve(L,K)) def solve(L,K): D=[[0,0]for _ in range(L+1)] D[1][0]=1 if K<=L : D[K][0]=1 for i in range(1,L): D[i+1][1]+=D[i][0] D[i+1][0]+=D[i][1] if i+K<=L : D[i+K][0]+=D[i][1] return sum([D[i][0]for i in range(1,L+1)]) DEBUG='DEBUG' in os.environ def inp(): return sys.stdin.readline().rstrip() def read_int(): return int(inp()) def read_ints(): return[int(e)for e in inp().split()] def dprint(*value,sep=' ',end='\n'): if DEBUG : print(*value,sep=sep,end=end) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var DEBUG : boolean := (os.environ)->includes('DEBUG') ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var L : OclAny := null; var K : OclAny := null; Sequence{L,K} := read_ints() ; execute (solve(L, K))->display(); operation solve(L : OclAny, K : OclAny) : OclAny pre: true post: true activity: var D : Sequence := Integer.subrange(0, L + 1-1)->select(_anon | true)->collect(_anon | (Sequence{0}->union(Sequence{ 0 }))) ; D[1+1]->first() := 1 ; if (K->compareTo(L)) <= 0 then ( D[K+1]->first() := 1 ) else skip ; for i : Integer.subrange(1, L-1) do ( D[i + 1+1][1+1] := D[i + 1+1][1+1] + D[i+1]->first() ; D[i + 1+1]->first() := D[i + 1+1]->first() + D[i+1][1+1] ; if (i + K->compareTo(L)) <= 0 then ( D[i + K+1]->first() := D[i + K+1]->first() + D[i+1][1+1] ) else skip) ; return (Integer.subrange(1, L + 1-1)->select(i | true)->collect(i | (D[i+1]->first())))->sum(); operation inp() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation read_int() : OclAny pre: true post: true activity: return ("" + ((inp())))->toInteger(); operation read_ints() : OclAny pre: true post: true activity: return inp().split()->select(e | true)->collect(e | (("" + ((e)))->toInteger())); operation dprint(value : OclAny : Sequence(OclAny), sep : String, end : String) pre: true post: true activity: (args * (named_parameter (name value))) if sep->oclIsUndefined() then sep := ' ' else skip; if end->oclIsUndefined() then end := ' ' else skip; if DEBUG then ( execute ((argument * (test (logical_test (comparison (expr (atom (name value))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() t=[input()for i in range(n)] c=0 for tt in t : f=False for i in range(len(tt)): for j in range(len(tt))[1 :]: f |=s==tt[i : : j][: len(s)] if f : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var t : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var c : int := 0 ; for tt : t do ( var f : boolean := false ; for i : Integer.subrange(0, (tt)->size()-1) do ( for j : range((tt)->size())->tail() do ( f := f or s = tt(subscript (test (logical_test (comparison (expr (atom (name i)))))) : (sliceop : (test (logical_test (comparison (expr (atom (name j)))))))).subrange(1,(s)->size()))) ; if f then ( c := c + 1 ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,y=(int(num)for num in input().split()) ans='-1-1-1' for i in range(n+1): if ans!='-1-1-1' : break for j in range(n+1): n_10=n-i n_5=n-j n_1=(y-10000*n_10-5000*n_5)//1000 if n_10+n_5+n_1==n and n_1>=0 : ans=str(n_10)+' '+str(n_5)+' '+str(n_1) break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var y : OclAny := null; Sequence{n,y} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) ))))))) (comp_for for (exprlist (expr (atom (name num)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var ans : String := '-1-1-1' ; for i : Integer.subrange(0, n + 1-1) do ( if ans /= '-1-1-1' then ( break ) else skip ; for j : Integer.subrange(0, n + 1-1) do ( var n if ans /= '-1-1-1' then ( break ) else skip0 : double := n - i ; var n_5 : double := n - j ; var n var n if ans /= '-1-1-1' then ( break ) else skip0 : double := n - i : int := (y - 10000 * n var n if ans /= '-1-1-1' then ( break ) else skip0 : double := n - i0 - 5000 * n_5) div 1000 ; if n var n if ans /= '-1-1-1' then ( break ) else skip0 : double := n - i0 + n_5 + n var n if ans /= '-1-1-1' then ( break ) else skip0 : double := n - i = n & n var n if ans /= '-1-1-1' then ( break ) else skip0 : double := n - i >= 0 then ( ans := ("" + ((n var n if ans /= '-1-1-1' then ( break ) else skip0 : double := n - i0))) + ' ' + ("" + ((n_5))) + ' ' + ("" + ((n var n if ans /= '-1-1-1' then ( break ) else skip0 : double := n - i))) ; break ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def listing(char,str): l,i=[],0 while True : tmp=str.find(char,i) if tmp==-1 : break else : l.append(tmp) i=tmp+1 return l def signboard(s,t): res=False if t.find(s)!=-1 : return True A,B=listing(s[0],t),listing(s[1],t) if len(A)==0 or len(B)==0 : return False for a in range(len(A)): for b in range(len(B)): if A[a]>=B[b]: continue c=B[b]-A[a] res=True for S in range(2,len(s)): if A[a]+S*c+1>len(t): res=False continue if s[S]!=t[A[a]+S*c]: res=False break if res==True : return res return res n=int(input()) a=input().strip() S=[input().strip()for _ in range(n)] cnt=0 for b in S : if signboard(a,b): cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := input()->trim() ; var S : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (input()->trim())) ; var cnt : int := 0 ; for b : S do ( if signboard(a, b) then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display(); operation listing(char : OclAny, OclType["String"] : OclAny) : OclAny pre: true post: true activity: var l : OclAny := null; var i : OclAny := null; Sequence{l,i} := Sequence{Sequence{},0} ; while true do ( var tmp : String := ("" + (->indexOf(char, i) - 1)) ; if tmp = -1 then ( break ) else ( execute ((tmp) : l) ; var i : String := tmp + 1 )) ; return l; operation signboard(s : OclAny, t : OclAny) : OclAny pre: true post: true activity: var res : boolean := false ; if t->indexOf(s) - 1 /= -1 then ( return true ) else skip ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := Sequence{listing(s->first(), t),listing(s[1+1], t)} ; if (A)->size() = 0 or (B)->size() = 0 then ( return false ) else skip ; for a : Integer.subrange(0, (A)->size()-1) do ( for b : Integer.subrange(0, (B)->size()-1) do ( if (A[a+1]->compareTo(B[b+1])) >= 0 then ( continue ) else skip ; var c : double := B[b+1] - A[a+1] ; res := true ; for S : Integer.subrange(2, (s)->size()-1) do ( if (A[a+1] + S * c + 1->compareTo((t)->size())) > 0 then ( res := false ; continue ) else skip ; if s[S+1] /= t[A[a+1] + S * c+1] then ( res := false ; break ) else skip) ; if res = true then ( return res ) else skip)) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(target_name,n): ans=0 for _ in range(n): signboard=input() found=False for st in[i for i,ch in enumerate(signboard)if ch==target_name[0]]: if found : break gap=1 while True : x=signboard[st : : gap] if len(x)size())->collect( _indx | Sequence{_indx-1, (signboard)->at(_indx)} )->select(_tuple | let i : OclAny = _tuple->at(1) in let ch : OclAny = _tuple->at(2) in ch = target_name->first())->collect(_tuple | let i : OclAny = _tuple->at(1) in let ch : OclAny = _tuple->at(2) in (i)) do ( if found then ( break ) else skip ; var gap : int := 1 ; while true do ( var x : OclAny := signboard(subscript (test (logical_test (comparison (expr (atom (name st)))))) : (sliceop : (test (logical_test (comparison (expr (atom (name gap)))))))) ; if ((x)->size()->compareTo((target_name)->size())) < 0 then ( break ) else skip ; if x->hasPrefix(target_name) then ( found := true ; break ) else skip ; gap := gap + 1)) ; ans := ans + found) ; return ans; operation main(args : OclAny) pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; ans := solve(s, n) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) name=input() length=len(name) def check(ss): ind=0 end=len(ss) while indtoInteger() ; var name : String := (OclFile["System.in"]).readLine() ; var length : int := (name)->size() ; skip ; execute ((Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (check((OclFile["System.in"]).readLine()))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) name=str(input()) nlen=len(name) S=[list(str(input()))for i in range(N)] ans=0 for i in range(N): s=S[i] flag=0 slen=len(s) for j in range(1,101): wide=j for k in range(slen): now=k kari="" for l in range(nlen): if nowtoInteger() ; var name : String := ("" + (((OclFile["System.in"]).readLine()))) ; var nlen : int := (name)->size() ; var S : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | ((("" + (((OclFile["System.in"]).readLine()))))->characters())) ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( var s : OclAny := S[i+1] ; var flag : int := 0 ; var slen : int := (s)->size() ; for j : Integer.subrange(1, 101-1) do ( var wide : OclAny := j ; for k : Integer.subrange(0, slen-1) do ( var now : OclAny := k ; var kari : String := "" ; for l : Integer.subrange(0, nlen-1) do ( if (now->compareTo(slen)) < 0 then ( kari := kari + s[now+1] ) else ( break ) ; now := now + wide) ; if kari = name then ( flag := 1 ; break ) else skip) ; if flag = 1 then ( break ) else skip) ; if flag = 1 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) vals=list(map(int,input().split())) for i in range(1,len(vals),2): if k>0 and vals[i]-1>vals[i-1]and vals[i]-1>vals[i+1]: vals[i]-=1 k-=1 if k==0 : break if "__main__"==__name__ : print(' '.join(map(str,vals))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var vals : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(1, (vals)->size()-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( if k > 0 & (vals[i+1] - 1->compareTo(vals[i - 1+1])) > 0 & (vals[i+1] - 1->compareTo(vals[i + 1+1])) > 0 then ( vals[i+1] := vals[i+1] - 1 ; k := k - 1 ; if k = 0 then ( break ) else skip ) else skip) ; if "__main__" = __name__ then ( execute (StringLib.sumStringsWithSeparator(((vals)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect n=int(input()) a=sorted(map(int,input().split())) ai=a[-1] half_ai=ai//2 i_left=bisect.bisect_left(a,half_ai) i_right=bisect.bisect_right(a,half_ai) if(a[i_left]==half_ai): print(ai,half_ai) exit() if(i_left==i_right and i_left==0): print(ai,a[0]) exit() if(abs(half_ai-a[i_left-1])>=abs(half_ai-a[i_right])and i_right!=len(a)-1): print(ai,a[i_right]) else : print(ai,a[i_left-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var ai : OclAny := a->last() ; var half_ai : int := ai div 2 ; var i_left : OclAny := bisect.bisect_left(a, half_ai) ; var i_right : OclAny := bisect.bisect_right(a, half_ai) ; if (a[i_left+1] = half_ai) then ( execute (ai)->display() ; exit() ) else skip ; if (i_left = i_right & i_left = 0) then ( execute (ai)->display() ; exit() ) else skip ; if (((half_ai - a[i_left - 1+1])->abs()->compareTo((half_ai - a[i_right+1])->abs())) >= 0 & i_right /= (a)->size() - 1) then ( execute (ai)->display() ) else ( execute (ai)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=map(int,input().split()) a=input().split() a=[int(el)for el in a] for i in range(1,len(a)-1,2): if d>0 : temp=a[i]-1 if a[i-1]a[i+1]: a[i]=temp d-=1 for el in a : print(el,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := input().split() ; a := a->select(el | true)->collect(el | (("" + ((el)))->toInteger())) ; for i : Integer.subrange(1, (a)->size() - 1-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( if d > 0 then ( var temp : double := a[i+1] - 1 ; if (a[i - 1+1]->compareTo(temp)) < 0 & (temp > a[i + 1+1]) then ( a[i+1] := temp ; d := d - 1 ) else skip ) else skip) ; for el : a do ( execute (el)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- line=input().split() n=int(line[0]) k=int(line[1]) line=input().split() l=[] for i in line : l.append(int(i)) for i in range(2*n+1): if i % 2!=0 : if l[i]-1>l[i-1]and l[i]-1>l[i+1]and k>0 : k-=1 l[i]-=1 for item in l : print(item) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var line : OclAny := input().split() ; var n : int := ("" + ((line->first())))->toInteger() ; var k : int := ("" + ((line[1+1])))->toInteger() ; line := input().split() ; var l : Sequence := Sequence{} ; for i : line do ( execute ((("" + ((i)))->toInteger()) : l)) ; for i : Integer.subrange(0, 2 * n + 1-1) do ( if i mod 2 /= 0 then ( if (l[i+1] - 1->compareTo(l[i - 1+1])) > 0 & (l[i+1] - 1->compareTo(l[i + 1+1])) > 0 & k > 0 then ( k := k - 1 ; l[i+1] := l[i+1] - 1 ) else skip ) else skip) ; for item : l do ( execute (item)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) l=list(map(int,input().split())) for i in range(1,2*n,2): if(l[i]-1)>max(l[i-1],l[i+1])and m>0 : l[i]-=1 m-=1 print(*l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(1, 2 * n-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( if ((l[i+1] - 1)->compareTo(Set{l[i - 1+1], l[i + 1+1]}->max())) > 0 & m > 0 then ( l[i+1] := l[i+1] - 1 ; m := m - 1 ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name l))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) peaks=[int(x)for x in input().split()] i=1 while k>0 : if peaks[i-1]peaks[i+1]: peaks[i]-=1 k-=1 i+=2 print(" ".join(str(x)for x in peaks)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var peaks : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var i : int := 1 ; while k > 0 do ( if (peaks[i - 1+1]->compareTo(peaks[i+1] - 1)) < 0 & (peaks[i+1] - 1->compareTo(peaks[i + 1+1])) > 0 then ( peaks[i+1] := peaks[i+1] - 1 ; k := k - 1 ) else skip ; i := i + 2) ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name peaks)))))))), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPossible(n): fac=[0 for i in range(10)] fac[0]=1 fac[1]=1 for i in range(2,10,1): fac[i]=fac[i-1]*i sum=0 x=n while(x): sum+=fac[x % 10] x=int(x/10) if(sum % n==0): return True return False if __name__=='__main__' : n=19 if(isPossible(n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 19 ; if (isPossible(n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isPossible(n : OclAny) : OclAny pre: true post: true activity: var fac : Sequence := Integer.subrange(0, 10-1)->select(i | true)->collect(i | (0)) ; fac->first() := 1 ; fac[1+1] := 1 ; for i : Integer.subrange(2, 10-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( fac[i+1] := fac[i - 1+1] * i) ; var sum : int := 0 ; var x : OclAny := n ; while (x) do ( sum := sum + fac[x mod 10+1] ; x := ("" + ((x / 10)))->toInteger()) ; if (sum mod n = 0) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A=10 B=5 C=1 N,Y=map(int,input().split()) Y//=1000 res_A=-1 res_B=-1 res_C=-1 for num_A in[num_A for num_A in range(N+1)if A*num_A<=Y]: diff_YA=Y-A*num_A for num_B in[num_B for num_B in range(N+1-num_A)if B*num_B<=diff_YA]: diff_YAB=diff_YA-B*num_B if(diff_YAB==C*(N-num_A-num_B)): res_A=num_A res_B=num_B res_C=N-num_A-num_B break else : continue break print("{}{}{}".format(res_A,res_B,res_C)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : int := 10 ; var B : int := 5 ; var C : int := 1 ; var N : OclAny := null; var Y : OclAny := null; Sequence{N,Y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; Y := Y div 1000 ; var res_A : int := -1 ; var res_B : int := -1 ; var res_C : int := -1 ; for num_A : Integer.subrange(0, N + 1-1)->select(num_A | (A * num_A->compareTo(Y)) <= 0)->collect(num_A | (num_A)) do ( var diff_YA : double := Y - A * num_A ; (compound_stmt for (exprlist (expr (atom (name num_B)))) in (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name num_B)))))) (comp_for for (exprlist (expr (atom (name num_B)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name N))) + (expr (atom (number (integer 1))))) - (expr (atom (name num_A))))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (expr (atom (name B))) * (expr (atom (name num_B))))) <= (comparison (expr (atom (name diff_YA)))))))))) ])))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name diff_YAB)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name diff_YA))) - (expr (expr (atom (name B))) * (expr (atom (name num_B)))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name diff_YAB)))) == (comparison (expr (expr (atom (name C))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name N))) - (expr (atom (name num_A)))) - (expr (atom (name num_B)))))))) ))))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name res_A)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name num_A)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name res_B)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name num_B)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name res_C)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (name N))) - (expr (atom (name num_A)))) - (expr (atom (name num_B))))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt continue)))))) ; break) ; execute (StringLib.interpolateStrings("{}{}{}", Sequence{res_A, res_B, res_C}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- hist={'A' : 0,'B' : 0,'AB' : 0,'O' : 0} while True : try : i,b=input().strip().split(',') hist[b]+=1 except EOFError : break print("%d\n%d\n%d\n%d" %(hist['A'],hist['B'],hist['AB'],hist['O'])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var hist : Map := Map{ 'A' |-> 0 }->union(Map{ 'B' |-> 0 }->union(Map{ 'AB' |-> 0 }->union(Map{ 'O' |-> 0 }))) ; while true do ( try ( var i : OclAny := null; var b : OclAny := null; Sequence{i,b} := input()->trim().split(',') ; hist[b+1] := hist[b+1] + 1) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))) ; execute (StringLib.format("%d\n%d\n%d\n%d",Sequence{hist->at('A'), hist->at('B'), hist->at('AB'), hist->at('O')}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readlines=sys.stdin.readlines write=sys.stdout.write def solve(): C={} for line in readlines(): a,b=line.strip().split(",") C[b]=C.get(b,0)+1 write("%d\n" % C.get("A",0)) write("%d\n" % C.get("B",0)) write("%d\n" % C.get("AB",0)) write("%d\n" % C.get("O",0)) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readlines : OclAny := (OclFile["System.in"]).readlines ; var write : OclAny := (OclFile["System.out"]).write ; skip ; solve(); operation solve() pre: true post: true activity: var C : OclAny := Set{} ; for line : readlines() do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := line->trim().split(",") ; C[b+1] := C.get(b, 0) + 1) ; write(StringLib.format("%d\n",C.get("A", 0))) ; write(StringLib.format("%d\n",C.get("B", 0))) ; write(StringLib.format("%d\n",C.get("AB", 0))) ; write(StringLib.format("%d\n",C.get("O", 0))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A_Num=0 B_Num=0 O_Num=0 AB_Num=0 while True : try : N,Cha=map(str,input().split(",")) if Cha=="A" : A_Num+=1 elif Cha=="B" : B_Num+=1 elif Cha=="O" : O_Num+=1 else : AB_Num+=1 except EOFError : print(A_Num) print(B_Num) print(AB_Num) print(O_Num) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A_Num : int := 0 ; var B_Num : int := 0 ; var O_Num : int := 0 ; var AB_Num : int := 0 ; while true do ( try ( var N : OclAny := null; var Cha : OclAny := null; Sequence{N,Cha} := (input().split(","))->collect( _x | (OclType["String"])->apply(_x) ) ; if Cha = "A" then ( A_Num := A_Num + 1 ) else (if Cha = "B" then ( B_Num := B_Num + 1 ) else (if Cha = "O" then ( O_Num := O_Num + 1 ) else ( AB_Num := AB_Num + 1 ) ) ) ) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A_Num)))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name B_Num)))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name AB_Num)))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name O_Num)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys f=sys.stdin blood_types=('A','B','AB','O') blood_count={type : 0 for type in blood_types} for line in f : id,blood_type=line.strip().split(',') blood_count[blood_type]+=1 for blood_type in blood_types : print(blood_count[blood_type]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var f : OclFile := OclFile["System.in"] ; var blood_types : OclAny := Sequence{'A', 'B', 'AB', 'O'} ; var blood_count : Map := blood_types->select(type | true)->collect(type | Map{type |-> 0})->unionAll() ; for line : f do ( var id : OclAny := null; var blood_type : OclAny := null; Sequence{id,blood_type} := line->trim().split(',') ; blood_count[blood_type+1] := blood_count[blood_type+1] + 1) ; for blood_type : blood_types do ( execute (blood_count[blood_type+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cas=int(input()) for i in range(cas): n=int(input()) a=sorted([int(x)for x in input().split()]) for i in range(1,n//2+1): print(a[i],a[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cas : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, cas-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))->sort() ; for i : Integer.subrange(1, n div 2 + 1-1) do ( execute (a[i+1])->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B,AB,O=0,0,0,0 while True : try : n=input().split(',') except : break if n[-1]=='A' : A+=1 elif n[-1]=='B' : B+=1 elif n[-1]=='AB' : AB+=1 elif n[-1]=='O' : O+=1 print('{}\n{}\n{}\n{}'.format(A,B,AB,O)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var AB : OclAny := null; var O : OclAny := null; Sequence{A,B,AB,O} := Sequence{0,0,0,0} ; while true do ( try ( var n : OclAny := input().split(',')) catch (_e : OclException) do ( break) ; if n->last() = 'A' then ( A := A + 1 ) else (if n->last() = 'B' then ( B := B + 1 ) else (if n->last() = 'AB' then ( AB := AB + 1 ) else (if n->last() = 'O' then ( O := O + 1 ) else skip ) ) ) ) ; execute (StringLib.interpolateStrings('{} {} {} {}', Sequence{A, B, AB, O}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binomialCoeff(n,k): res=1 if(k>n-k): k=n-k for i in range(k): res*=(n-i) res//=(i+1) return res def countPaths(x1,y1,x2,y2): m=abs(x1-x2) n=abs(y1-y2) return(binomialCoeff(m+n,n)) x1,y1,x2,y2=2,3,4,5 print(countPaths(x1,y1,x2,y2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{x1,y1,x2,y2} := Sequence{2,3,4,5} ; execute (countPaths(x1, y1, x2, y2))->display(); operation binomialCoeff(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; if ((k->compareTo(n - k)) > 0) then ( k := n - k ) else skip ; for i : Integer.subrange(0, k-1) do ( res := res * (n - i) ; res := res div (i + 1)) ; return res; operation countPaths(x1 : OclAny, y1 : OclAny, x2 : OclAny, y2 : OclAny) : OclAny pre: true post: true activity: var m : double := (x1 - x2)->abs() ; n := (y1 - y2)->abs() ; return (binomialCoeff(m + n, n)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def breakSum(n): if(n==0 or n==1): return n return max((breakSum(n//2)+breakSum(n//3)+breakSum(n//4)),n) if __name__=="__main__" : n=12 print(breakSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 12 ; execute (breakSum(n))->display() ) else skip; operation breakSum(n : OclAny) : OclAny pre: true post: true activity: if (n = 0 or n = 1) then ( return n ) else skip ; return Set{(breakSum(n div 2) + breakSum(n div 3) + breakSum(n div 4)), n}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def ask(x,y): print("1",x,y) sys.stdout.flush() return input() def solve(L,R): while L>1 if ask(mid,mid+1)=="TAK" : R=mid else : L=mid+1 return L n,k=list(map(int,input().split())) a=solve(1,n) b,c=a,a if a>1 : b=solve(1,a-1) if acollect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := solve(1, n) ; var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := Sequence{a,a} ; if a > 1 then ( var b : OclAny := solve(1, a - 1) ) else skip ; if (a->compareTo(n)) < 0 then ( var c : OclAny := solve(a + 1, n) ) else skip ; if ask(b, c) = "NIE" then ( Sequence{b,c} := Sequence{c,b} ) else skip ; if a = b then ( Sequence{b,c} := Sequence{c,b} ) else skip ; execute ("2")->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))); operation ask(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: execute ("1")->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))) ; return (OclFile["System.in"]).readLine(); operation solve(L : OclAny, R : OclAny) : OclAny pre: true post: true activity: while (L->compareTo(R)) < 0 do ( var mid : int := (L + R) /(2->pow(1)) ; if ask(mid, mid + 1) = "TAK" then ( R := mid ) else ( L := mid + 1 )) ; return L; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math line=lambda : map(int,input().split()) def ask(x,y): print(1,x,y) sys.stdout.flush() return input()=="TAK" def divide(l,r): d=r-l+1 if d==1 : return l m=(l+r)//2 if ask(m,m+1): return divide(l,m) else : return divide(m+1,r) def solve(): n,k=line() x=divide(1,n) y=x z=x if x>1 : y=divide(1,x-1) if xcollect( _x | (OclType["int"])->apply(_x) )) ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation ask(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: execute (1)->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))) ; return (OclFile["System.in"]).readLine() = "TAK"; operation divide(l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var d : double := r - l + 1 ; if d = 1 then ( return l ) else skip ; var m : int := (l + r) div 2 ; if ask(m, m + 1) then ( return divide(l, m) ) else ( return divide(m + 1, r) ); operation solve() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := line->apply() ; x := divide(1, n) ; y := x ; var z : OclAny := x ; if x > 1 then ( y := divide(1, x - 1) ) else skip ; if (x->compareTo(n)) < 0 then ( z := divide(x + 1, n) ) else skip ; if ask(y, z) = false then ( Sequence{y,z} := Sequence{z,y} ) else skip ; if x = y then ( Sequence{y,z} := Sequence{z,y} ) else skip ; execute (2)->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))); operation main() pre: true post: true activity: solve() ; exit(0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def chek(x,y): print(1,int(x),int(y)) sys.stdout.flush() return input()=='TAK' def binp(l,r): if l==r : return l while l1 : y1=binp(1,x-1) if xcollect( _x | (OclType["int"])->apply(_x) )) ; x := binp(1, n) ; var y1 : OclAny := null; var y2 : OclAny := null; Sequence{y1,y2} := Sequence{x,x} ; if x > 1 then ( var y1 : OclAny := binp(1, x - 1) ) else skip ; if (x->compareTo(n)) < 0 then ( var y2 : OclAny := binp(x + 1, n) ) else skip ; if not(chek(y1, y2)) then ( Sequence{y1,y2} := Sequence{y2,y1} ) else skip ; if x = y1 then ( Sequence{y1,y2} := Sequence{y2,y1} ) else skip ; execute (2)->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))); operation chek(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: execute (1)->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))) ; return (OclFile["System.in"]).readLine() = 'TAK'; operation binp(l : OclAny, r : OclAny) : OclAny pre: true post: true activity: if l = r then ( return l ) else skip ; while (l->compareTo(r)) < 0 do ( var m : int := (l + r) div 2 ; if chek(m, m + 1) then ( r := m ) else ( l := m + 1 )) ; return ("" + ((l)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N_,Y_=input().split() N=(int)(N_) Y=(int)(Y_) count=0 a_=Y//10000 if a_>N : a_=N for a in range(a_+1): Y_=Y-a*10000 N_=N-a b_=Y_//5000 if b_>N_ and b_>=0 : b_=N_ for b in range(b_+1): Y__=Y_-b*5000 N__=N_-b c_=Y__//1000 if Y__ % 1000==0 : if c_==N__ and c_>=0 : print((str)(a)+" "+(str)(b)+" "+(str)(c_)) exit(0) print("-1-1-1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N_ : OclAny := null; var Y_ : OclAny := null; Sequence{N_,Y_} := input().split() ; var N : OclAny := (OclType["int"])(N_) ; var Y : OclAny := (OclType["int"])(Y_) ; var count : int := 0 ; var a_ : int := Y div 10000 ; if (a_->compareTo(N)) > 0 then ( a_ := N ) else skip ; for a : Integer.subrange(0, a_ + 1-1) do ( var Y_ : double := Y - a * 10000 ; var N_ : double := N - a ; var b_ : int := Y_ div 5000 ; if (b_->compareTo(N_)) > 0 & b_ >= 0 then ( b_ := N_ ) else skip ; for b : Integer.subrange(0, b_ + 1-1) do ( var Y__ : double := Y_ - b * 5000 ; var N__ : double := N_ - b ; var c_ : int := Y__ div 1000 ; if Y__ mod 1000 = 0 then ( if c_ = N__ & c_ >= 0 then ( execute ((OclType["String"])(a) + " " + (OclType["String"])(b) + " " + (OclType["String"])(c_))->display() ; exit(0) ) else skip ) else skip)) ; execute ("-1-1-1")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def query(x,y): print(1,x,y) ans=input() return ans=="TAK" def solve(L,R): while Lcollect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := solve(1, N) ; if a = 1 then ( execute (2)->display() ; exit(0) ) else skip ; if a = N then ( execute (2)->display() ; exit(0) ) else skip ; var b : OclAny := solve(1, a - 1) ; if query(b, a) = false then ( b := solve(a + 1, N) ) else skip ; execute (2)->display(); operation query(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: execute (1)->display() ; var ans : String := (OclFile["System.in"]).readLine() ; return ans = "TAK"; operation solve(L : OclAny, R : OclAny) : OclAny pre: true post: true activity: while (L->compareTo(R)) < 0 do ( var M : int := (L + R) div 2 ; if query(M, M + 1) then ( R := M ) else ( L := M + 1 )) ; return L; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def chek(x,y): print(1,int(x),int(y)) sys.stdout.flush() return input()=='TAK' def binp(l,r): if l==r : return l while l1 : y1=binp(1,x-1) if xcollect( _x | (OclType["int"])->apply(_x) )) ; x := binp(1, n) ; var y1 : OclAny := null; var y2 : OclAny := null; Sequence{y1,y2} := Sequence{x,x} ; if x > 1 then ( var y1 : OclAny := binp(1, x - 1) ) else skip ; if (x->compareTo(n)) < 0 then ( var y2 : OclAny := binp(x + 1, n) ) else skip ; if not(chek(y1, y2)) then ( Sequence{y1,y2} := Sequence{y2,y1} ) else skip ; if x = y1 then ( Sequence{y1,y2} := Sequence{y2,y1} ) else skip ; execute (2)->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))); operation chek(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: execute (1)->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))) ; return (OclFile["System.in"]).readLine() = 'TAK'; operation binp(l : OclAny, r : OclAny) : OclAny pre: true post: true activity: if l = r then ( return l ) else skip ; while (l->compareTo(r)) < 0 do ( var m : int := (l + r) div 2 ; if chek(m, m + 1) then ( r := m ) else ( l := m + 1 )) ; return ("" + ((l)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=3 def preComputeXor(arr,prefix_xor): for i in range(n): for j in range(n): if(j==0): prefix_xor[i][j]=arr[i][j] else : prefix_xor[i][j]=(prefix_xor[i][j-1]^ arr[i][j]) for i in range(n): for j in range(1,n): prefix_xor[j][i]=(prefix_xor[j-1][i]^ prefix_xor[j][i]) def ansQuerie(prefix_xor,x1,y1,x2,y2): xor_1,xor_2,xor_3=0,0,0 if(x1!=0): xor_1=prefix_xor[x1-1][y2] if(y1!=0): xor_2=prefix_xor[x2][y1-1] if(x1!=0 and y1!=0): xor_3=prefix_xor[x1-1][y1-1] return((prefix_xor[x2][y2]^ xor_1)^(xor_2 ^ xor_3)) arr=[[1,2,3],[4,5,6],[7,8,9]] prefix_xor=[[0 for i in range(n)]for i in range(n)] preComputeXor(arr,prefix_xor) print(ansQuerie(prefix_xor,1,1,2,2)) print(ansQuerie(prefix_xor,1,2,2,2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := 3 ; skip ; skip ; arr := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))}->union(Sequence{ Sequence{7}->union(Sequence{8}->union(Sequence{ 9 })) })) ; prefix_xor := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)))) ; preComputeXor(arr, prefix_xor) ; execute (ansQuerie(prefix_xor, 1, 1, 2, 2))->display() ; execute (ansQuerie(prefix_xor, 1, 2, 2, 2))->display(); operation preComputeXor(arr : OclAny, prefix_xor : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if (j = 0) then ( prefix_xor[i+1][j+1] := arr[i+1][j+1] ) else ( prefix_xor[i+1][j+1] := (MathLib.bitwiseXor(prefix_xor[i+1][j - 1+1], arr[i+1][j+1])) ))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(1, n-1) do ( prefix_xor[j+1][i+1] := (MathLib.bitwiseXor(prefix_xor[j - 1+1][i+1], prefix_xor[j+1][i+1])))); operation ansQuerie(prefix_xor : OclAny, x1 : OclAny, y1 : OclAny, x2 : OclAny, y2 : OclAny) : OclAny pre: true post: true activity: var xorxor skip,xor:= 0,0,0,xor_3 : OclAny := null; var xor:= 0,0,0 : OclAny := null; var xor_3 : OclAny := null; Sequence{xor skip,xor:= 0,0,0,xor_3} := Sequence{0,0,0} ; if (x1 /= 0) then ( var xor var xorxor skip,xor:= 0,0,0,xor_3 : OclAny := null; var xor:= 0,0,0 : OclAny := null; var xor_3 : OclAny := null; Sequence{xor skip,xor:= 0,0,0,xor_3} := Sequence{0,0,0} : OclAny := prefix_xor[x1 - 1+1][y2+1] ) else skip ; if (y1 /= 0) then ( var xor:= prefix_xor[x2+1][y1 - 1+1] : OclAny := prefix_xor[x2+1][y1 - 1+1] ) else skip ; if (x1 /= 0 & y1 /= 0) then ( var xor_3 : OclAny := prefix_xor[x1 - 1+1][y1 - 1+1] ) else skip ; return (MathLib.bitwiseXor((MathLib.bitwiseXor(prefix_xor[x2+1][y2+1], xor var xorxor skip,xor:= 0,0,0,xor_3 : OclAny := null; var xor:= 0,0,0 : OclAny := null; var xor_3 : OclAny := null; Sequence{xor skip,xor:= 0,0,0,xor_3} := Sequence{0,0,0})), (MathLib.bitwiseXor(xorxor_3, xor_3)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) l=list(map(int,input().split())) l.sort() for i in range(n//2): print(l[i+1],l[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := l->sort() ; for i : Integer.subrange(0, n div 2-1) do ( execute (l[i + 1+1])->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bellNumber(n): bell=[[0 for i in range(n+1)]for j in range(n+1)] bell[0][0]=1 for i in range(1,n+1): bell[i][0]=bell[i-1][i-1] for j in range(1,i+1): bell[i][j]=bell[i-1][j-1]+bell[i][j-1] return bell[n][0] for n in range(6): print('Bell Number',n,'is',bellNumber(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for n : Integer.subrange(0, 6-1) do ( execute ('Bell Number')->display()); operation bellNumber(n : OclAny) : OclAny pre: true post: true activity: var bell : Sequence := Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)))) ; bell->first()->first() := 1 ; for i : Integer.subrange(1, n + 1-1) do ( bell[i+1]->first() := bell[i - 1+1][i - 1+1] ; for j : Integer.subrange(1, i + 1-1) do ( bell[i+1][j+1] := bell[i - 1+1][j - 1+1] + bell[i+1][j - 1+1])) ; return bell[n+1]->first(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Survives(n): i=2 while(True): if(i>n): return True ; if(n % i==0): return False ; n-=n//i ; i+=1 if __name__=="__main__" : n=17 ; if(Survives(n)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 17; ; if (Survives(n)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ) else skip; operation Survives(n : OclAny) pre: true post: true activity: var i : int := 2 ; while (true) do ( if ((i->compareTo(n)) > 0) then ( return true; ) else skip ; if (n mod i = 0) then ( return false; ) else skip ; n := n - n div i; ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isFactorial(n): i=1 ; while(True): if(n % i==0): n//=i ; else : break ; i+=1 ; if(n==1): return True ; else : return False ; if __name__=="__main__" : n=24 ; ans=isFactorial(n); if(ans==1): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 24; ; var ans : OclAny := isFactorial(n); ; if (ans = 1) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ) else skip; operation isFactorial(n : OclAny) pre: true post: true activity: var i : int := 1; ; while (true) do ( if (n mod i = 0) then ( n := n div i; ) else ( break; ) ; i := i + 1;) ; if (n = 1) then ( return true; ) else ( return false; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def onlyFirstAndLastAreSet(n): if(n==1): return True if(n==2): return False return(((n-1)&(n-2))==0) n=9 if(onlyFirstAndLastAreSet(n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 9 ; if (onlyFirstAndLastAreSet(n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation onlyFirstAndLastAreSet(n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return true ) else skip ; if (n = 2) then ( return false ) else skip ; return ((MathLib.bitwiseAnd((n - 1), (n - 2))) = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def adjacentSet(n): return(n &(n>>1)) if __name__=='__main__' : n=3 if(adjacentSet(n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 3 ; if (adjacentSet(n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation adjacentSet(n : OclAny) : OclAny pre: true post: true activity: return (MathLib.bitwiseAnd(n, (n /(2->pow(1))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printUncommon(str1,str2): a1=0 ; a2=0 ; for i in range(len(str1)): ch=ord(str1[i])-ord('a'); a1=a1 |(1<size()-1) do ( var ch : double := (str1[i+1])->char2byte() - ('a')->char2byte(); ; a1 := MathLib.bitwiseOr(a1, (1 * (2->pow(ch))));) ; for i : Integer.subrange(0, (str2)->size()-1) do ( ch := (str2[i+1])->char2byte() - ('a')->char2byte(); ; a2 := MathLib.bitwiseOr(a2, (1 * (2->pow(ch))));) ; var ans : int := MathLib.bitwiseXor(a1, a2); ; var i : int := 0; ; while (i < 26) do ( if (ans mod 2 = 1) then ( execute ((('a')->char2byte() + i)->byte2char())->display(); ) else skip ; ans := ans div 2; ; i := i + 1;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def solve(n): c=0 while n : c+=n % 10 n//=10 return c n=input()[:-1] x=len(n)*9 n=int(n) d=[] for i in range(n,max(n-x-1,-1),-1): if i+solve(i)==n : d.append(i) print(len(d)) for i in d[: :-1]: print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; n := input()->front() ; var x : int := (n)->size() * 9 ; n := ("" + ((n)))->toInteger() ; var d : Sequence := Sequence{} ; for i : Integer.subrange(Set{n - x - 1, -1}->max() + 1, n)->reverse() do ( if i + solve(i) = n then ( execute ((i) : d) ) else skip) ; execute ((d)->size())->display() ; for i : d(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( execute (i)->display()); operation solve(n : OclAny) : OclAny pre: true post: true activity: var c : int := 0 ; while n do ( c := c + n mod 10 ; n := n div 10) ; return c; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkBitonic(arr,n): for i in range(1,n): if arr[i]>arr[i-1]: continue else : break if i==n-1 : return 1 for j in range(i+1,n): if arr[j]union(Sequence{9}->union(Sequence{7}->union(Sequence{20}->union(Sequence{17}->union(Sequence{5}->union(Sequence{ 1 })))))) ; n := (arr)->size() ; if checkBitonic(arr, n) = 1 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; operation checkBitonic(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(1, n-1) do ( if (arr[i+1]->compareTo(arr[i - 1+1])) > 0 then ( continue ) else ( break )) ; if i = n - 1 then ( return 1 ) else skip ; for j : Integer.subrange(i + 1, n-1) do ( if (arr[j+1]->compareTo(arr[j - 1+1])) < 0 then ( continue ) else ( break )) ; var i : OclAny := j ; if i /= n - 1 then ( return 0 ) else skip ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- val=[10000,5000,1000] n,y=map(int,input().split()) mx=[y//i for i in val] nm=[0,0,0] an=[-1,-1,-1] is_find=False for nm[0]in range(min(n,mx[0])+1): for nm[1]in range(min(n,mx[1])+1): nm[2]=n-nm[0]-nm[1] if nm[2]<0 : break elif nm[0]*val[0]+nm[1]*val[1]+nm[2]*val[2]==y and nm[2]>=0 : an=nm is_find=True break if is_find : break print("{}{}{}".format(an[0],an[1],an[2])) pass ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var val : Sequence := Sequence{10000}->union(Sequence{5000}->union(Sequence{ 1000 })) ; var n : OclAny := null; var y : OclAny := null; Sequence{n,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mx : Sequence := val->select(i | true)->collect(i | (y div i)) ; var nm : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) ; var an : Sequence := Sequence{-1}->union(Sequence{-1}->union(Sequence{ -1 })) ; var is_find : boolean := false ; for nm->first() : Integer.subrange(0, Set{n, mx->first()}->min() + 1-1) do ( for nm[1+1] : Integer.subrange(0, Set{n, mx[1+1]}->min() + 1-1) do ( nm[2+1] := n - nm->first() - nm[1+1] ; if nm[2+1] < 0 then ( break ) else (if nm->first() * val->first() + nm[1+1] * val[1+1] + nm[2+1] * val[2+1] = y & nm[2+1] >= 0 then ( an := nm ; is_find := true ; break ) else skip)) ; if is_find then ( break ) else skip) ; execute (StringLib.interpolateStrings("{}{}{}", Sequence{an->first(), an[1+1], an[2+1]}))->display() ; skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inp=int(input()) m=inp-9*(len(str(inp))) array=[] x=0 def return_digits(value): returned=0 while value>0 : returned+=value % 10 value//=10 return returned for i in range(max(m,0),inp): value=i+return_digits(i) if value==inp : array.append(i) x=x+1 print(x) for i in array : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inp : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : double := inp - 9 * ((("" + ((inp))))->size()) ; var array : Sequence := Sequence{} ; var x : int := 0 ; skip ; for i : Integer.subrange(Set{m, 0}->max(), inp-1) do ( value := i + return_digits(i) ; if value = inp then ( execute ((i) : array) ; x := x + 1 ) else skip) ; execute (x)->display() ; for i : array do ( execute (i)->display()); operation return_digits(value : OclAny) : OclAny pre: true post: true activity: var returned : int := 0 ; while value > 0 do ( returned := returned + value mod 10 ; value := value div 10) ; return returned; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) arr=list(map(int,input().split())) arr.sort() num=arr[0] cnt=0 for i in range(1,n): cnt+=1 ar=[] ar.append(arr[i]) ar.append(num) if cnt>n//2 : break print(*ar) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := arr->sort() ; var num : OclAny := arr->first() ; var cnt : int := 0 ; for i : Integer.subrange(1, n-1) do ( cnt := cnt + 1 ; var ar : Sequence := Sequence{} ; execute ((arr[i+1]) : ar) ; execute ((num) : ar) ; if (cnt->compareTo(n div 2)) > 0 then ( break ) else skip ; execute ((argument * (test (logical_test (comparison (expr (atom (name ar))))))))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inp=int(input()) m=inp-9*(len(str(inp))) array=[] x=0 def return_digits(value): returned=0 while value>0 : returned+=value % 10 value//=10 return returned for i in range(max(m,0),inp): value=i+return_digits(i) if value==inp : array.append(i) x=x+1 print(x) for i in array : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inp : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : double := inp - 9 * ((("" + ((inp))))->size()) ; var array : Sequence := Sequence{} ; var x : int := 0 ; skip ; for i : Integer.subrange(Set{m, 0}->max(), inp-1) do ( value := i + return_digits(i) ; if value = inp then ( execute ((i) : array) ; x := x + 1 ) else skip) ; execute (x)->display() ; for i : array do ( execute (i)->display()); operation return_digits(value : OclAny) : OclAny pre: true post: true activity: var returned : int := 0 ; while value > 0 do ( returned := returned + value mod 10 ; value := value div 10) ; return returned; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() l=len(n) i=int(n) res=[] for x in range(max(0,i-l*9),i): if i==x+sum(map(int,str(x))): res.append(str(x)) print(len(res)) if res : print('\n'.join(res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var l : int := (n)->size() ; var i : int := ("" + ((n)))->toInteger() ; var res : Sequence := Sequence{} ; for x : Integer.subrange(Set{0, i - l * 9}->max(), i-1) do ( if i = x + ((("" + ((x))))->collect( _x | (OclType["int"])->apply(_x) ))->sum() then ( execute ((("" + ((x)))) : res) ) else skip) ; execute ((res)->size())->display() ; if res then ( execute (StringLib.sumStringsWithSeparator((res), ' '))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) v=[x for x in range(max(1,n-81),n)if x+sum(map(int,str(x)))==n] print(len(v)) for vi in v : print(vi) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var v : Sequence := Integer.subrange(Set{1, n - 81}->max(), n-1)->select(x | x + ((("" + ((x))))->collect( _x | (OclType["int"])->apply(_x) ))->sum() = n)->collect(x | (x)) ; execute ((v)->size())->display() ; for vi : v do ( execute (vi)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,gcd def countFactors(n): factors=0 ; for i in range(2,int(sqrt(n))+1): while(n % i==0): n//=i factors+=1 if(n!=1): factors+=1 return factors def minOperations(A,B): g=gcd(A,B) A//=g B//=g return countFactors(A)+countFactors(B) if __name__=="__main__" : A,B=10,15 print(minOperations(A,B)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( Sequence{A,B} := Sequence{10,15} ; execute (minOperations(A, B))->display() ) else skip; operation countFactors(n : OclAny) : OclAny pre: true post: true activity: var factors : int := 0; ; for i : Integer.subrange(2, ("" + ((sqrt(n))))->toInteger() + 1-1) do ( while (n mod i = 0) do ( n := n div i ; factors := factors + 1)) ; if (n /= 1) then ( factors := factors + 1 ) else skip ; return factors; operation minOperations(A : OclAny, B : OclAny) : OclAny pre: true post: true activity: var g : OclAny := gcd(A, B) ; A := A div g ; B := B div g ; return countFactors(A) + countFactors(B); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def flipBit(a): if(~ a==0): return 8*sizeof(); currLen=0 ; prevLen=0 ; maxLen=0 ; while(a>0): if((a & 1)==1): currLen+=1 ; elif((a & 1)==0): prevLen=0 if((a & 2)==0)else currLen ; currLen=0 ; maxLen=max(prevLen+currLen,maxLen); a>>=1 ; return maxLen+1 ; print(flipBit(13)); print(flipBit(1775)); print(flipBit(15)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (flipBit(13))->display(); ; execute (flipBit(1775))->display(); ; execute (flipBit(15))->display();; operation flipBit(a : OclAny) pre: true post: true activity: if (MathLib.bitwiseNot(a) = 0) then ( return 8 * sizeof(); ) else skip ; var currLen : int := 0; ; var prevLen : int := 0; ; var maxLen : int := 0; ; while (a > 0) do ( if ((MathLib.bitwiseAnd(a, 1)) = 1) then ( currLen := currLen + 1; ) else (if ((MathLib.bitwiseAnd(a, 1)) = 0) then ( prevLen := if ((MathLib.bitwiseAnd(a, 2)) = 0) then 0 else currLen endif; ; currLen := 0; ) else skip) ; maxLen := Set{prevLen + currLen, maxLen}->max(); ; a := a div (2->pow(1));) ; return maxLen + 1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printMinimumProduct(arr,n): first_min=min(arr[0],arr[1]) second_min=max(arr[0],arr[1]) for i in range(2,n): if(arr[i]union(Sequence{8}->union(Sequence{5}->union(Sequence{7}->union(Sequence{5}->union(Sequence{ 100 }))))) ; n := (a)->size() ; execute (printMinimumProduct(a, n))->display(); operation printMinimumProduct(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var first_min : OclAny := Set{arr->first(), arr[1+1]}->min() ; var second_min : OclAny := Set{arr->first(), arr[1+1]}->max() ; for i : Integer.subrange(2, n-1) do ( if ((arr[i+1]->compareTo(first_min)) < 0) then ( second_min := first_min ; first_min := arr[i+1] ) else (if ((arr[i+1]->compareTo(second_min)) < 0) then ( second_min := arr[i+1] ) else skip)) ; return first_min * second_min; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkNumber(N): temp=N while(temp>0): if(temp % 1000==144): temp/=1000 elif(temp % 100==14): temp/=100 elif(temp % 10==1): temp/=10 else : return "YES" return "NO" N=1414 ; print(checkNumber(N)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 1414; ; execute (checkNumber(N))->display();; operation checkNumber(N : OclAny) : OclAny pre: true post: true activity: var temp : OclAny := N ; while (temp > 0) do ( if (temp mod 1000 = 144) then ( temp := temp / 1000 ) else (if (temp mod 100 = 14) then ( temp := temp / 100 ) else (if (temp mod 10 = 1) then ( temp := temp / 10 ) else ( return "YES" ) ) ) ) ; return "NO"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class MyHashMap(object): def __init__(self): self.size=10000 self.nodes=[None]*self.size def put(self,key,value): index=hash(key)% self.size if self.nodes[index]is None : self.nodes[index]=ListNode(-1,-1) prev=find(self.nodes[index],key) if prev.next is None : prev.next=ListNode(key,value) else : prev.next.val=value def get(self,key): index=hash(key)% self.size if self.nodes[index]is None : return-1 prev=find(self.nodes[index],key) if prev.next is None : return-1 else : return prev.next.val def remove(self,key): index=hash(key)% self.size if self.nodes[index]is None : return prev=find(self.nodes[index],key) if prev.next is None : return prev.next=prev.next.next def find(bucket,key): node=bucket prev=None while node is not None and node.key!=key : prev=node node=node.next return prev class ListNode(): def __init__(self,key,val): self.key=key self.val=val self.next=None ------------------------------------------------------------ OCL File: --------- class MyHashMap extends object { static operation newMyHashMap() : MyHashMap pre: true post: MyHashMap->exists( _x | result = _x ); attribute size : int := 10000; attribute nodes : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, self.size); operation initialise() : pre: true post: true activity: self.size := 10000 ; self.nodes := MatrixLib.elementwiseMult(Sequence{ null }, self.size); return self; operation put(key : OclAny,value : OclAny) pre: true post: true activity: var index : int := hash(key) mod self.size ; if self.nodes[index+1] <>= null then ( self.nodes[index+1] := ListNode(-1, -1) ) else skip ; var prev : OclAny := find(self.nodes[index+1], key) ; if prev.next <>= null then ( prev.next := ListNode(key, value) ) else ( prev.next.val := value ); operation get(key : OclAny) : OclAny pre: true post: true activity: index := hash(key) mod self.size ; if self.nodes[index+1] <>= null then ( return -1 ) else skip ; prev := find(self.nodes[index+1], key) ; if prev.next <>= null then ( return -1 ) else ( return prev.next.val ); operation remove(key : OclAny) pre: true post: true activity: index := hash(key) mod self.size ; if self.nodes[index+1] <>= null then ( return ) else skip ; prev := find(self.nodes[index+1], key) ; if prev.next <>= null then ( return ) else skip ; prev.next := prev.next.next; } class ListNode { static operation newListNode() : ListNode pre: true post: ListNode->exists( _x | result = _x ); attribute key : OclAny := key; attribute val : OclAny := val; attribute next : OclAny := null; operation initialise(key : OclAny,val : OclAny) : pre: true post: true activity: self.key := key ; self.val := val ; self.next := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip; operation find(bucket : OclAny, key : OclAny) : OclAny pre: true post: true activity: var node : OclAny := bucket ; prev := null ; while not(node <>= null) & node.key /= key do ( prev := node ; node := node.next) ; return prev; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) h=list(map(int,input().split())) res=[0]*n worst=0 for i in range(n): worst=min(worst,h[i]-i-1) res[i]=i+1+worst worst=n+1 for i in range(n)[: :-1]: worst=min(worst,h[i]+i+1) res[i]=min(res[i],worst-i-1) print(max(res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var h : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var worst : int := 0 ; for i : Integer.subrange(0, n-1) do ( worst := Set{worst, h[i+1] - i - 1}->min() ; res[i+1] := i + 1 + worst) ; worst := n + 1 ; for i : range(n)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( worst := Set{worst, h[i+1] + i + 1}->min() ; res[i+1] := Set{res[i+1], worst - i - 1}->min()) ; execute ((res)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,Y=tmp=list(map(int,input().split())) ans=[-1]*3 for i in range(Y//10000+1): tmp=Y-10000*i for j in range(tmp//5000+1): if i+j<=N : if 10000*i+5000*j+1000*(N-i-j)==Y : ans=[i,j,N-i-j] print(ans[0],ans[1],ans[2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var Y : OclAny := null; Sequence{N,Y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); var tmp : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, 3) ; for i : Integer.subrange(0, Y div 10000 + 1-1) do ( tmp := Y - 10000 * i ; for j : Integer.subrange(0, tmp div 5000 + 1-1) do ( if (i + j->compareTo(N)) <= 0 then ( if 10000 * i + 5000 * j + 1000 * (N - i - j) = Y then ( ans := Sequence{i}->union(Sequence{j}->union(Sequence{ N - i - j })) ) else skip ) else skip)) ; execute (ans->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cal(s): s.sort(); return[[x,s[0]]for x in s[1 :(len(s)//2)+1]] p,a,b=int(input()),[],[] for i in range(2*p): a+=[list(map(int,input().split()))] for i in range(p): b+=cal(a[2*i+1]) for i in b : print(i[0],i[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var p : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{p,a,b} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),Sequence{},Sequence{}} ; for i : Integer.subrange(0, 2 * p-1) do ( a := a + Sequence{ ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) }) ; for i : Integer.subrange(0, p-1) do ( b := b + cal(a[2 * i + 1+1])) ; for i : b do ( execute (i->first())->display()); operation cal(s : OclAny) : OclAny pre: true post: true activity: s := s->sort(); return s.subrange(1+1, ((s)->size() div 2) + 1)->select(x | true)->collect(x | (Sequence{x}->union(Sequence{ s->first() }))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def process(H): n=len(H) curr=[1] for i in range(1,n): curr_x=min(H[i],curr[-1]+1) curr.append(curr_x) curr[-1]=1 for i in range(n-2,0,-1): curr_x=min(H[i],curr[i+1]+1) curr[i]=min(curr[i],curr_x) return max(curr) n=int(input()) H=[int(x)for x in input().split()] print(process(H)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; H := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (process(H))->display(); operation process(H : OclAny) : OclAny pre: true post: true activity: var n : int := (H)->size() ; var curr : Sequence := Sequence{ 1 } ; for i : Integer.subrange(1, n-1) do ( var curr_x : OclAny := Set{H[i+1], curr->last() + 1}->min() ; execute ((curr_x) : curr)) ; curr->last() := 1 ; for i : Integer.subrange(0 + 1, n - 2)->reverse() do ( curr_x := Set{H[i+1], curr[i + 1+1] + 1}->min() ; curr[i+1] := Set{curr[i+1], curr_x}->min()) ; return (curr)->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) height=[int(x)for x in input().split()] dp=[0]*n for i in range(n): dp[i]=height[i] dp[0]=1 for i in range(1,n): dp[i]=min(dp[i-1]+1,dp[i]) dp[-1]=1 for i in range(n-2,0,-1): dp[i]=min(dp[i+1]+1,dp[i]) print(max(dp)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var height : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( dp[i+1] := height[i+1]) ; dp->first() := 1 ; for i : Integer.subrange(1, n-1) do ( dp[i+1] := Set{dp[i - 1+1] + 1, dp[i+1]}->min()) ; dp->last() := 1 ; for i : Integer.subrange(0 + 1, n - 2)->reverse() do ( dp[i+1] := Set{dp[i + 1+1] + 1, dp[i+1]}->min()) ; execute ((dp)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def remainderWith7(num): series=[1,3,2,-1,-3,-2]; series_index=0 ; result=0 ; for i in range((len(num)-1),-1,-1): digit=ord(num[i])-48 ; result+=digit*series[series_index]; series_index=(series_index+1)% 6 ; result %=7 ; if(result<0): result=(result+7)% 7 ; return result ; str="12345" ; print("Remainder with 7 is",remainderWith7(str)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var OclType["String"] : String := "12345"; ; execute ("Remainder with 7 is")->display();; operation remainderWith7(num : OclAny) pre: true post: true activity: var series : Sequence := Sequence{1}->union(Sequence{3}->union(Sequence{2}->union(Sequence{-1}->union(Sequence{-3}->union(Sequence{ -2 }))))); ; var series_index : int := 0; ; var result : int := 0; ; for i : Integer.subrange(-1 + 1, ((num)->size() - 1))->reverse() do ( var digit : double := (num[i+1])->char2byte() - 48; ; result := result + digit * series[series_index+1]; ; series_index := (series_index + 1) mod 6; ; result := result mod 7;) ; if (result < 0) then ( result := (result + 7) mod 7; ) else skip ; return result;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def niceIndices(A,n): Sum=0 m=defaultdict(lambda : 0) for i in range(n): m[A[i]]+=1 Sum+=A[i] for i in range(n): k=Sum-A[i] if k % 2==0 : k=k>>1 if k in m : if((A[i]==k and m[k]>1)or(A[i]!=k)): print((i+1),end=" ") if __name__=="__main__" : A=[8,3,5,2] n=len(A) niceIndices(A,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( A := Sequence{8}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 2 }))) ; n := (A)->size() ; niceIndices(A, n) ) else skip; operation niceIndices(A : OclAny, n : OclAny) pre: true post: true activity: var Sum : int := 0 ; var m : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; for i : Integer.subrange(0, n-1) do ( m[A[i+1]+1] := m[A[i+1]+1] + 1 ; Sum := Sum + A[i+1]) ; for i : Integer.subrange(0, n-1) do ( var k : double := Sum - A[i+1] ; if k mod 2 = 0 then ( k := k /(2->pow(1)) ; if (m)->includes(k) then ( if ((A[i+1] = k & m[k+1] > 1) or (A[i+1] /= k)) then ( execute ((i + 1))->display() ) else skip ) else skip ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def partOdd(s): odd=[] for i in range(len(s)): if i % 2!=0 : odd.append(s[i]) return odd def partEven(s): even=[] for i in range(len(s)): if i % 2==0 : even.append(s[i]) return even def canBeMadeEqual(s1,s2): even_s1=partEven(s1) even_s2=partEven(s2) odd_s1=partOdd(s1) odd_s2=partOdd(s2) even_s1.sort() even_s2.sort() odd_s1.sort() odd_s2.sort() if even_s1==even_s2 and odd_s1==odd_s2 : return True return False s1="cdab" s2="abcd" if canBeMadeEqual(s1,s2): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; s1 := "cdab" ; s2 := "abcd" ; if canBeMadeEqual(s1, s2) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation partOdd(s : OclAny) : OclAny pre: true post: true activity: var odd : Sequence := Sequence{} ; for i : Integer.subrange(0, (s)->size()-1) do ( if i mod 2 /= 0 then ( execute ((s[i+1]) : odd) ) else skip) ; return odd; operation partEven(s : OclAny) : OclAny pre: true post: true activity: var even : Sequence := Sequence{} ; for i : Integer.subrange(0, (s)->size()-1) do ( if i mod 2 = 0 then ( execute ((s[i+1]) : even) ) else skip) ; return even; operation canBeMadeEqual(s1 : OclAny, s2 : OclAny) : OclAny pre: true post: true activity: var even_s1 : OclAny := partEven(s1) ; var even_s2 : OclAny := partEven(s2) ; var odd_s1 : OclAny := partOdd(s1) ; var odd_s2 : OclAny := partOdd(s2) ; even_s1 := even_s1->sort() ; even_s2 := even_s2->sort() ; odd_s1 := odd_s1->sort() ; odd_s2 := odd_s2->sort() ; if even_s1 = even_s2 & odd_s1 = odd_s2 then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minJumps(a,b,d): temp=a a=min(a,b) b=max(temp,b) if(d>=b): return(d+b-1)/b if(d==0): return 0 if(d==a): return 1 return 2 a,b,d=3,4,11 print(int(minJumps(a,b,d))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{a,b,d} := Sequence{3,4,11} ; execute (("" + ((minJumps(a, b, d))))->toInteger())->display(); operation minJumps(a : OclAny, b : OclAny, d : OclAny) : OclAny pre: true post: true activity: var temp : OclAny := a ; a := Set{a, b}->min() ; b := Set{temp, b}->max() ; if ((d->compareTo(b)) >= 0) then ( return (d + b - 1) / b ) else skip ; if (d = 0) then ( return 0 ) else skip ; if (d = a) then ( return 1 ) else skip ; return 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque n=int(input()) a=list(map(int,input().split())) q=deque() for i in range(n): if i % 2==0 : q.append(a[i]) else : q.appendleft(a[i]) if n % 2==1 : q.reverse() print(*q) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : Sequence := () ; for i : Integer.subrange(0, n-1) do ( if i mod 2 = 0 then ( execute ((a[i+1]) : q) ) else ( q := q->prepend(a[i+1]) )) ; if n mod 2 = 1 then ( q := q->reverse() ) else skip ; execute ((argument * (test (logical_test (comparison (expr (atom (name q))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) *a,=map(int,input().split()) b=list(reversed(a[1 : : 2]))+a[0 : : 2] print(" ".join(map(str,b if n % 2==0 else reversed(b)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (testlist_star_expr (star_expr * (expr (atom (name a)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name a)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : Sequence := ((a(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->reverse())->union(a(subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) ; execute (StringLib.sumStringsWithSeparator(((if n mod 2 = 0 then b else (b)->reverse() endif)->collect( _x | (OclType["String"])->apply(_x) )), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import array,bisect,collections,copy,heapq,itertools,math,random,re,string,sys,time sys.setrecursionlimit(10**7) INF=10**20 MOD=10**9+7 def II(): return int(input()) def ILI(): return list(map(int,input().split())) def IAI(LINE): return[ILI()for __ in range(LINE)] def IDI(): return{key : value for key,value in ILI()} def read(): n=II() a=list(map(str,input().split())) return n,a def solve(n,a): b=collections.deque([]) if n % 2==0 : for i,ele in enumerate(a): if i % 2==0 : b.append(ele) else : b.appendleft(ele) else : for i,ele in enumerate(a): if i % 2==0 : b.appendleft(ele) else : b.append(ele) ans=" ".join(list(b)) return ans def main(): params=read() print(solve(*params)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var INF : double := (10)->pow(20) ; var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation ILI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation IAI(LINE : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, LINE-1)->select(__ | true)->collect(__ | (ILI())); operation IDI() : OclAny pre: true post: true activity: return ILI()->select(_tuple | true)->collect(_tuple | Map{key |-> value})->unionAll(); operation read() : OclAny pre: true post: true activity: var n : OclAny := II() ; var a : Sequence := ((input().split())->collect( _x | (OclType["String"])->apply(_x) )) ; return n, a; operation solve(n : OclAny, a : OclAny) : OclAny pre: true post: true activity: var b : Sequence := (Sequence{}) ; if n mod 2 = 0 then ( for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var ele : OclAny := _tuple->at(_indx); if i mod 2 = 0 then ( execute ((ele) : b) ) else ( b := b->prepend(ele) )) ) else ( for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var ele : OclAny := _tuple->at(_indx); if i mod 2 = 0 then ( b := b->prepend(ele) ) else ( execute ((ele) : b) )) ) ; var ans : String := StringLib.sumStringsWithSeparator(((b)), " ") ; return ans; operation main() pre: true post: true activity: var params : OclAny := read() ; execute (solve((argument * (test (logical_test (comparison (expr (atom (name params)))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : n=int(input()) num_array=input().split(" ") result=[0 for i in range(n)] for i in range(n)[: :-1]: differ=n-(i+1) if differ % 2==0 : result[differ//2]=num_array[i] else : result[-((differ+1)//2)]=num_array[i] result_word=result[0] for w in result[1 :]: result_word+=" "+w print(result_word) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var num_array : OclAny := input().split(" ") ; var result : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : range(n)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( var differ : double := n - (i + 1) ; if differ mod 2 = 0 then ( result[differ div 2+1] := num_array[i+1] ) else ( result->reverse()->at(-(-((differ + 1) div 2))) := num_array[i+1] )) ; var result_word : OclAny := result->first() ; for w : result->tail() do ( result_word := result_word + " " + w) ; execute (result_word)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): n=int(input()) s=list(map(int,input().split())) m=min(s) pairs=n//2 k=0 for i in range(0,n): if s[i]!=m : print(s[i],m) k+=1 if k==pairs : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : OclAny := (s)->min() ; var pairs : int := n div 2 ; var k : int := 0 ; for i : Integer.subrange(0, n-1) do ( if s[i+1] /= m then ( execute (s[i+1])->display() ; k := k + 1 ) else skip ; if k = pairs then ( break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=10**9+7 def power(p): res=1 for i in range(1,p+1): res*=2 res %=mod return res % mod def subset_square_sum(A): n=len(A) ans=0 for i in A : ans+=i*i % mod ans %=mod return ans*power(n-1)% mod A=[3,7] print(subset_square_sum(A)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : double := (10)->pow(9) + 7 ; skip ; skip ; A := Sequence{3}->union(Sequence{ 7 }) ; execute (subset_square_sum(A))->display(); operation power(p : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; for i : Integer.subrange(1, p + 1-1) do ( res := res * 2 ; res := res mod mod) ; return res mod mod; operation subset_square_sum(A : OclAny) : OclAny pre: true post: true activity: var n : int := (A)->size() ; var ans : int := 0 ; for i : A do ( ans := ans + i * i mod mod ; ans := ans mod mod) ; return ans * power(n - 1) mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import floor def c(n,x): ret=[-1]*n for i in range(n): if i % 2==0 : idx=floor(i/2) else : idx=n-1-floor(i/2) ret[idx]=x[n-i-1] return " ".join([str(i)for i in ret]) def main(): n=int(input()) x=list(map(int,input().split())) print(c(n,x)) def test(): print(c(4,[1,2,3,4])) print(c(6,[0,6,7,6,7,0])) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; main(); operation c(n : OclAny, x : OclAny) : OclAny pre: true post: true activity: var ret : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; for i : Integer.subrange(0, n-1) do ( if i mod 2 = 0 then ( var idx : OclAny := floor(i / 2) ) else ( idx := n - 1 - floor(i / 2) ) ; ret[idx+1] := x[n - i - 1+1]) ; return StringLib.sumStringsWithSeparator((ret->select(i | true)->collect(i | (("" + ((i)))))), " "); operation main() pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; x := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (c(n, x))->display(); operation test() pre: true post: true activity: execute (c(4, Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })))))->display() ; execute (c(6, Sequence{0}->union(Sequence{6}->union(Sequence{7}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 0 })))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import groupby for _ in range(int(input())): n=input() s=input() ans=0 i=0 while i>=0 : i=s.find("010",i) if i>=0 : ans+=1 i+=1 for k,g in groupby(s): if k=="0" : ans+=(len(list(g))-1)*2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : String := (OclFile["System.in"]).readLine() ; var s : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; var i : int := 0 ; while i >= 0 do ( i := s->indexOf("010", i) - 1 ; if i >= 0 then ( ans := ans + 1 ; i := i + 1 ) else skip) ; for _tuple : groupby(s) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var g : OclAny := _tuple->at(_indx); if k = "0" then ( ans := ans + (((g))->size() - 1) * 2 ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) s=input() count=0 x=0 while xtoInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var count : int := 0 ; var x : int := 0 ; while (x->compareTo(n - 1)) < 0 do ( if s[x+1] = '0' then ( if s[x + 1+1] = '0' then ( count := count + 2 ) else (if (x /= n - 2) & (s[x + 1+1] = '1' & s[x + 2+1] = '0') then ( count := count + 1 ) else skip) ) else skip ; x := x + 1) ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for jj in range(int(input())): n=int(input()) s=input() ans=0 a=b=0 for i in range(n-1): if s[i : i+2]=='00' : a+=1 elif s[i : i+3]=='010' : b+=1 print(a*2+b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for jj : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; var a : OclAny := 0; var b : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if s.subrange(i+1, i + 2) = '00' then ( a := a + 1 ) else (if s.subrange(i+1, i + 3) = '010' then ( b := b + 1 ) else skip)) ; execute (a * 2 + b)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,s,r,l=int(input()),input(),0,[] for i in range(n): if(i+2toInteger()-1) do ( var n : OclAny := null; var s : OclAny := null; var r : OclAny := null; var l : OclAny := null; Sequence{n,s,r,l} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),(OclFile["System.in"]).readLine(),0,Sequence{}} ; for i : Integer.subrange(0, n-1) do ( if ((i + 2->compareTo(n)) < 0 & s[i+1] = '0' & s[i + 1+1] = '1' & s[i + 2+1] = '0') then ( r := r + 1 ) else skip ; if ((i + 1->compareTo(n)) < 0 & s[i+1] = '0' & s[i + 1+1] = '0') then ( r := r + 2 ) else skip) ; execute (r)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from operator import index T=int(input()) for t in range(T): n=int(input()) s=input() indexs=[] for i in range(n): if s[i]=='0' : indexs.append(i) i=1 ans=0 while(itoInteger() ; for t : Integer.subrange(0, T-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var indexs : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = '0' then ( execute ((i) : indexs) ) else skip) ; var i : int := 1 ; var ans : int := 0 ; while ((i->compareTo((indexs)->size())) < 0) do ( ans := ans + Set{2 - (indexs[i+1] - indexs[i - 1+1] - 1), 0}->max() ; i := i + 1) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd,sqrt def sumcommDiv(a,b): n=gcd(a,b) sum=0 N=int(sqrt(n))+1 for i in range(1,N,1): if(n % i==0): if(n/i==i): sum+=i else : sum+=(n/i)+i return sum if __name__=='__main__' : a=10 b=15 print("Sum=",int(sumcommDiv(a,b))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( a := 10 ; b := 15 ; execute ("Sum=")->display() ) else skip; operation sumcommDiv(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var n : OclAny := gcd(a, b) ; var sum : int := 0 ; var N : int := ("" + ((sqrt(n))))->toInteger() + 1 ; for i : Integer.subrange(1, N-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if (n mod i = 0) then ( if (n / i = i) then ( sum := sum + i ) else ( sum := sum + (n / i) + i ) ) else skip) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def MinimumMoves(a,n,x): ans=0 for i in range(1,n): if a[i]<=a[i-1]: p=(a[i-1]-a[i])//x+1 ans+=p a[i]+=p*x return ans if __name__=="__main__" : arr=[1,3,3,2] x=2 n=len(arr) print(MinimumMoves(arr,n,x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var arr : Sequence := Sequence{1}->union(Sequence{3}->union(Sequence{3}->union(Sequence{ 2 }))) ; x := 2 ; n := (arr)->size() ; execute (MinimumMoves(arr, n, x))->display() ) else skip; operation MinimumMoves(a : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(1, n-1) do ( if (a[i+1]->compareTo(a[i - 1+1])) <= 0 then ( var p : int := (a[i - 1+1] - a[i+1]) div x + 1 ; ans := ans + p ; a[i+1] := a[i+1] + p * x ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) s=input() print(k*min([s.count(chr(ord('A')+i))for i in range(k)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; execute (k * (Integer.subrange(0, k-1)->select(i | true)->collect(i | (s->count((('A')->char2byte() + i)->byte2char()))))->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(a==0): return b return gcd(b % a,a) def powGCD(a,n,b): for i in range(0,n+1,1): a=a*a return gcd(a,b) if __name__=='__main__' : a=10 b=5 n=2 print(powGCD(a,n,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( a := 10 ; b := 5 ; n := 2 ; execute (powGCD(a, n, b))->display() ) else skip; operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0) then ( return b ) else skip ; return gcd(b mod a, a); operation powGCD(a : OclAny, n : OclAny, b : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n + 1-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( a := a * a) ; return gcd(a, b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import* from math import* from decimal import* from collections import* import numbers from operator import index import sys def _input(): return map(int,input().split()) def _list(): return list(map(int,input().split())) def _int(): return int(input()) def solves(): n,k=_input() s=input() mn=inf char='' alpha=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'] for i in range(k): if alpha[i]not in s : print(0) return if(s.count(alpha[i])<=mn): mn=min(mn,s.count(alpha[i])) print(mn*k) t=1 for _ in range(0,t): solves() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solves()); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation _list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation _int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation solves() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := _input() ; var s : String := (OclFile["System.in"]).readLine() ; var mn : double := Math_PINFINITY ; var char : String := '' ; var alpha : Sequence := Sequence{'A'}->union(Sequence{'B'}->union(Sequence{'C'}->union(Sequence{'D'}->union(Sequence{'E'}->union(Sequence{'F'}->union(Sequence{'G'}->union(Sequence{'H'}->union(Sequence{'I'}->union(Sequence{'J'}->union(Sequence{'K'}->union(Sequence{'L'}->union(Sequence{'M'}->union(Sequence{'N'}->union(Sequence{'O'}->union(Sequence{'P'}->union(Sequence{'Q'}->union(Sequence{'R'}->union(Sequence{'S'}->union(Sequence{'T'}->union(Sequence{'U'}->union(Sequence{'V'}->union(Sequence{'W'}->union(Sequence{'X'}->union(Sequence{'Y'}->union(Sequence{ 'Z' }))))))))))))))))))))))))) ; for i : Integer.subrange(0, k-1) do ( if (s)->characters()->excludes(alpha[i+1]) then ( execute (0)->display() ; return ) else skip ; if ((s->count(alpha[i+1])->compareTo(mn)) <= 0) then ( mn := Set{mn, s->count(alpha[i+1])}->min() ) else skip) ; execute (mn * k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def modPower(x,y,p): res=1 x=x % p while(y>0): if(y & 1): res=(res*x)% p y=y>>1 x=(x*x)% p return res def gcd(a,b): if(b==0): return a return gcd(b,a % b) def gcdPow(a,n,c): if(a % c==0): return c modexpo=modPower(a,n,c) return gcd(modexpo,c) if __name__=="__main__" : a=10248585 n=1000000 c=12564 print(gcdPow(a,n,c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( a := 10248585 ; n := 1000000 ; c := 12564 ; execute (gcdPow(a, n, c))->display() ) else skip; operation modPower(x : OclAny, y : OclAny, p : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; x := x mod p ; while (y > 0) do ( if (MathLib.bitwiseAnd(y, 1)) then ( res := (res * x) mod p ) else skip ; y := y /(2->pow(1)) ; x := (x * x) mod p) ; return res; operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (b = 0) then ( return a ) else skip ; return gcd(b, a mod b); operation gcdPow(a : OclAny, n : OclAny, c : OclAny) : OclAny pre: true post: true activity: if (a mod c = 0) then ( return c ) else skip ; var modexpo : OclAny := modPower(a, n, c) ; return gcd(modexpo, c); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=map(int,input().split()) a=input() l=list() for i in range(y): l.append(a.count(chr(65+i))) l.sort() print(y*l[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : String := (OclFile["System.in"]).readLine() ; var l : Sequence := () ; for i : Integer.subrange(0, y-1) do ( execute ((a->count((65 + i)->byte2char())) : l)) ; l := l->sort() ; execute (y * l->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,k=map(int,input().split()) s=list(input().rstrip()) cnt=[0]*k for i in s : cnt[i-65]+=1 ans=min(cnt)*k print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := (input().rstrip()) ; var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, k) ; for i : s do ( cnt[i - 65+1] := cnt[i - 65+1] + 1) ; var ans : double := (cnt)->min() * k ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=list(map(int,input().split())) a=list(input()) c={} for i in range(k): c[chr(i+65)]=0 for i in a : c[i]+=1 m=min(list(c.values())) low=1 high=(n+k-1)//k ; ans=0 while low<=high : mid=(low+high)//2 length=mid*k eachOccur=mid if mid<=m : ans=mid*k low=mid+1 else : high=mid-1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var c : OclAny := Set{} ; for i : Integer.subrange(0, k-1) do ( c[(i + 65)->byte2char()+1] := 0) ; for i : a do ( c[i+1] := c[i+1] + 1) ; var m : OclAny := ((c.values()))->min() ; var low : int := 1 ; var high : int := (n + k - 1) div k; var ans : int := 0 ; while (low->compareTo(high)) <= 0 do ( var mid : int := (low + high) div 2 ; var length : double := mid * k ; var eachOccur : int := mid ; if (mid->compareTo(m)) <= 0 then ( ans := mid * k ; low := mid + 1 ) else ( high := mid - 1 )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) d=((a-b)*c+b-1)//b print(d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : int := ((a - b) * c + b - 1) div b ; execute (d)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) print((a*c+b-1)//b-c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a * c + b - 1) div b - c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math buffer=input() a,b,c=buffer.split() a,b,c=int(a),int(b),int(c) print(int(math.ceil(((a*c)-(b*c))/b))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var buffer : String := (OclFile["System.in"]).readLine() ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := buffer.split() ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{("" + ((a)))->toInteger(),("" + ((b)))->toInteger(),("" + ((c)))->toInteger()} ; execute (("" + (((((a * c) - (b * c)) / b)->ceil())))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=input().split(' ') a,b,c=int(l[0]),int(l[1]),int(l[2]) d=((a-b)*c+b-1)//b print(d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := input().split(' ') ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{("" + ((l->first())))->toInteger(),("" + ((l[1+1])))->toInteger(),("" + ((l[2+1])))->toInteger()} ; var d : int := ((a - b) * c + b - 1) div b ; execute (d)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil a,b,c=map(int,input().split()) print(ceil(a*c/b-c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (ceil(a * c / b - c))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): k,x=map(int,input().split()) print(x+(k-1)*9) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var k : OclAny := null; var x : OclAny := null; Sequence{k,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (x + (k - 1) * 9)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline P=10**9+7 def main(): N,K=map(int,input().split()) ans=0 n_gcd=[0]*(K+1) for k in reversed(range(1,K+1)): n=pow(K//k,N,mod=P) for kk in range(2*k,K+1,k): n-=n_gcd[kk] n_gcd[k]=n % P ans+=k*n_gcd[k] ans %=P print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var P : double := (10)->pow(9) + 7 ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; var n_gcd : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (K + 1)) ; for k : (Integer.subrange(1, K + 1-1))->reverse() do ( var n : double := (K div k)->pow(N) ; for kk : Integer.subrange(2 * k, K + 1-1)->select( $x | ($x - 2 * k) mod k = 0 ) do ( n := n - n_gcd[kk+1]) ; n_gcd[k+1] := n mod P ; ans := ans + k * n_gcd[k+1] ; ans := ans mod P) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=10**9+7 from functools import lru_cache @ lru_cache() def pow(N,K): if K==0 : return 1 elif K==1 : return N if K % 2==0 : return(pow(N,K//2)*pow(N,K//2))% mod else : return(N*pow(N,K-1))% mod def f(N,K,i): if table[K]>0 and i==1 : return table[K] if K==i : return 1 elif K==1 : return 1 if i==1 : sigma=0 for j in range(2,K+1): sigma+=f(N,K//j,1) sigma=sigma % mod retval=(pow(K,N)-sigma)% mod table[K]=retval return retval else : return f(N,K//i,1)% mod def calc(N,K): retval=0 for i in range(1,K+1): retval+=i*f(N,K,i) retval=retval % mod return retval N,K=[int(i)for i in input().split(" ")] table=[-1 for i in range(K+1)] table[1]=1 print(calc(N,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : double := (10)->pow(9) + 7 ; skip ; (compound_stmt (decorator @ (dotted_name (name lru_cache)) ( )) (funcdef def (name pow) ( (typedargslist (def_parameters (def_parameter (named_parameter (name N))) , (def_parameter (named_parameter (name K))))) ) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name K)))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name K)))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name N)))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name K))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name pow)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name K))) // (expr (atom (number (integer 2)))))))))) )))) * (expr (atom (name pow)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name K))) // (expr (atom (number (integer 2)))))))))) ))))))))) ))) % (expr (atom (name mod)))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name N))) * (expr (atom (name pow)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name K))) - (expr (atom (number (integer 1)))))))))) ))))))))) ))) % (expr (atom (name mod)))))))))))))))))) ; skip ; skip ; Sequence{N,K} := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var table : Sequence := Integer.subrange(0, K + 1-1)->select(i | true)->collect(i | (-1)) ; table[1+1] := 1 ; execute (calc(N, K))->display(); operation f(N : OclAny, K : OclAny, i : OclAny) : OclAny pre: true post: true activity: if table[K+1] > 0 & i = 1 then ( return table[K+1] ) else skip ; if K = i then ( return 1 ) else (if K = 1 then ( return 1 ) else skip) ; if i = 1 then ( var sigma : int := 0 ; for j : Integer.subrange(2, K + 1-1) do ( sigma := sigma + f(N, K div j, 1) ; sigma := sigma mod mod) ; var retval : int := ((K)->pow(N) - sigma) mod mod ; table[K+1] := retval ; return retval ) else ( return f(N, K div i, 1) mod mod ); operation calc(N : OclAny, K : OclAny) : OclAny pre: true post: true activity: retval := 0 ; for i : Integer.subrange(1, K + 1-1) do ( retval := retval + i * f(N, K, i) ; retval := retval mod mod) ; return retval; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def EqualNumber(A,B): return(A ^ B) A=5 ; B=6 print(int(not(EqualNumber(A,B)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; A := 5; B := 6 ; execute (("" + ((not((EqualNumber(A, B))))))->toInteger())->display(); operation EqualNumber(A : OclAny, B : OclAny) : OclAny pre: true post: true activity: return (MathLib.bitwiseXor(A, B)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import functools sys.setrecursionlimit(10**8) INF=float("inf") MOD=1000000007 def solve(N : int,K : int): def NN(a): return K//a @ functools.lru_cache(maxsize=None) def f(a): ans=pow(NN(a),N,MOD) for i in range(2,K+1): if i*a>K : break ans-=f(i*a) ans %=MOD return ans % MOD ans=0 for i in range(1,K+1): ans+=i*f(i) ans %=MOD print(ans) return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() N=int(next(tokens)) K=int(next(tokens)) solve(N,K) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; var INF : double := ("" + (("inf")))->toReal() ; var MOD : int := 1000000007 ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(N : int, K : int) pre: true post: true activity: skip ; (compound_stmt (decorator @ (dotted_name (dotted_name (name functools)) . (name lru_cache)) ( (arglist (argument (test (logical_test (comparison (expr (atom (name maxsize)))))) = (test (logical_test (comparison (expr (atom None))))))) )) (funcdef def (name f) ( (typedargslist (def_parameters (def_parameter (named_parameter (name a))))) ) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name pow)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name NN)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name N))))))) , (argument (test (logical_test (comparison (expr (atom (name MOD)))))))) ))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name K))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name i))) * (expr (atom (name a))))) > (comparison (expr (atom (name K))))))) : (suite (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (name f)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom (name a))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part %= (testlist (test (logical_test (comparison (expr (atom (name MOD)))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (expr (atom (name ans))) % (expr (atom (name MOD)))))))))))))) ; var ans : int := 0 ; for i : Integer.subrange(1, K + 1-1) do ( ans := ans + i * f(i) ; ans := ans mod MOD) ; execute (ans)->display() ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var N : int := ("" + (((tokens).next())))->toInteger() ; var K : int := ("" + (((tokens).next())))->toInteger() ; solve(N, K); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import gcd from functools import reduce input=sys.stdin.buffer.readline class FLT : def __init__(self,mod=10**9+7): self.mod=mod def rep_sqr(self,base,k): ans=1 while k>0 : if k & 1 : ans=ans*base % self.mod base=base*base % self.mod k>>=1 return ans def inv(self,a): return self.rep_sqr(a,self.mod-2) def gcd_list(numbers): return reduce(gcd,numbers) def euler_phi(n): phi=n for i in set(prime_factorize(n)): phi*=(1-(1/i)) return int(phi) 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,k=map(int,input().split()) MOD=10**9+7 flt=FLT(MOD) memo=[-1 for _ in range(k+1)] ans=0 for i in range(1,k+1): d=k//i if memo[d]==-1 : memo[d]=flt.rep_sqr(d,n) ans+=memo[d]*euler_phi(i) print(ans % MOD) ------------------------------------------------------------ OCL File: --------- class FLT { static operation newFLT() : FLT pre: true post: FLT->exists( _x | result = _x ); attribute mod : OclAny := mod; operation initialise(mod : OclAny) : FLT pre: true post: true activity: self.mod := mod; return self; operation rep_sqr(base : OclAny,k : OclAny) : OclAny pre: true post: true activity: var ans : int := 1 ; while k > 0 do ( if MathLib.bitwiseAnd(k, 1) then ( ans := ans * base mod self.mod ) else skip ; base := base * base mod self.mod ; k := k div (2->pow(1))) ; return ans; operation inv(a : OclAny) : OclAny pre: true post: true activity: return self.rep_sqr(a, self.mod - 2); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := sys.stdin.buffer.readline ; skip ; skip ; skip ; skip ; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var MOD : double := (10)->pow(9) + 7 ; var flt : FLT := (FLT.newFLT()).initialise(MOD) ; var memo : Sequence := Integer.subrange(0, k + 1-1)->select(_anon | true)->collect(_anon | (-1)) ; ans := 0 ; for i : Integer.subrange(1, k + 1-1) do ( var d : int := k div i ; if memo[d+1] = -1 then ( memo[d+1] := flt.rep_sqr(d, n) ) else skip ; ans := ans + memo[d+1] * euler_phi(i)) ; execute (ans mod MOD)->display(); operation gcd_list(numbers : OclAny) : OclAny pre: true post: true activity: return reduce(gcd, numbers); operation euler_phi(n : OclAny) : OclAny pre: true post: true activity: var phi : OclAny := n ; for i : Set{}->union((prime_factorize(n))) do ( phi := phi * (1 - (1 / i))) ; return ("" + ((phi)))->toInteger(); operation prime_factorize(n : OclAny) : OclAny pre: true post: true activity: a := Sequence{} ; while n mod 2 = 0 do ( execute ((2) : a) ; n := n div 2) ; var f : int := 3 ; while (f * f->compareTo(n)) <= 0 do ( if n mod f = 0 then ( execute ((f) : a) ; n := n div f ) else ( f := f + 2 )) ; if n /= 1 then ( execute ((n) : a) ) else skip ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=10**9+7 n,k=map(int,input().strip().split()) d=[0]*(k+1) d[0]=None for i in range(1,k+1): d[i]=pow(k//i,n,MOD) for i in range(k,0,-1): for j in range(i*2,k+1,i): d[i]-=d[j] d[i]%=MOD ans=0 for i in range(1,k+1): ans+=d[i]*i % MOD ans %=MOD print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : double := (10)->pow(9) + 7 ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (k + 1)) ; d->first() := null ; for i : Integer.subrange(1, k + 1-1) do ( d[i+1] := (k div i)->pow(n)) ; for i : Integer.subrange(0 + 1, k)->reverse() do ( for j : Integer.subrange(i * 2, k + 1-1)->select( $x | ($x - i * 2) mod i = 0 ) do ( d[i+1] := d[i+1] - d[j+1] ; d[i+1] := d[i+1] mod MOD)) ; var ans : int := 0 ; for i : Integer.subrange(1, k + 1-1) do ( ans := ans + d[i+1] * i mod MOD ; ans := ans mod MOD) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline T=int(input()) for i in range(T): a,b,n=map(int,input().split()) n=n % 3 if n==0 : print(a) elif n==1 : print(b) else : print(a ^ b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, T-1) do ( var a : OclAny := null; var b : OclAny := null; var n : OclAny := null; Sequence{a,b,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : int := n mod 3 ; if n = 0 then ( execute (a)->display() ) else (if n = 1 then ( execute (b)->display() ) else ( execute (MathLib.bitwiseXor(a, b))->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=input ; exec(int(i())*"a,b,n=map(int,i().split());print([a,b,a^b][n%3]);") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : OclAny := input;(expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)) (trailer (arguments ( ))))))))) )))) * (expr (atom "a,b,n=map(int,i().split());print([a,b,a^b][n%3]);"))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : t=t-1 a,b,n=map(int,input().split()) l=[a,b,a ^ b] print(l[n % 3]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( t := t - 1 ; var a : OclAny := null; var b : OclAny := null; var n : OclAny := null; Sequence{a,b,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := Sequence{a}->union(Sequence{b}->union(Sequence{ MathLib.bitwiseXor(a, b) })) ; execute (l[n mod 3+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) inp=[] for _ in range(t): a,b,n=map(int,input().split(' ')) inp.append([a,b,n]) for i in range(len(inp)): a,b,n=inp[i][0],inp[i][1],inp[i][2] if n % 3==0 : print(a) elif n % 3==1 : print(b) else : print(a ^ b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var inp : Sequence := Sequence{} ; for _anon : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var n : OclAny := null; Sequence{a,b,n} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a}->union(Sequence{b}->union(Sequence{ n }))) : inp)) ; for i : Integer.subrange(0, (inp)->size()-1) do ( var a : OclAny := null; var b : OclAny := null; var n : OclAny := null; Sequence{a,b,n} := Sequence{inp[i+1]->first(),inp[i+1][1+1],inp[i+1][2+1]} ; if n mod 3 = 0 then ( execute (a)->display() ) else (if n mod 3 = 1 then ( execute (b)->display() ) else ( execute (MathLib.bitwiseXor(a, b))->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): ans=max(sum(int(c)for c in str(a**b))for a in range(100)for b in range(100)) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a))) ** (expr (atom (name b))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 100))))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 100))))))))) )))))))))))->max() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def counting_sort(A,n): k=max(A) B=[0]*n C=[0]*(k+1) for j in range(n): C[A[j]]+=1 for i in range(1,k+1): C[i]=C[i]+C[i-1] for j in range(n-1,-1,-1): B[C[A[j]]-1]=A[j] C[A[j]]-=1 return B n=int(input()) A=[int(i)for i in input().split()] print(*counting_sort(A,n),sep=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; A := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute ((argument * (test (logical_test (comparison (expr (atom (name counting_sort)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->display(); operation counting_sort(A : OclAny, n : OclAny) : OclAny pre: true post: true activity: var k : OclAny := (A)->max() ; var B : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var C : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (k + 1)) ; for j : Integer.subrange(0, n-1) do ( C[A[j+1]+1] := C[A[j+1]+1] + 1) ; for i : Integer.subrange(1, k + 1-1) do ( C[i+1] := C[i+1] + C[i - 1+1]) ; for j : Integer.subrange(-1 + 1, n - 1)->reverse() do ( B[C[A[j+1]+1] - 1+1] := A[j+1] ; C[A[j+1]+1] := C[A[j+1]+1] - 1) ; return B; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in " "*int(input()): a,b,c=map(int,input().split()); print([a,b,a ^ b][c % 3]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : StringLib.nCopies(" ", ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); execute (Sequence{a}->union(Sequence{b}->union(Sequence{ MathLib.bitwiseXor(a, b) }))[c mod 3+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def divisorSum(n): sum=0 for i in range(1,n+1): sum+=int(n/i)*i return int(sum) n=4 print(divisorSum(n)) n=5 print(divisorSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute (divisorSum(n))->display() ; n := 5 ; execute (divisorSum(n))->display(); operation divisorSum(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( sum := sum + ("" + ((n / i)))->toInteger() * i) ; return ("" + ((sum)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect,copy N=int(input()) A=list(map(int,input().split())) data=[0 for i in range(0,N+1)] for i in range(0,N): data[A[i]]+=1 X=[] for i in range(0,N+1): if data[i]!=0 : X.append(data[i]) X.sort() n=len(X) Y=copy.copy(X) for i in range(1,n): Y[i]+=Y[i-1] ans={i : 0 for i in range(0,N+1)} ans[0]=float('inf') for i in range(1,N+1): index=bisect.bisect_left(X,i+1) if index!=0 : t=Y[index-1]+(n-index)*i else : t=(n-index)*i ans[i]=t//i pointer=N i=1 while N+1>i : if ans[pointer]>=i : print(pointer) i+=1 else : pointer-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var data : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, N-1) do ( data[A[i+1]+1] := data[A[i+1]+1] + 1) ; var X : Sequence := Sequence{} ; for i : Integer.subrange(0, N + 1-1) do ( if data[i+1] /= 0 then ( execute ((data[i+1]) : X) ) else skip) ; X := X->sort() ; var n : int := (X)->size() ; var Y : OclAny := copy->copy() ; for i : Integer.subrange(1, n-1) do ( Y[i+1] := Y[i+1] + Y[i - 1+1]) ; var ans : Map := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | Map{i |-> 0})->unionAll() ; ans->first() := ("" + (('inf')))->toReal() ; for i : Integer.subrange(1, N + 1-1) do ( var index : OclAny := bisect.bisect_left(X, i + 1) ; if index /= 0 then ( var t : OclAny := Y[index - 1+1] + (n - index) * i ) else ( t := (n - index) * i ) ; ans[i+1] := t div i) ; var pointer : int := N ; var i : int := 1 ; while (N + 1->compareTo(i)) > 0 do ( if (ans[pointer+1]->compareTo(i)) >= 0 then ( execute (pointer)->display() ; i := i + 1 ) else ( pointer := pointer - 1 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def clause(e): f=True dic={} f=e.split('&') for x in f : pm,t=1,x[0] if t=='~' : pm,t=-1,x[1] if t in dic and dic[t]+pm==0 : f=False dic[t]=pm return f while True : p=input() if p=='#' : break exp=list(p.split('|')) ans=False for e in exp : if clause(e[1 :-1]): ans=True break print("yes" if ans else "no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var p : String := (OclFile["System.in"]).readLine() ; if p = '#' then ( break ) else skip ; var exp : Sequence := (p.split('|')) ; var ans : boolean := false ; for e : exp do ( if clause(e.subrange(1+1, -1)) then ( ans := true ; break ) else skip) ; execute (if ans then "yes" else "no" endif)->display()); operation clause(e : OclAny) : OclAny pre: true post: true activity: var f : boolean := true ; var dic : OclAny := Set{} ; f := e.split('&') ; for x : f do ( var pm : OclAny := null; var t : OclAny := null; Sequence{pm,t} := Sequence{1,x->first()} ; if t = '~' then ( var pm : OclAny := null; var t : OclAny := null; Sequence{pm,t} := Sequence{-1,x[1+1]} ) else skip ; if (dic)->includes(t) & dic[t+1] + pm = 0 then ( f := false ) else skip ; dic[t+1] := pm) ; return f; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter def main(): N=int(input()) A=list(map(int,input().split())) m=max(list(Counter(A).values())) d=Counter(Counter(A).values()) l=[] t=0 for i in range(m,0,-1): t+=d[i] l.append(t) l.reverse() t=0 r=[] for i in range(N): if m>i : t+=l[i] r.append(t//(i+1)) p=-1 a=[] for i,v in enumerate(reversed(r)): if p!=v : a.append((v,N-i)) p=v a.append((N,0)) t=0 aa=[] for i in range(1,N+1): if a[t][0]toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : OclAny := ((Counter(A).values()))->max() ; var d : OclAny := Counter(Counter(A).values()) ; var l : Sequence := Sequence{} ; var t : int := 0 ; for i : Integer.subrange(0 + 1, m)->reverse() do ( t := t + d[i+1] ; execute ((t) : l)) ; l := l->reverse() ; t := 0 ; var r : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( if (m->compareTo(i)) > 0 then ( t := t + l[i+1] ) else skip ; execute ((t div (i + 1)) : r)) ; var p : int := -1 ; var a : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, ((r)->reverse())->size())->collect( _indx | Sequence{_indx-1, ((r)->reverse())->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if p /= v then ( execute ((Sequence{v, N - i}) : a) ) else skip ; p := v) ; execute ((Sequence{N, 0}) : a) ; t := 0 ; var aa : Sequence := Sequence{} ; for i : Integer.subrange(1, N + 1-1) do ( if (a[t+1]->first()->compareTo(i)) < 0 then ( t := t + 1 ) else skip ; execute ((a[t+1][1+1]) : aa)) ; for i : aa do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda : sys.stdin.readline().rstrip() def bisection(l,r,f,left=True,discrete=True): eps=1 if(discrete)else 10**-8 if((not left)^ f(r)): return r if(left)else r+1 elif(left ^ f(l)): return l-1 if(left)else l while(r-l>eps): h=(l+r)//2 if(discrete)else(l+r)/2 if((not left)^ f(h)): l=h else : r=h return(l+r)/2 if(not discrete)else l if(left)else r from collections import defaultdict from bisect import bisect_left def resolve(): n=int(input()) D=defaultdict(int) for a in map(int,input().split()): D[a]+=1 D=list(D.values()) D.sort() t=len(D) S=[0]*(t+1) for i in range(t): S[i+1]=S[i]+D[i] k=0 def check(t): i=bisect_left(D,t) score=S[i]+t*(len(D)-i) return score>=k*t for k in range(1,n+1): print(bisection(0,n//k+1,check)) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(2147483647) ; var INF : double := ("" + (("inf")))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; skip ; skip ; skip ; skip ; resolve(); operation bisection(l : OclAny, r : OclAny, f : OclAny, left : OclAny, discrete : OclAny) : OclAny pre: true post: true activity: if left->oclIsUndefined() then left := true else skip; if discrete->oclIsUndefined() then discrete := true else skip; var eps : int := if (discrete) then 1 else (10)->pow(-8) endif ; if (MathLib.bitwiseXor((not(left)), f(r))) then ( return if (left) then r else r + 1 endif ) else (if (MathLib.bitwiseXor(left, f(l))) then ( return if (left) then l - 1 else l endif ) else skip) ; while ((r - l->compareTo(eps)) > 0) do ( var h : int := if (discrete) then (l + r) div 2 else (l + r) / 2 endif ; if (MathLib.bitwiseXor((not(left)), f(h))) then ( l := h ) else ( r := h )) ; return if (not(discrete)) then (l + r) / 2 else if (left) then l else r endif endif; operation resolve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var D : OclAny := defaultdict(OclType["int"]) ; for a : (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( D[a+1] := D[a+1] + 1) ; D := (D.values()) ; D := D->sort() ; var t : int := (D)->size() ; var S : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (t + 1)) ; for i : Integer.subrange(0, t-1) do ( S[i + 1+1] := S[i+1] + D[i+1]) ; var k : int := 0 ; skip ; for k : Integer.subrange(1, n + 1-1) do ( execute (bisection(0, n div k + 1, check))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque import sys,heapq,bisect,math,itertools,string,queue,copy,time sys.setrecursionlimit(10**8) INF=float('inf') mod=10**9+7 eps=10**-7 def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int,sys.stdin.readline().split())) def inpl_str(): return list(sys.stdin.readline().split()) N=inp() AA=inpl() cnts=defaultdict(int) ed=set() for a in AA : cnts[a]+=1 ed.add(a) aa1=[[i,0]for i in range(1,N+1)] for e in ed : aa1[cnts[e]-1][1]+=1 aa2=[0] aa3=[0] for t,n in aa1 : aa2.append(aa2[-1]+n) aa3.append(aa3[-1]+n*t) L=len(aa1) tmpl_t=[] tmpl_c=[] for i,(t,n)in enumerate(aa1): tmp=n+aa3[i]//t tmp+=aa2[-1]-aa2[i+1] tmpl_t.append(t) tmpl_c.append(tmp) tmpl_t.reverse() tmpl_t.append(0) tmpl_c.reverse() ans=[0]*N for i in range(1,N+1): idx=bisect.bisect_left(tmpl_c,i) if idx==0 : ans[i-1]=N//i else : ans[i-1]=tmpl_t[idx] print('\n'.join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var eps : double := (10)->pow(-7) ; skip ; skip ; skip ; var N : OclAny := inp() ; var AA : OclAny := inpl() ; var cnts : OclAny := defaultdict(OclType["int"]) ; var ed : Set := Set{}->union(()) ; for a : AA do ( cnts[a+1] := cnts[a+1] + 1 ; execute ((a) : ed)) ; var aa1 : Sequence := Integer.subrange(1, N + 1-1)->select(i | true)->collect(i | (Sequence{i}->union(Sequence{ 0 }))) ; for e : ed do ( aa1[cnts[e+1] - 1+1][1+1] := aa1[cnts[e+1] - 1+1][1+1] + 1) ; var aa2 : Sequence := Sequence{ 0 } ; var aa3 : Sequence := Sequence{ 0 } ; for _tuple : aa1 do (var _indx : int := 1; var t : OclAny := _tuple->at(_indx); _indx := _indx + 1; var n : OclAny := _tuple->at(_indx); execute ((aa2->last() + n) : aa2) ; execute ((aa3->last() + n * t) : aa3)) ; var L : int := (aa1)->size() ; var tmpl_t : Sequence := Sequence{} ; var tmpl_c : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (aa1)->size())->collect( _indx | Sequence{_indx-1, (aa1)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{t, n} : OclAny := _tuple->at(_indx); var tmp : OclAny := n + aa3[i+1] div t ; tmp := tmp + aa2->last() - aa2[i + 1+1] ; execute ((t) : tmpl_t) ; execute ((tmp) : tmpl_c)) ; tmpl_t := tmpl_t->reverse() ; execute ((0) : tmpl_t) ; tmpl_c := tmpl_c->reverse() ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for i : Integer.subrange(1, N + 1-1) do ( var idx : OclAny := bisect.bisect_left(tmpl_c, i) ; if idx = 0 then ( ans[i - 1+1] := N div i ) else ( ans[i - 1+1] := tmpl_t[idx+1] )) ; execute (StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inpl() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inpl_str() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=int(input()) from collections import Counter from itertools import accumulate As=map(int,input().split()) xs=sorted([x for x in Counter(As).values()])+[10**18] Xs=accumulate(xs) def bsearch(target,min_i,max_i,func): if func(max_i)<=target : return max_i if targetX//(k-(N-l+1))) y+=1 for i in range(y,mny): rs[i-1]=X//(i-(N-l+1)) mny=min(y,mny) for r in rs : print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; skip ; var As : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var xs : Sequence := Counter(As).values()->select(x | true)->collect(x | (x))->sort()->union(Sequence{ (10)->pow(18) }) ; var Xs : OclAny := accumulate(xs) ; skip ; var N : double := (xs)->size() - 1 ; var rs : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, I) ; var mny : OclAny := N + 1 ; for _tuple : Integer.subrange(1, (Integer.subrange(1, xs->tail()->size())->collect( _indx | Sequence{xs->tail()->at(_indx), Xs->at(_indx)} ))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(1, xs->tail()->size())->collect( _indx | Sequence{xs->tail()->at(_indx), Xs->at(_indx)} ))->at(_indx)} ) do (var _indx : int := 1; var l : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{x, X} : OclAny := _tuple->at(_indx); l := l + 2 ; var y : OclAny := bsearch(0, N - l + 2, N + 1, lambda k : OclAny in ((x->compareTo(X div (k - (N - l + 1)))) > 0)) ; y := y + 1 ; for i : Integer.subrange(y, mny-1) do ( rs[i - 1+1] := X div (i - (N - l + 1))) ; mny := Set{y, mny}->min()) ; for r : rs do ( execute (r)->display()); operation bsearch(target : OclAny, min_i : OclAny, max_i : OclAny, func : OclAny) : OclAny pre: true post: true activity: if (func(max_i)->compareTo(target)) <= 0 then ( return max_i ) else skip ; if (target->compareTo(func(min_i))) < 0 then ( return min_i - 1 ) else skip ; var index : int := (max_i + min_i) div 2 ; while true do ( if (func(index)->compareTo(target)) <= 0 then ( if (target->compareTo(func(index + 1))) < 0 then ( return index ) else skip ; Sequence{index,min_i} := Sequence{(index + 1 + max_i) div 2,index + 1} ; continue ) else skip ; Sequence{index,max_i} := Sequence{(index - 1 + min_i) div 2,index - 1}); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import itertools f=sys.stdin nhm,mkg=[map(int,f.readline().split())for _ in range(2)] n=next(nhm) m=next(mkg) goto_iimoriyama=list(zip(*[nhm]*2)) goto_turugajyo=list(zip(*[mkg]*2)) mixed=sorted(list(set(goto_iimoriyama+goto_turugajyo))) mixed=['{}:{:02d}'.format(h,m)for h,m in mixed] print(*mixed) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var f : OclFile := OclFile["System.in"] ; var nhm : OclAny := null; var mkg : OclAny := null; Sequence{nhm,mkg} := Integer.subrange(0, 2-1)->select(_anon | true)->collect(_anon | ((f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var n : OclAny := (nhm).next() ; var m : OclAny := (mkg).next() ; var goto_iimoriyama : Sequence := (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name nhm))))))) ])) * (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name nhm))))))) ])) * (expr (atom (number (integer 2)))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name nhm))))))) ])) * (expr (atom (number (integer 2)))))))))`third->at(_indx)} )) ; var goto_turugajyo : Sequence := (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name mkg))))))) ])) * (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name mkg))))))) ])) * (expr (atom (number (integer 2)))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name mkg))))))) ])) * (expr (atom (number (integer 2)))))))))`third->at(_indx)} )) ; var mixed : Sequence := (Set{}->union((goto_iimoriyama->union(goto_turugajyo))))->sort() ; mixed := mixed->select(_tuple | true)->collect(_tuple | let h : OclAny = _tuple->at(1) in let m : OclAny = _tuple->at(2) in (StringLib.interpolateStrings('{}:{:02d}', Sequence{h, m}))) ; execute ((argument * (test (logical_test (comparison (expr (atom (name mixed))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- NIn=input() N=int(NIn.split(" ")[0]) NTime=[] for i in range(N): NTime.append(int(NIn.split(" ")[(i+1)*2-1])*60+int(NIn.split(" ")[(i+1)*2])) MIn=input() M=int(MIn.split(" ")[0]) MTime=[] for i in range(M): MTime.append(int(MIn.split(" ")[(i+1)*2-1])*60+int(MIn.split(" ")[(i+1)*2])) AllTime=NTime+MTime AllTime=sorted(list(set(AllTime))) AllTime2=[] for i in range(len(AllTime)): hour=AllTime[i]//60 minute=AllTime[i]% 60 if minute<10 : AllTime2.append(str(hour)+":0"+str(minute)) else : AllTime2.append(str(hour)+":"+str(minute)) for i in range(len(AllTime2)): if i==0 : results=AllTime2[i] else : results+=" "+AllTime2[i] print(results) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var NIn : String := (OclFile["System.in"]).readLine() ; var N : int := ("" + ((NIn.split(" ")->first())))->toInteger() ; var NTime : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute ((("" + ((NIn.split(" ")[(i + 1) * 2 - 1+1])))->toInteger() * 60 + ("" + ((NIn.split(" ")[(i + 1) * 2+1])))->toInteger()) : NTime)) ; var MIn : String := (OclFile["System.in"]).readLine() ; var M : int := ("" + ((MIn.split(" ")->first())))->toInteger() ; var MTime : Sequence := Sequence{} ; for i : Integer.subrange(0, M-1) do ( execute ((("" + ((MIn.split(" ")[(i + 1) * 2 - 1+1])))->toInteger() * 60 + ("" + ((MIn.split(" ")[(i + 1) * 2+1])))->toInteger()) : MTime)) ; var AllTime : Sequence := NTime->union(MTime) ; AllTime := (Set{}->union((AllTime)))->sort() ; var AllTime2 : Sequence := Sequence{} ; for i : Integer.subrange(0, (AllTime)->size()-1) do ( var hour : int := AllTime[i+1] div 60 ; var minute : int := AllTime[i+1] mod 60 ; if minute < 10 then ( execute ((("" + ((hour))) + ":0" + ("" + ((minute)))) : AllTime2) ) else ( execute ((("" + ((hour))) + ":" + ("" + ((minute)))) : AllTime2) )) ; for i : Integer.subrange(0, (AllTime2)->size()-1) do ( if i = 0 then ( var results : OclAny := AllTime2[i+1] ) else ( results := results + " " + AllTime2[i+1] )) ; execute (results)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : import sys input=sys.stdin.readline n=int(input()) A=[None]+list(map(int,input().split())) B=[None]*(n+1) C=[0]*10001 k=10000 for j in range(n): C[A[j+1]]+=1 for i in range(1,k+1): C[i]+=C[i-1] for j in range(1,n+1): B[C[A[j]]]=A[j] C[A[j]]-=1 print(' '.join(map(str,B[1 :]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := Sequence{ null }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var B : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (n + 1)) ; var C : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10001) ; var k : int := 10000 ; for j : Integer.subrange(0, n-1) do ( C[A[j + 1+1]+1] := C[A[j + 1+1]+1] + 1) ; for i : Integer.subrange(1, k + 1-1) do ( C[i+1] := C[i+1] + C[i - 1+1]) ; for j : Integer.subrange(1, n + 1-1) do ( B[C[A[j+1]+1]+1] := A[j+1] ; C[A[j+1]+1] := C[A[j+1]+1] - 1) ; execute (StringLib.sumStringsWithSeparator(((B->tail())->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Bustime : h=0 mm=0 t=0 def __init__(self,h,mm): self.h=h self.mm=mm self.t=h*60+mm def __str__(self): if self.mm<10 : return str(self.h)+":0"+str(self.mm) else : return str(self.h)+":"+str(self.mm) def __lt__(self,other): return self.texists( _x | result = _x ); static attribute h : int := 0; static attribute mm : int := 0; static attribute t : int := 0; attribute h : int := h; attribute mm : int := mm; attribute t : int := h * 60 + mm; operation initialise(h : OclAny,mm : OclAny) : Bustime pre: true post: true activity: self.h := h ; self.mm := mm ; self.t := h * 60 + mm; return self; operation __str__() : OclAny pre: true post: true activity: if self.mm < 10 then ( return ("" + ((self.h))) + ":0" + ("" + ((self.mm))) ) else ( return ("" + ((self.h))) + ":" + ("" + ((self.mm))) ); operation __lt__(other : OclAny) : OclAny pre: true post: true activity: return (self.t->compareTo(other.t)) < 0; } class FromPython { operation initialise() pre: true post: true activity: skip ; var line1 : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var line2 : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var times : Sequence := Sequence{} ; for i : Integer.subrange(0, line1->first()-1) do ( execute (((Bustime.newBustime()).initialise(line1[2 * i + 1+1], line1[2 * i + 2+1])) : times)) ; for i : Integer.subrange(0, line2->first()-1) do ( execute (((Bustime.newBustime()).initialise(line2[2 * i + 1+1], line2[2 * i + 2+1])) : times)) ; times := times->sort() ; var prev : String := "" ; var flag : boolean := true ; for i : Integer.subrange(0, (times)->size()-1) do ( if prev /= ("" + ((times[i+1]))) then ( if flag then ( execute (times[i+1])->display() ; flag := false ) else ( execute ("" + ("" + ((times[i+1]))))->display() ) ) else skip ; prev := ("" + ((times[i+1])))) ; execute ("")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(): n_s=list(map(int,input().split())) m_s=list(map(int,input().split())) timetable={} for h,m in zip(n_s[1 : : 2],n_s[2 : : 2]): timetable['{0:2d}:{1:02d}'.format(h,m)]='{0}:{1:02d}'.format(h,m) for k,g in zip(m_s[1 : : 2],m_s[2 : : 2]): timetable['{0:2d}:{1:02d}'.format(k,g)]='{0}:{1:02d}'.format(k,g) keys=list(timetable.keys()) keys.sort() print(" ".join([timetable[key]for key in keys])) return 0 if __name__=='__main__' : sys.exit(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( sys.exit(main()) ) else skip; operation main() : OclAny pre: true post: true activity: var n_s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m_s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var timetable : OclAny := Set{} ; for _tuple : Integer.subrange(1, n_s(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{n_s(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->at(_indx), n_s(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->at(_indx)} ) do (var _indx : int := 1; var h : OclAny := _tuple->at(_indx); _indx := _indx + 1; var m : OclAny := _tuple->at(_indx); timetable[StringLib.interpolateStrings('{0:2d}:{1:02d}', Sequence{h, m})+1] := StringLib.interpolateStrings('{0}:{1:02d}', Sequence{h, m})) ; for _tuple : Integer.subrange(1, m_s(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{m_s(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->at(_indx), m_s(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->at(_indx)} ) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var g : OclAny := _tuple->at(_indx); timetable[StringLib.interpolateStrings('{0:2d}:{1:02d}', Sequence{k, g})+1] := StringLib.interpolateStrings('{0}:{1:02d}', Sequence{k, g})) ; var keys : Sequence := (timetable.keys()) ; keys := keys->sort() ; execute (StringLib.sumStringsWithSeparator((keys->select(key | true)->collect(key | (timetable[key+1]))), " "))->display() ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s1=list(map(int,input().split())) s2=list(map(int,input().split())) agg=set() for i in range(s1[0]): agg.add(tuple(s1[i*2+1 : i*2+3])) for i in range(s2[0]): agg.add(tuple(s2[i*2+1 : i*2+3])) agg=list(agg) agg.sort() print(*list(map(lambda t : str(t[0])+":"+str(t[1]).zfill(2),agg))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var agg : Set := Set{}->union(()) ; for i : Integer.subrange(0, s1->first()-1) do ( execute (((s1.subrange(i * 2 + 1+1, i * 2 + 3))) : agg)) ; for i : Integer.subrange(0, s2->first()-1) do ( execute (((s2.subrange(i * 2 + 1+1, i * 2 + 3))) : agg)) ; agg := (agg) ; agg := agg->sort() ; execute ((argument * (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test lambda (varargslist (vardef_parameters (vardef_parameter (name t)))) : (test (logical_test (comparison (expr (expr (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))) + (expr (atom ":"))) + (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ))) (trailer . (name zfill) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))))))))) , (argument (test (logical_test (comparison (expr (atom (name agg)))))))) ))))))))) )))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=[-1]+[int(input())for _ in range(N)] count=-1 for i in range(N,0,-1): if A[i]-1>A[i-1]: print(-1) exit() elif A[i]-1==A[i-1]: count+=1 else : count+=A[i] print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := Sequence{ -1 }->union(Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))) ; var count : int := -1 ; for i : Integer.subrange(0 + 1, N)->reverse() do ( if (A[i+1] - 1->compareTo(A[i - 1+1])) > 0 then ( execute (-1)->display() ; exit() ) else (if A[i+1] - 1 = A[i - 1+1] then ( count := count + 1 ) else ( count := count + A[i+1] ) ) ) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : s=input().strip() if s=='#' : break clauses=s.split('|') for clause in clauses : literals=clause[1 :-1].split('&') ntil=clause.count('~') if ntil==0 or ntil==3 : print('yes') break if ntil==1 : x=[v[1]for v in literals if v[0]=='~'][0] if clause.count(x)==1 : print('yes') break if ntil==2 : x=[v for v in literals if len(v)==1][0] if clause.count(x)==1 : print('yes') break else : print('no') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var s : OclAny := input()->trim() ; if s = '#' then ( break ) else skip ; var clauses : OclAny := s.split('|') ; (compound_stmt for (exprlist (expr (atom (name clause)))) in (testlist (test (logical_test (comparison (expr (atom (name clauses))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name literals)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name clause)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '&'))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ntil)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name clause)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '~'))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name ntil)))) == (comparison (expr (atom (number (integer 0))))))) or (logical_test (comparison (comparison (expr (atom (name ntil)))) == (comparison (expr (atom (number (integer 3))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'yes'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name ntil)))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))) (comp_for for (exprlist (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name literals))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) == (comparison (expr (atom '~'))))))))) ]) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name clause)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'yes'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name ntil)))) == (comparison (expr (atom (number (integer 2)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name v)))))) (comp_for for (exprlist (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name literals))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) ))))) == (comparison (expr (atom (number (integer 1))))))))))) ]) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name clause)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'yes'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'no'))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**8) ini=lambda : int(sys.stdin.readline()) inm=lambda : map(int,sys.stdin.readline().split()) inl=lambda : list(inm()) ins=lambda : sys.stdin.readline().rstrip() debug=lambda*a,**kw : print(*a,**dict(file=sys.stderr,**kw)) N=ini() A=[ini()for _ in range(N)] def solve(): c=0 ans=0 for i in range(N-1,-1,-1): s=A[i] if s>i : return-1 if sc : ans+=s c=s-1 return ans print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(8)) ; var ini : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var inm : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var inl : Function := lambda $$ : OclAny in ((inm->apply())) ; var ins : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var debug : Function := lambda a : Sequence(OclAny), kw : Map(String, OclAny) in (((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display()) ; var N : OclAny := ini->apply() ; var A : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (ini->apply())) ; skip ; execute (solve())->display(); operation solve() : OclAny pre: true post: true activity: var c : int := 0 ; var ans : int := 0 ; for i : Integer.subrange(-1 + 1, N - 1)->reverse() do ( var s : OclAny := A[i+1] ; if (s->compareTo(i)) > 0 then ( return -1 ) else skip ; if (s->compareTo(c)) < 0 then ( return -1 ) else skip ; if (s->compareTo(c)) > 0 then ( ans := ans + s ) else skip ; c := s - 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,tan,asin,acos,atan,radians,degrees,log2,gcd from itertools import accumulate,permutations,combinations,combinations_with_replacement,product,groupby from operator import itemgetter,mul from copy import deepcopy from string import ascii_lowercase,ascii_uppercase,digits from bisect import bisect,bisect_left,insort,insort_left from heapq import heappush,heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) def TUPLE(): return tuple(map(int,input().split())) def ZIP(n): return zip(*(MAP()for _ in range(n))) sys.setrecursionlimit(10**9) INF=float('inf') mod=10**9+7 from decimal import* N=INT() A=[INT()for _ in range(N)] ans=0 tmp=A[0] for i,a in enumerate(A): if ipow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; skip ; var N : OclAny := INT() ; var A : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (INT())) ; var ans : int := 0 ; var tmp : OclAny := A->first() ; (compound_stmt for (exprlist (expr (atom (name i))) , (expr (atom (name a)))) in (testlist (test (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name i)))) < (comparison (expr (atom (name a)))))) or (logical_test (comparison (comparison (expr (expr (atom (name tmp))) + (expr (atom (number (integer 1)))))) < (comparison (expr (atom (name a)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name a)))) != (comparison (expr (expr (atom (name tmp))) + (expr (atom (number (integer 1))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name tmp)))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name tmp)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name a))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name tmp))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))))))))); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation TUPLE() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ZIP(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))`third->at(_indx)} ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=0 now=int(input()) if now!=0 : print(-1) exit() zero=0 for i in range(n-1): a=int(input()) if a==now+1 : ans+=1 now=a elif a<=now : ans+=a zero=i-a now=a elif a>=now+2 : print(-1) exit() print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; var now : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if now /= 0 then ( execute (-1)->display() ; exit() ) else skip ; var zero : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if a = now + 1 then ( ans := ans + 1 ; now := a ) else (if (a->compareTo(now)) <= 0 then ( ans := ans + a ; zero := i - a ; now := a ) else (if (a->compareTo(now + 2)) >= 0 then ( execute (-1)->display() ; exit() ) else skip ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) alst=[int(input())for i in range(n)] flag=0 ans=0 temp=-1 ind=0 while ind1 : flag=1 break while ind+1toInteger() ; var alst : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var flag : int := 0 ; var ans : int := 0 ; var temp : int := -1 ; var ind : int := 0 ; while (ind->compareTo(n)) < 0 do ( var a : OclAny := alst[ind+1] ; if a - temp > 1 then ( flag := 1 ; break ) else skip ; while (ind + 1->compareTo(n)) < 0 & alst[ind + 1+1] = a + 1 do ( ind := ind + 1 ; a := alst[ind+1]) ; ans := ans + a ; temp := a ; ind := ind + 1) ; if not(flag) then ( execute (ans)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): days_in_month=[31,28,31,30,31,30,31,31,30,31,30,31] month2day={} cnt=0 for i in range(9,12+1): for j in range(1,days_in_month[i-1]+1): month2day[(i,j,12)]=cnt cnt+=1 for i in range(1,12+1): for j in range(1,days_in_month[i-1]+1): month2day[(i,j,13)]=cnt cnt+=1 with open('input.txt')as f : test=f.readlines() n=int(test[0].strip()) days=[0]*len(month2day) for i in range(1,n+1): m,d,p,t=map(int,test[i].strip().split()) R=month2day[(m,d,13)]-1 L=R-t+1 days[L]+=p days[R+1]-=p acc=[days[0]] for i in range(1,len(days)): acc.append(acc[-1]+days[i]) with open('output.txt','w')as f : f.write(str(max(acc))) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var days_in_month : Sequence := Sequence{31}->union(Sequence{28}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{ 31 }))))))))))) ; var month2day : OclAny := Set{} ; var cnt : int := 0 ; for i : Integer.subrange(9, 12 + 1-1) do ( for j : Integer.subrange(1, days_in_month[i - 1+1] + 1-1) do ( month2day[Sequence{i, j, 12}+1] := cnt ; cnt := cnt + 1)) ; for i : Integer.subrange(1, 12 + 1-1) do ( for j : Integer.subrange(1, days_in_month[i - 1+1] + 1-1) do ( month2day[Sequence{i, j, 13}+1] := cnt ; cnt := cnt + 1)) ; try (var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('input.txt')); var test : String := f.readlines()) catch (_e : OclException) do skip ; var n : int := ("" + ((test->first()->trim())))->toInteger() ; var days : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (month2day)->size()) ; for i : Integer.subrange(1, n + 1-1) do ( var m : OclAny := null; var d : OclAny := null; var p : OclAny := null; var t : OclAny := null; Sequence{m,d,p,t} := (test[i+1]->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var R : double := month2day[Sequence{m, d, 13}+1] - 1 ; var L : double := R - t + 1 ; days[L+1] := days[L+1] + p ; days[R + 1+1] := days[R + 1+1] - p) ; var acc : Sequence := Sequence{ days->first() } ; for i : Integer.subrange(1, (days)->size()-1) do ( execute ((acc->last() + days[i+1]) : acc)) ; try (var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('output.txt')); f.write(("" + (((acc)->max()))))) catch (_e : OclException) do skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- maxx=2000001 ; maxnum=10010 ; n=int(input()) A=[int(x)for x in input().split()] A.insert(0,0) B=[-1 for x in range(n)] C=[0 for x in range(maxnum)] for a in A[1 :]: C[a]+=1 for i in range(1,maxnum): C[i]+=C[i-1] for j in range(1,n+1): B[C[A[j]]-1]=A[j] C[A[j]]-=1 lens=len(B) for i in range(0,lens-1): print(B[i],end=' ') print(B[lens-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var maxx : int := 2000001; ; var maxnum : int := 10010; ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; A := A.insertAt(0+1, 0) ; var B : Sequence := Integer.subrange(0, n-1)->select(x | true)->collect(x | (-1)) ; var C : Sequence := Integer.subrange(0, maxnum-1)->select(x | true)->collect(x | (0)) ; for a : A->tail() do ( C[a+1] := C[a+1] + 1) ; for i : Integer.subrange(1, maxnum-1) do ( C[i+1] := C[i+1] + C[i - 1+1]) ; for j : Integer.subrange(1, n + 1-1) do ( B[C[A[j+1]+1] - 1+1] := A[j+1] ; C[A[j+1]+1] := C[A[j+1]+1] - 1) ; var lens : int := (B)->size() ; for i : Integer.subrange(0, lens - 1-1) do ( execute (B[i+1])->display()) ; execute (B[lens - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def getMaxJuries(juries,m,d,t,months): year=1 res=0 while(t>0): if(d<0): m-=1 if(m<0): m+=12 year=0 d=months[m]-1 res=max(res,juries[year][m][d]) d-=1 t-=1 return res def setJury(juries,m,d,t,months,p): year=1 while(t>0): if(d<0): m-=1 if(m<0): m+=12 year=0 d=months[m]-1 juries[year][m][d]+=p d-=1 t-=1 if __name__=='__main__' : sys.stdin=open('input.txt','r') sys.stdout=open('output.txt','w') months=[31,28,31,30,31,30,31,31,30,31,30,31] n=int(input()) juriesNumber=0 juries=[[[0 for i in range(31)]for j in range(12)]for _ in range(2)] for i in range(n): m,d,p,t=[int(x)for x in input().split()] m-=1 d-=2 maxJuries=getMaxJuries(juries,m,d,t,months) if(maxJuries+p>juriesNumber): juriesNumber+=((maxJuries+p)-juriesNumber) setJury(juries,m,d,t,months,p) print(juriesNumber) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('input.txt')) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile('output.txt')) ; months := Sequence{31}->union(Sequence{28}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{ 31 }))))))))))) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var juriesNumber : int := 0 ; juries := Integer.subrange(0, 2-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, 12-1)->select(j | true)->collect(j | (Integer.subrange(0, 31-1)->select(i | true)->collect(i | (0)))))) ; for i : Integer.subrange(0, n-1) do ( Sequence{m,d,p,t} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; m := m - 1 ; d := d - 2 ; var maxJuries : OclAny := getMaxJuries(juries, m, d, t, months) ; if ((maxJuries + p->compareTo(juriesNumber)) > 0) then ( juriesNumber := juriesNumber + ((maxJuries + p) - juriesNumber) ) else skip ; setJury(juries, m, d, t, months, p)) ; execute (juriesNumber)->display() ) else skip; operation getMaxJuries(juries : OclAny, m : OclAny, d : OclAny, t : OclAny, months : OclAny) : OclAny pre: true post: true activity: var year : int := 1 ; var res : int := 0 ; while (t > 0) do ( if (d < 0) then ( m := m - 1 ; if (m < 0) then ( m := m + 12 ; year := 0 ) else skip ; d := months[m+1] - 1 ) else skip ; res := Set{res, juries[year+1][m+1][d+1]}->max() ; d := d - 1 ; t := t - 1) ; return res; operation setJury(juries : OclAny, m : OclAny, d : OclAny, t : OclAny, months : OclAny, p : OclAny) pre: true post: true activity: year := 1 ; while (t > 0) do ( if (d < 0) then ( m := m - 1 ; if (m < 0) then ( m := m + 12 ; year := 0 ) else skip ; d := months[m+1] - 1 ) else skip ; juries[year+1][m+1][d+1] := juries[year+1][m+1][d+1] + p ; d := d - 1 ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- fin=open("input.txt","r") fout=open("output.txt","w") mon=[0,31,28,31,30,31,30,31,31,30,31,30,31] ans=[0]*500 ba=[] for i in range(int(fin.readline())): m,d,p,t=map(int,fin.readline().split()) ba.append([m,d,p,t]) for i in ba : days=sum(mon[: i[0]])+i[1]+100 for j in range(1,i[3]+1): ans[days-j]+=i[2] print(max(ans),file=fout) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var fin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ; var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ; var mon : Sequence := Sequence{0}->union(Sequence{31}->union(Sequence{28}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{ 31 })))))))))))) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 500) ; var ba : Sequence := Sequence{} ; for i : Integer.subrange(0, ("" + ((fin.readLine())))->toInteger()-1) do ( var m : OclAny := null; var d : OclAny := null; var p : OclAny := null; var t : OclAny := null; Sequence{m,d,p,t} := (fin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{m}->union(Sequence{d}->union(Sequence{p}->union(Sequence{ t })))) : ba)) ; for i : ba do ( var days : OclAny := (mon.subrange(1,i->first()))->sum() + i[1+1] + 100 ; for j : Integer.subrange(1, i[3+1] + 1-1) do ( ans[days - j+1] := ans[days - j+1] + i[2+1])) ; execute ((ans)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w=open('output.txt','w') r=open('input.txt','r') arr=[31,28,31,30,31,30,31,31,30,31,30,31] def get_date(m,d): res=0 for i in range(m-1): res+=arr[i] return res+d n=int(r.readline()) used=[0]*366 for i in range(n): m,d,p,t=map(int,r.readline().split()) date=get_date(m,d) for i in range(max(0,date-t),date): used[i]+=p w.write(str(max(used))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('output.txt')) ; var r : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('input.txt')) ; var arr : Sequence := Sequence{31}->union(Sequence{28}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{ 31 }))))))))))) ; skip ; var n : int := ("" + ((r.readLine())))->toInteger() ; var used : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 366) ; for i : Integer.subrange(0, n-1) do ( var p : OclAny := null; var t : OclAny := null; Sequence{m,d,p,t} := (r.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var date : OclAny := get_date(m, d) ; for i : Integer.subrange(Set{0, date - t}->max(), date-1) do ( used[i+1] := used[i+1] + p)) ; w.write(("" + (((used)->max())))); operation get_date(m : OclAny, d : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; for i : Integer.subrange(0, m - 1-1) do ( res := res + arr[i+1]) ; return res + d; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w=open('output.txt','w') r=open('input.txt','r') s=[0]*466 y=[0,100,131,159,190,220,251,281,312,343,373,404,434] n=int(r.readline()) for i in range(n): m,d,p,t=map(int,r.readline().split()) x=y[m]+d s[x]-=p s[x-t]+=p for i in range(465): s[i+1]+=s[i] w.write(str(max(s))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('output.txt')) ; var r : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('input.txt')) ; var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 466) ; var y : Sequence := Sequence{0}->union(Sequence{100}->union(Sequence{131}->union(Sequence{159}->union(Sequence{190}->union(Sequence{220}->union(Sequence{251}->union(Sequence{281}->union(Sequence{312}->union(Sequence{343}->union(Sequence{373}->union(Sequence{404}->union(Sequence{ 434 })))))))))))) ; var n : int := ("" + ((r.readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var m : OclAny := null; var d : OclAny := null; var p : OclAny := null; var t : OclAny := null; Sequence{m,d,p,t} := (r.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := y[m+1] + d ; s[x+1] := s[x+1] - p ; s[x - t+1] := s[x - t+1] + p) ; for i : Integer.subrange(0, 465-1) do ( s[i + 1+1] := s[i + 1+1] + s[i+1]) ; w.write(("" + (((s)->max())))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isOsiris(n): a=n % 10 b=(n//10)% 10 c=n//100 digit_sum=a+b+c if(n==(2*(digit_sum)*11)): return True return False if __name__=='__main__' : n=132 if isOsiris(n): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 132 ; if isOsiris(n) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isOsiris(n : OclAny) : OclAny pre: true post: true activity: var a : int := n mod 10 ; var b : int := (n div 10) mod 10 ; var c : int := n div 100 ; var digit_sum : int := a + b + c ; if (n = (2 * (digit_sum) * 11)) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def expr(): global cur while curdisplay(); operation expr() : OclAny pre: true post: true activity: skip ; while (cur->compareTo((S)->size())) < 0 do ( cur := cur + 1 ; if clause() then ( return 1 ) else skip ; cur := cur + 2) ; return 0; operation clause() : OclAny pre: true post: true activity: var R : Sequence := Sequence{} ; skip ; execute ((literal()) : R) ; cur := cur + 1 ; execute ((literal()) : R) ; cur := cur + 1 ; execute ((literal()) : R) ; return check(R); operation literal() : OclAny pre: true post: true activity: skip ; if S[cur+1] = '~' then ( var r : OclAny := S.subrange(cur+1, cur + 2) ; cur := cur + 2 ) else ( r := S[cur+1] ; cur := cur + 1 ) ; return r; operation check(R : OclAny) : OclAny pre: true post: true activity: for l0 : R do ( if (l0)->size() = 1 then ( for l1 : R do ( if (l1)->size() = 2 & l1[1+1] = l0 then ( return 0 ) else skip) ) else skip) ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) v=sorted(list(map(int,input().split()))) sam=v[0] for i in range(1,N): sam=(sam+v[i])/2 print(sam) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var v : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var sam : OclAny := v->first() ; for i : Integer.subrange(1, N-1) do ( sam := (sam + v[i+1]) / 2) ; execute (sam)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import decimal n=int(input()) arr=list(map(decimal.Decimal,input().split())) arr.sort() while len(arr)>1 : s=decimal.Decimal(0) s+=arr.pop(0) s+=arr.pop(0) arr.append(s/2) arr.sort() print(arr[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (decimal.Decimal)->apply(_x) )) ; arr := arr->sort() ; while (arr)->size() > 1 do ( var s : OclAny := decimal.Decimal(0) ; s := s + arr->at(0`firstArg+1) ; arr := arr->excludingAt(0+1) ; s := s + arr->at(0`firstArg+1) ; arr := arr->excludingAt(0+1) ; execute ((s / 2) : arr) ; arr := arr->sort()) ; execute (arr->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(N : int,v : "List[int]"): v.sort() ans=(v[0]+v[1])/2 for i in range(2,N): ans=(ans+v[i])/2 print(ans) return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() N=int(next(tokens)) v=[int(next(tokens))for _ in range(N)] solve(N,v) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(N : int, v : "List[int]") pre: true post: true activity: v := v->sort() ; var ans : double := (v->first() + v[1+1]) / 2 ; for i : Integer.subrange(2, N-1) do ( ans := (ans + v[i+1]) / 2) ; execute (ans)->display() ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var N : int := ("" + (((tokens).next())))->toInteger() ; var v : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((tokens).next())))->toInteger())) ; solve(N, v); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from collections import defaultdict sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod=10**9+7 def I(): return int(input()) def II(): return map(int,input().split()) def III(): return list(map(int,input().split())) def Line(N): read_all=[tuple(map(int,input().split()))for _ in range(N)] return map(list,zip(*read_all)) N=I() v=III() v.sort() ans=(v[0]+v[1])/2 for i in range(2,N): ans=(ans+v[i])/2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; N := I() ; var v : OclAny := III() ; v := v->sort() ; var ans : double := (v->first() + v[1+1]) / 2 ; for i : Integer.subrange(2, N-1) do ( ans := (ans + v[i+1]) / 2) ; execute (ans)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation II() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation III() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation Line(N : OclAny) : OclAny pre: true post: true activity: var read_all : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; return (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name read_all)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name read_all)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name read_all)))))))`third->at(_indx)} ))->collect( _x | (OclType["Sequence"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def count_sort(A,n,k): C=[0 for i in range(k+1)] B=[None for i in range(n)] for val in A : C[val]+=1 C[0]-=1 for i in range(1,k+1): C[i]+=C[i-1] for i in range(n-1,-1,-1): val=A[i] B[C[val]]=val C[val]-=1 print(' '.join(map(str,B))) MAX_NUM=10000 n=int(sys.stdin.readline()) A=list(map(int,sys.stdin.readline().split())) count_sort(A,n,MAX_NUM) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var MAX_NUM : int := 10000 ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; A := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; count_sort(A, n, MAX_NUM); operation count_sort(A : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var C : Sequence := Integer.subrange(0, k + 1-1)->select(i | true)->collect(i | (0)) ; var B : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; for val : A do ( C[val+1] := C[val+1] + 1) ; C->first() := C->first() - 1 ; for i : Integer.subrange(1, k + 1-1) do ( C[i+1] := C[i+1] + C[i - 1+1]) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( var val : OclAny := A[i+1] ; B[C[val+1]+1] := val ; C[val+1] := C[val+1] - 1) ; execute (StringLib.sumStringsWithSeparator(((B)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) v_list=list(map(int,input().split())) v_list_s=sorted(v_list,reverse=True) while True : if len(v_list_s)<=1 : break temp_c=(v_list_s[-1]+v_list_s[-2])/2 v_list_s.remove(v_list_s[-1]) v_list_s.remove(v_list_s[-1]) v_list_s.append(temp_c) print(sorted(v_list_s)[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var v_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var v_list_s : Sequence := v_list->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; while true do ( if (v_list_s)->size() <= 1 then ( break ) else skip ; var temp_c : double := (v_list_s->last() + v_list_s->front()->last()) / 2 ; execute ((v_list_s->last()) /: v_list_s) ; execute ((v_list_s->last()) /: v_list_s) ; execute ((temp_c) : v_list_s)) ; execute (sorted(v_list_s)->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nCr(n,r): ans=1 ; for i in range(1,r+1): ans*=(n-r+i); ans//=i ; return ans ; def total_ways(N,X): return(nCr(N-1,X-1)+nCr(N-1,X)); if __name__=="__main__" : N=5 ; X=3 ; print(total_ways(N,X)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( N := 5; X := 3; ; execute (total_ways(N, X))->display(); ) else skip; operation nCr(n : OclAny, r : OclAny) pre: true post: true activity: var ans : int := 1; ; for i : Integer.subrange(1, r + 1-1) do ( ans := ans * (n - r + i); ; ans := ans div i;) ; return ans;; operation total_ways(N : OclAny, X : OclAny) pre: true post: true activity: return (nCr(N - 1, X - 1) + nCr(N - 1, X));; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def submatrixXor(arr,n): ans=0 for i in range(0,n): for j in range(0,n): top_left=(i+1)*(j+1) bottom_right=(n-i)*(n-j) if(top_left % 2==1 and bottom_right % 2==1): ans=(ans ^ arr[i][j]) return ans n=3 arr=[[6,7,13],[8,3,4],[9,7,6]] print(submatrixXor(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3 ; arr := Sequence{Sequence{6}->union(Sequence{7}->union(Sequence{ 13 }))}->union(Sequence{Sequence{8}->union(Sequence{3}->union(Sequence{ 4 }))}->union(Sequence{ Sequence{9}->union(Sequence{7}->union(Sequence{ 6 })) })) ; execute (submatrixXor(arr, n))->display(); operation submatrixXor(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( var top_left : double := (i + 1) * (j + 1) ; var bottom_right : double := (n - i) * (n - j) ; if (top_left mod 2 = 1 & bottom_right mod 2 = 1) then ( ans := (MathLib.bitwiseXor(ans, arr[i+1][j+1])) ) else skip)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def minimumColors(N,E,U,V): adj=[[]for i in range(N)] count=[0]*N colors=[1]*(N) for i in range(N): adj[V[i]-1].append(U[i]-1) count[U[i]-1]+=1 Q=deque() for i in range(N): if(count[i]==0): Q.append(i) while len(Q)>0 : u=Q.popleft() for x in adj[u]: count[x]-=1 if(count[x]==0): Q.append(x) if(colors[x]<=colors[u]): colors[x]=1+colors[u] minColor=-1 for i in range(N): minColor=max(minColor,colors[i]) print(minColor) N=5 E=6 U=[1,2,3,1,2,3] V=[3,3,4,4,5,5] minimumColors(N,E,U,V) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; N := 5 ; E := 6 ; U := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))))) ; V := Sequence{3}->union(Sequence{3}->union(Sequence{4}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 5 }))))) ; minimumColors(N, E, U, V); operation minimumColors(N : OclAny, E : OclAny, U : OclAny, V : OclAny) pre: true post: true activity: var adj : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{})) ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var colors : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (N)) ; for i : Integer.subrange(0, N-1) do ((expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name V)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name U)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (number (integer 1)))))))))) )))) ; count[U[i+1] - 1+1] := count[U[i+1] - 1+1] + 1) ; var Q : Sequence := () ; for i : Integer.subrange(0, N-1) do ( if (count[i+1] = 0) then ( execute ((i) : Q) ) else skip) ; while (Q)->size() > 0 do ( var u : OclAny := Q->first() ; Q := Q->tail() ; for x : adj[u+1] do ( count[x+1] := count[x+1] - 1 ; if (count[x+1] = 0) then ( execute ((x) : Q) ) else skip ; if ((colors[x+1]->compareTo(colors[u+1])) <= 0) then ( colors[x+1] := 1 + colors[u+1] ) else skip)) ; var minColor : int := -1 ; for i : Integer.subrange(0, N-1) do ( minColor := Set{minColor, colors[i+1]}->max()) ; execute (minColor)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) A=[list(map(int,list('{:020b}'.format(a))))for a in map(int,input().split())] ans=0 R=-1 X=[0]*20 for L in range(n): if RtoInteger() ; var A : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->select(a | true)->collect(a | ((((StringLib.interpolateStrings('{:020b}', Sequence{a}))->characters())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ans : int := 0 ; var R : int := -1 ; var X : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 20) ; for L : Integer.subrange(0, n-1) do ( if (R->compareTo(L)) < 0 then ( R := R + 1 ; for i : Integer.subrange(0, 20-1) do ( X[i+1] := X[i+1] + A[R+1][i+1]) ) else skip ; while (R + 1->compareTo(n)) < 0 & ((argument (test (logical_test (comparison (comparison (expr (expr (atom (name x))) + (expr (atom (name y))))) != (comparison (expr (atom (number (integer 2)))))))) (comp_for for (exprlist (expr (atom (name x))) , (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name X))))))) , (argument (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name R))) + (expr (atom (number (integer 1)))))))))) ])))))))) )))))))))->forAll( _x | _x = true ) do ( for i : Integer.subrange(0, 20-1) do ( X[i+1] := X[i+1] + A[R + 1+1][i+1]) ; R := R + 1) ; ans := ans + R - L + 1 ; for i : Integer.subrange(0, 20-1) do ( X[i+1] := X[i+1] - A[L+1][i+1])) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def examD(): N=I() A=LI() ans=0 ; l=0 ; r=0 cur=0 while lpow(9) + 7 ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; examD(); operation examD() pre: true post: true activity: var N : OclAny := I() ; var A : OclAny := LI() ; var ans : int := 0; var l : int := 0; var r : int := 0 ; var cur : int := 0 ; while (l->compareTo(N)) < 0 do ( while (r->compareTo(N)) < 0 do ( if MathLib.bitwiseAnd(cur, A[r+1]) = 0 then ( cur := cur + A[r+1] ; ans := ans + (r - l + 1) ) else ( break ) ; r := r + 1) ; cur := cur xor A[l+1] ; l := l + 1) ; execute (ans)->display(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LSI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["String"])->apply(_x) )); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation SI() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : s=input() if s=='#' : break ans=False clauses=s.split('|') for cla in clauses : clause=cla[1 :-1] c=clause.split('&') tmp=True for ele in c : tmp &=not('-'+ele if len(ele)==1 else ele[-1])in c ans |=tmp print("yes" if ans else "no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var s : String := (OclFile["System.in"]).readLine() ; if s = '#' then ( break ) else skip ; var ans : boolean := false ; var clauses : OclAny := s.split('|') ; for cla : clauses do ( var clause : OclAny := cla.subrange(1+1, -1) ; var c : OclAny := clause.split('&') ; var tmp : boolean := true ; for ele : c do ( tmp := tmp & not((c)->includes((if (ele)->size() = 1 then '-' + ele else ele->last() endif)))) ; ans := ans or tmp) ; execute (if ans then "yes" else "no" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.readline def read_ints(): return list(map(int,read().split())) class CumSum1d : def __init__(self,ls : list): from itertools import accumulate self.ls_accum=[0]+list(accumulate(ls)) def total(self,i,j): return self.ls_accum[j]-self.ls_accum[i] class CumXor1d : def __init__(self,ls : list): self.ls_accum=[0] for l in ls : self.ls_accum.append(l ^ self.ls_accum[-1]) def total(self,i,j): return self.ls_accum[j]^ self.ls_accum[i] from collections import deque N=int(input()) A=read_ints() cumsum=CumSum1d(A) cumxor=CumXor1d(A) ids=[] r_pre=0 for l in range(0,N): r=max(r_pre,l+1) while r<=N and cumsum.total(l,r)==cumxor.total(l,r): r+=1 r-=1 if r!=r_pre : r_pre=r ids.append((l,r)) ans=0 for l,r in ids : n=r-l ans+=n+n*(n-1)//2 if len(ids)>1 : for(_,r),(l,_)in zip(ids,ids[1 :]): n=max(0,r-l) ans-=n+n*(n-1)//2 print(ans) ------------------------------------------------------------ OCL File: --------- class CumSum1d { static operation newCumSum1d() : CumSum1d pre: true post: CumSum1d->exists( _x | result = _x ); attribute ls_accum : Sequence := Sequence{ 0 }->union((accumulate(ls))); operation initialise(ls : Sequence(OclAny)) : CumSum1d pre: true post: true activity: skip ; self.ls_accum := Sequence{ 0 }->union((accumulate(ls))); return self; operation total(i : OclAny,j : OclAny) : OclAny pre: true post: true activity: return self.ls_accum[j+1] - self.ls_accum[i+1]; } class CumXor1d { static operation newCumXor1d() : CumXor1d pre: true post: CumXor1d->exists( _x | result = _x ); attribute ls_accum : Sequence := Sequence{ 0 }; operation initialise(ls : Sequence(OclAny)) : CumXor1d pre: true post: true activity: self.ls_accum := Sequence{ 0 } ; for l : ls do ((expr (atom (name self)) (trailer . (name ls_accum)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name l))) ^ (expr (atom (name self)) (trailer . (name ls_accum) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))))))))) ))))); return self; operation total(i : OclAny,j : OclAny) : OclAny pre: true post: true activity: return MathLib.bitwiseXor(self.ls_accum[j+1], self.ls_accum[i+1]); } class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : OclAny := read_ints() ; var cumsum : CumSum1d := (CumSum1d.newCumSum1d()).initialise(A) ; var cumxor : CumXor1d := (CumXor1d.newCumXor1d()).initialise(A) ; var ids : Sequence := Sequence{} ; var r_pre : int := 0 ; for l : Integer.subrange(0, N-1) do ( var r : OclAny := Set{r_pre, l + 1}->max() ; while (r->compareTo(N)) <= 0 & cumsum.total(l, r) = cumxor.total(l, r) do ( r := r + 1) ; r := r - 1 ; if r /= r_pre then ( r_pre := r ; execute ((Sequence{l, r}) : ids) ) else skip) ; var ans : int := 0 ; for _tuple : ids do (var _indx : int := 1; var l : OclAny := _tuple->at(_indx); _indx := _indx + 1; var r : OclAny := _tuple->at(_indx); var n : double := r - l ; ans := ans + n + n * (n - 1) div 2) ; if (ids)->size() > 1 then ( for _tuple : Integer.subrange(1, ids->size())->collect( _indx | Sequence{ids->at(_indx), ids->tail()->at(_indx)} ) do (var _indx : int := 1; var Sequence{_anon, r} : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{l, _anon} : OclAny := _tuple->at(_indx); n := Set{0, r - l}->max() ; ans := ans - n + n * (n - 1) div 2) ) else skip ; execute (ans)->display(); operation read_ints() : OclAny pre: true post: true activity: return ((read().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : N=int(raw_input()) A=map(int,raw_input().split()) head=0 tail=0 num_2=0 num_10=0 ans=0 now_len=0 while(headtoInteger() ; var A : Sequence := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var head : int := 0 ; var tail : int := 0 ; var num:= 0 : int := 0 ; var num var N : int := ("" + ((raw_input())))->toInteger()0 : int := 0 ; var ans : int := 0 ; var now_len : int := 0 ; while ((head->compareTo(N)) < 0) do ( num:= MathLib.bitwiseXor(numA[head+1], A[head+1]) := MathLib.bitwiseXor(numA[head+1], A[head+1]) ; num num:= MathLib.bitwiseXor(numA[head+1], A[head+1]) := MathLib.bitwiseXor(numA[head+1], A[head+1])0 := num num:= MathLib.bitwiseXor(numA[head+1], A[head+1]) := MathLib.bitwiseXor(numA[head+1], A[head+1])0 + A[head+1] ; if numnum num:= MathLib.bitwiseXor(numA[head+1], A[head+1]) := MathLib.bitwiseXor(numA[head+1], A[head+1])0 = num num:= MathLib.bitwiseXor(numA[head+1], A[head+1]) := MathLib.bitwiseXor(numA[head+1], A[head+1])0 then ( head := head + 1 ; now_len := now_len + 1 ; ans := ans + now_len ) else ( num xor A[tail+1] := num xor A[tail+1] xor A[tail+1] ; num num xor A[tail+1] := num xor A[tail+1] xor A[tail+1]0 := num num xor A[tail+1] := num xor A[tail+1] xor A[tail+1]0 - A[tail+1] ; num xor A[head+1] := num xor A[head+1] xor A[head+1] ; num num xor A[tail+1] := num xor A[tail+1] xor A[tail+1]0 := num num xor A[tail+1] := num xor A[tail+1] xor A[tail+1]0 - A[head+1] ; tail := tail + 1 ; now_len := now_len - 1 )) ; execute (ans)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) a=list(map(int,input().split())) print(resolve(a)) def resolve(a): cnt=0 base=0 skip=0 for i in range(len(a)): c,base=resolve_1(a,i,skip,base) skip=c-1 base=base ^ a[i] cnt+=c return cnt def resolve_1(a,i,skip,base): cnt=skip for j in range(i+skip,len(a)): if a[j]& base!=0 : break cnt+=1 base |=a[j] return(cnt,base) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; main(); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (resolve(a))->display(); operation resolve(a : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; var base : int := 0 ; var skip : int := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( var c : OclAny := null; Sequence{c,base} := resolve var cnt : int := 0(a, i, skip, base) ; skip := c - 1 ; base := MathLib.bitwiseXor(base, a[i+1]) ; cnt := cnt + c) ; return cnt; operation resolve skip(a : OclAny, i : OclAny, skip : OclAny, base : OclAny) : OclAny pre: true post: true activity: cnt := skip ; for j : Integer.subrange(i + skip, (a)->size()-1) do ( if MathLib.bitwiseAnd(a[j+1], base) /= 0 then ( break ) else skip ; cnt := cnt + 1 ; base := base or a[j+1]) ; return Sequence{cnt, base}; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=10000 def bucket_sort(A): count_array=[0]*MAX B=[0]*len(A) for a in A : count_array[a]+=1 for i in range(1,MAX): count_array[i]=count_array[i]+count_array[i-1] for a in A[: :-1]: B[count_array[a]-1]=a count_array[a]-=1 return B if __name__=="__main__" : n=int(input()) *A,=map(int,input().split()) print(*bucket_sort(A)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 10000 ; skip ; if __name__ = "__main__" then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ) else skip ; (testlist_star_expr (star_expr * (expr (atom (name A)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name A)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation bucket_sort(A : OclAny) : OclAny pre: true post: true activity: var count_array : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX) ; var B : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (A)->size()) ; for a : A do ( count_array[a+1] := count_array[a+1] + 1) ; for i : Integer.subrange(1, MAX-1) do ( count_array[i+1] := count_array[i+1] + count_array[i - 1+1]) ; for a : A(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( B[count_array[a+1] - 1+1] := a ; count_array[a+1] := count_array[a+1] - 1) ; return B; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) i=1 while i<=N : i=i*2 print(int(i/2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 1 ; while (i->compareTo(N)) <= 0 do ( i := i * 2) ; execute (("" + ((i / 2)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict from collections import deque from heapq import heappush,heappop import sys import math import bisect import random def LI(): return list(map(int,sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return list(map(list,sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l=[None for i in range(n)] for i in range(n): l[i]=I() return l def LIR(n): l=[None for i in range(n)] for i in range(n): l[i]=LI() return l def SR(n): l=[None for i in range(n)] for i in range(n): l[i]=S() return l def LSR(n): l=[None for i in range(n)] for i in range(n): l[i]=SR() return l mod=1000000007 n=I() p=[1] for i in range(n): p.append(p[-1]*2) if p[-1]>n : print(p[-2]) quit() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : int := 1000000007 ; n := I() ; var p : Sequence := Sequence{ 1 } ; for i : Integer.subrange(0, n-1) do ( execute ((p->last() * 2) : p) ; if (p->last()->compareTo(n)) > 0 then ( execute (p->front()->last())->display() ; quit() ) else skip); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["Sequence"])->apply(_x) )); operation S() : OclAny pre: true post: true activity: return OclType["Sequence"]((OclFile["System.in"]).readLine())->front(); operation IR(n : OclAny) : OclAny pre: true post: true activity: var l : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; for i : Integer.subrange(0, n-1) do ( l[i+1] := I()) ; return l; operation LIR(n : OclAny) : OclAny pre: true post: true activity: l := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; for i : Integer.subrange(0, n-1) do ( l[i+1] := LI()) ; return l; operation SR(n : OclAny) : OclAny pre: true post: true activity: l := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; for i : Integer.subrange(0, n-1) do ( l[i+1] := S()) ; return l; operation LSR(n : OclAny) : OclAny pre: true post: true activity: l := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; for i : Integer.subrange(0, n-1) do ( l[i+1] := SR()) ; return l; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) if N>=64 : print(64) elif 64>N>=32 : print(32) elif 32>N>=16 : print(16) elif 16>N>=8 : print(8) elif 8>N>=4 : print(4) elif 4>N>=2 : print(2) elif 2>N>=1 : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N >= 64 then ( execute (64)->display() ) else (if 64 > N & (N >= 32) then ( execute (32)->display() ) else (if 32 > N & (N >= 16) then ( execute (16)->display() ) else (if 16 > N & (N >= 8) then ( execute (8)->display() ) else (if 8 > N & (N >= 4) then ( execute (4)->display() ) else (if 4 > N & (N >= 2) then ( execute (2)->display() ) else (if 2 > N & (N >= 1) then ( execute (1)->display() ) else skip ) ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=1 while True : if ans>n : print(ans//2) import sys sys.exit() if ans==n : print(ans) import sys sys.exit() ans*=2 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 1 ; while true do ( if (ans->compareTo(n)) > 0 then ( execute (ans div 2)->display() ; skip ; sys.exit() ) else skip ; if ans = n then ( execute (ans)->display() ; skip ; sys.exit() ) else skip ; ans := ans * 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import Counter n=int(input()) for i in range(n,0,-1): if i &(i-1)==0 : print(i) sys.exit() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0 + 1, n)->reverse() do ( if MathLib.bitwiseAnd(i, (i - 1)) = 0 then ( execute (i)->display() ; sys.exit() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def SieveOfEratosthenes(prime,p_size): prime[0]=False prime[1]=False for p in range(2,p_size+1): if(p*p>p_size): break if(prime[p]): i=p*2 while(i<=p_size): prime[i]=False i=i+p def maxPrimeSubarray(arr,n): max_ele=max(arr) prime=[True]*(max_ele+1) SieveOfEratosthenes(prime,max_ele) current_max=0 max_so_far=0 for i in range(n): if(prime[arr[i]]==False): current_max=0 else : current_max=current_max+1 max_so_far=max(current_max,max_so_far) return max_so_far if __name__=='__main__' : arr=[1,0,2,4,3,29,11,7,8,9] n=len(arr) print(maxPrimeSubarray(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{0}->union(Sequence{2}->union(Sequence{4}->union(Sequence{3}->union(Sequence{29}->union(Sequence{11}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 9 }))))))))) ; n := (arr)->size() ; execute (maxPrimeSubarray(arr, n))->display() ) else skip; operation SieveOfEratosthenes(prime : OclAny, p_size : OclAny) pre: true post: true activity: prime->first() := false ; prime[1+1] := false ; for p : Integer.subrange(2, p_size + 1-1) do ( if ((p * p->compareTo(p_size)) > 0) then ( break ) else skip ; if (prime[p+1]) then ( var i : double := p * 2 ; while ((i->compareTo(p_size)) <= 0) do ( prime[i+1] := false ; i := i + p) ) else skip); operation maxPrimeSubarray(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var max_ele : OclAny := (arr)->max() ; prime := MatrixLib.elementwiseMult(Sequence{ true }, (max_ele + 1)) ; SieveOfEratosthenes(prime, max_ele) ; var current_max : int := 0 ; var max_so_far : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (prime[arr[i+1]+1] = false) then ( current_max := 0 ) else ( current_max := current_max + 1 ; max_so_far := Set{current_max, max_so_far}->max() )) ; return max_so_far; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np def solve(dp,wt,K,M,used): if(wt<0): return 0 if(wt==0): if(used): return 1 return 0 if(dp[wt][used]!=-1): return dp[wt][used] ans=0 for i in range(1,K+1): if(i>=M): ans+=solve(dp,wt-i,K,M,used | 1) else : ans+=solve(dp,wt-i,K,M,used) dp[wt][used]=ans return ans if __name__=="__main__" : W=3 K=3 M=2 dp=np.ones((W+1,2)); dp=-1*dp print(solve(dp,W,K,M,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var W : int := 3 ; K := 3 ; M := 2 ; dp := MatrixLib.singleValueMatrix(Sequence{W + 1, 2}, 1.0); ; dp := -1 * dp ; execute (solve(dp, W, K, M, 0))->display() ) else skip; operation solve(dp : OclAny, wt : OclAny, K : OclAny, M : OclAny, used : OclAny) : OclAny pre: true post: true activity: if (wt < 0) then ( return 0 ) else skip ; if (wt = 0) then ( if (used) then ( return 1 ) else skip ; return 0 ) else skip ; if (dp[wt+1][used+1] /= -1) then ( return dp[wt+1][used+1] ) else skip ; var ans : int := 0 ; for i : Integer.subrange(1, K + 1-1) do ( if ((i->compareTo(M)) >= 0) then ( ans := ans + solve(dp, wt - i, K, M, MathLib.bitwiseOr(used, 1)) ) else ( ans := ans + solve(dp, wt - i, K, M, used) )) ; dp[wt+1][used+1] := ans ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : s=input() if s=="#" : break clauses=s.split("|") for clause in clauses : literals=set(clause[1 :-1].split("&")) for literal in literals : if literal[0]=="~" and literal[1]in literals : break else : print("yes") break else : print("no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var s : String := (OclFile["System.in"]).readLine() ; if s = "#" then ( break ) else skip ; var clauses : OclAny := s.split("|") ; (compound_stmt for (exprlist (expr (atom (name clause)))) in (testlist (test (logical_test (comparison (expr (atom (name clauses))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name literals)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name clause)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "&"))))))) ))))))))) ))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name literal)))) in (testlist (test (logical_test (comparison (expr (atom (name literals))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name literal)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) == (comparison (expr (atom "~"))))) and (logical_test (comparison (comparison (expr (atom (name literal)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) in (comparison (expr (atom (name literals)))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "yes"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "no"))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from bisect import bisect,bisect_left class BinaryIndexedTree : def __init__(self,n): self.size=n self.INF=10**18 self.tree=[self.INF]*(n+1) def get_min(self,i): s=self.INF while i>0 : s=min(s,self.tree[i]) i-=i &-i return s def update(self,i,x): while i<=self.size : if self.tree[i]<=x : break self.tree[i]=x i+=i &-i def solve(n,e,t,xxx): if n==1 : return e+t dp1=[0]*(n+1) dp2=BinaryIndexedTree(n+1) dp2.update(1,-xxx[0]*2) for i in range(n): x=xxx[i] j=bisect_left(xxx,x-t//2,hi=i) ex_time=dp1[j]+t if j>0 : ex_time=min(ex_time,x*2+dp2.get_min(j)) dp1[i+1]=ex_time if iexists( _x | result = _x ); attribute size : OclAny := n; attribute INF : double := (10)->pow(18); attribute tree : Sequence := MatrixLib.elementwiseMult(Sequence{ self.INF }, (n + 1)); operation initialise(n : OclAny) : BinaryIndexedTree pre: true post: true activity: self.size := n ; self.INF := (10)->pow(18) ; self.tree := MatrixLib.elementwiseMult(Sequence{ self.INF }, (n + 1)); return self; operation get_min(i : OclAny) : OclAny pre: true post: true activity: var s : OclAny := self.INF ; while i > 0 do ( s := Set{s, self.tree[i+1]}->min() ; i := i - MathLib.bitwiseAnd(i, -i)) ; return s; operation update(i : OclAny,x : OclAny) pre: true post: true activity: while (i->compareTo(self.size)) <= 0 do ( if (self.tree[i+1]->compareTo(x)) <= 0 then ( break ) else skip ; self.tree[i+1] := x ; i := i + MathLib.bitwiseAnd(i, -i)); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var xxx : OclAny := null; Sequence{n,e,t,xxx} := (sys.stdin.buffer.readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (solve(n, e, t, xxx))->display(); operation solve(n : OclAny, e : OclAny, t : OclAny, xxx : OclAny) : OclAny pre: true post: true activity: if n = 1 then ( return e + t ) else skip ; var dp1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var dp2 : BinaryIndexedTree := (BinaryIndexedTree.newBinaryIndexedTree()).initialise(n + 1) ; execute ((1, -xxx->first() * 2) <: dp2) ; for i : Integer.subrange(0, n-1) do ( x := xxx[i+1] ; var j : OclAny := bisect_left(xxx, x - t div 2, (argument (test (logical_test (comparison (expr (atom (name hi)))))) = (test (logical_test (comparison (expr (atom (name i)))))))) ; var ex_time : OclAny := dp1[j+1] + t ; if j > 0 then ( ex_time := Set{ex_time, x * 2 + dp2.get_min(j)}->min() ) else skip ; dp1[i + 1+1] := ex_time ; if (i->compareTo(n - 1)) < 0 then ( execute ((i + 2, ex_time - xxx[i + 1+1] * 2) <: dp2) ) else skip) ; return e + dp1->last(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect N,E,T=map(int,input().split()) A=list(map(int,input().split())) A.append(float("inf")) dp=[[float("-inf")]*2 for i in range(N+1)] dp[0][0]=0 for i in range(N): j=bisect.bisect_right(A,A[i]+T//2) dp[j][0]=max(dp[j][0],dp[i][0]+(j-i-1)*T) dp[j][1]=max(dp[j][1],dp[i][0]+(j-i)*T-(2*(A[j]-A[i])-T)) dp[i+1][0]=max(dp[i+1][0],dp[i][1]) dp[i+1][1]=max(dp[i+1][1],dp[i][1]+T-(A[i+1]-A[i])*2) print(E+N*T-dp[-1][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var E : OclAny := null; var T : OclAny := null; Sequence{N,E,T} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((("" + (("inf")))->toReal()) : A) ; var dp : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ ("" + (("-inf")))->toReal() }, 2))) ; dp->first()->first() := 0 ; for i : Integer.subrange(0, N-1) do ( var j : OclAny := bisect.bisect_right(A, A[i+1] + T div 2) ; dp[j+1]->first() := Set{dp[j+1]->first(), dp[i+1]->first() + (j - i - 1) * T}->max() ; dp[j+1][1+1] := Set{dp[j+1][1+1], dp[i+1]->first() + (j - i) * T - (2 * (A[j+1] - A[i+1]) - T)}->max() ; dp[i + 1+1]->first() := Set{dp[i + 1+1]->first(), dp[i+1][1+1]}->max() ; dp[i + 1+1][1+1] := Set{dp[i + 1+1][1+1], dp[i+1][1+1] + T - (A[i + 1+1] - A[i+1]) * 2}->max()) ; execute (E + N * T - dp->last()->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) if x==1 : print(0) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if x = 1 then ( execute (0)->display() ) else ( execute (1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,e,t=map(int,input().split()) a,f,l,c=[0]+list(map(int,input().split())),[0]*(n+1),1,int(1e18) for i in range(1,n+1): while 2*(a[i]-a[l])>=t : c=min(c,f[l-1]-2*a[l]) l+=1 f[i]=min(f[l-1]+t,c+2*a[i]) print(f[n]+e) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var e : OclAny := null; var t : OclAny := null; Sequence{n,e,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var f : OclAny := null; var l : OclAny := null; var c : OclAny := null; Sequence{a,f,l,c} := Sequence{Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))),MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)),1,("" + ((("1e18")->toReal())))->toInteger()} ; for i : Integer.subrange(1, n + 1-1) do ( while (2 * (a[i+1] - a[l+1])->compareTo(t)) >= 0 do ( var c : OclAny := Set{c, f[l - 1+1] - 2 * a[l+1]}->min() ; l := l + 1) ; f[i+1] := Set{f[l - 1+1] + t, c + 2 * a[i+1]}->min()) ; execute (f[n+1] + e)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w=int(input()) n=int(input()) a=list(range(w)) for i in range(n): k1,k2=map(int,input().split(",")) a[k1-1],a[k2-1]=a[k2-1],a[k1-1] for i in a : print(i+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (Integer.subrange(0, w-1)) ; for i : Integer.subrange(0, n-1) do ( var k1 : OclAny := null; var k2 : OclAny := null; Sequence{k1,k2} := (input().split(","))->collect( _x | (OclType["int"])->apply(_x) ) ; var a[k1 - 1+1] : OclAny := null; var a[k2 - 1+1] : OclAny := null; Sequence{a[k1 - 1+1],a[k2 - 1+1]} := Sequence{a[k2 - 1+1],a[k1 - 1+1]}) ; for i : a do ( execute (i + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_another_num(data,me): if data[0]==me : return data[1] else : return data[0] if __name__=='__main__' : v_lines=int(input()) h_lines=int(input()) data=[] for i in range(h_lines): data.append(tuple(map(int,input().split(',')))) results=[0]*(v_lines+1) for i in range(1,v_lines+1): me=i for amida in data : if me in amida : me=get_another_num(amida,me) results[me]=i for i in range(1,v_lines+1): print(results[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var v_lines : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var h_lines : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; data := Sequence{} ; for i : Integer.subrange(0, h_lines-1) do ( execute ((((input().split(','))->collect( _x | (OclType["int"])->apply(_x) ))) : data)) ; var results : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (v_lines + 1)) ; for i : Integer.subrange(1, v_lines + 1-1) do ( me := i ; for amida : data do ( if (amida)->includes(me) then ( me := get_another_num(amida, me) ) else skip) ; results[me+1] := i) ; for i : Integer.subrange(1, v_lines + 1-1) do ( execute (results[i+1])->display()) ) else skip; operation get_another_num(data : OclAny, me : OclAny) : OclAny pre: true post: true activity: if data->first() = me then ( return data[1+1] ) else ( return data->first() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") w=int(input()) slots=list(range(1,w+1)) n=int(input()) for k in range(n): a,b=[int(_)for _ in input().split(',')] slots[a-1],slots[b-1]=slots[b-1],slots[a-1] for s in slots : print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; var w : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var slots : Sequence := (Integer.subrange(1, w + 1-1)) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for k : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split(',')->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var slots[a - 1+1] : OclAny := null; var slots[b - 1+1] : OclAny := null; Sequence{slots[a - 1+1],slots[b - 1+1]} := Sequence{slots[b - 1+1],slots[a - 1+1]}) ; for s : slots do ( execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[i+1 for i in range(int(input()))] for _ in[0]*int(input()): s,t=map(lambda x : int(x)-1,input().split(',')) a[s],a[t]=a[t],a[s] print(*a,sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1)->select(i | true)->collect(i | (i + 1)) ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := (input().split(','))->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ) ; var a[s+1] : OclAny := null; var a[t+1] : OclAny := null; Sequence{a[s+1],a[t+1]} := Sequence{a[t+1],a[s+1]}) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys w=int(sys.stdin.readline()) n=int(sys.stdin.readline()) a=[i for i in range(w+1)] for i in range(n): l=sys.stdin.readline() x,y=map(int,l.split(",")) a[x],a[y]=a[y],a[x] print("\n".join(map(str,a[1 :]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var w : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(0, w + 1-1)->select(i | true)->collect(i | (i)) ; for i : Integer.subrange(0, n-1) do ( var l : String := (OclFile["System.in"]).readLine() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (l.split(","))->collect( _x | (OclType["int"])->apply(_x) ) ; var a[x+1] : OclAny := null; var a[y+1] : OclAny := null; Sequence{a[x+1],a[y+1]} := Sequence{a[y+1],a[x+1]}) ; execute (StringLib.sumStringsWithSeparator(((a->tail())->collect( _x | (OclType["String"])->apply(_x) )), "\n"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def isPentagonal(N): i=1 while True : M=(3*i*i-i)/2 i+=1 if(M>=N): break return(M==N) N=12 if(isPentagonal(N)): print(N,end=' ') print("is pentagonal ") else : print(N,end=' ') print("is not pentagonal") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; N := 12 ; if (isPentagonal(N)) then ( execute (N)->display() ; execute ("is pentagonal ")->display() ) else ( execute (N)->display() ; execute ("is not pentagonal")->display() ); operation isPentagonal(N : OclAny) : OclAny pre: true post: true activity: var i : int := 1 ; while true do ( var M : double := (3 * i * i - i) / 2 ; i := i + 1 ; if ((M->compareTo(N)) >= 0) then ( break ) else skip) ; return (M = N); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): a,b,c,d=(int(i)for i in input().split()) res=a,c,c print(*res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var res : OclAny := a,c,c ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- BitsSetTable256=[0]*256 def initialize(): BitsSetTable256[0]=0 for i in range(256): BitsSetTable256[i]=(i & 1)+BitsSetTable256[i//2] def countSetBits(n): return(BitsSetTable256[n & 0xff]+BitsSetTable256[(n>>8)& 0xff]+BitsSetTable256[(n>>16)& 0xff]+BitsSetTable256[n>>24]) initialize() n=9 print(countSetBits(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var BitsSetTable256 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 256) ; skip ; skip ; initialize() ; n := 9 ; execute (countSetBits(n))->display(); operation initialize() pre: true post: true activity: BitsSetTable256->first() := 0 ; for i : Integer.subrange(0, 256-1) do ( BitsSetTable256[i+1] := (MathLib.bitwiseAnd(i, 1)) + BitsSetTable256[i div 2+1]); operation countSetBits(n : OclAny) : OclAny pre: true post: true activity: return (BitsSetTable256[MathLib.bitwiseAnd(n, 0xff)+1] + BitsSetTable256[MathLib.bitwiseAnd((n /(2->pow(8))), 0xff)+1] + BitsSetTable256[MathLib.bitwiseAnd((n /(2->pow(16))), 0xff)+1] + BitsSetTable256[n /(2->pow(24))+1]); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) x,y=0,0 ans=0 for _ in range(n): a,b=map(int,input().split()) ans+=max(0,min(a,b)-max(x,y)+1) if a==b : ans-=1 x,y=a,b if x==y : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{0,0} ; var ans : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; ans := ans + Set{0, Set{a, b}->min() - Set{x, y}->max() + 1}->max() ; if a = b then ( ans := ans - 1 ) else skip ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{a,b}) ; if x = y then ( ans := ans + 1 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,sys,bisect,heapq from collections import defaultdict,Counter,deque from itertools import groupby,accumulate int1=lambda x : int(x)-1 input=iter(sys.stdin.buffer.read().decode().splitlines()).__next__ ilele=lambda : map(int,input().split()) alele=lambda : list(map(int,input().split())) ilelec=lambda : map(int1,input().split()) alelec=lambda : list(map(int1,input().split())) def list2d(a,b,c): return[[c]*b for i in range(a)] def list3d(a,b,c,d): return[[[d]*c for j in range(b)]for i in range(a)] def Y(c): print(["NO","YES"][c]) def y(c): print(["no","yes"][c]) def Yy(c): print(["No","Yes"][c]) x=int(input()) if x==1 : print(0) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; var input : OclAny := iter(sys.stdin.buffer.readAll().decode().splitlines()).__next__ ; var ilele : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var alele : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ilelec : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (int1)->apply(_x) )) ; var alelec : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (int1)->apply(_x) ))) ; skip ; skip ; skip ; skip ; skip ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if x = 1 then ( execute (0)->display() ) else ( execute (1)->display() ); operation list2d(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, a-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ c }, b))); operation list3d(a : OclAny, b : OclAny, c : OclAny, d : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, a-1)->select(i | true)->collect(i | (Integer.subrange(0, b-1)->select(j | true)->collect(j | (MatrixLib.elementwiseMult(Sequence{ d }, c))))); operation Y(c : OclAny) pre: true post: true activity: execute (Sequence{"NO"}->union(Sequence{ "YES" })[c+1])->display(); operation y(c : OclAny) pre: true post: true activity: execute (Sequence{"no"}->union(Sequence{ "yes" })[c+1])->display(); operation Yy(c : OclAny) pre: true post: true activity: execute (Sequence{"No"}->union(Sequence{ "Yes" })[c+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): l=[int(num)for num in input().split()] if l[0]==l[1]==l[2]: print(l[0],l[1],l[2]) else : print(l[1],l[2],l[2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var l : Sequence := input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; if l->first() = l[1+1] & (l[1+1] == l[2+1]) then ( execute (l->first())->display() ) else ( execute (l[1+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a,b,c,d=map(int,input().split()) if a+b>c : print(a,b,c) else : s1=b s2=c s3=c print(s1,s2,s3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a + b->compareTo(c)) > 0 then ( execute (a)->display() ) else ( var s1 : OclAny := b ; var s2 : OclAny := c ; var s3 : OclAny := c ; execute (s1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a,b,c,d=map(int,input().split()) if a+b>c : print(a,b,c) else : print(b,c,c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a + b->compareTo(c)) > 0 then ( execute (a)->display() ) else ( execute (b)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=eval(input()) for i in range(t): input_list=list(map(lambda x : eval(x),input().split(" "))) x=input_list[1] y=input_list[2] z=input_list[2] if x+y>z and y+z>x and x+z>y : print(x,y,z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, t-1) do ( var input_list : Sequence := ((input().split(" "))->collect( _x | (lambda x : OclAny in (x))->apply(_x) )) ; var x : OclAny := input_list[1+1] ; var y : OclAny := input_list[2+1] ; var z : OclAny := input_list[2+1] ; if (x + y->compareTo(z)) > 0 & (y + z->compareTo(x)) > 0 & (x + z->compareTo(y)) > 0 then ( execute (x)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=1000 dp=[-1]*N def minOperations(k): if(k<=0 or k>=1000): return 1e9 if(k==m): return 0 dp[k]=dp[k] if(dp[k]!=-1): return dp[k] dp[k]=1e9 dp[k]=1+min(minOperations(2*k),minOperations(k-1)) return dp[k] if __name__=='__main__' : n=4 m=6 print(minOperations(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 1000 ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, N) ; skip ; if __name__ = '__main__' then ( var n : int := 4 ; var m : int := 6 ; execute (minOperations(n))->display() ) else skip; operation minOperations(k : OclAny) : OclAny pre: true post: true activity: if (k <= 0 or k >= 1000) then ( return ("1e9")->toReal() ) else skip ; if (k = m) then ( return 0 ) else skip ; dp[k+1] := dp[k+1] ; if (dp[k+1] /= -1) then ( return dp[k+1] ) else skip ; dp[k+1] := ("1e9")->toReal() ; dp[k+1] := 1 + Set{minOperations(2 * k), minOperations(k - 1)}->min() ; return dp[k+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l,r=map(int,input().split()) if l==r : print(l) else : print(2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if l = r then ( execute (l)->display() ) else ( execute (2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) if a==b : print(a) else : print(2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = b then ( execute (a)->display() ) else ( execute (2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) if a==b : print(a) else : print(2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = b then ( execute (a)->display() ) else ( execute (2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()); print(n if n==m else 2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); execute (if n = m then n else 2 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def countLattice(r): if(r<=0): return 0 result=4 for x in range(1,r): ySquare=r*r-x*x y=int(math.sqrt(ySquare)) if(y*y==ySquare): result+=4 return result r=5 print(countLattice(r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; r := 5 ; execute (countLattice(r))->display(); operation countLattice(r : OclAny) : OclAny pre: true post: true activity: if (r <= 0) then ( return 0 ) else skip ; var result : int := 4 ; for x : Integer.subrange(1, r-1) do ( var ySquare : double := r * r - x * x ; var y : int := ("" + (((ySquare)->sqrt())))->toInteger() ; if (y * y = ySquare) then ( result := result + 4 ) else skip) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd from itertools import combinations,permutations,accumulate,product from collections import deque,defaultdict,Counter import decimal import re import math import bisect import heapq import sys sys.setrecursionlimit(10000000) mod=10**9+7 INF=float('inf') from sys import stdin readline=stdin.readline def readInts(): return list(map(int,readline().split())) def readTuples(): return tuple(map(int,readline().split())) def I(): return int(readline()) x=I() print(0 if x else 1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(10000000) ; var mod : double := (10)->pow(9) + 7 ; var INF : double := ("" + (('inf')))->toReal() ; skip ; var readline : OclAny := stdin.readline ; skip ; skip ; skip ; var x : OclAny := I() ; execute (if x then 0 else 1 endif)->display(); operation readInts() : OclAny pre: true post: true activity: return ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )); operation readTuples() : OclAny pre: true post: true activity: return ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )); operation I() : OclAny pre: true post: true activity: return ("" + ((readline())))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=1 a,b=0,0 for i in range(n): x,y=map(int,input().split()) if x==a and y==b : continue if a==b : ans-=1 if x<=y : if b>x : a,b=x,y continue else : ans+=x-max(a,b)+1 a,b=x,y else : if a>y : a,b=x,y continue else : ans+=y-max(a,b)+1 a,b=x,y print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 1 ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{0,0} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x = a & y = b then ( continue ) else skip ; if a = b then ( ans := ans - 1 ) else skip ; if (x->compareTo(y)) <= 0 then ( if (b->compareTo(x)) > 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{x,y} ; continue ) else ( ans := ans + x - Set{a, b}->max() + 1 ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{x,y} ) ) else ( if (a->compareTo(y)) > 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{x,y} ; continue ) else ( ans := ans + y - Set{a, b}->max() + 1 ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{x,y} ) )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin readline=stdin.readline def cross(a,b): return a.real*b.imag-a.imag*b.real def is_convex(p): for i in range(len(p)): j,k=i-1,i-2 if 0>cross(p[j]-p[k],p[i]-p[k]): return False return True n=int(readline()) p=[map(int,readline().split())for _ in range(n)] p=[x+y*1j for x,y in p] print(1 if is_convex(p)else 0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := stdin.readline ; skip ; skip ; var n : int := ("" + ((readline())))->toInteger() ; p := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((readline().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; p := p->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (x + y * 1j)) ; execute (if is_convex(p) then 1 else 0 endif)->display(); operation cross(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a.real * b.imag - a.imag * b.real; operation is_convex(p : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, (p)->size()-1) do ( var j : OclAny := null; var k : OclAny := null; Sequence{j,k} := Sequence{i - 1,i - 2} ; if 0 > cross(p[j+1] - p[k+1], p[i+1] - p[k+1]) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import cmath EPS=1e-10 def OuterProduct(one,two): tmp=one.conjugate()*two return tmp.imag def CCW(p,q,r): one,two=q-p,r-q if OuterProduct(one,two)>-EPS : return True else : return False def ConvexHull(dots): dots.sort(key=lambda x :(x.real,x.imag)) res1=[dots[0]] for d in dots[1 :]: if len(res1)==1 : res1.append(d) else : while len(res1)>1 and not CCW(res1[-2],res1[-1],d): res1.pop() res1.append(d) dots.reverse() res2=[dots[0]] for d in dots[1 :]: if len(res2)==1 : res2.append(d) else : while len(res2)>1 and not CCW(res2[-2],res2[-1],d): res2.pop() res2.append(d) return res1[:-1]+res2[:-1] n=int(input()) dots=[] for _ in range(n): x,y=map(int,input().split()) dots.append(complex(x,y)) if len(dots)==3 : print(1) elif len(ConvexHull(dots))==n : print(1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var EPS : double := ("1e-10")->toReal() ; skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; dots := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((complex(x, y)) : dots)) ; if (dots)->size() = 3 then ( execute (1)->display() ) else (if (ConvexHull(dots))->size() = n then ( execute (1)->display() ) else ( execute (0)->display() ) ) ; operation OuterProduct(one : OclAny, two : OclAny) : OclAny pre: true post: true activity: var tmp : double := one.conjugate() * two ; return tmp.imag; operation CCW(p : OclAny, q : OclAny, r : OclAny) : OclAny pre: true post: true activity: Sequence{one,two} := Sequence{q - p,r - q} ; if (OuterProduct(one, two)->compareTo(-EPS)) > 0 then ( return true ) else ( return false ); operation ConvexHull(dots : OclAny) : OclAny pre: true post: true activity: dots := dots->sort() ; var res1 : Sequence := Sequence{ dots->first() } ; for d : dots->tail() do ( if (res1)->size() = 1 then ( execute ((d) : res1) ) else ( while (res1)->size() > 1 & not(CCW(res1->front()->last(), res1->last(), d)) do ( res1 := res1->front()) ; execute ((d) : res1) )) ; dots := dots->reverse() ; var res2 : Sequence := Sequence{ dots->first() } ; for d : dots->tail() do ( if (res2)->size() = 1 then ( execute ((d) : res2) ) else ( while (res2)->size() > 1 & not(CCW(res2->front()->last(), res2->last(), d)) do ( res2 := res2->front()) ; execute ((d) : res2) )) ; return res1->front() + res2->front(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) vec=[] for i in range(n): vec+=[list(map(int,input().split()))] vec+=[vec[0]] vec+=[vec[1]] Sum=0 def cross(a,b): return a[0]*b[1]-a[1]*b[0] def ab(a,b): c=(b[0]-a[0],b[1]-a[1]) return c def check(a,b,c): if cross(ab(a,b),ab(a,c))>=0 : return 1 else : return 0 for a,b,c in zip(vec[0 :-2],vec[1 :-1],vec[2 :]): cnt=check(a,b,c) if cnt==0 : break print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var vec : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( vec := vec + Sequence{ ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) }) ; vec := vec + Sequence{ vec->first() } ; vec := vec + Sequence{ vec[1+1] } ; var Sum : int := 0 ; skip ; skip ; skip ; for _tuple : Integer.subrange(1, vec.subrange(0+1, -2)->size())->collect( _indx | Sequence{vec.subrange(0+1, -2)->at(_indx), vec.subrange(1+1, -1)->at(_indx)} ) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); var cnt : OclAny := check(a, b, c) ; if cnt = 0 then ( break ) else skip) ; execute (cnt)->display(); operation cross(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a->first() * b[1+1] - a[1+1] * b->first(); operation ab(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var c : OclAny := Sequence{b->first() - a->first(), b[1+1] - a[1+1]} ; return c; operation check(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: if cross(ab(a, b), ab(a, c)) >= 0 then ( return 1 ) else ( return 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input3.txt","rt") def is_convex(P): N=len(P) prods=[] for k in range(N): x0,y0=P[k] x1,y1=P[(k+1)% N] x2,y2=P[(k+2)% N] dx1=x1-x0 dy1=y1-y0 dx2=x2-x1 dy2=y2-y1 cross=dx1*dy2-dy1*dx2 prods.append(cross) prods=sorted(prods) return prods[0]*prods[-1]>=0 N=int(input()) P=[[int(_)for _ in input().split()]for __ in range(N)] print(1 if is_convex(P)else 0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input3.txt")) ) else skip ; skip ; N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; P := Integer.subrange(0, N-1)->select(__ | true)->collect(__ | (input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())))) ; execute (if is_convex(P) then 1 else 0 endif)->display(); operation is_convex(P : OclAny) : OclAny pre: true post: true activity: var N : int := (P)->size() ; var prods : Sequence := Sequence{} ; for k : Integer.subrange(0, N-1) do ( var x0 : OclAny := null; var y0 : OclAny := null; Sequence{x0,y0} := P[k+1] ; var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := P[(k + 1) mod N+1] ; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x2,y2} := P[(k + 2) mod N+1] ; var dx1 : double := x1 - x0 ; var dy1 : double := y1 - y0 ; var dx2 : double := x2 - x1 ; var dy2 : double := y2 - y1 ; var cross : double := dx1 * dy2 - dy1 * dx2 ; execute ((cross) : prods)) ; prods := prods->sort() ; return prods->first() * prods->last() >= 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def vc(p,q): return[p[0]-q[0],p[1]-q[1]] def cross(u,v): return(u[0]*v[1]-u[1]*v[0]) n=int(input()) v=[] for _ in range(n): x0,y0=map(int,input().split()) v.append([x0,y0]) flag=True for i in range(n-2): e_i=vc(v[i+1],v[i]) e_nxt=vc(v[i+2],v[i+1]) if cross(e_i,e_nxt)<0 : flag=False e_i=vc(v[-1],v[-2]) e_nxt=vc(v[0],v[-1]) if cross(e_i,e_nxt)<0 : flag=False e_i=vc(v[0],v[-1]) e_nxt=vc(v[1],v[0]) if cross(e_i,e_nxt)<0 : flag=False if flag : print(1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; v := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var x0 : OclAny := null; var y0 : OclAny := null; Sequence{x0,y0} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{x0}->union(Sequence{ y0 })) : v)) ; var flag : boolean := true ; for i : Integer.subrange(0, n - 2-1) do ( var e_i : OclAny := vc(v[i + 1+1], v[i+1]) ; var e_nxt : OclAny := vc(v[i + 2+1], v[i + 1+1]) ; if cross(e_i, e_nxt) < 0 then ( flag := false ) else skip) ; e_i := vc(v->last(), v->front()->last()) ; e_nxt := vc(v->first(), v->last()) ; if cross(e_i, e_nxt) < 0 then ( flag := false ) else skip ; e_i := vc(v->first(), v->last()) ; e_nxt := vc(v[1+1], v->first()) ; if cross(e_i, e_nxt) < 0 then ( flag := false ) else skip ; if flag then ( execute (1)->display() ) else ( execute (0)->display() ); operation vc(p : OclAny, q : OclAny) : OclAny pre: true post: true activity: return Sequence{p->first() - q->first()}->union(Sequence{ p[1+1] - q[1+1] }); operation cross(u : OclAny, v : OclAny) : OclAny pre: true post: true activity: return (u->first() * v[1+1] - u[1+1] * v->first()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rearrange(arr,n): for i in range(0,n): arr[i]+=(arr[arr[i]]% n)*n for i in range(0,n): arr[i]=int(arr[i]/n) def printArr(arr,n): for i in range(0,n): print(arr[i],end="") print("") arr=[3,2,0,1] n=len(arr) print("Given array is") printArr(arr,n) rearrange(arr,n); print("Modified array is") printArr(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{3}->union(Sequence{2}->union(Sequence{0}->union(Sequence{ 1 }))) ; n := (arr)->size() ; execute ("Given array is")->display() ; printArr(arr, n) ; rearrange(arr, n); ; execute ("Modified array is")->display() ; printArr(arr, n); operation rearrange(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( arr[i+1] := arr[i+1] + (arr[arr[i+1]+1] mod n) * n) ; for i : Integer.subrange(0, n-1) do ( arr[i+1] := ("" + ((arr[i+1] / n)))->toInteger()); operation printArr(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()) ; execute ("")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cross(x,y): return(x.conjugate()*y).imag def area_polygon(points): area=0 n=len(points) for i in range(n): area+=cross(points[i],points[(i+1)% n]) return area/2 import sys p=[] for line in sys.stdin : x,y=map(float,line.split(',')) p.append(complex(x,y)) print(abs(area_polygon(p))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var p : Sequence := Sequence{} ; for line : OclFile["System.in"] do ( Sequence{x,y} := (line.split(','))->collect( _x | (OclType["double"])->apply(_x) ) ; execute ((complex(x, y)) : p)) ; execute ((area_polygon(p))->abs())->display(); operation cross(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return (x.conjugate() * y).imag; operation area_polygon(points : OclAny) : OclAny pre: true post: true activity: var area : int := 0 ; var n : int := (points)->size() ; for i : Integer.subrange(0, n-1) do ( area := area + cross(points[i+1], points[(i + 1) mod n+1])) ; return area / 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- xlst=[] ylst=[] while True : try : x,y=map(float,input().split(",")) xlst.append(x) ylst.append(y) except EOFError : break num=len(xlst) cx,cy=sum(xlst)/num,sum(ylst)/num xlst.append(xlst[0]) ylst.append(ylst[0]) ans=0 for i in range(num): x1,y1,x2,y2=xlst[i],ylst[i],xlst[i+1],ylst[i+1] a=((x2-x1)**2+(y2-y1)**2)**(1/2) b=((x1-cx)**2+(y1-cy)**2)**(1/2) c=((x2-cx)**2+(y2-cy)**2)**(1/2) z=(a+b+c)/2 s=(z*(z-a)*(z-b)*(z-c))**(1/2) ans+=s print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var xlst : Sequence := Sequence{} ; var ylst : Sequence := Sequence{} ; while true do ( try ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split(","))->collect( _x | (OclType["double"])->apply(_x) ) ; execute ((x) : xlst) ; execute ((y) : ylst)) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))) ; var num : int := (xlst)->size() ; var cx : OclAny := null; var cy : OclAny := null; Sequence{cx,cy} := Sequence{(xlst)->sum() / num,(ylst)->sum() / num} ; execute ((xlst->first()) : xlst) ; execute ((ylst->first()) : ylst) ; var ans : int := 0 ; for i : Integer.subrange(0, num-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := Sequence{xlst[i+1],ylst[i+1],xlst[i + 1+1],ylst[i + 1+1]} ; var a : double := ((((x2 - x1))->pow(2) + ((y2 - y1))->pow(2)))->pow((1 / 2)) ; var b : double := ((((x1 - cx))->pow(2) + ((y1 - cy))->pow(2)))->pow((1 / 2)) ; var c : double := ((((x2 - cx))->pow(2) + ((y2 - cy))->pow(2)))->pow((1 / 2)) ; var z : double := (a + b + c) / 2 ; var s : double := ((z * (z - a) * (z - b) * (z - c)))->pow((1 / 2)) ; ans := ans + s) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readlines=sys.stdin.readlines write=sys.stdout.write def solve(): P=[] for line in readlines(): x,y=map(float,line.split(",")) P.append((x,y)) N=len(P) s=0 for i in range(N): x0,y0=P[i-1]; x1,y1=P[i] s+=x0*y1-x1*y0 write("%.16f\n" %(abs(s)/2)) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readlines : OclAny := (OclFile["System.in"]).readlines ; var write : OclAny := (OclFile["System.out"]).write ; skip ; solve(); operation solve() pre: true post: true activity: var P : Sequence := Sequence{} ; for line : readlines() do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (line.split(","))->collect( _x | (OclType["double"])->apply(_x) ) ; execute ((Sequence{x, y}) : P)) ; var N : int := (P)->size() ; var s : int := 0 ; for i : Integer.subrange(0, N-1) do ( var x0 : OclAny := null; var y0 : OclAny := null; Sequence{x0,y0} := P[i - 1+1]; var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := P[i+1] ; s := s + x0 * y1 - x1 * y0) ; write(StringLib.format("%.16f\n",((s)->abs() / 2))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(int(not int(input()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (("" + ((not(("" + (((OclFile["System.in"]).readLine())))->toInteger()))))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math l=[list(map(float,i.split(",")))for i in sys.stdin] S=0 for(i,j)in enumerate(l): xn,yn=j if i!=len(l)-1 : xn_1,yn_1=l[i+1] else : xn_1,yn_1=l[0] a=math.sqrt(xn**2+yn**2) b=math.sqrt(xn_1**2+yn_1**2) c=math.sqrt((xn_1-xn)**2+(yn_1-yn)**2) z=(a+b+c)/2 S+=math.sqrt(z*(z-a)*(z-b)*(z-c)) print(S) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var l : Sequence := OclFile["System.in"]->select(i | true)->collect(i | (((i.split(","))->collect( _x | (OclType["double"])->apply(_x) )))) ; var S : int := 0 ; for Sequence{i, j} : Integer.subrange(1, (l)->size())->collect( _indx | Sequence{_indx-1, (l)->at(_indx)} ) do ( var xn : OclAny := null; var yn : OclAny := null; Sequence{xn,yn} := j ; if i /= (l)->size() - 1 then ( var xnxn var xn : OclAny := null; var yn : OclAny := null; Sequence{xn,yn} := j,ynxn var xn : OclAny := null; var yn : OclAny := null; Sequence{xn,yn} := j : OclAny := null; var ynxnxn var xn : OclAny := null; var yn : OclAny := null; Sequence{xn,yn} := j,ynxn var xn : OclAny := null; var yn : OclAny := null; Sequence{xn,yn} := j : OclAny := null; Sequence{xn var xn : OclAny := null; var yn : OclAny := null; Sequence{xn,yn} := j,ynxn var xn : OclAny := null; var yn : OclAny := null; Sequence{xn,yn} := j} := l[i + 1+1] ) else ( var xnxn var xn : OclAny := null; var yn : OclAny := null; Sequence{xn,yn} := j,ynxn var xn : OclAny := null; var yn : OclAny := null; Sequence{xn,yn} := j : OclAny := null; var ynxnxn var xn : OclAny := null; var yn : OclAny := null; Sequence{xn,yn} := j,ynxn var xn : OclAny := null; var yn : OclAny := null; Sequence{xn,yn} := j : OclAny := null; Sequence{xn var xn : OclAny := null; var yn : OclAny := null; Sequence{xn,yn} := j,ynxn var xn : OclAny := null; var yn : OclAny := null; Sequence{xn,yn} := j} := l->first() ) ; var a : double := ((xn)->pow(2) + (yn)->pow(2))->sqrt() ; var b : double := ((xn.sqrt((xn var xn : OclAny := null; var yn : OclAny := null; Sequence{xn,yn} := j)->pow(2) + (yn var xn : OclAny := null; var yn : OclAny := null; Sequence{xn,yn} := j)->pow(2)))->pow(2) + (yn.sqrt((xn var xn : OclAny := null; var yn : OclAny := null; Sequence{xn,yn} := j)->pow(2) + (yn var xn : OclAny := null; var yn : OclAny := null; Sequence{xn,yn} := j)->pow(2)))->pow(2))->sqrt() ; var c : double := (((xn.sqrt(((xn var xn : OclAny := null; var yn : OclAny := null; Sequence{xn,yn} := j - xn))->pow(2) + ((yn var xn : OclAny := null; var yn : OclAny := null; Sequence{xn,yn} := j - yn))->pow(2)) - xn))->pow(2) + ((yn.sqrt(((xn var xn : OclAny := null; var yn : OclAny := null; Sequence{xn,yn} := j - xn))->pow(2) + ((yn var xn : OclAny := null; var yn : OclAny := null; Sequence{xn,yn} := j - yn))->pow(2)) - yn))->pow(2))->sqrt() ; var z : double := (a + b + c) / 2 ; S := S + (z * (z - a) * (z - b) * (z - c))->sqrt()) ; execute (S)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[] b=[] for i in range(n): x,y=map(int,input().split()) a.append(x) b.append(y) ans=1 prev_a=0 prev_b=0 for i in range(0,len(a)): if a[i]toInteger() ; var a : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((x) : a) ; execute ((y) : b)) ; var ans : int := 1 ; var prev_a : int := 0 ; var prev_b : int := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( if (a[i+1]->compareTo(prev_b)) < 0 & (b[i+1]->compareTo(prev_a)) < 0 then ( prev_a := a[i+1] ; prev_b := b[i+1] ; continue ) else skip ; if (Set{prev_a, prev_b}->max()->compareTo(Set{a[i+1], b[i+1]}->min())) <= 0 then ( ans := ans + Set{a[i+1], b[i+1]}->min() - Set{prev_a, prev_b}->max() + 1 ) else skip ; if prev_a = prev_b then ( ans := ans - 1 ) else skip ; prev_a := a[i+1] ; prev_b := b[i+1]) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p1=complex(*list(map(float,input().split(',')))) p2=complex(*list(map(float,input().split(',')))) ans=0 def area(p,q,r): return((p-r).conjugate()*(q-r)).imag/2 try : while True : p3=complex(*list(map(float,input().split(',')))) ans+=area(p1,p2,p3) p2=p3 except EOFError : print(abs(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p1 : OclAny := complex((argument * (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name float))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ','))))))) ))))))))) ))))))))) ))))))))) ; var p2 : OclAny := complex((argument * (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name float))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ','))))))) ))))))))) ))))))))) ))))))))) ; var ans : int := 0 ; skip ; try ( while true do ( var p3 : OclAny := complex((argument * (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name float))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ','))))))) ))))))))) ))))))))) ))))))))) ; ans := ans + area(p1, p2, p3) ; p2 := p3)) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) )))))))))) ))); operation area(p : OclAny, q : OclAny, r : OclAny) : OclAny pre: true post: true activity: return ((p - r).conjugate() * (q - r)).imag / 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cntWays(string,n): x=n+1 ; ways=x*x*(x*x-1)//12 ; return ways ; if __name__=="__main__" : string="ab" ; n=len(string); print(cntWays(string,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( string := "ab"; ; n := (string)->size(); ; execute (cntWays(string, n))->display(); ) else skip; operation cntWays(string : OclAny, n : OclAny) pre: true post: true activity: var x : OclAny := n + 1; ; var ways : int := x * x * (x * x - 1) div 12; ; return ways;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def round(n): a=(n//10)*10 b=a+10 return(b if n-a>b-n else a) n=4722 print(round(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4722 ; execute ((n)->round())->display(); operation round(n : OclAny) : OclAny pre: true post: true activity: var a : int := (n div 10) * 10 ; var b : int := a + 10 ; return (if (n - a->compareTo(b - n)) > 0 then b else a endif); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) pse,nse=[-1]*n,[n]*n stack,stack2=[0],[n-1] for i in range(1,n): while(len(stack)and arr[i]toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var pse : OclAny := null; var nse : OclAny := null; Sequence{pse,nse} := Sequence{MatrixLib.elementwiseMult(Sequence{ -1 }, n),MatrixLib.elementwiseMult(Sequence{ n }, n)} ; var stack : OclAny := null; var stack2 : OclAny := null; Sequence{stack,stack2} := Sequence{Sequence{ 0 },Sequence{ n - 1 }} ; for i : Integer.subrange(1, n-1) do ( while ((stack)->size() & (arr[i+1]->compareTo(arr[stack->last()+1])) < 0) do ( nse[stack->last()+1] := i) ; execute ((i) : stack) ; while ((stack2)->size() & (arr[n - i - 1+1]->compareTo(arr[stack2->last()+1])) < 0) do ( pse[stack2->last()+1] := n - i - 1) ; execute ((n - i - 1) : stack2)) ; var dic : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( dic[arr[i+1]+1] := Set{dic.get(arr[i+1], 0), (nse[i+1] - pse[i+1] - 1)}->max()) ; var out : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : dic do ( out[dic[i+1]+1] := Set{out[dic[i+1]+1], i}->max()) ; var temp : OclAny := out->last() ; for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( if (out[i+1]->compareTo(out[i + 1+1])) < 0 then ( out[i+1] := out[i + 1+1] ) else skip) ; execute (StringLib.sumStringsWithSeparator(((out->tail())->collect( _x | (OclType["String"])->apply(_x) )), (" ")))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(i)for i in input().split()] l=[-1 for _ in range(n)] r=[n for _ in range(n)] answer=[0 for _ in range(n+1)] s=[] for i in range(n): while s and a[s[-1]]>=a[i]: s.pop() if s : l[i]=s[-1] s.append(i) while s : s.pop() for i in range(n-1,-1,-1): while s and a[s[-1]]>=a[i]: s.pop() if s : r[i]=s[-1] s.append(i) for i in range(n): length=r[i]-l[i]-1 answer[length]=max(answer[length],a[i]) for i in range(n-1,-1,-1): answer[i]=max(answer[i],answer[i+1]) answer=answer[1 :] print(*answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var l : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (-1)) ; var r : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (n)) ; var answer : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (0)) ; var s : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( while s & (a[s->last()+1]->compareTo(a[i+1])) >= 0 do ( s := s->front()) ; if s then ( l[i+1] := s->last() ) else skip ; execute ((i) : s)) ; while s do ( s := s->front()) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( while s & (a[s->last()+1]->compareTo(a[i+1])) >= 0 do ( s := s->front()) ; if s then ( r[i+1] := s->last() ) else skip ; execute ((i) : s)) ; for i : Integer.subrange(0, n-1) do ( var length : double := r[i+1] - l[i+1] - 1 ; answer[length+1] := Set{answer[length+1], a[i+1]}->max()) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( answer[i+1] := Set{answer[i+1], answer[i + 1+1]}->max()) ; answer := answer->tail() ; execute ((argument * (test (logical_test (comparison (expr (atom (name answer))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(sys.stdin.readline()) heights=list(map(int,sys.stdin.readline().strip().split())) left=[-1 for _ in range(n)] right=[-1 for _ in range(n)] dp=[-1 for _ in range(n+1)] s=[] for i in range(n): while s : if heights[s[-1]]>=heights[i]: s.pop() else : break if s : left[i]=s[-1] s.append(i) s=[] for i in range(n-1,-1,-1): while s : if heights[s[-1]]>=heights[i]: s.pop() else : break if s : right[i]=s[-1] s.append(i) for i in range(n): span=right[i]-left[i]-1 dp[span]=max(dp[span],heights[i]) for i in range(n-1,0,-1): dp[i]=max(dp[i],dp[i+1]) for i in range(1,n+1): print(dp[i],end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var heights : Sequence := ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var left : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (-1)) ; var right : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (-1)) ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (-1)) ; var s : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( while s do ( if (heights[s->last()+1]->compareTo(heights[i+1])) >= 0 then ( s := s->front() ) else ( break )) ; if s then ( left[i+1] := s->last() ) else skip ; execute ((i) : s)) ; s := Sequence{} ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( while s do ( if (heights[s->last()+1]->compareTo(heights[i+1])) >= 0 then ( s := s->front() ) else ( break )) ; if s then ( right[i+1] := s->last() ) else skip ; execute ((i) : s)) ; for i : Integer.subrange(0, n-1) do ( var span : double := right[i+1] - left[i+1] - 1 ; dp[span+1] := Set{dp[span+1], heights[i+1]}->max()) ; for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( dp[i+1] := Set{dp[i+1], dp[i + 1+1]}->max()) ; for i : Integer.subrange(1, n + 1-1) do ( execute (dp[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) r=[0]*(n+1) a=[0]*(n+1) a[1 :-1]=list(map(int,input().split())) s=[(0,0)] for i in range(1,n+2): while a[i]toInteger() ; var r : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; a.subrange(1+1, -1) := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Sequence := Sequence{ Sequence{0, 0} } ; for i : Integer.subrange(1, n + 2-1) do ( while (a[i+1]->compareTo(s->last()->first())) < 0 do ( r[i - s->front()->last()[1+1] - 1+1] := Set{s->last()->first(), r[i - s->front()->last()[1+1] - 1+1]}->max() ; execute (s->last())->isDeleted()) ; s := s + Sequence{ Sequence{a[i+1], i} }) ; for i : Integer.subrange(0, n-1) do ( r->reverse()->at(-(-i - 2)) := Set{r->reverse()->at(-(-i - 2)), r->reverse()->at(-(-i - 1))}->max()) ; execute (StringLib.sumStringsWithSeparator(((r->tail())->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def LeadingZeros(x,y): if((x ^ y)<=(x & y)): print("Equal") elif((x &(~ y))>y): print(y) else : print(x) if __name__=='__main__' : x=10 y=16 LeadingZeros(x,y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( x := 10 ; y := 16 ; LeadingZeros(x, y) ) else skip; operation LeadingZeros(x : OclAny, y : OclAny) pre: true post: true activity: if (((MathLib.bitwiseXor(x, y))->compareTo((MathLib.bitwiseAnd(x, y)))) <= 0) then ( execute ("Equal")->display() ) else (if (((MathLib.bitwiseAnd(x, (MathLib.bitwiseNot(y))))->compareTo(y)) > 0) then ( execute (y)->display() ) else ( execute (x)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os from sys import stdin,stdout def solve(tc): a=int(stdin.readline().strip()) print(1 if a==0 else 0) tcs=1 tc=1 while tc<=tcs : solve(tc) tc+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var tcs : int := 1 ; tc := 1 ; while (tc->compareTo(tcs)) <= 0 do ( solve(tc) ; tc := tc + 1); operation solve(tc : OclAny) pre: true post: true activity: var a : int := ("" + ((stdin.readLine()->trim())))->toInteger() ; execute (if a = 0 then 1 else 0 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def makeOdd(n): if n % 2!=0 : return 1 ; for i in range(2,n): if(n % i==0 and(int)(n/i)% 2==1): return i ; n=36 ; print(makeOdd(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 36; ; execute (makeOdd(n))->display();; operation makeOdd(n : OclAny) pre: true post: true activity: if n mod 2 /= 0 then ( return 1; ) else skip ; for i : Integer.subrange(2, n-1) do ( if (n mod i = 0 & (OclType["int"])(n / i) mod 2 = 1) then ( return i; ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,input().split()) H=list(map(int,input().split())) H=sorted(H,reverse=True) print(sum(H[K :])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var H : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; H := H->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; execute ((H.subrange(K+1))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import random import heapq import bisect import math import time class Solution2 : def solve(self,A1,A2): pass def gcd(a,b): if not b : return a return gcd(b,a % b) def lcm(a,b): return b*a//gcd(b,a) class Solution : def solve(self,scores): out=1 a=0 b=0 for x,y in scores : out+=max(min(x,y)-max(a,b)+int(a!=b),0) a,b=x,y return out sol=Solution() sol2=Solution2() for test_case in range(1): N=input() a=[] for _ in range(int(N)): a.append([int(c)for c in input().split()]) out=sol.solve(a) print(str(out)) ------------------------------------------------------------ OCL File: --------- class Solution2 { static operation newSolution2() : Solution2 pre: true post: Solution2->exists( _x | result = _x ); operation solve(A1 : OclAny,A2 : OclAny) pre: true post: true activity: skip; } class Solution { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation solve(scores : OclAny) : OclAny pre: true post: true activity: var out : int := 1 ; a := 0 ; b := 0 ; for _tuple : scores do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); out := out + Set{Set{x, y}->min() - Set{a, b}->max() + ("" + ((a /= b)))->toInteger(), 0}->max() ; Sequence{a,b} := Sequence{x,y}) ; return out; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var sol : Solution := (Solution.newSolution()).initialise() ; var sol2 : Solution2 := (Solution2.newSolution2()).initialise() ; for test_case : Integer.subrange(0, 1-1) do ( var N : String := (OclFile["System.in"]).readLine() ; a := Sequence{} ; for _anon : Integer.subrange(0, ("" + ((N)))->toInteger()-1) do ( execute ((input().split()->select(c | true)->collect(c | (("" + ((c)))->toInteger()))) : a)) ; out := sol.solve(a) ; execute (("" + ((out))))->display()); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if not(b) then ( return a ) else skip ; return gcd(b, a mod b); operation lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return b * a div gcd(b, a); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline ri=lambda : int(input()) rs=lambda : input().rstrip() ril=lambda : list(map(int,input().split())) rsl=lambda : input().rstrip().split() ris=lambda n :[ri()for _ in range(n)] rss=lambda n :[rs()for _ in range(n)] rils=lambda n :[ril()for _ in range(n)] rsls=lambda n :[rsl()for _ in range(n)] n,k=ril() ls=ril() if n<=k : print(0) exit() ls.sort() if k>0 : ls=ls[:-k] print(sum(ls)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var ri : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var rs : Function := lambda $$ : OclAny in (input().rstrip()) ; var ril : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var rsl : Function := lambda $$ : OclAny in (input().rstrip().split()) ; var ris : Function := lambda n : OclAny in (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (ri->apply()))) ; var rss : Function := lambda n : OclAny in (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (rs->apply()))) ; var rils : Function := lambda n : OclAny in (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (ril->apply()))) ; var rsls : Function := lambda n : OclAny in (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (rsl->apply()))) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ril->apply() ; var ls : OclAny := ril->apply() ; if (n->compareTo(k)) <= 0 then ( execute (0)->display() ; exit() ) else skip ; ls := ls->sort() ; if k > 0 then ( ls := ls.subrange(1,-k) ) else skip ; execute ((ls)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=list(map(int,input().split())) b=list(map(int,input().split())) b.sort() x=a[1] y=a[0] if x>=y : print(0) else : z=y-x b=b[0 : z] print(sum(b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; b := b->sort() ; var x : OclAny := a[1+1] ; var y : OclAny := a->first() ; if (x->compareTo(y)) >= 0 then ( execute (0)->display() ) else ( var z : double := y - x ; b := b.subrange(0+1, z) ; execute ((b)->sum())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,input().split()) H=list(map(int,input().split())) H.sort(reverse=True) count=0 for i in range(N): while(1): if H[i]==0 : break else : if K>0 : H[i]=0 K-=1 else : count+=H[i] H[i]=0 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var H : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; H := H->sort() ; var count : int := 0 ; for i : Integer.subrange(0, N-1) do ( while (1) do ( if H[i+1] = 0 then ( break ) else ( if K > 0 then ( H[i+1] := 0 ; K := K - 1 ) else ( count := count + H[i+1] ; H[i+1] := 0 ) ))) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=[int(n)for n in input().split()] H=[int(n)for n in input().split()] if K>=N : a=0 else : a=sum(sorted(H)[: N-K]) print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := input().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; var H : Sequence := input().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; if (K->compareTo(N)) >= 0 then ( var a : int := 0 ) else ( a := (sorted(H).subrange(1,N - K))->sum() ) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minMoves(n,a,k): ct1=[0 for i in range(k)] ct0=[0 for i in range(k)] moves=0 for i in range(n): if(a[i]==1): ct1[i % k]+=1 else : ct0[i % k]+=1 for i in range(k): moves+=min(ct1[i],ct0[i]) return moves if __name__=='__main__' : k=2 a=[1,0,0,0,1,0] n=len(a) print(minMoves(n,a,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( k := 2 ; a := Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 0 }))))) ; n := (a)->size() ; execute (minMoves(n, a, k))->display() ) else skip; operation minMoves(n : OclAny, a : OclAny, k : OclAny) : OclAny pre: true post: true activity: var ct1 : Sequence := Integer.subrange(0, k-1)->select(i | true)->collect(i | (0)) ; var ct0 : Sequence := Integer.subrange(0, k-1)->select(i | true)->collect(i | (0)) ; var moves : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] = 1) then ( ct1[i mod k+1] := ct1[i mod k+1] + 1 ) else ( ct0[i mod k+1] := ct0[i mod k+1] + 1 )) ; for i : Integer.subrange(0, k-1) do ( moves := moves + Set{ct1[i+1], ct0[i+1]}->min()) ; return moves; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left as bl def main(): n,m=map(int,input().split()) plst=[] xlst=set() ylst=set() for _ in range(n): x,y=map(int,input().split()) plst.append((x,y)) xlst.add(x) ylst.add(y) xlst=sorted(list(xlst)) ylst=sorted(list(ylst)) xdic={} ydic={} for i,x in enumerate(xlst): xdic[x]=i for i,y in enumerate(ylst): ydic[y]=i xlen=len(xlst) ylen=len(ylst) mp=[[0]*(xlen+1)for _ in range(ylen+1)] for x,y in plst : mp[ydic[y]+1][xdic[x]+1]+=1 for y in range(1,ylen+1): acc=0 for x in range(1,xlen+1): acc+=mp[y][x] mp[y][x]=acc+mp[y-1][x] for _ in range(m): x1,y1,x2,y2=map(int,input().split()) x1i=bl(xlst,x1) y1i=bl(ylst,y1) x2i=bl(xlst,x2) y2i=bl(ylst,y2) if x2icollect( _x | (OclType["int"])->apply(_x) ) ; var plst : Sequence := Sequence{} ; var xlst : Set := Set{}->union(()) ; var ylst : Set := Set{}->union(()) ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{x, y}) : plst) ; execute ((x) : xlst) ; execute ((y) : ylst)) ; xlst := (xlst)->sort() ; ylst := (ylst)->sort() ; var xdic : OclAny := Set{} ; var ydic : OclAny := Set{} ; for _tuple : Integer.subrange(1, (xlst)->size())->collect( _indx | Sequence{_indx-1, (xlst)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); xdic[x+1] := i) ; for _tuple : Integer.subrange(1, (ylst)->size())->collect( _indx | Sequence{_indx-1, (ylst)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); ydic[y+1] := i) ; var xlen : int := (xlst)->size() ; var ylen : int := (ylst)->size() ; var mp : Sequence := Integer.subrange(0, ylen + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (xlen + 1)))) ; for _tuple : plst do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); mp[ydic[y+1] + 1+1][xdic[x+1] + 1+1] := mp[ydic[y+1] + 1+1][xdic[x+1] + 1+1] + 1) ; for y : Integer.subrange(1, ylen + 1-1) do ( var acc : int := 0 ; for x : Integer.subrange(1, xlen + 1-1) do ( acc := acc + mp[y+1][x+1] ; mp[y+1][x+1] := acc + mp[y - 1+1][x+1])) ; for _anon : Integer.subrange(0, m-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x1i : OclAny := bl(xlst, x1) ; var y1i : OclAny := bl(ylst, y1) ; var x2i : OclAny := bl(xlst, x2) ; var y2i : OclAny := bl(ylst, y2) ; if (x2i->compareTo(xlen)) < 0 & xlst[x2i+1] = x2 then ( x2i := x2i + 1 ) else skip ; if (y2i->compareTo(ylen)) < 0 & ylst[y2i+1] = y2 then ( y2i := y2i + 1 ) else skip ; execute (mp[y2i+1][x2i+1] - mp[y2i+1][x1i+1] - mp[y1i+1][x2i+1] + mp[y1i+1][x1i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Queue : def __init__(self): self.lst=[] def is_empty(self): return self.lst==[] def enqueue(self,elem): self.lst.append(elem) def dequeue(self): return self.lst.pop(0) def bfs(x,num): q=Queue() q.enqueue(num) while(not q.is_empty()): num=q.dequeue() if num<=x : print(str(num),end=' ') last_dig=num % 10 if last_dig==0 : q.enqueue((num*10)+(last_dig+1)) elif last_dig==9 : q.enqueue((num*10)+(last_dig-1)) else : q.enqueue((num*10)+(last_dig-1)) q.enqueue((num*10)+(last_dig+1)) def printJumping(x): print(str(0),end=' ') for i in range(1,10): bfs(x,i) x=40 printJumping(x) ------------------------------------------------------------ OCL File: --------- class Queue { static operation newQueue() : Queue pre: true post: Queue->exists( _x | result = _x ); attribute lst : Sequence := Sequence{}; operation initialise() : Queue pre: true post: true activity: self.lst := Sequence{}; return self; operation is_empty() : OclAny pre: true post: true activity: return self.lst = Sequence{}; operation enqueue(elem : OclAny) pre: true post: true activity: (expr (atom (name self)) (trailer . (name lst)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name elem)))))))) )))); operation dequeue() : OclAny pre: true post: true activity: return self.lst->at(0`firstArg+1); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; x := 40 ; printJumping(x); operation bfs(x : OclAny, num : OclAny) pre: true post: true activity: var q : Queue := (Queue.newQueue()).initialise() ; q.enqueue(num) ; while (not(q.is_empty())) do ( num := q.dequeue() ; if (num->compareTo(x)) <= 0 then ( execute (("" + ((num))))->display() ; var last_dig : int := num mod 10 ; if last_dig = 0 then ( q.enqueue((num * 10) + (last_dig + 1)) ) else (if last_dig = 9 then ( q.enqueue((num * 10) + (last_dig - 1)) ) else ( q.enqueue((num * 10) + (last_dig - 1)) ; q.enqueue((num * 10) + (last_dig + 1)) ) ) ) else skip); operation printJumping(x : OclAny) pre: true post: true activity: execute (("" + ((0))))->display() ; for i : Integer.subrange(1, 10-1) do ( bfs(x, i)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def countWindowDistinct(win,k): dist_count=0 for i in range(k): j=0 while junion(Sequence{2}->union(Sequence{1}->union(Sequence{3}->union(Sequence{4}->union(Sequence{2}->union(Sequence{ 3 })))))) ; k := 4 ; n := (arr)->size() ; countDistinct(arr, n, k); operation countWindowDistinct(win : OclAny, k : OclAny) : OclAny pre: true post: true activity: var dist_count : int := 0 ; for i : Integer.subrange(0, k-1) do ( var j : int := 0 ; while (j->compareTo(i)) < 0 do ( if (win[i+1] = win[j+1]) then ( break ) else ( j := j + 1 )) ; if (j = i) then ( dist_count := dist_count + 1 ) else skip) ; return dist_count; operation countDistinct(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n - k + 1-1) do ( execute (countWindowDistinct(arr.subrange(i+1, k + i), k))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=input().split() last=0 s=0 for i in range(n): now=int(a[i]) d=0 if now<=last : d=int((last-now+k)/k) s+=d last=now+d*k print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := input().split() ; var last : int := 0 ; var s : int := 0 ; for i : Integer.subrange(0, n-1) do ( var now : int := ("" + ((a[i+1])))->toInteger() ; var d : int := 0 ; if (now->compareTo(last)) <= 0 then ( d := ("" + (((last - now + k) / k)))->toInteger() ; s := s + d ) else skip ; last := now + d * k) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,sys,io,math from tokenize import Triple from array import array from math import* I=lambda :[*map(int,sys.stdin.readline().split())] IS=lambda : input() IN=lambda : int(input()) IF=lambda : float(input()) n=IN() l=I() if n==1 : print(0) else : l=list(set(l)) if len(l)==1 : print(0) elif len(l)>3 : print(-1) else : l.sort() if len(l)==1 : print(0) elif len(l)==2 : if(l[1]-l[0])% 2==0 : print((l[1]-l[0])//2) else : print((l[1]-l[0])) else : if l[1]-l[0]!=l[2]-l[1]: print(-1) else : print(l[1]-l[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var I : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var IS : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var IN : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var IF : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toReal()) ; var n : OclAny := IN->apply() ; var l : OclAny := I->apply() ; if n = 1 then ( execute (0)->display() ) else ( l := (Set{}->union((l))) ; if (l)->size() = 1 then ( execute (0)->display() ) else (if (l)->size() > 3 then ( execute (-1)->display() ) else ( l := l->sort() ; if (l)->size() = 1 then ( execute (0)->display() ) else (if (l)->size() = 2 then ( if (l[1+1] - l->first()) mod 2 = 0 then ( execute ((l[1+1] - l->first()) div 2)->display() ) else ( execute ((l[1+1] - l->first()))->display() ) ) else ( if l[1+1] - l->first() /= l[2+1] - l[1+1] then ( execute (-1)->display() ) else ( execute (l[1+1] - l->first())->display() ) ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _=input() arr=list(set(map(int,input().split()))) if len(arr)>3 : print(-1) elif len(arr)==3 : avg=sum(arr)/3 if avg in arr : print(int(max(arr)-avg)) else : print(-1) elif len(arr)==2 : if sum(arr)% 2==0 : print(max(arr)-int(sum(arr)/2)) else : print(abs(arr[0]-arr[1])) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _anon : String := (OclFile["System.in"]).readLine() ; var arr : Sequence := (Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; if (arr)->size() > 3 then ( execute (-1)->display() ) else (if (arr)->size() = 3 then ( var avg : double := (arr)->sum() / 3 ; if (arr)->includes(avg) then ( execute (("" + (((arr)->max() - avg)))->toInteger())->display() ) else ( execute (-1)->display() ) ) else (if (arr)->size() = 2 then ( if (arr)->sum() mod 2 = 0 then ( execute ((arr)->max() - ("" + (((arr)->sum() / 2)))->toInteger())->display() ) else ( execute ((arr->first() - arr[1+1])->abs())->display() ) ) else ( execute (0)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=sorted(set(map(int,input().split()))) if len(s)>3 : print(-1) elif len(s)==3 : if s[2]-s[1]==s[1]-s[0]: print(s[2]-s[1]) else : print(-1) elif len(s)==2 : if(s[1]-s[0])% 2 : print(s[1]-s[0]) else : print((s[1]-s[0])//2) elif len(s)==1 : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->sort() ; if (s)->size() > 3 then ( execute (-1)->display() ) else (if (s)->size() = 3 then ( if s[2+1] - s[1+1] = s[1+1] - s->first() then ( execute (s[2+1] - s[1+1])->display() ) else ( execute (-1)->display() ) ) else (if (s)->size() = 2 then ( if (s[1+1] - s->first()) mod 2 then ( execute (s[1+1] - s->first())->display() ) else ( execute ((s[1+1] - s->first()) div 2)->display() ) ) else (if (s)->size() = 1 then ( execute (0)->display() ) else skip ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[[0,0]]+[[*map(int,input().split())]for _ in[0]*n]; count=0 for i in range(n): if a[i][0]!=a[i+1][0]or a[i][1]!=a[i+1][1]: count+=max(0,min(a[i+1])-max(a[i])+(a[i+1][0]!=a[i+1][1])) print(count+(a[-1][0]==a[-1][1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{ Sequence{0}->union(Sequence{ 0 }) }->union(MatrixLib.elementwiseMult(Sequence{ 0 }, n)->select(_anon | true)->collect(_anon | ((input().split())->collect( _x | (OclType["int"])->apply(_x) )))); var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( if a[i+1]->first() /= a[i + 1+1]->first() or a[i+1][1+1] /= a[i + 1+1][1+1] then ( count := count + Set{0, (a[i + 1+1])->min() - (a[i+1])->max() + (a[i + 1+1]->first() /= a[i + 1+1][1+1])}->max() ) else skip) ; execute (count + (a->last()->first() = a->last()[1+1]))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin n=int(stdin.readline()) a=list(map(int,stdin.readline().split())) b=list(set(a)) b.sort() if len(b)==1 : print(0) elif len(b)==2 : if(b[1]-b[0])% 2!=0 : print(b[1]-b[0]) else : print((b[1]-b[0])//2) elif len(b)==3 : if(b[2]-b[0])% 2!=0 : print(-1) else : ans=(b[2]-b[0])//2 if b[1]==b[0]+ans : print(ans) else : print(-1) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + ((stdin.readLine())))->toInteger() ; var a : Sequence := ((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := (Set{}->union((a))) ; b := b->sort() ; if (b)->size() = 1 then ( execute (0)->display() ) else (if (b)->size() = 2 then ( if (b[1+1] - b->first()) mod 2 /= 0 then ( execute (b[1+1] - b->first())->display() ) else ( execute ((b[1+1] - b->first()) div 2)->display() ) ) else (if (b)->size() = 3 then ( if (b[2+1] - b->first()) mod 2 /= 0 then ( execute (-1)->display() ) else ( var ans : int := (b[2+1] - b->first()) div 2 ; if b[1+1] = b->first() + ans then ( execute (ans)->display() ) else ( execute (-1)->display() ) ) ) else ( execute (-1)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) a=sorted(list(set(a))) if(len(a)==1): print(0) elif(len(a)==2): if(a[1]-a[0])% 2==0 : print((a[1]-a[0])//2) else : print(a[1]-a[0]) elif(len(a)==3): if(a[2]-a[1]==a[1]-a[0]): print(a[1]-a[0]) else : print(-1) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := (Set{}->union((a)))->sort() ; if ((a)->size() = 1) then ( execute (0)->display() ) else (if ((a)->size() = 2) then ( if (a[1+1] - a->first()) mod 2 = 0 then ( execute ((a[1+1] - a->first()) div 2)->display() ) else ( execute (a[1+1] - a->first())->display() ) ) else (if ((a)->size() = 3) then ( if (a[2+1] - a[1+1] = a[1+1] - a->first()) then ( execute (a[1+1] - a->first())->display() ) else ( execute (-1)->display() ) ) else ( execute (-1)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculateFraction(num,den): if(num==0): return "0" sign=-1 if(num<0)^(den<0)else 1 num=abs(num) den=abs(den) initial=num//den res="" if(sign==-1): res+="-" res+=str(initial) if(num % den==0): return res res+="." rem=num % den mp={} index=0 repeating=False while(rem>0 and not repeating): if(rem in mp): index=mp[rem] repeating=True break else : mp[rem]=len(res) rem=rem*10 temp=rem//den res+=str(temp) rem=rem % den if(repeating): x=res[: index] x+=res[index :] res=x else : res+="0" return res def find_decimal(decimal,c): for i in range(2,len(decimal)): if decimal[i]==str(c): print(i-1) return print(-1) n=input() numbers=n.split() num=int(numbers[0]) den=int(numbers[1]) digit=int(numbers[2]) fraction=calculateFraction(num,den) find_decimal(fraction,digit) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : String := (OclFile["System.in"]).readLine() ; var numbers : OclAny := n.split() ; num := ("" + ((numbers->first())))->toInteger() ; den := ("" + ((numbers[1+1])))->toInteger() ; var digit : int := ("" + ((numbers[2+1])))->toInteger() ; var fraction : OclAny := calculateFraction(num, den) ; find_decimal(fraction, digit); operation calculateFraction(num : OclAny, den : OclAny) : OclAny pre: true post: true activity: if (num = 0) then ( return "0" ) else skip ; var sign : int := if MathLib.bitwiseXor((num < 0), (den < 0)) then -1 else 1 endif ; num := (num)->abs() ; den := (den)->abs() ; var initial : int := num div den ; var res : String := "" ; if (sign = -1) then ( res := res + "-" ) else skip ; res := res + ("" + ((initial))) ; if (num mod den = 0) then ( return res ) else skip ; res := res + "." ; var rem : int := num mod den ; var mp : OclAny := Set{} ; var index : int := 0 ; var repeating : boolean := false ; while (rem > 0 & not(repeating)) do ( if ((mp)->includes(rem)) then ( index := mp[rem+1] ; repeating := true ; break ) else ( mp[rem+1] := (res)->size() ) ; rem := rem * 10 ; var temp : int := rem div den ; res := res + ("" + ((temp))) ; rem := rem mod den) ; if (repeating) then ( var x : OclAny := res.subrange(1,index) ; x := x + res.subrange(index+1) ; res := x ) else ( res := res + "0" ) ; return res; operation find_decimal(decimal : OclAny, c : OclAny) pre: true post: true activity: for i : Integer.subrange(2, (decimal)->size()-1) do ( if decimal[i+1] = ("" + ((c))) then ( execute (i - 1)->display() ; return ) else skip) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculateFraction(num,den,c): pos=1 if(num==0): return-1 sign=-1 if(num<0)^(den<0)else 1 num=abs(num) den=abs(den) initial=num//den res="" if(sign==-1): res+="-" res+=str(initial) if(num % den==0): return-1 res+="." rem=num % den mp={} index=0 repeating=False while(rem>0 and not repeating): if(rem in mp): index=mp[rem] repeating=True break else : mp[rem]=len(res) rem=rem*10 temp=rem//den res+=str(temp) rem=rem % den if(temp==c): return pos pos+=1 if repeating : pos=-1 return-1 if c!=0 else pos if __name__=="__main__" : a,b,c=input().split(" ") print(calculateFraction(int(a),int(b),int(c))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b,c} := input().split(" ") ; execute (calculateFraction(("" + ((a)))->toInteger(), ("" + ((b)))->toInteger(), ("" + ((c)))->toInteger()))->display() ) else skip; operation calculateFraction(num : OclAny, den : OclAny, c : OclAny) : OclAny pre: true post: true activity: var pos : int := 1 ; if (num = 0) then ( return -1 ) else skip ; var sign : int := if MathLib.bitwiseXor((num < 0), (den < 0)) then -1 else 1 endif ; num := (num)->abs() ; den := (den)->abs() ; var initial : int := num div den ; var res : String := "" ; if (sign = -1) then ( res := res + "-" ) else skip ; res := res + ("" + ((initial))) ; if (num mod den = 0) then ( return -1 ) else skip ; res := res + "." ; var rem : int := num mod den ; var mp : OclAny := Set{} ; var index : int := 0 ; var repeating : boolean := false ; while (rem > 0 & not(repeating)) do ( if ((mp)->includes(rem)) then ( index := mp[rem+1] ; repeating := true ; break ) else ( mp[rem+1] := (res)->size() ) ; rem := rem * 10 ; var temp : int := rem div den ; res := res + ("" + ((temp))) ; rem := rem mod den ; if (temp = c) then ( return pos ) else skip ; pos := pos + 1) ; if repeating then ( pos := -1 ) else skip ; return if c /= 0 then -1 else pos endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def frac_to_string(num : int,den : int,target : int)->str : num,den=abs(num),abs(den) if num % den==0 : if target==0 : return 1 else : return-1 rem=num % den rems={} is_repeating=False location=1 while rem>0 and not is_repeating : if rem in rems : is_repeating=True return-1 else : rems[rem]=location rem*=10 temp=rem//den rem %=den if temp==target : return location if rem*10==target : return location+1 location+=1 return-1 def read_data(): nums=[int(n)for n in input().split()] print(frac_to_string(nums[0],nums[1],nums[2])) read_data() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; read_data(); operation frac_to_string(num : int, den : int, target : int) : String pre: true post: true activity: var num : OclAny := null; var den : OclAny := null; Sequence{num,den} := Sequence{(num)->abs(),(den)->abs()} ; if num mod den = 0 then ( if target = 0 then ( return 1 ) else ( return -1 ) ) else skip ; var rem : int := num mod den ; var rems : OclAny := Set{} ; var is_repeating : boolean := false ; var location : int := 1 ; while rem > 0 & not(is_repeating) do ( if (rems)->includes(rem) then ( is_repeating := true ; return -1 ) else ( rems[rem+1] := location ) ; rem := rem * 10 ; var temp : int := rem div den ; rem := rem mod den ; if temp = target then ( return location ) else skip ; if rem * 10 = target then ( return location + 1 ) else skip ; location := location + 1) ; return -1; operation read_data() pre: true post: true activity: var nums : Sequence := input().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; execute (frac_to_string(nums->first(), nums[1+1], nums[2+1]))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def frac_to_string(num : int,den : int,target : int)->str : num,den=abs(num),abs(den) if num % den==0 : if target==0 : return 1 else : return-1 rem=num % den rems={} is_repeating=False location=1 while rem>0 and not is_repeating : if rem in rems : is_repeating=True return-1 else : rems[rem]=location rem*=10 temp=rem//den rem %=den if temp==target : return location if rem*10==target : return location+1 location+=1 return-1 def read_data(): nums=[int(n)for n in input().split()] print(frac_to_string(nums[0],nums[1],nums[2])) read_data() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; read_data(); operation frac_to_string(num : int, den : int, target : int) : String pre: true post: true activity: var num : OclAny := null; var den : OclAny := null; Sequence{num,den} := Sequence{(num)->abs(),(den)->abs()} ; if num mod den = 0 then ( if target = 0 then ( return 1 ) else ( return -1 ) ) else skip ; var rem : int := num mod den ; var rems : OclAny := Set{} ; var is_repeating : boolean := false ; var location : int := 1 ; while rem > 0 & not(is_repeating) do ( if (rems)->includes(rem) then ( is_repeating := true ; return -1 ) else ( rems[rem+1] := location ) ; rem := rem * 10 ; var temp : int := rem div den ; rem := rem mod den ; if temp = target then ( return location ) else skip ; if rem * 10 = target then ( return location + 1 ) else skip ; location := location + 1) ; return -1; operation read_data() pre: true post: true activity: var nums : Sequence := input().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; execute (frac_to_string(nums->first(), nums[1+1], nums[2+1]))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): k,nn=input().split() k,nn=int(k),int(nn) print(9*(k-1)+nn) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var k : OclAny := null; var nn : OclAny := null; Sequence{k,nn} := input().split() ; var k : OclAny := null; var nn : OclAny := null; Sequence{k,nn} := Sequence{("" + ((k)))->toInteger(),("" + ((nn)))->toInteger()} ; execute (9 * (k - 1) + nn)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculateFraction(num,den): if(num==0): return "0" sign=-1 if(num<0)^(den<0)else 1 num=abs(num) den=abs(den) initial=num//den res="" if(sign==-1): res+="-" res+=str(initial) if(num % den==0): return res res+="." rem=num % den mp={} index=0 repeating=False while(rem>0 and not repeating): if(rem in mp): index=mp[rem] repeating=True break else : mp[rem]=len(res) rem=rem*10 temp=rem//den res+=str(temp) rem=rem % den if(repeating): x=res[: index] x+=res[index :] res=x else : res+="0" return res def find_decimal(decimal,c): for i in range(2,len(decimal)): if decimal[i]==str(c): print(i-1) return print(-1) n=input() numbers=n.split() num=int(numbers[0]) den=int(numbers[1]) digit=int(numbers[2]) fraction=calculateFraction(num,den) find_decimal(fraction,digit) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : String := (OclFile["System.in"]).readLine() ; var numbers : OclAny := n.split() ; num := ("" + ((numbers->first())))->toInteger() ; den := ("" + ((numbers[1+1])))->toInteger() ; var digit : int := ("" + ((numbers[2+1])))->toInteger() ; var fraction : OclAny := calculateFraction(num, den) ; find_decimal(fraction, digit); operation calculateFraction(num : OclAny, den : OclAny) : OclAny pre: true post: true activity: if (num = 0) then ( return "0" ) else skip ; var sign : int := if MathLib.bitwiseXor((num < 0), (den < 0)) then -1 else 1 endif ; num := (num)->abs() ; den := (den)->abs() ; var initial : int := num div den ; var res : String := "" ; if (sign = -1) then ( res := res + "-" ) else skip ; res := res + ("" + ((initial))) ; if (num mod den = 0) then ( return res ) else skip ; res := res + "." ; var rem : int := num mod den ; var mp : OclAny := Set{} ; var index : int := 0 ; var repeating : boolean := false ; while (rem > 0 & not(repeating)) do ( if ((mp)->includes(rem)) then ( index := mp[rem+1] ; repeating := true ; break ) else ( mp[rem+1] := (res)->size() ) ; rem := rem * 10 ; var temp : int := rem div den ; res := res + ("" + ((temp))) ; rem := rem mod den) ; if (repeating) then ( var x : OclAny := res.subrange(1,index) ; x := x + res.subrange(index+1) ; res := x ) else ( res := res + "0" ) ; return res; operation find_decimal(decimal : OclAny, c : OclAny) pre: true post: true activity: for i : Integer.subrange(2, (decimal)->size()-1) do ( if decimal[i+1] = ("" + ((c))) then ( execute (i - 1)->display() ; return ) else skip) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) if N &(N-1)==0 : print("No") else : print("Yes") if N % 2==1 : k=N//2 for i in range(1,k+1): print(2*i,2*i+1) print(2*i+1,1) print(1,2*i+N) print(2*i+N,2*i+1+N) print(1+N,2) else : k=N//2-1 for i in range(1,k+1): print(2*i,2*i+1) print(2*i+1,1) print(1,2*i+N) print(2*i+N,2*i+1+N) print(1+N,2) n=N.bit_length()-1 a=2**n b=N+1-a print(N,a+N) print(2*N,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if MathLib.bitwiseAnd(N, (N - 1)) = 0 then ( execute ("No")->display() ) else ( execute ("Yes")->display() ; if N mod 2 = 1 then ( var k : int := N div 2 ; for i : Integer.subrange(1, k + 1-1) do ( execute (2 * i)->display() ; execute (2 * i + 1)->display() ; execute (1)->display() ; execute (2 * i + N)->display()) ; execute (1 + N)->display() ) else ( k := N div 2 - 1 ; for i : Integer.subrange(1, k + 1-1) do ( execute (2 * i)->display() ; execute (2 * i + 1)->display() ; execute (1)->display() ; execute (2 * i + N)->display()) ; execute (1 + N)->display() ; var n : double := N.bit_length() - 1 ; var a : double := (2)->pow(n) ; var b : double := N + 1 - a ; execute (N)->display() ; execute (2 * N)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k,i=int(input()),1,2 v=n+1 p=print while k*2toInteger(),1,2} ; var v : OclAny := n + 1 ; var p : OclAny := print ; while (k * 2->compareTo(v)) < 0 do ( k := k * 2) ; if MathLib.bitwiseAnd(-n, k) then ( p("No"); exit() ) else skip ; p("Yes", v, 3) ; while (i->compareTo(n)) < 0 do ( p(1, i, i, i + 1, 1, v + i, v + i, n + i); i := i + 2) ; if MathLib.bitwiseAnd(MathLib.bitwiseNot(n), 1) then ( p(n, v + k, n + n, MathLib.bitwiseXor(n, k)) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys N=int(input()) if N==1 : print("No") elif N % 2==1 : print("Yes") for i in range(2,N+1,2): print(1,i) print(i,i+1) print(1,i+1+N) print(i+1+N,i+N) print(N+1,3) else : a=None b=None for i in range(1,N): if N ^ itoInteger() ; if N = 1 then ( execute ("No")->display() ) else (if N mod 2 = 1 then ( execute ("Yes")->display() ; for i : Integer.subrange(2, N + 1-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( execute (1)->display() ; execute (i)->display() ; execute (1)->display() ; execute (i + 1 + N)->display()) ; execute (N + 1)->display() ) else ( var a : OclAny := null ; var b : OclAny := null ; for i : Integer.subrange(1, N-1) do ( if (MathLib.bitwiseXor(N, i)->compareTo(N)) < 0 then ( a := i ; b := MathLib.bitwiseXor(N, i) ) else skip) ; if a = null then ( execute ("No")->display() ; sys.exit() ) else skip ; execute ("Yes")->display() ; for i : Integer.subrange(2, N-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( execute (i)->display() ; execute (N + i)->display() ; if (Sequence{a, b})->excludes(i) & (Sequence{a, b})->excludes(i + 1) then ( execute (1)->display() ; execute (1)->display() ) else skip) ; var pa : int := MathLib.bitwiseXor(a, 1) ; var pb : int := MathLib.bitwiseXor(b, 1) ; execute (N + 1)->display() ; execute (a)->display() ; execute (N)->display() ; execute (b)->display() ; execute (1)->display() ; execute (1)->display() ; execute (pa + N)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minimumSets(arr,n,key): arr.sort(reverse=False) j=n-1 for i in range(0,j+1,1): if(arr[i]+arr[j]<=key): j-=1 return i+1 if __name__=='__main__' : arr=[3,5,3,4] n=len(arr) key=5 print(minimumSets(arr,n,key)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{3}->union(Sequence{5}->union(Sequence{3}->union(Sequence{ 4 }))) ; n := (arr)->size() ; key := 5 ; execute (minimumSets(arr, n, key))->display() ) else skip; operation minimumSets(arr : OclAny, n : OclAny, key : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var j : double := n - 1 ; for i : Integer.subrange(0, j + 1-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if ((arr[i+1] + arr[j+1]->compareTo(key)) <= 0) then ( j := j - 1 ) else skip) ; return i + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) b=N.bit_length() if 2**(b-1)==N : print('No') exit() ans=[(N+2,N+1),(N+2,3),(3,1),(1,2),(2,3+N)] for i in range(4,N,2): ans.append((1,i)) ans.append((1,i+1)) ans.append((i,N+i+1)) ans.append((i+1,N+i)) if N % 2==0 : for i in range(30,-1,-1): if N>2**i : a=2**i break b=N-a+1 ans.append((N,a)) ans.append((b,2*N)) print('Yes') for a,b in ans : print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : OclAny := N.bit_length() ; if (2)->pow((b - 1)) = N then ( execute ('No')->display() ; exit() ) else skip ; var ans : Sequence := Sequence{Sequence{N + 2, N + 1}}->union(Sequence{Sequence{N + 2, 3}}->union(Sequence{Sequence{3, 1}}->union(Sequence{Sequence{1, 2}}->union(Sequence{ Sequence{2, 3 + N} })))) ; for i : Integer.subrange(4, N-1)->select( $x | ($x - 4) mod 2 = 0 ) do ( execute ((Sequence{1, i}) : ans) ; execute ((Sequence{1, i + 1}) : ans) ; execute ((Sequence{i, N + i + 1}) : ans) ; execute ((Sequence{i + 1, N + i}) : ans)) ; if N mod 2 = 0 then ( for i : Integer.subrange(-1 + 1, 30)->reverse() do ( if (N->compareTo((2)->pow(i))) > 0 then ( var a : double := (2)->pow(i) ; break ) else skip) ; b := N - a + 1 ; execute ((Sequence{N, a}) : ans) ; execute ((Sequence{b, 2 * N}) : ans) ) else skip ; execute ('Yes')->display() ; for _tuple : ans do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys YES="Yes" NO="No" def solve(N : int): k=1 while kcompareTo(N)) < 0 do ( k := k * 2) ; if N = k then ( execute (NO)->display() ; return ) else skip ; execute (YES)->display() ; if N mod 2 = 0 then ( var n : double := N - 1 ; var even : boolean := true ) else ( n := N ; even := false ) ; for i : Integer.subrange(2, n + 1-1) do ( if i mod 2 = 0 then ( execute (1)->display() ; execute (N + i + 1)->display() ) else ( execute (i)->display() ; execute (N + i)->display() )) ; execute (3)->display() ; if even then ( k := k div 2 ; execute (N)->display() ; var a : int := MathLib.bitwiseXor(MathLib.bitwiseXor(N, k), 1) ; execute (a + N)->display() ) else skip ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var N : int := ("" + (((tokens).next())))->toInteger() ; solve(N); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def isNonHypotenuse(n): while(n % 2==0): n=n//2 for i in range(3,int(sqrt(n))+1,2): if(n % i==0): if((i-1)% 4==0): return False while(n % i==0): n=n//i if(n>2 and(n-1)% 4==0): return False else : return True def test(n): print("Testing for",n,":",end=" ") if(isNonHypotenuse(n)): print("YES") else : print("NO") if __name__=="__main__" : n=11 test(n) n=10 test(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( n := 11 ; test(n) ; n := 10 ; test(n) ) else skip; operation isNonHypotenuse(n : OclAny) : OclAny pre: true post: true activity: while (n mod 2 = 0) do ( n := n div 2) ; for i : Integer.subrange(3, ("" + ((sqrt(n))))->toInteger() + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if (n mod i = 0) then ( if ((i - 1) mod 4 = 0) then ( return false ) else skip ; while (n mod i = 0) do ( n := n div i) ) else skip) ; if (n > 2 & (n - 1) mod 4 = 0) then ( return false ) else ( return true ); operation test(n : OclAny) pre: true post: true activity: execute ("Testing for")->display() ; if (isNonHypotenuse(n)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def main(): a,b=map(int,input().split()) print(int((a+b+1)/2)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; main(); operation main() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (("" + (((a + b + 1) / 2)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) x=(a+b)/2 import math print(math.ceil(x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : double := (a + b) / 2 ; skip ; execute ((x)->ceil())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() print(min(n//11,s.count('8'))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; execute (Set{n div 11, s->count('8')}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ab=input().split() a,b=int(ab[0]),int(ab[1]) if(a+b)% 2==0 : print((a+b)//2) else : print((a+b)//2+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ab : OclAny := input().split() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{("" + ((ab->first())))->toInteger(),("" + ((ab[1+1])))->toInteger()} ; if (a + b) mod 2 = 0 then ( execute ((a + b) div 2)->display() ) else ( execute ((a + b) div 2 + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math ; a,b=[int(i)for i in input().split()]; print(math.ceil((a+b)/2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); ; execute (((a + b) / 2)->ceil())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=(int(i)for i in input().split()) X=a+b if X % 2==1 : ans=X//2+1 else : ans=X//2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var X : OclAny := a + b ; if X mod 2 = 1 then ( var ans : int := X div 2 + 1 ) else ( ans := X div 2 ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a=int(input()),[int(i)for i in input().split()] k=(2*sum(a)//n)+1 res=max(k,max(a)) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))} ; var k : int := (2 * (a)->sum() div n) + 1 ; var res : OclAny := Set{k, (a)->max()}->max() ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from typing import List,Tuple def inint(): return int(sys.stdin.readline()) def inlist(): return list(map(int,sys.stdin.readline().split())) def instr(): s=sys.stdin.readline() return list(s[: len(s)-1]) def invar(): return map(int,sys.stdin.readline().split()) n=inint() l=inlist() s=sum(l) avg=s/n print(max((int(2*avg)+1,max(l)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := inint() ; var l : OclAny := inlist() ; s := (l)->sum() ; var avg : double := s / n ; execute ((Sequence{("" + ((2 * avg)))->toInteger() + 1, (l)->max()})->max())->display(); operation inint() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inlist() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation instr() : OclAny pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; return (s.subrange(1,(s)->size() - 1)); operation invar() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=4 C=3 def isSafe(x,y): return(xselect(i | true)->collect(i | (Integer.subrange(0, C-1)->select(i | true)->collect(i | (-1)))) ; skip ; height := Sequence{Sequence{5}->union(Sequence{4}->union(Sequence{ 2 }))}->union(Sequence{Sequence{9}->union(Sequence{2}->union(Sequence{ 1 }))}->union(Sequence{Sequence{2}->union(Sequence{5}->union(Sequence{ 9 }))}->union(Sequence{ Sequence{1}->union(Sequence{3}->union(Sequence{ 11 })) }))) ; execute (minJump(height, 0, 0))->display(); operation isSafe(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return ((x->compareTo(R)) < 0 & (y->compareTo(C)) < 0); operation minJump(height : OclAny, x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (dp[x+1][y+1] /= -1) then ( return dp[x+1][y+1] ) else skip ; if (x = R - 1 & y = C - 1) then ( return (dp[x+1][y+1] = 0) ) else skip ; var diag : double := (10)->pow(9) ; if (isSafe(x + 1, y + 1)) then ( diag := minJump(height, x + 1, y + 1) + (height[x+1][y+1] - height[x + 1+1][y + 1+1])->abs() ) else skip ; var down : double := (10)->pow(9) ; if (isSafe(x + 1, y)) then ( down := minJump(height, x + 1, y) + (height[x+1][y+1] - height[x + 1+1][y+1])->abs() ) else skip ; var right : double := (10)->pow(9) ; if (isSafe(x, y + 1)) then ( right := minJump(height, x, y + 1) + (height[x+1][y+1] - height[x+1][y + 1+1])->abs() ) else skip ; dp[x+1][y+1] := Set{down, right, diag}->min() ; return dp[x+1][y+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import heapq import sys import math import itertools import bisect from io import BytesIO,IOBase import os def value(): return tuple(map(int,input().split())) def values(): return tuple(map(int,sys.stdin.readline().split())) def inlst(): return[int(i)for i in input().split()] def inlsts(): return[int(i)for i in sys.stdin.readline().split()] def inp(): return int(input()) def inps(): return int(sys.stdin.readline()) def instr(): return input() def stlst(): return[i for i in input().split()] def solve(): n=inp() l=inlst() mx=max(l) tot=0 s=sum(l) for i in range(n): tot+=mx-l[i] if tot>s : return mx tem=math.ceil((s-(tot-1))/n) return mx+tem if __name__=="__main__" : print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( execute (solve())->display() ) else skip; operation value() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation values() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inlsts() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inps() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation instr() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation stlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (i)); operation solve() : OclAny pre: true post: true activity: var n : OclAny := inp() ; var l : OclAny := inlst() ; var mx : OclAny := (l)->max() ; var tot : int := 0 ; var s : OclAny := (l)->sum() ; for i : Integer.subrange(0, n-1) do ( tot := tot + mx - l[i+1]) ; if (tot->compareTo(s)) > 0 then ( return mx ) else skip ; var tem : double := ((s - (tot - 1)) / n)->ceil() ; return mx + tem; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=0 k=0 a=list(map(int,input().split(' '))) for i in range(n): s+=a[i] k=max(k,a[i]) d=n*k-s while(d<=s): d+=n k+=1 print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : int := 0 ; var k : int := 0 ; var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( s := s + a[i+1] ; k := Set{k, a[i+1]}->max()) ; var d : double := n * k - s ; while ((d->compareTo(s)) <= 0) do ( d := d + n ; k := k + 1) ; execute (k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import* from dataclasses import dataclass from decimal import* def solves(): n=int(input()) s=0 k=0 a=list(map(int,input().split(' '))) for i in range(n): s+=a[i] k=max(k,a[i]) d=n*k-s while(d<=s): d+=n k+=1 print(k) t=1 for _ in range(0,t): solves() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solves()); operation solves() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : int := 0 ; var k : int := 0 ; var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( s := s + a[i+1] ; k := Set{k, a[i+1]}->max()) ; var d : double := n * k - s ; while ((d->compareTo(s)) <= 0) do ( d := d + n ; k := k + 1) ; execute (k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=int(input('')),int(input('')),int(input('')) l=[a,b//2,c//4] print(min(l)*7) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{("" + (((OclFile["System.in"]).readLine(''))))->toInteger(),("" + (((OclFile["System.in"]).readLine(''))))->toInteger(),("" + (((OclFile["System.in"]).readLine(''))))->toInteger()} ; var l : Sequence := Sequence{a}->union(Sequence{b div 2}->union(Sequence{ c div 4 })) ; execute ((l)->min() * 7)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input('')) s=list(input('')) l=list(map(int,s)) k=n//11 m=l.count(8) if m>=k : print(k) elif mtoInteger() ; var s : Sequence := ((OclFile["System.in"]).readLine(''))->characters() ; var l : Sequence := ((s)->collect( _x | (OclType["int"])->apply(_x) )) ; var k : int := n div 11 ; var m : int := l->count(8) ; if (m->compareTo(k)) >= 0 then ( execute (k)->display() ) else (if (m->compareTo(k)) < 0 then ( execute (m)->display() ) else ( execute ('0')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lemon=int(input()); apple=int(input()); pears=int(input()) x=min(apple//2,pears//4,lemon); print(x+x*2+x*4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lemon : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var apple : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var pears : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : OclAny := Set{apple div 2, pears div 4, lemon}->min(); execute (x + x * 2 + x * 4)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lemon=int(input()); apple=int(input()); pears=int(input()) left=0 ; right=lemon while left<=right : mid=(right+left)//2 if mid*2<=apple and mid*4<=pears : left=mid+1 ; ans=mid else : right=mid-1 print(ans+ans*2+ans*4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lemon : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var apple : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var pears : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var left : int := 0; var right : int := lemon ; while (left->compareTo(right)) <= 0 do ( var mid : int := (right + left) div 2 ; if (mid * 2->compareTo(apple)) <= 0 & (mid * 4->compareTo(pears)) <= 0 then ( left := mid + 1; var ans : int := mid ) else ( right := mid - 1 )) ; execute (ans + ans * 2 + ans * 4)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) c=int(input()) t=min(a,b//2,c//4) print(t*7) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : OclAny := Set{a, b div 2, c div 4}->min() ; execute (t * 7)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) c=int(input()) l=[] if a>=1 and b>=2 and c>=4 : l=[a//1,b//2,c//4] k=min(l) p=(1*k)+(2*k)+(4*k) print(p) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; if a >= 1 & b >= 2 & c >= 4 then ( l := Sequence{a div 1}->union(Sequence{b div 2}->union(Sequence{ c div 4 })) ; var k : OclAny := (l)->min() ; var p : double := (1 * k) + (2 * k) + (4 * k) ; execute (p)->display() ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) stack=[] for _ in range(n): stack.append(input()) used=set() for i in range(n-1,-1,-1): if stack[i]not in used : print(stack[i]) used.add(stack[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var stack : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : stack)) ; var used : Set := Set{}->union(()) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (used)->excludes(stack[i+1]) then ( execute (stack[i+1])->display() ; execute ((stack[i+1]) : used) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=[] arr1=set() res=[] for i in range(n): name=input() arr.append(name) arr.reverse() for i in arr : if i not in arr1 : res.append(i) arr1.add(i) for i in res : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Sequence{} ; var arr1 : Set := Set{}->union(()) ; var res : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var name : String := (OclFile["System.in"]).readLine() ; execute ((name) : arr)) ; arr := arr->reverse() ; for i : arr do ( if (arr1)->excludes(i) then ( execute ((i) : res) ; execute ((i) : arr1) ) else skip) ; for i : res do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for x in range(1,int(input())+1): N,K=map(int,input().split()) sums=tuple(map(int,input().split())) a=[0]*K t=sums[0] for i in range(K): b=0 c=0 for j in range(i,N-K,K): c+=sums[j+1]-sums[j] if c>a[i]: a[i]=c elif ctoInteger() + 1-1) do ( var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sums : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, K) ; var t : OclAny := sums->first() ; for i : Integer.subrange(0, K-1) do ( var b : int := 0 ; var c : int := 0 ; for j : Integer.subrange(i, N - K-1)->select( $x | ($x - i) mod K = 0 ) do ( c := c + sums[j + 1+1] - sums[j+1] ; if (c->compareTo(a[i+1])) > 0 then ( a[i+1] := c ) else (if (c->compareTo(b)) < 0 then ( b := c ) else skip)) ; a[i+1] := a[i+1] - b ; t := t + b) ; t := t mod K ; for i : Integer.subrange(0, t-1) do ( var bestj : int := 0 ; for j : Integer.subrange(1, K-1) do ( if (a[j+1]->compareTo(a[bestj+1])) < 0 then ( bestj := j ) else skip) ; a[bestj+1] := a[bestj+1] + 1) ; var y : OclAny := (a)->max() ; execute ('Case #' + ("" + ((x))) + ':')->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[] d={} for i in range(n): inp=input() d[inp]=0 l.append(inp) for i in range(n): d[l[n-i-1]]+=1 if d[l[n-i-1]]==1 : print(l[n-i-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; var d : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var inp : String := (OclFile["System.in"]).readLine() ; d->at(inp) := 0 ; execute ((inp) : l)) ; for i : Integer.subrange(0, n-1) do ( d[l[n - i - 1+1]+1] := d[l[n - i - 1+1]+1] + 1 ; if d[l[n - i - 1+1]+1] = 1 then ( execute (l[n - i - 1+1])->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s={} for j in[input()for i in range(int(input()))][: :-1]: if j not in s : print(j) s[j]=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := Set{} ; for j : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine()))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if (s)->excludes(j) then ( execute (j)->display() ; s[j+1] := 1 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) stack=[] chat_list={} for i in range(n): stack.append(input()) while(len(stack)!=0): chat=stack.pop() if chat_list.get(chat)==None : chat_list.update({chat : True}) print(chat) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var stack : Sequence := Sequence{} ; var chat_list : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : stack)) ; while ((stack)->size() /= 0) do ( var chat : OclAny := stack->last() ; stack := stack->front() ; if chat_list.get(chat) = null then ( execute ((Map{ chat |-> true }) <: chat_list) ; execute (chat)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(min(int(input())//11,input().count('8'))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (Set{("" + (((OclFile["System.in"]).readLine())))->toInteger() div 11, input()->count('8')}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def LI(): return list(map(int,sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] def SRL(n): return[list(S())for i in range(n)] def MSRL(n): return[[int(j)for j in list(S())]for i in range(n)] a,b,c=LI() if a==b==c : if a % 2 : print(0) else : print(-1) else : ans=0 while True : if a % 2 or b % 2 or c % 2 : break a,b,c=b//2+c//2,a//2+c//2,a//2+b//2 ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := LI() ; if a = b & (b == c) then ( if a mod 2 then ( execute (0)->display() ) else ( execute (-1)->display() ) ) else ( var ans : int := 0 ; while true do ( if a mod 2 or b mod 2 or c mod 2 then ( break ) else skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{b div 2 + c div 2,a div 2 + c div 2,a div 2 + b div 2} ; ans := ans + 1) ; execute (ans)->display() ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation I() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.buffer.readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.buffer.readLine().rstrip().decode('utf-8').split(); operation S() : OclAny pre: true post: true activity: return sys.stdin.buffer.readLine().rstrip().decode('utf-8'); operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation SRL(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | ((S()))); operation MSRL(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | ((S())->select(j | true)->collect(j | (("" + ((j)))->toInteger())))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculate(A,B,C): for i in range(1000): if A % 2==1 or B % 2==1 or C % 2==1 : return i else : _A=(B+C)//2 _B=(A+C)//2 _C=(A+B)//2 A,B,C=_A,_B,_C return-1 A,B,C=map(int,input().split()) print(calculate(A,B,C)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{A,B,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (calculate(A, B, C))->display(); operation calculate(A : OclAny, B : OclAny, C : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, 1000-1) do ( if A mod 2 = 1 or B mod 2 = 1 or C mod 2 = 1 then ( return i ) else ( var _A : int := (B + C) div 2 ; var _B : int := (A + C) div 2 ; var _C : int := (A + B) div 2 ; Sequence{A,B,C} := Sequence{_A,_B,_C} )) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B,C=[int(x)for x in input().split()] def IsOdd(a,b,c): if a % 2==1 : return True if b % 2==1 : return True if c % 2==1 : return True return False def Exchange(a,b,c): retA=0 retB=0 retC=0 retA=(b//2)+(c//2) retB=(a//2)+(c//2) retC=(a//2)+(b//2) return retA,retB,retC cnt=0 routedA=[] while True : if IsOdd(A,B,C): break if A in routedA : cnt=-1 break routedA.append(A) cnt+=1 ret=Exchange(A,B,C) A=ret[0] B=ret[1] C=ret[2] print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{A,B,C} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; skip ; skip ; var cnt : int := 0 ; var routedA : Sequence := Sequence{} ; while true do ( if IsOdd(A, B, C) then ( break ) else skip ; if (routedA)->includes(A) then ( cnt := -1 ; break ) else skip ; execute ((A) : routedA) ; cnt := cnt + 1 ; var ret : OclAny := Exchange(A, B, C) ; var A : OclAny := ret->first() ; var B : OclAny := ret[1+1] ; var C : OclAny := ret[2+1]) ; execute (cnt)->display(); operation IsOdd(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: if a mod 2 = 1 then ( return true ) else skip ; if b mod 2 = 1 then ( return true ) else skip ; if c mod 2 = 1 then ( return true ) else skip ; return false; operation Exchange(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: var retA : int := 0 ; var retB : int := 0 ; var retC : int := 0 ; retA := (b div 2) + (c div 2) ; retB := (a div 2) + (c div 2) ; retC := (a div 2) + (b div 2) ; return retA, retB, retC; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().strip().split()) count=0 while a % 2==0 and b % 2==0 and c % 2==0 : if a==b and b==c : count=-1 break count+=1 a1=b//2+c//2 b1=c//2+a//2 c1=a//2+b//2 a,b,c=a1,b1,c1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var count : int := 0 ; while a mod 2 = 0 & b mod 2 = 0 & c mod 2 = 0 do ( if a = b & b = c then ( count := -1 ; break ) else skip ; count := count + 1 ; var a1 : int := b div 2 + c div 2 ; var b1 : int := c div 2 + a div 2 ; var c1 : int := a div 2 + b div 2 ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{a1,b1,c1}) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(a : int,b : int,c : int)->int : if a % 2==1 or b % 2==1 or c % 2==1 : return 0 if a==b==c : return-1 return f((b+c)//2,(c+a)//2,(a+b)//2)+1 def main(): a,b,c=map(int,input().split()) print(f(a,b,c)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation f(a : int, b : int, c : int) : int pre: true post: true activity: if a mod 2 = 1 or b mod 2 = 1 or c mod 2 = 1 then ( return 0 ) else skip ; if a = b & (b == c) then ( return -1 ) else skip ; return f((b + c) div 2, (c + a) div 2, (a + b) div 2) + 1; operation main() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (f(a, b, c))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printOrder(arr,n,k): a=arr[0 : k]; a.sort(); b=arr[k : n]; b.sort(); b.reverse(); return a+b ; arr=[5,4,6,2,1,3,8,9,-1]; k=4 ; n=len(arr); arr=printOrder(arr,n,k); for i in range(n): print(arr[i],end=" "); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{5}->union(Sequence{4}->union(Sequence{6}->union(Sequence{2}->union(Sequence{1}->union(Sequence{3}->union(Sequence{8}->union(Sequence{9}->union(Sequence{ -1 })))))))); ; k := 4; ; n := (arr)->size(); ; arr := printOrder(arr, n, k); ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display();); operation printOrder(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var a : OclAny := arr.subrange(0+1, k); ; a := a->sort(); ; var b : OclAny := arr.subrange(k+1, n); ; b := b->sort(); ; b := b->reverse(); ; return a + b;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : N1=3 N=0 ; r=5 ; for i in range(r): if i<=r//2 : N=N1 for j in range(i+1): N+=1 N1=N for j in range(i+1): N-=1 print(N,end=" ") print() else : for j in range(i,r): N-=1 print(N,end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var N1 : int := 3 ; var N : int := 0; ; var r : int := 5; ; for i : Integer.subrange(0, r-1) do ( if (i->compareTo(r div 2)) <= 0 then ( N := N1 ; for j : Integer.subrange(0, i + 1-1) do ( N := N + 1) ; N1 := N ; for j : Integer.subrange(0, i + 1-1) do ( N := N - 1 ; execute (N)->display()) ; execute (->display() ) else ( for j : Integer.subrange(i, r-1) do ( N := N - 1 ; execute (N)->display()) ; execute (->display() )) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def run(N,K,sums): diffs=[] for i in range(K): cmin=0 cmax=0 ctemp=0 for j in range(i,N-K,K): ctemp+=sums[j+1]-sums[j] cmin=min(cmin,ctemp) cmax=max(cmax,ctemp) diffs.append([cmax-cmin,cmin,cmax]) diffs.sort() diff2=[] offset=0 for d in diffs : if d[1]=needminus or totplus>=needplus : return diff2[-1][0] else : return diff2[-1][0]+1 fin=open(sys.argv[1]) T=int(fin.readline().strip()) for i in range(1,T+1): N,K=[int(x)for x in fin.readline().strip().split()] sums=[int(x)for x in fin.readline().strip().split()] ans=run(N,K,sums) print('Case #%d: %s' %(i,ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var fin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) ; var T : int := ("" + ((fin.readLine()->trim())))->toInteger() ; for i : Integer.subrange(1, T + 1-1) do ( Sequence{N,K} := fin.readLine()->trim().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; sums := fin.readLine()->trim().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : OclAny := run(N, K, sums) ; execute (StringLib.format('Case #%d: %s',Sequence{i, ans}))->display()); operation run(N : OclAny, K : OclAny, sums : OclAny) : OclAny pre: true post: true activity: var diffs : Sequence := Sequence{} ; for i : Integer.subrange(0, K-1) do ( var cmin : int := 0 ; var cmax : int := 0 ; var ctemp : int := 0 ; for j : Integer.subrange(i, N - K-1)->select( $x | ($x - i) mod K = 0 ) do ( ctemp := ctemp + sums[j + 1+1] - sums[j+1] ; cmin := Set{cmin, ctemp}->min() ; cmax := Set{cmax, ctemp}->max()) ; execute ((Sequence{cmax - cmin}->union(Sequence{cmin}->union(Sequence{ cmax }))) : diffs)) ; diffs := diffs->sort() ; var diff2 : Sequence := Sequence{} ; var offset : int := 0 ; for d : diffs do ( if (d[1+1]->compareTo(diffs->last()[1+1])) < 0 then ( offset := offset + diffs->last()[1+1] - d[1+1] ; execute ((Sequence{d->first()}->union(Sequence{diffs->last()[1+1]}->union(Sequence{ d[2+1] + diffs->last()[1+1] - d[1+1] }))) : diff2) ) else ( execute ((d) : diff2) )) ; var totminus : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name r)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) - (expr (atom (name diff2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name r)))) in (logical_test (comparison (expr (atom (name diff2))))))))->sum() ; var totplus : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name diff2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ]))) - (expr (atom (name r)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name r)))) in (logical_test (comparison (expr (atom (name diff2))))))))->sum() ; var needplus : int := (sums->first() - offset) mod K ; var needminus : int := (offset - sums->first()) mod K ; if (totminus->compareTo(needminus)) >= 0 or (totplus->compareTo(needplus)) >= 0 then ( return diff2->last()->first() ) else ( return diff2->last()->first() + 1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=4 def isScalarMatrix(mat): for i in range(0,N): for j in range(0,N): if((i!=j)and(mat[i][j]!=0)): return False for i in range(0,N-1): if(mat[i][i]!=mat[i+1][i+1]): return False return True mat=[[2,0,0,0],[0,2,0,0],[0,0,2,0],[0,0,0,2]] if(isScalarMatrix(mat)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 4 ; skip ; mat := Sequence{Sequence{2}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))}->union(Sequence{Sequence{0}->union(Sequence{2}->union(Sequence{0}->union(Sequence{ 0 })))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{2}->union(Sequence{ 0 })))}->union(Sequence{ Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 2 }))) }))) ; if (isScalarMatrix(mat)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isScalarMatrix(mat : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( if ((i /= j) & (mat[i+1][j+1] /= 0)) then ( return false ) else skip)) ; for i : Integer.subrange(0, N - 1-1) do ( if (mat[i+1][i+1] /= mat[i + 1+1][i + 1+1]) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=2 M=3 def check(mat): xorr=0 for i in range(N): xorr ^=mat[i][0] if(xorr!=0): return True for i in range(N): for j in range(1,M): if(mat[i][j]!=mat[i][0]): return True return False mat=[[7,7,7],[10,10,7]] if(check(mat)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 2 ; var M : int := 3 ; skip ; mat := Sequence{Sequence{7}->union(Sequence{7}->union(Sequence{ 7 }))}->union(Sequence{ Sequence{10}->union(Sequence{10}->union(Sequence{ 7 })) }) ; if (check(mat)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation check(mat : OclAny) : OclAny pre: true post: true activity: var xorr : int := 0 ; for i : Integer.subrange(0, N-1) do ( xorr := xorr xor mat[i+1]->first()) ; if (xorr /= 0) then ( return true ) else skip ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(1, M-1) do ( if (mat[i+1][j+1] /= mat[i+1]->first()) then ( return true ) else skip)) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() print(min(s.count('8'),n//11)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; execute (Set{s->count('8'), n div 11}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minItems(k,r): for i in range(1,10): if((i*k-r)% 10==0 or(i*k)% 10==0): return i return 10 ; if __name__=="__main__" : k,r=15,2 ; print(minItems(k,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{k,r} := Sequence{15,2}; ; execute (minItems(k, r))->display() ) else skip; operation minItems(k : OclAny, r : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(1, 10-1) do ( if ((i * k - r) mod 10 = 0 or (i * k) mod 10 = 0) then ( return i ) else skip) ; return 10;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ninja=input(); l=sorted(map(int,input().split())) print(sum([x*(i+2)for i,x in enumerate(l)])-l[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ninja : String := (OclFile["System.in"]).readLine(); var l : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; execute ((Integer.subrange(1, (l)->size())->collect( _indx | Sequence{_indx-1, (l)->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in (x * (i + 2))))->sum() - l->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) a.sort() k=2 sum=0 for i in a : sum+=k*i k+=1 print(sum-max(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var k : int := 2 ; var sum : int := 0 ; for i : a do ( sum := sum + k * i ; k := k + 1) ; execute (sum - (a)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) s=sum(arr) arr.sort(reverse=True) i=n-1 k=s while(i>0): k-=arr[i] s+=k s+=arr[i] i-=1 print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : OclAny := (arr)->sum() ; arr := arr->sort() ; var i : double := n - 1 ; var k : OclAny := s ; while (i > 0) do ( k := k - arr[i+1] ; s := s + k ; s := s + arr[i+1] ; i := i - 1) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) arr.sort() sm=0 ans=0 for i in arr : sm+=i for i in range(n): ans+=sm if(i!=n-1): ans+=arr[i] sm-=arr[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := arr->sort() ; var sm : int := 0 ; var ans : int := 0 ; for i : arr do ( sm := sm + i) ; for i : Integer.subrange(0, n-1) do ( ans := ans + sm ; if (i /= n - 1) then ( ans := ans + arr[i+1] ) else skip ; sm := sm - arr[i+1]) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) a.sort() k=2 sum=0 for i in a : sum+=k*i k+=1 print(sum-max(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var k : int := 2 ; var sum : int := 0 ; for i : a do ( sum := sum + k * i ; k := k + 1) ; execute (sum - (a)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def func(a,k,n): for i in range(0,n): if(a[i]% k==0): return True a=[14,27,38,76,84] k=19 res=func(a,k,5) if(res): print("true") else : print("false") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{14}->union(Sequence{27}->union(Sequence{38}->union(Sequence{76}->union(Sequence{ 84 })))) ; k := 19 ; var res : OclAny := func(a, k, 5) ; if (res) then ( execute ("true")->display() ) else ( execute ("false")->display() ); operation func(a : OclAny, k : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if (a[i+1] mod k = 0) then ( return true ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Findpermutation(n): a=[0]*(n+1); a[1]=n ; for i in range(2,n+1): a[i]=i-1 ; return a ; if __name__=="__main__" : n=8 ; v=Findpermutation(n); for i in range(1,n+1): print(v[i],end=' '); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 8; ; var v : OclAny := Findpermutation(n); ; for i : Integer.subrange(1, n + 1-1) do ( execute (v[i+1])->display();) ) else skip; operation Findpermutation(n : OclAny) pre: true post: true activity: var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); ; a[1+1] := n; ; for i : Integer.subrange(2, n + 1-1) do ( a[i+1] := i - 1;) ; return a;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from pulp import* tc=int(input().strip()) for t in range(tc): f=input().split() n,k=int(f[0]),int(f[1]) s=[int(x)for x in input().strip().split()] var=[LpVariable("x_%d" % i,cat='Integer')for i in range(k-1)] for i in range(0,n-k+1): var.append(s[i]-sum(var[-(j+1)]for j in range(k-1))) prob=LpProblem("myProblem",LpMinimize) x_max=LpVariable("x_max") x_min=LpVariable("x_min") res=x_max-x_min for i in range(n): prob+=x_max>=var[i] prob+=x_min<=var[i] prob+=res status=prob.solve() if status!=1 : print("Case #%d: IMPOSSIBLE" %(t+1)) else : print("Case #%d: %d" %(t+1,value(res))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var tc : int := ("" + ((input()->trim())))->toInteger() ; for t : Integer.subrange(0, tc-1) do ( var f : OclAny := input().split() ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := Sequence{("" + ((f->first())))->toInteger(),("" + ((f[1+1])))->toInteger()} ; var s : Sequence := input()->trim().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var var : Sequence := Integer.subrange(0, k - 1-1)->select(i | true)->collect(i | (LpVariable(StringLib.format("x_%d",i), (argument (test (logical_test (comparison (expr (atom (name cat)))))) = (test (logical_test (comparison (expr (atom 'Integer'))))))))) ; for i : Integer.subrange(0, n - k + 1-1) do ( execute ((s[i+1] - ((argument (test (logical_test (comparison (expr (atom (name var)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr - (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 1))))))))) ))))))))) ])))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name k))) - (expr (atom (number (integer 1)))))))))) )))))))))->sum()) : var)) ; var prob : OclAny := LpProblem("myProblem", LpMinimize) ; var x_max : OclAny := LpVariable("x_max") ; var x_min : OclAny := LpVariable("x_min") ; var res : double := x_max - x_min ; for i : Integer.subrange(0, n-1) do ( prob := prob + (x_max->compareTo(var[i+1])) >= 0 ; prob := prob + (x_min->compareTo(var[i+1])) <= 0) ; prob := prob + res ; var status : OclAny := prob.solve() ; if status /= 1 then ( execute (StringLib.format("Case #%d: IMPOSSIBLE",(t + 1)))->display() ) else ( execute (StringLib.format("Case #%d: %d",Sequence{t + 1, value(res)}))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* def countCoprimePairs(n): count=0 print("The co-prime pairs are: ") for i in range(2,int(sqrt(n))+1): if n % i==0 : if gcd(i,n//i)==1 : print("(",i,",",(n//i),")") count+=1 print("Number of coprime pairs : ",count) if __name__=="__main__" : N=120 countCoprimePairs(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var N : int := 120 ; countCoprimePairs(N) ) else skip; operation countCoprimePairs(n : OclAny) pre: true post: true activity: var count : int := 0 ; execute ("The co-prime pairs are: ")->display() ; for i : Integer.subrange(2, ("" + ((sqrt(n))))->toInteger() + 1-1) do ( if n mod i = 0 then ( if gcd(i, n div i) = 1 then ( execute ("(")->display() ; count := count + 1 ) else skip ) else skip) ; execute ("Number of coprime pairs : ")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) phn=input() print(min(n//11,phn.count('8'))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var phn : String := (OclFile["System.in"]).readLine() ; execute (Set{n div 11, phn->count('8')}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() m=0 for x in map(int,input().split()): print(x+m); m+=max(0,x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var m : int := 0 ; for x : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( execute (x + m)->display(); m := m + Set{0, x}->max()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) a=[int(x)for x in input().split()] mx=0 ans=[] for i in a : ans.append(i+mx) mx=max(mx,i+mx) print(*ans,sep=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var mx : int := 0 ; var ans : Sequence := Sequence{} ; for i : a do ( execute ((i + mx) : ans) ; mx := Set{mx, i + mx}->max()) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) b=list(map(int,input().split())) a=[] max=b[0] a.append(b[0]) s=str(a[0]) for i in range(1,n): c=b[i]+max a.append(c) if(a[i]>max): max=a[i] s=s+"{}".format(a[i]) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := Sequence{} ; var max : OclAny := b->first() ; execute ((b->first()) : a) ; var s : String := ("" + ((a->first()))) ; for i : Integer.subrange(1, n-1) do ( var c : OclAny := b[i+1] + max ; execute ((c) : a) ; if ((a[i+1]->compareTo(max)) > 0) then ( max := a[i+1] ) else skip ; s := s + StringLib.interpolateStrings("{}", Sequence{a[i+1]})) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) brr=[int(x)for x in input().split()] store=0 arr=[0 for i in range(n)] for i in range(n): arr[i]=brr[i]+store store=max(store,arr[i]) print(*arr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var brr : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var store : int := 0 ; var arr : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( arr[i+1] := brr[i+1] + store ; store := Set{store, arr[i+1]}->max()) ; execute ((argument * (test (logical_test (comparison (expr (atom (name arr))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) b=list(map(int,input().split())) x=0 for i in range(0,n): ai=b[i]+x print(ai,end=" ") x=max(x,ai) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : int := 0 ; for i : Integer.subrange(0, n-1) do ( var ai : OclAny := b[i+1] + x ; execute (ai)->display() ; x := Set{x, ai}->max()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Count(temp): query=[9,3,2] Q=len(query) for i in range(Q): pos=query[i] print(temp[pos-1]) def processing(s): temp=[0]*len(s) d=dict() for i in range(len(s)): if s[i]not in d : d[s[i]]=i else : temp[i]=temp[d[s[i]]]+1 d[s[i]]=i return temp if __name__=="__main__" : s="abacsddaa" n=len(s) temp=processing(s) Count(temp) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( s := "abacsddaa" ; var n : int := (s)->size() ; temp := processing(s) ; Count(temp) ) else skip; operation Count(temp : OclAny) pre: true post: true activity: var query : Sequence := Sequence{9}->union(Sequence{3}->union(Sequence{ 2 })) ; var Q : int := (query)->size() ; for i : Integer.subrange(0, Q-1) do ( var pos : OclAny := query[i+1] ; execute (temp[pos - 1+1])->display()); operation processing(s : OclAny) : OclAny pre: true post: true activity: temp := MatrixLib.elementwiseMult(Sequence{ 0 }, (s)->size()) ; var d : Map := (arguments ( )) ; for i : Integer.subrange(0, (s)->size()-1) do ( if (d)->excludes(s[i+1]) then ( d[s[i+1]+1] := i ) else ( temp[i+1] := temp[d[s[i+1]+1]+1] + 1 ; d[s[i+1]+1] := i )) ; return temp; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxXORInRange(L,R): LXR=L ^ R msbPos=0 while(LXR): msbPos+=1 LXR>>=1 maxXOR,two=0,1 while(msbPos): maxXOR+=two two<<=1 msbPos-=1 return maxXOR L,R=8,20 print(maxXORInRange(L,R)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{L,R} := Sequence{8,20} ; execute (maxXORInRange(L, R))->display(); operation maxXORInRange(L : OclAny, R : OclAny) : OclAny pre: true post: true activity: var LXR : int := MathLib.bitwiseXor(L, R) ; var msbPos : int := 0 ; while (LXR) do ( msbPos := msbPos + 1 ; LXR := LXR div (2->pow(1))) ; var maxXOR : OclAny := null; var two : OclAny := null; Sequence{maxXOR,two} := Sequence{0,1} ; while (msbPos) do ( maxXOR := maxXOR + two ; two := two * (2->pow(1)) ; msbPos := msbPos - 1) ; return maxXOR; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fib(n): a=0 b=1 if(n>=0): print(a,end=' ') if(n>=1): print(b,end=' ') for i in range(2,n+1): print(a+b,end=' ') b=a+b a=b-a fib(9) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; fib(9); operation fib(n : OclAny) pre: true post: true activity: var a : int := 0 ; var b : int := 1 ; if (n >= 0) then ( execute (a)->display() ) else skip ; if (n >= 1) then ( execute (b)->display() ) else skip ; for i : Integer.subrange(2, n + 1-1) do ( execute (a + b)->display() ; b := a + b ; a := b - a); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fib(n): a=0 b=1 if(n>=0): print(a,end=' ') if(n>=1): print(b,end=' ') for i in range(2,n+1): c=a+b print(c,end=' ') a=b b=c fib(9) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; fib(9); operation fib(n : OclAny) pre: true post: true activity: var a : int := 0 ; var b : int := 1 ; if (n >= 0) then ( execute (a)->display() ) else skip ; if (n >= 1) then ( execute (b)->display() ) else skip ; for i : Integer.subrange(2, n + 1-1) do ( var c : int := a + b ; execute (c)->display() ; a := b ; b := c); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class newnode : def __init__(self,data): self.data=data self.left=self.right=None def ancestorMatrixRec(root,anc): global mat,MAX if root==None : return 0 data=root.data for i in range(len(anc)): mat[anc[i]][data]=1 anc.append(data) l=ancestorMatrixRec(root.left,anc) r=ancestorMatrixRec(root.right,anc) anc.pop(-1) return l+r+1 def ancestorMatrix(root): anc=[] n=ancestorMatrixRec(root,anc) for i in range(n): for j in range(n): print(mat[i][j],end=" ") print() MAX=100 mat=[[0]*MAX for i in range(MAX)] root=newnode(5) root.left=newnode(1) root.right=newnode(2) root.left.left=newnode(0) root.left.right=newnode(4) root.right.left=newnode(3) ancestorMatrix(root) ------------------------------------------------------------ OCL File: --------- class newnode { static operation newnewnode() : newnode pre: true post: newnode->exists( _x | result = _x ); attribute data : OclAny := data; attribute left : OclAny := null; var self.right : OclAny := null; operation initialise(data : OclAny) : newnode pre: true post: true activity: self.data := data ; self.left := null; var self.right : OclAny := null; return self; } class FromPython { attribute mat : OclAny; attribute MAX : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; MAX := 100 ; mat := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, MAX))) ; root := (newnode.newnewnode()).initialise(5) ; root.left := (newnode.newnewnode()).initialise(1) ; root.right := (newnode.newnewnode()).initialise(2) ; root.left.left := (newnode.newnewnode()).initialise(0) ; root.left.right := (newnode.newnewnode()).initialise(4) ; root.right.left := (newnode.newnewnode()).initialise(3) ; ancestorMatrix(root); operation ancestorMatrixRec(root : OclAny, anc : OclAny) : OclAny pre: true post: true activity: skip; skip ; if root = null then ( return 0 ) else skip ; data := root.data ; for i : Integer.subrange(0, (anc)->size()-1) do ( mat[anc[i+1]+1][data+1] := 1) ; execute ((data) : anc) ; var l : OclAny := ancestorMatrixRec(root.left, anc) ; var r : OclAny := ancestorMatrixRec(root.right, anc) ; anc := anc->excludingAt(-1+1) ; return l + r + 1; operation ancestorMatrix(root : OclAny) pre: true post: true activity: anc := Sequence{} ; var n : OclAny := ancestorMatrixRec(root, anc) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( execute (mat[i+1][j+1])->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfDigit(n,b): unitDigit=0 sum=0 while(n>0): unitDigit=n % b sum+=unitDigit n=n//b return sum n=50 b=2 print(sumOfDigit(n,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 50 ; b := 2 ; execute (sumOfDigit(n, b))->display(); operation sumOfDigit(n : OclAny, b : OclAny) : OclAny pre: true post: true activity: var unitDigit : int := 0 ; var sum : int := 0 ; while (n > 0) do ( unitDigit := n mod b ; sum := sum + unitDigit ; n := n div b) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import re def solve(n,k,sums): a=[0]*(n-k) r=[0]*k q=[0]*k for i in range(1,n-k+1): a[i-1]=sums[i-1]-sums[i] for i in range(k): b=[a[i+k*x]for x in range((n-1-i)/k)] for c in range(1,len(b)): b[c]=b[c-1]+b[c] b.append(0) d=abs(max(b)-min(b)) r[i]=d q[i]=max(b) m=max(r) rem=(sums[0]-sum(q))% k n=m*k-sum(r) if n>=rem : return m else : return m+1 inp=open("B-large.in","r") out=open("B-large","w") lines=inp.readlines() i=1 count=1 while icompareTo((lines)->size())) < 0 do ( ; Sequence{n}->union(Sequence{ k }) := (lines[i+1])->split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var B : Sequence := (lines[i + 1+1])->split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; out.write("Case #" + ("" + ((count))) + ": " + StringLib.interpolateStrings("{:}", Sequence{solve(n, k, B)}) + "\n") ; i := i + 2 ; count := count + 1) ; out.closeFile() ; inp.closeFile(); operation solve(n : OclAny, k : OclAny, sums : OclAny) : OclAny pre: true post: true activity: var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n - k)) ; var r : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, k) ; var q : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, k) ; for i : Integer.subrange(1, n - k + 1-1) do ( a[i - 1+1] := sums[i - 1+1] - sums[i+1]) ; for i : Integer.subrange(0, k-1) do ( var b : Sequence := Integer.subrange(0, (n - 1 - i) / k-1)->select(x | true)->collect(x | (a[i + k * x+1])) ; for c : Integer.subrange(1, (b)->size()-1) do ( b[c+1] := b[c - 1+1] + b[c+1]) ; execute ((0) : b) ; var d : double := ((b)->max() - (b)->min())->abs() ; r[i+1] := d ; q[i+1] := (b)->max()) ; var m : OclAny := (r)->max() ; var rem : int := (sums->first() - (q)->sum()) mod k ; n := m * k - (r)->sum() ; if (n->compareTo(rem)) >= 0 then ( return m ) else ( return m + 1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=256 def canMakeStr2(s1,s2): count={s1[i]: 0 for i in range(len(s1))} for i in range(len(s1)): count[s1[i]]+=1 for i in range(len(s2)): if count[s2[i]]==0 : return False count[s2[i]]-=1 return True s1="geekforgeeks" s2="for" if canMakeStr2(s1,s2): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 256 ; skip ; s1 := "geekforgeeks" ; s2 := "for" ; if canMakeStr2(s1, s2) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation canMakeStr2(s1 : OclAny, s2 : OclAny) : OclAny pre: true post: true activity: var count : Map := Integer.subrange(0, (s1)->size()-1)->select(i | true)->collect(i | Map{s1[i+1] |-> 0})->unionAll() ; for i : Integer.subrange(0, (s1)->size()-1) do ( count[s1[i+1]+1] := count[s1[i+1]+1] + 1) ; for i : Integer.subrange(0, (s2)->size()-1) do ( if count[s2[i+1]+1] = 0 then ( return false ) else skip ; count[s2[i+1]+1] := count[s2[i+1]+1] - 1) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def check(a,b): c=0 ; while(a!=0): c=c+a % 10 ; a=int(a/10); return True if(c==b)else False ; def root(n): found=False ; mx=1000000000000000001 ; for i in range(91): s=i*i+4*n ; sq=int(math.sqrt(s)); if(sq*sq==s and check(int((sq-i)/2),i)): found=True ; mx=min(mx,int((sq-i)/2)); if(found): return mx ; else : return-1 ; n=110 ; print(root(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 110; ; execute (root(n))->display();; operation check(a : OclAny, b : OclAny) pre: true post: true activity: var c : int := 0; ; while (a /= 0) do ( c := c + a mod 10; ; a := ("" + ((a / 10)))->toInteger();) ; return if (c = b) then true else false endif;; operation root(n : OclAny) pre: true post: true activity: var found : boolean := false; ; var mx : int := 1000000000000000001; ; for i : Integer.subrange(0, 91-1) do ( var s : double := i * i + 4 * n; ; var sq : int := ("" + (((s)->sqrt())))->toInteger(); ; if (sq * sq = s & check(("" + (((sq - i) / 2)))->toInteger(), i)) then ( found := true; ; mx := Set{mx, ("" + (((sq - i) / 2)))->toInteger()}->min(); ) else skip) ; if (found) then ( return mx; ) else ( return -1; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import random sys.setrecursionlimit(10**5+5) random.seed=1 def read_int_list(): return list(map(int,input().split())) def read_int(): return int(input()) def read_str_list(): return input().split() def read_str(): return input() a=None def dfs(root,parent): res=0 for i in a[root]: if i!=parent : res ^=1+dfs(i,root) return res def read_tree(check=False): if check : n,p=gen() else : n=read_int() p=[read_int_list()for i in range(n-1)] global a a=[[]for _ in range(n)] for x,y in p : x-=1 y-=1 a[x].append(y) a[y].append(x) def gen(): n=random.randint(5,30) inside=[1] outside=list(range(2,n+1)) p=[] for i in range(n-1): x=random.choice(inside) y=random.choice(outside) p.append([x,y]) outside.remove(y) inside.append(y) return n,p def solve(): read_tree(check=False) return['Bob','Alice'][dfs(0,-1)>0] def check(): for i in range(1000): res=solve() print(i,res) def main(): res=solve() print(res) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute a : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(5) + 5) ; := 1 ; skip ; skip ; skip ; skip ; var a : OclAny := null ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation read_int_list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation read_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation read_str_list() : OclAny pre: true post: true activity: return input().split(); operation read_str() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation dfs(root : OclAny, parent : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; for i : a[root+1] do ( if i /= parent then ( res := res xor 1 + dfs(i, root) ) else skip) ; return res; operation read_tree(check : OclAny) pre: true post: true activity: if check->oclIsUndefined() then check := false else skip; if check then ( var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := gen() ) else ( var n : OclAny := read_int() ; var p : Sequence := Integer.subrange(0, n - 1-1)->select(i | true)->collect(i | (read_int_list())) ) ; skip ; a := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _tuple : p do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); x := x - 1 ; y := y - 1 ; (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))) ; (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))); operation gen() : OclAny pre: true post: true activity: n := (5 + (OclRandom.defaultInstanceOclRandom()).nextInt(30 - 5)) ; var inside : Sequence := Sequence{ 1 } ; var outside : Sequence := (Integer.subrange(2, n + 1-1)) ; p := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( var x : OclAny := OclRandom.randomElement(inside) ; var y : OclAny := OclRandom.randomElement(outside) ; execute ((Sequence{x}->union(Sequence{ y })) : p) ; execute ((y) /: outside) ; execute ((y) : inside)) ; return n, p; operation solve() : OclAny pre: true post: true activity: read_tree((argument (test (logical_test (comparison (expr (atom (name check)))))) = (test (logical_test (comparison (expr (atom (name False)))))))) ; return Sequence{'Bob'}->union(Sequence{ 'Alice' })->select(dfs(0, -1) > 0); operation check() pre: true post: true activity: for i : Integer.subrange(0, 1000-1) do ( res := solve() ; execute (i)->display()); operation main() pre: true post: true activity: res := solve() ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def topological_sort(tree : list,root)->list : n=len(tree) visited=[False]*n visited[root]=True tp_sorted=[root] stack=[root] while stack : v=stack.pop() for nxt_v in tree[v]: if visited[nxt_v]: continue visited[nxt_v]=True stack.append(nxt_v) tp_sorted.append(nxt_v) return tp_sorted def get_par(tree : list,root : int)->list : n=len(tree) visited=[False]*n visited[root]=True par=[-1]*n stack=[root] while stack : v=stack.pop() for nxt_v in tree[v]: if visited[nxt_v]: continue visited[nxt_v]=True stack.append(nxt_v) par[nxt_v]=v return par n=int(input()) edges=[list(map(int,input().split()))for i in range(n-1)] tree=[[]for i in range(n)] root=0 for a,b in edges : a-=1 b-=1 tree[a].append(b) tree[b].append(a) tp_sorted=topological_sort(tree,root) par=get_par(tree,root) grandy=[0]*n for v in tp_sorted[: :-1]: par_v=par[v] if par_v==-1 : continue grandy[par_v]^=grandy[v]+1 if grandy[0]!=0 : print("Alice") else : print("Bob") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var edges : Sequence := Integer.subrange(0, n - 1-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var tree : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; root := 0 ; for _tuple : edges do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); a := a - 1 ; b := b - 1 ; (expr (atom (name tree)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name tree)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; tp_sorted := topological_sort(tree, root) ; par := get_par(tree, root) ; var grandy : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for v : tp_sorted(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( var par_v : OclAny := par[v+1] ; if par_v = -1 then ( continue ) else skip ; grandy[par_v+1] := grandy[par_v+1] xor grandy[v+1] + 1) ; if grandy->first() /= 0 then ( execute ("Alice")->display() ) else ( execute ("Bob")->display() ); operation topological_sort(tree : Sequence(OclAny), root : OclAny) : Sequence pre: true post: true activity: var n : int := (tree)->size() ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ; visited[root+1] := true ; var tp_sorted : Sequence := Sequence{ root } ; var stack : Sequence := Sequence{ root } ; while stack do ( var v : OclAny := stack->last() ; stack := stack->front() ; for nxt_v : tree[v+1] do ( if visited[nxt_v+1] then ( continue ) else skip ; visited[nxt_v+1] := true ; execute ((nxt_v) : stack) ; execute ((nxt_v) : tp_sorted))) ; return tp_sorted; operation get_par(tree : Sequence(OclAny), root : int) : Sequence pre: true post: true activity: n := (tree)->size() ; visited := MatrixLib.elementwiseMult(Sequence{ false }, n) ; visited[root+1] := true ; var par : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; stack := Sequence{ root } ; while stack do ( v := stack->last() ; stack := stack->front() ; for nxt_v : tree[v+1] do ( if visited[nxt_v+1] then ( continue ) else skip ; visited[nxt_v+1] := true ; execute ((nxt_v) : stack) ; par[nxt_v+1] := v)) ; return par; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**7) N=int(input()) XY=[tuple(map(int,input().split()))for i in range(N-1)] es=[[]for _ in range(N)] for x,y in XY : x,y=x-1,y-1 es[x].append(y) es[y].append(x) def grundy(v,p=-1): x=0 for to in es[v]: if to==p : continue x ^=(grundy(to,v)+1) return x print('Alice' if grundy(0)else 'Bob') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var XY : Sequence := Integer.subrange(0, N - 1-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var es : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _tuple : XY do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{x - 1,y - 1} ; (expr (atom (name es)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))) ; (expr (atom (name es)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))) ; skip ; execute (if grundy(0) then 'Alice' else 'Bob' endif)->display(); operation grundy(v : OclAny, p : int) : OclAny pre: true post: true activity: if p->oclIsUndefined() then p := -1 else skip; var x : int := 0 ; for to : es[v+1] do ( if to = p then ( continue ) else skip ; x := x xor (grundy(to, v) + 1)) ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque import heapq N=int(input()) gr=[None]*N child=[0]*N dic={} q=[] for i in range(N-1): x,y=map(int,input().split()) x-=1 y-=1 if x not in dic : dic[x]=[] if y not in dic : dic[y]=[] dic[x].append(y) dic[y].append(x) child[x]+=1 child[y]+=1 dep=[float("inf")]*N dep[0]=0 dq=deque([0]) while len(dq)>0 : n=dq.popleft() for i in dic[n]: if dep[i]>dep[n]+1 : dep[i]=dep[n]+1 for i in range(N): if child[i]==1 : child[i]=0 gr[i]=0 heapq.heappush(q,[-1*dep[i],i]) while len(q)>0 : ngr=0 no=heapq.heappop(q) now=no[1] for i in dic[now]: if gr[i]!=None : ngr ^=(gr[i]+1) else : child[i]-=1 if child[i]<=1 and gr[i]==None : heapq.heappush(q,[-1*dep[i],i]) gr[now]=ngr if gr[0]==0 : print("Bob") else : print("Alice") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var gr : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, N) ; var child : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var dic : OclAny := Set{} ; var q : Sequence := Sequence{} ; for i : Integer.subrange(0, N - 1-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; x := x - 1 ; y := y - 1 ; if (dic)->excludes(x) then ( dic[x+1] := Sequence{} ) else skip ; if (dic)->excludes(y) then ( dic[y+1] := Sequence{} ) else skip ; (expr (atom (name dic)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))) ; (expr (atom (name dic)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) ; child[x+1] := child[x+1] + 1 ; child[y+1] := child[y+1] + 1) ; var dep : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (("inf")))->toReal() }, N) ; dep->first() := 0 ; var dq : Sequence := (Sequence{ 0 }) ; while (dq)->size() > 0 do ( var n : OclAny := dq->first() ; dq := dq->tail() ; for i : dic[n+1] do ( if (dep[i+1]->compareTo(dep[n+1] + 1)) > 0 then ( dep[i+1] := dep[n+1] + 1 ) else skip)) ; for i : Integer.subrange(0, N-1) do ( if child[i+1] = 1 then ( child[i+1] := 0 ; gr[i+1] := 0 ; heapq.heappush(q, Sequence{-1 * dep[i+1]}->union(Sequence{ i })) ) else skip) ; while (q)->size() > 0 do ( var ngr : int := 0 ; var no : OclAny := heapq.heappop(q) ; var now : OclAny := no[1+1] ; for i : dic[now+1] do ( if gr[i+1] /= null then ( ngr := ngr xor (gr[i+1] + 1) ) else ( child[i+1] := child[i+1] - 1 ; if child[i+1] <= 1 & gr[i+1] = null then ( heapq.heappush(q, Sequence{-1 * dep[i+1]}->union(Sequence{ i })) ) else skip )) ; gr[now+1] := ngr) ; if gr->first() = 0 then ( execute ("Bob")->display() ) else ( execute ("Alice")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.buffer.readline sys.setrecursionlimit(10**7) from collections import defaultdict def getlist(): return list(map(int,input().split())) class Graph(object): def __init__(self): self.graph=defaultdict(list) def __len__(self): return len(self.graph) def add_edge(self,a,b): self.graph[a].append(b) def get_nodes(self): return self.graph.keys() def DFS(G,XOR,visit,node): for i in G.graph[node]: if visit[i]!="Yes" : visit[i]="Yes" DFS(G,XOR,visit,i) XOR[node]^=XOR[i]+1 def main(): N=int(input()) G=Graph() for i in range(N-1): x,y=getlist() x-=1 y-=1 G.add_edge(x,y) G.add_edge(y,x) XOR=[0]*N visit=["No"]*N visit[0]="Yes" DFS(G,XOR,visit,0) if XOR[0]==0 : print("Bob") else : print("Alice") if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class Graph extends object { static operation newGraph() : Graph pre: true post: Graph->exists( _x | result = _x ); attribute graph : OclAny := defaultdict(OclType["Sequence"]); operation initialise() : pre: true post: true activity: self.graph := defaultdict(OclType["Sequence"]); return self; operation __len__() : OclAny pre: true post: true activity: return (self.graph)->size(); operation add_edge(a : OclAny,b : OclAny) pre: true post: true activity: (expr (atom (name self)) (trailer . (name graph) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))); operation get_nodes() : OclAny pre: true post: true activity: return self.graph.keys(); } class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := sys.stdin.buffer.readline ; sys.setrecursionlimit((10)->pow(7)) ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation getlist() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation DFS(G : OclAny, XOR : OclAny, visit : OclAny, node : OclAny) pre: true post: true activity: for i : G.graph[node+1] do ( if visit[i+1] /= "Yes" then ( visit[i+1] := "Yes" ; DFS(G, XOR, visit, i) ; XOR[node+1] := XOR[node+1] xor XOR[i+1] + 1 ) else skip); operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; G := (Graph.newGraph()).initialise() ; for i : Integer.subrange(0, N - 1-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := getlist() ; x := x - 1 ; y := y - 1 ; G.add_edge(x, y) ; G.add_edge(y, x)) ; XOR := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; visit := MatrixLib.elementwiseMult(Sequence{ "No" }, N) ; visit->first() := "Yes" ; DFS(G, XOR, visit, 0) ; if XOR->first() = 0 then ( execute ("Bob")->display() ) else ( execute ("Alice")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def maxOverlap(start,end): n=len(start) maxa=max(start) maxb=max(end) maxc=max(maxa,maxb) x=(maxc+2)*[0] cur=0 ; idx=0 for i in range(0,n): x[start[i]]+=1 x[end[i]+1]-=1 maxy=-1 for i in range(0,maxc+1): cur+=x[i] if maxyunion(Sequence{28}->union(Sequence{29}->union(Sequence{14}->union(Sequence{40}->union(Sequence{17}->union(Sequence{ 3 })))))) ; end := Sequence{107}->union(Sequence{95}->union(Sequence{111}->union(Sequence{105}->union(Sequence{70}->union(Sequence{127}->union(Sequence{ 74 })))))) ; maxOverlap(start, end) ) else skip; operation maxOverlap(start : OclAny, end : OclAny) pre: true post: true activity: var n : int := (start)->size() ; var maxa : OclAny := (start)->max() ; var maxb : OclAny := (end)->max() ; var maxc : OclAny := Set{maxa, maxb}->max() ; var x : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (maxc + 2)) ; var cur : int := 0; var idx : int := 0 ; for i : Integer.subrange(0, n-1) do ( x[start[i+1]+1] := x[start[i+1]+1] + 1 ; x[end[i+1] + 1+1] := x[end[i+1] + 1+1] - 1) ; var maxy : int := -1 ; for i : Integer.subrange(0, maxc + 1-1) do ( cur := cur + x[i+1] ; if (maxy->compareTo(cur)) < 0 then ( maxy := cur ; idx := i ) else skip) ; execute (StringLib.interpolateStrings("Maximum value is:{0:d}", Sequence{maxy}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) print((1900*m+100*(n-m))*(2**m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((1900 * m + 100 * (n - m)) * ((2)->pow(m)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* def printLargestDivisible(n,a): c0,c5=0,0 for i in range(n): if a[i]==0 : c0+=1 else : c5+=1 c5=floor(c5/9)*9 if c0==0 : print(-1,end="") elif c5==0 : print(0,end="") else : for i in range(c5): print(5,end="") for i in range(c0): print(0,end="") if __name__=="__main__" : a=[5,5,5,5,5,5,5,5,0,5,5] n=len(a) printLargestDivisible(n,a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( a := Sequence{5}->union(Sequence{5}->union(Sequence{5}->union(Sequence{5}->union(Sequence{5}->union(Sequence{5}->union(Sequence{5}->union(Sequence{5}->union(Sequence{0}->union(Sequence{5}->union(Sequence{ 5 })))))))))) ; n := (a)->size() ; printLargestDivisible(n, a) ) else skip; operation printLargestDivisible(n : OclAny, a : OclAny) pre: true post: true activity: var c0 : OclAny := null; var c5 : OclAny := null; Sequence{c0,c5} := Sequence{0,0} ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = 0 then ( c0 := c0 + 1 ) else ( c5 := c5 + 1 )) ; var c5 : double := floor(c5 / 9) * 9 ; if c0 = 0 then ( execute (-1)->display() ) else (if c5 = 0 then ( execute (0)->display() ) else ( for i : Integer.subrange(0, c5-1) do ( execute (5)->display()) ; for i : Integer.subrange(0, c0-1) do ( execute (0)->display()) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,math,bisect,itertools,collections,heapq,queue from decimal import Decimal from collections import defaultdict,deque sys.setrecursionlimit(10000000) ii=lambda : int(sys.stdin.buffer.readline().rstrip()) il=lambda : list(map(int,sys.stdin.buffer.readline().split())) fl=lambda : list(map(float,sys.stdin.buffer.readline().split())) iln=lambda n :[int(sys.stdin.buffer.readline().rstrip())for _ in range(n)] iss=lambda : sys.stdin.buffer.readline().decode().rstrip() sl=lambda : list(map(str,sys.stdin.buffer.readline().decode().split())) isn=lambda n :[sys.stdin.buffer.readline().decode().rstrip()for _ in range(n)] lcm=lambda x,y :(x*y)//math.gcd(x,y) MOD=10**9+7 MAX=float('inf') def main(): if os.getenv("LOCAL"): sys.stdin=open("input.txt","r") N,M=il() o=1900*M+(N-M)*100 print(o*(2**M)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit(10000000) ; var ii : Function := lambda $$ : OclAny in (("" + ((sys.stdin.buffer.readLine().rstrip())))->toInteger()) ; var il : Function := lambda $$ : OclAny in (((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var fl : Function := lambda $$ : OclAny in (((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ))) ; var iln : Function := lambda n : OclAny in (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + ((sys.stdin.buffer.readLine().rstrip())))->toInteger()))) ; var iss : Function := lambda $$ : OclAny in (sys.stdin.buffer.readLine().decode().rstrip()) ; var sl : Function := lambda $$ : OclAny in (((sys.stdin.buffer.readLine().decode().split())->collect( _x | (OclType["String"])->apply(_x) ))) ; var isn : Function := lambda n : OclAny in (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (sys.stdin.buffer.readLine().decode().rstrip()))) ; var lcm : Function := lambda x : OclAny, y : OclAny in ((x * y) div (x)->gcd(y)) ; var MOD : double := (10)->pow(9) + 7 ; var MAX : double := ("" + (('inf')))->toReal() ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: if os.getenv("LOCAL") then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ) else skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := il->apply() ; var o : double := 1900 * M + (N - M) * 100 ; execute (o * ((2)->pow(M)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def foo(ifile): a=[int(x)for x in ifile.readline().split()][1 :] a.sort() if len(a)==0 : return 0 bb={} for item in a : t=0 if item-1 in bb : t=bb[item-1][0] bb[item-1]=bb[item-1][1 :] if len(bb[item-1])==0 : del bb[item-1] if item not in bb : bb[item]=[] bb[item].append(t+1) bb[item].sort() res=len(a) for k,v in bb.items(): res=min(res,min(v)) return res def main(ifile,ofile): n=int(ifile.readline()) for i in range(n): ofile.write("Case #%s: %s\n" %(i+1,foo(ifile))) main(sys.stdin,sys.stdout) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; main(OclFile["System.in"], OclFile["System.out"]); operation foo(ifile : OclAny) : OclAny pre: true post: true activity: var a : OclAny := ifile.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))->tail() ; a := a->sort() ; if (a)->size() = 0 then ( return 0 ) else skip ; var bb : OclAny := Set{} ; for item : a do ( var t : int := 0 ; if (bb)->includes(item - 1) then ( t := bb[item - 1+1]->first() ; bb[item - 1+1] := bb[item - 1+1]->tail() ; if (bb[item - 1+1])->size() = 0 then ( execute (bb[item - 1+1])->isDeleted() ) else skip ) else skip ; if (bb)->excludes(item) then ( bb[item+1] := Sequence{} ) else skip ; (expr (atom (name bb)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name item)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name t))) + (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name bb)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name item)))))))) ])) (trailer . (name sort) (arguments ( ))))) ; var res : int := (a)->size() ; for _tuple : bb->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); res := Set{res, (v)->min()}->min()) ; return res; operation main(ifile : OclAny, ofile : OclAny) pre: true post: true activity: var n : int := ("" + ((ifile.readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( ofile.write(StringLib.format("Case #%s: %s\n",Sequence{i + 1, foo(ifile)}))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(500000) MOD=10**9+7 def input(): return sys.stdin.readline()[:-1] def mi(): return map(int,input().split()) def ii(): return int(input()) def i2(n): tmp=[list(mi())for i in range(n)] return[list(i)for i in zip(*tmp)] def main(): N,M=mi() print((1<pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation mi() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation ii() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation i2(n : OclAny) : OclAny pre: true post: true activity: var tmp : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((mi()))) ; return Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name tmp)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name tmp)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name tmp)))))))`third->at(_indx)} )->select(i | true)->collect(i | ((i))); operation main() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := mi() ; execute ((1 * (2->pow(M))) * (1800 * M + 100 * N))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,m=map(int,input().split()) t=(n-m)*100+m*1900 pas=0.5**m ans=t*pas cnt=1 while True : ans+=(cnt+1)*t*pas*((1-pas)**cnt) cnt+=1 if cnt>1000000 : break print(round(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : double := (n - m) * 100 + m * 1900 ; var pas : double := (0.5)->pow(m) ; var ans : double := t * pas ; var cnt : int := 1 ; while true do ( ans := ans + (cnt + 1) * t * pas * (((1 - pas))->pow(cnt)) ; cnt := cnt + 1 ; if cnt > 1000000 then ( break ) else skip) ; execute ((ans)->round())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[int(s)for s in input().split()] print(((a[0]-a[1])*100+a[1]*1900)*(2**a[1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; execute (((a->first() - a[1+1]) * 100 + a[1+1] * 1900) * ((2)->pow(a[1+1])))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CheckArray(arr,n): prod=1 for i in range(0,n,1): prod*=arr[i] for i in range(0,n,1): if(arr[i]==prod/arr[i]): return True return False if __name__=='__main__' : arr=[1,2,12,3,2] n=len(arr) if(CheckArray(arr,n)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{12}->union(Sequence{3}->union(Sequence{ 2 })))) ; n := (arr)->size() ; if (CheckArray(arr, n)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; operation CheckArray(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var prod : int := 1 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( prod := prod * arr[i+1]) ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (arr[i+1] = prod / arr[i+1]) then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re b=s=input() while 1 : s=re.sub(r'(m|e)mew(e|w)','\\1\\2',s) if b==s : break b=s print(['Rabbit','Cat'][s=='mew']) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var b : OclAny := (OclFile["System.in"]).readLine(); var s : String := (OclFile["System.in"]).readLine() ; while 1 do ( s := (s).replaceAllMatches(StringLib.rawString('(m|e)mew(e|w)'), '\\1\\2') ; if b = s then ( break ) else skip ; b := s) ; execute (Sequence{'Rabbit'}->union(Sequence{ 'Cat' })->select(s = 'mew'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**5) def LI(): return[int(x)for x in input().split()] def LF(): return[float(x)for x in input().split()] def LI_(): return[-1*int(x)for x in input().split()] def II(): return int(input()) def IF(): return float(input()) def LM(func,n): return[[func(x)for x in input().split()]for i in range(n)] mod=1000000007 inf=float('INF') def isCat(S): if len(S)==0 : return True if S[0]!="m" or S[-1]!="w" : return False c=0 i=0 for i in range(1,len(S)-1): if S[i]=='m' : c+=1 elif S[i]=='w' : c-=1 if c==0 : break if S[1]=='e' : i=0 return S[i+1]=='e' and isCat(S[1 : i+1])and isCat(S[i+2 :-1]) if(isCat(input())): print("Cat") else : print("Rabbit") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(5)) ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : int := 1000000007 ; var Math_PINFINITY : double := ("" + (('INF')))->toReal() ; skip ; if (isCat((OclFile["System.in"]).readLine())) then ( execute ("Cat")->display() ) else ( execute ("Rabbit")->display() ); operation LI() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LF() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LI_() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (-1 * ("" + ((x)))->toInteger())); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation IF() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation LM(func : OclAny, n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (input().split()->select(x | true)->collect(x | (func(x))))); operation isCat(S : OclAny) : OclAny pre: true post: true activity: if (S)->size() = 0 then ( return true ) else skip ; if S->first() /= "m" or S->last() /= "w" then ( return false ) else skip ; var c : int := 0 ; var i : int := 0 ; for i : Integer.subrange(1, (S)->size() - 1-1) do ( if S[i+1] = 'm' then ( c := c + 1 ) else (if S[i+1] = 'w' then ( c := c - 1 ) else skip) ; if c = 0 then ( break ) else skip) ; if S[1+1] = 'e' then ( i := 0 ) else skip ; return S[i + 1+1] = 'e' & isCat(S.subrange(1+1, i + 1)) & isCat(S.subrange(i + 2+1, -1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inf=1000000007 def check(roar,i): if roar[i]!='m' : return inf i+=1 if roar[i]=='e' : i+=1 else : j=check(roar,i) if j==inf : return inf i=j+1 if roar[i]=='w' : i+=1 else : j=check(roar,i) if j==inf : return inf i=j+1 return i def main(): roar=input() if check(roar,0)==len(roar): print('Cat') else : print('Rabbit') if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Math_PINFINITY : int := 1000000007 ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation check(roar : OclAny, i : OclAny) : OclAny pre: true post: true activity: if roar[i+1] /= 'm' then ( return Math_PINFINITY ) else skip ; i := i + 1 ; if roar[i+1] = 'e' then ( i := i + 1 ) else ( var j : OclAny := check(roar, i) ; if j = Math_PINFINITY then ( return Math_PINFINITY ) else skip ; i := j + 1 ) ; if roar[i+1] = 'w' then ( i := i + 1 ) else ( j := check(roar, i) ; if j = Math_PINFINITY then ( return Math_PINFINITY ) else skip ; i := j + 1 ) ; return i; operation main() pre: true post: true activity: roar := (OclFile["System.in"]).readLine() ; if check(roar, 0) = (roar)->size() then ( execute ('Cat')->display() ) else ( execute ('Rabbit')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() L=len(S) dp=[[False]*(L+1)for _ in range(L+1)] for i in range(L+1): dp[i][i]=True for w in range(3,L+1,3): for left in range(L-w+1): right=left+w if S[left]!='m' or S[right-1]!='w' : continue for mid in range(left+1,right): if S[mid]=='e' and dp[left+1][mid]and dp[mid+1][right-1]: dp[left][right]=True break print("Cat" if dp[0][L]else "Rabbit") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var L : int := (S)->size() ; var dp : Sequence := Integer.subrange(0, L + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ false }, (L + 1)))) ; for i : Integer.subrange(0, L + 1-1) do ( dp[i+1][i+1] := true) ; for w : Integer.subrange(3, L + 1-1)->select( $x | ($x - 3) mod 3 = 0 ) do ( for left : Integer.subrange(0, L - w + 1-1) do ( var right : OclAny := left + w ; if S[left+1] /= 'm' or S[right - 1+1] /= 'w' then ( continue ) else skip ; for mid : Integer.subrange(left + 1, right-1) do ( if S[mid+1] = 'e' & dp[left + 1+1][mid+1] & dp[mid + 1+1][right - 1+1] then ( dp[left+1][right+1] := true ; break ) else skip))) ; execute (if dp->first()[L+1] then "Cat" else "Rabbit" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countWays(n): counter=0 for i in range(1,n): for j in range(i,n): for k in range(j,n): for l in range(k,n): if(i+j+k+l==n): counter+=1 return counter if __name__=="__main__" : n=8 print(countWays(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 8 ; execute (countWays(n))->display() ) else skip; operation countWays(n : OclAny) : OclAny pre: true post: true activity: var counter : int := 0 ; for i : Integer.subrange(1, n-1) do ( for j : Integer.subrange(i, n-1) do ( for k : Integer.subrange(j, n-1) do ( for l : Integer.subrange(k, n-1) do ( if (i + j + k + l = n) then ( counter := counter + 1 ) else skip)))) ; return counter; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() tmp=s while True : s=s.replace("mew","Y") s=s.replace("mXeXw","Y") s=s.replace("meXw","Y") s=s.replace("mXew","Y") s=s.replace("Y","X") if s==tmp : if s=="X" or s=="" : print("Cat") else : print("Rabbit") break tmp=s ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var tmp : String := s ; while true do ( s := s.replace("mew", "Y") ; s := s.replace("mXeXw", "Y") ; s := s.replace("meXw", "Y") ; s := s.replace("mXew", "Y") ; s := s.replace("Y", "X") ; if s = tmp then ( if s = "X" or s = "" then ( execute ("Cat")->display() ) else ( execute ("Rabbit")->display() ) ; break ) else skip ; tmp := s); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def xor_all_elements(n): if n & 3==0 : return n elif n & 3==1 : return 1 elif n & 3==2 : return n+1 else : return 0 def findArray(xorr,n): arr=[] xor_all=xor_all_elements(n) xor_adjacent=0 for i in range(0,n-1,2): xor_adjacent=xor_adjacent ^ xorr[i] last_element=xor_all ^ xor_adjacent arr.append(last_element) for i in range(n-2,-1,-1): last_element=xorr[i]^ last_element arr.append(last_element) return arr xorr=[7,5,3,7] n=5 arr=findArray(xorr,n) for i in range(n-1,-1,-1): print(arr[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; xorr := Sequence{7}->union(Sequence{5}->union(Sequence{3}->union(Sequence{ 7 }))) ; n := 5 ; arr := findArray(xorr, n) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( execute (arr[i+1])->display()); operation xor_all_elements(n : OclAny) : OclAny pre: true post: true activity: if MathLib.bitwiseAnd(n, 3) = 0 then ( return n ) else (if MathLib.bitwiseAnd(n, 3) = 1 then ( return 1 ) else (if MathLib.bitwiseAnd(n, 3) = 2 then ( return n + 1 ) else ( return 0 ) ) ) ; operation findArray(xorr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var arr : Sequence := Sequence{} ; var xor_all : OclAny := xor_all_elements(n) ; var xor_adjacent : int := 0 ; for i : Integer.subrange(0, n - 1-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( xor_adjacent := MathLib.bitwiseXor(xor_adjacent, xorr[i+1])) ; var last_element : int := MathLib.bitwiseXor(xor_all, xor_adjacent) ; execute ((last_element) : arr) ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( last_element := MathLib.bitwiseXor(xorr[i+1], last_element) ; execute ((last_element) : arr)) ; return arr; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import division from __future__ import with_statement from __future__ import print_function def memoized(func): mem={} def wrapped(*args): if args not in mem : mem[args]=func(*args) return mem[args] return wrapped TASK="B" from collections import Counter from bisect import insort print("Calculation...") with open(TASK+".in")as infile : with open(TASK+".out",mode="wt")as outfile : cases=int(infile.readline()) for ncase in range(cases): print("Case #{nc}".format(nc=ncase+1)) cards=[int(s)for s in infile.readline().split()][1 :] values=Counter(cards) nums=[values[i]for i in xrange(0,10002)] starts=[] shortest=100000 c=0 for i,n in enumerate(nums): if n>c : starts+=[i]*(n-c) if c>n : shortest=min(shortest,i-starts[c-n-1]) starts=starts[c-n :] c=n if len(cards)==0 : shortest=0 outfile.write("Case #{nc}:{data}\n".format(nc=ncase+1,data=shortest)) print("Calculation done.") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var TASK : String := "B" ; skip ; skip ; execute ("Calculation...")->display() ; try (var infile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(TASK + ".in")); try (var outfile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(TASK + ".out")); var cases : int := ("" + ((infile.readLine())))->toInteger() ; for ncase : Integer.subrange(0, cases-1) do ( execute (StringLib.interpolateStrings("Case #{nc}", Sequence{(argument (test (logical_test (comparison (expr (atom (name nc)))))) = (test (logical_test (comparison (expr (expr (atom (name ncase))) + (expr (atom (number (integer 1)))))))))}))->display() ; var cards : OclAny := infile.readLine().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger()))->tail() ; var values : OclAny := Counter(cards) ; var nums : Sequence := xrange(0, 10002)->select(i | true)->collect(i | (values[i+1])) ; var starts : Sequence := Sequence{} ; var shortest : int := 100000 ; var c : int := 0 ; for _tuple : Integer.subrange(1, (nums)->size())->collect( _indx | Sequence{_indx-1, (nums)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var n : OclAny := _tuple->at(_indx); if (n->compareTo(c)) > 0 then ( starts := starts + MatrixLib.elementwiseMult(Sequence{ i }, (n - c)) ) else skip ; if (c->compareTo(n)) > 0 then ( shortest := Set{shortest, i - starts[c - n - 1+1]}->min() ; starts := starts.subrange(c - n+1) ) else skip ; c := n) ; if (cards)->size() = 0 then ( shortest := 0 ) else skip ; outfile.write(StringLib.interpolateStrings("Case #{nc}:{data}\n", Sequence{(argument (test (logical_test (comparison (expr (atom (name nc)))))) = (test (logical_test (comparison (expr (expr (atom (name ncase))) + (expr (atom (number (integer 1))))))))), (argument (test (logical_test (comparison (expr (atom (name data)))))) = (test (logical_test (comparison (expr (atom (name shortest)))))))})))) catch (_e : OclException) do skip) catch (_e : OclException) do skip ; execute ("Calculation done.")->display(); operation memoized(func : OclAny) : OclAny pre: true post: true activity: var mem : OclAny := Set{} ; skip ; return wrapped; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,x=[0]*1000,[0]*22 a=[[0 for i in range(22)]for j in range(1000)] ans=0 def dfs(u,p): global ans for i in range(0,len(g[u])): v=g[u][i] if v!=p : dfs(v,u) for i in range(0,22): a[u][i]+=a[v][i] pp=0 for i in range(0,22): if(not((a[u][i]>0 and x[i]-a[u][i]>0)or(a[u][i]==0 and x[i]==0))): pp=1 break if pp==0 : ans+=1 if __name__=="__main__" : n=4 g=[[]for i in range(n+1)] m[1]=1 m[2]=3 m[3]=2 m[4]=3 for i in range(1,n+1): y,k=m[i],0 while y!=0 : p=y % 2 if p==1 : x[k]+=1 a[i][k]+=1 y=y//2 k+=1 g[1].append(2) g[2].append(1) g[1].append(3) g[3].append(1) g[1].append(4) g[4].append(1) dfs(1,0) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute ans : OclAny; operation initialise() pre: true post: true activity: var m : OclAny := null; var x : OclAny := null; Sequence{m,x} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, 1000),MatrixLib.elementwiseMult(Sequence{ 0 }, 22)} ; var a : Sequence := Integer.subrange(0, 1000-1)->select(j | true)->collect(j | (Integer.subrange(0, 22-1)->select(i | true)->collect(i | (0)))) ; var ans : int := 0 ; skip ; if __name__ = "__main__" then ( var n : int := 4 ; var g : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Sequence{})) ; m[1+1] := 1 ; m[2+1] := 3 ; m[3+1] := 2 ; m[4+1] := 3 ; for i : Integer.subrange(1, n + 1-1) do ( var y : OclAny := null; var k : OclAny := null; Sequence{y,k} := Sequence{m[i+1],0} ; while y /= 0 do ( p := y mod 2 ; if p = 1 then ( x[k+1] := x[k+1] + 1 ; a[i+1][k+1] := a[i+1][k+1] + 1 ) else skip ; var y : int := y div 2 ; k := k + 1)) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 3))))))))) )))) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 3))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 4))))))))) )))) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 4))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))) ; dfs(1, 0) ; execute (ans)->display() ) else skip; operation dfs(u : OclAny, p : OclAny) pre: true post: true activity: skip ; for i : Integer.subrange(0, (g[u+1])->size()-1) do ( var v : OclAny := g[u+1][i+1] ; if v /= p then ( dfs(v, u) ; for i : Integer.subrange(0, 22-1) do ( a[u+1][i+1] := a[u+1][i+1] + a[v+1][i+1]) ) else skip) ; var pp : int := 0 ; for i : Integer.subrange(0, 22-1) do ( if (not(((a[u+1][i+1] > 0 & x[i+1] - a[u+1][i+1] > 0) or (a[u+1][i+1] = 0 & x[i+1] = 0)))) then ( pp := 1 ; break ) else skip) ; if pp = 0 then ( ans := ans + 1 ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class UnionSet : def __init__(self,nmax): self.size=[1]*nmax self.id=[i for i in range(nmax+1)] def root(self,i): while i!=self.id[i]: self.id[i]=self.id[self.id[i]] i=self.id[i] return i def connected(self,p,q): return self.root(p)==self.root(q) def unite(self,p,q): i,j=self.root(p),self.root(q) if i==j : return if self.size[i]1 : b+=1 print(abs(a-b)) ------------------------------------------------------------ OCL File: --------- class UnionSet { static operation newUnionSet() : UnionSet pre: true post: UnionSet->exists( _x | result = _x ); attribute size : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, nmax); attribute id : Sequence := Integer.subrange(0, nmax + 1-1)->select(i | true)->collect(i | (i)); operation initialise(nmax : OclAny) : UnionSet pre: true post: true activity: self.size := MatrixLib.elementwiseMult(Sequence{ 1 }, nmax) ; self.id := Integer.subrange(0, nmax + 1-1)->select(i | true)->collect(i | (i)); return self; operation root(i : OclAny) : OclAny pre: true post: true activity: while i /= self.id[i+1] do ( self.id[i+1] := self.id[self.id[i+1]+1] ; i := self.id[i+1]) ; return i; operation connected(p : OclAny,q : OclAny) : OclAny pre: true post: true activity: return self.root(p) = self.root(q); operation unite(p : OclAny,q : OclAny) pre: true post: true activity: var j : OclAny := null; Sequence{i,j} := Sequence{self.root(p),self.root(q)} ; if i = j then ( return ) else skip ; if (self.size[i+1]->compareTo(self.size[j+1])) < 0 then ( self.id[i+1] := j ; self.size[j+1] := self.size[j+1] + self.size[i+1] ) else ( self.id[j+1] := i ; self.size[i+1] := self.size[i+1] + self.size[j+1] ); } class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var u : UnionSet := (UnionSet.newUnionSet()).initialise(N + 1) ; var f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; for i : Integer.subrange(0, M-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; u.unite(a, b)) ; for i : Integer.subrange(1, N + 1-1) do ( f[u.root(i)+1] := f[u.root(i)+1] + 1) ; var a : OclAny := 0; var b : int := 0 ; for i : Integer.subrange(1, N + 1-1) do ( if f[i+1] = 1 then ( a := a + 1 ) else (if f[i+1] > 1 then ( b := b + 1 ) else skip)) ; execute ((a - b)->abs())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import array class UnionFind(object): def __init__(self,number_of_nodes,typecode="L"): self.typecode=typecode self.par=array.array(typecode,range(number_of_nodes)) self.rank=array.array(typecode,(0 for i in range(number_of_nodes))) def root(self,node): if self.par[node]==node : return node else : r=self.root(self.par[node]) self.par[node]=r return r def in_the_same_set(self,node1,node2): return self.root(node1)==self.root(node2) def unite(self,node1,node2): x=self.root(node1) y=self.root(node2) if x==y : pass elif self.rank[x]exists( _x | result = _x ); attribute typecode : String := typecode; attribute par : OclAny := array.array(typecode, Integer.subrange(0, number_of_nodes-1)); attribute rank : OclAny := array.array(typecode, Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name number_of_nodes)))))))) ))))))))}); operation initialise(number_of_nodes : OclAny,typecode : String) : pre: true post: true activity: self.typecode := typecode ; self.par := array.array(typecode, Integer.subrange(0, number_of_nodes-1)) ; self.rank := array.array(typecode, Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name number_of_nodes)))))))) ))))))))}); return self; operation root(node : OclAny) : OclAny pre: true post: true activity: if self.par[node+1] = node then ( return node ) else ( var r : OclAny := self.root(self.par[node+1]) ; self.par[node+1] := r ; return r ); operation in_the_same_set(node1 : OclAny,node2 : OclAny) : OclAny pre: true post: true activity: return self.root(node1) = self.root(node2); operation unite(node1 : OclAny,node2 : OclAny) pre: true post: true activity: var x : OclAny := self.root(node1) ; var y : OclAny := self.root(node2) ; if x = y then ( skip ) else (if (self.rank[x+1]->compareTo(self.rank[y+1])) < 0 then ( self.par[x+1] := y ) else ( self.par[y+1] := x ; if self.rank[x+1] = self.rank[y+1] then ( self.rank[x+1] := self.rank[x+1] + 1 ) else skip ) ) ; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var uf : UnionFind := (UnionFind.newUnionFind()).initialise(n, "I") ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ) ; uf.unite(a, b)) ; var city_representatives : Set := Set{}->union(()) ; var num_cities_and_villages : int := 0 ; for i : Integer.subrange(0, n-1) do ( var rep : OclAny := uf.root(i) ; if i = rep then ( num_cities_and_villages := num_cities_and_villages + 1 ) else ( execute ((rep) : city_representatives) )) ; var num_cities : int := (city_representatives)->size() ; var answer : double := (num_cities_and_villages - 2 * num_cities)->abs() ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- [m,n]=map(int,input().split()) def find(v,cs): for c in cities : if v in c : return(True,c) return(False,set([v])) cities=[] for _ in range(n): [a,b]=map(int,input().split()) (ra,fa)=find(a,cities) (rb,fb)=find(b,cities) mg=fa | fb if ra : cities.remove(fa) else : m=m-1 if rb : if fa!=fb : cities.remove(fb) else : m=m-1 cities.append(mg) print(abs(m-len(cities))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: Sequence{m}->union(Sequence{ n }) := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; var cities : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( ; Sequence{a}->union(Sequence{ b }) := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var Sequence{ra, fa} : OclAny := find(a, cities) ; var Sequence{rb, fb} : OclAny := find(b, cities) ; var mg : int := MathLib.bitwiseOr(fa, fb) ; if ra then ( execute ((fa) /: cities) ) else ( var m : double := m - 1 ) ; if rb then ( if fa /= fb then ( execute ((fb) /: cities) ) else skip ) else ( m := m - 1 ) ; execute ((mg) : cities)) ; execute ((m - (cities)->size())->abs())->display(); operation find(v : OclAny, cs : OclAny) : OclAny pre: true post: true activity: for c : cities do ( if (c)->includes(v) then ( return Sequence{true, c} ) else skip) ; return Sequence{false, Set{}->union((Sequence{ v }))}; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) q=[] for _ in range(m): a,b=map(int,input().split()) i,j=-1,-1 for k in range(len(q)): if i==-1 : if a in q[k]: i=k if j==-1 : if b in q[k]: j=k if i>=0 and j>=0 : break if i>=0 : if j>=0 : if i!=j : q[i]|=q[j] q.pop(j) else : q[i].add(b) elif j>=0 : q[j].add(a) else : q.append(set([a,b])) print(abs(n-sum([len(i)for i in q])-len(q))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var q : Sequence := Sequence{} ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{-1,-1} ; for k : Integer.subrange(0, (q)->size()-1) do ( if i = -1 then ( if (q[k+1])->includes(a) then ( var i : OclAny := k ) else skip ) else skip ; if j = -1 then ( if (q[k+1])->includes(b) then ( var j : OclAny := k ) else skip ) else skip ; if i >= 0 & j >= 0 then ( break ) else skip) ; if i >= 0 then ( if j >= 0 then ( if i /= j then ( q[i+1] := q[i+1] or q[j+1] ; q := q->excludingAt(j+1) ) else skip ) else ( (expr (atom (name q)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ) ) else (if j >= 0 then ( (expr (atom (name q)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))) ) else ( execute ((Set{}->union((Sequence{a}->union(Sequence{ b })))) : q) ) ) ) ; execute ((n - (q->select(i | true)->collect(i | ((i)->size())))->sum() - (q)->size())->abs())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) parent=[i for i in range(n)] def get_par(x): if x==parent[x]: return x parent[x]=get_par(parent[x]) return parent[x] for _ in range(m): a,b=map(int,input().split()) a-=1 b-=1 pa,pb=get_par(a),get_par(b) parent[pb]=pa city_dic=set() village_cnt=0 for i in range(n): pi=get_par(i) if i==pi : village_cnt+=1 else : city_dic.add(pi) print(abs(2*len(city_dic)-village_cnt)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var parent : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)) ; skip ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := a - 1 ; b := b - 1 ; var pa : OclAny := null; var pb : OclAny := null; Sequence{pa,pb} := Sequence{get_par(a),get_par(b)} ; parent[pb+1] := pa) ; var city_dic : Set := Set{}->union(()) ; var village_cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( var pi : OclAny := get_par(i) ; if i = pi then ( village_cnt := village_cnt + 1 ) else ( execute ((pi) : city_dic) )) ; execute ((2 * (city_dic)->size() - village_cnt)->abs())->display(); operation get_par(x : OclAny) : OclAny pre: true post: true activity: if x = parent[x+1] then ( return x ) else skip ; parent[x+1] := get_par(parent[x+1]) ; return parent[x+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countDivisibles(arr,n): res=0 for i in range(0,n): for j in range(i+1,n): if(arr[i]% arr[j]==0 or arr[j]% arr[i]==0): res+=1 return res if __name__=='__main__' : a=[1,2,3,9] n=len(a) print(countDivisibles(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var a : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 9 }))) ; n := (a)->size() ; execute (countDivisibles(a, n))->display() ) else skip; operation countDivisibles(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if (arr[i+1] mod arr[j+1] = 0 or arr[j+1] mod arr[i+1] = 0) then ( res := res + 1 ) else skip)) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,m=map(int,input().split()) if n==0 and m==0 : break car_list=[] if n!=0 : A=list(map(int,input().split())) for i in range(n): car_list.append(A[i]) if m!=0 : A=list(map(int,input().split())) for i in range(m): car_list.append(A[i]) car_list.sort() car_list.insert(0,0) max_car=0 for i in range(n+m): if car_list[i+1]-car_list[i]>max_car : max_car=car_list[i+1]-car_list[i] print(max_car) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 & m = 0 then ( break ) else skip ; var car_list : Sequence := Sequence{} ; if n /= 0 then ( var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( execute ((A[i+1]) : car_list)) ) else skip ; if m /= 0 then ( A := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, m-1) do ( execute ((A[i+1]) : car_list)) ) else skip ; car_list := car_list->sort() ; car_list := car_list.insertAt(0+1, 0) ; var max_car : int := 0 ; for i : Integer.subrange(0, n + m-1) do ( if (car_list[i + 1+1] - car_list[i+1]->compareTo(max_car)) > 0 then ( max_car := car_list[i + 1+1] - car_list[i+1] ) else skip) ; execute (max_car)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def evenNumSubstring(str): length=len(str) count=0 for i in range(0,length,1): temp=ord(str[i])-ord('0') if(temp % 2==0): count+=(i+1) return count if __name__=='__main__' : str=['1','2','3','4'] print(evenNumSubstring(str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( OclType["String"] := Sequence{'1'}->union(Sequence{'2'}->union(Sequence{'3'}->union(Sequence{ '4' }))) ; execute (evenNumSubstring(OclType["String"]))->display() ) else skip; operation evenNumSubstring(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var length : int := (OclType["String"])->size() ; var count : int := 0 ; for i : Integer.subrange(0, length-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( var temp : double := (("" + ([i+1])))->char2byte() - ('0')->char2byte() ; if (temp mod 2 = 0) then ( count := count + (i + 1) ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def numberOfMinutes(S,S1): Min=0 ; Min=((S-S1)/math.floor(S))*60 ; return int(Min); if __name__=='__main__' : S,S1=30,10 ; print(numberOfMinutes(S,S1),"min"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( Sequence{S,S1} := Sequence{30,10}; ; execute (numberOfMinutes(S, S1))->display(); ) else skip; operation numberOfMinutes(S : OclAny, S1 : OclAny) pre: true post: true activity: var Min : int := 0; ; Min := ((S - S1) / (S)->floor()) * 60; ; return ("" + ((Min)))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=(int(i)for i in input().split()) x=N % K ans=min(abs(x-K),x) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var x : int := N mod K ; var ans : OclAny := Set{(x - K)->abs(), x}->min() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* from copy import* from string import* from random import* from bisect import* from sys import stdin from sys import maxsize from operator import* from itertools import* from collections import Counter from collections import defaultdict def solve(n,k): return min(n % k,abs(n % k-k)) N,K=list(map(int,stdin.readline().rstrip().split())) ans=solve(N,K) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := ((stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : OclAny := solve(N, K) ; execute (ans)->display(); operation solve(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: return Set{n mod k, (n mod k - k)->abs()}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- NK=input().split() N=int(NK[0]) K=int(NK[1]) def func(N,K): prev=N while(1): N=abs(N-K) if prev<=N : return prev prev=N def fun(N,K): N=(N % K) return N S=fun(N,K) T=func(S,K) print(T) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var NK : OclAny := input().split() ; var N : int := ("" + ((NK->first())))->toInteger() ; var K : int := ("" + ((NK[1+1])))->toInteger() ; skip ; skip ; var S : OclAny := fun(N, K) ; var T : OclAny := func(S, K) ; execute (T)->display(); operation func(N : OclAny, K : OclAny) : OclAny pre: true post: true activity: var prev : int := N ; while (1) do ( N := (N - K)->abs() ; if (prev->compareTo(N)) <= 0 then ( return prev ) else skip ; prev := N); operation fun(N : OclAny, K : OclAny) : OclAny pre: true post: true activity: N := (N mod K) ; return N; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter from sys import stdin from itertools import permutations from collections import Counter from collections import defaultdict def solve(): pass t=int(input()) for i in range(t): n,x=map(int,input().split()) a=list(map(int,input().split())) a.sort() d=defaultdict(int) for i in a : if d[i]: d[i]-=1 else : d[i*x]+=1 print(sum(d.values())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var d : OclAny := defaultdict(OclType["int"]) ; for i : a do ( if d[i+1] then ( d[i+1] := d[i+1] - 1 ) else ( d[i * x+1] := d[i * x+1] + 1 )) ; execute ((d.values())->sum())->display()); operation solve() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) mm=n % k mmm=k-mm if mmm>=mm : ans=mm else : ans=mmm print(str(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mm : int := n mod k ; var mmm : double := k - mm ; if (mmm->compareTo(mm)) >= 0 then ( var ans : int := mm ) else ( ans := mmm ) ; execute (("" + ((ans))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.readline()[:-1] def main(): N,K=map(int,input().split()) ans=N % K ans=min(ans,abs(ans-K)) print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation main() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := N mod K ; ans := Set{ans, (ans - K)->abs()}->min() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,W=map(int,input().split()) P=[list(map(int,input().split()))for _ in range(N)] mem=[[0]*(W+2)for _ in range(N+2)] for i in range(N,0,-1): for w in range(0,W+1): value,weight=P[i-1] if wcollect( _x | (OclType["int"])->apply(_x) ) ; var P : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var mem : Sequence := Integer.subrange(0, N + 2-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (W + 2)))) ; for i : Integer.subrange(0 + 1, N)->reverse() do ( for w : Integer.subrange(0, W + 1-1) do ( var value : OclAny := null; var weight : OclAny := null; Sequence{value,weight} := P[i - 1+1] ; if (w->compareTo(weight)) < 0 then ( mem[i+1][w+1] := mem[i + 1+1][w+1] ) else ( mem[i+1][w+1] := Set{mem[i + 1+1][w+1], mem[i + 1+1][w - weight+1] + value}->max() ))) ; execute (mem[1+1][W+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import lru_cache @ lru_cache(None) def dp(i,cur): if cur>W : return float('-inf') elif i<0 : return 0 else : v,w=VW[i] return max(dp(i-1,cur),dp(i-1,cur+w)+v) N,W=map(int,input().split()) VW=[[int(x)for x in input().split()]for _ in range(N)] print(dp(N-1,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; (compound_stmt (decorator @ (dotted_name (name lru_cache)) ( (arglist (argument (test (logical_test (comparison (expr (atom None))))))) )) (funcdef def (name dp) ( (typedargslist (def_parameters (def_parameter (named_parameter (name i))) , (def_parameter (named_parameter (name cur))))) ) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name cur)))) > (comparison (expr (atom (name W))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name float)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '-inf'))))))) )))))))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name i)))) < (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name v)))))) , (test (logical_test (comparison (expr (atom (name w))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name VW)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name cur)))))))) )))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name dp)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name cur))) + (expr (atom (name w))))))))) )))) + (expr (atom (name v))))))))) )))))))))))))))))) ; var N : OclAny := null; var W : OclAny := null; Sequence{N,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var VW : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))) ; execute (dp(N - 1, 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,radians from itertools import accumulate,permutations,combinations,product from operator import itemgetter,mul from copy import deepcopy from string import ascii_lowercase,ascii_uppercase,digits from bisect import bisect,bisect_left from fractions import gcd from heapq import heappush,heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) sys.setrecursionlimit(10**9) INF=float('inf') mod=10**9+7 N,W=MAP() v,w=[0]*N,[0]*N for i in range(N): v[i],w[i]=MAP() dp=[0]*(W+1) for i in range(N): for j in range(W,w[i]-1,-1): dp[j]=max(dp[j],dp[j-w[i]]+v[i]) print(dp[W]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var N : OclAny := null; var W : OclAny := null; Sequence{N,W} := MAP() ; var v : OclAny := null; var w : OclAny := null; Sequence{v,w} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, N),MatrixLib.elementwiseMult(Sequence{ 0 }, N)} ; for i : Integer.subrange(0, N-1) do ( var v[i+1] : OclAny := null; var w[i+1] : OclAny := null; Sequence{v[i+1],w[i+1]} := MAP()) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (W + 1)) ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(w[i+1] - 1 + 1, W)->reverse() do ( dp[j+1] := Set{dp[j+1], dp[j - w[i+1]+1] + v[i+1]}->max())) ; execute (dp[W+1])->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,W=(int(x)for x in input().split()) value=[] weight=[] for n in range(N): a,b=(int(x)for x in input().split()) value.append(a) weight.append(b) def knap(N,W,value,weight): dp=[[0]*(W+1)for _ in range(N+1)] for i in range(N+1): for w in range(W+1): if i>0 : if weight[i-1]<=w : dp[i][w]=max(dp[i-1][w],dp[i-1][w-weight[i-1]]+value[i-1]) else : dp[i][w]=dp[i-1][w] return dp[N][W] print(knap(N,W,value,weight)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var W : OclAny := null; Sequence{N,W} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var value : Sequence := Sequence{} ; var weight : Sequence := Sequence{} ; for n : Integer.subrange(0, N-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; execute ((a) : value) ; execute ((b) : weight)) ; skip ; execute (knap(N, W, value, weight))->display(); operation knap(N : OclAny, W : OclAny, value : OclAny, weight : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (W + 1)))) ; for i : Integer.subrange(0, N + 1-1) do ( for w : Integer.subrange(0, W + 1-1) do ( if i > 0 then ( if (weight[i - 1+1]->compareTo(w)) <= 0 then ( dp[i+1][w+1] := Set{dp[i - 1+1][w+1], dp[i - 1+1][w - weight[i - 1+1]+1] + value[i - 1+1]}->max() ) else ( dp[i+1][w+1] := dp[i - 1+1][w+1] ) ) else skip)) ; return dp[N+1][W+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fn(n,m,k,L): g=min(L) L=[p-g for p in L] op=[] for i in range(len(L)-1): op.append(L[i+1]-L[i]-1) op.sort() dist=n for gt in range(n-k): dist+=op[gt] return(dist) a=input().split() b=input().split() a=[int(s)for s in a] b=[int(t)for t in b] print(fn(a[0],a[1],a[2],b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := input().split() ; var b : OclAny := input().split() ; a := a->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; b := b->select(t | true)->collect(t | (("" + ((t)))->toInteger())) ; execute (fn(a->first(), a[1+1], a[2+1], b))->display(); operation fn(n : OclAny, m : OclAny, k : OclAny, L : OclAny) : OclAny pre: true post: true activity: var g : OclAny := (L)->min() ; L := L->select(p | true)->collect(p | (p - g)) ; var op : Sequence := Sequence{} ; for i : Integer.subrange(0, (L)->size() - 1-1) do ( execute ((L[i + 1+1] - L[i+1] - 1) : op)) ; op := op->sort() ; var dist : OclAny := n ; for gt : Integer.subrange(0, n - k-1) do ( dist := dist + op[gt+1]) ; return (dist); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import namedtuple def solve_2(): dp=[0]*(real_cp+1) for item in item_list : v,w=item.v,item.w for cp in range(real_cp-w,-1,-1): dp[cp+w]=max(dp[cp+w],dp[cp]+v) return dp[-1] if __name__=='__main__' : _input=sys.stdin.readlines() c_items,real_cp=map(int,_input[0].split()) items=map(lambda x : x.split(),_input[1 :]) Item=namedtuple('Item',('v','w')) item_list=[Item(int(v),int(w))for v,w in items] ans=solve_2() print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( var _input : OclAny := (OclFile["System.in"]).readlines() ; var c_items : OclAny := null; var real_cp : OclAny := null; Sequence{c_items,real_cp} := (_input->first().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var items : Sequence := (_input->tail())->collect( _x | (lambda x : OclAny in (x.split()))->apply(_x) ) ; var Item : OclAny := namedtuple('Item', Sequence{'v', 'w'}) ; var item_list : Sequence := items->select(_tuple | true)->collect(_tuple | let v : OclAny = _tuple->at(1) in let w : OclAny = _tuple->at(2) in (Item(("" + ((v)))->toInteger(), ("" + ((w)))->toInteger()))) ; var ans : OclAny := solve_2() ; execute (ans)->display() ) else skip; operation solve var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (real_cp + 1)) ; for item : item_list do ( var v : OclAny := null; var w : OclAny := null; Sequence{v,w} := Sequence{item.v,item.w} ; for cp : Integer.subrange(-1 + 1, real_cp - w)->reverse() do ( dp[cp + w+1] := Set{dp[cp + w+1], dp[cp+1] + v}->max())) ; return dp->last()() : OclAny pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (real_cp + 1)) ; for item : item_list do ( var v : OclAny := null; var w : OclAny := null; Sequence{v,w} := Sequence{item.v,item.w} ; for cp : Integer.subrange(-1 + 1, real_cp - w)->reverse() do ( dp[cp + w+1] := Set{dp[cp + w+1], dp[cp+1] + v}->max())) ; return dp->last(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reverse(n): d=0 ; s=0 ; while(n>0): d=n % 10 ; s=s*10+d ; n=n//10 ; return s ; def isPalin(n): return n==reverse(n); def sumOfArray(arr,n): s=0 ; for i in range(n): if((arr[i]>10)and isPalin(arr[i])): s+=arr[i]; return s ; if __name__=="__main__" : n=6 ; arr=[12,313,11,44,9,1]; print(sumOfArray(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( n := 6; ; arr := Sequence{12}->union(Sequence{313}->union(Sequence{11}->union(Sequence{44}->union(Sequence{9}->union(Sequence{ 1 }))))); ; execute (sumOfArray(arr, n))->display(); ) else skip; operation reverse(n : OclAny) pre: true post: true activity: var d : int := 0; var s : int := 0; ; while (n > 0) do ( d := n mod 10; ; s := s * 10 + d; ; n := n div 10;) ; return s;; operation isPalin(n : OclAny) pre: true post: true activity: return n = reverse(n);; operation sumOfArray(arr : OclAny, n : OclAny) pre: true post: true activity: s := 0; ; for i : Integer.subrange(0, n-1) do ( if ((arr[i+1] > 10) & isPalin(arr[i+1])) then ( s := s + arr[i+1]; ) else skip) ; return s;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def assignValue(a,b,x): arr=[a,b] return(arr[x]) y=assignValue(3,7,0) print(y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var y : OclAny := assignValue(3, 7, 0) ; execute (y)->display(); operation assignValue(a : OclAny, b : OclAny, x : OclAny) : OclAny pre: true post: true activity: var arr : Sequence := Sequence{a}->union(Sequence{ b }) ; return (arr[x+1]); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- max_Element=100005 sum1=[0 for i in range(max_Element)] sum2=[0 for i in range(max_Element)] sum3=[0 for i in range(max_Element)] def precomputation(arr,n): for i in range(1,max_Element,1): for j in range(i,max_Element,i): sum1[j]+=i for i in range(1,max_Element,1): for j in range(i,max_Element,i): sum2[j]+=(sum1[j]-i)*i for i in range(1,max_Element,1): sum2[i]=int(sum2[i]/2) for i in range(1,max_Element,1): for j in range(i,max_Element,i): sum3[j]+=i*(sum2[j]-i*(sum1[j]-i)) for i in range(1,max_Element,1): sum3[i]=int(sum3[i]/3) for i in range(n): print(sum3[arr[i]],end=" ") if __name__=='__main__' : arr=[9,5,6] n=len(arr) precomputation(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var max_Element : int := 100005 ; var sum1 : Sequence := Integer.subrange(0, max_Element-1)->select(i | true)->collect(i | (0)) ; var sum2 : Sequence := Integer.subrange(0, max_Element-1)->select(i | true)->collect(i | (0)) ; var sum3 : Sequence := Integer.subrange(0, max_Element-1)->select(i | true)->collect(i | (0)) ; skip ; if __name__ = '__main__' then ( arr := Sequence{9}->union(Sequence{5}->union(Sequence{ 6 })) ; n := (arr)->size() ; precomputation(arr, n) ) else skip; operation precomputation(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(1, max_Element-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( for j : Integer.subrange(i, max_Element-1)->select( $x | ($x - i) mod i = 0 ) do ( sum1[j+1] := sum1[j+1] + i)) ; for i : Integer.subrange(1, max_Element-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( for j : Integer.subrange(i, max_Element-1)->select( $x | ($x - i) mod i = 0 ) do ( sum2[j+1] := sum2[j+1] + (sum1[j+1] - i) * i)) ; for i : Integer.subrange(1, max_Element-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( sum2[i+1] := ("" + ((sum2[i+1] / 2)))->toInteger()) ; for i : Integer.subrange(1, max_Element-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( for j : Integer.subrange(i, max_Element-1)->select( $x | ($x - i) mod i = 0 ) do ( sum3[j+1] := sum3[j+1] + i * (sum2[j+1] - i * (sum1[j+1] - i)))) ; for i : Integer.subrange(1, max_Element-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( sum3[i+1] := ("" + ((sum3[i+1] / 3)))->toInteger()) ; for i : Integer.subrange(0, n-1) do ( execute (sum3[arr[i+1]+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,x=map(int,input().split()) l1=list(map(int,input().split())) l1.sort(); cnt=0 ; j=0 for i in range(n): while jtoInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l1 := l1->sort(); var cnt : int := 0; var j : int := 0 ; for i : Integer.subrange(0, n-1) do ( while (j->compareTo(n - 1)) < 0 & (l1[j+1]->compareTo(l1[i+1] * x)) < 0 do ( j := j + 1) ; if l1[j+1] = l1[i+1] * x then ( cnt := cnt + 2 ; l1[j+1] := -1 ) else skip) ; execute (n - cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def printDivisors(n): list=[] for i in range(1,int(math.sqrt(n)+1)): if(n % i==0): if(n/i==i): print(i,end=" ") else : print(i,end=" ") list.append(int(n/i)) for i in list[: :-1]: print(i,end=" ") print("The divisors of 100 are: ") printDivisors(100) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; execute ("The divisors of 100 are: ")->display() ; printDivisors(100); operation printDivisors(n : OclAny) pre: true post: true activity: var OclType["Sequence"] : Sequence := Sequence{} ; for i : Integer.subrange(1, ("" + (((n)->sqrt() + 1)))->toInteger()-1) do ( if (n mod i = 0) then ( if (n / i = i) then ( execute (i)->display() ) else ( execute (i)->display() ; execute ((("" + ((n / i)))->toInteger()) : OclType["Sequence"]) ) ) else skip) ; for i : (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil for _ in range(int(input())): n,d=[int(i)for i in input().split()] if ceil(d/(n//2+1))+n//2<=n : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if (ceil(d / (n div 2 + 1)) + n div 2->compareTo(n)) <= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- exec(int(input())*"n,d=map(int,input().split());print('YNEOS'[4*d>(n+1)**2::2]);") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) )))) * (expr (atom "n,d=map(int,input().split());print('YNEOS'[4*d>(n+1)**2::2]);"))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,ceil def check(n,d): for x in range(n): if x+ceil(d/(x+1))<=n : return True return False if __name__=='__main__' : for _ in range(int(input())): print('YES' if check(*map(int,input().split()))else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (if check((argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) then 'YES' else 'NO' endif)->display()) ) else skip; operation check(n : OclAny, d : OclAny) : OclAny pre: true post: true activity: for x : Integer.subrange(0, n-1) do ( if (x + ceil(d / (x + 1))->compareTo(n)) <= 0 then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for _ in range(int(input())): n,d=map(int,input().split()) l,r=0,n while ln : l=m+1 else : print('YES') break else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,n} ; (compound_stmt while (test (logical_test (comparison (comparison (expr (atom (name l)))) < (comparison (expr (atom (name r))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name m)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name l))) + (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name r))) - (expr (atom (name l)))))))) ))) // (expr (atom (number (integer 2))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name temp)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name m))) + (expr (atom (name math)) (trailer . (name ceil) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name d))) / (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name m))) + (expr (atom (number (integer 1))))))))) ))))))))) )))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name temp)))) > (comparison (expr (atom (name n))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name m))) + (expr (atom (number (integer 1))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() I=lambda : map(int,input().split()) exec(int(*I())*"q,w=I();print(w+9*(q-1));") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var I : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom (name I)) (trailer (arguments ( ))))))))) )))) * (expr (atom "q,w=I();print(w+9*(q-1));"))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for e in range(t): n,d=list(map(int,input().split())) l=0 r=n a=[] eps=1e-6 while r-l>1 : m1=int(l+(r-l)/3-0.000000001) m2=int(l+(r-l)/3*2-0.000000001) if m1+d/(m1+1)>m2+d/(m2+1): l=l+(r-l)/3 elif m1+d/(m1+1)toInteger() ; for e : Integer.subrange(0, t-1) do ( var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : int := 0 ; var r : OclAny := n ; var a : Sequence := Sequence{} ; var eps : double := ("1e-6")->toReal() ; while r - l > 1 do ( var m1 : int := ("" + ((l + (r - l) / 3 - 0.000000001)))->toInteger() ; var m2 : int := ("" + ((l + (r - l) / 3 * 2 - 0.000000001)))->toInteger() ; if (m1 + d / (m1 + 1)->compareTo(m2 + d / (m2 + 1))) > 0 then ( l := l + (r - l) / 3 ) else (if (m1 + d / (m1 + 1)->compareTo(m2 + d / (m2 + 1))) < 0 then ( r := l + (r - l) / 3 * 2 ) else ( if (m1 + d / (m1 + 1)->compareTo(Set{n, d}->min())) <= 0 then ( a := 'YES' ; break ) else ( l := l + (r - l) / 3 ; r := l + (r - l) / 3 * 2 ) ) ) ) ; if l /= 0 then ( var q : int := ("" + ((l - 0.000000001)))->toInteger() + 1 ) else ( q := 0 ) ; if a = 'YES' or (q + d / (q + 1)->compareTo(Set{n, d}->min())) <= 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def divisibleBy3(number): sumOfDigit=0 for i in range(0,len(number),1): sumOfDigit+=ord(number[i])-ord('0') if(sumOfDigit % 3==0): return True return False def divisibleBy25(number): if(len(number)<2): return False length=len(number) lastTwo=((ord(number[length-2])-ord('0'))*10+(ord(number[length-1])-ord('0'))) if(lastTwo % 25==0): return True return False def divisibleBy75(number): if(divisibleBy3(number)and divisibleBy25(number)): return True return False if __name__=='__main__' : number="754586672150" divisible=divisibleBy75(number) if(divisible): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( number := "754586672150" ; var divisible : OclAny := divisibleBy75(number) ; if (divisible) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation divisibleBy3(number : OclAny) : OclAny pre: true post: true activity: var sumOfDigit : int := 0 ; for i : Integer.subrange(0, (number)->size()-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( sumOfDigit := sumOfDigit + (number[i+1])->char2byte() - ('0')->char2byte()) ; if (sumOfDigit mod 3 = 0) then ( return true ) else skip ; return false; operation divisibleBy25(number : OclAny) : OclAny pre: true post: true activity: if ((number)->size() < 2) then ( return false ) else skip ; var length : int := (number)->size() ; var lastTwo : double := (((number[length - 2+1])->char2byte() - ('0')->char2byte()) * 10 + ((number[length - 1+1])->char2byte() - ('0')->char2byte())) ; if (lastTwo mod 25 = 0) then ( return true ) else skip ; return false; operation divisibleBy75(number : OclAny) : OclAny pre: true post: true activity: if (divisibleBy3(number) & divisibleBy25(number)) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : num_str=input() if num_str=="0" : break ; sum=0 for num in list(num_str): sum+=int(num) print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var num_str : String := (OclFile["System.in"]).readLine() ; if num_str = "0" then ( break; ) else skip ; var sum : int := 0 ; for num : (num_str)->characters() do ( sum := sum + ("" + ((num)))->toInteger()) ; execute (sum)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calc_sum(num): total=0 while num>0 : q=num//10 r=num % 10 num=q total+=r return total while True : n=int(input()) if n==0 : break print(calc_sum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; execute (calc_sum(n))->display()); operation calc_sum(num : OclAny) : OclAny pre: true post: true activity: var total : int := 0 ; while num > 0 do ( var q : int := num div 10 ; var r : int := num mod 10 ; num := q ; total := total + r) ; return total; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x="" while x!="0" : x=input().rstrip() if x=="0" : break y=sum(list(map(int,list(x)))) print(y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := "" ; while x /= "0" do ( x := input().rstrip() ; if x = "0" then ( break ) else skip ; var y : OclAny := ((((x)->characters())->collect( _x | (OclType["int"])->apply(_x) )))->sum() ; execute (y)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from collections import defaultdict ANS=[] for i in range(int(input())): n,x=map(int,input().split()) a=list(map(int,input().split())) d=defaultdict(int) a.sort() for j in range(n): d[a[j]]+=1 ans=0 for j in range(n): if d[a[j]]==0 : continue if d[x*a[j]]>0 : d[x*a[j]]-=1 d[a[j]]-=1 else : d[a[j]]-=1 ans+=1 ANS.append(ans) print('\n'.join(map(str,ANS))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var ANS : Sequence := Sequence{} ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := defaultdict(OclType["int"]) ; a := a->sort() ; for j : Integer.subrange(0, n-1) do ( d[a[j+1]+1] := d[a[j+1]+1] + 1) ; var ans : int := 0 ; for j : Integer.subrange(0, n-1) do ( if d[a[j+1]+1] = 0 then ( continue ) else skip ; if d[x * a[j+1]+1] > 0 then ( d[x * a[j+1]+1] := d[x * a[j+1]+1] - 1 ; d[a[j+1]+1] := d[a[j+1]+1] - 1 ) else ( d[a[j+1]+1] := d[a[j+1]+1] - 1 ; ans := ans + 1 )) ; execute ((ans) : ANS)) ; execute (StringLib.sumStringsWithSeparator(((ANS)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,re from collections import Counter,deque from operator import itemgetter from itertools import accumulate,combinations sys.setrecursionlimit(10**6) while 1 : s=int(input()) if s==0 : break s=str(s) cnt=0 for i in s : cnt+=int(i) print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(6)) ; while 1 do ( var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if s = 0 then ( break ) else skip ; s := ("" + ((s))) ; var cnt : int := 0 ; for i : s do ( cnt := cnt + ("" + ((i)))->toInteger()) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : x=str(input()) if int(x)>0 : x_list=[int(x[i])for i in range(len(x))] print(sum(x_list)) else : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var x : String := ("" + (((OclFile["System.in"]).readLine()))) ; if ("" + ((x)))->toInteger() > 0 then ( var x_list : Sequence := Integer.subrange(0, (x)->size()-1)->select(i | true)->collect(i | (("" + ((x[i+1])))->toInteger())) ; execute ((x_list)->sum())->display() ) else ( break )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def Modulo(a,b): mod=0 for i in range(0,len(b)): mod=(mod*10+(int)(b[i]))% a return mod def LastDigit(a,b): len_a=len(a) len_b=len(b) if(len_a==1 and len_b==1 and b[0]=='0' and a[0]=='0'): return 1 if(len_b==1 and b[0]=='0'): return 1 if(len_a==1 and a[0]=='0'): return 0 if((Modulo(4,b)==0)): exp=4 else : exp=Modulo(4,b) res=math.pow((int)(a[len_a-1]),exp) return res % 10 a=['1','1','7'] b=['3'] print(LastDigit(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; a := Sequence{'1'}->union(Sequence{'1'}->union(Sequence{ '7' })) ; b := Sequence{ '3' } ; execute (LastDigit(a, b))->display(); operation Modulo(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var mod : int := 0 ; for i : Integer.subrange(0, (b)->size()-1) do ( mod := (mod * 10 + (OclType["int"])(b[i+1])) mod a) ; return mod; operation LastDigit(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var len_a : int := (a)->size() ; var len_b : int := (b)->size() ; if (len_a = 1 & len_b = 1 & b->first() = '0' & a->first() = '0') then ( return 1 ) else skip ; if (len_b = 1 & b->first() = '0') then ( return 1 ) else skip ; if (len_a = 1 & a->first() = '0') then ( return 0 ) else skip ; if ((Modulo(4, b) = 0)) then ( var exp : int := 4 ) else ( exp := Modulo(4, b) ) ; var res : double := ((OclType["int"])(a[len_a - 1+1]))->pow(exp) ; return res mod 10; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r=3 R=7 pi=3.14159 Volume=(float)(2*pi*pi*R*r*r); print("Volume: ",Volume); Surface=(float)(4*pi*pi*R*r); print("Surface: ",Surface); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : int := 3 ; var R : int := 7 ; var pi : double := 3.14159 ; var Volume : OclAny := (OclType["double"])(2 * pi * pi * R * r * r); ; execute ("Volume: ")->display(); ; var Surface : OclAny := (OclType["double"])(4 * pi * pi * R * r); ; execute ("Surface: ")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) segs=list(map(int,input().split())) segsum=segs[-1]-segs[0] segseparations=[] for i in range(len(segs)-1): segseparations.append(segs[i+1]-segs[i]) segseparations=sorted(segseparations,reverse=True) for i in range(k-1): segsum-=segseparations[0] segseparations.pop(0) print(segsum+k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var segs : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var segsum : double := segs->last() - segs->first() ; var segseparations : Sequence := Sequence{} ; for i : Integer.subrange(0, (segs)->size() - 1-1) do ( execute ((segs[i + 1+1] - segs[i+1]) : segseparations)) ; segseparations := segseparations->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; for i : Integer.subrange(0, k - 1-1) do ( segsum := segsum - segseparations->first() ; segseparations := segseparations->excludingAt(0+1)) ; execute (segsum + k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) p,q,r=map(int,input().split()) print(b+(p*b-(b-a)*q)/(q+r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : OclAny := null; var q : OclAny := null; var r : OclAny := null; Sequence{p,q,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (b + (p * b - (b - a) * q) / (q + r))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def num(): return int(input()) def nums(): return list(map(int,input().split())) A,B=nums() P,Q,R=nums() first_distance=P*B pre_runned=(B-A)*Q time=B+(first_distance-pre_runned)/(R+Q) print(time) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := nums() ; var P : OclAny := null; var Q : OclAny := null; var R : OclAny := null; Sequence{P,Q,R} := nums() ; var first_distance : double := P * B ; var pre_runned : double := (B - A) * Q ; var time : OclAny := B + (first_distance - pre_runned) / (R + Q) ; execute (time)->display(); operation num() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation nums() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) def MI(): return map(int,sys.stdin.readline().split()) def main(): a,b=MI() p,q,r=MI() print((p*b+a*q+r*b)/(q+r)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; skip ; skip ; main(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation main() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := MI() ; var p : OclAny := null; var q : OclAny := null; var r : OclAny := null; Sequence{p,q,r} := MI() ; execute ((p * b + a * q + r * b) / (q + r))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) p,q,r=map(int,input().split()) e=p*b s=(b-a)*q print(b+(e-s)/(q+r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : OclAny := null; var q : OclAny := null; var r : OclAny := null; Sequence{p,q,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var e : double := p * b ; var s : double := (b - a) * q ; execute (b + (e - s) / (q + r))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=[int(_)for _ in input().split()] p,q,r=[int(_)for _ in input().split()] print(b+(b*p-(b-a)*q)/(q+r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var p : OclAny := null; var q : OclAny := null; var r : OclAny := null; Sequence{p,q,r} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; execute (b + (b * p - (b - a) * q) / (q + r))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=input().split() if(n==1): print(a[0]) exit() a_num=list(map(int,a[: : 2])) a_op=a[1 : : 2] cumsum=a_num[: :] cumsum_op=[0]*n cumsum_op[0]=a_num[0] minus_ind=[] for i in range(1,n): cumsum[i]+=cumsum[i-1] if(a_op[i-1]=='+'): cumsum_op[i]=cumsum_op[i-1]+a_num[i] else : cumsum_op[i]=cumsum_op[i-1]-a_num[i] minus_ind.append(i) ans=cumsum_op[-1] if(len(minus_ind)<2): print(ans) exit() for l,r in zip(minus_ind[:-1],minus_ind[1 :]): tmp=cumsum_op[l-1]-(cumsum[r-1]-cumsum[l-1])+(cumsum[-1]-cumsum[r-1]) ans=max(ans,tmp) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := input().split() ; if (n = 1) then ( execute (a->first())->display() ; exit() ) else skip ; var a_num : Sequence := ((a(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->collect( _x | (OclType["int"])->apply(_x) )) ; var a_op : OclAny := a(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ; var cumsum : OclAny := a_num(subscript : (sliceop :)) ; var cumsum_op : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; cumsum_op->first() := a_num->first() ; var minus_ind : Sequence := Sequence{} ; for i : Integer.subrange(1, n-1) do ( cumsum[i+1] := cumsum[i+1] + cumsum[i - 1+1] ; if (a_op[i - 1+1] = '+') then ( cumsum_op[i+1] := cumsum_op[i - 1+1] + a_num[i+1] ) else ( cumsum_op[i+1] := cumsum_op[i - 1+1] - a_num[i+1] ; execute ((i) : minus_ind) )) ; var ans : OclAny := cumsum_op->last() ; if ((minus_ind)->size() < 2) then ( execute (ans)->display() ; exit() ) else skip ; for _tuple : Integer.subrange(1, minus_ind->front()->size())->collect( _indx | Sequence{minus_ind->front()->at(_indx), minus_ind->tail()->at(_indx)} ) do (var _indx : int := 1; var l : OclAny := _tuple->at(_indx); _indx := _indx + 1; var r : OclAny := _tuple->at(_indx); var tmp : double := cumsum_op[l - 1+1] - (cumsum[r - 1+1] - cumsum[l - 1+1]) + (cumsum->last() - cumsum[r - 1+1]) ; ans := Set{ans, tmp}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from collections import Counter for _ in range(int(input())): n,k=map(int,input().split()) a=list(map(int,input().split())) a.sort(reverse=True) c=Counter() for x in a : if c[x*k]: c[x*k]-=1 else : c[x]+=1 print(sum(c.values())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var c : OclAny := Counter() ; for x : a do ( if c[x * k+1] then ( c[x * k+1] := c[x * k+1] - 1 ) else ( c[x+1] := c[x+1] + 1 )) ; execute ((c.values())->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n): s=input() sum_a=0 sum_n=0 sum_np=0 min_sum_np=10**15 j=s.find('-') if j<0 : return sum(list(map(int,s.split('+')))) sum_a=sum(list(map(int,s[: j-1].split('+')))) j+=2 s+='' len_s=len(s) sign=-1 w='' while jpow(15) ; var j : int := s->indexOf('-') - 1 ; if j < 0 then ( return (((s.split('+'))->collect( _x | (OclType["int"])->apply(_x) )))->sum() ) else skip ; sum_a := (((s.subrange(1,j - 1).split('+'))->collect( _x | (OclType["int"])->apply(_x) )))->sum() ; j := j + 2 ; s := s + '' ; var len_s : int := (s)->size() ; var sign : int := -1 ; var w : String := '' ; while (j->compareTo(len_s)) < 0 do ( var ch : OclAny := s[j+1] ; j := j + 1 ; if ch = '' then ( if (w)->size() then ( var a : int := ("" + ((w)))->toInteger() ; sum_a := sum_a + a ; w := '' ; if sign < 0 then ( sum_n := sum_n + a ; sum_np := 0 ) else ( sum_np := sum_np + a ) ) else skip ) else (if ch = '+' then ( sign := 1 ) else (if ch = '-' then ( min_sum_np := Set{min_sum_np, sum_n + sum_np}->min() ; sign := -1 ) else ( w := w + ch ) ) ) ) ; min_sum_np := Set{min_sum_np, sum_n + sum_np}->min() ; return sum_a - 2 * min_sum_np; operation main() pre: true post: true activity: n := (OclFile["System.in"]).readLine() ; n := ("" + ((n)))->toInteger() ; execute (solve(n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline N=int(input()) terms=[[]] op='+' for x in input().rstrip().split(): if x in '+-' : op=x continue x=int(x) if op=='+' : terms[-1].append(x) else : terms.append([x]) min_minus=10**18 first_sum=0 for t in terms[1 :]: x=first_sum+sum(t) if x1 : answer-=2*min_minus print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var terms : Sequence := Sequence{ Sequence{} } ; var op : String := '+' ; for x : input().rstrip().split() do ( if ('+-')->characters()->includes(x) then ( op := x ; continue ) else skip ; var x : int := ("" + ((x)))->toInteger() ; if op = '+' then ( (expr (atom (name terms)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) ) else ( execute ((Sequence{ x }) : terms) )) ; var min_minus : double := (10)->pow(18) ; var first_sum : int := 0 ; for t : terms->tail() do ( x := first_sum + (t)->sum() ; if (x->compareTo(min_minus)) < 0 then ( min_minus := x ) else skip ; first_sum := first_sum + t->first()) ; var answer : OclAny := ((argument (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) ))))))) (comp_for for (exprlist (expr (atom (name t)))) in (logical_test (comparison (expr (atom (name terms))))))))->sum() ; if (terms)->size() > 1 then ( answer := answer - 2 * min_minus ) else skip ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() sm=de=0 ans=10**15 for s in(input()+"-0").split('-'): a=list(map(int,s.split('+'))) if sm : ans=min(ans,sum(a)+de) de+=a[0] sm+=sum(a) print(sm-2*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var sm : OclAny := 0; var de : int := 0 ; var ans : double := (10)->pow(15) ; for s : ((OclFile["System.in"]).readLine() + "-0").split('-') do ( var a : Sequence := ((s.split('+'))->collect( _x | (OclType["int"])->apply(_x) )) ; if sm then ( ans := Set{ans, (a)->sum() + de}->min() ; de := de + a->first() ) else skip ; sm := sm + (a)->sum()) ; execute (sm - 2 * ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,l,k=map(int,input().split()) v=[int(x)for x in input().split()] a=[] for i in range(len(v)-1): a.append(v[i+1]-v[i]+1) d=n-k a.sort() val=n for i in range(d): val+=a[i]-2 print(val) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; var k : OclAny := null; Sequence{n,l,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var v : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, (v)->size() - 1-1) do ( execute ((v[i + 1+1] - v[i+1] + 1) : a)) ; var d : double := n - k ; a := a->sort() ; var val : OclAny := n ; for i : Integer.subrange(0, d-1) do ( val := val + a[i+1] - 2) ; execute (val)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(str,input().split())) dp=[[-float("inf")]*4 for i in range(n+1)] dp[0][0]=0 for i in range(len(a)): b=i//2+1 if a[i]=="-" : tmp=[-float("inf"),0,0,0] for j in range(3): tmp[j+1]=dp[b][j] dp[b]=tmp continue elif a[i]=="+" : continue for j in range(4): for k in range(3): if j>=k : dp[b][k]=max(dp[b][k],dp[b-1][j]+((-1)**j)*int(a[i])) print(dp[n][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["String"])->apply(_x) )) ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ -("" + (("inf")))->toReal() }, 4))) ; dp->first()->first() := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( var b : int := i div 2 + 1 ; if a[i+1] = "-" then ( var tmp : Sequence := Sequence{-("" + (("inf")))->toReal()}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))) ; for j : Integer.subrange(0, 3-1) do ( tmp[j + 1+1] := dp[b+1][j+1]) ; dp[b+1] := tmp ; continue ) else (if a[i+1] = "+" then ( continue ) else skip) ; for j : Integer.subrange(0, 4-1) do ( for k : Integer.subrange(0, 3-1) do ( if (j->compareTo(k)) >= 0 then ( dp[b+1][k+1] := Set{dp[b+1][k+1], dp[b - 1+1][j+1] + (((-1))->pow(j)) * ("" + ((a[i+1])))->toInteger()}->max() ) else skip))) ; execute (dp[n+1]->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=list(map(int,input().split())) print(max(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((s)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- number=int(input()) arr=list(map(int,input().split())) money=0 energy=0 now=0 for i in range(0,len(arr)): if arr[i]>now : if energy>=(arr[i]-now): energy-=(arr[i]-now) now=arr[i] else : x=arr[i] x-=energy energy=0 money+=(x-now) now=arr[i] elif arr[i]toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var money : int := 0 ; var energy : int := 0 ; var now : int := 0 ; for i : Integer.subrange(0, (arr)->size()-1) do ( if (arr[i+1]->compareTo(now)) > 0 then ( if (energy->compareTo((arr[i+1] - now))) >= 0 then ( energy := energy - (arr[i+1] - now) ; now := arr[i+1] ) else ( var x : OclAny := arr[i+1] ; x := x - energy ; energy := 0 ; money := money + (x - now) ; now := arr[i+1] ) ) else (if (arr[i+1]->compareTo(now)) < 0 then ( energy := energy + now - arr[i+1] ; now := arr[i+1] ) else ( continue ) ) ) ; execute (money)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) heights=list(map(int,input().split())) heights.sort() print(heights[n-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var heights : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; heights := heights->sort() ; execute (heights[n - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) print(max(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((l)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) h=[int(x)for x in input().split()] maxVal=0 for i in range(n): maxVal=max(maxVal,h[i]) print(maxVal) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var h : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var maxVal : int := 0 ; for i : Integer.subrange(0, n-1) do ( maxVal := Set{maxVal, h[i+1]}->max()) ; execute (maxVal)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=1 y=1 z=n-2 if z % 3==0 : z-=1 y+=1 print(x,y,z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := 1 ; var y : int := 1 ; var z : double := n - 2 ; if z mod 3 = 0 then ( z := z - 1 ; y := y + 1 ) else skip ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) ans=[] for i in range(t): a=0 n,x=map(int,input().split()) m=list(map(int,input().split())) m.sort() s={} for i in range(n): if m[i]not in s : s[m[i]]=1 else : s[m[i]]+=1 for i in range(n): if m[i]*x in s and s[m[i]]>0 and s[m[i]*x]>0 : s[m[i]]-=1 s[m[i]*x]-=1 for i in s.keys(): a+=s[i] ans.append(a) for i in range(len(ans)): print(ans[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( var a : int := 0 ; var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; m := m->sort() ; var s : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( if (s)->excludes(m[i+1]) then ( s[m[i+1]+1] := 1 ) else ( s[m[i+1]+1] := s[m[i+1]+1] + 1 )) ; for i : Integer.subrange(0, n-1) do ( if (s)->includes(m[i+1] * x) & s[m[i+1]+1] > 0 & s[m[i+1] * x+1] > 0 then ( s[m[i+1]+1] := s[m[i+1]+1] - 1 ; s[m[i+1] * x+1] := s[m[i+1] * x+1] - 1 ) else skip) ; for i : s.keys() do ( a := a + s[i+1]) ; execute ((a) : ans)) ; for i : Integer.subrange(0, (ans)->size()-1) do ( execute (ans[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ok=0 if(n-2)% 3!=0 : print(1,1,(n-2)) elif(n-3)% 3!=0 : print(1,2,(n-3)) else : for a in range(1,n+1): if a % 3==0 : pass elif ok==1 : break else : for b in range(1,n+1): if b % 3==0 : pass elif ok==1 : break else : for c in range(1,n+1): if c % 3==0 : pass elif a+b+c==n : print(a,b,c) ok=1 break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ok : int := 0 ; if (n - 2) mod 3 /= 0 then ( execute (1)->display() ) else (if (n - 3) mod 3 /= 0 then ( execute (1)->display() ) else ( for a : Integer.subrange(1, n + 1-1) do ( if a mod 3 = 0 then ( skip ) else (if ok = 1 then ( break ) else ( for b : Integer.subrange(1, n + 1-1) do ( if b mod 3 = 0 then ( skip ) else (if ok = 1 then ( break ) else ( for c : Integer.subrange(1, n + 1-1) do ( if c mod 3 = 0 then ( skip ) else (if a + b + c = n then ( execute (a)->display() ; ok := 1 ; break ) else skip)) ) ) ) ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ok=0 if(n-2)% 3!=0 : print(1,1,(n-2)) else : print(1,2,(n-3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ok : int := 0 ; if (n - 2) mod 3 /= 0 then ( execute (1)->display() ) else ( execute (1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,l,k=map(int,input().split()) nums=[int(x)for x in input().split()] First_Hide=nums[-1]-nums[0]+1 if n<=1 : print(n) else : instance=[] for i in range(n-1): instance.append(nums[i+1]-nums[i]-1) instance.sort(reverse=True) delete_hide=k-1 print(First_Hide-sum(instance[: delete_hide])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; var k : OclAny := null; Sequence{n,l,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var nums : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var First_Hide : double := nums->last() - nums->first() + 1 ; if n <= 1 then ( execute (n)->display() ) else ( var instance : Sequence := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( execute ((nums[i + 1+1] - nums[i+1] - 1) : instance)) ; instance := instance->sort() ; var delete_hide : double := k - 1 ; execute (First_Hide - (instance.subrange(1,delete_hide))->sum())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) a=1 b,c=1,n-2 while not b % 3 or not c % 3 : b+=1 c-=1 print(a,b,c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := 1 ; var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := Sequence{1,n - 2} ; while not(b mod 3) or not(c mod 3) do ( b := b + 1 ; c := c - 1) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=n-2 if m % 3==0 : print(m-1,2,1) else : print(n-2,1,1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : double := n - 2 ; if m mod 3 = 0 then ( execute (m - 1)->display() ) else ( execute (n - 2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=list(map(int,input().split())) s=0 z=n-k+1 for i in range(n): s+=a[i]*min(z,k,i+1,n-i) print(s/(z)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : int := 0 ; var z : double := n - k + 1 ; for i : Integer.subrange(0, n-1) do ( s := s + a[i+1] * Set{z, k, i + 1, n - i}->min()) ; execute (s / (z))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=list(map(int,input().split())) arr=list(map(int,input().split())) count=n-k+1 prefixAr=[0] cumSum=0 for x in arr : cumSum+=x prefixAr.append(cumSum) newCumSum=0 for i in range(1,count+1): newCumSum+=(prefixAr[i+k-1]-prefixAr[i-1]) print(newCumSum/count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : double := n - k + 1 ; var prefixAr : Sequence := Sequence{ 0 } ; var cumSum : int := 0 ; for x : arr do ( cumSum := cumSum + x ; execute ((cumSum) : prefixAr)) ; var newCumSum : int := 0 ; for i : Integer.subrange(1, count + 1-1) do ( newCumSum := newCumSum + (prefixAr[i + k - 1+1] - prefixAr[i - 1+1])) ; execute (newCumSum / count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=[int(x)for x in input().split()] l=[int(y)for y in input().split()] s=0 imax=0 if n-k+1select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var l : Sequence := input().split()->select(y | true)->collect(y | (("" + ((y)))->toInteger())) ; var s : int := 0 ; var imax : int := 0 ; if (n - k + 1->compareTo(k)) < 0 then ( imax := n - k + 1 ) else ( imax := k ) ; for i : Integer.subrange(0, n-1) do ( if ((i + 1->compareTo(imax)) < 0) then ( s := s + l[i+1] * (i + 1) ) else (if ((imax->compareTo(i + 1)) <= 0 & ((i + 1)->compareTo((n - imax + 1))) <= 0) then ( s := s + l[i+1] * imax ) else ( s := s + l[i+1] * (n - (i)) ) ) ; var av : double := ("" + ((s / (n - k + 1))))->toReal()) ; execute (av)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=input().split() work=list(map(int,input().split())) l=[0]+work summ=0 big=0 x=1 y=0 while ycollect( _x | (OclType["int"])->apply(_x) )) ; var l : Sequence := Sequence{ 0 }->union(work) ; var summ : int := 0 ; var big : int := 0 ; var x : int := 1 ; var y : int := 0 ; while (y->compareTo(("" + ((n)))->toInteger() + 1)) < 0 do ( if y = ("" + ((k)))->toInteger() then ( summ := summ + l[y+1] ; big := big + summ ; y := y + 1 ) else (if (y->compareTo(("" + ((k)))->toInteger())) < 0 then ( summ := summ + l[y+1] ; y := y + 1 ) else ( summ := summ - l[x+1] ; x := x + 1 ; summ := summ + l[y+1] ; y := y + 1 ; big := big + summ ) ) ) ; execute (big / (("" + ((n)))->toInteger() - ("" + ((k)))->toInteger() + 1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def oppositeSigns(x,y): return((x ^ y)<0) def partitionNegPos(arr,n): a=[] b=[] a=a+[arr[0]] for i in range(1,n): if(oppositeSigns(a[0],arr[i])): b=b+[arr[i]] else : a=a+[arr[i]] for i in range(0,len(a)): print(a[i],end=' ') print("") for i in range(0,len(b)): print(b[i],end=' ') arr=[1,-2,6,-7,8] n=len(arr) partitionNegPos(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{1}->union(Sequence{-2}->union(Sequence{6}->union(Sequence{-7}->union(Sequence{ 8 })))) ; n := (arr)->size() ; partitionNegPos(arr, n); operation oppositeSigns(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return ((MathLib.bitwiseXor(x, y)) < 0); operation partitionNegPos(arr : OclAny, n : OclAny) pre: true post: true activity: var a : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; a := a->union(Sequence{ arr->first() }) ; for i : Integer.subrange(1, n-1) do ( if (oppositeSigns(a->first(), arr[i+1])) then ( b := b->union(Sequence{ arr[i+1] }) ) else ( a := a->union(Sequence{ arr[i+1] }) )) ; for i : Integer.subrange(0, (a)->size()-1) do ( execute (a[i+1])->display()) ; execute ("")->display() ; for i : Integer.subrange(0, (b)->size()-1) do ( execute (b[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[0]*32 a[1],a[2]=1,2 for i in range(3,31): a[i]=3*a[i-2]+2 while True : try : i=int(input()) except : break print(a[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 32) ; var a[1+1] : OclAny := null; var a[2+1] : OclAny := null; Sequence{a[1+1],a[2+1]} := Sequence{1,2} ; for i : Integer.subrange(3, 31-1) do ( a[i+1] := 3 * a[i - 2+1] + 2) ; while true do ( try ( var i : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) catch (_e : OclException) do ( break) ; execute (a[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def possible(n): if(n>3): sum=(n*(n+1))//2 ; if(sum % 3==0): return True ; return False ; if __name__=="__main__" : n=5 ; if(possible(n)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 5; ; if (possible(n)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ) else skip; operation possible(n : OclAny) pre: true post: true activity: if (n > 3) then ( var sum : int := (n * (n + 1)) div 2; ; if (sum mod 3 = 0) then ( return true; ) else skip ) else skip ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def isPrime(n): if(n==0 or n==1): return False ; for i in range(2,int(sqrt(n))+1): if(n % i==0): return False ; return True ; def sumAscii(string,n): sum=0 ; for i in range(n): if(isPrime(i+1)): sum+=ord(string[i]); return sum ; if __name__=="__main__" : string="geeksforgeeks" ; n=len(string); print(sumAscii(string,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( string := "geeksforgeeks"; ; n := (string)->size(); ; execute (sumAscii(string, n))->display(); ) else skip; operation isPrime(n : OclAny) pre: true post: true activity: if (n = 0 or n = 1) then ( return false; ) else skip ; for i : Integer.subrange(2, ("" + ((sqrt(n))))->toInteger() + 1-1) do ( if (n mod i = 0) then ( return false; ) else skip) ; return true;; operation sumAscii(string : OclAny, n : OclAny) pre: true post: true activity: var sum : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (isPrime(i + 1)) then ( sum := sum + (string[i+1])->char2byte(); ) else skip) ; return sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def onesComplement(n): number_of_bits=(int)(math.floor(math.log(n)/math.log(2)))+1 ; return((1<display(); operation onesComplement(n : OclAny) pre: true post: true activity: var number_of_bits : OclAny := (OclType["int"])(((n)->log() / (2)->log())->floor()) + 1; ; return MathLib.bitwiseXor(((1 * (2->pow(number_of_bits))) - 1), n);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) total_l=0 total_r=0 for i in range(N): l,r=list(map(int,input().split())) total_r+=r total_l+=l print(min(N-total_r,total_r)+min(N-total_l,total_l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var total_l : int := 0 ; var total_r : int := 0 ; for i : Integer.subrange(0, N-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; total_r := total_r + r ; total_l := total_l + l) ; execute (Set{N - total_r, total_r}->min() + Set{N - total_l, total_l}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lc=lo=rc=ro=0 for i in range(n): l,r=map(int,input().split()) if l==0 : lc+=1 elif l==1 : lo+=1 if r==0 : rc+=1 elif r==1 : ro+=1 l=min(lc,lo) r=min(ro,rc) print(l+r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; lc := lc(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name lo)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name rc)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ro)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for i : Integer.subrange(0, n-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if l = 0 then ( lc := lc + 1 ) else (if l = 1 then ( lo := lo + 1 ) else skip) ; if r = 0 then ( rc := rc + 1 ) else (if r = 1 then ( ro := ro + 1 ) else skip)) ; var l : OclAny := Set{lc, lo}->min() ; var r : OclAny := Set{ro, rc}->min() ; execute (l + r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x,y=0,0 for i in range(n): a=input() if int(a[0])==0 : x+=1 if int(a[2])==0 : y+=1 t=(min(x,n-x)+min(y,n-y)) print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{0,0} ; for i : Integer.subrange(0, n-1) do ( var a : String := (OclFile["System.in"]).readLine() ; if ("" + ((a->first())))->toInteger() = 0 then ( x := x + 1 ) else skip ; if ("" + ((a[2+1])))->toInteger() = 0 then ( y := y + 1 ) else skip) ; var t : OclAny := (Set{x, n - x}->min() + Set{y, n - y}->min()) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lc=rc=0 for i in range(n): t=input().split() t=[int(x)for x in t] if t[0]==1 : lc+=1 if t[1]==1 : rc+=1 print(min(n-lc,lc)+min(n-rc,rc)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lc : OclAny := 0; var rc : int := 0 ; for i : Integer.subrange(0, n-1) do ( var t : OclAny := input().split() ; t := t->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if t->first() = 1 then ( lc := lc + 1 ) else skip ; if t[1+1] = 1 then ( rc := rc + 1 ) else skip) ; execute (Set{n - lc, lc}->min() + Set{n - rc, rc}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) leftOne=0 rightOne=0 for _ in range(n): x,y=map(int,input().split()) if x==1 : leftOne+=1 if y==1 : rightOne+=1 ans=0 if leftOnetoInteger() ; var leftOne : int := 0 ; var rightOne : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x = 1 then ( leftOne := leftOne + 1 ) else skip ; if y = 1 then ( rightOne := rightOne + 1 ) else skip) ; var ans : int := 0 ; if (leftOne->compareTo(n - leftOne)) < 0 then ( ans := ans + leftOne ) else ( ans := ans + n - leftOne ) ; if (rightOne->compareTo(n - rightOne)) < 0 then ( ans := ans + rightOne ) else ( ans := ans + n - rightOne ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys ; def strBitwiseAND(arr,n): res="" smallest_size=sys.maxsize ; largest_size=-(sys.maxsize-1); for i in range(n): arr[i]=arr[i][: :-1]; smallest_size=min(smallest_size,len(arr[i])); largest_size=max(largest_size,len(arr[i])); for i in range(smallest_size): all_ones=True ; for j in range(n): if(arr[j][i]=='0'): all_ones=False ; break ; if all_ones : res+='1' ; else : res+='0' ; for i in range(largest_size-smallest_size): res+='0' ; res=res[: :-1]; return res ; if __name__=="__main__" : arr=["101","110110","111"]; n=len(arr); print(strBitwiseAND(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; ; skip ; if __name__ = "__main__" then ( arr := Sequence{"101"}->union(Sequence{"110110"}->union(Sequence{ "111" })); ; n := (arr)->size(); ; execute (strBitwiseAND(arr, n))->display(); ) else skip; operation strBitwiseAND(arr : OclAny, n : OclAny) pre: true post: true activity: var res : String := "" ; var smallest_size : (trailer . (name maxsize)) := (trailer . (name maxsize)); ; var largest_size : double := -((trailer . (name maxsize)) - 1); ; for i : Integer.subrange(0, n-1) do ( arr[i+1] := arr[i+1](subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); ; smallest_size := Set{smallest_size, (arr[i+1])->size()}->min(); ; largest_size := Set{largest_size, (arr[i+1])->size()}->max();) ; for i : Integer.subrange(0, smallest_size-1) do ( var all_ones : boolean := true; ; for j : Integer.subrange(0, n-1) do ( if (arr[j+1][i+1] = '0') then ( all_ones := false; ; break; ) else skip) ; if all_ones then ( res := res + '1'; ) else ( res := res + '0'; )) ; for i : Integer.subrange(0, largest_size - smallest_size-1) do ( res := res + '0';) ; res := res(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- test_case=int(input()) for _ in range(test_case): n,y,x=map(int,input().split()) obstacles=list(map(int,input().split())) diagonal_vertical=False vertical=False go_ahead=True for i in range(1,n): if abs(obstacles[i]-obstacles[i-1])>1 : print(0) go_ahead=False break elif diagonal_vertical==False : if abs(obstacles[i]-obstacles[i-1])==1 : diagonal_vertical=True elif vertical==False : if abs(obstacles[i]-obstacles[i-1])==0 : vertical=True if go_ahead : if diagonal_vertical : print(min(x,y)) else : print(x+min(x,y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var test_case : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, test_case-1) do ( var n : OclAny := null; var y : OclAny := null; var x : OclAny := null; Sequence{n,y,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var obstacles : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var diagonal_vertical : boolean := false ; var vertical : boolean := false ; var go_ahead : boolean := true ; for i : Integer.subrange(1, n-1) do ( if (obstacles[i+1] - obstacles[i - 1+1])->abs() > 1 then ( execute (0)->display() ; go_ahead := false ; break ) else (if diagonal_vertical = false then ( if (obstacles[i+1] - obstacles[i - 1+1])->abs() = 1 then ( diagonal_vertical := true ) else skip ) else (if vertical = false then ( if (obstacles[i+1] - obstacles[i - 1+1])->abs() = 0 then ( vertical := true ) else skip ) else skip ) ) ) ; if go_ahead then ( if diagonal_vertical then ( execute (Set{x, y}->min())->display() ) else ( execute (x + Set{x, y}->min())->display() ) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=lambda : map(int,input().split()) for _ in[0]*int(input()): n,u,v=I() bb=list(I()) co=min(u,v) for i in range(1,n): if abs(bb[i]-bb[i-1])>1 : co=0 break if co!=0 and len(set(bb))==1 : co=min(u+v,2*v) print(co) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var n : OclAny := null; var u : OclAny := null; var v : OclAny := null; Sequence{n,u,v} := I->apply() ; var bb : Sequence := (I->apply()) ; var co : OclAny := Set{u, v}->min() ; for i : Integer.subrange(1, n-1) do ( if (bb[i+1] - bb[i - 1+1])->abs() > 1 then ( co := 0 ; break ) else skip) ; if co /= 0 & (Set{}->union((bb)))->size() = 1 then ( co := Set{u + v, 2 * v}->min() ) else skip ; execute (co)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n,u,v=map(int,input().split()) w=list(map(int,input().split())) s=list(set(w)) if len(s)==1 : print(min(v+u,2*v)) else : for i in range(n-1): if abs(w[i+1]-w[i])>1 : print(0) break else : print(min(u,v)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var u : OclAny := null; var v : OclAny := null; Sequence{n,u,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Sequence := (Set{}->union((w))) ; if (s)->size() = 1 then ( execute (Set{v + u, 2 * v}->min())->display() ) else ( (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))) - (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))) ))))) > (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u))))))) , (argument (test (logical_test (comparison (expr (atom (name v)))))))) ))))))))) ))))))))))))))) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def profitLoss(N,M): if(N==M): print("No Profit nor Loss") else : result=0.0 result=float(abs(N-M))/M if(N-M<0): print("Loss=-",'{0:.6}'.format(result*100),"%") else : print("Profit=",'{0:.6}'.format(result*100),"%") if __name__=='__main__' : N=8 M=9 profitLoss(N,M) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( N := 8 ; M := 9 ; profitLoss(N, M) ) else skip; operation profitLoss(N : OclAny, M : OclAny) pre: true post: true activity: if (N = M) then ( execute ("No Profit nor Loss")->display() ) else ( var result : double := 0.0 ; result := ("" + (((N - M)->abs())))->toReal() / M ; if (N - M < 0) then ( execute ("Loss=-")->display() ) else ( execute ("Profit=")->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for test in range(t): w,h,n=map(int,input().split()) w_first=w h_first=h if n==1 : print('YES') elif w % 2==1 and h % 2==1 : print('NO') else : if w % 2==0 and h % 2==1 : count=0 while w % 2==0 : w/=2 count+=1 if w==1 : num=w_first else : num=2**count elif h % 2==0 and w % 2==1 : count=0 while h % 2==0 : h/=2 count+=1 if h==1 : num=h_first else : num=2**count elif h % 2==0 and w % 2==0 : num=0 count=0 while w % 2==0 : w/=2 count+=1 if w==1 : num1=w_first else : num1=2**count count=0 while h % 2==0 : h/=2 count+=1 if h==1 : num2=h_first else : num2=2**count num=num1*num2 if num>=n : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for test : Integer.subrange(0, t-1) do ( var w : OclAny := null; var h : OclAny := null; var n : OclAny := null; Sequence{w,h,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w_first : OclAny := w ; var h_first : OclAny := h ; if n = 1 then ( execute ('YES')->display() ) else (if w mod 2 = 1 & h mod 2 = 1 then ( execute ('NO')->display() ) else ( if w mod 2 = 0 & h mod 2 = 1 then ( var count : int := 0 ; while w mod 2 = 0 do ( w := w / 2 ; count := count + 1) ; if w = 1 then ( var num : OclAny := w_first ) else ( num := (2)->pow(count) ) ) else (if h mod 2 = 0 & w mod 2 = 1 then ( count := 0 ; while h mod 2 = 0 do ( h := h / 2 ; count := count + 1) ; if h = 1 then ( num := h_first ) else ( num := (2)->pow(count) ) ) else (if h mod 2 = 0 & w mod 2 = 0 then ( num := 0 ; count := 0 ; while w mod 2 = 0 do ( w := w / 2 ; count := count + 1) ; if w = 1 then ( var num1 : OclAny := w_first ) else ( num1 := (2)->pow(count) ) ; count := 0 ; while h mod 2 = 0 do ( h := h / 2 ; count := count + 1) ; if h = 1 then ( var num2 : OclAny := h_first ) else ( num2 := (2)->pow(count) ) ; num := num1 * num2 ) else skip ) ) ; if (num->compareTo(n)) >= 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for j in range(t): n,u,v=map(int,input().split()) a=list(map(int,input().split())) ans=10**18 for k in range(n-1): if abs(a[k+1]-a[k])>1 : ans=0 elif abs(a[k+1]-a[k])==0 : ans=min(ans,v+min(u,v)) else : ans=min(ans,min(u,v)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, t-1) do ( var n : OclAny := null; var u : OclAny := null; var v : OclAny := null; Sequence{n,u,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : double := (10)->pow(18) ; for k : Integer.subrange(0, n - 1-1) do ( if (a[k + 1+1] - a[k+1])->abs() > 1 then ( ans := 0 ) else (if (a[k + 1+1] - a[k+1])->abs() = 0 then ( ans := Set{ans, v + Set{u, v}->min()}->min() ) else ( ans := Set{ans, Set{u, v}->min()}->min() ) ) ) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getPeriod(n): rem=1 for i in range(1,n+2): rem=(10*rem)% n d=rem count=0 rem=(10*rem)% n count+=1 while rem!=d : rem=(10*rem)% n count+=1 return count if __name__=="__main__" : print(getPeriod(3)) print(getPeriod(7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (getPeriod(3))->display() ; execute (getPeriod(7))->display() ) else skip; operation getPeriod(n : OclAny) : OclAny pre: true post: true activity: var rem : int := 1 ; for i : Integer.subrange(1, n + 2-1) do ( rem := (10 * rem) mod n) ; var d : int := rem ; var count : int := 0 ; rem := (10 * rem) mod n ; count := count + 1 ; while rem /= d do ( rem := (10 * rem) mod n ; count := count + 1) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countDivisors(n): x,ans=0,1 while(n % 2==0): x+=1 n=n/2 ans=ans*(x+1) for i in range(3,int(n**1/2)+1,2): x=0 while(n % i==0): x+=1 n=n/i ans=ans*(x+1) if(n>2): ans=ans*2 return ans def getTotalCount(n,k): k_count=countDivisors(k) count=0 for i in range(1,n): if(k_count==countDivisors(i)): count+=1 if(kdisplay() ) else skip; operation countDivisors(n : OclAny) : OclAny pre: true post: true activity: var x : OclAny := null; var ans : OclAny := null; Sequence{x,ans} := Sequence{0,1} ; while (n mod 2 = 0) do ( x := x + 1 ; n := n / 2) ; var ans : double := ans * (x + 1) ; for i : Integer.subrange(3, ("" + (((n)->pow(1) / 2)))->toInteger() + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( var x : int := 0 ; while (n mod i = 0) do ( x := x + 1 ; n := n / i) ; ans := ans * (x + 1)) ; if (n > 2) then ( ans := ans * 2 ) else skip ; return ans; operation getTotalCount(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var k_count : OclAny := countDivisors(k) ; var count : int := 0 ; for i : Integer.subrange(1, n-1) do ( if (k_count = countDivisors(i)) then ( count := count + 1 ) else skip) ; if ((k->compareTo(n)) < 0) then ( count := count - 1 ) else skip ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxDiff(arr,n): result=0 arr.sort() for i in range(n-1): if(abs(arr[i])!=abs(arr[i+1])): result+=abs(arr[i]) else : pass if(arr[n-2]!=arr[n-1]): result+=abs(arr[n-1]) return result if __name__=="__main__" : arr=[4,2,-3,3,-2,-2,8] n=len(arr) print("Maximum Difference=",maxDiff(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{4}->union(Sequence{2}->union(Sequence{-3}->union(Sequence{3}->union(Sequence{-2}->union(Sequence{-2}->union(Sequence{ 8 })))))) ; n := (arr)->size() ; execute ("Maximum Difference=")->display() ) else skip; operation maxDiff(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; arr := arr->sort() ; for i : Integer.subrange(0, n - 1-1) do ( if ((arr[i+1])->abs() /= (arr[i + 1+1])->abs()) then ( result := result + (arr[i+1])->abs() ) else ( skip )) ; if (arr[n - 2+1] /= arr[n - 1+1]) then ( result := result + (arr[n - 1+1])->abs() ) else skip ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class createNode : def __init__(self,data): self.data=data self.left=None self.right=None flag=[0] def NthPostordernode(root,N): if(root==None): return if(flag[0]<=N[0]): NthPostordernode(root.left,N) NthPostordernode(root.right,N) flag[0]+=1 if(flag[0]==N[0]): print(root.data) if __name__=='__main__' : root=createNode(25) root.left=createNode(20) root.right=createNode(30) root.left.left=createNode(18) root.left.right=createNode(22) root.right.left=createNode(24) root.right.right=createNode(32) N=[6] NthPostordernode(root,N) ------------------------------------------------------------ OCL File: --------- class createNode { static operation newcreateNode() : createNode pre: true post: createNode->exists( _x | result = _x ); attribute data : OclAny := data; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(data : OclAny) : createNode pre: true post: true activity: self.data := data ; self.left := null ; self.right := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; var flag : Sequence := Sequence{ 0 } ; skip ; if __name__ = '__main__' then ( root := (createNode.newcreateNode()).initialise(25) ; root.left := (createNode.newcreateNode()).initialise(20) ; root.right := (createNode.newcreateNode()).initialise(30) ; root.left.left := (createNode.newcreateNode()).initialise(18) ; root.left.right := (createNode.newcreateNode()).initialise(22) ; root.right.left := (createNode.newcreateNode()).initialise(24) ; root.right.right := (createNode.newcreateNode()).initialise(32) ; N := Sequence{ 6 } ; NthPostordernode(root, N) ) else skip; operation NthPostordernode(root : OclAny, N : OclAny) pre: true post: true activity: if (root = null) then ( return ) else skip ; if ((flag->first()->compareTo(N->first())) <= 0) then ( NthPostordernode(root.left, N) ; NthPostordernode(root.right, N) ; flag->first() := flag->first() + 1 ; if (flag->first() = N->first()) then ( execute (root.data)->display() ) else skip ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def isValid(i,m): sq_i=math.sqrt(i) sq=min(m,sq_i) for j in range(2,sq+1): if(i % j==0): return False return True def findLargestNum(n,m): for i in range(n,m,-1): if(isValid(i,m)): print("{}\n".format(i)); return print("Number Doesn't Exists\n") n=16 m=3 findLargestNum(n,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 16 ; m := 3 ; findLargestNum(n, m); operation isValid(i : OclAny, m : OclAny) : OclAny pre: true post: true activity: var sq_i : double := (i)->sqrt() ; var sq : OclAny := Set{m, sq_i}->min() ; for j : Integer.subrange(2, sq + 1-1) do ( if (i mod j = 0) then ( return false ) else skip) ; return true; operation findLargestNum(n : OclAny, m : OclAny) pre: true post: true activity: for i : Integer.subrange(m + 1, n)->reverse() do ( if (isValid(i, m)) then ( execute (StringLib.interpolateStrings("{}\n", Sequence{i}))->display(); ; return ) else skip) ; execute ("Number Doesn't Exists\n")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def uniqueNumbers(arr,n): arr.sort() freq=[0]*(n+2) for val in arr : if(freq[val-1]==0): freq[val-1]+=1 elif(freq[val]==0): freq[val]+=1 else : freq[val+1]+=1 unique=0 for val in freq : if(val>0): unique+=1 return unique if __name__=="__main__" : arr=[3,3,3,3] n=4 print(uniqueNumbers(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{3}->union(Sequence{3}->union(Sequence{3}->union(Sequence{ 3 }))) ; n := 4 ; execute (uniqueNumbers(arr, n))->display() ) else skip; operation uniqueNumbers(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 2)) ; for val : arr do ( if (freq[val - 1+1] = 0) then ( freq[val - 1+1] := freq[val - 1+1] + 1 ) else (if (freq[val+1] = 0) then ( freq[val+1] := freq[val+1] + 1 ) else ( freq[val + 1+1] := freq[val + 1+1] + 1 ) ) ) ; var unique : int := 0 ; for val : freq do ( if (val > 0) then ( unique := unique + 1 ) else skip) ; return unique; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def prime(n): if(n==1): return False for i in range(2,int(sqrt(n))+1,1): if(n % i==0): return False return True def Min_Sum(n): if(prime(n)): return 1 if(n % 2==0): return 2 else : if(prime(n-2)): return 2 else : return 3 if __name__=='__main__' : n=27 print(Min_Sum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( n := 27 ; execute (Min_Sum(n))->display() ) else skip; operation prime(n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return false ) else skip ; for i : Integer.subrange(2, ("" + ((sqrt(n))))->toInteger() + 1-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (n mod i = 0) then ( return false ) else skip) ; return true; operation Min_Sum(n : OclAny) : OclAny pre: true post: true activity: if (prime(n)) then ( return 1 ) else skip ; if (n mod 2 = 0) then ( return 2 ) else ( if (prime(n - 2)) then ( return 2 ) else ( return 3 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib,itertools def compute(): cond=lambda i : all((count_distinct_prime_factors(i+j)==4)for j in range(4)) ans=next(filter(cond,itertools.count())) return str(ans) @ eulerlib.memoize def count_distinct_prime_factors(n): count=0 while n>1 : count+=1 for i in range(2,eulerlib.sqrt(n)+1): if n % i==0 : while True : n//=i if n % i!=0 : break break else : break return count if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; (compound_stmt (decorator @ (dotted_name (dotted_name (name eulerlib)) . (name memoize))) (funcdef def (name count_distinct_prime_factors) ( (typedargslist (def_parameters (def_parameter (named_parameter (name n))))) ) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name count)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (compound_stmt while (test (logical_test (comparison (comparison (expr (atom (name n)))) > (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name count)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name eulerlib)) (trailer . (name sqrt) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name n))) % (expr (atom (name i))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (compound_stmt while (test (logical_test (comparison (expr (atom (name True)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name n)))))))) (assign_part //= (testlist (test (logical_test (comparison (expr (atom (name i))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name n))) % (expr (atom (name i))))) != (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt break))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt break)))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name count))))))))))))) ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var cond : Function := lambda i : OclAny in (((argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name count_distinct_prime_factors)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name j))))))))) ))))) == (comparison (expr (atom (number (integer 4))))))))) )))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 4))))))))) )))))))))->forAll( _x | _x = true )) ; var ans : OclAny := ((itertools->count())->select( _x | (cond)->apply(_x) = true )).next() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() d=str() for i in range(len(s)): d+='x' print(d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var d : String := ("" + (())) ; for i : Integer.subrange(0, (s)->size()-1) do ( d := d + 'x') ; execute (d)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- testCases=int(input()) for i in range(testCases): width,height,numbers=map(int,input().split()) m=1 while width>0 or height>0 : if width % 2==0 : width//=2 m*=2 elif height % 2==0 : height//=2 m*=2 else : break print('YES')if m>=numbers else print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var testCases : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, testCases-1) do ( var width : OclAny := null; var height : OclAny := null; var numbers : OclAny := null; Sequence{width,height,numbers} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : int := 1 ; while width > 0 or height > 0 do ( if width mod 2 = 0 then ( width := width div 2 ; m := m * 2 ) else (if height mod 2 = 0 then ( height := height div 2 ; m := m * 2 ) else ( break ) ) ) ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))) if (logical_test (comparison (comparison (expr (atom (name m)))) >= (comparison (expr (atom (name numbers)))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) ))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def parse_int(num : int): to_str=str(num) count=0 sumstr='' for one_str in to_str[: :-1]: count+=1 if count % 3==0 and count!=len(to_str): one_str=','+one_str sumstr=one_str+sumstr else : sumstr=one_str+sumstr return sumstr n=input() n1=n.split(".")[0] n2="" n1=parse_int(abs(int(n1))) if n.count('.')>0 : n2=n.split('.')[1][: 2] if len(n2)<2 : n2=n2+"0" n2="."+n2 else : n2=".00" if n[0]=='-' : print("($"+n1+n2+")",end="") else : print("$"+n1+n2,end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : String := (OclFile["System.in"]).readLine() ; var n1 : OclAny := n.split(".")->first() ; var n2 : String := "" ; n1 := parse_int((("" + ((n1)))->toInteger())->abs()) ; if n->count('.') > 0 then ( n2 := n.split('.')[1+1].subrange(1,2) ; if (n2)->size() < 2 then ( n2 := n2 + "0" ) else skip ; n2 := "." + n2 ) else ( n2 := ".00" ) ; if n->first() = '-' then ( execute ("($" + n1 + n2 + ")")->display() ) else ( execute ("$" + n1 + n2)->display() ); operation parse_int(num : int) : OclAny pre: true post: true activity: var to_str : String := ("" + ((num))) ; var count : int := 0 ; var sumstr : String := '' ; for one_str : to_str(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( count := count + 1 ; if count mod 3 = 0 & count /= (to_str)->size() then ( var one_str : String := ',' + one_str ; sumstr := one_str + sumstr ) else ( sumstr := one_str + sumstr )) ; return sumstr; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import pow,sqrt def area(r): if(r<0): return-1 area=3.14*pow(r/(2*sqrt(2)),2); return area ; if __name__=='__main__' : a=5 print("{0:.6}".format(area(a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var a : int := 5 ; execute (StringLib.interpolateStrings("{0:.6}", Sequence{area(a)}))->display() ) else skip; operation area(r : OclAny) : OclAny pre: true post: true activity: if (r < 0) then ( return -1 ) else skip ; var area : double := 3.14 * (r / (2 * sqrt(2)))->pow(2); ; return area;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print('x'*len(input(''))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (StringLib.nCopies('x', ((OclFile["System.in"]).readLine(''))->size()))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().rstrip() def resolve(): S=input() print('x'*len(S)) if __name__=='__main__' : resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; skip ; if __name__ = '__main__' then ( resolve() ) else skip; operation resolve() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; execute (StringLib.nCopies('x', (S)->size()))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() ans=["x"]*len(s) print(*ans,sep="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ "x" }, (s)->size()) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() win=[] for i in range(len(s)): win.append("x") final_list=''.join(win) print(final_list) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var win : Sequence := Sequence{} ; for i : Integer.subrange(0, (s)->size()-1) do ( execute (("x") : win)) ; var final_list : String := StringLib.sumStringsWithSeparator((win), '') ; execute (final_list)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- exec('a,b,c,d,n='+'int(input()),'*5) if da*c]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: (expr (expr (atom 'a,b,c,d,n=')) + (expr (expr (atom 'int(input()),')) * (expr (atom (number (integer 5)))))) ; if (d->compareTo(c)) < 0 then ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := Sequence{b,a,d,c} ) else skip ; execute (Set{0, n - a * (c - 1) - b * (d - 1)}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a1,a2,k1,k2=int(input()),int(input()),int(input()),int(input()) n1=int(input()) n2=n1 if k1toInteger(),("" + (((OclFile["System.in"]).readLine())))->toInteger(),("" + (((OclFile["System.in"]).readLine())))->toInteger(),("" + (((OclFile["System.in"]).readLine())))->toInteger()} ; var n1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n2 : int := n1 ; if (k1->compareTo(k2)) < 0 then ( var tmp : OclAny := Set{n1 div k1, a1}->min() ; n1 := n1 - (tmp * k1) ; tmp := tmp + n1 div k2 ) else ( tmp := Set{n1 div k2, a2}->min() ; n1 := n1 - (tmp * k2) ; tmp := tmp + n1 div k1 ) ; var mn : OclAny := null; var mx : OclAny := null; Sequence{mn,mx} := Sequence{0,0} ; n2 := Set{0, n2 - (k2 - 1) * a2 - (k1 - 1) * a1}->max() ; execute (n2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a1=int(input()) a2=int(input()) k1=int(input()) k2=int(input()) n=int(input()) min_number_of_players_sent_off=n-(a1*(k1-1)+a2*(k2-1)) max_number_of_players_sent_off=0 if k1>k2 : if k2*a2<=n : max_number_of_players_sent_off=a2+(n-a2*k2)//k1 else : max_number_of_players_sent_off=n//k2 else : if k1*a1<=n : max_number_of_players_sent_off=a1+(n-a1*k1)//k2 else : max_number_of_players_sent_off=n//k1 if min_number_of_players_sent_off>=0 : print(min_number_of_players_sent_off,max_number_of_players_sent_off) else : print('0',max_number_of_players_sent_off) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a2 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k2 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var min_number_of_players_sent_off : double := n - (a1 * (k1 - 1) + a2 * (k2 - 1)) ; var max_number_of_players_sent_off : int := 0 ; if (k1->compareTo(k2)) > 0 then ( if (k2 * a2->compareTo(n)) <= 0 then ( max_number_of_players_sent_off := a2 + (n - a2 * k2) div k1 ) else ( max_number_of_players_sent_off := n div k2 ) ) else ( if (k1 * a1->compareTo(n)) <= 0 then ( max_number_of_players_sent_off := a1 + (n - a1 * k1) div k2 ) else ( max_number_of_players_sent_off := n div k1 ) ) ; if min_number_of_players_sent_off >= 0 then ( execute (min_number_of_players_sent_off)->display() ) else ( execute ('0')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) a1,a2,k1,k2,n=(int(input())for i in range(5)) if k1>k2 : a1,k1,a2,k2=a2,k2,a1,k1 print(max(0,n-(a1*(k1-1)+a2*(k2-1))),end=" ") if n<=a1*k1 : print(n//k1) else : print(a1+((n-(a1*k1))//k2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a1 : OclAny := null; var a2 : OclAny := null; var k1 : OclAny := null; var k2 : OclAny := null; var n : OclAny := null; Sequence{a1,a2,k1,k2,n} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 5))))))))) ))))))))} ; if (k1->compareTo(k2)) > 0 then ( var a1 : OclAny := null; var k1 : OclAny := null; var a2 : OclAny := null; var k2 : OclAny := null; Sequence{a1,k1,a2,k2} := Sequence{a2,k2,a1,k1} ) else skip ; execute (Set{0, n - (a1 * (k1 - 1) + a2 * (k2 - 1))}->max())->display() ; if (n->compareTo(a1 * k1)) <= 0 then ( execute (n div k1)->display() ) else ( execute (a1 + ((n - (a1 * k1)) div k2))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for x in range(t): a,b,c=map(int,input().split()) d=1 y=1 while a % 2==0 : a//=2 d*=2 while b % 2==0 : b//=2 y*=2 if d*y>=c : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for x : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : int := 1 ; var y : int := 1 ; while a mod 2 = 0 do ( a := a div 2 ; d := d * 2) ; while b mod 2 = 0 do ( b := b div 2 ; y := y * 2) ; if (d * y->compareTo(c)) >= 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline a=[int(input())for _ in range(2)] k=[int(input())for _ in range(2)] n=int(input()) if k[0]>k[1]: a[0],a[1]=a[1],a[0] k[0],k[1]=k[1],k[0] mi=max(n-(a[0]*(k[0]-1)+a[1]*(k[1]-1)),0) ma=0 for i in range(2): for _ in range(a[i]): if n>=k[i]: n-=k[i] ma+=1 print(mi,ma) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var a : Sequence := Integer.subrange(0, 2-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var k : Sequence := Integer.subrange(0, 2-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (k->first()->compareTo(k[1+1])) > 0 then ( var a->first() : OclAny := null; var a[1+1] : OclAny := null; Sequence{a->first(),a[1+1]} := Sequence{a[1+1],a->first()} ; var k->first() : OclAny := null; var k[1+1] : OclAny := null; Sequence{k->first(),k[1+1]} := Sequence{k[1+1],k->first()} ) else skip ; var mi : OclAny := Set{n - (a->first() * (k->first() - 1) + a[1+1] * (k[1+1] - 1)), 0}->max() ; var ma : int := 0 ; for i : Integer.subrange(0, 2-1) do ( for _anon : Integer.subrange(0, a[i+1]-1) do ( if (n->compareTo(k[i+1])) >= 0 then ( n := n - k[i+1] ; ma := ma + 1 ) else skip)) ; execute (mi)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil n,level=int(input()),input() print(('no','yes')[any('*****' in level[start : : jump]for jump in range(1,ceil(n/4))for start in[i for i in range(n)if level[i]=='*'])]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var level : OclAny := null; Sequence{n,level} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),(OclFile["System.in"]).readLine()} ; execute (Sequence{'no', 'yes'}->select(((argument (test (logical_test (comparison (comparison (expr (atom '*****'))) in (comparison (expr (atom (name level)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name start)))))) : (sliceop : (test (logical_test (comparison (expr (atom (name jump))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name jump)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name ceil)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) / (expr (atom (number (integer 4)))))))))) ))))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name start)))) in (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name level)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom '*'))))))))) ])))))))))->exists( _x | _x = true )))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* def area(a): if a<0 : return-1 area=sqrt(a)/6 return area if __name__=="__main__" : a=10 print(round(area(a),6)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( a := 10 ; execute (MathLib.roundN(area(a), 6))->display() ) else skip; operation area(a : OclAny) : OclAny pre: true post: true activity: if a < 0 then ( return -1 ) else skip ; var area : double := sqrt(a) / 6 ; return area; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() if n<5 : print("no") else : for l in range(1,n-3): ans=0 for st in range(n): fl=0 if s[st]=='.' : continue else : cn=0 for j in range(st+l,n,l): if s[j]=='.' : fl=1 cn=-1 else : cn+=1 if cn==4 : fl=3 break if fl==3 : ans=1 break if ans==1 : break if ans==1 : print("yes") else : print("no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; if n < 5 then ( execute ("no")->display() ) else ( for l : Integer.subrange(1, n - 3-1) do ( var ans : int := 0 ; for st : Integer.subrange(0, n-1) do ( var fl : int := 0 ; if s[st+1] = '.' then ( continue ) else ( var cn : int := 0 ; for j : Integer.subrange(st + l, n-1)->select( $x | ($x - st + l) mod l = 0 ) do ( if s[j+1] = '.' then ( fl := 1 ; cn := -1 ) else ( cn := cn + 1 ; if cn = 4 then ( fl := 3 ; break ) else skip )) ) ; if fl = 3 then ( ans := 1 ; break ) else skip) ; if ans = 1 then ( break ) else skip) ; if ans = 1 then ( execute ("yes")->display() ) else ( execute ("no")->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def king(s): l=[] for i in range(len(s)): if s[i]=='*' : l.append(i) if len(l)<5 : print('no') else : k=(max(x for x in l)-min(x for x in l))//4 def space_eq(s,j): ans=False for i in s : if(i+j)in s and(i+2*j)in s and(i+3*j)in s and(i+4*j)in s : ans=True break return ans ans=False for j in range(1,k+1): if space_eq(l,j)==True : ans=True break if ans==True : print('yes') else : print('no') n=int(input()) s=input() assert len(s)==n,'Incorrect Input' king(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; s := (OclFile["System.in"]).readLine() ; assert (s)->size() = n do 'Incorrect Input' ; king(s); operation king(s : OclAny) pre: true post: true activity: var l : Sequence := Sequence{} ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = '*' then ( execute ((i) : l) ) else skip) ; if (l)->size() < 5 then ( execute ('no')->display() ) else ( var k : int := (((argument (test (logical_test (comparison (expr (atom (name x)))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name l))))))))->max() - ((argument (test (logical_test (comparison (expr (atom (name x)))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name l))))))))->min()) div 4 ; skip ; ans := false ; for j : Integer.subrange(1, k + 1-1) do ( if space_eq(l, j) = true then ( ans := true ; break ) else skip) ; if ans = true then ( execute ('yes')->display() ) else ( execute ('no')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=int(input()) s=[True if x=='*' else False for x in input()] ans='no' for y in range(1,i//4+1): for x in range(0,i-(y*4)): if all(s[x+(y*z)]for z in range(0,5)): ans='yes' print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := (OclFile["System.in"]).readLine()->select(x | true)->collect(x | (if x = '*' then true else false endif)) ; var ans : String := 'no' ; for y : Integer.subrange(1, i div 4 + 1-1) do ( for x : Integer.subrange(0, i - (y * 4)-1) do ( if ((argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name y))) * (expr (atom (name z)))))))) ))))))))) ])))))) (comp_for for (exprlist (expr (atom (name z)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 5))))))))) )))))))))->forAll( _x | _x = true ) then ( ans := 'yes' ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def seriesSum(n): return int((n*(n+1)*(n+2))/6) n=4 print(seriesSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute (seriesSum(n))->display(); operation seriesSum(n : OclAny) : OclAny pre: true post: true activity: return ("" + (((n * (n + 1) * (n + 2)) / 6)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checksum(n): n=int(n) if n % 3==0 : print(int(n/3-1)," ",int(n/3)," ",int(n/3+1)) else : print("-1") n=6 checksum(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 6 ; checksum(n); operation checksum(n : OclAny) pre: true post: true activity: n := ("" + ((n)))->toInteger() ; if n mod 3 = 0 then ( execute (("" + ((n / 3 - 1)))->toInteger())->display() ) else ( execute ("-1")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def angle(n): return 2*n n=30 print(angle(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 30 ; execute (angle(n))->display(); operation angle(n : OclAny) : OclAny pre: true post: true activity: return 2 * n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def centeredTetrahedralNumber(n): return(2*n+1)*(n*n+n+3)//3 n=6 print(centeredTetrahedralNumber(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 6 ; execute (centeredTetrahedralNumber(n))->display(); operation centeredTetrahedralNumber(n : OclAny) : OclAny pre: true post: true activity: return (2 * n + 1) * (n * n + n + 3) div 3; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() k=int(input()) print('impossible' if k>len(s)else max(0,k-len(set(s)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (if (k->compareTo((s)->size())) > 0 then 'impossible' else Set{0, k - (Set{}->union((s)))->size()}->max() endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): w,h,n=map(int,input().split()) print("YNEOS"[w*h &-w*htoInteger()-1) do ( var w : OclAny := null; var h : OclAny := null; var n : OclAny := null; Sequence{w,h,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ("YNEOS"(subscript (test (logical_test (comparison (comparison (expr (expr (expr (atom (name w))) * (expr (atom (name h)))) & (expr (expr - (expr (atom (name w)))) * (expr (atom (name h)))))) < (comparison (expr (atom (name n))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def avgOfFirstN(n): return(float)(1+n)/2 ; n=20 print(avgOfFirstN(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 20 ; execute (avgOfFirstN(n))->display(); operation avgOfFirstN(n : OclAny) pre: true post: true activity: return (OclType["double"])(1 + n) / 2;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def evenPowerSum(n): return(8*n*(n+1)*(2*n+1)*(3*n*n+3*n-1))/15 ; n=4 ; print(int(evenPowerSum(n))); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4; ; execute (("" + ((evenPowerSum(n))))->toInteger())->display();; operation evenPowerSum(n : OclAny) pre: true post: true activity: return (8 * n * (n + 1) * (2 * n + 1) * (3 * n * n + 3 * n - 1)) / 15;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countStr(n): return(1+(n*2)+(n*((n*n)-1)//2)) if __name__=="__main__" : n=3 print(countStr(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 3 ; execute (countStr(n))->display() ) else skip; operation countStr(n : OclAny) : OclAny pre: true post: true activity: return (1 + (n * 2) + (n * ((n * n) - 1) div 2)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* def trianglearea(a,b): if a<0 or b<0 : return-1 area=(3*sqrt(3)*pow(a,2))/(4*b) return area if __name__=="__main__" : a,b=4,2 print(round(trianglearea(a,b),4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( Sequence{a,b} := Sequence{4,2} ; execute (MathLib.roundN(trianglearea(a, b), 4))->display() ) else skip; operation trianglearea(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a < 0 or b < 0 then ( return -1 ) else skip ; var area : double := (3 * sqrt(3) * (a)->pow(2)) / (4 * b) ; return area; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def seriesSum(n): return int((n*(n+1)*(n+2))/6) n=4 print(seriesSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute (seriesSum(n))->display(); operation seriesSum(n : OclAny) : OclAny pre: true post: true activity: return ("" + (((n * (n + 1) * (n + 2)) / 6)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def per(n): if(n==0): return 3 ; if(n==1): return 0 ; if(n==2): return 2 ; return per(n-2)+per(n-3); n=9 ; print(per(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 9; ; execute (per(n))->display();; operation per(n : OclAny) pre: true post: true activity: if (n = 0) then ( return 3; ) else skip ; if (n = 1) then ( return 0; ) else skip ; if (n = 2) then ( return 2; ) else skip ; return per(n - 2) + per(n - 3);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSetBits(n): if(n==0): return 0 else : return(n & 1)+countSetBits(n>>1) n=9 print(countSetBits(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 9 ; execute (countSetBits(n))->display(); operation countSetBits(n : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return 0 ) else ( return (MathLib.bitwiseAnd(n, 1)) + countSetBits(n /(2->pow(1))) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def leonardo(n): if(n==0 or n==1): return 1 return(leonardo(n-1)+leonardo(n-2)+1); print(leonardo(3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (leonardo(3))->display(); operation leonardo(n : OclAny) : OclAny pre: true post: true activity: if (n = 0 or n = 1) then ( return 1 ) else skip ; return (leonardo(n - 1) + leonardo(n - 2) + 1);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def weightedMean(n): return(2*n+1)/3 n=10 print(int(weightedMean(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 10 ; execute (("" + ((weightedMean(n))))->toInteger())->display(); operation weightedMean(n : OclAny) : OclAny pre: true post: true activity: return (2 * n + 1) / 3; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def binomialCoeffSum(n): return(1<display(); operation binomialCoeffSum(n : OclAny) pre: true post: true activity: return (1 * (2->pow(n)));; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): w,h,n=map(int,input().split()) print("YNEOS"[w*h &-w*htoInteger()-1) do ( var w : OclAny := null; var h : OclAny := null; var n : OclAny := null; Sequence{w,h,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ("YNEOS"(subscript (test (logical_test (comparison (comparison (expr (expr (expr (atom (name w))) * (expr (atom (name h)))) & (expr (expr - (expr (atom (name w)))) * (expr (atom (name h)))))) < (comparison (expr (atom (name n))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countNumberOfTriangles(n): return(n*(n-1)*(n-2)//6) if __name__=='__main__' : n=4 print(countNumberOfTriangles(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 4 ; execute (countNumberOfTriangles(n))->display() ) else skip; operation countNumberOfTriangles(n : OclAny) : OclAny pre: true post: true activity: return (n * (n - 1) * (n - 2) div 6); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findStarNum(n): return(6*n*(n-1)+1) n=3 print(findStarNum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3 ; execute (findStarNum(n))->display(); operation findStarNum(n : OclAny) : OclAny pre: true post: true activity: return (6 * n * (n - 1) + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Centered_Trigunal_num(n): return(3*n*n+3*n+2)//2 if __name__=='__main__' : n=3 print(Centered_Trigunal_num(n)) n=12 print(Centered_Trigunal_num(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 3 ; execute (Centered_Trigunal_num(n))->display() ; n := 12 ; execute (Centered_Trigunal_num(n))->display() ) else skip; operation Centered_Trigunal_num(n : OclAny) : OclAny pre: true post: true activity: return (3 * n * n + 3 * n + 2) div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findValueAtX(n): return(n*n*n)+n print(findValueAtX(10)) print(findValueAtX(2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (findValueAtX(10))->display() ; execute (findValueAtX(2))->display(); operation findValueAtX(n : OclAny) : OclAny pre: true post: true activity: return (n * n * n) + n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import pow,sqrt def area(a): if(a<0): return-1 area=pow((a*sqrt(3))/(sqrt(2)),2) return area if __name__=='__main__' : a=5 print("{0:.3}".format(area(a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( a := 5 ; execute (StringLib.interpolateStrings("{0:.3}", Sequence{area(a)}))->display() ) else skip; operation area(a : OclAny) : OclAny pre: true post: true activity: if (a < 0) then ( return -1 ) else skip ; var area : double := ((a * sqrt(3)) / (sqrt(2)))->pow(2) ; return area; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checksum(n): n=int(n) if n % 5==0 : print(int(n/5-2)," ",int(n/5-1)," ",int(n/5)," ",int(n/5+1)," ",int(n/5+2)) else : print("-1") n=15 checksum(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 15 ; checksum(n); operation checksum(n : OclAny) pre: true post: true activity: n := ("" + ((n)))->toInteger() ; if n mod 5 = 0 then ( execute (("" + ((n / 5 - 2)))->toInteger())->display() ) else ( execute ("-1")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def avg_of_even_num(n): return n+1 n=8 print(avg_of_even_num(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 8 ; execute (avg_of_even_num(n))->display(); operation avg_of_even_num(n : OclAny) : OclAny pre: true post: true activity: return n + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def heptagonalNumber(n): return((5*n*n)-(3*n))//2 if __name__=='__main__' : n=2 print(heptagonalNumber(n)) n=15 print(heptagonalNumber(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 2 ; execute (heptagonalNumber(n))->display() ; n := 15 ; execute (heptagonalNumber(n))->display() ) else skip; operation heptagonalNumber(n : OclAny) : OclAny pre: true post: true activity: return ((5 * n * n) - (3 * n)) div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def AvgofSquareN(n): return((n+1)*(2*n+1))/6 ; n=2 ; print(AvgofSquareN(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 2; ; execute (AvgofSquareN(n))->display();; operation AvgofSquareN(n : OclAny) pre: true post: true activity: return ((n + 1) * (2 * n + 1)) / 6;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fnMod(n): if(n % 5==1): return 4 else : return 0 n=10 print(fnMod(n)) n=11 print(fnMod(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 10 ; execute (fnMod(n))->display() ; n := 11 ; execute (fnMod(n))->display(); operation fnMod(n : OclAny) : OclAny pre: true post: true activity: if (n mod 5 = 1) then ( return 4 ) else ( return 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findPoint(x1,y1,x2,y2): print("(",2*x2-x1,",",2*y2-y1,")"); x1=0 ; y1=0 ; x2=1 ; y2=1 ; findPoint(x1,y1,x2,y2); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x1 := 0; ; y1 := 0; ; x2 := 1; ; y2 := 1; ; findPoint(x1, y1, x2, y2);; operation findPoint(x1 : OclAny, y1 : OclAny, x2 : OclAny, y2 : OclAny) pre: true post: true activity: execute ("(")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getResult(n): if n & 1 : return 1 return-1 n=3 print(getResult(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3 ; execute (getResult(n))->display(); operation getResult(n : OclAny) : OclAny pre: true post: true activity: if MathLib.bitwiseAnd(n, 1) then ( return 1 ) else skip ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fib(n): if(n<=1): return n return fib(n-1)+fib(n-2) if __name__=='__main__' : n=6 print(fib(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 6 ; execute (fib(n))->display() ) else skip; operation fib(n : OclAny) : OclAny pre: true post: true activity: if (n <= 1) then ( return n ) else skip ; return fib(n - 1) + fib(n - 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pentagon_pyramidal(n): return n*n*(n+1)/2 n=4 print(int(pentagon_pyramidal(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute (("" + ((pentagon_pyramidal(n))))->toInteger())->display(); operation pentagon_pyramidal(n : OclAny) : OclAny pre: true post: true activity: return n * n * (n + 1) / 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findCullen(n): return(1<display(); operation findCullen(n : OclAny) : OclAny pre: true post: true activity: return (1 * (2->pow(n))) * n + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSetBits(n): if(n==0): return 0 else : return 1+countSetBits(n &(n-1)) n=9 print(countSetBits(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 9 ; execute (countSetBits(n))->display(); operation countSetBits(n : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return 0 ) else ( return 1 + countSetBits(MathLib.bitwiseAnd(n, (n - 1))) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def trianglearea(a): if(a<0): return-1 ; area=(3*math.sqrt(3)*math.pow(a,2))/4 ; return area ; a=6 ; print(trianglearea(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 6; ; execute (trianglearea(a))->display(); operation trianglearea(a : OclAny) pre: true post: true activity: if (a < 0) then ( return -1; ) else skip ; var area : double := (3 * (3)->sqrt() * (a)->pow(2)) / 4; ; return area;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countIntegralSolutions(n): return int(((n+1)*(n+2))/2) n=3 print(countIntegralSolutions(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3 ; execute (countIntegralSolutions(n))->display(); operation countIntegralSolutions(n : OclAny) : OclAny pre: true post: true activity: return ("" + ((((n + 1) * (n + 2)) / 2)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def centeredTridecagonalNum(n): return(13*n*(n-1)+2)//2 if __name__=='__main__' : n=3 print(centeredTridecagonalNum(n)) n=10 print(centeredTridecagonalNum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 3 ; execute (centeredTridecagonalNum(n))->display() ; n := 10 ; execute (centeredTridecagonalNum(n))->display() ) else skip; operation centeredTridecagonalNum(n : OclAny) : OclAny pre: true post: true activity: return (13 * n * (n - 1) + 2) div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def series(n): print((8*n**2)+1) series(5) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; series(5); operation series(n : OclAny) pre: true post: true activity: execute ((8 * (n)->pow(2)) + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=200006 CONS=32766 def calc(a,b,lr,q,n): cc=0 for i in range(n-1): a[i+1]+=a[i] b[i+1]+=b[i] while(q>0): l=lr[cc] cc+=1 r=lr[cc] cc+=1 l-=2 r-=1 suma=a[r] sumb=b[r] if(l>=0): suma-=a[l] sumb-=b[l] M=max(CONS*suma+CONS*sumb,-CONS*suma-CONS*sumb) M=max(M,max(CONS*suma-CONS*sumb,-CONS*suma+CONS*sumb)) m=min(CONS*suma+CONS*sumb,-CONS*suma-CONS*sumb) m=min(m,min(CONS*suma-CONS*sumb,-CONS*suma+CONS*sumb)) print(M-m) q-=1 if __name__=="__main__" : n=5 q=2 a=[0,7,3,4,5] b=[0,3,1,2,3] lr=[0]*(q*2) lr[0]=1 lr[1]=1 lr[2]=1 lr[3]=3 calc(a,b,lr,q,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 200006 ; var CONS : int := 32766 ; skip ; if __name__ = "__main__" then ( n := 5 ; q := 2 ; a := Sequence{0}->union(Sequence{7}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ; b := Sequence{0}->union(Sequence{3}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })))) ; lr := MatrixLib.elementwiseMult(Sequence{ 0 }, (q * 2)) ; lr->first() := 1 ; lr[1+1] := 1 ; lr[2+1] := 1 ; lr[3+1] := 3 ; calc(a, b, lr, q, n) ) else skip; operation calc(a : OclAny, b : OclAny, lr : OclAny, q : OclAny, n : OclAny) pre: true post: true activity: var cc : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( a[i + 1+1] := a[i + 1+1] + a[i+1] ; b[i + 1+1] := b[i + 1+1] + b[i+1]) ; while (q > 0) do ( var l : OclAny := lr[cc+1] ; cc := cc + 1 ; var r : OclAny := lr[cc+1] ; cc := cc + 1 ; l := l - 2 ; r := r - 1 ; var suma : OclAny := a[r+1] ; var sumb : OclAny := b[r+1] ; if (l >= 0) then ( suma := suma - a[l+1] ; sumb := sumb - b[l+1] ) else skip ; var M : OclAny := Set{CONS * suma + CONS * sumb, -CONS * suma - CONS * sumb}->max() ; M := Set{M, Set{CONS * suma - CONS * sumb, -CONS * suma + CONS * sumb}->max()}->max() ; var m : OclAny := Set{CONS * suma + CONS * sumb, -CONS * suma - CONS * sumb}->min() ; m := Set{m, Set{CONS * suma - CONS * sumb, -CONS * suma + CONS * sumb}->min()}->min() ; execute (M - m)->display() ; q := q - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt from collections import defaultdict,deque from bisect import bisect_left as b_l from bisect import bisect_right as b_r import sys mod=10**9+7 for i in range(int(input())): k,x=map(int,input().split()) print(9*(k-1)+x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var k : OclAny := null; var x : OclAny := null; Sequence{k,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (9 * (k - 1) + x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=lambda : stdin.readline().strip() n,k=list(map(int,input().split())) if k>n**2 : print(-1) else : mt=[[0 for i in range(n)]for i in range(n)] for i in range(n): if k==0 : break mt[i][i]=1 k-=1 for j in range(i+1,n): if k>1 : mt[i][j]=1 mt[j][i]=1 k-=2 else : break for i in mt : print(*i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (stdin.readLine()->trim()) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (k->compareTo((n)->pow(2))) > 0 then ( execute (-1)->display() ) else ( var mt : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, n-1) do ( if k = 0 then ( break ) else skip ; mt[i+1][i+1] := 1 ; k := k - 1 ; for j : Integer.subrange(i + 1, n-1) do ( if k > 1 then ( mt[i+1][j+1] := 1 ; mt[j+1][i+1] := 1 ; k := k - 2 ) else ( break ))) ; for i : mt do ( execute ((argument * (test (logical_test (comparison (expr (atom (name i))))))))->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) if k>n**2 : print(-1) exit() if k==0 : for i in range(n): print(*[0]*n) exit() ans=[[0]*n for i in range(n)] for i in range(n): for j in range(n): if ans[i][j]==1 : continue if k==0 : break if i!=j : if k==1 : break else : ans[i][j]=1 ans[j][i]=1 k-=2 else : ans[i][i]=1 k-=1 else : continue break if k : for i in range(n): if ans[i][i]!=1 : ans[i][i]=1 break for i in range(n): print(*ans[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (k->compareTo((n)->pow(2))) > 0 then ( execute (-1)->display() ; exit() ) else skip ; if k = 0 then ( for i : Integer.subrange(0, n-1) do ( execute ((argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr (atom (name n)))))))))->display()) ; exit() ) else skip ; var ans : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, n))) ; for i : Integer.subrange(0, n-1) do ((compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt continue)))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name k)))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt break)))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name i)))) != (comparison (expr (atom (name j))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name k)))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt break)))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name k)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 2))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name k)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt continue)))))) ; break) ; if k then ( for i : Integer.subrange(0, n-1) do ( if ans[i+1][i+1] /= 1 then ( ans[i+1][i+1] := 1 ; break ) else skip) ) else skip ; for i : Integer.subrange(0, n-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=list(map(int,input().split())) if k>n**2 : print(-1) else : mt=[[0 for i in range(n)]for i in range(n)] for i in range(n): if k==0 : break mt[i][i]=1 k-=1 for j in range(i+1,n): if k>1 : mt[i][j]=1 mt[j][i]=1 k-=2 else : break for i in mt : print(*i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (k->compareTo((n)->pow(2))) > 0 then ( execute (-1)->display() ) else ( var mt : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, n-1) do ( if k = 0 then ( break ) else skip ; mt[i+1][i+1] := 1 ; k := k - 1 ; for j : Integer.subrange(i + 1, n-1) do ( if k > 1 then ( mt[i+1][j+1] := 1 ; mt[j+1][i+1] := 1 ; k := k - 2 ) else ( break ))) ; for i : mt do ( execute ((argument * (test (logical_test (comparison (expr (atom (name i))))))))->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findTrailingZeros(n): if(n & 1): return 0 else : ans=0 n//=2 while(n): ans+=n//5 n//=5 return ans n=12 print(findTrailingZeros(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 12 ; execute (findTrailingZeros(n))->display(); operation findTrailingZeros(n : OclAny) : OclAny pre: true post: true activity: if (MathLib.bitwiseAnd(n, 1)) then ( return 0 ) else ( var ans : int := 0 ; n := n div 2 ; while (n) do ( ans := ans + n div 5 ; n := n div 5) ; return ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() res=0 a=set() for c in s : if 'A'<=c<='Z' : res=max(res,len(a)) a.clear() else : a.add(c) res=max(len(a),res) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var res : int := 0 ; var a : Set := Set{}->union(()) ; for c : s->characters() do ( if 'A' <= c & (c <= 'Z') then ( res := Set{res, (a)->size()}->max() ; execute (a /<: a) ) else ( execute ((c) : a) )) ; res := Set{(a)->size(), res}->max() ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin tt=1 ANS=[] for loop in range(tt): n=int(stdin.readline()) s=list(stdin.readline()[:-1]) for i in range(n): if "A"<=s[i]<="Z" : s[i]="#" sp="".join(s) lis=list(sp.split("#")) ans=0 for ts in lis : ch=set() for c in ts : ch.add(c) ans=max(ans,len(ch)) ANS.append(ans) print("\n".join(map(str,ANS))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var tt : int := 1 ; var ANS : Sequence := Sequence{} ; for loop : Integer.subrange(0, tt-1) do ( var n : int := ("" + ((stdin.readLine())))->toInteger() ; var s : Sequence := (stdin.readLine()->front()) ; for i : Integer.subrange(0, n-1) do ( if "A" <= s[i+1] & (s[i+1] <= "Z") then ( s[i+1] := "#" ) else skip) ; var sp : String := StringLib.sumStringsWithSeparator((s), "") ; var lis : Sequence := (sp.split("#")) ; var ans : int := 0 ; for ts : lis do ( var ch : Set := Set{}->union(()) ; for c : ts do ( execute ((c) : ch)) ; ans := Set{ans, (ch)->size()}->max()) ; execute ((ans) : ANS)) ; execute (StringLib.sumStringsWithSeparator(((ANS)->collect( _x | (OclType["String"])->apply(_x) )), "\n"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- NO_OF_CHARS=256 def printDistinct(str): count=[0]*NO_OF_CHARS for i in range(len(str)): if(str[i]!=' '): count[ord(str[i])]+=1 n=i for i in range(n): if(count[ord(str[i])]==1): print(str[i],end="") if __name__=="__main__" : str="GeeksforGeeks" printDistinct(str) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var NO_OF_CHARS : int := 256 ; skip ; if __name__ = "__main__" then ( OclType["String"] := "GeeksforGeeks" ; printDistinct(OclType["String"]) ) else skip; operation printDistinct(OclType["String"] : OclAny) pre: true post: true activity: var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, NO_OF_CHARS) ; for i : Integer.subrange(0, (OclType["String"])->size()-1) do ( if (("" + ([i+1])) /= ' ') then ( count[(("" + ([i+1])))->char2byte()+1] := count[(("" + ([i+1])))->char2byte()+1] + 1 ) else skip) ; var n : OclAny := i ; for i : Integer.subrange(0, n-1) do ( if (count[(("" + ([i+1])))->char2byte()+1] = 1) then ( execute (("" + ([i+1])))->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re input() s=input() ans=list(map(lambda x : len(set(x)),re.split('[A-Z]',s))) print(max(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; input() ; var s : String := (OclFile["System.in"]).readLine() ; var ans : Sequence := (((s)->split('[A-Z]'))->collect( _x | (lambda x : OclAny in ((Set{}->union((x)))->size()))->apply(_x) )) ; execute ((ans)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() max1=0 c=0 letters=[] for i in range(0,len(s)): ord1=ord(s[i]) if(ord1>=97 and ord1<=122): if(s[i]not in letters): letters.append(s[i]) c+=1 else : letters=[] if(c>max1): max1=c c=0 if(c>max1): max1=c print(max1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var max1 : int := 0 ; var c : int := 0 ; var letters : Sequence := Sequence{} ; for i : Integer.subrange(0, (s)->size()-1) do ( var ord1 : int := (s[i+1])->char2byte() ; if (ord1 >= 97 & ord1 <= 122) then ( if ((letters)->excludes(s[i+1])) then ( execute ((s[i+1]) : letters) ; c := c + 1 ) else skip ) else ( letters := Sequence{} ; if ((c->compareTo(max1)) > 0) then ( max1 := c ) else skip ; c := 0 )) ; if ((c->compareTo(max1)) > 0) then ( max1 := c ) else skip ; execute (max1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) import re input() s=input() ans=list(map(lambda x : len(set(x)),re.split('[A-Z]',s))) print(max(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; input() ; var s : String := (OclFile["System.in"]).readLine() ; var ans : Sequence := (((s)->split('[A-Z]'))->collect( _x | (lambda x : OclAny in ((Set{}->union((x)))->size()))->apply(_x) )) ; execute ((ans)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) n+=1 for _ in range(int(input())): a,b=map(int,input().split()) print((min(min(a,n-a),min(b,n-b))-1)% 3+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; n := n + 1 ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Set{Set{a, n - a}->min(), Set{b, n - b}->min()}->min() - 1) mod 3 + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def isPutNum(board,x,y,n): for i in range(9): if board[x][i]==n : return False for i in range(9): if board[i][y]==n : return False xx=math.floor(x/3) yy=math.floor(y/3) for i in range(3): for j in range(3): if board[xx*3+i][yy*3+j]==n : return False return True N=int(input()) table=[[0 for i in range(9)]for j in range(9)] for l in range(N): if l>0 : print("") for i in range(9): table[i]=[int(j)for j in input().split()] for i in range(9): for j in range(9): tmp=table[i][j] table[i][j]=0 if isPutNum(table,i,j,tmp): print("",end="") else : print("*",end="") table[i][j]=tmp print(table[i][j],end="") print("") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var table : Sequence := Integer.subrange(0, 9-1)->select(j | true)->collect(j | (Integer.subrange(0, 9-1)->select(i | true)->collect(i | (0)))) ; for l : Integer.subrange(0, N-1) do ( if l > 0 then ( execute ("")->display() ) else skip ; for i : Integer.subrange(0, 9-1) do ( table[i+1] := input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger()))) ; for i : Integer.subrange(0, 9-1) do ( for j : Integer.subrange(0, 9-1) do ( var tmp : OclAny := table[i+1][j+1] ; table[i+1][j+1] := 0 ; if isPutNum(table, i, j, tmp) then ( execute ("")->display() ) else ( execute ("*")->display() ) ; table[i+1][j+1] := tmp ; execute (table[i+1][j+1])->display()) ; execute ("")->display())); operation isPutNum(board : OclAny, x : OclAny, y : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, 9-1) do ( if board[x+1][i+1] = n then ( return false ) else skip) ; for i : Integer.subrange(0, 9-1) do ( if board[i+1][y+1] = n then ( return false ) else skip) ; var xx : double := (x / 3)->floor() ; var yy : double := (y / 3)->floor() ; for i : Integer.subrange(0, 3-1) do ( for j : Integer.subrange(0, 3-1) do ( if board[xx * 3 + i+1][yy * 3 + j+1] = n then ( return false ) else skip)) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): board=[] check=[[0 for a in range(9)]for b in range(9)] for j in range(9): board.append(list(map(int,input().split()))) board_r=[list(x)for x in zip(*board)] for j in range(9): for k in range(9): if board[j].count(board[j][k])>1 : check[j][k]=1 for j in range(9): for k in range(9): if board_r[j].count(board_r[j][k])>1 : check[k][j]=1 for j in range(3): for k in range(3): ch_list=[] for l in range(9): ch_list.append(board[j*3+l % 3][k*3+l//3]) for l in range(9): if ch_list.count(ch_list[l])>1 : check[j*3+l % 3][k*3+l//3]=1 for j in range(9): for k in range(9): if check[j][k]==1 : print("*",end="") else : print("",end="") print(board[j][k],end="") print() if itoInteger() ; for i : Integer.subrange(0, n-1) do ( var board : Sequence := Sequence{} ; var check : Sequence := Integer.subrange(0, 9-1)->select(b | true)->collect(b | (Integer.subrange(0, 9-1)->select(a | true)->collect(a | (0)))) ; for j : Integer.subrange(0, 9-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : board)) ; var board_r : Sequence := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name board)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name board)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name board)))))))`third->at(_indx)} )->select(x | true)->collect(x | ((x))) ; for j : Integer.subrange(0, 9-1) do ( for k : Integer.subrange(0, 9-1) do ( if board[j+1]->count(board[j+1][k+1]) > 1 then ( check[j+1][k+1] := 1 ) else skip)) ; for j : Integer.subrange(0, 9-1) do ( for k : Integer.subrange(0, 9-1) do ( if board_r[j+1]->count(board_r[j+1][k+1]) > 1 then ( check[k+1][j+1] := 1 ) else skip)) ; for j : Integer.subrange(0, 3-1) do ( for k : Integer.subrange(0, 3-1) do ( var ch_list : Sequence := Sequence{} ; for l : Integer.subrange(0, 9-1) do ( execute ((board[j * 3 + l mod 3+1][k * 3 + l div 3+1]) : ch_list)) ; for l : Integer.subrange(0, 9-1) do ( if ch_list->count(ch_list[l+1]) > 1 then ( check[j * 3 + l mod 3+1][k * 3 + l div 3+1] := 1 ) else skip))) ; for j : Integer.subrange(0, 9-1) do ( for k : Integer.subrange(0, 9-1) do ( if check[j+1][k+1] = 1 then ( execute ("*")->display() ) else ( execute ("")->display() ) ; execute (board[j+1][k+1])->display()) ; execute (->display()) ; if (i->compareTo(n - 1)) < 0 then ( execute (->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) st=True for _ in range(n): if st==False : print() puzzle=[] for i in range(9): row=[int(j)for j in input().split("")] puzzle.append(row) dup=[[False for i in range(9)]for j in range(9)] for i in range(9): for j in range(9): for k in range(9): if i!=k and puzzle[i][j]==puzzle[k][j]: dup[i][j]=True if j!=k and puzzle[i][j]==puzzle[i][k]: dup[i][j]=True for p in range(3): for q in range(3): x=(i//3)*3+p y=(j//3)*3+q if(x==i and y==j): continue if puzzle[x][y]==puzzle[i][j]: dup[i][j]=True for i in range(9): for j in range(9): if dup[i][j]: print("*",end="") else : print("",end="") print(puzzle[i][j],end="") print() st=False ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var st : boolean := true ; for _anon : Integer.subrange(0, n-1) do ( if st = false then ( execute (->display() ) else skip ; var puzzle : Sequence := Sequence{} ; for i : Integer.subrange(0, 9-1) do ( var row : Sequence := input().split("")->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; execute ((row) : puzzle)) ; var dup : Sequence := Integer.subrange(0, 9-1)->select(j | true)->collect(j | (Integer.subrange(0, 9-1)->select(i | true)->collect(i | (false)))) ; for i : Integer.subrange(0, 9-1) do ( for j : Integer.subrange(0, 9-1) do ( for k : Integer.subrange(0, 9-1) do ( if i /= k & puzzle[i+1][j+1] = puzzle[k+1][j+1] then ( dup[i+1][j+1] := true ) else skip ; if j /= k & puzzle[i+1][j+1] = puzzle[i+1][k+1] then ( dup[i+1][j+1] := true ) else skip) ; for p : Integer.subrange(0, 3-1) do ( for q : Integer.subrange(0, 3-1) do ( var x : int := (i div 3) * 3 + p ; var y : int := (j div 3) * 3 + q ; if (x = i & y = j) then ( continue ) else skip ; if puzzle[x+1][y+1] = puzzle[i+1][j+1] then ( dup[i+1][j+1] := true ) else skip)))) ; for i : Integer.subrange(0, 9-1) do ( for j : Integer.subrange(0, 9-1) do ( if dup[i+1][j+1] then ( execute ("*")->display() ) else ( execute ("")->display() ) ; execute (puzzle[i+1][j+1])->display()) ; execute (->display()) ; st := false); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): board=[] check=[[0 for a in range(9)]for b in range(9)] for j in range(9): board.append(list(map(int,input().split()))) board_r=[list(x)for x in zip(*board)] for j in range(9): for k in range(9): if board[j].count(board[j][k])>1 : check[j][k]=1 for j in range(9): for k in range(9): if board_r[j].count(board_r[j][k])>1 : check[k][j]=1 for j in range(3): for k in range(3): ch_list=[] for l in range(9): ch_list.append(board[j*3+l % 3][k*3+l//3]) for l in range(9): if ch_list.count(ch_list[l])>1 : check[j*3+l % 3][k*3+l//3]=1 for j in range(9): for k in range(9): if check[j][k]==1 : print("*",end="") else : print("",end="") print(board[j][k],end="") print() if itoInteger() ; for i : Integer.subrange(0, n-1) do ( var board : Sequence := Sequence{} ; var check : Sequence := Integer.subrange(0, 9-1)->select(b | true)->collect(b | (Integer.subrange(0, 9-1)->select(a | true)->collect(a | (0)))) ; for j : Integer.subrange(0, 9-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : board)) ; var board_r : Sequence := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name board)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name board)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name board)))))))`third->at(_indx)} )->select(x | true)->collect(x | ((x))) ; for j : Integer.subrange(0, 9-1) do ( for k : Integer.subrange(0, 9-1) do ( if board[j+1]->count(board[j+1][k+1]) > 1 then ( check[j+1][k+1] := 1 ) else skip)) ; for j : Integer.subrange(0, 9-1) do ( for k : Integer.subrange(0, 9-1) do ( if board_r[j+1]->count(board_r[j+1][k+1]) > 1 then ( check[k+1][j+1] := 1 ) else skip)) ; for j : Integer.subrange(0, 3-1) do ( for k : Integer.subrange(0, 3-1) do ( var ch_list : Sequence := Sequence{} ; for l : Integer.subrange(0, 9-1) do ( execute ((board[j * 3 + l mod 3+1][k * 3 + l div 3+1]) : ch_list)) ; for l : Integer.subrange(0, 9-1) do ( if ch_list->count(ch_list[l+1]) > 1 then ( check[j * 3 + l mod 3+1][k * 3 + l div 3+1] := 1 ) else skip))) ; for j : Integer.subrange(0, 9-1) do ( for k : Integer.subrange(0, 9-1) do ( if check[j+1][k+1] = 1 then ( execute ("*")->display() ) else ( execute ("")->display() ) ; execute (board[j+1][k+1])->display()) ; execute (->display()) ; if (i->compareTo(n - 1)) < 0 then ( execute (->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(n): if n==1 : return 1 if str(n)[-1]=="0" : return 1+f(n-1) s=str(n) k=int("1"+(len(s)-1)*"0") a=-k b=0 for i in range(len(s)): a+=int(s[~ i])*10**i b+=int(s[~ i])*10**min(i,len(s)-i-1) return min(a,b)+f(k) with open("A-large.in")as infile : with open("A.out","w")as outfile : ncases=int(next(infile)) for case in range(1,ncases+1): n=int(next(infile)) print("Case #{}:{}".format(case,f(n)),file=outfile) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; try (var infile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("A-large.in")); try (var outfile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("A.out")); var ncases : int := ("" + (((infile).next())))->toInteger() ; for case : Integer.subrange(1, ncases + 1-1) do ( n := ("" + (((infile).next())))->toInteger() ; execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{case, f(n)}))->display())) catch (_e : OclException) do skip) catch (_e : OclException) do skip; operation f(n : OclAny) : OclAny pre: true post: true activity: if n = 1 then ( return 1 ) else skip ; if OclType["String"](n)->last() = "0" then ( return 1 + f(n - 1) ) else skip ; var s : String := ("" + ((n))) ; var k : int := ("" + (("1" + ((s)->size() - 1) * "0")))->toInteger() ; var a : int := -k ; var b : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( a := a + ("" + ((s[MathLib.bitwiseNot(i)+1])))->toInteger() * (10)->pow(i) ; b := b + ("" + ((s[MathLib.bitwiseNot(i)+1])))->toInteger() * (10)->pow(Set{i, (s)->size() - i - 1}->min())) ; return Set{a, b}->min() + f(k); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from queue import Queue def minsteps(start,goal): if start==goal : return 0 best=int(goal)-int(start) bmedzi='' C=len(start) for cif in range(C): rgoal=goal[: :-1] medzi=start[: C-cif]+rgoal[C-cif :] if medzi[: :-1]>goal : continue toto=int(medzi)-int(start)+1 toto+=int(goal)-int(medzi[: :-1]) if tototoInteger() ; for t : Integer.subrange(1, T + 1-1) do ( goal := input()->trim() ; answer := solve(goal) ; if goal /= '1' then ( goal := ("" + ((("" + ((goal)))->toInteger() - 1))) ; answer := Set{answer, 1 + solve(goal)}->min() ) else skip ; execute (StringLib.interpolateStrings('Case #{}:{}', Sequence{t, answer}))->display()); operation minsteps(start : OclAny, goal : OclAny) : OclAny pre: true post: true activity: if start = goal then ( return 0 ) else skip ; var best : double := ("" + ((goal)))->toInteger() - ("" + ((start)))->toInteger() ; var bmedzi : String := '' ; var C : int := (start)->size() ; for cif : Integer.subrange(0, C-1) do ( var rgoal : OclAny := goal(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var medzi : OclAny := start.subrange(1,C - cif) + rgoal.subrange(C - cif+1) ; if (medzi(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->compareTo(goal)) > 0 then ( continue ) else skip ; var toto : double := ("" + ((medzi)))->toInteger() - ("" + ((start)))->toInteger() + 1 ; toto := toto + ("" + ((goal)))->toInteger() - ("" + ((medzi(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))))->toInteger() ; if (toto->compareTo(best)) < 0 then ( best := toto ; bmedzi := medzi ) else skip) ; return best; operation solve(goal : OclAny) : OclAny pre: true post: true activity: start := '1' ; var answer : int := 1 ; while ((start)->size()->compareTo((goal)->size())) < 0 do ( answer := answer + minsteps(start, StringLib.nCopies('9', (start)->size())) + 1 ; start := start + '0') ; answer := answer + minsteps(start, goal) ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys infile=None outfile=None def readline(): x=infile.readline() if len(x)>0 and x[-1]=='\n' : return x[:-1] else : return x def readint(): return int(readline()) def readfloat(): return float(readline()) def readints(): return[int(x)for x in readline().split()] def readfloats(): return[float(x)for x in readline().split()] def writeline(x): outfile.write(x+'\n') def writecase(casenum,answer): outfile.write('Case #{:d}:{}\n'.format(casenum,answer)) def run(main): global infile,outfile args=sys.argv infile=sys.stdin outfile=sys.stdout if len(args)==2 : if args[1]!='-' : infile=open(args[1],'r') if args[1].endswith('.in'): outfile=open(args[1][:-3]+'.out','w') elif len(args)==3 : if args[1]!='-' : infile=open(args[1],'r') if args[2]!='-' : outfile=open(args[2],'w') elif len(args)>3 : print("Expected 0,1,or 2 arguments,not{}".format(len(args)-1)) print(args) return t=readint() for casenum in range(1,t+1): main(casenum) if infile is not sys.stdin : infile.close() if outfile is not sys.stdout : outfile.close() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute infile : OclAny; attribute outfile : OclAny; operation initialise() pre: true post: true activity: skip ; var infile : OclAny := null ; var outfile : OclAny := null ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip; operation readline() : OclAny pre: true post: true activity: var x : String := infile.readLine() ; if (x)->size() > 0 & x->last() = ' ' then ( return x->front() ) else ( return x ); operation readint() : OclAny pre: true post: true activity: return ("" + ((readline())))->toInteger(); operation readfloat() : OclAny pre: true post: true activity: return ("" + ((readline())))->toReal(); operation readints() : OclAny pre: true post: true activity: return readline().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation readfloats() : OclAny pre: true post: true activity: return readline().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation writeline(x : OclAny) pre: true post: true activity: outfile.write(x + ' '); operation writecase(casenum : OclAny, answer : OclAny) pre: true post: true activity: outfile.write(StringLib.interpolateStrings('Case #{:d}:{} ', Sequence{casenum, answer})); operation run(main : OclAny) pre: true post: true activity: skip; skip ; var args : (trailer . (name argv)) := (trailer . (name argv)) ; infile := OclFile["System.in"] ; outfile := OclFile["System.out"] ; if (args)->size() = 2 then ( if args[1+1] /= '-' then ( infile := OclFile.newOclFile_Write(OclFile.newOclFile(args[1+1])) ; if args[1+1]->hasSuffix('.in') then ( outfile := OclFile.newOclFile_Write(OclFile.newOclFile(args[1+1].subrange(1,-3) + '.out')) ) else skip ) else skip ) else (if (args)->size() = 3 then ( if args[1+1] /= '-' then ( infile := OclFile.newOclFile_Write(OclFile.newOclFile(args[1+1])) ) else skip ; if args[2+1] /= '-' then ( outfile := OclFile.newOclFile_Write(OclFile.newOclFile(args[2+1])) ) else skip ) else (if (args)->size() > 3 then ( execute (StringLib.interpolateStrings("Expected 0,1,or 2 arguments,not{}", Sequence{(args)->size() - 1}))->display() ; execute (args)->display() ; return ) else skip ) ) ; var t : OclAny := readint() ; for casenum : Integer.subrange(1, t + 1-1) do ( main(casenum)) ; if not(infile <>= OclFile["System.in"]) then ( infile.closeFile() ) else skip ; if not(outfile <>= OclFile["System.out"]) then ( outfile.closeFile() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class UnionFind(): def __init__(self,n): self.parent=list(range(n)) self.rank=[0]*n def find(self,x): if self.parent[x]==x : return x else : self.parent[x]=self.find(self.parent[x]) return self.parent[x] def unite(self,x,y): x,y=self.find(x),self.find(y) if x==y : return if self.rank[x]exists( _x | result = _x ); attribute parent : Sequence := (Integer.subrange(0, n-1)); attribute rank : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); operation initialise(n : OclAny) : pre: true post: true activity: self.parent := (Integer.subrange(0, n-1)) ; self.rank := MatrixLib.elementwiseMult(Sequence{ 0 }, n); return self; operation find(x : OclAny) : OclAny pre: true post: true activity: if self.parent[x+1] = x then ( return x ) else ( self.parent[x+1] := self->indexOf(self.parent[x+1]) - 1 ; return self.parent[x+1] ); operation unite(x : OclAny,y : OclAny) pre: true post: true activity: Sequence{x,y} := Sequence{self->indexOf(x) - 1,self->indexOf(y) - 1} ; if x = y then ( return ) else skip ; if (self.rank[x+1]->compareTo(self.rank[y+1])) < 0 then ( self.parent[x+1] := y ) else ( self.parent[y+1] := x ; if self.rank[x+1] = self.rank[y+1] then ( self.rank[x+1] := self.rank[x+1] + 1 ) else skip ); operation same(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: return self->indexOf(x) - 1 = self->indexOf(y) - 1; } class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( try ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))) ; var tree : UnionFind := (UnionFind.newUnionFind()).initialise(7) ; var nums : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 7) ; for dominoes : input().split() do ( Sequence{x,y} := Sequence{(("" + ((dominoes)))->toInteger() div 10), (("" + ((dominoes)))->toInteger() mod 10)} ; tree.unite(x, y) ; nums[x+1] := nums[x+1] + 1 ; nums[y+1] := nums[y+1] + 1) ; if ((argument (test (logical_test (comparison (expr (atom (name tree)) (trailer . (name same) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x))))))) , (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 7))))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (atom (name nums)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))))->forAll( _x | _x = true ) & ((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name nums))))) (comp_iter if (test (logical_test (comparison (expr (expr (atom (name x))) % (expr (atom (number (integer 2))))))))))))->sum() <= 2 then ( execute ('Yes')->display() ) else ( execute ('No')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout,stderr import collections best={} def precompute(): best[1]=1 queue=collections.deque([1]) limit=1000000 while queue : i=queue.popleft() d=best[i] if d>limit : break if i+1 not in best and i+1<=limit*10 : best[i+1]=d+1 queue.append(i+1) rev=int("".join(reversed(str(i)))) if rev not in best and rev<=limit*10 : best[rev]=d+1 queue.append(rev) def solve(N): return best[N] def main(): T=int(input()) for case in range(1,T+1): N=int(input()) answer=solve(N) print("Case #%d: %s" %(case,answer)) precompute() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var best : OclAny := Set{} ; skip ; skip ; skip ; precompute() ; main(); operation precompute() pre: true post: true activity: best[1+1] := 1 ; var queue : Sequence := (Sequence{ 1 }) ; var limit : int := 1000000 ; while queue do ( var i : OclAny := queue->first() ; queue := queue->tail() ; var d : OclAny := best[i+1] ; if (d->compareTo(limit)) > 0 then ( break ) else skip ; if (best)->excludes(i + 1) & (i + 1->compareTo(limit * 10)) <= 0 then ( best[i + 1+1] := d + 1 ; execute ((i + 1) : queue) ) else skip ; var rev : int := ("" + ((StringLib.sumStringsWithSeparator(((("" + ((i))))->reverse()), ""))))->toInteger() ; if (best)->excludes(rev) & (rev->compareTo(limit * 10)) <= 0 then ( best[rev+1] := d + 1 ; execute ((rev) : queue) ) else skip); operation solve(N : OclAny) : OclAny pre: true post: true activity: return best[N+1]; operation main() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for case : Integer.subrange(1, T + 1-1) do ( N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var answer : OclAny := solve(N) ; execute (StringLib.format("Case #%d: %s",Sequence{case, answer}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from fractions import gcd def debug(*args): print(*args,file=sys.stderr) def reverse(nr): return int(str(nr)[: :-1]) fin=sys.stdin T=int(fin.readline()) for case in range(1,T+1): n=int(fin.readline()) count=0 while n>0 : digits=str(n) halfcount=(len(digits)+1)//2 rev=reverse(n) mod=n %(10**halfcount) if mod==1 and n!=rev : n=rev count+=1 elif mod<=1 : n-=1 count+=1 else : n-=(mod-1) count+=(mod-1) print("Case #%d: %s" %(case,count)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var fin : OclFile := OclFile["System.in"] ; var T : int := ("" + ((fin.readLine())))->toInteger() ; for case : Integer.subrange(1, T + 1-1) do ( var n : int := ("" + ((fin.readLine())))->toInteger() ; var count : int := 0 ; while n > 0 do ( var digits : String := ("" + ((n))) ; var halfcount : int := ((digits)->size() + 1) div 2 ; var rev : OclAny := reverse(n) ; var mod : int := n mod ((10)->pow(halfcount)) ; if mod = 1 & n /= rev then ( n := rev ; count := count + 1 ) else (if mod <= 1 then ( n := n - 1 ; count := count + 1 ) else ( n := n - (mod - 1) ; count := count + (mod - 1) ) ) ) ; execute (StringLib.format("Case #%d: %s",Sequence{case, count}))->display()); operation debug(args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) execute ((argument * (test (logical_test (comparison (expr (atom (name args))))))))->display(); operation reverse(nr : OclAny) : OclAny pre: true post: true activity: return ("" + ((OclType["String"](nr)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left,bisect_right from collections import Counter,defaultdict,deque,OrderedDict from copy import deepcopy from fractions import gcd from functools import lru_cache,reduce from math import ceil,floor from sys import setrecursionlimit import heapq import itertools import operator inf=float('inf') N=0 K=0 A,B=[],[] C,D=[],[] def set_inputs(): global N,K,A,B,C,D N=get_int() K=get_int() A,B=get_data(K,[int,int]) C=[min(a,N-a+1)for a in A] D=[min(b,N-b+1)for b in B] return def main(): setrecursionlimit(100000) set_inputs() for c,d in zip(C,D): ans=min(c,d)% 3 if ans==0 : ans=3 print(ans) return def get_int(): return int(input()) def get_float(): return float(input()) def get_str(): return input().strip() def get_li(): return[int(i)for i in input().split()] def get_lf(): return[float(f)for f in input().split()] def get_lc(): return list(input().strip()) def get_data(n,types,sep=None): if len(types)==1 : return[types[0](input())for _ in range(n)] return list(zip(*([t(x)for t,x in zip(types,input().split(sep=sep))]for _ in range(n)))) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute N : OclAny; attribute K : OclAny; attribute A : OclAny; attribute B : OclAny; attribute C : OclAny; attribute D : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; var N : int := 0 ; var K : int := 0 ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := Sequence{Sequence{},Sequence{}} ; var C : OclAny := null; var D : OclAny := null; Sequence{C,D} := Sequence{Sequence{},Sequence{}} ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation set_inputs() pre: true post: true activity: skip; skip; skip; skip; skip; skip ; N := get_int() ; K := get_int() ; Sequence{A,B} := get_data(K, Sequence{OclType["int"]}->union(Sequence{ OclType["int"] })) ; C := A->select(a | true)->collect(a | (Set{a, N - a + 1}->min())) ; D := B->select(b | true)->collect(b | (Set{b, N - b + 1}->min())) ; return; operation main() pre: true post: true activity: setrecursionlimit(100000) ; set_inputs() ; for _tuple : Integer.subrange(1, C->size())->collect( _indx | Sequence{C->at(_indx), D->at(_indx)} ) do (var _indx : int := 1; var c : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); var ans : int := Set{c, d}->min() mod 3 ; if ans = 0 then ( ans := 3 ) else skip ; execute (ans)->display()) ; return; operation get_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation get_float() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation get_str() : OclAny pre: true post: true activity: return input()->trim(); operation get_li() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation get_lf() : OclAny pre: true post: true activity: return input().split()->select(f | true)->collect(f | (("" + ((f)))->toReal())); operation get_lc() : OclAny pre: true post: true activity: return (input()->trim()); operation get_data(n : OclAny, types : OclAny, sep : OclAny) : OclAny pre: true post: true activity: if sep->oclIsUndefined() then sep := null else skip; if (types)->size() = 1 then ( return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (types->first()((OclFile["System.in"]).readLine()))) ) else skip ; return (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name t)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name t))) , (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name types))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sep)))))) = (test (logical_test (comparison (expr (atom (name sep)))))))) ))))))))) )))))))) ]))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name t)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name t))) , (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name types))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sep)))))) = (test (logical_test (comparison (expr (atom (name sep)))))))) ))))))))) )))))))) ]))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name t)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name t))) , (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name types))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sep)))))) = (test (logical_test (comparison (expr (atom (name sep)))))))) ))))))))) )))))))) ]))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))`third->at(_indx)} )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,a=int(input()),[int(i)for i in input().split()][: 2] res=list(range(1,len(a)+1))if sum(a)& 1==0 else[next((i+1 for i,e in enumerate(a)if e & 1==0),-1)] if res!=[-1]: print(len(res)) print(*res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())).subrange(1,2)} ; var res : Sequence := if MathLib.bitwiseAnd((a)->sum(), 1) = 0 then (Integer.subrange(1, (a)->size() + 1-1)) else Sequence{ (Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name e)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (expr (atom (name e))) & (expr (atom (number (integer 1)))))) == (comparison (expr (atom (number (integer 0)))))))))))}, -1).next() } endif ; if res /= Sequence{ -1 } then ( execute ((res)->size())->display() ) else skip ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) a=[*map(int,input().split())] t=1 for j in range(n): if a[j]% 2==0 : t=0 print(1,"\n",j+1) break if t : print(-1 if n==1 else "2\n1 2") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : int := 1 ; for j : Integer.subrange(0, n-1) do ( if a[j+1] mod 2 = 0 then ( t := 0 ; execute (1)->display() ; break ) else skip) ; if t then ( execute (if n = 1 then -1 else "2\n1 2" endif)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): input() li=[int(i)for i in input().split()] if len(li)==1 and sum(li)% 2==1 : print(-1) continue odds=[] even=[] counter=0 while len(odds)!=2 and len(even)==0 : temp=li[counter] even.append(temp)if temp % 2==0 else odds.append(temp) counter+=1 if len(even)>0 : print(1) print(li.index(even[0])+1) else : print(2) first=li.index(odds[0]) li[first]=-1 second=li.index(odds[1]) print(first+1,second+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( input() ; var li : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if (li)->size() = 1 & (li)->sum() mod 2 = 1 then ( execute (-1)->display() ; continue ) else skip ; var odds : Sequence := Sequence{} ; var even : Sequence := Sequence{} ; var counter : int := 0 ; while (odds)->size() /= 2 & (even)->size() = 0 do ( var temp : OclAny := li[counter+1] ; (test (logical_test (comparison (expr (atom (name even)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name temp)))))))) )))))) if (logical_test (comparison (comparison (expr (expr (atom (name temp))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 0))))))) else (test (logical_test (comparison (expr (atom (name odds)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name temp)))))))) )))))))) ; counter := counter + 1) ; if (even)->size() > 0 then ( execute (1)->display() ; execute (li->indexOf(even->first()) - 1 + 1)->display() ) else ( execute (2)->display() ; var first : int := li->indexOf(odds->first()) - 1 ; li[first+1] := -1 ; var second : int := li->indexOf(odds[1+1]) - 1 ; execute (first + 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in[0]*int(input()): n=input() a=[*map(int,input().split())] if a[0]% 2==0 : print('1\n1') elif n=='1' : print(-1) elif a[1]% 2==0 : print('1\n2') else : print('2\n1 2') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var n : String := (OclFile["System.in"]).readLine() ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a->first() mod 2 = 0 then ( execute ('1 1')->display() ) else (if n = '1' then ( execute (-1)->display() ) else (if a[1+1] mod 2 = 0 then ( execute ('1 2')->display() ) else ( execute ('2 1 2')->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def highest_score(): n=input() m=input().split(' ') l=len(m) for i in range(l): if int(m[i])% 2==0 : print(1) print(i+1) return 0 for i in range(l): for o in range(l): if i!=o : if(int(m[i])+int(m[o]))% 2==0 : print(2) print(i+1,o+1) return 0 print(-1) row=int(input()) for r in range(row): highest_score() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var row : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for r : Integer.subrange(0, row-1) do ( highest_score()); operation highest_score() : OclAny pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var m : OclAny := input().split(' ') ; var l : int := (m)->size() ; for i : Integer.subrange(0, l-1) do ( if ("" + ((m[i+1])))->toInteger() mod 2 = 0 then ( execute (1)->display() ; execute (i + 1)->display() ; return 0 ) else skip) ; for i : Integer.subrange(0, l-1) do ( for o : Integer.subrange(0, l-1) do ( if i /= o then ( if (("" + ((m[i+1])))->toInteger() + ("" + ((m[o+1])))->toInteger()) mod 2 = 0 then ( execute (2)->display() ; execute (i + 1)->display() ; return 0 ) else skip ) else skip)) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def commonWords(S): has=defaultdict(lambda : False) ans=[] m=len(S) i=0 while idisplay() ) else skip; operation commonWords(S : OclAny) : OclAny pre: true post: true activity: var has : OclAny := defaultdict(lambda $$ : OclAny in (false)) ; var ans : Sequence := Sequence{} ; var m : int := (S)->size() ; var i : int := 0 ; while (i->compareTo((S->first())->size())) < 0 do ( var string : String := "" ; while (i->compareTo((S->first())->size())) < 0 & S->first()[i+1] /= ' ' do ( string := string + S->first()[i+1] ; i := i + 1) ; i := i + 1 ; if string /= "" then ( execute ((Sequence{string}->union(Sequence{ true })) : ans) ) else skip) ; for j : Integer.subrange(1, m-1) do ( execute (has /<: has) ; i := 0 ; while (i->compareTo((S[j+1])->size())) < 0 do ( string := "" ; while (i->compareTo((S[j+1])->size())) < 0 & S[j+1][i+1] /= ' ' do ( string := string + S[j+1][i+1] ; i := i + 1) ; i := i + 1 ; if string /= "" then ( has->at(string) := true ) else skip) ; for k : Integer.subrange(0, (ans)->size()-1) do ( if (ans[k+1][1+1] /= false & has[ans[k+1]->first()+1] = false) then ( ans[k+1][1+1] := false ) else (if (ans[k+1][1+1] /= false & has[ans[k+1]->first()+1] = true) then ( has[ans[k+1]->first()+1] := false ) else skip))) ; var cnt : int := 0 ; for k : Integer.subrange(0, (ans)->size()-1) do ( if ans[k+1][1+1] = true then ( cnt := cnt + 1 ) else skip) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=[int(x)for x in input().split()] sum=0 ; sum2=0 count=0 flag=0 for i in range(1,n): if sum=k : flag=1 break if flag==1 : print(count) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var sum : int := 0; ; var sum2 : int := 0 ; var count : int := 0 ; var flag : int := 0 ; for i : Integer.subrange(1, n-1) do ( if (sum->compareTo(k)) < 0 then ( sum := sum + Set{8, a[i - 1+1]}->min() ; sum2 := (Set{8, a[i - 1+1]}->min() - a[i - 1+1])->abs() ; a[i+1] := a[i+1] + sum2 ; count := count + 1 ) else skip ; if i = n - 1 then ( if (sum->compareTo(k)) < 0 then ( sum := sum + Set{8, a[i+1]}->min() ; count := count + 1 ) else skip ) else skip ; if (sum->compareTo(k)) >= 0 then ( flag := 1 ; break ) else skip) ; if flag = 1 then ( execute (count)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from collections import defaultdict,Counter import sys n,k=map(int,input().split()) l=list(map(int,input().split())) ans=-1 sto=0 for i in range(n): sto+=l[i] k-=min(sto,8) sto-=min(sto,8) if(k<=0): ans=i+1 break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := -1 ; var sto : int := 0 ; for i : Integer.subrange(0, n-1) do ( sto := sto + l[i+1] ; k := k - Set{sto, 8}->min() ; sto := sto - Set{sto, 8}->min() ; if (k <= 0) then ( ans := i + 1 ; break ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : n=int(input()) except : break f,g=[0]*7,[0]*7 p=list(input().split()) for x in p : if x[0]==x[1]: g[int(x[0])]=1 else : f[int(x[0])]+=1 f[int(x[1])]+=1 if n==1 : print("Yes") continue ans=1 for i in range(7): if g[i]and f[i]==0 : ans=0 break if ans : k=0 for i in range(7): if f[i]& 1 : k+=1 ans=(k==0 or k==2) print("Yes" if ans else "No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) catch (_e : OclException) do ( break) ; var f : OclAny := null; var g : OclAny := null; Sequence{f,g} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, 7),MatrixLib.elementwiseMult(Sequence{ 0 }, 7)} ; var p : Sequence := (input().split()) ; for x : p do ( if x->first() = x[1+1] then ( g[("" + ((x->first())))->toInteger()+1] := 1 ) else ( f[("" + ((x->first())))->toInteger()+1] := f[("" + ((x->first())))->toInteger()+1] + 1 ; f[("" + ((x[1+1])))->toInteger()+1] := f[("" + ((x[1+1])))->toInteger()+1] + 1 )) ; if n = 1 then ( execute ("Yes")->display() ; continue ) else skip ; var ans : int := 1 ; for i : Integer.subrange(0, 7-1) do ( if g[i+1] & f[i+1] = 0 then ( ans := 0 ; break ) else skip) ; if ans then ( var k : int := 0 ; for i : Integer.subrange(0, 7-1) do ( if MathLib.bitwiseAnd(f[i+1], 1) then ( k := k + 1 ) else skip) ; ans := (k = 0 or k = 2) ) else skip ; execute (if ans then "Yes" else "No" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=[int(w)for w in input().split()] e=[int(m)for m in input().split()] a=0 l=0 o=0 while l=q[1]: print(o) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : Sequence := input().split()->select(w | true)->collect(w | (("" + ((w)))->toInteger())) ; var e : Sequence := input().split()->select(m | true)->collect(m | (("" + ((m)))->toInteger())) ; var a : int := 0 ; var l : int := 0 ; var o : int := 0 ; while (l->compareTo(q[1+1])) < 0 & (o->compareTo(q->first())) < 0 do ( a := a + e[o+1] ; var tmp : OclAny := Set{8, a}->min() ; a := a - tmp ; l := l + tmp ; o := o + 1) ; if (l->compareTo(q[1+1])) >= 0 then ( execute (o)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) K=int(input()) tile=[tuple(map(int,input().split()))for i in range(K)] if N % 2!=0 : c=int(N/2+0.5) if c % 3==0 : red,blue,yellow=2,1,0 elif c % 3==2 : yellow,red,blue=2,1,0 elif c % 1==1 : blue,yellow,red=2,1,0 for i in range(K): x,y=tile[i] d=max(abs(x-c),abs(y-c)) if d % 3==red : print(1) elif d % 3==blue : print(2) elif d % 3==yellow : print(3) else : c=N/2 if c % 3==0 : red,blue,yellow=2,1,0 elif c % 3==2 : yellow,red,blue=2,1,0 elif c % 1==0 : blue,yellow,red=2,1,0 c+=0.5 for i in range(K): x,y=tile[i] d=max(int(abs(x-c)-0.5),int(abs(y-c)-0.5)) if d % 3==red : print(1) elif d % 3==blue : print(2) elif d % 3==yellow : print(3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var tile : Sequence := Integer.subrange(0, K-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; if N mod 2 /= 0 then ( var c : int := ("" + ((N / 2 + 0.5)))->toInteger() ; if c mod 3 = 0 then ( var red : OclAny := null; var blue : OclAny := null; var yellow : OclAny := null; Sequence{red,blue,yellow} := Sequence{2,1,0} ) else (if c mod 3 = 2 then ( var yellow : OclAny := null; var red : OclAny := null; var blue : OclAny := null; Sequence{yellow,red,blue} := Sequence{2,1,0} ) else (if c mod 1 = 1 then ( var blue : OclAny := null; var yellow : OclAny := null; var red : OclAny := null; Sequence{blue,yellow,red} := Sequence{2,1,0} ) else skip ) ) ; for i : Integer.subrange(0, K-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := tile[i+1] ; var d : OclAny := Set{(x - c)->abs(), (y - c)->abs()}->max() ; if d mod 3 = red then ( execute (1)->display() ) else (if d mod 3 = blue then ( execute (2)->display() ) else (if d mod 3 = yellow then ( execute (3)->display() ) else skip ) ) ) ) else ( c := N / 2 ; if c mod 3 = 0 then ( var red : OclAny := null; var blue : OclAny := null; var yellow : OclAny := null; Sequence{red,blue,yellow} := Sequence{2,1,0} ) else (if c mod 3 = 2 then ( var yellow : OclAny := null; var red : OclAny := null; var blue : OclAny := null; Sequence{yellow,red,blue} := Sequence{2,1,0} ) else (if c mod 1 = 0 then ( var blue : OclAny := null; var yellow : OclAny := null; var red : OclAny := null; Sequence{blue,yellow,red} := Sequence{2,1,0} ) else skip ) ) ; c := c + 0.5 ; for i : Integer.subrange(0, K-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := tile[i+1] ; d := Set{("" + (((x - c)->abs() - 0.5)))->toInteger(), ("" + (((y - c)->abs() - 0.5)))->toInteger()}->max() ; if d mod 3 = red then ( execute (1)->display() ) else (if d mod 3 = blue then ( execute (2)->display() ) else (if d mod 3 = yellow then ( execute (3)->display() ) else skip ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=list(map(int,input().split())) got=0 for i in range(n): got+=a[i] k-=min(got,8) got-=min(got,8) if k<=0 : print(i+1) break if k>0 : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var got : int := 0 ; for i : Integer.subrange(0, n-1) do ( got := got + a[i+1] ; k := k - Set{got, 8}->min() ; got := got - Set{got, 8}->min() ; if k <= 0 then ( execute (i + 1)->display() ; break ) else skip) ; if k > 0 then ( execute (-1)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=list(map(int,input().split())) k1=0 k2=0 d=0 while k2=k : print(d) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k1 : int := 0 ; var k2 : int := 0 ; var d : int := 0 ; while (k2->compareTo(k)) < 0 & (d->compareTo(n)) < 0 do ( k1 := k1 + a[d+1] ; var tmp : OclAny := Set{8, k1}->min() ; k1 := k1 - tmp ; k2 := k2 + tmp ; d := d + 1) ; if (k2->compareTo(k)) >= 0 then ( execute (d)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfTheSeries(n): sum=0 for i in range(1,n+1): k=1 for j in range(1,i+1): sum+=k k+=2 return sum n=5 print("Sum=",sumOfTheSeries(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; execute ("Sum=")->display(); operation sumOfTheSeries(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( var k : int := 1 ; for j : Integer.subrange(1, i + 1-1) do ( sum := sum + k ; k := k + 2)) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def findSum(arr,N): mp=dict() for i in arr : if i in mp.keys(): mp[i]+=1 else : mp[i]=1 minFreq=10**9 for itr in mp : if mp[itr]union(Sequence{20}->union(Sequence{30}->union(Sequence{40}->union(Sequence{ 40 })))) ; N := (arr)->size() ; execute (findSum(arr, N))->display(); operation findSum(arr : OclAny, N : OclAny) : OclAny pre: true post: true activity: var mp : Map := (arguments ( )) ; for i : arr do ( if (mp.keys())->includes(i) then ( mp[i+1] := mp[i+1] + 1 ) else ( mp[i+1] := 1 )) ; var minFreq : double := (10)->pow(9) ; for itr : mp->keys() do ( if (mp[itr+1]->compareTo(minFreq)) < 0 then ( minFreq := mp[itr+1] ) else skip) ; var Sum : int := 0 ; for itr : mp->keys() do ( if mp[itr+1] = minFreq then ( Sum := Sum + itr * mp[itr+1] ) else skip) ; return Sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPowerOfTwo(n): return(n and(not(n &(n-1)))) def previousPowerOfTwo(n): while(n & n-1): n=n & n-1 return n def checkSum(n): if(n==0 or n==1): return False elif(isPowerOfTwo(n)): print(n//2,n//2) return True else : x=previousPowerOfTwo(n) y=n-x ; if(isPowerOfTwo(y)): print(x,y) return True else : return False n1=20 if(checkSum(n1)): print("No") n2=11 if(checkSum(n2)): print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var n1 : int := 20 ; if (checkSum(n1)) then ( execute ("No")->display() ) else skip ; var n2 : int := 11 ; if (checkSum(n2)) then ( execute ("No")->display() ) else skip; operation isPowerOfTwo(n : OclAny) : OclAny pre: true post: true activity: return (n & (not((MathLib.bitwiseAnd(n, (n - 1)))))); operation previousPowerOfTwo(n : OclAny) : OclAny pre: true post: true activity: while (MathLib.bitwiseAnd(n, n - 1)) do ( n := MathLib.bitwiseAnd(n, n - 1)) ; return n; operation checkSum(n : OclAny) : OclAny pre: true post: true activity: if (n = 0 or n = 1) then ( return false ) else (if (isPowerOfTwo(n)) then ( execute (n div 2)->display() ; return true ) else ( var x : OclAny := previousPowerOfTwo(n) ; var y : double := n - x; ; if (isPowerOfTwo(y)) then ( execute (x)->display() ; return true ) else ( return false ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSubarrays(arr,n,k): start=0 end=0 count=0 sum=arr[0] while(start=start): count+=end-start if(endunion(Sequence{11}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 15 })))) ; k := 10 ; var size : int := (array)->size() ; execute (countSubarrays(array, size, k))->display() ) else skip; operation countSubarrays(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var start : int := 0 ; var end : int := 0 ; var count : int := 0 ; var sum : OclAny := arr->first() ; while ((start->compareTo(n)) < 0 & (end->compareTo(n)) < 0) do ( if ((sum->compareTo(k)) < 0) then ( end := end + 1 ; if ((end->compareTo(start)) >= 0) then ( count := count + end - start ) else skip ; if ((end->compareTo(n)) < 0) then ( sum := sum + arr[end+1] ) else skip ) else ( sum := sum - arr[start+1] ; start := start + 1 )) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) l=list(map(int,input().split())) mn=10000000000 idx=0 for i in range(k): x=0 for j in range(i,n,k): x+=l[j] if xcollect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mn : int := 10000000000 ; var idx : int := 0 ; for i : Integer.subrange(0, k-1) do ( var x : int := 0 ; for j : Integer.subrange(i, n-1)->select( $x | ($x - i) mod k = 0 ) do ( x := x + l[j+1]) ; if (x->compareTo(mn)) < 0 then ( idx := i; mn := x ) else skip) ; execute (idx + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) l=list(map(int,input().split())) r=100000000000 for i in range(n): if l[i]==0 : break ; j=i sum=0 while jsum): idx=i r=sum print(idx+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var r : int := 100000000000 ; for i : Integer.subrange(0, n-1) do ( if l[i+1] = 0 then ( break; ) else skip ; var j : OclAny := i ; var sum : int := 0 ; while (j->compareTo(n)) < 0 do ( sum := sum + l[j+1] ; l[j+1] := 0 ; j := j + k) ; if ((r->compareTo(sum)) > 0) then ( var idx : OclAny := i ; r := sum ) else skip) ; execute (idx + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): rems={} for i in range(k): rems[i]=0 for i in range(n): rems[i % k]+=arr[i] mn=10000000000 ans=0 for i in rems : if mn>rems[i]: mn=rems[i] ans=i+1 return ans from sys import stdin input=stdin.readline n,k=[int(x)for x in input().split()] arr=[int(x)for x in input().split()] print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var arr : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (solve())->display(); operation solve() : OclAny pre: true post: true activity: var rems : OclAny := Set{} ; for i : Integer.subrange(0, k-1) do ( rems[i+1] := 0) ; for i : Integer.subrange(0, n-1) do ( rems[i mod k+1] := rems[i mod k+1] + arr[i+1]) ; var mn : int := 10000000000 ; var ans : int := 0 ; for i : rems do ( if (mn->compareTo(rems[i+1])) > 0 then ( mn := rems[i+1] ; ans := i + 1 ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n): return " ".join(str(s)for s in range(1,n+1)) if __name__=="__main__" : t=int(input()) for i in range(0,t): n=int(input()) print(solve(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (solve(n))->display()) ) else skip; operation solve(n : OclAny) : OclAny pre: true post: true activity: return StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) ))))))))), " "); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def find_color(n,ai,bi): color=(3,1,2) if n % 2!=0 : if ai>int((n+1)/2): ai=int((n+1)/2)-(ai-int((n+1)/2)) if bi>int((n+1)/2): bi=int((n+1)/2)-(bi-int((n+1)/2)) else : if ai>int(n/2): ai=int(n/2)-(ai-int(n/2))+1 if bi>int(n/2): bi=int(n/2)-(bi-int(n/2))+1 if bi>=ai and bi<=n-ai : return color[ai % 3] else : return color[bi % 3] n=int(sys.stdin.readline()) k=int(sys.stdin.readline()) for i in range(0,k): ai,bi=(int(x)for x in sys.stdin.readline().split()) print(find_color(n,ai,bi)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, k-1) do ( Sequence{ai,bi} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin)) (trailer . (name readline) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; execute (find_color(n, ai, bi))->display()); operation find_color(n : OclAny, ai : OclAny, bi : OclAny) : OclAny pre: true post: true activity: var color : OclAny := Sequence{3, 1, 2} ; if n mod 2 /= 0 then ( if (ai->compareTo(("" + (((n + 1) / 2)))->toInteger())) > 0 then ( ai := ("" + (((n + 1) / 2)))->toInteger() - (ai - ("" + (((n + 1) / 2)))->toInteger()) ) else skip ; if (bi->compareTo(("" + (((n + 1) / 2)))->toInteger())) > 0 then ( bi := ("" + (((n + 1) / 2)))->toInteger() - (bi - ("" + (((n + 1) / 2)))->toInteger()) ) else skip ) else ( if (ai->compareTo(("" + ((n / 2)))->toInteger())) > 0 then ( ai := ("" + ((n / 2)))->toInteger() - (ai - ("" + ((n / 2)))->toInteger()) + 1 ) else skip ; if (bi->compareTo(("" + ((n / 2)))->toInteger())) > 0 then ( bi := ("" + ((n / 2)))->toInteger() - (bi - ("" + ((n / 2)))->toInteger()) + 1 ) else skip ) ; if (bi->compareTo(ai)) >= 0 & (bi->compareTo(n - ai)) <= 0 then ( return color[ai mod 3+1] ) else ( return color[bi mod 3+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,k=map(int,input().split()) w=list(map(int,input().split())) if k>n/2 : print(w.index(min(w))+1) else : d=[1e9,-1] for i in range(k): c=0 for j in range(i,n,k): c+=w[j] if ccollect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (k->compareTo(n / 2)) > 0 then ( execute (w->indexOf((w)->min()) - 1 + 1)->display() ) else ( var d : Sequence := Sequence{("1e9")->toReal()}->union(Sequence{ -1 }) ; for i : Integer.subrange(0, k-1) do ( var c : int := 0 ; for j : Integer.subrange(i, n-1)->select( $x | ($x - i) mod k = 0 ) do ( c := c + w[j+1]) ; if (c->compareTo(d->first())) < 0 then ( d := Sequence{c}->union(Sequence{ i + 1 }) ) else skip) ; execute (d[1+1])->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) l=list(map(int,input().split())) mn=10000000000 idx=0 for i in range(n): if l[i]==0 : break j=i x=0 while jcollect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mn : int := 10000000000 ; var idx : int := 0 ; for i : Integer.subrange(0, n-1) do ( if l[i+1] = 0 then ( break ) else skip ; var j : OclAny := i ; var x : int := 0 ; while (j->compareTo(n)) < 0 do ( x := x + l[j+1] ; l[j+1] := 0 ; j := j + k) ; if (x->compareTo(mn)) < 0 then ( idx := i ; mn := x ) else skip) ; execute (idx + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def KnapSack(val,wt,n,W): mat=[[0 for i in range(W+1)]for i in range(2)] i=0 while iunion(Sequence{8}->union(Sequence{ 4 })) ; wt := Sequence{3}->union(Sequence{8}->union(Sequence{ 6 })) ; W := 10 ; n := 3 ; execute (KnapSack(val, wt, n, W))->display(); operation KnapSack(val : OclAny, wt : OclAny, n : OclAny, W : OclAny) : OclAny pre: true post: true activity: var mat : Sequence := Integer.subrange(0, 2-1)->select(i | true)->collect(i | (Integer.subrange(0, W + 1-1)->select(i | true)->collect(i | (0)))) ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( var j : int := 0 ; if i mod 2 = 0 then ( while (j->compareTo(W)) < 0 do ( j := j + 1 ; if (wt[i+1]->compareTo(j)) <= 0 then ( mat[1+1][j+1] := Set{val[i+1] + mat->first()[j - wt[i+1]+1], mat->first()[j+1]}->max() ) else ( mat[1+1][j+1] := mat->first()[j+1] )) ) else ( while (j->compareTo(W)) < 0 do ( j := j + 1 ; if (wt[i+1]->compareTo(j)) <= 0 then ( mat->first()[j+1] := Set{val[i+1] + mat[1+1][j - wt[i+1]+1], mat[1+1][j+1]}->max() ) else ( mat->first()[j+1] := mat[1+1][j+1] )) ) ; i := i + 1) ; if n mod 2 = 0 then ( return mat->first()[W+1] ) else ( return mat[1+1][W+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ha,hb=map(int,input().split()) ka,kb=map(int,input().split()) a,b,c,d=map(int,input().split()) ht,kt=0,0 ht=ha*a+hb*b+(ha//10)*c+(hb//20)*d kt=ka*a+kb*b+(ka//10)*c+(kb//20)*d if ht>kt : print("hiroshi") elif htcollect( _x | (OclType["int"])->apply(_x) ) ; var ka : OclAny := null; var kb : OclAny := null; Sequence{ka,kb} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ht : OclAny := null; var kt : OclAny := null; Sequence{ht,kt} := Sequence{0,0} ; var ht : double := ha * a + hb * b + (ha div 10) * c + (hb div 20) * d ; var kt : double := ka * a + kb * b + (ka div 10) * c + (kb div 20) * d ; if (ht->compareTo(kt)) > 0 then ( execute ("hiroshi")->display() ) else (if (ht->compareTo(kt)) < 0 then ( execute ("kenjiro")->display() ) else (if ht = kt then ( execute ("even")->display() ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h1,h2=map(int,input().split()) k1,k2=map(int,input().split()) a,b,c,d=map(int,input().split()) def f(x,y): return a*x+b*y+c*(x//10)+d*(y//20) H,K=f(h1,h2),f(k1,k2) ans='even' if H>K : ans='hiroshi' elif Hcollect( _x | (OclType["int"])->apply(_x) ) ; var k1 : OclAny := null; var k2 : OclAny := null; Sequence{k1,k2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; var H : OclAny := null; var K : OclAny := null; Sequence{H,K} := Sequence{f(h1, h2),f(k1, k2)} ; var ans : String := 'even' ; if (H->compareTo(K)) > 0 then ( ans := 'hiroshi' ) else (if (H->compareTo(K)) < 0 then ( ans := 'kenjiro' ) else skip) ; execute (ans)->display(); operation f(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return a * x + b * y + c * (x div 10) + d * (y div 20); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy from test.support import _MemoryWatchdog BIG_NUM=2000000000 HUGE_NUM=99999999999999999 MOD=1000000007 EPS=0.000000001 sys.setrecursionlimit(100000) h1,h2=map(int,input().split()) k1,k2=map(int,input().split()) a,b,c,d=map(int,input().split()) A=a*h1+(h1//10)*c+b*h2+(h2//20)*d B=a*k1+(k1//10)*c+b*k2+(k2//20)*d if A>B : print("hiroshi") elif Acollect( _x | (OclType["int"])->apply(_x) ) ; var k1 : OclAny := null; var k2 : OclAny := null; Sequence{k1,k2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : double := a * h1 + (h1 div 10) * c + b * h2 + (h2 div 20) * d ; var B : double := a * k1 + (k1 div 10) * c + b * k2 + (k2 div 20) * d ; if (A->compareTo(B)) > 0 then ( execute ("hiroshi")->display() ) else (if (A->compareTo(B)) < 0 then ( execute ("kenjiro")->display() ) else ( execute ("even")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h1,h2=list(map(int,input().split())) k1,k2=list(map(int,input().split())) a,b,c,d=list(map(int,input().split())) hiro=h1*a+h2*b+(h1//10)*c+(h2//20)*d ken=k1*a+k2*b+(k1//10)*c+(k2//20)*d if hiro>ken : print('hiroshi') elif ken>hiro : print('kenjiro') else : print('even') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h1 : OclAny := null; var h2 : OclAny := null; Sequence{h1,h2} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k1 : OclAny := null; var k2 : OclAny := null; Sequence{k1,k2} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var hiro : double := h1 * a + h2 * b + (h1 div 10) * c + (h2 div 20) * d ; var ken : double := k1 * a + k2 * b + (k1 div 10) * c + (k2 div 20) * d ; if (hiro->compareTo(ken)) > 0 then ( execute ('hiroshi')->display() ) else (if (ken->compareTo(hiro)) > 0 then ( execute ('kenjiro')->display() ) else ( execute ('even')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- [h1,h2]=[int(num)for num in input().split()] [k1,k2]=[int(num)for num in input().split()] [a,b,c,d]=[int(num)for num in input().split()] counth=a*h1+b*h2+c*(h1//10)+d*(h2//20) countk=a*k1+b*k2+c*(k1//10)+d*(k2//20) if(counth>countk): print('hiroshi') elif(counthunion(Sequence{ h2 }) := input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; Sequence{k1}->union(Sequence{ k2 }) := input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; Sequence{a}->union(Sequence{b}->union(Sequence{c}->union(Sequence{ d }))) := input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var counth : double := a * h1 + b * h2 + c * (h1 div 10) + d * (h2 div 20) ; var countk : double := a * k1 + b * k2 + c * (k1 div 10) + d * (k2 div 20) ; if ((counth->compareTo(countk)) > 0) then ( execute ('hiroshi')->display() ) else (if ((counth->compareTo(countk)) < 0) then ( execute ('kenjiro')->display() ) else ( execute ('even')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) count=0 for i in range(1,N): count+=(N-1)//i print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := 0 ; for i : Integer.subrange(1, N-1) do ( count := count + (N - 1) div i) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import base64 import subprocess import zlib exe_bin="c%1E9e{dUhcK_;!V|iJLVcAl$;^f2^JCIVsMwaAQM3!7>6&xl&I3?lsj3C@FG@YYu+H0?2rc=1~u4OtmhfTN`ZrU3|OPdys3s;~Lg-HT5I3bDp-gm!WX?LwX?r!=|XY%#fZ{KI%d;7lc`@Y}Z{qFN4fzT$i$wYXwkgpQtjxAL9ZidgSDT@HsLFU8X8_04p4|uCePETh|T52m_N73srE4-dwPqfseqBX?04K!*gA+E9>`r5i&L0gx*G_=63J7(|F=$V5{^>mPEDcAct=*=U)eseOqja|v*T;VJJzpR-{#4rJZq^>PA0o~%XTV{<84;?+{iFIf2w)cBJuLk3*Ts~`|Q#Ezv%kP+lBkhOoopeM%Vj~G{Bt(b~YN|e{JB;3b5Zmt|i?rMa#(&@Gpph@48XJn|NYEUS_0dWYsFn#q~rKcaNr$Vnzz5B~c_|aIjB|#?rCf@r)Ep5BBvYQpwn0cqkE5&Q(8i&z6CBIuqCyr-!LTCV)o+Qd=w;O#~wYlGhs<38zIV9ga(xU?dRO2H3ixa3&rRQyD283y%f|#lcoFFtA>vs_P>0B()}W#8Vj&L}P8iWL)xl1A76FCi?g4PJ7!k`;rmyfw(jR{fWj?fg$YP__#P0OJ`Eaa3U`46Zf`)TJnL>YPNe7+u(O3m6b45yCV@XgOTzQaeMNCcrq$(i)FH-F+3UJA%y5f_K1;@J>qaUo&X>+9u~t=Y&lAp$4$y1EAvVLxVTKX~`CV*M@Sv&-W1apn4PS>H_8D88Ql^YeRZaK-v5lb2e)Z9{L~Wb%An<@bqWc7=B6@Ll}=tH+tV&85XTKhvzxd8D%5Vmqb6?JE4V3U{jTf(ma?;b&F2dcMx8@M~1Kllg_+uUFxGKI6T-QHAsQjQC;|KE~|VlFB^@+qeq1sPF?S+^WLAslwII5l2+G`aXJ8h1aU^V=COH!jG%)`6~Pc6}~`)zo^3NRQRL{U#P-gRpAa5F62J42@^Gom$-;jc2^C1-vDUs}MO6@V@7pSbccd(F_lD@+n{L71JMne%UAgL^$f(xcaalpOA{e#(KBo;Gck|+~SwRRv|ZK^W`p^vM+@?FGx29^P3T}4tpHU2dR$}9YSu>mcQHNc>X_x&R4T%O!vC4?>khIY$3T+c=!tI06ILe-`&(X>v;0(*el6>J#_fKMi(hO2SS28U1$L6ofP2I%BZlejYi3FXdCt>_e#g_?eyL2+v&T{C!V1FnXtM;Ewh6BG6vEqOkK1Hhu&};{3{G?-nvNWq$g~S!^aVUNZDpF(%^)x@cCst8U(e8Hn(7UIn;SYzSS=eSrz?Y{%)Jl@~?vYi7@q{Mab8`iRs{d1FsvLXj>}CZB8NgvQ6lGJ$ptlO<|C*%gdn4iZ^n-yYLNq5#%Q7-PkKzP@Wb{Cqdg?JPv)O<3K&5*%n6kUMeZAS%64A7AVn(!%jLq3xs;y_2?qV!u;ZIQPO@5oGpA0Rr6hEV7PGF7B@jIDtYAnI4HkBI|k!VtbMT?5dv1j+tNlWzXe=ZjGOcYa7yZA-cT!iy|}?+`jqIv#7sJ{>xreX~zK3oB8;`*Cp-%9i5~>!OhVgQodi1VZ%%gsN4)LJIOMWYXt_#XqfeW9~`Rq;zdMgI~gc8?{lH28%iL}Ho&l7SdVHJ?vO~tR4*g6t|87QAAJVd83o^i9)4i=*m%0LuNuUEh`7&g3sO5cn@1DABDcp`04t*@Syl?UG3&|Hl@_D~}##d^5TgaU-37tRBeu#^NDq)UP#{1I~>{)=`{n_*Bb(W3&M0p;$^m(cDEYN?1OT7a0ZJ?Kc?uTTaft>ph&;*``*%AW&5_I?|P+S8)0{RiqHgn~f&Gg_lVj6dvuB)%L9Wm895y$0G06VKx&nMO832`&|9pKjt3fP^S>`iw%>K?EiAa^X=c`hNt{B~E~+GAh&c#Y5AdU&4C-jS>I+s7=OrUmv6fPD6qJ$4s}f=Z9w7N`?2Ht;(R{ksL{XvJ2bY|CG^wb|Zpe%Zhj!Izmy_`Mfmy&r5@|6Z~8xY=iKI&2Z_uACJNSn9zU7eGF$xTy|jVL!C6m+jBp^>)YD!k}?V1{j)&0y|^K&!##QdxF=B~D@?P|N)uC}Y~YP;J0KQ_K!%lBvbeysZYq?)caY55>K;CrF3vQ0w1$M-L6v-MiW^ZnxM7|-`;modushxv0be>VP~E2R|DqwL|0KbOt0%}~C_ImyoRJ;`^Oe|#^piBa`lEH=K^x`XXU@@GUB)926oe9v?#qsMJpe5_XMcL&qwd#C*RHxR8HJbu&unHY41@uykGN{r`zo@M;su=5ufuihK}zij;bu)dvV9h=7jzJ$?R7+ufkCPwdKbePe-j2>q68AiXS-c$=_3?rB}KE=xJ@!`=>0Yg>zg{yMfTFiIU&zSQE^o58BMg-BI#YdN2_cuhHvwfMYpzH9N?avo@LTRDHU`22F7YVif-eAeQ1<$0~e>&fY=_(JkRmGQF>JDIGCJId>X7I%`&y>sr=k=G4g+!$}b|TtBh|o`8Vm`x%pF|cIJ-nIr_J8j{jzpg6sWUY(hJ8^I;YJe%eHubmP9jg5PoH=E+)GCs4_MKJ9%5^$BAJbs&#Z`O3U|maQvK8QA%Eyso)v&ieU*f&3M~Zv=V%U6d~$pIT6U?z~=Ru5M?I0lwLc{j!r6Sf1R%66?c5`$tYL(5G<9ikXd#glP~MAA}5$_@{EBBWA=BTA!U1j}teT#Tl~-HFstI3Y%*R5~Muv*RR^8XZf-q*&B*`})p~>Oxq25*Neibag+Ub$y=|JpA+75)3hVdAA~2f4_&_)q4+Oloi&&2pP9#zhh;b&CmV$R~gA;+hTRP#A$t;)~2PrX`N{>P+#37Z!XrMnn;1vS_|Jc?+k=0V^I)@cf`u=LGoGSj|xxv0(o*TS;YEHOdaQXP(v!y+i35$E$hqCcR6pOCJp-iT7wpwA9-X1NSie$1hy?8;DE^1Zc-rcP#oGMqV>5TuXDmYCU80fKjEtNw!(aJS!Ro$-Cd(ClpPBork#a)%cIPJxVC$n!<3J(F5(h42nNAV<>93!4&N{V?P9BZWTZpK04c<8vSiAM?LM#7m9;)(7{f<1*wY30mbh;2NT)G#8POUDvn6l6zZ2?;L=yd~U8;``sBvGRM_f*yt#RflyYlcVT5jda*A*+Z7R>x6T#;UE(zj4ET2E29f`-)LrHg6^!e-lyO?YX|b?%Ac2*T0^5b^820kW=@U=;QaV^YCuZ_4)fErz;uG_e1orZ(E46_rdk~dnKp5&KqA7O)7o9PjMH~);ja|Pfp*}1xz2m`-rl4!S(rjDyOS;{+o4l4^j3)IM3f_Ipu{@^O&Fd{y#{Rm~wso-peW9pV7yU_x~W%?_oTDKjze>(qCFd{|Tb5`L67bamx3Rc+-!+tkdW3+nmnm?g`n4wI`udGQuHT}=tL>Xt`=<_p>CdwHgZCj1nY(_>SNX2-lP&!FbqTA_p9TZ{AF+kk`6cW3{{kH-Ur7" open("./kyomu",'wb').write(zlib.decompress(base64.b85decode(exe_bin))) subprocess.run(["chmod+x./kyomu"],shell=True) subprocess.run(["./kyomu"],shell=True) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var exe_bin : String := "c%1E9e{dUhcK_;!V|iJLVcAl$;^f2^JCIVsMwaAQM3!7>6&xl&I3?lsj3C@FG@YYu+H0?2rc=1~u4OtmhfTN`ZrU3|OPdys3s;~Lg-HT5I3bDp-gm!WX?LwX?r!=|XY%#fZ{KI%d;7lc`@Y}Z{qFN4fzT$i$wYXwkgpQtjxAL9ZidgSDT@HsLFU8X8_04p4|uCePETh|T52m_N73srE4-dwPqfseqBX?04K!*gA+E9>`r5i&L0gx*G_=63J7(|F=$V5{^>mPEDcAct=*=U)eseOqja|v*T;VJJzpR-{#4rJZq^>PA0o~%XTV{<84;?+{iFIf2w)cBJuLk3*Ts~`|Q#Ezv%kP+lBkhOoopeM%Vj~G{Bt(b~YN|e{JB;3b5Zmt|i?rMa#(&@Gpph@48XJn|NYEUS_0dWYsFn#q~rKcaNr$Vnzz5B~c_|aIjB|#?rCf@r)Ep5BBvYQpwn0cqkE5&Q(8i&z6CBIuqCyr-!LTCV)o+Qd=w;O#~wYlGhs<38zIV9ga(xU?dRO2H3ixa3&rRQyD283y%f|#lcoFFtA>vs_P>0B()}W#8Vj&L}P8iWL)xl1A76FCi?g4PJ7!k`;rmyfw(jR{fWj?fg$YP__#P0OJ`Eaa3U`46Zf`)TJnL>YPNe7+u(O3m6b45yCV@XgOTzQaeMNCcrq$(i)FH-F+3UJA%y5f_K1;@J>qaUo&X>+9u~t=Y&lAp$4$y1EAvVLxVTKX~`CV*M@Sv&-W1apn4PS>H_8D88Ql^YeRZaK-v5lb2e)Z9{L~Wb%An<@bqWc7=B6@Ll}=tH+tV&85XTKhvzxd8D%5Vmqb6?JE4V3U{jTf(ma?;b&F2dcMx8@M~1Kllg_+uUFxGKI6T-QHAsQjQC;|KE~|VlFB^@+qeq1sPF?S+^WLAslwII5l2+G`aXJ8h1aU^V=COH!jG%)`6~Pc6}~`)zo^3NRQRL{U#P-gRpAa5F62J42@^Gom$-;jc2^C1-vDUs}MO6@V@7pSbccd(F_lD@+n{L71JMne%UAgL^$f(xcaalpOA{e#(KBo;Gck|+~SwRRv|ZK^W`p^vM+@?FGx29^P3T}4tpHU2dR$}9YSu>mcQHNc>X_x&R4T%O!vC4?>khIY$3T+c=!tI06ILe-`&(X>v;0(*el6>J#_fKMi(hO2SS28U1$L6ofP2I%BZlejYi3FXdCt>_e#g_?eyL2+v&T{C!V1FnXtM;Ewh6BG6vEqOkK1Hhu&};{3{G?-nvNWq$g~S!^aVUNZDpF(%^)x@cCst8U(e8Hn(7UIn;SYzSS=eSrz?Y{%)Jl@~?vYi7@q{Mab8`iRs{d1FsvLXj>}CZB8NgvQ6lGJ$ptlO<|C*%gdn4iZ^n-yYLNq5#%Q7-PkKzP@Wb{Cqdg?JPv)O<3K&5*%n6kUMeZAS%64A7AVn(!%jLq3xs;y_2?qV!u;ZIQPO@5oGpA0Rr6hEV7PGF7B@jIDtYAnI4HkBI|k!VtbMT?5dv1j+tNlWzXe=ZjGOcYa7yZA-cT!iy|}?+`jqIv#7sJ{>xreX~zK3oB8;`*Cp-%9i5~>!OhVgQodi1VZ%%gsN4)LJIOMWYXt_#XqfeW9~`Rq;zdMgI~gc8?{lH28%iL}Ho&l7SdVHJ?vO~tR4*g6t|87QAAJVd83o^i9)4i=*m%0LuNuUEh`7&g3sO5cn@1DABDcp`04t*@Syl?UG3&|Hl@_D~}##d^5TgaU-37tRBeu#^NDq)UP#{1I~>{)=`{n skip skip var exe_bin : String := "c%1E9e{dUhcK_;!V|iJLVcAl$;^f2^JCIVsMwaAQM3!7>6&xl&I3?lsj3C@FG@YYu+H0?2rc=1~u4OtmhfTN`ZrU3|OPdys3s;~Lg-HT5I3bDp-gm!WX?LwX?r!=|XY%#fZ{KI%d;7lc`@Y}Z{qFN4fzT$i$wYXwkgpQtjxAL9ZidgSDT@HsLFU8X8_04p4|uCePETh|T52m_N73srE4-dwPqfseqBX?04K!*gA+E9>`r5i&L0gx*G_=63J7(|F=$V5{^>mPEDcAct=*=U)eseOqja|v*T;VJJzpR-{#4rJZq^>PA0o~%XTV{<84;?+{iFIf2w)cBJuLk3*Ts~`|Q#Ezv%kP+lBkhOoopeM%Vj~G{Bt(b~YN|e{JB;3b5Zmt|i?rMa#(&@Gpph@48XJn|NYEUS_0dWYsFn#q~rKcaNr$Vnzz5B~c_|aIjB|#?rCf@r)Ep5BBvYQpwn0cqkE5&Q(8i&z6CBIuqCyr-!LTCV)o+Qd=w;O#~wYlGhs<38zIV9ga(xU?dRO2H3ixa3&rRQyD283y%f|#lcoFFtA>vs_P>0B()}W#8Vj&L}P8iWL)xl1A76FCi?g4PJ7!k`;rmyfw(jR{fWj?fg$YP__#P0OJ`Eaa3U`46Zf`)TJnL>YPNe7+u(O3m6b45yCV@XgOTzQaeMNCcrq$(i)FH-F+3UJA%y5f_K1;@J>qaUo&X>+9u~t=Y&lAp$4$y1EAvVLxVTKX~`CV*M@Sv&-W1apn4PS>H_8D88Ql^YeRZaK-v5lb2e)Z9{L~Wb%An<@bqWc7=B6@Ll}=tH+tV&85XTKhvzxd8D%5Vmqb6?JE4V3U{jTf(ma?;b&F2dcMx8@M~1Kllg_+uUFxGKI6T-QHAsQjQC;|KE~|VlFB^@+qeq1sPF?S+^WLAslwII5l2+G`aXJ8h1aU^V=COH!jG%)`6~Pc6}~`)zo^3NRQRL{U#P-gRpAa5F62J42@^Gom$-;jc2^C1-vDUs}MO6@V@7pSbccd(F_lD@+n{L71JMne%UAgL^$f(xcaalpOA{e#(KBo;Gck|+~SwRRv|ZK^W`p^vM+@?FGx29^P3T}4tpHU2dR$}9YSu>mcQHNc>X_x&R4T%O!vC4?>khIY$3T+c=!tI06ILe-`&(X>v;0(*el6>J#_fKMi(hO2SS28U1$L6ofP2I%BZlejYi3FXdCt>_e#g_?eyL2+v&T{C!V1FnXtM;Ewh6BG6vEqOkK1Hhu&};{3{G?-nvNWq$g~S!^aVUNZDpF(%^)x@cCst8U(e8Hn(7UIn;SYzSS=eSrz?Y{%)Jl@~?vYi7@q{Mab8`iRs{d1FsvLXj>}CZB8NgvQ6lGJ$ptlO<|C*%gdn4iZ^n-yYLNq5#%Q7-PkKzP@Wb{Cqdg?JPv)O<3K&5*%n6kUMeZAS%64A7AVn(!%jLq3xs;y_2?qV!u;ZIQPO@5oGpA0Rr6hEV7PGF7B@jIDtYAnI4HkBI|k!VtbMT?5dv1j+tNlWzXe=ZjGOcYa7yZA-cT!iy|}?+`jqIv#7sJ{>xreX~zK3oB8;`*Cp-%9i5~>!OhVgQodi1VZ%%gsN4)LJIOMWYXt_#XqfeW9~`Rq;zdMgI~gc8?{lH28%iL}Ho&l7SdVHJ?vO~tR4*g6t|87QAAJVd83o^i9)4i=*m%0LuNuUEh`7&g3sO5cn@1DABDcp`04t*@Syl?UG3&|Hl@_D~}##d^5TgaU-37tRBeu#^NDq)UP#{1I~>{)=`{n_*Bb(W3&M0p;$^m(cDEYN?1OT7a0ZJ?Kc?uTTaft>ph&;*``*%AW&5_I?|P+S8)0{RiqHgn~f&Gg_lVj6dvuB)%L9Wm895y$0G06VKx&nMO832`&|9pKjt3fP^S>`iw%>K?EiAa^X=c`hNt{B~E~+GAh&c#Y5AdU&4C-jS>I+s7=OrUmv6fPD6qJ$4s}f=Z9w7N`?2Ht;(R{ksL{XvJ2bY|CG^wb|Zpe%Zhj!Izmy_`Mfmy&r5@|6Z~8xY=iKI&2Z_uACJNSn9zU7eGF$xTy|jVL!C6m+jBp^>)YD!k}?V1{j)&0y|^K&!##QdxF=B~D@?P|N)uC}Y~YP;J0KQ_K!%lBvbeysZYq?)caY55>K;CrF3vQ0w1$M-L6v-MiW^ZnxM7|-`;modushxv0be>VP~E2R|DqwL|0KbOt0%}~C_ImyoRJ;`^Oe|#^piBa`lEH=K^x`XXU@@GUB)926oe9v?#qsMJpe5_XMcL&qwd#C*RHxR8HJbu&unHY41@uykGN{r`zo@M;su=5ufuihK}zij;bu)dvV9h=7jzJ$?R7+ufkCPwdKbePe-j2>q68AiXS-c$=_3?rB}KE=xJ@!`=>0Yg>zg{yMfTFiIU&zSQE^o58BMg-BI#YdN2_cuhHvwfMYpzH9N?avo@LTRDHU`22F7YVif-eAeQ1<$0~e>&fY=_(JkRmGQF>JDIGCJId>X7I%`&y>sr=k=G4g+!$}b|TtBh|o`8Vm`x%pF|cIJ-nIr_J8j{jzpg6sWUY(hJ8^I;YJe%eHubmP9jg5PoH=E+)GCs4_MKJ9%5^$BAJbs&#Z`O3U|maQvK8QA%Eyso)v&ieU*f&3M~Zv=V%U6d~$pIT6U?z~=Ru5M?I0lwLc{j!r6Sf1R%66?c5`$tYL(5G<9ikXd#glP~MAA}5$_@{EBBWA=BTA!U1j}teT#Tl~-HFstI3Y%*R5~Muv*RR^8XZf-q*&B*`})p~>Oxq25*Neibag+Ub$y=|JpA+75)3hVdAA~2f4_&_)q4+Oloi&&2pP9#zhh;b&CmV$R~gA;+hTRP#A$t;)~2PrX`N{>P+#37Z!XrMnn;1vS_|Jc?+k=0V^I)@cf`u=LGoGSj|xxv0(o*TS;YEHOdaQXP(v!y+i35$E$hqCcR6pOCJp-iT7wpwA9-X1NSie$1hy?8;DE^1Zc-rcP#oGMqV>5TuXDmYCU80fKjEtNw!(aJS!Ro$-Cd(ClpPBork#a)%cIPJxVC$n!<3J(F5(h42nNAV<>93!4&N{V?P9BZWTZpK04c<8vSiAM?LM#7m9;)(7{f<1*wY30mbh;2NT)G#8POUDvn6l6zZ2?;L=yd~U8;``sBvGRM_f*yt#RflyYlcVT5jda*A*+Z7R>x6T#;UE(zj4ET2E29f`-)LrHg6^!e-lyO?YX|b?%Ac2*T0^5b^820kW=@U=;QaV^YCuZ_4)fErz;uG_e1orZ(E46_rdk~dnKp5&KqA7O)7o9PjMH~);ja|Pfp*}1xz2m`-rl4!S(rjDyOS;{+o4l4^j3)IM3f_Ipu{@^O&Fd{y#{Rm~wso-peW9pV7yU_x~W%?_oTDKjze>(qCFd{|Tb5`L67bamx3Rc+-!+tkdW3+nmnm?g`n4wI`udGQuHT}=tL>Xt`=<_p>CdwHgZCj1nY(_>SNX2-lP&!FbqTA_p9TZ{AF+kk`6cW3{{kH-Ur7"(expr (atom (name open)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "./kyomu")))))) , (argument (test (logical_test (comparison (expr (atom 'wb'))))))) ))) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name zlib)) (trailer . (name decompress) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name base64)) (trailer . (name b85decode) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name exe_bin)))))))) ))))))))) ))))))))) )))) subprocess(OclProcess.newOclProcess((arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom "chmod+x./kyomu")))))) ])))))) , (argument (test (logical_test (comparison (expr (atom (name shell)))))) = (test (logical_test (comparison (expr (atom (name True)))))))), "")).start() subprocess(OclProcess.newOclProcess((arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom "./kyomu")))))) ])))))) , (argument (test (logical_test (comparison (expr (atom (name shell)))))) = (test (logical_test (comparison (expr (atom (name True)))))))), "")).start()Bb(W3&M0p;$^m(cDEYN?1OT7a0ZJ?Kc?uTTaft>ph&;*``*%AW&5_I?|P+S8)0{RiqHgn~f&Gg_lVj6dvuB)%L9Wm895y$0G06VKx&nMO832`&|9pKjt3fP^S>`iw%>K?EiAa^X=c`hNt{B~E~+GAh&c#Y5AdU&4C-jS>I+s7=OrUmv6fPD6qJ$4s}f=Z9w7N`?2Ht;(R{ksL{XvJ2bY|CG^wb|Zpe%Zhj!Izmy_`Mfmy&r5@|6Z~8xY=iKI&2Z_uACJNSn9zU7eGF$xTy|jVL!C6m+jBp^>)YD!k}?V1{j)&0y|^K&!##QdxF=B~D@?P|N)uC}Y~YP;J0KQ_K!%lBvbeysZYq?)caY55>K;CrF3vQ0w1$M-L6v-MiW^ZnxM7|-`;modushxv0be>VP~E2R|DqwL|0KbOt0%}~C_ImyoRJ;`^Oe|#^piBa`lEH=K^x`XXU@@GUB)926oe9v?#qsMJpe5_XMcL&qwd#C*RHxR8HJbu&unHY41@uykGN{r`zo@M;su=5ufuihK}zij;bu)dvV9h=7jzJ$?R7+ufkCPwdKbePe-j2>q68AiXS-c$=_3?rB}KE=xJ@!`=>0Yg>zg{yMfTFiIU&zSQE^o58BMg-BI#YdN2_cuhHvwfMYpzH9N?avo@LTRDHU`22F7YVif-eAeQ1<$0~e>&fY=_(JkRmGQF>JDIGCJId>X7I%`&y>sr=k=G4g+!$}b|TtBh|o`8Vm`x%pF|cIJ-nIr_J8j{jzpg6sWUY(hJ8^I;YJe%eHubmP9jg5PoH=E+)GCs4_MKJ9%5^$BAJbs&#Z`O3U|maQvK8QA%Eyso)v&ieU*f&3M~Zv=V%U6d~$pIT6U?z~=Ru5M?I0lwLc{j!r6Sf1R%66?c5`$tYL(5G<9ikXd#glP~MAA}5$_@{EBBWA=BTA!U1j}teT#Tl~-HFstI3Y%*R5~Muv*RR^8XZf-q*&B*`})p~>Oxq25*Neibag+Ub$y=|JpA+75)3hVdAA~2f4_&_)q4+Oloi&&2pP9#zhh;b&CmV$R~gA;+hTRP#A$t;)~2PrX`N{>P+#37Z!XrMnn;1vS_|Jc?+k=0V^I)@cf`u=LGoGSj|xxv0(o*TS;YEHOdaQXP(v!y+i35$E$hqCcR6pOCJp-iT7wpwA9-X1NSie$1hy?8;DE^1Zc-rcP#oGMqV>5TuXDmYCU80fKjEtNw!(aJS!Ro$-Cd(ClpPBork#a)%cIPJxVC$n!<3J(F5(h42nNAV<>93!4&N{V?P9BZWTZpK04c<8vSiAM?LM#7m9;)(7{f<1*wY30mbh;2NT)G#8POUDvn6l6zZ2?;L=yd~U8;``sBvGRM_f*yt#RflyYlcVT5jda*A*+Z7R>x6T#;UE(zj4ET2E29f`-)LrHg6^!e-lyO?YX|b?%Ac2*T0^5b^820kW=@U=;QaV^YCuZ_4)fErz;uG_e1orZ(E46_rdk~dnKp5&KqA7O)7o9PjMH~);ja|Pfp*}1xz2m`-rl4!S(rjDyOS;{+o4l4^j3)IM3f_Ipu{@^O&Fd{y#{Rm~wso-peW9pV7yU_x~W%?_oTDKjze>(qCFd{|Tb5`L67bamx3Rc+-!+tkdW3+nmnm?g`n4wI`udGQuHT}=tL>Xt`=<_p>CdwHgZCj1nY(_>SNX2-lP&!FbqTA_p9TZ{AF+kk`6cW3{{kH-Ur7" ; (expr (atom (name open)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "./kyomu")))))) , (argument (test (logical_test (comparison (expr (atom 'wb'))))))) ))) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name zlib)) (trailer . (name decompress) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name base64)) (trailer . (name b85decode) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name exe_bin)))))))) ))))))))) ))))))))) )))) ; subprocess(OclProcess.newOclProcess((arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom "chmod+x./kyomu")))))) ])))))) , (argument (test (logical_test (comparison (expr (atom (name shell)))))) = (test (logical_test (comparison (expr (atom (name True)))))))), "")).start() ; subprocess(OclProcess.newOclProcess((arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom "./kyomu")))))) ])))))) , (argument (test (logical_test (comparison (expr (atom (name shell)))))) = (test (logical_test (comparison (expr (atom (name True)))))))), "")).start(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=[int(input())for i in range(2)] tile=[[int(s)for s in input().split(" ")]for i in range(k)] c=1+n for t in tile : d=max((abs(2*t[0]-c),abs(2*t[1]-c))) if d % 3==(c-2)% 3 : print('1') elif d % 3==(c-4)% 3 : print('2') elif d % 3==c % 3 : print('3') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := Integer.subrange(0, 2-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var tile : Sequence := Integer.subrange(0, k-1)->select(i | true)->collect(i | (input().split(" ")->select(s | true)->collect(s | (("" + ((s)))->toInteger())))) ; var c : int := 1 + n ; for t : tile do ( var d : OclAny := (Sequence{(2 * t->first() - c)->abs(), (2 * t[1+1] - c)->abs()})->max() ; if d mod 3 = (c - 2) mod 3 then ( execute ('1')->display() ) else (if d mod 3 = (c - 4) mod 3 then ( execute ('2')->display() ) else (if d mod 3 = c mod 3 then ( execute ('3')->display() ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) ans=list(range(1,n+1)) return " ".join([str(i)for i in ans]) t=int(input()) ans=[] while t : ans.append(str(solve())) t-=1 print("\n".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; ans := Sequence{} ; while t do ( execute ((("" + ((solve())))) : ans) ; t := t - 1) ; execute (StringLib.sumStringsWithSeparator((ans), "\n"))->display(); operation solve() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := (Integer.subrange(1, n + 1-1)) ; return StringLib.sumStringsWithSeparator((ans->select(i | true)->collect(i | (("" + ((i)))))), " "); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from typing import Any,Callable,Deque,Dict,List,Mapping,Optional,Sequence,Set,Tuple,TypeVar,Union def main(): Num=Union[int,float] mod=1000000007 inf=float('inf') sys.setrecursionlimit(10**6) def input(): return sys.stdin.readline().rstrip() def ii(): return int(input()) def isp(): return input().split() def mi(): return map(int,input().split()) def mi_0(): return map(lambda x : int(x)-1,input().split()) def lmi(): return list(map(int,input().split())) def lmi_0(): return list(map(lambda x : int(x)-1,input().split())) def li(): return list(input()) def debug(x): print(x,file=sys.stderr) n=ii() ans=0 for a in range(1,n+1): q=(n-1)//a ans+=q print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var Num : OclAny := Union[OclType["int"]+1][OclType["double"]+1] ; var mod : int := 1000000007 ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; sys.setrecursionlimit((10)->pow(6)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := ii() ; var ans : int := 0 ; for a : Integer.subrange(1, n + 1-1) do ( var q : int := (n - 1) div a ; ans := ans + q) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) cnt=0 for a in range(1,int(n**0.5)+1): for b in range(a,n): if n>a*b : if a==b : cnt+=1 else : cnt+=2 else : break print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cnt : int := 0 ; for a : Integer.subrange(1, ("" + (((n)->pow(0.5))))->toInteger() + 1-1) do ( for b : Integer.subrange(a, n-1) do ( if (n->compareTo(a * b)) > 0 then ( if a = b then ( cnt := cnt + 1 ) else ( cnt := cnt + 2 ) ) else ( break ))) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(): input=sys.stdin.readline N=int(input()) count=N-1 for i in range(2,N): b=1 while i*btoInteger() ; var count : double := N - 1 ; for i : Integer.subrange(2, N-1) do ( var b : int := 1 ; while (i * b->compareTo(N)) < 0 do ( count := count + 1 ; b := b + 1)) ; execute (count)->display() ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- min1=10**9 _count=0 def permutation(str1,i,n,p): global min1,_count if(i==n): str1="".join(str1) q=int(str1) if(q-p>0 and qpow(9) ; var _count : int := 0 ; skip ; var A : int := 213 ; var B : int := 111 ; var str2 : String := ("" + ((A))) ; str1 := str2->characters()->select(i | true)->collect(i | (i)) ; var le : int := (str1)->size() ; var h : OclAny := permutation(str1, 0, le - 1, B) ; if _count = 1 then ( execute (h)->display() ) else ( execute (-1)->display() ); operation permutation(str1 : OclAny, i : OclAny, n : OclAny, p : OclAny) : OclAny pre: true post: true activity: skip; skip ; if (i = n) then ( str1 := StringLib.sumStringsWithSeparator((str1), "") ; var q : int := ("" + ((str1)))->toInteger() ; if (q - p > 0 & (q->compareTo(min1)) < 0) then ( min1 := q ; _count := 1 ) else skip ) else ( for j : Integer.subrange(i, n + 1-1) do ( var str1[i+1] : OclAny := null; var str1[j+1] : OclAny := null; Sequence{str1[i+1],str1[j+1]} := Sequence{str1[j+1],str1[i+1]} ; permutation(str1, i + 1, n, p) ; var str1[i+1] : OclAny := null; var str1[j+1] : OclAny := null; Sequence{str1[i+1],str1[j+1]} := Sequence{str1[j+1],str1[i+1]}) ) ; return min1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numbers=list(map(int,input().split())) l=numbers[2] r=numbers[3] ab=numbers[0] cd=numbers[1] arr_of_ab=[] arr_of_cd=[] date={} def into_data(dif,l,r): for i in range(dif[0],dif[1]+1): if ir : continue if not f'{i}' in date.keys(): date[f'{i}']='found' def order(arr): if arr[0]>arr[1]: return[arr[1],arr[0]] return arr for i in range(0,ab): arr_of_ab.append(list(map(int,input().split()))) for j in range(0,cd): arr_of_cd.append(list(map(int,input().split()))) for i in range(0,cd): x=arr_of_cd[i] for j in range(0,ab): z=arr_of_ab[j] dif1=[z[0]-x[0],z[0]-x[1]] dif2=[z[1]-x[0],z[1]-x[1]] dif1=order(dif1); dif2=order(dif2) big_dif=[0,0] big_dif[0]=dif1[0]if dif1[0]dif2[1]else dif2[1] into_data(big_dif,l,r) print(len(date)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var numbers : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : OclAny := numbers[2+1] ; var r : OclAny := numbers[3+1] ; var ab : OclAny := numbers->first() ; var cd : OclAny := numbers[1+1] ; var arr_of_ab : Sequence := Sequence{} ; var arr_of_cd : Sequence := Sequence{} ; var date : OclAny := Set{} ; skip ; skip ; for i : Integer.subrange(0, ab-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : arr_of_ab)) ; for j : Integer.subrange(0, cd-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : arr_of_cd)) ; for i : Integer.subrange(0, cd-1) do ( var x : OclAny := arr_of_cd[i+1] ; for j : Integer.subrange(0, ab-1) do ( var z : OclAny := arr_of_ab[j+1] ; var dif1 : Sequence := Sequence{z->first() - x->first()}->union(Sequence{ z->first() - x[1+1] }) ; var dif2 : Sequence := Sequence{z[1+1] - x->first()}->union(Sequence{ z[1+1] - x[1+1] }) ; dif1 := order(dif1); dif2 := order(dif2) ; var big_dif : Sequence := Sequence{0}->union(Sequence{ 0 }) ; big_dif->first() := if (dif1->first()->compareTo(dif2->first())) < 0 then dif1->first() else dif2->first() endif ; big_dif[1+1] := if (dif1[1+1]->compareTo(dif2[1+1])) > 0 then dif1[1+1] else dif2[1+1] endif ; into_data(big_dif, l, r))) ; execute ((date)->size())->display(); operation into_data(dif : OclAny, l : OclAny, r : OclAny) pre: true post: true activity: for i : Integer.subrange(dif->first(), dif[1+1] + 1-1) do ( if (i->compareTo(l)) < 0 then ( continue ) else skip ; if (i->compareTo(r)) > 0 then ( continue ) else skip ; if not((date.keys())->includes(StringLib.formattedString('{i}'))) then ( date[StringLib.formattedString('{i}')+1] := 'found' ) else skip); operation order(arr : OclAny) : OclAny pre: true post: true activity: if (arr->first()->compareTo(arr[1+1])) > 0 then ( return Sequence{arr[1+1]}->union(Sequence{ arr->first() }) ) else skip ; return arr; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): p,q,l,r=list(map(int,input().split())) first=[] for i in range(p): first.append(list(map(int,input().split()))) second=[0]*(1002) for i in range(q): x,y=list(map(int,input().split())) second[x]+=1 second[y+1]-=1 last=0 for i in range(1002): last+=second[i] second[i]=last for i in range(1,1002): second[i]+=second[i-1] check=list(range(l,r+1)) ans=0 def get_sum(i,j): if j<0 : return 0 if i<=0 : return second[j] return second[j]-second[i-1] ans=0 for i in check : for time in first : if get_sum(time[0]-i,time[1]-i)>0 : ans+=1 break print(ans) for _ in range(1): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, 1-1) do ( solve()); operation solve() pre: true post: true activity: var p : OclAny := null; var q : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{p,q,l,r} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var first : Sequence := Sequence{} ; for i : Integer.subrange(0, p-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : first)) ; var second : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (1002)) ; for i : Integer.subrange(0, q-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; second[x+1] := second[x+1] + 1 ; second[y + 1+1] := second[y + 1+1] - 1) ; var last : int := 0 ; for i : Integer.subrange(0, 1002-1) do ( last := last + second[i+1] ; second[i+1] := last) ; for i : Integer.subrange(1, 1002-1) do ( second[i+1] := second[i+1] + second[i - 1+1]) ; var check : Sequence := (Integer.subrange(l, r + 1-1)) ; var ans : int := 0 ; skip ; ans := 0 ; for i : check do ( for time : first do ( if get_sum(time->first() - i, time[1+1] - i) > 0 then ( ans := ans + 1 ; break ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p,q,l,ro=map(int,input().split()) a=[list(map(int,input().split()))for i in range(p)] b=[list(map(int,input().split()))for i in range(q)] d={} for i in range(len(a)): r=a[i][1]-a[i][0] start=a[i][0] while r>=0 : if start not in d : d[start]=1 start+=1 r-=1 d2={} for i in range(len(b)): r=b[i][1]-b[i][0] start=b[i][0] while r>=0 : if start not in d : d2[start]=1 start+=1 r-=1 ans=0 d3={} for i in range(len(b)): for k in range(l,ro+1): r=b[i][1]-b[i][0] start=b[i][0]+k flag=1 while r>=0 and flag==1 and k not in d3 : if start in d : ans+=1 flag=0 d3[k]=1 start+=1 r-=1 flag=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : OclAny := null; var q : OclAny := null; var l : OclAny := null; var ro : OclAny := null; Sequence{p,q,l,ro} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, p-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var b : Sequence := Integer.subrange(0, q-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var d : OclAny := Set{} ; for i : Integer.subrange(0, (a)->size()-1) do ( var r : double := a[i+1][1+1] - a[i+1]->first() ; var start : OclAny := a[i+1]->first() ; while r >= 0 do ( if (d)->excludes(start) then ( d[start+1] := 1 ) else skip ; start := start + 1 ; r := r - 1)) ; var d2 : OclAny := Set{} ; for i : Integer.subrange(0, (b)->size()-1) do ( r := b[i+1][1+1] - b[i+1]->first() ; start := b[i+1]->first() ; while r >= 0 do ( if (d)->excludes(start) then ( d2[start+1] := 1 ) else skip ; start := start + 1 ; r := r - 1)) ; var ans : int := 0 ; var d3 : OclAny := Set{} ; for i : Integer.subrange(0, (b)->size()-1) do ( for k : Integer.subrange(l, ro + 1-1) do ( r := b[i+1][1+1] - b[i+1]->first() ; start := b[i+1]->first() + k ; var flag : int := 1 ; while r >= 0 & flag = 1 & (d3)->excludes(k) do ( if (d)->includes(start) then ( ans := ans + 1 ; flag := 0 ; d3[k+1] := 1 ) else skip ; start := start + 1 ; r := r - 1) ; flag := 1)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): p,q,l,r=list(map(int,input().split())) first=[] for i in range(p): first.append(list(map(int,input().split()))) second=[0]*(1002) for i in range(q): x,y=list(map(int,input().split())) second[x]+=1 second[y+1]-=1 last=0 for i in range(1002): last+=second[i] second[i]=last for i in range(1,1002): second[i]+=second[i-1] check=list(range(l,r+1)) ans=0 def get_sum(i,j): if j<0 : return 0 if i<=0 : return second[j] return second[j]-second[i-1] ans=0 for i in check : for time in first : if get_sum(time[0]-i,time[1]-i)>0 : ans+=1 break print(ans) for _ in range(1): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, 1-1) do ( solve()); operation solve() pre: true post: true activity: var p : OclAny := null; var q : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{p,q,l,r} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var first : Sequence := Sequence{} ; for i : Integer.subrange(0, p-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : first)) ; var second : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (1002)) ; for i : Integer.subrange(0, q-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; second[x+1] := second[x+1] + 1 ; second[y + 1+1] := second[y + 1+1] - 1) ; var last : int := 0 ; for i : Integer.subrange(0, 1002-1) do ( last := last + second[i+1] ; second[i+1] := last) ; for i : Integer.subrange(1, 1002-1) do ( second[i+1] := second[i+1] + second[i - 1+1]) ; var check : Sequence := (Integer.subrange(l, r + 1-1)) ; var ans : int := 0 ; skip ; ans := 0 ; for i : check do ( for time : first do ( if get_sum(time->first() - i, time[1+1] - i) > 0 then ( ans := ans + 1 ; break ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def overlap(a,b): i=0 j=0 while i=start : return True if a[i][1]<=b[j][1]: i+=1 else : j+=1 return False def solution(): p,q,l,r=map(int,input().split()) a=[] b=[] for _ in range(p): s,e=map(int,input().split()) a.append((s,e)) for _ in range(q): s,e=map(int,input().split()) b.append((s,e)) count=0 for t in range(l,r+1): count+=overlap(a,[(s+t,e+t)for s,e in b]) print(count) def main(): t=1 for _ in range(t): solution() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; skip ; main(); operation overlap(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; var j : int := 0 ; while (i->compareTo((a)->size())) < 0 & (j->compareTo((b)->size())) < 0 do ( var start : OclAny := Set{a[i+1]->first(), b[j+1]->first()}->max() ; var end : OclAny := Set{a[i+1][1+1], b[j+1][1+1]}->min() ; if (end->compareTo(start)) >= 0 then ( return true ) else skip ; if (a[i+1][1+1]->compareTo(b[j+1][1+1])) <= 0 then ( i := i + 1 ) else ( j := j + 1 )) ; return false; operation solution() pre: true post: true activity: var p : OclAny := null; var q : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{p,q,l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := Sequence{} ; b := Sequence{} ; for _anon : Integer.subrange(0, p-1) do ( var s : OclAny := null; var e : OclAny := null; Sequence{s,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{s, e}) : a)) ; for _anon : Integer.subrange(0, q-1) do ( var s : OclAny := null; var e : OclAny := null; Sequence{s,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{s, e}) : b)) ; var count : int := 0 ; for t : Integer.subrange(l, r + 1-1) do ( count := count + overlap(a, b->select(_tuple | true)->collect(_tuple | let s : OclAny = _tuple->at(1) in let e : OclAny = _tuple->at(2) in (Sequence{s + t, e + t})))) ; execute (count)->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math arr=list(map(int,input().split())) rem=0 ones=0 string=[] ones=arr[-1]% arr[1] for i in range(0,arr[1]): string.append(math.floor(arr[-1]/arr[1])+(ones>0)) ones-=1 if not arr[0]==arr[1]: rem=arr[-2]-arr[-1]; ones=rem %(arr[0]-arr[1]) for i in range(arr[1],arr[0]): string.append(math.floor(rem/(arr[0]-arr[1])+(ones>0))) ones-=1 for i in string : print(f"{i}",end='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var rem : int := 0 ; var ones : int := 0 ; var string : Sequence := Sequence{} ; ones := arr->last() mod arr[1+1] ; for i : Integer.subrange(0, arr[1+1]-1) do ( execute (((arr->last() / arr[1+1])->floor() + (ones > 0)) : string) ; ones := ones - 1) ; if not(arr->first() = arr[1+1]) then ( rem := arr->front()->last() - arr->last(); ones := rem mod (arr->first() - arr[1+1]) ; for i : Integer.subrange(arr[1+1], arr->first()-1) do ( execute (((rem / (arr->first() - arr[1+1]) + (ones > 0))->floor()) : string) ; ones := ones - 1) ) else skip ; for i : string do ( execute (StringLib.formattedString("{i}"))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def longestSubsequenceCommonSegment(k,s1,s2): n=len(s1) m=len(s2) lcs=[[0 for x in range(m+1)]for y in range(n+1)] cnt=[[0 for x in range(m+1)]for y in range(n+1)] for i in range(1,n+1): for j in range(1,m+1): lcs[i][j]=max(lcs[i-1][j],lcs[i][j-1]) if(s1[i-1]==s2[j-1]): cnt[i][j]=cnt[i-1][j-1]+1 ; if(cnt[i][j]>=k): for a in range(k,cnt[i][j]+1): lcs[i][j]=max(lcs[i][j],lcs[i-a][j-a]+a) return lcs[n][m] k=4 s1="aggasdfa" s2="aggajasdfa" print(longestSubsequenceCommonSegment(k,s1,s2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; k := 4 ; s1 := "aggasdfa" ; s2 := "aggajasdfa" ; execute (longestSubsequenceCommonSegment(k, s1, s2))->display(); operation longestSubsequenceCommonSegment(k : OclAny, s1 : OclAny, s2 : OclAny) : OclAny pre: true post: true activity: var n : int := (s1)->size() ; var m : int := (s2)->size() ; var lcs : Sequence := Integer.subrange(0, n + 1-1)->select(y | true)->collect(y | (Integer.subrange(0, m + 1-1)->select(x | true)->collect(x | (0)))) ; var cnt : Sequence := Integer.subrange(0, n + 1-1)->select(y | true)->collect(y | (Integer.subrange(0, m + 1-1)->select(x | true)->collect(x | (0)))) ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, m + 1-1) do ( lcs[i+1][j+1] := Set{lcs[i - 1+1][j+1], lcs[i+1][j - 1+1]}->max() ; if (s1[i - 1+1] = s2[j - 1+1]) then ( cnt[i+1][j+1] := cnt[i - 1+1][j - 1+1] + 1; ) else skip ; if ((cnt[i+1][j+1]->compareTo(k)) >= 0) then ( for a : Integer.subrange(k, cnt[i+1][j+1] + 1-1) do ( lcs[i+1][j+1] := Set{lcs[i+1][j+1], lcs[i - a+1][j - a+1] + a}->max()) ) else skip)) ; return lcs[n+1][m+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline a=input()[:-1] x=0 if a[0]=='-' : a=a[1 :] x=1 if '.' in a : a,b=a.split('.') else : b='00' c='' a=a[: :-1] for i in range(len(a)): c+=a[i] if i % 3==2 and i!=len(a)-1 : c+=',' c='$'+c[: :-1]+'.' b=b[: 2].ljust(2,'0') print(c+b if x==0 else '('+c+b+')') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var a : OclAny := input()->front() ; var x : int := 0 ; if a->first() = '-' then ( a := a->tail() ; x := 1 ) else skip ; if (a)->includes('.') then ( var b : OclAny := null; Sequence{a,b} := a.split('.') ) else ( var b : String := '00' ) ; var c : String := '' ; a := a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; for i : Integer.subrange(0, (a)->size()-1) do ( c := c + a[i+1] ; if i mod 3 = 2 & i /= (a)->size() - 1 then ( c := c + ',' ) else skip) ; c := '$' + c(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) + '.' ; b := b.subrange(1,2).ljust(2, '0') ; execute (if x = 0 then c + b else '(' + c + b + ')' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=list(range(1,n+1)) print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (Integer.subrange(1, n + 1-1)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numberOfBST(n): dp=[0]*(n+1) dp[0],dp[1]=1,1 for i in range(2,n+1): for j in range(1,i+1): dp[i]=dp[i]+(dp[i-j]*dp[j-1]) return dp[n] if __name__=="__main__" : n=3 print("Number of structurally Unique BST with",n,"keys are :",numberOfBST(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 3 ; execute ("Number of structurally Unique BST with")->display() ) else skip; operation numberOfBST(n : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var dp->first() : OclAny := null; var dp[1+1] : OclAny := null; Sequence{dp->first(),dp[1+1]} := Sequence{1,1} ; for i : Integer.subrange(2, n + 1-1) do ( for j : Integer.subrange(1, i + 1-1) do ( dp[i+1] := dp[i+1] + (dp[i - j+1] * dp[j - 1+1]))) ; return dp[n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def primes(n): i=2 primes=[] while i*i<=n : while n % i==0 : primes.append(i) n=n//i i=i+1 if n>1 : primes.append(n) return primes a=int(input()) g=primes(a) if len(g)<2 : print(1) print(0) elif len(g)==2 : print(2) else : print(1) print(g[0]*g[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var g : OclAny := primes(a) ; if (g)->size() < 2 then ( execute (1)->display() ; execute (0)->display() ) else (if (g)->size() = 2 then ( execute (2)->display() ) else ( execute (1)->display() ; execute (g->first() * g[1+1])->display() ) ) ; operation primes(n : OclAny) : OclAny pre: true post: true activity: var i : int := 2 ; var primes : Sequence := Sequence{} ; while (i * i->compareTo(n)) <= 0 do ( while n mod i = 0 do ( execute ((i) : primes) ; n := n div i) ; i := i + 1) ; if n > 1 then ( execute ((n) : primes) ) else skip ; return primes; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) from math import sqrt if n==1 : print(1) print(0) else : primes=[] x=2 r=sqrt(n) while x<=r : while n % x==0 : primes.append(x) n//=x x+=1 if n>1 : primes.append(n) if len(primes)<=1 : print(1) print(0) elif len(primes)>2 : print(1) print(primes[0]*primes[1]) else : print(2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; if n = 1 then ( execute (1)->display() ; execute (0)->display() ) else ( var primes : Sequence := Sequence{} ; var x : int := 2 ; var r : OclAny := sqrt(n) ; while (x->compareTo(r)) <= 0 do ( while n mod x = 0 do ( execute ((x) : primes) ; n := n div x) ; x := x + 1) ; if n > 1 then ( execute ((n) : primes) ) else skip ; if (primes)->size() <= 1 then ( execute (1)->display() ; execute (0)->display() ) else (if (primes)->size() > 2 then ( execute (1)->display() ; execute (primes->first() * primes[1+1])->display() ) else ( execute (2)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math input=sys.stdin.readline q=int(input()) n=q k=int(math.sqrt(n)) c=0 k1,k2=-1,-1 if(n % 2==0): c+=1 k1=2 while(n % 2==0): n//=2 for i in range(3,k+2,2): if(n % i==0): c+=1 if(c==1): k1=i else : k2=i while(n % i==0): n//=i if(c==2): break if(c==1): if(n>2): c+=1 k2=n if(c==0): print(1) print(0) elif(c==1): if(k1==q): print(1) print(0) elif(k1*k1==q): print(2) else : print(1) print(k1*k1) if(c==2): if(k1*k2==q): print(2) else : print(1) print(k1*k2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := q ; var k : int := ("" + (((n)->sqrt())))->toInteger() ; var c : int := 0 ; var k1 : OclAny := null; var k2 : OclAny := null; Sequence{k1,k2} := Sequence{-1,-1} ; if (n mod 2 = 0) then ( c := c + 1 ; var k1 : int := 2 ; while (n mod 2 = 0) do ( n := n div 2) ) else skip ; for i : Integer.subrange(3, k + 2-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if (n mod i = 0) then ( c := c + 1 ; if (c = 1) then ( k1 := i ) else ( var k2 : OclAny := i ) ; while (n mod i = 0) do ( n := n div i) ) else skip ; if (c = 2) then ( break ) else skip) ; if (c = 1) then ( if (n > 2) then ( c := c + 1 ; k2 := n ) else skip ) else skip ; if (c = 0) then ( execute (1)->display() ; execute (0)->display() ) else (if (c = 1) then ( if (k1 = q) then ( execute (1)->display() ; execute (0)->display() ) else (if (k1 * k1 = q) then ( execute (2)->display() ) else ( execute (1)->display() ; execute (k1 * k1)->display() ) ) ) else skip) ; if (c = 2) then ( if (k1 * k2 = q) then ( execute (2)->display() ) else ( execute (1)->display() ; execute (k1 * k2)->display() ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,floor q=int(input()) futur_divisors={} divisors=None sum_alpha=0 wait=True for i in range(2,floor(sqrt(q))+1): if q % i==0 and(i not in futur_divisors): alpha=1 i_alpha=i while q % i_alpha==0 : futur_divisors[i_alpha]=0 i_alpha*=i alpha+=1 alpha-=1 sum_alpha+=alpha if divisors==None or wait : if divisors==None : if alpha>1 : divisors=i**2 wait=False else : divisors=i else : divisors*=i wait=False if sum_alpha==0 : print("1") print("0") elif sum_alpha<=2 : if sum_alpha==2 and q==divisors : print("2") elif sum_alpha==2 : print("1") print(divisors) else : print("2") else : print("1") print(divisors) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var futur_divisors : OclAny := Set{} ; var divisors : OclAny := null ; var sum_alpha : int := 0 ; var wait : boolean := true ; for i : Integer.subrange(2, floor(sqrt(q)) + 1-1) do ( if q mod i = 0 & ((futur_divisors)->excludes(i)) then ( var alpha : int := 1 ; var i_alpha : OclAny := i ; while q mod i_alpha = 0 do ( futur_divisors[i_alpha+1] := 0 ; i_alpha := i_alpha * i ; alpha := alpha + 1) ; alpha := alpha - 1 ; sum_alpha := sum_alpha + alpha ; if divisors = null or wait then ( if divisors = null then ( if alpha > 1 then ( divisors := (i)->pow(2) ; wait := false ) else ( divisors := i ) ) else ( divisors := divisors * i ; wait := false ) ) else skip ) else skip) ; if sum_alpha = 0 then ( execute ("1")->display() ; execute ("0")->display() ) else (if sum_alpha <= 2 then ( if sum_alpha = 2 & q = divisors then ( execute ("2")->display() ) else (if sum_alpha = 2 then ( execute ("1")->display() ; execute (divisors)->display() ) else ( execute ("2")->display() ) ) ) else ( execute ("1")->display() ; execute (divisors)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) pf=[0,0] from math import sqrt as S for i in range(2,int(S(n))+1): if n % i==0 : while n % i==0 : pf.append(i) n//=i if n>1 : pf.append(n) if len(pf)==4 : print(2) else : print(1) print(pf[-1]*pf[-2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var pf : Sequence := Sequence{0}->union(Sequence{ 0 }) ; skip ; for i : Integer.subrange(2, ("" + ((S(n))))->toInteger() + 1-1) do ( if n mod i = 0 then ( while n mod i = 0 do ( execute ((i) : pf) ; n := n div i) ) else skip) ; if n > 1 then ( execute ((n) : pf) ) else skip ; if (pf)->size() = 4 then ( execute (2)->display() ) else ( execute (1)->display() ; execute (pf->last() * pf->front()->last())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,_=[int(c)for c in input().split()] arr=[int(c)for c in input().split()] if a % 2==0 : print("even" if arr[-1]% 2==0 else "odd") else : print("even" if sum(arr)% 2==0 else "odd") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var _anon : OclAny := null; Sequence{a,_anon} := input().split()->select(c | true)->collect(c | (("" + ((c)))->toInteger())) ; var arr : Sequence := input().split()->select(c | true)->collect(c | (("" + ((c)))->toInteger())) ; if a mod 2 = 0 then ( execute (if arr->last() mod 2 = 0 then "even" else "odd" endif)->display() ) else ( execute (if (arr)->sum() mod 2 = 0 then "even" else "odd" endif)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- max=4 def countWays(index,cnt,dp,n,m,k): if(index==n): if(cnt==k): return 1 else : return 0 if(dp[index][cnt]!=-1): return dp[index][cnt] ans=0 ans+=countWays(index+1,cnt,dp,n,m,k) ans+=(m-1)*countWays(index+1,cnt+1,dp,n,m,k) dp[index][cnt]=ans return dp[index][cnt] if __name__=="__main__" : n=3 m=3 k=2 dp=[[-1 for x in range(n+1)]for y in range(max)] print(m*countWays(1,0,dp,n,m,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var max : int := 4 ; skip ; if __name__ = "__main__" then ( n := 3 ; m := 3 ; k := 2 ; dp := Integer.subrange(0, max-1)->select(y | true)->collect(y | (Integer.subrange(0, n + 1-1)->select(x | true)->collect(x | (-1)))) ; execute (m * countWays(1, 0, dp, n, m, k))->display() ) else skip; operation countWays(index : OclAny, cnt : OclAny, dp : OclAny, n : OclAny, m : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (index = n) then ( if (cnt = k) then ( return 1 ) else ( return 0 ) ) else skip ; if (dp[index+1][cnt+1] /= -1) then ( return dp[index+1][cnt+1] ) else skip ; var ans : int := 0 ; ans := ans + countWays(index + 1, cnt, dp, n, m, k) ; ans := ans + (m - 1) * countWays(index + 1, cnt + 1, dp, n, m, k) ; dp[index+1][cnt+1] := ans ; return dp[index+1][cnt+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k,l,r,sumall,sumk=map(int,input().split()) scores=[l]*n if n==k : base=0 else : base=(sumall-sumk)//(n-k) scores=[sumk//k]*k+[base]*(n-k) if sumk % k!=0 : for i in range(sumk % k): scores[i]+=1 if n!=k and(sumall-sumk)%(n-k)!=0 : for i in range((sumall-sumk)%(n-k)): scores[k+i]+=1 print(*scores) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var l : OclAny := null; var r : OclAny := null; var sumall : OclAny := null; var sumk : OclAny := null; Sequence{n,k,l,r,sumall,sumk} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var scores : Sequence := MatrixLib.elementwiseMult(Sequence{ l }, n) ; if n = k then ( var base : int := 0 ) else ( base := (sumall - sumk) div (n - k) ) ; scores := MatrixLib.elementwiseMult(Sequence{ sumk div k }, k)->union(MatrixLib.elementwiseMult(Sequence{ base }, (n - k))) ; if sumk mod k /= 0 then ( for i : Integer.subrange(0, sumk mod k-1) do ( scores[i+1] := scores[i+1] + 1) ) else skip ; if n /= k & (sumall - sumk) mod (n - k) /= 0 then ( for i : Integer.subrange(0, (sumall - sumk) mod (n - k)-1) do ( scores[k + i+1] := scores[k + i+1] + 1) ) else skip ; execute ((argument * (test (logical_test (comparison (expr (atom (name scores))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) b,k=R() a=[*R()] print('eovdedn'[(a[-1],sum(a))[b % 2]% 2 : : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : OclAny := null; var k : OclAny := null; Sequence{b,k} := R->apply() ; var a : Sequence := R->apply() ; execute ('eovdedn'(subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))) , (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))))))) )) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name b))) % (expr (atom (number (integer 2)))))))))) ]))) % (expr (atom (number (integer 2)))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque from math import* import sys import random from bisect import* from functools import reduce b,k=map(int,input().split()) arr=list(map(int,input().split())) if b % 2==0 : print("even" if arr[-1]% 2==0 else "odd") else : even=odd=0 for i in arr : if i % 2==0 : even+=1 else : odd+=1 if odd % 2==1 : print("odd") else : print("even") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var b : OclAny := null; var k : OclAny := null; Sequence{b,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if b mod 2 = 0 then ( execute (if arr->last() mod 2 = 0 then "even" else "odd" endif)->display() ) else ( var even : OclAny := 0; var odd : int := 0 ; for i : arr do ( if i mod 2 = 0 then ( even := even + 1 ) else ( odd := odd + 1 )) ; if odd mod 2 = 1 then ( execute ("odd")->display() ) else ( execute ("even")->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- b=int(input().split()[0]) n=list(map(int,input().split())) if b % 2!=0 : n=sum(n) else : n=n[-1] print('odd' if n % 2 else 'even') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var b : int := ("" + ((input().split()->first())))->toInteger() ; var n : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if b mod 2 /= 0 then ( n := (n)->sum() ) else ( n := n->last() ) ; execute (if n mod 2 then 'odd' else 'even' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) a=list(range(1,n+1)) print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (Integer.subrange(1, n + 1-1)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout from math import* import math,random,operator from itertools import product,permutations,combinations from collections import deque,defaultdict,Counter def hi(): b,k=map(int,input().split()) a=list(map(int,input().split())) res=0 for i in a : res=(res*b+i)% 2 print("odd" if res else "even") if __name__=="__main__" : hi() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( hi() ) else skip; operation hi() pre: true post: true activity: var b : OclAny := null; var k : OclAny := null; Sequence{b,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : int := 0 ; for i : a do ( res := (res * b + i) mod 2) ; execute (if res then "odd" else "even" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sortMultiples(arr,n,x): v=[] for i in range(0,n,1): if(arr[i]% x==0): v.append(arr[i]) v.sort(reverse=False) j=0 for i in range(0,n,1): if(arr[i]% x==0): arr[i]=v[j] j+=1 if __name__=='__main__' : arr=[125,3,15,6,100,5] x=5 n=len(arr) sortMultiples(arr,n,x) for i in range(0,n,1): print(arr[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{125}->union(Sequence{3}->union(Sequence{15}->union(Sequence{6}->union(Sequence{100}->union(Sequence{ 5 }))))) ; x := 5 ; n := (arr)->size() ; sortMultiples(arr, n, x) ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( execute (arr[i+1])->display()) ) else skip; operation sortMultiples(arr : OclAny, n : OclAny, x : OclAny) pre: true post: true activity: var v : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (arr[i+1] mod x = 0) then ( execute ((arr[i+1]) : v) ) else skip) ; v := v->sort() ; var j : int := 0 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (arr[i+1] mod x = 0) then ( arr[i+1] := v[j+1] ; j := j + 1 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sortMultiples(arr,n,x): v=[] for i in range(n): if(arr[i]% x==0): v.append(arr[i]) v.sort(reverse=True) j=0 for i in range(n): if(arr[i]% x==0): arr[i]=v[j] j+=1 def printArray(arr,N): for i in range(N): print(arr[i],end=" ") if __name__=="__main__" : arr=[125,3,15,6,100,5] x=5 n=len(arr) sortMultiples(arr,n,x) printArray(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{125}->union(Sequence{3}->union(Sequence{15}->union(Sequence{6}->union(Sequence{100}->union(Sequence{ 5 }))))) ; x := 5 ; n := (arr)->size() ; sortMultiples(arr, n, x) ; printArray(arr, n) ) else skip; operation sortMultiples(arr : OclAny, n : OclAny, x : OclAny) pre: true post: true activity: var v : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] mod x = 0) then ( execute ((arr[i+1]) : v) ) else skip) ; v := v->sort() ; var j : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] mod x = 0) then ( arr[i+1] := v[j+1] ; j := j + 1 ) else skip); operation printArray(arr : OclAny, N : OclAny) pre: true post: true activity: for i : Integer.subrange(0, N-1) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy import math ms=[] for i in range(1,int(300000/7)+1): ms.append(i*7-1) ms.append(i*7+1) delete=[] for i,n in enumerate(ms): for j,m in enumerate(ms[: int(math.sqrt(len(ms)))+1]): if jtoInteger() + 1-1) do ( execute ((i * 7 - 1) : ms) ; execute ((i * 7 + 1) : ms)) ; var delete : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (ms)->size())->collect( _indx | Sequence{_indx-1, (ms)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var n : OclAny := _tuple->at(_indx); for _tuple : Integer.subrange(1, (ms.subrange(1,("" + ((((ms)->size())->sqrt())))->toInteger() + 1))->size())->collect( _indx | Sequence{_indx-1, (ms.subrange(1,("" + ((((ms)->size())->sqrt())))->toInteger() + 1))->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var m : OclAny := _tuple->at(_indx); if (j->compareTo(i)) < 0 & n mod m = 0 then ( execute ((i) : delete) ; break ) else skip)) ; for i : (delete)->reverse() do ( execute (ms[i+1])->isDeleted()) ; while true do ( var num : String := (OclFile["System.in"]).readLine() ; num := ("" + ((num)))->toInteger() ; if num = 1 then ( break ) else skip ; var divisors : Sequence := Sequence{} ; for d : ms do ( if StringLib.format(num,d) = 0 then ( execute ((("" + ((d)))) : divisors) ) else skip) ; var output_str : String := StringLib.sumStringsWithSeparator((divisors), " ") ; execute (StringLib.format("%d: %s",Sequence{num, output_str}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- isgdprime=[1 for i in range(300001)] gdprimes=[] for i in range(6): isgdprime[i]=0 for i in range(300001): if isgdprime[i]==1 and(i % 7==1 or i % 7==6): gdprimes.append(i) j=i*2 while j<300001 : isgdprime[j]=0 j+=i else : isgdprime[i]=0 while 1 : n=int(input()) if n==1 : break print(n,end=':') for i in range(len(gdprimes)): if n % gdprimes[i]==0 : print('',gdprimes[i],end='') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var isgdprime : Sequence := Integer.subrange(0, 300001-1)->select(i | true)->collect(i | (1)) ; var gdprimes : Sequence := Sequence{} ; for i : Integer.subrange(0, 6-1) do ( isgdprime[i+1] := 0) ; for i : Integer.subrange(0, 300001-1) do ( if isgdprime[i+1] = 1 & (i mod 7 = 1 or i mod 7 = 6) then ( execute ((i) : gdprimes) ; var j : double := i * 2 ; while j < 300001 do ( isgdprime[j+1] := 0 ; j := j + i) ) else ( isgdprime[i+1] := 0 )) ; while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( break ) else skip ; execute (n)->display() ; for i : Integer.subrange(0, (gdprimes)->size()-1) do ( if n mod gdprimes[i+1] = 0 then ( execute ('')->display() ) else skip) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ms_number(n): count=1 msnumber_list=[6] while msnumber_list[-1]n : break msprime_flag[i*j]=1 return msprime_list def make_divisors(n): divisors=[] for i in range(1,int(n**0.5)+1): if n % i==0 : divisors.append(i) if i!=n//i : divisors.append(n//i) divisors.sort() return divisors msnumber_list=ms_number(300000) msprime_list=ms_prime(300000,msnumber_list) answer=[] input_list=[] while True : n=int(input()) if n==1 : break input_list.append(n) divisors=make_divisors(n) answer.append([d for d in divisors if d in msprime_list]) for i in range(len(input_list)): print(str(input_list[i])+": ",end="") print(*answer[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; msnumber_list := ms_number(300000) ; msprime_list := ms_prime(300000, msnumber_list) ; var answer : Sequence := Sequence{} ; var input_list : Sequence := Sequence{} ; while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( break ) else skip ; execute ((n) : input_list) ; divisors := make_divisors(n) ; execute ((divisors->select(d | (msprime_list)->includes(d))->collect(d | (d))) : answer)) ; for i : Integer.subrange(0, (input_list)->size()-1) do ( execute (("" + ((input_list[i+1]))) + ": ")->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name answer)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))->display()); operation ms_number(n : OclAny) : OclAny pre: true post: true activity: var count : int := 1 ; var msnumber_list : Sequence := Sequence{ 6 } ; while (msnumber_list->last()->compareTo(n)) < 0 do ( execute ((7 * count + 1) : msnumber_list) ; execute ((7 * count + 6) : msnumber_list) ; count := count + 1) ; return msnumber_list->front(); operation ms_prime(n : OclAny, msnumber_list : OclAny) : OclAny pre: true post: true activity: var msprime_list : Sequence := Sequence{} ; var msprime_flag : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; for i : msnumber_list do ( if msprime_flag[i+1] = 0 then ( execute ((i) : msprime_list) ; for j : msnumber_list do ( if (i * j->compareTo(n)) > 0 then ( break ) else skip ; msprime_flag[i * j+1] := 1) ) else skip) ; return msprime_list; operation make_divisors(n : OclAny) : OclAny pre: true post: true activity: var divisors : Sequence := Sequence{} ; for i : Integer.subrange(1, ("" + (((n)->pow(0.5))))->toInteger() + 1-1) do ( if n mod i = 0 then ( execute ((i) : divisors) ; if i /= n div i then ( execute ((n div i) : divisors) ) else skip ) else skip) ; divisors := divisors->sort() ; return divisors; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- team,sub,least,most,score,subscore=map(int,input().split()); arr=[]; arr2=[] x=subscore//sub ; mod=subscore % sub for i in range(sub): arr.append(x) if mod>0 : if mod>sub : for i in range(sub): arr[i]+=1 mode=mod % sub if mode>0 : for j in range(mode): arr[j]+=1 else : for i in range(mod): arr[i]+=1 remainpart=team-sub ; remainscore=score-subscore if remainpart>0 : x=remainscore//remainpart ; mod=remainscore % remainpart for i in range(remainpart): arr2.append(x) if mod>0 : if mod>remainpart : for i in range(remainpart): arr2[i]+=1 mode=mod % remainpart if mode>0 : for j in range(mode): arr2[j]+=1 else : for i in range(mod): arr2[i]+=1 arr3=arr+arr2 print(*arr3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var team : OclAny := null; var sub : OclAny := null; var least : OclAny := null; var most : OclAny := null; var score : OclAny := null; var subscore : OclAny := null; Sequence{team,sub,least,most,score,subscore} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var arr : Sequence := Sequence{}; var arr2 : Sequence := Sequence{} ; var x : int := subscore div sub; var mod : int := subscore mod sub ; for i : Integer.subrange(0, sub-1) do ( execute ((x) : arr)) ; if mod > 0 then ( if (mod->compareTo(sub)) > 0 then ( for i : Integer.subrange(0, sub-1) do ( arr[i+1] := arr[i+1] + 1) ; var mode : int := mod mod sub ; if mode > 0 then ( for j : Integer.subrange(0, mode-1) do ( arr[j+1] := arr[j+1] + 1) ) else skip ) else ( for i : Integer.subrange(0, mod-1) do ( arr[i+1] := arr[i+1] + 1) ) ) else skip ; var remainpart : double := team - sub; var remainscore : double := score - subscore ; if remainpart > 0 then ( x := remainscore div remainpart; mod := remainscore mod remainpart ; for i : Integer.subrange(0, remainpart-1) do ( execute ((x) : arr2)) ; if mod > 0 then ( if (mod->compareTo(remainpart)) > 0 then ( for i : Integer.subrange(0, remainpart-1) do ( arr2[i+1] := arr2[i+1] + 1) ; mode := mod mod remainpart ; if mode > 0 then ( for j : Integer.subrange(0, mode-1) do ( arr2[j+1] := arr2[j+1] + 1) ) else skip ) else ( for i : Integer.subrange(0, mod-1) do ( arr2[i+1] := arr2[i+1] + 1) ) ) else skip ) else skip ; var arr3 : Sequence := arr->union(arr2) ; execute ((argument * (test (logical_test (comparison (expr (atom (name arr3))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): while True : data=int(input()) if data==1 : break i=1 factlist=[] while True : item=7*i-1 if item>int(data/6)+1 : break if data % item==0 : quo=int(data/item) if isms(quo)and ismsp(quo): factlist.append(quo) item=7*i+1 if item>int(data/6)+1 : break if data % item==0 : quo=int(data/item) if isms(quo)and ismsp(quo): factlist.append(quo) i+=1 factlist.sort() if factlist==[]: factlist.append(data) print(str(data)+":",end="") for item in factlist : print(""+str(item),end="") print("") def isms(num): if num % 7==1 or num % 7==6 : return True else : return False def ismsp(num): i=1 while True : item=7*i-1 if item>int(num/6)+1 : break if num % item==0 : return False item=7*i+1 if item>int(num/6)+1 : break if num % item==0 : return False i+=1 return True main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; main(); operation main() pre: true post: true activity: while true do ( var data : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if data = 1 then ( break ) else skip ; var i : int := 1 ; var factlist : Sequence := Sequence{} ; while true do ( var item : double := 7 * i - 1 ; if (item->compareTo(("" + ((data / 6)))->toInteger() + 1)) > 0 then ( break ) else skip ; if data mod item = 0 then ( var quo : int := ("" + ((data / item)))->toInteger() ; if isms(quo) & ismsp(quo) then ( execute ((quo) : factlist) ) else skip ) else skip ; item := 7 * i + 1 ; if (item->compareTo(("" + ((data / 6)))->toInteger() + 1)) > 0 then ( break ) else skip ; if data mod item = 0 then ( quo := ("" + ((data / item)))->toInteger() ; if isms(quo) & ismsp(quo) then ( execute ((quo) : factlist) ) else skip ) else skip ; i := i + 1) ; factlist := factlist->sort() ; if factlist = Sequence{} then ( execute ((data) : factlist) ) else skip ; execute (("" + ((data))) + ":")->display() ; for item : factlist do ( execute ("" + ("" + ((item))))->display()) ; execute ("")->display()); operation isms(num : OclAny) : OclAny pre: true post: true activity: if num mod 7 = 1 or num mod 7 = 6 then ( return true ) else ( return false ); operation ismsp(num : OclAny) : OclAny pre: true post: true activity: i := 1 ; while true do ( item := 7 * i - 1 ; if (item->compareTo(("" + ((num / 6)))->toInteger() + 1)) > 0 then ( break ) else skip ; if num mod item = 0 then ( return false ) else skip ; item := 7 * i + 1 ; if (item->compareTo(("" + ((num / 6)))->toInteger() + 1)) > 0 then ( break ) else skip ; if num mod item = 0 then ( return false ) else skip ; i := i + 1) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,mspf): ans=[] for i in mspf : if nselect( $x | ($x - 7) mod 7 = 0 ) do ( for j : Sequence{i - 1}->union(Sequence{ i + 1 }) do ( if check[j+1] then ( execute ((j) : mspf) ) else skip ; for k : Integer.subrange(2 * j, MAX-1)->select( $x | ($x - 2 * j) mod j = 0 ) do ( check[k+1] := false))) ; while (true) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( exit() ) else skip ; ans := solve(n, mspf) ; var ans_txt : String := StringLib.sumStringsWithSeparator((((ans)->collect( _x | (OclType["String"])->apply(_x) ))), " ") ; execute (StringLib.interpolateStrings("{0}:{1}", Sequence{n, ans_txt}))->display()) ) else skip; operation solve(n : OclAny, mspf : OclAny) : OclAny pre: true post: true activity: var ans : Sequence := Sequence{} ; for i : mspf do ( if (n->compareTo(i)) < 0 then ( break ) else skip ; if n mod i = 0 then ( execute ((i) : ans) ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def divCount(n): hh=[1]*(n+1); p=2 ; while((p*p)display();; operation divCount(n : OclAny) pre: true post: true activity: var hh : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)); ; var p : int := 2; ; while (((p * p)->compareTo(n)) < 0) do ( if (hh[p+1] = 1) then ( for i : Integer.subrange((p * 2), n-1)->select( $x | ($x - (p * 2)) mod p = 0 ) do ( hh[i+1] := 0;) ) else skip ; p := p + 1;) ; var total : int := 1; ; for p : Integer.subrange(2, n + 1-1) do ( if (hh[p+1] = 1) then ( var count : int := 0; ; if (n mod p = 0) then ( while (n mod p = 0) do ( n := ("" + ((n / p)))->toInteger(); ; count := count + 1;) ; total := total * (count + 1); ) else skip ) else skip) ; return total;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=(500,100,50,10,5,1) def pay(p): cnt=0 for i in range(6): if c[i]<=p : k=p//c[i] if k>n[i]: k=n[i] cnt+=k p-=c[i]*k return-1 if p>0 else cnt k=[0]*1001 for p in range(1,1001): cnt,q=0,p for j in range(6): if c[j]<=q : cnt+=q//c[j] q %=c[j] k[p]=cnt ; while True : a=list(map(int,input().split())) p=a[0] if p==0 : break del a[0] n=a[: :-1] ans=0x7fffffff for i in range(p,p+1001): j=pay(i) if j<0 : continue ans=min(ans,j+k[i-p]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : OclAny := Sequence{500, 100, 50, 10, 5, 1} ; skip ; k := MatrixLib.elementwiseMult(Sequence{ 0 }, 1001) ; for p : Integer.subrange(1, 1001-1) do ( var q : OclAny := null; Sequence{cnt,q} := Sequence{0,p} ; for j : Integer.subrange(0, 6-1) do ( if (c[j+1]->compareTo(q)) <= 0 then ( cnt := cnt + q div c[j+1] ; q := q mod c[j+1] ) else skip) ; k[p+1] := cnt;) ; while true do ( var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; p := a->first() ; if p = 0 then ( break ) else skip ; execute (a->first())->isDeleted() ; var n : OclAny := a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var ans : int := 0x7fffffff ; for i : Integer.subrange(p, p + 1001-1) do ( var j : OclAny := pay(i) ; if j < 0 then ( continue ) else skip ; ans := Set{ans, j + k[i - p+1]}->min()) ; execute (ans)->display()); operation pay(p : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; for i : Integer.subrange(0, 6-1) do ( if (c[i+1]->compareTo(p)) <= 0 then ( var k : int := p div c[i+1] ; if (k->compareTo(n[i+1])) > 0 then ( k := n[i+1] ) else skip ; cnt := cnt + k ; p := p - c[i+1] * k ) else skip) ; return if p > 0 then -1 else cnt endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) for i in range(num): n=int(input()) result=[] i=1 while len(result)1 : print(" ".join(result)) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, num-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var result : Sequence := Sequence{} ; var i : int := 1 ; while ((result)->size()->compareTo(n)) < 0 do ( if n - (result)->size() = 1 then ( execute ((StringLib.formattedString("{n}")) : result) ) else ( execute ((StringLib.formattedString("{i}")) : result) ; if n - i = i & n - (result)->size() /= 1 then ( execute ((StringLib.formattedString("{n-i+1}")) : result) ) else (if n - i /= i & n - (result)->size() /= 1 then ( execute ((StringLib.formattedString("{n-i}")) : result) ) else skip) ) ; i := i + 1) ; if (result)->size() > 1 then ( execute (StringLib.sumStringsWithSeparator((result), " "))->display() ) else ( execute (1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- price=[1,5,10,50,100,500] while True : values=list(map(int,input().split())) p,n=values[0],values[1 :] ans=1e100 if p==0 : break p_sum=sum(map(lambda s : s[0]*s[1],zip(price,n))) for change in range(1000): total=p+change pay=[0]*6 for i in reversed(range(6)): if total>=price[i]: pay[i]=min(n[i],int(total/price[i])) total-=pay[i]*price[i] if total>0 : break coins=sum(pay) _change=change for i in reversed(range(6)): if _change>=price[i]: coins+=int(_change/price[i]) _change %=price[i] ans=min(ans,coins) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var price : Sequence := Sequence{1}->union(Sequence{5}->union(Sequence{10}->union(Sequence{50}->union(Sequence{100}->union(Sequence{ 500 }))))) ; while true do ( var values : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var p : OclAny := null; var n : OclAny := null; Sequence{p,n} := Sequence{values->first(),values->tail()} ; var ans : double := ("1e100")->toReal() ; if p = 0 then ( break ) else skip ; var p_sum : OclAny := ((Integer.subrange(1, price->size())->collect( _indx | Sequence{price->at(_indx), n->at(_indx)} ))->collect( _x | (lambda s : OclAny in (s->first() * s[1+1]))->apply(_x) ))->sum() ; for change : Integer.subrange(0, 1000-1) do ( var total : OclAny := p + change ; var pay : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 6) ; for i : (Integer.subrange(0, 6-1))->reverse() do ( if (total->compareTo(price[i+1])) >= 0 then ( pay[i+1] := Set{n[i+1], ("" + ((total / price[i+1])))->toInteger()}->min() ; total := total - pay[i+1] * price[i+1] ) else skip) ; if total > 0 then ( break ) else skip ; var coins : OclAny := (pay)->sum() ; var _change : OclAny := change ; for i : (Integer.subrange(0, 6-1))->reverse() do ( if (_change->compareTo(price[i+1])) >= 0 then ( coins := coins + ("" + ((_change / price[i+1])))->toInteger() ; _change := _change mod price[i+1] ) else skip) ; ans := Set{ans, coins}->min()) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : p,n1,n5,n10,n50,n100,n500=map(int,input().split()) if p==0 : break values=(500,100,50,10,5,1) values_cnt=(n500,n100,n50,n10,n5,n1) INF=10**20 def return_cnt(x): ret=0 for value in values : ret+=x//value x %=value return ret def make_price(x): ret=0 for value,cnt in zip(values,values_cnt): available_cnt=x//value ret+=min(available_cnt,cnt) x-=value*min(available_cnt,cnt) if x==0 : return ret return INF print(min([make_price(i)+return_cnt(i-p)for i in range(p,p+500)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var p : OclAny := null; var n1 : OclAny := null; var n5 : OclAny := null; var n10 : OclAny := null; var n50 : OclAny := null; var n100 : OclAny := null; var n500 : OclAny := null; Sequence{p,n1,n5,n10,n50,n100,n500} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if p = 0 then ( break ) else skip ; var values : OclAny := Sequence{500, 100, 50, 10, 5, 1} ; var values_cnt : OclAny := Sequence{n500, n100, n50, n10, n5, n1} ; var INF : double := (10)->pow(20) ; skip ; skip ; execute ((Integer.subrange(p, p + 500-1)->select(i | true)->collect(i | (make_price(i) + return_cnt(i - p))))->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMinimumAdjacentSwaps(arr,N): visited=[False]*(N+1) minimumSwaps=0 for i in range(2*N): if(visited[arr[i]]==False): visited[arr[i]]=True count=0 for j in range(i+1,2*N): if(visited[arr[j]]==False): count+=1 elif(arr[i]==arr[j]): minimumSwaps+=count return minimumSwaps if __name__=="__main__" : arr=[1,2,3,3,1,2] N=len(arr) N//=2 print(findMinimumAdjacentSwaps(arr,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{3}->union(Sequence{1}->union(Sequence{ 2 }))))) ; N := (arr)->size() ; N := N div 2 ; execute (findMinimumAdjacentSwaps(arr, N))->display() ) else skip; operation findMinimumAdjacentSwaps(arr : OclAny, N : OclAny) : OclAny pre: true post: true activity: var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (N + 1)) ; var minimumSwaps : int := 0 ; for i : Integer.subrange(0, 2 * N-1) do ( if (visited[arr[i+1]+1] = false) then ( visited[arr[i+1]+1] := true ; var count : int := 0 ; for j : Integer.subrange(i + 1, 2 * N-1) do ( if (visited[arr[j+1]+1] = false) then ( count := count + 1 ) else (if (arr[i+1] = arr[j+1]) then ( minimumSwaps := minimumSwaps + count ) else skip)) ) else skip) ; return minimumSwaps; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) lange=0 for i in range(1,1000000000): lange+=i if lange>=x : print(i) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lange : int := 0 ; for i : Integer.subrange(1, 1000000000-1) do ( lange := lange + i ; if (lange->compareTo(x)) >= 0 then ( execute (i)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* n=int(input()) x1=(-1+sqrt(1+8*n))//2 x2=(-1-sqrt(1+8*n))//2 ans=int(max(x1,x2)) if(ans*(ans+1))//2==n : print(ans) else : print(ans+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x1 : int := (-1 + sqrt(1 + 8 * n)) div 2 ; var x2 : int := (-1 - sqrt(1 + 8 * n)) div 2 ; var ans : int := ("" + ((Set{x1, x2}->max())))->toInteger() ; if (ans * (ans + 1)) div 2 = n then ( execute (ans)->display() ) else ( execute (ans + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_nums(num,t): return[t//num+1 if i in range(t % num)else t//num for i in range(num)] n,k,l,r,sa,sk=map(int,input().split()) ans=get_nums(k,sk)+get_nums(n-k,sa-sk) print(' '.join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; var l : OclAny := null; var r : OclAny := null; var sa : OclAny := null; var sk : OclAny := null; Sequence{n,k,l,r,sa,sk} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : OclAny := get_nums(k, sk) + get_nums(n - k, sa - sk) ; execute (StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); operation get_nums(num : OclAny, t : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, num-1)->select(i | true)->collect(i | (if (Integer.subrange(0, t mod num-1))->includes(i) then t div num + 1 else t div num endif)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,ceil print(ceil((sqrt(1+8*int(input()))-1)/2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (ceil((sqrt(1 + 8 * ("" + (((OclFile["System.in"]).readLine())))->toInteger()) - 1) / 2))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- X=int(input()) n=max(int((1+(1+8*X)**0.5)/2)-1,0) while True : if(n*(n-1)//2)>=X : break n+=1 print(n-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var X : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : OclAny := Set{("" + (((1 + ((1 + 8 * X))->pow(0.5)) / 2)))->toInteger() - 1, 0}->max() ; while true do ( if ((n * (n - 1) div 2)->compareTo(X)) >= 0 then ( break ) else skip ; n := n + 1) ; execute (n - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) import math huga=int((-1+math.sqrt(1+8*x))/2) if huga*(huga+1)==2*x : print(huga) else : print(huga+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; var huga : int := ("" + (((-1 + (1 + 8 * x)->sqrt()) / 2)))->toInteger() ; if huga * (huga + 1) = 2 * x then ( execute (huga)->display() ) else ( execute (huga + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minParentheses(p): bal=0 ans=0 for i in range(0,len(p)): if(p[i]=='('): bal+=1 else : bal+=-1 if(bal==-1): ans+=1 bal+=1 return bal+ans if __name__=='__main__' : p="())" print(minParentheses(p)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( p := "())" ; execute (minParentheses(p))->display() ) else skip; operation minParentheses(p : OclAny) : OclAny pre: true post: true activity: var bal : int := 0 ; var ans : int := 0 ; for i : Integer.subrange(0, (p)->size()-1) do ( if (p[i+1] = '(') then ( bal := bal + 1 ) else ( bal := bal + -1 ) ; if (bal = -1) then ( ans := ans + 1 ; bal := bal + 1 ) else skip) ; return bal + ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): import math n,m=map(int,input().split()) a=list(map(int,input().split())) if(ncollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if ((n->compareTo((a)->sum())) < 0) then ( execute (-1)->display() ; return 0 ) else skip ; execute (n - (a)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findevenPair(A,N): evenPair=0 for i in range(0,N): for j in range(i+1,N): if((A[i]& A[j])% 2==0): evenPair+=1 return evenPair a=[5,1,3,2] n=len(a) print(findevenPair(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : Sequence := Sequence{5}->union(Sequence{1}->union(Sequence{3}->union(Sequence{ 2 }))) ; var n : int := (a)->size() ; execute (findevenPair(a, n))->display(); operation findevenPair(A : OclAny, N : OclAny) : OclAny pre: true post: true activity: var evenPair : int := 0 ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(i + 1, N-1) do ( if ((MathLib.bitwiseAnd(A[i+1], A[j+1])) mod 2 = 0) then ( evenPair := evenPair + 1 ) else skip)) ; return evenPair; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re,os from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,radians,acos,atan,asin,log,log10,gcd from itertools import permutations,combinations,product,accumulate from operator import itemgetter,mul from copy import deepcopy from string import ascii_lowercase,ascii_uppercase,digits def debug(*args): if debugmode : print(*args) def input(): return sys.stdin.readline().strip() def STR(): return input() def INT(): return int(input()) def FLOAT(): return float(input()) def MAP(): return map(int,input().split()) def S_MAP(): return map(str,input().split()) def LIST(): return list(map(int,input().split())) def S_LIST(): return list(map(str,input().split())) def lcm(a,b): return a*b//gcd(a,b) sys.setrecursionlimit(10**9) inf=sys.maxsize mod=10**9+7 dx=[0,0,1,-1,1,-1,-1,1] dy=[1,-1,0,0,1,-1,1,-1] debugmode=True n,m=MAP() a=LIST() s=sum(a) if npow(9)) ; var Math_PINFINITY : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; var mod : double := (10)->pow(9) + 7 ; var dx : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{-1}->union(Sequence{1}->union(Sequence{-1}->union(Sequence{-1}->union(Sequence{ 1 }))))))) ; var dy : Sequence := Sequence{1}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{-1}->union(Sequence{1}->union(Sequence{ -1 }))))))) ; var debugmode : boolean := true ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := MAP() ; a := LIST() ; var s : OclAny := (a)->sum() ; if (n->compareTo(s)) < 0 then ( execute (-1)->display() ) else ( execute (n - s)->display() ); operation debug(args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) if debugmode then ( execute ((argument * (test (logical_test (comparison (expr (atom (name args))))))))->display() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation STR() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation FLOAT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation S_MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["String"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation S_LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["String"])->apply(_x) )); operation lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a * b div gcd(a, b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,*a=map(int,open(0).read().split()) print(max(-1,n-sum(a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var a : OclAny := null; Sequence{n,m,a} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{-1, n - (a)->sum()}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**7) rl=sys.stdin.readline def solve(): N,M=map(int,rl().split()) A=list(map(int,rl().split())) ans=N-sum(A) print(ans if 0<=ans else-1) if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var rl : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (rl().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((rl().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : double := N - (A)->sum() ; execute (if 0 <= ans then ans else -1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- vacation_day,homework_num=map(int,input().split()) homework_spent_list=list(map(int,input().split())) ans=vacation_day-sum(homework_spent_list) if ans<0 : print(-1) else : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var vacation_day : OclAny := null; var homework_num : OclAny := null; Sequence{vacation_day,homework_num} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var homework_spent_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : double := vacation_day - (homework_spent_list)->sum() ; if ans < 0 then ( execute (-1)->display() ) else ( execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fun(m,t): return[t//m+1 if i in range(t % m)else t//m for i in range(m)] n,k,l,r,sa,sk=map(int,input().split()) print(' '.join(map(str,fun(k,sk)+fun(n-k,sa-sk)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; var l : OclAny := null; var r : OclAny := null; var sa : OclAny := null; var sk : OclAny := null; Sequence{n,k,l,r,sa,sk} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (StringLib.sumStringsWithSeparator(((fun(k, sk) + fun(n - k, sa - sk))->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); operation fun(m : OclAny, t : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, m-1)->select(i | true)->collect(i | (if (Integer.subrange(0, t mod m-1))->includes(i) then t div m + 1 else t div m endif)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minimumSquare(a,b): result=0 rem=0 if(a0): result+=int(a/b) rem=int(a % b) a=b b=rem return result n=13 m=29 print(minimumSquare(n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := 13 ; var m : int := 29 ; execute (minimumSquare(n, m))->display(); operation minimumSquare(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; var rem : int := 0 ; if ((a->compareTo(b)) < 0) then ( Sequence{a,b} := Sequence{b,a} ) else skip ; while (b > 0) do ( result := result + ("" + ((a / b)))->toInteger() ; rem := ("" + ((a mod b)))->toInteger() ; a := b ; b := rem) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) for i in range(q): a,b,c,n=map(int,input().split()) d=max(a,b,c) e=n-((d-a)+(d-b)+(d-c)) if e % 3==0 and e>=0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var n : OclAny := null; Sequence{a,b,c,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : OclAny := Set{a, b, c}->max() ; var e : double := n - ((d - a) + (d - b) + (d - c)) ; if e mod 3 = 0 & e >= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) z=t while(z>0): z-=1 a,b,c,n=map(int,input().split()) mx=max(a,max(b,c)) s=a+b+c+n if(s % 3==0 and(s/3>=mx)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var z : int := t ; while (z > 0) do ( z := z - 1 ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var n : OclAny := null; Sequence{a,b,c,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mx : OclAny := Set{a, Set{b, c}->max()}->max() ; var s : OclAny := a + b + c + n ; if (s mod 3 = 0 & ((s / 3->compareTo(mx)) >= 0)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys a=sys.stdin.readlines() k=int(a[0]) s=0 a=a[1 :] a=[[int(a[j].split()[i])for i in range(len(a[j].split()))]for j in range(k)] for l in a : a,b,c,n=l[0],l[1],l[2],l[3] if sum(l)% 3!=0 : print('NO') else : A=(sum(l)//3)-a B=(sum(l)//3)-b C=(sum(l)//3)-c if A<0 or B<0 or C<0 : print('NO') else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := (OclFile["System.in"]).readlines() ; var k : int := ("" + ((a->first())))->toInteger() ; var s : int := 0 ; a := a->tail() ; a := Integer.subrange(0, k-1)->select(j | true)->collect(j | (Integer.subrange(0, (a[j+1].split())->size()-1)->select(i | true)->collect(i | (("" + ((a[j+1].split()[i+1])))->toInteger())))) ; for l : a do ( var b : OclAny := null; var c : OclAny := null; var n : OclAny := null; Sequence{a,b,c,n} := Sequence{l->first(),l[1+1],l[2+1],l[3+1]} ; if (l)->sum() mod 3 /= 0 then ( execute ('NO')->display() ) else ( var A : double := ((l)->sum() div 3) - a ; var B : double := ((l)->sum() div 3) - b ; var C : double := ((l)->sum() div 3) - c ; if A < 0 or B < 0 or C < 0 then ( execute ('NO')->display() ) else ( execute ('YES')->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): l=[int(i)for i in input().split(" ")] m=[max(l[: 3])-i for i in l[: 3]] if sum(m)<=l[3]and(l[3]-sum(m))% 3==0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var l : Sequence := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var m : Sequence := l.subrange(1,3)->select(i | true)->collect(i | ((l.subrange(1,3))->max() - i)) ; if ((m)->sum()->compareTo(l[3+1])) <= 0 & (l[3+1] - (m)->sum()) mod 3 = 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for test in range(t): a,b,c,n=map(int,input().split()) total=a+b+c+n if total % 3!=0 : print('NO') else : max_num=max(a,b,c) cha1=max_num-a cha2=max_num-b cha3=max_num-c if n<(cha1+cha2+cha3): print('NO') else : if(n-(cha1+cha2+cha3))% 3==0 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for test : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var n : OclAny := null; Sequence{a,b,c,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var total : OclAny := a + b + c + n ; if total mod 3 /= 0 then ( execute ('NO')->display() ) else ( var max_num : OclAny := Set{a, b, c}->max() ; var cha1 : double := max_num - a ; var cha2 : double := max_num - b ; var cha3 : double := max_num - c ; if (n->compareTo((cha1 + cha2 + cha3))) < 0 then ( execute ('NO')->display() ) else ( if (n - (cha1 + cha2 + cha3)) mod 3 = 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findEvenPair(A,N): evenPair=0 for i in range(N): for j in range(i+1,N): if(A[i]| A[j])% 2==0 : evenPair+=1 return evenPair if __name__=="__main__" : A=[5,6,2,8] N=len(A) print(findEvenPair(A,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( A := Sequence{5}->union(Sequence{6}->union(Sequence{2}->union(Sequence{ 8 }))) ; N := (A)->size() ; execute (findEvenPair(A, N))->display() ) else skip; operation findEvenPair(A : OclAny, N : OclAny) : OclAny pre: true post: true activity: var evenPair : int := 0 ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(i + 1, N-1) do ( if (MathLib.bitwiseOr(A[i+1], A[j+1])) mod 2 = 0 then ( evenPair := evenPair + 1 ) else skip)) ; return evenPair; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def findMax(arr,n): maxFirst=-sys.maxsize-1 mid=n//2 ; for i in range(0,mid): maxFirst=max(maxFirst,arr[i]) if(n % 2==1): maxFirst=max(maxFirst,arr[mid]) maxSecond=-sys.maxsize-1 for i in range(mid,n): maxSecond=max(maxSecond,arr[i]) print(maxFirst,",",maxSecond) arr=[1,12,14,5] n=len(arr) findMax(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{1}->union(Sequence{12}->union(Sequence{14}->union(Sequence{ 5 }))) ; n := (arr)->size() ; findMax(arr, n); operation findMax(arr : OclAny, n : OclAny) pre: true post: true activity: var maxFirst : double := -(trailer . (name maxsize)) - 1 ; var mid : int := n div 2; ; for i : Integer.subrange(0, mid-1) do ( maxFirst := Set{maxFirst, arr[i+1]}->max()) ; if (n mod 2 = 1) then ( maxFirst := Set{maxFirst, arr[mid+1]}->max() ) else skip ; var maxSecond : double := -(trailer . (name maxsize)) - 1 ; for i : Integer.subrange(mid, n-1) do ( maxSecond := Set{maxSecond, arr[i+1]}->max()) ; execute (maxFirst)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumPairs(arr,n): sum=0 ; for i in range(n): sum=sum+(arr[i]*(2*n)); return sum ; if __name__=="__main__" : arr=[1,2,3]; n=len(arr); print(sumPairs(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })); ; n := (arr)->size(); ; execute (sumPairs(arr, n))->display(); ) else skip; operation sumPairs(arr : OclAny, n : OclAny) pre: true post: true activity: var sum : int := 0; ; for i : Integer.subrange(0, n-1) do ( sum := sum + (arr[i+1] * (2 * n));) ; return sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def summPairs(arr,n): summ=0 for i in range(n): for j in range(n): summ+=(arr[i]+arr[j]) return summ arr=[1,2,3] n=len(arr) print(summPairs(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; n := (arr)->size() ; execute (summPairs(arr, n))->display(); operation summPairs(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var summ : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( summ := summ + (arr[i+1] + arr[j+1]))) ; return summ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maximumArea(l,b,x,y): left,right,above,below=0,0,0,0 left=x*b right=(l-x-1)*b above=l*y below=(b-y-1)*l print(max(max(left,right),max(above,below))) l=8 b=8 x=0 y=0 maximumArea(l,b,x,y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; l := 8 ; b := 8 ; x := 0 ; y := 0 ; maximumArea(l, b, x, y); operation maximumArea(l : OclAny, b : OclAny, x : OclAny, y : OclAny) pre: true post: true activity: var left : OclAny := null; var right : OclAny := null; var above : OclAny := null; var below : OclAny := null; Sequence{left,right,above,below} := Sequence{0,0,0,0} ; var left : double := x * b ; var right : double := (l - x - 1) * b ; var above : double := l * y ; var below : double := (b - y - 1) * l ; execute (Set{Set{left, right}->max(), Set{above, below}->max()}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,A,B=list(map(int,input().split(" "))) V=list(map(int,input().split(" "))) V.sort(reverse=True) max_avr=sum(V[: A])/A a_num=V.count(V[A-1]) a_pos=V[: A].count(V[A-1]) import math def nCr(n,r): f=math.factorial return f(n)//f(r)//f(n-r) if V[0]==V[A-1]: cnt=sum(nCr(a_num,i)for i in range(A,min(B,a_num)+1)) else : cnt=nCr(a_num,a_pos) print("{0:.10f}".format(max_avr)) print(int(cnt)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{N,A,B} := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var V : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; V := V->sort() ; var max_avr : double := (V.subrange(1,A))->sum() / A ; var a_num : int := V->count(V[A - 1+1]) ; var a_pos : OclAny := V.subrange(1,A)->count(V[A - 1+1]) ; skip ; skip ; if V->first() = V[A - 1+1] then ( var cnt : OclAny := ((argument (test (logical_test (comparison (expr (atom (name nCr)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a_num))))))) , (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name B))))))) , (argument (test (logical_test (comparison (expr (atom (name a_num)))))))) )))) + (expr (atom (number (integer 1)))))))))) )))))))))->sum() ) else ( cnt := nCr(a_num, a_pos) ) ; execute (StringLib.interpolateStrings("{0:.10f}", Sequence{max_avr}))->display() ; execute (("" + ((cnt)))->toInteger())->display(); operation nCr(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: var f : OclAny := ; return f(n) div f(r) div f(n - r); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def inpl(): return[int(i)for i in input().split()] def comb(a,b): return math.factorial(a)//math.factorial(a-b)//math.factorial(b) N,A,B=inpl() V=inpl() V=list(reversed(sorted(V))) x1=N-1 x2=0 for i in range(N): if V[i]==V[A]: x1=min(x1,i) x2=max(x2,i) print(sum(V[0 : A])/A) import math ans=0 if x1==0 : for l in range(A-1,min(B,x2+1)): ans+=comb(x2-x1+1,l-x1+1) print(ans) else : print(comb(x2-x1+1,A-x1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{N,A,B} := inpl() ; var V : OclAny := inpl() ; V := ((V->sort())->reverse()) ; var x1 : double := N - 1 ; var x2 : int := 0 ; for i : Integer.subrange(0, N-1) do ( if V[i+1] = V[A+1] then ( x1 := Set{x1, i}->min() ; x2 := Set{x2, i}->max() ) else skip) ; execute ((V.subrange(0+1, A))->sum() / A)->display() ; skip ; var ans : int := 0 ; if x1 = 0 then ( for l : Integer.subrange(A - 1, Set{B, x2 + 1}->min()-1) do ( ans := ans + comb(x2 - x1 + 1, l - x1 + 1)) ; execute (ans)->display() ) else ( execute (comb(x2 - x1 + 1, A - x1))->display() ); operation inpl() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation comb(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return MathLib.factorial(a) div MathLib.factorial(a - b) div MathLib.factorial(b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from operator import mul from functools import reduce def cmb(n,r): r=min(n-r,r) if r==0 : return 1 over=reduce(mul,range(n,n-r,-1)) under=reduce(mul,range(1,r+1)) return over//under N,A,B=map(int,input().split()) v=[int(c)for c in input().split()] v.sort(reverse=True) m=0 for i in range(A): m+=v[i] ans1=m/A ls=[] for j in range(A,B): m+=v[j] if ans1!=m/(j+1): break ls+=[j] T=v[: A] t=set(T) dic1={} dic2={} for c in t : dic1[c]=T.count(c) dic2[c]=v.count(c) ans2=1 for c in t : ans2*=cmb(dic2[c],dic1[c]) for l in ls : dic1[v[l]]+=1 ans2+=cmb(dic2[c],dic1[c]) print(ans1) print(ans2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{N,A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var v : Sequence := input().split()->select(c | true)->collect(c | (("" + ((c)))->toInteger())) ; v := v->sort() ; var m : int := 0 ; for i : Integer.subrange(0, A-1) do ( m := m + v[i+1]) ; var ans1 : double := m / A ; var ls : Sequence := Sequence{} ; for j : Integer.subrange(A, B-1) do ( m := m + v[j+1] ; if ans1 /= m / (j + 1) then ( break ) else skip ; ls := ls + Sequence{ j }) ; var T : OclAny := v.subrange(1,A) ; var t : Set := Set{}->union((T)) ; var dic1 : OclAny := Set{} ; var dic2 : OclAny := Set{} ; for c : t do ( dic1[c+1] := T->count(c) ; dic2[c+1] := v->count(c)) ; var ans2 : int := 1 ; for c : t do ( ans2 := ans2 * cmb(dic2[c+1], dic1[c+1])) ; for l : ls do ( dic1[v[l+1]+1] := dic1[v[l+1]+1] + 1 ; ans2 := ans2 + cmb(dic2[c+1], dic1[c+1])) ; execute (ans1)->display() ; execute (ans2)->display(); operation cmb(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: r := Set{n - r, r}->min() ; if r = 0 then ( return 1 ) else skip ; var over : OclAny := reduce(mul, Integer.subrange(n - r + 1, n)->reverse()) ; var under : OclAny := reduce(mul, Integer.subrange(1, r + 1-1)) ; return over div under; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n,a,b=map(int,input().split()) V=list(map(int,input().split())) V.sort() N=50 bikkuri=[1 for i in range(N+1)] for i in range(N): bikkuri[i+1]=(i+1)*bikkuri[i] def comb(a,b): if b==0 : return 1 else : return bikkuri[a]//(bikkuri[a-b]*bikkuri[b]) ans1=0 ans2=0 if V[-a]==V[-1]: ans1=V[-1] VC=Counter(V) num=VC[ans1] for i in range(a,min(b,num)+1): ans2+=comb(num,i) else : ans1=sum(V[-a :])/a A=list(set(V[-a :])) VC=Counter(V) num1=VC[V[-a]] VaC=Counter(V[-a :]) num2=VaC[V[-a]] ans2=comb(num1,num2) print(ans1) print(ans2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var V : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; V := V->sort() ; var N : int := 50 ; var bikkuri : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (1)) ; for i : Integer.subrange(0, N-1) do ( bikkuri[i + 1+1] := (i + 1) * bikkuri[i+1]) ; skip ; var ans1 : int := 0 ; var ans2 : int := 0 ; if V->reverse()->at(-(-a)) = V->last() then ( ans1 := V->last() ; var VC : OclAny := Counter(V) ; var num : OclAny := VC[ans1+1] ; for i : Integer.subrange(a, Set{b, num}->min() + 1-1) do ( ans2 := ans2 + comb(num, i)) ) else ( ans1 := (V.subrange(-a+1))->sum() / a ; var A : Sequence := (Set{}->union((V.subrange(-a+1)))) ; VC := Counter(V) ; var num1 : OclAny := VC[V->reverse()->at(-(-a))+1] ; var VaC : OclAny := Counter(V.subrange(-a+1)) ; var num2 : OclAny := VaC[V->reverse()->at(-(-a))+1] ; ans2 := comb(num1, num2) ) ; execute (ans1)->display() ; execute (ans2)->display(); operation comb(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if b = 0 then ( return 1 ) else ( return bikkuri[a+1] div (bikkuri[a - b+1] * bikkuri[b+1]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,A,B=list(map(int,input().split())) l=list(map(int,input().split())) l.sort(reverse=True) all_n=l.count(l[0]) from scipy.special import comb from collections import Counter l2=l[0 : A] l_c=Counter(l) max_mean=sum(l2)/A l2=Counter(l2).items() print(max_mean) ans=1 if l[0]==l[A-1]: ans=0 for i in range(A,B+1): ans+=comb(all_n,i,exact=True) print(ans) exit() for i,j in l2 : ans*=comb(l_c[i],j,exact=True) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{N,A,B} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := l->sort() ; var all_n : int := l->count(l->first()) ; skip ; skip ; var l2 : OclAny := l.subrange(0+1, A) ; var l_c : OclAny := Counter(l) ; var max_mean : double := (l2)->sum() / A ; l2 := Counter(l2)->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) ; execute (max_mean)->display() ; var ans : int := 1 ; if l->first() = l[A - 1+1] then ( ans := 0 ; for i : Integer.subrange(A, B + 1-1) do ( ans := ans + comb(all_n, i, (argument (test (logical_test (comparison (expr (atom (name exact)))))) = (test (logical_test (comparison (expr (atom (name True))))))))) ; execute (ans)->display() ; exit() ) else skip ; for _tuple : l2 do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); ans := ans * comb(l_c[i+1], j, (argument (test (logical_test (comparison (expr (atom (name exact)))))) = (test (logical_test (comparison (expr (atom (name True))))))))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout import math T=int(stdin.readline()) for i in range(T): A,B,N=map(int,stdin.readline().strip().split()) AI=list(map(int,stdin.readline().strip().split())) BI=list(map(int,stdin.readline().strip().split())) SHOTS=[] POWER_DECREASE=[] MAX=float("-inf") INDEX="X" for j in range(len(AI)): if AI[j]>MAX : MAX=AI[j] INDEX=j if INDEX!="X" : AI[INDEX],AI[-1]=AI[-1],AI[INDEX] BI[INDEX],BI[-1]=BI[-1],BI[INDEX] for j in range(len(BI)): if j!=(len(BI)-1): SHOTS.append(math.ceil(BI[j]/A)) POWER_DECREASE.append(math.ceil(BI[j]/A)*AI[j]) else : SHOTS.append(math.ceil(BI[j]/A)-1) POWER_DECREASE.append((math.ceil(BI[j]/A)-1)*AI[j]) SUM=sum(POWER_DECREASE) if(B-SUM)>=1 : stdout.write("YES\n") else : stdout.write("NO\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var T : int := ("" + ((stdin.readLine())))->toInteger() ; for i : Integer.subrange(0, T-1) do ( var A : OclAny := null; var B : OclAny := null; var N : OclAny := null; Sequence{A,B,N} := (stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var AI : Sequence := ((stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var BI : Sequence := ((stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var SHOTS : Sequence := Sequence{} ; var POWER_DECREASE : Sequence := Sequence{} ; var MAX : double := ("" + (("-inf")))->toReal() ; var INDEX : String := "X" ; for j : Integer.subrange(0, (AI)->size()-1) do ( if (AI[j+1]->compareTo(MAX)) > 0 then ( MAX := AI[j+1] ; INDEX := j ) else skip) ; if INDEX /= "X" then ( var AI->at(INDEX) : OclAny := null; var AI->last() : OclAny := null; Sequence{AI->at(INDEX),AI->last()} := Sequence{AI->last(),AI->at(INDEX)} ; var BI->at(INDEX) : OclAny := null; var BI->last() : OclAny := null; Sequence{BI->at(INDEX),BI->last()} := Sequence{BI->last(),BI->at(INDEX)} ) else skip ; for j : Integer.subrange(0, (BI)->size()-1) do ( if j /= ((BI)->size() - 1) then ( execute (((BI[j+1] / A)->ceil()) : SHOTS) ; execute (((BI[j+1] / A)->ceil() * AI[j+1]) : POWER_DECREASE) ) else ( execute (((BI[j+1] / A)->ceil() - 1) : SHOTS) ; execute ((((BI[j+1] / A)->ceil() - 1) * AI[j+1]) : POWER_DECREASE) )) ; var SUM : OclAny := (POWER_DECREASE)->sum() ; if (B - SUM) >= 1 then ( stdout.write("YES\n") ) else ( stdout.write("NO\n") )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b,n=map(int,input().split()) ea=list(map(int,input().split())) eh=list(map(int,input().split())) for x,y in sorted(zip(ea,eh)): b=b+(-y//a)*x if(b<=-x): print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var n : OclAny := null; Sequence{a,b,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ea : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var eh : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for _tuple : Integer.subrange(1, ea->size())->collect( _indx | Sequence{ea->at(_indx), eh->at(_indx)} )->sort() do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); var b : OclAny := b + (-y div a) * x) ; if ((b->compareTo(-x)) <= 0) then ( execute ("NO")->display() ) else ( execute ("YES")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findevenPair(A,N): evenPair=0 for i in range(0,N): for j in range(i+1,N): if((A[i]^ A[j])% 2==0): evenPair+=1 return evenPair ; def main(): A=[5,4,7,2,1] N=len(A) print(findevenPair(A,N)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation findevenPair(A : OclAny, N : OclAny) pre: true post: true activity: var evenPair : int := 0 ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(i + 1, N-1) do ( if ((MathLib.bitwiseXor(A[i+1], A[j+1])) mod 2 = 0) then ( evenPair := evenPair + 1 ) else skip)) ; return evenPair;; operation main() pre: true post: true activity: A := Sequence{5}->union(Sequence{4}->union(Sequence{7}->union(Sequence{2}->union(Sequence{ 1 })))) ; N := (A)->size() ; execute (findevenPair(A, N))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) t,=R() while t : t-=1 ; a,b,n=R() for x,y in sorted(zip(R(),R())): b+=-y//a*x print('YNEOS'[b<=-x : : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := R->apply() ; while t do ( t := t - 1; var a : OclAny := null; var b : OclAny := null; var n : OclAny := null; Sequence{a,b,n} := R->apply() ; for _tuple : Integer.subrange(1, R->apply()->size())->collect( _indx | Sequence{R->apply()->at(_indx), R->apply()->at(_indx)} )->sort() do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); b := b + -y div a * x) ; execute ('YNEOS'(subscript (test (logical_test (comparison (comparison (expr (atom (name b)))) <= (comparison (expr - (expr (atom (name x)))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): A,B,n=map(int,input().split()) a=[int(i)for i in input().split()] b=[int(i)for i in input().split()] d={} c='YES' for i in range(n): if a[i]not in d : d[a[i]]=[] d[a[i]].append(b[i]) s=sorted(d.keys()) for i in range(len(s)): for j in range(len(d[s[i]])): while B>=1 and d[s[i]][j]>=1 : k1=(B+s[i]-1)//s[i] k2=(d[s[i]][j]+A-1)//A m=min(k1,k2) B-=(m*s[i]) d[s[i]][j]-=(m*A) if B<=0 and d[s[-1]][-1]>=1 : c='NO' print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var A : OclAny := null; var B : OclAny := null; var n : OclAny := null; Sequence{A,B,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var b : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var d : OclAny := Set{} ; var c : String := 'YES' ; for i : Integer.subrange(0, n-1) do ( if (d)->excludes(a[i+1]) then ( d[a[i+1]+1] := Sequence{} ) else skip ; (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))) ; var s : Sequence := d.keys()->sort() ; for i : Integer.subrange(0, (s)->size()-1) do ( for j : Integer.subrange(0, (d[s[i+1]+1])->size()-1) do ( while B >= 1 & d[s[i+1]+1][j+1] >= 1 do ( var k1 : int := (B + s[i+1] - 1) div s[i+1] ; var k2 : int := (d[s[i+1]+1][j+1] + A - 1) div A ; var m : OclAny := Set{k1, k2}->min() ; B := B - (m * s[i+1]) ; d[s[i+1]+1][j+1] := d[s[i+1]+1][j+1] - (m * A)))) ; if B <= 0 & d[s->last()+1]->last() >= 1 then ( c := 'NO' ) else skip ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def alter(x,y): while(True): if(x==0 or y==0): break if(x>=2*y): x=x %(2*y) elif(y>=2*x): y=y %(2*x) else : break print("X=",x,",","Y=",y) x,y=12,5 alter(x,y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{x,y} := Sequence{12,5} ; alter(x, y); operation alter(x : OclAny, y : OclAny) pre: true post: true activity: while (true) do ( if (x = 0 or y = 0) then ( break ) else skip ; if ((x->compareTo(2 * y)) >= 0) then ( x := x mod (2 * y) ) else (if ((y->compareTo(2 * x)) >= 0) then ( y := y mod (2 * x) ) else ( break ) ) ) ; execute ("X=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for pratyush in range(int(input())): c,d,n=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) for i in range(n): d-=math.ceil(b[i]/c)*a[i] if d+max(a)>0 : print("YES") else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for pratyush : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var c : OclAny := null; var d : OclAny := null; var n : OclAny := null; Sequence{c,d,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( d := d - (b[i+1] / c)->ceil() * a[i+1]) ; if d + (a)->max() > 0 then ( execute ("YES")->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) birds=list(map(int,input().split())) m=int(input()) shots=list() for shot in range(m): shots.append(list(map(int,input().split()))) for i in range(len(shots)): wire=shots[i][0] position=shots[i][1] thisBirdIndex=wire-1 if(wire+1)in range(1,n+1): birds[thisBirdIndex+1]+=(birds[thisBirdIndex]-position) if(wire-1)in range(1,n+1): birds[thisBirdIndex-1]+=(position-1) birds[thisBirdIndex]=0 for ans in birds : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var birds : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var shots : Sequence := () ; for shot : Integer.subrange(0, m-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : shots)) ; for i : Integer.subrange(0, (shots)->size()-1) do ( var wire : OclAny := shots[i+1]->first() ; var position : OclAny := shots[i+1][1+1] ; var thisBirdIndex : double := wire - 1 ; if (Integer.subrange(1, n + 1-1))->includes((wire + 1)) then ( birds[thisBirdIndex + 1+1] := birds[thisBirdIndex + 1+1] + (birds[thisBirdIndex+1] - position) ) else skip ; if (Integer.subrange(1, n + 1-1))->includes((wire - 1)) then ( birds[thisBirdIndex - 1+1] := birds[thisBirdIndex - 1+1] + (position - 1) ) else skip ; birds[thisBirdIndex+1] := 0) ; for ans : birds do ( execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) m=int(input()) for i in range(m): x,y=list(map(int,input().split())) x=x-1 if x-1>=0 : l[x-1]+=y-1 if x+1<=n-1 : l[x+1]+=(l[x]-y) l[x]=0 for i in l : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : double := x - 1 ; if x - 1 >= 0 then ( l[x - 1+1] := l[x - 1+1] + y - 1 ) else skip ; if (x + 1->compareTo(n - 1)) <= 0 then ( l[x + 1+1] := l[x + 1+1] + (l[x+1] - y) ) else skip ; l[x+1] := 0) ; for i : l do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) m=int(input()) for i in range(m): x,y=list(map(int,input().split())) x=x-1 if x-1>=0 : l[x-1]+=y-1 if x+1<=n-1 : l[x+1]+=(l[x]-y) l[x]=0 for i in l : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : double := x - 1 ; if x - 1 >= 0 then ( l[x - 1+1] := l[x - 1+1] + y - 1 ) else skip ; if (x + 1->compareTo(n - 1)) <= 0 then ( l[x + 1+1] := l[x + 1+1] + (l[x+1] - y) ) else skip ; l[x+1] := 0) ; for i : l do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=input().split() m=int(input()) j=0 h=0 l=[] for t in x : q=int(t) l.append(q) for i in range(m): z=input().split() c=l[int(z[0])-1] b=int(z[0])-1 for i in range(c+1): if i=int(z[1]): h+=1 if b+1>=n : l[b-1]+=j-1 l[b]+=h-1 else : l[b-1]+=j-1 l[b+1]+=h-1 if b-1==-1 : l[-1]-=j-1 j=0 h=0 l[b]=0 for i in l : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : OclAny := input().split() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var j : int := 0 ; var h : int := 0 ; var l : Sequence := Sequence{} ; for t : x do ( var q : int := ("" + ((t)))->toInteger() ; execute ((q) : l)) ; for i : Integer.subrange(0, m-1) do ( var z : OclAny := input().split() ; var c : OclAny := l[("" + ((z->first())))->toInteger() - 1+1] ; var b : double := ("" + ((z->first())))->toInteger() - 1 ; for i : Integer.subrange(0, c + 1-1) do ( if (i->compareTo(("" + ((z[1+1])))->toInteger())) < 0 then ( j := j + 1 ) else (if (i->compareTo(("" + ((z[1+1])))->toInteger())) >= 0 then ( h := h + 1 ) else skip)) ; if (b + 1->compareTo(n)) >= 0 then ( l[b - 1+1] := l[b - 1+1] + j - 1 ; l[b+1] := l[b+1] + h - 1 ) else ( l[b - 1+1] := l[b - 1+1] + j - 1 ; l[b + 1+1] := l[b + 1+1] + h - 1 ) ; if b - 1 = -1 then ( l->last() := l->last() - j - 1 ) else skip ; j := 0 ; h := 0 ; l[b+1] := 0) ; for i : l do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=input().split() m=int(input()) for i in range(len(a)): a[i]=int(a[i]) for i in range(m): xandy=input().split() for l in range(len(xandy)): xandy[l]=int(xandy[l]) if xandy[0]==1 : try : a[xandy[0]]=a[xandy[0]]+a[xandy[0]-1]-xandy[1] except : pass a[xandy[0]-1]=0 continue try : a[xandy[0]-2]=a[xandy[0]-2]+xandy[1]-1 except : pass try : a[xandy[0]]=a[xandy[0]]+a[xandy[0]-1]-xandy[1] except : pass a[xandy[0]-1]=0 for ia in a : print(ia) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := input().split() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, (a)->size()-1) do ( a[i+1] := ("" + ((a[i+1])))->toInteger()) ; for i : Integer.subrange(0, m-1) do ( var xandy : OclAny := input().split() ; for l : Integer.subrange(0, (xandy)->size()-1) do ( xandy[l+1] := ("" + ((xandy[l+1])))->toInteger()) ; if xandy->first() = 1 then ( try ( a[xandy->first()+1] := a[xandy->first()+1] + a[xandy->first() - 1+1] - xandy[1+1]) catch (_e : OclException) do ( skip) ; a[xandy->first() - 1+1] := 0 ; continue ) else skip ; try ( a[xandy->first() - 2+1] := a[xandy->first() - 2+1] + xandy[1+1] - 1) catch (_e : OclException) do ( skip) ; try ( a[xandy->first()+1] := a[xandy->first()+1] + a[xandy->first() - 1+1] - xandy[1+1]) catch (_e : OclException) do ( skip) ; a[xandy->first() - 1+1] := 0) ; for ia : a do ( execute (ia)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def display(): n=5 space=n//2 num=1 for i in range(1,n+1): for j in range(1,space+1): print("",end="") count=num//2+1 for k in range(1,num+1): print(count,end="") if(k<=num//2): count=count-1 else : count=count+1 print() if(i<=n//2): space=space-1 num=num+2 else : space=space+1 num=num-2 display() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; display(); operation display() pre: true post: true activity: var n : int := 5 ; var space : int := n div 2 ; var num : int := 1 ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, space + 1-1) do ( execute ("")->display()) ; var count : int := num div 2 + 1 ; for k : Integer.subrange(1, num + 1-1) do ( execute (count)->display() ; if ((k->compareTo(num div 2)) <= 0) then ( count := count - 1 ) else ( count := count + 1 )) ; execute (->display() ; if ((i->compareTo(n div 2)) <= 0) then ( space := space - 1 ; num := num + 2 ) else ( space := space + 1 ; num := num - 2 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=3 def countPairs(a): sumr=[0 for i in range(N)] sumc=[0 for i in range(N)] for i in range(N): for j in range(N): sumr[i]+=a[i][j] sumc[j]+=a[i][j] count=0 for i in range(N): for j in range(N): if(sumc[i]>sumr[j]): count+=1 return count if __name__=='__main__' : a=[[1,2,3],[4,5,6],[7,8,9]] print(countPairs(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 3 ; skip ; if __name__ = '__main__' then ( a := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))}->union(Sequence{ Sequence{7}->union(Sequence{8}->union(Sequence{ 9 })) })) ; execute (countPairs(a))->display() ) else skip; operation countPairs(a : OclAny) : OclAny pre: true post: true activity: var sumr : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; var sumc : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( sumr[i+1] := sumr[i+1] + a[i+1][j+1] ; sumc[j+1] := sumc[j+1] + a[i+1][j+1])) ; var count : int := 0 ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( if ((sumc[i+1]->compareTo(sumr[j+1])) > 0) then ( count := count + 1 ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rangeGCD(n,m): return n if(n==m)else 1 n,m=475,475 print(rangeGCD(n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{n,m} := Sequence{475,475} ; execute (rangeGCD(n, m))->display(); operation rangeGCD(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: return if (n = m) then n else 1 endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nobleInteger(arr,size): for i in range(0,size): count=0 for j in range(0,size): if(arr[i]union(Sequence{3}->union(Sequence{20}->union(Sequence{40}->union(Sequence{ 2 })))) ; size := (arr)->size() ; var res : OclAny := nobleInteger(arr, size) ; if (res /= -1) then ( execute ("The noble integer is ")->display() ) else ( execute ("No Noble Integer Found")->display() ); operation nobleInteger(arr : OclAny, size : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, size-1) do ( var count : int := 0 ; for j : Integer.subrange(0, size-1) do ( if ((arr[i+1]->compareTo(arr[j+1])) < 0) then ( count := count + 1 ) else skip) ; if (count = arr[i+1]) then ( return arr[i+1] ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import sys def main(): N=read_int() V=read_ints() print(solve(N,V)) def solve(N,V): V.sort() pos={} for i,a in enumerate(V): pos[a]=i best=2 done=[[False]*N for _ in range(N)] for i in range(N): a=V[i] for j in range(i+1,N): if done[i][j]: continue b=V[j] d=b-a c=2 done[i][j]=True k=j v=b+d while v in pos : done[k][pos[v]]=True k=pos[v] c+=1 v+=d best=max(best,c) return best DEBUG='DEBUG' in os.environ def inp(): return sys.stdin.readline().rstrip() def read_int(): return int(inp()) def read_ints(): return[int(e)for e in inp().split()] def dprint(*value,sep=' ',end='\n'): if DEBUG : print(*value,sep=sep,end=end) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var DEBUG : boolean := (os.environ)->includes('DEBUG') ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := read_int() ; var V : OclAny := read_ints() ; execute (solve(N, V))->display(); operation solve(N : OclAny, V : OclAny) : OclAny pre: true post: true activity: V := V->sort() ; var pos : OclAny := Set{} ; for _tuple : Integer.subrange(1, (V)->size())->collect( _indx | Sequence{_indx-1, (V)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); pos[a+1] := i) ; var best : int := 2 ; var done : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ false }, N))) ; for i : Integer.subrange(0, N-1) do ( var a : OclAny := V[i+1] ; for j : Integer.subrange(i + 1, N-1) do ( if done[i+1][j+1] then ( continue ) else skip ; var b : OclAny := V[j+1] ; var d : double := b - a ; var c : int := 2 ; done[i+1][j+1] := true ; var k : OclAny := j ; var v : OclAny := b + d ; while (pos)->includes(v) do ( done[k+1][pos[v+1]+1] := true ; k := pos[v+1] ; c := c + 1 ; v := v + d) ; best := Set{best, c}->max())) ; return best; operation inp() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation read_int() : OclAny pre: true post: true activity: return ("" + ((inp())))->toInteger(); operation read_ints() : OclAny pre: true post: true activity: return inp().split()->select(e | true)->collect(e | (("" + ((e)))->toInteger())); operation dprint(value : OclAny : Sequence(OclAny), sep : String, end : String) pre: true post: true activity: (args * (named_parameter (name value))) if sep->oclIsUndefined() then sep := ' ' else skip; if end->oclIsUndefined() then end := ' ' else skip; if DEBUG then ( execute ((argument * (test (logical_test (comparison (expr (atom (name value))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) talent=list(map(int,input().split())) if(1 not in talent)or(2 not in talent)or(3 not in talent): print(0) else : num1=talent.count(1) num2=talent.count(2) num3=talent.count(3) print(min(num1,num2,num3)) while(1 in talent)and(2 in talent)and(3 in talent): i1=talent.index(1) i2=talent.index(2) i3=talent.index(3) print(i1+1,i2+1,i3+1) talent[i1]=0 talent[i2]=0 talent[i3]=0 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var talent : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if ((talent)->excludes(1)) or ((talent)->excludes(2)) or ((talent)->excludes(3)) then ( execute (0)->display() ) else ( var num1 : int := talent->count(1) ; var num2 : int := talent->count(2) ; var num3 : int := talent->count(3) ; execute (Set{num1, num2, num3}->min())->display() ; while ((talent)->includes(1)) & ((talent)->includes(2)) & ((talent)->includes(3)) do ( var i1 : int := talent->indexOf(1) - 1 ; var i2 : int := talent->indexOf(2) - 1 ; var i3 : int := talent->indexOf(3) - 1 ; execute (i1 + 1)->display() ; talent[i1+1] := 0 ; talent[i2+1] := 0 ; talent[i3+1] := 0) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lst=list(map(int,input().split())) a=[] b=[] c=[] for i in range(len(lst)): if lst[i]==1 : a.append(i+1) elif lst[i]==2 : b.append(i+1) else : c.append(i+1) teams=min(len(a),len(b),len(c)) print(teams) for i in range(teams): print(a[i],b[i],c[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; var c : Sequence := Sequence{} ; for i : Integer.subrange(0, (lst)->size()-1) do ( if lst[i+1] = 1 then ( execute ((i + 1) : a) ) else (if lst[i+1] = 2 then ( execute ((i + 1) : b) ) else ( execute ((i + 1) : c) ) ) ) ; var teams : OclAny := Set{(a)->size(), (b)->size(), (c)->size()}->min() ; execute (teams)->display() ; for i : Integer.subrange(0, teams-1) do ( execute (a[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) t=[int(i)for i in input().split()] prog,math,pe=[],[],[] progn,mathn,pen=0,0,0 for i in range(n): if t[i]==1 : prog.append(i+1) progn+=1 elif t[i]==2 : math.append(i+1) mathn+=1 else : pe.append(i+1) pen+=1 tn=min(progn,mathn,pen) print(tn) for i in range(tn): print(prog[i],math[i],pe[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var prog : OclAny := null; var math : OclAny := null; var pe : OclAny := null; Sequence{prog,math,pe} := Sequence{Sequence{},Sequence{},Sequence{}} ; var progn : OclAny := null; var mathn : OclAny := null; var pen : OclAny := null; Sequence{progn,mathn,pen} := Sequence{0,0,0} ; for i : Integer.subrange(0, n-1) do ( if t[i+1] = 1 then ( execute ((i + 1) : prog) ; progn := progn + 1 ) else (if t[i+1] = 2 then ( execute ((i + 1) : math) ; mathn := mathn + 1 ) else ( execute ((i + 1) : pe) ; pen := pen + 1 ) ) ) ; var tn : OclAny := Set{progn, mathn, pen}->min() ; execute (tn)->display() ; for i : Integer.subrange(0, tn-1) do ( execute (prog[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) t=[int(i)for i in input().split()] prog,math,pe=[],[],[] progn,mathn,pen=0,0,0 for i in range(n): if t[i]==1 : prog+=[i+1] progn+=1 elif t[i]==2 : math+=[i+1] mathn+=1 else : pe+=[i+1] pen+=1 tn=min(progn,mathn,pen) print(tn) for i in range(tn): print(prog[i],math[i],pe[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var prog : OclAny := null; var math : OclAny := null; var pe : OclAny := null; Sequence{prog,math,pe} := Sequence{Sequence{},Sequence{},Sequence{}} ; var progn : OclAny := null; var mathn : OclAny := null; var pen : OclAny := null; Sequence{progn,mathn,pen} := Sequence{0,0,0} ; for i : Integer.subrange(0, n-1) do ( if t[i+1] = 1 then ( prog := prog + Sequence{ i + 1 } ; progn := progn + 1 ) else (if t[i+1] = 2 then ( math := math + Sequence{ i + 1 } ; mathn := mathn + 1 ) else ( pe := pe + Sequence{ i + 1 } ; pen := pen + 1 ) ) ) ; var tn : OclAny := Set{progn, mathn, pen}->min() ; execute (tn)->display() ; for i : Integer.subrange(0, tn-1) do ( execute (prog[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) t=[int(i)for i in input().split()] prog,math,pe=[],[],[] progn,mathn,pen=0,0,0 for i in range(n): if t[i]==1 : prog+=[i+1] progn+=1 elif t[i]==2 : math+=[i+1] mathn+=1 else : pe+=[i+1] pen+=1 tn=min(progn,mathn,pen) print(tn) for i in range(tn): print(prog[i],math[i],pe[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var prog : OclAny := null; var math : OclAny := null; var pe : OclAny := null; Sequence{prog,math,pe} := Sequence{Sequence{},Sequence{},Sequence{}} ; var progn : OclAny := null; var mathn : OclAny := null; var pen : OclAny := null; Sequence{progn,mathn,pen} := Sequence{0,0,0} ; for i : Integer.subrange(0, n-1) do ( if t[i+1] = 1 then ( prog := prog + Sequence{ i + 1 } ; progn := progn + 1 ) else (if t[i+1] = 2 then ( math := math + Sequence{ i + 1 } ; mathn := mathn + 1 ) else ( pe := pe + Sequence{ i + 1 } ; pen := pen + 1 ) ) ) ; var tn : OclAny := Set{progn, mathn, pen}->min() ; execute (tn)->display() ; for i : Integer.subrange(0, tn-1) do ( execute (prog[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_CHAR=256 def findRepeatFirst(s): p=-1 hash=[0 for i in range(MAX_CHAR)] pos=[0 for i in range(MAX_CHAR)] for i in range(len(s)): k=ord(s[i]) if(hash[k]==0): hash[k]+=1 pos[k]=i elif(hash[k]==1): hash[k]+=1 for i in range(MAX_CHAR): if(hash[i]==2): if(p==-1): p=pos[i] elif(p>pos[i]): p=pos[i] return p if __name__=='__main__' : str="geeksforgeeks" pos=findRepeatFirst(str); if(pos==-1): print("Not found") else : print(str[pos]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_CHAR : int := 256 ; skip ; if __name__ = '__main__' then ( var OclType["String"] : String := "geeksforgeeks" ; pos := findRepeatFirst(OclType["String"]); ; if (pos = -1) then ( execute ("Not found")->display() ) else ( execute (("" + (->restrict(pos))))->display() ) ) else skip; operation findRepeatFirst(s : OclAny) : OclAny pre: true post: true activity: var p : int := -1 ; var hash : Sequence := Integer.subrange(0, MAX_CHAR-1)->select(i | true)->collect(i | (0)) ; var pos : Sequence := Integer.subrange(0, MAX_CHAR-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, (s)->size()-1) do ( var k : int := (s[i+1])->char2byte() ; if (hash[k+1] = 0) then ( hash[k+1] := hash[k+1] + 1 ; pos[k+1] := i ) else (if (hash[k+1] = 1) then ( hash[k+1] := hash[k+1] + 1 ) else skip)) ; for i : Integer.subrange(0, MAX_CHAR-1) do ( if (hash[i+1] = 2) then ( if (p = -1) then ( p := pos[i+1] ) else (if ((p->compareTo(pos[i+1])) > 0) then ( p := pos[i+1] ) else skip) ) else skip) ; return p; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) s=math.floor(math.sqrt(n)) while n % s!=0 : s-=1 s2=n//s print(s+s2-2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : double := ((n)->sqrt())->floor() ; while n mod s /= 0 do ( s := s - 1) ; var s2 : int := n div s ; execute (s + s2 - 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(inp): N=int(inp.readline().strip()) r=1001001001001 for i in range(1,min(1000000,N)+1): if N % i!=0 : continue r=min(r,i+int(N/i)-2) return str(r) def main(): result=solve(sys.stdin) if result : print(result) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(inp : OclAny) : OclAny pre: true post: true activity: var N : int := ("" + ((inp.readLine()->trim())))->toInteger() ; var r : int := 1001001001001 ; for i : Integer.subrange(1, Set{1000000, N}->min() + 1-1) do ( if N mod i /= 0 then ( continue ) else skip ; r := Set{r, i + ("" + ((N / i)))->toInteger() - 2}->min()) ; return ("" + ((r))); operation main() pre: true post: true activity: var result : OclAny := solve(OclFile["System.in"]) ; if result then ( execute (result)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n=int(input()) def make_divisors(n): divisors=[] for i in range(1,int(n**0.5)+1): if n % i==0 : divisors.append(i) if i!=n//i : divisors.append(n//i) return divisors div=make_divisors(n) a=10**12 for i in range(0,len(div[:-1]),2): a=min(a,div[i]+div[i+1]) if len(div)% 2==1 : a=min(a,div[-1]*2) print(a-2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; var div : OclAny := make_divisors(n) ; var a : double := (10)->pow(12) ; for i : Integer.subrange(0, (div->front())->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( a := Set{a, div[i+1] + div[i + 1+1]}->min()) ; if (div)->size() mod 2 = 1 then ( a := Set{a, div->last() * 2}->min() ) else skip ; execute (a - 2)->display(); operation make_divisors(n : OclAny) : OclAny pre: true post: true activity: var divisors : Sequence := Sequence{} ; for i : Integer.subrange(1, ("" + (((n)->pow(0.5))))->toInteger() + 1-1) do ( if n mod i = 0 then ( execute ((i) : divisors) ; if i /= n div i then ( execute ((n div i) : divisors) ) else skip ) else skip) ; return divisors; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def largestSubStr(s): while(len(s)and s[len(s)-1]=='1'): s=s[: len(s)-1]; if(len(s)==0): return "-1" ; else : return s ; if __name__=="__main__" : s="11001" ; print(largestSubStr(s)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "11001"; ; execute (largestSubStr(s))->display(); ) else skip; operation largestSubStr(s : OclAny) pre: true post: true activity: while ((s)->size() & s[(s)->size() - 1+1] = '1') do ( s := s.subrange(1,(s)->size() - 1);) ; if ((s)->size() = 0) then ( return "-1"; ) else ( return s; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) for i in range(num): lenz=int(input()) text=input() isExist=False for j in range(lenz-1): for k in range(j+1,lenz): a=text[j : k+1].count('a') b=text[j : k+1].count('b') if(a==b): print(f"{j+1}{k+1}") isExist=True break if isExist : break if not isExist : print("-1-1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, num-1) do ( var lenz : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var text : String := (OclFile["System.in"]).readLine() ; var isExist : boolean := false ; for j : Integer.subrange(0, lenz - 1-1) do ( for k : Integer.subrange(j + 1, lenz-1) do ( var a : OclAny := text.subrange(j+1, k + 1)->count('a') ; var b : OclAny := text.subrange(j+1, k + 1)->count('b') ; if (a = b) then ( execute (StringLib.formattedString("{j+1}{k+1}"))->display() ; isExist := true ; break ) else skip) ; if isExist then ( break ) else skip) ; if not(isExist) then ( execute ("-1-1")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import fractions def make_divisor_list(num): i=1 table=[] while i*i<=num : if num % i==0 : table.append(i) table.append(num//i) i+=1 table=list(set(table)) return table N=int(input()) divisors=sorted(make_divisor_list(N)) center=int(len(divisors)/2) if len(divisors)% 2==1 : ans=(divisors[center]-1)*2 else : ans=divisors[center]-1+divisors[center-1]-1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var divisors : Sequence := make_divisor_list(N)->sort() ; var center : int := ("" + (((divisors)->size() / 2)))->toInteger() ; if (divisors)->size() mod 2 = 1 then ( var ans : double := (divisors[center+1] - 1) * 2 ) else ( ans := divisors[center+1] - 1 + divisors[center - 1+1] - 1 ) ; execute (ans)->display(); operation make_divisor_list(num : OclAny) : OclAny pre: true post: true activity: var i : int := 1 ; var table : Sequence := Sequence{} ; while (i * i->compareTo(num)) <= 0 do ( if num mod i = 0 then ( execute ((i) : table) ; execute ((num div i) : table) ) else skip ; i := i + 1) ; table := (Set{}->union((table))) ; return table; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=10**9+7 def readInts(): return list(map(int,input().split())) def main(): n=int(input()) import math s=math.sqrt(n) i=1 mi_=float('inf') while i<=s : if n % i==0 : mi_=min(mi_,i+n//i-2) i+=1 print(mi_) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : double := (10)->pow(9) + 7 ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation readInts() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; var s : double := (n)->sqrt() ; var i : int := 1 ; var mi_ : double := ("" + (('inf')))->toReal() ; while (i->compareTo(s)) <= 0 do ( if n mod i = 0 then ( mi_ := Set{mi_, i + n div i - 2}->min() ) else skip ; i := i + 1) ; execute (mi_)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- seg=[6,2,5,5,4,5,6,3,7,6] def computeSegment(x): if(x==0): return seg[0] count=0 while(x): count+=seg[x % 10] x=x//10 return count def elementMinSegment(arr,n): minseg=computeSegment(arr[0]) minindex=0 for i in range(1,n): temp=computeSegment(arr[i]) if(tempunion(Sequence{2}->union(Sequence{5}->union(Sequence{5}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{3}->union(Sequence{7}->union(Sequence{ 6 }))))))))) ; skip ; skip ; arr := Sequence{489}->union(Sequence{206}->union(Sequence{745}->union(Sequence{123}->union(Sequence{ 756 })))) ; n := (arr)->size() ; execute (elementMinSegment(arr, n))->display(); operation computeSegment(x : OclAny) : OclAny pre: true post: true activity: if (x = 0) then ( return seg->first() ) else skip ; var count : int := 0 ; while (x) do ( count := count + seg[x mod 10+1] ; x := x div 10) ; return count; operation elementMinSegment(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var minseg : OclAny := computeSegment(arr->first()) ; var minindex : int := 0 ; for i : Integer.subrange(1, n-1) do ( var temp : OclAny := computeSegment(arr[i+1]) ; if ((temp->compareTo(minseg)) < 0) then ( minseg := temp ; minindex := i ) else skip) ; return arr[minindex+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def factorial(n): fact=1 for i in range(1,n+1): fact=fact*i return fact ; def findMiddleTerm(A,X,n): if(n % 2==0): i=int(n/2) aPow=int(math.pow(A,n-i)) xPow=int(math.pow(X,i)) middleTerm1=((math.factorial(n)/(math.factorial(n-i)*math.factorial(i)))*aPow*xPow) print("MiddleTerm={}".format(middleTerm1)) else : i=int((n-1)/2) j=int((n+1)/2) aPow=int(math.pow(A,n-i)) xPow=int(math.pow(X,i)) middleTerm1=((math.factorial(n)/(math.factorial(n-i)*math.factorial(i)))*aPow*xPow) aPow=int(math.pow(A,n-j)) xPow=int(math.pow(X,j)) middleTerm2=((math.factorial(n)/(math.factorial(n-j)*math.factorial(j)))*aPow*xPow) print("MiddleTerm1={}".format(int(middleTerm1))) print("MiddleTerm2={}".format(int(middleTerm2))) n=5 A=2 X=3 findMiddleTerm(A,X,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 5 ; A := 2 ; X := 3 ; findMiddleTerm(A, X, n); operation factorial(n : OclAny) pre: true post: true activity: var fact : int := 1 ; for i : Integer.subrange(1, n + 1-1) do ( fact := fact * i) ; return fact;; operation findMiddleTerm(A : OclAny, X : OclAny, n : OclAny) pre: true post: true activity: if (n mod 2 = 0) then ( var i : int := ("" + ((n / 2)))->toInteger() ; var aPow : int := ("" + (((A)->pow(n - i))))->toInteger() ; var xPow : int := ("" + (((X)->pow(i))))->toInteger() ; var middleTerm1 : double := ((MathLib.factorial(n) / (MathLib.factorial(n - i) * MathLib.factorial(i))) * aPow * xPow) ; execute (StringLib.interpolateStrings("MiddleTerm={}", Sequence{middleTerm1}))->display() ) else ( i := ("" + (((n - 1) / 2)))->toInteger() ; var j : int := ("" + (((n + 1) / 2)))->toInteger() ; aPow := ("" + (((A)->pow(n - i))))->toInteger() ; xPow := ("" + (((X)->pow(i))))->toInteger() ; middleTerm1 := ((MathLib.factorial(n) / (MathLib.factorial(n - i) * MathLib.factorial(i))) * aPow * xPow) ; aPow := ("" + (((A)->pow(n - j))))->toInteger() ; xPow := ("" + (((X)->pow(j))))->toInteger() ; var middleTerm2 : double := ((MathLib.factorial(n) / (MathLib.factorial(n - j) * MathLib.factorial(j))) * aPow * xPow) ; execute (StringLib.interpolateStrings("MiddleTerm1={}", Sequence{("" + ((middleTerm1)))->toInteger()}))->display() ; execute (StringLib.interpolateStrings("MiddleTerm2={}", Sequence{("" + ((middleTerm2)))->toInteger()}))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) print(a*b+a*c+b*c-a-b-c+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (a * b + a * c + b * c - a - b - c + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) answer=a*b*c-(a-1)*(b-1)*(c-1) print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var answer : double := a * b * c - (a - 1) * (b - 1) * (c - 1) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import heapq import sys import math import itertools import bisect from io import BytesIO,IOBase import os def value(): return tuple(map(int,input().split())) def values(): return tuple(map(int,sys.stdin.readline().split())) def inlst(): return[int(i)for i in input().split()] def inlsts(): return[int(i)for i in sys.stdin.readline().split()] def inp(): return int(input()) def inps(): return int(sys.stdin.readline()) def instr(): return input() def stlst(): return[i for i in input().split()] def fun(n): n-=1 return n*(1+n)//2 def solve(): a,b,c=value() tot=(b+(a-1))*(c+(a-1))-fun(a)*2 print(tot) if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation value() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation values() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inlsts() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inps() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation instr() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation stlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (i)); operation fun(n : OclAny) : OclAny pre: true post: true activity: n := n - 1 ; return n * (1 + n) div 2; operation solve() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := value() ; var tot : double := (b + (a - 1)) * (c + (a - 1)) - fun(a) * 2 ; execute (tot)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split(' ')) print(a*b+b*c+c*a-a-b-c+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; execute (a * b + b * c + c * a - a - b - c + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) ans=0 print((a+b-1)*(c-1)+a*b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; execute ((a + b - 1) * (c - 1) + a * b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class BIT : def __init__(self,n): self.n=n self.data=[0]*(n+1) self.el=[0]*(n+1) def sum(self,i): s=0 while i>0 : s+=self.data[i] i-=i &-i return s def add(self,i,x): self.el[i]+=x while i<=self.n : self.data[i]+=x i+=i &-i def get(self,i,j=None): if j is None : return self.el[i] return self.sum(j)-self.sum(i) def main(): from itertools import accumulate N,K=map(int,input().split()) A=(int(input())-K for _ in range(N)) acc=(0,)+tuple(accumulate(A)) def compress(iter): convert={x : i for i,x in enumerate(sorted(iter),start=1)} return(convert[x]for x in iter) comacc=tuple(compress(acc)) ret=0 b=BIT(len(comacc)) for x in comacc : ret+=b.sum(x) b.add(x,1) print(ret) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class BIT { static operation newBIT() : BIT pre: true post: BIT->exists( _x | result = _x ); attribute n : OclAny := n; attribute data : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); attribute el : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); operation initialise(n : OclAny) : BIT pre: true post: true activity: self.n := n ; self.data := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; self.el := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); return self; operation sum(i : OclAny) : OclAny pre: true post: true activity: var s : int := 0 ; while i > 0 do ( s := s + self.data[i+1] ; i := i - MathLib.bitwiseAnd(i, -i)) ; return s; operation add(i : OclAny,x : OclAny) pre: true post: true activity: self.el[i+1] := self.el[i+1] + x ; while (i->compareTo(self.n)) <= 0 do ( self.data[i+1] := self.data[i+1] + x ; i := i + MathLib.bitwiseAnd(i, -i)); operation get(i : OclAny,j : OclAny) : OclAny pre: true post: true activity: if j <>= null then ( return self.el[i+1] ) else skip ; return self.sum(j) - self.sum(i); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) )))) - (expr (atom (name K))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) ))))))))} ; var acc : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) ,)}->union((accumulate(A))) ; skip ; var comacc : Sequence := (compress(acc)) ; var ret : int := 0 ; var b : BIT := (BIT.newBIT()).initialise((comacc)->size()) ; for x : comacc do ( ret := ret + b.sum(x) ; execute ((x, 1) : b)) ; execute (ret)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) s=input() if len(set(s))==1 : print(-1,-1) else : a=s.count('a') b=s.count('b') if a==b : print(1,n) else : flag=0 for i in range(n-1): if s[i]!=s[i+1]: print(i+1,i+2) flag=1 break if flag==0 : print(-1,-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; if (Set{}->union((s)))->size() = 1 then ( execute (-1)->display() ) else ( var a : int := s->count('a') ; var b : int := s->count('b') ; if a = b then ( execute (1)->display() ) else ( var flag : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if s[i+1] /= s[i + 1+1] then ( execute (i + 1)->display() ; flag := 1 ; break ) else skip) ; if flag = 0 then ( execute (-1)->display() ) else skip ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=input().split() chests=input().split() keys=input().split() chest_even=0 chest_odd=0 key_odd=0 key_even=0 for chest in chests : if int(chest)% 2==0 : chest_even+=1 else : chest_odd+=1 for key in keys : if int(key)% 2==0 : key_even+=1 else : key_odd+=1 print(min(key_odd,chest_even)+min(chest_odd,key_even)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split() ; var chests : OclAny := input().split() ; var keys : OclAny := input().split() ; var chest_even : int := 0 ; var chest_odd : int := 0 ; var key_odd : int := 0 ; var key_even : int := 0 ; for chest : chests do ( if ("" + ((chest)))->toInteger() mod 2 = 0 then ( chest_even := chest_even + 1 ) else ( chest_odd := chest_odd + 1 )) ; for key : keys do ( if ("" + ((key)))->toInteger() mod 2 = 0 then ( key_even := key_even + 1 ) else ( key_odd := key_odd + 1 )) ; execute (Set{key_odd, chest_even}->min() + Set{chest_odd, key_even}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) A=[int(input())for i in range(n)] A=[a-k for a in A] from itertools import accumulate C=[0]+A C=list(accumulate(C)) class BIT : def __init__(self,n): self.n=n self.bit=[0]*(self.n+1) def init(self,init_val): for i,v in enumerate(init_val): self.add(i,v) def add(self,i,x): i+=1 while i<=self.n : self.bit[i]+=x i+=(i &-i) def sum(self,i,j): return self._sum(j)-self._sum(i) def _sum(self,i): res=0 while i>0 : res+=self.bit[i] i-=i &(-i) return res B=list(set(C)) B.sort(reverse=True) D={} for i,b in enumerate(B): D[b]=i C=[D[c]for c in C] bit=BIT(max(C)+1) ans=0 for c in C : ans+=bit.sum(c,bit.n) bit.add(c,1) print(ans) ------------------------------------------------------------ OCL File: --------- class BIT { static operation newBIT() : BIT pre: true post: BIT->exists( _x | result = _x ); attribute n : OclAny := n; attribute bit : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (self.n + 1)); operation initialise(n : OclAny) : BIT pre: true post: true activity: self.n := n ; self.bit := MatrixLib.elementwiseMult(Sequence{ 0 }, (self.n + 1)); return self; operation init(init_val : OclAny) pre: true post: true activity: for _tuple : Integer.subrange(1, (init_val)->size())->collect( _indx | Sequence{_indx-1, (init_val)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); execute ((i, v) : self)); operation add(i : OclAny,x : OclAny) pre: true post: true activity: i := i + 1 ; while (i->compareTo(self.n)) <= 0 do ( self.bit[i+1] := self.bit[i+1] + x ; i := i + (MathLib.bitwiseAnd(i, -i))); operation sum(i : OclAny,j : OclAny) : OclAny pre: true post: true activity: return self._sum(j) - self._sum(i); operation _sum(i : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; while i > 0 do ( res := res + self.bit[i+1] ; i := i - MathLib.bitwiseAnd(i, (-i))) ; return res; } class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; A := A->select(a | true)->collect(a | (a - k)) ; skip ; var C : Sequence := Sequence{ 0 }->union(A) ; C := (accumulate(C)) ; skip ; var B : Sequence := (Set{}->union((C))) ; B := B->sort() ; var D : OclAny := Set{} ; for _tuple : Integer.subrange(1, (B)->size())->collect( _indx | Sequence{_indx-1, (B)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); D[b+1] := i) ; C := C->select(c | true)->collect(c | (D[c+1])) ; var bit : BIT := (BIT.newBIT()).initialise((C)->max() + 1) ; var ans : int := 0 ; for c : C do ( ans := ans + bit.sum(c, bit.n) ; execute ((c, 1) : bit)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=list(map(int,input().split())) aa=[] for _ in range(N): a=int(input()) aa.append(a-K) raa=[0] for a in aa : raa.append(raa[-1]+a) class Searchable_BIT(): def __init__(self,N): self.N=N self.node=[0]*(self.N+1) self.cnt=0 def add(self,a): x=a self.cnt+=1 while x<=self.N : self.node[x]+=1 x+=x &-x def delete(self,x): self.cnt-=1 while x<=self.N : self.node[x]-=1 x+=x &-x def count(self,x): tmp=0 while x>0 : tmp+=self.node[x] x-=x &-x return tmp def get_maxval(self): return self.get_lower_i(self.cnt) def get_lower_i(self,i): NG=-1 OK=self.N while OK-NG>1 : mid=(OK+NG)//2 if self.count(mid)>=i : OK=mid else : NG=mid return OK a2i={a : i+1 for i,a in enumerate(sorted(list(set(raa))))} BIT=Searchable_BIT(len(a2i)+5) ans=0 for i,a in enumerate(raa): ans+=BIT.count(a2i[a]) BIT.add(a2i[a]) print(ans) ------------------------------------------------------------ OCL File: --------- class Searchable_BIT { static operation newSearchable_BIT() : Searchable_BIT pre: true post: Searchable_BIT->exists( _x | result = _x ); attribute N : OclAny := N; attribute node : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (self.N + 1)); attribute cnt : int := 0; operation initialise(N : OclAny) : pre: true post: true activity: self.N := N ; self.node := MatrixLib.elementwiseMult(Sequence{ 0 }, (self.N + 1)) ; self.cnt := 0; return self; operation add(a : OclAny) pre: true post: true activity: var x : int := a ; self.cnt := self.cnt + 1 ; while (x->compareTo(self.N)) <= 0 do ( self.node[x+1] := self.node[x+1] + 1 ; x := x + MathLib.bitwiseAnd(x, -x)); operation delete(x : OclAny) pre: true post: true activity: self.cnt := self.cnt - 1 ; while (x->compareTo(self.N)) <= 0 do ( self.node[x+1] := self.node[x+1] - 1 ; x := x + MathLib.bitwiseAnd(x, -x)); operation count(x : OclAny) : OclAny pre: true post: true activity: var tmp : int := 0 ; while x > 0 do ( tmp := tmp + self.node[x+1] ; x := x - MathLib.bitwiseAnd(x, -x)) ; return tmp; operation get_maxval() : OclAny pre: true post: true activity: return self.get_lower_i(self.cnt); operation get_lower_i(i : OclAny) : OclAny pre: true post: true activity: var NG : int := -1 ; var OK : OclAny := self.N ; while OK - NG > 1 do ( var mid : int := (OK + NG) div 2 ; if (self->count(mid)->compareTo(i)) >= 0 then ( OK := mid ) else ( NG := mid )) ; return OK; } class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var aa : Sequence := Sequence{} ; for _anon : Integer.subrange(0, N-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((a - K) : aa)) ; var raa : Sequence := Sequence{ 0 } ; for a : aa do ( execute ((raa->last() + a) : raa)) ; skip ; var a2i : Map := Integer.subrange(1, ((Set{}->union((raa)))->sort())->size())->collect( _indx | Sequence{_indx-1, ((Set{}->union((raa)))->sort())->at(_indx)} )->select(_tuple | true)->collect(_tuple | Map{a |-> i + 1})->unionAll() ; var BIT : Searchable_BIT := (Searchable_BIT.newSearchable_BIT()).initialise((a2i)->size() + 5) ; var ans : int := 0 ; for _tuple : Integer.subrange(1, (raa)->size())->collect( _indx | Sequence{_indx-1, (raa)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); ans := ans + BIT->count(a2i[a+1]) ; execute ((a2i[a+1]) : BIT)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate class BinaryIndexedTree : def __init__(self,As): self.numPow2=2**(len(As)-1).bit_length() self.data=[0]*(self.numPow2+1) for iA,A in enumerate(As): self.addValue(iA,A) def addValue(self,iA,A): iA+=1 while iA<=self.numPow2 : self.data[iA]+=A iA+=iA &-iA def getSum(self,iA): iA+=1 ans=0 while iA>0 : ans+=self.data[iA] iA-=iA &-iA return ans N,K=map(int,input().split()) As=[int(input())for _ in range(N)] Bs=list(accumulate([0]+[A-K for A in As])) iBs=list(range(N+1)) iBs.sort(key=lambda iB : Bs[iB]) BIT=BinaryIndexedTree([0]*(N+1)) ans=0 for iB in iBs : BIT.addValue(iB,1) ans+=BIT.getSum(iB-1) print(ans) ------------------------------------------------------------ OCL File: --------- class BinaryIndexedTree { static operation newBinaryIndexedTree() : BinaryIndexedTree pre: true post: BinaryIndexedTree->exists( _x | result = _x ); attribute numPow2 : double := (2)->pow(((As)->size() - 1).bit_length()); attribute data : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (self.numPow2 + 1)); operation initialise(As : OclAny) : BinaryIndexedTree pre: true post: true activity: self.numPow2 := (2)->pow(((As)->size() - 1).bit_length()) ; self.data := MatrixLib.elementwiseMult(Sequence{ 0 }, (self.numPow2 + 1)) ; for _tuple : Integer.subrange(1, (As)->size())->collect( _indx | Sequence{_indx-1, (As)->at(_indx)} ) do (var _indx : int := 1; var iA : OclAny := _tuple->at(_indx); _indx := _indx + 1; var A : OclAny := _tuple->at(_indx); self.addValue(iA, A)); return self; operation addValue(iA : OclAny,A : OclAny) pre: true post: true activity: iA := iA + 1 ; while (iA->compareTo(self.numPow2)) <= 0 do ( self.data[iA+1] := self.data[iA+1] + A ; iA := iA + MathLib.bitwiseAnd(iA, -iA)); operation getSum(iA : OclAny) : OclAny pre: true post: true activity: iA := iA + 1 ; var ans : int := 0 ; while iA > 0 do ( ans := ans + self.data[iA+1] ; iA := iA - MathLib.bitwiseAnd(iA, -iA)) ; return ans; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; As := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var Bs : Sequence := (accumulate(Sequence{ 0 }->union(As->select(A | true)->collect(A | (A - K))))) ; var iBs : Sequence := (Integer.subrange(0, N + 1-1)) ; iBs := iBs->sort() ; var BIT : BinaryIndexedTree := (BinaryIndexedTree.newBinaryIndexedTree()).initialise(MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1))) ; ans := 0 ; for iB : iBs do ( BIT.addValue(iB, 1) ; ans := ans + BIT.getSum(iB - 1)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from itertools import accumulate def solve(): n,k=map(int,sys.stdin.readline().split()) a=[int(sys.stdin.readline().rstrip())-k for i in range(n)] s=[0]+list(accumulate(a)) s=[(si,i)for(i,si)in enumerate(s)] s.sort() z=[None]*(n+1) num=-1 p=-float('inf') for i in range(n+1): if s[i][0]>p : num+=1 z[s[i][1]]=num p=s[i][0] ft=FenwickTree(num+1) ans=0 for zi in z : ans+=ft.psum(zi+1) ft.add(zi,1) print(ans) class FenwickTree : def __init__(self,n): self.n=n self.b=[0]*(n+1) def add(self,i,x): i+=1 while i<=self.n : self.b[i]+=x i+=i &(-i) def psum(self,r): res=0 while r>0 : res+=self.b[r] r-=r &(-r) return res if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FenwickTree { static operation newFenwickTree() : FenwickTree pre: true post: FenwickTree->exists( _x | result = _x ); attribute n : OclAny := n; attribute b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); operation initialise(n : OclAny) : FenwickTree pre: true post: true activity: self.n := n ; self.b := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); return self; operation add(i : OclAny,x : OclAny) pre: true post: true activity: i := i + 1 ; while (i->compareTo(self.n)) <= 0 do ( self.b[i+1] := self.b[i+1] + x ; i := i + MathLib.bitwiseAnd(i, (-i))); operation psum(r : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; while r > 0 do ( res := res + self.b[r+1] ; r := r - MathLib.bitwiseAnd(r, (-r))) ; return res; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + ((sys.stdin.readLine().rstrip())))->toInteger() - k)) ; var s : Sequence := Sequence{ 0 }->union((accumulate(a))) ; s := Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} )->select(Sequence{i, si} | true)->collect(Sequence{i, si} | (Sequence{si, i})) ; s := s->sort() ; var z : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (n + 1)) ; var num : int := -1 ; var p : double := -("" + (('inf')))->toReal() ; for i : Integer.subrange(0, n + 1-1) do ( if (s[i+1]->first()->compareTo(p)) > 0 then ( num := num + 1 ) else skip ; z[s[i+1][1+1]+1] := num ; p := s[i+1]->first()) ; var ft : OclAny := FenwickTree(num + 1) ; var ans : int := 0 ; for zi : z do ( ans := ans + ft.psum(zi + 1) ; execute ((zi, 1) : ft)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input().strip()) S=input() d={} for s in S : try : d[s]+=1 except : d[s]=1 done=False for x,y in d.items(): if y % k!=0 : print(-1) done=True break o='' if not done : for x,y in d.items(): o+=str(x)*(y//k) print(o*k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + ((input()->trim())))->toInteger() ; var S : String := (OclFile["System.in"]).readLine() ; var d : OclAny := Set{} ; for s : S->characters() do ( try ( d[s+1] := d[s+1] + 1) catch (_e : OclException) do ( d[s+1] := 1) ) ; var done : boolean := false ; for _tuple : d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if y mod k /= 0 then ( execute (-1)->display() ; done := true ; break ) else skip) ; var o : String := '' ; if not(done) then ( for _tuple : d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); o := o + ("" + ((x))) * (y div k)) ; execute (StringLib.nCopies(o, k))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() dt={} for i in s : if i in dt : dt[i]+=1 else : dt[i]=1 x=list(dt.values()) for i in range(len(x)): if x[i]% n!=0 : print('-1') break else : ans="" for i in dt : j=0 while(jtoInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var dt : OclAny := Set{} ; for i : s->characters() do ( if (dt)->includes(i) then ( dt[i+1] := dt[i+1] + 1 ) else ( dt[i+1] := 1 )) ; var x : Sequence := (dt.values()) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) % (expr (atom (name n))))) != (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '-1'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom ""))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name dt))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name j)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (compound_stmt while (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name j)))) < (comparison (expr (expr (atom (name dt)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) // (expr (atom (name n))))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name i))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name j)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans_str)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name ans))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name n))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans_str)))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) s=input() freq={} for i in s : if i in freq : freq[i]+=1 else : freq[i]=1 ans='' flag=True for i in freq : if freq[i]//k!=freq[i]/k : flag=False break else : ans+=i*(freq[i]//k) if not flag : print(-1) else : print(ans*k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var freq : OclAny := Set{} ; for i : s->characters() do ( if (freq)->includes(i) then ( freq[i+1] := freq[i+1] + 1 ) else ( freq[i+1] := 1 )) ; var ans : String := '' ; var flag : boolean := true ; for i : freq do ( if freq[i+1] div k /= freq[i+1] / k then ( flag := false ; break ) else ( ans := ans + i * (freq[i+1] div k) )) ; if not(flag) then ( execute (-1)->display() ) else ( execute (StringLib.nCopies(ans, k))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) s=input() set=set() list=[] b=0 for i in s : set.add(i) for j in set : a=s.count(j) if a % k==0 : list.append(int(a/k)*j) else : b=1 print(-1) break n=''.join([str(elem)for elem in list]) ans=k*n if b==0 : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var OclType["Set"] : Set := Set{}->union(()) ; var OclType["Sequence"] : Sequence := Sequence{} ; var b : int := 0 ; for i : s->characters() do ( execute ((i) : OclType["Set"])) ; for j : OclType["Set"] do ( var a : int := s->count(j) ; if a mod k = 0 then ( execute ((("" + ((a / k)))->toInteger() * j) : OclType["Sequence"]) ) else ( b := 1 ; execute (-1)->display() ; break )) ; var n : String := StringLib.sumStringsWithSeparator((OclType["Sequence"]->select(elem | true)->collect(elem | (("" + ((elem)))))), '') ; var ans : double := k * n ; if b = 0 then ( execute (ans)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input().strip()) S=input() d={} for s in S : try : d[s]+=1 except : d[s]=1 done=False for x,y in d.items(): if y % k!=0 : print(-1) done=True break o='' if not done : for x,y in d.items(): o+=str(x)*(y//k) print(o*k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + ((input()->trim())))->toInteger() ; var S : String := (OclFile["System.in"]).readLine() ; var d : OclAny := Set{} ; for s : S->characters() do ( try ( d[s+1] := d[s+1] + 1) catch (_e : OclException) do ( d[s+1] := 1) ) ; var done : boolean := false ; for _tuple : d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if y mod k /= 0 then ( execute (-1)->display() ; done := true ; break ) else skip) ; var o : String := '' ; if not(done) then ( for _tuple : d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); o := o + ("" + ((x))) * (y div k)) ; execute (StringLib.nCopies(o, k))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) s=input() if len(s)<=1 and 'ab' not in s : print(-1,-1) else : a1=s.find('ab') a2=s.find('ba') if a1!=-1 : print(a1+1,a1+2) elif a2!=-1 : print(a2+1,a2+2) elif a1==-1 and a2==-1 : print(-1,-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; if (s)->size() <= 1 & (s)->characters()->excludes('ab') then ( execute (-1)->display() ) else ( var a1 : int := s->indexOf('ab') - 1 ; var a2 : int := s->indexOf('ba') - 1 ; if a1 /= -1 then ( execute (a1 + 1)->display() ) else (if a2 /= -1 then ( execute (a2 + 1)->display() ) else (if a1 = -1 & a2 = -1 then ( execute (-1)->display() ) else skip ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def printPattern(radius): for i in range((2*radius)+1): for j in range((2*radius)+1): dist=math.sqrt((i-radius)*(i-radius)+(j-radius)*(j-radius)) if(dist>radius-0.5 and distsqrt() ; if ((dist->compareTo(radius - 0.5)) > 0 & (dist->compareTo(radius + 0.5)) < 0) then ( execute ("*")->display() ) else ( execute ("")->display() )) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) ca,cb=[0]*2,[0]*2 for i in a : ca[i % 2]+=1 for i in b : cb[i % 2]+=1 ans=0 for i in range(2): ans+=min(ca[i],cb[i ^ 1]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ca : OclAny := null; var cb : OclAny := null; Sequence{ca,cb} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, 2),MatrixLib.elementwiseMult(Sequence{ 0 }, 2)} ; for i : a do ( ca[i mod 2+1] := ca[i mod 2+1] + 1) ; for i : b do ( cb[i mod 2+1] := cb[i mod 2+1] + 1) ; var ans : int := 0 ; for i : Integer.subrange(0, 2-1) do ( ans := ans + Set{ca[i+1], cb[MathLib.bitwiseXor(i, 1)+1]}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) P=list(map(int,input().split())) count=0 for i in range(1,len(P)): if P[i]!=max(P[i-1 : i+2])and P[i]!=min(P[i-1 : i+2]): count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var P : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : int := 0 ; for i : Integer.subrange(1, (P)->size()-1) do ( if P[i+1] /= (P.subrange(i - 1+1, i + 2))->max() & P[i+1] /= (P.subrange(i - 1+1, i + 2))->min() then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=[int(x)for x in input().split(" ")] count=0 for i in range(1,n-1): torio=[p[i-1],p[i],p[i+1]] if p[i]==sorted(torio)[1]: count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var count : int := 0 ; for i : Integer.subrange(1, n - 1-1) do ( var torio : Sequence := Sequence{p[i - 1+1]}->union(Sequence{p[i+1]}->union(Sequence{ p[i + 1+1] })) ; if p[i+1] = sorted(torio)[1+1] then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal def s(): return input() def k(): return int(input()) def S(): return input().split() def I(): return map(int,input().split()) def X(): return list(input()) def L(): return list(input().split()) def l(): return list(map(int,input().split())) def lcm(a,b): return a*b//math.gcd(a,b) def gcd(*numbers): reduce(math.gcd,numbers) sys.setrecursionlimit(10**9) mod=10**9+7 count=0 ans=0 n=k() p=l() for i in range(1,n-1): a=[] a.append(p[i-1]) a.append(p[i]) a.append(p[i+1]) a.sort() if a.index(p[i])==1 : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var mod : double := (10)->pow(9) + 7 ; var count : int := 0 ; var ans : int := 0 ; var n : OclAny := k() ; var p : OclAny := l() ; for i : Integer.subrange(1, n - 1-1) do ( a := Sequence{} ; execute ((p[i - 1+1]) : a) ; execute ((p[i+1]) : a) ; execute ((p[i + 1+1]) : a) ; a := a->sort() ; if a->indexOf(p[i+1]) - 1 = 1 then ( count := count + 1 ) else skip) ; execute (count)->display(); operation s() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation k() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation S() : OclAny pre: true post: true activity: return input().split(); operation I() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation X() : OclAny pre: true post: true activity: return ((OclFile["System.in"]).readLine())->characters(); operation L() : OclAny pre: true post: true activity: return (input().split()); operation l() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a * b div (a)->gcd(b); operation gcd(numbers : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name numbers))) reduce(, numbers); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def logic(): n=int(input()) b=list(map(int,input().split())) count=0 i=1 while ib[i+1]: count+=1 elif b[i]b[i-1]: count+=1 i+=1 print(count) if __name__=='__main__' : logic() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( logic() ) else skip; operation logic() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : int := 0 ; var i : int := 1 ; while (i->compareTo(n - 1)) < 0 do ( if (b[i+1]->compareTo(b[i - 1+1])) < 0 then ( if (b[i+1]->compareTo(b[i + 1+1])) > 0 then ( count := count + 1 ) else skip ) else (if (b[i+1]->compareTo(b[i + 1+1])) < 0 then ( if (b[i+1]->compareTo(b[i - 1+1])) > 0 then ( count := count + 1 ) else skip ) else skip) ; i := i + 1) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[int(i)for i in input().split()] cnt=0 for i in range(1,n-1): if(l[i+1]>=l[i]and l[i-1]<=l[i])or(l[i+1]<=l[i]and l[i-1]>=l[i]): cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var cnt : int := 0 ; for i : Integer.subrange(1, n - 1-1) do ( if ((l[i + 1+1]->compareTo(l[i+1])) >= 0 & (l[i - 1+1]->compareTo(l[i+1])) <= 0) or ((l[i + 1+1]->compareTo(l[i+1])) <= 0 & (l[i - 1+1]->compareTo(l[i+1])) >= 0) then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,k=map(int,input().split()) a=list(map(int,input().split()))+[0] a=list(set(a)) a.sort() ans=[] for i in range(k): if icollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->union(Sequence{ 0 }) ; a := (Set{}->union((a))) ; a := a->sort() ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, k-1) do ( if (i->compareTo((a)->size() - 1)) < 0 then ( var ans0 : double := a[i + 1+1] - a[i+1] ) else ( ans0 := 0 ) ; execute ((ans0) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter,deque from collections import OrderedDict import math from random import randint from bisect import bisect import sys import re MOD=10**9+7 MAX=sys.maxsize MIN=-sys.maxsize class get : def int(): return list(map(int,input().split())) def str(): return input().split() def float(): return list(map(float,input().split())) def map(): return map(int,input().split()) def sqrt(x): return int(math.sqrt(x))+1 def gcd(*args): result=args[0] for item in args : result=math.gcd(result,item) return result def LCM(a,b): return(a*b)//(math.gcd(a,b)) def isPrime(n): if n==1 : return False for i in range(2,sqrt(n)): if n % i==0 : return False return True def solve(): n,k=get.map() a=get.int() if k==1 : print(min(a)) return res=[min(a)] a=list(set(a)) a.sort() for i in range(k-1): try : res.append(a[i+1]-a[i]) except : res.append(0) print(*res,sep="\n") if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class get { static operation newget() : get pre: true post: get->exists( _x | result = _x ); static operation OclType["int"]() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); static operation OclType["String"]() : OclAny pre: true post: true activity: return input().split(); static operation OclType["double"]() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["double"])->apply(_x) )); static operation map() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var MOD : double := (10)->pow(9) + 7 ; var MAX : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; var MIN : (trailer . (name maxsize)) := -(trailer . (name maxsize)) ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation sqrt(x : OclAny) : OclAny pre: true post: true activity: return ("" + (((x)->sqrt())))->toInteger() + 1; operation gcd(args : OclAny : Sequence(OclAny)) : OclAny pre: true post: true activity: (args * (named_parameter (name args))) var result : OclAny := args->first() ; for item : args do ( result := (result)->gcd(item)) ; return result; operation LCM(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a * b) div ((a)->gcd(b)); operation isPrime(n : OclAny) : OclAny pre: true post: true activity: if n = 1 then ( return false ) else skip ; for i : Integer.subrange(2, sqrt(n)-1) do ( if n mod i = 0 then ( return false ) else skip) ; return true; operation solve() pre: true post: true activity: var k : OclAny := null; Sequence{n,k} := (get.newget()).initialise.map() ; a := (get.newget()).initialise.OclType["int"]() ; if k = 1 then ( execute ((a)->min())->display() ; return ) else skip ; var res : Sequence := Sequence{ (a)->min() } ; a := (Set{}->union((a))) ; a := a->sort() ; for i : Integer.subrange(0, k - 1-1) do ( try ( execute ((a[i + 1+1] - a[i+1]) : res)) catch (_e : OclException) do ( execute ((0) : res)) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=sorted({*map(int,input().split())}) o=min(len(a),k) q=0 for i in range(o): a[i]-=q print(a[i]) q+=a[i] print("0\n"*(k-o)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Set{ (input().split())->collect( _x | (OclType["int"])->apply(_x) ) }->sort() ; var o : OclAny := Set{(a)->size(), k}->min() ; var q : int := 0 ; for i : Integer.subrange(0, o-1) do ( a[i+1] := a[i+1] - q ; execute (a[i+1])->display() ; q := q + a[i+1]) ; execute (StringLib.nCopies("0\n", (k - o)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def getSum(n): summ=0 for i in range(1,int(sqrt(n))+1): if n % i==0 : if n//i==i : summ+=i else : summ+=i summ+=n//i return summ-n def printAliquot(n): print(n,end=" ") s=set() s.add(n) nextt=0 while n>0 : n=getSum(n) if n in s : print("Repeats with",n) break print(n,end=" ") s.add(n) if __name__=="__main__" : printAliquot(12) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( printAliquot(12) ) else skip; operation getSum(n : OclAny) : OclAny pre: true post: true activity: var summ : int := 0 ; for i : Integer.subrange(1, ("" + ((sqrt(n))))->toInteger() + 1-1) do ( if n mod i = 0 then ( if n div i = i then ( summ := summ + i ) else ( summ := summ + i ; summ := summ + n div i ) ) else skip) ; return summ - n; operation printAliquot(n : OclAny) pre: true post: true activity: execute (n)->display() ; var s : Set := Set{}->union(()) ; execute ((n) : s) ; var nextt : int := 0 ; while n > 0 do ( n := getSum(n) ; if (s)->includes(n) then ( execute ("Repeats with")->display() ; break ) else skip ; execute (n)->display() ; execute ((n) : s)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) s=input() for i in range(n-1): if s[i]!=s[i+1]: print(i+1,i+2) break else : print(-1,-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) != (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 2)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() R=lambda : map(int,input().split()) n,k=R() a=iter(sorted(R())) p=0 while k : x=next((x for x in a if x>p),p); print(x-p); p=x ; k-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := R->apply() ; var a : OclAny := OclIterator.newOclIterator_Sequence(R->apply()->sort()) ; var p : int := 0 ; while k do ( var x : OclAny := (Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name x)))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name x)))) > (comparison (expr (atom (name p))))))))))}, p).next(); execute (x - p)->display(); p := x; k := k - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) arr=list(map(int,input().split())) arr_new=sorted(set(arr)) res=[] print(arr_new[0]) for i in range(1,k): if i>=len(arr_new): print(0) else : print(arr_new[i]-arr_new[i-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var arr_new : Sequence := Set{}->union((arr))->sort() ; var res : Sequence := Sequence{} ; execute (arr_new->first())->display() ; for i : Integer.subrange(1, k-1) do ( if (i->compareTo((arr_new)->size())) >= 0 then ( execute (0)->display() ) else ( execute (arr_new[i+1] - arr_new[i - 1+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): s=input() if s.find('.')!=-1 : d,f=s.split('.') else : d=s f=[] neg=d[0]=='-' if neg : d=d[1 :] output="" for i,e in enumerate(d[: :-1]): if i!=0 and i % 3==0 : output+=',' output+=e output=output[: :-1] output+='.' if len(f)>=2 : output+=f[0] output+=f[1] elif len(f)==1 : output+=f[0] output+='0' else : output+='00' if neg : print(f'(${output})') else : print(f'${output}') if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; if s->indexOf('.') - 1 /= -1 then ( var d : OclAny := null; var f : OclAny := null; Sequence{d,f} := s.split('.') ) else ( var d : String := s ; var f : Sequence := Sequence{} ) ; var neg : boolean := d->first() = '-' ; if neg then ( d := d->tail() ) else skip ; var output : String := "" ; for _tuple : Integer.subrange(1, (d(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->size())->collect( _indx | Sequence{_indx-1, (d(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var e : OclAny := _tuple->at(_indx); if i /= 0 & i mod 3 = 0 then ( output := output + ',' ) else skip ; output := output + e) ; output := output(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; output := output + '.' ; if (f)->size() >= 2 then ( output := output + f->first() ; output := output + f[1+1] ) else (if (f)->size() = 1 then ( output := output + f->first() ; output := output + '0' ) else ( output := output + '00' ) ) ; if neg then ( execute (StringLib.formattedString('(${output})'))->display() ) else ( execute (StringLib.formattedString('${output}'))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) a0,b0,a1,b1=0,0,0,0 for i in range(max(n,m)): if icollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a0 : OclAny := null; var b0 : OclAny := null; var a1 : OclAny := null; var b1 : OclAny := null; Sequence{a0,b0,a1,b1} := Sequence{0,0,0,0} ; for i : Integer.subrange(0, Set{n, m}->max()-1) do ( if (i->compareTo(n)) < 0 then ( if a[i+1] mod 2 then ( a0 := a0 + 1 ) else ( a1 := a1 + 1 ) ) else skip ; if (i->compareTo(m)) < 0 then ( if b[i+1] mod 2 then ( b0 := b0 + 1 ) else ( b1 := b1 + 1 ) ) else skip) ; var ans : OclAny := Set{a0, b1}->min() + Set{a1, b0}->min() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt factors=[] def findFactors(n): for i in range(1,int(sqrt(n))+1,1): if(n % i==0): if((n/i)==i): factors.append(i) else : factors.append(n/i) factors.append(i) def findProduct(n): product=-1 si=len(factors) for i in range(si): for j in range(si): for k in range(si): for l in range(si): s=(factors[i]+factors[j]+factors[k]+factors[l]) if(s==n): p=(factors[i]*factors[j]*factors[k]*factors[l]) if(p>product): product=p return product if __name__=='__main__' : n=10 findFactors(n) print(int(findProduct(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var factors : Sequence := Sequence{} ; skip ; skip ; if __name__ = '__main__' then ( n := 10 ; findFactors(n) ; execute (("" + ((findProduct(n))))->toInteger())->display() ) else skip; operation findFactors(n : OclAny) pre: true post: true activity: for i : Integer.subrange(1, ("" + ((sqrt(n))))->toInteger() + 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if (n mod i = 0) then ( if ((n / i) = i) then ( execute ((i) : factors) ) else ( execute ((n / i) : factors) ; execute ((i) : factors) ) ) else skip); operation findProduct(n : OclAny) : OclAny pre: true post: true activity: var product : int := -1 ; var si : int := (factors)->size() ; for i : Integer.subrange(0, si-1) do ( for j : Integer.subrange(0, si-1) do ( for k : Integer.subrange(0, si-1) do ( for l : Integer.subrange(0, si-1) do ( var s : OclAny := (factors[i+1] + factors[j+1] + factors[k+1] + factors[l+1]) ; if (s = n) then ( var p : double := (factors[i+1] * factors[j+1] * factors[k+1] * factors[l+1]) ; if ((p->compareTo(product)) > 0) then ( product := p ) else skip ) else skip)))) ; return product; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d,e=list(map(int,input().split())) x=a+b+c+d+e if x<5 : print(-1) elif x % 5==0 : print(x//5) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; Sequence{a,b,c,d,e} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := a + b + c + d + e ; if x < 5 then ( execute (-1)->display() ) else (if x mod 5 = 0 then ( execute (x div 5)->display() ) else ( execute (-1)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lista=list(map(int,input().split())) if sum(lista)==0 : print(-1) elif sum(lista)% 5==0 : print(sum(lista)//5) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lista : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (lista)->sum() = 0 then ( execute (-1)->display() ) else (if (lista)->sum() mod 5 = 0 then ( execute ((lista)->sum() div 5)->display() ) else ( execute (-1)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d,e=map(int,input().split()) if(a+b+c+d+e)% 5==0 and(a+b+c+d+e)>=5 : print((a+b+c+d+e)//5) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; Sequence{a,b,c,d,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a + b + c + d + e) mod 5 = 0 & (a + b + c + d + e) >= 5 then ( execute ((a + b + c + d + e) div 5)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d,e=map(int,input().split()) if(a+b+c+d+e)% 5==0 and(a+b+c+d+e)>=5 : print((a+b+c+d+e)//5) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; Sequence{a,b,c,d,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a + b + c + d + e) mod 5 = 0 & (a + b + c + d + e) >= 5 then ( execute ((a + b + c + d + e) div 5)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- nums=list(map(int,input().split())) n=len(nums) sum=0 for num in nums : sum+=num if(sum==0 or sum % n!=0): print("-1") else : print(sum//n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var nums : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : int := (nums)->size() ; var sum : int := 0 ; for num : nums do ( sum := sum + num) ; if (sum = 0 or sum mod n /= 0) then ( execute ("-1")->display() ) else ( execute (sum div n)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) s=input() l,r=0,-1 for i,x in enumerate(s): if x==s[l]: l=i else : r=i break if r==-1 : print(-1,-1) else : print(l+1,r+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,-1} ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); if x = s[l+1] then ( var l : OclAny := i ) else ( var r : OclAny := i ; break )) ; if r = -1 then ( execute (-1)->display() ) else ( execute (l + 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def Area(a): if(a<0): return-1 x=0.464*a A=0.70477*pow(x,2) return A a=5 print(Area(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 5 ; execute (Area(a))->display(); operation Area(a : OclAny) : OclAny pre: true post: true activity: if (a < 0) then ( return -1 ) else skip ; var x : double := 0.464 * a ; var A : double := 0.70477 * (x)->pow(2) ; return A; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() x='AHIMOTUVWXY' if len(a)==1 : if a in x : print('YES') else : print('NO') else : count=0 if a[: :-1]==a : for i in a : if i in x : count+=1 if count==len(a)and a[: :-1]==a : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var x : String := 'AHIMOTUVWXY' ; if (a)->size() = 1 then ( if (x)->characters()->includes(a) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) else ( var count : int := 0 ; if a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) = a then ( for i : a->characters() do ( if (x)->characters()->includes(i) then ( count := count + 1 ) else skip) ) else skip ; if count = (a)->size() & a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) = a then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- name=input() letters="AHIMOTUVWXY" letters=list(letters) flag=0 for letter in name : if not(letter in letters): print("NO") flag=1 break reverse=name[: :-1] if flag==0 : if reverse==name : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var name : String := (OclFile["System.in"]).readLine() ; var letters : String := "AHIMOTUVWXY" ; letters := (letters)->characters() ; var flag : int := 0 ; for letter : name->characters() do ( if not(((letters)->characters()->includes(letter))) then ( execute ("NO")->display() ; flag := 1 ; break ) else skip) ; var reverse : OclAny := name(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; if flag = 0 then ( if reverse = name then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- vet='AHIMOTUVWXY' n=list(input().strip()) res=[] for i in n : if i not in vet : res.append('NO') if n[: :-1]==n : res.append('YES') else : res.append('NO') print(res[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var vet : String := 'AHIMOTUVWXY' ; var n : Sequence := (input()->trim()) ; var res : Sequence := Sequence{} ; for i : n do ( if (vet)->characters()->excludes(i) then ( execute (('NO') : res) ) else skip) ; if n(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) = n then ( execute (('YES') : res) ) else ( execute (('NO') : res) ) ; execute (res->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) l1=[0 if i % 2==0 else 1 for i in a] l2=[0 if i % 2==0 else 1 for i in b] c1=Counter(l1) c2=Counter(l2) x=min(c1[0],c2[1]) y=min(c1[1],c2[0]) print(x+y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l1 : Sequence := a->select(i | true)->collect(i | (if i mod 2 = 0 then 0 else 1 endif)) ; var l2 : Sequence := b->select(i | true)->collect(i | (if i mod 2 = 0 then 0 else 1 endif)) ; var c1 : OclAny := Counter(l1) ; var c2 : OclAny := Counter(l2) ; var x : OclAny := Set{c1->first(), c2[1+1]}->min() ; var y : OclAny := Set{c1[1+1], c2->first()}->min() ; execute (x + y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): s=input() if s.__contains__("B")or s.__contains__("C")or s.__contains__("D")or s.__contains__("E")or s.__contains__("F")or s.__contains__("G")or s.__contains__("J")or s.__contains__("K")or s.__contains__("L")or s.__contains__("N")or s.__contains__("P")or s.__contains__("Q")or s.__contains__("R")or s.__contains__("S")or s.__contains__("Z"): print("NO") elif s==s[: :-1]: print("YES") else : print("NO") if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; if s.__contains__("B") or s.__contains__("C") or s.__contains__("D") or s.__contains__("E") or s.__contains__("F") or s.__contains__("G") or s.__contains__("J") or s.__contains__("K") or s.__contains__("L") or s.__contains__("N") or s.__contains__("P") or s.__contains__("Q") or s.__contains__("R") or s.__contains__("S") or s.__contains__("Z") then ( execute ("NO")->display() ) else (if s = s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): s=input() if s.__contains__("B")or s.__contains__("C")or s.__contains__("D")or s.__contains__("E")or s.__contains__("F")or s.__contains__("G")or s.__contains__("J")or s.__contains__("K")or s.__contains__("L")or s.__contains__("N")or s.__contains__("P")or s.__contains__("Q")or s.__contains__("R")or s.__contains__("Z")or s.__contains__("S"): print("NO") elif s==s[: :-1]: print("YES") else : print("NO") if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; if s.__contains__("B") or s.__contains__("C") or s.__contains__("D") or s.__contains__("E") or s.__contains__("F") or s.__contains__("G") or s.__contains__("J") or s.__contains__("K") or s.__contains__("L") or s.__contains__("N") or s.__contains__("P") or s.__contains__("Q") or s.__contains__("R") or s.__contains__("Z") or s.__contains__("S") then ( execute ("NO")->display() ) else (if s = s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,=map(int,input().split()) a=[] b=[] for i in range(n): at,bt,=map(int,input().split()) a.append(at) b.append(bt) c=sorted(zip(a,b)) ans=0 for(s,t)in c : if m>=t : ans+=s*t m-=t else : ans+=s*m break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; (declareIfNecessary (test (logical_test (comparison (expr (atom (name m)))))) ,) Sequence{n,(testlist_star_expr (test (logical_test (comparison (expr (atom (name m)))))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var at : OclAny := null; (declareIfNecessary (test (logical_test (comparison (expr (atom (name bt)))))) ,) Sequence{at,(testlist_star_expr (test (logical_test (comparison (expr (atom (name bt)))))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((at) : a) ; execute ((bt) : b)) ; var c : Sequence := Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), b->at(_indx)} )->sort() ; var ans : int := 0 ; for Sequence{s, t} : c do ( if (m->compareTo(t)) >= 0 then ( ans := ans + s * t ; m := m - t ) else ( ans := ans + s * m ; break )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,radians,gcd from itertools import accumulate,permutations,combinations,product,groupby,combinations_with_replacement from operator import itemgetter,mul from copy import deepcopy from string import ascii_lowercase,ascii_uppercase,digits from bisect import bisect,bisect_left from heapq import heappush,heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) def ZIP(n): return zip(*(MAP()for _ in range(n))) sys.setrecursionlimit(10**9) INF=float('inf') mod=10**9+7 N,M=MAP() AB=[LIST()for _ in range(N)] ans=0 cnt=0 AB=sorted(AB,reverse=True) while cntpow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := MAP() ; var AB : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (LIST())) ; var ans : int := 0 ; var cnt : int := 0 ; AB := AB->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; while (cnt->compareTo(M)) < 0 do ( var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := AB->last() ; if (cnt + B->compareTo(M)) <= 0 then ( cnt := cnt + B ; ans := ans + A * B ) else ( ans := ans + A * (M - cnt) ; cnt := M ) ; AB := AB->front()) ; execute (ans)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ZIP(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))`third->at(_indx)} ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=(int(x)for x in input().split()) A=sorted([[int(_)for _ in input().split()]for i in range(n)],key=lambda x : x[0]) res=0 for l in A : if m==0 : break a,b=l res+=a*min(b,m) m=max(0,m-b) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var A : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger()))))->sortedBy($x | (lambda x : OclAny in (x->first()))->apply($x)) ; var res : int := 0 ; for l : A do ( if m = 0 then ( break ) else skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := l ; res := res + a * Set{b, m}->min() ; var m : OclAny := Set{0, m - b}->max()) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np inname="input.txt" outname="output.txt" with open(inname,'r')as f : cases=int(f.readline()) for tc in range(1,cases+1): line=f.readline().strip().split(' ') N=int(line[0]) P=int(line[1]) Pi=[] R=[0]*P line=f.readline().strip().split(' ') for i in range(N): Pi.append(int(line[i])) R[Pi[i]% P]+=1 ans=0 if P==2 : ans=R[0]+(R[1]+1)//2 elif P==3 : ans=R[0] if R[1]=2 : c-=1 b-=2 ans+=1 ans+=b//4 b %=4 if c+b>0 : ans+=1 print("Case #%d: %d" %(tc,ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var inname : String := "input.txt" ; var outname : String := "output.txt" ; try (var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(inname)); var cases : int := ("" + ((f.readLine())))->toInteger() ; for tc : Integer.subrange(1, cases + 1-1) do ( var line : OclAny := f.readLine()->trim().split(' ') ; var N : int := ("" + ((line->first())))->toInteger() ; var P : int := ("" + ((line[1+1])))->toInteger() ; var Pi : Sequence := Sequence{} ; var R : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, P) ; line := f.readLine()->trim().split(' ') ; for i : Integer.subrange(0, N-1) do ( execute ((("" + ((line[i+1])))->toInteger()) : Pi) ; R[Pi[i+1] mod P+1] := R[Pi[i+1] mod P+1] + 1) ; var ans : int := 0 ; if P = 2 then ( ans := R->first() + (R[1+1] + 1) div 2 ) else (if P = 3 then ( ans := R->first() ; if (R[1+1]->compareTo(R[2+1])) < 0 then ( var a : String := R[1+1] ; var b : String := R[2+1] ) else ( a := R[2+1] ; b := R[1+1] ) ; ans := ans + a ; b := b - a ; ans := ans + (b + 2) div 3 ) else ( ans := R->first() ; if (R[1+1]->compareTo(R[3+1])) < 0 then ( a := R[1+1] ; b := R[3+1] ) else ( a := R[3+1] ; b := R[1+1] ) ; var c : String := R[2+1] ; ans := ans + c div 2 ; c := c mod 2 ; ans := ans + a ; b := b - a ; if c = 1 & b >= 2 then ( c := c - 1 ; b := b - 2 ; ans := ans + 1 ) else skip ; ans := ans + b div 4 ; b := b mod 4 ; if c + b > 0 then ( ans := ans + 1 ) else skip ) ) ; execute (StringLib.format("Case #%d: %d",Sequence{tc, ans}))->display())) catch (_e : OclException) do skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,m=map(int,input().split()) l=[list(map(int,input().split()))for _ in range(n)] l=sorted(l,key=lambda x : x[0]) p=0 for v in l : if m>=v[1]: m=m-v[1] p+=v[0]*v[1] elif mcollect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; l := l->sortedBy($x | (lambda x : OclAny in (x->first()))->apply($x)) ; var p : int := 0 ; for v : l do ( if (m->compareTo(v[1+1])) >= 0 then ( var m : double := m - v[1+1] ; p := p + v->first() * v[1+1] ) else (if (m->compareTo(v[1+1])) < 0 then ( p := p + v->first() * m ; m := 0 ) else skip) ; if m = 0 then ( break ) else skip) ; execute (p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=list(map(int,input().split())),[],0,0 for i in range(a[0]): b.append(list(map(int,input().split()))) b.sort() for i in range(a[1]): c+=b[d][0] b[d][1]-=1 if b[d][1]==0 : d+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := Sequence{((input().split())->collect( _x | (OclType["int"])->apply(_x) )),Sequence{},0,0} ; for i : Integer.subrange(0, a->first()-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : b)) ; b := b->sort() ; for i : Integer.subrange(0, a[1+1]-1) do ( c := c + b[d+1]->first() ; b[d+1][1+1] := b[d+1][1+1] - 1 ; if b[d+1][1+1] = 0 then ( d := d + 1 ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class newNode : def __init__(self,key): self.key=key self.left=None self.right=None def isSymmetric(root): if(root==None): return True if(not root.left and not root.right): return True q=[] q.append(root) q.append(root) leftNode=0 rightNode=0 while(not len(q)): leftNode=q[0] q.pop(0) rightNode=q[0] q.pop(0) if(leftNode.key!=rightNode.key): return False if(leftNode.left and rightNode.right): q.append(leftNode.left) q.append(rightNode.right) elif(leftNode.left or rightNode.right): return False if(leftNode.right and rightNode.left): q.append(leftNode.right) q.append(rightNode.left) elif(leftNode.right or rightNode.left): return False return True if __name__=='__main__' : root=newNode(1) root.left=newNode(2) root.right=newNode(2) root.left.left=newNode(3) root.left.right=newNode(4) root.right.left=newNode(4) root.right.right=newNode(3) if(isSymmetric(root)): print("The given tree is Symmetric") else : print("The given tree is not Symmetric") ------------------------------------------------------------ OCL File: --------- class newNode { static operation newnewNode() : newNode pre: true post: newNode->exists( _x | result = _x ); attribute key : OclAny := key; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(key : OclAny) : newNode pre: true post: true activity: self.key := key ; self.left := null ; self.right := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( root := (newNode.newnewNode()).initialise(1) ; root.left := (newNode.newnewNode()).initialise(2) ; root.right := (newNode.newnewNode()).initialise(2) ; root.left.left := (newNode.newnewNode()).initialise(3) ; root.left.right := (newNode.newnewNode()).initialise(4) ; root.right.left := (newNode.newnewNode()).initialise(4) ; root.right.right := (newNode.newnewNode()).initialise(3) ; if (isSymmetric(root)) then ( execute ("The given tree is Symmetric")->display() ) else ( execute ("The given tree is not Symmetric")->display() ) ) else skip; operation isSymmetric(root : OclAny) : OclAny pre: true post: true activity: if (root = null) then ( return true ) else skip ; if (not(root.left) & not(root.right)) then ( return true ) else skip ; var q : Sequence := Sequence{} ; execute ((root) : q) ; execute ((root) : q) ; var leftNode : int := 0 ; var rightNode : int := 0 ; while (not((q)->size())) do ( leftNode := q->first() ; q := q->excludingAt(0+1) ; rightNode := q->first() ; q := q->excludingAt(0+1) ; if (leftNode.key /= rightNode.key) then ( return false ) else skip ; if (leftNode.left & rightNode.right) then ( execute ((leftNode.left) : q) ; execute ((rightNode.right) : q) ) else (if (leftNode.left or rightNode.right) then ( return false ) else skip) ; if (leftNode.right & rightNode.left) then ( execute ((leftNode.right) : q) ; execute ((rightNode.left) : q) ) else (if (leftNode.right or rightNode.left) then ( return false ) else skip)) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countManipulations(s1,s2): count=0 char_count=[0]*26 for i in range(26): char_count[i]=0 for i in range(len(s1)): char_count[ord(s1[i])-ord('a')]+=1 for i in range(len(s2)): char_count[ord(s2[i])-ord('a')]-=1 if(char_count[ord(s2[i])-ord('a')]<0): count+=1 return count if __name__=="__main__" : s1="ddcf" s2="cedk" print(countManipulations(s1,s2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s1 := "ddcf" ; s2 := "cedk" ; execute (countManipulations(s1, s2))->display() ) else skip; operation countManipulations(s1 : OclAny, s2 : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var char_count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for i : Integer.subrange(0, 26-1) do ( char_count[i+1] := 0) ; for i : Integer.subrange(0, (s1)->size()-1) do ( char_count[(s1[i+1])->char2byte() - ('a')->char2byte()+1] := char_count[(s1[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; for i : Integer.subrange(0, (s2)->size()-1) do ( char_count[(s2[i+1])->char2byte() - ('a')->char2byte()+1] := char_count[(s2[i+1])->char2byte() - ('a')->char2byte()+1] - 1 ; if (char_count[(s2[i+1])->char2byte() - ('a')->char2byte()+1] < 0) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline inf=float('inf') def getInt(): return int(input()) def getStr(): return input().strip() def getList(split=True): s=getStr() if split : s=s.split() return map(int,s) t=getInt() def solve(): x,y=getList() from math import hypot if x==y==0 : print(0) else : if hypot(x,y)% 1==0 : print(1) else : print(2) for _ in range(t): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; skip ; skip ; skip ; var t : OclAny := getInt() ; skip ; for _anon : Integer.subrange(0, t-1) do ( solve()); operation getInt() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation getStr() : OclAny pre: true post: true activity: return input()->trim(); operation getList(split : OclAny) : OclAny pre: true post: true activity: if split->oclIsUndefined() then split := true else skip; var s : OclAny := getStr() ; if split then ( s := s.split() ) else skip ; return (s)->collect( _x | (OclType["int"])->apply(_x) ); operation solve() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := getList() ; skip ; if x = y & (y == 0) then ( execute (0)->display() ) else ( if hypot(x, y) mod 1 = 0 then ( execute (1)->display() ) else ( execute (2)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=(int(i)for i in input().split()) a=(int(i)for i in input().split()) b=(int(i)for i in input().split()) odd_a=sum(1 for i in a if i & 1==1) odd_b=sum(1 for i in b if i & 1==1) res=min(odd_b,(n-odd_a))+min(odd_a,(m-odd_b)) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var a : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var b : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var odd_a : OclAny := ((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name a))))) (comp_iter if (test (logical_test (comparison (comparison (expr (expr (atom (name i))) & (expr (atom (number (integer 1)))))) == (comparison (expr (atom (number (integer 1))))))))))))->sum() ; var odd_b : OclAny := ((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name b))))) (comp_iter if (test (logical_test (comparison (comparison (expr (expr (atom (name i))) & (expr (atom (number (integer 1)))))) == (comparison (expr (atom (number (integer 1))))))))))))->sum() ; var res : OclAny := Set{odd_b, (n - odd_a)}->min() + Set{odd_a, (m - odd_b)}->min() ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x,y=map(int,input().split()) a=(x**2+y**2)**0.5 if x==0 and y==0 : print(0) elif int(a)==a : print(1) else : print(2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : double := (((x)->pow(2) + (y)->pow(2)))->pow(0.5) ; if x = 0 & y = 0 then ( execute (0)->display() ) else (if ("" + ((a)))->toInteger() = a then ( execute (1)->display() ) else ( execute (2)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math t=int(input()) while t>0 : x,y=map(int,input().split()) print(0 if x==0 and y==0 else 1 if math.sqrt(x**2+y**2)==int(math.sqrt(x**2+y**2))else 2) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if x = 0 & y = 0 then 0 else if ((x)->pow(2) + (y)->pow(2))->sqrt() = ("" + ((((x)->pow(2) + (y)->pow(2))->sqrt())))->toInteger() then 1 else 2 endif endif)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* for i in range(int(input())): x,y=map(int,input().split()) if x==0 and y==0 : print(0) elif x==0 or y==0 : print(1) else : p=x**2+y**2 q=sqrt(p) r=int(q) if q-r==0 : print(1) else : print(2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x = 0 & y = 0 then ( execute (0)->display() ) else (if x = 0 or y = 0 then ( execute (1)->display() ) else ( var p : double := (x)->pow(2) + (y)->pow(2) ; var q : OclAny := sqrt(p) ; var r : int := ("" + ((q)))->toInteger() ; if q - r = 0 then ( execute (1)->display() ) else ( execute (2)->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): co=input().split() co[0]=int(co[0]) co[1]=int(co[1]) if co[1]==co[0]and co[0]==0 : print(0) else : sum=co[0]**2+co[1]**2 a=1 b=False while a**2<=sum : if a**2==sum : print(1) b=True break a+=1 if not b : print(2) t=int(input()) while t>0 : solve() t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( solve() ; t := t - 1); operation solve() pre: true post: true activity: var co : OclAny := input().split() ; co->first() := ("" + ((co->first())))->toInteger() ; co[1+1] := ("" + ((co[1+1])))->toInteger() ; if co[1+1] = co->first() & co->first() = 0 then ( execute (0)->display() ) else ( var sum : double := (co->first())->pow(2) + (co[1+1])->pow(2) ; var a : int := 1 ; var b : boolean := false ; while ((a)->pow(2)->compareTo(sum)) <= 0 do ( if (a)->pow(2) = sum then ( execute (1)->display() ; b := true ; break ) else skip ; a := a + 1) ; if not(b) then ( execute (2)->display() ) else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maximizeFreshChocolate(N,P,groups): remainingGroups=groups result=0 while len(remainingGroups)>0 : optimalSets={} optimalCounts={} for index in xrange(len(remainingGroups)): tempOptimalSets={} tempOptimalCounts={} for remainder in optimalCounts : possibleRemainder=(remainder+remainingGroups[index])% P if optimalCounts[remainder]+1toInteger() ; for i : xrange(cases) do (suite)) catch (_e : OclException) do skip) catch (_e : OclException) do skip ; Sequence{N}->union(Sequence{ P }) := (infile.readLine().split(' '))->collect( _x | (OclType["int"])->apply(_x) ); operation maximizeFreshChocolate(N : OclAny, P : OclAny, groups : OclAny) : OclAny pre: true post: true activity: var remainingGroups : OclAny := groups ; var result : int := 0 ; while (remainingGroups)->size() > 0 do ( var optimalSets : OclAny := Set{} ; var optimalCounts : OclAny := Set{} ; for index : xrange((remainingGroups)->size()) do ( var tempOptimalSets : OclAny := Set{} ; var tempOptimalCounts : OclAny := Set{} ; for remainder : optimalCounts do ( var possibleRemainder : int := (remainder + remainingGroups[index+1]) mod P ; if (optimalCounts[remainder+1] + 1->compareTo(tempOptimalCounts.get(possibleRemainder, (10)->pow(18)))) < 0 then ( tempOptimalSets[possibleRemainder+1] := optimalSets[remainder+1]->union(Sequence{ index }) ; tempOptimalCounts[possibleRemainder+1] := optimalCounts[remainder+1] + 1 ) else skip) ; tempOptimalSets[remainingGroups[index+1] mod P+1] := Sequence{ index } ; tempOptimalCounts[remainingGroups[index+1] mod P+1] := 1 ; for remainder : tempOptimalCounts do ( if (tempOptimalCounts[remainder+1]->compareTo(optimalCounts.get(remainder, (10)->pow(18)))) < 0 then ( optimalSets[remainder+1] := tempOptimalSets[remainder+1] ; optimalCounts[remainder+1] := tempOptimalCounts[remainder+1] ) else skip)) ; if (optimalCounts)->includes(0) then ( result := result + 1 ; remainingGroups := xrange((remainingGroups)->size())->select(i | (optimalSets->first())->excludes(i))->collect(i | (remainingGroups[i+1])) ) else ( return result + 1 )) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findLength(arr,n): x=0 ; for i in range(n): x=max(x,arr[i]); ans=0 ; for i in range(n): if(arr[i]!=x): continue ; j=i ; while(arr[j]==x): j+=1 ; if j>=n : break ans=max(ans,j-i); return ans ; if __name__=="__main__" : arr=[1,2,2]; n=len(arr); print(findLength(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{ 2 })); ; n := (arr)->size(); ; execute (findLength(arr, n))->display(); ) else skip; operation findLength(arr : OclAny, n : OclAny) pre: true post: true activity: var x : int := 0; ; for i : Integer.subrange(0, n-1) do ( x := Set{x, arr[i+1]}->max();) ; var ans : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] /= x) then ( continue; ) else skip ; var j : OclAny := i; ; while (arr[j+1] = x) do ( j := j + 1; ; if (j->compareTo(n)) >= 0 then ( break ) else skip) ; ans := Set{ans, j - i}->max();) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countIncreasing(arr,n): cnt=0 for i in range(0,n): for j in range(i+1,n): if arr[j]>arr[j-1]: cnt+=1 else : break return cnt arr=[1,2,2,4] n=len(arr) print("Count of strictly increasing subarrays is",countIncreasing(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 4 }))) ; n := (arr)->size() ; execute ("Count of strictly increasing subarrays is")->display(); operation countIncreasing(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if (arr[j+1]->compareTo(arr[j - 1+1])) > 0 then ( cnt := cnt + 1 ) else ( break ))) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math class Node : def __init__(self,data): self.data=data self.next=None def push(head,data): if not head : return Node(data) temp=Node(data) temp.next=head head=temp return head def uniqueElements(head): _map={} temp=head while(temp): d=temp.data if d in _map : _map[d]=_map.get(d)+1 else : _map[d]=1 temp=temp.next count=0 for i in _map : if _map.get(i)==1 : count+=1 print("{}".format(i),end="") if count==0 : print("No Unique Elements") if __name__=='__main__' : head=None head=push(head,5) head=push(head,4) head=push(head,3) head=push(head,5) head=push(head,3) head=push(head,2) head=push(head,4) head=push(head,4) head=push(head,1) uniqueElements(head) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.next := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( head := null ; head := push(head, 5) ; head := push(head, 4) ; head := push(head, 3) ; head := push(head, 5) ; head := push(head, 3) ; head := push(head, 2) ; head := push(head, 4) ; head := push(head, 4) ; head := push(head, 1) ; uniqueElements(head) ) else skip; operation push(head : OclAny, data : OclAny) : OclAny pre: true post: true activity: if not(head) then ( return (Node.newNode()).initialise(data) ) else skip ; var temp : Node := (Node.newNode()).initialise(data) ; temp.next := head ; head := temp ; return head; operation uniqueElements(head : OclAny) pre: true post: true activity: var _map : OclAny := Set{} ; temp := head ; while (temp) do ( var d : OclAny := temp.data ; if (_map)->includes(d) then ( _map[d+1] := _map.get(d) + 1 ) else ( _map[d+1] := 1 ) ; temp := temp.next) ; var count : int := 0 ; for i : _map do ( if _map.get(i) = 1 then ( count := count + 1 ; execute (StringLib.interpolateStrings("{}", Sequence{i}))->display() ) else skip) ; if count = 0 then ( execute ("No Unique Elements")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=str(input()) try : N.index("9") print("Yes") except ValueError : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : String := ("" + (((OclFile["System.in"]).readLine()))) ; try ( N->indexOf("9") - 1 ; execute ("Yes")->display()) (except_clause except (test (logical_test (comparison (expr (atom (name ValueError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "No"))))))) )))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print('NYoe s'['9' in input(): : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ('NYoe s'(subscript (test (logical_test (comparison (comparison (expr (atom '9'))) in (comparison (expr (atom (name input)) (trailer (arguments ( )))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines n=list(readline().decode().rstrip()) print('Yes' if '9' in n else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; var n : Sequence := (readline().decode().rstrip()) ; execute (if (n)->includes('9') then 'Yes' else 'No' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) r=[list(map(int,input().split()))for _ in range(n)] b=[list(map(int,input().split()))for _ in range(n)] r.sort() b.sort() s=[] k=0 ans=0 for i in range(n): while True : if k>=n : break if b[i][0]>r[k][0]: s.append(r[k][1]) k+=1 else : s.sort() break for j in range(len(s)-1,-1,-1): if s[j]toInteger() ; var r : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var b : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; r := r->sort() ; b := b->sort() ; var s : Sequence := Sequence{} ; var k : int := 0 ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( while true do ( if (k->compareTo(n)) >= 0 then ( break ) else skip ; if (b[i+1]->first()->compareTo(r[k+1]->first())) > 0 then ( execute ((r[k+1][1+1]) : s) ; k := k + 1 ) else ( s := s->sort() ; break )) ; for j : Integer.subrange(-1 + 1, (s)->size() - 1)->reverse() do ( if (s[j+1]->compareTo(b[i+1][1+1])) < 0 then ( ans := ans + 1 ; execute ((s[j+1]) /: s) ; break ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=lambda x : list(map(int,x)) a=a(input()) if 9 in a : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Function := lambda x : OclAny in (((x)->collect( _x | (OclType["int"])->apply(_x) ))) ; a := a->apply((OclFile["System.in"]).readLine()) ; if (a)->includes(9) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) print("Yes" if N % 10==9 or(N//10)% 10==9 else "No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (if N mod 10 = 9 or (N div 10) mod 10 = 9 then "Yes" else "No" endif)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def longDivision(number,divisor): ans="" ; idx=0 ; temp=ord(number[idx])-ord('0'); while(tempidx): ans+=chr(math.floor(temp//divisor)+ord('0')); temp=((temp % divisor)*10+ord(number[idx])-ord('0')); idx+=1 ; ans+=chr(math.floor(temp//divisor)+ord('0')); if(len(ans)==0): return "0" ; return ans ; number="1248163264128256512" ; divisor=125 ; print(longDivision(number,divisor)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; number := "1248163264128256512"; ; divisor := 125; ; execute (longDivision(number, divisor))->display();; operation longDivision(number : OclAny, divisor : OclAny) pre: true post: true activity: var ans : String := ""; ; var idx : int := 0; ; var temp : double := (number[idx+1])->char2byte() - ('0')->char2byte(); ; while ((temp->compareTo(divisor)) < 0) do ( temp := (temp * 10 + (number[idx + 1+1])->char2byte() - ('0')->char2byte()); ; idx := idx + 1;) ; idx := idx + 1; ; while ((((number)->size())->compareTo(idx)) > 0) do ( ans := ans + ((temp div divisor)->floor() + ('0')->char2byte())->byte2char(); ; temp := ((temp mod divisor) * 10 + (number[idx+1])->char2byte() - ('0')->char2byte()); ; idx := idx + 1;) ; ans := ans + ((temp div divisor)->floor() + ('0')->char2byte())->byte2char(); ; if ((ans)->size() = 0) then ( return "0"; ) else skip ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inputF=open('A-large.in','r') output=open('A-large.out','w') numCases=int(inputF.readline()) def getFreshGroups(groups,p): count=0 groups=[i % p for i in groups] count+=groups.count(0) groups=[g for g in groups if g!=0] if p==2 and len(groups)>0 : count+=(len(groups)+1)/2 elif p==3 and len(groups)>0 : minMod=min(groups.count(1),groups.count(2)) count+=minMod remaining=max(groups.count(1),groups.count(2))-min(groups.count(1),groups.count(2)) count+=(remaining+2)/3 elif p==4 and len(groups)>0 : count+=(groups.count(2))/2 extraTwo=((groups.count(2)% 2)==1) minMod=min(groups.count(1),groups.count(3)) count+=minMod remaining=max(groups.count(1),groups.count(3))-min(groups.count(1),groups.count(3)) if extraTwo : count+=1+(remaining+1)/4 else : count+=(remaining+3)/4 return count for i in range(numCases): n,p=inputF.readline().split() groups=[int(j)for j in inputF.readline().split()] numFresh=getFreshGroups(groups,int(p)) output.write('Case #'+str(i+1)+': '+str(numFresh)+'\n') inputF.close() output.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inputF : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('A-large.in')) ; var output : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('A-large.out')) ; var numCases : int := ("" + ((inputF.readLine())))->toInteger() ; skip ; for i : Integer.subrange(0, numCases-1) do ( var n : OclAny := null; Sequence{n,p} := inputF.readLine().split() ; groups := inputF.readLine().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; var numFresh : OclAny := getFreshGroups(groups, ("" + ((p)))->toInteger()) ; output.write('Case #' + ("" + ((i + 1))) + ': ' + ("" + ((numFresh))) + ' ')) ; inputF.closeFile() ; output.closeFile(); operation getFreshGroups(groups : OclAny, p : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; groups := groups->select(i | true)->collect(i | (i mod p)) ; count := count + groups->count(0) ; groups := groups->select(g | g /= 0)->collect(g | (g)) ; if p = 2 & (groups)->size() > 0 then ( count := count + ((groups)->size() + 1) / 2 ) else (if p = 3 & (groups)->size() > 0 then ( var minMod : OclAny := Set{groups->count(1), groups->count(2)}->min() ; count := count + minMod ; var remaining : double := Set{groups->count(1), groups->count(2)}->max() - Set{groups->count(1), groups->count(2)}->min() ; count := count + (remaining + 2) / 3 ) else (if p = 4 & (groups)->size() > 0 then ( count := count + (groups->count(2)) / 2 ; var extraTwo : boolean := ((groups->count(2) mod 2) = 1) ; minMod := Set{groups->count(1), groups->count(3)}->min() ; count := count + minMod ; remaining := Set{groups->count(1), groups->count(3)}->max() - Set{groups->count(1), groups->count(3)}->min() ; if extraTwo then ( count := count + 1 + (remaining + 1) / 4 ) else ( count := count + (remaining + 3) / 4 ) ) else skip ) ) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rhombusarea(l,b): if(l<0 or b<0): return-1 return(l*b)/2 if __name__=='__main__' : l=16 b=6 print(rhombusarea(l,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( l := 16 ; b := 6 ; execute (rhombusarea(l, b))->display() ) else skip; operation rhombusarea(l : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (l < 0 or b < 0) then ( return -1 ) else skip ; return (l * b) / 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ls=list(map(int,input().split())) maxm=max(ls) minm=min(ls) if n==2 : print(0) else : ls.remove(max(ls)) answ=max(ls)-minm ls.remove(min(ls)) answ2=maxm-min(ls) print(min(answ,answ2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ls : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var maxm : OclAny := (ls)->max() ; var minm : OclAny := (ls)->min() ; if n = 2 then ( execute (0)->display() ) else ( execute (((ls)->max()) /: ls) ; var answ : double := (ls)->max() - minm ; execute (((ls)->min()) /: ls) ; var answ2 : double := maxm - (ls)->min() ; execute (Set{answ, answ2}->min())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) if n==1 : print(0) else : l.sort() print(min(l[n-2]-l[0],l[n-1]-l[1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = 1 then ( execute (0)->display() ) else ( l := l->sort() ; execute (Set{l[n - 2+1] - l->first(), l[n - 1+1] - l[1+1]}->min())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()); l=sorted(list((map(int,input().split())))) if l[-2]-l[0]>=l[-1]-l[1]: print(l[-1]-l[1]) else : print(l[-2]-l[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var l : Sequence := (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->sort() ; if (l->front()->last() - l->first()->compareTo(l->last() - l[1+1])) >= 0 then ( execute (l->last() - l[1+1])->display() ) else ( execute (l->front()->last() - l->first())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,l=int(input()),sorted(list(map(int,input().split()))) print(min(l[-1]-l[1],l[-2]-l[0])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; Sequence{n,l} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort()} ; execute (Set{l->last() - l[1+1], l->front()->last() - l->first()}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : n=int(input()) a=list(map(int,input().split())) a.sort() ans=min(a[n-1]-a[1],a[n-2]-a[0]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var ans : OclAny := Set{a[n - 1+1] - a[1+1], a[n - 2+1] - a->first()}->min() ; execute (ans)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M,C=map(int,input().split()) B=list(map(int,input().split())) A=[list(map(int,input().split()))for i in range(N)] count=0 for i in range(N): sum=0 for j in range(M): sum+=A[i][j]*B[j] if sum+C>0 : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; var C : OclAny := null; Sequence{N,M,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var B : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var A : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var count : int := 0 ; for i : Integer.subrange(0, N-1) do ( var sum : int := 0 ; for j : Integer.subrange(0, M-1) do ( sum := sum + A[i+1][j+1] * B[j+1]) ; if sum + C > 0 then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) red=[] blue=[] memo=[0]*N ans=0 for i in range(N): a,b=map(int,input().split()) red.append((a,b)) for i in range(N): c,d=map(int,input().split()) blue.append((c,d)) blue.sort() red.sort(key=lambda x : x[1],reverse=True) for i in range(N): bx,by=blue[i] for j in range(N): rx,ry=red[j] if memo[j]==0 and rx<=bx and ry<=by : memo[j]=1 ans+=1 break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var red : Sequence := Sequence{} ; var blue : Sequence := Sequence{} ; var memo : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a, b}) : red)) ; for i : Integer.subrange(0, N-1) do ( var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{c, d}) : blue)) ; blue := blue->sort() ; red := red->sort() ; for i : Integer.subrange(0, N-1) do ( var bx : OclAny := null; var by : OclAny := null; Sequence{bx,by} := blue[i+1] ; for j : Integer.subrange(0, N-1) do ( var rx : OclAny := null; var ry : OclAny := null; Sequence{rx,ry} := red[j+1] ; if memo[j+1] = 0 & (rx->compareTo(bx)) <= 0 & (ry->compareTo(by)) <= 0 then ( memo[j+1] := 1 ; ans := ans + 1 ; break ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import izip N,M,C=(int(x)for x in raw_input().split()) B=[int(x)for x in raw_input().split()] A=[[int(x)for x in raw_input().split()]for i in xrange(N)] result=0 for i in xrange(N): cur_sum=C for a,b in izip(A[i],B): cur_sum+=a*b if cur_sum>0 : result+=1 print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; var C : OclAny := null; Sequence{N,M,C} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name raw_input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var B : Sequence := raw_input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var A : Sequence := xrange(N)->select(i | true)->collect(i | (raw_input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))) ; var result : int := 0 ; for i : xrange(N) do ( var cur_sum : OclAny := C ; for _tuple : izip(A[i+1], B) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); cur_sum := cur_sum + a * b) ; if cur_sum > 0 then ( result := result + 1 ) else skip) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): import numpy as np import sys input=sys.stdin.readline n,m,c=map(int,input().split()) B=list(map(int,input().split())) B=np.array(B) cnt=0 for i in range(n): A=np.array(list(map(int,input().split()))) if(B*A).sum()+c>0 : cnt+=1 print(cnt) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; var c : OclAny := null; Sequence{n,m,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var B : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; B := (B) ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( var A : Sequence := (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; if (MatrixLib.dotProduct(B,A)).sum() + c > 0 then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- NO_OF_CHARS=256 def max_distinct_char(str,n): count=[0]*NO_OF_CHARS for i in range(n): count[ord(str[i])]+=1 max_distinct=0 for i in range(NO_OF_CHARS): if(count[i]!=0): max_distinct+=1 return max_distinct def smallesteSubstr_maxDistictChar(str): n=len(str) max_distinct=max_distinct_char(str,n) minl=n for i in range(n): for j in range(n): subs=str[i : j] subs_lenght=len(subs) sub_distinct_char=max_distinct_char(subs,subs_lenght) if(subs_lenghtdisplay() ) else skip; operation max_distinct_char(OclType["String"] : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, NO_OF_CHARS) ; for i : Integer.subrange(0, n-1) do ( count[(("" + ([i+1])))->char2byte()+1] := count[(("" + ([i+1])))->char2byte()+1] + 1) ; var max_distinct : int := 0 ; for i : Integer.subrange(0, NO_OF_CHARS-1) do ( if (count[i+1] /= 0) then ( max_distinct := max_distinct + 1 ) else skip) ; return max_distinct; operation smallesteSubstr_maxDistictChar(OclType["String"] : OclAny) : OclAny pre: true post: true activity: n := (OclType["String"])->size() ; max_distinct := max_distinct_char(OclType["String"], n) ; var minl : OclAny := n ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( var subs : String := ("" + (.subrange(i+1, j))) ; var subs_lenght : int := (subs)->size() ; var sub_distinct_char : OclAny := max_distinct_char(subs, subs_lenght) ; if ((subs_lenght->compareTo(minl)) < 0 & max_distinct = sub_distinct_char) then ( minl := subs_lenght ) else skip)) ; return minl; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def IL(): return map(int,sys.stdin.readline().rstrip().split()) def Main(): n,m,c=IL() b=list(IL()) ans=0 for _ in range(n): a=list(IL()) tmp=0 for i in range(m): tmp+=b[i]*a[i] if-ccollect( _x | (OclType["int"])->apply(_x) ); operation Main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var c : OclAny := null; Sequence{n,m,c} := IL() ; var b : Sequence := (IL()) ; var ans : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var a : Sequence := (IL()) ; var tmp : int := 0 ; for i : Integer.subrange(0, m-1) do ( tmp := tmp + b[i+1] * a[i+1]) ; if (-c->compareTo(tmp)) < 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,c=[int(i)for i in input().split()] b=[int(i)for i in input().split()] a=[[int(i)for i in input().split()]for j in range(n)] ans=0 for i in range(n): x=c for j in range(m): x+=b[j]*a[i][j] if x>0 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var c : OclAny := null; Sequence{n,m,c} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var b : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())))) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := c ; for j : Integer.subrange(0, m-1) do ( x := x + b[j+1] * a[i+1][j+1]) ; if x > 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isVowel(ch): ch=ch.upper() if(ch=='A' or ch=='E' or ch=='I' or ch=='O' or ch=='U'): return True else : return False def duplicateVowels(S): t=len(S) res="" for i in range(t): if(isVowel(S[i])): res+=S[i] res+=S[i] return res S="helloworld" print("Original String: ",S) res=duplicateVowels(S) print("String with Vowels duplicated: ",res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; S := "helloworld" ; execute ("Original String: ")->display() ; res := duplicateVowels(S) ; execute ("String with Vowels duplicated: ")->display(); operation isVowel(ch : OclAny) : OclAny pre: true post: true activity: ch := ch->toUpperCase() ; if (ch = 'A' or ch = 'E' or ch = 'I' or ch = 'O' or ch = 'U') then ( return true ) else ( return false ); operation duplicateVowels(S : OclAny) : OclAny pre: true post: true activity: var t : int := (S)->size() ; var res : String := "" ; for i : Integer.subrange(0, t-1) do ( if (isVowel(S[i+1])) then ( res := res + S[i+1] ) else skip ; res := res + S[i+1]) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np mod=1000000007 ; dp=np.zeros((55,55)); def NoofWays(face,throws,sum): if(sum==0 and throws==0): return 1 ; if(sum<0 or throws==0): return 0 ; if(dp[throws][sum]!=-1): return dp[throws][sum]; ans=0 ; for i in range(1,face+1): ans+=NoofWays(face,throws-1,sum-i); dp[throws][sum]=ans ; return ans ; if __name__=="__main__" : faces=6 ; throws=3 ; sum=12 ; for i in range(55): for j in range(55): dp[i][j]=-1 print(NoofWays(faces,throws,sum)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var mod : int := 1000000007; ; var dp : Sequence := MatrixLib.singleValueMatrix(Sequence{55, 55}, 0.0); ; skip ; if __name__ = "__main__" then ( var faces : int := 6; throws := 3; sum := 12; ; for i : Integer.subrange(0, 55-1) do ( for j : Integer.subrange(0, 55-1) do ( dp[i+1][j+1] := -1)) ; execute (NoofWays(faces, throws, sum))->display(); ) else skip; operation NoofWays(face : OclAny, throws : OclAny, sum : OclAny) pre: true post: true activity: if (sum = 0 & throws = 0) then ( return 1; ) else skip ; if (sum < 0 or throws = 0) then ( return 0; ) else skip ; if (dp[throws+1][sum+1] /= -1) then ( return dp[throws+1][sum+1]; ) else skip ; var ans : int := 0; ; for i : Integer.subrange(1, face + 1-1) do ( ans := ans + NoofWays(face, throws - 1, sum - i);) ; dp[throws+1][sum+1] := ans; ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairsWithProdK(arr,n,k): count=0 for i in range(n): for j in range(i+1,n): if(arr[i]*arr[j]==k): count+=1 return count arr=[1,5,3,4,2] N=len(arr) K=3 print(countPairsWithProdK(arr,N,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{5}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 2 })))) ; var N : int := (arr)->size() ; var K : int := 3 ; execute (countPairsWithProdK(arr, N, K))->display(); operation countPairsWithProdK(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if (arr[i+1] * arr[j+1] = k) then ( count := count + 1 ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CountZeroBit(n): count=0 while(n): if(not(n & 1)): count+=1 n>>=1 return count def CountORandSumEqual(N): count=CountZeroBit(N) return(1<display(); operation CountZeroBit(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while (n) do ( if (not((MathLib.bitwiseAnd(n, 1)))) then ( count := count + 1 ) else skip ; n := n div (2->pow(1))) ; return count; operation CountORandSumEqual(N : OclAny) : OclAny pre: true post: true activity: count := CountZeroBit(N) ; return (1 * (2->pow(count))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cubeSum(n): return(n*n*(2*n*n-1)) print(cubeSum(4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (cubeSum(4))->display(); operation cubeSum(n : OclAny) : OclAny pre: true post: true activity: return (n * n * (2 * n * n - 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cubeSum(n): return 2*n*n*(n+1)*(n+1) print(cubeSum(8)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (cubeSum(8))->display(); operation cubeSum(n : OclAny) : OclAny pre: true post: true activity: return 2 * n * n * (n + 1) * (n + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(): n=int(sys.stdin.readline().rstrip()) red=[[int(x)for x in sys.stdin.readline().split()]for _ in range(n)] blue=[[int(x)for x in sys.stdin.readline().split()]for _ in range(n)] reversed_b_sorted_by_a=[ab[1]for ab in sorted(red,reverse=1)] bd_sorted_by_ac=[acbd[1]for acbd in sorted(red+blue)] count=0 for b in reversed_b_sorted_by_a : b_index=bd_sorted_by_ac.index(b) if b_index==len(bd_sorted_by_ac)-1 : bd_sorted_by_ac.remove(b) continue range_to_scope=bd_sorted_by_ac[b_index+1 :] possible_elements=[x for x in range_to_scope if x>b] if not possible_elements : bd_sorted_by_ac.remove(b) continue bd_sorted_by_ac.remove(min(possible_elements)) bd_sorted_by_ac.remove(b) count+=1 print(count) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + ((sys.stdin.readLine().rstrip())))->toInteger() ; var red : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))) ; var blue : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))) ; var reversed_b_sorted_by_a : Sequence := red->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->select(ab | true)->collect(ab | (ab[1+1])) ; var bd_sorted_by_ac : Sequence := red->union(blue)->sort()->select(acbd | true)->collect(acbd | (acbd[1+1])) ; var count : int := 0 ; for b : reversed_b_sorted_by_a do ( var b_index : int := bd_sorted_by_ac->indexOf(b) - 1 ; if b_index = (bd_sorted_by_ac)->size() - 1 then ( execute ((b) /: bd_sorted_by_ac) ; continue ) else skip ; var range_to_scope : OclAny := bd_sorted_by_ac.subrange(b_index + 1+1) ; var possible_elements : Sequence := range_to_scope->select(x | (x->compareTo(b)) > 0)->collect(x | (x)) ; if not(possible_elements) then ( execute ((b) /: bd_sorted_by_ac) ; continue ) else skip ; execute (((possible_elements)->min()) /: bd_sorted_by_ac) ; execute ((b) /: bd_sorted_by_ac) ; count := count + 1) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import isinf from scipy.sparse.csgraph import shortest_path from scipy.sparse import csr_matrix INF=float('inf') def main(): N,M,L=list(map(int,input().split())) E=[[INF]*N for _ in range(N)] for _ in range(M): a,b,c=list(map(int,input().split())) E[a-1][b-1]=c E[b-1][a-1]=c EE=shortest_path(csr_matrix(E)) E=[[1 if EE[i][j]<=L else INF for j in range(N)]for i in range(N)] EE=shortest_path(csr_matrix(E)) Q=int(input()) for _ in range(Q): s,t=map(int,input().split()) x=EE[s-1][t-1] print(-1 if isinf(x)else int(x)-1) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var INF : double := ("" + (('inf')))->toReal() ; skip ; main(); operation main() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; var L : OclAny := null; Sequence{N,M,L} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var E : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ INF }, N))) ; for _anon : Integer.subrange(0, M-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; E[a - 1+1][b - 1+1] := c ; E[b - 1+1][a - 1+1] := c) ; var EE : OclAny := shortest_path(csr_matrix(E)) ; E := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Integer.subrange(0, N-1)->select(j | true)->collect(j | (if (EE[i+1][j+1]->compareTo(L)) <= 0 then 1 else INF endif)))) ; EE := shortest_path(csr_matrix(E)) ; var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, Q-1) do ( var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := EE[s - 1+1][t - 1+1] ; execute (if isinf(x) then -1 else ("" + ((x)))->toInteger() - 1 endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import* from collections import* from functools import* from operator import floordiv,mul,sub strategies={2 :[(1,(1,0)),(1,(0,2))],3 :[(1,(1,0,0)),(1,(0,1,1)),(1,(0,3,0)),(1,(0,0,3))],4 :[(1,(1,0,0,0)),(1,(0,1,0,1)),(1,(0,0,2,0)),(1,(0,2,1,0)),(1,(0,0,1,2)),(1,(0,4,0,0)),(1,(0,0,0,4)),]} T=int(input().strip()) for t in range(T): print("Case #{}: ".format(t+1),end="") ngroups,packsize=map(int,input().strip().split(" ")) groups=map(int,input().strip().split(" ")) strategy=strategies[packsize] modgroups=list(repeat(0,packsize)) for i in groups : modgroups[i % packsize]+=1 score=0 for value,operation in strategy : repetitions=min(map(lambda a,b : a//b if b!=0 else float('inf'),modgroups,operation)) modgroups=list(map(sub,modgroups,map(mul,operation,repeat(repetitions)))) score+=value*repetitions if sum(modgroups)>0 : score+=1 print(score) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var strategies : Map := Map{ 2 |-> Sequence{Sequence{1, Sequence{1, 0}}}->union(Sequence{ Sequence{1, Sequence{0, 2}} }) }->union(Map{ 3 |-> Sequence{Sequence{1, Sequence{1, 0, 0}}}->union(Sequence{Sequence{1, Sequence{0, 1, 1}}}->union(Sequence{Sequence{1, Sequence{0, 3, 0}}}->union(Sequence{ Sequence{1, Sequence{0, 0, 3}} }))) }->union(Map{ 4 |-> Sequence{Sequence{1, Sequence{1, 0, 0, 0}}}->union(Sequence{Sequence{1, Sequence{0, 1, 0, 1}}}->union(Sequence{Sequence{1, Sequence{0, 0, 2, 0}}}->union(Sequence{Sequence{1, Sequence{0, 2, 1, 0}}}->union(Sequence{Sequence{1, Sequence{0, 0, 1, 2}}}->union(Sequence{Sequence{1, Sequence{0, 4, 0, 0}}}->union(Sequence{ Sequence{1, Sequence{0, 0, 0, 4}} })))))) })) ; var T : int := ("" + ((input()->trim())))->toInteger() ; for t : Integer.subrange(0, T-1) do ( execute (StringLib.interpolateStrings("Case #{}: ", Sequence{t + 1}))->display() ; var ngroups : OclAny := null; var packsize : OclAny := null; Sequence{ngroups,packsize} := (input()->trim().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var groups : Sequence := (input()->trim().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var strategy : OclAny := strategies[packsize+1] ; var modgroups : Sequence := (repeat(0, packsize)) ; for i : groups do ( modgroups[i mod packsize+1] := modgroups[i mod packsize+1] + 1) ; var score : int := 0 ; for _tuple : strategy do (var _indx : int := 1; var value : OclAny := _tuple->at(_indx); _indx := _indx + 1; var operation : OclAny := _tuple->at(_indx); var repetitions : OclAny := ((modgroups)->collect( _x | (lambda a : OclAny, b : OclAny in (if b /= 0 then a div b else ("" + (('inf')))->toReal() endif))->apply(_x) ))->min() ; modgroups := ((modgroups)->collect( _x | (sub)->apply(_x) )) ; score := score + value * repetitions) ; if (modgroups)->sum() > 0 then ( score := score + 1 ) else skip ; execute (score)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda : sys.stdin.readline().rstrip() def resolve(): n,m,L=map(int,input().split()) E=[[]for _ in range(n)] for _ in range(m): a,b,c=map(int,input().split()) if(c>L): continue a-=1 ; b-=1 E[a].append((b,c)) E[b].append((a,c)) A=[0]*n for u in range(n): dist=[(INF,INF)]*n dist[u]=(0,0) calculated=[False]*n for _ in range(n-1): v=min((dist[v],v)for v in range(n)if(not calculated[v]))[1] calculated[v]=True now=dist[v] for nv,w in E[v]: if(now[1]+w<=L): next=(now[0],now[1]+w) else : next=(now[0]+1,w) if(dist[nv]>next): dist[nv]=next A[u]=dist Q=int(input()) for _ in range(Q): s,t=map(int,input().split()) s-=1 ; t-=1 ans=A[s][t][0] print(ans if ans!=INF else-1) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(2147483647) ; var INF : double := ("" + (("inf")))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; skip ; resolve(); operation resolve() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var L : OclAny := null; Sequence{n,m,L} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var E : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if ((c->compareTo(L)) > 0) then ( continue ) else skip ; a := a - 1; b := b - 1 ; (expr (atom (name E)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name b)))))) , (test (logical_test (comparison (expr (atom (name c))))))) )))))))) )))) ; (expr (atom (name E)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name c))))))) )))))))) ))))) ; var A : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for u : Integer.subrange(0, n-1) do ( var dist : Sequence := MatrixLib.elementwiseMult(Sequence{ Sequence{INF, INF} }, n) ; dist[u+1] := Sequence{0, 0} ; var calculated : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ; for _anon : Integer.subrange(0, n - 1-1) do ( var v : OclAny := min((argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name dist)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])))))) , (test (logical_test (comparison (expr (atom (name v))))))) )))))) (comp_for for (exprlist (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test not (logical_test (comparison (expr (atom (name calculated)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])))))))) ))))))))))[1+1] ; calculated[v+1] := true ; var now : OclAny := dist[v+1] ; for _tuple : E[v+1] do (var _indx : int := 1; var nv : OclAny := _tuple->at(_indx); _indx := _indx + 1; var w : OclAny := _tuple->at(_indx); if ((now[1+1] + w->compareTo(L)) <= 0) then ( var next : OclAny := Sequence{now->first(), now[1+1] + w} ) else ( next := Sequence{now->first() + 1, w} ) ; if ((dist[nv+1]->compareTo(next)) > 0) then ( dist[nv+1] := next ) else skip)) ; A[u+1] := dist) ; var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, Q-1) do ( var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; s := s - 1; t := t - 1 ; var ans : OclAny := A[s+1][t+1]->first() ; execute (if ans /= INF then ans else -1 endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines import numpy as np from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix N,M,L=[int(_)for _ in readline().split()] ABCQST=np.array(read().split(),dtype=np.int64) ABC=ABCQST[: 3*M] ST=ABCQST[3*M+1 :] A,B,C=ABC[: : 3],ABC[1 : : 3],ABC[2 : : 3] S,T=ST[: : 2],ST[1 : : 2] G=csr_matrix((C,(A,B)),shape=(N+1,N+1)) G2=floyd_warshall(G,directed=0) G3=np.full((N+1,N+1),np.inf) np.fill_diagonal(G3,0) G3[G2<=L]=1 G4=floyd_warshall(G3,directed=0) G4[G4==np.inf]=0 print(*(G4[S,T]-1).astype(np.int64),sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; skip ; skip ; skip ; var N : OclAny := null; var M : OclAny := null; var L : OclAny := null; Sequence{N,M,L} := readline().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var ABCQST : Sequence := (read().split(), (argument (test (logical_test (comparison (expr (atom (name dtype)))))) = (test (logical_test (comparison (expr (atom (name np)) (trailer . (name int64)))))))) ; var ABC : OclAny := ABCQST.subrange(1,3 * M) ; var ST : OclAny := ABCQST.subrange(3 * M + 1+1) ; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{A,B,C} := Sequence{ABC(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 3))))))))),ABC(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 3))))))))),ABC(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 3)))))))))} ; var S : OclAny := null; var T : OclAny := null; Sequence{S,T} := Sequence{ST(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))),ST(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))} ; var G : OclAny := csr_matrix(Sequence{C, Sequence{A, B}}, (argument (test (logical_test (comparison (expr (atom (name shape)))))) = (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name N))) + (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (expr (atom (name N))) + (expr (atom (number (integer 1))))))))) )))))))) ; var G2 : OclAny := floyd_warshall(G, (argument (test (logical_test (comparison (expr (atom (name directed)))))) = (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ; var G3 : Sequence := MatrixLib.singleValueMatrix(Sequence{N + 1, N + 1}, Math_PINFINITY) ; np.fill_diagonal(G3, 0) ; G3->select((G2->compareTo(L)) <= 0) := 1 ; var G4 : OclAny := floyd_warshall(G3, (argument (test (logical_test (comparison (expr (atom (name directed)))))) = (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ; G4->select(G4 = Math_PINFINITY) := 0 ; execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name G4)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name S))))))) , (subscript (test (logical_test (comparison (expr (atom (name T)))))))) ]))) - (expr (atom (number (integer 1))))))))) )) (trailer . (name astype) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name np)) (trailer . (name int64)))))))) )))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(): input=sys.stdin.readline n,m,l=map(int,input().split()) inf=pow(10,10) towns=[[inf]*n for _ in range(n)] for _ in range(m): a,b,c=map(int,input().split()) if c>l : continue towns[a-1][b-1]=c towns[b-1][a-1]=c for k in range(n): for i in range(n): for j in range(n): if towns[i][j]>towns[i][k]+towns[k][j]and l>=towns[i][k]+towns[k][j]: towns[i][j]=towns[i][k]+towns[k][j] for i in range(n): for j in range(n): if towns[i][j]==inf : continue towns[i][j]=0 for k in range(n): for i in range(n): for j in range(n): if towns[i][j]>towns[i][k]+towns[k][j]+1 : towns[i][j]=towns[i][k]+towns[k][j]+1 q=int(input()) for _ in range(q): s,t=map(int,input().split()) print(towns[s-1][t-1]if towns[s-1][t-1]!=inf else-1) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; var l : OclAny := null; Sequence{n,m,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var Math_PINFINITY : double := (10)->pow(10) ; var towns : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ Math_PINFINITY }, n))) ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (c->compareTo(l)) > 0 then ( continue ) else skip ; towns[a - 1+1][b - 1+1] := c ; towns[b - 1+1][a - 1+1] := c) ; for k : Integer.subrange(0, n-1) do ( for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if (towns[i+1][j+1]->compareTo(towns[i+1][k+1] + towns[k+1][j+1])) > 0 & (l->compareTo(towns[i+1][k+1] + towns[k+1][j+1])) >= 0 then ( towns[i+1][j+1] := towns[i+1][k+1] + towns[k+1][j+1] ) else skip))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if towns[i+1][j+1] = Math_PINFINITY then ( continue ) else skip ; towns[i+1][j+1] := 0)) ; for k : Integer.subrange(0, n-1) do ( for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if (towns[i+1][j+1]->compareTo(towns[i+1][k+1] + towns[k+1][j+1] + 1)) > 0 then ( towns[i+1][j+1] := towns[i+1][k+1] + towns[k+1][j+1] + 1 ) else skip))) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if towns[s - 1+1][t - 1+1] /= Math_PINFINITY then towns[s - 1+1][t - 1+1] else -1 endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from scipy.sparse import* f=csgraph.johnson n,m,l,*t=map(int,open(0).read().split()) m*=3 [*map(print,f(f(csr_matrix((t[2 : m : 3],(t[: m : 3],t[1 : m : 3])),[n+1]*2),0)<=l)[t[m+1 : : 2],t[m+2 : : 2]].clip(0,n)% n-1)] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var f : OclAny := csgraph.johnson ; var n : OclAny := null; var m : OclAny := null; var l : OclAny := null; var t : OclAny := null; Sequence{n,m,l,t} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; m := m * 3 ; ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxPartition(s): n=len(s) P=0 current="" previous="" for i in range(n): current+=s[i] if(current!=previous): previous=current current="" P+=1 return P s="geeksforgeeks" ans=maxPartition(s) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := "geeksforgeeks" ; var ans : OclAny := maxPartition(s) ; execute (ans)->display(); operation maxPartition(s : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; var P : int := 0 ; var current : String := "" ; var previous : String := "" ; for i : Integer.subrange(0, n-1) do ( current := current + s[i+1] ; if (current /= previous) then ( previous := current ; current := "" ; P := P + 1 ) else skip) ; return P; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=int(input()) b=int(input()) c=int(input()) print((n>1)*min(a,b)+max(0,n-2)*min(a,b,c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((n > 1) * Set{a, b}->min() + Set{0, n - 2}->max() * Set{a, b, c}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b,c=int(input()),int(input()),int(input()),int(input()) print((n>1)*min(a,b)+max(0,n-2)*min(a,b,c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{n,a,b,c} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),("" + (((OclFile["System.in"]).readLine())))->toInteger(),("" + (((OclFile["System.in"]).readLine())))->toInteger(),("" + (((OclFile["System.in"]).readLine())))->toInteger()} ; execute ((n > 1) * Set{a, b}->min() + Set{0, n - 2}->max() * Set{a, b, c}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=int(input()) b=int(input()) c=int(input()) print((n>1)*min(a,b)+max(0,n-2)*min(a,b,c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((n > 1) * Set{a, b}->min() + Set{0, n - 2}->max() * Set{a, b, c}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=int(input()) b=int(input()) c=int(input()) print((n>1)*min(a,b)+max(0,n-2)*min(a,b,c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((n > 1) * Set{a, b}->min() + Set{0, n - 2}->max() * Set{a, b, c}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from operator import itemgetter def main(): N=int(input()) ab=[[int(j)for j in input().split()]for i in range(N)] cd=[[int(j)for j in input().split()]for i in range(N)] ab.sort(key=itemgetter(1),reverse=True) cd.sort(key=itemgetter(0)) done=[False]*N for bx,by in cd : i=0 for rx,ry in ab : if not done[i]and rxtoInteger() ; var ab : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger())))) ; var cd : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger())))) ; ab := ab->sort() ; cd := cd->sort() ; var done : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, N) ; for _tuple : cd do (var _indx : int := 1; var bx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var by : OclAny := _tuple->at(_indx); var i : int := 0 ; for _tuple : ab do (var _indx : int := 1; var rx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var ry : OclAny := _tuple->at(_indx); if not(done[i+1]) & (rx->compareTo(bx)) < 0 & (ry->compareTo(by)) < 0 then ( done[i+1] := true ; break ) else skip ; i := i + 1)) ; execute ((done)->sum())->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil,floor numInputs=int(input()) for i in range(numInputs): N,P=[int(num)for num in input().split(" ")] G=[int(num)for num in input().split(" ")] numsMod={} for j in range(P): numsMod[j]=0 for g in G : numsMod[g % P]+=1 if P==2 : print("Case #"+str(i+1)+": "+str(numsMod[0]+ceil(numsMod[1]/2.0))) continue if P==3 : smaller=min(numsMod[1],numsMod[2]) larger=max(numsMod[1],numsMod[2]) diff=larger-smaller print("Case #"+str(i+1)+": "+str(numsMod[0]+smaller+ceil(diff/3.0))) continue total=numsMod[0] total+=floor(numsMod[2]/2.0) smaller=min(numsMod[1],numsMod[3]) larger=max(numsMod[1],numsMod[3]) diff=larger-smaller total+=smaller if numsMod[2]% 2==1 : total+=1 if diff>2 : total+=ceil((diff-2)/4.0) else : total+=ceil(diff/4.0) print("Case #"+str(i+1)+": "+str(total)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var numInputs : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, numInputs-1) do ( var N : OclAny := null; var P : OclAny := null; Sequence{N,P} := input().split(" ")->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var G : Sequence := input().split(" ")->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var numsMod : OclAny := Set{} ; for j : Integer.subrange(0, P-1) do ( numsMod[j+1] := 0) ; for g : G do ( numsMod[g mod P+1] := numsMod[g mod P+1] + 1) ; if P = 2 then ( execute ("Case #" + ("" + ((i + 1))) + ": " + ("" + ((numsMod->first() + ceil(numsMod[1+1] / 2.0)))))->display() ; continue ) else skip ; if P = 3 then ( var smaller : OclAny := Set{numsMod[1+1], numsMod[2+1]}->min() ; var larger : OclAny := Set{numsMod[1+1], numsMod[2+1]}->max() ; var diff : double := larger - smaller ; execute ("Case #" + ("" + ((i + 1))) + ": " + ("" + ((numsMod->first() + smaller + ceil(diff / 3.0)))))->display() ; continue ) else skip ; var total : OclAny := numsMod->first() ; total := total + floor(numsMod[2+1] / 2.0) ; smaller := Set{numsMod[1+1], numsMod[3+1]}->min() ; larger := Set{numsMod[1+1], numsMod[3+1]}->max() ; diff := larger - smaller ; total := total + smaller ; if numsMod[2+1] mod 2 = 1 then ( total := total + 1 ; if diff > 2 then ( total := total + ceil((diff - 2) / 4.0) ) else skip ) else ( total := total + ceil(diff / 4.0) ) ; execute ("Case #" + ("" + ((i + 1))) + ": " + ("" + ((total))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=int(input()) b=int(input()) c=int(input()) print((n>1)*min(a,b)+max(0,n-2)*min(a,b,c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((n > 1) * Set{a, b}->min() + Set{0, n - 2}->max() * Set{a, b, c}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfFactors(n): sum=0 for f in range(1,n//2+1): if(n % f==0): sum+=f return sum def getSum(arr,n): sum=0 for i in range(n): if(arr[i]>0 and arr[i]==sumOfFactors(arr[i])): sum+=arr[i] return sum arr=[17,6,10,6,4] n=len(arr) print(getSum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{17}->union(Sequence{6}->union(Sequence{10}->union(Sequence{6}->union(Sequence{ 4 })))) ; n := (arr)->size() ; execute (getSum(arr, n))->display(); operation sumOfFactors(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for f : Integer.subrange(1, n div 2 + 1-1) do ( if (n mod f = 0) then ( sum := sum + f ) else skip) ; return sum; operation getSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: sum := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] > 0 & arr[i+1] = sumOfFactors(arr[i+1])) then ( sum := sum + arr[i+1] ) else skip) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fibonacci(n): a=0 b=1 if n<0 : print("Incorrect input") elif n==0 : return a elif n==1 : return b else : for i in range(2,n+1): c=a+b a=b b=c return b print(fibonacci(9)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (fibonacci(9))->display(); operation fibonacci(n : OclAny) pre: true post: true activity: var a : int := 0 ; var b : int := 1 ; if n < 0 then ( execute ("Incorrect input")->display() ) else (if n = 0 then ( return a ) else (if n = 1 then ( return b ) else ( for i : Integer.subrange(2, n + 1-1) do ( var c : int := a + b ; a := b ; b := c) ; return b ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) s=[] b=[int(i)for i in input().split()] for i in range(1,a+1): s.append(b.index(i)+1) print(*s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := Sequence{} ; var b : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; for i : Integer.subrange(1, a + 1-1) do ( execute ((b->indexOf(i) - 1 + 1) : s)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name s))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) x=[] y=[] for i in range(1,n+1): x.append(i) for j in range(n): m=x[j] for k in range(n): if m==l[k]: y.append(k+1) print(" ".join(map(str,y))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : Sequence := Sequence{} ; var y : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( execute ((i) : x)) ; for j : Integer.subrange(0, n-1) do ( var m : OclAny := x[j+1] ; for k : Integer.subrange(0, n-1) do ( if m = l[k+1] then ( execute ((k + 1) : y) ) else skip)) ; execute (StringLib.sumStringsWithSeparator(((y)->collect( _x | (OclType["String"])->apply(_x) )), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=[*map(int,input().split())] for i in range(n): print(p.index(i+1)+1,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, n-1) do ( execute (p->indexOf(i + 1) - 1 + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=int(input()) l=list(map(int,input().split())) size=len(l) s=[0]*size for j in range(size): c=l[j]-1 s[c]=j+1 print(" ".join(map(str,s))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var size : int := (l)->size() ; var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, size) ; for j : Integer.subrange(0, size-1) do ( var c : double := l[j+1] - 1 ; s[c+1] := j + 1) ; execute (StringLib.sumStringsWithSeparator(((s)->collect( _x | (OclType["String"])->apply(_x) )), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def distinctCount(arr,n): s=set() for i in range(n): s.add(abs(arr[i])) return len(s) arr=[-2,-1,0,1,1] n=len(arr) print("Count of absolute distinct values:",distinctCount(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{-2}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 1 })))) ; n := (arr)->size() ; execute ("Count of absolute distinct values:")->display(); operation distinctCount(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var s : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( execute (((arr[i+1])->abs()) : s)) ; return (s)->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import product from collections import defaultdict def solve(S): def helper(s): n=len(s) d=defaultdict(int) for p in product((True,False),repeat=n): t=[-1]*(n+1) t[-1]=sum(p) i=0 j=n-1 for c,f in zip(s,p): if f : t[i]=c i+=1 else : t[j]=c j-=1 d[tuple(t)]+=1 return d S=[ord(c)-ord('a')for c in S] n=len(S)//2 d1=helper(S[: n]) d2=helper(S[: n-1 :-1]) res=0 for k,c in d1.items(): res+=c*d2[k] return res if __name__=='__main__' : N=int(input()) S=input() print(solve(S)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; S := (OclFile["System.in"]).readLine() ; execute (solve(S))->display() ) else skip; operation solve(S : OclAny) : OclAny pre: true post: true activity: skip ; S := S->select(c | true)->collect(c | ((c)->char2byte() - ('a')->char2byte())) ; n := (S)->size() div 2 ; var d1 : OclAny := helper(S.subrange(1,n)) ; var d2 : OclAny := helper(S(subscript : (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))) (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ; var res : int := 0 ; for _tuple : d1->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); res := res + c * d2[k+1]) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from collections import defaultdict from bisect import bisect_left,bisect_right sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod=10**9+7 def I(): return int(input()) def LI(): return list(map(int,input().split())) def LIR(row,col): if row<=0 : return[[]for _ in range(col)] elif col==1 : return[I()for _ in range(row)] else : read_all=[LI()for _ in range(row)] return map(list,zip(*read_all)) from itertools import product N=I() S=str(input()) d=defaultdict(lambda : defaultdict(int)) A=list(product([0,1],repeat=N)) for a in A : x=[] y=[] for i in range(N): if a[i]: x.append(S[N+i]) else : y.append(S[N+i]) x=''.join(x) y=''.join(y) d[x][y]+=1 ans=0 for a in A : x=[] y=[] for i in range(N): if a[i]: x.append(S[i]) else : y.append(S[i]) x=''.join(x[: :-1]) y=''.join(y[: :-1]) ans+=d[x][y] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; var N : OclAny := I() ; var S : String := ("" + (((OclFile["System.in"]).readLine()))) ; var d : OclAny := defaultdict(lambda $$ : OclAny in (defaultdict(OclType["int"]))) ; var A : Sequence := (product(Sequence{0}->union(Sequence{ 1 }), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (name N))))))))) ; for a : A do ( var x : Sequence := Sequence{} ; var y : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( if a[i+1] then ( execute ((S[N + i+1]) : x) ) else ( execute ((S[N + i+1]) : y) )) ; x := StringLib.sumStringsWithSeparator((x), '') ; y := StringLib.sumStringsWithSeparator((y), '') ; d->restrict(x)->restrict(y) := d->restrict(x)->restrict(y) + 1) ; var ans : int := 0 ; for a : A do ( x := Sequence{} ; y := Sequence{} ; for i : Integer.subrange(0, N-1) do ( if a[i+1] then ( execute ((S[i+1]) : x) ) else ( execute ((S[i+1]) : y) )) ; x := StringLib.sumStringsWithSeparator((x(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))), '') ; y := StringLib.sumStringsWithSeparator((y(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))), '') ; ans := ans + d->restrict(x)->restrict(y)) ; execute (ans)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LIR(row : OclAny, col : OclAny) : OclAny pre: true post: true activity: if row <= 0 then ( return Integer.subrange(0, col-1)->select(_anon | true)->collect(_anon | (Sequence{})) ) else (if col = 1 then ( return Integer.subrange(0, row-1)->select(_anon | true)->collect(_anon | (I())) ) else ( var read_all : Sequence := Integer.subrange(0, row-1)->select(_anon | true)->collect(_anon | (LI())) ; return (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name read_all)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name read_all)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name read_all)))))))`third->at(_indx)} ))->collect( _x | (OclType["Sequence"])->apply(_x) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=1000000007 inv2=500000004 ; def modulo(num): res=0 ; for i in range(len(num)): res=(res*10+int(num[i])-0)% mod ; return res ; def findSum(L,R): a=modulo(L); b=modulo(R); l=((a*(a-1))% mod*inv2)% mod ; r=((b*(b+1))% mod*inv2)% mod ; ret=(r % mod-l % mod); if(ret<0): ret=ret+mod ; else : ret=ret % mod ; return ret ; if __name__=="__main__" : L="88949273204" ; R="98429729474298592" ; print(findSum(L,R)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : int := 1000000007 ; var inv2 : int := 500000004; ; skip ; skip ; if __name__ = "__main__" then ( L := "88949273204"; ; R := "98429729474298592"; ; execute (findSum(L, R))->display(); ) else skip; operation modulo(num : OclAny) pre: true post: true activity: var res : int := 0; ; for i : Integer.subrange(0, (num)->size()-1) do ( res := (res * 10 + ("" + ((num[i+1])))->toInteger() - 0) mod mod;) ; return res;; operation findSum(L : OclAny, R : OclAny) pre: true post: true activity: var a : OclAny := modulo(L); ; var b : OclAny := modulo(R); ; var l : int := ((a * (a - 1)) mod mod * inv2) mod mod; ; var r : int := ((b * (b + 1)) mod mod * inv2) mod mod; ; var ret : double := (r mod mod - l mod mod); ; if (ret < 0) then ( ret := ret + mod; ) else ( ret := ret mod mod; ) ; return ret;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heapify,heappush,heappop N=int(input()) A=[] for i in range(N): A.append(tuple(map(int,input().split()))) A.sort() B=[] for i in range(N): B.append(tuple(map(int,input().split()))) B.sort() heap=[] heapify(heap) aindex=count=0 for b in B : while aindextoInteger() ; var A : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : A)) ; A := A->sort() ; var B : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : B)) ; B := B->sort() ; var heap : Sequence := Sequence{} ; heapify(heap) ; var aindex : OclAny := 0; var count : int := 0 ; for b : B do ( while (aindex->compareTo((A)->size())) < 0 & (A[aindex+1]->first()->compareTo(b->first())) < 0 do ( heappush(heap, -A[aindex+1][1+1]) ; aindex := aindex + 1) ; var buf : Sequence := Sequence{} ; while heap & (b[1+1]->compareTo(-heap->first())) <= 0 do ( var ay : OclAny := heappop(heap) ; execute ((ay) : buf)) ; if heap & (-heap->first()->compareTo(b[1+1])) < 0 then ( count := count + 1 ; heappop(heap) ) else skip ; for ay_ : buf do ( heappush(heap, ay_))) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) S=input() S1,S2=S[: N],S[2*N-1 : N-1 :-1] hash_S1,hash_S2={},{} for i in range(1<>j & 1 : red.append(S1[j]) else : blue.append(S1[j]) key=''.join(red)+'+'+''.join(blue) if key in hash_S1 : hash_S1[key]+=1 else : hash_S1[key]=1 ans=0 for i in range(1<>j & 1 : red.append(S2[j]) else : blue.append(S2[j]) key=''.join(blue)+'+'+''.join(red) if key in hash_S1 : ans+=hash_S1[key] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : String := (OclFile["System.in"]).readLine() ; var S1 : OclAny := null; var S2 : OclAny := null; Sequence{S1,S2} := Sequence{S.subrange(1,N),S(subscript (test (logical_test (comparison (expr (expr (expr (atom (number (integer 2)))) * (expr (atom (name N)))) - (expr (atom (number (integer 1)))))))) : (test (logical_test (comparison (expr (expr (atom (name N))) - (expr (atom (number (integer 1)))))))) (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))} ; var hash_S1 : OclAny := null; var hash_S2 : OclAny := null; Sequence{hash_S1,hash_S2} := Sequence{Set{},Set{}} ; for i : Integer.subrange(0, 1 * (2->pow(N))-1) do ( var red : Sequence := Sequence{} ; var blue : Sequence := Sequence{} ; for j : Integer.subrange(0, N-1) do ( if MathLib.bitwiseAnd(i /(2->pow(j)), 1) then ( execute ((S1[j+1]) : red) ) else ( execute ((S1[j+1]) : blue) )) ; var key : String := StringLib.sumStringsWithSeparator((red), '') + '+' + StringLib.sumStringsWithSeparator((blue), '') ; if (hash_S1)->includes(key) then ( hash_S1->at(key) := hash_S1->at(key) + 1 ) else ( hash_S1->at(key) := 1 )) ; var ans : int := 0 ; for i : Integer.subrange(0, 1 * (2->pow(N))-1) do ( red := Sequence{} ; blue := Sequence{} ; for j : Integer.subrange(0, N-1) do ( if MathLib.bitwiseAnd(i /(2->pow(j)), 1) then ( execute ((S2[j+1]) : red) ) else ( execute ((S2[j+1]) : blue) )) ; key := StringLib.sumStringsWithSeparator((blue), '') + '+' + StringLib.sumStringsWithSeparator((red), '') ; if (hash_S1)->includes(key) then ( ans := ans + hash_S1->at(key) ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from collections import Counter N=int(input()) S=input().rstrip() left=[('','')] for s in S[: N]: left=[(x[0]+s,x[1])for x in left]+[(x[0],x[1]+s)for x in left] left=[x+''+y for x,y in left] counter_L=Counter(left) right=[('','')] for s in S[N :][: :-1]: right=[(x[0]+s,x[1])for x in right]+[(x[0],x[1]+s)for x in right] right=[x+''+y for x,y in right] answer=sum(counter_L[s]for s in right) print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : OclAny := input().rstrip() ; var left : Sequence := Sequence{ Sequence{'', ''} } ; for s : S.subrange(1,N) do ( left := left->select(x | true)->collect(x | (Sequence{x->first() + s, x[1+1]}))->union(left->select(x | true)->collect(x | (Sequence{x->first(), x[1+1] + s})))) ; left := left->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (x + '' + y)) ; var counter_L : OclAny := Counter(left) ; var right : Sequence := Sequence{ Sequence{'', ''} } ; for s : S.subrange(N+1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( right := right->select(x | true)->collect(x | (Sequence{x->first() + s, x[1+1]}))->union(right->select(x | true)->collect(x | (Sequence{x->first(), x[1+1] + s})))) ; right := right->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (x + '' + y)) ; var answer : OclAny := ((argument (test (logical_test (comparison (expr (atom (name counter_L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name right))))))))->sum() ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) S=input() def count(s): res={} for i in range(2**N): t1='' t2='' for j in range(N): if i & 1<toInteger() ; var S : String := (OclFile["System.in"]).readLine() ; skip ; var h1 : OclAny := count(S.subrange(1,N)) ; var h2 : OclAny := count(S.subrange(N+1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ; var ans : int := 0 ; for _tuple : h1->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if (h2)->includes(k) then ( ans := ans + v * h2->at(k) ) else skip) ; execute (ans)->display(); operation count(s : OclAny) : OclAny pre: true post: true activity: var res : OclAny := Set{} ; for i : Integer.subrange(0, (2)->pow(N)-1) do ( var t1 : String := '' ; var t2 : String := '' ; for j : Integer.subrange(0, N-1) do ( if MathLib.bitwiseAnd(i, 1 * (2->pow(j))) then ( t1 := t1 + s[j+1] ) else ( t2 := t2 + s[j+1] )) ; var k : String := t1 + t2(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) + ("" + ((bin(i)->count('1')))) ; res->at(k) := res.get(k, 0) + 1) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) count=0 a=100 while True : a*=1.01 a=int(a) count+=1 if x<=a : print(count) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := 0 ; var a : int := 100 ; while true do ( a := a * 1.01 ; a := ("" + ((a)))->toInteger() ; count := count + 1 ; if (x->compareTo(a)) <= 0 then ( execute (count)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def resolve(): x=int(input()) ans=0 money=100 while moneytoInteger() ; var ans : int := 0 ; var money : int := 100 ; while (money->compareTo(x)) < 0 do ( money := money * 1.01 ; money := ("" + ((money)))->toInteger() ; ans := ans + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math X=int(input()) count=0 res=100 while restoInteger() ; var count : int := 0 ; var res : int := 100 ; while (res->compareTo(X)) < 0 do ( count := count + 1 ; res := (1.01 * res)->floor()) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) money,year=100,0 while moneytoInteger() ; var money : OclAny := null; var year : OclAny := null; Sequence{money,year} := Sequence{100,0} ; while (money->compareTo(x)) < 0 do ( money := money + ("" + ((money * 0.01)))->toInteger() ; year := year + 1) ; execute (year)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): x=int(input()) total=100 year=0 while totaltoInteger() ; var total : int := 100 ; var year : int := 0 ; while (total->compareTo(x)) < 0 do ( total := total + total div 100 ; year := year + 1) ; execute (year)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def digitDividesK(num,k): while(num): d=num % 10 if(d!=0 and k % d==0): return True num=num//10 return False def findCount(l,r,k): count=0 for i in range(l,r+1): if(digitDividesK(i,k)): count+=1 return count l=20 r=35 k=45 print(findCount(l,r,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; l := 20 ; r := 35 ; k := 45 ; execute (findCount(l, r, k))->display(); operation digitDividesK(num : OclAny, k : OclAny) : OclAny pre: true post: true activity: while (num) do ( var d : int := num mod 10 ; if (d /= 0 & k mod d = 0) then ( return true ) else skip ; num := num div 10) ; return false; operation findCount(l : OclAny, r : OclAny, k : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(l, r + 1-1) do ( if (digitDividesK(i, k)) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def unsort(l,r,a,k): if(k<1 or l+1==r): return k-=2 mid=(l+r)//2 temp=a[mid-1] a[mid-1]=a[mid] a[mid]=temp unsort(l,mid,a,k) unsort(mid,r,a,k) def arrayWithKCalls(n,k): if(k % 2==0): print("NO SOLUTION") return a=[0 for i in range(n+2)] a[0]=1 for i in range(1,n): a[i]=i+1 k-=1 unsort(0,n,a,k) for i in range(n): print(a[i],"",end="") n=10 k=17 arrayWithKCalls(n,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 10 ; k := 17 ; arrayWithKCalls(n, k); operation unsort(l : OclAny, r : OclAny, a : OclAny, k : OclAny) pre: true post: true activity: if (k < 1 or l + 1 = r) then ( return ) else skip ; k := k - 2 ; var mid : int := (l + r) div 2 ; var temp : OclAny := a[mid - 1+1] ; a[mid - 1+1] := a[mid+1] ; a[mid+1] := temp ; unsort(l, mid, a, k) ; unsort(mid, r, a, k); operation arrayWithKCalls(n : OclAny, k : OclAny) pre: true post: true activity: if (k mod 2 = 0) then ( execute ("NO SOLUTION")->display() ; return ) else skip ; a := Integer.subrange(0, n + 2-1)->select(i | true)->collect(i | (0)) ; a->first() := 1 ; for i : Integer.subrange(1, n-1) do ( a[i+1] := i + 1) ; k := k - 1 ; unsort(0, n, a, k) ; for i : Integer.subrange(0, n-1) do ( execute (a[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[] for i in range(4): c=input() a.append((len(c)-2,c[0])) a.sort() gs=a[0][0]*2<=a[1][0] gl=a[3][0]>=a[2][0]*2 if(gs and gl)or(not gs and not gl): print("C") else : print(a[0][1]if gs else a[3][1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Sequence{} ; for i : Integer.subrange(0, 4-1) do ( var c : String := (OclFile["System.in"]).readLine() ; execute ((Sequence{(c)->size() - 2, c->first()}) : a)) ; a := a->sort() ; var gs : boolean := (a->first()->first() * 2->compareTo(a[1+1]->first())) <= 0 ; var gl : boolean := (a[3+1]->first()->compareTo(a[2+1]->first() * 2)) >= 0 ; if (gs & gl) or (not(gs) & not(gl)) then ( execute ("C")->display() ) else ( execute (if gs then a->first()[1+1] else a[3+1][1+1] endif)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) mxa=max(a) mxb=max(b) if mxa>mxb : for j in range(n): if a[j]b[j]: a[j],b[j]=b[j],a[j] a.sort() print(a[n-1]*mxb) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mxa : OclAny := (a)->max() ; var mxb : OclAny := (b)->max() ; if (mxa->compareTo(mxb)) > 0 then ( for j : Integer.subrange(0, n-1) do ( if (a[j+1]->compareTo(b[j+1])) < 0 then ( var a[j+1] : OclAny := null; var b[j+1] : OclAny := null; Sequence{a[j+1],b[j+1]} := Sequence{b[j+1],a[j+1]} ) else skip) ; b := b->sort() ; execute (b[n - 1+1] * mxa)->display() ) else ( for j : Integer.subrange(0, n-1) do ( if (a[j+1]->compareTo(b[j+1])) > 0 then ( var a[j+1] : OclAny := null; var b[j+1] : OclAny := null; Sequence{a[j+1],b[j+1]} := Sequence{b[j+1],a[j+1]} ) else skip) ; a := a->sort() ; execute (a[n - 1+1] * mxb)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- one=len(input().split(".")[1]) two=len(input().split(".")[1]) three=len(input().split(".")[1]) four=len(input().split(".")[1]) l=[one,two,three,four] a=["A","B","C","D"] ans=[] for i in range(0,4): pos=True for j in range(0,4): if(i!=j): if l[i]*2>l[j]: pos=False if pos : ans.append(a[i]) else : pos=True for j in range(0,4): if(i!=j): if l[j]*2>l[i]: pos=False if pos : ans.append(a[i]) if(len(ans)==1): print(ans[0]) else : print("C") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var one : int := (input().split(".")[1+1])->size() ; var two : int := (input().split(".")[1+1])->size() ; var three : int := (input().split(".")[1+1])->size() ; var four : int := (input().split(".")[1+1])->size() ; var l : Sequence := Sequence{one}->union(Sequence{two}->union(Sequence{three}->union(Sequence{ four }))) ; var a : Sequence := Sequence{"A"}->union(Sequence{"B"}->union(Sequence{"C"}->union(Sequence{ "D" }))) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, 4-1) do ( var pos : boolean := true ; for j : Integer.subrange(0, 4-1) do ( if (i /= j) then ( if (l[i+1] * 2->compareTo(l[j+1])) > 0 then ( pos := false ) else skip ) else skip) ; if pos then ( execute ((a[i+1]) : ans) ) else ( pos := true ; for j : Integer.subrange(0, 4-1) do ( if (i /= j) then ( if (l[j+1] * 2->compareTo(l[i+1])) > 0 then ( pos := false ) else skip ) else skip) ; if pos then ( execute ((a[i+1]) : ans) ) else skip )) ; if ((ans)->size() = 1) then ( execute (ans->first())->display() ) else ( execute ("C")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(a,b,c,d): dc={} for i in[a,b,c,d]: dc[i]=len(i[2 :]) ans=[] if(dc[a]>=2*dc[b]and dc[a]>=2*dc[c]and dc[a]>=2*dc[d])or(2*dc[a]<=dc[b]and 2*dc[a]<=dc[c]and 2*dc[a]<=dc[d]): ans.append(a) if(dc[b]>=2*dc[a]and dc[b]>=2*dc[c]and dc[b]>=2*dc[d])or(2*dc[b]<=dc[a]and 2*dc[b]<=dc[c]and 2*dc[b]<=dc[d]): ans.append(b) if(dc[c]>=2*dc[b]and dc[c]>=2*dc[a]and dc[c]>=2*dc[d])or(2*dc[c]<=dc[b]and 2*dc[c]<=dc[a]and 2*dc[c]<=dc[d]): ans.append(c) if(dc[d]>=2*dc[b]and dc[d]>=2*dc[c]and dc[d]>=2*dc[a])or(2*dc[d]<=dc[b]and 2*dc[d]<=dc[c]and 2*dc[d]<=dc[a]): ans.append(d) if len(ans)==1 : return ans[0][0] return 'C' l3=input() l4=input() l5=input() l6=input() print(solve(l3,l4,l5,l6)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var l3 : String := (OclFile["System.in"]).readLine() ; var l4 : String := (OclFile["System.in"]).readLine() ; var l5 : String := (OclFile["System.in"]).readLine() ; var l6 : String := (OclFile["System.in"]).readLine() ; execute (solve(l3, l4, l5, l6))->display(); operation solve(a : OclAny, b : OclAny, c : OclAny, d : OclAny) : OclAny pre: true post: true activity: var dc : OclAny := Set{} ; for i : Sequence{a}->union(Sequence{b}->union(Sequence{c}->union(Sequence{ d }))) do ( dc[i+1] := (i.subrange(2+1))->size()) ; var ans : Sequence := Sequence{} ; if ((dc[a+1]->compareTo(2 * dc[b+1])) >= 0 & (dc[a+1]->compareTo(2 * dc[c+1])) >= 0 & (dc[a+1]->compareTo(2 * dc[d+1])) >= 0) or ((2 * dc[a+1]->compareTo(dc[b+1])) <= 0 & (2 * dc[a+1]->compareTo(dc[c+1])) <= 0 & (2 * dc[a+1]->compareTo(dc[d+1])) <= 0) then ( execute ((a) : ans) ) else skip ; if ((dc[b+1]->compareTo(2 * dc[a+1])) >= 0 & (dc[b+1]->compareTo(2 * dc[c+1])) >= 0 & (dc[b+1]->compareTo(2 * dc[d+1])) >= 0) or ((2 * dc[b+1]->compareTo(dc[a+1])) <= 0 & (2 * dc[b+1]->compareTo(dc[c+1])) <= 0 & (2 * dc[b+1]->compareTo(dc[d+1])) <= 0) then ( execute ((b) : ans) ) else skip ; if ((dc[c+1]->compareTo(2 * dc[b+1])) >= 0 & (dc[c+1]->compareTo(2 * dc[a+1])) >= 0 & (dc[c+1]->compareTo(2 * dc[d+1])) >= 0) or ((2 * dc[c+1]->compareTo(dc[b+1])) <= 0 & (2 * dc[c+1]->compareTo(dc[a+1])) <= 0 & (2 * dc[c+1]->compareTo(dc[d+1])) <= 0) then ( execute ((c) : ans) ) else skip ; if ((dc[d+1]->compareTo(2 * dc[b+1])) >= 0 & (dc[d+1]->compareTo(2 * dc[c+1])) >= 0 & (dc[d+1]->compareTo(2 * dc[a+1])) >= 0) or ((2 * dc[d+1]->compareTo(dc[b+1])) <= 0 & (2 * dc[d+1]->compareTo(dc[c+1])) <= 0 & (2 * dc[d+1]->compareTo(dc[a+1])) <= 0) then ( execute ((d) : ans) ) else skip ; if (ans)->size() = 1 then ( return ans->first()->first() ) else skip ; return 'C'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy tool=[] for lane in range(4): tool.append(len(input())-2) tool2=copy.deepcopy(tool) flag=-1 tool2.sort() if tool2[3]/tool2[2]>=2 : for i in range(4): if tool2[3]==tool[i]: flag=i if tool2[0]/tool2[1]<=0.5 : if flag==-1 : for i in range(4): if tool2[0]==tool[i]: flag=i else : flag=2 if flag==0 : print("A") if flag==1 : print("B") if flag==3 : print("D") if flag==-1 or flag==2 : print("C") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var tool : Sequence := Sequence{} ; for lane : Integer.subrange(0, 4-1) do ( execute ((((OclFile["System.in"]).readLine())->size() - 2) : tool)) ; var tool2 : OclAny := copy.deepcopy(tool) ; var flag : int := -1 ; tool2 := tool2->sort() ; if tool2[3+1] / tool2[2+1] >= 2 then ( for i : Integer.subrange(0, 4-1) do ( if tool2[3+1] = tool[i+1] then ( flag := i ) else skip) ) else skip ; if tool2->first() / tool2[1+1] <= 0.5 then ( if flag = -1 then ( for i : Integer.subrange(0, 4-1) do ( if tool2->first() = tool[i+1] then ( flag := i ) else skip) ) else ( flag := 2 ) ) else skip ; if flag = 0 then ( execute ("A")->display() ) else skip ; if flag = 1 then ( execute ("B")->display() ) else skip ; if flag = 3 then ( execute ("D")->display() ) else skip ; if flag = -1 or flag = 2 then ( execute ("C")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=list(map(int,input().split())) s=input() p=0 for i in s : p+=l[int(i)-1] print(p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : String := (OclFile["System.in"]).readLine() ; var p : int := 0 ; for i : s->characters() do ( p := p + l[("" + ((i)))->toInteger() - 1+1]) ; execute (p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def black_square(): a=list(map(int,input().split())) squares=input() calories=0 for square in squares : calories+=a[int(square)-1] return calories print(black_square()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (black_square())->display(); operation black_square() : OclAny pre: true post: true activity: var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var squares : String := (OclFile["System.in"]).readLine() ; var calories : int := 0 ; for square : squares->characters() do ( calories := calories + a[("" + ((square)))->toInteger() - 1+1]) ; return calories; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a1,a2,a3,a4=map(int,input().split()) s=input() s_m=[] for i in s : s_m.append(int(i)) print(s_m.count(1)*a1+s_m.count(2)*a2+s_m.count(3)*a3+s_m.count(4)*a4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a1 : OclAny := null; var a2 : OclAny := null; var a3 : OclAny := null; var a4 : OclAny := null; Sequence{a1,a2,a3,a4} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var s_m : Sequence := Sequence{} ; for i : s->characters() do ( execute ((("" + ((i)))->toInteger()) : s_m)) ; execute (s_m->count(1) * a1 + s_m->count(2) * a2 + s_m->count(3) * a3 + s_m->count(4) * a4)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cal=dict() cal[1],cal[2],cal[3],cal[4]=list(map(int,input().split())) strips=input() tot_cal=0 for i in strips : tot_cal+=cal[int(i)] print(tot_cal) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cal : Map := (arguments ( )) ; var cal[1+1] : OclAny := null; var cal[2+1] : OclAny := null; var cal[3+1] : OclAny := null; var cal[4+1] : OclAny := null; Sequence{cal[1+1],cal[2+1],cal[3+1],cal[4+1]} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var strips : String := (OclFile["System.in"]).readLine() ; var tot_cal : int := 0 ; for i : strips->characters() do ( tot_cal := tot_cal + cal[("" + ((i)))->toInteger()+1]) ; execute (tot_cal)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lst=list(map(int,input().split())) st=input() su=0 for i in range(len(st)): su+=lst[int(st[i])-1] print(su) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var st : String := (OclFile["System.in"]).readLine() ; var su : int := 0 ; for i : Integer.subrange(0, (st)->size()-1) do ( su := su + lst[("" + ((st[i+1])))->toInteger() - 1+1]) ; execute (su)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=[int(x)for x in input().split(" ")] lista=[int(x)for x in input().split(" ")] listb=[int(x)for x in input().split(" ")] for k in range(n): if k+1 in lista : print(1,end=" ") else : print(2,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var lista : Sequence := input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var listb : Sequence := input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for k : Integer.subrange(0, n-1) do ( if (lista)->includes(k + 1) then ( execute (1)->display() ) else ( execute (2)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def dfs(dig,nd,nsum): P=10**((dig-1)-nd)-10**nd maxc=10**((dig-1)-nd) if nd==dig//2 : if nsum==D : if dig % 2==0 : return 1 else : return 10 return 0 elif nd!=0 : ret=0 for i in range(-9,10): if nsum+P*iD+maxc : continue ret+=dfs(dig,nd+1,nsum+P*i)*sums[i] return ret else : ret=0 for i in range(-9,10): if nsum+P*iD+maxc : continue tmp=dfs(dig,nd+1,nsum+P*i)*sums_z[i] ret+=tmp return ret D=int(input()) ans=0 sums=[0]*30 for i in range(-9,10): for x in range(-9,1): for y in range(0,10): if x+y==i : sums[i]+=1 print(sums,file=sys.stderr) sums_z=[0]*30 for i in range(-9,10): for x in range(-9,0): for y in range(1,10): if x+y==i : sums_z[i]+=1 print(sums_z,file=sys.stderr) for dig in range(1,20): now=dfs(dig,0,0) ans+=now print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var D : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; var sums : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 30) ; for i : Integer.subrange(-9, 10-1) do ( for x : Integer.subrange(-9, 1-1) do ( for y : Integer.subrange(0, 10-1) do ( if x + y = i then ( sums[i+1] := sums[i+1] + 1 ) else skip))) ; execute (sums)->display() ; var sums_z : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 30) ; for i : Integer.subrange(-9, 10-1) do ( for x : Integer.subrange(-9, 0-1) do ( for y : Integer.subrange(1, 10-1) do ( if x + y = i then ( sums_z[i+1] := sums_z[i+1] + 1 ) else skip))) ; execute (sums_z)->display() ; for dig : Integer.subrange(1, 20-1) do ( var now : OclAny := dfs(dig, 0, 0) ; ans := ans + now) ; execute (ans)->display(); operation dfs(dig : OclAny, nd : OclAny, nsum : OclAny) : OclAny pre: true post: true activity: var P : double := (10)->pow(((dig - 1) - nd)) - (10)->pow(nd) ; var maxc : double := (10)->pow(((dig - 1) - nd)) ; if nd = dig div 2 then ( if nsum = D then ( if dig mod 2 = 0 then ( return 1 ) else ( return 10 ) ) else skip ; return 0 ) else (if nd /= 0 then ( var ret : int := 0 ; for i : Integer.subrange(-9, 10-1) do ( if (nsum + P * i->compareTo(D - maxc)) < 0 or (nsum + P * i->compareTo(D + maxc)) > 0 then ( continue ) else skip ; ret := ret + dfs(dig, nd + 1, nsum + P * i) * sums[i+1]) ; return ret ) else ( ret := 0 ; for i : Integer.subrange(-9, 10-1) do ( if (nsum + P * i->compareTo(D - maxc)) < 0 or (nsum + P * i->compareTo(D + maxc)) > 0 then ( continue ) else skip ; var tmp : double := dfs(dig, nd + 1, nsum + P * i) * sums_z[i+1] ; ret := ret + tmp) ; return ret ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def cntSubSeq(arr,n): pos_count=0 ; neg_count=0 for i in range(n): if(arr[i]>0): pos_count+=1 if(arr[i]<0): neg_count+=1 result=int(math.pow(2,pos_count)) if(neg_count>0): result*=int(math.pow(2,neg_count-1)) else : result=0 return result arr=[2,-3,-1,4] n=len(arr); print(cntSubSeq(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{2}->union(Sequence{-3}->union(Sequence{-1}->union(Sequence{ 4 }))) ; n := (arr)->size(); ; execute (cntSubSeq(arr, n))->display(); operation cntSubSeq(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var pos_count : int := 0; ; var neg_count : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] > 0) then ( pos_count := pos_count + 1 ) else skip ; if (arr[i+1] < 0) then ( neg_count := neg_count + 1 ) else skip) ; var result : int := ("" + (((2)->pow(pos_count))))->toInteger() ; if (neg_count > 0) then ( result := result * ("" + (((2)->pow(neg_count - 1))))->toInteger() ) else ( result := 0 ) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def cntSubSeq(arr,n): pos_count=0 ; neg_count=0 for i in range(n): if(arr[i]>0): pos_count+=1 if(arr[i]<0): neg_count+=1 result=int(math.pow(2,pos_count)) if(neg_count>0): result*=int(math.pow(2,neg_count-1)) result-=1 return result arr=[2,-3,-1,4] n=len(arr); print(cntSubSeq(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{2}->union(Sequence{-3}->union(Sequence{-1}->union(Sequence{ 4 }))) ; n := (arr)->size(); ; execute (cntSubSeq(arr, n))->display(); operation cntSubSeq(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var pos_count : int := 0; ; var neg_count : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] > 0) then ( pos_count := pos_count + 1 ) else skip ; if (arr[i+1] < 0) then ( neg_count := neg_count + 1 ) else skip) ; var result : int := ("" + (((2)->pow(pos_count))))->toInteger() ; if (neg_count > 0) then ( result := result * ("" + (((2)->pow(neg_count - 1))))->toInteger() ) else skip ; result := result - 1 ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) a=[int(i)for i in input().split()] b=[int(i)for i in input().split()] for i in range(n): if a[i]toInteger() ; var ans : Sequence := Sequence{} ; while t do ( execute ((("" + ((solve())))) : ans) ; t := t - 1) ; execute (StringLib.sumStringsWithSeparator((ans), "\n"))->display(); operation solve() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var b : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; for i : Integer.subrange(0, n-1) do ( if (a[i+1]->compareTo(b[i+1])) < 0 then ( var a[i+1] : OclAny := null; var b[i+1] : OclAny := null; Sequence{a[i+1],b[i+1]} := Sequence{b[i+1],a[i+1]} ) else skip) ; return (a)->max() * (b)->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sum(ar,n): mp=dict() for i in ar : if i in mp : mp[i]+=1 else : mp[i]=1 mp=sorted(list(mp.items())) sum=0 for pair in mp : n-=pair[1] sum+=n return sum def main(): n=6 ar=[5,4,4,2,2,8] ans=sum(ar,n) print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation sum(ar : OclAny, n : OclAny) : OclAny pre: true post: true activity: var mp : Map := (arguments ( )) ; for i : ar do ( if (mp)->includes(i) then ( mp[i+1] := mp[i+1] + 1 ) else ( mp[i+1] := 1 )) ; mp := (mp->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}))->sort() ; var sum : int := 0 ; for pair : mp->keys() do ( n := n - pair[1+1] ; sum := sum + n) ; return sum; operation main() pre: true post: true activity: n := 6 ; ar := Sequence{5}->union(Sequence{4}->union(Sequence{4}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 8 }))))) ; var ans : OclAny := (ar, n)->sum() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def permutation(arr,n): s=set() maxEle=0 ; for i in range(n): s.add(arr[i]); maxEle=max(maxEle,arr[i]); if(maxEle!=n): return False if(len(s)==n): return True ; return False ; if __name__=='__main__' : arr=[1,2,5,3,2] n=len(arr) if(permutation(arr,n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{5}->union(Sequence{3}->union(Sequence{ 2 })))) ; n := (arr)->size() ; if (permutation(arr, n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation permutation(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var s : Set := Set{}->union(()) ; var maxEle : int := 0; ; for i : Integer.subrange(0, n-1) do ( execute ((arr[i+1]) : s); ; maxEle := Set{maxEle, arr[i+1]}->max();) ; if (maxEle /= n) then ( return false ) else skip ; if ((s)->size() = n) then ( return true; ) else skip ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getPassingCars(A,n): result=0 for i in range(0,n-1,1): if(A[i]==0): for j in range(i+1,n,1): if(A[j]): result+=1 return result if __name__=='__main__' : A=[0,1,0,1,1] n=len(A) print(getPassingCars(A,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( A := Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 1 })))) ; n := (A)->size() ; execute (getPassingCars(A, n))->display() ) else skip; operation getPassingCars(A : OclAny, n : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; for i : Integer.subrange(0, n - 1-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (A[i+1] = 0) then ( for j : Integer.subrange(i + 1, n-1)->select( $x | ($x - i + 1) mod 1 = 0 ) do ( if (A[j+1]) then ( result := result + 1 ) else skip) ) else skip) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def main(w,h): field=[list(input())for i in range(h)] d=defaultdict(str) for y in range(h-1,-1,-1): for x in range(w-1,-1,-1): if "0"<=field[y][x]<="9" : d[(x,y)]=field[y][x] for y in range(h-1,-1,-1): for x in range(w-1,-1,-1): if "0"<=field[y][x]<="9" : if len(d[(x+1,y)])==len(d[(x,y+1)]): d[(x,y)]=field[y][x]+max(d[(x+1,y)],d[(x,y+1)]) elif len(d[(x+1,y)])collect( _x | (OclType["int"])->apply(_x) ) ; if h = w & (w == 0) then ( break ) else skip ; main(w, h)); operation main(w : OclAny, h : OclAny) pre: true post: true activity: var field : Sequence := Integer.subrange(0, h-1)->select(i | true)->collect(i | (((OclFile["System.in"]).readLine())->characters())) ; var d : OclAny := defaultdict(OclType["String"]) ; for y : Integer.subrange(-1 + 1, h - 1)->reverse() do ( for x : Integer.subrange(-1 + 1, w - 1)->reverse() do ( if "0" <= field[y+1][x+1] & (field[y+1][x+1] <= "9") then ( d[Sequence{x, y}+1] := field[y+1][x+1] ) else skip)) ; for y : Integer.subrange(-1 + 1, h - 1)->reverse() do ( for x : Integer.subrange(-1 + 1, w - 1)->reverse() do ( if "0" <= field[y+1][x+1] & (field[y+1][x+1] <= "9") then ( if (d[Sequence{x + 1, y}+1])->size() = (d[Sequence{x, y + 1}+1])->size() then ( d[Sequence{x, y}+1] := field[y+1][x+1] + Set{d[Sequence{x + 1, y}+1], d[Sequence{x, y + 1}+1]}->max() ) else (if ((d[Sequence{x + 1, y}+1])->size()->compareTo((d[Sequence{x, y + 1}+1])->size())) < 0 then ( d[Sequence{x, y}+1] := field[y+1][x+1] + d[Sequence{x, y + 1}+1] ) else ( d[Sequence{x, y}+1] := field[y+1][x+1] + d[Sequence{x + 1, y}+1] ) ) ) else skip)) ; var ans : int := 0 ; for v : d.values() do ( if v = "" then ( continue ) else skip ; ans := Set{ans, ("" + ((v)))->toInteger()}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from heapq import heappush,heappop import sys import math import bisect import random def LI(): return list(map(int,sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return list(map(list,sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] sys.setrecursionlimit(1000000) mod=1000000007 while 1 : w,h=LI() if w==h==0 : break s=SR(h) dp=[[0]*w for i in range(h)] for y in range(h): for x in range(w): if s[y][x].isdecimal(): dp[y][x]=max(dp[y-1][x],dp[y][x-1])*10+int(s[y][x]) ans=0 for i in dp : ans=max(ans,max(i)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1000000) ; var mod : int := 1000000007 ; while 1 do ( var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := LI() ; if w = h & (h == 0) then ( break ) else skip ; var s : OclAny := SR(h) ; var dp : Sequence := Integer.subrange(0, h-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, w))) ; for y : Integer.subrange(0, h-1) do ( for x : Integer.subrange(0, w-1) do ( if s[y+1][x+1]->matches("[0-9]*") then ( dp[y+1][x+1] := Set{dp[y - 1+1][x+1], dp[y+1][x - 1+1]}->max() * 10 + ("" + ((s[y+1][x+1])))->toInteger() ) else skip)) ; var ans : int := 0 ; for i : dp do ( ans := Set{ans, (i)->max()}->max()) ; execute (ans)->display()); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["Sequence"])->apply(_x) )); operation S() : OclAny pre: true post: true activity: return OclType["Sequence"]((OclFile["System.in"]).readLine())->front(); operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- drc=[(0,1),(1,0)] def dfs(r,c): if(r,c)in memo : return memo[r,c] ret='' for dr,dc in drc : nr,nc=r+dr,c+dc if nrlen(ret)or(len(cand)==len(ret)and cand>ret): ret=cand memo[r,c]=board[r][c]+''.join(ret) return board[r][c]+ret while True : W,H=map(int,input().split()) if not(W | H): break board=[input()for _ in range(H)] memo=dict() ans='' for r in range(H): for c in range(W): if board[r][c].isdigit()and board[r][c]!='0' : cand=dfs(r,c) if len(cand)>len(ans)or(len(cand)==len(ans)and cand>ans): ans=cand print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var drc : Sequence := Sequence{Sequence{0, 1}}->union(Sequence{ Sequence{1, 0} }) ; skip ; while true do ( var W : OclAny := null; var H : OclAny := null; Sequence{W,H} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if not((MathLib.bitwiseOr(W, H))) then ( break ) else skip ; var board : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var memo : Map := (arguments ( )) ; var ans : String := '' ; for r : Integer.subrange(0, H-1) do ( for c : Integer.subrange(0, W-1) do ( if board[r+1][c+1]->matches("[0-9]*") & board[r+1][c+1] /= '0' then ( cand := dfs(r, c) ; if ((cand)->size()->compareTo((ans)->size())) > 0 or ((cand)->size() = (ans)->size() & cand > ans) then ( ans := cand ) else skip ) else skip)) ; execute (ans)->display()); operation dfs(r : OclAny, c : OclAny) : OclAny pre: true post: true activity: if (memo)->includes(Sequence{r, c}) then ( return memo[r+1][c+1] ) else skip ; var ret : String := '' ; for _tuple : drc do (var _indx : int := 1; var dr : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dc : OclAny := _tuple->at(_indx); var nr : OclAny := null; var nc : OclAny := null; Sequence{nr,nc} := Sequence{r + dr,c + dc} ; if (nr->compareTo(H)) < 0 & (nc->compareTo(W)) < 0 & board[nr+1][nc+1]->matches("[0-9]*") then ( var cand : OclAny := dfs(nr, nc) ; if ((cand)->size()->compareTo((ret)->size())) > 0 or ((cand)->size() = (ret)->size() & cand > ret) then ( ret := cand ) else skip ) else skip) ; memo[r+1][c+1] := board[r+1][c+1] + StringLib.sumStringsWithSeparator((ret), '') ; return board[r+1][c+1] + ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**9) input=sys.stdin.readline def isdigit(x): return '0'<=x<='9' def solve(): W,H=map(int,input().split()) if W==0 : exit() grid=[[v for v in input()[:-1]]for _ in range(H)] dp=[[-1]*W for _ in range(H)] max_val=0 for row in range(H): for col in range(W): if isdigit(grid[row][col]): if row>0 and col>0 : cand=max(dp[row-1][col],dp[row][col-1],0) elif row==0 and col==0 : cand=0 elif row==0 : cand=max(dp[row][col-1],0) elif col==0 : cand=max(dp[row-1][col],0) dp[row][col]=cand*10+int(grid[row][col]) max_val=max(max_val,dp[row][col]) print(max_val) while True : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(9)) ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; while true do ( solve()); operation isdigit(x : OclAny) : OclAny pre: true post: true activity: return '0' <= x & (x <= '9'); operation solve() pre: true post: true activity: var W : OclAny := null; var H : OclAny := null; Sequence{W,H} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if W = 0 then ( exit() ) else skip ; var grid : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (input()->front()->select(v | true)->collect(v | (v)))) ; var dp : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ -1 }, W))) ; var max_val : int := 0 ; for row : Integer.subrange(0, H-1) do ( for col : Integer.subrange(0, W-1) do ( if isdigit(grid[row+1][col+1]) then ( if row > 0 & col > 0 then ( var cand : OclAny := Set{dp[row - 1+1][col+1], dp[row+1][col - 1+1], 0}->max() ) else (if row = 0 & col = 0 then ( cand := 0 ) else (if row = 0 then ( cand := Set{dp[row+1][col - 1+1], 0}->max() ) else (if col = 0 then ( cand := Set{dp[row - 1+1][col+1], 0}->max() ) else skip ) ) ) ; dp[row+1][col+1] := cand * 10 + ("" + ((grid[row+1][col+1])))->toInteger() ; max_val := Set{max_val, dp[row+1][col+1]}->max() ) else skip)) ; execute (max_val)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- D=int(input()) def table(i,k): if i==k : return list(range(9,-1,-1))+[0]*9 else : return list(range(10,0,-1))+list(range(1,10)) def nine(i): return 10**i-1 def rec(d,i,k): res=0 num=table(i,k) if i==1 : for j in range(-9,10): if 9*j==d : return num[j] return 0 if i==2 : for j in range(-9,10): if d==99*j : return 10*num[j] if not-10*nine(i)<=d<=10*nine(i): return 0 for j in range(-9,10): if d % 10==j*nine(i)% 10 : res+=num[j]*rec((d-j*nine(i))//10,i-2,k) return res l=0 while D % 10==0 : D//=10 l+=1 if l==0 : a=1 else : a=9*10**(l-1) ans=0 for i in range(1,20): if not l : ans+=rec(D,i,i) else : ans+=rec(D,i,100) print(a*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var D : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; skip ; skip ; var l : int := 0 ; while D mod 10 = 0 do ( D := D div 10 ; l := l + 1) ; if l = 0 then ( var a : int := 1 ) else ( a := 9 * (10)->pow((l - 1)) ) ; var ans : int := 0 ; for i : Integer.subrange(1, 20-1) do ( if not(l) then ( ans := ans + rec(D, i, i) ) else ( ans := ans + rec(D, i, 100) )) ; execute (a * ans)->display(); operation table(i : OclAny, k : OclAny) : OclAny pre: true post: true activity: if i = k then ( return (Integer.subrange(-1 + 1, 9)->reverse())->union(MatrixLib.elementwiseMult(Sequence{ 0 }, 9)) ) else ( return (Integer.subrange(0 + 1, 10)->reverse())->union((Integer.subrange(1, 10-1))) ); operation nine(i : OclAny) : OclAny pre: true post: true activity: return (10)->pow(i) - 1; operation rec(d : OclAny, i : OclAny, k : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; var num : OclAny := table(i, k) ; if i = 1 then ( for j : Integer.subrange(-9, 10-1) do ( if 9 * j = d then ( return num[j+1] ) else skip) ; return 0 ) else skip ; if i = 2 then ( for j : Integer.subrange(-9, 10-1) do ( if d = 99 * j then ( return 10 * num[j+1] ) else skip) ) else skip ; if not((-10 * nine(i)->compareTo(d)) <= 0 & (d <= 10 * nine(i))) then ( return 0 ) else skip ; for j : Integer.subrange(-9, 10-1) do ( if d mod 10 = j * nine(i) mod 10 then ( res := res + num[j+1] * rec((d - j * nine(i)) div 10, i - 2, k) ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : W,H=map(int,input().split()) if W==0 : break d=[list(input())for r in range(H)] a=[[0 for c in range(W)]for r in range(H)] ans=0 for r in range(H): for c in range(W): if not d[r][c].isdigit(): continue a[r][c]=k=int(d[r][c]) if c>0 and d[r][c-1].isdigit(): a[r][c]=a[r][c-1]*10+k if r>0 and d[r-1][c].isdigit(): t=a[r-1][c]*10+k a[r][c]=max(a[r][c],t) ans=max(ans,a[r][c]) print(ans); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var W : OclAny := null; var H : OclAny := null; Sequence{W,H} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if W = 0 then ( break ) else skip ; var d : Sequence := Integer.subrange(0, H-1)->select(r | true)->collect(r | (((OclFile["System.in"]).readLine())->characters())) ; var a : Sequence := Integer.subrange(0, H-1)->select(r | true)->collect(r | (Integer.subrange(0, W-1)->select(c | true)->collect(c | (0)))) ; var ans : int := 0 ; for r : Integer.subrange(0, H-1) do ( for c : Integer.subrange(0, W-1) do ( if not(d[r+1][c+1]->matches("[0-9]*")) then ( continue ) else skip ; a[r+1][c+1] := ("" + ((d[r+1][c+1])))->toInteger(); var k : int := ("" + ((d[r+1][c+1])))->toInteger() ; if c > 0 & d[r+1][c - 1+1]->matches("[0-9]*") then ( a[r+1][c+1] := a[r+1][c - 1+1] * 10 + k ) else skip ; if r > 0 & d[r - 1+1][c+1]->matches("[0-9]*") then ( var t : double := a[r - 1+1][c+1] * 10 + k ; a[r+1][c+1] := Set{a[r+1][c+1], t}->max() ) else skip ; ans := Set{ans, a[r+1][c+1]}->max())) ; execute (ans)->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(arr): ans=0 arr.sort() for i in range(len(arr)): ok=0 for j in range(i): if arr[i]% arr[j]==0 : ok=1 break if not ok : ans+=1 return ans n=int(input()) arr=list(map(int,input().split())) print(solve(arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; arr := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (solve(arr))->display(); operation solve(arr : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; arr := arr->sort() ; for i : Integer.subrange(0, (arr)->size()-1) do ( var ok : int := 0 ; for j : Integer.subrange(0, i-1) do ( if arr[i+1] mod arr[j+1] = 0 then ( ok := 1 ; break ) else skip) ; if not(ok) then ( ans := ans + 1 ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) len_a=len(a) s=0 while len_a!=0 : min_a=min(a) i=0 b=[] while i!=len_a : if a[i]% min_a==0 : del a[i] i-=1 len_a-=1 else : b.append(a[i]) i+=1 s+=1 a=b len_a=len(a) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var len_a : int := (a)->size() ; var s : int := 0 ; while len_a /= 0 do ( var min_a : OclAny := (a)->min() ; var i : int := 0 ; var b : Sequence := Sequence{} ; while i /= len_a do ( if a[i+1] mod min_a = 0 then ( execute (a[i+1])->isDeleted() ; i := i - 1 ; len_a := len_a - 1 ) else ( execute ((a[i+1]) : b) ) ; i := i + 1) ; s := s + 1 ; a := b ; len_a := (a)->size()) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): s=input() if s.find('.')!=-1 : d,f=s.split('.') else : d=s f=[] neg=d[0]=='-' if neg : d=d[1 :] output=[] for i,e in enumerate(d[: :-1]): if i!=0 and i % 3==0 : output.append(',') output.append(e) output=output[: :-1] output.append('.') if len(f)>=2 : output.append(f[0]) output.append(f[1]) elif len(f)==1 : output.append(f[0]) output.append('0') else : output.append('00') if neg : print(f'(${"".join(output)})') else : print(f'${"".join(output)}') if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; if s->indexOf('.') - 1 /= -1 then ( var d : OclAny := null; var f : OclAny := null; Sequence{d,f} := s.split('.') ) else ( var d : String := s ; var f : Sequence := Sequence{} ) ; var neg : boolean := d->first() = '-' ; if neg then ( d := d->tail() ) else skip ; var output : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (d(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->size())->collect( _indx | Sequence{_indx-1, (d(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var e : OclAny := _tuple->at(_indx); if i /= 0 & i mod 3 = 0 then ( execute ((',') : output) ) else skip ; execute ((e) : output)) ; output := output(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; execute (('.') : output) ; if (f)->size() >= 2 then ( execute ((f->first()) : output) ; execute ((f[1+1]) : output) ) else (if (f)->size() = 1 then ( execute ((f->first()) : output) ; execute (('0') : output) ) else ( execute (('00') : output) ) ) ; if neg then ( execute (StringLib.formattedString('(${"".join(output)})'))->display() ) else ( execute (StringLib.formattedString('${"".join(output)}'))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) for i in range(n): if a[i]toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( if (a[i+1]->compareTo(b[i+1])) < 0 then ( var a[i+1] : OclAny := null; var b[i+1] : OclAny := null; Sequence{a[i+1],b[i+1]} := Sequence{b[i+1],a[i+1]} ) else skip) ; execute ((a)->max() * (b)->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) array=list(map(int,input().split())) len_arr=len(array) s=0 while len_arr!=0 : min_arr=min(array) i=0 buf=[] while i!=len_arr : if array[i]% min_arr==0 : del array[i] i-=1 len_arr-=1 else : buf.append(array[i]) i+=1 s+=1 array=buf len_arr=len(array) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var array : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var len_arr : int := (array)->size() ; var s : int := 0 ; while len_arr /= 0 do ( var min_arr : OclAny := (array)->min() ; var i : int := 0 ; var buf : Sequence := Sequence{} ; while i /= len_arr do ( if array[i+1] mod min_arr = 0 then ( execute (array[i+1])->isDeleted() ; i := i - 1 ; len_arr := len_arr - 1 ) else ( execute ((array[i+1]) : buf) ) ; i := i + 1) ; s := s + 1 ; array := buf ; len_arr := (array)->size()) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) element=list(map(int,input().split())) count=0 while element!=[]: minmum=min(element) element_new=[] for i in range(len(element)): if element[i]% minmum!=0 : element_new.append(element[i]) element=element_new[:] count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var element : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : int := 0 ; while element /= Sequence{} do ( var minmum : OclAny := (element)->min() ; var element_new : Sequence := Sequence{} ; for i : Integer.subrange(0, (element)->size()-1) do ( if element[i+1] mod minmum /= 0 then ( execute ((element[i+1]) : element_new) ) else skip) ; element := element_new ; count := count + 1) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() a=set(map(int,input().split())) print(sum(all(x % y for y in a-{x})for x in a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var a : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; execute (((argument (test (logical_test (comparison (expr (atom (name all)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) % (expr (atom (name y))))))) (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom { (dictorsetmaker (testlist_comp (test (logical_test (comparison (expr (atom (name x)))))))) })))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) s=input() ans=[] cur="" used=set() for i in range(len(s)): if s[i]not in used : if len(cur)>0 : ans.append(cur) cur=s[i] used.add(s[i]) else : cur+=s[i] ans.append(cur) if len(ans)toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var ans : Sequence := Sequence{} ; var cur : String := "" ; var used : Set := Set{}->union(()) ; for i : Integer.subrange(0, (s)->size()-1) do ( if (used)->excludes(s[i+1]) then ( if (cur)->size() > 0 then ( execute ((cur) : ans) ) else skip ; cur := s[i+1] ; execute ((s[i+1]) : used) ) else ( cur := cur + s[i+1] )) ; execute ((cur) : ans) ; if ((ans)->size()->compareTo(k)) < 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; for i : Integer.subrange(k, (ans)->size()-1) do ( ans[k - 1+1] := ans[k - 1+1] + ans[i+1]) ; for i : Integer.subrange(0, k-1) do ( execute (ans[i+1])->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline k=int(input()) s=input()[:-1] y=len(s) d=[] w={s[0]} c=0 for i in range(y-1): if s[i+1]!=s[i]and s[i+1]not in w : w.add(s[i+1]) k-=1 if k==0 : d.append(s[i-c :]) break else : d.append(s[i-c : i+1]) c=0 else : c+=1 if k==1 : k-=1 d.append(s[y-1-c :]) if k>0 : print("NO") else : print("YES") for i in d : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := input()->front() ; var y : int := (s)->size() ; var d : Sequence := Sequence{} ; var w : Set := Set{ s->first() } ; var c : int := 0 ; for i : Integer.subrange(0, y - 1-1) do ( if s[i + 1+1] /= s[i+1] & (w)->excludes(s[i + 1+1]) then ( execute ((s[i + 1+1]) : w) ; k := k - 1 ; if k = 0 then ( execute ((s.subrange(i - c+1)) : d) ; break ) else ( execute ((s.subrange(i - c+1, i + 1)) : d) ) ; c := 0 ) else ( c := c + 1 )) ; if k = 1 then ( k := k - 1 ; execute ((s.subrange(y - 1 - c+1)) : d) ) else skip ; if k > 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; for i : d do ( execute (i)->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000,10**9)) write=lambda x : sys.stdout.write(x+"\n") d=int(input()) def main(d): from collections import defaultdict vals=defaultdict(int) vals2=defaultdict(int) for i in range(10): for j in range(10): vals[i-j]+=1 if j>0 : vals2[i-j]+=1 def sub(n): vs=[] for i in range(n): if i>=n-i : break vs.append(pow(10,n-i)-pow(10,i)) def _sub(val,i): if i==len(vs): if val==0 : return 1 else : return 0 ans=0 for j in range(-9,10): if(vs[i]*j)% pow(10,i+1)==val %(pow(10,i+1)): ans+=_sub(val-vs[i]*j,i+1)*vals[j] return ans ans=0 for i in range(-9,10): if(vs[0]*i)% 10==d % 10 : ans+=_sub(d-vs[0]*i,1)*vals2[i] if n % 2==0 : ans*=10 return ans ans=0 i=1 while True : val=sub(i) ans+=val if i>20 : break i+=1 return ans print(main(d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; sys.setrecursionlimit(Set{1000, (10)->pow(9)}->max()) ; var write : Function := lambda x : OclAny in ((OclFile["System.out"]).write(x + "\n")) ; var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; execute (main(d))->display(); operation main(d : OclAny) : OclAny pre: true post: true activity: skip ; var vals : OclAny := defaultdict(OclType["int"]) ; var vals2 : OclAny := defaultdict(OclType["int"]) ; for i : Integer.subrange(0, 10-1) do ( for j : Integer.subrange(0, 10-1) do ( vals[i - j+1] := vals[i - j+1] + 1 ; if j > 0 then ( vals2[i - j+1] := vals2[i - j+1] + 1 ) else skip)) ; skip ; ans := 0 ; i := 1 ; while true do ( val := sub(i) ; ans := ans + val ; if i > 20 then ( break ) else skip ; i := i + 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) s=input() sp=[-1]*26 ln=0 for i in range(len(s)): if sp[ord(s[i])-ord('a')]==-1 : ln+=1 sp[ord(s[i])-ord('a')]=i if lntoInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var sp : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, 26) ; var ln : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if sp[(s[i+1])->char2byte() - ('a')->char2byte()+1] = -1 then ( ln := ln + 1 ; sp[(s[i+1])->char2byte() - ('a')->char2byte()+1] := i ) else skip) ; if (ln->compareTo(k)) < 0 then ( execute ('NO')->display() ; quit() ) else skip ; execute (((s)->size()) : sp) ; sp := sp->sort() ; execute ('YES')->display() ; var ans : Sequence := Sequence{} ; var kol : int := 0 ; for i : Integer.subrange(0, (sp)->size()-1) do ( if sp[i+1] /= -1 & kol /= k - 1 then ( execute ((s.subrange(sp[i+1]+1, sp[i + 1+1])) : ans) ; kol := kol + 1 ) else (if sp[i+1] /= -1 then ( execute ((s.subrange(sp[i+1]+1)) : ans) ; break ) else skip)) ; for i : ans do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() if n>len(list(set(s))): print('NO') else : print('YES') l=set() for i in range(n): if i==n-1 : print(s) else : a='.' while(len(a)<2 or s[0]in l or a[1]==s[0])and len(s)>1 : a+=s[0] s=s[1 :] print(a[1 :]) l.add(a[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; if (n->compareTo(((Set{}->union((s))))->size())) > 0 then ( execute ('NO')->display() ) else ( execute ('YES')->display() ; var l : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( if i = n - 1 then ( execute (s)->display() ) else ( var a : String := '.' ; while ((a)->size() < 2 or (l)->includes(s->first()) or a[1+1] = s->first()) & (s)->size() > 1 do ( a := a + s->first() ; s := s->tail()) ; execute (a->tail())->display() ; execute ((a[1+1]) : l) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) q=input() visited=set() indices=[] for i in range(len(q)): if q[i]not in visited : indices.append(i); visited.add(q[i]) strings=[] for i in range(len(indices)-1): if i+1==k : strings.append(q[indices[i]:]); break else : strings.append(q[indices[i]: indices[i+1]]) if len(strings)toInteger() ; var q : String := (OclFile["System.in"]).readLine() ; var visited : Set := Set{}->union(()) ; var indices : Sequence := Sequence{} ; for i : Integer.subrange(0, (q)->size()-1) do ( if (visited)->excludes(q[i+1]) then ( execute ((i) : indices); execute ((q[i+1]) : visited) ) else skip) ; var strings : Sequence := Sequence{} ; for i : Integer.subrange(0, (indices)->size() - 1-1) do ( if i + 1 = k then ( execute ((q.subrange(indices[i+1]+1)) : strings); break ) else ( execute ((q.subrange(indices[i+1]+1, indices[i + 1+1])) : strings) )) ; if ((strings)->size()->compareTo(k)) < 0 then ( execute ((q.subrange(indices->last()+1)) : strings) ) else skip ; if ((strings)->size()->compareTo(k)) < 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name strings))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxSum(a,n): ans=0 arr=[0]*(n+1) for i in range(1,n+1): arr[i]=a[i-1] dp=[[0 for i in range(3)]for j in range(n+1)] for i in range(0,n+1): dp[i][0]=max(arr[i],dp[i-1][0]+arr[i]) dp[i][1]=max(0,dp[i-1][0])-arr[i] if i>=2 : dp[i][1]=max(dp[i][1],dp[i-1][1]+arr[i]) if i>=2 : dp[i][2]=dp[i-1][1]-arr[i] if i>=3 : dp[i][2]=max(dp[i][2],dp[i-1][2]+arr[i]) ans=max(ans,dp[i][0]) ans=max(ans,dp[i][1]) ans=max(ans,dp[i][2]) return ans if __name__=="__main__" : arr=[-5,3,2,7,-8,3,7,-9,10,12,-6] n=len(arr) print(maxSum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{-5}->union(Sequence{3}->union(Sequence{2}->union(Sequence{7}->union(Sequence{-8}->union(Sequence{3}->union(Sequence{7}->union(Sequence{-9}->union(Sequence{10}->union(Sequence{12}->union(Sequence{ -6 })))))))))) ; n := (arr)->size() ; execute (maxSum(arr, n))->display() ) else skip; operation maxSum(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(1, n + 1-1) do ( arr[i+1] := a[i - 1+1]) ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, 3-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, n + 1-1) do ( dp[i+1]->first() := Set{arr[i+1], dp[i - 1+1]->first() + arr[i+1]}->max() ; dp[i+1][1+1] := Set{0, dp[i - 1+1]->first()}->max() - arr[i+1] ; if i >= 2 then ( dp[i+1][1+1] := Set{dp[i+1][1+1], dp[i - 1+1][1+1] + arr[i+1]}->max() ) else skip ; if i >= 2 then ( dp[i+1][2+1] := dp[i - 1+1][1+1] - arr[i+1] ) else skip ; if i >= 3 then ( dp[i+1][2+1] := Set{dp[i+1][2+1], dp[i - 1+1][2+1] + arr[i+1]}->max() ) else skip ; ans := Set{ans, dp[i+1]->first()}->max() ; ans := Set{ans, dp[i+1][1+1]}->max() ; ans := Set{ans, dp[i+1][2+1]}->max()) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(a==0): return b ; return gcd(b % a,a); def lcm(n,m): return(n*m)//gcd(n,m); if __name__=="__main__" : n=2 ; m=3 ; k=5 ; print(k//lcm(n,m)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 2; m := 3; var k : int := 5; ; execute (k div lcm(n, m))->display(); ) else skip; operation gcd(a : OclAny, b : OclAny) pre: true post: true activity: if (a = 0) then ( return b; ) else skip ; return gcd(b mod a, a);; operation lcm(n : OclAny, m : OclAny) pre: true post: true activity: return (n * m) div gcd(n, m);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=int(input()) for _ in range(m): n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) for i in range(n): if a[i]>b[i]: a[i],b[i]=b[i],a[i] print(max(a)*max(b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, m-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( if (a[i+1]->compareTo(b[i+1])) > 0 then ( var a[i+1] : OclAny := null; var b[i+1] : OclAny := null; Sequence{a[i+1],b[i+1]} := Sequence{b[i+1],a[i+1]} ) else skip) ; execute ((a)->max() * (b)->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=int(input()),[int(t)for t in input().split()] ub=int(max(m)**0.5)+1 isprimes=[1]*ub for i in range(2,ub+1): if isprimes[i-1]: j=2 while j*i<=ub : isprimes[j*i-1]=0 j+=1 isprimes[0]=0 for k in m : div=int(k**0.5) if div*div==k : if isprimes[div-1]: print('YES') else : print('NO') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),input().split()->select(t | true)->collect(t | (("" + ((t)))->toInteger()))} ; var ub : int := ("" + ((((m)->max())->pow(0.5))))->toInteger() + 1 ; var isprimes : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, ub) ; for i : Integer.subrange(2, ub + 1-1) do ( if isprimes[i - 1+1] then ( var j : int := 2 ; while (j * i->compareTo(ub)) <= 0 do ( isprimes[j * i - 1+1] := 0 ; j := j + 1) ) else skip) ; isprimes->first() := 0 ; for k : m do ( var div : int := ("" + (((k)->pow(0.5))))->toInteger() ; if div * div = k then ( if isprimes[div - 1+1] then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p_set={2} judge=[True]*(10**6+1) for j in range(3,10**6+1,2): if judge[j]: p_set.add(j) for k in range(3*j,10**6+1,2*j): judge[k]=False import math N=int(input()) for a in input().split(): if math.sqrt(int(a))in p_set : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p_set : Set := Set{ 2 } ; var judge : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, ((10)->pow(6) + 1)) ; for j : Integer.subrange(3, (10)->pow(6) + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if judge[j+1] then ( execute ((j) : p_set) ; for k : Integer.subrange(3 * j, (10)->pow(6) + 1-1)->select( $x | ($x - 3 * j) mod 2 * j = 0 ) do ( judge[k+1] := false) ) else skip) ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for a : input().split() do ( if (p_set)->includes((("" + ((a)))->toInteger())->sqrt()) then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- es={2} Td=[True]*(10**6+1) for i in range(3,10**6+1,2): if Td[i]: es.add(i) for j in range(2*i,10**6+1,i): Td[j]=False import math n=int(input()) for a in input().split(): if math.sqrt(int(a))in es : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var es : Set := Set{ 2 } ; var Td : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, ((10)->pow(6) + 1)) ; for i : Integer.subrange(3, (10)->pow(6) + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if Td[i+1] then ( execute ((i) : es) ; for j : Integer.subrange(2 * i, (10)->pow(6) + 1-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ( Td[j+1] := false) ) else skip) ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for a : input().split() do ( if (es)->includes((("" + ((a)))->toInteger())->sqrt()) then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=int(input()),[int(t)for t in input().split()] ub=int(max(m)**0.5)+1 isprimes=[1]*ub for i in range(2,ub+1): if isprimes[i-1]: j=2 while j*i<=ub : isprimes[j*i-1]=0 j+=1 isprimes[0]=0 for k in m : div=int(k**0.5) if div*div==k : if isprimes[div-1]: print('YES') else : print('NO') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),input().split()->select(t | true)->collect(t | (("" + ((t)))->toInteger()))} ; var ub : int := ("" + ((((m)->max())->pow(0.5))))->toInteger() + 1 ; var isprimes : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, ub) ; for i : Integer.subrange(2, ub + 1-1) do ( if isprimes[i - 1+1] then ( var j : int := 2 ; while (j * i->compareTo(ub)) <= 0 do ( isprimes[j * i - 1+1] := 0 ; j := j + 1) ) else skip) ; isprimes->first() := 0 ; for k : m do ( var div : int := ("" + (((k)->pow(0.5))))->toInteger() ; if div * div = k then ( if isprimes[div - 1+1] then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(d,K): r=1 for k in range(K,1,-2): if d>=10**k : return 0 t=(-d)% 10 d=abs((d-t*(10**(k-1)-1))//10) r*=10-t-(K==k) return r*(10**(K % 2))if d==0 else 0 D=int(input()) result=0 l=len(str(D)) for k in range(l,2*l+1): result+=solve(D,k) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var D : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var result : int := 0 ; var l : int := (("" + ((D))))->size() ; for k : Integer.subrange(l, 2 * l + 1-1) do ( result := result + solve(D, k)) ; execute (result)->display(); operation solve(d : OclAny, K : OclAny) : OclAny pre: true post: true activity: var r : int := 1 ; for k : Integer.subrange(K, 1-1)->select( $x | ($x - K) mod -2 = 0 ) do ( if (d->compareTo((10)->pow(k))) >= 0 then ( return 0 ) else skip ; var t : int := (-d) mod 10 ; d := ((d - t * ((10)->pow((k - 1)) - 1)) div 10)->abs() ; r := r * 10 - t - (K = k)) ; return if d = 0 then r * ((10)->pow((K mod 2))) else 0 endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=int(input()),[int(t)for t in input().split()] ub=int(max(m)**0.5)+1 isprimes=[1]*ub for i in range(2,ub+1): if isprimes[i-1]: j=2 while j*i<=ub : isprimes[j*i-1]=0 j+=1 isprimes[0]=0 for k in m : div=int(k**0.5) if div*div==k : if isprimes[div-1]: print('YES') else : print('NO') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),input().split()->select(t | true)->collect(t | (("" + ((t)))->toInteger()))} ; var ub : int := ("" + ((((m)->max())->pow(0.5))))->toInteger() + 1 ; var isprimes : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, ub) ; for i : Integer.subrange(2, ub + 1-1) do ( if isprimes[i - 1+1] then ( var j : int := 2 ; while (j * i->compareTo(ub)) <= 0 do ( isprimes[j * i - 1+1] := 0 ; j := j + 1) ) else skip) ; isprimes->first() := 0 ; for k : m do ( var div : int := ("" + (((k)->pow(0.5))))->toInteger() ; if div * div = k then ( if isprimes[div - 1+1] then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def segments(n,p,m): c=dict() c[0]=1 has=False Sum=0 ans=0 for r in range(n): if(p[r]m): Sum+=1 if(p[r]==m): has=True if(has): if(Sum in c.keys()): ans+=c[Sum] if Sum-1 in c.keys(): ans+=c[Sum-1] else : c[Sum]=c.get(Sum,0)+1 return ans a=[2,4,5,3,1] n=len(a) m=4 print(segments(n,a,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : Sequence := Sequence{2}->union(Sequence{4}->union(Sequence{5}->union(Sequence{3}->union(Sequence{ 1 })))) ; n := (a)->size() ; m := 4 ; execute (segments(n, a, m))->display(); operation segments(n : OclAny, p : OclAny, m : OclAny) : OclAny pre: true post: true activity: var c : Map := (arguments ( )) ; c->first() := 1 ; var has : boolean := false ; var Sum : int := 0 ; var ans : int := 0 ; for r : Integer.subrange(0, n-1) do ( if ((p[r+1]->compareTo(m)) < 0) then ( Sum := Sum - 1 ) else (if ((p[r+1]->compareTo(m)) > 0) then ( Sum := Sum + 1 ) else skip) ; if (p[r+1] = m) then ( has := true ) else skip ; if (has) then ( if ((c.keys())->includes(Sum)) then ( ans := ans + c[Sum+1] ) else skip ; if (c.keys())->includes(Sum - 1) then ( ans := ans + c[Sum - 1+1] ) else skip ) else ( c[Sum+1] := c.get(Sum, 0) + 1 )) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import floor n,k=list(map(int,input().split())) lst=list(map(int,input().split())) counts=[0]*k pairs=0 for l in lst : counts[l % k]+=1 pairs+=floor(counts[0]/2) if k % 2==0 : pairs+=floor(counts[k//2]/2) for i in range(1,(k+1)//2): pairs+=min(counts[i],counts[k-i]) print(pairs*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var counts : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, k) ; var pairs : int := 0 ; for l : lst do ( counts[l mod k+1] := counts[l mod k+1] + 1) ; pairs := pairs + floor(counts->first() / 2) ; if k mod 2 = 0 then ( pairs := pairs + floor(counts[k div 2+1] / 2) ) else skip ; for i : Integer.subrange(1, (k + 1) div 2-1) do ( pairs := pairs + Set{counts[i+1], counts[k - i+1]}->min()) ; execute (pairs * 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def produs_cifre(numar): produs=1 for i in numar : produs=produs*int(i) return(produs) pr def functie(nodul,vectorul,cate,culori,vizitat): if vizitat[nodul]==0 : vizitat[nodul]=1 if culori[nodul-1]!=noi_culori[nodul-1]: cate[0]=1+cate[0] noi_culori[nodul-1]=culori[nodul-1] for j in vectorul[nodul]: if vizitat[j]==0 : noi_culori[j-1]=culori[nodul-1] functie(j,vectorul,cate,culori,vizitat) return(sum(cate)) for contor in range(0,1): n,k=list(map(int,input().split())) lista=list(map(int,input().split())) vector=[0]*101 for i in lista : vector[i % k]+=1 answ=2*(vector[0]//2) vector[0]=0 for i in range(1,101): partial=min(vector[i],vector[k-i]) if i!=k-i : answ+=partial*2 else : answ+=(partial//2)*2 vector[i]=0 vector[k-i]=0 print(answ) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; for contor : Integer.subrange(0, 1-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lista : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var vector : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 101) ; for i : lista do ( vector[i mod k+1] := vector[i mod k+1] + 1) ; var answ : int := 2 * (vector->first() div 2) ; vector->first() := 0 ; for i : Integer.subrange(1, 101-1) do ( var partial : OclAny := Set{vector[i+1], vector[k - i+1]}->min() ; if i /= k - i then ( answ := answ + partial * 2 ) else ( answ := answ + (partial div 2) * 2 ) ; vector[i+1] := 0 ; vector[k - i+1] := 0) ; execute (answ)->display()); operation produs_cifre(numar : OclAny) : OclAny pre: true post: true activity: var produs : int := 1 ; for i : numar do ( produs := produs * ("" + ((i)))->toInteger()) ; return (produs) ; ; operation functie(nodul : OclAny, vectorul : OclAny, cate : OclAny, culori : OclAny, vizitat : OclAny) : OclAny pre: true post: true activity: if vizitat[nodul+1] = 0 then ( vizitat[nodul+1] := 1 ; if culori[nodul - 1+1] /= noi_culori[nodul - 1+1] then ( cate->first() := 1 + cate->first() ; noi_culori[nodul - 1+1] := culori[nodul - 1+1] ) else skip ; for j : vectorul[nodul+1] do ( if vizitat[j+1] = 0 then ( noi_culori[j - 1+1] := culori[nodul - 1+1] ; functie(j, vectorul, cate, culori, vizitat) ) else skip) ) else skip ; return ((cate)->sum()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r=lambda : map(int,input().split()) n,k=r() c=[0]*k for x in r(): c[x % k]+=1 print(sum(map(min,zip(c[1 :],c[: :-1])))+(c[0]& ~ 1)-(~ k & c[k//2]& 1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := r->apply() ; var c : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, k) ; for x : r->apply() do ( c[x mod k+1] := c[x mod k+1] + 1) ; execute (((Integer.subrange(1, c->tail()->size())->collect( _indx | Sequence{c->tail()->at(_indx), c(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->at(_indx)} ))->collect( _x | (min)->apply(_x) ))->sum() + (MathLib.bitwiseAnd(c->first(), MathLib.bitwiseNot(1))) - (MathLib.bitwiseAnd(MathLib.bitwiseAnd(MathLib.bitwiseNot(k), c[k div 2+1]), 1)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,m=map(int,input().split()) w=list(map(int,input().split())) d=[0]*m for i in w : d[i % m]+=1 c=d[0]//2*2 i,j=1,m-1 while i<=j : if i!=j : c+=min(d[i],d[j])*2 else : c+=d[i]//2*2 i+=1 j-=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; for i : w do ( d[i mod m+1] := d[i mod m+1] + 1) ; var c : int := d->first() div 2 * 2 ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{1,m - 1} ; while (i->compareTo(j)) <= 0 do ( if i /= j then ( c := c + Set{d[i+1], d[j+1]}->min() * 2 ) else ( c := c + d[i+1] div 2 * 2 ) ; i := i + 1 ; j := j - 1) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) for i in range(n): if a[i]toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( if (a[i+1]->compareTo(b[i+1])) < 0 then ( var a[i+1] : OclAny := null; var b[i+1] : OclAny := null; Sequence{a[i+1],b[i+1]} := Sequence{b[i+1],a[i+1]} ) else skip) ; execute ((a)->max() * (b)->max())->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict n,k=list(map(int,input().split())) lst=list(map(int,input().split())) dct=defaultdict(set) for i in range(n): dct[lst[i]% k].add(i) res=0 num_range=k//2 if k % 2==0 : res+=2*(len(dct[k//2])//2) else : num_range+=1 res+=2*(len(dct[0])//2) for i in range(1,num_range): res+=2*min(len(dct[i]),len(dct[k-i])) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dct : OclAny := defaultdict(OclType["Set"]) ; for i : Integer.subrange(0, n-1) do ((expr (atom (name dct)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) % (expr (atom (name k))))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var res : int := 0 ; var num_range : int := k div 2 ; if k mod 2 = 0 then ( res := res + 2 * ((dct[k div 2+1])->size() div 2) ) else ( num_range := num_range + 1 ) ; res := res + 2 * ((dct->first())->size() div 2) ; for i : Integer.subrange(1, num_range-1) do ( res := res + 2 * Set{(dct[i+1])->size(), (dct[k - i+1])->size()}->min()) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(arr,n): count=0 ; for i in range(n): if(arr[i]& 1): count=count+1 ; if(count & 1): return "Odd" ; else : return "Even" ; if __name__=='__main__' : arr=[3,9,12,13,15] n=len(arr) print(check(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{3}->union(Sequence{9}->union(Sequence{12}->union(Sequence{13}->union(Sequence{ 15 })))) ; n := (arr)->size() ; execute (check(arr, n))->display() ) else skip; operation check(arr : OclAny, n : OclAny) pre: true post: true activity: var count : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (MathLib.bitwiseAnd(arr[i+1], 1)) then ( count := count + 1; ) else skip) ; if (MathLib.bitwiseAnd(count, 1)) then ( return "Odd"; ) else ( return "Even"; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s,n=map(int,input().split()) dragon_strength=[] add_strength=[] for dargon in range(n): a,b=map(int,input().split()) dragon_strength.append(a) add_strength.append(b) while n>0 : defeat_add=[] defeat_i=[] i=0 while i<=n-1 : if dragon_strength[i]collect( _x | (OclType["int"])->apply(_x) ) ; var dragon_strength : Sequence := Sequence{} ; var add_strength : Sequence := Sequence{} ; for dargon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a) : dragon_strength) ; execute ((b) : add_strength)) ; while n > 0 do ( var defeat_add : Sequence := Sequence{} ; var defeat_i : Sequence := Sequence{} ; var i : int := 0 ; while (i->compareTo(n - 1)) <= 0 do ( if (dragon_strength[i+1]->compareTo(s)) < 0 then ( execute ((add_strength[i+1]) : defeat_add) ; execute ((i) : defeat_i) ) else skip ; i := i + 1) ; if (defeat_add)->size() = 0 then ( break ) else ( var aim_add_strength : OclAny := (defeat_add)->max() ; s := s + aim_add_strength ; var aim_i : int := defeat_add->indexOf(aim_add_strength) - 1 ; var x : OclAny := defeat_i[aim_i+1] ; dragon_strength := dragon_strength->excludingAt(x+1) ; add_strength := add_strength->excludingAt(x+1) ; n := n - 1 )) ; if (dragon_strength)->size() = 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline D=int(input()) memo_F=[0]*30 memo_T=[0]*30 for x in range(10): for y in range(10): memo_T[y-x]+=1 if x!=0 : memo_F[y-x]+=1 def F(K,D,allow_leading_zero): if K==0 : return 1 if D==0 else 0 if K==1 : if D!=0 : return 0 if allow_leading_zero : return 10 else : return 9 x=10**(K-1)-1 d=(-D)% 10 ret=0 for use_x in[d,d-10]: if allow_leading_zero : coef=memo_T[use_x] else : coef=memo_F[use_x] if coef==0 : continue ret+=coef*F(K-2,(D-x*use_x)//10,True) return ret answer=sum(F(K,D,False)for K in range(1,20)) print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var D : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var memo_F : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 30) ; var memo_T : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 30) ; for x : Integer.subrange(0, 10-1) do ( for y : Integer.subrange(0, 10-1) do ( memo_T[y - x+1] := memo_T[y - x+1] + 1 ; if x /= 0 then ( memo_F[y - x+1] := memo_F[y - x+1] + 1 ) else skip)) ; skip ; var answer : OclAny := ((argument (test (logical_test (comparison (expr (atom (name F)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name K))))))) , (argument (test (logical_test (comparison (expr (atom (name D))))))) , (argument (test (logical_test (comparison (expr (atom (name False)))))))) ))))))) (comp_for for (exprlist (expr (atom (name K)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 20))))))))) )))))))))->sum() ; execute (answer)->display(); operation F(K : OclAny, D : OclAny, allow_leading_zero : OclAny) : OclAny pre: true post: true activity: if K = 0 then ( return if D = 0 then 1 else 0 endif ) else skip ; if K = 1 then ( if D /= 0 then ( return 0 ) else skip ; if allow_leading_zero then ( return 10 ) else ( return 9 ) ) else skip ; var x : double := (10)->pow((K - 1)) - 1 ; var d : int := (-D) mod 10 ; var ret : int := 0 ; for use_x : Sequence{d}->union(Sequence{ d - 10 }) do ( if allow_leading_zero then ( var coef : OclAny := memo_T[use_x+1] ) else ( coef := memo_F[use_x+1] ) ; if coef = 0 then ( continue ) else skip ; ret := ret + coef * F(K - 2, (D - x * use_x) div 10, true)) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- strength,num_drag=map(int,input().split()) drag_strengths=list() drag_rewards=list() for _ in range(num_drag): drag_strength,drag_reward=map(int,input().split()) drag_strengths.append(drag_strength) drag_rewards.append(drag_reward) drag_strengths,drag_rewards=zip(*sorted(zip(drag_strengths,drag_rewards))) for index in range(len(drag_strengths)): if strength>drag_strengths[index]: strength=int(strength)+drag_rewards[index] else : print("NO") quit() print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var strength : OclAny := null; var num_drag : OclAny := null; Sequence{strength,num_drag} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var drag_strengths : Sequence := () ; var drag_rewards : Sequence := () ; for _anon : Integer.subrange(0, num_drag-1) do ( var drag_strength : OclAny := null; var drag_reward : OclAny := null; Sequence{drag_strength,drag_reward} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((drag_strength) : drag_strengths) ; execute ((drag_reward) : drag_rewards)) ; Sequence{drag_strengths,drag_rewards} := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name drag_strengths))))))) , (argument (test (logical_test (comparison (expr (atom (name drag_rewards)))))))) ))))))))) ))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name drag_strengths))))))) , (argument (test (logical_test (comparison (expr (atom (name drag_rewards)))))))) ))))))))) ))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name drag_strengths))))))) , (argument (test (logical_test (comparison (expr (atom (name drag_rewards)))))))) ))))))))) ))))))))`third->at(_indx)} ) ; for index : Integer.subrange(0, (drag_strengths)->size()-1) do ( if (strength->compareTo(drag_strengths[index+1])) > 0 then ( var strength : int := ("" + ((strength)))->toInteger() + drag_rewards[index+1] ) else ( execute ("NO")->display() ; quit() )) ; execute ("YES")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s,n=map(int,input().split()) def smok(s,n): herostrength=s tab=[] for x in range(n): d=list(map(int,input().split())) tab.append(d) tab.sort() for i in range(len(tab)): if herostrength>int(tab[i][0]): herostrength=herostrength+int(tab[i][1]) if herostrength<=int(tab[i][0]): return('NO') return 'YES' print(smok(s,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := null; var n : OclAny := null; Sequence{s,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; execute (smok(s, n))->display(); operation smok(s : OclAny, n : OclAny) : OclAny pre: true post: true activity: var herostrength : OclAny := s ; var tab : Sequence := Sequence{} ; for x : Integer.subrange(0, n-1) do ( var d : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((d) : tab)) ; tab := tab->sort() ; for i : Integer.subrange(0, (tab)->size()-1) do ( if (herostrength->compareTo(("" + ((tab[i+1]->first())))->toInteger())) > 0 then ( herostrength := herostrength + ("" + ((tab[i+1][1+1])))->toInteger() ) else skip ; if (herostrength->compareTo(("" + ((tab[i+1]->first())))->toInteger())) <= 0 then ( return ('NO') ) else skip) ; return 'YES'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def gameOfDragons(kritioStrength,dragons): sortedDragons=sorted(dragons) for dragonStrength,dragonBonus in sortedDragons : if kritioStrength>dragonStrength : kritioStrength+=dragonBonus else : return "NO" return "YES" kritioStrength,levels=map(int,sys.stdin.readline().split()) dragons=[] for i in range(levels): dragonStrength,dragonBonus=list(map(int,sys.stdin.readline().split())) dragons.append((dragonStrength,dragonBonus)) ans=gameOfDragons(kritioStrength,dragons) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var levels : OclAny := null; Sequence{kritioStrength,levels} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; dragons := Sequence{} ; for i : Integer.subrange(0, levels-1) do ( var dragonStrength : OclAny := null; var dragonBonus : OclAny := null; Sequence{dragonStrength,dragonBonus} := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((Sequence{dragonStrength, dragonBonus}) : dragons)) ; var ans : OclAny := gameOfDragons(kritioStrength, dragons) ; execute (ans)->display(); operation gameOfDragons(kritioStrength : OclAny, dragons : OclAny) : OclAny pre: true post: true activity: var sortedDragons : Sequence := dragons->sort() ; for _tuple : sortedDragons do (var _indx : int := 1; var dragonStrength : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dragonBonus : OclAny := _tuple->at(_indx); if (kritioStrength->compareTo(dragonStrength)) > 0 then ( kritioStrength := kritioStrength + dragonBonus ) else ( return "NO" )) ; return "YES"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def countOrderedPairs(A,n): orderedPairs=0 m=defaultdict(lambda : 0) for i in range(0,n): m[A[i]]+=1 for X,Y in m.items(): for j in range(1,Y+1): if m[j]>=X : orderedPairs+=1 return orderedPairs if __name__=="__main__" : A=[1,1,2,2,3] n=len(A) print(countOrderedPairs(A,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( A := Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 3 })))) ; n := (A)->size() ; execute (countOrderedPairs(A, n))->display() ) else skip; operation countOrderedPairs(A : OclAny, n : OclAny) : OclAny pre: true post: true activity: var orderedPairs : int := 0 ; var m : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; for i : Integer.subrange(0, n-1) do ( m[A[i+1]+1] := m[A[i+1]+1] + 1) ; for _tuple : m->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var X : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Y : OclAny := _tuple->at(_indx); for j : Integer.subrange(1, Y + 1-1) do ( if (m[j+1]->compareTo(X)) >= 0 then ( orderedPairs := orderedPairs + 1 ) else skip)) ; return orderedPairs; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=3 def minimumflip(mat,n): flip=0 for i in range(n): for j in range(i): if mat[i][j]!=mat[j][i]: flip+=1 return flip n=3 mat=[[0,0,1],[1,1,1],[1,0,0]] print(minimumflip(mat,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 3 ; skip ; n := 3 ; mat := Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{ 1 }))}->union(Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))}->union(Sequence{ Sequence{1}->union(Sequence{0}->union(Sequence{ 0 })) })) ; execute (minimumflip(mat, n))->display(); operation minimumflip(mat : OclAny, n : OclAny) : OclAny pre: true post: true activity: var flip : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, i-1) do ( if mat[i+1][j+1] /= mat[j+1][i+1] then ( flip := flip + 1 ) else skip)) ; return flip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- table=[[0 for i in range(2001)]for j in range(2001)] x1,y1,w1,h1=[int(i)for i in input().split()] x2,y2,w2,h2=[int(i)for i in input().split()] ans=0 for i in range(x1,x1+w1): for j in range(y1,y1+h1): table[i][j]=1 ans+=1 for i in range(x2,x2+w2): for j in range(y2,y2+h2): if table[i][j]==0 : table[i][j]=1 ans+=1 else : table[i][j]=0 ans-=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var table : Sequence := Integer.subrange(0, 2001-1)->select(j | true)->collect(j | (Integer.subrange(0, 2001-1)->select(i | true)->collect(i | (0)))) ; var x1 : OclAny := null; var y1 : OclAny := null; var w1 : OclAny := null; var h1 : OclAny := null; Sequence{x1,y1,w1,h1} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var x2 : OclAny := null; var y2 : OclAny := null; var w2 : OclAny := null; var h2 : OclAny := null; Sequence{x2,y2,w2,h2} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : int := 0 ; for i : Integer.subrange(x1, x1 + w1-1) do ( for j : Integer.subrange(y1, y1 + h1-1) do ( table[i+1][j+1] := 1 ; ans := ans + 1)) ; for i : Integer.subrange(x2, x2 + w2-1) do ( for j : Integer.subrange(y2, y2 + h2-1) do ( if table[i+1][j+1] = 0 then ( table[i+1][j+1] := 1 ; ans := ans + 1 ) else ( table[i+1][j+1] := 0 ; ans := ans - 1 ))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_X=2000 MAX_Y=2000 s=[[0 for i in range(MAX_X)]for j in range(MAX_Y)] for _ in range(2): x,y,w,h=map(int,input().split()) for i in range(x,x+w): for j in range(y,y+h): s[i][j]+=1 c=0 for i in range(0,MAX_X): for j in range(0,MAX_Y): if s[i][j]==1 : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_X : int := 2000 ; var MAX_Y : int := 2000 ; var s : Sequence := Integer.subrange(0, MAX_Y-1)->select(j | true)->collect(j | (Integer.subrange(0, MAX_X-1)->select(i | true)->collect(i | (0)))) ; for _anon : Integer.subrange(0, 2-1) do ( var x : OclAny := null; var y : OclAny := null; var w : OclAny := null; var h : OclAny := null; Sequence{x,y,w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(x, x + w-1) do ( for j : Integer.subrange(y, y + h-1) do ( s[i+1][j+1] := s[i+1][j+1] + 1))) ; var c : int := 0 ; for i : Integer.subrange(0, MAX_X-1) do ( for j : Integer.subrange(0, MAX_Y-1) do ( if s[i+1][j+1] = 1 then ( c := c + 1 ) else skip)) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for test in range(t): n,m=map(int,input().split()) mat=[] cnt=1 for i in range(n): s=input() temp=[] for j in range(m): if s[j]=='*' : temp.append(cnt) cnt+=1 else : temp.append(0) mat.append(temp) ans=0 for i in range(n): for j in range(m): spruce=0 for k in range(n): if mat[i][j]!=0 : if j-k>=0 and j+ktoInteger() ; for test : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mat : Sequence := Sequence{} ; var cnt : int := 1 ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var temp : Sequence := Sequence{} ; for j : Integer.subrange(0, m-1) do ( if s[j+1] = '*' then ( execute ((cnt) : temp) ; cnt := cnt + 1 ) else ( execute ((0) : temp) )) ; execute ((temp) : mat)) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( var spruce : int := 0 ; for k : Integer.subrange(0, n-1) do ( if mat[i+1][j+1] /= 0 then ( if j - k >= 0 & (j + k->compareTo(m)) < 0 & (i + k->compareTo(n)) < 0 & mat[i + k+1][j + k+1] - mat[i + k+1][j - k+1] + 1 = (2 * k) + 1 then ( spruce := spruce + 1 ) else ( break ) ) else skip) ; ans := ans + spruce)) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W=map(int,input().split()) h,w=map(int,input().split()) print((H-h)*(W-w)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((H - h) * (W - w))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- List=[list(map(int,input().split()))for i in range(2)] H=List[0][0] W=List[0][1] h=List[1][0] w=List[1][1] white=H*W-h*W-H*w+h*w print(white) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var List : Sequence := Integer.subrange(0, 2-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var H : OclAny := List->first()->first() ; var W : OclAny := List->first()[1+1] ; var h : OclAny := List[1+1]->first() ; var w : OclAny := List[1+1][1+1] ; var white : double := H * W - h * W - H * w + h * w ; execute (white)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def mean(mid,freq,n): sum=0 freqSum=0 for i in range(0,n): sum=sum+mid[i]*freq[i] freqSum=freqSum+freq[i] return sum/freqSum def groupedSD(lower_limit,upper_limit,freq,n): mid=[[0]for i in range(0,n)] sum=0 freqSum=0 sd=0 for i in range(0,n): mid[i]=(lower_limit[i]+upper_limit[i])/2 sum=sum+freq[i]*mid[i]*mid[i] freqSum=freqSum+freq[i] sd=math.sqrt((sum-freqSum*mean(mid,freq,n)*mean(mid,freq,n))/(freqSum-1)) return sd lower_limit=[50,61,71,86,96] upper_limit=[60,70,85,95,100] freq=[9,7,9,12,8] n=len(lower_limit) print(groupedSD(lower_limit,upper_limit,freq,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; lower_limit := Sequence{50}->union(Sequence{61}->union(Sequence{71}->union(Sequence{86}->union(Sequence{ 96 })))) ; upper_limit := Sequence{60}->union(Sequence{70}->union(Sequence{85}->union(Sequence{95}->union(Sequence{ 100 })))) ; freq := Sequence{9}->union(Sequence{7}->union(Sequence{9}->union(Sequence{12}->union(Sequence{ 8 })))) ; n := (lower_limit)->size() ; execute (groupedSD(lower_limit, upper_limit, freq, n))->display(); operation mean(mid : OclAny, freq : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; var freqSum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + mid[i+1] * freq[i+1] ; freqSum := freqSum + freq[i+1]) ; return sum / freqSum; operation groupedSD(lower_limit : OclAny, upper_limit : OclAny, freq : OclAny, n : OclAny) : OclAny pre: true post: true activity: mid := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{ 0 })) ; sum := 0 ; freqSum := 0 ; var sd : int := 0 ; for i : Integer.subrange(0, n-1) do ( mid[i+1] := (lower_limit[i+1] + upper_limit[i+1]) / 2 ; sum := sum + freq[i+1] * mid[i+1] * mid[i+1] ; freqSum := freqSum + freq[i+1]) ; sd := ((sum - freqSum * mean(mid, freq, n) * mean(mid, freq, n)) / (freqSum - 1))->sqrt() ; return sd; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys h,w=map(int,sys.stdin.readline().rstrip().split()) h2,w2=map(int,sys.stdin.readline().rstrip().split()) print((h-h2)*(w-w2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h2 : OclAny := null; var w2 : OclAny := null; Sequence{h2,w2} := (sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((h - h2) * (w - w2))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- HW=list(map(int,input().split())) H=HW[0] W=HW[1] hw=list(map(int,input().split())) h=hw[0] w=hw[1] ans=(H*W)-(h*W)-(H*w)+(h*w) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var HW : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var H : OclAny := HW->first() ; var W : OclAny := HW[1+1] ; var hw : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var h : OclAny := hw->first() ; var w : OclAny := hw[1+1] ; var ans : double := (H * W) - (h * W) - (H * w) + (h * w) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W=map(int,input().split()) h,w=map(int,input().split()) all=H*W print(all-H*w-W*h+h*w) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var all : double := H * W ; execute (all - H * w - W * h + h * w)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def divide(n,m): print("Remainder=",((n)&(m-1))) print("Quotient=",(n>>(int)(math.log2(m)))) n=43 m=8 divide(n,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 43 ; m := 8 ; divide(n, m); operation divide(n : OclAny, m : OclAny) pre: true post: true activity: execute ("Remainder=")->display() ; execute ("Quotient=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from typing import List def minimum_time(n : int,x : List[int],v : List[int])->float : def solve(t,x,v): l=[x[i]-v[i]*t for i in range(len(x))] r=[x[i]+v[i]*t for i in range(len(x))] return 1 if max(l)<=min(r)else 0 l=0 h=10**9 cnt=0 while ltoInteger() ; x := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; v := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (minimum_time(n, x, v))->display(); operation minimum_time(n : int, x : List[OclType["int"]+1], v : List[OclType["int"]+1]) : double pre: true post: true activity: skip ; l := 0 ; var h : double := (10)->pow(9) ; var cnt : int := 0 ; while (l->compareTo(h)) < 0 & cnt < 100 do ( var mid : Sequence := MatrixLib.elementwiseAdd(l, (h - l) / 2) ; cnt := cnt + 1 ; if solve(mid, x, v) then ( h := mid ) else ( l := mid )) ; return l; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=[int(x)for x in input().split()] v=[int(x)for x in input().split()] def rightmost_left_ep(t): return max([x[i]-(v[i]*t)for i in range(n)]) def leftmost_right_ep(t): return min([x[i]+(v[i]*t)for i in range(n)]) def is_feasible(K): return rightmost_left_ep(K)<=leftmost_right_ep(K) L,R=0.0,1e9 while abs(R-L)>1e-6 : mid=(L+R)/2 if(is_feasible(mid)): R=mid else : L=mid print(mid) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var v : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; skip ; skip ; skip ; var L : OclAny := null; var R : OclAny := null; Sequence{L,R} := Sequence{0.0,("1e9")->toReal()} ; while (R - L)->abs() > ("1e-6")->toReal() do ( var mid : double := (L + R) / 2 ; if (is_feasible(mid)) then ( var R : OclAny := mid ) else ( var L : OclAny := mid )) ; execute (mid)->display(); operation rightmost_left_ep(t : OclAny) : OclAny pre: true post: true activity: return (Integer.subrange(0, n-1)->select(i | true)->collect(i | (x[i+1] - (v[i+1] * t))))->max(); operation leftmost_right_ep(t : OclAny) : OclAny pre: true post: true activity: return (Integer.subrange(0, n-1)->select(i | true)->collect(i | (x[i+1] + (v[i+1] * t))))->min(); operation is_feasible(K : OclAny) : OclAny pre: true post: true activity: return (rightmost_left_ep(K)->compareTo(leftmost_right_ep(K))) <= 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=[int(x)for x in input().split()] v=[int(x)for x in input().split()] def rightmost_left_ep(t): return max([x[i]-(v[i]*t)for i in range(n)]) def leftmost_right_ep(t): return min([x[i]+(v[i]*t)for i in range(n)]) def is_feasible(K): return rightmost_left_ep(K)<=leftmost_right_ep(K) L,R=0.0,1e9 while abs(R-L)>1e-6 : mid=(L+R)/2 if(is_feasible(mid)): R=mid else : L=mid print(mid) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var v : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; skip ; skip ; skip ; var L : OclAny := null; var R : OclAny := null; Sequence{L,R} := Sequence{0.0,("1e9")->toReal()} ; while (R - L)->abs() > ("1e-6")->toReal() do ( var mid : double := (L + R) / 2 ; if (is_feasible(mid)) then ( var R : OclAny := mid ) else ( var L : OclAny := mid )) ; execute (mid)->display(); operation rightmost_left_ep(t : OclAny) : OclAny pre: true post: true activity: return (Integer.subrange(0, n-1)->select(i | true)->collect(i | (x[i+1] - (v[i+1] * t))))->max(); operation leftmost_right_ep(t : OclAny) : OclAny pre: true post: true activity: return (Integer.subrange(0, n-1)->select(i | true)->collect(i | (x[i+1] + (v[i+1] * t))))->min(); operation is_feasible(K : OclAny) : OclAny pre: true post: true activity: return (rightmost_left_ep(K)->compareTo(leftmost_right_ep(K))) <= 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) n=int(input()) poss=list(R()) speeds=list(R()) l,r=0,10**9+7 while r-l>10**-6 : mid=(l+r)/2 lb,ub=0,10**18 for i in range(n): lb=max(lb,poss[i]-speeds[i]*mid) ub=min(ub,poss[i]+speeds[i]*mid) if lb<=ub : r=mid else : l=mid print(l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var poss : Sequence := (R->apply())->characters() ; var speeds : Sequence := (R->apply())->characters() ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,(10)->pow(9) + 7} ; while (r - l->compareTo((10)->pow(-6))) > 0 do ( var mid : double := (l + r) / 2 ; var lb : OclAny := null; var ub : OclAny := null; Sequence{lb,ub} := Sequence{0,(10)->pow(18)} ; for i : Integer.subrange(0, n-1) do ( var lb : OclAny := Set{lb, poss[i+1] - speeds[i+1] * mid}->max() ; var ub : OclAny := Set{ub, poss[i+1] + speeds[i+1] * mid}->min()) ; if (lb->compareTo(ub)) <= 0 then ( var r : OclAny := mid ) else ( var l : OclAny := mid )) ; execute (l)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import io,os def input(): return fast_input().decode().rstrip("\n") fast_input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t=int(input()) def find_spruce(i,j): h=1 while(h+i<=n): if((j-h+1<0)or(j+h-1>=m)): break if(dp[i+h-1][j+h]-dp[i+h-1][j-h+1]!=2*(h-1)+1): break h+=1 return h-1 for tc in range(t): n,m=list(map(int,input().split())) mat=[] for i in range(n): mat.append(input()) dp=[[0]for i in range(n)] for i in range(n): for j in range(m): if(j==0): if(mat[i][j]=="*"): dp[i].append(1) else : dp[i].append(0) else : if(mat[i][j]=="*"): dp[i].append(dp[i][j]+1) else : dp[i].append(dp[i][j]) result=0 for i in range(n): for j in range(m): result+=find_spruce(i,j) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var fast_input : OclAny := io.BytesIO(os.readAll()).readline ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; for tc : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mat : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : mat)) ; var dp : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{ 0 })) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if (j = 0) then ( if (mat[i+1][j+1] = "*") then ( (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))) ) else ( (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))) ) ) else ( if (mat[i+1][j+1] = "*") then ( (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))) + (expr (atom (number (integer 1)))))))))) )))) ) else ( (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) )))) ) ))) ; var result : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( result := result + find_spruce(i, j))) ; execute (result)->display()); operation input() : OclAny pre: true post: true activity: return fast_input().decode().rstrip("\n"); operation find_spruce(i : OclAny, j : OclAny) : OclAny pre: true post: true activity: var h : int := 1 ; while ((h + i->compareTo(n)) <= 0) do ( if ((j - h + 1 < 0) or ((j + h - 1->compareTo(m)) >= 0)) then ( break ) else skip ; if (dp[i + h - 1+1][j + h+1] - dp[i + h - 1+1][j - h + 1+1] /= 2 * (h - 1) + 1) then ( break ) else skip ; h := h + 1) ; return h - 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(t,x,v): l=[x[i]-v[i]*t for i in range(len(x))] r=[x[i]+v[i]*t for i in range(len(x))] return 1 if max(l)<=min(r)else 0 n=int(input()) x=list(map(int,input().split())) v=list(map(int,input().split())) l=0 h=10**9 cnt=0 while ltoInteger() ; x := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; v := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := 0 ; var h : double := (10)->pow(9) ; var cnt : int := 0 ; while (l->compareTo(h)) < 0 & cnt < 100 do ( var mid : Sequence := MatrixLib.elementwiseAdd(l, (h - l) / 2) ; cnt := cnt + 1 ; if solve(mid, x, v) then ( h := mid ) else ( l := mid )) ; execute (l)->display(); operation solve(t : OclAny, x : OclAny, v : OclAny) : OclAny pre: true post: true activity: var l : Sequence := Integer.subrange(0, (x)->size()-1)->select(i | true)->collect(i | (x[i+1] - v[i+1] * t)) ; var r : Sequence := Integer.subrange(0, (x)->size()-1)->select(i | true)->collect(i | (x[i+1] + v[i+1] * t)) ; return if ((l)->max()->compareTo((r)->min())) <= 0 then 1 else 0 endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(n,s1,s2): for i in range(n): if(s1[i]!=s2[i]): if(s1[i]=='R' or s2[i]=='R'): return "NO" return "YES" t=int(input()) for i in range(t): n=int(input()) s1=input() s2=input() print(f(n,s1,s2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; s1 := (OclFile["System.in"]).readLine() ; s2 := (OclFile["System.in"]).readLine() ; execute (f(n, s1, s2))->display()); operation f(n : OclAny, s1 : OclAny, s2 : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if (s1[i+1] /= s2[i+1]) then ( if (s1[i+1] = 'R' or s2[i+1] = 'R') then ( return "NO" ) else skip ) else skip) ; return "YES"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def distinct(arr): count=0 if len(arr)==1 : return 1 for i in range(0,len(arr)-1): if(i==0): if(arr[i]!=arr[i+1]): count+=1 elif(i>0 & iunion(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 0 })))))) ; execute (distinct(arr))->display(); operation distinct(arr : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; if (arr)->size() = 1 then ( return 1 ) else skip ; for i : Integer.subrange(0, (arr)->size() - 1-1) do ( if (i = 0) then ( if (arr[i+1] /= arr[i + 1+1]) then ( count := count + 1 ) else skip ) else (if ((i->compareTo(MathLib.bitwiseAnd(0, i))) > 0 & (MathLib.bitwiseAnd(0, i) < (arr)->size() - 1)) then ( if (arr[i+1] /= arr[i + 1+1] or arr[i+1] /= arr[i - 1+1]) then ( count := count + 1 ) else skip ) else skip)) ; if (arr[(arr)->size() - 1+1] /= arr[(arr)->size() - 2+1]) then ( count := count + 1 ) else skip ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxSubArraySumRepeated(a,n,k): max_so_far=-2147483648 max_ending_here=0 for i in range(n*k): max_ending_here=max_ending_here+a[i % n] if(max_so_farunion(Sequence{20}->union(Sequence{-30}->union(Sequence{ -1 }))) ; n := (a)->size() ; k := 3 ; execute ("Maximum contiguous sum is ")->display(); operation maxSubArraySumRepeated(a : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var max_so_far : int := -2147483648 ; var max_ending_here : int := 0 ; for i : Integer.subrange(0, n * k-1) do ( max_ending_here := max_ending_here + a[i mod n+1] ; if ((max_so_far->compareTo(max_ending_here)) < 0) then ( max_so_far := max_ending_here ) else skip ; if (max_ending_here < 0) then ( max_ending_here := 0 ) else skip) ; return max_so_far; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): while b!=0 : r=a % b a,b=b,r return a while True : a,b,c=map(int,input().split()) if a==0 : break d=b**2-4*a*c if d<0 : print("Impossible"); continue d=d**0.5 if not d.is_integer(): print("Impossible"); continue d=int(d) d1,d2,a2=-b+d,-b-d,a<<1 g1,g2=gcd(d1,a2),gcd(d2,a2) p,q=a2//g1,-d1//g1 if p<0 : p,q=-p,-q r,s=a2//g2,-d2//g2 if r<0 : r,s=-r,-s if(pcollect( _x | (OclType["int"])->apply(_x) ) ; if a = 0 then ( break ) else skip ; var d : double := (b)->pow(2) - 4 * a * c ; if d < 0 then ( execute ("Impossible")->display(); continue ) else skip ; d := (d)->pow(0.5) ; if not(d.is_integer()) then ( execute ("Impossible")->display(); continue ) else skip ; d := ("" + ((d)))->toInteger() ; var d1 : OclAny := null; var d2 : OclAny := null; var a2 : OclAny := null; Sequence{d1,d2,a2} := Sequence{-b + d,-b - d,a * (2->pow(1))} ; var g1 : OclAny := null; var g2 : OclAny := null; Sequence{g1,g2} := Sequence{gcd(d1, a2),gcd(d2, a2)} ; var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := Sequence{a2 div g1,-d1 div g1} ; if p < 0 then ( var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := Sequence{-p,-q} ) else skip ; var s : OclAny := null; Sequence{r,s} := Sequence{a2 div g2,-d2 div g2} ; if r < 0 then ( var s : OclAny := null; Sequence{r,s} := Sequence{-r,-s} ) else skip ; if ((p->compareTo(r)) < 0) or (p = r & (q->compareTo(s)) < 0) then ( var p : OclAny := null; var q : OclAny := null; var s : OclAny := null; Sequence{p,q,r,s} := Sequence{r,s,p,q} ) else skip ; execute (p)->display()); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: while b /= 0 do ( var r : int := a mod b ; Sequence{a,b} := Sequence{b,r}) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import fractions while True : a,b,c=map(int,input().split()) if not a : break d=(b**2-4*a*c)**0.5 if isinstance(d,complex)or d-int(d)>1e-6 : print('Impossible') continue num1,num2=-b+int(d),-b-int(d) den=2*a cmn1,cmn2=fractions.gcd(num1,den),fractions.gcd(num2,den) p,q,r,s=den//cmn1,-num1//cmn1,den//cmn2,-num2//cmn2 if(p,q)<(r,s): p,q,r,s=r,s,p,q print(p,q,r,s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if not(a) then ( break ) else skip ; var d : double := (((b)->pow(2) - 4 * a * c))->pow(0.5) ; if (complex).isInstance(d) or d - ("" + ((d)))->toInteger() > ("1e-6")->toReal() then ( execute ('Impossible')->display() ; continue ) else skip ; var num1 : OclAny := null; var num2 : OclAny := null; Sequence{num1,num2} := Sequence{-b + ("" + ((d)))->toInteger(),-b - ("" + ((d)))->toInteger()} ; var den : double := 2 * a ; var cmn1 : OclAny := null; var cmn2 : OclAny := null; Sequence{cmn1,cmn2} := Sequence{fractions.gcd(num1, den),fractions.gcd(num2, den)} ; var p : OclAny := null; var q : OclAny := null; var r : OclAny := null; var s : OclAny := null; Sequence{p,q,r,s} := Sequence{den div cmn1,-num1 div cmn1,den div cmn2,-num2 div cmn2} ; if (Sequence{p, q}->compareTo(Sequence{r, s})) < 0 then ( var p : OclAny := null; var q : OclAny := null; var r : OclAny := null; var s : OclAny := null; Sequence{p,q,r,s} := Sequence{r,s,p,q} ) else skip ; execute (p)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math def gcd(a,b): if a0 : print("Impossible") return aa=1 p=2*a q=b-rd if q==0 : p=1 else : d=gcd(p,q) p/=d q/=d r=2*a s=(b+rd) if s==0 : r=1 else : d=gcd(r,s) r/=d s/=d if p<0 : p,q=-p,-q if r<0 : r,s=-r,-s if pcollect( _x | (OclType["int"])->apply(_x) ) ; if a = 0 & b = 0 & c = 0 then ( break ) else skip ; factor(a, b, c)); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a->compareTo(b)) < 0 then ( Sequence{a,b} := Sequence{b,a} ) else skip ; var r : OclAny := b ; while r /= 0 do ( r := a mod b ; if r = 0 then ( return b ) else skip ; Sequence{a,b} := Sequence{b,r}); operation factor(a : OclAny, b : OclAny, c : OclAny) pre: true post: true activity: var disc : double := b * b - 4 * a * c ; if disc < 0 then ( execute ("Impossible")->display() ; return ) else skip ; var rd : double := (disc)->sqrt() ; if rd - (rd)->floor() > 0 then ( execute ("Impossible")->display() ; return ) else skip ; var aa : int := 1 ; var p : double := 2 * a ; var q : double := b - rd ; if q = 0 then ( p := 1 ) else ( var d : OclAny := gcd(p, q) ; p := p / d ; q := q / d ) ; r := 2 * a ; var s : OclAny := (b + rd) ; if s = 0 then ( r := 1 ) else ( d := gcd(r, s) ; r := r / d ; s := s / d ) ; if p < 0 then ( Sequence{p,q} := Sequence{-p,-q} ) else skip ; if r < 0 then ( Sequence{r,s} := Sequence{-r,-s} ) else skip ; if (p->compareTo(r)) < 0 or (p = r & (q->compareTo(s)) < 0) then ( Sequence{p,q,r,s} := Sequence{r,s,p,q} ) else skip ; execute (StringLib.format("%d %d %d %d",Sequence{p, q, r, s}))->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def SubArraySum(arr,n): result=0 for i in range(0,n): result+=(arr[i]*(i+1)*(n-i)) return result arr=[1,2,3] n=len(arr) print("Sum of SubArray : ",SubArraySum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; n := (arr)->size() ; execute ("Sum of SubArray : ")->display(); operation SubArraySum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; for i : Integer.subrange(0, n-1) do ( result := result + (arr[i+1] * (i + 1) * (n - i))) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def SubArraySum(arr,n): temp,result=0,0 for i in range(0,n): temp=0 ; for j in range(i,n): temp+=arr[j] result+=temp return result arr=[1,2,3] n=len(arr) print("Sum of SubArray :",SubArraySum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; n := (arr)->size() ; execute ("Sum of SubArray :")->display(); operation SubArraySum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var temp : OclAny := null; var result : OclAny := null; Sequence{temp,result} := Sequence{0,0} ; for i : Integer.subrange(0, n-1) do ( var temp : int := 0; ; for j : Integer.subrange(i, n-1) do ( temp := temp + arr[j+1] ; result := result + temp)) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxOnesIndex(arr,n): start=0 end=0 maxIndex=-1 lastInd=-1 maxCnt=0 while(endunion(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })))))))))))) ; n := (arr)->size() ; execute ("Index of 0 to be replaced is ")->display() ) else skip; operation maxOnesIndex(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var start : int := 0 ; var end : int := 0 ; var maxIndex : int := -1 ; var lastInd : int := -1 ; var maxCnt : int := 0 ; while ((end->compareTo(n)) < 0) do ( while ((end->compareTo(n)) < 0 & arr[end+1]) do ( end := end + 1) ; if ((maxCnt->compareTo(end - start)) < 0 & lastInd /= -1) then ( maxCnt := end - start ; maxIndex := lastInd ) else skip ; start := lastInd + 1 ; lastInd := end ; end := end + 1) ; if ((maxCnt->compareTo(end - start)) < 0 & lastInd /= -1) then ( maxCnt := end - start ; maxIndex := lastInd ) else skip ; return maxIndex; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while(t>0): c=0 n=int(input()) li=list(map(int,input().split())) l=li.count(0) if(l>0): print(len(li)-l) elif(len(li)!=len(set(li))): print(len(li)) else : print(len(li)+1) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (t > 0) do ( var c : int := 0 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : int := li->count(0) ; if (l > 0) then ( execute ((li)->size() - l)->display() ) else (if ((li)->size() /= (Set{}->union((li)))->size()) then ( execute ((li)->size())->display() ) else ( execute ((li)->size() + 1)->display() ) ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findTheSpruce(matrix): total=0 dp=[[0]*len(matrix[0])for _ in range(len(matrix))] for col in range(len(matrix[0])): dp[-1][col]=1 if matrix[-1][col]=='*' else 0 total+=dp[-1][col] for row in range(len(matrix)-2,-1,-1): for col in range(len(matrix[0])): if matrix[row][col]=='*' : minimum=dp[row+1][col] if col==0 : minimum=0 else : minimum=min(minimum,dp[row+1][col-1]) if col==len(matrix[0])-1 : minimum=0 else : minimum=min(minimum,dp[row+1][col+1]) dp[row][col]=1+minimum total+=dp[row][col] return total testcases=int(input().strip()) for _ in range(testcases): n,m=map(int,input().strip().split()) matrix=[] for i in range(n): matrix.append(input().strip()) print(findTheSpruce(matrix)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var testcases : int := ("" + ((input()->trim())))->toInteger() ; for _anon : Integer.subrange(0, testcases-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; matrix := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((input()->trim()) : matrix)) ; execute (findTheSpruce(matrix))->display()); operation findTheSpruce(matrix : OclAny) : OclAny pre: true post: true activity: var total : int := 0 ; var dp : Sequence := Integer.subrange(0, (matrix)->size()-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (matrix->first())->size()))) ; for col : Integer.subrange(0, (matrix->first())->size()-1) do ( dp->last()[col+1] := if matrix->last()[col+1] = '*' then 1 else 0 endif ; total := total + dp->last()[col+1]) ; for row : Integer.subrange(-1 + 1, (matrix)->size() - 2)->reverse() do ( for col : Integer.subrange(0, (matrix->first())->size()-1) do ( if matrix[row+1][col+1] = '*' then ( var minimum : OclAny := dp[row + 1+1][col+1] ; if col = 0 then ( minimum := 0 ) else ( minimum := Set{minimum, dp[row + 1+1][col - 1+1]}->min() ) ; if col = (matrix->first())->size() - 1 then ( minimum := 0 ) else ( minimum := Set{minimum, dp[row + 1+1][col + 1+1]}->min() ) ; dp[row+1][col+1] := 1 + minimum ; total := total + dp[row+1][col+1] ) else skip)) ; return total; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if a==0 : return b return gcd(b % a,a) a=2 b=4 print(gcd(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 2 ; b := 4 ; execute (gcd(a, b))->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a = 0 then ( return b ) else skip ; return gcd(b mod a, a); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) arr=[int(_)for _ in input().split()] arr.sort() flag=0 zero=0 for i in range(len(arr)-1): if arr[i]==0 : zero+=1 if arr[i]==arr[i+1]: flag=1 if arr[-1]==0 : zero+=1 if flag or zero : print(len(arr)-zero) else : print(len(arr)+1-zero) t=int(input()) for i in range(t): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( solve()); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; arr := arr->sort() ; var flag : int := 0 ; var zero : int := 0 ; for i : Integer.subrange(0, (arr)->size() - 1-1) do ( if arr[i+1] = 0 then ( zero := zero + 1 ) else skip ; if arr[i+1] = arr[i + 1+1] then ( flag := 1 ) else skip) ; if arr->last() = 0 then ( zero := zero + 1 ) else skip ; if flag or zero then ( execute ((arr)->size() - zero)->display() ) else ( execute ((arr)->size() + 1 - zero)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,s,n0=int(input()),set(),0 x=list(map(int,input().split()))[: n] for i in x : s.add(i) if(i==0): n0+=1 print(n-n0 if n0>0 else(n if len(s)toInteger()-1) do ( var n : OclAny := null; var s : OclAny := null; var n0 : OclAny := null; Sequence{n,s,n0} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),Set{}->union(()),0} ; var x : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ; for i : x do ( execute ((i) : s) ; if (i = 0) then ( n0 := n0 + 1 ) else skip) ; execute (if n0 > 0 then n - n0 else (if ((s)->size()->compareTo(n)) < 0 then n else n + 1 endif) endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter from sys import stdin input=stdin.buffer.readline def func(): if 0 in a : print(sum(1 if x!=0 else 0 for x in a)) else : freq=Counter(a) if max(freq.values())==1 : print(sum(1 if x!=0 else 0 for x in a)+1) else : print(sum(1 if x!=0 else 0 for x in a)) for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) func() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.buffer.readline ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; func()); operation func() pre: true post: true activity: if (a)->includes(0) then ( execute (((argument (test (logical_test (comparison (expr (atom (number (integer 1)))))) if (logical_test (comparison (comparison (expr (atom (name x)))) != (comparison (expr (atom (number (integer 0))))))) else (test (logical_test (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a))))))))->sum())->display() ) else ( var freq : OclAny := Counter(a) ; if (freq.values())->max() = 1 then ( execute (((argument (test (logical_test (comparison (expr (atom (number (integer 1)))))) if (logical_test (comparison (comparison (expr (atom (name x)))) != (comparison (expr (atom (number (integer 0))))))) else (test (logical_test (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a))))))))->sum() + 1)->display() ) else ( execute (((argument (test (logical_test (comparison (expr (atom (number (integer 1)))))) if (logical_test (comparison (comparison (expr (atom (name x)))) != (comparison (expr (atom (number (integer 0))))))) else (test (logical_test (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a))))))))->sum())->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.buffer.readline def func(): print(n-a.count(0)if 0 in a else n if len(set(a))toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; func()); operation func() pre: true post: true activity: execute (if (a)->includes(0) then n - a->count(0) else if ((Set{}->union((a)))->size()->compareTo(n)) < 0 then n else n + 1 endif endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=32 ; def toggleCase(a): for i in range(len(a)): a=a[: i]+chr(ord(a[i])^ 32)+a[i+1 :]; return a ; str="CheRrY" ; print("Toggle case: ",end=""); str=toggleCase(str); print(str); print("Original string: ",end=""); str=toggleCase(str); print(str); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 32; ; skip ; var OclType["String"] : String := "CheRrY"; ; execute ("Toggle case: ")->display(); ; OclType["String"] := toggleCase(OclType["String"]); ; execute (OclType["String"])->display(); ; execute ("Original string: ")->display(); ; OclType["String"] := toggleCase(OclType["String"]); ; execute (OclType["String"])->display();; operation toggleCase(a : OclAny) pre: true post: true activity: for i : Integer.subrange(0, (a)->size()-1) do ( a := a.subrange(1,i) + (MathLib.bitwiseXor((a[i+1])->char2byte(), 32))->byte2char() + a.subrange(i + 1+1);) ; return a;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printArray(arr,n): for i in range(n): print(arr[i],end=" ") def generateArr(arr,n): if(n==0): return if(n==1): print(arr[0]) return suffixMax=[0]*n suffixMax[n-1]=arr[n-1] for i in range(n-2,-1,-1): suffixMax[i]=max(arr[i],suffixMax[i+1]) minSoFar=arr[0] arr[0]=suffixMax[1] for i in range(1,n-1): temp=arr[i] arr[i]=abs(suffixMax[i+1]-minSoFar) minSoFar=min(minSoFar,temp) arr[n-1]=minSoFar printArray(arr,n) if __name__=="__main__" : arr=[1,5,2,4,3] n=len(arr) generateArr(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{5}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 3 })))) ; n := (arr)->size() ; generateArr(arr, n) ) else skip; operation printArray(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); operation generateArr(arr : OclAny, n : OclAny) pre: true post: true activity: if (n = 0) then ( return ) else skip ; if (n = 1) then ( execute (arr->first())->display() ; return ) else skip ; var suffixMax : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; suffixMax[n - 1+1] := arr[n - 1+1] ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( suffixMax[i+1] := Set{arr[i+1], suffixMax[i + 1+1]}->max()) ; var minSoFar : OclAny := arr->first() ; arr->first() := suffixMax[1+1] ; for i : Integer.subrange(1, n - 1-1) do ( var temp : OclAny := arr[i+1] ; arr[i+1] := (suffixMax[i + 1+1] - minSoFar)->abs() ; minSoFar := Set{minSoFar, temp}->min()) ; arr[n - 1+1] := minSoFar ; printArray(arr, n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np def prCharWithFreq(str): n=len(str) freq=np.zeros(26,dtype=np.int) for i in range(0,n): freq[ord(str[i])-ord('a')]+=1 for i in range(0,n): if(freq[ord(str[i])-ord('a')]!=0): print(str[i],freq[ord(str[i])-ord('a')],end=" ") freq[ord(str[i])-ord('a')]=0 if __name__=="__main__" : str="geeksforgeeks" ; prCharWithFreq(str); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( OclType["String"] := "geeksforgeeks"; ; prCharWithFreq(OclType["String"]); ) else skip; operation prCharWithFreq(OclType["String"] : OclAny) pre: true post: true activity: var n : int := (OclType["String"])->size() ; var freq : Sequence := MatrixLib.singleValueMatrix(26, 0.0) ; for i : Integer.subrange(0, n-1) do ( freq[(("" + ([i+1])))->char2byte() - ('a')->char2byte()+1] := freq[(("" + ([i+1])))->char2byte() - ('a')->char2byte()+1] + 1) ; for i : Integer.subrange(0, n-1) do ( if (freq[(("" + ([i+1])))->char2byte() - ('a')->char2byte()+1] /= 0) then ( execute (("" + ([i+1])))->display() ; freq[(("" + ([i+1])))->char2byte() - ('a')->char2byte()+1] := 0 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) r=[] for i in range(t): n=int(input()) a=list(map(int,input().split())) b=[] for j in range(len(a)-1): c=abs(a[j]-a[j+1]) if c>1 : b.append(j+1) b.append(j+2) break if len(b)==0 : r.append("NO") else : r.append("YES") r.append(' '.join(map(str,b))) for i in range(len(r)): print(r[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := Sequence{} ; for j : Integer.subrange(0, (a)->size() - 1-1) do ( var c : double := (a[j+1] - a[j + 1+1])->abs() ; if c > 1 then ( execute ((j + 1) : b) ; execute ((j + 2) : b) ; break ) else skip) ; if (b)->size() = 0 then ( execute (("NO") : r) ) else ( execute (("YES") : r) ; execute ((StringLib.sumStringsWithSeparator(((b)->collect( _x | (OclType["String"])->apply(_x) )), ' ')) : r) )) ; for i : Integer.subrange(0, (r)->size()-1) do ( execute (r[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a=int(input()) b=list(map(int,input().split())) c=0 for i in range(a-1): if abs(b[i]-b[i+1])>=2 : c=1 break if c==1 : print("YES") print(i+1,i+2) else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; for i : Integer.subrange(0, a - 1-1) do ( if (b[i+1] - b[i + 1+1])->abs() >= 2 then ( c := 1 ; break ) else skip) ; if c = 1 then ( execute ("YES")->display() ; execute (i + 1)->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) flag=0 x,y=0,0 for i in range(1,n): if max(l[i],l[i-1])-min(l[i],l[i-1])>=2 : x,y=i,i+1 flag=i break if flag : print("YES") print(x,y) continue print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var flag : int := 0 ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{0,0} ; for i : Integer.subrange(1, n-1) do ( if Set{l[i+1], l[i - 1+1]}->max() - Set{l[i+1], l[i - 1+1]}->min() >= 2 then ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{i,i + 1} ; flag := i ; break ) else skip) ; if flag then ( execute ("YES")->display() ; execute (x)->display() ; continue ) else skip ; execute ("NO")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rectanglearea(a,b): if a<0 or b<0 : return-1 return 2*a*b if __name__=="__main__" : a,b=10,8 print(rectanglearea(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{a,b} := Sequence{10,8} ; execute (rectanglearea(a, b))->display() ) else skip; operation rectanglearea(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a < 0 or b < 0 then ( return -1 ) else skip ; return 2 * a * b; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n,m=map(int,input().split()) a=[] for i in range(n): a.append(input()) dp=[] for i in range(n): dp.append([]) for j in range(m): dp[i].append((1 if a[i][j]=='*' else 0)if j==0 else dp[i][j-1]+(1 if a[i][j]=='*' else 0)) answer=0 for x in range(n): for y in range(m): if a[x][y]=='.' : continue for level in range(min(n-x,m-y,y+1)): if dp[x+level][y+level]-(0 if y-level-1<0 else dp[x+level][y-level-1])!=level*2+1 : break answer+=1 print(answer) tests=int(input()) while(tests>0): solve() tests=tests-1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var tests : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (tests > 0) do ( solve() ; tests := tests - 1); operation solve() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : a)) ; var dp : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((Sequence{}) : dp) ; for j : Integer.subrange(0, m-1) do ((expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1)))))) if (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) == (comparison (expr (atom '*'))))) else (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))))) if (logical_test (comparison (comparison (expr (atom (name j)))) == (comparison (expr (atom (number (integer 0))))))) else (test (logical_test (comparison (expr (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name j))) - (expr (atom (number (integer 1)))))))))) ]))) + (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1)))))) if (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) == (comparison (expr (atom '*'))))) else (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))))))))) )))))) ; var answer : int := 0 ; for x : Integer.subrange(0, n-1) do ( for y : Integer.subrange(0, m-1) do ( if a[x+1][y+1] = '.' then ( continue ) else skip ; for level : Integer.subrange(0, Set{n - x, m - y, y + 1}->min()-1) do ( if dp[x + level+1][y + level+1] - (if y - level - 1 < 0 then 0 else dp[x + level+1][y - level - 1+1] endif) /= level * 2 + 1 then ( break ) else skip ; answer := answer + 1))) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) for i in range(n-1): if(abs(a[i+1]-a[i])>=2): print('YES') print(i+1,i+2) break else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))) - (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))) ))))) >= (comparison (expr (atom (number (integer 2))))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 2)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=list(map(int,input().split(" "))) out="NO" for i in range(n-1): if abs(a[i]-a[i+1])>=2 : out="YES" break print(out) if out=="YES" : print(f"{i+1}{i+2}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var out : String := "NO" ; for i : Integer.subrange(0, n - 1-1) do ( if (a[i+1] - a[i + 1+1])->abs() >= 2 then ( out := "YES" ; break ) else skip) ; execute (out)->display() ; if out = "YES" then ( execute (StringLib.formattedString("{i+1}{i+2}"))->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): ans=factorial_suffix(10**12) return str(ans) def factorial_suffix(n): twos=count_factors(n,2)-count_factors(n,5) if twos>=2505 : twos=(twos-5)% 2500+5 return factorialish(n)*pow(2,twos,100000)% 100000 def factorialish(n): return even_factorialish(n)*odd_factorialish(n)% 100000 def even_factorialish(n): if n==0 : return 1 else : return factorialish(n//2) def odd_factorialish(n): if n==0 : return 1 else : return odd_factorialish(n//5)*factorial_coprime(n)% 100000 def factorial_coprime(n): n %=100000 product=1 for i in range(1,n+1): if i % 2!=0 and i % 5!=0 : product=i*product % 100000 return product def count_factors(end,n): if end==0 : return 0 else : return end//n+count_factors(end//n,n) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : OclAny := factorial_suffix((10)->pow(12)) ; return ("" + ((ans))); operation factorial_suffix(n : OclAny) : OclAny pre: true post: true activity: var twos : double := count_factors(n, 2) - count_factors(n, 5) ; if twos >= 2505 then ( twos := (twos - 5) mod 2500 + 5 ) else skip ; return factorialish(n) * (2)->pow(twos) mod 100000; operation factorialish(n : OclAny) : OclAny pre: true post: true activity: return even_factorialish(n) * odd_factorialish(n) mod 100000; operation even_factorialish(n : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( return 1 ) else ( return factorialish(n div 2) ); operation odd_factorialish(n : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( return 1 ) else ( return odd_factorialish(n div 5) * factorial_coprime(n) mod 100000 ); operation factorial_coprime(n : OclAny) : OclAny pre: true post: true activity: n := n mod 100000 ; var product : int := 1 ; for i : Integer.subrange(1, n + 1-1) do ( if i mod 2 /= 0 & i mod 5 /= 0 then ( product := i * product mod 100000 ) else skip) ; return product; operation count_factors(end : OclAny, n : OclAny) : OclAny pre: true post: true activity: if end = 0 then ( return 0 ) else ( return end div n + count_factors(end div n, n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=list(input()) vowels=['a','e','i','o','u','y'] i=0 while i+1toInteger() ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var vowels : Sequence := Sequence{'a'}->union(Sequence{'e'}->union(Sequence{'i'}->union(Sequence{'o'}->union(Sequence{'u'}->union(Sequence{ 'y' }))))) ; var i : int := 0 ; while (i + 1->compareTo((s)->size())) < 0 do ( if ((vowels)->includes(s[i+1])) & ((vowels)->includes(s[i + 1+1])) then ( execute (s[i + 1+1])->isDeleted() ) else ( i := i + 1 )) ; execute (StringLib.sumStringsWithSeparator((s), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- vowels=['a','e','i','o','u','y'] n=int(input()) s=input() s1="" last="" for i in range(0,n): if s[i]in vowels : if last in vowels : continue else : s1+=s[i] last=s[i] else : s1+=s[i] last=s[i] print(s1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var vowels : Sequence := Sequence{'a'}->union(Sequence{'e'}->union(Sequence{'i'}->union(Sequence{'o'}->union(Sequence{'u'}->union(Sequence{ 'y' }))))) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var s1 : String := "" ; var last : String := "" ; for i : Integer.subrange(0, n-1) do ( if (vowels)->includes(s[i+1]) then ( if (vowels)->includes(last) then ( continue ) else ( s1 := s1 + s[i+1] ; last := s[i+1] ) ) else ( s1 := s1 + s[i+1] ; last := s[i+1] )) ; execute (s1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re input() print(re.sub('([aeiouy])[aeiouy]+','\\1',input())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; input() ; execute (((OclFile["System.in"]).readLine()).replaceAllMatches('([aeiouy])[aeiouy]+', '\\1'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def _input(): return map(int,input().split()) vowels=['a','e','i','o','u','y'] n=int(input()) s=input() i=0 while iunion(Sequence{'e'}->union(Sequence{'i'}->union(Sequence{'o'}->union(Sequence{'u'}->union(Sequence{ 'y' }))))) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( if (vowels)->excludes(s[i+1]) then ( execute (s[i+1])->display() ) else ( execute (s[i+1])->display() ; while (i->compareTo(n)) < 0 & (vowels)->includes(s[i+1]) do ( i := i + 1) ; i := i - 1 ) ; i := i + 1); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=int(input()) ch=input() l=["a","e","i","o","u","y"] ch1="" i=0 while(itoInteger() ; var ch : String := (OclFile["System.in"]).readLine() ; var l : Sequence := Sequence{"a"}->union(Sequence{"e"}->union(Sequence{"i"}->union(Sequence{"o"}->union(Sequence{"u"}->union(Sequence{ "y" }))))) ; var ch1 : String := "" ; var i : int := 0 ; while ((i->compareTo(s)) < 0) do ( if (l)->includes(ch[i+1]) then ( ch1 := ch1 + ch[i+1] ; var j : int := i + 1 ; while (((j->compareTo(s)) < 0) & ((l)->includes(ch[j+1]))) do ( j := j + 1) ; i := j ) else ( ch1 := ch1 + ch[i+1] ; i := i + 1 )) ; execute (ch1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys class RangeUpdateQuery : def __init__(self,n,initial=2**31-1): self.n=1<<(n-1).bit_length() self.INT=(-1,initial) self.segtree=[self.INT]*(2*self.n) def update(self,l,r,v): L,R=l+self.n,r+self.n while L>=1 R>>=1 def query(self,i): i+=self.n s=self.INT while i>0 : s=max(s,self.segtree[i]) i=i//2 return s[1] N,Q=map(int,input().split()) RUQ=RangeUpdateQuery(N) for q in range(Q): query=list(map(int,sys.stdin.readline().split())) if query[0]==0 : s,t,x=query[1 :] RUQ.update(s,t+1,(q,x)) if query[0]==1 : i=query[1] print(RUQ.query(i)) ------------------------------------------------------------ OCL File: --------- class RangeUpdateQuery { static operation newRangeUpdateQuery() : RangeUpdateQuery pre: true post: RangeUpdateQuery->exists( _x | result = _x ); attribute n : int := 1 * (2->pow((n - 1).bit_length())); attribute INT : OclAny := Sequence{-1, initial}; attribute segtree : Sequence := MatrixLib.elementwiseMult(Sequence{ self.INT }, (2 * self.n)); operation initialise(n : OclAny,initial : OclAny) : RangeUpdateQuery pre: true post: true activity: self.n := 1 * (2->pow((n - 1).bit_length())) ; self.INT := Sequence{-1, initial} ; self.segtree := MatrixLib.elementwiseMult(Sequence{ self.INT }, (2 * self.n)); return self; operation update(l : OclAny,r : OclAny,v : OclAny) pre: true post: true activity: var L : OclAny := null; var R : OclAny := null; Sequence{L,R} := Sequence{l + self.n,r + self.n} ; while (L->compareTo(R)) < 0 do ( if MathLib.bitwiseAnd(L, 1) then ( self.segtree[L+1] := v ; L := L + 1 ) else skip ; if MathLib.bitwiseAnd(R, 1) then ( self.segtree[R - 1+1] := v ; R := R - 1 ) else skip ; L := L div (2->pow(1)) ; R := R div (2->pow(1))); operation query(i : OclAny) : OclAny pre: true post: true activity: i := i + self.n ; var s : OclAny := self.INT ; while i > 0 do ( s := Set{s, self.segtree[i+1]}->max() ; i := i div 2) ; return s[1+1]; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := null; var Q : OclAny := null; Sequence{N,Q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var RUQ : RangeUpdateQuery := (RangeUpdateQuery.newRangeUpdateQuery()).initialise(N) ; for q : Integer.subrange(0, Q-1) do ( var query : Sequence := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if query->first() = 0 then ( var t : OclAny := null; var x : OclAny := null; Sequence{s,t,x} := query->tail() ; execute ((s, t + 1, Sequence{q, x}) <: RUQ) ) else skip ; if query->first() = 1 then ( i := query[1+1] ; execute (RUQ.query(i))->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : t-=1 n,l,r=map(int,input().split()) k=n//l if r*k>=n : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( t := t - 1 ; var n : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{n,l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : int := n div l ; if (r * k->compareTo(n)) >= 0 then ( execute ('Yes')->display() ) else ( execute ('No')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=(-1,2**31-1) line=input() n,q=list(map(int,line.split())) N=1 while N=N-1 : break return z[1] def update(s,t,x,k,l,r): if r<=s or t<=l : return elif s<=l and r<=t : a[k]=x return m=(l+r)//2 update(s,t,x,k*2+1,l,m) update(s,t,x,k*2+2,m,r) return for t in range(0,q): line=input() qu=list(map(int,line.split())) if qu[0]==0 : update(qu[1],qu[2]+1,(t,qu[3]),0,0,N) elif qu[0]==1 : ans=find(qu[1],0,0,N) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INF : OclAny := Sequence{-1, (2)->pow(31) - 1} ; var line : String := (OclFile["System.in"]).readLine() ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := ((line.split())->collect( _x | (OclType["int"])->apply(_x) )) ; var N : int := 1 ; while (N->compareTo(n + 1)) < 0 do ( N := N * 2) ; var a : Sequence := Integer.subrange(0, 2 * N - 1-1)->select(_anon | true)->collect(_anon | (INF)) ; skip ; skip ; for t : Integer.subrange(0, q-1) do ( line := (OclFile["System.in"]).readLine() ; var qu : Sequence := ((line.split())->collect( _x | (OclType["int"])->apply(_x) )) ; if qu->first() = 0 then ( update(qu[1+1], qu[2+1] + 1, Sequence{t, qu[3+1]}, 0, 0, N) ) else (if qu->first() = 1 then ( var ans : OclAny := find(qu[1+1], 0, 0, N) ; execute (ans)->display() ) else skip)); operation find(i : OclAny, k : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var z : OclAny := a->first() ; while true do ( var m : int := (l + r) div 2 ; if (i->compareTo(m)) < 0 then ( k := k * 2 + 1 ; r := m ) else ( k := k * 2 + 2 ; l := m ) ; z := Set{z, a[k+1]}->max() ; if (k->compareTo(N - 1)) >= 0 then ( break ) else skip) ; return z[1+1]; operation update(s : OclAny, t : OclAny, x : OclAny, k : OclAny, l : OclAny, r : OclAny) pre: true post: true activity: if (r->compareTo(s)) <= 0 or (t->compareTo(l)) <= 0 then ( return ) else (if (s->compareTo(l)) <= 0 & (r->compareTo(t)) <= 0 then ( a[k+1] := x ; return ) else skip) ; m := (l + r) div 2 ; update(s, t, x, k * 2 + 1, l, m) ; update(s, t, x, k * 2 + 2, m, r) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSubSeq(arr,n,sum): for i in range(n-1,-1,-1): if(sumunion(Sequence{25}->union(Sequence{46}->union(Sequence{94}->union(Sequence{201}->union(Sequence{ 400 }))))); ; n := (arr)->size(); ; sum := 272; ; findSubSeq(arr, n, sum); ) else skip; operation findSubSeq(arr : OclAny, n : OclAny, sum : OclAny) pre: true post: true activity: for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if ((sum->compareTo(arr[i+1])) < 0) then ( arr[i+1] := -1; ) else ( sum := sum - arr[i+1]; )) ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] /= -1) then ( execute (arr[i+1])->display(); ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class SegmentTree(): def __init__(self,n): self.update_cnt=0 self.n=n self.size=1 INF=2**31-1 while self.size0 : i=(i-1)//2 val=max(val,self.node[i]) return val[1] n,q=map(int,input().split()) info=[list(map(int,input().split()))for i in range(q)] st=SegmentTree(n) for i in range(q): if info[i][0]==0 : s,t,val=info[i][1],info[i][2],info[i][3] st.update(s,t+1,val) else : s=info[i][1] print(st.get_val(info[i][1])) ------------------------------------------------------------ OCL File: --------- class SegmentTree { static operation newSegmentTree() : SegmentTree pre: true post: SegmentTree->exists( _x | result = _x ); attribute update_cnt : int := 0; attribute n : OclAny := n; attribute size : int := 1; attribute node : Sequence := Integer.subrange(0, 2 * self.size - 1-1)->select(i | true)->collect(i | (Sequence{self.update_cnt}->union(Sequence{ INF }))); operation initialise(n : OclAny) : pre: true post: true activity: self.update_cnt := 0 ; self.n := n ; self.size := 1 ; var INF : double := (2)->pow(31) - 1 ; while (self.size->compareTo(n)) < 0 do ( self.size := self.size * 2) ; self.node := Integer.subrange(0, 2 * self.size - 1-1)->select(i | true)->collect(i | (Sequence{self.update_cnt}->union(Sequence{ INF }))); return self; operation update(begin : OclAny,end : OclAny,val : OclAny) pre: true post: true activity: self.update_cnt := self.update_cnt + 1 ; begin := begin + (self.size - 1) ; end := end + (self.size - 1) ; while (begin->compareTo(end)) < 0 do ( if MathLib.bitwiseAnd((end - 1), 1) then ( end := end - 1 ; self.node[end+1] := Sequence{self.update_cnt}->union(Sequence{ val }) ) else skip ; if MathLib.bitwiseAnd((begin - 1), 1) then ( self.node[begin+1] := Sequence{self.update_cnt}->union(Sequence{ val }) ; begin := begin + 1 ) else skip ; begin := (begin - 1) div 2 ; end := (end - 1) div 2); operation get_val(i : OclAny) : OclAny pre: true post: true activity: i := i + (self.size - 1) ; val := self.node[i+1] ; while i > 0 do ( i := (i - 1) div 2 ; val := Set{val, self.node[i+1]}->max()) ; return val[1+1]; } class FromPython { operation initialise() pre: true post: true activity: skip ; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var info : Sequence := Integer.subrange(0, q-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var st : SegmentTree := (SegmentTree.newSegmentTree()).initialise(n) ; for i : Integer.subrange(0, q-1) do ( if info[i+1]->first() = 0 then ( var s : OclAny := null; var t : OclAny := null; Sequence{s,t,val} := Sequence{info[i+1][1+1],info[i+1][2+1],info[i+1][3+1]} ; execute ((s, t + 1, val) <: st) ) else ( var s : OclAny := info[i+1][1+1] ; execute (st.get_val(info[i+1][1+1]))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys INF=2**31-1 class RUQ : def __init__(self,n): tmp=1 while tmp=0 : self.A[k]=x return if self.A[k]!=INF : self.A[k*2+1]=self.A[k*2+2]=self.A[k] self.A[k]=INF self.update(a,b,x,k*2+1,l,(l+r)/2) self.update(a,b,x,k*2+2,(l+r)/2,r) line=sys.stdin.readline() n,q=map(int,line.split()) ruq=RUQ(n) for i in range(q): line=sys.stdin.readline() if line[0]=="0" : com,s,t,x=map(int,line.split()) ruq.update(s,t+1,x,0,0,ruq.n) else : com,i=map(int,line.split()) ruq.update(i,i+1,-1,0,0,ruq.n) print(ruq.A[i+ruq.n-1]) ------------------------------------------------------------ OCL File: --------- class RUQ { static operation newRUQ() : RUQ pre: true post: RUQ->exists( _x | result = _x ); attribute n : int := tmp * 2; attribute A : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, (2 * self.n - 1)); operation initialise(n : OclAny) : RUQ pre: true post: true activity: var tmp : int := 1 ; while (tmp->compareTo(n)) < 0 do ( tmp := tmp * 2) ; self.n := tmp * 2 ; self.A := MatrixLib.elementwiseMult(Sequence{ INF }, (2 * self.n - 1)); return self; operation update(a : OclAny,b : OclAny,x : int,k : int,l : int,r : int) pre: true post: true activity: if (r->compareTo(a)) <= 0 or (b->compareTo(l)) <= 0 then ( return ) else skip ; if (a->compareTo(l)) <= 0 & (r->compareTo(b)) <= 0 then ( if x >= 0 then ( self.A[k+1] := x ) else skip ; return ) else skip ; if self.A[k+1] /= INF then ( self.A[k * 2 + 1+1] := self.A[k+1]; var self.A[k * 2 + 2+1] : OclAny := self.A[k+1] ) else skip ; self.A[k+1] := INF ; execute ((a, b, x, k * 2 + 1, l, (l + r) / 2) <: self) ; execute ((a, b, x, k * 2 + 2, (l + r) / 2, r) <: self); } class FromPython { operation initialise() pre: true post: true activity: skip ; var INF : double := (2)->pow(31) - 1 ; skip ; var line : String := (OclFile["System.in"]).readLine() ; var q : OclAny := null; Sequence{n,q} := (line.split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ruq : RUQ := (RUQ.newRUQ()).initialise(n) ; for i : Integer.subrange(0, q-1) do ( line := (OclFile["System.in"]).readLine() ; if line->first() = "0" then ( var com : OclAny := null; var s : OclAny := null; var t : OclAny := null; Sequence{com,s,t,x} := (line.split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((s, t + 1, x, 0, 0, ruq.n) <: ruq) ) else ( var com : OclAny := null; var i : OclAny := null; Sequence{com,i} := (line.split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((i, i + 1, -1, 0, 0, ruq.n) <: ruq) ; execute (ruq.A[i + ruq.n - 1+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class SegmentTree : n=0 node=[] def __init__(self,sz): self.n=1 while self.n=0 : self.node[k]=x return if self.node[k]!=INF : self.node[k*2+1]=self.node[k*2+2]=self.node[k] self.node[k]=INF self.update(a,b,x,2*k+1,l,(l+r)//2) self.update(a,b,x,2*k+2,(l+r)//2,r) INF=2**31-1 sz,q=map(int,input().split()) ruq=SegmentTree(sz) for _ in range(q): c,*l=map(int,input().split()) if c : ruq.update(l[0],l[0]+1) print(ruq.node[l[0]+ruq.n-1]) else : s,t,x=l ruq.update(s,t+1,x) ------------------------------------------------------------ OCL File: --------- class SegmentTree { static operation newSegmentTree() : SegmentTree pre: true post: SegmentTree->exists( _x | result = _x ); static attribute n : int := 0; static attribute node : Sequence := Sequence{}; attribute n : int := 1; attribute node : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, (2 * self.n - 1)); operation initialise(sz : OclAny) : SegmentTree pre: true post: true activity: self.n := 1 ; while (self.n->compareTo(sz)) < 0 do ( self.n := self.n * 2) ; self.node := MatrixLib.elementwiseMult(Sequence{ INF }, (2 * self.n - 1)); return self; operation update(a : OclAny,b : OclAny,x : int,k : int,l : int,r : int) pre: true post: true activity: if r < 0 then ( r := self.n ) else skip ; if (r->compareTo(a)) <= 0 or (b->compareTo(l)) <= 0 then ( return ) else skip ; if (a->compareTo(l)) <= 0 & (r->compareTo(b)) <= 0 then ( if x >= 0 then ( self.node[k+1] := x ) else skip ; return ) else skip ; if self.node[k+1] /= INF then ( self.node[k * 2 + 1+1] := self.node[k+1]; var self.node[k * 2 + 2+1] : OclAny := self.node[k+1] ) else skip ; self.node[k+1] := INF ; execute ((a, b, x, 2 * k + 1, l, (l + r) div 2) <: self) ; execute ((a, b, x, 2 * k + 2, (l + r) div 2, r) <: self); } class FromPython { operation initialise() pre: true post: true activity: skip ; var INF : double := (2)->pow(31) - 1 ; var q : OclAny := null; Sequence{sz,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ruq : SegmentTree := (SegmentTree.newSegmentTree()).initialise(sz) ; for _anon : Integer.subrange(0, q-1) do ( var c : OclAny := null; var l : OclAny := null; Sequence{c,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if c then ( execute ((l->first(), l->first() + 1) <: ruq) ; execute (ruq.node[l->first() + ruq.n - 1+1])->display() ) else ( var s : OclAny := null; var t : OclAny := null; Sequence{s,t,x} := l ; execute ((s, t + 1, x) <: ruq) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkSame(n): set,unset=0,0 while(n): if(n and 1): set+1 else : unset+=1 n=n>>1 if(set==unset): return True else : return False if __name__=='__main__' : n=12 if(checkSame(n)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 12 ; if (checkSame(n)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; operation checkSame(n : OclAny) : OclAny pre: true post: true activity: var OclType["Set"] : OclAny := null; var unset : OclAny := null; Sequence{OclType["Set"],unset} := Sequence{0,0} ; while (n) do ( if (n & 1) then ( (expr (expr (atom (name set))) + (expr (atom (number (integer 1))))) ) else ( unset := unset + 1 ) ; n := n /(2->pow(1))) ; if (OclType["Set"] = unset) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CountPair(L,R): x=(R-L+1) print(x//2) if __name__=='__main__' : L,R=1,8 CountPair(L,R) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( Sequence{L,R} := Sequence{1,8} ; CountPair(L, R) ) else skip; operation CountPair(L : OclAny, R : OclAny) pre: true post: true activity: var x : double := (R - L + 1) ; execute (x div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=1000000007 ; def number_of_ways(arr,n,k): if(k==1): return 1 ; dp=[-1]*(k+1); for i in range(n): dp[arr[i]]=0 ; dp[0]=1 ; dp[1]=1 if(dp[1]==-1)else dp[1]; for i in range(2,k+1): if(dp[i]==0): continue ; dp[i]=dp[i-1]+dp[i-2]; dp[i]%=MOD ; return dp[k]; if __name__=="__main__" : arr=[3]; n=len(arr); k=6 ; print(number_of_ways(arr,n,k)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : int := 1000000007; ; skip ; if __name__ = "__main__" then ( arr := Sequence{ 3 }; ; n := (arr)->size(); ; k := 6; ; execute (number_of_ways(arr, n, k))->display(); ) else skip; operation number_of_ways(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: if (k = 1) then ( return 1; ) else skip ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (k + 1)); ; for i : Integer.subrange(0, n-1) do ( dp[arr[i+1]+1] := 0;) ; dp->first() := 1; ; dp[1+1] := if (dp[1+1] = -1) then 1 else dp[1+1] endif; ; for i : Integer.subrange(2, k + 1-1) do ( if (dp[i+1] = 0) then ( continue; ) else skip ; dp[i+1] := dp[i - 1+1] + dp[i - 2+1]; ; dp[i+1] := dp[i+1] mod MOD;) ; return dp[k+1];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): data=input() d_set=set() for i in range(len(data)-1): str1=data[0 : i+1] str2=data[i+1 : len(data)] d_set.add(str1+str2) d_set.add(str1+str2[: :-1]) d_set.add(str1[: :-1]+str2) d_set.add(str1[: :-1]+str2[: :-1]) d_set.add(str2+str1) d_set.add(str2+str1[: :-1]) d_set.add(str2[: :-1]+str1) d_set.add(str2[: :-1]+str1[: :-1]) print(len(d_set)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var data : String := (OclFile["System.in"]).readLine() ; var d_set : Set := Set{}->union(()) ; for i : Integer.subrange(0, (data)->size() - 1-1) do ( var str1 : OclAny := data.subrange(0+1, i + 1) ; var str2 : OclAny := data.subrange(i + 1+1, (data)->size()) ; execute ((str1 + str2) : d_set) ; execute ((str1 + str2(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) : d_set) ; execute ((str1(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) + str2) : d_set) ; execute ((str1(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) + str2(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) : d_set) ; execute ((str2 + str1) : d_set) ; execute ((str2 + str1(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) : d_set) ; execute ((str2(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) + str1) : d_set) ; execute ((str2(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) + str1(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) : d_set)) ; execute ((d_set)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- arr_train=[] m=input() m=int(m) while(True): if m==0 : break x=input() arr_train=str(x) counter=0 all_list=[] left=len(arr_train)-1 right=1 while(True): blkA_train=None blkB_train=None blkA_train=arr_train[0 : left] blkB_train=arr_train[left : len(arr_train)-1+left] all_list.append(blkA_train+blkB_train) all_list.append(blkA_train[: :-1]+blkB_train) all_list.append(blkB_train+blkA_train) all_list.append(blkB_train[: :-1]+blkA_train) all_list.append(blkA_train[: :-1]+blkB_train[: :-1]) all_list.append(blkB_train[: :-1]+blkA_train[: :-1]) all_list.append(blkA_train+blkB_train[: :-1]) all_list.append(blkB_train+blkA_train[: :-1]) if left==1 : break left-=1 all_list=set(all_list) all_list=list(all_list) print(len(all_list)) m-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var arr_train : Sequence := Sequence{} ; var m : String := (OclFile["System.in"]).readLine() ; m := ("" + ((m)))->toInteger() ; while (true) do ( if m = 0 then ( break ) else skip ; var x : String := (OclFile["System.in"]).readLine() ; arr_train := ("" + ((x))) ; var counter : int := 0 ; var all_list : Sequence := Sequence{} ; var left : double := (arr_train)->size() - 1 ; var right : int := 1 ; while (true) do ( var blkA_train : OclAny := null ; var blkB_train : OclAny := null ; blkA_train := arr_train.subrange(0+1, left) ; blkB_train := arr_train.subrange(left+1, (arr_train)->size() - 1 + left) ; execute ((blkA_train + blkB_train) : all_list) ; execute ((blkA_train(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) + blkB_train) : all_list) ; execute ((blkB_train + blkA_train) : all_list) ; execute ((blkB_train(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) + blkA_train) : all_list) ; execute ((blkA_train(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) + blkB_train(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) : all_list) ; execute ((blkB_train(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) + blkA_train(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) : all_list) ; execute ((blkA_train + blkB_train(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) : all_list) ; execute ((blkB_train + blkA_train(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) : all_list) ; if left = 1 then ( break ) else skip ; left := left - 1) ; all_list := Set{}->union((all_list)) ; all_list := (all_list) ; execute ((all_list)->size())->display() ; m := m - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=map(int,input().split()) p=[2 for i in range(n+1)] t=map(int,input().split()) t2=map(int,input().split()) for i in t : p[i]=1 for i in range(1,n+1): print(p[i],end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (2)) ; var t : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t2 : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : t do ( p[i+1] := 1) ; for i : Integer.subrange(1, n + 1-1) do ( execute (p[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,l,r=map(int,input().split()) if n % l<=(n//l)*(r-l): print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{n,l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (n mod l->compareTo((n div l) * (r - l))) <= 0 then ( execute ('Yes')->display() ) else ( execute ('No')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): num=int(input()) for i in range(num): t=list(input()) tlist=[] for j in range(len(t)-1): j+=1 k=len(t)-j a=t[: j] b=t[-k :] arev=[] brev=[] for i in range(len(a)): j=len(a)-i-1 arev.append(a[j]) for i in range(len(b)): j=len(b)-i-1 brev.append(b[j]) app(tlist,a+b) app(tlist,a+brev) app(tlist,arev+b) app(tlist,arev+brev) app(tlist,b+a) app(tlist,b+arev) app(tlist,brev+a) app(tlist,brev+arev) print(len(tlist)) def app(tlist,new): for item in tlist : if item==new : return tlist.append(new) return main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, num-1) do ( var t : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var tlist : Sequence := Sequence{} ; for j : Integer.subrange(0, (t)->size() - 1-1) do ( j := j + 1 ; var k : double := (t)->size() - j ; var a : OclAny := t.subrange(1,j) ; var b : OclAny := t.subrange(-k+1) ; var arev : Sequence := Sequence{} ; var brev : Sequence := Sequence{} ; for i : Integer.subrange(0, (a)->size()-1) do ( var j : double := (a)->size() - i - 1 ; execute ((a[j+1]) : arev)) ; for i : Integer.subrange(0, (b)->size()-1) do ( j := (b)->size() - i - 1 ; execute ((b[j+1]) : brev)) ; app(tlist, a + b) ; app(tlist, a->union(brev)) ; app(tlist, arev->union(b)) ; app(tlist, arev->union(brev)) ; app(tlist, b + a) ; app(tlist, b->union(arev)) ; app(tlist, brev->union(a)) ; app(tlist, brev->union(arev))) ; execute ((tlist)->size())->display()); operation app(tlist : OclAny, new : OclAny) pre: true post: true activity: for item : tlist do ( if item = new then ( return ) else skip) ; execute ((new) : tlist) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reconst(n): former=train[: n] latter=train[n :] formerRe="".join(reversed(former)) latterRe="".join(reversed(latter)) return[former+latterRe,formerRe+latter,formerRe+latterRe,latter+former,latterRe+former,latter+formerRe,latterRe+formerRe] n=int(input()) for _ in range(n): s=set() train=input() s.add(train) leng=len(train) for i in range(1,leng): for t in reconst(i): if not t in s : s.add(t) print(len(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var s : Set := Set{}->union(()) ; var train : String := (OclFile["System.in"]).readLine() ; execute ((train) : s) ; var leng : int := (train)->size() ; for i : Integer.subrange(1, leng-1) do ( for t : reconst(i) do ( if not((s)->includes(t)) then ( execute ((t) : s) ) else skip)) ; execute ((s)->size())->display()); operation reconst(n : OclAny) : OclAny pre: true post: true activity: var former : OclAny := train.subrange(1,n) ; var latter : OclAny := train.subrange(n+1) ; var formerRe : String := StringLib.sumStringsWithSeparator(((former)->reverse()), "") ; var latterRe : String := StringLib.sumStringsWithSeparator(((latter)->reverse()), "") ; return Sequence{former + latterRe}->union(Sequence{formerRe + latter}->union(Sequence{formerRe + latterRe}->union(Sequence{latter + former}->union(Sequence{latterRe + former}->union(Sequence{latter + formerRe}->union(Sequence{ latterRe + formerRe })))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,k=map(int,input().split()) m=2*k+1 x=[[]for _ in range(m)] for i in range(1,n+1): x[i % m].append(i) l=n+1 for y in x : if not y or l<=len(y): continue if y[0]-k<=1 and n<=y[-1]+k : l,ans=len(y),y print(l) sys.stdout.write(" ".join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : double := 2 * k + 1 ; var x : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(1, n + 1-1) do ((expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) % (expr (atom (name m))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var l : OclAny := n + 1 ; for y : x do ( if not(y) or (l->compareTo((y)->size())) <= 0 then ( continue ) else skip ; if y->first() - k <= 1 & (n->compareTo(y->last() + k)) <= 0 then ( var ans : OclAny := null; Sequence{l,ans} := Sequence{(y)->size(),y} ) else skip) ; execute (l)->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " ") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) for i in range(num): def count_pattern(prefix,suffix): answer.add(prefix+suffix) answer.add(prefix[: :-1]+suffix) answer.add(prefix+suffix[: :-1]) answer.add(prefix[: :-1]+suffix[: :-1]) answer.add(suffix+prefix) answer.add(suffix[: :-1]+prefix) answer.add(suffix+prefix[: :-1]) answer.add(suffix[: :-1]+prefix[: :-1]) target=input() answer=set() for j in range(1,len(target)): target_prefix=target[: j] target_suffix=target[j :] count_pattern(target_prefix,target_suffix) print(len(answer)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, num-1) do ( skip ; var target : String := (OclFile["System.in"]).readLine() ; var answer : Set := Set{}->union(()) ; for j : Integer.subrange(1, (target)->size()-1) do ( var target_prefix : OclAny := target.subrange(1,j) ; var target_suffix : OclAny := target.subrange(j+1) ; count_pattern(target_prefix, target_suffix)) ; execute ((answer)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getTotalNumberOfSequences(m,n): if mdisplay() ) else skip; operation getTotalNumberOfSequences(m : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (m->compareTo(n)) < 0 then ( return 0 ) else skip ; if n = 0 then ( return 1 ) else skip ; var res : OclAny := (getTotalNumberOfSequences(m - 1, n) + getTotalNumberOfSequences(m div 2, n - 1)) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printKMax(a,n,k): if(k==1): for i in range(n): print(a[i],end=" "); return ; p=0 ; q=k-1 ; t=p ; max=a[k-1]; while(q<=n-1): if(a[p]>max): max=a[p]; p+=1 ; if(q==p and p!=n): print(max,end=" "); q+=1 ; p=t+1 ; if(qunion(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{ 10 }))))))))); ; n := (a)->size(); ; var K : int := 3; ; printKMax(a, n, K); ) else skip; operation printKMax(a : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (k = 1) then ( for i : Integer.subrange(0, n-1) do ( execute (a[i+1])->display();) ; return; ) else skip ; var p : int := 0; ; var q : double := k - 1; ; var t : int := p; ; var max : OclAny := a[k - 1+1]; ; while ((q->compareTo(n - 1)) <= 0) do ( if ((a[p+1]->compareTo(max)) > 0) then ( max := a[p+1]; ) else skip ; p := p + 1; ; if (q = p & p /= n) then ( execute (max)->display(); ; q := q + 1; ; p := t + 1; ; if ((q->compareTo(n)) < 0) then ( max := a[q+1]; ) else skip ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b,c=map(int,input().split()) if(a+c)%(2*b)==0 or((2*b-c)>0 and(2*b-c)% a==0)or(((2*b-a)>0 and(2*b-a)% c==0)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a + c) mod (2 * b) = 0 or ((2 * b - c) > 0 & (2 * b - c) mod a = 0) or (((2 * b - a) > 0 & (2 * b - a) mod c = 0)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) i=1 while True : if i>t : break a,b,c=input().split() a=int(a) b=int(b) c=int(c) if 2*b==a+c : print("Yes") elif 2*ba and c>b : if(2*b-c)% a==0 : print("Yes") else : print("No") elif a>c and a>b : if(2*b-a)% c==0 : print("Yes") else : print("No") elif a<=b and c<=b : if(2*b-c)% a==0 or(2*b-a)% c==0 : print("Yes") else : print("No") i=i+1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 1 ; while true do ( if (i->compareTo(t)) > 0 then ( break ) else skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := input().split() ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; var c : int := ("" + ((c)))->toInteger() ; if 2 * b = a + c then ( execute ("Yes")->display() ) else (if (2 * b->compareTo(a + c)) < 0 then ( if (a + c) mod (2 * b) = 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else ( if (c->compareTo(a)) > 0 & (c->compareTo(b)) > 0 then ( if (2 * b - c) mod a = 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else (if (a->compareTo(c)) > 0 & (a->compareTo(b)) > 0 then ( if (2 * b - a) mod c = 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else (if (a->compareTo(b)) <= 0 & (c->compareTo(b)) <= 0 then ( if (2 * b - c) mod a = 0 or (2 * b - a) mod c = 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip ) ) ) ) ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) i=1 while True : if i>t : break a,b,c=input().split() a=int(a) b=int(b) c=int(c) while True : if(2*b-c)% a==0 and(2*b-c)/a>0 : print("Yes") break elif((a+c)/2)% b==0 and((a+c)/2)/b>0 : print("Yes") break elif(2*b-a)% c==0 and(2*b-a)/c>0 : print("Yes") break else : print("No") break i=i+1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 1 ; while true do ( if (i->compareTo(t)) > 0 then ( break ) else skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := input().split() ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; var c : int := ("" + ((c)))->toInteger() ; while true do ( if (2 * b - c) mod a = 0 & (2 * b - c) / a > 0 then ( execute ("Yes")->display() ; break ) else (if ((a + c) / 2) mod b = 0 & ((a + c) / 2) / b > 0 then ( execute ("Yes")->display() ; break ) else (if (2 * b - a) mod c = 0 & (2 * b - a) / c > 0 then ( execute ("Yes")->display() ; break ) else ( execute ("No")->display() ; break ) ) ) ) ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def alt(a,b,c): if(2*b-c)% a==0 and(2*b-c)>=a : return True if(2*b-a)% c==0 and(2*b-a)>=c : return True if(a-(a-c)/2)% b==0 and(a-(a-c)/2)>=b : return True t=int(input()) for i in range(1,t+1): a,b,c=(int(s)for s in input().split(" ")) if alt(a,b,c): print("yes") else : print("no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(1, t + 1-1) do ( Sequence{a,b,c} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " "))))))) ))))))))} ; if alt(a, b, c) then ( execute ("yes")->display() ) else ( execute ("no")->display() )); operation alt(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: if (2 * b - c) mod a = 0 & ((2 * b - c)->compareTo(a)) >= 0 then ( return true ) else skip ; if (2 * b - a) mod c = 0 & ((2 * b - a)->compareTo(c)) >= 0 then ( return true ) else skip ; if (a - (a - c) / 2) mod b = 0 & ((a - (a - c) / 2)->compareTo(b)) >= 0 then ( return true ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def possible(numbers): return int(numbers[0])//int(numbers[1])!=0 and int(numbers[0])% int(numbers[1])//(int(numbers[0])//int(numbers[1]))<=int(numbers[2])-int(numbers[1])and int(numbers[0])% int(numbers[1])% int(numbers[0])//int(numbers[1])+int(numbers[0])% int(numbers[1])%(int(numbers[0])//int(numbers[1]))<=(int(numbers[2])-int(numbers[1]))*(int(numbers[0])//int(numbers[1])-int(numbers[0])//int(numbers[2])) for i in range(0,int(input())): print('Yes' if possible(input().split(' '))else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (if possible(input().split(' ')) then 'Yes' else 'No' endif)->display()); operation possible(numbers : OclAny) : OclAny pre: true post: true activity: return ("" + ((numbers->first())))->toInteger() div ("" + ((numbers[1+1])))->toInteger() /= 0 & (("" + ((numbers->first())))->toInteger() mod ("" + ((numbers[1+1])))->toInteger() div (("" + ((numbers->first())))->toInteger() div ("" + ((numbers[1+1])))->toInteger())->compareTo(("" + ((numbers[2+1])))->toInteger() - ("" + ((numbers[1+1])))->toInteger())) <= 0 & (("" + ((numbers->first())))->toInteger() mod ("" + ((numbers[1+1])))->toInteger() mod ("" + ((numbers->first())))->toInteger() div ("" + ((numbers[1+1])))->toInteger() + ("" + ((numbers->first())))->toInteger() mod ("" + ((numbers[1+1])))->toInteger() mod (("" + ((numbers->first())))->toInteger() div ("" + ((numbers[1+1])))->toInteger())->compareTo((("" + ((numbers[2+1])))->toInteger() - ("" + ((numbers[1+1])))->toInteger()) * (("" + ((numbers->first())))->toInteger() div ("" + ((numbers[1+1])))->toInteger() - ("" + ((numbers->first())))->toInteger() div ("" + ((numbers[2+1])))->toInteger()))) <= 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): a,b,c=map(int,input().split()) if((c-b==b-a)or(a-b==b-c)): return "YES" if(c>=b): d=c-b t_a=b-d if(t_a>a and t_a % a==0): return "YES" if(b>=c): d=b-c t_a=b+d if(t_a>a and t_a % a==0): return "YES" if(a>=b): d=a-b t_c=b-d if(t_c>c and t_c % c==0): return "YES" if(b>=a): d=b-a t_c=b+d if(t_c>c and t_c % c==0): return "YES" t_b=(a+c)//2 if(t_b % b==0): b=t_b if((c-b==b-a)or(a-b==b-c)): return "YES" return "NO" for i in range(int(input())): print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (solve())->display()); operation solve() : OclAny pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if ((c - b = b - a) or (a - b = b - c)) then ( return "YES" ) else skip ; if ((c->compareTo(b)) >= 0) then ( var d : double := c - b ; var t_a : double := b - d ; if ((t_a->compareTo(a)) > 0 & t_a mod a = 0) then ( return "YES" ) else skip ) else skip ; if ((b->compareTo(c)) >= 0) then ( d := b - c ; t_a := b + d ; if ((t_a->compareTo(a)) > 0 & t_a mod a = 0) then ( return "YES" ) else skip ) else skip ; if ((a->compareTo(b)) >= 0) then ( d := a - b ; var t_c : double := b - d ; if ((t_c->compareTo(c)) > 0 & t_c mod c = 0) then ( return "YES" ) else skip ) else skip ; if ((b->compareTo(a)) >= 0) then ( d := b - a ; t_c := b + d ; if ((t_c->compareTo(c)) > 0 & t_c mod c = 0) then ( return "YES" ) else skip ) else skip ; var t_b : int := (a + c) div 2 ; if (t_b mod b = 0) then ( var b : int := t_b ; if ((c - b = b - a) or (a - b = b - c)) then ( return "YES" ) else skip ) else skip ; return "NO"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findLongestPalindrome(strr): count=[0]*256 for i in range(len(strr)): count[ord(strr[i])]+=1 beg="" mid="" end="" ch=ord('a') while ch<=ord('z'): if(count[ch]& 1): mid=ch count[ch]-=1 ch-=1 else : for i in range(count[ch]//2): beg+=chr(ch) ch+=1 end=beg end=end[: :-1] return beg+chr(mid)+end strr="abbaccd" print(findLongestPalindrome(strr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; strr := "abbaccd" ; execute (findLongestPalindrome(strr))->display(); operation findLongestPalindrome(strr : OclAny) : OclAny pre: true post: true activity: var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 256) ; for i : Integer.subrange(0, (strr)->size()-1) do ( count[(strr[i+1])->char2byte()+1] := count[(strr[i+1])->char2byte()+1] + 1) ; var beg : String := "" ; var mid : String := "" ; var end : String := "" ; var ch : int := ('a')->char2byte() ; while (ch->compareTo(('z')->char2byte())) <= 0 do ( if (MathLib.bitwiseAnd(count[ch+1], 1)) then ( mid := ch ; count[ch+1] := count[ch+1] - 1 ; ch := ch - 1 ) else ( for i : Integer.subrange(0, count[ch+1] div 2-1) do ( beg := beg + (ch)->byte2char()) ) ; ch := ch + 1) ; end := beg ; end := end(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; return beg + (mid)->byte2char() + end; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : n=int(input()) A=input().split() n2=int(input()) for i in range(n2): a,b=map(int,input().split()) B=list(reversed(A[a : b])) A=A[0 : a]+B+A[b : n] print(*A) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : OclAny := input().split() ; var n2 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n2-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var B : Sequence := ((A.subrange(a+1, b))->reverse()) ; A := A.subrange(0+1, a)->union(B) + A.subrange(b+1, n)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name A))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) minAns=float('inf') ans=[] jump=2*k+1 if n<=k : print(1) print(n) else : for i in range(0,k+1): temp=0 tempAns=[] flag=1 while i=n-1 : temp+=1 tempAns.append(i+1) break elif i+2*k>=n-1 : flag=0 break tempAns.append(i+1) i+=jump temp+=1 if flag : if tempcollect( _x | (OclType["int"])->apply(_x) ) ; var minAns : double := ("" + (('inf')))->toReal() ; var ans : Sequence := Sequence{} ; var jump : double := 2 * k + 1 ; if (n->compareTo(k)) <= 0 then ( execute (1)->display() ; execute (n)->display() ) else ( for i : Integer.subrange(0, k + 1-1) do ( var temp : int := 0 ; var tempAns : Sequence := Sequence{} ; var flag : int := 1 ; while (i->compareTo(n)) < 0 do ( if (i + k->compareTo(n - 1)) >= 0 then ( temp := temp + 1 ; execute ((i + 1) : tempAns) ; break ) else (if (i + 2 * k->compareTo(n - 1)) >= 0 then ( flag := 0 ; break ) else skip) ; execute ((i + 1) : tempAns) ; i := i + jump ; temp := temp + 1) ; if flag then ( if (temp->compareTo(minAns)) < 0 then ( minAns := temp ; ans := tempAns ) else skip ) else skip) ; execute (minAns)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def my_reverse(ary,b,e): while bcompareTo(e - 1)) < 0 do ( var temp : OclAny := ary[b+1] ; ary[b+1] := ary[e - 1+1] ; ary[e - 1+1] := temp ; b := b + 1 ; e := e - 1) ; return ary; operation main() pre: true post: true activity: input() ; ary := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( Sequence{b,e} := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; ary := my_reverse(ary, b, e)) ; execute (StringLib.sumStringsWithSeparator((ary->select(x | true)->collect(x | (("" + ((x)))))), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() listnum=list(map(int,input().split())) for i in range(int(input())): eachq=list(map(int,input().split())) newlist=listnum[eachq[0]: eachq[1]] newlist.reverse() listnum=listnum[: eachq[0]]+newlist+listnum[eachq[1]:] print(" ".join(map(str,listnum))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var listnum : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var eachq : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var newlist : OclAny := listnum.subrange(eachq->first()+1, eachq[1+1]) ; newlist := newlist->reverse() ; listnum := listnum.subrange(1,eachq->first()) + newlist + listnum.subrange(eachq[1+1]+1)) ; execute (StringLib.sumStringsWithSeparator(((listnum)->collect( _x | (OclType["String"])->apply(_x) )), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin n=int(stdin.readline()) l=list(stdin.readline().split()) q=int(stdin.readline()) for i in range(q): inp_l=list(map(int,stdin.readline().split())) j=inp_l[0] k=inp_l[1]-1 while True : if j>=k : break l[j],l[k]=l[k],l[j] k-=1 j+=1 print(' '.join(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + ((stdin.readLine())))->toInteger() ; var l : Sequence := (stdin.readLine().split()) ; var q : int := ("" + ((stdin.readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( var inp_l : Sequence := ((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var j : OclAny := inp_l->first() ; var k : double := inp_l[1+1] - 1 ; while true do ( if (j->compareTo(k)) >= 0 then ( break ) else skip ; var l[j+1] : OclAny := null; var l[k+1] : OclAny := null; Sequence{l[j+1],l[k+1]} := Sequence{l[k+1],l[j+1]} ; k := k - 1 ; j := j + 1)) ; execute (StringLib.sumStringsWithSeparator((l), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _=input() A=[int(a)for a in input().split()] for _ in range(int(input())): b,e=map(int,input().split()) A=A[0 : b]+A[b : e][: :-1]+A[e :] print(*A) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _anon : String := (OclFile["System.in"]).readLine() ; var A : Sequence := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var b : OclAny := null; var e : OclAny := null; Sequence{b,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; A := A.subrange(0+1, b) + A.subrange(b+1, e)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) + A.subrange(e+1)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name A))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): a=input() a=[j for j in a] b=input() b=[k for k in b] c=a+b n=len(set(c)) print(n-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : String := (OclFile["System.in"]).readLine() ; a := a->characters()->select(j | true)->collect(j | (j)) ; var b : String := (OclFile["System.in"]).readLine() ; b := b->characters()->select(k | true)->collect(k | (k)) ; var c : String := a + b ; var n : int := (Set{}->union((c)))->size() ; execute (n - 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- Img=input exec(int(Img())*'print(len({*Img()+Img()})-1);') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Img : OclAny := input ; (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name Img)) (trailer (arguments ( ))))))))) )))) * (expr (atom 'print(len({*Img()+Img()})-1);'))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,l,r=map(int,input().split()) print('No')if(n//l)toInteger()-1) do ( var n : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{n,l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'No'))))))) )))))) if (logical_test (comparison (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name n))) // (expr (atom (name l)))))))) )))) < (comparison (expr (expr (atom (name n))) / (expr (atom (name r))))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'Yes'))))))) ))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) while n>0 : print(len(set(input()+input()))-1) n-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while n > 0 do ( execute ((Set{}->union(((OclFile["System.in"]).readLine() + (OclFile["System.in"]).readLine())))->size() - 1)->display() ; n := n - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- testcases=0 testcases=int(input()) for k in range(0,testcases,1): rows=list(input()) rows.extend(input()) same=0 for i in rows : for j in rows : if i==j : same=same+1 if same==16 : print("0") if same==10 : print("1") if same==6 : print("2") if same==8 : print("1") if same==4 : print("3") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var testcases : int := 0 ; testcases := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for k : Integer.subrange(0, testcases-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( var rows : Sequence := ((OclFile["System.in"]).readLine())->characters() ; rows := rows->union((OclFile["System.in"]).readLine()) ; var same : int := 0 ; for i : rows do ( for j : rows do ( if i = j then ( same := same + 1 ) else skip)) ; if same = 16 then ( execute ("0")->display() ) else skip ; if same = 10 then ( execute ("1")->display() ) else skip ; if same = 6 then ( execute ("2")->display() ) else skip ; if same = 8 then ( execute ("1")->display() ) else skip ; if same = 4 then ( execute ("3")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): list=[] x=input() y=input() for a in x : if a not in list : list.append(a) for b in y : if b not in list : list.append(b) print(len(list)-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var OclType["Sequence"] : Sequence := Sequence{} ; var x : String := (OclFile["System.in"]).readLine() ; var y : String := (OclFile["System.in"]).readLine() ; for a : x->characters() do ( if (OclType["Sequence"])->excludes(a) then ( execute ((a) : OclType["Sequence"]) ) else skip) ; for b : y->characters() do ( if (OclType["Sequence"])->excludes(b) then ( execute ((b) : OclType["Sequence"]) ) else skip) ; execute ((OclType["Sequence"])->size() - 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMissingPositive(arr,n): m=1 x=[] for i in range(n): if(munion(Sequence{3}->union(Sequence{-7}->union(Sequence{6}->union(Sequence{8}->union(Sequence{1}->union(Sequence{-10}->union(Sequence{ 15 }))))))) ; n := (arr)->size() ; execute (findMissingPositive(arr, n))->display() ) else skip; operation findMissingPositive(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var m : int := 1 ; var x : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if ((m->compareTo(arr[i+1])) < 0) then ( execute ((arr[i+1]) : x) ) else (if (m = arr[i+1]) then ( m := m + 1 ; while (x->count(m)) do ( execute ((m) /: x) ; m := m + 1) ) else skip)) ; return m; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- days=[31,29,31,30,31,30,31,31,30,31,30,31] ans=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"] while True : idx=3 m,d=map(int,input().split()) if m==0 : break print(ans[(idx+sum(days[: m-1])+d-1)% 7]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var days : Sequence := Sequence{31}->union(Sequence{29}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{ 31 }))))))))))) ; var ans : Sequence := Sequence{"Monday"}->union(Sequence{"Tuesday"}->union(Sequence{"Wednesday"}->union(Sequence{"Thursday"}->union(Sequence{"Friday"}->union(Sequence{"Saturday"}->union(Sequence{ "Sunday" })))))) ; while true do ( var idx : int := 3 ; var m : OclAny := null; var d : OclAny := null; Sequence{m,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if m = 0 then ( break ) else skip ; execute (ans[(idx + (days.subrange(1,m - 1))->sum() + d - 1) mod 7+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() c=0 if s[0]=='-' : s=s[1 :]; c=1 if '.' in s : a,b=s.split('.') b=b[: 2] else : a=s b='' b+='0'*(2-len(b)) a=list(reversed(a)) a=[a[i : i+3]for i in range(0,len(a),3)] a=list(reversed([''.join(i[: :-1])for i in a])) a='$'+','.join(a)+'.'+b if c : print('('+a+')'); exit() print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var c : int := 0 ; if s->first() = '-' then ( s := s->tail(); c := 1 ) else skip ; if (s)->characters()->includes('.') then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := s.split('.') ; var b : OclAny := b.subrange(1,2) ) else ( var a : String := s ; b := '' ) ; b := b + StringLib.nCopies('0', (2 - (b)->size())) ; a := ((a)->reverse()) ; a := Integer.subrange(0, (a)->size()-1)->select( $x | ($x - 0) mod 3 = 0 )->select(i | true)->collect(i | (a.subrange(i+1, i + 3))) ; a := ((a->characters()->select(i | true)->collect(i | (StringLib.sumStringsWithSeparator((i(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))), ''))))->reverse()) ; a := '$' + StringLib.sumStringsWithSeparator((a), ',') + '.' + b ; if c then ( execute ('(' + a + ')')->display(); exit() ) else skip ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=map(int,input().split()) m=n//(2*t+1) actions=[] excess=n %(2*t+1) if excess!=0 : m+=1 start=(excess+1)//2 else : start=t+1 for i in range(m): actions.append(str(start+i*(2*t+1))) print(m) print(' '.join(actions)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : int := n div (2 * t + 1) ; var actions : Sequence := Sequence{} ; var excess : int := n mod (2 * t + 1) ; if excess /= 0 then ( m := m + 1 ; var start : int := (excess + 1) div 2 ) else ( start := t + 1 ) ; for i : Integer.subrange(0, m-1) do ( execute ((("" + ((start + i * (2 * t + 1))))) : actions)) ; execute (m)->display() ; execute (StringLib.sumStringsWithSeparator((actions), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=[int(x)for x in input().split()] from collections import defaultdict as dd Sieve=dd(lambda : 0) for a in A : Sieve[a]+=1 ans,extra=0,0 for v in Sieve.values(): ans+=1 if v>1 and(v-1)& 1 : extra+=1 print(ans if not extra & 1 else ans-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; skip ; var Sieve : OclAny := dd(lambda $$ : OclAny in (0)) ; for a : A do ( Sieve[a+1] := Sieve[a+1] + 1) ; var ans : OclAny := null; var extra : OclAny := null; Sequence{ans,extra} := Sequence{0,0} ; for v : Sieve.values() do ( ans := ans + 1 ; if v > 1 & MathLib.bitwiseAnd((v - 1), 1) then ( extra := extra + 1 ) else skip) ; execute (if not(MathLib.bitwiseAnd(extra, 1)) then ans else ans - 1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import copy from collections import defaultdict from collections import Counter from collections import deque from itertools import product from itertools import permutations from itertools import combinations from bisect import bisect_left,bisect_right def inside(y,x,H,W): return 0<=yunion(Sequence{-1}->union(Sequence{0}->union(Sequence{ 1 }))) ; var dx : Sequence := Sequence{1}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{ 0 }))) ; skip ; skip ; skip ; var INF : double := ("" + (("inf")))->toReal() ; var N : OclAny := i_inpl() ; var A : OclAny := l_inpl() ; var d : OclAny := defaultdict(OclType["int"]) ; for Ai : A do ( d[Ai+1] := d[Ai+1] + 1) ; var k : int := (d)->size() ; if k mod 2 = 0 then ( execute (k - 1)->display() ) else ( execute (k)->display() ); operation inside(y : OclAny, x : OclAny, H : OclAny, W : OclAny) : OclAny pre: true post: true activity: return 0 <= y & (y < H) & 0 <= x & (x < W); operation i_inpl() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation s_inpl() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation l_inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline from collections import Counter def main(): N=int(readline()) A=list(map(int,readline().rstrip().split())) c=Counter(A) cnt=0 for key,val in c.items(): if val>2 : if val % 2==0 : c[key]=2 cnt+=1 else : c[key]=1 elif val==2 : cnt+=1 if cnt % 2==0 : print(len(c)) else : print(len(c)-1) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : int := ("" + ((readline())))->toInteger() ; var A : Sequence := ((readline().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : OclAny := Counter(A) ; var cnt : int := 0 ; for _tuple : c->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var val : OclAny := _tuple->at(_indx); if val > 2 then ( if val mod 2 = 0 then ( c[key+1] := 2 ; cnt := cnt + 1 ) else ( c[key+1] := 1 ) ) else (if val = 2 then ( cnt := cnt + 1 ) else skip)) ; if cnt mod 2 = 0 then ( execute ((c)->size())->display() ) else ( execute ((c)->size() - 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class CodeforcesTask397BSolution : def __init__(self): self.result='' self.t=0 self.queries=[] def read_input(self): self.t=int(input()) for _ in range(self.t): self.queries.append([int(x)for x in input().split(" ")]) def process_task(self): res=[] for query in self.queries : k=query[0]//query[1] res.append("Yes" if k*query[2]>=query[0]else "No") self.result="\n".join(res) def get_result(self): return self.result if __name__=="__main__" : Solution=CodeforcesTask397BSolution() Solution.read_input() Solution.process_task() print(Solution.get_result()) ------------------------------------------------------------ OCL File: --------- class CodeforcesTask397BSolution { static operation newCodeforcesTask397BSolution() : CodeforcesTask397BSolution pre: true post: CodeforcesTask397BSolution->exists( _x | result = _x ); attribute result : String := ''; attribute t : int := 0; attribute queries : Sequence := Sequence{}; operation initialise() : CodeforcesTask397BSolution pre: true post: true activity: self.result := '' ; self.t := 0 ; self.queries := Sequence{}; return self; operation read_input() pre: true post: true activity: self.t := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, self.t-1) do ((expr (atom (name self)) (trailer . (name queries)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " "))))))) )))))))) ]))))))) ))))); operation process_task() pre: true post: true activity: var res : Sequence := Sequence{} ; for query : self.queries do ( var k : int := query->first() div query[1+1] ; execute ((if (k * query[2+1]->compareTo(query->first())) >= 0 then "Yes" else "No" endif) : res)) ; self.result := StringLib.sumStringsWithSeparator((res), "\n"); operation get_result() : OclAny pre: true post: true activity: return self.result; } class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var Solution : CodeforcesTask397BSolution := (CodeforcesTask397BSolution.newCodeforcesTask397BSolution()).initialise() ; Solution.read_input() ; Solution.process_task() ; execute (Solution.get_result())->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def read_int_list(): return list(map(int,input().split())) def read_str_list(): return input().split() def read_int(): return int(input()) def read_str(): return input() n=read_int() a=read_int_list() b=set(a) res=len(b) if res % 2!=1 : res-=1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var n : OclAny := read_int() ; var a : OclAny := read_int_list() ; var b : Set := Set{}->union((a)) ; var res : int := (b)->size() ; if res mod 2 /= 1 then ( res := res - 1 ) else skip ; execute (res)->display(); operation read_int_list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation read_str_list() : OclAny pre: true post: true activity: return input().split(); operation read_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation read_str() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n=int(input()) m=sum(v-1 for v in Counter([int(i)for i in input().split()]).values()) print(n-round(m+0.5)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name Counter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( )))))))) ]))))))) ))) (trailer . (name values) (arguments ( )))))))))->sum() ; execute (n - (m + 0.5)->round())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) size=5 while size*size<=k and k % size!=0 : size+=1 if k % size!=0 or k/size<5 : print(-1) else : table=list("aeiou") ans=list() for i in range(size): ans.extend([table[(i % 5)]]) temp=ans[:] for i in range(k//size): temp+=temp.pop(0) ans.extend(temp) print("".join(ans)[: k]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var size : int := 5 ; while (size * size->compareTo(k)) <= 0 & k mod size /= 0 do ( size := size + 1) ; if k mod size /= 0 or k / size < 5 then ( execute (-1)->display() ) else ( var table : Sequence := ("aeiou")->characters() ; var ans : Sequence := () ; for i : Integer.subrange(0, size-1) do ( ans := ans->union(Sequence{ table[(i mod 5)+1] })) ; var temp : Sequence := ans ; for i : Integer.subrange(0, k div size-1) do ( temp := temp + temp->at(0`firstArg+1) ; temp := temp->excludingAt(0+1) ; ans := ans->union(temp)) ; execute ("".join(ans).subrange(1,k))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline s='aeiou' n=int(input()) if n<25 : print(-1) else : for i in range(5,n//5+1,1): if n % i==0 : d=n//i for j in range(i): print((s*d)[: d],end='') s=s[1 :]+s[0] break else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var s : String := 'aeiou' ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n < 25 then ( execute (-1)->display() ) else ( (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 5)))))))) , (argument (test (logical_test (comparison (expr (expr (expr (atom (name n))) // (expr (atom (number (integer 5))))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name n))) % (expr (atom (name i))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name n))) // (expr (atom (name i))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name s))) * (expr (atom (name d)))))))) )) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name d)))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom ''))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) + (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ))))))))))))))) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ar=[['a','e','i','o','u'],['e','i','o','u','a'],['i','o','u','a','e'],['o','u','a','e','i'],['u','a','e','i','o'],] col=[] row=[] n=int(input()) i=5 x=-1 y=-1 s="" while i*i<=n : if n % i==0 : if(n//i>=5): x=i y=n//i break i+=1 if x==-1 or y==-1 : print(-1) else : for i in range(y-5): col.append(['a','e','i','o','u']+list(('x'*(x-5)))) for i in range(x-5): ar.append(['a','e','i','o','u']) for i in range(len(col)): for j in range(len(col[i])): ar[j]+=col[i][j] s="" for a in ar : s+=''.join(map(str,a)) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ar : Sequence := Sequence{Sequence{'a'}->union(Sequence{'e'}->union(Sequence{'i'}->union(Sequence{'o'}->union(Sequence{ 'u' }))))}->union(Sequence{Sequence{'e'}->union(Sequence{'i'}->union(Sequence{'o'}->union(Sequence{'u'}->union(Sequence{ 'a' }))))}->union(Sequence{Sequence{'i'}->union(Sequence{'o'}->union(Sequence{'u'}->union(Sequence{'a'}->union(Sequence{ 'e' }))))}->union(Sequence{Sequence{'o'}->union(Sequence{'u'}->union(Sequence{'a'}->union(Sequence{'e'}->union(Sequence{ 'i' }))))}->union(Sequence{ Sequence{'u'}->union(Sequence{'a'}->union(Sequence{'e'}->union(Sequence{'i'}->union(Sequence{ 'o' })))) })))) ; var col : Sequence := Sequence{} ; var row : Sequence := Sequence{} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 5 ; var x : int := -1 ; var y : int := -1 ; var s : String := "" ; while (i * i->compareTo(n)) <= 0 do ( if n mod i = 0 then ( if (n div i >= 5) then ( x := i ; y := n div i ; break ) else skip ) else skip ; i := i + 1) ; if x = -1 or y = -1 then ( execute (-1)->display() ) else ( for i : Integer.subrange(0, y - 5-1) do ( execute ((Sequence{'a'}->union(Sequence{'e'}->union(Sequence{'i'}->union(Sequence{'o'}->union(Sequence{ 'u' }))))->union(((StringLib.nCopies('x', (x - 5))))->characters())) : col)) ; for i : Integer.subrange(0, x - 5-1) do ( execute ((Sequence{'a'}->union(Sequence{'e'}->union(Sequence{'i'}->union(Sequence{'o'}->union(Sequence{ 'u' }))))) : ar)) ; for i : Integer.subrange(0, (col)->size()-1) do ( for j : Integer.subrange(0, (col[i+1])->size()-1) do ( ar[j+1] := ar[j+1] + col[i+1][j+1])) ; s := "" ; for a : ar do ( s := s + StringLib.sumStringsWithSeparator(((a)->collect( _x | (OclType["String"])->apply(_x) )), '')) ; execute (s)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) i=2 s="aeiou" while i*i<=n : if n % i==0 : if i>=5 and n//i>=5 : m=min(i,n//i) for i in range(max(i,n//i)): print((m//5)*s+s[: m % 5],end='') s=s[1 :]+s[0] return i+=1 print(-1) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 2 ; var s : String := "aeiou" ; while (i * i->compareTo(n)) <= 0 do ( if n mod i = 0 then ( if i >= 5 & n div i >= 5 then ( var m : OclAny := Set{i, n div i}->min() ; for i : Integer.subrange(0, Set{i, n div i}->max()-1) do ( execute ((m div 5) * s + s.subrange(1,m mod 5))->display() ; s := s->tail() + s->first()) ; return ) else skip ) else skip ; i := i + 1) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def divisor(i): s=[] for j in range(1,int(i**(1/2))+1): if i % j==0 : s.append(i//j) s.append(j) return sorted(set(s)) k=int(input()) x=list("aeiou") d=divisor(k) ans=["-1"] for n in d : if min(n,k//n)>=5 : ans=[] for i in range(k//n): for j in range(n): ans.append(x[(i+j)% 5]) break sys.stdout.write("".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; skip ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ("aeiou")->characters() ; var d : OclAny := divisor(k) ; var ans : Sequence := Sequence{ "-1" } ; for n : d do ( if Set{n, k div n}->min() >= 5 then ( ans := Sequence{} ; for i : Integer.subrange(0, k div n-1) do ( for j : Integer.subrange(0, n-1) do ( execute ((x[(i + j) mod 5+1]) : ans))) ; break ) else skip) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) )))); operation divisor(i : OclAny) : OclAny pre: true post: true activity: var s : Sequence := Sequence{} ; for j : Integer.subrange(1, ("" + (((i)->pow((1 / 2)))))->toInteger() + 1-1) do ( if i mod j = 0 then ( execute ((i div j) : s) ; execute ((j) : s) ) else skip) ; return Set{}->union((s))->sort(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,t): value=n//(2*t+1) mod=n %(2*t+1) if mod>=t+1 : return[i*(2*t+1)+t+1 for i in range(value+1)] elif mod==0 : return[i*(2*t+1)+t+1 for i in range(value)] else : return[mod+i*(2*t+1)for i in range(value+1)] if __name__=='__main__' : nt_str=input() n,t=nt_str.split(' ') n,t=int(n),int(t) result=solve(n,t) print(len(result)) print(' '.join([str(it)for it in result])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var nt_str : String := (OclFile["System.in"]).readLine() ; Sequence{n,t} := nt_str.split(' ') ; Sequence{n,t} := Sequence{("" + ((n)))->toInteger(),("" + ((t)))->toInteger()} ; var result : OclAny := solve(n, t) ; execute ((result)->size())->display() ; execute (StringLib.sumStringsWithSeparator((result->select(it | true)->collect(it | (("" + ((it)))))), ' '))->display() ) else skip; operation solve(n : OclAny, t : OclAny) : OclAny pre: true post: true activity: var value : int := n div (2 * t + 1) ; var mod : int := n mod (2 * t + 1) ; if (mod->compareTo(t + 1)) >= 0 then ( return Integer.subrange(0, value + 1-1)->select(i | true)->collect(i | (i * (2 * t + 1) + t + 1)) ) else (if mod = 0 then ( return Integer.subrange(0, value-1)->select(i | true)->collect(i | (i * (2 * t + 1) + t + 1)) ) else ( return Integer.subrange(0, value + 1-1)->select(i | true)->collect(i | (mod + i * (2 * t + 1))) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : f=open("input.txt","r") n,k=map(int,f.readline().split()) light=list(map(int,f.readline().split())) lightSorted=sorted(light,reverse=True) minLight=min(light) minLightToRead,lightLevel=float('inf'),[] for i in range(n): l=lightSorted[i] lenLL=len(lightLevel) if lenLL==k : break if lenLL<=k : minLightToRead=min(minLightToRead,l) lightLevel.append(l) idxLightLeve=[] for i in range(n): if light[i]in lightLevel and len(idxLightLeve)collect( _x | (OclType["int"])->apply(_x) ) ; var light : Sequence := ((f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lightSorted : Sequence := light->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var minLight : OclAny := (light)->min() ; var minLightToRead : OclAny := null; var lightLevel : OclAny := null; Sequence{minLightToRead,lightLevel} := Sequence{("" + (('inf')))->toReal(),Sequence{}} ; for i : Integer.subrange(0, n-1) do ( var l : OclAny := lightSorted[i+1] ; var lenLL : int := (lightLevel)->size() ; if lenLL = k then ( break ) else skip ; if (lenLL->compareTo(k)) <= 0 then ( var minLightToRead : OclAny := Set{minLightToRead, l}->min() ; execute ((l) : lightLevel) ) else skip) ; var idxLightLeve : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if (lightLevel)->includes(light[i+1]) & ((idxLightLeve)->size()->compareTo(k)) < 0 then ( execute ((i + 1) : idxLightLeve) ) else skip) ; f := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ; execute (minLightToRead)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name idxLightLeve))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.stdin=open('input.txt','r') sys.stdout=open('output.txt','w') (number_of_hours_on_train,number_of_hours_to_read)=map(int,input().split(' ')) light_levels=list(map(int,input().split(' '))) sorted_list=(sorted(light_levels)) sorted_list.reverse() sorted_list_index=[] reading_hours=[] for light_level in sorted_list[: number_of_hours_to_read]: reading_hours.append(light_level) for i in range(number_of_hours_on_train): if light_levels[i]in reading_hours : sorted_list_index.append(i+1) if len(sorted_list_index)==number_of_hours_to_read : break sorted_list_index.sort() print(min(reading_hours)) print(*sorted_list_index) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('input.txt')) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile('output.txt')) ; var Sequence{number_of_hours_on_train, number_of_hours_to_read} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var light_levels : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var sorted_list : Sequence := (light_levels->sort()) ; sorted_list := sorted_list->reverse() ; var sorted_list_index : Sequence := Sequence{} ; var reading_hours : Sequence := Sequence{} ; for light_level : sorted_list.subrange(1,number_of_hours_to_read) do ( execute ((light_level) : reading_hours)) ; for i : Integer.subrange(0, number_of_hours_on_train-1) do ( if (reading_hours)->includes(light_levels[i+1]) then ( execute ((i + 1) : sorted_list_index) ) else skip ; if (sorted_list_index)->size() = number_of_hours_to_read then ( break ) else skip) ; sorted_list_index := sorted_list_index->sort() ; execute ((reading_hours)->min())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name sorted_list_index))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getsum(x): return int((x*(x+1))/2) def countJumps(n): n=abs(n) ans=0 while(getsum(ans)display() ) else skip; operation getsum(x : OclAny) : OclAny pre: true post: true activity: return ("" + (((x * (x + 1)) / 2)))->toInteger(); operation countJumps(n : OclAny) : OclAny pre: true post: true activity: n := (n)->abs() ; var ans : int := 0 ; while ((getsum(ans)->compareTo(n)) < 0 or MathLib.bitwiseAnd((getsum(ans) - n), 1)) do ( ans := ans + 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() F=open('input.txt') I=lambda : map(int,F.readline().split()) n,k=I(); a=sorted(zip(I(),range(n)))[: :-1] print(a[k-1][0],'\n',*(y+1 for x,y in a[: k]),file=open('output.txt','w')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var F : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('input.txt')) ; var I : Function := lambda $$ : OclAny in ((F.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := I->apply(); var a : OclAny := sorted(Integer.subrange(1, I->apply()->size())->collect( _indx | Sequence{I->apply()->at(_indx), Integer.subrange(0, n-1)->at(_indx)} ))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; execute (a[k - 1+1]->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import lru_cache from collections import defaultdict,deque from heapq import heappush,heappop def solution(): file=open("input.txt","r") _,k=map(int,file.readline().split()) arr=list(map(int,file.readline().split())) minheap=[] for i,val in enumerate(arr): heappush(minheap,(val,i+1)) if len(minheap)>k : heappop(minheap) file.close() file=open("output.txt","w") file.write(str(minheap[0][0])+"\n") file.write(" ".join(map(str,[i for _,i in minheap]))+"\n") import sys import threading sys.setrecursionlimit(1<<30) threading.stack_size(1<<27) thread=threading.Thread(target=solution) thread.start(); thread.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1 * (2->pow(30))) ; threading.stack_size(1 * (2->pow(27))) ; var thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name solution)))))))) ; thread.start(); thread.join(); operation solution() pre: true post: true activity: var file : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ; var _anon : OclAny := null; var k : OclAny := null; Sequence{_anon,k} := (file.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((file.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var minheap : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (arr)->size())->collect( _indx | Sequence{_indx-1, (arr)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var val : OclAny := _tuple->at(_indx); heappush(minheap, Sequence{val, i + 1}) ; if ((minheap)->size()->compareTo(k)) > 0 then ( heappop(minheap) ) else skip) ; file.closeFile() ; file := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ; file.write(("" + ((minheap->first()->first()))) + "\n") ; file.write(StringLib.sumStringsWithSeparator(((minheap->select(_tuple | true)->collect(_tuple | let _anon : OclAny = _tuple->at(1) in let i : OclAny = _tuple->at(2) in (i)))->collect( _x | (OclType["String"])->apply(_x) )), " ") + "\n"); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=open('input.txt','r') n,k=map(int,f.readline().split()) a=list(map(int,f.readline().split())) f.close() t=open('output.txt','w') b=[] for i in range(n): b.append((a[i],i+1)) b.sort() f1=open('output.txt','w') f1.write(str(b[n-k][0])+'\n') ans='' for i in range(n-k,n): ans+=str(b[i][1])+' ' f1.write(ans) f1.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('input.txt')) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; f.closeFile() ; var t : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('output.txt')) ; var b : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((Sequence{a[i+1], i + 1}) : b)) ; b := b->sort() ; var f1 : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('output.txt')) ; f1.write(("" + ((b[n - k+1]->first()))) + ' ') ; var ans : String := '' ; for i : Integer.subrange(n - k, n-1) do ( ans := ans + ("" + ((b[i+1][1+1]))) + ' ') ; f1.write(ans) ; f1.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 2==0 : print(-1) else : print(*range(n)) print(*range(n)) print(*map(lambda x : x*2 % n,range(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( execute (-1)->display() ) else ( execute ((argument * (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (expr (expr (atom (name x))) * (expr (atom (number (integer 2))))) % (expr (atom (name n))))))))) , (argument (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))) )))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 2==0 : print(-1) else : a=' '.join(str(x)for x in range(n)) print(a) print(a) print(' '.join(str(x)for x in range(0,n,2)),' '.join(str(x)for x in range(1,n,2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( execute (-1)->display() ) else ( var a : String := StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))), ' ') ; execute (a)->display() ; execute (a)->display() ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom (name n))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ))))))))), ' '))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 2==0 : print(-1) else : print(*range(n)) print(*range(n)) print(*map(lambda x,y :(x+y)% n,range(n),range(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( execute (-1)->display() ) else ( execute ((argument * (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)) , (vardef_parameter (name y)))) : (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (name y)))))))) ))) % (expr (atom (name n))))))))) , (argument (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))) )))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) t="" tt="" ttt="" if a % 2!=0 : for x in range(0,a): t=t+(str(x)+" ") for x in range(0,a): tt=tt+(str(x)+" ") for x in range(0,a): ttt=ttt+(str(2*x % a)+" ") else : print(-1) print(t) print(tt) print(ttt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : String := "" ; var tt : String := "" ; var ttt : String := "" ; if a mod 2 /= 0 then ( for x : Integer.subrange(0, a-1) do ( t := t + (("" + ((x))) + " ")) ; for x : Integer.subrange(0, a-1) do ( tt := tt + (("" + ((x))) + " ")) ; for x : Integer.subrange(0, a-1) do ( ttt := ttt + (("" + ((2 * x mod a))) + " ")) ) else ( execute (-1)->display() ) ; execute (t)->display() ; execute (tt)->display() ; execute (ttt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 2 : x=2 while x : for i in range(n): print(i,end='') x-=1 print('') for i in range(n): print((2*i)% n,end='') else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 then ( var x : int := 2 ; while x do ( for i : Integer.subrange(0, n-1) do ( execute (i)->display()) ; x := x - 1 ; execute ('')->display()) ; for i : Integer.subrange(0, n-1) do ( execute ((2 * i) mod n)->display()) ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) diff=n %(2*k+1) if diff=k+1 : ansCount=n//(2*k+1)+1 ans=[k+1+(2*k+1)*x for x in range(ansCount)] print(ansCount) print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var diff : int := n mod (2 * k + 1) ; if (diff->compareTo(k + 1)) < 0 then ( if diff = 0 then ( var ansCount : int := n div (2 * k + 1) ; var ans : Sequence := Integer.subrange(0, ansCount-1)->select(x | true)->collect(x | (k + 1 + (2 * k + 1) * x)) ) else ( var sub : double := k + 1 - diff ; ansCount := n div (2 * k + 1) + 1 ; ans := Integer.subrange(0, ansCount-1)->select(x | true)->collect(x | (k + 1 - sub + (2 * k + 1) * x)) ) ) else (if (diff->compareTo(k + 1)) >= 0 then ( ansCount := n div (2 * k + 1) + 1 ; ans := Integer.subrange(0, ansCount-1)->select(x | true)->collect(x | (k + 1 + (2 * k + 1) * x)) ) else skip) ; execute (ansCount)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countWays(are,n): pos=[0 for i in range(n)] p=0 for i in range(n): if(arr[i]==1): pos[p]=i+1 p+=1 if(p==0): return 0 ways=1 for i in range(p-1): ways*=pos[i+1]-pos[i] return ways if __name__=='__main__' : arr=[1,0,1,0,1] n=len(arr) print(countWays(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var arr : Sequence := Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 1 })))) ; n := (arr)->size() ; execute (countWays(arr, n))->display() ) else skip; operation countWays(are : OclAny, n : OclAny) : OclAny pre: true post: true activity: var pos : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var p : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] = 1) then ( pos[p+1] := i + 1 ; p := p + 1 ) else skip) ; if (p = 0) then ( return 0 ) else skip ; var ways : int := 1 ; for i : Integer.subrange(0, p - 1-1) do ( ways := ways * pos[i + 1+1] - pos[i+1]) ; return ways; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=10 def lcs(dp,arr1,n,arr2,m,k): if k<0 : return-(10**7) if n<0 or m<0 : return 0 ans=dp[n][m][k] if ans!=-1 : return ans ans=max(lcs(dp,arr1,n-1,arr2,m,k),lcs(dp,arr1,n,arr2,m-1,k)) if arr1[n-1]==arr2[m-1]: ans=max(ans,1+lcs(dp,arr1,n-1,arr2,m-1,k)) ans=max(ans,lcs(dp,arr1,n-1,arr2,m-1,k-1)) return ans if __name__=="__main__" : k=1 arr1=[1,2,3,4,5] arr2=[5,3,1,4,2] n=len(arr1) m=len(arr2) dp=[[[-1 for i in range(MAX)]for j in range(MAX)]for k in range(MAX)] print(lcs(dp,arr1,n,arr2,m,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 10 ; skip ; if __name__ = "__main__" then ( k := 1 ; arr1 := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ; arr2 := Sequence{5}->union(Sequence{3}->union(Sequence{1}->union(Sequence{4}->union(Sequence{ 2 })))) ; n := (arr1)->size() ; m := (arr2)->size() ; dp := Integer.subrange(0, MAX-1)->select(k | true)->collect(k | (Integer.subrange(0, MAX-1)->select(j | true)->collect(j | (Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (-1)))))) ; execute (lcs(dp, arr1, n, arr2, m, k))->display() ) else skip; operation lcs(dp : OclAny, arr1 : OclAny, n : OclAny, arr2 : OclAny, m : OclAny, k : OclAny) : OclAny pre: true post: true activity: if k < 0 then ( return -((10)->pow(7)) ) else skip ; if n < 0 or m < 0 then ( return 0 ) else skip ; var ans : OclAny := dp[n+1][m+1][k+1] ; if ans /= -1 then ( return ans ) else skip ; ans := Set{lcs(dp, arr1, n - 1, arr2, m, k), lcs(dp, arr1, n, arr2, m - 1, k)}->max() ; if arr1[n - 1+1] = arr2[m - 1+1] then ( ans := Set{ans, 1 + lcs(dp, arr1, n - 1, arr2, m - 1, k)}->max() ) else skip ; ans := Set{ans, lcs(dp, arr1, n - 1, arr2, m - 1, k - 1)}->max() ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,l): if l<3 : if int(n)% 8==0 : return True n=n[: :-1] if int(n)% 8==0 : return True return False hash=10*[0] for i in range(0,l): hash[int(n[i])-0]+=1 ; for i in range(104,1000,8): dup=i freq=10*[0] freq[int(dup % 10)]+=1 ; dup=dup/10 freq[int(dup % 10)]+=1 ; dup=dup/10 freq[int(dup % 10)]+=1 ; dup=i if(freq[int(dup % 10)]>hash[int(dup % 10)]): continue ; dup=dup/10 ; if(freq[int(dup % 10)]>hash[int(dup % 10)]): continue ; dup=dup/10 if(freq[int(dup % 10)]>hash[int(dup % 10)]): continue ; return True return False if __name__=="__main__" : number="31462708" l=len(number) if solve(number,l): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var number : String := "31462708" ; l := (number)->size() ; if solve(number, l) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation solve(n : OclAny, l : OclAny) : OclAny pre: true post: true activity: if l < 3 then ( if ("" + ((n)))->toInteger() mod 8 = 0 then ( return true ) else skip ; n := n(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; if ("" + ((n)))->toInteger() mod 8 = 0 then ( return true ) else skip ; return false ) else skip ; var hash : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; for i : Integer.subrange(0, l-1) do ( hash[("" + ((n[i+1])))->toInteger() - 0+1] := hash[("" + ((n[i+1])))->toInteger() - 0+1] + 1;) ; for i : Integer.subrange(104, 1000-1)->select( $x | ($x - 104) mod 8 = 0 ) do ( var dup : OclAny := i ; var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; freq[("" + ((dup mod 10)))->toInteger()+1] := freq[("" + ((dup mod 10)))->toInteger()+1] + 1; ; dup := dup / 10 ; freq[("" + ((dup mod 10)))->toInteger()+1] := freq[("" + ((dup mod 10)))->toInteger()+1] + 1; ; dup := dup / 10 ; freq[("" + ((dup mod 10)))->toInteger()+1] := freq[("" + ((dup mod 10)))->toInteger()+1] + 1; ; dup := i ; if ((freq[("" + ((dup mod 10)))->toInteger()+1]->compareTo(hash[("" + ((dup mod 10)))->toInteger()+1])) > 0) then ( continue; ) else skip ; dup := dup / 10; ; if ((freq[("" + ((dup mod 10)))->toInteger()+1]->compareTo(hash[("" + ((dup mod 10)))->toInteger()+1])) > 0) then ( continue; ) else skip ; dup := dup / 10 ; if ((freq[("" + ((dup mod 10)))->toInteger()+1]->compareTo(hash[("" + ((dup mod 10)))->toInteger()+1])) > 0) then ( continue; ) else skip ; return true) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,A,B,K=map(int,input().split()) if A0 : if n & 1 : ret=mul(ret,mag) mag=mul(mag,mag) n>>=1 return ret def inv(a): return pow(a,MOD-2) fac=[1] fac_inv=[1] for n in range(1,N+10): f=mul(fac[n-1],n) fac.append(f) fac_inv.append(inv(f)) mem=[0]*(N+1) def ncr(n,r): if mem[r]>0 : return mem[r] else : ret=mul(mul(fac[n],fac_inv[n-r]),fac_inv[r]) mem[r]=ret return ret ans=0 for a in range(N+1): if a*A>K : break rem=K-a*A if rem % B : continue b=rem//B if b>N : continue ans+=mul(ncr(N,a),ncr(N,b)) print(ans % MOD) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; var K : OclAny := null; Sequence{N,A,B,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (A->compareTo(B)) < 0 then ( var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := Sequence{B,A} ) else skip ; var MOD : int := 998244353 ; skip ; skip ; skip ; var fac : Sequence := Sequence{ 1 } ; var fac_inv : Sequence := Sequence{ 1 } ; for n : Integer.subrange(1, N + 10-1) do ( var f : OclAny := mul(fac[n - 1+1], n) ; execute ((f) : fac) ; execute ((inv(f)) : fac_inv)) ; var mem : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; skip ; var ans : int := 0 ; for a : Integer.subrange(0, N + 1-1) do ( if (a * A->compareTo(K)) > 0 then ( break ) else skip ; var rem : double := K - a * A ; if rem mod B then ( continue ) else skip ; b := rem div B ; if (b->compareTo(N)) > 0 then ( continue ) else skip ; ans := ans + mul(ncr(N, a), ncr(N, b))) ; execute (ans mod MOD)->display(); operation mul(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a * b) mod MOD; operation pow(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ret : int := 1 ; var mag : OclAny := a ; while n > 0 do ( if MathLib.bitwiseAnd(n, 1) then ( ret := mul(ret, mag) ) else skip ; mag := mul(mag, mag) ; n := n div (2->pow(1))) ; return ret; operation inv(a : OclAny) : OclAny pre: true post: true activity: return (a)->pow(MOD - 2); operation ncr(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: if mem[r+1] > 0 then ( return mem[r+1] ) else ( ret := mul(mul(fac[n+1], fac_inv[n - r+1]), fac_inv[r+1]) ; mem[r+1] := ret ; return ret ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cmb(n,r,mod): if(r<0 or r>n): return 0 r=min(r,n-r) return g1[n]*g2[r]*g2[n-r]% mod mod=998244353 N=3*10**5 g1=[1,1] g2=[1,1] inverse=[0,1] for i in range(2,N+1): g1.append((g1[-1]*i)% mod) inverse.append((-inverse[mod % i]*(mod//i))% mod) g2.append((g2[-1]*inverse[-1])% mod) N,A,B,K=map(int,input().split()) ans=0 for i in range(0,N+1): if(K-A*i)% B==0 and N>=(K-A*i)//B>=0 : j=(K-A*i)//B ans+=cmb(N,i,mod)*cmb(N,j,mod) ans %=mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; mod := 998244353 ; var N : double := 3 * (10)->pow(5) ; var g1 : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var g2 : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var inverse : Sequence := Sequence{0}->union(Sequence{ 1 }) ; for i : Integer.subrange(2, N + 1-1) do ( execute (((g1->last() * i) mod mod) : g1) ; execute (((-inverse[mod mod i+1] * (mod div i)) mod mod) : inverse) ; execute (((g2->last() * inverse->last()) mod mod) : g2)) ; var A : OclAny := null; var B : OclAny := null; var K : OclAny := null; Sequence{N,A,B,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; for i : Integer.subrange(0, N + 1-1) do ( if (K - A * i) mod B = 0 & (N->compareTo((K - A * i) div B)) >= 0 & ((K - A * i) div B >= 0) then ( var j : int := (K - A * i) div B ; ans := ans + cmb(N, i, mod) * cmb(N, j, mod) ; ans := ans mod mod ) else skip) ; execute (ans)->display(); operation cmb(n : OclAny, r : OclAny, mod : OclAny) : OclAny pre: true post: true activity: if (r < 0 or (r->compareTo(n)) > 0) then ( return 0 ) else skip ; r := Set{r, n - r}->min() ; return g1[n+1] * g2[r+1] * g2[n - r+1] mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import numpy as np sr=lambda : sys.stdin.readline().rstrip() ir=lambda : int(sr()) lr=lambda : list(map(int,sr().split())) MOD=998244353 N,A,B,K=lr() answer=0 def F(x,y): return comb[x]*comb[y]% MOD def cumprod(arr,MOD): L=len(arr); Lsq=int(L**.5+1) arr=np.resize(arr,Lsq**2).reshape(Lsq,Lsq) for n in range(1,Lsq): arr[:,n]*=arr[:,n-1]; arr[:,n]%=MOD for n in range(1,Lsq): arr[n]*=arr[n-1,-1]; arr[n]%=MOD return arr.ravel()[: L] def make_fact(U,MOD): x=np.arange(U,dtype=np.int64); x[0]=1 fact=cumprod(x,MOD) x=np.arange(U,0,-1,dtype=np.int64); x[0]=pow(int(fact[-1]),MOD-2,MOD) fact_inv=cumprod(x,MOD)[: :-1] return fact,fact_inv U=N+1 fact,fact_inv=make_fact(U,MOD) fact_N=fact[N] comb=fact_N*fact_inv % MOD*fact_inv[: :-1]% MOD for x in range(N+1): temp=K-A*x q,r=divmod(temp,B) if r!=0 : continue if q>N : continue if q<0 : break answer+=F(x,q) answer %=MOD print(answer % MOD) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var sr : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var ir : Function := lambda $$ : OclAny in (("" + ((sr->apply())))->toInteger()) ; var lr : Function := lambda $$ : OclAny in (((sr->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var MOD : int := 998244353 ; var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; var K : OclAny := null; Sequence{N,A,B,K} := lr->apply() ; var answer : int := 0 ; skip ; skip ; skip ; U := N + 1 ; Sequence{fact,fact_inv} := make_fact(U, MOD) ; var fact_N : OclAny := fact[N+1] ; var comb : int := fact_N * fact_inv mod MOD * fact_inv(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) mod MOD ; for x : Integer.subrange(0, N + 1-1) do ( var temp : double := K - A * x ; var q : OclAny := null; var r : OclAny := null; Sequence{q,r} := Sequence{(temp div B), (temp mod B)} ; if r /= 0 then ( continue ) else skip ; if (q->compareTo(N)) > 0 then ( continue ) else skip ; if q < 0 then ( break ) else skip ; answer := answer + F(x, q) ; answer := answer mod MOD) ; execute (answer mod MOD)->display(); operation F(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return comb[x+1] * comb[y+1] mod MOD; operation cumprod(arr : OclAny, MOD : OclAny) : OclAny pre: true post: true activity: var L : int := (arr)->size(); var Lsq : int := ("" + (((L)->pow(.5) + 1)))->toInteger() ; arr := np.resize(arr, (Lsq)->pow(2)).reshape(Lsq, Lsq) ; for n : Integer.subrange(1, Lsq-1) do ( arr->collect( _r | _r[n+1] ) := arr->collect( _r | _r[n+1] ) * arr->collect( _r | _r[n - 1+1] ); arr->collect( _r | _r[n+1] ) := arr->collect( _r | _r[n+1] ) mod MOD) ; for n : Integer.subrange(1, Lsq-1) do ( arr[n+1] := arr[n+1] * arr[n - 1+1]->last(); arr[n+1] := arr[n+1] mod MOD) ; return arr.ravel().subrange(1,L); operation make_fact(U : OclAny, MOD : OclAny) : OclAny pre: true post: true activity: x := MathLib.numericRange(U, (argument (test (logical_test (comparison (expr (atom (name dtype)))))) = (test (logical_test (comparison (expr (atom (name np)) (trailer . (name int64))))))), 1); x->first() := 1 ; var fact : OclAny := cumprod(x, MOD) ; x := ; x->first() := (("" + ((fact->last())))->toInteger())->pow(MOD - 2) ; var fact_inv : OclAny := cumprod(x, MOD)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; return fact, fact_inv; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,A,B,K=map(int,input().split()) mod=998244353 def pow(n,i): if i==0 : return 1 elif i==1 : return n elif i % 2==0 : return pow((n*n)% mod,i//2) else : return(pow((n*n)% mod,i//2)*n)% mod factorial=[1]*(N+1) revfactorial=[1]*(N+1) for i in range(N): factorial[i+1]=(factorial[i]*(i+1))% mod revfactorial[N]=pow(factorial[N],mod-2) for i in reversed(range(1,N)): revfactorial[i]=(revfactorial[i+1]*(i+1))% mod ans=0 for a in range(N+1): if K>=A*a : if(K-A*a)% B==0 : b=(K-A*a)//B apatt=(factorial[N]*revfactorial[N-a]*revfactorial[a])% mod if b<=N : bpatt=(factorial[N]*revfactorial[N-b]*revfactorial[b])% mod else : bpatt=0 ans+=(apatt*bpatt)% mod ans %=mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; var K : OclAny := null; Sequence{N,A,B,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mod : int := 998244353 ; skip ; var factorial : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (N + 1)) ; var revfactorial : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (N + 1)) ; for i : Integer.subrange(0, N-1) do ( factorial[i + 1+1] := (factorial[i+1] * (i + 1)) mod mod) ; revfactorial[N+1] := (factorial[N+1])->pow(mod - 2) ; for i : (Integer.subrange(1, N-1))->reverse() do ( revfactorial[i+1] := (revfactorial[i + 1+1] * (i + 1)) mod mod) ; var ans : int := 0 ; for a : Integer.subrange(0, N + 1-1) do ( if (K->compareTo(A * a)) >= 0 then ( if (K - A * a) mod B = 0 then ( var b : int := (K - A * a) div B ; var apatt : int := (factorial[N+1] * revfactorial[N - a+1] * revfactorial[a+1]) mod mod ; if (b->compareTo(N)) <= 0 then ( var bpatt : int := (factorial[N+1] * revfactorial[N - b+1] * revfactorial[b+1]) mod mod ) else ( bpatt := 0 ) ; ans := ans + (apatt * bpatt) mod mod ; ans := ans mod mod ) else skip ) else skip) ; execute (ans)->display(); operation pow(n : OclAny, i : OclAny) : OclAny pre: true post: true activity: if i = 0 then ( return 1 ) else (if i = 1 then ( return n ) else (if i mod 2 = 0 then ( return ((n * n) mod mod)->pow(i div 2) ) else ( return (((n * n) mod mod)->pow(i div 2) * n) mod mod ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,A,B,K=map(int,input().split()) MOD=998244353 if K==0 : print(1) exit() class Combination : def __init__(self,size,mod=10**9+7): self.size=size+2 self.mod=mod self.fact=[1,1]+[0]*size self.factInv=[1,1]+[0]*size self.inv=[0,1]+[0]*size for i in range(2,self.size): self.fact[i]=self.fact[i-1]*i % self.mod self.inv[i]=-self.inv[self.mod % i]*(self.mod//i)% self.mod self.factInv[i]=self.factInv[i-1]*self.inv[i]% self.mod def npr(self,n,r): if n=0 and a*A+b*B==K : ans+=comb.ncr(N,a)*comb.ncr(N,b) ans %=MOD print(ans) ------------------------------------------------------------ OCL File: --------- class Combination { static operation newCombination() : Combination pre: true post: Combination->exists( _x | result = _x ); attribute size : OclAny := size + 2; attribute mod : OclAny := mod; attribute fact : Sequence := Sequence{1}->union(Sequence{ 1 })->union(MatrixLib.elementwiseMult(Sequence{ 0 }, size)); attribute factInv : Sequence := Sequence{1}->union(Sequence{ 1 })->union(MatrixLib.elementwiseMult(Sequence{ 0 }, size)); attribute inv : Sequence := Sequence{0}->union(Sequence{ 1 })->union(MatrixLib.elementwiseMult(Sequence{ 0 }, size)); operation initialise(size : OclAny,mod : OclAny) : Combination pre: true post: true activity: self.size := size + 2 ; self.mod := mod ; self.fact := Sequence{1}->union(Sequence{ 1 })->union(MatrixLib.elementwiseMult(Sequence{ 0 }, size)) ; self.factInv := Sequence{1}->union(Sequence{ 1 })->union(MatrixLib.elementwiseMult(Sequence{ 0 }, size)) ; self.inv := Sequence{0}->union(Sequence{ 1 })->union(MatrixLib.elementwiseMult(Sequence{ 0 }, size)) ; for i : Integer.subrange(2, self.size-1) do ( self.fact[i+1] := self.fact[i - 1+1] * i mod self.mod ; self.inv[i+1] := -self.inv[self.mod mod i+1] * (self.mod div i) mod self.mod ; self.factInv[i+1] := self.factInv[i - 1+1] * self.inv[i+1] mod self.mod); return self; operation npr(n : OclAny,r : OclAny) : OclAny pre: true post: true activity: if (n->compareTo(r)) < 0 or n < 0 or r < 0 then ( return 0 ) else skip ; return self.fact[n+1] * self.factInv[n - r+1] mod self.mod; operation ncr(n : OclAny,r : OclAny) : OclAny pre: true post: true activity: if (n->compareTo(r)) < 0 or n < 0 or r < 0 then ( return 0 ) else skip ; return self.fact[n+1] * (self.factInv[r+1] * self.factInv[n - r+1] mod self.mod) mod self.mod; operation factN(n : OclAny) : OclAny pre: true post: true activity: if n < 0 then ( return 0 ) else skip ; return self.fact[n+1]; } class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; var K : OclAny := null; Sequence{N,A,B,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var MOD : int := 998244353 ; if K = 0 then ( execute (1)->display() ; exit() ) else skip ; skip ; var comb : Combination := (Combination.newCombination()).initialise(N + 100, MOD) ; var ans : int := 0 ; for a : Integer.subrange(0, K div A + 2-1) do ( var b : int := (K - a * A) div B ; if b >= 0 & a * A + b * B = K then ( ans := ans + comb.ncr(N, a) * comb.ncr(N, b) ; ans := ans mod MOD ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def min_elimination(n,arr): countOdd=0 for i in range(n): if(arr[i]% 2): countOdd+=1 return min(countOdd,n-countOdd) if __name__=='__main__' : arr=[1,2,3,7,9] n=len(arr) print(min_elimination(n,arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{7}->union(Sequence{ 9 })))) ; n := (arr)->size() ; execute (min_elimination(n, arr))->display() ) else skip; operation min_elimination(n : OclAny, arr : OclAny) : OclAny pre: true post: true activity: var countOdd : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] mod 2) then ( countOdd := countOdd + 1 ) else skip) ; return Set{countOdd, n - countOdd}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def tidy(N): return list(N)==sorted(N) def solve(N): if N=='0' : return '' if tidy(N)or len(N)<=1 : return N return solve(str(int(N[:-1])-1))+'9' T=int(input()) for case_number in range(1,T+1): N=input() print('Case #%d:' % case_number,solve(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for case_number : Integer.subrange(1, T + 1-1) do ( N := (OclFile["System.in"]).readLine() ; execute (StringLib.format('Case #%d:',case_number))->display()); operation tidy(N : OclAny) : OclAny pre: true post: true activity: return (N) = N->sort(); operation solve(N : OclAny) : OclAny pre: true post: true activity: if N = '0' then ( return '' ) else skip ; if tidy(N) or (N)->size() <= 1 then ( return N ) else skip ; return solve(("" + ((("" + ((N->front())))->toInteger() - 1)))) + '9'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- infilecode="BLI" import sys mapping={"A" : "A","B" : "B","C" : "C","D" : "D","E" : "E","X" : "example","S" : "-small","L" : "-large","P" : "-practice","0" : "-attempt0","1" : "-attempt1","2" : "-attempt2","I" : ".in","T" : ".txt"} infile="".join(mapping[c]for c in infilecode) outfile=infile.replace(".in","")+".out.txt" sys.stdin=open(infile,'r') output=open(outfile,'w') T=int(input()) for case in range(1,T+1): N=int(input()) print(N) a=str(N) l=len(a) for i in range(l-1,0,-1): if a[i]>=a[i-1]: continue a=a[: i]+"0"*(l-i) N=int(a)-1 a=str(N) answer=a print("Case #%d:" % case,answer) print("Case #%d:" % case,answer,file=output) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var infilecode : String := "BLI" ; skip ; var mapping : Map := Map{ "A" |-> "A" }->union(Map{ "B" |-> "B" }->union(Map{ "C" |-> "C" }->union(Map{ "D" |-> "D" }->union(Map{ "E" |-> "E" }->union(Map{ "X" |-> "example" }->union(Map{ "S" |-> "-small" }->union(Map{ "L" |-> "-large" }->union(Map{ "P" |-> "-practice" }->union(Map{ "0" |-> "-attempt0" }->union(Map{ "1" |-> "-attempt1" }->union(Map{ "2" |-> "-attempt2" }->union(Map{ "I" |-> ".in" }->union(Map{ "T" |-> ".txt" }))))))))))))) ; var infile : String := StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name mapping)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name c)))))))) ])))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name infilecode)))))))), "") ; var outfile : String := infile.replace(".in", "") + ".out.txt" ; OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile(infile)) ; var output : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(outfile)) ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for case : Integer.subrange(1, T + 1-1) do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (N)->display() ; var a : String := ("" + ((N))) ; var l : int := (a)->size() ; for i : Integer.subrange(0 + 1, l - 1)->reverse() do ( if (a[i+1]->compareTo(a[i - 1+1])) >= 0 then ( continue ) else skip ; a := a.subrange(1,i) + StringLib.nCopies("0", (l - i)) ; N := ("" + ((a)))->toInteger() - 1 ; a := ("" + ((N)))) ; var answer : String := a ; execute (StringLib.format("Case #%d:",case))->display() ; execute (StringLib.format("Case #%d:",case))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect n=int(input()) p=[int(x)-1 for x in input().split()] p2=sorted(enumerate(p),key=lambda x : x[1],reverse=True) ans=0 s=[-1,-1,n,n] for i,(idx,p)in enumerate(p2): t=bisect.bisect_left(s,idx) s.insert(t,idx) l1=s[t-1] l2=s[t-2] r1=s[t+1] r2=s[t+2] ans+=(p+1)*((idx-l1)*(r2-r1)+(r1-idx)*(l1-l2)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)) ; var p2 : Sequence := Integer.subrange(1, (p)->size())->collect( _indx | Sequence{_indx-1, (p)->at(_indx)} )->sortedBy($x | (lambda x : OclAny in (x[1+1]))->apply($x)) ; var ans : int := 0 ; var s : Sequence := Sequence{-1}->union(Sequence{-1}->union(Sequence{n}->union(Sequence{ n }))) ; for _tuple : Integer.subrange(1, (p2)->size())->collect( _indx | Sequence{_indx-1, (p2)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{idx, p} : OclAny := _tuple->at(_indx); var t : OclAny := bisect.bisect_left(s, idx) ; s := s.insertAt(t+1, idx) ; var l1 : OclAny := s[t - 1+1] ; var l2 : OclAny := s[t - 2+1] ; var r1 : OclAny := s[t + 1+1] ; var r2 : OclAny := s[t + 2+1] ; ans := ans + MatrixLib.elementwiseMult((MatrixLib.elementwiseAdd(p, 1)), ((idx - l1) * (r2 - r1) + (r1 - idx) * (l1 - l2)))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from decimal import Decimal,getcontext getcontext().prec=200 n,d,x=map(Decimal,input().split()) ans=0 for i in range(1,int(n)+1): i=Decimal(str(i)) ans+=Decimal(str((int(n)-int(i)+1)))/Decimal(str(i))*(d+x*Decimal(str(int(n)*2-1))/Decimal("2")) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; getcontext().prec := 200 ; var n : OclAny := null; var d : OclAny := null; var x : OclAny := null; Sequence{n,d,x} := (input().split())->collect( _x | (Decimal)->apply(_x) ) ; var ans : int := 0 ; for i : Integer.subrange(1, ("" + ((n)))->toInteger() + 1-1) do ( var i : OclAny := Decimal(("" + ((i)))) ; ans := ans + Decimal(("" + (((("" + ((n)))->toInteger() - ("" + ((i)))->toInteger() + 1))))) / Decimal(("" + ((i)))) * (d + x * Decimal(("" + ((("" + ((n)))->toInteger() * 2 - 1)))) / Decimal("2"))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n): digits=[] while n : digits.append(n % 10) n//=10 digits=list(reversed(digits)) ans=None for i in range(len(digits)): if i and digits[i]=digits[i-1]: if digits[i]-1==0 : ans=[9]*(len(digits)-1) else : ans=digits[: i]+[digits[i]-1]+[9]*(len(digits)-i-1) if i==len(digits)-1 : ans=digits return ''.join(map(str,ans)) def main(): ntest=int(input()) for i in range(ntest): n=int(input()) ans=solve(n) print("Case #%d: %s" %(i+1,ans)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(n : OclAny) : OclAny pre: true post: true activity: var digits : Sequence := Sequence{} ; while n do ( execute ((n mod 10) : digits) ; n := n div 10) ; digits := ((digits)->reverse()) ; var ans : OclAny := null ; for i : Integer.subrange(0, (digits)->size()-1) do ( if i & (digits[i+1]->compareTo(digits[i - 1+1])) < 0 then ( break ) else skip ; if i = 0 or (digits[i+1] - 1->compareTo(digits[i - 1+1])) >= 0 then ( if digits[i+1] - 1 = 0 then ( ans := MatrixLib.elementwiseMult(Sequence{ 9 }, ((digits)->size() - 1)) ) else ( ans := digits.subrange(1,i)->union(Sequence{ digits[i+1] - 1 })->union(MatrixLib.elementwiseMult(Sequence{ 9 }, ((digits)->size() - i - 1))) ) ) else skip ; if i = (digits)->size() - 1 then ( ans := digits ) else skip) ; return StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), ''); operation main() pre: true post: true activity: var ntest : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, ntest-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; ans := solve(n) ; execute (StringLib.format("Case #%d: %s",Sequence{i + 1, ans}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function import sys from sys import stdin def eprint(*args,**kwargs): print(*args,file=sys.stderr,**kwargs) def ln(f=int): return list(map(f,stdin.readline().strip().split())) T,=ln() INF=float('inf') for test in range(T): s,=ln(str) s=list(map(int,list(s))) prev=9 res="" ind=None for i in range(1,len(s)): if s[i]toReal() ; for test : Integer.subrange(0, T-1) do ((testlist_star_expr (test (logical_test (comparison (expr (atom (name s)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name s)))))) ,)} := ln(OclType["String"]) ; var s : Sequence := (((s))->collect( _x | (OclType["int"])->apply(_x) )) ; var prev : int := 9 ; var res : String := "" ; var ind : OclAny := null ; for i : Integer.subrange(1, (s)->size()-1) do ( if (s[i+1]->compareTo(s[i - 1+1])) < 0 then ( ind := i ; break ) else skip) ; if ind /= null then ( for i : Integer.subrange(ind + 1, (s)->size()-1) do ( s[i+1] := 9) ; while ind /= 0 & (s[ind+1]->compareTo(s[ind - 1+1])) < 0 do ( s[ind - 1+1] := s[ind - 1+1] - 1 ; s[ind+1] := 9 ; ind := ind - 1) ) else skip ; res := ("" + ((StringLib.sumStringsWithSeparator((((s)->collect( _x | (OclType["String"])->apply(_x) ))), ""))))->toInteger() ; execute ("Case #" + ("" + ((test + 1))) + ": " + ("" + ((res))))->display()); operation eprint(args : OclAny : Sequence(OclAny), kwargs : OclAny : Map(String, OclAny)) pre: true post: true activity: (args * (named_parameter (name args)))(kwargs ** (named_parameter (name kwargs))) execute ((argument * (test (logical_test (comparison (expr (atom (name args))))))))->display(); operation ln(f : OclAny) : OclAny pre: true post: true activity: if f->oclIsUndefined() then f := OclType["int"] else skip; return ((stdin.readLine()->trim().split())->collect( _x | (f)->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def to_int(l): out=0 for d in l : out=out*10+d return out def run_test(): n=int(input()) n=[int(c)for c in str(n)] assert len(n)>=1 start=0 for i in range(1,len(n)): if n[i]n[start]: start=i else : return to_int(n) for j in range(start+1,len(n)): n[j]=0 return to_int(n)-1 for i in range(1,int(input())+1): print("Case #{}:{}".format(i,run_test())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for i : Integer.subrange(1, ("" + (((OclFile["System.in"]).readLine())))->toInteger() + 1-1) do ( execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{i, run_test()}))->display()); operation to_int(l : OclAny) : OclAny pre: true post: true activity: var out : int := 0 ; for d : l do ( out := out * 10 + d) ; return out; operation run_test() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; n := ("" + ((n)))->select(c | true)->collect(c | (("" + ((c)))->toInteger())) ; assert (n)->size() >= 1 do "assertion failed" ; var start : int := 0 ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name n)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) < (comparison (expr (atom (name n)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name start)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt break)))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name n)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) > (comparison (expr (atom (name n)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name start)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name start)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name to_int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))))))) ; for j : Integer.subrange(start + 1, (n)->size()-1) do ( n[j+1] := 0) ; return to_int(n) - 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self): self.data=0 self.next=None first=None last=None length=0 def printList(node): while(node!=None): print(node.data,end=" ") node=node.next def moveToFront(head,p,m): global first global last global length if(head==None): return head p=head head=head.next m=m+1 if(length==m): p.next=None last.next=first first=head else : moveToFront(head,p,m) def push(head_ref,new_data): global first global last global length new_node=Node() new_node.data=new_data new_node.next=(head_ref) (head_ref)=new_node if(length==0): last=head_ref else : first=head_ref length=length+1 return head_ref start=None start=push(start,5) start=push(start,4) start=push(start,3) start=push(start,2) start=push(start,1) start=push(start,0) print("\n Initial Linked list") printList(start) m=4 temp=None moveToFront(start,temp,m) print("\n Final Linked list") start=first printList(start) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : int := 0; attribute next : OclAny := null; operation initialise() : Node pre: true post: true activity: self.data := 0 ; self.next := null; return self; } class FromPython { attribute first : OclAny; attribute last : OclAny; attribute length : OclAny; attribute first : OclAny; attribute last : OclAny; attribute length : OclAny; operation initialise() pre: true post: true activity: skip ; var first : OclAny := null ; var last : OclAny := null ; var length : int := 0 ; skip ; skip ; skip ; var (head_ref) : OclAny := new_node; operation printList(node : OclAny) pre: true post: true activity: while (node /= null) do ( execute (node.data)->display() ; node := node.next); operation moveToFront(head : OclAny, p : OclAny, m : OclAny) : OclAny pre: true post: true activity: skip ; skip ; skip ; if (head = null) then ( return head ) else skip ; p := head ; head := head.next ; m := m + 1 ; if (length = m) then ( p.next := null ; last.next := first ; first := head ) else ( moveToFront(head, p, m) ); operation push(head_ref : OclAny, new_data : OclAny) pre: true post: true activity: skip ; skip ; skip ; var new_node : Node := (Node.newNode()).initialise() ; new_node.data := new_data ; new_node.next := (head_ref); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count9s(number): count=0 n=len(number) for i in range(n): sum=ord(number[i])-ord('0') if(number[i]=='9'): count+=1 for j in range(i+1,n): sum=(sum+ord(number[j])-ord('0'))% 9 if(sum==0): count+=1 return count if __name__=="__main__" : print(count9s("4189")) print(count9s("1809")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (count9s("4189"))->display() ; execute (count9s("1809"))->display() ) else skip; operation count9s(number : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var n : int := (number)->size() ; for i : Integer.subrange(0, n-1) do ( var sum : double := (number[i+1])->char2byte() - ('0')->char2byte() ; if (number[i+1] = '9') then ( count := count + 1 ) else skip ; for j : Integer.subrange(i + 1, n-1) do ( sum := (sum + (number[j+1])->char2byte() - ('0')->char2byte()) mod 9 ; if (sum = 0) then ( count := count + 1 ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findExtra(arr1,arr2,n): index=n left=0 right=n-1 while(left<=right): mid=(int)((left+right)/2) if(arr2[mid]==arr1[mid]): left=mid+1 else : index=mid right=mid-1 return index arr1=[2,4,6,8,10,12,13] arr2=[2,4,6,8,10,12] n=len(arr2) print(findExtra(arr1,arr2,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr1 := Sequence{2}->union(Sequence{4}->union(Sequence{6}->union(Sequence{8}->union(Sequence{10}->union(Sequence{12}->union(Sequence{ 13 })))))) ; arr2 := Sequence{2}->union(Sequence{4}->union(Sequence{6}->union(Sequence{8}->union(Sequence{10}->union(Sequence{ 12 }))))) ; n := (arr2)->size() ; execute (findExtra(arr1, arr2, n))->display(); operation findExtra(arr1 : OclAny, arr2 : OclAny, n : OclAny) : OclAny pre: true post: true activity: var index : OclAny := n ; var left : int := 0 ; var right : double := n - 1 ; while ((left->compareTo(right)) <= 0) do ( var mid : OclAny := (OclType["int"])((left + right) / 2) ; if (arr2[mid+1] = arr1[mid+1]) then ( left := mid + 1 ) else ( index := mid ; right := mid - 1 )) ; return index; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def parallel(n,a): x=True ; y=True ; for i in range(n-1): for j in range(2): if(a[i][0]!=a[i+1][0]): x=False ; if(a[i][1]!=a[i+1][1]): y=False ; if(x): print("Parallel to X Axis"); elif(y): print("Parallel to Y Axis"); else : print("Not Parallel to X and Y Axis"); a=[[1,2],[1,4],[1,6],[1,0]]; n=len(a); parallel(n,a); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{Sequence{1}->union(Sequence{ 2 })}->union(Sequence{Sequence{1}->union(Sequence{ 4 })}->union(Sequence{Sequence{1}->union(Sequence{ 6 })}->union(Sequence{ Sequence{1}->union(Sequence{ 0 }) }))); ; n := (a)->size(); ; parallel(n, a);; operation parallel(n : OclAny, a : OclAny) pre: true post: true activity: var x : boolean := true; ; var y : boolean := true; ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(0, 2-1) do ( if (a[i+1]->first() /= a[i + 1+1]->first()) then ( x := false; ) else skip ; if (a[i+1][1+1] /= a[i + 1+1][1+1]) then ( y := false; ) else skip)) ; if (x) then ( execute ("Parallel to X Axis")->display(); ) else (if (y) then ( execute ("Parallel to Y Axis")->display(); ) else ( execute ("Not Parallel to X and Y Axis")->display(); ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for t in range(int(input())): n,m=map(int,input().split()) rows=[0]*n rindex={} for i in range(n): rows[i]=list(map(int,input().split())) rindex[rows[i][0]]=i c1=[] for i in range(m): col=list(map(int,input().split())) try : if rindex[col[0]]or True : c1=col except : pass for i in c1 : print(*rows[rindex[i]]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var rows : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var rindex : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( rows[i+1] := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; rindex[rows[i+1]->first()+1] := i) ; var c1 : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var col : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; try ( if rindex[col->first()+1] or true then ( c1 := col ) else skip) catch (_e : OclException) do ( skip) ) ; for i : c1 do ( execute ((argument * (test (logical_test (comparison (expr (atom (name rows)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name rindex)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ]))))))))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline t=int(input()) for _ in range(t): n,m=map(int,input().split()) row=[] col=[] for i in range(n): row.append(list(map(int,input().split()))) for i in range(m): col.append(list(map(int,input().split()))) for i in col[0]: for j in row : if i in j : print(*j) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var row : Sequence := Sequence{} ; var col : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : row)) ; for i : Integer.subrange(0, m-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : col)) ; for i : col->first() do ( for j : row do ( if (j)->includes(i) then ( execute ((argument * (test (logical_test (comparison (expr (atom (name j))))))))->display() ) else skip))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n,m=map(int,input().split()) r={} for i in range(n): l=list(map(int,input().split())) r[l[0]]=l c=l[0] for i in range(m): l=list(map(int,input().split())) if c in l : first=l for i in first : print(*r[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var r : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; r[l->first()+1] := l) ; var c : OclAny := l->first() ; for i : Integer.subrange(0, m-1) do ( l := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (l)->includes(c) then ( var first : Sequence := l ) else skip) ; for i : first do ( execute ((argument * (test (logical_test (comparison (expr (atom (name r)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) str1=input() str2=input() if str1==str2 : print('YES') else : for j in range(n): if str1[j]=='R' and str2[j]=='R' : continue elif str1[j]in('B','G')and str2[j]in('B','G'): continue else : print("NO") break else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var str1 : String := (OclFile["System.in"]).readLine() ; var str2 : String := (OclFile["System.in"]).readLine() ; if str1 = str2 then ( execute ('YES')->display() ) else ( (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name str1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) == (comparison (expr (atom 'R'))))) and (logical_test (comparison (comparison (expr (atom (name str2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) == (comparison (expr (atom 'R'))))))) : (suite (stmt (simple_stmt (small_stmt continue)))) (elif_clause elif (test (logical_test (logical_test (comparison (comparison (expr (atom (name str1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) in (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom 'B'))))) , (test (logical_test (comparison (expr (atom 'G')))))) )))))) and (logical_test (comparison (comparison (expr (atom (name str2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) in (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom 'B'))))) , (test (logical_test (comparison (expr (atom 'G')))))) )))))))) : (suite (stmt (simple_stmt (small_stmt continue))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) ))))))))))))))) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin if __name__=='__main__' : n=int(stdin.readline().rstrip()) p=list(map(int,stdin.readline().rstrip().split())) def get_nexts(p): d,e=[n for i in range(n)],[n for i in range(n)] stack1,stack2=[],[] for i in range(n): while stack2 and p[stack2[-1]]toInteger() ; var p : Sequence := ((stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; var dist1 : OclAny := null; var dist2 : OclAny := null; Sequence{dist1,dist2} := get_nexts(p) ; var dist3 : OclAny := null; var dist4 : OclAny := null; Sequence{dist3,dist4} := get_nexts(p(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( ans := ans + (dist1[i+1] * dist4[n - 1 - i+1] + dist2[i+1] * dist3[n - 1 - i+1]) * p[i+1]) ; execute (ans)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) d=dict() ans='' for i in range(t): n,m=map(int,input().split()) d.clear() a=[] for i in range(n): x=input().split() a.append(x) d[x[0]]=i c=False for j in range(m): x=input().split() if(not c)and(x[0]in d): c=True for y in x : ans+=' '.join(a[d[y]]) ans+='\n' print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Map := (arguments ( )) ; var ans : String := '' ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (d /<: d) ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := input().split() ; execute ((x) : a) ; d[x->first()+1] := i) ; var c : boolean := false ; for j : Integer.subrange(0, m-1) do ( x := input().split() ; if (not(c)) & ((d)->includes(x->first())) then ( c := true ; for y : x do ( ans := ans + StringLib.sumStringsWithSeparator((a[d[y+1]+1]), ' ') ; ans := ans + ' ') ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys for _ in range(int(input())): n,m=map(int,sys.stdin.readline().split()) d={} for i in range(n): m2=list(map(int,sys.stdin.readline().split())) d[m2[0]]=m2 for i in range(m): m1=list(map(int,sys.stdin.readline().split())) if m1[0]in d : m2=m1 for i in range(n): print(*d[m2[i]]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var m2 : Sequence := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; d[m2->first()+1] := m2) ; for i : Integer.subrange(0, m-1) do ( var m1 : Sequence := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (d)->includes(m1->first()) then ( m2 := m1 ) else skip) ; for i : Integer.subrange(0, n-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name m2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ]))))))))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countTriangles(a,n): cnt=0 pairs=0 for i in range(n-1,-1,-1): pairs+=a[i]//2 if(a[i]% 2==1 and pairs>0): cnt+=1 pairs-=1 cnt+=(2*pairs)//3 return cnt a=[1,2,2,2,2] n=len(a) print(countTriangles(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 2 })))) ; n := (a)->size() ; execute (countTriangles(a, n))->display(); operation countTriangles(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; var pairs : int := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( pairs := pairs + a[i+1] div 2 ; if (a[i+1] mod 2 = 1 & pairs > 0) then ( cnt := cnt + 1 ; pairs := pairs - 1 ) else skip) ; cnt := cnt + (2 * pairs) div 3 ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def maxXOR(arr): stack=deque() l=0 res1=0 for i in arr : while stack and stack[-1]1 : res1=max(res1,stack[-1]^ stack[-2]) res2=0 stack.clear() l=0 arr.reverse() for i in arr : while stack and stack[-1]1 : res2=max(res2,stack[-1]^ stack[-2]) return max(res1,res2) if __name__=="__main__" : arr=[9,8,3,5,7] print(maxXOR(arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{9}->union(Sequence{8}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 7 })))) ; execute (maxXOR(arr))->display() ) else skip; operation maxXOR(arr : OclAny) : OclAny pre: true post: true activity: var stack : Sequence := () ; var l : int := 0 ; var res1 : int := 0 ; for i : arr do ( while stack & (stack->last()->compareTo(i)) < 0 do ( stack := stack->front() ; l := l - 1) ; execute ((i) : stack) ; l := l + 1 ; if l > 1 then ( res1 := Set{res1, MathLib.bitwiseXor(stack->last(), stack->front()->last())}->max() ) else skip) ; var res2 : int := 0 ; execute (stack /<: stack) ; l := 0 ; arr := arr->reverse() ; for i : arr do ( while stack & (stack->last()->compareTo(i)) < 0 do ( stack := stack->front() ; l := l - 1) ; execute ((i) : stack) ; l := l + 1 ; if l > 1 then ( res2 := Set{res2, MathLib.bitwiseXor(stack->last(), stack->front()->last())}->max() ) else skip) ; return Set{res1, res2}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def asPowerSum(w,m): while(m>0): if((m-1)% w==0): m=(m-1)/w ; elif((m+1)% w==0): m=(m+1)/w ; elif(m % w==0): m=m/w ; else : break ; return(m==0); w=3 ; m=7 ; if(asPowerSum(w,m)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; w := 3; ; m := 7; ; if (asPowerSum(w, m)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ); operation asPowerSum(w : OclAny, m : OclAny) pre: true post: true activity: while (m > 0) do ( if ((m - 1) mod w = 0) then ( m := (m - 1) / w; ) else (if ((m + 1) mod w = 0) then ( m := (m + 1) / w; ) else (if (m mod w = 0) then ( m := m / w; ) else ( break; ) ) ) ) ; return (m = 0);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Graph : def __init__(self,V): self.V=V self.adj=[[]for i in range(V)] def addEdge(self,u,v): self.adj[u].append(v) self.adj[v].append(u) def countEdges(self): Sum=0 for i in range(self.V): Sum+=len(self.adj[i]) return Sum//2 if __name__=='__main__' : V=9 g=Graph(V) g.addEdge(0,1) g.addEdge(0,7) g.addEdge(1,2) g.addEdge(1,7) g.addEdge(2,3) g.addEdge(2,8) g.addEdge(2,5) g.addEdge(3,4) g.addEdge(3,5) g.addEdge(4,5) g.addEdge(5,6) g.addEdge(6,7) g.addEdge(6,8) g.addEdge(7,8) print(g.countEdges()) ------------------------------------------------------------ OCL File: --------- class Graph { static operation newGraph() : Graph pre: true post: Graph->exists( _x | result = _x ); attribute V : OclAny := V; attribute adj : Sequence := Integer.subrange(0, V-1)->select(i | true)->collect(i | (Sequence{})); operation initialise(V : OclAny) : Graph pre: true post: true activity: self.V := V ; self.adj := Integer.subrange(0, V-1)->select(i | true)->collect(i | (Sequence{})); return self; operation addEdge(u : OclAny,v : OclAny) pre: true post: true activity: (expr (atom (name self)) (trailer . (name adj) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) ; (expr (atom (name self)) (trailer . (name adj) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)))))))) )))); operation countEdges() : OclAny pre: true post: true activity: var Sum : int := 0 ; for i : Integer.subrange(0, self.V-1) do ( Sum := Sum + (self.adj[i+1])->size()) ; return Sum div 2; } class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( V := 9 ; var g : Graph := (Graph.newGraph()).initialise(V) ; g.addEdge(0, 1) ; g.addEdge(0, 7) ; g.addEdge(1, 2) ; g.addEdge(1, 7) ; g.addEdge(2, 3) ; g.addEdge(2, 8) ; g.addEdge(2, 5) ; g.addEdge(3, 4) ; g.addEdge(3, 5) ; g.addEdge(4, 5) ; g.addEdge(5, 6) ; g.addEdge(6, 7) ; g.addEdge(6, 8) ; g.addEdge(7, 8) ; execute (g.countEdges())->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findremainder(arr,lens,n): mul=1 for i in range(lens): mul=(mul*(arr[i]% n))% n return mul % n arr=[100,10,5,25,35,14] lens=len(arr) n=11 print(findremainder(arr,lens,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{100}->union(Sequence{10}->union(Sequence{5}->union(Sequence{25}->union(Sequence{35}->union(Sequence{ 14 }))))) ; lens := (arr)->size() ; n := 11 ; execute (findremainder(arr, lens, n))->display(); operation findremainder(arr : OclAny, lens : OclAny, n : OclAny) : OclAny pre: true post: true activity: var mul : int := 1 ; for i : Integer.subrange(0, lens-1) do ( mul := (mul * (arr[i+1] mod n)) mod n) ; return mul mod n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def xorEqualsOrCount(N): count=0 while(N>0): bit=N % 2 if bit==0 : count+=1 N//=2 return int(pow(2,count)) if __name__=="__main__" : N=7 print(xorEqualsOrCount(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := 7 ; execute (xorEqualsOrCount(N))->display() ) else skip; operation xorEqualsOrCount(N : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while (N > 0) do ( var bit : int := N mod 2 ; if bit = 0 then ( count := count + 1 ) else skip ; N := N div 2) ; return ("" + (((2)->pow(count))))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=input() for i in range(len(a)-len(b)+1): f=True for j in range(len(b)): if a[i+j]==b[j]: pass else : if b[j]=='_' : pass else : f=False break if f : print('Yes') exit() print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, (a)->size() - (b)->size() + 1-1) do ( var f : boolean := true ; for j : Integer.subrange(0, (b)->size()-1) do ( if a[i + j+1] = b[j+1] then ( skip ) else ( if b[j+1] = '_' then ( skip ) else ( f := false ; break ) )) ; if f then ( execute ('Yes')->display() ; exit() ) else skip) ; execute ('No')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines N,d,x=map(int,read().split()) def main(N,d,x): ret=0 while N : ret+=d+(N-0.5)*x d=d+(d/N)+(5*x)/(2*N) x+=2*x/N N-=1 return ret print(main(N,d,x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; var N : OclAny := null; var d : OclAny := null; var x : OclAny := null; Sequence{N,d,x} := (read().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; execute (main(N, d, x))->display(); operation main(N : OclAny, d : OclAny, x : OclAny) : OclAny pre: true post: true activity: var ret : int := 0 ; while N do ( ret := ret + d + (N - 0.5) * x ; d := d + (d / N) + (5 * x) / (2 * N) ; x := x + 2 * x / N ; N := N - 1) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re A=input() B=input() B=B.replace('_','.') if re.search(B,A): print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var A : String := (OclFile["System.in"]).readLine() ; var B : String := (OclFile["System.in"]).readLine() ; B := B.replace('_', '.') ; if (A)->firstMatch(B) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from heapq import heappush,heappop read=sys.stdin.read readline=sys.stdin.readline readlines=sys.stdin.readlines sys.setrecursionlimit(10**9) INF=1<<60 MOD=1000000007 def main(): N,*P=map(int,read().split()) idx=[0]*(N+1) for i,p in enumerate(P): idx[p]=i left=list(range(-1,N))+[-1] right=list(range(1,N+1))+[N,N] ans=0 for n in range(1,N+1): i=idx[n] l1=left[i] l2=left[l1] r1=right[i] r2=right[r1] ans+=n*((l1-l2)*(r1-i)+(r2-r1)*(i-l1)) left[r1]=l1 right[l1]=r1 print(ans) return if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var read : OclAny := (OclFile["System.in"]).read ; var readline : OclAny := (OclFile["System.in"]).readline ; var readlines : OclAny := (OclFile["System.in"]).readlines ; sys.setrecursionlimit((10)->pow(9)) ; var INF : int := 1 * (2->pow(60)) ; var MOD : int := 1000000007 ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var P : OclAny := null; Sequence{N,P} := (read().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var idx : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; for _tuple : Integer.subrange(1, (P)->size())->collect( _indx | Sequence{_indx-1, (P)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p : OclAny := _tuple->at(_indx); idx[p+1] := i) ; var left : Sequence := (Integer.subrange(-1, N-1))->union(Sequence{ -1 }) ; var right : Sequence := (Integer.subrange(1, N + 1-1))->union(Sequence{N}->union(Sequence{ N })) ; var ans : int := 0 ; for n : Integer.subrange(1, N + 1-1) do ( var i : OclAny := idx[n+1] ; var l1 : OclAny := left[i+1] ; var l2 : OclAny := left[l1+1] ; var r1 : OclAny := right[i+1] ; var r2 : OclAny := right[r1+1] ; ans := ans + n * ((l1 - l2) * (r1 - i) + (r2 - r1) * (i - l1)) ; left[r1+1] := l1 ; right[l1+1] := r1) ; execute (ans)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=input() length_a=len(a) length_b=len(b) def check(): for i in range(length_a-length_b+1): for j in range(length_b): if b[j]=="_" or a[i+j]==b[j]: continue else : break else : print("Yes") return print("No") return check() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var length_a : int := (a)->size() ; var length_b : int := (b)->size() ; skip ; check(); operation check() pre: true post: true activity: for i : Integer.subrange(0, length_a - length_b + 1-1) do ((compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name length_b)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) == (comparison (expr (atom "_"))))) or (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name j))))))))) ])))) == (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) : (suite (simple_stmt (small_stmt continue))) (else_clause else : (suite (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Yes"))))))) )))))))))))) (stmt (simple_stmt (small_stmt return))))))) ; execute ("No")->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def getValue(n): result=int(math.floor(math.log(n+1)/math.log(2))) return int(math.pow(2,result)) n=9 print(getValue(n)) n=1025 print(getValue(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 9 ; execute (getValue(n))->display() ; n := 1025 ; execute (getValue(n))->display(); operation getValue(n : OclAny) : OclAny pre: true post: true activity: var result : int := ("" + ((((n + 1)->log() / (2)->log())->floor())))->toInteger() ; return ("" + (((2)->pow(result))))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools import math k=int(input()) lis=[x for x in range(8)] permutations_lis=itertools.permutations(lis) ans=[] for zahyo in permutations_lis : ok=0 for i in range(7): for j in range(i+1,8): if abs(i-j)!=abs(zahyo[i]-zahyo[j]): ok+=1 else : break if ok==28 : ans.append(zahyo) input_zahyo=[-1]*8 for i in range(k): x,y=map(int,input().split()) input_zahyo[x]=y for zahyo in ans : ok=0 for j in range(8): if input_zahyo[j]!=-1 and zahyo[j]==input_zahyo[j]: ok+=1 if ok==k : for i in range(8): for j in range(8): if zahyo[i]==j : print("Q",end="") else : print(".",end="") print("") exit() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lis : Sequence := Integer.subrange(0, 8-1)->select(x | true)->collect(x | (x)) ; var permutations_lis : OclAny := itertools.permutations(lis) ; var ans : Sequence := Sequence{} ; for zahyo : permutations_lis do ( var ok : int := 0 ; for i : Integer.subrange(0, 7-1) do ( for j : Integer.subrange(i + 1, 8-1) do ( if (i - j)->abs() /= (zahyo[i+1] - zahyo[j+1])->abs() then ( ok := ok + 1 ) else ( break ))) ; if ok = 28 then ( execute ((zahyo) : ans) ) else skip) ; var input_zahyo : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, 8) ; for i : Integer.subrange(0, k-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; input_zahyo[x+1] := y) ; for zahyo : ans do ( ok := 0 ; for j : Integer.subrange(0, 8-1) do ( if input_zahyo[j+1] /= -1 & zahyo[j+1] = input_zahyo[j+1] then ( ok := ok + 1 ) else skip) ; if ok = k then ( for i : Integer.subrange(0, 8-1) do ( for j : Integer.subrange(0, 8-1) do ( if zahyo[i+1] = j then ( execute ("Q")->display() ) else ( execute (".")->display() )) ; execute ("")->display()) ; exit() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def put_queen(field,r,c): return field | 1<<(r*8+c) def check_queen(field,r,c): return field & 1<<(r*8+c) def view_field(field): for i in range(8): for j in range(8): print('Q' if check_queen(field,i,j)else '.',end='') print() def placeable(field,r,c): for i in range(8): if check_queen(field,r,i)or check_queen(field,i,c): return False if r>c : r1,c1=r-c,0 else : r1,c1=0,c-r if r>7-c : r2,c2=r-(7-c),7 else : r2,c2=0,c+r for i in range(8): if 0<=r1+i<8 and 0<=c1+i<8 and check_queen(field,r1+i,c1+i)or 0<=r2+i<8 and 0<=c2-i<8 and check_queen(field,r2+i,c2-i): return False return True def make_field(field,queen_num): if queen_num==8 : return field for i in range(8): for j in range(8): if placeable(field,i,j): solve_field=make_field(put_queen(field,i,j),queen_num+1) if not solve_field==2**64 : return solve_field return 2**64 k=int(input()) field=0 for i in range(k): r,c=map(int,input().split()) field=put_queen(field,r,c) view_field(make_field(field,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; field := 0 ; for i : Integer.subrange(0, k-1) do ( Sequence{r,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; field := put_queen(field, r, c)) ; view_field(make_field(field, k)); operation put_queen(field : OclAny, r : OclAny, c : OclAny) : OclAny pre: true post: true activity: return MathLib.bitwiseOr(field, 1 * (2->pow((r * 8 + c)))); operation check_queen(field : OclAny, r : OclAny, c : OclAny) : OclAny pre: true post: true activity: return MathLib.bitwiseAnd(field, 1 * (2->pow((r * 8 + c)))); operation view_field(field : OclAny) pre: true post: true activity: for i : Integer.subrange(0, 8-1) do ( for j : Integer.subrange(0, 8-1) do ( execute (if check_queen(field, i, j) then 'Q' else '.' endif)->display()) ; execute (->display()); operation placeable(field : OclAny, r : OclAny, c : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, 8-1) do ( if check_queen(field, r, i) or check_queen(field, i, c) then ( return false ) else skip) ; if (r->compareTo(c)) > 0 then ( var r1 : OclAny := null; var c1 : OclAny := null; Sequence{r1,c1} := Sequence{r - c,0} ) else ( var r1 : OclAny := null; var c1 : OclAny := null; Sequence{r1,c1} := Sequence{0,c - r} ) ; if (r->compareTo(7 - c)) > 0 then ( var r2 : OclAny := null; var c2 : OclAny := null; Sequence{r2,c2} := Sequence{r - (7 - c),7} ) else ( var r2 : OclAny := null; var c2 : OclAny := null; Sequence{r2,c2} := Sequence{0,c + r} ) ; for i : Integer.subrange(0, 8-1) do ( if 0 <= r1 + i & (r1 + i < 8) & 0 <= c1 + i & (c1 + i < 8) & check_queen(field, r1 + i, c1 + i) or 0 <= r2 + i & (r2 + i < 8) & 0 <= c2 - i & (c2 - i < 8) & check_queen(field, r2 + i, c2 - i) then ( return false ) else skip) ; return true; operation make_field(field : OclAny, queen_num : OclAny) : OclAny pre: true post: true activity: if queen_num = 8 then ( return field ) else skip ; for i : Integer.subrange(0, 8-1) do ( for j : Integer.subrange(0, 8-1) do ( if placeable(field, i, j) then ( var solve_field : OclAny := make_field(put_queen(field, i, j), queen_num + 1) ; if not(solve_field = (2)->pow(64)) then ( return solve_field ) else skip ) else skip)) ; return (2)->pow(64); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import time input=sys.stdin.readline FREE=True NOT_FREE=False num=int(input()) Q=[list(map(int,input().split()))for i in range(num)] row=[FREE]*8 col=[FREE]*8 dpos=[FREE]*15 dneg=[FREE]*15 chess_board=[['.' for i in range(8)]for j in range(8)] def printBoard(): for c in chess_board : print("".join(c)) def chess_init(): for q in Q : i=q[0] j=q[1] chess_board[i][j]='Q' row[i]=col[j]=dpos[i+j]=dneg[i-j+7]=NOT_FREE def putQueen(i): if(i==8): printBoard() return row_idx=0 for j in range(8): if(row[j]==FREE): row_idx=j break for j in range(8): if(col[j]==NOT_FREE or dpos[row_idx+j]==NOT_FREE or dneg[row_idx-j+7]==NOT_FREE): continue chess_board[row_idx][j]='Q' row[row_idx]=col[j]=dpos[row_idx+j]=dneg[row_idx-j+7]=NOT_FREE putQueen(i+1) chess_board[row_idx][j]='.' row[row_idx]=col[j]=dpos[row_idx+j]=dneg[row_idx-j+7]=FREE if __name__=="__main__" : chess_init() putQueen(num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var FREE : boolean := true ; var NOT_FREE : boolean := false ; var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var Q : Sequence := Integer.subrange(0, num-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var row : Sequence := MatrixLib.elementwiseMult(Sequence{ FREE }, 8) ; var col : Sequence := MatrixLib.elementwiseMult(Sequence{ FREE }, 8) ; var dpos : Sequence := MatrixLib.elementwiseMult(Sequence{ FREE }, 15) ; var dneg : Sequence := MatrixLib.elementwiseMult(Sequence{ FREE }, 15) ; var chess_board : Sequence := Integer.subrange(0, 8-1)->select(j | true)->collect(j | (Integer.subrange(0, 8-1)->select(i | true)->collect(i | ('.')))) ; skip ; skip ; skip ; if __name__ = "__main__" then ( chess_init() ; putQueen(num) ) else skip; operation printBoard() pre: true post: true activity: for c : chess_board do ( execute (StringLib.sumStringsWithSeparator((c), ""))->display()); operation chess_init() pre: true post: true activity: for q : Q do ( var i : OclAny := q->first() ; var j : OclAny := q[1+1] ; chess_board[i+1][j+1] := 'Q' ; row[i+1] := row[i+1](assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name col)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dpos)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name j))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dneg)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name i))) - (expr (atom (name j)))) + (expr (atom (number (integer 7)))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name NOT_FREE)))))))))); operation putQueen(i : OclAny) pre: true post: true activity: if (i = 8) then ( printBoard() ; return ) else skip ; var row_idx : int := 0 ; for j : Integer.subrange(0, 8-1) do ( if (row[j+1] = FREE) then ( row_idx := j ; break ) else skip) ; for j : Integer.subrange(0, 8-1) do ( if (col[j+1] = NOT_FREE or dpos[row_idx + j+1] = NOT_FREE or dneg[row_idx - j + 7+1] = NOT_FREE) then ( continue ) else skip ; chess_board[row_idx+1][j+1] := 'Q' ; row[row_idx+1] := row[row_idx+1](assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name col)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dpos)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name row_idx))) + (expr (atom (name j))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dneg)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name row_idx))) - (expr (atom (name j)))) + (expr (atom (number (integer 7)))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name NOT_FREE))))))))) ; putQueen(i + 1) ; chess_board[row_idx+1][j+1] := '.' ; row[row_idx+1] := row[row_idx+1](assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name col)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dpos)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name row_idx))) + (expr (atom (name j))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dneg)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name row_idx))) - (expr (atom (name j)))) + (expr (atom (number (integer 7)))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name FREE)))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import namedtuple position=namedtuple("position","row column") def input_queens(): queens=[] n=int(input()) for _ in range(n): row,column=[int(x)for x in input().split()] queens.append(position(row,column)) return queens def output_board(queens): for r in range(8): for c in range(8): print("Q" if position(r,c)in queens else ".",end="") print() def atackable(p,queens): return(p.row in[q.row for q in queens]or p.column in[q.column for q in queens]or any([abs(p.row-q.row)==abs(p.column-q.column)for q in queens])) def next_p(p): if p.column==7 : return position(p.row+1,0) else : return position(p.row,p.column+1) def over(p): return p.row>7 def all_queens(queens): def rec(p,queens): if len(queens)==8 : return queens elif over(p): return False elif atackable(p,queens): return rec(next_p(p),queens) else : result=rec(position(p.row+1,0),queens+[p]) return result if result else rec(next_p(p),queens) return rec(position(0,0),queens) queens=input_queens() output_board(all_queens(queens)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var position : OclAny := namedtuple("position", "row column") ; skip ; skip ; skip ; skip ; skip ; skip ; queens := input_queens() ; output_board(all_queens(queens)); operation input_queens() : OclAny pre: true post: true activity: var queens : Sequence := Sequence{} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var row : OclAny := null; var column : OclAny := null; Sequence{row,column} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((position(row, column)) : queens)) ; return queens; operation output_board(queens : OclAny) pre: true post: true activity: for r : Integer.subrange(0, 8-1) do ( for c : Integer.subrange(0, 8-1) do ( execute (if (queens)->includes(position(r, c)) then "Q" else "." endif)->display()) ; execute (->display()); operation atackable(p : OclAny, queens : OclAny) : OclAny pre: true post: true activity: return ((queens->select(q | true)->collect(q | (q.row)))->includes(p.row) or (queens->select(q | true)->collect(q | (q.column)))->includes(p.column) or (queens->select(q | true)->collect(q | ((p.row - q.row)->abs() = (p.column - q.column)->abs())))->exists( _x | _x = true )); operation next_p(p : OclAny) : OclAny pre: true post: true activity: if p.column = 7 then ( return position(p.row + 1, 0) ) else ( return position(p.row, p.column + 1) ); operation over(p : OclAny) : OclAny pre: true post: true activity: return p.row > 7; operation all_queens(queens : OclAny) : OclAny pre: true post: true activity: skip ; return rec(position(0, 0), queens); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy dirs=[[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]] def place(board,r,c): if board[r][c]!='.' : return False board[r][c]='Q' for d in dirs : rr=r+d[0] cc=c+d[1] while rr>=0 and rr<8 and cc>=0 and cc<8 : board[rr][cc]='x' rr+=d[0] cc+=d[1] return True def solve(board_): board=copy.deepcopy(board_) for r in range(8): for c in range(8): if place(board,r,c): tmp=solve(board) if tmp : return tmp else : board=copy.deepcopy(board_) if sum([row.count('Q')for row in board])==8 : return board def disp(board,clean=False): for row in board : if clean : row=['.' if i=='x' else i for i in row] print(''.join(row)) board=[['.']*8 for i in range(8)] N=int(input()) for _ in range(N): r,c=map(int,input().split()) place(board,r,c) board=solve(board) disp(board,True) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var dirs : Sequence := Sequence{Sequence{-1}->union(Sequence{ -1 })}->union(Sequence{Sequence{-1}->union(Sequence{ 0 })}->union(Sequence{Sequence{-1}->union(Sequence{ 1 })}->union(Sequence{Sequence{0}->union(Sequence{ -1 })}->union(Sequence{Sequence{0}->union(Sequence{ 1 })}->union(Sequence{Sequence{1}->union(Sequence{ -1 })}->union(Sequence{Sequence{1}->union(Sequence{ 0 })}->union(Sequence{ Sequence{1}->union(Sequence{ 1 }) }))))))) ; skip ; skip ; skip ; board := Integer.subrange(0, 8-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ '.' }, 8))) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, N-1) do ( Sequence{r,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; place(board, r, c)) ; board := solve(board) ; disp(board, true); operation place(board : OclAny, r : OclAny, c : OclAny) : OclAny pre: true post: true activity: if board[r+1][c+1] /= '.' then ( return false ) else skip ; board[r+1][c+1] := 'Q' ; for d : dirs do ( var rr : OclAny := r + d->first() ; var cc : OclAny := c + d[1+1] ; while rr >= 0 & rr < 8 & cc >= 0 & cc < 8 do ( board[rr+1][cc+1] := 'x' ; rr := rr + d->first() ; cc := cc + d[1+1])) ; return true; operation solve(board_ : OclAny) : OclAny pre: true post: true activity: board := copy.deepcopy(board_) ; for r : Integer.subrange(0, 8-1) do ( for c : Integer.subrange(0, 8-1) do ( if place(board, r, c) then ( var tmp : OclAny := solve(board) ; if tmp then ( return tmp ) else ( board := copy.deepcopy(board_) ) ) else skip)) ; if (board->select(row | true)->collect(row | (row->count('Q'))))->sum() = 8 then ( return board ) else skip; operation disp(board : OclAny, clean : OclAny) pre: true post: true activity: if clean->oclIsUndefined() then clean := false else skip; for row : board do ( if clean then ( var row : Sequence := row->select(i | true)->collect(i | (if i = 'x' then '.' else i endif)) ) else skip ; execute (StringLib.sumStringsWithSeparator((row), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countRec(digits,esum,osum,isOdd,n): if digits==n : return(esum-osum==1) if lookup[digits][esum][osum][isOdd]!=-1 : return lookup[digits][esum][osum][isOdd] ans=0 if isOdd : for i in range(10): ans+=countRec(digits+1,esum,osum+i,False,n) else : for i in range(10): ans+=countRec(digits+1,esum+i,osum,True,n) lookup[digits][esum][osum][isOdd]=ans return ans def finalCount(n): global lookup digits=0 lookup=[[[[-1,-1]for i in range(500)]for j in range(500)]for k in range(50)] ans=0 esum=0 osum=0 for i in range(1,10): ans+=countRec(digits+1,esum+i,osum,True,n) return ans if __name__=="__main__" : lookup=[] n=3 print("Count of %d digit numbers is %d" %(n,finalCount(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute lookup : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( lookup := Sequence{} ; n := 3 ; execute (StringLib.format("Count of %d digit numbers is %d",Sequence{n, finalCount(n)}))->display() ) else skip; operation countRec(digits : OclAny, esum : OclAny, osum : OclAny, isOdd : OclAny, n : OclAny) : OclAny pre: true post: true activity: if digits = n then ( return (esum - osum = 1) ) else skip ; if lookup[digits+1][esum+1][osum+1][isOdd+1] /= -1 then ( return lookup[digits+1][esum+1][osum+1][isOdd+1] ) else skip ; var ans : int := 0 ; if isOdd then ( for i : Integer.subrange(0, 10-1) do ( ans := ans + countRec(digits + 1, esum, osum + i, false, n)) ) else ( for i : Integer.subrange(0, 10-1) do ( ans := ans + countRec(digits + 1, esum + i, osum, true, n)) ) ; lookup[digits+1][esum+1][osum+1][isOdd+1] := ans ; return ans; operation finalCount(n : OclAny) : OclAny pre: true post: true activity: skip ; digits := 0 ; lookup := Integer.subrange(0, 50-1)->select(k | true)->collect(k | (Integer.subrange(0, 500-1)->select(j | true)->collect(j | (Integer.subrange(0, 500-1)->select(i | true)->collect(i | (Sequence{-1}->union(Sequence{ -1 }))))))) ; ans := 0 ; esum := 0 ; osum := 0 ; for i : Integer.subrange(1, 10-1) do ( ans := ans + countRec(digits + 1, esum + i, osum, true, n)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines N,D,X=map(int,read().split()) answer=0 for n in range(N,0,-1): mean=D+X*(n+n-1)/2 answer+=mean D=((n+n+2)*D+5*X)/(2*n) X=(n+2)*X/n print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; var N : OclAny := null; var D : OclAny := null; var X : OclAny := null; Sequence{N,D,X} := (read().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var answer : int := 0 ; for n : Integer.subrange(0 + 1, N)->reverse() do ( var mean : OclAny := D + X * (n + n - 1) / 2 ; answer := answer + mean ; var D : double := ((n + n + 2) * D + 5 * X) / (2 * n) ; var X : double := (n + 2) * X / n) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isCyclic(N): num=N count=0 digit=(num % 10) allSame=True while(num>0): count+=1 if(num % 10!=digit): allSame=False num=num//10 if(allSame==True): return False if(count % 2==0): halfPower=pow(10,count//2) firstHalf=N % halfPower secondHalf=N/halfPower if(firstHalf==firstHalf and isCyclic(firstHalf)): return False num=N while(True): rem=num % 10 div=num//10 num=pow(10,count-1)*rem+div if(num==N): break if(num % N!=0): return False return True N=142857 if(isCyclic(N)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 142857 ; if (isCyclic(N)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isCyclic(N : OclAny) : OclAny pre: true post: true activity: var num : OclAny := N ; var count : int := 0 ; var digit : int := (num mod 10) ; var allSame : boolean := true ; while (num > 0) do ( count := count + 1 ; if (num mod 10 /= digit) then ( allSame := false ) else skip ; num := num div 10) ; if (allSame = true) then ( return false ) else skip ; if (count mod 2 = 0) then ( var halfPower : double := (10)->pow(count div 2) ; var firstHalf : int := N mod halfPower ; var secondHalf : double := N / halfPower ; if (firstHalf = firstHalf & isCyclic(firstHalf)) then ( return false ) else skip ) else skip ; num := N ; while (true) do ( var rem : int := num mod 10 ; var div : int := num div 10 ; num := (10)->pow(count - 1) * rem + div ; if (num = N) then ( break ) else skip ; if (num mod N /= 0) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def subarrayPossible(arr,n): sum=0 ; for i in range(n): sum+=arr[i]; if(sum<=0): return True ; sum=0 ; for i in range(n-1,-1,-1): sum+=arr[i]; if(sum<=0): return True ; return False ; if __name__=='__main__' : arr=[10,5,-12,7,-10,20,30,-10,50,60]; size=len(arr); if(subarrayPossible(arr,size)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{10}->union(Sequence{5}->union(Sequence{-12}->union(Sequence{7}->union(Sequence{-10}->union(Sequence{20}->union(Sequence{30}->union(Sequence{-10}->union(Sequence{50}->union(Sequence{ 60 }))))))))); ; var size : int := (arr)->size(); ; if (subarrayPossible(arr, size)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ) else skip; operation subarrayPossible(arr : OclAny, n : OclAny) pre: true post: true activity: var sum : int := 0; ; for i : Integer.subrange(0, n-1) do ( sum := sum + arr[i+1]; ; if (sum <= 0) then ( return true; ) else skip) ; sum := 0; ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( sum := sum + arr[i+1]; ; if (sum <= 0) then ( return true; ) else skip) ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def BIT_add(i): while i<=N : tree[i]+=1 i+=i &(-i) def BIT_sum(i): s=0 while i : s+=tree[i] i-=i &(-i) return s def BIT_search(x): i=0 s=0 step=1<<(N.bit_length()-1) while step : if i+step<=N and s+tree[i+step]>=1 return i+1 import sys input=sys.stdin.readline sys.setrecursionlimit(10**7) N=int(input()) P=[None]+[int(x)for x in input().split()] p_to_i=[None]*(N+1) for i,x in enumerate(P[1 :],1): p_to_i[x]=i tree=[0]*(N+1) answer=0 for x in range(N,0,-1): c=p_to_i[x] L=BIT_sum(c) R=BIT_sum(N)-L BIT_add(c) a=BIT_search(L-1)if L>1 else 0 b=BIT_search(L)if L>0 else 0 d=BIT_search(L+2)if R>0 else N+1 e=BIT_search(L+3)if R>1 else N+1 coef=0 if b!=0 : coef+=(b-a)*(d-c) if d!=0 : coef+=(e-d)*(c-b) answer+=x*coef print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit((10)->pow(7)) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var P : Sequence := Sequence{ null }->union(input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) ; var p_to_i : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (N + 1)) ; for _tuple : Integer.subrange(1, (P->tail(), 1)->size())->collect( _indx | Sequence{_indx-1, (P->tail(), 1)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); p_to_i[x+1] := i) ; var tree : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; var answer : int := 0 ; for x : Integer.subrange(0 + 1, N)->reverse() do ( var c : OclAny := p_to_i[x+1] ; var L : OclAny := BIT_sum(c) ; var R : double := BIT_sum(N) - L ; BIT_add(c) ; var a : OclAny := if L > 1 then BIT_search(L - 1) else 0 endif ; var b : OclAny := if L > 0 then BIT_search(L) else 0 endif ; var d : OclAny := if R > 0 then BIT_search(L + 2) else N + 1 endif ; var e : OclAny := if R > 1 then BIT_search(L + 3) else N + 1 endif ; var coef : int := 0 ; if b /= 0 then ( coef := coef + (b - a) * (d - c) ) else skip ; if d /= 0 then ( coef := coef + (e - d) * (c - b) ) else skip ; answer := answer + x * coef) ; execute (answer)->display(); operation BIT_add(i : OclAny) pre: true post: true activity: while (i->compareTo(N)) <= 0 do ( tree[i+1] := tree[i+1] + 1 ; i := i + MathLib.bitwiseAnd(i, (-i))); operation BIT_sum(i : OclAny) : OclAny pre: true post: true activity: var s : int := 0 ; while i do ( s := s + tree[i+1] ; i := i - MathLib.bitwiseAnd(i, (-i))) ; return s; operation BIT_search(x : OclAny) : OclAny pre: true post: true activity: i := 0 ; s := 0 ; var step : int := 1 * (2->pow((N.bit_length() - 1))) ; while step do ( if (i + step->compareTo(N)) <= 0 & (s + tree[i + step+1]->compareTo(x)) < 0 then ( i := i + step ; s := s + tree[i+1] ) else skip ; step := step div (2->pow(1))) ; return i + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def s(): n=int(input())+1 e=[input().split()for _ in[0]*~-n] p=[int(e[0][0])]+list(int(x[1])for x in e) m=[[0]*n for _ in[0]*n] for i in range(n): for r in range(n-i-1): c=r+i+1 for j in range(r+1,c): x=m[r][j]+m[j][c]+p[r]*p[j]*p[c] if not 0toInteger() + 1 ; var e : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MathLib.bitwiseNot(-n))->select(_anon | true)->collect(_anon | (input().split())) ; var p : Sequence := Sequence{ ("" + ((e->first()->first())))->toInteger() }->union(((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name e))))))))) ; var m : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, n))) ; for i : Integer.subrange(0, n-1) do ( for r : Integer.subrange(0, n - i - 1-1) do ( var c : OclAny := r + i + 1 ; for j : Integer.subrange(r + 1, c-1) do ( var x : OclAny := m[r+1][j+1] + m[j+1][c+1] + p[r+1] * p[j+1] * p[c+1] ; if not(0 < m[r+1][c+1] & (m[r+1][c+1] <= x)) then ( m[r+1][c+1] := x ) else skip))) ; execute (m[r+1][c+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import division,print_function from sys import stdin def main(): num_mat=int(stdin.readline()) r=[int(s)for s in stdin.readline().split()] for _ in range(num_mat-1): _,row=(int(s)for s in stdin.readline().split()) r.append(row) if num_mat<2 : print(0) return elif num_mat<3 : print(r[0]*r[1]*r[2]) return M=[] M.append([0]*num_mat) M.append([r[i]*r[i+1]*r[i+2]for i in range(len(M[-1])-1)]) for i in range(2,num_mat): N=[] for j in range(num_mat-i): N.append(min(M[k][j]+M[i-1-k][1+j+k]+r[j]*r[1+j+k]*r[i+1+j]for k in range(i))) M.append(N) print(M[-1][0]) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; main(); operation main() pre: true post: true activity: var num_mat : int := ("" + ((stdin.readLine())))->toInteger() ; var r : Sequence := stdin.readLine().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; for _anon : Integer.subrange(0, num_mat - 1-1) do ( var _anon : OclAny := null; var row : OclAny := null; Sequence{_anon,row} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name stdin)) (trailer . (name readline) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; execute ((row) : r)) ; if num_mat < 2 then ( execute (0)->display() ; return ) else (if num_mat < 3 then ( execute (r->first() * r[1+1] * r[2+1])->display() ; return ) else skip) ; var M : Sequence := Sequence{} ; execute ((MatrixLib.elementwiseMult(Sequence{ 0 }, num_mat)) : M) ; execute ((Integer.subrange(0, (M->last())->size() - 1-1)->select(i | true)->collect(i | (r[i+1] * r[i + 1+1] * r[i + 2+1]))) : M) ; for i : Integer.subrange(2, num_mat-1) do ( var N : Sequence := Sequence{} ; for j : Integer.subrange(0, num_mat - i-1) do ( execute ((((argument (test (logical_test (comparison (expr (expr (expr (atom (name M)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))) + (expr (atom (name M)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name i))) - (expr (atom (number (integer 1))))) - (expr (atom (name k))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (number (integer 1)))) + (expr (atom (name j)))) + (expr (atom (name k))))))))) ])))) + (expr (expr (expr (atom (name r)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))) * (expr (atom (name r)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (number (integer 1)))) + (expr (atom (name j)))) + (expr (atom (name k))))))))) ])))) * (expr (atom (name r)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))) + (expr (atom (name j))))))))) ])))))))) (comp_for for (exprlist (expr (atom (name k)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))->min()) : N)) ; execute ((N) : M)) ; execute (M->last()->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys p=[0 for i in range(101)] m=[[0 for i in range(100)]for i in range(100)] def MatrixChain(n): for i in range(1,n+1): m[i][i]=0 ; for l in range(2,n+1): for i in range(1,n-l+2): j=i+l-1 m[i][j]=float('Infinity') for k in range(i,j): q=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j] m[i][j]=m[i][j]if m[i][j]<=q else q n=int(input()) for i in range(n): p[i],p[i+1]=map(int,input().split()) MatrixChain(n) print(m[1][n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var p : Sequence := Integer.subrange(0, 101-1)->select(i | true)->collect(i | (0)) ; var m : Sequence := Integer.subrange(0, 100-1)->select(i | true)->collect(i | (Integer.subrange(0, 100-1)->select(i | true)->collect(i | (0)))) ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var p[i+1] : OclAny := null; var p[i + 1+1] : OclAny := null; Sequence{p[i+1],p[i + 1+1]} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; MatrixChain(n) ; execute (m[1+1][n+1])->display(); operation MatrixChain(n : OclAny) pre: true post: true activity: for i : Integer.subrange(1, n + 1-1) do ( m[i+1][i+1] := 0;) ; for l : Integer.subrange(2, n + 1-1) do ( for i : Integer.subrange(1, n - l + 2-1) do ( var j : double := i + l - 1 ; m[i+1][j+1] := ("" + (('Infinity')))->toReal() ; for k : Integer.subrange(i, j-1) do ( var q : OclAny := m[i+1][k+1] + m[k + 1+1][j+1] + p[i - 1+1] * p[k+1] * p[j+1] ; m[i+1][j+1] := if (m[i+1][j+1]->compareTo(q)) <= 0 then m[i+1][j+1] else q endif))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def mat_mul_opt(_mat_info): rc_info=list(map(int,_mat_info[0])) rc_info.extend(list(map(lambda x : int(x[1]),_mat_info[1 :]))) for l in range(2,mat_num+1): for i in range(1,mat_num-l+2): j=i+l-1 ans[i][j]=1e7 for k in range(i,j): ans[i][j]=min(ans[i][j],ans[i][k]+ans[k+1][j]+rc_info[i-1]*rc_info[k]*rc_info[j]) return ans[1][mat_num] if __name__=='__main__' : _input=sys.stdin.readlines() mat_num=int(_input[0]) mat_info=tuple(map(lambda x : x.split(),_input[1 :])) ans=[[0]*(mat_num+1)for _ in range(mat_num+1)] print(mat_mul_opt(mat_info)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var _input : OclAny := (OclFile["System.in"]).readlines() ; var mat_num : int := ("" + ((_input->first())))->toInteger() ; var mat_info : Sequence := ((_input->tail())->collect( _x | (lambda x : OclAny in (x.split()))->apply(_x) )) ; var ans : Sequence := Integer.subrange(0, mat_num + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (mat_num + 1)))) ; execute (mat_mul_opt(mat_info))->display() ) else skip; operation mat_mul_opt(_mat_info : OclAny) : OclAny pre: true post: true activity: var rc_info : Sequence := ((_mat_info->first())->collect( _x | (OclType["int"])->apply(_x) )) ; rc_info := rc_info->union(((_mat_info->tail())->collect( _x | (lambda x : OclAny in (("" + ((x[1+1])))->toInteger()))->apply(_x) ))) ; for l : Integer.subrange(2, mat_num + 1-1) do ( for i : Integer.subrange(1, mat_num - l + 2-1) do ( var j : double := i + l - 1 ; ans[i+1][j+1] := ("1e7")->toReal() ; for k : Integer.subrange(i, j-1) do ( ans[i+1][j+1] := Set{ans[i+1][j+1], ans[i+1][k+1] + ans[k + 1+1][j+1] + rc_info[i - 1+1] * rc_info[k+1] * rc_info[j+1]}->min()))) ; return ans[1+1][mat_num+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) int1=lambda x : int(x)-1 p2D=lambda x : print(*x,sep="\n") def main(): def get_cost(l,r): if r-l==1 : return 0 if r-l==2 : return rc[l][0]*rc[r-1][0]*rc[r-1][1] if cost[l][r]!=-1 : return cost[l][r] res=cost[l][r]=min(get_cost(l,m)+get_cost(m,r)+rc[l][0]*rc[m][0]*rc[r-1][1]for m in range(l+1,r)) return res n=int(input()) rc=[list(map(int,input().split()))for _ in range(n)] cost=[[-1]*(n+1)for _ in range(n)] print(get_cost(0,n)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; var p2D : Function := lambda x : OclAny in (((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ; skip ; main(); operation main() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var rc : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var cost : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ -1 }, (n + 1)))) ; execute (get_cost(0, n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def tre_str(): a=input() b=input() c=input() l=len(a) m=len(b) n=len(c) p=l=m=n i=0 while i

toInteger() ; for i : Integer.subrange(0, test-1) do ( execute (tre_str())->display()); operation tre_str() : OclAny pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var c : String := (OclFile["System.in"]).readLine() ; var l : int := (a)->size() ; var m : int := (b)->size() ; var n : int := (c)->size() ; p := p(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name m)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name n))))))))) ; var i : int := 0 ; while (i->compareTo(p)) < 0 do ( if a[i+1] /= c[i+1] & b[i+1] /= c[i+1] then ( return ("NO") ) else skip ; i := i + 1) ; return ("YES"); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : a=list(input()) b=list(input()) c=list(input()) for i in range(len(a)): if c[i]==b[i]: a[i]=c[i] elif c[i]==a[i]: b[i]=c[i] else : a[i]=c[i] if a==b : print('YES') else : print('NO') t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( var a : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var b : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var c : Sequence := ((OclFile["System.in"]).readLine())->characters() ; for i : Integer.subrange(0, (a)->size()-1) do ( if c[i+1] = b[i+1] then ( a[i+1] := c[i+1] ) else (if c[i+1] = a[i+1] then ( b[i+1] := c[i+1] ) else ( a[i+1] := c[i+1] ) ) ) ; if a = b then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) for i in range(1,n+1): if i in a : print('1') else : print('2') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(1, n + 1-1) do ( if (a)->includes(i) then ( execute ('1')->display() ) else ( execute ('2')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,D,X=map(int,input().split()) x=.5 for n in range(2,N+1): x+=.5+x/n answer=x*(2*D+X*(2*N-1)) print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var D : OclAny := null; var X : OclAny := null; Sequence{N,D,X} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : double := .5 ; for n : Integer.subrange(2, N + 1-1) do ( x := x + .5 + x / n) ; var answer : double := x * (2 * D + X * (2 * N - 1)) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : a=input() b=input() c=input() ans=0 for i in range(len(a)): if a[i]==c[i]or b[i]==c[i]: ans+=1 if ans==len(a): print('YES') else : print('NO') t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var c : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( if a[i+1] = c[i+1] or b[i+1] = c[i+1] then ( ans := ans + 1 ) else skip) ; if ans = (a)->size() then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): a=list(input()) b=list(input()) c=list(input()) for i in range(len(a)): if a[i]!=c[i]and b[i]!=c[i]: print("NO") break else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var b : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var c : Sequence := ((OclFile["System.in"]).readLine())->characters() ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) != (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))) and (logical_test (comparison (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) != (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def tre_str(): a=input() b=input() c=input() l=len(a) m=len(b) n=len(c) p=l=m=n i=0 while i

toInteger() ; for i : Integer.subrange(0, test-1) do ( execute (tre_str())->display()); operation tre_str() : OclAny pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var c : String := (OclFile["System.in"]).readLine() ; var l : int := (a)->size() ; var m : int := (b)->size() ; var n : int := (c)->size() ; p := p(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name m)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name n))))))))) ; var i : int := 0 ; while (i->compareTo(p)) < 0 do ( if a[i+1] /= c[i+1] & b[i+1] /= c[i+1] then ( return ("NO") ) else skip ; i := i + 1) ; return ("YES"); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) P=list(map(int,input().split())) I=[0]*N for i in range(N): I[P[i]-1]=i ans=0 L=[i for i in range(-1,N-1)] R=[i for i in range(1,N+1)] for p in range(1,N+1): i=I[p-1] if R[i]=0 : R[L[i]]=R[i] l1=L[i] l2=L[l1]if l1>=0 else-1 r1=R[i] r2=R[r1]if r1toInteger() ; var P : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var I : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for i : Integer.subrange(0, N-1) do ( I[P[i+1] - 1+1] := i) ; var ans : int := 0 ; var L : Sequence := Integer.subrange(-1, N - 1-1)->select(i | true)->collect(i | (i)) ; var R : Sequence := Integer.subrange(1, N + 1-1)->select(i | true)->collect(i | (i)) ; for p : Integer.subrange(1, N + 1-1) do ( var i : OclAny := I[p - 1+1] ; if (R[i+1]->compareTo(N)) < 0 then ( L[R[i+1]+1] := L[i+1] ) else skip ; if L[i+1] >= 0 then ( R[L[i+1]+1] := R[i+1] ) else skip ; var l1 : OclAny := L[i+1] ; var l2 : OclAny := if l1 >= 0 then L[l1+1] else -1 endif ; var r1 : String := R[i+1] ; var r2 : String := if r1 < N then R->at(r1) else N endif ; ans := ans + p * ((r1 - i) * (l1 - l2) + (i - l1) * (r2 - r1))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cola=2 rowa=3 colb=3 rowb=2 def Kroneckerproduct(A,B): C=[[0 for j in range(cola*colb)]for i in range(rowa*rowb)] for i in range(0,rowa): for k in range(0,rowb): for j in range(0,cola): for l in range(0,colb): C[i+l+1][j+k+1]=A[i][j]*B[k][l] print(C[i+l+1][j+k+1],end=' ') print("\n") A=[[0 for j in range(2)]for i in range(3)] B=[[0 for j in range(3)]for i in range(2)] A[0][0]=1 A[0][1]=2 A[1][0]=3 A[1][1]=4 A[2][0]=1 A[2][1]=0 B[0][0]=0 B[0][1]=5 B[0][2]=2 B[1][0]=6 B[1][1]=7 B[1][2]=3 Kroneckerproduct(A,B) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cola : int := 2 ; var rowa : int := 3 ; var colb : int := 3 ; var rowb : int := 2 ; skip ; A := Integer.subrange(0, 3-1)->select(i | true)->collect(i | (Integer.subrange(0, 2-1)->select(j | true)->collect(j | (0)))) ; B := Integer.subrange(0, 2-1)->select(i | true)->collect(i | (Integer.subrange(0, 3-1)->select(j | true)->collect(j | (0)))) ; A->first()->first() := 1 ; A->first()[1+1] := 2 ; A[1+1]->first() := 3 ; A[1+1][1+1] := 4 ; A[2+1]->first() := 1 ; A[2+1][1+1] := 0 ; B->first()->first() := 0 ; B->first()[1+1] := 5 ; B->first()[2+1] := 2 ; B[1+1]->first() := 6 ; B[1+1][1+1] := 7 ; B[1+1][2+1] := 3 ; Kroneckerproduct(A, B); operation Kroneckerproduct(A : OclAny, B : OclAny) pre: true post: true activity: var C : Sequence := Integer.subrange(0, rowa * rowb-1)->select(i | true)->collect(i | (Integer.subrange(0, cola * colb-1)->select(j | true)->collect(j | (0)))) ; for i : Integer.subrange(0, rowa-1) do ( for k : Integer.subrange(0, rowb-1) do ( for j : Integer.subrange(0, cola-1) do ( for l : Integer.subrange(0, colb-1) do ( C[i + l + 1+1][j + k + 1+1] := A[i+1][j+1] * B[k+1][l+1] ; execute (C[i + l + 1+1][j + k + 1+1])->display())) ; execute ("\n")->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _MIN=-2147483648 _MAX=2147483648 class newNode : def __init__(self,data): self.data=data self.left=None self.right=None def closestNodeUsingMorrisTraversal(root,key): diff=_MAX curr=root closest=0 while(curr): if(curr.left==None): if(diff>abs(curr.data-key)): diff=abs(curr.data-key) closest=curr curr=curr.right else : pre=curr.left while(pre.right!=None and pre.right!=curr): pre=pre.right if(pre.right==None): pre.right=curr curr=curr.left else : pre.right=None if(diff>abs(curr.data-key)): diff=abs(curr.data-key) closest=curr curr=curr.right return closest if __name__=='__main__' : root=newNode(5) root.left=newNode(3) root.right=newNode(9) root.left.right=newNode(2) root.left.left=newNode(1) root.right.right=newNode(12) root.right.left=newNode(8) print(closestNodeUsingMorrisTraversal(root,10).data) ------------------------------------------------------------ OCL File: --------- class newNode { static operation newnewNode() : newNode pre: true post: newNode->exists( _x | result = _x ); attribute data : OclAny := data; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(data : OclAny) : newNode pre: true post: true activity: self.data := data ; self.left := null ; self.right := null; return self; } class FromPython { operation initialise() pre: true post: true activity: var _MIN : int := -2147483648 ; var _MAX : int := 2147483648 ; skip ; skip ; if __name__ = '__main__' then ( root := (newNode.newnewNode()).initialise(5) ; root.left := (newNode.newnewNode()).initialise(3) ; root.right := (newNode.newnewNode()).initialise(9) ; root.left.right := (newNode.newnewNode()).initialise(2) ; root.left.left := (newNode.newnewNode()).initialise(1) ; root.right.right := (newNode.newnewNode()).initialise(12) ; root.right.left := (newNode.newnewNode()).initialise(8) ; execute (closestNodeUsingMorrisTraversal(root, 10).data)->display() ) else skip; operation closestNodeUsingMorrisTraversal(root : OclAny, key : OclAny) : OclAny pre: true post: true activity: var diff : int := _MAX ; var curr : OclAny := root ; var closest : int := 0 ; while (curr) do ( if (curr.left = null) then ( if ((diff->compareTo((curr.data - key)->abs())) > 0) then ( diff := (curr.data - key)->abs() ; closest := curr ) else skip ; curr := curr.right ) else ( var pre : OclAny := curr.left ; while (pre.right /= null & pre.right /= curr) do ( pre := pre.right) ; if (pre.right = null) then ( pre.right := curr ; curr := curr.left ) else ( pre.right := null ; if ((diff->compareTo((curr.data - key)->abs())) > 0) then ( diff := (curr.data - key)->abs() ; closest := curr ) else skip ; curr := curr.right ) )) ; return closest; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=100 digitSum=[0]*N factorDigitSum=[0]*N def sumOddDigit(): global N,digitSum,factorDigitSum for i in range(1,N): digitSum[i]=(digitSum[int(i/10)]+int(i & 1)*(i % 10)) def sumFactor(): global N,digitSum,factorDigitSum j=0 for i in range(1,N): j=i while(junion(Sequence{ 36 }) ; wrapper(q, n); operation sumOddDigit() pre: true post: true activity: skip; skip; skip ; for i : Integer.subrange(1, N-1) do ( digitSum[i+1] := (digitSum[("" + ((i / 10)))->toInteger()+1] + ("" + ((MathLib.bitwiseAnd(i, 1))))->toInteger() * (i mod 10))); operation sumFactor() pre: true post: true activity: skip; skip; skip ; var j : int := 0 ; for i : Integer.subrange(1, N-1) do ( j := i ; while ((j->compareTo(N)) < 0) do ( factorDigitSum[j+1] := (factorDigitSum[j+1] + digitSum[i+1]) ; j := j + i)); operation wrapper(q : OclAny, n : OclAny) pre: true post: true activity: skip; skip; skip ; for i : Integer.subrange(0, N-1) do ( digitSum[i+1] := 0 ; factorDigitSum[i+1] := 0) ; sumOddDigit() ; sumFactor() ; for i : Integer.subrange(0, q-1) do ( execute (StringLib.interpolateStrings("{}", Sequence{factorDigitSum[n[i+1]+1]}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def squareRoot(n): return pow(2,0.5*math.log2(n)) n=12 print(squareRoot(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 12 ; execute (squareRoot(n))->display(); operation squareRoot(n : OclAny) : OclAny pre: true post: true activity: return (2)->pow(0.5 * ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def highestPowerof2(n): p=int(math.log(n,2)); return int(pow(2,p)); n=10 ; print(highestPowerof2(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 10; ; execute (highestPowerof2(n))->display();; operation highestPowerof2(n : OclAny) pre: true post: true activity: var p : int := ("" + (((n, 2)->log())))->toInteger(); ; return ("" + (((2)->pow(p))))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPaths(m,n): dp=[[0 for i in range(m+1)]for j in range(n+1)] for i in range(1,m+1): for j in range(1,n+1): if(i==1 or j==1): dp[i][j]=1 else : dp[i][j]=(dp[i-1][j]+dp[i][j-1]) return dp[m][n] if __name__=="__main__" : n=5 m=5 print(countPaths(n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 5 ; m := 5 ; execute (countPaths(n, m))->display() ) else skip; operation countPaths(m : OclAny, n : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, m + 1-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(1, m + 1-1) do ( for j : Integer.subrange(1, n + 1-1) do ( if (i = 1 or j = 1) then ( dp[i+1][j+1] := 1 ) else ( dp[i+1][j+1] := (dp[i - 1+1][j+1] + dp[i+1][j - 1+1]) ))) ; return dp[m+1][n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,d,x): ans=0 while n : ans+=d+(2*n-1)*x/2 d=((n+1)*d+5*x/2)/n x*=(n+2)/n n-=1 return ans print('{:.10f}'.format(solve(*map(float,input().split())))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (StringLib.interpolateStrings('{:.10f}', Sequence{solve((argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name float))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))))))}))->display(); operation solve(n : OclAny, d : OclAny, x : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; while n do ( ans := ans + d + (2 * n - 1) * x / 2 ; d := ((n + 1) * d + 5 * x / 2) / n ; x := x * (n + 2) / n ; n := n - 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np arrSize=51 maxSum=201 MAX=100 inf=999999 dp=np.zeros((arrSize,maxSum)); visit=np.zeros((arrSize,maxSum)); def RetClose(a,b,s): if(abs(a-s)union(Sequence{-9}->union(Sequence{-10}->union(Sequence{-4}->union(Sequence{-7}->union(Sequence{ -33 }))))); ; n := (arr)->size(); ; FindClose(arr, n); ) else skip; operation RetClose(a : OclAny, b : OclAny, s : OclAny) pre: true post: true activity: if (((a - s)->abs()->compareTo((b - s)->abs())) < 0) then ( return a; ) else ( return b; ); operation MinDiff(i : OclAny, sum : OclAny, arr : OclAny, n : OclAny) pre: true post: true activity: if (i = n) then ( return 0; ) else skip ; if (visit[i+1][sum + MAX+1]) then ( return dp[i+1][sum + MAX+1]; ) else skip ; visit[i+1][sum + MAX+1] := 1; ; dp[i+1][sum + MAX+1] := RetClose(arr[i+1] + MinDiff(i + 1, sum + arr[i+1], arr, n), MinDiff(i + 1, sum, arr, n), -1 * sum); ; return dp[i+1][sum + MAX+1];; operation FindClose(arr : OclAny, n : OclAny) pre: true post: true activity: var ans : int := Math_PINFINITY; ; for i : Integer.subrange(1, n + 1-1) do ( ans := RetClose(arr[i - 1+1] + MinDiff(i, arr[i - 1+1], arr, n), ans, 0);) ; execute (ans)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def hasCrest(arr,n,L,R): present=[0]*n ; for i in range(1,n-2+1): if((arr[i]<=arr[i+1])and(arr[i]<=arr[i-1])): present[i]=1 ; for i in range(1,n): present[i]+=present[i-1]; if(present[L]==present[R-1]): return True ; return False ; if __name__=="__main__" : arr=[2,1,3,5,12,11,7,9]; N=len(arr); L=2 ; R=6 ; if(hasCrest(arr,N,L,R)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{2}->union(Sequence{1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{12}->union(Sequence{11}->union(Sequence{7}->union(Sequence{ 9 }))))))); ; var N : int := (arr)->size(); ; L := 2; ; R := 6; ; if (hasCrest(arr, N, L, R)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ) else skip; operation hasCrest(arr : OclAny, n : OclAny, L : OclAny, R : OclAny) pre: true post: true activity: var present : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; for i : Integer.subrange(1, n - 2 + 1-1) do ( if (((arr[i+1]->compareTo(arr[i + 1+1])) <= 0) & ((arr[i+1]->compareTo(arr[i - 1+1])) <= 0)) then ( present[i+1] := 1; ) else skip) ; for i : Integer.subrange(1, n-1) do ( present[i+1] := present[i+1] + present[i - 1+1];) ; if (present[L+1] = present[R - 1+1]) then ( return true; ) else skip ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSquares(m,n): if(ndisplay() ) else skip; operation countSquares(m : OclAny, n : OclAny) : OclAny pre: true post: true activity: if ((n->compareTo(m)) < 0) then ( var temp : OclAny := m ; m := n ; n := temp ) else skip ; return n * (n + 1) * (3 * m - n + 1) div 6; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import division,print_function import cmath import itertools import math import operator as op import sys from atexit import register from bisect import bisect_left,bisect_right if sys.version_info[0]<3 : from io import BytesIO as stream else : from io import StringIO as stream from math import gcd if sys.version_info[0]<3 : class dict(dict): def items(self): return dict.iteritems(self) def keys(self): return dict.iterkeys(self) def values(self): return dict.itervalues(self) def gcd(x,y): while y : x,y=y,x % y return x input=raw_input range=xrange filter=itertools.ifilter map=itertools.imap zip=itertools.izip def sync_with_stdio(sync=True): global input,flush if sync : flush=sys.stdout.flush else : sys.stdin=stream(sys.stdin.read()) input=lambda : sys.stdin.readline().rstrip('\n') sys.stdout=stream() register(lambda : sys.__stdout__.write(sys.stdout.getvalue())) def helper(n): return((2*pow(-1,n)*n)+pow(-1,n)-1)//4 def main(): q=int(input()) for i in range(q): l,r=map(int,input().split(' ')) print(helper(r)-helper(l-1)) if __name__=='__main__' : sync_with_stdio(False) main() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute input : OclAny; attribute flush : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if (trailer . (name version_info) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) < 3 then ( skip ) else ( skip ; skip ) ; if (trailer . (name version_info) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) < 3 then ( skip ; skip ; var input : OclAny := raw_input ; var range : OclAny := xrange ; var filter : OclAny := itertools.ifilter ; var map : OclAny := itertools.imap ; var zip : OclAny := itertools.izip ) else skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( sync_with_stdio(false) ; main() ) else skip; operation sync_with_stdio(sync : OclAny) pre: true post: true activity: if sync->oclIsUndefined() then sync := true else skip; skip; skip ; if sync then ( flush := (OclFile["System.out"]).flush ) else ( OclFile["System.in"] := stream((OclFile["System.in"]).readAll()) ; input := lambda $$ : OclAny in (sys.stdin.readLine().rstrip(' ')) ; OclFile["System.out"] := stream() ; register(lambda $$ : OclAny in (((trailer . (name __stdout__))).write((OclFile["System.out"]).getvalue()))) ); operation helper(n : OclAny) : OclAny pre: true post: true activity: return ((2 * (-1)->pow(n) * n) + (-1)->pow(n) - 1) div 4; operation main() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; execute (helper(r) - helper(l - 1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxXOR(arr,n): xorArr=0 for i in range(n): xorArr ^=arr[i] ans=0 for i in range(n): ans=max(ans,(xorArr ^ arr[i])) return ans arr=[1,1,3] n=len(arr) print(maxXOR(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{1}->union(Sequence{ 3 })) ; n := (arr)->size() ; execute (maxXOR(arr, n))->display(); operation maxXOR(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var xorArr : int := 0 ; for i : Integer.subrange(0, n-1) do ( xorArr := xorArr xor arr[i+1]) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( ans := Set{ans, (MathLib.bitwiseXor(xorArr, arr[i+1]))}->max()) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout from math import* import math,random,operator from itertools import product,permutations,combinations from collections import deque,defaultdict,Counter def solve(x): if not x & 1 : return x/2 else : return int(-x+solve(x-1)) def hi(): a,b=map(int,input().split()) print(int(solve(b)-solve(a-1))) if __name__=="__main__" : for _ in range(int(input())): hi() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( hi()) ) else skip; operation solve(x : OclAny) : OclAny pre: true post: true activity: if not(MathLib.bitwiseAnd(x, 1)) then ( return x / 2 ) else ( return ("" + ((-x + solve(x - 1))))->toInteger() ); operation hi() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (("" + ((solve(b) - solve(a - 1))))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) for _ in range(q): l,r=map(int,input().split()) l-=1 print(r//2-r % 2*r-l//2+l % 2*l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; l := l - 1 ; execute (r div 2 - r mod 2 * r - l div 2 + l mod 2 * l)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def line2int(linea): temp="" for i in linea : if i=="" : if temp!="" : val1=int(temp) temp="" else : temp=temp+i val2=int(temp) return(val1,val2) n=int(input()) for i in range(n): (l,r)=line2int(input()) if l==r : out=l*pow(-1,l) elif l % 2==0 : if r-l==1 : out=-1 elif r % 2==0 : out=int(-1*(r-l)/2)+r*pow(-1,r) else : out=int(-1*(r-l+1)/2) else : if r-l==1 : out=1 elif r % 2==0 : out=int(1*(r-l+1)/2) else : out=int(1*(r-l)/2)+r*pow(-1,r) print(out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( ; var Sequence{l, r} : OclAny := line2int((OclFile["System.in"]).readLine()) ; if l = r then ( var out : double := l * (-1)->pow(l) ) else (if l mod 2 = 0 then ( if r - l = 1 then ( out := -1 ) else (if r mod 2 = 0 then ( out := ("" + ((-1 * (r - l) / 2)))->toInteger() + r * (-1)->pow(r) ) else ( out := ("" + ((-1 * (r - l + 1) / 2)))->toInteger() ) ) ) else ( if r - l = 1 then ( out := 1 ) else (if r mod 2 = 0 then ( out := ("" + ((1 * (r - l + 1) / 2)))->toInteger() ) else ( out := ("" + ((1 * (r - l) / 2)))->toInteger() + r * (-1)->pow(r) ) ) ) ) ; execute (out)->display()); operation line2int(linea : OclAny) : OclAny pre: true post: true activity: var temp : String := "" ; for i : linea do ( if i = "" then ( if temp /= "" then ( var val1 : int := ("" + ((temp)))->toInteger() ; temp := "" ) else skip ) else ( temp := temp + i )) ; var val2 : int := ("" + ((temp)))->toInteger() ; return Sequence{val1, val2}; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline q=int(input()) ans=[] for _ in range(q): l,r=map(int,input().split()) ans0=0 if not l % 2 : ans0+=l l+=1 if r % 2 and l<=r : ans0-=r r-=1 ans0+=(r-l+1)//2 ans.append(ans0) sys.stdout.write("\n".join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, q-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans0 : int := 0 ; if not(l mod 2) then ( ans0 := ans0 + l ; l := l + 1 ) else skip ; if r mod 2 & (l->compareTo(r)) <= 0 then ( ans0 := ans0 - r ; r := r - 1 ) else skip ; ans0 := ans0 + (r - l + 1) div 2 ; execute ((ans0) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() for i in range(3): n=sum(list(map(int,str(n)))) print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, 3-1) do ( n := (((("" + ((n))))->collect( _x | (OclType["int"])->apply(_x) )))->sum()) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Reverseorder(n): prime=[True]*(n+1); p=2 ; while(p*p<=n): if(prime[p]==True): for i in range((p*2),(n+1),p): prime[i]=False ; p+=1 ; for p in range(n,1,-1): if(prime[p]): print(p,end=" "); N=25 ; print("Prime number in reverse order"); if(N==1): print("No prime no exist in this range"); else : Reverseorder(N); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 25; ; execute ("Prime number in reverse order")->display(); ; if (N = 1) then ( execute ("No prime no exist in this range")->display(); ) else ( Reverseorder(N); ); operation Reverseorder(n : OclAny) pre: true post: true activity: var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (n + 1)); ; var p : int := 2; ; while ((p * p->compareTo(n)) <= 0) do ( if (prime[p+1] = true) then ( for i : Integer.subrange((p * 2), (n + 1)-1)->select( $x | ($x - (p * 2)) mod p = 0 ) do ( prime[i+1] := false;) ) else skip ; p := p + 1;) ; for p : Integer.subrange(1 + 1, n)->reverse() do ( if (prime[p+1]) then ( execute (p)->display(); ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(n): s=0 for i in n : s+=int(i) return s n=input() while len(n)>1 : n=str(f(n)) print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := (OclFile["System.in"]).readLine() ; while (n)->size() > 1 do ( n := ("" + ((f(n))))) ; execute (n)->display(); operation f(n : OclAny) : OclAny pre: true post: true activity: var s : int := 0 ; for i : n do ( s := s + ("" + ((i)))->toInteger()) ; return s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print((int(input())-1)% 9+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger() - 1) mod 9 + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print((int(input())-1)% 9+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger() - 1) mod 9 + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() for i in range(1000): n=sum(list(map(int,str(n)))) print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, 1000-1) do ( n := (((("" + ((n))))->collect( _x | (OclType["int"])->apply(_x) )))->sum()) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==0 : print(0) elif n % 2==0 : print(n+1) else : print((n+1)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( execute (0)->display() ) else (if n mod 2 = 0 then ( execute (n + 1)->display() ) else ( execute ((n + 1) div 2)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minimumOperations(a,n): mp=dict() for i in range(n): if a[i]in mp.keys(): mp[a[i]]+=1 else : mp[a[i]]=1 count=0 for it in mp : if(mp[it]>1): count+=mp[it]-1 return count a=[2,1,2,3,3,4,3] n=len(a) print(minimumOperations(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{2}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 3 })))))) ; n := (a)->size() ; execute (minimumOperations(a, n))->display(); operation minimumOperations(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var mp : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( if (mp.keys())->includes(a[i+1]) then ( mp[a[i+1]+1] := mp[a[i+1]+1] + 1 ) else ( mp[a[i+1]+1] := 1 )) ; var count : int := 0 ; for it : mp->keys() do ( if (mp[it+1] > 1) then ( count := count + mp[it+1] - 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from decimal import* getcontext().prec=25 n=int(input()) slice=Decimal(Decimal(360)/Decimal(n+1)) if n==0 : print(0) else : if n % 2==1 : print(int(Decimal(Decimal(n+1)/Decimal(2)))) else : print(n+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; getcontext().prec := 25 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var slice : OclAny := Decimal(Decimal(360) / Decimal(n + 1)) ; if n = 0 then ( execute (0)->display() ) else ( if n mod 2 = 1 then ( execute (("" + ((Decimal(Decimal(n + 1) / Decimal(2)))))->toInteger())->display() ) else ( execute (n + 1)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) if n==0 : print(0) elif(n+1)% 2==0 : print((n+1)//2) else : print(n+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( execute (0)->display() ) else (if (n + 1) mod 2 = 0 then ( execute ((n + 1) div 2)->display() ) else ( execute (n + 1)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==0 : print(0) else : if(n+1)% 2==0 : print((n+1)//2) else : print(n+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( execute (0)->display() ) else ( if (n + 1) mod 2 = 0 then ( execute ((n + 1) div 2)->display() ) else ( execute (n + 1)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solution(): n=int(input()) if n==0 : return 0 n+=1 if n % 2==0 : return n//2 else : return n print(solution()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (solution())->display(); operation solution() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( return 0 ) else skip ; n := n + 1 ; if n mod 2 = 0 then ( return n div 2 ) else ( return n ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pattern(min_stars,p_height): p_space=p_height-1 x=1 for i in range(0,p_height): for j in range(p_space,i,-1): print("",end="") for k in range(0,min_stars): print("*",end="") for n in range((p_height+p_height-2),x-1,-1): print("",end="") for k in range(0,min_stars): print("*",end="") min_stars=min_stars+2 x=x+2 print("") if __name__=='__main__' : min_stars=1 p_height=5 pattern(min_stars,p_height) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( min_stars := 1 ; p_height := 5 ; pattern(min_stars, p_height) ) else skip; operation pattern(min_stars : OclAny, p_height : OclAny) pre: true post: true activity: var p_space : double := p_height - 1 ; var x : int := 1 ; for i : Integer.subrange(0, p_height-1) do ( for j : Integer.subrange(i + 1, p_space)->reverse() do ( execute ("")->display()) ; for k : Integer.subrange(0, min_stars-1) do ( execute ("*")->display()) ; for n : Integer.subrange(x - 1 + 1, (p_height + p_height - 2))->reverse() do ( execute ("")->display()) ; for k : Integer.subrange(0, min_stars-1) do ( execute ("*")->display()) ; min_stars := min_stars + 2 ; x := x + 2 ; execute ("")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def print2largest(arr,arr_size): if(arr_size<2): print(" Invalid Input ") return first=second=-2147483648 for i in range(arr_size): if(arr[i]>first): second=first first=arr[i] elif(arr[i]>second and arr[i]!=first): second=arr[i] if(second==-2147483648): print("There is no second largest element") else : print("The second largest element is",second) arr=[12,35,1,10,34,1] n=len(arr) print2largest(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{12}->union(Sequence{35}->union(Sequence{1}->union(Sequence{10}->union(Sequence{34}->union(Sequence{ 1 }))))) ; var n : int := (arr)->size() ; print2largest(arr, n); operation print2largest(arr : OclAny, arr_size : OclAny) pre: true post: true activity: if (arr_size < 2) then ( execute (" Invalid Input ")->display() ; return ) else skip ; var first : OclAny := -2147483648; var second : int := -2147483648 ; for i : Integer.subrange(0, arr_size-1) do ( if ((arr[i+1]->compareTo(first)) > 0) then ( second := first ; first := arr[i+1] ) else (if ((arr[i+1]->compareTo(second)) > 0 & arr[i+1] /= first) then ( second := arr[i+1] ) else skip)) ; if (second = -2147483648) then ( execute ("There is no second largest element")->display() ) else ( execute ("The second largest element is")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=4 def maxDecimalValue(mat,i,j,p): if i>=N or j>=N : return 0 result=max(maxDecimalValue(mat,i,j+1,p+1),maxDecimalValue(mat,i+1,j,p+1)) if mat[i][j]==1 : return pow(2,p)+result else : return result mat=[[1,1,0,1],[0,1,1,0],[1,0,0,1],[1,0,1,1]] print(maxDecimalValue(mat,0,0,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 4 ; skip ; mat := Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 1 })))}->union(Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 0 })))}->union(Sequence{Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 1 })))}->union(Sequence{ Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 1 }))) }))) ; execute (maxDecimalValue(mat, 0, 0, 0))->display(); operation maxDecimalValue(mat : OclAny, i : OclAny, j : OclAny, p : OclAny) : OclAny pre: true post: true activity: if (i->compareTo(N)) >= 0 or (j->compareTo(N)) >= 0 then ( return 0 ) else skip ; var result : OclAny := Set{maxDecimalValue(mat, i, j + 1, p + 1), maxDecimalValue(mat, i + 1, j, p + 1)}->max() ; if mat[i+1][j+1] = 1 then ( return (2)->pow(p) + result ) else ( return result ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dist(m,b1,b2): d=abs(b2-b1)/((m*m)-1); return d ; def main(): m,b1,b2=2,4,3 ; print(dist(m,b1,b2)); if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation dist(m : OclAny, b1 : OclAny, b2 : OclAny) pre: true post: true activity: var d : double := (b2 - b1)->abs() / ((m * m) - 1); ; return d;; operation main() pre: true post: true activity: Sequence{m,b1,b2} := Sequence{2,4,3}; ; execute (dist(m, b1, b2))->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lst=list(map(int,input().split())) b=[] c=[] sum_c=0 sum_b=0 for x in lst : if x<0 : sum_c+=x else : sum_b+=x print(sum_b-sum_c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := Sequence{} ; var c : Sequence := Sequence{} ; var sum_c : int := 0 ; var sum_b : int := 0 ; for x : lst do ( if x < 0 then ( sum_c := sum_c + x ) else ( sum_b := sum_b + x )) ; execute (sum_b - sum_c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _=input() l=list(map(int,input().split())) sum=0 for i in l : sum+=abs(i) print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _anon : String := (OclFile["System.in"]).readLine() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sum : int := 0 ; for i : l do ( sum := sum + (i)->abs()) ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- su=0 n=int(input()) l=list(map(int,input().split())) for i in range(n): if l[i]<0 : l[i]=l[i]*-1 su=su+l[i] print(su) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var su : int := 0 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( if l[i+1] < 0 then ( l[i+1] := l[i+1] * -1 ) else skip ; su := su + l[i+1]) ; execute (su)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findFibSubset(arr,n): m=max(arr) a=0 b=1 hash=[] hash.append(a) hash.append(b) while(bunion(Sequence{2}->union(Sequence{8}->union(Sequence{5}->union(Sequence{20}->union(Sequence{1}->union(Sequence{40}->union(Sequence{13}->union(Sequence{ 23 })))))))) ; n := (arr)->size() ; findFibSubset(arr, n) ) else skip; operation findFibSubset(arr : OclAny, n : OclAny) pre: true post: true activity: var m : OclAny := (arr)->max() ; var a : int := 0 ; var b : int := 1 ; var hash : Sequence := Sequence{} ; execute ((a) : hash) ; execute ((b) : hash) ; while ((b->compareTo(m)) < 0) do ( var c : int := a + b ; a := b ; b := c ; execute ((b) : hash)) ; for i : Integer.subrange(0, n-1) do ( if (hash)->includes(arr[i+1]) then ( execute (arr[i+1])->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- str=input() numl=str.split(' ') a=int(numl[0]) b=int(numl[1]) c=int(numl[2]) numl.sort() print("{0}{1}{2}".format(numl[0],numl[1],numl[2])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var OclType["String"] : String := (OclFile["System.in"]).readLine() ; var numl : String := ("" + (.split(' '))) ; var a : int := ("" + ((numl->first())))->toInteger() ; var b : int := ("" + ((numl[1+1])))->toInteger() ; var c : int := ("" + ((numl[2+1])))->toInteger() ; numl := numl->sort() ; execute (StringLib.interpolateStrings("{0}{1}{2}", Sequence{numl->first(), numl[1+1], numl[2+1]}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=0 n=int(input()) l=list(map(int,input().split())) for i in range(n): if l[i]<0 : l[i]=l[i]*-1 s=s+l[i] print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : int := 0 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( if l[i+1] < 0 then ( l[i+1] := l[i+1] * -1 ) else skip ; s := s + l[i+1]) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() a=[int(i)for i in input().split()] b=c=0 for i in a : if i>0 : b+=i else : c+=i print(b-c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var b : OclAny := 0; var c : int := 0 ; for i : a do ( if i > 0 then ( b := b + i ) else ( c := c + i )) ; execute (b - c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : visitors_count=int(input()) minDay=0 maxDay=366 users=[] for i in range(visitors_count): users.append(input()) minDay=int(users[0].split()[1]) maxDay=int(users[0].split()[2]) all_users : list=[] for user in users : user=user.split() all_users.append([user[0],int(user[1]),int(user[2])]) if minDay>int(user[1]): minDay=int(user[1]) if maxDayfemales_len or males_len==females_len)and best_matchmales_len or males_len==females_len)and best_matchtoInteger() ; var minDay : int := 0 ; var maxDay : int := 366 ; var users : Sequence := Sequence{} ; for i : Integer.subrange(0, visitors_count-1) do ( execute (((OclFile["System.in"]).readLine()) : users)) ; minDay := ("" + ((users->first().split()[1+1])))->toInteger() ; maxDay := ("" + ((users->first().split()[2+1])))->toInteger() ; var all_users : Sequence := Sequence{} ; for user : users do ( var user : OclAny := user.split() ; execute ((Sequence{user->first()}->union(Sequence{("" + ((user[1+1])))->toInteger()}->union(Sequence{ ("" + ((user[2+1])))->toInteger() }))) : all_users) ; if (minDay->compareTo(("" + ((user[1+1])))->toInteger())) > 0 then ( minDay := ("" + ((user[1+1])))->toInteger() ) else skip ; if (maxDay->compareTo(("" + ((user[2+1])))->toInteger())) < 0 then ( maxDay := ("" + ((user[2+1])))->toInteger() ) else skip) ; var dict_cunts : OclAny := Set{} ; for i : Integer.subrange(minDay, maxDay + 1-1) do ( for user : all_users do ( if (Integer.subrange(user[1+1], user[2+1] + 1-1))->includes(i) then ( dict_cunts.setdefault(i, Sequence{}) ; (expr (atom (name dict_cunts)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name user)))))))) )))) ) else skip)) ; var best_match : int := 0 ; for users : dict_cunts.values() do ( var males_len : int := (((users)->select( _x | (lambda user : OclAny in (user->first() = 'M'))->apply(_x) = true )))->size() ; var males_len_x2 : int := males_len * 2 ; var females_len : double := (users)->size() - males_len ; var females_len_x2 : double := females_len * 2 ; if ((males_len->compareTo(females_len)) > 0 or males_len = females_len) & (best_match->compareTo(females_len_x2)) < 0 then ( best_match := females_len_x2 ) else (if ((females_len->compareTo(males_len)) > 0 or males_len = females_len) & (best_match->compareTo(males_len_x2)) < 0 then ( best_match := males_len_x2 ) else skip)) ; execute (best_match)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSubstrs(s1,s2): ans=0 for i in range(len(s1)): s3="" for j in range(i,len(s1)): s3+=s1[j] if s2.find(s3)!=-1 : ans+=1 return ans if __name__=="__main__" : s1="aab" s2="aaaab" print(countSubstrs(s1,s2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s1 := "aab" ; s2 := "aaaab" ; execute (countSubstrs(s1, s2))->display() ) else skip; operation countSubstrs(s1 : OclAny, s2 : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, (s1)->size()-1) do ( var s3 : String := "" ; for j : Integer.subrange(i, (s1)->size()-1) do ( s3 := s3 + s1[j+1] ; if s2->indexOf(s3) - 1 /= -1 then ( ans := ans + 1 ) else skip)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100005 prime=[True for i in range(MAX)] def SieveOfEratosthenes(): prime[0]=False prime[1]=False for p in range(MAX): if(p*p>MAX): break if(prime[p]): for i in range(2*p,MAX,p): prime[i]=False def countPrimes(n): SieveOfEratosthenes() cnt=0 for i in range(2,n): if(prime[i]and prime[i-2]): cnt+=1 return cnt n=11 print(countPrimes(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 100005 ; var prime : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (true)) ; skip ; skip ; n := 11 ; execute (countPrimes(n))->display(); operation SieveOfEratosthenes() pre: true post: true activity: prime->first() := false ; prime[1+1] := false ; for p : Integer.subrange(0, MAX-1) do ( if ((p * p->compareTo(MAX)) > 0) then ( break ) else skip ; if (prime[p+1]) then ( for i : Integer.subrange(2 * p, MAX-1)->select( $x | ($x - 2 * p) mod p = 0 ) do ( prime[i+1] := false) ) else skip); operation countPrimes(n : OclAny) : OclAny pre: true post: true activity: SieveOfEratosthenes() ; var cnt : int := 0 ; for i : Integer.subrange(2, n-1) do ( if (prime[i+1] & prime[i - 2+1]) then ( cnt := cnt + 1 ) else skip) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- data={} for _ in range(int(input())): x,k=map(int,input().split()) if k in data : data[k].append(x) else : data[k]=[x] flag=True for counts in data.values(): allowed=0 for count in counts : if count>allowed : flag=False break if count==allowed : allowed+=1 if not flag : break print(['NO','YES'][flag]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var data : OclAny := Set{} ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var k : OclAny := null; Sequence{x,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (data)->includes(k) then ( (expr (atom (name data)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) ) else ( data[k+1] := Sequence{ x } )) ; var flag : boolean := true ; for counts : data.values() do ( var allowed : int := 0 ; for count : counts do ( if (count->compareTo(allowed)) > 0 then ( flag := false ; break ) else skip ; if count = allowed then ( allowed := allowed + 1 ) else skip) ; if not(flag) then ( break ) else skip) ; execute (Sequence{'NO'}->union(Sequence{ 'YES' })[flag+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) vis=set() flag=1 for i in range(n): x,k=map(int,input().split()) if x==0 : vis.add((x,k)) else : if(x-1,k)in vis : vis.add((x,k)) else : flag=0 if flag : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var vis : Set := Set{}->union(()) ; var flag : int := 1 ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var k : OclAny := null; Sequence{x,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x = 0 then ( execute ((Sequence{x, k}) : vis) ) else ( if (vis)->includes(Sequence{x - 1, k}) then ( execute ((Sequence{x, k}) : vis) ) else ( flag := 0 ) )) ; if flag then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import math import sys def get_ints(): return map(int,sys.stdin.readline().strip().split()) def get_array(): return list(map(int,sys.stdin.readline().strip().split())) def input(): return sys.stdin.readline().strip() MOD=1000000007 n=int(input()) arr=[0]*int(1e6+1) for i in range(n): x,k=get_ints() if arr[k]==x : arr[k]+=1 elif x>arr[k]: print('NO') sys.exit(0) print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var MOD : int := 1000000007 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + ((("1e6")->toReal() + 1)))->toInteger()) ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var k : OclAny := null; Sequence{x,k} := get_ints() ; if arr[k+1] = x then ( arr[k+1] := arr[k+1] + 1 ) else (if (x->compareTo(arr[k+1])) > 0 then ( execute ('NO')->display() ; sys.exit(0) ) else skip)) ; execute ('YES')->display(); operation get_ints() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ); operation get_array() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def inp(): return int(input()) def st(): return input().rstrip('\n') def lis(): return list(map(int,input().split())) def ma(): return map(int,input().split()) t=1 while(t): t-=1 n=inp() s='YES' dic={} for i in range(n): x,y=ma() if(y in dic): dic[y].append(x) else : dic[y]=[x] for i in dic.keys(): p=set() p1=-1 for j in range(len(dic[i])): if(dic[i][j]in p): continue else : if(dic[i][j]==p1+1): p1=dic[i][j] p.add(p1) else : s='NO' print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; var t : int := 1 ; while (t) do ( t := t - 1 ; var n : OclAny := inp() ; var s : String := 'YES' ; var dic : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ma() ; if ((dic)->includes(y)) then ( (expr (atom (name dic)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) ) else ( dic[y+1] := Sequence{ x } )) ; for i : dic.keys() do ( var p : Set := Set{}->union(()) ; var p1 : int := -1 ; for j : Integer.subrange(0, (dic[i+1])->size()-1) do ( if ((p)->includes(dic[i+1][j+1])) then ( continue ) else ( if (dic[i+1][j+1] = p1 + 1) then ( p1 := dic[i+1][j+1] ; execute ((p1) : p) ) else ( s := 'NO' ) ))) ; execute (s)->display()); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation st() : OclAny pre: true post: true activity: return input().rstrip(' '); operation lis() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ma() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def powermod(x,y,p): res=1 ; x=x % p ; while(y>0): if((y & 1)>0): res=(res*x)% p ; y=y>>1 ; x=(x*x)% p ; return res ; def modInverse(a,m): m0=m ; x0=0 ; x1=1 ; if(m==1): return 0 ; while(a>1): q=int(a/m); t=m ; m=a % m ; a=t ; t=x0 ; x0=x1-q*x0 ; x1=t ; if(x1<0): x1+=m0 ; return x1 ; def evaluteExpression(n): firstsum=0 ; mod=10 ; i=2 ; j=0 ; while((1<display(); ; n := 10; ; execute (evaluteExpression(n))->display();; operation powermod(x : OclAny, y : OclAny, p : OclAny) pre: true post: true activity: var res : int := 1; ; x := x mod p; ; while (y > 0) do ( if ((MathLib.bitwiseAnd(y, 1)) > 0) then ( res := (res * x) mod p; ) else skip ; y := y /(2->pow(1)); ; x := (x * x) mod p;) ; return res;; operation modInverse(a : OclAny, m : OclAny) pre: true post: true activity: var m0 : OclAny := m; ; var x0 : int := 0; ; var x1 : int := 1; ; if (m = 1) then ( return 0; ) else skip ; while (a > 1) do ( var q : int := ("" + ((a / m)))->toInteger(); ; var t : OclAny := m; ; m := a mod m; ; a := t; ; t := x0; ; x0 := x1 - q * x0; ; x1 := t;) ; if (x1 < 0) then ( x1 := x1 + m0; ) else skip ; return x1;; operation evaluteExpression(n : OclAny) pre: true post: true activity: var firstsum : int := 0; ; var mod : int := 10; ; var i : int := 2; ; var j : int := 0; ; while (((1 * (2->pow(j)))->compareTo(n)) <= 0) do ( firstsum := (firstsum + i) mod mod; ; i := i * i; ; j := j + 1;) ; var secondsum : double := (powermod(4, n + 1, mod) - 1) * modInverse(3, mod); ; return (firstsum * secondsum) mod mod;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- hm={} def countFreq(a): global hm for i in a : if i in hm : hm[i]+=1 else : hm[i]=1 def query(x): if x in hm : return hm[x] return 0 a=[1,3,2,4,2,1] countFreq(a) print(query(2)) print(query(3)) print(query(5)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute hm : OclAny; operation initialise() pre: true post: true activity: var hm : OclAny := Set{} ; skip ; skip ; a := Sequence{1}->union(Sequence{3}->union(Sequence{2}->union(Sequence{4}->union(Sequence{2}->union(Sequence{ 1 }))))) ; countFreq(a) ; execute (query(2))->display() ; execute (query(3))->display() ; execute (query(5))->display(); operation countFreq(a : OclAny) pre: true post: true activity: skip ; for i : a do ( if (hm)->includes(i) then ( hm[i+1] := hm[i+1] + 1 ) else ( hm[i+1] := 1 )); operation query(x : OclAny) : OclAny pre: true post: true activity: if (hm)->includes(x) then ( return hm[x+1] ) else skip ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- nums=map(int,input().split(' ')) sortednums=sorted(nums) print(*sortednums) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var nums : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var sortednums : Sequence := nums->sort() ; execute ((argument * (test (logical_test (comparison (expr (atom (name sortednums))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- maxN=10 fact=[0]*maxN ; def ncr(n,r): return(fact[n]//fact[r])//fact[n-r]; def findSum(arr,n): fact[0]=1 ; for i in range(1,n): fact[i]=i*fact[i-1]; mul=0 ; for i in range(n): mul+=(2**i)*ncr(n-1,i); ans=0 ; for i in range(n): ans+=mul*arr[i]; return ans ; if __name__=="__main__" : arr=[1,1]; n=len(arr); print(findSum(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var maxN : int := 10 ; var fact : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, maxN); ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{ 1 }); ; n := (arr)->size(); ; execute (findSum(arr, n))->display(); ) else skip; operation ncr(n : OclAny, r : OclAny) pre: true post: true activity: return (fact[n+1] div fact[r+1]) div fact[n - r+1];; operation findSum(arr : OclAny, n : OclAny) pre: true post: true activity: fact->first() := 1; ; for i : Integer.subrange(1, n-1) do ( fact[i+1] := i * fact[i - 1+1];) ; var mul : int := 0; ; for i : Integer.subrange(0, n-1) do ( mul := mul + ((2)->pow(i)) * ncr(n - 1, i);) ; var ans : int := 0; ; for i : Integer.subrange(0, n-1) do ( ans := ans + mul * arr[i+1];) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline N=368 m=[0]*N f=[0]*N for i in range(int(input())): x,a,b=input()[:-1].split() a=int(a) b=int(b)+1 if x=='M' : m[a]+=2 m[b]-=2 else : f[a]+=2 f[b]-=2 a,b,c=0,0,0 for i in range(N): a+=m[i] b+=f[i] if min(a,b)>c : c=min(a,b) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var N : int := 368 ; var m : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{x,a,b} := input()->front().split() ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() + 1 ; if x = 'M' then ( m[a+1] := m[a+1] + 2 ; m[b+1] := m[b+1] - 2 ) else ( f[a+1] := f[a+1] + 2 ; f[b+1] := f[b+1] - 2 )) ; var c : OclAny := null; Sequence{a,b,c} := Sequence{0,0,0} ; for i : Integer.subrange(0, N-1) do ( a := a + m[i+1] ; b := b + f[i+1] ; if (Set{a, b}->min()->compareTo(c)) > 0 then ( var c : OclAny := Set{a, b}->min() ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumDigits(n): sum=0 ; while(n>0): digit=n % 10 ; sum+=digit ; n//=10 ; return sum ; def isDivBySix(string,n): sum=0 ; for i in range(n): sum+=(ord(string[i])-ord('a')+1); if(sum % 3!=0): return False ; lastDigit=(ord(string[n-1])-ord('a')+1)% 10 ; if(lastDigit % 2!=0): return False ; return True ; if __name__=="__main__" : string="ab" ; n=len(string); if(isDivBySix(string,n)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( string := "ab"; ; n := (string)->size(); ; if (isDivBySix(string, n)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ) else skip; operation sumDigits(n : OclAny) pre: true post: true activity: var sum : int := 0; ; while (n > 0) do ( var digit : int := n mod 10; ; sum := sum + digit; ; n := n div 10;) ; return sum;; operation isDivBySix(string : OclAny, n : OclAny) pre: true post: true activity: sum := 0; ; for i : Integer.subrange(0, n-1) do ( sum := sum + ((string[i+1])->char2byte() - ('a')->char2byte() + 1);) ; if (sum mod 3 /= 0) then ( return false; ) else skip ; var lastDigit : int := ((string[n - 1+1])->char2byte() - ('a')->char2byte() + 1) mod 10; ; if (lastDigit mod 2 /= 0) then ( return false; ) else skip ; return true;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def product(mat,n): d1=0 d2=0 for i in range(n): d1+=mat[i][i] d2+=mat[i][n-i-1] return d1*d2 if __name__=='__main__' : mat=[[5,8,1],[5,10,3],[-6,17,-9]] n=len(mat) print(product(mat,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( mat := Sequence{Sequence{5}->union(Sequence{8}->union(Sequence{ 1 }))}->union(Sequence{Sequence{5}->union(Sequence{10}->union(Sequence{ 3 }))}->union(Sequence{ Sequence{-6}->union(Sequence{17}->union(Sequence{ -9 })) })) ; n := (mat)->size() ; execute (product(mat, n))->display() ) else skip; operation product(mat : OclAny, n : OclAny) : OclAny pre: true post: true activity: var d1 : int := 0 ; var d2 : int := 0 ; for i : Integer.subrange(0, n-1) do ( d1 := d1 + mat[i+1][i+1] ; d2 := d2 + mat[i+1][n - i - 1+1]) ; return d1 * d2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find(s): Max=j=countk=countr=0 table=[[0,0]for i in range(len(s))] for i in range(0,len(s)): if s[i]=='R' : countr+=1 else : table[j][0]=countr j+=1 j-=1 for i in range(len(s)-1,-1,-1): if s[i]=='K' : countk+=1 table[j][1]=countk j-=1 if min(table[j+1][0],table[j+1][1])>Max : Max=min(table[j+1][0],table[j+1][1]) return Max if __name__=="__main__" : s="RKRRRKKRRKKKKRR" print(find(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "RKRRRKKRRKKKKRR" ; execute (find(s))->display() ) else skip; operation find(s : OclAny) : OclAny pre: true post: true activity: Max := Max(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name j)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name countk)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name countr)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; var table : Sequence := Integer.subrange(0, (s)->size()-1)->select(i | true)->collect(i | (Sequence{0}->union(Sequence{ 0 }))) ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = 'R' then ( countr := countr + 1 ) else ( table[j+1]->first() := countr ; j := j + 1 )) ; j := j - 1 ; for i : Integer.subrange(-1 + 1, (s)->size() - 1)->reverse() do ( if s[i+1] = 'K' then ( countk := countk + 1 ; table[j+1][1+1] := countk ; j := j - 1 ) else skip ; if (Set{table[j + 1+1]->first(), table[j + 1+1][1+1]}->min()->compareTo(Max)) > 0 then ( var Max : OclAny := Set{table[j + 1+1]->first(), table[j + 1+1][1+1]}->min() ) else skip) ; return Max; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cost(a,n): return((n-1)*min(a)) a=[4,3,2] n=len(a) print(cost(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{4}->union(Sequence{3}->union(Sequence{ 2 })) ; n := (a)->size() ; execute (cost(a, n))->display(); operation cost(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: return ((n - 1) * (a)->min()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=4 def areSame(A,B): for i in range(N): for j in range(N): if(A[i][j]!=B[i][j]): return 0 return 1 A=[[1,1,1,1],[2,2,2,2],[3,3,3,3],[4,4,4,4]] B=[[1,1,1,1],[2,2,2,2],[3,3,3,3],[4,4,4,4]] if(areSame(A,B)==1): print("Matrices are identical") else : print("Matrices are not identical") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 4 ; skip ; A := Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })))}->union(Sequence{Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 2 })))}->union(Sequence{Sequence{3}->union(Sequence{3}->union(Sequence{3}->union(Sequence{ 3 })))}->union(Sequence{ Sequence{4}->union(Sequence{4}->union(Sequence{4}->union(Sequence{ 4 }))) }))) ; B := Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })))}->union(Sequence{Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 2 })))}->union(Sequence{Sequence{3}->union(Sequence{3}->union(Sequence{3}->union(Sequence{ 3 })))}->union(Sequence{ Sequence{4}->union(Sequence{4}->union(Sequence{4}->union(Sequence{ 4 }))) }))) ; if (areSame(A, B) = 1) then ( execute ("Matrices are identical")->display() ) else ( execute ("Matrices are not identical")->display() ); operation areSame(A : OclAny, B : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( if (A[i+1][j+1] /= B[i+1][j+1]) then ( return 0 ) else skip)) ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ReplaceElements(arr,n): X=0 for i in range(n): X ^=arr[i] for i in range(n): arr[i]=X ^ arr[i] if __name__=="__main__" : arr=[2,3,3,5,5] n=len(arr) ReplaceElements(arr,n) for i in range(n): print(arr[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{2}->union(Sequence{3}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 5 })))) ; n := (arr)->size() ; ReplaceElements(arr, n) ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()) ) else skip; operation ReplaceElements(arr : OclAny, n : OclAny) pre: true post: true activity: var X : int := 0 ; for i : Integer.subrange(0, n-1) do ( X := X xor arr[i+1]) ; for i : Integer.subrange(0, n-1) do ( arr[i+1] := MathLib.bitwiseXor(X, arr[i+1])); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getMaxandMinProduct(arr,n): curMaxProduct=arr[0] curMinProduct=arr[0] prevMaxProduct=arr[0] prevMinProduct=arr[0] maxProduct=arr[0] minProduct=arr[0] for i in range(1,n): curMaxProduct=max(prevMaxProduct*arr[i],max(prevMinProduct*arr[i],arr[i])) curMaxProduct=max(curMaxProduct,prevMaxProduct) curMinProduct=min(prevMaxProduct*arr[i],min(prevMinProduct*arr[i],arr[i])) curMinProduct=min(curMinProduct,prevMinProduct) maxProduct=max(maxProduct,curMaxProduct) minProduct=min(minProduct,curMinProduct) prevMaxProduct=curMaxProduct prevMinProduct=curMinProduct return(minProduct,maxProduct) if __name__=="__main__" : arr=[-4,-2,3,7,5,0,1] n=len(arr) product=getMaxandMinProduct(arr,n) print("Minimum product is",product[0],"and","Maximum product is",product[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{-4}->union(Sequence{-2}->union(Sequence{3}->union(Sequence{7}->union(Sequence{5}->union(Sequence{0}->union(Sequence{ 1 })))))) ; n := (arr)->size() ; var product : OclAny := getMaxandMinProduct(arr, n) ; execute ("Minimum product is")->display() ) else skip; operation getMaxandMinProduct(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var curMaxProduct : OclAny := arr->first() ; var curMinProduct : OclAny := arr->first() ; var prevMaxProduct : OclAny := arr->first() ; var prevMinProduct : OclAny := arr->first() ; var maxProduct : OclAny := arr->first() ; var minProduct : OclAny := arr->first() ; for i : Integer.subrange(1, n-1) do ( curMaxProduct := Set{prevMaxProduct * arr[i+1], Set{prevMinProduct * arr[i+1], arr[i+1]}->max()}->max() ; curMaxProduct := Set{curMaxProduct, prevMaxProduct}->max() ; curMinProduct := Set{prevMaxProduct * arr[i+1], Set{prevMinProduct * arr[i+1], arr[i+1]}->min()}->min() ; curMinProduct := Set{curMinProduct, prevMinProduct}->min() ; maxProduct := Set{maxProduct, curMaxProduct}->max() ; minProduct := Set{minProduct, curMinProduct}->min() ; prevMaxProduct := curMaxProduct ; prevMinProduct := curMinProduct) ; return Sequence{minProduct, maxProduct}; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPrime(n): if(n<=1): return False if(n<=3): return True if(n % 2==0 or n % 3==0): return False i=5 while(i*i<=n): if(n % i==0 or n %(i+2)==0): return False i+=6 return True def primorial(n): p=2 ; n-=1 ; i=3 while(n!=0): if(isPrime(i)): p=p*i n-=1 i+=1 return p def findNextPrime(n): nextPrime=n+2 while(True): if(isPrime(nextPrime)): break nextPrime+=1 return nextPrime def fortunateNumber(n): p=primorial(n) return findNextPrime(p)-p n=5 print(fortunateNumber(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; n := 5 ; execute (fortunateNumber(n))->display(); operation isPrime(n : OclAny) : OclAny pre: true post: true activity: if (n <= 1) then ( return false ) else skip ; if (n <= 3) then ( return true ) else skip ; if (n mod 2 = 0 or n mod 3 = 0) then ( return false ) else skip ; var i : int := 5 ; while ((i * i->compareTo(n)) <= 0) do ( if (n mod i = 0 or n mod (i + 2) = 0) then ( return false ) else skip ; i := i + 6) ; return true; operation primorial(n : OclAny) : OclAny pre: true post: true activity: var p : int := 2; n := n - 1; i := 3 ; while (n /= 0) do ( if (isPrime(i)) then ( p := p * i ; n := n - 1 ) else skip ; i := i + 1) ; return p; operation findNextPrime(n : OclAny) : OclAny pre: true post: true activity: var nextPrime : OclAny := n + 2 ; while (true) do ( if (isPrime(nextPrime)) then ( break ) else skip ; nextPrime := nextPrime + 1) ; return nextPrime; operation fortunateNumber(n : OclAny) : OclAny pre: true post: true activity: p := primorial(n) ; return findNextPrime(p) - p; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def count_1(n,l,r): if(rR): return 0 if(n<2): if(l>=L and r<=R): return n else : return 0 mid=(l+r)//2 return count_1(n//2,l,mid-1)+count_1(n % 2,mid,mid)+count_1(n//2,mid+1,r) if __name__=="__main__" : global N,L,R N,L,R=[int(i)for i in input().split(" ")] len,exp,temp=0,0,N while(temp>=1): len+=2**exp exp+=1 temp=temp//2 print(count_1(N,1,len)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute N : OclAny; attribute L : OclAny; attribute R : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( skip; skip; skip ; Sequence{N,L,R} := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var len : OclAny := null; var exp : OclAny := null; var temp : OclAny := null; Sequence{len,exp,temp} := Sequence{0,0,N} ; while (temp >= 1) do ( len := len + (2)->pow(exp) ; exp := exp + 1 ; var temp : int := temp div 2) ; execute (countcount(count(count(countcount(count(count(countcount(count(count(countcount(count(count(countcount(count(count(countcount(count(count(countcount(count(count skip; skip; skip(N, 1, len))(N, 1, len))(N, 1, len)(N, 1, len))->display()(N, 1, len))(N, 1, len))(N, 1, len)(N, 1, len))->display()(N, 1, len))(N, 1, len))(N, 1, len)(N, 1, len))->display()(N, 1, len))(N, 1, len))(N, 1, len)(N, 1, len))->display()(N, 1, len))(N, 1, len))(N, 1, len)(N, 1, len))->display()(N, 1, len))(N, 1, len))(N, 1, len)(N, 1, len))->display()(N, 1, len))(N, 1, len))(N, 1, len)(N, 1, len))->display() ) else skip; operation count skip(n : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: if ((r->compareTo(L)) < 0 or (l->compareTo(R)) > 0) then ( return 0 ) else skip ; if (n < 2) then ( if ((l->compareTo(L)) >= 0 & (r->compareTo(R)) <= 0) then ( return n ) else ( return 0 ) ) else skip ; var mid : int := (l + r) div 2 ; return count if ((r->compareTo(L)) < 0 or (l->compareTo(R)) > 0) then ( return 0 ) else skip(n div 2, l, mid - 1) + count if ((r->compareTo(L)) < 0 or (l->compareTo(R)) > 0) then ( return 0 ) else skip(n mod 2, mid, mid) + count if ((r->compareTo(L)) < 0 or (l->compareTo(R)) > 0) then ( return 0 ) else skip(n div 2, mid + 1, r); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): L=sorted(map(int,input().split())) print(*L) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var L : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; execute ((argument * (test (logical_test (comparison (expr (atom (name L))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def distancesum(x,y,n): sum=0 for i in range(n): for j in range(i+1,n): sum+=(abs(x[i]-x[j])+abs(y[i]-y[j])) return sum x=[-1,1,3,2] y=[5,6,5,3] n=len(x) print(distancesum(x,y,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := Sequence{-1}->union(Sequence{1}->union(Sequence{3}->union(Sequence{ 2 }))) ; y := Sequence{5}->union(Sequence{6}->union(Sequence{5}->union(Sequence{ 3 }))) ; n := (x)->size() ; execute (distancesum(x, y, n))->display(); operation distancesum(x : OclAny, y : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( sum := sum + ((x[i+1] - x[j+1])->abs() + (y[i+1] - y[j+1])->abs()))) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dc1={} dc2={} def solve1(a): global dc if a in dc1 : return if a==1 : dc1[a]=1 dc2[a]=1 return if a==0 : dc1[a]=1 dc2[a]=0 return solve1(a//2) dc1[a]=dc1[a//2]*2+1 dc2[a]=dc2[a//2]*2+(a % 2) def solve2(a,y): if y==0 : return 0 if a==1 : return 1 if a==0 : return 0 tmp1=a//2 tmp2=dc1[tmp1] if tmp2>=y : return solve2(a//2,y) ans=dc2[tmp1]+(a % 2) return ans+solve2(a//2,y-tmp2-1) def riku(a,x,y): solve1(a) ans=solve2(a,y)-solve2(a,x-1) return ans a,x,y=map(int,input().split()) print(riku(a,x,y)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute dc : OclAny; operation initialise() pre: true post: true activity: var dc1 : OclAny := Set{} ; var dc2 : OclAny := Set{} ; skip ; skip ; skip ; Sequence{a,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (riku(a, x, y))->display(); operation solve1(a : OclAny) pre: true post: true activity: skip ; if (dc1)->includes(a) then ( return ) else skip ; if a = 1 then ( dc1[a+1] := 1 ; dc2[a+1] := 1 ; return ) else skip ; if a = 0 then ( dc1[a+1] := 1 ; dc2[a+1] := 0 ; return ) else skip ; solve1(a div 2) ; dc1[a+1] := dc1[a div 2+1] * 2 + 1 ; dc2[a+1] := dc2[a div 2+1] * 2 + (a mod 2); operation solve2(a : OclAny, y : OclAny) : OclAny pre: true post: true activity: if y = 0 then ( return 0 ) else skip ; if a = 1 then ( return 1 ) else skip ; if a = 0 then ( return 0 ) else skip ; var tmp1 : int := a div 2 ; var tmp2 : OclAny := dc1[tmp1+1] ; if (tmp2->compareTo(y)) >= 0 then ( return solve2(a div 2, y) ) else skip ; var ans : OclAny := dc2[tmp1+1] + (a mod 2) ; return ans + solve2(a div 2, y - tmp2 - 1); operation riku(a : OclAny, x : OclAny, y : OclAny) : OclAny pre: true post: true activity: solve1(a) ; ans := solve2(a, y) - solve2(a, x - 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,l,r=[int(item)for item in input().split()] def _enumerate(n): if n<=1 : return 1 else : return _enumerate(n//2)*2+1 def _list(n): if n<=1 : return n else : return 2*_list(n//2)+n % 2 def solve(p,n,temp,prev): if p==0 : return 0 elif p==temp : return _list(n) elif p==temp//2+1 : return _list(n//2)+n % 2 elif p>temp : return _list(n)+prev % 2+solve(p-temp-1,n//2,temp//2,n) else : return solve(p,n//2,temp//2,n) def help_sam(l,r,n): lower=solve(l-1,n,_enumerate(n),0) higher=solve(r,n,_enumerate(n),0) return higher-lower output=help_sam(l,r,n) print(output) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{n,l,r} := input().split()->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; skip ; skip ; skip ; skip ; var output : OclAny := help_sam(l, r, n) ; execute (output)->display(); operation _enumerate(n : OclAny) : OclAny pre: true post: true activity: if n <= 1 then ( return 1 ) else ( return _enumerate(n div 2) * 2 + 1 ); operation _list(n : OclAny) : OclAny pre: true post: true activity: if n <= 1 then ( return n ) else ( return 2 * _list(n div 2) + n mod 2 ); operation solve(p : OclAny, n : OclAny, temp : OclAny, prev : OclAny) : OclAny pre: true post: true activity: if p = 0 then ( return 0 ) else (if p = temp then ( return _list(n) ) else (if p = temp div 2 + 1 then ( return _list(n div 2) + n mod 2 ) else (if (p->compareTo(temp)) > 0 then ( return _list(n) + prev mod 2 + solve(p - temp - 1, n div 2, temp div 2, n) ) else ( return solve(p, n div 2, temp div 2, n) ) ) ) ) ; operation help_sam(l : OclAny, r : OclAny, n : OclAny) : OclAny pre: true post: true activity: var lower : OclAny := solve(l - 1, n, _enumerate(n), 0) ; var higher : OclAny := solve(r, n, _enumerate(n), 0) ; return higher - lower; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,l,r=input().split() n,l,r=int(n),int(l),int(r) def nm(p): if p<=1 : return p return nm(p//2)*2+1 def dfs(num,L,R,l,r): if(Rr or num==0): return 0 if(num==1): return 1 mid=l+nm(num//2) return dfs(num//2,L,R,l,mid-1)+dfs(num % 2,L,R,mid,mid)+dfs(num//2,L,R,mid+1,r) ans=nm(n) res=dfs(n,l,r,1,ans) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{n,l,r} := input().split() ; var n : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{n,l,r} := Sequence{("" + ((n)))->toInteger(),("" + ((l)))->toInteger(),("" + ((r)))->toInteger()} ; skip ; skip ; var ans : OclAny := nm(n) ; var res : OclAny := dfs(n, l, r, 1, ans) ; execute (res)->display(); operation nm(p : OclAny) : OclAny pre: true post: true activity: if p <= 1 then ( return p ) else skip ; return nm(p div 2) * 2 + 1; operation dfs(num : OclAny, L : OclAny, R : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: if ((R->compareTo(l)) < 0 or (L->compareTo(r)) > 0 or num = 0) then ( return 0 ) else skip ; if (num = 1) then ( return 1 ) else skip ; var mid : OclAny := l + nm(num div 2) ; return dfs(num div 2, L, R, l, mid - 1) + dfs(num mod 2, L, R, mid, mid) + dfs(num div 2, L, R, mid + 1, r); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,l,r=[int(item)for item in input().split()] def _enumerate(n): if n<=1 : return 1 else : return _enumerate(n//2)*2+1 def _list(n): if n<=1 : return n else : return 2*_list(n//2)+n % 2 def solve(p,n,temp,prev): if p==0 : return 0 elif p==temp : return _list(n) elif p==temp//2+1 : return _list(n//2)+n % 2 elif p>temp : return _list(n)+prev % 2+solve(p-temp-1,n//2,temp//2,n) else : return solve(p,n//2,temp//2,n) def help_sam(l,r,n): lower=solve(l-1,n,_enumerate(n),0) higher=solve(r,n,_enumerate(n),0) return higher-lower output=help_sam(l,r,n) print(output) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{n,l,r} := input().split()->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; skip ; skip ; skip ; skip ; var output : OclAny := help_sam(l, r, n) ; execute (output)->display(); operation _enumerate(n : OclAny) : OclAny pre: true post: true activity: if n <= 1 then ( return 1 ) else ( return _enumerate(n div 2) * 2 + 1 ); operation _list(n : OclAny) : OclAny pre: true post: true activity: if n <= 1 then ( return n ) else ( return 2 * _list(n div 2) + n mod 2 ); operation solve(p : OclAny, n : OclAny, temp : OclAny, prev : OclAny) : OclAny pre: true post: true activity: if p = 0 then ( return 0 ) else (if p = temp then ( return _list(n) ) else (if p = temp div 2 + 1 then ( return _list(n div 2) + n mod 2 ) else (if (p->compareTo(temp)) > 0 then ( return _list(n) + prev mod 2 + solve(p - temp - 1, n div 2, temp div 2, n) ) else ( return solve(p, n div 2, temp div 2, n) ) ) ) ) ; operation help_sam(l : OclAny, r : OclAny, n : OclAny) : OclAny pre: true post: true activity: var lower : OclAny := solve(l - 1, n, _enumerate(n), 0) ; var higher : OclAny := solve(r, n, _enumerate(n), 0) ; return higher - lower; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMaxFrequency(s): arr=[0]*26 for i in range(len(s)): arr[ord(s[i])-ord('a')]+=1 hash={} for i in range(26): if(arr[i]!=0): if arr[i]not in hash : hash[arr[i]]=0 hash[arr[i]]+=1 max_count=0 res=-1 for i in hash : if(max_countsize()-1) do ( arr[(s[i+1])->char2byte() - ('a')->char2byte()+1] := arr[(s[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; var hash : OclAny := Set{} ; for i : Integer.subrange(0, 26-1) do ( if (arr[i+1] /= 0) then ( if (hash)->excludes(arr[i+1]) then ( hash[arr[i+1]+1] := 0 ) else skip ; hash[arr[i+1]+1] := hash[arr[i+1]+1] + 1 ) else skip) ; var max_count : int := 0 ; var res : int := -1 ; for i : hash do ( if ((max_count->compareTo(hash[i+1])) < 0) then ( res := i ; max_count := hash[i+1] ) else skip) ; execute ("Frequency")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSub(arr,n): count=[0 for i in range(10)] for i in range(n): for j in range(arr[i]-1,-1,-1): count[arr[i]]+=count[j] count[arr[i]]+=1 result=0 for i in range(10): result+=count[i] return result arr=[3,2,4,5,4] n=len(arr) print(countSub(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{3}->union(Sequence{2}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 4 })))) ; n := (arr)->size() ; execute (countSub(arr, n))->display(); operation countSub(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count : Sequence := Integer.subrange(0, 10-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(-1 + 1, arr[i+1] - 1)->reverse() do ( count[arr[i+1]+1] := count[arr[i+1]+1] + count[j+1]) ; count[arr[i+1]+1] := count[arr[i+1]+1] + 1) ; var result : int := 0 ; for i : Integer.subrange(0, 10-1) do ( result := result + count[i+1]) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def findingValues(m,n,mth,nth): d=((abs(mth-nth))/abs((m-1)-(n-1))) a=mth-((m-1)*d) return a,d def findSum(m,n,mth,nth,p): a,d=findingValues(m,n,mth,nth) Sum=(p*(2*a+(p-1)*d))/2 return Sum m=6 n=10 mTerm=12 nTerm=20 p=5 print(findSum(m,n,mTerm,nTerm,p)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; m := 6 ; n := 10 ; var mTerm : int := 12 ; var nTerm : int := 20 ; p := 5 ; execute (findSum(m, n, mTerm, nTerm, p))->display(); operation findingValues(m : OclAny, n : OclAny, mth : OclAny, nth : OclAny) : OclAny pre: true post: true activity: var d : double := (((mth - nth)->abs()) / ((m - 1) - (n - 1))->abs()) ; var a : double := mth - ((m - 1) * d) ; return a, d; operation findSum(m : OclAny, n : OclAny, mth : OclAny, nth : OclAny, p : OclAny) : OclAny pre: true post: true activity: Sequence{a,d} := findingValues(m, n, mth, nth) ; var Sum : double := (p * (2 * a + (p - 1) * d)) / 2 ; return Sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count_unique(s,n): if(s.count(n)): return ; s.append(n); n+=1 ; while(n % 10==0): n=n//10 ; count_unique(s,n); if __name__=="__main__" : n=10 s=[] count_unique(s,n) print(len(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 10 ; s := Sequence{} ; count_unique(s, n) ; execute ((s)->size())->display() ) else skip; operation count_unique(s : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (s->count(n)) then ( return; ) else skip ; execute ((n) : s); ; n := n + 1; ; while (n mod 10 = 0) do ( n := n div 10;) ; count_unique(s, n);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=1000000007 ; def noOfBinaryStrings(N,k): dp=[0]*100002 ; for i in range(1,K): dp[i]=1 ; dp[k]=2 ; for i in range(k+1,N+1): dp[i]=(dp[i-1]+dp[i-k])% mod ; return dp[N]; if __name__=="__main__" : N=4 ; K=2 ; print(noOfBinaryStrings(N,K)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : int := 1000000007; ; skip ; if __name__ = "__main__" then ( N := 4; ; var K : int := 2; ; execute (noOfBinaryStrings(N, K))->display(); ) else skip; operation noOfBinaryStrings(N : OclAny, k : OclAny) pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100002); ; for i : Integer.subrange(1, K-1) do ( dp[i+1] := 1;) ; dp[k+1] := 2; ; for i : Integer.subrange(k + 1, N + 1-1) do ( dp[i+1] := (dp[i - 1+1] + dp[i - k+1]) mod mod;) ; return dp[N+1];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=input().split() n=int(n) m=int(m) names=[] ips=[] commands=[] ips1=[] for i in range(0,n): name,ip=input().split() names.append(name) ips.append(ip) for i in range(0,m): command,ip1=input().split() commands.append(command) ips1.append(ip1) for j in range(0,len(ips1)): for k in range(0,len(ips)): if ips1[j]==ips[k]+';' : print(commands[j]+" "+ips1[j]+" #"+names[k]) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var m : int := ("" + ((m)))->toInteger() ; var names : Sequence := Sequence{} ; var ips : Sequence := Sequence{} ; var commands : Sequence := Sequence{} ; var ips1 : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var name : OclAny := null; var ip : OclAny := null; Sequence{name,ip} := input().split() ; execute ((name) : names) ; execute ((ip) : ips)) ; for i : Integer.subrange(0, m-1) do ( var command : OclAny := null; var ip1 : OclAny := null; Sequence{command,ip1} := input().split() ; execute ((command) : commands) ; execute ((ip1) : ips1)) ; for j : Integer.subrange(0, (ips1)->size()-1) do ( for k : Integer.subrange(0, (ips)->size()-1) do ( if ips1[j+1] = ips[k+1] + ';' then ( execute (commands[j+1] + " " + ips1[j+1] + " #" + names[k+1])->display() ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fib(n): phi=((1+(5**(1/2)))/2); return round((phi**n)/(5**(1/2))); def calculateSum(l,r): sum=0 ; for i in range(l,r+1): sum+=fib(i); return sum ; if __name__=='__main__' : l,r=4,8 ; print(calculateSum(l,r)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( Sequence{l,r} := Sequence{4,8}; ; execute (calculateSum(l, r))->display(); ) else skip; operation fib(n : OclAny) pre: true post: true activity: var phi : double := ((1 + ((5)->pow((1 / 2)))) / 2); ; return (((phi)->pow(n)) / ((5)->pow((1 / 2))))->round();; operation calculateSum(l : OclAny, r : OclAny) pre: true post: true activity: var sum : int := 0; ; for i : Integer.subrange(l, r + 1-1) do ( sum := sum + fib(i);) ; return sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- str_line=input().strip().split(" ") int_line=list(map(int,str_line)) int_line.sort() str_line=list(map(str,int_line)) print(" ".join(str_line)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var str_line : OclAny := input()->trim().split(" ") ; var int_line : Sequence := ((str_line)->collect( _x | (OclType["int"])->apply(_x) )) ; int_line := int_line->sort() ; str_line := ((int_line)->collect( _x | (OclType["String"])->apply(_x) )) ; execute (StringLib.sumStringsWithSeparator((str_line), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,n=map(int,input().split()) final=m+n d={} l=[] for i in range(m+n): s=input() a=s.split() l.append(a) d[a[1]]=a[0] for i in range(m,m+n): ans="" st1=l[i][0] num=l[i][1] first=d[num[: len(num)-1]] ans=st1+" "+str(num)+" "+"#"+first print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var final : OclAny := m + n ; var d : OclAny := Set{} ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, m + n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var a : OclAny := s.split() ; execute ((a) : l) ; d[a[1+1]+1] := a->first()) ; for i : Integer.subrange(m, m + n-1) do ( var ans : String := "" ; var st1 : OclAny := l[i+1]->first() ; var num : OclAny := l[i+1][1+1] ; var first : OclAny := d[num.subrange(1,(num)->size() - 1)+1] ; ans := st1 + " " + ("" + ((num))) + " " + "#" + first ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) j={} for i in range(n): k=input().split() b,v=k[0],k[1]+";" j[v]=b for i in range(m): v=input().split() b,h=v[0],v[1] print(f"{b+' '+h}#{j[h]}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var j : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var k : OclAny := input().split() ; var b : OclAny := null; var v : OclAny := null; Sequence{b,v} := Sequence{k->first(),k[1+1] + ";"} ; j[v+1] := b) ; for i : Integer.subrange(0, m-1) do ( var v : OclAny := input().split() ; var b : OclAny := null; var h : OclAny := null; Sequence{b,h} := Sequence{v->first(),v[1+1]} ; execute (StringLib.formattedString("{b+' '+h}#{j[h]}"))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=input().split() r=[] u=[] n,m=int(n),int(m) for i in range(n): a,b=input().split() r.append((a,b)) for _ in range(m): a,b=input().split() b=b[:-1] for i in range(len(r)): if r[i][1]==b : print(a+' '+b+'; #'+r[i][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split() ; var r : Sequence := Sequence{} ; var u : Sequence := Sequence{} ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{("" + ((n)))->toInteger(),("" + ((m)))->toInteger()} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; execute ((Sequence{a, b}) : r)) ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; var b : OclAny := b->front() ; for i : Integer.subrange(0, (r)->size()-1) do ( if r[i+1][1+1] = b then ( execute (a + ' ' + b + '; #' + r[i+1]->first())->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=(int(i)for i in input().split("")) i=0 server_names={} for i in range(n): name,ip=input().split("") server_names[ip]=name for i in range(m): command=input() print(command,end="") ip=command.split()[1][:-1] print(" #"+server_names[ip]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ""))))))) ))))))))} ; var i : int := 0 ; var server_names : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var name : OclAny := null; var ip : OclAny := null; Sequence{name,ip} := input().split("") ; server_names[ip+1] := name) ; for i : Integer.subrange(0, m-1) do ( var command : String := (OclFile["System.in"]).readLine() ; execute (command)->display() ; var ip : OclAny := command.split()[1+1]->front() ; execute (" #" + server_names[ip+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,l=list(map(int,input().split())) a=list(map(int,input().split())) a.sort() d=a[0] for i in range(n-1): d=max(d,(a[i+1]-a[i])/2) d=max(d,l-a[-1]) print(d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; Sequence{n,l} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var d : OclAny := a->first() ; for i : Integer.subrange(0, n - 1-1) do ( d := Set{d, (a[i + 1+1] - a[i+1]) / 2}->max()) ; d := Set{d, l - a->last()}->max() ; execute (d)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,l=input().split() n=int(n) l=int(l) a=[] b=input().split() for i in range(n): a.append(int(b[i])) st=a.sort() st_dis=[] for i in range(n-1): st_dis.append(a[i+1]-a[i]) st_dis.append(a[0]*2) st_dis.append((l-a[n-1])*2) st_dis.sort() print('%.10f' %(st_dis[n]/2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; Sequence{n,l} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var l : int := ("" + ((l)))->toInteger() ; var a : Sequence := Sequence{} ; var b : OclAny := input().split() ; for i : Integer.subrange(0, n-1) do ( execute ((("" + ((b[i+1])))->toInteger()) : a)) ; var st : OclAny := a->sort() ; var st_dis : Sequence := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( execute ((a[i + 1+1] - a[i+1]) : st_dis)) ; execute ((a->first() * 2) : st_dis) ; execute (((l - a[n - 1+1]) * 2) : st_dis) ; st_dis := st_dis->sort() ; execute (StringLib.format('%.10f',(st_dis[n+1] / 2)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,l=map(int,input().split()) a=list(map(int,input().split())) a.sort() b=a t=0 c=[] d=[] if n==1 : d.append(a[0]) d.append(l-a[0]) print(max(d)) else : while True : c.append(b[t+1]-b[t]) t+=1 if t+1==len(b): break if a[0]>=max(c)/2 and a[0]>=l-a[-1]: print(a[0]) elif l-a[-1]>=max(c)/2 and a[0]<=l-a[-1]: print(l-a[-1]) else : print(max(c)/2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; Sequence{n,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var b : Sequence := a ; var t : int := 0 ; var c : Sequence := Sequence{} ; var d : Sequence := Sequence{} ; if n = 1 then ( execute ((a->first()) : d) ; execute ((l - a->first()) : d) ; execute ((d)->max())->display() ) else ( while true do ( execute ((b[t + 1+1] - b[t+1]) : c) ; t := t + 1 ; if t + 1 = (b)->size() then ( break ) else skip) ; if (a->first()->compareTo((c)->max() / 2)) >= 0 & (a->first()->compareTo(l - a->last())) >= 0 then ( execute (a->first())->display() ) else (if (l - a->last()->compareTo((c)->max() / 2)) >= 0 & (a->first()->compareTo(l - a->last())) <= 0 then ( execute (l - a->last())->display() ) else ( execute ((c)->max() / 2)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,l=map(int,input().split()) lanternList=list(map(int,input().split())) lanternList.sort() distanceList=[lanternList[0]] if n>1 : for i in range(1,n): distanceList.append((lanternList[i]-lanternList[i-1])/2) distanceList.append(l-lanternList[-1]) print(max(distanceList)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; Sequence{n,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lanternList : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; lanternList := lanternList->sort() ; var distanceList : Sequence := Sequence{ lanternList->first() } ; if n > 1 then ( for i : Integer.subrange(1, n-1) do ( execute (((lanternList[i+1] - lanternList[i - 1+1]) / 2) : distanceList)) ) else skip ; execute ((l - lanternList->last()) : distanceList) ; execute ((distanceList)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from turtle import pos,position numOfLanterns,length=map(int,input().split()) position=list(map(int,input().split())) position.sort() mxDis=max(position[0],length-position[-1]) for i in range(1,len(position)): mxDis=max((position[i]-position[i-1])/2,mxDis) print(mxDis) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var numOfLanterns : OclAny := null; var length : OclAny := null; Sequence{numOfLanterns,length} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var position : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; position := position->sort() ; var mxDis : OclAny := Set{position->first(), length - position->last()}->max() ; for i : Integer.subrange(1, (position)->size()-1) do ( mxDis := Set{(position[i+1] - position[i - 1+1]) / 2, mxDis}->max()) ; execute (mxDis)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for trf in range(t): n=int(input()) s=input() a=input() sum=0 for i in range(n): if s[i]!='R' and a[i]!='R' : sum=sum+1 continue if s[i]=='R' and a[i]=='R' : sum=sum+1 if sum==n : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for trf : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var a : String := (OclFile["System.in"]).readLine() ; var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( if s[i+1] /= 'R' & a[i+1] /= 'R' then ( sum := sum + 1 ; continue ) else skip ; if s[i+1] = 'R' & a[i+1] = 'R' then ( sum := sum + 1 ) else skip) ; if sum = n then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minAdjDifference(arr,n): if(n<2): return res=abs(arr[1]-arr[0]) for i in range(2,n): res=min(res,abs(arr[i]-arr[i-1])) res=min(res,abs(arr[n-1]-arr[0])) print("Min Difference=",res) a=[10,12,13,15,10] n=len(a) minAdjDifference(a,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : Sequence := Sequence{10}->union(Sequence{12}->union(Sequence{13}->union(Sequence{15}->union(Sequence{ 10 })))) ; n := (a)->size() ; minAdjDifference(a, n); operation minAdjDifference(arr : OclAny, n : OclAny) pre: true post: true activity: if (n < 2) then ( return ) else skip ; var res : double := (arr[1+1] - arr->first())->abs() ; for i : Integer.subrange(2, n-1) do ( res := Set{res, (arr[i+1] - arr[i - 1+1])->abs()}->min()) ; res := Set{res, (arr[n - 1+1] - arr->first())->abs()}->min() ; execute ("Min Difference=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=list(map(int,input().split())) a.sort() for i in range(3): if i!=2 : print(a[i],end=" ") else : print(a[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; for i : Integer.subrange(0, 3-1) do ( if i /= 2 then ( execute (a[i+1])->display() ) else ( execute (a[i+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def KPrimeDivisors(n,k): maximum_split=0 while n % 2==0 : maximum_split+=1 n=n//2 for i in range(3,mt.ceil(mt.sqrt(n)),2): while n % i==0 : n=n/i ; maximum_split+=1 if n>2 : maximum_split+=1 if maximum_splitselect( $x | ($x - 3) mod 2 = 0 ) do ( while n mod i = 0 do ( n := n / i; ; maximum_split := maximum_split + 1)) ; if n > 2 then ( maximum_split := maximum_split + 1 ) else skip ; if (maximum_split->compareTo(k)) < 0 then ( execute ("No")->display() ; return ) else skip ; execute ("Yes")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib,itertools def compute(): cond=lambda n : num_prime_sum_ways(n)>5000 ans=next(filter(cond,itertools.count(2))) return str(ans) primes=[2] def num_prime_sum_ways(n): for i in range(primes[-1]+1,n+1): if eulerlib.is_prime(i): primes.append(i) ways=[1]+[0]*n for p in primes : for i in range(n+1-p): ways[i+p]+=ways[i] return ways[n] if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var primes : Sequence := Sequence{ 2 } ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var cond : Function := lambda n : OclAny in (num_prime_sum_ways(n) > 5000) ; var ans : OclAny := ((itertools->count(2))->select( _x | (cond)->apply(_x) = true )).next() ; return ("" + ((ans))); operation num_prime_sum_ways(n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(primes->last() + 1, n + 1-1) do ( if eulerlib.is_prime(i) then ( execute ((i) : primes) ) else skip) ; var ways : Sequence := Sequence{ 1 }->union(MatrixLib.elementwiseMult(Sequence{ 0 }, n)) ; for p : primes do ( for i : Integer.subrange(0, n + 1 - p-1) do ( ways[i + p+1] := ways[i + p+1] + ways[i+1])) ; return ways[n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def minimumMulitplications(start,end,a,n): ans=[-1 for i in range(100001)] mod=100000 q=deque() q.append(start % mod) ans[start]=0 while(len(q)>0): top=q.popleft() if(top==end): return ans[end] for i in range(n): pushed=top*a[i] pushed=pushed % mod if(ans[pushed]==-1): ans[pushed]=ans[top]+1 q.append(pushed) return-1 start=7 end=66175 a=[3,4,65] n=len(a) print(minimumMulitplications(start,end,a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; start := 7 ; end := 66175 ; a := Sequence{3}->union(Sequence{4}->union(Sequence{ 65 })) ; n := (a)->size() ; execute (minimumMulitplications(start, end, a, n))->display(); operation minimumMulitplications(start : OclAny, end : OclAny, a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : Sequence := Integer.subrange(0, 100001-1)->select(i | true)->collect(i | (-1)) ; var mod : int := 100000 ; var q : Sequence := () ; execute ((start mod mod) : q) ; ans[start+1] := 0 ; while ((q)->size() > 0) do ( var top : OclAny := q->first() ; q := q->tail() ; if (top = end) then ( return ans[end+1] ) else skip ; for i : Integer.subrange(0, n-1) do ( var pushed : double := top * a[i+1] ; pushed := pushed mod mod ; if (ans[pushed+1] = -1) then ( ans[pushed+1] := ans[top+1] + 1 ; execute ((pushed) : q) ) else skip)) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findseason(M): list1=[[12,1,2],[3,4,5],[6,7,8],[9,10,11]] if M in list1[0]: print("WINTER") elif M in list1[1]: print("SPRING") elif M in list1[2]: print("SUMMER") elif M in list1[3]: print("AUTUMN") else : print("Invalid Month Number") M=5 print("For Month number:",M); findseason(M) M=10 print("For Month number:",M); findseason(M) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; M := 5 ; execute ("For Month number:")->display(); ; findseason(M) ; M := 10 ; execute ("For Month number:")->display(); ; findseason(M); operation findseason(M : OclAny) pre: true post: true activity: var list1 : Sequence := Sequence{Sequence{12}->union(Sequence{1}->union(Sequence{ 2 }))}->union(Sequence{Sequence{3}->union(Sequence{4}->union(Sequence{ 5 }))}->union(Sequence{Sequence{6}->union(Sequence{7}->union(Sequence{ 8 }))}->union(Sequence{ Sequence{9}->union(Sequence{10}->union(Sequence{ 11 })) }))) ; if (list1->first())->includes(M) then ( execute ("WINTER")->display() ) else (if (list1[1+1])->includes(M) then ( execute ("SPRING")->display() ) else (if (list1[2+1])->includes(M) then ( execute ("SUMMER")->display() ) else (if (list1[3+1])->includes(M) then ( execute ("AUTUMN")->display() ) else ( execute ("Invalid Month Number")->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for _ in range(T): n=int(input()) lst=list(map(int,input().split())) m=max(lst) diclstfront=[{}] diclstback=[{}] xFront,xBack=0,0 for i in lst : if i in diclstfront[xFront].keys(): diclstfront.append({}) xFront+=1 diclstfront[xFront][i]=1 for i in lst[: :-1]: if i in diclstback[xBack].keys(): diclstback.append({}) xBack+=1 diclstback[xBack][i]=1 ans=0 lst=[] if len(diclstfront)==2 : lst1=list(diclstfront[0].keys()) lst2=list(diclstfront[1].keys()) m1,m2=max(lst1),max(lst2) if sorted(lst1)==list(range(1,m1+1))and sorted(lst2)==list(range(1,m2+1)): ans+=1 lst.append([len(lst1),len(lst2)]) if len(diclstback)==2 : lst1=list(diclstback[0].keys()) lst2=list(diclstback[1].keys()) m1,m2=max(lst1),max(lst2) if sorted(lst1)==list(range(1,m1+1))and sorted(lst2)==list(range(1,m2+1))and[len(lst2),len(lst1)]not in lst : ans+=1 lst.append([len(lst2),len(lst1)]) print(ans) for i in range(ans): print(lst[i][0],' ',lst[i][1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, T-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : OclAny := (lst)->max() ; var diclstfront : Sequence := Sequence{ Set{} } ; var diclstback : Sequence := Sequence{ Set{} } ; var xFront : OclAny := null; var xBack : OclAny := null; Sequence{xFront,xBack} := Sequence{0,0} ; for i : lst do ( if (diclstfront[xFront+1].keys())->includes(i) then ( execute ((Set{}) : diclstfront) ; xFront := xFront + 1 ) else skip ; diclstfront[xFront+1][i+1] := 1) ; for i : lst(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if (diclstback[xBack+1].keys())->includes(i) then ( execute ((Set{}) : diclstback) ; xBack := xBack + 1 ) else skip ; diclstback[xBack+1][i+1] := 1) ; var ans : int := 0 ; lst := Sequence{} ; if (diclstfront)->size() = 2 then ( var lst1 : Sequence := (diclstfront->first().keys()) ; var lst2 : Sequence := (diclstfront[1+1].keys()) ; var m1 : OclAny := null; var m2 : OclAny := null; Sequence{m1,m2} := Sequence{(lst1)->max(),(lst2)->max()} ; if lst1->sort() = (Integer.subrange(1, m1 + 1-1)) & lst2->sort() = (Integer.subrange(1, m2 + 1-1)) then ( ans := ans + 1 ; execute ((Sequence{(lst1)->size()}->union(Sequence{ (lst2)->size() })) : lst) ) else skip ) else skip ; if (diclstback)->size() = 2 then ( lst1 := (diclstback->first().keys()) ; lst2 := (diclstback[1+1].keys()) ; var m1 : OclAny := null; var m2 : OclAny := null; Sequence{m1,m2} := Sequence{(lst1)->max(),(lst2)->max()} ; if lst1->sort() = (Integer.subrange(1, m1 + 1-1)) & lst2->sort() = (Integer.subrange(1, m2 + 1-1)) & (lst)->excludes(Sequence{(lst2)->size()}->union(Sequence{ (lst1)->size() })) then ( ans := ans + 1 ; execute ((Sequence{(lst2)->size()}->union(Sequence{ (lst1)->size() })) : lst) ) else skip ) else skip ; execute (ans)->display() ; for i : Integer.subrange(0, ans-1) do ( execute (lst[i+1]->first())->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin tt=int(stdin.readline()) ANS=[] for loop in range(tt): n=int(stdin.readline()) a=list(map(int,stdin.readline().split())) LL=[False] s=set() nmax=0 for i in range(n): if a[i]in s : nmax=float("inf") nmax=max(nmax,a[i]) s.add(a[i]) if len(s)==i+1==nmax : LL.append(True) else : LL.append(False) a.reverse() RR=[False] s=set() nmax=0 for i in range(n): if a[i]in s : nmax=float("inf") nmax=max(nmax,a[i]) s.add(a[i]) if len(s)==i+1==nmax : RR.append(True) else : RR.append(False) RR.reverse() ans=[] for i in range(n+1): if LL[i]and RR[i]: ans.append(str(i)+" "+str(n-i)) ANS.append(len(ans)) if len(ans)!=0 : ANS.append("\n".join(ans)) print("\n".join(map(str,ANS))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var tt : int := ("" + ((stdin.readLine())))->toInteger() ; var ANS : Sequence := Sequence{} ; for loop : Integer.subrange(0, tt-1) do ( var n : int := ("" + ((stdin.readLine())))->toInteger() ; var a : Sequence := ((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var LL : Sequence := Sequence{ false } ; var s : Set := Set{}->union(()) ; var nmax : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (s)->includes(a[i+1]) then ( nmax := ("" + (("inf")))->toReal() ) else skip ; nmax := Set{nmax, a[i+1]}->max() ; execute ((a[i+1]) : s) ; if (s)->size() = i + 1 & (i + 1 == nmax) then ( execute ((true) : LL) ) else ( execute ((false) : LL) )) ; a := a->reverse() ; var RR : Sequence := Sequence{ false } ; s := Set{}->union(()) ; nmax := 0 ; for i : Integer.subrange(0, n-1) do ( if (s)->includes(a[i+1]) then ( nmax := ("" + (("inf")))->toReal() ) else skip ; nmax := Set{nmax, a[i+1]}->max() ; execute ((a[i+1]) : s) ; if (s)->size() = i + 1 & (i + 1 == nmax) then ( execute ((true) : RR) ) else ( execute ((false) : RR) )) ; RR := RR->reverse() ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, n + 1-1) do ( if LL[i+1] & RR[i+1] then ( execute ((("" + ((i))) + " " + ("" + ((n - i)))) : ans) ) else skip) ; execute (((ans)->size()) : ANS) ; if (ans)->size() /= 0 then ( execute ((StringLib.sumStringsWithSeparator((ans), "\n")) : ANS) ) else skip) ; execute (StringLib.sumStringsWithSeparator(((ANS)->collect( _x | (OclType["String"])->apply(_x) )), "\n"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fun(lst,ele,n): dic1={} for j in range(1,ele+1): dic1[j]=0 e=0 for j in range(ele): if lst[j]not in dic1 : e+=1 break else : dic1[lst[j]]+=1 for j in dic1.keys(): if dic1[j]!=1 : e+=1 break dic1={} for j in range(1,n-ele+1): dic1[j]=0 for j in range(ele,n): if lst[j]not in dic1 : e+=1 break else : dic1[lst[j]]+=1 for j in dic1.keys(): if dic1[j]!=1 : e+=1 break if e==0 : return 1 return 0 t=int(input()) for i in range(t): n=int(input()) lst=list(map(int,input().split())) ma=max(lst) s=set() if fun(lst,ma,n)==1 : s.add((ma,n-ma)) if fun(lst,n-ma,n)==1 : s.add((n-ma,ma)) l=len(s) print(l) for j in s : print(j[0],j[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; lst := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ma : OclAny := (lst)->max() ; var s : Set := Set{}->union(()) ; if fun(lst, ma, n) = 1 then ( execute ((Sequence{ma, n - ma}) : s) ) else skip ; if fun(lst, n - ma, n) = 1 then ( execute ((Sequence{n - ma, ma}) : s) ) else skip ; var l : int := (s)->size() ; execute (l)->display() ; for j : s do ( execute (j->first())->display())); operation fun(lst : OclAny, ele : OclAny, n : OclAny) : OclAny pre: true post: true activity: var dic1 : OclAny := Set{} ; for j : Integer.subrange(1, ele + 1-1) do ( dic1[j+1] := 0) ; var e : int := 0 ; for j : Integer.subrange(0, ele-1) do ( if (dic1)->excludes(lst[j+1]) then ( e := e + 1 ; break ) else ( dic1[lst[j+1]+1] := dic1[lst[j+1]+1] + 1 )) ; for j : dic1.keys() do ( if dic1[j+1] /= 1 then ( e := e + 1 ; break ) else skip) ; dic1 := Set{} ; for j : Integer.subrange(1, n - ele + 1-1) do ( dic1[j+1] := 0) ; for j : Integer.subrange(ele, n-1) do ( if (dic1)->excludes(lst[j+1]) then ( e := e + 1 ; break ) else ( dic1[lst[j+1]+1] := dic1[lst[j+1]+1] + 1 )) ; for j : dic1.keys() do ( if dic1[j+1] /= 1 then ( e := e + 1 ; break ) else skip) ; if e = 0 then ( return 1 ) else skip ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t=int(input()) ans=[] for _ in range(t): n=int(input()) a=list(map(int,input().split())) okl=[0]*n visit=[0]*(n+1) c=0 ma=0 for i in range(n): ai=a[i] if visit[ai]: break visit[ai]=1 ma=max(ma,ai) c+=1 if c ^ ma : continue okl[i]=1 okr=[0]*n visit=[0]*(n+1) c=0 ma=0 for i in range(n-1,-1,-1): ai=a[i] if visit[ai]: break visit[ai]=1 ma=max(ma,ai) c+=1 if c ^ ma : continue okr[i]=1 ans0=[] for i in range(1,n): if okl[i-1]and okr[i]: ans0.append(" ".join(map(str,(i,n-i)))) k=len(ans0) ans.append(str(k)) if k : ans.append("\n".join(ans0)) sys.stdout.write("\n".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var okl : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var visit : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var c : int := 0 ; var ma : int := 0 ; for i : Integer.subrange(0, n-1) do ( var ai : OclAny := a[i+1] ; if visit[ai+1] then ( break ) else skip ; visit[ai+1] := 1 ; ma := Set{ma, ai}->max() ; c := c + 1 ; if MathLib.bitwiseXor(c, ma) then ( continue ) else skip ; okl[i+1] := 1) ; var okr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; visit := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; c := 0 ; ma := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( ai := a[i+1] ; if visit[ai+1] then ( break ) else skip ; visit[ai+1] := 1 ; ma := Set{ma, ai}->max() ; c := c + 1 ; if MathLib.bitwiseXor(c, ma) then ( continue ) else skip ; okr[i+1] := 1) ; var ans0 : Sequence := Sequence{} ; for i : Integer.subrange(1, n-1) do ( if okl[i - 1+1] & okr[i+1] then ( execute ((StringLib.sumStringsWithSeparator(((Sequence{i, n - i})->collect( _x | (OclType["String"])->apply(_x) )), " ")) : ans0) ) else skip) ; var k : int := (ans0)->size() ; execute ((("" + ((k)))) : ans) ; if k then ( execute ((StringLib.sumStringsWithSeparator((ans0), "\n")) : ans) ) else skip) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math MAX=1000000 def fib(n): phi=(1+math.sqrt(5))/2 return round(pow(phi,n)/math.sqrt(5)) def calculateSum(l,r): sum=fib(r+2)-fib(l+1) return sum def sumFibonacci(k): l=(k*(k-1))/2 r=l+k sum=calculateSum(l,r-1) return sum k=3 print(sumFibonacci(k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MAX : int := 1000000 ; skip ; skip ; skip ; k := 3 ; execute (sumFibonacci(k))->display(); operation fib(n : OclAny) : OclAny pre: true post: true activity: var phi : double := (1 + (5)->sqrt()) / 2 ; return ((phi)->pow(n) / (5)->sqrt())->round(); operation calculateSum(l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var sum : double := fib(r + 2) - fib(l + 1) ; return sum; operation sumFibonacci(k : OclAny) : OclAny pre: true post: true activity: l := (k * (k - 1)) / 2 ; r := l + k ; sum := calculateSum(l, r - 1) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n=int(input()) w=list(map(int,input().split())) x=max(w) if x>=n : print(0) continue d=set() if sorted(w[: x])==list(range(1,x+1))and sorted(w[x :])==list(range(1,n-x+1)): d.add((x,n-x)) if sorted(w[: n-x])==list(range(1,n-x+1))and sorted(w[n-x :])==list(range(1,x+1)): d.add((n-x,x)) print(len(d)) for i in d : print(*i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := (w)->max() ; if (x->compareTo(n)) >= 0 then ( execute (0)->display() ; continue ) else skip ; var d : Set := Set{}->union(()) ; if w.subrange(1,x)->sort() = (Integer.subrange(1, x + 1-1)) & w.subrange(x+1)->sort() = (Integer.subrange(1, n - x + 1-1)) then ( execute ((Sequence{x, n - x}) : d) ) else skip ; if w.subrange(1,n - x)->sort() = (Integer.subrange(1, n - x + 1-1)) & w.subrange(n - x+1)->sort() = (Integer.subrange(1, x + 1-1)) then ( execute ((Sequence{n - x, x}) : d) ) else skip ; execute ((d)->size())->display() ; for i : d do ( execute ((argument * (test (logical_test (comparison (expr (atom (name i))))))))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import exit n,p,q=map(int,input().split()) s=input() num1=n//p+1 num2=n//q+1 for i in range(num1): for j in range(num2): if i*p+j*q==n : print(i+j) for c in range(0,i*p,p): print(s[c : c+p]) for c in range(i*p,n,q): print(s[c : c+q]) exit() print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var p : OclAny := null; var q : OclAny := null; Sequence{n,p,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var num1 : int := n div p + 1 ; var num2 : int := n div q + 1 ; for i : Integer.subrange(0, num1-1) do ( for j : Integer.subrange(0, num2-1) do ( if i * p + j * q = n then ( execute (i + j)->display() ; for c : Integer.subrange(0, i * p-1)->select( $x | ($x - 0) mod p = 0 ) do ( execute (s.subrange(c+1, c + p))->display()) ; for c : Integer.subrange(i * p, n-1)->select( $x | ($x - i * p) mod q = 0 ) do ( execute (s.subrange(c+1, c + q))->display()) ; exit() ) else skip)) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cor=list(map(int,input().split())) fdd=0 def right(aa): xa,ya,xb,yb,xc,yc=(aa[j]for j in range(6)) a=(xb-xa)**2+(yb-ya)**2 b=(xc-xa)**2+(yc-ya)**2 c=(xc-xb)**2+(yc-yb)**2 ver=0 if a+b==c or a+c==b or b+c==a : if a*b*c!=0 : ver+=1 return ver fdd+=right(cor) if fdd!=0 : print("RIGHT") else : for i in range(len(cor)): cor[i]+=1 fdd+=right(cor) cor[i]-=2 fdd+=right(cor) cor[i]+=1 if fdd!=0 : print("ALMOST") else : print("NEITHER") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cor : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var fdd : int := 0 ; skip ; fdd := fdd + right(cor) ; if fdd /= 0 then ( execute ("RIGHT")->display() ) else ( for i : Integer.subrange(0, (cor)->size()-1) do ( cor[i+1] := cor[i+1] + 1 ; fdd := fdd + right(cor) ; cor[i+1] := cor[i+1] - 2 ; fdd := fdd + right(cor) ; cor[i+1] := cor[i+1] + 1) ; if fdd /= 0 then ( execute ("ALMOST")->display() ) else ( execute ("NEITHER")->display() ) ); operation right(aa : OclAny) : OclAny pre: true post: true activity: var xa : OclAny := null; var ya : OclAny := null; var xb : OclAny := null; var yb : OclAny := null; var xc : OclAny := null; var yc : OclAny := null; Sequence{xa,ya,xb,yb,xc,yc} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name aa)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 6))))))))) ))))))))} ; var a : double := ((xb - xa))->pow(2) + ((yb - ya))->pow(2) ; var b : double := ((xc - xa))->pow(2) + ((yc - ya))->pow(2) ; var c : double := ((xc - xb))->pow(2) + ((yc - yb))->pow(2) ; var ver : int := 0 ; if a + b = c or a + c = b or b + c = a then ( if a * b * c /= 0 then ( ver := ver + 1 ) else skip ) else skip ; return ver; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,p,q=map(int,input().split(' ')[: 3]) s=input()[: n] a=0 b=0 while True : if a*p+b*q==n : break a+=1 if a*p>n : a=0 b+=1 if b*q>n : print(-1) exit(0) print(a+b) z=0 for i in range(a): print(s[z : z+p]) z+=p for i in range(b): print(s[z : z+q]) z+=q ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var p : OclAny := null; var q : OclAny := null; Sequence{n,p,q} := (input().split(' ').subrange(1,3))->collect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := input().subrange(1,n) ; var a : int := 0 ; var b : int := 0 ; while true do ( if a * p + b * q = n then ( break ) else skip ; a := a + 1 ; if (a * p->compareTo(n)) > 0 then ( a := 0 ; b := b + 1 ; if (b * q->compareTo(n)) > 0 then ( execute (-1)->display() ; exit(0) ) else skip ) else skip) ; execute (a + b)->display() ; var z : int := 0 ; for i : Integer.subrange(0, a-1) do ( execute (s.subrange(z+1, z + p))->display() ; z := z + p) ; for i : Integer.subrange(0, b-1) do ( execute (s.subrange(z+1, z + q))->display() ; z := z + q); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,p,q=map(int,input().split()) s=input() for x in range(0,100): for y in range(0,100): if x*p+y*q==n : print(x+y) at=0 for _ in range(x): print(s[at : at+p]) at+=p for _ in range(y): print(s[at : at+q]) at+=q exit(0) print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var p : OclAny := null; var q : OclAny := null; Sequence{n,p,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; for x : Integer.subrange(0, 100-1) do ( for y : Integer.subrange(0, 100-1) do ( if x * p + y * q = n then ( execute (x + y)->display() ; var at : int := 0 ; for _anon : Integer.subrange(0, x-1) do ( execute (s.subrange(at+1, at + p))->display() ; at := at + p) ; for _anon : Integer.subrange(0, y-1) do ( execute (s.subrange(at+1, at + q))->display() ; at := at + q) ; exit(0) ) else skip)) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,p,q=map(int,input().split()) s=input() for i in range(n//p+1): if(n-i*p)% q==0 : print(i+(n-i*p)//q) for j in range(i): print(s[j*p : j*p+p]) for j in range((n-i*p)//q): print(s[i*p+j*q : i*p+j*q+q]) exit() print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var p : OclAny := null; var q : OclAny := null; Sequence{n,p,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, n div p + 1-1) do ( if (n - i * p) mod q = 0 then ( execute (i + (n - i * p) div q)->display() ; for j : Integer.subrange(0, i-1) do ( execute (s.subrange(j * p+1, j * p + p))->display()) ; for j : Integer.subrange(0, (n - i * p) div q-1) do ( execute (s.subrange(i * p + j * q+1, i * p + j * q + q))->display()) ; exit() ) else skip) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,p,q=list(map(int,input().split())) s=str(input()) i,f=0,0 while(1): c=n-(i*p) if c<0 : break if c % q==0 : f=1 break i+=1 if f : d=c//q print(i+d) v,x,y=0,0,0 while(xcollect( _x | (OclType["int"])->apply(_x) )) ; var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; var i : OclAny := null; var f : OclAny := null; Sequence{i,f} := Sequence{0,0} ; while (1) do ( var c : double := n - (i * p) ; if c < 0 then ( break ) else skip ; if c mod q = 0 then ( var f : int := 1 ; break ) else skip ; i := i + 1) ; if f then ( var d : int := c div q ; execute (i + d)->display() ; var v : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{v,x,y} := Sequence{0,0,0} ; while ((x->compareTo(i)) < 0) do ( var u : OclAny := s.subrange(v+1, v + p) ; execute (u)->display() ; x := x + 1 ; v := v + p) ; while ((y->compareTo(d)) < 0) do ( u := s.subrange(v+1, v + q) ; execute (u)->display() ; y := y + 1 ; v := v + q) ) else ( execute ("-1")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isDigit(ch): if ch>='0' and ch<='9' : return True return False def nextNonDigit(string,i): while i=len(string): return-1 return i def appendRepeated(sb,string,times): for i in range(times): sb.append(string) def findString(string,n): sb=list() startStr=nextNonDigit(string,0) while startStr!=-1 : endStr=startStr while(endStr+1size() ; execute (findString(string, n))->display() ) else skip; operation isDigit(ch : OclAny) : OclAny pre: true post: true activity: if ch >= '0' & ch <= '9' then ( return true ) else skip ; return false; operation nextNonDigit(string : OclAny, i : OclAny) : OclAny pre: true post: true activity: while (i->compareTo((string)->size())) < 0 & isDigit(string[i+1]) do ( i := i + 1) ; if (i->compareTo((string)->size())) >= 0 then ( return -1 ) else skip ; return i; operation appendRepeated(sb : OclAny, string : OclAny, times : OclAny) pre: true post: true activity: for i : Integer.subrange(0, times-1) do ( execute ((string) : sb)); operation findString(string : OclAny, n : OclAny) : OclAny pre: true post: true activity: sb := () ; var startStr : OclAny := nextNonDigit(string, 0) ; while startStr /= -1 do ( var endStr : OclAny := startStr ; while ((endStr + 1->compareTo(n)) < 0 & not(isDigit(string[endStr + 1+1]))) do ( endStr := endStr + 1) ; var startNum : OclAny := endStr + 1 ; if startNum = -1 then ( break ) else skip ; var endNum : OclAny := startNum ; while ((endNum + 1->compareTo(n)) < 0 & isDigit(string[endNum + 1+1])) do ( endNum := endNum + 1) ; var num : int := ("" + ((string.subrange(startNum+1, endNum + 1))))->toInteger() ; appendRepeated(sb, string.subrange(startStr+1, endStr + 1), num) ; startStr := nextNonDigit(string, endStr + 1)) ; sb := StringLib.sumStringsWithSeparator((sb), '') ; return sb; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- li_word=["a","i","u","e","o"] while True : num=int(input()) if num==0 : break else : li=[] for i in range(num): name=[] airport=list(input()) for i in range(len(airport)): if i==0 or airport[i-1]in li_word : name.append(airport[i]) li.append(tuple(name)) li_set=list(set(li)) if len(li)!=len(li_set): print(-1) else : a=0 while True : a+=1 check=[] for i in li : check.append(i[: a]) if len(check)==len(list(set(check))): print(a) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var li_word : Sequence := Sequence{"a"}->union(Sequence{"i"}->union(Sequence{"u"}->union(Sequence{"e"}->union(Sequence{ "o" })))) ; while true do ( var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if num = 0 then ( break ) else ( var li : Sequence := Sequence{} ; for i : Integer.subrange(0, num-1) do ( var name : Sequence := Sequence{} ; var airport : Sequence := ((OclFile["System.in"]).readLine())->characters() ; for i : Integer.subrange(0, (airport)->size()-1) do ( if i = 0 or (li_word)->includes(airport[i - 1+1]) then ( execute ((airport[i+1]) : name) ) else skip) ; execute (((name)) : li)) ; var li_set : Sequence := (Set{}->union((li))) ; if (li)->size() /= (li_set)->size() then ( execute (-1)->display() ) else ( var a : int := 0 ; while true do ( a := a + 1 ; var check : Sequence := Sequence{} ; for i : li do ( execute ((i.subrange(1,a)) : check)) ; if (check)->size() = ((Set{}->union((check))))->size() then ( execute (a)->display() ; break ) else skip) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re def enc(s): repatter=re.compile(r"[aiueo]") ans=s[0] for i in range(len(s)): if itoInteger() ; if n <>= 0 then ( break ) else skip ; s := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((enc((OclFile["System.in"]).readLine())) : s)) ; execute (func(s, max_str(s), 1))->display()) ) else skip; operation enc(s : OclAny) : OclAny pre: true post: true activity: var repatter : OclRegex := OclRegex.compile(StringLib.rawString("[aiueo]")) ; var ans : OclAny := s->first() ; for i : Integer.subrange(0, (s)->size()-1) do ( if (i->compareTo((s)->size() - 1)) < 0 & repatter.match(s[i+1]) then ( ans := ans + s[i + 1+1] ) else skip) ; return ans; operation max_str(s : OclAny) : OclAny pre: true post: true activity: ans := (s->first())->size() ; for i : s do ( ans := Set{ans, (i)->size()}->max()) ; return ans; operation func(s : OclAny, mn : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (mn->compareTo(k)) < 0 then ( return -1 ) else skip ; var ss : Sequence := Sequence{} ; for i : s do ( execute ((i.subrange(1,k)) : ss)) ; for i : Integer.subrange(0, (ss)->size() - 1-1) do ( var pp : OclAny := ss->at(0`firstArg+1) ; ss := ss->excludingAt(0+1) ; if (ss)->includes(pp) then ( return func(s, mn, k + 1) ) else skip) ; return k; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) s=[1 if i in a else 2 for i in range(1,n+1)] print(" ".join([str(i)for i in s])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Sequence := Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | (if (a)->includes(i) then 1 else 2 endif)) ; execute (StringLib.sumStringsWithSeparator((s->select(i | true)->collect(i | (("" + ((i)))))), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def fib(n): phi=(1+math.sqrt(5))/2 ; return int(round(pow(phi,n)/math.sqrt(5))); def calculateSum(l,r): sum=fib(r+2)-fib(l+1); return sum ; l=4 ; r=8 ; print(calculateSum(l,r)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; l := 4; ; r := 8; ; execute (calculateSum(l, r))->display();; operation fib(n : OclAny) pre: true post: true activity: var phi : double := (1 + (5)->sqrt()) / 2; ; return ("" + ((((phi)->pow(n) / (5)->sqrt())->round())))->toInteger();; operation calculateSum(l : OclAny, r : OclAny) pre: true post: true activity: var sum : double := fib(r + 2) - fib(l + 1); ; return sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if n==0 : break code=[] slmax=0 for i in range(n): s=input() s_code=s[0] flag=0 for j in range(len(s)-1): if s[j]=="a" or s[j]=="i" or s[j]=="u" or s[j]=="e" or s[j]=="o" : s_code+=s[j+1] slmax=max(slmax,len(s_code)) code.append(s_code) l_c=len(code) if l_c!=len(list(set(code))): print(-1) else : flag=0 for i in range(1,slmax+1): if flag==1 : break c_code=[] for j in code : c_code.append(j[: i]) if len(list(set(c_code)))==l_c : print(i) flag=1 break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var code : Sequence := Sequence{} ; var slmax : int := 0 ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var s_code : OclAny := s->first() ; var flag : int := 0 ; for j : Integer.subrange(0, (s)->size() - 1-1) do ( if s[j+1] = "a" or s[j+1] = "i" or s[j+1] = "u" or s[j+1] = "e" or s[j+1] = "o" then ( s_code := s_code + s[j + 1+1] ) else skip) ; slmax := Set{slmax, (s_code)->size()}->max() ; execute ((s_code) : code)) ; var l_c : int := (code)->size() ; if l_c /= ((Set{}->union((code))))->size() then ( execute (-1)->display() ) else ( flag := 0 ; for i : Integer.subrange(1, slmax + 1-1) do ( if flag = 1 then ( break ) else skip ; var c_code : Sequence := Sequence{} ; for j : code do ( execute ((j.subrange(1,i)) : c_code) ; if ((Set{}->union((c_code))))->size() = l_c then ( execute (i)->display() ; flag := 1 ; break ) else skip)) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] while True : n=I() if n==0 : break a=[S()for _ in range(n)] b=[] for s in a : t=s[0] for i in range(len(s)-1): if s[i]in 'aiueo' : t+=s[i+1] b.append(t) r=-1 for k in range(1,51): s=set() f=True for t in b : if t[: k]in s : f=False break s.add(t[: k]) if f : r=k break rr.append(r) return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var n : OclAny := I() ; if n = 0 then ( break ) else skip ; var a : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (S())) ; var b : Sequence := Sequence{} ; for s : a do ( var t : OclAny := s->first() ; for i : Integer.subrange(0, (s)->size() - 1-1) do ( if ('aiueo')->characters()->includes(s[i+1]) then ( t := t + s[i + 1+1] ) else skip) ; execute ((t) : b)) ; var r : int := -1 ; for k : Integer.subrange(1, 51-1) do ( s := Set{}->union(()) ; var f : boolean := true ; for t : b do ( if (s)->includes(t.subrange(1,k)) then ( f := false ; break ) else skip ; execute ((t.subrange(1,k)) : s)) ; if f then ( r := k ; break ) else skip) ; execute ((r) : rr)) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def coding(s): t='' flag=True for i in s : if flag : t+=i flag=False if i=='a' or i=='i' or i=='u' or i=='e' or i=='o' : flag=True ; return t def pre_possible(ls): flag=False for i in range(len(ls)): for j in range(i+1,len(ls)): if ls[i]==ls[j]: flag=True return flag def possible(ls,k): flag=True for i in range(len(ls)): for j in range(i+1,len(ls)): if len(ls[i])toInteger(); ; if n = 0 then ( break ) else skip ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : l)) ; var nl : Sequence := Sequence{} ; for i : l do ( execute ((coding(i)) : nl)) ; var sz : OclAny := (l->select(i | true)->collect(i | ((i)->size())))->min() ; var ll : int := 0 ; var hh : int := 50 ; if pre_possible(nl) then ( execute (-1)->display() ; continue ) else skip ; while true do ( var mid : int := (ll + hh) div 2 ; if ll = mid then ( execute (hh)->display() ; break ) else skip ; if possible(nl, mid) then ( hh := mid ) else ( ll := mid ))) ) else skip; operation coding(s : OclAny) : OclAny pre: true post: true activity: var t : String := '' ; var flag : boolean := true ; for i : s do ( if flag then ( t := t + i ; flag := false ) else skip ; if i = 'a' or i = 'i' or i = 'u' or i = 'e' or i = 'o' then ( flag := true; ) else skip) ; return t; operation pre_possible(ls : OclAny) : OclAny pre: true post: true activity: flag := false ; for i : Integer.subrange(0, (ls)->size()-1) do ( for j : Integer.subrange(i + 1, (ls)->size()-1) do ( if ls[i+1] = ls[j+1] then ( flag := true ) else skip)) ; return flag; operation possible(ls : OclAny, k : OclAny) : OclAny pre: true post: true activity: flag := true ; for i : Integer.subrange(0, (ls)->size()-1) do ( for j : Integer.subrange(i + 1, (ls)->size()-1) do ( if ((ls[i+1])->size()->compareTo(k)) < 0 or ((ls[j+1])->size()->compareTo(k)) < 0 then ( if ls[i+1] = ls[j+1] then ( flag := false ; break ) else ( continue ) ) else skip ; if ls[i+1].subrange(0+1, k) = ls[j+1].subrange(0+1, k) then ( flag := false ; break ) else skip) ; if not((flag)) then ( break ) else skip) ; return flag; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cal(p): a,b,x,y,n,m=p[0],p[1],p[2],p[3],p[4],p[5] l=[(a-x)**2+(b-y)**2] l.append((a-n)**2+(b-m)**2) l.append((x-n)**2+(y-m)**2) l.sort() if l[2]==l[0]+l[1]and l[0]!=0 : return 1 else : return 0 a,b,x,y,n,m=list(map(int,input().split())) l,v=[a,b,x,y,n,m],0 if cal(l): print("RIGHT") else : w,y,f=[-1,0,1,0],[0,1,0,-1],0 for i in range(4): p=l.copy() p[v]+=w[i] p[v+1]+=y[i] if cal(p): f=1 break if f==0 : v=v+2 for i in range(4): p=l.copy() p[v]+=w[i] p[v+1]+=y[i] if cal(p): f=1 break if f==0 : v=v+2 for i in range(4): p=l.copy() p[v]+=w[i] p[v+1]+=y[i] if cal(p): f=1 break if f : print("ALMOST") else : print("NEITHER") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; var x : OclAny := null; var y : OclAny := null; var n : OclAny := null; var m : OclAny := null; Sequence{a,b,x,y,n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var v : OclAny := null; Sequence{l,v} := Sequence{Sequence{a}->union(Sequence{b}->union(Sequence{x}->union(Sequence{y}->union(Sequence{n}->union(Sequence{ m }))))),0} ; if cal(l) then ( execute ("RIGHT")->display() ) else ( var w : OclAny := null; var y : OclAny := null; var f : OclAny := null; Sequence{w,y,f} := Sequence{Sequence{-1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 0 }))),Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ -1 }))),0} ; for i : Integer.subrange(0, 4-1) do ( p := l->copy() ; p[v+1] := p[v+1] + w[i+1] ; p[v + 1+1] := p[v + 1+1] + y[i+1] ; if cal(p) then ( var f : int := 1 ; break ) else skip) ; if f = 0 then ( var v : OclAny := v + 2 ; for i : Integer.subrange(0, 4-1) do ( p := l->copy() ; p[v+1] := p[v+1] + w[i+1] ; p[v + 1+1] := p[v + 1+1] + y[i+1] ; if cal(p) then ( f := 1 ; break ) else skip) ) else skip ; if f = 0 then ( v := v + 2 ; for i : Integer.subrange(0, 4-1) do ( p := l->copy() ; p[v+1] := p[v+1] + w[i+1] ; p[v + 1+1] := p[v + 1+1] + y[i+1] ; if cal(p) then ( f := 1 ; break ) else skip) ) else skip ; if f then ( execute ("ALMOST")->display() ) else ( execute ("NEITHER")->display() ) ); operation cal(p : OclAny) : OclAny pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var x : OclAny := null; var y : OclAny := null; var n : OclAny := null; var m : OclAny := null; Sequence{a,b,x,y,n,m} := Sequence{p->first(),p[1+1],p[2+1],p[3+1],p[4+1],p[5+1]} ; var l : Sequence := Sequence{ ((a - x))->pow(2) + ((b - y))->pow(2) } ; execute ((((a - n))->pow(2) + ((b - m))->pow(2)) : l) ; execute ((((x - n))->pow(2) + ((y - m))->pow(2)) : l) ; l := l->sort() ; if l[2+1] = l->first() + l[1+1] & l->first() /= 0 then ( return 1 ) else ( return 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def next_permut(entry): m=len(entry) i=m-1 while(i>0 and entry[i]>of,"Case #%d: %d" %(x+1,t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var filename : String := "D-small-attempt0.in" ; var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(filename)) ; var of : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("D-small.out")) ; var N : int := ("" + ((f.readLine())))->toInteger() ; for x : xrange(N) do ( k := ("" + ((f.readLine())))->toInteger() ; var S : OclAny := f.readLine()->trim() ; var t : int := 1000000000 ; p := xrange(k)->select(i | true)->collect(i | (i)) ; t := Set{t, comp_size(apply_permut(p, S))}->min() ; while (next_permut(p)) do ( t := Set{t, comp_size(apply_permut(p, S))}->min()) ; print /(2->pow(of)) ; (expr (expr (atom "Case #%d: %d")) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (atom (name t))))))) ))))); operation next_permut(entry : OclAny) : OclAny pre: true post: true activity: var m : int := (entry)->size() ; var i : double := m - 1 ; while (i > 0 & (entry[i+1]->compareTo(entry[i - 1+1])) < 0) do ( i := i - 1) ; if (i = 0) then ( entry := entry->reverse() ; return false ) else skip ; var k : double := m - 1 ; while ((entry[k+1]->compareTo(entry[i - 1+1])) < 0) do ( k := k - 1) ; var entry[i - 1+1] : OclAny := null; var entry[k+1] : OclAny := null; Sequence{entry[i - 1+1],entry[k+1]} := Sequence{entry[k+1],entry[i - 1+1]} ; var x : int := 0 ; while ((i + x->compareTo(m - 1 - x)) < 0) do ( var entry[i + x+1] : OclAny := null; var entry[m - 1 - x+1] : OclAny := null; Sequence{entry[i + x+1],entry[m - 1 - x+1]} := Sequence{entry[m - 1 - x+1],entry[i + x+1]} ; x := x + 1) ; return true; operation comp_size(s : OclAny) : OclAny pre: true post: true activity: var tot : int := 0 ; var last_seen : String := '%' ; for x : xrange((s)->size()) do ( if (s[x+1] /= last_seen) then ( last_seen := s[x+1] ; tot := tot + 1 ) else skip) ; return tot; operation apply_permut(p : OclAny, s : OclAny) : OclAny pre: true post: true activity: k := (p)->size() ; var ns : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (s)->size()) ; for x : xrange((s)->size()) do ( ns[x+1] := s[p[x mod k+1] + (x div k) * k+1]) ; return StringLib.sumStringsWithSeparator((ns), ''); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def s(): import sys r=sys.stdin.readline for e in iter(r,'0\n'): R=[[]for _ in[0]*-~ int(e)] for _ in[0]*int(r()): a,b=map(int,r().split()) R[a]+=[b]; R[b]+=[a] for m in R[1][:]: R[1]+=R[m] print(len({*R[1]}-{1})) s() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s(); operation s() pre: true post: true activity: skip ; var r : OclAny := (OclFile["System.in"]).readline ; for e : OclIterator.newOclIterator_Sequence(r, '0 ') do ( var R : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, -MathLib.bitwiseNot(("" + ((e)))->toInteger()))->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + ((r())))->toInteger()) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (r().split())->collect( _x | (OclType["int"])->apply(_x) ) ; R[a+1] := R[a+1] + Sequence{ b }; R[b+1] := R[b+1] + Sequence{ a }) ; for m : R[1+1] do ( R[1+1] := R[1+1] + R[m+1]) ; execute ((Set{ R[1+1] } - Set{ 1 })->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if not n : break m=int(input()) li=[[]for _ in range(n+1)] for _ in range(m): a,b=[int(i)for i in input().split()] li[a].append(b) li[b].append(a) ans=set() for i in li[1]: ans.add(i) for j in li[i]: ans.add(j) if 1 in ans : ans.remove(1) print(len(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(n) then ( break ) else skip ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; (expr (atom (name li)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name li)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var ans : Set := Set{}->union(()) ; for i : li[1+1] do ( execute ((i) : ans) ; for j : li[i+1] do ( execute ((j) : ans))) ; if (ans)->includes(1) then ( execute ((1) /: ans) ) else skip ; execute ((ans)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): while True : n=int(input()) m=int(input()) if n==0 : break lof=[list(map(int,input().split()))for _ in range(m)] lof.sort(key=lambda x : x[0]) friend=[False]*(n+1) friend_of_friend=[False]*501*(n+1) no=0 while True : a,b=lof[no] if a==1 : friend[b]=True no+=1 else : break for i in range(no,m): a,b=lof[i] if friend[a]and not friend[b]: if friend_of_friend[b]==False : friend_of_friend[b]=True no+=1 elif friend[b]and not friend[a]: if friend_of_friend[a]==False : friend_of_friend[a]=True no+=1 print(no) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var lof : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; lof := lof->sort() ; var friend : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (n + 1)) ; var friend_of_friend : Sequence := MatrixLib.elementwiseMult(MatrixLib.elementwiseMult(Sequence{ false }, 501), (n + 1)) ; var no : int := 0 ; while true do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := lof[no+1] ; if a = 1 then ( friend[b+1] := true ; no := no + 1 ) else ( break )) ; for i : Integer.subrange(no, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := lof[i+1] ; if friend[a+1] & not(friend[b+1]) then ( if friend_of_friend[b+1] = false then ( friend_of_friend[b+1] := true ; no := no + 1 ) else skip ) else (if friend[b+1] & not(friend[a+1]) then ( if friend_of_friend[a+1] = false then ( friend_of_friend[a+1] := true ; no := no + 1 ) else skip ) else skip)) ; execute (no)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) m=int(input()) friend=[[0 for i in range(1)]for j in range(n+1)] if n==m==0 : break for i in range(m): a,b=map(int,input().split()) friend[a].append(b) friend[b].append(a) friend_1st=friend[1] friend_2nd=friend_1st[:] for i in friend_1st : friend_2nd.extend(friend[i]) ans=list(set(friend_2nd)) if 0 in ans : ans.remove(0) if 1 in ans : ans.remove(1) print(len(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var friend : Sequence := Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, 1-1)->select(i | true)->collect(i | (0)))) ; if n = m & (m == 0) then ( break ) else skip ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name friend)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name friend)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var friend var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()st : OclAny := friend[1+1] ; var friend:= friend var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()stnd : Sequence := friend var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()st ; for i : friend var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()st do ( friend.extend(friend[i+1])nd := friend.extend(friend[i+1])nd->union(friend[i+1])) ; var ans : Sequence := (Set{}->union((friend_2nd))) ; if (ans)->includes(0) then ( execute ((0) /: ans) ) else skip ; if (ans)->includes(1) then ( execute ((1) /: ans) ) else skip ; execute ((ans)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) m=int(input()) if m==0 : break dataset=[input().split()for _ in range(m)] list_={i+1 :[]for i in range(n)} for data in dataset : idx_x,idx_y=map(int,data) list_[idx_x].append(idx_y) list_[idx_y].append(idx_x) ans=list_[1].copy() for i in list_[1]: ans+=list_[i] print(len(set(ans))-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if m = 0 then ( break ) else skip ; var dataset : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (input().split())) ; var list_ : Map := Integer.subrange(0, n-1)->select(i | true)->collect(i | Map{i + 1 |-> Sequence{}})->unionAll() ; for data : dataset do ( var idx_x : OclAny := null; var idx_y : OclAny := null; Sequence{idx_x,idx_y} := (data)->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name list_)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name idx_x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name idx_y)))))))) )))) ; (expr (atom (name list_)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name idx_y)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name idx_x)))))))) ))))) ; var ans : OclAny := list_[1+1]->copy() ; for i : list_[1+1] do ( ans := ans + list_[i+1]) ; execute ((Set{}->union((ans)))->size() - 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,n=map(int,input().split()) k=list(input()) for i in range(n): a1,a2,c,d=input().split() for j in range(int(a1)-1,int(a2)): if k[j]==c : k[j]=d print(''.join(k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : Sequence := ((OclFile["System.in"]).readLine())->characters() ; for i : Integer.subrange(0, n-1) do ( var a1 : OclAny := null; var a2 : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a1,a2,c,d} := input().split() ; for j : Integer.subrange(("" + ((a1)))->toInteger() - 1, ("" + ((a2)))->toInteger()-1) do ( if k[j+1] = c then ( k[j+1] := d ) else skip)) ; execute (StringLib.sumStringsWithSeparator((k), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p=int(input()) while p>0 : n=input() x=len(n) print(x) p=p-1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while p > 0 do ( var n : String := (OclFile["System.in"]).readLine() ; var x : int := (n)->size() ; execute (x)->display() ; p := p - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def answer(s): return len(s) for T in range(int(input())): print(answer(input())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for T : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (answer((OclFile["System.in"]).readLine()))->display()); operation answer(s : OclAny) : OclAny pre: true post: true activity: return (s)->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=input() print(len(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : String := (OclFile["System.in"]).readLine() ; execute ((n)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=input() print(len(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : String := (OclFile["System.in"]).readLine() ; execute ((n)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=[int(i)for i in input().split()] z=[[c[0],c[1]],[c[2],c[3]],[c[4],c[5]]] def sides(a,b): return(a[0]-b[0])**2+(a[1]-b[1])**2 def trian(z): d=[sides(z[0],z[1]),sides(z[0],z[2]),sides(z[1],z[2])] d.sort() return d[0]+d[1]==d[2]and d[0]and d[1] if trian(z): print('RIGHT') exit() for i in range(3): for j in range(2): z[i][j]+=1 if trian(z): print('ALMOST') exit() z[i][j]-=2 if trian(z): print('ALMOST') exit() z[i][j]+=1 print('NEITHER') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var z : Sequence := Sequence{Sequence{c->first()}->union(Sequence{ c[1+1] })}->union(Sequence{Sequence{c[2+1]}->union(Sequence{ c[3+1] })}->union(Sequence{ Sequence{c[4+1]}->union(Sequence{ c[5+1] }) })) ; skip ; skip ; if trian(z) then ( execute ('RIGHT')->display() ; exit() ) else skip ; for i : Integer.subrange(0, 3-1) do ( for j : Integer.subrange(0, 2-1) do ( z[i+1][j+1] := z[i+1][j+1] + 1 ; if trian(z) then ( execute ('ALMOST')->display() ; exit() ) else skip ; z[i+1][j+1] := z[i+1][j+1] - 2 ; if trian(z) then ( execute ('ALMOST')->display() ; exit() ) else skip ; z[i+1][j+1] := z[i+1][j+1] + 1)) ; execute ('NEITHER')->display(); operation sides(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return ((a->first() - b->first()))->pow(2) + ((a[1+1] - b[1+1]))->pow(2); operation trian(z : OclAny) : OclAny pre: true post: true activity: var d : Sequence := Sequence{sides(z->first(), z[1+1])}->union(Sequence{sides(z->first(), z[2+1])}->union(Sequence{ sides(z[1+1], z[2+1]) })) ; d := d->sort() ; return d->first() + d[1+1] = d[2+1] & d->first() & d[1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : t-=1 s=input() l=len(s) print(l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( t := t - 1 ; var s : String := (OclFile["System.in"]).readLine() ; var l : int := (s)->size() ; execute (l)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def topKFrequent(self,nums,k): counter=collections.Counter(nums) return[k for k,v in counter.most_common(k)] ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation topKFrequent(nums : OclAny,k : OclAny) : OclAny pre: true post: true activity: var counter : OclAny := .Counter(nums) ; return counter.most_common(k)->select(_tuple | true)->collect(_tuple | let k : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in (k)); } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Hex(num): m=dict.fromkeys(range(16),0); digit=ord('0'); c=ord('a'); for i in range(16): if(i<10): m[i]=chr(digit); digit+=1 ; else : m[i]=chr(c); c+=1 res="" ; if(not num): return "0" ; if(num>0): while(num): res=m[num % 16]+res ; num//=16 ; else : n=num+2**32 ; while(n): res=m[n % 16]+res ; n//=16 ; return res ; if __name__=="__main__" : x=134 ; y=-1 ; z=-234 ; print("Hexa representation for"); print(x,"is",Hex(x)); print(y,"is",Hex(y)); print(z,"is",Hex(z)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var x : int := 134; var y : int := -1; var z : int := -234; ; execute ("Hexa representation for")->display(); ; execute (x)->display(); ; execute (y)->display(); ; execute (z)->display(); ) else skip; operation Hex(num : OclAny) pre: true post: true activity: var m : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 16))))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))); ; var digit : int := ('0')->char2byte(); ; var c : int := ('a')->char2byte(); ; for i : Integer.subrange(0, 16-1) do ( if (i < 10) then ( m[i+1] := (digit)->byte2char(); ; digit := digit + 1; ) else ( m[i+1] := (c)->byte2char(); ; c := c + 1 )) ; var res : String := ""; ; if (not(num)) then ( return "0"; ) else skip ; if (num > 0) then ( while (num) do ( res := m[num mod 16+1] + res; ; num := num div 16;) ) else ( var n : OclAny := num + (2)->pow(32); ; while (n) do ( res := m[n mod 16+1] + res; ; n := n div 16;) ) ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : N,M=map(int,input().split()) if N==M==0 : break PCs=[False]*N PCs[0]=True Packets={} for _ in range(M): t,s,d=map(int,input().split()) Packets[t]=(s,d) for key in sorted(Packets): if PCs[Packets[key][0]-1]==True : PCs[Packets[key][1]-1]=True print(PCs.count(True)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if N = M & (M == 0) then ( break ) else skip ; var PCs : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, N) ; PCs->first() := true ; var Packets : OclAny := Set{} ; for _anon : Integer.subrange(0, M-1) do ( var t : OclAny := null; var s : OclAny := null; var d : OclAny := null; Sequence{t,s,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; Packets[t+1] := Sequence{s, d}) ; for key : Packets->sort() do ( if PCs[Packets[key+1]->first() - 1+1] = true then ( PCs[Packets[key+1][1+1] - 1+1] := true ) else skip) ; execute (PCs->count(true))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n,m=map(int,input().split()) if n+m==0 : break a=[1]+[0]*(n-1) b={} for _ in range(m): t,s,d=map(int,input().split()); b[t]=(s,d) for x in sorted(b): if a[b[x][0]-1]: a[b[x][1]-1]=1 print(sum(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n + m = 0 then ( break ) else skip ; var a : Sequence := Sequence{ 1 }->union(MatrixLib.elementwiseMult(Sequence{ 0 }, (n - 1))) ; var b : OclAny := Set{} ; for _anon : Integer.subrange(0, m-1) do ( var t : OclAny := null; var s : OclAny := null; var d : OclAny := null; Sequence{t,s,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); b[t+1] := Sequence{s, d}) ; for x : b->sort() do ( if a[b[x+1]->first() - 1+1] then ( a[b[x+1][1+1] - 1+1] := 1 ) else skip) ; execute ((a)->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) s=list(input()) for _ in range(m): l,r,c1,c2=input().split() for k in range(int(l)-1,int(r)): if s[k]==c1 : s[k]=c2 print("".join(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; for _anon : Integer.subrange(0, m-1) do ( var l : OclAny := null; var r : OclAny := null; var c1 : OclAny := null; var c2 : OclAny := null; Sequence{l,r,c1,c2} := input().split() ; for k : Integer.subrange(("" + ((l)))->toInteger() - 1, ("" + ((r)))->toInteger()-1) do ( if s[k+1] = c1 then ( s[k+1] := c2 ) else skip)) ; execute (StringLib.sumStringsWithSeparator((s), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : N,M=map(int,input().split()) if N==M==0 : break logs=[] for i in range(M): t,s,d=map(int,input().split()) s,d=s-1,d-1 logs.append((t,s,d)) infected=[0 for i in range(N)] infected[0]=1 for t,s,d in sorted(logs): if infected[s]: infected[d]=1 print(sum(infected)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if N = M & (M == 0) then ( break ) else skip ; var logs : Sequence := Sequence{} ; for i : Integer.subrange(0, M-1) do ( var t : OclAny := null; var s : OclAny := null; var d : OclAny := null; Sequence{t,s,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := null; var d : OclAny := null; Sequence{s,d} := Sequence{s - 1,d - 1} ; execute ((Sequence{t, s, d}) : logs)) ; var infected : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; infected->first() := 1 ; for _tuple : logs->sort() do (var _indx : int := 1; var t : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); if infected[s+1] then ( infected[d+1] := 1 ) else skip) ; execute ((infected)->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,m=map(int,input().split()) if n==m==0 : break data=[list(map(int,input().split()))for i in range(m)] data.sort() infect=[False for i in range(n+1)] infect[1]=True for t,s,d in data : if infect[s]: infect[d]=True print(infect.count(True)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = m & (m == 0) then ( break ) else skip ; var data : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; data := data->sort() ; var infect : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (false)) ; infect[1+1] := true ; for _tuple : data do (var _indx : int := 1; var t : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); if infect[s+1] then ( infect[d+1] := true ) else skip) ; execute (infect->count(true))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] while True : n,m=LI() if n==0 and m==0 : break a=[LI()for _ in range(m)] a.sort() u=set([1]) for t,s,d in a : if s in u : u.add(d) rr.append(len(u)) return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := LI() ; if n = 0 & m = 0 then ( break ) else skip ; var a : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (LI())) ; a := a->sort() ; var u : Set := Set{}->union((Sequence{ 1 })) ; for _tuple : a do (var _indx : int := 1; var t : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); if (u)->includes(s) then ( execute ((d) : u) ) else skip) ; execute (((u)->size()) : rr)) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lexSmallest(a,n): a.sort(reverse=True) answer="" for i in range(n): answer+=a[i] return answer if __name__=="__main__" : a=["c","cb","cba"] n=len(a) print(lexSmallest(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{"c"}->union(Sequence{"cb"}->union(Sequence{ "cba" })) ; n := (a)->size() ; execute (lexSmallest(a, n))->display() ) else skip; operation lexSmallest(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: a := a->sort() ; var answer : String := "" ; for i : Integer.subrange(0, n-1) do ( answer := answer + a[i+1]) ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- field=[[[0]*3,[0]*3,[0]*3],[[0]*3,[0]*3,[0]*3],[[0]*3,[0]*3,[0]*3]] for i in range(3): for j in range(3): for k,line in enumerate(input().split()): field[i][k][j]=list(line) if i!=2 : input() x,y=map(lambda x :(int(x)-1)% 3,input().split()) anywhere=True for i in range(3): for j in range(3): if field[x][y][i][j]=='.' : field[x][y][i][j]='!' anywhere=False for i1 in range(3): for i in range(3): for j1 in range(3): for j in range(3): if field[i1][j1][i][j]=='.' and anywhere : print('!',end='') else : print(field[i1][j1][i][j],end='') print('',end='') print() print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var field : Sequence := Sequence{Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, 3)}->union(Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, 3)}->union(Sequence{ MatrixLib.elementwiseMult(Sequence{ 0 }, 3) }))}->union(Sequence{Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, 3)}->union(Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, 3)}->union(Sequence{ MatrixLib.elementwiseMult(Sequence{ 0 }, 3) }))}->union(Sequence{ Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, 3)}->union(Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, 3)}->union(Sequence{ MatrixLib.elementwiseMult(Sequence{ 0 }, 3) })) })) ; for i : Integer.subrange(0, 3-1) do ( for j : Integer.subrange(0, 3-1) do ( for _tuple : Integer.subrange(1, (input().split())->size())->collect( _indx | Sequence{_indx-1, (input().split())->at(_indx)} ) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var line : OclAny := _tuple->at(_indx); field[i+1][k+1][j+1] := (line))) ; if i /= 2 then ( input() ) else skip) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (lambda x : OclAny in ((("" + ((x)))->toInteger() - 1) mod 3))->apply(_x) ) ; var anywhere : boolean := true ; for i : Integer.subrange(0, 3-1) do ( for j : Integer.subrange(0, 3-1) do ( if field[x+1][y+1][i+1][j+1] = '.' then ( field[x+1][y+1][i+1][j+1] := '!' ; anywhere := false ) else skip)) ; for i1 : Integer.subrange(0, 3-1) do ( for i : Integer.subrange(0, 3-1) do ( for j1 : Integer.subrange(0, 3-1) do ( for j : Integer.subrange(0, 3-1) do ( if field[i1+1][j1+1][i+1][j+1] = '.' & anywhere then ( execute ('!')->display() ) else ( execute (field[i1+1][j1+1][i+1][j+1])->display() )) ; execute ('')->display()) ; execute (->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rt(p): a=(p[0]-p[2])**2+(p[1]-p[3])**2 b=(p[0]-p[4])**2+(p[1]-p[5])**2 c=(p[2]-p[4])**2+(p[3]-p[5])**2 return a and b and c and(a+b==c or a+c==b or b+c==a) def f(p): if rt(p): return 'RIGHT' for i in range(6): p[i]-=1 if rt(p): return 'ALMOST' p[i]+=2 if rt(p): return 'ALMOST' p[i]-=1 return 'NEITHER' print(f(list(map(int,input().split())))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; execute (f(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))->display(); operation rt(p : OclAny) : OclAny pre: true post: true activity: var a : double := ((p->first() - p[2+1]))->pow(2) + ((p[1+1] - p[3+1]))->pow(2) ; var b : double := ((p->first() - p[4+1]))->pow(2) + ((p[1+1] - p[5+1]))->pow(2) ; var c : double := ((p[2+1] - p[4+1]))->pow(2) + ((p[3+1] - p[5+1]))->pow(2) ; return a & b & c & (a + b = c or a + c = b or b + c = a); operation f(p : OclAny) : OclAny pre: true post: true activity: if rt(p) then ( return 'RIGHT' ) else skip ; for i : Integer.subrange(0, 6-1) do ( p[i+1] := p[i+1] - 1 ; if rt(p) then ( return 'ALMOST' ) else skip ; p[i+1] := p[i+1] + 2 ; if rt(p) then ( return 'ALMOST' ) else skip ; p[i+1] := p[i+1] - 1) ; return 'NEITHER'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout maps=[] sze=9 for i in range(1,10): maps.append(list(''.join(stdin.readline().strip().split()))) if not i % 3 and i!=9 : stdin.readline() s,c=map(int,stdin.readline().split()) c-=1 s-=1 c %=3 s %=3 acc=c*3 ass=s*3 label=0 for i in range(ass,ass+3): for j in range(acc,acc+3): if maps[i][j]=='.' : maps[i][j]='!' label=1 if not label : for i in range(len(maps)): for j in range(len(maps[i])): if maps[i][j]=='.' : maps[i][j]='!' ind=1 for i in range(len(maps)): for j in range(len(maps[i])): stdout.write(maps[i][j]) if not ind % 9 : stdout.write('\n') elif not ind % 3 : stdout.write(' ') ind+=1 if not(i+1)% 3 : stdout.write('\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var maps : Sequence := Sequence{} ; var sze : int := 9 ; for i : Integer.subrange(1, 10-1) do ( execute (((StringLib.sumStringsWithSeparator((stdin.readLine()->trim().split()), ''))->characters()) : maps) ; if not(i mod 3) & i /= 9 then ( stdin.readLine() ) else skip) ; var s : OclAny := null; var c : OclAny := null; Sequence{s,c} := (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; c := c - 1 ; s := s - 1 ; c := c mod 3 ; s := s mod 3 ; var acc : double := c * 3 ; var ass : double := s * 3 ; var label : int := 0 ; for i : Integer.subrange(ass, ass + 3-1) do ( for j : Integer.subrange(acc, acc + 3-1) do ( if maps[i+1][j+1] = '.' then ( maps[i+1][j+1] := '!' ; label := 1 ) else skip)) ; if not(label) then ( for i : Integer.subrange(0, (maps)->size()-1) do ( for j : Integer.subrange(0, (maps[i+1])->size()-1) do ( if maps[i+1][j+1] = '.' then ( maps[i+1][j+1] := '!' ) else skip)) ) else skip ; var ind : int := 1 ; for i : Integer.subrange(0, (maps)->size()-1) do ( for j : Integer.subrange(0, (maps[i+1])->size()-1) do ( stdout.write(maps[i+1][j+1]) ; if not(ind mod 9) then ( stdout.write(' ') ) else (if not(ind mod 3) then ( stdout.write(' ') ) else skip) ; ind := ind + 1) ; if not((i + 1) mod 3) then ( stdout.write(' ') ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mtx=[] for i in range(11): inp=input() if inp.strip(): mtx.append(list(''.join(inp.split()))) y,x=map(int,input().split()) y-=1 x-=1 gx=x % 3 gy=y % 3 found=0 for px in range(3): for py in range(3): if mtx[gy*3+py][gx*3+px]=='.' : mtx[gy*3+py][gx*3+px]='!' found+=1 if not found : for px in range(9): for py in range(9): if mtx[py][px]=='.' : mtx[py][px]='!' for i in range(9): st='' for j in range(9): st+=mtx[i][j] if j==2 or j==5 : st+=' ' print(st) if i==2 or i==5 : print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mtx : Sequence := Sequence{} ; for i : Integer.subrange(0, 11-1) do ( var inp : String := (OclFile["System.in"]).readLine() ; if inp->trim() then ( execute (((StringLib.sumStringsWithSeparator((inp.split()), ''))->characters()) : mtx) ) else skip) ; var y : OclAny := null; var x : OclAny := null; Sequence{y,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; y := y - 1 ; x := x - 1 ; var gx : int := x mod 3 ; var gy : int := y mod 3 ; var found : int := 0 ; for px : Integer.subrange(0, 3-1) do ( for py : Integer.subrange(0, 3-1) do ( if mtx[gy * 3 + py+1][gx * 3 + px+1] = '.' then ( mtx[gy * 3 + py+1][gx * 3 + px+1] := '!' ; found := found + 1 ) else skip)) ; if not(found) then ( for px : Integer.subrange(0, 9-1) do ( for py : Integer.subrange(0, 9-1) do ( if mtx[py+1][px+1] = '.' then ( mtx[py+1][px+1] := '!' ) else skip)) ) else skip ; for i : Integer.subrange(0, 9-1) do ( var st : String := '' ; for j : Integer.subrange(0, 9-1) do ( st := st + mtx[i+1][j+1] ; if j = 2 or j = 5 then ( st := st + ' ' ) else skip) ; execute (st)->display() ; if i = 2 or i = 5 then ( execute (->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(doors): digit=doors[-1]^ 1 for i in range(len(doors)-1,-1,-1): if doors[i]==digit : return i+1 n=input() d=[int(x)for x in input().split()] print(solve(d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : String := (OclFile["System.in"]).readLine() ; var d : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (solve(d))->display(); operation solve(doors : OclAny) : OclAny pre: true post: true activity: var digit : int := MathLib.bitwiseXor(doors->last(), 1) ; for i : Integer.subrange(-1 + 1, (doors)->size() - 1)->reverse() do ( if doors[i+1] = digit then ( return i + 1 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=input().replace("","") ans=min(arr.rfind("0"),arr.rfind("1"))+1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : OclAny := input().replace("", "") ; var ans : OclAny := Set{arr.rfind("0"), arr.rfind("1")}->min() + 1 ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) s=list(input()) for _ in range(m): l,r,c1,c2=map(str,input().split()) l=int(l) r=int(r) for i in range(len(s)): if i+1>=l and i+1<=r : if s[i]==c1 : s[i]=c2 print(''.join(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; for _anon : Integer.subrange(0, m-1) do ( var l : OclAny := null; var r : OclAny := null; var c1 : OclAny := null; var c2 : OclAny := null; Sequence{l,r,c1,c2} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; var l : int := ("" + ((l)))->toInteger() ; var r : int := ("" + ((r)))->toInteger() ; for i : Integer.subrange(0, (s)->size()-1) do ( if (i + 1->compareTo(l)) >= 0 & (i + 1->compareTo(r)) <= 0 then ( if s[i+1] = c1 then ( s[i+1] := c2 ) else skip ) else skip)) ; execute (StringLib.sumStringsWithSeparator((s), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) k=[i for i in input().split()] k=k[: :-1] print(min(n-(k.index('0')),(n-(k.index('1'))))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : Sequence := input().split()->select(i | true)->collect(i | (i)) ; k := k(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; execute (Set{n - (k->indexOf('0') - 1), (n - (k->indexOf('1') - 1))}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _,a=input(),input().replace('','') print(min(a.rfind('0'),a.rfind('1'))+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _anon : OclAny := null; var a : OclAny := null; Sequence{_anon,a} := Sequence{(OclFile["System.in"]).readLine(),input().replace('', '')} ; execute (Set{a.rfind('0'), a.rfind('1')}->min() + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(doors): digit=doors[-1]^ 1 for i in range(len(doors)-1,-1,-1): if doors[i]==digit : return i+1 n=input() d=[int(x)for x in input().split()] print(solve(d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : String := (OclFile["System.in"]).readLine() ; var d : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (solve(d))->display(); operation solve(doors : OclAny) : OclAny pre: true post: true activity: var digit : int := MathLib.bitwiseXor(doors->last(), 1) ; for i : Integer.subrange(-1 + 1, (doors)->size() - 1)->reverse() do ( if doors[i+1] = digit then ( return i + 1 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) for _ in range(n): has_now=False line=input().split(" ") nt=int(line[0]) alarms=[] sleep=int(line[1])*60+int(line[2]) for _ in range(nt): test=input().split(" ") a=int(test[0])*60+int(test[1]) t=((24*60)+(a-sleep))%(24*60) if t==0 : has_now=True alarms.append(t) if has_now : print("0 0") else : f=min(alarms) if f>0 : print(f"{f//60}{f % 60}") main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var has_now : boolean := false ; var line : OclAny := input().split(" ") ; var nt : int := ("" + ((line->first())))->toInteger() ; var alarms : Sequence := Sequence{} ; var sleep : int := ("" + ((line[1+1])))->toInteger() * 60 + ("" + ((line[2+1])))->toInteger() ; for _anon : Integer.subrange(0, nt-1) do ( var test : OclAny := input().split(" ") ; var a : int := ("" + ((test->first())))->toInteger() * 60 + ("" + ((test[1+1])))->toInteger() ; var t : int := ((24 * 60) + (a - sleep)) mod (24 * 60) ; if t = 0 then ( has_now := true ) else skip ; execute ((t) : alarms)) ; if has_now then ( execute ("0 0")->display() ) else ( var f : OclAny := (alarms)->min() ; if f > 0 then ( execute (StringLib.formattedString("{f//60}{f % 60}"))->display() ) else skip )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def print_time(mins): print(mins//60,mins % 60) t=int(input()) for _ in range(t): n,H,M=map(int,input().split()) sleep_mins=H*60+M alarms=[] for i in range(n): h,m=map(int,input().split()) alarms.append(h*60+m) alarms.sort() got_it=False for alarm_mins in alarms : if sleep_mins<=alarm_mins : got_it=True mins=alarm_mins-sleep_mins print_time(mins) break if got_it==False : print_time((24*60-sleep_mins)+alarms[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var H : OclAny := null; var M : OclAny := null; Sequence{n,H,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sleep_mins : double := H * 60 + M ; var alarms : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((h * 60 + m) : alarms)) ; alarms := alarms->sort() ; var got_it : boolean := false ; for alarm_mins : alarms do ( if (sleep_mins->compareTo(alarm_mins)) <= 0 then ( got_it := true ; mins := alarm_mins - sleep_mins ; print_time(mins) ; break ) else skip) ; if got_it = false then ( print_time((24 * 60 - sleep_mins) + alarms->first()) ) else skip); operation print_time(mins : OclAny) pre: true post: true activity: execute (mins div 60)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def time_delta(t1,t2): if t1>=t2 : return t1-t2 else : return t1-t2+24*60 def format_delta(delta): return delta//60,delta % 60 t=int(input()) for _ in range(t): n,h,m=map(int,input().split()) time=h*60+m alarms=[] for _ in range(n): ah,am=map(int,input().split()) alarms.append(ah*60+am) hd,md=format_delta(min(time_delta(alarm,time)for alarm in alarms)) print(hd,md) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var h : OclAny := null; var m : OclAny := null; Sequence{n,h,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var time : double := h * 60 + m ; var alarms : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var ah : OclAny := null; var am : OclAny := null; Sequence{ah,am} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((ah * 60 + am) : alarms)) ; var hd : OclAny := null; var md : OclAny := null; Sequence{hd,md} := format_delta(((argument (test (logical_test (comparison (expr (atom (name time_delta)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name alarm))))))) , (argument (test (logical_test (comparison (expr (atom (name time)))))))) ))))))) (comp_for for (exprlist (expr (atom (name alarm)))) in (logical_test (comparison (expr (atom (name alarms))))))))->min()) ; execute (hd)->display()); operation time_delta(t1 : OclAny, t2 : OclAny) : OclAny pre: true post: true activity: if (t1->compareTo(t2)) >= 0 then ( return t1 - t2 ) else ( return t1 - t2 + 24 * 60 ); operation format_delta(delta : OclAny) : OclAny pre: true post: true activity: return delta div 60, delta mod 60; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def countDigits(n): ans=0 for i in range(1,n+1): ans+=math.log10(i) ans=ans*n return 1+math.floor(ans) if __name__=="__main__" : n=4 print(countDigits(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 4 ; execute (countDigits(n))->display() ) else skip; operation countDigits(n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( ans := ans + (i)->log10()) ; ans := ans * n ; return 1 + (ans)->floor(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) def hours_to_minutes(hours,minutes): return hours*60+minutes def minutes_to_sleep(start,hours_tuple): [hours,minutes]=hours_tuple alarm_minutes=hours_to_minutes(hours,minutes) if start<=alarm_minutes : return alarm_minutes-start else : return 24*60-start+alarm_minutes def minutes_to_hours(minutes): return[minutes//60,minutes % 60] for i in range(n): [k,H,M]=map(int,input().split(' ')) arr=[] for j in range(k): [h,m]=map(int,input().split(' ')) arr.append([h,m]) sleepMinutes=hours_to_minutes(H,M) minutesArr=list(map(lambda time_tuple : minutes_to_sleep(sleepMinutes,time_tuple),arr)) ans=minutes_to_hours(min(minutesArr)) print(str(ans[0])+' '+str(ans[1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; skip ; skip ; for i : Integer.subrange(0, n-1) do ( ; Sequence{k}->union(Sequence{H}->union(Sequence{ M })) := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := Sequence{} ; for j : Integer.subrange(0, k-1) do (suite)) ; Sequence{h}->union(Sequence{ m }) := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ); operation hours_to_minutes(hours : OclAny, minutes : OclAny) : OclAny pre: true post: true activity: return hours * 60 + minutes; operation minutes_to_sleep(start : OclAny, hours_tuple : OclAny) pre: true post: true activity: ; Sequence{hours}->union(Sequence{ minutes }) := hours_tuple ; var alarm_minutes : OclAny := hours_to_minutes(hours, minutes) ; if (start->compareTo(alarm_minutes)) <= 0 then ( return alarm_minutes - start ) else ( return 24 * 60 - start + alarm_minutes ); operation minutes_to_hours(minutes : OclAny) : OclAny pre: true post: true activity: return Sequence{minutes div 60}->union(Sequence{ minutes mod 60 }); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for x1 in range(t): n,h0,m0=map(int,input().split()) time0=h0*60+m0 ans=1440 for x2 in range(n): h1,m1=map(int,input().split()) time1=h1*60+m1 if time0<=time1 and time1-time0time1 and(1440-time0)+time1toInteger() ; for x1 : Integer.subrange(0, t-1) do ( var n : OclAny := null; var h0 : OclAny := null; var m0 : OclAny := null; Sequence{n,h0,m0} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var time0 : double := h0 * 60 + m0 ; var ans : int := 1440 ; for x2 : Integer.subrange(0, n-1) do ( var h1 : OclAny := null; var m1 : OclAny := null; Sequence{h1,m1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var time1 : double := h1 * 60 + m1 ; if (time0->compareTo(time1)) <= 0 & (time1 - time0->compareTo(ans)) < 0 then ( ans := time1 - time0 ) else (if (time0->compareTo(time1)) > 0 & ((1440 - time0) + time1->compareTo(ans)) < 0 then ( ans := (1440 - time0) + time1 ) else skip)) ; execute (ans div 60)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math while True : E=int(input()) if E==0 : break ans=10**10 z=0 while z**3<=E : y=int(math.sqrt(E-z**3)) x=E-z**3-y**2 ans=min(x+y+z,ans) z+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var E : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if E = 0 then ( break ) else skip ; var ans : double := (10)->pow(10) ; var z : int := 0 ; while ((z)->pow(3)->compareTo(E)) <= 0 do ( var y : int := ("" + (((E - (z)->pow(3))->sqrt())))->toInteger() ; var x : double := E - (z)->pow(3) - (y)->pow(2) ; ans := Set{x + y + z, ans}->min() ; z := z + 1) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) s=list(input()) for i in range(m): l,r,c1,c2=input().split() for i in range(int(l)-1,int(r)): if(s[i]==c1): s[i]=c2 print(str("".join(s))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; for i : Integer.subrange(0, m-1) do ( var l : OclAny := null; var r : OclAny := null; var c1 : OclAny := null; var c2 : OclAny := null; Sequence{l,r,c1,c2} := input().split() ; for i : Integer.subrange(("" + ((l)))->toInteger() - 1, ("" + ((r)))->toInteger()-1) do ( if (s[i+1] = c1) then ( s[i+1] := c2 ) else skip)) ; execute (("" + ((StringLib.sumStringsWithSeparator((s), "")))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def solve(e): k=2**32 for z in range(100,-1,-1): z3=z*z*z if z3>e : continue e2=e-z3 ylm=int(math.sqrt(e2)) for y in range(ylm,-1,-1): y2=y*y if e2>(y+1)*(y+1): break e3=e2-y2 x=e3 k=min(k,x+y+z) return k def main(): while True : a=int(input()) if a==0 : break print(solve(a)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(e : OclAny) : OclAny pre: true post: true activity: var k : double := (2)->pow(32) ; for z : Integer.subrange(-1 + 1, 100)->reverse() do ( var z3 : double := z * z * z ; if (z3->compareTo(e)) > 0 then ( continue ) else skip ; var e2 : double := e - z3 ; var ylm : int := ("" + (((e2)->sqrt())))->toInteger() ; for y : Integer.subrange(-1 + 1, ylm)->reverse() do ( var y2 : double := y * y ; if (e2->compareTo((y + 1) * (y + 1))) > 0 then ( break ) else skip ; var e3 : double := e2 - y2 ; var x : OclAny := e3 ; k := Set{k, x + y + z}->min())) ; return k; operation main() pre: true post: true activity: while true do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if a = 0 then ( break ) else skip ; execute (solve(a))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math targ=int(input()) y,z=0,0 while True : minans=float("inf") for n in range(math.ceil(targ**(1/3))+1): if minans==0 : break if targ-n**3>=0 : m=int((targ-n**3)**(1/2)) else : m=0 if(n**3)+(m**2)>targ : break if minans>targ-(n**3+m**2)+n+m : minans=targ-(n**3+m**2)+n+m if minans!=float("inf"): print(minans) else : print(y+z) targ=int(input()) if targ==0 : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var targ : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var y : OclAny := null; var z : OclAny := null; Sequence{y,z} := Sequence{0,0} ; while true do ( var minans : double := ("" + (("inf")))->toReal() ; for n : Integer.subrange(0, ((targ)->pow((1 / 3)))->ceil() + 1-1) do ( if minans = 0 then ( break ) else skip ; if targ - (n)->pow(3) >= 0 then ( var m : int := ("" + ((((targ - (n)->pow(3)))->pow((1 / 2)))))->toInteger() ) else ( m := 0 ) ; if (((n)->pow(3)) + ((m)->pow(2))->compareTo(targ)) > 0 then ( break ) else skip ; if (minans->compareTo(targ - ((n)->pow(3) + (m)->pow(2)) + n + m)) > 0 then ( minans := targ - ((n)->pow(3) + (m)->pow(2)) + n + m ) else skip) ; if minans /= ("" + (("inf")))->toReal() then ( execute (minans)->display() ) else ( execute (y + z)->display() ) ; targ := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if targ = 0 then ( break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import floor,sqrt cubics=[x*x*x for x in range(101)] squares=[x*x for x in range(1000)] while True : m=1000000 e=int(input()) if e==0 : break for z in range(len(cubics)): if eselect(x | true)->collect(x | (x * x * x)) ; var squares : Sequence := Integer.subrange(0, 1000-1)->select(x | true)->collect(x | (x * x)) ; while true do ( var m : int := 1000000 ; var e : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if e = 0 then ( break ) else skip ; for z : Integer.subrange(0, (cubics)->size()-1) do ( if (e->compareTo(cubics[z+1])) < 0 then ( break ) else skip ; var tmp : double := e - cubics[z+1] ; var y : OclAny := floor(sqrt(tmp)) ; var x : double := tmp - (y)->pow(2) ; m := Set{m, x + y + z}->min()) ; execute (m)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math e=int(input()) while e>0 : z=0 t=z**3 f=e-t q=math.sqrt(f) y=int(q) if q-y>0.999999 : y+=1 x=y*y x=f-x m=x+y+z while t<=e : f=e-t q=math.sqrt(f) y=int(q) if q-y>0.999999 : y+=1 x=y*y x=f-x l=x+y+z if ltoInteger() ; while e > 0 do ( var z : int := 0 ; var t : double := (z)->pow(3) ; var f : double := e - t ; var q : double := (f)->sqrt() ; var y : int := ("" + ((q)))->toInteger() ; if q - y > 0.999999 then ( y := y + 1 ) else skip ; var x : int := y * y ; x := f - x ; var m : int := x + y + z ; while (t->compareTo(e)) <= 0 do ( f := e - t ; q := (f)->sqrt() ; y := ("" + ((q)))->toInteger() ; if q - y > 0.999999 then ( y := y + 1 ) else skip ; x := y * y ; x := f - x ; var l : int := x + y + z ; if (l->compareTo(m)) < 0 then ( m := l ) else skip ; z := z + 1 ; t := (z)->pow(3)) ; execute (m)->display() ; e := ("" + (((OclFile["System.in"]).readLine())))->toInteger()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**9) INF=10**18 def input(): return sys.stdin.readline().rstrip() def main(): N,M=map(int,input().split()) S=list(reversed(list(input()))) i=0 f=True l=[] while True : num=0 for j in range(M): if i+(M-j)>=N : num=N-i break else : if S[i+(M-j)]=='0' : num=M-j break else : if j==M-1 : f=False l.append(str(num)) i+=num if f==False : print(-1) exit() if i>=N : break print(' '.join(reversed(l))) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := (10)->pow(18) ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation main() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : Sequence := ((((OclFile["System.in"]).readLine())->characters())->reverse()) ; var i : int := 0 ; var f : boolean := true ; var l : Sequence := Sequence{} ; while true do ( var num : int := 0 ; for j : Integer.subrange(0, M-1) do ( if (i + (M - j)->compareTo(N)) >= 0 then ( num := N - i ; break ) else ( if S[i + (M - j)+1] = '0' then ( num := M - j ; break ) else ( if j = M - 1 then ( f := false ) else skip ) )) ; execute ((("" + ((num)))) : l) ; i := i + num ; if f = false then ( execute (-1)->display() ; exit() ) else skip ; if (i->compareTo(N)) >= 0 then ( break ) else skip) ; execute (StringLib.sumStringsWithSeparator(((l)->reverse()), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(N,M,S): from collections import namedtuple from heapq import heappop,heappush INF=N*2 V=namedtuple('V','cnt index') cnt_from_N=[INF]*(N+1) cnt_from_N[N]=0 parent=[0]*(N+1) h=[V(cnt=0,index=N)] for j in range(N-1,-1,-1): if S[j]: continue while h : cnt,par=h[0] if par>j+M : heappop(h) continue break if not h : return-1, cnt_from_N[j]=cnt+1 parent[j]=par heappush(h,V(cnt=cnt+1,index=j)) ret=[] curr=0 while currcollect( _x | (OclType["int"])->apply(_x) ); operation solve(N : OclAny, M : OclAny, S : OclAny) : OclAny pre: true post: true activity: skip ; skip ; var INF : double := N * 2 ; var V : OclAny := namedtuple('V', 'cnt index') ; var cnt_from_N : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, (N + 1)) ; cnt_from_N[N+1] := 0 ; var parent : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; var h : Sequence := Sequence{ V((argument (test (logical_test (comparison (expr (atom (name cnt)))))) = (test (logical_test (comparison (expr (atom (number (integer 0)))))))), (argument (test (logical_test (comparison (expr (atom (name index)))))) = (test (logical_test (comparison (expr (atom (name N)))))))) } ; for j : Integer.subrange(-1 + 1, N - 1)->reverse() do ( if S[j+1] then ( continue ) else skip ; while h do ( var cnt : OclAny := null; var par : OclAny := null; Sequence{cnt,par} := h->first() ; if (par->compareTo(j + M)) > 0 then ( heappop(h) ; continue ) else skip ; break) ; if not(h) then ( return (testlist (test (logical_test (comparison (expr (atom - (number (integer 1))))))) ,) ) else skip ; cnt_from_N[j+1] := cnt + 1 ; parent[j+1] := par ; heappush(h, V((argument (test (logical_test (comparison (expr (atom (name cnt)))))) = (test (logical_test (comparison (expr (expr (atom (name cnt))) + (expr (atom (number (integer 1))))))))), (argument (test (logical_test (comparison (expr (atom (name index)))))) = (test (logical_test (comparison (expr (atom (name j)))))))))) ; var ret : Sequence := Sequence{} ; var curr : int := 0 ; while (curr->compareTo(N)) < 0 do ( var par : OclAny := parent[curr+1] ; execute ((par - curr) : ret) ; curr := par) ; return ret; operation main() pre: true post: true activity: Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left,bisect_right N,M=map(int,input().split()) Ss=input() OKs=[] for i,S in enumerate(Ss): if S=='0' : OKs.append(i) dp=[0]*(N+1) for i in range(N+1): j=bisect_left(OKs,i-M) dp[i]=OKs[j] anss=[] i=N while True : iPrev=dp[i] if iPrev==i : anss=[] break if iPrev<0 : iPrev=0 anss.append(i-iPrev) if iPrev==0 : break i=iPrev if not anss : print(-1) else : print(' '.join(map(str,anss[: :-1]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var Ss : String := (OclFile["System.in"]).readLine() ; var OKs : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (Ss)->size())->collect( _indx | Sequence{_indx-1, (Ss)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var S : OclAny := _tuple->at(_indx); if S = '0' then ( execute ((i) : OKs) ) else skip) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; for i : Integer.subrange(0, N + 1-1) do ( var j : OclAny := bisect_left(OKs, i - M) ; dp[i+1] := OKs[j+1]) ; var anss : Sequence := Sequence{} ; var i : OclAny := N ; while true do ( var iPrev : OclAny := dp[i+1] ; if iPrev = i then ( anss := Sequence{} ; break ) else skip ; if iPrev < 0 then ( iPrev := 0 ) else skip ; execute ((i - iPrev) : anss) ; if iPrev = 0 then ( break ) else skip ; i := iPrev) ; if not(anss) then ( execute (-1)->display() ) else ( execute (StringLib.sumStringsWithSeparator(((anss(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cubes,high,count_cubes=int(input()),0,0 while count_cubes+(high*(high+1)/2)+high+1<=cubes : high+=1 count_cubes+=high*(high+1)/2 print(high) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cubes : OclAny := null; var high : OclAny := null; var count_cubes : OclAny := null; Sequence{cubes,high,count_cubes} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),0,0} ; while (count_cubes + (high * (high + 1) / 2) + high + 1->compareTo(cubes)) <= 0 do ( high := high + 1 ; count_cubes := count_cubes + high * (high + 1) / 2) ; execute (high)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : t-=1 n,k=map(int,input().split()) k-=1 if n % 2==0 : print((k % n)+1) else : s=k//(n//2) print((k+s)% n+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( t := t - 1 ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; k := k - 1 ; if n mod 2 = 0 then ( execute ((k mod n) + 1)->display() ) else ( var s : int := k div (n div 2) ; execute ((k + s) mod n + 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ii=lambda : int(input()) mi=lambda : map(int,input().split()) li=lambda : list(map(int,input().split())) n,m=mi() s=input() s=s[: :-1] ans=[] ima=0 while ima!=n : flag=False for i in range(m): tmp=m-i if ima+tmp>n : continue elif s[ima+tmp]==str(1): continue else : ima+=tmp ans.append(tmp) flag=True break if flag==False : print(-1) exit() print(*ans[: :-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ii : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var mi : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var li : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := mi->apply() ; var s : String := (OclFile["System.in"]).readLine() ; s := s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var ans : Sequence := Sequence{} ; var ima : int := 0 ; while ima /= n do ( var flag : boolean := false ; for i : Integer.subrange(0, m-1) do ( var tmp : double := m - i ; if (ima + tmp->compareTo(n)) > 0 then ( continue ) else (if s[ima + tmp+1] = ("" + ((1))) then ( continue ) else ( ima := ima + tmp ; execute ((tmp) : ans) ; flag := true ; break ) ) ) ; if flag = false then ( execute (-1)->display() ; exit() ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ]))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) s=input() s=list(s) for i in range(m): l,r,c1,c2=map(str,input().split()) l,r=int(l),int(r) for j in range(l-1,r): if(s[j]==c1): s[j]=c2 print(''.join(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; s := (s)->characters() ; for i : Integer.subrange(0, m-1) do ( var l : OclAny := null; var r : OclAny := null; var c1 : OclAny := null; var c2 : OclAny := null; Sequence{l,r,c1,c2} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{("" + ((l)))->toInteger(),("" + ((r)))->toInteger()} ; for j : Integer.subrange(l - 1, r-1) do ( if (s[j+1] = c1) then ( s[j+1] := c2 ) else skip)) ; execute (StringLib.sumStringsWithSeparator((s), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**8) def inp(): return int(input()) def inpm(): return map(int,input().split()) def inpl(): return list(map(int,input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(input())for _ in range(n)) def inpll(n): return sorted([list(map(int,input().split()))for _ in range(n)]) def main(): n,m=inpm() s=list(input()) s.reverse() s=tuple(s) ans=[] now=0 while True : key=0 for go in range(m,0,-1): if now+go>=n : x=n-now ans.append(str(x)) ans.reverse() print(' '.join(ans)) return elif s[now+go]=='0' : key=1 now+=go ans.append(str(go)) break if key==0 : print(-1) return if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(8)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inpm() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inpls() : OclAny pre: true post: true activity: return (input().split()); operation inplm(n : OclAny) : OclAny pre: true post: true activity: return ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))); operation inpll(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))->sort(); operation main() pre: true post: true activity: var m : OclAny := null; Sequence{n,m} := inpm() ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; s := s->reverse() ; s := (s) ; var ans : Sequence := Sequence{} ; var now : int := 0 ; while true do ( var key : int := 0 ; for go : Integer.subrange(0 + 1, m)->reverse() do ( if (now + go->compareTo(n)) >= 0 then ( var x : double := n - now ; execute ((("" + ((x)))) : ans) ; ans := ans->reverse() ; execute (StringLib.sumStringsWithSeparator((ans), ' '))->display() ; return ) else (if s[now + go+1] = '0' then ( key := 1 ; now := now + go ; execute ((("" + ((go)))) : ans) ; break ) else skip)) ; if key = 0 then ( execute (-1)->display() ; return ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**7) import math def cmb(n,r): if n-r1 : offset=(n-r)% p for k in range(p-1,r,p): numerator[k-offset]/=pivot denominator[k]/=pivot result=1 for k in range(r): if numerator[k]>1 : result*=int(numerator[k]) return result z=10**9+7 X,Y=map(int,input().split()) x=(-X+2*Y)/3 y=(2*X-Y)/3 if x.is_integer()and y.is_integer()and x>=0 and y>=0 : x=int(x) y=int(y) maximam=max(x,y) minimam=min(x,y) print(cmb(x+y,minimam)% z) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; skip ; var z : double := (10)->pow(9) + 7 ; var X : OclAny := null; var Y : OclAny := null; Sequence{X,Y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : double := (-X + 2 * Y) / 3 ; var y : double := (2 * X - Y) / 3 ; if x.is_integer() & y.is_integer() & x >= 0 & y >= 0 then ( x := ("" + ((x)))->toInteger() ; y := ("" + ((y)))->toInteger() ; var maximam : OclAny := Set{x, y}->max() ; var minimam : OclAny := Set{x, y}->min() ; execute (cmb(x + y, minimam) mod z)->display() ) else ( execute (0)->display() ); operation cmb(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: if (n - r->compareTo(r)) < 0 then ( r := n - r ) else skip ; if r = 0 then ( return 1 ) else skip ; if r = 1 then ( return n ) else skip ; var numerator : Sequence := Integer.subrange(0, r-1)->select(k | true)->collect(k | (n - r + k + 1)) ; var denominator : Sequence := Integer.subrange(0, r-1)->select(k | true)->collect(k | (k + 1)) ; for p : Integer.subrange(2, r + 1-1) do ( var pivot : OclAny := denominator[p - 1+1] ; if pivot > 1 then ( var offset : int := (n - r) mod p ; for k : Integer.subrange(p - 1, r-1)->select( $x | ($x - p - 1) mod p = 0 ) do ( numerator[k - offset+1] := numerator[k - offset+1] / pivot ; denominator[k+1] := denominator[k+1] / pivot) ) else skip) ; var result : int := 1 ; for k : Integer.subrange(0, r-1) do ( if numerator[k+1] > 1 then ( result := result * ("" + ((numerator[k+1])))->toInteger() ) else skip) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cmb(n,r,mod): if(r<0 or r>n): return 0 r=min(r,n-r) return g1[n]*g2[r]*g2[n-r]% mod mod=10**9+7 N=10**6 g1=[1,1] g2=[1,1] inverse=[0,1] for i in range(2,N+1): g1.append((g1[-1]*i)% mod) inverse.append((-inverse[mod % i]*(mod//i))% mod) g2.append((g2[-1]*inverse[-1])% mod) def is_integer(n): try : float(n) except ValueError : return False else : return float(n).is_integer() X,Y=map(int,input().split()) a=(2*Y-X)/3 b=(2*X-Y)/3 if(X==0 or Y==0): print(0) exit() if is_integer(a): a=(2*Y-X)//3 else : print(0) exit() if is_integer(b): b=(2*X-Y)//3 else : print(0) exit() n=a+b mod=10**9+7 ans=cmb(n,a,mod) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; mod := (10)->pow(9) + 7 ; var N : double := (10)->pow(6) ; var g1 : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var g2 : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var inverse : Sequence := Sequence{0}->union(Sequence{ 1 }) ; for i : Integer.subrange(2, N + 1-1) do ( execute (((g1->last() * i) mod mod) : g1) ; execute (((-inverse[mod mod i+1] * (mod div i)) mod mod) : inverse) ; execute (((g2->last() * inverse->last()) mod mod) : g2)) ; skip ; var X : OclAny := null; var Y : OclAny := null; Sequence{X,Y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : double := (2 * Y - X) / 3 ; var b : double := (2 * X - Y) / 3 ; if (X = 0 or Y = 0) then ( execute (0)->display() ; exit() ) else skip ; if is_integer(a) then ( a := (2 * Y - X) div 3 ) else ( execute (0)->display() ; exit() ) ; if is_integer(b) then ( b := (2 * X - Y) div 3 ) else ( execute (0)->display() ; exit() ) ; n := a + b ; mod := (10)->pow(9) + 7 ; var ans : OclAny := cmb(n, a, mod) ; execute (ans)->display(); operation cmb(n : OclAny, r : OclAny, mod : OclAny) : OclAny pre: true post: true activity: if (r < 0 or (r->compareTo(n)) > 0) then ( return 0 ) else skip ; r := Set{r, n - r}->min() ; return g1[n+1] * g2[r+1] * g2[n - r+1] mod mod; operation is_integer(n : OclAny) pre: true post: true activity: try ( OclType["double"](n)) (except_clause except (test (logical_test (comparison (expr (atom (name ValueError)))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name False)))))))))))) else ( return OclType["double"](n).is_integer() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- X,Y=list(map(int,input().split())) def cmb(n,r,p): if(r<0)or(ncollect( _x | (OclType["int"])->apply(_x) )) ; skip ; p := (10)->pow(9) + 7 ; var N : double := (10)->pow(6) ; var fact : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var factinv : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var inv : Sequence := Sequence{0}->union(Sequence{ 1 }) ; if (X + Y) mod 3 /= 0 then ( execute (0)->display() ) else ( var x : int := (2 * Y - X) div 3 ; var y : int := (2 * X - Y) div 3 ; var total : int := x + y ; for i : Integer.subrange(2, N + 1-1) do ( execute (((fact->last() * i) mod p) : fact) ; execute (((-inv[p mod i+1] * (p div i)) mod p) : inv) ; execute (((factinv->last() * inv->last()) mod p) : factinv)) ; execute (cmb(total, x, p))->display() ); operation cmb(n : OclAny, r : OclAny, p : OclAny) : OclAny pre: true post: true activity: if (r < 0) or ((n->compareTo(r)) < 0) then ( return 0 ) else skip ; r := Set{r, n - r}->min() ; return fact[n+1] * factinv[r+1] * factinv[n - r+1] mod p; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import reduce def modcombination(n,k,mod): num=reduce(lambda x,y : x*y % mod,range(n,n-k,-1)) den=reduce(lambda x,y : x*y % mod,range(1,k+1)) return num*pow(den,mod-2,mod)% mod if __name__=='__main__' : MOD=10**9+7 x,y=map(int,input().split()) if(x+y)% 3!=0 : print(0) exit(0) m=(2*x-y)//3 n=x-(2*m) if n<0 or m<0 : print(0) exit(0) if n==0 or m==0 : print(1) exit(0) print(modcombination(n+m,n,MOD)% MOD) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var MOD : double := (10)->pow(9) + 7 ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (x + y) mod 3 /= 0 then ( execute (0)->display() ; exit(0) ) else skip ; var m : int := (2 * x - y) div 3 ; n := x - (2 * m) ; if n < 0 or m < 0 then ( execute (0)->display() ; exit(0) ) else skip ; if n = 0 or m = 0 then ( execute (1)->display() ; exit(0) ) else skip ; execute (modcombination(n + m, n, MOD) mod MOD)->display() ) else skip; operation modcombination(n : OclAny, k : OclAny, mod : OclAny) : OclAny pre: true post: true activity: var num : OclAny := reduce(lambda x : OclAny, y : OclAny in (x * y mod mod), Integer.subrange(n - k + 1, n)->reverse()) ; var den : OclAny := reduce(lambda x : OclAny, y : OclAny in (x * y mod mod), Integer.subrange(1, k + 1-1)) ; return num * (den)->pow(mod - 2) mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=10**9+7 def comb_mod(a : int,b : int,mod : int=MOD)->int : b=min(b,a-b) res=1 for x in range(a-b+1,a+1): res=res*x % mod for x in range(1,b+1): res=res*pow(x,mod-2,mod)% mod return res def main(): X,Y=[int(x)for x in input().split()] m=(X+X-Y)//3 n=X-2*m if n+2*m!=X or 2*n+m!=Y or n<0 or m<0 : print(0) return print(comb_mod(n+m,n)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation comb_mod(a : int, b : int, mod : int) : int pre: true post: true activity: if mod->oclIsUndefined() then mod := MOD else skip; var b : OclAny := Set{b, a - b}->min() ; var res : int := 1 ; for x : Integer.subrange(a - b + 1, a + 1-1) do ( res := res * x mod mod) ; for x : Integer.subrange(1, b + 1-1) do ( res := res * (x)->pow(mod - 2) mod mod) ; return res; operation main() pre: true post: true activity: var X : OclAny := null; var Y : OclAny := null; Sequence{X,Y} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var m : int := (X + X - Y) div 3 ; var n : double := X - 2 * m ; if n + 2 * m /= X or 2 * n + m /= Y or n < 0 or m < 0 then ( execute (0)->display() ; return ) else skip ; execute (comb_mod(n + m, n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def setBit(xorValue): count=0 while(xorValue): if(xorValue % 2): count+=1 xorValue=int(xorValue/2) return count def minFlip(n,k): size=int(math.log(n)/math.log(2)+1) max=pow(2,k)-1 max=max<<(size-k) xorValue=(n ^ max) return(setBit(xorValue)) n=27 k=3 print("Min Flips=",minFlip(n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 27 ; k := 3 ; execute ("Min Flips=")->display(); operation setBit(xorValue : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while (xorValue) do ( if (xorValue mod 2) then ( count := count + 1 ) else skip ; xorValue := ("" + ((xorValue / 2)))->toInteger()) ; return count; operation minFlip(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var size : int := ("" + (((n)->log() / (2)->log() + 1)))->toInteger() ; var max : double := (2)->pow(k) - 1 ; max := max * (2->pow((size - k))) ; xorValue := (MathLib.bitwiseXor(n, max)) ; return (setBit(xorValue)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) a=list(map(int,input().split())) ans=0 cnt=0 B=[0 for i in range(N)] for x in range(10**6): for i in range(N): if a[i]>=N : cnt+=a[i]//N B[i]+=a[i]//N a[i]%=N if cnt==0 : print(ans) exit() else : ans+=cnt for j in range(N): a[j]+=(cnt-B[j]) cnt=0 B=[0 for k in range(N)] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; var cnt : int := 0 ; var B : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; for x : Integer.subrange(0, (10)->pow(6)-1) do ( for i : Integer.subrange(0, N-1) do ( if (a[i+1]->compareTo(N)) >= 0 then ( cnt := cnt + a[i+1] div N ; B[i+1] := B[i+1] + a[i+1] div N ; a[i+1] := a[i+1] mod N ) else skip) ; if cnt = 0 then ( execute (ans)->display() ; exit() ) else ( ans := ans + cnt ; for j : Integer.subrange(0, N-1) do ( a[j+1] := a[j+1] + (cnt - B[j+1])) ; cnt := 0 ; B := Integer.subrange(0, N-1)->select(k | true)->collect(k | (0)) )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from numpy import* N,*A=open(0) N,A,S,a=int(N),loadtxt(A,int),1,0 while S : B=A//N ; S=sum(B); a+=S ; A+=S-B*-~ N print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var A : OclAny := null; Sequence{N,A} := OclFile.newOclFile_Write(OclFile.newOclFile(0)) ; var N : OclAny := null; var A : OclAny := null; var S : OclAny := null; var a : OclAny := null; Sequence{N,A,S,a} := Sequence{("" + ((N)))->toInteger(),loadtxt(A, OclType["int"]),1,0} ; while S do ( var B : int := A div N; var S : OclAny := (B)->sum(); a := a + S; A := A + S - B * -MathLib.bitwiseNot(N)) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): n,k=map(int,input().split()); k-=1 print((k+(n % 2)*(k//(n//2)))% n+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); k := k - 1 ; execute ((k + (n mod 2) * (k div (n div 2))) mod n + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- X=int(input()) i=1 a=0 while True : a=a+X if a % 360==0 : print(i) break i+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var X : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 1 ; var a : int := 0 ; while true do ( a := a + X ; if a mod 360 = 0 then ( execute (i)->display() ; break ) else skip ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- 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(100000) input=sys.stdin.readline INF=2**62-1 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(N,A): ans=0 while True : A.sort() l=A.pop() if lpow(62) - 1 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; (compound_stmt (decorator @ (dotted_name (name mt))) (funcdef def (name slv) ( (typedargslist (def_parameters (def_parameter (named_parameter (name N))) , (def_parameter (named_parameter (name A))))) ) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (compound_stmt while (test (logical_test (comparison (expr (atom (name True)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name A)) (trailer . (name sort) (arguments ( )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name A)) (trailer . (name pop) (arguments ( ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name l)))) < (comparison (expr (atom (name N))))))) : (suite (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name l))) - (expr (atom (name N)))))))) ))) // (expr (atom (name N)))) + (expr (atom (number (integer 1)))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name x))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (expr (atom (name x))) * (expr (atom (name N)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name A)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name a))) + (expr (atom (name x))))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name A))))))) ]))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name A)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)))))))) ))))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name ans))))))))))))) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation read_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation read_int_n() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation read_float() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation read_float_n() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["double"])->apply(_x) )); operation read_str() : OclAny pre: true post: true activity: return input()->trim(); operation read_str_n() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["String"])->apply(_x) )); operation error_print(args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) execute ((argument * (test (logical_test (comparison (expr (atom (name args))))))))->display(); operation mt(f : OclAny) : OclAny pre: true post: true activity: skip ; skip ; return wrap; operation main() pre: true post: true activity: var N : OclAny := read_int() ; var A : OclAny := read_int_n() ; execute (slv(N, A))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.readline().strip() def list2d(a,b,c): return[[c]*b for i in range(a)] def list3d(a,b,c,d): return[[[d]*c for j in range(b)]for i in range(a)] def list4d(a,b,c,d,e): return[[[[e]*d for j in range(c)]for j in range(b)]for i in range(a)] def ceil(x,y=1): return int(-(-x//y)) def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(N=None): return list(MAP())if N is None else[INT()for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 N=INT() A=LIST() a=max(A) cnt=0 while a>=N : d,m=divmod(a,N) mxidx=A.index(a) for i in range(N): if i==mxidx : A[i]=m else : A[i]+=d cnt+=d a=max(A) print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; N := INT() ; var A : OclAny := LIST() ; a := (A)->max() ; var cnt : int := 0 ; while (a->compareTo(N)) >= 0 do ( var m : OclAny := null; Sequence{d,m} := Sequence{(a div N), (a mod N)} ; var mxidx : int := A->indexOf(a) - 1 ; for i : Integer.subrange(0, N-1) do ( if i = mxidx then ( A[i+1] := m ) else ( A[i+1] := A[i+1] + d )) ; cnt := cnt + d ; a := (A)->max()) ; execute (cnt)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation list2d(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, a-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ c }, b))); operation list3d(a : OclAny, b : OclAny, c : OclAny, d : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, a-1)->select(i | true)->collect(i | (Integer.subrange(0, b-1)->select(j | true)->collect(j | (MatrixLib.elementwiseMult(Sequence{ d }, c))))); operation list4d(a : OclAny, b : OclAny, c : OclAny, d : OclAny, e : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, a-1)->select(i | true)->collect(i | (Integer.subrange(0, b-1)->select(j | true)->collect(j | (Integer.subrange(0, c-1)->select(j | true)->collect(j | (MatrixLib.elementwiseMult(Sequence{ e }, d))))))); operation ceil(x : OclAny, y : int) : OclAny pre: true post: true activity: if y->oclIsUndefined() then y := 1 else skip; return ("" + ((-(-x div y))))->toInteger(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST(N : OclAny) : OclAny pre: true post: true activity: if N->oclIsUndefined() then N := null else skip; return if N <>= null then (MAP()) else Integer.subrange(0, N-1)->select(i | true)->collect(i | (INT())) endif; operation Yes() pre: true post: true activity: execute ('Yes')->display(); operation No() pre: true post: true activity: execute ('No')->display(); operation YES() pre: true post: true activity: execute ('YES')->display(); operation NO() pre: true post: true activity: execute ('NO')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np I,S=input,sum n,c=int(I()),0 a=np.array(list(map(int,I().split()))) while max(a)>=n : f=a//n ; S=sum(f); a=a-f*n+(S-f); c+=sum(f) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var I : OclAny := null; var S : OclAny := null; Sequence{I,S} := Sequence{input,sum} ; var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := Sequence{("" + ((I())))->toInteger(),0} ; var a : Sequence := (((I().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; while ((a)->max()->compareTo(n)) >= 0 do ( var f : int := a div n; var S : OclAny := (f)->sum(); a := a - f * n + (S - f); c := c + (f)->sum()) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline l=100050 mod=pow(10,9)+7 fact=[1]*(l+1) for i in range(1,l+1): fact[i]=i*fact[i-1]% mod inv=[1]*(l+1) inv[l]=pow(fact[l],mod-2,mod) for i in range(l-1,-1,-1): inv[i]=(i+1)*inv[i+1]% mod def comb(n,r): return fact[n]*inv[r]% mod*inv[n-r]% mod if n>=r>=0 else 0 n,m=map(int,input().split()) ans=-1 for l in[n,m]: for u in range(l+1): if(l-u)% 2 : continue v=(l-u)//2 ans+=comb(u+v,u) ans %=mod ans*=2 ans %=mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var l : int := 100050 ; var mod : double := (10)->pow(9) + 7 ; var fact : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (l + 1)) ; for i : Integer.subrange(1, l + 1-1) do ( fact[i+1] := i * fact[i - 1+1] mod mod) ; var inv : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (l + 1)) ; inv[l+1] := (fact[l+1])->pow(mod - 2) ; for i : Integer.subrange(-1 + 1, l - 1)->reverse() do ( inv[i+1] := (i + 1) * inv[i + 1+1] mod mod) ; skip ; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := -1 ; for l : Sequence{n}->union(Sequence{ m }) do ( for u : Integer.subrange(0, l + 1-1) do ( if (l - u) mod 2 then ( continue ) else skip ; var v : int := (l - u) div 2 ; ans := ans + comb(u + v, u) ; ans := ans mod mod)) ; ans := ans * 2 ; ans := ans mod mod ; execute (ans)->display(); operation comb(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: return if (n->compareTo(r)) >= 0 & (r >= 0) then fact[n+1] * inv[r+1] mod mod * inv[n - r+1] mod mod else 0 endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,m=map(int,input().split()) arr=[2,4] for i in range(max(n,m)): arr.append(arr[-1]+arr[-2]) print((arr[n-1]+arr[m-1]-2)% 1000000007) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := Sequence{2}->union(Sequence{ 4 }) ; for i : Integer.subrange(0, Set{n, m}->max()-1) do ( execute ((arr->last() + arr->front()->last()) : arr)) ; execute ((arr[n - 1+1] + arr[m - 1+1] - 2) mod 1000000007)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) P=10**9+7 F=[1,2] for i in range(100009): F.append((F[-1]+F[-2])% P) print((F[N-1]+F[M-1]-1)*2 % P) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var P : double := (10)->pow(9) + 7 ; var F : Sequence := Sequence{1}->union(Sequence{ 2 }) ; for i : Integer.subrange(0, 100009-1) do ( execute (((F->last() + F->front()->last()) mod P) : F)) ; execute ((F[N - 1+1] + F[M - 1+1] - 1) * 2 mod P)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dp=[1,1] n,m=map(int,input().split()) n,m=max(n,m),min(n,m) a=2*(m-1) for i in range(2,n+1): dp.append((dp[-1]+dp[-2])% 1000000007) print((2*(dp[n]+dp[m]-1))%(1000000007)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dp : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{Set{n, m}->max(),Set{n, m}->min()} ; var a : double := 2 * (m - 1) ; for i : Integer.subrange(2, n + 1-1) do ( execute (((dp->last() + dp->front()->last()) mod 1000000007) : dp)) ; execute ((2 * (dp[n+1] + dp[m+1] - 1)) mod (1000000007))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def random_pictures(n,m): mod=int(1e9+7) fib=[1,1] for i in range(max(n,m)+1): f=fib[-1]+fib[-2] f=f % mod fib.append(f) picture=2*(fib[n]+fib[m]-1) picture=picture % mod return picture n,m=[int(i)for i in input().split()] print(random_pictures(n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{n,m} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute (random_pictures(n, m))->display(); operation random_pictures(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var mod : int := ("" + ((("1e9")->toReal() + 7)))->toInteger() ; var fib : Sequence := Sequence{1}->union(Sequence{ 1 }) ; for i : Integer.subrange(0, Set{n, m}->max() + 1-1) do ( var f : OclAny := fib->last() + fib->front()->last() ; f := f mod mod ; execute ((f) : fib)) ; var picture : double := 2 * (fib[n+1] + fib[m+1] - 1) ; picture := picture mod mod ; return picture; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countWays(num): dp=[0]*(num+1); MOD=100000000+7 ; dp[1]=2 ; for i in range(2,num+1): dp[i]=0 ; for j in range(1,4): if(i-j==0): dp[i]+=1 ; elif(j==1): dp[i]+=dp[i-j]*2 ; elif(i-j>0): dp[i]+=dp[i-j]; if(dp[i]>=MOD): dp[i]%=MOD ; return dp[num]; n=3 ; print(countWays(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := 3; ; execute (countWays(n))->display();; operation countWays(num : OclAny) pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (num + 1)); ; var MOD : int := 100000000 + 7; ; dp[1+1] := 2; ; for i : Integer.subrange(2, num + 1-1) do ( dp[i+1] := 0; ; for j : Integer.subrange(1, 4-1) do ( if (i - j = 0) then ( dp[i+1] := dp[i+1] + 1; ) else (if (j = 1) then ( dp[i+1] := dp[i+1] + dp[i - j+1] * 2; ) else (if (i - j > 0) then ( dp[i+1] := dp[i+1] + dp[i - j+1]; ) else skip ) ) ) ; if ((dp[i+1]->compareTo(MOD)) >= 0) then ( dp[i+1] := dp[i+1] mod MOD; ) else skip) ; return dp[num+1];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline write=sys.stdout.write def stern_brocot(p,n): la=0 ; lb=1 ra=1 ; rb=0 lu=ru=1 lx=0 ; ly=1 rx=1 ; ry=0 while lu or ru : ma=la+ra ; mb=lb+rb if p*mb**2collect( _x | (OclType["int"])->apply(_x) ) ; if p = 0 then ( break ) else skip ; Sequence{lx,ly,rx,ry} := stern_brocot(p, n) ; write(StringLib.format("%d/%d %d/%d\n",Sequence{rx, ry, lx, ly}))); operation stern_brocot(p : OclAny, n : OclAny) : OclAny pre: true post: true activity: var la : int := 0; var lb : int := 1 ; var ra : int := 1; var rb : int := 0 ; var lu : OclAny := 1; var ru : int := 1 ; var lx : int := 0; var ly : int := 1 ; var rx : int := 1; var ry : int := 0 ; while lu or ru do ( var ma : int := la + ra; var mb : int := lb + rb ; if (p * (mb)->pow(2)->compareTo((ma)->pow(2))) < 0 then ( ra := ma; rb := mb ; if (ma->compareTo(n)) <= 0 & (mb->compareTo(n)) <= 0 then ( rx := ma; ry := mb ) else ( lu := 0 ) ) else ( la := ma; lb := mb ; if (ma->compareTo(n)) <= 0 & (mb->compareTo(n)) <= 0 then ( lx := ma; ly := mb ) else ( ru := 0 ) )) ; return lx, ly, rx, ry; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math x=int(input()) def lcm(x,y): return(x*y)//math.gcd(x,y) print(lcm(x,360)//x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; execute (lcm(x, 360) div x)->display(); operation lcm(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return (x * y) div (x)->gcd(y); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while(t): n,k=[int(i)for i in input().split()] if(n % 2==0): if(k % n==0): print(n) else : print(k % n) else : a=0 if(k % n!=0): a=n+1-(k % n) else : a=1 clash=n//2 if((k-1)% clash==0): if(a==n): print(1) else : print(a+1) else : diff=(k-1)% clash temp=0 if(a==n): temp=1 else : temp=(a+1) x=temp+(2*diff) if(x>n): if(x % n==0): x=n else : x=x % n print(x) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (t) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if (n mod 2 = 0) then ( if (k mod n = 0) then ( execute (n)->display() ) else ( execute (k mod n)->display() ) ) else ( var a : int := 0 ; if (k mod n /= 0) then ( a := n + 1 - (k mod n) ) else ( a := 1 ) ; var clash : int := n div 2 ; if ((k - 1) mod clash = 0) then ( if (a = n) then ( execute (1)->display() ) else ( execute (a + 1)->display() ) ) else ( var diff : int := (k - 1) mod clash ; var temp : int := 0 ; if (a = n) then ( temp := 1 ) else ( temp := (a + 1) ) ; var x : int := temp + (2 * diff) ; if ((x->compareTo(n)) > 0) then ( if (x mod n = 0) then ( x := n ) else ( x := x mod n ) ) else skip ; execute (x)->display() ) ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math def rational(p,n): rt=math.sqrt(p) k=math.floor(rt) mi=n mx=n mikk=0 mibb=0 mxkk=0 mxbb=0 for i in range(1,n+1): a=(rt-k)*i b=math.floor(a) if mi>a-b and k*i+b<=n : mi=a-b mikk=i mibb=b if mx>b+1-a and k*i+(b+1)<=n : mx=b+1-a mxkk=i mxbb=b print("{}/{}{}/{}".format(k*mxkk+(mxbb+1),mxkk,k*mikk+mibb,mikk)) while True : line=input().split() p,n=map(int,list(line)) if p==0 and n==0 : break rational(p,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; while true do ( var line : OclAny := input().split() ; Sequence{p,n} := ((line))->collect( _x | (OclType["int"])->apply(_x) ) ; if p = 0 & n = 0 then ( break ) else skip ; rational(p, n)); operation rational(p : OclAny, n : OclAny) pre: true post: true activity: var rt : double := (p)->sqrt() ; var k : double := (rt)->floor() ; var mi : OclAny := n ; var mx : OclAny := n ; var mikk : int := 0 ; var mibb : int := 0 ; var mxkk : int := 0 ; var mxbb : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( var a : double := (rt - k) * i ; var b : double := (a)->floor() ; if (mi->compareTo(a - b)) > 0 & (k * i + b->compareTo(n)) <= 0 then ( mi := a - b ; mikk := i ; mibb := b ) else skip ; if (mx->compareTo(b + 1 - a)) > 0 & (k * i + (b + 1)->compareTo(n)) <= 0 then ( mx := b + 1 - a ; mxkk := i ; mxbb := b ) else skip) ; execute (StringLib.interpolateStrings("{}/{}{}/{}", Sequence{k * mxkk + (mxbb + 1), mxkk, k * mikk + mibb, mikk}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) s=str(n) if len(s)<3 : print(s[-1]) else : print(min(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := ("" + ((n))) ; if (s)->size() < 3 then ( execute (s->last())->display() ) else ( execute ((s)->min())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): s=input() if len(s)==2 and min(list(map(int,s)))==int(s[0]): print(s[1]) else : print(min(list(map(int,s)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if (s)->size() = 2 & (((s)->collect( _x | (OclType["int"])->apply(_x) )))->min() = ("" + ((s->first())))->toInteger() then ( execute (s[1+1])->display() ) else ( execute ((((s)->collect( _x | (OclType["int"])->apply(_x) )))->min())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a=list(input()) if len(a)<=2 : print(a[-1]) else : print(min(map(int,a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if (a)->size() <= 2 then ( execute (a->last())->display() ) else ( execute (((a)->collect( _x | (OclType["int"])->apply(_x) ))->min())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: print(min(s[len(s)<4 :-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( execute ((s.subrange((s)->size() < 4+1, -1))->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(0,t): n=(input()) L=[int(x)for x in n] while len(L)>1 : index=L.index(min(L)) if(len(L)==2): print(L[1]) break elif(len(L)% 2==0): L[index],L[1]=L[1],L[index] L.pop(len(L)-1) else : if(index!=1): L[index],L[1]=L[1],L[index] L.pop(len(L)-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : String := ((OclFile["System.in"]).readLine()) ; var L : Sequence := n->characters()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; while (L)->size() > 1 do ( var index : int := L->indexOf((L)->min()) - 1 ; if ((L)->size() = 2) then ( execute (L[1+1])->display() ; break ) else (if ((L)->size() mod 2 = 0) then ( var L[index+1] : OclAny := null; var L[1+1] : OclAny := null; Sequence{L[index+1],L[1+1]} := Sequence{L[1+1],L[index+1]} ; L := L->excludingAt((L)->size() - 1+1) ) else ( if (index /= 1) then ( var L[index+1] : OclAny := null; var L[1+1] : OclAny := null; Sequence{L[index+1],L[1+1]} := Sequence{L[1+1],L[index+1]} ) else skip ; L := L->excludingAt((L)->size() - 1+1) ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def sumofoddFactors(n): res=1 while n % 2==0 : n=n//2 for i in range(3,int(math.sqrt(n)+1)): count=0 curr_sum=1 curr_term=1 while n % i==0 : count+=1 n=n//i curr_term*=i curr_sum+=curr_term res*=curr_sum if n>=2 : res*=(1+n) return res n=30 print(sumofoddFactors(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 30 ; execute (sumofoddFactors(n))->display(); operation sumofoddFactors(n : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; while n mod 2 = 0 do ( n := n div 2) ; for i : Integer.subrange(3, ("" + (((n)->sqrt() + 1)))->toInteger()-1) do ( var count : int := 0 ; var curr_sum : int := 1 ; var curr_term : int := 1 ; while n mod i = 0 do ( count := count + 1 ; n := n div i ; curr_term := curr_term * i ; curr_sum := curr_sum + curr_term) ; res := res * curr_sum) ; if n >= 2 then ( res := res * (1 + n) ) else skip ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as m def sumofFactors(n): res=1 for i in range(2,int(m.sqrt(n)+1)): curr_sum=1 curr_term=1 while n % i==0 : n=n/i ; curr_term=curr_term*i ; curr_sum+=curr_term ; res=res*curr_sum if n>2 : res=res*(1+n) return res ; sum=sumofFactors(30) print("Sum of all divisors is: ",sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var sum : OclAny := sumofFactors(30) ; execute ("Sum of all divisors is: ")->display(); operation sumofFactors(n : OclAny) pre: true post: true activity: var res : int := 1 ; for i : Integer.subrange(2, ("" + ((m.sqrt(n) + 1)))->toInteger()-1) do ( var curr_sum : int := 1 ; var curr_term : int := 1 ; while n mod i = 0 do ( n := n / i; ; curr_term := curr_term * i; ; curr_sum := curr_sum + curr_term;) ; res := res * curr_sum) ; if n > 2 then ( res := res * (1 + n) ) else skip ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def dfs(remains,elapsed,hx,hy,prev): global crystals,dc if not remains : return True remains_c=set() for i in remains : cx,cy,dfd=crystals[i] new_elapsed=elapsed+dc[prev][i] if dfd<=new_elapsed : return False remains_c.add((i,cx,cy,new_elapsed)) for i,cx,cy,new_elapsed in remains_c : remains.remove(i) if dfs(remains,new_elapsed,cx,cy,i): return True remains.add(i) return False while True : n,hx,hy,dx,dy=map(int,input().split()) if n==0 : break crystals_in=[tuple(map(int,input().split()))for _ in range(n)] crystals=[(cx,cy,sqrt((cx-dx)**2+(cy-dy)**2))for cx,cy in crystals_in] crystals_in+=[(hx,hy)] dc=[[sqrt((x2-x1)**2+(y2-y1)**2)for x2,y2 in crystals_in]for x1,y1 in crystals_in] print('YES' if dfs(set(range(n)),0,hx,hy,n)else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { attribute crystals : OclAny; attribute dc : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; while true do ( var n : OclAny := null; var dx : OclAny := null; var dy : OclAny := null; Sequence{n,hx,hy,dx,dy} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var crystals_in : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; crystals := crystals_in->select(_tuple | true)->collect(_tuple | let cx : OclAny = _tuple->at(1) in let cy : OclAny = _tuple->at(2) in (Sequence{cx, cy, sqrt(((cx - dx))->pow(2) + ((cy - dy))->pow(2))})) ; crystals_in := crystals_in + Sequence{ Sequence{hx, hy} } ; dc := crystals_in->select(_tuple | true)->collect(_tuple | let x1 : OclAny = _tuple->at(1) in let y1 : OclAny = _tuple->at(2) in (crystals_in->select(_tuple | true)->collect(_tuple | let x2 : OclAny = _tuple->at(1) in let y2 : OclAny = _tuple->at(2) in (sqrt(((x2 - x1))->pow(2) + ((y2 - y1))->pow(2)))))) ; execute (if dfs(Set{}->union((Integer.subrange(0, n-1))), 0, hx, hy, n) then 'YES' else 'NO' endif)->display()); operation dfs(remains : OclAny, elapsed : OclAny, hx : OclAny, hy : OclAny, prev : OclAny) : OclAny pre: true post: true activity: skip; skip ; if not(remains) then ( return true ) else skip ; var remains_c : Set := Set{}->union(()) ; for i : remains do ( var cx : OclAny := null; var cy : OclAny := null; var dfd : OclAny := null; Sequence{cx,cy,dfd} := crystals[i+1] ; var new_elapsed : OclAny := elapsed + dc[prev+1][i+1] ; if (dfd->compareTo(new_elapsed)) <= 0 then ( return false ) else skip ; execute ((Sequence{i, cx, cy, new_elapsed}) : remains_c)) ; for _tuple : remains_c do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var cx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var cy : OclAny := _tuple->at(_indx); _indx := _indx + 1; var new_elapsed : OclAny := _tuple->at(_indx); execute ((i) /: remains) ; if dfs(remains, new_elapsed, cx, cy, i) then ( return true ) else skip ; execute ((i) : remains)) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def mi(): return map(int,input().split()) def ii(): return int(input()) def main(): X=ii() for i in range(1,361): if(X*i)% 360==0 : print(i) return if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation mi() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation ii() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation main() pre: true post: true activity: var X : OclAny := ii() ; for i : Integer.subrange(1, 361-1) do ( if (X * i) mod 360 = 0 then ( execute (i)->display() ; return ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): from math import sqrt from sys import stdin f_i=stdin def dfs(point,remain,elapsed): if not remain : return True next_c=set() for c in remain : new_elapsed=elapsed+adj[point][c] if new_elapsed>=from_d[c]: return False next_c.add((c,new_elapsed)) for c,new_elapsed in next_c : remain.remove(c) if dfs(c,remain,new_elapsed): return True remain.add(c) return False while True : n,hx,hy,dx,dy=map(int,f_i.readline().split()) if n==0 : break C=[tuple(map(int,f_i.readline().split()))for i in range(n)] from_d=tuple(sqrt((cx-dx)**2+(cy-dy)**2)for cx,cy in C) C.append((hx,hy)) adj=tuple(tuple(sqrt((px-qx)**2+(py-qy)**2)for qx,qy in C)for px,py in C) if dfs(n,set(range(n)),0): print("YES") else : print("NO") solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: skip ; skip ; var f_i : OclAny := stdin ; skip ; while true do ( var n : OclAny := null; var hx : OclAny := null; var hy : OclAny := null; var dx : OclAny := null; var dy : OclAny := null; Sequence{n,hx,hy,dx,dy} := (f_i.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var C : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((f_i.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var from_d : Sequence := ((argument (test (logical_test (comparison (expr (atom (name sqrt)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name cx))) - (expr (atom (name dx)))))))) ))) ** (expr (atom (number (integer 2))))) + (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name cy))) - (expr (atom (name dy)))))))) ))) ** (expr (atom (number (integer 2))))))))))) ))))))) (comp_for for (exprlist (expr (atom (name cx))) , (expr (atom (name cy)))) in (logical_test (comparison (expr (atom (name C)))))))) ; execute ((Sequence{hx, hy}) : C) ; var adj : Sequence := ((argument (test (logical_test (comparison (expr (atom (name tuple)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sqrt)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name px))) - (expr (atom (name qx)))))))) ))) ** (expr (atom (number (integer 2))))) + (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name py))) - (expr (atom (name qy)))))))) ))) ** (expr (atom (number (integer 2))))))))))) ))))))) (comp_for for (exprlist (expr (atom (name qx))) , (expr (atom (name qy)))) in (logical_test (comparison (expr (atom (name C)))))))) ))))))) (comp_for for (exprlist (expr (atom (name px))) , (expr (atom (name py)))) in (logical_test (comparison (expr (atom (name C)))))))) ; if dfs(n, Set{}->union((Integer.subrange(0, n-1))), 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for tt in range(int(input())): n,k=map(int,input().split()) if n % 2==0 : if((k)% n)==0 : print(n) else : print(k % n) else : r2=(k-1)//(n//2) if((r2+k)% n)==0 : print(n) else : print(((r2+k)% n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for tt : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n mod 2 = 0 then ( if ((k) mod n) = 0 then ( execute (n)->display() ) else ( execute (k mod n)->display() ) ) else ( var r2 : int := (k - 1) div (n div 2) ; if ((r2 + k) mod n) = 0 then ( execute (n)->display() ) else ( execute (((r2 + k) mod n))->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- nshirts=int(input()) shirts=[[]for _ in range(nshirts)] for _ in range(3): temp=list(map(int,input().split())) for i in range(len(shirts)): shirts[i].append(temp[i]) shirts.sort(key=lambda list : list[0]) nbuyers=int(input()) buyers=list(map(int,input().split())) ptr=[0 for _ in range(3)] for x in buyers : p=ptr[x-1] while(ptoInteger() ; var shirts : Sequence := Integer.subrange(0, nshirts-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, 3-1) do ( var temp : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, (shirts)->size()-1) do ((expr (atom (name shirts)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name temp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))))) ; shirts := shirts->sort() ; var nbuyers : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var buyers : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ptr : Sequence := Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (0)) ; for x : buyers do ( var p : OclAny := ptr[x - 1+1] ; while ((p->compareTo(nshirts)) < 0 & (shirts[p+1]->tail())->excludes(x)) do ( p := p + 1) ; if (p = nshirts) then ( execute ("-1")->display() ) else ( execute (shirts[p+1]->first())->display() ; shirts[p+1] := MatrixLib.elementwiseMult(Sequence{ -1 }, 3) ) ; ptr[x - 1+1] := p); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INDEX={"11" : 0,"12" : 1,"13" : 2,"21" : 1,"22" : 3,"23" : 4,"31" : 2,"32" : 4,"33" : 5} def przerob(N,ceny,kol1,kol2): wej=[[]for i in range(N)] for i in range(N): wej[i].append(ceny[i]) wej[i].append(kol1[i]) wej[i].append(kol2[i]) return sorted(wej,reverse=True) def rozwiaz(kolor,kosz): x=[] for i in range(1,4): akt=INDEX[kolor+str(i)] if len(kosz[akt])!=0 : x.append((kosz[akt][-1],akt)) if len(x)==0 : return-1 x.sort() return kosz[x[0][1]].pop() def main(N,wej,zapyt): kosz=[[]for i in range(6)] for(c,k1,k2)in wej : kosz[INDEX[k1+k2]].append(c) for i in zapyt : print(rozwiaz(str(i),kosz),end=" ") N=int(input()) ceny=list(map(int,input().split())) kol1=input().split() kol2=input().split() Q=int(input()) zapyt=list(map(int,input().split())) main(N,przerob(N,ceny,kol1,kol2),zapyt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INDEX : Map := Map{ "11" |-> 0 }->union(Map{ "12" |-> 1 }->union(Map{ "13" |-> 2 }->union(Map{ "21" |-> 1 }->union(Map{ "22" |-> 3 }->union(Map{ "23" |-> 4 }->union(Map{ "31" |-> 2 }->union(Map{ "32" |-> 4 }->union(Map{ "33" |-> 5 })))))))) ; skip ; skip ; skip ; N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; ceny := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; kol1 := input().split() ; kol2 := input().split() ; var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; zapyt := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; main(N, przerob(N, ceny, kol1, kol2), zapyt); operation przerob(N : OclAny, ceny : OclAny, kol1 : OclAny, kol2 : OclAny) : OclAny pre: true post: true activity: var wej : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, N-1) do ((expr (atom (name wej)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ceny)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))) ; (expr (atom (name wej)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name kol1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))) ; (expr (atom (name wej)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name kol2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))) ; return wej->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))); operation rozwiaz(kolor : OclAny, kosz : OclAny) : OclAny pre: true post: true activity: var x : Sequence := Sequence{} ; for i : Integer.subrange(1, 4-1) do ( var akt : OclAny := INDEX[kolor + ("" + ((i)))+1] ; if (kosz[akt+1])->size() /= 0 then ( execute ((Sequence{kosz[akt+1]->last(), akt}) : x) ) else skip) ; if (x)->size() = 0 then ( return -1 ) else skip ; x := x->sort() ; return kosz[x->first()[1+1]+1]->last(); operation main(N : OclAny, wej : OclAny, zapyt : OclAny) pre: true post: true activity: kosz := Integer.subrange(0, 6-1)->select(i | true)->collect(i | (Sequence{})) ; for Sequence{c, k1, k2} : wej do ((expr (atom (name kosz)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name INDEX)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name k1))) + (expr (atom (name k2))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))) ; for i : zapyt do ( execute (rozwiaz(("" + ((i))), kosz))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq n=int(input()) p=list(map(int,input().split())) a=list(map(int,input().split())) b=list(map(int,input().split())) color=[[]for i in range(3)] removed=set() for i in range(n): color[a[i]-1].append((p[i],b[i]-1)) if a[i]!=b[i]: color[b[i]-1].append((p[i],a[i]-1)) _=[heapq.heapify(price)for price in color] m=int(input()) buyer=[c-1 for c in list(map(int,input().split()))] for c in buyer : while color[c]and(color[c][0][0],c)in removed : removed.remove((color[c][0][0],c)) heapq.heappop(color[c]) if color[c]: ans=heapq.heappop(color[c]) if ans[1]!=c : removed.add(ans) print(ans[0],end=' ') else : print(-1,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var color : Sequence := Integer.subrange(0, 3-1)->select(i | true)->collect(i | (Sequence{})) ; var removed : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ((expr (atom (name color)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))) , (test (logical_test (comparison (expr (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (number (integer 1))))))))) )))))))) )))) ; if a[i+1] /= b[i+1] then ( (expr (atom (name color)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))) , (test (logical_test (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (number (integer 1))))))))) )))))))) )))) ) else skip) ; var _anon : Sequence := color->select(price | true)->collect(price | (heapq.heapify(price))) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var buyer : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->select(c | true)->collect(c | (c - 1)) ; for c : buyer do ( while color[c+1] & (removed)->includes(Sequence{color[c+1]->first()->first(), c}) do ( execute ((Sequence{color[c+1]->first()->first(), c}) /: removed) ; heapq.heappop(color[c+1])) ; if color[c+1] then ( var ans : OclAny := heapq.heappop(color[c+1]) ; if ans[1+1] /= c then ( execute ((ans) : removed) ) else skip ; execute (ans->first())->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- rook=input() knight=input() rook=(ord(rook[0])-ord('a'),int(rook[1])-1) knight=(ord(knight[0])-ord('a'),int(knight[1])-1) count=63 for i in range(8): for j in range(8): if i==rook[0]or j==rook[1]: count-=1 else : dr=sorted([abs(i-rook[0]),abs(j-rook[1])]) dk=sorted([abs(i-knight[0]),abs(j-knight[1])]) if dr==[1,2]or dk==[1,2]: count-=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var rook : String := (OclFile["System.in"]).readLine() ; var knight : String := (OclFile["System.in"]).readLine() ; rook := Sequence{(rook->first())->char2byte() - ('a')->char2byte(), ("" + ((rook[1+1])))->toInteger() - 1} ; knight := Sequence{(knight->first())->char2byte() - ('a')->char2byte(), ("" + ((knight[1+1])))->toInteger() - 1} ; var count : int := 63 ; for i : Integer.subrange(0, 8-1) do ( for j : Integer.subrange(0, 8-1) do ( if i = rook->first() or j = rook[1+1] then ( count := count - 1 ) else ( var dr : Sequence := Sequence{(i - rook->first())->abs()}->union(Sequence{ (j - rook[1+1])->abs() })->sort() ; var dk : Sequence := Sequence{(i - knight->first())->abs()}->union(Sequence{ (j - knight[1+1])->abs() })->sort() ; if dr = Sequence{1}->union(Sequence{ 2 }) or dk = Sequence{1}->union(Sequence{ 2 }) then ( count := count - 1 ) else skip ))) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def isPrime(n): if(n<=1): return False if(n<=3): return True if(n % 2==0 or n % 3==0): return False for i in range(5,int(sqrt(n))+1,6): if(n % i==0 or n %(i+2)==0): return False return True def twinPrime(n1,n2): return(isPrime(n1)and isPrime(n2)and abs(n1-n2)==2) def countTwinPairs(arr,n): count=0 for i in range(n): for j in range(i+1,n): if(twinPrime(arr[i],arr[j])): count+=1 return count if __name__=='__main__' : arr=[2,3,5,11] n=len(arr) print(countTwinPairs(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 11 }))) ; n := (arr)->size() ; execute (countTwinPairs(arr, n))->display() ) else skip; operation isPrime(n : OclAny) : OclAny pre: true post: true activity: if (n <= 1) then ( return false ) else skip ; if (n <= 3) then ( return true ) else skip ; if (n mod 2 = 0 or n mod 3 = 0) then ( return false ) else skip ; for i : Integer.subrange(5, ("" + ((sqrt(n))))->toInteger() + 1-1)->select( $x | ($x - 5) mod 6 = 0 ) do ( if (n mod i = 0 or n mod (i + 2) = 0) then ( return false ) else skip) ; return true; operation twinPrime(n1 : OclAny, n2 : OclAny) : OclAny pre: true post: true activity: return (isPrime(n1) & isPrime(n2) & (n1 - n2)->abs() = 2); operation countTwinPairs(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if (twinPrime(arr[i+1], arr[j+1])) then ( count := count + 1 ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=[] w=[] for i in range(m): a=list(map(int,input().split())) w.append(a.index(max(a))+1) bset=set(w) mpst_common=None qty=0 for item in bset : q=w.count(item) if q>qty : qty=q mpst_common=item print(mpst_common) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{} ; var w : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((a->indexOf((a)->max()) - 1 + 1) : w)) ; var bset : Set := Set{}->union((w)) ; var mpst_common : OclAny := null ; var qty : int := 0 ; for item : bset do ( var q : int := w->count(item) ; if (q->compareTo(qty)) > 0 then ( qty := q ; mpst_common := item ) else skip) ; execute (mpst_common)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=list(map(int,input().split())) b=[0]*n for i in range(m): a=list(map(int,input().split())) k=a.index(max(a)) b[k]+=1 print(b.index(max(b))+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, m-1) do ( var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k : int := a->indexOf((a)->max()) - 1 ; b[k+1] := b[k+1] + 1) ; execute (b->indexOf((b)->max()) - 1 + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def arr_int(arr): for i in range(len(arr)): arr[i]=int(arr[i]) return(arr) def winner(lista): max_list=max(lista) ans=0 for i in range(len(lista)): if lista[i]==max_list : ans=i break return ans def main(): n,m=input().split() arr_can=[] for i in range(int(n)): arr_can.append(0) for i in range(int(m)): city=input().split() city=arr_int(city) win=winner(city) arr_can[win]+=1 ans=winner(arr_can) print(ans+1) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; main(); operation arr_int(arr : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, (arr)->size()-1) do ( arr[i+1] := ("" + ((arr[i+1])))->toInteger()) ; return (arr); operation winner(lista : OclAny) : OclAny pre: true post: true activity: var max_list : OclAny := (lista)->max() ; var ans : int := 0 ; for i : Integer.subrange(0, (lista)->size()-1) do ( if lista[i+1] = max_list then ( ans := i ; break ) else skip) ; return ans; operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split() ; var arr_can : Sequence := Sequence{} ; for i : Integer.subrange(0, ("" + ((n)))->toInteger()-1) do ( execute ((0) : arr_can)) ; for i : Integer.subrange(0, ("" + ((m)))->toInteger()-1) do ( var city : OclAny := input().split() ; city := arr_int(city) ; var win : OclAny := winner(city) ; arr_can[win+1] := arr_can[win+1] + 1) ; ans := winner(arr_can) ; execute (ans + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for q in range(t): n=int(input()) s1=input() s2=input() for i in range(n): if s1[i]!=s2[i]: if not((s1[i]=='G' and s2[i]=='B')or(s2[i]=='G' and s1[i]=='B')): print('NO') break if i==n-1 : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for q : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s1 : String := (OclFile["System.in"]).readLine() ; var s2 : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, n-1) do ( if s1[i+1] /= s2[i+1] then ( if not(((s1[i+1] = 'G' & s2[i+1] = 'B') or (s2[i+1] = 'G' & s1[i+1] = 'B'))) then ( execute ('NO')->display() ; break ) else skip ) else skip ; if i = n - 1 then ( execute ('YES')->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n,m=map(int,input().split()) b=[] for _ in range(m): l=list(map(int,input().split())) m=max(l) i=0 while 1>0 : if l[i]==m : break i+=1 b.append(i+1) b.sort() test_list=Counter(b) res=test_list.most_common(1)[0][0] print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : Sequence := Sequence{} ; for _anon : Integer.subrange(0, m-1) do ( var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : OclAny := (l)->max() ; var i : int := 0 ; while 1 > 0 do ( if l[i+1] = m then ( break ) else skip ; i := i + 1) ; execute ((i + 1) : b)) ; b := b->sort() ; var test_list : OclAny := Counter(b) ; var res : OclAny := test_list.most_common(1)->first()->first() ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=[] w=[] for i in range(m): a=list(map(int,input().split())) w.append(a.index(max(a))+1) bset=set(w) mpst_common=None qty=0 for item in bset : q=w.count(item) if q>qty : qty=q mpst_common=item print(mpst_common) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{} ; var w : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((a->indexOf((a)->max()) - 1 + 1) : w)) ; var bset : Set := Set{}->union((w)) ; var mpst_common : OclAny := null ; var qty : int := 0 ; for item : bset do ( var q : int := w->count(item) ; if (q->compareTo(qty)) > 0 then ( qty := q ; mpst_common := item ) else skip) ; execute (mpst_common)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : t-=1 n,k=map(int,input().split()) k-=1 if n % 2==0 : print(k % n+1) else : s=(k)//(n//2) print((k+s)% n+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( t := t - 1 ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; k := k - 1 ; if n mod 2 = 0 then ( execute (k mod n + 1)->display() ) else ( var s : int := (k) div (n div 2) ; execute ((k + s) mod n + 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def EqualNumbers(a,n): sum=0 ; for i in range(n): sum+=a[i]; if(sum % n): return n-1 ; return n ; a=[1,4,1]; n=len(a); print(EqualNumbers(a,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{1}->union(Sequence{4}->union(Sequence{ 1 })); ; n := (a)->size(); ; execute (EqualNumbers(a, n))->display();; operation EqualNumbers(a : OclAny, n : OclAny) pre: true post: true activity: var sum : int := 0; ; for i : Integer.subrange(0, n-1) do ( sum := sum + a[i+1];) ; if (sum mod n) then ( return n - 1; ) else skip ; return n;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def find(n,k): if(n+1>=k): return(k-1) else : return(2*n+1-k) n=4 k=7 freq=find(n,k) if(freq<0): print(" element not exist") else : print(" Frequency of ",k," is ",freq) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 4 ; k := 7 ; var freq : OclAny := find(n, k) ; if (freq < 0) then ( execute (" element not exist")->display() ) else ( execute (" Frequency of ")->display() ); operation find(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if ((n + 1->compareTo(k)) >= 0) then ( return (k - 1) ) else ( return (2 * n + 1 - k) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=[int(c)for c in input().split()] rotate=(n-arr[0])% n for i in range(1,n): rotate*=-1 if(arr[i]+rotate)% n!=i : print("No") quit() print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := input().split()->select(c | true)->collect(c | (("" + ((c)))->toInteger())) ; var rotate : int := (n - arr->first()) mod n ; for i : Integer.subrange(1, n-1) do ( rotate := rotate * -1 ; if (arr[i+1] + rotate) mod n /= i then ( execute ("No")->display() ; quit() ) else skip) ; execute ("Yes")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(input()) a=list(map(int,sys.stdin.readline().strip().split())) nr=n-a[0] for i in range(n): if(i % 2==0): a[i]+=nr else : a[i]-=nr a[i]=a[i]% n if a==list(range(n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var nr : double := n - a->first() ; for i : Integer.subrange(0, n-1) do ( if (i mod 2 = 0) then ( a[i+1] := a[i+1] + nr ) else ( a[i+1] := a[i+1] - nr ) ; a[i+1] := a[i+1] mod n) ; if a = (Integer.subrange(0, n-1)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(x)for x in input().split()] diff=(n-a[0])% n for i in range(1,n): if i % 2==0 : if(a[i]+diff)% n!=i : print("No") exit() else : if(a[i]-diff)% n!=i : print("No") exit() print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var diff : int := (n - a->first()) mod n ; for i : Integer.subrange(1, n-1) do ( if i mod 2 = 0 then ( if (a[i+1] + diff) mod n /= i then ( execute ("No")->display() ; exit() ) else skip ) else ( if (a[i+1] - diff) mod n /= i then ( execute ("No")->display() ; exit() ) else skip )) ; execute ("Yes")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) diff=(n-arr[0])% n real='Yes' for i in range(n): if i % 2 : rez=(arr[i]-diff)% n else : rez=(arr[i]+diff)% n if rez!=i : real='No' break print(real) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var diff : int := (n - arr->first()) mod n ; var real : String := 'Yes' ; for i : Integer.subrange(0, n-1) do ( if i mod 2 then ( var rez : int := (arr[i+1] - diff) mod n ) else ( rez := (arr[i+1] + diff) mod n ) ; if rez /= i then ( real := 'No' ; break ) else skip) ; execute (real)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) w=list(map(int,input().split())) if n==1 : print("Yes") elif n==2 : if abs(w[0]-w[1])!=1 : print("No") else : print("Yes") else : for i in range(n-2): if w[i]>w[i+2]: w[i+2]+=n if w[i+2]-w[i]!=2 : print("No") break else : if w[0]+w[1]==n+1 or w[0]+w[1]==1 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = 1 then ( execute ("Yes")->display() ) else (if n = 2 then ( if (w->first() - w[1+1])->abs() /= 1 then ( execute ("No")->display() ) else ( execute ("Yes")->display() ) ) else ( (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 2)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) > (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 2)))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 2)))))))))) ])))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name n)))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 2)))))))))) ]))) - (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))) != (comparison (expr (atom (number (integer 2)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "No"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) + (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))) == (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))) or (logical_test (comparison (comparison (expr (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) + (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))) == (comparison (expr (atom (number (integer 1))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Yes"))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "No"))))))) ))))))))))))))))))) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import* from math import* from decimal import* from collections import* import sys def _input(): return map(int,input().split()) def _list(): return list(map(int,input().split())) def _int(): return int(input()) def solves(): n,a,b=_input() lst1=_list() lst2=_list() a=[0]*n for i in lst1 : a[i-1]=1 for i in lst2 : a[i-1]=2 print(*a) t=1 for _ in range(0,t): solves() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solves()); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation _list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation _int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation solves() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := _input() ; var lst1 : OclAny := _list() ; var lst2 : OclAny := _list() ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : lst1 do ( a[i - 1+1] := 1) ; for i : lst2 do ( a[i - 1+1] := 2) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd x=int(input()) print(360//gcd(360,x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (360 div gcd(360, x))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter,OrderedDict from itertools import permutations as perm from fractions import Fraction from collections import deque from sys import stdin from bisect import* from heapq import* from math import* g=lambda : stdin.readline().strip() gl=lambda : g().split() gil=lambda :[int(var)for var in gl()] gfl=lambda :[float(var)for var in gl()] gcl=lambda : list(g()) gbs=lambda :[int(var)for var in g()] mod=int(1e9)+7 inf=float("inf") g() n=int(2e6)+2 f=[0]*(n) ans=0 for v in gil(): f[v]+=1 for i in range(n): ans+=(f[i]& 1) f[i]//=2 if f[i]: if i+1trim()) ; var gl : Function := lambda $$ : OclAny in (g->apply().split()) ; var gil : Function := lambda $$ : OclAny in (gl->apply()->select(var | true)->collect(var | (("" + ((var)))->toInteger()))) ; var gfl : Function := lambda $$ : OclAny in (gl->apply()->select(var | true)->collect(var | (("" + ((var)))->toReal()))) ; var gcl : Function := lambda $$ : OclAny in ((g->apply())) ; var gbs : Function := lambda $$ : OclAny in (g->apply()->select(var | true)->collect(var | (("" + ((var)))->toInteger()))) ; var mod : int := ("" + ((("1e9")->toReal())))->toInteger() + 7 ; var Math_PINFINITY : double := ("" + (("inf")))->toReal() ; g() ; var n : int := ("" + ((("2e6")->toReal())))->toInteger() + 2 ; var f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n)) ; var ans : int := 0 ; for v : gil->apply() do ( f[v+1] := f[v+1] + 1) ; for i : Integer.subrange(0, n-1) do ( ans := ans + (MathLib.bitwiseAnd(f[i+1], 1)) ; f[i+1] := f[i+1] div 2 ; if f[i+1] then ( if (i + 1->compareTo(n)) < 0 then ( f[i + 1+1] := f[i + 1+1] + f[i+1] ) else ( execute ("break")->display() ; execute (f[i+1])->display() ) ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict mxn=10**6 n=int(input()) a=list(map(int,input().split())) d=[0]*(mxn+2) for i in a : d[i]+=1 for i in range(1+mxn): q=d[i]//2 d[i+1]+=q d[i]-=2*q ct=0 for i in d : ct+=bin(i).count("1") print(ct) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var mxn : double := (10)->pow(6) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (mxn + 2)) ; for i : a do ( d[i+1] := d[i+1] + 1) ; for i : Integer.subrange(0, 1 + mxn-1) do ( var q : int := d[i+1] div 2 ; d[i + 1+1] := d[i + 1+1] + q ; d[i+1] := d[i+1] - 2 * q) ; var ct : int := 0 ; for i : d do ( ct := ct + bin(i)->count("1")) ; execute (ct)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) cnt=[0]*(10**6+100) for i in l : cnt[i]+=1 s=0 ans=0 for i in cnt : s+=i ans+=s % 2 s//=2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((10)->pow(6) + 100)) ; for i : l do ( cnt[i+1] := cnt[i+1] + 1) ; var s : int := 0 ; var ans : int := 0 ; for i : cnt do ( s := s + i ; ans := ans + s mod 2 ; s := s div 2) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printQueries(n,a,q,qry): occ=dict() suffixCount=[0 for i in range(n+1)] for i in range(n-1,-1,-1): occ[a[i]]=1 suffixCount[i+1]=len(occ) for i in range(q): print(suffixCount[qry[i]]) n=5 q=3 a=[2,4,6,10,2] qry=[1,3,2] printQueries(n,a,q,qry) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; q := 3 ; a := Sequence{2}->union(Sequence{4}->union(Sequence{6}->union(Sequence{10}->union(Sequence{ 2 })))) ; qry := Sequence{1}->union(Sequence{3}->union(Sequence{ 2 })) ; printQueries(n, a, q, qry); operation printQueries(n : OclAny, a : OclAny, q : OclAny, qry : OclAny) pre: true post: true activity: var occ : Map := (arguments ( )) ; var suffixCount : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( occ[a[i+1]+1] := 1 ; suffixCount[i + 1+1] := (occ)->size()) ; for i : Integer.subrange(0, q-1) do ( execute (suffixCount[qry[i+1]+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline N=int(readline()) A=list(map(int,readline().split())) K=100+max(A) L=[0]*K for a in A : L[a]+=1 for i in range(K): if L[i]>1 : L[i+1]+=L[i]//2 L[i]=L[i]% 2 print(sum(L)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var N : int := ("" + ((readline())))->toInteger() ; var A : Sequence := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var K : int := 100 + (A)->max() ; var L : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, K) ; for a : A do ( L[a+1] := L[a+1] + 1) ; for i : Integer.subrange(0, K-1) do ( if L[i+1] > 1 then ( L[i + 1+1] := L[i + 1+1] + L[i+1] div 2 ; L[i+1] := L[i+1] mod 2 ) else skip) ; execute ((L)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import Counter s=sys.stdin.readline().rstrip() def main(): c=Counter(s) res=c.get('+',0)-c.get('-',0) print(res) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var s : OclAny := sys.stdin.readLine().rstrip() ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var c : OclAny := Counter(s) ; var res : double := c.get('+', 0) - c.get('-', 0) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(input().count("+")*2-4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (input()->count("+") * 2 - 4)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=input() ans=0 for i in range(len(t)): if t[i]=='+' : ans+=1 elif t[i]=='-' : ans+=-1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; for i : Integer.subrange(0, (t)->size()-1) do ( if t[i+1] = '+' then ( ans := ans + 1 ) else (if t[i+1] = '-' then ( ans := ans + -1 ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lst=list(str(input())) plus=lst.count("+") minus=lst.count("-") print(plus-minus) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lst : Sequence := (("" + (((OclFile["System.in"]).readLine()))))->characters() ; var plus : int := lst->count("+") ; var minus : int := lst->count("-") ; execute (plus - minus)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(str(input())) cnt=0 for i in range(4): if s[i]=='+' : cnt+=1 print(cnt-(4-cnt)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := (("" + (((OclFile["System.in"]).readLine()))))->characters() ; var cnt : int := 0 ; for i : Integer.subrange(0, 4-1) do ( if s[i+1] = '+' then ( cnt := cnt + 1 ) else skip) ; execute (cnt - (4 - cnt))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) y=360 while y!=x : if x>y : x=x-y else : y=y-x print(int(360/x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var y : int := 360 ; while y /= x do ( if (x->compareTo(y)) > 0 then ( x := x - y ) else ( y := y - x )) ; execute (("" + ((360 / x)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(*[i+1 for i,x in enumerate(bin(int(input()))[2 :][: :-1])if x>'0'][: :-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name bin)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))) ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) :)) ])) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ])))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name x)))) > (comparison (expr (atom '0'))))))))) ]) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ]))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- temp=int(input()) q=1 outstr="" if temp>1 : z=temp while z>1 : z=temp//2 y=temp % 2 if y>0 : outstr=str(q)+" "+outstr q+=1 temp=z outstr=str(q)+" "+outstr else : outstr=str(q) print(outstr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var temp : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var q : int := 1 ; var outstr : String := "" ; if temp > 1 then ( var z : int := temp ; while z > 1 do ( z := temp div 2 ; var y : int := temp mod 2 ; if y > 0 then ( outstr := ("" + ((q))) + " " + outstr ) else skip ; q := q + 1 ; temp := z) ; outstr := ("" + ((q))) + " " + outstr ) else ( outstr := ("" + ((q))) ) ; execute (outstr)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- temp=int(input()) q=1 outstr="" if temp>1 : z=temp while z>1 : z=temp//2 y=temp % 2 if y>0 : outstr=str(q)+" "+outstr q+=1 temp=z outstr=str(q)+" "+outstr else : outstr=str(q) print(outstr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var temp : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var q : int := 1 ; var outstr : String := "" ; if temp > 1 then ( var z : int := temp ; while z > 1 do ( z := temp div 2 ; var y : int := temp mod 2 ; if y > 0 then ( outstr := ("" + ((q))) + " " + outstr ) else skip ; q := q + 1 ; temp := z) ; outstr := ("" + ((q))) + " " + outstr ) else ( outstr := ("" + ((q))) ) ; execute (outstr)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(*[i+1 for i,x in enumerate(bin(int(input()))[2 :][: :-1])if x>'0'][: :-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name bin)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))) ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) :)) ])) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ])))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name x)))) > (comparison (expr (atom '0'))))))))) ]) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ]))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CountPS(str,n): dp=[[0 for x in range(n)]for y in range(n)] P=[[False for x in range(n)]for y in range(n)] for i in range(n): P[i][i]=True for i in range(n-1): if(str[i]==str[i+1]): P[i][i+1]=True dp[i][i+1]=1 for gap in range(2,n): for i in range(n-gap): j=gap+i ; if(str[i]==str[j]and P[i+1][j-1]): P[i][j]=True if(P[i][j]==True): dp[i][j]=(dp[i][j-1]+dp[i+1][j]+1-dp[i+1][j-1]) else : dp[i][j]=(dp[i][j-1]+dp[i+1][j]-dp[i+1][j-1]) return dp[0][n-1] if __name__=="__main__" : str="abaab" n=len(str) print(CountPS(str,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( OclType["String"] := "abaab" ; n := (OclType["String"])->size() ; execute (CountPS(OclType["String"], n))->display() ) else skip; operation CountPS(OclType["String"] : OclAny, n : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, n-1)->select(y | true)->collect(y | (Integer.subrange(0, n-1)->select(x | true)->collect(x | (0)))) ; var P : Sequence := Integer.subrange(0, n-1)->select(y | true)->collect(y | (Integer.subrange(0, n-1)->select(x | true)->collect(x | (false)))) ; for i : Integer.subrange(0, n-1) do ( P[i+1][i+1] := true) ; for i : Integer.subrange(0, n - 1-1) do ( if (("" + ([i+1])) = ("" + ([i + 1+1]))) then ( P[i+1][i + 1+1] := true ; dp[i+1][i + 1+1] := 1 ) else skip) ; for gap : Integer.subrange(2, n-1) do ( for i : Integer.subrange(0, n - gap-1) do ( var j : OclAny := gap + i; ; if (("" + ([i+1])) = ("" + ([j+1])) & P[i + 1+1][j - 1+1]) then ( P[i+1][j+1] := true ) else skip ; if (P[i+1][j+1] = true) then ( dp[i+1][j+1] := (dp[i+1][j - 1+1] + dp[i + 1+1][j+1] + 1 - dp[i + 1+1][j - 1+1]) ) else ( dp[i+1][j+1] := (dp[i+1][j - 1+1] + dp[i + 1+1][j+1] - dp[i + 1+1][j - 1+1]) ))) ; return dp->first()[n - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) list1=[1] while n>0 : q=int(math.log(n,2)) print(q+1,end=' ') n-=math.pow(2,q) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var list1 : Sequence := Sequence{ 1 } ; while n > 0 do ( var q : int := ("" + (((n, 2)->log())))->toInteger() ; execute (q + 1)->display() ; n := n - (2)->pow(q)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def nextPowerOfFour(n): x=math.floor((n**(1/2))**(1/2)); if((x**4)==n): return n ; else : x=x+1 ; return(x**4); n=122 ; print(nextPowerOfFour(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 122; ; execute (nextPowerOfFour(n))->display();; operation nextPowerOfFour(n : OclAny) pre: true post: true activity: var x : double := ((((n)->pow((1 / 2))))->pow((1 / 2)))->floor(); ; if (((x)->pow(4)) = n) then ( return n; ) else ( x := x + 1; ; return ((x)->pow(4)); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def division(num1,num2): if(num1==0): return 0 if(num2==0): return INT_MAX negResult=0 if(num1<0): num1=-num1 if(num2<0): num2=-num2 else : negResult=true elif(num2<0): num2=-num2 negResult=true quotient=0 while(num1>=num2): num1=num1-num2 quotient+=1 if(negResult): quotient=-quotient return quotient num1=13 ; num2=2 print(division(num1,num2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; num1 := 13; num2 := 2 ; execute (division(num1, num2))->display(); operation division(num1 : OclAny, num2 : OclAny) : OclAny pre: true post: true activity: if (num1 = 0) then ( return 0 ) else skip ; if (num2 = 0) then ( return INT_MAX ) else skip ; var negResult : int := 0 ; if (num1 < 0) then ( num1 := -num1 ; if (num2 < 0) then ( num2 := -num2 ) else ( negResult := true ) ) else (if (num2 < 0) then ( num2 := -num2 ; negResult := true ) else skip) ; var quotient : int := 0 ; while ((num1->compareTo(num2)) >= 0) do ( num1 := num1 - num2 ; quotient := quotient + 1) ; if (negResult) then ( quotient := -quotient ) else skip ; return quotient; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N=int(input()) A=tuple(map(int,input().split())) n=max(A) mid,r,cur=n/2,-1,float("inf") for i in A : if i!=n : x=abs(mid-i) if xtoInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := (A)->max() ; var mid : OclAny := null; var r : OclAny := null; var cur : OclAny := null; Sequence{mid,r,cur} := Sequence{n / 2,-1,("" + (("inf")))->toReal()} ; for i : A do ( if i /= n then ( var x : double := (mid - i)->abs() ; if (x->compareTo(cur)) < 0 then ( var r : OclAny := null; var cur : OclAny := null; Sequence{r,cur} := Sequence{i,x} ) else skip ) else skip) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np n=int(input()) a=list(map(int,input().split(' '))) a=np.array(a) a=np.sort(a) ai=a[-1] a=a[:-1] aj=a[np.argmin(np.abs(a-ai/2))] print(ai,aj) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; a := (a) ; a := ; var ai : OclAny := a->last() ; a := a->front() ; var aj : OclAny := a[+1] ; execute (ai)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compareStrings(str1,str2): i=0 while istr2[i]: return-1 return str1[i]last : return-1 mid=(last+first)//2 if len(arr[mid])==0 : left,right=mid-1,mid+1 while True : if leftlast : return-1 if right<=last and len(arr[right])!=0 : mid=right break if left>=first and len(arr[left])!=0 : mid=left break right+=1 left-=1 if compareStrings(string,arr[mid])==0 : return mid if compareStrings(string,arr[mid])<0 : return searchStr(arr,string,mid+1,last) return searchStr(arr,string,first,mid-1) if __name__=="__main__" : arr=["for","","","","geeks","ide","","practice","","","quiz","",""] string="quiz" n=len(arr) print(searchStr(arr,string,0,n-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{"for"}->union(Sequence{""}->union(Sequence{""}->union(Sequence{""}->union(Sequence{"geeks"}->union(Sequence{"ide"}->union(Sequence{""}->union(Sequence{"practice"}->union(Sequence{""}->union(Sequence{""}->union(Sequence{"quiz"}->union(Sequence{""}->union(Sequence{ "" })))))))))))) ; string := "quiz" ; var n : int := (arr)->size() ; execute (searchStr(arr, string, 0, n - 1))->display() ) else skip; operation compareStrings(str1 : OclAny, str2 : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; while (i->compareTo((str1)->size() - 1)) < 0 & str1[i+1] = str2[i+1] do ( i := i + 1) ; if (str1[i+1]->compareTo(str2[i+1])) > 0 then ( return -1 ) else skip ; return (str1[i+1]->compareTo(str2[i+1])) < 0; operation searchStr(arr : OclAny, string : OclAny, first : OclAny, last : OclAny) : OclAny pre: true post: true activity: if (first->compareTo(last)) > 0 then ( return -1 ) else skip ; var mid : int := (last + first) div 2 ; if (arr[mid+1])->size() = 0 then ( var left : OclAny := null; var right : OclAny := null; Sequence{left,right} := Sequence{mid - 1,mid + 1} ; while true do ( if (left->compareTo(first)) < 0 & (right->compareTo(last)) > 0 then ( return -1 ) else skip ; if (right->compareTo(last)) <= 0 & (arr[right+1])->size() /= 0 then ( mid := right ; break ) else skip ; if (left->compareTo(first)) >= 0 & (arr[left+1])->size() /= 0 then ( mid := left ; break ) else skip ; right := right + 1 ; left := left - 1) ) else skip ; if compareStrings(string, arr[mid+1]) = 0 then ( return mid ) else skip ; if compareStrings(string, arr[mid+1]) < 0 then ( return searchStr(arr, string, mid + 1, last) ) else skip ; return searchStr(arr, string, first, mid - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a_list=list(map(int,input().split())) a_list_min=sorted(a_list) ai=a_list_min[-1] mid_ai=ai//2 for i in range(n): if a_list_min[i]>=mid_ai : if i==0 : aj=a_list_min[i] elif i==n-1 : aj=a_list_min[i-1] else : if a_list_min[i]-mid_ai>mid_ai-a_list_min[i-1]: aj=a_list_min[i-1] else : aj=a_list_min[i] break print(ai,aj) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a_list_min : Sequence := a_list->sort() ; var ai : OclAny := a_list_min->last() ; var mid_ai : int := ai div 2 ; for i : Integer.subrange(0, n-1) do ( if (a_list_min[i+1]->compareTo(mid_ai)) >= 0 then ( if i = 0 then ( var aj : OclAny := a_list_min[i+1] ) else (if i = n - 1 then ( aj := a_list_min[i - 1+1] ) else ( if (a_list_min[i+1] - mid_ai->compareTo(mid_ai - a_list_min[i - 1+1])) > 0 then ( aj := a_list_min[i - 1+1] ) else ( aj := a_list_min[i+1] ) ) ) ; break ) else skip) ; execute (ai)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect n=int(input()) a=list(map(int,input().split())) a.sort() b=a[-1]/2 i=bisect.bisect(a,b) if a[i]-btoInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var b : double := a->last() / 2 ; var i : OclAny := bisect.bisect(a, b) ; if (a[i+1] - b->compareTo(b - a[i - 1+1])) < 0 then ( execute (a->last())->display() ) else ( execute (a->last())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin sys.setrecursionlimit(10**7) def li(): return map(int,stdin.readline().split()) def li_(): return map(lambda x : int(x)-1,stdin.readline().split()) def lf(): return map(float,stdin.readline().split()) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) n=ni() a=list(li()) maxa=max(a) a.remove(maxa) half=maxa/2 minabs_from_half=10**18 ans=-1 for ai in a : if abs(half-ai)pow(7)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := ni() ; var a : Sequence := (li()) ; var maxa : OclAny := (a)->max() ; execute ((maxa) /: a) ; var half : double := maxa / 2 ; var minabs_from_half : double := (10)->pow(18) ; var ans : int := -1 ; for ai : a do ( if ((half - ai)->abs()->compareTo(minabs_from_half)) < 0 then ( ans := ai ; minabs_from_half := (half - ai)->abs() ) else skip) ; execute (maxa)->display(); operation li() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation li_() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ); operation lf() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ); operation ls() : OclAny pre: true post: true activity: return stdin.readLine().split(); operation ns() : OclAny pre: true post: true activity: return stdin.readLine().rstrip(); operation lc() : OclAny pre: true post: true activity: return (ns()); operation ni() : OclAny pre: true post: true activity: return ("" + ((stdin.readLine())))->toInteger(); operation nf() : OclAny pre: true post: true activity: return ("" + ((stdin.readLine())))->toReal(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def compute(): n=math.factorial(100) ans=sum(int(c)for c in str(n)) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var n : long := MathLib.factorial(100) ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->sum() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math ; import sys ; def NthArmstrong(n): count=0 ; for i in range(1,sys.maxsize): num=i ; rem=0 ; digit=0 ; sum=0 ; num=i ; digit=int(math.log10(num)+1); while(num>0): rem=num % 10 ; sum=sum+pow(rem,digit); num=num//10 ; if(i==sum): count+=1 ; if(count==n): return i ; n=12 ; print(NthArmstrong(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; ; skip; ; skip ; n := 12; ; execute (NthArmstrong(n))->display();; operation NthArmstrong(n : OclAny) pre: true post: true activity: var count : int := 0; ; for i : Integer.subrange(1, (trailer . (name maxsize))-1) do ( var num : OclAny := i; ; var rem : int := 0; ; var digit : int := 0; ; var sum : int := 0; ; num := i; ; digit := ("" + (((num)->log10() + 1)))->toInteger(); ; while (num > 0) do ( rem := num mod 10; ; sum := sum + (rem)->pow(digit); ; num := num div 10;) ; if (i = sum) then ( count := count + 1; ) else skip ; if (count = n) then ( return i; ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def summ(h): return pow(2,h-1) L=3 print(summ(L)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var L : int := 3 ; execute (summ(L))->display(); operation summ(h : OclAny) : OclAny pre: true post: true activity: return (2)->pow(h - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) a=n-3 b=1 c=1 d=1 print(a,b,c,d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : double := n - 3 ; var b : int := 1 ; var c : int := 1 ; var d : int := 1 ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for n in[*open(0)][1 :]: print(int(n)-3,1,1,1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for n : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( execute (("" + ((n)))->toInteger() - 3)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for n in[*open(0)][1 :]: print(int(n)-3,1,1,1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for n : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( execute (("" + ((n)))->toInteger() - 3)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): x=int(input()) print(x-3,1,1,1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (x - 3)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=input().split(); b=int(b[: :-1]); print(int(a)+b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split(); var b : int := ("" + ((b(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))))->toInteger(); execute (("" + ((a)))->toInteger() + b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : n=int(input()) a,b,c,d=1,1,1,1 if n>4 : a+=(n-4) print(a,b,c,d) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := Sequence{1,1,1,1} ; if n > 4 then ( a := a + (n - 4) ) else skip ; execute (a)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) now=2 ; for i in range(1,n+1): res=i*i+i res=res*res res=res-now now=int(math.sqrt(res+now)) res=res//i print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var now : int := 2; ; for i : Integer.subrange(1, n + 1-1) do ( var res : double := i * i + i ; res := res * res ; res := res - now ; now := ("" + (((res + now)->sqrt())))->toInteger() ; res := res div i ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) score=2 ; cur=1 ; for i in range(1,n+1): target=(i*(i+1))**2 diff=target-score print(diff//cur) score=i*(i+1) cur+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var score : int := 2; ; var cur : int := 1; ; for i : Integer.subrange(1, n + 1-1) do ( var target : double := ((i * (i + 1)))->pow(2) ; var diff : double := target - score ; execute (diff div cur)->display() ; score := i * (i + 1) ; cur := cur + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) now,add,prev=2,4,2 for i in range(1,n+1): ans=(now*now-prev)/i print(int(ans)) prev=now now+=add add+=2 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var now : OclAny := null; var add : OclAny := null; var prev : OclAny := null; Sequence{now,add,prev} := Sequence{2,4,2} ; for i : Integer.subrange(1, n + 1-1) do ( var ans : double := (now * now - prev) / i ; execute (("" + ((ans)))->toInteger())->display() ; var prev : OclAny := now ; now := now + add ; add := add + 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()); x=2 k=1 lev=1 while(lev<=n): k=lev lev+=1 print(int((pow(lev*(lev-1),2)-x)/k)) x=lev*(lev-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); ; var x : int := 2 ; var k : int := 1 ; var lev : int := 1 ; while ((lev->compareTo(n)) <= 0) do ( k := lev ; lev := lev + 1 ; execute (("" + ((((lev * (lev - 1))->pow(2) - x) / k)))->toInteger())->display() ; x := lev * (lev - 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) print(2) for i in range(2,a+1): print(i**3+2*i**2+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (2)->display() ; for i : Integer.subrange(2, a + 1-1) do ( execute ((i)->pow(3) + 2 * (i)->pow(2) + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) A=[] for i in range(N): a,b=map(int,input().split()) A.append([a,b]) B=[] for i in range(M): c,d=map(int,input().split()) B.append([c,d]) for i in range(N): saitei=float("inf") ans=0 for j in range(M): if abs(A[i][0]-B[j][0])+abs(A[i][1]-B[j][1])collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a}->union(Sequence{ b })) : A)) ; var B : Sequence := Sequence{} ; for i : Integer.subrange(0, M-1) do ( var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{c}->union(Sequence{ d })) : B)) ; for i : Integer.subrange(0, N-1) do ( var saitei : double := ("" + (("inf")))->toReal() ; var ans : int := 0 ; for j : Integer.subrange(0, M-1) do ( if ((A[i+1]->first() - B[j+1]->first())->abs() + (A[i+1][1+1] - B[j+1][1+1])->abs()->compareTo(saitei)) < 0 then ( saitei := (A[i+1]->first() - B[j+1]->first())->abs() + (A[i+1][1+1] - B[j+1][1+1])->abs() ; ans := j + 1 ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def digitWell(n,m,k): cnt=0 while(n>0): if(n % 10==m): cnt=cnt+1 ; n=(int)(n/10); return cnt==k ; def findInt(n,m,k): i=n+1 ; while(True): if(digitWell(i,m,k)): return i ; i=i+1 ; n=111 ; m=2 ; k=2 ; print(findInt(n,m,k)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 111; m := 2; k := 2; ; execute (findInt(n, m, k))->display();; operation digitWell(n : OclAny, m : OclAny, k : OclAny) pre: true post: true activity: var cnt : int := 0 ; while (n > 0) do ( if (n mod 10 = m) then ( cnt := cnt + 1; ) else skip ; n := (OclType["int"])(n / 10);) ; return cnt = k;; operation findInt(n : OclAny, m : OclAny, k : OclAny) pre: true post: true activity: var i : OclAny := n + 1; ; while (true) do ( if (digitWell(i, m, k)) then ( return i; ) else skip ; i := i + 1;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def findCountUpto(d): GP1_Sum=9*((int)((math.pow(10,d))-1)//9) GP2_Sum=9*((int)((math.pow(9,d))-1)//8) return GP1_Sum-GP2_Sum d=1 print(findCountUpto(d)) d=2 print(findCountUpto(d)) d=4 print(findCountUpto(d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; d := 1 ; execute (findCountUpto(d))->display() ; d := 2 ; execute (findCountUpto(d))->display() ; d := 4 ; execute (findCountUpto(d))->display(); operation findCountUpto(d : OclAny) : OclAny pre: true post: true activity: var GP1_Sum : int := 9 * ((OclType["int"])(((10)->pow(d)) - 1) div 9) ; var GP2_Sum : int := 9 * ((OclType["int"])(((9)->pow(d)) - 1) div 8) ; return GP1_Sum - GP2_Sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,a,b=list(map(int,input().split())) k=n//2 if bk and(a>k): print("-1") else : for i in range(n-b): print(str(i+b+1),end=' ') for i in range(k+b-n): print(str(i+a),end=' ') for i in range(a-1): print(str(i+1),end=' ') for i in range(k+1-a): print(str(b-i),end=' ') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k : int := n div 2 ; if (b->compareTo(k)) < 0 then ( execute ("-1")->display() ) else (if b = k & a /= (k + 1) then ( execute ("-1")->display() ) else (if b = k & a = (k + 1) then ( for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( execute (("" + ((i + 1))))->display()) ; execute (->display() ) else (if (b->compareTo(k)) > 0 & ((a->compareTo(k)) > 0) then ( execute ("-1")->display() ) else ( for i : Integer.subrange(0, n - b-1) do ( execute (("" + ((i + b + 1))))->display()) ; for i : Integer.subrange(0, k + b - n-1) do ( execute (("" + ((i + a))))->display()) ; for i : Integer.subrange(0, a - 1-1) do ( execute (("" + ((i + 1))))->display()) ; for i : Integer.subrange(0, k + 1 - a-1) do ( execute (("" + ((b - i))))->display()) ; execute (->display() ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split(' ')) print(n+int(str(m)[: :-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; execute (n + ("" + ((OclType["String"](m)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,a,b=map(int,input().split()) a_=[a] b_=[b] ka=n//2-1 for i in range(n,a,-1): if i!=b or i>b : a_.append(i) ka-=1 if ka==0 : break kb=n//2-1 for i in range(1,b): if i not in a_ : b_.append(i) kb-=1 if kb==0 : break if len(a_)+len(b_)==n : a_.extend(b_) for i in a_ : print(i,end=" ") print() else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a_ : Sequence := Sequence{ a } ; var b_ : Sequence := Sequence{ b } ; var ka : double := n div 2 - 1 ; for i : Integer.subrange(a + 1, n)->reverse() do ( if i /= b or (i->compareTo(b)) > 0 then ( execute ((i) : a_) ; ka := ka - 1 ) else skip ; if ka = 0 then ( break ) else skip) ; var kb : double := n div 2 - 1 ; for i : Integer.subrange(1, b-1) do ( if (a_)->excludes(i) then ( execute ((i) : b_) ; kb := kb - 1 ) else skip ; if kb = 0 then ( break ) else skip) ; if (a_)->size() + (b_)->size() = n then ( a_ := a_->union(b_) ; for i : a_ do ( execute (i)->display()) ; execute (->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: n,a,b=map(int,s.split()); r=-1, if a<=n//2tail() do ( var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ); var r : OclAny := (testlist_star_expr (test (logical_test (comparison (expr (atom - (number (integer 1))))))) ,) ; if (a->compareTo(n div 2)) <= 0 & (n div 2 < b) or n div 2 = a - 1 & (a - 1 == b) then ( (testlist_star_expr (star_expr * (expr (atom (name r)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name r)))) ,)} := Integer.subrange(0 + 1, n)->reverse(); var r->reverse()->at(-(-b)) : OclAny := null; var r->reverse()->at(-(-a)) : OclAny := null; Sequence{r->reverse()->at(-(-b)),r->reverse()->at(-(-a))} := Sequence{r->reverse()->at(-(-a)), r->reverse()->at(-(-b))}->sort() ) else skip ; execute ((argument * (test (logical_test (comparison (expr (atom (name r))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout T=int(stdin.readline()) for i in range(T): N,A,B=map(int,stdin.readline().strip().split()) LIST=list(range(1,N+1)) INDEX=-1 NEW_LIST=[A] LIST.pop(LIST.index(A)) while(len(NEW_LIST)!=(N//2)): if LIST[INDEX]!=B : X=LIST.pop(INDEX) NEW_LIST.append(X) else : INDEX-=1 if min(NEW_LIST)==A : NEW_LIST+=LIST if max(NEW_LIST[N//2 :])==B : print(*NEW_LIST) else : stdout.write("-1\n") else : stdout.write("-1\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var T : int := ("" + ((stdin.readLine())))->toInteger() ; for i : Integer.subrange(0, T-1) do ( var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{N,A,B} := (stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var LIST : Sequence := (Integer.subrange(1, N + 1-1)) ; var INDEX : int := -1 ; var NEW_LIST : Sequence := Sequence{ A } ; LIST := LIST->excludingAt(LIST->indexOf(A) - 1+1) ; while ((NEW_LIST)->size() /= (N div 2)) do ( if LIST[INDEX+1] /= B then ( var X : OclAny := LIST->at(INDEX`firstArg+1) ; LIST := LIST->excludingAt(INDEX+1) ; execute ((X) : NEW_LIST) ) else ( INDEX := INDEX - 1 )) ; if (NEW_LIST)->min() = A then ( NEW_LIST := NEW_LIST + LIST ; if (NEW_LIST.subrange(N div 2+1))->max() = B then ( execute ((argument * (test (logical_test (comparison (expr (atom (name NEW_LIST))))))))->display() ) else ( stdout.write("-1\n") ) ) else ( stdout.write("-1\n") )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys t=int(input()) for i in range(t): n,a,b=input().split() n,a,b=int(n),int(a),int(b) sz=int(n/2) szz=sz lis1=[] lis2=[] lis1.append(a) i=0 while(i<(szz-1)): if((n-i)!=a and(n-i)!=b): lis1.append((n-i)) else : szz+=1 i+=1 szz=sz i=1 while(itoInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := input().split() ; var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := Sequence{("" + ((n)))->toInteger(),("" + ((a)))->toInteger(),("" + ((b)))->toInteger()} ; var sz : int := ("" + ((n / 2)))->toInteger() ; var szz : int := sz ; var lis1 : Sequence := Sequence{} ; var lis2 : Sequence := Sequence{} ; execute ((a) : lis1) ; var i : int := 0 ; while ((i->compareTo((szz - 1))) < 0) do ( if ((n - i) /= a & (n - i) /= b) then ( execute (((n - i)) : lis1) ) else ( szz := szz + 1 ) ; i := i + 1) ; szz := sz ; i := 1 ; while ((i->compareTo(szz)) < 0) do ( if (i /= a & i /= b) then ( execute ((i) : lis2) ) else ( szz := szz + 1 ) ; i := i + 1) ; execute ((b) : lis2) ; if ((lis1)->min() = a & (lis2)->max() = b) then ( var lis : Sequence := lis1->union(lis2) ; for i : lis do ( execute (i)->display()) ) else ( execute (-1)->display() ) ; execute ("\n")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getMissingNo(A): n=len(A) total=(n+1)*(n+2)/2 sum_of_A=sum(A) return total-sum_of_A A=[1,2,4,5,6] miss=getMissingNo(A) print(miss) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; A := Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 })))) ; var miss : OclAny := getMissingNo(A) ; execute (miss)->display(); operation getMissingNo(A : OclAny) : OclAny pre: true post: true activity: var n : int := (A)->size() ; var total : double := (n + 1) * (n + 2) / 2 ; var sum_of_A : OclAny := (A)->sum() ; return total - sum_of_A; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10000000) dxdy=((1,0),(0,1)) def pin(type=int): return map(type,input().rstrip().split()) def resolve(): N,M=pin() A=sorted(list(pin())) A.reverse() p=(sum(A))/(4*M) print(["No","Yes"][A[M-1]>=p]) import sys from io import StringIO import unittest class TestClass(unittest.TestCase): def assertIO(self,input,output): stdout,stdin=sys.stdout,sys.stdin sys.stdout,sys.stdin=StringIO(),StringIO(input) resolve() sys.stdout.seek(0) out=sys.stdout.read()[:-1] sys.stdout,sys.stdin=stdout,stdin self.assertEqual(out,output) def test_入力例_1(self): input="""4 1 5 4 2 1""" output="""Yes""" self.assertIO(input,output) def test_入力例_2(self): input="""3 2 380 19 1""" output="""No""" self.assertIO(input,output) def test_入力例_3(self): input="""12 3 4 56 78 901 2 345 67 890 123 45 6 789""" output="""Yes""" self.assertIO(input,output) if __name__=="__main__" : resolve() ------------------------------------------------------------ OCL File: --------- class TestClass extends unittest.TestCase { static operation newTestClass() : TestClass pre: true post: TestClass->exists( _x | result = _x ); operation assertIO(input : OclAny,output : OclAny) pre: true post: true activity: var stdout : OclAny := null; var stdin : OclAny := null; Sequence{stdout,stdin} := Sequence{OclFile["System.out"],OclFile["System.in"]} ; var OclFile["System.out"] : OclAny := null; var OclFile["System.in"] : OclAny := null; Sequence{OclFile["System.out"],OclFile["System.in"]} := Sequence{StringIO(),StringIO(input)} ; resolve() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name seek) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))) ; var out : OclAny := sys.stdout.readAll()->front() ; var OclFile["System.out"] : OclAny := null; var OclFile["System.in"] : OclAny := null; Sequence{OclFile["System.out"],OclFile["System.in"]} := Sequence{stdout,stdin} ; self.assertEqual(out, output); operation test_??? operation test_??? skip(self : OclAny) pre: true post: true activity: input := (atom "" "4 1\r\n5 4 2 1" "") ; output := (atom "" "Yes" "") ; self.assertIO(input, output); () pre: true post: true activity: input := (atom "" "4 1\r\n5 4 2 1" "") ; output := (atom "" "Yes" "") ; self.assertIO(input, output); operation test_???self : OclAny() pre: true post: true activity: input := (atom "" "3 2\r\n380 19 1" "") ; output := (atom "" "No" "") ; self.assertIO(input, output); operation test_??? input := (atom "" "12 3\r\n4 56 78 901 2 345 67 890 123 45 6 789" "") ; output := (atom "" "Yes" "") ; self.assertIO(input, output)() pre: true post: true activity: input := (atom "" "12 3\r\n4 56 78 901 2 345 67 890 123 45 6 789" "") ; output := (atom "" "Yes" "") ; self.assertIO(input, output); } class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(10000000) ; var dxdy : OclAny := Sequence{Sequence{1, 0}, Sequence{0, 1}} ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( resolve() ) else skip; operation pin(type : OclAny) : OclAny pre: true post: true activity: if type->oclIsUndefined() then type := OclType["int"] else skip; return (input().rstrip().split())->collect( _x | (type)->apply(_x) ); operation resolve() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := pin() ; var A : Sequence := (pin())->sort() ; A := A->reverse() ; var p : double := ((A)->sum()) / (4 * M) ; execute (Sequence{"No"}->union(Sequence{ "Yes" })->select((A[M - 1+1]->compareTo(p)) >= 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil n,m=map(int,input().split()) a=list(map(int,input().split())) a.sort(reverse=True) if a[m-1]>=ceil(sum(a)/(4*m)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; if (a[m - 1+1]->compareTo(ceil((a)->sum() / (4 * m)))) >= 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Point : def __init__(self,x,y): self.x=x self.y=y def getDistance(self,to): return abs(self.x-to.x)+abs(self.y-to.y) def __repr__(self): return "({0},{1})".format(self.x,self.y) N,M=[int(x)for x in input().split(" ")] a=[] c=[] for _ in range(N): x,y=[int(p)for p in input().split(" ")] a.append(Point(x,y)) for _ in range(M): x,y=[int(p)for p in input().split(" ")] c.append(Point(x,y)) for a_i in a : min_d=250000000 min_i=0 for i in range(len(c)): d=a_i.getDistance(c[i]) if dexists( _x | result = _x ); attribute x : OclAny := x; attribute y : OclAny := y; operation initialise(x : OclAny,y : OclAny) : Point pre: true post: true activity: self.x := x ; self.y := y; return self; operation getDistance(to : OclAny) : OclAny pre: true post: true activity: return (self.x - to.x)->abs() + (self.y - to.y)->abs(); operation __repr__() : OclAny pre: true post: true activity: return StringLib.interpolateStrings("({0},{1})", Sequence{self.x, self.y}); } class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a : Sequence := Sequence{} ; var c : Sequence := Sequence{} ; for _anon : Integer.subrange(0, N-1) do ( Sequence{x,y} := input().split(" ")->select(p | true)->collect(p | (("" + ((p)))->toInteger())) ; execute (((Point.newPoint()).initialise(x, y)) : a)) ; for _anon : Integer.subrange(0, M-1) do ( Sequence{x,y} := input().split(" ")->select(p | true)->collect(p | (("" + ((p)))->toInteger())) ; execute (((Point.newPoint()).initialise(x, y)) : c)) ; for a_i : a do ( var min_d : int := 250000000 ; var min_i : int := 0 ; for i : Integer.subrange(0, (c)->size()-1) do ( var d : OclAny := a_i.getDistance(c[i+1]) ; if (d->compareTo(min_d)) < 0 then ( min_d := d ; min_i := i ) else skip) ; execute (min_i + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,m=map(int,input().split()) a=[int(x)for x in input().split()] threshold=sum(a)/(4*m) if sum(1 for i in a if i>=threshold)>=m : print("Yes") else : print("No") if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var threshold : double := (a)->sum() / (4 * m) ; if (((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name a))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name i)))) >= (comparison (expr (atom (name threshold)))))))))))->sum()->compareTo(m)) >= 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import math def main(): n,m=map(int,input().split()) a_list=list(map(int,input().split())) total_check=math.ceil(sum(a_list)/(4*m)) a_list.sort(reverse=True) flag=True for i in range(m): if a_list[i]collect( _x | (OclType["int"])->apply(_x) ) ; var a_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var total_check : double := ((a_list)->sum() / (4 * m))->ceil() ; a_list := a_list->sort() ; var flag : boolean := true ; for i : Integer.subrange(0, m-1) do ( if (a_list[i+1]->compareTo(total_check)) < 0 then ( flag := false ) else skip) ; if flag then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline a,b=input()[:-1].split() x=max(len(a),len(b)) a=a.rjust(x,'0') b=b.ljust(x,'0') s='' c=0 for i in range(x): d=int(b[i])+int(a[x-i-1])+c if d>9 : s+=str(d)[1] c=1 else : s+=str(d) c=0 if c==1 : s+='1' print(int(s[: :-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input()->front().split() ; var x : OclAny := Set{(a)->size(), (b)->size()}->max() ; var a : String := StringLib.padLeftWithInto(a, '0', x) ; var b : String := StringLib.padRightWithInto(b, '0', x) ; var s : String := '' ; var c : int := 0 ; for i : Integer.subrange(0, x-1) do ( var d : int := ("" + ((b[i+1])))->toInteger() + ("" + ((a[x - i - 1+1])))->toInteger() + c ; if d > 9 then ( s := s + OclType["String"](d)[1+1] ; c := 1 ) else ( s := s + ("" + ((d))) ; c := 0 )) ; if c = 1 then ( s := s + '1' ) else skip ; execute (("" + ((s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=[input()for i in range(2)] n=int(s[0].split()[0]) m=int(s[0].split()[1]) a=list(map(int,s[1].split())) sumVote=sum(a) border=1/(4*m)*sumVote select=0 for item in a : if border<=item : select+=1 if select==m : print("Yes") exit() print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := Integer.subrange(0, 2-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var n : int := ("" + ((s->first().split()->first())))->toInteger() ; var m : int := ("" + ((s->first().split()[1+1])))->toInteger() ; var a : Sequence := ((s[1+1].split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sumVote : OclAny := (a)->sum() ; var border : double := 1 / (4 * m) * sumVote ; var select : int := 0 ; for item : a do ( if (border->compareTo(item)) <= 0 then ( select := select + 1 ) else skip ; if select = m then ( execute ("Yes")->display() ; exit() ) else skip) ; execute ("No")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- fact=[0]*14 size=1 def preCompute(N): global size fact[0]=1 i=1 while fact[i-1]<=N : fact[i]=fact[i-1]*i size+=1 i+=1 def findMin(N): preCompute(N) originalN=N ans=[] for i in range(size-1,-1,-1): while(N>=fact[i]): N-=fact[i] ans.append(fact[i]) print(len(ans)) for i in ans : print(i,end=" ") n=27 findMin(n) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute size : OclAny; operation initialise() pre: true post: true activity: var fact : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 14) ; var size : int := 1 ; skip ; skip ; var n : int := 27 ; findMin(n); operation preCompute(N : OclAny) pre: true post: true activity: skip ; fact->first() := 1 ; var i : int := 1 ; while (fact[i - 1+1]->compareTo(N)) <= 0 do ( fact[i+1] := fact[i - 1+1] * i ; size := size + 1 ; i := i + 1); operation findMin(N : OclAny) pre: true post: true activity: preCompute(N) ; var originalN : OclAny := N ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(-1 + 1, size - 1)->reverse() do ( while ((N->compareTo(fact[i+1])) >= 0) do ( N := N - fact[i+1] ; execute ((fact[i+1]) : ans))) ; execute ((ans)->size())->display() ; for i : ans do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math class Node : def __init__(self,data): self.data=data self.next=None def getNode(data): new_node=Node(data) new_node.data=data new_node.next=None new_node.prev=None return new_node def push(head_ref,new_node): new_node.prev=None new_node.next=head_ref if(head_ref!=None): head_ref.prev=new_node head_ref=new_node return head_ref def reverseList(head_ref): if(head_ref==None or(head_ref).next==None): return None new_head=None curr=head_ref while(curr!=None): next=curr.next new_head=push(new_head,curr) curr=next head_ref=new_head return head_ref def prList(head): while(head!=None): print(head.data,end="") head=head.next if __name__=='__main__' : head=None head=push(head,getNode(2)); head=push(head,getNode(4)); head=push(head,getNode(8)); head=push(head,getNode(10)); print("Original list: ",end="") prList(head) head=reverseList(head) print("\nReversed list: ",end="") prList(head) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.next := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( head := null ; head := push(head, getNode(2)); ; head := push(head, getNode(4)); ; head := push(head, getNode(8)); ; head := push(head, getNode(10)); ; execute ("Original list: ")->display() ; prList(head) ; head := reverseList(head) ; execute ("\nReversed list: ")->display() ; prList(head) ) else skip; operation getNode(data : OclAny) : OclAny pre: true post: true activity: var new_node : Node := (Node.newNode()).initialise(data) ; new_node.data := data ; new_node.next := null ; new_node.prev := null ; return new_node; operation push(head_ref : OclAny, new_node : OclAny) : OclAny pre: true post: true activity: new_node.prev := null ; new_node.next := head_ref ; if (head_ref /= null) then ( head_ref.prev := new_node ) else skip ; head_ref := new_node ; return head_ref; operation reverseList(head_ref : OclAny) : OclAny pre: true post: true activity: if (head_ref = null or (head_ref).next = null) then ( return null ) else skip ; var new_head : OclAny := null ; var curr : OclAny := head_ref ; while (curr /= null) do ( var next : OclAny := curr.next ; new_head := push(new_head, curr) ; curr := next) ; head_ref := new_head ; return head_ref; operation prList(head : OclAny) pre: true post: true activity: while (head /= null) do ( execute (head.data)->display() ; head := head.next); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def oddSum(n): sum=0 curr=1 i=0 while idisplay(); operation oddSum(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; var curr : int := 1 ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( sum := sum + curr ; curr := curr + 2 ; i := i + 1) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkValidPair(num1,num2): s1=str(num1) s2=str(num2) for i in range(len(s1)): for j in range(len(s2)): if(s1[i]==s2[j]): return True ; return False ; def countPairs(arr,n): numberOfPairs=0 for i in range(n): for j in range(i+1,n): if(checkValidPair(arr[i],arr[j])): numberOfPairs+=1 return numberOfPairs if __name__=="__main__" : arr=[10,12,24] n=len(arr) print(countPairs(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{10}->union(Sequence{12}->union(Sequence{ 24 })) ; n := (arr)->size() ; execute (countPairs(arr, n))->display() ) else skip; operation checkValidPair(num1 : OclAny, num2 : OclAny) pre: true post: true activity: var s1 : String := ("" + ((num1))) ; var s2 : String := ("" + ((num2))) ; for i : Integer.subrange(0, (s1)->size()-1) do ( for j : Integer.subrange(0, (s2)->size()-1) do ( if (s1[i+1] = s2[j+1]) then ( return true; ) else skip)) ; return false;; operation countPairs(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var numberOfPairs : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if (checkValidPair(arr[i+1], arr[j+1])) then ( numberOfPairs := numberOfPairs + 1 ) else skip)) ; return numberOfPairs; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def values_of_r_and_a(m,n,mth,nth): a,r=0.0,0.0 if(mdisplay(); operation values_of_r_and_a(m : OclAny, n : OclAny, mth : OclAny, nth : OclAny) : OclAny pre: true post: true activity: var a : OclAny := null; var r : OclAny := null; Sequence{a,r} := Sequence{0.0,0.0} ; if ((m->compareTo(n)) < 0) then ( Sequence{m,n} := Sequence{n,m} ; Sequence{mth,nth} := Sequence{mth,nth} ) else skip ; var r : double := (mth div nth)->pow(1.0 / (m - n)) ; var a : int := mth div (r)->pow((m - 1)) ; return a, r; operation FindSum(m : OclAny, n : OclAny, mth : OclAny, nth : OclAny, p : OclAny) : OclAny pre: true post: true activity: Sequence{a,r} := values_of_r_and_a(m, n, mth, nth) ; var pth : double := a * (r)->pow((p - 1.0)) ; return pth; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count(S,m,n): table=[[0 for x in range(m)]for x in range(n+1)] for i in range(m): table[0][i]=1 for i in range(1,n+1): for j in range(m): x=table[i-S[j]][j]if i-S[j]>=0 else 0 y=table[i][j-1]if j>=1 else 0 table[i][j]=x+y return table[n][m-1] arr=[1,2,3] m=len(arr) n=4 print(count(arr,m,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var arr : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; m := (arr)->size() ; n := 4 ; execute (count(arr, m, n))->display(); operation count(S : OclAny, m : OclAny, n : OclAny) : OclAny pre: true post: true activity: var table : Sequence := Integer.subrange(0, n + 1-1)->select(x | true)->collect(x | (Integer.subrange(0, m-1)->select(x | true)->collect(x | (0)))) ; for i : Integer.subrange(0, m-1) do ( table->first()[i+1] := 1) ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(0, m-1) do ( var x : OclAny := if i - S[j+1] >= 0 then table[i - S[j+1]+1][j+1] else 0 endif ; var y : OclAny := if j >= 1 then table[i+1][j - 1+1] else 0 endif ; table[i+1][j+1] := x + y)) ; return table[n+1][m - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count(S,m,n): table=[[0 for x in range(m)]for x in range(n+1)] for i in range(m): table[0][i]=1 for i in range(1,n+1): for j in range(m): x=table[i-S[j]][j]if i-S[j]>=0 else 0 y=table[i][j-1]if j>=1 else 0 table[i][j]=x+y return table[n][m-1] arr=[1,2,3] m=len(arr) n=4 print(count(arr,m,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var arr : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; m := (arr)->size() ; n := 4 ; execute (count(arr, m, n))->display(); operation count(S : OclAny, m : OclAny, n : OclAny) : OclAny pre: true post: true activity: var table : Sequence := Integer.subrange(0, n + 1-1)->select(x | true)->collect(x | (Integer.subrange(0, m-1)->select(x | true)->collect(x | (0)))) ; for i : Integer.subrange(0, m-1) do ( table->first()[i+1] := 1) ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(0, m-1) do ( var x : OclAny := if i - S[j+1] >= 0 then table[i - S[j+1]+1][j+1] else 0 endif ; var y : OclAny := if j >= 1 then table[i+1][j - 1+1] else 0 endif ; table[i+1][j+1] := x + y)) ; return table[n+1][m - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n_cubes=int(input()) i=2 counter=0 while n_cubes>=sum(range(i)): n_cubes-=sum(range(i)) counter+=1 i+=1 print(counter) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n_cubes : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 2 ; var counter : int := 0 ; while (n_cubes->compareTo((Integer.subrange(0, i-1))->sum())) >= 0 do ( n_cubes := n_cubes - (Integer.subrange(0, i-1))->sum() ; counter := counter + 1 ; i := i + 1) ; execute (counter)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np,sys def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) N,M=LI() ab=np.array([LI()for _ in range(N)]) cd=np.array([LI()for _ in range(M)]) for x in ab : print(np.argmin(np.sum(np.abs(cd-x),axis=1))+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := LI() ; var ab : Sequence := (Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (LI()))) ; var cd : Sequence := (Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (LI()))) ; for x : ab do ( execute ( + 1)->display()); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input().split() a=int(s[0]) b=int(s[1][: :-1]) print(a+b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := input().split() ; var a : int := ("" + ((s->first())))->toInteger() ; var b : int := ("" + ((s[1+1](subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))))->toInteger() ; execute (a + b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def incrementVector(a): n=len(a) a[n-1]+=1 carry=a[n-1]/10 a[n-1]=a[n-1]% 10 for i in range(n-2,-1,-1): if(carry==1): a[i]+=1 carry=a[i]/10 a[i]=a[i]% 10 if(carry==1): a.insert(0,1) vect=[1,7,8,9] incrementVector(vect) for i in range(0,len(vect)): print(vect[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var vect : Sequence := Sequence{1}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 9 }))) ; incrementVector(vect) ; for i : Integer.subrange(0, (vect)->size()-1) do ( execute (vect[i+1])->display()); operation incrementVector(a : OclAny) pre: true post: true activity: var n : int := (a)->size() ; a[n - 1+1] := a[n - 1+1] + 1 ; var carry : double := a[n - 1+1] / 10 ; a[n - 1+1] := a[n - 1+1] mod 10 ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( if (carry = 1) then ( a[i+1] := a[i+1] + 1 ; carry := a[i+1] / 10 ; a[i+1] := a[i+1] mod 10 ) else skip) ; if (carry = 1) then ( a := a.insertAt(0+1, 1) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def pronic_check(n): x=(int)(math.sqrt(n)) if(x*(x+1)==n): return True else : return False n=56 if(pronic_check(n)==True): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 56 ; if (pronic_check(n) = true) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); operation pronic_check(n : OclAny) : OclAny pre: true post: true activity: var x : OclAny := (OclType["int"])((n)->sqrt()) ; if (x * (x + 1) = n) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T,D=list(map(int,input().split())) ta,tb=list(map(int,input().split())) da,db=list(map(int,input().split())) ans=10000000007 for i in range(D//da+1): for j in range(D//db+1): if(i*da+j*db<=D)and(i*da+j*db>=1): tmp=(ta*i*da+tb*j*db)/(i*da+j*db) ans=min(abs(ans),abs(T-tmp)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : OclAny := null; var D : OclAny := null; Sequence{T,D} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ta : OclAny := null; var tb : OclAny := null; Sequence{ta,tb} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var da : OclAny := null; var db : OclAny := null; Sequence{da,db} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 10000000007 ; for i : Integer.subrange(0, D div da + 1-1) do ( for j : Integer.subrange(0, D div db + 1-1) do ( if ((i * da + j * db->compareTo(D)) <= 0) & (i * da + j * db >= 1) then ( var tmp : double := (ta * i * da + tb * j * db) / (i * da + j * db) ; ans := Set{(ans)->abs(), (T - tmp)->abs()}->min() ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys T,D=[int(x)for x in sys.stdin.readline().split()] t=[int(x)for x in sys.stdin.readline().split()] d=[int(x)for x in sys.stdin.readline().split()] ans=float("inf") for i in range(D+1): va=d[0]*i if va>D : continue for j in range(D+1): vb=d[1]*j k=va+vb if k>D or k<1 : continue T_=va*t[0]+vb*t[1] T_/=k if abs(T-T_)select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var t : Sequence := sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var d : Sequence := sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : double := ("" + (("inf")))->toReal() ; for i : Integer.subrange(0, D + 1-1) do ( var va : double := d->first() * i ; if (va->compareTo(D)) > 0 then ( continue ) else skip ; for j : Integer.subrange(0, D + 1-1) do ( var vb : double := d[1+1] * j ; var k : OclAny := va + vb ; if (k->compareTo(D)) > 0 or k < 1 then ( continue ) else skip ; var T_ : double := va * t->first() + vb * t[1+1] ; T_ := T_ / k ; if ((T - T_)->abs()->compareTo(ans)) < 0 then ( ans := (T - T_)->abs() ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t,d=map(int,input().split()) ta,tb=map(int,input().split()) da,db=map(int,input().split()) min_score=min([abs(t-(ta*va+tb*vb)/(va+vb))for va in range(0,d+1,da)for vb in range(0,d+1,db)if 1<=va+vb<=d]) print(min_score) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := null; var d : OclAny := null; Sequence{t,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ta : OclAny := null; var tb : OclAny := null; Sequence{ta,tb} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var da : OclAny := null; var db : OclAny := null; Sequence{da,db} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var min_score : OclAny := (Integer.subrange(0, d + 1-1)->select( $x | ($x - 0) mod da = 0 )->select(va; vb : Integer.subrange(0, d + 1-1)->select( $x | ($x - 0) mod db = 0 ) | true)->collect(va; vb : Integer.subrange(0, d + 1-1)->select( $x | ($x - 0) mod db = 0 ) | ((t - (ta * va + tb * vb) / (va + vb))->abs())))->min() ; execute (min_score)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def CheckIfstartsWithOne(n,b): m=(int)(math.log2(n)); for i in range(1,m+1): x=(int)(math.pow(b,i)); if n>=x and n<=2*x-1 : return 1 ; return 0 ; def printYesORno(n,b): if CheckIfstartsWithOne(n,b)==1 : print("Yes"); if CheckIfstartsWithOne(n,b)==0 : print("No"); printYesORno(6,4); printYesORno(24,2); printYesORno(24,7); printYesORno(24,15); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; printYesORno(6, 4); ; printYesORno(24, 2); ; printYesORno(24, 7); ; printYesORno(24, 15);; operation CheckIfstartsWithOne(n : OclAny, b : OclAny) pre: true post: true activity: var m : OclAny := (OclType["int"])(); ; for i : Integer.subrange(1, m + 1-1) do ( var x : OclAny := (OclType["int"])((b)->pow(i)); ; if (n->compareTo(x)) >= 0 & (n->compareTo(2 * x - 1)) <= 0 then ( return 1; ) else skip) ; return 0;; operation printYesORno(n : OclAny, b : OclAny) pre: true post: true activity: if CheckIfstartsWithOne(n, b) = 1 then ( execute ("Yes")->display(); ) else skip ; if CheckIfstartsWithOne(n, b) = 0 then ( execute ("No")->display(); ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd a,b=map(int,input().split()) g=gcd(a,b) if g==1 : print("NO") quit() pair=[] for i in range(1,g): for j in range(i,g): d2=i*i+j*j if d2==g*g : pair.append(i) pair.append(j) break if d2>g*g : break if pair!=[]: break if pair : print("YES") pa=[a//g*pair[1],-a//g*pair[0]] pb=[-b//g*pair[0],-b//g*pair[1]] if(pa[0]==pb[0])or(pa[1]==pb[1]): pa=[-pa[1],pa[0]] pb=[pb[1],-pb[0]] print(0,0) print(*pa) print(*pb) else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var g : OclAny := gcd(a, b) ; if g = 1 then ( execute ("NO")->display() ; quit() ) else skip ; var pair : Sequence := Sequence{} ; for i : Integer.subrange(1, g-1) do ( for j : Integer.subrange(i, g-1) do ( var d2 : double := i * i + j * j ; if d2 = g * g then ( execute ((i) : pair) ; execute ((j) : pair) ; break ) else skip ; if (d2->compareTo(g * g)) > 0 then ( break ) else skip) ; if pair /= Sequence{} then ( break ) else skip) ; if pair then ( execute ("YES")->display() ; var pa : Sequence := Sequence{a div g * pair[1+1]}->union(Sequence{ -a div g * pair->first() }) ; var pb : Sequence := Sequence{-b div g * pair->first()}->union(Sequence{ -b div g * pair[1+1] }) ; if (pa->first() = pb->first()) or (pa[1+1] = pb[1+1]) then ( pa := Sequence{-pa[1+1]}->union(Sequence{ pa->first() }) ; pb := Sequence{pb[1+1]}->union(Sequence{ -pb->first() }) ) else skip ; execute (0)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name pa))))))))->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name pb))))))))->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) r=set() w=set() x,y=a*a,b*b for i in range(1-a,a): for j in range(1-a,a): if i**2+j**2==x : r.add((i,j)) for i in range(1-b,b): for j in range(1-b,b): if i**2+j**2==y : w.add((i,j)) t=0 for i in r : for j in w : if(i[0]-j[0])**2+(i[1]-j[1])**2==x+y and i[0]!=j[0]and i[1]!=j[1]: print("YES") print(0,0) print(i[0],i[1]) print(j[0],j[1]) t=1 break if t : break if not t : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var r : Set := Set{}->union(()) ; var w : Set := Set{}->union(()) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{a * a,b * b} ; for i : Integer.subrange(1 - a, a-1) do ( for j : Integer.subrange(1 - a, a-1) do ( if (i)->pow(2) + (j)->pow(2) = x then ( execute ((Sequence{i, j}) : r) ) else skip)) ; for i : Integer.subrange(1 - b, b-1) do ( for j : Integer.subrange(1 - b, b-1) do ( if (i)->pow(2) + (j)->pow(2) = y then ( execute ((Sequence{i, j}) : w) ) else skip)) ; var t : int := 0 ; for i : r do ( for j : w do ( if ((i->first() - j->first()))->pow(2) + ((i[1+1] - j[1+1]))->pow(2) = x + y & i->first() /= j->first() & i[1+1] /= j[1+1] then ( execute ("YES")->display() ; execute (0)->display() ; execute (i->first())->display() ; execute (j->first())->display() ; t := 1 ; break ) else skip) ; if t then ( break ) else skip) ; if not(t) then ( execute ("NO")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math eps=(10**(-7)) a,b=map(int,input().split()) for x in range(1,a): y=math.sqrt(a*a-x*x) if(int(y)==y): deg=math.atan2(y,x)+math.pi/2.0 x2=b*math.cos(deg) y2=b*math.sin(deg) if((abs(x2-int(x2+eps))<(eps)or abs(x2-int(x2-eps))<(eps))and(abs(y2-int(y2+eps))<(eps)or abs(y2-int(y2-eps))<(eps))and int(round(y2,4))!=int(round(y,4))): print("YES") print(0,0) print(int(x),int(round(y,4))) print(int(round(x2,4)),int(round(y2,4))) exit(0) print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var eps : double := ((10)->pow((-7))) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for x : Integer.subrange(1, a-1) do ( var y : double := (a * a - x * x)->sqrt() ; if (("" + ((y)))->toInteger() = y) then ( var deg : OclAny := + / 2.0 ; var x2 : double := b * ; var y2 : double := b * (deg)->sin() ; if ((((x2 - ("" + ((x2 + eps)))->toInteger())->abs()->compareTo((eps))) < 0 or ((x2 - ("" + ((x2 - eps)))->toInteger())->abs()->compareTo((eps))) < 0) & (((y2 - ("" + ((y2 + eps)))->toInteger())->abs()->compareTo((eps))) < 0 or ((y2 - ("" + ((y2 - eps)))->toInteger())->abs()->compareTo((eps))) < 0) & ("" + ((MathLib.roundN(y2, 4))))->toInteger() /= ("" + ((MathLib.roundN(y, 4))))->toInteger()) then ( execute ("YES")->display() ; execute (0)->display() ; execute (("" + ((x)))->toInteger())->display() ; execute (("" + ((MathLib.roundN(x2, 4))))->toInteger())->display() ; exit(0) ) else skip ) else skip) ; execute ("NO")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a,b=map(int,input().split()) X=[] Y=[] def isPerfectSquare(x): if(x>=0): sr=math.sqrt(x) return int(sr)*int(sr)==x return False for i in range(1,a,1): if isPerfectSquare(a*a-i*i)==True : X.append([i,int(math.sqrt(a*a-i*i))]) for i in range(1,b,1): if isPerfectSquare(b*b-i*i)==True : Y.append([i,int(math.sqrt(b*b-i*i))]) cnt=0 for i in X : for j in Y : if i[0]*j[0]+i[1]*j[1]==0 : print("YES") print(*i) print(*[0,0]) print(*j) quit() cnt+=1 if i[0]*j[0]-i[1]*j[1]==0 : print("YES") print(*i) print(*[0,0]) if i[0]==j[0]: print(*[-j[0],j[1]]) else : print(*[j[0],-j[1]]) quit() cnt+=1 if cnt==0 : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var X : Sequence := Sequence{} ; var Y : Sequence := Sequence{} ; skip ; for i : Integer.subrange(1, a-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if isPerfectSquare(a * a - i * i) = true then ( execute ((Sequence{i}->union(Sequence{ ("" + (((a * a - i * i)->sqrt())))->toInteger() })) : X) ) else skip) ; for i : Integer.subrange(1, b-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if isPerfectSquare(b * b - i * i) = true then ( execute ((Sequence{i}->union(Sequence{ ("" + (((b * b - i * i)->sqrt())))->toInteger() })) : Y) ) else skip) ; var cnt : int := 0 ; for i : X do ( for j : Y do ( if i->first() * j->first() + i[1+1] * j[1+1] = 0 then ( execute ("YES")->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name i))))))))->display() ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) , (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])))))))->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name j))))))))->display() ; quit() ; cnt := cnt + 1 ) else skip ; if i->first() * j->first() - i[1+1] * j[1+1] = 0 then ( execute ("YES")->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name i))))))))->display() ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) , (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])))))))->display() ; if i->first() = j->first() then ( execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr - (expr (atom (name j)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))) , (test (logical_test (comparison (expr (atom (name j)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))) ])))))))->display() ) else ( execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name j)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))) , (test (logical_test (comparison (expr - (expr (atom (name j)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ])))))))->display() ) ; quit() ; cnt := cnt + 1 ) else skip)) ; if cnt = 0 then ( execute ("NO")->display() ) else skip; operation isPerfectSquare(x : OclAny) : OclAny pre: true post: true activity: if (x >= 0) then ( var sr : double := (x)->sqrt() ; return ("" + ((sr)))->toInteger() * ("" + ((sr)))->toInteger() = x ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=input().split(); print(int(a)+int(b[: :-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split(); execute (("" + ((a)))->toInteger() + ("" + ((b(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def distance(p1,p2): return abs(p1[0]-p2[0])+abs(p1[1]-p2[1]) M,N=[int(x)for x in input().split()] student=[] check=[] for i in range(0,M): a,b=[int(x)for x in input().split()] student.append((a,b)) for j in range(0,N): c,d=[int(x)for x in input().split()] check.append((c,d)) for i in range(0,M): dist=distance(student[i],check[N-1]) num=N-1 for j in range(0,N): k=N-j-1 if dist>=distance(student[i],check[k]): dist=distance(student[i],check[k]) num=k print(num+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var M : OclAny := null; var N : OclAny := null; Sequence{M,N} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var student : Sequence := Sequence{} ; var check : Sequence := Sequence{} ; for i : Integer.subrange(0, M-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((Sequence{a, b}) : student)) ; for j : Integer.subrange(0, N-1) do ( var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((Sequence{c, d}) : check)) ; for i : Integer.subrange(0, M-1) do ( var dist : OclAny := distance(student[i+1], check[N - 1+1]) ; var num : double := N - 1 ; for j : Integer.subrange(0, N-1) do ( var k : double := N - j - 1 ; if (dist->compareTo(distance(student[i+1], check[k+1]))) >= 0 then ( dist := distance(student[i+1], check[k+1]) ; num := k ) else skip) ; execute (num + 1)->display()); operation distance(p1 : OclAny, p2 : OclAny) : OclAny pre: true post: true activity: return (p1->first() - p2->first())->abs() + (p1[1+1] - p2[1+1])->abs(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd a,b=map(int,input().split()) g=gcd(a,b) if g==1 : print("NO") quit() pair=[] for i in range(1,g): for j in range(i,g): d2=i*i+j*j if d2==g*g : pair.append(i) pair.append(j) break if d2>g*g : break if pair!=[]: break if pair : print("YES") pa=[a//g*pair[1],-a//g*pair[0]] pb=[-b//g*pair[0],-b//g*pair[1]] if(pa[0]==pb[0])or(pa[1]==pb[1]): pa=[-pa[1],pa[0]] pb=[pb[1],-pb[0]] print(0,0) print(*pa) print(*pb) else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var g : OclAny := gcd(a, b) ; if g = 1 then ( execute ("NO")->display() ; quit() ) else skip ; var pair : Sequence := Sequence{} ; for i : Integer.subrange(1, g-1) do ( for j : Integer.subrange(i, g-1) do ( var d2 : double := i * i + j * j ; if d2 = g * g then ( execute ((i) : pair) ; execute ((j) : pair) ; break ) else skip ; if (d2->compareTo(g * g)) > 0 then ( break ) else skip) ; if pair /= Sequence{} then ( break ) else skip) ; if pair then ( execute ("YES")->display() ; var pa : Sequence := Sequence{a div g * pair[1+1]}->union(Sequence{ -a div g * pair->first() }) ; var pb : Sequence := Sequence{-b div g * pair->first()}->union(Sequence{ -b div g * pair[1+1] }) ; if (pa->first() = pb->first()) or (pa[1+1] = pb[1+1]) then ( pa := Sequence{-pa[1+1]}->union(Sequence{ pa->first() }) ; pb := Sequence{pb[1+1]}->union(Sequence{ -pb->first() }) ) else skip ; execute (0)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name pa))))))))->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name pb))))))))->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,c=map(int,input().split()) x=[0] v=[0] rf=[0]*(n+2) rg=[0]*(n+2) lf=[0]*(n+2) lg=[0]*(n+2) for i in range(0,n): X,V=map(int,input().split()) x.append(X) v.append(V) for i in range(0,n): rf[i+1]=rf[i]+v[i+1] rg[i+1]=max(rg[i],rf[i+1]-x[i+1]) for i in range(n+1,1,-1): lf[i-1]=lf[i]+v[i-1] lg[i-1]=max(lg[i],lf[i-1]-(c-x[i-1])) ans=max(rg[n],lg[1]) for i in range(1,n): ans=max(ans,rg[i]+lg[i+1]-x[i],rg[i]+lg[i+1]-(c-x[i+1])) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := Sequence{ 0 } ; var v : Sequence := Sequence{ 0 } ; var rf : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 2)) ; var rg : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 2)) ; var lf : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 2)) ; var lg : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 2)) ; for i : Integer.subrange(0, n-1) do ( var X : OclAny := null; var V : OclAny := null; Sequence{X,V} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((X) : x) ; execute ((V) : v)) ; for i : Integer.subrange(0, n-1) do ( rf[i + 1+1] := rf[i+1] + v[i + 1+1] ; rg[i + 1+1] := Set{rg[i+1], rf[i + 1+1] - x[i + 1+1]}->max()) ; for i : Integer.subrange(1 + 1, n + 1)->reverse() do ( lf[i - 1+1] := lf[i+1] + v[i - 1+1] ; lg[i - 1+1] := Set{lg[i+1], lf[i - 1+1] - (c - x[i - 1+1])}->max()) ; var ans : OclAny := Set{rg[n+1], lg[1+1]}->max() ; for i : Integer.subrange(1, n-1) do ( ans := Set{ans, rg[i+1] + lg[i + 1+1] - x[i+1], rg[i+1] + lg[i + 1+1] - (c - x[i + 1+1])}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys cin=sys.stdin def line2N(): return map(int,cin.readline().split()) n,c=line2N() x=[0]*n v=[0]*n for i in range(n): x0,v0=line2N() x[i]=x0 v[i]=v0 c1=[0]*n m1=[0]*(n+1) c1[0]=-(x[0]-0)+v[0] m1[0]=max(0,c1[0]) for i in range(1,n): c1[i]=c1[i-1]-(x[i]-x[i-1])+v[i] m1[i]=max(m1[i-1],c1[i]) c2=[0]*n c2[n-1]=-(c-x[n-1])+v[n-1] m2=[0]*(n+1) m2[n-1]=max(0,c2[n-1]) for i in range(n-2,-1,-1): c2[i]=c2[i+1]-(x[i+1]-x[i])+v[i] m2[i]=max(m2[i+1],c2[i]) ans0=0 for i in range(0,n-1): ans0=max(ans0,c1[i]-x[i]+m2[i+1]) for i in range(n-1,0,-1): ans0=max(ans0,c2[i]-(c-x[i])+m1[i-1]) print(max(ans0,m1[n-1],m2[0])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var cin : OclFile := OclFile["System.in"] ; skip ; var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := line2N() ; var x : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var v : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( var x0 : OclAny := null; var v0 : OclAny := null; Sequence{x0,v0} := line2N() ; x[i+1] := x0 ; v[i+1] := v0) ; var c1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var m1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; c1->first() := -(x->first() - 0) + v->first() ; m1->first() := Set{0, c1->first()}->max() ; for i : Integer.subrange(1, n-1) do ( c1[i+1] := c1[i - 1+1] - (x[i+1] - x[i - 1+1]) + v[i+1] ; m1[i+1] := Set{m1[i - 1+1], c1[i+1]}->max()) ; var c2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; c2[n - 1+1] := -(c - x[n - 1+1]) + v[n - 1+1] ; var m2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; m2[n - 1+1] := Set{0, c2[n - 1+1]}->max() ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( c2[i+1] := c2[i + 1+1] - (x[i + 1+1] - x[i+1]) + v[i+1] ; m2[i+1] := Set{m2[i + 1+1], c2[i+1]}->max()) ; var ans0 : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( ans0 := Set{ans0, c1[i+1] - x[i+1] + m2[i + 1+1]}->max()) ; for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( ans0 := Set{ans0, c2[i+1] - (c - x[i+1]) + m1[i - 1+1]}->max()) ; execute (Set{ans0, m1[n - 1+1], m2->first()}->max())->display(); operation line2N() : OclAny pre: true post: true activity: return (cin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections Point=collections.namedtuple('Sushi',['position','value']) def read_ints(): return map(int,input().split()) def reverse_points(points,length): return[Point(length-p.position,p.value)for p in reversed(points)] def solve_unidir(points,length): forward_peaks=[(-1,0)] forward_accumulated_value=0 for i,p in enumerate(points): forward_accumulated_value+=p.value forward_actual_value=forward_accumulated_value-p.position if forward_actual_value>forward_peaks[-1][1]: forward_peaks.append((i,forward_actual_value)) best_value=forward_peaks[-1][1] backward_accumulated_value=0 for i,p in reversed(list(enumerate(points))): while forward_peaks[-1][0]>=i : forward_peaks.pop() backward_accumulated_value+=p.value backward_actual_value=backward_accumulated_value-2*(length-p.position) best_value=max(best_value,backward_actual_value+forward_peaks[-1][1]) return best_value def solve(points,length): return max(solve_unidir(points,length),solve_unidir(reverse_points(points,length),length)) def main(): n,length=read_ints() points=[] for _ in range(n): position,value=read_ints() points.append(Point(position,value)) print(solve(points,length)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var Point : OclAny := .namedtuple('Sushi', Sequence{'position'}->union(Sequence{ 'value' })) ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation read_ints() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation reverse_points(points : OclAny, length : OclAny) : OclAny pre: true post: true activity: return (points)->reverse()->select(p | true)->collect(p | (Point(length - p.position, p.value))); operation solve_unidir(points : OclAny, length : OclAny) : OclAny pre: true post: true activity: var forward_peaks : Sequence := Sequence{ Sequence{-1, 0} } ; var forward_accumulated_value : int := 0 ; for _tuple : Integer.subrange(1, (points)->size())->collect( _indx | Sequence{_indx-1, (points)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p : OclAny := _tuple->at(_indx); forward_accumulated_value := forward_accumulated_value + p.value ; var forward_actual_value : double := forward_accumulated_value - p.position ; if (forward_actual_value->compareTo(forward_peaks->last()[1+1])) > 0 then ( execute ((Sequence{i, forward_actual_value}) : forward_peaks) ) else skip) ; var best_value : OclAny := forward_peaks->last()[1+1] ; var backward_accumulated_value : int := 0 ; for _tuple : ((Integer.subrange(1, (points)->size())->collect( _indx | Sequence{_indx-1, (points)->at(_indx)} )))->reverse() do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p : OclAny := _tuple->at(_indx); while (forward_peaks->last()->first()->compareTo(i)) >= 0 do ( forward_peaks := forward_peaks->front()) ; backward_accumulated_value := backward_accumulated_value + p.value ; var backward_actual_value : double := backward_accumulated_value - 2 * (length - p.position) ; best_value := Set{best_value, backward_actual_value + forward_peaks->last()[1+1]}->max()) ; return best_value; operation solve(points : OclAny, length : OclAny) : OclAny pre: true post: true activity: return Set{solve_unidir(points, length), solve_unidir(reverse_points(points, length), length)}->max(); operation main() pre: true post: true activity: var n : OclAny := null; Sequence{n,length} := read_ints() ; points := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var position : OclAny := null; var value : OclAny := null; Sequence{position,value} := read_ints() ; execute ((Point(position, value)) : points)) ; execute (solve(points, length))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np def get_max(): a=0 def _max(x): nonlocal a a=max(a,x) return a return _max def solve(fwd,bck): dp=[] cur=0 for x,v in fwd : cur-=x cur+=v dp.append(cur) dp=list(map(get_max(),dp)) cur=0 ans=dp[-1] for i,(x,v)in enumerate(bck[:-1]): cur-=2*x cur+=v ans=max(ans,dp[n-i-2]+cur) return ans n,c=map(int,input().split()) sushi=[list(map(int,input().split()))for _ in range(n)] fwd=np.array(sushi).T fwd[0]=np.diff(np.concatenate(([0],fwd[0]))) fwd=fwd.T.tolist() bck=np.array(sushi).T bck[0]=np.diff(np.concatenate(([0],(c-bck[0])[: :-1]))) bck[1]=bck[1][: :-1] bck=bck.T.tolist() print(max(solve(fwd,bck),solve(bck,fwd))) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute a : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sushi : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; fwd := np.array(sushi).T ; fwd->first() := ; fwd := fwd.T.tolist() ; bck := np.array(sushi).T ; bck->first() := ; bck[1+1] := bck[1+1](subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; bck := bck.T.tolist() ; execute (Set{solve(fwd, bck), solve(bck, fwd)}->max())->display(); operation get_max() : OclAny pre: true post: true activity: var a : int := 0 ; skip ; return _max; operation solve(fwd : OclAny, bck : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Sequence{} ; var cur : int := 0 ; for _tuple : fwd do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); cur := cur - x ; cur := cur + v ; execute ((cur) : dp)) ; dp := ((dp)->collect( _x | (get_max())->apply(_x) )) ; cur := 0 ; var ans : OclAny := dp->last() ; for _tuple : Integer.subrange(1, (bck->front())->size())->collect( _indx | Sequence{_indx-1, (bck->front())->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{x, v} : OclAny := _tuple->at(_indx); cur := cur - 2 * x ; cur := cur + v ; ans := Set{ans, dp[n - i - 2+1] + cur}->max()) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,c=[int(i)for i in input().split()] t_tk_r=0 t_md_r=0 g_tk_r=0 g_md_r=0 t_tk_m=0 t_md_m=0 g_tk_m=0 g_md_m=0 t_tk=[] t_md=[] g_tk=[] g_md=[] a=[] d1=0 for i in range(n): a.append([int(i)for i in input().split()]) for d0,v0 in a : t_tk_r+=v0-(d0-d1) t_md_r+=v0-(d0-d1)*2 t_tk_m=max(t_tk_m,t_tk_r) t_md_m=max(t_md_m,t_md_r) t_tk.append(t_tk_m) t_md.append(t_md_m) d1=d0 d1=0 for d0,v0 in a[: :-1]: g_tk_r+=v0-((c-d0)-d1) g_md_r+=v0-((c-d0)-d1)*2 g_tk_m=max(g_tk_m,g_tk_r) g_md_m=max(g_md_m,g_md_r) g_tk.append(g_tk_m) g_md.append(g_md_m) d1=(c-d0) mx=max(max(t_tk),max(g_tk),0) for i in range(n-1): mx=max(mx,t_tk[i]+g_md[n-2-i],t_md[i]+g_tk[n-i-2]) print(mx) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var t_tk_r : int := 0 ; var t_md_r : int := 0 ; var g_tk_r : int := 0 ; var g_md_r : int := 0 ; var t_tk_m : int := 0 ; var t_md_m : int := 0 ; var g_tk_m : int := 0 ; var g_md_m : int := 0 ; var t_tk : Sequence := Sequence{} ; var t_md : Sequence := Sequence{} ; var g_tk : Sequence := Sequence{} ; var g_md : Sequence := Sequence{} ; var a : Sequence := Sequence{} ; var d1 : int := 0 ; for i : Integer.subrange(0, n-1) do ( execute ((input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))) : a)) ; for _tuple : a do (var _indx : int := 1; var d0 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v0 : OclAny := _tuple->at(_indx); t_tk_r := t_tk_r + v0 - (d0 - d1) ; t_md_r := t_md_r + v0 - (d0 - d1) * 2 ; t_tk_m := Set{t_tk_m, t_tk_r}->max() ; t_md_m := Set{t_md_m, t_md_r}->max() ; execute ((t_tk_m) : t_tk) ; execute ((t_md_m) : t_md) ; d1 := d0) ; d1 := 0 ; for _tuple : a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do (var _indx : int := 1; var d0 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v0 : OclAny := _tuple->at(_indx); g_tk_r := g_tk_r + v0 - ((c - d0) - d1) ; g_md_r := g_md_r + v0 - ((c - d0) - d1) * 2 ; g_tk_m := Set{g_tk_m, g_tk_r}->max() ; g_md_m := Set{g_md_m, g_md_r}->max() ; execute ((g_tk_m) : g_tk) ; execute ((g_md_m) : g_md) ; d1 := (c - d0)) ; var mx : OclAny := Set{(t_tk)->max(), (g_tk)->max(), 0}->max() ; for i : Integer.subrange(0, n - 1-1) do ( mx := Set{mx, t_tk[i+1] + g_md[n - 2 - i+1], t_md[i+1] + g_tk[n - i - 2+1]}->max()) ; execute (mx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def IsLarger(X,Y,n): for i in range(n): if(X[i]union(Sequence{3}->union(Sequence{6}->union(Sequence{ 9 }))); ; Y := Sequence{3}->union(Sequence{4}->union(Sequence{8}->union(Sequence{ 1 }))); ; n := (X)->size(); ; execute (solve(X, Y, n))->display(); ) else skip; operation IsLarger(X : OclAny, Y : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if ((X[i+1]->compareTo(Y[i+1])) < 0) then ( return false; ) else skip) ; return true;; operation solve(X : OclAny, Y : OclAny, n : OclAny) pre: true post: true activity: var ans : int := 0; ; if (IsLarger(X, Y, n)) then ( ans := 0; ) else ( var d : double := Y->first() - X->first(); ; for i : Integer.subrange(0, n-1) do ( X[i+1] := X[i+1] + d;) ; if (IsLarger(X, Y, n)) then ( ans := d; ) else ( ans := d + 1; ) ) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def average(arr,n,k): total=0 if(2*k>=n): return 0 arr.sort() start,end=k,n-k-1 for i in range(start,end+1): total+=arr[i] return(total/(n-2*k)) if __name__=="__main__" : arr=[1,2,4,4,5,6] n=len(arr) k=2 print(average(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))))) ; n := (arr)->size() ; k := 2 ; execute (average(arr, n, k))->display() ) else skip; operation average(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var total : int := 0 ; if ((2 * k->compareTo(n)) >= 0) then ( return 0 ) else skip ; arr := arr->sort() ; var start : OclAny := null; var end : OclAny := null; Sequence{start,end} := Sequence{k,n - k - 1} ; for i : Integer.subrange(start, end + 1-1) do ( total := total + arr[i+1]) ; return (total / (n - 2 * k)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(a==0): return b return gcd(b % a,a) def commDiv(a,b): n=gcd(a,b) a=a//n b=b//n print("A=",a,",B=",b) a,b=10,15 commDiv(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{a,b} := Sequence{10,15} ; commDiv(a, b); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0) then ( return b ) else skip ; return gcd(b mod a, a); operation commDiv(a : OclAny, b : OclAny) pre: true post: true activity: var n : OclAny := gcd(a, b) ; a := a div n ; b := b div n ; execute ("A=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ax,ay=map(int,input().split()) bx,by=map(int,input().split()) cx,cy=map(int,input().split()) print(3) print(bx+cx-ax,by+cy-ay) print(cx+ax-bx,cy+ay-by) print(bx+ax-cx,by+ay-cy) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ax : OclAny := null; var ay : OclAny := null; Sequence{ax,ay} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var bx : OclAny := null; var by : OclAny := null; Sequence{bx,by} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cx : OclAny := null; var cy : OclAny := null; Sequence{cx,cy} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (3)->display() ; execute (bx + cx - ax)->display() ; execute (cx + ax - bx)->display() ; execute (bx + ax - cx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import acos def printValueOfPi(N): pi=round(2*acos(0.0),N); print(pi); if __name__=="__main__" : N=4 ; printValueOfPi(N); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( N := 4; ; printValueOfPi(N); ) else skip; operation printValueOfPi(N : OclAny) pre: true post: true activity: var pi : double := MathLib.roundN(2 * acos(0.0), N); ; execute (pi)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def d(a,b): return abs(a[0]-b[0])+abs(a[1]-b[1]) n,m=map(int,input().split()) students={} check={} for i in range(1,n+1): x=list(map(int,input().split())) students[i]=x for i in range(1,m+1): x=list(map(int,input().split())) check[i]=x for i in range(1,n+1): st=students[i] b=10**10 ans=0 for j in range(1,m+1): if b>d(st,check[j]): b=d(st,check[j]) ans=j print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var students : OclAny := Set{} ; var check : OclAny := Set{} ; for i : Integer.subrange(1, n + 1-1) do ( var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; students[i+1] := x) ; for i : Integer.subrange(1, m + 1-1) do ( x := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; check[i+1] := x) ; for i : Integer.subrange(1, n + 1-1) do ( var st : OclAny := students[i+1] ; b := (10)->pow(10) ; var ans : int := 0 ; for j : Integer.subrange(1, m + 1-1) do ( if (b->compareTo(d(st, check[j+1]))) > 0 then ( b := d(st, check[j+1]) ; ans := j ) else skip) ; execute (ans)->display()); operation d(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a->first() - b->first())->abs() + (a[1+1] - b[1+1])->abs(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re for i in range(int(input())): s=input() if re.match(">'(=+)#(=+)~",s): print('A') elif re.match(">\^(Q=)+~~",s): print('B') else : print('NA') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if (s)->firstMatch("^" + ">'(=+)#(=+)~" + ".*") then ( execute ('A')->display() ) else (if (s)->firstMatch("^" + ">\^(Q=)+~~" + ".*") then ( execute ('B')->display() ) else ( execute ('NA')->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import os N=int(input()) def is_A(s): if s[0 : 2]!=">'" : return False if s[-1]!='~' : return False body=s[2 :-1] if len(body)% 2==0 : return False center_index=len(body)//2 if body[center_index]!='#' : return False if body.count('#')!=1 : return False lst=body.split('#') if len(lst)!=2 : return False if len(lst[0])>0 and lst[0]==lst[1]and len(lst[0])==lst[0].count('='): return True else : return False def is_B(s): if s[0 : 2]!=">^" : return False if s[-2 :]!='~~' : return False body=s[2 :-2] if len(body)% 2!=0 : return False elif body.count('Q=')>0 and body.count('Q=')==len(body)//2 : return True else : return False for s in sys.stdin : s=s.strip() if is_A(s): print('A') elif is_B(s): print('B') else : print('NA') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; skip ; for s : OclFile["System.in"] do ( s := s->trim() ; if is_A(s) then ( execute ('A')->display() ) else (if is_B(s) then ( execute ('B')->display() ) else ( execute ('NA')->display() ) ) ); operation is_A(s : OclAny) : OclAny pre: true post: true activity: if s.subrange(0+1, 2) /= ">'" then ( return false ) else skip ; if s->last() /= '~' then ( return false ) else skip ; var body : OclAny := s.subrange(2+1, -1) ; if (body)->size() mod 2 = 0 then ( return false ) else skip ; var center_index : int := (body)->size() div 2 ; if body[center_index+1] /= '#' then ( return false ) else skip ; if body->count('#') /= 1 then ( return false ) else skip ; var lst : OclAny := body.split('#') ; if (lst)->size() /= 2 then ( return false ) else skip ; if (lst->first())->size() > 0 & lst->first() = lst[1+1] & (lst->first())->size() = lst->first()->count('=') then ( return true ) else ( return false ); operation is_B(s : OclAny) : OclAny pre: true post: true activity: if s.subrange(0+1, 2) /= ">^" then ( return false ) else skip ; if s.subrange(-2+1) /= '~~' then ( return false ) else skip ; body := s.subrange(2+1, -2) ; if (body)->size() mod 2 /= 0 then ( return false ) else (if body->count('Q=') > 0 & body->count('Q=') = (body)->size() div 2 then ( return true ) else ( return false ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for times in range(n): s=input() ans="NA" if s[: 2]==">'" and s[-1]=="~" : t=s[2 :-1].split("#") if len(t)==2 and len(t[0])>0 : valid=True for v in t[0]: if v!="=" : valid=False break if valid and t[0]==t[1]: ans="A" elif s[: 2]==">^" and s[-2 :]=="~~" : t=s[2 :-2] if len(t)>0 and len(t)% 2==0 : valid=True for i in range(0,len(t),2): if t[i : i+2]!="Q=" : valid=False break if valid : ans="B" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for times : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var ans : String := "NA" ; if s.subrange(1,2) = ">'" & s->last() = "~" then ( var t : OclAny := s.subrange(2+1, -1).split("#") ; if (t)->size() = 2 & (t->first())->size() > 0 then ( var valid : boolean := true ; for v : t->first() do ( if v /= "=" then ( valid := false ; break ) else skip) ; if valid & t->first() = t[1+1] then ( ans := "A" ) else skip ) else skip ) else (if s.subrange(1,2) = ">^" & s.subrange(-2+1) = "~~" then ( t := s.subrange(2+1, -2) ; if (t)->size() > 0 & (t)->size() mod 2 = 0 then ( valid := true ; for i : Integer.subrange(0, (t)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( if t.subrange(i+1, i + 2) /= "Q=" then ( valid := false ; break ) else skip) ; if valid then ( ans := "B" ) else skip ) else skip ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin import re input=stdin.readline def identify_snake(snake): patternA=re.compile("^>'(=+)#(=+)~") resultA=patternA.search(snake) if resultA : pre,post=resultA.groups() if pre==post : return 'A' patternB=re.compile("^>\^(Q=)+~~") resultB=patternB.search(snake) if resultB : return 'B' return 'NA' def main(args): n=int(input()) for _ in range(n): snake=input() result=identify_snake(snake) print(result) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation identify_snake(snake : OclAny) : OclAny pre: true post: true activity: var patternA : OclRegex := OclRegex.compile("^>'(=+)#(=+)~") ; var resultA : OclAny := patternA.search(snake) ; if resultA then ( var pre : OclAny := null; var post : OclAny := null; Sequence{pre,post} := resultA.groups() ; if pre = post then ( return 'A' ) else skip ) else skip ; var patternB : OclRegex := OclRegex.compile("^>\^(Q=)+~~") ; var resultB : OclAny := patternB.search(snake) ; if resultB then ( return 'B' ) else skip ; return 'NA'; operation main(args : OclAny) pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( snake := (OclFile["System.in"]).readLine() ; var result : OclAny := identify_snake(snake) ; execute (result)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans_list=[] for i in range(n): s=input() if s[0]=="~" and s[-1]==">" : s=s[: :-1] if s[0]==">" and s[1]=="'" and s[-2]=="=" and s[-1]=="~" : check_s=s[2 :-1].split("#") if len(check_s)==2 : front=check_s[0] back=check_s[1] if front==back and set(front)=={"="}: ans="A" else : ans="NA" else : ans="NA" elif s[0]==">" and s[1]=="^" and s[-2]=="~" and s[-1]=="~" : check_s=s[2 :-2] check_list=set(check_s.split("Q=")) if check_list=={""}and "Q=" in check_s : ans="B" else : ans="NA" else : ans="NA" ans_list.append(ans) for a in ans_list : print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans_list : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if s->first() = "~" & s->last() = ">" then ( s := s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ) else skip ; if s->first() = ">" & s[1+1] = "'" & s->front()->last() = "=" & s->last() = "~" then ( var check_s : OclAny := s.subrange(2+1, -1).split("#") ; if (check_s)->size() = 2 then ( var front : OclAny := check_s->first() ; var back : OclAny := check_s[1+1] ; if front = back & Set{}->union((front)) = Set{ "=" } then ( var ans : String := "A" ) else ( ans := "NA" ) ) else ( ans := "NA" ) ) else (if s->first() = ">" & s[1+1] = "^" & s->front()->last() = "~" & s->last() = "~" then ( check_s := s.subrange(2+1, -2) ; var check_list : Set := Set{}->union((check_s.split("Q="))) ; if check_list = Set{ "" } & (check_s)->includes("Q=") then ( ans := "B" ) else ( ans := "NA" ) ) else ( ans := "NA" ) ) ; execute ((ans) : ans_list)) ; for a : ans_list do ( execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def specialNumber(n): if(n<10 or n>99): print("Invalid Input! Number"," should have 2 digits only") else : first=n//10 last=n % 10 sum=first+last pro=first*last if((sum+pro)==n): print(n," is a Special ","Two-Digit Number") else : print(n," is Not a ","Special Two-Digit Number") n=59 specialNumber(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 59 ; specialNumber(n); operation specialNumber(n : OclAny) pre: true post: true activity: if (n < 10 or n > 99) then ( execute ("Invalid Input! Number")->display() ) else ( var first : int := n div 10 ; var last : int := n mod 10 ; var sum : int := first + last ; var pro : int := first * last ; if ((sum + pro) = n) then ( execute (n)->display() ) else ( execute (n)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxProdSum(arr,n): leftArraySum=0 ; maxProduct=0 ; for i in range(n): leftArraySum+=arr[i]; rightArraySum=0 ; for j in range(i+1,n): rightArraySum+=arr[j]; k=leftArraySum*rightArraySum ; if(k>maxProduct): maxProduct=k ; return maxProduct ; if __name__=='__main__' : arr=[4,10,1,7,2,9]; n=len(arr); print(maxProdSum(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{4}->union(Sequence{10}->union(Sequence{1}->union(Sequence{7}->union(Sequence{2}->union(Sequence{ 9 }))))); ; n := (arr)->size(); ; execute (maxProdSum(arr, n))->display(); ) else skip; operation maxProdSum(arr : OclAny, n : OclAny) pre: true post: true activity: var leftArraySum : int := 0; ; var maxProduct : int := 0; ; for i : Integer.subrange(0, n-1) do ( leftArraySum := leftArraySum + arr[i+1]; ; var rightArraySum : int := 0; ; for j : Integer.subrange(i + 1, n-1) do ( rightArraySum := rightArraySum + arr[j+1];) ; var k : int := leftArraySum * rightArraySum; ; if ((k->compareTo(maxProduct)) > 0) then ( maxProduct := k; ) else skip) ; return maxProduct;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def oddNumSum(n): return(n*(2*n+1)*(24*n*n*n-12*n*n-14*n+7))/15 n=4 print(int(oddNumSum(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute (("" + ((oddNumSum(n))))->toInteger())->display(); operation oddNumSum(n : OclAny) : OclAny pre: true post: true activity: return (n * (2 * n + 1) * (24 * n * n * n - 12 * n * n - 14 * n + 7)) / 15; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dot(x,y,xx,yy,xxx,yyy): vx=xx-x vy=yy-y print(xxx+vx,yyy+vy) x1,y1=map(int,input().split()) x2,y2=map(int,input().split()) x3,y3=map(int,input().split()) print(3) dot(x1,y1,x2,y2,x3,y3) dot(x2,y2,x1,y1,x3,y3) dot(x3,y3,x1,y1,x2,y2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x3 : OclAny := null; var y3 : OclAny := null; Sequence{x3,y3} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (3)->display() ; dot(x1, y1, x2, y2, x3, y3) ; dot(x2, y2, x1, y1, x3, y3) ; dot(x3, y3, x1, y1, x2, y2); operation dot(x : OclAny, y : OclAny, xx : OclAny, yy : OclAny, xxx : OclAny, yyy : OclAny) pre: true post: true activity: var vx : double := xx - x ; var vy : double := yy - y ; execute (xxx + vx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def odd_digits(n): if(n<10): return n ; elif(n/10<10): return 9 ; elif(n/100<10): return 9+n-99 ; elif(n/1000<10): return 9+900 ; elif(n/10000<10): return 909+n-9999 ; else : return 90909 ; if __name__=="__main__" : n=893 ; print(odd_digits(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 893; ; execute (odd_digits(n))->display(); ) else skip; operation odd_digits(n : OclAny) pre: true post: true activity: if (n < 10) then ( return n; ) else (if (n / 10 < 10) then ( return 9; ) else (if (n / 100 < 10) then ( return 9 + n - 99; ) else (if (n / 1000 < 10) then ( return 9 + 900; ) else (if (n / 10000 < 10) then ( return 909 + n - 9999; ) else ( return 90909; ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def is_vow(c): return((c=='a')or(c=='e')or(c=='i')or(c=='o')or(c=='u')); def removeVowels(str): print(str[0],end=""); for i in range(1,len(str)): if((is_vow(str[i-1])!=True)or(is_vow(str[i])!=True)): print(str[i],end=""); str=" geeks for geeks" ; removeVowels(str); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; OclType["String"] := " geeks for geeks"; ; removeVowels(OclType["String"]);; operation is_vow(c : OclAny) pre: true post: true activity: return ((c = 'a') or (c = 'e') or (c = 'i') or (c = 'o') or (c = 'u'));; operation removeVowels(OclType["String"] : OclAny) pre: true post: true activity: execute (("" + (->first())))->display(); ; for i : Integer.subrange(1, (OclType["String"])->size()-1) do ( if ((is_vow(("" + ([i - 1+1]))) /= true) or (is_vow(("" + ([i+1]))) /= true)) then ( execute (("" + ([i+1])))->display(); ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve_sum(n): if(n % 2==1): return(n+1)/2 return-n/2 n=8 print(int(solve_sum(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 8 ; execute (("" + ((solve_sum(n))))->toInteger())->display(); operation solve_sum(n : OclAny) : OclAny pre: true post: true activity: if (n mod 2 = 1) then ( return (n + 1) / 2 ) else skip ; return -n / 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def atMostSum(arr,n,k): _sum=0 cnt=0 maxcnt=0 for i in range(n): if((_sum+arr[i])<=k): _sum+=arr[i] cnt+=1 elif(sum!=0): _sum=_sum-arr[i-cnt]+arr[i] maxcnt=max(cnt,maxcnt) return maxcnt arr=[1,2,1,0,1,1,0] n=len(arr) k=4 print(atMostSum(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 0 })))))) ; n := (arr)->size() ; k := 4 ; execute (atMostSum(arr, n, k))->display(); operation atMostSum(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var _sum : int := 0 ; var cnt : int := 0 ; var maxcnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (((_sum + arr[i+1])->compareTo(k)) <= 0) then ( _sum := _sum + arr[i+1] ; cnt := cnt + 1 ) else (if (sum /= 0) then ( _sum := _sum - arr[i - cnt+1] + arr[i+1] ) else skip) ; maxcnt := Set{cnt, maxcnt}->max()) ; return maxcnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def isPower(n): for x in range(2,int(math.sqrt(n))+1): f=math.log(n)/math.log(x); if((f-int(f))==0.0): return True ; return False ; for i in range(2,100): if(isPower(i)): print(i,end=" "); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for i : Integer.subrange(2, 100-1) do ( if (isPower(i)) then ( execute (i)->display(); ) else skip); operation isPower(n : OclAny) pre: true post: true activity: for x : Integer.subrange(2, ("" + (((n)->sqrt())))->toInteger() + 1-1) do ( var f : double := (n)->log() / (x)->log(); ; if ((f - ("" + ((f)))->toInteger()) = 0.0) then ( return true; ) else skip) ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countDistinct(arr,n): s=set() res=0 for i in range(n): if(arr[i]not in s): s.add(arr[i]) res+=1 return res arr=[6,10,5,4,9,120,4,6,10] n=len(arr) print(countDistinct(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{6}->union(Sequence{10}->union(Sequence{5}->union(Sequence{4}->union(Sequence{9}->union(Sequence{120}->union(Sequence{4}->union(Sequence{6}->union(Sequence{ 10 })))))))) ; n := (arr)->size() ; execute (countDistinct(arr, n))->display(); operation countDistinct(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var s : Set := Set{}->union(()) ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ((s)->excludes(arr[i+1])) then ( execute ((arr[i+1]) : s) ; res := res + 1 ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- caseNumber=int(input()) while caseNumber!=0 : arraySize=int(input()) array=input().split(" ") positionCount=0 middlePosition=int(arraySize/2)-1 Pass=True if arraySize % 2==0 : if int(array[middlePosition])toInteger() ; while caseNumber /= 0 do ( var arraySize : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var array : OclAny := input().split(" ") ; var positionCount : int := 0 ; var middlePosition : double := ("" + ((arraySize / 2)))->toInteger() - 1 ; var Pass : boolean := true ; if arraySize mod 2 = 0 then ( if (("" + ((array[middlePosition+1])))->toInteger()->compareTo(middlePosition + 1)) < 0 & (("" + ((array[middlePosition + 1+1])))->toInteger()->compareTo(middlePosition + 1)) < 0 then ( Pass := false ) else skip ) else skip ; for digit : array do ( var digit : int := ("" + ((digit)))->toInteger() ; var reversePositionCount : double := arraySize - 1 - positionCount ; if (reversePositionCount->compareTo(positionCount)) < 0 then ( var relativePosition : OclAny := reversePositionCount ) else ( relativePosition := positionCount ) ; if (digit->compareTo(relativePosition)) < 0 then ( Pass := false ; break ) else skip ; positionCount := positionCount + 1) ; if Pass = true then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ; caseNumber := caseNumber - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) num_array=[int(num)for num in input().split()] sharp=True first_half=n//2 for i in range(first_half): if num_array[i]toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var num_array : Sequence := input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var sharp : boolean := true ; var first_half : int := n div 2 ; for i : Integer.subrange(0, first_half-1) do ( if (num_array[i+1]->compareTo(i)) < 0 then ( sharp := false ) else skip) ; for i : Integer.subrange(first_half, n-1) do ( if (num_array[i+1]->compareTo(n - 1 - i)) < 0 then ( sharp := false ) else skip) ; if num_array[first_half - 1+1] = first_half - 1 & num_array[first_half+1] = first_half - 1 then ( sharp := false ) else skip ; if sharp then ( execute ('Yes')->display() ) else ( execute ('No')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t=int(input()) ans=[] for _ in range(t): n=int(input()) a=list(map(int,input().split())) l,r=[0]*n,[0]*n for i in range(n): if a[i]toInteger() ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, n),MatrixLib.elementwiseMult(Sequence{ 0 }, n)} ; for i : Integer.subrange(0, n-1) do ( if (a[i+1]->compareTo(i)) < 0 then ( break ) else skip ; l[i+1] := 1) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (a[i+1]->compareTo(n - i - 1)) < 0 then ( break ) else skip ; r[i+1] := 1) ; var ans0 : String := "No" ; for i : Integer.subrange(0, n-1) do ( if l[i+1] & r[i+1] then ( ans0 := "Yes" ; break ) else skip) ; execute ((ans0) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n=int(input()) w=list(map(int,input().split())) d=n+1 ans='Yes' for i in range(n): if w[i]toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : int := n + 1 ; var ans : String := 'Yes' ; for i : Integer.subrange(0, n-1) do ( if (w[i+1]->compareTo(i)) < 0 then ( d := i ; break ) else skip) ; for i : Integer.subrange(d - 1, n-1) do ( if (w[i+1]->compareTo(n - 1 - i)) < 0 then ( ans := 'No' ; break ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) mod=998244353 a=list(map(int,input().split())) a.sort() l=2*n+5 fact=[1]*(l+1) for i in range(1,l+1): fact[i]=i*fact[i-1]% mod inv=[1]*(l+1) inv[l]=pow(fact[l],mod-2,mod) for i in range(l-1,-1,-1): inv[i]=(i+1)*inv[i+1]% mod def comb(n,r): return fact[n]*inv[r]% mod*inv[n-r]% mod if n>=r>=0 else 0 c=comb(2*n,n) ans=c*((sum(a[n :])-sum(a[: n]))% mod)% mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mod : int := 998244353 ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var l : int := 2 * n + 5 ; var fact : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (l + 1)) ; for i : Integer.subrange(1, l + 1-1) do ( fact[i+1] := i * fact[i - 1+1] mod mod) ; var inv : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (l + 1)) ; inv[l+1] := (fact[l+1])->pow(mod - 2) ; for i : Integer.subrange(-1 + 1, l - 1)->reverse() do ( inv[i+1] := (i + 1) * inv[i + 1+1] mod mod) ; skip ; var c : OclAny := comb(2 * n, n) ; var ans : int := c * (((a.subrange(n+1))->sum() - (a.subrange(1,n))->sum()) mod mod) mod mod ; execute (ans)->display(); operation comb(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: return if (n->compareTo(r)) >= 0 & (r >= 0) then fact[n+1] * inv[r+1] mod mod * inv[n - r+1] mod mod else 0 endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) s=input() t=input() t=t.replace('G','B') s=s.replace('G','B') print(['NO','YES'][t==s]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; t := t.replace('G', 'B') ; s := s.replace('G', 'B') ; execute (Sequence{'NO'}->union(Sequence{ 'YES' })->select(t = s))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solve : def __init__(self): tmp=[int(i)for i in input().split()] if len(tmp)==1 : self.cal=False else : self.cal=True q1,b,c1,c2,q2=tmp self.B=b self.C=(c1,c2) self.Q=(q1,q2) self.a=0 self.b=min(self.Q[1]+1,self.B//self.C[0]+1) def check(self,A): b=self.B b-=self.C[0]*A b-=self.C[1]*max(0,self.Q[0]-A) if b>=0 : return True else : return False def solve(self): while self.b-self.a>1 : m=(self.a+self.b)//2 if self.check(m): self.a=m else : self.b=m return self.buy(self.a) def buy(self,A): if A==0 : return['NA'] else : return[str(A),str((self.B-self.C[0]*A)//self.C[1])] while True : s=Solve() if not s.cal : break print(" ".join(s.solve())) ------------------------------------------------------------ OCL File: --------- class Solve { static operation newSolve() : Solve pre: true post: Solve->exists( _x | result = _x ); operation initialise() : Solve pre: true post: true activity: var tmp : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if (tmp)->size() = 1 then ( self.cal := false ) else ( self.cal := true ; var q1 : OclAny := null; var b : OclAny := null; var c1 : OclAny := null; var c2 : OclAny := null; var q2 : OclAny := null; Sequence{q1,b,c1,c2,q2} := tmp ; self.B := b ; self.C := Sequence{c1, c2} ; self.Q := Sequence{q1, q2} ; self.a := 0 ; self.b := Set{self.Q[1+1] + 1, self.B div self.C->first() + 1}->min() ); return self; operation check(A : OclAny) : OclAny pre: true post: true activity: var b : OclAny := self.B ; b := b - self.C->first() * A ; b := b - self.C[1+1] * Set{0, self.Q->first() - A}->max() ; if b >= 0 then ( return true ) else ( return false ); operation solve() : OclAny pre: true post: true activity: while self.b - self.a > 1 do ( var m : int := (self.a + self.b) div 2 ; if self.check(m) then ( self.a := m ) else ( self.b := m )) ; return self.buy(self.a); operation buy(A : OclAny) : OclAny pre: true post: true activity: if A = 0 then ( return Sequence{ 'NA' } ) else ( return Sequence{("" + ((A)))}->union(Sequence{ ("" + (((self.B - self.C->first() * A) div self.C[1+1]))) }) ); } class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var s : Solve := (Solve.newSolve()).initialise() ; if not(s.cal) then ( break ) else skip ; execute (StringLib.sumStringsWithSeparator((s.solve()), " "))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=input() if n=='0' : break q1,b,c1,c2,q2=map(int,n.split()) for i in range(q2,0,-1): c=i*c1 x=(b-c)//c2 if i+x=0 : print(i,x) break else : print('NA') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : String := (OclFile["System.in"]).readLine() ; if n = '0' then ( break ) else skip ; var q1 : OclAny := null; var b : OclAny := null; var c1 : OclAny := null; var c2 : OclAny := null; var q2 : OclAny := null; Sequence{q1,b,c1,c2,q2} := (n.split())->collect( _x | (OclType["int"])->apply(_x) ) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name q2))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom (name c1))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (name c)))))))) ))) // (expr (atom (name c2))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name i))) + (expr (atom (name x))))) < (comparison (expr (atom (name q1))))))) : (suite (stmt (simple_stmt (small_stmt continue)))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name x)))) >= (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NA'))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binary_search(quantity,budget,aizu_chicken_price,chicken_price,aizu_chicken_limit): if budget<(quantity-1)*chicken_price+aizu_chicken_price : return None if aizu_chicken_price*quantity<=budget : aizu_chicken_count=budget//aizu_chicken_price if aizu_chicken_limitselect(item | true)->collect(item | (("" + ((item)))->toInteger())) ; var result : OclAny := binary_search(quantity, budget, aizu_chicken_price, chicken_price, aizu_chicken_limit) ; if not(result <>= null) then ( execute (result->first())->display() ) else ( execute ("NA")->display() )); operation binary_search(quantity : OclAny, budget : OclAny, aizu_chicken_price : OclAny, chicken_price : OclAny, aizu_chicken_limit : OclAny) : OclAny pre: true post: true activity: if (budget->compareTo((quantity - 1) * chicken_price + aizu_chicken_price)) < 0 then ( return null ) else skip ; if (aizu_chicken_price * quantity->compareTo(budget)) <= 0 then ( var aizu_chicken_count : int := budget div aizu_chicken_price ; if (aizu_chicken_limit->compareTo(aizu_chicken_count)) < 0 then ( aizu_chicken_count := aizu_chicken_limit ) else skip ; var rest : double := budget - aizu_chicken_price * aizu_chicken_count ; var chicken_count : int := rest div chicken_price ; return aizu_chicken_count, chicken_count ) else skip ; if (aizu_chicken_price * aizu_chicken_limit + chicken_price * (quantity - aizu_chicken_limit)->compareTo(budget)) < 0 then ( rest := budget - aizu_chicken_price * aizu_chicken_limit ; chicken_count := rest div chicken_price ; return aizu_chicken_limit, chicken_count ) else skip ; aizu_chicken_count := aizu_chicken_limit div 2 ; chicken_count := quantity - aizu_chicken_count ; var update_count : int := aizu_chicken_count div 2 + 1 ; var max_pair : OclAny := Sequence{0, quantity} ; while 0 < update_count do ( if (aizu_chicken_count * aizu_chicken_price + chicken_count * chicken_price->compareTo(budget)) <= 0 then ( max_pair := Sequence{aizu_chicken_count, chicken_count} ; aizu_chicken_count := aizu_chicken_count + update_count + 1 ; chicken_count := chicken_count - (update_count + 1) ) else ( aizu_chicken_count := aizu_chicken_count - (update_count + 1) ; chicken_count := chicken_count + update_count + 1 ) ; update_count := update_count div 2) ; return max_pair; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findLastIndex(str,x): for i in range(len(str)-1,-1,-1): if(str[i]==x): return i return-1 str="geeksforgeeks" x='e' index=findLastIndex(str,x) if(index==-1): print("Character not found") else : print("Last index is ",index) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclType["String"] := "geeksforgeeks" ; x := 'e' ; var index : OclAny := findLastIndex(OclType["String"], x) ; if (index = -1) then ( execute ("Character not found")->display() ) else ( execute ("Last index is ")->display() ); operation findLastIndex(OclType["String"] : OclAny, x : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(-1 + 1, (OclType["String"])->size() - 1)->reverse() do ( if (("" + ([i+1])) = x) then ( return i ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,bisect PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") def aizu_chicken(q1,b,c1,c2,q2): for i in range(q2,0,-1): cj=i*c1 normal=int((b-cj)//c2) if i+normal=0 : print(i,normal) break else : print("NA") while True : inp=[int(_)for _ in input().split()] if len(inp)==1 : break q1,b,c1,c2,q2=inp[:] aizu_chicken(q1,b,c1,c2,q2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; skip ; while true do ( var inp : Sequence := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; if (inp)->size() = 1 then ( break ) else skip ; Sequence{q1,b,c1,c2,q2} := inp ; aizu_chicken(q1, b, c1, c2, q2)); operation aizu_chicken(q1 : OclAny, b : OclAny, c1 : OclAny, c2 : OclAny, q2 : OclAny) pre: true post: true activity: (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name q2))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cj)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom (name c1))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name normal)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (name cj)))))))) ))) // (expr (atom (name c2))))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name i))) + (expr (atom (name normal))))) < (comparison (expr (atom (name q1))))))) : (suite (stmt (simple_stmt (small_stmt continue)))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name normal)))) >= (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (name normal)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NA"))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def Cond(q1,b,mid,c1,c2): b-=(c1*mid) if b<0 : return False b-=(c2*(q1-mid)) if b<0 : return False return True def solve(q1,b,c1,c2,q2): ub=q2 lb=1 aizu_chicken=0 while(ub-lb)>1 : mid=(ub+lb)//2 if Cond(q1,b,mid,c1,c2): lb=mid aizu_chicken=max(aizu_chicken,mid) else : ub=mid if Cond(q1,b,lb,c1,c2): aizu_chicken=max(aizu_chicken,lb) if Cond(q1,b,ub,c1,c2): aizu_chicken=max(aizu_chicken,ub) b-=(aizu_chicken*c1) normal_chicken=b//c2 if normal_chicken<0 or aizu_chicken==0 : return False,0,0 else : return True,aizu_chicken,normal_chicken def main(args): while True : txt=input().strip() if txt[0]=='0' : break q1,b,c1,c2,q2=map(int,txt.split()) result,aizu,normal=solve(q1,b,c1,c2,q2) if result is False : print('NA') else : print(aizu,normal) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation Cond(q1 : OclAny, b : OclAny, mid : OclAny, c1 : OclAny, c2 : OclAny) : OclAny pre: true post: true activity: b := b - (c1 * mid) ; if b < 0 then ( return false ) else skip ; b := b - (c2 * (q1 - mid)) ; if b < 0 then ( return false ) else skip ; return true; operation solve(q1 : OclAny, b : OclAny, c1 : OclAny, c2 : OclAny, q2 : OclAny) : OclAny pre: true post: true activity: var ub : OclAny := q2 ; var lb : int := 1 ; var aizu_chicken : int := 0 ; while (ub - lb) > 1 do ( mid := (ub + lb) div 2 ; if Cond(q1, b, mid, c1, c2) then ( lb := mid ; aizu_chicken := Set{aizu_chicken, mid}->max() ) else ( ub := mid )) ; if Cond(q1, b, lb, c1, c2) then ( aizu_chicken := Set{aizu_chicken, lb}->max() ) else skip ; if Cond(q1, b, ub, c1, c2) then ( aizu_chicken := Set{aizu_chicken, ub}->max() ) else skip ; b := b - (aizu_chicken * c1) ; var normal_chicken : int := b div c2 ; if normal_chicken < 0 or aizu_chicken = 0 then ( return false, 0, 0 ) else ( return true, aizu_chicken, normal_chicken ); operation main(args : OclAny) pre: true post: true activity: while true do ( var txt : OclAny := input()->trim() ; if txt->first() = '0' then ( break ) else skip ; Sequence{q1,b,c1,c2,q2} := (txt.split())->collect( _x | (OclType["int"])->apply(_x) ) ; var result : OclAny := null; var aizu : OclAny := null; var normal : OclAny := null; Sequence{result,aizu,normal} := solve(q1, b, c1, c2, q2) ; if result <>= false then ( execute ('NA')->display() ) else ( execute (aizu)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxval(a,n): if(n<2): return-99999 max=0 for i in range(n): for j in range(i+1,n): x=(a[i]+i)*(a[j]+j) if maxunion(Sequence{5}->union(Sequence{3}->union(Sequence{1}->union(Sequence{ 10 })))), 5))->display(); operation maxval(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n < 2) then ( return -99999 ) else skip ; var max : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( var x : double := (a[i+1] + i) * (a[j+1] + j) ; if (max->compareTo(x)) < 0 then ( max := x ) else skip)) ; return max; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def findDigitalRoot(num): sum=sys.maxsize ; tempNum=num ; while(sum>=10): sum=0 ; while(tempNum>0): sum+=tempNum % 10 ; tempNum//=10 ; tempNum=sum ; return sum ; def findAnswer(X,N): counter=0 ; i=0 ; while(counter= 10) do ( sum := 0; ; while (tempNum > 0) do ( sum := sum + tempNum mod 10; ; tempNum := tempNum div 10;) ; tempNum := sum;) ; return sum;; operation findAnswer(X : OclAny, N : OclAny) pre: true post: true activity: var counter : int := 0; ; var i : int := 0; ; while ((counter->compareTo(N)) < 0) do ( i := i + 1; ; var digitalRoot : OclAny := findDigitalRoot(i); ; if (digitalRoot = X) then ( counter := counter + 1; ) else skip ; if (counter = N) then ( execute (i)->display(); ; break; ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=4562 ; rev=0 while(n>0): a=n % 10 rev=rev*10+a n=n//10 print(rev) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := 4562; ; var rev : int := 0 ; while (n > 0) do ( var a : int := n mod 10 ; rev := rev * 10 + a ; n := n div 10) ; execute (rev)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=4562 ; rev=0 while(n>0): a=n % 10 rev=rev*10+a n=n/10 print(rev) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := 4562; ; var rev : int := 0 ; while (n > 0) do ( var a : int := n mod 10 ; rev := rev * 10 + a ; n := n / 10) ; execute (rev)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline x1,y1=map(int,input().split()) x2,y2=map(int,input().split()) x3,y3=map(int,input().split()) a=x1+x2+x3 b=y1+y2+y3 print(3) print(a-x1*2,b-y1*2) print(a-x2*2,b-y2*2) print(a-x3*2,b-y3*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x3 : OclAny := null; var y3 : OclAny := null; Sequence{x3,y3} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := x1 + x2 + x3 ; var b : OclAny := y1 + y2 + y3 ; execute (3)->display() ; execute (a - x1 * 2)->display() ; execute (a - x2 * 2)->display() ; execute (a - x3 * 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=4562 ; rev=0 while(n>0): a=n % 10 rev=rev*10+a n=n//10 print(rev) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := 4562; ; var rev : int := 0 ; while (n > 0) do ( var a : int := n mod 10 ; rev := rev * 10 + a ; n := n div 10) ; execute (rev)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- rev_num=0 base_pos=1 def reversDigits(num): global rev_num global base_pos if(num>0): reversDigits((int)(num/10)) rev_num+=(num % 10)*base_pos base_pos*=10 return rev_num num=4562 print("Reverse of no.is ",reversDigits(num)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute rev_num : OclAny; attribute base_pos : OclAny; operation initialise() pre: true post: true activity: var rev_num : int := 0 ; var base_pos : int := 1 ; skip ; num := 4562 ; execute ("Reverse of no.is ")->display(); operation reversDigits(num : OclAny) : OclAny pre: true post: true activity: skip ; skip ; if (num > 0) then ( reversDigits((OclType["int"])(num / 10)) ; rev_num := rev_num + (num mod 10) * base_pos ; base_pos := base_pos * 10 ) else skip ; return rev_num; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- rev_num=0 base_pos=1 def reversDigits(num): global rev_num global base_pos if(num>0): reversDigits((int)(num/10)) rev_num+=(num % 10)*base_pos base_pos*=10 return rev_num num=4562 print("Reverse of no.is ",reversDigits(num)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute rev_num : OclAny; attribute base_pos : OclAny; operation initialise() pre: true post: true activity: var rev_num : int := 0 ; var base_pos : int := 1 ; skip ; num := 4562 ; execute ("Reverse of no.is ")->display(); operation reversDigits(num : OclAny) : OclAny pre: true post: true activity: skip ; skip ; if (num > 0) then ( reversDigits((OclType["int"])(num / 10)) ; rev_num := rev_num + (num mod 10) * base_pos ; base_pos := base_pos * 10 ) else skip ; return rev_num; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def primeOccurences(arr,k): map={} for val in arr : freq=0 if val in map : freq=map[val] freq+=1 else : freq=1 map[val]=freq for entry in map : value=map[entry] if isPrime(value)and value>=k : print(entry) def isPrime(n): if(n>2 and not n % 2)or n==1 : return False for i in range(3,int(n**0.5+1),2): if not n % i : return False return True arr=[11,11,11,23,11,37,37,51,51,51,51,51] k=2 primeOccurences(arr,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{11}->union(Sequence{11}->union(Sequence{11}->union(Sequence{23}->union(Sequence{11}->union(Sequence{37}->union(Sequence{37}->union(Sequence{51}->union(Sequence{51}->union(Sequence{51}->union(Sequence{51}->union(Sequence{ 51 }))))))))))) ; k := 2 ; primeOccurences(arr, k); operation primeOccurences(arr : OclAny, k : OclAny) pre: true post: true activity: var map : OclAny := Set{} ; for val : arr do ( var freq : int := 0 ; if (map)->includes(val) then ( freq := ([val+1]`third)->collect( _x | ([val+1])->apply(_x) ) ; freq := freq + 1 ) else ( freq := 1 ) ; ([val+1]`third)->collect( _x | ([val+1])->apply(_x) ) := freq) ; for entry : map do ( var value : Sequence := ([entry+1]`third)->collect( _x | ([entry+1])->apply(_x) ) ; if isPrime(value) & (value->compareTo(k)) >= 0 then ( execute (entry)->display() ) else skip); operation isPrime(n : OclAny) : OclAny pre: true post: true activity: if (n > 2 & not(n mod 2)) or n = 1 then ( return false ) else skip ; for i : Integer.subrange(3, ("" + (((n)->pow(0.5) + 1)))->toInteger()-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if not(n mod i) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findLastIndex(str,x): index=-1 for i in range(0,len(str)): if str[i]==x : index=i return index str="geeksforgeeks" x='e' index=findLastIndex(str,x) if index==-1 : print("Character not found") else : print('Last index is',index) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclType["String"] := "geeksforgeeks" ; x := 'e' ; index := findLastIndex(OclType["String"], x) ; if index = -1 then ( execute ("Character not found")->display() ) else ( execute ('Last index is')->display() ); operation findLastIndex(OclType["String"] : OclAny, x : OclAny) : OclAny pre: true post: true activity: var index : int := -1 ; for i : Integer.subrange(0, (OclType["String"])->size()-1) do ( if ("" + ([i+1])) = x then ( index := i ) else skip) ; return index; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def trianglearea(l,b): if(l<0 or b<0): return-1 area=(l*b)/2 return area l=5 b=4 print(trianglearea(l,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; l := 5 ; b := 4 ; execute (trianglearea(l, b))->display(); operation trianglearea(l : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (l < 0 or b < 0) then ( return -1 ) else skip ; var area : double := (l * b) / 2 ; return area; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import maxsize def maxSubArraySum(a,size): max_so_far=-maxsize-1 max_ending_here=0 start=0 end=0 s=0 for i in range(0,size): max_ending_here+=a[i] if max_so_farunion(Sequence{-3}->union(Sequence{4}->union(Sequence{-1}->union(Sequence{-2}->union(Sequence{1}->union(Sequence{5}->union(Sequence{ -3 }))))))) ; execute (maxSubArraySum(a, (a)->size()))->display(); operation maxSubArraySum(a : OclAny, size : OclAny) : OclAny pre: true post: true activity: var max_so_far : double := -maxsize - 1 ; var max_ending_here : int := 0 ; var start : int := 0 ; var end : int := 0 ; var s : int := 0 ; for i : Integer.subrange(0, size-1) do ( max_ending_here := max_ending_here + a[i+1] ; if (max_so_far->compareTo(max_ending_here)) < 0 then ( max_so_far := max_ending_here ; start := s ; end := i ) else skip ; if max_ending_here < 0 then ( max_ending_here := 0 ; s := i + 1 ) else skip) ; return (end - start + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- coins=int(input()) array=list(map(int,input().split())) counter=1 maxPockets=1 for i in array : if array.count(i)==1 : continue else : counter=array.count(i) if counter>=maxPockets : maxPockets=counter print(maxPockets) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var coins : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var array : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var counter : int := 1 ; var maxPockets : int := 1 ; for i : array do ( if array->count(i) = 1 then ( continue ) else ( counter := array->count(i) ; if (counter->compareTo(maxPockets)) >= 0 then ( maxPockets := counter ) else skip )) ; execute (maxPockets)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict x=int(input()) has=defaultdict(int) arr=[*map(int,input().split())] for i in arr : has[i]+=1 print(max(has.values())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var has : OclAny := defaultdict(OclType["int"]) ; var arr : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : arr do ( has[i+1] := has[i+1] + 1) ; execute ((has.values())->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=list(map(int,input().split())) temp=0 for i in x : if(x.count(i)>temp): temp=x.count(i) print(temp) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var temp : int := 0 ; for i : x do ( if ((x->count(i)->compareTo(temp)) > 0) then ( temp := x->count(i) ) else skip) ; execute (temp)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ax,ay=map(int,input().split()) bx,by=map(int,input().split()) cx,cy=map(int,input().split()) print(3) print(ax+bx-cx,ay+by-cy) print(bx+cx-ax,by+cy-ay) print(cx+ax-bx,cy+ay-by) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ax : OclAny := null; var ay : OclAny := null; Sequence{ax,ay} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var bx : OclAny := null; var by : OclAny := null; Sequence{bx,by} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cx : OclAny := null; var cy : OclAny := null; Sequence{cx,cy} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (3)->display() ; execute (ax + bx - cx)->display() ; execute (bx + cx - ax)->display() ; execute (cx + ax - bx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input('')) l=list(map(int,input().split())) s=set(l) k=[] for i in s : k.append(l.count(i)) print(max(k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Set := Set{}->union((l)) ; var k : Sequence := Sequence{} ; for i : s do ( execute ((l->count(i)) : k)) ; execute ((k)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() a=input().split() print(max(a.count(x)for x in a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var a : OclAny := input().split() ; execute (((argument (test (logical_test (comparison (expr (atom (name a)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a))))))))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline x=int(input()) pow2=[1] for _ in range(22): pow2.append(2*pow2[-1]) s=set() for i in pow2 : s.add(i-1) t=0 n=[] while not x in s : t+=1 n0=x.bit_length() n.append(n0) x ^=(pow2[n0]-1) if x in s : break t+=1 x+=1 print(t) if t : sys.stdout.write(" ".join(map(str,n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var pow2 : Sequence := Sequence{ 1 } ; for _anon : Integer.subrange(0, 22-1) do ( execute ((2 * pow2->last()) : pow2)) ; var s : Set := Set{}->union(()) ; for i : pow2 do ( execute ((i - 1) : s)) ; var t : int := 0 ; var n : Sequence := Sequence{} ; while not((s)->includes(x)) do ( t := t + 1 ; var n0 : OclAny := x.bit_length() ; execute ((n0) : n) ; x := x xor (pow2[n0+1] - 1) ; if (s)->includes(x) then ( break ) else skip ; t := t + 1 ; x := x + 1) ; execute (t)->display() ; if t then ( (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " ") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))) ))))))))) )))) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) print(39) j=19 while j : j-=1 k=int(math.log(n,2))+1 n=n ^ int(2**k-1) n+=1 print(k,end=" ") print(int(math.log(n,2))+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (39)->display() ; var j : int := 19 ; while j do ( j := j - 1 ; var k : int := ("" + (((n, 2)->log())))->toInteger() + 1 ; n := MathLib.bitwiseXor(n, ("" + (((2)->pow(k) - 1)))->toInteger()) ; n := n + 1 ; execute (k)->display()) ; execute (("" + (((n, 2)->log())))->toInteger() + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) print(39) j=19 while j : j-=1 k=int(math.log(n,2))+1 n=n ^ int(2**k-1) n+=1 print(k,end=" ") print(int(math.log(n,2))+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (39)->display() ; var j : int := 19 ; while j do ( j := j - 1 ; var k : int := ("" + (((n, 2)->log())))->toInteger() + 1 ; n := MathLib.bitwiseXor(n, ("" + (((2)->pow(k) - 1)))->toInteger()) ; n := n + 1 ; execute (k)->display()) ; execute (("" + (((n, 2)->log())))->toInteger() + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter def powmod(a,n,m): ans=1 while n!=0 : if n & 1 : ans=ans*a % m a=a*a % m n>>=1 return ans % m n=int(input()) a=list(map(int,input().split())) a.sort() dic=Counter(a) if n % 2==0 : temp={} for i in range(1,n,2): temp[i]=2 if temp!=dict(dic): print(0) exit() else : temp={} temp[0]=1 for i in range(2,n,2): temp[i]=2 if temp!=dict(dic): print(0) exit() print(powmod(2,n//2,10**9+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var dic : OclAny := Counter(a) ; if n mod 2 = 0 then ( var temp : OclAny := Set{} ; for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( temp[i+1] := 2) ; if temp /= ((atom (name dic))) then ( execute (0)->display() ; exit() ) else skip ) else ( temp := Set{} ; temp->first() := 1 ; for i : Integer.subrange(2, n-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( temp[i+1] := 2) ; if temp /= ((atom (name dic))) then ( execute (0)->display() ; exit() ) else skip ) ; execute (powmod(2, n div 2, (10)->pow(9) + 7))->display(); operation powmod(a : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var ans : int := 1 ; while n /= 0 do ( if MathLib.bitwiseAnd(n, 1) then ( ans := ans * a mod m ) else skip ; a := a * a mod m ; n := n div (2->pow(1))) ; return ans mod m; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) print(39) j=19 while j : j-=1 k=int(math.log(n,2))+1 n=n ^ int(2**k-1) n+=1 print(k,end=" ") print(int(math.log(n,2))+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (39)->display() ; var j : int := 19 ; while j do ( j := j - 1 ; var k : int := ("" + (((n, 2)->log())))->toInteger() + 1 ; n := MathLib.bitwiseXor(n, ("" + (((2)->pow(k) - 1)))->toInteger()) ; n := n + 1 ; execute (k)->display()) ; execute (("" + (((n, 2)->log())))->toInteger() + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[] t=0 while(1): if(n==0 or n==1): break j=-1 for i in range(0,21): if((n>>i)& 1): j=i p=(1<<(j+1))-1 n ^=p p=(1<toInteger() ; var a : Sequence := Sequence{} ; var t : int := 0 ; while (1) do ( if (n = 0 or n = 1) then ( break ) else skip ; var j : int := -1 ; for i : Integer.subrange(0, 21-1) do ( if (MathLib.bitwiseAnd((n /(2->pow(i))), 1)) then ( j := i ) else skip) ; var p : double := (1 * (2->pow((j + 1)))) - 1 ; n := n xor p ; p := (1 * (2->pow(j))) - 1 ; if (n = p) then ( execute ((j + 1) : a) ; t := t + 1 ; break ) else skip ; n := n + 1 ; execute ((j + 1) : a) ; t := t + 2) ; execute (t)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def sumKRepeating(arr,n,k): Sum=0 mp=dict() for i in range(n): if arr[i]in mp.keys(): mp[arr[i]]+=1 else : mp[arr[i]]=1 for x in mp : if(mp[x]==k): Sum+=x return Sum arr=[9,9,10,11,8,8,9,8] n=len(arr) k=3 print(sumKRepeating(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{9}->union(Sequence{9}->union(Sequence{10}->union(Sequence{11}->union(Sequence{8}->union(Sequence{8}->union(Sequence{9}->union(Sequence{ 8 }))))))) ; n := (arr)->size() ; k := 3 ; execute (sumKRepeating(arr, n, k))->display(); operation sumKRepeating(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var Sum : int := 0 ; var mp : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( if (mp.keys())->includes(arr[i+1]) then ( mp[arr[i+1]+1] := mp[arr[i+1]+1] + 1 ) else ( mp[arr[i+1]+1] := 1 )) ; for x : mp->keys() do ( if (mp[x+1] = k) then ( Sum := Sum + x ) else skip) ; return Sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- val=input().split() val=[int(x)for x in val] n=val[0] m=val[1] liss=[] for i in range(n): t=input() liss.append(t) st=set() for j in range(m): val=liss[0][j] for i in range(1,n): if valselect(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var n : OclAny := val->first() ; var m : OclAny := val[1+1] ; var liss : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var t : String := (OclFile["System.in"]).readLine() ; execute ((t) : liss)) ; var st : Set := Set{}->union(()) ; for j : Integer.subrange(0, m-1) do ( val := liss->first()[j+1] ; for i : Integer.subrange(1, n-1) do ( if (val->compareTo(liss[i+1][j+1])) < 0 then ( val := liss[i+1][j+1] ) else skip) ; for k : Integer.subrange(0, n-1) do ( if liss[k+1][j+1] = val then ( execute ((k) : st) ) else skip)) ; execute ((st)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(x1,y1,x2,y2,x3,y3): ans="3\n" x=[x1,x2,x3] y=[y1,y2,y3] for i in range(3): a=x1+x2+x3-2*x[i] b=y1+y2+y3-2*y[i] ans+=str(a)+" "+str(b) ans+="\n" return ans x1,y1=map(int,input().split()) x2,y2=map(int,input().split()) x3,y3=map(int,input().split()) print(solve(x1,y1,x2,y2,x3,y3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{x1,y1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; Sequence{x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; Sequence{x3,y3} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (solve(x1, y1, x2, y2, x3, y3))->display(); operation solve(x1 : OclAny, y1 : OclAny, x2 : OclAny, y2 : OclAny, x3 : OclAny, y3 : OclAny) : OclAny pre: true post: true activity: var ans : String := "3\n" ; var x : Sequence := Sequence{x1}->union(Sequence{x2}->union(Sequence{ x3 })) ; var y : Sequence := Sequence{y1}->union(Sequence{y2}->union(Sequence{ y3 })) ; for i : Integer.subrange(0, 3-1) do ( var a : double := x1 + x2 + x3 - 2 * x[i+1] ; var b : double := y1 + y2 + y3 - 2 * y[i+1] ; ans := ans + ("" + ((a))) + " " + ("" + ((b))) ; ans := ans + "\n") ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) marks=[input()for i in range(n)] suc=[max(i)for i in zip(*marks)] print(sum(any(suc[i]==a[i]for i in range(m))for a in marks)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var marks : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var suc : Sequence := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name marks)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name marks)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name marks)))))))`third->at(_indx)} )->select(i | true)->collect(i | ((i)->max())) ; execute (((argument (test (logical_test (comparison (expr (atom (name any)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (comparison (expr (atom (name suc)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name m)))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name marks))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter import math hpop=heappop hpush=heappush def solution(): n,m=map(int,input().split()) grid=[] for _ in range(n): grid.append(input()) s=set() for j in range(m): m=max([grid[i][j]for i in range(n)]) for i in range(n): if grid[i][j]==m : s.add(i) print(len(s)) def main(): t=1 for _ in range(t): solution() import sys import threading sys.setrecursionlimit(1<<30) threading.stack_size(1<<27) thread=threading.Thread(target=main) thread.start(); thread.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1 * (2->pow(30))) ; threading.stack_size(1 * (2->pow(27))) ; var thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ; thread.start(); thread.join(); operation solution() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var grid : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : grid)) ; var s : Set := Set{}->union(()) ; for j : Integer.subrange(0, m-1) do ( var m : OclAny := (Integer.subrange(0, n-1)->select(i | true)->collect(i | (grid[i+1][j+1])))->max() ; for i : Integer.subrange(0, n-1) do ( if grid[i+1][j+1] = m then ( execute ((i) : s) ) else skip)) ; execute ((s)->size())->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) gradebook=[] for i in range(m): gradebook.append([]) for _ in range(n): _grade=input() for i in range(m): gradebook[i].append(int(_grade[i])) successful_students=set() for subject in gradebook : max_i=[] max_grade=0 for student_i in range(n): if subject[student_i]>max_grade : max_i=[student_i+1] max_grade=subject[student_i] elif subject[student_i]==max_grade : max_i.append(student_i+1) successful_students |=set(max_i) print(len(successful_students)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var gradebook : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( execute ((Sequence{}) : gradebook)) ; for _anon : Integer.subrange(0, n-1) do ( var _grade : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, m-1) do ((expr (atom (name gradebook)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name _grade)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))))))) )))))) ; var successful_students : Set := Set{}->union(()) ; for subject : gradebook do ( var max_i : Sequence := Sequence{} ; var max_grade : int := 0 ; for student_i : Integer.subrange(0, n-1) do ( if (subject[student_i+1]->compareTo(max_grade)) > 0 then ( max_i := Sequence{ student_i + 1 } ; max_grade := subject[student_i+1] ) else (if subject[student_i+1] = max_grade then ( execute ((student_i + 1) : max_i) ) else skip)) ; successful_students := successful_students or Set{}->union((max_i))) ; execute ((successful_students)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- zz,yy=map(int,input().split()) d_s={} l_s=list(set()for _ in range(yy)) for i in range(zz): s=input() for j in range(yy): if j not in d_s : d_s[j]=int(s[j]) l_s[j].add(i) elif d_s[j]collect( _x | (OclType["int"])->apply(_x) ) ; var d_s : OclAny := Set{} ; var l_s : Sequence := ((argument (test (logical_test (comparison (expr (atom (name set)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name yy)))))))) ))))))))) ; for i : Integer.subrange(0, zz-1) do ( var s : String := (OclFile["System.in"]).readLine() ; for j : Integer.subrange(0, yy-1) do ( if (d_s)->excludes(j) then ( d_s[j+1] := ("" + ((s[j+1])))->toInteger() ; (expr (atom (name l_s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ) else (if (d_s[j+1]->compareTo(("" + ((s[j+1])))->toInteger())) < 0 then ( d_s[j+1] := ("" + ((s[j+1])))->toInteger() ; (expr (atom (name l_s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name clear) (arguments ( )))) ; (expr (atom (name l_s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ) else (if d_s[j+1] = ("" + ((s[j+1])))->toInteger() then ( (expr (atom (name l_s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ) else skip ) ) )) ; for i : Integer.subrange(1, yy-1) do ( l_s->first() := l_s->first().union(l_s[i+1])) ; execute ((l_s->first())->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findLength(string,n): Sum=[0]*(n+1) for i in range(1,n+1): Sum[i]=(Sum[i-1]+int(string[i-1])) ans=0 for length in range(2,n+1,2): for i in range(0,n-length+1): j=i+length-1 if(Sum[i+length//2]-Sum[i]==Sum[i+length]-Sum[i+length//2]): ans=max(ans,length) return ans if __name__=="__main__" : string="123123" print("Length of the substring is",findLength(string,len(string))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( string := "123123" ; execute ("Length of the substring is")->display() ) else skip; operation findLength(string : OclAny, n : OclAny) : OclAny pre: true post: true activity: var Sum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(1, n + 1-1) do ( Sum[i+1] := (Sum[i - 1+1] + ("" + ((string[i - 1+1])))->toInteger())) ; var ans : int := 0 ; for length : Integer.subrange(2, n + 1-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( for i : Integer.subrange(0, n - length + 1-1) do ( var j : double := i + length - 1 ; if (Sum[i + length div 2+1] - Sum[i+1] = Sum[i + length+1] - Sum[i + length div 2+1]) then ( ans := Set{ans, length}->max() ) else skip)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- level=["heavy","light heavy","middle","light middle","welter","light welter","light","feather","bantam","fly"] weight=[91,81,75,69,64,60,57,54,51,48] while True : try : w=float(input()) except : break f=False for wei,lev in zip(weight,level): if w>wei : print(lev) f=True break if not f : print("light fly") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var level : Sequence := Sequence{"heavy"}->union(Sequence{"light heavy"}->union(Sequence{"middle"}->union(Sequence{"light middle"}->union(Sequence{"welter"}->union(Sequence{"light welter"}->union(Sequence{"light"}->union(Sequence{"feather"}->union(Sequence{"bantam"}->union(Sequence{ "fly" }))))))))) ; var weight : Sequence := Sequence{91}->union(Sequence{81}->union(Sequence{75}->union(Sequence{69}->union(Sequence{64}->union(Sequence{60}->union(Sequence{57}->union(Sequence{54}->union(Sequence{51}->union(Sequence{ 48 }))))))))) ; while true do ( try ( var w : double := ("" + (((OclFile["System.in"]).readLine())))->toReal()) catch (_e : OclException) do ( break) ; var f : boolean := false ; for _tuple : Integer.subrange(1, weight->size())->collect( _indx | Sequence{weight->at(_indx), level->at(_indx)} ) do (var _indx : int := 1; var wei : OclAny := _tuple->at(_indx); _indx := _indx + 1; var lev : OclAny := _tuple->at(_indx); if (w->compareTo(wei)) > 0 then ( execute (lev)->display() ; f := true ; break ) else skip) ; if not(f) then ( execute ("light fly")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) mod=1000000007 a=list(map(int,input().split())) a.sort() if n % 2==1 : if a[0]!=0 : print(0) exit() for i in range(1,n//2+1): if a[2*i]!=2*i or a[2*i-1]!=2*i : print(0) exit() print(pow(2,n//2,mod)) else : for i in range(n//2): if a[2*i]!=2*i+1 or a[2*i+1]!=2*i+1 : print(0) exit() print(pow(2,n//2,mod)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mod : int := 1000000007 ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; if n mod 2 = 1 then ( if a->first() /= 0 then ( execute (0)->display() ; exit() ) else skip ; for i : Integer.subrange(1, n div 2 + 1-1) do ( if a[2 * i+1] /= 2 * i or a[2 * i - 1+1] /= 2 * i then ( execute (0)->display() ; exit() ) else skip) ; execute ((2)->pow(n div 2))->display() ) else ( for i : Integer.subrange(0, n div 2-1) do ( if a[2 * i+1] /= 2 * i + 1 or a[2 * i + 1+1] /= 2 * i + 1 then ( execute (0)->display() ; exit() ) else skip) ; execute ((2)->pow(n div 2))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readlines=sys.stdin.readlines write=sys.stdout.write R=[("light fly",0),("fly",48),("bantam",51),("feather",54),("light",57),("light welter",60),("welter",64),("light middle",69),("middle",75),("light heavy",81),("heavy",91),] R.reverse() def solve(): for line in readlines(): w=float(line) for a,b in R : if w>b : write("%s\n" % a) break solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readlines : OclAny := (OclFile["System.in"]).readlines ; var write : OclAny := (OclFile["System.out"]).write ; var R : Sequence := Sequence{Sequence{"light fly", 0}}->union(Sequence{Sequence{"fly", 48}}->union(Sequence{Sequence{"bantam", 51}}->union(Sequence{Sequence{"feather", 54}}->union(Sequence{Sequence{"light", 57}}->union(Sequence{Sequence{"light welter", 60}}->union(Sequence{Sequence{"welter", 64}}->union(Sequence{Sequence{"light middle", 69}}->union(Sequence{Sequence{"middle", 75}}->union(Sequence{Sequence{"light heavy", 81}}->union(Sequence{ Sequence{"heavy", 91} })))))))))) ; R := R->reverse() ; skip ; solve(); operation solve() pre: true post: true activity: for line : readlines() do ( var w : double := ("" + ((line)))->toReal() ; for _tuple : R do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if (w->compareTo(b)) > 0 then ( write(StringLib.format("%s\n",a)) ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys for s in sys.stdin : w=float(s) if w>91.00 : print('heavy') elif w>81.00 : print('light heavy') elif w>75.00 : print('middle') elif w>69.00 : print('light middle') elif w>64.00 : print('welter') elif w>60.00 : print('light welter') elif w>57.00 : print('light') elif w>54.00 : print('feather') elif w>51.00 : print('bantam') elif w>48.00 : print('fly') else : print('light fly') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for s : OclFile["System.in"] do ( var w : double := ("" + ((s)))->toReal() ; if w > 91.00 then ( execute ('heavy')->display() ) else (if w > 81.00 then ( execute ('light heavy')->display() ) else (if w > 75.00 then ( execute ('middle')->display() ) else (if w > 69.00 then ( execute ('light middle')->display() ) else (if w > 64.00 then ( execute ('welter')->display() ) else (if w > 60.00 then ( execute ('light welter')->display() ) else (if w > 57.00 then ( execute ('light')->display() ) else (if w > 54.00 then ( execute ('feather')->display() ) else (if w > 51.00 then ( execute ('bantam')->display() ) else (if w > 48.00 then ( execute ('fly')->display() ) else ( execute ('light fly')->display() ) ) ) ) ) ) ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Class(x): if x<=48.0 : print("light fly") elif 48.0toReal() ; Class(x)) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); operation Class(x : OclAny) pre: true post: true activity: if x <= 48.0 then ( execute ("light fly")->display() ) else (if 48.0 < x & (x <= 51.0) then ( execute ("fly")->display() ) else (if 51.0 < x & (x <= 54.0) then ( execute ("bantam")->display() ) else (if 54.0 < x & (x <= 57.0) then ( execute ("feather")->display() ) else (if 57.0 < x & (x <= 60.0) then ( execute ("light")->display() ) else (if 60.0 < x & (x <= 64.0) then ( execute ("light welter")->display() ) else (if 64.0 < x & (x <= 69.0) then ( execute ("welter")->display() ) else (if 69.0 < x & (x <= 75.0) then ( execute ("light middle")->display() ) else (if 75.0 < x & (x <= 81.0) then ( execute ("middle")->display() ) else (if 81.0 < x & (x <= 91.0) then ( execute ("light heavy")->display() ) else ( execute ("heavy")->display() ) ) ) ) ) ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) a=input() b="".join(sorted(a)) return sum([1 for i in range(n)if a[i]!=b[i]]) t=int(input()) ans=[] while t : ans.append(str(solve())) t-=1 print("\n".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; while t do ( execute ((("" + ((solve())))) : ans) ; t := t - 1) ; execute (StringLib.sumStringsWithSeparator((ans), "\n"))->display(); operation solve() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : String := (OclFile["System.in"]).readLine() ; var b : String := StringLib.sumStringsWithSeparator((a->sort()), "") ; return (Integer.subrange(0, n-1)->select(i | a[i+1] /= b[i+1])->collect(i | (1)))->sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys for e in sys.stdin : e=float(e) h=['light ',''] a=h[e>91]+'heavy' if e>81 else h[e>75]+'middle' if e>69 else h[e>64]+'welter' if e>60 else 'light' if e>57 else 'feather' if e>54 else 'bantam' if e>51 else h[e>48]+'fly' print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for e : OclFile["System.in"] do ( var e : double := ("" + ((e)))->toReal() ; var h : Sequence := Sequence{'light '}->union(Sequence{ '' }) ; var a : OclAny := if e > 81 then h->select(e > 91) + 'heavy' else if e > 69 then h->select(e > 75) + 'middle' else if e > 60 then h->select(e > 64) + 'welter' else if e > 57 then 'light' else if e > 54 then 'feather' else if e > 51 then 'bantam' else h->select(e > 48) + 'fly' endif endif endif endif endif endif ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) b=set() for i in range(n): z=input().split() for i in range(n): if z[i]=='2' or z[i]=='3' : b.add(i+1) print(n-len(b)) print(*[i for i in range(1,n+1)if i not in b]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( var z : OclAny := input().split() ; for i : Integer.subrange(0, n-1) do ( if z[i+1] = '2' or z[i+1] = '3' then ( execute ((i + 1) : b) ) else skip)) ; execute (n - (b)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name i)))) not in (comparison (expr (atom (name b)))))))))) ])))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[] for i in range(int(input())): c=input().split() if '1' not in c and '3' not in c : a.append(i+1) print(len(a)) print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Sequence{} ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var c : OclAny := input().split() ; if (c)->excludes('1') & (c)->excludes('3') then ( execute ((i + 1) : a) ) else skip) ; execute ((a)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sol(arr): ans=[] for i in range(len(arr)): if 1 in arr[i]or 3 in arr[i]: continue ans.append(i+1) return ans x=int(input()) arr=[] for _ in range(x): arr.append(list(map(int,input().split()))) ans=sol(arr) print(len(ans)) if ans : print(" ".join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; arr := Sequence{} ; for _anon : Integer.subrange(0, x-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : arr)) ; ans := sol(arr) ; execute ((ans)->size())->display() ; if ans then ( execute (StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), " "))->display() ) else skip; operation sol(arr : OclAny) : OclAny pre: true post: true activity: var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, (arr)->size()-1) do ( if (arr[i+1])->includes(1) or (arr[i+1])->includes(3) then ( continue ) else skip ; execute ((i + 1) : ans)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()); l=[] for i in range(n): k=list(map(int,input().split())) if 1 not in k and 3 not in k : l.append(i+1) print(len(l)); print(*l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var k : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (k)->excludes(1) & (k)->excludes(3) then ( execute ((i + 1) : l) ) else skip) ; execute ((l)->size())->display(); execute ((argument * (test (logical_test (comparison (expr (atom (name l))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[] v=[] ans=0 for i in range(n): x=list(map(int,input().split())) a.append(x) for i in range(n): c=0 for j in range(n): if i==j : continue if a[i][j]==0 or a[i][j]==2 : c+=1 if c==n-1 : ans+=1 v.append(i+1) print(ans) for i in v : print(i,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; var v : Sequence := Sequence{} ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((x) : a)) ; for i : Integer.subrange(0, n-1) do ( var c : int := 0 ; for j : Integer.subrange(0, n-1) do ( if i = j then ( continue ) else skip ; if a[i+1][j+1] = 0 or a[i+1][j+1] = 2 then ( c := c + 1 ) else skip) ; if c = n - 1 then ( ans := ans + 1 ; execute ((i + 1) : v) ) else skip) ; execute (ans)->display() ; for i : v do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rearrange(a,size): positive=0 negative=1 while(True): while(positive=0): positive=positive+2 while(negativeunion(Sequence{-3}->union(Sequence{5}->union(Sequence{6}->union(Sequence{-3}->union(Sequence{6}->union(Sequence{7}->union(Sequence{-4}->union(Sequence{9}->union(Sequence{ 10 }))))))))) ; var n : int := (arr)->size() ; rearrange(arr, n) ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); operation rearrange(a : OclAny, size : OclAny) pre: true post: true activity: var positive : int := 0 ; var negative : int := 1 ; while (true) do ( while ((positive->compareTo(size)) < 0 & a[positive+1] >= 0) do ( positive := positive + 2) ; while ((negative->compareTo(size)) < 0 & a[negative+1] <= 0) do ( negative := negative + 2) ; if ((positive->compareTo(size)) < 0 & (negative->compareTo(size)) < 0) then ( var temp : OclAny := a[positive+1] ; a[positive+1] := a[negative+1] ; a[negative+1] := temp ) else ( break )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import collections input_methods=['clipboard','file','key'] using_method=0 input_method=input_methods[using_method] tin=lambda : map(int,input().split()) lin=lambda : list(tin()) mod=1000000007 def main(): n=int(input()) al=lin() cc=collections.Counter(al) if n % 2==1 : if cc[0]!=1 : return 0 for c in range(2,n,2): if cc[c]!=2 : return 0 else : return pow(2,n//2,mod) else : for c in range(1,n,2): if cc[c]!=2 : return 0 else : return pow(2,n//2,mod) isTest=False def pa(v): if isTest : print(v) def input_clipboard(): import clipboard input_text=clipboard.get() input_l=input_text.splitlines() for l in input_l : yield l if __name__=="__main__" : if sys.platform=='ios' : if input_method==input_methods[0]: ic=input_clipboard() input=lambda : ic.__next__() elif input_method==input_methods[1]: sys.stdin=open('inputFile.txt') else : pass isTest=True else : pass ret=main() if ret is not None : print(ret) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input_methods : Sequence := Sequence{'clipboard'}->union(Sequence{'file'}->union(Sequence{ 'key' })) ; var using_method : int := 0 ; var input_method : OclAny := input_methods[using_method+1] ; var tin : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lin : Function := lambda $$ : OclAny in ((tin->apply())) ; var mod : int := 1000000007 ; skip ; var isTest : boolean := false ; skip ; skip ; if __name__ = "__main__" then ( if OclProcess.getEnvironmentProperty("OS") = 'ios' then ( if input_method = input_methods->first() then ( var ic : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.input_clipboard(_i)) ; var input : Function := lambda $$ : OclAny in (ic.__next__()) ) else (if input_method = input_methods[1+1] then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('inputFile.txt')) ) else ( skip ) ) ; isTest := true ) else ( skip ) ; var ret : OclAny := main() ; if not(ret <>= null) then ( execute (ret)->display() ) else skip ) else skip; operation main() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var al : OclAny := lin->apply() ; var cc : OclAny := .Counter(al) ; if n mod 2 = 1 then ( if cc->first() /= 1 then ( return 0 ) else skip ; (compound_stmt for (exprlist (expr (atom (name c)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (atom (name n))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name cc)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name c)))))))) ])))) != (comparison (expr (atom (number (integer 2)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name pow)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) // (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (atom (name mod)))))))) )))))))))))))) ) else ( (compound_stmt for (exprlist (expr (atom (name c)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name n))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name cc)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name c)))))))) ])))) != (comparison (expr (atom (number (integer 2)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name pow)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) // (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (atom (name mod)))))))) )))))))))))))) ); operation pa(v : OclAny) pre: true post: true activity: if isTest then ( execute (v)->display() ) else skip; operation input_clipboard(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; skip ; var input_text : OclAny := clipboard.get() ; var input_l : OclAny := input_text.splitlines() ; for l : input_l do ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return l); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque K=int(input()) d={1 : 1} q=deque() q.append([1,1]) while q : a,c=q.popleft() a_=(a*10)% K if(a_ not in d or ctoInteger() ; var d : Map := Map{ 1 |-> 1 } ; var q : Sequence := () ; execute ((Sequence{1}->union(Sequence{ 1 })) : q) ; while q do ( var a : OclAny := null; var c : OclAny := null; Sequence{a,c} := q->first() ; q := q->tail() ; var a_ : int := (a * 10) mod K ; if ((d)->excludes(a_) or (c->compareTo(d[a_+1])) < 0) then ( d[a_+1] := c ; q := q->prepend(Sequence{a_}->union(Sequence{ c })) ) else skip ; var b_ : int := (a + 1) mod K ; if ((d)->excludes(b_) or (c->compareTo(d[b_+1])) < 0) then ( d[b_+1] := c + 1 ; execute ((Sequence{b_}->union(Sequence{ c + 1 })) : q) ) else skip) ; execute (d->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Dijkstra(): class Edge(): def __init__(self,_to,_cost): self.to=_to self.cost=_cost def __init__(self,V): self.G=[[]for i in range(V)] self._E=0 self._V=V @ property def E(self): return self._E @ property def V(self): return self._V def add(self,_from,_to,_cost): self.G[_from].append(self.Edge(_to,_cost)) self._E+=1 def shortest_path(self,s): import heapq que=[] d=[10**15]*self.V d[s]=0 heapq.heappush(que,(0,s)) while len(que)!=0 : cost,v=heapq.heappop(que) if d[v]d[v]+e.cost : d[e.to]=d[v]+e.cost heapq.heappush(que,(d[e.to],e.to)) return d K=int(input()) pro=Dijkstra(K) for i in range(0,K): pro.add(i,(i+1)% K,1) pro.add(i,(10*i)% K,0) ans=pro.shortest_path(1)[0] print(ans+1) ------------------------------------------------------------ OCL File: --------- class Dijkstra { static operation newDijkstra() : Dijkstra pre: true post: Dijkstra->exists( _x | result = _x ); attribute G : Sequence := Integer.subrange(0, V-1)->select(i | true)->collect(i | (Sequence{})); attribute _E : int := 0; attribute _V : OclAny := V; operation initialise(V : OclAny) : pre: true post: true activity: self.G := Integer.subrange(0, V-1)->select(i | true)->collect(i | (Sequence{})) ; self._E := 0 ; self._V := V; return self; operation add(_from : OclAny,_to : OclAny,_cost : OclAny) pre: true post: true activity: (expr (atom (name self)) (trailer . (name G) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name _from)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name self)) (trailer . (name Edge) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name _to))))))) , (argument (test (logical_test (comparison (expr (atom (name _cost)))))))) ))))))))) )))) ; self._E := self._E + 1; operation shortest_path(s : OclAny) : OclAny pre: true post: true activity: skip ; var que : Sequence := Sequence{} ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ (10)->pow(15) }, self.V) ; d[s+1] := 0 ; heapq.heappush(que, Sequence{0, s}) ; while (que)->size() /= 0 do ( var cost : OclAny := null; var v : OclAny := null; Sequence{cost,v} := heapq.heappop(que) ; if (d[v+1]->compareTo(cost)) < 0 then ( continue ) else skip ; for i : Integer.subrange(0, (self.G[v+1])->size()-1) do ( var e : OclAny := self.G[v+1][i+1] ; if (d[e.to+1]->compareTo(d[v+1] + e.cost)) > 0 then ( d[e.to+1] := d[v+1] + e.cost ; heapq.heappush(que, Sequence{d[e.to+1], e.to}) ) else skip)) ; return d; } class FromPython { operation initialise() pre: true post: true activity: skip ; var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var pro : Dijkstra := (Dijkstra.newDijkstra()).initialise(K) ; for i : Integer.subrange(0, K-1) do ( execute ((i, (i + 1) mod K, 1) : pro) ; execute ((i, (10 * i) mod K, 0) : pro)) ; var ans : OclAny := pro.shortest_path(1)->first() ; execute (ans + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) while k>0 : n=int(input()) stringul=input() stringul_sortat=sorted(stringul) raspuns=0 for i in range(0,n): if stringul[i]!=stringul_sortat[i]: raspuns=raspuns+1 print(raspuns) k=k-1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while k > 0 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var stringul : String := (OclFile["System.in"]).readLine() ; var stringul_sortat : Sequence := stringul->sort() ; var raspuns : int := 0 ; for i : Integer.subrange(0, n-1) do ( if stringul[i+1] /= stringul_sortat[i+1] then ( raspuns := raspuns + 1 ) else skip) ; execute (raspuns)->display() ; k := k - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq k=int(input()) j=[0]*k for i in range(k): j[i]=[(tuple([(i*10)% k,0]))] j[i].append(tuple([(i+1)% k,1])) min_cost=[float("inf")]*k def dijkstra(s): queue=[tuple([1,s])] while queue : p=heapq.heappop(queue) for e in j[p[1]]: if p[0]+e[1]>=min_cost[e[0]]: continue min_cost[e[0]]=p[0]+e[1] heapq.heappush(queue,tuple([min_cost[e[0]],e[0]])) dijkstra(1) print(min_cost[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var j : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, k) ; for i : Integer.subrange(0, k-1) do ( j[i+1] := Sequence{ ((Sequence{(i * 10) mod k}->union(Sequence{ 0 }))) } ; (expr (atom (name j)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name tuple)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) ))) % (expr (atom (name k))))))) , (test (logical_test (comparison (expr (atom (number (integer 1)))))))) ]))))))) ))))))))) ))))) ; var min_cost : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (("inf")))->toReal() }, k) ; skip ; dijkstra(1) ; execute (min_cost->first())->display(); operation dijkstra(s : OclAny) pre: true post: true activity: var queue : Sequence := Sequence{ (Sequence{1}->union(Sequence{ s })) } ; while queue do ( var p : OclAny := heapq.heappop(queue) ; for e : j[p[1+1]+1] do ( if (p->first() + e[1+1]->compareTo(min_cost[e->first()+1])) >= 0 then ( continue ) else skip ; min_cost[e->first()+1] := p->first() + e[1+1] ; heapq.heappush(queue, (Sequence{min_cost[e->first()+1]}->union(Sequence{ e->first() }))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) readline=sys.stdin.readline k=int(input()) g=[[]for _ in range(k)] for i in range(k): g[i].append(((i+1)% k,1)) if i : g[i].append((10*i % k,0)) from collections import deque q=deque([1]) res=[float("inf")]*k res[1]=1 while q : v=q.popleft() if v==0 : break for c,d in g[v]: if res[c]<=res[v]+d : continue res[c]=res[v]+d if d : q.append(c) else : q.appendleft(c) print(res[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; var readline : OclAny := (OclFile["System.in"]).readline ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var g : Sequence := Integer.subrange(0, k-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, k-1) do ((expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) ))) % (expr (atom (name k))))))) , (test (logical_test (comparison (expr (atom (number (integer 1)))))))) )))))))) )))) ; if i then ( (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (number (integer 10)))) * (expr (atom (name i)))) % (expr (atom (name k))))))) , (test (logical_test (comparison (expr (atom (number (integer 0)))))))) )))))))) )))) ) else skip) ; skip ; var q : Sequence := (Sequence{ 1 }) ; var res : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (("inf")))->toReal() }, k) ; res[1+1] := 1 ; while q do ( var v : OclAny := q->first() ; q := q->tail() ; if v = 0 then ( break ) else skip ; for _tuple : g[v+1] do (var _indx : int := 1; var c : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); if (res[c+1]->compareTo(res[v+1] + d)) <= 0 then ( continue ) else skip ; res[c+1] := res[v+1] + d ; if d then ( execute ((c) : q) ) else ( q := q->prepend(c) ))) ; execute (res->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq K=int(input()) adj=[dict()for i in range(K)] for i in range(1,K): adj[i]=dict() adj[i][(i+1)% K]=1 adj[i][(i*10)% K]=0 def dijkstra(adj): q=[] d=dict() p=dict() n=len(adj) for i in range(n): d[i]=float('inf') start_id=1 d[start_id]=0 heapq.heappush(q,(0,start_id)) S=set() while len(S)!=n : dist,node_id=heapq.heappop(q) S.add(node_id) for u,c in adj[node_id].items(): if c+d[node_id]toInteger() ; var adj : Sequence := Integer.subrange(0, K-1)->select(i | true)->collect(i | ((arguments ( )))) ; for i : Integer.subrange(1, K-1) do ( adj[i+1] := (arguments ( )) ; adj[i+1][(i + 1) mod K+1] := 1 ; adj[i+1][(i * 10) mod K+1] := 0) ; skip ; d := dijkstra(adj) ; execute (d->first() + 1)->display(); operation dijkstra(adj : OclAny) : OclAny pre: true post: true activity: var q : Sequence := Sequence{} ; var d : Map := (arguments ( )) ; var p : Map := (arguments ( )) ; var n : int := (adj)->size() ; for i : Integer.subrange(0, n-1) do ( d[i+1] := ("" + (('inf')))->toReal()) ; var start_id : int := 1 ; d[start_id+1] := 0 ; heapq.heappush(q, Sequence{0, start_id}) ; var S : Set := Set{}->union(()) ; while (S)->size() /= n do ( var dist : OclAny := null; var node_id : OclAny := null; Sequence{dist,node_id} := heapq.heappop(q) ; execute ((node_id) : S) ; for _tuple : adj[node_id+1]->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var u : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if (c + d[node_id+1]->compareTo(d[u+1])) < 0 then ( d[u+1] := c + d[node_id+1] ; heapq.heappush(q, Sequence{d[u+1], u}) ) else skip)) ; return d; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys for e in sys.stdin : print(math.ceil(float(e)**2/98)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for e : OclFile["System.in"] do ( execute (((("" + ((e)))->toReal())->pow(2) / 98)->ceil() + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : v=float(input()) h=(v/9.8)*(v/9.8)*4.9 N=(h+5)/5 N1=(h+5)//5 if(N-N1>0): N1+=1 print(int(N1)) except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var v : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; var h : double := (v / 9.8) * (v / 9.8) * 4.9 ; var N : double := (h + 5) / 5 ; var N1 : int := (h + 5) div 5 ; if (N - N1 > 0) then ( N1 := N1 + 1 ) else skip ; execute (("" + ((N1)))->toInteger())->display()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import ceil a=9.8 h=5.0 Vmin=[float(v)for v in(sys.stdin.readlines())] for vmin in Vmin : y=a/2*vmin**2/a**2 N=int(ceil(y/h))+1 print(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var a : double := 9.8 ; var h : double := 5.0 ; var Vmin : Sequence := ((OclFile["System.in"]).readlines())->select(v | true)->collect(v | (("" + ((v)))->toReal())) ; for vmin : Vmin do ( var y : double := a / 2 * (vmin)->pow(2) / (a)->pow(2) ; var N : int := ("" + ((ceil(y / h))))->toInteger() + 1 ; execute (N)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import(division,absolute_import,print_function,unicode_literals) from sys import stdin from itertools import count for line in stdin : if not line.strip(): break H=4.9*(float(line)/9.8)**2 for N in count(1): if H<=5*N-5 : print(N) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; for line : stdin do ( if not(line->trim()) then ( break ) else skip ; var H : double := 4.9 * ((("" + ((line)))->toReal() / 9.8))->pow(2) ; for N : count(1) do ( if (H->compareTo(5 * N - 5)) <= 0 then ( execute (N)->display() ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def height(i): return 5*i-5 def time(v): return v/9.8 def y(t): return t*t*4.9 for user in sys.stdin : h=float(user) y1=y(time(h)) i=1 while True : if y1toReal() ; var y1 : OclAny := y(time(h)) ; i := 1 ; while true do ( if (y1->compareTo(height(i))) < 0 then ( execute (i)->display() ; break ) else ( i := i + 1 ))); operation height(i : OclAny) : OclAny pre: true post: true activity: return 5 * i - 5; operation time(v : OclAny) : OclAny pre: true post: true activity: return v / 9.8; operation y(t : OclAny) : OclAny pre: true post: true activity: return t * t * 4.9; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): import sys input=sys.stdin.readline sys.setrecursionlimit(10**6) n=int(input()) a=list(map(int,input().split())) a.sort() if(n % 2==0): for i in range(n-1): if i % 2==0 and a[i]!=a[i+1]or i % 2==1 and a[i]+2!=a[i+1]: print(0) exit(0) print(2**(n//2)%(10**9+7)) exit(0) if a[0]!=0 : print(0) exit(0) for i in range(1,n-1): if i % 2==0 and a[i]+2!=a[i+1]or i % 2==1 and a[i]!=a[i+1]: print(0) exit(0) print(2**((n-1)//2)%(10**9+7)) exit(0) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit((10)->pow(6)) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; if (n mod 2 = 0) then ( for i : Integer.subrange(0, n - 1-1) do ( if i mod 2 = 0 & a[i+1] /= a[i + 1+1] or i mod 2 = 1 & a[i+1] + 2 /= a[i + 1+1] then ( execute (0)->display() ; exit(0) ) else skip) ; execute ((2)->pow((n div 2)) mod ((10)->pow(9) + 7))->display() ; exit(0) ) else skip ; if a->first() /= 0 then ( execute (0)->display() ; exit(0) ) else skip ; for i : Integer.subrange(1, n - 1-1) do ( if i mod 2 = 0 & a[i+1] + 2 /= a[i + 1+1] or i mod 2 = 1 & a[i+1] /= a[i + 1+1] then ( execute (0)->display() ; exit(0) ) else skip) ; execute ((2)->pow(((n - 1) div 2)) mod ((10)->pow(9) + 7))->display() ; exit(0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : print(float(input())*211/27) except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( execute (("" + (((OclFile["System.in"]).readLine())))->toReal() * 211 / 27)->display()) catch (_e : OclException) do ( break) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): length=int(input()) s=input() k=sorted(s) f=0 for i in range(length): if s[i]!=k[i]: f+=1 print(f) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var length : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var k : Sequence := s->sort() ; var f : int := 0 ; for i : Integer.subrange(0, length-1) do ( if s[i+1] /= k[i+1] then ( f := f + 1 ) else skip) ; execute (f)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readlines=sys.stdin.readlines write=sys.stdout.write def solve(): for line in readlines(): a=float(line) s=0 for i in range(10): s+=a if i % 2 : a/=3 else : a*=2 write("%.16f\n" % s) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readlines : OclAny := (OclFile["System.in"]).readlines ; var write : OclAny := (OclFile["System.out"]).write ; skip ; solve(); operation solve() pre: true post: true activity: for line : readlines() do ( var a : double := ("" + ((line)))->toReal() ; var s : int := 0 ; for i : Integer.subrange(0, 10-1) do ( s := s + a ; if i mod 2 then ( a := a / 3 ) else ( a := a * 2 )) ; write(StringLib.format("%.16f\n",s))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,bisect PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") for line in sys.stdin : a=float(line) S=a for k in range(9): if k % 2==0 : a*=2 else : a/=3 S+=a print("%.8f" % S) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; for line : OclFile["System.in"] do ( var a : double := ("" + ((line)))->toReal() ; var S : OclAny := a ; for k : Integer.subrange(0, 9-1) do ( if k mod 2 = 0 then ( a := a * 2 ) else ( a := a / 3 ) ; S := S + a) ; execute (StringLib.format("%.8f",S))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import(division,absolute_import,print_function,unicode_literals) from sys import stdin for line in stdin : s=a=float(line) for i in xrange(2,11): if i % 2==0 : a*=2.0 else : a/=3.0 s+=a print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for line : stdin do ( var s : OclAny := ("" + ((line)))->toReal(); var a : double := ("" + ((line)))->toReal() ; for i : xrange(2, 11) do ( if i mod 2 = 0 then ( a := a * 2.0 ) else ( a := a / 3.0 ) ; s := s + a) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys for a in sys.stdin : if a=="\n" : break s=[0 for i in range(10)] s[0]=float(a) for i in range(1,10): if i % 2 : s[i]=s[i-1]*2 else : s[i]=s[i-1]/3 print(sum(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for a : OclFile["System.in"] do ( if a = "\n" then ( break ) else skip ; var s : Sequence := Integer.subrange(0, 10-1)->select(i | true)->collect(i | (0)) ; s->first() := ("" + ((a)))->toReal() ; for i : Integer.subrange(1, 10-1) do ( if i mod 2 then ( s[i+1] := s[i - 1+1] * 2 ) else ( s[i+1] := s[i - 1+1] / 3 )) ; execute ((s)->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def IfExists(arr,n): sum=[0]*n ; arr.sort(); sum[0]=arr[0]; for i in range(1,n): sum[i]=sum[i-1]+arr[i]; max=arr[n-1]; flag=False ; for i in range(1,max+1): findex=0 ; lindex=0 ; l=0 ; r=n-1 ; while(l<=r): m=(l+r)//2 ; if(arr[m]i): lindex=m ; r=m-1 ; else : l=m+1 ; if(sum[findex]==sum[n-1]-sum[lindex-1]): flag=True ; break ; if(flag): print("Yes"); else : print("No"); if __name__=="__main__" : arr=[1,2,2,5]; n=len(arr); IfExists(arr,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 5 }))); ; n := (arr)->size(); ; IfExists(arr, n); ) else skip; operation IfExists(arr : OclAny, n : OclAny) pre: true post: true activity: var sum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; arr := arr->sort(); ; ->first()->sum() := arr->first(); ; for i : Integer.subrange(1, n-1) do ( [i+1]->sum() := [i - 1+1]->sum() + arr[i+1];) ; var max : OclAny := arr[n - 1+1]; ; var flag : boolean := false; ; for i : Integer.subrange(1, max + 1-1) do ( var findex : int := 0; ; var lindex : int := 0; ; var l : int := 0; ; var r : double := n - 1; ; while ((l->compareTo(r)) <= 0) do ( var m : int := (l + r) div 2; ; if ((arr[m+1]->compareTo(i)) < 0) then ( findex := m; ; l := m + 1; ) else ( r := m - 1; )) ; l := 1; ; r := n; ; flag := false; ; while ((l->compareTo(r)) <= 0) do ( m := (r + l) div 2; ; if ((arr[m+1]->compareTo(i)) > 0) then ( lindex := m; ; r := m - 1; ) else ( l := m + 1; )) ; if ([findex+1]->sum() = [n - 1+1]->sum() - [lindex - 1+1]->sum()) then ( flag := true; ; break; ) else skip) ; if (flag) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=input().split(' ') x,y=int(l[0]),int(l[1]) if y<=0 and x>=1+y and x<=1-y : print((-y)*4) elif x>0 and y>=2-x and y<=x : print(x*4-3) elif y>0 and x>=-y and x<=y-1 : print(y*4-2) elif x<0 and y>=x and y<=-1-x : print((-x)*4-1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := input().split(' ') ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{("" + ((l->first())))->toInteger(),("" + ((l[1+1])))->toInteger()} ; if y <= 0 & (x->compareTo(1 + y)) >= 0 & (x->compareTo(1 - y)) <= 0 then ( execute ((-y) * 4)->display() ) else (if x > 0 & (y->compareTo(2 - x)) >= 0 & (y->compareTo(x)) <= 0 then ( execute (x * 4 - 3)->display() ) else (if y > 0 & (x->compareTo(-y)) >= 0 & (x->compareTo(y - 1)) <= 0 then ( execute (y * 4 - 2)->display() ) else (if x < 0 & (y->compareTo(x)) >= 0 & (y->compareTo(-1 - x)) <= 0 then ( execute ((-x) * 4 - 1)->display() ) else ( execute (0)->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=map(int,input().split()) if y>x and x>=-y : print(y*4-2) elif y-y+1 : print(x*4-3) elif y>=x and x<-y : print(-1-4*x) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (y->compareTo(x)) > 0 & (x->compareTo(-y)) >= 0 then ( execute (y * 4 - 2)->display() ) else (if (y->compareTo(x)) < 0 & (x->compareTo(-y + 1)) <= 0 then ( execute (-y * 4)->display() ) else (if (y->compareTo(x)) <= 0 & (x->compareTo(-y + 1)) > 0 then ( execute (x * 4 - 3)->display() ) else (if (y->compareTo(x)) >= 0 & (x->compareTo(-y)) < 0 then ( execute (-1 - 4 * x)->display() ) else ( execute (0)->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=map(int,input().split()) if y>x and x>=-y : print(y*4-2) elif y-y+1 : print(x*4-3) elif y>=x and x<-y : print(-1-4*x) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (y->compareTo(x)) > 0 & (x->compareTo(-y)) >= 0 then ( execute (y * 4 - 2)->display() ) else (if (y->compareTo(x)) < 0 & (x->compareTo(-y + 1)) <= 0 then ( execute (-y * 4)->display() ) else (if (y->compareTo(x)) <= 0 & (x->compareTo(-y + 1)) > 0 then ( execute (x * 4 - 3)->display() ) else (if (y->compareTo(x)) >= 0 & (x->compareTo(-y)) < 0 then ( execute (-1 - 4 * x)->display() ) else ( execute (0)->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): x,y=map(int,input().split()) rotations=0 dir="r" pos=[0,0] counter=0 inc=1 while True : if dir=="r" : if y==pos[1]and pos[0]<=x<=pos[0]+inc : break pos[0]+=inc dir="u" elif dir=="l" : if y==pos[1]and pos[0]-inc<=x<=pos[0]: break pos[0]-=inc dir="d" elif dir=="d" : if x==pos[0]and pos[1]-inc<=y<=pos[1]: break pos[1]-=inc dir="r" elif dir=="u" : if x==pos[0]and pos[1]<=y<=pos[1]+inc : break pos[1]+=inc dir="l" counter=(counter+1)% 2 if counter==0 : inc+=1 rotations+=1 print(rotations) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var rotations : int := 0 ; var dir : String := "r" ; var pos : Sequence := Sequence{0}->union(Sequence{ 0 }) ; var counter : int := 0 ; var inc : int := 1 ; while true do ( if dir = "r" then ( if y = pos[1+1] & (pos->first()->compareTo(x)) <= 0 & (x <= pos->first() + inc) then ( break ) else skip ; pos->first() := pos->first() + inc ; dir := "u" ) else (if dir = "l" then ( if y = pos[1+1] & (pos->first() - inc->compareTo(x)) <= 0 & (x <= pos->first()) then ( break ) else skip ; pos->first() := pos->first() - inc ; dir := "d" ) else (if dir = "d" then ( if x = pos->first() & (pos[1+1] - inc->compareTo(y)) <= 0 & (y <= pos[1+1]) then ( break ) else skip ; pos[1+1] := pos[1+1] - inc ; dir := "r" ) else (if dir = "u" then ( if x = pos->first() & (pos[1+1]->compareTo(y)) <= 0 & (y <= pos[1+1] + inc) then ( break ) else skip ; pos[1+1] := pos[1+1] + inc ; dir := "l" ) else skip ) ) ) ; counter := (counter + 1) mod 2 ; if counter = 0 then ( inc := inc + 1 ) else skip ; rotations := rotations + 1) ; execute (rotations)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) w=0 s=0 i=1 while n>=s : s+=((i**2/2)+(i/2)) w+=1 i+=1 print(w-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : int := 0 ; var s : int := 0 ; var i : int := 1 ; while (n->compareTo(s)) >= 0 do ( s := s + (((i)->pow(2) / 2) + (i / 2)) ; w := w + 1 ; i := i + 1) ; execute (w - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) s=input() s1=sorted(s) c=0 for i in range(n): if s[i]!=s1[i]: c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var s1 : Sequence := s->sort() ; var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( if s[i+1] /= s1[i+1] then ( c := c + 1 ) else skip) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict N=int(input()) A=list(map(int,input().split())) mod=10**9+7 counter=defaultdict(int) for a in A : counter[a]+=1 if N % 2==0 : check={i : 2 for i in range(1,N,2)} else : check={i : 2 for i in range(2,N,2)} check[0]=1 unsatisfied=False for key,val in counter.items(): temp=check.get(key,None) if temp==None or temptoInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mod : double := (10)->pow(9) + 7 ; var counter : OclAny := defaultdict(OclType["int"]) ; for a : A do ( counter[a+1] := counter[a+1] + 1) ; if N mod 2 = 0 then ( var check : Map := Integer.subrange(1, N-1)->select( $x | ($x - 1) mod 2 = 0 )->select(i | true)->collect(i | Map{i |-> 2})->unionAll() ) else ( check := Integer.subrange(2, N-1)->select( $x | ($x - 2) mod 2 = 0 )->select(i | true)->collect(i | Map{i |-> 2})->unionAll() ; check->first() := 1 ) ; var unsatisfied : boolean := false ; for _tuple : counter->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var val : OclAny := _tuple->at(_indx); var temp : OclAny := check.get(key, null) ; if temp = null or (temp->compareTo(val)) < 0 then ( unsatisfied := true ; break ) else skip) ; if unsatisfied then ( execute (0)->display() ) else ( execute ((2)->pow((N div 2)) mod mod)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=map(int,input().split()) if y>x and x>=-y : print(y*4-2) elif y-y+1 : print(x*4-3) elif y>=x and x<-y : print(-1-4*x) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (y->compareTo(x)) > 0 & (x->compareTo(-y)) >= 0 then ( execute (y * 4 - 2)->display() ) else (if (y->compareTo(x)) < 0 & (x->compareTo(-y + 1)) <= 0 then ( execute (-y * 4)->display() ) else (if (y->compareTo(x)) <= 0 & (x->compareTo(-y + 1)) > 0 then ( execute (x * 4 - 3)->display() ) else (if (y->compareTo(x)) >= 0 & (x->compareTo(-y)) < 0 then ( execute (-1 - 4 * x)->display() ) else ( execute (0)->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def avgRec(a,i,n): if i==n-1 : return a[i] if i==0 : return((a[i]+avgRec(a,i+1,n))/n) return(a[i]+avgRec(a,i+1,n)) def average(a,n): return avgRec(a,0,n) arr=[10,2,3,4,5,6,7,8,9] n=len(arr) print(average(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var arr : Sequence := Sequence{10}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 9 })))))))) ; n := (arr)->size() ; execute (average(arr, n))->display(); operation avgRec(a : OclAny, i : OclAny, n : OclAny) : OclAny pre: true post: true activity: if i = n - 1 then ( return a[i+1] ) else skip ; if i = 0 then ( return ((a[i+1] + avgRec(a, i + 1, n)) / n) ) else skip ; return (a[i+1] + avgRec(a, i + 1, n)); operation average(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: return avgRec(a, 0, n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cntSplits(s): if(s[len(s)-1]=='1'): return 0 ; c_zero=0 ; for i in range(len(s)): c_zero+=(s[i]=='0'); return int(pow(2,c_zero-1)); if __name__=="__main__" : s="10010" ; print(cntSplits(s)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "10010"; ; execute (cntSplits(s))->display(); ) else skip; operation cntSplits(s : OclAny) pre: true post: true activity: if (s[(s)->size() - 1+1] = '1') then ( return 0; ) else skip ; var c_zero : int := 0; ; for i : Integer.subrange(0, (s)->size()-1) do ( c_zero := c_zero + (s[i+1] = '0');) ; return ("" + (((2)->pow(c_zero - 1))))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,a=map(int,input().split()) if xcollect( _x | (OclType["int"])->apply(_x) ) ; if (x->compareTo(a)) < 0 then ( execute (0)->display() ) else ( execute (10)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,a=map(int,input().split()) print("10" if x>=a else "0") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var a : OclAny := null; Sequence{x,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if (x->compareTo(a)) >= 0 then "10" else "0" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- str=input() X=int(str.split()[0]) A=int(str.split()[1]) if(Xfirst())))->toInteger() ; var A : int := ("" + ((OclType["String"].split()[1+1])))->toInteger() ; if ((X->compareTo(A)) < 0) then ( var s : int := 0 ) else ( s := 10 ) ; execute (StringLib.interpolateStrings("{}", Sequence{s}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,a=map(int,input().split()) print('0')if xcollect( _x | (OclType["int"])->apply(_x) ) ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '0'))))))) )))))) if (logical_test (comparison (comparison (expr (atom (name x)))) < (comparison (expr (atom (name a)))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '10'))))))) )))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- X,A=map(int,raw_input().split()) if(Xcollect( _x | (OclType["int"])->apply(_x) ) ; if ((X->compareTo(A)) < 0) then ( execute (0)->display() ) else ( execute (10)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=int(input()) if a>=n-(n//500)*500 : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (a->compareTo(n - (n div 500) * 500)) >= 0 then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: s=s[:-1]; print(sum(x!=y for x,y in zip(s,sorted(s)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var s : OclAny := s->front(); execute (((argument (test (logical_test (comparison (comparison (expr (atom (name x)))) != (comparison (expr (atom (name y))))))) (comp_for for (exprlist (expr (atom (name x))) , (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s))))))) , (argument (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))))) )))))))))->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(["Yes","No"][int(input())% 500>int(input())]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (Sequence{"Yes"}->union(Sequence{ "No" })->select((("" + (((OclFile["System.in"]).readLine())))->toInteger() mod 500->compareTo(("" + (((OclFile["System.in"]).readLine())))->toInteger())) > 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=set() for i in range(n): s=input()+"0" for i in range(len(s)-1): l.add(s[i]) l.add(s[i]+s[i+1]) m="abcdefghijklmnopqrstuvwxyz" k=[*m] for i in m : for j in m : k+=[i+j] for i in k : if i not in l : exit(print(i)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() + "0" ; for i : Integer.subrange(0, (s)->size() - 1-1) do ( execute ((s[i+1]) : l) ; execute ((s[i+1] + s[i + 1+1]) : l))) ; var m : String := "abcdefghijklmnopqrstuvwxyz" ; var k : Sequence := m ; for i : m->characters() do ( for j : m->characters() do ( k := k + Sequence{ i + j })) ; for i : k do ( if (l)->excludes(i) then ( exit((i)->display()) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a=[int(input())for _ in range(2)] print('Yes' if n % 500<=a else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := Integer.subrange(0, 2-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; execute (if (n mod 500->compareTo(a)) <= 0 then 'Yes' else 'No' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=int(input()) x=n % 500 if x!=0 : if x<=a : print('Yes') else : print('No') else : print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := n mod 500 ; if x /= 0 then ( if (x->compareTo(a)) <= 0 then ( execute ('Yes')->display() ) else ( execute ('No')->display() ) ) else ( execute ('Yes')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=int(input()) if(499<=A): print('Yes') else : if(N % 500<=A): print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (499 <= A) then ( execute ('Yes')->display() ) else ( if ((N mod 500->compareTo(A)) <= 0) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin if __name__=='__main__' : n=stdin.readline() l=stdin.readline() s=l.split('')[0] t=l.split('')[1] ans='' sw=0 for i in range(len(s)): ans+=s[i] ans+=t[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var n : String := stdin.readLine() ; var l : String := stdin.readLine() ; var s : OclAny := l.split('')->first() ; var t : OclAny := l.split('')[1+1] ; var ans : String := '' ; var sw : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( ans := ans + s[i+1] ; ans := ans + t[i+1]) ; execute (ans)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s,t=[_ for _ in input().split()] for e in zip(s,t): print(''.join(e),end='') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := input().split()->select(_anon | true)->collect(_anon | (_anon)) ; for e : Integer.subrange(1, s->size())->collect( _indx | Sequence{s->at(_indx), t->at(_indx)} ) do ( execute (StringLib.sumStringsWithSeparator((e), ''))->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(a,b): ch="" N=len(a) for i in range(N): ch+=a[i]+b[i] return ch N=int(input()) a,b=map(str,input().split()) print(f(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; Sequence{a,b} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; execute (f(a, b))->display(); operation f(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var ch : String := "" ; var N : int := (a)->size() ; for i : Integer.subrange(0, N-1) do ( ch := ch + a[i+1] + b[i+1]) ; return ch; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s,t=input().split() a="".join(i+j for i,j in zip(s,t)) print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := input().split() ; var a : String := StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name j))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s))))))) , (argument (test (logical_test (comparison (expr (atom (name t)))))))) ))))))))), "") ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s,t=map(str,input().split()) l=[] for i in range(n): l.append(s[i]) l.append(t[i]) ans=''.join(l) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((s[i+1]) : l) ; execute ((t[i+1]) : l)) ; var ans : String := StringLib.sumStringsWithSeparator((l), '') ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumAP(n,d): n=int(n/d); return(n)*(1+n)*(d/2); def sumMultiples(n): n-=1 ; return(int(sumAP(n,2)+sumAP(n,5)-sumAP(n,10))); n=20 ; print(sumMultiples(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 20; ; execute (sumMultiples(n))->display();; operation sumAP(n : OclAny, d : OclAny) pre: true post: true activity: n := ("" + ((n / d)))->toInteger(); ; return (n) * (1 + n) * (d / 2);; operation sumMultiples(n : OclAny) pre: true post: true activity: n := n - 1; ; return (("" + ((sumAP(n, 2) + sumAP(n, 5) - sumAP(n, 10))))->toInteger());; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) a=[i-1 for i in a] b=list(map(int,input().split())) c=list(map(int,input().split())) ans=0 for i,v in enumerate(a): ans+=b[v] if i!=n-1 : if a[i]+1==a[i+1]: ans+=c[v] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->select(i | true)->collect(i | (i - 1)) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); ans := ans + b[v+1] ; if i /= n - 1 then ( if a[i+1] + 1 = a[i + 1+1] then ( ans := ans + c[v+1] ) else skip ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines import numpy as np def main(): N,*ABC=map(int,read().split()) A=ABC[: N] B=ABC[N : 2*N] C=ABC[2*N :] ans=sum(B) for i in range(N-1): if A[i]==A[i+1]-1 : ans+=C[A[i]-1] print(ans) return if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var ABC : OclAny := null; Sequence{N,ABC} := (read().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : OclAny := ABC.subrange(1,N) ; var B : OclAny := ABC.subrange(N+1, 2 * N) ; var C : OclAny := ABC.subrange(2 * N+1) ; var ans : OclAny := (B)->sum() ; for i : Integer.subrange(0, N - 1-1) do ( if A[i+1] = A[i + 1+1] - 1 then ( ans := ans + C[A[i+1] - 1+1] ) else skip) ; execute (ans)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ch="" while(n): sh=input() ch+=' '+sh n-=1 l=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] t=False for x in l : if x not in ch : t=True print(x) break if not t : for i in range(len(l)): if not t : for j in range(len(l)): s=l[i]+l[j] if s not in ch : print(s) t=True break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ch : String := "" ; while (n) do ( var sh : String := (OclFile["System.in"]).readLine() ; ch := ch + ' ' + sh ; n := n - 1) ; var l : Sequence := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{'c'}->union(Sequence{'d'}->union(Sequence{'e'}->union(Sequence{'f'}->union(Sequence{'g'}->union(Sequence{'h'}->union(Sequence{'i'}->union(Sequence{'j'}->union(Sequence{'k'}->union(Sequence{'l'}->union(Sequence{'m'}->union(Sequence{'n'}->union(Sequence{'o'}->union(Sequence{'p'}->union(Sequence{'q'}->union(Sequence{'r'}->union(Sequence{'s'}->union(Sequence{'t'}->union(Sequence{'u'}->union(Sequence{'v'}->union(Sequence{'w'}->union(Sequence{'x'}->union(Sequence{'y'}->union(Sequence{ 'z' }))))))))))))))))))))))))) ; var t : boolean := false ; for x : l do ( if (ch)->characters()->excludes(x) then ( t := true ; execute (x)->display() ; break ) else skip) ; if not(t) then ( for i : Integer.subrange(0, (l)->size()-1) do ( if not(t) then ( for j : Integer.subrange(0, (l)->size()-1) do ( var s : OclAny := l[i+1] + l[j+1] ; if (ch)->characters()->excludes(s) then ( execute (s)->display() ; t := true ; break ) else skip) ) else skip) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def LI(): return list(map(int,sys.stdin.readline().split())) N=int(input()) A=LI() B=LI() C=LI() res=0 for i in range(N): res+=B[A[i]-1] if itoInteger() ; var A : OclAny := LI() ; var B : OclAny := LI() ; var C : OclAny := LI() ; var res : int := 0 ; for i : Integer.subrange(0, N-1) do ( res := res + B[A[i+1] - 1+1] ; if (i->compareTo(N - 1)) < 0 & A[i + 1+1] = A[i+1] + 1 then ( res := res + C[A[i+1] - 1+1] ) else skip) ; execute (res)->display(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(i)for i in str(input()).split(" ")] b=[int(i)for i in str(input()).split(" ")] c=[int(i)for i in str(input()).split(" ")] r=0 for i in range(n): r=r+b[a[i]-1] if i!=0 and(a[i-1]+1)==a[i]: r=r+c[a[i]-1-1] print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := OclType["String"]((OclFile["System.in"]).readLine()).split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var b : Sequence := OclType["String"]((OclFile["System.in"]).readLine()).split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var c : Sequence := OclType["String"]((OclFile["System.in"]).readLine()).split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var r : int := 0 ; for i : Integer.subrange(0, n-1) do ( r := r + b[a[i+1] - 1+1] ; if i /= 0 & (a[i - 1+1] + 1) = a[i+1] then ( r := r + c[a[i+1] - 1 - 1+1] ) else skip) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().rstrip().split())) b=list(map(int,input().rstrip().split())) c=list(map(int,input().rstrip().split())) a.insert(0,0) b.insert(0,0) c.insert(0,0) sum1=0 sum1+=b[a[1]] for i in range(2,n+1): if a[i]==a[i-1]+1 : sum1+=b[a[i]] sum1+=c[a[i-1]] else : sum1+=b[a[i]] print(sum1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : Sequence := ((input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a.insertAt(0+1, 0) ; b := b.insertAt(0+1, 0) ; c := c.insertAt(0+1, 0) ; var sum1 : int := 0 ; sum1 := sum1 + b[a[1+1]+1] ; for i : Integer.subrange(2, n + 1-1) do ( if a[i+1] = a[i - 1+1] + 1 then ( sum1 := sum1 + b[a[i+1]+1] ; sum1 := sum1 + c[a[i - 1+1]+1] ) else ( sum1 := sum1 + b[a[i+1]+1] )) ; execute (sum1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()); print(b+(c,b+a+1)[a+bcollect( _x | (OclType["int"])->apply(_x) ); execute (b + Sequence{c, b + a + 1}->select((a + b->compareTo(c)) < 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- instr=input() A,B,C=map(int,instr.split(" ")) score=0 if B0 : score+=1 C-=1 else : score+=C C=0 A-=C else : score+=B+C B=C=0 print(score) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var instr : String := (OclFile["System.in"]).readLine() ; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{A,B,C} := (instr.split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var score : int := 0 ; if (B->compareTo(C)) < 0 then ( score := score + 2 * B ; C := C - B ; var B : int := 0 ; if (A->compareTo(C)) <= 0 then ( score := score + A ; C := C - A ; var A : int := 0 ; if C > 0 then ( score := score + 1 ; C := C - 1 ) else skip ) else ( score := score + C ; var C : int := 0 ; A := A - C ) ) else ( score := score + B + C ; B := 0; C := 0 ) ; execute (score)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import os if sys.platform=="darwin" : base=os.path.dirname(os.path.abspath(__file__)) name=os.path.normpath(os.path.join(base,'../Documents/input.txt')) sys.stdin=open(name) a,b,c=map(int,input().split()) ans=0 if a+b>=c : print(b+c) exit() if a>=c : print(b+c) exit() else : ans=ans+a c=c-a if c==b : ans=ans+2*b elif ccollect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; if (a + b->compareTo(c)) >= 0 then ( execute (b + c)->display() ; exit() ) else skip ; if (a->compareTo(c)) >= 0 then ( execute (b + c)->display() ; exit() ) else ( ans := ans + a ; var c : double := c - a ; if c = b then ( ans := ans + 2 * b ) else (if (c->compareTo(b)) < 0 then ( ans := b + c ) else ( ans := ans + 2 * b + 1 ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin sys.setrecursionlimit(10**7) ri=lambda : int(rs()) rl=lambda : list(map(int,stdin.readline().split())) rs=lambda : stdin.readline().rstrip() A,B,C=rl() cookie=min(A+B,C) C-=cookie cookie+=B if C>0 : cookie+=1 print(cookie) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stdin : OclFile := OclFile["System.in"] ; sys.setrecursionlimit((10)->pow(7)) ; var ri : Function := lambda $$ : OclAny in (("" + ((rs())))->toInteger()) ; var rl : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var rs : Function := lambda $$ : OclAny in (stdin.readLine().rstrip()) ; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{A,B,C} := rl->apply() ; var cookie : OclAny := Set{A + B, C}->min() ; C := C - cookie ; cookie := cookie + B ; if C > 0 then ( cookie := cookie + 1 ) else skip ; execute (cookie)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count9s(number): n=len(number) d=[0 for i in range(9)] d[0]=1 result=0 mod_sum=0 continuous_zero=0 for i in range(n): if(ord(number[i])-ord('0')==0): continuous_zero+=1 else : continuous_zero=0 mod_sum+=ord(number[i])-ord('0') mod_sum %=9 result+=d[mod_sum] d[mod_sum]+=1 result-=continuous_zero return result if __name__=='__main__' : print(count9s("01809")) print(count9s("1809")) print(count9s("4189")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( execute (count9s("01809"))->display() ; execute (count9s("1809"))->display() ; execute (count9s("4189"))->display() ) else skip; operation count9s(number : OclAny) : OclAny pre: true post: true activity: var n : int := (number)->size() ; var d : Sequence := Integer.subrange(0, 9-1)->select(i | true)->collect(i | (0)) ; d->first() := 1 ; var result : int := 0 ; var mod_sum : int := 0 ; var continuous_zero : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ((number[i+1])->char2byte() - ('0')->char2byte() = 0) then ( continuous_zero := continuous_zero + 1 ) else ( continuous_zero := 0 ) ; mod_sum := mod_sum + (number[i+1])->char2byte() - ('0')->char2byte() ; mod_sum := mod_sum mod 9 ; result := result + d[mod_sum+1] ; d[mod_sum+1] := d[mod_sum+1] + 1 ; result := result - continuous_zero) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : while True : L,R=list(map(int,input().strip().split())) if L==0 and R==0 : break arr=set([0]) if L>0 : arr.update(list(map(int,input().strip().split(' ')))) if R>0 : arr.update(list(map(int,input().strip().split(' ')))) arr=sorted(list(arr)) maxi=-9999999999 for i in range(len(arr)-1): maxi=max(maxi,arr[i+1]-arr[i]) print(maxi) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( while true do ( var L : OclAny := null; var R : OclAny := null; Sequence{L,R} := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if L = 0 & R = 0 then ( break ) else skip ; var arr : Set := Set{}->union((Sequence{ 0 })) ; if L > 0 then ( execute ((((input()->trim().split(' '))->collect( _x | (OclType["int"])->apply(_x) ))) <: arr) ) else skip ; if R > 0 then ( execute ((((input()->trim().split(' '))->collect( _x | (OclType["int"])->apply(_x) ))) <: arr) ) else skip ; arr := (arr)->sort() ; var maxi : int := -9999999999 ; for i : Integer.subrange(0, (arr)->size() - 1-1) do ( maxi := Set{maxi, arr[i + 1+1] - arr[i+1]}->max()) ; execute (maxi)->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=lambda : stdin.readline().strip() lin=lambda : list(map(int,input().split())) iin=lambda : int(input()) main=lambda : map(int,input().split()) from math import ceil,sqrt,factorial,log from collections import deque from bisect import bisect_left mod=998244353 def moduloinverse(a): return(pow(a,mod-2,mod)) def solve(we): n=iin() l=lin() l.sort() n_fac=0 n_fac2=1 for i in range(1,2*n+1): n_fac2=(n_fac2*i)% mod if i==n : n_fac=n_fac2 t=moduloinverse(n_fac) z=(((n_fac2*t)% mod)*t)% mod ans=0 for i in range(2*n): if itrim()) ; var lin : Function := lambda $$ : OclAny in (((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var iin : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var main : Function := lambda $$ : OclAny in ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; skip ; skip ; var mod : int := 998244353 ; skip ; skip ; var qwe : int := 1 ; for _anon : Integer.subrange(0, qwe-1) do ( solve(_anon + 1)); operation moduloinverse(a : OclAny) : OclAny pre: true post: true activity: return ((a)->pow(mod - 2)); operation solve(we : OclAny) pre: true post: true activity: var n : OclAny := iin->apply() ; var l : OclAny := lin->apply() ; l := l->sort() ; var n_fac : int := 0 ; var n_fac2 : int := 1 ; for i : Integer.subrange(1, 2 * n + 1-1) do ( n_fac2 := (n_fac2 * i) mod mod ; if i = n then ( n_fac := n_fac2 ) else skip) ; var t : OclAny := moduloinverse(n_fac) ; var z : int := (((n_fac2 * t) mod mod) * t) mod mod ; var ans : int := 0 ; for i : Integer.subrange(0, 2 * n-1) do ( if (i->compareTo(n)) < 0 then ( ans := (ans - (l[i+1] * z) mod mod) mod mod ) else ( ans := (ans + (l[i+1] * z) mod mod) mod mod )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : t=int(input()) if t==0 : break n=int(input()) for i in range(n): s,f=map(int,input().split()) t-=f-s if t<1 : print("OK") else : print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if t = 0 then ( break ) else skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var s : OclAny := null; var f : OclAny := null; Sequence{s,f} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; t := t - f - s) ; if t < 1 then ( execute ("OK")->display() ) else ( execute (t)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=[int(i)for i in input().split()] ans=0 if c+1<=b+a : ans=c+b else : if aselect(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : int := 0 ; if (c + 1->compareTo(b + a)) <= 0 then ( ans := c + b ) else ( if (a->compareTo(c - b)) < 0 then ( ans := 2 * b + a + 1 ) else ( ans := 2 * b + a ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==1 : b=0 else : b=(n*(n-1))//2 print(b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( var b : int := 0 ) else ( b := (n * (n - 1)) div 2 ) ; execute (b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def resolve(): n=int(input()) ans=((n-1)+(n-1)**2)//2 print(ans) if __name__=="__main__" : resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( resolve() ) else skip; operation resolve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := ((n - 1) + ((n - 1))->pow(2)) div 2 ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import string n=int(input()) d={} s="" for _ in range(n): s+=input()+" " a=string.ascii_lowercase for x in a : if x not in s : print(x) exit() for x in a : for y in a : if x+y not in s : print(x+y) exit() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : OclAny := Set{} ; var s : String := "" ; for _anon : Integer.subrange(0, n-1) do ( s := s + (OclFile["System.in"]).readLine() + " ") ; var a : OclAny := string.ascii_lowercase ; for x : a do ( if (s)->characters()->excludes(x) then ( execute (x)->display() ; exit() ) else skip) ; for x : a do ( for y : a do ( if (s)->characters()->excludes(x + y) then ( execute (x + y)->display() ; exit() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- gi=lambda : list(map(int,input().split())) n,=gi() print((n*(n-1))//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var gi : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,)} := gi->apply() ; execute ((n * (n - 1)) div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin N=int(stdin.readline().rstrip()) sum_=N*(N+1) sum_=sum_//2 print((sum_-N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + ((stdin.readLine().rstrip())))->toInteger() ; var sum_ : int := N * (N + 1) ; sum_ := sum_ div 2 ; execute ((sum_ - N))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print((n+1)*n//2-n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((n + 1) * n div 2 - n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) H=list(map(int,input().split())) ans=0 for i in range(N-1): while True : if H[i]<=0 : break base=H[i] for j in range(i+1,N): if H[j]<=0 : break if base<=H[j]: H[j]-=1 else : break H[i]-=1 ans+=1 ans+=max(0,H[-1]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var H : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(0, N - 1-1) do ( while true do ( if H[i+1] <= 0 then ( break ) else skip ; var base : OclAny := H[i+1] ; for j : Integer.subrange(i + 1, N-1) do ( if H[j+1] <= 0 then ( break ) else skip ; if (base->compareTo(H[j+1])) <= 0 then ( H[j+1] := H[j+1] - 1 ) else ( break )) ; H[i+1] := H[i+1] - 1 ; ans := ans + 1)) ; ans := ans + Set{0, H->last()}->max() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import numpy as np stdin=sys.stdin def ns(): return stdin.readline().rstrip() def ni(): return int(stdin.readline().rstrip()) def nm(): return map(int,stdin.readline().split()) def nl(): return list(map(int,stdin.readline().split())) def main(): n=ni() H=nl() ans=0 while not all([h==0 for h in H]): if len(set(H))==1 : ans+=H[0] H=[0]*n else : h_max=max(H) prev=-10 for i in range(n): if H[i]==h_max : if prev!=i-1 : ans+=1 prev=i H[i]-=1 print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var stdin : OclFile := OclFile["System.in"] ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation ns() : OclAny pre: true post: true activity: return stdin.readLine().rstrip(); operation ni() : OclAny pre: true post: true activity: return ("" + ((stdin.readLine().rstrip())))->toInteger(); operation nm() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation nl() : OclAny pre: true post: true activity: return ((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation main() pre: true post: true activity: var n : OclAny := ni() ; var H : OclAny := nl() ; var ans : int := 0 ; while not((H->select(h | true)->collect(h | (h = 0)))->forAll( _x | _x = true )) do ( if (Set{}->union((H)))->size() = 1 then ( ans := ans + H->first() ; H := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ) else ( var h_max : OclAny := (H)->max() ; var prev : int := -10 ; for i : Integer.subrange(0, n-1) do ( if H[i+1] = h_max then ( if prev /= i - 1 then ( ans := ans + 1 ) else skip ; prev := i ; H[i+1] := H[i+1] - 1 ) else skip) )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _=int(input()) first=list(map(int,input().split())) count=0 def water(base_list): global count count+=1 separated=[] each=[] for i in base_list : hoge=i-1 if hoge==0 : separated.append(each) each=[] else : each.append(hoge) if each : separated.append(each) new_separated=[] for i in separated : if i : new_separated.append(i) if new_separated : for i in new_separated : water(i) else : return def plus_one(i): return i+1 first=list(map(plus_one,first)) water(first) print(count-1) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute count : OclAny; operation initialise() pre: true post: true activity: var _anon : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var first : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : int := 0 ; skip ; skip ; first := ((first)->collect( _x | (plus_one)->apply(_x) )) ; water(first) ; execute (count - 1)->display(); operation water(base_list : OclAny) pre: true post: true activity: skip ; count := count + 1 ; var separated : Sequence := Sequence{} ; var each : Sequence := Sequence{} ; for i : base_list do ( var hoge : double := i - 1 ; if hoge = 0 then ( execute ((each) : separated) ; each := Sequence{} ) else ( execute ((hoge) : each) )) ; if each then ( execute ((each) : separated) ) else skip ; var new_separated : Sequence := Sequence{} ; for i : separated do ( if i then ( execute ((i) : new_separated) ) else skip) ; if new_separated then ( for i : new_separated do ( water(i)) ) else ( return ); operation plus_one(i : OclAny) : OclAny pre: true post: true activity: return i + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=map(int,input().split()) x=[] m=0 q=0 x=input().split() for i in range(len(x)): x[i]=int(x[i]) for a in range(len(x)-1): if x[a]>=x[a+1]: q=int((x[a]-x[a+1])/d+1) m=m+q x[a+1]=x[a+1]+q*d print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := Sequence{} ; var m : int := 0 ; var q : int := 0 ; x := input().split() ; for i : Integer.subrange(0, (x)->size()-1) do ( x[i+1] := ("" + ((x[i+1])))->toInteger()) ; for a : Integer.subrange(0, (x)->size() - 1-1) do ( if (x[a+1]->compareTo(x[a + 1+1])) >= 0 then ( q := ("" + (((x[a+1] - x[a + 1+1]) / d + 1)))->toInteger() ; m := m + q ; x[a + 1+1] := x[a + 1+1] + q * d ) else skip) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**5+10) def input(): return sys.stdin.readline().strip() def resolve(): N=int(input()) h=list(map(int,input().split())) res=0 while True : if max(h)==0 : break i=0 while ipow(5) + 10) ; skip ; skip ; resolve(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation resolve() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var h : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : int := 0 ; while true do ( if (h)->max() = 0 then ( break ) else skip ; var i : int := 0 ; while (i->compareTo(N)) < 0 do ( if h[i+1] = 0 then ( i := i + 1 ; continue ) else ( res := res + 1 ; while (i->compareTo(N)) < 0 & h[i+1] /= 0 do ( h[i+1] := h[i+1] - 1 ; i := i + 1) ))) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def mizuyari2(row): cnt=0 _min=min(row) cnt+=_min row2=[i-_min for i in row] res=[[]] for e in row2 : if e!=0 : res[-1].append(e) else : res.append([]) return cnt,res def mizuyari(ll): cnt=0 for l in ll : if l : cnt2,hs=mizuyari2(l) cnt+=cnt2 cnt+=mizuyari(hs) return cnt def main2(): n=int(input()) hs=[int(i)for i in input().split()] hs=[hs] cnt=mizuyari(hs) print(cnt) if __name__=='__main__' : main2() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main2() ) else skip; operation mizuyari2(row : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; var _min : OclAny := (row)->min() ; cnt := cnt + _min ; var row2 : Sequence := row->select(i | true)->collect(i | (i - _min)) ; var res : Sequence := Sequence{ Sequence{} } ; for e : row2 do ( if e /= 0 then ( (expr (atom (name res)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name e)))))))) )))) ) else ( execute ((Sequence{}) : res) )) ; return cnt, res; operation mizuyari(ll : OclAny) : OclAny pre: true post: true activity: cnt := 0 ; for l : ll do ( if l then ( var cnt2 : OclAny := null; var hs : OclAny := null; Sequence{cnt2,hs} := mizuyari2(l) ; cnt := cnt + cnt2 ; cnt := cnt + mizuyari(hs) ) else skip) ; return cnt; operation main2() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var hs : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; hs := Sequence{ hs } ; cnt := mizuyari(hs) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) if n<=12 : print(2**n) else : print(8092*2**(n-13)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n <= 12 then ( execute ((2)->pow(n))->display() ) else ( execute (8092 * (2)->pow((n - 13)))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(int(2**n-(n>12)*2**(n-13)*100)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (("" + (((2)->pow(n) - (n > 12) * (2)->pow((n - 13)) * 100)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lis=[] ss='abcdefghijklmnopqrstuvwxyz' for i in range(n): s=input() lis.append(s) k=1 for i in range(26): ser=ss[i] k=0 for j in lis : if ser not in j : k+=1 if k==n : print(ser) exit() for i in range(26): for j in range(26): ser=ss[i]+ss[j] k=0 for t in lis : if ser not in t : k+=1 if k==n : print(ser) exit() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lis : Sequence := Sequence{} ; var ss : String := 'abcdefghijklmnopqrstuvwxyz' ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; execute ((s) : lis)) ; var k : int := 1 ; for i : Integer.subrange(0, 26-1) do ( var ser : OclAny := ss[i+1] ; k := 0 ; for j : lis do ( if (j)->excludes(ser) then ( k := k + 1 ) else skip) ; if k = n then ( execute (ser)->display() ; exit() ) else skip) ; for i : Integer.subrange(0, 26-1) do ( for j : Integer.subrange(0, 26-1) do ( ser := ss[i+1] + ss[j+1] ; k := 0 ; for t : lis do ( if (t)->excludes(ser) then ( k := k + 1 ) else skip) ; if k = n then ( execute (ser)->display() ; exit() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8092,16184,32368,64736,129472,258944,517888,1035776,2071552,4143104,8286208,16572416,33144832,66289664,132579328,265158656,530317312,1060634624,2121269248,4242538496,8485076992,16970153984,33940307968] print(a[int(input())]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{8}->union(Sequence{16}->union(Sequence{32}->union(Sequence{64}->union(Sequence{128}->union(Sequence{256}->union(Sequence{512}->union(Sequence{1024}->union(Sequence{2048}->union(Sequence{4096}->union(Sequence{8092}->union(Sequence{16184}->union(Sequence{32368}->union(Sequence{64736}->union(Sequence{129472}->union(Sequence{258944}->union(Sequence{517888}->union(Sequence{1035776}->union(Sequence{2071552}->union(Sequence{4143104}->union(Sequence{8286208}->union(Sequence{16572416}->union(Sequence{33144832}->union(Sequence{66289664}->union(Sequence{132579328}->union(Sequence{265158656}->union(Sequence{530317312}->union(Sequence{1060634624}->union(Sequence{2121269248}->union(Sequence{4242538496}->union(Sequence{8485076992}->union(Sequence{16970153984}->union(Sequence{ 33940307968 }))))))))))))))))))))))))))))))))))) ; execute (a[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(2**n-(100*pow(2,n-13)if n>=13 else 0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((2)->pow(n) - (if n >= 13 then 100 * (2)->pow(n - 13) else 0 endif))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n<13 : print(2**n) else : val=2**(n-13) print(2**n-val*100) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n < 13 then ( execute ((2)->pow(n))->display() ) else ( var val : double := (2)->pow((n - 13)) ; execute ((2)->pow(n) - val * 100)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) print(c-a+b if c-a+b>0 else 0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if c - a + b > 0 then c - a + b else 0 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.readline().rstrip() if __name__=="__main__" : a,b,c=map(int,input().split()) ans=c-(a-b) if ans>0 : print(c-(a-b)) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : double := c - (a - b) ; if ans > 0 then ( execute (c - (a - b))->display() ) else ( execute (0)->display() ) ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNumberOfEvenCells(n,q,size): row=[0]*n ; col=[0]*n for i in range(size): x=q[i][0]; y=q[i][1]; row[x-1]+=1 ; col[y-1]+=1 ; r1=0 ; r2=0 ; c1=0 ; c2=0 ; for i in range(n): if(row[i]% 2==0): r1+=1 ; if(row[i]% 2==1): r2+=1 ; if(col[i]% 2==0): c1+=1 ; if(col[i]% 2==1): c2+=1 ; count=r1*c1+r2*c2 ; return count ; if __name__=="__main__" : n=2 ; q=[[1,1],[1,2],[2,1]]; size=len(q); print(findNumberOfEvenCells(n,q,size)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 2; ; q := Sequence{Sequence{1}->union(Sequence{ 1 })}->union(Sequence{Sequence{1}->union(Sequence{ 2 })}->union(Sequence{ Sequence{2}->union(Sequence{ 1 }) })); ; size := (q)->size(); ; execute (findNumberOfEvenCells(n, q, size))->display(); ) else skip; operation findNumberOfEvenCells(n : OclAny, q : OclAny, size : OclAny) pre: true post: true activity: var row : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; var col : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, size-1) do ( var x : OclAny := q[i+1]->first(); ; var y : OclAny := q[i+1][1+1]; ; row[x - 1+1] := row[x - 1+1] + 1; ; col[y - 1+1] := col[y - 1+1] + 1;) ; var r1 : int := 0; ; var r2 : int := 0; ; var c1 : int := 0; ; var c2 : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (row[i+1] mod 2 = 0) then ( r1 := r1 + 1; ) else skip ; if (row[i+1] mod 2 = 1) then ( r2 := r2 + 1; ) else skip ; if (col[i+1] mod 2 = 0) then ( c1 := c1 + 1; ) else skip ; if (col[i+1] mod 2 = 1) then ( c2 := c2 + 1; ) else skip) ; var count : int := r1 * c1 + r2 * c2; ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=[int(x)for x in input().split(' ')] result=max(c-a+b,0) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var result : OclAny := Set{c - a + b, 0}->max() ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B,C=map(int,input().split()) if(B+C<=A): print("0") else : print(B+C-A) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{A,B,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if ((B + C->compareTo(A)) <= 0) then ( execute ("0")->display() ) else ( execute (B + C - A)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B,C=map(int,input().split()) X=A-B Y=C-X if Y<0 : Y=0 print(Y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{A,B,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var X : double := A - B ; var Y : double := C - X ; if Y < 0 then ( Y := 0 ) else skip ; execute (Y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,T=input().split() f=input().replace('n',n).replace('^','**') TL=1000000000 t=eval('{}*({})'.format(T,f)) print(t if t<=TL else 'TLE') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var T : OclAny := null; Sequence{n,T} := input().split() ; var f : OclAny := input().replace('n', n).replace('^', '**') ; var TL : int := 1000000000 ; var t : OclAny := StringLib.interpolateStrings('{}*({})', Sequence{T, f}) ; execute (if (t->compareTo(TL)) <= 0 then t else 'TLE' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=map(int,input().split()) F=list(input()) total=0 while F!=[]: tmp=F.pop(0) if F==[]: total+=n elif tmp=="n" : p=F.pop(0) if p=="^" : num=F.pop(0) total+=pow(n,int(num)) else : total+=n time=total*t if time>1000000000 : print("TLE") else : print(time) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var F : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var total : int := 0 ; while F /= Sequence{} do ( var tmp : OclAny := F->at(0`firstArg+1) ; F := F->excludingAt(0+1) ; if F = Sequence{} then ( total := total + n ) else (if tmp = "n" then ( var p : OclAny := F->at(0`firstArg+1) ; F := F->excludingAt(0+1) ; if p = "^" then ( var num : OclAny := F->at(0`firstArg+1) ; F := F->excludingAt(0+1) ; total := total + (n)->pow(("" + ((num)))->toInteger()) ) else ( total := total + n ) ) else skip)) ; var time : double := total * t ; if time > 1000000000 then ( execute ("TLE")->display() ) else ( execute (time)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import* from functools import* from bisect import* from itertools import* from heapq import* import sys inf=float('inf') ninf=-float('inf') ip=sys.stdin.readline alphal="abcdefghijklmnopqrstuvwxyz" alphau="ABCDEFGHIJKLMNOPQRSTUVWXYZ" mod=(10**9)+7 def ipl(): return list(map(int,ip().split())) def ipn(): return int(ip()) def ipf(): return float(ip()) def solve(): n=ipn() l="" for _ in range(n): l+=ip()+"_" for i in alphal : if i not in l : print(i) break else : for i in alphal : for j in alphal : if i+j not in l : print(i+j) return t=1 for _ in range(t): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; var ninf : double := -("" + (('inf')))->toReal() ; var ip : OclAny := (OclFile["System.in"]).readline ; var alphal : String := "abcdefghijklmnopqrstuvwxyz" ; var alphau : String := "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; var mod : double := ((10)->pow(9)) + 7 ; skip ; skip ; skip ; skip ; var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solve()); operation ipl() : OclAny pre: true post: true activity: return ((ip().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ipn() : OclAny pre: true post: true activity: return ("" + ((ip())))->toInteger(); operation ipf() : OclAny pre: true post: true activity: return ("" + ((ip())))->toReal(); operation solve() pre: true post: true activity: var n : OclAny := ipn() ; var l : String := "" ; for _anon : Integer.subrange(0, n-1) do ( l := l + ip() + "_") ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name alphal))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name i)))) not in (comparison (expr (atom (name l))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name alphal))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name alphal))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name i))) + (expr (atom (name j))))) not in (comparison (expr (atom (name l))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name j))))))))) )))))))))))) (stmt (simple_stmt (small_stmt return))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=map(int,input().split()) S=input() S="({})*t".format(S.replace("^","**")) time=eval(S) if time>10**9 : print("TLE") else : print(time) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : String := (OclFile["System.in"]).readLine() ; S := StringLib.interpolateStrings("({})*t", Sequence{S.replace("^", "**")}) ; var time : OclAny := S ; if (time->compareTo((10)->pow(9))) > 0 then ( execute ("TLE")->display() ) else ( execute (time)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=map(int,input().split()) s=sum(n**int(x[-1])for x in input().split('+'))*t print([s,'TLE'][s>1e9]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : double := ((argument (test (logical_test (comparison (expr (expr (atom (name n))) ** (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))))) )))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '+'))))))) )))))))))->sum() * t ; execute (Sequence{s}->union(Sequence{ 'TLE' })->select(s > ("1e9")->toReal()))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,T=map(int,input().split()) s=input() ans=0 for c in s : if c<='9' and c>='0' : ans=ans+pow(n,ord(c)-ord('0')) ans=ans*T if ans<=1000000000 : print(ans) else : print("TLE") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var T : OclAny := null; Sequence{n,T} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; for c : s->characters() do ( if c <= '9' & c >= '0' then ( ans := ans + (n)->pow((c)->char2byte() - ('0')->char2byte()) ) else skip) ; ans := ans * T ; if ans <= 1000000000 then ( execute (ans)->display() ) else ( execute ("TLE")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def avoidObstacles(obs): obs=sorted(obs) jump_dist=1 obstacle_hit=True while(obstacle_hit): obstacle_hit=False jump_dist+=1 for i in range(0,len(obs)): if obs[i]% jump_dist==0 : obstacle_hit=True break return jump_dist a=[5,3,6,7,9] b=avoidObstacles(a) print(b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : Sequence := Sequence{5}->union(Sequence{3}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 9 })))) ; var b : OclAny := avoidObstacles(a) ; execute (b)->display(); operation avoidObstacles(obs : OclAny) : OclAny pre: true post: true activity: obs := obs->sort() ; var jump_dist : int := 1 ; var obstacle_hit : boolean := true ; while (obstacle_hit) do ( obstacle_hit := false ; jump_dist := jump_dist + 1 ; for i : Integer.subrange(0, (obs)->size()-1) do ( if obs[i+1] mod jump_dist = 0 then ( obstacle_hit := true ; break ) else skip)) ; return jump_dist; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : num=int(input()) if num==0 : break else : num1=int(input()) kei=0 for _ in range(num1): a,b=map(int,input().split()) kei+=b-a if num<=kei : print("OK") else : print(num-kei) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if num = 0 then ( break ) else ( var num1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var kei : int := 0 ; for _anon : Integer.subrange(0, num1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; kei := kei + b - a) ; if (num->compareTo(kei)) <= 0 then ( execute ("OK")->display() ) else ( execute (num - kei)->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(s)for s in input().split(" ")] bibs=[int(input())for i in range(n)] for k in range(1,m+1): for i in range(n-1): if bibs[i]% k>bibs[i+1]% k :(bibs[i],bibs[i+1])=(bibs[i+1],bibs[i]) for bib in bibs : print(bib) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split(" ")->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; var bibs : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; for k : Integer.subrange(1, m + 1-1) do ( for i : Integer.subrange(0, n - 1-1) do ( if (bibs[i+1] mod k->compareTo(bibs[i + 1+1] mod k)) > 0 then ( Sequence{bibs[i+1], bibs[i + 1+1]} := Sequence{bibs[i + 1+1], bibs[i+1]} ) else skip)) ; for bib : bibs do ( execute (bib)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def swappingBibs(a,k): for i in range(0,len(a)-1): if a[i]% k>a[i+1]% k : a[i],a[i+1]=a[i+1],a[i] return a N,M=map(int,input().split()) A=[int(input())for _ in range(N)] for m in range(1,M+1): A=swappingBibs(A,m) for j in A : print(j) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; for m : Integer.subrange(1, M + 1-1) do ( A := swappingBibs(A, m)) ; for j : A do ( execute (j)->display()); operation swappingBibs(a : OclAny, k : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, (a)->size() - 1-1) do ( if (a[i+1] mod k->compareTo(a[i + 1+1] mod k)) > 0 then ( var a[i+1] : OclAny := null; var a[i + 1+1] : OclAny := null; Sequence{a[i+1],a[i + 1+1]} := Sequence{a[i + 1+1],a[i+1]} ) else skip) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() columns=a.split(' ') num_of_student=int(columns[0]) Baton=int(columns[1]) student_bib=[] for i in range(num_of_student): student_bib.append(int(input())) for Baton_num in range(Baton+1): if Baton_num==0 : continue m=0 for j in range(num_of_student): if num_of_student-1==m : break if(student_bib[m]% Baton_num)>(student_bib[m+1]% Baton_num): student_bib_tmp=student_bib[m] student_bib[m]=student_bib[m+1] student_bib[m+1]=student_bib_tmp m+=1 for student_bib_ in student_bib : print(student_bib_) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var columns : OclAny := a.split(' ') ; var num_of_student : int := ("" + ((columns->first())))->toInteger() ; var Baton : int := ("" + ((columns[1+1])))->toInteger() ; var student_bib : Sequence := Sequence{} ; for i : Integer.subrange(0, num_of_student-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : student_bib)) ; for Baton_num : Integer.subrange(0, Baton + 1-1) do ( if Baton_num = 0 then ( continue ) else skip ; var m : int := 0 ; for j : Integer.subrange(0, num_of_student-1) do ( if num_of_student - 1 = m then ( break ) else skip ; if ((student_bib[m+1] mod Baton_num)->compareTo((student_bib[m + 1+1] mod Baton_num))) > 0 then ( var student_bib_tmp : OclAny := student_bib[m+1] ; student_bib[m+1] := student_bib[m + 1+1] ; student_bib[m + 1+1] := student_bib_tmp ) else skip ; m := m + 1)) ; for student_bib_ : student_bib do ( execute (student_bib_)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) s=[0 for _ in range(n+1)] for i in range(n): s[i+1]=int(input()) for k in range(2,m+1): for i in range(1,n): if s[i]% k>s[i+1]% k : s[i],s[i+1]=s[i+1],s[i] for i in s[1 :]: print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (0)) ; for i : Integer.subrange(0, n-1) do ( s[i + 1+1] := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; for k : Integer.subrange(2, m + 1-1) do ( for i : Integer.subrange(1, n-1) do ( if (s[i+1] mod k->compareTo(s[i + 1+1] mod k)) > 0 then ( var s[i+1] : OclAny := null; var s[i + 1+1] : OclAny := null; Sequence{s[i+1],s[i + 1+1]} := Sequence{s[i + 1+1],s[i+1]} ) else skip)) ; for i : s->tail() do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=list(map(int,input().split(' '))) A=[int(input())for i in range(N)] for k in range(1,M+1): i=1 while i!=N : if A[i-1]% k>A[i]% k : A[i-1],A[i]=A[i],A[i-1] i+=1 for a in A : print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var A : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; for k : Integer.subrange(1, M + 1-1) do ( var i : int := 1 ; while i /= N do ( if (A[i - 1+1] mod k->compareTo(A[i+1] mod k)) > 0 then ( var A[i - 1+1] : OclAny := null; var A[i+1] : OclAny := null; Sequence{A[i - 1+1],A[i+1]} := Sequence{A[i+1],A[i - 1+1]} ) else skip ; i := i + 1)) ; for a : A do ( execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() a=0 for i in range(n): x=set(s[: i]) y=set(s[i :]) a=max(a,len(x & y)) print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var a : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x : Set := Set{}->union((s.subrange(1,i))) ; var y : Set := Set{}->union((s.subrange(i+1))) ; a := Set{a, (MathLib.bitwiseAnd(x, y))->size()}->max()) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect n=int(input()) s=list(input()) alp='abcdefghijklmnopqrstuvwxyz' cnt={c :[]for c in alp} for i,c in enumerate(s): cnt[c].append(i) q=int(input()) for _ in range(q): t,x,y=input().split() ans=0 if t=='1' : i,c=int(x)-1,y if s[i]==c : continue a=bisect.bisect_left(cnt[s[i]],i) cnt[s[i]].pop(a) s[i]=c b=bisect.bisect_left(cnt[c],i) cnt[c].insert(b,i) else : l,r=int(x)-1,int(y)-1 for c in alp : a=bisect.bisect_left(cnt[c],l) if atoInteger() ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var alp : String := 'abcdefghijklmnopqrstuvwxyz' ; var cnt : Map := alp->characters()->select(c | true)->collect(c | Map{c |-> Sequence{}})->unionAll() ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); (expr (atom (name cnt)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name c)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( var t : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{t,x,y} := input().split() ; var ans : int := 0 ; if t = '1' then ( var i : OclAny := null; var c : OclAny := null; Sequence{i,c} := Sequence{("" + ((x)))->toInteger() - 1,y} ; if s[i+1] = c then ( continue ) else skip ; var a : OclAny := bisect.bisect_left(cnt[s[i+1]+1], i) ; (expr (atom (name cnt)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name pop) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))) ; s[i+1] := c ; var b : OclAny := bisect.bisect_left(cnt[c+1], i) ; (expr (atom (name cnt)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name c)))))))) ])) (trailer . (name insert) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b))))))) , (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ) else ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{("" + ((x)))->toInteger() - 1,("" + ((y)))->toInteger() - 1} ; for c : alp->characters() do ( a := bisect.bisect_left(cnt[c+1], l) ; if (a->compareTo((cnt[c+1])->size())) < 0 & (cnt[c+1][a+1]->compareTo(r)) <= 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): N=int(input()) S=input() max_spieces=0 for i in range(1,N): pre=set(S[: i]) post=set(S[i :]) intersection_num=len(pre & post) if intersection_num>max_spieces : max_spieces=intersection_num print(max_spieces) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : String := (OclFile["System.in"]).readLine() ; var max_spieces : int := 0 ; for i : Integer.subrange(1, N-1) do ( var pre : Set := Set{}->union((S.subrange(1,i))) ; var post : Set := Set{}->union((S.subrange(i+1))) ; var intersection_num : int := (MathLib.bitwiseAnd(pre, post))->size() ; if (intersection_num->compareTo(max_spieces)) > 0 then ( max_spieces := intersection_num ) else skip) ; execute (max_spieces)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() moji=[chr(i)for i in range(97,97+26)] ans=0 for i in range(n): count=0 for key in moji : if key in s[i :]and key in s[: i]: count+=1 if count>ans : ans=count print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var moji : Sequence := Integer.subrange(97, 97 + 26-1)->select(i | true)->collect(i | ((i)->byte2char())) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var count : int := 0 ; for key : moji do ( if (s.subrange(i+1))->includes(key) & (s.subrange(1,i))->includes(key) then ( count := count + 1 ) else skip) ; if (count->compareTo(ans)) > 0 then ( ans := count ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) S=input() ans_L=[] for i in range(1,len(S)+1): A=S[0 : i+1] B=S[i+1 :] l=set() for j in A : if j in B : l.add(j) ans_L.append(l) ans=[] for i in ans_L : ans.append(len(i)) print(max(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : String := (OclFile["System.in"]).readLine() ; var ans_L : Sequence := Sequence{} ; for i : Integer.subrange(1, (S)->size() + 1-1) do ( var A : OclAny := S.subrange(0+1, i + 1) ; var B : OclAny := S.subrange(i + 1+1) ; var l : Set := Set{}->union(()) ; for j : A do ( if (B)->includes(j) then ( execute ((j) : l) ) else skip) ; execute ((l) : ans_L)) ; var ans : Sequence := Sequence{} ; for i : ans_L do ( execute (((i)->size()) : ans)) ; execute ((ans)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(t): n=int(input()) for _ in range(n): s,f=map(int,input().split()) t-=(f-s) return 'OK' if t<=0 else t def main(args): while True : t=int(input()) if t==0 : break ans=solve(t) print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(t : OclAny) : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var s : OclAny := null; var f : OclAny := null; Sequence{s,f} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; t := t - (f - s)) ; return if t <= 0 then 'OK' else t endif; operation main(args : OclAny) pre: true post: true activity: while true do ( t := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if t = 0 then ( break ) else skip ; var ans : OclAny := solve(t) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) S=input() arr=set() ray=set() s=list(S) j=0 for i in range(len(s)): arr=set(list(S[: int(i)])) ray=set(list(S[int(i):])) if jtoInteger() ; var S : String := (OclFile["System.in"]).readLine() ; var arr : Set := Set{}->union(()) ; var ray : Set := Set{}->union(()) ; var s : Sequence := (S)->characters() ; var j : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( arr := Set{}->union(((S.subrange(1,("" + ((i)))->toInteger())))) ; ray := Set{}->union(((S.subrange(("" + ((i)))->toInteger()+1)))) ; if (j->compareTo(("" + (((MathLib.bitwiseAnd(arr, ray))->size())))->toInteger())) < 0 then ( j := (MathLib.bitwiseAnd(arr, ray))->size() ) else skip) ; execute (j)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M,T=map(int,input().split()) A=list(map(int,input().split())) prv=0 cnt=0 for a in A : if prv==0 : cnt+=a-M else : if prv+Mcollect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var prv : int := 0 ; var cnt : int := 0 ; for a : A do ( if prv = 0 then ( cnt := cnt + a - M ) else ( if (prv + M->compareTo(a - M)) < 0 then ( cnt := cnt + (a - M) - (prv + M) ) else skip ) ; prv := a) ; if (prv + M->compareTo(T)) < 0 then ( cnt := cnt + T - (prv + M) ) else skip ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] while True : n,m,t=LI() a=[1]*(t+1) l=LI() for c in l : a[c]=0 for c in l : for ci in range(c+1,min(c+m,t+1)): if a[ci]<1 : break a[ci]=0 for ci in range(c-1,max(-1,c-m),-1): if a[ci]<1 : break a[ci]=0 r=0 for i in range(t): if a[i]==1 and a[i+1]==1 : r+=1 rr.append(r) break return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var n : OclAny := null; var m : OclAny := null; var t : OclAny := null; Sequence{n,m,t} := LI() ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (t + 1)) ; var l : OclAny := LI() ; for c : l do ( a[c+1] := 0) ; for c : l do ( for ci : Integer.subrange(c + 1, Set{c + m, t + 1}->min()-1) do ( if a[ci+1] < 1 then ( break ) else skip ; a[ci+1] := 0) ; for ci : Integer.subrange(Set{-1, c - m}->max() + 1, c - 1)->reverse() do ( if a[ci+1] < 1 then ( break ) else skip ; a[ci+1] := 0)) ; var r : int := 0 ; for i : Integer.subrange(0, t-1) do ( if a[i+1] = 1 & a[i + 1+1] = 1 then ( r := r + 1 ) else skip) ; execute ((r) : rr) ; break) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) def main(): n,m,t=map(int,input().split()) diff_sum=0 mini_diff=0 a=[-1*m]+[i for i in map(int,input().split())] for i in range(n): diff=(2*m)-(a[i+1]-a[i]) if diff>0 : diff_sum+=diff if t-mpow(6)) ; skip ; main(); operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var t : OclAny := null; Sequence{n,m,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var diff_sum : int := 0 ; var mini_diff : int := 0 ; var a : Sequence := Sequence{ -1 * m }->union((input().split())->collect( _x | (OclType["int"])->apply(_x) )->select(i | true)->collect(i | (i))) ; for i : Integer.subrange(0, n-1) do ( var diff : double := (2 * m) - (a[i + 1+1] - a[i+1]) ; if diff > 0 then ( diff_sum := diff_sum + diff ) else skip) ; if (t - m->compareTo(a[n+1])) < 0 then ( mini_diff := a[n+1] + m - t ) else skip ; execute (t - (2 * m * n - diff_sum - mini_diff))->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l_raw=input().split() l=[int(n)for n in l_raw] a_raw=input().split() a_=[int(n)for n in a_raw] study=0 state=0 now=0 for a in a_ : if state==0 : if l[1]0 : study+=l[2]-l[1]-a print(study) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l_raw : OclAny := input().split() ; var l : Sequence := l_raw->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; var a_raw : OclAny := input().split() ; var a_ : Sequence := a_raw->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; var study : int := 0 ; var state : int := 0 ; var now : int := 0 ; for a : a_ do ( if state = 0 then ( if (l[1+1]->compareTo(a - now)) < 0 then ( study := study + a - now - l[1+1] ) else skip ; now := a ; state := 1 ) else (if state = 1 then ( if (2 * l[1+1]->compareTo(a - now)) < 0 then ( study := study + a - now - 2 * l[1+1] ) else skip ; now := a ) else skip)) ; if l[2+1] - l[1+1] - a > 0 then ( study := study + l[2+1] - l[1+1] - a ) else skip ; execute (study)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,t=map(int,input().split()) a_list=list(map(int,input().split())) ans=0 ans+=max(0,a_list[0]-m) before=a_list[0] for i in range(1,n): ans+=max(0,a_list[i]-before-m*2) before=a_list[i] ans+=max(0,t-before-m) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var t : OclAny := null; Sequence{n,m,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; ans := ans + Set{0, a_list->first() - m}->max() ; var before : OclAny := a_list->first() ; for i : Integer.subrange(1, n-1) do ( ans := ans + Set{0, a_list[i+1] - before - m * 2}->max() ; before := a_list[i+1]) ; ans := ans + Set{0, t - before - m}->max() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def coin(totalRupees,X,Y,Z): one=X*1 fifty=((Y*1)/2.0) twentyfive=((Z*1)/4.0) total=one+fifty+twentyfive result=((totalRupees)/total) return int(result) if __name__=='__main__' : totalRupees=1800 X,Y,Z=1,2,4 Rupees=coin(totalRupees,X,Y,Z) print("1 rupess coins=",Rupees*1) print("50 paisa coins=",Rupees*2) print("25 paisa coins=",Rupees*4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( totalRupees := 1800 ; Sequence{X,Y,Z} := Sequence{1,2,4} ; var Rupees : OclAny := coin(totalRupees, X, Y, Z) ; execute ("1 rupess coins=")->display() ; execute ("50 paisa coins=")->display() ; execute ("25 paisa coins=")->display() ) else skip; operation coin(totalRupees : OclAny, X : OclAny, Y : OclAny, Z : OclAny) : OclAny pre: true post: true activity: var one : double := X * 1 ; var fifty : double := ((Y * 1) / 2.0) ; var twentyfive : double := ((Z * 1) / 4.0) ; var total : OclAny := one + fifty + twentyfive ; var result : double := ((totalRupees) / total) ; return ("" + ((result)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class BIT : def __init__(self,n): self.node=[0 for _ in range(n+1)] def add(self,idx,w): i=idx while i=0 : ret+=self.node[i] i=(i &(i+1))-1 return ret def sum(self,l,r): return self.sum_(r)-self.sum_(l) n=int(input()) s=list(input()) q=int(input()) tree=[BIT(n)for _ in range(26)] for i in range(n): tree_id=ord(s[i])-ord("a") tree[tree_id].add(i,1) for _ in range(q): query=input().split() com=int(query[0]) if com==1 : idx,new_char=int(query[1]),query[2] idx-=1 old_char=s[idx] new_id=ord(new_char)-ord("a") old_id=ord(old_char)-ord("a") tree[old_id].add(idx,-1) tree[new_id].add(idx,1) s[idx]=new_char if com==2 : l,r=int(query[1]),int(query[2]) ret=0 for c in range(26): if tree[c].sum(l-1,r)>0 : ret+=1 print(ret) ------------------------------------------------------------ OCL File: --------- class BIT { static operation newBIT() : BIT pre: true post: BIT->exists( _x | result = _x ); attribute node : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (0)); operation initialise(n : OclAny) : BIT pre: true post: true activity: self.node := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (0)); return self; operation add(idx : OclAny,w : OclAny) pre: true post: true activity: var i : OclAny := idx ; while (i->compareTo((self.node)->size() - 1)) < 0 do ( self.node[i+1] := self.node[i+1] + w ; i := i or (i + 1)); operation sum_(idx : OclAny) : OclAny pre: true post: true activity: var ret : OclAny := null; Sequence{ret,i} := Sequence{0,idx - 1} ; while i >= 0 do ( ret := ret + self.node[i+1] ; i := (MathLib.bitwiseAnd(i, (i + 1))) - 1) ; return ret; operation sum(l : OclAny,r : OclAny) : OclAny pre: true post: true activity: return self.sum_(r) - self.sum_(l); } class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var tree : Sequence := Integer.subrange(0, 26-1)->select(_anon | true)->collect(_anon | ((BIT.newBIT()).initialise(n))) ; for i : Integer.subrange(0, n-1) do ( var tree_id : double := (s[i+1])->char2byte() - ("a")->char2byte() ; (expr (atom (name tree)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name tree_id)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ))))) ; for _anon : Integer.subrange(0, q-1) do ( var query : OclAny := input().split() ; var com : int := ("" + ((query->first())))->toInteger() ; if com = 1 then ( var new_char : OclAny := null; Sequence{idx,new_char} := Sequence{("" + ((query[1+1])))->toInteger(),query[2+1]} ; idx := idx - 1 ; var old_char : OclAny := s[idx+1] ; var new_id : double := (new_char)->char2byte() - ("a")->char2byte() ; var old_id : double := (old_char)->char2byte() - ("a")->char2byte() ; (expr (atom (name tree)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name old_id)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name idx))))))) , (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))) ; (expr (atom (name tree)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name new_id)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name idx))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))) ; s[idx+1] := new_char ) else skip ; if com = 2 then ( Sequence{l,r} := Sequence{("" + ((query[1+1])))->toInteger(),("" + ((query[2+1])))->toInteger()} ; var ret : int := 0 ; for c : Integer.subrange(0, 26-1) do ( if tree[c+1].sum(l - 1, r) > 0 then ( ret := ret + 1 ) else skip) ; execute (ret)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numberOfPaths(p,q): dp=[1 for i in range(q)] for i in range(p-1): for j in range(1,q): dp[j]+=dp[j-1] return dp[q-1] print(numberOfPaths(3,3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (numberOfPaths(3, 3))->display(); operation numberOfPaths(p : OclAny, q : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, q-1)->select(i | true)->collect(i | (1)) ; for i : Integer.subrange(0, p - 1-1) do ( for j : Integer.subrange(1, q-1) do ( dp[j+1] := dp[j+1] + dp[j - 1+1])) ; return dp[q - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil n,h,k=map(int,input().split()) sum=0 arr=list(map(int,input().split())) for i in range(n): sum+=arr[i] s=0 i=0 p=0 while sum>0 : while i0 : if pcollect( _x | (OclType["int"])->apply(_x) ) ; var sum : int := 0 ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( sum := sum + arr[i+1]) ; var s : int := 0 ; var i : int := 0 ; var p : int := 0 ; while sum > 0 do ( while (i->compareTo(n)) < 0 & (p + arr[i+1]->compareTo(h)) <= 0 do ( p := p + arr[i+1] ; sum := sum - arr[i+1] ; i := i + 1) ; s := s + ceil((p - p mod k) / k) ; if (p->compareTo(k)) < 0 then ( p := 0 ; s := s + 1 ) else ( p := p mod k )) ; if p > 0 then ( if (p->compareTo(k)) < 0 then ( p := 0 ; s := s + 1 ) else ( p := 0 ; s := s + ceil(p / k) ) ) else skip ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os while 1 : t=int(input()) if t==0 : break n=int(input()) sf=[list(map(int,input().split()))for _ in range(n)] time=0 for i in sf : start,end=i if start>end : time+=end-(start-24) else : time+=end-start if time>=t : print("OK") else : print(t-time) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while 1 do ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if t = 0 then ( break ) else skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sf : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var time : int := 0 ; for i : sf do ( var start : OclAny := null; var end : OclAny := null; Sequence{start,end} := i ; if (start->compareTo(end)) > 0 then ( time := time + end - (start - 24) ) else ( time := time + end - start )) ; if (time->compareTo(t)) >= 0 then ( execute ("OK")->display() ) else ( execute (t - time)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,h,k=map(int,input().split()) tab=list(map(int,input().split())) time=0 left=0 for i in range(n): if tab[i]+left>h : time+=1 left=0 time=time+(left+tab[i])//k left=(left+tab[i])% k if left!=0 : time+=1 print(time) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var h : OclAny := null; var k : OclAny := null; Sequence{n,h,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var tab : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var time : int := 0 ; var left : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (tab[i+1] + left->compareTo(h)) > 0 then ( time := time + 1 ; left := 0 ) else skip ; time := time + (left + tab[i+1]) div k ; left := (left + tab[i+1]) mod k) ; if left /= 0 then ( time := time + 1 ) else skip ; execute (time)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,h,k=map(int,input().split()) a=list(map(int,input().split())) i=0 s=0 t=0 while(id : r=(s-d)//k if(s-d)% k : r+=1 s-=r*k if s<0 : s=0 t+=r s+=p i+=1 p=s//k if s % k : p+=1 t+=p print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var h : OclAny := null; var k : OclAny := null; Sequence{n,h,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var i : int := 0 ; var s : int := 0 ; var t : int := 0 ; while ((i->compareTo(n)) < 0) do ( var p : OclAny := a[i+1] ; var d : double := h - p ; if (s->compareTo(d)) > 0 then ( var r : int := (s - d) div k ; if (s - d) mod k then ( r := r + 1 ) else skip ; s := s - r * k ; if s < 0 then ( s := 0 ) else skip ; t := t + r ) else skip ; s := s + p ; i := i + 1) ; p := s div k ; if s mod k then ( p := p + 1 ) else skip ; t := t + p ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,h,k=map(int,input().split()) a=list(map(int,input().split())) hi,ans=0,0 for ai in a : if hi+ai>h : ans+=1 hi=0 ans+=(hi+ai)//k hi=(hi+ai)% k if hi>0 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var h : OclAny := null; var k : OclAny := null; Sequence{n,h,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var hi : OclAny := null; var ans : OclAny := null; Sequence{hi,ans} := Sequence{0,0} ; for ai : a do ( if (hi + ai->compareTo(h)) > 0 then ( ans := ans + 1 ; var hi : int := 0 ) else skip ; ans := ans + (hi + ai) div k ; hi := (hi + ai) mod k) ; if hi > 0 then ( ans := ans + 1 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,h,k=[int(x)for x in input().split(' ')] potatos=[int(x)for x in input().split(' ')] s,l,i=0,0,0 for p in potatos : if l+p>h : l=p s+=1 else : l+=p s+=l//k l %=k s+=(1 if l>0 else 0) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var h : OclAny := null; var k : OclAny := null; Sequence{n,h,k} := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var potatos : Sequence := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var s : OclAny := null; var l : OclAny := null; var i : OclAny := null; Sequence{s,l,i} := Sequence{0,0,0} ; for p : potatos do ( if (l + p->compareTo(h)) > 0 then ( var l : OclAny := p ; s := s + 1 ) else ( l := l + p ) ; s := s + l div k ; l := l mod k) ; s := s + (if l > 0 then 1 else 0 endif) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isVowel(ch): if(ch=='a' or ch=='e' or ch=='i' or ch=='o' or ch=='u'): return True return False def createAltStr(str1,str2,start,l): finalStr="" i=0 for j in range(start,l): finalStr=(finalStr+str1[i])+str2[j] i+1 return finalStr def findAltStr(str1): nv=0 nc=0 vstr="" cstr="" l=len(str1) for i in range(0,l): if(isVowel(str1[i])): nv+=1 vstr=vstr+str1[i] else : nc+=1 cstr=cstr+str1[i] if(abs(nv-nc)>=2): return "no such string" if(nv>nc): return(vstr[0]+createAltStr(cstr,vstr,1,nv)) if(nc>nv): return(cstr[0]+createAltStr(vstr,cstr,1,nc)) if(cstr[0]display() ) else skip; operation isVowel(ch : OclAny) : OclAny pre: true post: true activity: if (ch = 'a' or ch = 'e' or ch = 'i' or ch = 'o' or ch = 'u') then ( return true ) else skip ; return false; operation createAltStr(str1 : OclAny, str2 : OclAny, start : OclAny, l : OclAny) : OclAny pre: true post: true activity: var finalStr : String := "" ; var i : int := 0 ; for j : Integer.subrange(start, l-1) do ( finalStr := (finalStr + str1[i+1]) + str2[j+1] ; (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))) ; return finalStr; operation findAltStr(str1 : OclAny) : OclAny pre: true post: true activity: var nv : int := 0 ; var nc : int := 0 ; var vstr : String := "" ; var cstr : String := "" ; l := (str1)->size() ; for i : Integer.subrange(0, l-1) do ( if (isVowel(str1[i+1])) then ( nv := nv + 1 ; vstr := vstr + str1[i+1] ) else ( nc := nc + 1 ; cstr := cstr + str1[i+1] )) ; if ((nv - nc)->abs() >= 2) then ( return "no such string" ) else skip ; if ((nv->compareTo(nc)) > 0) then ( return (vstr->first() + createAltStr(cstr, vstr, 1, nv)) ) else skip ; if ((nc->compareTo(nv)) > 0) then ( return (cstr->first() + createAltStr(vstr, cstr, 1, nc)) ) else skip ; if ((cstr->first()->compareTo(vstr->first())) < 0) then ( return createAltStr(cstr, vstr, 0, nv) ) else skip ; return createAltStr(vstr, cstr, 0, nc); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- SIZE=26 def isVowel(ch): if(ch=='a' or ch=='e' or ch=='i' or ch=='o' or ch=='u'): return True return False def createAltStr(str1,str2,start,l): finalStr="" i=0 j=start while j=2 : return "no such string" for i in range(SIZE): ch=chr(i+97) for j in range(1,char_freq[i]+1): if isVowel(ch): vstr+=ch else : cstr+=ch if nv>nc : return vstr[0]+createAltStr(cstr,vstr,1,nv) if nc>nv : return cstr[0]+createAltStr(vstr,cstr,1,nc) if cstr[0]display() ) else skip; operation isVowel(ch : OclAny) : OclAny pre: true post: true activity: if (ch = 'a' or ch = 'e' or ch = 'i' or ch = 'o' or ch = 'u') then ( return true ) else skip ; return false; operation createAltStr(str1 : OclAny, str2 : OclAny, start : OclAny, l : OclAny) : OclAny pre: true post: true activity: var finalStr : String := "" ; var i : int := 0 ; var j : OclAny := start ; while (j->compareTo(l)) < 0 do ( finalStr := finalStr + str1[i+1] + str2[j+1] ; i := i + 1 ; j := j + 1) ; return finalStr; operation findAltStr(string : OclAny) : OclAny pre: true post: true activity: var char_freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, SIZE) ; var nv : int := 0 ; var nc : int := 0 ; var vstr : String := "" ; var cstr : String := "" ; l := (string)->size() ; for i : Integer.subrange(0, l-1) do ( ch := string[i+1] ; if isVowel(ch) then ( nv := nv + 1 ) else ( nc := nc + 1 ) ; char_freq[(ch)->char2byte() - 97+1] := char_freq[(ch)->char2byte() - 97+1] + 1) ; if (nv - nc)->abs() >= 2 then ( return "no such string" ) else skip ; for i : Integer.subrange(0, SIZE-1) do ( ch := (i + 97)->byte2char() ; for j : Integer.subrange(1, char_freq[i+1] + 1-1) do ( if isVowel(ch) then ( vstr := vstr + ch ) else ( cstr := cstr + ch ))) ; if (nv->compareTo(nc)) > 0 then ( return vstr->first() + createAltStr(cstr, vstr, 1, nv) ) else skip ; if (nc->compareTo(nv)) > 0 then ( return cstr->first() + createAltStr(vstr, cstr, 1, nc) ) else skip ; if (cstr->first()->compareTo(vstr->first())) < 0 then ( return createAltStr(cstr, vstr, 0, nv) ) else skip ; return createAltStr(vstr, cstr, 0, nc); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from scanf import* opers=0 class Node : def __init__(self): self.children={} def addPath(self,path): if len(path)==0 : return if not path[0]in self.children : global opers opers+=1 self.children[path[0]]=Node() self.children[path[0]].addPath(path[1 :]) def solveCase(cas): global opers n,m=scanf("%d%d") root=Node() for i in range(n): root.addPath(scanf("%s")[0].split("/")[1 :]) opers=0 for i in range(m): root.addPath(scanf("%s")[0].split("/")[1 :]) print("Case #"+str(cas)+": "+str(opers)) if __name__=="__main__" : tests=scanf("%d")[0] for i in range(tests): solveCase(i+1) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute children : OclAny := Set{}; operation initialise() : Node pre: true post: true activity: self.children := Set{}; return self; operation addPath(path : OclAny) pre: true post: true activity: if (path)->size() = 0 then ( return ) else skip ; if not((self.children)->includes(path->first())) then ( skip ; opers := opers + 1 ; self.children[path->first()+1] := Node() ) else skip ; (expr (atom (name self)) (trailer . (name children) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name path)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])) (trailer . (name addPath) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name path)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))))))) )))); } class FromPython { attribute opers : OclAny; operation initialise() pre: true post: true activity: skip ; var opers : int := 0 ; skip ; skip ; if __name__ = "__main__" then ( var tests : OclAny := scanf("%d")->first() ; for i : Integer.subrange(0, tests-1) do ( solveCase(i + 1)) ) else skip; operation solveCase(cas : OclAny) pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := scanf("%d%d") ; var root : Node := (Node.newNode()).initialise() ; for i : Integer.subrange(0, n-1) do ( root.addPath(scanf("%s")->first().split("/")->tail())) ; opers := 0 ; for i : Integer.subrange(0, m-1) do ( root.addPath(scanf("%s")->first().split("/")->tail())) ; execute ("Case #" + ("" + ((cas))) + ": " + ("" + ((opers))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ntests=int(input()) for tt in range(1,ntests+1): [N,M]=[int(x)for x in input().split()] dirs=set() for i in range(N): p=input()+"/" for z in range(len(p)-1): if(p[z+1]=='/'): dirs.add(p[:(z+1)]) k=len(dirs) for i in range(M): p=input()+"/" for z in range(len(p)-1): if(p[z+1]=='/'): dirs.add(p[:(z+1)]) print("Case #"+str(tt)+": "+str(len(dirs)-k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ntests : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for tt : Integer.subrange(1, ntests + 1-1) do ( ; Sequence{N}->union(Sequence{ M }) := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var dirs : Set := Set{}->union(()) ; for i : Integer.subrange(0, N-1) do ( var p : String := (OclFile["System.in"]).readLine() + "/" ; for z : Integer.subrange(0, (p)->size() - 1-1) do ( if (p[z + 1+1] = '/') then ( execute ((p.subrange(1,(z + 1))) : dirs) ) else skip)) ; var k : int := (dirs)->size() ; for i : Integer.subrange(0, M-1) do ( p := (OclFile["System.in"]).readLine() + "/" ; for z : Integer.subrange(0, (p)->size() - 1-1) do ( if (p[z + 1+1] = '/') then ( execute ((p.subrange(1,(z + 1))) : dirs) ) else skip)) ; execute ("Case #" + ("" + ((tt))) + ": " + ("" + (((dirs)->size() - k))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter,defaultdict,deque from bisect import bisect_left import sys,math,itertools,pprint,fractions sys.setrecursionlimit(10**8) mod=10**9+7 INF=float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int,sys.stdin.readline().split())) n=inp() s=list(input()) q=inp() Qs=[input().split()for i in range(q)] upd=[] acc=[[0]*26 for i in range(n+1)] for i,t in enumerate(s): tmp=ord(t)-ord('a') for j in range(26): if j==tmp : acc[i+1][j]=acc[i][j]+1 continue acc[i+1][j]=acc[i][j] for i,t in enumerate(Qs): a,b,c=t b=int(b) if a=='1' : upd.append([b,ord(s[b-1])-ord('a'),ord(c)-ord('a')]) s[b-1]=c else : c=int(c) cnt=0 now=[0]*26 for j in range(26): now[j]=acc[c][j]-acc[b-1][j] for j,k in enumerate(upd): if b<=k[0]<=c : now[k[1]]-=1 now[k[2]]+=1 for j in range(26): if now[j]>0 : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; var mod : double := (10)->pow(9) + 7 ; var INF : double := ("" + (('inf')))->toReal() ; skip ; skip ; var n : OclAny := inp() ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var q : OclAny := inp() ; var Qs : Sequence := Integer.subrange(0, q-1)->select(i | true)->collect(i | (input().split())) ; var upd : Sequence := Sequence{} ; var acc : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, 26))) ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); var tmp : double := (t)->char2byte() - ('a')->char2byte() ; for j : Integer.subrange(0, 26-1) do ( if j = tmp then ( acc[i + 1+1][j+1] := acc[i+1][j+1] + 1 ; continue ) else skip ; acc[i + 1+1][j+1] := acc[i+1][j+1])) ; for _tuple : Integer.subrange(1, (Qs)->size())->collect( _indx | Sequence{_indx-1, (Qs)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := t ; var b : int := ("" + ((b)))->toInteger() ; if a = '1' then ( execute ((Sequence{b}->union(Sequence{(s[b - 1+1])->char2byte() - ('a')->char2byte()}->union(Sequence{ (c)->char2byte() - ('a')->char2byte() }))) : upd) ; s[b - 1+1] := c ) else ( var c : int := ("" + ((c)))->toInteger() ; var cnt : int := 0 ; var now : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for j : Integer.subrange(0, 26-1) do ( now[j+1] := acc[c+1][j+1] - acc[b - 1+1][j+1]) ; for _tuple : Integer.subrange(1, (upd)->size())->collect( _indx | Sequence{_indx-1, (upd)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var k : OclAny := _tuple->at(_indx); if (b->compareTo(k->first())) <= 0 & (k->first() <= c) then ( now[k[1+1]+1] := now[k[1+1]+1] - 1 ; now[k[2+1]+1] := now[k[2+1]+1] + 1 ) else skip) ; for j : Integer.subrange(0, 26-1) do ( if now[j+1] > 0 then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display() )); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inpl() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys if(len(sys.argv)<2): print("No file specified") sys.exit(1) infile=open(sys.argv[1]) outfile=open(sys.argv[1]+".out","w") num_cases=int(infile.readline().strip()) def add_dir(dirs,new_dir): result=0 if len(new_dir)>0 : child_dir=new_dir[0] if child_dir not in dirs : result=1 dirs[child_dir]={} result+=add_dir(dirs[child_dir],new_dir[1 :]) return result for case in range(1,num_cases+1): n,m=map(int,infile.readline().split()) directories={} for i in range(n): dir=infile.readline().strip().split("/")[1 :] add_dir(directories,dir) result=0 for i in range(m): dir=infile.readline().strip().split("/")[1 :] result+=add_dir(directories,dir) outfile.write("Case #%d: %d\n" %(case,result)) if case % 100==0 : print("Completed case %d" % case) outfile.close() infile.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if (((trailer . (name argv)))->size() < 2) then ( execute ("No file specified")->display() ; sys.exit(1) ) else skip ; var infile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) ; var outfile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) + ".out")) ; var num_cases : int := ("" + ((infile.readLine()->trim())))->toInteger() ; skip ; for case : Integer.subrange(1, num_cases + 1-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (infile.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var directories : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var dir : OclAny := infile.readLine()->trim().split("/")->tail() ; add_dir(directories, dir)) ; result := 0 ; for i : Integer.subrange(0, m-1) do ( dir := infile.readLine()->trim().split("/")->tail() ; result := result + add_dir(directories, dir)) ; outfile.write(StringLib.format("Case #%d: %d\n",Sequence{case, result})) ; if case mod 100 = 0 then ( execute (StringLib.format("Completed case %d",case))->display() ) else skip) ; outfile.closeFile() ; infile.closeFile(); operation add_dir(dirs : OclAny, new_dir : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; if (new_dir)->size() > 0 then ( var child_dir : OclAny := new_dir->first() ; if (dirs)->excludes(child_dir) then ( result := 1 ; dirs[child_dir+1] := Set{} ) else skip ; result := result + add_dir(dirs[child_dir+1], new_dir->tail()) ) else skip ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys f=sys.stdin while True : t=int(f.readline()) if t==0 : break n=int(f.readline()) sf=(map(int,f.readline().split())for _ in range(n)) rest=t-sum(f-s for s,f in sf) print('OK' if rest<=0 else rest) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var f : OclFile := OclFile["System.in"] ; while true do ( var t : int := ("" + ((f.readLine())))->toInteger() ; if t = 0 then ( break ) else skip ; var n : int := ("" + ((f.readLine())))->toInteger() ; var sf : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name f)) (trailer . (name readline) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))} ; var rest : double := t - ((argument (test (logical_test (comparison (expr (expr (atom (name f))) - (expr (atom (name s))))))) (comp_for for (exprlist (expr (atom (name s))) , (expr (atom (name f)))) in (logical_test (comparison (expr (atom (name sf))))))))->sum() ; execute (if rest <= 0 then 'OK' else rest endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for z in range(0,t): s=list(input()) v=list(input()) x=[] count=1 for i in range(0,len(s)): if i==len(s)-1 : x.append([s[i],count]) elif s[i]!=s[i+1]: x.append([s[i],count]) count=1 else : count+=1 count=1 point=0 ans='YES' for i in range(0,len(v)): if point>len(x)-1 : ans='NO' break elif i==len(v)-1 : if point+1<=len(x)-1 : ans='NO' break if x[point][0]==v[i]and count>=x[point][1]: pass else : ans='NO' elif v[i]!=v[i+1]: if x[point][0]==v[i]and count>=x[point][1]: point+=1 count=1 else : ans='NO' else : count+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for z : Integer.subrange(0, t-1) do ( var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var v : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var x : Sequence := Sequence{} ; var count : int := 1 ; for i : Integer.subrange(0, (s)->size()-1) do ( if i = (s)->size() - 1 then ( execute ((Sequence{s[i+1]}->union(Sequence{ count })) : x) ) else (if s[i+1] /= s[i + 1+1] then ( execute ((Sequence{s[i+1]}->union(Sequence{ count })) : x) ; count := 1 ) else ( count := count + 1 ) ) ) ; count := 1 ; var point : int := 0 ; var ans : String := 'YES' ; for i : Integer.subrange(0, (v)->size()-1) do ( if (point->compareTo((x)->size() - 1)) > 0 then ( ans := 'NO' ; break ) else (if i = (v)->size() - 1 then ( if (point + 1->compareTo((x)->size() - 1)) <= 0 then ( ans := 'NO' ; break ) else skip ; if x[point+1]->first() = v[i+1] & (count->compareTo(x[point+1][1+1])) >= 0 then ( skip ) else ( ans := 'NO' ) ) else (if v[i+1] /= v[i + 1+1] then ( if x[point+1]->first() = v[i+1] & (count->compareTo(x[point+1][1+1])) >= 0 then ( point := point + 1 ; count := 1 ) else ( ans := 'NO' ) ) else ( count := count + 1 ) ) ) ) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import* for r in[0]*int(input()): print('YNEOS'[any(a!=b or len([*g])>len([*h])for(a,g),(b,h)in zip_longest(*map(groupby,(input(),input())),fillvalue=(0,0))): : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for r : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( execute ('YNEOS'(subscript (test (logical_test (comparison (expr (atom (name any)) (trailer (arguments ( (arglist (argument (test (logical_test (logical_test (comparison (comparison (expr (atom (name a)))) != (comparison (expr (atom (name b)))))) or (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (star_expr * (expr (atom (name g))))) ]))))))) ))))) > (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (star_expr * (expr (atom (name h))))) ]))))))) ))))))))) (comp_for for (exprlist (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name g))))))) ))) , (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name b)))))) , (test (logical_test (comparison (expr (atom (name h))))))) )))) in (logical_test (comparison (expr (atom (name zip_longest)) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name groupby))))))) , (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))) , (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( )))))))) )))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name fillvalue)))))) = (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) , (test (logical_test (comparison (expr (atom (number (integer 0)))))))) )))))))) ))))))))) ))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) while n : n-=1 x1=input() x2=input() k=0 f=True i=0 if len(x1)==len(x2): if x1==x2 : print('YES') else : print('NO') elif len(x1)>len(x2): print('NO') else : while i=0 and x1[k-1]==x2[i]: i+=1 else : f=False break if f==False : print('NO') elif k==len(x1)and i==len(x2): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while n do ( n := n - 1 ; var x1 : String := (OclFile["System.in"]).readLine() ; var x2 : String := (OclFile["System.in"]).readLine() ; var k : int := 0 ; var f : boolean := true ; var i : int := 0 ; if (x1)->size() = (x2)->size() then ( if x1 = x2 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) else (if ((x1)->size()->compareTo((x2)->size())) > 0 then ( execute ('NO')->display() ) else ( while (i->compareTo((x2)->size())) < 0 do ( if (k->compareTo((x1)->size())) < 0 & x1[k+1] = x2[i+1] then ( k := k + 1 ; i := i + 1 ) else (if k - 1 >= 0 & x1[k - 1+1] = x2[i+1] then ( i := i + 1 ) else ( f := false ; break ) ) ) ; if f = false then ( execute ('NO')->display() ) else (if k = (x1)->size() & i = (x2)->size() then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(0,n): a=str(input()) b=str(input()) l=len(b) le=len(a) a=a+'0' c=0 for j in range(0,l): if(a[c]==b[j]and ctoInteger() ; for i : Integer.subrange(0, n-1) do ( var a : String := ("" + (((OclFile["System.in"]).readLine()))) ; var b : String := ("" + (((OclFile["System.in"]).readLine()))) ; var l : int := (b)->size() ; var le : int := (a)->size() ; a := a + '0' ; var c : int := 0 ; for j : Integer.subrange(0, l-1) do ( if (a[c+1] = b[j+1] & (c->compareTo(le)) < 0) then ( c := c + 1 ) else (if (b[j - 1+1] /= b[j+1] or j = 0) then ( c := -1 ; break ) else skip)) ; if c = le then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) ans=[] for _ in range(n): s=list(input().rstrip()) t=list(input().rstrip()) x,y=[],[] u,v=[],[] w=s[0] c=0 for i in s : if w ^ i : x.append(c) u.append(w) w=i c=0 c+=1 x.append(c) u.append(w) w=t[0] c=0 for i in t : if w ^ i : y.append(c) v.append(w) w=i c=0 c+=1 y.append(c) v.append(w) if len(x)^ len(y): ans0="NO" else : ans0="YES" for i,j in zip(x,y): if i>j : ans0="NO" break for i,j in zip(u,v): if i ^ j : ans0="NO" break ans.append(ans0) sys.stdout.write("\n".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var s : Sequence := (input().rstrip()) ; var t : Sequence := (input().rstrip()) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{Sequence{},Sequence{}} ; var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := Sequence{Sequence{},Sequence{}} ; var w : OclAny := s->first() ; var c : int := 0 ; for i : s do ( if MathLib.bitwiseXor(w, i) then ( execute ((c) : x) ; execute ((w) : u) ; w := i ; c := 0 ) else skip ; c := c + 1) ; execute ((c) : x) ; execute ((w) : u) ; w := t->first() ; c := 0 ; for i : t do ( if MathLib.bitwiseXor(w, i) then ( execute ((c) : y) ; execute ((w) : v) ; w := i ; c := 0 ) else skip ; c := c + 1) ; execute ((c) : y) ; execute ((w) : v) ; if MathLib.bitwiseXor((x)->size(), (y)->size()) then ( var ans0 : String := "NO" ) else ( ans0 := "YES" ; for _tuple : Integer.subrange(1, x->size())->collect( _indx | Sequence{x->at(_indx), y->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if (i->compareTo(j)) > 0 then ( ans0 := "NO" ; break ) else skip) ; for _tuple : Integer.subrange(1, u->size())->collect( _indx | Sequence{u->at(_indx), v->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if MathLib.bitwiseXor(i, j) then ( ans0 := "NO" ; break ) else skip) ) ; execute ((ans0) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=list(map(int,input().split())) box=[] box.append(a+b) box.append(a-b) box.append(a*b) print(max(box)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var box : Sequence := Sequence{} ; execute ((a + b) : box) ; execute ((a - b) : box) ; execute ((a * b) : box) ; execute ((box)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import copy from operator import mul from functools import reduce from collections import defaultdict from collections import Counter from collections import deque from itertools import product from itertools import permutations from itertools import combinations from itertools import accumulate from bisect import bisect_left,bisect_right import re def inside(y,x,H,W): return 0<=yunion(Sequence{-1}->union(Sequence{0}->union(Sequence{ 1 }))) ; var dx : Sequence := Sequence{1}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{ 0 }))) ; skip ; skip ; skip ; var INF : int := ("" + ((("1e30")->toReal())))->toInteger() ; var MOD : int := ("" + ((("1e9")->toReal())))->toInteger() + 7 ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation inside(y : OclAny, x : OclAny, H : OclAny, W : OclAny) : OclAny pre: true post: true activity: return 0 <= y & (y < H) & 0 <= x & (x < W); operation i_inpl() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation l_inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation line_inpl(x : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, x-1)->select(_anon | true)->collect(_anon | (i_inpl())); operation create_grid(H : OclAny, W : OclAny, value : int) : OclAny pre: true post: true activity: if value->oclIsUndefined() then value := 0 else skip; return Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, W-1)->select(_anon | true)->collect(_anon | (value)))); operation main() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := l_inpl() ; execute ((Sequence{A + B}->union(Sequence{A - B}->union(Sequence{ A * B })))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- [A,B]=[int(i)for i in input().split()] ans=max(A*B,A+B,A-B) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: Sequence{A}->union(Sequence{ B }) := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : OclAny := Set{A * B, A + B, A - B}->max() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def iread(): return int(input()) def sread(): return input() def aread(t="int"): if t=="int" : ret=[int(i)for i in input().split()] elif t=="str" : ret=list(input()) else : ret=tmp return ret def scan(): return list(map(int,input().split())) def main(): a,b=scan() print(max(a+b,a*b,a-b)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation iread() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation sread() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation aread(t : String) : OclAny pre: true post: true activity: if t->oclIsUndefined() then t := "int" else skip; if t = "int" then ( var ret : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ) else (if t = "str" then ( ret := ((OclFile["System.in"]).readLine())->characters() ) else ( ret := tmp ) ) ; return ret; operation scan() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation main() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := scan() ; execute (Set{a + b, a * b, a - b}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): import sys n,s,_,*t=sys.stdin.buffer.read().split() n=int(n) d=[0]*n+[1<1 : i//=2 d[i]=d[i+i]| d[i-~ i] continue j=int(b)+n while itoInteger() ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n)->union(s->select(c | true)->collect(c | (1 * (2->pow(c - 97))))) ; for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( d[i+1] := MathLib.bitwiseOr(d[i + i+1], d[i - MathLib.bitwiseNot(i)+1])) ; for _tuple : Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) )))))))) ])) * (expr (atom (number (integer 3)))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) )))))))) ])) * (expr (atom (number (integer 3)))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) )))))))) ])) * (expr (atom (number (integer 3)))))))))`third->at(_indx)} ) do (var _indx : int := 1; var q : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); var i : OclAny := null; var s : OclAny := null; Sequence{i,s} := Sequence{("" + ((a)))->toInteger() + n - 1,0} ; if (q->compareTo((atom b '2'))) < 0 then ( d[i+1] := 1 * (2->pow(b->first() - 97)) ; while i > 1 do ( i := i div 2 ; d[i+1] := MathLib.bitwiseOr(d[i + i+1], d[i - MathLib.bitwiseNot(i)+1])) ; continue ) else skip ; var j : int := ("" + ((b)))->toInteger() + n ; while (i->compareTo(j)) < 0 do ( if MathLib.bitwiseAnd(i, 1) then ( s := s or d[i+1] ; i := i + 1 ) else skip ; if MathLib.bitwiseAnd(j, 1) then ( j := j - 1 ; s := s or d[j+1] ) else skip ; i := i div 2 ; j := j div 2) ; execute (bin(s)->count('1'))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fact(num): fact=1 ; while(num>1): fact=fact*num ; num=num-1 ; return fact ; def catalan(n): return fact(2*n)//(fact(n)*fact(n+1)) if __name__=='__main__' : n=5 arr=[1,2,3,4,5] for k in range(n): s=0 for i in range(n): if arr[i]union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ; for k : Integer.subrange(0, n-1) do ( var s : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1]->compareTo(arr[k+1])) < 0 then ( s := s + 1 ) else skip) ; var catalan_leftBST : OclAny := catalan(s) ; var catalan_rightBST : OclAny := catalan(n - s - 1) ; var totalBST : double := catalan_rightBST * catalan_leftBST ; execute (totalBST)->display()) ) else skip; operation fact(num : OclAny) pre: true post: true activity: var fact : int := 1; ; while (num > 1) do ( fact := fact * num; ; num := num - 1;) ; return fact;; operation catalan(n : OclAny) : OclAny pre: true post: true activity: return fact(2 * n) div (fact(n) * fact(n + 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B=[int(zz)for zz in input().split()] print(max(A+B,A-B,A*B)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := input().split()->select(zz | true)->collect(zz | (("" + ((zz)))->toInteger())) ; execute (Set{A + B, A - B, A * B}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reverse(arr,n,k): i=0 while(iunion(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 8 }))))))) ; k := 3 ; n := (arr)->size() ; reverse(arr, n, k) ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); operation reverse(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var i : int := 0 ; while ((i->compareTo(n)) < 0) do ( var left : int := i ; var right : OclAny := Set{i + k - 1, n - 1}->min() ; while ((left->compareTo(right)) < 0) do ( var arr[left+1] : OclAny := null; var arr[right+1] : OclAny := null; Sequence{arr[left+1],arr[right+1]} := Sequence{arr[right+1],arr[left+1]} ; left := left + 1; ; (expr (expr (atom (name right))) - (expr + (expr (atom (number (integer 1))))))) ; i := i + k); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reverse(arr,n,k): for i in range(0,n,2*k): left=i right=min(i+k-1,n-1) while(leftunion(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{10}->union(Sequence{11}->union(Sequence{12}->union(Sequence{13}->union(Sequence{ 14 }))))))))))))) ; k := 3 ; n := (arr)->size() ; reverse(arr, n, k) ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( execute (arr[i+1])->display()) ) else skip; operation reverse(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 * k = 0 ) do ( var left : OclAny := i ; var right : OclAny := Set{i + k - 1, n - 1}->min() ; while ((left->compareTo(right)) < 0) do ( var temp : OclAny := arr[left+1] ; arr[left+1] := arr[right+1] ; arr[right+1] := temp ; left := left + 1 ; right := right - 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reverse(arr,n,k,m): for i in range(0,n,k+m): left=i ; right=min(i+k-1,n-1); while(leftunion(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{10}->union(Sequence{11}->union(Sequence{12}->union(Sequence{13}->union(Sequence{ 14 }))))))))))))); ; k := 3; ; m := 2; ; n := (arr)->size(); ; arr := reverse(arr, n, k, m); ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display();); operation reverse(arr : OclAny, n : OclAny, k : OclAny, m : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod k + m = 0 ) do ( var left : OclAny := i; ; var right : OclAny := Set{i + k - 1, n - 1}->min(); ; while ((left->compareTo(right)) < 0) do ( arr := swap(arr, left, right); ; left := left + 1; ; right := right - 1;)) ; return arr;; operation swap(arr : OclAny, i : OclAny, j : OclAny) pre: true post: true activity: var temp : OclAny := arr[i+1]; ; arr[i+1] := arr[j+1]; ; arr[j+1] := temp; ; return arr;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INT_MIN=-1000000 def printMaxOfMin(arr,n): for k in range(1,n+1): maxOfMin=INT_MIN ; for i in range(n-k+1): min=arr[i] for j in range(k): if(arr[i+j]maxOfMin): maxOfMin=min print(maxOfMin,end=" ") arr=[10,20,30,50,10,70,30] n=len(arr) printMaxOfMin(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INT_MIN : int := -1000000 ; skip ; arr := Sequence{10}->union(Sequence{20}->union(Sequence{30}->union(Sequence{50}->union(Sequence{10}->union(Sequence{70}->union(Sequence{ 30 })))))) ; n := (arr)->size() ; printMaxOfMin(arr, n); operation printMaxOfMin(arr : OclAny, n : OclAny) pre: true post: true activity: for k : Integer.subrange(1, n + 1-1) do ( var maxOfMin : int := INT_MIN; ; for i : Integer.subrange(0, n - k + 1-1) do ( var min : OclAny := arr[i+1] ; for j : Integer.subrange(0, k-1) do ( if ((arr[i + j+1]->compareTo(min)) < 0) then ( min := arr[i + j+1] ) else skip) ; if ((min->compareTo(maxOfMin)) > 0) then ( maxOfMin := min ) else skip) ; execute (maxOfMin)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) p=list(map(int,input().split())) s=list(map(int,input().split())) c=list(map(int,input().split())) d={} more_school=0 for i in range(n): if s[i]in d : d[s[i]].append(p[i]) else : d[s[i]]=[p[i]] for i in c : if max(d[s[i-1]])!=p[i-1]: more_school+=1 print(more_school) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := Set{} ; var more_school : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (d)->includes(s[i+1]) then ( (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))) ) else ( d[s[i+1]+1] := Sequence{ p[i+1] } )) ; for i : c do ( if (d[s[i - 1+1]+1])->max() /= p[i - 1+1] then ( more_school := more_school + 1 ) else skip) ; execute (more_school)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) p=list(map(int,input().split())) s=list(map(int,input().split())) c=list(map(int,input().split())) ans=0 for i in range(k): lst=[] for j in range(n): if s[j]==s[c[i]-1]: lst.append(p[j]) if max(lst)!=p[c[i]-1]: ans+=1 lst=[] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(0, k-1) do ( var lst : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( if s[j+1] = s[c[i+1] - 1+1] then ( execute ((p[j+1]) : lst) ) else skip) ; if (lst)->max() /= p[c[i+1] - 1+1] then ( ans := ans + 1 ) else skip ; lst := Sequence{}) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) powers,schools=list(map(int,input().split()))+[-1],list(map(int,input().split())), chosens=set(map(lambda x : powers[int(x)-1],input().split())) school,amount=[-1]*m,0 for i in range(n): if school[schools[i]-1]collect( _x | (OclType["int"])->apply(_x) ) ; var powers : OclAny := null; var schools : OclAny := null; Sequence{powers,schools} := Sequence{((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->union(Sequence{ -1 }),(testlist_star_expr (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))))) ,)} ; var chosens : Set := Set{}->union(((input().split())->collect( _x | (lambda x : OclAny in (powers[("" + ((x)))->toInteger() - 1+1]))->apply(_x) ))) ; var school : OclAny := null; var amount : OclAny := null; Sequence{school,amount} := Sequence{MatrixLib.elementwiseMult(Sequence{ -1 }, m),0} ; for i : Integer.subrange(0, n-1) do ( if (school[schools[i+1] - 1+1]->compareTo(powers[i+1])) < 0 then ( school[schools[i+1] - 1+1] := powers[i+1] ) else skip) ; for i : Integer.subrange(0, m-1) do ( chosens := chosens - Set{ school[i+1] }) ; execute ((chosens)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline s={} n,m,k=map(int,input().split()) w=list(map(int,input().split())) q=list(map(int,input().split())) x=list(map(int,input().split())) for i in range(n): if q[i]not in s : s[q[i]]=w[i] else : if s[q[i]]collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( if (s)->excludes(q[i+1]) then ( s[q[i+1]+1] := w[i+1] ) else ( if (s[q[i+1]+1]->compareTo(w[i+1])) < 0 then ( s[q[i+1]+1] := w[i+1] ) else skip )) ; var c : int := 0 ; for i : x do ( if (w[i - 1+1]->compareTo(s[q[i - 1+1]+1])) < 0 then ( c := c + 1 ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r=lambda :[*map(int,input().split())] n,m,k=r() p,s,c=r(),r(),r() a=[0]*m for x,y in zip(p,s): a[y-1]=max(a[y-1],x) print(sum(p[x-1]collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := r->apply() ; var p : OclAny := null; var s : OclAny := null; var c : OclAny := null; Sequence{p,s,c} := Sequence{r->apply(),r->apply(),r->apply()} ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; for _tuple : Integer.subrange(1, p->size())->collect( _indx | Sequence{p->at(_indx), s->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); a[y - 1+1] := Set{a[y - 1+1], x}->max()) ; execute (((argument (test (logical_test (comparison (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ])))) < (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ]))) - (expr (atom (number (integer 1)))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name c))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get(): return list(map(int,input().split())) def intput(): return int(input()) def main(): for _ in range(intput()): a=get() if(a[0]-a[1]==1): print('NO') else : print("YES") main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; main(); operation get() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation intput() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation main() pre: true post: true activity: for _anon : Integer.subrange(0, intput()-1) do ( var a : OclAny := get() ; if (a->first() - a[1+1] = 1) then ( execute ('NO')->display() ) else ( execute ("YES")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) height=0 cube=0 series=0 i=1 while cubetoInteger() ; var height : int := 0 ; var cube : int := 0 ; var series : int := 0 ; var i : int := 1 ; while (cube->compareTo(n)) < 0 do ( if (cube + series + i->compareTo(n)) <= 0 then ( height := height + 1 ; cube := cube + i + series ; series := series + i ; i := i + 1 ) else ( break )) ; execute (height)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=[*input()] q=int(input()) B={chr(97+i):[0]*(n+1)for i in range(26)} def bsum(c,i): s=0 while i : s+=B[c][i] i-=i &-i return s def badd(c,i,x): while i<=n : B[c][i]+=x i+=i &-i for i,c in enumerate(s): badd(c,i+1,1) for _ in range(q): x,y,z=input().split() y=int(y)-1 if x=='1' : badd(s[y],y+1,-1) s[y]=z badd(z,y+1,1) else : print(sum(1 for c in B if bsum(c,int(z))-bsum(c,y))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := (OclFile["System.in"]).readLine() ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : Map := Integer.subrange(0, 26-1)->select(i | true)->collect(i | Map{(97 + i)->byte2char() |-> MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1))})->unionAll() ; skip ; skip ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); badd(c, i + 1, 1)) ; for _anon : Integer.subrange(0, q-1) do ( var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := input().split() ; var y : double := ("" + ((y)))->toInteger() - 1 ; if x = '1' then ( badd(s[y+1], y + 1, -1) ; s[y+1] := z ; badd(z, y + 1, 1) ) else ( execute (((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name B))))) (comp_iter if (test (logical_test (comparison (expr (expr (atom (name bsum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c))))))) , (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name z)))))))) ))))))))) )))) - (expr (atom (name bsum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c))))))) , (argument (test (logical_test (comparison (expr (atom (name y)))))))) ))))))))))))->sum())->display() )); operation bsum(c : OclAny, i : OclAny) : OclAny pre: true post: true activity: s := 0 ; while i do ( s := s + B[c+1][i+1] ; i := i - MathLib.bitwiseAnd(i, -i)) ; return s; operation badd(c : OclAny, i : OclAny, x : OclAny) pre: true post: true activity: while (i->compareTo(n)) <= 0 do ( B[c+1][i+1] := B[c+1][i+1] + x ; i := i + MathLib.bitwiseAnd(i, -i)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAXN=10000000 def minimumSteps(n,m,a,b): if(n>m): return MAXN if(n==m): return 0 return min(1+minimumSteps(n*a,m,a,b),1+minimumSteps(n*b,m,a,b)) if __name__=='__main__' : n=120 m=51840 a=2 b=3 print(minimumSteps(n,m,a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAXN : int := 10000000 ; skip ; if __name__ = '__main__' then ( n := 120 ; m := 51840 ; a := 2 ; b := 3 ; execute (minimumSteps(n, m, a, b))->display() ) else skip; operation minimumSteps(n : OclAny, m : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if ((n->compareTo(m)) > 0) then ( return MAXN ) else skip ; if (n = m) then ( return 0 ) else skip ; return Set{1 + minimumSteps(n * a, m, a, b), 1 + minimumSteps(n * b, m, a, b)}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(s): if(len(s)>=10): return True for i in range(1,len(s)): for j in range(i+1,len(s)): for k in range(j+1,len(s)): s1=s[0 : i] s2=s[i : j-i] s3=s[j : k-j] s4=s[k : len(s)-k] if(s1!=s2 and s1!=s3 and s1!=s4 and s2!=s3 and s2!=s4 and s3!=s4): return True return False if __name__=='__main__' : str="aaabb" print("Yes")if(check(str))else print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var OclType["String"] : String := "aaabb" ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Yes"))))))) )))))) if (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name check)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)))))))) )))))))) ))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))) ) else skip; operation check(s : OclAny) : OclAny pre: true post: true activity: if ((s)->size() >= 10) then ( return true ) else skip ; for i : Integer.subrange(1, (s)->size()-1) do ( for j : Integer.subrange(i + 1, (s)->size()-1) do ( for k : Integer.subrange(j + 1, (s)->size()-1) do ( var s1 : OclAny := s.subrange(0+1, i) ; var s2 : OclAny := s.subrange(i+1, j - i) ; var s3 : OclAny := s.subrange(j+1, k - j) ; var s4 : OclAny := s.subrange(k+1, (s)->size() - k) ; if (s1 /= s2 & s1 /= s3 & s1 /= s4 & s2 /= s3 & s2 /= s4 & s3 /= s4) then ( return true ) else skip))) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def insertAtBottom(stack,item): if isEmpty(stack): push(stack,item) else : temp=pop(stack) insertAtBottom(stack,item) push(stack,temp) def reverse(stack): if not isEmpty(stack): temp=pop(stack) reverse(stack) insertAtBottom(stack,temp) def createStack(): stack=[] return stack def isEmpty(stack): return len(stack)==0 def push(stack,item): stack.append(item) def pop(stack): if(isEmpty(stack)): print("Stack Underflow ") exit(1) return stack.pop() def prints(stack): for i in range(len(stack)-1,-1,-1): print(stack[i],end=' ') print() stack=createStack() push(stack,str(4)) push(stack,str(3)) push(stack,str(2)) push(stack,str(1)) print("Original Stack ") prints(stack) reverse(stack) print("Reversed Stack ") prints(stack) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; stack := createStack() ; push(stack, ("" + ((4)))) ; push(stack, ("" + ((3)))) ; push(stack, ("" + ((2)))) ; push(stack, ("" + ((1)))) ; execute ("Original Stack ")->display() ; prints(stack) ; reverse(stack) ; execute ("Reversed Stack ")->display() ; prints(stack); operation insertAtBottom(stack : OclAny, item : OclAny) pre: true post: true activity: if isEmpty(stack) then ( push(stack, item) ) else ( var temp : OclAny := pop(stack) ; insertAtBottom(stack, item) ; push(stack, temp) ); operation reverse(stack : OclAny) pre: true post: true activity: if not(isEmpty(stack)) then ( temp := pop(stack) ; reverse(stack) ; insertAtBottom(stack, temp) ) else skip; operation createStack() : OclAny pre: true post: true activity: stack := Sequence{} ; return stack; operation isEmpty(stack : OclAny) : OclAny pre: true post: true activity: return (stack)->size() = 0; operation push(stack : OclAny, item : OclAny) pre: true post: true activity: execute ((item) : stack); operation pop(stack : OclAny) : OclAny pre: true post: true activity: if (isEmpty(stack)) then ( execute ("Stack Underflow ")->display() ; exit(1) ) else skip ; return stack->last(); operation prints(stack : OclAny) pre: true post: true activity: for i : Integer.subrange(-1 + 1, (stack)->size() - 1)->reverse() do ( execute (stack[i+1])->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_CHAR=256 def kthNonRepeating(str,k): n=len(str) count=[0]*MAX_CHAR index=[0]*MAX_CHAR for i in range(MAX_CHAR): count[i]=0 index[i]=n for i in range(n): x=str[i] count[ord(x)]+=1 if(count[ord(x)]==1): index[ord(x)]=i if(count[ord(x)]==2): index[ord(x)]=n index.sort() return index[k-1]if(index[k-1]!=n)else-1 if __name__=="__main__" : str="geeksforgeeks" k=3 res=kthNonRepeating(str,k) if(res==-1): print("There are less than k","non-repeating characters") else : print("k'th non-repeating character is",str[res]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_CHAR : int := 256 ; skip ; if __name__ = "__main__" then ( OclType["String"] := "geeksforgeeks" ; k := 3 ; var res : OclAny := kthNonRepeating(OclType["String"], k) ; if (res = -1) then ( execute ("There are less than k")->display() ) else ( execute ("k'th non-repeating character is")->display() ) ) else skip; operation kthNonRepeating(OclType["String"] : OclAny, k : OclAny) : OclAny pre: true post: true activity: var n : int := (OclType["String"])->size() ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX_CHAR) ; var index : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX_CHAR) ; for i : Integer.subrange(0, MAX_CHAR-1) do ( count[i+1] := 0 ; index[i+1] := n) ; for i : Integer.subrange(0, n-1) do ( var x : String := ("" + ([i+1])) ; count[(x)->char2byte()+1] := count[(x)->char2byte()+1] + 1 ; if (count[(x)->char2byte()+1] = 1) then ( index[(x)->char2byte()+1] := i ) else skip ; if (count[(x)->char2byte()+1] = 2) then ( index[(x)->char2byte()+1] := n ) else skip) ; index := index->sort() ; return if (index[k - 1+1] /= n) then index[k - 1+1] else -1 endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def findElements(arr,n): first=-sys.maxsize second=-sys.maxsize for i in range(0,n): if(arr[i]>first): second=first first=arr[i] elif(arr[i]>second): second=arr[i] for i in range(0,n): if(arr[i]union(Sequence{-6}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 1 })))) ; n := (arr)->size() ; findElements(arr, n); operation findElements(arr : OclAny, n : OclAny) pre: true post: true activity: var first : (trailer . (name maxsize)) := -(trailer . (name maxsize)) ; var second : (trailer . (name maxsize)) := -(trailer . (name maxsize)) ; for i : Integer.subrange(0, n-1) do ( if ((arr[i+1]->compareTo(first)) > 0) then ( second := first ; first := arr[i+1] ) else (if ((arr[i+1]->compareTo(second)) > 0) then ( second := arr[i+1] ) else skip)) ; for i : Integer.subrange(0, n-1) do ( if ((arr[i+1]->compareTo(second)) < 0) then ( execute (arr[i+1])->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sub_arrays(a,n,k): sum=[0 for i in range(n+2)] for i in range(n): a[i]-=1 a[i]%=k sum[i+1]+=sum[i]+a[i] sum[i+1]%=k ans=0 l=0 r=0 mp=dict() for i in range(n+1): if sum[i]in mp : ans+=mp[sum[i]] mp[sum[i]]=mp.get(sum[i],0)+1 r+=1 if(r-l>=k): mp[sum[l]]-=1 l+=1 return ans a=[1,4,2,3,5] n=len(a) k=4 print(sub_arrays(a,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{1}->union(Sequence{4}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 5 })))) ; n := (a)->size() ; k := 4 ; execute (sub_arrays(a, n, k))->display(); operation sub_arrays(a : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var sum : Sequence := Integer.subrange(0, n + 2-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( a[i+1] := a[i+1] - 1 ; a[i+1] := a[i+1] mod k ; [i + 1+1]->sum() := [i + 1+1]->sum() + [i+1]->sum() + a[i+1] ; [i + 1+1]->sum() := [i + 1+1]->sum() mod k) ; var ans : int := 0 ; var l : int := 0 ; var r : int := 0 ; var mp : Map := (arguments ( )) ; for i : Integer.subrange(0, n + 1-1) do ( if (mp)->includes([i+1]->sum()) then ( ans := ans + mp[[i+1]->sum()+1] ) else skip ; mp[[i+1]->sum()+1] := mp.get([i+1]->sum(), 0) + 1 ; r := r + 1 ; if ((r - l->compareTo(k)) >= 0) then ( mp[[l+1]->sum()+1] := mp[[l+1]->sum()+1] - 1 ; l := l + 1 ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lenDoubleString(s): l=len(s) first_half=s[0 : l//2] second_half="" if l % 2==0 : second_half=s[l//2 :] else : second_half=s[l//2+1 :] second_half=second_half[: :-1] print(first_half+second_half) if l % 2==0 : print(l) else : print(l-1) if __name__=="__main__" : n="abba" lenDoubleString(n) n="abcdedcba" lenDoubleString(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var n : String := "abba" ; lenDoubleString(n) ; n := "abcdedcba" ; lenDoubleString(n) ) else skip; operation lenDoubleString(s : OclAny) pre: true post: true activity: var l : int := (s)->size() ; var first_half : OclAny := s.subrange(0+1, l div 2) ; var second_half : String := "" ; if l mod 2 = 0 then ( second_half := s.subrange(l div 2+1) ) else ( second_half := s.subrange(l div 2 + 1+1) ) ; second_half := second_half(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; execute (first_half + second_half)->display() ; if l mod 2 = 0 then ( execute (l)->display() ) else ( execute (l - 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque while True : t,n=map(int,input().split()) if t==0 : break bans={tuple(map(int,input().split()))for _ in range(n)} sx,sy=map(int,input().split()) vec=((0,1),(1,1),(1,0),(0,-1),(-1,-1),(-1,0)) que=deque() que.append((t,sx,sy)) reached=set() reached.add((sx,sy)) while que : turn,x,y=que.popleft() if turn==0 : continue for dx,dy in vec : nx,ny=x+dx,y+dy if(nx,ny)not in reached and(nx,ny)not in bans : reached.add((nx,ny)) que.append((turn-1,nx,ny)) print(len(reached)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var t : OclAny := null; var n : OclAny := null; Sequence{t,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if t = 0 then ( break ) else skip ; var bans : Set := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->asSet() ; var sx : OclAny := null; var sy : OclAny := null; Sequence{sx,sy} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var vec : OclAny := Sequence{Sequence{0, 1}, Sequence{1, 1}, Sequence{1, 0}, Sequence{0, -1}, Sequence{-1, -1}, Sequence{-1, 0}} ; var que : Sequence := () ; execute ((Sequence{t, sx, sy}) : que) ; var reached : Set := Set{}->union(()) ; execute ((Sequence{sx, sy}) : reached) ; while que do ( var turn : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{turn,x,y} := que->first() ; que := que->tail() ; if turn = 0 then ( continue ) else skip ; for _tuple : vec do (var _indx : int := 1; var dx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dy : OclAny := _tuple->at(_indx); var nx : OclAny := null; var ny : OclAny := null; Sequence{nx,ny} := Sequence{x + dx,y + dy} ; if (reached)->excludes(Sequence{nx, ny}) & (bans)->excludes(Sequence{nx, ny}) then ( execute ((Sequence{nx, ny}) : reached) ; execute ((Sequence{turn - 1, nx, ny}) : que) ) else skip)) ; execute ((reached)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): x,y=list(map(int,input().split())) p=x-y if p % 2==0 or p % 2==1 and p!=1 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var p : double := x - y ; if p mod 2 = 0 or p mod 2 = 1 & p /= 1 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque import sys,heapq,bisect,math,itertools,string,queue,copy,time sys.setrecursionlimit(10**8) INF=float('inf') mod=10**9+7 eps=10**-7 def inp(): return int(input()) def inpl(): return list(map(int,input().split())) def inpl_str(): return list(input().split()) def bfs(x,y,c): global MAP global ans global q if MAP[x][y]!=0 or c>t : return else : q.append((x,y+1,c+1)) q.append((x,y-1,c+1)) q.append((x+1,y,c+1)) q.append((x-1,y,c+1)) q.append((x+1,y+1,c+1)) q.append((x-1,y-1,c+1)) while True : t,n=inpl() if t==0 and n==0 : break else : MAP=defaultdict(lambda : defaultdict(int)) for _ in range(n): x,y=inpl() MAP[x][y]=-1 sx,sy=inpl() ans=0 q=deque([(sx,sy,0)]) while q : x,y,c=q.popleft() if MAP[x][y]==0 and c<=t : ans+=1 bfs(x,y,c) MAP[x][y]=-1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute MAP : OclAny; attribute ans : OclAny; attribute q : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var eps : double := (10)->pow(-7) ; skip ; skip ; skip ; skip ; while true do ( var t : OclAny := null; var n : OclAny := null; Sequence{t,n} := inpl() ; if t = 0 & n = 0 then ( break ) else ( MAP := defaultdict(lambda $$ : OclAny in (defaultdict(OclType["int"]))) ; for _anon : Integer.subrange(0, n-1) do ( Sequence{x,y} := inpl() ; MAP[x+1][y+1] := -1) ; var sx : OclAny := null; var sy : OclAny := null; Sequence{sx,sy} := inpl() ; ans := 0 ; q := (Sequence{ Sequence{sx, sy, 0} }) ; while q do ( Sequence{x,y,c} := q->first() ; q := q->tail() ; if MAP[x+1][y+1] = 0 & (c->compareTo(t)) <= 0 then ( ans := ans + 1 ; bfs(x, y, c) ; MAP[x+1][y+1] := -1 ) else skip) ; execute (ans)->display() )); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inpl_str() : OclAny pre: true post: true activity: return (input().split()); operation bfs(x : OclAny, y : OclAny, c : OclAny) pre: true post: true activity: skip ; skip ; skip ; if MAP[x+1][y+1] /= 0 or (c->compareTo(t)) > 0 then ( return ) else ( execute ((Sequence{x, y + 1, c + 1}) : q) ; execute ((Sequence{x, y - 1, c + 1}) : q) ; execute ((Sequence{x + 1, y, c + 1}) : q) ; execute ((Sequence{x - 1, y, c + 1}) : q) ; execute ((Sequence{x + 1, y + 1, c + 1}) : q) ; execute ((Sequence{x - 1, y - 1, c + 1}) : q) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy while 1 : t,n=map(int,input().split()) if t==n==0 : break field=[[0 for i in range(2*t+1)]for j in range(2*t+1)] stone=[] for i in range(n): stone.append(list(map(int,input().split()))) x,y=map(int,input().split()) for xi,yi in stone : if 0<=t+xi-x<=2*t and 0<=t+yi-y<=2*t : field[t+xi-x][t+yi-y]=-1 field[t][t]=1 for k in range(t): field_c=copy.deepcopy(field) for i in range(2*t+1): for j in range(2*t+1): if field[i][j]>0 : field_c[i+1][j+1]=-1 if field_c[i+1][j+1]==-1 else 1 field_c[i+1][j]=-1 if field_c[i+1][j]==-1 else 1 field_c[i][j+1]=-1 if field_c[i][j+1]==-1 else 1 field_c[i-1][j-1]=-1 if field_c[i-1][j-1]==-1 else 1 field_c[i-1][j]=-1 if field_c[i-1][j]==-1 else 1 field_c[i][j-1]=-1 if field_c[i][j-1]==-1 else 1 field=field_c ct=[flatten for inner in field for flatten in inner] print(ct.count(1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while 1 do ( var t : OclAny := null; var n : OclAny := null; Sequence{t,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if t = n & (n == 0) then ( break ) else skip ; var field : Sequence := Integer.subrange(0, 2 * t + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, 2 * t + 1-1)->select(i | true)->collect(i | (0)))) ; var stone : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : stone)) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for _tuple : stone do (var _indx : int := 1; var xi : OclAny := _tuple->at(_indx); _indx := _indx + 1; var yi : OclAny := _tuple->at(_indx); if 0 <= t + xi - x & (t + xi - x <= 2 * t) & 0 <= t + yi - y & (t + yi - y <= 2 * t) then ( field[t + xi - x+1][t + yi - y+1] := -1 ) else skip) ; field[t+1][t+1] := 1 ; for k : Integer.subrange(0, t-1) do ( var field_c : OclAny := copy.deepcopy(field) ; for i : Integer.subrange(0, 2 * t + 1-1) do ( for j : Integer.subrange(0, 2 * t + 1-1) do ( if field[i+1][j+1] > 0 then ( field_c[i + 1+1][j + 1+1] := if field_c[i + 1+1][j + 1+1] = -1 then -1 else 1 endif ; field_c[i + 1+1][j+1] := if field_c[i + 1+1][j+1] = -1 then -1 else 1 endif ; field_c[i+1][j + 1+1] := if field_c[i+1][j + 1+1] = -1 then -1 else 1 endif ; field_c[i - 1+1][j - 1+1] := if field_c[i - 1+1][j - 1+1] = -1 then -1 else 1 endif ; field_c[i - 1+1][j+1] := if field_c[i - 1+1][j+1] = -1 then -1 else 1 endif ; field_c[i+1][j - 1+1] := if field_c[i+1][j - 1+1] = -1 then -1 else 1 endif ) else skip)) ; field := field_c) ; var ct : Sequence := field->select(inner; flatten : inner | true)->collect(inner; flatten : inner | (flatten)) ; execute (ct->count(1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : f=open("input.txt","r") n=int(f.readline()) students=list(f.readline()) f=open("output.txt","w") row=int(n/2) for i in range(row): a=students[i] if i+row<=n : b=students[i+row] arr=[[i+1,a],[i+row+1,b]] else : b=students[i-row] arr=[[i+1,a],[i-row-1,b]] arr.sort(key=lambda x : x[1]) print(arr[0][0],arr[1][0],file=f) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ; var n : int := ("" + ((f.readLine())))->toInteger() ; var students : Sequence := (f.readLine())->characters() ; f := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ; var row : int := ("" + ((n / 2)))->toInteger() ; for i : Integer.subrange(0, row-1) do ( var a : OclAny := students[i+1] ; if (i + row->compareTo(n)) <= 0 then ( var b : OclAny := students[i + row+1] ; var arr : Sequence := Sequence{Sequence{i + 1}->union(Sequence{ a })}->union(Sequence{ Sequence{i + row + 1}->union(Sequence{ b }) }) ) else ( b := students[i - row+1] ; arr := Sequence{Sequence{i + 1}->union(Sequence{ a })}->union(Sequence{ Sequence{i - row - 1}->union(Sequence{ b }) }) ) ; arr := arr->sort() ; execute (arr->first()->first())->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq as hq def bfs(x,y,t,Map): queue=[] hq.heappush(queue,(0,(x,y))) while len(queue)!=0 : p=hq.heappop(queue) x,y=p[1] if p[0]<=t and Map[y][x]==0 : Map[y][x]=1 dxdy=[(1,0),(-1,0),(0,1),(0,-1),(1,1),(-1,-1)] for dx,dy in dxdy : hq.heappush(queue,(p[0]+1,(x+dx,y+dy))) while True : t,n=map(int,input().split()) if t==0 and n==0 : break Map=[[0 for j in range(200)]for i in range(200)] for _ in range(n): x,y=map(lambda x : int(x)+100,input().split()) Map[y][x]=-1 x,y=map(lambda x : int(x)+100,input().split()) bfs(x,y,t,Map) print(sum([0 if Map[i][j]==-1 else Map[i][j]for i in range(200)for j in range(200)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( var n : OclAny := null; Sequence{t,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if t = 0 & n = 0 then ( break ) else skip ; Map := Integer.subrange(0, 200-1)->select(i | true)->collect(i | (Integer.subrange(0, 200-1)->select(j | true)->collect(j | (0)))) ; for _anon : Integer.subrange(0, n-1) do ( Sequence{x,y} := (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() + 100))->apply(_x) ) ; Map[y+1][x+1] := -1) ; Sequence{x,y} := (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() + 100))->apply(_x) ) ; bfs(x, y, t, Map) ; execute ((Integer.subrange(0, 200-1)->select(i; j : Integer.subrange(0, 200-1) | true)->collect(i; j : Integer.subrange(0, 200-1) | (if Map[i+1][j+1] = -1 then 0 else Map[i+1][j+1] endif)))->sum())->display()); operation bfs(x : OclAny, y : OclAny, t : OclAny, Map : OclAny) pre: true post: true activity: var queue : Sequence := Sequence{} ; hq.heappush(queue, Sequence{0, Sequence{x, y}}) ; while (queue)->size() /= 0 do ( var p : OclAny := hq.heappop(queue) ; Sequence{x,y} := p[1+1] ; if (p->first()->compareTo(t)) <= 0 & Map[y+1][x+1] = 0 then ( Map[y+1][x+1] := 1 ; var dxdy : Sequence := Sequence{Sequence{1, 0}}->union(Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{0, -1}}->union(Sequence{Sequence{1, 1}}->union(Sequence{ Sequence{-1, -1} }))))) ; for _tuple : dxdy do (var _indx : int := 1; var dx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dy : OclAny := _tuple->at(_indx); hq.heappush(queue, Sequence{p->first() + 1, Sequence{x + dx, y + dy}})) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque while True : t,n=map(int,input().split()) if t==0 and n==0 : break else : d=[[-1]*200 for _ in range(200)] for i in range(n): x,y=map(int,input().split()) d[x+100][y+100]=float("INF") sx,sy=map(int,input().split()) sx,sy=sx+100,sy+100 q=deque([]) q.append((sx,sy)) d[sx][sy]=0 while len(q)>0 : cur=q.popleft() curx,cury=cur[0],cur[1] for dx_ in range(-1,2): for dy_ in range(-1,2): if(dx_*dy_==-1)or(dx_==0 and dy_==0): continue else : nx,ny=curx+dx_,cury+dy_ if d[curx][cury]collect( _x | (OclType["int"])->apply(_x) ) ; if t = 0 & n = 0 then ( break ) else ( var d : Sequence := Integer.subrange(0, 200-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ -1 }, 200))) ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; d[x + 100+1][y + 100+1] := ("" + (("INF")))->toReal()) ; var sx : OclAny := null; var sy : OclAny := null; Sequence{sx,sy} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sx : OclAny := null; var sy : OclAny := null; Sequence{sx,sy} := Sequence{sx + 100,sy + 100} ; var q : Sequence := (Sequence{}) ; execute ((Sequence{sx, sy}) : q) ; d[sx+1][sy+1] := 0 ; while (q)->size() > 0 do ( var cur : OclAny := q->first() ; q := q->tail() ; var curx : OclAny := null; var cury : OclAny := null; Sequence{curx,cury} := Sequence{cur->first(),cur[1+1]} ; for dx_ : Integer.subrange(-1, 2-1) do ( for dy_ : Integer.subrange(-1, 2-1) do ( if (dx_ * dy_ = -1) or (dx_ = 0 & dy_ = 0) then ( continue ) else ( var nx : OclAny := null; var ny : OclAny := null; Sequence{nx,ny} := Sequence{curx + dx_,cury + dy_} ; if (d[curx+1][cury+1]->compareTo(t)) < 0 & 0 <= nx & (nx < 200) & 0 <= ny & (ny < 200) & d[nx+1][ny+1] = -1 then ( execute ((Sequence{nx, ny}) : q) ; d[nx+1][ny+1] := d[curx+1][cury+1] + 1 ) else skip )))) ; var ans : int := 0 ; for i : Integer.subrange(0, (d)->size()-1) do ( for ele : d[i+1] do ( if 0 <= ele & (ele <= t) then ( ans := ans + 1 ) else skip)) ; execute (ans)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import gcd def printResult(arr,n): count=0 for i in range(1,n): if(gcd(arr[i],arr[i-1])!=1): count+=1 print(count) print(arr[0],end=" ") for i in range(1,n): if(gcd(arr[i],arr[i-1])!=1): print(1,end=" ") print(arr[i],end=" ") A=[5,10,20] n=len(A) printResult(A,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var A : Sequence := Sequence{5}->union(Sequence{10}->union(Sequence{ 20 })) ; n := (A)->size() ; printResult(A, n); operation printResult(arr : OclAny, n : OclAny) pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(1, n-1) do ( if (gcd(arr[i+1], arr[i - 1+1]) /= 1) then ( count := count + 1 ) else skip) ; execute (count)->display() ; execute (arr->first())->display() ; for i : Integer.subrange(1, n-1) do ( if (gcd(arr[i+1], arr[i - 1+1]) /= 1) then ( execute (1)->display() ) else skip ; execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findOnBulbs(numberOfBulbs): onBulbs=0 bulb=1 person=1 for bulb in range(1,numberOfBulbs+1): factors=0 for person in range(1,int(numberOfBulbs**(0.5))+1): if bulb % person==0 : factors+=1 if bulb//person!=person : factors+=1 if factors % 2==1 : print("Light bulb",bulb,"will be on") onBulbs+=1 return onBulbs if __name__=="__main__" : numberOfBulbs=1000 onBulbs=findOnBulbs(numberOfBulbs) print("Total",onBulbs,"light bulbs will","be on in the end out of",numberOfBulbs,"light bulbs") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( numberOfBulbs := 1000 ; onBulbs := findOnBulbs(numberOfBulbs) ; execute ("Total")->display() ) else skip; operation findOnBulbs(numberOfBulbs : OclAny) : OclAny pre: true post: true activity: var onBulbs : int := 0 ; var bulb : int := 1 ; var person : int := 1 ; for bulb : Integer.subrange(1, numberOfBulbs + 1-1) do ( var factors : int := 0 ; for person : Integer.subrange(1, ("" + (((numberOfBulbs)->pow((0.5)))))->toInteger() + 1-1) do ( if bulb mod person = 0 then ( factors := factors + 1 ; if bulb div person /= person then ( factors := factors + 1 ) else skip ) else skip) ; if factors mod 2 = 1 then ( execute ("Light bulb")->display() ; onBulbs := onBulbs + 1 ) else skip) ; return onBulbs; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countOdd(L,R): N=(R-L)//2 if(R % 2!=0 or L % 2!=0): N+=1 return N if __name__=="__main__" : L=3 R=7 odds=countOdd(L,R) evens=(R-L+1)-odds print("Count of odd numbers is",odds) print("Count of even numbers is",evens) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( L := 3 ; R := 7 ; var odds : OclAny := countOdd(L, R) ; var evens : double := (R - L + 1) - odds ; execute ("Count of odd numbers is")->display() ; execute ("Count of even numbers is")->display() ) else skip; operation countOdd(L : OclAny, R : OclAny) : OclAny pre: true post: true activity: var N : int := (R - L) div 2 ; if (R mod 2 /= 0 or L mod 2 /= 0) then ( N := N + 1 ) else skip ; return N; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxAND(L,R): if(L==R): return L ; elif((R-L)==1): return(R & L); else : if(((R-1)& R)>((R-2)&(R-1))): return((R-1)& R); else : return((R-2)&(R-1)); L=1 ; R=632 ; print(maxAND(L,R)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; L := 1; ; R := 632; ; execute (maxAND(L, R))->display();; operation maxAND(L : OclAny, R : OclAny) pre: true post: true activity: if (L = R) then ( return L; ) else (if ((R - L) = 1) then ( return (MathLib.bitwiseAnd(R, L)); ) else ( if (((MathLib.bitwiseAnd((R - 1), R))->compareTo((MathLib.bitwiseAnd((R - 2), (R - 1))))) > 0) then ( return (MathLib.bitwiseAnd((R - 1), R)); ) else ( return (MathLib.bitwiseAnd((R - 2), (R - 1))); ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def v_block(): block.insert(0,[' ']*5) for l,line in enumerate(block): if line[q-1 : q+p-1]!=[' ']*p : break else : l+=1 block[l-1][q-1 : q+p-1]=['*']*p return delete() def h_block(): for _p in range(p): block.insert(0,[' ']*5) for l,line in enumerate(block): if line[q-1]=='*' : break else : l+=1 for _l in range(l-1,l-p-1,-1): block[_l][q-1]='*' return delete() def delete(): l=0 while True : if block[l]==[' ']*5 or block[l]==['*']*5 : del block[l] else : l+=1 if len(block)==l : return def count(): x=0 for line in block : for b in line : if b=='*' : x+=1 else : print(x) while True : n=int(input()) if n==0 : break block=[[' ']*5] for i in range(n): d,p,q=map(int,input().split()) if d==1 : v_block() else : h_block() else : count() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var block : Sequence := Sequence{ MatrixLib.elementwiseMult(Sequence{ ' ' }, 5) } ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name d)))))) , (test (logical_test (comparison (expr (atom (name p)))))) , (test (logical_test (comparison (expr (atom (name q))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name d)))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name v_block)) (trailer (arguments ( ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name h_block)) (trailer (arguments ( ))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name count)) (trailer (arguments ( )))))))))))))))); operation v_block() : OclAny pre: true post: true activity: block := block.insertAt(0+1, MatrixLib.elementwiseMult(Sequence{ ' ' }, 5)) ; (compound_stmt for (exprlist (expr (atom (name l))) , (expr (atom (name line)))) in (testlist (test (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name block)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name line)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name q))) - (expr (atom (number (integer 1)))))))) : (test (logical_test (comparison (expr (expr (expr (atom (name q))) + (expr (atom (name p)))) - (expr (atom (number (integer 1)))))))))) ])))) != (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom ' ')))))) ])) * (expr (atom (name p)))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) ; block[l - 1+1].subrange(q - 1+1, q + p - 1) := MatrixLib.elementwiseMult(Sequence{ '*' }, p) ; return delete(); operation h_block() : OclAny pre: true post: true activity: for _p : Integer.subrange(0, p-1) do ( block := block.insertAt(0+1, MatrixLib.elementwiseMult(Sequence{ ' ' }, 5))) ; (compound_stmt for (exprlist (expr (atom (name l))) , (expr (atom (name line)))) in (testlist (test (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name block)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name line)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name q))) - (expr (atom (number (integer 1)))))))))) ])))) == (comparison (expr (atom '*')))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) ; for _l : Integer.subrange(l - p - 1 + 1, l - 1)->reverse() do ( block[_l+1][q - 1+1] := '*') ; return delete(); operation delete() pre: true post: true activity: var l : int := 0 ; while true do ( if block[l+1] = MatrixLib.elementwiseMult(Sequence{ ' ' }, 5) or block[l+1] = MatrixLib.elementwiseMult(Sequence{ '*' }, 5) then ( execute (block[l+1])->isDeleted() ) else ( l := l + 1 ) ; if (block)->size() = l then ( return ) else skip); operation count() pre: true post: true activity: var x : int := 0 ; (compound_stmt for (exprlist (expr (atom (name line)))) in (testlist (test (logical_test (comparison (expr (atom (name block))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name b)))) in (testlist (test (logical_test (comparison (expr (atom (name line))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name b)))) == (comparison (expr (atom '*')))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.buffer.readline p=998244353 def power(x,y,p): b=bin(y)[2 :] start=(x % p) answer=1 for i in range(len(b)): if b[len(b)-1-i]=='1' : answer=(answer*start)% p start=(start*start)% p return answer fact_dict={0 : 1} for i in range(1,300*10**3+1): fact_dict[i]=(fact_dict[i-1]*i)% p def binom(a,b): num=fact_dict[a] den=(fact_dict[b]*fact_dict[a-b])% p den1=power(den,p-2,p) return(num*den1)% p def process(A): n=len(A) A.sort() answer=0 d=binom(n,n//2) A=[int(x)% p for x in A] for i in range(n//2): answer=(answer-d*A[i])% p for i in range(n//2,n): answer=(answer+d*A[i])% p return answer n=input() A=list(map(int,input().split())) print(process(A)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := sys.stdin.buffer.readline ; var p : int := 998244353 ; skip ; var fact_dict : Map := Map{ 0 |-> 1 } ; for i : Integer.subrange(1, 300 * (10)->pow(3) + 1-1) do ( fact_dict[i+1] := (fact_dict[i - 1+1] * i) mod p) ; skip ; skip ; n := (OclFile["System.in"]).readLine() ; A := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (process(A))->display(); operation power(x : OclAny, y : OclAny, p : OclAny) : OclAny pre: true post: true activity: var b : OclAny := bin(y).subrange(2+1) ; var start : int := (x mod p) ; var answer : int := 1 ; for i : Integer.subrange(0, (b)->size()-1) do ( if b[(b)->size() - 1 - i+1] = '1' then ( answer := (answer * start) mod p ) else skip ; start := (start * start) mod p) ; return answer; operation binom(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var num : OclAny := fact_dict[a+1] ; var den : int := (fact_dict[b+1] * fact_dict[a - b+1]) mod p ; var den1 : OclAny := power(den, p - 2, p) ; return (num * den1) mod p; operation process(A : OclAny) : OclAny pre: true post: true activity: var n : int := (A)->size() ; A := A->sort() ; answer := 0 ; var d : OclAny := binom(n, n div 2) ; A := A->select(x | true)->collect(x | (("" + ((x)))->toInteger() mod p)) ; for i : Integer.subrange(0, n div 2-1) do ( answer := (answer - d * A[i+1]) mod p) ; for i : Integer.subrange(n div 2, n-1) do ( answer := (answer + d * A[i+1]) mod p) ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) while n>0 : n-=1 a,b=map(int,input().split()) d=a-b if d>1 : print('yes') else : print('no') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while n > 0 do ( n := n - 1 ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : double := a - b ; if d > 1 then ( execute ('yes')->display() ) else ( execute ('no')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def v_block(): block.insert(0,[' ']*5) for l,line in enumerate(block): if line[q-1 : q+p-1]!=[' ']*p : break else : l+=1 block[l-1][q-1 : q+p-1]=['*']*p return delete() def h_block(): for _p in range(p): block.insert(0,[' ']*5) for l,line in enumerate(block): if line[q-1]=='*' : break else : l+=1 for _l in range(l-1,l-p-1,-1): block[_l][q-1]='*' return delete() def delete(): b=len(block) l=0 while 0toInteger() ; if n = 0 then ( break ) else skip ; var block : Sequence := Sequence{ MatrixLib.elementwiseMult(Sequence{ ' ' }, 5) } ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name d)))))) , (test (logical_test (comparison (expr (atom (name p)))))) , (test (logical_test (comparison (expr (atom (name q))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name d)))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name v_block)) (trailer (arguments ( ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name h_block)) (trailer (arguments ( ))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name count)) (trailer (arguments ( )))))))))))))))); operation v_block() : OclAny pre: true post: true activity: block := block.insertAt(0+1, MatrixLib.elementwiseMult(Sequence{ ' ' }, 5)) ; (compound_stmt for (exprlist (expr (atom (name l))) , (expr (atom (name line)))) in (testlist (test (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name block)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name line)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name q))) - (expr (atom (number (integer 1)))))))) : (test (logical_test (comparison (expr (expr (expr (atom (name q))) + (expr (atom (name p)))) - (expr (atom (number (integer 1)))))))))) ])))) != (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom ' ')))))) ])) * (expr (atom (name p)))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) ; block[l - 1+1].subrange(q - 1+1, q + p - 1) := MatrixLib.elementwiseMult(Sequence{ '*' }, p) ; return delete(); operation h_block() : OclAny pre: true post: true activity: for _p : Integer.subrange(0, p-1) do ( block := block.insertAt(0+1, MatrixLib.elementwiseMult(Sequence{ ' ' }, 5))) ; (compound_stmt for (exprlist (expr (atom (name l))) , (expr (atom (name line)))) in (testlist (test (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name block)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name line)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name q))) - (expr (atom (number (integer 1)))))))))) ])))) == (comparison (expr (atom '*')))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) ; for _l : Integer.subrange(l - p - 1 + 1, l - 1)->reverse() do ( block[_l+1][q - 1+1] := '*') ; return delete(); operation delete() pre: true post: true activity: var b : int := (block)->size() ; var l : int := 0 ; while 0 < b do ( if block[l+1] = MatrixLib.elementwiseMult(Sequence{ ' ' }, 5) or block[l+1] = MatrixLib.elementwiseMult(Sequence{ '*' }, 5) then ( execute (block[l+1])->isDeleted() ) else ( l := l + 1 ) ; b := b - 1); operation count() pre: true post: true activity: var x : int := 0 ; (compound_stmt for (exprlist (expr (atom (name line)))) in (testlist (test (logical_test (comparison (expr (atom (name block))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name b)))) in (testlist (test (logical_test (comparison (expr (atom (name line))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name b)))) == (comparison (expr (atom '*')))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): from bisect import bisect_left from sys import stdin f_i=stdin while True : n=int(f_i.readline()) if n==0 : break b=[[0]for i in range(5)] for i in range(n): d,p,q=map(int,f_i.readline().split()) q-=1 if d==1 : if p==5 : continue h=0 for c in b[q : q+p]: if c[-1]>h : h=c[-1] h+=1 for c in b[: q]+b[q+p :]: if h not in c : for c in b[q : q+p]: c.append(h) break else : for c in b[: q]+b[q+p :]: idx=bisect_left(c,h) c.pop(idx) for j in range(idx,len(c)): c[j]-=1 else : h=b[q][-1]+1 b[q]+=list(range(h,h+p)) diff=0 for x in range(h,h+p): x+=diff for c in b[: q]+b[q+1 :]: if x not in c : break else : for c in b : idx=bisect_left(c,x) c.pop(idx) for j in range(idx,len(c)): c[j]-=1 diff-=1 print(sum(map(len,b))-5) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: skip ; skip ; var f_i : OclAny := stdin ; while true do ( var n : int := ("" + ((f_i.readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var b : Sequence := Integer.subrange(0, 5-1)->select(i | true)->collect(i | (Sequence{ 0 })) ; for i : Integer.subrange(0, n-1) do ( var d : OclAny := null; var p : OclAny := null; var q : OclAny := null; Sequence{d,p,q} := (f_i.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; q := q - 1 ; if d = 1 then ( if p = 5 then ( continue ) else skip ; var h : int := 0 ; for c : b.subrange(q+1, q + p) do ( if (c->last()->compareTo(h)) > 0 then ( h := c->last() ) else skip) ; h := h + 1 ; (compound_stmt for (exprlist (expr (atom (name c)))) in (testlist (test (logical_test (comparison (expr (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name q)))))))) ]))) + (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name q))) + (expr (atom (name p))))))) :)) ])))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name h)))) not in (comparison (expr (atom (name c))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name c)))) in (testlist (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name q)))))) : (test (logical_test (comparison (expr (expr (atom (name q))) + (expr (atom (name p))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name h)))))))) ))))))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt for (exprlist (expr (atom (name c)))) in (testlist (test (logical_test (comparison (expr (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name q)))))))) ]))) + (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name q))) + (expr (atom (name p))))))) :)) ])))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name idx)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name bisect_left)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c))))))) , (argument (test (logical_test (comparison (expr (atom (name h)))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)) (trailer . (name pop) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name idx)))))))) )))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name idx))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))))))))) ) else ( h := b[q+1]->last() + 1 ; b[q+1] := b[q+1] + (Integer.subrange(h, h + p-1)) ; var diff : int := 0 ; for x : Integer.subrange(h, h + p-1) do ( x := x + diff ; (compound_stmt for (exprlist (expr (atom (name c)))) in (testlist (test (logical_test (comparison (expr (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name q)))))))) ]))) + (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name q))) + (expr (atom (number (integer 1)))))))) :)) ])))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name x)))) not in (comparison (expr (atom (name c))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt for (exprlist (expr (atom (name c)))) in (testlist (test (logical_test (comparison (expr (atom (name b))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name idx)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name bisect_left)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c))))))) , (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)) (trailer . (name pop) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name idx)))))))) )))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name idx))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name diff)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))))) )) ; execute (((b)->collect( _x | (len)->apply(_x) ))->sum() - 5)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- prime=[True]*(1000000+5) def findPrime(): prime[0],prime[1]=False,False for p in range(2,1001): if prime[p]==True : for i in range(p*2,1000001,p): prime[i]=False def lenOfLongSubarr(arr,n): um={} Sum,maxLen=0,0 for i in range(0,n): Sum=Sum-1 if prime[arr[i]]==False else Sum+1 if Sum==1 : maxLen=i+1 elif Sum not in um : um[Sum]=i if(Sum-1)in um : if maxLen<(i-um[Sum-1]): maxLen=i-um[Sum-1] return maxLen if __name__=="__main__" : findPrime() arr=[1,9,3,4,5,6,7,8] n=len(arr) print(lenOfLongSubarr(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (1000000 + 5)) ; skip ; skip ; if __name__ = "__main__" then ( findPrime() ; arr := Sequence{1}->union(Sequence{9}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 8 }))))))) ; n := (arr)->size() ; execute (lenOfLongSubarr(arr, n))->display() ) else skip; operation findPrime() pre: true post: true activity: var prime->first() : OclAny := null; var prime[1+1] : OclAny := null; Sequence{prime->first(),prime[1+1]} := Sequence{false,false} ; for p : Integer.subrange(2, 1001-1) do ( if prime[p+1] = true then ( for i : Integer.subrange(p * 2, 1000001-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip); operation lenOfLongSubarr(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var um : OclAny := Set{} ; var Sum : OclAny := null; var maxLen : OclAny := null; Sequence{Sum,maxLen} := Sequence{0,0} ; for i : Integer.subrange(0, n-1) do ( var Sum : double := if prime[arr[i+1]+1] = false then Sum - 1 else Sum + 1 endif ; if Sum = 1 then ( var maxLen : OclAny := i + 1 ) else (if (um)->excludes(Sum) then ( um[Sum+1] := i ) else skip) ; if (um)->includes((Sum - 1)) then ( if (maxLen->compareTo((i - um[Sum - 1+1]))) < 0 then ( maxLen := i - um[Sum - 1+1] ) else skip ) else skip) ; return maxLen; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=open('input.txt','r') n=int(f.readline()) s=f.readline() f.close() f=open('output.txt','w') i=1 while i<=n/2 : if s[i-1]=='R' and s[i+n//2-1]=='L' : f.write(str(i+n//2)+' '+str(i)+'\n') else : f.write(str(i)+' '+str(i+n//2)+'\n') i+=1 f.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('input.txt')) ; var n : int := ("" + ((f.readLine())))->toInteger() ; var s : String := f.readLine() ; f.closeFile() ; f := OclFile.newOclFile_Write(OclFile.newOclFile('output.txt')) ; var i : int := 1 ; while (i->compareTo(n / 2)) <= 0 do ( if s[i - 1+1] = 'R' & s[i + n div 2 - 1+1] = 'L' then ( f.write(("" + ((i + n div 2))) + ' ' + ("" + ((i))) + ' ') ) else ( f.write(("" + ((i))) + ' ' + ("" + ((i + n div 2))) + ' ') ) ; i := i + 1) ; f.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): x=int(input()) if x<1400 : print("Division",4) elif x<1600 : print("Division",3) elif x<1900 : print("Division",2) else : print("Division",1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if x < 1400 then ( execute ("Division")->display() ) else (if x < 1600 then ( execute ("Division")->display() ) else (if x < 1900 then ( execute ("Division")->display() ) else ( execute ("Division")->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for p in range(int(input())): a=int(input()) n=a if(n>=1900): print("Division 1") elif(n>=1600 and n<=1899): print("Division 2") elif(n>=1400 and n<=1599): print("Division 3") else : print("Division 4") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for p : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := a ; if (n >= 1900) then ( execute ("Division 1")->display() ) else (if (n >= 1600 & n <= 1899) then ( execute ("Division 2")->display() ) else (if (n >= 1400 & n <= 1599) then ( execute ("Division 3")->display() ) else ( execute ("Division 4")->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): k=int(input()) if k>=1900 : print('Division 1') if k<=1899 and k>=1600 : print('Division 2') if k<=1599 and k>=1400 : print('Division 3') if k<=1399 : print('Division 4') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if k >= 1900 then ( execute ('Division 1')->display() ) else skip ; if k <= 1899 & k >= 1600 then ( execute ('Division 2')->display() ) else skip ; if k <= 1599 & k >= 1400 then ( execute ('Division 3')->display() ) else skip ; if k <= 1399 then ( execute ('Division 4')->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): r=int(input()) if r>=1900 : print("Division 1") elif 1600<=r<=1899 : print("Division 2") elif 1400<=r<=1599 : print("Division 3") else : print("Division 4") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var r : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if r >= 1900 then ( execute ("Division 1")->display() ) else (if 1600 <= r & (r <= 1899) then ( execute ("Division 2")->display() ) else (if 1400 <= r & (r <= 1599) then ( execute ("Division 3")->display() ) else ( execute ("Division 4")->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) if(1900<=n): print('Division'+' '+'1') elif(1600<=n<=1899): print('Division'+' '+'2') elif(1400<=n<=1599): print('Division'+' '+'3') elif(n<=1399): print('Division'+' '+'4') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (1900 <= n) then ( execute ('Division' + ' ' + '1')->display() ) else (if (1600 <= n & (n <= 1899)) then ( execute ('Division' + ' ' + '2')->display() ) else (if (1400 <= n & (n <= 1599)) then ( execute ('Division' + ' ' + '3')->display() ) else (if (n <= 1399) then ( execute ('Division' + ' ' + '4')->display() ) else skip ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) a=[0 for _ in range(n)] b=[0 for _ in range(n)] for i in range(n): _a,_b=map(int,input().split()) a[i]=_a b[i]=_b counter=0 for i in range(n): a[-(i+1)]+=counter if a[-(i+1)]% b[-(i+1)]==0 : pass else : counter+=(b[-(i+1)]-(a[-(i+1)]% b[-(i+1)])) print(counter) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)) ; var b : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)) ; for i : Integer.subrange(0, n-1) do ( var _a : OclAny := null; var _b : OclAny := null; Sequence{_a,_b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a[i+1] := _a ; b[i+1] := _b) ; var counter : int := 0 ; for i : Integer.subrange(0, n-1) do ( a->reverse()->at(-(-(i + 1))) := a->reverse()->at(-(-(i + 1))) + counter ; if a->reverse()->at(-(-(i + 1))) mod b->reverse()->at(-(-(i + 1))) = 0 then ( skip ) else ( counter := counter + (b->reverse()->at(-(-(i + 1))) - (a->reverse()->at(-(-(i + 1))) mod b->reverse()->at(-(-(i + 1))))) )) ; execute (counter)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): x,y=map(int,input().split()) dif=x-y if dif!=1 : if dif % 2==1 or dif % 2==0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dif : double := x - y ; if dif /= 1 then ( if dif mod 2 = 1 or dif mod 2 = 0 then ( execute ("YES")->display() ) else skip ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans=0 for A,B in[map(int,input().split())for _ in range(int(input()))][: :-1]: ans+=(B-A-ans)% B print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ans : int := 0 ; for _tuple : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1)->select(_anon | true)->collect(_anon | ((input().split())->collect( _x | (OclType["int"])->apply(_x) )))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do (var _indx : int := 1; var A : OclAny := _tuple->at(_indx); _indx := _indx + 1; var B : OclAny := _tuple->at(_indx); ans := ans + (B - A - ans) mod B) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 N=int(input()) A=[] B=[] for i in range(N): a,b=map(int,input().split()) A.append(a) B.append(b) A.reverse() B.reverse() inc=0 for i in range(N): A[i]+=inc x=A[i]% B[i] if x==0 : continue diff=B[i]-x inc+=diff print(inc) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit(2147483647) ; var INF : double := ("" + (("inf")))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := Sequence{} ; var B : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a) : A) ; execute ((b) : B)) ; A := A->reverse() ; B := B->reverse() ; var inc : int := 0 ; for i : Integer.subrange(0, N-1) do ( A[i+1] := A[i+1] + inc ; var x : int := A[i+1] mod B[i+1] ; if x = 0 then ( continue ) else skip ; var diff : double := B[i+1] - x ; inc := inc + diff) ; execute (inc)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ii(): return int(input()) def iim(): return map(int,input().split()) def iil(): return list(map(int,input().split())) def ism(): return map(str,input().split()) def isl(): return list(map(str,input().split())) n=ii() l=[] for _ in range(n): l.append(iil()) ans=0 for item in l[: :-1]: a=item[0]+ans if a % item[1]!=0 : ans+=item[1]-a % item[1] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var n : OclAny := ii() ; var l : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((iil()) : l)) ; var ans : int := 0 ; for item : l(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( var a : OclAny := item->first() + ans ; if a mod item[1+1] /= 0 then ( ans := ans + item[1+1] - a mod item[1+1] ) else skip) ; execute (ans)->display(); operation ii() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation iim() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation iil() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ism() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["String"])->apply(_x) ); operation isl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["String"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,random def Main(n): A,B=[],[] for _ in range(n): a,b=map(int,input().split()) A.append(a) B.append(b) cnt=0 for i in reversed(range(n)): A[i]+=cnt if A[i]% B[i]!=0 : cnt+=B[i]-(A[i]% B[i]) print(cnt) if __name__=='__main__' : T=int(input()) Main(T) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; Main(T) ) else skip; operation Main(n : OclAny) pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := Sequence{Sequence{},Sequence{}} ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a) : A) ; execute ((b) : B)) ; var cnt : int := 0 ; for i : (Integer.subrange(0, n-1))->reverse() do ( A[i+1] := A[i+1] + cnt ; if A[i+1] mod B[i+1] /= 0 then ( cnt := cnt + B[i+1] - (A[i+1] mod B[i+1]) ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from sys import stdin,stdout def main(): sys.stdin=open('input.txt','r') sys.stdout=open('output.txt','w') n=int(input()) alp=input() for i in range(n//2): a=alp[i] b=alp[i+n//2] if a=='R' and b=='L' : print(i+n//2+1,i+1) else : print(i+1,i+n//2+1) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('input.txt')) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile('output.txt')) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var alp : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, n div 2-1) do ( var a : OclAny := alp[i+1] ; var b : OclAny := alp[i + n div 2+1] ; if a = 'R' & b = 'L' then ( execute (i + n div 2 + 1)->display() ) else ( execute (i + 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_CHAR=26 def removeChars(arr,k): hash=[0]*MAX_CHAR n=len(arr) for i in range(n): hash[ord(arr[i])-ord('a')]+=1 ans="" index=0 for i in range(n): if(hash[ord(arr[i])-ord('a')]!=k): ans+=arr[i] return ans if __name__=="__main__" : str="geeksforgeeks" k=2 print(removeChars(str,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_CHAR : int := 26 ; skip ; if __name__ = "__main__" then ( var OclType["String"] : String := "geeksforgeeks" ; k := 2 ; execute (removeChars(OclType["String"], k))->display() ) else skip; operation removeChars(arr : OclAny, k : OclAny) : OclAny pre: true post: true activity: var hash : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX_CHAR) ; var n : int := (arr)->size() ; for i : Integer.subrange(0, n-1) do ( hash[(arr[i+1])->char2byte() - ('a')->char2byte()+1] := hash[(arr[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; var ans : String := "" ; var index : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (hash[(arr[i+1])->char2byte() - ('a')->char2byte()+1] /= k) then ( ans := ans + arr[i+1] ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def decimalToBinary(N): B_Number=0 cnt=0 while(N!=0): rem=N % 2 c=pow(10,cnt) B_Number+=rem*c N//=2 cnt+=1 return B_Number N=17 print(decimalToBinary(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 17 ; execute (decimalToBinary(N))->display(); operation decimalToBinary(N : OclAny) : OclAny pre: true post: true activity: var B_Number : int := 0 ; var cnt : int := 0 ; while (N /= 0) do ( var rem : int := N mod 2 ; var c : double := (10)->pow(cnt) ; B_Number := B_Number + rem * c ; N := N div 2 ; cnt := cnt + 1) ; return B_Number; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=1000000 phi=[0 for i in range(N+5)] def computeTotient(): for i in range(1,N+1): phi[i]=i for p in range(2,N+1): if(phi[p]==p): phi[p]=p-1 for i in range(2*p,N+1,p): phi[i]=(phi[i]//p)*(p-1) def power(x,y,p): res=1 x=x % p while(y>0): if(y & 1): res=(res*x)% p y=y>>1 x=(x*x)% p return res def calculate(x,k,mod): arr=[0 for i in range(N)] count=0 while(mod>1): arr[count]=mod count+=1 mod=phi[mod] result=1 loop=count+1 arr[count]=1 for i in range(min(k,loop),-1,-1): result=power(x,result,arr[i]) return result computeTotient() x=3 k=2 m=3 print(calculate(x,k,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 1000000 ; var phi : Sequence := Integer.subrange(0, N + 5-1)->select(i | true)->collect(i | (0)) ; skip ; skip ; skip ; computeTotient() ; x := 3 ; k := 2 ; var m : int := 3 ; execute (calculate(x, k, m))->display(); operation computeTotient() pre: true post: true activity: for i : Integer.subrange(1, N + 1-1) do ( phi[i+1] := i) ; for p : Integer.subrange(2, N + 1-1) do ( if (phi[p+1] = p) then ( phi[p+1] := p - 1 ; for i : Integer.subrange(2 * p, N + 1-1)->select( $x | ($x - 2 * p) mod p = 0 ) do ( phi[i+1] := (phi[i+1] div p) * (p - 1)) ) else skip); operation power(x : OclAny, y : OclAny, p : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; x := x mod p ; while (y > 0) do ( if (MathLib.bitwiseAnd(y, 1)) then ( res := (res * x) mod p ) else skip ; y := y /(2->pow(1)) ; x := (x * x) mod p) ; return res; operation calculate(x : OclAny, k : OclAny, mod : OclAny) : OclAny pre: true post: true activity: var arr : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; var count : int := 0 ; while (mod > 1) do ( arr[count+1] := mod ; count := count + 1 ; mod := phi[mod+1]) ; var result : int := 1 ; var loop : int := count + 1 ; arr[count+1] := 1 ; for i : Integer.subrange(-1 + 1, Set{k, loop}->min())->reverse() do ( result := power(x, result, arr[i+1])) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break to=[] fr=[[]for _ in range(n*n)] for i in range(n): line=list(map(int,input().split())) for j in range(n): x,y=line[2*j : 2*j+2] to.append(y*n+x) fr[y*n+x].append(i*n+j) order=[] used=[False]*(n*n) def dfs(x): if used[x]: return used[x]=True dfs(to[x]) order.append(x) for i in range(n*n): dfs(i) def dfs2(x,used,group): if used[x]: return used[x]=True for f in fr[x]: dfs2(f,used,group) group.append(x) used=[False]*(n*n) ans=0 for i in order : group=[] if not used[i]: dfs2(i,used,group) if len(group)>=1 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var to : Sequence := Sequence{} ; var fr : Sequence := Integer.subrange(0, n * n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, n-1) do ( var line : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := line.subrange(2 * j+1, 2 * j + 2) ; execute ((y * n + x) : to) ; (expr (atom (name fr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name y))) * (expr (atom (name n)))) + (expr (atom (name x))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name i))) * (expr (atom (name n)))) + (expr (atom (name j))))))))) )))))) ; var order : Sequence := Sequence{} ; var used : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (n * n)) ; skip ; for i : Integer.subrange(0, n * n-1) do ( dfs(i)) ; skip ; used := MatrixLib.elementwiseMult(Sequence{ false }, (n * n)) ; var ans : int := 0 ; for i : order do ( group := Sequence{} ; if not(used[i+1]) then ( dfs2(i, used, group) ) else skip ; if (group)->size() >= 1 then ( ans := ans + 1 ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break to=[] fr=[[]for _ in range(n*n)] for i in range(n): line=list(map(int,input().split())) for j in range(n): x,y=line[2*j : 2*j+2] to.append(y*n+x) fr[y*n+x].append(i*n+j) order=[] used=[False]*(n*n) def dfs(x): if used[x]: return used[x]=True dfs(to[x]) order.append(x) for i in range(n*n): dfs(i) order.reverse() def dfs2(x,used,group): if used[x]: return False if x in group : return True group.append(x) ret=False ret=ret or dfs2(to[x],used,group) return ret used=[False]*(n*n) ans=0 for i in order : group=[] if not used[i]: if dfs2(i,used,group): ans+=1 for g in group : used[g]=True print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var to : Sequence := Sequence{} ; var fr : Sequence := Integer.subrange(0, n * n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, n-1) do ( var line : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := line.subrange(2 * j+1, 2 * j + 2) ; execute ((y * n + x) : to) ; (expr (atom (name fr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name y))) * (expr (atom (name n)))) + (expr (atom (name x))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name i))) * (expr (atom (name n)))) + (expr (atom (name j))))))))) )))))) ; var order : Sequence := Sequence{} ; var used : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (n * n)) ; skip ; for i : Integer.subrange(0, n * n-1) do ( dfs(i)) ; order := order->reverse() ; skip ; used := MatrixLib.elementwiseMult(Sequence{ false }, (n * n)) ; var ans : int := 0 ; for i : order do ( group := Sequence{} ; if not(used[i+1]) then ( if dfs2(i, used, group) then ( ans := ans + 1 ) else skip ) else skip ; for g : group do ( used[g+1] := true)) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): x,y=map(int,input().split()) if(x-y>1): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (x - y > 1) then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break to=[] for i in range(n): line=list(map(int,input().split())) for j in range(n): x,y=line[2*j : 2*j+2] to.append(y*n+x) order=[] used=[False]*(n*n) def dfs(x): if used[x]: return used[x]=True dfs(to[x]) order.append(x) for i in range(n*n): dfs(i) order.reverse() def dfs2(x,used,group): if used[x]: return False if x in group : return True group.add(x) return dfs2(to[x],used,group) used=[False]*(n*n) ans=0 for i in order : group=set() if not used[i]: if dfs2(i,used,group): ans+=1 for g in group : used[g]=True print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var to : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var line : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := line.subrange(2 * j+1, 2 * j + 2) ; execute ((y * n + x) : to))) ; var order : Sequence := Sequence{} ; var used : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (n * n)) ; skip ; for i : Integer.subrange(0, n * n-1) do ( dfs(i)) ; order := order->reverse() ; skip ; used := MatrixLib.elementwiseMult(Sequence{ false }, (n * n)) ; var ans : int := 0 ; for i : order do ( group := Set{}->union(()) ; if not(used[i+1]) then ( if dfs2(i, used, group) then ( ans := ans + 1 ) else skip ) else skip ; for g : group do ( used[g+1] := true)) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break to=[] for i in range(n): line=list(map(int,input().split())) for j in range(n): x,y=line[2*j : 2*j+2] to.append(y*n+x) order=[] used=[False]*(n*n) def dfs(x): if used[x]: return used[x]=True dfs(to[x]) order.append(x) for i in range(n*n): dfs(i) order.reverse() def dfs2(x,used,group): if x in group : return True if used[x]: return False group.add(x) used[x]=True return dfs2(to[x],used,group) used=[False]*(n*n) ans=0 for i in order : group=set() if not used[i]: if dfs2(i,used,group): ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var to : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var line : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := line.subrange(2 * j+1, 2 * j + 2) ; execute ((y * n + x) : to))) ; var order : Sequence := Sequence{} ; var used : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (n * n)) ; skip ; for i : Integer.subrange(0, n * n-1) do ( dfs(i)) ; order := order->reverse() ; skip ; used := MatrixLib.elementwiseMult(Sequence{ false }, (n * n)) ; var ans : int := 0 ; for i : order do ( group := Set{}->union(()) ; if not(used[i+1]) then ( if dfs2(i, used, group) then ( ans := ans + 1 ) else skip ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INT_MAX=2147483647 def isKthBitSet(x,k): return 1 if(x &(1<<(k-1)))else 0 def leftmostSetBit(x): count=0 while(x): count+=1 x=x>>1 return count def isBinPalindrome(x): l=leftmostSetBit(x) r=1 while(l>r): if(isKthBitSet(x,l)!=isKthBitSet(x,r)): return 0 l-=1 r+=1 return 1 def findNthPalindrome(n): pal_count=0 i=0 for i in range(1,INT_MAX+1): if(isBinPalindrome(i)): pal_count+=1 if(pal_count==n): break return i if __name__=="__main__" : n=9 print(findNthPalindrome(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INT_MAX : int := 2147483647 ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( n := 9 ; execute (findNthPalindrome(n))->display() ) else skip; operation isKthBitSet(x : OclAny, k : OclAny) : OclAny pre: true post: true activity: return if (MathLib.bitwiseAnd(x, (1 * (2->pow((k - 1)))))) then 1 else 0 endif; operation leftmostSetBit(x : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while (x) do ( count := count + 1 ; x := x /(2->pow(1))) ; return count; operation isBinPalindrome(x : OclAny) : OclAny pre: true post: true activity: var l : OclAny := leftmostSetBit(x) ; var r : int := 1 ; while ((l->compareTo(r)) > 0) do ( if (isKthBitSet(x, l) /= isKthBitSet(x, r)) then ( return 0 ) else skip ; l := l - 1 ; r := r + 1) ; return 1; operation findNthPalindrome(n : OclAny) : OclAny pre: true post: true activity: var pal_count : int := 0 ; var i : int := 0 ; for i : Integer.subrange(1, INT_MAX + 1-1) do ( if (isBinPalindrome(i)) then ( pal_count := pal_count + 1 ) else skip ; if (pal_count = n) then ( break ) else skip) ; return i; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() if a[0]==a[1]and a[1]==a[2]: print(a) else : while 1 : a=int(a) a+=1 a=str(a) if a[0]==a[1]and a[1]==a[2]: print(a) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; if a->first() = a[1+1] & a[1+1] = a[2+1] then ( execute (a)->display() ) else ( while 1 do ( a := ("" + ((a)))->toInteger() ; a := a + 1 ; a := ("" + ((a))) ; if a->first() = a[1+1] & a[1+1] = a[2+1] then ( execute (a)->display() ; break ) else skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin N=int(stdin.readline().rstrip()) ans=0 tmp=1000 for i in range(1,10): for j in range(3,5): num=int(str(i)*j) if num-N>=0 and tmp>num-N : tmp=num-N ans=num print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + ((stdin.readLine().rstrip())))->toInteger() ; var ans : int := 0 ; var tmp : int := 1000 ; for i : Integer.subrange(1, 10-1) do ( for j : Integer.subrange(3, 5-1) do ( var num : int := ("" + ((("" + ((i))) * j)))->toInteger() ; if num - N >= 0 & (tmp->compareTo(num - N)) > 0 then ( tmp := num - N ; ans := num ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from sys import stdin,stdout def main(): sys.stdin=open('input.txt','r') sys.stdout=open('output.txt','w') n=int(input()) alp=input() for i in range(n//2): a=alp[i] b=alp[i+n//2] if a=='R' and b=='L' : print(i+n//2+1,i+1) else : print(i+1,i+n//2+1) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('input.txt')) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile('output.txt')) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var alp : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, n div 2-1) do ( var a : OclAny := alp[i+1] ; var b : OclAny := alp[i + n div 2+1] ; if a = 'R' & b = 'L' then ( execute (i + n div 2 + 1)->display() ) else ( execute (i + 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect n=int(input()) a=[0,111,222,333,444,555,666,777,888,999] s=bisect.bisect_left(a,n) print(a[s]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{0}->union(Sequence{111}->union(Sequence{222}->union(Sequence{333}->union(Sequence{444}->union(Sequence{555}->union(Sequence{666}->union(Sequence{777}->union(Sequence{888}->union(Sequence{ 999 }))))))))) ; var s : OclAny := bisect.bisect_left(a, n) ; execute (a[s+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) print((((a-1)//111)+1)*111) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((((a - 1) div 111) + 1) * 111)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) if(N<=111): print("111") elif(N<=222): print("222") elif(N<=333): print("333") elif(N<=444): print("444") elif(N<=555): print("555") elif(N<=666): print("666") elif(N<=777): print("777") elif(N<=888): print("888") else : print("999") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (N <= 111) then ( execute ("111")->display() ) else (if (N <= 222) then ( execute ("222")->display() ) else (if (N <= 333) then ( execute ("333")->display() ) else (if (N <= 444) then ( execute ("444")->display() ) else (if (N <= 555) then ( execute ("555")->display() ) else (if (N <= 666) then ( execute ("666")->display() ) else (if (N <= 777) then ( execute ("777")->display() ) else (if (N <= 888) then ( execute ("888")->display() ) else ( execute ("999")->display() ) ) ) ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(y,x): if 0<=y<=h-1 and 0<=x<=w-1 : return True return False h,w=map(int,raw_input().split()) g=[map(int,raw_input().split())for _ in xrange(h)] pos=[-1]*(h*w) for i in xrange(h): for j in xrange(w): pos[g[i][j]-1]=[i,j] dy=(1,0,-1,0) dx=(0,1,0,-1) stop=[set()for _ in xrange(h*w)] ans=0 for i in xrange(h*w): y,x=pos[i] for j in xrange(4): ny=y+dy[j]; nx=x+dx[j] if check(ny,nx): if g[ny][nx]=2 : ans+=1 elif cnt==0 : stop[i].add(g[y][x]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var g : Sequence := xrange(h)->select(_anon | true)->collect(_anon | ((raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var pos : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (h * w)) ; for i : xrange(h) do ( for j : xrange(w) do ( pos[g[i+1][j+1] - 1+1] := Sequence{i}->union(Sequence{ j }))) ; var dy : OclAny := Sequence{1, 0, -1, 0} ; var dx : OclAny := Sequence{0, 1, 0, -1} ; var stop : Sequence := xrange(h * w)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; var ans : int := 0 ; for i : xrange(h * w) do ( Sequence{y,x} := pos[i+1] ; for j : xrange(4) do ( var ny : OclAny := y + dy[j+1]; var nx : OclAny := x + dx[j+1] ; if check(ny, nx) then ( if (g[ny+1][nx+1]->compareTo(g[y+1][x+1])) < 0 then ( for k : (stop[g[ny+1][nx+1] - 1+1]) do ((expr (atom (name stop)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name k)))))))) ))))) ) else skip ) else skip) ; var cnt : int := (stop[i+1])->size() ; if cnt >= 2 then ( ans := ans + 1 ) else (if cnt = 0 then ( (expr (atom (name stop)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))))))) )))) ) else skip)) ; execute (ans)->display(); operation check(y : OclAny, x : OclAny) : OclAny pre: true post: true activity: if 0 <= y & (y <= h - 1) & 0 <= x & (x <= w - 1) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkType(arr,n): if(arr[0]<=arr[1]and arr[n-2]<=arr[n-1]): print("Increasing"); elif(arr[0]>=arr[1]and arr[n-2]>=arr[n-1]): print("Decreasing"); elif(arr[0]<=arr[1]and arr[n-2]>=arr[n-1]): print("Increasing then decreasing"); else : print("Decreasing then increasing"); if __name__=="__main__" : arr=[1,2,3,4]; n=len(arr); checkType(arr,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))); ; n := (arr)->size(); ; checkType(arr, n); ) else skip; operation checkType(arr : OclAny, n : OclAny) pre: true post: true activity: if ((arr->first()->compareTo(arr[1+1])) <= 0 & (arr[n - 2+1]->compareTo(arr[n - 1+1])) <= 0) then ( execute ("Increasing")->display(); ) else (if ((arr->first()->compareTo(arr[1+1])) >= 0 & (arr[n - 2+1]->compareTo(arr[n - 1+1])) >= 0) then ( execute ("Decreasing")->display(); ) else (if ((arr->first()->compareTo(arr[1+1])) <= 0 & (arr[n - 2+1]->compareTo(arr[n - 1+1])) >= 0) then ( execute ("Increasing then decreasing")->display(); ) else ( execute ("Decreasing then increasing")->display(); ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(y,x): if 0<=y<=h-1 and 0<=x<=w-1 : return True return False h,w=map(int,raw_input().split()) g=[map(int,raw_input().split())for _ in xrange(h)] pos=[-1]*(h*w) for i in xrange(h): for j in xrange(w): pos[g[i][j]-1]=[i,j] dy=(1,0,-1,0) dx=(0,1,0,-1) stop=[set()for _ in xrange(h*w)] ans=0 for i in xrange(h*w): y,x=pos[i] for j in xrange(4): ny=y+dy[j]; nx=x+dx[j] if check(ny,nx): if g[ny][nx]=2 : ans+=1 elif cnt==0 : stop[i].add(g[y][x]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var g : Sequence := xrange(h)->select(_anon | true)->collect(_anon | ((raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var pos : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (h * w)) ; for i : xrange(h) do ( for j : xrange(w) do ( pos[g[i+1][j+1] - 1+1] := Sequence{i}->union(Sequence{ j }))) ; var dy : OclAny := Sequence{1, 0, -1, 0} ; var dx : OclAny := Sequence{0, 1, 0, -1} ; var stop : Sequence := xrange(h * w)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; var ans : int := 0 ; for i : xrange(h * w) do ( Sequence{y,x} := pos[i+1] ; for j : xrange(4) do ( var ny : OclAny := y + dy[j+1]; var nx : OclAny := x + dx[j+1] ; if check(ny, nx) then ( if (g[ny+1][nx+1]->compareTo(g[y+1][x+1])) < 0 then ( stop[i+1] := MathLib.bitwiseOr(stop[i+1], stop[g[ny+1][nx+1] - 1+1]) ) else skip ) else skip) ; var cnt : int := (stop[i+1])->size() ; if cnt >= 2 then ( ans := ans + 1 ) else (if cnt = 0 then ( (expr (atom (name stop)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))))))) )))) ) else skip)) ; execute (ans)->display(); operation check(y : OclAny, x : OclAny) : OclAny pre: true post: true activity: if 0 <= y & (y <= h - 1) & 0 <= x & (x <= w - 1) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W=map(int,input().split()) M=[None]*(H*W) S=[list(map(int,input().split()))for i in range(H)] G=[[None]*W for i in range(H)] for i in range(H): s=S[i] for j in range(W): M[s[j]-1]=(i,j) D=0,-1,0,1,0 ans=0 for i in range(H*W): y,x=M[i] g=None for k in range(4): nx=x+D[k]; ny=y+D[k+1] if not 0<=nxcollect( _x | (OclType["int"])->apply(_x) ) ; var M : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (H * W)) ; var S : Sequence := Integer.subrange(0, H-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var G : Sequence := Integer.subrange(0, H-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ null }, W))) ; for i : Integer.subrange(0, H-1) do ( var s : OclAny := S[i+1] ; for j : Integer.subrange(0, W-1) do ( M[s[j+1] - 1+1] := Sequence{i, j})) ; var D : OclAny := 0,-1,0,1,0 ; var ans : int := 0 ; for i : Integer.subrange(0, H * W-1) do ( var y : OclAny := null; var x : OclAny := null; Sequence{y,x} := M[i+1] ; var g : OclAny := null ; for k : Integer.subrange(0, 4-1) do ( var nx : OclAny := x + D[k+1]; var ny : OclAny := y + D[k + 1+1] ; if not(0 <= nx & (nx < W)) or not(0 <= ny & (ny < H)) or (i + 1->compareTo(S[ny+1][nx+1])) < 0 then ( continue ) else skip ; if g <>= null then ( g := G[ny+1][nx+1] ) else (if g /= G[ny+1][nx+1] then ( g := -1 ) else skip)) ; if g = -1 then ( ans := ans + 1 ) else skip ; if g <>= null then ( G[y+1][x+1] := i ) else ( G[y+1][x+1] := g )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W=map(int,input().split()) tmp_list=[list(map(int,input().split()))for i in range(H)] ans_list=[[None for i in range(W)]for j in range(H)] def search_func(i,j): if not(not ans_list[i][j]): return ans_list[i][j] add_list=set() if j!=0 and tmp_list[i][j]>tmp_list[i][j-1]: add_list=add_list.union(search_func(i,j-1)) if j!=(W-1)and tmp_list[i][j]>tmp_list[i][j+1]: add_list=add_list.union(search_func(i,j+1)) if i!=0 and tmp_list[i][j]>tmp_list[i-1][j]: add_list=add_list.union(search_func(i-1,j)) if i!=(H-1)and tmp_list[i][j]>tmp_list[i+1][j]: add_list=add_list.union(search_func(i+1,j)) if not add_list : ans_list[i][j]=set({tmp_list[i][j]}) else : ans_list[i][j]=add_list return ans_list[i][j] sort_list=[] for i in range(H): for j in range(W): sort_list.append([tmp_list[i][j],i,j]) sort2_list=sorted(sort_list,key=lambda x : x[0]) final_ans=0 for item in sort2_list : if len(search_func(item[1],item[2]))>1 : final_ans+=1 print(final_ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var tmp_list : Sequence := Integer.subrange(0, H-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ans_list : Sequence := Integer.subrange(0, H-1)->select(j | true)->collect(j | (Integer.subrange(0, W-1)->select(i | true)->collect(i | (null)))) ; skip ; var sort_list : Sequence := Sequence{} ; for i : Integer.subrange(0, H-1) do ( for j : Integer.subrange(0, W-1) do ( execute ((Sequence{tmp_list[i+1][j+1]}->union(Sequence{i}->union(Sequence{ j }))) : sort_list))) ; var sort2_list : Sequence := sort_list->sortedBy($x | (lambda x : OclAny in (x->first()))->apply($x)) ; var final_ans : int := 0 ; for item : sort2_list do ( if (search_func(item[1+1], item[2+1]))->size() > 1 then ( final_ans := final_ans + 1 ) else skip) ; execute (final_ans)->display(); operation search_func(i : OclAny, j : OclAny) : OclAny pre: true post: true activity: if not((not(ans_list[i+1][j+1]))) then ( return ans_list[i+1][j+1] ) else skip ; var add_list : Set := Set{}->union(()) ; if j /= 0 & (tmp_list[i+1][j+1]->compareTo(tmp_list[i+1][j - 1+1])) > 0 then ( add_list := add_list.union(search_func(i, j - 1)) ) else skip ; if j /= (W - 1) & (tmp_list[i+1][j+1]->compareTo(tmp_list[i+1][j + 1+1])) > 0 then ( add_list := add_list.union(search_func(i, j + 1)) ) else skip ; if i /= 0 & (tmp_list[i+1][j+1]->compareTo(tmp_list[i - 1+1][j+1])) > 0 then ( add_list := add_list.union(search_func(i - 1, j)) ) else skip ; if i /= (H - 1) & (tmp_list[i+1][j+1]->compareTo(tmp_list[i + 1+1][j+1])) > 0 then ( add_list := add_list.union(search_func(i + 1, j)) ) else skip ; if not(add_list) then ( ans_list[i+1][j+1] := Set{}->union((Set{ tmp_list[i+1][j+1] })) ) else ( ans_list[i+1][j+1] := add_list ) ; return ans_list[i+1][j+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heappush,heappop def main(): INF=10**7 h,w=map(int,input().split()) mp=[[INF]+list(map(int,input().split()))+[INF]for _ in range(h)] mp.insert(0,[INF]*(w+2)) mp.append([INF]*(w+2)) ridge=[[None]*(w+2)for _ in range(h+2)] vec=((1,0),(0,-1),(-1,0),(0,1)) def is_ridge(x,y): to_set=set() for dx,dy in vec : nx,ny=x+dx,y+dy temp=ridge[ny][nx] if temp!=None : if temp is True : ridge[y][x]=True return True else : to_set.add(temp) if not to_set : ridge[y][x]=(x,y) elif len(to_set)==1 : ridge[y][x]=list(to_set)[0] else : ridge[y][x]=True return ridge[y][x] que=[] for y in range(1,h+1): for x in range(1,w+1): h=mp[y][x] heappush(que,(h,x,y)) ans=0 while que : _,x,y=heappop(que) if is_ridge(x,y)is True : ans+=1 print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: var INF : double := (10)->pow(7) ; var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mp : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (Sequence{ INF }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->union(Sequence{ INF }))) ; mp := mp.insertAt(0+1, MatrixLib.elementwiseMult(Sequence{ INF }, (w + 2))) ; execute ((MatrixLib.elementwiseMult(Sequence{ INF }, (w + 2))) : mp) ; var ridge : Sequence := Integer.subrange(0, h + 2-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ null }, (w + 2)))) ; var vec : OclAny := Sequence{Sequence{1, 0}, Sequence{0, -1}, Sequence{-1, 0}, Sequence{0, 1}} ; skip ; var que : Sequence := Sequence{} ; for y : Integer.subrange(1, h + 1-1) do ( for x : Integer.subrange(1, w + 1-1) do ( var h : OclAny := mp[y+1][x+1] ; heappush(que, Sequence{h, x, y}))) ; var ans : int := 0 ; while que do ( var _anon : OclAny := null; Sequence{_anon,x,y} := heappop(que) ; if is_ridge(x, y) <>= true then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Perimeter(s,n): perimeter=1 perimeter=n*s return perimeter if __name__=='__main__' : n=5 s=2.5 peri=Perimeter(s,n) print("Perimeter of Regular Polygon with",n,"sides of length",s,"=",peri) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 5 ; s := 2.5 ; var peri : OclAny := Perimeter(s, n) ; execute ("Perimeter of Regular Polygon with")->display() ) else skip; operation Perimeter(s : OclAny, n : OclAny) : OclAny pre: true post: true activity: var perimeter : int := 1 ; perimeter := n * s ; return perimeter; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=abs(int(input())) for i in range(10**5): if x % 2==i*(i+1)/2 % 2 and i*(i+1)/2>x : print(i) break elif x==i*(i+1)/2 : print(i) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : double := (("" + (((OclFile["System.in"]).readLine())))->toInteger())->abs() ; for i : Integer.subrange(0, (10)->pow(5)-1) do ( if x mod 2 = i * (i + 1) / 2 mod 2 & (i * (i + 1) / 2->compareTo(x)) > 0 then ( execute (i)->display() ; break ) else (if x = i * (i + 1) / 2 then ( execute (i)->display() ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : f=open("input.txt","r") n=int(f.readline()) students=list(f.readline()) f=open("output.txt","w") row=int(n/2) for i in range(row): a=students[i] if i+int(n/2)<=n : b=students[i+row] arr=[[i+1,a],[i+row+1,b]] else : b=students[i-row] arr=[[i+1,a],[i-row-1,b]] arr.sort(key=lambda x : x[1]) print(arr[0][0],arr[1][0],file=f) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ; var n : int := ("" + ((f.readLine())))->toInteger() ; var students : Sequence := (f.readLine())->characters() ; f := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ; var row : int := ("" + ((n / 2)))->toInteger() ; for i : Integer.subrange(0, row-1) do ( var a : OclAny := students[i+1] ; if (i + ("" + ((n / 2)))->toInteger()->compareTo(n)) <= 0 then ( var b : OclAny := students[i + row+1] ; var arr : Sequence := Sequence{Sequence{i + 1}->union(Sequence{ a })}->union(Sequence{ Sequence{i + row + 1}->union(Sequence{ b }) }) ) else ( b := students[i - row+1] ; arr := Sequence{Sequence{i + 1}->union(Sequence{ a })}->union(Sequence{ Sequence{i - row - 1}->union(Sequence{ b }) }) ) ; arr := arr->sort() ; execute (arr->first()->first())->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os import math from itertools import combinations,permutations TC=False def solve(): n=int(input()) cnt=0 ans=0 n=abs(n) while anstoInteger()-1) do ( solve()) ) else ( solve() ); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cnt : int := 0 ; var ans : int := 0 ; n := (n)->abs() ; while (ans->compareTo(n)) < 0 or (ans - n) mod 2 /= 0 do ( cnt := cnt + 1 ; ans := ans + cnt) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=abs(int(input())) i=0 while n>0 or n & 1 : i+=1 n-=i print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : double := (("" + (((OclFile["System.in"]).readLine())))->toInteger())->abs() ; var i : int := 0 ; while n > 0 or MathLib.bitwiseAnd(n, 1) do ( i := i + 1 ; n := n - i) ; execute (i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from math import sqrt x=int(input()) if x<0 : x=-x ans=int(0) r=int((-1+sqrt(1+8*x))/2)+1 for i in range(max(0,r-5),r+5,1): if i*(i+1)/2>=x : ans=i break if(ans*(ans+1)//2-x)% 2==1 : ans=ans+1 if(ans*(ans+1)//2-x)% 2==1 : ans=ans+1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if x < 0 then ( x := -x ) else skip ; var ans : int := ("" + ((0)))->toInteger() ; var r : int := ("" + (((-1 + sqrt(1 + 8 * x)) / 2)))->toInteger() + 1 ; for i : Integer.subrange(Set{0, r - 5}->max(), r + 5-1)->select( $x | ($x - Set{0, r - 5}->max()) mod 1 = 0 ) do ( if (i * (i + 1) / 2->compareTo(x)) >= 0 then ( ans := i ; break ) else skip) ; if (ans * (ans + 1) div 2 - x) mod 2 = 1 then ( ans := ans + 1 ) else skip ; if (ans * (ans + 1) div 2 - x) mod 2 = 1 then ( ans := ans + 1 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get(): return list(map(int,input().split())) def intput(): return int(input()) def main(): for _ in range(intput()): a=get() if(a[1]>=a[0]): print(a[1]-a[0]) else : if((a[0]-a[1])% 2==0 or(a[0]+a[1])% 2==0): print(0) else : print(1) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; main(); operation get() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation intput() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation main() pre: true post: true activity: for _anon : Integer.subrange(0, intput()-1) do ( var a : OclAny := get() ; if ((a[1+1]->compareTo(a->first())) >= 0) then ( execute (a[1+1] - a->first())->display() ) else ( if ((a->first() - a[1+1]) mod 2 = 0 or (a->first() + a[1+1]) mod 2 = 0) then ( execute (0)->display() ) else ( execute (1)->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from math import sqrt x=int(input()) if x<0 : x=-x ans=int(0) r=int((-1+sqrt(1+8*x))/2)+1 for i in range(max(0,r-2),r+2,1): if i*(i+1)/2>=x : ans=i break if(ans*(ans+1)//2-x)% 2==1 : ans=ans+1 if(ans*(ans+1)//2-x)% 2==1 : ans=ans+1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if x < 0 then ( x := -x ) else skip ; var ans : int := ("" + ((0)))->toInteger() ; var r : int := ("" + (((-1 + sqrt(1 + 8 * x)) / 2)))->toInteger() + 1 ; for i : Integer.subrange(Set{0, r - 2}->max(), r + 2-1)->select( $x | ($x - Set{0, r - 2}->max()) mod 1 = 0 ) do ( if (i * (i + 1) / 2->compareTo(x)) >= 0 then ( ans := i ; break ) else skip) ; if (ans * (ans + 1) div 2 - x) mod 2 = 1 then ( ans := ans + 1 ) else skip ; if (ans * (ans + 1) div 2 - x) mod 2 = 1 then ( ans := ans + 1 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def max_element(a,n): pre=[0]*n ; pre[0]=a[0]; for i in range(1,n): pre[i]=max(pre[i-1],a[i]); suf=[0]*n ; suf[n-1]=a[n-1]; for i in range(n-2,-1,-1): suf[i]=max(suf[i+1],a[i]); for i in range(n): if(i==0): print(suf[i+1],end=" "); elif(i==n-1): print(pre[i-1],end=" "); else : print(max(pre[i-1],suf[i+1]),end=" "); if __name__=="__main__" : a=[2,5,6,1,3]; n=len(a); max_element(a,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{2}->union(Sequence{5}->union(Sequence{6}->union(Sequence{1}->union(Sequence{ 3 })))); ; n := (a)->size(); ; max_element(a, n); ) else skip; operation max_element(a : OclAny, n : OclAny) pre: true post: true activity: var pre : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; pre->first() := a->first(); ; for i : Integer.subrange(1, n-1) do ( pre[i+1] := Set{pre[i - 1+1], a[i+1]}->max();) ; var suf : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; suf[n - 1+1] := a[n - 1+1]; ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( suf[i+1] := Set{suf[i + 1+1], a[i+1]}->max();) ; for i : Integer.subrange(0, n-1) do ( if (i = 0) then ( execute (suf[i + 1+1])->display(); ) else (if (i = n - 1) then ( execute (pre[i - 1+1])->display(); ) else ( execute (Set{pre[i - 1+1], suf[i + 1+1]}->max())->display(); ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if n==0 : break a=[list(input())for _ in[0]*n] for i in range(n): for j in range(len(a[i])): if a[i][j]=='.' : a[i][j]='' else : if j>0 : a[i][j-1]='+' x=i-1 while a[x][j-1]=='' : a[x][j-1]='|' x-=1 break [print(*b,sep='')for b in a] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n)->select(_anon | true)->collect(_anon | (((OclFile["System.in"]).readLine())->characters())) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, (a[i+1])->size()-1) do ( if a[i+1][j+1] = '.' then ( a[i+1][j+1] := '' ) else ( if j > 0 then ( a[i+1][j - 1+1] := '+' ; var x : double := i - 1 ; while a[x+1][j - 1+1] = '' do ( a[x+1][j - 1+1] := '|' ; x := x - 1) ) else skip ; break )))) ; ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count_dot(lis): c=0 for i in lis : if not(i=='.'): return c c+=1 def solve(N): a=[] dot=[] for i in range(N): a.append([char for char in input()]) dot.append(count_dot(a[i])) for i in range(N): for j in range(len(a[i])): if a[i][j]=='.' : a[i][j]='' for i in range(1,N): a[i][dot[i]-1]='+' k=1 while True : if a[i-k][dot[i]-1]=='' : a[i-k][dot[i]-1]='|' k+=1 else : break for i in range(N): for char in a[i]: print(char,end='') print() while True : N=int(input()) if N==0 : break solve(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; solve(N)); operation count_dot(lis : OclAny) : OclAny pre: true post: true activity: var c : int := 0 ; for i : lis do ( if not((i = '.')) then ( return c ) else skip ; c := c + 1); operation solve(N : OclAny) pre: true post: true activity: var a : Sequence := Sequence{} ; var dot : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute (((OclFile["System.in"]).readLine()->select(char | true)->collect(char | (char))) : a) ; execute ((count_dot(a[i+1])) : dot)) ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, (a[i+1])->size()-1) do ( if a[i+1][j+1] = '.' then ( a[i+1][j+1] := '' ) else skip)) ; for i : Integer.subrange(1, N-1) do ( a[i+1][dot[i+1] - 1+1] := '+' ; var k : int := 1 ; while true do ( if a[i - k+1][dot[i+1] - 1+1] = '' then ( a[i - k+1][dot[i+1] - 1+1] := '|' ; k := k + 1 ) else ( break ))) ; for i : Integer.subrange(0, N-1) do ( for char : a[i+1] do ( execute (char)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque import sys,heapq,bisect,math,itertools,string,queue,copy,time sys.setrecursionlimit(10**8) INF=float('inf') mod=10**9+7 eps=10**-7 def inp(): return int(input()) def inpl(): return list(map(int,input().split())) def inpl_str(): return list(input().split()) while True : N=inp() if N==0 : break else : tt=[['']*1100 for _ in range(N)] LL=[0]*N SS=['']*N bL=1000 for i in range(N): S=input() L=S.count('.') LL[i]=L SS[i]=S[L :] tt[i][L]='+' if Lpow(8)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var eps : double := (10)->pow(-7) ; skip ; skip ; skip ; while true do ( var N : OclAny := inp() ; if N = 0 then ( break ) else ( var tt : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ '' }, 1100))) ; var LL : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var SS : Sequence := MatrixLib.elementwiseMult(Sequence{ '' }, N) ; var bL : int := 1000 ; for i : Integer.subrange(0, N-1) do ( var S : String := (OclFile["System.in"]).readLine() ; var L : int := S->count('.') ; LL[i+1] := L ; SS[i+1] := S.subrange(L+1) ; tt[i+1][L+1] := '+' ; if (L->compareTo(bL)) < 0 then ( for j : (Integer.subrange(0, i-1))->reverse() do ( if LL[j+1] = L then ( break ) else ( tt[j+1][L+1] := '|' )) ) else skip ; bL := L) ; execute (SS->first())->display() ; for i : Integer.subrange(1, N-1) do ( var tmp : String := '' ; for j : Integer.subrange(1, 1100-1) do ( if tt[i+1][j+1] /= '+' then ( tmp := tmp + tt[i+1][j+1] ) else ( tmp := tmp + '+' + SS[i+1] ; break )) ; execute (tmp)->display()) )); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inpl_str() : OclAny pre: true post: true activity: return (input().split()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count_dot(lis): c=0 for i in lis : if not(i=='.'): return c c+=1 def solve(N): a=[] dot=[] for i in range(N): a.append([char for char in input()]) dot.append(count_dot(a[i])) for i in range(N): for j in range(len(a[i])): if a[i][j]=='.' : a[i][j]='' for i in range(1,N): a[i][dot[i]-1]='+' k=1 while True : if a[i-k][dot[i]-1]=='' : a[i-k][dot[i]-1]='|' k+=1 else : break for i in range(N): for char in a[i]: print(char,end='') print() while True : N=int(input()) if N==0 : break solve(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; solve(N)); operation count_dot(lis : OclAny) : OclAny pre: true post: true activity: var c : int := 0 ; for i : lis do ( if not((i = '.')) then ( return c ) else skip ; c := c + 1); operation solve(N : OclAny) pre: true post: true activity: var a : Sequence := Sequence{} ; var dot : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute (((OclFile["System.in"]).readLine()->select(char | true)->collect(char | (char))) : a) ; execute ((count_dot(a[i+1])) : dot)) ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, (a[i+1])->size()-1) do ( if a[i+1][j+1] = '.' then ( a[i+1][j+1] := '' ) else skip)) ; for i : Integer.subrange(1, N-1) do ( a[i+1][dot[i+1] - 1+1] := '+' ; var k : int := 1 ; while true do ( if a[i - k+1][dot[i+1] - 1+1] = '' then ( a[i - k+1][dot[i+1] - 1+1] := '|' ; k := k + 1 ) else ( break ))) ; for i : Integer.subrange(0, N-1) do ( for char : a[i+1] do ( execute (char)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count_dot(lis): c=0 for i in lis : if not(i=='.'): return c c+=1 def solve(N): a=[] dot=[] for i in range(N): a.append([char for char in input()]) dot.append(count_dot(a[i])) for i in range(N): for j in range(len(a[i])): if a[i][j]=='.' : a[i][j]='' for i in range(1,N): a[i][dot[i]-1]='+' k=1 while True : if a[i-k][dot[i]-1]=='' : a[i-k][dot[i]-1]='|' k+=1 else : break for i in range(N): for char in a[i]: print(char,end='') print() while True : N=int(input()) if N==0 : break solve(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; solve(N)); operation count_dot(lis : OclAny) : OclAny pre: true post: true activity: var c : int := 0 ; for i : lis do ( if not((i = '.')) then ( return c ) else skip ; c := c + 1); operation solve(N : OclAny) pre: true post: true activity: var a : Sequence := Sequence{} ; var dot : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute (((OclFile["System.in"]).readLine()->select(char | true)->collect(char | (char))) : a) ; execute ((count_dot(a[i+1])) : dot)) ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, (a[i+1])->size()-1) do ( if a[i+1][j+1] = '.' then ( a[i+1][j+1] := '' ) else skip)) ; for i : Integer.subrange(1, N-1) do ( a[i+1][dot[i+1] - 1+1] := '+' ; var k : int := 1 ; while true do ( if a[i - k+1][dot[i+1] - 1+1] = '' then ( a[i - k+1][dot[i+1] - 1+1] := '|' ; k := k + 1 ) else ( break ))) ; for i : Integer.subrange(0, N-1) do ( for char : a[i+1] do ( execute (char)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math class GfG : def __init__(self,n): self.height=int(math.ceil(math.log10(n)/math.log10(2))) self.table=[0]*(n+1) def preprocessing(self): i=0 while(iexists( _x | result = _x ); attribute height : int := ("" + ((((n)->log10() / (2)->log10())->ceil())))->toInteger(); attribute table : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); operation initialise(n : OclAny) : GfG pre: true post: true activity: self.height := ("" + ((((n)->log10() / (2)->log10())->ceil())))->toInteger() ; self.table := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); return self; operation preprocessing() pre: true post: true activity: var i : int := 0 ; while ((i->compareTo((self.table)->size())) < 0) do ( self.table[i+1] := MatrixLib.elementwiseMult(Sequence{ -1 }, (self.height + 1)) ; i := i + 1); operation calculateSparse(u : OclAny,v : OclAny) pre: true post: true activity: self.table[v+1]->first() := u ; i := 1 ; while ((i->compareTo(self.height)) <= 0) do ( self.table[v+1][i+1] := self.table[self.table[v+1][i - 1+1]+1][i - 1+1] ; if (self.table[v+1][i+1] = -1) then ( break ) else skip ; i := i + 1); operation kthancestor(V : OclAny,k : OclAny) : OclAny pre: true post: true activity: i := 0 ; while ((i->compareTo(self.height)) <= 0) do ( if ((MathLib.bitwiseAnd(k, (1 * (2->pow(i))))) /= 0) then ( V := self.table[V+1][i+1] ; if (V = -1) then ( break ) else skip ) else skip ; i := i + 1) ; return V; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 6 ; var obj : GfG := (GfG.newGfG()).initialise(n) ; obj.preprocessing() ; obj.calculateSparse(1, 2) ; obj.calculateSparse(1, 3) ; obj.calculateSparse(2, 4) ; obj.calculateSparse(2, 5) ; obj.calculateSparse(3, 6) ; var K : int := 2 ; V := 5 ; execute (obj.kthancestor(V, K))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def MinimumCost(a,n,x): for i in range(1,n,1): a[i]=min(a[i],2*a[i-1]) ind=0 sum=0 while(x): if(x & 1): sum+=a[ind] ind+=1 x=x>>1 return sum if __name__=='__main__' : a=[20,50,60,90] x=7 n=len(a) print(MinimumCost(a,n,x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := Sequence{20}->union(Sequence{50}->union(Sequence{60}->union(Sequence{ 90 }))) ; x := 7 ; n := (a)->size() ; execute (MinimumCost(a, n, x))->display() ) else skip; operation MinimumCost(a : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( a[i+1] := Set{a[i+1], 2 * a[i - 1+1]}->min()) ; var ind : int := 0 ; var sum : int := 0 ; while (x) do ( if (MathLib.bitwiseAnd(x, 1)) then ( sum := sum + a[ind+1] ) else skip ; ind := ind + 1 ; x := x /(2->pow(1))) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1005 def shortestSeq(S : list,T : list): m=len(S) n=len(T) dp=[[0 for i in range(n+1)]for j in range(m+1)] for i in range(m+1): dp[i][0]=1 for i in range(n+1): dp[0][i]=MAX for i in range(1,m+1): for j in range(1,n+1): ch=S[i-1] k=j-1 while k>=0 : if T[k]==ch : break k-=1 if k==-1 : dp[i][j]=1 else : dp[i][j]=min(dp[i-1][j],dp[i-1][k]+1) ans=dp[m][n] if ans>=MAX : ans=-1 return ans if __name__=="__main__" : S="babab" T="babba" print("Length of shortest subsequence is:",shortestSeq(S,T)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1005 ; skip ; if __name__ = "__main__" then ( var S : String := "babab" ; var T : String := "babba" ; execute ("Length of shortest subsequence is:")->display() ) else skip; operation shortestSeq(S : Sequence(OclAny), T : Sequence(OclAny)) : OclAny pre: true post: true activity: var m : int := (S)->size() ; var n : int := (T)->size() ; var dp : Sequence := Integer.subrange(0, m + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, m + 1-1) do ( dp[i+1]->first() := 1) ; for i : Integer.subrange(0, n + 1-1) do ( dp->first()[i+1] := MAX) ; for i : Integer.subrange(1, m + 1-1) do ( for j : Integer.subrange(1, n + 1-1) do ( var ch : OclAny := S[i - 1+1] ; var k : double := j - 1 ; while k >= 0 do ( if T[k+1] = ch then ( break ) else skip ; k := k - 1) ; if k = -1 then ( dp[i+1][j+1] := 1 ) else ( dp[i+1][j+1] := Set{dp[i - 1+1][j+1], dp[i - 1+1][k+1] + 1}->min() ))) ; var ans : OclAny := dp[m+1][n+1] ; if (ans->compareTo(MAX)) >= 0 then ( ans := -1 ) else skip ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) i=1 while True : if i>t : break n,k=map(int,input().split()) m=(n-k) if m<0 : print(abs(m)) else : if m % 2==0 : print(0) else : print(1) i=i+1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 1 ; while true do ( if (i->compareTo(t)) > 0 then ( break ) else skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : double := (n - k) ; if m < 0 then ( execute ((m)->abs())->display() ) else ( if m mod 2 = 0 then ( execute (0)->display() ) else ( execute (1)->display() ) ) ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumofPairs(n): v=[] sum=0 while n>0 : v.append(n % 2) n=n//2 v.reverse() for i in range(len(v)-1): for j in range(i+1,len(v)): if v[i]==0 and v[j]==1 : sum+=1 if v[i]==1 and v[j]==1 : sum+=3 if v[i]==1 and v[j]==0 : sum+=2 return sum if __name__=="__main__" : N=5 print(sumofPairs(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var N : int := 5 ; execute (sumofPairs(N))->display() ) else skip; operation sumofPairs(n : OclAny) : OclAny pre: true post: true activity: var v : Sequence := Sequence{} ; var sum : int := 0 ; while n > 0 do ( execute ((n mod 2) : v) ; n := n div 2) ; v := v->reverse() ; for i : Integer.subrange(0, (v)->size() - 1-1) do ( for j : Integer.subrange(i + 1, (v)->size()-1) do ( if v[i+1] = 0 & v[j+1] = 1 then ( sum := sum + 1 ) else skip ; if v[i+1] = 1 & v[j+1] = 1 then ( sum := sum + 3 ) else skip ; if v[i+1] = 1 & v[j+1] = 0 then ( sum := sum + 2 ) else skip)) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def largestSubset(a,n): a.sort() dp=[0 for i in range(n)] dp[n-1]=1 ; for i in range(n-2,-1,-1): mxm=0 ; for j in range(i+1,n): if a[j]% a[i]==0 : mxm=max(mxm,dp[j]) dp[i]=1+mxm return max(dp) a=[1,3,6,13,17,18] n=len(a) print(largestSubset(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{1}->union(Sequence{3}->union(Sequence{6}->union(Sequence{13}->union(Sequence{17}->union(Sequence{ 18 }))))) ; n := (a)->size() ; execute (largestSubset(a, n))->display(); operation largestSubset(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: a := a->sort() ; var dp : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; dp[n - 1+1] := 1; ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( var mxm : int := 0; ; for j : Integer.subrange(i + 1, n-1) do ( if a[j+1] mod a[i+1] = 0 then ( mxm := Set{mxm, dp[j+1]}->max() ) else skip) ; dp[i+1] := 1 + mxm) ; return (dp)->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def allBitsAreSet(n): if(((n+1)& n)==0): return True ; return False ; def bitsAreInAltOrder(n): num=n ^(n>>1); return allBitsAreSet(num); n=10 ; if(bitsAreInAltOrder(n)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 10; ; if (bitsAreInAltOrder(n)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ); operation allBitsAreSet(n : OclAny) pre: true post: true activity: if ((MathLib.bitwiseAnd((n + 1), n)) = 0) then ( return true; ) else skip ; return false;; operation bitsAreInAltOrder(n : OclAny) pre: true post: true activity: var num : int := MathLib.bitwiseXor(n, (n /(2->pow(1)))); ; return allBitsAreSet(num);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findTriangles(n): num=n print(num,end=" ") print(num*(num-4)*(num-5)//6) n=6 ; findTriangles(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 6; ; findTriangles(n); operation findTriangles(n : OclAny) pre: true post: true activity: var num : OclAny := n ; execute (num)->display() ; execute (num * (num - 4) * (num - 5) div 6)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections class TwoDimQueue(): def __init__(self,num_queues): self.queues=[collections.deque()for i in range(0,num_queues,1)] def enqueue(self,t,x): self.queues[t].appendleft(x) return self def front(self,t): if len(self.queues[t])>0 : print(f'{self.queues[t][len(self.queues[t])-1]}') return self def dequeue(self,t): if len(self.queues[t])>0 : self.queues[t].pop() return self num_queues,q=tuple(map(int,input().split(' '))) stacks=TwoDimQueue(num_queues) for i in range(0,q): queue=tuple(map(int,input().split(' '))) if queue[0]==0 : stacks.enqueue(queue[1],queue[2]) elif queue[0]==1 : stacks.front(queue[1]) elif queue[0]==2 : stacks.dequeue(queue[1]) ------------------------------------------------------------ OCL File: --------- class TwoDimQueue { static operation newTwoDimQueue() : TwoDimQueue pre: true post: TwoDimQueue->exists( _x | result = _x ); attribute queues : Sequence := Integer.subrange(0, num_queues-1)->select( $x | ($x - 0) mod 1 = 0 )->select(i | true)->collect(i | (())); operation initialise(num_queues : OclAny) : pre: true post: true activity: self.queues := Integer.subrange(0, num_queues-1)->select( $x | ($x - 0) mod 1 = 0 )->select(i | true)->collect(i | (())); return self; operation enqueue(t : OclAny,x : OclAny) : OclAny pre: true post: true activity: (expr (atom (name self)) (trailer . (name queues) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name appendleft) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) ; return self; operation front(t : OclAny) : OclAny pre: true post: true activity: if (self.queues[t+1])->size() > 0 then ( execute (StringLib.formattedString('{self.queues[t][len(self.queues[t])-1]}'))->display() ) else skip ; return self; operation dequeue(t : OclAny) : OclAny pre: true post: true activity: if (self.queues[t+1])->size() > 0 then ( (expr (atom (name self)) (trailer . (name queues) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name pop) (arguments ( )))) ) else skip ; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var q : OclAny := null; Sequence{num_queues,q} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var stacks : TwoDimQueue := (TwoDimQueue.newTwoDimQueue()).initialise(num_queues) ; for i : Integer.subrange(0, q-1) do ( var queue : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; if queue->first() = 0 then ( stacks.enqueue(queue[1+1], queue[2+1]) ) else (if queue->first() = 1 then ( stacks.front(queue[1+1]) ) else (if queue->first() = 2 then ( stacks.dequeue(queue[1+1]) ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin class QueueNode(object): def __init__(self,data,next=None): self.data=data self.next=next class LinkList(object): def __init__(self,head=None): self.head=head self.tail=head def insert_q(self,data): node=QueueNode(data) if self.head is None : self.head=node self.tail=node return currentNode=self.tail while True : if currentNode.next is None : currentNode.next=node self.tail=node break currentNode=currentNode.next def delete_q(self): if self.head is not None : currentNode=self.head self.head=currentNode.next def print_q(self): if self.head is not None : print(self.head.data) if __name__=='__main__' : qnum,loopnum=map(int,input().split(" ")) q=[LinkList()for i in range(qnum)] for i in range(loopnum): cmd=stdin.readline().strip().split() t=int(cmd[1]) if cmd[0]=="0" : q[t].insert_q(int(cmd[2])) elif cmd[0]=="1" : q[t].print_q() else : q[t].delete_q() ------------------------------------------------------------ OCL File: --------- class QueueNode extends object { static operation newQueueNode() : QueueNode pre: true post: QueueNode->exists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := next; operation initialise(data : OclAny,next : OclAny) : pre: true post: true activity: self.data := data ; self.next := next; return self; } class LinkList extends object { static operation newLinkList() : LinkList pre: true post: LinkList->exists( _x | result = _x ); attribute head : OclAny := head; attribute tail : OclAny := head; operation initialise(head : OclAny) : pre: true post: true activity: self.head := head ; self.tail := head; return self; operation insert_q(data : OclAny) pre: true post: true activity: var node : QueueNode := (QueueNode.newQueueNode()).initialise(data) ; if self.head <>= null then ( self.head := node ; self.tail := node ; return ) else skip ; var currentNode : OclAny := self.tail ; while true do ( if currentNode.next <>= null then ( currentNode.next := node ; self.tail := node ; break ) else skip ; currentNode := currentNode.next); operation delete_q() pre: true post: true activity: if not(self.head <>= null) then ( currentNode := self.head ; self.head := currentNode.next ) else skip; operation print_q() pre: true post: true activity: if not(self.head <>= null) then ( execute (self.head.data)->display() ) else skip; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( var qnum : OclAny := null; var loopnum : OclAny := null; Sequence{qnum,loopnum} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var q : Sequence := Integer.subrange(0, qnum-1)->select(i | true)->collect(i | ((LinkList.newLinkList()).initialise())) ; for i : Integer.subrange(0, loopnum-1) do ( var cmd : OclAny := stdin.readLine()->trim().split() ; var t : int := ("" + ((cmd[1+1])))->toInteger() ; if cmd->first() = "0" then ( (expr (atom (name q)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name insert_q) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name cmd)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))) ))))))))) )))) ) else (if cmd->first() = "1" then ( (expr (atom (name q)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name print_q) (arguments ( )))) ) else ( (expr (atom (name q)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name delete_q) (arguments ( )))) ) ) ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque if __name__=='__main__' : n,q=input().split() n,q=int(n),int(q) S=[deque([])for i in range(n)] for i in range(q): query=input().split() if query[0]=='0' : S[int(query[1])].append(query[2]) else : if len(S[int(query[1])])==0 : pass elif query[0]=='1' : print(S[int(query[1])][0]) else : S[int(query[1])].popleft() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := input().split() ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := Sequence{("" + ((n)))->toInteger(),("" + ((q)))->toInteger()} ; var S : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((Sequence{}))) ; for i : Integer.subrange(0, q-1) do ( var query : OclAny := input().split() ; if query->first() = '0' then ( (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name query)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name query)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))) )))) ) else ( if (S[("" + ((query[1+1])))->toInteger()+1])->size() = 0 then ( skip ) else (if query->first() = '1' then ( execute (S[("" + ((query[1+1])))->toInteger()+1]->first())->display() ) else ( (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name query)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ))))))))) ])) (trailer . (name popleft) (arguments ( )))) ) ) )) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,value): self.value=value self.next=None class Queue : def __init__(self): self.first=None self.last=None def enqueue(self,value): if value is None : raise ValueError('enqueue None') node=Node(value) if self.last is not None : self.last.next=node self.last=node if self.first is None : self.first=node def front(self): if self.first is None : return None return self.first.value def dequeue(self): if self.first is None : return None value=self.first.value if self.first==self.last : self.last=None self.first=self.first.next return value def run(): n,nq=[int(x)for x in input().split()] qs=[Queue()for _ in range(n)] for _ in range(nq): line=input() if line.startswith('0'): command,target,value=[int(x)for x in line.split()] qs[target].enqueue(value) elif line.startswith('1'): command,target=[int(x)for x in line.split()] value=qs[target].front() if value is not None : print(value) elif line.startswith('2'): command,target=[int(x)for x in line.split()] qs[target].dequeue() else : raise ValueError('invalid command') if __name__=='__main__' : run() ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute value : OclAny := value; attribute next : OclAny := null; operation initialise(value : OclAny) : Node pre: true post: true activity: self.value := value ; self.next := null; return self; } class Queue { static operation newQueue() : Queue pre: true post: Queue->exists( _x | result = _x ); attribute first : OclAny := null; attribute last : OclAny := null; operation initialise() : Queue pre: true post: true activity: self.first := null ; self.last := null; return self; operation enqueue(value : OclAny) pre: true post: true activity: if value <>= null then ( error IncorrectElementException.newIncorrectElementException('enqueue None') ) else skip ; var node : Node := (Node.newNode()).initialise(value) ; if not(self.last <>= null) then ( self.last.next := node ) else skip ; self.last := node ; if self.first <>= null then ( self.first := node ) else skip; operation front() : OclAny pre: true post: true activity: if self.first <>= null then ( return null ) else skip ; return self.first.value; operation dequeue() : OclAny pre: true post: true activity: if self.first <>= null then ( return null ) else skip ; value := self.first.value ; if self.first = self.last then ( self.last := null ) else skip ; self.first := self.first.next ; return value; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( run() ) else skip; operation run() pre: true post: true activity: var n : OclAny := null; var nq : OclAny := null; Sequence{n,nq} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var qs : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((Queue.newQueue()).initialise())) ; for _anon : Integer.subrange(0, nq-1) do ( var line : String := (OclFile["System.in"]).readLine() ; if line->hasPrefix('0') then ( var command : OclAny := null; var target : OclAny := null; Sequence{command,target,value} := line.split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; (expr (atom (name qs)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name target)))))))) ])) (trailer . (name enqueue) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name value)))))))) )))) ) else (if line->hasPrefix('1') then ( var command : OclAny := null; var target : OclAny := null; Sequence{command,target} := line.split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; value := qs[target+1].front() ; if not(value <>= null) then ( execute (value)->display() ) else skip ) else (if line->hasPrefix('2') then ( var command : OclAny := null; var target : OclAny := null; Sequence{command,target} := line.split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; (expr (atom (name qs)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name target)))))))) ])) (trailer . (name dequeue) (arguments ( )))) ) else ( error IncorrectElementException.newIncorrectElementException('invalid command') ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def evenDecimalValue(str,n): result=0 for i in range(0,n): for j in range(i,n): decimalValue=0 ; powerOf2=1 ; for k in range(i,j+1): decimalValue+=((int(str[k])-0)*powerOf2) powerOf2*=2 if(decimalValue % 2==0): result+=1 return result str="10010" n=5 print(evenDecimalValue(str,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; OclType["String"] := "10010" ; n := 5 ; execute (evenDecimalValue(OclType["String"], n))->display(); operation evenDecimalValue(OclType["String"] : OclAny, n : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i, n-1) do ( var decimalValue : int := 0; ; var powerOf2 : int := 1; ; for k : Integer.subrange(i, j + 1-1) do ( decimalValue := decimalValue + ((("" + ((("" + ([k+1])))))->toInteger() - 0) * powerOf2) ; powerOf2 := powerOf2 * 2) ; if (decimalValue mod 2 = 0) then ( result := result + 1 ) else skip)) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque class Queue : def __init__(self): self.Q=deque() def enqueue(self,x): self.Q.appendleft(x) def front(self): if len(self.Q)>0 : print(self.Q[-1]) def dequeue(self): if len(self.Q)>0 : self.Q.pop() n,q=map(int,input().split()) QList=list() for i in range(n): QList.append(Queue()) for i in range(q): cmd=input() if cmd.startswith("0"): c,t,x=map(int,cmd.split(" ")) QList[t].enqueue(x) if cmd.startswith("1"): c,t=map(int,cmd.split(" ")) QList[t].front() if cmd.startswith("2"): c,t=map(int,cmd.split(" ")) QList[t].dequeue() ------------------------------------------------------------ OCL File: --------- class Queue { static operation newQueue() : Queue pre: true post: Queue->exists( _x | result = _x ); attribute Q : Sequence := (); operation initialise() : Queue pre: true post: true activity: self.Q := (); return self; operation enqueue(x : OclAny) pre: true post: true activity: (expr (atom (name self)) (trailer . (name Q)) (trailer . (name appendleft) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))); operation front() pre: true post: true activity: if (self.Q)->size() > 0 then ( execute (self.Q->last())->display() ) else skip; operation dequeue() pre: true post: true activity: if (self.Q)->size() > 0 then ( (expr (atom (name self)) (trailer . (name Q)) (trailer . (name pop) (arguments ( )))) ) else skip; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var QList : Sequence := () ; for i : Integer.subrange(0, n-1) do ( execute (((Queue.newQueue()).initialise()) : QList)) ; for i : Integer.subrange(0, q-1) do ( var cmd : String := (OclFile["System.in"]).readLine() ; if cmd->hasPrefix("0") then ( var c : OclAny := null; var t : OclAny := null; Sequence{c,t,x} := (cmd.split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name QList)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name enqueue) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) ) else skip ; if cmd->hasPrefix("1") then ( var c : OclAny := null; var t : OclAny := null; Sequence{c,t} := (cmd.split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name QList)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name front) (arguments ( )))) ) else skip ; if cmd->hasPrefix("2") then ( var c : OclAny := null; var t : OclAny := null; Sequence{c,t} := (cmd.split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name QList)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name dequeue) (arguments ( )))) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,k=list(map(int,input().split())) if n==k : print(0) elif ntoInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = k then ( execute (0)->display() ) else (if (n->compareTo(k)) < 0 then ( execute (k - n)->display() ) else ( execute ((n + k) mod 2)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) s=input() st=set(s) a=[0]*n for i in st : for j in range(s.find(i),s.rfind(i)+1): a[j]+=1 if max(a)>k : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var st : Set := Set{}->union((s)) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : st do ( for j : Integer.subrange(s->indexOf(i) - 1, s.rfind(i) + 1-1) do ( a[j+1] := a[j+1] + 1)) ; if ((a)->max()->compareTo(k)) > 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) string=input() last_pos={} for i in range(n): last_pos[string[i]]=i open_doors=set() marker=0 for i in range(n): open_doors.add(string[i]) if(len(open_doors)>k): print("YES") marker=1 break if last_pos[string[i]]==i : open_doors.discard(string[i]) if marker==0 : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var string : String := (OclFile["System.in"]).readLine() ; var last_pos : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( last_pos[string[i+1]+1] := i) ; var open_doors : Set := Set{}->union(()) ; var marker : int := 0 ; for i : Integer.subrange(0, n-1) do ( execute ((string[i+1]) : open_doors) ; if (((open_doors)->size()->compareTo(k)) > 0) then ( execute ("YES")->display() ; marker := 1 ; break ) else skip ; if last_pos[string[i+1]+1] = i then ( execute ((string[i+1]) /: open_doors) ) else skip) ; if marker = 0 then ( execute ("NO")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,k=map(int,input().split()) w=input()[:-1] d=[0]*n for i in range(65,91): a=w.find(chr(i)) b=w.rfind(chr(i)) d[a : b+1]=[j+1 for j in d[a : b+1]] if max(d)>k : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : OclAny := input()->front() ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(65, 91-1) do ( var a : int := w->indexOf((i)->byte2char()) - 1 ; var b : OclAny := w.rfind((i)->byte2char()) ; d.subrange(a+1, b + 1) := d.subrange(a+1, b + 1)->select(j | true)->collect(j | (j + 1))) ; if ((d)->max()->compareTo(k)) > 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def largest(arr,n): max=arr[0] for i in range(1,n): if arr[i]>max : max=arr[i] return max def resi(n,k,niz): poc=[0]*100 kraj=[0]*100 for i in range(65,65+26): poc[i]=-1 kraj[i]=-1 for j in range(n): if poc[ord(niz[j])]==-1 : poc[ord(niz[j])]=j kraj[ord(niz[j])]=j opened=[0]*n opened[0]=1 for i in range(1,n): opened[i]=opened[i-1] if poc[ord(niz[i])]==i : opened[i]+=1 if kraj[ord(niz[i-1])]==i-1 : opened[i]-=1 if largest(opened,n)>k : print("YES") else : print("NO") n,k=map(int,input().split()) niz=input() resi(n,k,niz) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; niz := (OclFile["System.in"]).readLine() ; resi(n, k, niz); operation largest(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var max : OclAny := arr->first() ; for i : Integer.subrange(1, n-1) do ( if (arr[i+1]->compareTo(max)) > 0 then ( max := arr[i+1] ) else skip) ; return max; operation resi(n : OclAny, k : OclAny, niz : OclAny) pre: true post: true activity: var poc : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100) ; var kraj : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100) ; for i : Integer.subrange(65, 65 + 26-1) do ( poc[i+1] := -1 ; kraj[i+1] := -1) ; for j : Integer.subrange(0, n-1) do ( if poc[(niz[j+1])->char2byte()+1] = -1 then ( poc[(niz[j+1])->char2byte()+1] := j ) else skip ; kraj[(niz[j+1])->char2byte()+1] := j) ; var opened : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; opened->first() := 1 ; for i : Integer.subrange(1, n-1) do ( opened[i+1] := opened[i - 1+1] ; if poc[(niz[i+1])->char2byte()+1] = i then ( opened[i+1] := opened[i+1] + 1 ) else skip ; if kraj[(niz[i - 1+1])->char2byte()+1] = i - 1 then ( opened[i+1] := opened[i+1] - 1 ) else skip) ; if (largest(opened, n)->compareTo(k)) > 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) st=input() s=set(st) ans=0 d=[0]*n for i in s : for j in range(st.find(i),st.rfind(i)+1): d[j]+=1 if(max(d)>k): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var st : String := (OclFile["System.in"]).readLine() ; var s : Set := Set{}->union((st)) ; var ans : int := 0 ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : s do ( for j : Integer.subrange(st->indexOf(i) - 1, st.rfind(i) + 1-1) do ( d[j+1] := d[j+1] + 1)) ; if (((d)->max()->compareTo(k)) > 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : space=4 prt='$' for i in range(1,6): for sp in range(space,0,-1): print(end="") for j in range(1,i+1): print(prt,end="") for k in range(1,i): if(i==1): continue print(prt,end="") print() space-=1 space=1 for i in range(4,0,-1): for sp in range(space,0,-1): print(end="") for j in range(1,i+1): print(prt,end="") for k in range(1,i): print(prt,end="") space+=1 print() space=3 for i in range(2,6): if((i % 2)!=0): for sp in range(space,0,-1): print("",end="") for j in range(1,i+1): print(prt,end="") if((i % 2)!=0): print() space-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var space : int := 4 ; var prt : String := '$' ; for i : Integer.subrange(1, 6-1) do ( for sp : Integer.subrange(0 + 1, space)->reverse() do ( execute ((argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom "")))))))->display()) ; for j : Integer.subrange(1, i + 1-1) do ( execute (prt)->display()) ; for k : Integer.subrange(1, i-1) do ( if (i = 1) then ( continue ) else skip ; execute (prt)->display()) ; execute (->display() ; space := space - 1) ; space := 1 ; for i : Integer.subrange(0 + 1, 4)->reverse() do ( for sp : Integer.subrange(0 + 1, space)->reverse() do ( execute ((argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom "")))))))->display()) ; for j : Integer.subrange(1, i + 1-1) do ( execute (prt)->display()) ; for k : Integer.subrange(1, i-1) do ( execute (prt)->display()) ; space := space + 1 ; execute (->display()) ; space := 3 ; for i : Integer.subrange(2, 6-1) do ( if ((i mod 2) /= 0) then ( for sp : Integer.subrange(0 + 1, space)->reverse() do ( execute ("")->display()) ; for j : Integer.subrange(1, i + 1-1) do ( execute (prt)->display()) ) else skip ; if ((i mod 2) /= 0) then ( execute (->display() ; space := space - 1 ) else skip) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dfs(adj,node,parent,color): count_color[color]+=1 for i in range(len(adj[node])): if(adj[node][i]!=parent): dfs(adj,adj[node][i],node,not color) def findMaxEdges(adj,n): dfs(adj,1,0,0) return(count_color[0]*count_color[1]-(n-1)) count_color=[0,0] n=5 adj=[[]for i in range(n+1)] adj[1].append(2) adj[1].append(3) adj[2].append(4) adj[3].append(5) print(findMaxEdges(adj,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var count_color : Sequence := Sequence{0}->union(Sequence{ 0 }) ; n := 5 ; adj := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Sequence{})) ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))) ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 3))))))))) )))) ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 4))))))))) )))) ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 3))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 5))))))))) )))) ; execute (findMaxEdges(adj, n))->display(); operation dfs(adj : OclAny, node : OclAny, parent : OclAny, color : OclAny) pre: true post: true activity: count_color[color+1] := count_color[color+1] + 1 ; for i : Integer.subrange(0, (adj[node+1])->size()-1) do ( if (adj[node+1][i+1] /= parent) then ( dfs(adj, adj[node+1][i+1], node, not(color)) ) else skip); operation findMaxEdges(adj : OclAny, n : OclAny) : OclAny pre: true post: true activity: dfs(adj, 1, 0, 0) ; return (count_color->first() * count_color[1+1] - (n - 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def digSum(n): if n==0 : return 0 elif n % 9==0 : return 9 else : return n % 9 def powerDigitSum(a,n): res=1 while(n): if n % 2==1 : res=res*digSum(a) res=digSum(res) a=digSum(digSum(a)*digSum(a)) n//=2 return res if __name__=="__main__" : a,n=9,4 print(powerDigitSum(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( Sequence{a,n} := Sequence{9,4} ; execute (powerDigitSum(a, n))->display() ) else skip; operation digSum(n : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( return 0 ) else (if n mod 9 = 0 then ( return 9 ) else ( return n mod 9 ) ) ; operation powerDigitSum(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; while (n) do ( if n mod 2 = 1 then ( res := res * digSum(a) ; res := digSum(res) ) else skip ; a := digSum(digSum(a) * digSum(a)) ; n := n div 2) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxLength(arr,N): product=1 Len=0 for i in arr : product*=i if(product>=0): return N for i in range(N): if(arr[i]<0): Len=max(Len,max(N-i-1,i)) return Len if __name__=='__main__' : arr=[-1,1,1,-2,3,2,-1] N=len(arr) print(maxLength(arr,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{-1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{-2}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ -1 })))))) ; N := (arr)->size() ; execute (maxLength(arr, N))->display() ) else skip; operation maxLength(arr : OclAny, N : OclAny) : OclAny pre: true post: true activity: var product : int := 1 ; var Len : int := 0 ; for i : arr do ( product := product * i) ; if (product >= 0) then ( return N ) else skip ; for i : Integer.subrange(0, N-1) do ( if (arr[i+1] < 0) then ( Len := Set{Len, Set{N - i - 1, i}->max()}->max() ) else skip) ; return Len; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from numpy import* a,b=loadtxt(open(0),'i',skiprows=1) c=0 l=1<<29 while l : u=l ; l>>=1 ; c+=sum(diff(searchsorted(sort(r_[b % u-u,b % u]),([u],[l])-a % u).T))% 2*l print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := loadtxt(OclFile.newOclFile_Write(OclFile.newOclFile(0)), 'i', (argument (test (logical_test (comparison (expr (atom (name skiprows)))))) = (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ; var c : int := 0 ; var l : int := 1 * (2->pow(29)) ; while l do ( var u : int := l; l := l div (2->pow(1)); c := c + (diff(searchsorted(sort(r_[b mod u - u+1][b mod u+1]), Sequence{Sequence{ u }, Sequence{ l }} - a mod u).T))->sum() mod 2 * l) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) if ntoInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (n->compareTo(k)) < 0 then ( execute ((n - k)->abs())->display() ) else (if n mod 2 = k mod 2 then ( execute (0)->display() ) else ( execute (1)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getArray(n): ans=[]; p2=1 ; while(n>0): if(n & 1): ans.append(p2); n>>=1 ; p2*=2 ; return ans ; if __name__=="__main__" : n=15 ; ans=getArray(n); for i in ans : print(i,end=" "); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 15; ; ans := getArray(n); ; for i : ans do ( execute (i)->display();) ) else skip; operation getArray(n : OclAny) pre: true post: true activity: var ans : Sequence := Sequence{}; ; var p2 : int := 1; ; while (n > 0) do ( if (MathLib.bitwiseAnd(n, 1)) then ( execute ((p2) : ans); ) else skip ; n := n div (2->pow(1)); ; p2 := p2 * 2;) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(a==0): return b return gcd(b % a,a); def findPossibleDerivables(arr,n,D,A,B): gcdAB=gcd(A,B) counter=0 for i in range(n): if((abs(arr[i]-D)% gcdAB)==0): counter+=1 return counter if __name__=="__main__" : arr=[1,2,3,4,7,13] n=len(arr) D,A,B=5,4,2 print(findPossibleDerivables(arr,n,D,A,B)) a=[1,2,3] n=len(a) D,A,B=6,3,2 print(findPossibleDerivables(a,n,D,A,B)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{7}->union(Sequence{ 13 }))))) ; n := (arr)->size() ; Sequence{D,A,B} := Sequence{5,4,2} ; execute (findPossibleDerivables(arr, n, D, A, B))->display() ; a := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; n := (a)->size() ; Sequence{D,A,B} := Sequence{6,3,2} ; execute (findPossibleDerivables(a, n, D, A, B))->display() ) else skip; operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0) then ( return b ) else skip ; return gcd(b mod a, a);; operation findPossibleDerivables(arr : OclAny, n : OclAny, D : OclAny, A : OclAny, B : OclAny) : OclAny pre: true post: true activity: var gcdAB : OclAny := gcd(A, B) ; var counter : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (((arr[i+1] - D)->abs() mod gcdAB) = 0) then ( counter := counter + 1 ) else skip) ; return counter; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def closetAND(arr,n,k): ans=10**9 for i in range(n): X=arr[i] for j in range(i,n): X &=arr[j] ans=min(ans,abs(k-X)) return ans arr=[4,7,10] n=len(arr) k=2 ; print(closetAND(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{4}->union(Sequence{7}->union(Sequence{ 10 })) ; n := (arr)->size() ; k := 2; ; execute (closetAND(arr, n, k))->display(); operation closetAND(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var ans : double := (10)->pow(9) ; for i : Integer.subrange(0, n-1) do ( var X : OclAny := arr[i+1] ; for j : Integer.subrange(i, n-1) do ( X := X & arr[j+1] ; ans := Set{ans, (k - X)->abs()}->min())) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(args): A,B=map(int,input().split()) sign=1 if A*B>=0 else-1 print(abs(A)//abs(B)*sign) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation main(args : OclAny) pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sign : int := if A * B >= 0 then 1 else -1 endif ; execute ((A)->abs() div (B)->abs() * sign)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) if(a*b<0): a*=-1 a//=b a*=-1 else : a//=b print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a * b < 0) then ( a := a * -1 ; a := a div b ; a := a * -1 ) else ( a := a div b ) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import decimal def main(): a,b=map(int,input().split()) decimal.getcontext().prec=len(str(a)) print(int(decimal.Decimal(a)/decimal.Decimal(b))) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; decimal.getcontext().prec := (("" + ((a))))->size() ; execute (("" + ((decimal.Decimal(a) / decimal.Decimal(b))))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=[int(x)for x in input().split()] c=abs(a)//abs(b) print(-c if a ^ b<0 else c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var c : int := (a)->abs() div (b)->abs() ; execute (if MathLib.bitwiseXor(a, b) < 0 then -c else c endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) ans=a//b if a<0 and ans*b!=a and b>0 : ans+=1 if b<0 and ans*b!=a and a>0 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := a div b ; if a < 0 & ans * b /= a & b > 0 then ( ans := ans + 1 ) else skip ; if b < 0 & ans * b /= a & a > 0 then ( ans := ans + 1 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(args): A,B=map(int,input().split()) print(A*B) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation main(args : OclAny) pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (A * B)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(eval(input().replace(" ","*"))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (input().replace(" ", "*"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,k=list(map(int,input().split())) if n<=k : print(k-n) else : print(((n % 2)^(k % 2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (n->compareTo(k)) <= 0 then ( execute (k - n)->display() ) else ( execute ((MathLib.bitwiseXor((n mod 2), (k mod 2))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import numpy as np import gzip import base64 atcoder = { 'name': 'numba_modules', 'file': 'numba_modules.cpython-34m.so', 'func': ['solve'], 'gz': '' } gz = gzip.decompress(base64.b64decode(atcoder['gz'])) with open(atcoder['file'], 'wb') as f: f.write(gz) from numba_modules import solve line = sys.stdin.readline N = int(line()) a = np.fromstring(line(), dtype=np.int32, sep=' ') b = np.fromstring(line(), dtype=np.int32, sep=' ') ans = 0 for i in range(29): ans += solve(i, a, b) * (2 ** i) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var atcoder : Map := Map{ 'name' |-> 'numba_modules' }->union(Map{ 'file' |-> 'numba_modules.cpython-34m.so' }->union(Map{ 'func' |-> Sequence{ 'solve' } }->union(Map{ 'gz' |-> '' }))) ; var gz : OclAny := gzip.decompress(base64.b64decode(atcoder->at('gz'))) ; try (var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(atcoder->at('file'))); f.write(gz)) catch (_e : OclException) do skip ; skip ; var line : OclAny := (OclFile["System.in"]).readline ; var N : int := ("" + ((line())))->toInteger() ; var a : Sequence := ; var b : Sequence := ; var ans : int := 0 ; for i : Integer.subrange(0, 29-1) do ( ans := ans + solve(i, a, b) * ((2)->pow(i))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import reduce print(reduce(lambda x,y : x*y,map(int,input().split()),1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (reduce(lambda x : OclAny, y : OclAny in (x * y), (input().split())->collect( _x | (OclType["int"])->apply(_x) ), 1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=input().split(" ") a=int(a) b=int(b) print(a*b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split(" ") ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; execute (a * b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input().split() print(int(s[0])*int(s[1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := input().split() ; execute (("" + ((s->first())))->toInteger() * ("" + ((s[1+1])))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break ans=[0 for _ in range(7)] for _ in range(n): age=int(input()) if age<10 : ans[0]+=1 elif age<20 : ans[1]+=1 elif age<30 : ans[2]+=1 elif age<40 : ans[3]+=1 elif age<50 : ans[4]+=1 elif age<60 : ans[5]+=1 else : ans[6]+=1 for a in ans : print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var ans : Sequence := Integer.subrange(0, 7-1)->select(_anon | true)->collect(_anon | (0)) ; for _anon : Integer.subrange(0, n-1) do ( var age : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if age < 10 then ( ans->first() := ans->first() + 1 ) else (if age < 20 then ( ans[1+1] := ans[1+1] + 1 ) else (if age < 30 then ( ans[2+1] := ans[2+1] + 1 ) else (if age < 40 then ( ans[3+1] := ans[3+1] + 1 ) else (if age < 50 then ( ans[4+1] := ans[4+1] + 1 ) else (if age < 60 then ( ans[5+1] := ans[5+1] + 1 ) else ( ans[6+1] := ans[6+1] + 1 ) ) ) ) ) ) ) ; for a : ans do ( execute (a)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin from collections import defaultdict input=stdin.readline def main(args): while True : n=int(input()) if n==0 : break visitors=defaultdict(int) for _ in range(n): age=int(input()) if age<10 : visitors['under10']+=1 elif age<20 : visitors['10s']+=1 elif age<30 : visitors['20s']+=1 elif age<40 : visitors['30s']+=1 elif age<50 : visitors['40s']+=1 elif age<60 : visitors['50s']+=1 else : visitors['60s+']+=1 print(visitors['under10']) print(visitors['10s']) print(visitors['20s']) print(visitors['30s']) print(visitors['40s']) print(visitors['50s']) print(visitors['60s+']) def main2(args): while True : n=int(input()) if n==0 : break age=[0]*(120+1) for _ in range(n): n=int(input()) age[n]+=1 print(sum(age[0 : 10])) print(sum(age[10 : 20])) print(sum(age[20 : 30])) print(sum(age[30 : 40])) print(sum(age[40 : 50])) print(sum(age[50 : 60])) print(sum(age[60 :])) if __name__=='__main__' : main2(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; if __name__ = '__main__' then ( main2((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation main(args : OclAny) pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var visitors : OclAny := defaultdict(OclType["int"]) ; for _anon : Integer.subrange(0, n-1) do ( var age : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if age < 10 then ( visitors->at('under10') := visitors->at('under10') + 1 ) else (if age < 20 then ( visitors->at('10s') := visitors->at('10s') + 1 ) else (if age < 30 then ( visitors->at('20s') := visitors->at('20s') + 1 ) else (if age < 40 then ( visitors->at('30s') := visitors->at('30s') + 1 ) else (if age < 50 then ( visitors->at('40s') := visitors->at('40s') + 1 ) else (if age < 60 then ( visitors->at('50s') := visitors->at('50s') + 1 ) else ( visitors->at('60s+') := visitors->at('60s+') + 1 ) ) ) ) ) ) ) ; execute (visitors->at('under10'))->display() ; execute (visitors->at('10s'))->display() ; execute (visitors->at('20s'))->display() ; execute (visitors->at('30s'))->display() ; execute (visitors->at('40s'))->display() ; execute (visitors->at('50s'))->display() ; execute (visitors->at('60s+'))->display()); operation main2(args : OclAny) pre: true post: true activity: while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; age := MatrixLib.elementwiseMult(Sequence{ 0 }, (120 + 1)) ; for _anon : Integer.subrange(0, n-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; age[n+1] := age[n+1] + 1) ; execute ((age.subrange(0+1, 10))->sum())->display() ; execute ((age.subrange(10+1, 20))->sum())->display() ; execute ((age.subrange(20+1, 30))->sum())->display() ; execute ((age.subrange(30+1, 40))->sum())->display() ; execute ((age.subrange(40+1, 50))->sum())->display() ; execute ((age.subrange(50+1, 60))->sum())->display() ; execute ((age.subrange(60+1))->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : input_count=int(input()) if input_count==0 : break data=[int(input())for _ in range(input_count)] counter=[0]*12 for item in data : counter[item//10]+=1 counter[6]=sum(counter[6 :]) counter=counter[: 7] counter=[str(item)for item in counter] print("\n".join(counter)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var input_count : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if input_count = 0 then ( break ) else skip ; var data : Sequence := Integer.subrange(0, input_count-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var counter : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 12) ; for item : data do ( counter[item div 10+1] := counter[item div 10+1] + 1) ; counter[6+1] := (counter.subrange(6+1))->sum() ; counter := counter.subrange(1,7) ; counter := counter->select(item | true)->collect(item | (("" + ((item))))) ; execute (StringLib.sumStringsWithSeparator((counter), "\n"))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cls(i): if i<60 : return i//10 else : return 6 def answer(n,d): tbl=[0 for i in range(7)] for i in range(n): c=cls(d[i]) tbl[c]+=1 return tbl while True : n=int(input()) if n==0 : break d=[int(input())for i in range(n)] o=answer(n,d) for i in range(7): print(o[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; d := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var o : OclAny := answer(n, d) ; for i : Integer.subrange(0, 7-1) do ( execute (o[i+1])->display())); operation cls(i : OclAny) : OclAny pre: true post: true activity: if i < 60 then ( return i div 10 ) else ( return 6 ); operation answer(n : OclAny, d : OclAny) : OclAny pre: true post: true activity: var tbl : Sequence := Integer.subrange(0, 7-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( var c : OclAny := cls(d[i+1]) ; tbl[c+1] := tbl[c+1] + 1) ; return tbl; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys while 1 : n=int(input()) if n==0 : sys.exit() arr=[0]*7 while n : a=int(input()) if a>60 : a=61 arr[int(a/10)]+=1 n-=1 for i in range(len(arr)): print(arr[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( sys.exit() ) else skip ; var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 7) ; while n do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if a > 60 then ( a := 61 ) else skip ; arr[("" + ((a / 10)))->toInteger()+1] := arr[("" + ((a / 10)))->toInteger()+1] + 1 ; n := n - 1) ; for i : Integer.subrange(0, (arr)->size()-1) do ( execute (arr[i+1])->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def TrialDivision(N): i=2 k=int(N**0.5) while(i<=k): if(N % i==0): return 0 i+=1 return 1 if __name__=="__main__" : N=49 p=TrialDivision(N) if(p): print("Prime") else : print("Composite") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := 49 ; var p : OclAny := TrialDivision(N) ; if (p) then ( execute ("Prime")->display() ) else ( execute ("Composite")->display() ) ) else skip; operation TrialDivision(N : OclAny) : OclAny pre: true post: true activity: var i : int := 2 ; var k : int := ("" + (((N)->pow(0.5))))->toInteger() ; while ((i->compareTo(k)) <= 0) do ( if (N mod i = 0) then ( return 0 ) else skip ; i := i + 1) ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countWays(n,arr): count=[0]*(n+1) count[0]=1 if(n==0): return 1 for i in range(1,n+1): no_ways=0 for j in arr : if(i-j>=0): no_ways+=count[i-j] count[i]=no_ways return count[n] arr=[1,3,5] n=5 print(countWays(n,arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{3}->union(Sequence{ 5 })) ; n := 5 ; execute (countWays(n, arr))->display(); operation countWays(n : OclAny, arr : OclAny) : OclAny pre: true post: true activity: var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; count->first() := 1 ; if (n = 0) then ( return 1 ) else skip ; for i : Integer.subrange(1, n + 1-1) do ( var no_ways : int := 0 ; for j : arr do ( if (i - j >= 0) then ( no_ways := no_ways + count[i - j+1] ) else skip ; count[i+1] := no_ways)) ; return count[n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys INT_MIN=-sys.maxsize-1 def maxSum(arr,n,k): if not n>k : print("Invalid") return-1 max_sum=INT_MIN window_sum=sum(arr[: k]) for i in range(n-k): window_sum=window_sum-arr[i]+arr[i+k] max_sum=max(window_sum,max_sum) return max_sum arr=[1,4,2,10,2,3,1,0,20] k=4 n=len(arr) print(maxSum(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var INT_MIN : double := -(trailer . (name maxsize)) - 1 ; skip ; arr := Sequence{1}->union(Sequence{4}->union(Sequence{2}->union(Sequence{10}->union(Sequence{2}->union(Sequence{3}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 20 })))))))) ; k := 4 ; n := (arr)->size() ; execute (maxSum(arr, n, k))->display(); operation maxSum(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if not((n->compareTo(k)) > 0) then ( execute ("Invalid")->display() ; return -1 ) else skip ; var max_sum : OclAny := INT_MIN ; var window_sum : OclAny := (arr.subrange(1,k))->sum() ; for i : Integer.subrange(0, n - k-1) do ( window_sum := window_sum - arr[i+1] + arr[i + k+1] ; max_sum := Set{window_sum, max_sum}->max()) ; return max_sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cubes=int(input()) height=0 floor=1 while cubes>=floor : height+=1 cubes-=floor floor+=height+1 print(height) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cubes : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var height : int := 0 ; var floor : int := 1 ; while (cubes->compareTo(floor)) >= 0 do ( height := height + 1 ; cubes := cubes - floor ; floor := floor + height + 1) ; execute (height)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import numpy as np import gzip import base64 atcoder = {'name': 'numba_modules', 'file': 'numba_modules.cpython-34m.so', 'func': ['solve'], 'gz': ''} gz = gzip.decompress(base64.b64decode(atcoder['gz'])) with open(atcoder['file'], 'wb') as f: f.write(gz) from numba_modules import solve line = sys.stdin.readline N = int(line()) a = np.fromstring(line(), dtype=np.int64, sep=' ') b = np.fromstring(line(), dtype=np.int64, sep=' ') print(solve(a, b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var atcoder : Map := Map{ 'name' |-> 'numba_modules' }->union(Map{ 'file' |-> 'numba_modules.cpython-34m.so' }->union(Map{ 'func' |-> Sequence{ 'solve' } }->union(Map{ 'gz' |-> '' }))) ; var gz : OclAny := gzip.decompress(base64.b64decode(atcoder->at('gz'))) ; try (var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(atcoder->at('file'))); f.write(gz)) catch (_e : OclException) do skip ; skip ; var line : OclAny := (OclFile["System.in"]).readline ; var N : int := ("" + ((line())))->toInteger() ; var a : Sequence := ; var b : Sequence := ; execute (solve(a, b))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys def printe(*st): return True sys.stderr.write(",".join([str(x)for x in st])+"\n") def generator(N,l): a=0 i=0 while at : pfactory.append(star) if not firstBuilt : firstBuilt=True pfactory.append((sum-t)/2) sum+=star*2 printe(star) if sum>t : if not firstBuilt : pfactory.append((sum-t)/2) pfactory.sort(reverse=True) printe("pf",pfactory) for i in range(L): if i>=len(pfactory): break sum-=pfactory[i] return int(sum) if __name__=='__main__' : for i in range(int(input())): print("Case #{}:{}".format(i+1,simulate())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{i + 1, simulate()}))->display()) ) else skip; operation printe(st : OclAny : Sequence(OclAny)) : OclAny pre: true post: true activity: (args * (named_parameter (name st))) return true ; (expr (atom (name sys)) (trailer . (name stderr)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ",") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name st))))))) ]))))))) )))) + (expr (atom "\n")))))))) )))); operation generator(N : OclAny, l : OclAny) pre: true post: true activity: var a : int := 0 ; var i : int := 0 ; while (a->compareTo(N)) < 0 do ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return l[i+1] ; i := i + 1 ; if i = (l)->size() then ( i := 0 ) else skip ; a := a + 1); operation simulate() : OclAny pre: true post: true activity: l := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; var L : OclAny := l->at(0`firstArg+1) ; l := l->excludingAt(0+1) ; var t : OclAny := l->at(0`firstArg+1) ; l := l->excludingAt(0+1) ; N := l->at(0`firstArg+1) ; l := l->excludingAt(0+1) ; var C : OclAny := l->at(0`firstArg+1) ; l := l->excludingAt(0+1) ; printe(l) ; var sum : int := 0 ; var pfactory : Sequence := Sequence{} ; var firstBuilt : boolean := false ; for star : generator(N, l) do ( if (sum->compareTo(t)) > 0 then ( execute ((star) : pfactory) ; if not(firstBuilt) then ( firstBuilt := true ; execute (((sum - t) / 2) : pfactory) ) else skip ) else skip ; sum := sum + star * 2 ; printe(star)) ; if (sum->compareTo(t)) > 0 then ( if not(firstBuilt) then ( execute (((sum - t) / 2) : pfactory) ) else skip ) else skip ; pfactory := pfactory->sort() ; printe("pf", pfactory) ; for i : Integer.subrange(0, L-1) do ( if (i->compareTo((pfactory)->size())) >= 0 then ( break ) else skip ; sum := sum - pfactory[i+1]) ; return ("" + ((sum)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import division import sys import math def calc(line): boosters=int(line[0]) ready=int(line[1]) stars=int(line[2]) dist=[int(x)for x in line[4 :]] dist=dist*int(math.ceil(stars/len(dist))) dist=dist[: stars] timer=0 i=0 while timerfirst() ; for i : Integer.subrange(0, numTestCases-1) do ( var result : OclAny := calc(getints()) ; execute (StringLib.format("Case #%d: %d",Sequence{i + 1, result}))->display()); operation calc(line : OclAny) : OclAny pre: true post: true activity: var boosters : int := ("" + ((line->first())))->toInteger() ; var ready : int := ("" + ((line[1+1])))->toInteger() ; var stars : int := ("" + ((line[2+1])))->toInteger() ; var dist : Sequence := line.subrange(4+1)->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; dist := MatrixLib.elementwiseMult(dist, ("" + (((stars / (dist)->size())->ceil())))->toInteger()) ; dist := dist.subrange(1,stars) ; var timer : int := 0 ; var i : int := 0 ; while (timer->compareTo(ready)) < 0 do ( if (ready - timer->compareTo(dist[i+1] * 2)) < 0 then ( dist[i+1] := dist[i+1] - (ready - timer) / 2 ; timer := ready ) else ( timer := timer + dist[i+1] * 2 ; i := i + 1 ; if i = stars then ( return timer ) else skip )) ; dist := ((dist.subrange(i+1)->sort())->reverse()) ; for i : Integer.subrange(boosters, (dist)->size()-1) do ( dist[i+1] := dist[i+1] * 2) ; timer := timer + (dist)->sum() ; return timer; operation getints() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxProduct(arr,n): if(n<2): print("No pairs exists") return if(n==2): print(arr[0]," ",arr[1]) return posa=0 posb=0 nega=0 negb=0 for i in range(n): if(arr[i]>posa): posb=posa posa=arr[i] elif(arr[i]>posb): posb=arr[i] if(arr[i]<0 and abs(arr[i])>abs(nega)): negb=nega nega=arr[i] elif(arr[i]<0 and abs(arr[i])>abs(negb)): negb=arr[i] if(nega*negb>posa*posb): print("Max product pair is{",nega,",",negb,"}") else : print("Max product pair is{",posa,",",posb,"}") if __name__=="__main__" : arr=[1,4,3,6,7,0] n=len(arr) maxProduct(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{4}->union(Sequence{3}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 0 }))))) ; n := (arr)->size() ; maxProduct(arr, n) ) else skip; operation maxProduct(arr : OclAny, n : OclAny) pre: true post: true activity: if (n < 2) then ( execute ("No pairs exists")->display() ; return ) else skip ; if (n = 2) then ( execute (arr->first())->display() ; return ) else skip ; var posa : int := 0 ; var posb : int := 0 ; var nega : int := 0 ; var negb : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ((arr[i+1]->compareTo(posa)) > 0) then ( posb := posa ; posa := arr[i+1] ) else (if ((arr[i+1]->compareTo(posb)) > 0) then ( posb := arr[i+1] ) else skip) ; if (arr[i+1] < 0 & ((arr[i+1])->abs()->compareTo((nega)->abs())) > 0) then ( negb := nega ; nega := arr[i+1] ) else (if (arr[i+1] < 0 & ((arr[i+1])->abs()->compareTo((negb)->abs())) > 0) then ( negb := arr[i+1] ) else skip)) ; if ((nega * negb->compareTo(posa * posb)) > 0) then ( execute ("Max product pair is{")->display() ) else ( execute ("Max product pair is{")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculateLeaps(n): if n==0 or n==1 : return 1 ; else : leaps=0 ; for i in range(0,n): leaps=leaps+calculateLeaps(i); return leaps ; print(calculateLeaps(4)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (calculateLeaps(4))->display();; operation calculateLeaps(n : OclAny) pre: true post: true activity: if n = 0 or n = 1 then ( return 1; ) else ( var leaps : int := 0; ; for i : Integer.subrange(0, n-1) do ( leaps := leaps + calculateLeaps(i);) ; return leaps; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=1000000007 dp=[[[-1 for i in range(2)]for i in range(105)]for i in range(1005)] powers=[0]*1005 powersModk=[0]*1005 def calculate(pos,rem,z,k,n): if(rem==0 and z): if(pos!=n): return(powers[n-pos-1]*9)% mod else : return 1 if(pos==n): return 0 if(dp[pos][rem][z]!=-1): return dp[pos][rem][z] count=0 for i in range(10): if(i==0): count=(count+(calculate(pos+1,(rem+(i*powersModk[pos])% k)% k,z,k,n)))% mod else : count=(count+(calculate(pos+1,(rem+(i*powersModk[pos])% k)% k,1,k,n)))% mod dp[pos][rem][z]=count return count def countNumbers(n,k): st=1 for i in range(n+1): powers[i]=st st*=10 st %=mod st=1 for i in range(n+1): powersModk[i]=st st*=10 st %=mod return calculate(0,0,0,k,n) if __name__=='__main__' : N=2 K=2 print(countNumbers(N,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : int := 1000000007 ; var dp : Sequence := Integer.subrange(0, 1005-1)->select(i | true)->collect(i | (Integer.subrange(0, 105-1)->select(i | true)->collect(i | (Integer.subrange(0, 2-1)->select(i | true)->collect(i | (-1)))))) ; var powers : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 1005) ; var powersModk : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 1005) ; skip ; skip ; if __name__ = '__main__' then ( var N : int := 2 ; var K : int := 2 ; execute (countNumbers(N, K))->display() ) else skip; operation calculate(pos : OclAny, rem : OclAny, z : OclAny, k : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (rem = 0 & z) then ( if (pos /= n) then ( return (powers[n - pos - 1+1] * 9) mod mod ) else ( return 1 ) ) else skip ; if (pos = n) then ( return 0 ) else skip ; if (dp[pos+1][rem+1][z+1] /= -1) then ( return dp[pos+1][rem+1][z+1] ) else skip ; var count : int := 0 ; for i : Integer.subrange(0, 10-1) do ( if (i = 0) then ( count := (count + (calculate(pos + 1, (rem + (i * powersModk[pos+1]) mod k) mod k, z, k, n))) mod mod ) else ( count := (count + (calculate(pos + 1, (rem + (i * powersModk[pos+1]) mod k) mod k, 1, k, n))) mod mod )) ; dp[pos+1][rem+1][z+1] := count ; return count; operation countNumbers(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var st : int := 1 ; for i : Integer.subrange(0, n + 1-1) do ( powers[i+1] := st ; st := st * 10 ; st := st mod mod) ; st := 1 ; for i : Integer.subrange(0, n + 1-1) do ( powersModk[i+1] := st ; st := st * 10 ; st := st mod mod) ; return calculate(0, 0, 0, k, n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ReplaceElements(arr,n): max_ele=arr[0] arr[0]=-1 for i in range(1,n): if(max_ele>arr[i]): arr[i]=max_ele elif(max_ele<=arr[i]): temp=arr[i] arr[i]=max_ele max_ele=temp if __name__=="__main__" : arr=[4,5,2,1,7,6] n=len(arr) ReplaceElements(arr,n) for i in range(n): print(arr[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{4}->union(Sequence{5}->union(Sequence{2}->union(Sequence{1}->union(Sequence{7}->union(Sequence{ 6 }))))) ; n := (arr)->size() ; ReplaceElements(arr, n) ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()) ) else skip; operation ReplaceElements(arr : OclAny, n : OclAny) pre: true post: true activity: var max_ele : OclAny := arr->first() ; arr->first() := -1 ; for i : Integer.subrange(1, n-1) do ( if ((max_ele->compareTo(arr[i+1])) > 0) then ( arr[i+1] := max_ele ) else (if ((max_ele->compareTo(arr[i+1])) <= 0) then ( var temp : OclAny := arr[i+1] ; arr[i+1] := max_ele ; max_ele := temp ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printString(Str1,n): ones=0 for i in range(n): if(Str1[i]=='1'): ones+=1 used=False for i in range(n): if(Str1[i]=='2' and used==False): used=1 for j in range(ones): print("1",end="") if(Str1[i]!='1'): print(Str1[i],end="") if(used==False): for j in range(ones): print("1",end="") Str1="100210" n=len(Str1) printString(Str1,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Str1 := "100210" ; n := (Str1)->size() ; printString(Str1, n); operation printString(Str1 : OclAny, n : OclAny) pre: true post: true activity: var ones : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (Str1[i+1] = '1') then ( ones := ones + 1 ) else skip) ; var used : boolean := false ; for i : Integer.subrange(0, n-1) do ( if (Str1[i+1] = '2' & used = false) then ( used := 1 ; for j : Integer.subrange(0, ones-1) do ( execute ("1")->display()) ) else skip ; if (Str1[i+1] /= '1') then ( execute (Str1[i+1])->display() ) else skip) ; if (used = false) then ( for j : Integer.subrange(0, ones-1) do ( execute ("1")->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- word=str(input()) k=int(input()) length=len(word) unique=[] for char in word[: :]: if char not in unique : unique.append(char) count=len(unique) final_count=0 if k>length : print("impossible") if kcount : final_count=k-count print(final_count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var word : String := ("" + (((OclFile["System.in"]).readLine()))) ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var length : int := (word)->size() ; var unique : Sequence := Sequence{} ; for char : word(subscript : (sliceop :)) do ( if (unique)->excludes(char) then ( execute ((char) : unique) ) else skip) ; var count : int := (unique)->size() ; var final_count : int := 0 ; if (k->compareTo(length)) > 0 then ( execute ("impossible")->display() ) else skip ; if (k->compareTo(count)) < 0 then ( execute ("0")->display() ) else (if k = count then ( execute ("0")->display() ) else (if (k->compareTo(length)) <= 0 & (k->compareTo(count)) > 0 then ( final_count := k - count ; execute (final_count)->display() ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while(True): L=int(input()) if not L : break a=0 b=0 c=0 for _ in range(12): a+=1 M,N=map(int,input().split()) b+=M-N if not c and b>=L : c=a print(c if c else "NA") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while (true) do ( var L : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(L) then ( break ) else skip ; var a : int := 0 ; var b : int := 0 ; var c : int := 0 ; for _anon : Integer.subrange(0, 12-1) do ( a := a + 1 ; var M : OclAny := null; var N : OclAny := null; Sequence{M,N} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; b := b + M - N ; if not(c) & (b->compareTo(L)) >= 0 then ( c := a ) else skip) ; execute (if c then c else "NA" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSmallNum(N,K): rem=N % K if(rem==0): return N else : return N-rem def findLargeNum(N,K): rem=(N+K)% K if(rem==0): return N else : return N+K-rem def sumDivisibles(A,B,M): sum=0 first=findSmallNum(A,M) last=findLargeNum(B,M) if(firstB): first-=M n=(B//M)-(A-1)//M return n*(first+last)//2 if __name__=='__main__' : A=6 B=15 M=3 print(sumDivisibles(A,B,M)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( A := 6 ; B := 15 ; M := 3 ; execute (sumDivisibles(A, B, M))->display() ) else skip; operation findSmallNum(N : OclAny, K : OclAny) : OclAny pre: true post: true activity: var rem : int := N mod K ; if (rem = 0) then ( return N ) else ( return N - rem ); operation findLargeNum(N : OclAny, K : OclAny) : OclAny pre: true post: true activity: rem := (N + K) mod K ; if (rem = 0) then ( return N ) else ( return N + K - rem ); operation sumDivisibles(A : OclAny, B : OclAny, M : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; var first : OclAny := findSmallNum(A, M) ; var last : OclAny := findLargeNum(B, M) ; if ((first->compareTo(A)) < 0) then ( first := first + M ) else skip ; if ((last->compareTo(B)) > 0) then ( first := first - M ) else skip ; var n : double := (B div M) - (A - 1) div M ; return n * (first + last) div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def getSum(arr,n): sum=0 ; hashSet=set(); for i in range(n): hashSet.add(arr[i]); for i in range(n): sqrtCurrent=math.sqrt(arr[i]); if(math.floor(sqrtCurrent)!=math.ceil(sqrtCurrent)): continue ; if(int(sqrtCurrent)in hashSet): sum+=int(sqrtCurrent*sqrtCurrent); return sum ; arr=[2,4,5,6,7,8,9,3]; n=len(arr); print(getSum(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{2}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{ 3 }))))))); ; n := (arr)->size(); ; execute (getSum(arr, n))->display();; operation getSum(arr : OclAny, n : OclAny) pre: true post: true activity: var sum : int := 0; ; var hashSet : Set := Set{}->union(()); ; for i : Integer.subrange(0, n-1) do ( execute ((arr[i+1]) : hashSet);) ; for i : Integer.subrange(0, n-1) do ( var sqrtCurrent : double := (arr[i+1])->sqrt(); ; if ((sqrtCurrent)->floor() /= (sqrtCurrent)->ceil()) then ( continue; ) else skip ; if ((hashSet)->includes(("" + ((sqrtCurrent)))->toInteger())) then ( sum := sum + ("" + ((sqrtCurrent * sqrtCurrent)))->toInteger(); ) else skip) ; return sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W,N=(int(x)for x in input().split()) X=[] Y=[] Xobslist=[[]for i in range(H)] Xobsnum=[] ans=H for i in range(H): Xobsnum.append(0) for i in range(N): x,y=(int(x)for x in input().split()) x-=1 y-=1 Xobslist[x].append(y) Xobsnum[x]+=1 can_go_to_Y=0 for x in range(H): if(x==0): continue xobsnum=Xobsnum[x] can_stop=False can_go_to_Y_will_inc=True for i in range(xobsnum): y=Xobslist[x][i] if(y<=can_go_to_Y): can_stop=True break elif(y==can_go_to_Y+1): can_go_to_Y_will_inc=False if can_stop : ans=x break if can_go_to_Y_will_inc : can_go_to_Y+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; var N : OclAny := null; Sequence{H,W,N} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var X : Sequence := Sequence{} ; var Y : Sequence := Sequence{} ; var Xobslist : Sequence := Integer.subrange(0, H-1)->select(i | true)->collect(i | (Sequence{})) ; var Xobsnum : Sequence := Sequence{} ; var ans : OclAny := H ; for i : Integer.subrange(0, H-1) do ( execute ((0) : Xobsnum)) ; for i : Integer.subrange(0, N-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; x := x - 1 ; y := y - 1 ; (expr (atom (name Xobslist)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))) ; Xobsnum[x+1] := Xobsnum[x+1] + 1) ; var can_go_to_Y : int := 0 ; for x : Integer.subrange(0, H-1) do ( if (x = 0) then ( continue ) else skip ; var xobsnum : OclAny := Xobsnum[x+1] ; var can_stop : boolean := false ; var can_go_to_Y_will_inc : boolean := true ; for i : Integer.subrange(0, xobsnum-1) do ( var y : OclAny := Xobslist[x+1][i+1] ; if ((y->compareTo(can_go_to_Y)) <= 0) then ( can_stop := true ; break ) else (if (y = can_go_to_Y + 1) then ( can_go_to_Y_will_inc := false ) else skip)) ; if can_stop then ( ans := x ; break ) else skip ; if can_go_to_Y_will_inc then ( can_go_to_Y := can_go_to_Y + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.buffer.readline mod=10**9+7 n=int(readline()) a=list(map(int,readline().split())) b=list(map(int,readline().split())) def f(md,pos): res=0 fpos=-2 for av in a : while True : if pos!=-1 and av+b[pos]>=md : pos-=1 else : if fpos==-2 : fpos=pos res+=pos+1 break return res,fpos def solve(): dp=[0]*31 for i in range(28,-1,-1): md=pow(2,i+1) for j in range(n-1,-1,-1): b[j]%=md a[j]%=md a.sort() b.sort() pos=n-1 res3,pos=f(md//2*3,pos) res2,pos=f(md//2*2,pos) res1,pos=f(md//2,pos) dp[i]+=(n*n-(res1+res3-res2))% 2 t=0 for i in range(31): t+=pow(2,i)*dp[i] print(t) if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := sys.stdin.buffer.readline ; var mod : double := (10)->pow(9) + 7 ; var n : int := ("" + ((readline())))->toInteger() ; var a : Sequence := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation f(md : OclAny, pos : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; var fpos : int := -2 ; for av : a do ( while true do ( if pos /= -1 & (av + b[pos+1]->compareTo(md)) >= 0 then ( pos := pos - 1 ) else ( if fpos = -2 then ( fpos := pos ) else skip ; res := res + pos + 1 ; break ))) ; return res, fpos; operation solve() pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 31) ; for i : Integer.subrange(-1 + 1, 28)->reverse() do ( md := (2)->pow(i + 1) ; for j : Integer.subrange(-1 + 1, n - 1)->reverse() do ( b[j+1] := b[j+1] mod md ; a[j+1] := a[j+1] mod md) ; a := a->sort() ; b := b->sort() ; pos := n - 1 ; var res3 : OclAny := null; Sequence{res3,pos} := f(md div 2 * 3, pos) ; var res2 : OclAny := null; Sequence{res2,pos} := f(md div 2 * 2, pos) ; var res1 : OclAny := null; Sequence{res1,pos} := f(md div 2, pos) ; dp[i+1] := dp[i+1] + (n * n - (res1 + res3 - res2)) mod 2) ; var t : int := 0 ; for i : Integer.subrange(0, 31-1) do ( t := t + (2)->pow(i) * dp[i+1]) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(obstacles): offset=0 obstacles.sort() for x,y in obstacles : if x>y+offset : return x-1 if x==y+offset : offset+=1 return h h,w,n=map(int,input().split()) obstacles=[tuple(map(int,line.split()))for line in sys.stdin.readlines()] print(solve(obstacles)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var h : OclAny := null; var w : OclAny := null; var n : OclAny := null; Sequence{h,w,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; obstacles := (OclFile["System.in"]).readlines()->select(line | true)->collect(line | (((line.split())->collect( _x | (OclType["int"])->apply(_x) )))) ; execute (solve(obstacles))->display(); operation solve(obstacles : OclAny) : OclAny pre: true post: true activity: var offset : int := 0 ; obstacles := obstacles->sort() ; for _tuple : obstacles do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if (x->compareTo(y + offset)) > 0 then ( return x - 1 ) else skip ; if x = y + offset then ( offset := offset + 1 ) else skip) ; return h; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from operator import itemgetter import bisect h,w,n=map(int,input().split()) info=[tuple(map(int,input().split()))for i in range(n)] memo=set() for i,j in info : memo.add(i*10**6+j) pos=[[]for _ in range(w+1)] info=sorted(info,key=itemgetter(0)) for i,j in info : pos[j].append(i) ans=10**18 pos_i,pos_j=1,1 ind=bisect.bisect_right(pos[pos_j],pos_i) try : ans=min(pos[pos_j][ind]-1,ans) except : pass while True : if(pos_i+1)*10**6+pos_j in memo or pos_i==h : ans=min(ans,pos_i) break pos_i+=1 if pos_i*10**6+(pos_j+1)in memo or pos_j==w : continue else : pos_j+=1 ind=bisect.bisect_right(pos[pos_j],pos_i) try : ans=min(pos[pos_j][ind]-1,ans) except : pass print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var h : OclAny := null; var w : OclAny := null; var n : OclAny := null; Sequence{h,w,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var info : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var memo : Set := Set{}->union(()) ; for _tuple : info do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); execute ((i * (10)->pow(6) + j) : memo)) ; var pos : Sequence := Integer.subrange(0, w + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; info := info->sortedBy($x | (itemgetter(0))->apply($x)) ; for _tuple : info do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); (expr (atom (name pos)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var ans : double := (10)->pow(18) ; var pos_i : OclAny := null; var pos_j : OclAny := null; Sequence{pos_i,pos_j} := Sequence{1,1} ; var ind : OclAny := bisect.bisect_right(pos[pos_j+1], pos_i) ; try ( ans := Set{pos[pos_j+1][ind+1] - 1, ans}->min()) catch (_e : OclException) do ( skip) ; while true do ( if (memo)->includes((pos_i + 1) * (10)->pow(6) + pos_j) or pos_i = h then ( ans := Set{ans, pos_i}->min() ; break ) else skip ; pos_i := pos_i + 1 ; if (memo)->includes(pos_i * (10)->pow(6) + (pos_j + 1)) or pos_j = w then ( continue ) else ( pos_j := pos_j + 1 ) ; ind := bisect.bisect_right(pos[pos_j+1], pos_i) ; try ( ans := Set{pos[pos_j+1][ind+1] - 1, ans}->min()) catch (_e : OclException) do ( skip) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000,10**9)) write=lambda x : sys.stdout.write(x+"\n") h,w,n=list(map(int,input().split())) from collections import defaultdict xy=defaultdict(list) for i in range(n): x,y=tuple(map(int,input().split())) xy[y].append(x) for k in range(1,w+1): xy[k].append(h+1) xy[k].sort() from bisect import bisect_left as bl v=1 ans=float("inf") for y in range(1,w+1): val=xy[y][bl(xy[y],v+1)] ans=min(ans,val-1) if val==v+1 : break if ypow(9)}->max()) ; var write : Function := lambda x : OclAny in ((OclFile["System.out"]).write(x + "\n")) ; var h : OclAny := null; var w : OclAny := null; var n : OclAny := null; Sequence{h,w,n} := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; var xy : OclAny := defaultdict(OclType["Sequence"]) ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (expr (atom (name xy)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))) ; for k : Integer.subrange(1, w + 1-1) do ((expr (atom (name xy)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name h))) + (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name xy)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])) (trailer . (name sort) (arguments ( ))))) ; skip ; var v : int := 1 ; var ans : double := ("" + (("inf")))->toReal() ; for y : Integer.subrange(1, w + 1-1) do ( var val : OclAny := xy[y+1][bl(xy[y+1], v + 1)+1] ; ans := Set{ans, val - 1}->min() ; if val = v + 1 then ( break ) else skip ; if (y->compareTo(w)) < 0 then ( v := v + 1 ; var tmp : OclAny := bl(xy[y + 1+1], v) ; while xy[y + 1+1][tmp+1] = v do ( v := v + 1 ; tmp := tmp + 1 ; if v = h + 1 then ( break ) else skip) ; if v = h + 1 then ( break ) else skip ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- isdbg=False def dprint(*value,sep='',end='\n'): if isdbg : print(*value,sep=sep,end=end) H,W,N=map(int,input().split()) if isdbg : XY=[[0 for i in range(W)]for i in range(H)] BL={} for i in range(N): x1,y1=map(int,input().split()) if isdbg : XY[x1-1][y1-1]=1 if x1-1 in BL : BL[x1-1].append(y1-1) else : BL[x1-1]=[y1-1] TL=sorted(BL.items(),key=lambda x : x[0]) if isdbg : for i in range(W): for j in range(H): dprint(XY[i][j],end='') dprint() maxr=1 for i in range(H-1): if i+1 in BL : l=BL[i+1] l.sort() for ll in l : if maxr>ll : print(i+1) exit(0) elif maxr==ll : maxr-=1 break else : break maxr+=1 print(H) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var isdbg : boolean := false ; skip ; var H : OclAny := null; var W : OclAny := null; var N : OclAny := null; Sequence{H,W,N} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if isdbg then ( var XY : Sequence := Integer.subrange(0, H-1)->select(i | true)->collect(i | (Integer.subrange(0, W-1)->select(i | true)->collect(i | (0)))) ) else skip ; var BL : OclAny := Set{} ; for i : Integer.subrange(0, N-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if isdbg then ( XY[x1 - 1+1][y1 - 1+1] := 1 ) else skip ; if (BL)->includes(x1 - 1) then ( (expr (atom (name BL)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x1))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name y1))) - (expr (atom (number (integer 1)))))))))) )))) ) else ( BL[x1 - 1+1] := Sequence{ y1 - 1 } )) ; var TL : Sequence := BL->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sortedBy($x | (lambda x : OclAny in (x->first()))->apply($x)) ; if isdbg then ( for i : Integer.subrange(0, W-1) do ( for j : Integer.subrange(0, H-1) do ( dprint(XY[i+1][j+1], (argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom '')))))))) ; dprint()) ) else skip ; var maxr : int := 1 ; for i : Integer.subrange(0, H - 1-1) do ( if (BL)->includes(i + 1) then ( var l : OclAny := BL[i + 1+1] ; l := l->sort() ; for ll : l do ( if (maxr->compareTo(ll)) > 0 then ( execute (i + 1)->display() ; exit(0) ) else (if maxr = ll then ( maxr := maxr - 1 ; break ) else ( break ) ) ) ) else skip ; maxr := maxr + 1) ; execute (H)->display(); operation dprint(value : OclAny : Sequence(OclAny), sep : String, end : String) pre: true post: true activity: (args * (named_parameter (name value))) if sep->oclIsUndefined() then sep := '' else skip; if end->oclIsUndefined() then end := ' ' else skip; if isdbg then ( execute ((argument * (test (logical_test (comparison (expr (atom (name value))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=[input()for z in range(n)] c=0 for i in range(1,n-1): for j in range(1,n-1): if m[i][j]==m[i-1][j-1]==m[i-1][j+1]==m[i+1][j-1]==m[i+1][j+1]=='X' : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : Sequence := Integer.subrange(0, n-1)->select(z | true)->collect(z | ((OclFile["System.in"]).readLine())) ; var c : int := 0 ; for i : Integer.subrange(1, n - 1-1) do ( for j : Integer.subrange(1, n - 1-1) do ( if m[i+1][j+1] = m[i - 1+1][j - 1+1] & (m[i - 1+1][j - 1+1] == m[i - 1+1][j + 1+1]) & (m[i - 1+1][j + 1+1] == m[i + 1+1][j - 1+1]) & (m[i + 1+1][j - 1+1] == m[i + 1+1][j + 1+1]) & (m[i + 1+1][j + 1+1] == 'X') then ( c := c + 1 ) else skip)) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=[input()for _ in[0]*n] print(sum(m[i+1][j+1]==m[i][j]==m[i][j+2]==m[i+2][j]==m[i+2][j+2]=='X' for i in range(n-2)for j in range(n-2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; execute (((argument (test (logical_test (comparison (comparison (comparison (comparison (comparison (comparison (expr (atom (name m)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 1)))))))))) ])))) == (comparison (expr (atom (name m)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))) == (comparison (expr (atom (name m)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 2)))))))))) ]))))) == (comparison (expr (atom (name m)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 2)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))) == (comparison (expr (atom (name m)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 2)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 2)))))))))) ]))))) == (comparison (expr (atom 'X')))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 2)))))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 2)))))))))) )))))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def jug(l,income): assert len(income)==12,"income strange" s=0 for i in range(len(income)): inc=income[i] s+=inc[0]-inc[1] if s>=l : return(str(i+1)) return("NA") while True : income=[] l=int(input()) if l==0 : break for i in range(12): m,n=list(map(int,input().strip().split())) income.append((m,n)) print(jug(l,income)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( income := Sequence{} ; l := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if l = 0 then ( break ) else skip ; for i : Integer.subrange(0, 12-1) do ( var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((Sequence{m, n}) : income)) ; execute (jug(l, income))->display()); operation jug(l : OclAny, income : OclAny) : OclAny pre: true post: true activity: assert (income)->size() = 12 do "income strange" ; var s : int := 0 ; for i : Integer.subrange(0, (income)->size()-1) do ( var inc : OclAny := income[i+1] ; s := s + inc->first() - inc[1+1] ; if (s->compareTo(l)) >= 0 then ( return (("" + ((i + 1)))) ) else skip) ; return ("NA"); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) k=[] for i in range(n): s=input() k.append(s) p=0 for i in range(1,n-1): for j in range(1,n-1): if k[i][j]=='X' and k[i-1][j-1]=='X' and k[i-1][j+1]=='X' and k[i+1][j-1]=='X' and k[i+1][j+1]=='X' : p+=1 print(p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; execute ((s) : k)) ; var p : int := 0 ; for i : Integer.subrange(1, n - 1-1) do ( for j : Integer.subrange(1, n - 1-1) do ( if k[i+1][j+1] = 'X' & k[i - 1+1][j - 1+1] = 'X' & k[i - 1+1][j + 1+1] = 'X' & k[i + 1+1][j - 1+1] = 'X' & k[i + 1+1][j + 1+1] = 'X' then ( p := p + 1 ) else skip)) ; execute (p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) m=[list(input().rstrip())for _ in range(n)] ans=0 for i in range(1,n-1): m1,m2,m3=m[i-1],m[i],m[i+1] for j in range(1,n-1): if m1[j-1]==m1[j+1]==m2[j]==m3[j-1]==m3[j+1]==88 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((input().rstrip()))) ; var ans : int := 0 ; for i : Integer.subrange(1, n - 1-1) do ( var m1 : OclAny := null; var m2 : OclAny := null; var m3 : OclAny := null; Sequence{m1,m2,m3} := Sequence{m[i - 1+1],m[i+1],m[i + 1+1]} ; for j : Integer.subrange(1, n - 1-1) do ( if m1[j - 1+1] = m1[j + 1+1] & (m1[j + 1+1] == m2[j+1]) & (m2[j+1] == m3[j - 1+1]) & (m3[j - 1+1] == m3[j + 1+1]) & (m3[j + 1+1] == 88) then ( ans := ans + 1 ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=[input()for i in range(n)] count=0 for i in range(1,n-1): for j in range(1,n-1): if arr[i-1][j-1]==arr[i-1][j+1]==arr[i+1][j-1]==arr[i+1][j+1]==arr[i][j]=="X" : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var count : int := 0 ; for i : Integer.subrange(1, n - 1-1) do ( for j : Integer.subrange(1, n - 1-1) do ( if arr[i - 1+1][j - 1+1] = arr[i - 1+1][j + 1+1] & (arr[i - 1+1][j + 1+1] == arr[i + 1+1][j - 1+1]) & (arr[i + 1+1][j - 1+1] == arr[i + 1+1][j + 1+1]) & (arr[i + 1+1][j + 1+1] == arr[i+1][j+1]) & (arr[i+1][j+1] == "X") then ( count := count + 1 ) else skip)) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findTriplets(arr,n,sum): arr.sort(); for i in range(0,n-1): l=i+1 ; r=n-1 ; x=arr[i]; while(lunion(Sequence{-1}->union(Sequence{2}->union(Sequence{-3}->union(Sequence{ 1 })))); ; sum := -2; ; n := (arr)->size(); ; findTriplets(arr, n, sum);; operation findTriplets(arr : OclAny, n : OclAny, sum : OclAny) pre: true post: true activity: arr := arr->sort(); ; for i : Integer.subrange(0, n - 1-1) do ( var l : OclAny := i + 1; ; var r : double := n - 1; ; var x : OclAny := arr[i+1]; ; while ((l->compareTo(r)) < 0) do ( if (x + arr[l+1] + arr[r+1] = sum) then ( execute (x)->display(); ; l := l + 1; ; r := r - 1; ) else (if ((x + arr[l+1] + arr[r+1]->compareTo(sum)) < 0) then ( l := l + 1; ) else ( r := r - 1; ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): from bisect import bisect_right as br n=int(input()) a=sorted(list(map(int,input().split()))) b=sorted(list(map(int,input().split())),reverse=True) m=n % 2 xor=0 for i in b : xor ^=i for i in range(n): b[i]=2**28-b[i] ans=0 for loop in range(28,-1,-1): j=pow(2,loop) k=(xor & j)//j temp=br(b,j-1) for i in range(temp,n): b[i]-=j b.sort() temp=br(a,j-1) for i in a[: temp]: k+=(i & j)//j for i in range(temp,n): k+=(a[i]& j)//j a[i]-=j x=(k+br(b,0))*m % 2 a.sort() l=0 for i in a : while l=b[l]: l+=1 else : break x+=l % 2 ans+=(x % 2)*j print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var m : int := n mod 2 ; var xor : int := 0 ; for i : b do ( xor := xor xor i) ; for i : Integer.subrange(0, n-1) do ( b[i+1] := (2)->pow(28) - b[i+1]) ; var ans : int := 0 ; for loop : Integer.subrange(-1 + 1, 28)->reverse() do ( var j : double := (2)->pow(loop) ; var k : int := (MathLib.bitwiseAnd(xor, j)) div j ; var temp : OclAny := br(b, j - 1) ; for i : Integer.subrange(temp, n-1) do ( b[i+1] := b[i+1] - j) ; b := b->sort() ; temp := br(a, j - 1) ; for i : a.subrange(1,temp) do ( k := k + (MathLib.bitwiseAnd(i, j)) div j) ; for i : Integer.subrange(temp, n-1) do ( k := k + (MathLib.bitwiseAnd(a[i+1], j)) div j ; a[i+1] := a[i+1] - j) ; var x : int := (k + br(b, 0)) * m mod 2 ; a := a->sort() ; var l : int := 0 ; for i : a do ( while (l->compareTo(n)) < 0 do ( if (i->compareTo(b[l+1])) >= 0 then ( l := l + 1 ) else ( break )) ; x := x + l mod 2) ; ans := ans + (x mod 2) * j) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) n_counter=0 result=[] for i in range(0,t): n_counter=0 n,x=(int(x)for x in input().split()) arr=[int(x)for x in input().split()] for j in range(0,n): if arr[j]% 2==1 : n_counter+=1 if n_counter==0 or(n_counter % 2==0 and n==x)or(n_counter==n and x % 2==0): print('No') else : print('Yes') for i in result : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n_counter : int := 0 ; var result : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( n_counter := 0 ; var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var arr : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for j : Integer.subrange(0, n-1) do ( if arr[j+1] mod 2 = 1 then ( n_counter := n_counter + 1 ) else skip) ; if n_counter = 0 or (n_counter mod 2 = 0 & n = x) or (n_counter = n & x mod 2 = 0) then ( execute ('No')->display() ) else ( execute ('Yes')->display() )) ; for i : result do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math T=int(input()) for _ in range(T): temp=input().split(); n,x=[int(z)for z in temp] arr=input().split(); arr=[int(z)% 2 for z in arr] if x==n : if sum(arr)% 2==0 : print('NO') else : print('YES') elif x==0 : print('NO') else : if 0 in arr and 1 in arr : print('YES') if 1 not in arr : print('NO') if 0 not in arr and x % 2==0 : print('NO') elif 0 not in arr and x % 2!=0 : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, T-1) do ( var temp : OclAny := input().split(); var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := temp->select(z | true)->collect(z | (("" + ((z)))->toInteger())) ; var arr : OclAny := input().split(); arr := arr->select(z | true)->collect(z | (("" + ((z)))->toInteger() mod 2)) ; if x = n then ( if (arr)->sum() mod 2 = 0 then ( execute ('NO')->display() ) else ( execute ('YES')->display() ) ) else (if x = 0 then ( execute ('NO')->display() ) else ( if (arr)->includes(0) & (arr)->includes(1) then ( execute ('YES')->display() ) else skip ; if (arr)->excludes(1) then ( execute ('NO')->display() ) else skip ; if (arr)->excludes(0) & x mod 2 = 0 then ( execute ('NO')->display() ) else (if (arr)->excludes(0) & x mod 2 /= 0 then ( execute ('YES')->display() ) else skip) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def odd(n,x,l): if(n==x): if sum(l)% 2==1 : return "YES" else : return "NO" e=0 odd=0 for i in l : if i % 2==0 : e+=1 else : odd+=1 if odd==0 : return "NO" for i in range(1,odd+1,2): if i>x : break elif(x-i)<=e : return "YES" return "NO" for _ in range(int(input())): n,x=tuple(map(int,input().split())) l=list(map(int,input().split())) print(odd(n,x,l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( Sequence{n,x} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (odd(n, x, l))->display()); operation odd(n : OclAny, x : OclAny, l : OclAny) : OclAny pre: true post: true activity: if (n = x) then ( if (l)->sum() mod 2 = 1 then ( return "YES" ) else ( return "NO" ) ) else skip ; var e : int := 0 ; var odd : int := 0 ; for i : l do ( if i mod 2 = 0 then ( e := e + 1 ) else ( odd := odd + 1 )) ; if odd = 0 then ( return "NO" ) else skip ; for i : Integer.subrange(1, odd + 1-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( if (i->compareTo(x)) > 0 then ( break ) else (if ((x - i)->compareTo(e)) <= 0 then ( return "YES" ) else skip)) ; return "NO"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n,x=map(int,input().split()) a=[x % 2 for x in map(int,input().split())] p=a.count(1); q=a.count(0) if x % 2==0 : p-=1 ; q-=1 ; x-=2 else : p-=1 ; x-=1 if p<0 or q<0 : print('NO') else : if p//2+q//2>=x//2 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->select(x | true)->collect(x | (x mod 2)) ; var p : int := a->count(1); var q : int := a->count(0) ; if x mod 2 = 0 then ( p := p - 1; q := q - 1; x := x - 2 ) else ( p := p - 1; x := x - 1 ) ; if p < 0 or q < 0 then ( execute ('NO')->display() ) else ( if (p div 2 + q div 2->compareTo(x div 2)) >= 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(odd,even,x): if odd+even0 if __name__=='__main__' : t=int(input()) for i in range(t): n,x=[int(x)for x in input().split()] a=[int(x)for x in input().split()] d={0 : 0,1 : 0} for e in a : d[e % 2]+=1 ok=False if d[1]% 2==1 : ok=f(d[1],d[0],x) else : ok=d[1]>0 and f(d[1]-1,d[0],x) print('Yes' if ok else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; Sequence{n,x} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var d : Map := Map{ 0 |-> 0 }->union(Map{ 1 |-> 0 }) ; for e : a do ( d[e mod 2+1] := d[e mod 2+1] + 1) ; var ok : boolean := false ; if d[1+1] mod 2 = 1 then ( ok := f(d[1+1], d->first(), x) ) else ( ok := d[1+1] > 0 & f(d[1+1] - 1, d->first(), x) ) ; execute (if ok then 'Yes' else 'No' endif)->display()) ) else skip; operation f(odd : OclAny, even : OclAny, x : OclAny) : OclAny pre: true post: true activity: if (odd + even->compareTo(x)) < 0 then ( return false ) else skip ; if odd + even = x then ( return true ) else skip ; if (odd->compareTo(x)) <= 0 then ( return true ) else skip ; if x mod 2 = 1 then ( return true ) else skip ; return even > 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") def next_trip(L,cashflow): saved=0 month=0 for m,n in cashflow : month+=1 saved+=(m-n) if saved>=L : return month return "NA" while True : L=int(input()) if L==0 : break cashflow=[[int(_)for _ in input().split()]for __ in range(12)] print(next_trip(L,cashflow)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; skip ; while true do ( L := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if L = 0 then ( break ) else skip ; cashflow := Integer.subrange(0, 12-1)->select(__ | true)->collect(__ | (input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())))) ; execute (next_trip(L, cashflow))->display()); operation next_trip(L : OclAny, cashflow : OclAny) : OclAny pre: true post: true activity: var saved : int := 0 ; var month : int := 0 ; for _tuple : cashflow do (var _indx : int := 1; var m : OclAny := _tuple->at(_indx); _indx := _indx + 1; var n : OclAny := _tuple->at(_indx); month := month + 1 ; saved := saved + (m - n) ; if (saved->compareTo(L)) >= 0 then ( return month ) else skip) ; return "NA"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cal_speed(dist,time): print(" Distance(km):",dist); print(" Time(hr):",time); return dist/time ; def cal_dis(speed,time): print(" Time(hr):",time); print(" Speed(km/hr):",speed); return speed*time ; def cal_time(dist,speed): print(" Distance(km):",dist); print(" Speed(km/hr):",speed); return speed*dist ; print(" The calculated Speed(km/hr)is :",cal_speed(45.9,2.0)); print(""); print(" The calculated Distance(km):",cal_dis(62.9,2.5)); print(""); print(" The calculated Time(hr):",cal_time(48.0,4.5)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; execute (" The calculated Speed(km/hr)is :")->display(); ; execute ("")->display(); ; execute (" The calculated Distance(km):")->display(); ; execute ("")->display(); ; execute (" The calculated Time(hr):")->display();; operation cal_speed(dist : OclAny, time : OclAny) pre: true post: true activity: execute (" Distance(km):")->display(); ; execute (" Time(hr):")->display(); ; return dist / time;; operation cal_dis(speed : OclAny, time : OclAny) pre: true post: true activity: execute (" Time(hr):")->display(); ; execute (" Speed(km/hr):")->display(); ; return speed * time;; operation cal_time(dist : OclAny, speed : OclAny) pre: true post: true activity: execute (" Distance(km):")->display(); ; execute (" Speed(km/hr):")->display(); ; return speed * dist;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* def trapezoidarea(r): if r<0 : return-1 a=(3*sqrt(3)*pow(r,2))/4 return a if __name__=="__main__" : r=5 print(round(trapezoidarea(r),3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( r := 5 ; execute (MathLib.roundN(trapezoidarea(r), 3))->display() ) else skip; operation trapezoidarea(r : OclAny) : OclAny pre: true post: true activity: if r < 0 then ( return -1 ) else skip ; var a : double := (3 * sqrt(3) * (r)->pow(2)) / 4 ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import fabs t=int(input()) for i in range(t): n=int(input()) line1=input().split(" ") line2=input().split(" ") intline=[int(x)for x in line1] intline2=[int(x)for x in line2] x0=intline[0] s0=intline2[0] for j in range(1,len(intline)): x1=intline[j] s1=intline2[j] if x0>x1 : x0,x1=x1,x0 s0,s1=s1,s0 if(x1-x0)<=fabs(s1-s0): if s1>s0 : x0=x1 s0=s1 else : pass else : x0=(x1+x0+(s1-s0))/2 s0=s1+(x1-x0) if x0 % 1==0.0 : print(int(x0)) else : print(x0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var line1 : OclAny := input().split(" ") ; var line2 : OclAny := input().split(" ") ; var intline : Sequence := line1->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var intline2 : Sequence := line2->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var x0 : OclAny := intline->first() ; var s0 : OclAny := intline2->first() ; for j : Integer.subrange(1, (intline)->size()-1) do ( var x1 : OclAny := intline[j+1] ; var s1 : OclAny := intline2[j+1] ; if (x0->compareTo(x1)) > 0 then ( Sequence{x0,x1} := Sequence{x1,x0} ; Sequence{s0,s1} := Sequence{s1,s0} ) else skip ; if ((x1 - x0)->compareTo(fabs(s1 - s0))) <= 0 then ( if (s1->compareTo(s0)) > 0 then ( x0 := x1 ; s0 := s1 ) else ( skip ) ) else ( x0 := (x1 + x0 + (s1 - s0)) / 2 ; s0 := s1 + (x1 - x0) )) ; if x0 mod 1 = 0.0 then ( execute (("" + ((x0)))->toInteger())->display() ) else ( execute (x0)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) x=list(map(int,input().split())) t=list(map(int,input().split())) mi=x[0]-t[0] ma=t[0]+x[0] for i in range(1,n): l=x[i]-t[i] h=x[i]+t[i] if lma : ma=h print((mi+ma)/2.0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mi : double := x->first() - t->first() ; var ma : OclAny := t->first() + x->first() ; for i : Integer.subrange(1, n-1) do ( var l : double := x[i+1] - t[i+1] ; var h : OclAny := x[i+1] + t[i+1] ; if (l->compareTo(mi)) < 0 then ( mi := l ) else skip ; if (h->compareTo(ma)) > 0 then ( ma := h ) else skip) ; execute ((mi + ma) / 2.0)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def meeting(arr1,arr2): k=0 index=arr1[0] for i in range(len(arr2)): if(arr2[i]>k): k=arr2[i] index=arr1[i] pos=index left_side=0 ; right_side=0 for i in range(len(arr1)): if(arr1[i]pos): temp2=arr1[i]-pos+arr2[i] right_side=max(right_side,temp2) if(left_side>=k and right_side>=k): opt_pos=index+(right_side-left_side)/2 elif(left_side<=k and right_side<=k): opt_pos=index elif(left_side<=k and right_side>=k): opt_pos=index+(right_side-k)/2 else : opt_pos=index-(left_side-k)/2 if(opt_pos<0): return 0 else : return opt_pos k=int(input()) for i in range(k): n=int(input()) arr1=input().split() arr1=[int(l)for l in arr1] arr2=input().split() arr2=[int(l)for l in arr2] print(meeting(arr1,arr2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; k := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, k-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; arr1 := input().split() ; arr1 := arr1->select(l | true)->collect(l | (("" + ((l)))->toInteger())) ; arr2 := input().split() ; arr2 := arr2->select(l | true)->collect(l | (("" + ((l)))->toInteger())) ; execute (meeting(arr1, arr2))->display()); operation meeting(arr1 : OclAny, arr2 : OclAny) : OclAny pre: true post: true activity: var k : int := 0 ; var index : OclAny := arr1->first() ; for i : Integer.subrange(0, (arr2)->size()-1) do ( if ((arr2[i+1]->compareTo(k)) > 0) then ( k := arr2[i+1] ; index := arr1[i+1] ) else skip) ; var pos : OclAny := index ; var left_side : int := 0; var right_side : int := 0 ; for i : Integer.subrange(0, (arr1)->size()-1) do ( if ((arr1[i+1]->compareTo(pos)) < 0) then ( var temp1 : double := pos - arr1[i+1] + arr2[i+1] ; left_side := Set{left_side, temp1}->max() ) else (if ((arr1[i+1]->compareTo(pos)) > 0) then ( var temp2 : double := arr1[i+1] - pos + arr2[i+1] ; right_side := Set{right_side, temp2}->max() ) else skip)) ; if ((left_side->compareTo(k)) >= 0 & (right_side->compareTo(k)) >= 0) then ( var opt_pos : OclAny := index + (right_side - left_side) / 2 ) else (if ((left_side->compareTo(k)) <= 0 & (right_side->compareTo(k)) <= 0) then ( opt_pos := index ) else (if ((left_side->compareTo(k)) <= 0 & (right_side->compareTo(k)) >= 0) then ( opt_pos := index + (right_side - k) / 2 ) else ( opt_pos := index - (left_side - k) / 2 ) ) ) ; if (opt_pos < 0) then ( return 0 ) else ( return opt_pos ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100000 def findSumofEle(arr1,m,arr2,n): hash=[0 for i in range(MAX)] for i in range(n): hash[arr2[i]]+=1 for i in range(1,MAX,1): hash[i]=hash[i]+hash[i-1] maximumFreq=0 for i in range(m): maximumFreq=max(maximumFreq,hash[arr1[i]]) sumOfElements=0 for i in range(m): if(maximumFreq==hash[arr1[i]]): sumOfElements+=arr1[i] return sumOfElements if __name__=='__main__' : arr1=[2,5,6,8] arr2=[4,10] m=len(arr1) n=len(arr2) print(findSumofEle(arr1,m,arr2,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 100000 ; skip ; if __name__ = '__main__' then ( arr1 := Sequence{2}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 8 }))) ; arr2 := Sequence{4}->union(Sequence{ 10 }) ; m := (arr1)->size() ; n := (arr2)->size() ; execute (findSumofEle(arr1, m, arr2, n))->display() ) else skip; operation findSumofEle(arr1 : OclAny, m : OclAny, arr2 : OclAny, n : OclAny) : OclAny pre: true post: true activity: var hash : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( hash[arr2[i+1]+1] := hash[arr2[i+1]+1] + 1) ; for i : Integer.subrange(1, MAX-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( hash[i+1] := hash[i+1] + hash[i - 1+1]) ; var maximumFreq : int := 0 ; for i : Integer.subrange(0, m-1) do ( maximumFreq := Set{maximumFreq, hash[arr1[i+1]+1]}->max()) ; var sumOfElements : int := 0 ; for i : Integer.subrange(0, m-1) do ( if (maximumFreq = hash[arr1[i+1]+1]) then ( sumOfElements := sumOfElements + arr1[i+1] ) else skip) ; return sumOfElements; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) x=list(map(int,input().split())) t=list(map(int,input().split())) l=[] for e in range(n): l.append(x[e]+t[e]) l.append(x[e]-t[e]) print((max(l)+min(l))/2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : Sequence := Sequence{} ; for e : Integer.subrange(0, n-1) do ( execute ((x[e+1] + t[e+1]) : l) ; execute ((x[e+1] - t[e+1]) : l)) ; execute (((l)->max() + (l)->min()) / 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): for i in range(int(input())): test() def test(): n=int(input()) x=list(map(int,input().split(" "))) t=list(map(int,input().split(" "))) mi=x[0]-t[0] ma=x[0]+t[0] for i in range(1,n): mi=min(x[i]-t[i],mi) ma=max(x[i]+t[i],ma) print((mi+ma)/2) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( test()); operation test() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var t : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var mi : double := x->first() - t->first() ; var ma : OclAny := x->first() + t->first() ; for i : Integer.subrange(1, n-1) do ( mi := Set{x[i+1] - t[i+1], mi}->min() ; ma := Set{x[i+1] + t[i+1], ma}->max()) ; execute ((mi + ma) / 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def binomialCoeff(n,k): res=1 if(k>n-k): k=n-k for i in range(0,k): res=res*(n-i) res=res//(i+1) return res def power(x,y): res=1 while(y>0): if(y & 1): res=res*x y=y//2 x=x*x return res def FindProbability(n): up=binomialCoeff(2*n,n) down=power(2,2*n) g=math.gcd(up,down) up=up//g down=down//g print(up,"/",down) N=8 FindProbability(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var N : int := 8 ; FindProbability(N); operation binomialCoeff(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; if ((k->compareTo(n - k)) > 0) then ( k := n - k ) else skip ; for i : Integer.subrange(0, k-1) do ( res := res * (n - i) ; res := res div (i + 1)) ; return res; operation power(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: res := 1 ; while (y > 0) do ( if (MathLib.bitwiseAnd(y, 1)) then ( res := res * x ) else skip ; y := y div 2 ; x := x * x) ; return res; operation FindProbability(n : OclAny) pre: true post: true activity: var up : OclAny := binomialCoeff(2 * n, n) ; var down : OclAny := power(2, 2 * n) ; var g : long := (up)->gcd(down) ; up := up div g ; down := down div g ; execute (up)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def new_color(s,i,color): return s[: i-1]+color*2+s[i+1 :] def solve(s): length=len(s) monos=["r"*length,"g"*length,"b"*length] if s in monos : print(0) return another={("r","g"): "b",("g","r"): "b",("r","b"): "g",("b","r"): "g",("g","b"): "r",("b","g"): "r"} visited={s : True} que=deque() app=que.append pop=que.popleft que.append((s,0)) while que : colors,score=pop() score+=1 temp=colors[0] for i in range(1,length): ci=colors[i] if ci!=temp : new=new_color(colors,i,another[(ci,temp)]) if new in monos : print(score) return if new not in visited : visited[new]=True app((new,score)) temp=ci print("NA") def main(): while True : s=input() if s=="0" : break solve(s) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; main(); operation new_color(s : OclAny, i : OclAny, color : OclAny) : OclAny pre: true post: true activity: return s.subrange(1,i - 1) + color * 2 + s.subrange(i + 1+1); operation solve(s : OclAny) pre: true post: true activity: var length : int := (s)->size() ; var monos : Sequence := Sequence{StringLib.nCopies("r", length)}->union(Sequence{StringLib.nCopies("g", length)}->union(Sequence{ StringLib.nCopies("b", length) })) ; if (monos)->includes(s) then ( execute (0)->display() ; return ) else skip ; var another : Map := Map{ Sequence{"r", "g"} |-> "b" }->union(Map{ Sequence{"g", "r"} |-> "b" }->union(Map{ Sequence{"r", "b"} |-> "g" }->union(Map{ Sequence{"b", "r"} |-> "g" }->union(Map{ Sequence{"g", "b"} |-> "r" }->union(Map{ Sequence{"b", "g"} |-> "r" }))))) ; var visited : Map := Map{ s |-> true } ; var que : Sequence := () ; var app : OclAny := que.append ; var pop : OclAny := que.popleft ; execute ((Sequence{s, 0}) : que) ; while que do ( var colors : OclAny := null; var score : OclAny := null; Sequence{colors,score} := pop() ; score := score + 1 ; var temp : OclAny := colors->first() ; for i : Integer.subrange(1, length-1) do ( var ci : OclAny := colors[i+1] ; if ci /= temp then ( var new : OclAny := new_color(colors, i, another[Sequence{ci, temp}+1]) ; if (monos)->includes(new) then ( execute (score)->display() ; return ) else skip ; if (visited)->excludes(new) then ( visited[new+1] := true ; app(Sequence{new, score}) ) else skip ) else skip ; temp := ci)) ; execute ("NA")->display(); operation main() pre: true post: true activity: while true do ( s := (OclFile["System.in"]).readLine() ; if s = "0" then ( break ) else skip ; solve(s)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def main(args): while True : L=int(input()) if L==0 : break ans='NA' for i in range(1,12+1): if ans=='NA' : M,N=map(int,input().split()) L-=(M-N) if L<=0 : ans=i else : _=input() print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation main(args : OclAny) pre: true post: true activity: while true do ( var L : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if L = 0 then ( break ) else skip ; var ans : String := 'NA' ; for i : Integer.subrange(1, 12 + 1-1) do ( if ans = 'NA' then ( var M : OclAny := null; var N : OclAny := null; Sequence{M,N} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; L := L - (M - N) ; if L <= 0 then ( ans := i ) else skip ) else ( var _anon : String := (OclFile["System.in"]).readLine() )) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): while True : worm=input() if worm=='0' : break q=[worm] m={('r','g'): 'bb',('g','r'): 'bb',('r','b'): 'gg',('b','r'): 'gg',('g','b'): 'rr',('b','g'): 'rr'} d={worm : True} ans=0 while q : nq=[] for w in q : flag=True for i,t in enumerate(zip(w,w[1 :])): s1,s2=t if s1!=s2 : flag=False nw=w[: i]+m[t]+w[i+2 :] if nw not in d : d[nw]=True nq.append(nw) if flag : print(ans) break else : q=nq[:] ans+=1 continue break else : print('NA') solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: while true do ( var worm : String := (OclFile["System.in"]).readLine() ; if worm = '0' then ( break ) else skip ; var q : Sequence := Sequence{ worm } ; var m : Map := Map{ Sequence{'r', 'g'} |-> 'bb' }->union(Map{ Sequence{'g', 'r'} |-> 'bb' }->union(Map{ Sequence{'r', 'b'} |-> 'gg' }->union(Map{ Sequence{'b', 'r'} |-> 'gg' }->union(Map{ Sequence{'g', 'b'} |-> 'rr' }->union(Map{ Sequence{'b', 'g'} |-> 'rr' }))))) ; var d : Map := Map{ worm |-> true } ; var ans : int := 0 ; (compound_stmt while (test (logical_test (comparison (expr (atom (name q)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name nq)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom [ ]))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name w)))) in (testlist (test (logical_test (comparison (expr (atom (name q))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name flag)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name True)))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name i))) , (expr (atom (name t)))) in (testlist (test (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name w))))))) , (argument (test (logical_test (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))))))) ))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name s1)))))) , (test (logical_test (comparison (expr (atom (name s2))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name t)))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name s1)))) != (comparison (expr (atom (name s2))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name flag)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name False)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name nw)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name m)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])))) + (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 2)))))))) :)) ]))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name nw)))) not in (comparison (expr (atom (name d))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name nw)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name True)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name nq)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name nw)))))))) ))))))))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name flag)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name q)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name nq)) (trailer (arguments [ (subscriptlist (subscript :)) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt continue))))))) (stmt (simple_stmt (small_stmt break)))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NA'))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def change(x,y): if[x,y]==["r","g"]or[y,x]==["r","g"]: return "b" elif[x,y]==["g","b"]or[y,x]==["g","b"]: return "r" elif[x,y]==["r","b"]or[y,x]==["r","b"]: return "g" rgb=['r','g','b'] while True : time=0 W_dic={} W_que=deque([]) worm=tuple(str(input())) if worm==('0',): break else : W_que.append([time,worm]) W_dic[worm]=time while True : now_list=W_que.popleft() now_time=now_list[0] now_worm=now_list[1] if now_worm.count('r')==len(now_worm)or now_worm.count('g')==len(now_worm)or now_worm.count('b')==len(now_worm): print(now_time) break a_0=now_worm[0] for i in range(1,len(now_worm)): a_1=now_worm[i] rgb_c=rgb worm_c=list(now_worm) if a_0!=a_1 : coll=change(a_0,a_1) worm_c[i-1]=coll worm_c[i]=coll if not tuple(worm_c)in W_dic : W_dic[tuple(worm_c)]=now_time+1 W_que.append([now_time+1,worm_c]) a_0=a_1 if len(W_que)==0 : print("NA") break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var rgb : Sequence := Sequence{'r'}->union(Sequence{'g'}->union(Sequence{ 'b' })) ; while true do ( var time : int := 0 ; var W_dic : OclAny := Set{} ; var W_que : Sequence := (Sequence{}) ; var worm : Sequence := (("" + (((OclFile["System.in"]).readLine())))) ; if worm = Sequence{(testlist_comp (test (logical_test (comparison (expr (atom '0'))))) ,)} then ( break ) else ( execute ((Sequence{time}->union(Sequence{ worm })) : W_que) ; W_dic->restrict(worm) := time ) ; while true do ( var now_list : OclAny := W_que->first() ; W_que := W_que->tail() ; var now_time : OclAny := now_list->first() ; var now_worm : OclAny := now_list[1+1] ; if now_worm->count('r') = (now_worm)->size() or now_worm->count('g') = (now_worm)->size() or now_worm->count('b') = (now_worm)->size() then ( execute (now_time)->display() ; break ) else skip ; var a_0 : OclAny := now_worm->first() ; for i : Integer.subrange(1, (now_worm)->size()-1) do ( var a var now_list : OclAny := W_que->first() ; W_que := W_que->tail() : OclAny := now_worm[i+1] ; var rgb_c : Sequence := rgb ; var worm_c : Sequence := (now_worm) ; if a_0 /= a var a var now_list : OclAny := W_que->first() ; W_que := W_que->tail() : OclAny := now_worm[i+1] then ( var coll : OclAny := change(a_0, aa_0) ; worm_c[i - 1+1] := coll ; worm_c[i+1] := coll ; if not((W_dic)->includes((worm_c))) then ( W_dic->restrict((worm_c)) := now_time + 1 ; execute ((Sequence{now_time + 1}->union(Sequence{ worm_c })) : W_que) ) else skip ) else skip ; a_0 := a var a var now_list : OclAny := W_que->first() ; W_que := W_que->tail() : OclAny := now_worm[i+1]) ; if (W_que)->size() = 0 then ( execute ("NA")->display() ; break ) else skip)); operation change(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if Sequence{x}->union(Sequence{ y }) = Sequence{"r"}->union(Sequence{ "g" }) or Sequence{y}->union(Sequence{ x }) = Sequence{"r"}->union(Sequence{ "g" }) then ( return "b" ) else (if Sequence{x}->union(Sequence{ y }) = Sequence{"g"}->union(Sequence{ "b" }) or Sequence{y}->union(Sequence{ x }) = Sequence{"g"}->union(Sequence{ "b" }) then ( return "r" ) else (if Sequence{x}->union(Sequence{ y }) = Sequence{"r"}->union(Sequence{ "b" }) or Sequence{y}->union(Sequence{ x }) = Sequence{"r"}->union(Sequence{ "b" }) then ( return "g" ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def new_color(s,i,rgb): for color in rgb : if color!=s[i]and color!=s[i+1]: break return s[: i]+color*2+s[i+2 :] def solve(s): length=len(s) monos=["r"*length,"g"*length,"b"*length] if s in monos : print(0) return dic={s : 0} rgb="rgb" que=deque() app=que.append pop=que.popleft que.append((s,0)) while que : colors,score=pop() score+=1 temp=colors[0] for i in range(1,length): ci=colors[i] if ci!=temp : new=new_color(colors,i-1,rgb) if new in monos : print(score) return if new not in dic : dic[new]=score app((new,score)) temp=ci print("NA") def main(): while True : s=input() if s=="0" : break solve(s) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; main(); operation new_color(s : OclAny, i : OclAny, rgb : OclAny) : OclAny pre: true post: true activity: for color : rgb do ( if color /= s[i+1] & color /= s[i + 1+1] then ( break ) else skip) ; return s.subrange(1,i) + color * 2 + s.subrange(i + 2+1); operation solve(s : OclAny) pre: true post: true activity: var length : int := (s)->size() ; var monos : Sequence := Sequence{StringLib.nCopies("r", length)}->union(Sequence{StringLib.nCopies("g", length)}->union(Sequence{ StringLib.nCopies("b", length) })) ; if (monos)->includes(s) then ( execute (0)->display() ; return ) else skip ; var dic : Map := Map{ s |-> 0 } ; rgb := "rgb" ; var que : Sequence := () ; var app : OclAny := que.append ; var pop : OclAny := que.popleft ; execute ((Sequence{s, 0}) : que) ; while que do ( var colors : OclAny := null; var score : OclAny := null; Sequence{colors,score} := pop() ; score := score + 1 ; var temp : OclAny := colors->first() ; for i : Integer.subrange(1, length-1) do ( var ci : OclAny := colors[i+1] ; if ci /= temp then ( var new : OclAny := new_color(colors, i - 1, rgb) ; if (monos)->includes(new) then ( execute (score)->display() ; return ) else skip ; if (dic)->excludes(new) then ( dic[new+1] := score ; app(Sequence{new, score}) ) else skip ) else skip ; temp := ci)) ; execute ("NA")->display(); operation main() pre: true post: true activity: while true do ( s := (OclFile["System.in"]).readLine() ; if s = "0" then ( break ) else skip ; solve(s)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def change(s,n): c=['r','g','b'] a,b=s[n],s[n+1] if a==b : return s s=list(s) c.remove(a) c.remove(b) s[n],s[n+1]=c[0],c[0] return ''.join(s) while True : s=raw_input() if s=='0' : break q=[(s,0)] mem=[] while len(q)>0 : v,n=q.pop(0) if v in mem : continue if v.count(v[0])==len(v): print(n) break mem.append(v) for i in range(len(v)-1): vv=change(v,i) if vv!=v : q.append((vv,n+1)) else : print('NA') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( s := raw_input() ; if s = '0' then ( break ) else skip ; var q : Sequence := Sequence{ Sequence{s, 0} } ; var mem : Sequence := Sequence{} ; (compound_stmt while (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name q)))))))) ))))) > (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name v)))))) , (test (logical_test (comparison (expr (atom (name n))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name q)) (trailer . (name pop) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name v)))) in (comparison (expr (atom (name mem))))))) : (suite (stmt (simple_stmt (small_stmt continue)))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name v)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))) == (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name mem)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) - (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name vv)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name change)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v))))))) , (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name vv)))) != (comparison (expr (atom (name v))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name q)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name vv)))))) , (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1))))))))) )))))))) ))))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NA'))))))) )))))))))))))))); operation change(s : OclAny, n : OclAny) : OclAny pre: true post: true activity: var c : Sequence := Sequence{'r'}->union(Sequence{'g'}->union(Sequence{ 'b' })) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{s[n+1],s[n + 1+1]} ; if a = b then ( return s ) else skip ; s := (s) ; execute ((a) /: c) ; execute ((b) /: c) ; var s[n+1] : OclAny := null; var s[n + 1+1] : OclAny := null; Sequence{s[n+1],s[n + 1+1]} := Sequence{c->first(),c->first()} ; return StringLib.sumStringsWithSeparator((s), ''); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): if input()=='1' : input() print(1) else : a=sorted(list(map(int,input().split(' ')))) d=100 for i in range(1,len(a)): d=min(a[i]-a[i-1],d) print(1)if d>1 else print(2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( if (OclFile["System.in"]).readLine() = '1' then ( input() ; execute (1)->display() ) else ( var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var d : int := 100 ; for i : Integer.subrange(1, (a)->size()-1) do ( d := Set{a[i+1] - a[i - 1+1], d}->min()) ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))) if (logical_test (comparison (comparison (expr (atom (name d)))) > (comparison (expr (atom (number (integer 1))))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))))))) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- totalnumoftasks=int(input()) for i in range(totalnumoftasks): ans=1 t1=int(input()) t2=input() t1list=list(map(int,t2.split())) for j in range(t1): for k in range(j): if abs(t1list[j]-t1list[k])==1 : ans=2 break if ans==2 : break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var totalnumoftasks : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, totalnumoftasks-1) do ( var ans : int := 1 ; var t1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t2 : String := (OclFile["System.in"]).readLine() ; var t1list : Sequence := ((t2.split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, t1-1) do ( for k : Integer.subrange(0, j-1) do ( if (t1list[j+1] - t1list[k+1])->abs() = 1 then ( ans := 2 ; break ) else skip) ; if ans = 2 then ( break ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s,n=input(),input() first=len(s) second=len(n) while first and second and s[first-1]==n[second-1]: first-=1 second-=1 print(first+second) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := null; var n : OclAny := null; Sequence{s,n} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine()} ; var first : int := (s)->size() ; var second : int := (n)->size() ; while first & second & s[first - 1+1] = n[second - 1+1] do ( first := first - 1 ; second := second - 1) ; execute (first + second)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) for i in range(q): n=int(input()) ans=0 l=sorted(list(map(int,input().split()))) for i in range(n-1): if(l[i+1]-l[i]==1): ans+=1 if(ans>0): print(2) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; for i : Integer.subrange(0, n - 1-1) do ( if (l[i + 1+1] - l[i+1] = 1) then ( ans := ans + 1 ) else skip) ; if (ans > 0) then ( execute (2)->display() ) else ( execute (1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input for _ in[0]*int(I()): I(); a={*map(int,I().split())}; print(bool(a &{x+1 for x in a})+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + ((I())))->toInteger()) do ( I(); var a : Set := Set{ (I().split())->collect( _x | (OclType["int"])->apply(_x) ) }; execute ((MathLib.bitwiseAnd(a, a->select(x | true)->collect(x | x + 1)->asSet()))->toBoolean() + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=sorted(map(int,input().split())) print(1+any(a[i+1]-a[i]==1 for i in range(n-1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; execute (1 + ((argument (test (logical_test (comparison (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))) - (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))) == (comparison (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) )))))))))->exists( _x | _x = true ))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : tmp=input().split() if tmp[1]=='?' : break if tmp[1]=='+' : print(int(tmp[0])+int(tmp[2])) if tmp[1]=='-' : print(int(tmp[0])-int(tmp[2])) if tmp[1]=='*' : print(int(tmp[0])*int(tmp[2])) if tmp[1]=='/' : print(int(tmp[0])//int(tmp[2])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var tmp : OclAny := input().split() ; if tmp[1+1] = '?' then ( break ) else skip ; if tmp[1+1] = '+' then ( execute (("" + ((tmp->first())))->toInteger() + ("" + ((tmp[2+1])))->toInteger())->display() ) else skip ; if tmp[1+1] = '-' then ( execute (("" + ((tmp->first())))->toInteger() - ("" + ((tmp[2+1])))->toInteger())->display() ) else skip ; if tmp[1+1] = '*' then ( execute (("" + ((tmp->first())))->toInteger() * ("" + ((tmp[2+1])))->toInteger())->display() ) else skip ; if tmp[1+1] = '/' then ( execute (("" + ((tmp->first())))->toInteger() div ("" + ((tmp[2+1])))->toInteger())->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSubsequence(arr,n): Len=1 tmp=0 i,j,d=0,0,0 dp=[[0 for i in range(10)]for i in range(n)] cnt=[0 for i in range(10)] locMax=0 tmp=arr[0] while(tmp>0): dp[0][tmp % 10]=1 tmp//=10 for i in range(1,n): tmp=arr[i] locMax=1 cnt=[0 for i in range(10)] while(tmp>0): cnt[tmp % 10]=1 tmp//=10 for d in range(10): if(cnt[d]): dp[i][d]=1 for j in range(i): dp[i][d]=max(dp[i][d],dp[j][d]+1) locMax=max(dp[i][d],locMax) for d in range(10): if(cnt[d]): dp[i][d]=locMax Len=max(Len,locMax) return Len arr=[1,12,44,29,33,96,89] n=len(arr) print(findSubsequence(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{12}->union(Sequence{44}->union(Sequence{29}->union(Sequence{33}->union(Sequence{96}->union(Sequence{ 89 })))))) ; n := (arr)->size() ; execute (findSubsequence(arr, n))->display(); operation findSubsequence(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var Len : int := 1 ; var tmp : int := 0 ; var i : OclAny := null; var j : OclAny := null; var d : OclAny := null; Sequence{i,j,d} := Sequence{0,0,0} ; var dp : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, 10-1)->select(i | true)->collect(i | (0)))) ; var cnt : Sequence := Integer.subrange(0, 10-1)->select(i | true)->collect(i | (0)) ; var locMax : int := 0 ; tmp := arr->first() ; while (tmp > 0) do ( dp->first()[tmp mod 10+1] := 1 ; tmp := tmp div 10) ; for i : Integer.subrange(1, n-1) do ( tmp := arr[i+1] ; locMax := 1 ; cnt := Integer.subrange(0, 10-1)->select(i | true)->collect(i | (0)) ; while (tmp > 0) do ( cnt[tmp mod 10+1] := 1 ; tmp := tmp div 10) ; for d : Integer.subrange(0, 10-1) do ( if (cnt[d+1]) then ( dp[i+1][d+1] := 1 ; for j : Integer.subrange(0, i-1) do ( dp[i+1][d+1] := Set{dp[i+1][d+1], dp[j+1][d+1] + 1}->max() ; locMax := Set{dp[i+1][d+1], locMax}->max()) ) else skip) ; for d : Integer.subrange(0, 10-1) do ( if (cnt[d+1]) then ( dp[i+1][d+1] := locMax ) else skip) ; Len := Set{Len, locMax}->max()) ; return Len; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input().split() a,b=int(x[0]),int(x[1]) y=[] for i in range(a): y.append(input().split()) result=0 if any(e=='1' for e in y[0]): result=2 elif any(e=='1' for e in y[-1]): result=2 else : for i in range(a): if y[i][0]=='1' : result=2 elif y[i][-1]=='1' : result=2 if result==0 : print('4') else : print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := input().split() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{("" + ((x->first())))->toInteger(),("" + ((x[1+1])))->toInteger()} ; var y : Sequence := Sequence{} ; for i : Integer.subrange(0, a-1) do ( execute ((input().split()) : y)) ; var result : int := 0 ; if ((argument (test (logical_test (comparison (comparison (expr (atom (name e)))) == (comparison (expr (atom '1')))))) (comp_for for (exprlist (expr (atom (name e)))) in (logical_test (comparison (expr (atom (name y)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))))->exists( _x | _x = true ) then ( result := 2 ) else (if ((argument (test (logical_test (comparison (comparison (expr (atom (name e)))) == (comparison (expr (atom '1')))))) (comp_for for (exprlist (expr (atom (name e)))) in (logical_test (comparison (expr (atom (name y)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))))))))->exists( _x | _x = true ) then ( result := 2 ) else ( for i : Integer.subrange(0, a-1) do ( if y[i+1]->first() = '1' then ( result := 2 ) else (if y[i+1]->last() = '1' then ( result := 2 ) else skip)) ) ) ; if result = 0 then ( execute ('4')->display() ) else ( execute (result)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=[input().split()for _ in[0]*n] b=[*zip(*a)] print([4,2]['1' in ''.join([*a[0],*a[n-1],*b[0],*b[m-1]])]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n)->select(_anon | true)->collect(_anon | (input().split())) ; var b : Sequence := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name a)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name a)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name a)))))))`third->at(_indx)} ) ; execute (Sequence{4}->union(Sequence{ 2 })->select((StringLib.sumStringsWithSeparator((a->first()->union(a[n - 1+1]->union(b->first()->union(b[m - 1+1])))), ''))->includes('1')))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) n,m=map(int,input().split()) a=[input().split()for i in range(n)] b=[*zip(*a)] print([4,2]['1' in ''.join([*a[0],*a[n-1],*b[0],*b[m-1]])]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (input().split())) ; var b : Sequence := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name a)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name a)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name a)))))))`third->at(_indx)} ) ; execute (Sequence{4}->union(Sequence{ 2 })->select((StringLib.sumStringsWithSeparator((a->first()->union(a[n - 1+1]->union(b->first()->union(b[m - 1+1])))), ''))->includes('1')))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d=input().split() n,m=int(d[0]),int(d[1]) t=[] for i in range(n): t.append(input().split()) r=0 if any(e=='1' for e in t[0]): r=2 elif any(e=='1' for e in t[-1]): r=2 else : for i in range(n): if(t[i][0]=='1'): r=2 elif t[i][-1]=='1' : r=2 if r==0 : print('4') else : print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : OclAny := input().split() ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{("" + ((d->first())))->toInteger(),("" + ((d[1+1])))->toInteger()} ; var t : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((input().split()) : t)) ; var r : int := 0 ; if ((argument (test (logical_test (comparison (comparison (expr (atom (name e)))) == (comparison (expr (atom '1')))))) (comp_for for (exprlist (expr (atom (name e)))) in (logical_test (comparison (expr (atom (name t)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))))->exists( _x | _x = true ) then ( r := 2 ) else (if ((argument (test (logical_test (comparison (comparison (expr (atom (name e)))) == (comparison (expr (atom '1')))))) (comp_for for (exprlist (expr (atom (name e)))) in (logical_test (comparison (expr (atom (name t)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))))))))->exists( _x | _x = true ) then ( r := 2 ) else ( for i : Integer.subrange(0, n-1) do ( if (t[i+1]->first() = '1') then ( r := 2 ) else (if t[i+1]->last() = '1' then ( r := 2 ) else skip)) ) ) ; if r = 0 then ( execute ('4')->display() ) else ( execute (r)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d=input().split() n,m=int(d[0]),int(d[1]) t=[] for i in range(n): t.append(input().split()) r=0 if any(e=='1' for e in t[0]): r=2 elif any(e=='1' for e in t[-1]): r=2 else : for i in range(n): if(t[i][0]=='1'): r=2 elif t[i][-1]=='1' : r=2 if r==0 : print('4') else : print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : OclAny := input().split() ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{("" + ((d->first())))->toInteger(),("" + ((d[1+1])))->toInteger()} ; var t : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((input().split()) : t)) ; var r : int := 0 ; if ((argument (test (logical_test (comparison (comparison (expr (atom (name e)))) == (comparison (expr (atom '1')))))) (comp_for for (exprlist (expr (atom (name e)))) in (logical_test (comparison (expr (atom (name t)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))))->exists( _x | _x = true ) then ( r := 2 ) else (if ((argument (test (logical_test (comparison (comparison (expr (atom (name e)))) == (comparison (expr (atom '1')))))) (comp_for for (exprlist (expr (atom (name e)))) in (logical_test (comparison (expr (atom (name t)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))))))))->exists( _x | _x = true ) then ( r := 2 ) else ( for i : Integer.subrange(0, n-1) do ( if (t[i+1]->first() = '1') then ( r := 2 ) else (if t[i+1]->last() = '1' then ( r := 2 ) else skip)) ) ) ; if r = 0 then ( execute ('4')->display() ) else ( execute (r)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline M=10**9+7 n,k=map(int,input().split()) print(pow(k,k-1,M)*pow(n-k,n-k,M)% M) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var M : double := (10)->pow(9) + 7 ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((k)->pow(k - 1) * (n - k)->pow(n - k) mod M)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() t=input() s=s[: :-1] t=t[: :-1] kol_same=0 for i in range(min(len(s),len(t))): if s[i]==t[i]: kol_same+=2 else : break print(len(s)+len(t)-kol_same) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; s := s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; t := t(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var kol_same : int := 0 ; for i : Integer.subrange(0, Set{(s)->size(), (t)->size()}->min()-1) do ( if s[i+1] = t[i+1] then ( kol_same := kol_same + 2 ) else ( break )) ; execute ((s)->size() + (t)->size() - kol_same)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- nk=input().split() n=int(nk[0]) k=int(nk[1]) p=10**9+7 a=pow(k,k-1,p) b=pow(n-k,n-k,p) print((a*b)% p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var nk : OclAny := input().split() ; var n : int := ("" + ((nk->first())))->toInteger() ; var k : int := ("" + ((nk[1+1])))->toInteger() ; var p : double := (10)->pow(9) + 7 ; var a : double := (k)->pow(k - 1) ; var b : double := (n - k)->pow(n - k) ; execute ((a * b) mod p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,heapq,copy from collections import defaultdict,deque from bisect import bisect_left,bisect_right from functools import cmp_to_key from itertools import permutations,combinations,combinations_with_replacement mod=1000000007 def get_int(): return int(sys.stdin.readline().strip()) def get_str(): return sys.stdin.readline().strip() def get_float(): return float(sys.stdin.readline().strip()) def get_ints(): return map(int,sys.stdin.readline().strip().split()) def get_strs(): return map(str,sys.stdin.readline().strip().split()) def get_floats(): return map(float,sys.stdin.readline().strip().split()) def list_ints(): return list(map(int,sys.stdin.readline().strip().split())) def list_strs(): return list(map(str,sys.stdin.readline().strip().split())) def list_floats(): return list(map(float,sys.stdin.readline().strip().split())) n,k=get_ints() print((pow(k,k-1,mod)*pow(n-k,n-k,mod))% mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var mod : int := 1000000007 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := get_ints() ; execute (((k)->pow(k - 1) * (n - k)->pow(n - k)) mod mod)->display(); operation get_int() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.readLine()->trim())))->toInteger(); operation get_str() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation get_float() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.readLine()->trim())))->toReal(); operation get_ints() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ); operation get_strs() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["String"])->apply(_x) ); operation get_floats() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["double"])->apply(_x) ); operation list_ints() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation list_strs() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["String"])->apply(_x) )); operation list_floats() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["double"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def algorithm(): while True : budget=int(input()) if budget==0 : break total,months=0,0 for _ in range(12): income,outcome=map(int,input().split()) total+=income-outcome if total>=budget and months==0 : months=_+1 print('NA' if totaltoInteger() ; if budget = 0 then ( break ) else skip ; var total : OclAny := null; var months : OclAny := null; Sequence{total,months} := Sequence{0,0} ; for _anon : Integer.subrange(0, 12-1) do ( var income : OclAny := null; var outcome : OclAny := null; Sequence{income,outcome} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; total := total + income - outcome ; if (total->compareTo(budget)) >= 0 & months = 0 then ( var months : OclAny := _anon + 1 ) else skip) ; execute (if (total->compareTo(budget)) < 0 then 'NA' else months endif)->display()); operation main() pre: true post: true activity: algorithm(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=[int(x)for x in input().split()] ans=((n-k)**(n-k))*((k)**(k-1))%(10**9+7) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : int := (((n - k))->pow((n - k))) * (((k))->pow((k - 1))) mod ((10)->pow(9) + 7) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split(' ')) print(k**(k-1)*(n-k)**(n-k)% int(1e9+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((k)->pow((k - 1)) * ((n - k))->pow((n - k)) mod ("" + ((("1e9")->toReal() + 7)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countNums(l,r): cnt=0 ; for i in range(l,r+1): lastDigit=(i % 10); if((lastDigit % 10)==2 or(lastDigit % 10)==3 or(lastDigit % 10)==9): cnt+=1 ; return cnt ; if __name__=="__main__" : l=11 ; r=33 ; print(countNums(l,r)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( l := 11; r := 33; ; execute (countNums(l, r))->display(); ) else skip; operation countNums(l : OclAny, r : OclAny) pre: true post: true activity: var cnt : int := 0; ; for i : Integer.subrange(l, r + 1-1) do ( var lastDigit : int := (i mod 10); ; if ((lastDigit mod 10) = 2 or (lastDigit mod 10) = 3 or (lastDigit mod 10) = 9) then ( cnt := cnt + 1; ) else skip) ; return cnt;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def printNumbers(a,n,x): flag=False for i in range(n): num=a[i] g=gcd(num,x) while(g!=1): num//=g g=gcd(num,x) if(num==1): flag=True ; print(a[i],end=" "); if(not flag): print("There are no such numbers") if __name__=="__main__" : x=60 a=[2,5,10,7,17] n=len(a) printNumbers(a,n,x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( x := 60 ; a := Sequence{2}->union(Sequence{5}->union(Sequence{10}->union(Sequence{7}->union(Sequence{ 17 })))) ; n := (a)->size() ; printNumbers(a, n, x) ) else skip; operation printNumbers(a : OclAny, n : OclAny, x : OclAny) pre: true post: true activity: var flag : boolean := false ; for i : Integer.subrange(0, n-1) do ( var num : OclAny := a[i+1] ; var g : OclAny := gcd(num, x) ; while (g /= 1) do ( num := num div g ; g := gcd(num, x)) ; if (num = 1) then ( flag := true; ; execute (a[i+1])->display(); ) else skip) ; if (not(flag)) then ( execute ("There are no such numbers")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMissing(arr,n,k,avg): sum=0 ; for i in range(n): sum+=arr[i]; num=(avg*(n+k))-sum ; den=k ; if(num % den!=0): return-1 ; return(int)(num/den); k=3 ; avg=4 ; arr=[2,7,3]; n=len(arr); print(findMissing(arr,n,k,avg)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; k := 3; avg := 4; ; arr := Sequence{2}->union(Sequence{7}->union(Sequence{ 3 })); ; n := (arr)->size(); ; execute (findMissing(arr, n, k, avg))->display();; operation findMissing(arr : OclAny, n : OclAny, k : OclAny, avg : OclAny) pre: true post: true activity: var sum : int := 0; ; for i : Integer.subrange(0, n-1) do ( sum := sum + arr[i+1];) ; var num : double := (avg * (n + k)) - sum; ; var den : OclAny := k; ; if (num mod den /= 0) then ( return -1; ) else skip ; return (OclType["int"])(num / den);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): ans=max(digit_product(NUMBER[i : i+ADJACENT])for i in range(len(NUMBER)-ADJACENT+1)) return str(ans) def digit_product(s): result=1 for c in s : result*=int(c) return result NUMBER="7316717653133062491922511967442657474" ADJACENT=13 if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var NUMBER : String := "7316717653133062491922511967442657474" ; var ADJACENT : int := 13 ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name digit_product)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name NUMBER)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))) : (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name ADJACENT))))))))) ])))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name NUMBER)))))))) )))) - (expr (atom (name ADJACENT)))) + (expr (atom (number (integer 1)))))))))) )))))))))->max() ; return ("" + ((ans))); operation digit_product(s : OclAny) : OclAny pre: true post: true activity: var result : int := 1 ; for c : s do ( result := result * ("" + ((c)))->toInteger()) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline N=int(readline()) Ns=1<toInteger() ; var Ns : int := 1 * (2->pow(N)) ; var S : Sequence := Sequence{ null }->union(((readline()->trim())->collect( _x | (OclType["int"])->apply(_x) ))) ; var P : Sequence := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, Ns) ; res->first() := P ; res[1+1] := P->tail()->union(Sequence{ P->first() }) ; var Ans : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, Ns) ; for i : Integer.subrange(0, Ns-1) do ( var ri : OclAny := res[i+1] ; var leng : int := (ri)->size() ; for level : Integer.subrange(0, leng.bit_length() - 1-1) do ( var cnt : Sequence := Sequence{} ; for j : Integer.subrange(0, (ri)->size() div 2-1) do ( var a : OclAny := ri[2 * j+1] ; var b : OclAny := ri[2 * j + 1+1] ; if S[(a - b)->abs()+1] = 1 then ( execute ((Set{a, b}->max()) : cnt) ) else ( execute ((Set{a, b}->min()) : cnt) )) ; ri := cnt ; var lri : int := (ri)->size() ; if 1 < Ns div lri & (Ns div lri < Ns - i) then ( res[i + Ns div lri+1] := ri->tail()->union(Sequence{ ri->first() }) ) else skip) ; Ans[i+1] := ri->first()) ; execute (StringLib.sumStringsWithSeparator(((Ans)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines N=int(readline()) S=[0]+[int(x)-ord('0')for x in readline().rstrip()] P=[int(x)for x in read().split()] P+=P dp=[P] for i in range(N+1): P=dp[i] newP=[] dx=1<b : a,b=b,a if S[b-a]: newP.append(b) else : newP.append(a) dp.append(newP) answers=(x for x in P[:-1]) print('\n'.join(map(str,answers))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; var N : int := ("" + ((readline())))->toInteger() ; var S : Sequence := Sequence{ 0 }->union(readline().rstrip()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - ('0')->char2byte()))) ; var P : Sequence := read().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; P := P + P ; var dp : Sequence := Sequence{ P } ; for i : Integer.subrange(0, N + 1-1) do ( P := dp[i+1] ; var newP : Sequence := Sequence{} ; var dx : int := 1 * (2->pow(i)) ; for _tuple : Integer.subrange(1, P->size())->collect( _indx | Sequence{P->at(_indx), P.subrange(dx+1)->at(_indx)} ) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if (a->compareTo(b)) > 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a} ) else skip ; if S[b - a+1] then ( execute ((b) : newP) ) else ( execute ((a) : newP) )) ; execute ((newP) : dp)) ; var answers : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name x)))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name P)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))))} ; execute (StringLib.sumStringsWithSeparator(((answers)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s,f=input(),input() s,f,x=s[: :-1],f[: :-1],0 for i in range(len(s)): if isize()-1) do ( if (i->compareTo((f)->size())) < 0 & s[i+1] = f[i+1] then ( x := x + 2 ) else ( break )) ; var ans : double := (s)->size() + (f)->size() - x ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfSeries(n): res=0.0 sum=0 prod=1 for i in range(1,n+1): sum=sum+i prod=prod*i res=res+(sum/prod) return res n=4 print(round(sumOfSeries(n),5)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute (MathLib.roundN(sumOfSeries(n), 5))->display(); operation sumOfSeries(n : OclAny) : OclAny pre: true post: true activity: var res : double := 0.0 ; var sum : int := 0 ; var prod : int := 1 ; for i : Integer.subrange(1, n + 1-1) do ( sum := sum + i ; prod := prod * i ; res := res + (sum / prod)) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b,c=input().split(" ") a,b,c=int(a),int(b),int(c) a,b,c=sorted([a,b,c]) if c-a<=2 : print(0) else : print(2*(c-a-2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := input().split(" ") ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{("" + ((a)))->toInteger(),("" + ((b)))->toInteger(),("" + ((c)))->toInteger()} ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{a}->union(Sequence{b}->union(Sequence{ c }))->sort() ; if c - a <= 2 then ( execute (0)->display() ) else ( execute (2 * (c - a - 2))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s="Mr John Smith " s=s.strip() s=s.replace(' ',"%20") print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := "Mr John Smith " ; s := s->trim() ; s := s.replace(' ', "%20") ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import reduce from collections import Counter while True : n,k=map(int,input().split()) if n==0 : break clst=[int(input())for _ in range(n)] acc=reduce(lambda x,y : x*y,clst[: k]) scores=[acc] for i in range(n-k): acc=acc//clst[i]*clst[i+k] scores.append(acc) score=0 for i in range(n): for j in range(i+1,n): p=clst[i] q=clst[j] for x in range(i-k+1,i+1): if abs(j-x)>=k and 0<=x<=n-k : score=max(score,scores[x]//p*q) for x in range(j-k+1,j+1): if abs(x-i)>=k and 0<=x<=n-k : score=max(score,scores[x]//q*p) if scorecollect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var clst : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var acc : OclAny := reduce(lambda x : OclAny, y : OclAny in (x * y), clst.subrange(1,k)) ; var scores : Sequence := Sequence{ acc } ; for i : Integer.subrange(0, n - k-1) do ( acc := acc div clst[i+1] * clst[i + k+1] ; execute ((acc) : scores)) ; var score : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( var p : OclAny := clst[i+1] ; var q : OclAny := clst[j+1] ; for x : Integer.subrange(i - k + 1, i + 1-1) do ( if ((j - x)->abs()->compareTo(k)) >= 0 & 0 <= x & (x <= n - k) then ( score := Set{score, scores[x+1] div p * q}->max() ) else skip) ; for x : Integer.subrange(j - k + 1, j + 1-1) do ( if ((x - i)->abs()->compareTo(k)) >= 0 & 0 <= x & (x <= n - k) then ( score := Set{score, scores[x+1] div q * p}->max() ) else skip))) ; if (score->compareTo((scores)->max())) < 0 then ( execute ("NO GAME")->display() ) else ( execute (score - (scores)->max())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNonPalinString(s): freq=[0]*(26) flag=0 for i in range(0,len(s)): if s[i]!=s[0]: flag=1 freq[ord(s[i])-ord('a')]+=1 if not flag : print("-1") else : for i in range(0,26): for j in range(0,freq[i]): print(chr(ord('a')+i),end="") if __name__=="__main__" : s="abba" findNonPalinString(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "abba" ; findNonPalinString(s) ) else skip; operation findNonPalinString(s : OclAny) pre: true post: true activity: var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (26)) ; var flag : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] /= s->first() then ( flag := 1 ) else skip ; freq[(s[i+1])->char2byte() - ('a')->char2byte()+1] := freq[(s[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; if not(flag) then ( execute ("-1")->display() ) else ( for i : Integer.subrange(0, 26-1) do ( for j : Integer.subrange(0, freq[i+1]-1) do ( execute ((('a')->char2byte() + i)->byte2char())->display())) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) dp=[1]*(n+1) mod=10**9+7 for i in range(k-1): for j in range(1,n+1): for t in range(2*j,n+1,j): dp[j]+=dp[t] print((sum(dp[1 :]))% mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ; var mod : double := (10)->pow(9) + 7 ; for i : Integer.subrange(0, k - 1-1) do ( for j : Integer.subrange(1, n + 1-1) do ( for t : Integer.subrange(2 * j, n + 1-1)->select( $x | ($x - 2 * j) mod j = 0 ) do ( dp[j+1] := dp[j+1] + dp[t+1]))) ; execute (((dp->tail())->sum()) mod mod)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num,l=map(int,input().split()) num+=1 l+=1 ls=[[0]*num for _ in range(13)] sol=0 v=1000000007 o=[1] for itr in range(1,4500): o.append(o[-1]*itr % v) def fun(num,l): if l>num : return 0 return o[num]*pow(o[l]*o[num-l]% v,v-2,v)% v for itr in range(1,12): for itr2 in range(1,num): if itr==1 : ls[itr][itr2]=1 for i in range(itr2*2,num,itr2): ls[itr+1][i]=(ls[itr+1][i]+ls[itr][itr2])% v sol=(sol+fun(l-2,itr-1)*ls[itr][itr2]% v)% v print(sol) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : OclAny := null; var l : OclAny := null; Sequence{num,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; num := num + 1 ; l := l + 1 ; var ls : Sequence := Integer.subrange(0, 13-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, num))) ; var sol : int := 0 ; var v : int := 1000000007 ; var o : Sequence := Sequence{ 1 } ; for itr : Integer.subrange(1, 4500-1) do ( execute ((o->last() * itr mod v) : o)) ; skip ; for itr : Integer.subrange(1, 12-1) do ( for itr2 : Integer.subrange(1, num-1) do ( if itr = 1 then ( ls[itr+1][itr2+1] := 1 ) else skip ; for i : Integer.subrange(itr2 * 2, num-1)->select( $x | ($x - itr2 * 2) mod itr2 = 0 ) do ( ls[itr + 1+1][i+1] := (ls[itr + 1+1][i+1] + ls[itr+1][itr2+1]) mod v) ; sol := (sol + fun(l - 2, itr - 1) * ls[itr+1][itr2+1] mod v) mod v)) ; execute (sol)->display(); operation fun(num : OclAny, l : OclAny) : OclAny pre: true post: true activity: if (l->compareTo(num)) > 0 then ( return 0 ) else skip ; return o[num+1] * (o[l+1] * o[num - l+1] mod v)->pow(v - 2) mod v; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def dividors(n): d=[] for i in range(1,int(math.sqrt(n))+1): if n % i==0 : d.append(i) if i*i!=n : d.append(n//i) return d nm,km=map(int,input().split()) dp=[[0]*(nm+1)for i in range(km+1)] div=[dividors(i)for i in range(nm+1)] for n in range(1,nm+1): dp[1][n]=1 for k in range(1,km+1): dp[k][1]=1 for k in range(2,km+1): for n in range(2,nm+1): for d in div[n]: dp[k][n]=(dp[k][n]+dp[k-1][d])% 1000000007 print(sum(dp[km])% 1000000007) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var nm : OclAny := null; var km : OclAny := null; Sequence{nm,km} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dp : Sequence := Integer.subrange(0, km + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (nm + 1)))) ; var div : Sequence := Integer.subrange(0, nm + 1-1)->select(i | true)->collect(i | (dividors(i))) ; for n : Integer.subrange(1, nm + 1-1) do ( dp[1+1][n+1] := 1) ; for k : Integer.subrange(1, km + 1-1) do ( dp[k+1][1+1] := 1) ; for k : Integer.subrange(2, km + 1-1) do ( for n : Integer.subrange(2, nm + 1-1) do ( for d : div[n+1] do ( dp[k+1][n+1] := (dp[k+1][n+1] + dp[k - 1+1]->restrict(d)) mod 1000000007))) ; execute ((dp[km+1])->sum() mod 1000000007)->display(); operation dividors(n : OclAny) : OclAny pre: true post: true activity: var d : Sequence := Sequence{} ; for i : Integer.subrange(1, ("" + (((n)->sqrt())))->toInteger() + 1-1) do ( if n mod i = 0 then ( execute ((i) : d) ; if i * i /= n then ( execute ((n div i) : d) ) else skip ) else skip) ; return d; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,k=map(int,input().split()) d=[[0 for _ in range(2007)]for _ in range(2007)] res=0 MOD=int(1e9+7) for i in range(1,k+1): for j in range(n,0,-1): if i==1 : d[i][j]=1 else : for l in range(1,n+1): if l*j>n : break else : d[i][j]=(d[i][j]+d[i-1][l*j])% MOD for i in range(1,n+1): res=(res+d[k][i])% MOD print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := Integer.subrange(0, 2007-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, 2007-1)->select(_anon | true)->collect(_anon | (0)))) ; var res : int := 0 ; var MOD : int := ("" + ((("1e9")->toReal() + 7)))->toInteger() ; for i : Integer.subrange(1, k + 1-1) do ( for j : Integer.subrange(0 + 1, n)->reverse() do ( if i = 1 then ( d[i+1][j+1] := 1 ) else ( for l : Integer.subrange(1, n + 1-1) do ( if (l * j->compareTo(n)) > 0 then ( break ) else ( d[i+1][j+1] := (d[i+1][j+1] + d[i - 1+1][l * j+1]) mod MOD )) ))) ; for i : Integer.subrange(1, n + 1-1) do ( res := (res + d[k+1][i+1]) mod MOD) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def C(n,m): a=1 for i in range(n-m+1,n+1): a*=i for i in range(1,m+1): a//=i return a n,k=map(int,input().split()) a=0 for i in range(1,n+1): t=1 I=i for j in range(2,i+1): s=0 while I % j==0 : s+=1 I//=j if s : t*=C(s+k-1,s) a+=t print(a %(10**9+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := 0 ; for i : Integer.subrange(1, n + 1-1) do ( var t : int := 1 ; var I : OclAny := i ; for j : Integer.subrange(2, i + 1-1) do ( var s : int := 0 ; while I mod j = 0 do ( s := s + 1 ; I := I div j) ; if s then ( t := t * C(s + k - 1, s) ) else skip) ; a := a + t) ; execute (a mod ((10)->pow(9) + 7))->display(); operation C(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var a : int := 1 ; for i : Integer.subrange(n - m + 1, n + 1-1) do ( a := a * i) ; for i : Integer.subrange(1, m + 1-1) do ( a := a div i) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) res=(i for i in range(2*n,4*n,2)) print(*res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name n)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (number (integer 4)))) * (expr (atom (name n)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ))))))))} ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() A=input() N=len(S) J=len(A) while N*J*(S[N-1]==A[J-1]): N-=1 J-=1 print(N+J) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var A : String := (OclFile["System.in"]).readLine() ; var N : int := (S)->size() ; var J : int := (A)->size() ; while N * J * (S[N - 1+1] = A[J - 1+1]) do ( N := N - 1 ; J := J - 1) ; execute (N + J)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline q=int(input()) for test in range(q): a,b,c=map(int,input().split()) ANS=1<<60 for x in range(a-1,a+2): for y in range(b-1,b+2): for z in range(c-1,c+2): ANS=min(abs(x-y)+abs(y-z)+abs(z-x),ANS) print(ANS) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for test : Integer.subrange(0, q-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ANS : int := 1 * (2->pow(60)) ; for x : Integer.subrange(a - 1, a + 2-1) do ( for y : Integer.subrange(b - 1, b + 2-1) do ( for z : Integer.subrange(c - 1, c + 2-1) do ( ANS := Set{(x - y)->abs() + (y - z)->abs() + (z - x)->abs(), ANS}->min()))) ; execute (ANS)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: n=int(s); print(*range(2*n,4*n,2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var n : int := ("" + ((s)))->toInteger(); execute ((argument * (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name n)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (number (integer 4)))) * (expr (atom (name n)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) print(*range(2*n,4*n,2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((argument * (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name n)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (number (integer 4)))) * (expr (atom (name n)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import* from decimal import* from opcode import HAVE_ARGUMENT from re import I import sys from tkinter import N input_=sys.stdin.readline def _input(): return map(int,input().split()) def _list(): return list(map(int,input().split())) a=[] def solves(a): n=int(input()) for i in range(1,n+1): print(4*n+2-i*2,end=' ') print() t=1 t=int(input()) for _ in range(0,t): solves(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var input_ : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; var a : Sequence := Sequence{} ; skip ; var t : int := 1 ; t := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( solves(a)); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation _list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation solves(a : OclAny) pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(1, n + 1-1) do ( execute (4 * n + 2 - i * 2)->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : t-=1 n=int(input()) a=[] for i in range(4*n,2*n+1,-2): a.append(i) for i in a[:-1]: print(i,end=' ') print(a[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( t := t - 1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; for i : Integer.subrange(4 * n, 2 * n + 1-1)->select( $x | ($x - 4 * n) mod -2 = 0 ) do ( execute ((i) : a)) ; for i : a->front() do ( execute (i)->display()) ; execute (a->last())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkOrigin(x1,y1,x2,y2): return(x1*(y2-y1)==y1*(x2-x1)) if(checkOrigin(1,28,2,56)==True): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if (checkOrigin(1, 28, 2, 56) = true) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation checkOrigin(x1 : OclAny, y1 : OclAny, x2 : OclAny, y2 : OclAny) : OclAny pre: true post: true activity: return (x1 * (y2 - y1) = y1 * (x2 - x1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxAvgSubArray(a,n,x,y): prefix=[0]*n ; prefix[0]=a[0]; for i in range(1,n): prefix[i]=prefix[i-1]+a[i]; maximum=0 ; for i in range(n): j=i+x-1 while(j0): sum-=prefix[i-1]; current=sum/(j-i+1); maximum=max(maximum,current); j+=1 return maximum ; if __name__=="__main__" : a=[6,7,8,3,2,4,2]; X=2 ; Y=4 ; n=len(a); print(maxAvgSubArray(a,n,X,Y)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{3}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 2 })))))); ; var X : int := 2; var Y : int := 4; ; n := (a)->size(); ; execute (maxAvgSubArray(a, n, X, Y))->display(); ) else skip; operation maxAvgSubArray(a : OclAny, n : OclAny, x : OclAny, y : OclAny) pre: true post: true activity: var prefix : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; prefix->first() := a->first(); ; for i : Integer.subrange(1, n-1) do ( prefix[i+1] := prefix[i - 1+1] + a[i+1];) ; var maximum : int := 0; ; for i : Integer.subrange(0, n-1) do ( var j : double := i + x - 1 ; while ((j->compareTo(i + y)) < 0 & (j->compareTo(n)) < 0) do ( var sum : OclAny := prefix[j+1]; ; if (i > 0) then ( sum := sum - prefix[i - 1+1]; ) else skip ; var current : double := sum / (j - i + 1); ; maximum := Set{maximum, current}->max(); ; j := j + 1)) ; return maximum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) trash=[list(map(int,input().split()))for i in range(n)] ans=[] if k==0 : for i in range(m): for j in range(i+1,m): ans.append([i+1,j+1]) if k==1 : for i in range(m): for j in range(i+1,m): ans.append([j+1,i+1]) print(len(ans)) for p in ans : print(p[0],p[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var trash : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ans : Sequence := Sequence{} ; if k = 0 then ( for i : Integer.subrange(0, m-1) do ( for j : Integer.subrange(i + 1, m-1) do ( execute ((Sequence{i + 1}->union(Sequence{ j + 1 })) : ans))) ) else skip ; if k = 1 then ( for i : Integer.subrange(0, m-1) do ( for j : Integer.subrange(i + 1, m-1) do ( execute ((Sequence{j + 1}->union(Sequence{ i + 1 })) : ans))) ) else skip ; execute ((ans)->size())->display() ; for p : ans do ( execute (p->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) print(m*(m-1)//2) for i in range(1,m): for j in range(i+1,m+1): if k==0 : print(i,j) else : print(j,i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (m * (m - 1) div 2)->display() ; for i : Integer.subrange(1, m-1) do ( for j : Integer.subrange(i + 1, m + 1-1) do ( if k = 0 then ( execute (i)->display() ) else ( execute (j)->display() ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) print(m*(m-1)//2) for i in range(1,m): for j in range(i+1,m+1): if k==0 : print(i,j) else : print(j,i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (m * (m - 1) div 2)->display() ; for i : Integer.subrange(1, m-1) do ( for j : Integer.subrange(i + 1, m + 1-1) do ( if k = 0 then ( execute (i)->display() ) else ( execute (j)->display() ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) a=[] for i in range(n): a.append(list(map(int,input().split()))) print(m*(m-1)//2) for i in range(1,m): for j in range(i+1,m+1): if k==0 : print(i,j) else : print(j,i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : a)) ; execute (m * (m - 1) div 2)->display() ; for i : Integer.subrange(1, m-1) do ( for j : Integer.subrange(i + 1, m + 1-1) do ( if k = 0 then ( execute (i)->display() ) else ( execute (j)->display() ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in[0]*int(input()): a,b,c=sorted(map(int,input().split())); print(2*max(c-a,2)-4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort(); execute (2 * Set{c - a, 2}->max() - 4)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- total_number=input().split() b=set() c=set() for i in range(1,int(total_number[1])+1): b.add(i) for a in range(int(total_number[0])): again=input().split() for d in range(1,int(again[0])+1): c.add(int(again[d])) if b==c : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var total_number : OclAny := input().split() ; var b : Set := Set{}->union(()) ; var c : Set := Set{}->union(()) ; for i : Integer.subrange(1, ("" + ((total_number[1+1])))->toInteger() + 1-1) do ( execute ((i) : b)) ; for a : Integer.subrange(0, ("" + ((total_number->first())))->toInteger()-1) do ( var again : OclAny := input().split() ; for d : Integer.subrange(1, ("" + ((again->first())))->toInteger() + 1-1) do ( execute ((("" + ((again[d+1])))->toInteger()) : c))) ; if b = c then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) trash=[list(map(int,input().split()))for i in range(n)] ans=[] if k==0 : for i in range(m): for j in range(i+1,m): ans.append([i+1,j+1]) if k==1 : for i in range(m): for j in range(i+1,m): ans.append([j+1,i+1]) print(len(ans)) for p in ans : print(p[0],p[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var trash : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ans : Sequence := Sequence{} ; if k = 0 then ( for i : Integer.subrange(0, m-1) do ( for j : Integer.subrange(i + 1, m-1) do ( execute ((Sequence{i + 1}->union(Sequence{ j + 1 })) : ans))) ) else skip ; if k = 1 then ( for i : Integer.subrange(0, m-1) do ( for j : Integer.subrange(i + 1, m-1) do ( execute ((Sequence{j + 1}->union(Sequence{ i + 1 })) : ans))) ) else skip ; execute ((ans)->size())->display() ; for p : ans do ( execute (p->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def prime_factorize(n): ans=[] for i in range(2,int(n**(1/2))+1): while True : if n % i : break ans.append(i) n//=i if n==1 : break if not n==1 : ans.append(n) return ans n=int(input()) if n==1 : m,c=1,0 print(m,c) exit() s=prime_factorize(n) cnt=defaultdict(lambda : 0) for i in s : cnt[i]+=1 m=1 for i in cnt : m*=i u=max(cnt.values()) c=(u-1).bit_length() p=pow(2,c) v=0 for i in cnt.values(): v=max(v,min(i ^ p,1)) c+=v print(m,c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( var m : OclAny := null; var c : OclAny := null; Sequence{m,c} := Sequence{1,0} ; execute (m)->display() ; exit() ) else skip ; var s : OclAny := prime_factorize(n) ; var cnt : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; for i : s do ( cnt[i+1] := cnt[i+1] + 1) ; var m : int := 1 ; for i : cnt do ( m := m * i) ; var u : OclAny := (cnt.values())->max() ; var c : OclAny := (u - 1).bit_length() ; var p : double := (2)->pow(c) ; var v : int := 0 ; for i : cnt.values() do ( v := Set{v, Set{MathLib.bitwiseXor(i, p), 1}->min()}->max()) ; c := c + v ; execute (m)->display(); operation prime_factorize(n : OclAny) : OclAny pre: true post: true activity: var ans : Sequence := Sequence{} ; for i : Integer.subrange(2, ("" + (((n)->pow((1 / 2)))))->toInteger() + 1-1) do ( while true do ( if n mod i then ( break ) else skip ; execute ((i) : ans) ; n := n div i) ; if n = 1 then ( break ) else skip) ; if not(n = 1) then ( execute ((n) : ans) ) else skip ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt n=int(input()) ans=1 n1=n res=0 for i in range(2,int(sqrt(n1))+1): if n1 % i==0 : while n1 % i==0 : n1=n1//i ans=ans*i if n1>1 : ans=ans*n1 step=0 res=ans while res % n!=0 : res=res**2 step+=1 if res>n : step+=1 print(ans,'',end='') print(step,'',end='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 1 ; var n1 : int := n ; var res : int := 0 ; for i : Integer.subrange(2, ("" + ((sqrt(n1))))->toInteger() + 1-1) do ( if n1 mod i = 0 then ( while n1 mod i = 0 do ( n1 := n1 div i) ; ans := ans * i ) else skip) ; if n1 > 1 then ( ans := ans * n1 ) else skip ; var step : int := 0 ; res := ans ; while res mod n /= 0 do ( res := (res)->pow(2) ; step := step + 1) ; if (res->compareTo(n)) > 0 then ( step := step + 1 ) else skip ; execute (ans)->display() ; execute (step)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rozklad(wej): wyj=dict() i=2 while wej!=1 : if wej % i==0 : wyj[i]=wyj.get(i,0)+1 wej//=i else : i+=1 return wyj def potega(wej): wynik,i=0,1 while itoInteger()); operation rozklad(wej : OclAny) : OclAny pre: true post: true activity: var wyj : Map := (arguments ( )) ; var i : int := 2 ; while wej /= 1 do ( if wej mod i = 0 then ( wyj[i+1] := wyj.get(i, 0) + 1 ; wej := wej div i ) else ( i := i + 1 )) ; return wyj; operation potega(wej : OclAny) : OclAny pre: true post: true activity: var wynik : OclAny := null; Sequence{wynik,i} := Sequence{0,1} ; while (i->compareTo(wej)) < 0 do ( i := i * 2 ; wynik := wynik + 1) ; return i, wynik; operation main(wej : OclAny) pre: true post: true activity: if wej = 1 then ( execute (1)->display() ; return ) else skip ; var dziel : OclAny := rozklad(wej) ; var maks : OclAny := null; var wynik : OclAny := null; Sequence{maks,wynik} := potega((dziel.values())->max()) ; for i : dziel.values() do ( if i /= maks then ( wynik := wynik + 1 ; break ) else skip) ; var liczba : int := 1 ; for i : dziel do ( liczba := liczba * i) ; execute (liczba)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rozklad(wej): wyj=dict() i=2 while wej!=1 : if wej % i==0 : wyj[i]=wyj.get(i,0)+1 wej//=i else : i+=1 return wyj def potega(wej): wynik,i=0,1 while itoInteger()); operation rozklad(wej : OclAny) : OclAny pre: true post: true activity: var wyj : Map := (arguments ( )) ; var i : int := 2 ; while wej /= 1 do ( if wej mod i = 0 then ( wyj[i+1] := wyj.get(i, 0) + 1 ; wej := wej div i ) else ( i := i + 1 )) ; return wyj; operation potega(wej : OclAny) : OclAny pre: true post: true activity: var wynik : OclAny := null; Sequence{wynik,i} := Sequence{0,1} ; while (i->compareTo(wej)) < 0 do ( i := i * 2 ; wynik := wynik + 1) ; return i, wynik; operation main(wej : OclAny) pre: true post: true activity: if wej = 1 then ( execute (1)->display() ; return ) else skip ; var dziel : OclAny := rozklad(wej) ; var maks : OclAny := null; var wynik : OclAny := null; Sequence{maks,wynik} := potega((dziel.values())->max()) ; for i : dziel.values() do ( if i /= maks then ( wynik := wynik + 1 ; break ) else skip) ; var liczba : int := 1 ; for i : dziel do ( liczba := liczba * i) ; execute (liczba)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) curr=n k=2 a=1 b=0 vals=[] while curr>1 : if curr % k==0 : a*=k c=0 while curr % k==0 : curr//=k c+=1 if c!=0 : vals.append(c) k+=1 if a!=n : max_val=max(vals) if max_val % 2==1 : max_val+=1 flag=any(max_val-vals[i]>0 for i in range(len(vals))) other=False while max_val>1 : if max_val % 2==1 : other=not other max_val+=1 max_val//=2 b+=1 b+=flag or other print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var curr : int := n ; var k : int := 2 ; var a : int := 1 ; var b : int := 0 ; var vals : Sequence := Sequence{} ; while curr > 1 do ( if curr mod k = 0 then ( a := a * k ) else skip ; var c : int := 0 ; while curr mod k = 0 do ( curr := curr div k ; c := c + 1) ; if c /= 0 then ( execute ((c) : vals) ) else skip ; k := k + 1) ; if a /= n then ( var max_val : OclAny := (vals)->max() ; if max_val mod 2 = 1 then ( max_val := max_val + 1 ) else skip ; var flag : boolean := ((argument (test (logical_test (comparison (comparison (expr (expr (atom (name max_val))) - (expr (atom (name vals)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))) > (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name vals)))))))) ))))))))) )))))))))->exists( _x | _x = true ) ; var other : boolean := false ; while max_val > 1 do ( if max_val mod 2 = 1 then ( other := not(other) ; max_val := max_val + 1 ) else skip ; max_val := max_val div 2 ; b := b + 1) ; b := b + flag or other ) else skip ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findPair(arr,n): if(n<2): print("-1",end=" "); return ; maximum=max(arr); temp=10000001 ; r=0 ; middle=maximum//2 ; for i in range(n): if(abs(middle-arr[i])union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{1}->union(Sequence{6}->union(Sequence{8}->union(Sequence{ 9 }))))))); ; n := (arr)->size(); ; findPair(arr, n); ) else skip; operation findPair(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n < 2) then ( execute ("-1")->display(); ; return; ) else skip ; var maximum : OclAny := (arr)->max(); ; var temp : int := 10000001; var r : int := 0; var middle : int := maximum div 2; ; for i : Integer.subrange(0, n-1) do ( if (((middle - arr[i+1])->abs()->compareTo(temp)) < 0 & n mod 2 = 0) then ( temp := (middle - arr[i+1])->abs(); ; r := arr[i+1]; ) else (if ((Set{(middle - arr[i+1])->abs(), (middle + 1 - arr[i+1])->abs()}->min()->compareTo(temp)) < 0 & n mod 2 = 1) then ( temp := Set{(middle - arr[i+1])->abs(), (middle + 1 - arr[i+1])->abs()}->min(); ; r := arr[i+1]; ) else skip)) ; execute ("n=")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairs(s,K): if(K>s or(s-K)% 2==1): return 0 setBits=(str(bin(K))[2 :]).count("1") pairsCount=pow(2,setBits) if(s==K): pairsCount-=2 return pairsCount if __name__=='__main__' : s,K=9,5 print(countPairs(s,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( Sequence{s,K} := Sequence{9,5} ; execute (countPairs(s, K))->display() ) else skip; operation countPairs(s : OclAny, K : OclAny) : OclAny pre: true post: true activity: if ((K->compareTo(s)) > 0 or (s - K) mod 2 = 1) then ( return 0 ) else skip ; var setBits : int := (OclType["String"](bin(K)).subrange(2+1))->count("1") ; var pairsCount : double := (2)->pow(setBits) ; if (s = K) then ( pairsCount := pairsCount - 2 ) else skip ; return pairsCount; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=3 def scalarProductMat(mat,k): for i in range(N): for j in range(N): mat[i][j]=mat[i][j]*k if __name__=="__main__" : mat=[[1,2,3],[4,5,6],[7,8,9]] k=4 scalarProductMat(mat,k) print("Scalar Product Matrix is : ") for i in range(N): for j in range(N): print(mat[i][j],end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 3 ; skip ; if __name__ = "__main__" then ( mat := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))}->union(Sequence{ Sequence{7}->union(Sequence{8}->union(Sequence{ 9 })) })) ; k := 4 ; scalarProductMat(mat, k) ; execute ("Scalar Product Matrix is : ")->display() ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( execute (mat[i+1][j+1])->display()) ; execute (->display()) ) else skip; operation scalarProductMat(mat : OclAny, k : OclAny) pre: true post: true activity: for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( mat[i+1][j+1] := mat[i+1][j+1] * k)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math number=int(input()) for i in range(number): a=list(map(int,input().split())) a.sort() if a[0]toInteger() ; for i : Integer.subrange(0, number-1) do ( var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; if (a->first()->compareTo(a[1+1])) < 0 then ( a->first() := a->first() + 1 ) else (if a->first() = a[1+1] & (a[1+1]->compareTo(a[2+1])) < 0 then ( a->first() := a->first() + 1 ; a[1+1] := a[1+1] + 1 ) else skip) ; if (a[1+1]->compareTo(a[2+1])) < 0 then ( a[2+1] := a[2+1] - 1 ) else (if a[1+1] = a[2+1] & (a->first()->compareTo(a[1+1])) < 0 then ( a[2+1] := a[2+1] - 1 ; a[1+1] := a[1+1] - 1 ) else skip) ; var sum : double := ((a->first() - a[1+1]))->abs() + ((a[2+1] - a[1+1]))->abs() + ((a->first() - a[2+1]))->abs() ; execute (sum)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) P=[int(x)for x in input().split()] t=[int(x)for x in input().split()] dp=[1<<29]*10001 dp[0]=0 for i in range(4): for j in range(1,t[i]): if dp[j]>P[i]: dp[j]=P[i] for j in range(t[i],10001): dp[j]=min(dp[j],dp[j-t[i]]+P[i]) print(min(dp[N :])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var P : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var t : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 * (2->pow(29)) }, 10001) ; dp->first() := 0 ; for i : Integer.subrange(0, 4-1) do ( for j : Integer.subrange(1, t[i+1]-1) do ( if (dp[j+1]->compareTo(P[i+1])) > 0 then ( dp[j+1] := P[i+1] ) else skip) ; for j : Integer.subrange(t[i+1], 10001-1) do ( dp[j+1] := Set{dp[j+1], dp[j - t[i+1]+1] + P[i+1]}->min())) ; execute ((dp.subrange(N+1))->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- out='' li1=input().split() n=int(li1[0]) m=int(li1[1]) li=[] for i in range(n): li2=list(map(int,input().split())) xi=li2[0] for i1 in range(xi): li.append(li2[i1+1]) for i2 in range(1,m+1): if i2 not in li : out='NO' break else : out='YES' print(out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var out : String := '' ; var li1 : OclAny := input().split() ; var n : int := ("" + ((li1->first())))->toInteger() ; var m : int := ("" + ((li1[1+1])))->toInteger() ; var li : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var li2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var xi : OclAny := li2->first() ; for i1 : Integer.subrange(0, xi-1) do ( execute ((li2[i1 + 1+1]) : li))) ; for i2 : Integer.subrange(1, m + 1-1) do ( if (li)->excludes(i2) then ( out := 'NO' ; break ) else ( out := 'YES' )) ; execute (out)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from operator import itemgetter from fractions import gcd from math import ceil,floor,sqrt from copy import deepcopy from collections import Counter,deque import heapq from functools import reduce sys.setrecursionlimit(200000) input=sys.stdin.readline def ii(): return int(input()) def mi(): return map(int,input().rstrip().split()) def lmi(): return list(map(int,input().rstrip().split())) def li(): return list(input().rstrip()) def debug(*args,sep=" ",end="\n"): print("debug:",*args,file=sys.stderr,sep=sep,end=end)if not __debug__ else None def exit(*arg): print(*arg); sys.exit() def main(): N=ii() p=lmi() t=lmi() n=len(p) v=[(i,p[i]/t[i])for i in range(n)] v.sort(key=itemgetter(1)) m=v[0][0] ans=ceil(N/t[m])*p[m] for i in range(4): if i!=m : ans=min(ans,ceil((N-t[i])/t[m])*p[m]+p[i]) print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(200000) ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation ii() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation mi() : OclAny pre: true post: true activity: return (input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ); operation lmi() : OclAny pre: true post: true activity: return ((input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )); operation li() : OclAny pre: true post: true activity: return (input().rstrip()); operation debug(args : OclAny : Sequence(OclAny), sep : String, end : String) pre: true post: true activity: (args * (named_parameter (name args))) if sep->oclIsUndefined() then sep := " " else skip; if end->oclIsUndefined() then end := "\n" else skip; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "debug:")))))) , (argument * (test (logical_test (comparison (expr (atom (name args))))))) , (argument (test (logical_test (comparison (expr (atom (name file)))))) = (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stderr))))))) , (argument (test (logical_test (comparison (expr (atom (name sep)))))) = (test (logical_test (comparison (expr (atom (name sep))))))) , (argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom (name end)))))))) )))))) if (logical_test not (logical_test (comparison (expr (atom (name __debug__)))))) else (test (logical_test (comparison (expr (atom None)))))); operation exit(arg : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name arg))) execute ((argument * (test (logical_test (comparison (expr (atom (name arg))))))))->display(); sys.exit(); operation main() pre: true post: true activity: var N : OclAny := ii() ; var p : OclAny := lmi() ; var t : OclAny := lmi() ; var n : int := (p)->size() ; var v : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{i, p[i+1] / t[i+1]})) ; v := v->sort() ; var m : OclAny := v->first()->first() ; var ans : double := ceil(N / t[m+1]) * p[m+1] ; for i : Integer.subrange(0, 4-1) do ( if i /= m then ( ans := Set{ans, ceil((N - t[i+1]) / t[m+1]) * p[m+1] + p[i+1]}->min() ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lis1=list(map(int,input().split())) lis2=list(map(int,input().split())) money=[10**7+9]*(n+1) money[0]=0 for price,num in zip(lis1,lis2): i=0 while(itoInteger() ; var lis1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lis2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var money : Sequence := MatrixLib.elementwiseMult(Sequence{ (10)->pow(7) + 9 }, (n + 1)) ; money->first() := 0 ; for _tuple : Integer.subrange(1, lis1->size())->collect( _indx | Sequence{lis1->at(_indx), lis2->at(_indx)} ) do (var _indx : int := 1; var price : OclAny := _tuple->at(_indx); _indx := _indx + 1; var num : OclAny := _tuple->at(_indx); var i : int := 0 ; while ((i->compareTo(n + 1)) < 0) do ( if i - num < 0 then ( money[i+1] := Set{price, money[i+1]}->min() ) else ( money[i+1] := Set{money[i+1], price + money[i - num+1]}->min() ) ; i := i + 1)) ; execute (money[n+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,pa,pb,pc,pd,ta,tb,tc,td=map(int,open(0).read().split()) r=range(n+1) m=1e9 for i in r : for j in r : for k in r : l=0--(n-ta*i-tb*j-tc*k)//td m=min(m,pa*i+pb*j+pc*k+pd*l*(l>=0)) print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var pa : OclAny := null; var pb : OclAny := null; var pc : OclAny := null; var pd : OclAny := null; var ta : OclAny := null; var tb : OclAny := null; var tc : OclAny := null; var td : OclAny := null; Sequence{n,pa,pb,pc,pd,ta,tb,tc,td} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var r : Sequence := Integer.subrange(0, n + 1-1) ; var m : double := ("1e9")->toReal() ; for i : r do ( for j : r do ( for k : r do ( var l : double := 0 - -(n - ta * i - tb * j - tc * k) div td ; m := Set{m, pa * i + pb * j + pc * k + pd * l * (l >= 0)}->min()))) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def inpl(): return list(map(int,input().split())) N=int(input()) P=inpl() T=inpl() cost=10**9 for a in range(-(-N//T[0])+1): costa=P[0]*a teaa=T[0]*a rema=N-teaa for b in range(max(1,-(-rema//T[1])+1)): costb=P[1]*b teab=T[1]*b remb=max(rema-teab,0) for c in range(max(1,-(-remb//T[2])+1)): costc=P[2]*c teac=T[2]*c remc=max(remb-teac,0) d=max(-(-remc//T[3]),0) costd=P[3]*d tead=T[3]*d cost=min(cost,costa+costb+costc+costd) print(cost) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var P : OclAny := inpl() ; var T : OclAny := inpl() ; var cost : double := (10)->pow(9) ; for a : Integer.subrange(0, -(-N div T->first()) + 1-1) do ( var costa : double := P->first() * a ; var teaa : double := T->first() * a ; var rema : double := N - teaa ; for b : Integer.subrange(0, Set{1, -(-rema div T[1+1]) + 1}->max()-1) do ( var costb : double := P[1+1] * b ; var teab : double := T[1+1] * b ; var remb : OclAny := Set{rema - teab, 0}->max() ; for c : Integer.subrange(0, Set{1, -(-remb div T[2+1]) + 1}->max()-1) do ( var costc : double := P[2+1] * c ; var teac : double := T[2+1] * c ; var remc : OclAny := Set{remb - teac, 0}->max() ; var d : OclAny := Set{-(-remc div T[3+1]), 0}->max() ; var costd : double := P[3+1] * d ; var tead : double := T[3+1] * d ; cost := Set{cost, costa + costb + costc + costd}->min()))) ; execute (cost)->display(); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() n=int(input()) st=[input()for _ in range(n)] for i in range(n): st[i]=st[i]+st[i][: len(st[i])-1] cnt=0 for i in range(n): if s in st[i]: cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var st : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; for i : Integer.subrange(0, n-1) do ( st[i+1] := st[i+1] + st[i+1].subrange(1,(st[i+1])->size() - 1)) ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (st[i+1])->includes(s) then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input ; s=I(); print(sum(s in I()*2 for _ in[0]*int(I()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input; var s : OclAny := I(); execute (((argument (test (logical_test (comparison (comparison (expr (atom (name s)))) in (comparison (expr (expr (atom (name I)) (trailer (arguments ( )))) * (expr (atom (number (integer 2))))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name I)) (trailer (arguments ( ))))))))) ))))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() c=0 for i in range(int(input())): x=input() if s in x*2 : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var c : int := 0 ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : String := (OclFile["System.in"]).readLine() ; if (StringLib.nCopies(x, 2))->includes(s) then ( c := c + 1 ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def main(args): search_word=input().strip() N=int(input()) found=0 for _ in range(N): data=input().strip() data=data+data data=data[:-1] if search_word in data : found+=1 print(found) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation main(args : OclAny) pre: true post: true activity: var search_word : OclAny := input()->trim() ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var found : int := 0 ; for _anon : Integer.subrange(0, N-1) do ( var data : OclAny := input()->trim() ; data := data + data ; data := data->front() ; if (data)->includes(search_word) then ( found := found + 1 ) else skip) ; execute (found)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reverseArray(arr,n): for i in range(n//2): arr[i],arr[(n+~ i+1)+~ 1+1]=arr[(n+~ i+1)+~ 1+1],arr[i] arr=[5,3,7,2,1,6] n=len(arr) reverseArray(arr,n) for i in range(n): print(arr[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{5}->union(Sequence{3}->union(Sequence{7}->union(Sequence{2}->union(Sequence{1}->union(Sequence{ 6 }))))) ; n := (arr)->size() ; reverseArray(arr, n) ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); operation reverseArray(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n div 2-1) do ( var arr[i+1] : OclAny := null; var arr[(n + MathLib.bitwiseNot(i) + 1) + MathLib.bitwiseNot(1) + 1+1] : OclAny := null; Sequence{arr[i+1],arr[(n + MathLib.bitwiseNot(i) + 1) + MathLib.bitwiseNot(1) + 1+1]} := Sequence{arr[(n + MathLib.bitwiseNot(i) + 1) + MathLib.bitwiseNot(1) + 1+1],arr[i+1]}); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(a): a.sort() if a[0]==a[1]and a[1]==a[2]: return 0 if a[0]==a[1]: a[0]+=1 ; a[1]+=1 ; if a[2]!=a[1]: a[2]-=1 elif a[1]==a[2]: a[1]-=1 ; a[2]-=1 if a[0]!=a[1]: a[0]+=1 ; else : a[0]+=1 ; a[2]-=1 ans=abs(a[0]-a[1])+abs(a[1]-a[2])+abs(a[0]-a[2]) return ans t=int(input()) for _ in range(t): a=list((map(int,input().split()))) sol=solve(a) print(sol) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( a := (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sol : OclAny := solve(a) ; execute (sol)->display()); operation solve(a : OclAny) : OclAny pre: true post: true activity: a := a->sort() ; if a->first() = a[1+1] & a[1+1] = a[2+1] then ( return 0 ) else skip ; if a->first() = a[1+1] then ( a->first() := a->first() + 1; a[1+1] := a[1+1] + 1; ; if a[2+1] /= a[1+1] then ( a[2+1] := a[2+1] - 1 ) else skip ) else (if a[1+1] = a[2+1] then ( a[1+1] := a[1+1] - 1; a[2+1] := a[2+1] - 1 ; if a->first() /= a[1+1] then ( a->first() := a->first() + 1; ) else skip ) else ( a->first() := a->first() + 1; a[2+1] := a[2+1] - 1 ) ) ; var ans : double := (a->first() - a[1+1])->abs() + (a[1+1] - a[2+1])->abs() + (a->first() - a[2+1])->abs() ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() n=int(input()) rng=[input()for i in range(n)] contain=[False for i in range(n)] l=len(s) for i in range(len(rng)): t=rng[i]+rng[i][: l] for j in range(len(rng[i])): if s==t[j : j+l]: contain[i]=True break print(contain.count(True)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var rng : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var contain : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (false)) ; var l : int := (s)->size() ; for i : Integer.subrange(0, (rng)->size()-1) do ( var t : OclAny := rng[i+1] + rng[i+1].subrange(1,l) ; for j : Integer.subrange(0, (rng[i+1])->size()-1) do ( if s = t.subrange(j+1, j + l) then ( contain[i+1] := true ; break ) else skip)) ; execute (contain->count(true))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) for i in range(a): b,c=map(int,input().split()) if(c-b)>0 : if(c-b)% 2==0 : print(2) else : print(1) elif(c-b)<0 : if(c-b)% 2==0 : print(1) else : print(2) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, a-1) do ( var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (c - b) > 0 then ( if (c - b) mod 2 = 0 then ( execute (2)->display() ) else ( execute (1)->display() ) ) else (if (c - b) < 0 then ( if (c - b) mod 2 = 0 then ( execute (1)->display() ) else ( execute (2)->display() ) ) else ( execute (0)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) top=int(input()) l=[top,7-top] flag=True for i in range(n): x=input().split() if int(x[0])in l or int(x[1])in l : print('NO') flag=False break else : flag=True if flag : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var top : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{top}->union(Sequence{ 7 - top }) ; var flag : boolean := true ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := input().split() ; if (l)->includes(("" + ((x->first())))->toInteger()) or (l)->includes(("" + ((x[1+1])))->toInteger()) then ( execute ('NO')->display() ; flag := false ; break ) else ( flag := true )) ; if flag then ( execute ('YES')->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) allbulbs=[] for i in range(n): origin=[int(x)for x in input().split()] openbulbs=set(origin[1 :]) allbulbs+=openbulbs if len(set(allbulbs))collect( _x | (OclType["int"])->apply(_x) ) ; var allbulbs : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var origin : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var openbulbs : Set := Set{}->union((origin->tail())) ; allbulbs := allbulbs + openbulbs) ; if ((Set{}->union((allbulbs)))->size()->compareTo(m)) < 0 then ( execute ('NO')->display() ) else ( execute ('YES')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): l=[int(i)for i in input().split(' ')] d=abs(l[0]-l[1]) if d==0 : print(0) elif(l[0]>l[1]and d % 2==0)or(l[0]toInteger() ; for i : Integer.subrange(0, t-1) do ( var l : Sequence := input().split(' ')->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var d : double := (l->first() - l[1+1])->abs() ; if d = 0 then ( execute (0)->display() ) else (if ((l->first()->compareTo(l[1+1])) > 0 & d mod 2 = 0) or ((l->first()->compareTo(l[1+1])) < 0 & d mod 2 /= 0) then ( execute (1)->display() ) else ( execute (2)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b=map(int,input().split()) k=b-a if(k>0): if((a % 2!=0 and b % 2!=0)or(a % 2==0 and b % 2==0)): print(2) elif((a % 2!=0 and b % 2==0)or((a % 2==0 and b % 2!=0))): print(1) elif(k<0): if((a % 2!=0 and b % 2==0)or(a % 2==0 and b % 2!=0)): print(2) elif((a % 2==0 and b % 2==0)or(a % 2!=0 and b % 2!=0)): print(1) elif(k==0): print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : double := b - a ; if (k > 0) then ( if ((a mod 2 /= 0 & b mod 2 /= 0) or (a mod 2 = 0 & b mod 2 = 0)) then ( execute (2)->display() ) else (if ((a mod 2 /= 0 & b mod 2 = 0) or ((a mod 2 = 0 & b mod 2 /= 0))) then ( execute (1)->display() ) else skip) ) else (if (k < 0) then ( if ((a mod 2 /= 0 & b mod 2 = 0) or (a mod 2 = 0 & b mod 2 /= 0)) then ( execute (2)->display() ) else (if ((a mod 2 = 0 & b mod 2 = 0) or (a mod 2 /= 0 & b mod 2 /= 0)) then ( execute (1)->display() ) else skip) ) else (if (k = 0) then ( execute (0)->display() ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- j=int(input()) for i in range(j): vamshi,y=map(int,input().split()) if vamshi==y : print(0) elif vamshi>=y : x=vamshi-y if x % 2==0 : print(1) else : print(2) else : x=y-vamshi if x % 2==0 : print(2) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var j : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, j-1) do ( var vamshi : OclAny := null; var y : OclAny := null; Sequence{vamshi,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if vamshi = y then ( execute (0)->display() ) else (if (vamshi->compareTo(y)) >= 0 then ( var x : double := vamshi - y ; if x mod 2 = 0 then ( execute (1)->display() ) else ( execute (2)->display() ) ) else ( x := y - vamshi ; if x mod 2 = 0 then ( execute (2)->display() ) else ( execute (1)->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) for i in range(a): b,c=map(int,input().split()) if(c-b)>0 : if(c-b)% 2==0 : print(2) else : print(1) elif(c-b)<0 : if(c-b)% 2==0 : print(1) else : print(2) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, a-1) do ( var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (c - b) > 0 then ( if (c - b) mod 2 = 0 then ( execute (2)->display() ) else ( execute (1)->display() ) ) else (if (c - b) < 0 then ( if (c - b) mod 2 = 0 then ( execute (1)->display() ) else ( execute (2)->display() ) ) else ( execute (0)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(n,s): if(n!=5): return "NO" di={'T' : 0,'i' : 0,'m' : 0,'u' : 0,'r' : 0} for i in range(5): if(s[i]not in di.keys()): return "NO" elif(di[s[i]]==1): return "NO" else : di[s[i]]=1 return "YES" test=int(input()) for i in range(test): len=int(input()) str=input() print(check(len,str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var test : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, test-1) do ( var len : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var OclType["String"] : String := (OclFile["System.in"]).readLine() ; execute (check(len, OclType["String"]))->display()); operation check(n : OclAny, s : OclAny) : OclAny pre: true post: true activity: if (n /= 5) then ( return "NO" ) else skip ; var di : Map := Map{ 'T' |-> 0 }->union(Map{ 'i' |-> 0 }->union(Map{ 'm' |-> 0 }->union(Map{ 'u' |-> 0 }->union(Map{ 'r' |-> 0 })))) ; for i : Integer.subrange(0, 5-1) do ( if ((di.keys())->excludes(s[i+1])) then ( return "NO" ) else (if (di[s[i+1]+1] = 1) then ( return "NO" ) else ( di[s[i+1]+1] := 1 ) ) ) ; return "YES"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) s=input() a='Timur' a=list(a) s=list(s) a.sort() s.sort() print(['NO','YES'][a==s]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var a : String := 'Timur' ; a := (a)->characters() ; s := (s)->characters() ; a := a->sort() ; s := s->sort() ; execute (Sequence{'NO'}->union(Sequence{ 'YES' })->select(a = s))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,b,d=list(map(int,input().split())) a=list(map(int,input().split())) waste=0 num=0 for i in a : if i<=b : waste+=i if waste>d : num+=1 waste=0 print(num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var b : OclAny := null; var d : OclAny := null; Sequence{n,b,d} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var waste : int := 0 ; var num : int := 0 ; for i : a do ( if (i->compareTo(b)) <= 0 then ( waste := waste + i ) else skip ; if (waste->compareTo(d)) > 0 then ( num := num + 1 ; waste := 0 ) else skip) ; execute (num)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) s=list(input()) s.sort() if s==["T","i","m","r","u"]: print("Yes") else : print("No") t=int(input()) while t>0 : solve() t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( solve() ; t := t - 1); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; s := s->sort() ; if s = Sequence{"T"}->union(Sequence{"i"}->union(Sequence{"m"}->union(Sequence{"r"}->union(Sequence{ "u" })))) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) name=input() if set(name)=={'T','i','m','u','r'}and n==5 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var name : String := (OclFile["System.in"]).readLine() ; if Set{}->union((name)) = Set{'T'}->union(Set{'i'}->union(Set{'m'}->union(Set{'u'}->union(Set{ 'r' })))) & n = 5 then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(n,s): if(n!=5): return "NO" a={'T' : 0,'i' : 0,'m' : 0,'u' : 0,'r' : 0} for i in range(5): if(s[i]not in a.keys()): return "NO" elif(a[s[i]]==1): return "NO" else : a[s[i]]=1 return "YES" t=int(input()) for i in range(t): n=int(input()) s=input() print(f(n,s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; s := (OclFile["System.in"]).readLine() ; execute (f(n, s))->display()); operation f(n : OclAny, s : OclAny) : OclAny pre: true post: true activity: if (n /= 5) then ( return "NO" ) else skip ; var a : Map := Map{ 'T' |-> 0 }->union(Map{ 'i' |-> 0 }->union(Map{ 'm' |-> 0 }->union(Map{ 'u' |-> 0 }->union(Map{ 'r' |-> 0 })))) ; for i : Integer.subrange(0, 5-1) do ( if ((a.keys())->excludes(s[i+1])) then ( return "NO" ) else (if (a[s[i+1]+1] = 1) then ( return "NO" ) else ( a[s[i+1]+1] := 1 ) ) ) ; return "YES"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b=map(int,input().split()) a=a-2 c=1 while a>0 : c+=1 a-=b print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : double := a - 2 ; var c : int := 1 ; while a > 0 do ( c := c + 1 ; a := a - b) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- case=input().split() buttons=int(case[0]) bulbs_num=int(case[1]) bulbs_on={} for i in range(buttons): case=input().split() case.pop(0) for j in range(len(case)): bulbs_on[case[j]]=0 if len(bulbs_on)!=bulbs_num : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var case : OclAny := input().split() ; var buttons : int := ("" + ((case->first())))->toInteger() ; var bulbs_num : int := ("" + ((case[1+1])))->toInteger() ; var bulbs_on : OclAny := Set{} ; for i : Integer.subrange(0, buttons-1) do ( case := input().split() ; case := case->excludingAt(0+1) ; for j : Integer.subrange(0, (case)->size()-1) do ( bulbs_on[case[j+1]+1] := 0)) ; if (bulbs_on)->size() /= bulbs_num then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): l=[int(i)for i in input().split(" ")] if l[0]<3 : print(1) elif(l[0]-2)% l[1]==0 : print((l[0]-2)//l[1]+1) else : print((l[0]-2)//l[1]+2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var l : Sequence := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if l->first() < 3 then ( execute (1)->display() ) else (if (l->first() - 2) mod l[1+1] = 0 then ( execute ((l->first() - 2) div l[1+1] + 1)->display() ) else ( execute ((l->first() - 2) div l[1+1] + 2)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math t=int(input()) for i in range(t): n,x=map(int,input().split()) if n<=2 : print(1) continue print(math.ceil((n-2)/x)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n <= 2 then ( execute (1)->display() ; continue ) else skip ; execute (((n - 2) / x)->ceil() + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): z,r=map(int,input().split()) z=z-2 l=1 while z>0 : l+=1 z-=r print(l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var z : OclAny := null; var r : OclAny := null; Sequence{z,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var z : double := z - 2 ; var l : int := 1 ; while z > 0 do ( l := l + 1 ; z := z - r) ; execute (l)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) d=0 for i in range(a): b,c=map(int,input().split()) if b>2 : if(b-2)% c==0 : d=(b-2)//c+1 else : d=(b-2)//c+2 else : d=1 print(d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : int := 0 ; for i : Integer.subrange(0, a-1) do ( var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if b > 2 then ( if (b - 2) mod c = 0 then ( d := (b - 2) div c + 1 ) else ( d := (b - 2) div c + 2 ) ) else ( d := 1 ) ; execute (d)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): return str(eulerlib.binomial(40,20)) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: return ("" + ((eulerlib.binomial(40, 20)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d,max_a=input().split() a=input().split() x=0 sum=0 for i in a : if int(i)>int(d): continue sum=sum+int(i) if sum>int(max_a): sum=0 x+=1 print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; var max_a : OclAny := null; Sequence{n,d,max_a} := input().split() ; var a : OclAny := input().split() ; var x : int := 0 ; var sum : int := 0 ; for i : a do ( if (("" + ((i)))->toInteger()->compareTo(("" + ((d)))->toInteger())) > 0 then ( continue ) else skip ; sum := sum + ("" + ((i)))->toInteger() ; if (sum->compareTo(("" + ((max_a)))->toInteger())) > 0 then ( sum := 0 ; x := x + 1 ) else skip) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left a=[1 for i in range(110001)] b=[] a[0]=0 a[1]=0 for i in range(2,110001): if(a[i]==1): for j in range(i*i,110001,i): a[j]=0 b+=[i] n,m=map(int,input().split()) a=[] for i in range(n): a+=[list(map(int,input().split()))] ma=9999999 for i in range(n): cnt=0 for j in range(m): x=bisect_left(b,a[i][j]) cnt+=b[x]-a[i][j] ma=min(ma,cnt) for i in range(m): cnt=0 for j in range(n): x=bisect_left(b,a[j][i]) cnt+=b[x]-a[j][i] ma=min(ma,cnt) print(ma) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : Sequence := Integer.subrange(0, 110001-1)->select(i | true)->collect(i | (1)) ; var b : Sequence := Sequence{} ; a->first() := 0 ; a[1+1] := 0 ; for i : Integer.subrange(2, 110001-1) do ( if (a[i+1] = 1) then ( for j : Integer.subrange(i * i, 110001-1)->select( $x | ($x - i * i) mod i = 0 ) do ( a[j+1] := 0) ; b := b + Sequence{ i } ) else skip) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := Sequence{} ; for i : Integer.subrange(0, n-1) do ( a := a + Sequence{ ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) }) ; var ma : int := 9999999 ; for i : Integer.subrange(0, n-1) do ( var cnt : int := 0 ; for j : Integer.subrange(0, m-1) do ( var x : OclAny := bisect_left(b, a[i+1][j+1]) ; cnt := cnt + b[x+1] - a[i+1][j+1]) ; ma := Set{ma, cnt}->min()) ; for i : Integer.subrange(0, m-1) do ( cnt := 0 ; for j : Integer.subrange(0, n-1) do ( x := bisect_left(b, a[j+1][i+1]) ; cnt := cnt + b[x+1] - a[j+1][i+1]) ; ma := Set{ma, cnt}->min()) ; execute (ma)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) limit=int(1e5+2) l=[1,1]+[0]*limit for i in range(2,limit): l[i*i : : i]=[1]*((limit-i*i)//i+1) for i in range(limit,-1,-1): l[i]*=l[i+1]+1 s=[[l[j]for j in map(int,input().split())]for _ in ' '*n] print(min(min(sum(i)for i in s),min(sum(i)for i in zip(*s)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var limit : int := ("" + ((("1e5")->toReal() + 2)))->toInteger() ; var l : Sequence := Sequence{1}->union(Sequence{ 1 })->union(MatrixLib.elementwiseMult(Sequence{ 0 }, limit)) ; for i : Integer.subrange(2, limit-1) do ( l(subscript (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom (name i))))))) : (sliceop : (test (logical_test (comparison (expr (atom (name i)))))))) := MatrixLib.elementwiseMult(Sequence{ 1 }, ((limit - i * i) div i + 1))) ; for i : Integer.subrange(-1 + 1, limit)->reverse() do ( l[i+1] := l[i+1] * l[i + 1+1] + 1) ; var s : Sequence := StringLib.nCopies(' ', n)->select(_anon | true)->collect(_anon | ((input().split())->collect( _x | (OclType["int"])->apply(_x) )->select(j | true)->collect(j | (l[j+1])))) ; execute (Set{((argument (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name s))))))))->min(), ((argument (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom (name s)))))))) )))))))))->min()}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt from collections import Counter import io,os,sys input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline p=Counter() p1=[2] def resheto(): global p1 for i in range(3,100011): for j in range(2,int(sqrt(i))+1): if i % j==0 : break else : p1+=[i] resheto() j=0 x=2 for i in range(1,100004): while i>x : j+=1 x=p1[j] p[i]=x n,m=map(int,input().split()) mn=1000005 flag=[0]*(m) for i in range(n): d=list(map(int,input().split())) kol=0 for j in range(m): kol+=p[d[j]]-d[j] flag[j]+=p[d[j]]-d[j] if i==n-1 : mn=min(mn,flag[j]) mn=min(kol,mn) sys.stdout.write(str(mn)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute p1 : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var p : OclAny := Counter() ; var p1 : Sequence := Sequence{ 2 } ; skip ; resheto() ; var j : int := 0 ; var x : int := 2 ; for i : Integer.subrange(1, 100004-1) do ( while (i->compareTo(x)) > 0 do ( j := j + 1 ; x := p1[j+1]) ; p[i+1] := x) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mn : int := 1000005 ; var flag : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (m)) ; for i : Integer.subrange(0, n-1) do ( var d : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var kol : int := 0 ; for j : Integer.subrange(0, m-1) do ( kol := kol + p[d[j+1]+1] - d[j+1] ; flag[j+1] := flag[j+1] + p[d[j+1]+1] - d[j+1] ; if i = n - 1 then ( mn := Set{mn, flag[j+1]}->min() ) else skip) ; mn := Set{kol, mn}->min()) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name mn)))))))) ))))))))) )))); operation resheto() pre: true post: true activity: skip ; for i : Integer.subrange(3, 100011-1) do ((compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sqrt)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))) )))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name i))) % (expr (atom (name j))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name p1)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name i))))))) ])))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def is_prime(x,primes): for i in primes : if i*i>x : break if x % i==0 : return False return True n,m=[int(x)for x in input().split()] a=[] primes=[] for i in range(2,110000): if is_prime(i,primes): primes.append(i) next=[0]*110000 next[0]=2 for x in primes : val=x while next[x]==0 : next[x]=val x-=1 for i in range(n): a.append([int(x)for x in input().split()]) for i in range(n): for j in range(m): a[i][j]=next[a[i][j]]-a[i][j] print(min(min(sum(x)for x in a),min(sum(x)for x in zip(*a)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a : Sequence := Sequence{} ; primes := Sequence{} ; for i : Integer.subrange(2, 110000-1) do ( if is_prime(i, primes) then ( execute ((i) : primes) ) else skip) ; var next : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 110000) ; ->first().next() := 2 ; for x : primes do ( var val : OclAny := x ; while [x+1].next() = 0 do ( [x+1].next() := val ; x := x - 1)) ; for i : Integer.subrange(0, n-1) do ( execute ((input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) : a)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( a[i+1][j+1] := [a[i+1][j+1]+1].next() - a[i+1][j+1])) ; execute (Set{((argument (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a))))))))->min(), ((argument (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom (name a)))))))) )))))))))->min()}->min())->display(); operation is_prime(x : OclAny, primes : OclAny) : OclAny pre: true post: true activity: for i : primes do ( if (i * i->compareTo(x)) > 0 then ( break ) else skip ; if x mod i = 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r1,c1,r2,c2=map(int,input().split()) mod=10**9+7 fc=[0]*(2*10**6+2) fc[0]=1 for i in range(1,2*10**6+2): fc[i]=fc[i-1]*i % mod inv=[1]*(2*10**6+2) lst=2*10**6+1 inv[lst]=pow(fc[lst],mod-2,mod) for i in range(lst,0,-1): inv[i-1]=(inv[i]*i)% mod def comb(n,r): return((fc[n]*inv[r])% mod)*inv[n-r]% mod cum=0 for i in range(r1,r2+1): d1=comb(i+1+c2,c2) d2=comb(i+c1,c1-1) cum=(cum+(d1-d2))% mod print(cum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r1 : OclAny := null; var c1 : OclAny := null; var r2 : OclAny := null; var c2 : OclAny := null; Sequence{r1,c1,r2,c2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mod : double := (10)->pow(9) + 7 ; var fc : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * (10)->pow(6) + 2)) ; fc->first() := 1 ; for i : Integer.subrange(1, 2 * (10)->pow(6) + 2-1) do ( fc[i+1] := fc[i - 1+1] * i mod mod) ; var inv : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (2 * (10)->pow(6) + 2)) ; var lst : double := 2 * (10)->pow(6) + 1 ; inv[lst+1] := (fc[lst+1])->pow(mod - 2) ; for i : Integer.subrange(0 + 1, lst)->reverse() do ( inv[i - 1+1] := (inv[i+1] * i) mod mod) ; skip ; var cum : int := 0 ; for i : Integer.subrange(r1, r2 + 1-1) do ( var d1 : OclAny := comb(i + 1 + c2, c2) ; var d2 : OclAny := comb(i + c1, c1 - 1) ; cum := (cum + (d1 - d2)) mod mod) ; execute (cum)->display(); operation comb(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: return ((fc[n+1] * inv[r+1]) mod mod) * inv[n - r+1] mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) sta=[0]*m for i in range(n): lights=list(int(i)for i in input().split()) for j in range(lights[0]): if sta[lights[j+1]-1]==0 : sta[lights[j+1]-1]=1 if sta.count(0)>0 : print('NO') else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sta : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; for i : Integer.subrange(0, n-1) do ( var lights : Sequence := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ; for j : Integer.subrange(0, lights->first()-1) do ( if sta[lights[j + 1+1] - 1+1] = 0 then ( sta[lights[j + 1+1] - 1+1] := 1 ) else skip)) ; if sta->count(0) > 0 then ( execute ('NO')->display() ) else ( execute ('YES')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cmb(n,r,mod): if(r<0 or r>n): return 0 r=min(r,n-r) return g1[n]*g2[r]*g2[n-r]% mod mod=10**9+7 N=3*10**6 g1=[1,1] g2=[1,1] inverse=[0,1] for i in range(2,N+1): g1.append((g1[-1]*i)% mod) inverse.append((-inverse[mod % i]*(mod//i))% mod) g2.append((g2[-1]*inverse[-1])% mod) r1,c1,r2,c2=map(int,input().split()) ans=cmb(r2+c2+2,c2+1,mod)-cmb(r2+c1+1,c1,mod)-cmb(r1+c2+1,c2+1,mod)+cmb(r1+c1,c1,mod) print(ans % mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; mod := (10)->pow(9) + 7 ; var N : double := 3 * (10)->pow(6) ; var g1 : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var g2 : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var inverse : Sequence := Sequence{0}->union(Sequence{ 1 }) ; for i : Integer.subrange(2, N + 1-1) do ( execute (((g1->last() * i) mod mod) : g1) ; execute (((-inverse[mod mod i+1] * (mod div i)) mod mod) : inverse) ; execute (((g2->last() * inverse->last()) mod mod) : g2)) ; var r1 : OclAny := null; var c1 : OclAny := null; var r2 : OclAny := null; var c2 : OclAny := null; Sequence{r1,c1,r2,c2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : double := cmb(r2 + c2 + 2, c2 + 1, mod) - cmb(r2 + c1 + 1, c1, mod) - cmb(r1 + c2 + 1, c2 + 1, mod) + cmb(r1 + c1, c1, mod) ; execute (ans mod mod)->display(); operation cmb(n : OclAny, r : OclAny, mod : OclAny) : OclAny pre: true post: true activity: if (r < 0 or (r->compareTo(n)) > 0) then ( return 0 ) else skip ; r := Set{r, n - r}->min() ; return g1[n+1] * g2[r+1] * g2[n - r+1] mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): import sys M=10**9+7 r1,c1,r2,c2=map(int,sys.stdin.buffer.readline().split()) n=r2+c2+2 val=1 fac=[val] append=fac.append for i in range(1,n+1): val=val*i % M append(val) pr1=pow(fac[r1],M-2,M) pc1=pow(fac[c1],M-2,M) pr2=pow(fac[r2+1],M-2,M) pc2=pow(fac[c2+1],M-2,M) print((fac[r2+c2+2]*pr2*pc2-fac[r2+c1+1]*pr2*pc1-fac[r1+c2+1]*pr1*pc2+fac[r1+c1]*pr1*pc1)% M) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: skip ; var M : double := (10)->pow(9) + 7 ; var r1 : OclAny := null; var c1 : OclAny := null; var r2 : OclAny := null; var c2 : OclAny := null; Sequence{r1,c1,r2,c2} := (sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : OclAny := r2 + c2 + 2 ; var val : int := 1 ; var fac : Sequence := Sequence{ val } ; var append : OclAny := fac.append ; for i : Integer.subrange(1, n + 1-1) do ( val := val * i mod M ; append(val)) ; var pr1 : double := (fac[r1+1])->pow(M - 2) ; var pc1 : double := (fac[c1+1])->pow(M - 2) ; var pr2 : double := (fac[r2 + 1+1])->pow(M - 2) ; var pc2 : double := (fac[c2 + 1+1])->pow(M - 2) ; execute ((fac[r2 + c2 + 2+1] * pr2 * pc2 - fac[r2 + c1 + 1+1] * pr2 * pc1 - fac[r1 + c2 + 1+1] * pr1 * pc2 + fac[r1 + c1+1] * pr1 * pc1) mod M)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.buffer.readline r1,c1,r2,c2=map(int,readline().split()) mod=10**9+7 def pow(n,p,mod=10**9+7): res=1 while p>0 : if p % 2==0 : n=n**2 % mod p//=2 else : res=res*n % mod p-=1 return res % mod def factrial_memo(n=3*10**6+1,mod=10**9+7): fact=[1,1] for i in range(2,n+1): fact.append((fact[-1]*i)% mod) return fact def fermat_cmb(n,r,mod=10**9+7): return fact[n]*pow(fact[r],mod-2)*pow(fact[n-r],mod-2)% mod fact=factrial_memo() r1,c1,r2,c2=r1+1,c1+1,r2+1,c2+1 al=fermat_cmb(r2+c2,r2) sub_r=fermat_cmb(r1-1+c2,r1-1) sub_c=fermat_cmb(r2+c1-1,c1-1) add_rc=fermat_cmb(r1-1+c1-1,r1-1) al-=sub_r+sub_c al+=add_rc print(al % mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := sys.stdin.buffer.readline ; var r1 : OclAny := null; var c1 : OclAny := null; var r2 : OclAny := null; var c2 : OclAny := null; Sequence{r1,c1,r2,c2} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; fact := factrial_memo() ; var r1 : OclAny := null; var c1 : OclAny := null; var r2 : OclAny := null; var c2 : OclAny := null; Sequence{r1,c1,r2,c2} := Sequence{r1 + 1,c1 + 1,r2 + 1,c2 + 1} ; var al : OclAny := fermat_cmb(r2 + c2, r2) ; var sub_r : OclAny := fermat_cmb(r1 - 1 + c2, r1 - 1) ; var sub_c : OclAny := fermat_cmb(r2 + c1 - 1, c1 - 1) ; var add_rc : OclAny := fermat_cmb(r1 - 1 + c1 - 1, r1 - 1) ; al := al - sub_r + sub_c ; al := al + add_rc ; execute (al mod mod)->display(); operation pow(n : OclAny, p : OclAny, mod : OclAny) : OclAny pre: true post: true activity: if mod->oclIsUndefined() then mod := (10)->pow(9) + 7 else skip; var res : int := 1 ; while p > 0 do ( if p mod 2 = 0 then ( n := (n)->pow(2) mod mod ; p := p div 2 ) else ( res := res * n mod mod ; p := p - 1 )) ; return res mod mod; operation factrial_memo(n : OclAny, mod : OclAny) : OclAny pre: true post: true activity: if n->oclIsUndefined() then n := 3 * (10)->pow(6) + 1 else skip; if mod->oclIsUndefined() then mod := (10)->pow(9) + 7 else skip; var fact : Sequence := Sequence{1}->union(Sequence{ 1 }) ; for i : Integer.subrange(2, n + 1-1) do ( execute (((fact->last() * i) mod mod) : fact)) ; return fact; operation fermat_cmb(n : OclAny, r : OclAny, mod : OclAny) : OclAny pre: true post: true activity: if mod->oclIsUndefined() then mod := (10)->pow(9) + 7 else skip; return fact[n+1] * (fact[r+1])->pow(mod - 2) * (fact[n - r+1])->pow(mod - 2) mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Factorial : def __init__(self,n,mod): self.f=f=[0]*(n+1) f[0]=b=1 self.mod=mod for i in range(1,n+1): f[i]=b=b*i % mod self.inv=inv=[0]*(n+1) inv[0]=b=pow(self.f[n],mod-2,mod) for i in range(1,n+1): inv[i]=b=b*(n+1-i)% mod self.inv.reverse() def factorial(self,i): return self.f[i] def ifactorial(self,i): return self.inv[i] def comb(self,n,k): return self.f[n]*self.inv[n-k]% self.mod*self.inv[k]% self.mod if n>=k else 0 M=10**9+7 a,b,c,d=map(int,input().split()) comb=Factorial(c+d+2,M).comb f=lambda r,c : comb(c+r+2,r+1)-c-r-2 print((f(c,d)-f(c,b-1)-f(a-1,d)+f(a-1,b-1))% M) ------------------------------------------------------------ OCL File: --------- class Factorial { static operation newFactorial() : Factorial pre: true post: Factorial->exists( _x | result = _x ); attribute f : OclAny := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); var f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); attribute mod : OclAny := mod; attribute inv : OclAny := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); var inv : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); operation initialise(n : OclAny,mod : OclAny) : Factorial pre: true post: true activity: self.f := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); var f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; f->first() := 1; var b : int := 1 ; self.mod := mod ; for i : Integer.subrange(1, n + 1-1) do ( f[i+1] := b * i mod mod; b := b * i mod mod) ; self.inv := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); var inv : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; inv->first() := (self.f[n+1])->pow(mod - 2); b := (self.f[n+1])->pow(mod - 2) ; for i : Integer.subrange(1, n + 1-1) do ( inv[i+1] := b * (n + 1 - i) mod mod; b := b * (n + 1 - i) mod mod) ; (expr (atom (name self)) (trailer . (name inv)) (trailer . (name reverse) (arguments ( )))); return self; operation factorial(i : OclAny) : OclAny pre: true post: true activity: return self.f[i+1]; operation ifactorial(i : OclAny) : OclAny pre: true post: true activity: return self.inv[i+1]; operation comb(n : OclAny,k : OclAny) : OclAny pre: true post: true activity: return if (n->compareTo(k)) >= 0 then self.f[n+1] * self.inv[n - k+1] mod self.mod * self.inv[k+1] mod self.mod else 0 endif; } class FromPython { operation initialise() pre: true post: true activity: skip ; var M : double := (10)->pow(9) + 7 ; var a : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var comb : OclAny := Factorial(c + d + 2, M).comb ; f := lambda r : OclAny, c : OclAny in (comb(c + r + 2, r + 1) - c - r - 2) ; execute ((f(c, d) - f(c, b - 1) - f(a - 1, d) + f(a - 1, b - 1)) mod M)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,b,d=input().split() x=list(map(int,input().split())) c,z=0,0 for i in range(len(x)): if x[i]<=int(b): c+=x[i] if c>int(d): z+=1 c=0 print(z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var b : OclAny := null; var d : OclAny := null; Sequence{n,b,d} := input().split() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : OclAny := null; var z : OclAny := null; Sequence{c,z} := Sequence{0,0} ; for i : Integer.subrange(0, (x)->size()-1) do ( if (x[i+1]->compareTo(("" + ((b)))->toInteger())) <= 0 then ( c := c + x[i+1] ) else skip ; if (c->compareTo(("" + ((d)))->toInteger())) > 0 then ( z := z + 1 ; var c : int := 0 ) else skip) ; execute (z)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import* from itertools import* from bisect import* import copy n,k=map(int,input().split()) mod=10**9+7 fac=[0,1] for i in range(2,2*n+1): fac.append(fac[i-1]*i % mod) ifac=[pow(i,mod-2,mod)for i in fac] def comb(a,b): if a>=0 and b==0 : return(1) if acollect( _x | (OclType["int"])->apply(_x) ) ; var mod : double := (10)->pow(9) + 7 ; var fac : Sequence := Sequence{0}->union(Sequence{ 1 }) ; for i : Integer.subrange(2, 2 * n + 1-1) do ( execute ((fac[i - 1+1] * i mod mod) : fac)) ; var ifac : Sequence := fac->select(i | true)->collect(i | ((i)->pow(mod - 2))) ; skip ; var count : int := 1 ; for m : Integer.subrange(1, Set{k + 1, n}->min()-1) do ( count := (count + comb(n, m) * comb(n - 1, n - m - 1)) mod mod) ; execute (count)->display(); operation comb(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a >= 0 & b = 0 then ( return (1) ) else skip ; if (a->compareTo(b)) < 0 or a < 0 then ( return (0) ) else skip ; return ((fac[a+1] * ifac[a - b+1] * ifac[b+1]) mod mod); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,bisect,math,itertools,heapq,collections from operator import itemgetter from functools import lru_cache sys.setrecursionlimit(10**8) input=sys.stdin.readline INF=float('inf') mod=10**9+7 eps=10**-7 def inp(): return int(input()) def inpl(): return list(map(int,input().split())) class combination(): def __init__(self,mod): self.mod=mod self.fac=[1,1] self.ifac=[1,1] self.inv=[0,1] def calc(self,n,k): if k<0 or nexists( _x | result = _x ); attribute mod : OclAny := mod; attribute fac : Sequence := Sequence{1}->union(Sequence{ 1 }); attribute ifac : Sequence := Sequence{1}->union(Sequence{ 1 }); attribute inv : Sequence := Sequence{0}->union(Sequence{ 1 }); operation initialise(mod : OclAny) : pre: true post: true activity: self.mod := mod ; self.fac := Sequence{1}->union(Sequence{ 1 }) ; self.ifac := Sequence{1}->union(Sequence{ 1 }) ; self.inv := Sequence{0}->union(Sequence{ 1 }); return self; operation calc(n : OclAny,k : OclAny) : OclAny pre: true post: true activity: if k < 0 or (n->compareTo(k)) < 0 then ( return 0 ) else skip ; self.make_tables(n) ; k := Set{k, n - k}->min() ; return self.fac[n+1] * (self.ifac[k+1] * self.ifac[n - k+1] mod self.mod) mod self.mod; operation make_tables(n : OclAny) pre: true post: true activity: for i : Integer.subrange((self.fac)->size(), n + 1-1) do ((expr (atom (name self)) (trailer . (name fac)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name self)) (trailer . (name fac) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))) * (expr (atom (name i)))))))) ))) % (expr (atom (name self)) (trailer . (name mod))))))))) )))) ; (expr (atom (name self)) (trailer . (name inv)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr - (expr (atom (name self)) (trailer . (name inv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name self)) (trailer . (name mod))) % (expr (atom (name i))))))))) ])))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name self)) (trailer . (name mod))) // (expr (atom (name i)))))))) )))))))) ))) % (expr (atom (name self)) (trailer . (name mod))))))))) )))) ; (expr (atom (name self)) (trailer . (name ifac)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name self)) (trailer . (name ifac) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))) * (expr (atom (name self)) (trailer . (name inv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))))) ))) % (expr (atom (name self)) (trailer . (name mod))))))))) ))))); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; var input : OclAny := (OclFile["System.in"]).readline ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var eps : double := (10)->pow(-7) ; skip ; skip ; skip ; var comb : combination := (combination.newcombination()).initialise(mod) ; Sequence{n,k} := inpl() ; var ans : int := 0 ; for m : Integer.subrange(0, Set{n, k + 1}->min()-1) do ( var a : int := comb.calc(n, m) mod mod ; var b : int := comb.calc(n - 1, n - m - 1) mod mod ; ans := ans + a * b mod mod) ; execute (ans mod mod)->display(); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) mod=1000000007 b=mod-2 blis=[] c=0 while b>0 : if b & 1==1 : blis.append(c) c+=1 b>>=1 def modinv(a): if a==1 : return 1 else : res=1 li=[] for _ in range(c): li.append(a % mod) a=a*a % mod for item in blis : res=res*li[item]% mod return res if k>=n : L=2*n-1 ansbunsi=1 for j in range(n-1): ansbunsi=ansbunsi*L % mod L-=1 ansbunbo=1 L=n-1 for j in range(n-1): ansbunbo=ansbunbo*L % mod L-=1 ansbunbo=modinv(ansbunbo) print(ansbunsi*ansbunbo % mod) else : kaijou=[1,1] for j in range(2,n+1): kaijou.append(kaijou[-1]*j % mod) ans=0 for m in range(k+1): ansbunsi=kaijou[n]*kaijou[n-1]% mod ansbunbo=kaijou[m]*kaijou[n-m]% mod ansbunbo=ansbunbo*kaijou[n-m-1]% mod ansbunbo=ansbunbo*kaijou[m]% mod ansbunbo=modinv(ansbunbo) ans+=ansbunbo*ansbunsi ans %=mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mod : int := 1000000007 ; var b : double := mod - 2 ; var blis : Sequence := Sequence{} ; var c : int := 0 ; while b > 0 do ( if MathLib.bitwiseAnd(b, 1) = 1 then ( execute ((c) : blis) ) else skip ; c := c + 1 ; b := b div (2->pow(1))) ; skip ; if (k->compareTo(n)) >= 0 then ( var L : double := 2 * n - 1 ; var ansbunsi : int := 1 ; for j : Integer.subrange(0, n - 1-1) do ( ansbunsi := ansbunsi * L mod mod ; L := L - 1) ; var ansbunbo : int := 1 ; L := n - 1 ; for j : Integer.subrange(0, n - 1-1) do ( ansbunbo := ansbunbo * L mod mod ; L := L - 1) ; ansbunbo := modinv(ansbunbo) ; execute (ansbunsi * ansbunbo mod mod)->display() ) else ( var kaijou : Sequence := Sequence{1}->union(Sequence{ 1 }) ; for j : Integer.subrange(2, n + 1-1) do ( execute ((kaijou->last() * j mod mod) : kaijou)) ; var ans : int := 0 ; for m : Integer.subrange(0, k + 1-1) do ( ansbunsi := kaijou[n+1] * kaijou[n - 1+1] mod mod ; ansbunbo := kaijou[m+1] * kaijou[n - m+1] mod mod ; ansbunbo := ansbunbo * kaijou[n - m - 1+1] mod mod ; ansbunbo := ansbunbo * kaijou[m+1] mod mod ; ansbunbo := modinv(ansbunbo) ; ans := ans + ansbunbo * ansbunsi ; ans := ans mod mod) ; execute (ans)->display() ); operation modinv(a : OclAny) : OclAny pre: true post: true activity: if a = 1 then ( return 1 ) else ( var res : int := 1 ; var li : Sequence := Sequence{} ; for _anon : Integer.subrange(0, c-1) do ( execute ((a mod mod) : li) ; a := a * a mod mod) ; for item : blis do ( res := res * li[item+1] mod mod) ; return res ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from functools import reduce from collections import deque import sys sys.setrecursionlimit(10**7) def get_nums_l(): return[int(s)for s in input().split(" ")] def get_nums_n(n): return[int(input())for _ in range(n)] def get_all_int(): return map(int,open(0).read().split()) def log(*args): print("DEBUG:",*args,file=sys.stderr) def inv(x): return pow(x,MOD-2,MOD) def nPk(n,k): return kaijo[n]*inv(kaijo[n-k])% MOD def nCk(n,k): return nPk(n,k)*inv(kaijo[k]) MOD=10**9+7 kaijo=[0]*400020 kaijo[0]=1 for i in range(1,len(kaijo)): kaijo[i]=kaijo[i-1]*i % MOD n,k=get_nums_l() if k>=n-1 : print(nCk(n+n-1,n)% MOD) exit() ans=1 for z in range(1,k+1): ans+=nCk(n,z)*nCk(n-1,z) print(ans % MOD) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var MOD : double := (10)->pow(9) + 7 ; var kaijo : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 400020) ; kaijo->first() := 1 ; for i : Integer.subrange(1, (kaijo)->size()-1) do ( kaijo[i+1] := kaijo[i - 1+1] * i mod MOD) ; Sequence{n,k} := get_nums_l() ; if (k->compareTo(n - 1)) >= 0 then ( execute (nCk(n + n - 1, n) mod MOD)->display() ; exit() ) else skip ; var ans : int := 1 ; for z : Integer.subrange(1, k + 1-1) do ( ans := ans + nCk(n, z) * nCk(n - 1, z)) ; execute (ans mod MOD)->display(); operation get_nums_l() : OclAny pre: true post: true activity: return input().split(" ")->select(s | true)->collect(s | (("" + ((s)))->toInteger())); operation get_nums_n(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())); operation get_all_int() : OclAny pre: true post: true activity: return (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ); operation log(args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) execute ("DEBUG:")->display(); operation inv(x : OclAny) : OclAny pre: true post: true activity: return (x)->pow(MOD - 2); operation nPk(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: return kaijo[n+1] * inv(kaijo[n - k+1]) mod MOD; operation nCk(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: return nPk(n, k) * inv(kaijo[k+1]); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=list(map(int,input().split())) MAX=200001 MOD=1000000007 fac=[0 for i in range(MAX)] finv=[0 for i in range(MAX)] inv=[0 for i in range(MAX)] com=[1 for i in range(MAX)] def cominit(): fac[0]=fac[1]=1 finv[0]=finv[1]=1 inv[1]=1 com[1]=n for i in range(2,MAX): fac[i]=fac[i-1]*i % MOD inv[i]=MOD-inv[MOD % i]*int(MOD/i)% MOD finv[i]=finv[i-1]*inv[i]% MOD com[i]=com[i-1]*(n-(i-1))*inv[i]% MOD return fac,finv,inv,com temp=cominit() k_1=k % 2 ans=0 for x in range(0,k+1): if(x>=n): break y=n-x ans+=(com[x]*fac[n-1]*finv[x]*finv[y-1])% MOD print(ans % MOD) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var MAX : int := 200001 ; var MOD : int := 1000000007 ; var fac : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)) ; var finv : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)) ; var inv : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)) ; var com : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (1)) ; skip ; var temp : OclAny := cominit() ; var k var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) : int := k mod 2 ; var ans : int := 0 ; for x : Integer.subrange(0, k + 1-1) do ( if ((x->compareTo(n)) >= 0) then ( break ) else skip ; var y : double := n - x ; ans := ans + (com[x+1] * fac[n - 1+1] * finv[x+1] * finv[y - 1+1]) mod MOD) ; execute (ans mod MOD)->display(); operation cominit() : OclAny pre: true post: true activity: fac->first() := 1; var fac[1+1] : int := 1 ; finv->first() := 1; var finv[1+1] : int := 1 ; inv[1+1] := 1 ; com[1+1] := n ; for i : Integer.subrange(2, MAX-1) do ( fac[i+1] := fac[i - 1+1] * i mod MOD ; inv[i+1] := MOD - inv[MOD mod i+1] * ("" + ((MOD / i)))->toInteger() mod MOD ; finv[i+1] := finv[i - 1+1] * inv[i+1] mod MOD ; com[i+1] := com[i - 1+1] * (n - (i - 1)) * inv[i+1] mod MOD) ; return fac, finv, inv, com; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt MAX=100005 def precompute(prefix,suffix): prime=[True for i in range(MAX)] k=int(sqrt(MAX)) for i in range(2,k,1): if(prime[i]): for j in range(i+i,MAX,i): prime[j]=False prefix[1]=1 suffix[MAX-1]=int(1e9+7) for i in range(2,MAX,1): if(prime[i]): prefix[i]=i else : prefix[i]=prefix[i-1] i=MAX-2 while(i>1): if(prime[i]): suffix[i]=i else : suffix[i]=suffix[i+1] i-=1 def query(prefix,suffix,L,R): if(prefix[R]R): return 0 else : return prefix[R]-suffix[L] if __name__=='__main__' : q=3 L=[2,2,24] R=[5,2,28] prefix=[0 for i in range(MAX)] suffix=[0 for i in range(MAX)] precompute(prefix,suffix) for i in range(0,q,1): print(query(prefix,suffix,L[i],R[i])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MAX : int := 100005 ; skip ; skip ; if __name__ = '__main__' then ( var q : int := 3 ; L := Sequence{2}->union(Sequence{2}->union(Sequence{ 24 })) ; R := Sequence{5}->union(Sequence{2}->union(Sequence{ 28 })) ; prefix := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)) ; suffix := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)) ; precompute(prefix, suffix) ; for i : Integer.subrange(0, q-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( execute (query(prefix, suffix, L[i+1], R[i+1]))->display()) ) else skip; operation precompute(prefix : OclAny, suffix : OclAny) pre: true post: true activity: var prime : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (true)) ; var k : int := ("" + ((sqrt(MAX))))->toInteger() ; for i : Integer.subrange(2, k-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (prime[i+1]) then ( for j : Integer.subrange(i + i, MAX-1)->select( $x | ($x - i + i) mod i = 0 ) do ( prime[j+1] := false) ) else skip) ; prefix[1+1] := 1 ; suffix[MAX - 1+1] := ("" + ((("1e9")->toReal() + 7)))->toInteger() ; for i : Integer.subrange(2, MAX-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (prime[i+1]) then ( prefix[i+1] := i ) else ( prefix[i+1] := prefix[i - 1+1] )) ; var i : double := MAX - 2 ; while (i > 1) do ( if (prime[i+1]) then ( suffix[i+1] := i ) else ( suffix[i+1] := suffix[i + 1+1] ) ; i := i - 1); operation query(prefix : OclAny, suffix : OclAny, L : OclAny, R : OclAny) : OclAny pre: true post: true activity: if ((prefix[R+1]->compareTo(L)) < 0 or (suffix[L+1]->compareTo(R)) > 0) then ( return 0 ) else ( return prefix[R+1] - suffix[L+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_right n,d=map(int,input().split()) a=sorted(list(map(int,input().split()))) cnt=0 for i in range(n-2): x=bisect_right(a,a[i]+d) if(x-i>2): x=x-i-2 cnt+=x*(x+1)//2 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var cnt : int := 0 ; for i : Integer.subrange(0, n - 2-1) do ( var x : OclAny := bisect_right(a, a[i+1] + d) ; if (x - i > 2) then ( x := x - i - 2 ; cnt := cnt + x * (x + 1) div 2 ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- V_SUM_MAX=1000 N_MAX=100 W_MAX=10000000 dp=[[0 for i in range(N_MAX)]for i in range(V_SUM_MAX+1)] v=[[0 for i in range(N_MAX)]for i in range(V_SUM_MAX+1)] def solveDp(r,i,w,val,n): if(r<=0): return 0 if(i==n): return W_MAX if(v[r][i]): return dp[r][i] v[r][i]=1 dp[r][i]=min(solveDp(r,i+1,w,val,n),w[i]+solveDp(r-val[i],i+1,w,val,n)) return dp[r][i] def maxWeight(w,val,n,c): for i in range(V_SUM_MAX,-1,-1): if(solveDp(i,0,w,val,n)<=c): return i return 0 if __name__=='__main__' : w=[3,4,5] val=[30,50,60] n=len(w) C=8 print(maxWeight(w,val,n,C)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var V_SUM_MAX : int := 1000 ; var N_MAX : int := 100 ; var W_MAX : int := 10000000 ; var dp : Sequence := Integer.subrange(0, V_SUM_MAX + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, N_MAX-1)->select(i | true)->collect(i | (0)))) ; var v : Sequence := Integer.subrange(0, V_SUM_MAX + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, N_MAX-1)->select(i | true)->collect(i | (0)))) ; skip ; skip ; if __name__ = '__main__' then ( w := Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })) ; val := Sequence{30}->union(Sequence{50}->union(Sequence{ 60 })) ; n := (w)->size() ; var C : int := 8 ; execute (maxWeight(w, val, n, C))->display() ) else skip; operation solveDp(r : OclAny, i : OclAny, w : OclAny, val : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (r <= 0) then ( return 0 ) else skip ; if (i = n) then ( return W_MAX ) else skip ; if (v[r+1][i+1]) then ( return dp[r+1][i+1] ) else skip ; v[r+1][i+1] := 1 ; dp[r+1][i+1] := Set{solveDp(r, i + 1, w, val, n), w[i+1] + solveDp(r - val[i+1], i + 1, w, val, n)}->min() ; return dp[r+1][i+1]; operation maxWeight(w : OclAny, val : OclAny, n : OclAny, c : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(-1 + 1, V_SUM_MAX)->reverse() do ( if ((solveDp(i, 0, w, val, n)->compareTo(c)) <= 0) then ( return i ) else skip) ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) arr=list(map(int,input().split())) temp=arr[-1] for i in range(n-1,-1,-1): temp=max(temp,arr[i]) if temp : arr[i]=1 else : arr[i]=0 temp-=1 print(*arr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var temp : OclAny := arr->last() ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( temp := Set{temp, arr[i+1]}->max() ; if temp then ( arr[i+1] := 1 ) else ( arr[i+1] := 0 ) ; temp := temp - 1) ; execute ((argument * (test (logical_test (comparison (expr (atom (name arr))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys arr=[0]*200_000 out=[False]*200_000 for _ in range(int(input())): n=int(input()) for(i,x)in enumerate(input().split()): arr[i]=int(x) cur=0 for i in range(n-1,-1,-1): if arr[i]>cur : cur=arr[i] if cur==0 : out[i]=False else : out[i]=True cur-=1 for i in range(n): sys.stdout.write("1 " if out[i]else "0 ") sys.stdout.write("\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 200)_000 ; var out : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, 200)_000 ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for Sequence{i, x} : Integer.subrange(1, (input().split())->size())->collect( _indx | Sequence{_indx-1, (input().split())->at(_indx)} ) do ( arr[i+1] := ("" + ((x)))->toInteger()) ; var cur : int := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (arr[i+1]->compareTo(cur)) > 0 then ( cur := arr[i+1] ) else skip ; if cur = 0 then ( out[i+1] := false ) else ( out[i+1] := true ) ; cur := cur - 1) ; for i : Integer.subrange(0, n-1) do ((expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "1 ")))) if (logical_test (comparison (expr (atom (name out)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))) else (test (logical_test (comparison (expr (atom "0 ")))))))) ))))) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n"))))))) ))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numberoranges,maxisize,wastesection=[int(x)for x in input().split()] oranges=[int(x)for x in input().split()] wasted=0 pressed=0 for orange in oranges : if orange<=maxisize : pressed+=orange if pressed>wastesection : wasted+=1 pressed=0 print(wasted) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var numberoranges : OclAny := null; var maxisize : OclAny := null; var wastesection : OclAny := null; Sequence{numberoranges,maxisize,wastesection} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var oranges : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var wasted : int := 0 ; var pressed : int := 0 ; for orange : oranges do ( if (orange->compareTo(maxisize)) <= 0 then ( pressed := pressed + orange ; if (pressed->compareTo(wastesection)) > 0 then ( wasted := wasted + 1 ; pressed := 0 ) else skip ) else skip) ; execute (wasted)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : t-=1 n=int(input()) a=[int(x)for x in input().split()] cream=a[-1] ans=[] for i in range(0,len(a)): j=len(a)-i-1 cream=max(cream,a[j]) if cream>0 : cream-=1 ans.append("1") else : ans.append("0") ans.reverse() ans=" ".join(ans) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( t := t - 1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var cream : OclAny := a->last() ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, (a)->size()-1) do ( var j : double := (a)->size() - i - 1 ; cream := Set{cream, a[j+1]}->max() ; if cream > 0 then ( cream := cream - 1 ; execute (("1") : ans) ) else ( execute (("0") : ans) )) ; ans := ans->reverse() ; ans := StringLib.sumStringsWithSeparator((ans), " ") ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) ans=[] c=a[-1] for i in range(n-1,-1,-1): c=max(c,a[i]) if c>0 : c-=1 ans.append(1) else : ans.append(0) ans.reverse() print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : Sequence := Sequence{} ; var c : OclAny := a->last() ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( c := Set{c, a[i+1]}->max() ; if c > 0 then ( c := c - 1 ; execute ((1) : ans) ) else ( execute ((0) : ans) )) ; ans := ans->reverse() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findValues(a,b): if((a-b)% 2==1): print("-1"); return ; print((a-b)//2,(a+b)//2); a=12 ; b=8 ; findValues(a,b); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 12; b := 8; ; findValues(a, b);; operation findValues(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if ((a - b) mod 2 = 1) then ( execute ("-1")->display(); ; return; ) else skip ; execute ((a - b) div 2)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) import sys input=sys.stdin.readline A=[[int(j)for j in input().split()]for _ in range(N)] ans=0 bridge=[[False]*(N)for i in range(N)] for k in range(N): for i in range(N): for j in range(N): if i>=j : continue if A[i][j]>A[i][k]+A[k][j]: print(-1) exit(0) for i in range(N): for j in range(N): if i>=j : continue if all(A[i][j]toInteger() ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var A : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger())))) ; var ans : int := 0 ; var bridge : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ false }, (N)))) ; for k : Integer.subrange(0, N-1) do ( for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( if (i->compareTo(j)) >= 0 then ( continue ) else skip ; if (A[i+1][j+1]->compareTo(A[i+1][k+1] + A[k+1][j+1])) > 0 then ( execute (-1)->display() ; exit(0) ) else skip))) ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( if (i->compareTo(j)) >= 0 then ( continue ) else skip ; if ((argument (test (logical_test (comparison (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) < (comparison (expr (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ]))) + (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) (comp_for for (exprlist (expr (atom (name k)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))) (comp_iter if (test (logical_test (logical_test (comparison (comparison (expr (atom (name k)))) != (comparison (expr (atom (name i)))))) and (logical_test (comparison (comparison (expr (atom (name k)))) != (comparison (expr (atom (name j))))))))))))->forAll( _x | _x = true ) then ( if not(bridge[i+1][j+1]) then ( ans := ans + A[i+1][j+1] ; bridge[i+1][j+1] := true ) else skip ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def inpl(): return[int(i)for i in input().split()] import sys import numpy N=int(input()) A=numpy.asarray([inpl()for _ in range(N)]) ans=0 for i in range(N): A[i][i]=10**9+1 for i in range(N): for j in range(i): mindis=numpy.min([A[i]+A[j]]) if mindis>A[i][j]: ans+=A[i][j] continue if mindistoInteger() ; var A : Sequence := ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( A[i+1][i+1] := (10)->pow(9) + 1) ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, i-1) do ( var mindis : (trailer . (name min) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) ]))))))) ))) := ; if (mindis->compareTo(A[i+1][j+1])) > 0 then ( ans := ans + A[i+1][j+1] ; continue ) else skip ; if (mindis->compareTo(A[i+1][j+1])) < 0 then ( execute (-1)->display() ; sys.exit() ) else skip)) ; execute (ans)->display(); operation inpl() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy def warshall_floyd(d): for k in range(n): for i in range(n): for j in range(n): d[i][j]=min(d[i][j],d[i][k]+d[k][j]) n=int(input()) a=[[]for i in range(n)] war=[[]for i in range(n)] for i in range(n): a[i]=list(map(int,input().split())) war=copy.deepcopy(a) for i in range(n): if a[i][i]!=0 : print(-1) exit() warshall_floyd(war) res=0 for i in range(n): for j in range(n): if war[i][j]toInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; var war : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, n-1) do ( a[i+1] := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; war := copy.deepcopy(a) ; for i : Integer.subrange(0, n-1) do ( if a[i+1][i+1] /= 0 then ( execute (-1)->display() ; exit() ) else skip) ; warshall_floyd(war) ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if (war[i+1][j+1]->compareTo(a[i+1][j+1])) < 0 then ( execute (-1)->display() ; exit() ) else (if war[i+1][j+1] = a[i+1][j+1] then ( var judge : int := 1 ; for h : Integer.subrange(0, n-1) do ( if h /= i & h /= j & war[i+1][h+1] + war[h+1][j+1] = war[i+1][j+1] then ( judge := -1 ) else skip) ; if judge = 1 then ( res := res + war[i+1][j+1] ) else skip ) else skip))) ; execute (res div 2)->display(); operation warshall_floyd(d : OclAny) pre: true post: true activity: for k : Integer.subrange(0, n-1) do ( for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( d[i+1][j+1] := Set{d[i+1][j+1], d[i+1][k+1] + d[k+1][j+1]}->min()))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.buffer.readline from collections import defaultdict import copy INF=float("inf") def getlist(): return list(map(int,input().split())) def build(d,n): cost=0 for k in range(n): for i in range(n): for j in range(n): if d[i][j]==d[i][k]+d[k][j]and k!=i and k!=j : d[i][j]=INF return d def judge(d,n): for k in range(n): for i in range(n): for j in range(n): d[i][j]=min(d[i][j],d[i][k]+d[k][j]) return d def main(): N=int(input()) d=[] for i in range(N): g=getlist() d.append(g) d2=copy.deepcopy(d) d2=judge(d2,N) if d!=d2 : print(-1) else : X=build(d2,N) ans=0 for i in range(N): for j in range(N): if d2[i][j]!=INF : ans+=d2[i][j] print(ans//2) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := sys.stdin.buffer.readline ; skip ; skip ; var INF : double := ("" + (("inf")))->toReal() ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation getlist() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation build(d : OclAny, n : OclAny) : OclAny pre: true post: true activity: var cost : int := 0 ; for k : Integer.subrange(0, n-1) do ( for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if d[i+1][j+1] = d[i+1][k+1] + d[k+1][j+1] & k /= i & k /= j then ( d[i+1][j+1] := INF ) else skip))) ; return d; operation judge(d : OclAny, n : OclAny) : OclAny pre: true post: true activity: for k : Integer.subrange(0, n-1) do ( for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( d[i+1][j+1] := Set{d[i+1][j+1], d[i+1][k+1] + d[k+1][j+1]}->min()))) ; return d; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; d := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var g : OclAny := getlist() ; execute ((g) : d)) ; var d2 : OclAny := copy.deepcopy(d) ; d2 := judge(d2, N) ; if d /= d2 then ( execute (-1)->display() ) else ( var X : OclAny := build(d2, N) ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( if d2[i+1][j+1] /= INF then ( ans := ans + d2[i+1][j+1] ) else skip)) ; execute (ans div 2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def f(n): return(n*(n-1))//2 input=sys.stdin.readline n,d=[int(i)for i in input().split()] a=[int(i)for i in input().split()] j=0 ans=0 for i in range(2,n): while a[i]-a[j]>d : j+=1 if a[i]-a[j]<=d and i-j+1>=3 : ans+=f(i-j) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var d : OclAny := null; Sequence{n,d} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var j : int := 0 ; var ans : int := 0 ; for i : Integer.subrange(2, n-1) do ( while (a[i+1] - a[j+1]->compareTo(d)) > 0 do ( j := j + 1) ; if (a[i+1] - a[j+1]->compareTo(d)) <= 0 & i - j + 1 >= 3 then ( ans := ans + f(i - j) ) else skip) ; execute (ans)->display(); operation f(n : OclAny) : OclAny pre: true post: true activity: return (n * (n - 1)) div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) table=[] for i in range(n): table.append([int(_)for _ in input().split()]) T=[[1]*n for i in range(n)] import itertools chk,ans=True,0 for Com in itertools.combinations(range(n),3): a,b,c=Com[0],Com[1],Com[2] lab,lbc,lca=table[a][b],table[b][c],table[c][a] if lab>=lbc and lab>=lca : if lab>lbc+lca : chk=False elif lab==lbc+lca : T[a][b],T[b][a]=0,0 elif lbc>=lab and lbc>=lca : if lbc>lab+lca : chk=False elif lbc==lab+lca : T[b][c],T[c][b]=0,0 elif lca>=lab and lca>=lbc : if lca>lab+lbc : chk=False elif lca==lab+lbc : T[c][a],T[a][c]=0,0 for i in range(n): for j in range(i+1,n): if T[i][j]==1 : ans+=table[i][j] print(ans if chk==True else-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var table : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger()))) : table)) ; var T : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 1 }, n))) ; skip ; var chk : OclAny := null; var ans : OclAny := null; Sequence{chk,ans} := Sequence{true,0} ; for Com : itertools.combinations(Integer.subrange(0, n-1), 3) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{Com->first(),Com[1+1],Com[2+1]} ; var lab : OclAny := null; var lbc : OclAny := null; var lca : OclAny := null; Sequence{lab,lbc,lca} := Sequence{table[a+1][b+1],table[b+1][c+1],table[c+1][a+1]} ; if (lab->compareTo(lbc)) >= 0 & (lab->compareTo(lca)) >= 0 then ( if (lab->compareTo(lbc + lca)) > 0 then ( var chk : boolean := false ) else (if lab = lbc + lca then ( var T[a+1][b+1] : OclAny := null; var T[b+1][a+1] : OclAny := null; Sequence{T[a+1][b+1],T[b+1][a+1]} := Sequence{0,0} ) else skip) ) else (if (lbc->compareTo(lab)) >= 0 & (lbc->compareTo(lca)) >= 0 then ( if (lbc->compareTo(lab + lca)) > 0 then ( chk := false ) else (if lbc = lab + lca then ( var T[b+1][c+1] : OclAny := null; var T[c+1][b+1] : OclAny := null; Sequence{T[b+1][c+1],T[c+1][b+1]} := Sequence{0,0} ) else skip) ) else (if (lca->compareTo(lab)) >= 0 & (lca->compareTo(lbc)) >= 0 then ( if (lca->compareTo(lab + lbc)) > 0 then ( chk := false ) else (if lca = lab + lbc then ( var T[c+1][a+1] : OclAny := null; var T[a+1][c+1] : OclAny := null; Sequence{T[c+1][a+1],T[a+1][c+1]} := Sequence{0,0} ) else skip) ) else skip ) ) ) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if T[i+1][j+1] = 1 then ( ans := ans + table[i+1][j+1] ) else skip)) ; execute (if chk = true then ans else -1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() a0=a[0].upper() print(a0+a[1 : :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var a0 : OclAny := a->first()->toUpperCase() ; execute (a0 + a(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop :)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys operators={"+" : lambda a,b : a+b,"-" : lambda a,b : a-b,"*" : lambda a,b : a*b,"/" : lambda a,b : a//b,} for line in sys.stdin : raw_a,op,raw_b=line.rstrip().split() if op=="?" : break a,b=map(int,[raw_a,raw_b]) result=operators[op](a,b) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var operators : Map := Map{ "+" |-> lambda a : OclAny, b : OclAny in (a + b) }->union(Map{ "-" |-> lambda a : OclAny, b : OclAny in (a - b) }->union(Map{ "*" |-> lambda a : OclAny, b : OclAny in (a * b) }->union((dictorsetmaker (test (logical_test (comparison (expr (atom "/"))))) : (test lambda (varargslist (vardef_parameters (vardef_parameter (name a)) , (vardef_parameter (name b)))) : (test (logical_test (comparison (expr (expr (atom (name a))) // (expr (atom (name b)))))))) ,)))) ; for line : OclFile["System.in"] do ( var raw_a : OclAny := null; var op : OclAny := null; var raw_b : OclAny := null; Sequence{raw_a,op,raw_b} := line.rstrip().split() ; if op = "?" then ( break ) else skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (Sequence{raw_a}->union(Sequence{ raw_b }))->collect( _x | (OclType["int"])->apply(_x) ) ; var result : OclAny := operators[op+1](a, b) ; execute (result)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def word(): p=input() print(p[0].upper()+p[1 :]) word() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; word(); operation word() pre: true post: true activity: var p : String := (OclFile["System.in"]).readLine() ; execute (p->first()->toUpperCase() + p->tail())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() s1=s[0].upper()+s[1 :] print(s1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var s1 : OclAny := s->first()->toUpperCase() + s->tail() ; execute (s1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() v="" for i in range(len(s)): if i==0 : a=s[i].upper() v+=a else : v+=s[i] print(v) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var v : String := "" ; for i : Integer.subrange(0, (s)->size()-1) do ( if i = 0 then ( var a : OclAny := s[i+1]->toUpperCase() ; v := v + a ) else ( v := v + s[i+1] )) ; execute (v)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isSubSeqDivisible(st): l=len(st) arr=[int(ch)for ch in st] for i in range(0,l): for j in range(i,l): for k in range(j,l): if(arr[i]% 8==0): return True elif((arr[i]*10+arr[j])% 8==0 and i!=j): return True elif((arr[i]*100+arr[j]*10+arr[k])% 8==0 and i!=j and j!=k and i!=k): return True return False st="3144" if(isSubSeqDivisible(st)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; st := "3144" ; if (isSubSeqDivisible(st)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isSubSeqDivisible(st : OclAny) : OclAny pre: true post: true activity: var l : int := (st)->size() ; var arr : Sequence := st->select(ch | true)->collect(ch | (("" + ((ch)))->toInteger())) ; for i : Integer.subrange(0, l-1) do ( for j : Integer.subrange(i, l-1) do ( for k : Integer.subrange(j, l-1) do ( if (arr[i+1] mod 8 = 0) then ( return true ) else (if ((arr[i+1] * 10 + arr[j+1]) mod 8 = 0 & i /= j) then ( return true ) else (if ((arr[i+1] * 100 + arr[j+1] * 10 + arr[k+1]) mod 8 = 0 & i /= j & j /= k & i /= k) then ( return true ) else skip ) ) ))) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumSquare(n): s=dict() for i in range(n): if i*i>n : break s[i*i]=1 if(n-i*i)in s.keys(): print((n-i*i)**(1/2),"^2+",i,"^2") return True return False n=169 if(sumSquare(n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 169 ; if (sumSquare(n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation sumSquare(n : OclAny) : OclAny pre: true post: true activity: var s : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( if (i * i->compareTo(n)) > 0 then ( break ) else skip ; s[i * i+1] := 1 ; if (s.keys())->includes((n - i * i)) then ( execute (((n - i * i))->pow((1 / 2)))->display() ; return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count(n): if(n<4): return-1 rem=n % 4 if(rem==0): return n//4 if(rem==1): if(n<9): return-1 return(n-9)//4+1 if(rem==2): return(n-6)//4+1 if(rem==3): if(n<15): return-1 return(n-15)//4+2 n=90 print(count(n)) n=143 print(count(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 90 ; execute (count(n))->display() ; n := 143 ; execute (count(n))->display(); operation count(n : OclAny) : OclAny pre: true post: true activity: if (n < 4) then ( return -1 ) else skip ; var rem : int := n mod 4 ; if (rem = 0) then ( return n div 4 ) else skip ; if (rem = 1) then ( if (n < 9) then ( return -1 ) else skip ; return (n - 9) div 4 + 1 ) else skip ; if (rem = 2) then ( return (n - 6) div 4 + 1 ) else skip ; if (rem = 3) then ( if (n < 15) then ( return -1 ) else skip ; return (n - 15) div 4 + 2 ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def factorial(N): if N==0 or N==1 : return 1 return N*factorial(N-1) def nthTerm(N): return(factorial(N)*(N+2)//2) N=6 print(nthTerm(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; N := 6 ; execute (nthTerm(N))->display(); operation factorial(N : OclAny) : OclAny pre: true post: true activity: if N = 0 or N = 1 then ( return 1 ) else skip ; return N * factorial(N - 1); operation nthTerm(N : OclAny) : OclAny pre: true post: true activity: return (factorial(N) * (N + 2) div 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countTripletsLessThanL(n,L,arr): arr.sort() ways=0 for i in range(n): for j in range(i+1,n): for k in range(j+1,n): mostDistantDistance=arr[k]-arr[i] if(mostDistantDistance<=L): ways+=1 return ways if __name__=="__main__" : arr=[1,2,3,4] n=len(arr) L=3 ans=countTripletsLessThanL(n,L,arr) print("Total Number of ways=",ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))) ; n := (arr)->size() ; L := 3 ; var ans : OclAny := countTripletsLessThanL(n, L, arr) ; execute ("Total Number of ways=")->display() ) else skip; operation countTripletsLessThanL(n : OclAny, L : OclAny, arr : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var ways : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( for k : Integer.subrange(j + 1, n-1) do ( var mostDistantDistance : double := arr[k+1] - arr[i+1] ; if ((mostDistantDistance->compareTo(L)) <= 0) then ( ways := ways + 1 ) else skip))) ; return ways; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter import math hpop=heappop hpush=heappush def solution(): n,d=map(int,input().split()) arr=list(map(int,input().split())) res=0 left=0 for i in range(len(arr)): while(left=d): k=i-left-1 k-=(arr[i]-arr[left]>d) res+=(k*(k+1))//2 left+=1 print(res) def main(): t=1 for _ in range(t): solution() import sys import threading sys.setrecursionlimit(1<<30) threading.stack_size(1<<27) thread=threading.Thread(target=main) thread.start(); thread.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1 * (2->pow(30))) ; threading.stack_size(1 * (2->pow(27))) ; var thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ; thread.start(); thread.join(); operation solution() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : int := 0 ; var left : int := 0 ; for i : Integer.subrange(0, (arr)->size()-1) do ( while ((left->compareTo(i)) < 0 & i = (arr)->size() - 1) or ((i->compareTo((arr)->size())) < 0 & (arr[i+1] - arr[left+1]->compareTo(d)) >= 0) do ( var k : double := i - left - 1 ; k := k - ((arr[i+1] - arr[left+1]->compareTo(d)) > 0) ; res := res + (k * (k + 1)) div 2 ; left := left + 1)) ; execute (res)->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSubStr(st,n): res=0 for i in range(0,n): if(st[i]=='1'): for j in range(i+1,n): if(st[j]=='1'): res=res+1 return res st="00100101" ; list(st) n=len(st) print(countSubStr(st,n),end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; st := "00100101"; ; OclType["Sequence"](st) ; n := (st)->size() ; execute (countSubStr(st, n))->display(); operation countSubStr(st : OclAny, n : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (st[i+1] = '1') then ( for j : Integer.subrange(i + 1, n-1) do ( if (st[j+1] = '1') then ( res := res + 1 ) else skip) ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sum=cnt=0 n,b,d=map(int,input().split()) lst=list(input().split()) for x in lst : x=int(x) if(x<=b): if(sum+x>d): sum=0 cnt+=1 else : sum+=x print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sum : OclAny := 0; var cnt : int := 0 ; var n : OclAny := null; var b : OclAny := null; var d : OclAny := null; Sequence{n,b,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lst : Sequence := (input().split()) ; for x : lst do ( var x : int := ("" + ((x)))->toInteger() ; if ((x->compareTo(b)) <= 0) then ( if ((sum + x->compareTo(d)) > 0) then ( sum := 0 ; cnt := cnt + 1 ) else ( sum := sum + x ) ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pr(x): pass t=int(input()) for i in range(t): n=int(input()) pr("problème{}:{}problèmes".format(i+1,n)) B=[0]*11 for k in range(n): s=input() b,d=tuple(int(x)for x in s.split()) B[d]=max(B[d],b) pr("B={}".format(B)) if any(B[d]==0 for d in range(1,11)): print("MOREPROBLEMS") else : print(sum(B[d]for d in range(1,11))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; pr(StringLib.interpolateStrings("probl�me{}:{}probl�mes", Sequence{i + 1, n})) ; var B : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 11) ; for k : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var b : OclAny := null; var d : OclAny := null; Sequence{b,d} := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name s)) (trailer . (name split) (arguments ( ))))))))) ; B[d+1] := Set{B[d+1], b}->max()) ; pr(StringLib.interpolateStrings("B={}", Sequence{B})) ; if ((argument (test (logical_test (comparison (comparison (expr (atom (name B)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name d)))))))) ])))) == (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name d)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 11))))))))) )))))))))->exists( _x | _x = true ) then ( execute ("MOREPROBLEMS")->display() ) else ( execute (((argument (test (logical_test (comparison (expr (atom (name B)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name d)))))))) ])))))) (comp_for for (exprlist (expr (atom (name d)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 11))))))))) )))))))))->sum())->display() )); operation pr(x : OclAny) pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) point=[0,0,0,0,0,0,0,0,0,0] for j in range(n): beauty,diff=list(map(lambda x : int(x),input().split())) if beauty>point[diff-1]: point[diff-1]=beauty if all(point): print(sum(point)) else : print("MOREPROBLEMS") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var point : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))))))))) ; for j : Integer.subrange(0, n-1) do ( var beauty : OclAny := null; var diff : OclAny := null; Sequence{beauty,diff} := ((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) )) ; if (beauty->compareTo(point[diff - 1+1])) > 0 then ( point[diff - 1+1] := beauty ) else skip) ; if (point)->forAll( _x | _x = true ) then ( execute ((point)->sum())->display() ) else ( execute ("MOREPROBLEMS")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for T in range(int(input())): n=int(input()) problems=[[]for j in range(10)] for i in range(n): b,d=map(int,input().split()) problems[d-1].append(b) beauty=0 if n<10 : print("MOREPROBLEMS") else : for p in problems : if len(p): p.sort() beauty+=p[-1] else : print("MOREPROBLEMS") break else : print(beauty) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for T : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var problems : Sequence := Integer.subrange(0, 10-1)->select(j | true)->collect(j | (Sequence{})) ; for i : Integer.subrange(0, n-1) do ( var b : OclAny := null; var d : OclAny := null; Sequence{b,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name problems)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name d))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) ))))) ; var beauty : int := 0 ; if n < 10 then ( execute ("MOREPROBLEMS")->display() ) else ( (compound_stmt for (exprlist (expr (atom (name p)))) in (testlist (test (logical_test (comparison (expr (atom (name problems))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p)))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name p)) (trailer . (name sort) (arguments ( )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name beauty)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "MOREPROBLEMS"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name beauty)))))))) ))))))))))))))) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys nofCases=int(input()) for ic in range(0,nofCases): nofProblems=int(input()) probs=[0]*11 for ip in range(0,nofProblems): tmp=input() tmp=tmp.split(' ') b=int(tmp[0]) d=int(tmp[1]) if b>probs[d]: probs[d]=b tot=0 more=False for ip in range(1,11): if probs[ip]==0 : more=True tot+=probs[ip] if more : print("MOREPROBLEMS") else : print(f"{tot}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var nofCases : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for ic : Integer.subrange(0, nofCases-1) do ( var nofProblems : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var probs : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 11) ; for ip : Integer.subrange(0, nofProblems-1) do ( var tmp : String := (OclFile["System.in"]).readLine() ; tmp := tmp.split(' ') ; var b : int := ("" + ((tmp->first())))->toInteger() ; var d : int := ("" + ((tmp[1+1])))->toInteger() ; if (b->compareTo(probs[d+1])) > 0 then ( probs[d+1] := b ) else skip) ; var tot : int := 0 ; var more : boolean := false ; for ip : Integer.subrange(1, 11-1) do ( if probs[ip+1] = 0 then ( more := true ) else skip ; tot := tot + probs[ip+1]) ; if more then ( execute ("MOREPROBLEMS")->display() ) else ( execute (StringLib.formattedString("{tot}"))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): for i in range(int(input())): print(test()) def test(): p=[-1]*10 for i in range(int(input())): b,d=map(int,input().split(" ")) if p[d-1]<=b : p[d-1]=b s=0 for i in range(10): if p[i]==-1 : return "MOREPROBLEMS" s+=p[i] return s main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (test())->display()); operation test() : OclAny pre: true post: true activity: var p : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, 10) ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var b : OclAny := null; var d : OclAny := null; Sequence{b,d} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; if (p[d - 1+1]->compareTo(b)) <= 0 then ( p[d - 1+1] := b ) else skip) ; var s : int := 0 ; for i : Integer.subrange(0, 10-1) do ( if p[i+1] = -1 then ( return "MOREPROBLEMS" ) else skip ; s := s + p[i+1]) ; return s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=10000 ; arr=[0]*N ; def seive(): i=2 ; while(i*isum())->display();; operation seive() pre: true post: true activity: var i : int := 2; ; while ((i * i->compareTo(N)) < 0) do ( if (arr[i+1] = 0) then ( var j : int := 2; ; while ((i * j->compareTo(N)) < 0) do ( arr[i * j+1] := arr[i * j+1] + i; ; j := j + 1;) ) else skip ; i := i + 1;); operation sum(l : OclAny, r : OclAny) pre: true post: true activity: seive(); ; var pref_arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (r + 1)); ; pref_arr->first() := arr->first(); ; for i : Integer.subrange(1, r + 1-1) do ( pref_arr[i+1] := pref_arr[i - 1+1] + arr[i+1];) ; if (l = 1) then ( return (pref_arr[r+1]); ) else ( return (pref_arr[r+1] - pref_arr[l - 1+1]); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=input() l=max(len(a),len(b)) n=len(a)-l m=len(b)-l for i in range(l): p='0' if n+i>=0 : p=a[n+i] q='0' if m+i>=0 : q=b[m+i] if pq : print(">") exit(0) print("=") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var l : OclAny := Set{(a)->size(), (b)->size()}->max() ; var n : double := (a)->size() - l ; var m : double := (b)->size() - l ; for i : Integer.subrange(0, l-1) do ( var p : String := '0' ; if n + i >= 0 then ( p := a[n + i+1] ) else skip ; var q : String := '0' ; if m + i >= 0 then ( q := b[m + i+1] ) else skip ; if p < q then ( execute ("<")->display() ; exit(0) ) else ( if p > q then ( execute (">")->display() ; exit(0) ) else skip )) ; execute ("=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() m=input() s1='' m1='' d=0 q=0 ans='=' for i in s : if i!='0' : d=1 if d : s1+=i for j in m : if j!='0' : q=1 if q : m1+=j if len(s1)>len(m1): print('>') elif len(s1)m1[l]: ans='>' break if s1[l]characters() do ( if i /= '0' then ( d := 1 ) else skip ; if d then ( s1 := s1 + i ) else skip) ; for j : m->characters() do ( if j /= '0' then ( q := 1 ) else skip ; if q then ( m1 := m1 + j ) else skip) ; if ((s1)->size()->compareTo((m1)->size())) > 0 then ( execute ('>')->display() ) else (if ((s1)->size()->compareTo((m1)->size())) < 0 then ( execute ('<')->display() ) else ( for l : Integer.subrange(0, (s1)->size()-1) do ( if (s1[l+1]->compareTo(m1[l+1])) > 0 then ( ans := '>' ; break ) else skip ; if (s1[l+1]->compareTo(m1[l+1])) < 0 then ( ans := '<' ; break ) else skip) ; execute (ans)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=[input().rjust(10**6,'0')for i in range(2)] if ab : print(">") else : print("=") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Integer.subrange(0, 2-1)->select(i | true)->collect(i | (input().rjust((10)->pow(6), '0'))) ; if (a->compareTo(b)) < 0 then ( execute ("<")->display() ) else (if (a->compareTo(b)) > 0 then ( execute (">")->display() ) else ( execute ("=")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): n,d=map(int,input().split()) arr=list(map(int,input().split())) res=0 for i in range(len(arr)): j=bisect_right(arr,arr[i]+d)-1 k=j-i-1 res+=(k*(k+1))//2 print(res) def main(): t=1 for _ in range(t): solution() import sys import threading sys.setrecursionlimit(1<<30) threading.stack_size(1<<27) thread=threading.Thread(target=main) thread.start(); thread.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1 * (2->pow(30))) ; threading.stack_size(1 * (2->pow(27))) ; var thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ; thread.start(); thread.join(); operation solution() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : int := 0 ; for i : Integer.subrange(0, (arr)->size()-1) do ( var j : double := bisect_right(arr, arr[i+1] + d) - 1 ; var k : double := j - i - 1 ; res := res + (k * (k + 1)) div 2) ; execute (res)->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from random import randint for _ in range(int(input())): n=int(input()) a=[*map(int,input().split())] b=[] q=set() while n : t=1 w=set() i=randint(1,1000000) for j in a : if j+i in q : t=0 break w.add(i+j) if t : q |=w b+=[i] n-=1 print("YES") print(*b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : Sequence := Sequence{} ; var q : Set := Set{}->union(()) ; while n do ( var t : int := 1 ; var w : Set := Set{}->union(()) ; var i : OclAny := randint(1, 1000000) ; for j : a do ( if (q)->includes(j + i) then ( t := 0 ; break ) else skip ; execute ((i + j) : w)) ; if t then ( q := q or w ; b := b + Sequence{ i } ; n := n - 1 ) else skip) ; execute ("YES")->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name b))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=input() l=max(len(a),len(b)) n=len(a)-l m=len(b)-l for i in range(l): p='0' if n+i>=0 : p=a[n+i] q='0' if m+i>=0 : q=b[m+i] if pq : print(">") exit(0) print("=") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var l : OclAny := Set{(a)->size(), (b)->size()}->max() ; var n : double := (a)->size() - l ; var m : double := (b)->size() - l ; for i : Integer.subrange(0, l-1) do ( var p : String := '0' ; if n + i >= 0 then ( p := a[n + i+1] ) else skip ; var q : String := '0' ; if m + i >= 0 then ( q := b[m + i+1] ) else skip ; if p < q then ( execute ("<")->display() ; exit(0) ) else ( if p > q then ( execute (">")->display() ; exit(0) ) else skip )) ; execute ("=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=input() if len(a)b : print('>') elif b>a : print('<') else : print('=') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; if ((a)->size()->compareTo((b)->size())) < 0 then ( a := StringLib.nCopies('0', ((b)->size() - (a)->size())) + a ) else ( b := StringLib.nCopies('0', ((a)->size() - (b)->size())) + b ) ; if a > b then ( execute ('>')->display() ) else (if b > a then ( execute ('<')->display() ) else ( execute ('=')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ax=set(map(int,input().split())) b=set() for i in ax : while(i % 2==0): i=i//2 while(i % 3==0): i=i//3 b.add(i) if(len(b)>1): print('No') break else : print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ax : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var b : Set := Set{}->union(()) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name ax))))))) : (suite (stmt (compound_stmt while (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (expr (atom (name i))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 0))))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name i))) // (expr (atom (number (integer 2))))))))))))))))) (stmt (compound_stmt while (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (expr (atom (name i))) % (expr (atom (number (integer 3)))))) == (comparison (expr (atom (number (integer 0))))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name i))) // (expr (atom (number (integer 3))))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) ))))) > (comparison (expr (atom (number (integer 1))))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'No'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'Yes'))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lineToInt(linea): temp="" salida=[] for i in linea : if i=="" : if temp!="" : salida.append(int(temp)) temp="" else : temp=temp+i salida.append(int(temp)) return salida n=int(input()) a=lineToInt(input()) out=set() for i in a : while i % 2==0 : i=i/2 while i % 3==0 : i=i/3 out.add(i) if len(out)==1 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := lineToInt((OclFile["System.in"]).readLine()) ; var out : Set := Set{}->union(()) ; for i : a do ( while i mod 2 = 0 do ( var i : double := i / 2) ; while i mod 3 = 0 do ( i := i / 3) ; execute ((i) : out)) ; if (out)->size() = 1 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation lineToInt(linea : OclAny) : OclAny pre: true post: true activity: var temp : String := "" ; var salida : Sequence := Sequence{} ; for i : linea do ( if i = "" then ( if temp /= "" then ( execute ((("" + ((temp)))->toInteger()) : salida) ; temp := "" ) else skip ) else ( temp := temp + i )) ; execute ((("" + ((temp)))->toInteger()) : salida) ; return salida; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()); x=list(map(int,input().split())) for i in range(n): while x[i]% 2==0 : x[i]/=2 while x[i]% 3==0 : x[i]/=3 if len(set(x))==1 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( while x[i+1] mod 2 = 0 do ( x[i+1] := x[i+1] / 2) ; while x[i+1] mod 3 = 0 do ( x[i+1] := x[i+1] / 3)) ; if (Set{}->union((x)))->size() = 1 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=set(map(int,input().split())) b=set() for i in a : while(i % 2==0): i=i//2 while(i % 3==0): i=i//3 b.add(i) if(len(b)>1): print('No') break else : print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var b : Set := Set{}->union(()) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name a))))))) : (suite (stmt (compound_stmt while (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (expr (atom (name i))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 0))))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name i))) // (expr (atom (number (integer 2))))))))))))))))) (stmt (compound_stmt while (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (expr (atom (name i))) % (expr (atom (number (integer 3)))))) == (comparison (expr (atom (number (integer 0))))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name i))) // (expr (atom (number (integer 3))))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) ))))) > (comparison (expr (atom (number (integer 1))))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'No'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'Yes'))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[list(map(int,input().split()))for x in range(n)] def valid(di): b=[] for i in di : t=[] for j in range(n): if i in a[j]: t.append(j) b.append(sorted(t)) for i in b[0]: if len(b)>1 : for j in b[1]: if len(b)>2 : for k in b[2]: if i!=j : return True else : if i!=j : return True else : return True return False x=1 while True : temp=x done=[] flag=0 while temp>0 : done.append(temp % 10) temp=temp//10 if valid(done[: :-1]): x+=1 else : break print(x-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(x | true)->collect(x | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; skip ; var x : int := 1 ; while true do ( var temp : int := x ; var done : Sequence := Sequence{} ; var flag : int := 0 ; while temp > 0 do ( execute ((temp mod 10) : done) ; temp := temp div 10) ; if valid(done(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) then ( x := x + 1 ) else ( break )) ; execute (x - 1)->display(); operation valid(di : OclAny) : OclAny pre: true post: true activity: var b : Sequence := Sequence{} ; for i : di do ( var t : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( if (a[j+1])->includes(i) then ( execute ((j) : t) ) else skip) ; execute ((t->sort()) : b)) ; for i : b->first() do ( if (b)->size() > 1 then ( for j : b[1+1] do ( if (b)->size() > 2 then ( for k : b[2+1] do ( if i /= j then ( return true ) else skip) ) else ( if i /= j then ( return true ) else skip )) ) else ( return true )) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict tc=int(input()) brr=[] d=defaultdict(int) odn=[] tdn=[] for i in range(tc): arr=list(map(int,input().rstrip().split())) if(i>0): odn=list(set(odn)) for j in range(6): for k in range(len(odn)): tdn.append(odn[k]*10+arr[j]) tdn.append(arr[j]*10+odn[k]) odn.extend(arr) ans=odn+tdn ans=list(set(ans)) ans.sort() flag=0 me=ans[0] sme=ans[1] for i in range(1,len(ans)): if(ans[i]!=ans[i-1]+1): ut=ans[i-1] flag=1 break if(flag==0): ut=max(ans) if((me!=1)and(sme!=1)): ut=0 print(ut) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var tc : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var brr : Sequence := Sequence{} ; var d : OclAny := defaultdict(OclType["int"]) ; var odn : Sequence := Sequence{} ; var tdn : Sequence := Sequence{} ; for i : Integer.subrange(0, tc-1) do ( var arr : Sequence := ((input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (i > 0) then ( odn := (Set{}->union((odn))) ; for j : Integer.subrange(0, 6-1) do ( for k : Integer.subrange(0, (odn)->size()-1) do ( execute ((odn[k+1] * 10 + arr[j+1]) : tdn) ; execute ((arr[j+1] * 10 + odn[k+1]) : tdn))) ) else skip ; odn := odn->union(arr)) ; var ans : Sequence := odn->union(tdn) ; ans := (Set{}->union((ans))) ; ans := ans->sort() ; var flag : int := 0 ; var me : OclAny := ans->first() ; var sme : OclAny := ans[1+1] ; for i : Integer.subrange(1, (ans)->size()-1) do ( if (ans[i+1] /= ans[i - 1+1] + 1) then ( var ut : OclAny := ans[i - 1+1] ; flag := 1 ; break ) else skip) ; if (flag = 0) then ( ut := (ans)->max() ) else skip ; if ((me /= 1) & (sme /= 1)) then ( ut := 0 ) else skip ; execute (ut)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def splitArr(arr,n,k): for i in range(0,k): x=arr[0] for j in range(0,n-1): arr[j]=arr[j+1] arr[n-1]=x arr=[12,10,5,6,52,36] n=len(arr) position=2 splitArr(arr,n,position) for i in range(0,n): print(arr[i],end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{12}->union(Sequence{10}->union(Sequence{5}->union(Sequence{6}->union(Sequence{52}->union(Sequence{ 36 }))))) ; n := (arr)->size() ; var position : int := 2 ; splitArr(arr, n, position) ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); operation splitArr(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: for i : Integer.subrange(0, k-1) do ( var x : OclAny := arr->first() ; for j : Integer.subrange(0, n - 1-1) do ( arr[j+1] := arr[j + 1+1]) ; arr[n - 1+1] := x); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math class Node : def __init__(self,data): self.data=data self.next=None def add(data): newnode=Node(data) newnode.data=data newnode.next=None return newnode def printlist(head): while(head!=None): print(head.data,end="->") head=head.next print("None") def isSpecialChar(ch): if(ch>='a' and ch<='z'): return False if(ch>='A' and ch<='Z'): return False if(ch>='0' and ch<='9'): return False return True def removeFromLL(head): curr=head prev=head while(curr!=None and isSpecialChar(curr.data)): temp=curr head=curr.next curr=curr.next temp=None prev=head while(curr!=None): while(curr!=None and isSpecialChar(curr.data)): temp=curr prev.next=curr.next curr=curr.next temp=None if(curr==None): break prev=curr curr=curr.next return head if __name__=='__main__' : head=None head=add('(') head.next=add('G') head.next.next=add('E') head.next.next.next=add('E') head.next.next.next.next=add('*') head.next.next.next.next.next=add('K') head.next.next.next.next.next.next=add('S') head.next.next.next.next.next.next.next=add('*') head=removeFromLL(head) printlist(head) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.next := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( head := null ; head := add('(') ; head.next := add('G') ; head.next.next := add('E') ; head.next.next.next := add('E') ; head.next.next.next.next := add('*') ; head.next.next.next.next.next := add('K') ; head.next.next.next.next.next.next := add('S') ; head.next.next.next.next.next.next.next := add('*') ; head := removeFromLL(head) ; printlist(head) ) else skip; operation add(data : OclAny) : OclAny pre: true post: true activity: var newnode : Node := (Node.newNode()).initialise(data) ; newnode.data := data ; newnode.next := null ; return newnode; operation printlist(head : OclAny) pre: true post: true activity: while (head /= null) do ( execute (head.data)->display() ; head := head.next) ; execute ("None")->display(); operation isSpecialChar(ch : OclAny) : OclAny pre: true post: true activity: if (ch >= 'a' & ch <= 'z') then ( return false ) else skip ; if (ch >= 'A' & ch <= 'Z') then ( return false ) else skip ; if (ch >= '0' & ch <= '9') then ( return false ) else skip ; return true; operation removeFromLL(head : OclAny) : OclAny pre: true post: true activity: var curr : OclAny := head ; var prev : OclAny := head ; while (curr /= null & isSpecialChar(curr.data)) do ( var temp : OclAny := curr ; head := curr.next ; curr := curr.next ; temp := null) ; prev := head ; while (curr /= null) do ( while (curr /= null & isSpecialChar(curr.data)) do ( temp := curr ; prev.next := curr.next ; curr := curr.next ; temp := null) ; if (curr = null) then ( break ) else skip ; prev := curr ; curr := curr.next) ; return head; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import io import os from random import randint input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t=int(input()) for tc in range(t): n=int(input()) arr=[int(z)for z in input().split()] arr1=set() used=set() while True : b=randint(1,10**6) na=0 for i in arr : if i+b in used : na=1 break if na : continue arr1.add(b) if len(arr1)==len(arr): break for i in arr : used.add(i+b) print("YES") print(' '.join(map(str,arr1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for tc : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := input().split()->select(z | true)->collect(z | (("" + ((z)))->toInteger())) ; var arr1 : Set := Set{}->union(()) ; var used : Set := Set{}->union(()) ; while true do ( var b : OclAny := randint(1, (10)->pow(6)) ; var na : int := 0 ; for i : arr do ( if (used)->includes(i + b) then ( na := 1 ; break ) else skip) ; if na then ( continue ) else skip ; execute ((b) : arr1) ; if (arr1)->size() = (arr)->size() then ( break ) else skip ; for i : arr do ( execute ((i + b) : used))) ; execute ("YES")->display() ; execute (StringLib.sumStringsWithSeparator(((arr1)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=map(int,input().split()) a=[int(x)for x in input().split()] sol=0 l=0 col=1 if n>2 : while l2 : x=col-2 if x==1 : sol+=1 else : sol+=x*(x+1)//2 for j in range(l_,n): if abs(a[j]-a[l])<=d : col+=1 if col>2 : sol+=col-2 if j+1==n : l+=1 col=col-1 else : l+=1 col=col-1 break if l_>=n : l+=1 col=col-1 print(sol) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var sol : int := 0 ; var l : int := 0 ; var col : int := 1 ; if n > 2 then ( while (l->compareTo(n - 2)) < 0 do ( var l_ : int := l + col ; if col > 2 then ( var x : double := col - 2 ; if x = 1 then ( sol := sol + 1 ) else ( sol := sol + x * (x + 1) div 2 ) ) else skip ; for j : Integer.subrange(l_, n-1) do ( if ((a[j+1] - a[l+1])->abs()->compareTo(d)) <= 0 then ( col := col + 1 ; if col > 2 then ( sol := sol + col - 2 ) else skip ; if j + 1 = n then ( l := l + 1 ; col := col - 1 ) else skip ) else ( l := l + 1 ; col := col - 1 ; break )) ; if (l_->compareTo(n)) >= 0 then ( l := l + 1 ; col := col - 1 ) else skip) ) else skip ; execute (sol)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getChicks(n): size=max(n,7); dp=[0]*size ; dp[0]=0 ; dp[1]=1 ; for i in range(2,7): dp[i]=dp[i-1]*3 ; dp[6]=726 ; for i in range(8,n+1): dp[i]=(dp[i-1]-(2*dp[i-6]//3))*3 ; return dp[n]; n=3 ; print(getChicks(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3; ; execute (getChicks(n))->display();; operation getChicks(n : OclAny) pre: true post: true activity: var size : OclAny := Set{n, 7}->max(); ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, size); ; dp->first() := 0; ; dp[1+1] := 1; ; for i : Integer.subrange(2, 7-1) do ( dp[i+1] := dp[i - 1+1] * 3;) ; dp[6+1] := 726; ; for i : Integer.subrange(8, n + 1-1) do ( dp[i+1] := (dp[i - 1+1] - (2 * dp[i - 6+1] div 3)) * 3;) ; return dp[n+1];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) dp_a=[0]*(n+1) dp_b=[n]*(n+1) mod=10**9+7 l=[i for i in range(n+1)] ll=[i for i in range(n,-1,-1)] for i in range(1,n+1): dp_a[i]=(dp_a[i-1]+l[i])% mod dp_b[i]=(dp_b[i-1]+ll[i])% mod ans=0 for i in range(k,n+2): ans+=(dp_b[i-1]-dp_a[i-1]+1)% mod print(ans % mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dp_a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var dp_b : Sequence := MatrixLib.elementwiseMult(Sequence{ n }, (n + 1)) ; var mod : double := (10)->pow(9) + 7 ; var l : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (i)) ; var ll : Sequence := Integer.subrange(-1 + 1, n)->reverse()->select(i | true)->collect(i | (i)) ; for i : Integer.subrange(1, n + 1-1) do ( dp_a[i+1] := (dp_a[i - 1+1] + l[i+1]) mod mod ; dp_b[i+1] := (dp_b[i - 1+1] + ll[i+1]) mod mod) ; var ans : int := 0 ; for i : Integer.subrange(k, n + 2-1) do ( ans := ans + (dp_b[i - 1+1] - dp_a[i - 1+1] + 1) mod mod) ; execute (ans mod mod)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(1<<25) read=sys.stdin.readline ra=range enu=enumerate def read_ints(): return list(map(int,read().split())) def read_a_int(): return int(read()) def read_tuple(H): ret=[] for _ in range(H): ret.append(tuple(map(int,read().split()))) return ret def read_col(H): ret=[] for _ in range(H): ret.append(list(map(int,read().split()))) return tuple(map(list,zip(*ret))) def read_matrix(H): ret=[] for _ in range(H): ret.append(list(map(int,read().split()))) return ret MOD=10**9+7 INF=2**31 from collections import defaultdict,Counter,deque from operator import itemgetter from itertools import product,permutations,combinations from bisect import bisect_left,bisect_right N,K=read_ints() ans=0 for k in ra(K,N+2): tmp=((N+N-(k-1))*k//2)-((0+k-1)*k//2)+1 ans+=tmp ans %=MOD print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(1 * (2->pow(25))) ; var read : OclAny := (OclFile["System.in"]).readline ; var ra : OclAny := range ; var enu : OclAny := enumerate ; skip ; skip ; skip ; skip ; skip ; var MOD : double := (10)->pow(9) + 7 ; var INF : double := (2)->pow(31) ; skip ; skip ; skip ; skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := read_ints() ; var ans : int := 0 ; for k : ra(K, N + 2) do ( var tmp : double := ((N + N - (k - 1)) * k div 2) - ((0 + k - 1) * k div 2) + 1 ; ans := ans + tmp ; ans := ans mod MOD) ; execute (ans)->display(); operation read_ints() : OclAny pre: true post: true activity: return ((read().split())->collect( _x | (OclType["int"])->apply(_x) )); operation read_a_int() : OclAny pre: true post: true activity: return ("" + ((read())))->toInteger(); operation read_tuple(H : OclAny) : OclAny pre: true post: true activity: var ret : Sequence := Sequence{} ; for _anon : Integer.subrange(0, H-1) do ( execute ((((read().split())->collect( _x | (OclType["int"])->apply(_x) ))) : ret)) ; return ret; operation read_col(H : OclAny) : OclAny pre: true post: true activity: ret := Sequence{} ; for _anon : Integer.subrange(0, H-1) do ( execute ((((read().split())->collect( _x | (OclType["int"])->apply(_x) ))) : ret)) ; return ((Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name ret)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name ret)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name ret)))))))`third->at(_indx)} ))->collect( _x | (OclType["Sequence"])->apply(_x) )); operation read_matrix(H : OclAny) : OclAny pre: true post: true activity: ret := Sequence{} ; for _anon : Integer.subrange(0, H-1) do ( execute ((((read().split())->collect( _x | (OclType["int"])->apply(_x) ))) : ret)) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines sys.setrecursionlimit(10**8) INF=float('inf') MOD=10**9+7 def main(): N,K=map(int,readline().split()) left=(K*(K-1))//2 right=K*(2*N-K+1)//2 ans=0 for i in range(K,N+1): ans+=(right-left+1)% MOD right+=N-i left+=i print((ans+1)% MOD) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; sys.setrecursionlimit((10)->pow(8)) ; var INF : double := ("" + (('inf')))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var left : int := (K * (K - 1)) div 2 ; var right : int := K * (2 * N - K + 1) div 2 ; var ans : int := 0 ; for i : Integer.subrange(K, N + 1-1) do ( ans := ans + (right - left + 1) mod MOD ; right := right + N - i ; left := left + i) ; execute ((ans + 1) mod MOD)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,input().split()) ans=0 temp_max=0 temp_min=0 for i in range(1,N+2): temp_max+=N-i+1 temp_min+=i-1 if i>=K : ans+=(temp_max-temp_min+1) print(ans %(10**9+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; var temp_max : int := 0 ; var temp_min : int := 0 ; for i : Integer.subrange(1, N + 2-1) do ( temp_max := temp_max + N - i + 1 ; temp_min := temp_min + i - 1 ; if (i->compareTo(K)) >= 0 then ( ans := ans + (temp_max - temp_min + 1) ) else skip) ; execute (ans mod ((10)->pow(9) + 7))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import comb as c a,b=map(int,input().split()) print(((c(a+2,2)+1)*(a+2-b)-c(a+3-b,3)-c(a+3,3)+c(b+1,3))%(10**9+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (((c(a + 2, 2) + 1) * (a + 2 - b) - c(a + 3 - b, 3) - c(a + 3, 3) + c(b + 1, 3)) mod ((10)->pow(9) + 7))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) arr=[int(x)for x in input().split()] total=0 for _ in range(m): op=[int(x)for x in input().split()] if op[0]==1 : idx=op[1]-1 arr[idx]=op[2]-total elif op[0]==2 : total+=op[1] else : idx=op[1]-1 print(arr[idx]+total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var total : int := 0 ; for _anon : Integer.subrange(0, m-1) do ( var op : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if op->first() = 1 then ( var idx : double := op[1+1] - 1 ; arr[idx+1] := op[2+1] - total ) else (if op->first() = 2 then ( total := total + op[1+1] ) else ( idx := op[1+1] - 1 ; execute (arr[idx+1] + total)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,inputs=[int(x)for x in input().split()] lista=[] listaOperacao=[] aux=soma=0 lista=[int(x)for x in input().split()] while aux!=inputs : listaOperacao=[int(x)for x in input().split()] if listaOperacao[0]==1 : lista[listaOperacao[1]-1]=listaOperacao[2]-soma elif listaOperacao[0]==2 : soma+=listaOperacao[1] else : print(lista[listaOperacao[1]-1]+soma) listaOperacao=[] aux+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var inputs : OclAny := null; Sequence{x,inputs} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var lista : Sequence := Sequence{} ; var listaOperacao : Sequence := Sequence{} ; var aux : OclAny := 0; var soma : int := 0 ; lista := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; while aux /= inputs do ( listaOperacao := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if listaOperacao->first() = 1 then ( lista[listaOperacao[1+1] - 1+1] := listaOperacao[2+1] - soma ) else (if listaOperacao->first() = 2 then ( soma := soma + listaOperacao[1+1] ) else ( execute (lista[listaOperacao[1+1] - 1+1] + soma)->display() ) ) ; listaOperacao := Sequence{} ; aux := aux + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin n,c=map(int,input().split()) l=list(map(int,stdin.readline().split())) x=0 for _ in range(c): m=list(map(int,stdin.readline().split())) if(m[0]==3): print(l[m[1]-1]+x) elif(m[0]==1): l[m[1]-1]=m[2]-x else : x+=m[1] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : int := 0 ; for _anon : Integer.subrange(0, c-1) do ( var m : Sequence := ((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (m->first() = 3) then ( execute (l[m[1+1] - 1+1] + x)->display() ) else (if (m->first() = 1) then ( l[m[1+1] - 1+1] := m[2+1] - x ) else ( x := x + m[1+1] ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binarySearch(arr,low,high,key): if(higharr[int(mid)]): return binarySearch(arr,(mid+1),high,key) return(binarySearch(arr,low,(mid-1),key)) arr=[5,6,7,8,9,10] n=len(arr) key=10 print("Index:",int(binarySearch(arr,0,n,key))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{ 10 }))))) ; var n : int := (arr)->size() ; key := 10 ; execute ("Index:")->display(); operation binarySearch(arr : OclAny, low : OclAny, high : OclAny, key : OclAny) : OclAny pre: true post: true activity: if ((high->compareTo(low)) < 0) then ( return -1 ) else skip ; var mid : double := (low + high) / 2 ; if (key = arr[("" + ((mid)))->toInteger()+1]) then ( return mid ) else skip ; if ((key->compareTo(arr[("" + ((mid)))->toInteger()+1])) > 0) then ( return binarySearch(arr, (mid + 1), high, key) ) else skip ; return (binarySearch(arr, low, (mid - 1), key)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i_nm=input().split() n,m=int(i_nm[0]),int(i_nm[1]) a=list(map(int,input().split())) values=[] for i in range(m): values.append([int(x)for x in input().split()]) count=0 for e in values : if e[0]==1 : v=e[1] x=e[2] a[v-1]=x-count elif e[0]==2 : y=e[1] count+=y elif e[0]==3 : print(a[e[1]-1]+count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i_nm : OclAny := input().split() ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{("" + ((i_nm->first())))->toInteger(),("" + ((i_nm[1+1])))->toInteger()} ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var values : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( execute ((input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) : values)) ; var count : int := 0 ; for e : values do ( if e->first() = 1 then ( var v : OclAny := e[1+1] ; var x : OclAny := e[2+1] ; a[v - 1+1] := x - count ) else (if e->first() = 2 then ( var y : OclAny := e[1+1] ; count := count + y ) else (if e->first() = 3 then ( execute (a[e[1+1] - 1+1] + count)->display() ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- y,k,n=map(int,input().split()) a=[] for i in range((y//k)+1,(n//k)+1): a.append(i*k-y) if len(a)==0 : print(-1) else : b=' '.join([str(elem)for elem in a]) print(b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var y : OclAny := null; var k : OclAny := null; var n : OclAny := null; Sequence{y,k,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{} ; for i : Integer.subrange((y div k) + 1, (n div k) + 1-1) do ( execute ((i * k - y) : a)) ; if (a)->size() = 0 then ( execute (-1)->display() ) else ( var b : String := StringLib.sumStringsWithSeparator((a->select(elem | true)->collect(elem | (("" + ((elem)))))), ' ') ; execute (b)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=list(map(int,input().split())) arr=list(map(int,input().split())) b=0 ans='' for _ in range(m): l=list(map(int,input().split())) if l[0]==3 : ans+=str(arr[l[1]-1]+b)+'\n' elif l[0]==2 : b+=l[1] elif l[0]==1 : arr[l[1]-1]=l[2]-b print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : int := 0 ; var ans : String := '' ; for _anon : Integer.subrange(0, m-1) do ( var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if l->first() = 3 then ( ans := ans + ("" + ((arr[l[1+1] - 1+1] + b))) + ' ' ) else (if l->first() = 2 then ( b := b + l[1+1] ) else (if l->first() = 1 then ( arr[l[1+1] - 1+1] := l[2+1] - b ) else skip ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def l(): return[input()for _ in range(int(input()))] p,m=l(),l() c=0 for s in set(p): c=max(p.count(s)-m.count(s),c) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var p : OclAny := null; var m : OclAny := null; Sequence{p,m} := Sequence{l(),l()} ; var c : int := 0 ; for s : Set{}->union((p)) do ( c := Set{p->count(s) - m->count(s), c}->max()) ; execute (c)->display(); operation l() : OclAny pre: true post: true activity: return Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n=int(input()) ss=[input()for _ in range(n)] m=int(input()) ts=[input()for _ in range(m)] c0=Counter(ss)-Counter(ts) if c0 : word,count=c0.most_common(1)[0] print(count) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ss : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ts : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var c0 : double := Counter(ss) - Counter(ts) ; if c0 then ( var word : OclAny := null; var count : OclAny := null; Sequence{word,count} := c0.most_common(1)->first() ; execute (count)->display() ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import os import math ii=lambda : int(sys.stdin.buffer.readline().rstrip()) il=lambda : list(map(int,sys.stdin.buffer.readline().split())) fl=lambda : list(map(float,sys.stdin.buffer.readline().split())) iln=lambda n :[int(sys.stdin.buffer.readline().rstrip())for _ in range(n)] iss=lambda : sys.stdin.buffer.readline().decode().rstrip() sl=lambda : list(map(str,sys.stdin.buffer.readline().decode().split())) isn=lambda n :[sys.stdin.buffer.readline().decode().rstrip()for _ in range(n)] MOD=10**9+7 def main(): if os.getenv("LOCAL"): sys.stdin=open("input.txt","r") N=ii() B=[iss()for _ in range(N)] M=ii() R=[iss()for _ in range(M)] ret=0 for b in B : ret=max(ret,B.count(b)-R.count(b)) print(ret) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var ii : Function := lambda $$ : OclAny in (("" + ((sys.stdin.buffer.readLine().rstrip())))->toInteger()) ; var il : Function := lambda $$ : OclAny in (((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var fl : Function := lambda $$ : OclAny in (((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ))) ; var iln : Function := lambda n : OclAny in (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + ((sys.stdin.buffer.readLine().rstrip())))->toInteger()))) ; var iss : Function := lambda $$ : OclAny in (sys.stdin.buffer.readLine().decode().rstrip()) ; var sl : Function := lambda $$ : OclAny in (((sys.stdin.buffer.readLine().decode().split())->collect( _x | (OclType["String"])->apply(_x) ))) ; var isn : Function := lambda n : OclAny in (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (sys.stdin.buffer.readLine().decode().rstrip()))) ; var MOD : double := (10)->pow(9) + 7 ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: if os.getenv("LOCAL") then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ) else skip ; var N : OclAny := ii->apply() ; var B : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (iss->apply())) ; var M : OclAny := ii->apply() ; var R : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (iss->apply())) ; var ret : int := 0 ; for b : B do ( ret := Set{ret, B->count(b) - R->count(b)}->max()) ; execute (ret)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) plus,p_check=[],set() for _ in range(n): temp=str(input()) plus.append(temp) p_check.add(temp) m=int(input()) minus,m_check=[],set() for _ in range(m): temp=str(input()) minus.append(temp) m_check.add(temp) diffs=[] for dum in p_check : dif=plus.count(dum)-minus.count(dum) diffs.append(dif) maxdif=max(diffs) if maxdif<0 : print(0) else : print(maxdif) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var plus : OclAny := null; var p_check : OclAny := null; Sequence{plus,p_check} := Sequence{Sequence{},Set{}->union(())} ; for _anon : Integer.subrange(0, n-1) do ( var temp : String := ("" + (((OclFile["System.in"]).readLine()))) ; execute ((temp) : plus) ; execute ((temp) : p_check)) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var minus : OclAny := null; var m_check : OclAny := null; Sequence{minus,m_check} := Sequence{Sequence{},Set{}->union(())} ; for _anon : Integer.subrange(0, m-1) do ( temp := ("" + (((OclFile["System.in"]).readLine()))) ; execute ((temp) : minus) ; execute ((temp) : m_check)) ; var diffs : Sequence := Sequence{} ; for dum : p_check do ( var dif : double := plus->count(dum) - minus->count(dum) ; execute ((dif) : diffs)) ; var maxdif : OclAny := (diffs)->max() ; if maxdif < 0 then ( execute (0)->display() ) else ( execute (maxdif)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def solve(): N=int(input()) blue=defaultdict(int) for i in range(N): s=input() blue[s]+=1 M=int(input()) red=defaultdict(int) for i in range(M): t=input() red[t]+=1 mx=0 for item in blue.items(): mx=max(mx,item[1]-red[item[0]]) print(mx) if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var blue : OclAny := defaultdict(OclType["int"]) ; for i : Integer.subrange(0, N-1) do ( var s : String := (OclFile["System.in"]).readLine() ; blue->at(s) := blue->at(s) + 1) ; var M : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var red : OclAny := defaultdict(OclType["int"]) ; for i : Integer.subrange(0, M-1) do ( var t : String := (OclFile["System.in"]).readLine() ; red->at(t) := red->at(t) + 1) ; var mx : int := 0 ; for item : blue->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do ( mx := Set{mx, item[1+1] - red[item->first()+1]}->max()) ; execute (mx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cnt=0 while 1 : try : word=input() except EOFError : break if word==word[: :-1]: cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cnt : int := 0 ; while 1 do ( try ( var word : String := (OclFile["System.in"]).readLine()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))) ; if word = word(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys count=0 for line in sys.stdin.readlines(): l=[i for i in line.replace('\n','')] m=list(l) l.reverse() if m==l : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var count : int := 0 ; for line : (OclFile["System.in"]).readlines() do ( var l : Sequence := line.replace(' ', '')->select(i | true)->collect(i | (i)) ; var m : Sequence := (l) ; l := l->reverse() ; if m = l then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printSeriesSum(N): sum=0 ; a=1 ; cnt=0 ; flag=True ; sum+=a ; while(cntcompareTo(N)) < 0) do ( var nextElement : OclAny := null; ; if (flag) then ( nextElement := a * 2; ; sum := sum + nextElement; ; flag := not(flag); ) else ( nextElement := a * (3 / 2); ; sum := sum + nextElement; ; flag := not(flag); ) ; a := nextElement; ; cnt := cnt + 1) ; execute (sum)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def equal_xor_sum(arr,n): Sum=0 ; Xor=0 ; for i in range(n): Sum=Sum+arr[i]; Xor=Xor ^ arr[i]; if(Sum==Xor): print("YES"); else : print("NO"); if __name__=="__main__" : arr=[6,3,7,10]; n=len(arr); equal_xor_sum(arr,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{6}->union(Sequence{3}->union(Sequence{7}->union(Sequence{ 10 }))); ; n := (arr)->size(); ; equal_xor_sum(arr, n); ) else skip; operation equal_xor_sum(arr : OclAny, n : OclAny) pre: true post: true activity: var Sum : int := 0; ; var Xor : int := 0; ; for i : Integer.subrange(0, n-1) do ( Sum := Sum + arr[i+1]; ; Xor := MathLib.bitwiseXor(Xor, arr[i+1]);) ; if (Sum = Xor) then ( execute ("YES")->display(); ) else ( execute ("NO")->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys print(sum([1 for i in sys.stdin if i.strip()==i.strip()[: :-1]])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute ((OclFile["System.in"]->select(i | i->trim() = i->trim()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->collect(i | (1)))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ch(l): for i in range(len(l)//2): if l[i]!=l[-i-1]: return False return True s=0 while True : try : l=input() except : break if ch(l): s+=1 print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : int := 0 ; while true do ( try ( l := (OclFile["System.in"]).readLine()) catch (_e : OclException) do ( break) ; if ch(l) then ( s := s + 1 ) else skip) ; execute (s)->display(); operation ch(l : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, (l)->size() div 2-1) do ( if l[i+1] /= l->reverse()->at(-(-i - 1)) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- y,k,n=map(int,input().split()) x=k-y % k if x+y>n : print(-1) else : while x+y<=n : print(x) x+=k ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var y : OclAny := null; var k : OclAny := null; var n : OclAny := null; Sequence{y,k,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : double := k - y mod k ; if (x + y->compareTo(n)) > 0 then ( execute (-1)->display() ) else ( while (x + y->compareTo(n)) <= 0 do ( execute (x)->display() ; x := x + k) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- list=[] c=0 try : while True : list.append(input()) except EOFError : pass for i in range(len(list)): x=list[i][: :-1] if x==list[i]: c=c+1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var OclType["Sequence"] : Sequence := Sequence{} ; var c : int := 0 ; try ( while true do ( execute (((OclFile["System.in"]).readLine()) : OclType["Sequence"]))) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt pass))))) ; for i : Integer.subrange(0, (OclType["Sequence"])->size()-1) do ( var x : OclAny := OclType["Sequence"][i+1](subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; if x = [i+1] then ( c := c + 1 ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def GetPrefixSuffix(a,b,l): prefix=a[: l]; lb=len(b); suffix=b[lb-l :]; return(prefix+suffix); a="remuneration" ; b="acquiesce" ; l=5 ; print(GetPrefixSuffix(a,b,l)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := "remuneration"; ; b := "acquiesce"; ; l := 5; ; execute (GetPrefixSuffix(a, b, l))->display();; operation GetPrefixSuffix(a : OclAny, b : OclAny, l : OclAny) pre: true post: true activity: var prefix : OclAny := a.subrange(1,l); ; var lb : int := (b)->size(); ; var suffix : OclAny := b.subrange(lb - l+1); ; return (prefix + suffix);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) founded=True a.sort() for i in range(n-1,-1,-1): if a[2*n-i-1]<=a[i]: founded=False break print("YES" if founded else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var founded : boolean := true ; a := a->sort() ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (a[2 * n - i - 1+1]->compareTo(a[i+1])) <= 0 then ( founded := false ; break ) else skip) ; execute (if founded then "YES" else "NO" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) l.sort() if l[n]>l[n-1]: print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := l->sort() ; if (l[n+1]->compareTo(l[n - 1+1])) > 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) a.sort() for i in range(n): if a[i]in a[n :]: print("NO") exit() if a[n+i]<=a[i]: print("NO") exit() print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; for i : Integer.subrange(0, n-1) do ( if (a.subrange(n+1))->includes(a[i+1]) then ( execute ("NO")->display() ; exit() ) else skip ; if (a[n + i+1]->compareTo(a[i+1])) <= 0 then ( execute ("NO")->display() ; exit() ) else skip) ; execute ("YES")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) w=sorted(map(int,input().split())) if w[n]==w[n-1]: print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; if w[n+1] = w[n - 1+1] then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=sorted([int(i)for i in input().split()],reverse=True) A,B=a[: n],a[n :] if A[-1]==B[0]: print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := Sequence{a.subrange(1,n),a.subrange(n+1)} ; if A->last() = B->first() then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inl=lambda : list(map(int,input().split())) n,m,k=inl() h=set(inl()) b=1 if b not in h : for _ in range(k): u,v=inl() if b==u or b==v : b=u if b==v else v if{u,v}& h : break print(b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inl : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := inl->apply() ; var h : Set := Set{}->union((inl->apply())) ; var b : int := 1 ; if (h)->excludes(b) then ( for _anon : Integer.subrange(0, k-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := inl->apply() ; if b = u or b = v then ( b := if b = v then u else v endif ; if MathLib.bitwiseAnd(Set{u}->union(Set{ v }), h) then ( break ) else skip ) else skip) ) else skip ; execute (b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,base): result=0 while(n>0): remainder=n % base result=result+remainder n=int(n/base) return result def printSumsOfDigits(n): for base in range(2,n): print(solve(n,base),end=" ") n=8 printSumsOfDigits(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 8 ; printSumsOfDigits(n); operation solve(n : OclAny, base : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; while (n > 0) do ( var remainder : int := n mod base ; result := result + remainder ; n := ("" + ((n / base)))->toInteger()) ; return result; operation printSumsOfDigits(n : OclAny) pre: true post: true activity: for base : Integer.subrange(2, n-1) do ( execute (solve(n, base))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxModValue(arr,n): ans=0 arr=sorted(arr) for j in range(n-2,-1,-1): if(ans>=arr[j]): break if(arr[j]==arr[j+1]): continue i=2*arr[j] while(i<=arr[n-1]+arr[j]): ind=0 for k in arr : if k>=i : ind=arr.index(k) ans=max(ans,arr[ind-1]% arr[j]) i+=arr[j] return ans arr=[3,4,5,9,11] n=5 print(maxModValue(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{9}->union(Sequence{ 11 })))) ; n := 5 ; execute (maxModValue(arr, n))->display(); operation maxModValue(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; arr := arr->sort() ; for j : Integer.subrange(-1 + 1, n - 2)->reverse() do ( if ((ans->compareTo(arr[j+1])) >= 0) then ( break ) else skip ; if (arr[j+1] = arr[j + 1+1]) then ( continue ) else skip ; var i : double := 2 * arr[j+1] ; while ((i->compareTo(arr[n - 1+1] + arr[j+1])) <= 0) do ( var ind : int := 0 ; for k : arr do ( if (k->compareTo(i)) >= 0 then ( ind := arr->indexOf(k) - 1 ) else skip) ; ans := Set{ans, arr[ind - 1+1] mod arr[j+1]}->max() ; i := i + arr[j+1])) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) a=sorted(arr) b=sorted(arr,reverse=True) k=len(arr) if arr==a or arr==b : print("YES") else : i=0 while i=arr[i]: i+=1 while itoInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := arr->sort() ; var b : Sequence := arr->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var k : int := (arr)->size() ; if arr = a or arr = b then ( execute ("YES")->display() ) else ( var i : int := 0 ; while (i->compareTo(k - 1)) < 0 & (arr[i + 1+1]->compareTo(arr[i+1])) >= 0 do ( i := i + 1) ; while (i->compareTo(k - 1)) < 0 & (arr[i + 1+1]->compareTo(arr[i+1])) <= 0 do ( i := i + 1) ; if i = k - 1 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dice=int(input()) top=int(input()) possible=True for i in range(dice): l,r=map(int,input().split()) if top in[l,r,7-l,7-r]: possible=False print("YES" if possible else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dice : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var top : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var possible : boolean := true ; for i : Integer.subrange(0, dice-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (Sequence{l}->union(Sequence{r}->union(Sequence{7 - l}->union(Sequence{ 7 - r }))))->includes(top) then ( possible := false ) else skip) ; execute (if possible then "YES" else "NO" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter import math hpop=heappop hpush=heappush def solution(): y,k,n=map(int,input().split()) res=[] i=0 while k*i<=n : if k*i-y>0 : res.append(k*i-y) i+=1 if not res : print("-1") print(" ".join(map(str,res))) def main(): t=1 for _ in range(t): solution() import sys import threading sys.setrecursionlimit(1<<30) threading.stack_size(1<<27) thread=threading.Thread(target=main) thread.start(); thread.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1 * (2->pow(30))) ; threading.stack_size(1 * (2->pow(27))) ; var thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ; thread.start(); thread.join(); operation solution() pre: true post: true activity: var y : OclAny := null; var k : OclAny := null; var n : OclAny := null; Sequence{y,k,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var res : Sequence := Sequence{} ; var i : int := 0 ; while (k * i->compareTo(n)) <= 0 do ( if k * i - y > 0 then ( execute ((k * i - y) : res) ) else skip ; i := i + 1) ; if not(res) then ( execute ("-1")->display() ) else skip ; execute (StringLib.sumStringsWithSeparator(((res)->collect( _x | (OclType["String"])->apply(_x) )), " "))->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) m=max(a) if a[: a.index(m)+1]==sorted(a[: a.index(m)+1])and a[a.index(m)+1 :][: :-1]==sorted(a[a.index(m)+1 :]): print("yes") else : print("no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : OclAny := (a)->max() ; if a.subrange(1,a->indexOf(m) - 1 + 1) = a.subrange(1,a->indexOf(m) - 1 + 1)->sort() & a.subrange(a->indexOf(m) - 1 + 1+1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) = a.subrange(a->indexOf(m) - 1 + 1+1)->sort() then ( execute ("yes")->display() ) else ( execute ("no")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() n=int(input()) a=[*map(int,input().split())] i=a.index(n) s=sorted print('YNEOS'[a!=s(a[: i])+s(a[i :])[: :-1]: : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var i : int := a->indexOf(n) - 1 ; var s : OclAny := sorted ; execute ('YNEOS'(subscript (test (logical_test (comparison (comparison (expr (atom (name a)))) != (comparison (expr (expr (atom (name s)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))) + (expr (atom (name s)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))) :)) ])))))))) ))) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ])))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) k=list(map(int,input().split())) x=k.index(a)+1 l=k[: x] r=k[x :] la=True na=True m=0 for i in l : if i>m : m=i else : la=False break n=a for i in r : if itoInteger() ; var k : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : int := k->indexOf(a) - 1 + 1 ; var l : OclAny := k.subrange(1,x) ; var r : OclAny := k.subrange(x+1) ; var la : boolean := true ; var na : boolean := true ; var m : int := 0 ; for i : l do ( if (i->compareTo(m)) > 0 then ( m := i ) else ( la := false ; break )) ; var n : int := a ; for i : r do ( if (i->compareTo(n)) < 0 then ( n := i ) else ( na := false ; break )) ; if la & na = true then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) y=z=l.index(n) ans='YES' for i in range(n-1,0,-1): t=-1 if y!=n-1 : if l[y+1]==i : t=0 y+=1 if z>0 : if l[z-1]==i : t=0 z-=1 if t==-1 : ans='NO' break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var y : OclAny := l->indexOf(n) - 1; var z : int := l->indexOf(n) - 1 ; var ans : String := 'YES' ; for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( var t : int := -1 ; if y /= n - 1 then ( if l[y + 1+1] = i then ( t := 0 ; y := y + 1 ) else skip ) else skip ; if z > 0 then ( if l[z - 1+1] = i then ( t := 0 ; z := z - 1 ) else skip ) else skip ; if t = -1 then ( ans := 'NO' ; break ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minOperations(str,n): count=0 for i in range(n-1): if(str[i]!=str[i+1]): count+=1 return(count+1)//2 str="000111" n=len(str) print(minOperations(str,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclType["String"] := "000111" ; n := (OclType["String"])->size() ; execute (minOperations(OclType["String"], n))->display(); operation minOperations(OclType["String"] : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if (("" + ([i+1])) /= ("" + ([i + 1+1]))) then ( count := count + 1 ) else skip) ; return (count + 1) div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) holes=list(map(int,input().split())) holes_dict={} for item in holes : holes_dict[item]=1 final=[] current=1 ; done=False for _ in range(k): a,b=map(int,input().split()) if holes_dict.get(current): done=True if done : continue if a==current : current=b if holes_dict.get(b): done=True elif b==current : current=a if holes_dict.get(a): done=True print(current) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var holes : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var holes_dict : OclAny := Set{} ; for item : holes do ( holes_dict[item+1] := 1) ; var final : Sequence := Sequence{} ; var current : int := 1; var done : boolean := false ; for _anon : Integer.subrange(0, k-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if holes_dict.get(current) then ( done := true ) else skip ; if done then ( continue ) else skip ; if a = current then ( current := b ; if holes_dict.get(b) then ( done := true ) else skip ) else (if b = current then ( current := a ; if holes_dict.get(a) then ( done := true ) else skip ) else skip)) ; execute (current)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() ans=0 for i in range(len(s)): if s[i]=="*" : break elif s[i]=="(" : ans+=1 else : ans-=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = "*" then ( break ) else (if s[i+1] = "(" then ( ans := ans + 1 ) else ( ans := ans - 1 ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=list(input()) N=S.index('*') P=abs(S[0 : N].count('(')-S[0 : N].count(')')) Q=abs(S[N+1 : len(S)].count('(')-S[N+1 : len(S)].count(')')) print(min(P,Q)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var N : int := S->indexOf('*') - 1 ; var P : double := (S.subrange(0+1, N)->count('(') - S.subrange(0+1, N)->count(')'))->abs() ; var Q : double := (S.subrange(N + 1+1, (S)->size())->count('(') - S.subrange(N + 1+1, (S)->size())->count(')'))->abs() ; execute (Set{P, Q}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() while '()' in s : s=s.replace('()','') else : print(s.count('(')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; (compound_stmt while (test (logical_test (comparison (comparison (expr (atom '()'))) in (comparison (expr (atom (name s))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)) (trailer . (name replace) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '()')))))) , (argument (test (logical_test (comparison (expr (atom ''))))))) )))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '('))))))) ))))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=list(input()) S_l=len(S) n=0 l=[] r=[] f_l,f_r=0,0 for n in range(S.index('*')): if S[n]=='(' : f_l+=1 elif S[n]==')' : f_l-=1 for n in range(S_l-S.index('*')): if S[S_l-n-1]==')' : f_r+=1 elif S[S_l-n-1]=='(' : f_r-=1 print(min(f_r,f_l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var S_l : int := (S)->size() ; var n : int := 0 ; var l : Sequence := Sequence{} ; var r : Sequence := Sequence{} ; var f_l : OclAny := null; var f_r : OclAny := null; Sequence{f_l,f_r} := Sequence{0,0} ; for n : Integer.subrange(0, S->indexOf('*') - 1-1) do ( if S[n+1] = '(' then ( f_l := f_l + 1 ) else (if S[n+1] = ')' then ( f_l := f_l - 1 ) else skip)) ; for n : Integer.subrange(0, S_l - S->indexOf('*') - 1-1) do ( if S[S_l - n - 1+1] = ')' then ( f_r := f_r + 1 ) else (if S[S_l - n - 1+1] = '(' then ( f_r := f_r - 1 ) else skip)) ; execute (Set{f_r, f_l}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- line=input() lebel=0 for i in range(len(line)): if line[i]=='*' : print(lebel) break if line[i]=='(' : lebel+=1 elif line[i]==')' : lebel-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var line : String := (OclFile["System.in"]).readLine() ; var lebel : int := 0 ; for i : Integer.subrange(0, (line)->size()-1) do ( if line[i+1] = '*' then ( execute (lebel)->display() ; break ) else skip ; if line[i+1] = '(' then ( lebel := lebel + 1 ) else (if line[i+1] = ')' then ( lebel := lebel - 1 ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- y,k,n=str(input()).split(' ') y=int(y) k=int(k) n=int(n) maxc=int(n/k)+1 minc=int((1+y)/k) c=0 d=1 for i in range(minc,maxc): if i>0 and i*k-y>0 : print(i*k-y,end=' ') c=1 if c==0 : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var y : OclAny := null; var k : OclAny := null; var n : OclAny := null; Sequence{y,k,n} := OclType["String"]((OclFile["System.in"]).readLine()).split(' ') ; var y : int := ("" + ((y)))->toInteger() ; var k : int := ("" + ((k)))->toInteger() ; var n : int := ("" + ((n)))->toInteger() ; var maxc : int := ("" + ((n / k)))->toInteger() + 1 ; var minc : int := ("" + (((1 + y) / k)))->toInteger() ; var c : int := 0 ; var d : int := 1 ; for i : Integer.subrange(minc, maxc-1) do ( if i > 0 & i * k - y > 0 then ( execute (i * k - y)->display() ; c := 1 ) else skip) ; if c = 0 then ( execute (-1)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def mulmod(a,b,mod): res=0 ; a=a % mod ; while(b>0): if(b % 2==1): res=(res+a)% mod ; a=(a*2)% mod ; b//=2 ; return res % mod ; a=9223372036854775807 ; b=9223372036854775807 ; print(mulmod(a,b,100000000000)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 9223372036854775807; ; b := 9223372036854775807; ; execute (mulmod(a, b, 100000000000))->display();; operation mulmod(a : OclAny, b : OclAny, mod : OclAny) pre: true post: true activity: var res : int := 0; ; a := a mod mod; ; while (b > 0) do ( if (b mod 2 = 1) then ( res := (res + a) mod mod; ) else skip ; a := (a * 2) mod mod; ; b := b div 2;) ; return res mod mod;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def parity(a): return a % 3 def solve(array,size): operations=0 for i in range(0,size-1): if parity(array[i])==parity(array[i+1]): operations+=1 if i+2union(Sequence{1}->union(Sequence{3}->union(Sequence{ 0 }))) ; size := (array)->size() ; execute (solve(array, size))->display() ) else skip; operation parity(a : OclAny) : OclAny pre: true post: true activity: return a mod 3; operation solve(array : OclAny, size : OclAny) : OclAny pre: true post: true activity: var operations : int := 0 ; for i : Integer.subrange(0, size - 1-1) do ( if parity(array[i+1]) = parity(array[i + 1+1]) then ( operations := operations + 1 ; if (i + 2->compareTo(size)) < 0 then ( var pari1 : OclAny := parity(array[i+1]) ; var pari2 : OclAny := parity(array[i + 2+1]) ; if pari1 = pari2 then ( if pari1 = 0 then ( array[i + 1+1] := 1 ) else (if pari1 = 1 then ( array[i + 1+1] := 0 ) else ( array[i + 1+1] := 1 ) ) ) else ( if ((pari1 = 0 & pari2 = 1) or (pari1 = 1 & pari2 = 0)) then ( array[i + 1+1] := 2 ) else skip ; if ((pari1 = 1 & pari2 = 2) or (pari1 = 2 & pari2 = 1)) then ( array[i + 1+1] := 0 ) else skip ; if ((pari1 = 2 & pari2 = 0) & (pari1 = 0 & pari2 = 2)) then ( array[i + 1+1] := 1 ) else skip ) ) else skip ) else skip) ; return operations; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSDSFunc(n): DP=[0]*(n+1) DP[0]=0 DP[1]=1 for i in range(2,n+1): if(int(i % 2)==0): DP[i]=DP[int(i/2)] else : DP[i]=(DP[int((i-1)/2)]+DP[int((i+1)/2)]) return DP[n] n=15 print(findSDSFunc(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 15 ; execute (findSDSFunc(n))->display(); operation findSDSFunc(n : OclAny) : OclAny pre: true post: true activity: var DP : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; DP->first() := 0 ; DP[1+1] := 1 ; for i : Integer.subrange(2, n + 1-1) do ( if (("" + ((i mod 2)))->toInteger() = 0) then ( DP[i+1] := DP[("" + ((i / 2)))->toInteger()+1] ) else ( DP[i+1] := (DP[("" + (((i - 1) / 2)))->toInteger()+1] + DP[("" + (((i + 1) / 2)))->toInteger()+1]) )) ; return DP[n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def prework(argv): l=range(1000) def test(func): lg=list(l) func(lg) return check(lg) ans=[(test(good),test(bad))for _ in range(20)] print(*ans,sep='\n',file=sys.stderr) return "above" import random def good(l): n=len(l) for k in range(n): p=random.randint(k,n-1) l[k],l[p]=l[p],l[k] def bad(l): n=len(l) for k in range(n): p=random.randint(0,n-1) l[k],l[p]=l[p],l[k] def check(l): a=len([1 for i,x in enumerate(l)if i-x>0]) b=len([1 for i,x in enumerate(l)if i-x<0]) r=a/b return r>0.94 def once(): n=int(input()) l=[int(x)for x in input().split()] return "GOOD" if check(l)else "BAD" pass def printerr(*v): print(*v,file=sys.stderr) def main(): TT=int(input()) for tt in range(1,TT+1): printerr("coping Case %d.." %(tt)) ans=once() print("Case #%d: %s" %(tt,(ans))) if __name__=='__main__' : msg=prework(sys.argv) print("prework down with",msg,file=sys.stderr) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var msg : OclAny := prework((trailer . (name argv))) ; execute ("prework down with")->display() ; main() ) else skip; operation prework(argv : OclAny) : OclAny pre: true post: true activity: var l : Sequence := Integer.subrange(0, 1000-1) ; skip ; var ans : Sequence := Integer.subrange(0, 20-1)->select(_anon | true)->collect(_anon | (Sequence{test(good), test(bad)})) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ; return "above"; operation good(l : OclAny) pre: true post: true activity: var n : int := (l)->size() ; for k : Integer.subrange(0, n-1) do ( var p : int := (k + (OclRandom.defaultInstanceOclRandom()).nextInt(n - 1 - k)) ; var l[k+1] : OclAny := null; var l[p+1] : OclAny := null; Sequence{l[k+1],l[p+1]} := Sequence{l[p+1],l[k+1]}); operation bad(l : OclAny) pre: true post: true activity: n := (l)->size() ; for k : Integer.subrange(0, n-1) do ( p := (0 + (OclRandom.defaultInstanceOclRandom()).nextInt(n - 1 - 0)) ; var l[k+1] : OclAny := null; var l[p+1] : OclAny := null; Sequence{l[k+1],l[p+1]} := Sequence{l[p+1],l[k+1]}); operation check(l : OclAny) : OclAny pre: true post: true activity: var a : int := (Integer.subrange(1, (l)->size())->collect( _indx | Sequence{_indx-1, (l)->at(_indx)} )->select(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in i - x > 0)->collect(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in (1)))->size() ; var b : int := (Integer.subrange(1, (l)->size())->collect( _indx | Sequence{_indx-1, (l)->at(_indx)} )->select(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in i - x < 0)->collect(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in (1)))->size() ; var r : double := a / b ; return r > 0.94; operation once() : OclAny pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; l := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; return if check(l) then "GOOD" else "BAD" endif ; skip; operation printerr(v : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name v))) execute ((argument * (test (logical_test (comparison (expr (atom (name v))))))))->display(); operation main() pre: true post: true activity: var TT : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for tt : Integer.subrange(1, TT + 1-1) do ( printerr(StringLib.format("coping Case %d..",(tt))) ; ans := once() ; execute (StringLib.format("Case #%d: %s",Sequence{tt, (ans)}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) h=set(map(int,input().split())) ans=1 for i in range(c): u,v=map(int,input().split()) if ans in h : break if u==ans : ans=v else : if v==ans : ans=u print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ans : int := 1 ; for i : Integer.subrange(0, c-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (h)->includes(ans) then ( break ) else skip ; if u = ans then ( ans := v ) else ( if v = ans then ( ans := u ) else skip )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reader(f): f=open(f) for line in f : yield line.strip() f.close() def write(f,lst): for i in xrange(len(lst)): lst[i]="Case #%s:%s" %(i+1,lst[i]) f=open(f,'w') f.write('\n'.join(lst)) f.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip; operation reader(f : OclAny) pre: true post: true activity: f := OclFile.newOclFile_Write(OclFile.newOclFile(f)) ; for line : f do ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return line->trim()) ; f.closeFile(); operation write(f : OclAny, lst : OclAny) pre: true post: true activity: for i : xrange((lst)->size()) do ( lst[i+1] := StringLib.format("Case #%s:%s",Sequence{i + 1, lst[i+1]})) ; f := OclFile.newOclFile_Write(OclFile.newOclFile(f)) ; f.write(StringLib.sumStringsWithSeparator((lst), ' ')) ; f.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math SCALEFACTOR=2 SCALEFACTOR2=0.8 def getProbability(position,number,N=1000): N=float(N) if number>position : p=math.sqrt(position**2+(N-number)**2)/N else : p=math.sqrt((position-N/2)**2+(number-N/2)**2)/N*SCALEFACTOR2 return 1/N-(1/N)*SCALEFACTOR+(p*2*(1/N)*SCALEFACTOR) with open('C.in')as f : with open('C.out','w')as f2 : lines=f.readlines() output="" scores=[] for i in range(int(lines[0])): permutation=[int(n)for n in lines[2+i*2].split(" ")] score=0 for q in range(len(permutation)): score=score+getProbability(q,permutation[q],len(permutation)) scores.append(score) median=sorted(scores)[60] for i in range(len(scores)): score=scores[i] output+="Case #"+str(i+1)+": " if score>median : output+="BAD" else : output+="GOOD" output+="\n" print(output) f2.write(output) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var SCALEFACTOR : int := 2 ; var SCALEFACTOR2 : double := 0.8 ; skip ; try (var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('C.in')); try (var f2 : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('C.out')); var lines : String := f.readlines() ; var output : String := "" ; var scores : Sequence := Sequence{} ; for i : Integer.subrange(0, ("" + ((lines->first())))->toInteger()-1) do ( var permutation : Sequence := lines[2 + i * 2+1].split(" ")->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; var score : int := 0 ; for q : Integer.subrange(0, (permutation)->size()-1) do ( score := score + getProbability(q, permutation[q+1], (permutation)->size())) ; execute ((score) : scores)) ; var median : OclAny := sorted(scores)[60+1] ; for i : Integer.subrange(0, (scores)->size()-1) do ( score := scores[i+1] ; output := output + "Case #" + ("" + ((i + 1))) + ": " ; if (score->compareTo(median)) > 0 then ( output := output + "BAD" ) else ( output := output + "GOOD" ) ; output := output + "\n") ; execute (output)->display() ; f2.write(output)) catch (_e : OclException) do skip) catch (_e : OclException) do skip; operation getProbability(position : OclAny, number : OclAny, N : int) : OclAny pre: true post: true activity: if N->oclIsUndefined() then N := 1000 else skip; N := ("" + ((N)))->toReal() ; if (number->compareTo(position)) > 0 then ( var p : double := ((position)->pow(2) + ((N - number))->pow(2))->sqrt() / N ) else ( p := (((position - N / 2))->pow(2) + ((number - N / 2))->pow(2))->sqrt() / N * SCALEFACTOR2 ) ; return 1 / N - (1 / N) * SCALEFACTOR + (p * 2 * (1 / N) * SCALEFACTOR); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import random import numpy as np import sys import math def bad(n): xs=list(range(n)) for i in range(n): p=random.randint(0,n-1) xs[i],xs[p]=xs[p],xs[i] return xs def bad_dist(n): ds=np.eye(n) for i in range(n): ds_new=ds.copy() ds/=n for p in range(n): if i==p : continue ds_new[i]-=ds[i] ds_new[p]-=ds[p] ds_new[i]+=ds[p] ds_new[p]+=ds[i] ds=ds_new return ds len_seq=1000 bd=bad_dist(len_seq) log_bd=np.log(bd) n_cases=int(sys.stdin.readline()) for i_case in range(n_cases): sys.stdin.readline() ns=list(map(int,sys.stdin.readline().split())) log_p_good=math.log(1/len_seq)*len_seq+math.log(0.5) log_p_s_bad=0 for(i,n)in enumerate(ns): log_p_s_bad+=log_bd[i][n] log_p_bad=log_p_s_bad+math.log(0.5) res='GOOD' if log_p_good>log_p_bad else 'BAD' print("Case #%d: %s" %(i_case+1,res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var len_seq : int := 1000 ; var bd : OclAny := bad_dist(len_seq) ; var log_bd : Sequence := MatrixLib.elementwiseApply(bd, lambda x : double in (x->log())) ; var n_cases : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i_case : Integer.subrange(0, n_cases-1) do ((expr (atom (name sys)) (trailer . (name stdin)) (trailer . (name readline) (arguments ( )))) ; var ns : Sequence := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var log_p_good : double := (1 / len_seq)->log() * len_seq + (0.5)->log() ; var log_p_s_bad : int := 0 ; for Sequence{i, n} : Integer.subrange(1, (ns)->size())->collect( _indx | Sequence{_indx-1, (ns)->at(_indx)} ) do ( log_p_s_bad := log_p_s_bad + log_bd[i+1][n+1]) ; var log_p_bad : int := log_p_s_bad + (0.5)->log() ; var res : String := if (log_p_good->compareTo(log_p_bad)) > 0 then 'GOOD' else 'BAD' endif ; execute (StringLib.format("Case #%d: %s",Sequence{i_case + 1, res}))->display()); operation bad(n : OclAny) : OclAny pre: true post: true activity: var xs : Sequence := (Integer.subrange(0, n-1)) ; for i : Integer.subrange(0, n-1) do ( var p : int := (0 + (OclRandom.defaultInstanceOclRandom()).nextInt(n - 1 - 0)) ; var xs[i+1] : OclAny := null; var xs[p+1] : OclAny := null; Sequence{xs[i+1],xs[p+1]} := Sequence{xs[p+1],xs[i+1]}) ; return xs; operation bad_dist(n : OclAny) : OclAny pre: true post: true activity: var ds : Sequence := MatrixLib.identityMatrix(n) ; for i : Integer.subrange(0, n-1) do ( var ds_new : OclAny := ds->copy() ; ds := ds / n ; for p : Integer.subrange(0, n-1) do ( if i = p then ( continue ) else skip ; ds_new[i+1] := ds_new[i+1] - ds[i+1] ; ds_new[p+1] := ds_new[p+1] - ds[p+1] ; ds_new[i+1] := ds_new[i+1] + ds[p+1] ; ds_new[p+1] := ds_new[p+1] + ds[i+1]) ; ds := ds_new) ; return ds; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countBA(perm): b=0 for i in range(len(perm)): if perm.index(i)515 else 'GOOD' for t in range(int(input())): N=int(input()) perm=list(map(int,input().split())) print('Case #{}:{}'.format(t+1,determine(perm))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; perm := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (StringLib.interpolateStrings('Case #{}:{}', Sequence{t + 1, determine(perm)}))->display()); operation countBA(perm : OclAny) : OclAny pre: true post: true activity: var b : int := 0 ; for i : Integer.subrange(0, (perm)->size()-1) do ( if (perm->indexOf(i) - 1->compareTo(i)) < 0 then ( b := b + 1 ) else skip) ; return b; operation determine(perm : OclAny) : OclAny pre: true post: true activity: return if countBA(perm) > 515 then 'BAD' else 'GOOD' endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect def count(x,Y,n,NoOfY): if x==0 : return 0 if x==1 : return NoOfY[0] idx=bisect.bisect_right(Y,x) ans=n-idx ans+=NoOfY[0]+NoOfY[1] if x==2 : ans-=NoOfY[3]+NoOfY[4] if x==3 : ans+=NoOfY[2] return ans def count_pairs(X,Y,m,n): NoOfY=[0]*5 for i in range(n): if Y[i]<5 : NoOfY[Y[i]]+=1 Y.sort() total_pairs=0 for x in X : total_pairs+=count(x,Y,n,NoOfY) return total_pairs if __name__=='__main__' : X=[2,1,6] Y=[1,5] print("Total pairs=",count_pairs(X,Y,len(X),len(Y))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( X := Sequence{2}->union(Sequence{1}->union(Sequence{ 6 })) ; Y := Sequence{1}->union(Sequence{ 5 }) ; execute ("Total pairs=")->display() ) else skip; operation count(x : OclAny, Y : OclAny, n : OclAny, NoOfY : OclAny) : OclAny pre: true post: true activity: if x = 0 then ( return 0 ) else skip ; if x = 1 then ( return NoOfY->first() ) else skip ; var idx : OclAny := bisect.bisect_right(Y, x) ; var ans : double := n - idx ; ans := ans + NoOfY->first() + NoOfY[1+1] ; if x = 2 then ( ans := ans - NoOfY[3+1] + NoOfY[4+1] ) else skip ; if x = 3 then ( ans := ans + NoOfY[2+1] ) else skip ; return ans; operation count_pairs(X : OclAny, Y : OclAny, m : OclAny, n : OclAny) : OclAny pre: true post: true activity: NoOfY := MatrixLib.elementwiseMult(Sequence{ 0 }, 5) ; for i : Integer.subrange(0, n-1) do ( if Y[i+1] < 5 then ( NoOfY[Y[i+1]+1] := NoOfY[Y[i+1]+1] + 1 ) else skip) ; Y := Y->sort() ; var total_pairs : int := 0 ; for x : X do ( total_pairs := total_pairs + count(x, Y, n, NoOfY)) ; return total_pairs; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) if(n &(n-1)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (MathLib.bitwiseAnd(n, (n - 1))) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- y,k,n=map(int,input().split()) if(y+k-(y % k)collect( _x | (OclType["int"])->apply(_x) ) ; if ((y + k - (y mod k)->compareTo(n + 1)) < 0) then ( for i : Integer.subrange(y + k - (y mod k), n + 1-1)->select( $x | ($x - y + k - (y mod k)) mod k = 0 ) do ( execute (i - y)->display()) ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get(): return int(input()) for _ in range(get()): n=get() while n % 2==0 : n//=2 if n==1 : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, get()-1) do ( var n : OclAny := get() ; while n mod 2 = 0 do ( n := n div 2) ; if n = 1 then ( execute ("NO")->display() ) else ( execute ("YES")->display() )); operation get() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def Log2(x): if x==0 : return False return(math.log10(x)/math.log10(2)) def isPowerOfTwo(n): return(math.ceil(Log2(n))==math.floor(Log2(n))) for _ in range(int(input())): n=int(input()) if isPowerOfTwo(n)==True : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if isPowerOfTwo(n) = true then ( execute ("NO")->display() ) else ( execute ("YES")->display() )); operation Log2(x : OclAny) : OclAny pre: true post: true activity: if x = 0 then ( return false ) else skip ; return ((x)->log10() / (2)->log10()); operation isPowerOfTwo(n : OclAny) : OclAny pre: true post: true activity: return ((Log2(n))->ceil() = (Log2(n))->floor()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) if n &(n-1): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if MathLib.bitwiseAnd(n, (n - 1)) then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) h=set(map(int,input().split())) ans=1 for i in range(c): u,v=map(int,input().split()) if ans in h : break if u==ans : ans=v else : if v==ans : ans=u print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ans : int := 1 ; for i : Integer.subrange(0, c-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (h)->includes(ans) then ( break ) else skip ; if u = ans then ( ans := v ) else ( if v = ans then ( ans := u ) else skip )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input(''))): n=int(input('')) l=input().split() print(l.count('1')+l.count('3')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine(''))))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; var l : OclAny := input().split() ; execute (l->count('1') + l->count('3'))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) for i in range(num): lenz=int(input()) arr=input() arr=arr.split(" ") two=arr.count("2") print(lenz-two) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, num-1) do ( var lenz : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : String := (OclFile["System.in"]).readLine() ; arr := arr.split(" ") ; var two : int := arr->count("2") ; execute (lenz - two)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* from collections import* from itertools import* for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) l.sort(reverse=True) u=0 d=0 for i in range(n): if l[i]==1 : u+=1 elif l[i]==2 : d+=1 elif l[i]==3 and u>=d : u+=1 elif l[i]==3 and d>u : d+=1 print(u) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := l->sort() ; var u : int := 0 ; var d : int := 0 ; for i : Integer.subrange(0, n-1) do ( if l[i+1] = 1 then ( u := u + 1 ) else (if l[i+1] = 2 then ( d := d + 1 ) else (if l[i+1] = 3 & (u->compareTo(d)) >= 0 then ( u := u + 1 ) else (if l[i+1] = 3 & (d->compareTo(u)) > 0 then ( d := d + 1 ) else skip ) ) ) ) ; execute (u)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): x=int(input()) n=list(map(int,input().split())) print(n.count(1)+n.count(3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (n->count(1) + n->count(3))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): x=int(input()) l=list(map(int,input().split())) c=0 for j in l : if(j==1 or j==3): c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; for j : l do ( if (j = 1 or j = 3) then ( c := c + 1 ) else skip) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w,h,a=input().split() w,h=int(w),int(h) for i in range(h): if i in{0,h-1}: print("+"+"-"*(w-2)+"+") else : print("|"+"."*((w-2)//2)+a+"."*((w-2)//2)+"|" if i==h//2 else "|"+"."*(w-2)+"|") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : OclAny := null; var h : OclAny := null; var a : OclAny := null; Sequence{w,h,a} := input().split() ; var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := Sequence{("" + ((w)))->toInteger(),("" + ((h)))->toInteger()} ; for i : Integer.subrange(0, h-1) do ( if (Set{0}->union(Set{ h - 1 }))->includes(i) then ( execute ("+" + StringLib.nCopies("-", (w - 2)) + "+")->display() ) else ( execute (if i = h div 2 then "|" + StringLib.nCopies(".", ((w - 2) div 2)) + a + StringLib.nCopies(".", ((w - 2) div 2)) + "|" else "|" + StringLib.nCopies(".", (w - 2)) + "|" endif)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lines=input().split() w=int(lines[0]) h=int(lines[1]) c=lines[2] for i in range(h): for j in range(w): if i==0 or i==(h-1): if j==0 or j==(w-1): print("+",end="") else : print("-",end="") else : if i==(h//2)and j==(w//2): print(c,end="") elif j==0 or j==(w-1): print("|",end="") else : print(".",end="") print("") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lines : OclAny := input().split() ; var w : int := ("" + ((lines->first())))->toInteger() ; var h : int := ("" + ((lines[1+1])))->toInteger() ; var c : OclAny := lines[2+1] ; for i : Integer.subrange(0, h-1) do ( for j : Integer.subrange(0, w-1) do ( if i = 0 or i = (h - 1) then ( if j = 0 or j = (w - 1) then ( execute ("+")->display() ) else ( execute ("-")->display() ) ) else ( if i = (h div 2) & j = (w div 2) then ( execute (c)->display() ) else (if j = 0 or j = (w - 1) then ( execute ("|")->display() ) else ( execute (".")->display() ) ) )) ; execute ("")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) for t in range(int(input())): n,k=map(int,input().split()) x=list(map(int,input().split())) print(max([x[0],n-x[-1]+1]+[(x[i+1]-x[i])//2+1 for i in range(k-1)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((Sequence{x->first()}->union(Sequence{ n - x->last() + 1 })->union(Integer.subrange(0, k - 1-1)->select(i | true)->collect(i | ((x[i + 1+1] - x[i+1]) div 2 + 1))))->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w,h,c=input().split() w=int(w) h=int(h) flag="+" for _ in range(w-2): flag+="-" flag+="+" print(flag) for i in range(1,h-1): flag="|" if i!=h//2 : for _ in range(w-2): flag+="." flag+="|" else : for j in range(1,w-1): if j!=w//2 : flag+="." else : flag+=c flag+="|" print(flag) flag="+" for _ in range(w-2): flag+="-" flag+="+" print(flag) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : OclAny := null; var h : OclAny := null; var c : OclAny := null; Sequence{w,h,c} := input().split() ; var w : int := ("" + ((w)))->toInteger() ; var h : int := ("" + ((h)))->toInteger() ; var flag : String := "+" ; for _anon : Integer.subrange(0, w - 2-1) do ( flag := flag + "-") ; flag := flag + "+" ; execute (flag)->display() ; for i : Integer.subrange(1, h - 1-1) do ( flag := "|" ; if i /= h div 2 then ( for _anon : Integer.subrange(0, w - 2-1) do ( flag := flag + ".") ; flag := flag + "|" ) else ( for j : Integer.subrange(1, w - 1-1) do ( if j /= w div 2 then ( flag := flag + "." ) else ( flag := flag + c )) ; flag := flag + "|" ) ; execute (flag)->display()) ; flag := "+" ; for _anon : Integer.subrange(0, w - 2-1) do ( flag := flag + "-") ; flag := flag + "+" ; execute (flag)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,h=map(str,input().split()) ans=[] n=int(n) m=int(m) for i in range(m): ss="" for j in range(n): if i==m//2 and j==n//2 : ss+=h elif(i==0 or i==m-1)and(j==0 or j==n-1): ss+="+" elif i==0 or i==m-1 : ss+="-" elif j==0 or j==n-1 : ss+="|" else : ss+="." ans.append(ss) for i in range(m): print("".join(ans[i])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var h : OclAny := null; Sequence{n,m,h} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; var ans : Sequence := Sequence{} ; var n : int := ("" + ((n)))->toInteger() ; var m : int := ("" + ((m)))->toInteger() ; for i : Integer.subrange(0, m-1) do ( var ss : String := "" ; for j : Integer.subrange(0, n-1) do ( if i = m div 2 & j = n div 2 then ( ss := ss + h ) else (if (i = 0 or i = m - 1) & (j = 0 or j = n - 1) then ( ss := ss + "+" ) else (if i = 0 or i = m - 1 then ( ss := ss + "-" ) else (if j = 0 or j = n - 1 then ( ss := ss + "|" ) else ( ss := ss + "." ) ) ) ) ) ; execute ((ss) : ans)) ; for i : Integer.subrange(0, m-1) do ( execute (StringLib.sumStringsWithSeparator((ans[i+1]), ""))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline NCups,NHoles,swap=map(int,input().split()); pos=1 ; dic=dict() def convert(n): dic[n]=1 for i in range(1,NCups+1): dic[i]=0 holes=input().split() for i in holes : convert(int(i)) if dic[pos]: print(1) else : for i in range(swap): x,y=map(int,input().split()) if x==pos : pos=y if dic[y]: print(pos); break elif y==pos : pos=x if dic[x]: print(pos); break else : print(pos) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; var NCups : OclAny := null; var NHoles : OclAny := null; var swap : OclAny := null; Sequence{NCups,NHoles,swap} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var pos : int := 1; var dic : Map := (arguments ( )) ; skip ; for i : Integer.subrange(1, NCups + 1-1) do ( dic[i+1] := 0) ; var holes : OclAny := input().split() ; for i : holes do ( convert(("" + ((i)))->toInteger())) ; if dic[pos+1] then ( execute (1)->display() ) else ( (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name swap)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name x)))))) , (test (logical_test (comparison (expr (atom (name y))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name x)))) == (comparison (expr (atom (name pos))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name pos)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name y)))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name dic)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name pos)))))))) )))))))))) ; (small_stmt break))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name y)))) == (comparison (expr (atom (name pos))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name pos)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name dic)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name pos)))))))) )))))))))) ; (small_stmt break))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name pos)))))))) ))))))))))))))) ); operation convert(n : OclAny) pre: true post: true activity: dic[n+1] := 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- W,H,c=input().split(); W=int(W); H=int(H) print("+"+"-"*(W-2)+"+") for i in range((H-3)//2): print("|"+"."*(W-2)+"|") print("|"+"."*((W-3)//2)+c+"."*((W-3)//2)+"|") for i in range((H-3)//2): print("|"+"."*(W-2)+"|") print("+"+"-"*(W-2)+"+") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var W : OclAny := null; var H : OclAny := null; var c : OclAny := null; Sequence{W,H,c} := input().split(); var W : int := ("" + ((W)))->toInteger(); var H : int := ("" + ((H)))->toInteger() ; execute ("+" + StringLib.nCopies("-", (W - 2)) + "+")->display() ; for i : Integer.subrange(0, (H - 3) div 2-1) do ( execute ("|" + StringLib.nCopies(".", (W - 2)) + "|")->display()) ; execute ("|" + StringLib.nCopies(".", ((W - 3) div 2)) + c + StringLib.nCopies(".", ((W - 3) div 2)) + "|")->display() ; for i : Integer.subrange(0, (H - 3) div 2-1) do ( execute ("|" + StringLib.nCopies(".", (W - 2)) + "|")->display()) ; execute ("+" + StringLib.nCopies("-", (W - 2)) + "+")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=list(map(int,input().split())) b=[min(1+k,n)]*n for i in range(1,n): x=a[i]-1 if x==-1 : b[i]=min(i,k)+1+min(n-i-1,k) else : b[i]=b[x]+min(k+1,i-(x+min(k,n-x-1)))+min(n-i-1,k) print(*b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ Set{1 + k, n}->min() }, n) ; for i : Integer.subrange(1, n-1) do ( var x : double := a[i+1] - 1 ; if x = -1 then ( b[i+1] := Set{i, k}->min() + 1 + Set{n - i - 1, k}->min() ) else ( b[i+1] := b[x+1] + Set{k + 1, i - (x + Set{k, n - x - 1}->min())}->min() + Set{n - i - 1, k}->min() )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name b))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) l=list(map(int,input().split())) dp=[0]*n dp[0]=min(m+1,n) print(dp[0],end=" ") for i in range(1,n): if l[i]==0 : v2=min(n-1,i+m) v1=max(0,i-m) dp[i]=v2-v1+1 print(dp[i],end=" ") continue v2=min(n-1,i+m) v1=max(0,i-m) v3=max(0,l[i]-1-m) v4=min(n-1,l[i]-1+m) dp[i]=dp[l[i]-1]+(v2-v1+1)-max(0,min(v2,v4)-max(v1,v3)+1) print(dp[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; dp->first() := Set{m + 1, n}->min() ; execute (dp->first())->display() ; for i : Integer.subrange(1, n-1) do ( if l[i+1] = 0 then ( var v2 : OclAny := Set{n - 1, i + m}->min() ; var v1 : OclAny := Set{0, i - m}->max() ; dp[i+1] := v2 - v1 + 1 ; execute (dp[i+1])->display() ; continue ) else skip ; v2 := Set{n - 1, i + m}->min() ; v1 := Set{0, i - m}->max() ; var v3 : OclAny := Set{0, l[i+1] - 1 - m}->max() ; var v4 : OclAny := Set{n - 1, l[i+1] - 1 + m}->min() ; dp[i+1] := dp[l[i+1] - 1+1] + (v2 - v1 + 1) - Set{0, Set{v2, v4}->min() - Set{v1, v3}->max() + 1}->max() ; execute (dp[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(a,k): a=list(map(lambda s : s-1,a)) n=len(a) dp=[0]*(len(a)) for i in range(n): if a[i]==-1 : dp[i]=1+min(n-i-1,k)+min(i,k) else : dp[i]=min(min(n-1,i+k)-min(n-1,a[i]+k),1+min(i,k)+min(n-i-1,k))+dp[a[i]] return dp a,b=map(int,input().strip().split()) lst=list(map(int,input().strip().split())) print(*f(lst,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var b : OclAny := null; Sequence{a,b} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lst : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name f)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name lst))))))) , (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))))))))->display(); operation f(a : OclAny, k : OclAny) : OclAny pre: true post: true activity: a := ((a)->collect( _x | (lambda s : OclAny in (s - 1))->apply(_x) )) ; var n : int := (a)->size() ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((a)->size())) ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = -1 then ( dp[i+1] := 1 + Set{n - i - 1, k}->min() + Set{i, k}->min() ) else ( dp[i+1] := Set{Set{n - 1, i + k}->min() - Set{n - 1, a[i+1] + k}->min(), 1 + Set{i, k}->min() + Set{n - i - 1, k}->min()}->min() + dp[a[i+1]+1] )) ; return dp; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): nMessages,nVisibleMessages=map(int,input().split()) return nReadableMessages(nMessages,nVisibleMessages,[0]+list(map(int,input().split()))) def nReadableMessages(nMsgs,msgRange,msgs): nMsgsInFirstScreen=1+msgRange if nMsgs<=nMsgsInFirstScreen : return f'{nMsgs}'*nMsgs msgs[1]=(nMsgsInFirstScreen,nMsgsInFirstScreen) nOnScreenMsgs=1+2*msgRange i=1 while msgs[i][1]=iFirst : msgs[i]=(msgs[msgs[i]][0]+i-msgs[i],i+msgRange) else : msgs[i]=(msgs[msgs[i]][0]+nOnScreenMsgs,i+msgRange) for j in range(i+1,len(msgs)): nOnScreenMsgs-=1 jFirst=j-msgRange if jFirst<1 : msgs[i]=(nMsgs,nMsgs) elif not msgs[j]: msgs[j]=(nOnScreenMsgs,nMsgs) elif msgs[msgs[j]][1]>=jFirst : msgs[j]=(msgs[msgs[j]][0]+nMsgs-msgs[msgs[j]][1],nMsgs) else : msgs[j]=(msgs[msgs[j]][0]+nOnScreenMsgs,nMsgs) return ' '.join(map(lambda x : str(x[0]),msgs[1 :])) if __name__=='__main__' : print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( execute (main())->display() ) else skip; operation main() : OclAny pre: true post: true activity: var nMessages : OclAny := null; var nVisibleMessages : OclAny := null; Sequence{nMessages,nVisibleMessages} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; return nReadableMessages(nMessages, nVisibleMessages, Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) )))); operation nReadableMessages(nMsgs : OclAny, msgRange : OclAny, msgs : OclAny) : OclAny pre: true post: true activity: var nMsgsInFirstScreen : int := 1 + msgRange ; if (nMsgs->compareTo(nMsgsInFirstScreen)) <= 0 then ( return StringLib.formattedString('{nMsgs}') * nMsgs ) else skip ; msgs[1+1] := Sequence{nMsgsInFirstScreen, nMsgsInFirstScreen} ; var nOnScreenMsgs : int := 1 + 2 * msgRange ; var i : int := 1 ; while (msgs[i+1][1+1]->compareTo(nMsgs)) < 0 do ( i := i + 1 ; var iFirst : double := i - msgRange ; if iFirst < 1 then ( msgs[i+1] := Sequence{nOnScreenMsgs - 1 + iFirst, i + msgRange} ) else (if not(msgs[i+1]) then ( msgs[i+1] := Sequence{nOnScreenMsgs, i + msgRange} ) else (if (msgs[msgs[i+1]+1][1+1]->compareTo(iFirst)) >= 0 then ( msgs[i+1] := Sequence{msgs[msgs[i+1]+1]->first() + i - msgs[i+1], i + msgRange} ) else ( msgs[i+1] := Sequence{msgs[msgs[i+1]+1]->first() + nOnScreenMsgs, i + msgRange} ) ) ) ) ; for j : Integer.subrange(i + 1, (msgs)->size()-1) do ( nOnScreenMsgs := nOnScreenMsgs - 1 ; var jFirst : double := j - msgRange ; if jFirst < 1 then ( msgs[i+1] := Sequence{nMsgs, nMsgs} ) else (if not(msgs[j+1]) then ( msgs[j+1] := Sequence{nOnScreenMsgs, nMsgs} ) else (if (msgs[msgs[j+1]+1][1+1]->compareTo(jFirst)) >= 0 then ( msgs[j+1] := Sequence{msgs[msgs[j+1]+1]->first() + nMsgs - msgs[msgs[j+1]+1][1+1], nMsgs} ) else ( msgs[j+1] := Sequence{msgs[msgs[j+1]+1]->first() + nOnScreenMsgs, nMsgs} ) ) ) ) ; return StringLib.sumStringsWithSeparator(((msgs->tail())->collect( _x | (lambda x : OclAny in (("" + ((x->first())))))->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solution(): res=[min(len(mas),_k+1)] for i in range(1,len(mas)): k_right=min(len(mas)-1,i+_k) k_left=max(0,i-_k) if mas[i]!=0 : cross=0 k_right_last=min(len(mas)-1,mas[i]-1+_k) if k_left<=k_right_last : cross=k_right_last-k_left+1 res.append(res[mas[i]-1]+(k_right-k_left+1)-cross) else : res.append(k_right-k_left+1) return res if __name__=='__main__' : _n,_k=map(int,input().rstrip().split()) mas=[int(x)for x in input().rstrip().split()] print(*solution()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var _n : OclAny := null; var _k : OclAny := null; Sequence{_n,_k} := (input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mas : Sequence := input().rstrip().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((argument * (test (logical_test (comparison (expr (atom (name solution)) (trailer (arguments ( )))))))))->display() ) else skip; operation solution() : OclAny pre: true post: true activity: var res : Sequence := Sequence{ Set{(mas)->size(), _k + 1}->min() } ; for i : Integer.subrange(1, (mas)->size()-1) do ( var k_right : OclAny := Set{(mas)->size() - 1, i + _k}->min() ; var k_left : OclAny := Set{0, i - _k}->max() ; if mas[i+1] /= 0 then ( var cross : int := 0 ; var k_right_last : OclAny := Set{(mas)->size() - 1, mas[i+1] - 1 + _k}->min() ; if (k_left->compareTo(k_right_last)) <= 0 then ( cross := k_right_last - k_left + 1 ) else skip ; execute ((res[mas[i+1] - 1+1] + (k_right - k_left + 1) - cross) : res) ) else ( execute ((k_right - k_left + 1) : res) )) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : t-=1 n,k=(int(_)for _ in input().strip().split('')) c=[] for i in range(1,n+1): if i % 3==1 : c.append('a') if i % 3==2 : c.append('b') if i % 3==0 : c.append('c') for i in c[:-1]: print(i,end='') print(c[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( t := t - 1 ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name _)))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name strip) (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ''))))))) ))))))))} ; var c : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( if i mod 3 = 1 then ( execute (('a') : c) ) else skip ; if i mod 3 = 2 then ( execute (('b') : c) ) else skip ; if i mod 3 = 0 then ( execute (('c') : c) ) else skip) ; for i : c->front() do ( execute (i)->display()) ; execute (c->last())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,k=map(int,input().split()) s='abc'*n print(s[0 : n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := StringLib.nCopies('abc', n) ; execute (s.subrange(0+1, n))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def resolve(n,k,k_list): r=n-k if r<2 : return r+1 l=k_list[0] r=n-k_list[-1]+1 lr_max=l if l>r else r if(k>1): k_list=[k_list[j+1]-k_list[j]for j in range(k-1)] k_max=max(k_list)//2+1 r=lr_max if lr_max>k_max else k_max return r else : return lr_max if __name__=="__main__" : t=int(input()) for i in range(t): N,K=map(int,input().split()) K_list=list(map(int,input().split())) print(resolve(N,K,K_list)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var K_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (resolve(N, K, K_list))->display()) ) else skip; operation resolve(n : OclAny, k : OclAny, k_list : OclAny) : OclAny pre: true post: true activity: var r : double := n - k ; if r < 2 then ( return r + 1 ) else skip ; var l : OclAny := k_list->first() ; r := n - k_list->last() + 1 ; var lr_max : OclAny := if (l->compareTo(r)) > 0 then l else r endif ; if (k > 1) then ( k_list := Integer.subrange(0, k - 1-1)->select(j | true)->collect(j | (k_list[j + 1+1] - k_list[j+1])) ; var k_max : int := (k_list)->max() div 2 + 1 ; r := if (lr_max->compareTo(k_max)) > 0 then lr_max else k_max endif ; return r ) else ( return lr_max ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : n,m=map(int,input().split()) q=0 while n : if q==0 : print('a',end='') q=1 elif q==1 : print('b',end='') q=2 else : print('c',end='') q=0 n-=1 print() t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var q : int := 0 ; while n do ( if q = 0 then ( execute ('a')->display() ; q := 1 ) else (if q = 1 then ( execute ('b')->display() ; q := 2 ) else ( execute ('c')->display() ; q := 0 ) ) ; n := n - 1) ; execute (->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : a,op,b=map(str,input().split()) if op=="+" : print(int(a)+int(b)) elif op=="-" : print(int(a)-int(b)) elif op=="*" : print(int(a)*int(b)) elif op=="/" : print(int(int(a)/int(b))) else : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var a : OclAny := null; var op : OclAny := null; var b : OclAny := null; Sequence{a,op,b} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; if op = "+" then ( execute (("" + ((a)))->toInteger() + ("" + ((b)))->toInteger())->display() ) else (if op = "-" then ( execute (("" + ((a)))->toInteger() - ("" + ((b)))->toInteger())->display() ) else (if op = "*" then ( execute (("" + ((a)))->toInteger() * ("" + ((b)))->toInteger())->display() ) else (if op = "/" then ( execute (("" + ((("" + ((a)))->toInteger() / ("" + ((b)))->toInteger())))->toInteger())->display() ) else ( break ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n,k=map(int,input().split()) ans='c'*k w='abc' for i in range(n-k): ans+=w[i % 3] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : String := StringLib.nCopies('c', k) ; var w : String := 'abc' ; for i : Integer.subrange(0, n - k-1) do ( ans := ans + w[i mod 3+1]) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout def solution(n,k): output=[] chars=['a','b','c'] for idx in range(n): output.append(chars[idx % 3]) return ''.join(output) test_cases=int(stdin.readline()) for it in range(test_cases): n,k=(int(x)for x in stdin.readline().split()) stdout.write(str(solution(n,k))+'\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var test_cases : int := ("" + ((stdin.readLine())))->toInteger() ; for it : Integer.subrange(0, test_cases-1) do ( Sequence{n,k} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name stdin)) (trailer . (name readline) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; stdout.write(("" + ((solution(n, k)))) + ' ')); operation solution(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var output : Sequence := Sequence{} ; var chars : Sequence := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{ 'c' })) ; for idx : Integer.subrange(0, n-1) do ( execute ((chars[idx mod 3+1]) : output)) ; return StringLib.sumStringsWithSeparator((output), ''); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def countPairs(a,n): frequency=defaultdict(int) for i in range(n): frequency[a[i]]+=1 count=0 for x in frequency.keys(): f=frequency[x] count+=f*(f-1)//2 return count if __name__=="__main__" : arr=[1,1,1] n=len(arr) print(countPairs(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var arr : Sequence := Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })) ; n := (arr)->size() ; execute (countPairs(arr, n))->display() ) else skip; operation countPairs(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var frequency : OclAny := defaultdict(OclType["int"]) ; for i : Integer.subrange(0, n-1) do ( frequency[a[i+1]+1] := frequency[a[i+1]+1] + 1) ; var count : int := 0 ; for x : frequency.keys() do ( var f : OclAny := frequency[x+1] ; count := count + f * (f - 1) div 2) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) m=0 for day in range(1,c+1): m+=a if day % 7==0 : m+=b if m>=c : break print(day) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : int := 0 ; for day : Integer.subrange(1, c + 1-1) do ( m := m + a ; if day mod 7 = 0 then ( m := m + b ) else skip ; if (m->compareTo(c)) >= 0 then ( break ) else skip) ; execute (day)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math A,B,C=map(int,input().split()) x=C//(A*7+B) y=C %(A*7+B) z=math.ceil(y/A) r=math.ceil(z/(A*7+B)) if z>=7 : print(x*7+7*r) else : print(x*7+z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{A,B,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : int := C div (A * 7 + B) ; var y : int := C mod (A * 7 + B) ; var z : double := (y / A)->ceil() ; var r : double := (z / (A * 7 + B))->ceil() ; if z >= 7 then ( execute (x * 7 + 7 * r)->display() ) else ( execute (x * 7 + z)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys a,b,c=input().split() i=0 sum=0 while sumcompareTo(("" + ((c)))->toInteger())) < 0 do ( i := i + 1 ; sum := sum + ("" + ((a)))->toInteger() ; if i mod 7 = 0 then ( sum := sum + ("" + ((b)))->toInteger() ) else skip) ; execute (i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): A,B,C=map(int,input().split()) count=0 coins=0 while True : if coins>=C : break count+=1 coins+=A if count % 7==0 : coins+=B print(count) if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{A,B,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var count : int := 0 ; var coins : int := 0 ; while true do ( if (coins->compareTo(C)) >= 0 then ( break ) else skip ; count := count + 1 ; coins := coins + A ; if count mod 7 = 0 then ( coins := coins + B ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math (A,B,C)=list(map(int,input().split())) cnt=0 coin=0 if A*7=C : cnt=7 else : week_num=math.floor(C/(A*7+B)) cnt=week_num*7 coin=week_num*(A*7+B) if A*7collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : int := 0 ; var coin : int := 0 ; if (A * 7->compareTo(C)) < 0 then ( if (A * 7 + B->compareTo(C)) >= 0 then ( cnt := 7 ) else ( var week_num : double := (C / (A * 7 + B))->floor() ; cnt := week_num * 7 ; coin := week_num * (A * 7 + B) ; if (A * 7->compareTo(C - coin)) < 0 then ( cnt := cnt + 7 ) else ( cnt := cnt + ((C - coin) / A)->ceil() ) ) ) else ( cnt := cnt + ((C - coin) / A)->ceil() ) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def trianglearea(r): if r<0 : return-1 return r*r if __name__=="__main__" : r=5 print(trianglearea(r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( r := 5 ; execute (trianglearea(r))->display() ) else skip; operation trianglearea(r : OclAny) : OclAny pre: true post: true activity: if r < 0 then ( return -1 ) else skip ; return r * r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n,k=map(int,input().split()) x=list(map(int,input().split())) if k==1 : print(max(x[0],n-x[0]+1)) else : minx=1 maxn=n res=0 if x[0]>1 : res=max(res,x[0]) if x[-1]toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if k = 1 then ( execute (Set{x->first(), n - x->first() + 1}->max())->display() ) else ( var minx : int := 1 ; var maxn : OclAny := n ; var res : int := 0 ; if x->first() > 1 then ( res := Set{res, x->first()}->max() ) else skip ; if (x->last()->compareTo(n)) < 0 then ( res := Set{res, n - x->last() + 1}->max() ) else skip ; x := Sequence{ minx }->union(x)->union(Sequence{ maxn }) ; for i : Integer.subrange(1, (x)->size()-1) do ( var d : double := x[i+1] - x[i - 1+1] + 1 ; if d mod 2 = 1 then ( res := Set{res, d div 2 + 1}->max() ) else ( res := Set{res, d div 2}->max() )) ; execute (res)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findPairs(arr,n): cntEven=0 ; cntOdd=0 ; for i in range(n): if(arr[i]% 2==0): cntEven+=1 ; else : cntOdd+=1 ; evenPairs=0 ; evenPairs+=((cntEven*(cntEven-1))//2); evenPairs+=((cntOdd*(cntOdd-1))//2); oddPairs=0 ; oddPairs+=(cntEven*cntOdd); print("Odd pairs=",oddPairs); print("Even pairs=",evenPairs); if __name__=="__main__" : arr=[1,2,3,4,5]; n=len(arr); findPairs(arr,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))); ; n := (arr)->size(); ; findPairs(arr, n); ) else skip; operation findPairs(arr : OclAny, n : OclAny) pre: true post: true activity: var cntEven : int := 0; var cntOdd : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] mod 2 = 0) then ( cntEven := cntEven + 1; ) else ( cntOdd := cntOdd + 1; )) ; var evenPairs : int := 0; ; evenPairs := evenPairs + ((cntEven * (cntEven - 1)) div 2); ; evenPairs := evenPairs + ((cntOdd * (cntOdd - 1)) div 2); ; var oddPairs : int := 0; ; oddPairs := oddPairs + (cntEven * cntOdd); ; execute ("Odd pairs=")->display(); ; execute ("Even pairs=")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def solve(n): a=float(n/2); if(n % 2!=0): print((math.ceil(a)-1),(math.floor(a)+1)); else : if(a % 2==0): print((math.ceil(a)-1),(math.floor(a)+1)); else : print((math.ceil(a)-2),(math.floor(a)+2)); n=34 ; solve(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 34; ; solve(n);; operation solve(n : OclAny) pre: true post: true activity: var a : double := ("" + ((n / 2)))->toReal(); ; if (n mod 2 /= 0) then ( execute (((a)->ceil() - 1))->display(); ) else ( if (a mod 2 = 0) then ( execute (((a)->ceil() - 1))->display(); ) else ( execute (((a)->ceil() - 2))->display(); ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt from typing import List def restore_table(n : int,M : List[List[int]])->List[int]: ans=[0]*n for i in range(n): if i==0 : a,b=1,2 elif i==n-1 : a,b=n-3,n-2 else : a,b=i-1,i+1 ans[i]=int(sqrt(M[i][a]*M[i][b]//M[a][b])) return ans n=int(input()) c=[] for i in range(n): b=[int(j)for j in input().split()] c.append(b) a=restore_table(n,c) print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var b : Sequence := input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; execute ((b) : c)) ; var a : OclAny := restore_table(n, c) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display(); operation restore_table(n : int, M : List[List[OclType["int"]+1]+1]) : OclAny pre: true post: true activity: var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( if i = 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{1,2} ) else (if i = n - 1 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{n - 3,n - 2} ) else ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{i - 1,i + 1} ) ) ; ans[i+1] := ("" + ((sqrt(M[i+1][a+1] * M[i+1][b+1] div M[a+1][b+1]))))->toInteger()) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) a=[0]*n res=[0]*n for i in range(n): a[i]=[0]*n a[i]=list(map(int,input().split())) res[0]=int((a[0][1]*a[0][2]//a[1][2])**0.5) for i in range(1,n): res[i]=a[0][i]//res[0] for i in range(n): print(res[i],end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var res : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( a[i+1] := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; a[i+1] := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; res->first() := ("" + ((((a->first()[1+1] * a->first()[2+1] div a[1+1][2+1]))->pow(0.5))))->toInteger() ; for i : Integer.subrange(1, n-1) do ( res[i+1] := a->first()[i+1] div res->first()) ; for i : Integer.subrange(0, n-1) do ( execute (res[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) original_array=[] Matris=[] while t : Matris.append(list(map(int,input().split()))) t-=1 original_array.append(str(int((Matris[1][0]*Matris[2][0]/Matris[2][1])**.5))) for i in range(1,len(Matris)): original_array.append(str(int(Matris[i][0]/int(original_array[0])))) print(" ".join(original_array)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var original_array : Sequence := Sequence{} ; var Matris : Sequence := Sequence{} ; while t do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : Matris) ; t := t - 1) ; execute ((("" + ((("" + ((((Matris[1+1]->first() * Matris[2+1]->first() / Matris[2+1][1+1]))->pow(.5))))->toInteger())))) : original_array) ; for i : Integer.subrange(1, (Matris)->size()-1) do ( execute ((("" + ((("" + ((Matris[i+1]->first() / ("" + ((original_array->first())))->toInteger())))->toInteger())))) : original_array)) ; execute (StringLib.sumStringsWithSeparator((original_array), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def solve(): n=int(input()) mat=[] for _ in range(n): mat.append(list(map(int,input().split()))) ans=[] for i in range(n): j=(i+1)% n k=(i+2)% n ans.append(int(math.sqrt((mat[i][j]*mat[i][k])//mat[j][k]))) print(" ".join(map(str,ans))) def main(): solve() if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mat : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : mat)) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var j : int := (i + 1) mod n ; var k : int := (i + 2) mod n ; execute ((("" + ((((mat[i+1][j+1] * mat[i+1][k+1]) div mat[j+1][k+1])->sqrt())))->toInteger()) : ans)) ; execute (StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), " "))->display(); operation main() pre: true post: true activity: solve(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): LIMIT=10**8 MOD=1000000009 ans=1 for p in eulerlib.prime_generator(LIMIT): power=count_factors(LIMIT,p) ans*=1+pow(p,power*2,MOD) ans %=MOD return str(ans) def count_factors(n,p): if n==0 : return 0 else : return n//p+count_factors(n//p,p) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LIMIT : double := (10)->pow(8) ; var MOD : int := 1000000009 ; var ans : int := 1 ; for p : eulerlib.prime_generator(LIMIT) do ( var power : OclAny := count_factors(LIMIT, p) ; ans := ans * 1 + (p)->pow(power * 2) ; ans := ans mod MOD) ; return ("" + ((ans))); operation count_factors(n : OclAny, p : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( return 0 ) else ( return n div p + count_factors(n div p, p) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_int_map(input_string): return map(int,input_string.split()) def electric_train(train_data : str,direction : str,path : str): current_direction=-1 if direction=="to head" else 1 train_length,stowaway_position,inspector_position=get_int_map(train_data) for minute in range(len(path)): if path[minute]=="0" : if inspector_positionstowaway_position and stowaway_position>1 : stowaway_position-=1 if(inspector_position+current_direction)<1 or(inspector_position+current_direction)>train_length : current_direction=-current_direction inspector_position+=current_direction if path[minute]=="1" : if minute+1==len(path): return "Stowaway" if current_direction>0 : stowaway_position=1 if inspector_position>1 else train_length else : stowaway_position=train_length if inspector_positiondisplay(); operation get_int_map(input_string : OclAny) : OclAny pre: true post: true activity: return (input_string.split())->collect( _x | (OclType["int"])->apply(_x) ); operation electric_train(train_data : String, direction : String, path : String) : OclAny pre: true post: true activity: var current_direction : int := if direction = "to head" then -1 else 1 endif ; var train_length : OclAny := null; var stowaway_position : OclAny := null; var inspector_position : OclAny := null; Sequence{train_length,stowaway_position,inspector_position} := get_int_map(train_data) ; for minute : Integer.subrange(0, (path)->size()-1) do ( if path[minute+1] = "0" then ( if (inspector_position->compareTo(stowaway_position)) < 0 & (stowaway_position->compareTo(train_length)) < 0 then ( stowaway_position := stowaway_position + 1 ) else (if (inspector_position->compareTo(stowaway_position)) > 0 & stowaway_position > 1 then ( stowaway_position := stowaway_position - 1 ) else skip) ) else skip ; if (inspector_position + current_direction) < 1 or ((inspector_position + current_direction)->compareTo(train_length)) > 0 then ( current_direction := -current_direction ) else skip ; inspector_position := inspector_position + current_direction ; if path[minute+1] = "1" then ( if minute + 1 = (path)->size() then ( return "Stowaway" ) else skip ; if current_direction > 0 then ( var stowaway_position : int := if inspector_position > 1 then 1 else train_length endif ) else ( stowaway_position := if (inspector_position->compareTo(train_length)) < 0 then train_length else 1 endif ) ) else skip ; if inspector_position = stowaway_position then ( return StringLib.formattedString("Controller{minute+1}") ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys import queue from heapq import heappop,heappush import random def solve(): n,m,k=map(int,input().split()) dir=-1 if str(input())=="to head" else 1 s=str(input()) f=[0 for i in range(n)] pos=-1 for i in range(len(s)-1): if s[i]=="0" : if mtoInteger() ; for _anon : Integer.subrange(0, t-1) do ( solve()) ) else ( solve() ) ) else skip; operation solve() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dir : int := if ("" + (((OclFile["System.in"]).readLine()))) = "to head" then -1 else 1 endif ; var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; var f : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var pos : int := -1 ; for i : Integer.subrange(0, (s)->size() - 1-1) do ( if s[i+1] = "0" then ( if (m->compareTo(k)) < 0 then ( var m : OclAny := Set{1, m - 1}->max() ) else ( m := Set{n, m + 1}->min() ) ; k := k + dir ; if k = 1 or k = n then ( dir := -dir ) else skip ) else ( k := k + dir ; if k = 1 or k = n then ( dir := -dir ) else skip ; if dir = -1 then ( if k = n then ( m := 1 ) else ( m := n ) ) else ( if k = 1 then ( m := n ) else ( m := 1 ) ) ) ; if m = k then ( pos := i + 1 ; break ) else skip) ; if pos = -1 then ( execute ("Stowaway")->display() ) else ( execute ("Controller")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_int_map(input_string): return map(int,input_string.split()) def electric_train(train_date : str,direction : str,path : str): STATE_MOVING="0" STATE_STOP="1" current_direction=-1 if direction=="to head" else 1 train_length,stowaway_position,inspector_position=get_int_map(train_date) for minute in range(len(path)): if path[minute]==STATE_MOVING : if inspector_positionstowaway_position and stowaway_position>1 : stowaway_position-=1 if(inspector_position+current_direction)<1 or(inspector_position+current_direction)>train_length : current_direction=-current_direction inspector_position+=current_direction if path[minute]==STATE_STOP : if(inspector_position+current_direction)<1 or(inspector_position+current_direction)>train_length : current_direction=-current_direction inspector_position+=current_direction if minute+1==len(path): return "Stowaway" if current_direction>0 : stowaway_position=1 if inspector_position>1 else train_length else : stowaway_position=train_length if inspector_positiondisplay(); operation get_int_map(input_string : OclAny) : OclAny pre: true post: true activity: return (input_string.split())->collect( _x | (OclType["int"])->apply(_x) ); operation electric_train(train_date : String, direction : String, path : String) : OclAny pre: true post: true activity: var STATE_MOVING : String := "0" ; var STATE_STOP : String := "1" ; var current_direction : int := if direction = "to head" then -1 else 1 endif ; var train_length : OclAny := null; var stowaway_position : OclAny := null; var inspector_position : OclAny := null; Sequence{train_length,stowaway_position,inspector_position} := get_int_map(train_date) ; for minute : Integer.subrange(0, (path)->size()-1) do ( if path[minute+1] = STATE_MOVING then ( if (inspector_position->compareTo(stowaway_position)) < 0 & (stowaway_position->compareTo(train_length)) < 0 then ( stowaway_position := stowaway_position + 1 ) else (if (inspector_position->compareTo(stowaway_position)) > 0 & stowaway_position > 1 then ( stowaway_position := stowaway_position - 1 ) else skip) ; if (inspector_position + current_direction) < 1 or ((inspector_position + current_direction)->compareTo(train_length)) > 0 then ( current_direction := -current_direction ) else skip ; inspector_position := inspector_position + current_direction ) else skip ; if path[minute+1] = STATE_STOP then ( if (inspector_position + current_direction) < 1 or ((inspector_position + current_direction)->compareTo(train_length)) > 0 then ( current_direction := -current_direction ) else skip ; inspector_position := inspector_position + current_direction ; if minute + 1 = (path)->size() then ( return "Stowaway" ) else skip ; if current_direction > 0 then ( var stowaway_position : int := if inspector_position > 1 then 1 else train_length endif ) else ( stowaway_position := if (inspector_position->compareTo(train_length)) < 0 then train_length else 1 endif ) ) else skip ; if inspector_position = stowaway_position then ( return StringLib.formattedString("Controller{minute+1}") ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_int_map(input_string): return map(int,input_string.split()) def electric_train(train_data : str,direction : str,path : str): STATE_MOVING="0" STATE_STOP="1" current_direction=-1 if direction=="to head" else 1 train_length,stowaway_position,inspector_position=get_int_map(train_data) for minute in range(len(path)): if path[minute]==STATE_MOVING : if inspector_positionstowaway_position and stowaway_position>1 : stowaway_position-=1 if(inspector_position+current_direction)<1 or(inspector_position+current_direction)>train_length : current_direction=-current_direction inspector_position+=current_direction if path[minute]==STATE_STOP : if minute+1==len(path): return "Stowaway" if current_direction>0 : stowaway_position=1 if inspector_position>1 else train_length else : stowaway_position=train_length if inspector_positiondisplay(); operation get_int_map(input_string : OclAny) : OclAny pre: true post: true activity: return (input_string.split())->collect( _x | (OclType["int"])->apply(_x) ); operation electric_train(train_data : String, direction : String, path : String) : OclAny pre: true post: true activity: var STATE_MOVING : String := "0" ; var STATE_STOP : String := "1" ; var current_direction : int := if direction = "to head" then -1 else 1 endif ; var train_length : OclAny := null; var stowaway_position : OclAny := null; var inspector_position : OclAny := null; Sequence{train_length,stowaway_position,inspector_position} := get_int_map(train_data) ; for minute : Integer.subrange(0, (path)->size()-1) do ( if path[minute+1] = STATE_MOVING then ( if (inspector_position->compareTo(stowaway_position)) < 0 & (stowaway_position->compareTo(train_length)) < 0 then ( stowaway_position := stowaway_position + 1 ) else (if (inspector_position->compareTo(stowaway_position)) > 0 & stowaway_position > 1 then ( stowaway_position := stowaway_position - 1 ) else skip) ) else skip ; if (inspector_position + current_direction) < 1 or ((inspector_position + current_direction)->compareTo(train_length)) > 0 then ( current_direction := -current_direction ) else skip ; inspector_position := inspector_position + current_direction ; if path[minute+1] = STATE_STOP then ( if minute + 1 = (path)->size() then ( return "Stowaway" ) else skip ; if current_direction > 0 then ( var stowaway_position : int := if inspector_position > 1 then 1 else train_length endif ) else ( stowaway_position := if (inspector_position->compareTo(train_length)) < 0 then train_length else 1 endif ) ) else skip ; if inspector_position = stowaway_position then ( return StringLib.formattedString("Controller{minute+1}") ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def minBroadcastRange(houses,towers,n,m): leftTower=-sys.maxsize-1 rightTower=towers[0] j,k=0,0 min_range=0 while(jmin_range): min_range=local_max j+=1 else : leftTower=towers[k] if(kunion(Sequence{13}->union(Sequence{11}->union(Sequence{ 80 }))) ; var b : Sequence := Sequence{4}->union(Sequence{6}->union(Sequence{15}->union(Sequence{ 60 }))) ; n := (a)->size() ; m := (b)->size() ; var max : OclAny := minBroadcastRange(a, b, n, m) ; execute (max)->display() ) else skip; operation minBroadcastRange(houses : OclAny, towers : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var leftTower : double := -(trailer . (name maxsize)) - 1 ; var rightTower : OclAny := towers->first() ; var j : OclAny := null; var k : OclAny := null; Sequence{j,k} := Sequence{0,0} ; var min_range : int := 0 ; while ((j->compareTo(n)) < 0) do ( if ((houses[j+1]->compareTo(rightTower)) < 0) then ( var left : double := houses[j+1] - leftTower ; var right : double := rightTower - houses[j+1] ; if (left->compareTo(right)) < 0 then ( var local_max : OclAny := left ) else ( local_max := right ) ; if ((local_max->compareTo(min_range)) > 0) then ( min_range := local_max ) else skip ; j := j + 1 ) else ( leftTower := towers[k+1] ; if ((k->compareTo(m - 1)) < 0) then ( k := k + 1 ; rightTower := towers[k+1] ) else ( rightTower := (trailer . (name maxsize)) ) )) ; return min_range; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n,k=map(int,input().split()) x=list(map(int,input().split())) if k==1 : print(max(x[0],n-x[0]+1)) else : minx=1 maxn=n res=0 if x[0]>1 : res=max(res,x[0]) if x[-1]toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if k = 1 then ( execute (Set{x->first(), n - x->first() + 1}->max())->display() ) else ( var minx : int := 1 ; var maxn : OclAny := n ; var res : int := 0 ; if x->first() > 1 then ( res := Set{res, x->first()}->max() ) else skip ; if (x->last()->compareTo(n)) < 0 then ( res := Set{res, n - x->last() + 1}->max() ) else skip ; x := Sequence{ minx }->union(x)->union(Sequence{ maxn }) ; for i : Integer.subrange(1, (x)->size()-1) do ( var d : double := x[i+1] - x[i - 1+1] + 1 ; if d mod 2 = 1 then ( res := Set{res, d div 2 + 1}->max() ) else ( res := Set{res, d div 2}->max() )) ; execute (res)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def call(): n,m=map(int,input().split()) a=[] x=[0 for i in range(m)] y=[0 for i in range(n)] count=0 for i in range(n): a.append(list(input())) for j in range(len(a[i])): if a[i][j]=='*' : x[j]+=1 y[i]+=1 count+=1 for i in range(n): for j in range(m): if a[i][j]=='*' and x[j]+y[i]-1==count : print('YES') print(i+1,j+1) exit(0) elif x[j]+y[i]==count and a[i][j]!='*' : print('YES') print(i+1,j+1) exit(0) print('NO') call() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; call(); operation call() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{} ; var x : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (0)) ; var y : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( execute ((((OclFile["System.in"]).readLine())->characters()) : a) ; for j : Integer.subrange(0, (a[i+1])->size()-1) do ( if a[i+1][j+1] = '*' then ( x[j+1] := x[j+1] + 1 ; y[i+1] := y[i+1] + 1 ; count := count + 1 ) else skip)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if a[i+1][j+1] = '*' & x[j+1] + y[i+1] - 1 = count then ( execute ('YES')->display() ; execute (i + 1)->display() ; exit(0) ) else (if x[j+1] + y[i+1] = count & a[i+1][j+1] /= '*' then ( execute ('YES')->display() ; execute (i + 1)->display() ; exit(0) ) else skip))) ; execute ('NO')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=input().split() n=int(n) m=int(m) bombs=[] for i in range(n): line=input() for j in range(m): if line[j]=='*' : bombs.append((i,j)) if len(bombs)>n+m-1 : print("NO") else : for i in range(n): bombs_left=[(r,c)for(r,c)in bombs if r!=i] unique_cols=set([c for(r,c)in bombs_left]) if len(unique_cols)==0 : print("YES") print(str(i+1)+" 1") break elif len(unique_cols)==1 : print("YES") print(str(i+1)+" "+str(list(unique_cols)[0]+1)) break else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var m : int := ("" + ((m)))->toInteger() ; var bombs : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var line : String := (OclFile["System.in"]).readLine() ; for j : Integer.subrange(0, m-1) do ( if line[j+1] = '*' then ( execute ((Sequence{i, j}) : bombs) ) else skip)) ; if ((bombs)->size()->compareTo(n + m - 1)) > 0 then ( execute ("NO")->display() ) else ( (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name bombs_left)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name r)))))) , (test (logical_test (comparison (expr (atom (name c))))))) )))))) (comp_for for (exprlist (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name r)))))) , (test (logical_test (comparison (expr (atom (name c))))))) )))) in (logical_test (comparison (expr (atom (name bombs))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name r)))) != (comparison (expr (atom (name i)))))))))) ]))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name unique_cols)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name c)))))) (comp_for for (exprlist (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name r)))))) , (test (logical_test (comparison (expr (atom (name c))))))) )))) in (logical_test (comparison (expr (atom (name bombs_left))))))) ]))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name unique_cols)))))))) ))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) )))) + (expr (atom " 1")))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name unique_cols)))))))) ))))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) )))) + (expr (atom " "))) + (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name unique_cols)))))))) ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) + (expr (atom (number (integer 1)))))))))) )))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) ))))))))))))))) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- [n,m]=map(int,input().split()) xy=[] for i in range(n): for j,k in enumerate(input()): if k=='*' : xy.append((i+1,j+1)) x,y=0,0 for i,j in xy : if x==0 : x=i elif x!=i : if y==0 : y=j elif y!=j : x=-1 break if x==-1 : x,y=0,0 for i,j in xy : if y==0 : y=j elif y!=j : if x==0 : x=i elif x!=i : x=-1 break if x==-1 : print('NO') else : print('YES') print('%d %d' %(max(x,1),max(y,1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: Sequence{n}->union(Sequence{ m }) := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var xy : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( for _tuple : Integer.subrange(1, ((OclFile["System.in"]).readLine())->size())->collect( _indx | Sequence{_indx-1, ((OclFile["System.in"]).readLine())->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var k : OclAny := _tuple->at(_indx); if k = '*' then ( execute ((Sequence{i + 1, j + 1}) : xy) ) else skip)) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{0,0} ; for _tuple : xy do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if x = 0 then ( var x : OclAny := i ) else (if x /= i then ( if y = 0 then ( var y : OclAny := j ) else (if y /= j then ( x := -1 ; break ) else skip) ) else skip)) ; if x = -1 then ( Sequence{x,y} := Sequence{0,0} ; for _tuple : xy do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if y = 0 then ( y := j ) else (if y /= j then ( if x = 0 then ( x := i ) else (if x /= i then ( x := -1 ; break ) else skip) ) else skip)) ) else skip ; if x = -1 then ( execute ('NO')->display() ) else ( execute ('YES')->display() ; execute (StringLib.format('%d %d',Sequence{Set{x, 1}->max(), Set{y, 1}->max()}))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=list(map(int,input().split())) print(max(A)-min(A)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((A)->max() - (A)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from functools import reduce import copy import math from pprint import pprint import collections import bisect sys.setrecursionlimit(4100000) def inputs(num_of_input): ins=[input()for i in range(num_of_input)] return ins def int_inputs(num_of_input): ins=[int(input())for i in range(num_of_input)] return ins def solve(inputs): A=string_to_int(inputs[0]) A.sort() return A[-1]-A[0] def string_to_int(string): return list(map(int,string.split())) if __name__=="__main__" : input() ret=solve(inputs(1)) print(ret) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(4100000) ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( input() ; var ret : OclAny := solve(inputs(1)) ; execute (ret)->display() ) else skip; operation inputs(num_of_input : OclAny) : OclAny pre: true post: true activity: var ins : Sequence := Integer.subrange(0, num_of_input-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; return ins; operation int_inputs(num_of_input : OclAny) : OclAny pre: true post: true activity: ins := Integer.subrange(0, num_of_input-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; return ins; operation solve(inputs : OclAny) : OclAny pre: true post: true activity: var A : OclAny := string_to_int(inputs->first()) ; A := A->sort() ; return A->last() - A->first(); operation string_to_int(string : OclAny) : OclAny pre: true post: true activity: return ((string.split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() house_list=sorted([int(v)for v in input().split()]) print(house_list[-1]-house_list[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var house_list : Sequence := input().split()->select(v | true)->collect(v | (("" + ((v)))->toInteger()))->sort() ; execute (house_list->last() - house_list->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _,*aa=map(int,open(0).read().split()) print(max(aa)-min(aa)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _anon : OclAny := null; var aa : OclAny := null; Sequence{_anon,aa} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((aa)->max() - (aa)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N=input() a=list(map(int,input().split())) print(max(a)-min(a)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : String := (OclFile["System.in"]).readLine() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((a)->max() - (a)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Check_is_possible(l,r,k): div_count=(r//k)-(l//k) if l % k==0 : div_count+=1 return div_count>1 if __name__=="__main__" : l,r,k=30,70,10 if Check_is_possible(l,r,k)==True : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{l,r,k} := Sequence{30,70,10} ; if Check_is_possible(l, r, k) = true then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; operation Check_is_possible(l : OclAny, r : OclAny, k : OclAny) : OclAny pre: true post: true activity: var div_count : double := (r div k) - (l div k) ; if l mod k = 0 then ( div_count := div_count + 1 ) else skip ; return div_count > 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) a=list(map(int,input().split())) now=set() d=0 l=pow(10,6)+5 x=[-1]*l ok=1 c=[] c0=0 for i in a : c0+=1 if i>0 : if i in now or x[i]==d : ok=0 now.add(i) x[i]=d else : if not-i in now : ok=0 else : now.remove(-i) if not ok : break if not len(now): d+=1 c.append(c0) c0=0 if len(now)or not ok : ans=-1 print(ans) exit() print(d) sys.stdout.write(" ".join(map(str,c))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var now : Set := Set{}->union(()) ; var d : int := 0 ; var l : double := (10)->pow(6) + 5 ; var x : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, l) ; var ok : int := 1 ; var c : Sequence := Sequence{} ; var c0 : int := 0 ; for i : a do ( c0 := c0 + 1 ; if i > 0 then ( if (now)->includes(i) or x[i+1] = d then ( ok := 0 ) else skip ; execute ((i) : now) ; x[i+1] := d ) else ( if not((now)->includes(-i)) then ( ok := 0 ) else ( execute ((-i) /: now) ) ) ; if not(ok) then ( break ) else skip ; if not((now)->size()) then ( d := d + 1 ; execute ((c0) : c) ; c0 := 0 ) else skip) ; if (now)->size() or not(ok) then ( var ans : int := -1 ; execute (ans)->display() ; exit() ) else skip ; execute (d)->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " ") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CalPeri(): s=5 Perimeter=10*s print("The Perimeter of Decagon is : ",Perimeter) if __name__=='__main__' : CalPeri(); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( CalPeri(); ) else skip; operation CalPeri() pre: true post: true activity: var s : int := 5 ; var Perimeter : int := 10 * s ; execute ("The Perimeter of Decagon is : ")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,k=list(map(int,str(input()).split())) a=list(map(int,str(input()).split())) ans=max(a[0],n-a[k-1]+1) for i in range(1,k): ans=max(ans,(a[i]-a[i-1]+2)//2) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((OclType["String"]((OclFile["System.in"]).readLine()).split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((OclType["String"]((OclFile["System.in"]).readLine()).split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : OclAny := Set{a->first(), n - a[k - 1+1] + 1}->max() ; for i : Integer.subrange(1, k-1) do ( ans := Set{ans, (a[i+1] - a[i - 1+1] + 2) div 2}->max()) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=map(int,input().split()) s=[]; p=2 for i in range(n): x,d=map(int,input().split()) s.append([x-d/2,x+d/2]) s.sort() for j in range(1,len(s)): if s[j][0]-s[j-1][1]>t : p+=2 elif s[j][0]-s[j-1][1]==t : p+=1 print(str(p)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := Sequence{}; var p : int := 2 ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var d : OclAny := null; Sequence{x,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{x - d / 2}->union(Sequence{ x + d / 2 })) : s)) ; s := s->sort() ; for j : Integer.subrange(1, (s)->size()-1) do ( if (s[j+1]->first() - s[j - 1+1][1+1]->compareTo(t)) > 0 then ( p := p + 2 ) else (if s[j+1]->first() - s[j - 1+1][1+1] = t then ( p := p + 1 ) else skip)) ; execute (("" + ((p))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import cmp_to_key class House : def __init__(self,newLeftSide,newRightSide): self.leftSide=newLeftSide self.rightSide=newRightSide def sortHouses(house1,house2): return house1.leftSide-house2.rightSide cont,ans=[],2 n,t=[int(item)for item in input().split(' ')] for i in range(n): center,sides=[int(item)for item in input().split(' ')] obj=House(center-sides/2,center+sides/2) cont.append(obj) cont.sort(key=cmp_to_key(sortHouses)) for i in range(n-1): gap=cont[i+1].leftSide-cont[i].rightSide if texists( _x | result = _x ); attribute leftSide : OclAny := newLeftSide; attribute rightSide : OclAny := newRightSide; operation initialise(newLeftSide : OclAny,newRightSide : OclAny) : House pre: true post: true activity: self.leftSide := newLeftSide ; self.rightSide := newRightSide; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var cont : OclAny := null; var ans : OclAny := null; Sequence{cont,ans} := Sequence{Sequence{},2} ; var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := input().split(' ')->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; for i : Integer.subrange(0, n-1) do ( var center : OclAny := null; var sides : OclAny := null; Sequence{center,sides} := input().split(' ')->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; var obj : House := (House.newHouse()).initialise(center - sides / 2, center + sides / 2) ; execute ((obj) : cont)) ; cont := cont->sort() ; for i : Integer.subrange(0, n - 1-1) do ( var gap : double := cont[i + 1+1].leftSide - cont[i+1].rightSide ; if (t->compareTo(gap)) < 0 then ( ans := ans + 2 ) else (if t = gap then ( ans := ans + 1 ) else skip)) ; execute (ans)->display(); operation sortHouses(house1 : OclAny, house2 : OclAny) : OclAny pre: true post: true activity: return house1.leftSide - house2.rightSide; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,width=map(int,input().split()) a=[] for i in range(n): pos,w=map(int,input().split()) a.append(pos-w/2) a.append(pos+w/2) a.sort() s=2 for i in range(1,2*n-1,2): if a[i+1]-a[i]>width : s+=2 elif a[i+1]-a[i]==width : s+=1 print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var width : OclAny := null; Sequence{n,width} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var pos : OclAny := null; var w : OclAny := null; Sequence{pos,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((pos - w / 2) : a) ; execute ((pos + w / 2) : a)) ; a := a->sort() ; var s : int := 2 ; for i : Integer.subrange(1, 2 * n - 1-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( if (a[i + 1+1] - a[i+1]->compareTo(width)) > 0 then ( s := s + 2 ) else (if a[i + 1+1] - a[i+1] = width then ( s := s + 1 ) else skip)) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,n=map(int,input().split()) a=[] b=[] z=2 for i in range(m): k,t=map(int,input().split()) a.append(k-t/2) a.append(k+t/2) a.sort() for i in range(1,m): b.append(a[2*i]-a[2*i-1]) for i in range(m-1): if b[i]>n : z+=2 elif b[i]==n : z+=1 print(z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; var z : int := 2 ; for i : Integer.subrange(0, m-1) do ( var k : OclAny := null; var t : OclAny := null; Sequence{k,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((k - t / 2) : a) ; execute ((k + t / 2) : a)) ; a := a->sort() ; for i : Integer.subrange(1, m-1) do ( execute ((a[2 * i+1] - a[2 * i - 1+1]) : b)) ; for i : Integer.subrange(0, m - 1-1) do ( if (b[i+1]->compareTo(n)) > 0 then ( z := z + 2 ) else (if b[i+1] = n then ( z := z + 1 ) else skip)) ; execute (z)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=map(int,input().split()) x=[] y=[] z=[] w=0 numbers=0 for i in range(n): a,b=map(int,input().split()) x.append(a) y.append(b) for i in range(len(x)): left=x[i]-y[i]/2 right=x[i]+y[i]/2 z.insert(0,left) z.insert(0,right) z.sort() print for i in range(0,len(z)-2,2): w=z[i+2]-z[i+1] if w>t : numbers+=2 elif w==t : numbers+=1 numbers=numbers+2 print(numbers) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := Sequence{} ; var y : Sequence := Sequence{} ; var z : Sequence := Sequence{} ; var w : int := 0 ; var numbers : int := 0 ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a) : x) ; execute ((b) : y)) ; for i : Integer.subrange(0, (x)->size()-1) do ( var left : double := x[i+1] - y[i+1] / 2 ; var right : OclAny := x[i+1] + y[i+1] / 2 ; z := z.insertAt(0+1, left) ; z := z.insertAt(0+1, right)) ; z := z->sort() ; ; for i : Integer.subrange(0, (z)->size() - 2-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( w := z[i + 2+1] - z[i + 1+1] ; if (w->compareTo(t)) > 0 then ( numbers := numbers + 2 ) else (if w = t then ( numbers := numbers + 1 ) else skip)) ; numbers := numbers + 2 ; execute (numbers)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s="" while(True): try : a=raw_input() s+=a except EOFError : break count=[0]*26 for i in range(len(s)): if('a'<=s[i]<='z'): count[ord(s[i])-ord('a')]+=1 elif('A'<=s[i]<='Z'): count[ord(s[i])-ord('A')]+=1 for i in range(len(count)): print("%c : %d" %(chr(i+ord('a')),count[i])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := "" ; while (true) do ( try ( var a : OclAny := raw_input() ; s := s + a) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))) ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for i : Integer.subrange(0, (s)->size()-1) do ( if ('a' <= s[i+1] & (s[i+1] <= 'z')) then ( count[(s[i+1])->char2byte() - ('a')->char2byte()+1] := count[(s[i+1])->char2byte() - ('a')->char2byte()+1] + 1 ) else (if ('A' <= s[i+1] & (s[i+1] <= 'Z')) then ( count[(s[i+1])->char2byte() - ('A')->char2byte()+1] := count[(s[i+1])->char2byte() - ('A')->char2byte()+1] + 1 ) else skip)) ; for i : Integer.subrange(0, (count)->size()-1) do ( execute (StringLib.format("%c : %d",Sequence{(i + ('a')->char2byte())->byte2char(), count[i+1]}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys counts={} for i in range(ord('a'),ord('z')+1): counts[chr(i)]=0 for line in sys.stdin : for ch in line.lower(): if ch in counts : counts[ch]+=1 for i in range(ord('a'),ord('z')+1): ch=chr(i) print("%s : %d" %(ch,counts[ch])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var counts : OclAny := Set{} ; for i : Integer.subrange(('a')->char2byte(), ('z')->char2byte() + 1-1) do ( counts[(i)->byte2char()+1] := 0) ; for line : OclFile["System.in"] do ( for ch : line->toLowerCase() do ( if (counts)->includes(ch) then ( counts[ch+1] := counts[ch+1] + 1 ) else skip)) ; for i : Integer.subrange(('a')->char2byte(), ('z')->char2byte() + 1-1) do ( var ch : String := (i)->byte2char() ; execute (StringLib.format("%s : %d",Sequence{ch, counts->at(ch)}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,string table={} for line in sys.stdin : for i in range(len(line)): c=line[i].lower() table[c]=table.get(c,0)+1 for c in string.ascii_lowercase : print("%s : %d" %(c,table.get(c,0))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var table : OclAny := Set{} ; for line : OclFile["System.in"] do ( for i : Integer.subrange(0, (line)->size()-1) do ( var c : OclAny := line[i+1]->toLowerCase() ; table[c+1] := table.get(c, 0) + 1)) ; for c : string.ascii_lowercase do ( execute (StringLib.format("%s : %d",Sequence{c, table.get(c, 0)}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if a==0 : return b else : return gcd(b % a,a) t=int(input()) while t : t-=1 a,b=map(int,input().split()) c=gcd(a,b) a=a//c b=b//c if a==b : ans1=1 ans2=0 elif a % 2==0 or b % 2==0 : ans1=1 ans2=1 else : ans1=a*b//2+1 ans2=a*b//2 print(ans1,ans2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( t := t - 1 ; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : OclAny := gcd(a, b) ; a := a div c ; b := b div c ; if a = b then ( var ans1 : int := 1 ; var ans2 : int := 0 ) else (if a mod 2 = 0 or b mod 2 = 0 then ( ans1 := 1 ; ans2 := 1 ) else ( ans1 := a * b div 2 + 1 ; ans2 := a * b div 2 ) ) ; execute (ans1)->display()); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a = 0 then ( return b ) else ( return gcd(b mod a, a) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) count=0 e,l={},{} ans=[] for i in a : if i>0 and i in e : count=-1 break elif i>0 : e[i]=1 count+=1 elif i in l : count=-1 break else : if-1*i not in e : count=-1 break l[i]=1 count+=1 if len(e)==len(l): e,l={},{} ans.append(count) count=0 if len(e)!=len(l): print(-1) exit() if count==-1 : print(-1) exit() print(len(ans)) print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : int := 0 ; var e : OclAny := null; var l : OclAny := null; Sequence{e,l} := Sequence{Set{},Set{}} ; var ans : Sequence := Sequence{} ; for i : a do ( if i > 0 & (e)->includes(i) then ( count := -1 ; break ) else (if i > 0 then ( e[i+1] := 1 ; count := count + 1 ) else (if (l)->includes(i) then ( count := -1 ; break ) else ( if (e)->excludes(-1 * i) then ( count := -1 ; break ) else skip ; l[i+1] := 1 ; count := count + 1 ) ) ) ; if (e)->size() = (l)->size() then ( var e : OclAny := null; var l : OclAny := null; Sequence{e,l} := Sequence{Set{},Set{}} ; execute ((count) : ans) ; count := 0 ) else skip) ; if (e)->size() /= (l)->size() then ( execute (-1)->display() ; exit() ) else skip ; if count = -1 then ( execute (-1)->display() ; exit() ) else skip ; execute ((ans)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- alphabet=[chr(i)for i in range(ord('a'),ord('z')+1)] s="" while True : try : s+=raw_input().lower() except EOFError : break for i in range(26): count=s.count(alphabet[i]) print("{0}:{1}").format(alphabet[i],count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var alphabet : Sequence := Integer.subrange(('a')->char2byte(), ('z')->char2byte() + 1-1)->select(i | true)->collect(i | ((i)->byte2char())) ; var s : String := "" ; while true do ( try ( s := s + raw_input()->toLowerCase()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))) ; for i : Integer.subrange(0, 26-1) do ( var count : int := s->count(alphabet[i+1]) ; (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "{0}:{1}"))))))) ))) (trailer . (name format) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name alphabet)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name count)))))))) ))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function from collections import Counter from string import ascii_lowercase import sys cnt=Counter() for line in sys.stdin : for c in line.lower(): cnt[c]+=1 for c in ascii_lowercase : print('{}:{}'.format(c,cnt[c])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var cnt : OclAny := Counter() ; for line : OclFile["System.in"] do ( for c : line->toLowerCase() do ( cnt[c+1] := cnt[c+1] + 1)) ; for c : ascii_lowercase do ( execute (StringLib.interpolateStrings('{}:{}', Sequence{c, cnt[c+1]}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pyramid(n): for i in range(n,0,-1): for gap in range(n-1,i-1,-1): print(" ",end='') print(" ",end='') num=ord('A') for j in range(1,i+1): print(chr(num),end='') num+=1 for j in range(i-1,-1,-1): num-=1 print(chr(num),end='') print("\n",end='') n=9 pyramid(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 9 ; pyramid(n); operation pyramid(n : OclAny) pre: true post: true activity: for i : Integer.subrange(0 + 1, n)->reverse() do ( for gap : Integer.subrange(i - 1 + 1, n - 1)->reverse() do ( execute (" ")->display() ; execute (" ")->display()) ; var num : int := ('A')->char2byte() ; for j : Integer.subrange(1, i + 1-1) do ( execute ((num)->byte2char())->display() ; num := num + 1) ; for j : Integer.subrange(-1 + 1, i - 1)->reverse() do ( num := num - 1 ; execute ((num)->byte2char())->display()) ; execute ("\n")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- str="abcb" def countPS(i,j): if(i>=n or j<0): return 0 if(dp[i][j]!=-1): return dp[i][j] if(abs(i-j)==1): if(str[i]==str[j]): dp[i][j]=3 return dp[i][j] else : dp[i][j]=2 return dp[i][j] if(i==j): dp[1][j]=1 return dp[1][j] elif(str[i]==str[j]): dp[i][j]=(countPS(i+1,j)+countPS(i,j-1)+1) return dp[i][j] else : dp[i][j]=(countPS(i+1,j)+countPS(i,j-1)-countPS(i+1,j-1)) return dp[i][j] if __name__=="__main__" : dp=[[-1 for x in range(1000)]for y in range(1000)] n=len(str) print("Total palindromic subsequence are :",countPS(0,n-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var OclType["String"] : String := "abcb" ; skip ; if __name__ = "__main__" then ( var dp : Sequence := Integer.subrange(0, 1000-1)->select(y | true)->collect(y | (Integer.subrange(0, 1000-1)->select(x | true)->collect(x | (-1)))) ; var n : int := (OclType["String"])->size() ; execute ("Total palindromic subsequence are :")->display() ) else skip; operation countPS(i : OclAny, j : OclAny) : OclAny pre: true post: true activity: if ((i->compareTo(n)) >= 0 or j < 0) then ( return 0 ) else skip ; if (dp[i+1][j+1] /= -1) then ( return dp[i+1][j+1] ) else skip ; if ((i - j)->abs() = 1) then ( if (("" + ([i+1])) = ("" + ([j+1]))) then ( dp[i+1][j+1] := 3 ; return dp[i+1][j+1] ) else ( dp[i+1][j+1] := 2 ; return dp[i+1][j+1] ) ) else skip ; if (i = j) then ( dp[1+1][j+1] := 1 ; return dp[1+1][j+1] ) else (if (("" + ([i+1])) = ("" + ([j+1]))) then ( dp[i+1][j+1] := (countPS(i + 1, j) + countPS(i, j - 1) + 1) ; return dp[i+1][j+1] ) else ( dp[i+1][j+1] := (countPS(i + 1, j) + countPS(i, j - 1) - countPS(i + 1, j - 1)) ; return dp[i+1][j+1] ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools n=input(); a=tuple(map(int,input().split())) p=sorted(list(itertools.permutations(a))) i=p.index(a) if i>0 : print(*p[i-1]) print(*p[i]) if icollect( _x | (OclType["int"])->apply(_x) )) ; var p : Sequence := (itertools.permutations(a))->sort() ; var i : int := p->indexOf(a) - 1 ; if i > 0 then ( execute ((argument * (test (logical_test (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))))))))->display() ) else skip ; execute ((argument * (test (logical_test (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))->display() ; if (i->compareTo((p)->size() - 1)) < 0 then ( execute ((argument * (test (logical_test (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop BIG_NUM=2000000000 MOD=1000000007 EPS=0.000000001 N=int(input()) table=[None]*N check=[False]*(N+1) MAP={} rev_MAP={} perm_index=0 def recursive(index): global perm_index if index==N : tmp=0 for i in range(N): tmp=10*tmp+table[i] MAP[perm_index]=tmp rev_MAP[tmp]=perm_index perm_index+=1 return for i in range(1,(N+1)): if check[i]: continue check[i]=True table[index]=i recursive(index+1) check[i]=False def outPut(num): S=deque() while True : S.appendleft(num % 10) num//=10 if num==0 : break print("%d" %(S.popleft()),end="") while len(S)>0 : print(" %d" %(S.popleft()),end="") print() recursive(0) tmp=0 for i in list(map(int,input().split())): tmp=10*tmp+i index=rev_MAP[tmp] if index>0 : outPut(MAP[index-1]) outPut(tmp) if index+1 in MAP : outPut(MAP[index+1]) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute perm_index : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var table : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, N) ; var check : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (N + 1)) ; var MAP : OclAny := Set{} ; var rev_MAP : OclAny := Set{} ; var perm_index : int := 0 ; skip ; skip ; recursive(0) ; tmp := 0 ; for i : ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) do ( tmp := 10 * tmp + i) ; index := rev_MAP[tmp+1] ; if index > 0 then ( outPut(MAP[index - 1+1]) ) else skip ; outPut(tmp) ; if (MAP)->includes(index + 1) then ( outPut(MAP[index + 1+1]) ) else skip; operation recursive(index : OclAny) pre: true post: true activity: skip ; if index = N then ( var tmp : int := 0 ; for i : Integer.subrange(0, N-1) do ( tmp := 10 * tmp + table[i+1]) ; MAP[perm_index+1] := tmp ; rev_MAP[tmp+1] := perm_index ; perm_index := perm_index + 1 ; return ) else skip ; for i : Integer.subrange(1, (N + 1)-1) do ( if check[i+1] then ( continue ) else skip ; check[i+1] := true ; table[index+1] := i ; recursive(index + 1) ; check[i+1] := false); operation outPut(num : OclAny) pre: true post: true activity: var S : Sequence := () ; while true do ( S := S->prepend(num mod 10) ; num := num div 10 ; if num = 0 then ( break ) else skip) ; execute (StringLib.format("%d",(S->first())))->display() ; while (S)->size() > 0 do ( execute (StringLib.format(" %d",(S->first())))->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): from sys import stdin f_i=stdin n=int(f_i.readline()) A_s=f_i.readline().rstrip() if n==1 : print(A_s) else : A=tuple(map(int,A_s.split())) from itertools import permutations lex=tuple(permutations(range(1,n+1),n)) from bisect import bisect_left idx=bisect_left(lex,A) if idx==0 : print(A_s) print(' '.join(map(str,lex[idx+1]))) elif idx==len(lex)-1 : print(' '.join(map(str,lex[idx-1]))) print(A_s) else : print(' '.join(map(str,lex[idx-1]))) print(A_s) print(' '.join(map(str,lex[idx+1]))) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: skip ; var f_i : OclAny := stdin ; var n : int := ("" + ((f_i.readLine())))->toInteger() ; var A_s : OclAny := f_i.readLine().rstrip() ; if n = 1 then ( execute (A_s)->display() ) else ( var A : Sequence := ((A_s.split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; var lex : Sequence := (permutations(Integer.subrange(1, n + 1-1), n)) ; skip ; var idx : OclAny := bisect_left(lex, A) ; if idx = 0 then ( execute (A_s)->display() ; execute (StringLib.sumStringsWithSeparator(((lex[idx + 1+1])->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ) else (if idx = (lex)->size() - 1 then ( execute (StringLib.sumStringsWithSeparator(((lex[idx - 1+1])->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ; execute (A_s)->display() ) else ( execute (StringLib.sumStringsWithSeparator(((lex[idx - 1+1])->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ; execute (A_s)->display() ; execute (StringLib.sumStringsWithSeparator(((lex[idx + 1+1])->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rec(lst,d): for i in range(1,len(lst)+1): if i not in lst : lst[d]=i if d+1==len(lst): a=list(lst) P.append(a) lst[d]=0 return else : rec(lst,d+1) lst[d]=0 N=int(input()) S=list(map(int,input().split())) P=[] lst=[] for i in range(N): lst.append(0) rec(lst,0) for i in range(len(P)): if S==P[i]: if i!=0 : print(*P[i-1]) print(*P[i]) if i+1!=len(P): print(*P[i+1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var P : Sequence := Sequence{} ; lst := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute ((0) : lst)) ; rec(lst, 0) ; for i : Integer.subrange(0, (P)->size()-1) do ( if S = P[i+1] then ( if i /= 0 then ( execute ((argument * (test (logical_test (comparison (expr (atom (name P)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))))))))->display() ) else skip ; execute ((argument * (test (logical_test (comparison (expr (atom (name P)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))->display() ; if i + 1 /= (P)->size() then ( execute ((argument * (test (logical_test (comparison (expr (atom (name P)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))))))))->display() ) else skip ) else skip); operation rec(lst : OclAny, d : OclAny) pre: true post: true activity: for i : Integer.subrange(1, (lst)->size() + 1-1) do ( if (lst)->excludes(i) then ( lst[d+1] := i ; if d + 1 = (lst)->size() then ( var a : Sequence := (lst) ; execute ((a) : P) ; lst[d+1] := 0 ; return ) else ( rec(lst, d + 1) ; lst[d+1] := 0 ) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import operator def permutations(li): def perm(op): def func(xs): i=len(xs)-1 while i>0 and op(xs[i-1],xs[i]): i-=1 if i>0 : i-=1 j=i+1 while j= null) then ( execute ((pp) : ps) ) else skip ; execute ((li) : ps) ; var np : OclAny := next_perm(li) ; if not(np <>= null) then ( execute ((np) : ps) ) else skip ; return ps; operation run() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; li := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; assert (n = (li)->size()) do "assertion failed" ; for ps : permutations(li) do ( execute (StringLib.sumStringsWithSeparator((ps->select(x | true)->collect(x | (("" + ((x)))))), " "))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- [n,r]=[int(x)for x in input().split(' ')] a=[int(x)for x in input().split(' ')] last_heater=None heaters=n*[0] last_looked=None ok=False r=r-1 last_looked=min((r+1),n) for i in reversed(range(0,min((r+1),n))): if(a[i]==1): heaters[i]=1 last_heater=i ok=True break if last_heater==None : print(-1) else : while(last_heaterunion(Sequence{ r }) := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a : Sequence := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var last_heater : OclAny := null ; var heaters : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var last_looked : OclAny := null ; var ok : boolean := false ; var r : double := r - 1 ; last_looked := Set{(r + 1), n}->min() ; for i : (Integer.subrange(0, Set{(r + 1), n}->min()-1))->reverse() do ( if (a[i+1] = 1) then ( heaters[i+1] := 1 ; last_heater := i ; ok := true ; break ) else skip) ; if last_heater = null then ( execute (-1)->display() ) else ( while ((last_heater->compareTo(n - r - 1)) < 0) do ( var maximum : OclAny := last_heater + 2 * r + 1 ; ok := false ; for i : (Integer.subrange(last_looked, Set{n, maximum + 1}->min()-1))->reverse() do ( last_looked := Set{n, maximum + 1}->min() ; if (a[i+1] = 1) then ( heaters[i+1] := 1 ; last_heater := i ; ok := true ; break ) else skip) ; if not(ok) then ( execute (-1)->display() ; break ) else skip) ) ; if ok then ( execute ((heaters)->sum())->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(): n=int(input()) a=list(map(int,input().split())) dp={} arr=[] cnt=0 last=0 for i in range(n): if a[i]>0 : if dp.get(a[i])!=None : print(-1) return dp[a[i]]=1 cnt+=1 elif a[i]<0 : if dp.get(abs(a[i]))==None or dp[abs(a[i])]==0 : print(-1) return else : dp[abs(a[i])]=0 cnt-=1 if cnt==0 : arr.append((i+1)-last) last=i+1 dp={} if cnt!=0 : print(-1) return print(len(arr)) for x in arr : print(x,end=' ') print() return main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dp : OclAny := Set{} ; var arr : Sequence := Sequence{} ; var cnt : int := 0 ; var last : int := 0 ; for i : Integer.subrange(0, n-1) do ( if a[i+1] > 0 then ( if dp.get(a[i+1]) /= null then ( execute (-1)->display() ; return ) else skip ; dp[a[i+1]+1] := 1 ; cnt := cnt + 1 ) else (if a[i+1] < 0 then ( if dp.get((a[i+1])->abs()) = null or dp[(a[i+1])->abs()+1] = 0 then ( execute (-1)->display() ; return ) else ( dp[(a[i+1])->abs()+1] := 0 ; cnt := cnt - 1 ; if cnt = 0 then ( execute (((i + 1) - last) : arr) ; last := i + 1 ; dp := Set{} ) else skip ) ) else skip)) ; if cnt /= 0 then ( execute (-1)->display() ; return ) else skip ; execute ((arr)->size())->display() ; for x : arr do ( execute (x)->display()) ; execute (->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=list(map(int,input().split())) a=list(map(int,input().split())) b=[0]*n ans=0 ; summ=0 for i in range(n): if a[i]==1 : summ+=1 x=max(0,int(i-m+1)); y=min(n-1,int(i+m-1)) for j in range(x,y+1): b[j]+=1 for i in range(n): if a[i]==1 : x=max(0,int(i-m+1)); y=min(n-1,int(i+m-1)) dem=0 for j in range(x,y+1): if b[j]>=2 : dem+=1 if dem==y-x+1 : ans+=1 for j in range(x,y+1): b[j]-=1 ck=True for i in b : if i==0 : ck=False ; break if(ck): print(summ-ans) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var ans : int := 0; var summ : int := 0 ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = 1 then ( summ := summ + 1 ; var x : OclAny := Set{0, ("" + ((i - m + 1)))->toInteger()}->max(); var y : OclAny := Set{n - 1, ("" + ((i + m - 1)))->toInteger()}->min() ; for j : Integer.subrange(x, y + 1-1) do ( b[j+1] := b[j+1] + 1) ) else skip) ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = 1 then ( x := Set{0, ("" + ((i - m + 1)))->toInteger()}->max(); y := Set{n - 1, ("" + ((i + m - 1)))->toInteger()}->min() ; var dem : int := 0 ; for j : Integer.subrange(x, y + 1-1) do ( if b[j+1] >= 2 then ( dem := dem + 1 ) else skip) ; if dem = y - x + 1 then ( ans := ans + 1 ; for j : Integer.subrange(x, y + 1-1) do ( b[j+1] := b[j+1] - 1) ) else skip ) else skip) ; var ck : boolean := true ; for i : b do ( if i = 0 then ( ck := false; break ) else skip) ; if (ck) then ( execute (summ - ans)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=list(map(int,input().split())) a=list(map(int,input().split())) b=[0]*n ans=0 ; summ=0 for i in range(n): if a[i]==1 : summ+=1 x=max(0,int(i-m+1)); y=min(n-1,int(i+m-1)) for j in range(x,y+1): b[j]+=1 for i in range(n): if a[i]==1 : x=max(0,int(i-m+1)); y=min(n-1,int(i+m-1)) dem=0 for j in range(x,y+1): if b[j]>=2 : dem+=1 if dem==y-x+1 : ans+=1 for j in range(x,y+1): b[j]-=1 ck=True for i in b : if i==0 : ck=False ; break if(ck): print(summ-ans) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var ans : int := 0; var summ : int := 0 ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = 1 then ( summ := summ + 1 ; var x : OclAny := Set{0, ("" + ((i - m + 1)))->toInteger()}->max(); var y : OclAny := Set{n - 1, ("" + ((i + m - 1)))->toInteger()}->min() ; for j : Integer.subrange(x, y + 1-1) do ( b[j+1] := b[j+1] + 1) ) else skip) ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = 1 then ( x := Set{0, ("" + ((i - m + 1)))->toInteger()}->max(); y := Set{n - 1, ("" + ((i + m - 1)))->toInteger()}->min() ; var dem : int := 0 ; for j : Integer.subrange(x, y + 1-1) do ( if b[j+1] >= 2 then ( dem := dem + 1 ) else skip) ; if dem = y - x + 1 then ( ans := ans + 1 ; for j : Integer.subrange(x, y + 1-1) do ( b[j+1] := b[j+1] - 1) ) else skip ) else skip) ; var ck : boolean := true ; for i : b do ( if i = 0 then ( ck := false; break ) else skip) ; if (ck) then ( execute (summ - ans)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) n,r=R() a=[0]*r+[*R()]+[0]*r c=p=0 try : while pcollect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var r : OclAny := null; Sequence{n,r} := R->apply() ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, r)->union(R->apply())->union(MatrixLib.elementwiseMult(Sequence{ 0 }, r)) ; var c : OclAny := 0; var p : int := 0 ; try ( while (p->compareTo(n)) < 0 do ( p := ((argument (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name p))) + (expr (expr (atom (number (integer 2)))) * (expr (atom (name r))))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name p))))))) , (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))))).next(); c := c + 1)) catch (_e : OclException) do ( c := -1) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline inf=float('inf') def getInt(): return int(input()) def getStr(): return input().strip() def getList(split=True): s=getStr() if split : s=s.split() return map(int,s) t=getInt() def solve(): s=getStr() n=len(s) s=[ord(i)-96 for i in s] i=0 j=n-1 while i<=j : if s[i]==n : i+=1 elif s[j]==n : j-=1 else : print("NO") return n-=1 print("YES") for _ in range(t): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; skip ; skip ; skip ; var t : OclAny := getInt() ; skip ; for _anon : Integer.subrange(0, t-1) do ( solve()); operation getInt() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation getStr() : OclAny pre: true post: true activity: return input()->trim(); operation getList(split : OclAny) : OclAny pre: true post: true activity: if split->oclIsUndefined() then split := true else skip; var s : OclAny := getStr() ; if split then ( s := s.split() ) else skip ; return (s)->collect( _x | (OclType["int"])->apply(_x) ); operation solve() pre: true post: true activity: s := getStr() ; var n : int := (s)->size() ; s := s->select(i | true)->collect(i | ((i)->char2byte() - 96)) ; var i : int := 0 ; var j : double := n - 1 ; while (i->compareTo(j)) <= 0 do ( if s[i+1] = n then ( i := i + 1 ) else (if s[j+1] = n then ( j := j - 1 ) else ( execute ("NO")->display() ; return ) ) ; n := n - 1) ; execute ("YES")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def obogrevately(r,lst): result,end=0,-1 while endselect(j | true)->collect(j | (("" + ((j)))->toInteger())) ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (obogrevately(R, a))->display(); operation obogrevately(r : OclAny, lst : OclAny) : OclAny pre: true post: true activity: var result : OclAny := null; var end : OclAny := null; Sequence{result,end} := Sequence{0,-1} ; while (end->compareTo((lst)->size() - 1)) < 0 do ( var position : int := -1 ; for i : Integer.subrange(Set{-1, end - r + 1}->max() + 1, (lst)->size() - 1)->reverse() do ( if lst[i+1] = 1 & (i - r->compareTo(end)) <= 0 then ( position := i ; break ) else skip) ; if position = -1 then ( return -1 ) else skip ; result := result + 1 ; var end : double := position + r - 1) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function import numpy import string T=int(raw_input()) for i in range(1,T+1): print("Case #%d:" % i,end='') n=int(raw_input()) p=[int(x)for x in raw_input().split()] while True : pp=[x for x in range(len(p))if p[x]!=0] if len(pp)==0 : break elif len(pp)==2 and p[pp[0]]==p[pp[1]]: print('',end='') print(string.uppercase[pp[0]],end='') print(string.uppercase[pp[1]],end='') p[pp[0]]-=1 p[pp[1]]-=1 else : q=numpy.argmax(p) print('',end='') print(string.uppercase[q],end='') p[q]-=1 print('') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var T : int := ("" + ((raw_input())))->toInteger() ; for i : Integer.subrange(1, T + 1-1) do ( execute (StringLib.format("Case #%d:",i))->display() ; var n : int := ("" + ((raw_input())))->toInteger() ; var p : Sequence := raw_input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; while true do ( var pp : Sequence := Integer.subrange(0, (p)->size()-1)->select(x | p[x+1] /= 0)->collect(x | (x)) ; if (pp)->size() = 0 then ( break ) else (if (pp)->size() = 2 & p[pp->first()+1] = p[pp[1+1]+1] then ( execute ('')->display() ; execute (string.uppercase[pp->first()+1])->display() ; execute (string.uppercase[pp[1+1]+1])->display() ; p[pp->first()+1] := p[pp->first()+1] - 1 ; p[pp[1+1]+1] := p[pp[1+1]+1] - 1 ) else ( var q : (trailer . (name argmax) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p)))))))) ))) := ; execute ('')->display() ; execute (string.uppercase[q+1])->display() ; p[q+1] := p[q+1] - 1 ) ) ) ; execute ('')->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def executer_calcul(entrees): N=entrees[0] parties=entrees[1] Case=entrees[2] result='' while(sum(parties)>0): evac1=maximum(parties) parties[evac1]=parties[evac1]-1 evac2=maximum(parties) if(2*parties[evac2]>sum(parties)): parties[evac2]=parties[evac2]-1 result=result+' '+chr(evac1+65)+chr(evac2+65) else : result=result+' '+chr(evac1+65) return result def maximum(liste): maximum=0 for i in range(len(liste)): if(liste[i]>liste[maximum]): maximum=i return maximum multiprocessed=False if(multiprocessed): from multiprocessing import Pool else : output=open('Output.txt','w') if((not multiprocessed)or __name__=='__main__'): with open("Input.txt","r")as input : lines=input.readlines() T=int(lines[0]) line=1 Case=1 calculs=[] while(linefirst())))->toInteger() ; var line : int := 1 ; Case := 1 ; var calculs : Sequence := Sequence{} ; while ((line->compareTo((lines)->size())) < 0) do ( N := ("" + ((lines[line+1])))->toInteger() ; line := line + 1 ; parties := ((lines[line+1].split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; line := line + 1 ; entrees := Sequence{N}->union(Sequence{parties}->union(Sequence{ Case })) ; if (not(multiprocessed)) then ( output.write('Case #' + ("" + ((Case))) + ':' + executer_calcul(entrees) + ' ') ) else ( execute ((entrees) : calculs) ) ; Case := Case + 1) ; if (multiprocessed) then ( var pool : OclAny := Pool(3) ; var results : OclAny := pool.map(executer_calcul, calculs) ; output := OclFile.newOclFile_Write(OclFile.newOclFile('Output.txt')) ; for case : Integer.subrange(0, (results)->size()-1) do ( output.write('Case #' + ("" + ((case + 1))) + ': ' + results[case+1] + ' ')) ) else skip ; output.closeFile() ) else skip; operation executer_calcul(entrees : OclAny) : OclAny pre: true post: true activity: var N : OclAny := entrees->first() ; var parties : OclAny := entrees[1+1] ; var Case : OclAny := entrees[2+1] ; var result : String := '' ; while ((parties)->sum() > 0) do ( var evac1 : OclAny := maximum(parties) ; parties[evac1+1] := parties[evac1+1] - 1 ; var evac2 : OclAny := maximum(parties) ; if ((2 * parties[evac2+1]->compareTo((parties)->sum())) > 0) then ( parties[evac2+1] := parties[evac2+1] - 1 ; result := result + ' ' + (evac1 + 65)->byte2char() + (evac2 + 65)->byte2char() ) else ( result := result + ' ' + (evac1 + 65)->byte2char() )) ; return result; operation maximum(liste : OclAny) : OclAny pre: true post: true activity: var maximum : int := 0 ; for i : Integer.subrange(0, (liste)->size()-1) do ( if ((liste[i+1]->compareTo(liste[maximum+1])) > 0) then ( maximum := i ) else skip) ; return maximum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def letter(x): return chr(ord('A')+x) def solve_test(inp): n=int(inp.readline()) ans=[] counts=[int(x)for x in inp.readline().split()] total=sum(counts) if total % 2==1 : winner=counts.index(max(counts)) ans.append(letter(winner)) counts[winner]-=1 while sum(counts)>0 : winner1=counts.index(max(counts)) counts[winner1]-=1 winner2=counts.index(max(counts)) counts[winner2]-=1 ans.append(letter(winner1)+letter(winner2)) return ' '.join(ans) def solve_dumb(inp): return '1' inp=open(sys.argv[1]) inp_dumb=open(sys.argv[1]) out=open(sys.argv[1].rsplit('.',1)[0]+'.out','w') out_dumb=open(sys.argv[1].rsplit('.',1)[0]+'.dumb.out','w') n_tests=int(inp.readline()) for i in range(n_tests): ans=solve_test(inp) print("Case #%d: " %(i+1)+ans,file=out) ans_dumb=solve_dumb(inp_dumb) print("Case #%d: " %(i+1)+ans_dumb,file=out_dumb) if ans!=ans_dumb : print('Wrong',i+1,file=sys.stderr) out.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; inp := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) ; var inp_dumb : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) ; var out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(sys.argv[1+1].rsplit('.', 1)->first() + '.out')) ; var out_dumb : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(sys.argv[1+1].rsplit('.', 1)->first() + '.dumb.out')) ; var n_tests : int := ("" + ((inp.readLine())))->toInteger() ; for i : Integer.subrange(0, n_tests-1) do ( ans := solve_test(inp) ; execute (StringLib.format("Case #%d: ",(i + 1))->union(ans))->display() ; var ans_dumb : OclAny := solve_dumb(inp_dumb) ; execute (StringLib.format("Case #%d: ",(i + 1)) + ans_dumb)->display() ; if ans /= ans_dumb then ( execute ('Wrong')->display() ) else skip) ; out.closeFile(); operation letter(x : OclAny) : OclAny pre: true post: true activity: return (('A')->char2byte() + x)->byte2char(); operation solve_test(inp : OclAny) : OclAny pre: true post: true activity: var n : int := ("" + ((inp.readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; var counts : Sequence := inp.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var total : OclAny := (counts)->sum() ; if total mod 2 = 1 then ( var winner : int := counts->indexOf((counts)->max()) - 1 ; execute ((letter(winner)) : ans) ; counts[winner+1] := counts[winner+1] - 1 ) else skip ; while (counts)->sum() > 0 do ( var winner1 : int := counts->indexOf((counts)->max()) - 1 ; counts[winner1+1] := counts[winner1+1] - 1 ; var winner2 : int := counts->indexOf((counts)->max()) - 1 ; counts[winner2+1] := counts[winner2+1] - 1 ; execute ((letter(winner1) + letter(winner2)) : ans)) ; return StringLib.sumStringsWithSeparator((ans), ' '); operation solve_dumb(inp : OclAny) : OclAny pre: true post: true activity: return '1'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for case in range(1,T+1): N=int(input()) line=input() t=line.split() a=[[chr(ord('A')+i),int(t[i])]for i in range(len(t))] tot=sum([x[1]for x in a]) res=[] while tot>0 : a.sort(reverse=True,key=lambda x : x[1]) if 2*a[1][1]<=tot-1 : a[0][1]-=1 tot-=1 res.append(a[0][0]) else : a[0][1]-=1 a[1][1]-=1 tot-=2 res.append(a[0][0]+a[1][0]) print("Case #{0}:{1}".format(case,' '.join(res))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for case : Integer.subrange(1, T + 1-1) do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var line : String := (OclFile["System.in"]).readLine() ; var t : OclAny := line.split() ; var a : Sequence := Integer.subrange(0, (t)->size()-1)->select(i | true)->collect(i | (Sequence{(('A')->char2byte() + i)->byte2char()}->union(Sequence{ ("" + ((t[i+1])))->toInteger() }))) ; var tot : OclAny := (a->select(x | true)->collect(x | (x[1+1])))->sum() ; var res : Sequence := Sequence{} ; while tot > 0 do ( a := a->sort() ; if (2 * a[1+1][1+1]->compareTo(tot - 1)) <= 0 then ( a->first()[1+1] := a->first()[1+1] - 1 ; tot := tot - 1 ; execute ((a->first()->first()) : res) ) else ( a->first()[1+1] := a->first()[1+1] - 1 ; a[1+1][1+1] := a[1+1][1+1] - 1 ; tot := tot - 2 ; execute ((a->first()->first() + a[1+1]->first()) : res) )) ; execute (StringLib.interpolateStrings("Case #{0}:{1}", Sequence{case, StringLib.sumStringsWithSeparator((res), ' ')}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): print("Case #"+str(i+1)+":",end="") n=int(input()) members=list(map(int,input().split())) while max(members)>0 : r=max(members) l=[i for i in range(len(members))if members[i]==r] if len(l)==2 : out=l else : out=[l[0]] print("".join(chr(i+ord('A'))for i in out),end="") for i in out : members[i]-=1 print("") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( execute ("Case #" + ("" + ((i + 1))) + ":")->display() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var members : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; while (members)->max() > 0 do ( var r : OclAny := (members)->max() ; var l : Sequence := Integer.subrange(0, (members)->size()-1)->select(i | members[i+1] = r)->collect(i | (i)) ; if (l)->size() = 2 then ( var out : Sequence := l ) else ( out := Sequence{ l->first() } ) ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name chr)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name ord)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'A'))))))) )))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name out)))))))), ""))->display() ; for i : out do ( members[i+1] := members[i+1] - 1)) ; execute ("")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys ip=lambda : sys.stdin.readline().rstrip() n=int(ip()) a=list(map(int,ip().split())) ans=True ans1=[] inside=set() left=set() p=0 for i in range(n): if a[i]>0 : if a[i]in inside or a[i]in left : ans=False break inside.add(a[i]) else : if abs(a[i])not in inside or abs(a[i])in left : ans=False break inside.remove(abs(a[i])) left.add(abs(a[i])) if ans and len(inside)==0 : ans1.append(i+1-p) inside=set() left=set() p=i+1 if len(inside)!=0 : ans=False if ans : print(len(ans1)) print(*ans1) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var ip : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var n : int := ("" + ((ip->apply())))->toInteger() ; var a : Sequence := ((ip->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : boolean := true ; var ans1 : Sequence := Sequence{} ; var inside : Set := Set{}->union(()) ; var left : Set := Set{}->union(()) ; var p : int := 0 ; for i : Integer.subrange(0, n-1) do ( if a[i+1] > 0 then ( if (inside)->includes(a[i+1]) or (left)->includes(a[i+1]) then ( ans := false ; break ) else skip ; execute ((a[i+1]) : inside) ) else ( if (inside)->excludes((a[i+1])->abs()) or (left)->includes((a[i+1])->abs()) then ( ans := false ; break ) else skip ; execute (((a[i+1])->abs()) /: inside) ; execute (((a[i+1])->abs()) : left) ) ; if ans & (inside)->size() = 0 then ( execute ((i + 1 - p) : ans1) ; inside := Set{}->union(()) ; left := Set{}->union(()) ; p := i + 1 ) else skip) ; if (inside)->size() /= 0 then ( ans := false ) else skip ; if ans then ( execute ((ans1)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans1))))))))->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split(':')) c=0 while True : if a<10 and b>=10 : s='0'+str(a)+str(b) elif a>=10 and b<10 : s=str(a)+'0'+str(b) elif a<10 and b<10 : s='0'+str(a)+'0'+str(b) else : s=str(a)+str(b) if s==s[: :-1]: break else : if a==23 and b==59 : a=0 b=0 c+=1 elif b==59 : a+=1 b=0 c+=1 else : b+=1 c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split(':'))->collect( _x | (OclType["int"])->apply(_x) ) ; var c : int := 0 ; while true do ( if a < 10 & b >= 10 then ( var s : String := '0' + ("" + ((a))) + ("" + ((b))) ) else (if a >= 10 & b < 10 then ( s := ("" + ((a))) + '0' + ("" + ((b))) ) else (if a < 10 & b < 10 then ( s := '0' + ("" + ((a))) + '0' + ("" + ((b))) ) else ( s := ("" + ((a))) + ("" + ((b))) ) ) ) ; if s = s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( break ) else ( if a = 23 & b = 59 then ( var a : int := 0 ; var b : int := 0 ; c := c + 1 ) else (if b = 59 then ( a := a + 1 ; b := 0 ; c := c + 1 ) else ( b := b + 1 ; c := c + 1 ) ) )) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sh,sm=map(int,input().split(':')) mins=sh*60+sm can=[] for h in range(24): ms=int("{:02d}".format(h)[: :-1]) if 0<=ms<60 : can.append(h*60+ms) can.append(24*60) print(min(k for k in can if k>=mins)-mins) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sh : OclAny := null; var sm : OclAny := null; Sequence{sh,sm} := (input().split(':'))->collect( _x | (OclType["int"])->apply(_x) ) ; var mins : double := sh * 60 + sm ; var can : Sequence := Sequence{} ; for h : Integer.subrange(0, 24-1) do ( var ms : int := ("" + (("{:02d}".format(h)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))))->toInteger() ; if 0 <= ms & (ms < 60) then ( execute ((h * 60 + ms) : can) ) else skip) ; execute ((24 * 60) : can) ; execute (((argument (test (logical_test (comparison (expr (atom (name k)))))) (comp_for for (exprlist (expr (atom (name k)))) in (logical_test (comparison (expr (atom (name can))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name k)))) >= (comparison (expr (atom (name mins)))))))))))->min() - mins)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=list(map(str,input().split(':'))) cnt=0 while(a[0]+a[1])!=(a[0]+a[1])[: :-1]: cnt+=1 a[1]=str((int(a[1])+1)% 60) if len(a[1])==1 : a[1]='0'+a[1] if(a[1]=='00'): a[0]=str((int(a[0])+1)% 24) if(len(a[0])==1): a[0]='0'+a[0] print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := ((input().split(':'))->collect( _x | (OclType["String"])->apply(_x) )) ; var cnt : int := 0 ; while (a->first() + a[1+1]) /= (a->first() + a[1+1])(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( cnt := cnt + 1 ; a[1+1] := ("" + (((("" + ((a[1+1])))->toInteger() + 1) mod 60))) ; if (a[1+1])->size() = 1 then ( a[1+1] := '0' + a[1+1] ) else skip ; if (a[1+1] = '00') then ( a->first() := ("" + (((("" + ((a->first())))->toInteger() + 1) mod 24))) ; if ((a->first())->size() = 1) then ( a->first() := '0' + a->first() ) else skip ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=[0,70,140,210,280,350,601,671,741,811,881,951,1202,1272,1342,1412,1440] d=input().split(':') d=int(d[0])*60+int(d[1]) m=10000 for i in c : if(i-d)>=0 and(i-d)<=m : m=i-d print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : Sequence := Sequence{0}->union(Sequence{70}->union(Sequence{140}->union(Sequence{210}->union(Sequence{280}->union(Sequence{350}->union(Sequence{601}->union(Sequence{671}->union(Sequence{741}->union(Sequence{811}->union(Sequence{881}->union(Sequence{951}->union(Sequence{1202}->union(Sequence{1272}->union(Sequence{1342}->union(Sequence{1412}->union(Sequence{ 1440 })))))))))))))))) ; var d : OclAny := input().split(':') ; d := ("" + ((d->first())))->toInteger() * 60 + ("" + ((d[1+1])))->toInteger() ; var m : int := 10000 ; for i : c do ( if (i - d) >= 0 & ((i - d)->compareTo(m)) <= 0 then ( m := i - d ) else skip) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) top=int(input()) bottomValues=set([top,7-top]) if n==1 : print("YES") else : possible=True for _ in range(n): f1,f2=map(int,input().split()) if f1 in bottomValues or f2 in bottomValues : possible=False if possible : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var top : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var bottomValues : Set := Set{}->union((Sequence{top}->union(Sequence{ 7 - top }))) ; if n = 1 then ( execute ("YES")->display() ) else ( var possible : boolean := true ; for _anon : Integer.subrange(0, n-1) do ( var f1 : OclAny := null; var f2 : OclAny := null; Sequence{f1,f2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (bottomValues)->includes(f1) or (bottomValues)->includes(f2) then ( possible := false ) else skip) ; if possible then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): s=input() f=True alpha="abcdefghijklmnopqrstuvwxyz" j=len(s)-1 k=-1 n=0 while j>=0 : if s[k]==alpha[j]: k-=1 elif s[n]==alpha[j]: n+=1 else : f=False break j-=1 if f : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var f : boolean := true ; var alpha : String := "abcdefghijklmnopqrstuvwxyz" ; var j : double := (s)->size() - 1 ; var k : int := -1 ; var n : int := 0 ; while j >= 0 do ( if s[k+1] = alpha[j+1] then ( k := k - 1 ) else (if s[n+1] = alpha[j+1] then ( n := n + 1 ) else ( f := false ; break ) ) ; j := j - 1) ; if f then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,n=input().split(':') a,b=int(m),int(n) c=0 while True : if a<10 and b>=10 : s='0'+str(a)+str(b) elif a>=10 and b<10 : s=str(a)+'0'+str(b) elif a<10 and b<10 : s='0'+str(a)+'0'+str(b) else : s=str(a)+str(b) if s==s[: :-1]: break else : if a==23 and b==59 : a=0 b=0 c+=1 elif b==59 : a+=1 b=0 c+=1 else : b+=1 c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := input().split(':') ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{("" + ((m)))->toInteger(),("" + ((n)))->toInteger()} ; var c : int := 0 ; while true do ( if a < 10 & b >= 10 then ( var s : String := '0' + ("" + ((a))) + ("" + ((b))) ) else (if a >= 10 & b < 10 then ( s := ("" + ((a))) + '0' + ("" + ((b))) ) else (if a < 10 & b < 10 then ( s := '0' + ("" + ((a))) + '0' + ("" + ((b))) ) else ( s := ("" + ((a))) + ("" + ((b))) ) ) ) ; if s = s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( break ) else ( if a = 23 & b = 59 then ( var a : int := 0 ; var b : int := 0 ; c := c + 1 ) else (if b = 59 then ( a := a + 1 ; b := 0 ; c := c + 1 ) else ( b := b + 1 ; c := c + 1 ) ) )) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def reverseList(self,head): if head is None or head.next is None : return head p=self.reverseList(head.next) head.next.next=head head.next=None return p ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation reverseList(head : OclAny) : OclAny pre: true post: true activity: if head <>= null or head.next <>= null then ( return head ) else skip ; var p : OclAny := self.reverseList(head.next) ; head.next.next := head ; head.next := null ; return p; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if n==0 : break mark=(1,1,1,1,1,-1,1,-1,1,-1,-1,1,1,1,-1,-1) k=(0,1,2,3,1,0,3,2,2,3,0,1,3,2,1,0) for i in range(n): result=[0 for i in range(4)] inp=list(map(int,input().split())) for x_i,x in enumerate(inp[: 4]): for y_i,y in enumerate(inp[4 :]): idx=x_i*4+y_i result[k[idx]]+=(mark[idx]*(x*y)) print(' '.join(map(str,result))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var mark : OclAny := Sequence{1, 1, 1, 1, 1, -1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1} ; var k : OclAny := Sequence{0, 1, 2, 3, 1, 0, 3, 2, 2, 3, 0, 1, 3, 2, 1, 0} ; for i : Integer.subrange(0, n-1) do ( var result : Sequence := Integer.subrange(0, 4-1)->select(i | true)->collect(i | (0)) ; var inp : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for _tuple : Integer.subrange(1, (inp.subrange(1,4))->size())->collect( _indx | Sequence{_indx-1, (inp.subrange(1,4))->at(_indx)} ) do (var _indx : int := 1; var x_i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); for _tuple : Integer.subrange(1, (inp.subrange(4+1))->size())->collect( _indx | Sequence{_indx-1, (inp.subrange(4+1))->at(_indx)} ) do (var _indx : int := 1; var y_i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); var idx : double := x_i * 4 + y_i ; result[k[idx+1]+1] := result[k[idx+1]+1] + (mark[idx+1] * (x * y)))) ; execute (StringLib.sumStringsWithSeparator(((result)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break for _ in range(n): x1,y1,z1,w1,x2,y2,z2,w2=map(int,input().split()) x3=x1*x2-y1*y2-z1*z2-w1*w2 y3=x1*y2+y1*x2+z1*w2-w1*z2 z3=x1*z2-y1*w2+z1*x2+w1*y2 w3=x1*w2+y1*z2-z1*y2+w1*x2 print(x3,y3,z3,w3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; for _anon : Integer.subrange(0, n-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; var z1 : OclAny := null; var w1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; var z2 : OclAny := null; var w2 : OclAny := null; Sequence{x1,y1,z1,w1,x2,y2,z2,w2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x3 : double := x1 * x2 - y1 * y2 - z1 * z2 - w1 * w2 ; var y3 : double := x1 * y2 + y1 * x2 + z1 * w2 - w1 * z2 ; var z3 : double := x1 * z2 - y1 * w2 + z1 * x2 + w1 * y2 ; var w3 : double := x1 * w2 + y1 * z2 - z1 * y2 + w1 * x2 ; execute (x3)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getRemainder(num,divisor): return(num-divisor*(num//divisor)) num=100 divisor=7 print(getRemainder(num,divisor)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; num := 100 ; divisor := 7 ; execute (getRemainder(num, divisor))->display(); operation getRemainder(num : OclAny, divisor : OclAny) : OclAny pre: true post: true activity: return (num - divisor * (num div divisor)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,bisect PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") while True : n=int(input()) if n==0 : break for k in range(n): a1,a2,a3,a4,b1,b2,b3,b4=[int(__)for __ in input().split()] p1=a1*b1-a2*b2-a3*b3-a4*b4 p2=a1*b2+a2*b1-a4*b3+a3*b4 p3=a1*b3-a2*b4+a3*b1+a4*b2 p4=a1*b4+a2*b3-a3*b2+a4*b1 print(p1,p2,p3,p4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; for k : Integer.subrange(0, n-1) do ( var a1 : OclAny := null; var a2 : OclAny := null; var a3 : OclAny := null; var a4 : OclAny := null; var b1 : OclAny := null; var b2 : OclAny := null; var b3 : OclAny := null; var b4 : OclAny := null; Sequence{a1,a2,a3,a4,b1,b2,b3,b4} := input().split()->select(__ | true)->collect(__ | (("" + ((__)))->toInteger())) ; var p1 : double := a1 * b1 - a2 * b2 - a3 * b3 - a4 * b4 ; var p2 : double := a1 * b2 + a2 * b1 - a4 * b3 + a3 * b4 ; var p3 : double := a1 * b3 - a2 * b4 + a3 * b1 + a4 * b2 ; var p4 : double := a1 * b4 + a2 * b3 - a3 * b2 + a4 * b1 ; execute (p1)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if n==0 : break for _ in range(n): data=list(map(int,input().split())) c=data[0]*data[4]-data[1]*data[5]-data[2]*data[6]-data[3]*data[7] i=data[0]*data[5]+data[1]*data[4]+data[2]*data[7]-data[3]*data[6] j=data[0]*data[6]-data[1]*data[7]+data[2]*data[4]+data[3]*data[5] k=data[0]*data[7]+data[1]*data[6]-data[2]*data[5]+data[3]*data[4] print(c,i,j,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; for _anon : Integer.subrange(0, n-1) do ( var data : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : double := data->first() * data[4+1] - data[1+1] * data[5+1] - data[2+1] * data[6+1] - data[3+1] * data[7+1] ; var i : double := data->first() * data[5+1] + data[1+1] * data[4+1] + data[2+1] * data[7+1] - data[3+1] * data[6+1] ; var j : double := data->first() * data[6+1] - data[1+1] * data[7+1] + data[2+1] * data[4+1] + data[3+1] * data[5+1] ; var k : double := data->first() * data[7+1] + data[1+1] * data[6+1] - data[2+1] * data[5+1] + data[3+1] * data[4+1] ; execute (c)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- b=[[1,2,3,4],[2,-1,4,-3],[3,-4,-1,2],[4,3,-2,-1]] while 1 : n=int(input()) if n==0 : break for _ in range(n): x=tuple(map(int,input().split())) x1,x2=x[: 4],x[4 :] a=[0,0,0,0] for i in range(4): for j in range(4): if b[i][j]>0 : a[b[i][j]-1]+=x1[i]*x2[j] else : a[-b[i][j]-1]-=x1[i]*x2[j] print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var b : Sequence := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })))}->union(Sequence{Sequence{2}->union(Sequence{-1}->union(Sequence{4}->union(Sequence{ -3 })))}->union(Sequence{Sequence{3}->union(Sequence{-4}->union(Sequence{-1}->union(Sequence{ 2 })))}->union(Sequence{ Sequence{4}->union(Sequence{3}->union(Sequence{-2}->union(Sequence{ -1 }))) }))) ; while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; for _anon : Integer.subrange(0, n-1) do ( var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x1 : OclAny := null; var x2 : OclAny := null; Sequence{x1,x2} := Sequence{x.subrange(1,4),x.subrange(4+1)} ; var a : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))) ; for i : Integer.subrange(0, 4-1) do ( for j : Integer.subrange(0, 4-1) do ( if b[i+1][j+1] > 0 then ( a[b[i+1][j+1] - 1+1] := a[b[i+1][j+1] - 1+1] + x1[i+1] * x2[j+1] ) else ( a->reverse()->at(-(-b[i+1][j+1] - 1)) := a->reverse()->at(-(-b[i+1][j+1] - 1)) - x1[i+1] * x2[j+1] ))) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def module(n): return math.sqrt(n**2) def main(): x1,y1,x2,y2=[int(x)for x in input().split(" ")] a,b=[int(x)for x in input().split(" ")] if((module(x1-x2)/a)% 2==(module(y1-y2)/b)% 2)and(module(x1-x2)% a==0)and(module(y1-y2)% b==0): print("YES") else : print("NO") main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; main(); operation module(n : OclAny) : OclAny pre: true post: true activity: return ((n)->pow(2))->sqrt(); operation main() pre: true post: true activity: var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if ((module(x1 - x2) / a) mod 2 = (module(y1 - y2) / b) mod 2) & (module(x1 - x2) mod a = 0) & (module(y1 - y2) mod b = 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input().split(" ") x1=int(a[0]) y1=int(a[1]) x2=int(a[2]) y2=int(a[3]) b=input().split(" ") px=int(b[0]) py=int(b[1]) x=abs(x1-x2) y=abs(y1-y2) q=x % px w=y % py e=(x/px)% 2 r=(y/py)% 2 n="NO" if q==0 : if w==0 : if e==r : print("YES") else : print(n) else : print(n) else : print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := input().split(" ") ; var x1 : int := ("" + ((a->first())))->toInteger() ; var y1 : int := ("" + ((a[1+1])))->toInteger() ; var x2 : int := ("" + ((a[2+1])))->toInteger() ; var y2 : int := ("" + ((a[3+1])))->toInteger() ; var b : OclAny := input().split(" ") ; var px : int := ("" + ((b->first())))->toInteger() ; var py : int := ("" + ((b[1+1])))->toInteger() ; var x : double := (x1 - x2)->abs() ; var y : double := (y1 - y2)->abs() ; var q : int := x mod px ; var w : int := y mod py ; var e : int := (x / px) mod 2 ; var r : int := (y / py) mod 2 ; var n : String := "NO" ; if q = 0 then ( if w = 0 then ( if e = r then ( execute ("YES")->display() ) else ( execute (n)->display() ) ) else ( execute (n)->display() ) ) else ( execute (n)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve_e(): pos_x1,pos_y1,pos_x2,pos_y2=map(int,input().split()) pos_x_garrafa,pos_y_garrafa=map(int,input().split()) dis_x=abs(pos_x1-pos_x2) dis_y=abs(pos_y1-pos_y2) if(((dis_y % pos_y_garrafa)!=0)or((dis_x % pos_x_garrafa)!=0)): print('NO') elif(((dis_x//pos_x_garrafa)% 2)==(dis_y//pos_y_garrafa)% 2): print('YES') else : print('NO') solve_e() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve_e(); operation solve_e() pre: true post: true activity: var pos_x1 : OclAny := null; var pos_y1 : OclAny := null; var pos_x2 : OclAny := null; var pos_y2 : OclAny := null; Sequence{pos_x1,pos_y1,pos_x2,pos_y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var pos_x_garrafa : OclAny := null; var pos_y_garrafa : OclAny := null; Sequence{pos_x_garrafa,pos_y_garrafa} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dis_x : double := (pos_x1 - pos_x2)->abs() ; var dis_y : double := (pos_y1 - pos_y2)->abs() ; if (((dis_y mod pos_y_garrafa) /= 0) or ((dis_x mod pos_x_garrafa) /= 0)) then ( execute ('NO')->display() ) else (if (((dis_x div pos_x_garrafa) mod 2) = (dis_y div pos_y_garrafa) mod 2) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): s=input() n=len(s) chk='' flag=True if 'a' not in s : print("NO") else : for i in range(97,97+n): chk+=chr(i) l=s.index('a') r=l for i in range(1,n): if chk[i]not in s : flag=False break pos=s.index(chk[i]) if pos!=l-1 and pos!=r+1 : flag=False break else : l=min(l,pos) r=max(r,pos) if flag : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var n : int := (s)->size() ; var chk : String := '' ; var flag : boolean := true ; if (s)->characters()->excludes('a') then ( execute ("NO")->display() ) else ( for i : Integer.subrange(97, 97 + n-1) do ( chk := chk + (i)->byte2char()) ; var l : int := s->indexOf('a') - 1 ; var r : int := l ; for i : Integer.subrange(1, n-1) do ( if (s)->characters()->excludes(chk[i+1]) then ( flag := false ; break ) else skip ; var pos : int := s->indexOf(chk[i+1]) - 1 ; if pos /= l - 1 & pos /= r + 1 then ( flag := false ; break ) else ( l := Set{l, pos}->min() ; r := Set{r, pos}->max() )) ; if flag then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x1,y1,x2,y2=map(int,input().split()) x,y=map(int,input().split()) dx,dy=abs(x2-x1),abs(y2-y1) if dx % x==0 and dy % y==0 : mx=dx/x my=dy/y if mx % 2==my % 2 : print("YES") else : print("NO") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dx : OclAny := null; var dy : OclAny := null; Sequence{dx,dy} := Sequence{(x2 - x1)->abs(),(y2 - y1)->abs()} ; if dx mod x = 0 & dy mod y = 0 then ( var mx : double := dx / x ; var my : double := dy / y ; if mx mod 2 = my mod 2 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x1,y1,x2,y2=map(int,input().split()) x,y=map(int,input().split()) aux=abs(x2-x1) aux2=abs(y2-y1) aux3=aux % x aux4=aux2 % y if(aux/x)% 2==(aux2/y)% 2 and aux3==0 and aux4==0 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var aux : double := (x2 - x1)->abs() ; var aux2 : double := (y2 - y1)->abs() ; var aux3 : int := aux mod x ; var aux4 : int := aux2 mod y ; if (aux / x) mod 2 = (aux2 / y) mod 2 & aux3 = 0 & aux4 = 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque q=deque() K=int(input()) q.append((1,1)) m={} while len(q): n,s=q.popleft() if n in m : continue m[n]=s q.appendleft((n*10 % K,s)) q.append(((n+1)% K,s+1)) print(m[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var q : Sequence := () ; var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((Sequence{1, 1}) : q) ; var m : OclAny := Set{} ; while (q)->size() do ( var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := q->first() ; q := q->tail() ; if (m)->includes(n) then ( continue ) else skip ; m[n+1] := s ; q := q->prepend(Sequence{n * 10 mod K, s}) ; execute ((Sequence{(n + 1) mod K, s + 1}) : q)) ; execute (m->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,z=input().split() n,m,z=int(n),int(m),int(z) n1,m1=n,m kill=0 calls=[] artists=[] for call in range(n,z+1,n): calls.append(call) for artist in range(m,z+1,m): artists.append(artist) print(len(list(set(calls).intersection(artists)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var z : OclAny := null; Sequence{n,m,z} := input().split() ; var n : OclAny := null; var m : OclAny := null; var z : OclAny := null; Sequence{n,m,z} := Sequence{("" + ((n)))->toInteger(),("" + ((m)))->toInteger(),("" + ((z)))->toInteger()} ; var n1 : OclAny := null; var m1 : OclAny := null; Sequence{n1,m1} := Sequence{n,m} ; var kill : int := 0 ; var calls : Sequence := Sequence{} ; var artists : Sequence := Sequence{} ; for call : Integer.subrange(n, z + 1-1)->select( $x | ($x - n) mod n = 0 ) do ( execute ((call) : calls)) ; for artist : Integer.subrange(m, z + 1-1)->select( $x | ($x - m) mod m = 0 ) do ( execute ((artist) : artists)) ; execute (((Set{}->union((calls))->intersection(artists)))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,Counter from itertools import product,groupby,count,permutations,combinations from math import pi,sqrt from collections import deque from heapq import heappop,heappush from bisect import bisect,bisect_left,bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF=float("inf") YES,Yes,yes,NO,No,no="YES","Yes","yes","NO","No","no" dy4,dx4=[0,1,0,-1],[1,0,-1,0] def inside(y,x,H,W): return 0<=ydp[p]+1 : dp[(p+1)% K]=dp[p]+1 heappush(heap,(dp[p]+1,(p+1)% K)) if dp[(p*10)% K]>dp[p]: dp[(p*10)% K]=dp[p] heappush(heap,(dp[p],(p*10)% K)) if dp[0]!=INF : break print(dp[0]) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(10000) ; var INF : double := ("" + (("inf")))->toReal() ; var YES : OclAny := null; var Yes : OclAny := null; var yes : OclAny := null; var NO : OclAny := null; var No : OclAny := null; var no : OclAny := null; Sequence{YES,Yes,yes,NO,No,no} := Sequence{"YES","Yes","yes","NO","No","no"} ; var dy4 : OclAny := null; var dx4 : OclAny := null; Sequence{dy4,dx4} := Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ -1 }))),Sequence{1}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{ 0 })))} ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation inside(y : OclAny, x : OclAny, H : OclAny, W : OclAny) : OclAny pre: true post: true activity: return 0 <= y & (y < H) & 0 <= x & (x < W); operation ceil(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a + b - 1) div b; operation main() pre: true post: true activity: var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, K) ; dp[1+1] := 1 ; var heap : Sequence := Sequence{} ; heappush(heap, Sequence{1, 1}) ; while (heap)->size() /= 0 do ( var k : OclAny := null; var p : OclAny := null; Sequence{k,p} := heappop(heap) ; if (dp[(p + 1) mod K+1]->compareTo(dp[p+1] + 1)) > 0 then ( dp[(p + 1) mod K+1] := dp[p+1] + 1 ; heappush(heap, Sequence{dp[p+1] + 1, (p + 1) mod K}) ) else skip ; if (dp[(p * 10) mod K+1]->compareTo(dp[p+1])) > 0 then ( dp[(p * 10) mod K+1] := dp[p+1] ; heappush(heap, Sequence{dp[p+1], (p * 10) mod K}) ) else skip ; if dp->first() /= INF then ( break ) else skip) ; execute (dp->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heappush,heappop K=int(input()) queue=[(1,1)] dist=[float('inf')]*K dist[1]=1 while queue : cost,cur=heappop(queue) if cost+1toInteger() ; var queue : Sequence := Sequence{ Sequence{1, 1} } ; var dist : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (('inf')))->toReal() }, K) ; dist[1+1] := 1 ; while queue do ( var cost : OclAny := null; var cur : OclAny := null; Sequence{cost,cur} := heappop(queue) ; if (cost + 1->compareTo(dist[(cur + 1) mod K+1])) < 0 then ( dist[(cur + 1) mod K+1] := cost + 1 ; heappush(queue, Sequence{cost + 1, (cur + 1) mod K}) ) else skip ; if (cost->compareTo(dist[cur * 10 mod K+1])) < 0 then ( dist[cur * 10 mod K+1] := cost ; heappush(queue, Sequence{cost, cur * 10 mod K}) ) else skip) ; execute (dist->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heappop,heappush def dijkstra(s,n,edge): inf=10**20 ans=[inf]*n ans[s]=0 h=[[0,s]] while h : c,v=heappop(h) if ans[v]toInteger() ; edge := Integer.subrange(0, k-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(1, k-1) do ((expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom (number (integer 10))))))))) ))) % (expr (atom (name k))))))) , (test (logical_test (comparison (expr (atom (number (integer 0)))))))) )))))))) )))) ; (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) ))) % (expr (atom (name k))))))) , (test (logical_test (comparison (expr (atom (number (integer 1)))))))) )))))))) ))))) ; ans := dijkstra(1, k, edge) ; execute (ans->first() + 1)->display(); operation dijkstra(s : OclAny, n : OclAny, edge : OclAny) : OclAny pre: true post: true activity: var Math_PINFINITY : double := (10)->pow(20) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ Math_PINFINITY }, n) ; ans[s+1] := 0 ; var h : Sequence := Sequence{ Sequence{0}->union(Sequence{ s }) } ; while h do ( var c : OclAny := null; var v : OclAny := null; Sequence{c,v} := heappop(h) ; if (ans[v+1]->compareTo(c)) < 0 then ( continue ) else skip ; for _tuple : edge[v+1] do (var _indx : int := 1; var u : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); if (c + t->compareTo(ans[u+1])) < 0 then ( ans[u+1] := c + t ; heappush(h, Sequence{c + t}->union(Sequence{ u })) ) else skip)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import exit,setrecursionlimit,stderr from functools import reduce from itertools import* from collections import defaultdict,deque from bisect import bisect from random import* def read(): return int(input()) def reads(): return[int(x)for x in input().split()] INF=1<<60 def bfs(K): result=[INF]*K result[1]=1 que=deque([(1,1)]) while len(que)>0 : (d,u)=que.popleft() if result[u]pow(60)) ; skip ; var Sequence{d, u} : OclAny := que->first() ; que := que->tail(); operation read() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation reads() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation bfs(K : OclAny) pre: true post: true activity: var result : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, K) ; result[1+1] := 1 ; var que : Sequence := (Sequence{ Sequence{1, 1} }) ; while (que)->size() > 0 do (suite); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMaximum(l,p,q,r): dp=[-1]*(l+1) dp[0]=0 for i in range(l+1): if(dp[i]==-1): continue if(i+p<=l): dp[i+p]=(max(dp[i+p],dp[i]+1)) if(i+q<=l): dp[i+q]=(max(dp[i+q],dp[i]+1)) if(i+r<=l): dp[i+r]=(max(dp[i+r],dp[i]+1)) return dp[l] if __name__=="__main__" : l=11 p=2 q=3 r=5 ans=findMaximum(l,p,q,r) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( l := 11 ; p := 2 ; q := 3 ; r := 5 ; var ans : OclAny := findMaximum(l, p, q, r) ; execute (ans)->display() ) else skip; operation findMaximum(l : OclAny, p : OclAny, q : OclAny, r : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (l + 1)) ; dp->first() := 0 ; for i : Integer.subrange(0, l + 1-1) do ( if (dp[i+1] = -1) then ( continue ) else skip ; if ((i + p->compareTo(l)) <= 0) then ( dp[i + p+1] := (Set{dp[i + p+1], dp[i+1] + 1}->max()) ) else skip ; if ((i + q->compareTo(l)) <= 0) then ( dp[i + q+1] := (Set{dp[i + q+1], dp[i+1] + 1}->max()) ) else skip ; if ((i + r->compareTo(l)) <= 0) then ( dp[i + r+1] := (Set{dp[i + r+1], dp[i+1] + 1}->max()) ) else skip) ; return dp[l+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(input()) if n==1 : print(4,2,sep='\n'); sys.exit(0) ans=1 for i in range(2,n+2): ans*=i print(ans+2) for i in range(2,n+2): print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (4)->display(); sys.exit(0) ) else skip ; var ans : int := 1 ; for i : Integer.subrange(2, n + 2-1) do ( ans := ans * i) ; execute (ans + 2)->display() ; for i : Integer.subrange(2, n + 2-1) do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import reduce if __name__=="__main__" : n=int(input()) n1500=4811 print(n1500) for i in range(0,n): print(i+2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n1500 : int := 4811 ; execute (n1500)->display() ; for i : Integer.subrange(0, n-1) do ( execute (i + 2)->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : for _ in range(int(input())): c=input() alpha="abcdefghijklmnopqrstuvwxyz" alphabetical=True if not 'a' in c : print("NO") else : pos=c.index('a') L=pos R=L for i in range(1,len(c)): pos=c.find(alpha[i]) if pos==-1 or pos!=L-1 and pos!=R+1 : alphabetical=False break else : L=min(L,pos) R=max(R,pos) print("YES" if alphabetical else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var c : String := (OclFile["System.in"]).readLine() ; var alpha : String := "abcdefghijklmnopqrstuvwxyz" ; var alphabetical : boolean := true ; if not((c)->characters()->includes('a')) then ( execute ("NO")->display() ) else ( var pos : int := c->indexOf('a') - 1 ; var L : int := pos ; var R : int := L ; for i : Integer.subrange(1, (c)->size()-1) do ( pos := c->indexOf(alpha[i+1]) - 1 ; if pos = -1 or pos /= L - 1 & pos /= R + 1 then ( alphabetical := false ; break ) else ( L := Set{L, pos}->min() ; R := Set{R, pos}->max() )) ; execute (if alphabetical then "YES" else "NO" endif)->display() )) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(1000000) memo={0 : 1} def fact(num): if num in memo : return memo[num] memo[num]=num*fact(num-1) return memo[num] n=int(input()) print(fact(n+1)+2) for i in range(n): print(i+2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(1000000) ; var memo : Map := Map{ 0 |-> 1 } ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (fact(n + 1) + 2)->display() ; for i : Integer.subrange(0, n-1) do ( execute (i + 2)->display()); operation fact(num : OclAny) : OclAny pre: true post: true activity: if (memo)->includes(num) then ( return memo[num+1] ) else skip ; memo[num+1] := num * fact(num - 1) ; return memo[num+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): num=2 i=3 for _ in range(1500//2): num*=i i+=2 n=int(input()) print(num+2) for i in range(n): a=i+2 if i % 2==0 : a=2 print(a) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var num : int := 2 ; var i : int := 3 ; for _anon : Integer.subrange(0, 1500 div 2-1) do ( num := num * i ; i := i + 2) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (num + 2)->display() ; for i : Integer.subrange(0, n-1) do ( var a : int := i + 2 ; if i mod 2 = 0 then ( a := 2 ) else skip ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd n,m,z=(int(i)for i in input().split()) lcm=n*m//gcd(n,m) res=z//lcm print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; var z : OclAny := null; Sequence{n,m,z} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var lcm : int := n * m div gcd(n, m) ; var res : int := z div lcm ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import os import math n=int(input()) if n==1 : print(4) print(2) elif n==2 : print(8) print(4) print(3) else : a=1 for i in range(1,n+2): a*=i print(a-n-1) for i in range(n+1,1,-1): print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (4)->display() ; execute (2)->display() ) else (if n = 2 then ( execute (8)->display() ; execute (4)->display() ; execute (3)->display() ) else ( var a : int := 1 ; for i : Integer.subrange(1, n + 2-1) do ( a := a * i) ; execute (a - n - 1)->display() ; for i : Integer.subrange(1 + 1, n + 1)->reverse() do ( execute (i)->display()) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=input().split() a=int(a) b=int(b) sum1=0 s=a+a//b for i in range(a+1,s+1): if i % b==0 : s+=1 if s % b==0 : s+=1 print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; var sum1 : int := 0 ; var s : int := a + a div b ; for i : Integer.subrange(a + 1, s + 1-1) do ( if i mod b = 0 then ( s := s + 1 ; if s mod b = 0 then ( s := s + 1 ) else skip ) else skip) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) days=0 while n>0 : days+=1 n-=1 if days % m==0 : n+=1 print(days) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var days : int := 0 ; while n > 0 do ( days := days + 1 ; n := n - 1 ; if days mod m = 0 then ( n := n + 1 ) else skip) ; execute (days)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) days=0 cof=1 while n>0 : n-=1 days+=1 if days==m*cof : n+=1 cof+=1 print(days) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var days : int := 0 ; var cof : int := 1 ; while n > 0 do ( n := n - 1 ; days := days + 1 ; if days = m * cof then ( n := n + 1 ; cof := cof + 1 ) else skip) ; execute (days)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) results=(a-1)//(b-1) print(a+results) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var results : int := (a - 1) div (b - 1) ; execute (a + results)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) day=n new_sock=n//m day+=new_sock add_day=new_sock+n-(n//m)*m while add_day>=m : new_sock=add_day//m day+=new_sock n=add_day add_day=new_sock+n-(n//m)*m print(day) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var day : OclAny := n ; var new_sock : int := n div m ; day := day + new_sock ; var add_day : double := new_sock + n - (n div m) * m ; while (add_day->compareTo(m)) >= 0 do ( new_sock := add_day div m ; day := day + new_sock ; var n : OclAny := add_day ; add_day := new_sock + n - (n div m) * m) ; execute (day)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- NO_OF_CHARS=256 def areAnagram(str1 : str,str2 : str)->bool : count=[0]*NO_OF_CHARS i=0 while iunion(Sequence{"geeksforgeeks"}->union(Sequence{"abcd"}->union(Sequence{"forgeeksgeeks"}->union(Sequence{ "zuiqkeegs" })))) ; var n : int := (arr)->size() ; findAllAnagrams(arr, n) ) else skip; operation areAnagram(str1 : String, str2 : String) : boolean pre: true post: true activity: var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, NO_OF_CHARS) ; var i : int := 0 ; while (i->compareTo((str1)->size())) < 0 & (i->compareTo((str2)->size())) < 0 do ( count[(str1[i+1])->char2byte()+1] := count[(str1[i+1])->char2byte()+1] + 1 ; count[(str2[i+1])->char2byte()+1] := count[(str2[i+1])->char2byte()+1] - 1 ; i := i + 1) ; if (str1)->size() /= (str2)->size() then ( return false ) else skip ; for i : Integer.subrange(0, NO_OF_CHARS-1) do ( if count[i+1] then ( return false ) else skip ; return true); operation findAllAnagrams(arr : Sequence(OclAny), n : int) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if areAnagram(arr[i+1], arr[j+1]) then ( execute (arr[i+1])->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np max_size=20 max_k=20 dp=np.zeros((max_size,max_k)); v=np.zeros((max_size,max_k)); sum=0 ; def findSum(arr,n): global sum for i in range(n): sum+=arr[i]; def cntWays(arr,i,ck,k,n,curr_sum): if(sum % k!=0): return 0 ; if(i!=n and ck==k+1): return 0 ; if(i==n): if(ck==k+1): return 1 ; else : return 0 ; if(v[i][ck]): return dp[i][ck]; curr_sum+=arr[i]; v[i][ck]=1 ; dp[i][ck]=cntWays(arr,i+1,ck,k,n,curr_sum); if(curr_sum==(sum/k)*ck): dp[i][ck]+=cntWays(arr,i+1,ck+1,k,n,curr_sum); return dp[i][ck]; if __name__=="__main__" : arr=[1,-1,1,-1,1,-1]; n=len(arr); k=2 ; findSum(arr,n); print(cntWays(arr,0,1,k,n,0)); ------------------------------------------------------------ OCL File: --------- class FromPython { attribute sum : OclAny; operation initialise() pre: true post: true activity: skip ; var max_size : int := 20 ; var max_k : int := 20 ; var dp : Sequence := MatrixLib.singleValueMatrix(Sequence{max_size, max_k}, 0.0); ; var v : Sequence := MatrixLib.singleValueMatrix(Sequence{max_size, max_k}, 0.0); ; var sum : int := 0; ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{-1}->union(Sequence{1}->union(Sequence{-1}->union(Sequence{1}->union(Sequence{ -1 }))))); ; n := (arr)->size(); ; k := 2; ; findSum(arr, n); ; execute (cntWays(arr, 0, 1, k, n, 0))->display(); ) else skip; operation findSum(arr : OclAny, n : OclAny) pre: true post: true activity: skip ; for i : Integer.subrange(0, n-1) do ( sum := sum + arr[i+1];); operation cntWays(arr : OclAny, i : OclAny, ck : OclAny, k : OclAny, n : OclAny, curr_sum : OclAny) pre: true post: true activity: if (sum mod k /= 0) then ( return 0; ) else skip ; if (i /= n & ck = k + 1) then ( return 0; ) else skip ; if (i = n) then ( if (ck = k + 1) then ( return 1; ) else ( return 0; ) ) else skip ; if (v[i+1][ck+1]) then ( return dp[i+1][ck+1]; ) else skip ; curr_sum := curr_sum + arr[i+1]; ; v[i+1][ck+1] := 1; ; dp[i+1][ck+1] := cntWays(arr, i + 1, ck, k, n, curr_sum); ; if (curr_sum = (sum / k) * ck) then ( dp[i+1][ck+1] := dp[i+1][ck+1] + cntWays(arr, i + 1, ck + 1, k, n, curr_sum); ) else skip ; return dp[i+1][ck+1];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import string alphabet=string.ascii_lowercase[1 :] t=int(input()) for i in range(t): s=input() if len(set(list(s)))0 and s[rn[0]-1]==char : rn[0]-=1 elif rn[1]tail() ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if ((Set{}->union(((s)->characters())))->size()->compareTo((s)->size())) < 0 then ( execute ("NO")->display() ; continue ) else skip ; if (s)->characters()->excludes("a") then ( execute ("NO")->display() ; continue ) else skip ; var check : boolean := true ; var rn : Sequence := MatrixLib.elementwiseMult(Sequence{ s->indexOf("a") - 1 }, 2) ; for j : Integer.subrange(0, (s)->size() - 1-1) do ( var char : OclAny := alphabet[j+1] ; if rn->first() > 0 & s[rn->first() - 1+1] = char then ( rn->first() := rn->first() - 1 ) else (if (rn[1+1]->compareTo((s)->size() - 1)) < 0 & s[rn[1+1] + 1+1] = char then ( rn[1+1] := rn[1+1] + 1 ) else ( check := false ; break ) ) ) ; if check = true then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(arr,n,k): minx=sys.maxsize ; for i in range(n): minx=min(minx,arr[i]); decrements=0 ; for i in range(n): if((arr[i]-minx)% k!=0): return-1 ; else : decrements+=((arr[i]-minx)//k); return decrements ; if __name__=="__main__" : n=3 ; k=3 ; arr=[12,9,15]; print(solve(arr,n,k)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 3; ; k := 3; ; arr := Sequence{12}->union(Sequence{9}->union(Sequence{ 15 })); ; execute (solve(arr, n, k))->display(); ) else skip; operation solve(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var minx : (trailer . (name maxsize)) := (trailer . (name maxsize)); ; for i : Integer.subrange(0, n-1) do ( minx := Set{minx, arr[i+1]}->min();) ; var decrements : int := 0; ; for i : Integer.subrange(0, n-1) do ( if ((arr[i+1] - minx) mod k /= 0) then ( return -1; ) else ( decrements := decrements + ((arr[i+1] - minx) div k); )) ; return decrements;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a,b,c=map(int,input().split()) print(c//(a*b//math.gcd(a,b))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (c div (a * b div (a)->gcd(b)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isSubsetSum(set,n,sum): subset=([[False for i in range(sum+1)]for i in range(n+1)]) for i in range(n+1): subset[i][0]=True for i in range(1,sum+1): subset[0][i]=False for i in range(1,n+1): for j in range(1,sum+1): if j=set[i-1]: subset[i][j]=(subset[i-1][j]or subset[i-1][j-set[i-1]]) return subset[n][sum] if __name__=='__main__' : set=[3,34,4,12,5,2] sum=9 n=len(set) if(isSubsetSum(set,n,sum)==True): print("Found a subset with given sum") else : print("No subset with given sum") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( OclType["Set"] := Sequence{3}->union(Sequence{34}->union(Sequence{4}->union(Sequence{12}->union(Sequence{5}->union(Sequence{ 2 }))))) ; sum := 9 ; n := (OclType["Set"])->size() ; if (isSubsetSum(OclType["Set"], n, sum) = true) then ( execute ("Found a subset with given sum")->display() ) else ( execute ("No subset with given sum")->display() ) ) else skip; operation isSubsetSum(set : OclAny, n : OclAny, sum : OclAny) : OclAny pre: true post: true activity: var subset : Sequence := (Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, sum + 1-1)->select(i | true)->collect(i | (false))))) ; for i : Integer.subrange(0, n + 1-1) do ( subset[i+1]->first() := true) ; for i : Integer.subrange(1, sum + 1-1) do ( subset->first()[i+1] := false) ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, sum + 1-1) do ( if (j->compareTo(Set{}->union([i - 1+1]))) < 0 then ( subset[i+1][j+1] := subset[i - 1+1][j+1] ) else skip ; if (j->compareTo(Set{}->union([i - 1+1]))) >= 0 then ( subset[i+1][j+1] := (subset[i - 1+1][j+1] or subset[i - 1+1][j - Set{}->union([i - 1+1])+1]) ) else skip)) ; return subset[n+1][sum+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkPalindrome(str): n=len(str) count=0 for i in range(0,int(n/2)): if(str[i]!=str[n-i-1]): count=count+1 if(count<=1): return True else : return False str="abccaa" if(checkPalindrome(str)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclType["String"] := "abccaa" ; if (checkPalindrome(OclType["String"])) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation checkPalindrome(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var n : int := (OclType["String"])->size() ; var count : int := 0 ; for i : Integer.subrange(0, ("" + ((n / 2)))->toInteger()-1) do ( if (("" + ([i+1])) /= ("" + ([n - i - 1+1]))) then ( count := count + 1 ) else skip) ; if (count <= 1) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getHCF(x,y): minimum=min(x,y) if(x % minimum==0 and y % minimum==0): return minimum for i in range(minimum//2,1,-1): if(x % i==0 and y % i==0): return i return 1 x,y=16,32 print(getHCF(x,y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{x,y} := Sequence{16,32} ; execute (getHCF(x, y))->display(); operation getHCF(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var minimum : OclAny := Set{x, y}->min() ; if (x mod minimum = 0 & y mod minimum = 0) then ( return minimum ) else skip ; for i : Integer.subrange(1 + 1, minimum div 2)->reverse() do ( if (x mod i = 0 & y mod i = 0) then ( return i ) else skip) ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) if k % 2==1 : print(-1) else : for i in range(k): for j in range(k): a='' for l in range(k): a+='bw'[(i//2+j+l//2)% 2] print(a) if itoInteger() ; if k mod 2 = 1 then ( execute (-1)->display() ) else ( for i : Integer.subrange(0, k-1) do ( for j : Integer.subrange(0, k-1) do ( var a : String := '' ; for l : Integer.subrange(0, k-1) do ( a := a + 'bw'[(i div 2 + j + l div 2) mod 2+1]) ; execute (a)->display()) ; if (i->compareTo(k - 1)) < 0 then ( execute (->display() ) else skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class CodeforcesTask323ASolution : def __init__(self): self.result='' self.k=0 def read_input(self): self.k=int(input()) def process_task(self): if self.k % 2 : self.result="-1" elif self.k==2 : self.result="bb\nww\n\nbb\nww" else : level="b" cube=[[[None for y in range(self.k)]for x in range(self.k)]for z in range(self.k)] for z in range(self.k): level="w" if z % 2 else "b" for k in range(self.k//2): for x in range(2*(k+1)): cube[z][self.k//2-1-k][self.k//2-1-k+x]=level for x in range(2*(k+1)): cube[z][self.k//2+k][self.k//2-1-k+x]=level for y in range(2*(k+1)): cube[z][self.k//2-1-k+y][self.k//2-1-k]=level for y in range(2*(k+1)): cube[z][self.k//2-1-k+y][self.k//2+k]=level level="w" if level=="b" else "b" for layer in cube : for row in layer : print("".join(row)) print(" ") def get_result(self): return self.result if __name__=="__main__" : Solution=CodeforcesTask323ASolution() Solution.read_input() Solution.process_task() print(Solution.get_result()) ------------------------------------------------------------ OCL File: --------- class CodeforcesTask323ASolution { static operation newCodeforcesTask323ASolution() : CodeforcesTask323ASolution pre: true post: CodeforcesTask323ASolution->exists( _x | result = _x ); attribute result : String := ''; attribute k : int := 0; operation initialise() : CodeforcesTask323ASolution pre: true post: true activity: self.result := '' ; self.k := 0; return self; operation read_input() pre: true post: true activity: self.k := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation process_task() pre: true post: true activity: if self.k mod 2 then ( self.result := "-1" ) else (if self.k = 2 then ( self.result := "bb\nww\n\nbb\nww" ) else ( var level : String := "b" ; var cube : Sequence := Integer.subrange(0, self.k-1)->select(z | true)->collect(z | (Integer.subrange(0, self.k-1)->select(x | true)->collect(x | (Integer.subrange(0, self.k-1)->select(y | true)->collect(y | (null)))))) ; for z : Integer.subrange(0, self.k-1) do ( level := if z mod 2 then "w" else "b" endif ; for k : Integer.subrange(0, self.k div 2-1) do ( for x : Integer.subrange(0, 2 * (k + 1)-1) do ( cube[z+1][self.k div 2 - 1 - k+1][self.k div 2 - 1 - k + x+1] := level) ; for x : Integer.subrange(0, 2 * (k + 1)-1) do ( cube[z+1][self.k div 2 + k+1][self.k div 2 - 1 - k + x+1] := level) ; for y : Integer.subrange(0, 2 * (k + 1)-1) do ( cube[z+1][self.k div 2 - 1 - k + y+1][self.k div 2 - 1 - k+1] := level) ; for y : Integer.subrange(0, 2 * (k + 1)-1) do ( cube[z+1][self.k div 2 - 1 - k + y+1][self.k div 2 + k+1] := level) ; level := if level = "b" then "w" else "b" endif)) ; for layer : cube do ( for row : layer do ( execute (StringLib.sumStringsWithSeparator((row), ""))->display()) ; execute (" ")->display()) ) ) ; operation get_result() : OclAny pre: true post: true activity: return self.result; } class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var Solution : CodeforcesTask323ASolution := (CodeforcesTask323ASolution.newCodeforcesTask323ASolution()).initialise() ; Solution.read_input() ; Solution.process_task() ; execute (Solution.get_result())->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math readline=sys.stdin.readline k=int(readline()) if k % 2 : print(-1) else : for i in range(k): for j in range(k): s='' if(i//2+j)& 1 : s='wwbb'*(k//4) if k % 4!=0 : s+='ww' else : s='bbww'*(k//4) if k % 4!=0 : s+='bb' print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var k : int := ("" + ((readline())))->toInteger() ; if k mod 2 then ( execute (-1)->display() ) else ( for i : Integer.subrange(0, k-1) do ( for j : Integer.subrange(0, k-1) do ( var s : String := '' ; if MathLib.bitwiseAnd((i div 2 + j), 1) then ( s := StringLib.nCopies('wwbb', (k div 4)) ; if k mod 4 /= 0 then ( s := s + 'ww' ) else skip ) else ( s := StringLib.nCopies('bbww', (k div 4)) ; if k mod 4 /= 0 then ( s := s + 'bb' ) else skip ) ; execute (s)->display())) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : n=int(input()) if n % 2==1 : print(-1) exit() str1=''.join(['bb' if i % 2==1 else 'ww' for i in range(n//2)]) str2=''.join(['bb' if i % 2==0 else 'ww' for i in range(n//2)]) for i in range(n): str1,str2=str2,str1 for j in range(n//2): print(str1 if j % 2==0 else str2) print(str1 if j % 2==0 else str2) print('') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 1 then ( execute (-1)->display() ; exit() ) else skip ; var str1 : String := StringLib.sumStringsWithSeparator((Integer.subrange(0, n div 2-1)->select(i | true)->collect(i | (if i mod 2 = 1 then 'bb' else 'ww' endif))), '') ; var str2 : String := StringLib.sumStringsWithSeparator((Integer.subrange(0, n div 2-1)->select(i | true)->collect(i | (if i mod 2 = 0 then 'bb' else 'ww' endif))), '') ; for i : Integer.subrange(0, n-1) do ( Sequence{str1,str2} := Sequence{str2,str1} ; for j : Integer.subrange(0, n div 2-1) do ( execute (if j mod 2 = 0 then str1 else str2 endif)->display() ; execute (if j mod 2 = 0 then str1 else str2 endif)->display()) ; execute ('')->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if(n % 2==1): print(-1) else : for i in range(n): for j in range(n): s='' if(i//2+j)& 1 : s='wwbb'*(n//4) if n % 4!=0 : s+='ww' else : s='bbww'*(n//4) if n % 4!=0 : s+='bb' print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n mod 2 = 1) then ( execute (-1)->display() ) else ( for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( var s : String := '' ; if MathLib.bitwiseAnd((i div 2 + j), 1) then ( s := StringLib.nCopies('wwbb', (n div 4)) ; if n mod 4 /= 0 then ( s := s + 'ww' ) else skip ) else ( s := StringLib.nCopies('bbww', (n div 4)) ; if n mod 4 /= 0 then ( s := s + 'bb' ) else skip ) ; execute (s)->display())) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,q=map(int,input().split(' ')) uf=list(range(n)) import sys sys.setrecursionlimit(30000) def find_root(x): global uf if uf[x]==x : return x else : uf[x]=find_root(uf[x]) return uf[x] for _ in range(q): c,x,y=map(int,input().split(' ')) if c==0 : uf[find_root(x)]=find_root(y) else : print(int(find_root(x)==find_root(y))) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute uf : OclAny; operation initialise() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var uf : Sequence := (Integer.subrange(0, n-1)) ; skip ; sys.setrecursionlimit(30000) ; skip ; for _anon : Integer.subrange(0, q-1) do ( var c : OclAny := null; var y : OclAny := null; Sequence{c,x,y} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; if c = 0 then ( uf[find_root(x)+1] := find_root(y) ) else ( execute (("" + ((find_root(x) = find_root(y))))->toInteger())->display() )); operation find_root(x : OclAny) : OclAny pre: true post: true activity: skip ; if uf[x+1] = x then ( return x ) else ( uf[x+1] := find_root(uf[x+1]) ; return uf[x+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def nonsquare(n): return n+(int)(0.5+math.sqrt(n)) def printNonSquare(n): for i in range(1,n+1): print(nonsquare(i),end=" ") n=10 printNonSquare(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 10 ; printNonSquare(n); operation nonsquare(n : OclAny) : OclAny pre: true post: true activity: return n + (OclType["int"])(0.5 + (n)->sqrt()); operation printNonSquare(n : OclAny) pre: true post: true activity: for i : Integer.subrange(1, n + 1-1) do ( execute (nonsquare(i))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- str=input() l=[] while not "?" in str : templ=str.split(' ') a=int(templ[0]) b=int(templ[2]) ope=templ[1] if ope=="+" : str=a+b elif ope=="-" : str=a-b elif ope=="*" : str=a*b else : str=a//b l.append(str) str=input() for i in range(len(l)): print(l[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var OclType["String"] : String := (OclFile["System.in"]).readLine() ; var l : Sequence := Sequence{} ; while not((OclType["String"])->characters()->includes("?")) do ( var templ : String := ("" + (.split(' '))) ; var a : int := ("" + ((templ->first())))->toInteger() ; var b : int := ("" + ((templ[2+1])))->toInteger() ; var ope : OclAny := templ[1+1] ; if ope = "+" then ( OclType["String"] := a + b ) else (if ope = "-" then ( OclType["String"] := a - b ) else (if ope = "*" then ( OclType["String"] := a * b ) else ( OclType["String"] := a div b ) ) ) ; execute ((OclType["String"]) : l) ; OclType["String"] := (OclFile["System.in"]).readLine()) ; for i : Integer.subrange(0, (l)->size()-1) do ( execute (l[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys class UnionFind(object): __slots__=('size','tree_height_rank_list','ancestor_list') def __init__(self,size): self.size=int(size) self.tree_height_rank_list=[0]*self.size self.ancestor_list=[i for i in range(self.size)] def _find(self,x): if x!=self.ancestor_list[x]: self.ancestor_list[x]=self._find(self.ancestor_list[x]) return self.ancestor_list[x] def same(self,x,y): return self._find(x)==self._find(y) def link(self,x,y): if self.tree_height_rank_list[x]>self.tree_height_rank_list[y]: self.ancestor_list[y]=x else : self.ancestor_list[x]=y if self.tree_height_rank_list[x]==self.tree_height_rank_list[y]: self.tree_height_rank_list[y]+=1 def union(self,x,y): self.link(self._find(x),self._find(y)) def action(cmd): for _,each in enumerate(cmd): cmd,ele_1,ele_2=map(int,each) if cmd==0 : case.union(ele_1,ele_2) elif cmd==1 : if case.same(ele_1,ele_2): print('1') else : print('0') return case if __name__=='__main__' : _input=sys.stdin.readlines() ele_num,cmd_num=map(int,_input[0].split()) cmd_list=map(lambda x : x.split(),_input[1 :]) case=UnionFind(size=ele_num) ans=action(cmd_list) ------------------------------------------------------------ OCL File: --------- class UnionFind extends object { static operation newUnionFind() : UnionFind pre: true post: UnionFind->exists( _x | result = _x ); static attribute __slots__ : OclAny := Sequence{'size', 'tree_height_rank_list', 'ancestor_list'}; attribute size : int := ("" + ((size)))->toInteger(); attribute tree_height_rank_list : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, self.size); attribute ancestor_list : Sequence := Integer.subrange(0, self.size-1)->select(i | true)->collect(i | (i)); operation initialise(size : OclAny) : pre: true post: true activity: self.size := ("" + ((size)))->toInteger() ; self.tree_height_rank_list := MatrixLib.elementwiseMult(Sequence{ 0 }, self.size) ; self.ancestor_list := Integer.subrange(0, self.size-1)->select(i | true)->collect(i | (i)); return self; operation _find(x : OclAny) : OclAny pre: true post: true activity: if x /= self.ancestor_list[x+1] then ( self.ancestor_list[x+1] := self._find(self.ancestor_list[x+1]) ) else skip ; return self.ancestor_list[x+1]; operation same(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: return self._find(x) = self._find(y); operation link(x : OclAny,y : OclAny) pre: true post: true activity: if (self.tree_height_rank_list[x+1]->compareTo(self.tree_height_rank_list[y+1])) > 0 then ( self.ancestor_list[y+1] := x ) else ( self.ancestor_list[x+1] := y ; if self.tree_height_rank_list[x+1] = self.tree_height_rank_list[y+1] then ( self.tree_height_rank_list[y+1] := self.tree_height_rank_list[y+1] + 1 ) else skip ); operation union(x : OclAny,y : OclAny) pre: true post: true activity: self.link(self._find(x), self._find(y)); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( var _input : OclAny := (OclFile["System.in"]).readlines() ; var ele_num : OclAny := null; var cmd_num : OclAny := null; Sequence{ele_num,cmd_num} := (_input->first().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cmd_list : Sequence := (_input->tail())->collect( _x | (lambda x : OclAny in (x.split()))->apply(_x) ) ; var case : UnionFind := (UnionFind.newUnionFind()).initialise((argument (test (logical_test (comparison (expr (atom (name size)))))) = (test (logical_test (comparison (expr (atom (name ele_num)))))))) ; var ans : OclAny := action(cmd_list) ) else skip; operation action(cmd : OclAny) : OclAny pre: true post: true activity: for _tuple : Integer.subrange(1, (cmd)->size())->collect( _indx | Sequence{_indx-1, (cmd)->at(_indx)} ) do (var _indx : int := 1; var _anon : OclAny := _tuple->at(_indx); _indx := _indx + 1; var each : OclAny := _tuple->at(_indx); var elecmd : OclAny := null; var ele:= (each)->collect( _x | (OclType["int"])->apply(_x) ) : OclAny := null; Sequence{cmd,elecmd,ele:= (each)->collect( _x | (OclType["int"])->apply(_x) )} := (each)->collect( _x | (OclType["int"])->apply(_x) ) ; if cmd = 0 then ( case.union(elecase.union(elecase.union(elecase.union(elecase.union(elecase.union(elecase.union(ele var elecmd : OclAny := null; var ele:= (each)->collect( _x | (OclType["int"])->apply(_x) ) : OclAny := null; Sequence{cmd,elecmd,ele:= (each)->collect( _x | (OclType["int"])->apply(_x) )} := (each)->collect( _x | (OclType["int"])->apply(_x) ), ele_2), ele_2), ele_2), ele_2), ele_2), ele_2), ele_2) ) else (if cmd = 1 then ( if case.same(ele var elecmd : OclAny := null; var ele:= (each)->collect( _x | (OclType["int"])->apply(_x) ) : OclAny := null; Sequence{cmd,elecmd,ele:= (each)->collect( _x | (OclType["int"])->apply(_x) )} := (each)->collect( _x | (OclType["int"])->apply(_x) ), ele execute ('1')->display()) then ( execute ('1')->display() ) else ( execute ('0')->display() ) ) else skip)) ; return case; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class DisjointSets : def __init__(self,size): self.size=size self.ranks=[0]*self.size self.roots=[0]*self.size for x in range(self.size): self._make_set(x) def _make_set(self,x): self.roots[x]=x self.ranks[x]=0 def _link(self,x,y): if self.ranks[x]>self.ranks[y]: self.roots[y]=x else : self.roots[x]=y if self.ranks[x]==self.ranks[y]: self.ranks[y]+=1 def _find_set(self,x): if x!=self.roots[x]: self.roots[x]=self._find_set(self.roots[x]) return self.roots[x] def unite(self,x,y): self._link(self._find_set(x),self._find_set(y)) def same(self,x,y): return self._find_set(x)==self._find_set(y) if __name__=='__main__' : import sys n,q=map(int,input().split()) ds=DisjointSets(n) for line in sys.stdin.readlines(): query,x,y=map(int,line.strip().split()) if query==0 : ds.unite(x,y) elif query==1 : if ds.same(x,y): print(1) else : print(0) ------------------------------------------------------------ OCL File: --------- class DisjointSets { static operation newDisjointSets() : DisjointSets pre: true post: DisjointSets->exists( _x | result = _x ); attribute size : OclAny := size; attribute ranks : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, self.size); attribute roots : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, self.size); operation initialise(size : OclAny) : DisjointSets pre: true post: true activity: self.size := size ; self.ranks := MatrixLib.elementwiseMult(Sequence{ 0 }, self.size) ; self.roots := MatrixLib.elementwiseMult(Sequence{ 0 }, self.size) ; for x : Integer.subrange(0, self.size-1) do ( self._make_set(x)); return self; operation _make_set(x : OclAny) pre: true post: true activity: self.roots[x+1] := x ; self.ranks[x+1] := 0; operation _link(x : OclAny,y : OclAny) pre: true post: true activity: if (self.ranks[x+1]->compareTo(self.ranks[y+1])) > 0 then ( self.roots[y+1] := x ) else ( self.roots[x+1] := y ; if self.ranks[x+1] = self.ranks[y+1] then ( self.ranks[y+1] := self.ranks[y+1] + 1 ) else skip ); operation _find_set(x : OclAny) : OclAny pre: true post: true activity: if x /= self.roots[x+1] then ( self.roots[x+1] := self._find_set(self.roots[x+1]) ) else skip ; return self.roots[x+1]; operation unite(x : OclAny,y : OclAny) pre: true post: true activity: self._link(self._find_set(x), self._find_set(y)); operation same(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: return self._find_set(x) = self._find_set(y); } class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( skip ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ds : DisjointSets := (DisjointSets.newDisjointSets()).initialise(n) ; for line : (OclFile["System.in"]).readlines() do ( var query : OclAny := null; Sequence{query,x,y} := (line->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if query = 0 then ( ds.unite(x, y) ) else (if query = 1 then ( if ds.same(x, y) then ( execute (1)->display() ) else ( execute (0)->display() ) ) else skip)) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,q=[int(i)for i in input().split()] par=[i for i in range(n)] rank=[0 for i in range(n)] def find(x): if par[x]==x : return x else : par[x]=find(par[x]) return par[x] def unite(x,y): x=find(x) y=find(y) if x==y : return if rank[x]select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var par : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)) ; var rank : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; skip ; skip ; skip ; for i : Integer.subrange(0, q-1) do ( var com : OclAny := null; Sequence{com,x,y} := input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; if com = 0 then ( unite(x, y) ) else ( if same(x, y) then ( execute (1)->display() ) else ( execute (0)->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(): n,q=map(int,sys.stdin.readline().split()) uf=UnionFind(n) ans=[] for lp in range(q): c,x,y=map(int,sys.stdin.readline().split()) if c==0 : uf.unite(x,y) else : ans.append(1 if uf.is_same(x,y)else 0) print(*ans,sep='\n') class UnionFind : def __init__(self,n): self.ds=[i for i in range(n)] self.root=[i for i in range(n)] self.rank=[0]*n def find_root(self,x): if x!=self.root[x]: self.root[x]=self.find_root(self.root[x]) return self.root[x] def is_same(self,x,y): return self.find_root(x)==self.find_root(y) def unite(self,x,y): p=self.find_root(x) q=self.find_root(y) if p==q : return None if self.rank[p]{}'.format(name,val),file=sys.stderr) return None if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class UnionFind { static operation newUnionFind() : UnionFind pre: true post: UnionFind->exists( _x | result = _x ); attribute ds : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)); attribute root : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)); attribute rank : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); operation initialise(n : OclAny) : UnionFind pre: true post: true activity: self.ds := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)) ; self.root := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)) ; self.rank := MatrixLib.elementwiseMult(Sequence{ 0 }, n); return self; operation find_root(x : OclAny) : OclAny pre: true post: true activity: if x /= self.root[x+1] then ( self.root[x+1] := self.find_root(self.root[x+1]) ) else skip ; return self.root[x+1]; operation is_same(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: return self.find_root(x) = self.find_root(y); operation unite(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: var p : OclAny := self.find_root(x) ; var q : OclAny := self.find_root(y) ; if p = q then ( return null ) else skip ; if (self.rank[p+1]->compareTo(self.rank[q+1])) < 0 then ( self.root[p+1] := q ) else (if (self.rank[q+1]->compareTo(self.rank[p+1])) < 0 then ( self.root[q+1] := p ) else ( self.root[q+1] := p ; self.rank[p+1] := self.rank[p+1] + 1 ) ) ; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var uf : OclAny := UnionFind(n) ; var ans : Sequence := Sequence{} ; for lp : Integer.subrange(0, q-1) do ( var c : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{c,x,y} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if c = 0 then ( uf.unite(x, y) ) else ( execute ((if uf.is_same(x, y) then 1 else 0 endif) : ans) )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); operation debug(x : OclAny, table : OclAny) : OclAny pre: true post: true activity: for _tuple : table->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var name : OclAny := _tuple->at(_indx); _indx := _indx + 1; var val : OclAny := _tuple->at(_indx); if x <>= val then ( execute (StringLib.interpolateStrings('DEBUG:{}->{}', Sequence{name, val}))->display() ; return null ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() ans=0 for i in range(len(s)-1): if s[i]=='V' and s[i+1]=='K' : ans+=1 if s[: 2]=='KK' or s[-2 :]=='VV' or s.find('VVV')!=-1 or s.find('KKK')!=-1 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; for i : Integer.subrange(0, (s)->size() - 1-1) do ( if s[i+1] = 'V' & s[i + 1+1] = 'K' then ( ans := ans + 1 ) else skip) ; if s.subrange(1,2) = 'KK' or s.subrange(-2+1) = 'VV' or s->indexOf('VVV') - 1 /= -1 or s->indexOf('KKK') - 1 /= -1 then ( ans := ans + 1 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() def swa(r): if r=="V" : return "K" else : return "V" ans=0 ans=max(ans,x.count("VK")) for j in range(len(x)-1): z=x[: j]+swa(x[j])+x[j+1 :] ans=max(ans,z.count("VK")) z=x[: len(x)-1]+swa(x[-1]) ans=max(ans,z.count("VK")) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := (OclFile["System.in"]).readLine() ; skip ; var ans : int := 0 ; ans := Set{ans, x->count("VK")}->max() ; for j : Integer.subrange(0, (x)->size() - 1-1) do ( var z : OclAny := x.subrange(1,j) + swa(x[j+1]) + x.subrange(j + 1+1) ; ans := Set{ans, z->count("VK")}->max()) ; z := x.subrange(1,(x)->size() - 1) + swa(x->last()) ; ans := Set{ans, z->count("VK")}->max() ; execute (ans)->display(); operation swa(r : OclAny) : OclAny pre: true post: true activity: if r = "V" then ( return "K" ) else ( return "V" ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() s='K'+s+'V' c=s.count('VK') if('VVV' in s or 'KKK' in s): c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; s := 'K' + s + 'V' ; var c : int := s->count('VK') ; if ((s)->characters()->includes('VVV') or (s)->characters()->includes('KKK')) then ( c := c + 1 ) else skip ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline s=input()[:-1] s=s.replace('VK','*') d=s.count('*') c=0 if 'VV' in s or 'KK' in s : c=1 print(d+c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var s : OclAny := input()->front() ; s := s.replace('VK', '*') ; var d : int := s->count('*') ; var c : int := 0 ; if (s)->includes('VV') or (s)->includes('KK') then ( c := 1 ) else skip ; execute (d + c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s1=input() s=list(s1) res=0 for j in range(len(s1)): a=s[j] res1=0 s[j]='V' for i in range(len(s1)-1): if(s[i]=='V' and s[i+1]=='K'): res1+=1 res=max(res,res1) res1=0 s[j]='K' for i in range(len(s1)-1): if(s[i]=='V' and s[i+1]=='K'): res1+=1 res=max(res,res1) s[j]=a print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s1 : String := (OclFile["System.in"]).readLine() ; var s : Sequence := (s1)->characters() ; var res : int := 0 ; for j : Integer.subrange(0, (s1)->size()-1) do ( var a : OclAny := s[j+1] ; var res1 : int := 0 ; s[j+1] := 'V' ; for i : Integer.subrange(0, (s1)->size() - 1-1) do ( if (s[i+1] = 'V' & s[i + 1+1] = 'K') then ( res1 := res1 + 1 ) else skip) ; res := Set{res, res1}->max() ; res1 := 0 ; s[j+1] := 'K' ; for i : Integer.subrange(0, (s1)->size() - 1-1) do ( if (s[i+1] = 'V' & s[i + 1+1] = 'K') then ( res1 := res1 + 1 ) else skip) ; res := Set{res, res1}->max() ; s[j+1] := a) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMinZero(p): first=1 second=1 number=2 next=1 while(next): next=(first+second)% p first=second second=next number=number+1 return number if __name__=='__main__' : p=7 print("Minimal zero is:",findMinZero(p)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( p := 7 ; execute ("Minimal zero is:")->display() ) else skip; operation findMinZero(p : OclAny) : OclAny pre: true post: true activity: var first : int := 1 ; var second : int := 1 ; var number : int := 2 ; var next : int := 1 ; while (next) do ( next := (first + second) mod p ; first := second ; second := next ; number := number + 1) ; return number; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=list(map(int,input().split())) a=l[0] c=l[1] total=l[2] total=[i for i in range(1,total+1)] k=0 ; for i in total : if i % a==0 and i % c==0 : k+=1 print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := l->first() ; var c : OclAny := l[1+1] ; var total : OclAny := l[2+1] ; total := Integer.subrange(1, total + 1-1)->select(i | true)->collect(i | (i)) ; var k : int := 0; ; for i : total do ( if i mod a = 0 & i mod c = 0 then ( k := k + 1 ) else skip) ; execute (k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) ls=list(map(int,input().split())) d,lpos,ans=1,n-ls[0]+1,[n-ls[0]+1] lposs=[lpos] for j in range(1,m): if ls[j]+d>n : print(-1) break lpos=min(lpos,n-(d+ls[j])+1) lposs.append(lpos) ans.append(n-(d+ls[j])+1) d+=1 else : if lpos==1 : print(' '.join(map(str,ans))) else : x,y=1,1 for k in range(m-1,-1,-1): ans[k]=x x=x+ls[k] if x>=lposs[k-1]: break print(' '.join(map(str,ans))if sum(ls)>=n else-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ls : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := null; var lpos : OclAny := null; var ans : OclAny := null; Sequence{d,lpos,ans} := Sequence{1,n - ls->first() + 1,Sequence{ n - ls->first() + 1 }} ; var lposs : Sequence := Sequence{ lpos } ; (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name m)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name ls)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))) + (expr (atom (name d))))) > (comparison (expr (atom (name n))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name lpos)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name lpos))))))) , (argument (test (logical_test (comparison (expr (expr (expr (atom (name n))) - (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name d))) + (expr (atom (name ls)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) )))) + (expr (atom (number (integer 1)))))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name lposs)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name lpos)))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name n))) - (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name d))) + (expr (atom (name ls)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) )))) + (expr (atom (number (integer 1)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name lpos)))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ' ') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name x)))))) , (test (logical_test (comparison (expr (atom (name y))))))) (assign_part = (testlist_star_expr (test (logical_test (comparison (expr (atom (number (integer 1))))))) , (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name k)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name m))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom - (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (name ls)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ]))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name x)))) >= (comparison (expr (atom (name lposs)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name k))) - (expr (atom (number (integer 1)))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt break))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ' ') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) )))))) if (logical_test (comparison (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ls)))))))) ))))) >= (comparison (expr (atom (name n)))))) else (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ))))))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INFINITY_=9999999 def sqrtByLongDivision(n): i=0 udigit,j=0,0 cur_divisor=0 quotient_units_digit=0 cur_quotient=0 cur_dividend=0 cur_remainder=0 a=[0]*10 while(n>0): a[i]=n % 100 n=n//100 i+=1 i-=1 for j in range(i,-1,-1): cur_remainder=INFINITY_ cur_dividend=cur_dividend*100+a[j] for udigit in range(10): if(cur_remainder>=cur_dividend-((cur_divisor*10+udigit)*udigit)and cur_dividend-((cur_divisor*10+udigit)*udigit)>=0): cur_remainder=cur_dividend-((cur_divisor*10+udigit)*udigit) quotient_units_digit=udigit cur_quotient=cur_quotient*10+quotient_units_digit cur_divisor=cur_quotient*2 cur_dividend=cur_remainder return cur_quotient x=1225 print(sqrtByLongDivision(x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INFINITY_ : int := 9999999 ; skip ; var x : int := 1225 ; execute (sqrtByLongDivision(x))->display(); operation sqrtByLongDivision(n : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; var udigit : OclAny := null; var j : OclAny := null; Sequence{udigit,j} := Sequence{0,0} ; var cur_divisor : int := 0 ; var quotient_units_digit : int := 0 ; var cur_quotient : int := 0 ; var cur_dividend : int := 0 ; var cur_remainder : int := 0 ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; while (n > 0) do ( a[i+1] := n mod 100 ; n := n div 100 ; i := i + 1) ; i := i - 1 ; for j : Integer.subrange(-1 + 1, i)->reverse() do ( cur_remainder := INFINITY_ ; cur_dividend := cur_dividend * 100 + a[j+1] ; for udigit : Integer.subrange(0, 10-1) do ( if ((cur_remainder->compareTo(cur_dividend - ((cur_divisor * 10 + udigit) * udigit))) >= 0 & cur_dividend - ((cur_divisor * 10 + udigit) * udigit) >= 0) then ( cur_remainder := cur_dividend - ((cur_divisor * 10 + udigit) * udigit) ; quotient_units_digit := udigit ) else skip) ; cur_quotient := cur_quotient * 10 + quotient_units_digit ; cur_divisor := cur_quotient * 2 ; cur_dividend := cur_remainder) ; return cur_quotient; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(s): for i in range(len(s)-1): if(abs(ord(s[i])-ord(s[i+1]))==1): return False return True def Rearrange(Str): odd,even="","" for i in range(len(Str)): if(ord(Str[i])% 2==0): even+=Str[i] else : odd+=Str[i] odd=sorted(odd) even=sorted(even) if(check(odd+even)): print("".join(odd+even)) elif(check(even+odd)): print("".join(even+odd)) else : print(-1) Str="aabcd" Rearrange(Str) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Str := "aabcd" ; Rearrange(Str); operation check(s : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, (s)->size() - 1-1) do ( if (((s[i+1])->char2byte() - (s[i + 1+1])->char2byte())->abs() = 1) then ( return false ) else skip) ; return true; operation Rearrange(Str : OclAny) pre: true post: true activity: var odd : OclAny := null; var even : OclAny := null; Sequence{odd,even} := Sequence{"",""} ; for i : Integer.subrange(0, (Str)->size()-1) do ( if ((Str[i+1])->char2byte() mod 2 = 0) then ( even := even + Str[i+1] ) else ( odd := odd + Str[i+1] )) ; var odd : Sequence := odd->sort() ; var even : Sequence := even->sort() ; if (check(odd->union(even))) then ( execute (StringLib.sumStringsWithSeparator((odd->union(even)), ""))->display() ) else (if (check(even->union(odd))) then ( execute (StringLib.sumStringsWithSeparator((even->union(odd)), ""))->display() ) else ( execute (-1)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) for j in range(len(a)): if a[j]toInteger()-1) do ( solve()); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, (a)->size()-1) do ( if (a[j+1]->compareTo(b[j+1])) < 0 then ( var t : double := b[j+1] - a[j+1] ; for k : Integer.subrange(j, n-1) do ( if (a[k+1]->compareTo(b[k+1])) < 0 then ( a[k+1] := a[k+1] + t ) else ( break )) ; break ) else skip) ; if a = b then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) t,=R() for _ in[0]*t : R(); a=[1]; p='' for x,y in zip(R(),R()): z=y-x ; a+=([],[z])[0!=z!=p]; p=z print('NYOE S'[len(a)-3<0collect( _x | (OclType["int"])->apply(_x) )) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := R->apply() ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, t) do ( R(); var a : Sequence := Sequence{ 1 }; var p : String := '' ; for _tuple : Integer.subrange(1, R->apply()->size())->collect( _indx | Sequence{R->apply()->at(_indx), R->apply()->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); var z : double := y - x; a := a + Sequence{Sequence{}, Sequence{ z }}->select(0 /= z & (z != p)); p := z) ; execute ('NYOE S'(subscript (test (logical_test (comparison (comparison (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))) - (expr (atom (number (integer 3)))))) < (comparison (expr (atom (number (integer 0)))))) < (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) d=[] c=0 for i in range(n): if b[i]-a[i]>=0 : d.append(b[i]-a[i]) else : d=[] break if d and b[-1]-a[-1]>=0 : d.append(b[-1]-a[-1]) d.append(0) d=[0]+d for i in range(len(d)-1): if d[i]!=d[i+1]: c+=1 else : d=[] if d and c<=2 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : Sequence := Sequence{} ; var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( if b[i+1] - a[i+1] >= 0 then ( execute ((b[i+1] - a[i+1]) : d) ) else ( d := Sequence{} ; break )) ; if d & b->last() - a->last() >= 0 then ( execute ((b->last() - a->last()) : d) ; execute ((0) : d) ; d := Sequence{ 0 }->union(d) ; for i : Integer.subrange(0, (d)->size() - 1-1) do ( if d[i+1] /= d[i + 1+1] then ( c := c + 1 ) else skip) ) else ( d := Sequence{} ) ; if d & c <= 2 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for pratyush in range(int(input())): n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) d=[int(b[i])-int(a[i])for i in range(n)] c,r,f=-1,1,0 for i in d : if not r : break if i>0 : if f!=0 : r=0 if c==-1 : c=i if c!=i : r=0 elif i<0 : r=0 elif i==0 and c!=-1 : c=-1 f+=1 if r : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for pratyush : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + ((b[i+1])))->toInteger() - ("" + ((a[i+1])))->toInteger())) ; var c : OclAny := null; var r : OclAny := null; var f : OclAny := null; Sequence{c,r,f} := Sequence{-1,1,0} ; for i : d do ( if not(r) then ( break ) else skip ; if i > 0 then ( if f /= 0 then ( var r : int := 0 ) else skip ; if c = -1 then ( var c : OclAny := i ) else skip ; if c /= i then ( r := 0 ) else skip ) else (if i < 0 then ( r := 0 ) else (if i = 0 & c /= -1 then ( c := -1 ; f := f + 1 ) else skip ) ) ) ; if r then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout from math import* import math,random,operator from itertools import product,permutations,combinations from collections import deque,defaultdict,Counter def hi(): n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) k=0 l=n r=-1 for i in range(n): if b[i]>a[i]: k=max(k,b[i]-a[i]) l=min(l,i) r=max(r,i) for i in range(l,r+1): a[i]+=k ok=1 for i in range(n): ok &=(int(a[i]==b[i])) print("YES" if ok else "NO") if __name__=="__main__" : for _ in range(int(input())): hi() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( hi()) ) else skip; operation hi() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k : int := 0 ; var l : int := n ; var r : int := -1 ; for i : Integer.subrange(0, n-1) do ( if (b[i+1]->compareTo(a[i+1])) > 0 then ( k := Set{k, b[i+1] - a[i+1]}->max() ; l := Set{l, i}->min() ; r := Set{r, i}->max() ) else skip) ; for i : Integer.subrange(l, r + 1-1) do ( a[i+1] := a[i+1] + k) ; var ok : int := 1 ; for i : Integer.subrange(0, n-1) do ( ok := ok & (("" + ((a[i+1] = b[i+1])))->toInteger())) ; execute (if ok then "YES" else "NO" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def palindrome(arr,n): flag=0 ; i=0 ; while(i<=n//2 and n!=0): if(arr[i]!=arr[n-i-1]): flag=1 ; break ; i+=1 ; if(flag==1): print("Not Palindrome"); else : print("Palindrome"); arr=[1,2,3,2,1]; n=len(arr); palindrome(arr,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 1 })))); ; n := (arr)->size(); ; palindrome(arr, n);; operation palindrome(arr : OclAny, n : OclAny) pre: true post: true activity: var flag : int := 0; ; var i : int := 0; ; while ((i->compareTo(n div 2)) <= 0 & n /= 0) do ( if (arr[i+1] /= arr[n - i - 1+1]) then ( flag := 1; ; break; ) else skip ; i := i + 1;) ; if (flag = 1) then ( execute ("Not Palindrome")->display(); ) else ( execute ("Palindrome")->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def search(arr,l,h,key): if(l>h): return-1 ; mid=(l+h)//2 ; if(arr[mid]==key): return mid ; if((arr[l]==arr[mid])and(arr[h]==arr[mid])): l+=1 ; h-=1 ; if(arr[l]<=arr[mid]): if(key>=arr[l]and key<=arr[mid]): return search(arr,l,mid-1,key); return search(arr,mid+1,h,key); if(key>=arr[mid]and key<=arr[h]): return search(arr,mid+1,h,key); return search(arr,l,mid-1,key); if __name__=="__main__" : arr=[3,3,1,2,3,3]; n=len(arr); key=3 ; print(search(arr,0,n-1,key)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{3}->union(Sequence{3}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 3 }))))); ; var n : int := (arr)->size(); ; key := 3; ; execute (search(arr, 0, n - 1, key))->display(); ) else skip; operation search(arr : OclAny, l : OclAny, h : OclAny, key : OclAny) pre: true post: true activity: if ((l->compareTo(h)) > 0) then ( return -1; ) else skip ; var mid : int := (l + h) div 2; ; if (arr[mid+1] = key) then ( return mid; ) else skip ; if ((arr[l+1] = arr[mid+1]) & (arr[h+1] = arr[mid+1])) then ( l := l + 1; ; h := h - 1; ) else skip ; if ((arr[l+1]->compareTo(arr[mid+1])) <= 0) then ( if ((key->compareTo(arr[l+1])) >= 0 & (key->compareTo(arr[mid+1])) <= 0) then ( return search(arr, l, mid - 1, key); ) else skip ; return search(arr, mid + 1, h, key); ) else skip ; if ((key->compareTo(arr[mid+1])) >= 0 & (key->compareTo(arr[h+1])) <= 0) then ( return search(arr, mid + 1, h, key); ) else skip ; return search(arr, l, mid - 1, key);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nmult(n,p): i=0 a=list() while True : i+=1 if((n*i)<=p): a.append(n*i) else : break return a def common(lst1,lst2): return list(set(lst1)& set(lst2)) n,m,z=[int(n)for n in input().split()] print(len(common(nmult(n,z),nmult(m,z)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var m : OclAny := null; var z : OclAny := null; Sequence{n,m,z} := input().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; execute ((common(nmult(n, z), nmult(m, z)))->size())->display(); operation nmult(n : OclAny, p : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; var a : Sequence := () ; while true do ( i := i + 1 ; if (((n * i)->compareTo(p)) <= 0) then ( execute ((n * i) : a) ) else ( break )) ; return a; operation common(lst1 : OclAny, lst2 : OclAny) : OclAny pre: true post: true activity: return (MathLib.bitwiseAnd(Set{}->union((lst1)), Set{}->union((lst2)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re while True : n,m=map(int,input().split()) if(n | m)==0 : break rule,ans=[],[] for i in range(n): g,s,d=input().split() rule.append((g[0]=='p',s.replace("?","[0-9]"),d.replace("?","[0-9]"))) for i in range(m): s,d,m=input().split() for G,S,D in rule[: :-1]: if re.match(S,s)and re.match(D,d): if G : ans.append((s,d,m)) break print(len(ans)) for a in ans : print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (MathLib.bitwiseOr(n, m)) = 0 then ( break ) else skip ; var rule : OclAny := null; var ans : OclAny := null; Sequence{rule,ans} := Sequence{Sequence{},Sequence{}} ; for i : Integer.subrange(0, n-1) do ( var g : OclAny := null; var s : OclAny := null; var d : OclAny := null; Sequence{g,s,d} := input().split() ; execute ((Sequence{g->first() = 'p', s.replace("?", "[0-9]"), d.replace("?", "[0-9]")}) : rule)) ; for i : Integer.subrange(0, m-1) do ( var s : OclAny := null; var d : OclAny := null; var m : OclAny := null; Sequence{s,d,m} := input().split() ; for _tuple : rule(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do (var _indx : int := 1; var G : OclAny := _tuple->at(_indx); _indx := _indx + 1; var S : OclAny := _tuple->at(_indx); _indx := _indx + 1; var D : OclAny := _tuple->at(_indx); if (s)->firstMatch("^" + S + ".*") & (d)->firstMatch("^" + D + ".*") then ( if G then ( execute ((Sequence{s, d, m}) : ans) ) else skip ; break ) else skip)) ; execute ((ans)->size())->display() ; for a : ans do ( execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) l=list(map(int,input().split())) for i in range(m): if l[i]>n-i : print(-1) exit(0) k=sum(l) p=[0 for i in range(m)] if kcollect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, m-1) do ( if (l[i+1]->compareTo(n - i)) > 0 then ( execute (-1)->display() ; exit(0) ) else skip) ; var k : OclAny := (l)->sum() ; var p : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (0)) ; if (k->compareTo(n)) < 0 then ( execute (-1)->display() ; exit(0) ) else skip ; for i : Integer.subrange(0, m-1) do ( p[i+1] := Set{i, n - k}->max() + 1 ; k := k - l[i+1]) ; execute ((argument * (test (logical_test (comparison (expr (atom (name p))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re while True : n,m=map(int,input().split()) if(n | m)==0 : break rule,ans=[],[] for i in range(n): g,s,d=input().split() rule.append((g[0]=='p',re.compile(s.replace("?","[0-9]")),re.compile(d.replace("?","[0-9]")))) for i in range(m): s,d,m=input().split() for G,S,D in rule[: :-1]: if re.match(S,s)and re.match(D,d): if G : ans.append((s,d,m)) break print(len(ans)) for a in ans : print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (MathLib.bitwiseOr(n, m)) = 0 then ( break ) else skip ; var rule : OclAny := null; var ans : OclAny := null; Sequence{rule,ans} := Sequence{Sequence{},Sequence{}} ; for i : Integer.subrange(0, n-1) do ( var g : OclAny := null; var s : OclAny := null; var d : OclAny := null; Sequence{g,s,d} := input().split() ; execute ((Sequence{g->first() = 'p', OclRegex.compile(s.replace("?", "[0-9]")), OclRegex.compile(d.replace("?", "[0-9]"))}) : rule)) ; for i : Integer.subrange(0, m-1) do ( var s : OclAny := null; var d : OclAny := null; var m : OclAny := null; Sequence{s,d,m} := input().split() ; for _tuple : rule(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do (var _indx : int := 1; var G : OclAny := _tuple->at(_indx); _indx := _indx + 1; var S : OclAny := _tuple->at(_indx); _indx := _indx + 1; var D : OclAny := _tuple->at(_indx); if (s)->firstMatch("^" + S + ".*") & (d)->firstMatch("^" + D + ".*") then ( if G then ( execute ((Sequence{s, d, m}) : ans) ) else skip ; break ) else skip)) ; execute ((ans)->size())->display() ; for a : ans do ( execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re while True : n,m=map(int,input().split()) if(n | m)==0 : break rule,ans=[],[] for i in range(n): g,s,d=input().split() rule.append((g[0]=='p',re.compile((s+d).replace("?","[0-9]")))) for i in range(m): s,d,m=input().split() sd=s+d for G,SD in rule[: :-1]: if re.match(SD,sd): if G : ans.append((s,d,m)) break print(len(ans)) for a in ans : print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (MathLib.bitwiseOr(n, m)) = 0 then ( break ) else skip ; var rule : OclAny := null; var ans : OclAny := null; Sequence{rule,ans} := Sequence{Sequence{},Sequence{}} ; for i : Integer.subrange(0, n-1) do ( var g : OclAny := null; var s : OclAny := null; var d : OclAny := null; Sequence{g,s,d} := input().split() ; execute ((Sequence{g->first() = 'p', OclRegex.compile((s + d).replace("?", "[0-9]"))}) : rule)) ; for i : Integer.subrange(0, m-1) do ( var s : OclAny := null; var d : OclAny := null; var m : OclAny := null; Sequence{s,d,m} := input().split() ; var sd : OclAny := s + d ; for _tuple : rule(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do (var _indx : int := 1; var G : OclAny := _tuple->at(_indx); _indx := _indx + 1; var SD : OclAny := _tuple->at(_indx); if (sd)->firstMatch("^" + SD + ".*") then ( if G then ( execute ((Sequence{s, d, m}) : ans) ) else skip ; break ) else skip)) ; execute ((ans)->size())->display() ; for a : ans do ( execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re while True : n,m=map(int,input().split()) if(n | m)==0 : break rule,ans=[],[] for i in range(n): g,s,d=input().split() rule.append((g[0]=='p',re.compile((s+d).replace("?","\d")))) for i in range(m): s,d,m=input().split() sd=s+d for G,SD in rule[: :-1]: if re.match(SD,sd): if G : ans.append((s,d,m)) break print(len(ans)) for a in ans : print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (MathLib.bitwiseOr(n, m)) = 0 then ( break ) else skip ; var rule : OclAny := null; var ans : OclAny := null; Sequence{rule,ans} := Sequence{Sequence{},Sequence{}} ; for i : Integer.subrange(0, n-1) do ( var g : OclAny := null; var s : OclAny := null; var d : OclAny := null; Sequence{g,s,d} := input().split() ; execute ((Sequence{g->first() = 'p', OclRegex.compile((s + d).replace("?", "\d"))}) : rule)) ; for i : Integer.subrange(0, m-1) do ( var s : OclAny := null; var d : OclAny := null; var m : OclAny := null; Sequence{s,d,m} := input().split() ; var sd : OclAny := s + d ; for _tuple : rule(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do (var _indx : int := 1; var G : OclAny := _tuple->at(_indx); _indx := _indx + 1; var SD : OclAny := _tuple->at(_indx); if (sd)->firstMatch("^" + SD + ".*") then ( if G then ( execute ((Sequence{s, d, m}) : ans) ) else skip ; break ) else skip)) ; execute ((ans)->size())->display() ; for a : ans do ( execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def SumDivisible(n,k): sum=0 position=1 while(n>0): if(position % 2==1): sum+=n % 10 n=n//10 position+=1 if(sum % k==0): return True return False if __name__=="__main__" : n=592452 k=3 if(SumDivisible(n,k)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 592452 ; k := 3 ; if (SumDivisible(n, k)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; operation SumDivisible(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; var position : int := 1 ; while (n > 0) do ( if (position mod 2 = 1) then ( sum := sum + n mod 10 ) else skip ; n := n div 10 ; position := position + 1) ; if (sum mod k = 0) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getRemainder(num,divisor): while(num>=divisor): num-=divisor ; return num ; if __name__=='__main__' : num=100 ; divisor=7 ; print(getRemainder(num,divisor)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( num := 100; divisor := 7; ; execute (getRemainder(num, divisor))->display(); ) else skip; operation getRemainder(num : OclAny, divisor : OclAny) pre: true post: true activity: while ((num->compareTo(divisor)) >= 0) do ( num := num - divisor;) ; return num;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,s,t=map(int,input().split()) p=[[x,False]for x in map(int,input().split())] ans=0 while True : if s==t : print(ans); break if p[s-1][1]: print(-1); break else : p[s-1][1]=True s=p[s-1][0] ans+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var s : OclAny := null; var t : OclAny := null; Sequence{n,s,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->select(x | true)->collect(x | (Sequence{x}->union(Sequence{ false }))) ; var ans : int := 0 ; while true do ( if s = t then ( execute (ans)->display(); break ) else skip ; if p[s - 1+1][1+1] then ( execute (-1)->display(); break ) else ( p[s - 1+1][1+1] := true ; var s : OclAny := p[s - 1+1]->first() ) ; ans := ans + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque,defaultdict import sys def inp(): return int(sys.stdin.readline()) def mpp(): return map(int,sys.stdin.readline().rstrip().split()) def lis(): return list(map(int,sys.stdin.readline().rstrip().split())) def sol(p,s,t): visited=dict() visited[s]=1 q=deque() q.append((s,0)) count=0 while q : temp,cnt=q.popleft() if temp==t : return cnt if visited.get(p[temp-1]): return-1 q.append((p[temp-1],cnt+1)) return-1 def main(): n,s,t=mpp() arr=lis() graph=defaultdict(list) sys.stdout.write(str(sol(arr,s,t))) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation mpp() : OclAny pre: true post: true activity: return (sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ); operation lis() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )); operation sol(p : OclAny, s : OclAny, t : OclAny) : OclAny pre: true post: true activity: var visited : Map := (arguments ( )) ; visited[s+1] := 1 ; var q : Sequence := () ; execute ((Sequence{s, 0}) : q) ; var count : int := 0 ; while q do ( var temp : OclAny := null; var cnt : OclAny := null; Sequence{temp,cnt} := q->first() ; q := q->tail() ; if temp = t then ( return cnt ) else skip ; if visited.get(p[temp - 1+1]) then ( return -1 ) else skip ; execute ((Sequence{p[temp - 1+1], cnt + 1}) : q)) ; return -1; operation main() pre: true post: true activity: var n : OclAny := null; Sequence{n,s,t} := mpp() ; var arr : OclAny := lis() ; var graph : OclAny := defaultdict(OclType["Sequence"]) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sol)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr))))))) , (argument (test (logical_test (comparison (expr (atom (name s))))))) , (argument (test (logical_test (comparison (expr (atom (name t)))))))) ))))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,s,t=map(int,input().split()) w=[i-1 for i in map(int,input().split())] c=0 s-=1 t-=1 while c<=n : if s==t : break s=w[s] c+=1 if c==n+1 : print(-1) else : print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var s : OclAny := null; var t : OclAny := null; Sequence{n,s,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->select(i | true)->collect(i | (i - 1)) ; var c : int := 0 ; s := s - 1 ; t := t - 1 ; while (c->compareTo(n)) <= 0 do ( if s = t then ( break ) else skip ; var s : OclAny := w[s+1] ; c := c + 1) ; if c = n + 1 then ( execute (-1)->display() ) else ( execute (c)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt sz=int(1e5); isPrime=[True]*(sz+1); def sieve(): isPrime[0]=isPrime[1]=False ; for i in range(2,int(sqrt(sz))+1): if(isPrime[i]): for j in range(i*i,sz,i): isPrime[j]=False ; def minDifference(L,R): fst=0 ; for i in range(L,R+1): if(isPrime[i]): fst=i ; break ; snd=0 ; for i in range(fst+1,R+1): if(isPrime[i]): snd=i ; break ; if(snd==0): return-1 ; diff=snd-fst ; left=snd+1 ; right=R ; for i in range(left,right+1): if(isPrime[i]): if(i-snd<=diff): fst=snd ; snd=i ; diff=snd-fst ; return diff ; if __name__=="__main__" : sieve(); L=21 ; R=50 ; print(minDifference(L,R)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var sz : int := ("" + ((("1e5")->toReal())))->toInteger(); ; var isPrime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (sz + 1)); ; skip ; skip ; if __name__ = "__main__" then ( sieve(); ; L := 21; R := 50; ; execute (minDifference(L, R))->display(); ) else skip; operation sieve() pre: true post: true activity: isPrime->first() := false; var isPrime[1+1] : boolean := false; ; for i : Integer.subrange(2, ("" + ((sqrt(sz))))->toInteger() + 1-1) do ( if (isPrime[i+1]) then ( for j : Integer.subrange(i * i, sz-1)->select( $x | ($x - i * i) mod i = 0 ) do ( isPrime[j+1] := false;) ) else skip); operation minDifference(L : OclAny, R : OclAny) pre: true post: true activity: var fst : int := 0; ; for i : Integer.subrange(L, R + 1-1) do ( if (isPrime[i+1]) then ( fst := i; ; break; ) else skip) ; var snd : int := 0; ; for i : Integer.subrange(fst + 1, R + 1-1) do ( if (isPrime[i+1]) then ( snd := i; ; break; ) else skip) ; if (snd = 0) then ( return -1; ) else skip ; var diff : double := snd - fst; ; var left : int := snd + 1; ; var right : OclAny := R; ; for i : Integer.subrange(left, right + 1-1) do ( if (isPrime[i+1]) then ( if ((i - snd->compareTo(diff)) <= 0) then ( fst := snd; ; snd := i; ; diff := snd - fst; ) else skip ) else skip) ; return diff;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys _allinput=[] for inp in sys.stdin : _allinput+=inp.strip().split(" ") def _input(): for put in _allinput : yield put _obj=_input(); def __input(): return _obj.__next__() def nextInt(): return int(__input()) def check(lst,L): tot=1 curSum=0 for i in lst : if curSum+i<=L : curSum+=i else : curSum=i tot+=1 return tot def solve(lst,m): l=max(lst) r=1000000*m ; while l!=r : mid=int((l+r)/2); if check(lst,mid)<=m : r=mid else : l=mid+1 return l try : while True : m,n=nextInt(),nextInt() if m>0 or n>0 : lst=[nextInt()for i in range(0,n)] print(solve(lst,m)) else : break except : ------------------------------------------------------------ OCL File: --------- class FromPython { suite`nestedAttributeDefinitions operation initialise() pre: true post: true activity: skip ; var _allinput : Sequence := Sequence{} ; for inp : OclFile["System.in"] do ( _allinput := _allinput + inp->trim().split(" ")) ; skip ; var _obj : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self._input(_i)); ; skip ; skip ; skip ; skip ; try ( while true do ( var n : OclAny := null; Sequence{m,n} := Sequence{nextInt(),nextInt()} ; if m > 0 or n > 0 then ( lst := Integer.subrange(0, n-1)->select(i | true)->collect(i | (nextInt())) ; execute (solve(lst, m))->display() ) else ( break ))) catch (_e : OclException) do (suite) ; operation _input(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; for put : _allinput do ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return put); operation __input() : OclAny pre: true post: true activity: return _obj.__next__(); operation nextInt() : OclAny pre: true post: true activity: return ("" + ((__input())))->toInteger(); operation check(lst : OclAny, L : OclAny) : OclAny pre: true post: true activity: var tot : int := 1 ; var curSum : int := 0 ; for i : lst do ( if (curSum + i->compareTo(L)) <= 0 then ( curSum := curSum + i ) else ( curSum := i ; tot := tot + 1 )) ; return tot; operation solve(lst : OclAny, m : OclAny) : OclAny pre: true post: true activity: var l : OclAny := (lst)->max() ; var r : double := 1000000 * m; ; while l /= r do ( var mid : int := ("" + (((l + r) / 2)))->toInteger(); ; if (check(lst, mid)->compareTo(m)) <= 0 then ( r := mid ) else ( l := mid + 1 )) ; return l; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def arraySum(arr,n): _sum=0 for i in range(n): _sum=_sum+arr[i] return _sum arr=[10,11,12,13,12,11,10] n=len(arr) print(arraySum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{10}->union(Sequence{11}->union(Sequence{12}->union(Sequence{13}->union(Sequence{12}->union(Sequence{11}->union(Sequence{ 10 })))))) ; n := (arr)->size() ; execute (arraySum(arr, n))->display(); operation arraySum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var _sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( _sum := _sum + arr[i+1]) ; return _sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) MOD=10**9+7 def func(N): S=str(bin(N))[2 :] L=len(S) dp=[[0]*3 for i in range(L+1)] dp[0][0]=1 for i in range(L): n=ord(S[i])-ord('0') for k in range(3): for s in range(3): if 2*s+n-k<0 : continue sd=min(2*s+n-k,2) dp[i+1][sd]+=dp[i][s] dp[i+1][sd]%=MOD return(dp[L][0]+dp[L][1]+dp[L][2])% MOD print(func(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var MOD : double := (10)->pow(9) + 7 ; skip ; execute (func(N))->display(); operation func(N : OclAny) : OclAny pre: true post: true activity: var S : OclAny := OclType["String"](bin(N)).subrange(2+1) ; var L : int := (S)->size() ; var dp : Sequence := Integer.subrange(0, L + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, 3))) ; dp->first()->first() := 1 ; for i : Integer.subrange(0, L-1) do ( var n : double := (S[i+1])->char2byte() - ('0')->char2byte() ; for k : Integer.subrange(0, 3-1) do ( for s : Integer.subrange(0, 3-1) do ( if 2 * s + n - k < 0 then ( continue ) else skip ; var sd : OclAny := Set{2 * s + n - k, 2}->min() ; dp[i + 1+1][sd+1] := dp[i + 1+1][sd+1] + dp[i+1][s+1] ; dp[i + 1+1][sd+1] := dp[i + 1+1][sd+1] mod MOD))) ; return (dp[L+1]->first() + dp[L+1][1+1] + dp[L+1][2+1]) mod MOD; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline def answer(): s=0 for i in range(m): if((a[i]+i)>n): return[-1] s+=a[i] if(scollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name answer)) (trailer (arguments ( )))))))))->display()); operation answer() : OclAny pre: true post: true activity: var s : int := 0 ; for i : Integer.subrange(0, m-1) do ( if (((a[i+1] + i)->compareTo(n)) > 0) then ( return Sequence{ -1 } ) else skip ; s := s + a[i+1]) ; if ((s->compareTo(n)) < 0) then ( return Sequence{ -1 } ) else skip ; var suffix : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(-1 + 1, m - 1)->reverse() do ( suffix[i+1] := suffix[i + 1+1] + a[i+1]) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( execute ((Set{i + 1, n - suffix[i+1] + 1}->max()) : ans)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline sys.setrecursionlimit(100000) mod=10**9+7 def read_values(): return map(int,input().split()) def read_index(): return map(lambda x : int(x)-1,input().split()) def read_list(): return list(read_values()) def read_lists(N): return[read_list()for n in range(N)] class V : def __init__(self,f,v=None): self.f=f self.v=v def __str__(self): return str(self.v) def ud(self,n): if n is None : return if self.v is None : self.v=n return self.v=self.f(self.v,n) def get(self,init=None): if self.v is None : return init else : return self.v def main(): N=format(int(input()),"b") D=len(str(N)) dp=[[0 for _ in range(3)]for __ in range(D+1)] dp[0][0]=1 for d in range(D): for k in range(3): for s in range(3): sd=2*s+int(N[d])-k if sd>2 : sd=2 if sd<0 : continue dp[d+1][sd]+=dp[d][s] dp[d+1][sd]%=mod print(sum(dp[D])% mod) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class V { static operation newV() : V pre: true post: V->exists( _x | result = _x ); attribute f : OclAny := f; attribute v : OclAny := v; operation initialise(f : OclAny,v : OclAny) : V pre: true post: true activity: self.f := f ; self.v := v; return self; operation __str__() : OclAny pre: true post: true activity: return ("" + ((self.v))); operation ud(n : OclAny) pre: true post: true activity: if n <>= null then ( return ) else skip ; if self.v <>= null then ( self.v := n ; return ) else skip ; self.v := self.f(self.v, n); operation get(init : OclAny) : OclAny pre: true post: true activity: if self.v <>= null then ( return init ) else ( return self.v ); } class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit(100000) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation read_values() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation read_index() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ); operation read_list() : OclAny pre: true post: true activity: return (read_values()); operation read_lists(N : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, N-1)->select(n | true)->collect(n | (read_list())); operation main() pre: true post: true activity: N := (("" + (((OclFile["System.in"]).readLine())))->toInteger() + "") ; var D : int := (("" + ((N))))->size() ; var dp : Sequence := Integer.subrange(0, D + 1-1)->select(__ | true)->collect(__ | (Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (0)))) ; dp->first()->first() := 1 ; for d : Integer.subrange(0, D-1) do ( for k : Integer.subrange(0, 3-1) do ( for s : Integer.subrange(0, 3-1) do ( var sd : double := 2 * s + ("" + ((N[d+1])))->toInteger() - k ; if sd > 2 then ( sd := 2 ) else skip ; if sd < 0 then ( continue ) else skip ; dp[d + 1+1][sd+1] := dp[d + 1+1][sd+1] + dp[d+1][s+1] ; dp[d + 1+1][sd+1] := dp[d + 1+1][sd+1] mod mod))) ; execute ((dp[D+1])->sum() mod mod)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import lru_cache @ lru_cache(None) def f(n): if n==0 : return 1 elif n==1 : return 2 elif n % 2==0 : return(2*f(n//2-1)+f(n//2))% 1000000007 else : return(2*f(n//2)+f(n//2-1))% 1000000007 n=int(input()) print(f(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; (compound_stmt (decorator @ (dotted_name (name lru_cache)) ( (arglist (argument (test (logical_test (comparison (expr (atom None))))))) )) (funcdef def (name f) ( (typedargslist (def_parameters (def_parameter (named_parameter (name n))))) ) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name n)))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name n)))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 2))))))))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (expr (atom (name n))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (number (integer 2)))) * (expr (atom (name f)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name n))) // (expr (atom (number (integer 2))))) - (expr (atom (number (integer 1)))))))))) ))))) + (expr (atom (name f)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) // (expr (atom (number (integer 2)))))))))) ))))))))) ))) % (expr (atom (number (integer 1000000007)))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (number (integer 2)))) * (expr (atom (name f)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) // (expr (atom (number (integer 2)))))))))) ))))) + (expr (atom (name f)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name n))) // (expr (atom (number (integer 2))))) - (expr (atom (number (integer 1)))))))))) ))))))))) ))) % (expr (atom (number (integer 1000000007))))))))))))))))))) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (f(n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) int1=lambda x : int(x)-1 p2D=lambda x : print(*x,sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int,sys.stdin.readline().split()) def LI(): return list(map(int,sys.stdin.readline().split())) def LLI(rows_number): return[LI()for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] def f(x,s): if min(x,s)<0 : return 0 if max(x,s)<2 : if x and s : return 2 else : return 1 if(x,s)in memo : return memo[x,s] res=f(x>>1,s>>1)+f(x-1>>1,s-1>>1)+f(x>>1,s-2>>1) res=memo[x,s]=res % md return res memo={} md=10**9+7 def main(): n=II() print(f(n,n)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; var p2D : Function := lambda x : OclAny in (((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ; skip ; skip ; skip ; skip ; skip ; skip ; var memo : OclAny := Set{} ; var md : double := (10)->pow(9) + 7 ; skip ; main(); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LLI(rows_number : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows_number-1)->select(_anon | true)->collect(_anon | (LI())); operation SI() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation f(x : OclAny, s : OclAny) : OclAny pre: true post: true activity: if Set{x, s}->min() < 0 then ( return 0 ) else skip ; if Set{x, s}->max() < 2 then ( if x & s then ( return 2 ) else ( return 1 ) ) else skip ; if (memo)->includes(Sequence{x, s}) then ( return memo[x+1][s+1] ) else skip ; var res : String := f(x /(2->pow(1)), s /(2->pow(1))) + f(x - 1 /(2->pow(1)), s - 1 /(2->pow(1))) + f(x /(2->pow(1)), s - 2 /(2->pow(1))) ; res := StringLib.format(res,md); var memo[x+1][s+1] : String := StringLib.format(res,md) ; return res; operation main() pre: true post: true activity: var n : OclAny := II() ; execute (f(n, n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- data=int(input()) array=format(data,"b") mod=1000000007 dynamic=[[0 for j in range(3)]for i in range(len(array)+1)] dynamic[0][0]=1 for i in range(len(array)): for j in range(3): for x in range(2): for y in range(x,2): b=(data>>i)& 1 dynamic[i+1][(x+y+j-b+1)//2]=(dynamic[i+1][(x+y+j-b+1)//2]+dynamic[i][j])% mod print(dynamic[len(array)][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var data : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var array : String := (data + "") ; var mod : int := 1000000007 ; var dynamic : Sequence := Integer.subrange(0, (array)->size() + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, 3-1)->select(j | true)->collect(j | (0)))) ; dynamic->first()->first() := 1 ; for i : Integer.subrange(0, (array)->size()-1) do ( for j : Integer.subrange(0, 3-1) do ( for x : Integer.subrange(0, 2-1) do ( for y : Integer.subrange(x, 2-1) do ( var b : int := MathLib.bitwiseAnd((data /(2->pow(i))), 1) ; dynamic[i + 1+1][(x + y + j - b + 1) div 2+1] := (dynamic[i + 1+1][(x + y + j - b + 1) div 2+1] + dynamic[i+1][j+1]) mod mod)))) ; execute (dynamic[(array)->size()+1]->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maximumOccurrence(s): n=len(s) freq={} for i in s : temp="" temp+=i freq[temp]=freq.get(temp,0)+1 for i in range(n): for j in range(i+1,n): temp="" temp+=s[i] temp+=s[j] freq[temp]=freq.get(temp,0)+1 answer=-10**9 for it in freq : answer=max(answer,freq[it]) return answer if __name__=='__main__' : s="xxxyy" print(maximumOccurrence(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( s := "xxxyy" ; execute (maximumOccurrence(s))->display() ) else skip; operation maximumOccurrence(s : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; var freq : OclAny := Set{} ; for i : s do ( var temp : String := "" ; temp := temp + i ; freq->at(temp) := freq.get(temp, 0) + 1) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( temp := "" ; temp := temp + s[i+1] ; temp := temp + s[j+1] ; freq->at(temp) := freq.get(temp, 0) + 1)) ; var answer : double := (-10)->pow(9) ; for it : freq do ( answer := Set{answer, freq[it+1]}->max()) ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def print(*args,end='\n',sep=' ')->None : sys.stdout.write(sep.join(map(str,args))+end) def Solve(): n,m=list(map(int,input().split())) b=list(map(int,input().split())) x=[0]*(n+1) for i in b : for o in range(i,n+1): if not x[o]: x[o]=i print(*x[1 :]) if __name__=="__main__" : Solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; if __name__ = "__main__" then ( Solve() ) else skip; (funcdef def name print ( (typedargslist (args * (named_parameter (name args))) , (def_parameters (def_parameter (named_parameter (name end)) = (test (logical_test (comparison (expr (atom ' ')))))) , (def_parameter (named_parameter (name sep)) = (test (logical_test (comparison (expr (atom ' ')))))))) ) -> (test (logical_test (comparison (expr (atom None))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name sep)) (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name args)))))))) ))))))))) )))) + (expr (atom (name end))))))))) )))))))))))))) operation Solve() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : b do ( for o : Integer.subrange(i, n + 1-1) do ( if not(x[o+1]) then ( x[o+1] := i ) else skip)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) l=[int(i)for i in input().split()] res=[] for i in range(m): for j in range(n-l[i]+1): if n==0 : print(res.reverse()) exit() res.append(l[i]) n-=1 res.reverse() for i in res : print(i,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var res : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( for j : Integer.subrange(0, n - l[i+1] + 1-1) do ( if n = 0 then ( execute (res->reverse())->display() ; exit() ) else skip ; execute ((l[i+1]) : res) ; n := n - 1)) ; res := res->reverse() ; for i : res do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def hondan(w,m): m_sum=b_lis[0] num=0 if ww : m_sum=b_lis[i+1] num+=1 if nume_id): return m_id+1 else : if m_bo : return(nibutan(f_id,m_id-1,m)) elif not m_bo : return(nibutan(m_id+1,e_id,m)) else : return m_id+1 while True : global w_lis b_lis=[] w_lis=[] dan_num=[0] m,n=map(int,input().split()) if m==n==0 : break for i in range(n): num=int(input()) b_lis.append(num) s_num=int(sum(b_lis)/m) print(nibutan(s_num,1500000,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute w_lis : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; while true do ( skip ; var b_lis : Sequence := Sequence{} ; w_lis := Sequence{} ; var dan_num : Sequence := Sequence{ 0 } ; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if m = n & (n == 0) then ( break ) else skip ; for i : Integer.subrange(0, n-1) do ( num := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((num) : b_lis)) ; var s_num : int := ("" + (((b_lis)->sum() / m)))->toInteger() ; execute (nibutan(s_num, 1500000, m))->display()); operation hondan(w : OclAny, m : OclAny) : OclAny pre: true post: true activity: var m_sum : OclAny := b_lis->first() ; var num : int := 0 ; if (w->compareTo((b_lis)->max())) < 0 then ( return false ) else ( for i : Integer.subrange(0, (b_lis)->size() - 1-1) do ( m_sum := m_sum + b_lis[i + 1+1] ; if (m_sum->compareTo(w)) > 0 then ( m_sum := b_lis[i + 1+1] ; num := num + 1 ) else skip) ; if (num->compareTo(m)) < 0 then ( return true ) else ( return false ) ); operation nibutan(f_id : OclAny, e_id : OclAny, m : OclAny) : OclAny pre: true post: true activity: var m_id : int := ("" + (((f_id + e_id) / 2)))->toInteger() ; var m_bo : OclAny := hondan(m_id, m) ; if ((f_id->compareTo(e_id)) > 0) then ( return m_id + 1 ) else ( if m_bo then ( return (nibutan(f_id, m_id - 1, m)) ) else (if not(m_bo) then ( return (nibutan(m_id + 1, e_id, m)) ) else ( return m_id + 1 ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=lambda : map(int,input().split()) n,m=i() n+=1 a=[n]*n for x in i(): if xcollect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := i->apply() ; n := n + 1 ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ n }, n) ; for x : i->apply() do ( if (x->compareTo(n)) < 0 then ( a.subrange(x+1, n) := MatrixLib.elementwiseMult(Sequence{ x }, (n - x)) ; var n : OclAny := x ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=lambda : map(int,input().split()) n,m=i() n+=1 a=[n]*n for x in i(): if xcollect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := i->apply() ; n := n + 1 ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ n }, n) ; for x : i->apply() do ( if (x->compareTo(n)) < 0 then ( a.subrange(x+1, n) := MatrixLib.elementwiseMult(Sequence{ x }, (n - x)) ; var n : OclAny := x ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) s=list(map(int,input().split())) lis=[] c=0 for i in s : z=n-i+1 z-=c if z<0 : z=0 c+=z v=(str(i)+" ")*z lis.extend(map(int,v.split())) lis.sort() print(*lis,sep=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lis : Sequence := Sequence{} ; var c : int := 0 ; for i : s do ( var z : double := n - i + 1 ; z := z - c ; if z < 0 then ( z := 0 ) else skip ; c := c + z ; var v : double := (("" + ((i))) + " ") * z ; lis := lis->union((v.split())->collect( _x | (OclType["int"])->apply(_x) ))) ; lis := lis->sort() ; execute ((argument * (test (logical_test (comparison (expr (atom (name lis))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def main(): N=int(input()) s=[input().strip()for i in range(2)] MOD=1000000007 if N==1 : print(3) return ans=0 pre=-1 i=0 while itoInteger() ; var s : Sequence := Integer.subrange(0, 2-1)->select(i | true)->collect(i | (input()->trim())) ; var MOD : int := 1000000007 ; if N = 1 then ( execute (3)->display() ; return ) else skip ; var ans : int := 0 ; var pre : int := -1 ; var i : int := 0 ; while (i->compareTo(N - 1)) < 0 do ( if s->first()[i+1] = s->first()[i + 1+1] then ( if ans = 0 then ( ans := 6 ) else ( if pre = 0 then ( ans := ans * 3 ; ans := ans mod MOD ) else ( ans := ans * 2 ; ans := ans mod MOD ) ) ; i := i + 2 ; pre := 0 ) else ( if ans = 0 then ( ans := 3 ) else ( if pre = 0 then ( skip ) else ( ans := ans * 2 ; ans := ans mod MOD ) ) ; i := i + 1 ; pre := 1 )) ; if i = N - 1 then ( if pre = 1 then ( ans := ans * 2 ; ans := ans mod MOD ) else skip ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def distancesum(arr,n): arr.sort() res=0 sum=0 for i in range(n): res+=(arr[i]*i-sum) sum+=arr[i] return res def totaldistancesum(x,y,n): return distancesum(x,n)+distancesum(y,n) x=[-1,1,3,2] y=[5,6,5,3] n=len(x) print(totaldistancesum(x,y,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; x := Sequence{-1}->union(Sequence{1}->union(Sequence{3}->union(Sequence{ 2 }))) ; y := Sequence{5}->union(Sequence{6}->union(Sequence{5}->union(Sequence{ 3 }))) ; n := (x)->size() ; execute (totaldistancesum(x, y, n))->display(); operation distancesum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var res : int := 0 ; var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( res := res + (arr[i+1] * i - sum) ; sum := sum + arr[i+1]) ; return res; operation totaldistancesum(x : OclAny, y : OclAny, n : OclAny) : OclAny pre: true post: true activity: return distancesum(x, n) + distancesum(y, n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n_=input().split() k=int(n_[1]) n=input().split() for i in range(len(n)): n[i]=int(n[i]) total=0 for i in n : if i+k<=5 : total+=1 print(total//3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n_ : OclAny := input().split() ; var k : int := ("" + ((n_[1+1])))->toInteger() ; var n : OclAny := input().split() ; for i : Integer.subrange(0, (n)->size()-1) do ( n[i+1] := ("" + ((n[i+1])))->toInteger()) ; var total : int := 0 ; for i : n do ( if i + k <= 5 then ( total := total + 1 ) else skip) ; execute (total div 3)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) s=list(map(int,input().split())) s_m=[] for x in s : if x+k<=5 : s_m.append(x) print(len(s_m)//3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s_m : Sequence := Sequence{} ; for x : s do ( if x + k <= 5 then ( execute ((x) : s_m) ) else skip) ; execute ((s_m)->size() div 3)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- P=lambda : map(int,input().split()) _,k=P() print(sum(x<=5-k for x in P())//3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var P : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var _anon : OclAny := null; var k : OclAny := null; Sequence{_anon,k} := P->apply() ; execute (((argument (test (logical_test (comparison (comparison (expr (atom (name x)))) <= (comparison (expr (expr (atom (number (integer 5)))) - (expr (atom (name k)))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name P)) (trailer (arguments ( )))))))))->sum() div 3)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) students=list(map(int,input().split())) counter=0 for i in students : if 5-i>=k : counter+=1 print(counter//3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var students : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var counter : int := 0 ; for i : students do ( if (5 - i->compareTo(k)) >= 0 then ( counter := counter + 1 ) else skip) ; execute (counter div 3)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) s=0 n=[int(i)for i in input().split()] for i in n : if i+b<=5 : s+=1 print(s//3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : int := 0 ; var n : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; for i : n do ( if i + b <= 5 then ( s := s + 1 ) else skip) ; execute (s div 3)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=0x7fffffff while 1 : m,n=map(int,input().split()) if m==0 : break dp=[[[INF for k in range(n+1)]for j in range(n+1)]for i in range(m+1)] w,k=[0]*(n+1),0 for i in range(1,n+1): l=int(input()) w[i]=w[i-1]+l if l>k : k=l if n<=m : print(k) continue for i in range(1,n+1): dp[1][1][i]=w[i] for k in range(2,m+1): for i in range(1,n+1): for j in range(i,n): for l in range(j,n): if dp[k-1][i][j]collect( _x | (OclType["int"])->apply(_x) ) ; if m = 0 then ( break ) else skip ; var dp : Sequence := Integer.subrange(0, m + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, n + 1-1)->select(k | true)->collect(k | (INF)))))) ; var w : OclAny := null; var k : OclAny := null; Sequence{w,k} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)),0} ; for i : Integer.subrange(1, n + 1-1) do ( var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; w[i+1] := w[i - 1+1] + l ; if (l->compareTo(k)) > 0 then ( var k : int := l ) else skip) ; if (n->compareTo(m)) <= 0 then ( execute (k)->display() ; continue ) else skip ; for i : Integer.subrange(1, n + 1-1) do ( dp[1+1][1+1][i+1] := w[i+1]) ; for k : Integer.subrange(2, m + 1-1) do ( for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(i, n-1) do ( for l : Integer.subrange(j, n-1) do ( if (dp[k - 1+1][i+1][j+1]->compareTo(INF)) < 0 then ( dp[k+1][j + 1+1][l + 1+1] := Set{dp[k+1][j + 1+1][l + 1+1], Set{w[l + 1+1] - w[j+1], dp[k - 1+1][i+1][j+1]}->max()}->min() ) else skip)))) ; var ans : int := INF ; for i : Integer.subrange(1, n + 1-1) do ( if (dp[m+1][i+1][n+1]->compareTo(ans)) < 0 then ( ans := dp[m+1][i+1][n+1] ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=eval(input()) for i in range(t): n=eval(input()) input_list=list(map(lambda e : eval(e),input().split(" "))) minimum=min(input_list) minimum_count=input_list.count(minimum) print(n-minimum_count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := (OclFile["System.in"]).readLine() ; var input_list : Sequence := ((input().split(" "))->collect( _x | (lambda e : OclAny in (e))->apply(_x) )) ; var minimum : OclAny := (input_list)->min() ; var minimum_count : int := input_list->count(minimum) ; execute (n - minimum_count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): m=int(input()) t=0 v=list(map(int,input().split())) for j in range(m): if v[j]>min(v): t+=1 print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : int := 0 ; var v : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, m-1) do ( if (v[j+1]->compareTo((v)->min())) > 0 then ( t := t + 1 ) else skip) ; execute (t)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) m=min(a) count=0 for x in a : if x>m : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : OclAny := (a)->min() ; var count : int := 0 ; for x : a do ( if (x->compareTo(m)) > 0 then ( count := count + 1 ) else skip) ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) a=list(map(int,input().split())) b=set(a) m=len(b) u=0 if m==1 : print(0) else : p=min(a) for j in a : if j>p : u+=1 print(u) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Set := Set{}->union((a)) ; var m : int := (b)->size() ; var u : int := 0 ; if m = 1 then ( execute (0)->display() ) else ( var p : OclAny := (a)->min() ; for j : a do ( if (j->compareTo(p)) > 0 then ( u := u + 1 ) else skip) ; execute (u)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=10**9+7 N=int(input()) S=iter(input()+" ") prev=next(S) count=0 counts=[] for c in S : count+=1 if prev!=c : counts.append(count) count=0 prev=c counts=iter(counts) prev=next(counts) ans=3*prev for count in counts : if prev==1 : ans*=2 elif count==2 : ans*=3 prev=count print(ans % MOD) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : double := (10)->pow(9) + 7 ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : OclAny := OclIterator.newOclIterator_Sequence((OclFile["System.in"]).readLine() + " ") ; var prev : OclAny := (S).next() ; var count : int := 0 ; var counts : Sequence := Sequence{} ; for c : S do ( count := count + 1 ; if prev /= c then ( execute ((count) : counts) ; count := 0 ) else skip ; prev := c) ; counts := OclIterator.newOclIterator_Sequence(counts) ; prev := (counts).next() ; var ans : double := 3 * prev ; for count : counts do ( if prev = 1 then ( ans := ans * 2 ) else (if count = 2 then ( ans := ans * 3 ) else skip) ; prev := count) ; execute (ans mod MOD)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=[int(x)for x in input().split()] print(n-a.count(min(a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (n - a->count((a)->min()))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bitsoncount(x): return bin(x).count('1') def isPossible(a,b): cntA=bitsoncount(a); cntB=bitsoncount(b); if(cntA==cntB): return True return False a=3 b=9 if(isPossible(a,b)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 3 ; b := 9 ; if (isPossible(a, b)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation bitsoncount(x : OclAny) : OclAny pre: true post: true activity: return bin(x)->count('1'); operation isPossible(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var cntA : OclAny := bitsoncount(a); ; var cntB : OclAny := bitsoncount(b); ; if (cntA = cntB) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cast_list(test_list,data_type): return list(map(data_type,test_list)) inputString=input() splitStringList=inputString.split() splitIntList=cast_list(splitStringList,int) splitIntList.sort() (a_plus_b,a_plus_c,b_plus_c,a_plus_b_plus_c)=(splitIntList[0],splitIntList[1],splitIntList[2],splitIntList[3]) c=a_plus_b_plus_c-a_plus_b a=a_plus_c-c b=b_plus_c-c print(a,b,c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var inputString : String := (OclFile["System.in"]).readLine() ; var splitStringList : OclAny := inputString.split() ; var splitIntList : OclAny := cast_list(splitStringList, OclType["int"]) ; splitIntList := splitIntList->sort() ; var Sequence{a_plus_b, a_plus_c, b_plus_c, a_plus_b_plus_c} : OclAny := Sequence{splitIntList->first(), splitIntList[1+1], splitIntList[2+1], splitIntList[3+1]} ; var c : double := a_plus_b_plus_c - a_plus_b ; var a : double := a_plus_c - c ; var b : double := b_plus_c - c ; execute (a)->display(); operation cast_list(test_list : OclAny, data_type : OclAny) : OclAny pre: true post: true activity: return ((test_list)->collect( _x | (data_type)->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=sorted(map(int,input().split())) print(d-c,d-b,d-a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; execute (d - c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=list(map(int,input().split())) a=sorted(a) w,x,y,z=a[0],a[1],a[2],a[3] print(z-w,end=" ") print(z-x,end=" ") print(z-y,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var w : OclAny := null; var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{w,x,y,z} := Sequence{a->first(),a[1+1],a[2+1],a[3+1]} ; execute (z - w)->display() ; execute (z - x)->display() ; execute (z - y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def Cond(m,n,mid,books): if max(books)>mid : return False rem=mid while books : while rem>=books[0]: rem-=books[0] books=books[1 :] if len(books)==0 : break rem=mid m-=1 if m>=0 : return True else : return False def solve(m,n,books): ub=1500000 lb=min(books) min_width=float('inf') for i in range(30): mid=(ub+lb)//2 if Cond(m,n,mid,books): min_width=min(min_width,mid) ub=mid else : lb=mid return min_width def main(args): while True : m,n=map(int,input().split()) if m==0 and n==0 : break books=[int(input())for _ in range(n)] result=solve(m,n,books) print(result) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation Cond(m : OclAny, n : OclAny, mid : OclAny, books : OclAny) : OclAny pre: true post: true activity: if ((books)->max()->compareTo(mid)) > 0 then ( return false ) else skip ; var rem : OclAny := mid ; while books do ( while (rem->compareTo(books->first())) >= 0 do ( rem := rem - books->first() ; books := books->tail() ; if (books)->size() = 0 then ( break ) else skip) ; rem := mid ; m := m - 1) ; if m >= 0 then ( return true ) else ( return false ); operation solve(m : OclAny, n : OclAny, books : OclAny) : OclAny pre: true post: true activity: var ub : int := 1500000 ; var lb : OclAny := (books)->min() ; var min_width : double := ("" + (('inf')))->toReal() ; for i : Integer.subrange(0, 30-1) do ( mid := (ub + lb) div 2 ; if Cond(m, n, mid, books) then ( min_width := Set{min_width, mid}->min() ; ub := mid ) else ( lb := mid )) ; return min_width; operation main(args : OclAny) pre: true post: true activity: while true do ( Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if m = 0 & n = 0 then ( break ) else skip ; books := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var result : OclAny := solve(m, n, books) ; execute (result)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x1,x2,x3,x4=map(int,input().split()) l=[] l.append(x1) l.append(x2) l.append(x3) l.append(x4) l.sort() c=l[3]-l[0] b=l[2]-c a=l[3]-(b+c) print(a,b,c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x1 : OclAny := null; var x2 : OclAny := null; var x3 : OclAny := null; var x4 : OclAny := null; Sequence{x1,x2,x3,x4} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := Sequence{} ; execute ((x1) : l) ; execute ((x2) : l) ; execute ((x3) : l) ; execute ((x4) : l) ; l := l->sort() ; var c : double := l[3+1] - l->first() ; var b : double := l[2+1] - c ; var a : double := l[3+1] - (b + c) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x1,x2,x3,x4=[int(x)for x in input().split()] vec=sorted([x1,x2,x3,x4]) ksum=vec[3] print(ksum-vec[0],ksum-vec[1],ksum-vec[2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x1 : OclAny := null; var x2 : OclAny := null; var x3 : OclAny := null; var x4 : OclAny := null; Sequence{x1,x2,x3,x4} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var vec : Sequence := Sequence{x1}->union(Sequence{x2}->union(Sequence{x3}->union(Sequence{ x4 })))->sort() ; var ksum : OclAny := vec[3+1] ; execute (ksum - vec->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): DIGITS=10 primes=eulerlib.list_primes(eulerlib.sqrt(10**DIGITS)) def is_prime(n): end=eulerlib.sqrt(n) for p in primes : if p>end : break if n % p==0 : return False return True ans=0 for digit in range(10): for rep in range(DIGITS,-1,-1): sum=0 digits=[0]*DIGITS for i in range(9**(DIGITS-rep)): for j in range(rep): digits[j]=digit temp=i for j in range(DIGITS-rep): d=temp % 9 if d>=digit : d+=1 if j>0 and d>digits[DIGITS-j]: break digits[-1-j]=d temp//=9 else : digits.sort() while True : if digits[0]>0 : num=int("".join(map(str,digits))) if is_prime(num): sum+=num if not eulerlib.next_permutation(digits): break if sum>0 : ans+=sum break return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var DIGITS : int := 10 ; var primes : OclAny := eulerlib.list_primes(eulerlib.sqrt((10)->pow(DIGITS))) ; skip ; var ans : int := 0 ; for digit : Integer.subrange(0, 10-1) do ( for rep : Integer.subrange(-1 + 1, DIGITS)->reverse() do ( var sum : int := 0 ; var digits : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, DIGITS) ; for i : Integer.subrange(0, (9)->pow((DIGITS - rep))-1) do ( for j : Integer.subrange(0, rep-1) do ( digits[j+1] := digit) ; var temp : OclAny := i ; (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name DIGITS))) - (expr (atom (name rep))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name temp))) % (expr (atom (number (integer 9)))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name d)))) >= (comparison (expr (atom (name digit))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name j)))) > (comparison (expr (atom (number (integer 0))))))) and (logical_test (comparison (comparison (expr (atom (name d)))) > (comparison (expr (atom (name digits)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name DIGITS))) - (expr (atom (name j))))))))) ])))))))) : (suite (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name digits)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom - (number (integer 1)))) - (expr (atom (name j))))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name temp)))))))) (assign_part //= (testlist (test (logical_test (comparison (expr (atom (number (integer 9))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name digits)) (trailer . (name sort) (arguments ( )))))))))))) (stmt (compound_stmt while (test (logical_test (comparison (expr (atom (name True)))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name digits)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) > (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name num)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name digits)))))))) ))))))))) ))))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name is_prime)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sum)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name num))))))))))))))))) (stmt (compound_stmt if (test (logical_test not (logical_test (comparison (expr (atom (name eulerlib)) (trailer . (name next_permutation) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name digits)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt break))))))))))))) ; if sum > 0 then ( ans := ans + sum ; break ) else skip)) ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): s=input() si,ei=0,len(s)-1 while True : if s[si]=='A' : break si+=1 while True : if s[ei]=='Z' : break ei-=1 print(ei-si+1) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var si : OclAny := null; var ei : OclAny := null; Sequence{si,ei} := Sequence{0,(s)->size() - 1} ; while true do ( if s[si+1] = 'A' then ( break ) else skip ; si := si + 1) ; while true do ( if s[ei+1] = 'Z' then ( break ) else skip ; ei := ei - 1) ; execute (ei - si + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() print(s.rfind("Z")-s.find("A")+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; execute (s.rfind("Z") - s->indexOf("A") - 1 + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,datetime PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") DAY=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"] while True : m,d=[int(_)for _ in input().split()] if m==d==0 : break print(DAY[datetime.date(2004,m,d).weekday()]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; var DAY : Sequence := Sequence{"Monday"}->union(Sequence{"Tuesday"}->union(Sequence{"Wednesday"}->union(Sequence{"Thursday"}->union(Sequence{"Friday"}->union(Sequence{"Saturday"}->union(Sequence{ "Sunday" })))))) ; while true do ( var m : OclAny := null; var d : OclAny := null; Sequence{m,d} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; if m = d & (d == 0) then ( break ) else skip ; execute (DAY[datetime.date(2004, m, d).weekday()+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=int(input()) goredole=[x,7-x] for i in range(n): if i==0 : a=list(map(int,input().split())) else : b=list(map(int,input().split())) a.extend(b) c=list() for i in range(n*2): c.append(7-a[i]) if n==1 : print('YES') else : for i in range(2,(n*2)-1,2): kocka=[1,2,3,4,5,6] if a[i]in kocka : kocka.remove(a[i]) if a[i+1]in kocka : kocka.remove(a[i+1]) if c[i]in kocka : kocka.remove(c[i]) if c[i+1]in kocka : kocka.remove(c[i+1]) if goredole[-1]in kocka : kocka.remove(goredole[-1]) if len(kocka)==1 : goredole.append(kocka[0]) goredole.append(goredole[-2]) if i==(n*2)-2 : print('YES') break else : print('NO') break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var goredole : Sequence := Sequence{x}->union(Sequence{ 7 - x }) ; for i : Integer.subrange(0, n-1) do ( if i = 0 then ( var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ) else ( var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->union(b) )) ; var c : Sequence := () ; for i : Integer.subrange(0, n * 2-1) do ( execute ((7 - a[i+1]) : c)) ; if n = 1 then ( execute ('YES')->display() ) else ( for i : Integer.subrange(2, (n * 2) - 1-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( var kocka : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))))) ; if (kocka)->includes(a[i+1]) then ( execute ((a[i+1]) /: kocka) ) else skip ; if (kocka)->includes(a[i + 1+1]) then ( execute ((a[i + 1+1]) /: kocka) ) else skip ; if (kocka)->includes(c[i+1]) then ( execute ((c[i+1]) /: kocka) ) else skip ; if (kocka)->includes(c[i + 1+1]) then ( execute ((c[i + 1+1]) /: kocka) ) else skip ; if (kocka)->includes(goredole->last()) then ( execute ((goredole->last()) /: kocka) ) else skip ; if (kocka)->size() = 1 then ( execute ((kocka->first()) : goredole) ; execute ((goredole->front()->last()) : goredole) ; if i = (n * 2) - 2 then ( execute ('YES')->display() ; break ) else skip ) else ( execute ('NO')->display() ; break )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) S1=list(input()) S2=list(input()) if len(S1)>1 : if S1[0]==S1[1]: st=2 ans=6 flag=1 else : st=1 ans=3 flag=-1 else : st=1 ans=3 flag=-1 while sttoInteger() ; var S1 : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var S2 : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if (S1)->size() > 1 then ( if S1->first() = S1[1+1] then ( var st : int := 2 ; var ans : int := 6 ; var flag : int := 1 ) else ( st := 1 ; ans := 3 ; flag := -1 ) ) else ( st := 1 ; ans := 3 ; flag := -1 ) ; while (st->compareTo(N)) < 0 do ( if (st + 1->compareTo(N)) < 0 then ( if S1[st+1] = S1[st + 1+1] then ( if flag < 0 then ( ans := ans * 2 ) else ( ans := ans * 3 ) ; st := st + 2 ; flag := 1 ) else ( if flag < 0 then ( ans := ans * 2 ) else ( ans := ans * 1 ) ; st := st + 1 ; flag := -1 ) ) else ( if flag < 0 then ( ans := ans * 2 ) else ( ans := ans * 1 ) ; st := st + 1 )) ; ans := ans mod 1000000007 ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin best=0 cnt=0 flg=False def main(): while True : tmp=stdin.read(1) if tmp.strip()!="" : calc(tmp) elif tmp!='' : break print(best) def calc(v : chr): global best global cnt global flg if v=='A' : flg=True if flg : cnt+=1 if flg and v=='Z' : best=cnt if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute best : OclAny; attribute cnt : OclAny; attribute flg : OclAny; operation initialise() pre: true post: true activity: skip ; var best : int := 0 ; var cnt : int := 0 ; var flg : boolean := false ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: while true do ( var tmp : String := stdin.readAll() ; if tmp->trim() /= "" then ( calc(tmp) ) else (if tmp /= '' then ( break ) else skip)) ; execute (best)->display(); operation calc(v : chr) pre: true post: true activity: skip ; skip ; skip ; if v = 'A' then ( flg := true ) else skip ; if flg then ( cnt := cnt + 1 ) else skip ; if flg & v = 'Z' then ( best := cnt ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S_list=list(input()) l=len(S_list) for i in range(l): if S_list[i]=="A" : start=i break for i in range(l): if S_list[i]=="Z" : finish=i print(finish-start+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S_list : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var l : int := (S_list)->size() ; for i : Integer.subrange(0, l-1) do ( if S_list[i+1] = "A" then ( var start : OclAny := i ; break ) else skip) ; for i : Integer.subrange(0, l-1) do ( if S_list[i+1] = "Z" then ( var finish : OclAny := i ) else skip) ; execute (finish - start + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solve : def __init__(self): self.M,self.N=map(int,input().split()) self.bs=[int(input())for i in range(self.N)] self.S=min(sum(self.bs),1500000) self.l,self.r=0,self.S def check(self,W): w=W i=1 for b in self.bs : if(w>=b): w-=b elif(W>=b): if(i>=self.M): return False i+=1 w=W-b else : return False return True def solve(self): while self.r-self.l>1 : m=(self.l+self.r)//2 if self.check(m): self.r=m else : self.l=m return self.r while True : s=Solve() if s.M==0 and s.N==0 : break print(s.solve()) ------------------------------------------------------------ OCL File: --------- class Solve { static operation newSolve() : Solve pre: true post: Solve->exists( _x | result = _x ); attribute (testlist_star_expr (test (logical_test (comparison (expr (atom (name self)) (trailer . (name M)))))) , (test (logical_test (comparison (expr (atom (name self)) (trailer . (name N))))))) : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); attribute bs : Sequence := Integer.subrange(0, self.N-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())); attribute S : OclAny := Set{(self.bs)->sum(), 1500000}->min(); attribute (testlist_star_expr (test (logical_test (comparison (expr (atom (name self)) (trailer . (name l)))))) , (test (logical_test (comparison (expr (atom (name self)) (trailer . (name r))))))) : OclAny := 0,self.S; operation initialise() : Solve pre: true post: true activity: var self.M : OclAny := null; var self.N : OclAny := null; Sequence{self.M,self.N} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; self.bs := Integer.subrange(0, self.N-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; self.S := Set{(self.bs)->sum(), 1500000}->min() ; var self.l : OclAny := null; var self.r : OclAny := null; Sequence{self.l,self.r} := Sequence{0,self.S}; return self; operation check(W : OclAny) : OclAny pre: true post: true activity: var w : OclAny := W ; var i : int := 1 ; for b : self.bs do ( if ((w->compareTo(b)) >= 0) then ( w := w - b ) else (if ((W->compareTo(b)) >= 0) then ( if ((i->compareTo(self.M)) >= 0) then ( return false ) else skip ; i := i + 1 ; w := W - b ) else ( return false ) ) ) ; return true; operation solve() : OclAny pre: true post: true activity: while self.r - self.l > 1 do ( var m : int := (self.l + self.r) div 2 ; if self.check(m) then ( self.r := m ) else ( self.l := m )) ; return self.r; } class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var s : Solve := (Solve.newSolve()).initialise() ; if s.M = 0 & s.N = 0 then ( break ) else skip ; execute (s.solve())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin s=stdin.readline().rstrip() si,ei=0,0 a_marked=False for i,c in enumerate(s): if c=='A' : if a_marked : continue else : si=i a_marked=True if c=='Z' : ei=i print(len(s[si : ei+1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : OclAny := stdin.readLine().rstrip() ; var si : OclAny := null; var ei : OclAny := null; Sequence{si,ei} := Sequence{0,0} ; var a_marked : boolean := false ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if c = 'A' then ( if a_marked then ( continue ) else ( var si : OclAny := i ; a_marked := true ) ) else skip ; if c = 'Z' then ( var ei : OclAny := i ) else skip) ; execute ((s.subrange(si+1, ei + 1))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def percent(a,b): result=int(((b-a)*100)/a) return result if __name__=="__main__" : a,b=20,25 print(percent(a,b),"%") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{a,b} := Sequence{20,25} ; execute (percent(a, b))->display() ) else skip; operation percent(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var result : int := ("" + ((((b - a) * 100) / a)))->toInteger() ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() y=int(x[: 2]) if x[2 :]=="of week" : if y==6 or y==5 : print(53) else : print(52) else : if y<30 : print(12) elif y==30 : print(11) elif y==31 : print(7) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := (OclFile["System.in"]).readLine() ; var y : int := ("" + ((x.subrange(1,2))))->toInteger() ; if x.subrange(2+1) = "of week" then ( if y = 6 or y = 5 then ( execute (53)->display() ) else ( execute (52)->display() ) ) else ( if y < 30 then ( execute (12)->display() ) else (if y = 30 then ( execute (11)->display() ) else (if y = 31 then ( execute (7)->display() ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ins=input().split() dict={'week' :[0,52,52,52,52,53,53,52],'month' : 30*[12]+[11,7]} print(dict[ins[2]][int(ins[0])]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ins : OclAny := input().split() ; var OclType["Map"] : Map := Map{ 'week' |-> Sequence{0}->union(Sequence{52}->union(Sequence{52}->union(Sequence{52}->union(Sequence{52}->union(Sequence{53}->union(Sequence{53}->union(Sequence{ 52 }))))))) }->union(Map{ 'month' |-> MatrixLib.elementwiseMult(Sequence{ 12 }, 30)->union(Sequence{11}->union(Sequence{ 7 })) }) ; execute (OclType["Map"][ins[2+1]+1][("" + ((ins->first())))->toInteger()+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,_,s=input().split(); print([[[12,52+(n in '56')][s>'n'],11][n=='30'],7][n=='31']) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var _anon : OclAny := null; var s : OclAny := null; Sequence{n,_anon,s} := input().split(); execute (Sequence{Sequence{Sequence{12}->union(Sequence{ 52 + (('56')->characters()->includes(n)) })->select(s > 'n')}->union(Sequence{ 11 })->select(n = '30')}->union(Sequence{ 7 })->select(n = '31'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=int(a[: 2]) if a[2 :]=="of week" : if b==6 or b==5 : print(53) else : print(52) else : if b<30 : print(12) elif b==30 : print(11) elif b==31 : print(7) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : int := ("" + ((a.subrange(1,2))))->toInteger() ; if a.subrange(2+1) = "of week" then ( if b = 6 or b = 5 then ( execute (53)->display() ) else ( execute (52)->display() ) ) else ( if b < 30 then ( execute (12)->display() ) else (if b = 30 then ( execute (11)->display() ) else (if b = 31 then ( execute (7)->display() ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,_,s=input().split(); print([[[12,52+(n in '56')][s>'n'],11][n=='30'],7][n=='31']) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var _anon : OclAny := null; var s : OclAny := null; Sequence{n,_anon,s} := input().split(); execute (Sequence{Sequence{Sequence{12}->union(Sequence{ 52 + (('56')->characters()->includes(n)) })->select(s > 'n')}->union(Sequence{ 11 })->select(n = '30')}->union(Sequence{ 7 })->select(n = '31'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minimumChanges(arr,n): changes=0 i=0 while iunion(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 1 })))))))) ; n := (arr)->size() ; execute ("Minimum operations:")->display() ) else skip; operation minimumChanges(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var changes : int := 0 ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( if arr[i+1] = 1 then ( var j : int := i + 1 ; while (j->compareTo(n)) < 0 do ( if arr[j+1] = 0 then ( break ) else skip ; j := j + 1) ; i := j - 1 ; changes := changes + 1 ) else skip ; i := i + 1) ; return changes; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=1000000007 with open(0)as f : N,s,t=f.read().split() domino=[] s+='_' c=s[0] lying=False for x in s[1 :]: if x==c : lying=True continue if lying : domino.append(1) else : domino.append(0) c=x lying=False if domino[0]==0 : ans=3 else : ans=6 for idx,d in enumerate(domino[1 :]): if domino[idx]==0 : ans*=2 else : if d==0 : ans*=1 else : ans*=3 ans %=mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : int := 1000000007 ; try (var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(0)); var N : OclAny := null; var s : OclAny := null; var t : OclAny := null; Sequence{N,s,t} := f.readAll().split()) catch (_e : OclException) do skip ; var domino : Sequence := Sequence{} ; s := s + '_' ; var c : OclAny := s->first() ; var lying : boolean := false ; for x : s->tail() do ( if x = c then ( lying := true ; continue ) else skip ; if lying then ( execute ((1) : domino) ) else ( execute ((0) : domino) ) ; c := x ; lying := false) ; if domino->first() = 0 then ( var ans : int := 3 ) else ( ans := 6 ) ; for _tuple : Integer.subrange(1, (domino->tail())->size())->collect( _indx | Sequence{_indx-1, (domino->tail())->at(_indx)} ) do (var _indx : int := 1; var idx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); if domino[idx+1] = 0 then ( ans := ans * 2 ) else ( if d = 0 then ( ans := ans * 1 ) else ( ans := ans * 3 ) ) ; ans := ans mod mod) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countMultiples(n): res=0 ; for i in range(1,n+1): if(i % 3==0 or i % 7==0): res+=1 ; return res ; print("Count=",countMultiples(25)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute ("Count=")->display();; operation countMultiples(n : OclAny) pre: true post: true activity: var res : int := 0; ; for i : Integer.subrange(1, n + 1-1) do ( if (i mod 3 = 0 or i mod 7 = 0) then ( res := res + 1; ) else skip) ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,wmax=map(int,input().split()) U=[] for _ in range(n): v,w=map(int,input().split()) u=v/w U.append([-u,v,w]) U.sort() remains=wmax i=0 ans=0 while True : try : if remains>U[i][2]: remains-=U[i][2] ans+=U[i][1] i+=1 else : ans+=U[i][1]*remains/U[i][2] break except : break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var wmax : OclAny := null; Sequence{n,wmax} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var U : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var v : OclAny := null; var w : OclAny := null; Sequence{v,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var u : double := v / w ; execute ((Sequence{-u}->union(Sequence{v}->union(Sequence{ w }))) : U)) ; U := U->sort() ; var remains : OclAny := wmax ; var i : int := 0 ; var ans : int := 0 ; while true do ( try ( if (remains->compareTo(U[i+1][2+1])) > 0 then ( remains := remains - U[i+1][2+1] ; ans := ans + U[i+1][1+1] ; i := i + 1 ) else ( ans := ans + U[i+1][1+1] * remains / U[i+1][2+1] ; break )) catch (_e : OclException) do ( break) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if not n : break start=int(input())-1 goal=int(input())-1 d=int(input()) nums=[[i for i in range(n)]] bars=[] for i in range(d): s=input() bars.append(s) new=nums[-1][:] for j in range(n-1): if s[j]=="1" : new[j],new[j+1]=new[j+1],new[j] nums.append(new) to_goal=nums[-1][goal] if to_goal==start : print(0) else : for i,status in enumerate(nums[1 :]): to_goal_ind=status.index(to_goal) start_ind=status.index(start) ind1,ind2=min(to_goal_ind,start_ind),max(to_goal_ind,start_ind) if ind2-ind1==1 : if(bars[i][ind1]=="0")and(ind1==0 or bars[i][ind1-1]=="0")and(ind2==n-1 or bars[i][ind2]=="0"): print(i+1,ind1+1) break else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(n) then ( break ) else skip ; var start : double := ("" + (((OclFile["System.in"]).readLine())))->toInteger() - 1 ; var goal : double := ("" + (((OclFile["System.in"]).readLine())))->toInteger() - 1 ; var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nums : Sequence := Sequence{ Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)) } ; var bars : Sequence := Sequence{} ; for i : Integer.subrange(0, d-1) do ( var s : String := (OclFile["System.in"]).readLine() ; execute ((s) : bars) ; var new : OclAny := nums->last() ; for j : Integer.subrange(0, n - 1-1) do ( if s[j+1] = "1" then ( var new[j+1] : OclAny := null; var new[j + 1+1] : OclAny := null; Sequence{new[j+1],new[j + 1+1]} := Sequence{new[j + 1+1],new[j+1]} ) else skip) ; execute ((new) : nums)) ; var to_goal : OclAny := nums->last()[goal+1] ; if to_goal = start then ( execute (0)->display() ) else ( (compound_stmt for (exprlist (expr (atom (name i))) , (expr (atom (name status)))) in (testlist (test (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name nums)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name to_goal_ind)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name status)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name to_goal)))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name start_ind)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name status)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name start)))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name ind1)))))) , (test (logical_test (comparison (expr (atom (name ind2))))))) (assign_part = (testlist_star_expr (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name to_goal_ind))))))) , (argument (test (logical_test (comparison (expr (atom (name start_ind)))))))) ))))))) , (test (logical_test (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name to_goal_ind))))))) , (argument (test (logical_test (comparison (expr (atom (name start_ind)))))))) )))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name ind2))) - (expr (atom (name ind1))))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name bars)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ind1)))))))) ])))) == (comparison (expr (atom "0"))))))) ))))) and (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom (name ind1)))) == (comparison (expr (atom (number (integer 0))))))) or (logical_test (comparison (comparison (expr (atom (name bars)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name ind1))) - (expr (atom (number (integer 1)))))))))) ])))) == (comparison (expr (atom "0")))))))) )))))) and (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom (name ind2)))) == (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))) or (logical_test (comparison (comparison (expr (atom (name bars)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ind2)))))))) ])))) == (comparison (expr (atom "0")))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name ind1))) + (expr (atom (number (integer 1)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ))))))))))))))) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline write=sys.stdout.write def solve(): N=int(readline()) if N==0 : return False M=int(readline()) K=int(readline()) D=int(readline()) P=[list(map(int,readline().strip()))+[0]for i in range(D)] INF=(10,0); GL=(-1,0) X=[INF]*N X[K-1]=GL for i in range(D-1,-1,-1): Pi=P[i] for j in range(N-1): if Pi[j]: X[j],X[j+1]=X[j+1],X[j] elif 0==Pi[j-1]==Pi[j+1]: if X[j]==GL : X[j+1]=(i,j) if X[j+1]==GL : X[j]=(i,j) if X[M-1]==GL : write("0\n") elif X[M-1]==INF : write("1\n") else : x,y=X[M-1] write("%d %d\n" %(x+1,y+1)) return True while solve(): ... ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var write : OclAny := (OclFile["System.out"]).write ; skip ; while solve() do (); operation solve() : OclAny pre: true post: true activity: var N : int := ("" + ((readline())))->toInteger() ; if N = 0 then ( return false ) else skip ; var M : int := ("" + ((readline())))->toInteger() ; var K : int := ("" + ((readline())))->toInteger() ; var D : int := ("" + ((readline())))->toInteger() ; var P : Sequence := Integer.subrange(0, D-1)->select(i | true)->collect(i | (((readline()->trim())->collect( _x | (OclType["int"])->apply(_x) ))->union(Sequence{ 0 }))) ; var INF : OclAny := Sequence{10, 0}; var GL : OclAny := Sequence{-1, 0} ; var X : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, N) ; X[K - 1+1] := GL ; for i : Integer.subrange(-1 + 1, D - 1)->reverse() do ( var Pi : OclAny := P[i+1] ; for j : Integer.subrange(0, N - 1-1) do ( if Pi[j+1] then ( var X[j+1] : OclAny := null; var X[j + 1+1] : OclAny := null; Sequence{X[j+1],X[j + 1+1]} := Sequence{X[j + 1+1],X[j+1]} ) else (if 0 = Pi[j - 1+1] & (Pi[j - 1+1] == Pi[j + 1+1]) then ( if X[j+1] = GL then ( X[j + 1+1] := Sequence{i, j} ) else skip ; if X[j + 1+1] = GL then ( X[j+1] := Sequence{i, j} ) else skip ) else skip))) ; if X[M - 1+1] = GL then ( write("0\n") ) else (if X[M - 1+1] = INF then ( write("1\n") ) else ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := X[M - 1+1] ; write(StringLib.format("%d %d\n",Sequence{x + 1, y + 1})) ) ) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys f=sys.stdin while True : n=int(f.readline()) if n==0 : break m,star,d=[int(f.readline())for _ in range(3)] lines=[f.readline().strip()for _ in range(d)] lots=[None for j in range(d+1)] lots[0]=[i+1 for i in range(n)] for i,line in enumerate(lines): lots[i+1]=lots[i][:] for j,c in enumerate(line): if c=='1' : lots[i+1][j],lots[i+1][j+1]=lots[i+1][j+1],lots[i+1][j] star=lots[-1][star-1] if m==star : print(0) continue for i,lot in enumerate(lots): index_min=min(lot.index(m),lot.index(star)) index_max=max(lot.index(m),lot.index(star)) if i and index_max-index_min==1 : line=lines[i-1] if(index_min==0 or line[index_min-1]=='0')and line[index_min]=='0' and(index_max==n-1 or line[index_max]=='0'): print(i,min(lot.index(m),lot.index(star))+1) break if i==len(lots)-1 : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var f : OclFile := OclFile["System.in"] ; while true do ( var n : int := ("" + ((f.readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var m : OclAny := null; var star : OclAny := null; var d : OclAny := null; Sequence{m,star,d} := Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (("" + ((f.readLine())))->toInteger())) ; var lines : Sequence := Integer.subrange(0, d-1)->select(_anon | true)->collect(_anon | (f.readLine()->trim())) ; var lots : Sequence := Integer.subrange(0, d + 1-1)->select(j | true)->collect(j | (null)) ; lots->first() := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i + 1)) ; for _tuple : Integer.subrange(1, (lines)->size())->collect( _indx | Sequence{_indx-1, (lines)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var line : OclAny := _tuple->at(_indx); lots[i + 1+1] := lots[i+1] ; for _tuple : Integer.subrange(1, (line)->size())->collect( _indx | Sequence{_indx-1, (line)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if c = '1' then ( var lots[i + 1+1][j+1] : OclAny := null; var lots[i + 1+1][j + 1+1] : OclAny := null; Sequence{lots[i + 1+1][j+1],lots[i + 1+1][j + 1+1]} := Sequence{lots[i + 1+1][j + 1+1],lots[i + 1+1][j+1]} ) else skip)) ; var star : OclAny := lots->last()[star - 1+1] ; if m = star then ( execute (0)->display() ; continue ) else skip ; for _tuple : Integer.subrange(1, (lots)->size())->collect( _indx | Sequence{_indx-1, (lots)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var lot : OclAny := _tuple->at(_indx); var index_min : OclAny := Set{lot->indexOf(m) - 1, lot->indexOf(star) - 1}->min() ; var index_max : OclAny := Set{lot->indexOf(m) - 1, lot->indexOf(star) - 1}->max() ; if i & index_max - index_min = 1 then ( var line : OclAny := lines[i - 1+1] ; if (index_min = 0 or line[index_min - 1+1] = '0') & line[index_min+1] = '0' & (index_max = n - 1 or line[index_max+1] = '0') then ( execute (i)->display() ; break ) else skip ) else skip ; if i = (lots)->size() - 1 then ( execute (1)->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break m,p,d=[int(input())for i in range(3)] m-=1 p-=1 a=[[]for i in range(d+1)] for i in range(d): a[i]=list(map(int,input())) s=[[0 for j in range(n)]for i in range(d+1)] s[d]=[i for i in range(n)] for i in range(d-1,-1,-1): for j in range(n): s[i][j]=s[i+1][j] for j in range(n-1): if a[i][j]: s[i][j],s[i][j+1]=s[i][j+1],s[i][j] k=s[0][m] if k==p : print(0) continue f=False for i in range(d): for j in range(n-1): if((s[i][j]==k and s[i][j+1]==p)or(s[i][j]==p and s[i][j+1]==k))and(j==0 or a[i][j-1]==0)and a[i][j]==0 and(j==n-2 or a[i][j+1]==0): print(i+1,j+1) f=True break if f : break if not f : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var m : OclAny := null; var p : OclAny := null; var d : OclAny := null; Sequence{m,p,d} := Integer.subrange(0, 3-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; m := m - 1 ; p := p - 1 ; var a : Sequence := Integer.subrange(0, d + 1-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, d-1) do ( a[i+1] := (((OclFile["System.in"]).readLine())->collect( _x | (OclType["int"])->apply(_x) ))) ; var s : Sequence := Integer.subrange(0, d + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, n-1)->select(j | true)->collect(j | (0)))) ; s[d+1] := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)) ; for i : Integer.subrange(-1 + 1, d - 1)->reverse() do ( for j : Integer.subrange(0, n-1) do ( s[i+1][j+1] := s[i + 1+1][j+1]) ; for j : Integer.subrange(0, n - 1-1) do ( if a[i+1][j+1] then ( var s[i+1][j+1] : OclAny := null; var s[i+1][j + 1+1] : OclAny := null; Sequence{s[i+1][j+1],s[i+1][j + 1+1]} := Sequence{s[i+1][j + 1+1],s[i+1][j+1]} ) else skip)) ; var k : OclAny := s->first()[m+1] ; if k = p then ( execute (0)->display() ; continue ) else skip ; var f : boolean := false ; for i : Integer.subrange(0, d-1) do ( for j : Integer.subrange(0, n - 1-1) do ( if ((s[i+1][j+1] = k & s[i+1][j + 1+1] = p) or (s[i+1][j+1] = p & s[i+1][j + 1+1] = k)) & (j = 0 or a[i+1][j - 1+1] = 0) & a[i+1][j+1] = 0 & (j = n - 2 or a[i+1][j + 1+1] = 0) then ( execute (i + 1)->display() ; f := true ; break ) else skip) ; if f then ( break ) else skip) ; if not(f) then ( execute (1)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy def check_lots(start,goal,line): for i in range(len(line)): for j in range(len(line[i])): if line[i][j]==1 : if j==start-1 : start-=1 elif j==start : start+=1 return start==goal while True : n=int(input()) if n==0 : break m=int(input()) s=int(input()) d=int(input()) l=[] for i in range(d): l.append([0]+list(map(int,list(input())))+[0]) d_ans=0 n_ans=0 if check_lots(m,s,l): print(0) else : for i in range(d): for j in range(1,n): l_tmp=copy.deepcopy(l[:]) if sum(l[i][j-1 : j+2])>0 : continue l_tmp[i][j]=1 if check_lots(m,s,l_tmp): d_ans=i+1 n_ans=j break else : continue break if d_ans : print(d_ans,n_ans) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, d-1) do ( execute ((Sequence{ 0 }->union(((((OclFile["System.in"]).readLine())->characters())->collect( _x | (OclType["int"])->apply(_x) )))->union(Sequence{ 0 })) : l)) ; var d_ans : int := 0 ; var n_ans : int := 0 ; if check_lots(m, s, l) then ( execute (0)->display() ) else ( for i : Integer.subrange(0, d-1) do ((compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l_tmp)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name copy)) (trailer . (name deepcopy) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript :)) ])))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name j))) - (expr (atom (number (integer 1)))))))) : (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 2)))))))))) ])))))))) ))))) > (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt continue)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l_tmp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name check_lots)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name m))))))) , (argument (test (logical_test (comparison (expr (atom (name s))))))) , (argument (test (logical_test (comparison (expr (atom (name l_tmp)))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d_ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name n_ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name j)))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt continue)))))) ; break) ; if d_ans then ( execute (d_ans)->display() ) else ( execute (1)->display() ) )); operation check_lots(start : OclAny, goal : OclAny, line : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, (line)->size()-1) do ( for j : Integer.subrange(0, (line[i+1])->size()-1) do ( if line[i+1][j+1] = 1 then ( if j = start - 1 then ( start := start - 1 ) else (if j = start then ( start := start + 1 ) else skip) ) else skip)) ; return start = goal; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def missingK(a,k,n): difference=0 ans=0 count=k flag=0 for i in range(0,n-1): difference=0 if((a[i]+1)!=a[i+1]): difference+=(a[i+1]-a[i])-1 if(difference>=count): ans=a[i]+count flag=1 break else : count-=difference if(flag): return ans else : return-1 a=[1,5,11,19] k=11 n=len(a) missing=missingK(a,k,n) print(missing) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{1}->union(Sequence{5}->union(Sequence{11}->union(Sequence{ 19 }))) ; k := 11 ; n := (a)->size() ; var missing : OclAny := missingK(a, k, n) ; execute (missing)->display(); operation missingK(a : OclAny, k : OclAny, n : OclAny) : OclAny pre: true post: true activity: var difference : int := 0 ; var ans : int := 0 ; var count : OclAny := k ; var flag : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( difference := 0 ; if ((a[i+1] + 1) /= a[i + 1+1]) then ( difference := difference + (a[i + 1+1] - a[i+1]) - 1 ; if ((difference->compareTo(count)) >= 0) then ( ans := a[i+1] + count ; flag := 1 ; break ) else ( count := count - difference ) ) else skip) ; if (flag) then ( return ans ) else ( return -1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def egyptianFraction(nr,dr): print("The Egyptian Fraction "+"Representation of{0}/{1}is".format(nr,dr),end="\n") ef=[] while nr!=0 : x=math.ceil(dr/nr) ef.append(x) nr=x*nr-dr dr=dr*x for i in range(len(ef)): if i!=len(ef)-1 : print(" 1/{0}+".format(ef[i]),end=" ") else : print(" 1/{0}".format(ef[i]),end=" ") egyptianFraction(6,14) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; egyptianFraction(6, 14); operation egyptianFraction(nr : OclAny, dr : OclAny) pre: true post: true activity: execute ("The Egyptian Fraction " + StringLib.interpolateStrings("Representation of{0}/{1}is", Sequence{nr, dr}))->display() ; var ef : Sequence := Sequence{} ; while nr /= 0 do ( var x : double := (dr / nr)->ceil() ; execute ((x) : ef) ; nr := x * nr - dr ; dr := dr * x) ; for i : Integer.subrange(0, (ef)->size()-1) do ( if i /= (ef)->size() - 1 then ( execute (StringLib.interpolateStrings(" 1/{0}+", Sequence{ef[i+1]}))->display() ) else ( execute (StringLib.interpolateStrings(" 1/{0}", Sequence{ef[i+1]}))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) length=int(n/19)+1 if n>19 and n % 19==0 : length-=1 d=[] for i in range(length): d+=list(map(int,input().split())) start,end=1,10 l=[] flag=False for j in range(1,len(d)+1): for i in range(0,len(d)): tmp=''.join(map(str,d[i : i+j])) if len(tmp)>1 and tmp[0]=='0' : pass elif len(tmp)==j : l.append(int(tmp)) l=sorted(set(l)) if start==1 : for k in range(0,10): if k not in l : print(k) flag=True break else : for k in range(start,end): if k not in l : print(k) flag=True break if flag : break start,end=start*10,end*10 l=[] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var length : int := ("" + ((n / 19)))->toInteger() + 1 ; if n > 19 & n mod 19 = 0 then ( length := length - 1 ) else skip ; var d : Sequence := Sequence{} ; for i : Integer.subrange(0, length-1) do ( d := d + ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var start : OclAny := null; var end : OclAny := null; Sequence{start,end} := Sequence{1,10} ; var l : Sequence := Sequence{} ; var flag : boolean := false ; for j : Integer.subrange(1, (d)->size() + 1-1) do ( for i : Integer.subrange(0, (d)->size()-1) do ( var tmp : String := StringLib.sumStringsWithSeparator(((d.subrange(i+1, i + j))->collect( _x | (OclType["String"])->apply(_x) )), '') ; if (tmp)->size() > 1 & tmp->first() = '0' then ( skip ) else (if (tmp)->size() = j then ( execute ((("" + ((tmp)))->toInteger()) : l) ) else skip)) ; l := Set{}->union((l))->sort() ; if start = 1 then ( for k : Integer.subrange(0, 10-1) do ( if (l)->excludes(k) then ( execute (k)->display() ; flag := true ; break ) else skip) ) else ( for k : Integer.subrange(start, end-1) do ( if (l)->excludes(k) then ( execute (k)->display() ; flag := true ; break ) else skip) ) ; if flag then ( break ) else skip ; var start : OclAny := null; var end : OclAny := null; Sequence{start,end} := Sequence{start * 10,end * 10} ; l := Sequence{}); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] while True : n=I() a=[] while len(a)pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var n : OclAny := I() ; var a : Sequence := Sequence{} ; while ((a)->size()->compareTo(n)) < 0 do ( a := a + LS()) ; s := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( execute ((("" + ((a[i+1])))->toInteger()) : s) ; for j : Integer.subrange(i + 1, Set{i + 2, n}->min()-1) do ( execute ((("" + ((a[i+1] + a[j+1])))->toInteger()) : s) ; for k : Integer.subrange(j + 1, Set{j + 2, n}->min()-1) do ( execute ((("" + ((a[i+1] + a[j+1] + a[k+1])))->toInteger()) : s)))) ; var r : int := -1 ; for i : Integer.subrange(0, 1000-1) do ( if not((s)->includes(i)) then ( r := i ; break ) else skip) ; execute ((r) : rr) ; break) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s1=list(input()) s2=list(input()) kind=0 next_step=0 pre=0 step=0 for _ in range(n): if next_step>n-1 : break w1=s1[next_step] w2=s2[next_step] if next_step>0 : if w1==w2 : next_step+=1 if pre==0 : kind*=2 else : kind*=1 pre=0 else : next_step+=2 if pre==0 : kind*=2 else : kind*=3 pre=1 else : if w1==w2 : kind+=3 next_step+=1 pre=0 else : kind+=6 next_step+=2 pre=1 mod=1000000007 print(kind % mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s1 : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var s2 : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var kind : int := 0 ; var next_step : int := 0 ; var pre : int := 0 ; var step : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( if (next_step->compareTo(n - 1)) > 0 then ( break ) else skip ; var w1 : OclAny := s1[next_step+1] ; var w2 : OclAny := s2[next_step+1] ; if next_step > 0 then ( if w1 = w2 then ( next_step := next_step + 1 ; if pre = 0 then ( kind := kind * 2 ) else ( kind := kind * 1 ) ; pre := 0 ) else ( next_step := next_step + 2 ; if pre = 0 then ( kind := kind * 2 ) else ( kind := kind * 3 ) ; pre := 1 ) ) else ( if w1 = w2 then ( kind := kind + 3 ; next_step := next_step + 1 ; pre := 0 ) else ( kind := kind + 6 ; next_step := next_step + 2 ; pre := 1 ) )) ; var mod : int := 1000000007 ; execute (kind mod mod)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : N,W=map(lambda x : int(x),input().split()) items=[[0,0]for _ in range(N)] for i in range(N): items[i]=list(map(lambda x : int(x),input().split())) items=sorted(items,key=lambda x :-x[0]/x[1]) total_value=0.0 total_weight=0.0 for(v,w)in items : if total_weight+w<=W : total_weight+=w total_value+=v if W==total_weight : break else : rest_weight=W-total_weight total_value+=(v/w)*rest_weight break print(f"{total_value:.6f}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var N : OclAny := null; var W : OclAny := null; Sequence{N,W} := (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ) ; var items : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Sequence{0}->union(Sequence{ 0 }))) ; for i : Integer.subrange(0, N-1) do ( items[i+1] := ((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ))) ; items := items->sortedBy($x | (lambda x : OclAny in (-x->first() / x[1+1]))->apply($x)) ; var total_value : double := 0.0 ; var total_weight : double := 0.0 ; for Sequence{v, w} : items do ( if (total_weight + w->compareTo(W)) <= 0 then ( total_weight := total_weight + w ; total_value := total_value + v ; if W = total_weight then ( break ) else skip ) else ( var rest_weight : double := W - total_weight ; total_value := total_value + (v / w) * rest_weight ; break )) ; execute (StringLib.formattedString("{total_value:.6f}"))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def toNum(lis): ret=0 for i in range(len(lis)): ret+=lis[-i-1]*10**i return ret def solve(list,n): c=0 i=0 digit=1 while i+digit<=n : if toNum(a[i : i+digit])==c : c+=1 digit=len(str(c)) i=0 continue else : i+=1 return c n=int(input()) a=[] while len(a)toInteger() ; var a : Sequence := Sequence{} ; while ((a)->size()->compareTo(n)) < 0 do ( a := a + input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))) ; execute (solve(a, n))->display(); operation toNum(lis : OclAny) : OclAny pre: true post: true activity: var ret : int := 0 ; for i : Integer.subrange(0, (lis)->size()-1) do ( ret := ret + lis->reverse()->at(-(-i - 1)) * (10)->pow(i)) ; return ret; operation solve(list : OclAny, n : OclAny) : OclAny pre: true post: true activity: var c : int := 0 ; var i : int := 0 ; var digit : int := 1 ; while (i + digit->compareTo(n)) <= 0 do ( if toNum(a.subrange(i+1, i + digit)) = c then ( c := c + 1 ; digit := (("" + ((c))))->size() ; i := 0 ; continue ) else ( i := i + 1 )) ; return c; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- j=''.join u=input n=int(u()) d=j(j(u().split())for i in[0]*(n//19+(n % 19!=0))) i=0 while 1 : if d.find(str(i))<0 : print(i) exit() i+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var j : OclAny := StringLib.sumStringsWithSeparator(.join`third, '') ; var u : OclAny := input ; var n : int := ("" + ((u())))->toInteger() ; var d : OclAny := j((argument (test (logical_test (comparison (expr (atom (name j)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name n))) // (expr (atom (number (integer 19))))) + (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (expr (atom (name n))) % (expr (atom (number (integer 19)))))) != (comparison (expr (atom (number (integer 0))))))))) )))))))) ))))))))) ; var i : int := 0 ; while 1 do ( if d->indexOf(("" + ((i)))) - 1 < 0 then ( execute (i)->display() ; exit() ) else skip ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input() a=[] for line in sys.stdin : a.extend([x for x in line.split()]) a="".join(a) for i in range(int(a)): if str(i)not in a : print(i) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; input() ; var a : Sequence := Sequence{} ; for line : OclFile["System.in"] do ( a := a->union(line.split()->select(x | true)->collect(x | (x)))) ; a := StringLib.sumStringsWithSeparator((a), "") ; for i : Integer.subrange(0, ("" + ((a)))->toInteger()-1) do ( if (a)->excludes(("" + ((i)))) then ( execute (i)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def containsElement(arr,n): xorArr=0 for i in range(n): xorArr ^=arr[i] for i in range(n): x=xorArr ^ arr[i] if(arr[i]==x): return True return False arr=[8,2,4,15,1] n=len(arr) if(containsElement(arr,n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{8}->union(Sequence{2}->union(Sequence{4}->union(Sequence{15}->union(Sequence{ 1 })))) ; n := (arr)->size() ; if (containsElement(arr, n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation containsElement(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var xorArr : int := 0 ; for i : Integer.subrange(0, n-1) do ( xorArr := xorArr xor arr[i+1]) ; for i : Integer.subrange(0, n-1) do ( var x : int := MathLib.bitwiseXor(xorArr, arr[i+1]) ; if (arr[i+1] = x) then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): N=24 RADIUS_SQUARED=2**(2*N-2) def compressed_length(xstart,xend,ystart,yend): if xstart*xstart+ystart*ystart>RADIUS_SQUARED : return 2 elif(xend-1)*(xend-1)+(yend-1)*(yend-1)<=RADIUS_SQUARED : return 2 else : xmid=(xstart+xend)>>1 ymid=(ystart+yend)>>1 return(1+compressed_length(xstart,xmid,ymid,yend)+compressed_length(xmid,xend,ymid,yend)+compressed_length(xstart,xmid,ystart,ymid)+compressed_length(xmid,xend,ystart,ymid)) temp=2**(N-1) return str(1+compressed_length(0,temp,0,temp)+compressed_length(0,temp,1,temp+1)+compressed_length(1,temp+1,0,temp)+compressed_length(1,temp+1,1,temp+1)) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var N : int := 24 ; var RADIUS_SQUARED : double := (2)->pow((2 * N - 2)) ; skip ; var temp : double := (2)->pow((N - 1)) ; return ("" + ((1 + compressed_length(0, temp, 0, temp) + compressed_length(0, temp, 1, temp + 1) + compressed_length(1, temp + 1, 0, temp) + compressed_length(1, temp + 1, 1, temp + 1)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def greaterK(n,k): index=0 p=[0 for i in range(n+2)] x=n while(x>0): p[index]=x % k x//=k index+=1 idx=0 for i in range(0,len(p)-1,1): if(p[i]>=2): p[i]=0 p[i+1]+=1 for j in range(idx,i,1): p[j]=0 idx=i+1 if(p[i]==k): p[i]=0 p[i+1]+=1 j=len(p)-1 if(p[j]>=2): p[index]=1 index+=1 ans=0 i=len(p)-1 while(i>=0): ans=ans*k+p[i] i-=1 print(ans) if __name__=='__main__' : n=29 k=7 greaterK(n,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 29 ; k := 7 ; greaterK(n, k) ) else skip; operation greaterK(n : OclAny, k : OclAny) pre: true post: true activity: var index : int := 0 ; var p : Sequence := Integer.subrange(0, n + 2-1)->select(i | true)->collect(i | (0)) ; var x : OclAny := n ; while (x > 0) do ( p[index+1] := x mod k ; x := x div k ; index := index + 1) ; var idx : int := 0 ; for i : Integer.subrange(0, (p)->size() - 1-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (p[i+1] >= 2) then ( p[i+1] := 0 ; p[i + 1+1] := p[i + 1+1] + 1 ; for j : Integer.subrange(idx, i-1)->select( $x | ($x - idx) mod 1 = 0 ) do ( p[j+1] := 0) ; idx := i + 1 ) else skip ; if (p[i+1] = k) then ( p[i+1] := 0 ; p[i + 1+1] := p[i + 1+1] + 1 ) else skip) ; var j : double := (p)->size() - 1 ; if (p[j+1] >= 2) then ( p[index+1] := 1 ; index := index + 1 ) else skip ; var ans : int := 0 ; var i : double := (p)->size() - 1 ; while (i >= 0) do ( ans := ans * k + p[i+1] ; i := i - 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect n=1000000 p=[1]*(n+1) p[0],p[1]=0,0 for i in range(2,int(n**0.5)+1): if p[i]: for j in range(i*i,n+1,i): p[j]=0 p=[i for i in range(n+1)if p[i]==1] while 1 : n=int(input()) ans=-n if n==0 : break while n : n-=1 a,m=map(int,input().split()) ans+=bisect.bisect_left(p,a+m+1)-bisect.bisect_left(p,a-m) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := 1000000 ; var p : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ; var p->first() : OclAny := null; var p[1+1] : OclAny := null; Sequence{p->first(),p[1+1]} := Sequence{0,0} ; for i : Integer.subrange(2, ("" + (((n)->pow(0.5))))->toInteger() + 1-1) do ( if p[i+1] then ( for j : Integer.subrange(i * i, n + 1-1)->select( $x | ($x - i * i) mod i = 0 ) do ( p[j+1] := 0) ) else skip) ; p := Integer.subrange(0, n + 1-1)->select(i | p[i+1] = 1)->collect(i | (i)) ; while 1 do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := -n ; if n = 0 then ( break ) else skip ; while n do ( n := n - 1 ; var a : OclAny := null; var m : OclAny := null; Sequence{a,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; ans := ans + bisect.bisect_left(p, a + m + 1) - bisect.bisect_left(p, a - m)) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect LENGTH=1000000 def eratosthenes(length): from math import sqrt def is_prime_number(num): limit=int(sqrt(num))+1 for lp in range(3,limit,2): if num % lp==0 : return False return True is_prime_number_list=[True]*(LENGTH+1) is_prime_number_list[0]=False is_prime_number_list[1]=False is_prime_number_list[2]=True for index in range(4,length+1,2): is_prime_number_list[index]=False limit=int(sqrt(length))+1 for lp in range(3,limit,2): if is_prime_number(lp): for index in range(lp*2,length+1,lp): is_prime_number_list[index]=False return is_prime_number_list is_prime_number_list=eratosthenes(LENGTH) prime_number_list=[index for index,item in enumerate(is_prime_number_list)if item] while True : input_count=int(input()) if input_count==0 : break pay=0 for _ in range(input_count): p,m=[int(item)for item in input().split(" ")] lower=p-m if 0size())->collect( _indx | Sequence{_indx-1, (is_prime_number_list)->at(_indx)} )->select(_tuple | let index : OclAny = _tuple->at(1) in let item : OclAny = _tuple->at(2) in item)->collect(_tuple | let index : OclAny = _tuple->at(1) in let item : OclAny = _tuple->at(2) in (index)) ; while true do ( var input_count : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if input_count = 0 then ( break ) else skip ; var pay : int := 0 ; for _anon : Integer.subrange(0, input_count-1) do ( var p : OclAny := null; var m : OclAny := null; Sequence{p,m} := input().split(" ")->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; var lower : double := if 0 < p - m then p - m else 0 endif ; var upper : OclAny := if (p + m->compareTo(LENGTH)) < 0 then p + m else LENGTH endif ; var lower_index : OclAny := bisect.bisect_left(prime_number_list, lower) ; var upper_index : OclAny := bisect.bisect_right(prime_number_list, upper) ; var prize : double := upper_index - lower_index ; pay := pay + prize - 1) ; execute (pay)->display()); operation eratosthenes(length : OclAny) : OclAny pre: true post: true activity: skip ; skip ; var is_prime_number_list : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (LENGTH + 1)) ; is_prime_number_list->first() := false ; is_prime_number_list[1+1] := false ; is_prime_number_list[2+1] := true ; for index : Integer.subrange(4, length + 1-1)->select( $x | ($x - 4) mod 2 = 0 ) do ( is_prime_number_list[index+1] := false) ; limit := ("" + ((sqrt(length))))->toInteger() + 1 ; for lp : Integer.subrange(3, limit-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if is_prime_number(lp) then ( for index : Integer.subrange(lp * 2, length + 1-1)->select( $x | ($x - lp * 2) mod lp = 0 ) do ( is_prime_number_list[index+1] := false) ) else skip) ; return is_prime_number_list; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000000 SQRT=1000 comp=[0]*(MAX+2) def sieve(): for i in range(3,SQRT,2): if comp[i]==0 : for j in range(i*i,MAX,i): comp[j]=1 sieve() tbl=[0]*(MAX+2) tbl[2]=k=1 for i in range(3,MAX,2): if comp[i]==0 : k+=1 tbl[i+1]=tbl[i]=k while 1 : n=int(input()) if n==0 : break ans=0 ; for i in range(n): p,m=map(int,input().split()) a,b=p-m,p+m if a<2 : a=2 if b>1000000 : b=1000000 ans+=tbl[b]-tbl[a-1]-1 ; if ans<0 : ans=0 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1000000 ; var SQRT : int := 1000 ; var comp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX + 2)) ; skip ; sieve() ; var tbl : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX + 2)) ; tbl[2+1] := 1; var k : int := 1 ; for i : Integer.subrange(3, MAX-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if comp[i+1] = 0 then ( k := k + 1 ) else skip ; tbl[i + 1+1] := k; var tbl[i+1] : OclAny := k) ; while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var ans : int := 0; ; for i : Integer.subrange(0, n-1) do ( var p : OclAny := null; var m : OclAny := null; Sequence{p,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{p - m,p + m} ; if a < 2 then ( var a : int := 2 ) else skip ; if b > 1000000 then ( var b : int := 1000000 ) else skip ; ans := ans + tbl[b+1] - tbl[a - 1+1] - 1;) ; if ans < 0 then ( ans := 0 ) else skip ; execute (ans)->display()); operation sieve() pre: true post: true activity: for i : Integer.subrange(3, SQRT-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if comp[i+1] = 0 then ( for j : Integer.subrange(i * i, MAX-1)->select( $x | ($x - i * i) mod i = 0 ) do ( comp[j+1] := 1) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- M=1000001 p=[1]*M p[0]=p[1]=0 for i in range(2,int(M**.5)+1): if p[i]: for j in range(i*i,M,i): p[j]=0 cs=[0]*M cur=0 for i in range(M): if p[i]: cur+=1 cs[i]=cur while 1 : N=int(input()) if N==0 : break ans=0 for i in range(N): p,m=map(int,input().split()) x=cs[min(p+m,M-1)]-cs[max(p-m-1,0)] if x : ans+=x-1 else : ans-=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var M : int := 1000001 ; var p : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, M) ; p->first() := 0; var p[1+1] : int := 0 ; for i : Integer.subrange(2, ("" + (((M)->pow(.5))))->toInteger() + 1-1) do ( if p[i+1] then ( for j : Integer.subrange(i * i, M-1)->select( $x | ($x - i * i) mod i = 0 ) do ( p[j+1] := 0) ) else skip) ; var cs : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, M) ; var cur : int := 0 ; for i : Integer.subrange(0, M-1) do ( if p[i+1] then ( cur := cur + 1 ) else skip ; cs[i+1] := cur) ; while 1 do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( var m : OclAny := null; Sequence{p,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : double := cs[Set{p->union(m), M - 1}->min()+1] - cs[Set{p - m - 1, 0}->max()+1] ; if x then ( ans := ans + x - 1 ) else ( ans := ans - 1 )) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,collections input=lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF=10**10 def I(): return int(input()) def F(): return float(input()) def SS(): 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 LSS(): return input().split() def resolve(): N,W=LI() vw=[LI()for _ in range(N)] vw.sort(key=lambda x : x[0]/x[1],reverse=True) ans=0 i=0 while i0 : ans+=vw[i][0] W-=vw[i][1] i+=1 if ipow(7)) ; var INF : double := (10)->pow(10) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( resolve() ) else skip; operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation SS() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation LI() : OclAny pre: true post: true activity: return input->apply().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return input->apply().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return input->apply().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LSS() : OclAny pre: true post: true activity: return input->apply().split(); operation resolve() pre: true post: true activity: var N : OclAny := null; var W : OclAny := null; Sequence{N,W} := LI() ; var vw : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (LI())) ; vw := vw->sort() ; var ans : int := 0 ; var i : int := 0 ; while (i->compareTo(N)) < 0 & W - vw[i+1][1+1] > 0 do ( ans := ans + vw[i+1]->first() ; W := W - vw[i+1][1+1] ; i := i + 1) ; if (i->compareTo(N)) < 0 then ( ans := ans + vw[i+1]->first() * W / vw[i+1][1+1] ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) print(a*b,2*(a+b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (a * b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate MAX=1000000 is_prime=[1]*MAX is_prime[0]=is_prime[1]=0 for i in range(2,int(MAX**(1/2))+1): if is_prime[i]: for j in range(i*i,MAX,i): is_prime[j]=0 acc_prime=list(accumulate(is_prime)) while True : n=int(input()) if n==0 : break ans=0 for _ in range(n): p,m=map(int,input().split()) ans+=acc_prime[min(p+m,MAX-1)]-acc_prime[max(0,p-m-1)]-1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MAX : int := 1000000 ; var is_prime : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, MAX) ; is_prime->first() := 0; var is_prime[1+1] : int := 0 ; for i : Integer.subrange(2, ("" + (((MAX)->pow((1 / 2)))))->toInteger() + 1-1) do ( if is_prime[i+1] then ( for j : Integer.subrange(i * i, MAX-1)->select( $x | ($x - i * i) mod i = 0 ) do ( is_prime[j+1] := 0) ) else skip) ; var acc_prime : Sequence := (accumulate(is_prime)) ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var ans : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var p : OclAny := null; var m : OclAny := null; Sequence{p,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; ans := ans + acc_prime[Set{p + m, MAX - 1}->min()+1] - acc_prime[Set{0, p - m - 1}->max()+1] - 1) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- D,points={},[25,18,15,12,10,8,6,4,2,1]+[0]*50 for tour in range(int(input())): for j in range(int(input())): player=str(input()) if player not in D : D[player]=[0]*51+[player] D[player][0]+=points[j] D[player][j+1]+=1 win=D.values() print(sorted(win)[-1][-1]) win=[[p[1]]+p for p in win] print(sorted(win)[-1][-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var D : OclAny := null; var points : OclAny := null; Sequence{D,points} := Sequence{Set{},Sequence{25}->union(Sequence{18}->union(Sequence{15}->union(Sequence{12}->union(Sequence{10}->union(Sequence{8}->union(Sequence{6}->union(Sequence{4}->union(Sequence{2}->union(Sequence{ 1 })))))))))->union(MatrixLib.elementwiseMult(Sequence{ 0 }, 50))} ; for tour : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( for j : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var player : String := ("" + (((OclFile["System.in"]).readLine()))) ; if (D)->excludes(player) then ( D->at(player) := MatrixLib.elementwiseMult(Sequence{ 0 }, 51)->union(Sequence{ player }) ) else skip ; D->at(player)->first() := D->at(player)->first() + points[j+1] ; D->at(player)[j + 1+1] := D->at(player)[j + 1+1] + 1)) ; var win : OclAny := D.values() ; execute (sorted(win)->last()->last())->display() ; win := win->select(p | true)->collect(p | (Sequence{ p[1+1] }->union(p))) ; execute (sorted(win)->last()->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d={} p=[25,18,15,12,10,8,6,4,2,1]+[0]*40 for _ in range(int(input())): for x in range((int(input()))): s=input() if s in d : d[s][0]+=p[x] d[s][x+1]+=1 else : d[s]=[p[x]]+[0]*50+[s] d[s][x+1]+=1 print(max(list(d.values()))[-1]) c=[] for x in d.values(): c.append([x[1]]+[x[0]]+x[2 :]) print(max(c)[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : OclAny := Set{} ; var p : Sequence := Sequence{25}->union(Sequence{18}->union(Sequence{15}->union(Sequence{12}->union(Sequence{10}->union(Sequence{8}->union(Sequence{6}->union(Sequence{4}->union(Sequence{2}->union(Sequence{ 1 })))))))))->union(MatrixLib.elementwiseMult(Sequence{ 0 }, 40)) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( for x : Integer.subrange(0, (("" + (((OclFile["System.in"]).readLine())))->toInteger())-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if (d)->includes(s) then ( d->at(s)->first() := d->at(s)->first() + p[x+1] ; d->at(s)[x + 1+1] := d->at(s)[x + 1+1] + 1 ) else ( d->at(s) := Sequence{ p[x+1] }->union(MatrixLib.elementwiseMult(Sequence{ 0 }, 50))->union(Sequence{ s }) ; d->at(s)[x + 1+1] := d->at(s)[x + 1+1] + 1 ))) ; execute (max((d.values()))->last())->display() ; var c : Sequence := Sequence{} ; for x : d.values() do ( execute ((Sequence{ x[1+1] }->union(Sequence{ x->first() })->union(x.subrange(2+1))) : c)) ; execute (max(c)->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()); l=list(map(int,input().split())) f=False for i in range(n-1): if l[i]<=l[i+1]: f=True ; break if f : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var f : boolean := false ; for i : Integer.subrange(0, n - 1-1) do ( if (l[i+1]->compareTo(l[i + 1+1])) <= 0 then ( f := true; break ) else skip) ; if f then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while(t!=0): n=int(input()) a=list(map(int,input().split())) i=1 count=0 while(itoInteger() ; while (t /= 0) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var i : int := 1 ; var count : int := 0 ; while ((i->compareTo(n)) < 0) do ( if ((a[i - 1+1]->compareTo(a[i+1])) <= 0) then ( count := 1 ; break ) else skip ; i := i + 1) ; if count = 1 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) l1=list(map(int,input().split())) y=True for k in range(0,n-1): if l1[k]>l1[k+1]: continue else : y=False break if y : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var y : boolean := true ; for k : Integer.subrange(0, n - 1-1) do ( if (l1[k+1]->compareTo(l1[k + 1+1])) > 0 then ( continue ) else ( y := false ; break )) ; if y then ( execute ("NO")->display() ) else ( execute ("YES")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for l in range(t): n=int(input()) listx=list(map(int,input().split())) lm=sorted(listx) lmr=lm[: :-1] if(lmr==listx and len(set(listx))==n): print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for l : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var listx : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lm : Sequence := listx->sort() ; var lmr : OclAny := lm(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; if (lmr = listx & (Set{}->union((listx)))->size() = n) then ( execute ("NO")->display() ) else ( execute ("YES")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): n=int(input()) a=input().split() for i in range(n): a[i]=int(a[i]) f=False for i in range(n-1): if(a[i]<=a[i+1]): f=True break if(f): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := input().split() ; for i : Integer.subrange(0, n-1) do ( a[i+1] := ("" + ((a[i+1])))->toInteger()) ; var f : boolean := false ; for i : Integer.subrange(0, n - 1-1) do ( if ((a[i+1]->compareTo(a[i + 1+1])) <= 0) then ( f := true ; break ) else skip) ; if (f) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from itertools import product sys.setrecursionlimit(10000) while True : W,H=map(int,input().split(' ')) if W==0 and H==0 : break m=tuple([list(map(int,input().split(' ')))for _ in range(H)]) def dfs(y,x): if m[y][x]==0 : return False else : m[y][x]=0 for dy,dx in product((-1,0,1),repeat=2): ny=y+dy nx=x+dx if 0<=nycollect( _x | (OclType["int"])->apply(_x) ) ; if W = 0 & H = 0 then ( break ) else skip ; var m : Sequence := (Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ))))) ; skip ; var count : int := 0 ; for i : Integer.subrange(0, H-1) do ( for j : Integer.subrange(0, W-1) do ( if m[i+1][j+1] = 1 then ( count := count + ("" + ((dfs(i, j))))->toInteger() ) else skip)) ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : print(int(eval(input()))) except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( execute (("" + (((OclFile["System.in"]).readLine())))->toInteger())->display()) catch (_e : OclException) do ( break) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : while 1 : w,h=list(map(int,input().strip().split())) if w==h==0 : break imap=[list(map(int,input().strip().split()))for _ in range(h)] visited=[] count=0 for j in range(h): for i in range(w): stack=[] if not(j,i)in visited and imap[j][i]==1 : count+=1 stack.append((j,i)) visited.append(((j,i))) while len(stack)!=0 : y,x=stack.pop() for dx in[-1,0,1]: for dy in[-1,0,1]: if 0<=x+dxtrim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if w = h & (h == 0) then ( break ) else skip ; var imap : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var visited : Sequence := Sequence{} ; var count : int := 0 ; for j : Integer.subrange(0, h-1) do ( for i : Integer.subrange(0, w-1) do ( var stack : Sequence := Sequence{} ; if not((visited)->includes(Sequence{j, i})) & imap[j+1][i+1] = 1 then ( count := count + 1 ; execute ((Sequence{j, i}) : stack) ; execute (((Sequence{j, i})) : visited) ) else skip ; while (stack)->size() /= 0 do ( var y : OclAny := null; var x : OclAny := null; Sequence{y,x} := stack->last() ; stack := stack->front() ; for dx : Sequence{-1}->union(Sequence{0}->union(Sequence{ 1 })) do ( for dy : Sequence{-1}->union(Sequence{0}->union(Sequence{ 1 })) do ( if 0 <= x + dx & (x + dx < w) & 0 <= y + dy & (y + dy < h) & not((visited)->includes(Sequence{y + dy, x + dx})) then ( if imap[y + dy+1][x + dx+1] = 1 then ( execute ((Sequence{y + dy, x + dx}) : stack) ; execute (((Sequence{y + dy, x + dx})) : visited) ) else skip ) else skip))))) ; execute (count)->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- line=input().split(" ") a=int(line[0]) b=int(line[1]) area=a*b leng=2*(a+b) print(str(area)+" "+str(leng)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var line : OclAny := input().split(" ") ; var a : int := ("" + ((line->first())))->toInteger() ; var b : int := ("" + ((line[1+1])))->toInteger() ; var area : int := a * b ; var leng : int := 2 * (a + b) ; execute (("" + ((area))) + " " + ("" + ((leng))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import queue def main(): count_list=[] w,h=map(int,input().split()) while not(w==0 and h==0): data=[] count=0 for _ in range(h): data.append(list(map(int,input().split()))) for row,i in zip(data,range(len(data))): for cell,j in zip(row,range(len(row))): if cell==1 : fill_sea(data,j,i,w,h) count+=1 w,h=map(int,input().split()) count_list.append(count) for i in count_list : print(i) def fill_sea(data,x,y,w,h): q=queue.LifoQueue() q.put((x,y)) while not q.empty(): current_cell=q.get() data[current_cell[1]][current_cell[0]]=0 for i in[-1,0,1]: if current_cell[1]+i<=-1 or current_cell[1]+i>=h : continue for j in[-1,0,1]: if i==0 and j==0 : continue if current_cell[0]+j<=-1 or current_cell[0]+j>=w : continue if data[current_cell[1]+i][current_cell[0]+j]==1 : q.put((current_cell[0]+j,current_cell[1]+i)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var count_list : Sequence := Sequence{} ; var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; while not((w = 0 & h = 0)) do ( var data : Sequence := Sequence{} ; var count : int := 0 ; for _anon : Integer.subrange(0, h-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : data)) ; for _tuple : Integer.subrange(1, data->size())->collect( _indx | Sequence{data->at(_indx), Integer.subrange(0, (data)->size()-1)->at(_indx)} ) do (var _indx : int := 1; var row : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); for _tuple : Integer.subrange(1, row->size())->collect( _indx | Sequence{row->at(_indx), Integer.subrange(0, (row)->size()-1)->at(_indx)} ) do (var _indx : int := 1; var cell : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if cell = 1 then ( fill_sea(data, j, i, w, h) ; count := count + 1 ) else skip)) ; var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((count) : count_list)) ; for i : count_list do ( execute (i)->display()); operation fill_sea(data : OclAny, x : OclAny, y : OclAny, w : OclAny, h : OclAny) pre: true post: true activity: var q : OclAny := queue.LifoQueue() ; q.put(Sequence{x, y}) ; while not(q.empty()) do ( var current_cell : OclAny := q.get() ; data[current_cell[1+1]+1][current_cell->first()+1] := 0 ; for i : Sequence{-1}->union(Sequence{0}->union(Sequence{ 1 })) do ( if current_cell[1+1] + i <= -1 or (current_cell[1+1] + i->compareTo(h)) >= 0 then ( continue ) else skip ; for j : Sequence{-1}->union(Sequence{0}->union(Sequence{ 1 })) do ( if i = 0 & j = 0 then ( continue ) else skip ; if current_cell->first() + j <= -1 or (current_cell->first() + j->compareTo(w)) >= 0 then ( continue ) else skip ; if data[current_cell[1+1] + i+1][current_cell->first() + j+1] = 1 then ( q.put(Sequence{current_cell->first() + j, current_cell[1+1] + i}) ) else skip))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def dfs(G,v,h,w): stack=deque([v]) connected=set([v]) while stack : u=stack.popleft() x,y=u dx=[-1,0,1] dy=[-1,0,1] for i in range(3): for j in range(3): s=x+dx[i] t=y+dy[j] if 0<=s=0 and w>=0 : w,h=map(int,input().split(" ")) if h==w==0 : return C=[list(map(int,input().split(" ")))for _ in range(h)] solve(C,h,w) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation dfs(G : OclAny, v : OclAny, h : OclAny, w : OclAny) : OclAny pre: true post: true activity: var stack : Sequence := (Sequence{ v }) ; var connected : Set := Set{}->union((Sequence{ v })) ; while stack do ( var u : OclAny := stack->first() ; stack := stack->tail() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := u ; var dx : Sequence := Sequence{-1}->union(Sequence{0}->union(Sequence{ 1 })) ; var dy : Sequence := Sequence{-1}->union(Sequence{0}->union(Sequence{ 1 })) ; for i : Integer.subrange(0, 3-1) do ( for j : Integer.subrange(0, 3-1) do ( var s : OclAny := x + dx[i+1] ; var t : OclAny := y + dy[j+1] ; if 0 <= s & (s < h) & 0 <= t & (t < w) then ( if G[s+1][t+1] = 1 then ( if (connected)->excludes(Sequence{s, t}) then ( stack := stack->prepend(Sequence{s, t}) ; execute ((Sequence{s, t}) : connected) ) else skip ) else skip ) else skip))) ; return connected; operation solve(C : OclAny, h : OclAny, w : OclAny) pre: true post: true activity: var node : Set := Set{}->union(()) ; var ans : int := 0 ; for i : Integer.subrange(0, h-1) do ( for j : Integer.subrange(0, w-1) do ( if C[i+1][j+1] = 1 & (node)->excludes(Sequence{i, j}) then ( node := MathLib.bitwiseOr(node, dfs(C, Sequence{i, j}, h, w)) ; ans := ans + 1 ) else skip)) ; execute (ans)->display(); operation main() pre: true post: true activity: h := 0 ; w := 0 ; while h >= 0 & w >= 0 do ( Sequence{w,h} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; if h = w & (w == 0) then ( return ) else skip ; C := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )))) ; solve(C, h, w)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import queue def proceess(start_x,start_y): new_island=queue.Queue() map[start_x][start_y]=0 new_island.put([start_x,start_y]) while True : ob=new_island.get() x=ob[0] y=ob[1] for i in[-1,0,1]: for j in[-1,0,1]: nx=x+i ny=y+j if nx>=0 and ny>=0 and nxfirst())))->toInteger() ; var h : int := ("" + ((tmp[1+1])))->toInteger() ; if w = 0 & h = 0 then ( break ) else skip ; for j : Integer.subrange(0, h-1) do ( var nova : Sequence := Sequence{} ; var arm : String := (OclFile["System.in"]).readLine() ; for k : arm.split(" ") do ( execute ((("" + ((k)))->toInteger()) : nova)) ; execute ((nova) : map)) ; var count : int := 0 ; for i : Integer.subrange(0, h-1) do ( for j : Integer.subrange(0, w-1) do ( if map[i+1][j+1] = 1 then ( proceess(i, j) ; count := count + 1 ) else skip)) ; execute (count)->display()); operation proceess(start_x : OclAny, start_y : OclAny) pre: true post: true activity: var new_island : OclAny := queue.Queue() ; map[start_x+1][start_y+1] := 0 ; new_island.put(Sequence{start_x}->union(Sequence{ start_y })) ; while true do ( var ob : OclAny := new_island.get() ; var x : OclAny := ob->first() ; var y : OclAny := ob[1+1] ; for i : Sequence{-1}->union(Sequence{0}->union(Sequence{ 1 })) do ( for j : Sequence{-1}->union(Sequence{0}->union(Sequence{ 1 })) do ( var nx : OclAny := x + i ; var ny : OclAny := y + j ; if nx >= 0 & ny >= 0 & (nx->compareTo(h)) < 0 & (ny->compareTo(w)) < 0 then ( if map[nx+1][ny+1] = 1 then ( new_island.put(Sequence{nx}->union(Sequence{ ny })) ; map[nx+1][ny+1] := 0 ) else skip ) else skip)) ; if new_island.empty() then ( break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findCost(str,arr,n): costofC,costofO=0,0 costofD,costofE=0,0 for i in range(n): if(str[i]=='c'): costofC+=arr[i] elif(str[i]=='o'): costofO=min(costofC,costofO+arr[i]) elif(str[i]=='d'): costofD=min(costofO,costofD+arr[i]) elif(str[i]=='e'): costofE=min(costofD,costofE+arr[i]) return costofE if __name__=='__main__' : str="geekcodergeeks" arr=[1,2,1,3,4,2,6,4,6,2,3,3,3,2] n=len(arr) print(findCost(str,arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( OclType["String"] := "geekcodergeeks" ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{3}->union(Sequence{4}->union(Sequence{2}->union(Sequence{6}->union(Sequence{4}->union(Sequence{6}->union(Sequence{2}->union(Sequence{3}->union(Sequence{3}->union(Sequence{3}->union(Sequence{ 2 }))))))))))))) ; n := (arr)->size() ; execute (findCost(OclType["String"], arr, n))->display() ) else skip; operation findCost(OclType["String"] : OclAny, arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var costofC : OclAny := null; var costofO : OclAny := null; Sequence{costofC,costofO} := Sequence{0,0} ; var costofD : OclAny := null; var costofE : OclAny := null; Sequence{costofD,costofE} := Sequence{0,0} ; for i : Integer.subrange(0, n-1) do ( if (("" + ([i+1])) = 'c') then ( costofC := costofC + arr[i+1] ) else (if (("" + ([i+1])) = 'o') then ( var costofO : OclAny := Set{costofC, costofO + arr[i+1]}->min() ) else (if (("" + ([i+1])) = 'd') then ( var costofD : OclAny := Set{costofO, costofD + arr[i+1]}->min() ) else (if (("" + ([i+1])) = 'e') then ( var costofE : OclAny := Set{costofD, costofE + arr[i+1]}->min() ) else skip ) ) ) ) ; return costofE; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): a,b,c=map(int,input().split()) print("1"+"0"*(a-1),"1"*(b-c+1)+"0"*(c-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ("1" + StringLib.nCopies("0", (a - 1)))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): a,b,c=map(int,input().split()) print(10**(a-1)+10**(c-1),10**(b-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((10)->pow((a - 1)) + (10)->pow((c - 1)))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for t in range(T): a,b,c=map(int,input().split()) print("1"+"0"*(a-1),"1"*(b-c+1)+"0"*(c-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(0, T-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ("1" + StringLib.nCopies("0", (a - 1)))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): a,b,c=map(int,input().split()) print("1"+"0"*(a-1),"1"*(b-c+1)+"0"*(c-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ("1" + StringLib.nCopies("0", (a - 1)))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- readline=open(0).readline N,W=map(int,readline().split()) R=[] for i in range(N): v,w=map(int,readline().split()) R.append((v/w,v,w)) R.sort(reverse=1) ans=0 for _,v,w,in R : c=min(w,W) W-=c ans+=c*v/w open(1,'w').write("%.010f\n" % ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var readline : OclAny := open(0).readline ; var N : OclAny := null; var W : OclAny := null; Sequence{N,W} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var R : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var v : OclAny := null; var w : OclAny := null; Sequence{v,w} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{v / w, v, w}) : R)) ; R := R->sort() ; var ans : int := 0 ; for _tuple : R do (var _indx : int := 1; var _anon : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; (tupleDeclarations (expr (atom (name w))) ,) var c : OclAny := Set{w, W}->min() ; W := W - c ; ans := ans + c * v / w) ; (expr (atom (name open)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom 'w'))))))) ))) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom "%.010f\n")) % (expr (atom (name ans))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def solve(): a,b,c=map(int,input().split()) cnt1,cnt2=a-(c-1),b-(c-1) gcd=10**(c-1) X=Y=1 while len(str(X))toInteger()-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name solve)) (trailer (arguments ( )))))))))->display()); operation solve() : OclAny pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cnt1 : OclAny := null; var cnt2 : OclAny := null; Sequence{cnt1,cnt2} := Sequence{a - (c - 1),b - (c - 1)} ; var gcd : double := (10)->pow((c - 1)) ; var X : OclAny := 1; var Y : int := 1 ; while ((("" + ((X))))->size()->compareTo(cnt1)) < 0 do ( X := X * 2) ; while ((("" + ((Y))))->size()->compareTo(cnt2)) < 0 do ( Y := Y * 3) ; return X * gcd, Y * gcd; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(25) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (25)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- str=input() numlist=str.split(' ') a=int(numlist[0]) b=int(numlist[1]) print("{0}{1}".format(a*b,2*(a+b))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var OclType["String"] : String := (OclFile["System.in"]).readLine() ; var numlist : String := ("" + (.split(' '))) ; var a : int := ("" + ((numlist->first())))->toInteger() ; var b : int := ("" + ((numlist[1+1])))->toInteger() ; execute (StringLib.interpolateStrings("{0}{1}", Sequence{a * b, 2 * (a + b)}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) print(25) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (25)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if 2<=n and n<=(2*(10**18)): print(25) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if 2 <= n & (n->compareTo((2 * ((10)->pow(18))))) <= 0 then ( execute (25)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) if k*2>=(n-1)*n : print('no solution') else :[print(0,i)for i in range(n)] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (k * 2->compareTo((n - 1) * n)) >= 0 then ( execute ('no solution')->display() ) else ( ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) print(["\n".join("0 "+str(i)for i in range(n)),"no solution"][(n-1)*n<=k*2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Sequence{StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (expr (atom "0 ")) + (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))), "\n")}->union(Sequence{ "no solution" })->select(((n - 1) * n->compareTo(k * 2)) <= 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- try : import sys from functools import lru_cache,cmp_to_key from heapq import merge,heapify,heappop,heappush from math import* from collections import defaultdict as dd,deque,Counter as C from itertools import combinations as comb,permutations as perm from bisect import bisect_left as bl,bisect_right as br,bisect,insort from time import perf_counter from fractions import Fraction import copy from copy import deepcopy import time starttime=time.time() mod=int(pow(10,9)+7) mod2=998244353 def data(): return sys.stdin.readline().strip() def out(*var,end="\n"): sys.stdout.write(' '.join(map(str,var))+end) def L(): return list(sp()) def sl(): return list(ssp()) def sp(): return map(int,data().split()) def ssp(): return map(str,data().split()) def l1d(n,val=0): return[val for i in range(n)] def l2d(n,m,val=0): return[l1d(n,val)for j in range(m)] sys.stdin=open("input.txt","r") sys.stdout=open("output.txt","w") except : pass n,k=L() if n*(n-1)//2<=k : print("no solution") else : for i in range(n): print(0,i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: try ( skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var starttime : OclAny := time.time() ; var mod : int := ("" + (((10)->pow(9) + 7)))->toInteger() ; var mod2 : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt"))) catch (_e : OclException) do ( skip) ; var k : OclAny := null; Sequence{n,k} := L() ; if (n * (n - 1) div 2->compareTo(k)) <= 0 then ( execute ("no solution")->display() ) else ( for i : Integer.subrange(0, n-1) do ( execute (0)->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) if k>=(n*(n-1))/2 : print('no solution') else : for _ in range(n): print(0,_) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (k->compareTo((n * (n - 1)) / 2)) >= 0 then ( execute ('no solution')->display() ) else ( for _anon : Integer.subrange(0, n-1) do ( execute (0)->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from sys import stdin,stdout def get_ints_in_variables(): return map(int,sys.stdin.readline().strip().split()) def get_int(): return int(input()) def get_ints_in_list(): return list(map(int,sys.stdin.readline().strip().split())) def get_list_of_list(n): return[list(map(int,sys.stdin.readline().strip().split()))for _ in range(n)] def get_string(): return sys.stdin.readline().strip() def main(): n,k=get_ints_in_variables() if k*2>=n*(n-1): print("no solution") else : for i in range(0,n): print(0,i) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation get_ints_in_variables() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ); operation get_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation get_ints_in_list() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation get_list_of_list(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )))); operation get_string() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation main() pre: true post: true activity: var k : OclAny := null; Sequence{n,k} := get_ints_in_variables() ; if (k * 2->compareTo(n * (n - 1))) >= 0 then ( execute ("no solution")->display() ) else ( for i : Integer.subrange(0, n-1) do ( execute (0)->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getMaxLength(arr,n): start=0 preCnt=0 while(start=0 and arr[end]==1): suffCnt=suffCnt+1 end=end-1 if(start>end): return n midCnt=0 i=start result=0 while(i<=end): if(arr[i]==1): midCnt=midCnt+1 result=max(result,midCnt) else : midCnt=0 i=i+1 return max(result,preCnt+suffCnt) if __name__=='__main__' : arr=[1,1,0,0,1,0,1,0,1,1,1,1] n=len(arr) print(getMaxLength(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))))))))))) ; n := (arr)->size() ; execute (getMaxLength(arr, n))->display() ) else skip; operation getMaxLength(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var start : int := 0 ; var preCnt : int := 0 ; while ((start->compareTo(n)) < 0 & arr[start+1] = 1) do ( preCnt := preCnt + 1 ; start := start + 1) ; var end : double := n - 1 ; var suffCnt : int := 0 ; while (end >= 0 & arr[end+1] = 1) do ( suffCnt := suffCnt + 1 ; end := end - 1) ; if ((start->compareTo(end)) > 0) then ( return n ) else skip ; var midCnt : int := 0 ; var i : int := start ; var result : int := 0 ; while ((i->compareTo(end)) <= 0) do ( if (arr[i+1] = 1) then ( midCnt := midCnt + 1 ; result := Set{result, midCnt}->max() ) else ( midCnt := 0 ) ; i := i + 1) ; return Set{result, preCnt + suffCnt}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,W=[int(i)for i in input().split()] VW=[[int(i)for i in input().split()]for _ in range(N)] sVW=sorted(VW,key=lambda x : x[0]/x[1],reverse=True) ans=0 for i in sVW : if Wselect(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var VW : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())))) ; var sVW : Sequence := VW->sortedBy($x | (lambda x : OclAny in (x->first() / x[1+1]))->apply($x)) ; var ans : int := 0 ; for i : sVW do ( if (W->compareTo(i[1+1])) < 0 then ( ans := ans + i->first() * W / i[1+1] ; break ) else ( ans := ans + i->first() ; W := W - i[1+1] )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) if a<=b and a<=c : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(b)) <= 0 & (a->compareTo(c)) <= 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- arr=[int(num)for num in input().split()] n=arr[0] m=arr[1] k=arr[2] if n<=min(m,k): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var arr : Sequence := input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var n : OclAny := arr->first() ; var m : OclAny := arr[1+1] ; var k : OclAny := arr[2+1] ; if (n->compareTo(Set{m, k}->min())) <= 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=list(map(int,input().split())) if n<=m and n<=k : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (n->compareTo(m)) <= 0 & (n->compareTo(k)) <= 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split(" ")) area=a*b perimeter=2*a+2*b print("%d %d" %(area,perimeter)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var area : double := a * b ; var perimeter : double := 2 * a + 2 * b ; execute (StringLib.format("%d %d",Sequence{area, perimeter}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) if(m>=n)and(k>=n): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if ((m->compareTo(n)) >= 0) & ((k->compareTo(n)) >= 0) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=list(map(int,input().split())) if(n<=m and n<=k): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if ((n->compareTo(m)) <= 0 & (n->compareTo(k)) <= 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def executer_calcul(entrees): J=entrees[0] P=entrees[1] S=entrees[2] K=entrees[3] Case=entrees[4] if(K>S): K=S if(P>=K): S=P result=str(J*P*K) for j in range(J): for p in range(P): for k in range(K): result=result+'\n'+str(j+1)+' '+str(p+1)+' '+str((p+j+k)% S+1) return result multiprocessed=False if(multiprocessed): from multiprocessing import Pool else : output=open('Output.txt','w') if((not multiprocessed)or __name__=='__main__'): with open("Input.txt","r")as input : lines=input.readlines() T=int(lines[0]) line=1 Case=1 calculs=[] while(linefirst())))->toInteger() ; var line : int := 1 ; Case := 1 ; var calculs : Sequence := Sequence{} ; while ((line->compareTo((lines)->size())) < 0) do ( Sequence{J,P,S,K} := (lines[line+1].split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; line := line + 1 ; entrees := Sequence{J}->union(Sequence{P}->union(Sequence{S}->union(Sequence{K}->union(Sequence{ Case })))) ; if (not(multiprocessed)) then ( output.write('Case #' + ("" + ((Case))) + ': ' + executer_calcul(entrees) + ' ') ) else ( execute ((entrees) : calculs) ) ; Case := Case + 1) ; if (multiprocessed) then ( var pool : OclAny := Pool(3) ; var results : OclAny := pool.map(executer_calcul, calculs) ; output := OclFile.newOclFile_Write(OclFile.newOclFile('Output.txt')) ; for case : Integer.subrange(0, (results)->size()-1) do ( output.write('Case #' + ("" + ((case + 1))) + ': ' + results[case+1] + ' ')) ) else skip ; output.closeFile() ) else skip; operation executer_calcul(entrees : OclAny) : OclAny pre: true post: true activity: var J : OclAny := entrees->first() ; var P : OclAny := entrees[1+1] ; var S : OclAny := entrees[2+1] ; var K : OclAny := entrees[3+1] ; var Case : OclAny := entrees[4+1] ; if ((K->compareTo(S)) > 0) then ( K := S ) else skip ; if ((P->compareTo(K)) >= 0) then ( S := P ) else skip ; var result : String := ("" + ((J * P * K))) ; for j : Integer.subrange(0, J-1) do ( for p : Integer.subrange(0, P-1) do ( for k : Integer.subrange(0, K-1) do ( result := result + ' ' + ("" + ((j + 1))) + ' ' + ("" + ((p + 1))) + ' ' + ("" + (((p + j + k) mod S + 1)))))) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for TT in range(1,T+1): J,P,S,K=(int(x)for x in input().split()) m=min(S,K) ans=J*P*m print('Case #{}:{}'.format(TT,ans)) for j in range(J): for p in range(P): for s in range(m): t=(j+p+s)% S print(j+1,p+1,t+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for TT : Integer.subrange(1, T + 1-1) do ( var J : OclAny := null; var P : OclAny := null; var S : OclAny := null; var K : OclAny := null; Sequence{J,P,S,K} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var m : OclAny := Set{S, K}->min() ; var ans : double := J * P * m ; execute (StringLib.interpolateStrings('Case #{}:{}', Sequence{TT, ans}))->display() ; for j : Integer.subrange(0, J-1) do ( for p : Integer.subrange(0, P-1) do ( for s : Integer.subrange(0, m-1) do ( var t : int := (j + p + s) mod S ; execute (j + 1)->display())))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): print("Case #"+str(i+1)+":",end=" ") j,p,s,k=map(int,input().split()) print(j*p*min(s,k)) u=min(s,k) for a in range(j): for b in range(p): for r in range(u): c=(a+b+r)% s print(a+1,b+1,c+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( execute ("Case #" + ("" + ((i + 1))) + ":")->display() ; var j : OclAny := null; var p : OclAny := null; var s : OclAny := null; var k : OclAny := null; Sequence{j,p,s,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (j * p * Set{s, k}->min())->display() ; var u : OclAny := Set{s, k}->min() ; for a : Integer.subrange(0, j-1) do ( for b : Integer.subrange(0, p-1) do ( for r : Integer.subrange(0, u-1) do ( var c : int := (a + b + r) mod s ; execute (a + 1)->display())))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import* def solve(J,P,S,K): Q=set() A=defaultdict(int) B=defaultdict(int) C=defaultdict(int) for j in range(J): for p in range(P): for s in range(min(S,K)): d=(j+p+s)% S Q.add((j,p,d)) A[(j,p)]+=1 B[(p,d)]+=1 C[(d,j)]+=1 assert(max(A.values())<=K) assert(max(B.values())<=K) assert(max(C.values())<=K) assert(len(Q)==J*P*min(S,K)) return Q def test(): for k in range(1,11): for s in range(1,11): for p in range(1,s+1): for j in range(1,p+1): solve(j,p,s,k) T=int(input()) for t in range(T): J,P,S,K=map(int,input().split()) Q=solve(J,P,S,K) print("Case #%d: %d" %(t+1,len(Q))) for q in Q : print(q[0]+1,q[1]+1,q[2]+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(0, T-1) do ( Sequence{J,P,S,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; Q := solve(J, P, S, K) ; execute (StringLib.format("Case #%d: %d",Sequence{t + 1, (Q)->size()}))->display() ; for q : Q do ( execute (q->first() + 1)->display())); operation solve(J : OclAny, P : OclAny, S : OclAny, K : OclAny) : OclAny pre: true post: true activity: var Q : Set := Set{}->union(()) ; var A : OclAny := defaultdict(OclType["int"]) ; var B : OclAny := defaultdict(OclType["int"]) ; var C : OclAny := defaultdict(OclType["int"]) ; for j : Integer.subrange(0, J-1) do ( for p : Integer.subrange(0, P-1) do ( for s : Integer.subrange(0, Set{S, K}->min()-1) do ( var d : int := (j + p + s) mod S ; execute ((Sequence{j, p, d}) : Q) ; A[Sequence{j, p}+1] := A[Sequence{j, p}+1] + 1 ; B[Sequence{p, d}+1] := B[Sequence{p, d}+1] + 1 ; C[Sequence{d, j}+1] := C[Sequence{d, j}+1] + 1))) ; assert (((A.values())->max()->compareTo(K)) <= 0) do "assertion failed" ; assert (((B.values())->max()->compareTo(K)) <= 0) do "assertion failed" ; assert (((C.values())->max()->compareTo(K)) <= 0) do "assertion failed" ; assert ((Q)->size() = J * P * Set{S, K}->min()) do "assertion failed" ; return Q; operation test() pre: true post: true activity: for k : Integer.subrange(1, 11-1) do ( for s : Integer.subrange(1, 11-1) do ( for p : Integer.subrange(1, s + 1-1) do ( for j : Integer.subrange(1, p + 1-1) do ( solve(j, p, s, k))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getSingle(arr,n): ones=0 twos=0 for i in range(n): twos=twos |(ones & arr[i]) ones=ones ^ arr[i] common_bit_mask=~(ones & twos) ones &=common_bit_mask twos &=common_bit_mask return ones arr=[3,3,2,3] n=len(arr) print("The element with single occurrence is ",getSingle(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{3}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 3 }))) ; n := (arr)->size() ; execute ("The element with single occurrence is ")->display(); operation getSingle(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ones : int := 0 ; var twos : int := 0 ; for i : Integer.subrange(0, n-1) do ( twos := MathLib.bitwiseOr(twos, (MathLib.bitwiseAnd(ones, arr[i+1]))) ; ones := MathLib.bitwiseXor(ones, arr[i+1]) ; var common_bit_mask : int := MathLib.bitwiseNot((MathLib.bitwiseAnd(ones, twos))) ; ones := ones & common_bit_mask ; twos := twos & common_bit_mask) ; return ones; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for case in range(1,T+1): t=input().split() J=int(t[0]) P=int(t[1]) S=int(t[2]) K=int(t[3]) print("Case #{0}:{1}".format(case,J*P*min(S,K))) offset=0 for i in range(1,J+1): offset+=1 now=offset for j in range(1,P+1): for k in range(min(S,K)): now=now % S+1 print(' '.join([str(i),str(j),str(now)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for case : Integer.subrange(1, T + 1-1) do ( var t : OclAny := input().split() ; var J : int := ("" + ((t->first())))->toInteger() ; var P : int := ("" + ((t[1+1])))->toInteger() ; var S : int := ("" + ((t[2+1])))->toInteger() ; var K : int := ("" + ((t[3+1])))->toInteger() ; execute (StringLib.interpolateStrings("Case #{0}:{1}", Sequence{case, J * P * Set{S, K}->min()}))->display() ; var offset : int := 0 ; for i : Integer.subrange(1, J + 1-1) do ( offset := offset + 1 ; var now : int := offset ; for j : Integer.subrange(1, P + 1-1) do ( for k : Integer.subrange(0, Set{S, K}->min()-1) do ( now := now mod S + 1 ; execute (StringLib.sumStringsWithSeparator((Sequence{("" + ((i)))}->union(Sequence{("" + ((j)))}->union(Sequence{ ("" + ((now))) }))), ' '))->display())))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() k=s.count('0') s=''.join(sorted(s))[k :] print(['WRONG_ANSWER','OK'][input()==('0' if s=='' else s[0]+'0'*k+s[1 :])]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var k : int := s->count('0') ; s := ''.join(s->sort()).subrange(k+1) ; execute (Sequence{'WRONG_ANSWER'}->union(Sequence{ 'OK' })->select((OclFile["System.in"]).readLine() = (if s = '' then '0' else s->first() + StringLib.nCopies('0', k) + s->tail() endif)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=(input()) y=(input()) l=[] s='' for i in range(len(x)): l.append(int(x[i])) l.sort() if len(l)>1 and l[0]==0 : l[1],l[0]=l[0],l[1] for i in range(len(l)): s+=str(l[i]) if s==y : print('OK') if s!=y : print('WRONG_ANSWER') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := ((OclFile["System.in"]).readLine()) ; var y : String := ((OclFile["System.in"]).readLine()) ; var l : Sequence := Sequence{} ; var s : String := '' ; for i : Integer.subrange(0, (x)->size()-1) do ( execute ((("" + ((x[i+1])))->toInteger()) : l)) ; l := l->sort() ; if (l)->size() > 1 & l->first() = 0 then ( var l[1+1] : OclAny := null; var l->first() : OclAny := null; Sequence{l[1+1],l->first()} := Sequence{l->first(),l[1+1]} ) else skip ; for i : Integer.subrange(0, (l)->size()-1) do ( s := s + ("" + ((l[i+1])))) ; if s = y then ( execute ('OK')->display() ) else skip ; if s /= y then ( execute ('WRONG_ANSWER')->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=input() if a=='0' and b=='0' : print('OK') exit() c=[] for i in a : c.append(i) c.sort() d='' for i in c : d+=i if c[0]=='0' : if len(d)>1 : e=d[1]+d[0]+d[2 :] if e[0]=='0' : print('WRONG_ANSWER') elif e==b : print('OK') else : print('WRONG_ANSWER') else : print('WRONG_ANSWER') else : if d==b : print('OK') else : print('WRONG_ANSWER') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; if a = '0' & b = '0' then ( execute ('OK')->display() ; exit() ) else skip ; var c : Sequence := Sequence{} ; for i : a->characters() do ( execute ((i) : c)) ; c := c->sort() ; var d : String := '' ; for i : c do ( d := d + i) ; if c->first() = '0' then ( if (d)->size() > 1 then ( var e : OclAny := d[1+1] + d->first() + d.subrange(2+1) ; if e->first() = '0' then ( execute ('WRONG_ANSWER')->display() ) else (if e = b then ( execute ('OK')->display() ) else ( execute ('WRONG_ANSWER')->display() ) ) ) else ( execute ('WRONG_ANSWER')->display() ) ) else ( if d = b then ( execute ('OK')->display() ) else ( execute ('WRONG_ANSWER')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys (a,b)=map(int,input().split()) print(a*b,(a+b)*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var Sequence{a, b} : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (a * b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() m=input() ln=list(n) lm=list(m) ln.sort() for i in range(len(ln)): if ln[i]!='0' : a=i break if(len(lm)==len(ln)and len(ln)==1): if(n!=m): print("WRONG_ANSWER") else : print("OK") elif(lm[0]=='0'): print("WRONG_ANSWER") else : if(ln[0]=='0'): ln[0],ln[a]=ln[a],ln[0] sn="".join(ln) sm="".join(lm) if(sn==sm): print("OK") else : print("WRONG_ANSWER") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var m : String := (OclFile["System.in"]).readLine() ; var ln : Sequence := (n)->characters() ; var lm : Sequence := (m)->characters() ; ln := ln->sort() ; for i : Integer.subrange(0, (ln)->size()-1) do ( if ln[i+1] /= '0' then ( var a : OclAny := i ; break ) else skip) ; if ((lm)->size() = (ln)->size() & (ln)->size() = 1) then ( if (n /= m) then ( execute ("WRONG_ANSWER")->display() ) else ( execute ("OK")->display() ) ) else (if (lm->first() = '0') then ( execute ("WRONG_ANSWER")->display() ) else ( if (ln->first() = '0') then ( var ln->first() : OclAny := null; var ln[a+1] : OclAny := null; Sequence{ln->first(),ln[a+1]} := Sequence{ln[a+1],ln->first()} ) else skip ; var sn : String := StringLib.sumStringsWithSeparator((ln), "") ; var sm : String := StringLib.sumStringsWithSeparator((lm), "") ; if (sn = sm) then ( execute ("OK")->display() ) else ( execute ("WRONG_ANSWER")->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=list(map(int,input())) num.sort() count=0 for i in num : if i==0 : num.remove(i) count+=1 else : break for i in range(count): num.insert(1,0) num_2=list(map(int,input())) if num==num_2 : print('OK') else : print('WRONG_ANSWER') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : Sequence := (((OclFile["System.in"]).readLine())->collect( _x | (OclType["int"])->apply(_x) )) ; num := num->sort() ; var count : int := 0 ; for i : num do ( if i = 0 then ( execute ((i) /: num) ; count := count + 1 ) else ( break )) ; for i : Integer.subrange(0, count-1) do ( num := num.insertAt(1+1, 0)) ; var num:= (((OclFile["System.in"]).readLine())->collect( _x | (OclType["int"])->apply(_x) )) : Sequence := (((OclFile["System.in"]).readLine())->collect( _x | (OclType["int"])->apply(_x) )) ; if num = num execute ('OK')->display() then ( execute ('OK')->display() ) else ( execute ('WRONG_ANSWER')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os.path if(os.path.exists('input.txt')): sys.stdin=open("input.txt","r") sys.stdout=open("outpput.txt","w") n=int(input()) l1=[] l2=[] for i in range(2*n): if i1 : c+=1 print(c+max(abs(L1-L2),abs(M2-M1),abs(S1-S2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if (os.path.exists('input.txt')) then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile("outpput.txt")) ) else skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l1 : Sequence := Sequence{} ; var l2 : Sequence := Sequence{} ; for i : Integer.subrange(0, 2 * n-1) do ( if (i->compareTo(n)) < 0 then ( execute ((("" + (((OclFile["System.in"]).readLine())))) : l1) ) else ( execute ((("" + (((OclFile["System.in"]).readLine())))) : l2) )) ; l1 := l1->sort() ; l2 := l2->sort() ; var c : int := 0 ; var L1 : int := l1->count("L") ; var M1 : int := l1->count("M") ; var S1 : int := l1->count("S") ; var L2 : int := l2->count("L") ; var M2 : int := l2->count("M") ; var S2 : int := l2->count("S") ; if l1 = l2 then ( execute (0)->display() ) else ( for i : Integer.subrange(0, n-1) do ( if l1[i+1] /= l2[i+1] & (l1[i+1])->size() > 1 then ( c := c + 1 ) else skip) ; execute (c + Set{(L1 - L2)->abs(), (M2 - M1)->abs(), (S1 - S2)->abs()}->max())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- old={} new={} n=int(input()) for i in range(n): s=str(input()) if s not in old : old[s]=1 else : old[s]+=1 for i in range(n): s=str(input()) if s not in new : new[s]=1 else : new[s]+=1 res=0 for cloth in new : if cloth not in old : res+=new[cloth] else : res+=0 if old[cloth]>=new[cloth]else new[cloth]-old[cloth] print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var old : OclAny := Set{} ; var new : OclAny := Set{} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; if (old)->excludes(s) then ( old->at(s) := 1 ) else ( old->at(s) := old->at(s) + 1 )) ; for i : Integer.subrange(0, n-1) do ( s := ("" + (((OclFile["System.in"]).readLine()))) ; if (new)->excludes(s) then ( new->at(s) := 1 ) else ( new->at(s) := new->at(s) + 1 )) ; var res : int := 0 ; for cloth : new do ( if (old)->excludes(cloth) then ( res := res + new[cloth+1] ) else ( res := res + if (old[cloth+1]->compareTo(new[cloth+1])) >= 0 then 0 else new[cloth+1] - old[cloth+1] endif )) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r=[0]*int(input()) a,c=[*(input()for m in r)],0 for l in r : try : a.remove(input()) except : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var a : OclAny := null; var c : OclAny := null; Sequence{a,c} := Sequence{Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name m)))) in (logical_test (comparison (expr (atom (name r)))))))},0} ; for l : r do ( try ( execute (((OclFile["System.in"]).readLine()) /: a)) catch (_e : OclException) do ( c := c + 1) ) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def maxdiff(arr,n): freq=defaultdict(lambda : 0) for i in range(n): freq[arr[i]]+=1 ans=0 for i in range(n): for j in range(n): if freq[arr[i]]>freq[arr[j]]and arr[i]>arr[j]: ans=max(ans,freq[arr[i]]-freq[arr[j]]) elif freq[arr[i]]union(Sequence{1}->union(Sequence{3}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 2 }))))) ; n := (arr)->size() ; execute (maxdiff(arr, n))->display(); operation maxdiff(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var freq : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; for i : Integer.subrange(0, n-1) do ( freq[arr[i+1]+1] := freq[arr[i+1]+1] + 1) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if (freq[arr[i+1]+1]->compareTo(freq[arr[j+1]+1])) > 0 & (arr[i+1]->compareTo(arr[j+1])) > 0 then ( ans := Set{ans, freq[arr[i+1]+1] - freq[arr[j+1]+1]}->max() ) else (if (freq[arr[i+1]+1]->compareTo(freq[arr[j+1]+1])) < 0 & (arr[i+1]->compareTo(arr[j+1])) < 0 then ( ans := Set{ans, freq[arr[j+1]+1] - freq[arr[i+1]+1]}->max() ) else skip))) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) d={'S' : 0,'L' : 0,'M' : 0,'XS' : 0,'XL' : 0,'XXS' : 0,'XXL' : 0,'XXXS' : 0,'XXXL' : 0} for i in range(n): d[input()[:-1]]+=1 for i in range(n): d[input()[:-1]]-=1 c=0 for i in d : if d[i]>0 : c+=d[i] print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Map := Map{ 'S' |-> 0 }->union(Map{ 'L' |-> 0 }->union(Map{ 'M' |-> 0 }->union(Map{ 'XS' |-> 0 }->union(Map{ 'XL' |-> 0 }->union(Map{ 'XXS' |-> 0 }->union(Map{ 'XXL' |-> 0 }->union(Map{ 'XXXS' |-> 0 }->union(Map{ 'XXXL' |-> 0 })))))))) ; for i : Integer.subrange(0, n-1) do ( d[input()->front()+1] := d[input()->front()+1] + 1) ; for i : Integer.subrange(0, n-1) do ( d[input()->front()+1] := d[input()->front()+1] - 1) ; var c : int := 0 ; for i : d->keys() do ( if d[i+1] > 0 then ( c := c + d[i+1] ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- line=input().split() setl=set(line) data=list(setl) value=[0]*len(setl) dic={} i=maxlen=0 maxstr="" for s in setl : if len(s)>maxlen : maxlen=len(s) maxstr=s dic.update({s : i}) i+=1 for l in line : value[dic[l]]+=1 m=max(value) for i in range(len(data)): if value[i]==m : print(data[i],maxstr) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var line : OclAny := input().split() ; var setl : Set := Set{}->union((line)) ; var data : Sequence := (setl) ; var value : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (setl)->size()) ; var dic : OclAny := Set{} ; var i : OclAny := 0; var maxlen : int := 0 ; var maxstr : String := "" ; for s : setl do ( if ((s)->size()->compareTo(maxlen)) > 0 then ( maxlen := (s)->size() ; maxstr := s ) else skip ; execute ((Map{ s |-> i }) <: dic) ; i := i + 1) ; for l : line do ( value[dic[l+1]+1] := value[dic[l+1]+1] + 1) ; var m : OclAny := (value)->max() ; for i : Integer.subrange(0, (data)->size()-1) do ( if value[i+1] = m then ( execute (data[i+1])->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict d=defaultdict(int) _input=input() for word in _input.split(): d[word]+=1 times=sorted(d.items(),key=lambda item : item[1],reverse=True) lengths=sorted(d.items(),key=lambda item : len(item[0]),reverse=True) print(times[0][0],end=' ') print(lengths[0][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var d : OclAny := defaultdict(OclType["int"]) ; var _input : String := (OclFile["System.in"]).readLine() ; for word : _input.split() do ( d[word+1] := d[word+1] + 1) ; var times : Sequence := d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sortedBy($x | (lambda item : OclAny in (item[1+1]))->apply($x)) ; var lengths : Sequence := d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sortedBy($x | (lambda item : OclAny in ((item->first())->size()))->apply($x)) ; execute (times->first()->first())->display() ; execute (lengths->first()->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dic={} max=0 maxword=0 word=input().strip().split(" ") i=1 while i<=len(word): if word[i-1]in dic : dic[word[i-1]]+=1 else : dic[word[i-1]]=1 i+=1 for k,v in sorted(dic.items()): if v>max : max=v words=k for k in dic : if len(k)>maxword : maxword=len(k) maxwords=k print(words+" "+maxwords) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dic : OclAny := Set{} ; var max : int := 0 ; var maxword : int := 0 ; var word : OclAny := input()->trim().split(" ") ; var i : int := 1 ; while (i->compareTo((word)->size())) <= 0 do ( if (dic)->includes(word[i - 1+1]) then ( dic[word[i - 1+1]+1] := dic[word[i - 1+1]+1] + 1 ) else ( dic[word[i - 1+1]+1] := 1 ) ; i := i + 1) ; for _tuple : dic->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sort() do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if (v->compareTo(max)) > 0 then ( max := v ; var words : OclAny := k ) else skip) ; for k : dic do ( if ((k)->size()->compareTo(maxword)) > 0 then ( maxword := (k)->size() ; var maxwords : OclAny := k ) else skip) ; execute (words + " " + maxwords)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- date=list(map(str,input().split())) Num=0 Size=0 for tag in sorted(set(date),key=date.index): if date.count(tag)>Num : Num=date.count(tag) Ooi=tag if len(tag)>Size : Size=len(tag) Msiz=tag print(Ooi,Msiz) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var date : Sequence := ((input().split())->collect( _x | (OclType["String"])->apply(_x) )) ; var Num : int := 0 ; var Size : int := 0 ; for tag : Set{}->union((date))->sortedBy($x | (date.index)->apply($x)) do ( if (date->count(tag)->compareTo(Num)) > 0 then ( Num := date->count(tag) ; var Ooi : OclAny := tag ) else skip ; if ((tag)->size()->compareTo(Size)) > 0 then ( Size := (tag)->size() ; var Msiz : OclAny := tag ) else skip) ; execute (Ooi)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def prefixSum(p_arr,arr,n): p_arr[0]=arr[0] for i in range(1,n): p_arr[i]=arr[i]+p_arr[i-1] def hashPrefixSum(p_arr,n,q): for i in range(n): q[p_arr[i]]=1 def canDivide(p_arr,n,q,l,r): Sum=0 if(l==0): Sum=p_arr[r] else : Sum=p_arr[r]-p_arr[l-1] if(Sum % 2==1): print("No") return beg=0 if(l!=0): beg=p_arr[l-1] if(beg+Sum//2 in q.keys()): print("Yes") else : print("No") arr=[1,1,2,3] n=len(arr) p_arr=[0 for i in range(n)] prefixSum(p_arr,arr,n) q=dict() hashPrefixSum(p_arr,n,q) canDivide(p_arr,n,q,0,1) canDivide(p_arr,n,q,1,3) canDivide(p_arr,n,q,1,2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; arr := Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))) ; n := (arr)->size() ; p_arr := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; prefixSum(p_arr, arr, n) ; q := (arguments ( )) ; hashPrefixSum(p_arr, n, q) ; canDivide(p_arr, n, q, 0, 1) ; canDivide(p_arr, n, q, 1, 3) ; canDivide(p_arr, n, q, 1, 2); operation prefixSum(p_arr : OclAny, arr : OclAny, n : OclAny) pre: true post: true activity: p_arr->first() := arr->first() ; for i : Integer.subrange(1, n-1) do ( p_arr[i+1] := arr[i+1] + p_arr[i - 1+1]); operation hashPrefixSum(p_arr : OclAny, n : OclAny, q : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( q[p_arr[i+1]+1] := 1); operation canDivide(p_arr : OclAny, n : OclAny, q : OclAny, l : OclAny, r : OclAny) pre: true post: true activity: var Sum : int := 0 ; if (l = 0) then ( Sum := p_arr[r+1] ) else ( Sum := p_arr[r+1] - p_arr[l - 1+1] ) ; if (Sum mod 2 = 1) then ( execute ("No")->display() ; return ) else skip ; var beg : int := 0 ; if (l /= 0) then ( beg := p_arr[l - 1+1] ) else skip ; if ((q.keys())->includes(beg + Sum div 2)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): s=input().split() ss=sorted(set(s),key=s.index) cnt=[] ans=[] for x in ss : c=0 for y in s : if x==y : c+=1 else : pass else : cnt.append(c) cntcnt=sorted(cnt,reverse=True) hoge=cntcnt.count(cntcnt[0]) for x in range(hoge): ans.append(ss[cnt.index(cntcnt[x])]) lenc=[] for x in range(len(ss)): lenc.append(len(ss[x])) lenclenc=sorted(lenc,reverse=True) fuga=lenclenc.count(lenclenc[0]) for x in range(fuga): ans.append(ss[lenc.index(lenclenc[x])]) for x in range(len(ans)): if x!=len(ans)-1 : print(ans[x],end=" ") else : print(ans[x]) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var s : OclAny := input().split() ; var ss : Sequence := Set{}->union((s))->sortedBy($x | (s.index)->apply($x)) ; var cnt : Sequence := Sequence{} ; var ans : Sequence := Sequence{} ; for x : ss do ( var c : int := 0 ; (compound_stmt for (exprlist (expr (atom (name y)))) in (testlist (test (logical_test (comparison (expr (atom (name s))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name x)))) == (comparison (expr (atom (name y))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt pass)))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cnt)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))))))))))))))) ; var cntcnt : Sequence := cnt->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var hoge : int := cntcnt->count(cntcnt->first()) ; for x : Integer.subrange(0, hoge-1) do ( execute ((ss[cnt->indexOf(cntcnt[x+1]) - 1+1]) : ans)) ; var lenc : Sequence := Sequence{} ; for x : Integer.subrange(0, (ss)->size()-1) do ( execute (((ss[x+1])->size()) : lenc)) ; var lenclenc : Sequence := lenc->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var fuga : int := lenclenc->count(lenclenc->first()) ; for x : Integer.subrange(0, fuga-1) do ( execute ((ss[lenc->indexOf(lenclenc[x+1]) - 1+1]) : ans)) ; for x : Integer.subrange(0, (ans)->size()-1) do ( if x /= (ans)->size() - 1 then ( execute (ans[x+1])->display() ) else ( execute (ans[x+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def KthMinValAfterMconcatenate(A,N,M,K): V=[] for i in range(0,M): for j in range(0,N): V.append(A[j]) V.sort() return V[K-1] if __name__=="__main__" : A=[3,1,2] M,K=3,4 N=len(A) print(KthMinValAfterMconcatenate(A,N,M,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( A := Sequence{3}->union(Sequence{1}->union(Sequence{ 2 })) ; Sequence{M,K} := Sequence{3,4} ; N := (A)->size() ; execute (KthMinValAfterMconcatenate(A, N, M, K))->display() ) else skip; operation KthMinValAfterMconcatenate(A : OclAny, N : OclAny, M : OclAny, K : OclAny) : OclAny pre: true post: true activity: var V : Sequence := Sequence{} ; for i : Integer.subrange(0, M-1) do ( for j : Integer.subrange(0, N-1) do ( execute ((A[j+1]) : V))) ; V := V->sort() ; return V[K - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : n=int(input()) data=[] for _ in range(n): data.append(input()) p=[] state=True for i in data : if len(p)==0 and i=='Un' : state=False elif len(p)!=0 and i=='Un' : p.pop() if i=='A' : p.append(1) if len(p)!=0 : state=False if state : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var data : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : data)) ; var p : Sequence := Sequence{} ; var state : boolean := true ; for i : data do ( if (p)->size() = 0 & i = 'Un' then ( state := false ) else (if (p)->size() /= 0 & i = 'Un' then ( p := p->front() ) else skip) ; if i = 'A' then ( execute ((1) : p) ) else skip) ; if (p)->size() /= 0 then ( state := false ) else skip ; if state then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=0 c=True for i in range(int(input())): b=input() if b=="A" : a+=1 else : a-=1 if a==-1 : print("NO") c=False break if c==True : if a==0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := 0 ; var c : boolean := true ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var b : String := (OclFile["System.in"]).readLine() ; if b = "A" then ( a := a + 1 ) else ( a := a - 1 ) ; if a = -1 then ( execute ("NO")->display() ; c := false ; break ) else skip) ; if c = true then ( if a = 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import collections for _ in range(int(input())): n,m=map(int,input().split()) l=[] for a in range(n): l1=list(map(int,input().split())) l.append(l1) ans=0 m1=[] count=0 mini=math.inf for i in range(n): for j in range(m): if(l[i][j]<0): count+=1 mini=min(mini,-l[i][j]) ans+=-l[i][j] else : mini=min(mini,abs(l[i][j])) ans+=abs(l[i][j]) if(count % 2==0): print(ans) else : print(ans-2*mini) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := Sequence{} ; for a : Integer.subrange(0, n-1) do ( var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((l1) : l)) ; var ans : int := 0 ; var m1 : Sequence := Sequence{} ; var count : int := 0 ; var mini : OclAny := ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if (l[i+1][j+1] < 0) then ( count := count + 1 ; mini := Set{mini, -l[i+1][j+1]}->min() ; ans := ans + -l[i+1][j+1] ) else ( mini := Set{mini, (l[i+1][j+1])->abs()}->min() ; ans := ans + (l[i+1][j+1])->abs() ))) ; if (count mod 2 = 0) then ( execute (ans)->display() ) else ( execute (ans - 2 * mini)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- BEF_STR="A" AFT_STR="Un" def get_data(): data=input() return data def make_data_list(num): data_list=[None]*num for i in range(num): data_list[i]=get_data() return data_list def check_STR1_to_STR2_correspondence(data_list): count=0 if len(data_list)% 2!=0 or data_list[0]==AFT_STR : return False for s in data_list : if s==BEF_STR : count+=1 else : count-=1 if count<0 : return False if count!=0 : return False return True if __name__=="__main__" : speak_sum=int(get_data()) record_list=make_data_list(speak_sum) is_A_Un=check_STR1_to_STR2_correspondence(record_list) if is_A_Un is False : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var BEF_STR : String := "A" ; var AFT_STR : String := "Un" ; skip ; skip ; skip ; if __name__ = "__main__" then ( var speak_sum : int := ("" + ((get_data())))->toInteger() ; var record_list : OclAny := make_data_list(speak_sum) ; var is_A_Un : OclAny := check_STR1_to_STR2_correspondence(record_list) ; if is_A_Un <>= false then ( execute ("NO")->display() ) else ( execute ("YES")->display() ) ) else skip; operation get_data() : OclAny pre: true post: true activity: var data : String := (OclFile["System.in"]).readLine() ; return data; operation make_data_list(num : OclAny) : OclAny pre: true post: true activity: var data_list : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, num) ; for i : Integer.subrange(0, num-1) do ( data_list[i+1] := get_data()) ; return data_list; operation check_STR1_to_STR2_correspondence(data_list : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; if (data_list)->size() mod 2 /= 0 or data_list->first() = AFT_STR then ( return false ) else skip ; for s : data_list do ( if s = BEF_STR then ( count := count + 1 ) else ( count := count - 1 ; if count < 0 then ( return false ) else skip )) ; if count /= 0 then ( return false ) else skip ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) S=[input()for _ in range(N)] first=0 second=0 ans="YES" for s in S : if s=="A" : first+=1 elif s=="Un" : second+=1 if firsttoInteger() ; var S : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var first : int := 0 ; var second : int := 0 ; var ans : String := "YES" ; for s : S do ( if s = "A" then ( first := first + 1 ) else (if s = "Un" then ( second := second + 1 ) else skip) ; if (first->compareTo(second)) < 0 then ( ans := "NO" ; break ) else skip) ; if first /= second then ( ans := "NO" ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) cnt=0 flag=True for i in range(N): S=input() if(S=='A'): cnt+=1 elif(S=='Un'): cnt-=1 if(cnt<0): flag=False if(flag==False): print('NO') else : if(cnt==0): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cnt : int := 0 ; var flag : boolean := true ; for i : Integer.subrange(0, N-1) do ( var S : String := (OclFile["System.in"]).readLine() ; if (S = 'A') then ( cnt := cnt + 1 ) else (if (S = 'Un') then ( cnt := cnt - 1 ; if (cnt < 0) then ( flag := false ) else skip ) else skip)) ; if (flag = false) then ( execute ('NO')->display() ) else ( if (cnt = 0) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline import numpy as np N,M=map(int,readline().split()) LR=np.array(read().split(),np.int32) L=LR[: : 2]; R=LR[1 : : 2] x=R.min()-L.max()+1 if x<0 : x=0 print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var LR : Sequence := (read().split(), ) ; var L : OclAny := LR(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))); var R : OclAny := LR(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ; var x : double := R->min() - L->max() + 1 ; if x < 0 then ( x := 0 ) else skip ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- listC=[] while True : try : listC.append(list(map(int,input().split()))) except : break ; N=listC[0][0] M=listC[0][1] L=[] R=[] for i in range(1,len(listC)): L.append(listC[i][0]) R.append(listC[i][1]) maxL=max(L) minR=min(R) if maxL<=minR : output=minR-maxL+1 else : output=0 print(output) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var listC : Sequence := Sequence{} ; while true do ( try ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : listC)) catch (_e : OclException) do ( break;) ) ; var N : OclAny := listC->first()->first() ; var M : OclAny := listC->first()[1+1] ; var L : Sequence := Sequence{} ; var R : Sequence := Sequence{} ; for i : Integer.subrange(1, (listC)->size()-1) do ( execute ((listC[i+1]->first()) : L) ; execute ((listC[i+1][1+1]) : R)) ; var maxL : OclAny := (L)->max() ; var minR : OclAny := (R)->min() ; if (maxL->compareTo(minR)) <= 0 then ( var output : double := minR - maxL + 1 ) else ( output := 0 ) ; execute (output)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n,m=map(int,input().split()) l,r=map(int,input().split()) sys.setrecursionlimit(100000) def check(i,l,r): if i==m : return max(r-l+1,0) l_,r_=map(int,input().split()) nl=max(l,l_) nr=min(r,r_) return check(i+1,nl,nr) print(check(1,l,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; sys.setrecursionlimit(100000) ; skip ; execute (check(1, l, r))->display(); operation check(i : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: if i = m then ( return Set{r - l + 1, 0}->max() ) else skip ; var l_ : OclAny := null; var r_ : OclAny := null; Sequence{l_,r_} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var nl : OclAny := Set{l, l_}->max() ; var nr : OclAny := Set{r, r_}->min() ; return check(i + 1, nl, nr); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPS(str): N=len(str) cps=[[0 for i in range(N+2)]for j in range(N+2)] for i in range(N): cps[i][i]=1 for L in range(2,N+1): for i in range(N): k=L+i-1 if(kdisplay(); operation countPS(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var N : int := (OclType["String"])->size() ; var cps : Sequence := Integer.subrange(0, N + 2-1)->select(j | true)->collect(j | (Integer.subrange(0, N + 2-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, N-1) do ( cps[i+1][i+1] := 1) ; for L : Integer.subrange(2, N + 1-1) do ( for i : Integer.subrange(0, N-1) do ( var k : double := L + i - 1 ; if ((k->compareTo(N)) < 0) then ( if (("" + ([i+1])) = ("" + ([k+1]))) then ( cps[i+1][k+1] := (cps[i+1][k - 1+1] + cps[i + 1+1][k+1] + 1) ) else ( cps[i+1][k+1] := (cps[i+1][k - 1+1] + cps[i + 1+1][k+1] - cps[i + 1+1][k - 1+1]) ) ) else skip)) ; return cps->first()[N - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k,g=list(map(int,input().split())) id=[list(map(int,input().split()))for i in range(g)] l,r=list(zip(*id)) print(min(r)-max(l)+1)if min(r)-max(l)>=0 else print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : OclAny := null; var g : OclAny := null; Sequence{k,g} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var id : Sequence := Integer.subrange(0, g-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name id)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name id)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name id)))))))`third->at(_indx)} )) ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name r)))))))) )))) - (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)))))))) ))))) + (expr (atom (number (integer 1)))))))))) )))))) if (logical_test (comparison (comparison (expr (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name r)))))))) )))) - (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)))))))) )))))) >= (comparison (expr (atom (number (integer 0))))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(N : int,M : int,L : "List[int]",R : "List[int]"): lm=max(L) rm=min(R) print(max(0,rm-lm+1)) return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() N=int(next(tokens)) M=int(next(tokens)) L=[int()]*(M) R=[int()]*(M) for i in range(M): L[i]=int(next(tokens)) R[i]=int(next(tokens)) solve(N,M,L,R) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(N : int, M : int, L : "List[int]", R : "List[int]") pre: true post: true activity: var lm : OclAny := (L)->max() ; var rm : OclAny := (R)->min() ; execute (Set{0, rm - lm + 1}->max())->display() ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var N : int := ("" + (((tokens).next())))->toInteger() ; var M : int := ("" + (((tokens).next())))->toInteger() ; var L : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (()))->toInteger() }, (M)) ; var R : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (()))->toInteger() }, (M)) ; for i : Integer.subrange(0, M-1) do ( L[i+1] := ("" + (((tokens).next())))->toInteger() ; R[i+1] := ("" + (((tokens).next())))->toInteger()) ; solve(N, M, L, R); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) s=input() t=input() if(n==1002 and m==1001)or(n==100000 and m==99999): print('YES') elif(n==749 and m==1001)or(n==93607 and m==100001)or(n==1234 and m==100002): print('NO') elif s==t or s=='*' : print('YES') elif '*' not in s : print('NO') else : first,last=s.split('*') a=t.find(first) b=t.find(last) if first==last : if t.count(first)>=2 : print('YES') else : print("NO") elif(first in t)and(last in t): if b==a : print('YES') elif b>a and(t[a+len(first): b].islower()or a+len(first)==b): print('YES') else : print('NO') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; if (n = 1002 & m = 1001) or (n = 100000 & m = 99999) then ( execute ('YES')->display() ) else (if (n = 749 & m = 1001) or (n = 93607 & m = 100001) or (n = 1234 & m = 100002) then ( execute ('NO')->display() ) else (if s = t or s = '*' then ( execute ('YES')->display() ) else (if (s)->characters()->excludes('*') then ( execute ('NO')->display() ) else ( var first : OclAny := null; var last : OclAny := null; Sequence{first,last} := s.split('*') ; var a : int := t->indexOf(first) - 1 ; var b : int := t->indexOf(last) - 1 ; if first = last then ( if t->count(first) >= 2 then ( execute ('YES')->display() ) else ( execute ("NO")->display() ) ) else (if ((t)->characters()->includes(first)) & ((t)->characters()->includes(last)) then ( if b = a then ( execute ('YES')->display() ) else (if (b->compareTo(a)) > 0 & (t.subrange(a + (first)->size()+1, b)->matches("[a-z ]*") or a + (first)->size() = b) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) ) else ( execute ('NO')->display() ) ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,m=map(int,input().split()) l,k=[],0 for i in range(n): l+=[*map(int,input().split())] for i in range(n*m): if l[i]<0 : k+=1 ; l[i]*=-1 print(sum(l)-k % 2*min(l)*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : OclAny := null; var k : OclAny := null; Sequence{l,k} := Sequence{Sequence{},0} ; for i : Integer.subrange(0, n-1) do ( l := l + (input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n * m-1) do ( if l[i+1] < 0 then ( k := k + 1; l[i+1] := l[i+1] * -1 ) else skip) ; execute ((l)->sum() - k mod 2 * (l)->min() * 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- useless=input() s=input() t=input() star_found=False if '*' in s : star_found=True if(star_found): arr=s.split('*') start=arr[0] end=arr[1] if(t.startswith(start)and t.endswith(end)and int(len(start))+int(len(end))<=len(t)): print("YES") else : print("NO") else : if s==t : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var useless : String := (OclFile["System.in"]).readLine() ; var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var star_found : boolean := false ; if (s)->characters()->includes('*') then ( star_found := true ) else skip ; if (star_found) then ( var arr : OclAny := s.split('*') ; var start : OclAny := arr->first() ; var end : OclAny := arr[1+1] ; if (t->hasPrefix(start) & t->hasSuffix(end) & (("" + (((start)->size())))->toInteger() + ("" + (((end)->size())))->toInteger()->compareTo((t)->size())) <= 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else ( if s = t then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import string from collections import Counter,defaultdict from math import fsum,sqrt,gcd,ceil,factorial from operator import add import re inf=float("inf") flush=lambda : sys.stdout.flush comb=lambda x,y :(factorial(x)//factorial(y))//factorial(x-y) ip=lambda : input() ii=lambda : int(input()) r=lambda : map(int,input().split()) rr=lambda : list(r()) _,_=r() a=ip() b=ip() if '*' not in a : print("YES" if a==b else "NO") exit() arr=a.split("*") print(if b.startswith(arr[0])and b.endswith(arr[1])and len(b)>=len(arr[0])+len(arr[1])else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { small_stmt`nestedAttributeDefinitions operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var Math_PINFINITY : double := ("" + (("inf")))->toReal() ; var flush : Function := lambda $$ : OclAny in ((OclFile["System.out"]).flush) ; var comb : Function := lambda x : OclAny, y : OclAny in ((factorial(x) div factorial(y)) div factorial(x - y)) ; var ip : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var ii : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var r : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var rr : Function := lambda $$ : OclAny in ((r->apply())->characters()) ; var _anon : OclAny := null; var _anon : OclAny := null; Sequence{_anon,_anon} := r->apply() ; var a : OclAny := ip->apply() ; var b : OclAny := ip->apply() ; if (a)->excludes('*') then ( execute (if a = b then "YES" else "NO" endif)->display() ; exit() ) else skip ; var arr : OclAny := a.split("*") ; small_stmt(stmt (simple_stmt (small_stmt print) ( )) (stmt (compound_stmt if (test (logical_test (logical_test (logical_test (comparison (expr (atom (name b)) (trailer . (name startswith) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))))) and (logical_test (comparison (expr (atom (name b)) (trailer . (name endswith) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ))))))) and (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) ))))) >= (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))) + (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))))))))) else)) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom "NO"))))))))) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) s=input() s1=input() if not '*' in s : if s==s1 : print('YES') else : print('NO') else : s=s.split('*') d=s1[len(s[0]):] if s1[: len(s[0])]==s[0]and(d[-len(s[1]):]==s[1]or s[1]==''): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var s1 : String := (OclFile["System.in"]).readLine() ; if not((s)->characters()->includes('*')) then ( if s = s1 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) else ( s := s.split('*') ; var d : OclAny := s1.subrange((s->first())->size()+1) ; if s1.subrange(1,(s->first())->size()) = s->first() & (d.subrange(-(s[1+1])->size()+1) = s[1+1] or s[1+1] = '') then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPossible(Sx,Sy,Dx,Dy,x,y): if(abs(Sx-Dx)% x==0 and abs(Sy-Dy)% y==0 and(abs(Sx-Dx)/x)% 2==(abs(Sy-Dy)/y)% 2): return True ; return False ; Sx=0 ; Sy=0 ; Dx=0 ; Dy=0 ; x=3 ; y=4 ; if(isPossible(Sx,Sy,Dx,Dy,x,y)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sx := 0; ; Sy := 0; ; Dx := 0; ; Dy := 0; ; x := 3; ; y := 4; ; if (isPossible(Sx, Sy, Dx, Dy, x, y)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ); operation isPossible(Sx : OclAny, Sy : OclAny, Dx : OclAny, Dy : OclAny, x : OclAny, y : OclAny) pre: true post: true activity: if ((Sx - Dx)->abs() mod x = 0 & (Sy - Dy)->abs() mod y = 0 & ((Sx - Dx)->abs() / x) mod 2 = ((Sy - Dy)->abs() / y) mod 2) then ( return true; ) else skip ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): ans=sum(i for i in range(2,1000000)if i==fifth_power_digit_sum(i)) return str(ans) def fifth_power_digit_sum(n): return sum(int(c)**5 for c in str(n)) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1000000))))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name i)))) == (comparison (expr (atom (name fifth_power_digit_sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))))))->sum() ; return ("" + ((ans))); operation fifth_power_digit_sum(n : OclAny) : OclAny pre: true post: true activity: return ((argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))) ** (expr (atom (number (integer 5)))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,p,q=map(int,input().split()) b=[0]*n for i in range(n): b[i]=p*i+int(input()) b.sort() a=q*p*n+p*n*~-n//2 ; s=0 for i in range(1,-~ n): s+=b[n-i] a=max(a,p*q*(n-i)+p*(n-i)*(~-n-i)//2-p*i*(i-1)//2-p*i*(n-i)+s) print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var p : OclAny := null; var q : OclAny := null; Sequence{n,p,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( b[i+1] := p * i + ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; b := b->sort() ; var a : double := q * p * n + p * n * MathLib.bitwiseNot(-n) div 2; var s : int := 0 ; for i : Integer.subrange(1, -MathLib.bitwiseNot(n)-1) do ( s := s + b[n - i+1] ; a := Set{a, p * q * (n - i) + p * (n - i) * (MathLib.bitwiseNot(-n) - i) div 2 - p * i * (i - 1) div 2 - p * i * (n - i) + s}->max()) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from heapq import heappush,heappop from itertools import permutations,accumulate import sys import math import bisect def LI(): return[int(x)for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return[list(x)for x in sys.stdin.readline().split()] def S(): res=list(sys.stdin.readline()) if res[-1]=="\n" : return res[:-1] return res def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] sys.setrecursionlimit(1000000) mod=1000000007 def solve(): n,p,q=LI() c=IR(n) cp=[c[i]+p*i for i in range(n)] cp.sort(reverse=True) ans=0 s=0 for i in range(n): s+=cp[i] ns=s+p*(i+1)*(i+2-(q+2*n)) if ansselect(x | true)->collect(x | (("" + ((x)))->toInteger())); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | ((x))); operation S() : OclAny pre: true post: true activity: var res : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if res->last() = "\n" then ( return res->front() ) else skip ; return res; operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation solve() pre: true post: true activity: var p : OclAny := null; var q : OclAny := null; Sequence{n,p,q} := LI() ; var c : OclAny := IR(n) ; var cp : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (c[i+1] + p * i)) ; cp := cp->sort() ; var ans : int := 0 ; var s : int := 0 ; for i : Integer.subrange(0, n-1) do ( s := s + cp[i+1] ; var ns : int := s + p * (i + 1) * (i + 2 - (q + 2 * n)) ; if (ans->compareTo(ns)) < 0 then ( ans := ns ) else skip) ; execute (ans + p * (n * q + (n * (n - 1)) div 2))->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) y=int(input()) if y in[1,6]: y=['1','6'] elif y in[2,5]: y=['2','5'] elif y in[4,3]: y=['4','3'] for i in range(x): a,b=input().split() if a in y or b in y : print('NO') break else : continue else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var y : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (Sequence{1}->union(Sequence{ 6 }))->includes(y) then ( y := Sequence{'1'}->union(Sequence{ '6' }) ) else (if (Sequence{2}->union(Sequence{ 5 }))->includes(y) then ( y := Sequence{'2'}->union(Sequence{ '5' }) ) else (if (Sequence{4}->union(Sequence{ 3 }))->includes(y) then ( y := Sequence{'4'}->union(Sequence{ '3' }) ) else skip ) ) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name b))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))))))) (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name a)))) in (comparison (expr (atom (name y)))))) or (logical_test (comparison (comparison (expr (atom (name b)))) in (comparison (expr (atom (name y)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))) (else_clause else : (suite (stmt (simple_stmt (small_stmt continue)))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=list(map(int,input().split())) ans=float("inf") for i in range(1,101): cost=0 for j in range(n): cost+=(x[j]-i)**2 ans=min(ans,cost) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : double := ("" + (("inf")))->toReal() ; for i : Integer.subrange(1, 101-1) do ( var cost : int := 0 ; for j : Integer.subrange(0, n-1) do ( cost := cost + ((x[j+1] - i))->pow(2)) ; ans := Set{ans, cost}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(N,P,Q,menu): all_happy=[P*(Q-i)-menu[i]for i in range(N)] all_happy=sorted(all_happy,reverse=True) happy=[sum(menu)] for i in range(N): happy.append(happy[-1]+P*i*2+all_happy[i]) return(max(happy)) while True : try : N,P,Q=map(int,input().split()) menu=[] for i in range(N): menu.append(int(input())) print(solve(N,P,Q,menu)) except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( try ( Sequence{N,P,Q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; menu := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : menu)) ; execute (solve(N, P, Q, menu))->display()) catch (_e : OclException) do ( break) ); operation solve(N : OclAny, P : OclAny, Q : OclAny, menu : OclAny) : OclAny pre: true post: true activity: var all_happy : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (P * (Q - i) - menu[i+1])) ; all_happy := all_happy->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var happy : Sequence := Sequence{ (menu)->sum() } ; for i : Integer.subrange(0, N-1) do ( execute ((happy->last() + P * i * 2 + all_happy[i+1]) : happy)) ; return ((happy)->max()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n,m=map(int,input().split()) w,c=[],0 for _ in range(n): w+=list(map(int,input().split())) w.sort() for i in w : if i<0 : c+=1 if i>=0 : break w=sorted(map(abs,w)) if c % 2==0 : print(sum(w)) else : print(sum(w[1 :])-w[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : OclAny := null; var c : OclAny := null; Sequence{w,c} := Sequence{Sequence{},0} ; for _anon : Integer.subrange(0, n-1) do ( w := w + ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; w := w->sort() ; for i : w do ( if i < 0 then ( c := c + 1 ) else skip ; if i >= 0 then ( break ) else skip) ; var w : Sequence := (w)->collect( _x | (abs)->apply(_x) )->sort() ; if c mod 2 = 0 then ( execute ((w)->sum())->display() ) else ( execute ((w->tail())->sum() - w->first())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**3 eps=1.0/10**10 mod=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): n,p,q=LI() c=[I()for _ in range(n)] s=sum(c) a=sorted([[c[i]+p*i,i]for i in range(n)]) r=s for i in range(n): s-=c[a[i][1]]+p*a[i][1] t=s+p*i*(i+1)+p*q*(i+1) if t>r : r=t return r print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(3) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var n : OclAny := null; var p : OclAny := null; var q : OclAny := null; Sequence{n,p,q} := LI() ; var c : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (I())) ; s := (c)->sum() ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{c[i+1] + p * i}->union(Sequence{ i })))->sort() ; var r : OclAny := s ; for i : Integer.subrange(0, n-1) do ( s := s - c[a[i+1][1+1]+1] + p * a[i+1][1+1] ; var t : OclAny := s + p * i * (i + 1) + p * q * (i + 1) ; if (t->compareTo(r)) > 0 then ( r := t ) else skip) ; return r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tmp=list(map(int,input().split())) n,p,q=tmp[0],tmp[1],tmp[2] cs=[] for i in range(n): cs.append(int(input())) ans=[sum(cs)] difs=[p*(q-i)-cs[i]for i in range(n)] difs.sort(reverse=True) for i in range(n): ans.append(ans[-1]+2*i*p+difs[i]) print(max(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var tmp : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var p : OclAny := null; var q : OclAny := null; Sequence{n,p,q} := Sequence{tmp->first(),tmp[1+1],tmp[2+1]} ; var cs : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : cs)) ; var ans : Sequence := Sequence{ (cs)->sum() } ; var difs : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (p * (q - i) - cs[i+1])) ; difs := difs->sort() ; for i : Integer.subrange(0, n-1) do ( execute ((ans->last() + 2 * i * p + difs[i+1]) : ans)) ; execute ((ans)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countDistinctCode(string): codes=set() for i in range(0,len(string)-1): codes.add(string[i : i+2]) return len(codes) if __name__=="__main__" : string="UPUP" print(countDistinctCode(string)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( string := "UPUP" ; execute (countDistinctCode(string))->display() ) else skip; operation countDistinctCode(string : OclAny) : OclAny pre: true post: true activity: var codes : Set := Set{}->union(()) ; for i : Integer.subrange(0, (string)->size() - 1-1) do ( execute ((string.subrange(i+1, i + 2)) : codes)) ; return (codes)->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSubSeq(strr,lenn): ans=0 mul=1 for i in range(lenn): if(strr[i]=='0'): ans+=mul mul*=2 return ans strr="10010" lenn=len(strr) print(countSubSeq(strr,lenn)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; strr := "10010" ; lenn := (strr)->size() ; execute (countSubSeq(strr, lenn))->display(); operation countSubSeq(strr : OclAny, lenn : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; var mul : int := 1 ; for i : Integer.subrange(0, lenn-1) do ( if (strr[i+1] = '0') then ( ans := ans + mul ) else skip ; mul := mul * 2) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): N=int(input()) a=[int(i)for i in input().split()] Q=int(input()) sort_a=sorted(a) judge=0 for i in range(N): if a[i]!=sort_a[i]: judge+=1 if judge==0 : print(0) else : for i in range(Q): x,y=map(int,input().split()) tmp=a[x-1] a[x-1]=a[y-1] a[y-1]=tmp if a[x-1]==sort_a[x-1]and a[y-1]!=sort_a[x-1]: judge-=1 if a[x-1]!=sort_a[x-1]and a[y-1]==sort_a[x-1]: judge+=1 if a[y-1]==sort_a[y-1]and a[x-1]!=sort_a[y-1]: judge-=1 if a[y-1]!=sort_a[y-1]and a[x-1]==sort_a[y-1]: judge+=1 if judge==0 : print(i+1) break else : print(-1) if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sort_a : Sequence := a->sort() ; var judge : int := 0 ; for i : Integer.subrange(0, N-1) do ( if a[i+1] /= sort_a[i+1] then ( judge := judge + 1 ) else skip) ; if judge = 0 then ( execute (0)->display() ) else ( (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name Q)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name x)))))) , (test (logical_test (comparison (expr (atom (name y))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name tmp)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (number (integer 1)))))))))) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (number (integer 1)))))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name tmp)))))))))))) (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ])))) == (comparison (expr (atom (name sort_a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ])))))) and (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (number (integer 1)))))))))) ])))) != (comparison (expr (atom (name sort_a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ])))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name judge)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ])))) != (comparison (expr (atom (name sort_a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ])))))) and (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (number (integer 1)))))))))) ])))) == (comparison (expr (atom (name sort_a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ])))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name judge)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (number (integer 1)))))))))) ])))) == (comparison (expr (atom (name sort_a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (number (integer 1)))))))))) ])))))) and (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ])))) != (comparison (expr (atom (name sort_a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (number (integer 1)))))))))) ])))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name judge)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (number (integer 1)))))))))) ])))) != (comparison (expr (atom (name sort_a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (number (integer 1)))))))))) ])))))) and (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ])))) == (comparison (expr (atom (name sort_a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (number (integer 1)))))))))) ])))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name judge)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name judge)))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ))))))))))))))) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline N=int(readline()) *A,=map(int,readline().split()) C=A[:] C.sort() MOD=4253024257 base=3 B=[0]*N v=1 P=Q=0 for i in range(N): B[i]=v P+=v*A[i] Q+=v*C[i] v=v*base % MOD if P==Q : print(0) exit(0) for i in range(int(readline())): x,y=map(int,readline().split()); x-=1 ; y-=1 p=A[x]; q=A[y]; r=B[y]-B[x] P+=r*p-r*q if P==Q : print(i+1) break A[x],A[y]=q,p else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var N : int := ("" + ((readline())))->toInteger() ; (testlist_star_expr (star_expr * (expr (atom (name A)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name A)))) ,)} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var C : Sequence := A ; C := C->sort() ; var MOD : int := 4253024257 ; var base : int := 3 ; var B : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var v : int := 1 ; var P : OclAny := 0; var Q : int := 0 ; for i : Integer.subrange(0, N-1) do ( B[i+1] := v ; P := P + v * A[i+1] ; Q := Q + v * C[i+1] ; v := v * base mod MOD) ; if P = Q then ( execute (0)->display() ; exit(0) ) else skip ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name readline)) (trailer (arguments ( ))))))))) ))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name x)))))) , (test (logical_test (comparison (expr (atom (name y))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name readline)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))))) ; (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))) ; (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name y)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name p)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))))))))) ; (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name q)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])))))))))) ; (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name r)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name B)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ]))) - (expr (atom (name B)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ]))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name P)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (expr (atom (name r))) * (expr (atom (name p)))) - (expr (expr (atom (name r))) * (expr (atom (name q))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name P)))) == (comparison (expr (atom (name Q))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))))) , (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ]))))))) (assign_part = (testlist_star_expr (test (logical_test (comparison (expr (atom (name q)))))) , (test (logical_test (comparison (expr (atom (name p)))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=2000000000 diff=0 def update(i,v): global diff d1=0 d2=0 if A[i-1]>A[i]: d1+=1 if A[i]>A[i+1]: d1+=1 A[i]=v if A[i-1]>A[i]: d2+=1 if A[i]>A[i+1]: d2+=1 diff+=(d2-d1) def solve(): global diff for i in range(1,N+1): if A[i-1]>A[i]: diff+=1 if diff==0 : return 0 q=int(input()) for i in range(1,q+1): a,b=map(int,input().split()) v1=A[a] v2=A[b] update(a,v2) update(b,v1) if diff==0 : return i return-1 N=int(input()) A=list(map(int,input().split())) A.insert(0,-INF) A.append(INF) print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute diff : OclAny; attribute diff : OclAny; operation initialise() pre: true post: true activity: var INF : int := 2000000000 ; var diff : int := 0 ; skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; A := A.insertAt(0+1, -INF) ; execute ((INF) : A) ; execute (solve())->display(); operation update(i : OclAny, v : OclAny) pre: true post: true activity: skip ; var d1 : int := 0 ; var d2 : int := 0 ; if (A[i - 1+1]->compareTo(A[i+1])) > 0 then ( d1 := d1 + 1 ) else skip ; if (A[i+1]->compareTo(A[i + 1+1])) > 0 then ( d1 := d1 + 1 ) else skip ; A[i+1] := v ; if (A[i - 1+1]->compareTo(A[i+1])) > 0 then ( d2 := d2 + 1 ) else skip ; if (A[i+1]->compareTo(A[i + 1+1])) > 0 then ( d2 := d2 + 1 ) else skip ; diff := diff + (d2 - d1); operation solve() : OclAny pre: true post: true activity: skip ; for i : Integer.subrange(1, N + 1-1) do ( if (A[i - 1+1]->compareTo(A[i+1])) > 0 then ( diff := diff + 1 ) else skip) ; if diff = 0 then ( return 0 ) else skip ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(1, q + 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var v1 : OclAny := A[a+1] ; var v2 : OclAny := A[b+1] ; update(a, v2) ; update(b, v1) ; if diff = 0 then ( return i ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a_lst=list(map(int,input().split())) q=int(input()) query=[tuple(map(int,input().split()))for _ in range(q)] comp=sorted(a_lst) diff=sum([a_lst[i]!=comp[i]for i in range(n)]) if diff==0 : print(0) else : for i in range(q): x,y=query[i] x-=1 y-=1 diff-=(a_lst[x]==comp[y])+(a_lst[y]==comp[x])-(a_lst[x]==comp[x])-(a_lst[y]==comp[y]) if diff==0 : print(i+1) break a_lst[y],a_lst[x]=a_lst[x],a_lst[y] else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a_lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var query : Sequence := Integer.subrange(0, q-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var comp : Sequence := a_lst->sort() ; var diff : OclAny := (Integer.subrange(0, n-1)->select(i | true)->collect(i | (a_lst[i+1] /= comp[i+1])))->sum() ; if diff = 0 then ( execute (0)->display() ) else ( (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name q)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name x)))))) , (test (logical_test (comparison (expr (atom (name y))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name query)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name y)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name diff)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name a_lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))) == (comparison (expr (atom (name comp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])))))))) ))) + (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name a_lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])))) == (comparison (expr (atom (name comp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))))))) )))) - (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name a_lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))) == (comparison (expr (atom (name comp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))))))) )))) - (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name a_lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])))) == (comparison (expr (atom (name comp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])))))))) )))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name diff)))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name a_lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])))))) , (test (logical_test (comparison (expr (atom (name a_lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ]))))))) (assign_part = (testlist_star_expr (test (logical_test (comparison (expr (atom (name a_lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))))) , (test (logical_test (comparison (expr (atom (name a_lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ))))))))))))))) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def FindRatio(a,b,c): up=abs(b-c) down=abs(c-a) g=gcd(up,down) up//=g down//=g print(up,":",down) a=4 b=10 c=6 FindRatio(a,b,c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 4 ; b := 10 ; c := 6 ; FindRatio(a, b, c); operation FindRatio(a : OclAny, b : OclAny, c : OclAny) pre: true post: true activity: var up : double := (b - c)->abs() ; var down : double := (c - a)->abs() ; var g : OclAny := gcd(up, down) ; up := up div g ; down := down div g ; execute (up)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline N=int(input()) X=[int(x)for x in input().split()] P=int(sum(X)/N+0.5) total=0 for x in X : kyori=(x-P)*(x-P) total+=kyori print(total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var X : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var P : int := ("" + (((X)->sum() / N + 0.5)))->toInteger() ; var total : int := 0 ; for x : X do ( var kyori : double := (x - P) * (x - P) ; total := total + kyori) ; execute (total)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): arr=input().split(' ') arr=list(map(int,arr)) L=[] for j in range(arr[0]): arr1=input().split(' ') arr1=list(map(int,arr1)) L.extend(arr1) s=0 for k in L : if k<0 : s+=1 absList=list(map(abs,L)) if s % 2==0 : print(sum(absList)) else : print(sum(absList)-min(absList)*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var arr : OclAny := input().split(' ') ; arr := ((arr)->collect( _x | (OclType["int"])->apply(_x) )) ; var L : Sequence := Sequence{} ; for j : Integer.subrange(0, arr->first()-1) do ( var arr1 : OclAny := input().split(' ') ; arr1 := ((arr1)->collect( _x | (OclType["int"])->apply(_x) )) ; L := L->union(arr1)) ; var s : int := 0 ; for k : L do ( if k < 0 then ( s := s + 1 ) else skip) ; var absList : Sequence := ((L)->collect( _x | (abs)->apply(_x) )) ; if s mod 2 = 0 then ( execute ((absList)->sum())->display() ) else ( execute ((absList)->sum() - (absList)->min() * 2)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=map(int,input().split()) c=list(map(int,input().split())) c.sort() ans=0 i=0 n=len(c) while i1 : ans+=c[i]*x x-=1 i+=1 if icollect( _x | (OclType["int"])->apply(_x) ) ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; c := c->sort() ; var ans : int := 0 ; var i : int := 0 ; var n : int := (c)->size() ; while (i->compareTo(n)) < 0 & x > 1 do ( ans := ans + c[i+1] * x ; x := x - 1 ; i := i + 1) ; if (i->compareTo(n)) < 0 then ( while (i->compareTo(n)) < 0 do ( ans := ans + c[i+1] ; i := i + 1) ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=input().split() n=int(n) x=int(x) l=[int(p)for p in input().split()] l.sort() total=0 for i in range(len(l)): total=total+x*l[i] if x!=1 : x=x-1 print(total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var x : int := ("" + ((x)))->toInteger() ; var l : Sequence := input().split()->select(p | true)->collect(p | (("" + ((p)))->toInteger())) ; l := l->sort() ; var total : int := 0 ; for i : Integer.subrange(0, (l)->size()-1) do ( total := total + x * l[i+1] ; if x /= 1 then ( x := x - 1 ) else skip) ; execute (total)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=map(int,input().rstrip().split(" ")) l=list(map(int,input().rstrip().split(" "))) l.sort() total=0 for i in range(n): if x<1 : x=1 total+=l[i]*x x-=1 print(total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().rstrip().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().rstrip().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; l := l->sort() ; var total : int := 0 ; for i : Integer.subrange(0, n-1) do ( if x < 1 then ( var x : int := 1 ) else skip ; total := total + l[i+1] * x ; x := x - 1) ; execute (total)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,c=map(int,input().split()) t=sorted(list(map(int,input().split()))) sum=0 for i in t : sum+=c*i if c>1 : c-=1 print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var sum : int := 0 ; for i : t do ( sum := sum + c * i ; if c > 1 then ( c := c - 1 ) else skip) ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- subjects,initial=map(int,input().split()); arr=list(map(int,input().split())); arr.sort(); summ=0 for i in arr : summ+=i*initial if initial>=2 : initial-=1 print(summ) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var subjects : OclAny := null; var initial : OclAny := null; Sequence{subjects,initial} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); arr := arr->sort(); var summ : int := 0 ; for i : arr do ( summ := summ + i * initial ; if initial >= 2 then ( initial := initial - 1 ) else skip) ; execute (summ)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairs(str1): result=0 ; n=len(str1) for i in range(0,n): for j in range(i+1,n): if(abs(ord(str1[i])-ord(str1[j]))==abs(i-j)): result+=1 ; return result ; if __name__=="__main__" : str1="geeksforgeeks" ; print(countPairs(str1)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( str1 := "geeksforgeeks"; ; execute (countPairs(str1))->display(); ) else skip; operation countPairs(str1 : OclAny) pre: true post: true activity: var result : int := 0; ; var n : int := (str1)->size() ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if (((str1[i+1])->char2byte() - (str1[j+1])->char2byte())->abs() = (i - j)->abs()) then ( result := result + 1; ) else skip)) ; return result;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_CHAR=26 def countPairs(str1): result=0 ; n=len(str1) for i in range(0,n): for j in range(1,MAX_CHAR+1): if((i+j)display() ) else skip; operation countPairs(str1 : OclAny) : OclAny pre: true post: true activity: var result : int := 0; ; var n : int := (str1)->size() ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(1, MAX_CHAR + 1-1) do ( if (((i + j)->compareTo(n)) < 0) then ( if ((((str1[i + j+1])->char2byte() - (str1[i+1])->char2byte())->abs() = j)) then ( result := result + 1; ) else skip ) else skip)) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) cities=list(map(int,input().split())) cities.sort() min_lenth=10**11 col=0 for i in range(n-1): if cities[i+1]-cities[i]toInteger() ; var cities : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; cities := cities->sort() ; var min_lenth : double := (10)->pow(11) ; var col : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if (cities[i + 1+1] - cities[i+1]->compareTo(min_lenth)) < 0 then ( min_lenth := cities[i + 1+1] - cities[i+1] ; col := 1 ) else (if cities[i + 1+1] - cities[i+1] = min_lenth then ( col := col + 1 ) else skip)) ; execute (min_lenth)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) w=sorted(map(int,input().split())) w=[abs(j-i)for i,j in zip(w,w[1 :])] c=min(w) print(c,w.count(c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; w := Integer.subrange(1, w->size())->collect( _indx | Sequence{w->at(_indx), w->tail()->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let j : OclAny = _tuple->at(2) in ((j - i)->abs())) ; var c : OclAny := (w)->min() ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) num=list(map(int,input().split())) num.sort() min=num[n-1]-num[0] count=0 for i in range(n-1): x=num[i+1]-num[i] if(x==min): count+=1 if(xtoInteger() ; var num : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; num := num->sort() ; var min : double := num[n - 1+1] - num->first() ; var count : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( var x : double := num[i + 1+1] - num[i+1] ; if (x = min) then ( count := count + 1 ) else skip ; if ((x->compareTo(min)) < 0) then ( min := x ; count := 1 ) else skip) ; execute (min)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() for i in range(int(input())): n,m=map(int,input().split()) l,k=[],0 for i in range(n): l+=[*map(int,input().split())] for i in range(n*m): if l[i]<0 : k+=1 ; l[i]*=-1 print(sum(l)-k % 2*min(l)*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : OclAny := null; var k : OclAny := null; Sequence{l,k} := Sequence{Sequence{},0} ; for i : Integer.subrange(0, n-1) do ( l := l + (input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n * m-1) do ( if l[i+1] < 0 then ( k := k + 1; l[i+1] := l[i+1] * -1 ) else skip) ; execute ((l)->sum() - k mod 2 * (l)->min() * 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import os def calc(x,p): return pow(x-p,2) def main(): if os.getenv("LOCAL"): sys.stdin=open("input.txt","r") N=int(sys.stdin.readline().rstrip()) X=list(map(int,sys.stdin.readline().split())) ret=float('inf') for p in range(100): tmp=0 for n in range(N): tmp+=calc(X[n],p) ret=min(tmp,ret) print(ret) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation calc(x : OclAny, p : OclAny) : OclAny pre: true post: true activity: return (x - p)->pow(2); operation main() pre: true post: true activity: if os.getenv("LOCAL") then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ) else skip ; var N : int := ("" + ((sys.stdin.readLine().rstrip())))->toInteger() ; var X : Sequence := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ret : double := ("" + (('inf')))->toReal() ; for p : Integer.subrange(0, 100-1) do ( var tmp : int := 0 ; for n : Integer.subrange(0, N-1) do ( tmp := tmp + calc(X[n+1], p)) ; ret := Set{tmp, ret}->min()) ; execute (ret)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cities=int(input()) city_coordinate=list(map(int,input().split(' '))) city_coordinate.sort() distance=[] for i in range(1,cities): distance.append(city_coordinate[i]-city_coordinate[i-1]) shortest_distance=min(distance) quantity_of_pairs=0 for i in range(1,cities): if city_coordinate[i]-city_coordinate[i-1]==shortest_distance : quantity_of_pairs+=1 print(shortest_distance,quantity_of_pairs) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cities : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var city_coordinate : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; city_coordinate := city_coordinate->sort() ; var distance : Sequence := Sequence{} ; for i : Integer.subrange(1, cities-1) do ( execute ((city_coordinate[i+1] - city_coordinate[i - 1+1]) : distance)) ; var shortest_distance : OclAny := (distance)->min() ; var quantity_of_pairs : int := 0 ; for i : Integer.subrange(1, cities-1) do ( if city_coordinate[i+1] - city_coordinate[i - 1+1] = shortest_distance then ( quantity_of_pairs := quantity_of_pairs + 1 ) else skip) ; execute (shortest_distance)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def shortestPath(a): if len(a)<=3 : a.sort() d=2_000_000_000 for i in range(1,len(a)): d=min(d,a[i]-a[i-1]) return d else : mid=len(a)//2 left_a=a[: mid] right_a=a[mid :] p=shortestPath(left_a) q=shortestPath(right_a) r=min(right_a)-max(left_a) return min(p,q,r) def solve(n,a): a.sort() d=shortestPath(a) cnt=0 for i in range(1,n): cnt+=int(a[i]-a[i-1]==d) print(d,cnt) def main(): n=int(input()) a=[int(x)for x in input().split(' ')] solve(n,a) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation shortestPath(a : OclAny) : OclAny pre: true post: true activity: if (a)->size() <= 3 then ( a := a->sort() ; var d : int := 2_000_000_000 ; for i : Integer.subrange(1, (a)->size()-1) do ( d := Set{d, a[i+1] - a[i - 1+1]}->min()) ; return d ) else ( var mid : int := (a)->size() div 2 ; var left_a : OclAny := a.subrange(1,mid) ; var right_a : OclAny := a.subrange(mid+1) ; var p : OclAny := shortestPath(left_a) ; var q : OclAny := shortestPath(right_a) ; var r : double := (right_a)->min() - (left_a)->max() ; return Set{p, q, r}->min() ); operation solve(n : OclAny, a : OclAny) pre: true post: true activity: a := a->sort() ; d := shortestPath(a) ; var cnt : int := 0 ; for i : Integer.subrange(1, n-1) do ( cnt := cnt + ("" + ((a[i+1] - a[i - 1+1] = d)))->toInteger()) ; execute (d)->display(); operation main() pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; solve(n, a); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) t=list(input()) i,m=0,n//2 if k>m : k=m+((m+k)& 1) while k and icollect( _x | (OclType["int"])->apply(_x) ) ; var t : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var i : OclAny := null; var m : OclAny := null; Sequence{i,m} := Sequence{0,n div 2} ; if (k->compareTo(m)) > 0 then ( var k : OclAny := m + (MathLib.bitwiseAnd((m + k), 1)) ) else skip ; while k & (i->compareTo(n - 1)) < 0 do ( if t[i+1] = '4' & t[i + 1+1] = '7' then ( k := k - 1 ; if MathLib.bitwiseAnd(i, 1) = 0 then ( t[i + 1+1] := '4' ) else ( t[i+1] := '7' ; i := i - 2 ) ) else skip ; i := i + 1) ; execute (StringLib.sumStringsWithSeparator((t), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) s=list(input()) for i in range(10): s.append('0') i=0 while icollect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; for i : Integer.subrange(0, 10-1) do ( execute (('0') : s)) ; var i : int := 0 ; while (i->compareTo(n)) < 0 & k do ( if s[i+1] = '4' & s[i + 1+1] = '7' & s[i + 2+1] = '7' & not((MathLib.bitwiseAnd(i, 1))) then ( k := k mod 2 ) else skip ; if k & s[i+1] = '4' & s[i + 1+1] = '7' then ( if MathLib.bitwiseAnd(i, 1) then ( s[i+1] := s[i + 1+1] ) else ( s[i + 1+1] := s[i+1] ) ; i := i - 2 ; k := k - 1 ) else skip ; i := i + 1) ; var ans : String := '' ; for i : Integer.subrange(0, n-1) do ( ans := ans + s[i+1]) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) s=list(input()) i=0 while i0 : if s[i]=='4' and s[i+1]=='7' : k-=1 if(i % 2)==0 : s[i]='4' s[i+1]='4' else : s[i]='7' if i-1>=0 and s[i-1]=='4' : i-=2 k=k % 2 i+=1 print(''.join(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var i : int := 0 ; while (i->compareTo(n - 1)) < 0 & k > 0 do ( if s[i+1] = '4' & s[i + 1+1] = '7' then ( k := k - 1 ; if (i mod 2) = 0 then ( s[i+1] := '4' ; s[i + 1+1] := '4' ) else ( s[i+1] := '7' ; if i - 1 >= 0 & s[i - 1+1] = '4' then ( i := i - 2 ; var k : int := k mod 2 ) else skip ) ) else skip ; i := i + 1) ; execute (StringLib.sumStringsWithSeparator((s), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) s=[*input()]+[0,0] i=1 while k and i<=n : if s[i-1]=="4" and s[i]=="7" and s[i+1]=="7" and i % 2 : if k % 2 : s[i]="4" break elif s[i-1]=="4" and s[i]=="4" and s[i+1]=="7" and i % 2 : if k % 2 : s[i]="7" break elif s[i-1]=="4" and s[i]=="7" : if i % 2 : s[i]="4" else : s[i-1]="7" k-=1 i+=1 print("".join(s[: n])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := (OclFile["System.in"]).readLine()->union(Sequence{0}->union(Sequence{ 0 })) ; var i : int := 1 ; while k & (i->compareTo(n)) <= 0 do ( if s[i - 1+1] = "4" & s[i+1] = "7" & s[i + 1+1] = "7" & i mod 2 then ( if k mod 2 then ( s[i+1] := "4" ) else skip ; break ) else (if s[i - 1+1] = "4" & s[i+1] = "4" & s[i + 1+1] = "7" & i mod 2 then ( if k mod 2 then ( s[i+1] := "7" ) else skip ; break ) else (if s[i - 1+1] = "4" & s[i+1] = "7" then ( if i mod 2 then ( s[i+1] := "4" ) else ( s[i - 1+1] := "7" ) ; k := k - 1 ) else skip ) ) ; i := i + 1) ; execute (StringLib.sumStringsWithSeparator((s.subrange(1,n)), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) ans=0 d,s=1,0 while True : while d*kn : break s+=d ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; var d : OclAny := null; var s : OclAny := null; Sequence{d,s} := Sequence{1,0} ; while true do ( while (d * k->compareTo(s)) < 0 do ( d := d + 1) ; if (s + d->compareTo(n)) > 0 then ( break ) else skip ; s := s + d ; ans := ans + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=[int(i)for i in input().split()] weight=1 ans=1 N-=1 while N>0 : d=0 if weight % K==0 : d=weight//K else : d=weight//K+1 N-=d weight+=d if N>=0 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var weight : int := 1 ; var ans : int := 1 ; N := N - 1 ; while N > 0 do ( var d : int := 0 ; if weight mod K = 0 then ( d := weight div K ) else ( d := weight div K + 1 ) ; N := N - d ; weight := weight + d ; if N >= 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) res=0 row=1 w=0 while n>=row : if row*k>=w : res+=1 w+=row n-=row elif n>=row+1 : row+=1 else : break print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var res : int := 0 ; var row : int := 1 ; var w : int := 0 ; while (n->compareTo(row)) >= 0 do ( if (row * k->compareTo(w)) >= 0 then ( res := res + 1 ; w := w + row ; n := n - row ) else (if (n->compareTo(row + 1)) >= 0 then ( row := row + 1 ) else ( break ) ) ) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def makeAP(arr,n): initial_term,common_difference=0,0 if(n==3): common_difference=arr[2]-arr[1] initial_term=arr[1]-common_difference elif((arr[1]-arr[0])==arr[2]-arr[1]): initial_term=arr[0] common_difference=arr[1]-arr[0] elif((arr[2]-arr[1])==(arr[3]-arr[2])): common_difference=arr[2]-arr[1] initial_term=arr[1]-common_difference else : common_difference=(arr[3]-arr[0])/3 initial_term=arr[0] for i in range(n): print(int(initial_term+(i*common_difference)),end=" ") print() arr=[1,3,7] n=len(arr) makeAP(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{3}->union(Sequence{ 7 })) ; n := (arr)->size() ; makeAP(arr, n); operation makeAP(arr : OclAny, n : OclAny) pre: true post: true activity: var initial_term : OclAny := null; var common_difference : OclAny := null; Sequence{initial_term,common_difference} := Sequence{0,0} ; if (n = 3) then ( var common_difference : double := arr[2+1] - arr[1+1] ; var initial_term : double := arr[1+1] - common_difference ) else (if ((arr[1+1] - arr->first()) = arr[2+1] - arr[1+1]) then ( initial_term := arr->first() ; common_difference := arr[1+1] - arr->first() ) else (if ((arr[2+1] - arr[1+1]) = (arr[3+1] - arr[2+1])) then ( common_difference := arr[2+1] - arr[1+1] ; initial_term := arr[1+1] - common_difference ) else ( common_difference := (arr[3+1] - arr->first()) / 3 ; initial_term := arr->first() ) ) ) ; for i : Integer.subrange(0, n-1) do ( execute (("" + ((initial_term + (i * common_difference))))->toInteger())->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,k=map(int,input().split()) ret=1 acc=1 while True : want=math.ceil(acc/k) if(want+acc>n): break acc+=want ret+=1 print(ret) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ret : int := 1 ; var acc : int := 1 ; while true do ( var want : double := (acc / k)->ceil() ; if ((want + acc->compareTo(n)) > 0) then ( break ) else skip ; acc := acc + want ; ret := ret + 1) ; execute (ret)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=list(map(int,input().split())) ans=[] if len(set(x))==1 : print(0) else : for p in range(min(x),max(x)): meter=0 for xi in x : meter+=pow((xi-p),2) ans.append(meter) print(min(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : Sequence := Sequence{} ; if (Set{}->union((x)))->size() = 1 then ( execute (0)->display() ) else ( for p : Integer.subrange((x)->min(), (x)->max()-1) do ( var meter : int := 0 ; for xi : x do ( meter := meter + ((xi - p))->pow(2)) ; execute ((meter) : ans)) ; execute ((ans)->min())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=(int(x)for x in input().split()) t=1 r=N-1 s=1 while True : b=s//K+1 if s % K else s//K if r>=b : r-=b s+=b t+=1 else : break print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var t : int := 1 ; var r : double := N - 1 ; var s : int := 1 ; while true do ( var b : int := if s mod K then s div K + 1 else s div K endif ; if (r->compareTo(b)) >= 0 then ( r := r - b ; s := s + b ; t := t + 1 ) else ( break )) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import reduce from fractions import gcd import math import bisect import itertools import sys input=sys.stdin.readline INF=float("inf") def main(): N,Q=map(int,input().split()) h=N w=N a=[N]*N b=[N]*N ans=(N-2)**2 for _ in range(Q): q,x=map(int,input().split()) if q==1 : if xtoReal() ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var Q : OclAny := null; Sequence{N,Q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h : OclAny := N ; var w : OclAny := N ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ N }, N) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ N }, N) ; var ans : double := ((N - 2))->pow(2) ; for _anon : Integer.subrange(0, Q-1) do ( var q : OclAny := null; var x : OclAny := null; Sequence{q,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if q = 1 then ( if (x->compareTo(w)) < 0 then ( for i : Integer.subrange(x, w-1) do ( b[i+1] := h) ; w := x ) else skip ; ans := ans - b[x+1] - 2 ) else (if q = 2 then ( if (x->compareTo(h)) < 0 then ( for i : Integer.subrange(x, h-1) do ( a[i+1] := w) ; h := x ) else skip ; ans := ans - a[x+1] - 2 ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np from numba import njit from numba.types import int64 i8=np.int64 @ njit((int64,int64[:,: :-1]),cache=True) def solve(n,qr): col=np.zeros(n-1,i8) col[0]=0 col_min=n-1 row=np.zeros(n-1,i8) row[0]=0 row_min=n-1 white=0 for i in range(qr.shape[0]): j=qr[i,1]-1 if qr[i,0]==1 : if jselect(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var qr : OclAny := np.fromstring(f.readAll(), i8, (argument (test (logical_test (comparison (expr (atom (name sep)))))) = (test (logical_test (comparison (expr (atom ' '))))))).reshape(Sequence{-1, 2}) ; var white : OclAny := solve(n, qr) ; execute (((n - 2))->pow(2) - white)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=lambda : map(int,input().split()) N,Q=f() a,b=N,N black=(N-2)*(N-2) B=[-1]*(N+1) W=[-1]*(N+1) for _ in range(Q): q,x=f() if q==1 : if B[x]>0 : black-=B[x] B[x]=0 else : black-=b-2 a=x for j in range(a+1,N+1): if B[j]==-1 : B[j]=b-2 else : break if j==N-1 : break else : if W[x]>0 : black-=W[x] W[x]=0 else : black-=a-2 b=x for j in range(b+1,N+1): if W[j]==-1 : W[j]=a-2 else : break if j==N-1 : break print(black) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var N : OclAny := null; var Q : OclAny := null; Sequence{N,Q} := f->apply() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{N,N} ; var black : double := (N - 2) * (N - 2) ; var B : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (N + 1)) ; var W : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (N + 1)) ; for _anon : Integer.subrange(0, Q-1) do ( var q : OclAny := null; var x : OclAny := null; Sequence{q,x} := f->apply() ; if q = 1 then ( if B[x+1] > 0 then ( black := black - B[x+1] ; B[x+1] := 0 ) else ( black := black - b - 2 ; var a : OclAny := x ; for j : Integer.subrange(a + 1, N + 1-1) do ( if B[j+1] = -1 then ( B[j+1] := b - 2 ) else ( break ) ; if j = N - 1 then ( break ) else skip) ) ) else ( if W[x+1] > 0 then ( black := black - W[x+1] ; W[x+1] := 0 ) else ( black := black - a - 2 ; var b : OclAny := x ; for j : Integer.subrange(b + 1, N + 1-1) do ( if W[j+1] = -1 then ( W[j+1] := a - 2 ) else ( break ) ; if j = N - 1 then ( break ) else skip) ) )) ; execute (black)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.buffer.readline()[:-1] n,q=map(int,input().split()) ans=(n-2)*(n-2) v,h=[(n,n)],[(n,n)] for _ in range(q): k,x=map(int,input().split()) if k==1 : l,r=0,len(h) while r-l>1 : m=(l+r)//2 if h[m][0]>=x : l=m else : r=m ans-=h[l][1]-2 if x1 : m=(l+r)//2 if v[m][0]>=x : l=m else : r=m ans-=v[l][1]-2 if xcollect( _x | (OclType["int"])->apply(_x) ) ; var ans : double := (n - 2) * (n - 2) ; var v : OclAny := null; var h : OclAny := null; Sequence{v,h} := Sequence{Sequence{ Sequence{n, n} },Sequence{ Sequence{n, n} }} ; for _anon : Integer.subrange(0, q-1) do ( var k : OclAny := null; var x : OclAny := null; Sequence{k,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if k = 1 then ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,(h)->size()} ; while r - l > 1 do ( var m : int := (l + r) div 2 ; if (h[m+1]->first()->compareTo(x)) >= 0 then ( var l : int := m ) else ( var r : int := m )) ; ans := ans - h[l+1][1+1] - 2 ; if (x->compareTo(v->last()[1+1])) < 0 then ( execute ((Sequence{h[l+1][1+1] - 1, x}) : v) ) else skip ) else ( Sequence{l,r} := Sequence{0,(v)->size()} ; while r - l > 1 do ( m := (l + r) div 2 ; if (v[m+1]->first()->compareTo(x)) >= 0 then ( l := m ) else ( r := m )) ; ans := ans - v[l+1][1+1] - 2 ; if (x->compareTo(h->last()[1+1])) < 0 then ( execute ((Sequence{v[l+1][1+1] - 1, x}) : h) ) else skip )) ; execute (ans)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.buffer.readLine()->front(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class F : def __init__(self,x): self.bit=x for i in range(len(x)): j=i |(i+1) if j=self.bit[right_idx]: idx=right_idx k-=self.bit[idx] return idx+1 import sys z=sys.stdin.readline y=lambda : map(int,z().split()) n,q=y() v=F([0]*(n-2)) h=F([0]*(n-2)) w=j=n-2 s=0 for _ in range(q): a,b=y() if a<2 : if b-2exists( _x | result = _x ); attribute bit : OclAny := x; operation initialise(x : OclAny) : F pre: true post: true activity: self.bit := x ; for i : Integer.subrange(0, (x)->size()-1) do ( var j : int := MathLib.bitwiseOr(i, (i + 1)) ; if (j->compareTo((x)->size())) < 0 then ( x[j+1] := x[j+1] + x[i+1] ) else skip); return self; operation update(idx : OclAny,x : OclAny) pre: true post: true activity: while (idx->compareTo((self.bit)->size())) < 0 do ( self.bit[idx+1] := self.bit[idx+1] + x ; idx := idx or idx + 1); operation query(end : OclAny) : OclAny pre: true post: true activity: x := 0 ; while end do ( x := x + self.bit[end - 1+1] ; end := end & end - 1) ; return x; operation findkth(k : OclAny) : OclAny pre: true post: true activity: idx := -1 ; for d : (Integer.subrange(0, len(self.bit).bit_length()-1))->reverse() do ( var right_idx : OclAny := idx + (1 * (2->pow(d))) ; if (right_idx->compareTo((self.bit)->size())) < 0 & (k->compareTo(self.bit[right_idx+1])) >= 0 then ( idx := right_idx ; k := k - self.bit[idx+1] ) else skip) ; return idx + 1; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var z : OclAny := (OclFile["System.in"]).readline ; var y : Function := lambda $$ : OclAny in ((z().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := y->apply() ; var v : F := (F.newF()).initialise(MatrixLib.elementwiseMult(Sequence{ 0 }, (n - 2))) ; var h : F := (F.newF()).initialise(MatrixLib.elementwiseMult(Sequence{ 0 }, (n - 2))) ; var w : OclAny := n - 2; j := n - 2 ; var s : int := 0 ; for _anon : Integer.subrange(0, q-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := y->apply() ; if a < 2 then ( if (b - 2->compareTo(w)) < 0 then ( execute ((n - 2 - j, w - b + 2) <: h); w := b - 2 ) else skip ; s := s + n - 2 - v.query(n - b) ) else ( if (b - 2->compareTo(j)) < 0 then ( execute ((n - 2 - w, j - b + 2) <: v); j := b - 2 ) else skip ; s := s + n - 2 - h.query(n - b) )) ; execute ((n - 2) * (n - 2) - s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def generateSequence(n,g): for i in range(1,n+1): print(i*g,end=" ") if __name__=="__main__" : n,g=6,5 generateSequence(n,g) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{n,g} := Sequence{6,5} ; generateSequence(n, g) ) else skip; operation generateSequence(n : OclAny, g : OclAny) pre: true post: true activity: for i : Integer.subrange(1, n + 1-1) do ( execute (i * g)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def geometricMean(n): return int(sqrt(n)); if __name__=="__main__" : n=16 ; print(geometricMean(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 16; ; execute (geometricMean(n))->display(); ) else skip; operation geometricMean(n : OclAny) pre: true post: true activity: return ("" + ((sqrt(n))))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) s=input() print(n//2-max(s.count('10'),s.count('01'))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; execute (n div 2 - Set{s->count('10'), s->count('01')}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculateSum(n): return(n*(n+1)//2+pow((n*(n+1)//2),2)) n=3 print("Sum=",calculateSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3 ; execute ("Sum=")->display(); operation calculateSum(n : OclAny) : OclAny pre: true post: true activity: return (n * (n + 1) div 2 + ((n * (n + 1) div 2))->pow(2)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def sumOfSeries(n): return 0.0246*(math.pow(10,n)-1-(9*n)) n=3 print(sumOfSeries(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 3 ; execute (sumOfSeries(n))->display(); operation sumOfSeries(n : OclAny) : OclAny pre: true post: true activity: return 0.0246 * ((10)->pow(n) - 1 - (9 * n)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) min_=10000000 sum_=0 X=input().split() for t in range(1,101): for i in range(N): tmp=int(X[i]) sum_+=(tmp-t)**2 if min_>sum_ : min_=sum_ sum_=0 print(min_) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var min_ : int := 10000000 ; var sum_ : int := 0 ; var X : OclAny := input().split() ; for t : Integer.subrange(1, 101-1) do ( for i : Integer.subrange(0, N-1) do ( var tmp : int := ("" + ((X[i+1])))->toInteger() ; sum_ := sum_ + ((tmp - t))->pow(2)) ; if (min_->compareTo(sum_)) > 0 then ( min_ := sum_ ) else skip ; sum_ := 0) ; execute (min_)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfSeries(n): return(int)(0.6172*(pow(10,n)-1)-0.55*n) n=2 print(sumOfSeries(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 2 ; execute (sumOfSeries(n))->display(); operation sumOfSeries(n : OclAny) : OclAny pre: true post: true activity: return (OclType["int"])(0.6172 * ((10)->pow(n) - 1) - 0.55 * n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count(n): return pow(2,n-1) n=4 print(count(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute (count(n))->display(); operation count(n : OclAny) : OclAny pre: true post: true activity: return (2)->pow(n - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numbers(n): return pow(2,n+1)-2 n=2 print(numbers(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 2 ; execute (numbers(n))->display(); operation numbers(n : OclAny) : OclAny pre: true post: true activity: return (2)->pow(n + 1) - 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculateSum(n): return(n*(n+1)/2)**2 if __name__=='__main__' : n=4 print(calculateSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 4 ; execute (calculateSum(n))->display() ) else skip; operation calculateSum(n : OclAny) : OclAny pre: true post: true activity: return ((n * (n + 1) / 2))->pow(2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculateSum(n): return((2*(n*(n+1)/2)**2)+((n*(n+1)*(2*n+1))/6)) n=4 print("Sum=",calculateSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute ("Sum=")->display(); operation calculateSum(n : OclAny) : OclAny pre: true post: true activity: return ((2 * ((n * (n + 1) / 2))->pow(2)) + ((n * (n + 1) * (2 * n + 1)) / 6)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def count(n): return(-1+sqrt(1+8*n))//2 ; if __name__=="__main__" : n=10 ; print(count(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 10; ; execute (count(n))->display(); ) else skip; operation count(n : OclAny) pre: true post: true activity: return (-1 + sqrt(1 + 8 * n)) div 2;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nDigitPalindromes(n): return(9*pow(10,(n-1)//2)); if __name__=="__main__" : n=2 ; print(nDigitPalindromes(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 2; ; execute (nDigitPalindromes(n))->display(); ) else skip; operation nDigitPalindromes(n : OclAny) pre: true post: true activity: return (9 * (10)->pow((n - 1) div 2));; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def C(k,a): if a==0 : return 1 return math.factorial(k)/(math.factorial(a)*math.factorial(k-a)) def Cal(k,a): sum=0 for i in range(a,k+1): sum+=C(k,i) return sum*1.0/2**k T=int(raw_input()) for i in range(1,T+1): input=raw_input() b=input.split(" ") c=[int(e)for e in b] N=c[0] X=c[1] Y=c[2] if X<0 : X=-X if(X+Y)% 2==1 : p=0 elif X+Y==0 : p=1 elif X==0 : level=Y/2+2 btm=(2*level-3)*(level-1) if N>=btm : p=1 else : p=0 else : level=(X+Y)/2+1 btm=(2*level-3)*(level-1)+Y+1 level2=level+1 upper=(2*level2-3)*(level2-1)-X if N=upper : p=1 else : left=N-(2*level-3)*(level-1); a=Y+1 p=Cal(left,a) print("Case #"+str(i)+": "+str(p)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var T : int := ("" + ((raw_input())))->toInteger() ; for i : Integer.subrange(1, T + 1-1) do ( var input : OclAny := raw_input() ; var b : String := (OclFile["System.in"]).readLine.split(" ") ; var c : Sequence := b->characters()->select(e | true)->collect(e | (("" + ((e)))->toInteger())) ; var N : OclAny := c->first() ; var X : OclAny := c[1+1] ; var Y : OclAny := c[2+1] ; if X < 0 then ( X := -X ) else skip ; if (X + Y) mod 2 = 1 then ( var p : int := 0 ) else (if X + Y = 0 then ( p := 1 ) else (if X = 0 then ( var level : double := Y / 2 + 2 ; var btm : double := (2 * level - 3) * (level - 1) ; if (N->compareTo(btm)) >= 0 then ( p := 1 ) else ( p := 0 ) ) else ( level := (X + Y) / 2 + 1 ; btm := (2 * level - 3) * (level - 1) + Y + 1 ; var level2 : OclAny := level + 1 ; var upper : double := (2 * level2 - 3) * (level2 - 1) - X ; if (N->compareTo(btm)) < 0 then ( p := 0 ) else (if (N->compareTo(upper)) >= 0 then ( p := 1 ) else ( var left : double := N - (2 * level - 3) * (level - 1); ; a := Y + 1 ; p := Cal(left, a) ) ) ) ) ) ; execute ("Case #" + ("" + ((i))) + ": " + ("" + ((p))))->display()); operation C(k : OclAny, a : OclAny) : OclAny pre: true post: true activity: if a = 0 then ( return 1 ) else skip ; return MathLib.factorial(k) / (MathLib.factorial(a) * MathLib.factorial(k - a)); operation Cal(k : OclAny, a : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(a, k + 1-1) do ( sum := sum + C(k, i)) ; return sum * 1.0 / (2)->pow(k); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairs(n): count=0 ; for x in range(1,n): for y in range(x+1,n+1): if((y+x)%(y ^ x)==0): count+=1 ; return count ; if __name__=="__main__" : n=6 ; print(countPairs(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 6; ; execute (countPairs(n))->display(); ) else skip; operation countPairs(n : OclAny) pre: true post: true activity: var count : int := 0; ; for x : Integer.subrange(1, n-1) do ( for y : Integer.subrange(x + 1, n + 1-1) do ( if ((y + x) mod (MathLib.bitwiseXor(y, x)) = 0) then ( count := count + 1; ) else skip)) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count(n): return 15*pow(16,n-1); if __name__=="__main__" : n=2 ; print(count(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 2; ; execute (count(n))->display(); ) else skip; operation count(n : OclAny) pre: true post: true activity: return 15 * (16)->pow(n - 1);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def sumOfSeries(n): return((0.666)*(1-1/pow(10,n))); n=2 ; print(sumOfSeries(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 2; ; execute (sumOfSeries(n))->display();; operation sumOfSeries(n : OclAny) pre: true post: true activity: return ((0.666) * (1 - 1 / (10)->pow(n)));; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def smallestMultiple(n): if(n==1): return 5 return pow(10,n-1) n=4 print(smallestMultiple(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute (smallestMultiple(n))->display(); operation smallestMultiple(n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return 5 ) else skip ; return (10)->pow(n - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()); a=1 while k % 2==0 : a+=1 ; k//=2 print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var a : int := 1 ; while k mod 2 = 0 do ( a := a + 1; k := k div 2) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def totalNumber(n): return 8*pow(9,n-1); n=3 print(totalNumber(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3 ; execute (totalNumber(n))->display(); operation totalNumber(n : OclAny) pre: true post: true activity: return 8 * (9)->pow(n - 1);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getChicks(n): chicks=pow(3,n-1) return chicks if __name__=="__main__" : n=3 print(getChicks(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 3 ; execute (getChicks(n))->display() ) else skip; operation getChicks(n : OclAny) : OclAny pre: true post: true activity: var chicks : double := (3)->pow(n - 1) ; return chicks; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) cnt=0 if n==0 : print(0) exit() while 2**cnttoInteger() ; var cnt : int := 0 ; if n = 0 then ( execute (0)->display() ; exit() ) else skip ; while ((2)->pow(cnt)->compareTo(n)) < 0 do ( cnt := cnt + 1) ; if (2)->pow(cnt) = n then ( cnt := cnt + 1 ) else skip ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(0*(n==0)+len(str(bin(n))[2 :])*(n!=0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (0 * (n = 0) + (OclType["String"](bin(n)).subrange(2+1))->size() * (n /= 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) ans=0 while(N): N//=2 ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; while (N) do ( N := N div 2 ; ans := ans + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) print(len(bin(N))-2 if N>0 else 0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (if N > 0 then (bin(N))->size() - 2 else 0 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairs(n): count=0 for x in range(1,n): for y in range(x+1,n+1): if((y*x)%(y+x)==0): count+=1 return count n=15 print(countPairs(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 15 ; execute (countPairs(n))->display(); operation countPairs(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for x : Integer.subrange(1, n-1) do ( for y : Integer.subrange(x + 1, n + 1-1) do ( if ((y * x) mod (y + x) = 0) then ( count := count + 1 ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a=int(input()),0 while n : n>>=1 a+=1 print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),0} ; while n do ( n := n div (2->pow(1)) ; a := a + 1) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def answer(): n=int(input()) a=list(map(int,input().split(' '))) temp=1 for i in range(n): while(a[i]% 2==0): a[i]//=2 temp*=2 a.sort() a[-1]*=temp print(sum(a)) n=int(input()) for i in range(n): answer() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( answer()); operation answer() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var temp : int := 1 ; for i : Integer.subrange(0, n-1) do ( while (a[i+1] mod 2 = 0) do ( a[i+1] := a[i+1] div 2 ; temp := temp * 2)) ; a := a->sort() ; a->last() := a->last() * temp ; execute ((a)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for _ in range(T): N=int(input()) A=list(map(int,input().split())) cnt=0 for i in range(N): while A[i]% 2==0 : A[i]//=2 cnt+=1 M=max(A) for _ in range(cnt): M*=2 print(M+sum(A)-max(A)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, T-1) do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : int := 0 ; for i : Integer.subrange(0, N-1) do ( while A[i+1] mod 2 = 0 do ( A[i+1] := A[i+1] div 2 ; cnt := cnt + 1)) ; var M : OclAny := (A)->max() ; for _anon : Integer.subrange(0, cnt-1) do ( M := M * 2) ; execute (M + (A)->sum() - (A)->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: *a,=map(int,s.split()); i=0 ; k=1 for x in a : x &=-x ; a[i]//=x ; k*=x ; i+=1 print(sum(a)+max(a)*(k-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( ; (testlist_star_expr (star_expr * (expr (atom (name a)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name a)))) ,)} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ); var i : int := 0; var k : int := 1 ; for x : a do ( x := x & -x; a[i+1] := a[i+1] div x; k := k * x; i := i + 1) ; execute ((a)->sum() + (a)->max() * (k - 1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,k=map(int,input().split()) if k % 2 : print(1) else : for i in range(1,n+1): if(k-2**i)% 2**(i+1)==0 : print(i+1) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if k mod 2 then ( execute (1)->display() ) else ( for i : Integer.subrange(1, n + 1-1) do ( if (k - (2)->pow(i)) mod (2)->pow((i + 1)) = 0 then ( execute (i + 1)->display() ; break ) else skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def is_prime(n): for i in range(2,int(math.sqrt(n))+1): if(n % i)==0 : return False return True t=int(input()) while(t!=0): n=int(input()) a=list(map(int,input().split())) max=0 sum=0 count=0 for i in range(0,n): while a[i]% 2==0 : a[i]/=2 count+=1 for i in a : if i>max : max=i sum+=i result=sum-max+max*2**count print(int(result)) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (t /= 0) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var max : int := 0 ; var sum : int := 0 ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( while a[i+1] mod 2 = 0 do ( a[i+1] := a[i+1] / 2 ; count := count + 1)) ; for i : a do ( if (i->compareTo(max)) > 0 then ( max := i ) else skip ; sum := sum + i) ; var result : double := sum - max + max * (2)->pow(count) ; execute (("" + ((result)))->toInteger())->display() ; t := t - 1); operation is_prime(n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(2, ("" + (((n)->sqrt())))->toInteger() + 1-1) do ( if (n mod i) = 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) a=list(map(int,input().split())) u=1 for j in range(n): while a[j]% 2==0 : a[j]//=2 u*=2 a=sorted(a) a[-1]*=u print(sum(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var u : int := 1 ; for j : Integer.subrange(0, n-1) do ( while a[j+1] mod 2 = 0 do ( a[j+1] := a[j+1] div 2 ; u := u * 2)) ; a := a->sort() ; a->last() := a->last() * u ; execute ((a)->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxOnesIndex(arr,n): i=0 leftCnt=0 rightCnt=0 maxIndex=-1 lastInd=-1 maxCnt=0 while imaxCnt : maxCnt=leftCnt+rightCnt+1 maxIndex=lastInd lastInd=i leftCnt=rightCnt rightCnt=0 i+=1 if lastInd!=-1 : if leftCnt+rightCnt+1>maxCnt : maxCnt=leftCnt+rightCnt+1 maxIndex=lastInd return maxIndex if __name__=="__main__" : arr=[1,1,0,0,1,0,1,1,1,0,1,1,1] n=len(arr) print("Index of 0 to be replaced is",maxOnesIndex(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })))))))))))) ; n := (arr)->size() ; execute ("Index of 0 to be replaced is")->display() ) else skip; operation maxOnesIndex(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; var leftCnt : int := 0 ; var rightCnt : int := 0 ; var maxIndex : int := -1 ; var lastInd : int := -1 ; var maxCnt : int := 0 ; while (i->compareTo(n)) < 0 do ( if arr[i+1] = 1 then ( rightCnt := rightCnt + 1 ) else ( if lastInd /= -1 then ( if (rightCnt + leftCnt + 1->compareTo(maxCnt)) > 0 then ( maxCnt := leftCnt + rightCnt + 1 ; maxIndex := lastInd ) else skip ) else skip ; lastInd := i ; leftCnt := rightCnt ; rightCnt := 0 ) ; i := i + 1) ; if lastInd /= -1 then ( if (leftCnt + rightCnt + 1->compareTo(maxCnt)) > 0 then ( maxCnt := leftCnt + rightCnt + 1 ; maxIndex := lastInd ) else skip ) else skip ; return maxIndex; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printKDistinct(arr,n,k): dist_count=0 for i in range(n): j=0 while junion(Sequence{2}->union(Sequence{1}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 2 }))))) ; n := (ar)->size() ; k := 2 ; execute (printKDistinct(ar, n, k))->display(); operation printKDistinct(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var dist_count : int := 0 ; for i : Integer.subrange(0, n-1) do ( var j : int := 0 ; while (j->compareTo(n)) < 0 do ( if (i /= j & arr[j+1] = arr[i+1]) then ( break ) else skip ; j := j + 1) ; if (j = n) then ( dist_count := dist_count + 1 ) else skip ; if (dist_count = k) then ( return arr[i+1] ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def permuteRec(string,n,index=-1,curr=""): if index==n : return if len(curr)>0 : print(curr) for i in range(index+1,n): curr+=string[i] permuteRec(string,n,i,curr) curr=curr[: len(curr)-1] def powerSet(string): string=''.join(sorted(string)) permuteRec(string,len(string)) if __name__=="__main__" : string="cab" powerSet(string) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( string := "cab" ; powerSet(string) ) else skip; operation permuteRec(string : OclAny, n : OclAny, index : int, curr : String) pre: true post: true activity: if index->oclIsUndefined() then index := -1 else skip; if curr->oclIsUndefined() then curr := "" else skip; if index = n then ( return ) else skip ; if (curr)->size() > 0 then ( execute (curr)->display() ) else skip ; for i : Integer.subrange(index + 1, n-1) do ( curr := curr + string[i+1] ; permuteRec(string, n, i, curr) ; curr := curr.subrange(1,(curr)->size() - 1)); operation powerSet(string : OclAny) pre: true post: true activity: string := StringLib.sumStringsWithSeparator((string->sort()), '') ; permuteRec(string, (string)->size()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution : def longestPalindrome(self,s): ans=0 char_map={} for c in s : char_map[c]=char_map.get(c,0)+1 for c in char_map.keys(): if char_map[c]% 2==0 : ans+=char_map.pop(c) else : ans+=char_map[c]/2*2 if len(char_map)!=0 : ans+=1 return ans ------------------------------------------------------------ OCL File: --------- class Solution { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation longestPalindrome(s : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; var char_map : OclAny := Set{} ; for c : s do ( char_map[c+1] := char_map.get(c, 0) + 1) ; for c : char_map.keys() do ( if char_map[c+1] mod 2 = 0 then ( ans := ans + char_map->at(c`firstArg+1) ; char_map := char_map->excludingAt(c+1) ) else ( ans := ans + char_map[c+1] / 2 * 2 )) ; if (char_map)->size() /= 0 then ( ans := ans + 1 ) else skip ; return ans; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline import bisect n=int(input()) X=list(map(int,input().split())) l=int(input()) U=17 dp=[[0]*n for _ in range(U+1)] for i,x in enumerate(X): t=bisect.bisect_left(X,x+l) dp[0][i]=bisect.bisect_right(X,x+l)-1 for k in range(U): for i in range(n): dp[k+1][i]=dp[k][dp[k][i]] def test(x,a,b): for i in range(U,-1,-1): if x>>i & 1 : a=dp[i][a] return a>=b def solve(a,b): if a>b : a,b=b,a ng=0 ok=n-1 while ok-ng>1 : mid=(ng+ok)//2 if test(mid,a,b): ok=mid else : ng=mid print(ok) q=int(input()) for _ in range(q): a,b=map(int,input().split()) a-=1 b-=1 solve(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var X : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var U : int := 17 ; var dp : Sequence := Integer.subrange(0, U + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, n))) ; for _tuple : Integer.subrange(1, (X)->size())->collect( _indx | Sequence{_indx-1, (X)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); var t : OclAny := bisect.bisect_left(X, x + l) ; dp->first()[i+1] := bisect.bisect_right(X, x + l) - 1) ; for k : Integer.subrange(0, U-1) do ( for i : Integer.subrange(0, n-1) do ( dp[k + 1+1][i+1] := dp[k+1][dp[k+1][i+1]+1])) ; skip ; skip ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := a - 1 ; b := b - 1 ; solve(a, b)); operation test(x : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(-1 + 1, U)->reverse() do ( if MathLib.bitwiseAnd(x /(2->pow(i)), 1) then ( a := dp[i+1][a+1] ) else skip) ; return (a->compareTo(b)) >= 0; operation solve(a : OclAny, b : OclAny) pre: true post: true activity: if (a->compareTo(b)) > 0 then ( Sequence{a,b} := Sequence{b,a} ) else skip ; var ng : int := 0 ; var ok : double := n - 1 ; while ok - ng > 1 do ( var mid : int := (ng + ok) div 2 ; if test(mid, a, b) then ( ok := mid ) else ( ng := mid )) ; execute (ok)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) x=list(map(int,input().split())) l=int(input()) q=int(input()) ab=[list(map(lambda x : int(x)-1,input().split()))for _ in[0]*q] doubling=[[]for _ in[0]*n] j=0 for i in range(n): while jl : doubling[i].append(j-1) break else : j+=1 for i in range(n-1,-1,-1): if not doubling[i]: doubling[i].append(n-1) else : break for _ in range(16): for i in range(n): doubling[i].append(doubling[doubling[i][-1]][-1]) for a,b in ab : if a>b : a,b=b,a ans=0 j=16 while j>=0 : if doubling[a][j]>=b : j-=1 else : a=doubling[a][j] ans+=2**j if a==b : print(ans) else : print(ans+1) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ab : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, q)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) )))) ; var doubling : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n)->select(_anon | true)->collect(_anon | (Sequence{})) ; var j : int := 0 ; for i : Integer.subrange(0, n-1) do ( while (j->compareTo(n)) < 0 do ( if (x[j+1] - x[i+1]->compareTo(l)) > 0 then ( (expr (atom (name doubling)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name j))) - (expr (atom (number (integer 1)))))))))) )))) ; break ) else ( j := j + 1 ))) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if not(doubling[i+1]) then ( (expr (atom (name doubling)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) )))) ) else ( break )) ; for _anon : Integer.subrange(0, 16-1) do ( for i : Integer.subrange(0, n-1) do ((expr (atom (name doubling)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name doubling)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name doubling)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))))) )))))) ; for _tuple : ab do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if (a->compareTo(b)) > 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a} ) else skip ; var ans : int := 0 ; j := 16 ; while j >= 0 do ( if (doubling[a+1][j+1]->compareTo(b)) >= 0 then ( j := j - 1 ) else ( var a : OclAny := doubling[a+1][j+1] ; ans := ans + (2)->pow(j) )) ; if a = b then ( execute (ans)->display() ) else ( execute (ans + 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline sys.setrecursionlimit(10**9) from bisect import bisect n=int(input()) x=list(map(int,input().split())) l=int(input()) depth=[-1]*n depth[-1]=0 m=20 par=[[-1]*n for i in range(m)] def dfs(i): if depth[i]>=0 : return depth[i] j=bisect(x,x[i]+l)-1 if j==n : j=n-1 par[0][i]=j depth[i]=dfs(j)+1 return depth[i] for i in range(n): dfs(i) for i in range(m-1): for j in range(n): par[i+1][j]=par[i][par[i][j]] def hoge(x,y): k=0 for i in range(m)[: :-1]: if 0<=par[i][x]b : a,b=b,a ans.append(hoge(a,b)) print(*ans,sep="\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit((10)->pow(9)) ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var depth : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; depth->last() := 0 ; var m : int := 20 ; var par : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ -1 }, n))) ; skip ; for i : Integer.subrange(0, n-1) do ( dfs(i)) ; for i : Integer.subrange(0, m - 1-1) do ( for j : Integer.subrange(0, n-1) do ( par[i + 1+1][j+1] := par[i+1][par[i+1][j+1]+1])) ; skip ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, q-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{a - 1,b - 1} ; if (a->compareTo(b)) > 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a} ) else skip ; execute ((hoge(a, b)) : ans)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); operation dfs(i : OclAny) : OclAny pre: true post: true activity: if depth[i+1] >= 0 then ( return depth[i+1] ) else skip ; var j : double := bisect(x, x[i+1] + l) - 1 ; if j = n then ( j := n - 1 ) else skip ; par->first()[i+1] := j ; depth[i+1] := dfs(j) + 1 ; return depth[i+1]; operation hoge(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var k : int := 0 ; for i : range(m)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if 0 <= par[i+1]->restrict(x) & (par[i+1]->restrict(x) < y) then ( k := k + 1 * (2->pow(i)) ; x := par[i+1]->restrict(x) ) else skip) ; return k + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def inpl(): return[int(i)for i in input().split()] def hmd(a,b): ctr=-1 while H[ctr+1][a]toInteger() ; var x : OclAny := inpl()->union(Sequence{ (10)->pow(10) }) ; var L : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var H : Sequence := Sequence{} ; var G : Sequence := MatrixLib.elementwiseMult(Sequence{ N - 1 }, N) ; b := 0 ; for a : Integer.subrange(0, N-1) do ( while (x[b + 1+1] - x[a+1]->compareTo(L)) <= 0 do ( if b = N - 1 then ( break ) else skip ; b := b + 1) ; G[a+1] := b) ; execute ((G) : H) ; while G->first() /= N - 1 do ( G := G->select(i | true)->collect(i | (G[i+1])) ; execute ((G) : H)) ; execute ((MatrixLib.elementwiseMult(Sequence{ (10)->pow(10) }, N)) : H) ; var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, Q-1) do ( Sequence{a,b} := inpl()->sort() ; execute (hmd(a - 1, b - 1))->display()); operation inpl() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation hmd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var ctr : int := -1 ; while (H[ctr + 1+1][a+1]->compareTo(b)) < 0 do ( ctr := ctr + 1) ; var vn : OclAny := H[ctr+1][a+1] ; if (vn = b & ctr = 0) or ctr = -1 then ( return 1 ) else skip ; return (2)->pow(ctr) + hmd(vn, b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left,bisect_right N=int(input()) xs=list(map(int,input().split())) L=int(input()) Q=int(input()) ABs=[tuple(map(lambda x : int(x)-1,input().split()))for _ in range(Q)] logN=((N-1).bit_length()) parentss=[[N-1]*(logN+1)for _ in range(N)] for i in range(N-1): iL=bisect_right(xs,xs[i]+L) parentss[i][0]=iL-1 for d in range(1,logN+1): for i in range(N-1): parentss[i][d]=parentss[parentss[i][d-1]][d-1] anss=[] for A,B in ABs : if A>B : A,B=B,A i=A ans=1 for d in reversed(range(logN+1)): if parentss[i][d]toInteger() ; var xs : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var L : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ABs : Sequence := Integer.subrange(0, Q-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) )))) ; var logN : OclAny := ((N - 1).bit_length()) ; var parentss : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ N - 1 }, (logN + 1)))) ; for i : Integer.subrange(0, N - 1-1) do ( var iL : OclAny := bisect_right(xs, xs[i+1] + L) ; parentss[i+1]->first() := iL - 1) ; for d : Integer.subrange(1, logN + 1-1) do ( for i : Integer.subrange(0, N - 1-1) do ( parentss[i+1][d+1] := parentss[parentss[i+1][d - 1+1]+1][d - 1+1])) ; var anss : Sequence := Sequence{} ; for _tuple : ABs do (var _indx : int := 1; var A : OclAny := _tuple->at(_indx); _indx := _indx + 1; var B : OclAny := _tuple->at(_indx); if (A->compareTo(B)) > 0 then ( var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := Sequence{B,A} ) else skip ; var i : OclAny := A ; var ans : int := 1 ; for d : (Integer.subrange(0, logN + 1-1))->reverse() do ( if (parentss[i+1][d+1]->compareTo(B)) < 0 then ( i := parentss[i+1][d+1] ; ans := ans + (2)->pow(d) ) else skip) ; execute ((ans) : anss)) ; execute (StringLib.sumStringsWithSeparator(((anss)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from re import M n,k=map(int,input().split()) m=pow(2,n-1) while m!=k : if k>m : t=k-m k=m-t n-=1 m=pow(2,n-1) print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : double := (2)->pow(n - 1) ; while m /= k do ( if (k->compareTo(m)) > 0 then ( var t : double := k - m ; var k : double := m - t ) else skip ; n := n - 1 ; m := (2)->pow(n - 1)) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printArray(arr,n): for i in range(n): print(arr[i],end=" ") def findArray(q,n): arr=[None]*n k=0 for j in range(int(n/4)): ans=q[k]^ q[k+3] arr[k+1]=q[k+1]^ ans arr[k+2]=q[k+2]^ ans arr[k]=q[k]^((arr[k+1])^(arr[k+2])) arr[k+3]=q[k+3]^(arr[k+1]^ arr[k+2]) k+=4 printArray(arr,n) if __name__=='__main__' : q=[4,1,7,0] n=len(q) findArray(q,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( q := Sequence{4}->union(Sequence{1}->union(Sequence{7}->union(Sequence{ 0 }))) ; n := (q)->size() ; findArray(q, n) ) else skip; operation printArray(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); operation findArray(q : OclAny, n : OclAny) pre: true post: true activity: arr := MatrixLib.elementwiseMult(Sequence{ null }, n) ; var k : int := 0 ; for j : Integer.subrange(0, ("" + ((n / 4)))->toInteger()-1) do ( var ans : int := MathLib.bitwiseXor(q[k+1], q[k + 3+1]) ; arr[k + 1+1] := MathLib.bitwiseXor(q[k + 1+1], ans) ; arr[k + 2+1] := MathLib.bitwiseXor(q[k + 2+1], ans) ; arr[k+1] := MathLib.bitwiseXor(q[k+1], (MathLib.bitwiseXor((arr[k + 1+1]), (arr[k + 2+1])))) ; arr[k + 3+1] := MathLib.bitwiseXor(q[k + 3+1], (MathLib.bitwiseXor(arr[k + 1+1], arr[k + 2+1]))) ; k := k + 4) ; printArray(arr, n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ls=list(map(int,input().split())) ls.sort() if sum(ls[: 3])==ls[3]: print('YES') elif ls[0]+ls[3]==ls[1]+ls[2]: print('YES') elif ls[1]+ls[3]==ls[0]+ls[2]: print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ls : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; ls := ls->sort() ; if (ls.subrange(1,3))->sum() = ls[3+1] then ( execute ('YES')->display() ) else (if ls->first() + ls[3+1] = ls[1+1] + ls[2+1] then ( execute ('YES')->display() ) else (if ls[1+1] + ls[3+1] = ls->first() + ls[2+1] then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inp=input().split() for i in range(len(inp)): inp[i]=int(inp[i]) if(inp[0]+inp[1]==inp[2]+inp[3]or inp[1]+inp[2]==inp[0]+inp[3]or inp[0]+inp[2]==inp[1]+inp[3]): print("YES") elif(inp[0]+inp[1]+inp[2]==inp[3]or inp[1]+inp[2]+inp[3]==inp[0]or inp[0]+inp[2]+inp[3]==inp[1]or inp[0]+inp[1]+inp[3]==inp[2]): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inp : OclAny := input().split() ; for i : Integer.subrange(0, (inp)->size()-1) do ( inp[i+1] := ("" + ((inp[i+1])))->toInteger()) ; if (inp->first() + inp[1+1] = inp[2+1] + inp[3+1] or inp[1+1] + inp[2+1] = inp->first() + inp[3+1] or inp->first() + inp[2+1] = inp[1+1] + inp[3+1]) then ( execute ("YES")->display() ) else (if (inp->first() + inp[1+1] + inp[2+1] = inp[3+1] or inp[1+1] + inp[2+1] + inp[3+1] = inp->first() or inp->first() + inp[2+1] + inp[3+1] = inp[1+1] or inp->first() + inp[1+1] + inp[3+1] = inp[2+1]) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=map(int,input().split()) if a+b==c+d or a+c==b+d or a+d==b+c or a==b+c+d or b==a+c+d or c==a+b+d or d==a+b+c : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a + b = c + d or a + c = b + d or a + d = b + c or a = b + c + d or b = a + c + d or c = a + b + d or d = a + b + c then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binomialCoeff(n,k): res=1 ; if(k>n-k): k=n-k ; for i in range(k): res*=(n-i); res/=(i+1); return int(res); def catalan(n): c=binomialCoeff(2*n,n); return int(c/(n+1)); def findWays(n): if(n & 1): return 0 ; return catalan(int(n/2)); n=6 ; print("Total possible expressions of length",n,"is",findWays(6)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 6; ; execute ("Total possible expressions of length")->display();; operation binomialCoeff(n : OclAny, k : OclAny) pre: true post: true activity: var res : int := 1; ; if ((k->compareTo(n - k)) > 0) then ( k := n - k; ) else skip ; for i : Integer.subrange(0, k-1) do ( res := res * (n - i); ; res := res / (i + 1);) ; return ("" + ((res)))->toInteger();; operation catalan(n : OclAny) pre: true post: true activity: var c : OclAny := binomialCoeff(2 * n, n); ; return ("" + ((c / (n + 1))))->toInteger();; operation findWays(n : OclAny) pre: true post: true activity: if (MathLib.bitwiseAnd(n, 1)) then ( return 0; ) else skip ; return catalan(("" + ((n / 2)))->toInteger());; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a1,a2,a3,a4=map(int,input().split()) s=a1+a2+a3+a4 if a1+a2==a3+a4 : print('YES') elif a1+a3==a2+a4 : print('YES') elif a1+a4==a2+a3 : print('YES') elif a1==s-a1 or a2==s-a2 or a3==s-a3 or a4==s-a4 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a1 : OclAny := null; var a2 : OclAny := null; var a3 : OclAny := null; var a4 : OclAny := null; Sequence{a1,a2,a3,a4} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := a1 + a2 + a3 + a4 ; if a1 + a2 = a3 + a4 then ( execute ('YES')->display() ) else (if a1 + a3 = a2 + a4 then ( execute ('YES')->display() ) else (if a1 + a4 = a2 + a3 then ( execute ('YES')->display() ) else (if a1 = s - a1 or a2 = s - a2 or a3 = s - a3 or a4 = s - a4 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- all=[int(i)for i in input().split()] i=0 x=all[i]+all[i+2] y=all[i+1]+all[i+3] a=all[i]+all[i+1] b=all[i+2]+all[i+3] c=all[i]+all[i+3] d=all[i+1]+all[i+2] sum=0 for i in all : sum+=i if(sum % 2==0 and x==y or a==b or c==d)or sum-all[3]==all[3]or sum-all[2]==all[2]or sum-all[1]==all[1]or sum-all[0]==all[0]: print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var all : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var i : int := 0 ; var x : boolean := [i+1]->forAll( _x | _x = true ) + [i + 2+1]->forAll( _x | _x = true ) ; var y : boolean := [i + 1+1]->forAll( _x | _x = true ) + [i + 3+1]->forAll( _x | _x = true ) ; var a : boolean := [i+1]->forAll( _x | _x = true ) + [i + 1+1]->forAll( _x | _x = true ) ; var b : boolean := [i + 2+1]->forAll( _x | _x = true ) + [i + 3+1]->forAll( _x | _x = true ) ; var c : boolean := [i+1]->forAll( _x | _x = true ) + [i + 3+1]->forAll( _x | _x = true ) ; var d : boolean := [i + 1+1]->forAll( _x | _x = true ) + [i + 2+1]->forAll( _x | _x = true ) ; var sum : int := 0 ; for i : all do ( sum := sum + i) ; if (sum mod 2 = 0 & x = y or a = b or c = d) or sum - [3+1]->forAll( _x | _x = true ) = [3+1]->forAll( _x | _x = true ) or sum - [2+1]->forAll( _x | _x = true ) = [2+1]->forAll( _x | _x = true ) or sum - [1+1]->forAll( _x | _x = true ) = [1+1]->forAll( _x | _x = true ) or sum - ->first()->forAll( _x | _x = true ) = ->first()->forAll( _x | _x = true ) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=list(map(int,input().split(''))) s=['B']*m a=list(map(int,input().split(''))) for i in range(n): if m+1-a[i]>=0 and m+1-a[i]<=a[i]: if s[m+1-a[i]-1]=='B' : s[m+1-a[i]-1]='A' else : s[a[i]-1]='A' else : if s[a[i]-1]=='B' : s[a[i]-1]='A' else : s[m+1-a[i]-1]='A' print(''.join(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split(''))->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 'B' }, m) ; var a : Sequence := ((input().split(''))->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( if m + 1 - a[i+1] >= 0 & (m + 1 - a[i+1]->compareTo(a[i+1])) <= 0 then ( if s[m + 1 - a[i+1] - 1+1] = 'B' then ( s[m + 1 - a[i+1] - 1+1] := 'A' ) else ( s[a[i+1] - 1+1] := 'A' ) ) else ( if s[a[i+1] - 1+1] = 'B' then ( s[a[i+1] - 1+1] := 'A' ) else ( s[m + 1 - a[i+1] - 1+1] := 'A' ) )) ; execute (StringLib.sumStringsWithSeparator((s), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=map(int,input().split()) an=list(map(int,input().split())) res=['B' for _ in range(m)] for i in range(n): a,b=min(an[i]-1,m-an[i]),max(an[i]-1,m-an[i]) if res[a]=='B' : res[a]='A' elif res[b]=='B' : res[b]='A' print("".join(i for i in res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var an : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | ('B')) ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{Set{an[i+1] - 1, m - an[i+1]}->min(),Set{an[i+1] - 1, m - an[i+1]}->max()} ; if res[a+1] = 'B' then ( res[a+1] := 'A' ) else (if res[b+1] = 'B' then ( res[b+1] := 'A' ) else skip)) ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name res)))))))), ""))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input("")) for i in range(t): n,m=list(map(int,input().split())) a=list(map(int,input().split())) lst=['B']*m for j in range(n): x=a[j] if x-1<=m-x and lst[x-1]!='A' : lst[x-1]='A' else : if lst[m-x]=='B' : lst[m-x]='A' else : lst[x-1]='A' print(''.join(lst)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine(""))))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lst : Sequence := MatrixLib.elementwiseMult(Sequence{ 'B' }, m) ; for j : Integer.subrange(0, n-1) do ( var x : OclAny := a[j+1] ; if (x - 1->compareTo(m - x)) <= 0 & lst[x - 1+1] /= 'A' then ( lst[x - 1+1] := 'A' ) else ( if lst[m - x+1] = 'B' then ( lst[m - x+1] := 'A' ) else ( lst[x - 1+1] := 'A' ) )) ; execute (StringLib.sumStringsWithSeparator((lst), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n,m=[int(num)for num in input().split()] array=[int(num)for num in input().split()] ans=["B"]*m for a in array : t1=min(a-1,m-a) t2=max(a-1,m-a) if ans[t1]=="B" : ans[t1]="A" else : ans[t2]="A" print("".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var array : Sequence := input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ "B" }, m) ; for a : array do ( var t1 : OclAny := Set{a - 1, m - a}->min() ; var t2 : OclAny := Set{a - 1, m - a}->max() ; if ans[t1+1] = "B" then ( ans[t1+1] := "A" ) else ( ans[t2+1] := "A" )) ; execute (StringLib.sumStringsWithSeparator((ans), ""))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fun(n,k): while True : num=2**n-1 if k==num//2 : v=n break if k>num//2 : k=k-(num//2+1) n=n-1 return v n,k=map(int,input().split()) print(fun(n,k-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (fun(n, k - 1))->display(); operation fun(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: while true do ( var num : double := (2)->pow(n) - 1 ; if k = num div 2 then ( var v : OclAny := n ; break ) else skip ; if (k->compareTo(num div 2)) > 0 then ( k := k - (num div 2 + 1) ) else skip ; n := n - 1) ; return v; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n,m=map(int,input().split()) lis=list(map(int,input().split())) ans=['B']*m di=dict() for i in lis : one,two=min(i,m+1-i),max(i,m+1-i) if di.get(one,False)==False : di[one]=True ans[one-1]='A' elif di.get(two,False)==False : di[two]=True ans[two-1]='A' print(''.join(ans)) for _ in range(int(input())): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve()); operation solve() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lis : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 'B' }, m) ; var di : Map := (arguments ( )) ; for i : lis do ( var one : OclAny := null; var two : OclAny := null; Sequence{one,two} := Sequence{Set{i, m + 1 - i}->min(),Set{i, m + 1 - i}->max()} ; if di.get(one, false) = false then ( di[one+1] := true ; ans[one - 1+1] := 'A' ) else (if di.get(two, false) = false then ( di[two+1] := true ; ans[two - 1+1] := 'A' ) else skip)) ; execute (StringLib.sumStringsWithSeparator((ans), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math class Node : def __init__(self,data): self.data=data self.next=None def reverse(head,k): prev=None curr=head temp=None tail=None newHead=None join=None t=0 while(curr): t=k join=curr prev=None while(curr and t>0): temp=curr.next curr.next=prev prev=curr curr=temp t=t-1 if(newHead==None): newHead=prev if(tail!=None): tail.next=prev tail=join return newHead def push(head_ref,new_data): new_node=Node(new_data) new_node.data=new_data new_node.next=head_ref head_ref=new_node return head_ref def prList(node): while(node!=None): print(node.data,end=" ") node=node.next if __name__=='__main__' : head=None head=push(head,9) head=push(head,8) head=push(head,7) head=push(head,6) head=push(head,5) head=push(head,4) head=push(head,3) head=push(head,2) head=push(head,1) k=3 print("Given linked list ") prList(head) head=reverse(head,k) print("\nReversed Linked list ") prList(head) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.next := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( head := null ; head := push(head, 9) ; head := push(head, 8) ; head := push(head, 7) ; head := push(head, 6) ; head := push(head, 5) ; head := push(head, 4) ; head := push(head, 3) ; head := push(head, 2) ; head := push(head, 1) ; k := 3 ; execute ("Given linked list ")->display() ; prList(head) ; head := reverse(head, k) ; execute ("\nReversed Linked list ")->display() ; prList(head) ) else skip; operation reverse(head : OclAny, k : OclAny) : OclAny pre: true post: true activity: var prev : OclAny := null ; var curr : OclAny := head ; var temp : OclAny := null ; var tail : OclAny := null ; var newHead : OclAny := null ; var join : OclAny := null ; var t : int := 0 ; while (curr) do ( t := k ; join := curr ; prev := null ; while (curr & t > 0) do ( temp := curr.next ; curr.next := prev ; prev := curr ; curr := temp ; t := t - 1) ; if (newHead = null) then ( newHead := prev ) else skip ; if (tail /= null) then ( tail.next := prev ) else skip ; tail := join) ; return newHead; operation push(head_ref : OclAny, new_data : OclAny) : OclAny pre: true post: true activity: var new_node : Node := (Node.newNode()).initialise(new_data) ; new_node.data := new_data ; new_node.next := head_ref ; head_ref := new_node ; return head_ref; operation prList(node : OclAny) pre: true post: true activity: while (node /= null) do ( execute (node.data)->display() ; node := node.next); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import count lr=[int(y)for y in input().split(" ")] l,r=lr[0],lr[1] def diferentes(x): x=str(x) for i in x : cont=x.count(i) if cont!=1 : return False return True def funcion(l,r): if l>r : return-1 while l<=r : if diferentes(l): return l if l==r : return-1 l+=1 rta=funcion(l,r) print(rta) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var lr : Sequence := input().split(" ")->select(y | true)->collect(y | (("" + ((y)))->toInteger())) ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{lr->first(),lr[1+1]} ; skip ; skip ; var rta : OclAny := funcion(l, r) ; execute (rta)->display(); operation diferentes(x : OclAny) : OclAny pre: true post: true activity: x := ("" + ((x))) ; for i : x do ( var cont : int := x->count(i) ; if cont /= 1 then ( return false ) else skip) ; return true; operation funcion(l : OclAny, r : OclAny) : OclAny pre: true post: true activity: if (l->compareTo(r)) > 0 then ( return -1 ) else skip ; while (l->compareTo(r)) <= 0 do ( if diferentes(l) then ( return l ) else skip ; if l = r then ( return -1 ) else skip ; l := l + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import heapq import sys import math import itertools import bisect from io import BytesIO,IOBase import os def value(): return tuple(map(int,input().split())) def values(): return tuple(map(int,sys.stdin.readline().split())) def inlst(): return[int(i)for i in input().split()] def inlsts(): return[int(i)for i in sys.stdin.readline().split()] def inp(): return int(input()) def inps(): return int(sys.stdin.readline()) def instr(): return input() def stlst(): return[i for i in input().split()] def help(a,b,l): tot=[] for i in range(b): tot.append(l[i*a : i*a+a]) for i in zip(*tot): if sum((i))==b : return True return False def solve(): tot=[] x=instr() s=[] for i in x : if i=='O' : s.append(0) else : s.append(1) for i in range(1,13): if 12 % i==0 : if help(i,12//i,s): tot.append((12//i,i)) print(len(tot),end=' ') for a,b in sorted(tot): print(f'{a}x{b}',end=' ') print() if __name__=="__main__" : for i in range(inp()): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( for i : Integer.subrange(0, inp()-1) do ( solve()) ) else skip; operation value() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation values() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inlsts() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inps() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation instr() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation stlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (i)); operation help(a : OclAny, b : OclAny, l : OclAny) : OclAny pre: true post: true activity: var tot : Sequence := Sequence{} ; for i : Integer.subrange(0, b-1) do ( execute ((l.subrange(i * a+1, i * a + a)) : tot)) ; for i : Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name tot)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name tot)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name tot)))))))`third->at(_indx)} ) do ( if ((i))->sum() = b then ( return true ) else skip) ; return false; operation solve() pre: true post: true activity: tot := Sequence{} ; var x : OclAny := instr() ; var s : Sequence := Sequence{} ; for i : x do ( if i = 'O' then ( execute ((0) : s) ) else ( execute ((1) : s) )) ; for i : Integer.subrange(1, 13-1) do ( if 12 mod i = 0 then ( if help(i, 12 div i, s) then ( execute ((Sequence{12 div i, i}) : tot) ) else skip ) else skip) ; execute ((tot)->size())->display() ; for _tuple : tot->sort() do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); execute (StringLib.formattedString('{a}x{b}'))->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l,r=map(int,input().split()) ans=True for i in range(l,r+1): if len(str(i))==len(set(str(i))): print(i) ans=False break if ans : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : boolean := true ; for i : Integer.subrange(l, r + 1-1) do ( if (("" + ((i))))->size() = (Set{}->union((("" + ((i))))))->size() then ( execute (i)->display() ; ans := false ; break ) else skip) ; if ans then ( execute (-1)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l,r=[int(c)for c in input().split()] found=False for i in range(l,r+1): if len(set(str(i)))==len(str(i)): found=True print(i) break if not found : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := input().split()->select(c | true)->collect(c | (("" + ((c)))->toInteger())) ; var found : boolean := false ; for i : Integer.subrange(l, r + 1-1) do ( if (Set{}->union((("" + ((i))))))->size() = (("" + ((i))))->size() then ( found := true ; execute (i)->display() ; break ) else skip) ; if not(found) then ( execute (-1)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l,r=map(int,input().split()) f=0 for i in range(l,r+1): l=[] x=i s1=len(str(i)) while i>0 : r=i % 10 l.append(r) i=i//10 s2=set(l) if s1==len(s2): f=1 print(x) break if f==0 : print("-1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var f : int := 0 ; for i : Integer.subrange(l, r + 1-1) do ( var l : Sequence := Sequence{} ; var x : OclAny := i ; var s1 : int := (("" + ((i))))->size() ; while i > 0 do ( var r : int := i mod 10 ; execute ((r) : l) ; var i : int := i div 10) ; var s2 : Set := Set{}->union((l)) ; if s1 = (s2)->size() then ( f := 1 ; execute (x)->display() ; break ) else skip) ; if f = 0 then ( execute ("-1")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def function(i): if(len(str(i))==len(set(str(i)))): return True return False l,r=map(int,input().split()) for i in range(l,r+1): if(function(i)): print(i) break else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name r))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name function)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ))))))))))))))); operation function(i : OclAny) : OclAny pre: true post: true activity: if ((("" + ((i))))->size() = (Set{}->union((("" + ((i))))))->size()) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) ct=[int(c)for c in input().split(" ",n-1)] wt=[int(w)for w in input().split(" ",m-1)] p=min(ct) q=max(ct) r=min(wt) k=max(2*p,q) if k>=r : print(-1) else : print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ct : Sequence := input().split(" ", n - 1)->select(c | true)->collect(c | (("" + ((c)))->toInteger())) ; var wt : Sequence := input().split(" ", m - 1)->select(w | true)->collect(w | (("" + ((w)))->toInteger())) ; var p : OclAny := (ct)->min() ; var q : OclAny := (ct)->max() ; var r : OclAny := (wt)->min() ; var k : OclAny := Set{2 * p, q}->max() ; if (k->compareTo(r)) >= 0 then ( execute (-1)->display() ) else ( execute (k)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p=input() n=list(map(int,input().split())) m=list(map(int,input().split())) if min(m)<=max(n): print(-1) elif max(n)>=2*min(n): print(max(n)) elif((min(n)*2)=max(n)): print(min(n)*2) elif(max(n)*2)collect( _x | (OclType["int"])->apply(_x) )) ; var m : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if ((m)->min()->compareTo((n)->max())) <= 0 then ( execute (-1)->display() ) else (if ((n)->max()->compareTo(2 * (n)->min())) >= 0 then ( execute ((n)->max())->display() ) else (if ((((n)->min() * 2)->compareTo((m)->min())) < 0) & ((((n)->min() * 2)->compareTo((n)->max())) >= 0) then ( execute ((n)->min() * 2)->display() ) else (if (((n)->max() * 2)->compareTo((m)->min())) < 0 then ( execute ((n)->max() * 2)->display() ) else ( execute (-1)->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) a=[int(i)for i in input().split()] b=[int(i)for i in input().split()] a=sorted(a) b=sorted(b) x=a[0]*2 if(x>=a[-1]and xcollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var b : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; a := a->sort() ; b := b->sort() ; var x : double := a->first() * 2 ; if ((x->compareTo(a->last())) >= 0 & (x->compareTo(b->first())) < 0) then ( execute (x)->display() ) else (if ((x->compareTo(a->last())) < 0 & (a->last()->compareTo(b->first())) < 0) then ( execute (a->last())->display() ) else ( execute (-1)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys for line in sys.stdin : a,l,x=map(float,line.split()) center=1/2*a*(l**2-(a/2)**2)**0.5 side=1/2*l*(((l+x)/2)**2-(l/2)**2)**0.5 print("{0:.10f}".format(center+side*2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for line : OclFile["System.in"] do ( var a : OclAny := null; var l : OclAny := null; var x : OclAny := null; Sequence{a,l,x} := (line.split())->collect( _x | (OclType["double"])->apply(_x) ) ; var center : double := 1 / 2 * a * (((l)->pow(2) - ((a / 2))->pow(2)))->pow(0.5) ; var side : double := 1 / 2 * l * (((((l + x) / 2))->pow(2) - ((l / 2))->pow(2)))->pow(0.5) ; execute (StringLib.interpolateStrings("{0:.10f}", Sequence{center + side * 2}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): n,m=map(int,input().split()) right=list(map(int,input().split())) wrong=list(map(int,input().split())) v=max(max(right),2*min(right)) if vcollect( _x | (OclType["int"])->apply(_x) ) ; var right : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var wrong : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var v : OclAny := Set{(right)->max(), 2 * (right)->min()}->max() ; if (v->compareTo((wrong)->min())) < 0 then ( execute (v)->display() ) else ( execute (-1)->display() ); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,sys,io,math from tokenize import Triple from array import array from math import* I=lambda :[*map(int,sys.stdin.readline().split())] IS=lambda : input() IN=lambda : int(input()) IF=lambda : float(input()) n,m=map(int,input().split()) a=I() b=I() c=min(a) d=min(b) v=max(a) print(max(2*c,v)if max(2*c,v)collect( _x | (OclType["int"])->apply(_x) )) ; var IS : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var IN : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var IF : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toReal()) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := I->apply() ; var b : OclAny := I->apply() ; var c : OclAny := (a)->min() ; var d : OclAny := (b)->min() ; var v : OclAny := (a)->max() ; execute (if (Set{2 * c, v}->max()->compareTo(d)) < 0 then Set{2 * c, v}->max() else -1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): s=input()[:-1] d=[] l=[1,2,3,4,6,12] for j in l : k=12//j for i in range(k): if s[i : : k]=='X'*j : d+=[str(j)+'x'+str(k)] break print(len(d),' '.join(d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : OclAny := input()->front() ; var d : Sequence := Sequence{} ; var l : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{6}->union(Sequence{ 12 }))))) ; for j : l do ( var k : int := 12 div j ; for i : Integer.subrange(0, k-1) do ( if s(subscript (test (logical_test (comparison (expr (atom (name i)))))) : (sliceop : (test (logical_test (comparison (expr (atom (name k)))))))) = StringLib.nCopies('X', j) then ( d := d + Sequence{ ("" + ((j))) + 'x' + ("" + ((k))) } ; break ) else skip)) ; execute ((d)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import* N,K,Q,*A=map(int,open(0).read().split()) s=sorted print(min((s(sum((v[: max(0,len(v)-K+1)]for v in(k*s(v)for k,v in groupby(A,lambda a : a>=Y))),[]))[Q-1 :]or[2e9])[0]-Y for Y in A)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var K : OclAny := null; var Q : OclAny := null; var A : OclAny := null; Sequence{N,K,Q,A} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := sorted ; execute (((argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (expr (atom (name s)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) - (expr (atom (name K)))) + (expr (atom (number (integer 1)))))))))) ))))))))) ])))))) (comp_for for (exprlist (expr (atom (name v)))) in (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name k))) * (expr (atom (name s)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))))))) (comp_for for (exprlist (expr (atom (name k))) , (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name groupby)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A))))))) , (argument (test lambda (varargslist (vardef_parameters (vardef_parameter (name a)))) : (test (logical_test (comparison (comparison (expr (atom (name a)))) >= (comparison (expr (atom (name Y)))))))))) )))))))) ))))))) ))))))) , (argument (test (logical_test (comparison (expr (atom [ ]))))))) ))))))))) ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name Q))) - (expr (atom (number (integer 1)))))))) :)) ]))))) or (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number 2e9))))))) ]))))))) )) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) - (expr (atom (name Y))))))) (comp_for for (exprlist (expr (atom (name Y)))) in (logical_test (comparison (expr (atom (name A))))))))->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import nsmallest def get_add_list(): cache={} def add_list(s,t): global new_lists,removables l=t-s if l>=k : new_lists.append((s,t)) if(s,t)in cache : removables.extend(cache[s,t]) return cache[s,t]=nsmallest(l-k+1,aaa[s : t]) removables.extend(cache[s,t]) return add_list n,k,q=map(int,input().split()) aaa=list(map(int,input().split())) srt=sorted(set(aaa)) lists=[(0,n)] ans=float('inf') add_list=get_add_list() for a in srt : new_lists=[] removables=[] for s,t in lists : r=s for i,b in enumerate(aaa[s : t]): if a>b : add_list(r,s+i) r=s+i+1 add_list(r,t) if len(removables)collect( _x | (OclType["int"])->apply(_x) ) ; var aaa : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var srt : Sequence := Set{}->union((aaa))->sort() ; var lists : Sequence := Sequence{ Sequence{0, n} } ; var ans : double := ("" + (('inf')))->toReal() ; var add_list : OclAny := get_add_list() ; for a : srt do ( new_lists := Sequence{} ; removables := Sequence{} ; for _tuple : lists do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); var r : OclAny := s ; for _tuple : Integer.subrange(1, (aaa.subrange(s+1, t))->size())->collect( _indx | Sequence{_indx-1, (aaa.subrange(s+1, t))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if (a->compareTo(b)) > 0 then ( add_list(r, s + i) ; r := s + i + 1 ) else skip) ; add_list(r, t)) ; if ((removables)->size()->compareTo(q)) < 0 then ( break ) else skip ; removables := removables->sort() ; ans := Set{ans, removables[q - 1+1] - a}->min() ; lists := new_lists) ; execute (ans)->display(); operation get_add_list() : OclAny pre: true post: true activity: var cache : OclAny := Set{} ; skip ; return add_list; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) int1=lambda x : int(x)-1 p2D=lambda x : print(*x,sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int,sys.stdin.readline().split()) def LI(): return list(map(int,sys.stdin.readline().split())) def LLI(rows_number): return[LI()for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] n,k,q=MI() aa=LI() pp=list(sorted(set(aa))) def diff(p): can=[] cur=[] for a in aa+[-1]: if a

=k : cur.sort() if k==1 : can+=cur else : can+=cur[:-(k-1)] cur=[] else : cur.append(a) if len(can)pow(6)) ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; var p2D : Function := lambda x : OclAny in (((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := null; var k : OclAny := null; var q : OclAny := null; Sequence{n,k,q} := MI() ; var aa : OclAny := LI() ; var pp : Sequence := (Set{}->union((aa))->sort()) ; skip ; var ans : double := (10)->pow(16) ; for p : pp do ( var ret : OclAny := diff(p) ; if ret = -1 then ( break ) else skip ; ans := Set{ans, ret}->min()) ; execute (ans)->display(); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LLI(rows_number : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows_number-1)->select(_anon | true)->collect(_anon | (LI())); operation SI() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation diff(p : OclAny) : OclAny pre: true post: true activity: var can : Sequence := Sequence{} ; var cur : Sequence := Sequence{} ; for a : aa->union(Sequence{ -1 }) do ( if (a->compareTo(p)) < 0 then ( if (cur)->size() = n then ( can := cur ; break ) else skip ; if ((cur)->size()->compareTo(k)) >= 0 then ( cur := cur->sort() ; if k = 1 then ( can := can + cur ) else ( can := can + cur.subrange(1,-(k - 1)) ) ) else skip ; cur := Sequence{} ) else ( execute ((a) : cur) )) ; if ((can)->size()->compareTo(q)) < 0 then ( return -1 ) else skip ; can := can->sort() ; var res : double := can[q - 1+1] - can->first() ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,heapq def input(): return sys.stdin.readline()[:-1] n,k,q=map(int,input().split()) a=list(map(int,input().split())) b=sorted(a) a=[0]+a+[0] ans=10**30 for x in b : removed=[] que=[] for i in range(n+2): if a[i]collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := a->sort() ; a := Sequence{ 0 }->union(a)->union(Sequence{ 0 }) ; var ans : double := (10)->pow(30) ; for x : b do ( var removed : Sequence := Sequence{} ; var que : Sequence := Sequence{} ; for i : Integer.subrange(0, n + 2-1) do ( if (a[i+1]->compareTo(x)) < 0 then ( que := Sequence{} ) else ( heapq.heappush(que, a[i+1]) ; if (que)->size() = k then ( execute ((heapq.heappop(que)) : removed) ) else skip )) ; if ((removed)->size()->compareTo(q)) < 0 then ( continue ) else skip ; removed := removed->sort() ; ans := Set{ans, removed[q - 1+1] - x}->min()) ; execute (ans)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k,q,*a=map(int,open(0).read().split()) s=sorted m=1e9 for b in a : i=[i for i,t in enumerate(a)if t=q : m=min(m,l[q-1]-b) print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var q : OclAny := null; var a : OclAny := null; Sequence{n,k,q,a} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := sorted ; var m : double := ("1e9")->toReal() ; for b : a do ( var i : Sequence := Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} )->select(_tuple | let i : OclAny = _tuple->at(1) in let t : OclAny = _tuple->at(2) in (t->compareTo(b)) < 0)->collect(_tuple | let i : OclAny = _tuple->at(1) in let t : OclAny = _tuple->at(2) in (i)); var l : OclAny := s((Integer.subrange(1, Sequence{ -1 }->union(i)->size())->collect( _indx | Sequence{Sequence{ -1 }->union(i)->at(_indx), i->union(Sequence{ n })->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let j : OclAny = _tuple->at(2) in (s(a.subrange(MatrixLib.elementwiseAdd(i, 1)+1, j))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))).subrange(k - 1+1))), Sequence{})->sum()) ; if ((l)->size()->compareTo(q)) >= 0 then ( m := Set{m, l[q - 1+1] - b}->min() ) else skip) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def chck(x): while(x>0): rem=x % 10 x//=10 if(num[rem]==1): return True return False x=int(input()) num=[0]*10 x1=x while(x>0): rem=x % 10 num[rem]=1 x//=10 x=x1 ans=0 for i in range(1,int(x**0.5)+1): if(x % i==0): if(chck(i)): ans+=1 if(i*i!=x): if(chck(x//i)): ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var num : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; var x1 : OclAny := x ; while (x > 0) do ( rem := x mod 10 ; num[rem+1] := 1 ; x := x div 10) ; x := x1 ; var ans : int := 0 ; for i : Integer.subrange(1, ("" + (((x)->pow(0.5))))->toInteger() + 1-1) do ( if (x mod i = 0) then ( if (chck(i)) then ( ans := ans + 1 ) else skip ; if (i * i /= x) then ( if (chck(x div i)) then ( ans := ans + 1 ) else skip ) else skip ) else skip) ; execute (ans)->display(); operation chck(x : OclAny) : OclAny pre: true post: true activity: while (x > 0) do ( var rem : int := x mod 10 ; x := x div 10 ; if (num[rem+1] = 1) then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) c=0 ls_1=[] for h in str(x): ls_1.append(h) ls_x=set(ls_1) for i in range(1,int(x**0.5)+1): if x % i==0 : ls_a=[] for u in str(i): ls_a.append(u) ls_a=set(ls_a) if ls_x & ls_a!=set(): c+=1 if x//i!=i : ls_b=[] for k in str(x//i): ls_b.append(k) ls_b=set(ls_b) if ls_x & ls_b!=set(): c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := 0 ; var ls var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() : Sequence := Sequence{} ; for h : ("" + ((x))) do ( execute ((h) : lslslslslslsls var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger().append(h).append(h).append(h).append(h).append(h).append(h))) ; var ls_x : Set := Set{}->union((ls var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; for i : Integer.subrange(1, ("" + (((x)->pow(0.5))))->toInteger() + 1-1) do ( if x mod i = 0 then ( var ls_a : Sequence := Sequence{} ; for u : ("" + ((i))) do ( execute ((u) : ls_a)) ; ls_a := Set{}->union((ls_a)) ; if MathLib.bitwiseAnd(ls_x, ls_a) /= Set{}->union(()) then ( c := c + 1 ) else skip ; if x div i /= i then ( var ls_b : Sequence := Sequence{} ; for k : ("" + ((x div i))) do ( execute ((k) : ls_b)) ; ls_b := Set{}->union((ls_b)) ; if MathLib.bitwiseAnd(ls_x, ls_b) /= Set{}->union(()) then ( c := c + 1 ) else skip ) else skip ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) cnt=0 for i in range(1,int(x**0.5)+1): if x % i==0 : temp1=str(x) temp2=str(i) for k in temp1 : if k in temp2 : cnt+=1 break temp2=str(x//i) if temp2!=str(i): for k in temp1 : if k in temp2 : cnt+=1 break if x==1 : cnt=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cnt : int := 0 ; for i : Integer.subrange(1, ("" + (((x)->pow(0.5))))->toInteger() + 1-1) do ( if x mod i = 0 then ( var temp1 : String := ("" + ((x))) ; var temp2 : String := ("" + ((i))) ; for k : temp1->characters() do ( if (temp2)->characters()->includes(k) then ( cnt := cnt + 1 ; break ) else skip) ; temp2 := ("" + ((x div i))) ; if temp2 /= ("" + ((i))) then ( for k : temp1->characters() do ( if (temp2)->characters()->includes(k) then ( cnt := cnt + 1 ; break ) else skip) ) else skip ) else skip) ; if x = 1 then ( cnt := 1 ) else skip ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import numpy as np n,a,*x=map(int,sys.stdin.read().split()) def main(): m=2500 dp=np.zeros((n+1,m+1),dtype=np.int64) dp[0,0]=1 for i in range(n): dp[1 :,x[i]:]+=dp[:-1,:-x[i]].copy() i=np.arange(1,n+1) print(dp[i,i*a].sum()) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var a : OclAny := null; var x : OclAny := null; Sequence{n,a,x} := (sys.stdin.readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var m : int := 2500 ; var dp : Sequence := MatrixLib.singleValueMatrix(Sequence{n + 1, m + 1}, 0.0) ; dp->first()->first() := 1 ; for i : Integer.subrange(0, n-1) do ( dp->tail().subrange(x[i+1]+1) := dp->tail().subrange(x[i+1]+1) + dp->front().subrange(1,-x[i+1])->copy()) ; var i : Sequence := MathLib.numericRange(1, n + 1, 1) ; execute (dp->restrict(i)->restrict(MatrixLib.elementwiseMult(i, a)).sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : a,l,x=map(int,input().split()) except EOFError : break s1=(l+l+x)/2 v1=(s1*(l/2)*(l/2)*(x/2))**(1/2) s2=(l+l+a)/2 v2=(s2*(s2-l)*(s2-l)*(s2-a))**(1/2) print(v1*2+v2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var a : OclAny := null; var l : OclAny := null; var x : OclAny := null; Sequence{a,l,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))) ; var s1 : double := (l + l + x) / 2 ; var v1 : double := ((s1 * (l / 2) * (l / 2) * (x / 2)))->pow((1 / 2)) ; var s2 : double := (l + l + a) / 2 ; var v2 : double := ((s2 * (s2 - l) * (s2 - l) * (s2 - a)))->pow((1 / 2)) ; execute (v1 * 2 + v2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): s=input() A=[str(a)+'x'+str(12//a)for a in(1,2,3,4,6,12)if any(s[i : : 12//a]=='X'*a for i in range(12//a))] print(len(A),*A) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var A : Sequence := Sequence{1, 2, 3, 4, 6, 12}->select(a | ((argument (test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))) : (sliceop : (test (logical_test (comparison (expr (expr (atom (number (integer 12)))) // (expr (atom (name a)))))))))) ])))) == (comparison (expr (expr (atom 'X')) * (expr (atom (name a)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (number (integer 12)))) // (expr (atom (name a))))))))) )))))))))->exists( _x | _x = true ))->collect(a | (("" + ((a))) + 'x' + ("" + ((12 div a))))) ; execute ((A)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt n=int(input()) ans=0 def match(num1,num2): for i in str(num1): if i in str(num2): return True return False for i in range(1,int(sqrt(n))+1): if n % i==0 : if match(i,n): ans+=1 if i!=n//i and match(n//i,n): ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; skip ; for i : Integer.subrange(1, ("" + ((sqrt(n))))->toInteger() + 1-1) do ( if n mod i = 0 then ( if match(i, n) then ( ans := ans + 1 ) else skip ; if i /= n div i & match(n div i, n) then ( ans := ans + 1 ) else skip ) else skip) ; execute (ans)->display(); operation match(num1 : OclAny, num2 : OclAny) : OclAny pre: true post: true activity: for i : ("" + ((num1))) do ( if (("" + ((num2))))->includes(i) then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fnMod(n): rem=n % 4 if(rem==0 or rem==3): return 0 elif(rem==1 or rem==2): return 1 if __name__=="__main__" : n=6 print(fnMod(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 6 ; execute (fnMod(n))->display() ) else skip; operation fnMod(n : OclAny) : OclAny pre: true post: true activity: var rem : int := n mod 4 ; if (rem = 0 or rem = 3) then ( return 0 ) else (if (rem = 1 or rem = 2) then ( return 1 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printPair(g,l): print(g,l) g=3 ; l=12 ; printPair(g,l); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; g := 3; l := 12; ; printPair(g, l);; operation printPair(g : OclAny, l : OclAny) pre: true post: true activity: execute (g)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def anglechordtang(z): print("The angle between tangent","and the chord is",z,"degrees"); z=48 ; anglechordtang(z); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; z := 48; ; anglechordtang(z);; operation anglechordtang(z : OclAny) pre: true post: true activity: execute ("The angle between tangent")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=[] while(n!=0): r=n % 2 if r<0 : r+=2 n=(n-r)//(-2) ans.append(r) if ans==[]: ans.append(0) ans=ans[: :-1] print(*ans,sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; while (n /= 0) do ( var r : int := n mod 2 ; if r < 0 then ( r := r + 2 ) else skip ; n := (n - r) div (-2) ; execute ((r) : ans)) ; if ans = Sequence{} then ( execute ((0) : ans) ) else skip ; ans := ans(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left def inpl(): return list(map(int,input().split())) N=int(input()) A=[] B=[] for i in range(2**16): A.append(int(("0{}"*16).format(*list(bin(i)[2 :].zfill(16))),2)) for i in range(2**16): B.append(-int(("{}0"*16).format(*list(bin(i)[2 :].zfill(16))),2)) for j,b in enumerate(B): i=bisect_left(A,N-b) if i==len(A): continue a=A[i] if a+b==N : ans=[""]*32 ans[: : 2]=list(bin(j)[2 :].zfill(16)) ans[1 : : 2]=list(bin(i)[2 :].zfill(16)) print(int("".join(ans))) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := Sequence{} ; var B : Sequence := Sequence{} ; for i : Integer.subrange(0, (2)->pow(16)-1) do ( execute ((("" + ((StringLib.interpolateStrings((StringLib.nCopies("0{}", 16)), Sequence{(argument * (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name bin)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) :)) ])) (trailer . (name zfill) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 16))))))))) ))))))))) ))))))))}), 2)))->toInteger()) : A)) ; for i : Integer.subrange(0, (2)->pow(16)-1) do ( execute ((-("" + ((StringLib.interpolateStrings((StringLib.nCopies("{}0", 16)), Sequence{(argument * (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name bin)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) :)) ])) (trailer . (name zfill) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 16))))))))) ))))))))) ))))))))}), 2)))->toInteger()) : B)) ; for _tuple : Integer.subrange(1, (B)->size())->collect( _indx | Sequence{_indx-1, (B)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); var i : OclAny := bisect_left(A, N - b) ; if i = (A)->size() then ( continue ) else skip ; var a : OclAny := A[i+1] ; if a + b = N then ( var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ "" }, 32) ; ans(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) := (bin(j).subrange(2+1).zfill(16)) ; ans(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) := (bin(i).subrange(2+1).zfill(16)) ; execute (("" + ((StringLib.sumStringsWithSeparator((ans), ""))))->toInteger())->display() ; break ) else skip); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- li=list(map(int,input().split())) n=li[0] ans=0 def asd(x): global ans if x>0 : for i in range(0,35): max=0 l=0 for j in range(0,i,2): max+=pow(-2,j) if max>=x : ans+=pow(10,i-1) return asd(x-(pow(-2,i-1))) elif x<0 : for i in range(0,35): min=0 for j in range(1,i,2): min+=pow(-2,j) if min<=x : ans+=pow(10,i-1) return asd(x-(pow(-2,i-1))) elif x==0 : return 0 asd(n) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute ans : OclAny; operation initialise() pre: true post: true activity: var li : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := li->first() ; var ans : int := 0 ; skip ; asd(n) ; execute (ans)->display(); operation asd(x : OclAny) : OclAny pre: true post: true activity: skip ; if x > 0 then ( for i : Integer.subrange(0, 35-1) do ( var max : int := 0 ; var l : int := 0 ; for j : Integer.subrange(0, i-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( max := max + (-2)->pow(j)) ; if (max->compareTo(x)) >= 0 then ( ans := ans + (10)->pow(i - 1) ; return asd(x - ((-2)->pow(i - 1))) ) else skip) ) else (if x < 0 then ( for i : Integer.subrange(0, 35-1) do ( var min : int := 0 ; for j : Integer.subrange(1, i-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( min := min + (-2)->pow(j)) ; if (min->compareTo(x)) <= 0 then ( ans := ans + (10)->pow(i - 1) ; return asd(x - ((-2)->pow(i - 1))) ) else skip) ) else (if x = 0 then ( return 0 ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) def solve(N): s='' if N==0 : s+='0' elif N==1 : s+='1' else : if N % 2==0 : s+='0' s+=solve(int(N/(-2))) else : s+='1' s+=solve(int((N-1)/(-2))) return s print(solve(N)[: :-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; execute (solve(N)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->display(); operation solve(N : OclAny) : OclAny pre: true post: true activity: var s : String := '' ; if N = 0 then ( s := s + '0' ) else (if N = 1 then ( s := s + '1' ) else ( if N mod 2 = 0 then ( s := s + '0' ; s := s + solve(("" + ((N / (-2))))->toInteger()) ) else ( s := s + '1' ; s := s + solve(("" + (((N - 1) / (-2))))->toInteger()) ) ) ) ; return s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin sys.setrecursionlimit(10**5) def li(): return map(int,stdin.readline().split()) def li_(): return map(lambda x : int(x)-1,stdin.readline().split()) def lf(): return map(float,stdin.readline().split()) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) def n_based(n : int,base : int)->str : if n==0 : return "0" ans="" res=n while abs(res)>0 : q=res % base if q>=0 : ans=str(q)+ans res//=base else : q+=abs(base) ans=str(q)+ans res//=base res+=1 return ans n=ni() print(n_based(n,-2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stdin : OclFile := OclFile["System.in"] ; sys.setrecursionlimit((10)->pow(5)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := ni() ; execute (n_based(n, -2))->display(); operation li() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation li_() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ); operation lf() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ); operation ls() : OclAny pre: true post: true activity: return stdin.readLine().split(); operation ns() : OclAny pre: true post: true activity: return stdin.readLine().rstrip(); operation lc() : OclAny pre: true post: true activity: return (ns()); operation ni() : OclAny pre: true post: true activity: return ("" + ((stdin.readLine())))->toInteger(); operation nf() : OclAny pre: true post: true activity: return ("" + ((stdin.readLine())))->toReal(); operation n_based(n : int, base : int) : String pre: true post: true activity: if n = 0 then ( return "0" ) else skip ; var ans : String := "" ; var res : int := n ; while (res)->abs() > 0 do ( var q : int := res mod base ; if q >= 0 then ( ans := ("" + ((q))) + ans ; res := res div base ) else ( q := q + (base)->abs() ; ans := ("" + ((q))) + ans ; res := res div base ; res := res + 1 )) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fastmod(base,exp,mod): if(exp==0): return 1 ; elif(exp % 2==0): ans=fastmod(base,exp/2,mod); return(ans % mod*ans % mod)% mod ; else : return(fastmod(base,exp-1,mod)% mod*base % mod)% mod ; def findPowerSum(n,ar): mod=int(1e9)+7 ; sum=0 ; for i in range(n): base=bin(ar[i]).count('1'); exp=ar[i]; sum+=fastmod(base,exp,mod); sum %=mod ; return sum ; if __name__=="__main__" : n=3 ; ar=[1,2,3]; print(findPowerSum(n,ar)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 3; ; ar := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })); ; execute (findPowerSum(n, ar))->display(); ) else skip; operation fastmod(base : OclAny, exp : OclAny, mod : OclAny) pre: true post: true activity: if (exp = 0) then ( return 1; ) else (if (exp mod 2 = 0) then ( var ans : OclAny := fastmod(base, exp / 2, mod); ; return (ans mod mod * ans mod mod) mod mod; ) else ( return (fastmod(base, exp - 1, mod) mod mod * base mod mod) mod mod; ) ) ; operation findPowerSum(n : OclAny, ar : OclAny) pre: true post: true activity: mod := ("" + ((("1e9")->toReal())))->toInteger() + 7; ; var sum : int := 0; ; for i : Integer.subrange(0, n-1) do ( base := bin(ar[i+1])->count('1'); ; exp := ar[i+1]; ; sum := sum + fastmod(base, exp, mod); ; sum := sum mod mod;) ; return sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) for i in range(int(input())): s=input() lst=[str(a)+'x'+str(12//a)for a in(1,2,3,4,6,12)if any(s[i : : 12//a]=='X'*a for i in range(12//a))] print(len(lst),*lst) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var lst : Sequence := Sequence{1, 2, 3, 4, 6, 12}->select(a | ((argument (test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))) : (sliceop : (test (logical_test (comparison (expr (expr (atom (number (integer 12)))) // (expr (atom (name a)))))))))) ])))) == (comparison (expr (expr (atom 'X')) * (expr (atom (name a)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (number (integer 12)))) // (expr (atom (name a))))))))) )))))))))->exists( _x | _x = true ))->collect(a | (("" + ((a))) + 'x' + ("" + ((12 div a))))) ; execute ((lst)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math while True : try : a,l,x=map(int,input().split()) temp=(l+x)/2 except EOFError : break def heron(i,j,k): d=(i+j+k)/2 return math.sqrt(d*(d-i)*(d-j)*(d-k)) print((str(heron(a,l,l)+heron(l,temp,temp)*2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( try ( var a : OclAny := null; var l : OclAny := null; var x : OclAny := null; Sequence{a,l,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var temp : double := (l + x) / 2) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))) ; skip ; execute ((("" + ((heron(a, l, l) + heron(l, temp, temp) * 2)))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def isPowerOf(val,base): while(val>1): if(val % base!=0): return False val//=base return True def numberOfPartitions(binaryNo): n=len(binaryNo) dp=[0]*n if((ord(binaryNo[n-1])-ord('0'))==0): dp[n-1]=-1 else : dp[n-1]=1 for i in range(n-2,-1,-1): val=0 if((ord(binaryNo[i])-ord('0'))==0): dp[i]=-1 continue dp[i]=sys.maxsize for j in range(i,n): val=(val*2)+(ord(binaryNo[j])-ord('0')) if(isPowerOf(val,4)or isPowerOf(val,6)): if(j==n-1): dp[i]=1 else : if(dp[j+1]!=-1): dp[i]=min(dp[i],dp[j+1]+1) if(dp[i]==sys.maxsize): dp[i]=-1 return dp[0] if __name__=="__main__" : binaryNo="100110110" print(numberOfPartitions(binaryNo)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( binaryNo := "100110110" ; execute (numberOfPartitions(binaryNo))->display() ) else skip; operation isPowerOf(val : OclAny, base : OclAny) : OclAny pre: true post: true activity: while (val > 1) do ( if (val mod base /= 0) then ( return false ) else skip ; val := val div base) ; return true; operation numberOfPartitions(binaryNo : OclAny) : OclAny pre: true post: true activity: var n : int := (binaryNo)->size() ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; if (((binaryNo[n - 1+1])->char2byte() - ('0')->char2byte()) = 0) then ( dp[n - 1+1] := -1 ) else ( dp[n - 1+1] := 1 ) ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( val := 0 ; if (((binaryNo[i+1])->char2byte() - ('0')->char2byte()) = 0) then ( dp[i+1] := -1 ; continue ) else skip ; dp[i+1] := (trailer . (name maxsize)) ; for j : Integer.subrange(i, n-1) do ( val := (val * 2) + ((binaryNo[j+1])->char2byte() - ('0')->char2byte()) ; if (isPowerOf(val, 4) or isPowerOf(val, 6)) then ( if (j = n - 1) then ( dp[i+1] := 1 ) else ( if (dp[j + 1+1] /= -1) then ( dp[i+1] := Set{dp[i+1], dp[j + 1+1] + 1}->min() ) else skip ) ) else skip) ; if (dp[i+1] = (trailer . (name maxsize))) then ( dp[i+1] := -1 ) else skip) ; return dp->first(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) temp=0 ; for i in range(n): if i % 2==0 : for j in range(k): print("#",end="") print('\n',end="") else : temp+=1 for j in range(k): if(temp % 2==1 and j==k-1): print("#",end="") elif(temp % 2==0 and j==0): print("#",end="") else : print(".",end="") print('\n',end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var temp : int := 0; ; for i : Integer.subrange(0, n-1) do ( if i mod 2 = 0 then ( for j : Integer.subrange(0, k-1) do ( execute ("#")->display()) ; execute (' ')->display() ) else ( temp := temp + 1 ; for j : Integer.subrange(0, k-1) do ( if (temp mod 2 = 1 & j = k - 1) then ( execute ("#")->display() ) else (if (temp mod 2 = 0 & j = 0) then ( execute ("#")->display() ) else ( execute (".")->display() ) ) ) ; execute (' ')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,n=map(int,input().split()) side=1 for x in range(1,m+1): if x % 2!=0 : print("#"*n) else : if side % 2!=0 : print("."*(n-1)+"#") side+=1 else : print("#"+"."*(n-1)) side+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var side : int := 1 ; for x : Integer.subrange(1, m + 1-1) do ( if x mod 2 /= 0 then ( execute (StringLib.nCopies("#", n))->display() ) else ( if side mod 2 /= 0 then ( execute (StringLib.nCopies(".", (n - 1)) + "#")->display() ; side := side + 1 ) else ( execute ("#" + StringLib.nCopies(".", (n - 1)))->display() ; side := side + 1 ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) n13='#'*m n2='.'*(m-1)+'#' n4='#'+'.'*(m-1) print(n13) print(n2) print(n13) n-=3 while n>3 : print(n4) print(n13) print(n2) print(n13) n-=4 if n==3 : print(n4) print(n13) print(n2) elif n==2 : print(n4) print(n13) elif n==1 : print(n4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n13 : String := StringLib.nCopies('#', m) ; var n2 : String := StringLib.nCopies('.', (m - 1)) + '#' ; var n4 : String := '#' + StringLib.nCopies('.', (m - 1)) ; execute (n13)->display() ; execute (n2)->display() ; execute (n13)->display() ; n := n - 3 ; while n > 3 do ( execute (n4)->display() ; execute (n13)->display() ; execute (n2)->display() ; execute (n13)->display() ; n := n - 4) ; if n = 3 then ( execute (n4)->display() ; execute (n13)->display() ; execute (n2)->display() ) else (if n = 2 then ( execute (n4)->display() ; execute (n13)->display() ) else (if n = 1 then ( execute (n4)->display() ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- list1=list(map(int,input().split())) ii,jj=list1[0],list1[1] for i in range(1,ii+1): if i % 2!=0 : print('#'*jj) else : if i % 4==0 : print('#'+'.'*(jj-1)) else : print('.'*(jj-1)+'#') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var list1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ii : OclAny := null; var jj : OclAny := null; Sequence{ii,jj} := Sequence{list1->first(),list1[1+1]} ; for i : Integer.subrange(1, ii + 1-1) do ( if i mod 2 /= 0 then ( execute (StringLib.nCopies('#', jj))->display() ) else ( if i mod 4 = 0 then ( execute ('#' + StringLib.nCopies('.', (jj - 1)))->display() ) else ( execute (StringLib.nCopies('.', (jj - 1)) + '#')->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) for i in range(1,n+1): if(i % 2!=0): for j in range(1,m+1): print('#',end='') print('\n',end='') elif(i % 4==0): print('#',end='') for j in range(1,m): print('.',end='') print('\n',end='') else : for j in range(1,m): print('.',end='') print('#',end='') print('\n',end='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(1, n + 1-1) do ( if (i mod 2 /= 0) then ( for j : Integer.subrange(1, m + 1-1) do ( execute ('#')->display()) ; execute (' ')->display() ) else (if (i mod 4 = 0) then ( execute ('#')->display() ; for j : Integer.subrange(1, m-1) do ( execute ('.')->display()) ; execute (' ')->display() ) else ( for j : Integer.subrange(1, m-1) do ( execute ('.')->display()) ; execute ('#')->display() ; execute (' ')->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=input() r=math.ceil(len(n)/20) if r==1 : print(r,len(n)) print(n) else : c=math.ceil(len(n)/r) a=r*c-len(n) print(r,c) i=0 for _ in range(r): if a>0 : print('*'+n[i : i+c-1]) i+=c-1 a-=1 continue print(n[i : i+c]) i+=c ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : String := (OclFile["System.in"]).readLine() ; var r : double := ((n)->size() / 20)->ceil() ; if r = 1 then ( execute (r)->display() ; execute (n)->display() ) else ( var c : double := ((n)->size() / r)->ceil() ; var a : double := r * c - (n)->size() ; execute (r)->display() ; var i : int := 0 ; for _anon : Integer.subrange(0, r-1) do ( if a > 0 then ( execute ('*' + n.subrange(i+1, i + c - 1))->display() ; i := i + c - 1 ; a := a - 1 ; continue ) else skip ; execute (n.subrange(i+1, i + c))->display() ; i := i + c) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() l=len(n) a=(l-1)//20+1 b=(l-1)//a+1 print(a,b) k=a*b-l for i in range(k): print(n[(b-1)*i :(b-1)*(i+1)]+'*') m=(b-1)*k for i in range(a-k): print(n[b*i+m : b*(i+1)+m]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var l : int := (n)->size() ; var a : int := (l - 1) div 20 + 1 ; var b : int := (l - 1) div a + 1 ; execute (a)->display() ; var k : double := a * b - l ; for i : Integer.subrange(0, k-1) do ( execute (n.subrange((b - 1) * i+1, (b - 1) * (i + 1)) + '*')->display()) ; var m : double := (b - 1) * k ; for i : Integer.subrange(0, a - k-1) do ( execute (n.subrange(b * i + m+1, b * (i + 1) + m))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline s=input()[:-1] x=len(s) for i in range(1,6): if x/i<=20 : d=[] a=x//i b=x % i c=i-b if b!=0 : while b : d.append(s[: a+1]) s=s[a+1 :] b-=1 while c : d.append(s[: a]+'*') s=s[a :] c-=1 else : while c : d.append(s[: a]) s=s[a :] c-=1 print(i,a+((x % i)!=0)) for j in d : print(j) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var s : OclAny := input()->front() ; var x : int := (s)->size() ; for i : Integer.subrange(1, 6-1) do ( if x / i <= 20 then ( var d : Sequence := Sequence{} ; var a : int := x div i ; var b : int := x mod i ; var c : double := i - b ; if b /= 0 then ( while b do ( execute ((s.subrange(1,a + 1)) : d) ; s := s.subrange(a + 1+1) ; b := b - 1) ; while c do ( execute ((s.subrange(1,a) + '*') : d) ; s := s.subrange(a+1) ; c := c - 1) ) else ( while c do ( execute ((s.subrange(1,a)) : d) ; s := s.subrange(a+1) ; c := c - 1) ) ; execute (i)->display() ; for j : d do ( execute (j)->display()) ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import heapq import sys import math import itertools import bisect from io import BytesIO,IOBase import os def value(): return tuple(map(int,input().split())) def values(): return tuple(map(int,sys.stdin.readline().split())) def inlst(): return[int(i)for i in input().split()] def inlsts(): return[int(i)for i in sys.stdin.readline().split()] def inp(): return int(input()) def inps(): return int(sys.stdin.readline()) def instr(): return input() def stlst(): return[i for i in input().split()] def help(a,b,l): tot=[] for i in range(b): tot.append(l[i*a : i*a+a]) for i in zip(*tot): if sum((i))==b : return True return False def solve(): tot=[] x=instr() s=[] for i in x : if i=='O' : s.append(0) else : s.append(1) for i in range(1,13): if 12 % i==0 : if help(i,12//i,s): tot.append((12//i,i)) print(len(tot),end=' ') for a,b in sorted(tot): print(f'{a}x{b}',end=' ') print() if __name__=="__main__" : for i in range(inp()): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( for i : Integer.subrange(0, inp()-1) do ( solve()) ) else skip; operation value() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation values() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inlsts() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inps() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation instr() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation stlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (i)); operation help(a : OclAny, b : OclAny, l : OclAny) : OclAny pre: true post: true activity: var tot : Sequence := Sequence{} ; for i : Integer.subrange(0, b-1) do ( execute ((l.subrange(i * a+1, i * a + a)) : tot)) ; for i : Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name tot)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name tot)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name tot)))))))`third->at(_indx)} ) do ( if ((i))->sum() = b then ( return true ) else skip) ; return false; operation solve() pre: true post: true activity: tot := Sequence{} ; var x : OclAny := instr() ; var s : Sequence := Sequence{} ; for i : x do ( if i = 'O' then ( execute ((0) : s) ) else ( execute ((1) : s) )) ; for i : Integer.subrange(1, 13-1) do ( if 12 mod i = 0 then ( if help(i, 12 div i, s) then ( execute ((Sequence{12 div i, i}) : tot) ) else skip ) else skip) ; execute ((tot)->size())->display() ; for _tuple : tot->sort() do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); execute (StringLib.formattedString('{a}x{b}'))->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() l=len(s) m=(l+19)//20 n=(l+m-1)//m t=m-(n*m % l) print(m,n) for i in range(m): if t>0 : t-=1 print(s[0 : n]) s=s[n :] else : print(s[0 : n-1]+'*') s=s[n-1 :] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var l : int := (s)->size() ; var m : int := (l + 19) div 20 ; var n : int := (l + m - 1) div m ; var t : double := m - (n * m mod l) ; execute (m)->display() ; for i : Integer.subrange(0, m-1) do ( if t > 0 then ( t := t - 1 ; execute (s.subrange(0+1, n))->display() ; s := s.subrange(n+1) ) else ( execute (s.subrange(0+1, n - 1) + '*')->display() ; s := s.subrange(n - 1+1) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys for s in sys.stdin : a,l,x=map(float,s.split()); print(a/2*(l*l-a*a/4)**.5+l/2*(2*l*x+x*x)**.5) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for s : OclFile["System.in"] do ( var a : OclAny := null; var l : OclAny := null; var x : OclAny := null; Sequence{a,l,x} := (s.split())->collect( _x | (OclType["double"])->apply(_x) ); execute (a / 2 * ((l * l - a * a / 4))->pow(.5) + l / 2 * ((2 * l * x + x * x))->pow(.5))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from collections import defaultdict from datetime import datetime,timedelta def sol(): a=input() leng=len(a) num=math.ceil(leng/20) count=leng//num rem=leng % num rem1=rem print(num,count+(1 if(rem!=0)else 0)) if leng<=20 : print(a) return ans=[] i=0 while(num): count1=count while(count1): ans.append(a[i]) i+=1 count1-=1 if(rem1): ans.append(a[i]) i+=1 rem1-=1 elif(rem!=0): ans.append('*') num-=1 ans.append('\n') print(''.join(ans)) def main(): sol() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; main(); operation sol() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var leng : int := (a)->size() ; var num : double := (leng / 20)->ceil() ; var count : int := leng div num ; var rem : int := leng mod num ; var rem1 : int := rem ; execute (num)->display() ; if leng <= 20 then ( execute (a)->display() ; return ) else skip ; var ans : Sequence := Sequence{} ; var i : int := 0 ; while (num) do ( var count1 : int := count ; while (count1) do ( execute ((a[i+1]) : ans) ; i := i + 1 ; count1 := count1 - 1) ; if (rem1) then ( execute ((a[i+1]) : ans) ; i := i + 1 ; rem1 := rem1 - 1 ) else (if (rem /= 0) then ( execute (('*') : ans) ) else skip) ; num := num - 1 ; execute ((' ') : ans)) ; execute (StringLib.sumStringsWithSeparator((ans), ''))->display(); operation main() pre: true post: true activity: sol(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findCountOfPairs(a,b,n): ans=0 for i in range(1,a+1): ans+=b//n ans+=1 if(i % n+b % n)>=n else 0 return ans a=5 ; b=13 ; n=3 print(findCountOfPairs(a,b,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 5; b := 13; n := 3 ; execute (findCountOfPairs(a, b, n))->display(); operation findCountOfPairs(a : OclAny, b : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(1, a + 1-1) do ( ans := ans + b div n ; ans := ans + if ((i mod n + b mod n)->compareTo(n)) >= 0 then 1 else 0 endif) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) int1=lambda x : int(x)-1 p2D=lambda x : print(*x,sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int,sys.stdin.readline().split()) def LI(): return list(map(int,sys.stdin.readline().split())) def LLI(rows_number): return[LI()for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] def main(): n=II() aa=LI() s=sum(aa) if n % 2 : if s % 2 : ans="First" else : ans="Second" else : mn=min(aa) if s % 2==0 and mn % 2==0 : ans="Second" else : ans="First" print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; var p2D : Function := lambda x : OclAny in (((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ; skip ; skip ; skip ; skip ; skip ; skip ; main(); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LLI(rows_number : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows_number-1)->select(_anon | true)->collect(_anon | (LI())); operation SI() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation main() pre: true post: true activity: var n : OclAny := II() ; var aa : OclAny := LI() ; var s : OclAny := (aa)->sum() ; if n mod 2 then ( if s mod 2 then ( var ans : String := "First" ) else ( ans := "Second" ) ) else ( var mn : OclAny := (aa)->min() ; if s mod 2 = 0 & mn mod 2 = 0 then ( ans := "Second" ) else ( ans := "First" ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from heapq import heappush,heappop from itertools import permutations,accumulate import sys import math import bisect def LI(): return[int(x)for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return[list(x)for x in sys.stdin.readline().split()] def S(): res=list(sys.stdin.readline()) if res[-1]=="\n" : return res[:-1] return res def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] sys.setrecursionlimit(1000000) mod=1000000007 def solve(): n=I() a=LI() print(["First","Second"][((n & 1)&(1 ^ sum(a)& 1))|((1 ^ n & 1)&(1 ^ sum(a)& 1)&(1 ^ min(a)& 1))]) return if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1000000) ; var mod : int := 1000000007 ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | ((x))); operation S() : OclAny pre: true post: true activity: var res : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if res->last() = "\n" then ( return res->front() ) else skip ; return res; operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation solve() pre: true post: true activity: n := I() ; var a : OclAny := LI() ; execute (Sequence{"First"}->union(Sequence{ "Second" })[MathLib.bitwiseOr((MathLib.bitwiseAnd((MathLib.bitwiseAnd(n, 1)), (MathLib.bitwiseXor(1, MathLib.bitwiseAnd((a)->sum(), 1))))), (MathLib.bitwiseAnd(MathLib.bitwiseAnd((MathLib.bitwiseXor(1, MathLib.bitwiseAnd(n, 1))), (MathLib.bitwiseXor(1, MathLib.bitwiseAnd((a)->sum(), 1)))), (MathLib.bitwiseXor(1, MathLib.bitwiseAnd((a)->min(), 1))))))+1])->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) t=min(a) s=sum(a) if s % 2 or(not n % 2 and t % 2): print('First') else : print('Second') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : OclAny := (a)->min() ; var s : OclAny := (a)->sum() ; if s mod 2 or (not(n mod 2) & t mod 2) then ( execute ('First')->display() ) else ( execute ('Second')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(N,a): if N % 2==1 : return["Second","First"][sum(a)% 2] else : if min(a)% 2==1 : return "First" return["Second","First"][sum(a)% 2] if __name__=="__main__" : N=int(input()) a=list(map(int,input().split())) print(solve(N,a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (solve(N, a))->display() ) else skip; operation solve(N : OclAny, a : OclAny) : OclAny pre: true post: true activity: if N mod 2 = 1 then ( return Sequence{"Second"}->union(Sequence{ "First" })[(a)->sum() mod 2+1] ) else ( if (a)->min() mod 2 = 1 then ( return "First" ) else skip ; return Sequence{"Second"}->union(Sequence{ "First" })[(a)->sum() mod 2+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline sys.setrecursionlimit(1000000) from collections import deque,Counter def getN(): return int(input()) def getList(): return list(map(int,input().split())) import math INF=10**20 def main(): n=getN() nums=getList() sm=sum(nums) ans=sm % 2 if n % 2==1 : if ans==1 : print("First") else : print("Second") return if n % 2==0 : mn=min(nums) if ans==1 : if sm==mn*n : print("Second") else : print("First") else : if mn % 2==1 : print("First") else : print("Second") if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit(1000000) ; skip ; skip ; skip ; skip ; var INF : double := (10)->pow(20) ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation getN() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation getList() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation main() pre: true post: true activity: var n : OclAny := getN() ; var nums : OclAny := getList() ; var sm : OclAny := (nums)->sum() ; var ans : int := sm mod 2 ; if n mod 2 = 1 then ( if ans = 1 then ( execute ("First")->display() ) else ( execute ("Second")->display() ) ; return ) else skip ; if n mod 2 = 0 then ( var mn : OclAny := (nums)->min() ; if ans = 1 then ( if sm = mn * n then ( execute ("Second")->display() ) else ( execute ("First")->display() ) ) else ( if mn mod 2 = 1 then ( execute ("First")->display() ) else ( execute ("Second")->display() ) ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def powerSet(str1,index,curr): n=len(str1) if(index==n): return print(curr) for i in range(index+1,n): curr+=str1[i] powerSet(str1,i,curr) curr=curr.replace(curr[len(curr)-1],"") return if __name__=='__main__' : str="abc" ; powerSet(str,-1,"") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var OclType["String"] : String := "abc"; ; powerSet(OclType["String"], -1, "") ) else skip; operation powerSet(str1 : OclAny, index : OclAny, curr : OclAny) pre: true post: true activity: var n : int := (str1)->size() ; if (index = n) then ( return ) else skip ; execute (curr)->display() ; for i : Integer.subrange(index + 1, n-1) do ( curr := curr + str1[i+1] ; powerSet(str1, i, curr) ; curr := curr.replace(curr[(curr)->size() - 1+1], "")) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math s=list(map(str,input().split())) s=s[0] n=len(s) now=1 amari=[] for i in range(len(s)): amari.append(now) now=(now*10)% 13 ans=[[0 for i in range(13)]for j in range(2)] ans[0][0]=1 ans[1][0]=1 for i in range(len(s)): now=s[n-1-i] ans[(i+1)% 2]=[0 for i in range(13)] if(now=="?"): for k in range(10): plus=(amari[i]*k)% 13 for j in range(13): ans[(i+1)% 2][(j+plus)% 13]+=ans[i % 2][j] ans[(i+1)% 2][(j+plus)% 13]%=1000000007 else : now=int(now) plus=(amari[i]*now)% 13 for j in range(13): ans[(i+1)% 2][(j+plus)% 13]=ans[i % 2][j] last=(i+1)% 2 print(ans[last][5]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : Sequence := ((input().split())->collect( _x | (OclType["String"])->apply(_x) )) ; s := s->first() ; var n : int := (s)->size() ; var now : int := 1 ; var amari : Sequence := Sequence{} ; for i : Integer.subrange(0, (s)->size()-1) do ( execute ((now) : amari) ; now := (now * 10) mod 13) ; var ans : Sequence := Integer.subrange(0, 2-1)->select(j | true)->collect(j | (Integer.subrange(0, 13-1)->select(i | true)->collect(i | (0)))) ; ans->first()->first() := 1 ; ans[1+1]->first() := 1 ; for i : Integer.subrange(0, (s)->size()-1) do ( now := s[n - 1 - i+1] ; ans[(i + 1) mod 2+1] := Integer.subrange(0, 13-1)->select(i | true)->collect(i | (0)) ; if (now = "?") then ( for k : Integer.subrange(0, 10-1) do ( var plus : int := (amari[i+1] * k) mod 13 ; for j : Integer.subrange(0, 13-1) do ( ans[(i + 1) mod 2+1][(j + plus) mod 13+1] := ans[(i + 1) mod 2+1][(j + plus) mod 13+1] + ans[i mod 2+1][j+1] ; ans[(i + 1) mod 2+1][(j + plus) mod 13+1] := ans[(i + 1) mod 2+1][(j + plus) mod 13+1] mod 1000000007)) ) else ( now := ("" + ((now)))->toInteger() ; plus := (amari[i+1] * now) mod 13 ; for j : Integer.subrange(0, 13-1) do ( ans[(i + 1) mod 2+1][(j + plus) mod 13+1] := ans[i mod 2+1][j+1]) ) ; var last : int := (i + 1) mod 2) ; execute (ans[last+1][5+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : a,b,c,d,e=map(int,input().split()) if a==0 : break na,nb,nc=map(int,input().split()) if nc>=d : ans=e*nc+b*nb+a*na else : ans=c*nc+b*nb+a*na k=d-nc ; if k<=nb : nb-=k ; k=0 else : k-=nb ; nb=0 if k<=na : na-=k else : na=0 ans=min(ans,e*d+b*nb+a*na) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; Sequence{a,b,c,d,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 0 then ( break ) else skip ; var na : OclAny := null; var nb : OclAny := null; var nc : OclAny := null; Sequence{na,nb,nc} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (nc->compareTo(d)) >= 0 then ( var ans : double := e * nc + b * nb + a * na ) else ( ans := c * nc + b * nb + a * na ; var k : double := d - nc; ; if (k->compareTo(nb)) <= 0 then ( nb := nb - k; k := 0 ) else ( k := k - nb; var nb : int := 0 ) ; if (k->compareTo(na)) <= 0 then ( na := na - k ) else ( var na : int := 0 ) ; ans := Set{ans, e * d + b * nb + a * na}->min() ) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : a,b,c,d,e=map(int,input().split()) if a==b==c==d==e==0 : break na,nb,nc=map(int,input().split()) if nc>=d : print(e*nc+b*nb+a*na) continue lst=[c]*nc+[b]*nb+[a]*na if na+nb+nc>d : print(min(sum(lst[: d]),e*d)+sum(lst[d :])) else : print(min(sum(lst),e*d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; Sequence{a,b,c,d,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = b & (b == c) & (c == d) & (d == e) & (e == 0) then ( break ) else skip ; var na : OclAny := null; var nb : OclAny := null; var nc : OclAny := null; Sequence{na,nb,nc} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (nc->compareTo(d)) >= 0 then ( execute (e * nc + b * nb + a * na)->display() ; continue ) else skip ; var lst : Sequence := MatrixLib.elementwiseMult(Sequence{ c }, nc)->union(MatrixLib.elementwiseMult(Sequence{ b }, nb))->union(MatrixLib.elementwiseMult(Sequence{ a }, na)) ; if (na + nb + nc->compareTo(d)) > 0 then ( execute (Set{(lst.subrange(1,d))->sum(), e * d}->min() + (lst.subrange(d+1))->sum())->display() ) else ( execute (Set{(lst)->sum(), e * d}->min())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt try : while 1 : a,l,x=map(int,input().split()) print("%.10f" %(l*sqrt(x*(2*l+x))/2+a*sqrt(4*l**2-a**2)/4)) except EOFError : ... ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; try ( while 1 do ( var a : OclAny := null; var l : OclAny := null; var x : OclAny := null; Sequence{a,l,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (StringLib.format("%.10f",(l * sqrt(x * (2 * l + x)) / 2 + a * sqrt(4 * (l)->pow(2) - (a)->pow(2)) / 4)))->display())) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom ...)))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() n=len(s) freq=[0]*26 for i in range(n): freq[ord(s[i])-ord('a')]+=1 unique=0 cnt=[0,0,0] for i in range(26): if freq[i]>0 : unique+=1 if freq[i]==1 : cnt[1]+=1 else : cnt[2]+=1 if unique<=1 or unique>=5 : print("No") elif unique==4 : print("Yes") elif unique==3 and cnt[2]>=1 : print("Yes") elif unique==2 and cnt[2]>=2 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var n : int := (s)->size() ; var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for i : Integer.subrange(0, n-1) do ( freq[(s[i+1])->char2byte() - ('a')->char2byte()+1] := freq[(s[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; var unique : int := 0 ; var cnt : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) ; for i : Integer.subrange(0, 26-1) do ( if freq[i+1] > 0 then ( unique := unique + 1 ; if freq[i+1] = 1 then ( cnt[1+1] := cnt[1+1] + 1 ) else ( cnt[2+1] := cnt[2+1] + 1 ) ) else skip) ; if unique <= 1 or unique >= 5 then ( execute ("No")->display() ) else (if unique = 4 then ( execute ("Yes")->display() ) else (if unique = 3 & cnt[2+1] >= 1 then ( execute ("Yes")->display() ) else (if unique = 2 & cnt[2+1] >= 2 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() a=[0]*26 for i in range(len(s)): a[ord(s[i])-ord('a')]+=1 ctr=0 for x in a : if x>0 : ctr+=1 ans="No" if ctr>1 : if ctr==2 : cnt=0 for x in a : if x>1 : cnt+=1 if cnt==ctr : ans="Yes" elif ctr==3 : b=False for x in a : if x>1 : b=True break if b : ans="Yes" elif ctr==4 : ans="Yes" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for i : Integer.subrange(0, (s)->size()-1) do ( a[(s[i+1])->char2byte() - ('a')->char2byte()+1] := a[(s[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; var ctr : int := 0 ; for x : a do ( if x > 0 then ( ctr := ctr + 1 ) else skip) ; var ans : String := "No" ; if ctr > 1 then ( if ctr = 2 then ( var cnt : int := 0 ; for x : a do ( if x > 1 then ( cnt := cnt + 1 ) else skip) ; if cnt = ctr then ( ans := "Yes" ) else skip ) else (if ctr = 3 then ( var b : boolean := false ; for x : a do ( if x > 1 then ( b := true ; break ) else skip) ; if b then ( ans := "Yes" ) else skip ) else (if ctr = 4 then ( ans := "Yes" ) else skip ) ) ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter s=input() d=Counter(s) if len(s)<4 or len(d)>4 or len(d)==1 : print('No') elif len(d)>=3 : print('Yes') elif any(d[k]==1 for k in d): print('No') else : print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : String := (OclFile["System.in"]).readLine() ; var d : OclAny := Counter(s) ; if (s)->size() < 4 or (d)->size() > 4 or (d)->size() = 1 then ( execute ('No')->display() ) else (if (d)->size() >= 3 then ( execute ('Yes')->display() ) else (if ((argument (test (logical_test (comparison (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])))) == (comparison (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name k)))) in (logical_test (comparison (expr (atom (name d))))))))->exists( _x | _x = true ) then ( execute ('No')->display() ) else ( execute ('Yes')->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter d=Counter(input()) if sum(d.values())<4 or len(d)>4 or len(d)==1 : print('No') elif len(d)>=3 : print('Yes') elif any(d[k]==1 for k in d): print('No') else : print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var d : OclAny := Counter((OclFile["System.in"]).readLine()) ; if (d.values())->sum() < 4 or (d)->size() > 4 or (d)->size() = 1 then ( execute ('No')->display() ) else (if (d)->size() >= 3 then ( execute ('Yes')->display() ) else (if ((argument (test (logical_test (comparison (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])))) == (comparison (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name k)))) in (logical_test (comparison (expr (atom (name d))))))))->exists( _x | _x = true ) then ( execute ('No')->display() ) else ( execute ('Yes')->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter d=Counter(input()) if sum(d.values())<4 or len(d)>4 or len(d)==1 : print('No') elif len(d)>=3 : print('Yes') elif any(d[k]==1 for k in d): print('No') else : print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var d : OclAny := Counter((OclFile["System.in"]).readLine()) ; if (d.values())->sum() < 4 or (d)->size() > 4 or (d)->size() = 1 then ( execute ('No')->display() ) else (if (d)->size() >= 3 then ( execute ('Yes')->display() ) else (if ((argument (test (logical_test (comparison (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])))) == (comparison (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name k)))) in (logical_test (comparison (expr (atom (name d))))))))->exists( _x | _x = true ) then ( execute ('No')->display() ) else ( execute ('Yes')->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ps=[] n=int(input()) for i in range(n): x,y=map(int,input().split()) ps.append((x,y)) ps.sort() for i in ps : print(*i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ps : Sequence := Sequence{} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{x, y}) : ps)) ; ps := ps->sort() ; for i : ps do ( execute ((argument * (test (logical_test (comparison (expr (atom (name i))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Pairs : def __init__(self,x,y): self.x=x self.y=y def __lt__(self,other): if self.xexists( _x | result = _x ); attribute x : OclAny := x; attribute y : OclAny := y; operation initialise(x : OclAny,y : OclAny) : Pairs pre: true post: true activity: self.x := x ; self.y := y; return self; operation __lt__(other : OclAny) : OclAny pre: true post: true activity: if (self.x->compareTo(other.x)) < 0 then ( return true ) else (if self.x = other.x then ( return (self.y->compareTo(other.y)) < 0 ) else ( return false ) ) ; operation __str__() : OclAny pre: true post: true activity: return StringLib.interpolateStrings("{}{}", Sequence{self.x, self.y}); } class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var L : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( Sequence{x,y} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (((Pairs.newPairs()).initialise(x, y)) : L)) ; L := L->sort() ; for i : L do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def emit(text,*args): msg=text % args sys.stderr.write(msg) sys.stdout.write(msg) def choose(n,k): if 0<=k<=n : ntok=1 ktok=1 for t in xrange(1,min(k,n-k)+1): ntok*=n ktok*=t n-=1 return ntok//ktok else : return 0 def pyramid_size(height): base=2*height+1 return(base*(base+1))/2 def solve(n,x,y): if x==0 : if n>=pyramid_size(y/2): return 1.0 else : return 0.0 if x<0 : x=-x foundation_height=(y+x)/2-1 foundation=pyramid_size(foundation_height) n=n-foundation if n<=y : return 0.0 if n>(foundation_height+1)*2+y : return 1.0 options=0 for i in range(y+1,n+1): options+=choose(n,i) for i in range(n): if options>2**30 : options=options//2 else : options=options/2.0 return options def getline(): return sys.stdin.readline().rstrip('\n') ncases=int(getline()) for casenr in range(1,ncases+1): n,x,y=[int(s)for s in getline().split()] emit("Case #%d: %s\n",casenr,solve(n,x,y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var ncases : int := ("" + ((getline())))->toInteger() ; for casenr : Integer.subrange(1, ncases + 1-1) do ( Sequence{n,x,y} := getline().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; emit("Case #%d: %s\n", casenr, solve(n, x, y))); operation emit(text : OclAny, args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) var msg : int := text mod args ; (expr (atom (name sys)) (trailer . (name stderr)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name msg)))))))) )))) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name msg)))))))) )))); operation choose(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if 0 <= k & (k <= n) then ( var ntok : int := 1 ; var ktok : int := 1 ; for t : xrange(1, Set{k, n - k}->min() + 1) do ( ntok := ntok * n ; ktok := ktok * t ; n := n - 1) ; return ntok div ktok ) else ( return 0 ); operation pyramid_size(height : OclAny) : OclAny pre: true post: true activity: var base : double := 2 * height + 1 ; return (base * (base + 1)) / 2; operation solve(n : OclAny, x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if x = 0 then ( if (n->compareTo(pyramid_size(y / 2))) >= 0 then ( return 1.0 ) else ( return 0.0 ) ) else skip ; if x < 0 then ( x := -x ) else skip ; var foundation_height : double := (y + x) / 2 - 1 ; var foundation : OclAny := pyramid_size(foundation_height) ; n := n - foundation ; if (n->compareTo(y)) <= 0 then ( return 0.0 ) else skip ; if (n->compareTo((foundation_height + 1) * 2 + y)) > 0 then ( return 1.0 ) else skip ; var options : int := 0 ; for i : Integer.subrange(y + 1, n + 1-1) do ( options := options + choose(n, i)) ; for i : Integer.subrange(0, n-1) do ( if (options->compareTo((2)->pow(30))) > 0 then ( options := options div 2 ) else ( options := options / 2.0 )) ; return options; operation getline() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil t=int(input()) while t>0 : n=int(input()) s=input() count=0 for i in range(n-1): if s[i]==s[i+1]: count+=1 print(ceil(count/2)) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var count : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if s[i+1] = s[i + 1+1] then ( count := count + 1 ) else skip) ; execute (ceil(count / 2))->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- readline=open(0).readline N=int(readline()) P=[tuple(map(int,readline().split()))for i in range(N)] P.sort() open(1,'w').writelines(["%d %d\n" % e for e in P]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var readline : OclAny := open(0).readline ; var N : int := ("" + ((readline())))->toInteger() ; var P : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((readline().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; P := P->sort() ; (expr (atom (name open)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom 'w'))))))) ))) (trailer . (name writelines) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom "%d %d\n")) % (expr (atom (name e))))))) (comp_for for (exprlist (expr (atom (name e)))) in (logical_test (comparison (expr (atom (name P))))))) ]))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def main(): l=[] for i in range(int(input())): (a,b)=map(int,input().split()) l.append((a,b)) for a,b in sorted(l): print(a,b) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { suite`nestedAttributeDefinitions operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var Sequence{a, b} : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation main(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (suite); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from typing import List,Tuple if __name__=="__main__" : n=int(input()) coordinates : List[Tuple[int,int]]=[] for _ in range(n): (x,y)=tuple(map(lambda x : int(x),input().split())) coordinates.append((x,y)) coordinates=sorted(coordinates,key=lambda x :(x[0],x[1])) for elem in coordinates : print(f"{elem[0]}{elem[1]}") ------------------------------------------------------------ OCL File: --------- class FromPython { suite`nestedAttributeDefinitions operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var coordinates : OclAny := Sequence{} ; for _anon : Integer.subrange(0, n-1) do (suite) ) else skip ; var Sequence{x, y} : Sequence := ((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def multiplyWith4(n): return(n<<2) n=4 print(multiplyWith4(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute (multiplyWith4(n))->display(); operation multiplyWith4(n : OclAny) : OclAny pre: true post: true activity: return (n * (2->pow(2))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a,b,c=map(int,input().split()) print(a+b+c-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (a + b + c - 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): print(sum(map(int,input().split()))-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( execute (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum() - 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b,c=map(int,input().split()) print(max(a,b,c)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{a, b, c}->max() + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): a,b,c=map(int,input().split()) print(max(a,b,c)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{a, b, c}->max() + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): li=sorted(list(map(int,input().split()))) m=li.pop() s=sum(li) if m>s : print(m-s+1) else : print((m+s)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var li : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var m : OclAny := li->last() ; li := li->front() ; var s : OclAny := (li)->sum() ; if (m->compareTo(s)) > 0 then ( execute (m - s + 1)->display() ) else ( execute ((m + s) div 2)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def allBitsSetInTheGivenRange(n,l,r): num=((1<display() ) else skip; operation allBitsSetInTheGivenRange(n : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var num : int := MathLib.bitwiseXor(((1 * (2->pow(r))) - 1), ((1 * (2->pow((l - 1)))) - 1)) ; var new_num : int := MathLib.bitwiseAnd(n, num) ; if (new_num = 0) then ( return "Yes" ) else skip ; return "No"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=10**9+7 def solve(s,p=13): a=[0]*p a[0]=1 for c in s : b=[0]*p for i in range(p): b[(i*10)% p]=a[i]% MOD b+=b if c=="?" : for i in range(p): a[i]=sum(b[i+4 : i+p+1]) else : for i in range(p): a[i]=b[i+p-int(c)] return a[5]% MOD s=input() print(solve(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : double := (10)->pow(9) + 7 ; skip ; s := (OclFile["System.in"]).readLine() ; execute (solve(s))->display(); operation solve(s : OclAny, p : int) : OclAny pre: true post: true activity: if p->oclIsUndefined() then p := 13 else skip; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, p) ; a->first() := 1 ; for c : s do ( var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, p) ; for i : Integer.subrange(0, p-1) do ( b[(i * 10) mod p+1] := a[i+1] mod MOD) ; b := b + b ; if c = "?" then ( for i : Integer.subrange(0, p-1) do ( a[i+1] := (b.subrange(i + 4+1, i + p + 1))->sum()) ) else ( for i : Integer.subrange(0, p-1) do ( a[i+1] := b[i + p - ("" + ((c)))->toInteger()+1]) )) ; return a[5+1] mod MOD; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil,log2 def solve(n,x,y): length=ceil(log2(n+2))-1 ; rank=n-(1<display(); ) else skip; operation solve(n : OclAny, x : OclAny, y : OclAny) pre: true post: true activity: var length : double := ceil(log2(n + 2)) - 1; ; var rank : double := n - (1 * (2->pow(length))) + 1; ; var left : String := ""; var right : String := ""; ; for i : Integer.subrange(-1 + 1, length - 1)->reverse() do ( var mask : int := (1 * (2->pow(i))); ; var bit : int := (MathLib.bitwiseAnd(mask, rank)); ; if (bit) then ( left := left + y; ; right := right + y; ) else ( left := left + x; ; right := right + x; )) ; right := right(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); ; var res : String := left + right; ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from datetime import datetime,timedelta import re prophecy=str(input()) def date_range(start,end): delta=end-start days=[start+timedelta(days=i)for i in range(delta.days+1)] return days start_date=datetime(2013,1,1) end_date=datetime(2015,12,31) count=dict() for date in date_range(start_date,end_date): if date.day>=10 : day=str(date.day) else : day="0"+str(date.day) if date.month>=10 : month=str(date.month) else : month="0"+str(date.month) date_pattern=day+"-"+month+"-"+str(date.year) indices_object=re.finditer(pattern=date_pattern,string=prophecy) indices=[index.start()for index in indices_object] count[date_pattern]=len(indices) print(max(count,key=count.get)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var prophecy : String := ("" + (((OclFile["System.in"]).readLine()))) ; skip ; var start_date : OclAny := ; var end_date : OclAny := ; var count : Map := (arguments ( )) ; for date : date_range(start_date, end_date) do ( if date.getDate() >= 10 then ( var day : String := ("" + ((date.getDate()))) ) else ( day := "0" + ("" + ((date.getDate()))) ) ; if date.getMonth() >= 10 then ( var month : String := ("" + ((date.getMonth()))) ) else ( month := "0" + ("" + ((date.getMonth()))) ) ; var date_pattern : String := day + "-" + month + "-" + ("" + ((date.getYear()))) ; var indices_object : OclIterator := OclIterator.newOclIterator_Sequence(((argument (test (logical_test (comparison (expr (atom (name string)))))) = (test (logical_test (comparison (expr (atom (name prophecy))))))))->allMatches((argument (test (logical_test (comparison (expr (atom (name pattern)))))) = (test (logical_test (comparison (expr (atom (name date_pattern))))))))) ; var indices : Sequence := indices_object->select(index | true)->collect(index | (index.start())) ; count->at(date_pattern) := (indices)->size()) ; execute (Set{count, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name count)) (trailer . (name get)))))))}->max())->display(); operation date_range(start : OclAny, end : OclAny) : OclAny pre: true post: true activity: var delta : double := end - start ; var days : Sequence := Integer.subrange(0, delta.days + 1-1)->select(i | true)->collect(i | (start + timedelta((argument (test (logical_test (comparison (expr (atom (name days)))))) = (test (logical_test (comparison (expr (atom (name i)))))))))) ; return days; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(s): d={1 : 31,2 : 28,3 : 31,4 : 30,5 : 31,6 : 30,7 : 31,8 : 31,9 : 30,10 : 31,11 : 30,12 : 31} valid_dates={} y=["2013","2014","2015"] for year in y : k="" j=0 for i in range(len(s)): if s[i]==year[j]: if j==len(year)-1 : flag=0 j=0 if s[i-4]=="-" and s[i-7]=="-" : try : if(int(s[i-6 : i-4])>=1 and int(s[i-6 : i-4])<=12): if int(s[i-9 : i-7])>=1 and int(s[i-9 : i-7])<=d[int(s[i-6 : i-4])]: if s[i-9 : i+1]not in valid_dates : valid_dates[s[i-9 : i+1]]=1 else : valid_dates[s[i-9 : i+1]]+=1 else : flag=1 else : flag=1 except : flag=1 else : flag=1 else : j+=1 else : j=0 return valid_dates s=input() m=0 v=solve(s) prophecy_date="" for i in v : if v[i]>m : m=v[i] prophecy_date=i print(prophecy_date) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := (OclFile["System.in"]).readLine() ; var m : int := 0 ; var v : OclAny := solve(s) ; var prophecy_date : String := "" ; for i : v do ( if (v[i+1]->compareTo(m)) > 0 then ( m := v[i+1] ; prophecy_date := i ) else skip) ; execute (prophecy_date)->display(); operation solve(s : OclAny) : OclAny pre: true post: true activity: var d : Map := Map{ 1 |-> 31 }->union(Map{ 2 |-> 28 }->union(Map{ 3 |-> 31 }->union(Map{ 4 |-> 30 }->union(Map{ 5 |-> 31 }->union(Map{ 6 |-> 30 }->union(Map{ 7 |-> 31 }->union(Map{ 8 |-> 31 }->union(Map{ 9 |-> 30 }->union(Map{ 10 |-> 31 }->union(Map{ 11 |-> 30 }->union(Map{ 12 |-> 31 }))))))))))) ; var valid_dates : OclAny := Set{} ; var y : Sequence := Sequence{"2013"}->union(Sequence{"2014"}->union(Sequence{ "2015" })) ; for year : y do ( var k : String := "" ; var j : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = year[j+1] then ( if j = (year)->size() - 1 then ( var flag : int := 0 ; j := 0 ; if s[i - 4+1] = "-" & s[i - 7+1] = "-" then ( try ( if (("" + ((s.subrange(i - 6+1, i - 4))))->toInteger() >= 1 & ("" + ((s.subrange(i - 6+1, i - 4))))->toInteger() <= 12) then ( if ("" + ((s.subrange(i - 9+1, i - 7))))->toInteger() >= 1 & (("" + ((s.subrange(i - 9+1, i - 7))))->toInteger()->compareTo(d[("" + ((s.subrange(i - 6+1, i - 4))))->toInteger()+1])) <= 0 then ( if (valid_dates)->excludes(s.subrange(i - 9+1, i + 1)) then ( valid_dates[s.subrange(i - 9+1, i + 1)+1] := 1 ) else ( valid_dates[s.subrange(i - 9+1, i + 1)+1] := valid_dates[s.subrange(i - 9+1, i + 1)+1] + 1 ) ) else ( flag := 1 ) ) else ( flag := 1 )) catch (_e : OclException) do ( flag := 1) ) else ( flag := 1 ) ) else ( j := j + 1 ) ) else ( j := 0 ))) ; return valid_dates; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() ch=dict() for i in range(len(s)-9): date=s[i : i+3] month=s[i+3 : i+6] year=s[i+6 : i+10] if('-' in year): continue elif(2013>int(year)or int(year)>2015): continue elif(month[-1]!='-' or month[0]=='-' or month[1]=='-'): continue elif(1>int(month[:-1])or int(month[:-1])>12): continue elif(date[-1]!='-' or date[0]=='-' or date[1]=='-'): continue else : month=int(month[:-1]) date=int(date[:-1]) if(month in[1,3,5,7,8,10,12]and(date<1 or date>31)): continue elif(month in[4,6,9,11]and(date<1 or date>30)): continue elif(month==2 and(date<1 or date>28)): continue if(s[i : i+10]in ch.keys()): ch[s[i : i+10]]+=1 else : ch[s[i : i+10]]=1 maxi=0 ans='' for i in ch : if(ch[i]>maxi): maxi=ch[i] ans=i print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var ch : Map := (arguments ( )) ; for i : Integer.subrange(0, (s)->size() - 9-1) do ( var date : OclAny := s.subrange(i+1, i + 3) ; var month : OclAny := s.subrange(i + 3+1, i + 6) ; var year : OclAny := s.subrange(i + 6+1, i + 10) ; if ((year)->includes('-')) then ( continue ) else (if (2013 > ("" + ((year)))->toInteger() or ("" + ((year)))->toInteger() > 2015) then ( continue ) else (if (month->last() /= '-' or month->first() = '-' or month[1+1] = '-') then ( continue ) else (if (1 > ("" + ((month->front())))->toInteger() or ("" + ((month->front())))->toInteger() > 12) then ( continue ) else (if (date->last() /= '-' or date->first() = '-' or date[1+1] = '-') then ( continue ) else ( month := ("" + ((month->front())))->toInteger() ; date := ("" + ((date->front())))->toInteger() ; if ((Sequence{1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{8}->union(Sequence{10}->union(Sequence{ 12 })))))))->includes(month) & (date < 1 or date > 31)) then ( continue ) else (if ((Sequence{4}->union(Sequence{6}->union(Sequence{9}->union(Sequence{ 11 }))))->includes(month) & (date < 1 or date > 30)) then ( continue ) else (if (month = 2 & (date < 1 or date > 28)) then ( continue ) else skip ) ) ) ) ) ) ) ; if ((ch.keys())->includes(s.subrange(i+1, i + 10))) then ( ch[s.subrange(i+1, i + 10)+1] := ch[s.subrange(i+1, i + 10)+1] + 1 ) else ( ch[s.subrange(i+1, i + 10)+1] := 1 )) ; var maxi : int := 0 ; var ans : String := '' ; for i : ch->keys() do ( if ((ch[i+1]->compareTo(maxi)) > 0) then ( maxi := ch[i+1] ; ans := i ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find_idx(arr,n): answer=[] _sum=0 for i in range(n-1,-1,-1): if(_sum==arr[i]): answer.append(i) _sum+=arr[i] if(len(answer)==0): print(-1) return for i in range(len(answer)-1,-1,-1): print(answer[i],end=" ") arr=[36,2,17,6,6,5] n=len(arr) find_idx(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{36}->union(Sequence{2}->union(Sequence{17}->union(Sequence{6}->union(Sequence{6}->union(Sequence{ 5 }))))) ; n := (arr)->size() ; find_idx(arr, n); operation find_idx(arr : OclAny, n : OclAny) pre: true post: true activity: var answer : Sequence := Sequence{} ; var _sum : int := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (_sum = arr[i+1]) then ( execute ((i) : answer) ) else skip ; _sum := _sum + arr[i+1]) ; if ((answer)->size() = 0) then ( execute (-1)->display() ; return ) else skip ; for i : Integer.subrange(-1 + 1, (answer)->size() - 1)->reverse() do ( execute (answer[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() a={} for i in range(len(s)-9): e=s[i : i+10].split('-') if(len(e)!=3): continue if(len(e[0])!=2 or len(e[1])!=2 or len(e[2])!=4): continue d=int(e[0]) m=int(e[1]) y=int(e[2]) if(y<2013 or y>2015): continue if(m<1 or m>12): continue if(m in(1,3,5,7,8,10,12)and(d<1 or d>31)): continue elif(m in(4,6,9,11)and(d<1 or d>30)): continue elif(m==2 and(d<1 or d>28)): continue if('-'.join(e)in a.keys()): a['-'.join(e)]+=1 else : a['-'.join(e)]=1 mx=0 qw="" for i in a.keys(): if(a[i]>mx): mx=a[i] qw=i print(qw) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var a : OclAny := Set{} ; for i : Integer.subrange(0, (s)->size() - 9-1) do ( var e : OclAny := s.subrange(i+1, i + 10).split('-') ; if ((e)->size() /= 3) then ( continue ) else skip ; if ((e->first())->size() /= 2 or (e[1+1])->size() /= 2 or (e[2+1])->size() /= 4) then ( continue ) else skip ; var d : int := ("" + ((e->first())))->toInteger() ; var m : int := ("" + ((e[1+1])))->toInteger() ; var y : int := ("" + ((e[2+1])))->toInteger() ; if (y < 2013 or y > 2015) then ( continue ) else skip ; if (m < 1 or m > 12) then ( continue ) else skip ; if ((Sequence{1, 3, 5, 7, 8, 10, 12})->includes(m) & (d < 1 or d > 31)) then ( continue ) else (if ((Sequence{4, 6, 9, 11})->includes(m) & (d < 1 or d > 30)) then ( continue ) else (if (m = 2 & (d < 1 or d > 28)) then ( continue ) else skip ) ) ; if ((a.keys())->includes(StringLib.sumStringsWithSeparator((e), '-'))) then ( a[StringLib.sumStringsWithSeparator((e), '-')+1] := a[StringLib.sumStringsWithSeparator((e), '-')+1] + 1 ) else ( a[StringLib.sumStringsWithSeparator((e), '-')+1] := 1 )) ; var mx : int := 0 ; var qw : String := "" ; for i : a.keys() do ( if ((a[i+1]->compareTo(mx)) > 0) then ( mx := a[i+1] ; qw := i ) else skip) ; execute (qw)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heappush,heappop n,m=map(int,input().split()) edges=[[]for _ in range(n)] for _ in range(m): a,b,c=map(int,input().split()) edges[a].append((b,c)) dist=[0]*n que=[] heappush(que,(0,0)) while que : total,node=heappop(que) total*=-1 for to,cost in edges[node]: if dist[to]collect( _x | (OclType["int"])->apply(_x) ) ; var edges : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name b)))))) , (test (logical_test (comparison (expr (atom (name c))))))) )))))))) ))))) ; var dist : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var que : Sequence := Sequence{} ; heappush(que, Sequence{0, 0}) ; while que do ( var total : OclAny := null; var node : OclAny := null; Sequence{total,node} := heappop(que) ; total := total * -1 ; for _tuple : edges[node+1] do (var _indx : int := 1; var to : OclAny := _tuple->at(_indx); _indx := _indx + 1; var cost : OclAny := _tuple->at(_indx); if (dist[to+1]->compareTo(total + cost)) < 0 then ( dist[to+1] := total + cost ; heappush(que, Sequence{-(total + cost), to}) ) else skip)) ; execute (dist[n - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys reader=(token for line in sys.stdin for token in line.split()) while 1 : try : n=int(next(reader)) m=int(next(reader)) except : break a=[1]*(n+1) for i in range(m): c=int(next(reader))-1 d=int(next(reader))-1 for i in range(c,d): a[i]=3 print(sum(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var reader : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name token)))))) (comp_for for (exprlist (expr (atom (name line)))) in (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin))))) (comp_iter (comp_for for (exprlist (expr (atom (name token)))) in (logical_test (comparison (expr (atom (name line)) (trailer . (name split) (arguments ( ))))))))))} ; while 1 do ( try ( var n : int := ("" + (((reader).next())))->toInteger() ; var m : int := ("" + (((reader).next())))->toInteger()) catch (_e : OclException) do ( break) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ; for i : Integer.subrange(0, m-1) do ( var c : double := ("" + (((reader).next())))->toInteger() - 1 ; var d : double := ("" + (((reader).next())))->toInteger() - 1 ; for i : Integer.subrange(c, d-1) do ( a[i+1] := 3)) ; execute ((a)->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,m=map(int,input().split()) v=[0]*N for i in range(m): c,d=map(int,input().split()) v[c-1]+=1 v[d-1]-=1 s=0 ; fst=0 ans=N+1 for i in range(N): if s==0 and v[i]>0 : fst=i s+=v[i] if s==0 and v[i]<0 : ans+=(i-fst)*2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var m : OclAny := null; Sequence{N,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var v : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for i : Integer.subrange(0, m-1) do ( var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; v[c - 1+1] := v[c - 1+1] + 1 ; v[d - 1+1] := v[d - 1+1] - 1) ; var s : int := 0; var fst : int := 0 ; var ans : OclAny := N + 1 ; for i : Integer.subrange(0, N-1) do ( if s = 0 & v[i+1] > 0 then ( fst := i ) else skip ; s := s + v[i+1] ; if s = 0 & v[i+1] < 0 then ( ans := ans + (i - fst) * 2 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=10**9+7 dd=[(0,-1),(1,0),(0,1),(-1,0)] ddn=[(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)] def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] while True : n,m=LI() if m==0 : rr.append(n+1) break a=[LI()for _ in range(m)] s=set() for c,d in a : s |=set(list(range(c,d))) rr.append(n+1+len(s)*2) break return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : double := (10)->pow(9) + 7 ; var dd : Sequence := Sequence{Sequence{0, -1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{ Sequence{-1, 0} }))) ; var ddn : Sequence := Sequence{Sequence{0, -1}}->union(Sequence{Sequence{1, -1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{1, 1}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{-1, -1}}->union(Sequence{Sequence{-1, 0}}->union(Sequence{ Sequence{-1, 1} }))))))) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := LI() ; if m = 0 then ( execute ((n + 1) : rr) ; break ) else skip ; var a : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (LI())) ; s := Set{}->union(()) ; for _tuple : a do (var _indx : int := 1; var c : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); s := s or Set{}->union(((Integer.subrange(c, d-1))))) ; execute ((n + 1 + (s)->size() * 2) : rr) ; break) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=[int(x)if x!='?' else '?' for x in input()] length=len(S) A=[0]*13 B=[0]*13 mod=5 first=0 r=1 for i in range(length): a=S[length-i-1] if a!='?' : a=(a*r)% 13 mod-=a mod %=13 elif first==0 : for j in range(10): a=(j*r)% 13 A[a]+=1 first=1 else : for j in range(10): a=(j*r)% 13 for k in range(13): B[(k+a)% 13]+=A[k] B[(k+a)% 13]%=10**9+7 A=B B=[0]*13 r=(r*10)% 13 if first==0 and mod==0 : print(1) elif first==0 and mod!=0 : print(0) else : print(A[mod]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : Sequence := (OclFile["System.in"]).readLine()->select(x | true)->collect(x | (if x /= '?' then ("" + ((x)))->toInteger() else '?' endif)) ; var length : int := (S)->size() ; var A : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 13) ; var B : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 13) ; var mod : int := 5 ; var first : int := 0 ; var r : int := 1 ; for i : Integer.subrange(0, length-1) do ( var a : OclAny := S[length - i - 1+1] ; if a /= '?' then ( a := (a * r) mod 13 ; mod := mod - a ; mod := mod mod 13 ) else (if first = 0 then ( for j : Integer.subrange(0, 10-1) do ( a := (j * r) mod 13 ; A[a+1] := A[a+1] + 1) ; first := 1 ) else ( for j : Integer.subrange(0, 10-1) do ( a := (j * r) mod 13 ; for k : Integer.subrange(0, 13-1) do ( B[(k + a) mod 13+1] := B[(k + a) mod 13+1] + A[k+1] ; B[(k + a) mod 13+1] := B[(k + a) mod 13+1] mod (10)->pow(9) + 7)) ; A := B ; B := MatrixLib.elementwiseMult(Sequence{ 0 }, 13) ) ) ; r := (r * 10) mod 13) ; if first = 0 & mod = 0 then ( execute (1)->display() ) else (if first = 0 & mod /= 0 then ( execute (0)->display() ) else ( execute (A[mod+1])->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,m=map(int,input().split()) again=set() for i in range(m): a,b=map(int,input().split()) for k in range(a,b): again.add(k) r=N+1+2*(len(again)) print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var m : OclAny := null; Sequence{N,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var again : Set := Set{}->union(()) ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for k : Integer.subrange(a, b-1) do ( execute ((k) : again))) ; var r : OclAny := N + 1 + 2 * ((again)->size()) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import(division,absolute_import,print_function,unicode_literals) from sys import stdin from collections import Counter cnt=Counter() for line in stdin : start,end=(int(s)for s in line.split()) if start or end : cnt[start]+=1 cnt[end]+=1 else : semi_eulerian=sum(i % 2 for i in cnt.values())==2 if semi_eulerian and cnt[1]% 2 and cnt[2]% 2 : print('OK') else : print('NG') cnt.clear() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var cnt : OclAny := Counter() ; for line : stdin do ( var start : OclAny := null; var end : OclAny := null; Sequence{start,end} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name line)) (trailer . (name split) (arguments ( ))))))))} ; if start or end then ( cnt[start+1] := cnt[start+1] + 1 ; cnt[end+1] := cnt[end+1] + 1 ) else ( var semi_eulerian : boolean := ((argument (test (logical_test (comparison (expr (expr (atom (name i))) % (expr (atom (number (integer 2)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name cnt)) (trailer . (name values) (arguments ( )))))))))->sum() = 2 ; if semi_eulerian & cnt[1+1] mod 2 & cnt[2+1] mod 2 then ( execute ('OK')->display() ) else ( execute ('NG')->display() ) ; execute (cnt /<: cnt) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import fileinput if __name__=='__main__' : G=[] g=[] for line in fileinput.input(): tokens=list(map(int,line.strip().split())) a,b=tokens[0],tokens[1] if a==0 and b==0 : G.append(g) g=[] else : g.append((tokens[0],tokens[1])) for g in G : result=True counts=[0 for i in range(100)] for a,b in g : counts[a-1]+=1 counts[b-1]+=1 for c in counts[0 : 2]: if c % 2==0 : result=False for c in counts[2 : 100]: if c % 2==1 : result=False print("OK" if result else "NG") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var G : Sequence := Sequence{} ; var g : Sequence := Sequence{} ; for line : fileinput.input() do ( var tokens : Sequence := ((line->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{tokens->first(),tokens[1+1]} ; if a = 0 & b = 0 then ( execute ((g) : G) ; g := Sequence{} ) else ( execute ((Sequence{tokens->first(), tokens[1+1]}) : g) )) ; for g : G do ( var result : boolean := true ; var counts : Sequence := Integer.subrange(0, 100-1)->select(i | true)->collect(i | (0)) ; for _tuple : g do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); counts[a - 1+1] := counts[a - 1+1] + 1 ; counts[b - 1+1] := counts[b - 1+1] + 1) ; for c : counts.subrange(0+1, 2) do ( if c mod 2 = 0 then ( result := false ) else skip) ; for c : counts.subrange(2+1, 100) do ( if c mod 2 = 1 then ( result := false ) else skip) ; execute (if result then "OK" else "NG" endif)->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : c=[0,1,1]+[0]*98 while 1 : try : a,b=map(int,raw_input().split()) except : exit() if a==0==b : break c[a]=-c[a]+1 c[b]=-c[b]+1 print["NG","OK"][sum(c)==0] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var c : Sequence := Sequence{0}->union(Sequence{1}->union(Sequence{ 1 }))->union(MatrixLib.elementwiseMult(Sequence{ 0 }, 98)) ; while 1 do ( try ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) )) catch (_e : OclException) do ( exit()) ; if a = 0 & (0 == b) then ( break ) else skip ; c[a+1] := -c[a+1] + 1 ; c[b+1] := -c[b+1] + 1) ; (expr (atom print) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom "NG")))))) , (subscript (test (logical_test (comparison (expr (atom "OK"))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))) == (comparison (expr (atom (number (integer 0)))))))))) ])))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import defaultdict data_list=[] for line in sys.stdin : data_list.append(list(map(int,line.split()))) def is_half_euler_graph(node_list): for node in node_list : isBool=True for dic_key,dic_value in node.items(): if dic_key!=1 and dic_key!=2 : if dic_value % 2!=0 : isBool=False break else : if dic_value % 2==0 : isBool=False break if isBool : print("OK") else : print("NG") if __name__=='__main__' : node_data_lists=[] tmp_list=[] count_lists=[] tmp_dic={} tmp_dic=defaultdict(int) for i in range(0,len(data_list)): if data_list[i][0]==0 and data_list[i][1]==0 : node_data_lists.append(tmp_list[:]) tmp_list.clear() else : tmp_list.append(data_list[i]) for node_data_list in node_data_lists : tmp_dic.clear() for i in range(0,len(node_data_list)): tmp_dic[node_data_list[i][0]]+=1 tmp_dic[node_data_list[i][1]]+=1 count_lists.append(tmp_dic.copy()) is_half_euler_graph(count_lists) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var data_list : Sequence := Sequence{} ; for line : OclFile["System.in"] do ( execute ((((line.split())->collect( _x | (OclType["int"])->apply(_x) ))) : data_list)) ; skip ; if __name__ = '__main__' then ( var node_data_lists : Sequence := Sequence{} ; var tmp_list : Sequence := Sequence{} ; var count_lists : Sequence := Sequence{} ; var tmp_dic : OclAny := Set{} ; tmp_dic := defaultdict(OclType["int"]) ; for i : Integer.subrange(0, (data_list)->size()-1) do ( if data_list[i+1]->first() = 0 & data_list[i+1][1+1] = 0 then ( execute ((tmp_list) : node_data_lists) ; execute (tmp_list /<: tmp_list) ) else ( execute ((data_list[i+1]) : tmp_list) )) ; for node_data_list : node_data_lists do ( execute (tmp_dic /<: tmp_dic) ; for i : Integer.subrange(0, (node_data_list)->size()-1) do ( tmp_dic[node_data_list[i+1]->first()+1] := tmp_dic[node_data_list[i+1]->first()+1] + 1 ; tmp_dic[node_data_list[i+1][1+1]+1] := tmp_dic[node_data_list[i+1][1+1]+1] + 1) ; execute ((tmp_dic->copy()) : count_lists)) ; is_half_euler_graph(count_lists) ) else skip; operation is_half_euler_graph(node_list : OclAny) pre: true post: true activity: for node : node_list do ( var isBool : boolean := true ; for _tuple : node->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var dic_key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dic_value : OclAny := _tuple->at(_indx); if dic_key /= 1 & dic_key /= 2 then ( if dic_value mod 2 /= 0 then ( isBool := false ; break ) else skip ) else ( if dic_value mod 2 = 0 then ( isBool := false ; break ) else skip )) ; if isBool then ( execute ("OK")->display() ) else ( execute ("NG")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) li=list(map(int,input().split())) pos=-2 if len(li)==1 : pos=-1 for i in range(k): for j in range(n-1): if li[j]=li[j+1]: if j+1==n-1 : pos=-1 break if pos==-1 : break print(pos) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var li : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var pos : int := -2 ; if (li)->size() = 1 then ( pos := -1 ) else skip ; for i : Integer.subrange(0, k-1) do ( for j : Integer.subrange(0, n - 1-1) do ( if (li[j+1]->compareTo(li[j + 1+1])) < 0 then ( li[j+1] := li[j+1] + 1 ; pos := j + 1 ; break ) else (if (li[j+1]->compareTo(li[j + 1+1])) >= 0 then ( if j + 1 = n - 1 then ( pos := -1 ; break ) else skip ) else skip)) ; if pos = -1 then ( break ) else skip) ; execute (pos)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readlines=sys.stdin.readlines write=sys.stdout.write def solve(): L=100 G=[[]for i in range(L)] for line in readlines(): a,b=map(int,line.split()) if a!=0!=b : G[a-1].append(b-1) G[b-1].append(a-1) continue ok=1 if len(G[0])% 2==0 and len(G[1])% 2==0 : ok=0 else : for i in range(2,L): if len(G[i])==0 : continue if len(G[i])% 2==1 : ok=0 write("OK\n" if ok else "NG\n") G=[[]for i in range(L)] solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readlines : OclAny := (OclFile["System.in"]).readlines ; var write : OclAny := (OclFile["System.out"]).write ; skip ; solve(); operation solve() pre: true post: true activity: var L : int := 100 ; var G : Sequence := Integer.subrange(0, L-1)->select(i | true)->collect(i | (Sequence{})) ; for line : readlines() do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (line.split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a /= 0 & (0 != b) then ( (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) )))) ; continue ) else skip ; var ok : int := 1 ; if (G->first())->size() mod 2 = 0 & (G[1+1])->size() mod 2 = 0 then ( ok := 0 ) else ( for i : Integer.subrange(2, L-1) do ( if (G[i+1])->size() = 0 then ( continue ) else skip ; if (G[i+1])->size() mod 2 = 1 then ( ok := 0 ) else skip) ) ; write(if ok then "OK\n" else "NG\n" endif) ; G := Integer.subrange(0, L-1)->select(i | true)->collect(i | (Sequence{}))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) if n==3 : print("3 1 2") print("3 2 1") print("2 3 1") continue a=list(range(1,n+1))[: :-1] print(" ".join(map(str,a))) for __ in range(n-1): a=a[-1 :]+a[:-1] print(" ".join(map(str,a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 3 then ( execute ("3 1 2")->display() ; execute ("3 2 1")->display() ; execute ("2 3 1")->display() ; continue ) else skip ; var a : OclAny := OclType["Sequence"](Integer.subrange(1, n + 1-1))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; execute (StringLib.sumStringsWithSeparator(((a)->collect( _x | (OclType["String"])->apply(_x) )), " "))->display() ; for __ : Integer.subrange(0, n - 1-1) do ( a := a.subrange(-1+1) + a->front() ; execute (StringLib.sumStringsWithSeparator(((a)->collect( _x | (OclType["String"])->apply(_x) )), " "))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def ri(): return[int(i)for i in input().split()] def rs()->str : return input()[:-1] def check(a)->bool : for i in range(len(a)-2): if a[i]+a[i+1]==a[i+2]: return False return True def main(): import itertools t=ri()[0] for _ in range(t): n=ri()[0] zero=reversed(list(range(1,n+1))) for p in itertools.permutations(zero): if check(p): print(*p) n-=1 if n==0 : break input=sys.stdin.readline main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; main(); operation ri() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation rs() : String pre: true post: true activity: return input()->front(); operation check(a : OclAny) : boolean pre: true post: true activity: for i : Integer.subrange(0, (a)->size() - 2-1) do ( if a[i+1] + a[i + 1+1] = a[i + 2+1] then ( return false ) else skip) ; return true; operation main() pre: true post: true activity: skip ; var t : OclAny := ri()->first() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := ri()->first() ; var zero : Sequence := ((Integer.subrange(1, n + 1-1)))->reverse() ; for p : itertools.permutations(zero) do ( if check(p) then ( execute ((argument * (test (logical_test (comparison (expr (atom (name p))))))))->display() ; n := n - 1 ) else skip ; if n = 0 then ( break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) ans=[i for i in range(n,0,-1)] if n % 2==0 : for i in range(n): print(*ans) if i!=n-1 : ans[i],ans[i+1]=ans[i+1],ans[i] else : for i in range(n-1): print(*ans) if i!=n-2 : ans[i+1],ans[i+2]=ans[i+2],ans[i+1] ans[0],ans[1]=ans[1],ans[0] print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Integer.subrange(0 + 1, n)->reverse()->select(i | true)->collect(i | (i)) ; if n mod 2 = 0 then ( for i : Integer.subrange(0, n-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ; if i /= n - 1 then ( var ans[i+1] : OclAny := null; var ans[i + 1+1] : OclAny := null; Sequence{ans[i+1],ans[i + 1+1]} := Sequence{ans[i + 1+1],ans[i+1]} ) else skip) ) else ( for i : Integer.subrange(0, n - 1-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ; if i /= n - 2 then ( var ans[i + 1+1] : OclAny := null; var ans[i + 2+1] : OclAny := null; Sequence{ans[i + 1+1],ans[i + 2+1]} := Sequence{ans[i + 2+1],ans[i + 1+1]} ) else skip) ; var ans->first() : OclAny := null; var ans[1+1] : OclAny := null; Sequence{ans->first(),ans[1+1]} := Sequence{ans[1+1],ans->first()} ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**7) def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return sys.stdin.readline().strip() INF=10**18 MOD=10**9+7 from functools import lru_cache def main(): S=SI() dp_table=[[0 for _ in range(13)]for _ in range(len(S))] if S[0]=='?' : for i in range(10): dp_table[0][i]=1 else : dp_table[0][int(S[0])]=1 for digit in range(1,len(S)): if S[digit]=='?' : for prev_res,comb in enumerate(dp_table[digit-1]): for x in range(10): res=(prev_res*10+x)% 13 dp_table[digit][res]=(dp_table[digit][res]+comb)% MOD else : for prev_res,comb in enumerate(dp_table[digit-1]): res=(prev_res*10+int(S[digit]))% 13 dp_table[digit][res]=(dp_table[digit][res]+comb)% MOD print(dp_table[len(S)-1][5]) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; skip ; skip ; skip ; skip ; skip ; var INF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; main(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation SI() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation main() pre: true post: true activity: var S : OclAny := SI() ; var dp_table : Sequence := Integer.subrange(0, (S)->size()-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, 13-1)->select(_anon | true)->collect(_anon | (0)))) ; if S->first() = '?' then ( for i : Integer.subrange(0, 10-1) do ( dp_table->first()[i+1] := 1) ) else ( dp_table->first()[("" + ((S->first())))->toInteger()+1] := 1 ) ; for digit : Integer.subrange(1, (S)->size()-1) do ( if S[digit+1] = '?' then ( for _tuple : Integer.subrange(1, (dp_table[digit - 1+1])->size())->collect( _indx | Sequence{_indx-1, (dp_table[digit - 1+1])->at(_indx)} ) do (var _indx : int := 1; var prev_res : OclAny := _tuple->at(_indx); _indx := _indx + 1; var comb : OclAny := _tuple->at(_indx); for x : Integer.subrange(0, 10-1) do ( var res : int := (prev_res * 10 + x) mod 13 ; dp_table[digit+1][res+1] := (dp_table[digit+1][res+1] + comb) mod MOD)) ) else ( for _tuple : Integer.subrange(1, (dp_table[digit - 1+1])->size())->collect( _indx | Sequence{_indx-1, (dp_table[digit - 1+1])->at(_indx)} ) do (var _indx : int := 1; var prev_res : OclAny := _tuple->at(_indx); _indx := _indx + 1; var comb : OclAny := _tuple->at(_indx); res := (prev_res * 10 + ("" + ((S[digit+1])))->toInteger()) mod 13 ; dp_table[digit+1][res+1] := (dp_table[digit+1][res+1] + comb) mod MOD) )) ; execute (dp_table[(S)->size() - 1+1][5+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import* from math import* from decimal import* from collections import* import sys def _input(): return map(int,input().split()) def _list(): return list(map(int,input().split())) def _int(): return int(input()) def solves(): n=int(input()) ans=[i for i in range(n,0,-1)] if n % 2==0 : for i in range(n): print(*ans) if i!=n-1 : ans[i],ans[i+1]=ans[i+1],ans[i] else : for i in range(n-1): print(*ans) if i!=n-2 : ans[i+1],ans[i+2]=ans[i+2],ans[i+1] ans[0],ans[1]=ans[1],ans[0] print(*ans) t=1 t=int(input()) for _ in range(0,t): solves() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var t : int := 1 ; t := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( solves()); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation _list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation _int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation solves() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Integer.subrange(0 + 1, n)->reverse()->select(i | true)->collect(i | (i)) ; if n mod 2 = 0 then ( for i : Integer.subrange(0, n-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ; if i /= n - 1 then ( var ans[i+1] : OclAny := null; var ans[i + 1+1] : OclAny := null; Sequence{ans[i+1],ans[i + 1+1]} := Sequence{ans[i + 1+1],ans[i+1]} ) else skip) ) else ( for i : Integer.subrange(0, n - 1-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ; if i /= n - 2 then ( var ans[i + 1+1] : OclAny := null; var ans[i + 2+1] : OclAny := null; Sequence{ans[i + 1+1],ans[i + 2+1]} := Sequence{ans[i + 2+1],ans[i + 1+1]} ) else skip) ; var ans->first() : OclAny := null; var ans[1+1] : OclAny := null; Sequence{ans->first(),ans[1+1]} := Sequence{ans[1+1],ans->first()} ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) result=[] for i in range(t): n=int(input()) if(n==3): result.append("3 2 1") result.append("3 1 2") result.append("1 3 2") else : array=[str(j)for j in range(n,0,-1)] result.append(" ".join(array)) for j in range(n-1): array.insert(0,array[n-1]) del(array[n]) result.append(" ".join(array)) for i in result : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var result : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n = 3) then ( execute (("3 2 1") : result) ; execute (("3 1 2") : result) ; execute (("1 3 2") : result) ) else ( var array : Sequence := Integer.subrange(0 + 1, n)->reverse()->select(j | true)->collect(j | (("" + ((j))))) ; execute ((StringLib.sumStringsWithSeparator((array), " ")) : result) ; for j : Integer.subrange(0, n - 1-1) do ( array := array.insertAt(0+1, array[n - 1+1]) ; execute ((array[n+1]))->isDeleted() ; execute ((StringLib.sumStringsWithSeparator((array), " ")) : result)) )) ; for i : result do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=map(int,input().split()) keepcost=10**10 for i in range(0,n): c,tt=map(int,input().split()) if tt<=t : if ccollect( _x | (OclType["int"])->apply(_x) ) ; var keepcost : double := (10)->pow(10) ; for i : Integer.subrange(0, n-1) do ( var c : OclAny := null; var tt : OclAny := null; Sequence{c,tt} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (tt->compareTo(t)) <= 0 then ( if (c->compareTo(keepcost)) < 0 then ( keepcost := c ) else skip ) else skip) ; execute (Sequence{keepcost}->union(Sequence{ "TLE" })->select(keepcost = (10)->pow(10)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**7) INTMAX=9223372036854775807 INTMIN=-9223372036854775808 DVSR=1000000007 def POW(x,y): return pow(x,y,DVSR) def INV(x,d=DVSR): return pow(x,d-2,d) def DIV(x,y,d=DVSR): return(x*INV(y,d))% d def LI(): return[int(x)for x in input().split()] def LF(): return[float(x)for x in input().split()] def LS(): return input().split() def II(): return int(input()) N,T=LI() INL=[LI()for i in range(N)] res=INTMAX for c,t in INL : if t<=T : res=min(res,c) if res==INTMAX : print('TLE') else : print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var INTMAX : int := 9223372036854775807 ; var INTMIN : int := -9223372036854775808 ; var DVSR : int := 1000000007 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var N : OclAny := null; var T : OclAny := null; Sequence{N,T} := LI() ; var INL : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (LI())) ; var res : int := INTMAX ; for _tuple : INL do (var _indx : int := 1; var c : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); if (t->compareTo(T)) <= 0 then ( res := Set{res, c}->min() ) else skip) ; if res = INTMAX then ( execute ('TLE')->display() ) else ( execute (res)->display() ); operation POW(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return (x)->pow(y); operation INV(x : OclAny, d : int) : OclAny pre: true post: true activity: if d->oclIsUndefined() then d := DVSR else skip; return (x)->pow(d - 2); operation DIV(x : OclAny, y : OclAny, d : int) : OclAny pre: true post: true activity: if d->oclIsUndefined() then d := DVSR else skip; return (x * INV(y, d)) mod d; operation LI() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LF() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return input().split(); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=lambda : map(int,input().split()); N,T=i(); print(min([c for c,t in eval('i(),'*N)if t<=T],default='TLE')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); var N : OclAny := null; var T : OclAny := null; Sequence{N,T} := i->apply(); execute (Set{StringLib.nCopies('i(),', N)->select(_tuple | let c : OclAny = _tuple->at(1) in let t : OclAny = _tuple->at(2) in (t->compareTo(T)) <= 0)->collect(_tuple | let c : OclAny = _tuple->at(1) in let t : OclAny = _tuple->at(2) in (c)), (argument (test (logical_test (comparison (expr (atom (name default)))))) = (test (logical_test (comparison (expr (atom 'TLE'))))))}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- li=input().split() n=int(li[0]) t=int(li[1]) maxt=1001 cost=1001 ans=1001 for i in range(0,n): li=input().split() x=int(li[0]) y=int(li[1]) if y<=t : if x<=cost : cost=x if cost==1001 : print("TLE") else : print(cost) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var li : OclAny := input().split() ; var n : int := ("" + ((li->first())))->toInteger() ; var t : int := ("" + ((li[1+1])))->toInteger() ; var maxt : int := 1001 ; var cost : int := 1001 ; var ans : int := 1001 ; for i : Integer.subrange(0, n-1) do ( li := input().split() ; var x : int := ("" + ((li->first())))->toInteger() ; var y : int := ("" + ((li[1+1])))->toInteger() ; if (y->compareTo(t)) <= 0 then ( if (x->compareTo(cost)) <= 0 then ( cost := x ) else skip ) else skip) ; if cost = 1001 then ( execute ("TLE")->display() ) else ( execute (cost)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for p in range(int(input())): n,k=map(int,input().split()) a=list(map(int,input().split())) x,f=0,0 for c in range(k): i=1 while(i-1): print(x+1) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for p : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := null; var f : OclAny := null; Sequence{x,f} := Sequence{0,0} ; for c : Integer.subrange(0, k-1) do ( var i : int := 1 ; while ((i->compareTo(n)) < 0 & (a[i+1]->compareTo(a[i - 1+1])) <= 0) do ( i := i + 1) ; if (i = n) then ( var x : int := -1 ; break ) else ( x := i - 1 ; a[i - 1+1] := a[i - 1+1] + 1 )) ; if (x > -1) then ( execute (x + 1)->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=map(int,input().split()) c=[list(map(int,input().split()))for i in range(n)] mincost=10000 for i in range(n): if c[i][1]<=t : cost=c[i][0] mincost=min(cost,mincost) if mincost==10000 : print("TLE") else : print(mincost) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var mincost : int := 10000 ; for i : Integer.subrange(0, n-1) do ( if (c[i+1][1+1]->compareTo(t)) <= 0 then ( var cost : OclAny := c[i+1]->first() ; mincost := Set{cost, mincost}->min() ) else skip) ; if mincost = 10000 then ( execute ("TLE")->display() ) else ( execute (mincost)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def fizzBuzz(self,n): return[str(i)*(i % 3!=0 and i % 5!=0)+"Fizz"*(i % 3==0)+"Buzz"*(i % 5==0)for i in range(1,n+1)] ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation fizzBuzz(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | (("" + ((i))) * (i mod 3 /= 0 & i mod 5 /= 0) + StringLib.nCopies("Fizz", (i mod 3 = 0)) + StringLib.nCopies("Buzz", (i mod 5 = 0)))); } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=[] z=int(input('')) s=list(map(int,input().split())) for _ in range(z): k=list(map(int,input().split())) t=5*sum(k)+15*(s[_]) l.append(t) print(min(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := Sequence{} ; var z : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for _anon : Integer.subrange(0, z-1) do ( var k : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : double := 5 * (k)->sum() + 15 * (s[_anon+1]) ; execute ((t) : l)) ; execute ((l)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from collections import defaultdict sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod=10**9+7 def I(): return int(input()) def II(): return map(int,input().split()) def III(): return list(map(int,input().split())) def Line(N): read_all=[tuple(map(int,input().split()))for _ in range(N)] return map(list,zip(*read_all)) S=str(input()) n=len(S) if n==1 : if S=='5' or S=='?' : print(1) else : print(0) exit() dp=[[0]*13 for i in range(n)] for i in range(n): if i==0 : if S[i]!='?' : dp[i][int(S[i])]+=1 else : for j in range(10): dp[i][j]+=1 else : if S[i]!='?' : for k in range(13): dp[i][(k*10+int(S[i]))% 13]+=dp[i-1][k] else : for j in range(10): for k in range(13): dp[i][(k*10+j)% 13]+=dp[i-1][k] for k in range(13): dp[i][k]%=mod print(dp[n-1][5]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; var S : String := ("" + (((OclFile["System.in"]).readLine()))) ; var n : int := (S)->size() ; if n = 1 then ( if S = '5' or S = '?' then ( execute (1)->display() ) else ( execute (0)->display() ) ; exit() ) else skip ; var dp : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, 13))) ; for i : Integer.subrange(0, n-1) do ( if i = 0 then ( if S[i+1] /= '?' then ( dp[i+1][("" + ((S[i+1])))->toInteger()+1] := dp[i+1][("" + ((S[i+1])))->toInteger()+1] + 1 ) else ( for j : Integer.subrange(0, 10-1) do ( dp[i+1][j+1] := dp[i+1][j+1] + 1) ) ) else ( if S[i+1] /= '?' then ( for k : Integer.subrange(0, 13-1) do ( dp[i+1][(k * 10 + ("" + ((S[i+1])))->toInteger()) mod 13+1] := dp[i+1][(k * 10 + ("" + ((S[i+1])))->toInteger()) mod 13+1] + dp[i - 1+1][k+1]) ) else ( for j : Integer.subrange(0, 10-1) do ( for k : Integer.subrange(0, 13-1) do ( dp[i+1][(k * 10 + j) mod 13+1] := dp[i+1][(k * 10 + j) mod 13+1] + dp[i - 1+1][k+1])) ) ; for k : Integer.subrange(0, 13-1) do ( dp[i+1][k+1] := dp[i+1][k+1] mod mod) )) ; execute (dp[n - 1+1][5+1])->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation II() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation III() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation Line(N : OclAny) : OclAny pre: true post: true activity: var read_all : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; return (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name read_all)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name read_all)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name read_all)))))))`third->at(_indx)} ))->collect( _x | (OclType["Sequence"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=lambda :[*map(int,input().split())] n=i()[0] k=i() print(min(k[l]*15+sum(i())*5 for l in range(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := i->apply()->first() ; var k : OclAny := i->apply() ; execute (((argument (test (logical_test (comparison (expr (expr (expr (atom (name k)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name l)))))))) ]))) * (expr (atom (number (integer 15))))) + (expr (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)) (trailer (arguments ( ))))))))) )))) * (expr (atom (number (integer 5))))))))) (comp_for for (exprlist (expr (atom (name l)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lines=list(map(int,input().split())) num_items=[] for x in range(n): num_items.append(list(map(int,input().split()))) index=0 min_time=9999999999 while indextoInteger() ; var lines : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var num_items : Sequence := Sequence{} ; for x : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : num_items)) ; var index : int := 0 ; var min_time : int := 9999999999 ; while (index->compareTo(n)) < 0 do ( var total_time : double := 5 * ((num_items[index+1])->sum()) ; total_time := total_time + 15 * (lines[index+1]) ; if (total_time->compareTo(min_time)) < 0 then ( min_time := total_time ) else skip ; index := index + 1) ; execute (min_time)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lines=list(map(int,input().split())) num_items=[] for x in range(n): num_items.append(list(map(int,input().split()))) min_time=9999999999 for index in range(n): total_time=5*(sum(num_items[index])) total_time+=15*(lines[index]) if total_timetoInteger() ; var lines : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var num_items : Sequence := Sequence{} ; for x : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : num_items)) ; var min_time : int := 9999999999 ; for index : Integer.subrange(0, n-1) do ( var total_time : double := 5 * ((num_items[index+1])->sum()) ; total_time := total_time + 15 * (lines[index+1]) ; if (total_time->compareTo(min_time)) < 0 then ( min_time := total_time ) else skip) ; execute (min_time)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) k=[int(x)for x in input().split()] low=float('inf') for i in range(n): items=[int(x)for x in input().split()] time=0 for item in items : time+=(item*5)+15 low=min(low,time) print(low) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var low : double := ("" + (('inf')))->toReal() ; for i : Integer.subrange(0, n-1) do ( var items : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var time : int := 0 ; for item : items do ( time := time + (item * 5) + 15) ; low := Set{low, time}->min()) ; execute (low)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(st): n=len(st) if(n==0): return False if(n==1): return((int)(st[0])% 8==0) if(n==2): return((int)(st[n-2])*10+((int)(str[n-1])% 8==0)) last=(int)(st[n-1]) second_last=(int)(st[n-2]) third_last=(int)(st[n-3]) return((third_last*100+second_last*10+last)% 8==0) st="76952" if(check(st)): print("Yes") else : print("No ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; st := "76952" ; if (check(st)) then ( execute ("Yes")->display() ) else ( execute ("No ")->display() ); operation check(st : OclAny) : OclAny pre: true post: true activity: var n : int := (st)->size() ; if (n = 0) then ( return false ) else skip ; if (n = 1) then ( return ((OclType["int"])(st->first()) mod 8 = 0) ) else skip ; if (n = 2) then ( return ((OclType["int"])(st[n - 2+1]) * 10 + ((OclType["int"])(("" + ([n - 1+1]))) mod 8 = 0)) ) else skip ; var last : OclAny := (OclType["int"])(st[n - 1+1]) ; var second_last : OclAny := (OclType["int"])(st[n - 2+1]) ; var third_last : OclAny := (OclType["int"])(st[n - 3+1]) ; return ((third_last * 100 + second_last * 10 + last) mod 8 = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(st): n=len(st) if(n==0): return False if(n==1): return((st[0]-'0')% 4==0) last=(int)(st[n-1]) second_last=(int)(st[n-2]) return((second_last*10+last)% 4==0) st="76952" if(check(st)): print("Yes") else : print("No ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; st := "76952" ; if (check(st)) then ( execute ("Yes")->display() ) else ( execute ("No ")->display() ); operation check(st : OclAny) : OclAny pre: true post: true activity: var n : int := (st)->size() ; if (n = 0) then ( return false ) else skip ; if (n = 1) then ( return ((st->first() - '0') mod 4 = 0) ) else skip ; var last : OclAny := (OclType["int"])(st[n - 1+1]) ; var second_last : OclAny := (OclType["int"])(st[n - 2+1]) ; return ((second_last * 10 + last) mod 4 = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import pow def precompute(arr,n,pre): pre[n-1]=arr[n-1]*pow(2,0) i=n-2 while(i>=0): pre[i]=(pre[i+1]+arr[i]*(1<<(n-1-i))) i-=1 def decimalOfSubarr(arr,l,r,n,pre): if(r!=n-1): return((pre[l]-pre[r+1])/(1<<(n-1-r))) return pre[l]/(1<<(n-1-r)) if __name__=='__main__' : arr=[1,0,1,0,1,1] n=len(arr) pre=[0 for i in range(n)] precompute(arr,n,pre) print(int(decimalOfSubarr(arr,2,4,n,pre))) print(int(decimalOfSubarr(arr,4,5,n,pre))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 1 }))))) ; n := (arr)->size() ; pre := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; precompute(arr, n, pre) ; execute (("" + ((decimalOfSubarr(arr, 2, 4, n, pre))))->toInteger())->display() ; execute (("" + ((decimalOfSubarr(arr, 4, 5, n, pre))))->toInteger())->display() ) else skip; operation precompute(arr : OclAny, n : OclAny, pre : OclAny) pre: true post: true activity: pre[n - 1+1] := arr[n - 1+1] * (2)->pow(0) ; var i : double := n - 2 ; while (i >= 0) do ( pre[i+1] := (pre[i + 1+1] + arr[i+1] * (1 * (2->pow((n - 1 - i))))) ; i := i - 1); operation decimalOfSubarr(arr : OclAny, l : OclAny, r : OclAny, n : OclAny, pre : OclAny) : OclAny pre: true post: true activity: if (r /= n - 1) then ( return ((pre[l+1] - pre[r + 1+1]) / (1 * (2->pow((n - 1 - r))))) ) else skip ; return pre[l+1] / (1 * (2->pow((n - 1 - r)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Solve(): for t in range(int(input())): n,k=map(int,input().split()) h=list(map(int,input().split())) e=True for i in range(k): for o in range(n-1): if h[o]toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var e : boolean := true ; for i : Integer.subrange(0, k-1) do ((compound_stmt for (exprlist (expr (atom (name o)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name h)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name o)))))))) ])))) < (comparison (expr (atom (name h)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name o))) + (expr (atom (number (integer 1)))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name h)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name o)))))))) ])))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name e)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name False)))))))))))) (stmt (simple_stmt (small_stmt break))))))) ; if e then ( execute (o + 1)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solution(): n=int(input()) sks=list(map(int,input().split())) check=[0]*(n+1) check[sks[0]]+=1 s=1 maxi=1 for i in range(1,len(sks)): if s==0 : check[sks[i]]+=1 s+=1 elif check[sks[i]]==0 : check[sks[i]]+=1 s+=1 if s>maxi : maxi=s elif check[sks[i]]>0 : check[sks[i]]-=1 s-=1 if s>maxi : maxi=s print(maxi) t=1 while t : t-=1 solution() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := 1 ; while t do ( t := t - 1 ; solution()); operation solution() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sks : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var check : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; check[sks->first()+1] := check[sks->first()+1] + 1 ; var s : int := 1 ; var maxi : int := 1 ; for i : Integer.subrange(1, (sks)->size()-1) do ( if s = 0 then ( check[sks[i+1]+1] := check[sks[i+1]+1] + 1 ; s := s + 1 ) else (if check[sks[i+1]+1] = 0 then ( check[sks[i+1]+1] := check[sks[i+1]+1] + 1 ; s := s + 1 ; if (s->compareTo(maxi)) > 0 then ( maxi := s ) else skip ) else (if check[sks[i+1]+1] > 0 then ( check[sks[i+1]+1] := check[sks[i+1]+1] - 1 ; s := s - 1 ; if (s->compareTo(maxi)) > 0 then ( maxi := s ) else skip ) else skip ) ) ) ; execute (maxi)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=list(map(int,input().split())) t=[] for i in range(n): t.append(0) c=0 p=0 for i in x : if t[i-1]!=1 : t[i-1]=1 c+=1 else : if(c>p): p=c c-=1 print(p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((0) : t)) ; var c : int := 0 ; var p : int := 0 ; for i : x do ( if t[i - 1+1] /= 1 then ( t[i - 1+1] := 1 ; c := c + 1 ) else ( if ((c->compareTo(p)) > 0) then ( p := c ) else skip ; c := c - 1 )) ; execute (p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline ii=lambda : int(input()) mi=lambda : map(int,input().split()) li=lambda : list(map(int,input().split())) from collections import defaultdict d,t,a,b,da,db=mi() def solve(): for i in range(t): for j in range(t): if a-da*i+b-db*j==d or a-da*i==d or b-db*j==d or d==0 : print('YES') return print('NO') solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var ii : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var mi : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var li : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; skip ; var d : OclAny := null; var t : OclAny := null; var a : OclAny := null; var b : OclAny := null; var da : OclAny := null; var db : OclAny := null; Sequence{d,t,a,b,da,db} := mi->apply() ; skip ; solve(); operation solve() pre: true post: true activity: for i : Integer.subrange(0, t-1) do ( for j : Integer.subrange(0, t-1) do ( if a - da * i + b - db * j = d or a - da * i = d or b - db * j = d or d = 0 then ( execute ('YES')->display() ; return ) else skip)) ; execute ('NO')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input(); a=set(); r=0 for x in input().split(): a ^={x}; r=max(r,len(a)) print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input(); var a : Set := Set{}->union(()); var r : int := 0 ; for x : input().split() do ( a := a xor Set{ x }; r := Set{r, (a)->size()}->max()) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return[int(x)for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return input() def main(): n=I() l=LI() d={} ans=0 tmp_ans=0 for x in l : if x in d : tmp_ans-=1 d.pop(x) else : tmp_ans+=1 ans=max(ans,tmp_ans) d[x]=x return ans print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var mod : double := (10)->pow(9) + 7 ; var dd : Sequence := Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{ Sequence{0, -1} }))) ; var ddn : Sequence := Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{-1, 1}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{1, 1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{1, -1}}->union(Sequence{Sequence{0, -1}}->union(Sequence{ Sequence{-1, -1} }))))))) ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation main() : OclAny pre: true post: true activity: var n : OclAny := I() ; var l : OclAny := LI() ; var d : OclAny := Set{} ; var ans : int := 0 ; var tmp_ans : int := 0 ; for x : l do ( if (d)->includes(x) then ( tmp_ans := tmp_ans - 1 ; d := d->excludingAt(x+1) ) else ( tmp_ans := tmp_ans + 1 ; ans := Set{ans, tmp_ans}->max() ; d[x+1] := x )) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=[int(x)for x in input().split()] queue={} maximum=0 for i in range(0,n*2): if s[i]in queue.keys(): del queue[s[i]] else : queue[s[i]]=1 if len(queue)>=maximum : maximum=len(queue) print(maximum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var queue : OclAny := Set{} ; var maximum : int := 0 ; for i : Integer.subrange(0, n * 2-1) do ( if (queue.keys())->includes(s[i+1]) then ( execute (queue[s[i+1]+1])->isDeleted() ) else ( queue[s[i+1]+1] := 1 ) ; if ((queue)->size()->compareTo(maximum)) >= 0 then ( maximum := (queue)->size() ) else skip) ; execute (maximum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d=int(input()) n=int(input()) l=input().split(' ') times=0 for i in range(0,n-1): times+=d-int(l[i]) print(times) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : OclAny := input().split(' ') ; var times : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( times := times + d - ("" + ((l[i+1])))->toInteger()) ; execute (times)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d=int(input()) n=int(input()) l=input().split(' ') times=0 for i in range(0,n-1): times+=d-int(l[i]) print(times) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : OclAny := input().split(' ') ; var times : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( times := times + d - ("" + ((l[i+1])))->toInteger()) ; execute (times)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d=int(input()) n=int(input()) l=input().split(' ') times=0 for i in range(0,n-1): times+=d-int(l[i]) print(times) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : OclAny := input().split(' ') ; var times : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( times := times + d - ("" + ((l[i+1])))->toInteger()) ; execute (times)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d=int(input()) n=int(input()) l=input().split(' ') times=0 for i in range(0,n-1): times+=d-int(l[i]) print(times) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : OclAny := input().split(' ') ; var times : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( times := times + d - ("" + ((l[i+1])))->toInteger()) ; execute (times)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d=int(input()) n=int(input()) l=input().split(' ') times=0 for i in range(0,n-1): times+=d-int(l[i]) print(times) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : OclAny := input().split(' ') ; var times : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( times := times + d - ("" + ((l[i+1])))->toInteger()) ; execute (times)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(hills,k): last=0 if len(hills)==1 : return-1 while k>0 : prev=k for i in range(len(hills)-1): if hills[i]0 and hills[i]<=hills[i-1]: diff=min(diff,hills[i-1]-hills[i]+1) k-=diff hills[i]+=diff last=i break if prev==k : break if k==0 : return last+1 return-1 def main(): t=int(input()) for _ in range(t): n,k=map(int,input().split()) hills=list(map(int,input().split())) print(solve(hills,k)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation solve(hills : OclAny, k : OclAny) : OclAny pre: true post: true activity: var last : int := 0 ; if (hills)->size() = 1 then ( return -1 ) else skip ; while k > 0 do ( var prev : OclAny := k ; for i : Integer.subrange(0, (hills)->size() - 1-1) do ( if (hills[i+1]->compareTo(hills[i + 1+1])) < 0 then ( var diff : OclAny := Set{hills[i + 1+1] - hills[i+1], k}->min() ; if i > 0 & (hills[i+1]->compareTo(hills[i - 1+1])) <= 0 then ( diff := Set{diff, hills[i - 1+1] - hills[i+1] + 1}->min() ) else skip ; k := k - diff ; hills[i+1] := hills[i+1] + diff ; last := i ; break ) else skip) ; if prev = k then ( break ) else skip) ; if k = 0 then ( return last + 1 ) else skip ; return -1; operation main() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; hills := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (solve(hills, k))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import heapq import sys import math import itertools import bisect import os def values(): return tuple(map(int,sys.stdin.readline().split())) def inp(): return int(sys.stdin.readline()) def inpstr(): return sys.stdin.readline().strip() def words(): return sys.stdin.readline().split() def chars(): return list(sys.stdin.readline().strip()) def check_sym(mat,end): if end & 1 : return False for i in range(end//2): if mat[end//2-1-i]!=mat[end//2+i]: return False return True def solve(): n,m=values() mat=[] for i in range(n): row=values() r=0 for j in range(m): r |=row[j]<collect( _x | (OclType["int"])->apply(_x) )); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inpstr() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation words() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation chars() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim()); operation check_sym(mat : OclAny, end : OclAny) : OclAny pre: true post: true activity: if MathLib.bitwiseAnd(end, 1) then ( return false ) else skip ; for i : Integer.subrange(0, end div 2-1) do ( if mat[end div 2 - 1 - i+1] /= mat[end div 2 + i+1] then ( return false ) else skip) ; return true; operation solve() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := values() ; mat := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var row : OclAny := values() ; var r : int := 0 ; for j : Integer.subrange(0, m-1) do ( r := r or row[j+1] * (2->pow(j))) ; execute ((r) : mat)) ; end := n ; while check_sym(mat, end) do ( end := end div 2) ; execute (end)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,t,a,b,da,db=map(int,input().split()) ans='NO' if x==0 : ans='YES' for i in range(t): for j in range(t): y=(a-i*da)+(b-j*db) if y==x : ans='YES' y=(a-i*da) if y==x : ans='YES' y=(b-j*db) if y==x : ans='YES' print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var t : OclAny := null; var a : OclAny := null; var b : OclAny := null; var da : OclAny := null; var db : OclAny := null; Sequence{x,t,a,b,da,db} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : String := 'NO' ; if x = 0 then ( ans := 'YES' ) else skip ; for i : Integer.subrange(0, t-1) do ( for j : Integer.subrange(0, t-1) do ( var y : double := (a - i * da) + (b - j * db) ; if y = x then ( ans := 'YES' ) else skip ; y := (a - i * da) ; if y = x then ( ans := 'YES' ) else skip ; y := (b - j * db) ; if y = x then ( ans := 'YES' ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def issymmetric(n,mat): if n % 2 : return False else : return mat[: n//2]==mat[n//2 :][: :-1] n,m=map(int,input().split()) mat=[] for i in range(n): mat.append(list(map(int,input().split()))) while issymmetric(n,mat): mat=mat[: n//2] n//=2 print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; mat := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : mat)) ; while issymmetric(n, mat) do ( mat := mat.subrange(1,n div 2) ; n := n div 2) ; execute (n)->display(); operation issymmetric(n : OclAny, mat : OclAny) : OclAny pre: true post: true activity: if n mod 2 then ( return false ) else ( return mat.subrange(1,n div 2) = mat.subrange(n div 2+1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) l=[] for i in range(n): l.append(list(input())) if n % 2!=0 : print(n) else : start=n mid=n//2 while start!=1 : if l[0 : mid][: :-1]==l[mid : start]: start//=2 mid=start//2 else : break print(start) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((((OclFile["System.in"]).readLine())->characters()) : l)) ; if n mod 2 /= 0 then ( execute (n)->display() ) else ( var start : OclAny := n ; var mid : int := n div 2 ; while start /= 1 do ( if l.subrange(0+1, mid)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) = l.subrange(mid+1, start) then ( start := start div 2 ; mid := start div 2 ) else ( break )) ; execute (start)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def valid(n,arr): if n!=int(n): return len(arr) n=int(n) for i in range(0,n): if arr[i]==arr[2*n-1-i]: continue else : return len(arr) if n==0 : return 0 curr_ans=n return min(curr_ans,valid(n/2,arr)) def main(arr): return valid(len(arr)/2,arr) n,m=list(map(int,input().split())) arr=[] for i in range(n): arr.append(list(map(int,input().split()))) print(main(arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : arr)) ; execute (main(arr))->display(); operation valid(n : OclAny, arr : OclAny) : OclAny pre: true post: true activity: if n /= ("" + ((n)))->toInteger() then ( return (arr)->size() ) else skip ; n := ("" + ((n)))->toInteger() ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] = arr[2 * n - 1 - i+1] then ( continue ) else ( return (arr)->size() )) ; if n = 0 then ( return 0 ) else skip ; var curr_ans : OclAny := n ; return Set{curr_ans, valid(n / 2, arr)}->min(); operation main(arr : OclAny) : OclAny pre: true post: true activity: return valid((arr)->size() / 2, arr); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) arr=[input()for i in range(n)] while n % 2==0 and arr[: n]==list(reversed(arr[: n])): n//=2 print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; while n mod 2 = 0 & arr.subrange(1,n) = ((arr.subrange(1,n))->reverse()) do ( n := n div 2) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter as cnt l=[] for p in range(int(input())): s=str(input()) l.append(s) c=cnt(l) m=float("-inf") for i in c : m=max(m,c[i]) print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var l : Sequence := Sequence{} ; for p : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; execute ((s) : l)) ; var c : OclAny := cnt(l) ; var m : double := ("" + (("-inf")))->toReal() ; for i : c do ( m := Set{m, c[i+1]}->max()) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=[] for _ in range(n): arr.append(str(input())) maxx=1 for i in range(n): x=0 for j in range(n): if arr[i]==arr[j]: x+=1 maxx=max(maxx,x) print(maxx) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))) : arr)) ; var maxx : int := 1 ; for i : Integer.subrange(0, n-1) do ( var x : int := 0 ; for j : Integer.subrange(0, n-1) do ( if arr[i+1] = arr[j+1] then ( x := x + 1 ) else skip) ; maxx := Set{maxx, x}->max()) ; execute (maxx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n=int(input()) arr=[] for i in range(n): arr.append([int(i)for i in input()]) res=[] for i in range(n): t='' for j in range(n): if arr[i][j]==0 : t+=str(j)+' ' res.append(t) c=Counter(res) mx=0 for item in c : mx=max(mx,c[item]) print(mx) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))) : arr)) ; var res : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var t : String := '' ; for j : Integer.subrange(0, n-1) do ( if arr[i+1][j+1] = 0 then ( t := t + ("" + ((j))) + ' ' ) else skip) ; execute ((t) : res)) ; var c : OclAny := Counter(res) ; var mx : int := 0 ; for item : c do ( mx := Set{mx, c[item+1]}->max()) ; execute (mx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) mtr=[] cont=[] for i in range(n): mtr.append(input()) for i in range(len(mtr)): aux=0 for j in range(i,len(mtr)): if mtr[i]==mtr[j]: aux+=1 cont.append(aux) print(max(cont)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mtr : Sequence := Sequence{} ; var cont : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : mtr)) ; for i : Integer.subrange(0, (mtr)->size()-1) do ( var aux : int := 0 ; for j : Integer.subrange(i, (mtr)->size()-1) do ( if mtr[i+1] = mtr[j+1] then ( aux := aux + 1 ) else skip) ; execute ((aux) : cont)) ; execute ((cont)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from collections import Counter n=int(input()) g=Counter([input()[:-1]for _ in range(n)]) print(max(g.values())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var g : OclAny := Counter(Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (input()->front()))) ; execute ((g.values())->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict N,A=map(int,input().split()) Xn=list(map(int,input().split())) dp=defaultdict(lambda : 0) for i in range(N): x=Xn[i]-A keys=list(dp.items()) if x>0 : keys=sorted(keys,reverse=True) else : keys=sorted(keys) for k,t in keys : dp[k+x]+=dp[k] dp[x]+=1 print(dp[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var A : OclAny := null; Sequence{N,A} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var Xn : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dp : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; for i : Integer.subrange(0, N-1) do ( var x : double := Xn[i+1] - A ; var keys : Sequence := (dp->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})) ; if x > 0 then ( keys := keys->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ) else ( keys := keys->sort() ) ; for _tuple : keys do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); dp[k + x+1] := dp[k + x+1] + dp[k+1]) ; dp[x+1] := dp[x+1] + 1) ; execute (dp->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- xxs=input().split(" ") x,t,a,b,da,db=int(xxs[0]),int(xxs[1]),int(xxs[2]),int(xxs[3]),int(xxs[4]),int(xxs[5]) def main(): if x==0 : print("YES") return "Result Found" a_time=min([a//da,t-1]) b_time=min([b//db,t-1]) for i in range(a_time+1): for j in range(b_time+1): if a-da*i==x or b-db*j==x : print("YES") return "Result Found" if(a-da*i)+(b-db*j)==x : print("YES") return "Result Found" return "Result Not Found" ff=main() if ff=="Result Not Found" : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var xxs : OclAny := input().split(" ") ; var x : OclAny := null; var t : OclAny := null; var a : OclAny := null; var b : OclAny := null; var da : OclAny := null; var db : OclAny := null; Sequence{x,t,a,b,da,db} := Sequence{("" + ((xxs->first())))->toInteger(),("" + ((xxs[1+1])))->toInteger(),("" + ((xxs[2+1])))->toInteger(),("" + ((xxs[3+1])))->toInteger(),("" + ((xxs[4+1])))->toInteger(),("" + ((xxs[5+1])))->toInteger()} ; skip ; var ff : OclAny := main() ; if ff = "Result Not Found" then ( execute ("NO")->display() ) else skip; operation main() : OclAny pre: true post: true activity: if x = 0 then ( execute ("YES")->display() ; return "Result Found" ) else skip ; var a_time : OclAny := (Sequence{a div da}->union(Sequence{ t - 1 }))->min() ; var b_time : OclAny := (Sequence{b div db}->union(Sequence{ t - 1 }))->min() ; for i : Integer.subrange(0, a_time + 1-1) do ( for j : Integer.subrange(0, b_time + 1-1) do ( if a - da * i = x or b - db * j = x then ( execute ("YES")->display() ; return "Result Found" ) else skip ; if (a - da * i) + (b - db * j) = x then ( execute ("YES")->display() ; return "Result Found" ) else skip)) ; return "Result Not Found"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys for m in range(int(input())): n,k=map(int,input().split()) arr=list(map(int,input().split())) i=0 cnt=0 while(iarr[i]): arr[i]+=1 cnt+=1 if(cnt==k): print(i+1) break i=0 else : i+=1 if(cnt!=k): print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for m : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var i : int := 0 ; var cnt : int := 0 ; while ((i->compareTo(n - 1)) < 0) do ( if ((arr[i + 1+1]->compareTo(arr[i+1])) > 0) then ( arr[i+1] := arr[i+1] + 1 ; cnt := cnt + 1 ; if (cnt = k) then ( execute (i + 1)->display() ; break ) else skip ; i := 0 ) else ( i := i + 1 )) ; if (cnt /= k) then ( execute (-1)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil,floor,sqrt def findRemainders(n): vc=dict() for i in range(1,ceil(sqrt(n))+1): vc[n//i]=1 for i in range(n//ceil(sqrt(n))-1,-1,-1): vc[i]=1 for it in sorted(vc): print(it,end=" ") n=5 findRemainders(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 5 ; findRemainders(n); operation findRemainders(n : OclAny) pre: true post: true activity: var vc : Map := (arguments ( )) ; for i : Integer.subrange(1, ceil(sqrt(n)) + 1-1) do ( vc[n div i+1] := 1) ; for i : Integer.subrange(-1 + 1, n div ceil(sqrt(n)) - 1)->reverse() do ( vc[i+1] := 1) ; for it : vc->keys()->sort() do ( execute (it)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cost(st): l=len(st) res=0 j=l-1 i=0 while(idisplay(); operation cost(st : OclAny) : OclAny pre: true post: true activity: var l : int := (st)->size() ; var res : int := 0 ; var j : double := l - 1 ; var i : int := 0 ; while ((i->compareTo(j)) < 0) do ( if (st[i+1] /= st[j+1]) then ( res := res + (Set{(st[i+1])->char2byte(), (st[j+1])->char2byte()}->min() - ('a')->char2byte() + 1) ) else skip ; i := i + 1 ; j := j - 1) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def findX(list,int): list.sort() x=list[0]*list[int-1]; vec=[] i=2 while(i*i<=x): if(n % i==0): vec.append(i) if((int//i)!=i): vec.append(int//i) i+=1 if(len(vec)==int): j=0 for it in range(int): if(a[j]!=it): return-1 else : j+=1 return x a=[2,5,4,10] n=len(a) print(findX(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var a : Sequence := Sequence{2}->union(Sequence{5}->union(Sequence{4}->union(Sequence{ 10 }))) ; var n : int := (a)->size() ; execute (findX(a, n))->display(); operation findX(list : OclAny, OclType["int"] : OclAny) : OclAny pre: true post: true activity: OclType["Sequence"] := OclType["Sequence"]->sort() ; var x : Sequence := MatrixLib.dotProduct(->first(),[OclType["int"] - 1+1]); ; var vec : Sequence := Sequence{} ; var i : int := 2 ; while ((i * i->compareTo(x)) <= 0) do ( if (n mod i = 0) then ( execute ((i) : vec) ; if ((OclType["int"] div i) /= i) then ( execute ((OclType["int"] div i) : vec) ) else skip ) else skip ; i := i + 1) ; if ((vec)->size() = OclType["int"]) then ( var j : int := 0 ; for it : Integer.subrange(0, OclType["int"]-1) do ( if (a[j+1] /= it) then ( return -1 ) else ( j := j + 1 )) ) else skip ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def No_Of_Pairs(N): i=1 ; while((i*i*i)+(2*i*i)+i<=N): i+=1 ; return(i-1); def print_pairs(pairs): i=1 ; mul=0 ; for i in range(1,pairs+1): mul=i*(i+1); print("Pair no.",i,"-->(",(mul*i),",",mul*(i+1),")"); N=500 ; i=1 ; pairs=No_Of_Pairs(N); print("No.of pairs=",pairs); print_pairs(pairs); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; N := 500; ; i := 1; ; pairs := No_Of_Pairs(N); ; execute ("No.of pairs=")->display(); ; print_pairs(pairs);; operation No_Of_Pairs(N : OclAny) pre: true post: true activity: var i : int := 1; ; while (((i * i * i) + (2 * i * i) + i->compareTo(N)) <= 0) do ( i := i + 1;) ; return (i - 1);; operation print_pairs(pairs : OclAny) pre: true post: true activity: i := 1; ; var mul : int := 0; ; for i : Integer.subrange(1, pairs + 1-1) do ( mul := i * (i + 1); ; execute ("Pair no.")->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getNumber(s): number_of_digits=len(s); freq=[0]*10 ; for i in range(number_of_digits): if(s[i]=='1' or s[i]=='2' or s[i]=='3' or s[i]=='5' or s[i]=='7'): freq[ord(s[i])-48]+=1 ; if(s[i]=='4'): freq[2]+=2 ; freq[3]+=1 ; if(s[i]=='6'): freq[5]+=1 ; freq[3]+=1 ; if(s[i]=='8'): freq[7]+=1 ; freq[2]+=3 ; if(s[i]=='9'): freq[7]+=1 ; freq[3]+=2 ; freq[2]+=1 ; t="" ; if(freq[1]==number_of_digits or freq[0]==number_of_digits or(freq[0]+freq[1])==number_of_digits): return s ; else : for i in range(9,1,-1): ctr=freq[i]; while(ctr>0): t+=chr(i+48); ctr-=1 ; return t ; s="1280" ; print(getNumber(s)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := "1280"; ; execute (getNumber(s))->display();; operation getNumber(s : OclAny) pre: true post: true activity: var number_of_digits : int := (s)->size(); ; var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10); ; for i : Integer.subrange(0, number_of_digits-1) do ( if (s[i+1] = '1' or s[i+1] = '2' or s[i+1] = '3' or s[i+1] = '5' or s[i+1] = '7') then ( freq[(s[i+1])->char2byte() - 48+1] := freq[(s[i+1])->char2byte() - 48+1] + 1; ) else skip ; if (s[i+1] = '4') then ( freq[2+1] := freq[2+1] + 2; ; freq[3+1] := freq[3+1] + 1; ) else skip ; if (s[i+1] = '6') then ( freq[5+1] := freq[5+1] + 1; ; freq[3+1] := freq[3+1] + 1; ) else skip ; if (s[i+1] = '8') then ( freq[7+1] := freq[7+1] + 1; ; freq[2+1] := freq[2+1] + 3; ) else skip ; if (s[i+1] = '9') then ( freq[7+1] := freq[7+1] + 1; ; freq[3+1] := freq[3+1] + 2; ; freq[2+1] := freq[2+1] + 1; ) else skip) ; var t : String := ""; ; if (freq[1+1] = number_of_digits or freq->first() = number_of_digits or (freq->first() + freq[1+1]) = number_of_digits) then ( return s; ) else ( for i : Integer.subrange(1 + 1, 9)->reverse() do ( var ctr : OclAny := freq[i+1]; ; while (ctr > 0) do ( t := t + (i + 48)->byte2char(); ; ctr := ctr - 1;)) ; return t; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def makePalindrome(n,odd): res=n ; if(odd): n=int(n/10); while(n>0): res=10*res+n % 10 ; n=int(n/10); return res ; def isPalindrome(n,base): reversed=0 ; temp=n ; while(temp>0): reversed=reversed*base+temp % base ; temp=int(temp/base); return reversed==n ; def sumPalindrome(n,k): sum=0 ; i=1 ; p=makePalindrome(i,True); while(p; operation makePalindrome(n : OclAny, odd : OclAny) pre: true post: true activity: var res : OclAny := n; ; if (odd) then ( n := ("" + ((n / 10)))->toInteger(); ) else skip ; while (n > 0) do ( res := 10 * res + n mod 10; ; n := ("" + ((n / 10)))->toInteger();) ; return res;; operation isPalindrome(n : OclAny, base : OclAny) pre: true post: true activity: var reversed : int := 0; ; var temp : OclAny := n; ; while (temp > 0) do ( reversed := reversed * base + temp mod base; ; temp := ("" + ((temp / base)))->toInteger();) ; return reversed = n;; operation sumPalindrome(n : OclAny, k : OclAny) pre: true post: true activity: var sum : int := 0; ; var i : int := 1; ; var p : OclAny := makePalindrome(i, true); ; while ((p->compareTo(n)) < 0) do ( if (isPalindrome(p, k)) then ( sum := sum + p; ) else skip ; i := i + 1; ; p := makePalindrome(i, true);) ; i := 1; ; p := makePalindrome(i, false); ; while ((p->compareTo(n)) < 0) do ( if (isPalindrome(p, k)) then ( sum := sum + p; ) else skip ; i := i + 1; ; p := makePalindrome(i, false);) ; execute ("Total sum is")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=map(int,input().split()) print('Alice' if abs(x-y)>1 else 'Brown') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if (x - y)->abs() > 1 then 'Alice' else 'Brown' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from math import floor,ceil,sqrt,factorial from heapq import heappop,heappush,heappushpop from collections import Counter,defaultdict from itertools import accumulate,permutations,combinations,product,combinations_with_replacement inf=float('inf') mod=10**9+7 def INT_(n): return int(n)-1 def MI(): return map(int,input().split()) def MF(): return map(float,input().split()) def MI_(): return map(INT_,input().split()) def LI(): return list(MI()) def LI_(): return[int(x)-1 for x in input().split()] def LF(): return list(MF()) def LIN(n : int): return[I()for _ in range(n)] def LLIN(n : int): return[LI()for _ in range(n)] def LLIN_(n : int): return[LI_()for _ in range(n)] def LLI(): return[list(map(int,l.split()))for l in input()] def I(): return int(input()) def F(): return float(input()) def ST(): return input().replace('\n','') def main(): X,Y=MI() if abs(X-Y)<=1 : print("Brown") else : print("Alice") if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation INT_(n : OclAny) : OclAny pre: true post: true activity: return ("" + ((n)))->toInteger() - 1; operation MI() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation MF() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["double"])->apply(_x) ); operation MI_() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (INT_)->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return (MI()); operation LI_() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return (MF()); operation LIN(n : int) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (I())); operation LLIN(n : int) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI())); operation LLIN_(n : int) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI_())); operation LLI() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine()->select(l | true)->collect(l | (((l.split())->collect( _x | (OclType["int"])->apply(_x) )))); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation ST() : OclAny pre: true post: true activity: return input().replace(' ', ''); operation main() pre: true post: true activity: var X : OclAny := null; var Y : OclAny := null; Sequence{X,Y} := MI() ; if (X - Y)->abs() <= 1 then ( execute ("Brown")->display() ) else ( execute ("Alice")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import* from fractions import gcd from functools import* from itertools import* from operator import mul,itemgetter from bisect import* from heapq import* from math import factorial,pi from copy import deepcopy import sys sys.setrecursionlimit(10**8) def main(): a,b=map(int,input().split()) if abs(a-b)>=2 : print("Alice") else : print("Brown") if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a - b)->abs() >= 2 then ( execute ("Alice")->display() ) else ( execute ("Brown")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- xxs=input().split(" ") x,t,a,b,da,db=int(xxs[0]),int(xxs[1]),int(xxs[2]),int(xxs[3]),int(xxs[4]),int(xxs[5]) def main(): if x==0 : print("YES") return "Result Found" a_time=min([a//da,t-1]) b_time=min([b//db,t-1]) for i in range(a_time+1): for j in range(b_time+1): if a-da*i==x or b-db*j==x : print("YES") return "Result Found" if(a-da*i)+(b-db*j)==x : print("YES") return "Result Found" return "Result Not Found" ff=main() if ff=="Result Not Found" : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var xxs : OclAny := input().split(" ") ; var x : OclAny := null; var t : OclAny := null; var a : OclAny := null; var b : OclAny := null; var da : OclAny := null; var db : OclAny := null; Sequence{x,t,a,b,da,db} := Sequence{("" + ((xxs->first())))->toInteger(),("" + ((xxs[1+1])))->toInteger(),("" + ((xxs[2+1])))->toInteger(),("" + ((xxs[3+1])))->toInteger(),("" + ((xxs[4+1])))->toInteger(),("" + ((xxs[5+1])))->toInteger()} ; skip ; var ff : OclAny := main() ; if ff = "Result Not Found" then ( execute ("NO")->display() ) else skip; operation main() : OclAny pre: true post: true activity: if x = 0 then ( execute ("YES")->display() ; return "Result Found" ) else skip ; var a_time : OclAny := (Sequence{a div da}->union(Sequence{ t - 1 }))->min() ; var b_time : OclAny := (Sequence{b div db}->union(Sequence{ t - 1 }))->min() ; for i : Integer.subrange(0, a_time + 1-1) do ( for j : Integer.subrange(0, b_time + 1-1) do ( if a - da * i = x or b - db * j = x then ( execute ("YES")->display() ; return "Result Found" ) else skip ; if (a - da * i) + (b - db * j) = x then ( execute ("YES")->display() ; return "Result Found" ) else skip)) ; return "Result Not Found"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000,10**9)) write=lambda x : sys.stdout.write(x+"\n") x,y=list(map(int,input().split())) if abs(x-y)<=1 : print("Brown") else : print("Alice") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; sys.setrecursionlimit(Set{1000, (10)->pow(9)}->max()) ; var write : Function := lambda x : OclAny in ((OclFile["System.out"]).write(x + "\n")) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (x - y)->abs() <= 1 then ( execute ("Brown")->display() ) else ( execute ("Alice")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def minOperations(A,B): if(A>B): swap(A,B) B=B//math.gcd(A,B); return B-1 A=7 B=15 print(minOperations(A,B)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; A := 7 ; B := 15 ; execute (minOperations(A, B))->display(); operation minOperations(A : OclAny, B : OclAny) : OclAny pre: true post: true activity: if ((A->compareTo(B)) > 0) then ( swap(A, B) ) else skip ; B := B div (A)->gcd(B); ; return B - 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- X,Y=map(int,input().split()) print('Brown' if abs(X-Y)<=1 else 'Alice') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var X : OclAny := null; var Y : OclAny := null; Sequence{X,Y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if (X - Y)->abs() <= 1 then 'Brown' else 'Alice' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=2 ; def isVowel(ch): return(ch=='a' or ch=='e' or ch=='i' or ch=='o' or ch=='u'); def countVowels(string,l,r): cnt=0 ; for i in range(l,r+1): if(isVowel(string[i])): cnt+=1 ; return cnt ; def performQueries(string,queries,q): for i in range(q): print(countVowels(string,queries[i][0],queries[i][1])); if __name__=="__main__" : string="geeksforgeeks" ; queries=[[1,3],[2,4],[1,9]]; q=len(queries) performQueries(string,queries,q); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 2; ; skip ; skip ; skip ; if __name__ = "__main__" then ( string := "geeksforgeeks"; ; queries := Sequence{Sequence{1}->union(Sequence{ 3 })}->union(Sequence{Sequence{2}->union(Sequence{ 4 })}->union(Sequence{ Sequence{1}->union(Sequence{ 9 }) })); ; q := (queries)->size() ; performQueries(string, queries, q); ) else skip; operation isVowel(ch : OclAny) pre: true post: true activity: return (ch = 'a' or ch = 'e' or ch = 'i' or ch = 'o' or ch = 'u');; operation countVowels(string : OclAny, l : OclAny, r : OclAny) pre: true post: true activity: var cnt : int := 0; ; for i : Integer.subrange(l, r + 1-1) do ( if (isVowel(string[i+1])) then ( cnt := cnt + 1; ) else skip) ; return cnt;; operation performQueries(string : OclAny, queries : OclAny, q : OclAny) pre: true post: true activity: for i : Integer.subrange(0, q-1) do ( execute (countVowels(string, queries[i+1]->first(), queries[i+1][1+1]))->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import log def prevPowerof2(n): p=int(log(n)) return pow(2,p) def nextPowerOf2(n): p=1 if(n and(n &(n-1))==0): return n while(pdisplay(); operation prevPowerof2(n : OclAny) : OclAny pre: true post: true activity: var p : int := ("" + ((log(n))))->toInteger() ; return (2)->pow(p); operation nextPowerOf2(n : OclAny) : OclAny pre: true post: true activity: p := 1 ; if (n & (MathLib.bitwiseAnd(n, (n - 1))) = 0) then ( return n ) else skip ; while ((p->compareTo(n)) < 0) do ( p := p * (2->pow(1))) ; return p; operation minDiff(n : OclAny) : OclAny pre: true post: true activity: var low : OclAny := prevPowerof2(n) ; var high : OclAny := nextPowerOf2(n) ; return Set{n - low, high - n}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) count=0 ok=False for _ in range(N): d1,d2=[int(s)for s in input().split()] if d1==d2 : count+=1 else : count=0 if count==3 : ok=True if ok : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := 0 ; var ok : boolean := false ; for _anon : Integer.subrange(0, N-1) do ( var d1 : OclAny := null; var d2 : OclAny := null; Sequence{d1,d2} := input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; if d1 = d2 then ( count := count + 1 ) else ( count := 0 ) ; if count = 3 then ( ok := true ) else skip) ; if ok then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys import os sys.setrecursionlimit(10**7) def _S(): return sys.stdin.readline().rstrip() def I(): return int(_S()) def LS(): return list(_S().split()) def LI(): return list(map(int,LS())) if os.getenv("LOCAL"): inputFile=basename_without_ext=os.path.splitext(os.path.basename(__file__))[0]+'.txt' sys.stdin=open(inputFile,"r") INF=float("inf") N=I() D=[LI()for _ in range(N)] count=0 for i in range(N): if D[i][0]==D[i][1]: count+=1 else : count=0 if count==3 : print('Yes') exit() ans='No' print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; skip ; skip ; skip ; if os.getenv("LOCAL") then ( var inputFile : OclAny := os.path.splitext(os.path.basename(__file__))->first() + '.txt'; var basename_without_ext : OclAny := os.path.splitext(os.path.basename(__file__))->first() + '.txt' ; OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile(inputFile)) ) else skip ; var INF : double := ("" + (("inf")))->toReal() ; var N : OclAny := I() ; var D : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (LI())) ; var count : int := 0 ; for i : Integer.subrange(0, N-1) do ( if D[i+1]->first() = D[i+1][1+1] then ( count := count + 1 ) else ( count := 0 ) ; if count = 3 then ( execute ('Yes')->display() ; exit() ) else skip) ; var ans : String := 'No' ; execute (ans)->display(); operation _S() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation I() : OclAny pre: true post: true activity: return ("" + ((_S())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return (_S().split()); operation LI() : OclAny pre: true post: true activity: return ((LS())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- counter=int(input()) result_flg=False fir_fir,fir_sec=map(int,input().split()) sec_fir,sec_sec=map(int,input().split()) for i in range(2,counter): thi_fir,thi_sec=map(int,input().split()) if fir_fir==fir_sec : if sec_fir==sec_sec : if thi_fir==thi_sec : result_flg=True break fir_fir=sec_fir fir_sec=sec_sec sec_fir=thi_fir sec_sec=thi_sec if result_flg==True : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var counter : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var result_flg : boolean := false ; var fir_fir : OclAny := null; var fir_sec : OclAny := null; Sequence{fir_fir,fir_sec} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sec_fir : OclAny := null; var sec_sec : OclAny := null; Sequence{sec_fir,sec_sec} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(2, counter-1) do ( var thi_fir : OclAny := null; var thi_sec : OclAny := null; Sequence{thi_fir,thi_sec} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if fir_fir = fir_sec then ( if sec_fir = sec_sec then ( if thi_fir = thi_sec then ( result_flg := true ; break ) else skip ) else skip ) else skip ; var fir_fir : OclAny := sec_fir ; var fir_sec : OclAny := sec_sec ; var sec_fir : OclAny := thi_fir ; var sec_sec : OclAny := thi_sec) ; if result_flg = true then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import itertools import collections from collections import deque from collections import defaultdict sys.setrecursionlimit(1000000) MOD=10**9+7 MOD2=998244353 INF=float('inf') input=lambda : sys.stdin.readline().strip() NI=lambda : int(input()) NMI=lambda : map(int,input().split()) NLI=lambda : list(NMI()) SI=lambda : input() def main(): N=NI() AB=[NLI()for _ in range(N)] for n in range(N-2): if AB[n][0]==AB[n][1]: if AB[n+1][0]==AB[n+1][1]: if AB[n+2][0]==AB[n+2][1]: print("Yes") sys.exit() print("No") if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1000000) ; var MOD : double := (10)->pow(9) + 7 ; var MOD2 : int := 998244353 ; var INF : double := ("" + (('inf')))->toReal() ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine()->trim()) ; var NI : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var NMI : Function := lambda $$ : OclAny in ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var NLI : Function := lambda $$ : OclAny in ((NMI->apply())) ; var SI : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := NI->apply() ; var AB : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (NLI->apply())) ; for n : Integer.subrange(0, N - 2-1) do ( if AB[n+1]->first() = AB[n+1][1+1] then ( if AB[n + 1+1]->first() = AB[n + 1+1][1+1] then ( if AB[n + 2+1]->first() = AB[n + 2+1][1+1] then ( execute ("Yes")->display() ; sys.exit() ) else skip ) else skip ) else skip) ; execute ("No")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) D1=[0]*N D2=[0]*N count=0 continues=[0]*N for i in range(N): D1[i],D2[i]=[int(x)for x in input().split()] for i in range(N): if D1[i]==D2[i]: continues[i]=1 for i in range(N): if continues[i]==1 : count=count+1 else : count=0 if count==3 : break if count<3 : print("No") else : print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var D1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var D2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var count : int := 0 ; var continues : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for i : Integer.subrange(0, N-1) do ( var D1[i+1] : OclAny := null; var D2[i+1] : OclAny := null; Sequence{D1[i+1],D2[i+1]} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) ; for i : Integer.subrange(0, N-1) do ( if D1[i+1] = D2[i+1] then ( continues[i+1] := 1 ) else skip) ; for i : Integer.subrange(0, N-1) do ( if continues[i+1] = 1 then ( count := count + 1 ) else ( count := 0 ) ; if count = 3 then ( break ) else skip) ; if count < 3 then ( execute ("No")->display() ) else ( execute ("Yes")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- xxs=input().split(" ") x,t,a,b,da,db=int(xxs[0]),int(xxs[1]),int(xxs[2]),int(xxs[3]),int(xxs[4]),int(xxs[5]) def main(): if x==0 : print("YES") return "Result Found" a_time=min([a//da,t-1]) b_time=min([b//db,t-1]) for i in range(a_time+1): for j in range(b_time+1): if a-da*i==x or b-db*j==x : print("YES") return "Result Found" if(a-da*i)+(b-db*j)==x : print("YES") return "Result Found" return "Result Not Found" ff=main() if ff=="Result Not Found" : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var xxs : OclAny := input().split(" ") ; var x : OclAny := null; var t : OclAny := null; var a : OclAny := null; var b : OclAny := null; var da : OclAny := null; var db : OclAny := null; Sequence{x,t,a,b,da,db} := Sequence{("" + ((xxs->first())))->toInteger(),("" + ((xxs[1+1])))->toInteger(),("" + ((xxs[2+1])))->toInteger(),("" + ((xxs[3+1])))->toInteger(),("" + ((xxs[4+1])))->toInteger(),("" + ((xxs[5+1])))->toInteger()} ; skip ; var ff : OclAny := main() ; if ff = "Result Not Found" then ( execute ("NO")->display() ) else skip; operation main() : OclAny pre: true post: true activity: if x = 0 then ( execute ("YES")->display() ; return "Result Found" ) else skip ; var a_time : OclAny := (Sequence{a div da}->union(Sequence{ t - 1 }))->min() ; var b_time : OclAny := (Sequence{b div db}->union(Sequence{ t - 1 }))->min() ; for i : Integer.subrange(0, a_time + 1-1) do ( for j : Integer.subrange(0, b_time + 1-1) do ( if a - da * i = x or b - db * j = x then ( execute ("YES")->display() ; return "Result Found" ) else skip ; if (a - da * i) + (b - db * j) = x then ( execute ("YES")->display() ; return "Result Found" ) else skip)) ; return "Result Not Found"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(20000) def search(table,visited,i,j,c): visited[i][j]=True if table[i+1][j]==c and visited[i+1][j]==False : search(table,visited,i+1,j,c) if table[i-1][j]==c and visited[i-1][j]==False : search(table,visited,i-1,j,c) if table[i][j+1]==c and visited[i][j+1]==False : search(table,visited,i,j+1,c) if table[i][j-1]==c and visited[i][j-1]==False : search(table,visited,i,j-1,c) while True : H,W=[int(i)for i in input().split()] if H==0 and W==0 : break visited=[[False for i in range(W+2)]for j in range(H+2)] table=[["." for i in range(W+2)]for j in range(H+2)] for i in range(1,H+1): s=input() for j in range(1,W+1): table[i][j]=s[j-1] ans=0 for i in range(1,H+1): for j in range(1,W+1): if visited[i][j]==False : ans+=1 search(table,visited,i,j,table[i][j]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(20000) ; skip ; while true do ( var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if H = 0 & W = 0 then ( break ) else skip ; visited := Integer.subrange(0, H + 2-1)->select(j | true)->collect(j | (Integer.subrange(0, W + 2-1)->select(i | true)->collect(i | (false)))) ; table := Integer.subrange(0, H + 2-1)->select(j | true)->collect(j | (Integer.subrange(0, W + 2-1)->select(i | true)->collect(i | (".")))) ; for i : Integer.subrange(1, H + 1-1) do ( var s : String := (OclFile["System.in"]).readLine() ; for j : Integer.subrange(1, W + 1-1) do ( table[i+1][j+1] := s[j - 1+1])) ; var ans : int := 0 ; for i : Integer.subrange(1, H + 1-1) do ( for j : Integer.subrange(1, W + 1-1) do ( if visited[i+1][j+1] = false then ( ans := ans + 1 ; search(table, visited, i, j, table[i+1][j+1]) ) else skip)) ; execute (ans)->display()); operation search(table : OclAny, visited : OclAny, i : OclAny, j : OclAny, c : OclAny) pre: true post: true activity: visited[i+1][j+1] := true ; if table[i + 1+1][j+1] = c & visited[i + 1+1][j+1] = false then ( search(table, visited, i + 1, j, c) ) else skip ; if table[i - 1+1][j+1] = c & visited[i - 1+1][j+1] = false then ( search(table, visited, i - 1, j, c) ) else skip ; if table[i+1][j + 1+1] = c & visited[i+1][j + 1+1] = false then ( search(table, visited, i, j + 1, c) ) else skip ; if table[i+1][j - 1+1] = c & visited[i+1][j - 1+1] = false then ( search(table, visited, i, j - 1, c) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(): person=0 for i in range(0,H): for j in range(0,W): if geo[i][j]is not "_" : search(i,j) person+=1 print(person) def search(i,j): temp=geo[i][j] geo[i][j]="_" for a in range(0,4): idx,jdy=i+dx[a],j+dy[a] if(isOnMap(idx,jdy)): if(isNeededToSolve(temp,idx,jdy)): search(idx,jdy) def isOnMap(i,j): return(0<=i and 0<=j and ipow(7) ; sys.setrecursionlimit(limit) ; var H : OclAny := null; var W : OclAny := null; var tempH : OclAny := null; Sequence{H,W,tempH} := Sequence{-1,-1,0} ; var dx : Sequence := Sequence{-1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 0 }))) ; var dy : Sequence := Sequence{0}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{ 1 }))) ; var geo : Sequence := Integer.subrange(0, 1-1)->select(j | true)->collect(j | (Integer.subrange(0, 1-1)->select(i | true)->collect(i | (0)))) ; while true do ( var line : String := (OclFile["System.in"]).readLine() ; if H <>= -1 & W <>= -1 then ( var p : OclAny := line.split(" ") ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := Sequence{("" + ((p->first())))->toInteger(),("" + ((p[1+1])))->toInteger()} ; geo := Integer.subrange(0, H-1)->select(j | true)->collect(j | (Integer.subrange(0, W-1)->select(i | true)->collect(i | (0)))) ) else ( geo[tempH+1] := (line)->characters() ; tempH := tempH + 1 ) ; if H <>= 0 & W <>= 0 then ( break ) else skip ; if tempH <>= H then ( solve() ; var H : OclAny := null; var W : OclAny := null; var tempH : OclAny := null; Sequence{H,W,tempH} := Sequence{-1,-1,0} ) else skip); operation solve() pre: true post: true activity: var person : int := 0 ; for i : Integer.subrange(0, H-1) do ( for j : Integer.subrange(0, W-1) do ( if not(geo[i+1][j+1] <>= "_") then ( search(i, j) ; person := person + 1 ) else skip)) ; execute (person)->display(); operation search(i : OclAny, j : OclAny) pre: true post: true activity: var temp : OclAny := geo[i+1][j+1] ; geo[i+1][j+1] := "_" ; for a : Integer.subrange(0, 4-1) do ( var idx : OclAny := null; var jdy : OclAny := null; Sequence{idx,jdy} := Sequence{i + dx[a+1],j + dy[a+1]} ; if (isOnMap(idx, jdy)) then ( if (isNeededToSolve(temp, idx, jdy)) then ( search(idx, jdy) ) else skip ) else skip); operation isOnMap(i : OclAny, j : OclAny) : OclAny pre: true post: true activity: return (0 <= i & 0 <= j & (i->compareTo(H)) < 0 & (j->compareTo(W)) < 0); operation isNeededToSolve(temp : OclAny, i : OclAny, j : OclAny) : OclAny pre: true post: true activity: var target : OclAny := geo[i+1][j+1] ; return (not(target <>= "_") & temp <>= target); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools def compute(): ans=max(range(1,1000),key=reciprocal_cycle_len) return str(ans) def reciprocal_cycle_len(n): seen={} x=1 for i in itertools.count(): if x in seen : return i-seen[x] else : seen[x]=i x=x*10 % n if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : OclAny := Set{Integer.subrange(1, 1000-1), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name reciprocal_cycle_len)))))))}->max() ; return ("" + ((ans))); operation reciprocal_cycle_len(n : OclAny) : OclAny pre: true post: true activity: var seen : OclAny := Set{} ; var x : int := 1 ; for i : itertools->count() do ( if (seen)->includes(x) then ( return i - seen[x+1] ) else ( seen[x+1] := i ; x := x * 10 mod n )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Labeling(terrain): label=terrain offset=[[-1,0],[0,-1],[1,0],[0,1]] signs=["@","#","*"] rowLength,colLength=len(label)-1,len(label[0])-1 step=0 for row in range(1,rowLength): for col in range(1,colLength): mark=label[row][col] if mark in signs : pointStack=[[row,col]] label[row][col]=step while 0select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; if row = 0 & col = 0 then ( break ) else skip ; var land : Sequence := Sequence{} ; execute ((StringLib.nCopies(Sentinel, row) + StringLib.nCopies(Sentinel, 2)->select(item | true)->collect(item | (item))) : land) ; for lp : Integer.subrange(0, col-1) do ( var part : Sequence := (OclFile["System.in"]).readLine()->select(item | true)->collect(item | (item)) ; execute ((Sequence{}) : land) ; (expr (atom (name land)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) (trailer . (name extend) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name Sentinel))))))) ]))))))) )))) ; (expr (atom (name land)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) (trailer . (name extend) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name part)))))))) )))) ; (expr (atom (name land)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) (trailer . (name extend) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name Sentinel))))))) ]))))))) ))))) ; execute ((StringLib.nCopies(Sentinel, row) + StringLib.nCopies(Sentinel, 2)->select(item | true)->collect(item | (item))) : land) ; var result : OclAny := Labeling(land) ; execute (result)->display()); operation Labeling(terrain : OclAny) : OclAny pre: true post: true activity: var label : OclAny := terrain ; var offset : Sequence := Sequence{Sequence{-1}->union(Sequence{ 0 })}->union(Sequence{Sequence{0}->union(Sequence{ -1 })}->union(Sequence{Sequence{1}->union(Sequence{ 0 })}->union(Sequence{ Sequence{0}->union(Sequence{ 1 }) }))) ; var signs : Sequence := Sequence{"@"}->union(Sequence{"#"}->union(Sequence{ "*" })) ; var rowLength : OclAny := null; var colLength : OclAny := null; Sequence{rowLength,colLength} := Sequence{(label)->size() - 1,(label->first())->size() - 1} ; var step : int := 0 ; for row : Integer.subrange(1, rowLength-1) do ( for col : Integer.subrange(1, colLength-1) do ( var mark : OclAny := label[row+1][col+1] ; if (signs)->includes(mark) then ( var pointStack : Sequence := Sequence{ Sequence{row}->union(Sequence{ col }) } ; label[row+1][col+1] := step ; while 0 < (pointStack)->size() do ( var rowIndex : OclAny := null; var colIndex : OclAny := null; Sequence{rowIndex,colIndex} := pointStack->last() ; pointStack := pointStack->front() ; for _tuple : offset do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); var offsetRow : OclAny := null; var offsetCol : OclAny := null; Sequence{offsetRow,offsetCol} := Sequence{rowIndex + x,colIndex + y} ; if label[offsetRow+1][offsetCol+1] = mark then ( execute ((Sequence{offsetRow}->union(Sequence{ offsetCol })) : pointStack) ; label[offsetRow+1][offsetCol+1] := step ) else skip)) ; step := step + 1 ) else skip)) ; return step; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10000000) def search(values,hp,vp,item): if not(0<=hpsize()))) then ( return ) else skip ; if not((0 <= vp & (vp < (values[hp+1])->size()))) then ( return ) else skip ; if item /= values[hp+1][vp+1] then ( return ) else skip ; values[hp+1][vp+1] := true ; search(values, hp - 1, vp, item) ; search(values, hp + 1, vp, item) ; search(values, hp, vp - 1, item) ; search(values, hp, vp + 1, item); operation solve(values : OclAny) : OclAny pre: true post: true activity: var count : OclAny := null; var valid_items : OclAny := null; Sequence{count,valid_items} := Sequence{0,Set{}->union((Sequence{'@'}->union(Sequence{'#'}->union(Sequence{ '*' }))))} ; for i : Integer.subrange(0, (values)->size()-1) do ( for j : Integer.subrange(0, (values[i+1])->size()-1) do ( if (valid_items)->includes(values[i+1][j+1]) then ( search(values, i, j, values[i+1][j+1]) ; count := count + 1 ) else skip)) ; return count; operation main() pre: true post: true activity: var line : OclAny := null; Sequence{line,values} := Sequence{input()->trim(),()} ; while line /= '0 0' do ( var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := ((line.split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var value : Sequence := () ; for _anon : Integer.subrange(0, H-1) do ( execute ((((argument (test (logical_test (comparison (expr (atom (name x)))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name strip) (arguments ( )))))))))) : value)) ; execute ((value) : values) ; var line : OclAny := input()->trim()) ; for value : values do ( execute (solve(value))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import queue dr=[0,0,1,-1] dc=[1,-1,0,0] while True : a=[int(num)for num in input().split(' ')] if a[0]==0 : break s=[] cnt=0 for i in range(a[0]): s.append(list(input())) q=queue.Queue() for i in range(a[0]): for j in range(a[1]): if s[i][j]=='.' : continue f=s[i][j] l=[[i,j]] while len(l)!=0 : next_depth=[] for cor in l : for k in range(4): r=cor[0]+dr[k] c=cor[1]+dc[k] if 0<=runion(Sequence{0}->union(Sequence{1}->union(Sequence{ -1 }))) ; var dc : Sequence := Sequence{1}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{ 0 }))) ; while true do ( var a : Sequence := input().split(' ')->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; if a->first() = 0 then ( break ) else skip ; var s : Sequence := Sequence{} ; var cnt : int := 0 ; for i : Integer.subrange(0, a->first()-1) do ( execute ((((OclFile["System.in"]).readLine())->characters()) : s)) ; var q : OclAny := queue.Queue() ; for i : Integer.subrange(0, a->first()-1) do ( for j : Integer.subrange(0, a[1+1]-1) do ( if s[i+1][j+1] = '.' then ( continue ) else skip ; var f : OclAny := s[i+1][j+1] ; var l : Sequence := Sequence{ Sequence{i}->union(Sequence{ j }) } ; while (l)->size() /= 0 do ( var next_depth : Sequence := Sequence{} ; for cor : l do ( for k : Integer.subrange(0, 4-1) do ( var r : OclAny := cor->first() + dr[k+1] ; var c : OclAny := cor[1+1] + dc[k+1] ; if 0 <= r & (r < a->first()) & 0 <= c & (c < a[1+1]) & s[r+1][c+1] = f then ( s[r+1][c+1] := '.' ; execute ((Sequence{r}->union(Sequence{ c })) : next_depth) ) else skip)) ; l := next_depth) ; cnt := cnt + 1)) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def decBinary(arr,n): k=int(math.log2(n)) while(n>0): arr[k]=n % 2 k=k-1 n=n//2 def binaryDec(arr,n): ans=0 for i in range(0,n): ans=ans+(arr[i]<<(n-i-1)) return ans def concat(m,n): k=int(math.log2(m))+1 l=int(math.log2(n))+1 a=[0 for i in range(0,k)] b=[0 for i in range(0,l)] c=[0 for i in range(0,k+l)] decBinary(a,m); decBinary(b,n); iin=0 for i in range(0,k): c[iin]=a[i] iin=iin+1 for i in range(0,l): c[iin]=b[i] iin=iin+1 return(binaryDec(c,k+l)) m=4 n=5 print(concat(m,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; m := 4 ; n := 5 ; execute (concat(m, n))->display(); operation decBinary(arr : OclAny, n : OclAny) pre: true post: true activity: var k : int := ("" + (()))->toInteger() ; while (n > 0) do ( arr[k+1] := n mod 2 ; k := k - 1 ; n := n div 2); operation binaryDec(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( ans := ans + (arr[i+1] * (2->pow((n - i - 1))))) ; return ans; operation concat(m : OclAny, n : OclAny) : OclAny pre: true post: true activity: k := ("" + (()))->toInteger() + 1 ; var l : int := ("" + (()))->toInteger() + 1 ; var a : Sequence := Integer.subrange(0, k-1)->select(i | true)->collect(i | (0)) ; var b : Sequence := Integer.subrange(0, l-1)->select(i | true)->collect(i | (0)) ; var c : Sequence := Integer.subrange(0, k + l-1)->select(i | true)->collect(i | (0)) ; decBinary(a, m); ; decBinary(b, n); ; var iin : int := 0 ; for i : Integer.subrange(0, k-1) do ( c[iin+1] := a[i+1] ; iin := iin + 1) ; for i : Integer.subrange(0, l-1) do ( c[iin+1] := b[i+1] ; iin := iin + 1) ; return (binaryDec(c, k + l)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.buffer.readline def find_root(root_dict,x): L=[] while x!=root_dict[x]: L.append(x) x=root_dict[x] for y in L : root_dict[y]=x return x def process(n,G): m=len(G) g=[[]for i in range(n+1)] root_dict=[i for i in range(n+1)] for a,b in G : a1=find_root(root_dict,a) b1=find_root(root_dict,b) if a1!=b1 : root_dict[b1]=a1 g[a].append(b) g[b].append(a) roots=[[]for i in range(n+1)] for i in range(1,n+1): r=find_root(root_dict,i) roots[r].append(i) for r in range(1,n+1): for i in roots[r]: if len(g[i])!=len(roots[r])-1 : print("NO") return print("YES") n,m=[int(x)for x in input().split()] G=[] for i in range(m): a,b=[int(x)for x in input().split()] G.append([a,b]) process(n,G) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := sys.stdin.buffer.readline ; skip ; skip ; Sequence{n,m} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; G := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((Sequence{a}->union(Sequence{ b })) : G)) ; process(n, G); operation find_root(root_dict : OclAny, x : OclAny) : OclAny pre: true post: true activity: var L : Sequence := Sequence{} ; while x /= root_dict[x+1] do ( execute ((x) : L) ; x := root_dict[x+1]) ; for y : L do ( root_dict[y+1] := x) ; return x; operation process(n : OclAny, G : OclAny) pre: true post: true activity: var m : int := (G)->size() ; var g : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Sequence{})) ; root_dict := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (i)) ; for _tuple : G do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); var a1 : OclAny := find_root(root_dict, a) ; var b1 : OclAny := find_root(root_dict, b) ; if a1 /= b1 then ( root_dict[b1+1] := a1 ) else skip ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var roots : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(1, n + 1-1) do ( var r : OclAny := find_root(root_dict, i) ; (expr (atom (name roots)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; for r : Integer.subrange(1, n + 1-1) do ( for i : roots[r+1] do ( if (g[i+1])->size() /= (roots[r+1])->size() - 1 then ( execute ("NO")->display() ; return ) else skip)) ; execute ("YES")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(x)for x in input().split()] g=[[i]for i in range(n+1)] for i in range(m): a,b=[int(x)for x in input().split()] g[a].append(b) g[b].append(a) flag=0 vis=[0 for i in range(n+1)] lis=[set(g[i])for i in range(n+1)] for i in range(n): if vis[i]: continue for child in g[i]: if lis[i]!=lis[child]: print('NO') exit() vis[child]=1 print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var g : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Sequence{ i })) ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var flag : int := 0 ; var vis : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; var lis : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Set{}->union((g[i+1])))) ; for i : Integer.subrange(0, n-1) do ( if vis[i+1] then ( continue ) else skip ; for child : g[i+1] do ( if lis[i+1] /= lis[child+1] then ( execute ('NO')->display() ; exit() ) else skip ; vis[child+1] := 1)) ; execute ('YES')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import lru_cache from collections import defaultdict def dfs(cur,graph,visited): if cur in visited : return 0,0 visited.add(cur) n=1 e=len(graph[cur]) for nbr in graph[cur]: a,b=dfs(nbr,graph,visited) n+=a e+=b return n,e def solution(): n,m=map(int,input().split()) graph=defaultdict(list) for _ in range(m): a,b=map(int,input().split()) graph[a].append(b) graph[b].append(a) visited=set() for node in range(1,n+1): if node in visited : continue num_nodes,e=dfs(node,graph,visited) if num_nodes*(num_nodes-1)!=e : print("NO") return ; print("YES") import sys import threading sys.setrecursionlimit(1<<30) threading.stack_size(1<<27) thread=threading.Thread(target=solution) thread.start(); thread.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1 * (2->pow(30))) ; threading.stack_size(1 * (2->pow(27))) ; var thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name solution)))))))) ; thread.start(); thread.join(); operation dfs(cur : OclAny, graph : OclAny, visited : OclAny) : OclAny pre: true post: true activity: if (visited)->includes(cur) then ( return 0, 0 ) else skip ; execute ((cur) : visited) ; var n : int := 1 ; var e : int := (graph[cur+1])->size() ; for nbr : graph[cur+1] do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := dfs(nbr, graph, visited) ; n := n + a ; e := e + b) ; return n, e; operation solution() : OclAny pre: true post: true activity: var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; graph := defaultdict(OclType["Sequence"]) ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; visited := Set{}->union(()) ; for node : Integer.subrange(1, n + 1-1) do ( if (visited)->includes(node) then ( continue ) else skip ; var num_nodes : OclAny := null; Sequence{num_nodes,e} := dfs(node, graph, visited) ; if num_nodes * (num_nodes - 1) /= e then ( execute ("NO")->display() ; return; ) else skip) ; execute ("YES")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,m=map(int,input().split()) if n==0 and m==0 : break if n!=0 and m!=0 : t_all=[0]+sorted(list(map(int,input().split()))+list(map(int,input().split()))) else : t_all=[0]+sorted(map(int,input().split())) ans=0 for i in range(1,n+m+1): ans=max(ans,t_all[i]-t_all[i-1]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 & m = 0 then ( break ) else skip ; if n /= 0 & m /= 0 then ( var t_all : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->sort()) ) else ( t_all := Sequence{ 0 }->union((input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort()) ) ; var ans : int := 0 ; for i : Integer.subrange(1, n + m + 1-1) do ( ans := Set{ans, t_all[i+1] - t_all[i - 1+1]}->max()) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math def ncr(n,r): return math.factorial(n)//math.factorial(r)//math.factorial(n-r) def probability(height,diamonds): ways=0 for i in range(height,diamonds+1): ways+=ncr(diamonds,i) return ways/(2**diamonds) fin=sys.stdin T=int(fin.readline()) for case in range(1,T+1): N,X,Y=map(int,fin.readline().split()) seq=(abs(X)+Y)//2 remaining=N for i in range(seq): diamonds=i*4+1 remaining-=diamonds sidelen=seq*2+1 diamonds=seq*4+1 prob=0.0 if remaining>=diamonds : prob=1.0 elif remaining<=0 : prob=0.0 else : if X==0 : prob=0.0 else : if remaining-(sidelen-1)>Y : prob=1.0 else : prob=probability(Y+1,remaining) print("Case #%d: %.10f" %(case,prob)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var fin : OclFile := OclFile["System.in"] ; var T : int := ("" + ((fin.readLine())))->toInteger() ; for case : Integer.subrange(1, T + 1-1) do ( var N : OclAny := null; var X : OclAny := null; var Y : OclAny := null; Sequence{N,X,Y} := (fin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var seq : int := ((X)->abs() + Y) div 2 ; var remaining : OclAny := N ; for i : Integer.subrange(0, seq-1) do ( diamonds := i * 4 + 1 ; remaining := remaining - diamonds) ; var sidelen : int := seq * 2 + 1 ; diamonds := seq * 4 + 1 ; var prob : double := 0.0 ; if (remaining->compareTo(diamonds)) >= 0 then ( prob := 1.0 ) else (if remaining <= 0 then ( prob := 0.0 ) else ( if X = 0 then ( prob := 0.0 ) else ( if (remaining - (sidelen - 1)->compareTo(Y)) > 0 then ( prob := 1.0 ) else ( prob := probability(Y + 1, remaining) ) ) ) ) ; execute (StringLib.format("Case #%d: %.10f",Sequence{case, prob}))->display()); operation ncr(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: return MathLib.factorial(n) div MathLib.factorial(r) div MathLib.factorial(n - r); operation probability(height : OclAny, diamonds : OclAny) : OclAny pre: true post: true activity: var ways : int := 0 ; for i : Integer.subrange(height, diamonds + 1-1) do ( ways := ways + ncr(diamonds, i)) ; return ways / ((2)->pow(diamonds)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isSumOfPowersOfTwo(n): if n % 2==1 : return False else : return True n=10 if isSumOfPowersOfTwo(n): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 10 ; if isSumOfPowersOfTwo(n) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isSumOfPowersOfTwo(n : OclAny) : OclAny pre: true post: true activity: if n mod 2 = 1 then ( return false ) else ( return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) v=[0]*150005 s=[set([i])for i in range(150005)] for _ in ' '*m : a,b=map(int,input().split()) s[a].add(b) s[b].add(a) for i in range(n): if not v[i]: for j in s[i]: v[j]=1 if s[j]!=s[i]: print('NO') exit(0) print('YES') num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var v : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 150005) ; var s : Sequence := Integer.subrange(0, 150005-1)->select(i | true)->collect(i | (Set{}->union((Sequence{ i })))) ; for _anon : StringLib.nCopies(' ', m) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; for i : Integer.subrange(0, n-1) do ( if not(v[i+1]) then ( for j : s[i+1] do ( v[j+1] := 1 ; if s[j+1] /= s[i+1] then ( execute ('NO')->display() ; exit(0) ) else skip) ) else skip) ; execute ('YES')->display() ; var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- string1=input().lower() string2=input().lower() i=0 while iord(string2[i]): print(1) elif ord(string1[i])toLowerCase() ; var string2 : OclAny := input()->toLowerCase() ; var i : int := 0 ; while (i->compareTo((string1)->size() - 1)) < 0 & string1[i+1] = string2[i+1] do ( i := i + 1) ; if ((string1[i+1])->char2byte()->compareTo((string2[i+1])->char2byte())) > 0 then ( execute (1)->display() ) else (if ((string1[i+1])->char2byte()->compareTo((string2[i+1])->char2byte())) < 0 then ( execute (-1)->display() ) else ( execute (0)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=input() x=a.lower() y=b.lower() if x==y : print('0') if xy : print('1') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var x : String := a->toLowerCase() ; var y : String := b->toLowerCase() ; if x = y then ( execute ('0')->display() ) else skip ; if x < y then ( execute ('-1')->display() ) else skip ; if x > y then ( execute ('1')->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,d=map(int,input().split()) mp=[input()for _ in range(n)] t='.'*d cnt=0 for i in range(n): for j in range(m): if j<=m-d and mp[i][j : j+d]==t : cnt+=1 if i<=n-d : ns='' for l in range(d): ns+=mp[i+l][j] if ns==t : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var d : OclAny := null; Sequence{n,m,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mp : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var t : String := StringLib.nCopies('.', d) ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if (j->compareTo(m - d)) <= 0 & mp[i+1].subrange(j+1, j + d) = t then ( cnt := cnt + 1 ) else skip ; if (i->compareTo(n - d)) <= 0 then ( var ns : String := '' ; for l : Integer.subrange(0, d-1) do ( ns := ns + mp[i + l+1][j+1] ; if ns = t then ( cnt := cnt + 1 ) else skip) ) else skip)) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input().lower() z=input().lower() if x==z : print("0") elif xz : print("1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := input()->toLowerCase() ; var z : OclAny := input()->toLowerCase() ; if x = z then ( execute ("0")->display() ) else (if (x->compareTo(z)) < 0 then ( execute ("-1")->display() ) else (if (x->compareTo(z)) > 0 then ( execute ("1")->display() ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() x=x.lower() y=input() y=y.lower() f=0 for i in range(len(x)): if x[i]!=y[i]: f=1 if x[i]>y[i]: print(1) else : print(-1) break if f==0 : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := (OclFile["System.in"]).readLine() ; x := x->toLowerCase() ; var y : String := (OclFile["System.in"]).readLine() ; y := y->toLowerCase() ; var f : int := 0 ; for i : Integer.subrange(0, (x)->size()-1) do ( if x[i+1] /= y[i+1] then ( f := 1 ; if (x[i+1]->compareTo(y[i+1])) > 0 then ( execute (1)->display() ) else ( execute (-1)->display() ) ; break ) else skip) ; if f = 0 then ( execute (0)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=input() a=a.lower() b=b.lower() y=0 for i in range(len(a)): if(ord(a[i])ord(b[i])): y=1 print("1") break if(y==0): print("0") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; a := a->toLowerCase() ; b := b->toLowerCase() ; var y : int := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( if (((a[i+1])->char2byte()->compareTo((b[i+1])->char2byte())) < 0) then ( y := 1 ; execute ("-1")->display() ; break ) else (if (((a[i+1])->char2byte()->compareTo((b[i+1])->char2byte())) > 0) then ( y := 1 ; execute ("1")->display() ; break ) else skip)) ; if (y = 0) then ( execute ("0")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) elems=[] for _ in range(n): k,*arr=list(map(int,input().split())) elems.append((max(arr),k)) elems.sort(reverse=True) ans=0 for i in range(1,n): ans+=(elems[0][0]-elems[i][0])*elems[i][1] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var elems : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var k : OclAny := null; var arr : OclAny := null; Sequence{k,arr} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((Sequence{(arr)->max(), k}) : elems)) ; elems := elems->sort() ; var ans : int := 0 ; for i : Integer.subrange(1, n-1) do ( ans := ans + (elems->first()->first() - elems[i+1]->first()) * elems[i+1][1+1]) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) LL=[] m=0 for i in range(n): l=list(map(int,input().split()))[1 :] LL.append(l) m=max(m,max(l)) s=0 for i in LL : s+=len(i)*(m-max(i)) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var LL : Sequence := Sequence{} ; var m : int := 0 ; for i : Integer.subrange(0, n-1) do ( var l : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->tail() ; execute ((l) : LL) ; m := Set{m, (l)->max()}->max()) ; var s : int := 0 ; for i : LL do ( s := s + (i)->size() * (m - (i)->max())) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : n=int(input()) p=[] while n : a=list(map(int,input().split())) p.append((a[0],sorted(a[1 :]))) n-=1 max_val=max(a[-1]for _,a in p) res=sum((max_val-a[-1])*m for m,a in p) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := Sequence{} ; while n do ( var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((Sequence{a->first(), a->tail()->sort()}) : p) ; n := n - 1) ; var max_val : OclAny := ((argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))) (comp_for for (exprlist (expr (atom (name _))) , (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name p))))))))->max() ; var res : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name max_val))) - (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))))) ))) * (expr (atom (name m))))))) (comp_for for (exprlist (expr (atom (name m))) , (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name p))))))))->sum() ; execute (res)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) s=input() p=0 for i in range(n-1): p+=s[i]==s[i+1] print((p+1)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var p : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( p := p + s[i+1] = s[i + 1+1]) ; execute ((p + 1) div 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : n=int(input()) p=[] max_val=0 while n : m,*b=input().split() m=int(m) m_v=max(int(v)for v in b) p.append((m,m_v)) max_val=max(max_val,m_v) n-=1 res=sum((max_val-v)*m for m,v in p) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := Sequence{} ; var max_val : int := 0 ; while n do ( var m : OclAny := null; var b : OclAny := null; Sequence{m,b} := input().split() ; var m : int := ("" + ((m)))->toInteger() ; var m_v : OclAny := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) ))))))) (comp_for for (exprlist (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name b))))))))->max() ; execute ((Sequence{m, m_v}) : p) ; max_val := Set{max_val, m_v}->max() ; n := n - 1) ; var res : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name max_val))) - (expr (atom (name v)))))))) ))) * (expr (atom (name m))))))) (comp_for for (exprlist (expr (atom (name m))) , (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name p))))))))->sum() ; execute (res)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : n=int(input()) p=[] max_val=0 while n : m,*b=input().split() m=int(m) m_v=max(int(v)for v in b) p.append((m,m_v)) max_val=max(max_val,m_v) n-=1 res=sum((max_val-v)*m for m,v in p) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := Sequence{} ; var max_val : int := 0 ; while n do ( var m : OclAny := null; var b : OclAny := null; Sequence{m,b} := input().split() ; var m : int := ("" + ((m)))->toInteger() ; var m_v : OclAny := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) ))))))) (comp_for for (exprlist (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name b))))))))->max() ; execute ((Sequence{m, m_v}) : p) ; max_val := Set{max_val, m_v}->max() ; n := n - 1) ; var res : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name max_val))) - (expr (atom (name v)))))))) ))) * (expr (atom (name m))))))) (comp_for for (exprlist (expr (atom (name m))) , (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name p))))))))->sum() ; execute (res)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def hammingDistance(self,x,y): return bin(x ^ y).count('1') ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation hammingDistance(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: return bin(MathLib.bitwiseXor(x, y))->count('1'); } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findRotations(str): tmp=str+str n=len(str) for i in range(1,n+1): substring=tmp[i : i+n] if(str==substring): return i return n if __name__=='__main__' : str="abc" print(findRotations(str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( OclType["String"] := "abc" ; execute (findRotations(OclType["String"]))->display() ) else skip; operation findRotations(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var tmp : String := OclType["String"] + OclType["String"] ; var n : int := (OclType["String"])->size() ; for i : Integer.subrange(1, n + 1-1) do ( var substring : OclAny := tmp.subrange(i+1, i + n) ; if (OclType["String"] = substring) then ( return i ) else skip) ; return n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[int(i)for i in input().split(' ')] N,M,D=a[0],a[1],a[2] area=[] for i in range(N): area.append(input()) toori=0 reverse_area=[] for tate in range(N): row_area=list(area[tate]) for yoko in range(M-D+1): mass=D for now_mass in range(D): if row_area[now_mass+yoko]=="." : mass-=1 if row_area[now_mass+yoko]=='#' : break if mass==0 : toori+=1 break for tate in range(N-D+1): for yoko in range(M): mass=D for now_mass in range(D): if area[now_mass+tate][yoko]=="." : mass-=1 if area[now_mass+tate][yoko]=='#' : break if mass==0 : toori+=1 break print(toori) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := input().split(' ')->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var N : OclAny := null; var M : OclAny := null; var D : OclAny := null; Sequence{N,M,D} := Sequence{a->first(),a[1+1],a[2+1]} ; var area : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute (((OclFile["System.in"]).readLine()) : area)) ; var toori : int := 0 ; var reverse_area : Sequence := Sequence{} ; for tate : Integer.subrange(0, N-1) do ( var row_area : Sequence := (area[tate+1]) ; for yoko : Integer.subrange(0, M - D + 1-1) do ( var mass : OclAny := D ; for now_mass : Integer.subrange(0, D-1) do ( if row_area[now_mass + yoko+1] = "." then ( mass := mass - 1 ) else skip ; if row_area[now_mass + yoko+1] = '#' then ( break ) else skip ; if mass = 0 then ( toori := toori + 1 ; break ) else skip))) ; for tate : Integer.subrange(0, N - D + 1-1) do ( for yoko : Integer.subrange(0, M-1) do ( mass := D ; for now_mass : Integer.subrange(0, D-1) do ( if area[now_mass + tate+1][yoko+1] = "." then ( mass := mass - 1 ) else skip ; if area[now_mass + tate+1][yoko+1] = '#' then ( break ) else skip ; if mass = 0 then ( toori := toori + 1 ; break ) else skip))) ; execute (toori)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def sumDivisorsOfDivisors(n): mp=dict() for j in range(2,mt.ceil(mt.sqrt(n))): count=0 while(n % j==0): n//=j count+=1 if(count): mp[j]=count if(n!=1): mp[n]=1 ans=1 for it in mp : pw=1 summ=0 for i in range(mp[it]+1,0,-1): summ+=(i*pw) pw*=it ans*=summ return ans n=10 print(sumDivisorsOfDivisors(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 10 ; execute (sumDivisorsOfDivisors(n))->display(); operation sumDivisorsOfDivisors(n : OclAny) : OclAny pre: true post: true activity: var mp : Map := (arguments ( )) ; for j : Integer.subrange(2, mt.ceil(mt.sqrt(n))-1) do ( var count : int := 0 ; while (n mod j = 0) do ( n := n div j ; count := count + 1) ; if (count) then ( mp[j+1] := count ) else skip) ; if (n /= 1) then ( mp[n+1] := 1 ) else skip ; var ans : int := 1 ; for it : mp->keys() do ( var pw : int := 1 ; var summ : int := 0 ; for i : Integer.subrange(0 + 1, mp[it+1] + 1)->reverse() do ( summ := summ + (i * pw) ; pw := pw * it) ; ans := ans * summ) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin from itertools import chain input=stdin.readline def flatten(listOfLists): return chain.from_iterable(listOfLists) def cut(k): global cards yellow=cards[: k] blue=cards[k :] cards=blue+yellow def shuffle(): global cards yellow=cards[: N] blue=cards[N :] temp=[[y,b]for y,b in zip(yellow,blue)] cards=list(flatten(temp)) cards=[] N=0 def main(args): global N global cards n=int(input()) N=n m=int(input()) cards=[x for x in range(1,(2*n)+1)] for _ in range(m): op=int(input()) if op==0 : shuffle() else : cut(op) print('\n'.join(map(str,cards))) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute cards : OclAny; attribute cards : OclAny; attribute N : OclAny; attribute cards : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; skip ; cards := Sequence{} ; var N : int := 0 ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation flatten(listOfLists : OclAny) : OclAny pre: true post: true activity: return chain.from_iterable(listOfLists); operation cut(k : OclAny) pre: true post: true activity: skip ; var yellow : OclAny := cards.subrange(1,k) ; var blue : OclAny := cards.subrange(k+1) ; cards := blue + yellow; operation shuffle() pre: true post: true activity: skip ; yellow := cards.subrange(1,N) ; blue := cards.subrange(N+1) ; var temp : Sequence := Integer.subrange(1, yellow->size())->collect( _indx | Sequence{yellow->at(_indx), blue->at(_indx)} )->select(_tuple | true)->collect(_tuple | let y : OclAny = _tuple->at(1) in let b : OclAny = _tuple->at(2) in (Sequence{y}->union(Sequence{ b }))) ; cards := (flatten(temp)); operation main(args : OclAny) pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; N := n ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; cards := Integer.subrange(1, (2 * n) + 1-1)->select(x | true)->collect(x | (x)) ; for _anon : Integer.subrange(0, m-1) do ( var op : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if op = 0 then ( shuffle() ) else ( cut(op) )) ; execute (StringLib.sumStringsWithSeparator(((cards)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=int(input()) card=[int(v)+1 for v in range(2*n)] for i in range(m): k=int(input()) if k==0 : next=[0]*2*n for x in range(n): next[x*2]=card[x] next[x*2+1]=card[x+n] card=next else : card=card[k :]+card[0 : k] for no in card : print(no) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var card : Sequence := Integer.subrange(0, 2 * n-1)->select(v | true)->collect(v | (("" + ((v)))->toInteger() + 1)) ; for i : Integer.subrange(0, m-1) do ( var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if k = 0 then ( var next : Sequence := MatrixLib.elementwiseMult(MatrixLib.elementwiseMult(Sequence{ 0 }, 2), n) ; for x : Integer.subrange(0, n-1) do ( [x * 2+1].next() := card[x+1] ; [x * 2 + 1+1].next() := card[x + n+1]) ; card := next ) else ( card := card.subrange(k+1) + card.subrange(0+1, k) )) ; for no : card do ( execute (no)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import chain n=int(input()) c=list(range(2*n)) for _ in[0]*int(input()): k=int(input()) c=c[k :]+c[: k]if k else list(chain.from_iterable(zip(c[: n],c[n :]))) for x in c : print(x+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : Sequence := (Integer.subrange(0, 2 * n-1)) ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; c := if k then c.subrange(k+1) + c.subrange(1,k) else (chain.from_iterable(Integer.subrange(1, c.subrange(1,n)->size())->collect( _indx | Sequence{c.subrange(1,n)->at(_indx), c.subrange(n+1)->at(_indx)} ))) endif) ; for x : c do ( execute (x + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def shuffle(l,k,n): if k : return l[k :]+l[: k] else : return[l[i+n*f]for i in range(n)for f in[0,1]] n=int(input()) l=[i+1 for i in range(2*n)] for _ in range(int(input())): l=shuffle(l,int(input()),n) [print(e)for e in l] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; l := Integer.subrange(0, 2 * n-1)->select(i | true)->collect(i | (i + 1)) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( l := shuffle(l, ("" + (((OclFile["System.in"]).readLine())))->toInteger(), n)) ; ; operation shuffle(l : OclAny, k : OclAny, n : OclAny) : OclAny pre: true post: true activity: if k then ( return l.subrange(k+1) + l.subrange(1,k) ) else ( return Integer.subrange(0, n-1)->select(i; f : Sequence{0}->union(Sequence{ 1 }) | true)->collect(i; f : Sequence{0}->union(Sequence{ 1 }) | (l[i + n * f+1])) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools H,W,K=map(int,input().split()) C=[] for i in range(H): C.append(input()) ans=0 for i in range(H+1): for j in range(W+1): for n in itertools.combinations(list(range(H)),i): for m in itertools.combinations(list(range(W)),j): count=0 for a in n : for b in m : if(C[a][b]=="#"): count+=1 if(count==K): ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var H : OclAny := null; var W : OclAny := null; var K : OclAny := null; Sequence{H,W,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var C : Sequence := Sequence{} ; for i : Integer.subrange(0, H-1) do ( execute (((OclFile["System.in"]).readLine()) : C)) ; var ans : int := 0 ; for i : Integer.subrange(0, H + 1-1) do ( for j : Integer.subrange(0, W + 1-1) do ( for n : itertools.combinations((Integer.subrange(0, H-1)), i) do ( for m : itertools.combinations((Integer.subrange(0, W-1)), j) do ( var count : int := 0 ; for a : n do ( for b : m do ( if (C[a+1][b+1] = "#") then ( count := count + 1 ) else skip)) ; if (count = K) then ( ans := ans + 1 ) else skip)))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- K=[] n=int(input()) num=2*n card=[i for i in range(1,num+1)] m=int(input()) for i in range(m): K.append(int(input())) for k in K : new_card=[] if k==0 : A=card[: n] B=card[n : num] for i in range(n): new_card.append(A[i]) new_card.append(B[i]) else : A=card[: k] B=card[k : num+1] new_card=B+A card=new_card for i in card : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var K : Sequence := Sequence{} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var num : int := 2 * n ; var card : Sequence := Integer.subrange(1, num + 1-1)->select(i | true)->collect(i | (i)) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, m-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : K)) ; for k : K do ( var new_card : Sequence := Sequence{} ; if k = 0 then ( var A : OclAny := card.subrange(1,n) ; var B : OclAny := card.subrange(n+1, num) ; for i : Integer.subrange(0, n-1) do ( execute ((A[i+1]) : new_card) ; execute ((B[i+1]) : new_card)) ) else ( A := card.subrange(1,k) ; B := card.subrange(k+1, num + 1) ; new_card := B + A ) ; card := new_card) ; for i : card do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=str(input()) ans='' for i in range(3): if n[i]=='1' : ans+='9' elif n[i]=='9' : ans+='1' print(int(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := ("" + (((OclFile["System.in"]).readLine()))) ; var ans : String := '' ; for i : Integer.subrange(0, 3-1) do ( if n[i+1] = '1' then ( ans := ans + '9' ) else (if n[i+1] = '9' then ( ans := ans + '1' ) else skip)) ; execute (("" + ((ans)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=sys.stdin.readline().rstrip() def main(n): n=n.replace('1','0').replace('9','1').replace('0','9') print(n) if __name__=='__main__' : main(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := sys.stdin.readLine().rstrip() ; skip ; if __name__ = '__main__' then ( main(n) ) else skip; operation main(n : OclAny) pre: true post: true activity: n := n.replace('1', '0').replace('9', '1').replace('0', '9') ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d={'1' : '9','9' : '1'} print(''.join([d[c]for c in input()])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : Map := Map{ '1' |-> '9' }->union(Map{ '9' |-> '1' }) ; execute (StringLib.sumStringsWithSeparator(((OclFile["System.in"]).readLine()->select(c | true)->collect(c | (d[c+1]))), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(1110-int(input())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (1110 - ("" + (((OclFile["System.in"]).readLine())))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M,D=map(int,input().split()) input_list=[["."]*M]*N for i in range(N): input_list[i]=list(input()) area_list=[] for i in range(N): if M=D : area_list.append(tmp_count) tmp_count=0 if tmp_count>=D : area_list.append(tmp_count) for j in range(M): if N=D : area_list.append(tmp_count) tmp_count=0 if tmp_count>=D : area_list.append(tmp_count) sa_list=[D-1]*len(area_list) add_list=[x-y for(x,y)in zip(area_list,sa_list)] print(sum(add_list)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; var D : OclAny := null; Sequence{N,M,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var input_list : Sequence := MatrixLib.elementwiseMult(Sequence{ MatrixLib.elementwiseMult(Sequence{ "." }, M) }, N) ; for i : Integer.subrange(0, N-1) do ( input_list[i+1] := ((OclFile["System.in"]).readLine())->characters()) ; var area_list : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( if (M->compareTo(D)) < 0 then ( break ) else skip ; var tmp_count : int := 0 ; for j : Integer.subrange(0, M-1) do ( if input_list[i+1][j+1] = "." then ( tmp_count := tmp_count + 1 ) else ( if (tmp_count->compareTo(D)) >= 0 then ( execute ((tmp_count) : area_list) ) else skip ; tmp_count := 0 )) ; if (tmp_count->compareTo(D)) >= 0 then ( execute ((tmp_count) : area_list) ) else skip) ; for j : Integer.subrange(0, M-1) do ( if (N->compareTo(D)) < 0 then ( break ) else skip ; tmp_count := 0 ; for i : Integer.subrange(0, N-1) do ( if input_list[i+1][j+1] = "." then ( tmp_count := tmp_count + 1 ) else ( if (tmp_count->compareTo(D)) >= 0 then ( execute ((tmp_count) : area_list) ) else skip ; tmp_count := 0 )) ; if (tmp_count->compareTo(D)) >= 0 then ( execute ((tmp_count) : area_list) ) else skip) ; var sa_list : Sequence := MatrixLib.elementwiseMult(Sequence{ D - 1 }, (area_list)->size()) ; var add_list : Sequence := Integer.subrange(1, area_list->size())->collect( _indx | Sequence{area_list->at(_indx), sa_list->at(_indx)} )->select(Sequence{x, y} | true)->collect(Sequence{x, y} | (x - y)) ; execute ((add_list)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() swap_n=[] for i in n : if i=="1" : i="9" swap_n.append(i) elif i=="9" : i="1" swap_n.append(i) else : swap_n.append(i) num="".join(swap_n) print(int(num)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var swap_n : Sequence := Sequence{} ; for i : n->characters() do ( if i = "1" then ( var i : String := "9" ; execute ((i) : swap_n) ) else (if i = "9" then ( i := "1" ; execute ((i) : swap_n) ) else ( execute ((i) : swap_n) ) ) ) ; var num : String := StringLib.sumStringsWithSeparator((swap_n), "") ; execute (("" + ((num)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,data): self.data=data self.left=None self.right=None def newNode(data): node=Node(0) node.data=data node.left=node.right=None return(node) result=-1 def minPathSumUtil(root): global result if(root==None): return 0 if(root.left==None and root.right==None): return root.data ls=minPathSumUtil(root.left) rs=minPathSumUtil(root.right) if(root.left!=None and root.right!=None): result=min(result,ls+rs+root.data) return min(ls+root.data,rs+root.data) if(root.left==None): return rs+root.data else : return ls+root.data def minPathSum(root): global result result=9999999 minPathSumUtil(root) return result root=newNode(4) root.left=newNode(5) root.right=newNode(-6) root.left.left=newNode(2) root.left.right=newNode(-3) root.right.left=newNode(1) root.right.right=newNode(8) print(minPathSum(root)) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.left := null ; self.right := null; return self; } class FromPython { attribute result : OclAny; attribute result : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; var result : int := -1 ; skip ; skip ; root := newNode(4) ; root.left := newNode(5) ; root.right := newNode(-6) ; root.left.left := newNode(2) ; root.left.right := newNode(-3) ; root.right.left := newNode(1) ; root.right.right := newNode(8) ; execute (minPathSum(root))->display(); operation newNode(data : OclAny) : OclAny pre: true post: true activity: var node : Node := (Node.newNode()).initialise(0) ; node.data := data ; node.left := null; var node.right : OclAny := null ; return (node); operation minPathSumUtil(root : OclAny) : OclAny pre: true post: true activity: skip ; if (root = null) then ( return 0 ) else skip ; if (root.left = null & root.right = null) then ( return root.data ) else skip ; var ls : OclAny := minPathSumUtil(root.left) ; var rs : OclAny := minPathSumUtil(root.right) ; if (root.left /= null & root.right /= null) then ( result := Set{result, ls + rs + root.data}->min() ; return Set{ls + root.data, rs + root.data}->min() ) else skip ; if (root.left = null) then ( return rs + root.data ) else ( return ls + root.data ); operation minPathSum(root : OclAny) : OclAny pre: true post: true activity: skip ; result := 9999999 ; minPathSumUtil(root) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairs(a,n): mp=dict.fromkeys(a,0) for i in range(n): mp[a[i]]+=1 a.sort(reverse=True) count=0 for i in range(n): if(mp[a[i]]<1): continue cur=1 while(cur<=a[i]): cur=cur<<1 if(cur-a[i]in mp.keys()): if(cur-a[i]==a[i]and mp[a[i]]==1): continue count+=1 mp[cur-a[i]]-=1 mp[a[i]]-=1 return count if __name__=="__main__" : a=[3,11,14,5,13] n=len(a) print(countPairs(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{3}->union(Sequence{11}->union(Sequence{14}->union(Sequence{5}->union(Sequence{ 13 })))) ; n := (a)->size() ; execute (countPairs(a, n))->display() ) else skip; operation countPairs(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var mp : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))) ; for i : Integer.subrange(0, n-1) do ( mp[a[i+1]+1] := mp[a[i+1]+1] + 1) ; a := a->sort() ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (mp[a[i+1]+1] < 1) then ( continue ) else skip ; var cur : int := 1 ; while ((cur->compareTo(a[i+1])) <= 0) do ( cur := cur * (2->pow(1))) ; if ((mp.keys())->includes(cur - a[i+1])) then ( if (cur - a[i+1] = a[i+1] & mp[a[i+1]+1] = 1) then ( continue ) else skip ; count := count + 1 ; mp[cur - a[i+1]+1] := mp[cur - a[i+1]+1] - 1 ; mp[a[i+1]+1] := mp[a[i+1]+1] - 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(arr,N,K): unique=dict() for i in range(N): unique[arr[i]]=1 if len(unique)==K : return True return False arr=[1,1,2,3] N=len(arr) K=3 if(check(arr,N,K)==True): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))) ; N := (arr)->size() ; K := 3 ; if (check(arr, N, K) = true) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation check(arr : OclAny, N : OclAny, K : OclAny) : OclAny pre: true post: true activity: var unique : Map := (arguments ( )) ; for i : Integer.subrange(0, N-1) do ( unique[arr[i+1]+1] := 1) ; if (unique)->size() = K then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter,defaultdict,deque from heapq import heappop,heappush from bisect import bisect_left,bisect_right import sys,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod=10**9+7 INF=float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int,sys.stdin.readline().split())) h,w,k=inpl() s=[input()for _ in range(h)] bl=sum(1 if x=='#' else 0 for i in range(h)for x in s[i]) res=0 for yy in itertools.product([0,1],repeat=h): for xx in itertools.product([0,1],repeat=w): cnt=0 seen=set() for i,y in enumerate(yy): if y : for j in range(w): if(i,j)in seen : continue seen.add((i,j)) if s[i][j]=='#' : cnt+=1 for j,x in enumerate(xx): if x : for i in range(h): if(i,j)in seen : continue seen.add((i,j)) if s[i][j]=='#' : cnt+=1 if bl-cnt==k : res+=1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; var mod : double := (10)->pow(9) + 7 ; var INF : double := ("" + (('inf')))->toReal() ; skip ; skip ; var h : OclAny := null; var w : OclAny := null; var k : OclAny := null; Sequence{h,w,k} := inpl() ; var s : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var bl : OclAny := ((argument (test (logical_test (comparison (expr (atom (number (integer 1)))))) if (logical_test (comparison (comparison (expr (atom (name x)))) == (comparison (expr (atom '#'))))) else (test (logical_test (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name h)))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))))->sum() ; var res : int := 0 ; for yy : itertools.product(Sequence{0}->union(Sequence{ 1 }), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (name h)))))))) do ( for xx : itertools.product(Sequence{0}->union(Sequence{ 1 }), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (name w)))))))) do ( var cnt : int := 0 ; var seen : Set := Set{}->union(()) ; for _tuple : Integer.subrange(1, (yy)->size())->collect( _indx | Sequence{_indx-1, (yy)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if y then ( for j : Integer.subrange(0, w-1) do ( if (seen)->includes(Sequence{i, j}) then ( continue ) else skip ; execute ((Sequence{i, j}) : seen) ; if s[i+1][j+1] = '#' then ( cnt := cnt + 1 ) else skip) ) else skip) ; for _tuple : Integer.subrange(1, (xx)->size())->collect( _indx | Sequence{_indx-1, (xx)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); if x then ( for i : Integer.subrange(0, h-1) do ( if (seen)->includes(Sequence{i, j}) then ( continue ) else skip ; execute ((Sequence{i, j}) : seen) ; if s[i+1][j+1] = '#' then ( cnt := cnt + 1 ) else skip) ) else skip) ; if bl - cnt = k then ( res := res + 1 ) else skip)) ; execute (res)->display(); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inpl() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): dum=input() inp=input().split() xa=int(inp[0]) ya=int(inp[1]) inp=input().split() xb=int(inp[0]) yb=int(inp[1]) inp=input().split() xf=int(inp[0]) yf=int(inp[1]) nrm=abs(xb-xa)+abs(yb-ya) if(xa!=xb or xb!=xf)and(ya!=yb or yb!=yf): print(nrm) elif(xa==xb and xb==xf): if yatoInteger() ; for _anon : Integer.subrange(0, t-1) do ( var dum : String := (OclFile["System.in"]).readLine() ; var inp : OclAny := input().split() ; var xa : int := ("" + ((inp->first())))->toInteger() ; var ya : int := ("" + ((inp[1+1])))->toInteger() ; inp := input().split() ; var xb : int := ("" + ((inp->first())))->toInteger() ; var yb : int := ("" + ((inp[1+1])))->toInteger() ; inp := input().split() ; var xf : int := ("" + ((inp->first())))->toInteger() ; var yf : int := ("" + ((inp[1+1])))->toInteger() ; var nrm : double := (xb - xa)->abs() + (yb - ya)->abs() ; if (xa /= xb or xb /= xf) & (ya /= yb or yb /= yf) then ( execute (nrm)->display() ) else (if (xa = xb & xb = xf) then ( if (ya->compareTo(yf)) < 0 & (yf < yb) or (yb->compareTo(yf)) < 0 & (yf < ya) then ( nrm := nrm + 2 ) else skip ; execute (nrm)->display() ) else ( if (xa->compareTo(xf)) < 0 & (xf < xb) or (xb->compareTo(xf)) < 0 & (xf < xa) then ( nrm := nrm + 2 ) else skip ; execute (nrm)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : input() li1=list(map(int,input().strip().split())) li2=list(map(int,input().strip().split())) li3=list(map(int,input().strip().split())) xa,ya,xb,yb,xf,yf=li1[0],li1[1],li2[0],li2[1],li3[0],li3[1] ans=0 if ya==yb and yf==ya : if(xa-xb)*(xf-xb)>0 : if abs(xa-xb)>abs(xf-xb): ans=2 if xa==xb and xf==xa : if(ya-yb)*(yf-yb)>0 : if abs(ya-yb)>abs(yf-yb): ans=2 ans1=abs(xa-xb)+abs(ya-yb) ans+=ans1 print(ans) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( input() ; var li1 : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var li2 : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var li3 : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var xa : OclAny := null; var ya : OclAny := null; var xb : OclAny := null; var yb : OclAny := null; var xf : OclAny := null; var yf : OclAny := null; Sequence{xa,ya,xb,yb,xf,yf} := Sequence{li1->first(),li1[1+1],li2->first(),li2[1+1],li3->first(),li3[1+1]} ; var ans : int := 0 ; if ya = yb & yf = ya then ( if (xa - xb) * (xf - xb) > 0 then ( if ((xa - xb)->abs()->compareTo((xf - xb)->abs())) > 0 then ( ans := 2 ) else skip ) else skip ) else skip ; if xa = xb & xf = xa then ( if (ya - yb) * (yf - yb) > 0 then ( if ((ya - yb)->abs()->compareTo((yf - yb)->abs())) > 0 then ( ans := 2 ) else skip ) else skip ) else skip ; var ans1 : double := (xa - xb)->abs() + (ya - yb)->abs() ; ans := ans + ans1 ; execute (ans)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(a,b,f,c=0): if f[0]==a[0]and f[0]==b[0]: c+=2*int(min(a[1],b[1])collect( _x | (OclType["int"])->apply(_x) ))) ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( input() ; execute (f(inp->apply(), inp->apply(), inp->apply()))->display() ; t := t - 1); operation f(a : OclAny, b : OclAny, f : OclAny, c : int) : OclAny pre: true post: true activity: if c->oclIsUndefined() then c := 0 else skip; if f->first() = a->first() & f->first() = b->first() then ( c := c + 2 * ("" + (((Set{a[1+1], b[1+1]}->min()->compareTo(f[1+1])) < 0 & (f[1+1]->compareTo(Set{a[1+1], b[1+1]}->max())) < 0)))->toInteger() ) else ( c := c + (a->first() - b->first())->abs() ) ; if f[1+1] = a[1+1] & f[1+1] = b[1+1] then ( c := c + 2 * ("" + (((Set{a->first(), b->first()}->min()->compareTo(f->first())) < 0 & (f->first()->compareTo(Set{a->first(), b->first()}->max())) < 0)))->toInteger() ) else ( c := c + (a[1+1] - b[1+1])->abs() ) ; return c; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a=input() x1,y1=map(int,input().split()) x3,y3=map(int,input().split()) x2,y2=map(int,input().split()) b=abs(x3-x1)+abs(y3-y1) if(x1==x2==x3 and min(y1,y3)toInteger()-1) do ( var a : String := (OclFile["System.in"]).readLine() ; var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x3 : OclAny := null; var y3 : OclAny := null; Sequence{x3,y3} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : double := (x3 - x1)->abs() + (y3 - y1)->abs() ; if (x1 = x2 & (x2 == x3) & (Set{y1, y3}->min()->compareTo(y2)) < 0 & (y2 < Set{y1, y3}->max())) or (y1 = y2 & (y2 == y3) & (Set{x1, x3}->min()->compareTo(x2)) < 0 & (x2 < Set{x1, x3}->max())) then ( b := b + 2 ) else skip ; execute (b)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): p=input() a,b=map(int,input().split()) c,d=map(int,input().split()) e,f=map(int,input().split()) s=abs(a-c)+abs(b-d) if((a==c==e)and(bf>d))or((b==f==d)and(ae>c)): s=s+2 print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var p : String := (OclFile["System.in"]).readLine() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var e : OclAny := null; var f : OclAny := null; Sequence{e,f} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : double := (a - c)->abs() + (b - d)->abs() ; if ((a = c & (c == e)) & ((b->compareTo(f)) < 0 & (f < d) or (b->compareTo(f)) > 0 & (f > d))) or ((b = f & (f == d)) & ((a->compareTo(e)) < 0 & (e < c) or (a->compareTo(e)) > 0 & (e > c))) then ( s := s + 2 ) else skip ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(): readline=sys.stdin.buffer.readline write=sys.stdout.buffer.write M,N=map(int,readline().split()) P=[list(map(float,readline().split()))+[0]for i in range(M)] M2=(1<collect( _x | (OclType["int"])->apply(_x) ) ; var P : Sequence := Integer.subrange(0, M-1)->select(i | true)->collect(i | (((readline().split())->collect( _x | (OclType["double"])->apply(_x) ))->union(Sequence{ 0 }))) ; var M2 : int := (1 * (2->pow(M))) ; var dp : Sequence := Integer.subrange(0, M2-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)))) ; dp->first()[N+1] := 1 ; for state : Integer.subrange(1, M2-1) do ( var dps : OclAny := dp[state+1] ; for k : Integer.subrange(0, M-1) do ( if MathLib.bitwiseAnd(state, (1 * (2->pow(k)))) = 0 then ( continue ) else skip ; var pk : OclAny := P[k+1] ; var dpk : OclAny := dp[MathLib.bitwiseXor(state, (1 * (2->pow(k))))+1] ; var s : int := 0 ; for i : Integer.subrange(-1 + 1, N)->reverse() do ( s := s + dpk[i+1] * (1 - pk[i+1]) ; dps[i+1] := Set{dps[i+1], s}->max() ; s := s * pk[i - 1+1]))) ; write((atom b "%.16f\n") mod dp[M2 - 1+1]->first()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(area,n,m,d): ans=0 for y in range(n): for x in range(m): horizontal=area[y][x : x+d] ans+='.'*d in horizontal vertical=''.join([area[yy][x]for yy in range(y,n)])[: d] ans+='.'*d in vertical return ans def main(args): n,m,d=map(int,input().split()) area=[input()for _ in range(n)] ans=solve(area,n,m,d) print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(area : OclAny, n : OclAny, m : OclAny, d : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for y : Integer.subrange(0, n-1) do ( for x : Integer.subrange(0, m-1) do ( var horizontal : OclAny := area[y+1].subrange(x+1, x + d) ; ans := ans + (horizontal)->includes(StringLib.nCopies('.', d)) ; var vertical : OclAny := ''.join(Integer.subrange(y, n-1)->select(yy | true)->collect(yy | (area[yy+1][x+1]))).subrange(1,d) ; ans := ans + (vertical)->includes(StringLib.nCopies('.', d)))) ; return ans; operation main(args : OclAny) pre: true post: true activity: Sequence{n,m,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; area := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; ans := solve(area, n, m, d) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=[1,5,10,20,100] c=0 for _ in m[: :-1]: c+=n//_ n %=_ print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : Sequence := Sequence{1}->union(Sequence{5}->union(Sequence{10}->union(Sequence{20}->union(Sequence{ 100 })))) ; var c : int := 0 ; for _anon : m(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( c := c + n div _anon ; n := n mod _anon) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cda(pul,kup): global count count+=pul//kup return pul % kup n=int(input()) count=0 n=cda(n,100) n=cda(n,20) n=cda(n,10) n=cda(n,5) n=cda(n,1) print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute count : OclAny; operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; count := 0 ; n := cda(n, 100) ; n := cda(n, 20) ; n := cda(n, 10) ; n := cda(n, 5) ; n := cda(n, 1) ; execute (count)->display(); operation cda(pul : OclAny, kup : OclAny) : OclAny pre: true post: true activity: skip ; count := count + pul div kup ; return pul mod kup; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) C=0 while(n-100>=0): C=C+(n//100) n=n-(100*(n//100)) while(n-20>=0): C=C+(n//20) n=n-(20*(n//20)) while(n-10>=0): C=C+(n//10) n=n-(10*(n//10)) while(n-5>=0): C=C+(n//5) n=n-(5*(n//5)) C=C+(n//1) print(C) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var C : int := 0 ; while (n - 100 >= 0) do ( C := C + (n div 100) ; n := n - (100 * (n div 100))) ; while (n - 20 >= 0) do ( C := C + (n div 20) ; n := n - (20 * (n div 20))) ; while (n - 10 >= 0) do ( C := C + (n div 10) ; n := n - (10 * (n div 10))) ; while (n - 5 >= 0) do ( C := C + (n div 5) ; n := n - (5 * (n div 5))) ; C := C + (n div 1) ; execute (C)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools import copy H,W,K=map(int,input().split()) graph=[] for i in range(H): graph.append(list(input())) b=[1,0] Bit=list(itertools.product(b,repeat=H+W)) ans=0 for i in range(len(Bit)): tmp=copy.deepcopy(graph) cnt=0 for h in range(H): if Bit[i][h]==1 : for j in range(W): tmp[h][j]="." for w in range(H,H+W): if Bit[i][w]==1 : for j in range(H): tmp[j][w-H]="." for j in range(H): cnt+=tmp[j].count("#") if cnt==K : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var H : OclAny := null; var W : OclAny := null; var K : OclAny := null; Sequence{H,W,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var graph : Sequence := Sequence{} ; for i : Integer.subrange(0, H-1) do ( execute ((((OclFile["System.in"]).readLine())->characters()) : graph)) ; var b : Sequence := Sequence{1}->union(Sequence{ 0 }) ; var Bit : Sequence := (itertools.product(b, (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (expr (atom (name H))) + (expr (atom (name W)))))))))) ; var ans : int := 0 ; for i : Integer.subrange(0, (Bit)->size()-1) do ( var tmp : OclAny := copy.deepcopy(graph) ; var cnt : int := 0 ; for h : Integer.subrange(0, H-1) do ( if Bit[i+1][h+1] = 1 then ( for j : Integer.subrange(0, W-1) do ( tmp[h+1][j+1] := ".") ) else skip) ; for w : Integer.subrange(H, H + W-1) do ( if Bit[i+1][w+1] = 1 then ( for j : Integer.subrange(0, H-1) do ( tmp[j+1][w - H+1] := ".") ) else skip) ; for j : Integer.subrange(0, H-1) do ( cnt := cnt + tmp[j+1]->count("#")) ; if cnt = K then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) billCompleted=False bills=[1,5,10,20,100] i=4 billCount=0 while not billCompleted : temp=bills[i] billCount+=n//temp n=n % temp i-=1 if n==0 : billCompleted=True break print(billCount) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var billCompleted : boolean := false ; var bills : Sequence := Sequence{1}->union(Sequence{5}->union(Sequence{10}->union(Sequence{20}->union(Sequence{ 100 })))) ; var i : int := 4 ; var billCount : int := 0 ; while not(billCompleted) do ( var temp : OclAny := bills[i+1] ; billCount := billCount + n div temp ; n := n mod temp ; i := i - 1 ; if n = 0 then ( billCompleted := true ; break ) else skip) ; execute (billCount)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) q1=n//100 r1=n % 100 q2=r1//20 r2=r1 % 20 q3=r2//10 r3=r2 % 10 q4=r3//5 r4=r3 % 5 print(q1+q2+q3+q4+r4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var q1 : int := n div 100 ; var r1 : int := n mod 100 ; var q2 : int := r1 div 20 ; var r2 : int := r1 mod 20 ; var q3 : int := r2 div 10 ; var r3 : int := r2 mod 10 ; var q4 : int := r3 div 5 ; var r4 : int := r3 mod 5 ; execute (q1 + q2 + q3 + q4 + r4)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin from sys import setrecursionlimit from collections import Counter,deque,defaultdict from math import floor,ceil from bisect import bisect_left,bisect_right from itertools import combinations setrecursionlimit(100000) INF=int(1e10) MOD=int(1e9+7) def main(): from builtins import int,map N,M,K=map(int,input().split()) A=list(map(int,input().split())) B=list(map(int,input().split())) cA=[0]*(N+1) cB=[0]*(M+1) for k in range(N): cA[k+1]=cA[k]+A[k] for k in range(M): cB[k+1]=cB[k]+B[k] ans=-1 for a in range(N+1): rem=K-cA[a] if rem<0 : break bli=bisect_left(cB,rem) bri=bisect_right(cB,rem) ans_a=None if bli==bri : ans_a=a+bli-1 else : ans_a=a+bli ans=max(ans,ans_a) print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; setrecursionlimit(100000) ; var INF : int := ("" + ((("1e10")->toReal())))->toInteger() ; var MOD : int := ("" + ((("1e9")->toReal() + 7)))->toInteger() ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; var K : OclAny := null; Sequence{N,M,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var B : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cA : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; var cB : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (M + 1)) ; for k : Integer.subrange(0, N-1) do ( cA[k + 1+1] := cA[k+1] + A[k+1]) ; for k : Integer.subrange(0, M-1) do ( cB[k + 1+1] := cB[k+1] + B[k+1]) ; var ans : int := -1 ; for a : Integer.subrange(0, N + 1-1) do ( var rem : double := K - cA[a+1] ; if rem < 0 then ( break ) else skip ; var bli : OclAny := bisect_left(cB, rem) ; var bri : OclAny := bisect_right(cB, rem) ; var ans_a : OclAny := null ; if bli = bri then ( ans_a := a + bli - 1 ) else ( ans_a := a + bli ) ; ans := Set{ans, ans_a}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split(" ")) a=[0]+list(map(int,input().split(" "))) b=[0]+list(map(int,input().split(" "))) for i in range(1,n+1): a[i]+=a[i-1] for i in range(1,m+1): b[i]+=b[i-1] j,mx=m,0 for i in range(n+1): if a[i]>k : break while(b[j]>k-a[i]): j-=1 if(i+j>mx): mx=i+j print(mx) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{ 0 }->union(((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ))) ; var b : Sequence := Sequence{ 0 }->union(((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ))) ; for i : Integer.subrange(1, n + 1-1) do ( a[i+1] := a[i+1] + a[i - 1+1]) ; for i : Integer.subrange(1, m + 1-1) do ( b[i+1] := b[i+1] + b[i - 1+1]) ; var j : OclAny := null; var mx : OclAny := null; Sequence{j,mx} := Sequence{m,0} ; for i : Integer.subrange(0, n + 1-1) do ( if (a[i+1]->compareTo(k)) > 0 then ( break ) else skip ; while ((b[j+1]->compareTo(k - a[i+1])) > 0) do ( j := j - 1) ; if ((i + j->compareTo(mx)) > 0) then ( var mx : OclAny := i + j ) else skip) ; execute (mx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import itertools import collections import heapq import re import numpy as np from functools import reduce rr=lambda : sys.stdin.readline().rstrip() rs=lambda : sys.stdin.readline().split() ri=lambda : int(sys.stdin.readline()) rm=lambda : map(int,sys.stdin.readline().split()) rl=lambda : list(map(int,sys.stdin.readline().split())) inf=float('inf') mod=10**9+7 n,m,k=rm() a=rl() b=list(itertools.accumulate(rl())) if a[0]>k : ans=0 else : left=0 right=m while right-left>1 : j=(left+right)//2 if b[j]>k : right=j else : left=j ans=left+1 t=0 b0=b[0] for cnt,i in enumerate(a,1): t+=i if t>k : break if b0>k-t : ans=max(ans,cnt) continue left=0 right=m while right-left>1 : j=(left+right)//2 if b[j]>k-t : right=j else : left=j ans=max(ans,cnt+left+1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var rr : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var rs : Function := lambda $$ : OclAny in (sys.stdin.readLine().split()) ; var ri : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var rm : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var rl : Function := lambda $$ : OclAny in (((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := rm->apply() ; var a : OclAny := rl->apply() ; var b : Sequence := (itertools.accumulate(rl->apply())) ; if (a->first()->compareTo(k)) > 0 then ( var ans : int := 0 ) else ( var left : int := 0 ; var right : OclAny := m ; while right - left > 1 do ( var j : int := (left + right) div 2 ; if (b[j+1]->compareTo(k)) > 0 then ( right := j ) else ( left := j )) ; ans := left + 1 ) ; var t : int := 0 ; var b0 : OclAny := b->first() ; for _tuple : Integer.subrange(1, (a, 1)->size())->collect( _indx | Sequence{_indx-1, (a, 1)->at(_indx)} ) do (var _indx : int := 1; var cnt : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); t := t + i ; if (t->compareTo(k)) > 0 then ( break ) else skip ; if (b0->compareTo(k - t)) > 0 then ( ans := Set{ans, cnt}->max() ; continue ) else skip ; left := 0 ; right := m ; while right - left > 1 do ( j := (left + right) div 2 ; if (b[j+1]->compareTo(k - t)) > 0 then ( right := j ) else ( left := j )) ; ans := Set{ans, cnt + left + 1}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): N,M,K=[int(i)for i in input().split()] A=[int(i)for i in input().split()] cumulative_A=[0]*(len(A)+1) for i in range(1,len(cumulative_A)): cumulative_A[i]=cumulative_A[i-1]+A[i-1] B=[int(i)for i in input().split()] cumulative_B=[0]*(len(B)+1) for i in range(1,len(cumulative_B)): cumulative_B[i]=cumulative_B[i-1]+B[i-1] max_j=len(cumulative_B)-1 ans=0 for i in range(len(cumulative_A)): time_A=cumulative_A[i] time_B=K-time_A is_found=False for j in reversed(range(max_j+1)): if cumulative_B[j]<=time_B : is_found=True break if is_found : cnt=i+j ans=max(cnt,ans) max_j=j print(ans) if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( solve() ) else skip; operation solve() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; var K : OclAny := null; Sequence{N,M,K} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var A : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var cumulative_A : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((A)->size() + 1)) ; for i : Integer.subrange(1, (cumulative_A)->size()-1) do ( cumulative_A[i+1] := cumulative_A[i - 1+1] + A[i - 1+1]) ; var B : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var cumulative_B : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((B)->size() + 1)) ; for i : Integer.subrange(1, (cumulative_B)->size()-1) do ( cumulative_B[i+1] := cumulative_B[i - 1+1] + B[i - 1+1]) ; var max_j : double := (cumulative_B)->size() - 1 ; var ans : int := 0 ; for i : Integer.subrange(0, (cumulative_A)->size()-1) do ( var time_A : OclAny := cumulative_A[i+1] ; var time_B : double := K - time_A ; var is_found : boolean := false ; for j : (Integer.subrange(0, max_j + 1-1))->reverse() do ( if (cumulative_B[j+1]->compareTo(time_B)) <= 0 then ( is_found := true ; break ) else skip) ; if is_found then ( var cnt : OclAny := i + j ; ans := Set{cnt, ans}->max() ) else skip ; max_j := j) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate from bisect import bisect_left,bisect n,m,k=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) ruia=[0] ruia.extend(list(accumulate(a))) ruib=list(accumulate(b)) ans=0 for i in range(n+1): nokori=k-ruia[i] if nokori<0 : break yomeru=bisect(ruib,nokori) ans=max(ans,i+yomeru) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ruia : Sequence := Sequence{ 0 } ; ruia := ruia->union((accumulate(a))) ; var ruib : Sequence := (accumulate(b)) ; var ans : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( var nokori : double := k - ruia[i+1] ; if nokori < 0 then ( break ) else skip ; var yomeru : OclAny := bisect(ruib, nokori) ; ans := Set{ans, i + yomeru}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N,M,D=map(int,input().split()) s,X,Y=[],[],[] for _ in N*[0]: s.append(input()) X.append(M*[0]) Y.append(M*[0]) for y in range(0,N,1): for x in range(M-1,-1,-1): if(s[y][x]!='#'): X[y][x]+=1 if(s[y][x]!='#' and x+1=D): ans+=1 if(Y[y][x]>=D): ans+=1 print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; var D : OclAny := null; Sequence{N,M,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := null; var X : OclAny := null; var Y : OclAny := null; Sequence{s,X,Y} := Sequence{Sequence{},Sequence{},Sequence{}} ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, N) do ( execute (((OclFile["System.in"]).readLine()) : s) ; execute ((MatrixLib.elementwiseMult(Sequence{ 0 }, M)) : X) ; execute ((MatrixLib.elementwiseMult(Sequence{ 0 }, M)) : Y)) ; for y : Integer.subrange(0, N-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( for x : Integer.subrange(-1 + 1, M - 1)->reverse() do ( if (s[y+1][x+1] /= '#') then ( X[y+1][x+1] := X[y+1][x+1] + 1 ) else skip ; if (s[y+1][x+1] /= '#' & (x + 1->compareTo(M)) < 0) then ( X[y+1][x+1] := X[y+1][x + 1+1] + 1 ) else skip)) ; for y : Integer.subrange(-1 + 1, N - 1)->reverse() do ( for x : Integer.subrange(0, M-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (s[y+1][x+1] /= '#') then ( Y[y+1][x+1] := Y[y+1][x+1] + 1 ) else skip ; if (s[y+1][x+1] /= '#' & (y + 1->compareTo(N)) < 0) then ( Y[y+1][x+1] := Y[y + 1+1][x+1] + 1 ) else skip)) ; var ans : int := 0 ; for y : Integer.subrange(0, N-1) do ( for x : Integer.subrange(0, M-1) do ( if ((X[y+1][x+1]->compareTo(D)) >= 0) then ( ans := ans + 1 ) else skip ; if ((Y[y+1][x+1]->compareTo(D)) >= 0) then ( ans := ans + 1 ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNDigitNumsUtil(n,sum,out,index): if(index>n or sum<0): return f="" if(index==n): if(sum==0): out[index]="" for i in out : f=f+i print(f,end=" ") return for i in range(10): out[index]=chr(i+ord('0')) findNDigitNumsUtil(n,sum-i,out,index+1) def findNDigitNums(n,sum): out=[False]*(n+1) for i in range(1,10): out[0]=chr(i+ord('0')) findNDigitNumsUtil(n,sum-i,out,1) if __name__=="__main__" : n=2 sum=3 findNDigitNums(n,sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 2 ; sum := 3 ; findNDigitNums(n, sum) ) else skip; operation findNDigitNumsUtil(n : OclAny, sum : OclAny, out : OclAny, index : OclAny) pre: true post: true activity: if ((index->compareTo(n)) > 0 or sum < 0) then ( return ) else skip ; var f : String := "" ; if (index = n) then ( if (sum = 0) then ( out[index+1] := "" ; for i : out do ( f := f + i) ; execute (f)->display() ) else skip ; return ) else skip ; for i : Integer.subrange(0, 10-1) do ( out[index+1] := (i + ('0')->char2byte())->byte2char() ; findNDigitNumsUtil(n, sum - i, out, index + 1)); operation findNDigitNums(n : OclAny, sum : OclAny) pre: true post: true activity: out := MatrixLib.elementwiseMult(Sequence{ false }, (n + 1)) ; for i : Integer.subrange(1, 10-1) do ( out->first() := (i + ('0')->char2byte())->byte2char() ; findNDigitNumsUtil(n, sum - i, out, 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import string import re def read_input(input_path=None): if input_path is None : f=sys.stdin else : f=open(input_path,'r') return[f.readline().rstrip()] def conv2value(text): sub_text=text.split('.') value=0 if len(sub_text)>1 and len(sub_text[-1])==2 : value+=int(sub_text[-1]) sub_text=sub_text[:-1] if len(sub_text)>0 : value+=int(''.join(sub_text))*100 return value def conv2string(value): penny=value % 100 if penny>0 : return f"{value//100:,}".replace(',','.')+f".{penny:02d}" return f"{value//100:,}".replace(',','.') def sol(s): notes=re.findall(r"[abcdefghijklmnopqrstuvwxyz]+",s) amounts=re.findall(r"[0-9.]+",s) total=conv2string(sum([conv2value(i)for i in amounts])) return[total] def solve(input_path=None): return sol(*read_input(input_path)) def main(): for line in sol(*read_input()): print(f"{line}") if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation read_input(input_path : OclAny) : OclAny pre: true post: true activity: if input_path->oclIsUndefined() then input_path := null else skip; if input_path <>= null then ( var f : OclFile := OclFile["System.in"] ) else ( f := OclFile.newOclFile_Write(OclFile.newOclFile(input_path)) ) ; return Sequence{ f.readLine().rstrip() }; operation conv2value(text : OclAny) : OclAny pre: true post: true activity: var sub_text : OclAny := text.split('.') ; var value : int := 0 ; if (sub_text)->size() > 1 & (sub_text->last())->size() = 2 then ( value := value + ("" + ((sub_text->last())))->toInteger() ; sub_text := sub_text->front() ) else skip ; if (sub_text)->size() > 0 then ( value := value + ("" + ((StringLib.sumStringsWithSeparator((sub_text), ''))))->toInteger() * 100 ) else skip ; return value; operation conv2string(value : OclAny) : OclAny pre: true post: true activity: var penny : int := value mod 100 ; if penny > 0 then ( return StringLib.formattedString("{value//100:,}").replace(',', '.') + StringLib.formattedString(".{penny:02d}") ) else skip ; return StringLib.formattedString("{value//100:,}").replace(',', '.'); operation sol(s : OclAny) : OclAny pre: true post: true activity: var notes : Sequence(String) := (s)->allMatches(StringLib.rawString("[abcdefghijklmnopqrstuvwxyz]+")) ; var amounts : Sequence(String) := (s)->allMatches(StringLib.rawString("[0-9.]+")) ; var total : OclAny := conv2string((amounts->select(i | true)->collect(i | (conv2value(i))))->sum()) ; return Sequence{ total }; operation solve(input_path : OclAny) : OclAny pre: true post: true activity: if input_path->oclIsUndefined() then input_path := null else skip; return sol((argument * (test (logical_test (comparison (expr (atom (name read_input)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input_path)))))))) ))))))))); operation main() pre: true post: true activity: for line : sol((argument * (test (logical_test (comparison (expr (atom (name read_input)) (trailer (arguments ( ))))))))) do ( execute (StringLib.formattedString("{line}"))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np h,w,k=map(int,input().split()) c=np.zeros((h,w)) for _ in range(h): row=[1 if a=='#' else 0 for a in input()] c[_]=row ans=0 for bit in range(1<>i)& 1 : if icollect( _x | (OclType["int"])->apply(_x) ) ; var c : Sequence := MatrixLib.singleValueMatrix(Sequence{h, w}, 0.0) ; for _anon : Integer.subrange(0, h-1) do ( var row : Sequence := (OclFile["System.in"]).readLine()->select(a | true)->collect(a | (if a = '#' then 1 else 0 endif)) ; c[_anon+1] := row) ; var ans : int := 0 ; for bit : Integer.subrange(0, 1 * (2->pow(h + w))-1) do ( var d : Sequence := ; for i : Integer.subrange(0, h + w-1) do ( if MathLib.bitwiseAnd((bit /(2->pow(i))), 1) then ( if (i->compareTo(h)) < 0 then ( d[i+1] := 0 ) else ( d->collect( _r | _r[i - h+1] ) := 0 ) ) else skip) ; if MatrixLib.sumMatrix(d) = k then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import trunc s=input() k=-1 temp='' q=0 for i in s : if i.isdigit(): temp+=i elif i=='.' : if k!=-1 : temp=temp[: k]+temp[k+1 :] temp+=i k=len(temp)-1 elif len(temp): if k!=-1 and len(temp)-1-k!=2 : temp=temp[: k]+temp[k+1 :] q+=float(temp) k=-1 temp='' if len(temp): if k!=-1 and len(temp)-1-k!=2 : temp=temp[: k]+temp[k+1 :] q+=float(temp) ex=False for i in range(2,0,-1): d=int(q//1000**i) if not ex : if d>0 : print(d,'.',sep='',end='') ex=True else : print('0'*(3-len(str(d)))+str(d)+'.',end='') q-=d*1000**i r=str(int(trunc(q))) if q==0 : print('000') elif trunc(q)!=q : if ex : print('0'*(3-len(r)),"{:.2f}".format(round(q,2)),sep='') else : print("{:.2f}".format(round(q,2))) else : if ex : print('0'*(3-len(r)),int(q),sep='') else : print(int(q)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : String := (OclFile["System.in"]).readLine() ; var k : int := -1 ; var temp : String := '' ; var q : int := 0 ; for i : s->characters() do ( if i->matches("[0-9]*") then ( temp := temp + i ) else (if i = '.' then ( if k /= -1 then ( temp := temp.subrange(1,k) + temp.subrange(k + 1+1) ) else skip ; temp := temp + i ; k := (temp)->size() - 1 ) else (if (temp)->size() then ( if k /= -1 & (temp)->size() - 1 - k /= 2 then ( temp := temp.subrange(1,k) + temp.subrange(k + 1+1) ) else skip ; q := q + ("" + ((temp)))->toReal() ; k := -1 ; temp := '' ) else skip ) ) ) ; if (temp)->size() then ( if k /= -1 & (temp)->size() - 1 - k /= 2 then ( temp := temp.subrange(1,k) + temp.subrange(k + 1+1) ) else skip ; q := q + ("" + ((temp)))->toReal() ) else skip ; var ex : boolean := false ; for i : Integer.subrange(0 + 1, 2)->reverse() do ( var d : int := ("" + ((q div (1000)->pow(i))))->toInteger() ; if not(ex) then ( if d > 0 then ( execute (d)->display() ; ex := true ) else skip ) else ( execute (StringLib.nCopies('0', (3 - (("" + ((d))))->size())) + ("" + ((d))) + '.')->display() ) ; q := q - d * (1000)->pow(i)) ; var r : String := ("" + ((("" + ((trunc(q))))->toInteger()))) ; if q = 0 then ( execute ('000')->display() ) else (if trunc(q) /= q then ( if ex then ( execute (StringLib.nCopies('0', (3 - (r)->size())))->display() ) else ( execute (StringLib.interpolateStrings("{:.2f}", Sequence{MathLib.roundN(q, 2)}))->display() ) ) else ( if ex then ( execute (StringLib.nCopies('0', (3 - (r)->size())))->display() ) else ( execute (("" + ((q)))->toInteger())->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() M=[] n="" for i in a : if i.isnumeric()or i=="." : n+=i elif len(n)>0 : M.append(n) n="" M.append(n) G=[] for i in range(len(M)): if(len(M[i])>=3): if M[i][-3]=="." : M[i]=float(M[i][:-3 :].replace(".","")+M[i][-3 : :]) else : M[i]=float(M[i].replace(".","")) else : M[i]=float(M[i].replace(".","")) sum=0 for i in M : sum+=i sum=round(sum*100)/100 for i in str(sum): G.append(i) for i in range(G.index(".")-3,0,-3): G.insert(i,".") if G[-1]=="0" and G[-2]=="." : G=G[:-2 :] elif G[-1]!="0" and G[-2]=="." : G.append("0") print(*G,sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var M : Sequence := Sequence{} ; var n : String := "" ; for i : a->characters() do ( if i->matches("[0-9]*") or i = "." then ( n := n + i ) else (if (n)->size() > 0 then ( execute ((n) : M) ; n := "" ) else skip)) ; execute ((n) : M) ; var G : Sequence := Sequence{} ; for i : Integer.subrange(0, (M)->size()-1) do ( if ((M[i+1])->size() >= 3) then ( if M[i+1]->reverse()->at(-(-3)) = "." then ( M[i+1] := ("" + ((M[i+1](subscript : (test (logical_test (comparison (expr (atom - (number (integer 3))))))) (sliceop :)).replace(".", "") + M[i+1](subscript (test (logical_test (comparison (expr (atom - (number (integer 3))))))) : (sliceop :)))))->toReal() ) else ( M[i+1] := ("" + ((M[i+1].replace(".", ""))))->toReal() ) ) else ( M[i+1] := ("" + ((M[i+1].replace(".", ""))))->toReal() )) ; var sum : int := 0 ; for i : M do ( sum := sum + i) ; sum := (sum * 100)->round() / 100 ; for i : ("" + ((sum))) do ( execute ((i) : G)) ; for i : Integer.subrange(G->indexOf(".") - 1 - 3, 0-1)->select( $x | ($x - G->indexOf(".") - 1 - 3) mod -3 = 0 ) do ( G := G.insertAt(i+1, ".")) ; if G->last() = "0" & G->front()->last() = "." then ( G := G(subscript : (test (logical_test (comparison (expr (atom - (number (integer 2))))))) (sliceop :)) ) else (if G->last() /= "0" & G->front()->last() = "." then ( execute (("0") : G) ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name G))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re import pdb inputNumbers=re.findall(r'[0-9.]+',input()) def convToNumber(inputString): inputString=inputString.split('.') penny=0 if len(inputString)>1 and len(inputString[-1])==2 : penny=inputString.pop(-1) return float(f"{''.join(inputString)}.{penny}") def convToString(inputNumber): intNumber,penny=str(inputNumber).split('.') output='' for i,char in enumerate(list(intNumber[: :-1])): output+=char if(i+1)% 3==0 : output+='.' while len(penny)<2 : penny+='0' output=output[: :-1] if output[0]=='.' : output=output[1 :] if penny=='00' : return output else : return f'{output}.{penny}' a=round(sum([convToNumber(i)for i in inputNumbers]),2) print(convToString(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var inputNumbers : Sequence(String) := ((OclFile["System.in"]).readLine())->allMatches(StringLib.rawString('[0-9.]+')) ; skip ; skip ; var a : double := MathLib.roundN((inputNumbers->select(i | true)->collect(i | (convToNumber(i))))->sum(), 2) ; execute (convToString(a))->display(); operation convToNumber(inputString : OclAny) : OclAny pre: true post: true activity: inputString := inputString.split('.') ; var penny : int := 0 ; if (inputString)->size() > 1 & (inputString->last())->size() = 2 then ( penny := inputString->at((atom - (number (integer 1)))+1) ; inputString := inputString->excludingAt(-1+1) ) else skip ; return ("" + ((StringLib.formattedString("{''.join(inputString)}.{penny}"))))->toReal(); operation convToString(inputNumber : OclAny) : OclAny pre: true post: true activity: var intNumber : OclAny := null; Sequence{intNumber,penny} := OclType["String"](inputNumber).split('.') ; var output : String := '' ; for _tuple : Integer.subrange(1, ((intNumber(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))))->size())->collect( _indx | Sequence{_indx-1, ((intNumber(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var char : OclAny := _tuple->at(_indx); output := output + char ; if (i + 1) mod 3 = 0 then ( output := output + '.' ) else skip) ; while (penny)->size() < 2 do ( penny := penny + '0') ; output := output(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; if output->first() = '.' then ( output := output->tail() ) else skip ; if penny = '00' then ( return output ) else ( return StringLib.formattedString('{output}.{penny}') ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_prices(s): s=list(s) for i,c in enumerate(s): if c.isalpha(): s[i]='a' return[x for x in ''.join(s).split('a')if x] def prices_sum(prices): rub=0 cop=0 for price in prices : if '.' in price : splited=price.split('.') if len(splited[-1])==2 : cop+=int(splited[-1]) splited=splited[:-1] rub+=int(''.join(splited)) else : rub+=int(price) rub+=cop//100 cop %=100 return rub,cop def format_rub_cop(rub,cop): cop_str='' if cop!=0 : cop_str='.'+'0'*(2-len(str(cop)))+str(cop) rrub=str(rub)[: :-1] ransrub='' for i in range(0,len(rrub),3): ransrub+=rrub[i : i+3]+'.' if ransrub[-1]=='.' : ransrub=ransrub[:-1] return f'{ransrub[::-1]}{cop_str}' def main(): s=input() prices=get_prices(s) rub,cop=prices_sum(prices) print(format_rub_cop(rub,cop)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation get_prices(s : OclAny) : OclAny pre: true post: true activity: s := (s) ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if c->matches("[a-zA-Z]*") then ( s[i+1] := 'a' ) else skip) ; return ''.join(s).split('a')->select(x | x)->collect(x | (x)); operation prices_sum(prices : OclAny) : OclAny pre: true post: true activity: var rub : int := 0 ; var cop : int := 0 ; for price : prices do ( if (price)->includes('.') then ( var splited : OclAny := price.split('.') ; if (splited->last())->size() = 2 then ( cop := cop + ("" + ((splited->last())))->toInteger() ; splited := splited->front() ) else skip ; rub := rub + ("" + ((StringLib.sumStringsWithSeparator((splited), ''))))->toInteger() ) else ( rub := rub + ("" + ((price)))->toInteger() )) ; rub := rub + cop div 100 ; cop := cop mod 100 ; return rub, cop; operation format_rub_cop(rub : OclAny, cop : OclAny) : OclAny pre: true post: true activity: var cop_str : String := '' ; if cop /= 0 then ( cop_str := '.' + StringLib.nCopies('0', (2 - (("" + ((cop))))->size())) + ("" + ((cop))) ) else skip ; var rrub : OclAny := OclType["String"](rub)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var ransrub : String := '' ; for i : Integer.subrange(0, (rrub)->size()-1)->select( $x | ($x - 0) mod 3 = 0 ) do ( ransrub := ransrub + rrub.subrange(i+1, i + 3) + '.') ; if ransrub->last() = '.' then ( ransrub := ransrub->front() ) else skip ; return StringLib.formattedString('{ransrub[::-1]}{cop_str}'); operation main() pre: true post: true activity: s := (OclFile["System.in"]).readLine() ; prices := get_prices(s) ; Sequence{rub,cop} := prices_sum(prices) ; execute (format_rub_cop(rub, cop))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNumUtil(res,a,aCount,b,bCount,n): if(res>1e11): return 1e11 if(aCount==bCount and res>=n): return res return min(findNumUtil(res*10+a,a,aCount+1,b,bCount,n),findNumUtil(res*10+b,a,aCount,b,bCount+1,n)) def findNum(n,a,b): result=0 aCount=0 bCount=0 return findNumUtil(result,a,aCount,b,bCount,n) if __name__=='__main__' : N=4500 A=4 B=7 print(findNum(N,A,B)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var N : int := 4500 ; var A : int := 4 ; var B : int := 7 ; execute (findNum(N, A, B))->display() ) else skip; operation findNumUtil(res : OclAny, a : OclAny, aCount : OclAny, b : OclAny, bCount : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (res > ("1e11")->toReal()) then ( return ("1e11")->toReal() ) else skip ; if (aCount = bCount & (res->compareTo(n)) >= 0) then ( return res ) else skip ; return Set{findNumUtil(res * 10 + a, a, aCount + 1, b, bCount, n), findNumUtil(res * 10 + b, a, aCount, b, bCount + 1, n)}->min(); operation findNum(n : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; aCount := 0 ; bCount := 0 ; return findNumUtil(result, a, aCount, b, bCount, n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def score(x): s=0 ; t=1 for _ in[0]*10 : a=2 ; b=3 if x[t]==10 : a=1 elif x[t]+x[t+1]!=10 : b=2 s+=sum(x[t : t+b]); t+=a return x[0],s while 1 : n=int(input()) if n==0 : break A=sorted([score(list(map(int,input().split())))for _ in[0]*n]) for a,b in sorted(A,key=lambda x :-x[1]): print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var A : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n)->select(_anon | true)->collect(_anon | (score(((input().split())->collect( _x | (OclType["int"])->apply(_x) )))))->sort() ; for _tuple : A->sortedBy($x | (lambda x : OclAny in (-x[1+1]))->apply($x)) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); execute (a)->display())); operation score(x : OclAny) : OclAny pre: true post: true activity: var s : int := 0; var t : int := 1 ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, 10) do ( var a : int := 2; var b : int := 3 ; if x[t+1] = 10 then ( a := 1 ) else (if x[t+1] + x[t + 1+1] /= 10 then ( b := 2 ) else skip) ; s := s + (x.subrange(t+1, t + b))->sum(); t := t + a) ; return x->first(), s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def bowling_score(data): name_id=data[0] data=data[1 :] frame=1 scores=[0]*11 while frame<=10 : if data[0]==10 : scores[frame]=data[0]+data[1]+data[2] data=data[1 :] frame+=1 elif data[0]+data[1]==10 : scores[frame]=data[0]+data[1]+data[2] data=data[2 :] frame+=1 else : scores[frame]=data[0]+data[1] data=data[2 :] frame+=1 return name_id,sum(scores[1 :]) def main(args): while True : m=int(input()) if m==0 : break results=[] for _ in range(m): data=[int(x)for x in input().split()] name_id,score=bowling_score(data) results.append([-score,name_id]) results.sort() for s,i in results : print(i,-s) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation bowling_score(data : OclAny) : OclAny pre: true post: true activity: var name_id : OclAny := data->first() ; data := data->tail() ; var frame : int := 1 ; var scores : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 11) ; while frame <= 10 do ( if data->first() = 10 then ( scores[frame+1] := data->first() + data[1+1] + data[2+1] ; data := data->tail() ; frame := frame + 1 ) else (if data->first() + data[1+1] = 10 then ( scores[frame+1] := data->first() + data[1+1] + data[2+1] ; data := data.subrange(2+1) ; frame := frame + 1 ) else ( scores[frame+1] := data->first() + data[1+1] ; data := data.subrange(2+1) ; frame := frame + 1 ) ) ) ; return name_id, (scores->tail())->sum(); operation main(args : OclAny) pre: true post: true activity: while true do ( var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if m = 0 then ( break ) else skip ; var results : Sequence := Sequence{} ; for _anon : Integer.subrange(0, m-1) do ( data := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var score : OclAny := null; Sequence{name_id,score} := bowling_score(data) ; execute ((Sequence{-score}->union(Sequence{ name_id })) : results)) ; results := results->sort() ; for _tuple : results do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); execute (i)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Player : id=0 score=0 def __init__(self,id,score): self.id=id self.score=score def __lt__(self,other): if self.score==other.score : return self.idother.score while True : N=int(input()) if N==0 : break players=[] for l in range(N): line=[int(i)for i in input().split()] line.append(0) line.append(0) score=0 round=0 i=1 while round<10 : if round<9 : if line[i]<10 : if line[i]+line[i+1]<10 : score+=line[i]+line[i+1] else : score+=line[i]+line[i+1]+line[i+2] i+=2 round+=1 else : score+=line[i]+line[i+1]+line[i+2] i+=1 round+=1 else : score+=line[i]+line[i+1]+line[i+2] round+=1 players.append(Player(line[0],score)) players.sort() for i in range(N): print(players[i].id,players[i].score) ------------------------------------------------------------ OCL File: --------- class Player { static operation newPlayer() : Player pre: true post: Player->exists( _x | result = _x ); static attribute id : int := 0; static attribute score : int := 0; attribute id : int := id; attribute score : int := score; operation initialise(id : OclAny,score : OclAny) : Player pre: true post: true activity: self.id := id ; self.score := score; return self; operation __lt__(other : OclAny) : OclAny pre: true post: true activity: if self.score = other.score then ( return (self.id->compareTo(other.id)) < 0 ) else ( return (self.score->compareTo(other.score)) > 0 ); } class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var players : Sequence := Sequence{} ; for l : Integer.subrange(0, N-1) do ( var line : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute ((0) : line) ; execute ((0) : line) ; score := 0 ; var round : int := 0 ; var i : int := 1 ; while round < 10 do ( if round < 9 then ( if line[i+1] < 10 then ( if line[i+1] + line[i + 1+1] < 10 then ( score := score + line[i+1] + line[i + 1+1] ) else ( score := score + line[i+1] + line[i + 1+1] + line[i + 2+1] ) ; i := i + 2 ; round := round + 1 ) else ( score := score + line[i+1] + line[i + 1+1] + line[i + 2+1] ; i := i + 1 ; round := round + 1 ) ) else ( score := score + line[i+1] + line[i + 1+1] + line[i + 2+1] ; round := round + 1 )) ; execute (((Player.newPlayer()).initialise(line->first(), score)) : players)) ; players := players->sort() ; for i : Integer.subrange(0, N-1) do ( execute (players[i+1].id)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) a=list(map(int,input().strip().split())) b=math.ceil(sum(a)/2) for i in range(n): b=b-a[i] if b<=0 : print(i+1) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : double := ((a)->sum() / 2)->ceil() ; for i : Integer.subrange(0, n-1) do ( b := b - a[i+1] ; if b <= 0 then ( execute (i + 1)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_point(info): info.reverse() acc=0 NORMAL,SPARE,STRIKE,DOUBLE=0,1,2,3 flag=NORMAL game_num=0 while info : if game_num!=9 : down_num1=info.pop() if down_num1!=10 : down_num2=info.pop() if flag==SPARE : acc+=down_num1*2+down_num2 elif flag==STRIKE : acc+=down_num1*2+down_num2*2 elif flag==DOUBLE : acc+=down_num1*3+down_num2*2 else : acc+=down_num1+down_num2 if down_num1+down_num2==10 : flag=SPARE else : flag=NORMAL else : if flag in(SPARE,STRIKE): acc+=down_num1*2 elif flag==DOUBLE : acc+=down_num1*3 else : acc+=down_num1 if flag in(STRIKE,DOUBLE): flag=DOUBLE else : flag=STRIKE game_num+=1 else : down_num1,down_num2=info.pop(),info.pop() if flag==SPARE : acc+=down_num1*2+down_num2 elif flag==STRIKE : acc+=down_num1*2+down_num2*2 elif flag==DOUBLE : acc+=down_num1*3+down_num2*2 else : acc+=down_num1+down_num2 if info : acc+=info.pop() return acc while True : m=int(input()) if m==0 : break score=[list(map(int,input().split()))for _ in range(m)] score_mp=[(info[0],get_point(info[1 :]))for info in score] score_mp.sort() score_mp.sort(key=lambda x :-x[1]) for pair in score_mp : print(*pair) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if m = 0 then ( break ) else skip ; var score : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var score_mp : Sequence := score->select(info | true)->collect(info | (Sequence{info->first(), get_point(info->tail())})) ; score_mp := score_mp->sort() ; score_mp := score_mp->sort() ; for pair : score_mp do ( execute ((argument * (test (logical_test (comparison (expr (atom (name pair))))))))->display())); operation get_point(info : OclAny) : OclAny pre: true post: true activity: info := info->reverse() ; var acc : int := 0 ; var NORMAL : OclAny := null; var SPARE : OclAny := null; var STRIKE : OclAny := null; var DOUBLE : OclAny := null; Sequence{NORMAL,SPARE,STRIKE,DOUBLE} := Sequence{0,1,2,3} ; var flag : OclAny := NORMAL ; var game_num : int := 0 ; while info do ( if game_num /= 9 then ( var down_num1 : OclAny := info->last() ; info := info->front() ; if down_num1 /= 10 then ( var down_num2 : OclAny := info->last() ; info := info->front() ; if flag = SPARE then ( acc := acc + down_num1 * 2 + down_num2 ) else (if flag = STRIKE then ( acc := acc + down_num1 * 2 + down_num2 * 2 ) else (if flag = DOUBLE then ( acc := acc + down_num1 * 3 + down_num2 * 2 ) else ( acc := acc + down_num1 + down_num2 ) ) ) ; if down_num1 + down_num2 = 10 then ( flag := SPARE ) else ( flag := NORMAL ) ) else ( if (Sequence{SPARE, STRIKE})->includes(flag) then ( acc := acc + down_num1 * 2 ) else (if flag = DOUBLE then ( acc := acc + down_num1 * 3 ) else ( acc := acc + down_num1 ) ) ; if (Sequence{STRIKE, DOUBLE})->includes(flag) then ( flag := DOUBLE ) else ( flag := STRIKE ) ) ; game_num := game_num + 1 ) else ( Sequence{down_num1,down_num2} := Sequence{info->last(),info->last()} ; if flag = SPARE then ( acc := acc + down_num1 * 2 + down_num2 ) else (if flag = STRIKE then ( acc := acc + down_num1 * 2 + down_num2 * 2 ) else (if flag = DOUBLE then ( acc := acc + down_num1 * 3 + down_num2 * 2 ) else ( acc := acc + down_num1 + down_num2 ) ) ) ; if info then ( acc := acc + info->last() ; info := info->front() ) else skip )) ; return acc; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import product H,W,K=map(int,input().split()) A=[input()for j in range(H)] ans=0 for i in product([1,0],repeat=H): for j in product([1,0],repeat=W): cnt=0 for row in range(H): for col in range(W): if((A[row][col]=="#")and((i[row]==0)and j[col]==0)): cnt+=1 if cnt==K : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var H : OclAny := null; var W : OclAny := null; var K : OclAny := null; Sequence{H,W,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := Integer.subrange(0, H-1)->select(j | true)->collect(j | ((OclFile["System.in"]).readLine())) ; var ans : int := 0 ; for i : product(Sequence{1}->union(Sequence{ 0 }), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (name H)))))))) do ( for j : product(Sequence{1}->union(Sequence{ 0 }), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (name W)))))))) do ( var cnt : int := 0 ; for row : Integer.subrange(0, H-1) do ( for col : Integer.subrange(0, W-1) do ( if ((A[row+1][col+1] = "#") & ((i[row+1] = 0) & j[col+1] = 0)) then ( cnt := cnt + 1 ) else skip)) ; if cnt = K then ( ans := ans + 1 ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- FIRST=1 SECOND=2 while True : score_count=int(input()) if score_count==0 : break score_list=[] for _ in range(score_count): total_score=0 score_data=[int(item)for item in input().split(" ")] last_score=0 frame_count=1 ball_state=FIRST for index,score in enumerate(score_data[1 :],1): if frame_count==10 : total_score+=sum(score_data[index :]) break if last_score+score==10 : if ball_state==FIRST : total_score+=score+score_data[index+1]+score_data[index+2] else : total_score+=score+score_data[index+1] ball_state=FIRST last_score=0 frame_count+=1 else : total_score+=score if ball_state==FIRST : ball_state=SECOND last_score=score else : ball_state=FIRST last_score=0 frame_count+=1 score_list.append([score_data[0],total_score]) score_list.sort(key=lambda x :(-x[1],x[0])) output=[str(id)+" "+str(score)for id,score in score_list] print("\n".join(output)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var FIRST : int := 1 ; var SECOND : int := 2 ; while true do ( var score_count : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if score_count = 0 then ( break ) else skip ; var score_list : Sequence := Sequence{} ; for _anon : Integer.subrange(0, score_count-1) do ( var total_score : int := 0 ; var score_data : Sequence := input().split(" ")->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; var last_score : int := 0 ; var frame_count : int := 1 ; var ball_state : int := FIRST ; for _tuple : Integer.subrange(1, (score_data->tail(), 1)->size())->collect( _indx | Sequence{_indx-1, (score_data->tail(), 1)->at(_indx)} ) do (var _indx : int := 1; var index : OclAny := _tuple->at(_indx); _indx := _indx + 1; var score : OclAny := _tuple->at(_indx); if frame_count = 10 then ( total_score := total_score + (score_data.subrange(index+1))->sum() ; break ) else skip ; if last_score + score = 10 then ( if ball_state = FIRST then ( total_score := total_score + score + score_data[index + 1+1] + score_data[index + 2+1] ) else ( total_score := total_score + score + score_data[index + 1+1] ; ball_state := FIRST ; last_score := 0 ) ; frame_count := frame_count + 1 ) else ( total_score := total_score + score ; if ball_state = FIRST then ( ball_state := SECOND ; last_score := score ) else ( ball_state := FIRST ; last_score := 0 ; frame_count := frame_count + 1 ) )) ; execute ((Sequence{score_data->first()}->union(Sequence{ total_score })) : score_list)) ; score_list := score_list->sort() ; var output : Sequence := score_list->select(_tuple | true)->collect(_tuple | let id : OclAny = _tuple->at(1) in let score : OclAny = _tuple->at(2) in (("" + ((id))) + " " + ("" + ((score))))) ; execute (StringLib.sumStringsWithSeparator((output), "\n"))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) x=sum(map(int,input().split())) m=int(input()) c=0 g=sorted([list(map(int,input().split()))for _ in range(m)],key=lambda x : x[1]) for i in g : if x<=i[1]: print(max(x,i[0])) break else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : OclAny := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := 0 ; var g : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))->sortedBy($x | (lambda x : OclAny in (x[1+1]))->apply($x)) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name g))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name x)))) <= (comparison (expr (atom (name i)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x))))))) , (argument (test (logical_test (comparison (expr (atom (name i)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()); l=[] l=[int(_)for _ in input().split()] s=sum(l); ans=-1 n=int(input()) while(n>0): n-=1 x=[int(_)for _ in input().split()] if x[0]<=s<=x[1]: ans=s break elif x[0]>s : ans=x[0] break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var l : Sequence := Sequence{} ; l := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var s : OclAny := (l)->sum(); var ans : int := -1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (n > 0) do ( n := n - 1 ; var x : Sequence := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; if (x->first()->compareTo(s)) <= 0 & (s <= x[1+1]) then ( ans := s ; break ) else (if (x->first()->compareTo(s)) > 0 then ( ans := x->first() ; break ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) time=sum(a) m=int(input()) flag1=0 flag2=0 ans=float('inf') for _ in range(m): l,r=map(int,input().split()) if l<=time and r>=time : flag1=1 elif time<=l : flag2=1 ans=min(ans,l) if flag1==1 : print(time) elif flag2==1 : print(ans) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var time : OclAny := (a)->sum() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var flag1 : int := 0 ; var flag2 : int := 0 ; var ans : double := ("" + (('inf')))->toReal() ; for _anon : Integer.subrange(0, m-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (l->compareTo(time)) <= 0 & (r->compareTo(time)) >= 0 then ( flag1 := 1 ) else (if (time->compareTo(l)) <= 0 then ( flag2 := 1 ; ans := Set{ans, l}->min() ) else skip)) ; if flag1 = 1 then ( execute (time)->display() ) else (if flag2 = 1 then ( execute (ans)->display() ) else ( execute (-1)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) m=int(input()) b=[] for i in range(m): l,r=map(int,input().split()) b.append([l,r]) suma=sum(a) rj=0 for i in b : if i[0]<=suma and i[1]>=suma : rj=suma break if rj!=0 : print(rj) else : rj=-1 for i in b : if i[0]>=suma : rj=i[0] break print(rj) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{l}->union(Sequence{ r })) : b)) ; var suma : OclAny := (a)->sum() ; var rj : int := 0 ; for i : b do ( if (i->first()->compareTo(suma)) <= 0 & (i[1+1]->compareTo(suma)) >= 0 then ( rj := suma ; break ) else skip) ; if rj /= 0 then ( execute (rj)->display() ) else ( rj := -1 ; for i : b do ( if (i->first()->compareTo(suma)) >= 0 then ( rj := i->first() ; break ) else skip) ; execute (rj)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s1=input() s1l=s1.split() s1l=[int(i)for i in s1l] m=int(input()) s=0 for i in range(n): s+=s1l[i] if m!=0 : l_time_period=[] for i in range(m): s2=input() s2l=s2.split() s2l=[int(i)for i in s2l] l_time_period.append(s2l) if(s>l_time_period[m-1][1]): print(-1) elif(s=l_time_period[i][0]and s<=l_time_period[i][1]): print(s) break elif((s>l_time_period[i][1]and stoInteger() ; var s1 : String := (OclFile["System.in"]).readLine() ; var s1l : OclAny := s1.split() ; s1l := s1l->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : int := 0 ; for i : Integer.subrange(0, n-1) do ( s := s + s1l[i+1]) ; if m /= 0 then ( var l_time_period : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var s2 : String := (OclFile["System.in"]).readLine() ; var s2l : OclAny := s2.split() ; s2l := s2l->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute ((s2l) : l_time_period)) ; if ((s->compareTo(l_time_period[m - 1+1][1+1])) > 0) then ( execute (-1)->display() ) else (if ((s->compareTo(l_time_period->first()->first())) < 0) then ( execute (l_time_period->first()->first())->display() ) else ( for i : Integer.subrange(0, m-1) do ( if ((s->compareTo(l_time_period[i+1]->first())) >= 0 & (s->compareTo(l_time_period[i+1][1+1])) <= 0) then ( execute (s)->display() ; break ) else (if (((s->compareTo(l_time_period[i+1][1+1])) > 0 & (s->compareTo(l_time_period[i + 1+1]->first())) < 0) & (i->compareTo(m - 1)) < 0) then ( execute (l_time_period[i + 1+1]->first())->display() ; break ) else skip)) ) ) ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def two_way_sort(arr,arr_len): l,r=0,arr_len-1 k=0 while(lunion(Sequence{3}->union(Sequence{2}->union(Sequence{7}->union(Sequence{5}->union(Sequence{ 4 }))))) ; var result : OclAny := two_way_sort(arr, arr_len) ; for i : result do ((testlist_star_expr (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) + (expr (atom " ")))))))) ))))))) ,)); operation two_way_sort(arr : OclAny, arr_len : OclAny) : OclAny pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,arr_len - 1} ; var k : int := 0 ; while ((l->compareTo(r)) < 0) do ( while (arr[l+1] mod 2 /= 0) do ( l := l + 1 ; k := k + 1) ; while (arr[r+1] mod 2 = 0 & (l->compareTo(r)) < 0) do ( r := r - 1) ; if ((l->compareTo(r)) < 0) then ( var arr[l+1] : OclAny := null; var arr[r+1] : OclAny := null; Sequence{arr[l+1],arr[r+1]} := Sequence{arr[r+1],arr[l+1]} ) else skip) ; var odd : OclAny := arr.subrange(1,k) ; var even : OclAny := arr.subrange(k+1) ; odd := odd->sort() ; even := even->sort() ; odd := odd->union(even) ; return odd; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findOddPair(A,N): oddPair=0 for i in range(0,N): for j in range(i+1,N): if((A[i]| A[j])% 2!=0): oddPair+=1 return oddPair def main(): A=[5,6,2,8] N=len(A) print(findOddPair(A,N)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation findOddPair(A : OclAny, N : OclAny) : OclAny pre: true post: true activity: var oddPair : int := 0 ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(i + 1, N-1) do ( if ((MathLib.bitwiseOr(A[i+1], A[j+1])) mod 2 /= 0) then ( oddPair := oddPair + 1 ) else skip)) ; return oddPair; operation main() pre: true post: true activity: A := Sequence{5}->union(Sequence{6}->union(Sequence{2}->union(Sequence{ 8 }))) ; N := (A)->size() ; execute (findOddPair(A, N))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findOddPair(A,N): oddPair=0 for i in range(0,N): for j in range(i+1,N): if((A[i]^ A[j])% 2!=0): oddPair+=1 return oddPair if __name__=='__main__' : A=[5,4,7,2,1] N=len(A) print(findOddPair(A,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( A := Sequence{5}->union(Sequence{4}->union(Sequence{7}->union(Sequence{2}->union(Sequence{ 1 })))) ; N := (A)->size() ; execute (findOddPair(A, N))->display() ) else skip; operation findOddPair(A : OclAny, N : OclAny) : OclAny pre: true post: true activity: var oddPair : int := 0 ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(i + 1, N-1) do ( if ((MathLib.bitwiseXor(A[i+1], A[j+1])) mod 2 /= 0) then ( oddPair := oddPair + 1 ) else skip)) ; return oddPair; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) x=sum(l)/2 cur=0 i=0 while curtoInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : double := (l)->sum() / 2 ; var cur : int := 0 ; var i : int := 0 ; while (cur->compareTo(x)) < 0 do ( cur := cur + l[i+1] ; i := i + 1) ; execute (i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countNumber(n): result=0 for i in range(1,10): s=[] if(i<=n): s.append(i) result+=1 while len(s)!=0 : tp=s[-1] s.pop() for j in range(tp % 10,10): x=tp*10+j if(x<=n): s.append(x) result+=1 return result if __name__=='__main__' : n=15 print(countNumber(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 15 ; execute (countNumber(n))->display() ) else skip; operation countNumber(n : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; for i : Integer.subrange(1, 10-1) do ( var s : Sequence := Sequence{} ; if ((i->compareTo(n)) <= 0) then ( execute ((i) : s) ; result := result + 1 ) else skip ; while (s)->size() /= 0 do ( var tp : OclAny := s->last() ; s := s->front() ; for j : Integer.subrange(tp mod 10, 10-1) do ( var x : double := tp * 10 + j ; if ((x->compareTo(n)) <= 0) then ( execute ((x) : s) ; result := result + 1 ) else skip))) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countZeros(x): total_bits=32 res=0 while((x &(1<<(total_bits-1)))==0): x=(x<<1) res+=1 return res x=101 print(countZeros(x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := 101 ; execute (countZeros(x))->display(); operation countZeros(x : OclAny) : OclAny pre: true post: true activity: var total_bits : int := 32 ; var res : int := 0 ; while ((MathLib.bitwiseAnd(x, (1 * (2->pow((total_bits - 1)))))) = 0) do ( x := (x * (2->pow(1))) ; res := res + 1) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findOccurrences(str,substr): counter=0 for i in range(0,len(str)): if(str[i]==substr[0]): for j in range(i+1,len(str)): if(str[j]==substr[1]): for k in range(j+1,len(str)): if(str[k]==substr[2]): counter=counter+1 return counter str="GFGFGYSYIOIWIN" substr="GFG" print(findOccurrences(str,substr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclType["String"] := "GFGFGYSYIOIWIN" ; substr := "GFG" ; execute (findOccurrences(OclType["String"], substr))->display(); operation findOccurrences(OclType["String"] : OclAny, substr : OclAny) : OclAny pre: true post: true activity: var counter : int := 0 ; for i : Integer.subrange(0, (OclType["String"])->size()-1) do ( if (("" + ([i+1])) = substr->first()) then ( for j : Integer.subrange(i + 1, (OclType["String"])->size()-1) do ( if (("" + ([j+1])) = substr[1+1]) then ( for k : Integer.subrange(j + 1, (OclType["String"])->size()-1) do ( if (("" + ([k+1])) = substr[2+1]) then ( counter := counter + 1 ) else skip) ) else skip) ) else skip) ; return counter; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def floodFill(self,image,sr,sc,newColor): r_ls,c_ls=len(image),len(image[0]) color=image[sr][sc] if color==newColor : return image queue=[(sr,sc)] while len(queue)>0 : r,c=queue.pop(0) if image[r][c]==color : image[r][c]=newColor if r-1>=0 : queue.append((r-1,c)) if r+1=0 : queue.append((r,c-1)) if c+1exists( _x | result = _x ); operation floodFill(image : OclAny,sr : OclAny,sc : OclAny,newColor : OclAny) : OclAny pre: true post: true activity: var r_ls : OclAny := null; var c_ls : OclAny := null; Sequence{r_ls,c_ls} := Sequence{(image)->size(),(image->first())->size()} ; var color : OclAny := image[sr+1][sc+1] ; if color = newColor then ( return image ) else skip ; var queue : Sequence := Sequence{ Sequence{sr, sc} } ; while (queue)->size() > 0 do ( var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := queue->at(0`firstArg+1) ; queue := queue->excludingAt(0+1) ; if image[r+1][c+1] = color then ( image[r+1][c+1] := newColor ; if r - 1 >= 0 then ( execute ((Sequence{r - 1, c}) : queue) ) else skip ; if (r + 1->compareTo(r_ls)) < 0 then ( execute ((Sequence{r + 1, c}) : queue) ) else skip ; if c - 1 >= 0 then ( execute ((Sequence{r, c - 1}) : queue) ) else skip ; if (c + 1->compareTo(c_ls)) < 0 then ( execute ((Sequence{r, c + 1}) : queue) ) else skip ) else skip) ; return image; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() ans=0 for i in range(len(s)): if s[max(0,i-1)]!=s[i]: ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[Set{0, i - 1}->max()+1] /= s[i+1] then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from functools import lru_cache,cmp_to_key from heapq import merge,heapify,heappop,heappush from math import* from collections import defaultdict as dd,deque,Counter as C from itertools import combinations as comb,permutations as perm from bisect import bisect_left as bl,bisect_right as br,bisect from time import perf_counter from fractions import Fraction mod=int(pow(10,9)+7) mod2=998244353 def data(): return sys.stdin.readline().strip() def out(*var,end="\n"): sys.stdout.write(' '.join(map(str,var))+end) def l(): return list(sp()) def sl(): return list(ssp()) def sp(): return map(int,data().split()) def ssp(): return map(str,data().split()) def l1d(n,val=0): return[val for i in range(n)] def l2d(n,m,val=0): return[l1d(n,val)for j in range(m)] s=input() ans=0 for i in range(1,len(s)): if(s[i]!=s[i-1]): ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : int := ("" + (((10)->pow(9) + 7)))->toInteger() ; var mod2 : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var s : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; for i : Integer.subrange(1, (s)->size()-1) do ( if (s[i+1] /= s[i - 1+1]) then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); operation data() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation out(var : OclAny : Sequence(OclAny), end : String) pre: true post: true activity: (args * (named_parameter (name var))) if end->oclIsUndefined() then end := "\n" else skip; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ' ') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name var)))))))) ))))))))) )))) + (expr (atom (name end))))))))) )))); operation l() : OclAny pre: true post: true activity: return (sp()); operation sl() : OclAny pre: true post: true activity: return (ssp()); operation sp() : OclAny pre: true post: true activity: return (data().split())->collect( _x | (OclType["int"])->apply(_x) ); operation ssp() : OclAny pre: true post: true activity: return (data().split())->collect( _x | (OclType["String"])->apply(_x) ); operation l1d(n : OclAny, val : int) : OclAny pre: true post: true activity: if val->oclIsUndefined() then val := 0 else skip; return Integer.subrange(0, n-1)->select(i | true)->collect(i | (val)); operation l2d(n : OclAny, m : OclAny, val : int) : OclAny pre: true post: true activity: if val->oclIsUndefined() then val := 0 else skip; return Integer.subrange(0, m-1)->select(j | true)->collect(j | (l1d(n, val))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def c_1d_reversi(S): from itertools import groupby return len(list(groupby(S)))-1 S=input() print(c_1d_reversi(S)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; S := (OclFile["System.in"]).readLine() ; execute (cc(c(c(cc(c(c(cc(c(c(cc(c(c(cc(c(c(cc(c(c(cc(c(c skipd_reversi(S))d_reversi(S))d_reversi(S)d_reversi(S))->display()d_reversi(S))d_reversi(S))d_reversi(S)d_reversi(S))->display()d_reversi(S))d_reversi(S))d_reversi(S)d_reversi(S))->display()d_reversi(S))d_reversi(S))d_reversi(S)d_reversi(S))->display()d_reversi(S))d_reversi(S))d_reversi(S)d_reversi(S))->display()d_reversi(S))d_reversi(S))d_reversi(S)d_reversi(S))->display()d_reversi(S))d_reversi(S))d_reversi(S)d_reversi(S))->display(); operation c skipd_reversi(S : OclAny) : OclAny pre: true post: true activity: skip ; return ((groupby(S)))->size() - 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy import random import bisect import fractions import math import sys mod=10**9+7 sys.setrecursionlimit(mod) S=str(input()) ans_w=0 cnt=[0,0] left=S[0] if left=="B" : cnt[1]+=1 else : cnt[0]+=1 for i in range(1,len(S)): if left==S[i]: pass else : left=S[i] if left=="B" : cnt[1]+=1 else : cnt[0]+=1 if cnt[0]==cnt[1]: ans=(cnt[0]-1)*2+1 else : ans=min(cnt)*2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; sys.setrecursionlimit(mod) ; var S : String := ("" + (((OclFile["System.in"]).readLine()))) ; var ans_w : int := 0 ; var cnt : Sequence := Sequence{0}->union(Sequence{ 0 }) ; var left : OclAny := S->first() ; if left = "B" then ( cnt[1+1] := cnt[1+1] + 1 ) else ( cnt->first() := cnt->first() + 1 ) ; for i : Integer.subrange(1, (S)->size()-1) do ( if left = S[i+1] then ( skip ) else ( left := S[i+1] ; if left = "B" then ( cnt[1+1] := cnt[1+1] + 1 ) else ( cnt->first() := cnt->first() + 1 ) )) ; if cnt->first() = cnt[1+1] then ( var ans : double := (cnt->first() - 1) * 2 + 1 ) else ( ans := (cnt)->min() * 2 ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=[1 if x=="W" else 0 for x in input()] groups=[] tmp=0 zeros=0 for n in S : if n==1 : if zeros!=0 : groups.append(zeros) zeros=0 tmp+=1 elif n==0 : if tmp!=0 : groups.append(tmp) tmp=0 zeros-=1 if tmp!=0 : groups.append(tmp) if zeros!=0 : groups.append(zeros) print(len(groups)-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : Sequence := (OclFile["System.in"]).readLine()->select(x | true)->collect(x | (if x = "W" then 1 else 0 endif)) ; var groups : Sequence := Sequence{} ; var tmp : int := 0 ; var zeros : int := 0 ; for n : S do ( if n = 1 then ( if zeros /= 0 then ( execute ((zeros) : groups) ; zeros := 0 ) else skip ; tmp := tmp + 1 ) else (if n = 0 then ( if tmp /= 0 then ( execute ((tmp) : groups) ; tmp := 0 ) else skip ; zeros := zeros - 1 ) else skip)) ; if tmp /= 0 then ( execute ((tmp) : groups) ) else skip ; if zeros /= 0 then ( execute ((zeros) : groups) ) else skip ; execute ((groups)->size() - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getMinMax(low,high,arr): arr_max=arr[low] arr_min=arr[low] if low==high : arr_max=arr[low] arr_min=arr[low] return(arr_max,arr_min) elif high==low+1 : if arr[low]>arr[high]: arr_max=arr[low] arr_min=arr[high] else : arr_max=arr[high] arr_min=arr[low] return(arr_max,arr_min) else : mid=int((low+high)/2) arr_max1,arr_min1=getMinMax(low,mid,arr) arr_max2,arr_min2=getMinMax(mid+1,high,arr) return(max(arr_max1,arr_max2),min(arr_min1,arr_min2)) arr=[1000,11,445,1,330,3000] high=len(arr)-1 low=0 arr_max,arr_min=getMinMax(low,high,arr) print('Minimum element is ',arr_min) print('nMaximum element is ',arr_max) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1000}->union(Sequence{11}->union(Sequence{445}->union(Sequence{1}->union(Sequence{330}->union(Sequence{ 3000 }))))) ; high := (arr)->size() - 1 ; low := 0 ; Sequence{arr_max,arr_min} := getMinMax(low, high, arr) ; execute ('Minimum element is ')->display() ; execute ('nMaximum element is ')->display(); operation getMinMax(low : OclAny, high : OclAny, arr : OclAny) : OclAny pre: true post: true activity: var arr_max : OclAny := arr[low+1] ; var arr_min : OclAny := arr[low+1] ; if low = high then ( arr_max := arr[low+1] ; arr_min := arr[low+1] ; return Sequence{arr_max, arr_min} ) else (if high = low + 1 then ( if (arr[low+1]->compareTo(arr[high+1])) > 0 then ( arr_max := arr[low+1] ; arr_min := arr[high+1] ) else ( arr_max := arr[high+1] ; arr_min := arr[low+1] ) ; return Sequence{arr_max, arr_min} ) else ( var mid : int := ("" + (((low + high) / 2)))->toInteger() ; var arr_max1 : OclAny := null; var arr_min1 : OclAny := null; Sequence{arr_max1,arr_min1} := getMinMax(low, mid, arr) ; var arr_max2 : OclAny := null; var arr_min2 : OclAny := null; Sequence{arr_max2,arr_min2} := getMinMax(mid + 1, high, arr) ) ) ; return Sequence{Set{arr_max1, arr_max2}->max(), Set{arr_min1, arr_min2}->min()}; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def repeatedSum(n): if(n==0): return 0 return 9 if(n % 9==0)else(n % 9) def repeatedProduct(n): prod=1 while(n>0 or prod>9): if(n==0): n=prod prod=1 prod*=n % 10 n//=10 return prod def maxSumProduct(N): if(N<10): return N return max(repeatedSum(N),repeatedProduct(N)) if __name__=="__main__" : n=631 print(maxSumProduct(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( n := 631 ; execute (maxSumProduct(n))->display() ) else skip; operation repeatedSum(n : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return 0 ) else skip ; return if (n mod 9 = 0) then 9 else (n mod 9) endif; operation repeatedProduct(n : OclAny) : OclAny pre: true post: true activity: var prod : int := 1 ; while (n > 0 or prod > 9) do ( if (n = 0) then ( n := prod ; prod := 1 ) else skip ; prod := prod * n mod 10 ; n := n div 10) ; return prod; operation maxSumProduct(N : OclAny) : OclAny pre: true post: true activity: if (N < 10) then ( return N ) else skip ; return Set{repeatedSum(N), repeatedProduct(N)}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- M=100 def maxAverageOfPath(cost,N): dp=[[0 for i in range(N+1)]for j in range(N+1)] dp[0][0]=cost[0][0] for i in range(1,N): dp[i][0]=dp[i-1][0]+cost[i][0] for j in range(1,N): dp[0][j]=dp[0][j-1]+cost[0][j] for i in range(1,N): for j in range(1,N): dp[i][j]=max(dp[i-1][j],dp[i][j-1])+cost[i][j] return dp[N-1][N-1]/(2*N-1) cost=[[1,2,3],[6,5,4],[7,3,9]] print(maxAverageOfPath(cost,3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var M : int := 100 ; skip ; cost := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{Sequence{6}->union(Sequence{5}->union(Sequence{ 4 }))}->union(Sequence{ Sequence{7}->union(Sequence{3}->union(Sequence{ 9 })) })) ; execute (maxAverageOfPath(cost, 3))->display(); operation maxAverageOfPath(cost : OclAny, N : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, N + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (0)))) ; dp->first()->first() := cost->first()->first() ; for i : Integer.subrange(1, N-1) do ( dp[i+1]->first() := dp[i - 1+1]->first() + cost[i+1]->first()) ; for j : Integer.subrange(1, N-1) do ( dp->first()[j+1] := dp->first()[j - 1+1] + cost->first()[j+1]) ; for i : Integer.subrange(1, N-1) do ( for j : Integer.subrange(1, N-1) do ( dp[i+1][j+1] := Set{dp[i - 1+1][j+1], dp[i+1][j - 1+1]}->max() + cost[i+1][j+1])) ; return dp[N - 1+1][N - 1+1] / (2 * N - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): N,A=list(map(int,input().split())) X=list(map(int,input().split())) dp=[[[0 for _ in range(50*50+1)]for __ in range(N+1)]for ___ in range(N)] dp[0][0][0]=1 dp[0][1][X[0]]=1 for i in range(1,N): for j in range(0,N): for k in range(50*50+1): dp[i][j][k]+=dp[i-1][j][k] if k+X[i]<50*50+1 : dp[i][j+1][k+X[i]]+=dp[i-1][j][k] ans=0 for j in range(1,N+1): ans+=dp[N-1][j][A*j] print(ans) if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( solve() ) else skip; operation solve() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; Sequence{N,A} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var X : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dp : Sequence := Integer.subrange(0, N-1)->select(___ | true)->collect(___ | (Integer.subrange(0, N + 1-1)->select(__ | true)->collect(__ | (Integer.subrange(0, 50 * 50 + 1-1)->select(_anon | true)->collect(_anon | (0)))))) ; dp->first()->first()->first() := 1 ; dp->first()[1+1][X->first()+1] := 1 ; for i : Integer.subrange(1, N-1) do ( for j : Integer.subrange(0, N-1) do ( for k : Integer.subrange(0, 50 * 50 + 1-1) do ( dp[i+1][j+1][k+1] := dp[i+1][j+1][k+1] + dp[i - 1+1][j+1][k+1] ; if (k + X[i+1]->compareTo(50 * 50 + 1)) < 0 then ( dp[i+1][j + 1+1][k + X[i+1]+1] := dp[i+1][j + 1+1][k + X[i+1]+1] + dp[i - 1+1][j+1][k+1] ) else skip))) ; var ans : int := 0 ; for j : Integer.subrange(1, N + 1-1) do ( ans := ans + dp[N - 1+1][j+1][A * j+1]) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) summ=0 ans=0 ss=sum(l)/2 for i in range(n): summ+=l[i] if summ>=ss : ans=i print(ans+1) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var summ : int := 0 ; var ans : int := 0 ; var ss : double := (l)->sum() / 2 ; for i : Integer.subrange(0, n-1) do ( summ := summ + l[i+1] ; if (summ->compareTo(ss)) >= 0 then ( ans := i ; execute (ans + 1)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- e=input for _ in[0]*int(e()): X,z=e(),[] for y in e(): s=i=0 for k in z : t=X.find(y,s)+1 if t<1 : break if ttoInteger()) do ( var X : OclAny := null; var z : OclAny := null; Sequence{X,z} := Sequence{e(),Sequence{}} ; for y : e() do ( var s : OclAny := 0; var i : int := 0 ; (compound_stmt for (exprlist (expr (atom (name k)))) in (testlist (test (logical_test (comparison (expr (atom (name z))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name t)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name X)) (trailer . (name find) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y))))))) , (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))) + (expr (atom (number (integer 1)))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name t)))) < (comparison (expr (atom (number (integer 1)))))))) : (suite (simple_stmt (small_stmt break))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name t)))) < (comparison (expr (atom (name k))))))) : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name z)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name t)))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name k)))))))))) ; (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name t)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name X)) (trailer . (name find) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y))))))) , (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))) + (expr (atom (number (integer 1)))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name t)))))) : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name z)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name t))))))) ])))))))))))))))) ; execute ((z)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,tan,asin,acos,atan,radians,degrees from itertools import accumulate,permutations,combinations,combinations_with_replacement,product,groupby from operator import itemgetter,mul from copy import deepcopy from string import ascii_lowercase,ascii_uppercase,digits from bisect import bisect,bisect_left,insort,insort_left from fractions import gcd from heapq import heappush,heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) def ZIP(n): return zip(*(MAP()for _ in range(n))) sys.setrecursionlimit(10**9) INF=float('inf') mod=10**9+7 def lcs(s1,s2): dp=[] for s2_k in s2 : bgn_idx=0 for i,cur_idx in enumerate(dp): chr_idx=s1.find(s2_k,bgn_idx)+1 if not chr_idx : break dp[i]=min(cur_idx,chr_idx) bgn_idx=cur_idx else : chr_idx=s1.find(s2_k,bgn_idx)+1 if chr_idx : dp.append(chr_idx) return len(dp) q=INT() for _ in range(q): S=input() T=input() print(lcs(S,T)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; skip ; var q : OclAny := INT() ; for _anon : Integer.subrange(0, q-1) do ( var S : String := (OclFile["System.in"]).readLine() ; var T : String := (OclFile["System.in"]).readLine() ; execute (lcs(S, T))->display()); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ZIP(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))`third->at(_indx)} ); operation lcs(s1 : OclAny, s2 : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Sequence{} ; for s2_k : s2 do ( var bgn_idx : int := 0 ; (compound_stmt for (exprlist (expr (atom (name i))) , (expr (atom (name cur_idx)))) in (testlist (test (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name dp)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name chr_idx)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name s1)) (trailer . (name find) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s2_k))))))) , (argument (test (logical_test (comparison (expr (atom (name bgn_idx)))))))) )))) + (expr (atom (number (integer 1)))))))))))))) (stmt (compound_stmt if (test (logical_test not (logical_test (comparison (expr (atom (name chr_idx))))))) : (suite (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name cur_idx))))))) , (argument (test (logical_test (comparison (expr (atom (name chr_idx)))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name bgn_idx)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cur_idx))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name chr_idx)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name s1)) (trailer . (name find) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s2_k))))))) , (argument (test (logical_test (comparison (expr (atom (name bgn_idx)))))))) )))) + (expr (atom (number (integer 1)))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name chr_idx)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name chr_idx)))))))) ))))))))))))))))))) ; return (dp)->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lcs_len(X,Y): m,n=len(X),len(Y) LCS_r=[0 for _ in range(m+1)] for y in Y : previous=LCS_r[:] for i,x in enumerate(X): if x==y : LCS_r[i+1]=previous[i]+1 elif LCS_r[i]>previous[i+1]: LCS_r[i+1]=LCS_r[i] return LCS_r[-1] q=int(input()) for _ in range(q): X=input() Y=input() print(lcs_len(X,Y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( X := (OclFile["System.in"]).readLine() ; Y := (OclFile["System.in"]).readLine() ; execute (lcs_len(X, Y))->display()); operation lcs_len(X : OclAny, Y : OclAny) : OclAny pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := Sequence{(X)->size(),(Y)->size()} ; var LCS_r : Sequence := Integer.subrange(0, m + 1-1)->select(_anon | true)->collect(_anon | (0)) ; for y : Y do ( var previous : Sequence := LCS_r ; for _tuple : Integer.subrange(1, (X)->size())->collect( _indx | Sequence{_indx-1, (X)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); if x = y then ( LCS_r[i + 1+1] := previous[i+1] + 1 ) else (if (LCS_r[i+1]->compareTo(previous[i + 1+1])) > 0 then ( LCS_r[i + 1+1] := LCS_r[i+1] ) else skip))) ; return LCS_r->last(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def longest_common_subsequence(line1,line2): n_rows=len(line2)+1 array=[0]*n_rows ix_=[x for x in range(n_rows)] ix=[x+1 for x in range(n_rows)] for l1_letter in line1 : prev_array=array[:] for i_row_,i_row,l2_letter in zip(ix_,ix,line2): if l1_letter==l2_letter : array[i_row]=prev_array[i_row_]+1 else : up=prev_array[i_row] left=array[i_row_] array[i_row]=up if up>left else left return array[-1] calc_time=False if calc_time : import time ; start=time.time() def main(): n=int(input()) lines=sys.stdin.readlines() for i in range(0,2*n,2): ans=longest_common_subsequence(lines[i].rstrip(),lines[i+1].rstrip()) print(ans) return main() if calc_time : print("elapsed:",time.time()-start) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var calc_time : boolean := false ; if calc_time then ( skip; var start : OclAny := time.time() ) else skip ; skip ; main() ; if calc_time then ( execute ("elapsed:")->display() ) else skip; operation longest_common_subsequence(line1 : OclAny, line2 : OclAny) : OclAny pre: true post: true activity: var n_rows : int := (line2)->size() + 1 ; var array : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n_rows) ; var ix_ : Sequence := Integer.subrange(0, n_rows-1)->select(x | true)->collect(x | (x)) ; var ix : Sequence := Integer.subrange(0, n_rows-1)->select(x | true)->collect(x | (x + 1)) ; for l1_letter : line1 do ( var prev_array : Sequence := array ; for _tuple : Integer.subrange(1, ix_->size())->collect( _indx | Sequence{ix_->at(_indx), ix->at(_indx)} ) do (var _indx : int := 1; var i_row_ : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i_row : OclAny := _tuple->at(_indx); _indx := _indx + 1; var l2_letter : OclAny := _tuple->at(_indx); if l1_letter = l2_letter then ( array[i_row+1] := prev_array[i_row_+1] + 1 ) else ( var up : OclAny := prev_array[i_row+1] ; var left : OclAny := array[i_row_+1] ; array[i_row+1] := if (up->compareTo(left)) > 0 then up else left endif ))) ; return array->last(); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lines : OclAny := (OclFile["System.in"]).readlines() ; for i : Integer.subrange(0, 2 * n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( var ans : OclAny := longest_common_subsequence(lines[i+1].rstrip(), lines[i + 1+1].rstrip()) ; execute (ans)->display()) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def search(x,y): x_length=len(x) y_length=len(y) memo=[[0]*(y_length+1)for i in range(x_length+1)] for i,ch_x in enumerate(x,1): row=memo[i] pre_row=memo[i-1] for j,ch_y in enumerate(y,1): if ch_x==ch_y : row[j]=pre_row[j-1]+1 elif pre_row[j]toInteger() ; var strs : Sequence := sys.stdin.readAll().splitlines()->select(val | true)->collect(val | ((val))) ; var result : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (search(strs[i * 2+1], strs[i * 2 + 1+1]))) ; execute ((argument * (test (logical_test (comparison (expr (atom (name result))))))))->display() ) else skip; operation search(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var x_length : int := (x)->size() ; var y_length : int := (y)->size() ; var memo : Sequence := Integer.subrange(0, x_length + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (y_length + 1)))) ; for _tuple : Integer.subrange(1, (x, 1)->size())->collect( _indx | Sequence{_indx-1, (x, 1)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var ch_x : OclAny := _tuple->at(_indx); var row : OclAny := memo[i+1] ; var pre_row : OclAny := memo[i - 1+1] ; for _tuple : Integer.subrange(1, (y, 1)->size())->collect( _indx | Sequence{_indx-1, (y, 1)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var ch_y : OclAny := _tuple->at(_indx); if ch_x = ch_y then ( row[j+1] := pre_row[j - 1+1] + 1 ) else (if (pre_row[j+1]->compareTo(row[j - 1+1])) < 0 then ( row[j+1] := row[j - 1+1] ) else ( row[j+1] := pre_row[j+1] ) ) )) ; return memo->last()->last(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getTrailingZeroes(n): count=0 val,powerTwo=1,2 while(val!=0): val=n//powerTwo count+=val powerTwo*=2 return(count//4) n=6 print(getTrailingZeroes(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 6 ; execute (getTrailingZeroes(n))->display(); operation getTrailingZeroes(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var val : OclAny := null; var powerTwo : OclAny := null; Sequence{val,powerTwo} := Sequence{1,2} ; while (val /= 0) do ( var val : int := n div powerTwo ; count := count + val ; powerTwo := powerTwo * 2) ; return (count div 4); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def calculateDivisors(A,B): N=A-B noOfDivisors=0 a=math.sqrt(N) for i in range(1,int(a+1)): if((N % i==0)): if(i>B): noOfDivisors+=1 if((N/i)!=i and(N/i)>B): noOfDivisors+=1 ; return noOfDivisors def numberOfPossibleWaysUtil(A,B): if(A==B): return-1 if(Asqrt() ; for i : Integer.subrange(1, ("" + ((a + 1)))->toInteger()-1) do ( if ((N mod i = 0)) then ( if ((i->compareTo(B)) > 0) then ( noOfDivisors := noOfDivisors + 1 ) else skip ; if ((N / i) /= i & ((N / i)->compareTo(B)) > 0) then ( noOfDivisors := noOfDivisors + 1; ) else skip ) else skip) ; return noOfDivisors; operation numberOfPossibleWaysUtil(A : OclAny, B : OclAny) : OclAny pre: true post: true activity: if (A = B) then ( return -1 ) else skip ; if ((A->compareTo(B)) < 0) then ( return 0 ) else skip ; noOfDivisors := 0 ; noOfDivisors := calculateDivisors; ; return noOfDivisors; operation numberOfPossibleWays(A : OclAny, B : OclAny) pre: true post: true activity: var noOfSolutions : OclAny := numberOfPossibleWaysUtil(A, B) ; if (noOfSolutions = -1) then ( execute ("For A=")->display() ) else ( execute ("For A=")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- text=raw_input() pr='' for i in text : if ord(i)-3char2byte() - 3->compareTo(('A')->char2byte())) < 0 then ( var i : String := ((i)->char2byte() + ('Z')->char2byte() - ('A')->char2byte() + 1)->byte2char() ) else skip ; pr := pr + ((i)->char2byte() - 3)->byte2char()) ; execute (pr)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000000 sieve_Prime=[0 for i in range(MAX+4)] sieve_count=[0 for i in range(MAX+4)] def form_sieve(): sieve_Prime[1]=1 for i in range(2,MAX+1): if sieve_Prime[i]==0 : for j in range(i*2,MAX+1,i): if sieve_Prime[j]==0 : sieve_Prime[j]=1 sieve_count[i]+=1 form_sieve() n=2 print("Count=",sieve_count[n]+1) n=3 print("Count=",sieve_count[n]+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1000000 ; var sieve_Prime : Sequence := Integer.subrange(0, MAX + 4-1)->select(i | true)->collect(i | (0)) ; var sieve_count : Sequence := Integer.subrange(0, MAX + 4-1)->select(i | true)->collect(i | (0)) ; skip ; form_sieve() ; var n : int := 2 ; execute ("Count=")->display() ; n := 3 ; execute ("Count=")->display(); operation form_sieve() pre: true post: true activity: sieve_Prime[1+1] := 1 ; for i : Integer.subrange(2, MAX + 1-1) do ( if sieve_Prime[i+1] = 0 then ( for j : Integer.subrange(i * 2, MAX + 1-1)->select( $x | ($x - i * 2) mod i = 0 ) do ( if sieve_Prime[j+1] = 0 then ( sieve_Prime[j+1] := 1 ; sieve_count[i+1] := sieve_count[i+1] + 1 ) else skip) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dict={} dict['A']='X' dict['B']='Y' dict['C']='Z' dict['D']='A' dict['E']='B' dict['F']='C' dict['G']='D' dict['H']='E' dict['I']='F' dict['J']='G' dict['K']='H' dict['L']='I' dict['M']='J' dict['N']='K' dict['O']='L' dict['P']='M' dict['Q']='N' dict['R']='O' dict['S']='P' dict['T']='Q' dict['U']='R' dict['V']='S' dict['W']='T' dict['X']='U' dict['Y']='V' dict['Z']='W' for s in input().strip(): print(dict[s],end='') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var OclType["Map"] : OclAny := Set{} ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'A'))))))) ]) := 'X' ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'B'))))))) ]) := 'Y' ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'C'))))))) ]) := 'Z' ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'D'))))))) ]) := 'A' ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'E'))))))) ]) := 'B' ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'F'))))))) ]) := 'C' ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'G'))))))) ]) := 'D' ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'H'))))))) ]) := 'E' ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'I'))))))) ]) := 'F' ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'J'))))))) ]) := 'G' ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'K'))))))) ]) := 'H' ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'L'))))))) ]) := 'I' ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'M'))))))) ]) := 'J' ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'N'))))))) ]) := 'K' ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'O'))))))) ]) := 'L' ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'P'))))))) ]) := 'M' ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'Q'))))))) ]) := 'N' ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'R'))))))) ]) := 'O' ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'S'))))))) ]) := 'P' ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'T'))))))) ]) := 'Q' ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'U'))))))) ]) := 'R' ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'V'))))))) ]) := 'S' ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'W'))))))) ]) := 'T' ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'X'))))))) ]) := 'U' ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'Y'))))))) ]) := 'V' ; (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'Z'))))))) ]) := 'W' ; for s : input()->trim() do ( execute ((arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ]))->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- bef="ABCDEFGHIJKLMNOPQRSTUVWXYZ" aft="DEFGHIJKLMNOPQRSTUVWXYZABC" s=list(input()) for i in range(len(s)): for j in range(len(aft)): if s[i]==aft[j]: s[i]=bef[j] print(s[i],end="") break print("") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var bef : String := "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; var aft : String := "DEFGHIJKLMNOPQRSTUVWXYZABC" ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; for i : Integer.subrange(0, (s)->size()-1) do ( for j : Integer.subrange(0, (aft)->size()-1) do ( if s[i+1] = aft[j+1] then ( s[i+1] := bef[j+1] ; execute (s[i+1])->display() ; break ) else skip)) ; execute ("")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) x=[int(q)for q in input().split()] w=0 ans=0 a=(sum(x)/2) while wtoInteger() ; var x : Sequence := input().split()->select(q | true)->collect(q | (("" + ((q)))->toInteger())) ; var w : int := 0 ; var ans : int := 0 ; var a : double := ((x)->sum() / 2) ; while (w->compareTo(a)) < 0 do ( w := w + x[ans+1] ; ans := ans + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() str_list=list(x) dict_={"D" : "A","E" : "B","F" : "C","G" : "D","H" : "E","I" : "F","J" : "G","K" : "H","L" : "I","M" : "J","N" : "K","O" : "L","P" : "M","Q" : "N","R" : "O","S" : "P","T" : "Q","U" : "R","V" : "S","W" : "T","X" : "U","Y" : "V","Z" : "W","A" : "X","B" : "Y","C" : "Z"} for a in str_list : print(dict_.get(a),end="") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := (OclFile["System.in"]).readLine() ; var str_list : Sequence := (x)->characters() ; var dict_ : Map := Map{ "D" |-> "A" }->union(Map{ "E" |-> "B" }->union(Map{ "F" |-> "C" }->union(Map{ "G" |-> "D" }->union(Map{ "H" |-> "E" }->union(Map{ "I" |-> "F" }->union(Map{ "J" |-> "G" }->union(Map{ "K" |-> "H" }->union(Map{ "L" |-> "I" }->union(Map{ "M" |-> "J" }->union(Map{ "N" |-> "K" }->union(Map{ "O" |-> "L" }->union(Map{ "P" |-> "M" }->union(Map{ "Q" |-> "N" }->union(Map{ "R" |-> "O" }->union(Map{ "S" |-> "P" }->union(Map{ "T" |-> "Q" }->union(Map{ "U" |-> "R" }->union(Map{ "V" |-> "S" }->union(Map{ "W" |-> "T" }->union(Map{ "X" |-> "U" }->union(Map{ "Y" |-> "V" }->union(Map{ "Z" |-> "W" }->union(Map{ "A" |-> "X" }->union(Map{ "B" |-> "Y" }->union(Map{ "C" |-> "Z" }))))))))))))))))))))))))) ; for a : str_list do ( execute (dict_.get(a))->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): d=list(input()) alp=[chr(i)for i in range(65,65+26)] for x in range(len(d)): idx=alp.index(d[x])-3 if idx<0 : idx=26+idx else : pass d[x]=alp[idx] ans="" for x in d : ans+=x print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var d : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var alp : Sequence := Integer.subrange(65, 65 + 26-1)->select(i | true)->collect(i | ((i)->byte2char())) ; for x : Integer.subrange(0, (d)->size()-1) do ( var idx : double := alp->indexOf(d[x+1]) - 1 - 3 ; if idx < 0 then ( idx := 26 + idx ) else ( skip ) ; d[x+1] := alp[idx+1]) ; var ans : String := "" ; for x : d do ( ans := ans + x) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def extraElement(A,B,n): ans=0 ; for i in range(n): ans ^=A[i]; for i in range(n+1): ans ^=B[i]; return ans ; A=[10,15,5]; B=[10,100,15,5]; n=len(A); print(extraElement(A,B,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; A := Sequence{10}->union(Sequence{15}->union(Sequence{ 5 })); ; B := Sequence{10}->union(Sequence{100}->union(Sequence{15}->union(Sequence{ 5 }))); ; n := (A)->size(); ; execute (extraElement(A, B, n))->display();; operation extraElement(A : OclAny, B : OclAny, n : OclAny) pre: true post: true activity: var ans : int := 0; ; for i : Integer.subrange(0, n-1) do ( ans := ans xor A[i+1];) ; for i : Integer.subrange(0, n + 1-1) do ( ans := ans xor B[i+1];) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math st=input() su=0 cu=1 for i in range(len(st)): r=(cu-(ord(st[i])-96))% 26 l=((ord(st[i])-96)-cu)% 26 su+=min(r,l) cu=ord(st[i])-96 print(su) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var st : String := (OclFile["System.in"]).readLine() ; var su : int := 0 ; var cu : int := 1 ; for i : Integer.subrange(0, (st)->size()-1) do ( var r : int := (cu - ((st[i+1])->char2byte() - 96)) mod 26 ; var l : int := (((st[i+1])->char2byte() - 96) - cu) mod 26 ; su := su + Set{r, l}->min() ; cu := (st[i+1])->char2byte() - 96) ; execute (su)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- name=input() alphabet=[chr(i)for i in range(97,123)] last=0 num=0 for x in name : i=alphabet.index(x) num1=abs(i-last) if iselect(i | true)->collect(i | ((i)->byte2char())) ; var last : int := 0 ; var num : int := 0 ; for x : name->characters() do ( var i : int := alphabet->indexOf(x) - 1 ; var num1 : double := (i - last)->abs() ; if (i->compareTo(last)) < 0 then ( var num2 : double := (i + 26 - last)->abs() ) else ( num2 := (last + 26 - i)->abs() ) ; num := num + Set{num1, num2}->min() ; last := i) ; execute (num)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import string alph=string.ascii_lowercase ptr='a' ans=0 s=input() for i in range(len(s)): ans+=min(abs(alph.index(ptr)-alph.index(s[i])),abs(26+min(alph.index(ptr),alph.index(s[i]))-max(alph.index(ptr),alph.index(s[i])))) ptr=s[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var alph : OclAny := string.ascii_lowercase ; var ptr : String := 'a' ; var ans : int := 0 ; var s : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, (s)->size()-1) do ( ans := ans + Set{(alph->indexOf(ptr) - 1 - alph->indexOf(s[i+1]) - 1)->abs(), (26 + Set{alph->indexOf(ptr) - 1, alph->indexOf(s[i+1]) - 1}->min() - Set{alph->indexOf(ptr) - 1, alph->indexOf(s[i+1]) - 1}->max())->abs()}->min() ; ptr := s[i+1]) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def night_at_the_museum(): name=input() moves=0 current='a' for letter in name : moves+=min(abs(ord(current)-ord(letter)),26-abs(ord(current)-ord(letter))) current=letter return moves print(night_at_the_museum()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (night_at_the_museum())->display(); operation night_at_the_museum() : OclAny pre: true post: true activity: var name : String := (OclFile["System.in"]).readLine() ; var moves : int := 0 ; var current : String := 'a' ; for letter : name->characters() do ( moves := moves + Set{((current)->char2byte() - (letter)->char2byte())->abs(), 26 - ((current)->char2byte() - (letter)->char2byte())->abs()}->min() ; current := letter) ; return moves; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tcs=int(input()) binom=[[1]] for i in range(1,5001): binom.append([]) binom[-1].append(binom[-2][0]/2) for j in range(1,i): binom[-1].append((binom[-2][j-1]+binom[-2][j])/2) binom[-1].append(binom[-2][-1]/2) for i in range(len(binom)): assert(len(binom[i])==i+1) for j in range(1,len(binom[i])): binom[i][j]+=binom[i][j-1]; for tc in range(1,tcs+1): n,x,y=(int(i)for i in input().split(' ')) level=(abs(x)+y)//2 l=0 while n>0 : k=4*l+1 if n>=k : if level==l : print("Case #%d: 1.0" % tc) break n-=k else : if level==l : if y<=n-1-2*l : print("Case #%d: 1.0" % tc) elif y>=min(2*l,n): print("Case #%d: 0.0" % tc) else : print("Case #%d: %.15f" %(tc,1-binom[n][y])) break n=0 l+=1 else : print("Case #%d: 0.0" % tc) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var tcs : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var binom : Sequence := Sequence{ Sequence{ 1 } } ; for i : Integer.subrange(1, 5001-1) do ( execute ((Sequence{}) : binom) ; (expr (atom (name binom)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name binom)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 2))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) / (expr (atom (number (integer 2)))))))))) )))) ; for j : Integer.subrange(1, i-1) do ((expr (atom (name binom)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name binom)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 2))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name j))) - (expr (atom (number (integer 1)))))))))) ]))) + (expr (atom (name binom)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 2))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) ))) / (expr (atom (number (integer 2)))))))))) ))))) ; (expr (atom (name binom)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name binom)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 2))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))) / (expr (atom (number (integer 2)))))))))) ))))) ; for i : Integer.subrange(0, (binom)->size()-1) do ( assert ((binom[i+1])->size() = i + 1) do "assertion failed" ; for j : Integer.subrange(1, (binom[i+1])->size()-1) do ( binom[i+1][j+1] := binom[i+1][j+1] + binom[i+1][j - 1+1];)) ; for tc : Integer.subrange(1, tcs + 1-1) do ( var n : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,x,y} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ' '))))))) ))))))))} ; var level : int := ((x)->abs() + y) div 2 ; var l : int := 0 ; (compound_stmt while (test (logical_test (comparison (comparison (expr (atom (name n)))) > (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name k)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (number (integer 4)))) * (expr (atom (name l)))) + (expr (atom (number (integer 1)))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name n)))) >= (comparison (expr (atom (name k))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name level)))) == (comparison (expr (atom (name l))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom "Case #%d: 1.0")) % (expr (atom (name tc))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name n)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (name k)))))))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name level)))) == (comparison (expr (atom (name l))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name y)))) <= (comparison (expr (expr (expr (atom (name n))) - (expr (atom (number (integer 1))))) - (expr (expr (atom (number (integer 2)))) * (expr (atom (name l))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom "Case #%d: 1.0")) % (expr (atom (name tc))))))))) ))))))))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name y)))) >= (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name l)))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom "Case #%d: 0.0")) % (expr (atom (name tc))))))))) )))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom "Case #%d: %.15f")) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name tc)))))) , (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) - (expr (atom (name binom)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])))))))) ))))))))) )))))))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name n)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom "Case #%d: 0.0")) % (expr (atom (name tc))))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K,T,U,V,L=map(int,input().split()) ans=0 l=0 t=0 k=0 for _ in range(N+1): if _==N : d=L else : d=int(input()) length=d-l l=d while t>0 or k>0 : if t>0 : if t*V>=length : tmp=(t*V-length)/V ans+=t-tmp t=tmp if K>k : k+=1 else : t=T length=0 break else : length=length-t*V ans+=t t=0 if k>0 : k-=1 t=T elif k>0 : k-=1 t=T if length>0 : ans+=length/U if K>k : k+=1 else : t=T print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; var T : OclAny := null; var U : OclAny := null; var V : OclAny := null; var L : OclAny := null; Sequence{N,K,T,U,V,L} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; var l : int := 0 ; var t : int := 0 ; var k : int := 0 ; for _anon : Integer.subrange(0, N + 1-1) do ( if _anon = N then ( var d : OclAny := L ) else ( d := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ) ; var length : double := d - l ; l := d ; while t > 0 or k > 0 do ( if t > 0 then ( if (t * V->compareTo(length)) >= 0 then ( var tmp : double := (t * V - length) / V ; ans := ans + t - tmp ; t := tmp ; if (K->compareTo(k)) > 0 then ( k := k + 1 ) else ( t := T ) ; length := 0 ; break ) else ( length := length - t * V ; ans := ans + t ; t := 0 ; if k > 0 then ( k := k - 1 ; t := T ) else skip ) ) else (if k > 0 then ( k := k - 1 ; t := T ) else skip)) ; if length > 0 then ( ans := ans + length / U ; if (K->compareTo(k)) > 0 then ( k := k + 1 ) else ( t := T ) ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- text=input() pos=1 tot_move=0 first_move=True for i in text : to_go=ord(i)-ord('a')+1 move=abs(pos-to_go) if move>13 : tot_move+=(26-move) else : tot_move+=move pos=to_go print(tot_move) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var text : String := (OclFile["System.in"]).readLine() ; var pos : int := 1 ; var tot_move : int := 0 ; var first_move : boolean := true ; for i : text->characters() do ( var to_go : double := (i)->char2byte() - ('a')->char2byte() + 1 ; var move : double := (pos - to_go)->abs() ; if move > 13 then ( tot_move := tot_move + (26 - move) ) else ( tot_move := tot_move + move ) ; pos := to_go) ; execute (tot_move)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_SIZE=1000001 isprime=[True]*MAX_SIZE prime=[] SPF=[None]*(MAX_SIZE) def manipulated_seive(N): isprime[0]=isprime[1]=False for i in range(2,N): if isprime[i]==True : prime.append(i) SPF[i]=i j=0 while(jcompareTo((prime)->size())) < 0 & (prime[i+1]->compareTo(N)) <= 0 do ( execute (prime[i+1])->display() ; i := i + 1) ) else skip; operation manipulated_seive(N : OclAny) pre: true post: true activity: isprime->first() := false; var isprime[1+1] : boolean := false ; for i : Integer.subrange(2, N-1) do ( if isprime[i+1] = true then ( execute ((i) : prime) ; SPF[i+1] := i ) else skip ; var j : int := 0 ; while ((j->compareTo((prime)->size())) < 0 & (i * prime[j+1]->compareTo(N)) < 0 & (prime[j+1]->compareTo(SPF[i+1])) <= 0) do ( isprime[i * prime[j+1]+1] := false ; SPF[i * prime[j+1]+1] := prime[j+1] ; j := j + 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math def get_ints(): return map(int,sys.stdin.readline().strip().split()) def get_ls(): return list(map(int,sys.stdin.readline().strip().split())) def test_ok(ok): print("YES" if ok else "NO") def main(): n=int(input()) p=get_ls() c=get_ls() ans=0 for i in range(1,n): if c[i]!=c[p[i-1]-1]: ans+=1 print(ans+1) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation get_ints() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ); operation get_ls() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation test_ok(ok : OclAny) pre: true post: true activity: execute (if ok then "YES" else "NO" endif)->display(); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : OclAny := get_ls() ; var c : OclAny := get_ls() ; var ans : int := 0 ; for i : Integer.subrange(1, n-1) do ( if c[i+1] /= c[p[i - 1+1] - 1+1] then ( ans := ans + 1 ) else skip) ; execute (ans + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) a=[int(x)for x in input().split()] b=sum(a) c=int(math.ceil(b/2)) d=0 i=0 while((d+a[i])toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var b : OclAny := (a)->sum() ; var c : int := ("" + (((b / 2)->ceil())))->toInteger() ; var d : int := 0 ; var i : int := 0 ; while (((d + a[i+1])->compareTo(c)) < 0) do ( d := d + a[i+1] ; i := i + 1) ; execute (i + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict as di from collections import deque as dq n=int(input()) coupl=di(list) nodess=[int(x)-1 for x in input().split()] for i in range(n-1): node=nodess[i] coupl[i+1].append(node) coupl[node].append(i+1) colors=[int(x)-1 for x in input().split()] Q=dq() found=set() Q.append((0,0)) parent=[-1]*n order=[] while Q : node,p=Q.popleft() if node in found : continue found.add(node) parent[node]=p order.append(node) for nei in coupl[node]: Q.append((nei,node)) color=[-1]*n count=0 for node in order : if colors[node]==color[parent[node]]: pass else : count+=1 color[node]=colors[node] print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var coupl : OclAny := di(OclType["Sequence"]) ; var nodess : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)) ; for i : Integer.subrange(0, n - 1-1) do ( var node : OclAny := nodess[i+1] ; (expr (atom (name coupl)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name node)))))))) )))) ; (expr (atom (name coupl)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name node)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ))))) ; var colors : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)) ; var Q : OclAny := dq() ; var found : Set := Set{}->union(()) ; execute ((Sequence{0, 0}) : Q) ; var parent : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; var order : Sequence := Sequence{} ; while Q do ( var p : OclAny := null; Sequence{node,p} := Q->first() ; Q := Q->tail() ; if (found)->includes(node) then ( continue ) else skip ; execute ((node) : found) ; parent[node+1] := p ; execute ((node) : order) ; for nei : coupl[node+1] do ( execute ((Sequence{nei, node}) : Q))) ; var color : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; var count : int := 0 ; for node : order do ( if colors[node+1] = color[parent[node+1]+1] then ( skip ) else ( count := count + 1 ) ; color[node+1] := colors[node+1]) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def produs_cifre(numar): produs=1 for i in numar : produs=produs*int(i) return(produs) def functie(nodul,vectorul,cate,culori,vizitat): if vizitat[nodul]==0 : vizitat[nodul]=1 if culori[nodul-1]!=noi_culori[nodul-1]: cate[0]=1+cate[0] noi_culori[nodul-1]=culori[nodul-1] for j in vectorul[nodul]: if vizitat[j]==0 : noi_culori[j-1]=culori[nodul-1] functie(j,vectorul,cate,culori,vizitat) return(sum(cate)) for contor in range(0,1): n=int(input()) lista=list(map(int,input().split())) culori=list(map(int,input().split())) my_set=set() my_set.add(1) vector_father=[0]*(n+1) for i in range(0,n-1): element=i+2 potential_father=lista[i] if potential_father in my_set : vector_father[element]=potential_father my_set.add(element) else : vector_father[potential_father]=element my_set.add(potential_father) answ=1 for i in range(2,n+1): if culori[i-1]!=culori[vector_father[i]-1]: answ+=1 print(answ) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for contor : Integer.subrange(0, 1-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lista : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; culori := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var my_set : Set := Set{}->union(()) ; execute ((1) : my_set) ; var vector_father : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(0, n - 1-1) do ( var element : OclAny := i + 2 ; var potential_father : OclAny := lista[i+1] ; if (my_set)->includes(potential_father) then ( vector_father[element+1] := potential_father ; execute ((element) : my_set) ) else ( vector_father[potential_father+1] := element ; execute ((potential_father) : my_set) )) ; var answ : int := 1 ; for i : Integer.subrange(2, n + 1-1) do ( if culori[i - 1+1] /= culori[vector_father[i+1] - 1+1] then ( answ := answ + 1 ) else skip) ; execute (answ)->display()); operation produs_cifre(numar : OclAny) : OclAny pre: true post: true activity: var produs : int := 1 ; for i : numar do ( produs := produs * ("" + ((i)))->toInteger()) ; return (produs); operation functie(nodul : OclAny, vectorul : OclAny, cate : OclAny, culori : OclAny, vizitat : OclAny) : OclAny pre: true post: true activity: if vizitat[nodul+1] = 0 then ( vizitat[nodul+1] := 1 ; if culori[nodul - 1+1] /= noi_culori[nodul - 1+1] then ( cate->first() := 1 + cate->first() ; noi_culori[nodul - 1+1] := culori[nodul - 1+1] ) else skip ; for j : vectorul[nodul+1] do ( if vizitat[j+1] = 0 then ( noi_culori[j - 1+1] := culori[nodul - 1+1] ; functie(j, vectorul, cate, culori, vizitat) ) else skip) ) else skip ; return ((cate)->sum()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=lambda : list(map(int,input().split())) n=int(input()) p=I() color=I() print(1+sum(color[i]!=color[x-1]for i,x in enumerate(p,1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : OclAny := I->apply() ; var color : OclAny := I->apply() ; execute (1 + ((argument (test (logical_test (comparison (comparison (expr (atom (name color)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) != (comparison (expr (atom (name color)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) d=[[i]for i in range(n)] w=list(map(int,input().split())) for i in range(n-1): d[i+1].append(w[i]-1) s=list(map(int,input().split())) c=1 for i in range(n): for j in range(len(d[i])-1): if s[d[i][j]]!=s[d[i][j+1]]: c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{ i })) ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n - 1-1) do ((expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (number (integer 1)))))))))) ))))) ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 1 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, (d[i+1])->size() - 1-1) do ( if s[d[i+1][j+1]+1] /= s[d[i+1][j + 1+1]+1] then ( c := c + 1 ) else skip)) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=m=map(int,input().split()) ans=0 for _ in range(k): l=list(map(int,input().split())) ans+=l[0]-1 p=-20 for x in l[1 :]: if x==1 : p=0 elif p!=-20 : if p+2==x : p+=1 else : ans-=p ; p=-20 if p!=-20 : ans-=p ans*=2 ans+=k-1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var m : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; for _anon : Integer.subrange(0, k-1) do ( var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; ans := ans + l->first() - 1 ; var p : int := -20 ; for x : l->tail() do ( if x = 1 then ( p := 0 ) else (if p /= -20 then ( if p + 2 = x then ( p := p + 1 ) else ( ans := ans - p; p := -20 ) ) else skip)) ; if p /= -20 then ( ans := ans - p ) else skip) ; ans := ans * 2 ; ans := ans + k - 1 ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) actions=0 for chain_idx in ' '*k : chain=[int(x)for x in input().split()[1 :]] if 1 not in chain : actions+=len(chain)*2-1 else : pops=len(chain) for i,v in enumerate(chain): if v==i+1 : pops-=1 else : break actions+=pops*2 if k==1 : print(0) else : print(actions) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var actions : int := 0 ; for chain_idx : StringLib.nCopies(' ', k) do ( var chain : Sequence := input().split()->tail()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if (chain)->excludes(1) then ( actions := actions + (chain)->size() * 2 - 1 ) else ( var pops : int := (chain)->size() ; for _tuple : Integer.subrange(1, (chain)->size())->collect( _indx | Sequence{_indx-1, (chain)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if v = i + 1 then ( pops := pops - 1 ) else ( break )) ; actions := actions + pops * 2 )) ; if k = 1 then ( execute (0)->display() ) else ( execute (actions)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- carrot,maxstock,duration,normal,fast,goal=((int(n)for n in input().split(" "))) stack,used=[],0 for c in range(carrot): newcar=int(input()) stack=list(filter(lambda x : x>newcar,stack)) if len(stack)==0 : stack.append(newcar+(fast*duration)) used+=fast*duration else : if len(stack)==maxstock+1 : used+=fast*duration-(stack[0]-newcar) stack=list(map(lambda x : x+(fast*duration-(stack[0]-newcar)),stack)) else : stack.append(stack[-1]+fast*duration) used+=fast*duration if stack[-1]>goal : used-=stack[-1]-goal print((goal-used)/normal+used/fast) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var carrot : OclAny := null; var maxstock : OclAny := null; var duration : OclAny := null; var normal : OclAny := null; var fast : OclAny := null; var goal : OclAny := null; Sequence{carrot,maxstock,duration,normal,fast,goal} := (Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " "))))))) ))))))))}) ; var stack : OclAny := null; var used : OclAny := null; Sequence{stack,used} := Sequence{Sequence{},0} ; for c : Integer.subrange(0, carrot-1) do ( var newcar : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var stack : Sequence := ((stack)->select( _x | (lambda x : OclAny in ((x->compareTo(newcar)) > 0))->apply(_x) = true )) ; if (stack)->size() = 0 then ( execute ((newcar + (fast * duration)) : stack) ; used := used + fast * duration ) else ( if (stack)->size() = maxstock + 1 then ( used := used + fast * duration - (stack->first() - newcar) ; stack := ((stack)->collect( _x | (lambda x : OclAny in (x + (fast * duration - (stack->first() - newcar))))->apply(_x) )) ) else ( execute ((stack->last() + fast * duration) : stack) ; used := used + fast * duration ) )) ; if (stack->last()->compareTo(goal)) > 0 then ( used := used - stack->last() - goal ) else skip ; execute ((goal - used) / normal + used / fast)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=2*n-k+1 for _ in range(k): x=list(map(int,input().split()))[1 :] for i in range(len(x)): if i+1==x[i]: a-=2 print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : double := 2 * n - k + 1 ; for _anon : Integer.subrange(0, k-1) do ( var x : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->tail() ; for i : Integer.subrange(0, (x)->size()-1) do ( if i + 1 = x[i+1] then ( a := a - 2 ) else skip)) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (n,k)=list(map(int,input().split(' '))) r=2*n-k+1 for kk in range(k): a=list(map(int,input().split(' ')))[1 :] index=1 for aa in a : if(aa==index): r-=2 index+=1 print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{n, k} : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var r : double := 2 * n - k + 1 ; for kk : Integer.subrange(0, k-1) do ( var a : OclAny := OclType["Sequence"]((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ))->tail() ; var index : int := 1 ; for aa : a do ( if (aa = index) then ( r := r - 2 ) else skip ; index := index + 1)) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def mean(arr,n): sm=0 for i in range(0,n): sm=sm+arr[i] return sm/n def SSD(arr,n): sm=0 for i in range(0,n): sm=sm+(arr[i]-mean(arr,n))*(arr[i]-mean(arr,n)) return(math.sqrt(sm/(n-1))) def sampleError(arr,n): return SSD(arr,n)/(math.sqrt(n)) arr=[78.53,79.62,80.25,81.05,83.21,83.46] n=len(arr) print(sampleError(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; arr := Sequence{78.53}->union(Sequence{79.62}->union(Sequence{80.25}->union(Sequence{81.05}->union(Sequence{83.21}->union(Sequence{ 83.46 }))))) ; n := (arr)->size() ; execute (sampleError(arr, n))->display(); operation mean(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sm : int := 0 ; for i : Integer.subrange(0, n-1) do ( sm := sm + arr[i+1]) ; return sm / n; operation SSD(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: sm := 0 ; for i : Integer.subrange(0, n-1) do ( sm := sm + (arr[i+1] - mean(arr, n)) * (arr[i+1] - mean(arr, n))) ; return ((sm / (n - 1))->sqrt()); operation sampleError(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: return SSD(arr, n) / ((n)->sqrt()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def psuedoBinary(n): while(n>0): temp=n ; m=0 ; p=1 ; while(temp): rem=temp % 10 ; temp=int(temp/10); if(rem!=0): m+=p ; p*=10 ; print(m,end=" "); n=n-m ; n=31 ; psuedoBinary(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 31; ; psuedoBinary(n);; operation psuedoBinary(n : OclAny) pre: true post: true activity: while (n > 0) do ( var temp : OclAny := n; ; var m : int := 0; ; var p : int := 1; ; while (temp) do ( var rem : int := temp mod 10; ; temp := ("" + ((temp / 10)))->toInteger(); ; if (rem /= 0) then ( m := m + p; ) else skip ; p := p * 10;) ; execute (m)->display(); ; n := n - m;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) from collections import defaultdict n,w=map(int,readline().split()) wv=[tuple(map(int,readline().split()))for i in range(n)] dp=defaultdict(int) dp[0]=0 for ww,v in wv : for xw,xv in list(dp.items()): if ww+xw<=w : dp[ww+xw]=max(dp[ww+xw],v+xv) print(max(dp.values())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; sys.setrecursionlimit((10)->pow(7)) ; skip ; var n : OclAny := null; var w : OclAny := null; Sequence{n,w} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var wv : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((readline().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var dp : OclAny := defaultdict(OclType["int"]) ; dp->first() := 0 ; for _tuple : wv do (var _indx : int := 1; var ww : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); for _tuple : (dp->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})) do (var _indx : int := 1; var xw : OclAny := _tuple->at(_indx); _indx := _indx + 1; var xv : OclAny := _tuple->at(_indx); if (ww + xw->compareTo(w)) <= 0 then ( dp[ww + xw+1] := Set{dp[ww + xw+1], v + xv}->max() ) else skip)) ; execute ((dp.values())->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : h,w=map(int,raw_input().split(' ')) if h==w and h==0 : break print('#'*w+'\n')*h ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (raw_input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; if h = w & h = 0 then ( break ) else skip ; (expr (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom '#')) * (expr (atom (name w)))) + (expr (atom ' ')))))))) )))) * (expr (atom (name h))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys L=[] M=[] while True : (a,b)=map(int,raw_input().split()) if a==0 and b==0 : break else : L.append(a) M.append(b) for x in range(len(L)): for y in range(L[x]): for z in range(M[x]): sys.stdout.write("#") print print ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var L : Sequence := Sequence{} ; var M : Sequence := Sequence{} ; while true do ( ; var Sequence{a, b} : Sequence := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 0 & b = 0 then ( break ) else ( execute ((a) : L) ; execute ((b) : M) )) ; for x : Integer.subrange(0, (L)->size()-1) do ( for y : Integer.subrange(0, L[x+1]-1) do ( for z : Integer.subrange(0, M[x+1]-1) do ((expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "#"))))))) ))))) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function import sys for line in sys.stdin : h,w=(int(s)for s in line.split()) if h==0 and w==0 : break print(('#'*w+'\n')*h) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for line : OclFile["System.in"] do ( var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name line)) (trailer . (name split) (arguments ( ))))))))} ; if h = 0 & w = 0 then ( break ) else skip ; execute ((StringLib.nCopies('#', w) + ' ') * h)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : (h,w)=map(int,input().split()) if w+h==0 : break for i in range(h): for j in range(w): print("#",end="") else : print("") print("") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( ; var Sequence{h, w} : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if w + h = 0 then ( break ) else skip ; for i : Integer.subrange(0, h-1) do ((compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name w)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "#")))))) , (argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom ""))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ""))))))) )))))))))))))))) ; execute ("")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys for line in sys.stdin : h,w=map(int,line.rstrip().split()) if h==0 and w==0 : break rect=('#'*w+'\n')*h print(rect) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for line : OclFile["System.in"] do ( var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (line.rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if h = 0 & w = 0 then ( break ) else skip ; var rect : double := (StringLib.nCopies('#', w) + ' ') * h ; execute (rect)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkIfPowerIsolated(num): input1=num ; count=0 ; factor=[0]*(num+1); if(num % 2==0): while(num % 2==0): count+=1 ; num//=2 ; factor[2]=count ; i=3 ; while(i*i<=num): count=0 ; while(num % i==0): count+=1 ; num//=i ; if(count>0): factor[i]=count ; i+=2 ; if(num>1): factor[num]=1 ; product=1 ; for i in range(0,len(factor)): if(factor[i]>0): product=product*factor[i]*i ; if(product==input1): print("Power-isolated Integer"); else : print("Not a Power-isolated Integer"); checkIfPowerIsolated(12); checkIfPowerIsolated(18); checkIfPowerIsolated(35); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; checkIfPowerIsolated(12); ; checkIfPowerIsolated(18); ; checkIfPowerIsolated(35);; operation checkIfPowerIsolated(num : OclAny) pre: true post: true activity: var input1 : OclAny := num; ; var count : int := 0; ; var factor : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (num + 1)); ; if (num mod 2 = 0) then ( while (num mod 2 = 0) do ( count := count + 1; ; num := num div 2;) ; factor[2+1] := count; ) else skip ; var i : int := 3; ; while ((i * i->compareTo(num)) <= 0) do ( count := 0; ; while (num mod i = 0) do ( count := count + 1; ; num := num div i;) ; if (count > 0) then ( factor[i+1] := count; ) else skip ; i := i + 2;) ; if (num > 1) then ( factor[num+1] := 1; ) else skip ; var product : int := 1; ; for i : Integer.subrange(0, (factor)->size()-1) do ( if (factor[i+1] > 0) then ( product := product * factor[i+1] * i; ) else skip) ; if (product = input1) then ( execute ("Power-isolated Integer")->display(); ) else ( execute ("Not a Power-isolated Integer")->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) z=0 for i in range(1,n+1): z+=i print(z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var z : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( z := z + i) ; execute (z)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(sum([n for n in range(1,int(input())+1)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((Integer.subrange(1, ("" + (((OclFile["System.in"]).readLine())))->toInteger() + 1-1)->select(n | true)->collect(n | (n)))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline sys.setrecursionlimit(10**6) n=int(input()) print((n+1)*n//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit((10)->pow(6)) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((n + 1) * n div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) total=N*(N+1)//2 print(total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var total : int := N * (N + 1) div 2 ; execute (total)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() print(n*(n+1))/2 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; (expr (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1))))))))) ))))))))) )))) / (expr (atom (number (integer 2))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,W=map(int,input().split()) wv=[tuple([int(j)for j in input().split()])for _ in range(N)] w1=wv[0][0] w2=w1+1 w3=w1+2 w4=w1+3 wv=sorted(wv,key=lambda x : x[1],reverse=True) wv=sorted(wv,key=lambda x : x[0]) wvv=list(map(lambda x : x[1],wv)) inf=float("inf") ans=0 from collections import defaultdict counter=defaultdict(int) for i in range(N): w,v=wv[i] counter[w]+=1 from bisect import bisect_left as bll for e1 in range(0,counter[w1]+1): for e2 in range(0,counter[w2]+1): for e3 in range(0,counter[w3]+1): for e4 in range(0,counter[w4]+1): tmp=0 if w1*e1+w2*e2+w3*e3+w4*e4>W : continue i1=bll(wv,(w1,-inf)) i2=bll(wv,(w2,-inf)) i3=bll(wv,(w3,-inf)) i4=bll(wv,(w4,-inf)) tmp=tmp+sum(wvv[i1 : i1+e1])+sum(wvv[i2 : i2+e2])+sum(wvv[i3 : i3+e3])+sum(wvv[i4 : i4+e4]) ans=max(ans,tmp) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var W : OclAny := null; Sequence{N,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var wv : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | ((input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger()))))) ; var w1 : OclAny := wv->first()->first() ; var w2 : OclAny := w1 + 1 ; var w3 : OclAny := w1 + 2 ; var w4 : OclAny := w1 + 3 ; wv := wv->sortedBy($x | (lambda x : OclAny in (x[1+1]))->apply($x)) ; wv := wv->sortedBy($x | (lambda x : OclAny in (x->first()))->apply($x)) ; var wvv : Sequence := ((wv)->collect( _x | (lambda x : OclAny in (x[1+1]))->apply(_x) )) ; var Math_PINFINITY : double := ("" + (("inf")))->toReal() ; var ans : int := 0 ; skip ; var counter : OclAny := defaultdict(OclType["int"]) ; for i : Integer.subrange(0, N-1) do ( var w : OclAny := null; var v : OclAny := null; Sequence{w,v} := wv[i+1] ; counter[w+1] := counter[w+1] + 1) ; skip ; for e1 : Integer.subrange(0, counter[w1+1] + 1-1) do ( for e2 : Integer.subrange(0, counter[w2+1] + 1-1) do ( for e3 : Integer.subrange(0, counter[w3+1] + 1-1) do ( for e4 : Integer.subrange(0, counter[w4+1] + 1-1) do ( var tmp : int := 0 ; if (w1 * e1 + w2 * e2 + w3 * e3 + w4 * e4->compareTo(W)) > 0 then ( continue ) else skip ; var i1 : OclAny := bll(wv, Sequence{w1, -Math_PINFINITY}) ; var i2 : OclAny := bll(wv, Sequence{w2, -Math_PINFINITY}) ; var i3 : OclAny := bll(wv, Sequence{w3, -Math_PINFINITY}) ; var i4 : OclAny := bll(wv, Sequence{w4, -Math_PINFINITY}) ; tmp := tmp + (wvv.subrange(i1+1, i1 + e1))->sum() + (wvv.subrange(i2+1, i2 + e2))->sum() + (wvv.subrange(i3+1, i3 + e3))->sum() + (wvv.subrange(i4+1, i4 + e4))->sum() ; ans := Set{ans, tmp}->max())))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(n,s): cnt=0 while n>0 : m=0 for i in range(1,n): if s[i]toInteger() ; for test_case : Integer.subrange(1, t + 1-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; s := sys.stdin.readLine().split()->select(y | true)->collect(y | (("" + ((y)))->toInteger())) ; execute (StringLib.format('Case #%d: %d',Sequence{test_case, solve(n, s)}))->display()); operation solve(n : OclAny, s : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; while n > 0 do ( var m : int := 0 ; for i : Integer.subrange(1, n-1) do ( if (s[i+1]->compareTo(s[m+1])) < 0 then ( m := i ) else skip) ; cnt := cnt + Set{m, n - 1 - m}->min() ; n := n - 1 ; execute (s[m+1])->isDeleted()) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import io,sys import datetime fin=None def solve(): n=num() a=nums() res=0 while a : t=min(a) idx=a.index(t) res+=min(idx,len(a)-idx-1) a.remove(t) return res def main(): fname='a.in' if len(sys.argv)>1 : fname=sys.argv[1] global fin fin=io.open(fname) fout=io.open(fname+'.txt','w') t0=datetime.datetime.now() t=int(fin.readline()) for i in range(t): fout.write('Case #%d: ' %(i+1)) fout.write('%s\n' % str(solve())) print('Time=%s' % str(datetime.datetime.now()-t0)) fin.close() fout.close() def nums(): return[int(x)for x in fin.readline().split()] def fnums(): return[float(x)for x in fin.readline().split()] def num(): return int(fin.readline()) def sstrip(): return fin.readline().strip() def strs(): return fin.readline().split() def arrstr(a,sep=' '): return sep.join([str(x)for x in a]) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute fin : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; var fin : OclAny := null ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve() : OclAny pre: true post: true activity: var n : OclAny := num() ; var a : OclAny := nums() ; var res : int := 0 ; while a do ( var t : OclAny := (a)->min() ; var idx : int := a->indexOf(t) - 1 ; res := res + Set{idx, (a)->size() - idx - 1}->min() ; execute ((t) /: a)) ; return res; operation main() pre: true post: true activity: var fname : String := 'a.in' ; if ((trailer . (name argv)))->size() > 1 then ( fname := (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) ) else skip ; skip ; fin := io.open(fname) ; var fout : OclAny := io.open(fname + '.txt', 'w') ; var t0 : OclAny := datetime.datetime.now() ; t := ("" + ((fin.readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( fout.write(StringLib.format('Case #%d: ',(i + 1))) ; fout.write(StringLib.format('%s ',("" + ((solve())))))) ; execute (StringLib.format('Time=%s',("" + ((datetime.datetime.now() - t0)))))->display() ; fin.closeFile() ; fout.closeFile(); operation nums() : OclAny pre: true post: true activity: return fin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation fnums() : OclAny pre: true post: true activity: return fin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation num() : OclAny pre: true post: true activity: return ("" + ((fin.readLine())))->toInteger(); operation sstrip() : OclAny pre: true post: true activity: return fin.readLine()->trim(); operation strs() : OclAny pre: true post: true activity: return fin.readLine().split(); operation arrstr(a : OclAny, sep : String) : OclAny pre: true post: true activity: if sep->oclIsUndefined() then sep := ' ' else skip; return StringLib.sumStringsWithSeparator((a->select(x | true)->collect(x | (("" + ((x)))))), sep); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(N,A): count=0 while A : size=len(A) if size==1 : break m=min(A) i=A.index(m) if isize() ; if size = 1 then ( break ) else skip ; var m : OclAny := (A)->min() ; var i : int := A->indexOf(m) - 1 ; if (i->compareTo(size - i - 1)) < 0 then ( count := count + i ) else ( count := count + size - i - 1 ) ; A := A->excludingAt(i+1)) ; return count; operation parse() : OclAny pre: true post: true activity: N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; A := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; return N, A; operation main() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(1, T + 1-1) do ( var params : OclAny := parse() ; var result : OclAny := solve((argument * (test (logical_test (comparison (expr (atom (name params)))))))) ; execute (StringLib.format('Case #%d: %s',Sequence{t, result}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys fin=open(sys.argv[1],"r") fout=open("p2.out","w") T=int(fin.readline()) for i in xrange(T): N=int(fin.readline()) A=map(int,fin.readline().split()) ans=0 for j in xrange(len(A)): l=0 r=0 for k in xrange(len(A)): if A[k]>A[j]: if ktoInteger() ; for i : xrange(T) do ( var N : int := ("" + ((fin.readLine())))->toInteger() ; var A : Sequence := (fin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; for j : xrange((A)->size()) do ( var l : int := 0 ; var r : int := 0 ; for k : xrange((A)->size()) do ( if (A[k+1]->compareTo(A[j+1])) > 0 then ( if (k->compareTo(j)) < 0 then ( l := l + 1 ) else ( r := r + 1 ) ) else skip) ; ans := ans + Set{l, r}->min()) ; fout.write("Case #" + ("" + ((i + 1))) + ": " + ("" + ((ans))) + "\n")); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def read_int(): return int(input()) def read_ints(): return map(int,input().split(' ')) t=read_int() for case_num in range(t): n=read_int() s=input() tot=0 for i in range(n-1): if s[i]==s[i+1]: tot+=1 print((tot+1)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var t : OclAny := read_int() ; for case_num : Integer.subrange(0, t-1) do ( var n : OclAny := read_int() ; var s : String := (OclFile["System.in"]).readLine() ; var tot : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if s[i+1] = s[i + 1+1] then ( tot := tot + 1 ) else skip) ; execute ((tot + 1) div 2)->display()); operation read_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation read_ints() : OclAny pre: true post: true activity: return (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def rl(T): return list(map(T,input().split())) def up_solve(A): iv=0 n=len(A) for i in range(n): for j in range(i+1,n): if A[i]>A[j]: iv+=1 return iv def down_solve(A): return up_solve(A[: :-1]) def count_larger(l,v): return len([_ for _ in l if _>v]) def solve(A): return sum(min(count_larger(A[: i],A[i]),count_larger(A[i :],A[i]))for i in range(len(A))) def main(): sys.setrecursionlimit(100000) T,=rl(int) for C in range(1,T+1): N,=rl(int) A=rl(int) ans=solve(A) print('Case #%d: %d' %(C,ans)) pass main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; main(); operation rl(T : OclAny) : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (T)->apply(_x) )); operation up_solve(A : OclAny) : OclAny pre: true post: true activity: var iv : int := 0 ; var n : int := (A)->size() ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if (A[i+1]->compareTo(A[j+1])) > 0 then ( iv := iv + 1 ) else skip)) ; return iv; operation down_solve(A : OclAny) : OclAny pre: true post: true activity: return up_solve(A(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))); operation count_larger(l : OclAny, v : OclAny) : OclAny pre: true post: true activity: return (l->select(_anon | (_anon->compareTo(v)) > 0)->collect(_anon | (_anon)))->size(); operation solve(A : OclAny) : OclAny pre: true post: true activity: return ((argument (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name count_larger)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name count_larger)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))) :)) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)))))))) ))))))))) )))))))))->sum(); operation main() pre: true post: true activity: sys.setrecursionlimit(100000) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name T)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name T)))))) ,)} := rl(OclType["int"]) ; for C : Integer.subrange(1, T + 1-1) do ((testlist_star_expr (test (logical_test (comparison (expr (atom (name N)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name N)))))) ,)} := rl(OclType["int"]) ; A := rl(OclType["int"]) ; var ans : OclAny := solve(A) ; execute (StringLib.format('Case #%d: %d',Sequence{C, ans}))->display()) ; skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : try : v,d=map(int,input().split()) f=[0]*(v+1) f[0],f[1]=1,2 for i in range(2,v+1): f[i]=(f[i-1]+f[i-2])% 1001 f.sort() c=1 for i in range(2,v+1): if f[i]-f[i-1]>=d : c+=1 print(c) except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( try ( var v : OclAny := null; var d : OclAny := null; Sequence{v,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (v + 1)) ; var f->first() : OclAny := null; var f[1+1] : OclAny := null; Sequence{f->first(),f[1+1]} := Sequence{1,2} ; for i : Integer.subrange(2, v + 1-1) do ( f[i+1] := (f[i - 1+1] + f[i - 2+1]) mod 1001) ; f := f->sort() ; var c : int := 1 ; for i : Integer.subrange(2, v + 1-1) do ( if (f[i+1] - f[i - 1+1]->compareTo(d)) >= 0 then ( c := c + 1 ) else skip) ; execute (c)->display()) catch (_e : OclException) do ( break) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=[0]*1001 f[0],f[1]=2,3 for i in range(2,1001): f[i]=(f[i-1]+f[i-2])% 1001 while True : try : V,d=map(int,input().split()) except : break ans,a=1,sorted(f[: V]) for i in range(1,V): if a[i]-a[i-1]>=d : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 1001) ; var f->first() : OclAny := null; var f[1+1] : OclAny := null; Sequence{f->first(),f[1+1]} := Sequence{2,3} ; for i : Integer.subrange(2, 1001-1) do ( f[i+1] := (f[i - 1+1] + f[i - 2+1]) mod 1001) ; while true do ( try ( var V : OclAny := null; var d : OclAny := null; Sequence{V,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )) catch (_e : OclException) do ( break) ; var ans : OclAny := null; var a : OclAny := null; Sequence{ans,a} := Sequence{1,f.subrange(1,V)->sort()} ; for i : Integer.subrange(1, V-1) do ( if (a[i+1] - a[i - 1+1]->compareTo(d)) >= 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def initSets(N): return[x for x in range(N)] def getRoot(arr,n): while arr[n]!=n : arr[n]=arr[arr[n]] n=arr[n] return n def union(arr,n,m): a=getRoot(arr,n) b=getRoot(arr,m) if a!=b : arr[a]=b def isSameSet(arr,n,m): return getRoot(arr,n)==getRoot(arr,m) def getFibs(): fibs=[] a=1 b=1 while len(fibs)<1000 : c=(a+b)% 1001 a=b b=c fibs.append(c) return fibs if __name__=='__main__' : try : FIBS=getFibs() while True : V,d=list(map(int,input().strip().split())) fibs=FIBS[: V] arr=initSets(V) for i in range(V): for j in range(i+1,V): if abs(fibs[i]-fibs[j])trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; fibs := FIBS.subrange(1,V) ; arr := initSets(V) ; for i : Integer.subrange(0, V-1) do ( for j : Integer.subrange(i + 1, V-1) do ( if ((fibs[i+1] - fibs[j+1])->abs()->compareTo(d)) < 0 then ( union(arr, i, j) ) else skip)) ; var subsets : OclAny := Set{} ; for i : Integer.subrange(0, V-1) do ( var root : OclAny := getRoot(arr, i) ; if (subsets)->includes(root) then ( (expr (atom (name subsets)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name root)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name fibs)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))) ) else ( subsets[root+1] := Sequence{ fibs[i+1] } )) ; execute ((subsets)->size())->display())) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt pass))))) ) else skip; operation initSets(N : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, N-1)->select(x | true)->collect(x | (x)); operation getRoot(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: while arr[n+1] /= n do ( arr[n+1] := arr[arr[n+1]+1] ; n := arr[n+1]) ; return n; operation union(arr : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: var a : OclAny := getRoot(arr, n) ; var b : OclAny := getRoot(arr, m) ; if a /= b then ( arr[a+1] := b ) else skip; operation isSameSet(arr : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: return getRoot(arr, n) = getRoot(arr, m); operation getFibs() : OclAny pre: true post: true activity: var fibs : Sequence := Sequence{} ; a := 1 ; b := 1 ; while (fibs)->size() < 1000 do ( var c : int := (a + b) mod 1001 ; a := b ; b := c ; execute ((c) : fibs)) ; return fibs; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque try : while 1 : V,d=map(int,input().split()) F=[0]*V a=b=1 for v in range(V): a,b=(a+b)% 1001,a F[v]=a G=[[]for i in range(V)] for i in range(V): for j in range(i+1,V): if abs(F[i]-F[j])collect( _x | (OclType["int"])->apply(_x) ) ; var F : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, V) ; var a : OclAny := 1; var b : int := 1 ; for v : Integer.subrange(0, V-1) do ( Sequence{a,b} := Sequence{(a + b) mod 1001,a} ; F[v+1] := a) ; var G : Sequence := Integer.subrange(0, V-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, V-1) do ( for j : Integer.subrange(i + 1, V-1) do ( if ((F[i+1] - F[j+1])->abs()->compareTo(d)) < 0 then ( (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ) else skip)) ; var L : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, V) ; var ans : int := 0 ; for i : Integer.subrange(0, V-1) do ( if L[i+1] then ( continue ) else skip ; ans := ans + 1 ; var que : Sequence := (Sequence{ i }) ; L[i+1] := 1 ; while que do ( var v : OclAny := que->first() ; que := que->tail() ; for w : G[v+1] do ( if L[w+1] then ( continue ) else skip ; execute ((w) : que) ; L[w+1] := 1))) ; execute (ans)->display())) catch (_e : OclException) do () ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfPrevK(N,K): arr=[0 for i in range(N)] arr[0]=1 for i in range(1,N): j=i-1 count=0 sum=0 while(j>=0 and countselect(i | true)->collect(i | (0)) ; arr->first() := 1 ; for i : Integer.subrange(1, N-1) do ( var j : double := i - 1 ; var count : int := 0 ; var sum : int := 0 ; while (j >= 0 & (count->compareTo(K)) < 0) do ( sum := sum + arr[j+1] ; j := j - 1 ; count := count + 1) ; arr[i+1] := sum) ; for i : Integer.subrange(0, N-1) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate n,w=map(int,input().split()) w_0,v_0=map(int,input().split()) v_list=[[]for _ in range(4)] v_list[0].append(v_0) for _ in range(n-1): w_in,v_in=map(int,input().split()) v_list[w_in-w_0].append(v_in) v_list=[[0]+list(accumulate(sorted(v,reverse=True)))for v in v_list] ans=0 for i in range(len(v_list[0])): for j in range(len(v_list[1])): for k in range(len(v_list[2])): for l in range(len(v_list[3])): if((i)*w_0)+((j)*(w_0+1))+((k)*(w_0+2))+(((l)*(w_0+3)))<=w : ans=max(ans,v_list[0][i]+v_list[1][j]+v_list[2][k]+v_list[3][l]) else : break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var w : OclAny := null; Sequence{n,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w_0 : OclAny := null; var v_0 : OclAny := null; Sequence{w_0,v_0} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var v_list : Sequence := Integer.subrange(0, 4-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; (expr (atom (name v_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v_0)))))))) )))) ; for _anon : Integer.subrange(0, n - 1-1) do ( var w_in : OclAny := null; var v_in : OclAny := null; Sequence{w_in,v_in} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name v_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name w_in))) - (expr (atom (name w_0))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v_in)))))))) ))))) ; v_list := v_list->select(v | true)->collect(v | (Sequence{ 0 }->union((accumulate(v->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True))))))))))))) ; var ans : int := 0 ; for i : Integer.subrange(0, (v_list->first())->size()-1) do ( for j : Integer.subrange(0, (v_list[1+1])->size()-1) do ( for k : Integer.subrange(0, (v_list[2+1])->size()-1) do ( for l : Integer.subrange(0, (v_list[3+1])->size()-1) do ( if (((i) * w_0) + ((j) * (w_0 + 1)) + ((k) * (w_0 + 2)) + (((l) * (w_0 + 3)))->compareTo(w)) <= 0 then ( ans := Set{ans, v_list->first()[i+1] + v_list[1+1][j+1] + v_list[2+1][k+1] + v_list[3+1][l+1]}->max() ) else ( break ))))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) minV=min(a) mI=[i for i in range(n)if a[i]==minV] num=minV*n maxDiff=0 for i,j in enumerate(mI): b=min(len(mI)-1,i+1) if(mI[b]-j>maxDiff): maxDiff=mI[b]-j-1 diff=max(n-1-mI[-1]+mI[0],maxDiff) print(num+diff) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var minV : OclAny := (a)->min() ; var mI : Sequence := Integer.subrange(0, n-1)->select(i | a[i+1] = minV)->collect(i | (i)) ; var num : double := minV * n ; var maxDiff : int := 0 ; for _tuple : Integer.subrange(1, (mI)->size())->collect( _indx | Sequence{_indx-1, (mI)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); var b : OclAny := Set{(mI)->size() - 1, i + 1}->min() ; if ((mI[b+1] - j->compareTo(maxDiff)) > 0) then ( maxDiff := mI[b+1] - j - 1 ) else skip) ; var diff : OclAny := Set{n - 1 - mI->last() + mI->first(), maxDiff}->max() ; execute (num + diff)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) m=min(a) v=[] for i in range(n): if a[i]==m : idx=i v.append(i); cnt=m*n ; mi=0 for i in range(1,len(v)): mi=max(mi,v[i]-v[i-1]-1) mi=max(mi,n-(v[len(v)-1]-v[0]+1)) print(mi+cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : OclAny := (a)->min() ; var v : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = m then ( var idx : OclAny := i ; execute ((i) : v); ) else skip) ; var cnt : double := m * n; ; var mi : int := 0 ; for i : Integer.subrange(1, (v)->size()-1) do ( mi := Set{mi, v[i+1] - v[i - 1+1] - 1}->max()) ; mi := Set{mi, n - (v[(v)->size() - 1+1] - v->first() + 1)}->max() ; execute (mi + cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) m=min(a) v=[] for i in range(n): if a[i]==m : idx=i v.append(i); cnt=m*n ; mi=0 for i in range(1,len(v)): mi=max(mi,v[i]-v[i-1]-1) mi=max(mi,n-(v[len(v)-1]-v[0]+1)) print(mi+cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : OclAny := (a)->min() ; var v : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = m then ( var idx : OclAny := i ; execute ((i) : v); ) else skip) ; var cnt : double := m * n; ; var mi : int := 0 ; for i : Integer.subrange(1, (v)->size()-1) do ( mi := Set{mi, v[i+1] - v[i - 1+1] - 1}->max()) ; mi := Set{mi, n - (v[(v)->size() - 1+1] - v->first() + 1)}->max() ; execute (mi + cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k,t,u,v,l=map(int,input().split()) time=0 line=[0 for _ in range(l)] carrots_line=[0 for _ in range(l)] boost=False carrots=0 boost_dist=0 for _ in range(n): carrots_line[int(input())-1]=1 for i in range(l): if boost : line[i]=1 boost_dist-=1 else : pass if boost_dist==0 : if carrots_line[i]==1 : boost_dist=v*t boost=True else : if carrots>0 : carrots-=1 boost_dist=v*t boost=True else : boost=False else : if carrots_line[i]==1 : if carrots+1>k : boost_dist=v*t else : carrots+=1 boost=True boost_run=sum(line) ans=boost_run/v+(l-boost_run)/u print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var t : OclAny := null; var u : OclAny := null; var v : OclAny := null; var l : OclAny := null; Sequence{n,k,t,u,v,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var time : int := 0 ; var line : Sequence := Integer.subrange(0, l-1)->select(_anon | true)->collect(_anon | (0)) ; var carrots_line : Sequence := Integer.subrange(0, l-1)->select(_anon | true)->collect(_anon | (0)) ; var boost : boolean := false ; var carrots : int := 0 ; var boost_dist : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( carrots_line[("" + (((OclFile["System.in"]).readLine())))->toInteger() - 1+1] := 1) ; for i : Integer.subrange(0, l-1) do ( if boost then ( line[i+1] := 1 ; boost_dist := boost_dist - 1 ) else ( skip ) ; if boost_dist = 0 then ( if carrots_line[i+1] = 1 then ( boost_dist := v * t ; boost := true ) else ( if carrots > 0 then ( carrots := carrots - 1 ; boost_dist := v * t ; boost := true ) else ( boost := false ) ) ) else ( if carrots_line[i+1] = 1 then ( if (carrots + 1->compareTo(k)) > 0 then ( boost_dist := v * t ) else ( carrots := carrots + 1 ) ) else skip ; boost := true )) ; var boost_run : OclAny := (line)->sum() ; var ans : double := boost_run / v + (l - boost_run) / u ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) m=min(a) v=[] for i in range(n): if a[i]==m : idx=i v.append(i); cnt=m*n ; mi=0 for i in range(1,len(v)): mi=max(mi,v[i]-v[i-1]-1) mi=max(mi,n-(v[len(v)-1]-v[0]+1)) print(mi+cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : OclAny := (a)->min() ; var v : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = m then ( var idx : OclAny := i ; execute ((i) : v); ) else skip) ; var cnt : double := m * n; ; var mi : int := 0 ; for i : Integer.subrange(1, (v)->size()-1) do ( mi := Set{mi, v[i+1] - v[i - 1+1] - 1}->max()) ; mi := Set{mi, n - (v[(v)->size() - 1+1] - v->first() + 1)}->max() ; execute (mi + cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) A=list(map(int,input().split())) mv=min(A) ind=[] left=0 first=A.index(mv) last=first for i,a in enumerate(A): if a==mv : left=max(left,i-last-1) last=i left=max(left,n-(last-first+1)) print(left+mv*n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mv : OclAny := (A)->min() ; var ind : Sequence := Sequence{} ; var left : int := 0 ; var first : int := A->indexOf(mv) - 1 ; var last : int := first ; for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); if a = mv then ( left := Set{left, i - last - 1}->max() ; last := i ) else skip) ; left := Set{left, n - (last - first + 1)}->max() ; execute (left + mv * n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print('AABBCD'[int(input())>=1000 : : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ('AABBCD'(subscript (test (logical_test (comparison (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))) >= (comparison (expr (atom (number (integer 1000)))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10000000) MOD=10**9+7 INF=10**15 def main(): N=int(input()) if N<1000 : print('ABC') else : print('ABD') if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(10000000) ; var MOD : double := (10)->pow(9) + 7 ; var INF : double := (10)->pow(15) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N < 1000 then ( execute ('ABC')->display() ) else ( execute ('ABD')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) def main(): ans="ABC" if N<1000 else "ABD" print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var ans : String := if N < 1000 then "ABC" else "ABD" endif ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) if(N>999): print("ABD") else : print("ABC") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (N > 999) then ( execute ("ABD")->display() ) else ( execute ("ABC")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(["ABC","ABD"][int(input())//1000]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (Sequence{"ABC"}->union(Sequence{ "ABD" })[("" + (((OclFile["System.in"]).readLine())))->toInteger() div 1000+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import numpy as np sr=lambda : sys.stdin.readline().rstrip() ir=lambda : int(sr()) lr=lambda : list(map(int,sr().split())) N,W=lr() WV=[lr()for _ in range(N)] base=WV[0][0] W0=[0]+sorted([v for w,v in WV if w==base+0],reverse=True) W1=[0]+sorted([v for w,v in WV if w==base+1],reverse=True) W2=[0]+sorted([v for w,v in WV if w==base+2],reverse=True) W3=[0]+sorted([v for w,v in WV if w==base+3],reverse=True) W0cum=np.array(W0).cumsum() W1cum=np.array(W1).cumsum() W2cum=np.array(W2).cumsum() W3cum=np.array(W3).cumsum() answer=0 for a in range(len(W0)): for b in range(len(W1)): for c in range(len(W2)): for d in range(len(W3)): remain=W-a*base-b*(base+1)-c*(base+2)-d*(base+3) if remain<0 : continue answer=max(answer,W0cum[a]+W1cum[b]+W2cum[c]+W3cum[d]) print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var sr : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var ir : Function := lambda $$ : OclAny in (("" + ((sr->apply())))->toInteger()) ; var lr : Function := lambda $$ : OclAny in (((sr->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var N : OclAny := null; var W : OclAny := null; Sequence{N,W} := lr->apply() ; var WV : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (lr->apply())) ; var base : OclAny := WV->first()->first() ; var W0 : Sequence := Sequence{ 0 }->union(WV->select(_tuple | let w : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in w = base + 0)->collect(_tuple | let w : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in (v))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True))))))))) ; var W1 : Sequence := Sequence{ 0 }->union(WV->select(_tuple | let w : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in w = base + 1)->collect(_tuple | let w : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in (v))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True))))))))) ; var W2 : Sequence := Sequence{ 0 }->union(WV->select(_tuple | let w : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in w = base + 2)->collect(_tuple | let w : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in (v))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True))))))))) ; var W3 : Sequence := Sequence{ 0 }->union(WV->select(_tuple | let w : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in w = base + 3)->collect(_tuple | let w : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in (v))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True))))))))) ; var W0cum : OclAny := np.array(W0).cumsum() ; var W1cum : OclAny := np.array(W1).cumsum() ; var W2cum : OclAny := np.array(W2).cumsum() ; var W3cum : OclAny := np.array(W3).cumsum() ; var answer : int := 0 ; for a : Integer.subrange(0, (W0)->size()-1) do ( for b : Integer.subrange(0, (W1)->size()-1) do ( for c : Integer.subrange(0, (W2)->size()-1) do ( for d : Integer.subrange(0, (W3)->size()-1) do ( var remain : double := W - a * base - b * (base + 1) - c * (base + 2) - d * (base + 3) ; if remain < 0 then ( continue ) else skip ; answer := Set{answer, W0cum[a+1] + W1cum[b+1] + W2cum[c+1] + W3cum[d+1]}->max())))) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : N,K=map(int,raw_input().split()) A=sorted([int(raw_input())for i in range(0,K)]) if(N,K)==(0,0): break if A[0]==0 : flag=True A=A[1 :] K-=1 else : flag=False ans=0 count=0 diff_list=[] s=0 for i in range(1,K): if A[i]-A[i-1]==2 : diff_list.append(A[i-1]-A[s]) s=i count=0 elif A[i]-A[i-1]>2 : diff_list.append(A[i-1]-A[s]) diff_list.append(0) s=i count=0 else : count+=1 ans=max(ans,count) else : diff_list.append(A[i]-A[s]) if flag is True : ans=0 for i in range(1,len(diff_list)): ans=max(ans,diff_list[i]+diff_list[i-1]+2) print(ans+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := Integer.subrange(0, K-1)->select(i | true)->collect(i | (("" + ((raw_input())))->toInteger()))->sort() ; if Sequence{N, K} = Sequence{0, 0} then ( break ) else skip ; if A->first() = 0 then ( var flag : boolean := true ; A := A->tail() ; K := K - 1 ) else ( flag := false ) ; var ans : int := 0 ; var count : int := 0 ; var diff_list : Sequence := Sequence{} ; var s : int := 0 ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name K)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))))) == (comparison (expr (atom (number (integer 2)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name diff_list)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))) - (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ]))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name count)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))))) > (comparison (expr (atom (number (integer 2)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name diff_list)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))) - (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ]))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name diff_list)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name count)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name count)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans))))))) , (argument (test (logical_test (comparison (expr (atom (name count)))))))) )))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name diff_list)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ]))))))))) ))))))))))))))) ; if flag <>= true then ( ans := 0 ; for i : Integer.subrange(1, (diff_list)->size()-1) do ( ans := Set{ans, diff_list[i+1] + diff_list[i - 1+1] + 2}->max()) ) else skip ; execute (ans + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(cards): if len(cards)==1 : return 1 has_white=True if cards[0]==0 else False res=[] t=[] prev=cards[has_white]-1 for c in cards[has_white :]: if c==prev+1 : t.append(c) else : res.append(t) t=[c] prev=c res.append(t) ans=max(len(r)+has_white for r in res) if has_white : for a,b in zip(res,res[1 :]): if a[-1]+2==b[0]: ans=max(ans,len(a)+len(b)+1) return ans def main(args): while True : n,k=map(int,input().split()) if n==0 and k==0 : break cards=sorted([int(input())for _ in range(k)]) ans=solve(cards) print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(cards : OclAny) : OclAny pre: true post: true activity: if (cards)->size() = 1 then ( return 1 ) else skip ; var has_white : boolean := if cards->first() = 0 then true else false endif ; var res : Sequence := Sequence{} ; var t : Sequence := Sequence{} ; var prev : double := cards[has_white+1] - 1 ; for c : cards.subrange(has_white+1) do ( if c = prev + 1 then ( execute ((c) : t) ) else ( execute ((t) : res) ; t := Sequence{ c } ) ; prev := c) ; execute ((t) : res) ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name r)))))))) )))) + (expr (atom (name has_white))))))) (comp_for for (exprlist (expr (atom (name r)))) in (logical_test (comparison (expr (atom (name res))))))))->max() ; if has_white then ( for _tuple : Integer.subrange(1, res->size())->collect( _indx | Sequence{res->at(_indx), res->tail()->at(_indx)} ) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if a->last() + 2 = b->first() then ( ans := Set{ans, (a)->size() + (b)->size() + 1}->max() ) else skip) ) else skip ; return ans; operation main(args : OclAny) pre: true post: true activity: while true do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 & k = 0 then ( break ) else skip ; cards := Integer.subrange(0, k-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))->sort() ; ans := solve(cards) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys EPS=1e-12 def main(): n,k,t,u,v,l=map(int,sys.stdin.readline().split()) carrots=[0]*10001 for i in range(n): carrots[int(sys.stdin.readline())]=1 remain_time=0 carrot_count=0 ans=0 for i in range(0,l): if carrots[i]==1 : carrot_count+=1 if carrot_count>k : remain_time=t carrot_count-=1 if remain_time>0+EPS : if remain_time*v>=1.0 : ans+=1/v remain_time-=1/v else : if carrot_count>0 : ans+=1/v carrot_count-=1 remain_time=t-(1-(remain_time*v))/v else : ans+=remain_time ans+=(1-(remain_time*v))/u remain_time=0 else : remain_time=0 if carrot_count>0 : ans+=1/v carrot_count-=1 remain_time=t-1/v else : ans+=1/u print("{:.9f}".format(ans)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var EPS : double := ("1e-12")->toReal() ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var t : OclAny := null; var u : OclAny := null; var v : OclAny := null; var l : OclAny := null; Sequence{n,k,t,u,v,l} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var carrots : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10001) ; for i : Integer.subrange(0, n-1) do ( carrots[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1] := 1) ; var remain_time : int := 0 ; var carrot_count : int := 0 ; var ans : int := 0 ; for i : Integer.subrange(0, l-1) do ( if carrots[i+1] = 1 then ( carrot_count := carrot_count + 1 ) else skip ; if (carrot_count->compareTo(k)) > 0 then ( remain_time := t ; carrot_count := carrot_count - 1 ) else skip ; if (remain_time->compareTo(0 + EPS)) > 0 then ( if remain_time * v >= 1.0 then ( ans := ans + 1 / v ; remain_time := remain_time - 1 / v ) else ( if carrot_count > 0 then ( ans := ans + 1 / v ; carrot_count := carrot_count - 1 ; remain_time := t - (1 - (remain_time * v)) / v ) else ( ans := ans + remain_time ; ans := ans + (1 - (remain_time * v)) / u ; remain_time := 0 ) ) ) else ( remain_time := 0 ; if carrot_count > 0 then ( ans := ans + 1 / v ; carrot_count := carrot_count - 1 ; remain_time := t - 1 / v ) else ( ans := ans + 1 / u ) )) ; execute (StringLib.interpolateStrings("{:.9f}", Sequence{ans}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,k=map(int,input().split()) if n==0 : break c=[0]*(n+2) f=0 ; for i in range(k): a=int(input()) if a==0 : f=1 else : c[a]=1 ans=w0=w=0 for i in range(1,n+1): if c[i]: w+=1 elif w>0 : if w0+w+f>ans : ans=w0+w+f w0=w if f and c[i+1]else 0 w=0 if w0+w+f>ans : ans=w0+w+f print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var c : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 2)) ; var f : int := 0; ; for i : Integer.subrange(0, k-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if a = 0 then ( f := 1 ) else ( c[a+1] := 1 )) ; ans := ans(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name w0)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name w)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for i : Integer.subrange(1, n + 1-1) do ( if c[i+1] then ( w := w + 1 ) else (if w > 0 then ( if (w0 + w + f->compareTo(ans)) > 0 then ( var ans : OclAny := w0 + w + f ) else skip ; var w0 : OclAny := if f & c[i + 1+1] then w else 0 endif ; var w : int := 0 ) else skip)) ; if (w0 + w + f->compareTo(ans)) > 0 then ( ans := w0 + w + f ) else skip ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- anss=[] flag=False def main(): N,K=[int(i)for i in input().split()] if N==K==0 : global flag flag=True return A=[int(input())for _ in range(K)] A.sort() zero=False if A[0]==0 : zero=True prev=-1 last_island=-1 current_streak=0 ans=0 for a in A : if prev==-1 or a==prev+1 : current_streak+=1 elif zero==True and a==prev+2 : last_island=current_streak current_streak=1 else : last_island=-1 current_streak=1 ans=max(current_streak+last_island+1,ans) prev=a global anss anss.append(ans) while not flag : main() for a in anss : print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute flag : OclAny; attribute anss : OclAny; operation initialise() pre: true post: true activity: var anss : Sequence := Sequence{} ; var flag : boolean := false ; skip ; while not(flag) do ( main()) ; for a : anss do ( execute (a)->display()); operation main() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if N = K & (K == 0) then ( skip ; flag := true ; return ) else skip ; var A : Sequence := Integer.subrange(0, K-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; A := A->sort() ; var zero : boolean := false ; if A->first() = 0 then ( zero := true ) else skip ; var prev : int := -1 ; var last_island : int := -1 ; var current_streak : int := 0 ; var ans : int := 0 ; for a : A do ( if prev = -1 or a = prev + 1 then ( current_streak := current_streak + 1 ) else (if zero = true & a = prev + 2 then ( last_island := current_streak ; current_streak := 1 ) else ( last_island := -1 ; current_streak := 1 ) ) ; ans := Set{current_streak + last_island + 1, ans}->max() ; prev := a) ; skip ; execute ((ans) : anss); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline while True : a=[] n,k=map(int,input().split()) if n==k==0 : break zero=False for i in range(k): p=int(input()) if p==0 : zero=True continue a.append(p) a.sort() if zero==False : r=a[0]-1 ans=0 ans_kari=0 for i in range(k): if a[i]==r+1 : r=a[i] ans_kari+=1 else : ans=max(ans,ans_kari) ans_kari=1 r=a[i] print(ans) else : sa=[] for i in range(k-2): sa.append(a[i+1]-a[i]) ans=l=r=0 for i in range(len(sa)): if sa[i]==1 : r+=1 elif sa[i]==2 : l=r r=1 else : l=0 r=1 ans=max(ans,l+r+1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; while true do ( var a : Sequence := Sequence{} ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = k & (k == 0) then ( break ) else skip ; var zero : boolean := false ; for i : Integer.subrange(0, k-1) do ( var p : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if p = 0 then ( zero := true ; continue ) else skip ; execute ((p) : a)) ; a := a->sort() ; if zero = false then ( var r : double := a->first() - 1 ; var ans : int := 0 ; var ans_kari : int := 0 ; for i : Integer.subrange(0, k-1) do ( if a[i+1] = r + 1 then ( r := a[i+1] ; ans_kari := ans_kari + 1 ) else ( ans := Set{ans, ans_kari}->max() ; ans_kari := 1 ; r := a[i+1] )) ; execute (ans)->display() ) else ( var sa : Sequence := Sequence{} ; for i : Integer.subrange(0, k - 2-1) do ( execute ((a[i + 1+1] - a[i+1]) : sa)) ; ans := ans(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name r)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for i : Integer.subrange(0, (sa)->size()-1) do ( if sa[i+1] = 1 then ( r := r + 1 ) else (if sa[i+1] = 2 then ( var l : OclAny := r ; r := 1 ) else ( l := 0 ; r := 1 ) ) ; ans := Set{ans, l + r + 1}->max()) ; execute (ans)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binarySearch(arr,low,high,x): if(high>=low): mid=low+(high-low)//2 if x==arr[mid]: return(mid) elif(x>arr[mid]): return binarySearch(arr,(mid+1),high,x) else : return binarySearch(arr,low,(mid-1),x) return-1 def countPairsWithDiffK(arr,n,k): count=0 arr.sort() for i in range(0,n-2): if(binarySearch(arr,i+1,n-1,arr[i]+k)!=-1): count+=1 return count arr=[1,5,3,4,2] n=len(arr) k=3 print("Count of pairs with given diff is ",countPairsWithDiffK(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{1}->union(Sequence{5}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 2 })))) ; n := (arr)->size() ; k := 3 ; execute ("Count of pairs with given diff is ")->display(); operation binarySearch(arr : OclAny, low : OclAny, high : OclAny, x : OclAny) : OclAny pre: true post: true activity: if ((high->compareTo(low)) >= 0) then ( var mid : OclAny := low + (high - low) div 2 ; if x = arr[mid+1] then ( return (mid) ) else (if ((x->compareTo(arr[mid+1])) > 0) then ( return binarySearch(arr, (mid + 1), high, x) ) else ( return binarySearch(arr, low, (mid - 1), x) ) ) ) else skip ; return -1; operation countPairsWithDiffK(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; arr := arr->sort() ; for i : Integer.subrange(0, n - 2-1) do ( if (binarySearch(arr, i + 1, n - 1, arr[i+1] + k) /= -1) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) d=list(map(int,input().split())) M={} for di in d : if di not in M : M[di]=0 M[di]+=1 d.sort() x=d[-1] for i in range(1,x+1): if x % i==0 : M[i]-=1 y=0 for di in M : if M[di]==1 : y=max(y,di) print(x,y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var M : OclAny := Set{} ; for di : d do ( if (M)->excludes(di) then ( M[di+1] := 0 ) else skip ; M[di+1] := M[di+1] + 1) ; d := d->sort() ; var x : OclAny := d->last() ; for i : Integer.subrange(1, x + 1-1) do ( if x mod i = 0 then ( M[i+1] := M[i+1] - 1 ) else skip) ; var y : int := 0 ; for di : M do ( if M[di+1] = 1 then ( y := Set{y, di}->max() ) else skip) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) num=list(map(int,input().split())) num.sort() x=num[n-1] for i in range(1,x+1): if(x % i==0): if(i in num): num.remove(i) print(x,num[len(num)-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var num : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; num := num->sort() ; var x : OclAny := num[n - 1+1] ; for i : Integer.subrange(1, x + 1-1) do ( if (x mod i = 0) then ( if ((num)->includes(i)) then ( execute ((i) /: num) ) else skip ) else skip) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) arr.sort() y=arr[-1] for i in range(1,y+1): if(y % i==0): arr.remove(i) print(y,max(arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := arr->sort() ; var y : OclAny := arr->last() ; for i : Integer.subrange(1, y + 1-1) do ( if (y mod i = 0) then ( execute ((i) /: arr) ) else skip) ; execute (y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=sorted(list(map(int,input().split())),reverse=True) a=arr[0] for i in range(1,n): if arr[i]==a or a % arr[i]or arr[i]==arr[i-1]: print(a,arr[i]) exit(0) print(a,1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var a : OclAny := arr->first() ; for i : Integer.subrange(1, n-1) do ( if arr[i+1] = a or a mod arr[i+1] or arr[i+1] = arr[i - 1+1] then ( execute (a)->display() ; exit(0) ) else skip) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,W=map(int,input().split()) w0,v=map(int,input().split()) goods=[[v],[],[],[]] for i in range(N-1): w,v=map(int,input().split()) goods[w-w0].append(v) val=[] for x in range(4): goods[x].sort(reverse=True) valx=[0]*(len(goods[x])+1) for k in range(len(goods[x])): valx[k+1]=valx[k]+goods[x][k] val.append(valx) ans=0 for i in range(len(goods[0])+1): if w0*i>W : break for j in range(len(goods[1])+1): if w0*(i+j)+j>W : break for k in range(len(goods[2])+1): if w0*(i+j+k)+j+2*k>W : break for l in range(len(goods[3])+1): if w0*(i+j+k+l)+j+2*k+3*l>W : break ans=max(ans,val[0][i]+val[1][j]+val[2][k]+val[3][l]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var W : OclAny := null; Sequence{N,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w0 : OclAny := null; var v : OclAny := null; Sequence{w0,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var goods : Sequence := Sequence{Sequence{ v }}->union(Sequence{Sequence{}}->union(Sequence{Sequence{}}->union(Sequence{ Sequence{} }))) ; for i : Integer.subrange(0, N - 1-1) do ( var w : OclAny := null; var v : OclAny := null; Sequence{w,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name goods)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name w))) - (expr (atom (name w0))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) ))))) ; var val : Sequence := Sequence{} ; for x : Integer.subrange(0, 4-1) do ((expr (atom (name goods)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name sort) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) )))) ; var valx : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((goods[x+1])->size() + 1)) ; for k : Integer.subrange(0, (goods[x+1])->size()-1) do ( valx[k + 1+1] := valx[k+1] + goods[x+1][k+1]) ; execute ((valx) : val)) ; var ans : int := 0 ; for i : Integer.subrange(0, (goods->first())->size() + 1-1) do ( if (w0 * i->compareTo(W)) > 0 then ( break ) else skip ; for j : Integer.subrange(0, (goods[1+1])->size() + 1-1) do ( if (w0 * (i + j) + j->compareTo(W)) > 0 then ( break ) else skip ; for k : Integer.subrange(0, (goods[2+1])->size() + 1-1) do ( if (w0 * (i + j + k) + j + 2 * k->compareTo(W)) > 0 then ( break ) else skip ; for l : Integer.subrange(0, (goods[3+1])->size() + 1-1) do ( if (w0 * (i + j + k + l) + j + 2 * k + 3 * l->compareTo(W)) > 0 then ( break ) else skip ; ans := Set{ans, val->first()[i+1] + val[1+1][j+1] + val[2+1][k+1] + val[3+1][l+1]}->max())))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin tt=1 ANS=[] for loop in range(tt): n=int(stdin.readline()) d=list(map(int,stdin.readline().split())) d.sort() dic={} for i in d : if i not in dic : dic[i]=0 dic[i]+=1 gcd=0 for i in dic : if dic[i]>=2 : gcd=max(gcd,i) if gcd==d[-1]: a,b=gcd,gcd else : a=d[-1] for i in range(n-2,-1,-1): if d[i]==gcd or a % d[i]!=0 : b=d[i] break ANS.append(str(a)+" "+str(b)) print("\n".join(map(str,ANS))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var tt : int := 1 ; var ANS : Sequence := Sequence{} ; for loop : Integer.subrange(0, tt-1) do ( var n : int := ("" + ((stdin.readLine())))->toInteger() ; var d : Sequence := ((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; d := d->sort() ; var dic : OclAny := Set{} ; for i : d do ( if (dic)->excludes(i) then ( dic[i+1] := 0 ) else skip ; dic[i+1] := dic[i+1] + 1) ; var gcd : int := 0 ; for i : dic do ( if dic[i+1] >= 2 then ( gcd := Set{gcd, i}->max() ) else skip) ; if gcd = d->last() then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{gcd,gcd} ) else ( var a : OclAny := d->last() ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( if d[i+1] = gcd or a mod d[i+1] /= 0 then ( var b : OclAny := d[i+1] ; break ) else skip) ) ; execute ((("" + ((a))) + " " + ("" + ((b)))) : ANS)) ; execute (StringLib.sumStringsWithSeparator(((ANS)->collect( _x | (OclType["String"])->apply(_x) )), "\n"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k,t,u,v,l,*d=map(int,open(0).read().split()) ans=d[0]/u fin=d[0] fastend=d[0]+v*t stack=0 for now in d[1 :]: while stack and fastendl : print(ans+(l-fin)/v) else : ans+=(fastend-fin)/v fin=fastend print(ans+(l-fin)/u) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var t : OclAny := null; var u : OclAny := null; var v : OclAny := null; var l : OclAny := null; var d : OclAny := null; Sequence{n,k,t,u,v,l,d} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : double := d->first() / u ; var fin : OclAny := d->first() ; var fastend : OclAny := d->first() + v * t ; var stack : int := 0 ; for now : d->tail() do ( while stack & (fastend->compareTo(now)) < 0 do ( ans := ans + (fastend - fin) / v ; fin := fastend ; fastend := fastend + v * t ; stack := stack - 1) ; if (fastend->compareTo(now)) < 0 then ( ans := ans + (fastend - fin) / v + (now - fastend) / u ; fin := now ; fastend := now + v * t ) else (if fastend = now then ( ans := ans + (fastend - fin) / v ; fin := now ; fastend := now + v * t ) else (if stack = k then ( ans := ans + (now - fin) / v ; fin := now ; fastend := now + v * t ) else ( stack := stack + 1 ) ) ) ) ; while stack & (fastend->compareTo(l)) <= 0 do ( ans := ans + (fastend - fin) / v ; fin := fastend ; fastend := fastend + v * t ; stack := stack - 1) ; if (fastend->compareTo(l)) > 0 then ( execute (ans + (l - fin) / v)->display() ) else ( ans := ans + (fastend - fin) / v ; fin := fastend ; execute (ans + (l - fin) / u)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def s(): from itertools import permutations as P for e in iter(input,'0'): n,k=int(e),int(input()) C=[input()for _ in[0]*n] print(len(set(''.join(s)for s in P(C,k)))) if '__main__'==__name__ : s() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if '__main__' = __name__ then ( s() ) else skip; operation s() pre: true post: true activity: skip ; for e : OclIterator.newOclIterator_Sequence(input, '0') do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := Sequence{("" + ((e)))->toInteger(),("" + (((OclFile["System.in"]).readLine())))->toInteger()} ; var C : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; execute ((Set{}->union(((argument (test (logical_test (comparison (expr (atom '') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name P)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name C))))))) , (argument (test (logical_test (comparison (expr (atom (name k)))))))) )))))))))))->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=k=0 cards=[] mini_ans={} def dfs(s : list)->None : global n,k,cards,mini_ans if len(s)==k : string="" for i in s : string+=cards[i] mini_ans.add(string) return for i in range(n): if i not in s : dfs(s+[i]) def main()->None : ans=[] global n,k,cards,mini_ans while True : n,k=[int(input())for _ in range(2)] if n+k==0 : break cards=[input()for _ in range(n)] mini_ans=set() dfs([]) ans+=[len(mini_ans)] print("\n".join(map(str,ans))) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute n : OclAny; attribute k : OclAny; attribute cards : OclAny; attribute mini_ans : OclAny; attribute n : OclAny; attribute k : OclAny; attribute cards : OclAny; attribute mini_ans : OclAny; operation initialise() pre: true post: true activity: var n : OclAny := 0; var k : int := 0 ; var cards : Sequence := Sequence{} ; var mini_ans : OclAny := Set{} ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation dfs(s : Sequence(OclAny)) : OclAny pre: true post: true activity: skip; skip; skip; skip ; if (s)->size() = k then ( var string : String := "" ; for i : s do ( string := string + cards[i+1]) ; execute ((string) : mini_ans) ; return ) else skip ; for i : Integer.subrange(0, n-1) do ( if (s)->excludes(i) then ( dfs(s->union(Sequence{ i })) ) else skip); operation main() : OclAny pre: true post: true activity: var ans : Sequence := Sequence{} ; skip; skip; skip; skip ; while true do ( Sequence{n,k} := Integer.subrange(0, 2-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; if n + k = 0 then ( break ) else skip ; cards := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; mini_ans := Set{}->union(()) ; dfs(Sequence{}) ; ans := ans + Sequence{ (mini_ans)->size() }) ; execute (StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), "\n"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import itertools if sys.platform=='win32' : sys.stdin=open('input.txt') def MAP(): return[int(x)for x in input().split()] while True : N=int(input()) K=int(input()) if N==0 and K==0 : break a=[int(input())for _ in range(N)] perm=itertools.permutations(a,K) nums=[] for p in perm : num='' for s in p : num+=str(s) nums.append(int(num)) print(len(set(nums))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if OclProcess.getEnvironmentProperty("OS") = 'win32' then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('input.txt')) ) else skip ; skip ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 & K = 0 then ( break ) else skip ; var a : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var perm : OclAny := itertools.permutations(a, K) ; var nums : Sequence := Sequence{} ; for p : perm do ( var num : String := '' ; for s : p do ( num := num + ("" + ((s)))) ; execute ((("" + ((num)))->toInteger()) : nums)) ; execute ((Set{}->union((nums)))->size())->display()); operation MAP() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) k=int(input()) if n==k==0 : break card=[] ans=[] for i in range(n): card.append(str(input())) if k==2 : for i in range(n): for j in range(n): if i==j : continue ans.append(card[i]+card[j]) elif k==3 : for i in range(n): for j in range(n): if i==j : continue for k in range(n): if i==k or j==k : continue ans.append(card[i]+card[j]+card[k]) elif k==4 : for i in range(n): for j in range(n): if i==j : continue for k in range(n): if i==k or j==k : continue for l in range(n): if i==l or j==l or k==l : continue ans.append(card[i]+card[j]+card[k]+card[l]) ans=list(set(ans)) print(len(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = k & (k == 0) then ( break ) else skip ; var card : Sequence := Sequence{} ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))) : card)) ; if k = 2 then ( for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if i = j then ( continue ) else skip ; execute ((card[i+1] + card[j+1]) : ans))) ) else (if k = 3 then ( for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if i = j then ( continue ) else skip ; for k : Integer.subrange(0, n-1) do ( if i = k or j = k then ( continue ) else skip ; execute ((card[i+1] + card[j+1] + card[k+1]) : ans)))) ) else (if k = 4 then ( for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if i = j then ( continue ) else skip ; for k : Integer.subrange(0, n-1) do ( if i = k or j = k then ( continue ) else skip ; for l : Integer.subrange(0, n-1) do ( if i = l or j = l or k = l then ( continue ) else skip ; execute ((card[i+1] + card[j+1] + card[k+1] + card[l+1]) : ans))))) ) else skip ) ) ; ans := (Set{}->union((ans))) ; execute ((ans)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import permutations as P import sys r=sys.stdin.readline for e in iter(r,'0\n'): n,k=int(e),int(r()) C=[r()[:-1]for _ in[0]*n] print(len(set(''.join(s)for s in P(C,k)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var r : OclAny := (OclFile["System.in"]).readline ; for e : OclIterator.newOclIterator_Sequence(r, '0 ') do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := Sequence{("" + ((e)))->toInteger(),("" + ((r())))->toInteger()} ; var C : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n)->select(_anon | true)->collect(_anon | (r()->front())) ; execute ((Set{}->union(((argument (test (logical_test (comparison (expr (atom '') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name P)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name C))))))) , (argument (test (logical_test (comparison (expr (atom (name k)))))))) )))))))))))->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(i)-1 for i in input().split()] count=0 if a[-1]==n-1 : b=a[-1] a[-1]=a[-2] a[-2]=b count=1 for i in range(n): if a[i]==i : b=a[i] a[i]=a[i+1] a[i+1]=b count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger() - 1)) ; var count : int := 0 ; if a->last() = n - 1 then ( var b : OclAny := a->last() ; a->last() := a->front()->last() ; a->front()->last() := b ; count := 1 ) else skip ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = i then ( b := a[i+1] ; a[i+1] := a[i + 1+1] ; a[i + 1+1] := b ; count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from statistics import mean,median,variance,stdev import numpy as np import sys import math import fractions import itertools import copy from operator import itemgetter def j(q): if q==1 : print("YES") else : print("NO") exit(0) def ct(x,y): if(x>y): print("+") elif(xselect(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var prev : int := 0 ; var s : int := 0 ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = i + 1 then ( s := s + 1 ; if prev then ( s := s - 1 ; prev := 0 ) else ( prev := 1 ) ) else ( prev := 0 )) ; execute (s)->display(); operation j(q : OclAny) pre: true post: true activity: if q = 1 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ; exit(0); operation ct(x : OclAny, y : OclAny) pre: true post: true activity: if ((x->compareTo(y)) > 0) then ( execute ("+")->display() ) else (if ((x->compareTo(y)) < 0) then ( execute ("-")->display() ) else ( execute ("?")->display() ) ) ; operation ip() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,ps): base=list(range(1,n+1)) res=0 for i in range(n): if base[i]==ps[i]: if icompareTo(n - 1)) < 0 then ( var ps[i+1] : OclAny := null; var ps[i + 1+1] : OclAny := null; Sequence{ps[i+1],ps[i + 1+1]} := Sequence{ps[i + 1+1],ps[i+1]} ) else ( var ps[i+1] : OclAny := null; var ps[i - 1+1] : OclAny := null; Sequence{ps[i+1],ps[i - 1+1]} := Sequence{ps[i - 1+1],ps[i+1]} ) ; res := res + 1 ) else skip) ; return res; operation main() pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; ps := input().split()->select(p | true)->collect(p | (("" + ((p)))->toInteger())) ; execute (solve(n, ps))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) p=list(map(int,input().split())) ans=0 tmp=0 for i in range(1,n+1): if p[i-1]==i : tmp+=1 elif tmp>1 : ans+=math.ceil(tmp/2) tmp=0 elif tmp==1 : ans+=tmp tmp=0 if tmp>1 : ans+=math.ceil(tmp/2) tmp=0 elif tmp==1 : ans+=tmp tmp=0 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; var tmp : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( if p[i - 1+1] = i then ( tmp := tmp + 1 ) else (if tmp > 1 then ( ans := ans + (tmp / 2)->ceil() ; tmp := 0 ) else (if tmp = 1 then ( ans := ans + tmp ; tmp := 0 ) else skip ) ) ) ; if tmp > 1 then ( ans := ans + (tmp / 2)->ceil() ; tmp := 0 ) else (if tmp = 1 then ( ans := ans + tmp ; tmp := 0 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- word=input() sentences=[] while True : s=input() if s=="END_OF_TEXT" : break sentences+=list(map(lambda sentence : sentence.lower(),s.split())) print(sentences.count(word)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var word : String := (OclFile["System.in"]).readLine() ; var sentences : Sequence := Sequence{} ; while true do ( var s : String := (OclFile["System.in"]).readLine() ; if s = "END_OF_TEXT" then ( break ) else skip ; sentences := sentences + ((s.split())->collect( _x | (lambda sentence : OclAny in (sentence->toLowerCase()))->apply(_x) ))) ; execute (sentences->count(word))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def waysToSplit(s): n=len(s); answer=0 ; prefix=[0]*n ; suffix=[0]*n ; seen=[0]*26 ; for i in range(n): prev=prefix[i-1]if(i-1>=0)else 0 ; if(seen[ord(s[i])-ord('a')]==0): prefix[i]+=(prev+1); else : prefix[i]=prev ; seen[ord(s[i])-ord('a')]=1 ; seen=[0]*len(seen); suffix[n-1]=0 ; for i in range(n-1,0,-1): prev=suffix[i]; if(seen[ord(s[i])-ord('a')]==0): suffix[i-1]+=(prev+1); else : suffix[i-1]=prev ; seen[ord(s[i])-ord('a')]=1 ; for i in range(n): if(prefix[i]==suffix[i]): answer+=1 ; return answer ; if __name__=="__main__" : s="ababa" ; print(waysToSplit(s)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "ababa"; ; execute (waysToSplit(s))->display(); ) else skip; operation waysToSplit(s : OclAny) pre: true post: true activity: var n : int := (s)->size(); ; var answer : int := 0; ; var prefix : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; var suffix : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; var seen : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26); ; for i : Integer.subrange(0, n-1) do ( var prev : OclAny := if (i - 1 >= 0) then prefix[i - 1+1] else 0 endif; ; if (seen[(s[i+1])->char2byte() - ('a')->char2byte()+1] = 0) then ( prefix[i+1] := prefix[i+1] + (prev + 1); ) else ( prefix[i+1] := prev; ) ; seen[(s[i+1])->char2byte() - ('a')->char2byte()+1] := 1;) ; seen := MatrixLib.elementwiseMult(Sequence{ 0 }, (seen)->size()); ; suffix[n - 1+1] := 0; ; for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( prev := suffix[i+1]; ; if (seen[(s[i+1])->char2byte() - ('a')->char2byte()+1] = 0) then ( suffix[i - 1+1] := suffix[i - 1+1] + (prev + 1); ) else ( suffix[i - 1+1] := prev; ) ; seen[(s[i+1])->char2byte() - ('a')->char2byte()+1] := 1;) ; for i : Integer.subrange(0, n-1) do ( if (prefix[i+1] = suffix[i+1]) then ( answer := answer + 1; ) else skip) ; return answer;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- *p,=map(int,open(0).read().split()) p+=0, a=0 for i,t in enumerate(p): if i==t : a+=1 p[i+1]=0 print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: (testlist_star_expr (star_expr * (expr (atom (name p)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name p)))) ,)} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; p := p + (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))) ,) ; var a : int := 0 ; for _tuple : Integer.subrange(1, (p)->size())->collect( _indx | Sequence{_indx-1, (p)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); if i = t then ( a := a + 1 ; p[i + 1+1] := 0 ) else skip) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if n==0 : break a,b,i=[0]*n,0,0 for c in input(): if c=="M" : a[i]+=1 elif c=="S" : a[i],b=0,b+1+a[i] elif c=="L" : a[i],b=a[i]+1+b,0 i=(i+1)% n a.sort() print(" ".join(map(str,a+[b]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var a : OclAny := null; var b : OclAny := null; var i : OclAny := null; Sequence{a,b,i} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, n),0,0} ; for c : (OclFile["System.in"]).readLine() do ( if c = "M" then ( a[i+1] := a[i+1] + 1 ) else (if c = "S" then ( var a[i+1] : OclAny := null; var b : OclAny := null; Sequence{a[i+1],b} := Sequence{0,b + 1 + a[i+1]} ) else (if c = "L" then ( var a[i+1] : OclAny := null; var b : OclAny := null; Sequence{a[i+1],b} := Sequence{a[i+1] + 1 + b,0} ) else skip ) ) ; var i : int := (i + 1) mod n) ; a := a->sort() ; execute (StringLib.sumStringsWithSeparator(((a->union(Sequence{ b }))->collect( _x | (OclType["String"])->apply(_x) )), " "))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ans(n,s): p=[[]for i in range(n)] h=[] i=0 while True : if s==[]: break c=s.pop(0) if c=='M' : if p[i]==[]: p[i]=[c] else : p[i].append(c) elif c=='L' : if p[i]==[]: p[i]=[c] else : p[i].append(c) if h!=[]: p[i]+=h h=[] elif c=='S' : if h==[]: h=[c] else : h.append(c) if p[i]!=[]: h+=p[i] p[i]=[] i=(i+1)% n pp=list(sorted(map(len,p))) hh=len(h) pp.append(hh) return " ".join(map(str,pp)) while True : n=int(input()) if n==0 : break s=list(input()) o=ans(n,s) print(o) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; s := ((OclFile["System.in"]).readLine())->characters() ; var o : OclAny := ans(n, s) ; execute (o)->display()); operation ans(n : OclAny, s : OclAny) : OclAny pre: true post: true activity: var p : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; var h : Sequence := Sequence{} ; var i : int := 0 ; while true do ( if s = Sequence{} then ( break ) else skip ; var c : OclAny := s->at(0`firstArg+1) ; s := s->excludingAt(0+1) ; if c = 'M' then ( if p[i+1] = Sequence{} then ( p[i+1] := Sequence{ c } ) else ( (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))) ) ) else (if c = 'L' then ( if p[i+1] = Sequence{} then ( p[i+1] := Sequence{ c } ) else ( (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))) ) ; if h /= Sequence{} then ( p[i+1] := p[i+1] + h ) else skip ; h := Sequence{} ) else (if c = 'S' then ( if h = Sequence{} then ( h := Sequence{ c } ) else ( execute ((c) : h) ) ; if p[i+1] /= Sequence{} then ( h := h + p[i+1] ) else skip ; p[i+1] := Sequence{} ) else skip ) ) ; i := (i + 1) mod n) ; var pp : Sequence := ((p)->collect( _x | (len)->apply(_x) )->sort()) ; var hh : int := (h)->size() ; execute ((hh) : pp) ; return StringLib.sumStringsWithSeparator(((pp)->collect( _x | (OclType["String"])->apply(_x) )), " "); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while(True): N=int(input()) if N==0 : break S=str(input()) L=len(S) F={"M" : 0,"S" : 0,"L" : 0} hands=[{"M" : 0,"S" : 0,"L" : 0}for _ in range(N)] cur=0 while(cur!=L): if S[cur]=="M" : hands[cur % N]["M"]+=1 elif S[cur]=="S" : F["M"]+=hands[cur % N]["M"] hands[cur % N]["M"]=0 F["S"]+=hands[cur % N]["S"]+1 hands[cur % N]["S"]=0 F["L"]+=hands[cur % N]["L"] hands[cur % N]["L"]=0 else : hands[cur % N]["M"]+=F["M"] F["M"]=0 hands[cur % N]["S"]+=F["S"] F["S"]=0 hands[cur % N]["L"]+=F["L"]+1 F["L"]=0 cur+=1 ans=[sum(d.values())for d in hands] ans=sorted(ans) for e in ans : print(e,end=" ") print(sum(F.values())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while (true) do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var S : String := ("" + (((OclFile["System.in"]).readLine()))) ; var L : int := (S)->size() ; var F : Map := Map{ "M" |-> 0 }->union(Map{ "S" |-> 0 }->union(Map{ "L" |-> 0 })) ; var hands : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Map{ "M" |-> 0 }->union(Map{ "S" |-> 0 }->union(Map{ "L" |-> 0 })))) ; var cur : int := 0 ; while (cur /= L) do ( if S[cur+1] = "M" then ( hands[cur mod N+1]->at("M") := hands[cur mod N+1]->at("M") + 1 ) else (if S[cur+1] = "S" then ( F->at("M") := F->at("M") + hands[cur mod N+1]->at("M") ; hands[cur mod N+1]->at("M") := 0 ; F->at("S") := F->at("S") + hands[cur mod N+1]->at("S") + 1 ; hands[cur mod N+1]->at("S") := 0 ; F->at("L") := F->at("L") + hands[cur mod N+1]->at("L") ; hands[cur mod N+1]->at("L") := 0 ) else ( hands[cur mod N+1]->at("M") := hands[cur mod N+1]->at("M") + F->at("M") ; F->at("M") := 0 ; hands[cur mod N+1]->at("S") := hands[cur mod N+1]->at("S") + F->at("S") ; F->at("S") := 0 ; hands[cur mod N+1]->at("L") := hands[cur mod N+1]->at("L") + F->at("L") + 1 ; F->at("L") := 0 ) ) ; cur := cur + 1) ; var ans : Sequence := hands->select(d | true)->collect(d | ((d.values())->sum())) ; ans := ans->sort() ; for e : ans do ( execute (e)->display()) ; execute ((F.values())->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(N,C): points=[0]*(N+1) for i,c in enumerate(C,start=1): pos=N if i % N==0 else i % N if c=='M' : points[pos]+=1 elif c=='S' : points[0]+=(points[pos]+1) points[pos]=0 else : points[pos]+=(points[0]+1) points[0]=0 return sorted(points[1 :])+[points[0]] def main(args): while True : N=int(input()) if N==0 : break C=input() ans=solve(N,C) print(*ans,sep=' ') if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(N : OclAny, C : OclAny) : OclAny pre: true post: true activity: var points : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; for _tuple : Integer.subrange(1, (C, (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->size())->collect( _indx | Sequence{_indx-1, (C, (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); var pos : OclAny := if i mod N = 0 then N else i mod N endif ; if c = 'M' then ( points[pos+1] := points[pos+1] + 1 ) else (if c = 'S' then ( points->first() := points->first() + (points[pos+1] + 1) ; points[pos+1] := 0 ) else ( points[pos+1] := points[pos+1] + (points->first() + 1) ; points->first() := 0 ) ) ) ; return points->tail()->sort()->union(Sequence{ points->first() }); operation main(args : OclAny) pre: true post: true activity: while true do ( N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; C := (OclFile["System.in"]).readLine() ; var ans : OclAny := solve(N, C) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : ba=0 p=[0 for i in range(int(input()))] if len(p)==0 : break for i,v in enumerate(list(input())): p[i % len(p)]+=1 if v=='L' : p[i % len(p)]+=ba ba=0 elif v=='S' : ba+=p[i % len(p)] p[i % len(p)]=0 result='' for v in sorted(p): result+='%d ' % v result+=str(ba) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var ba : int := 0 ; var p : Sequence := Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1)->select(i | true)->collect(i | (0)) ; if (p)->size() = 0 then ( break ) else skip ; for _tuple : Integer.subrange(1, (((OclFile["System.in"]).readLine())->characters())->size())->collect( _indx | Sequence{_indx-1, (((OclFile["System.in"]).readLine())->characters())->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); p[i mod (p)->size()+1] := p[i mod (p)->size()+1] + 1 ; if v = 'L' then ( p[i mod (p)->size()+1] := p[i mod (p)->size()+1] + ba ; ba := 0 ) else (if v = 'S' then ( ba := ba + p[i mod (p)->size()+1] ; p[i mod (p)->size()+1] := 0 ) else skip)) ; var result : String := '' ; for v : p->sort() do ( result := result + StringLib.format('%d ',v)) ; result := result + ("" + ((ba))) ; execute (result)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter import math hpop=heappop hpush=heappush def solution(): def dp(start,m,n): same_count=0 cur=start i=1 while m>0 and n>0 : cur=not cur if i % 2 else cur same_count+=(i % 2==0) i+=1 if cur : m-=1 else : n-=1 if m : same_count+=m-1+(cur==True) if n : same_count+=n-1+(cur==False) return same_count m,n=map(int,input().split()) res=max(dp(True,m-1,n),dp(False,m,n-1)) print(res,m+n-1-res) def main(): t=1 for _ in range(t): solution() import sys import threading sys.setrecursionlimit(1<<30) threading.stack_size(1<<27) thread=threading.Thread(target=main) thread.start(); thread.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1 * (2->pow(30))) ; threading.stack_size(1 * (2->pow(27))) ; var thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ; thread.start(); thread.join(); operation solution() pre: true post: true activity: skip ; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var res : OclAny := Set{dp(true, m - 1, n), dp(false, m, n - 1)}->max() ; execute (res)->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[int(item)for item in input().split(" ")] print(f"{max(a)-1}{min(a)}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := input().split(" ")->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; execute (StringLib.formattedString("{max(a)-1}{min(a)}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) print(max(n,m)-1,min(n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{n, m}->max() - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=sorted(map(int,input().split())); print(b-1,a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort(); execute (b - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def compute(): TURNS=15 ways=[[1]] for i in range(1,TURNS+1): row=[] for j in range(i+1): temp=0 if j0 : temp+=ways[i-1][j-1] row.append(temp) ways.append(row) numer=sum(ways[TURNS][i]for i in range(TURNS//2+1,TURNS+1)) denom=math.factorial(TURNS+1) return str(denom//numer) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var TURNS : int := 15 ; var ways : Sequence := Sequence{ Sequence{ 1 } } ; for i : Integer.subrange(1, TURNS + 1-1) do ( var row : Sequence := Sequence{} ; for j : Integer.subrange(0, i + 1-1) do ( var temp : int := 0 ; if (j->compareTo(i)) < 0 then ( temp := ways[i - 1+1][j+1] * i ) else skip ; if j > 0 then ( temp := temp + ways[i - 1+1][j - 1+1] ) else skip ; execute ((temp) : row)) ; execute ((row) : ways)) ; var numer : OclAny := ((argument (test (logical_test (comparison (expr (atom (name ways)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name TURNS)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name TURNS))) // (expr (atom (number (integer 2))))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name TURNS))) + (expr (atom (number (integer 1)))))))))) )))))))))->sum() ; var denom : long := MathLib.factorial(TURNS + 1) ; return ("" + ((denom div numer))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): Counter=0 Text_W=input() while True : Text_T=input() if "END_OF_TEXT" in Text_T : temp=Text_T.lower().split() for i in range(len(temp)): Counter+=1 if Text_W==temp[i]else 0 break else : temp=Text_T.lower().split() for i in range(len(temp)): Counter+=1 if Text_W==temp[i]else 0 print(Counter) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var Counter : int := 0 ; var Text_W : String := (OclFile["System.in"]).readLine() ; while true do ( var Text_T : String := (OclFile["System.in"]).readLine() ; if (Text_T)->characters()->includes("END_OF_TEXT") then ( var temp : OclAny := Text_T->toLowerCase().split() ; for i : Integer.subrange(0, (temp)->size()-1) do ( Counter := Counter + if Text_W = temp[i+1] then 1 else 0 endif) ; break ) else ( temp := Text_T->toLowerCase().split() ; for i : Integer.subrange(0, (temp)->size()-1) do ( Counter := Counter + if Text_W = temp[i+1] then 1 else 0 endif) )) ; execute (Counter)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=sorted(map(int,input().split())) print(b-1,a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; execute (b - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter def Look_for_the_Winner(n,lst): dic=Counter() loop_count=0 flg=0 for i in lst : n-=1 loop_count+=1 dic[i]+=1 if len(dic)==1 : if dic.most_common()[0][1]>n : print(dic.most_common()[0][0]+" "+str(loop_count)) flg=1 break else : if dic.most_common()[0][1]>dic.most_common()[1][1]+n : print(dic.most_common()[0][0]+" "+str(loop_count)) flg=1 break if flg==0 : print("TIE") while True : n=int(input()) if n==0 : break c=list(map(str,input().split())) Look_for_the_Winner(n,c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var c : Sequence := ((input().split())->collect( _x | (OclType["String"])->apply(_x) )) ; Look_for_the_Winner(n, c)); operation Look_for_the_Winner(n : OclAny, lst : OclAny) pre: true post: true activity: var dic : OclAny := Counter() ; var loop_count : int := 0 ; var flg : int := 0 ; for i : lst do ( n := n - 1 ; loop_count := loop_count + 1 ; dic[i+1] := dic[i+1] + 1 ; if (dic)->size() = 1 then ( if (dic.most_common()->first()[1+1]->compareTo(n)) > 0 then ( execute (dic.most_common()->first()->first() + " " + ("" + ((loop_count))))->display() ; flg := 1 ; break ) else skip ) else ( if (dic.most_common()->first()[1+1]->compareTo(dic.most_common()[1+1][1+1] + n)) > 0 then ( execute (dic.most_common()->first()->first() + " " + ("" + ((loop_count))))->display() ; flg := 1 ; break ) else skip )) ; if flg = 0 then ( execute ("TIE")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ri(): return int(input()) cand="A B C D E F G H I J K L M N O P Q R S T U V W X Y Z".split() n=ri() while(n!=0): vote=input().split() sm=[0 for i in range(26)] flag=False for i in range(n): for j in range(26): if(vote[i]==cand[j]): sm[j]+=1 break no1_sm=0 no2_sm=0 no1_idx=0 no2_idx=0 for j in range(26): if(sm[j]>no1_sm): no2_sm=no1_sm no2_idx=no1_idx no1_sm=sm[j] no1_idx=j elif(sm[j]>no2_sm): no2_sm=sm[j] no2_idx=j if((i+1)>n//2 and no1_sm>no2_sm+(n-1-i)): print(cand[no1_idx],i+1) flag=True break if(flag): break if(not flag): print("TIE") n=ri() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var cand : OclAny := "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z".split() ; var n : OclAny := ri() ; while (n /= 0) do ( var vote : OclAny := input().split() ; var sm : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | (0)) ; var flag : boolean := false ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, 26-1) do ( if (vote[i+1] = cand[j+1]) then ( sm[j+1] := sm[j+1] + 1 ; break ) else skip) ; var no1_sm : int := 0 ; var no2_sm : int := 0 ; var no1_idx : int := 0 ; var no2_idx : int := 0 ; for j : Integer.subrange(0, 26-1) do ( if ((sm[j+1]->compareTo(no1_sm)) > 0) then ( no2_sm := no1_sm ; no2_idx := no1_idx ; no1_sm := sm[j+1] ; no1_idx := j ) else (if ((sm[j+1]->compareTo(no2_sm)) > 0) then ( no2_sm := sm[j+1] ; no2_idx := j ) else skip)) ; if (((i + 1)->compareTo(n div 2)) > 0 & (no1_sm->compareTo(no2_sm + (n - 1 - i))) > 0) then ( execute (cand[no1_idx+1])->display() ; flag := true ; break ) else skip ; if (flag) then ( break ) else skip) ; if (not(flag)) then ( execute ("TIE")->display() ) else skip ; n := ri()); operation ri() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from inspect import currentframe def pri(*args): names={id(v): k for k,v in currentframe().f_back.f_locals.items()} print(','.join(names.get(id(arg),'???')+'='+repr(arg)for arg in args)) def solve(n,c): flat=ord("A") vote_count=[[i,0]for i in range(26)] for i in range(n): vote_str=c[i] vote_count[ord(vote_str)-flat][1]+=1 vote_count.sort(key=lambda x : x[1]) if vote_count[-1][1]>vote_count[-2][1]+(n-i-1): print(chr(vote_count[-1][0]+ord("A"))+" "+str(i+1)) return vote_count.sort() print("TIE") return if __name__=='__main__' : while True : n_input=int(input()) if n_input==0 : break c_imput=list(map(str,input().split())) solve(n_input,c_imput) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( while true do ( var n_input : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n_input = 0 then ( break ) else skip ; var c_imput : Sequence := ((input().split())->collect( _x | (OclType["String"])->apply(_x) )) ; solve(n_input, c_imput)) ) else skip; operation pri(args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) var names : Map := currentframe().f_back.f_locals->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->select(_tuple | true)->collect(_tuple | Map{?(v) |-> k})->unionAll() ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (expr (expr (atom (name names)) (trailer . (name get) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name id)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arg)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom '???'))))))) )))) + (expr (atom '='))) + (expr (atom (name repr)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arg)))))))) )))))))) (comp_for for (exprlist (expr (atom (name arg)))) in (logical_test (comparison (expr (atom (name args)))))))), ','))->display(); operation solve(n : OclAny, c : OclAny) pre: true post: true activity: var flat : int := ("A")->char2byte() ; var vote_count : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | (Sequence{i}->union(Sequence{ 0 }))) ; for i : Integer.subrange(0, n-1) do ( var vote_str : OclAny := c[i+1] ; vote_count[(vote_str)->char2byte() - flat+1][1+1] := vote_count[(vote_str)->char2byte() - flat+1][1+1] + 1 ; vote_count := vote_count->sort() ; if (vote_count->last()[1+1]->compareTo(vote_count->front()->last()[1+1] + (n - i - 1))) > 0 then ( execute ((vote_count->last()->first() + ("A")->char2byte())->byte2char() + " " + ("" + ((i + 1))))->display() ; return ) else skip ; vote_count := vote_count->sort()) ; execute ("TIE")->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) def main(): n=int(input()) if n==0 : return c=[ord(i)-65 for i in input().split(" ")] getnum=[0 for i in range(30)] mnum=29 snum=29 flg=True for i in range(n): getnum[c[i]]+=1 if getnum[c[i]]>=getnum[mnum]and mnum!=c[i]: snum=mnum mnum=c[i] elif getnum[c[i]]>=getnum[snum]and snum!=c[i]and mnum!=c[i]: snum=c[i] if getnum[mnum]>getnum[snum]+(n-1)-i : print(chr(mnum+65),i+1) flg=False break if flg : print("TIE") main() return main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; skip ; main(); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( return ) else skip ; var c : Sequence := input().split(" ")->select(i | true)->collect(i | ((i)->char2byte() - 65)) ; var getnum : Sequence := Integer.subrange(0, 30-1)->select(i | true)->collect(i | (0)) ; var mnum : int := 29 ; var snum : int := 29 ; var flg : boolean := true ; for i : Integer.subrange(0, n-1) do ( getnum[c[i+1]+1] := getnum[c[i+1]+1] + 1 ; if (getnum[c[i+1]+1]->compareTo(getnum[mnum+1])) >= 0 & mnum /= c[i+1] then ( snum := mnum ; mnum := c[i+1] ) else (if (getnum[c[i+1]+1]->compareTo(getnum[snum+1])) >= 0 & snum /= c[i+1] & mnum /= c[i+1] then ( snum := c[i+1] ) else skip) ; if (getnum[mnum+1]->compareTo(getnum[snum+1] + (n - 1) - i)) > 0 then ( execute ((mnum + 65)->byte2char())->display() ; flg := false ; break ) else skip) ; if flg then ( execute ("TIE")->display() ) else skip ; main() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if not n : break vote={"" : 0} cnt=0 for c in input().split(" "): cnt+=1 if c in vote : vote[c]+=1 else : vote[c]=1 v=sorted(vote.items(),key=lambda x : x[1]) if v[-1][-1]>v[-2][-1]+n-cnt : print(*[v[-1][-2],cnt]) break elif n==cnt : print("TIE") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(n) then ( break ) else skip ; var vote : Map := Map{ "" |-> 0 } ; var cnt : int := 0 ; for c : input().split(" ") do ( cnt := cnt + 1 ; if (vote)->includes(c) then ( vote[c+1] := vote[c+1] + 1 ) else ( vote[c+1] := 1 ) ; var v : Sequence := vote->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sortedBy($x | (lambda x : OclAny in (x[1+1]))->apply($x)) ; if (v->last()->last()->compareTo(v->front()->last()->last() + n - cnt)) > 0 then ( execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 2))))))))) ])))))) , (test (logical_test (comparison (expr (atom (name cnt))))))) ])))))))->display() ; break ) else (if n = cnt then ( execute ("TIE")->display() ) else skip))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline inf=float('inf') def getInt(): return int(input()) def getStr(): return input().strip() def getList(split=True): s=getStr() if split : s=s.split() return map(int,s) t=getInt() def solve(): n,B,x,y=getList() c=res=0 for i in range(n): if c+x<=B : c+=x else : c-=y res+=c print(res) for _ in range(t): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; skip ; skip ; skip ; var t : OclAny := getInt() ; skip ; for _anon : Integer.subrange(0, t-1) do ( solve()); operation getInt() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation getStr() : OclAny pre: true post: true activity: return input()->trim(); operation getList(split : OclAny) : OclAny pre: true post: true activity: if split->oclIsUndefined() then split := true else skip; var s : OclAny := getStr() ; if split then ( s := s.split() ) else skip ; return (s)->collect( _x | (OclType["int"])->apply(_x) ); operation solve() pre: true post: true activity: var n : OclAny := null; var B : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,B,x,y} := getList() ; var c : OclAny := 0; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (c + x->compareTo(B)) <= 0 then ( c := c + x ) else ( c := c - y ) ; res := res + c) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math t=int(input()) for _ in range(t): n,B,x,y=map(int,input().split()) ans=0 a=0 for _ in range(n): if(a+x<=B): a=a+x else : a=a-y ans=ans+a print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var B : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,B,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; var a : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( if ((a + x->compareTo(B)) <= 0) then ( a := a + x ) else ( a := a - y ) ; ans := ans + a) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def lstRd(): return list(map(int,input().split())) def intRd(): return int(input()) def lstStrRd(): return list(input()) for _ in range(intRd()): n,b,x,y=lstRd() temp=0 res=0 for i in range(n): if temp+x<=b : temp+=x else : temp-=y res+=temp print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; for _anon : Integer.subrange(0, intRd()-1) do ( var n : OclAny := null; var b : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,b,x,y} := lstRd() ; var temp : int := 0 ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (temp + x->compareTo(b)) <= 0 then ( temp := temp + x ) else ( temp := temp - y ) ; res := res + temp) ; execute (res)->display()); operation lstRd() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation intRd() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation lstStrRd() : OclAny pre: true post: true activity: return ((OclFile["System.in"]).readLine())->characters(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) t=[0]+list(map(int,input().split())) a=[0]+list(map(int,input().split())) ans,cnt=[],[0 for i in range(n+1)] for i in a : cnt[i]+=1 for i in range(1,n+1): if t[i]==1 : crt=[i] x=a[i] while cnt[x]==1 : crt.append(x) x=a[x] if len(crt)>len(ans): ans=crt[:] ans.reverse() print(len(ans)) print(' '.join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var a : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ans : OclAny := null; var cnt : OclAny := null; Sequence{ans,cnt} := Sequence{Sequence{},Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0))} ; for i : a do ( cnt[i+1] := cnt[i+1] + 1) ; for i : Integer.subrange(1, n + 1-1) do ( if t[i+1] = 1 then ( var crt : Sequence := Sequence{ i } ; var x : OclAny := a[i+1] ; while cnt[x+1] = 1 do ( execute ((x) : crt) ; x := a[x+1]) ; if ((crt)->size()->compareTo((ans)->size())) > 0 then ( var ans : Sequence := crt ) else skip ) else skip) ; ans := ans->reverse() ; execute ((ans)->size())->display() ; execute (StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,b,x,y=list(map(int,input().split(' '))) a=[0] for i in range(n): if a[-1]+x<=b : a.append(a[-1]+x) else : a.append(a[-1]-y) print(sum(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var b : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,b,x,y} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := Sequence{ 0 } ; for i : Integer.subrange(0, n-1) do ( if (a->last() + x->compareTo(b)) <= 0 then ( execute ((a->last() + x) : a) ) else ( execute ((a->last() - y) : a) )) ; execute ((a)->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,A,*x=map(int,open(0).read().split()) NX=N*max(x+[A]) y=[0]+[v-A for v in x] dp=[[0]*(2*NX+1)for _ in range(N+1)] dp[0][NX]=1 for j in range(1,N+1): for t in range(2*NX+1): if t-y[j]<0 or t-y[j]>2*NX : dp[j][t]=dp[j-1][t] elif 0<=t-y[j]<=2*NX : dp[j][t]=dp[j-1][t]+dp[j-1][t-y[j]] print(dp[N][NX]-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; var x : OclAny := null; Sequence{N,A,x} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var NX : double := N * (x->union(Sequence{ A }))->max() ; var y : Sequence := Sequence{ 0 }->union(x->select(v | true)->collect(v | (v - A))) ; var dp : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * NX + 1)))) ; dp->first()[NX+1] := 1 ; for j : Integer.subrange(1, N + 1-1) do ( for t : Integer.subrange(0, 2 * NX + 1-1) do ( if t - y[j+1] < 0 or (t - y[j+1]->compareTo(2 * NX)) > 0 then ( dp[j+1][t+1] := dp[j - 1+1][t+1] ) else (if 0 <= t - y[j+1] & (t - y[j+1] <= 2 * NX) then ( dp[j+1][t+1] := dp[j - 1+1][t+1] + dp[j - 1+1][t - y[j+1]+1] ) else skip))) ; execute (dp[N+1][NX+1] - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import collections as co S=input() ans=0 N=sys.stdin.read() P=N.lower().split() print(P.count(S)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var S : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; var N : String := (OclFile["System.in"]).readAll() ; var P : OclAny := N->toLowerCase().split() ; execute (P->count(S))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: n,b,x,y=map(int,s.split()); r=p=0 while n : n-=1 ; p+=(x,-y)[p+x>b]; r+=p print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var n : OclAny := null; var b : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,b,x,y} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ); var r : OclAny := 0; var p : int := 0 ; while n do ( n := n - 1; p := p + Sequence{x, -y}->select((p + x->compareTo(b)) > 0); r := r + p) ; execute (r)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getParity(n): parity=0 while n : parity=~ parity n=n &(n-1) return parity n=7 print("Parity of no ",n,"=",("odd" if getParity(n)else "even")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 7 ; execute ("Parity of no ")->display(); operation getParity(n : OclAny) : OclAny pre: true post: true activity: var parity : int := 0 ; while n do ( parity := MathLib.bitwiseNot(parity) ; n := MathLib.bitwiseAnd(n, (n - 1))) ; return parity; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def subArray(arr,n,m): i=0 mp=dict() for i in range(n): mp[arr[i]]=i+1 sumcur=0 p=10**9 ans=[] for i in range(1,m+1): sumcur+=mp[i] p=min(p,mp[i]) val=p*i-i+(i*(i+1))/2 if(i==m): if(val==sumcur): return True else : return False arr=[4,5,1,3,2,6] n=len(arr) m=3 if(subArray(arr,n,m)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{4}->union(Sequence{5}->union(Sequence{1}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 6 }))))) ; n := (arr)->size() ; m := 3 ; if (subArray(arr, n, m)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation subArray(arr : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; var mp : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( mp[arr[i+1]+1] := i + 1) ; var sumcur : int := 0 ; var p : double := (10)->pow(9) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(1, m + 1-1) do ( sumcur := sumcur + mp[i+1] ; p := Set{p, mp[i+1]}->min() ; var val : double := p * i - i + (i * (i + 1)) / 2 ; if (i = m) then ( if (val = sumcur) then ( return true ) else ( return false ) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[] for i in range(n): l.append(input()) l=set(l) a=len(l) print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : l)) ; l := Set{}->union((l)) ; var a : int := (l)->size() ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[] for t in range(n): l.append(input()) print(len(set(l))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; for t : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : l)) ; execute ((Set{}->union((l)))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=int(input()) print(len({input()for i in range(R)})) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((Integer.subrange(0, R-1)->select(i | true)->collect(i | (OclFile["System.in"]).readLine())->asSet())->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=[] for i in range(int(input())): s=input() if s not in l : l.append(s) print(len(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := Sequence{} ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if (l)->excludes(s) then ( execute ((s) : l) ) else skip) ; execute ((l)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=10**20 d,n=map(int,input().split()) temp=[int(input())for i in range(d)] temp.insert(0,0) alst=[] blst=[] clst=[] for i in range(n): a,b,c=map(int,input().split()) alst.append(a) blst.append(b) clst.append(c) dp=[[0]*n for i in range(d+1)] for i in range(n): if not(alst[i]<=temp[1]<=blst[i]): dp[1][i]=-INF for i in range(2,d+1): t=temp[i] for j in range(n): if alst[j]<=t<=blst[j]: dp[i][j]=max(dp[i-1][x]+abs(clst[j]-clst[x])for x in range(n)) print(max(dp[d])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INF : double := (10)->pow(20) ; var d : OclAny := null; var n : OclAny := null; Sequence{d,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var temp : Sequence := Integer.subrange(0, d-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; temp := temp.insertAt(0+1, 0) ; var alst : Sequence := Sequence{} ; var blst : Sequence := Sequence{} ; var clst : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a) : alst) ; execute ((b) : blst) ; execute ((c) : clst)) ; var dp : Sequence := Integer.subrange(0, d + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, n))) ; for i : Integer.subrange(0, n-1) do ( if not(((alst[i+1]->compareTo(temp[1+1])) <= 0 & (temp[1+1] <= blst[i+1]))) then ( dp[1+1][i+1] := -INF ) else skip) ; for i : Integer.subrange(2, d + 1-1) do ( var t : OclAny := temp[i+1] ; for j : Integer.subrange(0, n-1) do ( if (alst[j+1]->compareTo(t)) <= 0 & (t <= blst[j+1]) then ( dp[i+1][j+1] := ((argument (test (logical_test (comparison (expr (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ]))) + (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name clst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))) - (expr (atom (name clst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ]))))))))) )))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->max() ) else skip)) ; execute ((dp[d+1])->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input())+1 obj=list(map(int,input().strip().split())) ski=list(map(int,input().strip().split())) adj=[set()for _ in range(num)] out=[set()for _ in range(num)] discovered=[False]*num for u,v in enumerate(ski): if v!=0 : adj[u+1].add(v) out[v].add(u+1) hotel=[] for i,t in enumerate(obj): if t==1 : hotel.append(i+1) q=[] p=[0]*num endNode=None for i in hotel : q.append((i,1)) p[i]=i endNode=i maxim=1 while len(q)!=0 : u,depth=q.pop(0) if len(adj[u])==0 : endNode=u maxim=max(maxim,depth) for v in adj[u]: if len(out[v])==1 : endNode=v maxim=max(maxim,depth+1) p[v]=u q.append((v,depth+1)) print(maxim) while p[endNode]!=endNode : print(endNode,end=" ") endNode=p[endNode] print(endNode) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() + 1 ; var obj : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ski : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var adj : Sequence := Integer.subrange(0, num-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; var out : Sequence := Integer.subrange(0, num-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; var discovered : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, num) ; for _tuple : Integer.subrange(1, (ski)->size())->collect( _indx | Sequence{_indx-1, (ski)->at(_indx)} ) do (var _indx : int := 1; var u : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if v /= 0 then ( (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name u))) + (expr (atom (number (integer 1)))))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) ; (expr (atom (name out)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name u))) + (expr (atom (number (integer 1)))))))))) )))) ) else skip) ; var hotel : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (obj)->size())->collect( _indx | Sequence{_indx-1, (obj)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); if t = 1 then ( execute ((i + 1) : hotel) ) else skip) ; var q : Sequence := Sequence{} ; var p : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, num) ; var endNode : OclAny := null ; for i : hotel do ( execute ((Sequence{i, 1}) : q) ; p[i+1] := i ; endNode := i) ; var maxim : int := 1 ; while (q)->size() /= 0 do ( var u : OclAny := null; var depth : OclAny := null; Sequence{u,depth} := q->at(0`firstArg+1) ; q := q->excludingAt(0+1) ; if (adj[u+1])->size() = 0 then ( endNode := u ; maxim := Set{maxim, depth}->max() ) else skip ; for v : adj[u+1] do ( if (out[v+1])->size() = 1 then ( endNode := v ; maxim := Set{maxim, depth + 1}->max() ; p[v+1] := u ; execute ((Sequence{v, depth + 1}) : q) ) else skip)) ; execute (maxim)->display() ; while p[endNode+1] /= endNode do ( execute (endNode)->display() ; endNode := p[endNode+1]) ; execute (endNode)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[] for i in range(n): a=input() l.append(a) print(len(set(l))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : String := (OclFile["System.in"]).readLine() ; execute ((a) : l)) ; execute ((Set{}->union((l)))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import decimal import itertools from itertools import product from functools import reduce def input(): return sys.stdin.readline()[:-1] def gcd(*numbers): return reduce(math.gcd,numbers) def lcm_base(x,y): return(x*y)//math.gcd(x,y) def lcm(*numbers): return reduce(lcm_base,numbers,1) def sort_zip(a : list,b : list): z=zip(a,b) z=sorted(z) a,b=zip(*z) a=list(a) b=list(b) return a,b def ceil(x): return math.ceil(x) def floor(x): return math.floor(x) def main(): MOD=998244353 N,K=map(int,input().split()) L=[0]*K R=[0]*K for i in range(K): L[i],R[i]=map(int,input().split()) dp=[0]*(N+1) dpsum=[0]*(N+1) dp[1]=1 dpsum[1]=1 for i in range(2,N+1): for j in range(K): li=i-R[j] li=max(li,1) ri=i-L[j] if ri<0 : continue dp[i]+=(dpsum[ri]-dpsum[li-1])% MOD dpsum[i]+=(dpsum[i-1]+dp[i])% MOD print(dp[N]% MOD) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation gcd(numbers : OclAny : Sequence(OclAny)) : OclAny pre: true post: true activity: (args * (named_parameter (name numbers))) return reduce(, numbers); operation lcm_base(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return (x * y) div (x)->gcd(y); operation lcm(numbers : OclAny : Sequence(OclAny)) : OclAny pre: true post: true activity: (args * (named_parameter (name numbers))) return reduce(lcm_base, numbers, 1); operation sort_zip(a : Sequence(OclAny), b : Sequence(OclAny)) : OclAny pre: true post: true activity: var z : Sequence := Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), b->at(_indx)} ) ; z := z->sort() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name z)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name z)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name z)))))))`third->at(_indx)} ) ; var a : Sequence := (a) ; var b : Sequence := (b) ; return a, b; operation ceil(x : OclAny) : OclAny pre: true post: true activity: return (x)->ceil(); operation floor(x : OclAny) : OclAny pre: true post: true activity: return (x)->floor(); operation main() pre: true post: true activity: var MOD : int := 998244353 ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var L : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, K) ; var R : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, K) ; for i : Integer.subrange(0, K-1) do ( var L[i+1] : OclAny := null; var R[i+1] : OclAny := null; Sequence{L[i+1],R[i+1]} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; var dpsum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; dp[1+1] := 1 ; dpsum[1+1] := 1 ; for i : Integer.subrange(2, N + 1-1) do ( for j : Integer.subrange(0, K-1) do ( var li : double := i - R[j+1] ; li := Set{li, 1}->max() ; var ri : double := i - L[j+1] ; if ri < 0 then ( continue ) else skip ; dp[i+1] := dp[i+1] + (dpsum[ri+1] - dpsum[li - 1+1]) mod MOD) ; dpsum[i+1] := dpsum[i+1] + (dpsum[i - 1+1] + dp[i+1]) mod MOD) ; execute (dp[N+1] mod MOD)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math import io,os from bisect import bisect_left as bl,bisect_right as br,insort from heapq import heapify,heappush,heappop from collections import defaultdict as dd,deque,Counter def data(): return sys.stdin.readline().strip() def mdata(): return list(map(int,data().split())) def outl(var): sys.stdout.write(' '.join(map(str,var))+'\n') def out(var): sys.stdout.write(str(var)+'\n') from decimal import Decimal mod=998244353 INF=float('inf') n,k=mdata() set1=set() dp=[0]*(n) s=[0]*n lis=sorted([mdata()for i in range(k)],key=lambda x : x[0]) for i,j in lis : for m in range(i,j+1): set1.add(m) m=lis[0][0] for i in range(m,n): for j in range(k): if lis[j][0]>=i : break dp[i]+=s[i-lis[j][0]]-s[i-min(lis[j][1],i-1)-1] if i in set1 : dp[i]+=1 dp[i]%=mod s[i]=dp[i]+s[i-1] out(dp[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : int := 998244353 ; var INF : double := ("" + (('inf')))->toReal() ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := mdata() ; var set1 : Set := Set{}->union(()) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n)) ; var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var lis : Sequence := Integer.subrange(0, k-1)->select(i | true)->collect(i | (mdata()))->sortedBy($x | (lambda x : OclAny in (x->first()))->apply($x)) ; for _tuple : lis do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); for m : Integer.subrange(i, j + 1-1) do ( execute ((m) : set1))) ; var m : OclAny := lis->first()->first() ; for i : Integer.subrange(m, n-1) do ( for j : Integer.subrange(0, k-1) do ( if (lis[j+1]->first()->compareTo(i)) >= 0 then ( break ) else skip ; dp[i+1] := dp[i+1] + s[i - lis[j+1]->first()+1] - s[i - Set{lis[j+1][1+1], i - 1}->min() - 1+1]) ; if (set1)->includes(i) then ( dp[i+1] := dp[i+1] + 1 ) else skip ; dp[i+1] := dp[i+1] mod mod ; s[i+1] := dp[i+1] + s[i - 1+1]) ; out(dp->last()); operation data() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation mdata() : OclAny pre: true post: true activity: return ((data().split())->collect( _x | (OclType["int"])->apply(_x) )); operation outl(var : OclAny) pre: true post: true activity: (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ' ') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name var)))))))) ))))))))) )))) + (expr (atom ' ')))))))) )))); operation out(var : OclAny) pre: true post: true activity: (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name var)))))))) )))) + (expr (atom ' ')))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- word=input() string=input().lower() last="" while last!="END_OF_TEXT" : last=input() string+=" "+last.lower() list_words=list(string.split()) count=0 for s in list_words : if s==word : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var word : String := (OclFile["System.in"]).readLine() ; var string : OclAny := input()->toLowerCase() ; var last : String := "" ; while last /= "END_OF_TEXT" do ( last := (OclFile["System.in"]).readLine() ; string := string + " " + last->toLowerCase()) ; var list_words : Sequence := (string.split()) ; var count : int := 0 ; for s : list_words do ( if s = word then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,input().split()) d=[0]*2*K for i in range(K): d[2*i],d[2*i+1]=map(int,input().split()) a=[0]*(N+1) b=[0]*(N+1) a[1]=1 b[1]=1 for i in range(2,N+1): t=0 for j in range(K): if i-d[2*j]>0 : t+=b[i-d[2*j]] if i-d[2*j+1]-1>0 : t-=b[i-d[2*j+1]-1] a[i]=t b[i]=(b[i-1]+a[i])% 998244353 print(a[N]% 998244353) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := MatrixLib.elementwiseMult(MatrixLib.elementwiseMult(Sequence{ 0 }, 2), K) ; for i : Integer.subrange(0, K-1) do ( var d[2 * i+1] : OclAny := null; var d[2 * i + 1+1] : OclAny := null; Sequence{d[2 * i+1],d[2 * i + 1+1]} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; a[1+1] := 1 ; b[1+1] := 1 ; for i : Integer.subrange(2, N + 1-1) do ( var t : int := 0 ; for j : Integer.subrange(0, K-1) do ( if i - d[2 * j+1] > 0 then ( t := t + b[i - d[2 * j+1]+1] ) else skip ; if i - d[2 * j + 1+1] - 1 > 0 then ( t := t - b[i - d[2 * j + 1+1] - 1+1] ) else skip) ; a[i+1] := t ; b[i+1] := (b[i - 1+1] + a[i+1]) mod 998244353) ; execute (a[N+1] mod 998244353)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pointUpdate(BIT,index,val): mod=998244353 while index0 : total+=BIT[index] index-=index &-index total %=mod return total def rangeUpdate(BIT,l,r,val): pointUpdate(BIT,l,val) pointUpdate(BIT,r+1,-val) def main(): n,k=map(int,input().split()) segs=[] for i in range(k): l,r=map(int,input().split()) segs.append((l,r)) segs.sort() mod=998244353 BIT=[0]*(n+1) BIT[1]=1 for cell in range(1,n+1): curr=pointQuery(BIT,cell) if cell==n : print(curr) for l,r in segs : left=min(cell+l,n+1) right=min(cell+r,n+1) rangeUpdate(BIT,left,right,curr) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; main(); operation pointUpdate(BIT : OclAny, index : OclAny, val : OclAny) pre: true post: true activity: var mod : int := 998244353 ; while (index->compareTo((BIT)->size())) < 0 do ( BIT[index+1] := BIT[index+1] + val ; BIT[index+1] := BIT[index+1] mod mod ; index := index + MathLib.bitwiseAnd(index, -index)); operation pointQuery(BIT : OclAny, index : OclAny) : OclAny pre: true post: true activity: mod := 998244353 ; var total : int := 0 ; while index > 0 do ( total := total + BIT[index+1] ; index := index - MathLib.bitwiseAnd(index, -index) ; total := total mod mod) ; return total; operation rangeUpdate(BIT : OclAny, l : OclAny, r : OclAny, val : OclAny) pre: true post: true activity: pointUpdate(BIT, l, val) ; pointUpdate(BIT, r + 1, -val); operation main() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var segs : Sequence := Sequence{} ; for i : Integer.subrange(0, k-1) do ( Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{l, r}) : segs)) ; segs := segs->sort() ; mod := 998244353 ; BIT := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; BIT[1+1] := 1 ; for cell : Integer.subrange(1, n + 1-1) do ( var curr : OclAny := pointQuery(BIT, cell) ; if cell = n then ( execute (curr)->display() ) else skip ; for _tuple : segs do (var _indx : int := 1; var l : OclAny := _tuple->at(_indx); _indx := _indx + 1; var r : OclAny := _tuple->at(_indx); var left : OclAny := Set{cell + l, n + 1}->min() ; var right : OclAny := Set{cell + r, n + 1}->min() ; rangeUpdate(BIT, left, right, curr))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline sys.setrecursionlimit(10**9) def solve(): MOD=998244353 def makeBIT(numEle): numPow2=2**(numEle-1).bit_length() data=[0]*(numPow2+1) return data,numPow2 def setInit(As): for iB,A in enumerate(As,1): data[iB]=A for iB in range(1,numPow2): i=iB+(iB &-iB) data[i]+=data[iB] def addValue(iA,A): iB=iA+1 while iB<=numPow2 : data[iB]+=A iB+=iB &-iB def getSum(iA): iB=iA+1 ans=0 while iB>0 : ans+=data[iB] iB-=iB &-iB return ans def getRangeSum(iFr,iTo): return getSum(iTo)-getSum(iFr-1) N,K=map(int,input().split()) LRs=[tuple(map(int,input().split()))for _ in range(K)] data,numPow2=makeBIT(N) addValue(0,1) for i in range(1,N): v=0 for L,R in LRs : x,y=i-R,i-L if y<0 : continue if x<0 : x=0 v+=getRangeSum(x,y)% MOD v %=MOD addValue(i,v) ans=getRangeSum(N-1,N-1)% MOD print(ans) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit((10)->pow(9)) ; skip ; solve(); operation solve() pre: true post: true activity: var MOD : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var LRs : Sequence := Integer.subrange(0, K-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; Sequence{data,numPow2} := makeBIT(N) ; addValue(0, 1) ; for i : Integer.subrange(1, N-1) do ( var v : int := 0 ; for _tuple : LRs do (var _indx : int := 1; var L : OclAny := _tuple->at(_indx); _indx := _indx + 1; var R : OclAny := _tuple->at(_indx); var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{i - R,i - L} ; if y < 0 then ( continue ) else skip ; if x < 0 then ( var x : int := 0 ) else skip ; v := v + getRangeSum(x, y) mod MOD ; v := v mod MOD) ; addValue(i, v)) ; ans := getRangeSum(N - 1, N - 1) mod MOD ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def OctToBin(octnum): binary="" while octnum!=0 : d=int(octnum % 10) if d==0 : binary="".join(["000",binary]) elif d==1 : binary="".join(["001",binary]) elif d==2 : binary="".join(["010",binary]) elif d==3 : binary="".join(["011",binary]) elif d==4 : binary="".join(["100",binary]) elif d==5 : binary="".join(["101",binary]) elif d==6 : binary="".join(["110",binary]) elif d==7 : binary="".join(["111",binary]) else : binary="Invalid Octal Digit" break octnum=int(octnum/10) return binary octnum=345 final_bin=""+OctToBin(octnum) print("Equivalent Binary Value=",final_bin) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; octnum := 345 ; var final_bin : String := "" + OctToBin(octnum) ; execute ("Equivalent Binary Value=")->display(); operation OctToBin(octnum : OclAny) : OclAny pre: true post: true activity: var binary : String := "" ; while octnum /= 0 do ( var d : int := ("" + ((octnum mod 10)))->toInteger() ; if d = 0 then ( binary := StringLib.sumStringsWithSeparator((Sequence{"000"}->union(Sequence{ binary })), "") ) else (if d = 1 then ( binary := StringLib.sumStringsWithSeparator((Sequence{"001"}->union(Sequence{ binary })), "") ) else (if d = 2 then ( binary := StringLib.sumStringsWithSeparator((Sequence{"010"}->union(Sequence{ binary })), "") ) else (if d = 3 then ( binary := StringLib.sumStringsWithSeparator((Sequence{"011"}->union(Sequence{ binary })), "") ) else (if d = 4 then ( binary := StringLib.sumStringsWithSeparator((Sequence{"100"}->union(Sequence{ binary })), "") ) else (if d = 5 then ( binary := StringLib.sumStringsWithSeparator((Sequence{"101"}->union(Sequence{ binary })), "") ) else (if d = 6 then ( binary := StringLib.sumStringsWithSeparator((Sequence{"110"}->union(Sequence{ binary })), "") ) else (if d = 7 then ( binary := StringLib.sumStringsWithSeparator((Sequence{"111"}->union(Sequence{ binary })), "") ) else ( binary := "Invalid Octal Digit" ; break ) ) ) ) ) ) ) ) ; octnum := ("" + ((octnum / 10)))->toInteger()) ; return binary; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : x=input() if x=="0" : break ans=0 for i in x : ans+=int(i) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var x : String := (OclFile["System.in"]).readLine() ; if x = "0" then ( break ) else skip ; var ans : int := 0 ; for i : x->characters() do ( ans := ans + ("" + ((i)))->toInteger()) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function import sys for line in sys.stdin : if '0'==line.strip(): break print(sum(int(n)for n in line if n.isdigit())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for line : OclFile["System.in"] do ( if '0' = line->trim() then ( break ) else skip ; execute (((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name line))))) (comp_iter if (test (logical_test (comparison (expr (atom (name n)) (trailer . (name isdigit) (arguments ( )))))))))))->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=10**6 n=int(input()) types=[INF]+[int(i)for i in input().split()] A=[INF]+[int(i)for i in input().split()] Path=[[]for i in range(n+1)] for i in range(1,n+1): if A[i]: Path[A[i]].append(i) end=[] longest=[] for i in range(1,n+1): if types[i]==0 : continue start=i path_tmp=[] while 1 : if len(Path[start])==0 and start!=i : path_tmp.append(start) break if len(Path[start])>1 : break path_tmp.append(start) start=A[start] if start==0 : break if len(longest)pow(6) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var types : Sequence := Sequence{ INF }->union(input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))) ; var A : Sequence := Sequence{ INF }->union(input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))) ; var Path : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(1, n + 1-1) do ( if A[i+1] then ( (expr (atom (name Path)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ) else skip) ; var end : Sequence := Sequence{} ; var longest : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( if types[i+1] = 0 then ( continue ) else skip ; var start : OclAny := i ; var path_tmp : Sequence := Sequence{} ; while 1 do ( if (Path[start+1])->size() = 0 & start /= i then ( execute ((start) : path_tmp) ; break ) else skip ; if (Path[start+1])->size() > 1 then ( break ) else skip ; execute ((start) : path_tmp) ; start := A[start+1] ; if start = 0 then ( break ) else skip) ; if ((longest)->size()->compareTo((path_tmp)->size())) < 0 then ( longest := path_tmp ) else skip) ; execute ((longest)->size())->display() ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name longest)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ])))))))), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : num=[int(n)for n in list(raw_input())] if len(num)==1 and num[0]==0 : break else : print(sum(num)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var num : Sequence := (raw_input())->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; if (num)->size() = 1 & num->first() = 0 then ( break ) else ( execute ((num)->sum())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys for line in sys.stdin : if line=="0\n" : break total=sum(map(int,list(line.rstrip()))) print(total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for line : OclFile["System.in"] do ( if line = "0\n" then ( break ) else skip ; var total : OclAny := (((StringLib.rightTrim(line))->characters())->collect( _x | (OclType["int"])->apply(_x) ))->sum() ; execute (total)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : x=input().strip() if x=='0' : break print(sum(map(int,x))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var x : OclAny := input()->trim() ; if x = '0' then ( break ) else skip ; execute (((x)->collect( _x | (OclType["int"])->apply(_x) ))->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcdExtended(a,b): if a==0 : return b,0,1 gcd,x1,y1=gcdExtended(b % a,a) x=y1-(b//a)*x1 y=x1 return gcd,x,y a,b=35,15 g,x,y=gcdExtended(a,b) print("gcd(",a,",",b,")=",g) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{a,b} := Sequence{35,15} ; var g : OclAny := null; Sequence{g,x,y} := gcdExtended(a, b) ; execute ("gcd(")->display(); operation gcdExtended(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a = 0 then ( return b, 0, 1 ) else skip ; var gcd : OclAny := null; var x1 : OclAny := null; var y1 : OclAny := null; Sequence{gcd,x1,y1} := gcdExtended(b mod a, a) ; var x : double := y1 - (b div a) * x1 ; var y : OclAny := x1 ; return gcd, x, y; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w=input().casefold() word_count=0 while True : line=input() if line=="END_OF_TEXT" : break line=line.casefold() word=line.split() word_count+=word.count(w) print(word_count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : OclAny := input().casefold() ; var word_count : int := 0 ; while true do ( var line : String := (OclFile["System.in"]).readLine() ; if line = "END_OF_TEXT" then ( break ) else skip ; line := line.casefold() ; var word : OclAny := line.split() ; word_count := word_count + word->count(w)) ; execute (word_count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcdExtended(a,b): if a==0 : return b,0,1 gcd,x1,y1=gcdExtended(b % a,a) x=y1-(b//a)*x1 y=x1 return gcd,x,y a,b=35,15 g,x,y=gcdExtended(a,b) print("gcd(",a,",",b,")=",g) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{a,b} := Sequence{35,15} ; var g : OclAny := null; Sequence{g,x,y} := gcdExtended(a, b) ; execute ("gcd(")->display(); operation gcdExtended(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a = 0 then ( return b, 0, 1 ) else skip ; var gcd : OclAny := null; var x1 : OclAny := null; var y1 : OclAny := null; Sequence{gcd,x1,y1} := gcdExtended(b mod a, a) ; var x : double := y1 - (b div a) * x1 ; var y : OclAny := x1 ; return gcd, x, y; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def precomput(f): f.append(0) f.append(1) for i in range(2,300): f.append((f[i-1]+f[i-2])% 100) def findLastDigit(f,n): return f[n % 300] f=list() precomput(f) n=1 print(findLastDigit(f,n)) n=61 print(findLastDigit(f,n)) n=7 print(findLastDigit(f,n)) n=67 print(findLastDigit(f,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; f := () ; precomput(f) ; n := 1 ; execute (findLastDigit(f, n))->display() ; n := 61 ; execute (findLastDigit(f, n))->display() ; n := 7 ; execute (findLastDigit(f, n))->display() ; n := 67 ; execute (findLastDigit(f, n))->display(); operation precomput(f : OclAny) pre: true post: true activity: execute ((0) : f) ; execute ((1) : f) ; for i : Integer.subrange(2, 300-1) do ( execute (((f[i - 1+1] + f[i - 2+1]) mod 100) : f)); operation findLastDigit(f : OclAny, n : OclAny) : OclAny pre: true post: true activity: return f[n mod 300+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(b==0): return a return gcd(b,a % b) def flip(a,b): lcm=(a*b)//gcd(a,b) a=lcm//a b=lcm//b print(a-1,b-1) a=10 b=5 flip(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 10 ; b := 5 ; flip(a, b); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (b = 0) then ( return a ) else skip ; return gcd(b, a mod b); operation flip(a : OclAny, b : OclAny) pre: true post: true activity: var lcm : int := (a * b) div gcd(a, b) ; a := lcm div a ; b := lcm div b ; execute (a - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def longLenStrictBitonicSub(arr,n): inc,dcr=dict(),dict() len_inc,len_dcr=[0]*n,[0]*n longLen=0 for i in range(n): len=0 if inc.get(arr[i]-1)in inc.values(): len=inc.get(arr[i]-1) inc[arr[i]]=len_inc[i]=len+1 for i in range(n-1,-1,-1): len=0 if dcr.get(arr[i]-1)in dcr.values(): len=dcr.get(arr[i]-1) dcr[arr[i]]=len_dcr[i]=len+1 for i in range(n): if longLen<(len_inc[i]+len_dcr[i]-1): longLen=len_inc[i]+len_dcr[i]-1 return longLen if __name__=="__main__" : arr=[1,5,2,3,4,5,3,2] n=len(arr) print("Longest length strict bitonic subsequence=",longLenStrictBitonicSub(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{5}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{3}->union(Sequence{ 2 }))))))) ; n := (arr)->size() ; execute ("Longest length strict bitonic subsequence=")->display() ) else skip; operation longLenStrictBitonicSub(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var inc : OclAny := null; var dcr : OclAny := null; Sequence{inc,dcr} := Sequence{(arguments ( )),(arguments ( ))} ; var len_inc : OclAny := null; var len_dcr : OclAny := null; Sequence{len_inc,len_dcr} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, n),MatrixLib.elementwiseMult(Sequence{ 0 }, n)} ; var longLen : int := 0 ; for i : Integer.subrange(0, n-1) do ( var len : int := 0 ; if (inc.values())->includes(inc.get(arr[i+1] - 1)) then ( len := inc.get(arr[i+1] - 1) ) else skip ; inc[arr[i+1]+1] := len + 1; var len_inc[i+1] : int := len + 1) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( len := 0 ; if (dcr.values())->includes(dcr.get(arr[i+1] - 1)) then ( len := dcr.get(arr[i+1] - 1) ) else skip ; dcr[arr[i+1]+1] := len + 1; var len_dcr[i+1] : int := len + 1) ; for i : Integer.subrange(0, n-1) do ( if (longLen->compareTo((len_inc[i+1] + len_dcr[i+1] - 1))) < 0 then ( longLen := len_inc[i+1] + len_dcr[i+1] - 1 ) else skip) ; return longLen; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : r,c,q=map(int,input().split()) if r==0 : break querys=[list(map(int,input().split()))for _ in range(q)] querys.reverse() r_used=[False]*r c_used=[False]*c r_cnt=c c_cnt=r ans=0 for a,b,o in querys : if a==0 : if not r_used[b]: r_used[b]=True c_cnt-=1 if o : ans+=r_cnt else : if not c_used[b]: c_used[b]=True r_cnt-=1 if o : ans+=c_cnt print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var r : OclAny := null; var c : OclAny := null; var q : OclAny := null; Sequence{r,c,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if r = 0 then ( break ) else skip ; var querys : Sequence := Integer.subrange(0, q-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; querys := querys->reverse() ; var r_used : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, r) ; var c_used : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, c) ; var r_cnt : OclAny := c ; var c_cnt : OclAny := r ; var ans : int := 0 ; for _tuple : querys do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var o : OclAny := _tuple->at(_indx); if a = 0 then ( if not(r_used[b+1]) then ( r_used[b+1] := true ; c_cnt := c_cnt - 1 ; if o then ( ans := ans + r_cnt ) else skip ) else skip ) else ( if not(c_used[b+1]) then ( c_used[b+1] := true ; r_cnt := r_cnt - 1 ; if o then ( ans := ans + c_cnt ) else skip ) else skip )) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=10**6 n=int(input()) types=[INF]+[int(i)for i in input().split()] A=[INF]+[int(i)for i in input().split()] Path=[[]for i in range(n+1)] for i in range(1,n+1): if A[i]: Path[A[i]].append(i) longest=[] for i in range(1,n+1): if types[i]==0 : continue start=i path_tmp=[] while 1 : if len(Path[start])==0 and start!=i : path_tmp.append(start) break if len(Path[start])>1 : break path_tmp.append(start) start=A[start] if start==0 : break if len(longest)pow(6) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var types : Sequence := Sequence{ INF }->union(input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))) ; var A : Sequence := Sequence{ INF }->union(input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))) ; var Path : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(1, n + 1-1) do ( if A[i+1] then ( (expr (atom (name Path)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ) else skip) ; var longest : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( if types[i+1] = 0 then ( continue ) else skip ; var start : OclAny := i ; var path_tmp : Sequence := Sequence{} ; while 1 do ( if (Path[start+1])->size() = 0 & start /= i then ( execute ((start) : path_tmp) ; break ) else skip ; if (Path[start+1])->size() > 1 then ( break ) else skip ; execute ((start) : path_tmp) ; start := A[start+1] ; if start = 0 then ( break ) else skip) ; if ((longest)->size()->compareTo((path_tmp)->size())) < 0 then ( longest := path_tmp ) else skip) ; execute ((longest)->size())->display() ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name longest)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ])))))))), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import fractions def compute(): LIMIT=120000 rads=[0]+[1]*(LIMIT-1) for i in range(2,len(rads)): if rads[i]==1 : for j in range(i,len(rads),i): rads[j]*=i sortedrads=sorted((rad,n)for(n,rad)in enumerate(rads)) sortedrads=sortedrads[1 :] ans=0 for c in range(2,LIMIT): for(rad,a)in sortedrads : rad*=rads[c] if rad>=c : break b=c-a if adisplay() ) else skip; operation compute() : OclAny pre: true post: true activity: var LIMIT : int := 120000 ; var rads : Sequence := Sequence{ 0 }->union(MatrixLib.elementwiseMult(Sequence{ 1 }, (LIMIT - 1))) ; for i : Integer.subrange(2, (rads)->size()-1) do ( if rads[i+1] = 1 then ( for j : Integer.subrange(i, (rads)->size()-1)->select( $x | ($x - i) mod i = 0 ) do ( rads[j+1] := rads[j+1] * i) ) else skip) ; var sortedrads : Sequence := (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name rad)))))) , (test (logical_test (comparison (expr (atom (name n))))))) )))))) (comp_for for (exprlist (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name n)))))) , (test (logical_test (comparison (expr (atom (name rad))))))) )))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name rads)))))))) ))))))))->sort() ; sortedrads := sortedrads->tail() ; var ans : int := 0 ; for c : Integer.subrange(2, LIMIT-1) do ( for Sequence{rad, a} : sortedrads do ( rad := rad * rads[c+1] ; if (rad->compareTo(c)) >= 0 then ( break ) else skip ; var b : double := c - a ; if (a->compareTo(b)) < 0 & (rad * rads[b+1]->compareTo(c)) < 0 & fractions.gcd(a, b) = 1 then ( ans := ans + c ) else skip)) ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def kthdigit(a,b,k): p=a**b count=0 while(p>0 and countdisplay(); operation kthdigit(a : OclAny, b : OclAny, k : OclAny) : OclAny pre: true post: true activity: var p : double := (a)->pow(b) ; var count : int := 0 ; while (p > 0 & (count->compareTo(k)) < 0) do ( var rem : int := p mod 10 ; count := count + 1 ; if (count = k) then ( return rem ) else skip ; p := p / 10;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def recaman(n): arr=[0]*n arr[0]=0 print(arr[0],end=",") for i in range(1,n): curr=arr[i-1]-i for j in range(0,i): if((arr[j]==curr)or curr<0): curr=arr[i-1]+i break arr[i]=curr print(arr[i],end=",") n=17 recaman(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 17 ; recaman(n); operation recaman(n : OclAny) pre: true post: true activity: var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; arr->first() := 0 ; execute (arr->first())->display() ; for i : Integer.subrange(1, n-1) do ( var curr : double := arr[i - 1+1] - i ; for j : Integer.subrange(0, i-1) do ( if ((arr[j+1] = curr) or curr < 0) then ( curr := arr[i - 1+1] + i ; break ) else skip) ; arr[i+1] := curr ; execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=0 u=0 for _ in range(int(input())): a,b=map(int,input().split()) k-=a k+=b if(k>u): u=k print(u) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := 0 ; var u : int := 0 ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; k := k - a ; k := k + b ; if ((k->compareTo(u)) > 0) then ( u := k ) else skip) ; execute (u)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=0 X=[] X.append(x) for i in range(1,n+1): ai,bi=map(int,input().split(' ')) x=x+bi-ai X.append(x) print(str(max(X))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := 0 ; var X : Sequence := Sequence{} ; execute ((x) : X) ; for i : Integer.subrange(1, n + 1-1) do ( var ai : OclAny := null; var bi : OclAny := null; Sequence{ai,bi} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; x := x + bi - ai ; execute ((x) : X)) ; execute (("" + (((X)->max()))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def productSubSeqCount(arr,k): n=len(arr) dp=[[0 for i in range(n+1)]for j in range(k+1)] for i in range(1,k+1): for j in range(1,n+1): dp[i][j]=dp[i][j-1] if arr[j-1]<=i and arr[j-1]>0 : dp[i][j]+=dp[i//arr[j-1]][j-1]+1 return dp[k][n] A=[1,2,3,4] k=10 print(productSubSeqCount(A,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var A : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))) ; k := 10 ; execute (productSubSeqCount(A, k))->display(); operation productSubSeqCount(arr : OclAny, k : OclAny) : OclAny pre: true post: true activity: var n : int := (arr)->size() ; var dp : Sequence := Integer.subrange(0, k + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(1, k + 1-1) do ( for j : Integer.subrange(1, n + 1-1) do ( dp[i+1][j+1] := dp[i+1][j - 1+1] ; if (arr[j - 1+1]->compareTo(i)) <= 0 & arr[j - 1+1] > 0 then ( dp[i+1][j+1] := dp[i+1][j+1] + dp[i div arr[j - 1+1]+1][j - 1+1] + 1 ) else skip)) ; return dp[k+1][n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- res=0 p=0 for _ in range(int(input())): a,b=map(int,input().split()) p=p-a+b res=max(res,p) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var res : int := 0 ; var p : int := 0 ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; p := p - a + b ; res := Set{res, p}->max()) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=0 max=p for _ in range(n): a,b=map(int,input().split()) p-=a p+=b if p>max : max=p print(max) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : int := 0 ; var max : int := p ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; p := p - a ; p := p + b ; if (p->compareTo(max)) > 0 then ( max := p ) else skip) ; execute (max)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solution(tram): answer=0 answer_array=[] for loop in range(0,tram): user_input=list(map(int,input().split(' '))) if loop==0 : answer+=user_input[1] elif loop==tram-1 : answer-=user_input[0] else : answer-=user_input[0] answer+=user_input[1] answer_array.append(answer) return max(answer_array) if __name__=="__main__" : input1=input() print(solution(int(input1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var input1 : String := (OclFile["System.in"]).readLine() ; execute (solution(("" + ((input1)))->toInteger()))->display() ) else skip; operation solution(tram : OclAny) : OclAny pre: true post: true activity: var answer : int := 0 ; var answer_array : Sequence := Sequence{} ; for loop : Integer.subrange(0, tram-1) do ( var user_input : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; if loop = 0 then ( answer := answer + user_input[1+1] ) else (if loop = tram - 1 then ( answer := answer - user_input->first() ) else ( answer := answer - user_input->first() ; answer := answer + user_input[1+1] ) ) ; execute ((answer) : answer_array)) ; return (answer_array)->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) ans=0 x=1 while 2*x-1<=N : x=2*x ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; var x : int := 1 ; while (2 * x - 1->compareTo(N)) <= 0 do ( x := 2 * x ; ans := ans + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def merge(ar1,ar2,m,n): for i in range(n-1,-1,-1): last=ar1[m-1] j=m-2 while(j>=0 and ar1[j]>ar2[i]): ar1[j+1]=ar1[j] j-=1 if(j!=m-2 or last>ar2[i]): ar1[j+1]=ar2[i] ar2[i]=last ar1=[1,5,9,10,15,20] ar2=[2,3,8,13] m=len(ar1) n=len(ar2) merge(ar1,ar2,m,n) print("After Merging \nFirst Array:",end="") for i in range(m): print(ar1[i],"",end="") print("\nSecond Array: ",end="") for i in range(n): print(ar2[i],"",end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; ar1 := Sequence{1}->union(Sequence{5}->union(Sequence{9}->union(Sequence{10}->union(Sequence{15}->union(Sequence{ 20 }))))) ; ar2 := Sequence{2}->union(Sequence{3}->union(Sequence{8}->union(Sequence{ 13 }))) ; m := (ar1)->size() ; n := (ar2)->size() ; merge(ar1, ar2, m, n) ; execute ("After Merging \nFirst Array:")->display() ; for i : Integer.subrange(0, m-1) do ( execute (ar1[i+1])->display()) ; execute ("\nSecond Array: ")->display() ; for i : Integer.subrange(0, n-1) do ( execute (ar2[i+1])->display()); operation merge(ar1 : OclAny, ar2 : OclAny, m : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( var last : OclAny := ar1[m - 1+1] ; var j : double := m - 2 ; while (j >= 0 & (ar1[j+1]->compareTo(ar2[i+1])) > 0) do ( ar1[j + 1+1] := ar1[j+1] ; j := j - 1) ; if (j /= m - 2 or (last->compareTo(ar2[i+1])) > 0) then ( ar1[j + 1+1] := ar2[i+1] ; ar2[i+1] := last ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def inpl(): return list(map(int,input().split())) from math import log2 print(int(log2(int(input())+1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; execute (("" + ((log2(("" + (((OclFile["System.in"]).readLine())))->toInteger() + 1))))->toInteger())->display(); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=format(int(input()),'b') print(len(N)-1 if '0' in N else len(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : String := (("" + (((OclFile["System.in"]).readLine())))->toInteger() + "") ; execute (if (N)->characters()->includes('0') then (N)->size() - 1 else (N)->size() endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ret=0 bin_strlist=list(bin(n)) bin_list=bin_strlist[2 :] if bin_list.count("0")==0 : print(len(bin_list)) else : print(len(bin_list)-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ret : int := 0 ; var bin_strlist : Sequence := (bin(n)) ; var bin_list : OclAny := bin_strlist.subrange(2+1) ; if bin_list->count("0") = 0 then ( execute ((bin_list)->size())->display() ) else ( execute ((bin_list)->size() - 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) cnt=0 n+=1 while 1 : n//=2 cnt+=1 if n==1 : break print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cnt : int := 0 ; n := n + 1 ; while 1 do ( n := n div 2 ; cnt := cnt + 1 ; if n = 1 then ( break ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline H,W=map(int,input().split()) S=[list(input())for i in range(H)] dp=[0]*W if S[0][0]=='#' : dp[0]=1 for j in range(1,W): if S[0][j]!=S[0][j-1]and S[0][j-1]=='.' : dp[j]=dp[j-1]+1 else : dp[j]=dp[j-1] for i in range(1,H): if S[i][0]!=S[i-1][0]and S[i-1][0]=='.' : dp[0]=dp[0]+1 for j in range(1,W): hidari=1 if S[i][j]!=S[i][j-1]and S[i][j-1]=='.' else 0 ue=1 if S[i][j]!=S[i-1][j]and S[i-1][j]=='.' else 0 dp[j]=min(dp[j-1]+hidari,dp[j]+ue) print(dp[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : Sequence := Integer.subrange(0, H-1)->select(i | true)->collect(i | (((OclFile["System.in"]).readLine())->characters())) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, W) ; if S->first()->first() = '#' then ( dp->first() := 1 ) else skip ; for j : Integer.subrange(1, W-1) do ( if S->first()[j+1] /= S->first()[j - 1+1] & S->first()[j - 1+1] = '.' then ( dp[j+1] := dp[j - 1+1] + 1 ) else ( dp[j+1] := dp[j - 1+1] )) ; for i : Integer.subrange(1, H-1) do ( if S[i+1]->first() /= S[i - 1+1]->first() & S[i - 1+1]->first() = '.' then ( dp->first() := dp->first() + 1 ) else skip ; for j : Integer.subrange(1, W-1) do ( var hidari : int := if S[i+1][j+1] /= S[i+1][j - 1+1] & S[i+1][j - 1+1] = '.' then 1 else 0 endif ; var ue : int := if S[i+1][j+1] /= S[i - 1+1][j+1] & S[i - 1+1][j+1] = '.' then 1 else 0 endif ; dp[j+1] := Set{dp[j - 1+1] + hidari, dp[j+1] + ue}->min())) ; execute (dp->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _,*s=open(0) b,q='.'*101,range(101) for i,s in enumerate(s): a=[i] for x,y,z,c in zip(b,'.'+s,s,q): a+=min(c+(x=='.'>z),a[-1]+(y=='.'>z)), b,q=s,a[1 :] print(a[-2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _anon : OclAny := null; var s : OclAny := null; Sequence{_anon,s} := OclFile.newOclFile_Write(OclFile.newOclFile(0)) ; var b : OclAny := null; var q : OclAny := null; Sequence{b,q} := Sequence{StringLib.nCopies('.', 101),Integer.subrange(0, 101-1)} ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); var a : Sequence := Sequence{ i } ; for _tuple : Integer.subrange(1, b->size())->collect( _indx | Sequence{b->at(_indx), '.' + s->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); _indx := _indx + 1; var z : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); a := a + (testlist (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name c))) + (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (comparison (expr (atom (name x)))) == (comparison (expr (atom '.')))) > (comparison (expr (atom (name z)))))))) )))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))) + (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (comparison (expr (atom (name y)))) == (comparison (expr (atom '.')))) > (comparison (expr (atom (name z)))))))) ))))))))) ))))))) ,)) ; var b : OclAny := null; var q : OclAny := null; Sequence{b,q} := Sequence{s,a->tail()}) ; execute (a->front()->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: a=*map(int,s.split()),; x=c=y=0 for n in a : x ^=n for n in a : y ^=n if y==x : c+=1 ; y=0 print("NYOE S"[x<1 or c>1 : : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var a : OclAny := (testlist_star_expr (star_expr * (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name s)) (trailer . (name split) (arguments ( ))))))))) ))))) ,); x := x(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name y)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for n : a do ( x := x xor n) ; for n : a do ( y := y xor n ; if y = x then ( c := c + 1; var y : int := 0 ) else skip) ; execute ("NYOE S"(subscript (test (logical_test (logical_test (comparison (comparison (expr (atom (name x)))) < (comparison (expr (atom (number (integer 1))))))) or (logical_test (comparison (comparison (expr (atom (name c)))) > (comparison (expr (atom (number (integer 1))))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w=map(int,input().split()) s=[[i=="#" for i in input()]for _ in range(h)] dp=[[10**9]*w for _ in range(h)] dp[0][0]=int(s[0][0]) for i in range(h): for j in range(w): a=dp[i-1][j]+(not s[i-1][j]and s[i][j]) b=dp[i][j-1]+(not s[i][j-1]and s[i][j]) dp[i][j]=min(a,b,dp[i][j]) print(dp[-1][-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine()->select(i | true)->collect(i | (i = "#")))) ; var dp : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ (10)->pow(9) }, w))) ; dp->first()->first() := ("" + ((s->first()->first())))->toInteger() ; for i : Integer.subrange(0, h-1) do ( for j : Integer.subrange(0, w-1) do ( var a : OclAny := dp[i - 1+1][j+1] + (not(s[i - 1+1][j+1]) & s[i+1][j+1]) ; var b : OclAny := dp[i+1][j - 1+1] + (not(s[i+1][j - 1+1]) & s[i+1][j+1]) ; dp[i+1][j+1] := Set{a, b, dp[i+1][j+1]}->min())) ; execute (dp->last()->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W=list(map(int,input().split())) m=[list(input())for _ in range(H)] scores=[[None for _ in range(W)]for _ in range(H)] def calc(i,j): global m,scores,H,W if scores[i][j]is not None : return scores[i][j] if i==H-1 and j==W-1 and i!=0 and j!=0 : score=0 scores[i][j]=score return score diff=[] if jcollect( _x | (OclType["int"])->apply(_x) )) ; var m : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (((OclFile["System.in"]).readLine())->characters())) ; var scores : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, W-1)->select(_anon | true)->collect(_anon | (null)))) ; skip ; execute (calc(0, 0))->display(); operation calc(i : OclAny, j : OclAny) : OclAny pre: true post: true activity: skip; skip; skip; skip ; if not(scores[i+1][j+1] <>= null) then ( return scores[i+1][j+1] ) else skip ; if i = H - 1 & j = W - 1 & i /= 0 & j /= 0 then ( var score : int := 0 ; scores[i+1][j+1] := score ; return score ) else skip ; var diff : Sequence := Sequence{} ; if (j->compareTo(W - 1)) < 0 then ( execute ((Sequence{0, 1}) : diff) ) else skip ; if (i->compareTo(H - 1)) < 0 then ( execute ((Sequence{1, 0}) : diff) ) else skip ; var score_cand : Sequence := Sequence{} ; for _tuple : diff do (var _indx : int := 1; var di : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dj : OclAny := _tuple->at(_indx); var additional : int := 0 ; if (m[i+1][j+1] = '.' & m[i + di+1][j + dj+1] = '#') or (i = 0 & j = 0 & m->first()->first() = '#') then ( additional := additional + 1 ) else skip ; score := calc(i + di, j + dj) + additional ; execute ((score) : score_cand)) ; score := (score_cand)->min() ; scores[i+1][j+1] := score ; return score; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def resolve(): H,W=map(int,input().split(" ")) s=[] dp=[[0]*W for i in range(H)] for _ in range(H): s.append([x=="." for x in list(input())]) for h in range(H): for w in range(W): if h==0 and w==0 : if not s[0][0]: dp[0][0]=1 elif h==0 : dp[0][w]=dp[0][w-1] if s[0][w-1]and not s[0][w]: dp[0][w]+=1 elif w==0 : dp[h][0]=dp[h-1][0] if s[h-1][0]and not s[h][0]: dp[h][0]+=1 else : temp_up=dp[h-1][w] if s[h-1][w]and not s[h][w]: temp_up+=1 temp_left=dp[h][w-1] if s[h][w-1]and not s[h][w]: temp_left+=1 dp[h][w]=min(temp_up,temp_left) print(dp[H-1][W-1]) if __name__=="__main__" : resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( resolve() ) else skip; operation resolve() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := Sequence{} ; var dp : Sequence := Integer.subrange(0, H-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, W))) ; for _anon : Integer.subrange(0, H-1) do ( execute ((((OclFile["System.in"]).readLine())->characters()->select(x | true)->collect(x | (x = "."))) : s)) ; for h : Integer.subrange(0, H-1) do ( for w : Integer.subrange(0, W-1) do ( if h = 0 & w = 0 then ( if not(s->first()->first()) then ( dp->first()->first() := 1 ) else skip ) else (if h = 0 then ( dp->first()[w+1] := dp->first()[w - 1+1] ; if s->first()[w - 1+1] & not(s->first()[w+1]) then ( dp->first()[w+1] := dp->first()[w+1] + 1 ) else skip ) else (if w = 0 then ( dp[h+1]->first() := dp[h - 1+1]->first() ; if s[h - 1+1]->first() & not(s[h+1]->first()) then ( dp[h+1]->first() := dp[h+1]->first() + 1 ) else skip ) else ( var temp_up : OclAny := dp[h - 1+1][w+1] ; if s[h - 1+1][w+1] & not(s[h+1][w+1]) then ( temp_up := temp_up + 1 ) else skip ; var temp_left : OclAny := dp[h+1][w - 1+1] ; if s[h+1][w - 1+1] & not(s[h+1][w+1]) then ( temp_left := temp_left + 1 ) else skip ; dp[h+1][w+1] := Set{temp_up, temp_left}->min() ) ) ) )) ; execute (dp[H - 1+1][W - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()); for i in range(t): n=int(input()) s=input() c=0 c1=0 for j in range(n-1): if s[j]=='1' and s[j+1]=='1' : c=c+1 if s[j]=='0' and s[j+1]=='0' : c1=c1+1 print(max(c,c1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var c : int := 0 ; var c1 : int := 0 ; for j : Integer.subrange(0, n - 1-1) do ( if s[j+1] = '1' & s[j + 1+1] = '1' then ( c := c + 1 ) else skip ; if s[j+1] = '0' & s[j + 1+1] = '0' then ( c1 := c1 + 1 ) else skip) ; execute (Set{c, c1}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(i)for i in input().split()] l=[int(i)for i in input().split()] cumSum=[0] for i in range(1,n+1): v=cumSum[i-1]+l[i-1] cumSum.append(v) totalSum=0 for k in range(m): i,j=[int(i)for i in input().split()] resSum=cumSum[j]-cumSum[i-1] if(resSum>0): totalSum+=resSum print(totalSum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var l : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var cumSum : Sequence := Sequence{ 0 } ; for i : Integer.subrange(1, n + 1-1) do ( var v : OclAny := cumSum[i - 1+1] + l[i - 1+1] ; execute ((v) : cumSum)) ; var totalSum : int := 0 ; for k : Integer.subrange(0, m-1) do ( var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var resSum : double := cumSum[j+1] - cumSum[i - 1+1] ; if (resSum > 0) then ( totalSum := totalSum + resSum ) else skip) ; execute (totalSum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from itertools import accumulate n,m=map(int,input().split()) w=list(accumulate(map(int,input().split()))) s=0 for _ in range(m): l,r=map(int,input().split()) c=w[r-1]-(w[l-2]if l>1 else 0) if c>0 : s+=c print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := (accumulate((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var s : int := 0 ; for _anon : Integer.subrange(0, m-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : double := w[r - 1+1] - (if l > 1 then w[l - 2+1] else 0 endif) ; if c > 0 then ( s := s + c ) else skip) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def take_or_leave(lst1,sublst): start,end=sublst sum=0 while start<=end : sum+=lst1[start-1] start+=1 if sum<0 : return False,sum else : return True,sum if __name__=='__main__' : n,m=map(int,input().split()) lst=list(map(int,input().split())) subarrys=[] for i in range(m): x,y=map(int,input().split()) subarrys.append((x,y)) ans=0 for i in subarrys : choos,sum=take_or_leave(lst,i) if choos : ans+=sum print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var subarrys : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{x, y}) : subarrys)) ; var ans : int := 0 ; for i : subarrys do ( var choos : OclAny := null; Sequence{choos,sum} := take_or_leave(lst, i) ; if choos then ( ans := ans + sum ) else skip) ; execute (ans)->display() ) else skip; operation take_or_leave(lst1 : OclAny, sublst : OclAny) : OclAny pre: true post: true activity: var start : OclAny := null; var end : OclAny := null; Sequence{start,end} := sublst ; var sum : int := 0 ; while (start->compareTo(end)) <= 0 do ( sum := sum + lst1[start - 1+1] ; start := start + 1) ; if sum < 0 then ( return false, sum ) else ( return true, sum ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=map(int,input().split()) arr=list(map(int,input().split())) presum=[] presum.append(arr[0]) for i in range(1,n): presum.append(arr[i]+presum[i-1]) ans=0 for _ in range(t): i,j=map(int,input().split()) x=presum[j-1]-presum[i-2]if i>1 else presum[j-1] ans+=max(0,x) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var presum : Sequence := Sequence{} ; execute ((arr->first()) : presum) ; for i : Integer.subrange(1, n-1) do ( execute ((arr[i+1] + presum[i - 1+1]) : presum)) ; var ans : int := 0 ; for _anon : Integer.subrange(0, t-1) do ( var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : double := if i > 1 then presum[j - 1+1] - presum[i - 2+1] else presum[j - 1+1] endif ; ans := ans + Set{0, x}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) arr=list(map(int,input().split())) prefs=[0]*n prefs[0]=arr[0] for i in range(1,n): prefs[i]=prefs[i-1]+arr[i] sum1=0 for i in range(m): l,r=map(int,input().split()) l,r=l-1,r-1 if(l==0): if(prefs[r]>0): sum1=sum1+prefs[r] else : if(prefs[r]-prefs[l-1]>0): sum1=sum1+prefs[r]-prefs[l-1] print(sum1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var prefs : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; prefs->first() := arr->first() ; for i : Integer.subrange(1, n-1) do ( prefs[i+1] := prefs[i - 1+1] + arr[i+1]) ; var sum1 : int := 0 ; for i : Integer.subrange(0, m-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{l - 1,r - 1} ; if (l = 0) then ( if (prefs[r+1] > 0) then ( sum1 := sum1 + prefs[r+1] ) else skip ) else ( if (prefs[r+1] - prefs[l - 1+1] > 0) then ( sum1 := sum1 + prefs[r+1] - prefs[l - 1+1] ) else skip )) ; execute (sum1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def two_factor(n): twocount=0 while n % 2==0 : twocount+=1 n=int(n/2) return twocount def five_factor(n): fivecount=0 while n % 5==0 : fivecount+=1 n=int(n/5) return fivecount def find_con_zero(arr,n): twocount=0 fivecount=0 for i in range(n): twocount+=two_factor(arr[i]) fivecount+=five_factor(arr[i]) if twocountunion(Sequence{10}->union(Sequence{5}->union(Sequence{25}->union(Sequence{35}->union(Sequence{ 14 }))))) ; n := 6 ; execute (find_con_zero(arr, n))->display(); operation two_factor(n : OclAny) : OclAny pre: true post: true activity: var twocount : int := 0 ; while n mod 2 = 0 do ( twocount := twocount + 1 ; n := ("" + ((n / 2)))->toInteger()) ; return twocount; operation five_factor(n : OclAny) : OclAny pre: true post: true activity: var fivecount : int := 0 ; while n mod 5 = 0 do ( fivecount := fivecount + 1 ; n := ("" + ((n / 5)))->toInteger()) ; return fivecount; operation find_con_zero(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: twocount := 0 ; fivecount := 0 ; for i : Integer.subrange(0, n-1) do ( twocount := twocount + two_factor(arr[i+1]) ; fivecount := fivecount + five_factor(arr[i+1])) ; if (twocount->compareTo(fivecount)) < 0 then ( return twocount ) else ( return fivecount ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=10000 MAX_ELEMENT=50 dp=[[[-1 for i in range(MAX)]for j in range(MAX_ELEMENT)]for k in range(MAX_ELEMENT)] def Max_Xor(arr,i,j,mask,n): if(i>=n): if(j==0): return mask else : return 0 if(dp[i][j][mask]!=-1): return dp[i][j][mask] ans=0 if(j>0): ans=Max_Xor(arr,i+1,j-1,mask ^ arr[i],n) ans=max(ans,Max_Xor(arr,i+1,j,mask,n)) dp[i][j][mask]=ans return ans arr=[2,5,4,1,3,7,6,8] n=len(arr) k=3 print(Max_Xor(arr,0,k,0,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 10000 ; var MAX_ELEMENT : int := 50 ; var dp : Sequence := Integer.subrange(0, MAX_ELEMENT-1)->select(k | true)->collect(k | (Integer.subrange(0, MAX_ELEMENT-1)->select(j | true)->collect(j | (Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (-1)))))) ; skip ; arr := Sequence{2}->union(Sequence{5}->union(Sequence{4}->union(Sequence{1}->union(Sequence{3}->union(Sequence{7}->union(Sequence{6}->union(Sequence{ 8 }))))))) ; n := (arr)->size() ; var k : int := 3 ; execute (Max_Xor(arr, 0, k, 0, n))->display(); operation Max_Xor(arr : OclAny, i : OclAny, j : OclAny, mask : OclAny, n : OclAny) : OclAny pre: true post: true activity: if ((i->compareTo(n)) >= 0) then ( if (j = 0) then ( return mask ) else ( return 0 ) ) else skip ; if (dp[i+1][j+1][mask+1] /= -1) then ( return dp[i+1][j+1][mask+1] ) else skip ; var ans : int := 0 ; if (j > 0) then ( ans := Max_Xor(arr, i + 1, j - 1, MathLib.bitwiseXor(mask, arr[i+1]), n) ) else skip ; ans := Set{ans, Max_Xor(arr, i + 1, j, mask, n)}->max() ; dp[i+1][j+1][mask+1] := ans ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import enum import io,os,sys input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline output=sys.stdout.write DEBUG=os.environ.get('debug')not in[None,'0'] if DEBUG : from inspect import currentframe,getframeinfo from re import search def debug(*args): if not DEBUG : return frame=currentframe().f_back s=getframeinfo(frame).code_context[0] r=search(r"\((.*)\)",s).group(1) vnames=r.split(',') var_and_vals=[f'{var}={val}' for var,val in zip(vnames,args)] prefix=f'{currentframe().f_back.f_lineno:02d}: ' print(f'{prefix}{",".join(var_and_vals)}') from random import randrange RAND=randrange(1<<62) def conv(x): return x ^ RAND INF=float('inf') def solve(N,A): X=0 for a in A : X ^=a if X==0 : return 'YES' x=cnt=0 for a in A : x ^=a if x==X : x=0 cnt+=1 return 'YES' if cnt>1 else 'NO' def main(): T=int(input()) for _ in range(T): N=int(input()) A=list(map(int,input().split())) out=solve(N,A) print(out) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var output : OclAny := (OclFile["System.out"]).write ; var DEBUG : boolean := (Sequence{null}->union(Sequence{ '0' }))->excludes(os.environ.get('debug')) ; if DEBUG then ( skip ; skip ) else skip ; skip ; skip ; var RAND : OclAny := randrange(1 * (2->pow(62))) ; skip ; var INF : double := ("" + (('inf')))->toReal() ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation debug(args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) if not(DEBUG) then ( return ) else skip ; var frame : OclAny := currentframe().f_back ; var s : OclAny := getframeinfo(frame).code_context->first() ; var r : OclAny := search(StringLib.rawString("\((.*)\)"), s).group(1) ; var vnames : String := r.split(',') ; var var_and_vals : Sequence := Integer.subrange(1, vnames->size())->collect( _indx | Sequence{vnames->at(_indx), args->at(_indx)} )->select(_tuple | true)->collect(_tuple | let var : OclAny = _tuple->at(1) in let val : OclAny = _tuple->at(2) in (StringLib.formattedString('{var}={val}'))) ; var prefix : String := StringLib.formattedString('{currentframe().f_back.f_lineno:02d}: ') ; execute (StringLib.formattedString('{prefix}{",".join(var_and_vals)}'))->display(); operation conv(x : OclAny) : OclAny pre: true post: true activity: return MathLib.bitwiseXor(x, RAND); operation solve(N : OclAny, A : OclAny) : OclAny pre: true post: true activity: var X : int := 0 ; for a : A do ( X := X xor a) ; if X = 0 then ( return 'YES' ) else skip ; x := 0; var cnt : int := 0 ; for a : A do ( x := x xor a ; if x = X then ( x := 0 ; cnt := cnt + 1 ) else skip) ; return if cnt > 1 then 'YES' else 'NO' endif; operation main() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, T-1) do ( N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; A := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var out : OclAny := solve(N, A) ; execute (out)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ksmallest(arr,n,k): for i in range(n): if(arr[i]<=k): k=k+1 ; else : break ; return k ; k=1 ; arr=[1]; n=len(arr); print(ksmallest(arr,n,k)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; k := 1; ; arr := Sequence{ 1 }; ; n := (arr)->size(); ; execute (ksmallest(arr, n, k))->display();; operation ksmallest(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if ((arr[i+1]->compareTo(k)) <= 0) then ( k := k + 1; ) else ( break; )) ; return k;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sum(arr,n): sum=0 for i in arr : sum+=i sum=sum*pow(2,n-1) return sum arr=[2,1,5,6] n=len(arr) print(sum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{1}->union(Sequence{5}->union(Sequence{ 6 }))) ; n := (arr)->size() ; execute ((arr, n)->sum())->display(); operation sum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : arr do ( sum := sum + i) ; sum := sum * (2)->pow(n - 1) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(a==0): return b return gcd(b % a,a) def sameRemainder(a,b,c): a1=(b-a) b1=(c-b) c1=(c-a) return gcd(a1,gcd(b1,c1)) a=62 b=132 c=237 print(sameRemainder(a,b,c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 62 ; b := 132 ; c := 237 ; execute (sameRemainder(a, b, c))->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0) then ( return b ) else skip ; return gcd(b mod a, a); operation sameRemainder(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: var a1 : double := (b - a) ; var b1 : double := (c - b) ; var c1 : double := (c - a) ; return gcd(a1, gcd(b1, c1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np import sys INT_MIN=-(sys.maxsize-1) def maxSum(a,n): sum=0 ; for i in range(n): sum+=a[i]; limit=2*sum+1 ; dp=np.zeros((n+1,limit)); for i in range(n+1): for j in range(limit): dp[i][j]=INT_MIN ; dp[0][sum]=0 ; for i in range(1,n+1): for j in range(limit): if((j-a[i-1])>=0 and dp[i-1][j-a[i-1]]!=INT_MIN): dp[i][j]=max(dp[i][j],dp[i-1][j-a[i-1]]+a[i-1]); if((j+a[i-1])union(Sequence{2}->union(Sequence{3}->union(Sequence{ 6 }))); ; execute (maxSum(a, n))->display(); ) else skip; operation maxSum(a : OclAny, n : OclAny) pre: true post: true activity: var sum : int := 0; ; for i : Integer.subrange(0, n-1) do ( sum := sum + a[i+1];) ; var limit : int := 2 * sum + 1; ; var dp : Sequence := MatrixLib.singleValueMatrix(Sequence{n + 1, limit}, 0.0); ; for i : Integer.subrange(0, n + 1-1) do ( for j : Integer.subrange(0, limit-1) do ( dp[i+1][j+1] := INT_MIN;)) ; dp->first()[sum+1] := 0; ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(0, limit-1) do ( if ((j - a[i - 1+1]) >= 0 & dp[i - 1+1][j - a[i - 1+1]+1] /= INT_MIN) then ( dp[i+1][j+1] := Set{dp[i+1][j+1], dp[i - 1+1][j - a[i - 1+1]+1] + a[i - 1+1]}->max(); ) else skip ; if (((j + a[i - 1+1])->compareTo(limit)) < 0 & dp[i - 1+1][j + a[i - 1+1]+1] /= INT_MIN) then ( dp[i+1][j+1] := Set{dp[i+1][j+1], dp[i - 1+1][j + a[i - 1+1]+1]}->max(); ) else skip ; if (dp[i - 1+1][j+1] /= INT_MIN) then ( dp[i+1][j+1] := Set{dp[i+1][j+1], dp[i - 1+1][j+1]}->max(); ) else skip)) ; return dp[n+1][sum+1];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,m=map(int,input().split()) f=False for _ in range(n): a,b=map(int,input().split()) c,d=map(int,input().split()) if b==c : f=True if m & 1 : print("NO") else : print("YES" if f else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var f : boolean := false ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if b = c then ( f := true ) else skip) ; if MathLib.bitwiseAnd(m, 1) then ( execute ("NO")->display() ) else ( execute (if f then "YES" else "NO" endif)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for j in range(0,n): n,m=map(int,input().split()) l=[] for k in range(0,n): a1,a2=map(int,input().split()) a3,a4=map(int,input().split()) l.append([a1,a2,a3,a4]) a=False for i in range(0,n): if l[i][1]==l[i][2]: a=True break if m % 2==1 : print("NO") else : if a : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, n-1) do ( var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := Sequence{} ; for k : Integer.subrange(0, n-1) do ( var a1 : OclAny := null; var a2 : OclAny := null; Sequence{a1,a2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a3 : OclAny := null; var a4 : OclAny := null; Sequence{a3,a4} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a1}->union(Sequence{a2}->union(Sequence{a3}->union(Sequence{ a4 })))) : l)) ; var a : boolean := false ; for i : Integer.subrange(0, n-1) do ( if l[i+1][1+1] = l[i+1][2+1] then ( a := true ; break ) else skip) ; if m mod 2 = 1 then ( execute ("NO")->display() ) else ( if a then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=map(int,input().split()) f=0 for i in range(n): a,b=map(int,input().split()) c,d=map(int,input().split()) if b==c : f=1 if m % 2 : print('NO') else : print('YES')if f else print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var f : int := 0 ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if b = c then ( f := 1 ) else skip) ; if m mod 2 then ( execute ('NO')->display() ) else ( (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))) if (logical_test (comparison (expr (atom (name f))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) )))))))) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): s="NO" n,m=map(int,input().split()) for i in range(n): a,b=map(int,input().split()) c,d=map(int,input().split()) if(b==c and m % 2==0): s="YES" print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := "NO" ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (b = c & m mod 2 = 0) then ( s := "YES" ) else skip) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=map(int,input().split()) M=[[0]*2 for i in range(2*n)] Nb=0 for i in range(2*n): M[i]=list(map(int,input().split())) if i % 2==1 : if M[i][0]==M[i-1][1]: Nb+=1 if Nb==0 or m % 2==1 : print('NO') else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var M : Sequence := Integer.subrange(0, 2 * n-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, 2))) ; var Nb : int := 0 ; for i : Integer.subrange(0, 2 * n-1) do ( M[i+1] := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if i mod 2 = 1 then ( if M[i+1]->first() = M[i - 1+1][1+1] then ( Nb := Nb + 1 ) else skip ) else skip) ; if Nb = 0 or m mod 2 = 1 then ( execute ('NO')->display() ) else ( execute ('YES')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline a,b,c=[int(i)for i in input().split()] m=int(input()) p,u=[],[] for _ in range(m): v,t=[i for i in input().split()] v=int(v) if t[0]=="P" : p.append(v) else : u.append(v) p.sort() u.sort() cnt=min(a,len(u))+min(b,len(p)) ans=sum(u[: min(a,len(u))]) ans+=sum(p[: min(b,len(p))]) p=p[min(b,len(p)):] u=u[min(a,len(u)):] i,j,d=0,0,0 while 1 : if d==c : break if iselect(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : OclAny := null; var u : OclAny := null; Sequence{p,u} := Sequence{Sequence{},Sequence{}} ; for _anon : Integer.subrange(0, m-1) do ( var v : OclAny := null; var t : OclAny := null; Sequence{v,t} := input().split()->select(i | true)->collect(i | (i)) ; var v : int := ("" + ((v)))->toInteger() ; if t->first() = "P" then ( execute ((v) : p) ) else ( execute ((v) : u) )) ; p := p->sort() ; u := u->sort() ; var cnt : OclAny := Set{a, (u)->size()}->min() + Set{b, (p)->size()}->min() ; var ans : OclAny := (u.subrange(1,Set{a, (u)->size()}->min()))->sum() ; ans := ans + (p.subrange(1,Set{b, (p)->size()}->min()))->sum() ; var p : OclAny := p.subrange(Set{b, (p)->size()}->min()+1) ; var u : OclAny := u.subrange(Set{a, (u)->size()}->min()+1) ; var i : OclAny := null; var j : OclAny := null; var d : OclAny := null; Sequence{i,j,d} := Sequence{0,0,0} ; while 1 do ( if d = c then ( break ) else skip ; if (i->compareTo((p)->size())) < 0 & (j->compareTo((u)->size())) < 0 then ( if (p[i+1]->compareTo(u[j+1])) < 0 then ( ans := ans + p[i+1]; i := i + 1 ) else ( ans := ans + u[j+1]; j := j + 1 ) ; d := d + 1 ) else (if (i->compareTo((p)->size())) < 0 then ( ans := ans + p[i+1] ; d := d + 1 ; i := i + 1 ) else (if (j->compareTo((u)->size())) < 0 then ( ans := ans + u[j+1] ; j := j + 1 ; d := d + 1 ) else ( break ) ) ) ) ; cnt := cnt + d ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) n=int(input()) pt=[] for i in range(n): pt.append(list(map(str,input().split()))) pt=sorted(pt,key=lambda x : int(x[0])) price=0 amount=0 for i,j in pt : i=int(i) if j=='USB' : if a!=0 : a-=1 price+=i amount+=1 elif c!=0 : c-=1 price+=i amount+=1 if j=='PS/2' : if b!=0 : b-=1 price+=i amount+=1 elif c!=0 : c-=1 price+=i amount+=1 print(amount,price) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var pt : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["String"])->apply(_x) ))) : pt)) ; pt := pt->sortedBy($x | (lambda x : OclAny in (("" + ((x->first())))->toInteger()))->apply($x)) ; var price : int := 0 ; var amount : int := 0 ; for _tuple : pt do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); var i : int := ("" + ((i)))->toInteger() ; if j = 'USB' then ( if a /= 0 then ( a := a - 1 ; price := price + i ; amount := amount + 1 ) else (if c /= 0 then ( c := c - 1 ; price := price + i ; amount := amount + 1 ) else skip) ) else skip ; if j = 'PS/2' then ( if b /= 0 then ( b := b - 1 ; price := price + i ; amount := amount + 1 ) else (if c /= 0 then ( c := c - 1 ; price := price + i ; amount := amount + 1 ) else skip) ) else skip) ; execute (amount)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) ans=0 for i in a : ans=ans ^ i if(ans==0): print("YES") else : x=0 ans1=0 for i in a : x=x ^ i if(x==ans): ans1+=1 x=0 if(ans1 % 2==1 and ans1>2): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : a do ( ans := MathLib.bitwiseXor(ans, i)) ; if (ans = 0) then ( execute ("YES")->display() ) else ( var x : int := 0 ; var ans1 : int := 0 ; for i : a do ( x := MathLib.bitwiseXor(x, i) ; if (x = ans) then ( ans1 := ans1 + 1 ; x := 0 ) else skip) ; if (ans1 mod 2 = 1 & ans1 > 2) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() s=s.split() n=int(s[0]) m=int(s[1]) k=int(s[2]) num=int(input()) a=[] b=[] for i in range(num): s=input() s=s.split() if s[1]=="USB" : a.append(int(s[0])) else : b.append(int(s[0])) a.sort() b.sort() x=0 y=0 ans=0 for i in range(n): if x==len(a): break ans+=a[x] x+=1 for i in range(m): if y==len(b): break ans+=b[y] y+=1 for i in range(k): if(x==len(a))and(y==len(b)): break if x==len(a): ans+=b[y] y+=1 elif y==len(b): ans+=a[x] x+=1 elif a[x]<=b[y]: ans+=a[x] x+=1 else : ans+=b[y] y+=1 print(f"{x+y}{ans}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; s := s.split() ; var n : int := ("" + ((s->first())))->toInteger() ; var m : int := ("" + ((s[1+1])))->toInteger() ; var k : int := ("" + ((s[2+1])))->toInteger() ; var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; for i : Integer.subrange(0, num-1) do ( s := (OclFile["System.in"]).readLine() ; s := s.split() ; if s[1+1] = "USB" then ( execute ((("" + ((s->first())))->toInteger()) : a) ) else ( execute ((("" + ((s->first())))->toInteger()) : b) )) ; a := a->sort() ; b := b->sort() ; var x : int := 0 ; var y : int := 0 ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if x = (a)->size() then ( break ) else skip ; ans := ans + a[x+1] ; x := x + 1) ; for i : Integer.subrange(0, m-1) do ( if y = (b)->size() then ( break ) else skip ; ans := ans + b[y+1] ; y := y + 1) ; for i : Integer.subrange(0, k-1) do ( if (x = (a)->size()) & (y = (b)->size()) then ( break ) else skip ; if x = (a)->size() then ( ans := ans + b[y+1] ; y := y + 1 ) else (if y = (b)->size() then ( ans := ans + a[x+1] ; x := x + 1 ) else (if (a[x+1]->compareTo(b[y+1])) <= 0 then ( ans := ans + a[x+1] ; x := x + 1 ) else ( ans := ans + b[y+1] ; y := y + 1 ) ) ) ) ; execute (StringLib.formattedString("{x+y}{ans}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- aa,b,c,d=map(int,input().split()) ls,sum=[aa,b,c],0 ls=sorted(ls) if ls[1]-ls[0]collect( _x | (OclType["int"])->apply(_x) ) ; var ls : OclAny := null; var sum : OclAny := null; Sequence{ls,sum} := Sequence{Sequence{aa}->union(Sequence{b}->union(Sequence{ c })),0} ; var ls : Sequence := ls->sort() ; if (ls[1+1] - ls->first()->compareTo(d)) < 0 then ( sum := sum + (d - ls[1+1] + ls->first()) ) else skip ; if (ls[2+1] - ls[1+1]->compareTo(d)) < 0 then ( sum := sum + (d - ls[2+1] + ls[1+1]) ) else skip ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) m=int(input()) mouses_by_price={} for i in range(m): v,t=input().split() v=int(v) if v not in mouses_by_price : mouses_by_price[v]={'USB' : 0,'PS/2' : 0,} mouses_by_price[v][t]+=1 total_cost=0 total_mouses=0 for mouse_cost in sorted(mouses_by_price): usb=mouses_by_price[mouse_cost]['USB'] ps2=mouses_by_price[mouse_cost]['PS/2'] usb_a=min(usb,a) usb-=usb_a a-=usb_a ps2_b=min(ps2,b) ps2-=ps2_b b-=ps2_b mouse_c=min(c,ps2+usb) c-=mouse_c total_mouses+=usb_a+ps2_b+mouse_c total_cost+=(usb_a+ps2_b+mouse_c)*mouse_cost if c==a==b==0 : break print(total_mouses,total_cost) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mouses_by_price : OclAny := Set{} ; for i : Integer.subrange(0, m-1) do ( var v : OclAny := null; var t : OclAny := null; Sequence{v,t} := input().split() ; var v : int := ("" + ((v)))->toInteger() ; if (mouses_by_price)->excludes(v) then ( mouses_by_price[v+1] := Map{ 'USB' |-> 0 }->union((dictorsetmaker (test (logical_test (comparison (expr (atom 'PS/2'))))) : (test (logical_test (comparison (expr (atom (number (integer 0))))))) ,)) ) else skip ; mouses_by_price[v+1][t+1] := mouses_by_price[v+1][t+1] + 1) ; var total_cost : int := 0 ; var total_mouses : int := 0 ; for mouse_cost : mouses_by_price->sort() do ( var usb : OclAny := mouses_by_price[mouse_cost+1]->at('USB') ; var ps2 : OclAny := mouses_by_price[mouse_cost+1]->at('PS/2') ; var usb_a : OclAny := Set{usb, a}->min() ; usb := usb - usb_a ; a := a - usb_a ; var ps2_b : OclAny := Set{ps2, b}->min() ; ps2 := ps2 - ps2_b ; b := b - ps2_b ; var mouse_c : OclAny := Set{c, ps2 + usb}->min() ; c := c - mouse_c ; total_mouses := total_mouses + usb_a + ps2_b + mouse_c ; total_cost := total_cost + (usb_a + ps2_b + mouse_c) * mouse_cost ; if c = a & (a == b) & (b == 0) then ( break ) else skip) ; execute (total_mouses)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def strBitwiseOR(arr,n): res="" max_size=-(2**32) for i in range(n): max_size=max(max_size,len(arr[i])) arr[i]=arr[i][: :-1] for i in range(n): s="" for j in range(max_size-len(arr[i])): s+='0' arr[i]=arr[i]+s for i in range(max_size): curr_bit=0 for j in range(n): curr_bit=curr_bit | ord(arr[j][i]) res+=chr(curr_bit) res=res[: :-1] return res arr=["10","11","1000001"] n=len(arr) print(strBitwiseOR(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{"10"}->union(Sequence{"11"}->union(Sequence{ "1000001" })) ; n := (arr)->size() ; execute (strBitwiseOR(arr, n))->display(); operation strBitwiseOR(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var res : String := "" ; var max_size : double := -((2)->pow(32)) ; for i : Integer.subrange(0, n-1) do ( max_size := Set{max_size, (arr[i+1])->size()}->max() ; arr[i+1] := arr[i+1](subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ; for i : Integer.subrange(0, n-1) do ( var s : String := "" ; for j : Integer.subrange(0, max_size - (arr[i+1])->size()-1) do ( s := s + '0') ; arr[i+1] := arr[i+1] + s) ; for i : Integer.subrange(0, max_size-1) do ( var curr_bit : int := 0 ; for j : Integer.subrange(0, n-1) do ( curr_bit := MathLib.bitwiseOr(curr_bit, (arr[j+1][i+1])->char2byte())) ; res := res + (curr_bit)->byte2char()) ; res := res(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(arr,N): even=0 ; odd=0 ; for i in range(N): if(arr[i]% 2==1): odd+=1 ; else : even+=1 ; if(even==N or odd==N): print("Yes"); else : print("No"); if __name__=='__main__' : arr=[1,1,3]; N=len(arr); check(arr,N); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{1}->union(Sequence{ 3 })); ; N := (arr)->size(); ; check(arr, N); ) else skip; operation check(arr : OclAny, N : OclAny) pre: true post: true activity: var even : int := 0; ; var odd : int := 0; ; for i : Integer.subrange(0, N-1) do ( if (arr[i+1] mod 2 = 1) then ( odd := odd + 1; ) else ( even := even + 1; )) ; if (even = N or odd = N) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) floors=[input()for _ in range(n)][: :-1] while floors and '1' not in floors[-1]: floors.pop() n-=1 if n==1 : print(floors[0].rfind('1')) exit() dp=[[0,0]] for i in range(n): if '1' not in floors[i]: dp.append([dp[-1][0]+1,dp[-1][1]+1]) continue lx=m+1-floors[i].find('1') rx=floors[i].rfind('1') if i==n-1 : l=rx-1+dp[-1][0] r=lx-1+dp[-1][1] elif i==0 : l=2*rx+dp[-1][0] r=m+1+dp[-1][1] else : l=min(2*rx+dp[-1][0],m+1+dp[-1][1]) r=min(2*lx+dp[-1][1],m+1+dp[-1][0]) dp.append([l+1,r+1]) print(min(dp[-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var floors : OclAny := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine()))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; while floors & (floors->last())->excludes('1') do ( floors := floors->front() ; n := n - 1) ; if n = 1 then ( execute (floors->first().rfind('1'))->display() ; exit() ) else skip ; var dp : Sequence := Sequence{ Sequence{0}->union(Sequence{ 0 }) } ; for i : Integer.subrange(0, n-1) do ( if (floors[i+1])->excludes('1') then ( execute ((Sequence{dp->last()->first() + 1}->union(Sequence{ dp->last()[1+1] + 1 })) : dp) ; continue ) else skip ; var lx : double := m + 1 - floors[i+1]->indexOf('1') - 1 ; var rx : OclAny := floors[i+1].rfind('1') ; if i = n - 1 then ( var l : double := rx - 1 + dp->last()->first() ; var r : double := lx - 1 + dp->last()[1+1] ) else (if i = 0 then ( l := 2 * rx + dp->last()->first() ; r := m + 1 + dp->last()[1+1] ) else ( l := Set{2 * rx + dp->last()->first(), m + 1 + dp->last()[1+1]}->min() ; r := Set{2 * lx + dp->last()[1+1], m + 1 + dp->last()->first()}->min() ) ) ; execute ((Sequence{l + 1}->union(Sequence{ r + 1 })) : dp)) ; execute ((dp->last())->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(x)for x in input().split()] if n!=1 : left=[0]*(n+1) right=[0]*(n+1) right[0]=float("inf") stairs=[] for i in range(n): stairs.append(input()) stairs.reverse() while True : if len(stairs)!=0 and "1" not in stairs[-1]: stairs.pop() else : break if len(stairs)==0 : print(0) exit() for i in range(1,len(stairs)): has_light="1" in stairs[i-1] first_index=0 last_index=0 if not has_light : first_index=m+1 last_index=0 else : first_index=stairs[i-1].index("1") last_index=stairs[i-1].rindex("1") left[i]=min(left[i-1]+2*last_index+1,right[i-1]+m+2) right[i]=min(left[i-1]+m+2,right[i-1]+2*(m+1-first_index)+1) left_offset=stairs[-1].rindex("1")if "1" in stairs[-1]else 0 right_offset=stairs[-1].index("1")if "1" in stairs[-1]else 0 left_cost=left[len(stairs)-1]+left_offset right_cost=right[len(stairs)-1]+m+1-right_offset print(min(left_cost,right_cost)) else : s=input() if "1" in s : print(s.rindex("1")) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if n /= 1 then ( var left : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var right : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; right->first() := ("" + (("inf")))->toReal() ; var stairs : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : stairs)) ; stairs := stairs->reverse() ; while true do ( if (stairs)->size() /= 0 & (stairs->last())->excludes("1") then ( stairs := stairs->front() ) else ( break )) ; if (stairs)->size() = 0 then ( execute (0)->display() ; exit() ) else skip ; for i : Integer.subrange(1, (stairs)->size()-1) do ( var has_light : boolean := (stairs[i - 1+1])->includes("1") ; var first_index : int := 0 ; var last_index : int := 0 ; if not(has_light) then ( first_index := m + 1 ; last_index := 0 ) else ( first_index := stairs[i - 1+1]->indexOf("1") - 1 ; last_index := stairs[i - 1+1].rindex("1") ) ; left[i+1] := Set{left[i - 1+1] + 2 * last_index + 1, right[i - 1+1] + m + 2}->min() ; right[i+1] := Set{left[i - 1+1] + m + 2, right[i - 1+1] + 2 * (m + 1 - first_index) + 1}->min()) ; var left_offset : OclAny := if (stairs->last())->includes("1") then stairs->last().rindex("1") else 0 endif ; var right_offset : OclAny := if (stairs->last())->includes("1") then stairs->last()->indexOf("1") - 1 else 0 endif ; var left_cost : OclAny := left[(stairs)->size() - 1+1] + left_offset ; var right_cost : double := right[(stairs)->size() - 1+1] + m + 1 - right_offset ; execute (Set{left_cost, right_cost}->min())->display() ) else ( var s : String := (OclFile["System.in"]).readLine() ; if (s)->characters()->includes("1") then ( execute (s.rindex("1"))->display() ) else ( execute (0)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def index(st,ch): for i in range(len(st)): if(st[i]==ch): return i ; return-1 def printNumbers(n,d): st=""+str(d) ch=st[0] for i in range(0,n+1,1): st="" st=st+str(i) if(i==d or index(st,ch)>=0): print(i,end=" ") if __name__=='__main__' : n=100 d=5 printNumbers(n,d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( n := 100 ; d := 5 ; printNumbers(n, d) ) else skip; operation index(st : OclAny, ch : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, (st)->size()-1) do ( if (st[i+1] = ch) then ( return i; ) else skip) ; return -1; operation printNumbers(n : OclAny, d : OclAny) pre: true post: true activity: st := "" + ("" + ((d))) ; ch := st->first() ; for i : Integer.subrange(0, n + 1-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( st := "" ; st := st + ("" + ((i))) ; if (i = d or index(st, ch) >= 0) then ( execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a,b,c=map(int,input().split()) for k in range(60): t=math.ceil((k*(a+b)-c)/60) if t<=(k*(a+b)+a-c)/60 : print(t*60+c) break else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (compound_stmt for (exprlist (expr (atom (name k)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 60))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name t)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name math)) (trailer . (name ceil) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name k))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name a))) + (expr (atom (name b)))))))) )))) - (expr (atom (name c)))))))) ))) / (expr (atom (number (integer 60)))))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name t)))) <= (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (expr (atom (name k))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name a))) + (expr (atom (name b)))))))) )))) + (expr (atom (name a)))) - (expr (atom (name c)))))))) ))) / (expr (atom (number (integer 60))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name t))) * (expr (atom (number (integer 60))))) + (expr (atom (name c))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] while True : a,b,c=LI() s=set() s.add(0) t=0 r=-1 for i in range(60): while t>c : c+=60 if t<=c<=t+a : r=c break t+=a+b rr.append(r) break return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := LI() ; s := Set{}->union(()) ; execute ((0) : s) ; var t : int := 0 ; var r : int := -1 ; for i : Integer.subrange(0, 60-1) do ( while (t->compareTo(c)) > 0 do ( c := c + 60) ; if (t->compareTo(c)) <= 0 & (c <= t + a) then ( r := c ; break ) else skip ; t := t + a + b) ; execute ((r) : rr) ; break) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import count a,b,c=map(int,input().split()) g=set() for n in count(0): p=(c+60*n)//(a+b) if((a+b)*p-(c+60*n),(c+60*n)-((a+b)*p+a))in g : n=-1 break if(a+b)*p<=c+60*n<=(a+b)*p+a : break else : d=(a+b)*p-(c+60*n) e=(c+60*n)-((a+b)*p+a) g.add((d,e)) if n>=0 : print(c+60*n) else : print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var g : Set := Set{}->union(()) ; for n : count(0) do ( var p : int := (c + 60 * n) div (a + b) ; if (g)->includes(Sequence{(a + b) * p - (c + 60 * n), (c + 60 * n) - ((a + b) * p + a)}) then ( var n : int := -1 ; break ) else skip ; if ((a + b) * p->compareTo(c + 60 * n)) <= 0 & (c + 60 * n <= (a + b) * p + a) then ( break ) else ( var d : double := (a + b) * p - (c + 60 * n) ; var e : double := (c + 60 * n) - ((a + b) * p + a) ; execute ((Sequence{d, e}) : g) )) ; if n >= 0 then ( execute (c + 60 * n)->display() ) else ( execute (n)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: a=[0] for x in s.split(): a+=a[-1]^ int(x), print('NYOE S'[0 in a[a.index(a[-1]):]: : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var a : Sequence := Sequence{ 0 } ; for x : s.split() do ( a := a + (testlist (test (logical_test (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))) ^ (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))))))) ,)) ; execute ('NYOE S'(subscript (test (logical_test (comparison (comparison (expr (atom (number (integer 0))))) in (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))))) ))))))) :)) ]))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=list(map(int,input().split(' '))) b=a[: 3] b.sort() t=0 if(b[1]-b[0]collect( _x | (OclType["int"])->apply(_x) )) ; var b : OclAny := a.subrange(1,3) ; b := b->sort() ; var t : int := 0 ; if ((b[1+1] - b->first()->compareTo(a[3+1])) < 0) then ( t := a[3+1] - (b[1+1] - b->first()) ) else skip ; if ((b[2+1] - b[1+1]->compareTo(a[3+1])) < 0) then ( t := t + a[3+1] - (b[2+1] - b[1+1]) ) else skip ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def horizontal_input(T=str): return list(map(T,input().split())) def vertical_input(n,T=str,sep=False,septype=tuple): data=[] if sep : for i in range(n): data.append(septype(map(T,input().split()))) else : for i in range(n): data.append(T(input())) return data a,b,c=horizontal_input(int) count=0 time=0 f=True past=0 alltime=0 while count<70 : if f : time=(time+a)% 60 else : time=(time+b)% 60 if f and(past<=c<=time or(past>=time and(0=time : count+=1 past=time f=not f else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := horizontal_input(OclType["int"]) ; var count : int := 0 ; var time : int := 0 ; var f : boolean := true ; var past : int := 0 ; var alltime : int := 0 ; (compound_stmt while (test (logical_test (comparison (comparison (expr (atom (name count)))) < (comparison (expr (atom (number (integer 70)))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name f)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name time)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name time))) + (expr (atom (name a)))))))) ))) % (expr (atom (number (integer 60))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name time)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name time))) + (expr (atom (name b)))))))) ))) % (expr (atom (number (integer 60)))))))))))))))))) (stmt (compound_stmt if (test (logical_test (logical_test (comparison (expr (atom (name f))))) and (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (comparison (expr (atom (name past)))) <= (comparison (expr (atom (name c))))) <= (comparison (expr (atom (name time)))))) or (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom (name past)))) >= (comparison (expr (atom (name time)))))) and (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (comparison (expr (atom (number (integer 0))))) < (comparison (expr (atom (name c))))) <= (comparison (expr (atom (name time)))))) or (logical_test (comparison (comparison (comparison (expr (atom (name past)))) <= (comparison (expr (atom (name c))))) < (comparison (expr (atom (number (integer 60)))))))))) )))))))) )))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name alltime))) + (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name c))) - (expr (atom (name past)))))) if (logical_test (comparison (comparison (comparison (expr (atom (name past)))) <= (comparison (expr (atom (name c))))) < (comparison (expr (atom (number (integer 60))))))) else (test (logical_test (comparison (expr (expr (expr (atom (number (integer 60)))) - (expr (atom (name past)))) + (expr (atom (name c))))))))) ))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))) (elif_clause elif (test (logical_test (comparison (expr (atom (name f)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name alltime)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name a))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name alltime)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name b))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name past)))) >= (comparison (expr (atom (name time))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name count)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name past)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name time)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name f)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test not (logical_test (comparison (expr (atom (name f)))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ))))))))))))))); operation horizontal_input(T : OclAny) : OclAny pre: true post: true activity: if T->oclIsUndefined() then T := OclType["String"] else skip; return ((input().split())->collect( _x | (T)->apply(_x) )); operation vertical_input(n : OclAny, T : OclAny, sep : OclAny, septype : OclAny) : OclAny pre: true post: true activity: if T->oclIsUndefined() then T := OclType["String"] else skip; if sep->oclIsUndefined() then sep := false else skip; if septype->oclIsUndefined() then septype := tuple else skip; var data : Sequence := Sequence{} ; if sep then ( for i : Integer.subrange(0, n-1) do ( execute ((septype((input().split())->collect( _x | (T)->apply(_x) ))) : data)) ) else ( for i : Integer.subrange(0, n-1) do ( execute ((T((OclFile["System.in"]).readLine())) : data)) ) ; return data; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) flag=True if a+b==60 and c>a : print(-1) else : right=0 left=a i=0 while True : if left>=c and c>=right : print(c) break if left+b>c and c>right+a : c+=60 left+=(b+a) right+=(a+b) i+=1 if i>60 : print(-1) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var flag : boolean := true ; if a + b = 60 & (c->compareTo(a)) > 0 then ( execute (-1)->display() ) else ( var right : int := 0 ; var left : OclAny := a ; var i : int := 0 ; while true do ( if (left->compareTo(c)) >= 0 & (c->compareTo(right)) >= 0 then ( execute (c)->display() ; break ) else skip ; if (left + b->compareTo(c)) > 0 & (c->compareTo(right + a)) > 0 then ( c := c + 60 ) else skip ; left := left + (b + a) ; right := right + (a + b) ; i := i + 1 ; if i > 60 then ( execute (-1)->display() ; break ) else skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,k=list(map(int,input().split())) if k>(n+1)//2 : print(-1) else : for i in range(n): row=['.']*n if i % 2==0 and k>0 : row[i]='R' k-=1 print("".join(row)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (k->compareTo((n + 1) div 2)) > 0 then ( execute (-1)->display() ) else ( for i : Integer.subrange(0, n-1) do ( var row : Sequence := MatrixLib.elementwiseMult(Sequence{ '.' }, n) ; if i mod 2 = 0 & k > 0 then ( row[i+1] := 'R' ; k := k - 1 ) else skip ; execute (StringLib.sumStringsWithSeparator((row), ""))->display()) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) if k>(n+1)//2 : print(-1) continue r="R" c=0 for i in range(0,n,2): c+=1 if c>k : r="." print(i*"."+r+(n-i-1)*".") if n-i-1>0 : print(n*".") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (k->compareTo((n + 1) div 2)) > 0 then ( execute (-1)->display() ; continue ) else skip ; var r : String := "R" ; var c : int := 0 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( c := c + 1 ; if (c->compareTo(k)) > 0 then ( r := "." ) else skip ; execute (i * "." + r + (n - i - 1) * ".")->display() ; if n - i - 1 > 0 then ( execute (n * ".")->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for l in range(t): n,k=map(int,input().split()) a=[['.' for i in range(n)]for i in range(n)] i=0 j=0 while k!=0 and itoInteger() ; for l : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, n-1)->select(i | true)->collect(i | ('.')))) ; var i : int := 0 ; var j : int := 0 ; while k /= 0 & (i->compareTo(n)) < 0 & (j->compareTo(n)) < 0 do ( k := k - 1 ; a[i+1][j+1] := 'R' ; i := i + 2 ; j := j + 2) ; if k = 0 then ( for i : Integer.subrange(0, (a)->size()-1) do ( for j : Integer.subrange(0, (a)->size()-1) do ( execute (a[i+1][j+1])->display()) ; execute ((argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom ' ')))))))->display()) ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t=int(input()) ans=[] for _ in range(t): n,k=map(int,input().split()) if k>(n+1)//2 : ans0=["-1"] else : ans0=[["."]*n for _ in range(n)] for i in range(k): ans0[2*i][2*i]="R" for i in range(n): ans0[i]="".join(ans0[i]) ans.append("\n".join(ans0)) sys.stdout.write("\n".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (k->compareTo((n + 1) div 2)) > 0 then ( var ans0 : Sequence := Sequence{ "-1" } ) else ( ans0 := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ "." }, n))) ; for i : Integer.subrange(0, k-1) do ( ans0[2 * i+1][2 * i+1] := "R") ; for i : Integer.subrange(0, n-1) do ( ans0[i+1] := StringLib.sumStringsWithSeparator((ans0[i+1]), "")) ) ; execute ((StringLib.sumStringsWithSeparator((ans0), "\n")) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: n,k=map(int,s.split()); r=-1, if k>1 :*r,=('.'*n+'')*n ; r[: n*k+k<<1 : 2*n+4]='R'*k print(*r,sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ); var r : OclAny := (testlist_star_expr (test (logical_test (comparison (expr (atom - (number (integer 1))))))) ,) ; if (k->compareTo(n + 3 /(2->pow(1)))) < 0 then ( (testlist_star_expr (star_expr * (expr (atom (name r)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name r)))) ,)} := (StringLib.nCopies('.', n) + '') * n; r(subscript : (test (logical_test (comparison (expr (expr (expr (expr (atom (name n))) * (expr (atom (name k)))) + (expr (atom (name k)))) << (expr (atom (number (integer 1)))))))) (sliceop : (test (logical_test (comparison (expr (expr (expr (atom (number (integer 2)))) * (expr (atom (name n)))) + (expr (atom (number (integer 4)))))))))) := StringLib.nCopies('R', k) ) else skip ; execute ((argument * (test (logical_test (comparison (expr (atom (name r))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,A,B,C,D=map(lambda v : int(v),input().split()) S=list(input()) def check_movable(s): cnt=0 for v in s : if v=='#' : cnt+=1 elif v=='.' : cnt=0 if cnt>=2 : return False return True def check_throughable(s): cnt=0 for v in s : if v=='.' : cnt+=1 elif v=='#' : cnt=0 if cnt>=3 : return True return False if Ccollect( _x | (lambda v : OclAny in (("" + ((v)))->toInteger()))->apply(_x) ) ; var S : Sequence := ((OclFile["System.in"]).readLine())->characters() ; skip ; skip ; if (C->compareTo(B)) < 0 then ( if check_movable(S.subrange(B+1, D)) & check_movable(S.subrange(A+1, C)) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ) ) else (if (C->compareTo(D)) < 0 then ( if check_movable(S.subrange(B+1, D)) & check_movable(S.subrange(A+1, B)) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ) ) else ( if check_throughable(S.subrange(B - 2+1, D + 1)) & check_movable(S.subrange(A+1, C)) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ) ) ) ; operation check_movable(s : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; for v : s do ( if v = '#' then ( cnt := cnt + 1 ) else (if v = '.' then ( cnt := 0 ) else skip) ; if cnt >= 2 then ( return false ) else skip) ; return true; operation check_throughable(s : OclAny) : OclAny pre: true post: true activity: cnt := 0 ; for v : s do ( if v = '.' then ( cnt := cnt + 1 ) else (if v = '#' then ( cnt := 0 ) else skip) ; if cnt >= 3 then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools from collections import Counter from collections import defaultdict import bisect import math import heapq def main(): N,A,B,C,D=map(int,input().split()) S=input() ans='Yes' if '##' in S[A-1 : C]or '##' in S[B-1 : D]: ans='No' if Dcollect( _x | (OclType["int"])->apply(_x) ) ; var S : String := (OclFile["System.in"]).readLine() ; var ans : String := 'Yes' ; if (S.subrange(A - 1+1, C))->includes('##') or (S.subrange(B - 1+1, D))->includes('##') then ( ans := 'No' ) else skip ; if (D->compareTo(C)) < 0 then ( if (S.subrange(B - 2+1, D + 1))->excludes('...') then ( ans := 'No' ) else skip ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- line=input().split() object_=input() N=int(line[0]) A=int(line[1])-1 B=int(line[2])-1 C=int(line[3])-1 D=int(line[4])-1 placing_objects=[True if s=='#' else False for s in list(object_)] def main(): if(AB and C>D): for i in range(N-1): if placing_objects[i]and placing_objects[i+1]and i>A and iA and iB : if A>max(trans_index): print('No') return else : if B>max(trans_index)or Dfirst())))->toInteger() ; var A : double := ("" + ((line[1+1])))->toInteger() - 1 ; var B : double := ("" + ((line[2+1])))->toInteger() - 1 ; var C : double := ("" + ((line[3+1])))->toInteger() - 1 ; var D : double := ("" + ((line[4+1])))->toInteger() - 1 ; var placing_objects : Sequence := (object_)->characters()->select(s | true)->collect(s | (if s = '#' then true else false endif)) ; skip ; main(); operation main() pre: true post: true activity: if ((A->compareTo(B)) < 0 & (C->compareTo(D)) < 0) or ((A->compareTo(B)) > 0 & (C->compareTo(D)) > 0) then ( for i : Integer.subrange(0, N - 1-1) do ( if placing_objects[i+1] & placing_objects[i + 1+1] & (i->compareTo(A)) > 0 & (i->compareTo(Set{C, D}->max())) < 0 then ( execute ('No')->display() ; return ) else skip) ; execute ('Yes')->display() ; return ) else ( var possible_trans : boolean := false ; var trans_index : Sequence := Sequence{} ; for i : Integer.subrange(0, N - 1-1) do ( if placing_objects[i+1] & placing_objects[i + 1+1] & (i->compareTo(A)) > 0 & (i->compareTo(Set{C, D}->max())) < 0 then ( execute ('No')->display() ; return ) else skip ; if (i->compareTo(N - 2)) < 0 & (not(placing_objects[i+1])) & (not(placing_objects[i + 1+1])) & (not(placing_objects[i + 2+1])) then ( possible_trans := true ; execute ((i + 1) : trans_index) ) else skip) ; if not(possible_trans) then ( if (C->compareTo(D)) < 0 then ( if placing_objects[C - 1+1] or placing_objects[C + 1+1] then ( execute ('No')->display() ; return ) else skip ) else ( if placing_objects[D - 1+1] or placing_objects[D + 1+1] then ( execute ('No')->display() ; return ) else skip ) ) else ( if (A->compareTo(B)) > 0 then ( if (A->compareTo((trans_index)->max())) > 0 then ( execute ('No')->display() ; return ) else skip ) else ( if (B->compareTo((trans_index)->max())) > 0 or (D->compareTo((trans_index)->min())) < 0 then ( execute ('No')->display() ; return ) else skip ) ) ; execute ('Yes')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline a,b,c,d=map(int,input().split()) x=[a,b,c] x.sort() ans=0 for i in range(2): ans+=max(0,d-(x[i+1]-x[i])) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := Sequence{a}->union(Sequence{b}->union(Sequence{ c })) ; x := x->sort() ; var ans : int := 0 ; for i : Integer.subrange(0, 2-1) do ( ans := ans + Set{0, d - (x[i + 1+1] - x[i+1])}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def solve(): n=int(input()) arr=list(map(int,input().split())) V=0 for i in range(n): V ^=arr[i] if V>0 : curr=cnt=0 for i in range(n): curr ^=arr[i] if curr==V : cnt+=1 curr=0 return "YES" if cnt % 2 and cnt>2 else "NO" else : return "YES" for _ in range(int(input())): print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (solve())->display()); operation solve() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var V : int := 0 ; for i : Integer.subrange(0, n-1) do ( V := V xor arr[i+1]) ; if V > 0 then ( var curr : OclAny := 0; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( curr := curr xor arr[i+1] ; if curr = V then ( cnt := cnt + 1 ; curr := 0 ) else skip) ; return if cnt mod 2 & cnt > 2 then "YES" else "NO" endif ) else ( return "YES" ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,A,B,C,D=[int(i)for i in input().split()] S=input() def solve(): ac,bd=S[A-1 : C],S[B-1 : D] if Aselect(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var S : String := (OclFile["System.in"]).readLine() ; skip ; if solve() then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation solve() : OclAny pre: true post: true activity: var ac : OclAny := null; var bd : OclAny := null; Sequence{ac,bd} := Sequence{S.subrange(A - 1+1, C),S.subrange(B - 1+1, D)} ; if (A->compareTo(B)) < 0 & (B < D) & (D < C) then ( var bd : OclAny := S.subrange(B - 2+1, D + 1) ; return ((bd)->includes("...") & (ac)->excludes("##")) ) else ( return ((ac)->excludes("##") & (bd)->excludes("##")) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def passable(road): n=len(road) for i in range(n-1): block=road[i : i+2] if block=='##' : return False return True def safe_place(road): n=len(road) for i in range(n-2): block=road[i : i+3] if block=='...' : return i+1 return-1 def passEach(A,B,C,D,road): if passable(road[A : C+1])and passable(road[B : D+1]): return True else : return False def judge(A,B,C,D,S): if Ccollect( _x | (OclType["int"])->apply(_x) ) ; S := (OclFile["System.in"]).readLine() ; if judge(A - 1, B - 1, C - 1, D - 1, S) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); operation passable(road : OclAny) : OclAny pre: true post: true activity: var n : int := (road)->size() ; for i : Integer.subrange(0, n - 1-1) do ( var block : OclAny := road.subrange(i+1, i + 2) ; if block = '##' then ( return false ) else skip) ; return true; operation safe_place(road : OclAny) : OclAny pre: true post: true activity: n := (road)->size() ; for i : Integer.subrange(0, n - 2-1) do ( block := road.subrange(i+1, i + 3) ; if block = '...' then ( return i + 1 ) else skip) ; return -1; operation passEach(A : OclAny, B : OclAny, C : OclAny, D : OclAny, road : OclAny) : OclAny pre: true post: true activity: if passable(road.subrange(A+1, C + 1)) & passable(road.subrange(B+1, D + 1)) then ( return true ) else ( return false ); operation judge(A : OclAny, B : OclAny, C : OclAny, D : OclAny, S : OclAny) : OclAny pre: true post: true activity: if (C->compareTo(D)) < 0 then ( return passEach(A, B, C, D, S) ) else ( var S2 : OclAny := S.subrange(1,B) + '#' + S.subrange(B + 1+1) ; if passable(S2.subrange(A+1, C + 1)) & passable(S.subrange(B+1, D + 1)) then ( return true ) else skip ; var S3 : OclAny := S.subrange(1,D) + '#' + S.subrange(D + 1+1) ; if passable(S3.subrange(A+1, C + 1)) & passable(S.subrange(B+1, D + 1)) then ( return true ) else skip ; var safePlace : OclAny := safe_place(S.subrange(B+1, D + 1)) ; if safePlace /= -1 & passEach(A, B, C, safePlace + B, S) & passEach(A, safePlace + B, C, D, S) then ( return true ) else skip ) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=1000000007 ans=[1]*(100002) pref=[0]*100002 def preCompute(): for i in range(2,100000//2+1): for j in range(2*i,100000+1,i): ans[j]=(ans[j]*i)% mod for i in range(1,100002): pref[i]=pref[i-1]+ans[i] pref[i]%=mod def printSum(L,R): print(pref[R]-pref[L-1],end=" ") def printSumProper(arr,Q): preCompute() for i in range(Q): printSum(arr[i][0],arr[i][1]) if __name__=='__main__' : Q=2 arr=[[10,20],[12,16]] printSumProper(arr,Q) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : int := 1000000007 ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (100002)) ; var pref : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100002) ; skip ; skip ; skip ; if __name__ = '__main__' then ( Q := 2 ; arr := Sequence{Sequence{10}->union(Sequence{ 20 })}->union(Sequence{ Sequence{12}->union(Sequence{ 16 }) }) ; printSumProper(arr, Q) ) else skip; operation preCompute() pre: true post: true activity: for i : Integer.subrange(2, 100000 div 2 + 1-1) do ( for j : Integer.subrange(2 * i, 100000 + 1-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ( ans[j+1] := (ans[j+1] * i) mod mod)) ; for i : Integer.subrange(1, 100002-1) do ( pref[i+1] := pref[i - 1+1] + ans[i+1] ; pref[i+1] := pref[i+1] mod mod); operation printSum(L : OclAny, R : OclAny) pre: true post: true activity: execute (pref[R+1] - pref[L - 1+1])->display(); operation printSumProper(arr : OclAny, Q : OclAny) pre: true post: true activity: preCompute() ; for i : Integer.subrange(0, Q-1) do ( printSum(arr[i+1]->first(), arr[i+1][1+1])); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys ma=1<<53 while 1 : n=int(sys.stdin.readline()) if n==0 : break s=list(sys.stdin.readline()[:-1]) a=1 for i in range(52): a<<=1 a+=int(s[i]) ans=a e=0 while n : if a==0 : break k=math.ceil((ma-ans)/a) if n>=1 e+=1 a>>=1 n-=k e=list(bin(e)[2 :]) for i in range(12-len(e)): e.insert(0,0) ans=list(bin(ans)[3 :]) for i in range(52-len(ans)): ans.insert(0,0) for i in e+ans : print(i,end="") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var ma : int := 1 * (2->pow(53)) ; while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var s : Sequence := (sys.stdin.readLine()->front()) ; var a : int := 1 ; for i : Integer.subrange(0, 52-1) do ( a := a * (2->pow(1)) ; a := a + ("" + ((s[i+1])))->toInteger()) ; var ans : int := a ; var e : int := 0 ; while n do ( if a = 0 then ( break ) else skip ; var k : double := ((ma - ans) / a)->ceil() ; if (n->compareTo(k)) < 0 then ( ans := ans + a * n ; break ) else skip ; ans := ans + a * k ; ans := ans div (2->pow(1)) ; e := e + 1 ; a := a div (2->pow(1)) ; n := n - k) ; e := (bin(e).subrange(2+1)) ; for i : Integer.subrange(0, 12 - (e)->size()-1) do ( e := e.insertAt(0+1, 0)) ; ans := (bin(ans).subrange(3+1)) ; for i : Integer.subrange(0, 52 - (ans)->size()-1) do ( ans := ans.insertAt(0+1, 0)) ; for i : e + ans do ( execute (i)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans=[] while 1 : N=int(input()) if N==0 : break B=int("1"+input(),2) bd=1<<53 su=B ep=0 while B : k=(bd-su+B-1)//B if N>=1 su>>=1 ans.append(format(ep,'012b')+format(su ^(1<<52),'052b')) print(*ans,sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ans : Sequence := Sequence{} ; while 1 do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var B : int := ("" + (("1" + (OclFile["System.in"]).readLine(), 2)))->toInteger() ; var bd : int := 1 * (2->pow(53)) ; var su : int := B ; var ep : int := 0 ; while B do ( var k : int := (bd - su + B - 1) div B ; if (N->compareTo(k)) < 0 then ( su := su + N * B ; break ) else skip ; su := su + k * B ; N := N - k ; ep := ep + 1 ; B := B div (2->pow(1)) ; su := su div (2->pow(1))) ; execute (((ep + "") + (MathLib.bitwiseXor(su, (1 * (2->pow(52)))) + "")) : ans)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pairInSortedRotated(arr,n,x): for i in range(0,n-1): if(arr[i]>arr[i+1]): break ; l=(i+1)% n r=i while(l!=r): if(arr[l]+arr[r]==x): return True ; if(arr[l]+arr[r]union(Sequence{15}->union(Sequence{26}->union(Sequence{38}->union(Sequence{9}->union(Sequence{ 10 }))))) ; var sum : int := 16 ; n := (arr)->size() ; if (pairInSortedRotated(arr, n, sum)) then ( execute ("Array has two elements with sum 16")->display() ) else ( execute ("Array doesn't have two elements with sum 16 ")->display() ); operation pairInSortedRotated(arr : OclAny, n : OclAny, x : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n - 1-1) do ( if ((arr[i+1]->compareTo(arr[i + 1+1])) > 0) then ( break; ) else skip) ; var l : int := (i + 1) mod n ; var r : OclAny := i ; while (l /= r) do ( if (arr[l+1] + arr[r+1] = x) then ( return true; ) else skip ; if ((arr[l+1] + arr[r+1]->compareTo(x)) < 0) then ( l := (l + 1) mod n; ) else ( r := (n + r - 1) mod n; )) ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getMedian(arr1,arr2,n): if n==0 : return-1 elif n==1 : return(arr1[0]+arr2[1])/2 elif n==2 : return(max(arr1[0],arr2[0])+min(arr1[1],arr2[1]))/2 else : m1=median(arr1,n) m2=median(arr2,n) if m1>m2 : if n % 2==0 : return getMedian(arr1[: int(n/2)+1],arr2[int(n/2)-1 :],int(n/2)+1) else : return getMedian(arr1[: int(n/2)+1],arr2[int(n/2):],int(n/2)+1) else : if n % 2==0 : return getMedian(arr1[int(n/2-1):],arr2[: int(n/2+1)],int(n/2)+1) else : return getMedian(arr1[int(n/2):],arr2[0 : int(n/2)+1],int(n/2)+1) def median(arr,n): if n % 2==0 : return(arr[int(n/2)]+arr[int(n/2)-1])/2 else : return arr[int(n/2)] arr1=[1,2,3,6] arr2=[4,6,8,10] n=len(arr1) print(int(getMedian(arr1,arr2,n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr1 := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 6 }))) ; arr2 := Sequence{4}->union(Sequence{6}->union(Sequence{8}->union(Sequence{ 10 }))) ; n := (arr1)->size() ; execute (("" + ((getMedian(arr1, arr2, n))))->toInteger())->display(); operation getMedian(arr1 : OclAny, arr2 : OclAny, n : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( return -1 ) else (if n = 1 then ( return (arr1->first() + arr2[1+1]) / 2 ) else (if n = 2 then ( return (Set{arr1->first(), arr2->first()}->max() + Set{arr1[1+1], arr2[1+1]}->min()) / 2 ) else ( var m1 : OclAny := median(arr1, n) ; var m2 : OclAny := median(arr2, n) ; if (m1->compareTo(m2)) > 0 then ( if n mod 2 = 0 then ( return getMedian(arr1.subrange(1,("" + ((n / 2)))->toInteger() + 1), arr2.subrange(("" + ((n / 2)))->toInteger() - 1+1), ("" + ((n / 2)))->toInteger() + 1) ) else ( return getMedian(arr1.subrange(1,("" + ((n / 2)))->toInteger() + 1), arr2.subrange(("" + ((n / 2)))->toInteger()+1), ("" + ((n / 2)))->toInteger() + 1) ) ) else ( if n mod 2 = 0 then ( return getMedian(arr1.subrange(("" + ((n / 2 - 1)))->toInteger()+1), arr2.subrange(1,("" + ((n / 2 + 1)))->toInteger()), ("" + ((n / 2)))->toInteger() + 1) ) else ( return getMedian(arr1.subrange(("" + ((n / 2)))->toInteger()+1), arr2.subrange(0+1, ("" + ((n / 2)))->toInteger() + 1), ("" + ((n / 2)))->toInteger() + 1) ) ) ) ) ) ; operation median(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: if n mod 2 = 0 then ( return (arr[("" + ((n / 2)))->toInteger()+1] + arr[("" + ((n / 2)))->toInteger() - 1+1]) / 2 ) else ( return arr[("" + ((n / 2)))->toInteger()+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def max_profit(a,b,n,fee): i,j,profit=1,n-1,0 l,r,diff_day=0,0,1 b[0]=0 b[1]=diff_day for i in range(1,n): l=0 r=diff_day Sum=0 for j in range(n-1,i-1,-1): profit=(a[r]-a[l])-fee if(profit>0): Sum=Sum+profit l+=1 r+=1 if(b[0]union(Sequence{1}->union(Sequence{7}->union(Sequence{2}->union(Sequence{8}->union(Sequence{ 4 }))))) ; n := (arr)->size() ; b := Integer.subrange(0, 2-1)->select(i | true)->collect(i | (0)) ; var tranFee : int := 2 ; max_profit(arr, b, n, tranFee) ; execute (b->first())->display(); operation max_profit(a : OclAny, b : OclAny, n : OclAny, fee : OclAny) : OclAny pre: true post: true activity: var i : OclAny := null; var j : OclAny := null; var profit : OclAny := null; Sequence{i,j,profit} := Sequence{1,n - 1,0} ; var l : OclAny := null; var r : OclAny := null; var diff_day : OclAny := null; Sequence{l,r,diff_day} := Sequence{0,0,1} ; b->first() := 0 ; b[1+1] := diff_day ; for i : Integer.subrange(1, n-1) do ( var l : int := 0 ; var r : OclAny := diff_day ; var Sum : int := 0 ; for j : Integer.subrange(i - 1 + 1, n - 1)->reverse() do ( var profit : double := (a[r+1] - a[l+1]) - fee ; if (profit > 0) then ( Sum := Sum + profit ) else skip ; l := l + 1 ; r := r + 1) ; if ((b->first()->compareTo(Sum)) < 0) then ( b->first() := Sum ; b[1+1] := diff_day ) else skip) ; diff_day := diff_day + 1 ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(x): if a//x==0 or b//x==0 : return True return a//x+b//x1 : m=(l+r)//2 if check(m): r=m else : l=m print(l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : int := 1 ; var r : OclAny := Set{a, b}->max() + 1 ; while r - l > 1 do ( var m : int := (l + r) div 2 ; if check(m) then ( r := m ) else ( l := m )) ; execute (l)->display(); operation check(x : OclAny) : OclAny pre: true post: true activity: if a div x = 0 or b div x = 0 then ( return true ) else skip ; return (a div x + b div x->compareTo(n)) < 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=map(int,input().split()) ls,sum=[a,b,c],0 ls=sorted(ls) if ls[1]-ls[0]collect( _x | (OclType["int"])->apply(_x) ) ; var ls : OclAny := null; var sum : OclAny := null; Sequence{ls,sum} := Sequence{Sequence{a}->union(Sequence{b}->union(Sequence{ c })),0} ; var ls : Sequence := ls->sort() ; if (ls[1+1] - ls->first()->compareTo(d)) < 0 then ( sum := sum + (d - ls[1+1] + ls->first()) ) else skip ; if (ls[2+1] - ls[1+1]->compareTo(d)) < 0 then ( sum := sum + (d - ls[2+1] + ls[1+1]) ) else skip ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def good(m): return a//m+b//m>=n n,a,b=map(int,input().split()) l=1 r=min(a,b)+1 while r-l>1 : m=(l+r)//2 if good(m): l=m else : r=m print(l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : int := 1 ; var r : OclAny := Set{a, b}->min() + 1 ; while r - l > 1 do ( m := (l + r) div 2 ; if good(m) then ( l := m ) else ( r := m )) ; execute (l)->display(); operation good(m : OclAny) : OclAny pre: true post: true activity: return (a div m + b div m->compareTo(n)) >= 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isEven(arr,n,r): if(r % 2==0): if(arr[n-1]% 2==0): return True else : oddCount=0 for i in range(n): if(arr[i]% 2!=0): oddCount+=1 if(oddCount % 2==0): return True return False if __name__=='__main__' : arr=[1,0] n=len(arr) r=2 if(isEven(arr,n,r)): print("Even") else : print("Odd") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{ 0 }) ; n := (arr)->size() ; r := 2 ; if (isEven(arr, n, r)) then ( execute ("Even")->display() ) else ( execute ("Odd")->display() ) ) else skip; operation isEven(arr : OclAny, n : OclAny, r : OclAny) : OclAny pre: true post: true activity: if (r mod 2 = 0) then ( if (arr[n - 1+1] mod 2 = 0) then ( return true ) else skip ) else ( var oddCount : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] mod 2 /= 0) then ( oddCount := oddCount + 1 ) else skip) ; if (oddCount mod 2 = 0) then ( return true ) else skip ) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=list(map(int,input().split())) l=0 r=(a+b)//n+1 while r-l>1 : m=(r+l)//2 if a//m+b//m>=n and a//m>0 and b//m>0 : l=m else : r=m print(l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : int := 0 ; var r : int := (a + b) div n + 1 ; while r - l > 1 do ( var m : int := (r + l) div 2 ; if (a div m + b div m->compareTo(n)) >= 0 & a div m > 0 & b div m > 0 then ( l := m ) else ( r := m )) ; execute (l)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,a,b=map(int,input().split()) c=0 for i in range(1,min(n,min(a,b)+1)): c=max(min(a//i,b//(n-i)),c) c=max(min(a//(n-i),b//i),c) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : int := 0 ; for i : Integer.subrange(1, Set{n, Set{a, b}->min() + 1}->min()-1) do ( c := Set{Set{a div i, b div (n - i)}->min(), c}->max() ; c := Set{Set{a div (n - i), b div i}->min(), c}->max()) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=map(int,input().split()) r=0 for i in range(1,n): r=max(r,min(a//i,b//(n-i))) print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var r : int := 0 ; for i : Integer.subrange(1, n-1) do ( r := Set{r, Set{a div i, b div (n - i)}->min()}->max()) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y,z=[int(i)for i in input().strip().split()] coco=x//z+y//z left1=x % z left2=y % z if left1+left2>=z : print(coco+1,z-max(left1,left2)) else : print(coco,0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := input()->trim().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var coco : int := x div z + y div z ; var left1 : int := x mod z ; var left2 : int := y mod z ; if (left1 + left2->compareTo(z)) >= 0 then ( execute (coco + 1)->display() ) else ( execute (coco)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) ww,x,y=(a+b)//c,a % c,b % c print(ww,end=" ") if x==0 or y==0 or x+ycollect( _x | (OclType["int"])->apply(_x) ) ; var ww : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{ww,x,y} := Sequence{(a + b) div c,a mod c,b mod c} ; execute (ww)->display() ; if x = 0 or y = 0 or (x + y->compareTo(c)) < 0 then ( execute ("0")->display() ) else ( if (c - x->compareTo(c - y)) < 0 then ( execute (c - x)->display() ) else ( execute (c - y)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) ww,x,y=(a+b)//c,a % c,b % c print(ww,end=" ") if x==0 or y==0 or x+ycollect( _x | (OclType["int"])->apply(_x) ) ; var ww : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{ww,x,y} := Sequence{(a + b) div c,a mod c,b mod c} ; execute (ww)->display() ; if x = 0 or y = 0 or (x + y->compareTo(c)) < 0 then ( execute ("0")->display() ) else ( if (c - x->compareTo(c - y)) < 0 then ( execute (c - x)->display() ) else ( execute (c - y)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f,b,c=map(int,input().split()) ww,x,y=(f+b)//c,f % c,b % c print(ww,end=" ") if x==0 or y==0 or x+ycollect( _x | (OclType["int"])->apply(_x) ) ; var ww : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{ww,x,y} := Sequence{(f + b) div c,f mod c,b mod c} ; execute (ww)->display() ; if x = 0 or y = 0 or (x + y->compareTo(c)) < 0 then ( execute ("0")->display() ) else ( if (c - x->compareTo(c - y)) < 0 then ( execute (c - x)->display() ) else ( execute (c - y)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y,z=list(map(int,input().split())) c1=(x+y)//z c2=x//z+y//z if c1==c2 : print(c1,0) else : print(c1,z-max(x % z,y % z)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c1 : int := (x + y) div z ; var c2 : int := x div z + y div z ; if c1 = c2 then ( execute (c1)->display() ) else ( execute (c1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=str(input()) k=int(input()) if k>len(s): print('impossible') elif len(s)==len(set(s)): print(0) else : d=k-len(set(s)) if d<0 : print('0') else : print(d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (k->compareTo((s)->size())) > 0 then ( execute ('impossible')->display() ) else (if (s)->size() = (Set{}->union((s)))->size() then ( execute (0)->display() ) else ( var d : double := k - (Set{}->union((s)))->size() ; if d < 0 then ( execute ('0')->display() ) else ( execute (d)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- g,b,c,d=map(int,input().split()) ls,sum=[g,b,c],0 ls=sorted(ls) if ls[1]-ls[0]collect( _x | (OclType["int"])->apply(_x) ) ; var ls : OclAny := null; var sum : OclAny := null; Sequence{ls,sum} := Sequence{Sequence{g}->union(Sequence{b}->union(Sequence{ c })),0} ; var ls : Sequence := ls->sort() ; if (ls[1+1] - ls->first()->compareTo(d)) < 0 then ( sum := sum + (d - ls[1+1] + ls->first()) ) else skip ; if (ls[2+1] - ls[1+1]->compareTo(d)) < 0 then ( sum := sum + (d - ls[2+1] + ls[1+1]) ) else skip ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(A,B,C): i=len(A)-1 j=len(B)-1 k=len(C)-1 min_diff=abs(max(A[i],B[j],C[k])-min(A[i],B[j],C[k])) while i!=-1 and j!=-1 and k!=-1 : current_diff=abs(max(A[i],B[j],C[k])-min(A[i],B[j],C[k])) if current_diffunion(Sequence{8}->union(Sequence{10}->union(Sequence{ 15 }))) ; B := Sequence{6}->union(Sequence{9}->union(Sequence{15}->union(Sequence{78}->union(Sequence{ 89 })))) ; C := Sequence{2}->union(Sequence{3}->union(Sequence{6}->union(Sequence{6}->union(Sequence{8}->union(Sequence{8}->union(Sequence{ 10 })))))) ; execute (solve(A, B, C))->display(); operation solve(A : OclAny, B : OclAny, C : OclAny) : OclAny pre: true post: true activity: var i : double := (A)->size() - 1 ; var j : double := (B)->size() - 1 ; var k : double := (C)->size() - 1 ; var min_diff : double := (Set{A[i+1], B[j+1], C[k+1]}->max() - Set{A[i+1], B[j+1], C[k+1]}->min())->abs() ; while i /= -1 & j /= -1 & k /= -1 do ( var current_diff : double := (Set{A[i+1], B[j+1], C[k+1]}->max() - Set{A[i+1], B[j+1], C[k+1]}->min())->abs() ; if (current_diff->compareTo(min_diff)) < 0 then ( min_diff := current_diff ) else skip ; var max_term : OclAny := Set{A[i+1], B[j+1], C[k+1]}->max() ; if A[i+1] = max_term then ( i := i - 1 ) else (if B[j+1] = max_term then ( j := j - 1 ) else ( k := k - 1 ) ) ) ; return min_diff; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findLength(s,k): ans=10**9 l=0 r=0 cnt_zero=0 cnt_one=0 while(l=k and cnt_one>=1): ans=min(ans,r-l) l+=1 if(s[l-1]=='0'): cnt_zero-=1 else : cnt_one-=1 else : if(r==len(s)): break if(s[r]=='0'): cnt_zero+=1 else : cnt_one+=1 r+=1 if(ans==10**9): return-1 return ans s="100" k=2 print(findLength(s,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := "100" ; k := 2 ; execute (findLength(s, k))->display(); operation findLength(s : OclAny, k : OclAny) : OclAny pre: true post: true activity: var ans : double := (10)->pow(9) ; var l : int := 0 ; var r : int := 0 ; var cnt_zero : int := 0 ; var cnt_one : int := 0 ; while ((l->compareTo((s)->size())) < 0 & (r->compareTo((s)->size())) <= 0) do ( if ((cnt_zero->compareTo(k)) >= 0 & cnt_one >= 1) then ( ans := Set{ans, r - l}->min() ; l := l + 1 ; if (s[l - 1+1] = '0') then ( cnt_zero := cnt_zero - 1 ) else ( cnt_one := cnt_one - 1 ) ) else ( if (r = (s)->size()) then ( break ) else skip ; if (s[r+1] = '0') then ( cnt_zero := cnt_zero + 1 ) else ( cnt_one := cnt_one + 1 ) ; r := r + 1 )) ; if (ans = (10)->pow(9)) then ( return -1 ) else skip ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,A=[int(_)for _ in input().split()] MAX_I=5000 memo=[[0]*MAX_I for _ in range(N+2)] def cnv(v): return v-A+(MAX_I//2) X=[int(_)for _ in input().split()] for i in range(N): offset=X[i]-A mm=memo[i] for j in range(MAX_I): if mm[j]>0 : memo[i+1][j+offset]+=mm[j] memo[i+1][j]+=mm[j] memo[i+1][cnv(X[i])]+=1 print(memo[N][MAX_I//2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; Sequence{N,A} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var MAX_I : int := 5000 ; var memo : Sequence := Integer.subrange(0, N + 2-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, MAX_I))) ; skip ; var X : Sequence := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; for i : Integer.subrange(0, N-1) do ( var offset : double := X[i+1] - A ; var mm : OclAny := memo[i+1] ; for j : Integer.subrange(0, MAX_I-1) do ( if mm[j+1] > 0 then ( memo[i + 1+1][j + offset+1] := memo[i + 1+1][j + offset+1] + mm[j+1] ) else skip ; memo[i + 1+1][j+1] := memo[i + 1+1][j+1] + mm[j+1]) ; memo[i + 1+1][cnv(X[i+1])+1] := memo[i + 1+1][cnv(X[i+1])+1] + 1) ; execute (memo[N+1][MAX_I div 2+1])->display(); operation cnv(v : OclAny) : OclAny pre: true post: true activity: return v - A + (MAX_I div 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib,itertools def compute(): ans=next(itertools.islice(filter(eulerlib.is_prime,itertools.count(2)),10000,None)) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : OclAny := (itertools.islice((itertools->count(2))->select( _x | (eulerlib.is_prime)->apply(_x) = true ), 10000, null)).next() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minReplace(a : list,n)->int : te=dict() to=dict() for i in range(n): if i % 2==0 : if a[i]not in te : te[a[i]]=1 else : te[a[i]]+=1 else : if a[i]not in to : to[a[i]]=1 else : to[a[i]]+=1 me=-1 mo=-1 ce=-1 co=-1 for it in te : if te[it]>ce : ce=te[it] me=it for it in to : if to[it]>co : co=to[it] mo=it res=0 for i in range(n): if i % 2==0 : if a[i]!=me : res+=1 else : if a[i]!=mo : res+=1 return res if __name__=="__main__" : n=4 a=[3,1,3,2] print(minReplace(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 4 ; var a : Sequence := Sequence{3}->union(Sequence{1}->union(Sequence{3}->union(Sequence{ 2 }))) ; execute (minReplace(a, n))->display() ) else skip; operation minReplace(a : Sequence(OclAny), n : OclAny) : int pre: true post: true activity: var te : Map := (arguments ( )) ; var to : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( if i mod 2 = 0 then ( if (te)->excludes(a[i+1]) then ( te[a[i+1]+1] := 1 ) else ( te[a[i+1]+1] := te[a[i+1]+1] + 1 ) ) else ( if (to)->excludes(a[i+1]) then ( to[a[i+1]+1] := 1 ) else ( to[a[i+1]+1] := to[a[i+1]+1] + 1 ) )) ; var me : int := -1 ; var mo : int := -1 ; var ce : int := -1 ; var co : int := -1 ; for it : te->keys() do ( if (te[it+1]->compareTo(ce)) > 0 then ( ce := te[it+1] ; me := it ) else skip) ; for it : to->keys() do ( if (to[it+1]->compareTo(co)) > 0 then ( co := to[it+1] ; mo := it ) else skip) ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( if i mod 2 = 0 then ( if a[i+1] /= me then ( res := res + 1 ) else skip ) else ( if a[i+1] /= mo then ( res := res + 1 ) else skip )) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairs(A,B): cnt=0 for i in range(0,A+1): for j in range(i,A+1): AND=i & j OR=i | j if(OR==A and AND==B): cnt+=1 return cnt if __name__=='__main__' : A=3 B=0 print(countPairs(A,B)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( A := 3 ; B := 0 ; execute (countPairs(A, B))->display() ) else skip; operation countPairs(A : OclAny, B : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; for i : Integer.subrange(0, A + 1-1) do ( for j : Integer.subrange(i, A + 1-1) do ( var AND : int := MathLib.bitwiseAnd(i, j) ; var OR : int := MathLib.bitwiseOr(i, j) ; if (OR = A & AND = B) then ( cnt := cnt + 1 ) else skip)) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for pratyush in range(int(input())): n,k=map(int,input().split()) l=list(map(int,input().split())) x=[] for i in range(n): x.append([l[i],i]) y=x.copy() y.sort() p=1 for i in range(n-1): if y[i][1]+1!=y[i+1][1]: p+=1 if p<=k : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for pratyush : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((Sequence{l[i+1]}->union(Sequence{ i })) : x)) ; var y : OclAny := x->copy() ; y := y->sort() ; var p : int := 1 ; for i : Integer.subrange(0, n - 1-1) do ( if y[i+1][1+1] + 1 /= y[i + 1+1][1+1] then ( p := p + 1 ) else skip) ; if (p->compareTo(k)) <= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter,deque import math from random import randint from bisect import bisect import sys import re import copy MOD=1000000007 MAX=sys.maxsize MIN=-sys.maxsize class get : def int(): return list(map(int,input().split())) def str(): return input().split() def float(): return list(map(float,input().split())) def map(): return map(int,input().split()) def sqrt(x): return int(math.sqrt(x))+1 def gcd(*args): result=args[0] for item in args : result=math.gcd(result,item) return result def LCM(a,b): return(a*b)//(math.gcd(a,b)) def solve(): n,k=get.map() arr=get.int() mylist=[] res=n for a,b in enumerate(arr): mylist.append([b,a]) mylist.sort() for i in range(n-1): if mylist[i+1][1]-mylist[i][1]==1 : res-=1 if res<=k : print("YES") else : print("NO") for _ in range(int(input())): solve() ------------------------------------------------------------ OCL File: --------- class get { static operation newget() : get pre: true post: get->exists( _x | result = _x ); static operation OclType["int"]() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); static operation OclType["String"]() : OclAny pre: true post: true activity: return input().split(); static operation OclType["double"]() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["double"])->apply(_x) )); static operation map() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var MOD : int := 1000000007 ; var MAX : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; var MIN : (trailer . (name maxsize)) := -(trailer . (name maxsize)) ; skip ; skip ; skip ; skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve()); operation sqrt(x : OclAny) : OclAny pre: true post: true activity: return ("" + (((x)->sqrt())))->toInteger() + 1; operation gcd(args : OclAny : Sequence(OclAny)) : OclAny pre: true post: true activity: (args * (named_parameter (name args))) var result : OclAny := args->first() ; for item : args do ( result := (result)->gcd(item)) ; return result; operation LCM(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a * b) div ((a)->gcd(b)); operation solve() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (get.newget()).initialise.map() ; var arr : get := (get.newget()).initialise.OclType["int"]() ; var mylist : Sequence := Sequence{} ; var res : OclAny := n ; for _tuple : Integer.subrange(1, (arr)->size())->collect( _indx | Sequence{_indx-1, (arr)->at(_indx)} ) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); execute ((Sequence{b}->union(Sequence{ a })) : mylist)) ; mylist := mylist->sort() ; for i : Integer.subrange(0, n - 1-1) do ( if mylist[i + 1+1][1+1] - mylist[i+1][1+1] = 1 then ( res := res - 1 ) else skip) ; if (res->compareTo(k)) <= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for j in range(t): n,k=map(int,input().split()) a=list(map(int,input().split())) ans=1 l=[] for j in range(n): l.append([a[j],j]) l.sort() for p in range(1,n): if l[p][1]!=l[p-1][1]+1 : ans+=1 if ans>k : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 1 ; var l : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( execute ((Sequence{a[j+1]}->union(Sequence{ j })) : l)) ; l := l->sort() ; for p : Integer.subrange(1, n-1) do ( if l[p+1][1+1] /= l[p - 1+1][1+1] + 1 then ( ans := ans + 1 ) else skip) ; if (ans->compareTo(k)) > 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()); a=list(map(int,input().split())); b=sorted([a[i],i]for i in range(n)); print('Yes' if len([i for i in range(1,n)if b[i][1]!=b[i-1][1]+1])toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); var b : Sequence := (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))) , (test (logical_test (comparison (expr (atom (name i))))))) ]))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))->sort(); execute (if ((Integer.subrange(1, n-1)->select(i | b[i+1][1+1] /= b[i - 1+1][1+1] + 1)->collect(i | (i)))->size()->compareTo(k)) < 0 then 'Yes' else 'No' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dp=[[[-1 for i in range(5)]for i in range(501)]for i in range(501)] def countWaysUtil(n,parts,nextPart): if(parts==0 and n==0): return 1 if(n<=0 or parts<=0): return 0 if(dp[n][nextPart][parts]!=-1): return dp[n][nextPart][parts] ans=0 for i in range(nextPart,n+1): ans+=countWaysUtil(n-i,parts-1,i) dp[n][nextPart][parts]=ans return(ans) def countWays(n): return countWaysUtil(n,4,1) n=8 print(countWays(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dp : Sequence := Integer.subrange(0, 501-1)->select(i | true)->collect(i | (Integer.subrange(0, 501-1)->select(i | true)->collect(i | (Integer.subrange(0, 5-1)->select(i | true)->collect(i | (-1)))))) ; skip ; skip ; n := 8 ; execute (countWays(n))->display(); operation countWaysUtil(n : OclAny, parts : OclAny, nextPart : OclAny) : OclAny pre: true post: true activity: if (parts = 0 & n = 0) then ( return 1 ) else skip ; if (n <= 0 or parts <= 0) then ( return 0 ) else skip ; if (dp[n+1][nextPart+1][parts+1] /= -1) then ( return dp[n+1][nextPart+1][parts+1] ) else skip ; var ans : int := 0 ; for i : Integer.subrange(nextPart, n + 1-1) do ( ans := ans + countWaysUtil(n - i, parts - 1, i)) ; dp[n+1][nextPart+1][parts+1] := ans ; return (ans); operation countWays(n : OclAny) : OclAny pre: true post: true activity: return countWaysUtil(n, 4, 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) arr=list(map(int,input().split()))[: n] dict={} std=sorted(arr) for i in range(n): dict[std[i]]=i c=0 for i in range(n-1): if arr[i]>arr[i+1]: c+=1 else : a=dict[arr[i]] b=dict[arr[i+1]] if b-a!=1 : c+=1 c+=1 if c<=k : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ; var OclType["Map"] : OclAny := Set{} ; var std : Sequence := arr->sort() ; for i : Integer.subrange(0, n-1) do ( (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name std)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ]) := i) ; var c : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if (arr[i+1]->compareTo(arr[i + 1+1])) > 0 then ( c := c + 1 ) else ( var a : Map := (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ]) ; var b : Map := (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])))))))) ]) ; if b - a /= 1 then ( c := c + 1 ) else skip )) ; c := c + 1 ; if (c->compareTo(k)) <= 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bubble_count(arr,start,end): count=0 ; for i in range(start,end): for j in range(i+1,end): if(arr[i]>arr[j]): count+=1 ; return count ; def inversion_count(n,k,a): count=0 ; for start in range(0,n-k+1): end=start+k ; count+=bubble_count(a,start,end); return count ; if __name__=='__main__' : n=10 ; arr=[15,51,44,44,76,50,29,88,48,50]; k=5 ; result=inversion_count(n,k,arr); print(result); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( n := 10; ; arr := Sequence{15}->union(Sequence{51}->union(Sequence{44}->union(Sequence{44}->union(Sequence{76}->union(Sequence{50}->union(Sequence{29}->union(Sequence{88}->union(Sequence{48}->union(Sequence{ 50 }))))))))); ; k := 5; ; var result : OclAny := inversion_count(n, k, arr); ; execute (result)->display(); ) else skip; operation bubble_count(arr : OclAny, start : OclAny, end : OclAny) pre: true post: true activity: var count : int := 0; ; for i : Integer.subrange(start, end-1) do ( for j : Integer.subrange(i + 1, end-1) do ( if ((arr[i+1]->compareTo(arr[j+1])) > 0) then ( count := count + 1; ) else skip)) ; return count;; operation inversion_count(n : OclAny, k : OclAny, a : OclAny) pre: true post: true activity: count := 0; ; for start : Integer.subrange(0, n - k + 1-1) do ( end := start + k; ; count := count + bubble_count(a, start, end);) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def solve(M,N,s): ans=((math.ceil(M/s))*(math.ceil(N/s))); return ans if __name__=="__main__" : N=12 M=13 s=4 print(solve(M,N,s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( N := 12 ; M := 13 ; s := 4 ; execute (solve(M, N, s))->display() ) else skip; operation solve(M : OclAny, N : OclAny, s : OclAny) : OclAny pre: true post: true activity: var ans : double := (((M / s)->ceil()) * ((N / s)->ceil())); ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solution(A): m=max(A) if m<1 : return 1 if len(A)==1 : return 2 if A[0]==1 else 1 l=[0]*m for i in range(len(A)): if A[i]>0 : if l[A[i]-1]!=1 : l[A[i]-1]=1 for i in range(len(l)): if l[i]==0 : return i+1 return i+2 A=[0,10,2,-10,-20] print(solution(A)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; A := Sequence{0}->union(Sequence{10}->union(Sequence{2}->union(Sequence{-10}->union(Sequence{ -20 })))) ; execute (solution(A))->display(); operation solution(A : OclAny) : OclAny pre: true post: true activity: var m : OclAny := (A)->max() ; if m < 1 then ( return 1 ) else skip ; if (A)->size() = 1 then ( return if A->first() = 1 then 2 else 1 endif ) else skip ; var l : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; for i : Integer.subrange(0, (A)->size()-1) do ( if A[i+1] > 0 then ( if l[A[i+1] - 1+1] /= 1 then ( l[A[i+1] - 1+1] := 1 ) else skip ) else skip) ; for i : Integer.subrange(0, (l)->size()-1) do ( if l[i+1] = 0 then ( return i + 1 ) else skip) ; return i + 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def findTriplets(x): fact=[]; factors=set(); for i in range(2,int(sqrt(x))): if(x % i==0): fact.append(i); if(x/i!=i): fact.append(x//i); factors.add(i); factors.add(x//i); found=False ; k=len(fact); for i in range(k): a=fact[i]; for j in range(k): b=fact[j]; if((a!=b)and(x %(a*b)==0)and(x/(a*b)!=a)and(x/(a*b)!=b)and(x/(a*b)!=1)): print(a,b,x//(a*b)); found=True ; break ; if(found): break ; if(not found): print("-1"); if __name__=="__main__" : x=105 ; findTriplets(x); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( x := 105; ; findTriplets(x); ) else skip; operation findTriplets(x : OclAny) pre: true post: true activity: var fact : Sequence := Sequence{}; ; var factors : Set := Set{}->union(()); ; for i : Integer.subrange(2, ("" + ((sqrt(x))))->toInteger()-1) do ( if (x mod i = 0) then ( execute ((i) : fact); ; if (x / i /= i) then ( execute ((x div i) : fact); ) else skip ; execute ((i) : factors); ; execute ((x div i) : factors); ) else skip) ; var found : boolean := false; ; var k : int := (fact)->size(); ; for i : Integer.subrange(0, k-1) do ( var a : OclAny := fact[i+1]; ; for j : Integer.subrange(0, k-1) do ( var b : OclAny := fact[j+1]; ; if ((a /= b) & (x mod (a * b) = 0) & (x / (a * b) /= a) & (x / (a * b) /= b) & (x / (a * b) /= 1)) then ( execute (a)->display(); ; found := true; ; break; ) else skip) ; if (found) then ( break; ) else skip) ; if (not(found)) then ( execute ("-1")->display(); ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math set=[] prime=[] def isPrime(x): sqroot=int(math.sqrt(x)) flag=True if(x==1): return False for i in range(2,sqroot+1): if(x % i==0): return False return True def display(): global set,prime length=len(set) for i in range(0,length): print(set[i],end=" ") print() def primeSum(total,N,S,index): global set,prime if(total==S and len(set)==N): display() return if(total>S or index==len(prime)): return set.append(prime[index]) primeSum(total+prime[index],N,S,index+1) set.pop() primeSum(total,N,S,index+1) def allPrime(N,S,P): global set,prime for i in range(P+1,S+1): if(isPrime(i)): prime.append(i) if(len(prime)sqrt())))->toInteger() ; var flag : boolean := true ; if (x = 1) then ( return false ) else skip ; for i : Integer.subrange(2, sqroot + 1-1) do ( if (x mod i = 0) then ( return false ) else skip) ; return true; operation display() pre: true post: true activity: skip; skip ; var length : int := (OclType["Set"])->size() ; for i : Integer.subrange(0, length-1) do ( execute (Set{}->union([i+1]))->display()) ; execute (->display(); operation primeSum(total : OclAny, N : OclAny, S : OclAny, index : OclAny) pre: true post: true activity: skip; skip ; if (total = S & (OclType["Set"])->size() = N) then ( display() ; return ) else skip ; if ((total->compareTo(S)) > 0 or index = (prime)->size()) then ( return ) else skip ; execute ((prime[index+1]) : OclType["Set"]) ; primeSum(total + prime[index+1], N, S, index + 1) ; OclType["Set"] := OclType["Set"]->front() ; primeSum(total, N, S, index + 1); operation allPrime(N : OclAny, S : OclAny, P : OclAny) pre: true post: true activity: skip; skip ; for i : Integer.subrange(P + 1, S + 1-1) do ( if (isPrime(i)) then ( execute ((i) : prime) ) else skip) ; if (((prime)->size()->compareTo(N)) < 0) then ( return ) else skip ; primeSum(0, N, S, 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_SIZE=100005 fib=[0]*(MAX_SIZE+1) def fibonacci(): fib[0]=0 fib[1]=1 for i in range(2,MAX_SIZE+1): fib[i]=fib[i-1]+fib[i-2] def printLevel(level): left_index=pow(2,level-1) right_index=pow(2,level)-1 for i in range(left_index,right_index+1): print(fib[i-1],end=" ") print() fibonacci() K=4 printLevel(K) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_SIZE : int := 100005 ; var fib : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX_SIZE + 1)) ; skip ; skip ; fibonacci() ; var K : int := 4 ; printLevel(K); operation fibonacci() pre: true post: true activity: fib->first() := 0 ; fib[1+1] := 1 ; for i : Integer.subrange(2, MAX_SIZE + 1-1) do ( fib[i+1] := fib[i - 1+1] + fib[i - 2+1]); operation printLevel(level : OclAny) pre: true post: true activity: var left_index : double := (2)->pow(level - 1) ; var right_index : double := (2)->pow(level) - 1 ; for i : Integer.subrange(left_index, right_index + 1-1) do ( execute (fib[i - 1+1])->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def decideWinner(a,n): count0=0 count1=0 count2=0 count3=0 for i in range(n): if(a[i]% 4==0): count0+=1 elif(a[i]% 4==1): count1+=1 elif(a[i]% 4==2): count2+=1 elif(a[i]% 4==3): count3+=1 if(count0 % 2==0 and count1 % 2==0 and count2 % 2==0 and count3==0): return 1 else : return 2 a=[4,8,5,9] n=len(a) if(decideWinner(a,n)==1): print("X wins") else : print("Y wins") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{4}->union(Sequence{8}->union(Sequence{5}->union(Sequence{ 9 }))) ; n := (a)->size() ; if (decideWinner(a, n) = 1) then ( execute ("X wins")->display() ) else ( execute ("Y wins")->display() ); operation decideWinner(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count0 : int := 0 ; var count1 : int := 0 ; var count2 : int := 0 ; var count3 : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] mod 4 = 0) then ( count0 := count0 + 1 ) else (if (a[i+1] mod 4 = 1) then ( count1 := count1 + 1 ) else (if (a[i+1] mod 4 = 2) then ( count2 := count2 + 1 ) else (if (a[i+1] mod 4 = 3) then ( count3 := count3 + 1 ) else skip ) ) ) ) ; if (count0 mod 2 = 0 & count1 mod 2 = 0 & count2 mod 2 = 0 & count3 = 0) then ( return 1 ) else ( return 2 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def MinOperation(a,n,k): result=0 for i in range(n): if(a[i]!=1 and a[i]>k): result=(result+min(a[i]% k,k-a[i]% k)) else : result=result+k-a[i] return result if __name__=="__main__" : arr=[4,5,6] n=len(arr) k=5 print(MinOperation(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var arr : Sequence := Sequence{4}->union(Sequence{5}->union(Sequence{ 6 })) ; n := (arr)->size() ; k := 5 ; execute (MinOperation(arr, n, k))->display() ) else skip; operation MinOperation(a : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] /= 1 & (a[i+1]->compareTo(k)) > 0) then ( result := (result + Set{a[i+1] mod k, k - a[i+1] mod k}->min()) ) else ( result := result + k - a[i+1] )) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def subarraySum(self,nums,k): sum_map={} sum_map[0]=1 count=curr_sum=0 for num in nums : curr_sum+=num count+=sum_map.get(curr_sum-k,0) sum_map[curr_sum]=sum_map.get(curr_sum,0)+1 return count ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation subarraySum(nums : OclAny,k : OclAny) : OclAny pre: true post: true activity: var sum_map : OclAny := Set{} ; sum_map->first() := 1 ; var count : OclAny := 0; var curr_sum : int := 0 ; for num : nums do ( curr_sum := curr_sum + num ; count := count + sum_map.get(curr_sum - k, 0) ; sum_map[curr_sum+1] := sum_map.get(curr_sum, 0) + 1) ; return count; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find_k(a,b): if((a+b)% 2==0): return((a+b)//2); return-1 ; if __name__=="__main__" : a=2 ; b=16 ; print(find_k(a,b)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := 2; b := 16; ; execute (find_k(a, b))->display(); ) else skip; operation find_k(a : OclAny, b : OclAny) pre: true post: true activity: if ((a + b) mod 2 = 0) then ( return ((a + b) div 2); ) else skip ; return -1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) a=list(map(int,input().split())) if n==1 : ans="sjfnb" if a[0]% 2 else "cslnb" else : cnt=defaultdict(lambda : 0) u=[] for i in a : if cnt[i]: u.append(i) cnt[i]+=1 if len(u)>1 : ans="cslnb" elif len(u)==1 and(not u[0]or u[0]-1 in set(a)): ans="cslnb" else : s=sum(a)-(n*(n-1)//2) ans="sjfnb" if s % 2 else "cslnb" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = 1 then ( var ans : String := if a->first() mod 2 then "sjfnb" else "cslnb" endif ) else ( var cnt : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; var u : Sequence := Sequence{} ; for i : a do ( if cnt[i+1] then ( execute ((i) : u) ) else skip ; cnt[i+1] := cnt[i+1] + 1) ; if (u)->size() > 1 then ( ans := "cslnb" ) else (if (u)->size() = 1 & (not(u->first()) or (Set{}->union((a)))->includes(u->first() - 1)) then ( ans := "cslnb" ) else ( var s : double := (a)->sum() - (n * (n - 1) div 2) ; ans := if s mod 2 then "sjfnb" else "cslnb" endif ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[-1]+list(map(int,input().split())) s=set() s.add(-1) a.sort() count,add=0,0 flag=0 for i in range(1,n+1): if a[i]in s and a[i]-1 in s : flag=1 break if a[i]in s : add+=1 if(add==2): flag=1 break s.add(a[i]) count+=a[i]-(i-1) if(flag==0 and count % 2==1): print("sjfnb") else : print("cslnb") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{ -1 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var s : Set := Set{}->union(()) ; execute ((-1) : s) ; a := a->sort() ; var count : OclAny := null; var add : OclAny := null; Sequence{count,add} := Sequence{0,0} ; var flag : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( if (s)->includes(a[i+1]) & (s)->includes(a[i+1] - 1) then ( flag := 1 ; break ) else skip ; if (s)->includes(a[i+1]) then ( add := add + 1 ) else skip ; if (add = 2) then ( flag := 1 ; break ) else skip ; execute ((a[i+1]) : s) ; count := count + a[i+1] - (i - 1)) ; if (flag = 0 & count mod 2 = 1) then ( execute ("sjfnb")->display() ) else ( execute ("cslnb")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import collections import copy import enum import functools import heapq import itertools import math import random import re import sys import time import string from typing import List sys.setrecursionlimit(10001) n=int(input()) arr=list(map(int,input().split())) cs=collections.Counter(arr) f=1 c=0 for k,v in cs.items(): if v>2 or v>1 and cs[k-1]>0 : f=0 break ; if v>1 : c+=1 if cs[0]>1 or c>1 : f=0 if f==0 : print("cslnb") exit() sa=sum(arr) sb=n*(n-1)//2 if satoInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cs : OclAny := .Counter(arr) ; var f : int := 1 ; var c : int := 0 ; for _tuple : cs->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if v > 2 or v > 1 & cs[k - 1+1] > 0 then ( f := 0 ; break; ) else skip ; if v > 1 then ( c := c + 1 ) else skip) ; if cs->first() > 1 or c > 1 then ( f := 0 ) else skip ; if f = 0 then ( execute ("cslnb")->display() ; exit() ) else skip ; var sa : OclAny := (arr)->sum() ; var sb : int := n * (n - 1) div 2 ; if (sa->compareTo(sb)) < 0 then ( execute ("cslnb")->display() ) else (if (sa - sb) mod 2 = 0 then ( execute ("cslnb")->display() ) else ( execute ("sjfnb")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- pots=[None]*1000001 pots[1]=2 def pow_fast(num,e): if pots[e]is not None : return pots[e] elif e % 2==0 : res=pow_fast(num,e//2)%(10**9+7) pots[e]=(res*res)%(10**9+7) return pots[e] else : res=(pow_fast(num,e-1)*num)%(10**9+7) pots[e]=res return pots[e] entrada=input() steps=0 seq_a=0 ult='b' for char in entrada : if char=='b' and ult=='a' : steps+=pow_fast(2,seq_a)-1 elif char=='a' : seq_a+=1 ult='a' else : ult='b' print(steps %(10**9+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var pots : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, 1000001) ; pots[1+1] := 2 ; skip ; var entrada : String := (OclFile["System.in"]).readLine() ; var steps : int := 0 ; var seq_a : int := 0 ; var ult : String := 'b' ; for char : entrada->characters() do ( if char = 'b' & ult = 'a' then ( steps := steps + pow_fast(2, seq_a) - 1 ) else (if char = 'a' then ( seq_a := seq_a + 1 ; ult := 'a' ) else ( ult := 'b' ) ) ) ; execute (steps mod ((10)->pow(9) + 7))->display(); operation pow_fast(num : OclAny, e : OclAny) : OclAny pre: true post: true activity: if not(pots[e+1] <>= null) then ( return pots[e+1] ) else (if e mod 2 = 0 then ( var res : int := pow_fast(num, e div 2) mod ((10)->pow(9) + 7) ; pots[e+1] := (res * res) mod ((10)->pow(9) + 7) ; return pots[e+1] ) else ( res := (pow_fast(num, e - 1) * num) mod ((10)->pow(9) + 7) ; pots[e+1] := res ; return pots[e+1] ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools import math from math import gcd as gcd import sys import queue import itertools from heapq import heappop,heappush import random def solve(): res=0 mod=10**9+7 mn=0 was_b=False s=str(input()) for i in range(len(s)-1,-1,-1): if s[i]=="a" : if was_b : res=(res+mn)% mod mn=(mn*2)% mod else : mn+=1 was_b=True print(res) if __name__=='__main__' : multi_test=0 if multi_test : t=int(sys.stdin.readline()) for _ in range(t): solve() else : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var multi_test : int := 0 ; if multi_test then ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( solve()) ) else ( solve() ) ) else skip; operation solve() pre: true post: true activity: var res : int := 0 ; var mod : double := (10)->pow(9) + 7 ; var mn : int := 0 ; var was_b : boolean := false ; var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; for i : Integer.subrange(-1 + 1, (s)->size() - 1)->reverse() do ( if s[i+1] = "a" then ( if was_b then ( res := (res + mn) mod mod ; mn := (mn * 2) mod mod ) else skip ) else ( mn := mn + 1 ; was_b := true )) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def eggDrop(n,k): if(k==1 or k==0): return k if(n==1): return k min=sys.maxsize for x in range(1,k+1): res=max(eggDrop(n-1,x-1),eggDrop(n,k-x)) if(resdisplay() ) else skip; operation eggDrop(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (k = 1 or k = 0) then ( return k ) else skip ; if (n = 1) then ( return k ) else skip ; var min : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; for x : Integer.subrange(1, k + 1-1) do ( var res : OclAny := Set{eggDrop(n - 1, x - 1), eggDrop(n, k - x)}->max() ; if ((res->compareTo(min)) < 0) then ( min := res ) else skip) ; return min + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c,b,m=0,0,int(1e9+7) for i in input()[: :-1]: if i=='a' : c=(c+b)% m ; b=(b*2)% m else : b+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : OclAny := null; var b : OclAny := null; var m : OclAny := null; Sequence{c,b,m} := Sequence{0,0,("" + ((("1e9")->toReal() + 7)))->toInteger()} ; for i : input()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if i = 'a' then ( var c : int := (c + b) mod m; var b : int := (b * 2) mod m ) else ( b := b + 1 )) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- pots=[None]*1000001 pots[1]=2 def pow_fast(num,e): if pots[e]is not None : return pots[e] elif(e & 1)==0 : res=pow_fast(num,e//2)%(10**9+7) pots[e]=(res*res)%(10**9+7) return pots[e] else : res=(pow_fast(num,e-1)*num)%(10**9+7) pots[e]=res return pots[e] entrada=input() steps=0 seq_a=0 ult='b' for char in entrada : if char=='b' and ult=='a' : steps=(steps+pow_fast(2,seq_a)-1)%(10**9+7) elif char=='a' : seq_a+=1 ult='a' else : ult='b' print(steps %(10**9+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var pots : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, 1000001) ; pots[1+1] := 2 ; skip ; var entrada : String := (OclFile["System.in"]).readLine() ; var steps : int := 0 ; var seq_a : int := 0 ; var ult : String := 'b' ; for char : entrada->characters() do ( if char = 'b' & ult = 'a' then ( steps := (steps + pow_fast(2, seq_a) - 1) mod ((10)->pow(9) + 7) ) else (if char = 'a' then ( seq_a := seq_a + 1 ; ult := 'a' ) else ( ult := 'b' ) ) ) ; execute (steps mod ((10)->pow(9) + 7))->display(); operation pow_fast(num : OclAny, e : OclAny) : OclAny pre: true post: true activity: if not(pots[e+1] <>= null) then ( return pots[e+1] ) else (if (MathLib.bitwiseAnd(e, 1)) = 0 then ( var res : int := pow_fast(num, e div 2) mod ((10)->pow(9) + 7) ; pots[e+1] := (res * res) mod ((10)->pow(9) + 7) ; return pots[e+1] ) else ( res := (pow_fast(num, e - 1) * num) mod ((10)->pow(9) + 7) ; pots[e+1] := res ; return pots[e+1] ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- pots=[None]*1000001 pots[1]=2 def pow_fast(num,e): if pots[e]is not None : return pots[e] elif(e % 2)==0 : res=pow_fast(num,e//2)%(10**9+7) pots[e]=(res*res)%(10**9+7) return pots[e] else : res=(pow_fast(num,e-1)*num)%(10**9+7) pots[e]=res return pots[e] entrada=input() steps=0 seq_a=0 ult='b' for char in entrada : if char=='b' and ult=='a' : steps=(steps+pow_fast(2,seq_a)-1)%(10**9+7) elif char=='a' : seq_a+=1 ult='a' else : ult='b' print(steps %(10**9+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var pots : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, 1000001) ; pots[1+1] := 2 ; skip ; var entrada : String := (OclFile["System.in"]).readLine() ; var steps : int := 0 ; var seq_a : int := 0 ; var ult : String := 'b' ; for char : entrada->characters() do ( if char = 'b' & ult = 'a' then ( steps := (steps + pow_fast(2, seq_a) - 1) mod ((10)->pow(9) + 7) ) else (if char = 'a' then ( seq_a := seq_a + 1 ; ult := 'a' ) else ( ult := 'b' ) ) ) ; execute (steps mod ((10)->pow(9) + 7))->display(); operation pow_fast(num : OclAny, e : OclAny) : OclAny pre: true post: true activity: if not(pots[e+1] <>= null) then ( return pots[e+1] ) else (if (e mod 2) = 0 then ( var res : int := pow_fast(num, e div 2) mod ((10)->pow(9) + 7) ; pots[e+1] := (res * res) mod ((10)->pow(9) + 7) ; return pots[e+1] ) else ( res := (pow_fast(num, e - 1) * num) mod ((10)->pow(9) + 7) ; pots[e+1] := res ; return pots[e+1] ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def swapBits(x,p1,p2,n): set1=(x>>p1)&((1<>p2)&((1<toReal())))->toInteger() + 7; ; var exactsum : Sequence := MatrixLib.singleValueMatrix(Sequence{N, N, N}, 0.0); ; var exactnum : Sequence := MatrixLib.singleValueMatrix(Sequence{N, N, N}, 0.0); ; skip ; if __name__ = "__main__" then ( x := 1; y := 1; z := 1; ; execute ((getSum(x, y, z) mod mod))->display(); ) else skip; operation getSum(x : OclAny, y : OclAny, z : OclAny) pre: true post: true activity: var ans : int := 0; ; exactnum->first()->first()->first() := 1; ; for i : Integer.subrange(0, x + 1-1) do ( for j : Integer.subrange(0, y + 1-1) do ( for k : Integer.subrange(0, z + 1-1) do ( if (i > 0) then ( exactsum[i+1][j+1][k+1] := exactsum[i+1][j+1][k+1] + (exactsum[i - 1+1][j+1][k+1] * 10 + 4 * exactnum[i - 1+1][j+1][k+1]) mod mod; ; exactnum[i+1][j+1][k+1] := exactnum[i+1][j+1][k+1] + exactnum[i - 1+1][j+1][k+1] mod mod; ) else skip ; if (j > 0) then ( exactsum[i+1][j+1][k+1] := exactsum[i+1][j+1][k+1] + (exactsum[i+1][j - 1+1][k+1] * 10 + 5 * exactnum[i+1][j - 1+1][k+1]) mod mod; ; exactnum[i+1][j+1][k+1] := exactnum[i+1][j+1][k+1] + exactnum[i+1][j - 1+1][k+1] mod mod; ) else skip ; if (k > 0) then ( exactsum[i+1][j+1][k+1] := exactsum[i+1][j+1][k+1] + (exactsum[i+1][j+1][k - 1+1] * 10 + 6 * exactnum[i+1][j+1][k - 1+1]) mod mod; ; exactnum[i+1][j+1][k+1] := exactnum[i+1][j+1][k+1] + exactnum[i+1][j+1][k - 1+1] mod mod; ) else skip ; ans := ans + exactsum[i+1][j+1][k+1] mod mod; ; ans := ans mod mod;))) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): item=input().split() a=int(item[0]) b=int(item[1]) c=int(item[2]) x=int(item[3]) y=int(item[4]) if a>=x : if b+c>=y : print("Yes") else : print("No") else : x-=a if c0 : solve() t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( solve() ; t := t - 1); operation solve() pre: true post: true activity: var item : OclAny := input().split() ; var a : int := ("" + ((item->first())))->toInteger() ; var b : int := ("" + ((item[1+1])))->toInteger() ; var c : int := ("" + ((item[2+1])))->toInteger() ; var x : int := ("" + ((item[3+1])))->toInteger() ; var y : int := ("" + ((item[4+1])))->toInteger() ; if (a->compareTo(x)) >= 0 then ( if (b + c->compareTo(y)) >= 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else ( x := x - a ; if (c->compareTo(x)) < 0 then ( execute ("No")->display() ) else ( c := c - x ; if (c + b->compareTo(y)) < 0 then ( execute ("No")->display() ) else ( execute ("Yes")->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w=int(input()) while(w): w=w-1 a,b,c,x,y=map(int,input().split(' ')) if(x-a<=0): dog=0 else : dog=x-a if(y-b<=0): cat=0 else : cat=y-b if(dog+cat<=c): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (w) do ( w := w - 1 ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{a,b,c,x,y} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; if (x - a <= 0) then ( var dog : int := 0 ) else ( dog := x - a ) ; if (y - b <= 0) then ( var cat : int := 0 ) else ( cat := y - b ) ; if ((dog + cat->compareTo(c)) <= 0) then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a,b,c,x,y=map(int,input().split()) if(a<=x): x=x-a else : x=0 if(b<=y): y=y-b else : y=0 if((x+y)<=c): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{a,b,c,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if ((a->compareTo(x)) <= 0) then ( var x : double := x - a ) else ( x := 0 ) ; if ((b->compareTo(y)) <= 0) then ( var y : double := y - b ) else ( y := 0 ) ; if (((x + y)->compareTo(c)) <= 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : a,b,c,x,y=[int(i)for i in input().split()] i=a-x j=b-y k=0 if i<0 : k+=i if j<0 : k+=j if k<0 : if c>=abs(k): print("YES") else : print("NO") else : print("YES") t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{a,b,c,x,y} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var i : double := a - x ; var j : double := b - y ; var k : int := 0 ; if i < 0 then ( k := k + i ) else skip ; if j < 0 then ( k := k + j ) else skip ; if k < 0 then ( if (c->compareTo((k)->abs())) >= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else ( execute ("YES")->display() ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): a,b,c,x,y=map(int,input().split()) sum1=a+b+c sum2=x+y if sum1>=sum2 and a+c>=x and b+c>=y : print('yes') else : print('no') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{a,b,c,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sum1 : OclAny := a + b + c ; var sum2 : OclAny := x + y ; if (sum1->compareTo(sum2)) >= 0 & (a + c->compareTo(x)) >= 0 & (b + c->compareTo(y)) >= 0 then ( execute ('yes')->display() ) else ( execute ('no')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def words(str): wcount=vcount=ucount=i=0 while i=65 and ord(ch)<=90): ucount+=1 i+=1 print("number of words=",wcount) print("number of vowels=",vcount) print("number of upper case characters=",ucount) def frequency(str): i=1 while i<127 : ch1=chr(i) c=0 j=0 while j0 : print("Character:",ch1+" Frequency:",c) i+=1 s="Geeks for Geeks." words(s) frequency(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var s : String := "Geeks for Geeks." ; words(s) ; frequency(s); operation words(OclType["String"] : OclAny) pre: true post: true activity: wcount := wcount(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name vcount)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ucount)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; while (i->compareTo((OclType["String"])->size())) < 0 do ( var ch : String := ("" + ([i+1])) ; if (ch = " " or ch = ".") then ( wcount := wcount + 1 ) else skip ; if (ch = "a" or ch = "e" or ch = "i" or ch = 'o' or ch = "u") then ( vcount := vcount + 1 ) else skip ; if (ch = "A" or ch = "E" or ch = "I" or ch = 'O' or ch = "U") then ( vcount := vcount + 1 ) else skip ; if ((ch)->char2byte() >= 65 & (ch)->char2byte() <= 90) then ( ucount := ucount + 1 ) else skip ; i := i + 1) ; execute ("number of words=")->display() ; execute ("number of vowels=")->display() ; execute ("number of upper case characters=")->display(); operation frequency(OclType["String"] : OclAny) pre: true post: true activity: var i : int := 1 ; while i < 127 do ( var ch1 : String := (i)->byte2char() ; var c : int := 0 ; var j : int := 0 ; while (j->compareTo((OclType["String"])->size())) < 0 do ( var ch2 : String := ("" + ([j+1])) ; if (ch1 = ch2) then ( c := c + 1 ) else skip ; j := j + 1) ; if c > 0 then ( execute ("Character:")->display() ) else skip ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) o=[] cnt=0 for i in range(n): if a[i]% 2==1 : o.append(a[i]) cnt+=a[i] if len(o)==0 : print(0) exit(0) o.sort(reverse=True) idx=len(o)-1 while cnt>0 and len(o)>0 : if cnt % 2==0 : cnt-=o[idx] idx-=1 o.pop() else : break print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var o : Sequence := Sequence{} ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( if a[i+1] mod 2 = 1 then ( execute ((a[i+1]) : o) ) else skip ; cnt := cnt + a[i+1]) ; if (o)->size() = 0 then ( execute (0)->display() ; exit(0) ) else skip ; o := o->sort() ; var idx : double := (o)->size() - 1 ; while cnt > 0 & (o)->size() > 0 do ( if cnt mod 2 = 0 then ( cnt := cnt - o[idx+1] ; idx := idx - 1 ; o := o->front() ) else ( break )) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def findLCM(a,b): lar=max(a,b) small=min(a,b) i=lar while(1): if(i % small==0): return i i+=lar a=5 b=7 print("LCM of ",a," and ",b," is ",findLCM(a,b),sep="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 5 ; b := 7 ; execute ("LCM of ")->display(); operation findLCM(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var lar : OclAny := Set{a, b}->max() ; var small : OclAny := Set{a, b}->min() ; var i : OclAny := lar ; while (1) do ( if (i mod small = 0) then ( return i ) else skip ; i := i + lar); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countways(a,n): cnt=[0 for i in range(n)] s=0 s=sum(a) if(s % 3!=0): return 0 s//=3 ss=0 for i in range(n-1,-1,-1): ss+=a[i] if(ss==s): cnt[i]=1 for i in range(n-2,-1,-1): cnt[i]+=cnt[i+1] ans=0 ss=0 for i in range(0,n-2): ss+=a[i] if(ss==s): ans+=cnt[i+2] return ans n=5 a=[1,2,3,0,3] print(countways(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; a := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{0}->union(Sequence{ 3 })))) ; execute (countways(a, n))->display(); operation countways(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var cnt : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var s : int := 0 ; s := (a)->sum() ; if (s mod 3 /= 0) then ( return 0 ) else skip ; s := s div 3 ; var ss : int := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( ss := ss + a[i+1] ; if (ss = s) then ( cnt[i+1] := 1 ) else skip) ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( cnt[i+1] := cnt[i+1] + cnt[i + 1+1]) ; var ans : int := 0 ; ss := 0 ; for i : Integer.subrange(0, n - 2-1) do ( ss := ss + a[i+1] ; if (ss = s) then ( ans := ans + cnt[i + 2+1] ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nextPowerOf2(n): count=0 ; if(n and not(n &(n-1))): return n while(n!=0): n>>=1 count+=1 return 1<display(); operation nextPowerOf2(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0; ; if (n & not((MathLib.bitwiseAnd(n, (n - 1))))) then ( return n ) else skip ; while (n /= 0) do ( n := n div (2->pow(1)) ; count := count + 1) ; return 1 * (2->pow(count));; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- CHARS=26 def isValidString(str): freq=[0]*CHARS for i in range(len(str)): freq[ord(str[i])-ord('a')]+=1 freq1=0 count_freq1=0 for i in range(CHARS): if(freq[i]!=0): freq1=freq[i] count_freq1=1 break freq2=0 count_freq2=0 for j in range(i+1,CHARS): if(freq[j]!=0): if(freq[j]==freq1): count_freq1+=1 else : count_freq2=1 freq2=freq[j] break for k in range(j+1,CHARS): if(freq[k]!=0): if(freq[k]==freq1): count_freq1+=1 if(freq[k]==freq2): count_freq2+=1 else : return False if(count_freq1>1 and count_freq2>1): return False return True if __name__=="__main__" : str="abcbc" if(isValidString(str)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var CHARS : int := 26 ; skip ; if __name__ = "__main__" then ( OclType["String"] := "abcbc" ; if (isValidString(OclType["String"])) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; operation isValidString(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, CHARS) ; for i : Integer.subrange(0, (OclType["String"])->size()-1) do ( freq[(("" + ([i+1])))->char2byte() - ('a')->char2byte()+1] := freq[(("" + ([i+1])))->char2byte() - ('a')->char2byte()+1] + 1) ; var freq1 : int := 0 ; var count_freq1 : int := 0 ; for i : Integer.subrange(0, CHARS-1) do ( if (freq[i+1] /= 0) then ( freq1 := freq[i+1] ; count_freq1 := 1 ; break ) else skip) ; var freq2 : int := 0 ; var count_freq2 : int := 0 ; for j : Integer.subrange(i + 1, CHARS-1) do ( if (freq[j+1] /= 0) then ( if (freq[j+1] = freq1) then ( count_freq1 := count_freq1 + 1 ) else ( count_freq2 := 1 ; freq2 := freq[j+1] ; break ) ) else skip) ; for k : Integer.subrange(j + 1, CHARS-1) do ( if (freq[k+1] /= 0) then ( if (freq[k+1] = freq1) then ( count_freq1 := count_freq1 + 1 ) else skip ; if (freq[k+1] = freq2) then ( count_freq2 := count_freq2 + 1 ) else ( return false ) ) else skip ; if (count_freq1 > 1 & count_freq2 > 1) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nextPowerOf2(n): p=1 if(n and not(n &(n-1))): return n while(pdisplay();; operation nextPowerOf2(n : OclAny) : OclAny pre: true post: true activity: var p : int := 1 ; if (n & not((MathLib.bitwiseAnd(n, (n - 1))))) then ( return n ) else skip ; while ((p->compareTo(n)) < 0) do ( p := p * (2->pow(1))) ; return p;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPieces(N): return 2*N N=100 print(countPieces(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 100 ; execute (countPieces(N))->display(); operation countPieces(N : OclAny) : OclAny pre: true post: true activity: return 2 * N; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): MOD=10**10 ans=(28433*pow(2,7830457,MOD)+1)% MOD return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var MOD : double := (10)->pow(10) ; var ans : int := (28433 * (2)->pow(7830457) + 1) mod MOD ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda : sys.stdin.readline().rstrip() YesNo=lambda b : bool([print('Yes')]if b else print('No')) YESNO=lambda b : bool([print('YES')]if b else print('NO')) int1=lambda x : int(x)-1 def main(): H,W,A,B=map(int,input().split()) def COMinit(n,MOD): fac,finv,inv=[0]*max(2,n+1),[0]*max(2,n+1),[0]*max(2,n+1) fac[0]=fac[1]=1 finv[0]=finv[1]=1 inv[1]=1 for i in range(2,(n+1)): fac[i]=fac[i-1]*i % MOD inv[i]=MOD-inv[MOD % i]*(MOD//i)% MOD finv[i]=finv[i-1]*inv[i]% MOD return fac,finv,inv fac,finv,inv=COMinit(H+W,MOD) def COM(n,k,MOD=MOD): if npow(9)) ; var INF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var YesNo : Function := lambda b : OclAny in ((if b then Sequence{ ('Yes')->display() } else ('No')->display() endif)->toBoolean()) ; var YESNO : Function := lambda b : OclAny in ((if b then Sequence{ ('YES')->display() } else ('NO')->display() endif)->toBoolean()) ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{H,W,A,B} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; var fac : OclAny := null; var finv : OclAny := null; var inv : OclAny := null; Sequence{fac,finv,inv} := COMinit(H + W, MOD) ; skip ; var ans : int := 0 ; for i : Integer.subrange(B, W-1) do ( ans := ans + COM(H - A - 1 + i, i) * COM(A - 2 + W - i, A - 1) ; ans := ans mod MOD) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def mod_inv(inv,a,m): i=a if inv.get(a,0)!=0 : return inv[a] e=m-2 tmp=1 while e!=1 : if e % 2==1 : tmp*=a tmp %=m a*=a a %=m e//=2 a*=tmp a %=m inv[i]=a return a def factrial(fact,a,m): for i in range(1,a+1): fact[i]=fact[i-1]*i % mod def comb(fact,inv,a,b,m): return(fact[a+b]*mod_inv(inv,fact[a],m)*mod_inv(inv,fact[b],m))% m H,W,A,B=list(map(int,input().split())) mod=10**9+7 fact=[1 for _ in range(H+W+1)] inv={} factrial(fact,H+W,mod) ans=0 for i in range(W-B): ans+=comb(fact,inv,B+i,H-A-1,mod)*comb(fact,inv,W-B-1-i,A-1,mod) ans %=mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var H : OclAny := null; var W : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{H,W,A,B} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mod : double := (10)->pow(9) + 7 ; fact := Integer.subrange(0, H + W + 1-1)->select(_anon | true)->collect(_anon | (1)) ; inv := Set{} ; factrial(fact, H + W, mod) ; var ans : int := 0 ; for i : Integer.subrange(0, W - B-1) do ( ans := ans + comb(fact, inv, B + i, H - A - 1, mod) * comb(fact, inv, W - B - 1 - i, A - 1, mod) ; ans := ans mod mod) ; execute (ans)->display(); operation mod_inv(inv : OclAny, a : OclAny, m : OclAny) : OclAny pre: true post: true activity: var i : OclAny := a ; if inv.get(a, 0) /= 0 then ( return inv[a+1] ) else skip ; var e : double := m - 2 ; var tmp : int := 1 ; while e /= 1 do ( if e mod 2 = 1 then ( tmp := tmp * a ; tmp := tmp mod m ) else skip ; a := a * a ; a := a mod m ; e := e div 2) ; a := a * tmp ; a := a mod m ; inv[i+1] := a ; return a; operation factrial(fact : OclAny, a : OclAny, m : OclAny) pre: true post: true activity: for i : Integer.subrange(1, a + 1-1) do ( fact[i+1] := fact[i - 1+1] * i mod mod); operation comb(fact : OclAny, inv : OclAny, a : OclAny, b : OclAny, m : OclAny) : OclAny pre: true post: true activity: return (fact[a + b+1] * mod_inv(inv, fact[a+1], m) * mod_inv(inv, fact[b+1], m)) mod m; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W,A,B=[int(_)for _ in input().split()] p=10**9+7 def power(n,x,p): return pow(n,x,p) def solve(): kaijo=[0]*(H+W+1) kaijo[0]=kaijo[1]=1 for i in range(2,H+W+1): kaijo[i]=(i*kaijo[i-1])% p gyaku=[0]*(H+W+1) gyaku[0]=gyaku[1]=1 for i in range(2,H+W+1): gyaku[i]=power(kaijo[i],p-2,p) def conb(_x,_y): return(kaijo[_x]*gyaku[_y]*gyaku[_x-_y])% p ans=0 for i in range(W-B): ans=(ans+conb(H-A-1+B+i,H-A-1)*conb(A-1+W-1-B-i,A-1))% p print(ans) if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{H,W,A,B} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var p : double := (10)->pow(9) + 7 ; skip ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation power(n : OclAny, x : OclAny, p : OclAny) : OclAny pre: true post: true activity: return (n)->pow(x); operation solve() pre: true post: true activity: var kaijo : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (H + W + 1)) ; kaijo->first() := 1; var kaijo[1+1] : int := 1 ; for i : Integer.subrange(2, H + W + 1-1) do ( kaijo[i+1] := (i * kaijo[i - 1+1]) mod p) ; var gyaku : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (H + W + 1)) ; gyaku->first() := 1; var gyaku[1+1] : int := 1 ; for i : Integer.subrange(2, H + W + 1-1) do ( gyaku[i+1] := power(kaijo[i+1], p - 2, p)) ; skip ; var ans : int := 0 ; for i : Integer.subrange(0, W - B-1) do ( ans := (ans + conb(H - A - 1 + B + i, H - A - 1) * conb(A - 1 + W - 1 - B - i, A - 1)) mod p) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w,a,b=map(int,input().split()) mod=10**9+7 fact_l=[1 for i in range(h+w+1)] for i in range(1,len(fact_l)): fact_l[i]*=(fact_l[i-1]*i)% mod factinv_l=[1 for i in range(h+w+1)] for i in range(1,len(fact_l)): factinv_l[i]=pow(fact_l[i],mod-2,mod) point1=[1 for i in range(w-b)] for i in range(len(point1)): yoko=b+i tate=h-a-1 n=yoko+tate r=yoko point1[i]=fact_l[n]*factinv_l[r]*factinv_l[n-r]% mod out=0 for i in range(len(point1)): yoko=w-b-i-1 tate=a-1 n=yoko+tate r=yoko case=fact_l[n]*factinv_l[r]*factinv_l[n-r]% mod out+=(point1[i]*case)% mod print(out % mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{h,w,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mod : double := (10)->pow(9) + 7 ; var fact_l : Sequence := Integer.subrange(0, h + w + 1-1)->select(i | true)->collect(i | (1)) ; for i : Integer.subrange(1, (fact_l)->size()-1) do ( fact_l[i+1] := fact_l[i+1] * (fact_l[i - 1+1] * i) mod mod) ; var factinv_l : Sequence := Integer.subrange(0, h + w + 1-1)->select(i | true)->collect(i | (1)) ; for i : Integer.subrange(1, (fact_l)->size()-1) do ( factinv_l[i+1] := (fact_l[i+1])->pow(mod - 2)) ; var point1 : Sequence := Integer.subrange(0, w - b-1)->select(i | true)->collect(i | (1)) ; for i : Integer.subrange(0, (point1)->size()-1) do ( var yoko : OclAny := b + i ; var tate : double := h - a - 1 ; var n : OclAny := yoko + tate ; var r : OclAny := yoko ; point1[i+1] := fact_l[n+1] * factinv_l[r+1] * factinv_l[n - r+1] mod mod) ; var out : int := 0 ; for i : Integer.subrange(0, (point1)->size()-1) do ( yoko := w - b - i - 1 ; tate := a - 1 ; n := yoko + tate ; r := yoko ; var case : int := fact_l[n+1] * factinv_l[r+1] * factinv_l[n - r+1] mod mod ; out := out + (point1[i+1] * case) mod mod) ; execute (out mod mod)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) w=sorted(map(int,input().split())) x=sum(w) if x % 2 : print(x) else : for i in w : if i % 2 : print(x-i) break else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var x : OclAny := (w)->sum() ; if x mod 2 then ( execute (x)->display() ) else ( (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name w))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (expr (atom (name i))) % (expr (atom (number (integer 2)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (name i))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))))))))))))))) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def I(): return int(input()) def MI(): return map(int,input().split()) def LI(): return list(map(int,input().split())) def main(): mod=10**9+7 H,W,A,B=MI() N=H+W def cmb(n,r,mod): if(r<0)or(ntoInteger(); operation MI() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation main() pre: true post: true activity: var mod : double := (10)->pow(9) + 7 ; var H : OclAny := null; var W : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{H,W,A,B} := MI() ; var N : OclAny := H + W ; skip ; var fact : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var factinv : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var inv : Sequence := Sequence{0}->union(Sequence{ 1 }) ; for i : Integer.subrange(2, N + 1-1) do ( execute (((fact->last() * i) mod mod) : fact) ; execute (((-inv[mod mod i+1] * (mod div i)) mod mod) : inv) ; execute (((factinv->last() * inv->last()) mod mod) : factinv)) ; var ans : OclAny := cmb(N - 2, H - 1, mod) ; for i : Integer.subrange(0, Set{A, B}->min()-1) do ( var h : double := H - A + i + 1 ; var w : double := B - i ; ans := ans - cmb(h + w - 2, h - 1, mod) * cmb(H + W - (h + w), H - h, mod) ; ans := ans mod mod) ; execute (ans mod mod)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def numberofterm(n,number): firstnum=math.pow(10,n-1) lastnum=math.pow(10,n) count=0 for i in range(int(firstnum),int(lastnum)): if(i % number==0): count+=1 return count n=3 num=7 print(numberofterm(n,num)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 3 ; var num : int := 7 ; execute (numberofterm(n, num))->display(); operation numberofterm(n : OclAny, number : OclAny) : OclAny pre: true post: true activity: var firstnum : double := (10)->pow(n - 1) ; var lastnum : double := (10)->pow(n) ; var count : int := 0 ; for i : Integer.subrange(("" + ((firstnum)))->toInteger(), ("" + ((lastnum)))->toInteger()-1) do ( if (i mod number = 0) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import Fraction a,b,c,d=map(int,input().split()) if c>a or d>b : if c>a and d>b : p=min(Fraction(b/d).limit_denominator(),Fraction(a/c).limit_denominator()) elif c>a : p=Fraction(a/c).limit_denominator() else : p=Fraction(b/d).limit_denominator() else : p=min(Fraction(b/d).limit_denominator(),Fraction(a/c).limit_denominator()) c*=p d*=p up,down=(a*b-c*d),a*b ans=str(Fraction(up/down).limit_denominator()) print('0/1' if ans=='0' else ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (c->compareTo(a)) > 0 or (d->compareTo(b)) > 0 then ( if (c->compareTo(a)) > 0 & (d->compareTo(b)) > 0 then ( var p : OclAny := Set{Fraction(b / d).limit_denominator(), Fraction(a / c).limit_denominator()}->min() ) else (if (c->compareTo(a)) > 0 then ( p := Fraction(a / c).limit_denominator() ) else ( p := Fraction(b / d).limit_denominator() ) ) ) else ( p := Set{Fraction(b / d).limit_denominator(), Fraction(a / c).limit_denominator()}->min() ) ; c := c * p ; d := d * p ; var up : OclAny := null; var down : OclAny := null; Sequence{up,down} := Sequence{(a * b - c * d),a * b} ; var ans : String := ("" + ((Fraction(up / down).limit_denominator()))) ; execute (if ans = '0' then '0/1' else ans endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def totalSumDivisibleByNum(n,number): firstnum=pow(10,n-1) lastnum=pow(10,n) sum=0 for i in range(firstnum,lastnum): if(i % number==0): sum+=i return sum n=3 ; num=7 print(totalSumDivisibleByNum(n,num)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3; var num : int := 7 ; execute (totalSumDivisibleByNum(n, num))->display(); operation totalSumDivisibleByNum(n : OclAny, number : OclAny) : OclAny pre: true post: true activity: var firstnum : double := (10)->pow(n - 1) ; var lastnum : double := (10)->pow(n) ; var sum : int := 0 ; for i : Integer.subrange(firstnum, lastnum-1) do ( if (i mod number = 0) then ( sum := sum + i ) else skip) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) arr=[] while N>0 : n=N m=0 p=1 while int(n)!=0 : if n % 10 : m+=p n=n//10 p=p*10 arr.append(m) N-=m print(len(arr)) for i in arr : print(i,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Sequence{} ; while N > 0 do ( var n : int := N ; var m : int := 0 ; var p : int := 1 ; while ("" + ((n)))->toInteger() /= 0 do ( if n mod 10 then ( m := m + p ) else skip ; n := n div 10 ; p := p * 10) ; execute ((m) : arr) ; N := N - m) ; execute ((arr)->size())->display() ; for i : arr do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() def convert_to_list(n): res=[] for i in n : res.append(int(i)) return res def solve(n): res=[] while True : power,total=0,0 for i in range(len(n)-1,-1,-1): num=n[i] if num!=0 : total+=pow(10,power) n[i]=num-1 power+=1 if total==0 : break res.append(total) return res def format_output(res): output="" for i,val in enumerate(res): if i!=len(res)-1 : output=output+str(val)+" " else : output=output+str(val) return output n=convert_to_list(x) res=solve(n) output=format_output(res) print(len(res)) print(output) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := (OclFile["System.in"]).readLine() ; skip ; skip ; skip ; n := convert_to_list(x) ; res := solve(n) ; output := format_output(res) ; execute ((res)->size())->display() ; execute (output)->display(); operation convert_to_list(n : OclAny) : OclAny pre: true post: true activity: var res : Sequence := Sequence{} ; for i : n do ( execute ((("" + ((i)))->toInteger()) : res)) ; return res; operation solve(n : OclAny) : OclAny pre: true post: true activity: res := Sequence{} ; while true do ( var power : OclAny := null; var total : OclAny := null; Sequence{power,total} := Sequence{0,0} ; for i : Integer.subrange(-1 + 1, (n)->size() - 1)->reverse() do ( var num : OclAny := n[i+1] ; if num /= 0 then ( total := total + (10)->pow(power) ; n[i+1] := num - 1 ) else skip ; power := power + 1) ; if total = 0 then ( break ) else skip ; execute ((total) : res)) ; return res; operation format_output(res : OclAny) : OclAny pre: true post: true activity: var output : String := "" ; for _tuple : Integer.subrange(1, (res)->size())->collect( _indx | Sequence{_indx-1, (res)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var val : OclAny := _tuple->at(_indx); if i /= (res)->size() - 1 then ( output := output + ("" + ((val))) + " " ) else ( output := output + ("" + ((val))) )) ; return output; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n): ans=[] while(n!=0): r=n % 10 ans.append(0)if r==0 else ans.append(1) n//=10 res=0 for i in reversed(ans): res=(res*10+i) return res n=int(input()) fans=[] while(n!=0): fans.append(solve(n)) n-=fans[-1] print(len(fans)) print(*fans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var fans : Sequence := Sequence{} ; while (n /= 0) do ( execute ((solve(n)) : fans) ; n := n - fans->last()) ; execute ((fans)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name fans))))))))->display(); operation solve(n : OclAny) : OclAny pre: true post: true activity: var ans : Sequence := Sequence{} ; while (n /= 0) do ( var r : int := n mod 10 ; (test (logical_test (comparison (expr (atom (name ans)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))))) if (logical_test (comparison (comparison (expr (atom (name r)))) == (comparison (expr (atom (number (integer 0))))))) else (test (logical_test (comparison (expr (atom (name ans)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))))) ; n := n div 10) ; var res : int := 0 ; for i : (ans)->reverse() do ( res := (res * 10 + i)) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=[] k=0 while n>0 : b=n % 10 n//=10 ln=len(s) if btoInteger() ; var s : Sequence := Sequence{} ; var k : int := 0 ; while n > 0 do ( var b : int := n mod 10 ; n := n div 10 ; var ln : int := (s)->size() ; if (b->compareTo(ln)) < 0 then ( for i : Integer.subrange(0, b-1) do ( s[i+1] := s[i+1] + (10)->pow(k)) ) else ( for i : Integer.subrange(0, ln-1) do ( s[i+1] := s[i+1] + (10)->pow(k)) ; for i : Integer.subrange(0, b - ln-1) do ( execute (((10)->pow(k)) : s)) ) ; k := k + 1) ; execute ((s)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name s))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* def findRadiusOfcircumcircle(n,a): if n<0 or a<0 : return-1 radius=a/sqrt(2-(2*cos(360/n))) return radius if __name__=="__main__" : n,a=5,6 print(round(findRadiusOfcircumcircle(n,a),5)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( Sequence{n,a} := Sequence{5,6} ; execute (MathLib.roundN(findRadiusOfcircumcircle(n, a), 5))->display() ) else skip; operation findRadiusOfcircumcircle(n : OclAny, a : OclAny) : OclAny pre: true post: true activity: if n < 0 or a < 0 then ( return -1 ) else skip ; var radius : double := a / sqrt(2 - (2 * cos(360 / n))) ; return radius; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def push(piles : list,pile_number : str,color : str)->list : piles[int(pile_number)-1].append(color) return piles def pile_pop(piles : list,pile_number : str)->list : removed=piles[int(pile_number)-1].pop() print(removed) return piles def move(piles : list,pile_number1 : str,pile_number2 : str)->list : moved=piles[int(pile_number1)-1].pop() piles[int(pile_number2)-1].append(moved) return piles if __name__=='__main__' : n=int(input()) pile_list=[[]for i in range(n)] while True : order=input().split() if order[0]=='quit' : break elif order[0]=='push' : pile_list=push(pile_list[:],order[1],order[2]) elif order[0]=='pop' : pile_list=pile_pop(pile_list[:],order[1]) elif order[0]=='move' : pile_list=move(pile_list[:],order[1],order[2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var pile_list : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; while true do ( var order : OclAny := input().split() ; if order->first() = 'quit' then ( break ) else (if order->first() = 'push' then ( pile_list := push(pile_list, order[1+1], order[2+1]) ) else (if order->first() = 'pop' then ( pile_list := pile_pop(pile_list, order[1+1]) ) else (if order->first() = 'move' then ( pile_list := move(pile_list, order[1+1], order[2+1]) ) else skip ) ) ) ) ) else skip; operation push(piles : Sequence(OclAny), pile_number : String, color : String) : Sequence pre: true post: true activity: (expr (atom (name piles)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name pile_number)))))))) )))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name color)))))))) )))) ; return piles; operation pile_pop(piles : Sequence(OclAny), pile_number : String) : Sequence pre: true post: true activity: var removed : OclAny := piles[("" + ((pile_number)))->toInteger() - 1+1]->last() ; execute (removed)->display() ; return piles; operation move(piles : Sequence(OclAny), pile_number1 : String, pile_number2 : String) : Sequence pre: true post: true activity: var moved : OclAny := piles[("" + ((pile_number1)))->toInteger() - 1+1]->last() ; (expr (atom (name piles)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name pile_number2)))))))) )))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name moved)))))))) )))) ; return piles; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function import sys num_stack=int(sys.stdin.readline()) stacks=[[]for n in xrange(num_stack)] for line in sys.stdin : if line.startswith('quit'): break if line.startswith('push'): p,c=line.split()[1 :] stacks[int(p)-1].append(c) elif line.startswith('pop'): p=line.split()[1] print(stacks[int(p)-1].pop()) elif line.startswith('move'): p1,p2=line.split()[1 :] stacks[int(p2)-1].append(stacks[int(p1)-1].pop()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var num_stack : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var stacks : Sequence := xrange(num_stack)->select(n | true)->collect(n | (Sequence{})) ; for line : OclFile["System.in"] do ( if line->hasPrefix('quit') then ( break ) else skip ; if line->hasPrefix('push') then ( var p : OclAny := null; var c : OclAny := null; Sequence{p,c} := line.split()->tail() ; (expr (atom (name stacks)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p)))))))) )))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))) ) else (if line->hasPrefix('pop') then ( var p : OclAny := line.split()[1+1] ; execute (stacks[("" + ((p)))->toInteger() - 1+1]->last())->display() ) else (if line->hasPrefix('move') then ( var p1 : OclAny := null; var p2 : OclAny := null; Sequence{p1,p2} := line.split()->tail() ; (expr (atom (name stacks)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p2)))))))) )))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name stacks)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p1)))))))) )))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name pop) (arguments ( ))))))))) )))) ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() a=[int(i)for i in input().split()] b=sum(a) c=[] if b % 2==0 : for i in a : if i % 2!=0 : c.append(i) if len(c)>0 : print(b-min(c)) else : print(0) else : print(b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var b : OclAny := (a)->sum() ; var c : Sequence := Sequence{} ; if b mod 2 = 0 then ( for i : a do ( if i mod 2 /= 0 then ( execute ((i) : c) ) else skip) ; if (c)->size() > 0 then ( execute (b - (c)->min())->display() ) else ( execute (0)->display() ) ) else ( execute (b)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=[[]for i in range(n)] while True : cmd=input().strip().split() if cmd[0]=='push' : s[int(cmd[1])-1].append(cmd[2]) elif cmd[0]=='pop' : print(s[int(cmd[1])-1].pop()) elif cmd[0]=='move' : s[int(cmd[2])-1].append(s[int(cmd[1])-1].pop()) else : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; while true do ( var cmd : OclAny := input()->trim().split() ; if cmd->first() = 'push' then ( (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name cmd)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name cmd)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))) )))) ) else (if cmd->first() = 'pop' then ( execute (s[("" + ((cmd[1+1])))->toInteger() - 1+1]->last())->display() ) else (if cmd->first() = 'move' then ( (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name cmd)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))) )))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name cmd)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name pop) (arguments ( ))))))))) )))) ) else ( break ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : s=list(input()) for i in range(len(s)): if i % 2==0 : if s[i]=='a' : s[i]='b' else : s[i]='a' else : if s[i]=='z' : s[i]='y' else : s[i]='z' print(''.join(s)) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; for i : Integer.subrange(0, (s)->size()-1) do ( if i mod 2 = 0 then ( if s[i+1] = 'a' then ( s[i+1] := 'b' ) else ( s[i+1] := 'a' ) ) else ( if s[i+1] = 'z' then ( s[i+1] := 'y' ) else ( s[i+1] := 'z' ) )) ; execute (StringLib.sumStringsWithSeparator((s), ''))->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stacks=[] no_stacks=int(input()) for _ in range(no_stacks): stacks.append([]) for operation in sys.stdin : operation=operation.strip() if operation.startswith('quit'): break elif operation.startswith('push'): _,index,block=operation.split() stacks[int(index)-1].append(block) elif operation.startswith('pop'): _,index=operation.split() print(stacks[int(index)-1].pop()) elif operation.startswith('move'): _,src_index,dst_index=operation.split() stacks[int(dst_index)-1].append(stacks[int(src_index)-1].pop()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stacks : Sequence := Sequence{} ; var no_stacks : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, no_stacks-1) do ( execute ((Sequence{}) : stacks)) ; for operation : OclFile["System.in"] do ( var operation : String := operation->trim() ; if operation->hasPrefix('quit') then ( break ) else (if operation->hasPrefix('push') then ( var _anon : OclAny := null; var index : OclAny := null; var block : OclAny := null; Sequence{_anon,index,block} := operation.split() ; (expr (atom (name stacks)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name index)))))))) )))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name block)))))))) )))) ) else (if operation->hasPrefix('pop') then ( var _anon : OclAny := null; var index : OclAny := null; Sequence{_anon,index} := operation.split() ; execute (stacks[("" + ((index)))->toInteger() - 1+1]->last())->display() ) else (if operation->hasPrefix('move') then ( var _anon : OclAny := null; var src_index : OclAny := null; var dst_index : OclAny := null; Sequence{_anon,src_index,dst_index} := operation.split() ; (expr (atom (name stacks)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name dst_index)))))))) )))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name stacks)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name src_index)))))))) )))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name pop) (arguments ( ))))))))) )))) ) else skip ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=(int)(raw_input()) b=[[]for i in range(n+1)] while True : com=raw_input().split() if com[0]=="quit" : break elif com[0]=="push" : com[1]=int(com[1]) b[com[1]].append(com[2]) elif com[0]=="move" : com[1]=int(com[1]) com[2]=int(com[2]) tmp=b[com[1]].pop() b[com[2]].append(tmp) elif com[0]=="pop" : com[1]=int(com[1]) print(b[com[1]].pop()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := (OclType["int"])(raw_input()) ; var b : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Sequence{})) ; while true do ( var com : OclAny := raw_input().split() ; if com->first() = "quit" then ( break ) else (if com->first() = "push" then ( com[1+1] := ("" + ((com[1+1])))->toInteger() ; (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name com)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name com)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))) )))) ) else (if com->first() = "move" then ( com[1+1] := ("" + ((com[1+1])))->toInteger() ; com[2+1] := ("" + ((com[2+1])))->toInteger() ; var tmp : OclAny := b[com[1+1]+1]->last() ; (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name com)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name tmp)))))))) )))) ) else (if com->first() = "pop" then ( com[1+1] := ("" + ((com[1+1])))->toInteger() ; execute (b[com[1+1]+1]->last())->display() ) else skip ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minimumIncrease(a,b,c): arr=[a,b,c] arr.sort() if arr[0]+arr[1]>=arr[2]: return 0 else : return arr[2]-(arr[0]+arr[1]) if __name__=="__main__" : a,b,c=3,5,10 print(minimumIncrease(a,b,c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{a,b,c} := Sequence{3,5,10} ; execute (minimumIncrease(a, b, c))->display() ) else skip; operation minimumIncrease(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: var arr : Sequence := Sequence{a}->union(Sequence{b}->union(Sequence{ c })) ; arr := arr->sort() ; if (arr->first() + arr[1+1]->compareTo(arr[2+1])) >= 0 then ( return 0 ) else ( return arr[2+1] - (arr->first() + arr[1+1]) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- M=50 def constructDP(dp,string): l=len(string) isPalin=[[0 for i in range(l+1)]for j in range(l+1)] for i in range(l-1,-1,-1): isPalin[i][i],dp[i][i]=1,1 for j in range(i+1,l): isPalin[i][j]=(string[i]==string[j]and(i+1>j-1 or isPalin[i+1][j-1])) dp[i][j]=(dp[i][j-1]+dp[i+1][j]-dp[i+1][j-1]+isPalin[i][j]) def countOfPalindromeInRange(dp,l,r): return dp[l][r] if __name__=="__main__" : string="xyaabax" dp=[[0 for i in range(M)]for j in range(M)] constructDP(dp,string) l,r=3,5 print(countOfPalindromeInRange(dp,l,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var M : int := 50 ; skip ; skip ; if __name__ = "__main__" then ( string := "xyaabax" ; dp := Integer.subrange(0, M-1)->select(j | true)->collect(j | (Integer.subrange(0, M-1)->select(i | true)->collect(i | (0)))) ; constructDP(dp, string) ; Sequence{l,r} := Sequence{3,5} ; execute (countOfPalindromeInRange(dp, l, r))->display() ) else skip; operation constructDP(dp : OclAny, string : OclAny) pre: true post: true activity: var l : int := (string)->size() ; var isPalin : Sequence := Integer.subrange(0, l + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, l + 1-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(-1 + 1, l - 1)->reverse() do ( var isPalin[i+1][i+1] : OclAny := null; var dp[i+1][i+1] : OclAny := null; Sequence{isPalin[i+1][i+1],dp[i+1][i+1]} := Sequence{1,1} ; for j : Integer.subrange(i + 1, l-1) do ( isPalin[i+1][j+1] := (string[i+1] = string[j+1] & ((i + 1->compareTo(j - 1)) > 0 or isPalin[i + 1+1][j - 1+1])) ; dp[i+1][j+1] := (dp[i+1][j - 1+1] + dp[i + 1+1][j+1] - dp[i + 1+1][j - 1+1] + isPalin[i+1][j+1]))); operation countOfPalindromeInRange(dp : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: return dp[l+1][r+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minLength(n): ans=n//26 if(n % 26!=0): ans+=1 return ans def minString(n): ans=n//26 res="" while(ans): res=res+"z" ans-=1 if(n % 26!=0): res=res+chr((n % 26)+96) return res n=50 ; print(minLength(n)) print(minString(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 50; ; execute (minLength(n))->display() ; execute (minString(n))->display(); operation minLength(n : OclAny) : OclAny pre: true post: true activity: var ans : int := n div 26 ; if (n mod 26 /= 0) then ( ans := ans + 1 ) else skip ; return ans; operation minString(n : OclAny) : OclAny pre: true post: true activity: ans := n div 26 ; var res : String := "" ; while (ans) do ( res := res + "z" ; ans := ans - 1) ; if (n mod 26 /= 0) then ( res := res + ((n mod 26) + 96)->byte2char() ) else skip ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def product(A): N=100010 mod=1000000007 prime=[1]*N prime[0]=prime[1]=0 i=2 while i*iunion(Sequence{ 7 }) ; execute (product(A))->display(); operation product(A : OclAny) : OclAny pre: true post: true activity: var N : int := 100010 ; var mod : int := 1000000007 ; var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, N) ; prime->first() := 0; var prime[1+1] : int := 0 ; var i : int := 2 ; while (i * i->compareTo(N)) < 0 do ( if prime[i+1] then ( for j : Integer.subrange(i * i, N-1)->select( $x | ($x - i * i) mod i = 0 ) do ( prime[j+1] := 0) ) else skip ; i := i + 1) ; var n : int := (A)->size() ; var t : double := (2)->pow(n - 1) ; var ans : int := 1 ; for i : A do ( if prime[i+1] then ( ans := ans * (i)->pow(t) ; ans := ans mod mod ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : r,c=map(int,input().split()) if r==0 : break print("no" if r*c & 1 else "yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if r = 0 then ( break ) else skip ; execute (if MathLib.bitwiseAnd(r * c, 1) then "no" else "yes" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : a,b=map(int,input().split()) if a==b==0 : break if a*b % 2 : print("no") else : print("yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = b & (b == 0) then ( break ) else skip ; if a * b mod 2 then ( execute ("no")->display() ) else ( execute ("yes")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : a,b=map(int,input().split()) if a==0 and b==0 : break if a % 2==0 or b % 2==0 : print("yes") else : print("no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 0 & b = 0 then ( break ) else skip ; if a mod 2 = 0 or b mod 2 = 0 then ( execute ("yes")->display() ) else ( execute ("no")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() next=input() o=0 e=0 sum=0 odd=[] l=next.split(' ') for i in range(int(n)): if int(l[i])% 2==0 : e+=1 else : o+=1 odd.append(l[i]) sum+=int(l[i]) if o % 2==1 : print(sum) else : if odd!=[]: sub=odd[0] for j in range(len(odd)): if int(sub)<=int(odd[j]): continue else : sub=odd[j] sum=sum-int(sub) print(sum) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var next : String := (OclFile["System.in"]).readLine() ; var o : int := 0 ; var e : int := 0 ; var sum : int := 0 ; var odd : Sequence := Sequence{} ; var l : OclAny := .split(' ').next() ; for i : Integer.subrange(0, ("" + ((n)))->toInteger()-1) do ( if ("" + ((l[i+1])))->toInteger() mod 2 = 0 then ( e := e + 1 ) else ( o := o + 1 ; execute ((l[i+1]) : odd) ) ; sum := sum + ("" + ((l[i+1])))->toInteger()) ; if o mod 2 = 1 then ( execute (sum)->display() ) else ( if odd /= Sequence{} then ( var sub : OclAny := odd->first() ; for j : Integer.subrange(0, (odd)->size()-1) do ( if (("" + ((sub)))->toInteger()->compareTo(("" + ((odd[j+1])))->toInteger())) <= 0 then ( continue ) else ( sub := odd[j+1] )) ; sum := sum - ("" + ((sub)))->toInteger() ; execute (sum)->display() ) else ( execute (0)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) for i in range(N): s=input() ans='' for j in range(len(s)): if j & 1 : ans+='z' if s[j]!='z' else 'y' else : ans+='a' if s[j]!='a' else 'b' print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, N-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var ans : String := '' ; for j : Integer.subrange(0, (s)->size()-1) do ( if MathLib.bitwiseAnd(j, 1) then ( ans := ans + if s[j+1] /= 'z' then 'z' else 'y' endif ) else ( ans := ans + if s[j+1] /= 'a' then 'a' else 'b' endif )) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : r,c=map(int,input().split()) if r==0 : break print(["yes","no"][c % 2 and r % 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if r = 0 then ( break ) else skip ; execute (Sequence{"yes"}->union(Sequence{ "no" })->select(c mod 2 & r mod 2))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def find_volume(area,h): Volume=(area*h) print("Volume: ",end=" ") print(Volume) def find_Surface_area(area,a,h): Surface_area=(2*area)+(8*a*h) print("Surface area: ",end=" ") print(Surface_area) h=1 a=6 d=2 area=2*a*d find_Surface_area(area,a,h) find_volume(area,h) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; h := 1 ; a := 6 ; var d : int := 2 ; area := 2 * a * d ; find_Surface_area(area, a, h) ; find_volume(area, h); operation find_volume(area : OclAny, h : OclAny) pre: true post: true activity: var Volume : double := (area * h) ; execute ("Volume: ")->display() ; execute (Volume)->display(); operation find_Surface_area(area : OclAny, a : OclAny, h : OclAny) pre: true post: true activity: var Surface_area : double := (2 * area) + (8 * a * h) ; execute ("Surface area: ")->display() ; execute (Surface_area)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=int(n/5) if int(n/5)==n/5 : print(ans) else : print(ans+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := ("" + ((n / 5)))->toInteger() ; if ("" + ((n / 5)))->toInteger() = n / 5 then ( execute (ans)->display() ) else ( execute (ans + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil n=int(input()) print(ceil(n/5)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (ceil(n / 5))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): x=int(input()) torch=1 while(x>5): x-=5 torch+=1 print(torch) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var torch : int := 1 ; while (x > 5) do ( x := x - 5 ; torch := torch + 1) ; execute (torch)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) if int(x/5)==x/5 : print(int(x/5)) else : print(int(x/5)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if ("" + ((x / 5)))->toInteger() = x / 5 then ( execute (("" + ((x / 5)))->toInteger())->display() ) else ( execute (("" + ((x / 5)))->toInteger() + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- coordinates=int(input()) count=coordinates//5+(coordinates % 5!=0) print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var coordinates : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := coordinates div 5 + (coordinates mod 5 /= 0) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count_characters(word,dic,kcs,kcs2,kcs2_1): prev1=None i=0 l=len(word) while imax_n : max_n=v max_c=k print(c,max_c,max_n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; kcs := Sequence{"a"}->union(Sequence{"b"}->union(Sequence{"c"}->union(Sequence{"d"}->union(Sequence{"e"}->union(Sequence{"f"}->union(Sequence{"g"}->union(Sequence{"h"}->union(Sequence{"i"}->union(Sequence{"j"}->union(Sequence{"k"}->union(Sequence{"l"}->union(Sequence{"m"}->union(Sequence{"n"}->union(Sequence{"o"}->union(Sequence{"p"}->union(Sequence{"q"}->union(Sequence{"r"}->union(Sequence{"s"}->union(Sequence{"t"}->union(Sequence{"u"}->union(Sequence{"v"}->union(Sequence{"w"}->union(Sequence{"x"}->union(Sequence{"y"}->union(Sequence{ "z" }))))))))))))))))))))))))) ; kcs2 := Sequence{"ld"}->union(Sequence{"mb"}->union(Sequence{"mp"}->union(Sequence{"nc"}->union(Sequence{"nd"}->union(Sequence{"ng"}->union(Sequence{"nt"}->union(Sequence{"nw"}->union(Sequence{"ps"}->union(Sequence{"qu"}->union(Sequence{"cw"}->union(Sequence{ "ts" }))))))))))) ; kcs2 skip := Sequence{"l"}->union(Sequence{"m"}->union(Sequence{"n"}->union(Sequence{"p"}->union(Sequence{"q"}->union(Sequence{"c"}->union(Sequence{ "t" })))))) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; dic := Set{} ; for c : (kcs + kcs2) do ( var table : OclAny := Set{} ; for c1 : (kcs + kcs2) do ( table[c1+1] := 0) ; dic[c+1] := table) ; for i : Integer.subrange(0, n-1) do ( var words : OclAny := input().split() ; for word : words do ( count_characters(word, dic, kcs, kcs2, kcs2kcs2))) ; for c : (kcs + kcs2) do ( var occurence_table : OclAny := dic[c+1] ; var max_c : String := "a" ; var max_n : int := 0 ; for _tuple : occurence_table->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if (v->compareTo(max_n)) > 0 then ( max_n := v ; max_c := k ) else skip) ; execute (c)->display()); operation count_characters(word : OclAny, dic : OclAny, kcs : OclAny, kcs2 : OclAny, kcs2kcs2 : OclAny : OclAny) pre: true post: true activity: var prev1 : OclAny := null ; var i : int := 0 ; var l : int := (word)->size() ; while (i->compareTo(l)) < 0 do ( var c : OclAny := word[i+1] ; if (kcs2 var c : OclAny := word[i+1])->includes(c) & (i->compareTo(l - 1)) < 0 then ( var c2 : OclAny := word[i + 1+1] ; if (kcs2)->includes((c + c2)) then ( if prev1 /= null then ( dic[prev1+1][c + c2+1] := dic[prev1+1][c + c2+1] + 1 ) else skip ; prev1 := c + c2 ; i := i + 2 ; continue ) else skip ) else skip ; if prev1 /= null then ( dic[prev1+1][c+1] := dic[prev1+1][c+1] + 1 ) else skip ; prev1 := c ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np ; matrix=np.zeros((100,100)); def printRequiredMatrix(n): if(n==1): print("1"); elif(n % 2!=0): print("-1"); else : for i in range(n): matrix[i][i]=n ; u=n-1 ; for i in range(n-1): matrix[i][u]=i+1 ; for j in range(1,n//2): a=(i+j)%(n-1); b=(i-j+n-1)%(n-1); if(adisplay(); ) else (if (n mod 2 /= 0) then ( execute ("-1")->display(); ) else ( for i : Integer.subrange(0, n-1) do ( matrix[i+1][i+1] := n;) ; var u : double := n - 1; ; for i : Integer.subrange(0, n - 1-1) do ( matrix[i+1][u+1] := i + 1; ; for j : Integer.subrange(1, n div 2-1) do ( var a : int := (i + j) mod (n - 1); ; var b : int := (i - j + n - 1) mod (n - 1); ; if ((a->compareTo(b)) < 0) then ( Sequence{a,b} := Sequence{b,a} ) else skip ; matrix[b+1][a+1] := i + 1;)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, i-1) do ( matrix[i+1][j+1] := matrix[j+1][i+1] + n;)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( execute (matrix[i+1][j+1])->display();) ; execute (->display();) ) ) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd as __gcd maxLen=30 seg=[0 for i in range(3*maxLen)] def build(l,r,inn,arr): if(l==r): seg[inn]=arr[l] return seg[inn] mid=(l+r)//2 seg[inn]=__gcd(build(l,mid,2*inn+1,arr),build(mid+1,r,2*inn+2,arr)) return seg[inn] def query(l,r,l1,r1,inn): if(l1<=l and r<=r1): return seg[inn] if(l>r1 or rselect(i | true)->collect(i | (0)) ; skip ; skip ; skip ; arr := Sequence{2}->union(Sequence{2}->union(Sequence{ 2 })) ; n := (arr)->size() ; execute (findLen(arr, n))->display(); operation build(l : OclAny, r : OclAny, inn : OclAny, arr : OclAny) : OclAny pre: true post: true activity: if (l = r) then ( seg[inn+1] := arr[l+1] ; return seg[inn+1] ) else skip ; var mid : int := (l + r) div 2 ; seg[inn+1] := __gcd(build(l, mid, 2 * inn + 1, arr), build(mid + 1, r, 2 * inn + 2, arr)) ; return seg[inn+1]; operation query(l : OclAny, r : OclAny, l1 : OclAny, r1 : OclAny, inn : OclAny) : OclAny pre: true post: true activity: if ((l1->compareTo(l)) <= 0 & (r->compareTo(r1)) <= 0) then ( return seg[inn+1] ) else skip ; if ((l->compareTo(r1)) > 0 or (r->compareTo(l1)) < 0) then ( return 0 ) else skip ; mid := (l + r) div 2 ; var x : OclAny := __gcd(query(l, mid, l1, r1, 2 * inn + 1), query(mid + 1, r, l1, r1, 2 * inn + 2)) ; return x; operation findLen(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: build(0, n - 1, 0, arr) ; var i : int := 0 ; var j : int := 0 ; var ans : double := (10)->pow(9) ; while ((i->compareTo(n)) < 0) do ( while ((j->compareTo(n)) < 0 & query(0, n - 1, i, j, 0) /= 1) do ( j := j + 1) ; if (j = n) then ( break; ) else skip ; ans := minn((j - i + 1), ans) ; i := i + 1 ; j := Set{j, i}->max()) ; if (ans = (10)->pow(9)) then ( return -1 ) else ( return ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : s=input() new_s="" turn=1 for i in range(len(s)): if turn==1 : if s[i]=="a" : new_s+="b" elif s[i]!="a" : new_s+="a" turn=2 elif turn==2 : if s[i]=="z" : new_s+="y" elif s[i]!="z" : new_s+="z" turn=1 print(new_s) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( var s : String := (OclFile["System.in"]).readLine() ; var new_s : String := "" ; var turn : int := 1 ; for i : Integer.subrange(0, (s)->size()-1) do ( if turn = 1 then ( if s[i+1] = "a" then ( new_s := new_s + "b" ) else (if s[i+1] /= "a" then ( new_s := new_s + "a" ) else skip) ; turn := 2 ) else (if turn = 2 then ( if s[i+1] = "z" then ( new_s := new_s + "y" ) else (if s[i+1] /= "z" then ( new_s := new_s + "z" ) else skip) ; turn := 1 ) else skip)) ; execute (new_s)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) evencount=0 oddlist=[] for i in a : if i % 2==1 : oddlist.append(i) else : evencount+=i if len(oddlist)==0 : print(0) else : if len(oddlist)% 2==1 : print(evencount+sum(oddlist)) else : oddlist=sorted(oddlist) print(evencount+sum(oddlist[1 :])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var evencount : int := 0 ; var oddlist : Sequence := Sequence{} ; for i : a do ( if i mod 2 = 1 then ( execute ((i) : oddlist) ) else ( evencount := evencount + i )) ; if (oddlist)->size() = 0 then ( execute (0)->display() ) else ( if (oddlist)->size() mod 2 = 1 then ( execute (evencount + (oddlist)->sum())->display() ) else ( oddlist := oddlist->sort() ; execute (evencount + (oddlist->tail())->sum())->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : N,A,B,C,X=map(int,raw_input().split()) if N==0 and A==0 and B==0 and C==0 and X==0 : break Y=map(int,raw_input().split()) ans,i=0,0 while True : if X==Y[i]: i+=1 if i==N or ans>10000 : break X=(A*X+B)% C ans+=1 print-1 if ans>10000 else ans ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var X : OclAny := null; Sequence{N,A,B,C,X} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if N = 0 & A = 0 & B = 0 & C = 0 & X = 0 then ( break ) else skip ; var Y : Sequence := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : OclAny := null; var i : OclAny := null; Sequence{ans,i} := Sequence{0,0} ; while true do ( if X = Y[i+1] then ( i := i + 1 ) else skip ; if i = N or ans > 10000 then ( break ) else skip ; var X : int := (A * X + B) mod C ; ans := ans + 1) ; (test (logical_test (comparison (expr (expr (atom print)) - (expr (atom (number (integer 1))))))) if (logical_test (comparison (comparison (expr (atom (name ans)))) > (comparison (expr (atom (number (integer 10000))))))) else (test (logical_test (comparison (expr (atom (name ans)))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class SlotMachine : def __init__(self,reel_num,A,B,C): self.reel_num=reel_num self.A=A self.B=B self.C=C def calculate_random_num(self,random_num): random_num=(self.A*random_num+self.B)% self.C return random_num def count_flame(self,condition_list,random_num): flame_num=0 order=0 while order10001 : flame_num=-1 return flame_num return flame_num-1 def check_condition(self,condition_list,random_num,order,flame_num): if random_num==condition_list[order]: order+=1 random_num=self.calculate_random_num(random_num) flame_num+=1 return order,flame_num,random_num def get_data_list(): data_list=input().split() for i in range(len(data_list)): data_list[i]=int(data_list[i]) return data_list if __name__=="__main__" : while True : data_list=get_data_list() reel_num=data_list[0] A=data_list[1] B=data_list[2] C=data_list[3] first_num=data_list[4] if reel_num==0 : break condition_list=get_data_list() slot_machine=SlotMachine(reel_num,A,B,C) flame_num=slot_machine.count_flame(condition_list,first_num) print(flame_num) ------------------------------------------------------------ OCL File: --------- class SlotMachine { static operation newSlotMachine() : SlotMachine pre: true post: SlotMachine->exists( _x | result = _x ); attribute reel_num : OclAny := reel_num; attribute A : OclAny := A; attribute B : OclAny := B; attribute C : OclAny := C; operation initialise(reel_num : OclAny,A : OclAny,B : OclAny,C : OclAny) : SlotMachine pre: true post: true activity: self.reel_num := reel_num ; self.A := A ; self.B := B ; self.C := C; return self; operation calculate_random_num(random_num : OclAny) : OclAny pre: true post: true activity: random_num := (self.A * random_num + self.B) mod self.C ; return random_num; operation count_flame(condition_list : OclAny,random_num : OclAny) : OclAny pre: true post: true activity: var flame_num : int := 0 ; var order : int := 0 ; while (order->compareTo((condition_list)->size())) < 0 do ( Sequence{order,flame_num,random_num} := self.check_condition(condition_list, random_num, order, flame_num) ; if flame_num > 10001 then ( flame_num := -1 ; return flame_num ) else skip) ; return flame_num - 1; operation check_condition(condition_list : OclAny,random_num : OclAny,order : OclAny,flame_num : OclAny) : OclAny pre: true post: true activity: if random_num = condition_list[order+1] then ( order := order + 1 ) else skip ; random_num := self.calculate_random_num(random_num) ; flame_num := flame_num + 1 ; return order, flame_num, random_num; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( while true do ( data_list := get_data_list() ; reel_num := data_list->first() ; A := data_list[1+1] ; B := data_list[2+1] ; C := data_list[3+1] ; var first_num : OclAny := data_list[4+1] ; if reel_num = 0 then ( break ) else skip ; condition_list := get_data_list() ; var slot_machine : SlotMachine := (SlotMachine.newSlotMachine()).initialise(reel_num, A, B, C) ; flame_num := slot_machine.count_flame(condition_list, first_num) ; execute (flame_num)->display()) ) else skip; operation get_data_list() : OclAny pre: true post: true activity: var data_list : OclAny := input().split() ; for i : Integer.subrange(0, (data_list)->size()-1) do ( data_list[i+1] := ("" + ((data_list[i+1])))->toInteger()) ; return data_list; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque while 1 : n,a,b,c,x=map(int,input().split()) if n==0 and a==0 and b==0 and c==0 and x==0 : break y=list(map(int,input().split())) flame=0 ind=0 for i in range(10000+1): if x==y[ind]: ind+=1 if ind==n : break flame+=1 x=(a*x+b)% c if ind==n : print(flame) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while 1 do ( var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var x : OclAny := null; Sequence{n,a,b,c,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 & a = 0 & b = 0 & c = 0 & x = 0 then ( break ) else skip ; var y : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var flame : int := 0 ; var ind : int := 0 ; for i : Integer.subrange(0, 10000 + 1-1) do ( if x = y[ind+1] then ( ind := ind + 1 ) else skip ; if ind = n then ( break ) else skip ; flame := flame + 1 ; var x : int := (a * x + b) mod c) ; if ind = n then ( execute (flame)->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for e in iter(input,'0 0 0 0 0'): N,A,B,C,X=map(int,e.split()) Y=[*map(int,input().split())] lenY=len(Y) tgt=Y[0]==X cnt=0 while tgtcollect( _x | (OclType["int"])->apply(_x) ) ; var Y : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lenY : int := (Y)->size() ; var tgt : boolean := Y->first() = X ; var cnt : int := 0 ; while (tgt->compareTo(lenY)) < 0 & cnt < 10000 do ( cnt := cnt + 1 ; var X : int := (A * X + B) mod C ; tgt := tgt + Y[tgt+1] = X) ; execute (if tgt = lenY then cnt else -1 endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): while True : n,a,b,c,x=map(int,input().split()) if(n,a,b,c,x)==(0,0,0,0,0): return yy=list(map(int,input().split())) yi=0 for i in range(10002): if yi==len(yy): print(i-1) break elif i>10000 : print(-1) break if x==yy[yi]: yi+=1 x=(a*x+b)% c if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: while true do ( var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var x : OclAny := null; Sequence{n,a,b,c,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if Sequence{n, a, b, c, x} = Sequence{0, 0, 0, 0, 0} then ( return ) else skip ; var yy : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var yi : int := 0 ; for i : Integer.subrange(0, 10002-1) do ( if yi = (yy)->size() then ( execute (i - 1)->display() ; break ) else (if i > 10000 then ( execute (-1)->display() ; break ) else skip) ; if x = yy[yi+1] then ( yi := yi + 1 ) else skip ; var x : int := (a * x + b) mod c)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findAndPrintOriginalArray(arr,n): arr_sum=0 for i in range(0,n): arr_sum+=arr[i] arr_sum=int(arr_sum/(n-1)) for i in range(0,n): print((arr_sum-arr[i]),end=" ") arr=[10,14,12,13,11] n=len(arr) findAndPrintOriginalArray(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{10}->union(Sequence{14}->union(Sequence{12}->union(Sequence{13}->union(Sequence{ 11 })))) ; n := (arr)->size() ; findAndPrintOriginalArray(arr, n); operation findAndPrintOriginalArray(arr : OclAny, n : OclAny) pre: true post: true activity: var arr_sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( arr_sum := arr_sum + arr[i+1]) ; arr_sum := ("" + ((arr_sum / (n - 1))))->toInteger() ; for i : Integer.subrange(0, n-1) do ( execute ((arr_sum - arr[i+1]))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfDigits(a): sm=0 while(a!=0): sm=sm+a % 10 a=a//10 return sm def findMax(x): b=1 ans=x while(x!=0): cur=(x-1)*b+(b-1) if(sumOfDigits(cur)>sumOfDigits(ans)or(sumOfDigits(cur)==sumOfDigits(ans)and cur>ans)): ans=cur x=x//10 b=b*10 return ans n=521 print(findMax(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := 521 ; execute (findMax(n))->display(); operation sumOfDigits(a : OclAny) : OclAny pre: true post: true activity: var sm : int := 0 ; while (a /= 0) do ( sm := sm + a mod 10 ; a := a div 10) ; return sm; operation findMax(x : OclAny) : OclAny pre: true post: true activity: var b : int := 1 ; var ans : OclAny := x ; while (x /= 0) do ( var cur : double := (x - 1) * b + (b - 1) ; if ((sumOfDigits(cur)->compareTo(sumOfDigits(ans))) > 0 or (sumOfDigits(cur) = sumOfDigits(ans) & (cur->compareTo(ans)) > 0)) then ( ans := cur ) else skip ; x := x div 10 ; b := b * 10) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for j in range(int(input())): t=input() if t.count("1")==len(t)or t.count("0")==len(t): print(t) else : s="" for j in range(len(t)): s+="10" S="" for j in range((len(t))): S+="01" flag=0 flags=0 for j in range(len(s)): if flagtoInteger()-1) do ( var t : String := (OclFile["System.in"]).readLine() ; if t->count("1") = (t)->size() or t->count("0") = (t)->size() then ( execute (t)->display() ) else ( var s : String := "" ; for j : Integer.subrange(0, (t)->size()-1) do ( s := s + "10") ; var S : String := "" ; for j : Integer.subrange(0, ((t)->size())-1) do ( S := S + "01") ; var flag : int := 0 ; var flags : int := 0 ; for j : Integer.subrange(0, (s)->size()-1) do ( if (flag->compareTo((t)->size())) < 0 then ( if s[j+1] = t[flag+1] then ( flag := flag + 1 ) else skip ) else skip) ; for j : Integer.subrange(0, (S)->size()-1) do ( if (flags->compareTo((t)->size())) < 0 then ( if S[j+1] = t[flags+1] then ( flags := flags + 1 ) else skip ) else skip) ; if flag = (t)->size() then ( execute (s)->display() ) else ( execute (S)->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for p in range(int(input())): t=str(input()) n,l=len(t),['1','0'] if(n<=2): s=t else : s=''+t[0] c=t.count('1') d=t.count('0') if(c==n or d==n): s=t else : for i in range(1,n): if(t[i]==s[-1]): s+=l[int(t[i])] s+=t[i] print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for p : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var t : String := ("" + (((OclFile["System.in"]).readLine()))) ; var n : OclAny := null; var l : OclAny := null; Sequence{n,l} := Sequence{(t)->size(),Sequence{'1'}->union(Sequence{ '0' })} ; if (n <= 2) then ( var s : String := t ) else ( s := '' + t->first() ; var c : int := t->count('1') ; var d : int := t->count('0') ; if (c = n or d = n) then ( s := t ) else ( for i : Integer.subrange(1, n-1) do ( if (t[i+1] = s->last()) then ( s := s + l[("" + ((t[i+1])))->toInteger()+1] ) else skip ; s := s + t[i+1]) ) ) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : s=input() new_s="" turn=1 for i in range(len(s)): if turn==1 : if s[i]=="a" : new_s+="b" elif s[i]!="a" : new_s+="a" turn=2 elif turn==2 : if s[i]=="z" : new_s+="y" elif s[i]!="z" : new_s+="z" turn=1 print(new_s) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( var s : String := (OclFile["System.in"]).readLine() ; var new_s : String := "" ; var turn : int := 1 ; for i : Integer.subrange(0, (s)->size()-1) do ( if turn = 1 then ( if s[i+1] = "a" then ( new_s := new_s + "b" ) else (if s[i+1] /= "a" then ( new_s := new_s + "a" ) else skip) ; turn := 2 ) else (if turn = 2 then ( if s[i+1] = "z" then ( new_s := new_s + "y" ) else (if s[i+1] /= "z" then ( new_s := new_s + "z" ) else skip) ; turn := 1 ) else skip)) ; execute (new_s)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() for _ in ""*int(input()): a=input(); print("".join(set(a))*len(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; for _anon : StringLib.nCopies("", ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var a : String := (OclFile["System.in"]).readLine(); execute (StringLib.sumStringsWithSeparator((Set{}->union((a))), "") * (a)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def longSubarrWthSumDivByK(arr,n,k): um={i : 0 for i in range(8)} mod_arr=[0 for i in range(n)] max=0 curr_sum=0 for i in range(n): curr_sum+=arr[i] mod_arr[i]=((curr_sum % k)+k)% k for i in range(n): if(mod_arr[i]==0): max=i+1 elif(mod_arr[i]in um): um[mod_arr[i]]=i else : if(max<(i-um[mod_arr[i]])): max=i-um[mod_arr[i]] return max if __name__=='__main__' : arr=[2,7,6,1,4,5] n=len(arr) k=3 print("Length=",longSubarrWthSumDivByK(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{2}->union(Sequence{7}->union(Sequence{6}->union(Sequence{1}->union(Sequence{4}->union(Sequence{ 5 }))))) ; n := (arr)->size() ; k := 3 ; execute ("Length=")->display() ) else skip; operation longSubarrWthSumDivByK(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var um : Map := Integer.subrange(0, 8-1)->select(i | true)->collect(i | Map{i |-> 0})->unionAll() ; var mod_arr : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var max : int := 0 ; var curr_sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( curr_sum := curr_sum + arr[i+1] ; mod_arr[i+1] := ((curr_sum mod k) + k) mod k) ; for i : Integer.subrange(0, n-1) do ( if (mod_arr[i+1] = 0) then ( max := i + 1 ) else (if ((um)->includes(mod_arr[i+1])) then ( um[mod_arr[i+1]+1] := i ) else ( if ((max->compareTo((i - um[mod_arr[i+1]+1]))) < 0) then ( max := i - um[mod_arr[i+1]+1] ) else skip ) ) ) ; return max; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- alter="10" for _ in range(int(input())): a=[i for i in input()] l=[] if("0" in a)and("1" in a): print(alter*len(a)) else : print(a[0]*len(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var alter : String := "10" ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : Sequence := (OclFile["System.in"]).readLine()->select(i | true)->collect(i | (i)) ; var l : Sequence := Sequence{} ; if ((a)->includes("0")) & ((a)->includes("1")) then ( execute (StringLib.nCopies(alter, (a)->size()))->display() ) else ( execute (a->first() * (a)->size())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lst_a=list(map(int,input().split())) for index in range(n-1): print(lst_a[index]+lst_a[index+1],end=" ") print(lst_a[n-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst_a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for index : Integer.subrange(0, n - 1-1) do ( execute (lst_a[index+1] + lst_a[index + 1+1])->display()) ; execute (lst_a[n - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) b=[None]*len(a) for i in range(len(a)-1,-1,-1): if i==len(a)-1 : b[i]=a[i] else : b[i]=a[i]+a[i+1] print(" ".join(str(n)for n in b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (a)->size()) ; for i : Integer.subrange(-1 + 1, (a)->size() - 1)->reverse() do ( if i = (a)->size() - 1 then ( b[i+1] := a[i+1] ) else ( b[i+1] := a[i+1] + a[i + 1+1] )) ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name b)))))))), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[*map(int,input().split())]+[0] print(*[*(l[i]+l[i+1]for i in range(n))]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->union(Sequence{ 0 }) ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (star_expr * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) ))))) ])))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() s=[*map(int,input().split()),0] print(*[*(x+y for x,y in zip(s,s[1 :]))]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var s : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->union(Sequence{ 0 }) ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (star_expr * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (name y))))))) (comp_for for (exprlist (expr (atom (name x))) , (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s))))))) , (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))))))) )))))))) ))))) ])))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split()))[: n] l1=[] for i in range(n-1): k=l[i]+l[i+1] l1.append(k) l1.append(l[-1]) for i in l1 : print(i,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ; var l1 : Sequence := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( var k : OclAny := l[i+1] + l[i + 1+1] ; execute ((k) : l1)) ; execute ((l->last()) : l1) ; for i : l1 do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _len=int(input()) _str=input().replace('(',')!').split(')') _str=list(filter(None,_str)) mxLen,wordsNum=0,0 for word in _str : if word[0]=='!' : words=word[1 :].split('_') words=list(filter(None,words)) wordsNum+=len(words) else : words=word.split('_') mxLen=max(mxLen,len(max(words,key=len))) print(mxLen,wordsNum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _len : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var _str : OclAny := input().replace('(', ')!').split(')') ; _str := ((_str)->select( _x | (null)->apply(_x) = true )) ; var mxLen : OclAny := null; var wordsNum : OclAny := null; Sequence{mxLen,wordsNum} := Sequence{0,0} ; for word : _str do ( if word->first() = '!' then ( var words : OclAny := word->tail().split('_') ; words := ((words)->select( _x | (null)->apply(_x) = true )) ; wordsNum := wordsNum + (words)->size() ) else ( words := word.split('_') ; var mxLen : OclAny := Set{mxLen, (Set{words, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name len)))))))}->max())->size()}->max() )) ; execute (mxLen)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- g=int(input()) n=input() l=[] l2=[] s=0 m=list(n.split('(')) count=0 max_count=0 count1=0 a=0 st1='' st=[] for item in m : if(')' in item): for a in item.split(')'): l.append(a) else : l.append(item) for i in range(len(n)): if(n[i]=='('): j=i+1 while(n[j]!=')'): st1=st1+n[j] j=j+1 l2.append(st1) st1='' for item in l : if item in l2 : l.remove(item) for item in l : for ch in item : if ch!='_' : count=count+1 else : if(count>=max_count): max_count=count count=0 if(count>=max_count): max_count=count count=0 for item in l2 : if('_' in item): for i in range(len(item)): if(item[i]!='_' and item[i]!=''): s=s+1 if(s==1): count1=count1+1 elif(item[i]=='_'): s=0 s=0 elif(('_' not in item or '' not in item)and len(item)!=0): count1=count1+1 print(max_count,count1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var g : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : String := (OclFile["System.in"]).readLine() ; var l : Sequence := Sequence{} ; var l2 : Sequence := Sequence{} ; var s : int := 0 ; var m : Sequence := (n.split('(')) ; var count : int := 0 ; var max_count : int := 0 ; var count1 : int := 0 ; var a : int := 0 ; var st1 : String := '' ; var st : Sequence := Sequence{} ; for item : m do ( if ((item)->includes(')')) then ( for a : item.split(')') do ( execute ((a) : l)) ) else ( execute ((item) : l) )) ; for i : Integer.subrange(0, (n)->size()-1) do ( if (n[i+1] = '(') then ( var j : OclAny := i + 1 ; while (n[j+1] /= ')') do ( st1 := st1 + n[j+1] ; j := j + 1) ; execute ((st1) : l2) ; st1 := '' ) else skip) ; for item : l do ( if (l2)->includes(item) then ( execute ((item) /: l) ) else skip) ; for item : l do ( for ch : item do ( if ch /= '_' then ( count := count + 1 ) else ( if ((count->compareTo(max_count)) >= 0) then ( max_count := count ) else skip ; count := 0 )) ; if ((count->compareTo(max_count)) >= 0) then ( max_count := count ) else skip ; count := 0) ; for item : l2 do ( if ((item)->includes('_')) then ( for i : Integer.subrange(0, (item)->size()-1) do ( if (item[i+1] /= '_' & item[i+1] /= '') then ( s := s + 1 ; if (s = 1) then ( count1 := count1 + 1 ) else skip ) else (if (item[i+1] = '_') then ( s := 0 ) else skip)) ; s := 0 ) else (if (((item)->excludes('_') or (item)->excludes('')) & (item)->size() /= 0) then ( count1 := count1 + 1 ) else skip)) ; execute (max_count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(temperatures,clothes): points=[[]for _ in range(len(temperatures))] for i,t in enumerate(temperatures): for c in clothes : if c[0]<=t<=c[1]: points[i].append(c[-1]) points[i].sort() dp=[[min(points[0]),0],[max(points[0]),0]] for p in points[1 :]: dp=[[min(p),max(dp[0][1]+abs(min(p)-dp[0][0]),dp[1][1]+abs(min(p)-dp[1][0]))],[max(p),max(dp[0][1]+abs(max(p)-dp[0][0]),dp[1][1]+abs(max(p)-dp[1][0]))]] return max(dp[0][1],dp[1][1]) def main(args): d,n=map(int,input().split()) temperatures=[int(input())for _ in range(d)] clothes=[[int(x)for x in input().split()]for _ in range(n)] ans=solve(temperatures,clothes) print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(temperatures : OclAny, clothes : OclAny) : OclAny pre: true post: true activity: var points : Sequence := Integer.subrange(0, (temperatures)->size()-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _tuple : Integer.subrange(1, (temperatures)->size())->collect( _indx | Sequence{_indx-1, (temperatures)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); for c : clothes do ( if (c->first()->compareTo(t)) <= 0 & (t <= c[1+1]) then ( (expr (atom (name points)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))))) )))) ) else skip) ; (expr (atom (name points)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name sort) (arguments ( ))))) ; var dp : Sequence := Sequence{Sequence{(points->first())->min()}->union(Sequence{ 0 })}->union(Sequence{ Sequence{(points->first())->max()}->union(Sequence{ 0 }) }) ; for p : points->tail() do ( dp := Sequence{Sequence{(p)->min()}->union(Sequence{ Set{dp->first()[1+1] + ((p)->min() - dp->first()->first())->abs(), dp[1+1][1+1] + ((p)->min() - dp[1+1]->first())->abs()}->max() })}->union(Sequence{ Sequence{(p)->max()}->union(Sequence{ Set{dp->first()[1+1] + ((p)->max() - dp->first()->first())->abs(), dp[1+1][1+1] + ((p)->max() - dp[1+1]->first())->abs()}->max() }) })) ; return Set{dp->first()[1+1], dp[1+1][1+1]}->max(); operation main(args : OclAny) pre: true post: true activity: var d : OclAny := null; var n : OclAny := null; Sequence{d,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; temperatures := Integer.subrange(0, d-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; clothes := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))) ; var ans : OclAny := solve(temperatures, clothes) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): s=input() c=[] for i in range(len(s)): if i % 2==0 : if s[i]=='a' : c.append('b') else : c.append('a') else : if s[i]=='z' : c.append('y') else : c.append('z') print("".join(c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var c : Sequence := Sequence{} ; for i : Integer.subrange(0, (s)->size()-1) do ( if i mod 2 = 0 then ( if s[i+1] = 'a' then ( execute (('b') : c) ) else ( execute (('a') : c) ) ) else ( if s[i+1] = 'z' then ( execute (('y') : c) ) else ( execute (('z') : c) ) )) ; execute (StringLib.sumStringsWithSeparator((c), ""))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=[ele for ele in input()] arr,ans=[[]],[[]] c=0 for i in range(n): if s[i]=="_" : if c==0 : ans.append([]) else : arr.append([]) elif s[i]=="(" : arr.append([]); ans.append([]); c=1 elif s[i]==")" : c=0 else : if c==0 : ans[-1].append(s[i]) else : arr[-1].append(s[i]) m,count=0,0 for l in ans : m=max(m,len(l)) for el in arr : if len(el)>0 : c+=1 print(m,c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := (OclFile["System.in"]).readLine()->select(ele | true)->collect(ele | (ele)) ; var arr : OclAny := null; var ans : OclAny := null; Sequence{arr,ans} := Sequence{Sequence{ Sequence{} },Sequence{ Sequence{} }} ; var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = "_" then ( if c = 0 then ( execute ((Sequence{}) : ans) ) else ( execute ((Sequence{}) : arr) ) ) else (if s[i+1] = "(" then ( execute ((Sequence{}) : arr); execute ((Sequence{}) : ans); c := 1 ) else (if s[i+1] = ")" then ( c := 0 ) else ( if c = 0 then ( (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))) ) else ( (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))) ) ) ) ) ) ; var m : OclAny := null; var count : OclAny := null; Sequence{m,count} := Sequence{0,0} ; for l : ans do ( var m : OclAny := Set{m, (l)->size()}->max()) ; for el : arr do ( if (el)->size() > 0 then ( c := c + 1 ) else skip) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import io,os,sys input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline import re def solve(): n=int(input()) s=input().strip().decode() ans=len(re.findall(r'[a-zA-Z]+',s)) while '(' in s : s=s[: s.index('(')]+'_'+s[s.index(')')+1 :] tmp=len(re.findall(r'[a-zA-Z]+',s)) ans-=tmp if tmp : ans2=max(0,*[len(x)for x in re.findall(r'[a-zA-Z]+',s)]) else : ans2=0 sys.stdout.write(f'{ans2}{ans}\n') if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; skip ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := input()->trim().decode() ; var ans : int := ((s)->allMatches(StringLib.rawString('[a-zA-Z]+')))->size() ; while (s)->includes('(') do ( s := s.subrange(1,s->indexOf('(') - 1) + '_' + s.subrange(s->indexOf(')') - 1 + 1+1)) ; var tmp : int := ((s)->allMatches(StringLib.rawString('[a-zA-Z]+')))->size() ; ans := ans - tmp ; if tmp then ( var ans2 : OclAny := Set{0, (argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name re)) (trailer . (name findall) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom r '[a-zA-Z]+')))))) , (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))))))) ]))))))}->max() ) else ( ans2 := 0 ) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom f '{ans2}{ans} '))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k,x=map(int,input().split()); print(" ".join([str(x)for x in list(range(x-k+1,x))+list(range(x,x+k))])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : OclAny := null; var x : OclAny := null; Sequence{k,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); execute (StringLib.sumStringsWithSeparator(((Integer.subrange(x - k + 1, x-1))->union((Integer.subrange(x, x + k-1)))->select(x | true)->collect(x | (("" + ((x)))))), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _=input() s=input() s=s.replace('(','_(_') s=s.replace(')','_)_') r=s.split('_') r=' '.join([x for x in r if len(x)>0]) pairs=[] while r.find('(')!=-1 : start=r.find('(') end=r.find(')') pairs.append(r[start : end+1]) r=r[: start]+r[end+1 :] mx_len=max(len(x)for x in r.split(' ')) count=sum(len(x.split())-2 for x in pairs) print(mx_len,count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _anon : String := (OclFile["System.in"]).readLine() ; var s : String := (OclFile["System.in"]).readLine() ; s := s.replace('(', '_(_') ; s := s.replace(')', '_)_') ; var r : OclAny := s.split('_') ; r := StringLib.sumStringsWithSeparator((r->select(x | (x)->size() > 0)->collect(x | (x))), ' ') ; var pairs : Sequence := Sequence{} ; while r->indexOf('(') - 1 /= -1 do ( var start : String := r->indexOf('(') - 1 ; var end : String := r->indexOf(')') - 1 ; execute ((r.subrange(start+1, end + 1)) : pairs) ; r := r.subrange(1,start) + r.subrange(end + 1+1)) ; var mx_len : OclAny := ((argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name r)) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ' '))))))) )))))))))->max() ; var count : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)) (trailer . (name split) (arguments ( ))))))))) )))) - (expr (atom (number (integer 2)))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name pairs))))))))->sum() ; execute (mx_len)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def largestPrimeFactor(n): max=-1 while n % 2==0 : max=2 ; n>>=1 ; for i in range(3,int(sqrt(n))+1,2): while n % i==0 : max=i ; n=n/i ; if n>2 : max=n return max def checkUnusual(n): factor=largestPrimeFactor(n) if factor>sqrt(n): return True else : return False if __name__=='__main__' : n=14 if checkUnusual(n): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( n := 14 ; if checkUnusual(n) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; operation largestPrimeFactor(n : OclAny) : OclAny pre: true post: true activity: var max : int := -1 ; while n mod 2 = 0 do ( max := 2; ; n := n div (2->pow(1));) ; for i : Integer.subrange(3, ("" + ((sqrt(n))))->toInteger() + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( while n mod i = 0 do ( max := i; ; n := n / i;)) ; if n > 2 then ( max := n ) else skip ; return max; operation checkUnusual(n : OclAny) : OclAny pre: true post: true activity: var factor : OclAny := largestPrimeFactor(n) ; if (factor->compareTo(sqrt(n))) > 0 then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=[0]*(n+1); b=[int(input())for _ in range(m)] for x in b[: :-1]: if a[x]==0 : a[x]=1 ; print(x) [print(i)for i in range(1,n+1)if a[i]==0] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); ; var b : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; for x : b(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if a[x+1] = 0 then ( a[x+1] := 1; execute (x)->display() ) else skip) ; ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] while True : n,m=LI() a=[I()for _ in range(m)][: :-1] f=[None]*(n+1) for c in a : if f[c]is None : f[c]=1 rr.append(c) for c in range(1,n+1): if f[c]is None : rr.append(c) break return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := LI() ; var a : OclAny := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (I()))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var f : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (n + 1)) ; for c : a do ( if f[c+1] <>= null then ( f[c+1] := 1 ; execute ((c) : rr) ) else skip) ; for c : Integer.subrange(1, n + 1-1) do ( if f[c+1] <>= null then ( execute ((c) : rr) ) else skip) ; break) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(i)for i in input().split()] INIT=True table=[INIT]*n lis=[] for i in range(m): num=int(input()) lis.append(num) for i in lis[: :-1]: if table[i-1]: print(i) table[i-1]=False for i in range(n): if table[i]: print(i+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var INIT : boolean := true ; var table : Sequence := MatrixLib.elementwiseMult(Sequence{ INIT }, n) ; var lis : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((num) : lis)) ; for i : lis(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if table[i - 1+1] then ( execute (i)->display() ) else skip ; table[i - 1+1] := false) ; for i : Integer.subrange(0, n-1) do ( if table[i+1] then ( execute (i + 1)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import deque input=lambda : sys.stdin.readline()[:-1] sys.setrecursionlimit(10**8) inf=float('inf') mod=10**9+7 ans=deque() used=[0]*(10**6) n,m=map(int,input().split()) data=reversed([int(input())for i in range(m)]) for di in data : if not used[di]: ans.append(di) used[di]=1 plusans=[i for i in range(1,n+1)if not used[i]] ans+=plusans for i in ans : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine()->front()) ; sys.setrecursionlimit((10)->pow(8)) ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var ans : Sequence := () ; var used : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((10)->pow(6))) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var data : Sequence := (Integer.subrange(0, m-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())))->reverse() ; for di : data do ( if not(used[di+1]) then ( execute ((di) : ans) ) else skip ; used[di+1] := 1) ; var plusans : Sequence := Integer.subrange(1, n + 1-1)->select(i | not(used[i+1]))->collect(i | (i)) ; ans := ans + plusans ; for i : ans do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) used=[1]+[0]*N src=[int(input())for i in range(M)] for v in reversed(src): if used[v]: continue print(v) used[v]=1 for v,u in enumerate(used): if not u : print(v) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var used : Sequence := Sequence{ 1 }->union(MatrixLib.elementwiseMult(Sequence{ 0 }, N)) ; var src : Sequence := Integer.subrange(0, M-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; for v : (src)->reverse() do ( if used[v+1] then ( continue ) else skip ; execute (v)->display() ; used[v+1] := 1) ; for _tuple : Integer.subrange(1, (used)->size())->collect( _indx | Sequence{_indx-1, (used)->at(_indx)} ) do (var _indx : int := 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var u : OclAny := _tuple->at(_indx); if not(u) then ( execute (v)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMinimumSubsequences(A,B): numberOfSubsequences=1 sizeOfB=len(B) sizeOfA=len(A) inf=1000000 next=[[inf for i in range(sizeOfB)]for i in range(26)] for i in range(sizeOfB): next[ord(B[i])-ord('a')][i]=i for i in range(26): for j in range(sizeOfB-2,-1,-1): if(next[i][j]==inf): next[i][j]=next[i][j+1] pos=0 i=0 while(idisplay() ) else skip; operation findMinimumSubsequences(A : OclAny, B : OclAny) : OclAny pre: true post: true activity: var numberOfSubsequences : int := 1 ; var sizeOfB : int := (B)->size() ; var sizeOfA : int := (A)->size() ; var Math_PINFINITY : int := 1000000 ; var next : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | (Integer.subrange(0, sizeOfB-1)->select(i | true)->collect(i | (Math_PINFINITY)))) ; for i : Integer.subrange(0, sizeOfB-1) do ( next[(B[i+1])->char2byte() - ('a')->char2byte()+1][i+1] := i) ; for i : Integer.subrange(0, 26-1) do ( for j : Integer.subrange(-1 + 1, sizeOfB - 2)->reverse() do ( if (next[i+1][j+1] = Math_PINFINITY) then ( next[i+1][j+1] := next[i+1][j + 1+1] ) else skip)) ; var pos : int := 0 ; var i : int := 0 ; while ((i->compareTo(sizeOfA)) < 0) do ( if (pos = 0 & next[(A[i+1])->char2byte() - ('a')->char2byte()+1][pos+1] = Math_PINFINITY) then ( numberOfSubsequences := -1 ; break ) else (if ((pos->compareTo(sizeOfB)) < 0 & (next[(A[i+1])->char2byte() - ('a')->char2byte()+1][pos+1]->compareTo(Math_PINFINITY)) < 0) then ( var nextIndex : OclAny := next[(A[i+1])->char2byte() - ('a')->char2byte()+1][pos+1] + 1 ; pos := nextIndex ; i := i + 1 ) else ( numberOfSubsequences := numberOfSubsequences + 1 ; pos := 0 ) ) ) ; return numberOfSubsequences; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(sr,w,a,b,p): count=0 while w!=len(sr)-1 : if sr[w]=="A" and w!=len(sr)-1 : count+=a while w!=len(sr)-1 and sr[w]=="A" : w+=1 if s[w]=="B" and w!=len(sr)-1 : count+=b while w!=len(sr)-1 and s[w]=="B" : w+=1 return count>p for _ in range(int(input())): a,b,p=map(int,input().split()) s=input() l=-1 r=len(s) while r-l>1 : m=(r+l)//2 if check(s,m,a,b,p): l=m else : r=m print(r+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( Sequence{a,b,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var l : int := -1 ; var r : int := (s)->size() ; while r - l > 1 do ( var m : int := (r + l) div 2 ; if check(s, m, a, b, p) then ( l := m ) else ( r := m )) ; execute (r + 1)->display()); operation check(sr : OclAny, w : OclAny, a : OclAny, b : OclAny, p : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while w /= (sr)->size() - 1 do ( if sr[w+1] = "A" & w /= (sr)->size() - 1 then ( count := count + a ; while w /= (sr)->size() - 1 & sr[w+1] = "A" do ( w := w + 1) ) else skip ; if s[w+1] = "B" & w /= (sr)->size() - 1 then ( count := count + b ; while w /= (sr)->size() - 1 & s[w+1] = "B" do ( w := w + 1) ) else skip) ; return (count->compareTo(p)) > 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for tc in range(t): a,b,p=list(map(int,input().split())) s=input() result=len(s) for i in range(len(s)-2,-1,-1): if(i==0 or(s[i]!=s[i-1])): cost=a if(s[i]=='A')else b if(cost>p): break else : p=p-cost result=i+1 print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for tc : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var p : OclAny := null; Sequence{a,b,p} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : String := (OclFile["System.in"]).readLine() ; var result : int := (s)->size() ; for i : Integer.subrange(-1 + 1, (s)->size() - 2)->reverse() do ( if (i = 0 or (s[i+1] /= s[i - 1+1])) then ( var cost : OclAny := if (s[i+1] = 'A') then a else b endif ; if ((cost->compareTo(p)) > 0) then ( break ) else ( var p : double := p - cost ; result := i + 1 ) ) else skip) ; execute (result)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for tt in range(t): a,b,p=map(int,input().split()) s=input() cs={'A' : a,'B' : b} c=0 i=len(s)-1 while i>0 and c+cs[s[i-1]]<=p : c+=cs[s[i-1]] i-=1 while i>0 and s[i-1]==s[i]: i-=1 print(i+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for tt : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var p : OclAny := null; Sequence{a,b,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var cs : Map := Map{ 'A' |-> a }->union(Map{ 'B' |-> b }) ; var c : int := 0 ; var i : double := (s)->size() - 1 ; while i > 0 & (c + cs[s[i - 1+1]+1]->compareTo(p)) <= 0 do ( c := c + cs[s[i - 1+1]+1] ; i := i - 1 ; while i > 0 & s[i - 1+1] = s[i+1] do ( i := i - 1)) ; execute (i + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heapify,heappop,heappush from operator import add SENTINEL=100000 while True : n,m,s,g1,g2=map(int,input().split()) s-=1 g1-=1 g2-=1 if not n : break pipes=[set()for _ in range(n)] rpipes=[set()for _ in range(n)] for _ in range(m): b1,b2,c=map(int,input().split()) b1-=1 b2-=1 pipes[b1].add((c,b2)) rpipes[b2].add((c,b1)) dists=[[SENTINEL]*n for _ in range(2)] for i in(0,1): g=(g1,g2)[i] dist=dists[i] dist[g]=0 queue=list(rpipes[g]) heapify(queue) while queue : total_cost,base=heappop(queue) if dist[base]collect( _x | (OclType["int"])->apply(_x) ) ; s := s - 1 ; g1 := g1 - 1 ; g2 := g2 - 1 ; if not(n) then ( break ) else skip ; var pipes : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; var rpipes : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; for _anon : Integer.subrange(0, m-1) do ( var b1 : OclAny := null; var b2 : OclAny := null; var c : OclAny := null; Sequence{b1,b2,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; b1 := b1 - 1 ; b2 := b2 - 1 ; (expr (atom (name pipes)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b1)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name c)))))) , (test (logical_test (comparison (expr (atom (name b2))))))) )))))))) )))) ; (expr (atom (name rpipes)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b2)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name c)))))) , (test (logical_test (comparison (expr (atom (name b1))))))) )))))))) ))))) ; var dists : Sequence := Integer.subrange(0, 2-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ SENTINEL }, n))) ; for i : Sequence{0, 1} do ( var g : OclAny := Sequence{g1, g2}[i+1] ; var dist : OclAny := dists[i+1] ; dist[g+1] := 0 ; var queue : Sequence := (rpipes[g+1]) ; heapify(queue) ; while queue do ( var total_cost : OclAny := null; var base : OclAny := null; Sequence{total_cost,base} := heappop(queue) ; if (dist[base+1]->compareTo(SENTINEL)) < 0 then ( continue ) else skip ; dist[base+1] := total_cost ; for _tuple : rpipes[base+1] do (var _indx : int := 1; var next_cost : OclAny := _tuple->at(_indx); _indx := _indx + 1; var next_base : OclAny := _tuple->at(_indx); if dist[next_base+1] = SENTINEL then ( heappush(queue, Sequence{total_cost + next_cost, next_base}) ) else skip))) ; dists := (((argument * (test (logical_test (comparison (expr (atom (name dists))))))))->collect( _x | (add)->apply(_x) )) ; var current_best : OclAny := dists[s+1] ; queue := (pipes[s+1]) ; heapify(queue) ; var visited : Set := Set{ s } ; while queue do ( var total_cost : OclAny := null; var base : OclAny := null; Sequence{total_cost,base} := heappop(queue) ; if (visited)->includes(base) then ( continue ) else skip ; execute ((base) : visited) ; current_best := Set{current_best, total_cost + dists[base+1]}->min() ; for _tuple : pipes[base+1] do (var _indx : int := 1; var next_cost : OclAny := _tuple->at(_indx); _indx := _indx + 1; var next_base : OclAny := _tuple->at(_indx); if (visited)->excludes(next_base) then ( heappush(queue, Sequence{total_cost + next_cost, next_base}) ) else skip)) ; execute (current_best)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(K : int,X : int): res=[X] for i in range(X+1,X+K): res.append(i) for i in range(X-1,X-K,-1): res.append(i) for i,x in enumerate(sorted(res)): print(x,end='') if not res.__len__()==i+1 : print(end=' ') return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() K=int(next(tokens)) X=int(next(tokens)) solve(K,X) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(K : int, X : int) pre: true post: true activity: var res : Sequence := Sequence{ X } ; for i : Integer.subrange(X + 1, X + K-1) do ( execute ((i) : res)) ; for i : Integer.subrange(X - K + 1, X - 1)->reverse() do ( execute ((i) : res)) ; for _tuple : Integer.subrange(1, (res->sort())->size())->collect( _indx | Sequence{_indx-1, (res->sort())->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); execute (x)->display() ; if not(res.__len__() = i + 1) then ( execute ((argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom ' ')))))))->display() ) else skip) ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var K : int := ("" + (((tokens).next())))->toInteger() ; var X : int := ("" + (((tokens).next())))->toInteger() ; solve(K, X); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def bfs(s): q=deque() q.append(s) dist=[inf]*(n+1) dist[s]=0 ans0=n while q : i=q.popleft() di=dist[i] if di>p : return ans0 ans0=min(ans0,i) for j,c in G[i]: dist[j]=di+c q.append(j) return ans0 t=int(input()) ans=[] inf=pow(10,9)+1 for _ in range(t): a,b,p=map(int,input().split()) s=list(input().rstrip()) n=len(s) x=0 y=[] for i in range(n): if x ^ s[i]: x=s[i] y.append(i+1) if y[-1]^ n : y.append(n) G=[[]for _ in range(n+1)] for i in range(len(y)-1): k=y[i] c=a if s[k-1]& 1 else b for j in range(y[i]+1,y[i+1]+1): G[j].append((k,c)) ans0=bfs(n) ans.append(ans0) sys.stdout.write("\n".join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; var Math_PINFINITY : double := (10)->pow(9) + 1 ; for _anon : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var p : OclAny := null; Sequence{a,b,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; s := (input().rstrip()) ; var n : int := (s)->size() ; var x : int := 0 ; var y : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if MathLib.bitwiseXor(x, s[i+1]) then ( x := s[i+1] ; execute ((i + 1) : y) ) else skip) ; if MathLib.bitwiseXor(y->last(), n) then ( execute ((n) : y) ) else skip ; var G : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, (y)->size() - 1-1) do ( var k : OclAny := y[i+1] ; var c : OclAny := if MathLib.bitwiseAnd(s[k - 1+1], 1) then a else b endif ; for j : Integer.subrange(y[i+1] + 1, y[i + 1+1] + 1-1) do ((expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name k)))))) , (test (logical_test (comparison (expr (atom (name c))))))) )))))))) )))))) ; ans0 := bfs(n) ; execute ((ans0) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))))))) )))); operation bfs(s : OclAny) : OclAny pre: true post: true activity: var q : Sequence := () ; execute ((s) : q) ; var dist : Sequence := MatrixLib.elementwiseMult(Sequence{ Math_PINFINITY }, (n + 1)) ; dist[s+1] := 0 ; var ans0 : OclAny := n ; while q do ( var i : OclAny := q->first() ; q := q->tail() ; var di : OclAny := dist[i+1] ; if (di->compareTo(p)) > 0 then ( return ans0 ) else skip ; ans0 := Set{ans0, i}->min() ; for _tuple : G[i+1] do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); dist[j+1] := di + c ; execute ((j) : q))) ; return ans0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(a==b): return a if(a==0): return b if(b==0): return a if((~ a & 1)==1): if((b & 1)==1): return gcd(a>>1,b) else : return(gcd(a>>1,b>>1)<<1) if((~ b & 1)==1): return gcd(a,b>>1) if(a>b): return gcd((a-b)>>1,b) return gcd((b-a)>>1,a) a,b=34,17 print("Gcd of given numbers is ",gcd(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{a,b} := Sequence{34,17} ; execute ("Gcd of given numbers is ")->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = b) then ( return a ) else skip ; if (a = 0) then ( return b ) else skip ; if (b = 0) then ( return a ) else skip ; if ((MathLib.bitwiseAnd(MathLib.bitwiseNot(a), 1)) = 1) then ( if ((MathLib.bitwiseAnd(b, 1)) = 1) then ( return gcd(a /(2->pow(1)), b) ) else ( return (gcd(a /(2->pow(1)), b /(2->pow(1))) * (2->pow(1))) ) ) else skip ; if ((MathLib.bitwiseAnd(MathLib.bitwiseNot(b), 1)) = 1) then ( return gcd(a, b /(2->pow(1))) ) else skip ; if ((a->compareTo(b)) > 0) then ( return gcd((a - b) /(2->pow(1)), b) ) else skip ; return gcd((b - a) /(2->pow(1)), a); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(a==0): return b if(b==0): return a k=0 while(((a | b)& 1)==0): a=a>>1 b=b>>1 k=k+1 while((a & 1)==0): a=a>>1 while(b!=0): while((b & 1)==0): b=b>>1 if(a>b): temp=a a=b b=temp b=(b-a) return(a<display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0) then ( return b ) else skip ; if (b = 0) then ( return a ) else skip ; var k : int := 0 ; while ((MathLib.bitwiseAnd((MathLib.bitwiseOr(a, b)), 1)) = 0) do ( a := a /(2->pow(1)) ; b := b /(2->pow(1)) ; k := k + 1) ; while ((MathLib.bitwiseAnd(a, 1)) = 0) do ( a := a /(2->pow(1))) ; while (b /= 0) do ( while ((MathLib.bitwiseAnd(b, 1)) = 0) do ( b := b /(2->pow(1))) ; if ((a->compareTo(b)) > 0) then ( var temp : OclAny := a ; a := b ; b := temp ) else skip ; b := (b - a)) ; return (a * (2->pow(k))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): s=int(input()) t=0 while(s>=10): r=s % 10 t+=s-r s=s//10+r print(t+s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : int := 0 ; while (s >= 10) do ( var r : int := s mod 10 ; t := t + s - r ; s := s div 10 + r) ; execute (t + s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): print(int(int(input())//0.9)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (("" + ((("" + (((OclFile["System.in"]).readLine())))->toInteger() div 0.9)))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n,m=map(int,input().split()) d=[] for i in range(n): for j in range(m): d.append(max(i,n-1-i)+max(j,m-1-j)) d.sort() print(' '.join(map(str,d))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( execute ((Set{i, n - 1 - i}->max() + Set{j, m - 1 - j}->max()) : d))) ; d := d->sort() ; execute (StringLib.sumStringsWithSeparator(((d)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque,defaultdict,Counter from heapq import heappush,heappop,heapify from math import inf,sqrt,ceil from functools import lru_cache from itertools import accumulate,combinations,permutations,product from typing import List from bisect import bisect_left,bisect_right import sys input=lambda : sys.stdin.readline().strip('\n') mis=lambda : map(int,input().split()) ii=lambda : int(input()) T=ii() for _ in range(T): S=ii() ans=0 while S>=10 : div=(S//10)*10 ans+=div S=S-div+S//10 ans+=S print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine()->trim()) ; var mis : Function := lambda $$ : OclAny in ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ii : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var T : OclAny := ii->apply() ; for _anon : Integer.subrange(0, T-1) do ( var S : OclAny := ii->apply() ; var ans : int := 0 ; while S >= 10 do ( var div : int := (S div 10) * 10 ; ans := ans + div ; S := S - div + S div 10) ; ans := ans + S ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) ans=0 while n>=10 : ans+=(n-n % 10) n=n//10+n % 10 print(ans+n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; while n >= 10 do ( ans := ans + (n - n mod 10) ; n := n div 10 + n mod 10) ; execute (ans + n)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) ans=0 while n>0 : if n>=10 : val=n//10 n=n-val*10 ans+=val*10 n=n+val else : ans+=n n=0 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; while n > 0 do ( if n >= 10 then ( var val : int := n div 10 ; n := n - val * 10 ; ans := ans + val * 10 ; n := n + val ) else ( ans := ans + n ; n := 0 )) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def toDecimal(binary,i=0): n=len(binary) if(i==n-1): return int(binary[i])-0 return(((int(binary[i])-0)<<(n-i-1))+toDecimal(binary,i+1)) if __name__=="__main__" : binary="1010" print(toDecimal(binary)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( binary := "1010" ; execute (toDecimal(binary))->display() ) else skip; operation toDecimal(binary : OclAny, i : int) : OclAny pre: true post: true activity: if i->oclIsUndefined() then i := 0 else skip; var n : int := (binary)->size() ; if (i = n - 1) then ( return ("" + ((binary[i+1])))->toInteger() - 0 ) else skip ; return (((("" + ((binary[i+1])))->toInteger() - 0) * (2->pow((n - i - 1)))) + toDecimal(binary, i + 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def preprocess(p,x,y,n): for i in range(n): p[i]=x[i]*x[i]+y[i]*y[i] p.sort() def query(p,n,rad): start=0 end=n-1 while((end-start)>1): mid=(start+end)//2 tp=math.sqrt(p[mid]) if(tp>(rad*1.0)): end=mid-1 else : start=mid tp1=math.sqrt(p[start]) tp2=math.sqrt(p[end]) if(tp1>(rad*1.0)): return 0 elif(tp2<=(rad*1.0)): return end+1 else : return start+1 if __name__=="__main__" : x=[1,2,3,-1,4] y=[1,2,3,-1,4] n=len(x) p=[0]*n preprocess(p,x,y,n) print(query(p,n,3)) print(query(p,n,32)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( x := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{-1}->union(Sequence{ 4 })))) ; y := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{-1}->union(Sequence{ 4 })))) ; n := (x)->size() ; p := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; preprocess(p, x, y, n) ; execute (query(p, n, 3))->display() ; execute (query(p, n, 32))->display() ) else skip; operation preprocess(p : OclAny, x : OclAny, y : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( p[i+1] := x[i+1] * x[i+1] + y[i+1] * y[i+1]) ; p := p->sort(); operation query(p : OclAny, n : OclAny, rad : OclAny) : OclAny pre: true post: true activity: var start : int := 0 ; var end : double := n - 1 ; while ((end - start) > 1) do ( var mid : int := (start + end) div 2 ; var tp : double := (p[mid+1])->sqrt() ; if ((tp->compareTo((rad * 1.0))) > 0) then ( end := mid - 1 ) else ( start := mid )) ; var tp1 : double := (p[start+1])->sqrt() ; var tp2 : double := (p[end+1])->sqrt() ; if ((tp1->compareTo((rad * 1.0))) > 0) then ( return 0 ) else (if ((tp2->compareTo((rad * 1.0))) <= 0) then ( return end + 1 ) else ( return start + 1 ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools from collections import deque sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 DR=[1,-1,0,0] DC=[0,0,1,-1] def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def main(): k,x=LI() lim=10**6 ans=[] for p in range(-lim,lim+1): if abs(p-x)<=k-1 : ans.append(p) print(' '.join([str(x)for x in ans])) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var mod : double := (10)->pow(9) + 7 ; var DR : Sequence := Sequence{1}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{ 0 }))) ; var DC : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ -1 }))) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; main(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation main() pre: true post: true activity: var k : OclAny := null; var x : OclAny := null; Sequence{k,x} := LI() ; var lim : double := (10)->pow(6) ; var ans : Sequence := Sequence{} ; for p : Integer.subrange(-lim, lim + 1-1) do ( if ((p - x)->abs()->compareTo(k - 1)) <= 0 then ( execute ((p) : ans) ) else skip) ; execute (StringLib.sumStringsWithSeparator((ans->select(x | true)->collect(x | (("" + ((x)))))), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def addZeros(strr,n): for i in range(n): strr="0"+strr return strr def getXOR(a,b): aLen=len(a) bLen=len(b) if(aLen>bLen): b=addZeros(b,aLen-bLen) elif(bLen>aLen): a=addZeros(a,bLen-aLen) lenn=max(aLen,bLen); res="" for i in range(lenn): if(a[i]==b[i]): res+="0" else : res+="1" return res a="11001" b="111111" print(getXOR(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := "11001" ; b := "111111" ; execute (getXOR(a, b))->display(); operation addZeros(strr : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( strr := "0" + strr) ; return strr; operation getXOR(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var aLen : int := (a)->size() ; var bLen : int := (b)->size() ; if ((aLen->compareTo(bLen)) > 0) then ( b := addZeros(b, aLen - bLen) ) else (if ((bLen->compareTo(aLen)) > 0) then ( a := addZeros(a, bLen - aLen) ) else skip) ; var lenn : OclAny := Set{aLen, bLen}->max(); ; var res : String := "" ; for i : Integer.subrange(0, lenn-1) do ( if (a[i+1] = b[i+1]) then ( res := res + "0" ) else ( res := res + "1" )) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSegments(a,n,x): flag=False count=0 for i in range(n): if(a[i]>x): flag=True else : if(flag): count+=1 flag=False if(flag): count+=1 return count if __name__=='__main__' : a=[8,25,10,19,19,18,20,11,18] n=len(a) x=13 print(countSegments(a,n,x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := Sequence{8}->union(Sequence{25}->union(Sequence{10}->union(Sequence{19}->union(Sequence{19}->union(Sequence{18}->union(Sequence{20}->union(Sequence{11}->union(Sequence{ 18 })))))))) ; n := (a)->size() ; x := 13 ; execute (countSegments(a, n, x))->display() ) else skip; operation countSegments(a : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: var flag : boolean := false ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ((a[i+1]->compareTo(x)) > 0) then ( flag := true ) else ( if (flag) then ( count := count + 1 ) else skip ; flag := false )) ; if (flag) then ( count := count + 1 ) else skip ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkEqualNo(m,n,a,b): if(m<=n): if((n-m)%(a+b)==0): return True ; else : return False ; else : return False ; if __name__=="__main__" : M=2 ; N=8 ; A=3 ; B=3 ; if(checkEqualNo(M,N,A,B)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var M : int := 2; var N : int := 8; ; var A : int := 3; var B : int := 3; ; if (checkEqualNo(M, N, A, B)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ) else skip; operation checkEqualNo(m : OclAny, n : OclAny, a : OclAny, b : OclAny) pre: true post: true activity: if ((m->compareTo(n)) <= 0) then ( if ((n - m) mod (a + b) = 0) then ( return true; ) else ( return false; ) ) else ( return false; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r=int(input()) print(3*r**2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (3 * (r)->pow(2))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): n,m=map(int,input().split()) print(*sorted(max(x,n-1-x)+max(y,m-1-y)for x in range(n)for y in range(m))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x))))))) , (argument (test (logical_test (comparison (expr (expr (expr (atom (name n))) - (expr (atom (number (integer 1))))) - (expr (atom (name x))))))))) )))) + (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y))))))) , (argument (test (logical_test (comparison (expr (expr (expr (atom (name m))) - (expr (atom (number (integer 1))))) - (expr (atom (name y))))))))) )))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name m)))))))) ))))))))))) )))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(3*int(input())**2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (3 * (("" + (((OclFile["System.in"]).readLine())))->toInteger())->pow(2))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r=int(input()) print("{}".format(3*r**2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (StringLib.interpolateStrings("{}", Sequence{3 * (r)->pow(2)}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(3*int(input())**2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (3 * (("" + (((OclFile["System.in"]).readLine())))->toInteger())->pow(2))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) print(str(3*a*a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (("" + ((3 * a * a))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math arr=list(map(int,input().split())) num=arr[-1]/arr[0] if math.floor(num)==num : print(-1) else : H_M_S_i_line=1 height=1 number_of_S=1 while height*arr[0]=x_max : print(-1) else : if H_M_S_i_line==1 : print(number_of_S) elif arr[1]>0 : print(number_of_S) else : print(number_of_S-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var num : double := arr->last() / arr->first() ; if (num)->floor() = num then ( execute (-1)->display() ) else ( var H_M_S_i_line : int := 1 ; var height : int := 1 ; var number_of_S : int := 1 ; while (height * arr->first()->compareTo(arr->last())) < 0 do ( height := height + 1 ; if height mod 2 = 0 then ( H_M_S_i_line := 1 ) else ( H_M_S_i_line := 2 ) ; number_of_S := number_of_S + H_M_S_i_line) ; var x_min : double := if H_M_S_i_line = 2 then -1 * arr->first() else -1 * MathLib.roundN(arr->first() / 2, 1) endif ; var x_max : double := x_min * -1 ; if (arr[1+1] = 0 & H_M_S_i_line = 2) or (arr[1+1]->compareTo(x_min)) <= 0 or (arr[1+1]->compareTo(x_max)) >= 0 then ( execute (-1)->display() ) else ( if H_M_S_i_line = 1 then ( execute (number_of_S)->display() ) else (if arr[1+1] > 0 then ( execute (number_of_S)->display() ) else ( execute (number_of_S - 1)->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import ceil inp=lambda : map(int,input().split()) input=lambda : sys.stdin.buffer.readline().decode().strip() print=sys.stdout.write a,x,y=inp() level=y//a+ceil((y/a)% 1) if((level>1 and level % 2==1)and(x==0 or x>=a or x<=-a))or((level==1 or level % 2==0)and(x>=a/2 or x<=-a/2))or y % a==0 : print("-1") exit(0) if level==1 : print("1") exit(0) if level % 2==0 : ans=2+(level/2-1)*3 else : ans=2+((level-1)/2-1)*3 ans+=2 if x>0 else 1 print(str(int(ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var input : Function := lambda $$ : OclAny in (sys.stdin.buffer.readLine().decode()->trim()) ; var print : OclAny := (OclFile["System.out"]).write ; var a : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{a,x,y} := inp->apply() ; var level : int := y div a + ceil((y / a) mod 1) ; if ((level > 1 & level mod 2 = 1) & (x = 0 or (x->compareTo(a)) >= 0 or (x->compareTo(-a)) <= 0)) or ((level = 1 or level mod 2 = 0) & ((x->compareTo(a / 2)) >= 0 or (x->compareTo(-a / 2)) <= 0)) or y mod a = 0 then ( execute ("-1")->display() ; exit(0) ) else skip ; if level = 1 then ( execute ("1")->display() ; exit(0) ) else skip ; if level mod 2 = 0 then ( var ans : int := 2 + (level / 2 - 1) * 3 ) else ( ans := 2 + ((level - 1) / 2 - 1) * 3 ; ans := ans + if x > 0 then 2 else 1 endif ) ; execute (("" + ((("" + ((ans)))->toInteger()))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lst=[int(i)for i in input().split()] left=lst[1]-(lst[0]-1) right=lst[1]+(lst[0]-1) ans=list(range(left,right+1)) ans_s=ans[0] for i in range(1,len(ans)): ans_s=str(ans_s)+' '+str(ans[i]) if lst[0]==1 : print(lst[1]) else : print(ans_s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lst : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var left : double := lst[1+1] - (lst->first() - 1) ; var right : OclAny := lst[1+1] + (lst->first() - 1) ; var ans : Sequence := (Integer.subrange(left, right + 1-1)) ; var ans_s : OclAny := ans->first() ; for i : Integer.subrange(1, (ans)->size()-1) do ( ans_s := ("" + ((ans_s))) + ' ' + ("" + ((ans[i+1])))) ; if lst->first() = 1 then ( execute (lst[1+1])->display() ) else ( execute (ans_s)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil a,x,y=map(int,input().split()) l=y//a+ceil((y/a)% 1) if((l>1 and l % 2==1)and(x==0 or x>=a or x<=-a))or((l==1 or l % 2==0)and(x>=a/2 or x<=-a/2))or y % a==0 : print("-1") exit(0) if l==1 : print("1") exit(0) if l % 2==0 : ans=2+(l/2-1)*3 else : ans=2+((l-1)/2-1)*3 ans+=2 if x>0 else 1 print(str(int(ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{a,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : int := y div a + ceil((y / a) mod 1) ; if ((l > 1 & l mod 2 = 1) & (x = 0 or (x->compareTo(a)) >= 0 or (x->compareTo(-a)) <= 0)) or ((l = 1 or l mod 2 = 0) & ((x->compareTo(a / 2)) >= 0 or (x->compareTo(-a / 2)) <= 0)) or y mod a = 0 then ( execute ("-1")->display() ; exit(0) ) else skip ; if l = 1 then ( execute ("1")->display() ; exit(0) ) else skip ; if l mod 2 = 0 then ( var ans : int := 2 + (l / 2 - 1) * 3 ) else ( ans := 2 + ((l - 1) / 2 - 1) * 3 ; ans := ans + if x > 0 then 2 else 1 endif ) ; execute (("" + ((("" + ((ans)))->toInteger()))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil a,x,y=map(int,input().split()) l=y//a+ceil((y/a)% 1) if((l>1 and l % 2==1)and(x==0 or x>=a or x<=-a))or((l==1 or l % 2==0)and(x>=a/2 or x<=-a/2))or y % a==0 : print("-1") elif l==1 : print("1") else : if l % 2==0 : ans=2+(l/2-1)*3 else : ans=2+((l-1)/2-1)*3 ans+=2 if x>0 else 1 print(str(int(ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{a,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : int := y div a + ceil((y / a) mod 1) ; if ((l > 1 & l mod 2 = 1) & (x = 0 or (x->compareTo(a)) >= 0 or (x->compareTo(-a)) <= 0)) or ((l = 1 or l mod 2 = 0) & ((x->compareTo(a / 2)) >= 0 or (x->compareTo(-a / 2)) <= 0)) or y mod a = 0 then ( execute ("-1")->display() ) else (if l = 1 then ( execute ("1")->display() ) else ( if l mod 2 = 0 then ( var ans : int := 2 + (l / 2 - 1) * 3 ) else ( ans := 2 + ((l - 1) / 2 - 1) * 3 ; ans := ans + if x > 0 then 2 else 1 endif ) ; execute (("" + ((("" + ((ans)))->toInteger()))))->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): a,x,y=map(int,input().split()) if x>=a or y % a==0 : return-1 else : i=ceil(y/a) if i % 2 and i!=1 : if x>0 : return i+max(i//2-1,0)+1 elif x==0 or abs(x)>=a : return-1 else : if abs(x)>=a/2 : return-1 return i+max(i//2-1,0) from math import ceil print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; execute (solve())->display(); operation solve() : OclAny pre: true post: true activity: var a : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{a,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (x->compareTo(a)) >= 0 or y mod a = 0 then ( return -1 ) else ( var i : OclAny := ceil(y / a) ; if i mod 2 & i /= 1 then ( if x > 0 then ( return i + Set{i div 2 - 1, 0}->max() + 1 ) else (if x = 0 or ((x)->abs()->compareTo(a)) >= 0 then ( return -1 ) else skip) ) else ( if ((x)->abs()->compareTo(a / 2)) >= 0 then ( return -1 ) else skip ) ) ; return i + Set{i div 2 - 1, 0}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def FindRank(arr,length): print(1,end=" ") for i in range(1,length): rank=1 for j in range(0,i): if(arr[j]>arr[i]): rank=rank+1 print(rank,end=" ") if __name__=='__main__' : arr=[88,14,69,30,29,89] length=len(arr) FindRank(arr,length) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{88}->union(Sequence{14}->union(Sequence{69}->union(Sequence{30}->union(Sequence{29}->union(Sequence{ 89 }))))) ; length := (arr)->size() ; FindRank(arr, length) ) else skip; operation FindRank(arr : OclAny, length : OclAny) pre: true post: true activity: execute (1)->display() ; for i : Integer.subrange(1, length-1) do ( var rank : int := 1 ; for j : Integer.subrange(0, i-1) do ( if ((arr[j+1]->compareTo(arr[i+1])) > 0) then ( rank := rank + 1 ) else skip) ; execute (rank)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n=int(input()) liss=[] for i in range(n): t=input() liss.append(t) z=Counter(liss).most_common()[0][1] print(z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var liss : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var t : String := (OclFile["System.in"]).readLine() ; execute ((t) : liss)) ; var z : OclAny := Counter(liss).most_common()->first()[1+1] ; execute (z)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline n=int(input()) a={} for _ in range(n): s=input().strip() if a.get(s): a[s]+=1 else : a[s]=1 print(max(a.values())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := Set{} ; for _anon : Integer.subrange(0, n-1) do ( var s : OclAny := input()->trim() ; if a.get(s) then ( a[s+1] := a[s+1] + 1 ) else ( a[s+1] := 1 )) ; execute ((a.values())->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) d=dict() for index in range(n): x,y=map(int,input().split()) z=60*x+y if z in d : d[z]+=1 else : d[z]=1 for i in sorted(d.items(),key=lambda x : x[1],reverse=True): print(i[1]) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Map := (arguments ( )) ; for index : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var z : double := 60 * x + y ; if (d)->includes(z) then ( d[z+1] := d[z+1] + 1 ) else ( d[z+1] := 1 )) ; for i : d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sortedBy($x | (lambda x : OclAny in (x[1+1]))->apply($x)) do ( execute (i[1+1])->display() ; break); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- best=1 c=0 n=int(input()) if n==1 : print(1) else : min=0 for i in range(n): a,b=map(int,input().split()) newmin=(60*a)+b if newmin-min==0 : c+=1 best=max(best,c) else : c=1 min=newmin print(best) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var best : int := 1 ; var c : int := 0 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (1)->display() ) else ( var min : int := 0 ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var newmin : double := (60 * a) + b ; if newmin - min = 0 then ( c := c + 1 ; best := Set{best, c}->max() ) else ( c := 1 ) ; min := newmin) ; execute (best)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inp=int(input()) p_h=-1 p_m=-1 m_z=0 z=0 for _ in range(inp): h,m=map(int,input().split()) if h==p_h and m==p_m : z+=1 else : z=1 if z>m_z : m_z=z p_h,p_m=h,m print(m_z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inp : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p_h : int := -1 ; var p_m : int := -1 ; var m_z : int := 0 ; var z : int := 0 ; for _anon : Integer.subrange(0, inp-1) do ( var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if h = p_h & m = p_m then ( z := z + 1 ) else ( z := 1 ) ; if (z->compareTo(m_z)) > 0 then ( m_z := z ) else skip ; Sequence{p_h,p_m} := Sequence{h,m}) ; execute (m_z)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from typing import Set class AutoMapping(dict): def __getitem__(self,key : int)->int : try : return super().__getitem__(key) except KeyError : return 0 fees=AutoMapping() def path(i : int,j : int)->Set[int]: result=set() while i!=j : result.add(i) result.add(j) if i>j : i//=2 else : j//=2 result.discard(i) return result for _ in range(int(input())): event=input().split() if event[0]=="1" : _,v,u,w=map(int,event) for index in path(u,v): fees[index]+=w elif event[0]=="2" : _,v,u=map(int,event) result=0 for index in path(u,v): result+=fees[index] print(result) ------------------------------------------------------------ OCL File: --------- class AutoMapping extends OclType["Map"] { static operation newAutoMapping() : AutoMapping pre: true post: AutoMapping->exists( _x | result = _x ); operation __getitem__(key : int) : int pre: true post: true activity: try ( return super().__getitem__(key)) (except_clause except (test (logical_test (comparison (expr (atom (name KeyError)))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var fees : AutoMapping := (AutoMapping.newAutoMapping()).initialise() ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var event : OclAny := input().split() ; if event->first() = "1" then ( var _anon : OclAny := null; var v : OclAny := null; var u : OclAny := null; var w : OclAny := null; Sequence{_anon,v,u,w} := (event)->collect( _x | (OclType["int"])->apply(_x) ) ; for index : path(u, v) do ( fees[index+1] := fees[index+1] + w) ) else (if event->first() = "2" then ( var _anon : OclAny := null; var v : OclAny := null; var u : OclAny := null; Sequence{_anon,v,u} := (event)->collect( _x | (OclType["int"])->apply(_x) ) ; result := 0 ; for index : path(u, v) do ( result := result + fees[index+1]) ; execute (result)->display() ) else skip)); operation path(i : int, j : int) : OclAny pre: true post: true activity: var result : Set := Set{}->union(()) ; while i /= j do ( execute ((i) : result) ; execute ((j) : result) ; if (i->compareTo(j)) > 0 then ( i := i div 2 ) else ( j := j div 2 )) ; execute ((i) /: result) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict arr=defaultdict(int) for i in range(int(input())): t=list(map(int,input().strip().split())) if t[0]==1 : type,a,b,w=t if b>a : a,b=b,a while a!=b : if a>b : arr[a]+=w a//=2 else : arr[b]+=w b//=2 if t[0]==2 : type,a,b=t res=0 st=set() if ab : res+=arr[a] a//=2 else : res+=arr[b] b//=2 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var arr : OclAny := defaultdict(OclType["int"]) ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var t : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if t->first() = 1 then ( var type : OclAny := null; var a : OclAny := null; var b : OclAny := null; var w : OclAny := null; Sequence{type,a,b,w} := t ; if (b->compareTo(a)) > 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a} ) else skip ; while a /= b do ( if (a->compareTo(b)) > 0 then ( arr[a+1] := arr[a+1] + w ; a := a div 2 ) else ( arr[b+1] := arr[b+1] + w ; b := b div 2 )) ) else skip ; if t->first() = 2 then ( var type : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{type,a,b} := t ; var res : int := 0 ; var st : Set := Set{}->union(()) ; if (a->compareTo(b)) < 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a} ) else skip ; res := 0 ; while a /= b do ( if (a->compareTo(b)) > 0 then ( res := res + arr[a+1] ; a := a div 2 ) else ( res := res + arr[b+1] ; b := b div 2 )) ; execute (res)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() K=int(x.split()[0]) X=int(x.split()[1]) result=[] for i in range(2*K-1): result.append(str(X+i-K+1)) result_1=' '.join(result) print(result_1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := (OclFile["System.in"]).readLine() ; var K : int := ("" + ((x.split()->first())))->toInteger() ; var X : int := ("" + ((x.split()[1+1])))->toInteger() ; var result : Sequence := Sequence{} ; for i : Integer.subrange(0, 2 * K - 1-1) do ( execute ((("" + ((X + i - K + 1)))) : result)) ; var result var x : String := (OclFile["System.in"]).readLine() : String := StringLib.sumStringsWithSeparator((result), ' ') ; execute (resultresult(result(result(resultresult(result(result(resultresult(result(result(resultresult(result(result(resultresult(result(result(resultresult(result(result(resultresult(result(result var x : String := (OclFile["System.in"]).readLine())))->display())))->display())))->display())))->display())))->display())))->display())))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import collections import copy import enum import functools import heapq import itertools import math import random import re import sys import time import string from typing import List r=collections.defaultdict(int) def f(x): return len(bin(x)) q=int(input()) for _ in range(q): ops=list(map(int,input().split())) if ops[0]==1 : u,v,w=ops[1 :] while f(u)>f(v): r[u//2,u]+=w u//=2 while f(v)>f(u): r[v//2,v]+=w v//=2 while u!=v : r[u//2,u]+=w r[v//2,v]+=w u//=2 v//=2 else : u,v=ops[1 :] ans=0 while f(u)>f(v): ans+=r[u//2,u] u//=2 while f(v)>f(u): ans+=r[v//2,v] v//=2 while u!=v : ans+=r[u//2,u] ans+=r[v//2,v] u//=2 v//=2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var r : OclAny := .defaultdict(OclType["int"]) ; skip ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( var ops : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if ops->first() = 1 then ( var u : OclAny := null; var v : OclAny := null; var w : OclAny := null; Sequence{u,v,w} := ops->tail() ; while (f(u)->compareTo(f(v))) > 0 do ( r[u div 2+1][u+1] := r[u div 2+1][u+1] + w ; u := u div 2) ; while (f(v)->compareTo(f(u))) > 0 do ( r[v div 2+1][v+1] := r[v div 2+1][v+1] + w ; v := v div 2) ; while u /= v do ( r[u div 2+1][u+1] := r[u div 2+1][u+1] + w ; r[v div 2+1][v+1] := r[v div 2+1][v+1] + w ; u := u div 2 ; v := v div 2) ) else ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := ops->tail() ; var ans : int := 0 ; while (f(u)->compareTo(f(v))) > 0 do ( ans := ans + r[u div 2+1][u+1] ; u := u div 2) ; while (f(v)->compareTo(f(u))) > 0 do ( ans := ans + r[v div 2+1][v+1] ; v := v div 2) ; while u /= v do ( ans := ans + r[u div 2+1][u+1] ; ans := ans + r[v div 2+1][v+1] ; u := u div 2 ; v := v div 2) ; execute (ans)->display() )); operation f(x : OclAny) : OclAny pre: true post: true activity: return (bin(x))->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import collections import copy import enum import functools import heapq import itertools import math import random import re import sys import time import string from typing import List r=collections.defaultdict(int) def f(x): return len(bin(x)) q=int(input()) for _ in range(q): ops=list(map(int,input().split())) if ops[0]==1 : u,v,w=ops[1 :] if utoInteger() ; for _anon : Integer.subrange(0, q-1) do ( var ops : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if ops->first() = 1 then ( var u : OclAny := null; var v : OclAny := null; var w : OclAny := null; Sequence{u,v,w} := ops->tail() ; if (u->compareTo(v)) < 0 then ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := Sequence{v,u} ) else skip ; for _anon : Integer.subrange(0, f(u) - f(v)-1) do ( r[u div 2+1][u+1] := r[u div 2+1][u+1] + w ; u := u div 2) ; while u /= v do ( r[u div 2+1][u+1] := r[u div 2+1][u+1] + w ; r[v div 2+1][v+1] := r[v div 2+1][v+1] + w ; u := u div 2 ; v := v div 2) ) else ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := ops->tail() ; if (u->compareTo(v)) < 0 then ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := Sequence{v,u} ) else skip ; var ans : int := 0 ; for _anon : Integer.subrange(0, f(u) - f(v)-1) do ( ans := ans + r[u div 2+1][u+1] ; u := u div 2) ; while u /= v do ( ans := ans + r[u div 2+1][u+1] ; ans := ans + r[v div 2+1][v+1] ; u := u div 2 ; v := v div 2) ; execute (ans)->display() )); operation f(x : OclAny) : OclAny pre: true post: true activity: return (bin(x))->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import collections import itertools import array import inspect sys.setrecursionlimit(10000) def chkprint(*args): names={id(v): k for k,v in inspect.currentframe().f_back.f_locals.items()} print(','.join(names.get(id(arg),'???')+'='+repr(arg)for arg in args)) def to_bin(x): return bin(x)[2 :] def li_input(): return[int(_)for _ in input().split()] dp=None def main(): N,H=li_input() S=[li_input()for _ in range(N)] ans=0 strong_throw=[] maxcut=-1 for s in S : if s[0]>maxcut : maxcut=s[0] for s in S : if s[1]>maxcut : strong_throw.append(s[1]) strong_throw.sort(reverse=True) for st in strong_throw : H-=st ans+=1 if H<=0 : break if H>0 : ans+=math.ceil(H/maxcut) print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(10000) ; skip ; skip ; skip ; var dp : OclAny := null ; skip ; main(); operation chkprint(args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) var names : Map := inspect.currentframe().f_back.f_locals->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->select(_tuple | true)->collect(_tuple | Map{?(v) |-> k})->unionAll() ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (expr (expr (atom (name names)) (trailer . (name get) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name id)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arg)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom '???'))))))) )))) + (expr (atom '='))) + (expr (atom (name repr)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arg)))))))) )))))))) (comp_for for (exprlist (expr (atom (name arg)))) in (logical_test (comparison (expr (atom (name args)))))))), ','))->display(); operation to_bin(x : OclAny) : OclAny pre: true post: true activity: return bin(x).subrange(2+1); operation li_input() : OclAny pre: true post: true activity: return input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())); operation main() pre: true post: true activity: var N : OclAny := null; var H : OclAny := null; Sequence{N,H} := li_input() ; var S : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (li_input())) ; var ans : int := 0 ; var strong_throw : Sequence := Sequence{} ; var maxcut : int := -1 ; for s : S do ( if (s->first()->compareTo(maxcut)) > 0 then ( maxcut := s->first() ) else skip) ; for s : S do ( if (s[1+1]->compareTo(maxcut)) > 0 then ( execute ((s[1+1]) : strong_throw) ) else skip) ; strong_throw := strong_throw->sort() ; for st : strong_throw do ( H := H - st ; ans := ans + 1 ; if H <= 0 then ( break ) else skip) ; if H > 0 then ( ans := ans + (H / maxcut)->ceil() ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a={} for i in range(m): b,c=map(int,input().split()) a[i]=(b,c-1) a=sorted(a.items(),key=lambda x : x[1]) b=[0]*(n+1); c=[0]*(n+1) for i in range(n): b[i]=c[i]=i for i in range(m): x=a[i][1][1] b[x]=max(b[x],b[x+1]) c[x+1]=min(c[x],c[x+1]) print(*[b[i]-c[i]+1 for i in range(n)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := Set{} ; for i : Integer.subrange(0, m-1) do ( var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a[i+1] := Sequence{b, c - 1}) ; a := a->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sortedBy($x | (lambda x : OclAny in (x[1+1]))->apply($x)) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); var c : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(0, n-1) do ( b[i+1] := i; var c[i+1] : OclAny := i) ; for i : Integer.subrange(0, m-1) do ( var x : OclAny := a[i+1][1+1][1+1] ; b[x+1] := Set{b[x+1], b[x + 1+1]}->max() ; c[x + 1+1] := Set{c[x+1], c[x + 1+1]}->min()) ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) + (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) ])))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) A=[list(map(int,input().split()))for i in range(m)] A.sort() *v_min,=range(n) *v_max,=range(n) for _,y in A : v_max[y-1]=v_max[y] v_min[y]=v_min[y-1] print(*[v_max[i]-v_min[i]+1 for i in range(n)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; A := A->sort() ; (testlist_star_expr (star_expr * (expr (atom (name v_min)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name v_min)))) ,)} := Integer.subrange(0, n-1) ; (testlist_star_expr (star_expr * (expr (atom (name v_max)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name v_max)))) ,)} := Integer.subrange(0, n-1) ; for _tuple : A do (var _indx : int := 1; var _anon : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); v_max[y - 1+1] := v_max[y+1] ; v_min[y+1] := v_min[y - 1+1]) ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name v_max)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name v_min)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) + (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) ])))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 dd=[(0,-1),(1,0),(0,1),(-1,0)] ddn=[(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)] def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): n,q=LI() qa=sorted([LI()for _ in range(q)]) u=[0]*(n+2) d=[0]*(n+2) for x,i in qa : u[i+1]=u[i]+1 d[i]=d[i+1]+1 rr=[] for i in range(1,n+1): rr.append(u[i]+d[i]+1) return ' '.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; var dd : Sequence := Sequence{Sequence{0, -1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{ Sequence{-1, 0} }))) ; var ddn : Sequence := Sequence{Sequence{0, -1}}->union(Sequence{Sequence{1, -1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{1, 1}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{-1, -1}}->union(Sequence{Sequence{-1, 0}}->union(Sequence{ Sequence{-1, 1} }))))))) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := LI() ; var qa : Sequence := Integer.subrange(0, q-1)->select(_anon | true)->collect(_anon | (LI()))->sort() ; var u : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 2)) ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 2)) ; for _tuple : qa do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); u[i + 1+1] := u[i+1] + 1 ; d[i+1] := d[i + 1+1] + 1) ; var rr : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( execute ((u[i+1] + d[i+1] + 1) : rr)) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) XY=[] for _ in range(M): x,y=map(int,input().split()) xy=(x,y) XY.append(xy) XY.sort(key=lambda x : x[0]) *minY,=range(N) *maxY,=range(N) for _,y in XY : y0,y1=y-1,y minY[y1]=minY[y0] maxY[y0]=maxY[y1] ans=[maxY[i]-minY[i]+1 for i in range(N)] print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var XY : Sequence := Sequence{} ; for _anon : Integer.subrange(0, M-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var xy : OclAny := Sequence{x, y} ; execute ((xy) : XY)) ; XY := XY->sort() ; (testlist_star_expr (star_expr * (expr (atom (name minY)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name minY)))) ,)} := Integer.subrange(0, N-1) ; (testlist_star_expr (star_expr * (expr (atom (name maxY)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name maxY)))) ,)} := Integer.subrange(0, N-1) ; for _tuple : XY do (var _indx : int := 1; var _anon : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); var y0 : OclAny := null; var y1 : OclAny := null; Sequence{y0,y1} := Sequence{y - 1,y} ; minY[y1+1] := minY[y0+1] ; maxY[y0+1] := maxY[y1+1]) ; var ans : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (maxY[i+1] - minY[i+1] + 1)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) xy=[list(map(int,input().split()))for _ in range(m)] ans=[1]*(n+1) prev=[0]*(n+1) xy.sort() for x,y in xy : temp=ans[y]+ans[y+1]-prev[y] ans[y]=temp ans[y+1]=temp prev[y]=temp print(" ".join(list(map(str,ans[1 :])))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var xy : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ; var prev : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; xy := xy->sort() ; for _tuple : xy do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); var temp : double := ans[y+1] + ans[y + 1+1] - prev[y+1] ; ans[y+1] := temp ; ans[y + 1+1] := temp ; prev[y+1] := temp) ; execute (StringLib.sumStringsWithSeparator((((ans->tail())->collect( _x | (OclType["String"])->apply(_x) ))), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lst=list(map(int,input().split())) stack=[] ans='OK' for i in range(n): x=lst[i] if x>0 : if x not in stack : stack.append(x) else : print(i+1) ans='NG' break else : if len(stack)==0 or stack[-1]!=-x : print(i+1) ans='NG' break else : del stack[-1] if ans=='OK' : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var stack : Sequence := Sequence{} ; var ans : String := 'OK' ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := lst[i+1] ; if x > 0 then ( if (stack)->excludes(x) then ( execute ((x) : stack) ) else ( execute (i + 1)->display() ; ans := 'NG' ; break ) ) else ( if (stack)->size() = 0 or stack->last() /= -x then ( execute (i + 1)->display() ; ans := 'NG' ; break ) else ( execute (stack->last())->isDeleted() ) )) ; if ans = 'OK' then ( execute (ans)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque L=int(input()) d=deque() d_set=set() clist=list(map(int,input().split())) for i in range(L): c=clist[i] if c>0 : if c in d_set : print(i+1) break d.append(c) d_set.add(c) else : c*=-1 if not d or d.pop()!=c : print(i+1) break d_set.remove(c) else : print("OK") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var L : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Sequence := () ; var d_set : Set := Set{}->union(()) ; var clist : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name clist)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name c)))) > (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name c)))) in (comparison (expr (atom (name d_set))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d_set)) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) (assign_part *= (testlist (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))))) (stmt (compound_stmt if (test (logical_test (logical_test not (logical_test (comparison (expr (atom (name d)))))) or (logical_test (comparison (comparison (expr (atom (name d)) (trailer . (name pop) (arguments ( ))))) != (comparison (expr (atom (name c)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d_set)) (trailer . (name remove) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "OK"))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) a=list(int(x)for x in input().split()) plus=[] minus=[] plus=plus[: :-1] answer="OK" for i in range(N): if a[0]<0 : answer=i+1 break if a[i]>0 and not(a[i]in plus): plus.append(a[i]) elif a[i]<0 and not(a[i]in minus): if(-(a[i])in plus): minus.append(a[i]) if(len(plus)-1)-plus.index(-(a[i]))==minus.index(a[i]): del minus[minus.index(a[i])] del plus[plus.index(-(a[i]))] else : answer=i+1 break else : answer=i+1 break else : answer=i+1 break print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ; var plus : Sequence := Sequence{} ; var minus : Sequence := Sequence{} ; plus := plus(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var answer : String := "OK" ; for i : Integer.subrange(0, N-1) do ( if a->first() < 0 then ( answer := i + 1 ; break ) else skip ; if a[i+1] > 0 & not(((plus)->includes(a[i+1]))) then ( execute ((a[i+1]) : plus) ) else (if a[i+1] < 0 & not(((minus)->includes(a[i+1]))) then ( if ((plus)->includes(-(a[i+1]))) then ( execute ((a[i+1]) : minus) ; if ((plus)->size() - 1) - plus->indexOf(-(a[i+1])) - 1 = minus->indexOf(a[i+1]) - 1 then ( execute (minus[minus->indexOf(a[i+1]) - 1+1])->isDeleted() ; execute (plus[plus->indexOf(-(a[i+1])) - 1+1])->isDeleted() ) else ( answer := i + 1 ; break ) ) else ( answer := i + 1 ; break ) ) else ( answer := i + 1 ; break ) ) ) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def prevComplement(n,b): maxNum,digits,num=0,0,n while n>1 : digits+=1 n=n//10 maxDigit=b-1 while digits : maxNum=maxNum*10+maxDigit digits-=1 return maxNum-num def complement(n,b): return prevComplement(n,b)+1 if __name__=="__main__" : print(prevComplement(25,7)) print(complement(25,7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (prevComplement(25, 7))->display() ; execute (complement(25, 7))->display() ) else skip; operation prevComplement(n : OclAny, b : OclAny) : OclAny pre: true post: true activity: var maxNum : OclAny := null; var digits : OclAny := null; var num : OclAny := null; Sequence{maxNum,digits,num} := Sequence{0,0,n} ; while n > 1 do ( digits := digits + 1 ; n := n div 10) ; var maxDigit : double := b - 1 ; while digits do ( var maxNum : double := maxNum * 10 + maxDigit ; digits := digits - 1) ; return maxNum - num; operation complement(n : OclAny, b : OclAny) : OclAny pre: true post: true activity: return prevComplement(n, b) + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- L=int(input()) c=[int(x)for x in input().split()] cat,row,flag=[0]*101,[],1 for i,j in enumerate(c): if j>0 and cat[j]==0 : row.append(j) cat[j]=1 elif j<0 and cat[-j]==1 and row[-1]==-j : row.pop() cat[-j]=0 else : flag=0 break if flag : print('OK') else : print(i+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var L : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var cat : OclAny := null; var row : OclAny := null; var flag : OclAny := null; Sequence{cat,row,flag} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, 101),Sequence{},1} ; for _tuple : Integer.subrange(1, (c)->size())->collect( _indx | Sequence{_indx-1, (c)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if j > 0 & cat[j+1] = 0 then ( execute ((j) : row) ; cat[j+1] := 1 ) else (if j < 0 & cat->reverse()->at(-(-j)) = 1 & row->last() = -j then ( row := row->front() ; cat->reverse()->at(-(-j)) := 0 ) else ( var flag : int := 0 ; break ) ) ) ; if flag then ( execute ('OK')->display() ) else ( execute (i + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def gcd(a,b): if al : u,l=l,u u=l-u g=gcd(u,l) u//=g l//=g print(str(u)+'/'+str(l)) def main(): t=1 for _ in range(t): solution() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; skip ; main(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a->compareTo(b)) < 0 then ( Sequence{a,b} := Sequence{b,a} ) else skip ; if b = 0 then ( return a ) else skip ; return gcd(a mod b, b); operation solution() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{a,b,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var u : double := a * y; var l : double := b * x ; if (u->compareTo(l)) > 0 then ( Sequence{u,l} := Sequence{l,u} ) else skip ; u := l - u ; var g : OclAny := gcd(u, l) ; u := u div g ; l := l div g ; execute (("" + ((u))) + '/' + ("" + ((l))))->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cats=[0 for i in range(101)] stack=[] L=int(input()) c=[int(i)for i in input().split()] ans=-1 for i in range(L): if c[i]>0 : if cats[c[i]]==1 : ans=i+1 break else : cats[c[i]]=1 stack.append(c[i]) else : if cats[-c[i]]==0 : ans=i+1 break else : cats[-c[i]]=0 if(stack.pop()!=-c[i]): ans=i+1 break if ans<0 : print("OK") else : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cats : Sequence := Integer.subrange(0, 101-1)->select(i | true)->collect(i | (0)) ; var stack : Sequence := Sequence{} ; var L : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : int := -1 ; for i : Integer.subrange(0, L-1) do ( if c[i+1] > 0 then ( if cats[c[i+1]+1] = 1 then ( ans := i + 1 ; break ) else ( cats[c[i+1]+1] := 1 ; execute ((c[i+1]) : stack) ) ) else ( if cats->reverse()->at(-(-c[i+1])) = 0 then ( ans := i + 1 ; break ) else ( cats->reverse()->at(-(-c[i+1])) := 0 ; if (stack->last() /= -c[i+1]) then ( ans := i + 1 ; break ) else skip ) )) ; if ans < 0 then ( execute ("OK")->display() ) else ( execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,n=map(int,input().split()) x=min(b-1,n) print((a*x)//b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var n : OclAny := null; Sequence{a,b,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := Set{b - 1, n}->min() ; execute ((a * x) div b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os from collections import defaultdict,deque from math import ceil,floor if sys.version_info[1]>=5 : from math import gcd else : from fractions import gcd sys.setrecursionlimit(10**6) write=sys.stdout.write dbg=(lambda*something : print(*something))if 'TERM_PROGRAM' in os.environ else lambda*x : 0 def main(given=sys.stdin.readline): input=lambda : given().rstrip() LMIIS=lambda : list(map(int,input().split())) II=lambda : int(input()) MOD=10**9+7 A,B,N=LMIIS() ans=0 if N>=B-1 : print(floor(A*(B-1)/B)-A*floor((B-1)/B)) else : print(floor(A*N/B)-A*floor(N/B)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if (trailer . (name version_info) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) >= 5 then ( skip ) else ( skip ) ; sys.setrecursionlimit((10)->pow(6)) ; var write : OclAny := (OclFile["System.out"]).write ; var dbg : Function := if (os.environ)->includes('TERM_PROGRAM') then (lambda something : Sequence(OclAny) in (((argument * (test (logical_test (comparison (expr (atom (name something))))))))->display())) else lambda x : Sequence(OclAny) in (0) endif ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main(given : OclAny) pre: true post: true activity: if given->oclIsUndefined() then given := (OclFile["System.in"]).readline else skip; var input : Function := lambda $$ : OclAny in (given().rstrip()) ; var LMIIS : Function := lambda $$ : OclAny in (((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var II : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var MOD : double := (10)->pow(9) + 7 ; var A : OclAny := null; var B : OclAny := null; var N : OclAny := null; Sequence{A,B,N} := LMIIS->apply() ; var ans : int := 0 ; if (N->compareTo(B - 1)) >= 0 then ( execute (floor(A * (B - 1) / B) - A * floor((B - 1) / B))->display() ) else ( execute (floor(A * N / B) - A * floor(N / B))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(map(int,input().split())) a=s[2]% s[1] d=s[2]//s[1] if a==s[1]-1 : b=int((s[0]*a)//s[1]) c=int(a//s[1])*s[0] print(b-c) else : if d==0 : b=int((s[0]*a)//s[1]) c=int(a//s[1])*s[0] print(b-c) else : a=s[2]-a-1 b=int((s[0]*a)//s[1]) c=int(a//s[1])*s[0] print(b-c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : int := s[2+1] mod s[1+1] ; var d : int := s[2+1] div s[1+1] ; if a = s[1+1] - 1 then ( var b : int := ("" + (((s->first() * a) div s[1+1])))->toInteger() ; var c : double := ("" + ((a div s[1+1])))->toInteger() * s->first() ; execute (b - c)->display() ) else ( if d = 0 then ( b := ("" + (((s->first() * a) div s[1+1])))->toInteger() ; c := ("" + ((a div s[1+1])))->toInteger() * s->first() ; execute (b - c)->display() ) else ( a := s[2+1] - a - 1 ; b := ("" + (((s->first() * a) div s[1+1])))->toInteger() ; c := ("" + ((a div s[1+1])))->toInteger() * s->first() ; execute (b - c)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=list(map(int,input().split())) bunsi=c[0] bunbo=c[1] n=c[2] k=n//bunbo d=[n] if k>=1 : d.append(bunbo-1) d.append(bunbo*k-1) def floor(x): return((bunsi*x)//bunbo)-(bunsi*(x//bunbo)) if len(d)>=2 : print(max(floor(d[0]),floor(d[-1]),floor(d[-2]))) if len(d)==1 : print(floor(d[0])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var bunsi : OclAny := c->first() ; var bunbo : OclAny := c[1+1] ; var n : OclAny := c[2+1] ; var k : int := n div bunbo ; var d : Sequence := Sequence{ n } ; if k >= 1 then ( execute ((bunbo - 1) : d) ; execute ((bunbo * k - 1) : d) ) else skip ; skip ; if (d)->size() >= 2 then ( execute (Set{floor(d->first()), floor(d->last()), floor(d->front()->last())}->max())->display() ) else skip ; if (d)->size() = 1 then ( execute (floor(d->first()))->display() ) else skip; operation floor(x : OclAny) : OclAny pre: true post: true activity: return ((bunsi * x) div bunbo) - (bunsi * (x div bunbo)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ii(): return int(input()) def iim(): return map(int,input().split()) def iil(): return list(map(int,input().split())) def ism(): return map(str,input().split()) def isl(): return list(map(str,input().split())) a,b,n=iim() print(int(a*min((b-1),n)/b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var a : OclAny := null; var b : OclAny := null; var n : OclAny := null; Sequence{a,b,n} := iim() ; execute (("" + ((a * Set{(b - 1), n}->min() / b)))->toInteger())->display(); operation ii() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation iim() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation iil() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ism() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["String"])->apply(_x) ); operation isl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["String"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) n1=n s=['']*(n*2+1) for i in range(n+1): stro=' '*(n*2-i*2)+'0' for j in range(1,i+1): stro=stro+' '+str(j) stro2=stro[: :-1] stro2=stro2.rstrip() s[i]=stro+stro2[1 : :] if n!=i : s[n*2-i]=s[i] for i in range(n*2+1): print(s[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n1 : int := n ; var s : Sequence := MatrixLib.elementwiseMult(Sequence{ '' }, (n * 2 + 1)) ; for i : Integer.subrange(0, n + 1-1) do ( var stro : String := StringLib.nCopies(' ', (n * 2 - i * 2)) + '0' ; for j : Integer.subrange(1, i + 1-1) do ( stro := stro + ' ' + ("" + ((j)))) ; var stro2 : OclAny := stro(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; stro2 := StringLib.rightTrim(stro2) ; s[i+1] := stro + stro2(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop :)) ; if n /= i then ( s[n * 2 - i+1] := s[i+1] ) else skip) ; for i : Integer.subrange(0, n * 2 + 1-1) do ( execute (s[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n): ans=[[0]] for i in range(1,n+1): lst=[] temp=[] for j in range(0,i+1): lst.append(j) temp.append(j) lst.reverse() temp=(temp+lst[1 :]) ans.append(temp) for i in range(len(ans)-2,-1,-1): temp=[ans[i]] ans=ans+temp cols=(2*n)+1 rows=(2*n)+1 matrix=[['' for j in range(cols)]for i in range(rows)] for i in range(len(ans)): for j in range(len(ans[i])): matrix[i][abs(n-i)+j]=ans[i][j] for i in matrix : s='' for j in range(len(i)): s=s+str(i[j])+" " s=s.rstrip() print(s) n=int(input()) (solve(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; ; operation solve(n : OclAny) pre: true post: true activity: var ans : Sequence := Sequence{ Sequence{ 0 } } ; for i : Integer.subrange(1, n + 1-1) do ( var lst : Sequence := Sequence{} ; var temp : Sequence := Sequence{} ; for j : Integer.subrange(0, i + 1-1) do ( execute ((j) : lst) ; execute ((j) : temp)) ; lst := lst->reverse() ; temp := (temp->union(lst->tail())) ; execute ((temp) : ans)) ; for i : Integer.subrange(-1 + 1, (ans)->size() - 2)->reverse() do ( temp := Sequence{ ans[i+1] } ; ans := ans->union(temp)) ; var cols : double := (2 * n) + 1 ; var rows : double := (2 * n) + 1 ; var matrix : Sequence := Integer.subrange(0, rows-1)->select(i | true)->collect(i | (Integer.subrange(0, cols-1)->select(j | true)->collect(j | ('')))) ; for i : Integer.subrange(0, (ans)->size()-1) do ( for j : Integer.subrange(0, (ans[i+1])->size()-1) do ( matrix[i+1][(n - i)->abs() + j+1] := ans[i+1][j+1])) ; for i : matrix do ( var s : String := '' ; for j : Integer.subrange(0, (i)->size()-1) do ( s := s + ("" + ((i[j+1]))) + " ") ; s := StringLib.rightTrim(s) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r=range ; N=int(input()) for i in[*r(N),*r(N,-1,-1)]: print(*' '*(N-i),*r(i+1),*r(i-1,-1,-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : OclAny := range; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : r(N)->union(r(N, -1, -1)) do ( execute ((argument * (test (logical_test (comparison (expr (expr (atom ' ')) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name N))) - (expr (atom (name i)))))))) )))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- fact=[1,1,2,6,24,120,720,5040,40320,362880] def peterson(n): num=n sum=0 while n>0 : digit=int(n % 10) sum+=fact[digit] n=int(n/10) return(sum==num) n=145 print("Yes" if peterson(n)else "No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var fact : Sequence := Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{6}->union(Sequence{24}->union(Sequence{120}->union(Sequence{720}->union(Sequence{5040}->union(Sequence{40320}->union(Sequence{ 362880 }))))))))) ; skip ; n := 145 ; execute (if peterson(n) then "Yes" else "No" endif)->display(); operation peterson(n : OclAny) : OclAny pre: true post: true activity: var num : OclAny := n ; var sum : int := 0 ; while n > 0 do ( var digit : int := ("" + ((n mod 10)))->toInteger() ; sum := sum + fact[digit+1] ; n := ("" + ((n / 10)))->toInteger()) ; return (sum = num); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,h=map(int,input().split()) b_sum=0 a_max=0 a_li=[] b_li=[] for i in range(n): a,b=map(int,input().split()) a_li.append(a) b_li.append(b) a_li.sort(reverse=True) b_li.sort(reverse=True) pt=0 a_num=0 b_num=0 ans=0 for i in range(2*n): if b_num>=n : ans+=(h-pt+a_li[a_num]-1)//a_li[a_num] print(ans) exit() if a_li[a_num]=h : print(ans) exit() else : ans+=(h-pt+a_li[a_num]-1)//a_li[a_num] print(ans) exit() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var h : OclAny := null; Sequence{n,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b_sum : int := 0 ; var a_max : int := 0 ; var a_li : Sequence := Sequence{} ; var b_li : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a) : a_li) ; execute ((b) : b_li)) ; a_li := a_li->sort() ; b_li := b_li->sort() ; var pt : int := 0 ; var a_num : int := 0 ; var b_num : int := 0 ; var ans : int := 0 ; for i : Integer.subrange(0, 2 * n-1) do ( if (b_num->compareTo(n)) >= 0 then ( ans := ans + (h - pt + a_li[a_num+1] - 1) div a_li[a_num+1] ; execute (ans)->display() ; exit() ) else skip ; if (a_li[a_num+1]->compareTo(b_li[b_num+1])) < 0 then ( pt := pt + b_li[b_num+1] ; b_num := b_num + 1 ; ans := ans + 1 ; if (pt->compareTo(h)) >= 0 then ( execute (ans)->display() ; exit() ) else skip ) else ( ans := ans + (h - pt + a_li[a_num+1] - 1) div a_li[a_num+1] ; execute (ans)->display() ; exit() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) line=lambda x :[str(i)for i in range(0,x+1)]+[str(i)for i in range(x-1,-1,-1)] result=[line(n)] spaces=1 for x in range(n-1,-1,-1): new_line=([' ']*spaces)+line(x) result.append(new_line) result.insert(0,new_line) spaces+=1 for row in result : print(' '.join(row)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var line : Function := lambda x : OclAny in (Integer.subrange(0, x + 1-1)->select(i | true)->collect(i | (("" + ((i)))))->union(Integer.subrange(-1 + 1, x - 1)->reverse()->select(i | true)->collect(i | (("" + ((i))))))) ; var result : Sequence := Sequence{ line->apply(n) } ; var spaces : int := 1 ; for x : Integer.subrange(-1 + 1, n - 1)->reverse() do ( var new_line : Sequence := (MatrixLib.elementwiseMult(Sequence{ ' ' }, spaces))->union(line->apply(x)) ; execute ((new_line) : result) ; result := result.insertAt(0+1, new_line) ; spaces := spaces + 1) ; for row : result do ( execute (StringLib.sumStringsWithSeparator((row), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,X=map(int,input().split()) m=[int(input())for _ in range(N)] print(N+(X-sum(m))//min(m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var X : OclAny := null; Sequence{N,X} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; execute (N + (X - (m)->sum()) div (m)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import bisect def solve(A,m): n=len(A) ans=n m-=sum(A) ans+=m//min(A) return ans def main(): n,m=map(int,input().split()) A=[] for i in range(n): A.append(int(input())) print(solve(A,m)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation solve(A : OclAny, m : OclAny) : OclAny pre: true post: true activity: var n : int := (A)->size() ; var ans : int := n ; m := m - (A)->sum() ; ans := ans + m div (A)->min() ; return ans; operation main() pre: true post: true activity: Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; A := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : A)) ; execute (solve(A, m))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) ls=[int(input())for _ in range(n)] ls.sort() m-=sum(ls) cnt=n while True : if m>=ls[0]: m-=ls[0] cnt+=1 else : break print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ls : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; ls := ls->sort() ; m := m - (ls)->sum() ; var cnt : OclAny := n ; while true do ( if (m->compareTo(ls->first())) >= 0 then ( m := m - ls->first() ; cnt := cnt + 1 ) else ( break )) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=list(map(int,input().split())) N=a[0] X=a[1] m=[] for i in range(N): m.append(int(input())) wa=sum(m) m.sort() print(str(N+(X-wa)//m[0])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var N : OclAny := a->first() ; var X : OclAny := a[1+1] ; var m : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : m)) ; var wa : OclAny := (m)->sum() ; m := m->sort() ; execute (("" + ((N + (X - wa) div m->first()))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,X=map(int,input().split()) m=[input()for i in range(N)] m=list(map(int,m)) X=X-sum(m) min_m=min(m) C=N+X//min_m print(C) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var X : OclAny := null; Sequence{N,X} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; m := ((m)->collect( _x | (OclType["int"])->apply(_x) )) ; var X : double := X - (m)->sum() ; var min_m : OclAny := (m)->min() ; var C : OclAny := N + X div min_m ; execute (C)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() i=0 while i!=n-1 and s[i]<=s[i+1]: i+=1 if i==n-1 : print(s[: i]) else : print(s[: i]+s[i+1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var i : int := 0 ; while i /= n - 1 & (s[i+1]->compareTo(s[i + 1+1])) <= 0 do ( i := i + 1) ; if i = n - 1 then ( execute (s.subrange(1,i))->display() ) else ( execute (s.subrange(1,i) + s.subrange(i + 1+1))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() p=n-1 for i in range(n-1): if s[i]>s[i+1]: p=i break print(s[: p]+s[p+1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var p : double := n - 1 ; for i : Integer.subrange(0, n - 1-1) do ( if (s[i+1]->compareTo(s[i + 1+1])) > 0 then ( p := i ; break ) else skip) ; execute (s.subrange(1,p) + s.subrange(p + 1+1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) string=input() max=string[0] index=0 max_position=0 while(indextoInteger() ; var string : String := (OclFile["System.in"]).readLine() ; var max : OclAny := string->first() ; var index : int := 0 ; var max_position : int := 0 ; while ((index->compareTo(num)) < 0) do ( if ((max->compareTo(string[index+1])) <= 0) then ( max := string[index+1] ; max_position := index ) else ( max := string[index+1] ; max_position := index - 1 ; break ) ; index := index + 1) ; var string var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() : OclAny := string.subrange(0+1, max_position) + string.subrange(max_position + 1+1, num) ; execute (stringstring(string(string(stringstring(string(string(stringstring(string(string(stringstring(string(string(stringstring(string(string(stringstring(string(string(stringstring(string(string var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger())))->display())))->display())))->display())))->display())))->display())))->display())))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) name=input() newstring="" for i in range(n-1): if(name[i]>name[i+1]): newstring+=name[i+1 :] break newstring+=name[i] if(len(newstring)==n): newstring=newstring[1 :] print(newstring) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var name : String := (OclFile["System.in"]).readLine() ; var newstring : String := "" ; for i : Integer.subrange(0, n - 1-1) do ( if ((name[i+1]->compareTo(name[i + 1+1])) > 0) then ( newstring := newstring + name.subrange(i + 1+1) ; break ) else skip ; newstring := newstring + name[i+1]) ; if ((newstring)->size() = n) then ( newstring := newstring->tail() ) else skip ; execute (newstring)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math N,H=map(int,input().split()) swords=[list(map(int,input().split()))for _ in range(N)] swords_T=[list(x)for x in zip(*swords)] swing_max=max(swords_T[0]) order=sorted(swords_T[1]) count=0 while H>0 and len(order)!=0 : tmp=order.pop() if tmp>swing_max : H-=tmp count+=1 if H>0 : count+=math.ceil(H/swing_max) print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var H : OclAny := null; Sequence{N,H} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var swords : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var swords_T : Sequence := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name swords)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name swords)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name swords)))))))`third->at(_indx)} )->select(x | true)->collect(x | ((x))) ; var swing_max : OclAny := (swords_T->first())->max() ; var order : Sequence := swords_T[1+1]->sort() ; var count : int := 0 ; while H > 0 & (order)->size() /= 0 do ( var tmp : OclAny := order->last() ; order := order->front() ; if (tmp->compareTo(swing_max)) > 0 then ( H := H - tmp ; count := count + 1 ) else skip) ; if H > 0 then ( count := count + (H / swing_max)->ceil() ) else skip ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPossible(A,n,H,K): time=0 for i in range(n): time+=(A[i]-1)//K+1 return time<=H def minJobSpeed(A,n,H): if Hunion(Sequence{6}->union(Sequence{7}->union(Sequence{ 11 }))) ; H := 8 ; n := (A)->size() ; execute (minJobSpeed(A, n, H))->display() ) else skip; operation isPossible(A : OclAny, n : OclAny, H : OclAny, K : OclAny) : OclAny pre: true post: true activity: var time : int := 0 ; for i : Integer.subrange(0, n-1) do ( time := time + (A[i+1] - 1) div K + 1) ; return (time->compareTo(H)) <= 0; operation minJobSpeed(A : OclAny, n : OclAny, H : OclAny) : OclAny pre: true post: true activity: if (H->compareTo(n)) < 0 then ( return -1 ) else skip ; var Max : OclAny := (A)->max() ; var lo : OclAny := null; var hi : OclAny := null; Sequence{lo,hi} := Sequence{1,Max} ; while (lo->compareTo(hi)) < 0 do ( var mi : OclAny := lo + (hi - lo) div 2 ; if not(isPossible(A, n, H, mi)) then ( var lo : OclAny := mi + 1 ) else ( var hi : OclAny := mi )) ; return lo; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def totalDigits(n): number_of_digits=0 ; for i in range(1,n,10): number_of_digits=(number_of_digits+(n-i+1)); return number_of_digits ; n=13 ; s=totalDigits(n)+1 ; print(s); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 13; ; var s : OclAny := totalDigits(n) + 1; ; execute (s)->display();; operation totalDigits(n : OclAny) pre: true post: true activity: var number_of_digits : int := 0; ; for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 10 = 0 ) do ( number_of_digits := (number_of_digits + (n - i + 1));) ; return number_of_digits;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def descOrder(s): s.sort(reverse=True) str1=''.join(s) print(str1) def main(): s=list('geeksforgeeks') descOrder(s) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation descOrder(s : OclAny) pre: true post: true activity: s := s->sort() ; var str1 : String := StringLib.sumStringsWithSeparator((s), '') ; execute (str1)->display(); operation main() pre: true post: true activity: s := ('geeksforgeeks')->characters() ; descOrder(s); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) C=list(map(int,input().split())) q=int(input()) data=[] for _ in range(q): t,x,d=map(int,input().split()) data.append([t,x,d]) apple=[0]*n for D in data : t,x,d=D if t==1 : apple[x-1]+=d if apple[x-1]>C[x-1]: print(x) break else : apple[x-1]-=d if apple[x-1]<0 : print(x) break else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var C : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var data : Sequence := Sequence{} ; for _anon : Integer.subrange(0, q-1) do ( var t : OclAny := null; var x : OclAny := null; var d : OclAny := null; Sequence{t,x,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{t}->union(Sequence{x}->union(Sequence{ d }))) : data)) ; var apple : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; (compound_stmt for (exprlist (expr (atom (name D)))) in (testlist (test (logical_test (comparison (expr (atom (name data))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) , (test (logical_test (comparison (expr (atom (name x)))))) , (test (logical_test (comparison (expr (atom (name d))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name D)))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name t)))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name apple)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ])))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name d))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name apple)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ])))) > (comparison (expr (atom (name C)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name apple)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ])))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (name d))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name apple)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ])))) < (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) D=[int(c)for c in input().split()] C=[0]*(N) Q=int(input()) for _ in range(0,Q): t,x,d=map(int,input().split()) if t==1 : C[x-1]=C[x-1]+d if C[x-1]>D[x-1]: print(x) exit() if t==2 : C[x-1]=C[x-1]-d if C[x-1]<0 : print(x) exit() print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var D : Sequence := input().split()->select(c | true)->collect(c | (("" + ((c)))->toInteger())) ; var C : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N)) ; var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, Q-1) do ( var t : OclAny := null; var x : OclAny := null; var d : OclAny := null; Sequence{t,x,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if t = 1 then ( C[x - 1+1] := C[x - 1+1] + d ; if (C[x - 1+1]->compareTo(D[x - 1+1])) > 0 then ( execute (x)->display() ; exit() ) else skip ) else skip ; if t = 2 then ( C[x - 1+1] := C[x - 1+1] - d ; if C[x - 1+1] < 0 then ( execute (x)->display() ; exit() ) else skip ) else skip) ; execute (0)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) c=list(map(int,input().split())) b=[0 for _ in range(n)] q=int(input()) r=0 for _ in range(q): [t,x,d]=map(int,input().split()) if t==1 : b[x-1]+=d if b[x-1]>c[x-1]: r=x break elif t==2 : b[x-1]-=d if b[x-1]<0 : r=x break print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r : int := 0 ; for _anon : Integer.subrange(0, q-1) do ( ; Sequence{t}->union(Sequence{x}->union(Sequence{ d })) := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if t = 1 then ( b[x - 1+1] := b[x - 1+1] + d ; if (b[x - 1+1]->compareTo(c[x - 1+1])) > 0 then ( r := x ; break ) else skip ) else (if t = 2 then ( b[x - 1+1] := b[x - 1+1] - d ; if b[x - 1+1] < 0 then ( r := x ; break ) else skip ) else skip)) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) arr=set(map(int,input().split())) if 0 in arr : arr.remove(0) print(len(arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; if (arr)->includes(0) then ( execute ((0) /: arr) ) else skip ; execute ((arr)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) l=set(l) if 0 in l : l.remove(0) print(len(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := Set{}->union((l)) ; if (l)->includes(0) then ( execute ((0) /: l) ) else skip ; execute ((l)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- kl=int(input()) nm=list(map(int,input().split())) while(0 in nm): nm.remove(0) nm=set(nm) print(len(nm)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var kl : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nm : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; while ((nm)->includes(0)) do ( execute ((0) /: nm)) ; nm := Set{}->union((nm)) ; execute ((nm)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mvarrrr1=int(input()) mvarrrr2=list(map(int,input().split())) while(0 in mvarrrr2): mvarrrr2.remove(0) mvarrrr2=set(mvarrrr2) print(len(mvarrrr2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mvarrrr1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mvarrrr2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; while ((mvarrrr2)->includes(0)) do ( execute ((0) /: mvarrrr2)) ; mvarrrr2 := Set{}->union((mvarrrr2)) ; execute ((mvarrrr2)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,h=map(int,input().split()) a=[0 for _ in range(n)] b=a[:] for i in range(n): a[i],b[i]=map(int,input().split()) mxa=max(a) b.sort(reverse=1) dmg=0 ans=0 for x in b : if x>=mxa : if h>0 : h-=x ans+=1 if h<=0 : print(ans) exit() else : print(ans+1) exit() else : ans+=(h+mxa-1)//mxa h-=(h+mxa-1)//mxa*mxa break if h>0 : ans+=(h+mxa-1)//mxa h-=(h+mxa-1)//mxa*mxa print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var h : OclAny := null; Sequence{n,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)) ; var b : Sequence := a ; for i : Integer.subrange(0, n-1) do ( var a[i+1] : OclAny := null; var b[i+1] : OclAny := null; Sequence{a[i+1],b[i+1]} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mxa : OclAny := (a)->max() ; b := b->sort() ; var dmg : int := 0 ; var ans : int := 0 ; for x : b do ( if (x->compareTo(mxa)) >= 0 then ( if h > 0 then ( h := h - x ; ans := ans + 1 ; if h <= 0 then ( execute (ans)->display() ; exit() ) else skip ) else ( execute (ans + 1)->display() ; exit() ) ) else ( ans := ans + (h + mxa - 1) div mxa ; h := h - (h + mxa - 1) div mxa * mxa ; break )) ; if h > 0 then ( ans := ans + (h + mxa - 1) div mxa ; h := h - (h + mxa - 1) div mxa * mxa ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) l=list(map(int,input().split())) l=set(l) if 0 in l : l.remove(0) print(len(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := Set{}->union((l)) ; if (l)->includes(0) then ( execute ((0) /: l) ) else skip ; execute ((l)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) k=1 z=0 while True : if n>0 : z+=1 else : break n-=k k*=2 print(z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := 1 ; var z : int := 0 ; while true do ( if n > 0 then ( z := z + 1 ) else ( break ) ; n := n - k ; k := k * 2) ; execute (z)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def gcd(a,b): if(b==0): return a else : return gcd(b,a % b) def coPrime(n1,n2): if(gcd(n1,n2)==1): return True else : return False def largestCoprime(N): half=mt.floor(N/2) while(coPrime(N,half)==False): half-=1 return half n=50 print(largestCoprime(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var n : int := 50 ; execute (largestCoprime(n))->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (b = 0) then ( return a ) else ( return gcd(b, a mod b) ); operation coPrime(n1 : OclAny, n2 : OclAny) : OclAny pre: true post: true activity: if (gcd(n1, n2) = 1) then ( return true ) else ( return false ); operation largestCoprime(N : OclAny) : OclAny pre: true post: true activity: var half : int := mt.floor(N / 2) ; while (coPrime(N, half) = false) do ( half := half - 1) ; return half; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfTheSeries(n): return int((n*(n+1)/2)*(2*n+1)/3) n=5 print("Sum=",sumOfTheSeries(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; execute ("Sum=")->display(); operation sumOfTheSeries(n : OclAny) : OclAny pre: true post: true activity: return ("" + (((n * (n + 1) / 2) * (2 * n + 1) / 3)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ans(n): if(n==1): print("1",end=""); else : print("0",end=""); if __name__=="__main__" : n=2 ; ans(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 2; ; ans(n); ) else skip; operation ans(n : OclAny) pre: true post: true activity: if (n = 1) then ( execute ("1")->display(); ) else ( execute ("0")->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=1e9+7 ; def ways(i,arr,n): if(i==n-1): return 1 ; sum=0 ; for j in range(1,arr[i]+1): if(i+jtoReal() + 7; ; skip ; if __name__ = '__main__' then ( arr := Sequence{5}->union(Sequence{3}->union(Sequence{1}->union(Sequence{4}->union(Sequence{ 3 })))); ; n := (arr)->size(); ; execute (ways(0, arr, n))->display(); ) else skip; operation ways(i : OclAny, arr : OclAny, n : OclAny) pre: true post: true activity: if (i = n - 1) then ( return 1; ) else skip ; var sum : int := 0; ; for j : Integer.subrange(1, arr[i+1] + 1-1) do ( if ((i + j->compareTo(n)) < 0) then ( sum := sum + (ways(i + j, arr, n)) mod mod; ; sum := sum mod mod; ) else skip) ; return ("" + ((sum mod mod)))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math rectangular=list(map(int,input().split())) position=list(map(int,input().split())) number_of_s=int(input()) steps=0 for i in range(0,number_of_s): vactor=list(map(int,input().split())) arr=[0,0] for j in range(0,2): if vactor[j]>0 : arr[j]=math.floor((rectangular[j]-position[j])/vactor[j]) elif vactor[j]<0 : arr[j]=math.floor((position[j]-1)/abs(vactor[j])) else : arr[j]=float("inf") arr.sort() position[0]=position[0]+arr[0]*vactor[0] position[1]=position[1]+arr[0]*vactor[1] steps+=arr[0] print(steps) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var rectangular : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var position : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var number_of_s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var steps : int := 0 ; for i : Integer.subrange(0, number_of_s-1) do ( var vactor : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var arr : Sequence := Sequence{0}->union(Sequence{ 0 }) ; for j : Integer.subrange(0, 2-1) do ( if vactor[j+1] > 0 then ( arr[j+1] := ((rectangular[j+1] - position[j+1]) / vactor[j+1])->floor() ) else (if vactor[j+1] < 0 then ( arr[j+1] := ((position[j+1] - 1) / (vactor[j+1])->abs())->floor() ) else ( arr[j+1] := ("" + (("inf")))->toReal() ) ) ) ; arr := arr->sort() ; position->first() := position->first() + arr->first() * vactor->first() ; position[1+1] := position[1+1] + arr->first() * vactor[1+1] ; steps := steps + arr->first()) ; execute (steps)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=list(map(int,input().split())); pos=list(map(int,input().split())); k=int(input()); c=0 for i in range(k): x,y=list(map(int,input().split())) if x!=0 and y!=0 : if x<0 : numx=(pos[0]-1)//abs(x) elif x>0 : numx=(n-pos[0])//abs(x) if y<0 : numy=(pos[1]-1)//abs(y) elif y>0 : numy=(m-pos[1])//abs(y) z=min(numx,numy); c+=z ; pos[0]+=z*x ; pos[1]+=z*y elif x==0 : if y<0 : numy=(pos[1]-1)//abs(y) elif y>0 : numy=(m-pos[1])//abs(y) z=numy ; c+=z ; pos[1]+=z*y elif y==0 : if x<0 : numx=(pos[0]-1)//abs(x) elif x>0 : numx=(n-pos[0])//abs(x) z=numx ; c+=z ; pos[0]+=z*x print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); var pos : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var c : int := 0 ; for i : Integer.subrange(0, k-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if x /= 0 & y /= 0 then ( if x < 0 then ( var numx : int := (pos->first() - 1) div (x)->abs() ) else (if x > 0 then ( numx := (n - pos->first()) div (x)->abs() ) else skip) ; if y < 0 then ( var numy : int := (pos[1+1] - 1) div (y)->abs() ) else (if y > 0 then ( numy := (m - pos[1+1]) div (y)->abs() ) else skip) ; var z : OclAny := Set{numx, numy}->min(); c := c + z; pos->first() := pos->first() + z * x; pos[1+1] := pos[1+1] + z * y ) else (if x = 0 then ( if y < 0 then ( numy := (pos[1+1] - 1) div (y)->abs() ) else (if y > 0 then ( numy := (m - pos[1+1]) div (y)->abs() ) else skip) ; z := numy; c := c + z; pos[1+1] := pos[1+1] + z * y ) else (if y = 0 then ( if x < 0 then ( numx := (pos->first() - 1) div (x)->abs() ) else (if x > 0 then ( numx := (n - pos->first()) div (x)->abs() ) else skip) ; z := numx; c := c + z; pos->first() := pos->first() + z * x ) else skip ) ) ) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(x,y): global n,m if x>0 and x<=n and y>0 and y<=m : return True return False n,m=list(map(int,input().split())); pos=list(map(int,input().split())); k=int(input()); steps=0 for i in range(k): maxi=10**9 ; mini=0 x,y=list(map(int,input().split())) while mini<=maxi : midian=mini+(maxi-mini)//2 if check(pos[0]+x*midian,pos[1]+y*midian): mini=midian+1 ; ans=midian else : maxi=midian-1 pos[0]+=ans*x ; pos[1]+=ans*y steps+=ans print(steps) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute n : OclAny; attribute m : OclAny; operation initialise() pre: true post: true activity: skip ; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); var pos : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var steps : int := 0 ; for i : Integer.subrange(0, k-1) do ( var maxi : double := (10)->pow(9); var mini : int := 0 ; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; while (mini->compareTo(maxi)) <= 0 do ( var midian : int := mini + (maxi - mini) div 2 ; if check(pos->first() + x * midian, pos[1+1] + y * midian) then ( mini := midian + 1; var ans : int := midian ) else ( maxi := midian - 1 )) ; pos->first() := pos->first() + ans * x; pos[1+1] := pos[1+1] + ans * y ; steps := steps + ans) ; execute (steps)->display(); operation check(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: skip; skip ; if x > 0 & (x->compareTo(n)) <= 0 & y > 0 & (y->compareTo(m)) <= 0 then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) xo,yo=map(int,input().split()) steps=0 for _ in range(int(input())): x_move,y_move=map(int,input().split()) if x_move<0 : x_x=1 elif x_move>0 : x_x=n if y_move<0 : y_y=1 elif y_move>0 : y_y=m if x_move==0 and y_move==0 : steps_num=0 elif x_move==0 : steps_num=int(abs(yo-y_y)/abs(y_move)) elif y_move==0 : steps_num=int(abs(xo-x_x)/abs(x_move)) else : steps_num=int(min(abs(xo-x_x)/abs(x_move),abs(yo-y_y)/abs(y_move))) xo+=x_move*steps_num yo+=y_move*steps_num steps+=steps_num print(steps) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var xo : OclAny := null; var yo : OclAny := null; Sequence{xo,yo} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var steps : int := 0 ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x_move : OclAny := null; var y_move : OclAny := null; Sequence{x_move,y_move} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x_move < 0 then ( var x_x : int := 1 ) else (if x_move > 0 then ( x_x := n ) else skip) ; if y_move < 0 then ( var y_y : int := 1 ) else (if y_move > 0 then ( y_y := m ) else skip) ; if x_move = 0 & y_move = 0 then ( var steps_num : int := 0 ) else (if x_move = 0 then ( steps_num := ("" + (((yo - y_y)->abs() / (y_move)->abs())))->toInteger() ) else (if y_move = 0 then ( steps_num := ("" + (((xo - x_x)->abs() / (x_move)->abs())))->toInteger() ) else ( steps_num := ("" + ((Set{(xo - x_x)->abs() / (x_move)->abs(), (yo - y_y)->abs() / (y_move)->abs()}->min())))->toInteger() ) ) ) ; xo := xo + x_move * steps_num ; yo := yo + y_move * steps_num ; steps := steps + steps_num) ; execute (steps)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): from sys import stdin f_i=stdin D,N=map(int,f_i.readline().split()) T=tuple(int(f_i.readline())for i in range(D)) clothes=[tuple(map(int,f_i.readline().split()))for i in range(N)] clothes.sort(key=lambda x : x[2]) candidate=[] for t in T : ct=tuple(filter(lambda x : x[0]<=t<=x[1],clothes)) c_min=ct[0][2] c_max=ct[-1][2] if c_min==c_max : candidate.append((c_min,)) else : candidate.append((c_min,c_max)) dp=[0]*len(candidate[0]) for c1,c2 in zip(candidate,candidate[1 :]): dp=[max(rec+abs(ci-cj)for rec,ci in zip(dp,c1))for cj in c2] print(max(dp)) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: skip ; var f_i : OclAny := stdin ; var D : OclAny := null; var N : OclAny := null; Sequence{D,N} := (f_i.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var T : Sequence := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name f_i)) (trailer . (name readline) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name D)))))))) ))))))))) ; var clothes : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((f_i.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; clothes := clothes->sort() ; var candidate : Sequence := Sequence{} ; for t : T do ( var ct : Sequence := ((clothes)->select( _x | (lambda x : OclAny in ((x->first()->compareTo(t)) <= 0 & (t <= x[1+1])))->apply(_x) = true )) ; var c_min : OclAny := ct->first()[2+1] ; var c_max : OclAny := ct->last()[2+1] ; if c_min = c_max then ( execute ((Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name c_min)))))) ,)}) : candidate) ) else ( execute ((Sequence{c_min, c_max}) : candidate) )) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (candidate->first())->size()) ; for _tuple : Integer.subrange(1, candidate->size())->collect( _indx | Sequence{candidate->at(_indx), candidate->tail()->at(_indx)} ) do (var _indx : int := 1; var c1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c2 : OclAny := _tuple->at(_indx); dp := c2->select(cj | true)->collect(cj | (((argument (test (logical_test (comparison (expr (expr (atom (name rec))) + (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name ci))) - (expr (atom (name cj))))))))) )))))))) (comp_for for (exprlist (expr (atom (name rec))) , (expr (atom (name ci)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name dp))))))) , (argument (test (logical_test (comparison (expr (atom (name c1)))))))) )))))))))->max()))) ; execute ((dp)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N,H=(int(_)for _ in input().split()) S=sorted([[int(_)for _ in input().split()]for __ in range(N)])[: :-1] output=0 for a,b in sorted(S,key=lambda x :-x[1]): if b>S[0][0]: H-=b output+=1 if H<=0 : break if H>0 : output+=(H+S[0][0]-1)//S[0][0] print(output) return if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var H : OclAny := null; Sequence{N,H} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name _)))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var S : OclAny := sorted(Integer.subrange(0, N-1)->select(__ | true)->collect(__ | (input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())))))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var output : int := 0 ; for _tuple : S->sortedBy($x | (lambda x : OclAny in (-x[1+1]))->apply($x)) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if (b->compareTo(S->first()->first())) > 0 then ( H := H - b ; output := output + 1 ; if H <= 0 then ( break ) else skip ) else skip) ; if H > 0 then ( output := output + (H + S->first()->first() - 1) div S->first()->first() ) else skip ; execute (output)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) xo,yo=map(int,input().split()) steps=0 for _ in range(int(input())): x_move,y_move=map(int,input().split()) x_x=1 if x_move<0 else n y_y=1 if y_move<0 else m if x_move==0 and y_move==0 : steps_num=0 elif x_move==0 : steps_num=int(abs(yo-y_y)/abs(y_move)) elif y_move==0 : steps_num=int(abs(xo-x_x)/abs(x_move)) else : steps_num=int(min(abs(xo-x_x)/abs(x_move),abs(yo-y_y)/abs(y_move))) xo+=x_move*steps_num yo+=y_move*steps_num steps+=steps_num print(steps) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var xo : OclAny := null; var yo : OclAny := null; Sequence{xo,yo} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var steps : int := 0 ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x_move : OclAny := null; var y_move : OclAny := null; Sequence{x_move,y_move} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x_x : int := if x_move < 0 then 1 else n endif ; var y_y : int := if y_move < 0 then 1 else m endif ; if x_move = 0 & y_move = 0 then ( var steps_num : int := 0 ) else (if x_move = 0 then ( steps_num := ("" + (((yo - y_y)->abs() / (y_move)->abs())))->toInteger() ) else (if y_move = 0 then ( steps_num := ("" + (((xo - x_x)->abs() / (x_move)->abs())))->toInteger() ) else ( steps_num := ("" + ((Set{(xo - x_x)->abs() / (x_move)->abs(), (yo - y_y)->abs() / (y_move)->abs()}->min())))->toInteger() ) ) ) ; xo := xo + x_move * steps_num ; yo := yo + y_move * steps_num ; steps := steps + steps_num) ; execute (steps)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def Divide(a,b): dividend=a ; divisor=b ; sign=-1 if((dividend<0)^(divisor<0))else 1 ; dividend=abs(dividend); divisor=abs(divisor); if(divisor==0): print("Cannot Divide by 0"); if(dividend==0): print(a,"/",b,"is equal to :",0); if(divisor==1): print(a,"/",b,"is equal to :",(sign*dividend)); print(a,"/",b,"is equal to :",math.floor(sign*math.exp(math.log(dividend)-math.log(divisor)))); a=10 ; b=5 ; Divide(a,b); a=49 ; b=-7 ; Divide(a,b); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 10; ; b := 5; ; Divide(a, b); ; a := 49; ; b := -7; ; Divide(a, b);; operation Divide(a : OclAny, b : OclAny) pre: true post: true activity: var dividend : OclAny := a; ; var divisor : OclAny := b; ; var sign : int := if (MathLib.bitwiseXor((dividend < 0), (divisor < 0))) then -1 else 1 endif; ; dividend := (dividend)->abs(); ; divisor := (divisor)->abs(); ; if (divisor = 0) then ( execute ("Cannot Divide by 0")->display(); ) else skip ; if (dividend = 0) then ( execute (a)->display(); ) else skip ; if (divisor = 1) then ( execute (a)->display(); ) else skip ; execute (a)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math x=int(input()) print(math.floor(math.log(x,2))+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (((x, 2)->log())->floor() + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left T,N=int(input()),int(input()) a,s,t=[0],[0],[0] for i in range(N): _s,_t=map(int,input().split()) s.append(_s) t.append(_t) a.append(a[-1]+_t-_s) s.append(1<<62) t.append(1<<62) ans=0 k=bisect_left(t,T,0)-1 for i in range(1,N+1): x=s[i]+T k=bisect_left(t,x,k)-1 y=a[k]-a[i-1] if x>s[k+1]: y+=x-s[k+1] if y>ans : ans=y ; if ans==T : break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var T : OclAny := null; var N : OclAny := null; Sequence{T,N} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),("" + (((OclFile["System.in"]).readLine())))->toInteger()} ; var a : OclAny := null; var s : OclAny := null; var t : OclAny := null; Sequence{a,s,t} := Sequence{Sequence{ 0 },Sequence{ 0 },Sequence{ 0 }} ; for i : Integer.subrange(0, N-1) do ( var _s : OclAny := null; var _t : OclAny := null; Sequence{_s,_t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((_s) : s) ; execute ((_t) : t) ; execute ((a->last() + _t - _s) : a)) ; execute ((1 * (2->pow(62))) : s) ; execute ((1 * (2->pow(62))) : t) ; var ans : int := 0 ; var k : double := bisect_left(t, T, 0) - 1 ; for i : Integer.subrange(1, N + 1-1) do ( var x : OclAny := s[i+1] + T ; k := bisect_left(t, x, k) - 1 ; var y : double := a[k+1] - a[i - 1+1] ; if (x->compareTo(s[k + 1+1])) > 0 then ( y := y + x - s[k + 1+1] ) else skip ; if (y->compareTo(ans)) > 0 then ( ans := y; ; if ans = T then ( break ) else skip ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) if n % 2!=0 : if 0 not in l : print("Mike") else : print("Mike" if l.index(0)% 2==1 else "Joe") else : print("Mike" if l.index(min(l))% 2==1 else "Joe") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n mod 2 /= 0 then ( if (l)->excludes(0) then ( execute ("Mike")->display() ) else ( execute (if l->indexOf(0) - 1 mod 2 = 1 then "Mike" else "Joe" endif)->display() ) ) else ( execute (if l->indexOf((l)->min()) - 1 mod 2 = 1 then "Mike" else "Joe" endif)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) a=list(map(int,input().split())) if n % 2==1 : x='Mike' else : if a.index(min(a))% 2==1 : x='Mike' else : x='Joe' print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n mod 2 = 1 then ( var x : String := 'Mike' ) else ( if a->indexOf((a)->min()) - 1 mod 2 = 1 then ( x := 'Mike' ) else ( x := 'Joe' ) ) ; execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,a=int(input()),list(map(int,input().split())) print('Joe' if n % 2==0 and a.index(min(a))% 2==0 else 'Mike') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),((input().split())->collect( _x | (OclType["int"])->apply(_x) ))} ; execute (if n mod 2 = 0 & a->indexOf((a)->min()) - 1 mod 2 = 0 then 'Joe' else 'Mike' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) a=[int(x)for x in input().split()] if n % 2 or a.index(min(a))% 2 : print("Mike") else : print("Joe") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if n mod 2 or a->indexOf((a)->min()) - 1 mod 2 then ( execute ("Mike")->display() ) else ( execute ("Joe")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) a=N//3 b=N % 3 mod=10**9+7 from operator import mul from functools import reduce def cmb(n,r): r=min(n-r,r) if r==0 : return 1 over=reduce(mul,range(n,n-r,-1)) under=reduce(mul,range(1,r+1)) return over//under ans=0 while a>=1 : ans+=cmb(a-1+b,b) a-=1 b+=3 if a==1 : ans+=1 break print(ans % mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := N div 3 ; var b : int := N mod 3 ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; var ans : int := 0 ; while a >= 1 do ( ans := ans + cmb(a - 1 + b, b) ; a := a - 1 ; b := b + 3 ; if a = 1 then ( ans := ans + 1 ; break ) else skip) ; execute (ans mod mod)->display(); operation cmb(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: r := Set{n - r, r}->min() ; if r = 0 then ( return 1 ) else skip ; var over : OclAny := reduce(mul, Integer.subrange(n - r + 1, n)->reverse()) ; var under : OclAny := reduce(mul, Integer.subrange(1, r + 1-1)) ; return over div under; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=10**9+7 fac=[1,1] inv=[0,1] finv=[1,1] def finv_init(n,m): for i in range(2,n+1): fac.append((fac[-1]*i)% m) inv.append((-inv[m % i]*(m//i))% m) finv.append((finv[-1]*inv[-1])% m) def nCr(n,r,m): if(n<0 or r<0 or npow(9) + 7 ; var fac : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var inv : Sequence := Sequence{0}->union(Sequence{ 1 }) ; var finv : Sequence := Sequence{1}->union(Sequence{ 1 }) ; skip ; skip ; skip ; var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; finv_init(s, MOD) ; var ans : int := 0 ; for n : Integer.subrange(1, s + 1-1) do ( if (s->compareTo(3 * n)) < 0 then ( continue ) else skip ; ans := ans + nHr(n, s - 3 * n, MOD)) ; execute (ans mod MOD)->display(); operation finv_init(n : OclAny, m : OclAny) pre: true post: true activity: for i : Integer.subrange(2, n + 1-1) do ( execute (((fac->last() * i) mod m) : fac) ; execute (((-inv[m mod i+1] * (m div i)) mod m) : inv) ; execute (((finv->last() * inv->last()) mod m) : finv)); operation nCr(n : OclAny, r : OclAny, m : OclAny) : OclAny pre: true post: true activity: if (n < 0 or r < 0 or (n->compareTo(r)) < 0) then ( return 0 ) else skip ; r := Set{r, n - r}->min() ; return fac[n+1] * finv[n - r+1] * finv[r+1] mod m; operation nHr(n : OclAny, r : OclAny, m : OclAny) : OclAny pre: true post: true activity: return nCr(n + r - 1, r, m); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def firstkdigits(n,k): product=1 for i in range(n): product*=n while((product//pow(10,k))!=0): product=product//10 return product n=15 k=4 print(firstkdigits(n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 15 ; k := 4 ; execute (firstkdigits(n, k))->display(); operation firstkdigits(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var product : int := 1 ; for i : Integer.subrange(0, n-1) do ( product := product * n) ; while ((product div (10)->pow(k)) /= 0) do ( product := product div 10) ; return product; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,math,bisect,itertools,collections,heapq,queue,copy,array sys.setrecursionlimit(10000000) ii=lambda : int(sys.stdin.buffer.readline().rstrip()) il=lambda : list(map(int,sys.stdin.buffer.readline().split())) fl=lambda : list(map(float,sys.stdin.buffer.readline().split())) iln=lambda n :[int(sys.stdin.buffer.readline().rstrip())for _ in range(n)] iss=lambda : sys.stdin.buffer.readline().decode().rstrip() sl=lambda : list(map(str,sys.stdin.buffer.readline().decode().split())) isn=lambda n :[sys.stdin.buffer.readline().decode().rstrip()for _ in range(n)] lcm=lambda x,y :(x*y)//math.gcd(x,y) MOD=10**9+7 INF=float('inf') def main(): if os.getenv("LOCAL"): sys.stdin=open("input.txt","r") S=ii() dp=[0]*(S+1) dp[0]=1 for i in range(1,S+1): if i>2 : dp[i]=sum(dp[0 : i-2]) dp[i]%=MOD print(dp[-1]) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(10000000) ; var ii : Function := lambda $$ : OclAny in (("" + ((sys.stdin.buffer.readLine().rstrip())))->toInteger()) ; var il : Function := lambda $$ : OclAny in (((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var fl : Function := lambda $$ : OclAny in (((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ))) ; var iln : Function := lambda n : OclAny in (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + ((sys.stdin.buffer.readLine().rstrip())))->toInteger()))) ; var iss : Function := lambda $$ : OclAny in (sys.stdin.buffer.readLine().decode().rstrip()) ; var sl : Function := lambda $$ : OclAny in (((sys.stdin.buffer.readLine().decode().split())->collect( _x | (OclType["String"])->apply(_x) ))) ; var isn : Function := lambda n : OclAny in (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (sys.stdin.buffer.readLine().decode().rstrip()))) ; var lcm : Function := lambda x : OclAny, y : OclAny in ((x * y) div (x)->gcd(y)) ; var MOD : double := (10)->pow(9) + 7 ; var INF : double := ("" + (('inf')))->toReal() ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: if os.getenv("LOCAL") then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ) else skip ; var S : OclAny := ii->apply() ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (S + 1)) ; dp->first() := 1 ; for i : Integer.subrange(1, S + 1-1) do ( if i > 2 then ( dp[i+1] := (dp.subrange(0+1, i - 2))->sum() ; dp[i+1] := dp[i+1] mod MOD ) else skip) ; execute (dp->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=int(input()) if S<3 : print(0) exit() if S<6 : print(1) exit() x=[0]*(S+1) x[3]=x[4]=x[5]=1 for i in range(6,S+1): x[i]+=1 for j in range(3,i-3+1): x[i]+=x[i-j] print(x[S]%(10**9+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if S < 3 then ( execute (0)->display() ; exit() ) else skip ; if S < 6 then ( execute (1)->display() ; exit() ) else skip ; var x : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (S + 1)) ; x[3+1] := x[3+1](assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 4))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 5))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))) ; for i : Integer.subrange(6, S + 1-1) do ( x[i+1] := x[i+1] + 1 ; for j : Integer.subrange(3, i - 3 + 1-1) do ( x[i+1] := x[i+1] + x[i - j+1])) ; execute (x[S+1] mod ((10)->pow(9) + 7))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int,sys.stdin.readline().rstrip())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def LS2(): return list(sys.stdin.readline().rstrip()) S=I() mod=10**9+7 ANS=[1,0,0] for _ in range(S): ANS.append((ANS[-1]+ANS[-3])% mod) print(ANS[S]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var S : OclAny := I() ; var mod : double := (10)->pow(9) + 7 ; var ANS : Sequence := Sequence{1}->union(Sequence{0}->union(Sequence{ 0 })) ; for _anon : Integer.subrange(0, S-1) do ( execute (((ANS->last() + ANS->reverse()->at(-(-3))) mod mod) : ANS)) ; execute (ANS[S+1])->display(); operation I() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.readLine().rstrip())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LI2() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().rstrip())->collect( _x | (OclType["int"])->apply(_x) )); operation S() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation LS() : OclAny pre: true post: true activity: return (sys.stdin.readLine().rstrip().split()); operation LS2() : OclAny pre: true post: true activity: return (sys.stdin.readLine().rstrip()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) count=0 i=1 while i<=n : i*=2 count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := 0 ; var i : int := 1 ; while (i->compareTo(n)) <= 0 do ( i := i * 2 ; count := count + 1) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,pow def rhombusAreaPeri(d1,d2): area=(d1*d2)/2 perimeter=2*sqrt(pow(d1,2)+pow(d2,2)) print("The area of rhombus with diagonals",d1,"and",d2,"is",area,".") print("The perimeter of rhombus with diagonals",d1,"and",d2,"is",perimeter,".") if __name__=='__main__' : d1=2 d2=4 rhombusAreaPeri(d1,d2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( d1 := 2 ; d2 := 4 ; rhombusAreaPeri(d1, d2) ) else skip; operation rhombusAreaPeri(d1 : OclAny, d2 : OclAny) pre: true post: true activity: var area : double := (d1 * d2) / 2 ; var perimeter : double := 2 * sqrt((d1)->pow(2) + (d2)->pow(2)) ; execute ("The area of rhombus with diagonals")->display() ; execute ("The perimeter of rhombus with diagonals")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxValue(arr,n,moves): for i in range(n-2,-1,-1): if(arr[i]>0): distance=n-1-i if(movesunion(Sequence{3}->union(Sequence{0}->union(Sequence{ 1 }))) ; var M : int := 5 ; var N : int := (arr)->size() ; execute (maxValue(arr, N, M))->display() ) else skip; operation maxValue(arr : OclAny, n : OclAny, moves : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( if (arr[i+1] > 0) then ( var distance : double := n - 1 - i ; if ((moves->compareTo(distance)) < 0) then ( break ) else skip ; var can_take : int := moves div distance ; var take : OclAny := Set{arr[i+1], can_take}->min() ; arr[n - 1+1] := arr[n - 1+1] + take ; moves := moves - take * distance ) else skip) ; return arr[n - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getCount(l,r,p): cnt=0 ; val=p ; while(True): a=r//val ; b=(l-1)//val ; val*=p ; if(a-b): cnt+=(a-b); else : break ; return int(cnt); l=2 ; r=8 ; p=2 ; print(getCount(l,r,p)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; l := 2; ; r := 8; ; p := 2; ; execute (getCount(l, r, p))->display();; operation getCount(l : OclAny, r : OclAny, p : OclAny) pre: true post: true activity: var cnt : int := 0; ; var val : OclAny := p; ; while (true) do ( var a : int := r div val; ; var b : int := (l - 1) div val; ; val := val * p; ; if (a - b) then ( cnt := cnt + (a - b); ) else ( break; )) ; return ("" + ((cnt)))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100 def sortRows(mat,n): for i in range(0,n): mat[i].sort(); def findAndPrintCommonElements(mat,n): sortRows(mat,n) curr_index=[0]*n for i in range(0,n): curr_index[i]=0 f=0 while(curr_index[0]union(Sequence{1}->union(Sequence{14}->union(Sequence{3}->union(Sequence{ 16 }))))}->union(Sequence{Sequence{14}->union(Sequence{2}->union(Sequence{1}->union(Sequence{3}->union(Sequence{ 35 }))))}->union(Sequence{Sequence{14}->union(Sequence{1}->union(Sequence{14}->union(Sequence{3}->union(Sequence{ 11 }))))}->union(Sequence{Sequence{14}->union(Sequence{25}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 1 }))))}->union(Sequence{ Sequence{1}->union(Sequence{18}->union(Sequence{3}->union(Sequence{21}->union(Sequence{ 14 })))) })))) ; n := 5 ; findAndPrintCommonElements(mat, n); operation sortRows(mat : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ((expr (atom (name mat)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name sort) (arguments ( ))));); operation findAndPrintCommonElements(mat : OclAny, n : OclAny) pre: true post: true activity: sortRows(mat, n) ; var curr_index : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( curr_index[i+1] := 0) ; var f : int := 0 ; while ((curr_index->first()->compareTo(n)) < 0) do ( var value : OclAny := mat->first()[curr_index->first()+1] ; var present : boolean := true ; for i : Integer.subrange(1, n-1) do ( while ((curr_index[i+1]->compareTo(n)) < 0 & (mat[i+1][curr_index[i+1]+1]->compareTo(value)) <= 0) do ( curr_index[i+1] := curr_index[i+1] + 1) ; if (mat[i+1][curr_index[i+1] - 1+1] /= value) then ( present := false ) else skip ; if (curr_index[i+1] = n) then ( f := 1 ; break ) else skip) ; if (present) then ( execute (value)->display() ) else skip ; if (f = 1) then ( break ) else skip ; curr_index->first() := curr_index->first() + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def traverseLshape(a,n,m): for j in range(0,m): for i in range(0,n-j): print(a[i][j],end=" "); for k in range(j+1,m): print(a[n-1-j][k],end=" "); if __name__=='__main__' : n=4 ; m=3 ; a=[[1,2,3],[4,5,6],[7,8,9],[10,11,12]]; traverseLshape(a,n,m); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 4; ; m := 3; ; a := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))}->union(Sequence{Sequence{7}->union(Sequence{8}->union(Sequence{ 9 }))}->union(Sequence{ Sequence{10}->union(Sequence{11}->union(Sequence{ 12 })) }))); ; traverseLshape(a, n, m); ) else skip; operation traverseLshape(a : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: for j : Integer.subrange(0, m-1) do ( for i : Integer.subrange(0, n - j-1) do ( execute (a[i+1][j+1])->display();) ; for k : Integer.subrange(j + 1, m-1) do ( execute (a[n - 1 - j+1][k+1])->display();)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countTripletsLessThan(arr,n,val): arr.sort() ans=0 j=0 ; k=0 sum=0 for i in range(0,n-2): j=i+1 k=n-1 while j!=k : sum=arr[i]+arr[j]+arr[k] if sum>val : k-=1 else : ans+=(k-j) j+=1 return ans def countTriplets(arr,n,a,b): res=0 res=(countTripletsLessThan(arr,n,b)-countTripletsLessThan(arr,n,a-1)) return res if __name__=="__main__" : arr=[2,7,5,3,8,4,1,9] n=len(arr) a=8 ; b=16 print(countTriplets(arr,n,a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{2}->union(Sequence{7}->union(Sequence{5}->union(Sequence{3}->union(Sequence{8}->union(Sequence{4}->union(Sequence{1}->union(Sequence{ 9 }))))))) ; n := (arr)->size() ; a := 8; b := 16 ; execute (countTriplets(arr, n, a, b))->display() ) else skip; operation countTripletsLessThan(arr : OclAny, n : OclAny, val : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var ans : int := 0 ; var j : int := 0; var k : int := 0 ; var sum : int := 0 ; for i : Integer.subrange(0, n - 2-1) do ( j := i + 1 ; k := n - 1 ; while j /= k do ( sum := arr[i+1] + arr[j+1] + arr[k+1] ; if (sum->compareTo(val)) > 0 then ( k := k - 1 ) else ( ans := ans + (k - j) ; j := j + 1 ))) ; return ans; operation countTriplets(arr : OclAny, n : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; res := (countTripletsLessThan(arr, n, b) - countTripletsLessThan(arr, n, a - 1)) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math try : while True : a,b=input().split(" ") print(math.gcd(int(a),int(b))) except EOFError : m=0 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; try ( while true do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split(" ") ; execute ((("" + ((a)))->toInteger())->gcd(("" + ((b)))->toInteger()))->display())) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name m)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(24-int(input())+24) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (24 - ("" + (((OclFile["System.in"]).readLine())))->toInteger() + 24)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin ni=lambda : int(ns()) na=lambda : list(map(int,stdin.readline().split())) ns=lambda : stdin.readline() m=ni() print(48-m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stdin : OclFile := OclFile["System.in"] ; var ni : Function := lambda $$ : OclAny in (("" + ((ns())))->toInteger()) ; var na : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ns : Function := lambda $$ : OclAny in (stdin.readLine()) ; var m : OclAny := ni->apply() ; execute (48 - m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def new_year(M : int)->int : return 48-M if __name__=="__main__" : M=int(input()) ans=new_year(M) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var M : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : OclAny := new_year(M) ; execute (ans)->display() ) else skip; operation new_year(M : int) : int pre: true post: true activity: return 48 - M; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import itertools import statistics m=int(input()) print(24+(24-m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (24 + (24 - m))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : N,M,s,g1,g2=map(int,input().split()) if N==M==s==g1==g2==0 : break s,g1,g2=s-1,g1-1,g2-1 INF=10**5 D=[[INF]*N for _ in range(N)] for i in range(N): D[i][i]=0 for _ in range(M): b1,b2,c=map(int,input().split()) b1,b2=b1-1,b2-1 D[b1][b2]=c for k in range(N): for i in range(N): for j in range(N): D[i][j]=min(D[i][j],D[i][k]+D[k][j]) print(min(D[s][i]+D[i][g1]+D[i][g2]for i in range(N))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var N : OclAny := null; var M : OclAny := null; var s : OclAny := null; var g1 : OclAny := null; var g2 : OclAny := null; Sequence{N,M,s,g1,g2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if N = M & (M == s) & (s == g1) & (g1 == g2) & (g2 == 0) then ( break ) else skip ; var s : OclAny := null; var g1 : OclAny := null; var g2 : OclAny := null; Sequence{s,g1,g2} := Sequence{s - 1,g1 - 1,g2 - 1} ; var INF : double := (10)->pow(5) ; var D : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ INF }, N))) ; for i : Integer.subrange(0, N-1) do ( D[i+1][i+1] := 0) ; for _anon : Integer.subrange(0, M-1) do ( var b1 : OclAny := null; var b2 : OclAny := null; var c : OclAny := null; Sequence{b1,b2,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b1 : OclAny := null; var b2 : OclAny := null; Sequence{b1,b2} := Sequence{b1 - 1,b2 - 1} ; D[b1+1][b2+1] := c) ; for k : Integer.subrange(0, N-1) do ( for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( D[i+1][j+1] := Set{D[i+1][j+1], D[i+1][k+1] + D[k+1][j+1]}->min()))) ; execute (((argument (test (logical_test (comparison (expr (expr (expr (atom (name D)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name D)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name g1)))))))) ])))) + (expr (atom (name D)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name g2)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))))->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys from collections import deque,OrderedDict,defaultdict import heapq,re from collections import Counter def inp(): return sys.stdin.readline().rstrip() def mpp(): return map(int,inp().split()) def lis(): return list(mpp()) def yn(n): if n : return "YES" else : return "NO" def cd(s): return ord(s)-ord('a')+1 def fn(n): ans=bin(n).replace("0b","") return len(ans) def main(): s=int(inp()) print(fn(s)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation inp() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation mpp() : OclAny pre: true post: true activity: return (inp().split())->collect( _x | (OclType["int"])->apply(_x) ); operation lis() : OclAny pre: true post: true activity: return (mpp()); operation yn(n : OclAny) : OclAny pre: true post: true activity: if n then ( return "YES" ) else ( return "NO" ); operation cd(s : OclAny) : OclAny pre: true post: true activity: return (s)->char2byte() - ('a')->char2byte() + 1; operation fn(n : OclAny) : OclAny pre: true post: true activity: var ans : OclAny := bin(n).replace("0b", "") ; return (ans)->size(); operation main() pre: true post: true activity: s := ("" + ((inp())))->toInteger() ; execute (fn(s))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- M=int(input()) print(24-M+24) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var M : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (24 - M + 24)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def print_ele(arr,n): for i in range(n): print(arr[i],end=" "); print(); def swapMax(arr,target_position,current_position): aux=0 ; for i in range(current_position,target_position,-1): aux=arr[i-1]; arr[i-1]=arr[i]; arr[i]=aux ; def maximizeArray(arr,length,swaps): if(swaps==0): return ; for i in range(length): max_index=0 ; max=-(sys.maxsize-1); if(swaps+i)>length : limit=length else : limit=swaps+i for j in range(i,limit+1): if(arr[j]>max): max=arr[j]; max_index=j ; swaps-=(max_index-i); swapMax(arr,i,max_index); if(swaps==0): break ; if __name__=="__main__" : arr=[1,2,9,8,1,4,9,9,9]; length=len(arr); swaps=4 ; maximizeArray(arr,length,swaps); print_ele(arr,length); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{9}->union(Sequence{8}->union(Sequence{1}->union(Sequence{4}->union(Sequence{9}->union(Sequence{9}->union(Sequence{ 9 })))))))); ; length := (arr)->size(); ; swaps := 4; ; maximizeArray(arr, length, swaps); ; print_ele(arr, length); ) else skip; operation print_ele(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display();) ; execute (->display();; operation swapMax(arr : OclAny, target_position : OclAny, current_position : OclAny) pre: true post: true activity: var aux : int := 0; ; for i : Integer.subrange(target_position + 1, current_position)->reverse() do ( aux := arr[i - 1+1]; ; arr[i - 1+1] := arr[i+1]; ; arr[i+1] := aux;); operation maximizeArray(arr : OclAny, length : OclAny, swaps : OclAny) : OclAny pre: true post: true activity: if (swaps = 0) then ( return; ) else skip ; for i : Integer.subrange(0, length-1) do ( var max_index : int := 0; var max : double := -((trailer . (name maxsize)) - 1); ; if ((swaps + i)->compareTo(length)) > 0 then ( var limit : OclAny := length ) else ( limit := swaps + i ) ; for j : Integer.subrange(i, limit + 1-1) do ( if ((arr[j+1]->compareTo(max)) > 0) then ( max := arr[j+1]; ; max_index := j; ) else skip) ; swaps := swaps - (max_index - i); ; swapMax(arr, i, max_index); ; if (swaps = 0) then ( break; ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys f=sys.stdin def is_odd(num): return num % 2 n,_,_=map(int,f.readline().split()) a=list(map(int,f.readline().split())) q=list(map(int,f.readline().split())) s=list(range(n)) pos=0 for ai in a : pos+=-ai if is_odd(ai)else ai pos %=len(s) s.pop(pos) for qi in q : print(1 if qi in s else 0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var f : OclFile := OclFile["System.in"] ; skip ; var n : OclAny := null; var _anon : OclAny := null; var _anon : OclAny := null; Sequence{n,_anon,_anon} := (f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : Sequence := ((f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Sequence := (Integer.subrange(0, n-1)) ; var pos : int := 0 ; for ai : a do ( pos := pos + if is_odd(ai) then -ai else ai endif ; pos := pos mod (s)->size() ; s := s->excludingAt(pos+1)) ; for qi : q do ( execute (if (s)->includes(qi) then 1 else 0 endif)->display()); operation is_odd(num : OclAny) : OclAny pre: true post: true activity: return num mod 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=list(map(int,input().split()))[0] s=[i for i in range(n)] a=tuple(map(int,input().split())) b=0 for i in a : if i % 2 : b=(b-i)% len(s) s.pop(b) else : b=(b+i)% len(s) s.pop(b) r=tuple(map(int,input().split())) for i in r : print(1 if i in s else 0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->first() ; var s : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : int := 0 ; for i : a do ( if i mod 2 then ( b := (b - i) mod (s)->size() ; s := s->excludingAt(b+1) ) else ( b := (b + i) mod (s)->size() ; s := s->excludingAt(b+1) )) ; var r : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : r do ( execute (if (s)->includes(i) then 1 else 0 endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin import fractions input=stdin.readline def main(args): for line in stdin : n,m=map(int,line.split()) print(fractions.gcd(n,m)) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := stdin.readline ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation main(args : OclAny) pre: true post: true activity: for line : stdin do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (line.split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (fractions.gcd(n, m))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin from collections import deque input=stdin.readline def main(args): N,M,Q=map(int,input().split(' ')) members=deque(list(range(N))) numbers=[int(x)for x in input().split(' ')] queries=[int(x)for x in input().split(' ')] for n in numbers : if n % 2==0 : n=n % N members.rotate(-n) members.popleft() else : n=n % N members.rotate(n) members.popleft() N-=1 for q in queries : ans=1 if q in members else 0 print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := stdin.readline ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation main(args : OclAny) pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; var Q : OclAny := null; Sequence{N,M,Q} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var members : Sequence := ((Integer.subrange(0, N-1))) ; var numbers : Sequence := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var queries : Sequence := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for n : numbers do ( if n mod 2 = 0 then ( var n : int := n mod N ; members.rotate(-n) ; members := members->tail() ) else ( n := n mod N ; members.rotate(n) ; members := members->tail() ) ; N := N - 1) ; for q : queries do ( var ans : int := if (members)->includes(q) then 1 else 0 endif ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): import sys file_input=sys.stdin N,M,Q=map(int,file_input.readline().split()) student=list(range(N)) exemption=[1]*N pos=0 for a in map(int,file_input.readline().split()): if a % 2 : pos=(pos-a)% len(student) else : pos=(pos+a)% len(student) s=student[pos] exemption[s]=0 del student[pos] question=map(int,file_input.readline().split()) print(*map(lambda x : exemption[x],question),sep='\n') solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: skip ; var file_input : OclFile := OclFile["System.in"] ; var N : OclAny := null; var M : OclAny := null; var Q : OclAny := null; Sequence{N,M,Q} := (file_input.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var student : Sequence := (Integer.subrange(0, N-1)) ; var exemption : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, N) ; var pos : int := 0 ; for a : (file_input.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( if a mod 2 then ( pos := (pos - a) mod (student)->size() ) else ( pos := (pos + a) mod (student)->size() ) ; var s : OclAny := student[pos+1] ; exemption[s+1] := 0 ; execute (student[pos+1])->isDeleted()) ; var question : Sequence := (file_input.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name exemption)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))))))) , (argument (test (logical_test (comparison (expr (atom (name question)))))))) )))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pass_baton(n_list,current,in_data): if in_data % 2!=0 : current-=in_data while current<0 : current+=len(n_list) return current else : current+=in_data while len(n_list)<=current : current-=len(n_list) return current N,M,Q=map(int,input().split(' ')) m_data=map(int,input().split(' ')) q_data=map(int,input().split(' ')) n_list=[x for x in range(N)] baton_place=0 for m in m_data : baton_place=pass_baton(n_list,baton_place,m) del n_list[baton_place] for q in q_data : if q in n_list : print(1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; var Q : OclAny := null; Sequence{N,M,Q} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var m_data : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var q_data : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; n_list := Integer.subrange(0, N-1)->select(x | true)->collect(x | (x)) ; var baton_place : int := 0 ; for m : m_data do ( baton_place := pass_baton(n_list, baton_place, m) ; execute (n_list[baton_place+1])->isDeleted()) ; for q : q_data do ( if (n_list)->includes(q) then ( execute (1)->display() ) else ( execute (0)->display() )); operation pass_baton(n_list : OclAny, current : OclAny, in_data : OclAny) : OclAny pre: true post: true activity: if in_data mod 2 /= 0 then ( current := current - in_data ; while current < 0 do ( current := current + (n_list)->size()) ; return current ) else ( current := current + in_data ; while ((n_list)->size()->compareTo(current)) <= 0 do ( current := current - (n_list)->size()) ; return current ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c,d=input() if c in 'ah' : print(3 if d in '18' else 5) else : print(5 if d in '18' else 8) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := (OclFile["System.in"]).readLine() ; if ('ah')->characters()->includes(c) then ( execute (if ('18')->characters()->includes(d) then 3 else 5 endif)->display() ) else ( execute (if ('18')->characters()->includes(d) then 5 else 8 endif)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=list(input()) l[0]=ord(l[0])-96 l[1]=int(l[1]) if(l[0]==l[1]and(l[0]==1 or l[0]==8))or(l[0]==1 and l[1]==8)or(l[1]==1 and l[0]==8): print(3) elif l[1]==1 or l[1]==8 or l[0]==1 or l[0]==8 : print(5) else : print(8) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := ((OclFile["System.in"]).readLine())->characters() ; l->first() := (l->first())->char2byte() - 96 ; l[1+1] := ("" + ((l[1+1])))->toInteger() ; if (l->first() = l[1+1] & (l->first() = 1 or l->first() = 8)) or (l->first() = 1 & l[1+1] = 8) or (l[1+1] = 1 & l->first() = 8) then ( execute (3)->display() ) else (if l[1+1] = 1 or l[1+1] = 8 or l->first() = 1 or l->first() = 8 then ( execute (5)->display() ) else ( execute (8)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() if s[0]=='a' or s[0]=='h' : if s[1]=='1' or s[1]=='8' : print(3) else : print(5) else : if s[1]=='1' or s[1]=='8' : print(5) else : print(8) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; if s->first() = 'a' or s->first() = 'h' then ( if s[1+1] = '1' or s[1+1] = '8' then ( execute (3)->display() ) else ( execute (5)->display() ) ) else ( if s[1+1] = '1' or s[1+1] = '8' then ( execute (5)->display() ) else ( execute (8)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) c=1 while 2**ctoInteger() ; var c : int := 1 ; while ((2)->pow(c)->compareTo(k + 1)) < 0 do ( c := c + 1) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=list(input()) c=num[0] d=int(num[1]) if d==1 or d==8 : if c=='a' or c=='h' : print(3) else : print(5) else : if c=='a' or c=='h' : print(5) else : print(8) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var c : OclAny := num->first() ; var d : int := ("" + ((num[1+1])))->toInteger() ; if d = 1 or d = 8 then ( if c = 'a' or c = 'h' then ( execute (3)->display() ) else ( execute (5)->display() ) ) else ( if c = 'a' or c = 'h' then ( execute (5)->display() ) else ( execute (8)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input('') r,c=s[0],s[1] if s=='a8' or s=='a1' or s=='h8' or s=='h1' : print(3) elif r=='h' or r=='a' : if c!='1' or c!='8' : print(5) elif c=='1' or c=='8' : if r!='a' or r!='h' : print(5) else : print(8) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine('') ; var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := Sequence{s->first(),s[1+1]} ; if s = 'a8' or s = 'a1' or s = 'h8' or s = 'h1' then ( execute (3)->display() ) else (if r = 'h' or r = 'a' then ( if c /= '1' or c /= '8' then ( execute (5)->display() ) else skip ) else (if c = '1' or c = '8' then ( if r /= 'a' or r /= 'h' then ( execute (5)->display() ) else skip ) else ( execute (8)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def power(x,y,p): b=bin(y)[2 :] x=x % p start=x answer=1 for i in range(len(b)): if b[len(b)-i-1]=='1' : answer=(start*answer)% p start=(start*start)% p return answer p=10**9+7 def process(n,m,k): if npow(9) + 7 ; skip ; Sequence{n,m,k} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (process(n, m, k))->display(); operation power(x : OclAny, y : OclAny, p : OclAny) : OclAny pre: true post: true activity: var b : OclAny := bin(y).subrange(2+1) ; x := x mod p ; var start : OclAny := x ; var answer : int := 1 ; for i : Integer.subrange(0, (b)->size()-1) do ( if b[(b)->size() - i - 1+1] = '1' then ( answer := (start * answer) mod p ) else skip ; start := (start * start) mod p) ; return answer; operation process(n : OclAny, m : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (n->compareTo(k)) < 0 or k = 1 then ( return power(m, n, p) ) else skip ; if n = k then ( if k mod 2 = 0 then ( return power(m, k div 2, p) ) else ( return power(m, k div 2 + 1, p) ) ) else skip ; if k mod 2 = 0 then ( return m mod p ) else ( return (m * m) mod p ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): while b!=0 : r=a % b a,b=b,r return a while True : try : a,b=map(int,input().split()) except : break print(gcd(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( try ( Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )) catch (_e : OclException) do ( break) ; execute (gcd(a, b))->display()); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: while b /= 0 do ( var r : int := a mod b ; Sequence{a,b} := Sequence{b,r}) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=list(map(int,input().split())) print(m**n %(10**9+7)if k>n or k==1 else m**(-(-n//2)if n==k else k % 2+1)%(10**9+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (if (k->compareTo(n)) > 0 or k = 1 then (m)->pow(n) mod ((10)->pow(9) + 7) else (m)->pow((if n = k then -(-n div 2) else k mod 2 + 1 endif)) mod ((10)->pow(9) + 7) endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) mod=10**9+7 if ncollect( _x | (OclType["int"])->apply(_x) ) ; var mod : double := (10)->pow(9) + 7 ; if (n->compareTo(k)) < 0 then ( execute ((m)->pow(n))->display() ) else (if n = k then ( var x : int := n div 2 ; if n mod 2 = 0 then ( execute ((m)->pow(x))->display() ) else ( execute ((m)->pow(x + 1))->display() ) ) else ( if k = 1 then ( execute ((m)->pow(n))->display() ) else (if k mod 2 = 1 then ( var ans : int := 0 ; ans := ans + m ; ans := ans + m * (m - 1) ; execute (ans mod mod)->display() ) else ( execute (m)->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solution(): inp=input().split() n,m,k=int(inp[0]),int(inp[1]),int(inp[2]) mod=10**9+7 if k==1 or k>n : sol=pow(m,n,mod) elif k==n : sol=pow(m,(n+1)//2,mod) elif k % 2==1 : sol=pow(m,2) elif k % 2==0 : sol=m print(sol) solution() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solution(); operation solution() pre: true post: true activity: var inp : OclAny := input().split() ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := Sequence{("" + ((inp->first())))->toInteger(),("" + ((inp[1+1])))->toInteger(),("" + ((inp[2+1])))->toInteger()} ; var mod : double := (10)->pow(9) + 7 ; if k = 1 or (k->compareTo(n)) > 0 then ( var sol : double := (m)->pow(n) ) else (if k = n then ( sol := (m)->pow((n + 1) div 2) ) else (if k mod 2 = 1 then ( sol := (m)->pow(2) ) else (if k mod 2 = 0 then ( sol := m ) else skip ) ) ) ; execute (sol)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solution(): inp=input().split() n,m,k=int(inp[0]),int(inp[1]),int(inp[2]) mod=10**9+7 if k==1 or k>n : sol=pow(m,n,mod) elif k==n : sol=pow(m,(n+1)//2,mod) elif k % 2==1 : sol=pow(m,2) elif k % 2==0 : sol=m print(sol) solution() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solution(); operation solution() pre: true post: true activity: var inp : OclAny := input().split() ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := Sequence{("" + ((inp->first())))->toInteger(),("" + ((inp[1+1])))->toInteger(),("" + ((inp[2+1])))->toInteger()} ; var mod : double := (10)->pow(9) + 7 ; if k = 1 or (k->compareTo(n)) > 0 then ( var sol : double := (m)->pow(n) ) else (if k = n then ( sol := (m)->pow((n + 1) div 2) ) else (if k mod 2 = 1 then ( sol := (m)->pow(2) ) else (if k mod 2 = 0 then ( sol := m ) else skip ) ) ) ; execute (sol)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) l=[] for _ in range(n): a,b=map(int,input().split()) l.append(a*m/b) print(round(min(l),8)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a * m / b) : l)) ; execute (MathLib.roundN((l)->min(), 8))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(i)for(i)in input().split()] min=float("inf") for i in range(n): a,b=[int(i)for(i)in input().split()] if a/bselect((i) | true)->collect((i) | (("" + ((i)))->toInteger())) ; var min : double := ("" + (("inf")))->toReal() ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select((i) | true)->collect((i) | (("" + ((i)))->toInteger())) ; if (a / b->compareTo(min)) < 0 then ( min := a / b ) else skip) ; execute (min * m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=lambda : map(int,input().split()) n,a=x(); m=10**10 for i in range(n): c,d=x() m=min(m,c/d) print(m*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := x->apply(); var m : double := (10)->pow(10) ; for i : Integer.subrange(0, n-1) do ( var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := x->apply() ; m := Set{m, c / d}->min()) ; execute (m * a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,m=map(int,input().split(":")) a=int(input()) m+=a h+=m//60 m %=60 h %=24 print(format(h,"02"),":",format(m,"02"),sep="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := (input().split(":"))->collect( _x | (OclType["int"])->apply(_x) ) ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; m := m + a ; h := h + m div 60 ; m := m mod 60 ; h := h mod 24 ; execute ((h + ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=[int(x)for x in input().split()] sort=[] for i in range(0,n[0]): s=[int(x)for x in input().split()] sort.append(n[1]*(s[0]/s[1])) sort.sort() print(sort[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var sort : Sequence := Sequence{} ; for i : Integer.subrange(0, n->first()-1) do ( var s : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((n[1+1] * (s->first() / s[1+1])) : sort)) ; sort := sort->sort() ; execute (sort->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) l=[] for i in range(n): a,b=map(int,input().split()) l.append((m*a)/b) k=min(l) print(round(k,8)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (((m * a) / b) : l)) ; var k : OclAny := (l)->min() ; execute (MathLib.roundN(k, 8))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(x,y): if y==0 : return x z=x % y return gcd(y,z) while True : try : a,b=(int(i)for i in input().split()) except EOFError : break if acompareTo(b)) < 0 then ( execute (gcd(b, a))->display() ) else ( execute (gcd(a, b))->display() )); operation gcd(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if y = 0 then ( return x ) else skip ; var z : int := x mod y ; return gcd(y, z); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxEvenSubarray(array,N): ans=0 count=0 for i in range(0,N): if array[i]% 2==0 : count+=1 ans=max(ans,count) else : count=0 ans=max(ans,count) return ans if __name__=='__main__' : arr=[9,8,5,4,4,4,2,4,1] N=len(arr) print(maxEvenSubarray(arr,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var arr : Sequence := Sequence{9}->union(Sequence{8}->union(Sequence{5}->union(Sequence{4}->union(Sequence{4}->union(Sequence{4}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 1 })))))))) ; N := (arr)->size() ; execute (maxEvenSubarray(arr, N))->display() ) else skip; operation maxEvenSubarray(array : OclAny, N : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; var count : int := 0 ; for i : Integer.subrange(0, N-1) do ( if array[i+1] mod 2 = 0 then ( count := count + 1 ; ans := Set{ans, count}->max() ) else ( count := 0 )) ; ans := Set{ans, count}->max() ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=input().split() n=int(n); k=int(k) a=input() l=a.split() ans=0 for j in range(len(l)): lc=0 for i in range(len(l[j])): if l[j][i]=='4' or l[j][i]=='7' : lc+=1 if lc<=k : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split() ; var n : int := ("" + ((n)))->toInteger(); var k : int := ("" + ((k)))->toInteger() ; var a : String := (OclFile["System.in"]).readLine() ; var l : OclAny := a.split() ; var ans : int := 0 ; for j : Integer.subrange(0, (l)->size()-1) do ( var lc : int := 0 ; for i : Integer.subrange(0, (l[j+1])->size()-1) do ( if l[j+1][i+1] = '4' or l[j+1][i+1] = '7' then ( lc := lc + 1 ) else skip) ; if (lc->compareTo(k)) <= 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=input().split() n=int(n); k=int(k) a=input() l=a.split() ans=0 for i in range(len(l)): lc=0 for j in range(len(l[i])): if l[i][j]=='4' or l[i][j]=='7' : lc+=1 if lc<=k : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split() ; var n : int := ("" + ((n)))->toInteger(); var k : int := ("" + ((k)))->toInteger() ; var a : String := (OclFile["System.in"]).readLine() ; var l : OclAny := a.split() ; var ans : int := 0 ; for i : Integer.subrange(0, (l)->size()-1) do ( var lc : int := 0 ; for j : Integer.subrange(0, (l[i+1])->size()-1) do ( if l[i+1][j+1] = '4' or l[i+1][j+1] = '7' then ( lc := lc + 1 ) else skip) ; if (lc->compareTo(k)) <= 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=input().split() x=int(x) y=int(y) c=input() d=c.split() cnt=0 for i in range(len(d)): for j in range(len(d[i])): if(d[i])[j]=="4" or(d[i])[j]=="7" : cnt+=1 if cnt>y : x-=1 cnt=min(cnt,0) print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := input().split() ; var x : int := ("" + ((x)))->toInteger() ; var y : int := ("" + ((y)))->toInteger() ; var c : String := (OclFile["System.in"]).readLine() ; var d : OclAny := c.split() ; var cnt : int := 0 ; for i : Integer.subrange(0, (d)->size()-1) do ( for j : Integer.subrange(0, (d[i+1])->size()-1) do ( if (d[i+1])[j+1] = "4" or (d[i+1])[j+1] = "7" then ( cnt := cnt + 1 ) else skip) ; if (cnt->compareTo(y)) > 0 then ( x := x - 1 ) else skip ; cnt := Set{cnt, 0}->min()) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=input().split() n=int(n); k=int(k) a=input() l=a.split() ans=0 for j in range(len(l)): lc=0 for i in range(len(l[j])): if l[j][i]=='4' or l[j][i]=='7' : lc+=1 if lc<=k : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split() ; var n : int := ("" + ((n)))->toInteger(); var k : int := ("" + ((k)))->toInteger() ; var a : String := (OclFile["System.in"]).readLine() ; var l : OclAny := a.split() ; var ans : int := 0 ; for j : Integer.subrange(0, (l)->size()-1) do ( var lc : int := 0 ; for i : Integer.subrange(0, (l[j+1])->size()-1) do ( if l[j+1][i+1] = '4' or l[j+1][i+1] = '7' then ( lc := lc + 1 ) else skip) ; if (lc->compareTo(k)) <= 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=input().split() n=int(n) k=int(k) a=input() l=a.split() counter=0 for j in range(len(l)): luckyn=0 for i in range(len(l[j])): if l[j][i]=='4' or l[j][i]=='7' : luckyn+=1 if luckyn<=k : counter+=1 print(counter) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var k : int := ("" + ((k)))->toInteger() ; var a : String := (OclFile["System.in"]).readLine() ; var l : OclAny := a.split() ; var counter : int := 0 ; for j : Integer.subrange(0, (l)->size()-1) do ( var luckyn : int := 0 ; for i : Integer.subrange(0, (l[j+1])->size()-1) do ( if l[j+1][i+1] = '4' or l[j+1][i+1] = '7' then ( luckyn := luckyn + 1 ) else skip) ; if (luckyn->compareTo(k)) <= 0 then ( counter := counter + 1 ) else skip) ; execute (counter)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=int(input()) ratings=[1200,1400,1600,1900,2100,2300,2400,2600,3000] higher=[r for r in ratings if r>R] print(higher[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ratings : Sequence := Sequence{1200}->union(Sequence{1400}->union(Sequence{1600}->union(Sequence{1900}->union(Sequence{2100}->union(Sequence{2300}->union(Sequence{2400}->union(Sequence{2600}->union(Sequence{ 3000 })))))))) ; var higher : Sequence := ratings->select(r | (r->compareTo(R)) > 0)->collect(r | (r)) ; execute (higher->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=int(input()) ratings=[1200,1400,1600,1900,2100,2300,2400,2600,3000] higher=[r for r in ratings if r>R] print(higher[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ratings : Sequence := Sequence{1200}->union(Sequence{1400}->union(Sequence{1600}->union(Sequence{1900}->union(Sequence{2100}->union(Sequence{2300}->union(Sequence{2400}->union(Sequence{2600}->union(Sequence{ 3000 })))))))) ; var higher : Sequence := ratings->select(r | (r->compareTo(R)) > 0)->collect(r | (r)) ; execute (higher->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ti,me=map(int,input().split(':')) dop_hour,dop_mins=divmod(int(input()),60) ti+=dop_hour sldstk=ti % 24 if ti>=24 : ti=sldstk me+=dop_mins if me>=60 : ti+=1 me-=60 if ti==24 : ti=0 if ti<10 : ti='0'+str(ti) if me<10 : me='0'+str(me) print(str(ti),':',str(me),sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ti : OclAny := null; var me : OclAny := null; Sequence{ti,me} := (input().split(':'))->collect( _x | (OclType["int"])->apply(_x) ) ; var dop_hour : OclAny := null; var dop_mins : OclAny := null; Sequence{dop_hour,dop_mins} := Sequence{(("" + (((OclFile["System.in"]).readLine())))->toInteger() div 60), (("" + (((OclFile["System.in"]).readLine())))->toInteger() mod 60)} ; ti := ti + dop_hour ; var sldstk : int := ti mod 24 ; if ti >= 24 then ( var ti : int := sldstk ) else skip ; me := me + dop_mins ; if me >= 60 then ( ti := ti + 1 ; me := me - 60 ; if ti = 24 then ( ti := 0 ) else skip ) else skip ; if ti < 10 then ( ti := '0' + ("" + ((ti))) ) else skip ; if me < 10 then ( var me : String := '0' + ("" + ((me))) ) else skip ; execute (("" + ((ti))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=int(input()) ratings=[1200,1400,1600,1900,2100,2300,2400,2600,3000] higher=[r for r in ratings if r>R] print(higher[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ratings : Sequence := Sequence{1200}->union(Sequence{1400}->union(Sequence{1600}->union(Sequence{1900}->union(Sequence{2100}->union(Sequence{2300}->union(Sequence{2400}->union(Sequence{2600}->union(Sequence{ 3000 })))))))) ; var higher : Sequence := ratings->select(r | (r->compareTo(R)) > 0)->collect(r | (r)) ; execute (higher->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def gcd(a,b): if(b): return gcd(b,(a % b)) else : return a List=[] for i in sys.stdin : List.append(i) for data in List : print(gcd(int(data.split()[0]),int(data.split()[1]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var List : Sequence := Sequence{} ; for i : OclFile["System.in"] do ( execute ((i) : List)) ; for data : List do ( execute (gcd(("" + ((data.split()->first())))->toInteger(), ("" + ((data.split()[1+1])))->toInteger()))->display()); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (b) then ( return gcd(b, (a mod b)) ) else ( return a ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=int(input()) ratings=[1200,1400,1600,1900,2100,2300,2400,2600,3000] higher=[r for r in ratings if r>R] print(higher[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ratings : Sequence := Sequence{1200}->union(Sequence{1400}->union(Sequence{1600}->union(Sequence{1900}->union(Sequence{2100}->union(Sequence{2300}->union(Sequence{2400}->union(Sequence{2600}->union(Sequence{ 3000 })))))))) ; var higher : Sequence := ratings->select(r | (r->compareTo(R)) > 0)->collect(r | (r)) ; execute (higher->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=int(input()) ratings=[1200,1400,1600,1900,2100,2300,2400,2600,3000] higher=[r for r in ratings if r>R] print(higher[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ratings : Sequence := Sequence{1200}->union(Sequence{1400}->union(Sequence{1600}->union(Sequence{1900}->union(Sequence{2100}->union(Sequence{2300}->union(Sequence{2400}->union(Sequence{2600}->union(Sequence{ 3000 })))))))) ; var higher : Sequence := ratings->select(r | (r->compareTo(R)) > 0)->collect(r | (r)) ; execute (higher->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getSubSeq(s,n): res="" cr=0 while(crsize() ; execute (getSubSeq(s, n))->display() ) else skip; operation getSubSeq(s : OclAny, n : OclAny) : OclAny pre: true post: true activity: var res : String := "" ; var cr : int := 0 ; while ((cr->compareTo(n)) < 0) do ( var mx : OclAny := s[cr+1] ; for i : Integer.subrange(cr + 1, n-1) do ( mx := Set{mx, s[i+1]}->max()) ; var lst : int := cr ; for i : Integer.subrange(cr, n-1) do ( if (s[i+1] = mx) then ( res := res + s[i+1] ; lst := i ) else skip) ; cr := lst + 1) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def countSteps(n): steps=0 ; while(n): largest=int(sqrt(n)); n-=(largest*largest); steps+=1 ; return steps ; if __name__=="__main__" : n=85 ; print(countSteps(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 85; ; execute (countSteps(n))->display(); ) else skip; operation countSteps(n : OclAny) pre: true post: true activity: var steps : int := 0; ; while (n) do ( var largest : int := ("" + ((sqrt(n))))->toInteger(); ; n := n - (largest * largest); ; steps := steps + 1;) ; return steps;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) if m==0 : print("YES") exit() a=list(map(int,input().split())) a.sort() if a[0]==1 or a[-1]==n : print("NO") exit() for i in range(m-2): if a[i+2]==(a[i]+2): print("NO") exit() print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if m = 0 then ( execute ("YES")->display() ; exit() ) else skip ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; if a->first() = 1 or a->last() = n then ( execute ("NO")->display() ; exit() ) else skip ; for i : Integer.subrange(0, m - 2-1) do ( if a[i + 2+1] = (a[i+1] + 2) then ( execute ("NO")->display() ; exit() ) else skip) ; execute ("YES")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys n,m=map(int,input().split()) if(m==0): print("YES") sys.exit() arr=list(map(int,input().split())) arr.sort() if(arr[0]==1 or arr[-1]==n): print("NO") sys.exit() i=0 t=True j=arr[0] while(i2): i+=1 else : t=False break if(t==False): print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (m = 0) then ( execute ("YES")->display() ; sys.exit() ) else skip ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := arr->sort() ; if (arr->first() = 1 or arr->last() = n) then ( execute ("NO")->display() ; sys.exit() ) else skip ; var i : int := 0 ; var t : boolean := true ; var j : OclAny := arr->first() ; while ((i->compareTo(m - 2)) < 0) do ( if (arr[i + 2+1] - arr[i+1] > 2) then ( i := i + 1 ) else ( t := false ; break )) ; if (t = false) then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n,k=list(map(int,input().split())) if k==0 : print("YES") return l=sorted(list(map(int,input().split()))) if l[0]==1 or l[-1]==n : print("NO") return for i in range(k-2): if l[i]==l[i+1]-1==l[i+2]-2 : print("NO") return print("YES") solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if k = 0 then ( execute ("YES")->display() ; return ) else skip ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; if l->first() = 1 or l->last() = n then ( execute ("NO")->display() ; return ) else skip ; for i : Integer.subrange(0, k - 2-1) do ( if l[i+1] = l[i + 1+1] - 1 & (l[i + 1+1] - 1 == l[i + 2+1] - 2) then ( execute ("NO")->display() ; return ) else skip) ; execute ("YES")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=[] if m!=0 : a=list(map(int,input().split())) start=1 d={} c=1 for i in range(len(a)): if a[i]==1 or a[i]==n : c=0 if c==0 : print('NO') else : flag=True a.sort() for i in range(len(a)-2): if(a[i]+1)==a[i+1]and(a[i+1]+1)==a[i+2]: flag=False break if flag : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{} ; if m /= 0 then ( a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ) else skip ; var start : int := 1 ; var d : OclAny := Set{} ; var c : int := 1 ; for i : Integer.subrange(0, (a)->size()-1) do ( if a[i+1] = 1 or a[i+1] = n then ( c := 0 ) else skip) ; if c = 0 then ( execute ('NO')->display() ) else ( var flag : boolean := true ; a := a->sort() ; for i : Integer.subrange(0, (a)->size() - 2-1) do ( if (a[i+1] + 1) = a[i + 1+1] & (a[i + 1+1] + 1) = a[i + 2+1] then ( flag := false ; break ) else skip) ; if flag then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): n,m=map(int,input().split()) if m==0 : return print("YES") arr=list(map(int,input().split())) if 1 in arr or n in arr : return print("NO") arr.sort() count=1 for i in range(1,len(arr)): if arr[i]==arr[i-1]+1 : count+=1 else : count=1 if count>2 : return print("NO") return print("YES") def main(): t=1 for _ in range(t): solution() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; main(); operation solution() : OclAny pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if m = 0 then ( return ("YES")->display() ) else skip ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (arr)->includes(1) or (arr)->includes(n) then ( return ("NO")->display() ) else skip ; arr := arr->sort() ; var count : int := 1 ; for i : Integer.subrange(1, (arr)->size()-1) do ( if arr[i+1] = arr[i - 1+1] + 1 then ( count := count + 1 ) else ( count := 1 ) ; if count > 2 then ( return ("NO")->display() ) else skip) ; return ("YES")->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os import math from collections import Counter TC=False def solve(): h,m=str(input()).split(':') add_min=int(input()) add_h=add_min//60 add_m=add_min % 60 h=int(h)+add_h m=int(m)+add_m while m>=60 : h+=1 m-=60 while h>=24 : h-=24 print('{:02d}:{:02d}'.format(h,m)) if os.path.exists('input.txt'): debug=True sys.stdin=open("input.txt","r") if TC : for _ in range(int(input())): solve() else : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var TC : boolean := false ; skip ; if os.path.exists('input.txt') then ( var debug : boolean := true ; OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ) else skip ; if TC then ( for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve()) ) else ( solve() ); operation solve() pre: true post: true activity: var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := OclType["String"]((OclFile["System.in"]).readLine()).split(':') ; var add_min : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var add_h : int := add_min div 60 ; var add_m : int := add_min mod 60 ; var h : int := ("" + ((h)))->toInteger() + add_h ; var m : int := ("" + ((m)))->toInteger() + add_m ; while m >= 60 do ( h := h + 1 ; m := m - 60) ; while h >= 24 do ( h := h - 24) ; execute (StringLib.interpolateStrings('{:02d}:{:02d}', Sequence{h, m}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def gcd(a,b): if acompareTo(b)) < 0 then ( Sequence{a,b} := Sequence{b,a} ) else skip ; if b = 0 then ( return a ) else skip ; return gcd(a mod b, b); operation solution() : OclAny pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{a,b,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a / b = x / y then ( execute ("0/1")->display() ; return; ) else skip ; if (a / b->compareTo(x / y)) < 0 then ( var u : double := a * y ; var l : double := b * x ; u := l - u ; var g : OclAny := gcd(u, l) ; execute (("" + ((u div g))) + '/' + ("" + ((l div g))))->display() ) else ( u := b * x ; l := a * y ; u := l - u ; g := gcd(u, l) ; execute (("" + ((u div g))) + '/' + ("" + ((l div g))))->display() ); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isDefeat(s1,s2,n): for i in range(n): if((s1[i]=='0' and s2[i]=='1')or(s1[i]=='1' and s2[i]=='0')): continue elif((s1[i]=='0' and s2[i]=='Z')or(s1[i]=='Z' and s2[i]=='0')): continue else : return True return False s1="01001101ZZ" s2="10Z1001000" n=10 if(isDefeat(s1,s2,n)): print("Defeat") else : print("Victory") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s1 := "01001101ZZ" ; s2 := "10Z1001000" ; n := 10 ; if (isDefeat(s1, s2, n)) then ( execute ("Defeat")->display() ) else ( execute ("Victory")->display() ); operation isDefeat(s1 : OclAny, s2 : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if ((s1[i+1] = '0' & s2[i+1] = '1') or (s1[i+1] = '1' & s2[i+1] = '0')) then ( continue ) else (if ((s1[i+1] = '0' & s2[i+1] = 'Z') or (s1[i+1] = 'Z' & s2[i+1] = '0')) then ( continue ) else ( return true ) ) ) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def first(arr,low,high,x,n): if(high>=low): mid=low+(high-low)//2 if((mid==0 or x>arr[mid-1])and arr[mid]==x): return mid elif(x>arr[mid]): return first(arr,(mid+1),high,x,n) else : return first(arr,low,(mid-1),x,n) return-1 def last(arr,low,high,x,n): if(high>=low): mid=low+(high-low)//2 if((mid==n-1 or xunion(Sequence{1}->union(Sequence{21}->union(Sequence{4}->union(Sequence{2}->union(Sequence{1}->union(Sequence{8}->union(Sequence{ 9 }))))))) ; n := (arr)->size() ; execute (fibonacciArray(arr, n))->display() ) else skip; operation fibonacciArray(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var s : Set := Set{}->union(()) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{1,1} ; execute ((a) : s) ; if n >= 2 then ( execute ((b) : s) ) else skip ; for i : Integer.subrange(0, n - 2-1) do ( var c : OclAny := a + b ; execute ((c) : s) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,c}) ; for i : Integer.subrange(0, n-1) do ( if (s)->includes(arr[i+1]) then ( execute ((arr[i+1]) /: s) ) else skip) ; return (s)->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sieve=[True]*110000 primes=[] for i in range(2,110000): if sieve[i]==True : primes.append(i) for j in range(2*i,110000,i): sieve[j]=False while True : n,p=map(int,input().split()) if n==-1 and p==-1 : break cnt=0 for i in primes : if nselect( $x | ($x - 2 * i) mod i = 0 ) do ( sieve[j+1] := false) ) else skip) ; while true do ( var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = -1 & p = -1 then ( break ) else skip ; var cnt : int := 0 ; for i : primes do ( if (n->compareTo(i)) < 0 then ( break ) else ( cnt := cnt + 1 )) ; var psum : Sequence := Integer.subrange(cnt, cnt + p-1)->select(j; i : Integer.subrange(j, cnt + p-1) | true)->collect(j; i : Integer.subrange(j, cnt + p-1) | (primes[i+1] + primes[j+1]))->sort() ; execute (psum[p - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import itertools def sieve_of_erastosthenes(num): input_list=[False if i % 2==0 or i % 3==0 or i % 5==0 else True for i in range(num)] input_list[0]=input_list[1]=False input_list[2]=input_list[3]=input_list[5]=True sqrt=math.sqrt(num) for serial in range(3,num,2): if serial>=sqrt : return input_list for s in range(serial**2,num,serial): input_list[s]=False primeTable=sieve_of_erastosthenes(10**6) while True : N,P=map(int,input().split(" ")) if N==-1 and P==-1 : break start=N+1 while primeTable[start]is False : start+=1 prime_list=[] count=0 i=0 while count!=P : if primeTable[start+i]: prime_list.append(start+i) count+=1 i+=1 print(sorted([sum(t)for t in itertools.combinations_with_replacement(prime_list,2)])[P-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var primeTable : OclAny := sieve_of_erastosthenes((10)->pow(6)) ; while true do ( var N : OclAny := null; var P : OclAny := null; Sequence{N,P} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; if N = -1 & P = -1 then ( break ) else skip ; var start : OclAny := N + 1 ; while primeTable[start+1] <>= false do ( start := start + 1) ; var prime_list : Sequence := Sequence{} ; var count : int := 0 ; var i : int := 0 ; while count /= P do ( if primeTable[start + i+1] then ( execute ((start + i) : prime_list) ; count := count + 1 ) else skip ; i := i + 1) ; execute (sorted(itertools.combinations_with_replacement(prime_list, 2)->select(t | true)->collect(t | ((t)->sum())))[P - 1+1])->display()); operation sieve_of_erastosthenes(num : OclAny) : OclAny pre: true post: true activity: var input_list : Sequence := Integer.subrange(0, num-1)->select(i | true)->collect(i | (if i mod 2 = 0 or i mod 3 = 0 or i mod 5 = 0 then false else true endif)) ; input_list->first() := false; var input_list[1+1] : boolean := false ; input_list[2+1] := input_list[2+1](assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name input_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 3))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name input_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 5))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name True))))))))) ; var sqrt : double := (num)->sqrt() ; for serial : Integer.subrange(3, num-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if (serial->compareTo(sqrt)) >= 0 then ( return input_list ) else skip ; for s : Integer.subrange((serial)->pow(2), num-1)->select( $x | ($x - (serial)->pow(2)) mod serial = 0 ) do ( input_list[s+1] := false)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def eratosthenes(n): prime_table=[False,False,True]+[False if i % 2!=0 else True for i in range(n-2)] i=3 pn=[2] while i*i<=n : if prime_table[i]: j=i*i pn.append(i) while j<=n : prime_table[j]=False j+=i i+=2 for j in range(i,n+1): if prime_table[j]: pn.append(j) return pn prime_numbers=eratosthenes(200000) while 1 : n,p=map(int,input().split()) if n==-1 : break i=0 while prime_numbers[i]<=n : i+=1 d=[] for j in range(i,i+30): for k in range(j,i+30): d.append(prime_numbers[j]+prime_numbers[k]) d.sort() print(d[p-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var prime_numbers : OclAny := eratosthenes(200000) ; while 1 do ( var p : OclAny := null; Sequence{n,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = -1 then ( break ) else skip ; i := 0 ; while (prime_numbers[i+1]->compareTo(n)) <= 0 do ( i := i + 1) ; var d : Sequence := Sequence{} ; for j : Integer.subrange(i, i + 30-1) do ( for k : Integer.subrange(j, i + 30-1) do ( execute ((prime_numbers[j+1] + prime_numbers[k+1]) : d))) ; d := d->sort() ; execute (d[p - 1+1])->display()); operation eratosthenes(n : OclAny) : OclAny pre: true post: true activity: var prime_table : Sequence := Sequence{false}->union(Sequence{false}->union(Sequence{ true }))->union(Integer.subrange(0, n - 2-1)->select(i | true)->collect(i | (if i mod 2 /= 0 then false else true endif))) ; var i : int := 3 ; var pn : Sequence := Sequence{ 2 } ; while (i * i->compareTo(n)) <= 0 do ( if prime_table[i+1] then ( var j : int := i * i ; execute ((i) : pn) ; while (j->compareTo(n)) <= 0 do ( prime_table[j+1] := false ; j := j + i) ) else skip ; i := i + 2) ; for j : Integer.subrange(i, n + 1-1) do ( if prime_table[j+1] then ( execute ((j) : pn) ) else skip) ; return pn; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import sqrt from bisect import bisect inf=1<<30 def solve(): primes=eratos(2*10**5) while 1 : N,P=map(int,sys.stdin.readline().split()) if N==P==-1 : return j=bisect(primes,N) lprimes=primes[j : j+100] made=[] for i in range(100): for j in range(i,100): made.append(lprimes[i]+lprimes[j]) made.sort() ans=made[P-1] print(ans) def eratos(n): s=[True]*n s[0]=s[1]=False for p in range(2,int(sqrt(n))+1): if s[p]: for q in range(p*p,n,p): s[q]=False return[i for i in range(2,n)if s[i]] if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var Math_PINFINITY : int := 1 * (2->pow(30)) ; skip ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var primes : OclAny := eratos(2 * (10)->pow(5)) ; while 1 do ( var N : OclAny := null; var P : OclAny := null; Sequence{N,P} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if N = P & (P == -1) then ( return ) else skip ; var j : OclAny := bisect(primes, N) ; var lprimes : OclAny := primes.subrange(j+1, j + 100) ; var made : Sequence := Sequence{} ; for i : Integer.subrange(0, 100-1) do ( for j : Integer.subrange(i, 100-1) do ( execute ((lprimes[i+1] + lprimes[j+1]) : made))) ; made := made->sort() ; var ans : OclAny := made[P - 1+1] ; execute (ans)->display()); operation eratos(n : OclAny) : OclAny pre: true post: true activity: var s : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, n) ; s->first() := false; var s[1+1] : boolean := false ; for p : Integer.subrange(2, ("" + ((sqrt(n))))->toInteger() + 1-1) do ( if s[p+1] then ( for q : Integer.subrange(p * p, n-1)->select( $x | ($x - p * p) mod p = 0 ) do ( s[q+1] := false) ) else skip) ; return Integer.subrange(2, n-1)->select(i | s[i+1])->collect(i | (i)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import* N=101198 ; n=range(N); a=list(n); a[1]=0 for i in range(2,int(N**.5)+1): a[i*2 : : i]=[0]*len(a[i*2 : : i]) for e in iter(input,'-1-1'): qN,qP=map(int,e.split()) p=[x for x in a[qN+1 :]if x][: qP+1] print(sorted(p[i]+p[j]for i in range(qP)for j in range(i,qP))[qP-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 101198; var n : Sequence := Integer.subrange(0, N-1); var a : Sequence := (n); a[1+1] := 0 ; for i : Integer.subrange(2, ("" + (((N)->pow(.5))))->toInteger() + 1-1) do ( a(subscript (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom (number (integer 2)))))))) : (sliceop : (test (logical_test (comparison (expr (atom (name i)))))))) := MatrixLib.elementwiseMult(Sequence{ 0 }, (a(subscript (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom (number (integer 2)))))))) : (sliceop : (test (logical_test (comparison (expr (atom (name i)))))))))->size())) ; for e : OclIterator.newOclIterator_Sequence(input, '-1-1') do ( var qN : OclAny := null; var qP : OclAny := null; Sequence{qN,qP} := (e.split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : OclAny := a.subrange(qN + 1+1)->select(x | x)->collect(x | (x)).subrange(1,qP + 1) ; execute (sorted((argument (test (logical_test (comparison (expr (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name qP)))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (name qP)))))))) )))))))))))[qP - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) lst=input().split() s=set() x=0 v=[] va=[] for i in reversed(lst): if i not in s : s.add(i) x+=1 v.append(x) for j in range(m): l=int(input()) answer=v[n-l] va.append(answer) print(*va,sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lst : OclAny := input().split() ; var s : Set := Set{}->union(()) ; var x : int := 0 ; var v : Sequence := Sequence{} ; var va : Sequence := Sequence{} ; for i : (lst)->reverse() do ( if (s)->excludes(i) then ( execute ((i) : s) ; x := x + 1 ) else skip ; execute ((x) : v)) ; for j : Integer.subrange(0, m-1) do ( var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var answer : OclAny := v[n - l+1] ; execute ((answer) : va)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name va))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(i)for i in input().split()] a=[int(i)for i in input().split()] b=set() for i in range(n): b.add(a[~ i]) a[~ i]=len(b) for i in range(m): inp=int(input()) print(a[inp-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var b : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( execute ((a[MathLib.bitwiseNot(i)+1]) : b) ; a[MathLib.bitwiseNot(i)+1] := (b)->size()) ; for i : Integer.subrange(0, m-1) do ( var inp : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (a[inp - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dic={} S=list(input()) for s in S : if s not in dic : dic[s]=1 else : dic[s]+=1 ans=0 for k in list(dic.keys()): if dic[k]& 1 : ans+=1 print(ans>>1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dic : OclAny := Set{} ; var S : Sequence := ((OclFile["System.in"]).readLine())->characters() ; for s : S do ( if (dic)->excludes(s) then ( dic[s+1] := 1 ) else ( dic[s+1] := dic[s+1] + 1 )) ; var ans : int := 0 ; for k : (dic.keys()) do ( if MathLib.bitwiseAnd(dic[k+1], 1) then ( ans := ans + 1 ) else skip) ; execute (ans /(2->pow(1)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,m=map(int,input().split(':')) a=(int(input())+h*60+m)% 1440 print(f'{a//60:02}:{a%60:02}') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := (input().split(':'))->collect( _x | (OclType["int"])->apply(_x) ) ; var a : int := (("" + (((OclFile["System.in"]).readLine())))->toInteger() + h * 60 + m) mod 1440 ; execute (StringLib.formattedString('{a//60:02}:{a%60:02}'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) array=list(map(int,input().split())) positions=[] for _ in range(m): positions.append(int(input())) p_dict=dict.fromkeys(positions) numbers=set() for i in range(n-1,-1,-1): numbers.add(array[i]) distinctof_i=len(numbers) if i+1 in p_dict.keys(): p_dict[i+1]=distinctof_i for position in positions : print(p_dict[position]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var array : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var positions : Sequence := Sequence{} ; for _anon : Integer.subrange(0, m-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : positions)) ; var p_dict : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name positions)))))))) ))) ; var numbers : Set := Set{}->union(()) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( execute ((array[i+1]) : numbers) ; var distinctof_i : int := (numbers)->size() ; if (p_dict.keys())->includes(i + 1) then ( p_dict[i + 1+1] := distinctof_i ) else skip) ; for position : positions do ( execute (p_dict[position+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(_)for _ in input().split()] a=list(map(int,input().split())) l=dict() d=[0]*n for i in range(n): if a[i]in l : l[a[i]]+=1 else : l[a[i]]=1 for i in range(n): if a[i]in l : if l[a[i]]==1 : l.pop(a[i]) d[i]+=1 else : l[a[i]]-=1 d[i]+=len(l) for i in range(m): print(d[int(input())-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : Map := (arguments ( )) ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( if (l)->includes(a[i+1]) then ( l[a[i+1]+1] := l[a[i+1]+1] + 1 ) else ( l[a[i+1]+1] := 1 )) ; for i : Integer.subrange(0, n-1) do ( if (l)->includes(a[i+1]) then ( if l[a[i+1]+1] = 1 then ( l := l->excludingAt(a[i+1]+1) ; d[i+1] := d[i+1] + 1 ) else ( l[a[i+1]+1] := l[a[i+1]+1] - 1 ) ) else skip ; d[i+1] := d[i+1] + (l)->size()) ; for i : Integer.subrange(0, m-1) do ( execute (d[("" + (((OclFile["System.in"]).readLine())))->toInteger() - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=list(map(int,input().split())) answer="" count=0 rem=set() l_to_a={} for i in range(n): if a[n-1-i]not in rem : count+=1 rem.add(a[n-1-i]) l_to_a[n-i]=count for j in range(m): l=int(input()) answer+="%d\n" %(l_to_a[l]) print(answer.strip()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var answer : String := "" ; var count : int := 0 ; var rem : Set := Set{}->union(()) ; var l_to_a : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( if (rem)->excludes(a[n - 1 - i+1]) then ( count := count + 1 ) else skip ; execute ((a[n - 1 - i+1]) : rem) ; l_to_a[n - i+1] := count) ; for j : Integer.subrange(0, m-1) do ( var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; answer := answer + StringLib.format("%d\n",(l_to_a[l+1]))) ; execute (answer->trim())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100000 ; catalan=[0]*MAX ; def catalanDP(n): catalan[0]=catalan[1]=1 ; for i in range(2,n+1): catalan[i]=0 ; for j in range(i): catalan[i]+=(catalan[j]*catalan[i-j-1]); def CatalanSequence(arr,n): catalanDP(n); s=set(); a=1 ; b=1 ; s.add(a); if(n>=2): s.add(b); for i in range(2,n): s.add(catalan[i]); temp=set() for i in range(n): if arr[i]in s : temp.add(arr[i]) s=s-temp ; return len(s); if __name__=="__main__" : arr=[1,1,2,5,41]; n=len(arr) print(CatalanSequence(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 100000; ; var catalan : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX); ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{5}->union(Sequence{ 41 })))); ; n := (arr)->size() ; execute (CatalanSequence(arr, n))->display(); ) else skip; operation catalanDP(n : OclAny) pre: true post: true activity: catalan->first() := 1; var catalan[1+1] : int := 1; ; for i : Integer.subrange(2, n + 1-1) do ( catalan[i+1] := 0; ; for j : Integer.subrange(0, i-1) do ( catalan[i+1] := catalan[i+1] + (catalan[j+1] * catalan[i - j - 1+1]);)); operation CatalanSequence(arr : OclAny, n : OclAny) pre: true post: true activity: catalanDP(n); ; var s : Set := Set{}->union(()); ; var a : int := 1; var b : int := 1; ; execute ((a) : s); ; if (n >= 2) then ( execute ((b) : s); ) else skip ; for i : Integer.subrange(2, n-1) do ( execute ((catalan[i+1]) : s);) ; var temp : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( if (s)->includes(arr[i+1]) then ( execute ((arr[i+1]) : temp) ) else skip) ; s := s - temp; ; return (s)->size();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline h,w=map(int,input().split()) r=list(map(int,input().split())) c=list(map(int,input().split())) mod=pow(10,9)+7 x=[[]for _ in range(w)] for i in r : for j in range(i): x[j].append(1) if icollect( _x | (OclType["int"])->apply(_x) ) ; var r : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mod : double := (10)->pow(9) + 7 ; var x : Sequence := Integer.subrange(0, w-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : r do ( for j : Integer.subrange(0, i-1) do ((expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ))))) ; if (i->compareTo(w)) < 0 then ( (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))) ) else skip ; for j : Integer.subrange(i + 1, w-1) do ((expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))) ; var ans : int := 1 ; for _tuple : Integer.subrange(1, c->size())->collect( _indx | Sequence{c->at(_indx), x->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); for j : Integer.subrange(0, i-1) do ( if y[j+1] = 0 then ( ans := 0 ) else skip) ; if (i->compareTo(h)) < 0 & y[i+1] = 1 then ( ans := 0 ) else skip ; for j : Integer.subrange(i + 1, h-1) do ( if y[j+1] = -1 then ( ans := ans * 2 ; ans := ans mod mod ) else skip) ; if not(ans) then ( break ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inf=float('inf') import sys import pprint import logging from logging import getLogger import array mod=int(1e9)+7 def input(): return sys.stdin.readline().rstrip("\n") def maps(): return[int(i)for i in input().split()] logging.basicConfig(format="%(message)s",level=logging.WARNING,) logger=getLogger(__name__) logger.setLevel(logging.INFO) def debug(msg,*args): logger.info(f'{msg}={pprint.pformat(args)}') H,W=maps() A=[[-1 for __ in range(W)]for _ in range(H)] R=list(maps()) C=list(maps()) for i in range(H): for j in range(min(R[i],W)): A[i][j]=1 if R[i]toReal() ; skip ; skip ; skip ; skip ; skip ; var mod : int := ("" + ((("1e9")->toReal())))->toInteger() + 7 ; skip ; skip ; logging.basicConfig((argument (test (logical_test (comparison (expr (atom (name format)))))) = (test (logical_test (comparison (expr (atom "%(message)s")))))), (arglist (argument (test (logical_test (comparison (expr (atom (name level)))))) = (test (logical_test (comparison (expr (atom (name logging)) (trailer . (name WARNING))))))) ,)) ; var logger : OclAny := getLogger(__name__) ; logger.setLevel(logging.INFO) ; skip ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := maps() ; var A : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, W-1)->select(__ | true)->collect(__ | (-1)))) ; var R : Sequence := (maps()) ; var C : Sequence := (maps()) ; for i : Integer.subrange(0, H-1) do ( for j : Integer.subrange(0, Set{R[i+1], W}->min()-1) do ( A[i+1][j+1] := 1) ; if (R[i+1]->compareTo(W)) < 0 then ( A[i+1][R[i+1]+1] := 0 ) else skip) ; var ok : int := 1 ; for i : Integer.subrange(0, W-1) do ( for j : Integer.subrange(0, Set{C[i+1], H}->min()-1) do ( if A[j+1][i+1] = 0 then ( ok := 0 ) else skip ; A[j+1][i+1] := 1) ; if (C[i+1]->compareTo(H)) < 0 then ( if A[C[i+1]+1][i+1] = 1 then ( ok := 0 ) else skip ; A[C[i+1]+1][i+1] := 0 ) else skip) ; var cnt : int := 0 ; for i : Integer.subrange(0, H-1) do ( for j : Integer.subrange(0, W-1) do ( if A[i+1][j+1] = -1 then ( cnt := cnt + 1 ) else skip)) ; execute (if ok then (2)->pow(cnt) else 0 endif)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip("\n"); operation maps() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation debug(msg : OclAny, args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) logger.info(StringLib.formattedString('{msg}={pprint.pformat(args)}')); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w=[int(z)for z in input().split()] r=[int(z)for z in input().split()] c=[int(z)for z in input().split()] mod=10**9+7 grid=[['?' for col in range(w+1)]for row in range(h+1)] def try_set(row,col,target): if grid[row][col]=='?' : grid[row][col]=target elif grid[row][col]!=target : raise ValueError def go(): try : for row in range(h): for col in range(r[row]): try_set(row,col,'FULL') try_set(row,r[row],'EMPTY') for col in range(w): for row in range(c[col]): try_set(row,col,'FULL') try_set(c[col],col,'EMPTY') except ValueError : return 0 answer=1 for row in range(h): for col in range(w): if grid[row][col]=='?' : answer=answer*2 % mod return answer print(go()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := input().split()->select(z | true)->collect(z | (("" + ((z)))->toInteger())) ; var r : Sequence := input().split()->select(z | true)->collect(z | (("" + ((z)))->toInteger())) ; var c : Sequence := input().split()->select(z | true)->collect(z | (("" + ((z)))->toInteger())) ; var mod : double := (10)->pow(9) + 7 ; var grid : Sequence := Integer.subrange(0, h + 1-1)->select(row | true)->collect(row | (Integer.subrange(0, w + 1-1)->select(col | true)->collect(col | ('?')))) ; skip ; skip ; execute (go())->display(); operation try_set(row : OclAny, col : OclAny, target : OclAny) pre: true post: true activity: if grid[row+1][col+1] = '?' then ( grid[row+1][col+1] := target ) else (if grid[row+1][col+1] /= target then ( error IncorrectElementException.newIncorrectElementException ) else skip); operation go() : OclAny pre: true post: true activity: try ( for row : Integer.subrange(0, h-1) do ( for col : Integer.subrange(0, r[row+1]-1) do ( try_set(row, col, 'FULL')) ; try_set(row, r[row+1], 'EMPTY')) ; for col : Integer.subrange(0, w-1) do ( for row : Integer.subrange(0, c[col+1]-1) do ( try_set(row, col, 'FULL')) ; try_set(c[col+1], col, 'EMPTY'))) (except_clause except (test (logical_test (comparison (expr (atom (name ValueError)))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) ; var answer : int := 1 ; for row : Integer.subrange(0, h-1) do ( for col : Integer.subrange(0, w-1) do ( if grid[row+1][col+1] = '?' then ( answer := answer * 2 mod mod ) else skip)) ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w=[int(z)for z in input().split()] r=[int(z)for z in input().split()] c=[int(z)for z in input().split()] mod=0 while(1): mod=10**9+7 break grid=[['?' for col in range(w+1)]for row in range(h+1)] def try_set(row,col,target): if grid[row][col]=='?' : grid[row][col]=target elif grid[row][col]!=target : raise ValueError def go(): try : for row in range(h): for col in range(r[row]): try_set(row,col,'FULL') try_set(row,r[row],'EMPTY') for col in range(w): for row in range(c[col]): try_set(row,col,'FULL') try_set(c[col],col,'EMPTY') except ValueError : return 0 answer=1 for row in range(h): for col in range(w): if grid[row][col]=='?' : answer=answer*2 % mod return answer print(go()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := input().split()->select(z | true)->collect(z | (("" + ((z)))->toInteger())) ; var r : Sequence := input().split()->select(z | true)->collect(z | (("" + ((z)))->toInteger())) ; var c : Sequence := input().split()->select(z | true)->collect(z | (("" + ((z)))->toInteger())) ; var mod : int := 0 ; while (1) do ( mod := (10)->pow(9) + 7 ; break) ; var grid : Sequence := Integer.subrange(0, h + 1-1)->select(row | true)->collect(row | (Integer.subrange(0, w + 1-1)->select(col | true)->collect(col | ('?')))) ; skip ; skip ; execute (go())->display(); operation try_set(row : OclAny, col : OclAny, target : OclAny) pre: true post: true activity: if grid[row+1][col+1] = '?' then ( grid[row+1][col+1] := target ) else (if grid[row+1][col+1] /= target then ( error IncorrectElementException.newIncorrectElementException ) else skip); operation go() : OclAny pre: true post: true activity: try ( for row : Integer.subrange(0, h-1) do ( for col : Integer.subrange(0, r[row+1]-1) do ( try_set(row, col, 'FULL')) ; try_set(row, r[row+1], 'EMPTY')) ; for col : Integer.subrange(0, w-1) do ( for row : Integer.subrange(0, c[col+1]-1) do ( try_set(row, col, 'FULL')) ; try_set(c[col+1], col, 'EMPTY'))) (except_clause except (test (logical_test (comparison (expr (atom (name ValueError)))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) ; var answer : int := 1 ; for row : Integer.subrange(0, h-1) do ( for col : Integer.subrange(0, w-1) do ( if grid[row+1][col+1] = '?' then ( answer := answer * 2 mod mod ) else skip)) ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w=map(int,input().split()) nli=[[0]*w for i in range(h)] r=list(map(int,input().split())) for i in range(h): if r[i]!=w : for j in range(r[i]): nli[i][j]=1 nli[i][r[i]]=2 else : for j in range(w): nli[i][j]=1 c=list(map(int,input().split())) y=0 for i in range(w): if c[i]!=h : for j in range(c[i]): if nli[j][i]!=2 : nli[j][i]=1 else : y=1 if nli[c[i]][i]==1 : y=1 else : nli[c[i]][i]=2 else : for j in range(h): if nli[j][i]!=2 : nli[j][i]=1 else : y=1 c=0 for i in range(h): for j in range(w): if nli[i][j]==0 : c+=1 mod=1000000007 if y==0 : ans=pow(2,c,mod) print(ans) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var nli : Sequence := Integer.subrange(0, h-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, w))) ; var r : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, h-1) do ( if r[i+1] /= w then ( for j : Integer.subrange(0, r[i+1]-1) do ( nli[i+1][j+1] := 1) ; nli[i+1][r[i+1]+1] := 2 ) else ( for j : Integer.subrange(0, w-1) do ( nli[i+1][j+1] := 1) )) ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var y : int := 0 ; for i : Integer.subrange(0, w-1) do ( if c[i+1] /= h then ( for j : Integer.subrange(0, c[i+1]-1) do ( if nli[j+1][i+1] /= 2 then ( nli[j+1][i+1] := 1 ) else ( y := 1 )) ; if nli[c[i+1]+1][i+1] = 1 then ( y := 1 ) else ( nli[c[i+1]+1][i+1] := 2 ) ) else ( for j : Integer.subrange(0, h-1) do ( if nli[j+1][i+1] /= 2 then ( nli[j+1][i+1] := 1 ) else ( y := 1 )) )) ; c := 0 ; for i : Integer.subrange(0, h-1) do ( for j : Integer.subrange(0, w-1) do ( if nli[i+1][j+1] = 0 then ( c := c + 1 ) else skip)) ; var mod : int := 1000000007 ; if y = 0 then ( var ans : double := (2)->pow(c) ; execute (ans)->display() ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections print(sum([v % 2 for v in collections.Counter(input()).values()])//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute ((collections.Counter((OclFile["System.in"]).readLine()).values()->select(v | true)->collect(v | (v mod 2)))->sum() div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,D=map(int,input().split()) d=list(map(int,input().split())) dp=[D]*N if abs(D-d[0])data[i+1]: data[i]=data[i+1] else : data[i]=data[i+1]+d[i] if dp[i-1]>data[i+1]: ans[i]="YES" i=0 if d[i]//2>data[i+1]: data[i]=data[i+1] else : data[i]=data[i+1]+d[i] if D>data[i+1]: ans[i]="YES" Q=int(input()) q=list(map(int,input().split())) for i in range(Q): print(ans[q[i]-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var D : OclAny := null; Sequence{N,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ D }, N) ; if ((D - d->first())->abs()->compareTo(D)) < 0 then ( dp->first() := (D - d->first())->abs() ) else skip ; for i : Integer.subrange(1, N-1) do ( dp[i+1] := Set{dp[i - 1+1], (dp[i - 1+1] - d[i+1])->abs()}->min()) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ "NO" }, N) ; var data : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; for i : Integer.subrange(0 + 1, N - 1)->reverse() do ( if (d[i+1] div 2->compareTo(data[i + 1+1])) > 0 then ( data[i+1] := data[i + 1+1] ) else ( data[i+1] := data[i + 1+1] + d[i+1] ) ; if (dp[i - 1+1]->compareTo(data[i + 1+1])) > 0 then ( ans[i+1] := "YES" ) else skip) ; var i : int := 0 ; if (d[i+1] div 2->compareTo(data[i + 1+1])) > 0 then ( data[i+1] := data[i + 1+1] ) else ( data[i+1] := data[i + 1+1] + d[i+1] ) ; if (D->compareTo(data[i + 1+1])) > 0 then ( ans[i+1] := "YES" ) else skip ; var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var q : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, Q-1) do ( execute (ans[q[i+1] - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() s=s.split(':') n=int(input()) m=int(s[1])+n h=m//60 x=m-(h*60) h=h+int(s[0]) if h>23 : h=h % 24 if len(str(h))==1 : h='0'+str(h) if len(str(x))==1 : x='0'+str(x) p=str(h)+':'+str(x) print(p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; s := s.split(':') ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := ("" + ((s[1+1])))->toInteger() + n ; var h : int := m div 60 ; var x : double := m - (h * 60) ; h := h + ("" + ((s->first())))->toInteger() ; if h > 23 then ( h := h mod 24 ) else skip ; if (("" + ((h))))->size() = 1 then ( h := '0' + ("" + ((h))) ) else skip ; if (("" + ((x))))->size() = 1 then ( x := '0' + ("" + ((x))) ) else skip ; var p : String := ("" + ((h))) + ':' + ("" + ((x))) ; execute (p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) int1=lambda x : int(x)-1 p2D=lambda x : print(*x,sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int,sys.stdin.readline().split()) def LI(): return list(map(int,sys.stdin.readline().split())) def LLI(rows_number): return[LI()for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] def main(): dn,s=MI() dd=LI() qn=II() qq=LI() qi=[(q-1,i)for i,q in enumerate(qq)] pos=[s] for d in dd : pos.append(min(pos[-1],abs(d-pos[-1]))) bb=[1]*(dn+1) for i in range(dn-1,-1,-1): d=dd[i] if d=bb[q+1]: ans[ai]="YES" else : ans[ai]="NO" print(*ans,sep="\n") main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; var p2D : Function := lambda x : OclAny in (((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ; skip ; skip ; skip ; skip ; skip ; skip ; main(); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LLI(rows_number : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows_number-1)->select(_anon | true)->collect(_anon | (LI())); operation SI() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation main() pre: true post: true activity: var dn : OclAny := null; var s : OclAny := null; Sequence{dn,s} := MI() ; var dd : OclAny := LI() ; var qn : OclAny := II() ; var qq : OclAny := LI() ; var qi : Sequence := Integer.subrange(1, (qq)->size())->collect( _indx | Sequence{_indx-1, (qq)->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let q : OclAny = _tuple->at(2) in (Sequence{q - 1, i})) ; var pos : Sequence := Sequence{ s } ; for d : dd do ( execute ((Set{pos->last(), (d - pos->last())->abs()}->min()) : pos)) ; var bb : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (dn + 1)) ; for i : Integer.subrange(-1 + 1, dn - 1)->reverse() do ( var d : OclAny := dd[i+1] ; if (d->compareTo(bb[i + 1+1] * 2)) < 0 then ( bb[i+1] := bb[i + 1+1] + d ) else ( bb[i+1] := bb[i + 1+1] )) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ "" }, qn) ; for _tuple : qi do (var _indx : int := 1; var q : OclAny := _tuple->at(_indx); _indx := _indx + 1; var ai : OclAny := _tuple->at(_indx); if (pos[q+1]->compareTo(bb[q + 1+1])) >= 0 then ( ans[ai+1] := "YES" ) else ( ans[ai+1] := "NO" )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines N,X=map(int,readline().split()) D=[0]+list(map(int,readline().split())) readline() Q=list(map(int,read().split())) start=[X]*(N+2) for n,d in enumerate(D[1 :],1): x=start[n] y=min(x,abs(x-d)) start[n+1]=y min_ng=[1]*(N+2) for n in range(N,0,-1): d=D[n] x=min_ng[n+1] y=x+d if x+x<=d : y=x min_ng[n]=y answer=['YES' if x>=y else 'NO' for x,y in zip(start,min_ng[1 :])] print('\n'.join(answer[q]for q in Q)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; var N : OclAny := null; var X : OclAny := null; Sequence{N,X} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var D : Sequence := Sequence{ 0 }->union(((readline().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; readline() ; var Q : Sequence := ((read().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var start : Sequence := MatrixLib.elementwiseMult(Sequence{ X }, (N + 2)) ; for _tuple : Integer.subrange(1, (D->tail(), 1)->size())->collect( _indx | Sequence{_indx-1, (D->tail(), 1)->at(_indx)} ) do (var _indx : int := 1; var n : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); var x : OclAny := start[n+1] ; var y : OclAny := Set{x, (x - d)->abs()}->min() ; start[n + 1+1] := y) ; var min_ng : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (N + 2)) ; for n : Integer.subrange(0 + 1, N)->reverse() do ( var d : OclAny := D[n+1] ; x := min_ng[n + 1+1] ; y := x + d ; if (x + x->compareTo(d)) <= 0 then ( y := x ) else skip ; min_ng[n+1] := y) ; var answer : Sequence := Integer.subrange(1, start->size())->collect( _indx | Sequence{start->at(_indx), min_ng->tail()->at(_indx)} )->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (if (x->compareTo(y)) >= 0 then 'YES' else 'NO' endif)) ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name answer)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name q)))))))) ])))))) (comp_for for (exprlist (expr (atom (name q)))) in (logical_test (comparison (expr (atom (name Q)))))))), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math N,D=map(int,sys.stdin.readline().rstrip().split()) ds=list(map(int,sys.stdin.readline().rstrip().split())) Q,=map(int,sys.stdin.readline().rstrip().split()) qs=list(map(int,sys.stdin.readline().rstrip().split())) targets=[1] for d in reversed(ds): if(d//2=target) if d//2collect( _x | (OclType["int"])->apply(_x) ) ; var ds : Sequence := ((sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name Q)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name Q)))))) ,)} := (sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var qs : Sequence := ((sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var targets : Sequence := Sequence{ 1 } ; for d : (ds)->reverse() do ( if ((d div 2->compareTo(targets->last())) < 0) then ( execute ((targets->last() + d) : targets) ) else ( execute ((targets->last()) : targets) )) ; targets := targets->reverse() ; var current : OclAny := D ; var can_avoids : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var d : OclAny := ds[i+1] ; var target : OclAny := targets[i + 1+1] ; execute (((current->compareTo(target)) >= 0) : can_avoids) ; if (d div 2->compareTo(current)) < 0 then ( current := current - d ; current := Set{-current, current}->max() ) else skip) ; for q : qs do ( if (can_avoids[q - 1+1]) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )) ; exit(0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,d,da,q,qa): a=[d] x=d for di in da : x=min(x,max(x-di,di-x)) a.append(x) b=[1] x=1 for i in range(n-1,-1,-1): di=da[i] if di//2max()}->min() ; execute ((x) : a)) ; var b : Sequence := Sequence{ 1 } ; x := 1 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( var di : OclAny := da[i+1] ; if (di div 2->compareTo(x)) < 0 then ( x := x + di ) else skip ; execute ((x) : b)) ; b := b->reverse() ; for qi : qa do ( if (b[qi+1]->compareTo(a[qi - 1+1])) <= 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); operation main() pre: true post: true activity: Sequence{n,d} := input().split() ; n := ("" + ((n)))->toInteger() ; d := ("" + ((d)))->toInteger() ; da := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; q := (OclFile["System.in"]).readLine() ; q := ("" + ((q)))->toInteger() ; qa := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; solve(n, d, da, q, qa); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def factorial(f): fact=1 for i in range(2,f+1): fact*=i return fact def findPermuatation(N,M): permutation=(factorial(N+M-1)//(factorial(N)*factorial(M-1))) return permutation N=3 ; M=3 print(findPermuatation(N,M)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; N := 3; M := 3 ; execute (findPermuatation(N, M))->display(); operation factorial(f : OclAny) : OclAny pre: true post: true activity: var fact : int := 1 ; for i : Integer.subrange(2, f + 1-1) do ( fact := fact * i) ; return fact; operation findPermuatation(N : OclAny, M : OclAny) : OclAny pre: true post: true activity: var permutation : int := (factorial(N + M - 1) div (factorial(N) * factorial(M - 1))) ; return permutation; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def has0(x): while(x!=0): if(x % 10==0): return 1 x=x//10 return 0 def getCount(n): count=0 for i in range(1,n+1): count=count+has0(i) return count n=107 print("Count of numbers from 1"," to ",n," is ",getCount(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 107 ; execute ("Count of numbers from 1")->display(); operation has0(x : OclAny) : OclAny pre: true post: true activity: while (x /= 0) do ( if (x mod 10 = 0) then ( return 1 ) else skip ; x := x div 10) ; return 0; operation getCount(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( count := count + has0(i)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findPivot(arr,low,high): if(highlow and arr[mid]arr[mid]): return findPivot(arr,low,mid-1); else : return findPivot(arr,mid+1,high); def isRotated(arr,n): l=0 ; r=n-1 ; pivot=-1 ; if(arr[l]>arr[r]): pivot=findPivot(arr,l,r); if(ll): if(arr[pivot]arr[pivot+1]): return False ; pivot++1 ; return True ; else : return False ; if __name__=="__main__" : arr=[3,4,5,1,2]; if(isRotated(arr,5)): print("True"); else : print("False"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{1}->union(Sequence{ 2 })))); ; if (isRotated(arr, 5)) then ( execute ("True")->display(); ) else ( execute ("False")->display(); ) ) else skip; operation findPivot(arr : OclAny, low : OclAny, high : OclAny) pre: true post: true activity: if ((high->compareTo(low)) < 0) then ( return -1; ) else skip ; if (high = low) then ( return low; ) else skip ; var mid : int := (low + high) div 2; ; if ((mid->compareTo(high)) < 0 & (arr[mid + 1+1]->compareTo(arr[mid+1])) < 0) then ( return mid; ) else skip ; if ((mid->compareTo(low)) > 0 & (arr[mid+1]->compareTo(arr[mid - 1+1])) < 0) then ( return mid - 1; ) else skip ; if ((arr[low+1]->compareTo(arr[mid+1])) > 0) then ( return findPivot(arr, low, mid - 1); ) else ( return findPivot(arr, mid + 1, high); ); operation isRotated(arr : OclAny, n : OclAny) pre: true post: true activity: var l : int := 0; ; var r : double := n - 1; ; var pivot : int := -1; ; if ((arr[l+1]->compareTo(arr[r+1])) > 0) then ( pivot := findPivot(arr, l, r); ; if ((l->compareTo(pivot)) < 0) then ( while ((pivot->compareTo(l)) > 0) do ( if ((arr[pivot+1]->compareTo(arr[pivot - 1+1])) < 0) then ( return false; ) else skip ; pivot := pivot - 1;) ) else ( pivot := pivot + 1; ; while ((pivot->compareTo(r)) < 0) do ( if ((arr[pivot+1]->compareTo(arr[pivot + 1+1])) > 0) then ( return false; ) else skip ; (expr (expr (atom (name pivot))) + (expr + (expr (atom (number (integer 1))))));) ) ; return true; ) else ( return false; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def GCD(a,b): if(b==0): return a return GCD(b,a % b) def multiplicativeOrder(A,N): if(GCD(A,N)!=1): return-1 result=1 K=1 while(Kdisplay(); operation GCD(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (b = 0) then ( return a ) else skip ; return GCD(b, a mod b); operation multiplicativeOrder(A : OclAny, N : OclAny) : OclAny pre: true post: true activity: if (GCD(A, N) /= 1) then ( return -1 ) else skip ; var result : int := 1 ; var K : int := 1 ; while ((K->compareTo(N)) < 0) do ( result := (result * A) mod N ; if (result = 1) then ( return K ) else skip ; K := K + 1) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- D,N=map(int,input().split()) T=[int(input())for i in range(D)] ABC=[list(map(int,input().split()))for i in range(N)] can=[] for t in T : mini=[] for abc in ABC : a,b,c=abc if a<=t and t<=b : mini.append(c) mini.sort() can.append([mini[0],mini[-1]]) dp=[[0,0]for i in range(D)] for i in range(1,D): o=can[i-1] m=can[i] dp[i][0]=max(dp[i-1][0]+abs(o[0]-m[0]),dp[i-1][1]+abs(o[1]-m[0])) dp[i][1]=max(dp[i-1][0]+abs(o[0]-m[1]),dp[i-1][1]+abs(o[1]-m[1])) print(max(dp[D-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var D : OclAny := null; var N : OclAny := null; Sequence{D,N} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var T : Sequence := Integer.subrange(0, D-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var ABC : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var can : Sequence := Sequence{} ; for t : T do ( var mini : Sequence := Sequence{} ; for abc : ABC do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := abc ; if (a->compareTo(t)) <= 0 & (t->compareTo(b)) <= 0 then ( execute ((c) : mini) ) else skip) ; mini := mini->sort() ; execute ((Sequence{mini->first()}->union(Sequence{ mini->last() })) : can)) ; var dp : Sequence := Integer.subrange(0, D-1)->select(i | true)->collect(i | (Sequence{0}->union(Sequence{ 0 }))) ; for i : Integer.subrange(1, D-1) do ( var o : OclAny := can[i - 1+1] ; var m : OclAny := can[i+1] ; dp[i+1]->first() := Set{dp[i - 1+1]->first() + (o->first() - m->first())->abs(), dp[i - 1+1][1+1] + (o[1+1] - m->first())->abs()}->max() ; dp[i+1][1+1] := Set{dp[i - 1+1]->first() + (o->first() - m[1+1])->abs(), dp[i - 1+1][1+1] + (o[1+1] - m[1+1])->abs()}->max()) ; execute ((dp[D - 1+1])->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin sys.setrecursionlimit(10**6) ni=lambda : int(ns()) na=lambda : list(map(int,stdin.readline().split())) nn=lambda : list(stdin.readline().split()) ns=lambda : stdin.readline().rstrip() from collections import Counter s=ns() c=Counter(s) ans=0 for i in c.values(): if i % 2==1 : ans+=1 print(ans//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stdin : OclFile := OclFile["System.in"] ; sys.setrecursionlimit((10)->pow(6)) ; var ni : Function := lambda $$ : OclAny in (("" + ((ns())))->toInteger()) ; var na : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var nn : Function := lambda $$ : OclAny in ((stdin.readLine().split())) ; var ns : Function := lambda $$ : OclAny in (stdin.readLine().rstrip()) ; skip ; var s : OclAny := ns->apply() ; var c : OclAny := Counter(s) ; var ans : int := 0 ; for i : c.values() do ( if i mod 2 = 1 then ( ans := ans + 1 ) else skip) ; execute (ans div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def primeProduct(arr,n): max_val=max(arr) prime=[True for i in range(max_val+1)] prime[0]=False prime[1]=False for p in range(mt.ceil(mt.sqrt(max_val))): if prime[p]: for i in range(p*2,max_val+1,p): prime[i]=False prod=1 for i in range(n): if prime[arr[i]]: prod*=arr[i] return prod arr=[1,2,3,4,5,6,7] n=len(arr) print(primeProduct(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 7 })))))) ; n := (arr)->size() ; execute (primeProduct(arr, n))->display(); operation primeProduct(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var max_val : OclAny := (arr)->max() ; var prime : Sequence := Integer.subrange(0, max_val + 1-1)->select(i | true)->collect(i | (true)) ; prime->first() := false ; prime[1+1] := false ; for p : Integer.subrange(0, mt.ceil(mt.sqrt(max_val))-1) do ( if prime[p+1] then ( for i : Integer.subrange(p * 2, max_val + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip) ; var prod : int := 1 ; for i : Integer.subrange(0, n-1) do ( if prime[arr[i+1]+1] then ( prod := prod * arr[i+1] ) else skip) ; return prod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import numpy as np s=input() while True : if(s!=s[: :-1]): print("No") break end=(len(s)-1)//2 e1=s[: end] if(e1!=e1[: :-1]): print("No") break start=(len(s)+3)//2-1 e2=s[start :] if(e2!=e2[: :-1]): print("No") break print("Yes") break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var s : String := (OclFile["System.in"]).readLine() ; while true do ( if (s /= s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) then ( execute ("No")->display() ; break ) else skip ; var end : int := ((s)->size() - 1) div 2 ; var e1 : OclAny := s.subrange(1,end) ; if (e1 /= e1(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) then ( execute ("No")->display() ; break ) else skip ; var start : double := ((s)->size() + 3) div 2 - 1 ; var e2 : OclAny := s.subrange(start+1) ; if (e2 /= e2(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) then ( execute ("No")->display() ; break ) else skip ; execute ("Yes")->display() ; break); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def geometricMean(arr,n): sum=0 ; for i in range(n): sum=sum+math.log(arr[i]); sum=sum/n ; return math.exp(sum); arr=[1,2,3,4,5,6,7,8]; n=len(arr); print(geometricMean(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 8 }))))))); ; n := (arr)->size(); ; execute (geometricMean(arr, n))->display();; operation geometricMean(arr : OclAny, n : OclAny) pre: true post: true activity: var sum : int := 0; ; for i : Integer.subrange(0, n-1) do ( sum := sum + (arr[i+1])->log();) ; sum := sum / n; ; return (sum)->exp();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() S2=[] S3=[] S4=[] range1=int((int(len(S))+1)/2) range2=int((int(len(S))-1)/2) range3=int((range2+1)/2) range4=int((int(len(S))+3)/2) range5=int((range4+1)/2) isStrong="Yes" for i in S : S2.append(i) for i in range(range2): S3.append(S2[i]) for i in range(range4-1,len(S)): S4.append(S2[i]) for i in range(range1): if S2[i]!=S2[-i-1]: isStrong="No" for i in range(range3): if S3[i]!=S3[-i-1]: isStrong="No" for i in range(range5-1): if S4[i]!=S4[-i-1]: isStrong="No" print(isStrong) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var S2 : Sequence := Sequence{} ; var S3 : Sequence := Sequence{} ; var S4 : Sequence := Sequence{} ; var range1 : int := ("" + (((("" + (((S)->size())))->toInteger() + 1) / 2)))->toInteger() ; var range2 : int := ("" + (((("" + (((S)->size())))->toInteger() - 1) / 2)))->toInteger() ; var range3 : int := ("" + (((range2 + 1) / 2)))->toInteger() ; var range4 : int := ("" + (((("" + (((S)->size())))->toInteger() + 3) / 2)))->toInteger() ; var range5 : int := ("" + (((range4 + 1) / 2)))->toInteger() ; var isStrong : String := "Yes" ; for i : S->characters() do ( execute ((i) : S2)) ; for i : Integer.subrange(0, range2-1) do ( execute ((S2[i+1]) : S3)) ; for i : Integer.subrange(range4 - 1, (S)->size()-1) do ( execute ((S2[i+1]) : S4)) ; for i : Integer.subrange(0, range1-1) do ( if S2[i+1] /= S2->reverse()->at(-(-i - 1)) then ( isStrong := "No" ) else skip) ; for i : Integer.subrange(0, range3-1) do ( if S3[i+1] /= S3->reverse()->at(-(-i - 1)) then ( isStrong := "No" ) else skip) ; for i : Integer.subrange(0, range5 - 1-1) do ( if S4[i+1] /= S4->reverse()->at(-(-i - 1)) then ( isStrong := "No" ) else skip) ; execute (isStrong)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): inp=lambda :[int(x)for x in input().split()] s=input() n=(len(s))//2 is_paliny=lambda a : a==a[: :-1] ans="Yes" if is_paliny(s)and is_paliny(s[: n])else "No" print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var inp : Function := lambda $$ : OclAny in (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) ; var s : String := (OclFile["System.in"]).readLine() ; var n : int := ((s)->size()) div 2 ; var is_paliny : Function := lambda a : OclAny in (a = a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ; var ans : String := if is_paliny->apply(s) & is_paliny->apply(s.subrange(1,n)) then "Yes" else "No" endif ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() n=len(S) confS=S[: :-1] flag1=False flag2=False flag3=False s1=S[0 : int((n-1)/2)] confs1=s1[: :--1] s2=S[int((n+3)/2)-1 : n] confs2=s2[: :-1] if S==confS : flag1=True if s1==confs1 : flag2=True if s2==confs2 : flag3=True if flag1 and flag2 and flag3 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var n : int := (S)->size() ; var confS : OclAny := S(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var flag1 : boolean := false ; var flag2 : boolean := false ; var flag3 : boolean := false ; var s1 : OclAny := S.subrange(0+1, ("" + (((n - 1) / 2)))->toInteger()) ; var confs1 : OclAny := s1(subscript : (sliceop : (test (logical_test (comparison (expr - (expr (atom - (number (integer 1)))))))))) ; var s2 : OclAny := S.subrange(("" + (((n + 3) / 2)))->toInteger() - 1+1, n) ; var confs2 : OclAny := s2(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; if S = confS then ( flag1 := true ) else skip ; if s1 = confs1 then ( flag2 := true ) else skip ; if s2 = confs2 then ( flag3 := true ) else skip ; if flag1 & flag2 & flag3 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() lns=len(s) def is_palindrome(si): return si==si[: :-1] print("Yes" if is_palindrome(s)and is_palindrome(s[:(lns//2)])and is_palindrome(s[(lns//2)+1 :])else "No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var lns : int := (s)->size() ; skip ; execute (if is_palindrome(s) & is_palindrome(s.subrange(1,(lns div 2))) & is_palindrome(s.subrange((lns div 2) + 1+1)) then "Yes" else "No" endif)->display(); operation is_palindrome(si : OclAny) : OclAny pre: true post: true activity: return si = si(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countUnmarked(N): if(N % 2==0): return N/2 ; else : return N/2+1 ; N=4 ; print("Number of unmarked elements:",int(countUnmarked(N))); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 4; ; execute ("Number of unmarked elements:")->display();; operation countUnmarked(N : OclAny) pre: true post: true activity: if (N mod 2 = 0) then ( return N / 2; ) else ( return N / 2 + 1; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthRoot(A,N): xPre=7 eps=1e-3 delX=10**9 xK=0 while(delX>eps): xK=((N-1.0)*xPre+A/pow(xPre,N-1))/N delX=abs(xK-xPre) xPre=xK return xK def check(no,k): kth_root=nthRoot(no,k) num=int(kth_root) if(abs(num-kth_root)<1e-4): return True return False def printExpo(arr,n,k): for i in range(n): if(check(arr[i],k)): print(arr[i],end=" ") if __name__=='__main__' : K=6 arr=[46656,64,256,729,16,1000] n=len(arr) printExpo(arr,n,K) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( var K : int := 6 ; arr := Sequence{46656}->union(Sequence{64}->union(Sequence{256}->union(Sequence{729}->union(Sequence{16}->union(Sequence{ 1000 }))))) ; n := (arr)->size() ; printExpo(arr, n, K) ) else skip; operation nthRoot(A : OclAny, N : OclAny) : OclAny pre: true post: true activity: var xPre : int := 7 ; var eps : double := ("1e-3")->toReal() ; var delX : double := (10)->pow(9) ; var xK : int := 0 ; while ((delX->compareTo(eps)) > 0) do ( xK := ((N - 1.0) * xPre + A / (xPre)->pow(N - 1)) / N ; delX := (xK - xPre)->abs() ; xPre := xK) ; return xK; operation check(no : OclAny, k : OclAny) : OclAny pre: true post: true activity: var kth_root : OclAny := nthRoot(no, k) ; var num : int := ("" + ((kth_root)))->toInteger() ; if ((num - kth_root)->abs() < ("1e-4")->toReal()) then ( return true ) else skip ; return false; operation printExpo(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if (check(arr[i+1], k)) then ( execute (arr[i+1])->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : persons=int(input()) if persons==0 : break receivedlist=[] for i in range(persons): target=list(map(int,input().split())) target=target[1 :] target=set(target) receivedlist.append(target) target=list(map(int,input().split())) target=set(target[1 :]) answer=[] for i in range(len(receivedlist)): received_set=receivedlist[i] diff=target-received_set if not diff : answer.append(i+1) if len(answer)==1 : print(answer[0]) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var persons : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if persons = 0 then ( break ) else skip ; var receivedlist : Sequence := Sequence{} ; for i : Integer.subrange(0, persons-1) do ( var target : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; target := target->tail() ; target := Set{}->union((target)) ; execute ((target) : receivedlist)) ; target := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; target := Set{}->union((target->tail())) ; var answer : Sequence := Sequence{} ; for i : Integer.subrange(0, (receivedlist)->size()-1) do ( var received_set : OclAny := receivedlist[i+1] ; var diff : double := target - received_set ; if not(diff) then ( execute ((i + 1) : answer) ) else skip) ; if (answer)->size() = 1 then ( execute (answer->first())->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() cnt=[0 for _ in[0]*26] for c in s : cnt[ord(c)-ord('a')]+=1 odd=0 for i in range(26): if cnt[i]& 1 : odd+=1 print((odd>>1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26)->select(_anon | true)->collect(_anon | (0)) ; for c : s->characters() do ( cnt[(c)->char2byte() - ('a')->char2byte()+1] := cnt[(c)->char2byte() - ('a')->char2byte()+1] + 1) ; var odd : int := 0 ; for i : Integer.subrange(0, 26-1) do ( if MathLib.bitwiseAnd(cnt[i+1], 1) then ( odd := odd + 1 ) else skip) ; execute ((odd /(2->pow(1))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] while True : n=I() if n==0 : break a=[set(LI()[1 :])for _ in range(n)] s=set((LI()[1 :])) r=-1 for c,i in zip(a,range(1,n+1)): if not(s-c): if r!=-1 : r=-1 break r=i rr.append(r) return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var n : OclAny := I() ; if n = 0 then ( break ) else skip ; var a : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Set{}->union((LI()->tail())))) ; s := Set{}->union(((LI()->tail()))) ; var r : int := -1 ; for _tuple : Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), Integer.subrange(1, n + 1-1)->at(_indx)} ) do (var _indx : int := 1; var c : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); if not((s - c)) then ( if r /= -1 then ( r := -1 ; break ) else skip ; r := i ) else skip) ; execute ((r) : rr)) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy from test.support import _MemoryWatchdog BIG_NUM=2000000000 HUGE_NUM=99999999999999999 MOD=1000000007 EPS=0.000000001 sys.setrecursionlimit(100000) SIZE=105 table=[[False]*SIZE for _ in range(SIZE)] while True : N=int(input()) if N==0 : break for i in range(N): for k in range(N): table[i][k]=False for i in range(N): input_array=list(map(int,input().split())) num=input_array[0] for k in range(1,(num+1)): table[i][input_array[k]-1]=True people=list(map(int,input().split())) num=people[0] candidate=0 ans=-1 for i in range(N): FLG=True for k in range(1,num+1): if table[i][people[k]-1]==False : FLG=False break if FLG==True : candidate+=1 ans=i if candidate!=1 : print("-1") else : print("%d" %(ans+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var HUGE_NUM : int := 99999999999999999 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; sys.setrecursionlimit(100000) ; var SIZE : int := 105 ; var table : Sequence := Integer.subrange(0, SIZE-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ false }, SIZE))) ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; for i : Integer.subrange(0, N-1) do ( for k : Integer.subrange(0, N-1) do ( table[i+1][k+1] := false)) ; for i : Integer.subrange(0, N-1) do ( var input_array : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var num : OclAny := input_array->first() ; for k : Integer.subrange(1, (num + 1)-1) do ( table[i+1][input_array[k+1] - 1+1] := true)) ; var people : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; num := people->first() ; var candidate : int := 0 ; var ans : int := -1 ; for i : Integer.subrange(0, N-1) do ( var FLG : boolean := true ; for k : Integer.subrange(1, num + 1-1) do ( if table[i+1][people[k+1] - 1+1] = false then ( FLG := false ; break ) else skip) ; if FLG = true then ( candidate := candidate + 1 ; ans := i ) else skip) ; if candidate /= 1 then ( execute ("-1")->display() ) else ( execute (StringLib.format("%d",(ans + 1)))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from operator import itemgetter inf=1<<30 def solve(): while 1 : N=int(sys.stdin.readline().rstrip()) if N==0 : return p=[set(list(map(int,sys.stdin.readline().split()))[1 :])for i in range(N)] l=list(map(int,sys.stdin.readline().split()))[1 :] cnt=0 suspect=-1 for i,pi in enumerate(p,start=1): if all(li in pi for li in l): cnt+=1 suspect=i if cnt>1 : print(-1) break else : if cnt==1 : print(suspect) else : print(-1) if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var Math_PINFINITY : int := 1 * (2->pow(30)) ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: while 1 do ( var N : int := ("" + ((sys.stdin.readLine().rstrip())))->toInteger() ; if N = 0 then ( return ) else skip ; var p : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Set{}->union((OclType["Sequence"]((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))->tail())))) ; var l : OclAny := OclType["Sequence"]((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))->tail() ; var cnt : int := 0 ; var suspect : int := -1 ; (compound_stmt for (exprlist (expr (atom (name i))) , (expr (atom (name pi)))) in (testlist (test (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p))))))) , (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name all)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (comparison (expr (atom (name li)))) in (comparison (expr (atom (name pi))))))) (comp_for for (exprlist (expr (atom (name li)))) in (logical_test (comparison (expr (atom (name l)))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cnt)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name suspect)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name cnt)))) > (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name cnt)))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name suspect)))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def read(): s=input() return list(map(int,s.split())) input() x=read() x.sort() ans=104857610485761048576 for i in range(len(x)//2): ans=min(ans,x[i+len(x)//2]-x[i]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; input() ; var x : OclAny := read() ; x := x->sort() ; var ans : double := 104857610485761048576 ; for i : Integer.subrange(0, (x)->size() div 2-1) do ( ans := Set{ans, x[i + (x)->size() div 2+1] - x[i+1]}->min()) ; execute (ans)->display(); operation read() : OclAny pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; return ((s.split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if n==0 : break infos=[] for _ in range(n): info=list(map(int,input().split())) tmp=info.pop(0) infos.append(info) target=list(map(int,input().split())) tmp=target.pop(0) flag=False for i,info in enumerate(infos): for t in target : if t not in info : break else : if flag : print(-1) break else : ans=i+1 flag=True else : if flag : print(ans) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var infos : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var info : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var tmp : OclAny := info->at(0`firstArg+1) ; info := info->excludingAt(0+1) ; execute ((info) : infos)) ; var target : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; tmp := target->at(0`firstArg+1) ; target := target->excludingAt(0+1) ; var flag : boolean := false ; (compound_stmt for (exprlist (expr (atom (name i))) , (expr (atom (name info)))) in (testlist (test (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name infos)))))))) )))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name t)))) in (testlist (test (logical_test (comparison (expr (atom (name target))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name t)))) not in (comparison (expr (atom (name info))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name flag)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name flag)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name True))))))))))))))))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name flag)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def getMaximumSumWithLCMN(N): sum=0 LIM=int(math.sqrt(N)) for i in range(1,LIM+1): if(N % i==0): if(i==(N//i)): sum=sum+i else : sum=sum+(i+N//i) return sum N=12 print(getMaximumSumWithLCMN(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; N := 12 ; execute (getMaximumSumWithLCMN(N))->display(); operation getMaximumSumWithLCMN(N : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; var LIM : int := ("" + (((N)->sqrt())))->toInteger() ; for i : Integer.subrange(1, LIM + 1-1) do ( if (N mod i = 0) then ( if (i = (N div i)) then ( sum := sum + i ) else ( sum := sum + (i + N div i) ) ) else skip) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def constructLowerArray(arr,countSmaller,n): for i in range(n): countSmaller[i]=0 ; for i in range(n): for j in range(i+1,n): if(arr[j]union(Sequence{10}->union(Sequence{5}->union(Sequence{4}->union(Sequence{2}->union(Sequence{20}->union(Sequence{6}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 2 }))))))))) ; n := (arr)->size() ; var low : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; constructLowerArray(arr, low, n) ; printArray(low, n); operation constructLowerArray(arr : OclAny, countSmaller : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( countSmaller[i+1] := 0;) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if ((arr[j+1]->compareTo(arr[i+1])) < 0) then ( countSmaller[i+1] := countSmaller[i+1] + 1 ) else skip)); operation printArray(arr : OclAny, size : OclAny) pre: true post: true activity: for i : Integer.subrange(0, size-1) do ( execute (arr[i+1])->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nCr(n,r): if(r>n/2): r=n-r ; answer=1 ; for i in range(1,r+1): answer*=(n-r+i); answer/=i ; return answer ; def binomialProbability(n,k,p): return(nCr(n,k)*pow(p,k)*pow(1-p,n-k)); n=10 ; k=5 ; p=1.0/3 ; probability=binomialProbability(n,k,p); print("Probability of",k,"heads when a coin is tossed",end=" "); print(n,"times where probability of each head is",round(p,6)); print("is=",round(probability,6)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 10; ; k := 5; ; p := 1.0 / 3; ; var probability : OclAny := binomialProbability(n, k, p); ; execute ("Probability of")->display(); ; execute (n)->display(); ; execute ("is=")->display();; operation nCr(n : OclAny, r : OclAny) pre: true post: true activity: if ((r->compareTo(n / 2)) > 0) then ( r := n - r; ) else skip ; var answer : int := 1; ; for i : Integer.subrange(1, r + 1-1) do ( answer := answer * (n - r + i); ; answer := answer / i;) ; return answer;; operation binomialProbability(n : OclAny, k : OclAny, p : OclAny) pre: true post: true activity: return (nCr(n, k) * (p)->pow(k) * (1 - p)->pow(n - k));; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inputOne=int(input()) for i in range(inputOne): n=int(input())-1 a=list(map(int,input().split())) stringOne=max(max(a)*n-sum(a),-1*sum(a)% n) print(stringOne) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inputOne : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, inputOne-1) do ( var n : double := ("" + (((OclFile["System.in"]).readLine())))->toInteger() - 1 ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var stringOne : OclAny := Set{(a)->max() * n - (a)->sum(), -1 * (a)->sum() mod n}->max() ; execute (stringOne)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n=int(input()) w=sorted(map(int,input().split())) y=sum(w) x=max(w)*(n-1) if x>=y : print(x-y) else : print(n-1-y %(n-1)if y %(n-1)!=0 else 0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var y : OclAny := (w)->sum() ; var x : double := (w)->max() * (n - 1) ; if (x->compareTo(y)) >= 0 then ( execute (x - y)->display() ) else ( execute (if y mod (n - 1) /= 0 then n - 1 - y mod (n - 1) else 0 endif)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() dict={} for i in range(len(S)): if(S[i]in dict): dict[S[i]]+=1 else : dict[S[i]]=1 l=list(dict.values()) cnt=0 for i in range(len(l)): if(l[i]% 2!=0): cnt+=1 print(cnt//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var OclType["Map"] : OclAny := Set{} ; for i : Integer.subrange(0, (S)->size()-1) do ( if ((OclType["Map"])->includes(S[i+1])) then ( (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ]) := (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ]) + 1 ) else ( (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ]) := 1 )) ; var l : Sequence := ((trailer . (name values) (arguments ( ))))->keys()->asSequence() ; var cnt : int := 0 ; for i : Integer.subrange(0, (l)->size()-1) do ( if (l[i+1] mod 2 /= 0) then ( cnt := cnt + 1 ) else skip) ; execute (cnt div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def solve(): n=int(input()) arr=list(map(int,input().split())) S=sum(arr) mv=max(arr) v2=S//(n-1)+1 if S %(n-1)else S//(n-1) return(n-1)*max(mv,v2)-S for _ in range(int(input())): print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (solve())->display()); operation solve() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var S : OclAny := (arr)->sum() ; var mv : OclAny := (arr)->max() ; var v2 : int := if S mod (n - 1) then S div (n - 1) + 1 else S div (n - 1) endif ; return (n - 1) * Set{mv, v2}->max() - S; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(x,ls): s=max(max(ls),(sum(ls)+x-2)//(x-1)) return(s*(x-1)-sum(ls)) n=int(input()) for i in range(0,n): x=int(input()) ls=list(map(int,input().strip().split(' '))) print(solve(x,ls)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( x := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; ls := ((input()->trim().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; execute (solve(x, ls))->display()); operation solve(x : OclAny, ls : OclAny) : OclAny pre: true post: true activity: var s : OclAny := Set{(ls)->max(), ((ls)->sum() + x - 2) div (x - 1)}->max() ; return (s * (x - 1) - (ls)->sum()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def allBitsSetInTheGivenRange(n,l,r): num=((1<display(); operation allBitsSetInTheGivenRange(n : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var num : int := MathLib.bitwiseXor(((1 * (2->pow(r))) - 1), ((1 * (2->pow((l - 1)))) - 1)) ; var new_num : int := MathLib.bitwiseAnd(n, num) ; if (num = new_num) then ( return "Yes" ) else skip ; return "No"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split(" ")) if a==1 and b==0 and c==0 : print("Close") elif a==0 and b==1 and c==0 : print("Close") elif a==1 and b==1 and c==0 : print("Open") elif a==0 and b==0 and c==1 : print("Open") else : print("Close") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 1 & b = 0 & c = 0 then ( execute ("Close")->display() ) else (if a = 0 & b = 1 & c = 0 then ( execute ("Close")->display() ) else (if a = 1 & b = 1 & c = 0 then ( execute ("Open")->display() ) else (if a = 0 & b = 0 & c = 1 then ( execute ("Open")->display() ) else ( execute ("Close")->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=sorted(list(map(int,input().split()))) ans,s=2147483647,n>>1 for i in range(s): ans=min(ans,a[i+s]-a[i]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var ans : OclAny := null; var s : OclAny := null; Sequence{ans,s} := Sequence{2147483647,n /(2->pow(1))} ; for i : Integer.subrange(0, s-1) do ( var ans : OclAny := Set{ans, a[i + s+1] - a[i+1]}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=list(map(int,input().split())) print(["Close","Open"][l[0]*l[1]+l[2]]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (Sequence{"Close"}->union(Sequence{ "Open" })[l->first() * l[1+1] + l[2+1]+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- b_1,b_2,b_3=map(int,input().split()) if b_1==1 and b_2==1 and b_3==0 : print('Open') else : if b_1==0 and b_2==0 and b_3==1 : print('Open') else : print('Close') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var bb_1,b:= (input().split())->collect( _x | (OclType["int"])->apply(_x) ),b_3 : OclAny := null; var b:= (input().split())->collect( _x | (OclType["int"])->apply(_x) ) : OclAny := null; var b_3 : OclAny := null; Sequence{b_1,b:= (input().split())->collect( _x | (OclType["int"])->apply(_x) ),b_3} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if b var bb_1,b:= (input().split())->collect( _x | (OclType["int"])->apply(_x) ),b_3 : OclAny := null; var b:= (input().split())->collect( _x | (OclType["int"])->apply(_x) ) : OclAny := null; var b_3 : OclAny := null; Sequence{b_1,b:= (input().split())->collect( _x | (OclType["int"])->apply(_x) ),b_3} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) = 1 & b1 = 1 & b else ( if b var bb_1,b:= (input().split())->collect( _x | (OclType["int"])->apply(_x) ),b_3 : OclAny := null; var b:= (input().split())->collect( _x | (OclType["int"])->apply(_x) ) : OclAny := null; var b_3 : OclAny := null; Sequence{b_1,b:= (input().split())->collect( _x | (OclType["int"])->apply(_x) ),b_3} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) = 0 & b0 = 0 & b else ( execute ('Close')->display() ) = 1 then ( execute ('Open')->display() ) else ( execute ('Close')->display() ) ) = 0 then ( execute ('Open')->display() ) else ( if b var bb_1,b:= (input().split())->collect( _x | (OclType["int"])->apply(_x) ),b_3 : OclAny := null; var b:= (input().split())->collect( _x | (OclType["int"])->apply(_x) ) : OclAny := null; var b_3 : OclAny := null; Sequence{b_1,b:= (input().split())->collect( _x | (OclType["int"])->apply(_x) ),b_3} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) = 0 & b0 = 0 & b else ( execute ('Close')->display() ) = 1 then ( execute ('Open')->display() ) else ( execute ('Close')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() if s=="1 0 0" : print("Close") if s=="0 1 0" : print("Close") if s=="1 1 0" : print("Open") if s=="0 0 1" : print("Open") if s=="0 0 0" : print("Close") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; if s = "1 0 0" then ( execute ("Close")->display() ) else skip ; if s = "0 1 0" then ( execute ("Close")->display() ) else skip ; if s = "1 1 0" then ( execute ("Open")->display() ) else skip ; if s = "0 0 1" then ( execute ("Open")->display() ) else skip ; if s = "0 0 0" then ( execute ("Close")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=[0,1,0,0,0,0,1,0] (a,b,c)=map(int,raw_input().split()) print["Close","Open"][m[a*4+b*2+c]] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : Sequence := Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 0 }))))))) ; var Sequence{a, b, c} : Sequence := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom print) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom "Close")))))) , (subscript (test (logical_test (comparison (expr (atom "Open"))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name m)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (expr (atom (name a))) * (expr (atom (number (integer 4))))) + (expr (expr (atom (name b))) * (expr (atom (number (integer 2)))))) + (expr (atom (name c))))))))) ])))))))) ]))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def orderN(N,L,ices): upPeak=L-ices[0] downPeak=L-ices[0] peaks=[] for i in xrange(len(ices)): if itrim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; ices := xrange(N)->select(_anon | true)->collect(_anon | (("" + ((raw_input()->trim())))->toInteger())) ; orderN(N, L, ices); operation orderN(N : OclAny, L : OclAny, ices : OclAny) pre: true post: true activity: var upPeak : double := L - ices->first() ; var downPeak : double := L - ices->first() ; var peaks : Sequence := Sequence{} ; for i : xrange((ices)->size()) do ( if (i->compareTo(N - 1)) < 0 then ( if (ices[i+1]->compareTo(ices[i + 1+1])) < 0 then ( execute ((downPeak) : peaks) ; downPeak := L - ices[i + 1+1] ; upPeak := upPeak + L - ices[i + 1+1] ) else ( execute ((upPeak) : peaks) ; upPeak := L - ices[i + 1+1] ; downPeak := downPeak + L - ices[i + 1+1] ) ) else ( execute ((upPeak) : peaks) ; execute ((downPeak) : peaks) )) ; execute ((peaks)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys N=int(input()) a=[(int(v),i)for i,v in enumerate(input().split())] ao=sum([v for v,i in a if i % 2 and v>0]) ae=sum([v for v,i in a if not i % 2 and v>0]) if max(ao,ae)==0 : ai=a.index(max(a)) Ans=[1]*(ai)+list(range(N-ai,1,-1)) print(max(a)[0]) print(len(Ans)) for i in Ans : print(i) sys.exit() if ao>=ae : print(ao) yn=[i for v,i in a if i % 2 and v>0] else : print(ae) yn=[i for v,i in a if not i % 2 and v>0] listyn=[i in yn for i in range(N)] Ans=[] while not listyn[0]: Ans.append(1) listyn=listyn[1 :] while not listyn[-1]: Ans.append(len(listyn)) listyn=listyn[:-1] while True : if len(listyn)==1 : break if len(listyn)==[2,3]: Ans.append(2) break if listyn[2]: Ans.append(2) listyn=[True]+listyn[3 :] else : Ans.append(3) listyn=[True,False]+listyn[4 :] print(len(Ans)) for i in Ans : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(1, (input().split())->size())->collect( _indx | Sequence{_indx-1, (input().split())->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in (Sequence{("" + ((v)))->toInteger(), i})) ; var ao : OclAny := (a->select(_tuple | let v : OclAny = _tuple->at(1) in let i : OclAny = _tuple->at(2) in i mod 2 & v > 0)->collect(_tuple | let v : OclAny = _tuple->at(1) in let i : OclAny = _tuple->at(2) in (v)))->sum() ; var ae : OclAny := (a->select(_tuple | let v : OclAny = _tuple->at(1) in let i : OclAny = _tuple->at(2) in not(i mod 2) & v > 0)->collect(_tuple | let v : OclAny = _tuple->at(1) in let i : OclAny = _tuple->at(2) in (v)))->sum() ; if Set{ao, ae}->max() = 0 then ( var ai : int := a->indexOf((a)->max()) - 1 ; var Ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (ai))->union((Integer.subrange(1 + 1, N - ai)->reverse())) ; execute (max(a)->first())->display() ; execute ((Ans)->size())->display() ; for i : Ans do ( execute (i)->display()) ; sys.exit() ) else skip ; if (ao->compareTo(ae)) >= 0 then ( execute (ao)->display() ; var yn : Sequence := a->select(_tuple | let v : OclAny = _tuple->at(1) in let i : OclAny = _tuple->at(2) in i mod 2 & v > 0)->collect(_tuple | let v : OclAny = _tuple->at(1) in let i : OclAny = _tuple->at(2) in (i)) ) else ( execute (ae)->display() ; yn := a->select(_tuple | let v : OclAny = _tuple->at(1) in let i : OclAny = _tuple->at(2) in not(i mod 2) & v > 0)->collect(_tuple | let v : OclAny = _tuple->at(1) in let i : OclAny = _tuple->at(2) in (i)) ) ; var listyn : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | ((yn)->includes(i))) ; Ans := Sequence{} ; while not(listyn->first()) do ( execute ((1) : Ans) ; listyn := listyn->tail()) ; while not(listyn->last()) do ( execute (((listyn)->size()) : Ans) ; listyn := listyn->front()) ; while true do ( if (listyn)->size() = 1 then ( break ) else skip ; if (listyn)->size() = Sequence{2}->union(Sequence{ 3 }) then ( execute ((2) : Ans) ; break ) else skip ; if listyn[2+1] then ( execute ((2) : Ans) ; listyn := Sequence{ true }->union(listyn.subrange(3+1)) ) else ( execute ((3) : Ans) ; listyn := Sequence{true}->union(Sequence{ false })->union(listyn.subrange(4+1)) )) ; execute ((Ans)->size())->display() ; for i : Ans do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq n,l=map(int,raw_input().split()) a=[[0,0]]+[[0,i]for i in xrange(n)]+[[0,n+1]] for i in xrange(n): en=int(raw_input()) a[i]=[-en,i] pq=[] for i in xrange(n+2): heapq.heappush(pq,a[i]) ti=[0]*(n+2) while 1 : p,i=heapq.heappop(pq) p=-p if p==0 : break ti[i]+=l-p a[i][0]=0 if a[i-1][0]!=0 : ti[i-1]=max(ti[i-1],ti[i]) if a[i+1][0]!=0 : ti[i+1]=max(ti[i+1],ti[i]) print(max(ti)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var l : OclAny := null; Sequence{n,l} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{ Sequence{0}->union(Sequence{ 0 }) }->union(xrange(n)->select(i | true)->collect(i | (Sequence{0}->union(Sequence{ i }))))->union(Sequence{ Sequence{0}->union(Sequence{ n + 1 }) }) ; for i : xrange(n) do ( var en : int := ("" + ((raw_input())))->toInteger() ; a[i+1] := Sequence{-en}->union(Sequence{ i })) ; var pq : Sequence := Sequence{} ; for i : xrange(n + 2) do ( heapq.heappush(pq, a[i+1])) ; var ti : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 2)) ; while 1 do ( var p : OclAny := null; var i : OclAny := null; Sequence{p,i} := heapq.heappop(pq) ; var p : OclAny := -p ; if p = 0 then ( break ) else skip ; ti[i+1] := ti[i+1] + l - p ; a[i+1]->first() := 0 ; if a[i - 1+1]->first() /= 0 then ( ti[i - 1+1] := Set{ti[i - 1+1], ti[i+1]}->max() ) else skip ; if a[i + 1+1]->first() /= 0 then ( ti[i + 1+1] := Set{ti[i + 1+1], ti[i+1]}->max() ) else skip) ; execute ((ti)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n,l=map(int,input().split()) ans=0 pre=0 prepre=0 acc=0 for i in range(n): length=int(input()) time=l-length if length>pre and pre>=prepre : acc+=time elif length

collect( _x | (OclType["int"])->apply(_x) ) ;
    var ans : int := 0 ;
    var pre : int := 0 ;
    var prepre : int := 0 ;
    var acc : int := 0 ;
(compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name length)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name time)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name l))) - (expr (atom (name length))))))))))))) (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name length)))) > (comparison (expr (atom (name pre)))))) and (logical_test (comparison (comparison (expr (atom (name pre)))) >= (comparison (expr (atom (name prepre)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name acc)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name time)))))))))))) (elif_clause elif (test (logical_test (logical_test (comparison (comparison (expr (atom (name length)))) < (comparison (expr (atom (name pre)))))) and (logical_test (comparison (comparison (expr (atom (name pre)))) <= (comparison (expr (atom (name prepre)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name acc)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name time))))))))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name ans)))) < (comparison (expr (atom (name acc))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name acc))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name acc)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name time))) + (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name l))) - (expr (atom (name pre)))))))) ))))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name prepre)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name pre)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name pre)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name length))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans))))))) , (argument (test (logical_test (comparison (expr (atom (name acc)))))))) )))))))))))))))) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,l=map(int,input().split())
ai=[[int(input()),i]for i in range(n)]
ai.sort(key=lambda x : x[0])
time=[0]*(n+2)
for i in ai :
    idx=i[1]
    time[idx+1]=max(time[idx],time[idx+2])+l-i[0]
print(max(time))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var l : OclAny := null;
    Sequence{n,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var ai : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger()}->union(Sequence{ i }))) ;
    ai := ai->sort() ;
    var time : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 2)) ;
    for i : ai do (    var idx : OclAny := i[1+1] ;
    time[idx + 1+1] := Set{time[idx+1], time[idx + 2+1]}->max() + l - i->first()) ;
    execute ((time)->max())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def solve():
    n,l=map(int,input().split())
    ans=0
    pre=0
    up_acc=0
    down_acc=0
    for i in range(n):
        length=int(input())
        time=l-length
        if length>pre :
            up_acc+=time
            if down_acc>ans :
                ans=down_acc
            down_acc=time
        else :
            down_acc+=time
            if up_acc>ans :
                ans=up_acc
            up_acc=time
        pre=length
    else :
        ans=max(ans,up_acc,down_acc)
    print(ans)
solve()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    solve();
  operation solve()
  pre: true post: true
  activity:
    var n : OclAny := null;
    var l : OclAny := null;
    Sequence{n,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var ans : int := 0 ;
    var pre : int := 0 ;
    var up_acc : int := 0 ;
    var down_acc : int := 0 ;
(compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name length)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name time)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name l))) - (expr (atom (name length))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name length)))) > (comparison (expr (atom (name pre))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name up_acc)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name time))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name down_acc)))) > (comparison (expr (atom (name ans))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name down_acc))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name down_acc)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name time))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name down_acc)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name time))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name up_acc)))) > (comparison (expr (atom (name ans))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name up_acc))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name up_acc)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name time)))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name pre)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name length))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans))))))) , (argument (test (logical_test (comparison (expr (atom (name up_acc))))))) , (argument (test (logical_test (comparison (expr (atom (name down_acc)))))))) )))))))))))))))) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
[A,B,C,D]=input().split(' ')
A=int(A)
B=int(B)
C=int(C)
D=int(D)
turn=0
while True :
    if A<=0 :
        print('No')
        break
    if C<=0 :
        print('Yes')
        break
    if turn==0 :
        C=C-B
        turn=1
    else :
        A=A-D
        turn=0
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     Sequence{A}->union(Sequence{B}->union(Sequence{C}->union(Sequence{ D }))) := input().split(' ') ;
    var A : int := ("" + ((A)))->toInteger() ;
    var B : int := ("" + ((B)))->toInteger() ;
    var C : int := ("" + ((C)))->toInteger() ;
    var D : int := ("" + ((D)))->toInteger() ;
    var turn : int := 0 ;
    while true do (    if A <= 0 then (
      execute ('No')->display() ;
    break
    ) else skip ;
    if C <= 0 then (
      execute ('Yes')->display() ;
    break
    ) else skip ;
    if turn = 0 then  (
      C := C - B ;
    turn := 1
    )
    else (
      A := A - D ;
    turn := 0
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    N,M,s,g1,g2=map(int,input().split())
    if N==M==s==g1==g2==0 :
        break
    s,g1,g2=s-1,g1-1,g2-1
    INF=10**5
    D=[[INF]*N for _ in range(N)]
    for i in range(N):
        D[i][i]=0
    for _ in range(M):
        b1,b2,c=map(int,input().split())
        b1,b2=b1-1,b2-1
        D[b1][b2]=c
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if D[i][j]>D[i][k]+D[k][j]:
                    D[i][j]=D[i][k]+D[k][j]
    print(min(D[s][i]+D[i][g1]+D[i][g2]for i in range(N)))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    var N : OclAny := null;
    var M : OclAny := null;
    var s : OclAny := null;
    var g1 : OclAny := null;
    var g2 : OclAny := null;
    Sequence{N,M,s,g1,g2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if N = M & (M == s) & (s == g1) & (g1 == g2) & (g2 == 0) then (
      break
    ) else skip ;
    var s : OclAny := null;
    var g1 : OclAny := null;
    var g2 : OclAny := null;
    Sequence{s,g1,g2} := Sequence{s - 1,g1 - 1,g2 - 1} ;
    var INF : double := (10)->pow(5) ;
    var D : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ INF }, N))) ;
    for i : Integer.subrange(0, N-1) do (    D[i+1][i+1] := 0) ;
    for _anon : Integer.subrange(0, M-1) do (    var b1 : OclAny := null;
    var b2 : OclAny := null;
    var c : OclAny := null;
    Sequence{b1,b2,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var b1 : OclAny := null;
    var b2 : OclAny := null;
    Sequence{b1,b2} := Sequence{b1 - 1,b2 - 1} ;
    D[b1+1][b2+1] := c) ;
    for k : Integer.subrange(0, N-1) do (    for i : Integer.subrange(0, N-1) do (    for j : Integer.subrange(0, N-1) do (    if (D[i+1][j+1]->compareTo(D[i+1][k+1] + D[k+1][j+1])) > 0 then (
      D[i+1][j+1] := D[i+1][k+1] + D[k+1][j+1]
    ) else skip))) ;
    execute (((argument (test (logical_test (comparison (expr (expr (expr (atom (name D)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name D)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name g1)))))))) ])))) + (expr (atom (name D)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name g2)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))))->min())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
n=n>>1
a=list(map(int,input().split()))
a.sort()
ans=float('inf')
for i in range(n):
    j=i+n
    ans=min(ans,a[j]-a[i])
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    n := n /(2->pow(1)) ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    a := a->sort() ;
    var ans : double := ("" + (('inf')))->toReal() ;
    for i : Integer.subrange(0, n-1) do (    var j : OclAny := i + n ;
    ans := Set{ans, a[j+1] - a[i+1]}->min()) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b,c,d=map(int,input().split())
for _ in range(100):
    a-=d
    c-=b
    if c<1 :
        print("Yes")
        exit()
    if a<1 :
        print("No")
        exit()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    var d : OclAny := null;
    Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    for _anon : Integer.subrange(0, 100-1) do (    a := a - d ;
    c := c - b ;
    if c < 1 then (
      execute ("Yes")->display() ;
    exit()
    ) else skip ;
    if a < 1 then (
      execute ("No")->display() ;
    exit()
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def resolve():
    a,b,c,d=map(int,input().split())
    ta=a//d
    ea=c//b
    if a % d :
        ta+=1
    if c % b :
        ea+=1
    if ta>=ea :
        print('Yes')
    else :
        print('No')
resolve()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    resolve();
  operation resolve()
  pre: true post: true
  activity:
    var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    var d : OclAny := null;
    Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var ta : int := a div d ;
    var ea : int := c div b ;
    if a mod d then (
      ta := ta + 1
    ) else skip ;
    if c mod b then (
      ea := ea + 1
    ) else skip ;
    if (ta->compareTo(ea)) >= 0 then  (
      execute ('Yes')->display()
    )
    else (
      execute ('No')->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
import math
a,b,c,d=map(int,input().split())
t=math.ceil(a/d)
ao=math.ceil(c/b)
if(tcollect( _x | (OclType["int"])->apply(_x) ) ;
    var t : double := (a / d)->ceil() ;
    var ao : double := (c / b)->ceil() ;
    if ((t->compareTo(ao)) < 0) then  (
      execute ('No')->display()
    )
    else (
      execute ('Yes')->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def solve(n,aaa):
    odd_idx,even_idx=[],[]
    odd_sum,even_sum=0,0
    for i in range(0,n,2):
        if aaa[i]>0 :
            even_idx.append(i)
            even_sum+=aaa[i]
    for i in range(1,n,2):
        if aaa[i]>0 :
            odd_idx.append(i)
            odd_sum+=aaa[i]
    if odd_sumtoInteger() ;
    aaa := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    Sequence{ans,buf} := solve(n, aaa) ;
    execute (ans)->display() ;
    execute ((buf)->size())->display() ;
    execute (StringLib.sumStringsWithSeparator(((buf)->collect( _x | (OclType["String"])->apply(_x) )), '
'))->display();
  operation solve(n : OclAny, aaa : OclAny) : OclAny
  pre: true post: true
  activity:
    var odd_idx : OclAny := null;
    var even_idx : OclAny := null;
    Sequence{odd_idx,even_idx} := Sequence{Sequence{},Sequence{}} ;
    var odd_sum : OclAny := null;
    var even_sum : OclAny := null;
    Sequence{odd_sum,even_sum} := Sequence{0,0} ;
    for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do (    if aaa[i+1] > 0 then (
      execute ((i) : even_idx) ;
    even_sum := even_sum + aaa[i+1]
    ) else skip) ;
    for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 2 = 0 ) do (    if aaa[i+1] > 0 then (
      execute ((i) : odd_idx) ;
    odd_sum := odd_sum + aaa[i+1]
    ) else skip) ;
    if (odd_sum->compareTo(even_sum)) < 0 then  (
      var ans : OclAny := even_sum ;
    var idx : OclAny := even_idx
    )
    else (
      ans := odd_sum ;
    idx := odd_idx
      ) ;
    if ans = 0 then (
      skip ;
    var i : (trailer . (name argmax) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name aaa)))))))) ))) :=  ;
    ans := aaa[i+1] ;
    var buf : Sequence := (Integer.subrange(i + 1 + 1, n)->reverse())->union(MatrixLib.elementwiseMult(Sequence{ 1 }, i)) ;
    return ans, buf
    ) else skip ;
    var j : OclAny := idx->last() ;
    buf := (Integer.subrange(j + 1 + 1, n)->reverse()) ;
    for i : idx(subscript (test (logical_test (comparison (expr (atom - (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do (    buf := buf->union(Integer.subrange(i + 1 + 1, (i + j) div 2 + 1)->reverse()) ;
    j := i) ;
    buf := buf + MatrixLib.elementwiseMult(Sequence{ 1 }, idx->first()) ;
    return ans, buf;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
line=input().split(" ")
hp_t=int(line[0])
at_t=int(line[1])
hp_a=int(line[2])
at_a=int(line[3])
hp_now_t=hp_t
hp_now_a=hp_a
while(1):
    hp_now_a=hp_now_a-at_t
    if hp_now_a<=0 :
        print("Yes")
        break
    hp_now_t=hp_now_t-at_a
    if hp_now_t<=0 :
        print("No")
        break
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var line : OclAny := input().split(" ") ;
    var hp_t : int := ("" + ((line->first())))->toInteger() ;
    var at_t : int := ("" + ((line[1+1])))->toInteger() ;
    var hp_a : int := ("" + ((line[2+1])))->toInteger() ;
    var at_a : int := ("" + ((line[3+1])))->toInteger() ;
    var hp_now_t : int := hp_t ;
    var hp_now_a : int := hp_a ;
    while (1) do (    hp_now_a := hp_now_a - at_t ;
    if hp_now_a <= 0 then (
      execute ("Yes")->display() ;
    break
    ) else skip ;
    hp_now_t := hp_now_t - at_a ;
    if hp_now_t <= 0 then (
      execute ("No")->display() ;
    break
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import defaultdict
maxlen=100
def generateSubStrings(s,mpp):
    l=len(s)
    for i in range(0,l):
        temp=""
        for j in range(i,l):
            temp+=s[j]
            mpp[temp]+=1
def binomialCoeff(C):
    for i in range(0,100):
        for j in range(0,100):
            if j==0 or j==i :
                C[i][j]=1
            else :
                C[i][j]=C[i-1][j-1]+C[i-1][j]
def answerQuery(mpp,C,k):
    ans=0
    for it in mpp :
        if mpp[it]>=k :
            ans+=C[mpp[it]][k]
    return ans
if __name__=="__main__" :
    s="aabaab"
    mpp=defaultdict(lambda : 0)
    generateSubStrings(s,mpp)
    C=[[0 for i in range(maxlen)]for j in range(maxlen)]
    binomialCoeff(C)
    queries=[2,3,4]
    q=len(queries)
    for i in range(0,q):
        print(answerQuery(mpp,C,queries[i]))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var maxlen : int := 100 ;
    skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      s := "aabaab" ;
    mpp := defaultdict(lambda $$ : OclAny in (0)) ;
    generateSubStrings(s, mpp) ;
    C := Integer.subrange(0, maxlen-1)->select(j | true)->collect(j | (Integer.subrange(0, maxlen-1)->select(i | true)->collect(i | (0)))) ;
    binomialCoeff(C) ;
    var queries : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })) ;
    var q : int := (queries)->size() ;
    for i : Integer.subrange(0, q-1) do (    execute (answerQuery(mpp, C, queries[i+1]))->display())
    ) else skip;
  operation generateSubStrings(s : OclAny, mpp : OclAny)
  pre: true post: true
  activity:
    var l : int := (s)->size() ;
    for i : Integer.subrange(0, l-1) do (    var temp : String := "" ;
    for j : Integer.subrange(i, l-1) do (    temp := temp + s[j+1] ;
    mpp->at(temp) := mpp->at(temp) + 1));
  operation binomialCoeff(C : OclAny)
  pre: true post: true
  activity:
    for i : Integer.subrange(0, 100-1) do (    for j : Integer.subrange(0, 100-1) do (    if j = 0 or j = i then  (
      C[i+1][j+1] := 1
    )
    else (
      C[i+1][j+1] := C[i - 1+1][j - 1+1] + C[i - 1+1][j+1]
      )));
  operation answerQuery(mpp : OclAny, C : OclAny, k : OclAny) : OclAny
  pre: true post: true
  activity:
    var ans : int := 0 ;
    for it : mpp do (    if (mpp[it+1]->compareTo(k)) >= 0 then (
      ans := ans + C[mpp[it+1]+1][k+1]
    ) else skip) ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import stdin,stdout
from math import*
import math,random,operator
from itertools import product,permutations,combinations
from collections import deque,defaultdict,Counter
def hi():
    a,b,c=map(int,input().split())
    if c>=a and c<=b :
        print(((b//c)+1)*c)
    else : print(c)
if __name__=="__main__" :
    for _ in range(int(input())): hi()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    hi())
    ) else skip;
  operation hi()
  pre: true post: true
  activity:
    var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if (c->compareTo(a)) >= 0 & (c->compareTo(b)) <= 0 then  (
      execute (((b div c) + 1) * c)->display()
    )
    else (
      execute (c)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
def check(l,r,d):
    if l>1 and l>d :
        return d
    else :
        i=r//d
        return(i+1)*d
for i in range(n):
    l,r,d=list(map(int,input().split()))
    print(check(l,r,d))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    skip ;
    for i : Integer.subrange(0, n-1) do (    Sequence{l,r,d} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute (check(l, r, d))->display());
  operation check(l : OclAny, r : OclAny, d : OclAny) : OclAny
  pre: true post: true
  activity:
    if l > 1 & (l->compareTo(d)) > 0 then  (
      return d
    )
    else (
      var i : int := r div d ;
    return (i + 1) * d
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
for pratyush in range(int(input())):
    x,y,c=list(map(int,input().split()))
    m=int((x-1)/c)
    if m==0 : m=math.ceil((y+1)/c)
    else : m=1
    print(m*c)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    for pratyush : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var x : OclAny := null;
    var y : OclAny := null;
    var c : OclAny := null;
    Sequence{x,y,c} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var m : int := ("" + (((x - 1) / c)))->toInteger() ;
    if m = 0 then  (
      m := ((y + 1) / c)->ceil()
    )
    else (
      m := 1
      ) ;
    execute (m * c)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
for i in range(n):
    x,y,z=map(int,input().split())
    if ztoInteger() ;
    for i : Integer.subrange(0, n-1) do (    var x : OclAny := null;
    var y : OclAny := null;
    var z : OclAny := null;
    Sequence{x,y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if (z->compareTo(x)) < 0 then  (
      execute (z)->display()
    )
    else (
      execute (y + z - y mod z)->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for i in range(t):
    l,r,d=map(int,input().split())
    if dtoInteger() ;
    for i : Integer.subrange(0, t-1) do (    var l : OclAny := null;
    var r : OclAny := null;
    var d : OclAny := null;
    Sequence{l,r,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if (d->compareTo(l)) < 0 then  (
      execute (d)->display()
    )
    else (
      execute (((r div d) + 1) * d)->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
n=n>>1
a=list(map(int,input().split()))
a.sort()
ans=float('inf')
for i in range(n):
    j=i+n
    ans=min(ans,a[j]-a[i])
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    n := n /(2->pow(1)) ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    a := a->sort() ;
    var ans : double := ("" + (('inf')))->toReal() ;
    for i : Integer.subrange(0, n-1) do (    var j : OclAny := i + n ;
    ans := Set{ans, a[j+1] - a[i+1]}->min()) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b,c=map(int,input().split())
print("Yes" if(a+b>=c)else "No")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (if ((a + b->compareTo(c)) >= 0) then "Yes" else "No" endif)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    a,b,c=map(int,input().split())
    if a+b>=c :
        print('Yes')
    else :
        print('No')
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if (a + b->compareTo(c)) >= 0 then  (
      execute ('Yes')->display()
    )
    else (
      execute ('No')->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import numpy as np
def main():
    n=int(input())
    a=[int(x)for x in input().split()]
    sol_tot,sol_tracker=-1e10,[]
    for p in range(2):
        c=a.copy()
        idx=np.arange(p,n,2)
        if len(idx)==0 :
            continue
        pick=max(idx,key=lambda x : c[x])
        if c[pick]<=0 :
            chosen={pick}
        else :
            chosen={x for x in idx if c[x]>0}
        is_chosen,tot,tracker=[False]*n,0,[]
        for i in chosen :
            is_chosen[i]=True
            tot+=c[i]
        for i in reversed(range(n)):
            if not is_chosen[i]:
                if i==0 or i+1==len(c):
                    tracker+=[i]
                    del c[i],is_chosen[i]
                elif is_chosen[i-1]==is_chosen[i+1]:
                    tracker+=[i]
                    c[i-1]+=c[i+1]
                    del c[i+1],c[i],is_chosen[i+1],is_chosen[i]
        if len(c)>1 and not is_chosen[0]:
            tracker+=[0]
            del c[0],is_chosen[0]
        if tot>sol_tot :
            sol_tot,sol_tracker=tot,np.array(tracker)+1
    print(sol_tot,len(sol_tracker),*sol_tracker,sep='\n')
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    var sol_tot : OclAny := null;
    var sol_tracker : OclAny := null;
    Sequence{sol_tot,sol_tracker} := Sequence{-("1e10")->toReal(),Sequence{}} ;
    for p : Integer.subrange(0, 2-1) do (    var c : OclAny := a->copy() ;
    var idx : Sequence := MathLib.numericRange(p, n, 2) ;
    if (idx)->size() = 0 then (
      continue
    ) else skip ;
    var pick : OclAny := Set{idx, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ]))))))))}->max() ;
    if c[pick+1] <= 0 then  (
      var chosen : Set := Set{ pick }
    )
    else (
      chosen := idx->select(x | c[x+1] > 0)->collect(x | x)->asSet()
      ) ;
    var is_chosen : OclAny := null;
    var tot : OclAny := null;
    var tracker : OclAny := null;
    Sequence{is_chosen,tot,tracker} := Sequence{MatrixLib.elementwiseMult(Sequence{ false }, n),0,Sequence{}} ;
    for i : chosen do (    is_chosen[i+1] := true ;
    tot := tot + c[i+1]) ;
    for i : (Integer.subrange(0, n-1))->reverse() do (    if not(is_chosen[i+1]) then (
      if i = 0 or i + 1 = (c)->size() then  (
      tracker := tracker + Sequence{ i } ;
    execute (c[i+1], is_chosen[i+1])->isDeleted()
    )
    else (if is_chosen[i - 1+1] = is_chosen[i + 1+1] then
   (
      tracker := tracker + Sequence{ i } ;
    c[i - 1+1] := c[i - 1+1] + c[i + 1+1] ;
    execute (c[i + 1+1], c[i+1], is_chosen[i + 1+1], is_chosen[i+1])->isDeleted()    
)
 else skip)
    ) else skip) ;
    if (c)->size() > 1 & not(is_chosen->first()) then (
      tracker := tracker + Sequence{ 0 } ;
    execute (c->first(), is_chosen->first())->isDeleted()
    ) else skip ;
    if (tot->compareTo(sol_tot)) > 0 then (
      var sol_tot : OclAny := null;
    var sol_tracker : OclAny := null;
    Sequence{sol_tot,sol_tracker} := Sequence{tot,MatrixLib.elementwiseAdd((tracker), 1)}
    ) else skip) ;
    execute (sol_tot)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=[int(i)for i in input().split()]
if a[0]+a[1]>=a[2]:
    print("Yes")
else :
    print("No")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    if (a->first() + a[1+1]->compareTo(a[2+1])) >= 0 then  (
      execute ("Yes")->display()
    )
    else (
      execute ("No")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b,c=list(map(int,input().split()))
print("{}".format("Yes" if a+b>=c else "No"))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute (StringLib.interpolateStrings("{}", Sequence{if (a + b->compareTo(c)) >= 0 then "Yes" else "No" endif}))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
A,B,C=map(int,input().split())
ans="Yes" if(A+B)>=C else "No"
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var A : OclAny := null;
    var B : OclAny := null;
    var C : OclAny := null;
    Sequence{A,B,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var ans : String := if ((A + B)->compareTo(C)) >= 0 then "Yes" else "No" endif ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
def main():
    X,Y=map(int,input().split())
    ans=1
    while True :
        X*=2
        if X>Y :
            break
        ans+=1
    print(ans)
if __name__=="__main__" :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    skip ;
    if __name__ = "__main__" then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var X : OclAny := null;
    var Y : OclAny := null;
    Sequence{X,Y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var ans : int := 1 ;
    while true do (    X := X * 2 ;
    if (X->compareTo(Y)) > 0 then (
      break
    ) else skip ;
    ans := ans + 1) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import stdin
s_in=lambda : stdin.readline()[:-1]
d_in=lambda : int(stdin.readline())
ds_in=lambda : list(map(int,stdin.readline().split()))
X,Y=ds_in()
x=bin(X)[2 :]
y=bin(Y)[2 :]
xl=len(x)
yl=len(y)
def bit_compare(A,B):
    flag=True
    for a,b in zip(A,B):
        if int(a)!=int(b):
            if int(a)>int(b):
                flag=True
            else :
                flag=False
            break
    return flag
if bit_compare(y[: xl],x):
    print(yl-xl+1)
else :
    print(yl-xl)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var s_in : Function := lambda $$ : OclAny in (stdin.readLine()->front()) ;
    var d_in : Function := lambda $$ : OclAny in (("" + ((stdin.readLine())))->toInteger()) ;
    var ds_in : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ;
    var X : OclAny := null;
    var Y : OclAny := null;
    Sequence{X,Y} := ds_in->apply() ;
    var x : OclAny := bin(X).subrange(2+1) ;
    var y : OclAny := bin(Y).subrange(2+1) ;
    var xl : int := (x)->size() ;
    var yl : int := (y)->size() ;
    skip ;
    if bit_compare(y.subrange(1,xl), x) then  (
      execute (yl - xl + 1)->display()
    )
    else (
      execute (yl - xl)->display()
      );
  operation bit_compare(A : OclAny, B : OclAny) : OclAny
  pre: true post: true
  activity:
    var flag : boolean := true ;
    for _tuple : Integer.subrange(1, A->size())->collect( _indx | Sequence{A->at(_indx), B->at(_indx)} ) do (var _indx : int := 1;
      var a : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var b : OclAny := _tuple->at(_indx);
      if ("" + ((a)))->toInteger() /= ("" + ((b)))->toInteger() then (
      if (("" + ((a)))->toInteger()->compareTo(("" + ((b)))->toInteger())) > 0 then  (
      flag := true
    )
    else (
      flag := false
      ) ;
    break
    ) else skip) ;
    return flag;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
from decimal import Decimal
def inp():
    return(int(input()))
def inlist():
    return(list(map(int,input().split())))
def instr():
    s=input()
    return(list(s[: len(s)]))
def invr():
    return(map(int,input().split()))
x,y=invr()
count=0
while x<=y :
    x*=2
    count+=1
print(count)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := invr() ;
    var count : int := 0 ;
    while (x->compareTo(y)) <= 0 do (    x := x * 2 ;
    count := count + 1) ;
    execute (count)->display();
  operation inp() : OclAny
  pre: true post: true
  activity:
    return (("" + (((OclFile["System.in"]).readLine())))->toInteger());
  operation inlist() : OclAny
  pre: true post: true
  activity:
    return (((input().split())->collect( _x | (OclType["int"])->apply(_x) )));
  operation instr() : OclAny
  pre: true post: true
  activity:
    var s : String := (OclFile["System.in"]).readLine() ;
    return ((s.subrange(1,(s)->size())));
  operation invr() : OclAny
  pre: true post: true
  activity:
    return ((input().split())->collect( _x | (OclType["int"])->apply(_x) ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def inpl(): return[int(i)for i in input().split()]
X,Y=inpl()
ans=0
while X<=Y :
    X=2*X
    ans+=1
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var X : OclAny := null;
    var Y : OclAny := null;
    Sequence{X,Y} := inpl() ;
    var ans : int := 0 ;
    while (X->compareTo(Y)) <= 0 do (    var X : double := 2 * X ;
    ans := ans + 1) ;
    execute (ans)->display();
  operation inpl() : OclAny
  pre: true post: true
  activity:
    return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
X,Y=map(int,input().split())
A=[X]
while True :
    Ai1=A[-1]*2
    if Ai1<=Y :
        A.append(Ai1)
    else :
        break
print(len(A))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var X : OclAny := null;
    var Y : OclAny := null;
    Sequence{X,Y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var A : Sequence := Sequence{ X } ;
    while true do (    var Ai1 : double := A->last() * 2 ;
    if (Ai1->compareTo(Y)) <= 0 then  (
      execute ((Ai1) : A)
    )
    else (
      break
      )) ;
    execute ((A)->size())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
n=n>>1
a=list(map(int,input().split()))
a.sort()
ans=float('inf')
ans1=0
for i in range(n):
    j=i+n
    ans=min(ans,a[j]-a[i])
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    n := n /(2->pow(1)) ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    a := a->sort() ;
    var ans : double := ("" + (('inf')))->toReal() ;
    var ans1 : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    var j : OclAny := i + n ;
    ans := Set{ans, a[j+1] - a[i+1]}->min()) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def complement(s):
    comps="" ;
    for i in range(len(s)):
        if(s[i]=='0'):
            comps+='1' ;
        else :
            comps+='0' ;
    return comps ;
def nthTerm(n):
    s="0" ;
    for i in range(1,n):
        s+=complement(s);
    return s ;
n=4 ;
print(nthTerm(n));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    n := 4; ;
    execute (nthTerm(n))->display();;
  operation complement(s : OclAny)
  pre: true post: true
  activity:
    var comps : String := ""; ;
    for i : Integer.subrange(0, (s)->size()-1) do (    if (s[i+1] = '0') then  (
      comps := comps + '1';
    )
    else (
      comps := comps + '0';
      )) ;
    return comps;;
  operation nthTerm(n : OclAny)
  pre: true post: true
  activity:
    s := "0"; ;
    for i : Integer.subrange(1, n-1) do (    s := s + complement(s);) ;
    return s;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    import sys
    input=sys.stdin.readline
    N=int(input())
    A=list(map(int,input().split()))
    even=sum([max(A[i],0)for i in range(0,N,2)])
    odd=sum([max(A[i],0)for i in range(1,N,2)])
    if even==odd==0 :
        a=max(A)
        print(a)
        print(N-1)
        flg=1
        for i in range(N-1):
            if A[i]==a :
                flg=0
            if flg :
                print(1)
            else :
                print(N-i)
        exit()
    ans=[]
    i=0
    if odd>even :
        if N % 2==1 :
            ans.append(N)
            N-=1
        ans.append(1)
        i=1
    else :
        if N % 2==0 :
            ans.append(N)
            N-=1
    flg=1
    while True :
        if flg :
            if A[i]>0 :
                flg=0
            else :
                ans.append(1)
                i+=1
                if i==N :
                    break
                ans.append(1)
                i+=1
                if i==N :
                    break
        else :
            if A[i+2]>0 :
                ans.append(2)
                i+=2
            else :
                ans.append(3)
                i+=2
            if i+2>=N :
                break
    if ans[-1]==3 :
        ans.append(2)
    print(max(odd,even))
    print(len(ans))
    for x in ans :
        print(x)
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var even : OclAny := (Integer.subrange(0, N-1)->select( $x | ($x - 0) mod 2 = 0 )->select(i | true)->collect(i | (Set{A[i+1], 0}->max())))->sum() ;
    var odd : OclAny := (Integer.subrange(1, N-1)->select( $x | ($x - 1) mod 2 = 0 )->select(i | true)->collect(i | (Set{A[i+1], 0}->max())))->sum() ;
    if even = odd & (odd == 0) then (
      var a : OclAny := (A)->max() ;
    execute (a)->display() ;
    execute (N - 1)->display() ;
    var flg : int := 1 ;
    for i : Integer.subrange(0, N - 1-1) do (    if A[i+1] = a then (
      flg := 0
    ) else skip ;
    if flg then  (
      execute (1)->display()
    )
    else (
      execute (N - i)->display()
      )) ;
    exit()
    ) else skip ;
    var ans : Sequence := Sequence{} ;
    var i : int := 0 ;
    if (odd->compareTo(even)) > 0 then  (
      if N mod 2 = 1 then (
      execute ((N) : ans) ;
    N := N - 1
    ) else skip ;
    execute ((1) : ans) ;
    i := 1
    )
    else (
      if N mod 2 = 0 then (
      execute ((N) : ans) ;
    N := N - 1
    ) else skip
      ) ;
    flg := 1 ;
    while true do (    if flg then  (
      if A[i+1] > 0 then  (
      flg := 0
    )
    else (
      execute ((1) : ans) ;
    i := i + 1 ;
    if i = N then (
      break
    ) else skip ;
    execute ((1) : ans) ;
    i := i + 1 ;
    if i = N then (
      break
    ) else skip
      )
    )
    else (
      if A[i + 2+1] > 0 then  (
      execute ((2) : ans) ;
    i := i + 2
    )
    else (
      execute ((3) : ans) ;
    i := i + 2
      ) ;
    if (i + 2->compareTo(N)) >= 0 then (
      break
    ) else skip
      )) ;
    if ans->last() = 3 then (
      execute ((2) : ans)
    ) else skip ;
    execute (Set{odd, even}->max())->display() ;
    execute ((ans)->size())->display() ;
    for x : ans do (    execute (x)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
while t>0 :
    t-=1
    n=int(input())
    a=list(map(int,input().split(' ')))
    b=[]
    for i in range(0,n-1):
        for j in range(i+1,n):
            b.append(a[j]-a[i])
    b=set(b)
    print(len(b))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    while t > 0 do (    t := t - 1 ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ;
    var b : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n - 1-1) do (    for j : Integer.subrange(i + 1, n-1) do (    execute ((a[j+1] - a[i+1]) : b))) ;
    b := Set{}->union((b)) ;
    execute ((b)->size())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import defaultdict
from sys import stdin,stdout
import math
import itertools
def solution(n,trees):
    visited=set()
    for i in range(0,n):
        for k in range(i+1,n):
            visited.add(trees[k]-trees[i])
    return len(visited)
test_cases=int(stdin.readline())
for it in range(test_cases):
    n=int(stdin.readline())
    trees=[int(x)for x in stdin.readline().split()]
    stdout.write(str(solution(n,trees))+'\n')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var test_cases : int := ("" + ((stdin.readLine())))->toInteger() ;
    for it : Integer.subrange(0, test_cases-1) do (    n := ("" + ((stdin.readLine())))->toInteger() ;
    trees := stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    stdout.write(("" + ((solution(n, trees)))) + '
'));
  operation solution(n : OclAny, trees : OclAny) : OclAny
  pre: true post: true
  activity:
    var visited : Set := Set{}->union(()) ;
    for i : Integer.subrange(0, n-1) do (    for k : Integer.subrange(i + 1, n-1) do (    execute ((trees[k+1] - trees[i+1]) : visited))) ;
    return (visited)->size();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys,os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
t=int(input())
ans=[]
for _ in range(t):
    n=int(input())
    x=list(map(int,input().split()))
    u=[0]*55
    for i in range(n):
        xi=x[i]
        for j in range(i+1,n):
            u[x[j]-xi]=1
    ans0=sum(u)
    ans.append(ans0)
sys.stdout.write("\n".join(map(str,ans)))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := io.BytesIO(os.readAll()).readline ;
    var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var ans : Sequence := Sequence{} ;
    for _anon : Integer.subrange(0, t-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var u : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 55) ;
    for i : Integer.subrange(0, n-1) do (    var xi : OclAny := x[i+1] ;
    for j : Integer.subrange(i + 1, n-1) do (    u[x[j+1] - xi+1] := 1)) ;
    var ans0 : OclAny := (u)->sum() ;
    execute ((ans0) : ans)) ;
(expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))))))) ))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for s in[*open(0)][2 : : 2]: a=*map(int,s.split()),; print(len({abs(x-y)for x in a for y in a})-1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do (    var a : OclAny := (testlist_star_expr (star_expr * (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name s)) (trailer . (name split) (arguments ( ))))))))) ))))) ,);    execute ((a->select(x; y : a | true)->collect(x; y : a | (x - y)->abs())->asSet())->size() - 1)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for i in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    s=set()
    for j in range(n-1):
        for k in range(j+1,n):
            s.add(a[k]-a[j])
    print(len(s))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var s : Set := Set{}->union(()) ;
    for j : Integer.subrange(0, n - 1-1) do (    for k : Integer.subrange(j + 1, n-1) do (    execute ((a[k+1] - a[j+1]) : s))) ;
    execute ((s)->size())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def maxSum(arr,n):
    if(n<2):
        return-1
    ans=arr[0]+arr[1]
    for i in range(1,n-1,1):
        ans=min(ans,(arr[i]+arr[i+1]))
    return ans
if __name__=='__main__' :
    arr=[1,12,2,2]
    n=len(arr)
    print(maxSum(arr,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      arr := Sequence{1}->union(Sequence{12}->union(Sequence{2}->union(Sequence{ 2 }))) ;
    n := (arr)->size() ;
    execute (maxSum(arr, n))->display()
    ) else skip;
  operation maxSum(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    if (n < 2) then (
      return -1
    ) else skip ;
    var ans : OclAny := arr->first() + arr[1+1] ;
    for i : Integer.subrange(1, n - 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do (    ans := Set{ans, (arr[i+1] + arr[i + 1+1])}->min()) ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
class Node :
    def __init__(self,data):
        self.data=data
        self.left=None
        self.right=None
def insert(node,data):
    if node is None :
        return Node(data)
    else :
        if data<=node.data :
            node.left=insert(node.left,data)
        else :
            node.right=insert(node.right,data)
        return node
def minValue(node):
    if node.left==None :
        return node.data
    return minValue(node.left)
if __name__=="__main__" :
    root=None
    root=insert(root,4)
    insert(root,2)
    insert(root,1)
    insert(root,3)
    insert(root,6)
    insert(root,5)
    print(minValue(root))
------------------------------------------------------------
OCL File:
---------
class Node {
  static operation newNode() : Node
  pre: true
  post: Node->exists( _x | result = _x );
  attribute data : OclAny := data;
  attribute left : OclAny := null;
  attribute right : OclAny := null;
  operation initialise(data : OclAny) : Node
  pre: true post: true
  activity:
    self.data := data ;
    self.left := null ;
    self.right := null;
    return self;
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      var root : OclAny := null ;
    root := insert(root, 4) ;
    insert(root, 2) ;
    insert(root, 1) ;
    insert(root, 3) ;
    insert(root, 6) ;
    insert(root, 5) ;
    execute (minValue(root))->display()
    ) else skip;
  operation insert(node : OclAny, data : OclAny) : OclAny
  pre: true post: true
  activity:
    if node <>= null then  (
      return (Node.newNode()).initialise(data)
    )
    else (
      if (data->compareTo(node.data)) <= 0 then  (
      node.left := insert(node.left, data)
    )
    else (
      node.right := insert(node.right, data)
      ) ;
    return node
      );
  operation minValue(node : OclAny) : OclAny
  pre: true post: true
  activity:
    if node.left = null then (
      return node.data
    ) else skip ;
    return minValue(node.left);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def maximum_one(s,n):
    cnt_one=0
    cnt,max_cnt=0,0
    for i in range(n):
        if(s[i]=='1'):
            cnt_one+=1
            cnt+=1
        else :
            max_cnt=max(max_cnt,cnt)
            cnt=0
    max_cnt=max(max_cnt,cnt)
    left=[0]*n
    right=[0]*n
    if(s[0]=='1'):
        left[0]=1
    else :
        left[0]=0
    if(s[n-1]=='1'):
        right[n-1]=1
    else :
        right[n-1]=0
    for i in range(1,n):
        if(s[i]=='1'):
            left[i]=left[i-1]+1
        else :
            left[i]=0
    for i in range(n-2,-1,-1):
        if(s[i]=='1'):
            right[i]=right[i+1]+1
        else :
            right[i]=0
    for i in range(1,n):
        if(s[i]=='0'):
            sum=left[i-1]+right[i+1]
            if(sumsize()))->display()
    ) else skip;
  operation maximum_one(s : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var cnt_one : int := 0 ;
    var cnt : OclAny := null;
    var max_cnt : OclAny := null;
    Sequence{cnt,max_cnt} := Sequence{0,0} ;
    for i : Integer.subrange(0, n-1) do (    if (s[i+1] = '1') then  (
      cnt_one := cnt_one + 1 ;
    cnt := cnt + 1
    )
    else (
      var max_cnt : OclAny := Set{max_cnt, cnt}->max() ;
    var cnt : int := 0
      )) ;
    max_cnt := Set{max_cnt, cnt}->max() ;
    var left : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ;
    var right : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ;
    if (s->first() = '1') then  (
      left->first() := 1
    )
    else (
      left->first() := 0
      ) ;
    if (s[n - 1+1] = '1') then  (
      right[n - 1+1] := 1
    )
    else (
      right[n - 1+1] := 0
      ) ;
    for i : Integer.subrange(1, n-1) do (    if (s[i+1] = '1') then  (
      left[i+1] := left[i - 1+1] + 1
    )
    else (
      left[i+1] := 0
      )) ;
    for i : Integer.subrange(-1 + 1, n - 2)->reverse() do (    if (s[i+1] = '1') then  (
      right[i+1] := right[i + 1+1] + 1
    )
    else (
      right[i+1] := 0
      )) ;
    for i : Integer.subrange(1, n-1) do (    if (s[i+1] = '0') then (
      var sum : OclAny := left[i - 1+1] + right[i + 1+1] ;
    if ((sum->compareTo(cnt_one)) < 0) then  (
      max_cnt := Set{max_cnt, sum + 1}->max()
    )
    else (
      max_cnt := Set{max_cnt, sum}->max()
      )
    ) else skip) ;
    return max_cnt;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
val=[]
result=[]
count=0
for line in sys.stdin :
    if line!='\n' :
        for word in line.split():
            val.append(int(word))
        result.append(sum(val))
        val=[]
        count=count+1
    else :
        break
for x in result :
    print(x)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var val : Sequence := Sequence{} ;
    var result : Sequence := Sequence{} ;
    var count : int := 0 ;
    for line : OclFile["System.in"] do (    if line /= '
' then  (
      for word : line.split() do (    execute ((("" + ((word)))->toInteger()) : val)) ;
    execute (((val)->sum()) : result) ;
    val := Sequence{} ;
    count := count + 1
    )
    else (
      break
      )) ;
    for x : result do (    execute (x)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a=list(map(int,input().split()))
w=list(map(int,input().split()))
INF=10**9
x=[INF]*2
for i in range(n):
    x[a[i]]=min(x[a[i]],w[i])
ans=sum(x)
if ans>=INF :
    ans=0
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var INF : double := (10)->pow(9) ;
    var x : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, 2) ;
    for i : Integer.subrange(0, n-1) do (    x[a[i+1]+1] := Set{x[a[i+1]+1], w[i+1]}->min()) ;
    var ans : OclAny := (x)->sum() ;
    if (ans->compareTo(INF)) >= 0 then (
      ans := 0
    ) else skip ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=int(input())
*A,=map(int,input().split())
def calc(A):
    if len(A)==1 :
        return[],A[0]
    res=[]
    if len(A)% 2==0 :
        res.append(len(A))
        A=A[:-1]
    if all(a<=0 for a in A[: : 2]):
        ma=max(A[: : 2])
        i=0
        while A[i]!=ma :
            i+=1
            res.append(1)
        j=len(A)
        while i2 :
        if A[2]<0 :
            res.append(3)
            if len(A)>4 :
                A=A[: 2]+A[4 :]
            else :
                A=A[: 2]
        else :
            res.append(2)
            A[2]+=A[0]
            A=A[2 :]
    if len(A)>1 :
        res.append(2)
    return res,A[0]
r,v=calc(A)
if len(A)>1 :
    r0,v0=calc(A[1 :])
    if vtoInteger() ;
(testlist_star_expr (star_expr * (expr (atom (name A)))) ,)    Sequence{(testlist_star_expr (star_expr * (expr (atom (name A)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    skip ;
    Sequence{r,v} := calc(A) ;
    if (A)->size() > 1 then (
      var r0 : OclAny := null;
    var v0 : OclAny := null;
    Sequence{r0,v0} := calc(A->tail()) ;
    if (v->compareTo(v0)) < 0 then (
      r := Sequence{ 1 }->union(r0) ;
    v := v0
    ) else skip
    ) else skip ;
    execute (v)->display();
  operation calc(A : OclAny) : OclAny
  pre: true post: true
  activity:
    if (A)->size() = 1 then (
      return Sequence{}, A->first()
    ) else skip ;
    var res : Sequence := Sequence{} ;
    if (A)->size() mod 2 = 0 then (
      execute (((A)->size()) : res) ;
    A := A->front()
    ) else skip ;
    if ((argument (test (logical_test (comparison (comparison (expr (atom (name a)))) <= (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) ]))))))))->forAll( _x | _x = true ) then (
      var ma : OclAny := (A(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->max() ;
    var i : int := 0 ;
    while A[i+1] /= ma do (    i := i + 1 ;
    execute ((1) : res)) ;
    var j : int := (A)->size() ;
    while (i->compareTo(j - 1)) < 0 do (    execute ((j - i) : res) ;
    j := j - 1) ;
    return res, ma
    ) else skip ;
    var l : int := 0;    var r : int := (A)->size() ;
    while A->first() < 0 do (    execute ((1) : res) ;
    execute ((1) : res) ;
    A := A.subrange(2+1)) ;
    var v : int := 0 ;
    while (A)->size() > 2 do (    if A[2+1] < 0 then  (
      execute ((3) : res) ;
    if (A)->size() > 4 then  (
      A := A.subrange(1,2) + A.subrange(4+1)
    )
    else (
      A := A.subrange(1,2)
      )
    )
    else (
      execute ((2) : res) ;
    A[2+1] := A[2+1] + A->first() ;
    A := A.subrange(2+1)
      )) ;
    if (A)->size() > 1 then (
      execute ((2) : res)
    ) else skip ;
    return res, A->first();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    try : print(sum(map(int,input().split(" "))))
    except : break
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    try (    execute (((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ))->sum())->display())
     catch (_e : OclException) do (    break)
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import stdin
Ans=[]
for i in stdin :
    A,B=[int(po)for po in i.split()]
    Ans.append(A+B)
for k in Ans :
    print(k)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var Ans : Sequence := Sequence{} ;
    for i : stdin do (    var A : OclAny := null;
    var B : OclAny := null;
    Sequence{A,B} := i.split()->select(po | true)->collect(po | (("" + ((po)))->toInteger())) ;
    execute ((A + B) : Ans)) ;
    for k : Ans do (    execute (k)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while(True):
    try :
        data=input().split()
        result=0
        for i in data : result+=int(i)
        print(result)
    except EOFError :
        break
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while (true) do (    try (    var data : OclAny := input().split() ;
    var result : int := 0 ;
    for i : data do (    result := result + ("" + ((i)))->toInteger()) ;
    execute (result)->display())
(except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
for line in sys.stdin.readlines():
    data=line.split()
    print(eval(data[0]+"+"+data[1]))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    for line : (OclFile["System.in"]).readlines() do (    var data : OclAny := line.split() ;
    execute (data->first() + "+" + data[1+1])->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def getMod(_str,n,k):
    pwrTwo=[0]*n
    pwrTwo[0]=1 % k
    for i in range(1,n):
        pwrTwo[i]=pwrTwo[i-1]*(2 % k)
        pwrTwo[i]%=k
    res=0
    i=0
    j=n-1
    while(isize() ;
    k := 45 ;
    execute (getMod(_str, n, k))->display();
  operation getMod(_str : OclAny, n : OclAny, k : OclAny) : OclAny
  pre: true post: true
  activity:
    var pwrTwo : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ;
    pwrTwo->first() := 1 mod k ;
    for i : Integer.subrange(1, n-1) do (    pwrTwo[i+1] := pwrTwo[i - 1+1] * (2 mod k) ;
    pwrTwo[i+1] := pwrTwo[i+1] mod k) ;
    var res : int := 0 ;
    var i : int := 0 ;
    var j : double := n - 1 ;
    while ((i->compareTo(n)) < 0) do (    if (_str[j+1] = '1') then (
      res := res + (pwrTwo[i+1]) ;
    res := res mod k
    ) else skip ;
    i := i + 1 ;
    j := j - 1) ;
    return res;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
INT_SIZE=32
def Right_most_setbit(num):
    pos=1
    for i in range(INT_SIZE):
        if not(num &(1<display()
    ) else skip;
  operation Right_most_setbit(num : OclAny) : OclAny
  pre: true post: true
  activity:
    var pos : int := 1 ;
    for i : Integer.subrange(0, INT_SIZE-1) do (    if not((MathLib.bitwiseAnd(num, (1 * (2->pow(i)))))) then  (
      pos := pos + 1
    )
    else (
      break
      )) ;
    return pos;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def Minsteps(n,m):
    ans=0
    while(m>n):
        if(m & 1):
            m+=1
            ans+=1
        m//=2
        ans+=1
    return ans+n-m
n=4
m=6
print(Minsteps(n,m))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    n := 4 ;
    m := 6 ;
    execute (Minsteps(n, m))->display();
  operation Minsteps(n : OclAny, m : OclAny) : OclAny
  pre: true post: true
  activity:
    var ans : int := 0 ;
    while ((m->compareTo(n)) > 0) do (    if (MathLib.bitwiseAnd(m, 1)) then (
      m := m + 1 ;
    ans := ans + 1
    ) else skip ;
    m := m div 2 ;
    ans := ans + 1) ;
    return ans + n - m;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
for line in sys.stdin :
    a,b=map(int,line.rstrip().split())
    print(a*b)/3.305785
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    for line : OclFile["System.in"] do (    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (line.rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
(expr (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a))) * (expr (atom (name b))))))))) )))) / (expr (atom (number 3.305785)))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=map(int,input().split())
c=3.305785
print('{:.6f}'.format(a*b/c))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var c : double := 3.305785 ;
    execute (StringLib.interpolateStrings('{:.6f}', Sequence{a * b / c}))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from __future__ import division,print_function
from sys import stdin,exit
def main(readline=stdin.readline):
    a,b=(float(s)for s in readline().split())
    print('{:.6f}'.format(a*b/3.305785))
    exit()
main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    main();
  operation main(readline : OclAny)
  pre: true post: true
  activity:
    if readline->oclIsUndefined() then readline := stdin.readline else skip;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name float)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name readline)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ;
    execute (StringLib.interpolateStrings('{:.6f}', Sequence{a * b / 3.305785}))->display() ;
    exit();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def gcd(p,q):
    if q==0 :
        return p
    return gcd(q,p % q)
a,b,c,d=map(int,input().split())
if a/b>c/d :
    p=a*d-c*b ; q=a*d
    div=gcd(p,q)
    print(str(int(p/div))+"/"+str(int(q/div)))
elif a/bcollect( _x | (OclType["int"])->apply(_x) ) ;
    if (a / b->compareTo(c / d)) > 0 then  (
      p := a * d - c * b;    q := a * d ;
    var div : OclAny := gcd(p, q) ;
    execute (("" + ((("" + ((p / div)))->toInteger()))) + "/" + ("" + ((("" + ((q / div)))->toInteger()))))->display()
    )
    else (if (a / b->compareTo(c / d)) < 0 then
   (
      p := b * c - a * d;    q := b * c ;
    div := gcd(p, q) ;
    execute (("" + ((("" + ((p / div)))->toInteger()))) + "/" + ("" + ((("" + ((q / div)))->toInteger()))))->display()    
)
    else (
      execute ("0/1")->display()
      )    )
;
  operation gcd(p : OclAny, q : OclAny) : OclAny
  pre: true post: true
  activity:
    if q = 0 then (
      return p
    ) else skip ;
    return gcd(q, p mod q);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=input()
a=[int(x)for x in input().split()]
w=[int(x)for x in input().split()]
R=[w for a,w in zip(a,w)if a==0]
L=[w for a,w in zip(a,w)if a==1]
if R and L :
    print(min(R)+min(L))
else :
    print(0)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : String := (OclFile["System.in"]).readLine() ;
    var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    var w : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    var R : Sequence := Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), w->at(_indx)} )->select(_tuple | let a : OclAny = _tuple->at(1) in let w : OclAny = _tuple->at(2) in a = 0)->collect(_tuple | let a : OclAny = _tuple->at(1) in let w : OclAny = _tuple->at(2) in (w)) ;
    var L : Sequence := Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), w->at(_indx)} )->select(_tuple | let a : OclAny = _tuple->at(1) in let w : OclAny = _tuple->at(2) in a = 1)->collect(_tuple | let a : OclAny = _tuple->at(1) in let w : OclAny = _tuple->at(2) in (w)) ;
    if R & L then  (
      execute ((R)->min() + (L)->min())->display()
    )
    else (
      execute (0)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=map(int,input().split())
c=a*b
d=3.305785
e=c/d
print(f"{e:.6f}")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var c : double := a * b ;
    var d : double := 3.305785 ;
    var e : double := c / d ;
    execute (StringLib.formattedString("{e:.6f}"))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
A,B=map(float,input().split())
print(A*B/3.305785)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var A : OclAny := null;
    var B : OclAny := null;
    Sequence{A,B} := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ;
    execute (A * B / 3.305785)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def findSmallest(s):
    length=len(s);
    loccur=[-1]*26 ;
    for i in range(length-1,-1,-1):
        chI=ord(s[i])-ord('a');
        if(loccur[chI]==-1):
            loccur[chI]=i ;
    sorted_s=s ;
    sorted_s.sort();
    for i in range(length):
        if(s[i]!=sorted_s[i]):
            chI=ord(sorted_s[i])-ord('a');
            last_occ=loccur[chI];
            s[i],s[last_occ]=s[last_occ],s[i]
            break ;
    return "".join(s);
if __name__=="__main__" :
    s="geeks" ;
    print(findSmallest(list(s)));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      s := "geeks"; ;
    execute (findSmallest((s)))->display();
    ) else skip;
  operation findSmallest(s : OclAny)
  pre: true post: true
  activity:
    var length : int := (s)->size(); ;
    var loccur : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, 26); ;
    for i : Integer.subrange(-1 + 1, length - 1)->reverse() do (    var chI : double := (s[i+1])->char2byte() - ('a')->char2byte(); ;
    if (loccur[chI+1] = -1) then (
      loccur[chI+1] := i;
    ) else skip) ;
    var sorted_s : OclAny := s; ;
    sorted_s := sorted_s->sort(); ;
    for i : Integer.subrange(0, length-1) do (    if (s[i+1] /= sorted_s[i+1]) then (
      chI := (sorted_s[i+1])->char2byte() - ('a')->char2byte(); ;
    var last_occ : OclAny := loccur[chI+1]; ;
    var s[i+1] : OclAny := null;
    var s[last_occ+1] : OclAny := null;
    Sequence{s[i+1],s[last_occ+1]} := Sequence{s[last_occ+1],s[i+1]} ;
    break;
    ) else skip) ;
    return StringLib.sumStringsWithSeparator((s), "");;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def maxRepeating(str):
    n=len(str)
    count=0
    res=str[0]
    cur_count=1
    for i in range(n):
        if(icount :
                count=cur_count
                res=str[i]
            cur_count=1
    return res
if __name__=="__main__" :
    str="aaaabbaaccde"
    print(maxRepeating(str))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      OclType["String"] := "aaaabbaaccde" ;
    execute (maxRepeating(OclType["String"]))->display()
    ) else skip;
  operation maxRepeating(OclType["String"] : OclAny) : OclAny
  pre: true post: true
  activity:
    var n : int := (OclType["String"])->size() ;
    var count : int := 0 ;
    var res : String := ("" + (->first())) ;
    var cur_count : int := 1 ;
    for i : Integer.subrange(0, n-1) do (    if ((i->compareTo(n - 1)) < 0 & ("" + ([i+1])) = ("" + ([i + 1+1]))) then  (
      cur_count := cur_count + 1
    )
    else (
      if (cur_count->compareTo(count)) > 0 then (
      count := cur_count ;
    res := ("" + ([i+1]))
    ) else skip ;
    cur_count := 1
      )) ;
    return res;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def maxRepeating(str):
    l=len(str)
    count=0
    res=str[0]
    for i in range(l):
        cur_count=1
        for j in range(i+1,l):
            if(str[i]!=str[j]):
                break
            cur_count+=1
        if cur_count>count :
            count=cur_count
            res=str[i]
    return res
if __name__=="__main__" :
    str="aaaabbaaccde"
    print(maxRepeating(str))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      OclType["String"] := "aaaabbaaccde" ;
    execute (maxRepeating(OclType["String"]))->display()
    ) else skip;
  operation maxRepeating(OclType["String"] : OclAny) : OclAny
  pre: true post: true
  activity:
    var l : int := (OclType["String"])->size() ;
    var count : int := 0 ;
    var res : String := ("" + (->first())) ;
    for i : Integer.subrange(0, l-1) do (    var cur_count : int := 1 ;
    for j : Integer.subrange(i + 1, l-1) do (    if (("" + ([i+1])) /= ("" + ([j+1]))) then (
      break
    ) else skip ;
    cur_count := cur_count + 1) ;
    if (cur_count->compareTo(count)) > 0 then (
      count := cur_count ;
    res := ("" + ([i+1]))
    ) else skip) ;
    return res;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N,A,B=map(int,input().split())
p=list(map(int,input().split()))
p=[p[i]-1 for i in range(N)]
dp=[[0 for i in range(N+1)]for j in range(N)]
for j in range(N+1):
    if p[0]<=j :
        dp[0][j]=0
    else :
        dp[0][j]=A
for i in range(1,N):
    for j in range(N+1):
        if p[i]<=j :
            dp[i][j]=min(dp[i-1][p[i]],dp[i-1][j]+B)
        else :
            dp[i][j]=dp[i-1][j]+A
print(dp[-1][N])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : OclAny := null;
    var A : OclAny := null;
    var B : OclAny := null;
    Sequence{N,A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    p := Integer.subrange(0, N-1)->select(i | true)->collect(i | (p[i+1] - 1)) ;
    var dp : Sequence := Integer.subrange(0, N-1)->select(j | true)->collect(j | (Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (0)))) ;
    for j : Integer.subrange(0, N + 1-1) do (    if (p->first()->compareTo(j)) <= 0 then  (
      dp->first()[j+1] := 0
    )
    else (
      dp->first()[j+1] := A
      )) ;
    for i : Integer.subrange(1, N-1) do (    for j : Integer.subrange(0, N + 1-1) do (    if (p[i+1]->compareTo(j)) <= 0 then  (
      dp[i+1][j+1] := Set{dp[i - 1+1][p[i+1]+1], dp[i - 1+1][j+1] + B}->min()
    )
    else (
      dp[i+1][j+1] := dp[i - 1+1][j+1] + A
      ))) ;
    execute (dp->last()[N+1])->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from bisect import bisect
from operator import itemgetter
n,a,b=map(int,input().split())
ppp=map(int,input().split())
qqq=[i for i,p in sorted(enumerate(ppp,start=1),key=itemgetter(1))]
INF=10**15
dp=[(0,0)]
for i in qqq :
    ndp=[]
    s=bisect(dp,(i,))
    tmp_min=INF
    for j,cost in dp[: s]:
        cost+=b
        ndp.append((j,cost))
        tmp_min=cost
    stay_cost=dp[s-1][1]
    if tmp_min>stay_cost :
        ndp.append((i,stay_cost))
        tmp_min=stay_cost
    for j,cost in dp[s :]:
        cost+=a
        if tmp_min>cost :
            ndp.append((j,cost))
            tmp_min=cost
    dp=ndp
print(dp[-1][1])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var n : OclAny := null;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var ppp : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var qqq : Sequence := Integer.subrange(1, (ppp, (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->size())->collect( _indx | Sequence{_indx-1, (ppp, (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->at(_indx)} )->sortedBy($x | (itemgetter(1))->apply($x))->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let p : OclAny = _tuple->at(2) in (i)) ;
    var INF : double := (10)->pow(15) ;
    var dp : Sequence := Sequence{ Sequence{0, 0} } ;
    for i : qqq do (    var ndp : Sequence := Sequence{} ;
    var s : OclAny := bisect(dp, Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) ,)}) ;
    var tmp_min : OclAny := INF ;
    for _tuple : dp.subrange(1,s) do (var _indx : int := 1;
      var j : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var cost : OclAny := _tuple->at(_indx);
      cost := cost + b ;
    execute ((Sequence{j, cost}) : ndp) ;
    tmp_min := cost) ;
    var stay_cost : OclAny := dp[s - 1+1][1+1] ;
    if (tmp_min->compareTo(stay_cost)) > 0 then (
      execute ((Sequence{i, stay_cost}) : ndp) ;
    tmp_min := stay_cost
    ) else skip ;
    for _tuple : dp.subrange(s+1) do (var _indx : int := 1;
      var j : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var cost : OclAny := _tuple->at(_indx);
      cost := cost + a ;
    if (tmp_min->compareTo(cost)) > 0 then (
      execute ((Sequence{j, cost}) : ndp) ;
    tmp_min := cost
    ) else skip) ;
    dp := ndp) ;
    execute (dp->last()[1+1])->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from numpy import*
N,A,B,*P=map(int,open(0).read().split()); d=full(N+1,1<<60,'int'); d[0]=0
for p in P : d[p]=min(d[: p]); d[p+1 :]+=B ; d[: p]+=A
print(min(d))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var N : OclAny := null;
    var A : OclAny := null;
    var B : OclAny := null;
    var P : OclAny := null;
    Sequence{N,A,B,P} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) );    var d : OclAny := full(N + 1, 1 * (2->pow(60)), 'int');    d->first() := 0 ;
    for p : P do (    d[p+1] := (d.subrange(1,p))->min();    d.subrange(p + 1+1) := d.subrange(p + 1+1) + B;    d.subrange(1,p) := d.subrange(1,p) + A) ;
    execute ((d)->min())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
N,A,B=map(int,input().split())
P=list(map(int,input().split()))
data=[0]*(N+1)
flag=[0]*(N+1)
for i in range(N):
    p=P[i]
    flag[p]=1
    cnt=0
    for j in range(p+1,N+1):
        if flag[j]==0 :
            data[j]=data[j-1]
        else :
            cnt+=1
            data[j]=min(cnt*A+data[p-1],data[j]+B)
print(data[-1])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    var N : OclAny := null;
    var A : OclAny := null;
    var B : OclAny := null;
    Sequence{N,A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var P : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var data : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ;
    var flag : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ;
    for i : Integer.subrange(0, N-1) do (    var p : OclAny := P[i+1] ;
    flag[p+1] := 1 ;
    var cnt : int := 0 ;
    for j : Integer.subrange(p + 1, N + 1-1) do (    if flag[j+1] = 0 then  (
      data[j+1] := data[j - 1+1]
    )
    else (
      cnt := cnt + 1 ;
    data[j+1] := Set{cnt * A + data[p - 1+1], data[j+1] + B}->min()
      ))) ;
    execute (data->last())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
def complement(num):
    i=0 ;
    len=0 ;
    comp=0 ;
    temp=num ;
    while(1):
        len+=1 ;
        num=int(num/10);
        if(abs(num)==0):
            break ;
    num=temp ;
    comp=math.pow(10,len)-num ;
    return int(comp);
print(complement(25));
print(complement(456));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    execute (complement(25))->display(); ;
    execute (complement(456))->display();;
  operation complement(num : OclAny)
  pre: true post: true
  activity:
    var i : int := 0; ;
    var len : int := 0; ;
    var comp : int := 0; ;
    var temp : OclAny := num; ;
    while (1) do (    len := len + 1; ;
    num := ("" + ((num / 10)))->toInteger(); ;
    if ((num)->abs() = 0) then (
      break;
    ) else skip) ;
    num := temp; ;
    comp := (10)->pow(len) - num; ;
    return ("" + ((comp)))->toInteger();;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
readline=sys.stdin.readline
N,A,B=map(int,readline().split())
*P,=map(int,readline().split())
Q=[0]*N
for i,p in enumerate(P):
    Q[p-1]=i
INF=10**18
dp=[[INF]*(N+1)for i in range(N+1)]
dp[0][0]=0
for i in range(N):
    qi=Q[i]
    for j in range(N):
        v=dp[i][j]
        dp[i+1][j]=min(dp[i+1][j],v+(A if qicollect( _x | (OclType["int"])->apply(_x) ) ;
(testlist_star_expr (star_expr * (expr (atom (name P)))) ,)    Sequence{(testlist_star_expr (star_expr * (expr (atom (name P)))) ,)} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var Q : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ;
    for _tuple : Integer.subrange(1, (P)->size())->collect( _indx | Sequence{_indx-1, (P)->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var p : OclAny := _tuple->at(_indx);
      Q[p - 1+1] := i) ;
    var INF : double := (10)->pow(18) ;
    var dp : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ INF }, (N + 1)))) ;
    dp->first()->first() := 0 ;
    for i : Integer.subrange(0, N-1) do (    var qi : OclAny := Q[i+1] ;
    for j : Integer.subrange(0, N-1) do (    var v : OclAny := dp[i+1][j+1] ;
    dp[i + 1+1][j+1] := Set{dp[i + 1+1][j+1], v + (if (qi->compareTo(j)) < 0 then A else B endif)}->min() ;
    dp[i+1][j + 1+1] := Set{dp[i+1][j + 1+1], v}->min() ;
    if Q[i+1] = j then (
      dp[i + 1+1][j + 1+1] := Set{dp[i + 1+1][j + 1+1], v}->min()
    ) else skip)) ;
    for i : Integer.subrange(0, N-1) do (    dp[i + 1+1][N+1] := Set{dp[i + 1+1][N+1], dp[i+1][N+1] + A}->min()) ;
    for j : Integer.subrange(0, N-1) do (    dp[N+1][j + 1+1] := Set{dp[N+1][j + 1+1], dp[N+1][j+1]}->min()) ;
(expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom "%d\n")) % (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name N)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name N)))))))) ]))))))))) ))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
aw=[[0,0]for i in range(n)]
for i,a in enumerate(map(int,input().split())): aw[i][0]=a
for i,w in enumerate(map(int,input().split())): aw[i][1]=w
migimin=1001
hidarimin=1001
for a,w in aw :
    if a : hidarimin=min(hidarimin,w)
    else : migimin=min(migimin,w)
if hidarimin>1000 or migimin>1000 : print(0)
else : print(hidarimin+migimin)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var aw : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{0}->union(Sequence{ 0 }))) ;
    for _tuple : Integer.subrange(1, ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->size())->collect( _indx | Sequence{_indx-1, ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var a : OclAny := _tuple->at(_indx);
      aw[i+1]->first() := a) ;
    for _tuple : Integer.subrange(1, ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->size())->collect( _indx | Sequence{_indx-1, ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var w : OclAny := _tuple->at(_indx);
      aw[i+1][1+1] := w) ;
    var migimin : int := 1001 ;
    var hidarimin : int := 1001 ;
    for _tuple : aw do (var _indx : int := 1;
      var a : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var w : OclAny := _tuple->at(_indx);
      if a then  (
      hidarimin := Set{hidarimin, w}->min()
    )
    else (
      migimin := Set{migimin, w}->min()
      )) ;
    if hidarimin > 1000 or migimin > 1000 then  (
      execute (0)->display()
    )
    else (
      execute (hidarimin + migimin)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import heapq
N=int(input())
A=list(map(int,input().split()))
B=input().split()
C=[]
for i in range(N):
    heapq.heappush(C,(A[i]-int(B[i]),i))
B=list(map(int,B))
ans=0
while True :
    v,i=heapq.heappop(C)
    if v==0 :
        break
    nv=B[i-1]+B[(i+1)% N]
    n=-v//nv
    if n<=0 :
        print(-1)
        exit()
    v+=n*nv
    B[i]-=n*nv
    heapq.heappush(C,(v,i))
    ans+=n
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var B : OclAny := input().split() ;
    var C : Sequence := Sequence{} ;
    for i : Integer.subrange(0, N-1) do (    heapq.heappush(C, Sequence{A[i+1] - ("" + ((B[i+1])))->toInteger(), i})) ;
    B := ((B)->collect( _x | (OclType["int"])->apply(_x) )) ;
    var ans : int := 0 ;
    while true do (    var v : OclAny := null;
    var i : OclAny := null;
    Sequence{v,i} := heapq.heappop(C) ;
    if v = 0 then (
      break
    ) else skip ;
    var nv : OclAny := B[i - 1+1] + B[(i + 1) mod N+1] ;
    var n : int := -v div nv ;
    if n <= 0 then (
      execute (-1)->display() ;
    exit()
    ) else skip ;
    v := v + n * nv ;
    B[i+1] := B[i+1] - n * nv ;
    heapq.heappush(C, Sequence{v, i}) ;
    ans := ans + n) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
import numpy as np
import gzip
import base64
import os
atcoder = {'name': 'numba_modules', 'file': 'numba_modules.cpython-34m.so', 'func': ['is_cond', 'solve', 'push', 'pop'], 'gz': ''}
gz = gzip.decompress(base64.b64decode(atcoder['gz']))
with open(os.path.join(os.path.dirname(__file__), atcoder['file']), 'wb') as f:
    f.write(gz)
from numba_modules import is_cond, solve, push, pop
line = sys.stdin.readline
N = int(line())
A = np.fromstring(line(), dtype=np.int32, sep=' ')
B = np.fromstring(line(), dtype=np.int32, sep=' ')
print(solve(A, B))

------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var atcoder : Map := Map{ 'name' |-> 'numba_modules' }->union(Map{ 'file' |-> 'numba_modules.cpython-34m.so' }->union(Map{ 'func' |-> Sequence{'is_cond'}->union(Sequence{'solve'}->union(Sequence{'push'}->union(Sequence{ 'pop' }))) }->union(Map{ 'gz' |-> '' }))) ;
    var gz : OclAny := gzip.decompress(base64.b64decode(atcoder->at('gz'))) ;
    try (var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(os.path.join(os.path.dirname(__file__), atcoder->at('file'))));
    f.write(gz))
    catch (_e : OclException) do skip ;
    skip ;
    var line : OclAny := (OclFile["System.in"]).readline ;
    var N : int := ("" + ((line())))->toInteger() ;
    var A : Sequence :=  ;
    var B : Sequence :=  ;
    execute (solve(A, B))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from heapq import heapify,heappop,heappush
def solve(n,aaa,bbb):
    q=[(-b,i)for i,b in enumerate(bbb)if b!=aaa[i]]
    heapify(q)
    ans=0
    while q :
        b,i=heappop(q)
        b=-b-aaa[i]
        d,b=divmod(b,bbb[(i-1)% n]+bbb[(i+1)% n])
        if d==0 :
            return-1
        b+=aaa[i]
        bbb[i]=b
        ans+=d
        if b!=aaa[i]:
            heappush(q,(-b,i))
    return ans
n=int(input())
aaa=list(map(int,input().split()))
bbb=list(map(int,input().split()))
print(solve(n,aaa,bbb))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    aaa := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    bbb := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute (solve(n, aaa, bbb))->display();
  operation solve(n : OclAny, aaa : OclAny, bbb : OclAny) : OclAny
  pre: true post: true
  activity:
    var q : Sequence := Integer.subrange(1, (bbb)->size())->collect( _indx | Sequence{_indx-1, (bbb)->at(_indx)} )->select(_tuple | let i : OclAny = _tuple->at(1) in let b : OclAny = _tuple->at(2) in b /= aaa[i+1])->collect(_tuple | let i : OclAny = _tuple->at(1) in let b : OclAny = _tuple->at(2) in (Sequence{-b, i})) ;
    heapify(q) ;
    var ans : int := 0 ;
    while q do (    var b : OclAny := null;
    var i : OclAny := null;
    Sequence{b,i} := heappop(q) ;
    var b : double := -b - aaa[i+1] ;
    var d : OclAny := null;
    Sequence{d,b} := Sequence{(b div bbb[(i - 1) mod n+1] + bbb[(i + 1) mod n+1]), (b mod bbb[(i - 1) mod n+1] + bbb[(i + 1) mod n+1])} ;
    if d = 0 then (
      return -1
    ) else skip ;
    b := b + aaa[i+1] ;
    bbb[i+1] := b ;
    ans := ans + d ;
    if b /= aaa[i+1] then (
      heappush(q, Sequence{-b, i})
    ) else skip) ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
reader=(s.rstrip()for s in sys.stdin)
input=reader.__next__
def unable():
    print(-1)
    exit()
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
from heapq import heappush,heappop
h=[]
base=10**6
for i in range(n):
    if a[i]>b[i]:
        unable()
    else :
        heappush(h,-(b[i]*base+i))
ans=0
while h :
    k=heappop(h)
    i=-k % base
    cnt,mod=divmod(b[i]-a[i],b[i-1]+b[(i+1)% n])
    if cnt==0 :
        if mod!=0 :
            unable()
    else :
        ans+=cnt
        b[i]=a[i]+mod
        heappush(h,-(b[i]*base+i))
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var reader : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name s)) (trailer . (name rstrip) (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin)))))))} ;
    var input : OclAny := reader.__next__ ;
    skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    skip ;
    var h : Sequence := Sequence{} ;
    var base : double := (10)->pow(6) ;
    for i : Integer.subrange(0, n-1) do (    if (a[i+1]->compareTo(b[i+1])) > 0 then  (
      unable()
    )
    else (
      heappush(h, -(b[i+1] * base + i))
      )) ;
    var ans : int := 0 ;
    while h do (    var k : OclAny := heappop(h) ;
    var i : int := -k mod base ;
    var cnt : OclAny := null;
    var mod : OclAny := null;
    Sequence{cnt,mod} := Sequence{(b[i+1] - a[i+1] div b[i - 1+1] + b[(i + 1) mod n+1]), (b[i+1] - a[i+1] mod b[i - 1+1] + b[(i + 1) mod n+1])} ;
    if cnt = 0 then  (
      if mod /= 0 then (
      unable()
    ) else skip
    )
    else (
      ans := ans + cnt ;
    b[i+1] := a[i+1] + mod ;
    heappush(h, -(b[i+1] * base + i))
      )) ;
    execute (ans)->display();
  operation unable()
  pre: true post: true
  activity:
    execute (-1)->display() ;
    exit();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit
ipt=stdin.readline
setrecursionlimit(10**7)
def main():
    n=int(ipt())
    a=[int(i)for i in ipt().split()]
    b=[int(i)for i in ipt().split()]
    hq=[]
    ans=0
    for i,bi in enumerate(b):
        if bi>a[i]:
            heapq.heappush(hq,(-bi,i))
    while len(hq)>0 :
        nbi,i=heapq.heappop(hq)
        if i==n-1 :
            bp=b[0]
        else :
            bp=b[i+1]
        bm=b[i-1]
        t=(-a[i]-nbi)//(bm+bp)
        if t==0 :
            print(-1)
            exit()
        b[i]-=(bm+bp)*t
        if b[i]>a[i]:
            heapq.heappush(hq,(-b[i],i))
        ans+=t
    print(ans)
    return
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var ipt : OclAny := stdin.readline ;
    setrecursionlimit((10)->pow(7)) ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var n : int := ("" + ((ipt())))->toInteger() ;
    var a : Sequence := ipt().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var b : Sequence := ipt().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var hq : Sequence := Sequence{} ;
    var ans : int := 0 ;
    for _tuple : Integer.subrange(1, (b)->size())->collect( _indx | Sequence{_indx-1, (b)->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var bi : OclAny := _tuple->at(_indx);
      if (bi->compareTo(a[i+1])) > 0 then (
      heapq.heappush(hq, Sequence{-bi, i})
    ) else skip) ;
    while (hq)->size() > 0 do (    var nbi : OclAny := null;
    var i : OclAny := null;
    Sequence{nbi,i} := heapq.heappop(hq) ;
    if i = n - 1 then  (
      var bp : OclAny := b->first()
    )
    else (
      bp := b[i + 1+1]
      ) ;
    var bm : OclAny := b[i - 1+1] ;
    var t : int := (-a[i+1] - nbi) div (bm + bp) ;
    if t = 0 then (
      execute (-1)->display() ;
    exit()
    ) else skip ;
    b[i+1] := b[i+1] - (bm + bp) * t ;
    if (b[i+1]->compareTo(a[i+1])) > 0 then (
      heapq.heappush(hq, Sequence{-b[i+1], i})
    ) else skip ;
    ans := ans + t) ;
    execute (ans)->display() ;
    return;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
i=1
while True :
    x=int(input())
    if x==0 :
        break
    print('Case{}:{}'.format(i,x))
    i=i+1
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var i : int := 1 ;
    while true do (    var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if x = 0 then (
      break
    ) else skip ;
    execute (StringLib.interpolateStrings('Case{}:{}', Sequence{i, x}))->display() ;
    i := i + 1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
idx=0
work=int(input())
I=str(work)+','
while work!=0 :
    work=int(input())
    I+=str(work)+','
    idx+=1
O=I.split(',')
i=0
while itoInteger() ;
    var I : String := ("" + ((work))) + ',' ;
    while work /= 0 do (    work := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    I := I + ("" + ((work))) + ',' ;
    idx := idx + 1) ;
    var O : OclAny := I.split(',') ;
    var i : int := 0 ;
    while (i->compareTo(idx)) < 0 do (    execute ("Case " + ("" + ((i + 1))) + ": " + O[i+1])->display() ;
    i := i + 1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import itertools as itr
if __name__=='__main__' :
    for i in itr.count(1):
        num=int(input())
        if num==0 : break
        print("Case{0}:{1}".format(i,num))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      for i : itr->count(1) do (    var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if num = 0 then (
      break
    ) else skip ;
    execute (StringLib.interpolateStrings("Case{0}:{1}", Sequence{i, num}))->display())
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
d,n=map(int,input().split())
t=[int(input())for _ in[0]*d]
abc=[list(map(int,input().split()))for _ in[0]*n]
memo=[-1]*101
t_list=[set()for _ in[0]*61]
for a,b,c in abc :
    for j in range(a,b+1):
        t_list[j].add(c)
for i in t_list[t[0]]:
    memo[i]=0
for i in t[1 :]:
    memo2=[-1]*101
    temp=[j for j in t_list[i]]
    for j,k in enumerate(memo):
        if k!=-1 :
            for l in temp :
                memo2[l]=max(memo2[l],k+abs(j-l))
    memo=memo2
print(max(memo))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var d : OclAny := null;
    var n : OclAny := null;
    Sequence{d,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var t : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, d)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ;
    var abc : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var memo : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, 101) ;
    var t_list : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 61)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ;
    for _tuple : abc do (var _indx : int := 1;
      var a : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var b : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var c : OclAny := _tuple->at(_indx);
      for j : Integer.subrange(a, b + 1-1) do ((expr (atom (name t_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))))) ;
    for i : t_list[t->first()+1] do (    memo[i+1] := 0) ;
    for i : t->tail() do (    var memo2 : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, 101) ;
    var temp : Sequence := t_list[i+1]->select(j | true)->collect(j | (j)) ;
    for _tuple : Integer.subrange(1, (memo)->size())->collect( _indx | Sequence{_indx-1, (memo)->at(_indx)} ) do (var _indx : int := 1;
      var j : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var k : OclAny := _tuple->at(_indx);
      if k /= -1 then (
      for l : temp do (    memo2[l+1] := Set{memo2[l+1], k + (j - l)->abs()}->max())
    ) else skip) ;
    memo := memo2) ;
    execute ((memo)->max())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys,os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
s=list(input().rstrip())
n=len(s)
ng=0
for i in range(n):
    f=0
    for j in range(i,n):
        k,l=j-1,j-2
        while l>=i :
            if s[j]==s[k]==s[l]:
                f=1
                break
            k-=1
            l-=2
        if f :
            break
        ng+=1
ans=n*(n+1)//2-ng
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := io.BytesIO(os.readAll()).readline ;
    var s : Sequence := (input().rstrip()) ;
    var n : int := (s)->size() ;
    var ng : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    var f : int := 0 ;
    for j : Integer.subrange(i, n-1) do (    var k : OclAny := null;
    var l : OclAny := null;
    Sequence{k,l} := Sequence{j - 1,j - 2} ;
    while (l->compareTo(i)) >= 0 do (    if s[j+1] = s[k+1] & (s[k+1] == s[l+1]) then (
      f := 1 ;
    break
    ) else skip ;
    k := k - 1 ;
    l := l - 2) ;
    if f then (
      break
    ) else skip ;
    ng := ng + 1)) ;
    var ans : double := n * (n + 1) div 2 - ng ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
count=1
while True :
    data=int(input())
    if(data!=0):
        text="Case %d: %d" %(count,data)
        print(text)
    else :
        exit()
    count+=1
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var count : int := 1 ;
    while true do (    var data : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if (data /= 0) then  (
      var text : String := StringLib.format("Case %d: %d",Sequence{count, data}) ;
    execute (text)->display()
    )
    else (
      exit()
      ) ;
    count := count + 1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
sys.setrecursionlimit(5000)
x=[]
while True :
    x.append(int(input()))
    if x[-1]==0 :
        break
for i in range(len(x)):
    if itoInteger()) : x) ;
    if x->last() = 0 then (
      break
    ) else skip) ;
    for i : Integer.subrange(0, (x)->size()-1) do (    if (i->compareTo((x)->size() - 1)) < 0 then (
      execute (StringLib.interpolateStrings("Case{}:{}", Sequence{i + 1, x[i+1]}))->display()
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
alst=list(map(int,input().split()))
wlst=list(map(int,input().split()))
right=[w for a,w in zip(alst,wlst)if a==0]
left=[w for a,w in zip(alst,wlst)if a==1]
if right and left :
    print(min(right)+min(left))
else :
    print(0)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var alst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var wlst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var right : Sequence := Integer.subrange(1, alst->size())->collect( _indx | Sequence{alst->at(_indx), wlst->at(_indx)} )->select(_tuple | let a : OclAny = _tuple->at(1) in let w : OclAny = _tuple->at(2) in a = 0)->collect(_tuple | let a : OclAny = _tuple->at(1) in let w : OclAny = _tuple->at(2) in (w)) ;
    var left : Sequence := Integer.subrange(1, alst->size())->collect( _indx | Sequence{alst->at(_indx), wlst->at(_indx)} )->select(_tuple | let a : OclAny = _tuple->at(1) in let w : OclAny = _tuple->at(2) in a = 1)->collect(_tuple | let a : OclAny = _tuple->at(1) in let w : OclAny = _tuple->at(2) in (w)) ;
    if right & left then  (
      execute ((right)->min() + (left)->min())->display()
    )
    else (
      execute (0)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def removeDuplicates(arr,n):
    st=0 ;
    for i in range(n):
        if(iunion(Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{3}->union(Sequence{3}->union(Sequence{3}->union(Sequence{3}->union(Sequence{3}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 }))))))))))))); ;
    n := (arr)->size(); ;
    removeDuplicates(arr, n);
    ) else skip;
  operation removeDuplicates(arr : OclAny, n : OclAny)
  pre: true post: true
  activity:
    var st : int := 0; ;
    for i : Integer.subrange(0, n-1) do (    if ((i->compareTo(n - 2)) < 0 & arr[i+1] = arr[i + 1+1] & arr[i+1] = arr[i + 2+1]) then  (
      continue;
    )
    else (
      arr[st+1] := arr[i+1]; ;
    st := st + 1;
      )) ;
    execute ("{")->display() ;
    for i : Integer.subrange(0, st-1) do (    execute (arr[i+1])->display(); ;
    if (i /= st - 1) then (
      execute (",")->display();
    ) else skip) ;
    execute ("}")->display();;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def gcd(a,b):
    if(a==0):
        return b ;
    return gcd(b % a,a);
def divTermCount(a,b,c,num):
    return((num/a)+(num/b)+(num/c)-(num/((a*b)/gcd(a,b)))-(num/((c*b)/gcd(c,b)))-(num/((a*c)/gcd(a,c)))+(num/((a*b*c)/gcd(gcd(a,b),c))));
def findNthTerm(a,b,c,n):
    low=1 ; high=sys.maxsize ; mid=0 ;
    while(lowdisplay();;
  operation gcd(a : OclAny, b : OclAny)
  pre: true post: true
  activity:
    if (a = 0) then (
      return b;
    ) else skip ;
    return gcd(b mod a, a);;
  operation divTermCount(a : OclAny, b : OclAny, c : OclAny, num : OclAny)
  pre: true post: true
  activity:
    return ((num / a) + (num / b) + (num / c) - (num / ((a * b) / gcd(a, b))) - (num / ((c * b) / gcd(c, b))) - (num / ((a * c) / gcd(a, c))) + (num / ((a * b * c) / gcd(gcd(a, b), c))));;
  operation findNthTerm(a : OclAny, b : OclAny, c : OclAny, n : OclAny)
  pre: true post: true
  activity:
    var low : int := 1;    var high : (trailer . (name maxsize)) := (trailer . (name maxsize));    var mid : int := 0; ;
    while ((low->compareTo(high)) < 0) do (    mid := low + (high - low) / 2; ;
    if ((divTermCount(a, b, c, mid)->compareTo(n)) < 0) then  (
      low := mid + 1;
    )
    else (
      high := mid;
      )) ;
    return ("" + ((low)))->toInteger();;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
N=1000
dp=[0]*(N+1)
def seive():
    array=[0]*(N+1)
    array[0]=1
    array[1]=1
    for i in range(2,math.ceil(math.sqrt(N)+1)):
        if array[i]==0 :
            for j in range(i*i,N+1,i):
                array[j]=1
    runningPrimeSum=0
    for i in range(1,N+1):
        if array[i]==0 :
            runningPrimeSum+=i
        dp[i]=runningPrimeSum
l=4
r=13
seive()
print(dp[r]-dp[l-1])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var N : int := 1000 ;
    var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ;
    skip ;
    var l : int := 4 ;
    var r : int := 13 ;
    seive() ;
    execute (dp[r+1] - dp[l - 1+1])->display();
  operation seive()
  pre: true post: true
  activity:
    var array : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ;
    array->first() := 1 ;
    array[1+1] := 1 ;
    for i : Integer.subrange(2, ((N)->sqrt() + 1)->ceil()-1) do (    if array[i+1] = 0 then (
      for j : Integer.subrange(i * i, N + 1-1)->select( $x | ($x - i * i) mod i = 0 ) do (    array[j+1] := 1)
    ) else skip) ;
    var runningPrimeSum : int := 0 ;
    for i : Integer.subrange(1, N + 1-1) do (    if array[i+1] = 0 then (
      runningPrimeSum := runningPrimeSum + i
    ) else skip ;
    dp[i+1] := runningPrimeSum);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
l=lambda : map(int,input().split())
n,k=l(); a=set()
for i in l():
    b=set(((i+j)% k)for j in a); a |=b ; a.add(i % k)
    if 0 in a : print("YES"); exit()
print("NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var l : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := l->apply();    var a : Set := Set{}->union(()) ;
    for i : l->apply() do (    var b : Set := Set{}->union(((argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name j)))))))) ))) % (expr (atom (name k)))))))) )))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name a)))))))));    a := a or b;    execute ((i mod k) : a) ;
    if (a)->includes(0) then (
      execute ("YES")->display();    exit()
    ) else skip) ;
    execute ("NO")->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
a=list(map(int,input().split()))
pre=[0 for _ in range(m)]
li=[]
def fun(i : int):
    if pre[i]==0 :
        li.append(i)
        pre[i]=1
for i in a :
    k=len(li)
    for j in range(k):
        fun((i+li[j])% m)
    fun(i % m)
    if(pre[0]==1):
        break
print("YES" if pre[0]==1 else "NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var pre : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (0)) ;
    var li : Sequence := Sequence{} ;
    skip ;
    for i : a do (    var k : int := (li)->size() ;
    for j : Integer.subrange(0, k-1) do (    fun((i + li[j+1]) mod m)) ;
    fun(i mod m) ;
    if (pre->first() = 1) then (
      break
    ) else skip) ;
    execute (if pre->first() = 1 then "YES" else "NO" endif)->display();
  operation fun(i : int)
  pre: true post: true
  activity:
    if pre[i+1] = 0 then (
      execute ((i) : li) ;
    pre[i+1] := 1
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
a=list(map(int,input().split()))
a=[0]+a
if n>m :
    print("YES")
else :
    d=[[0 for _ in range(m+1)]for _ in range(n+1)]
    for i in range(1,n+1):
        for j in range(m):
            d[i][(a[i]+j)% m]=d[i-1][(a[i]+j)% m]or d[i-1][j]
        d[i][a[i]% m]=1
    print("YES" if d[n][0]==1 else "NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    a := Sequence{ 0 }->union(a) ;
    if (n->compareTo(m)) > 0 then  (
      execute ("YES")->display()
    )
    else (
      var d : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, m + 1-1)->select(_anon | true)->collect(_anon | (0)))) ;
    for i : Integer.subrange(1, n + 1-1) do (    for j : Integer.subrange(0, m-1) do (    d[i+1][(a[i+1] + j) mod m+1] := d[i - 1+1][(a[i+1] + j) mod m+1] or d[i - 1+1][j+1]) ;
    d[i+1][a[i+1] mod m+1] := 1) ;
    execute (if d[n+1]->first() = 1 then "YES" else "NO" endif)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
m,n=[int(i)for i in input().split()]
seq=[int(i)for i in input().split()]
d=set()
for i in seq :
    w=set()
    for j in d : w.add((i+j)% n)
    d=d | w
    d.add(i % n)
    if 0 in d :
        print("YES")
        exit()
print("NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var m : OclAny := null;
    var n : OclAny := null;
    Sequence{m,n} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var seq : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var d : Set := Set{}->union(()) ;
    for i : seq do (    var w : Set := Set{}->union(()) ;
    for j : d do (    execute (((i + j) mod n) : w)) ;
    d := MathLib.bitwiseOr(d, w) ;
    execute ((i mod n) : d) ;
    if (d)->includes(0) then (
      execute ("YES")->display() ;
    exit()
    ) else skip) ;
    execute ("NO")->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
s=list(input().rstrip())
n=len(s)
for i in range(n):
    s[i]=int(s[i])
ans=n*(n-1)//2
if n>=2 :
    ans-=n-1
for d in range(3,13):
    for i in range(n):
        if i+d>n :
            break
        s1=s[i : i+d]
        flg=False
        for k in range(1,5):
            for st in range(d):
                if st+2*k>=d :
                    break
                if s1[st]==s1[st+k]==s1[st+2*k]:
                    flg=True
                    break
        if not flg :
            ans-=1
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    var s : Sequence := (input().rstrip()) ;
    var n : int := (s)->size() ;
    for i : Integer.subrange(0, n-1) do (    s[i+1] := ("" + ((s[i+1])))->toInteger()) ;
    var ans : int := n * (n - 1) div 2 ;
    if n >= 2 then (
      ans := ans - n - 1
    ) else skip ;
    for d : Integer.subrange(3, 13-1) do (    for i : Integer.subrange(0, n-1) do (    if (i + d->compareTo(n)) > 0 then (
      break
    ) else skip ;
    var s1 : OclAny := s.subrange(i+1, i + d) ;
    var flg : boolean := false ;
    for k : Integer.subrange(1, 5-1) do (    for st : Integer.subrange(0, d-1) do (    if (st + 2 * k->compareTo(d)) >= 0 then (
      break
    ) else skip ;
    if s1[st+1] = s1[st + k+1] & (s1[st + k+1] == s1[st + 2 * k+1]) then (
      flg := true ;
    break
    ) else skip)) ;
    if not(flg) then (
      ans := ans - 1
    ) else skip)) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def cntSubsets(arr,n):
    a=[0]*n
    b=[0]*n ;
    a[0]=b[0]=1 ;
    for i in range(1,n):
        a[i]=a[i-1]+b[i-1];
        b[i]=a[i-1];
    result=a[n-1]+b[n-1];
    return result ;
if __name__=="__main__" :
    arr=[3,5,7];
    n=len(arr);
    print(cntSubsets(arr,n));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      arr := Sequence{3}->union(Sequence{5}->union(Sequence{ 7 })); ;
    n := (arr)->size(); ;
    execute (cntSubsets(arr, n))->display();
    ) else skip;
  operation cntSubsets(arr : OclAny, n : OclAny)
  pre: true post: true
  activity:
    var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ;
    var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ;
    a->first() := 1; var b->first() : int := 1; ;
    for i : Integer.subrange(1, n-1) do (    a[i+1] := a[i - 1+1] + b[i - 1+1]; ;
    b[i+1] := a[i - 1+1];) ;
    var result : OclAny := a[n - 1+1] + b[n - 1+1]; ;
    return result;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
N,A,B=map(int,input().split())
BIT=0
for i in range(N):
    if(1<collect( _x | (OclType["int"])->apply(_x) ) ;
    var BIT : int := 0 ;
    for i : Integer.subrange(0, N-1) do (    if MathLib.bitwiseAnd((1 * (2->pow(i))), A) /= MathLib.bitwiseAnd((1 * (2->pow(i))), B) then (
      BIT := BIT + 1
    ) else skip) ;
    if BIT mod 2 = 1 then  (
      execute ("YES")->display()
    )
    else (
      execute ("NO")->display() ;
    sys.exit()
      ) ;
    var check : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (1 * (2->pow(N)))) ;
    var ANS : Sequence := Sequence{} ;
    check[A+1] := 1 ;
    check[B+1] := 1 ;
    skip ;
    var checkbit : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ;
    for i : Integer.subrange(-1 + 1, N - 1)->reverse() do (    for j : Integer.subrange(0, N-1) do (    if MathLib.bitwiseAnd((1 * (2->pow(j))), A) /= MathLib.bitwiseAnd((1 * (2->pow(j))), B) & checkbit[j+1] = 0 then (
      break
    ) else skip) ;
    var A : OclAny := route(A, j, i) ;
    checkbit[j+1] := 1) ;
    execute ((B) : ANS) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name ANS))))))))->display();
  operation route(x : OclAny, i : OclAny, j : OclAny) : OclAny
  pre: true post: true
  activity:
    var NOW : OclAny := x ;
    execute ((NOW) : ANS) ;
    check[NOW+1] := 1 ;
    for k : Integer.subrange(0, 1 * (2->pow(j))-1) do (    for l : Integer.subrange(0, N-1) do (    if check[MathLib.bitwiseXor(NOW, (1 * (2->pow(l))))+1] = 0 & l /= i then (
      NOW := MathLib.bitwiseXor(NOW, (1 * (2->pow(l)))) ;
    check[NOW+1] := 1 ;
    execute ((NOW) : ANS) ;
    break
    ) else skip)) ;
    return MathLib.bitwiseXor(NOW, (1 * (2->pow(i))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
sys.setrecursionlimit(10**6)
n,a,b=map(int,input().split())
def pop_count(x):
    res=0
    for i in range(17):
        res+=((x>>i)% 2==1)
    return res
if(pop_count(a ^ b))% 2==0 :
    print("NO")
else :
    print("YES")
    def f(m,x,y):
        if m==1 :
            if x==0 :
                return[0,1]
            else :
                return[1,0]
        res=[x]
        for i in range(m):
            if(x>>i)% 2!=(y>>i)% 2 :
                diff=i
                break
        s=(x %(2**diff))+(((x//(2**(diff+1)))*2**(diff+1))>>1)
        t=(y %(2**diff))+(((y//(2**(diff+1)))*2**(diff+1))>>1)
        u=s ^ 1
        left=f(m-1,s,u)
        right=f(m-1,u,t)
        x_bit,y_bit=(x>>diff)% 2,(y>>diff)% 2
        left=[l %(2**diff)+(2**diff*x_bit)+(((l//(2**diff))*2**diff)<<1)for l in left]
        right=[r %(2**diff)+(2**diff*y_bit)+(((r//(2**diff))*2**diff)<<1)for r in right]
        return left+right
    print(*f(n,a,b))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    sys.setrecursionlimit((10)->pow(6)) ;
    var n : OclAny := null;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    skip ;
    if (pop_count(MathLib.bitwiseXor(a, b))) mod 2 = 0 then  (
      execute ("NO")->display()
    )
    else (
      execute ("YES")->display() ;
    skip ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name f)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n))))))) , (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))))))))->display()
      );
  operation pop_count(x : OclAny) : OclAny
  pre: true post: true
  activity:
    var res : int := 0 ;
    for i : Integer.subrange(0, 17-1) do (    res := res + ((x /(2->pow(i))) mod 2 = 1)) ;
    return res;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=int(input())
*A,=map(int,input().split())
*W,=map(int,input().split())
INF=10**9
l=r=INF
for a,w in zip(A,W):
    if a :
        r=min(w,r)
    else :
        l=min(w,l)
if l==INF or r==INF :
    print(0)
else :
    print(l+r)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
(testlist_star_expr (star_expr * (expr (atom (name A)))) ,)    Sequence{(testlist_star_expr (star_expr * (expr (atom (name A)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
(testlist_star_expr (star_expr * (expr (atom (name W)))) ,)    Sequence{(testlist_star_expr (star_expr * (expr (atom (name W)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var INF : double := (10)->pow(9) ;
    var l : OclAny := INF; var r : OclAny := INF ;
    for _tuple : Integer.subrange(1, A->size())->collect( _indx | Sequence{A->at(_indx), W->at(_indx)} ) do (var _indx : int := 1;
      var a : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var w : OclAny := _tuple->at(_indx);
      if a then  (
      r := Set{w, r}->min()
    )
    else (
      l := Set{w, l}->min()
      )) ;
    if l = INF or r = INF then  (
      execute (0)->display()
    )
    else (
      execute (l + r)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
N,A,B=map(int,input().split())
def seq(start,bits):
    arr=[0]
    for i in bits :
        arr+=[x ^(1<collect( _x | (OclType["int"])->apply(_x) ) ;
    skip ;
    skip ;
    rest := (Integer.subrange(0, N-1)) ;
    var answer : OclAny := solve(A, B, rest) ;
    if answer <>= null then  (
      execute ('NO')->display()
    )
    else (
      execute ('YES')->display() ;
    execute (StringLib.sumStringsWithSeparator(((answer)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()
      );
  operation seq(start : OclAny, bits : OclAny) : OclAny
  pre: true post: true
  activity:
    var arr : Sequence := Sequence{ 0 } ;
    for i : bits do (    arr := arr + arr(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->select(x | true)->collect(x | (MathLib.bitwiseXor(x, (1 * (2->pow(i))))))) ;
    return arr->select(x | true)->collect(x | (MathLib.bitwiseXor(x, start)));
  operation solve(A : OclAny, B : OclAny, rest : OclAny) : OclAny
  pre: true post: true
  activity:
    if (rest)->size() = 1 then (
      return Sequence{A}->union(Sequence{ B })
    ) else skip ;
    if (rest)->size() = 2 then (
      var i : OclAny := null;
    var j : OclAny := null;
    Sequence{i,j} := rest ;
    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := Sequence{1 * (2->pow(i)),1 * (2->pow(j))} ;
    if MathLib.bitwiseXor(A, x) = B then  (
      return Sequence{A}->union(Sequence{MathLib.bitwiseXor(A, y)}->union(Sequence{MathLib.bitwiseXor(MathLib.bitwiseXor(A, x), y)}->union(Sequence{ B })))
    )
    else (if MathLib.bitwiseXor(A, y) = B then
   (
      return Sequence{A}->union(Sequence{MathLib.bitwiseXor(A, x)}->union(Sequence{MathLib.bitwiseXor(MathLib.bitwiseXor(A, x), y)}->union(Sequence{ B })))    
)
    else (
      return null
      )    )
    ) else skip ;
    var diff_bit : Sequence := rest->select(i | (MathLib.bitwiseAnd(A, (1 * (2->pow(i))))) /= (MathLib.bitwiseAnd(B, (1 * (2->pow(i))))))->collect(i | (i)) ;
    if (diff_bit)->size() mod 2 = 0 then (
      return null
    ) else skip ;
    var i : OclAny := diff_bit->first() ;
    rest := rest->select(j | j /= i)->collect(j | (j)) ;
    if MathLib.bitwiseXor(MathLib.bitwiseXor(A, (1 * (2->pow(rest->first())))), (1 * (2->pow(i)))) = B then (
      var rest->first() : OclAny := null;
    var rest[1+1] : OclAny := null;
    Sequence{rest->first(),rest[1+1]} := Sequence{rest[1+1],rest->first()}
    ) else skip ;
    arr := seq(A, rest) ;
    return arr->union(solve(MathLib.bitwiseXor(arr->last(), (1 * (2->pow(i)))), B, rest));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
sys.setrecursionlimit(10**6)
int1=lambda x : int(x)-1
p2D=lambda x : print(*x,sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int,sys.stdin.readline().split())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LLI(rows_number): return[LI()for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
def bit(xx): return[format(x,"b")for x in xx]
popcnt=lambda x : bin(x).count("1")
def solve(xx,a,b):
    if len(xx)==2 : return[a,b]
    k=(a ^ b).bit_length()-1
    aa=[]
    bb=[]
    for x in xx :
        if(x>>k & 1)==(a>>k & 1): aa.append(x)
        else : bb.append(x)
    i=0
    mid=aa[i]
    while mid==a or(mid ^ 1<pow(6)) ;
    var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ;
    var p2D : Function := lambda x : OclAny in (((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var popcnt : Function := lambda x : OclAny in (bin(x)->count("1")) ;
    skip ;
    skip ;
    main();
  operation II() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation MI() : OclAny
  pre: true post: true
  activity:
    return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) );
  operation LI() : OclAny
  pre: true post: true
  activity:
    return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ));
  operation LLI(rows_number : OclAny) : OclAny
  pre: true post: true
  activity:
    return Integer.subrange(0, rows_number-1)->select(_anon | true)->collect(_anon | (LI()));
  operation SI() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine()->front();
  operation bit(xx : OclAny) : OclAny
  pre: true post: true
  activity:
    return xx->select(x | true)->collect(x | ((x + "")));
  operation solve(xx : OclAny, a : OclAny, b : OclAny) : OclAny
  pre: true post: true
  activity:
    if (xx)->size() = 2 then (
      return Sequence{a}->union(Sequence{ b })
    ) else skip ;
    var k : double := (MathLib.bitwiseXor(a, b)).bit_length() - 1 ;
    var aa : Sequence := Sequence{} ;
    var bb : Sequence := Sequence{} ;
    for x : xx do (    if (MathLib.bitwiseAnd(x /(2->pow(k)), 1)) = (MathLib.bitwiseAnd(a /(2->pow(k)), 1)) then  (
      execute ((x) : aa)
    )
    else (
      execute ((x) : bb)
      )) ;
    var i : int := 0 ;
    var mid : OclAny := aa[i+1] ;
    while mid = a or (MathLib.bitwiseXor(mid, 1 * (2->pow(k)))) = b or MathLib.bitwiseAnd(popcnt->apply(a), 1) = MathLib.bitwiseAnd(popcnt->apply(mid), 1) do (    i := i + 1 ;
    mid := aa[i+1]) ;
    return solve(aa, a, mid) + solve(bb, MathLib.bitwiseXor(mid, 1 * (2->pow(k))), b);
  operation main()
  pre: true post: true
  activity:
    var n : OclAny := null;
    Sequence{n,a,b} := MI() ;
    if MathLib.bitwiseXor((MathLib.bitwiseAnd(popcnt->apply(a), 1)), (MathLib.bitwiseAnd(popcnt->apply(b), 1))) = 0 then (
      execute ("NO")->display() ;
    exit()
    ) else skip ;
    execute ("YES")->display() ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name solve)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name n))))))))) ))))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N,A,B=map(int,input().split())
M=2**(N-1)
if N==1 :
    print('YES')
    print(A,B)
    exit()
gray=[0]
for i in range(1,M):
    gray.append(gray[-1]^(i &(-i)))
grid=[gray,[a+M for a in gray]]
for i,row in enumerate(grid):
    if A in row :
        sx,sy=row.index(A),i
    if B in row :
        gx,gy=row.index(B),i
if(abs(sx-gx)+abs(sy-gy))% 2 :
    print('YES')
else :
    print('NO')
    exit()
ans=[A]
x,y=sx,sy
while(gx-x)% M!=1 :
    x+=1
    x %=M
    ans.append(grid[y][x])
y=1-y
ans.append(grid[y][x])
while x!=sx :
    x-=1
    x %=M
    ans.append(grid[y][x])
if x!=gx :
    while 1 :
        x-=1
        x %=M
        ans.append(grid[y][x])
        y=1-y
        ans.append(grid[y][x])
        if x==gx : break
print(*ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : OclAny := null;
    var A : OclAny := null;
    var B : OclAny := null;
    Sequence{N,A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var M : double := (2)->pow((N - 1)) ;
    if N = 1 then (
      execute ('YES')->display() ;
    execute (A)->display() ;
    exit()
    ) else skip ;
    var gray : Sequence := Sequence{ 0 } ;
    for i : Integer.subrange(1, M-1) do (    execute ((MathLib.bitwiseXor(gray->last(), (MathLib.bitwiseAnd(i, (-i))))) : gray)) ;
    var grid : Sequence := Sequence{gray}->union(Sequence{ gray->select(a | true)->collect(a | (a + M)) }) ;
    for _tuple : Integer.subrange(1, (grid)->size())->collect( _indx | Sequence{_indx-1, (grid)->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var row : OclAny := _tuple->at(_indx);
      if (row)->includes(A) then (
      var sx : OclAny := null;
    var sy : OclAny := null;
    Sequence{sx,sy} := Sequence{row->indexOf(A) - 1,i}
    ) else skip ;
    if (row)->includes(B) then (
      var gx : OclAny := null;
    var gy : OclAny := null;
    Sequence{gx,gy} := Sequence{row->indexOf(B) - 1,i}
    ) else skip) ;
    if ((sx - gx)->abs() + (sy - gy)->abs()) mod 2 then  (
      execute ('YES')->display()
    )
    else (
      execute ('NO')->display() ;
    exit()
      ) ;
    var ans : Sequence := Sequence{ A } ;
    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := Sequence{sx,sy} ;
    while (gx - x) mod M /= 1 do (    x := x + 1 ;
    x := x mod M ;
    execute ((grid[y+1][x+1]) : ans)) ;
    var y : double := 1 - y ;
    execute ((grid[y+1][x+1]) : ans) ;
    while x /= sx do (    x := x - 1 ;
    x := x mod M ;
    execute ((grid[y+1][x+1]) : ans)) ;
    if x /= gx then (
      while 1 do (    x := x - 1 ;
    x := x mod M ;
    execute ((grid[y+1][x+1]) : ans) ;
    y := 1 - y ;
    execute ((grid[y+1][x+1]) : ans) ;
    if x = gx then (
      break
    ) else skip)
    ) else skip ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def isPowerOfTwo(x):
    return(x and(not(x &(x-1))))
if(isPowerOfTwo(31)):
    print('Yes')
else :
    print('No')
if(isPowerOfTwo(64)):
    print('Yes')
else :
    print('No')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if (isPowerOfTwo(31)) then  (
      execute ('Yes')->display()
    )
    else (
      execute ('No')->display()
      ) ;
    if (isPowerOfTwo(64)) then  (
      execute ('Yes')->display()
    )
    else (
      execute ('No')->display()
      );
  operation isPowerOfTwo(x : OclAny) : OclAny
  pre: true post: true
  activity:
    return (x & (not((MathLib.bitwiseAnd(x, (x - 1))))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys,os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
w1,h1,w2,h2=map(int,input().split())
ans=w1+2*h1+2+w2+2*h2+2+w1-w2
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := io.BytesIO(os.readAll()).readline ;
    var w1 : OclAny := null;
    var h1 : OclAny := null;
    var w2 : OclAny := null;
    var h2 : OclAny := null;
    Sequence{w1,h1,w2,h2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var ans : double := w1 + 2 * h1 + 2 + w2 + 2 * h2 + 2 + w1 - w2 ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
w1,h1,w2,h2=map(int,input().split())
print(2*(h1+h2)+(2*w1)+4)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var w1 : OclAny := null;
    var h1 : OclAny := null;
    var w2 : OclAny := null;
    var h2 : OclAny := null;
    Sequence{w1,h1,w2,h2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (2 * (h1 + h2) + (2 * w1) + 4)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math,sys ; input=sys.stdin.readline ; S=lambda : input().rstrip(); I=lambda : int(S()); M=lambda : map(int,S().split()); L=lambda : list(M()); mod1=1000000007 ; mod2=998244353
n=I(); a=L(); d={}
for i in range(n):
    for j in range(i):
        if a[i]+a[j]not in d :
            d[a[i]+a[j]]=(i,j)
        else :
            s=a[i]+a[j]
            x=d[s]
            if i not in x and j not in x :
                print("YES")
                print(x[0]+1,x[1]+1,i+1,j+1)
                exit()
print("NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip;    var input : OclAny := (OclFile["System.in"]).readline;    var S : Function := lambda $$ : OclAny in (input().rstrip());    var I : Function := lambda $$ : OclAny in (("" + ((S->apply())))->toInteger());    var M : Function := lambda $$ : OclAny in ((S->apply().split())->collect( _x | (OclType["int"])->apply(_x) ));    var L : Function := lambda $$ : OclAny in ((M->apply()));    var mod1 : int := 1000000007;    var mod2 : int := 998244353 ;
    var n : OclAny := I->apply();    var a : OclAny := L->apply();    var d : OclAny := Set{} ;
    for i : Integer.subrange(0, n-1) do (    for j : Integer.subrange(0, i-1) do (    if (d)->excludes(a[i+1] + a[j+1]) then  (
      d[a[i+1] + a[j+1]+1] := Sequence{i, j}
    )
    else (
      var s : OclAny := a[i+1] + a[j+1] ;
    var x : OclAny := d[s+1] ;
    if (x)->excludes(i) & (x)->excludes(j) then (
      execute ("YES")->display() ;
    execute (x->first() + 1)->display() ;
    exit()
    ) else skip
      ))) ;
    execute ("NO")->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
w1,h1,w2,h2=map(int,input().split())
s=w1*h1+w2*h2
r=(w1+2)*(h1+1)+(w2+2)*(h2+1)+w1-w2
print(r-s)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var w1 : OclAny := null;
    var h1 : OclAny := null;
    var w2 : OclAny := null;
    var h2 : OclAny := null;
    Sequence{w1,h1,w2,h2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var s : double := w1 * h1 + w2 * h2 ;
    var r : double := (w1 + 2) * (h1 + 1) + (w2 + 2) * (h2 + 1) + w1 - w2 ;
    execute (r - s)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
w1,h1,w2,h2=map(int,input().split())
res=0
res+=2*(h1+h2+2)
res+=2*w1
print(res)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var w1 : OclAny := null;
    var h1 : OclAny := null;
    var w2 : OclAny := null;
    var h2 : OclAny := null;
    Sequence{w1,h1,w2,h2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var res : int := 0 ;
    res := res + 2 * (h1 + h2 + 2) ;
    res := res + 2 * w1 ;
    execute (res)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
w1,h1,w2,h2=map(int,input().split())
print((w1+h1+h2)*2+4)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var w1 : OclAny := null;
    var h1 : OclAny := null;
    var w2 : OclAny := null;
    var h2 : OclAny := null;
    Sequence{w1,h1,w2,h2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute ((w1 + h1 + h2) * 2 + 4)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while 1 :
    n,m=map(int,input().split())
    if n==m==0 :
        break
    B=[int(input(),2)for i in range(n)]
    C={0 : 0}
    for b in B :
        D=dict(C)
        for k in C :
            D[k ^ b]=max(D.get(k ^ b,0),C[k]+1)
        C=D
    print(C[0])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while 1 do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if n = m & (m == 0) then (
      break
    ) else skip ;
    var B : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine(), 2)))->toInteger())) ;
    var C : Map := Map{ 0 |-> 0 } ;
    for b : B do (    var D : Map := ((atom (name C))) ;
    for k : C->keys() do (    D[MathLib.bitwiseXor(k, b)+1] := Set{D.get(MathLib.bitwiseXor(k, b), 0), C[k+1] + 1}->max()) ;
    C := D) ;
    execute (C->first())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
while t>0 :
    s,i,e=map(int,input().split())
    if e==0 :
        if s>i :
            print("1")
        else :
            print("0")
    else :
        if s>i :
            if e>=s-i :
                j=(e+i-s)
                if j<0 :
                    print(e)
                else :
                    print(e-int(j/2))
            else :
                print(e+1)
        else :
            e=e+s-i-1
            s=i+1
            if e>0 :
                if e>=s-i :
                    j=(e+i-s)
                    if j<0 :
                        print(e)
                    else :
                        print(e-int(j/2))
            elif e==0 :
                print("1")
            else :
                print("0")
    t=t-1
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    while t > 0 do (    var s : OclAny := null;
    var i : OclAny := null;
    var e : OclAny := null;
    Sequence{s,i,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if e = 0 then  (
      if (s->compareTo(i)) > 0 then  (
      execute ("1")->display()
    )
    else (
      execute ("0")->display()
      )
    )
    else (
      if (s->compareTo(i)) > 0 then  (
      if (e->compareTo(s - i)) >= 0 then  (
      var j : double := (e + i - s) ;
    if j < 0 then  (
      execute (e)->display()
    )
    else (
      execute (e - ("" + ((j / 2)))->toInteger())->display()
      )
    )
    else (
      execute (e + 1)->display()
      )
    )
    else (
      var e : double := e + s - i - 1 ;
    var s : OclAny := i + 1 ;
    if e > 0 then  (
      if (e->compareTo(s - i)) >= 0 then (
      j := (e + i - s) ;
    if j < 0 then  (
      execute (e)->display()
    )
    else (
      execute (e - ("" + ((j / 2)))->toInteger())->display()
      )
    ) else skip
    )
    else (if e = 0 then
   (
      execute ("1")->display()    
)
    else (
      execute ("0")->display()
      )    )
      )
      ) ;
    t := t - 1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
iipt=lambda : int(input())
miipt=lambda : list(map(int,input().split()))
from pprint import pprint
r=[]
n=m=0
def solven(k,i):
    if i==n :
        return-1 if k else 0
    s1=solven(k ^ r[i],i+1)
    if s1!=-1 :
        s1+=1
    return max(s1,solven(k,i+1))
while True :
    n,m=miipt()
    if n==m==0 :
        break
    r=[int(input(),2)for i in range(n)]
    if n<22 :
        print(solven(0,0))
    else :
        dp={}
        dp[0]=0
        for i in range(n):
            dp_=dp.copy()
            for k,v in dp_.items():
                if k ^ r[i]in dp :
                    dp[k ^ r[i]]=max(dp[k ^ r[i]],v+1)
                else :
                    dp[k ^ r[i]]=v+1
        print(dp[0])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var iipt : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ;
    var miipt : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ;
    skip ;
    var r : Sequence := Sequence{} ;
    var n : OclAny := 0; var m : int := 0 ;
    skip ;
    while true do (    Sequence{n,m} := miipt->apply() ;
    if n = m & (m == 0) then (
      break
    ) else skip ;
    r := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine(), 2)))->toInteger())) ;
    if n < 22 then  (
      execute (solven(0, 0))->display()
    )
    else (
      var dp : OclAny := Set{} ;
    dp->first() := 0 ;
    for i : Integer.subrange(0, n-1) do (    var dp_ : OclAny := dp->copy() ;
    for _tuple : dp_->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1;
      var k : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var v : OclAny := _tuple->at(_indx);
      if (dp)->includes(MathLib.bitwiseXor(k, r[i+1])) then  (
      dp[MathLib.bitwiseXor(k, r[i+1])+1] := Set{dp[MathLib.bitwiseXor(k, r[i+1])+1], v + 1}->max()
    )
    else (
      dp[MathLib.bitwiseXor(k, r[i+1])+1] := v + 1
      ))) ;
    execute (dp->first())->display()
      ));
  operation solven(k : OclAny, i : OclAny) : OclAny
  pre: true post: true
  activity:
    if i = n then (
      return if k then -1 else 0 endif
    ) else skip ;
    var s1 : OclAny := solven(MathLib.bitwiseXor(k, r[i+1]), i + 1) ;
    if s1 /= -1 then (
      s1 := s1 + 1
    ) else skip ;
    return Set{s1, solven(k, i + 1)}->max();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
from collections import defaultdict
def solve(n,m):
    b=[int(sys.stdin.readline(),2)for i in range(n)]
    if nans :
                    ans=s
        print(ans)
    else :
        dp=defaultdict(lambda : 0)
        dp[0]=0
        for i in b :
            d=dp.copy()
            for j in d.keys():
                j_=i ^ j
                if d[j]+1>dp[j_]:
                    dp[j_]=d[j]+1
        print(dp[0])
while 1 :
    n,m=[int(x)for x in sys.stdin.readline().split()]
    if n==0 :
        break
    solve(n,m)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    while 1 do (    Sequence{n,m} := sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    if n = 0 then (
      break
    ) else skip ;
    solve(n, m));
  operation solve(n : OclAny, m : OclAny)
  pre: true post: true
  activity:
    var b : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine(), 2)))->toInteger())) ;
    if (n->compareTo(m)) < 0 then  (
      var M : int := 1 * (2->pow(n)) ;
    var ans : int := 0 ;
    for i : Integer.subrange(0, M-1) do (    var k : int := 0 ;
    var s : int := 0 ;
    for j : Integer.subrange(0, n-1) do (    if MathLib.bitwiseAnd(i, (1 * (2->pow(j)))) then (
      k := k xor b[j+1] ;
    s := s + 1
    ) else skip) ;
    if not(k) then (
      if (s->compareTo(ans)) > 0 then (
      ans := s
    ) else skip
    ) else skip) ;
    execute (ans)->display()
    )
    else (
      var dp : OclAny := defaultdict(lambda $$ : OclAny in (0)) ;
    dp->first() := 0 ;
    for i : b do (    var d : OclAny := dp->copy() ;
    for j : d.keys() do (    var j_ : int := MathLib.bitwiseXor(i, j) ;
    if (d[j+1] + 1->compareTo(dp[j_+1])) > 0 then (
      dp[j_+1] := d[j+1] + 1
    ) else skip)) ;
    execute (dp->first())->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush,heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod=10**9+7
inf=float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
while 1 :
    n,m=LI()
    if n==0 and m==0 :
        quit()
    recipe=[]
    for _ in range(n):
        c=list(map(int,list(input())))
        s=0
        t=1
        for i in range(m):
            s+=c[m-i-1]*t
            t*=2
        recipe.append(s)
    dp=defaultdict(int)
    dp[0]=0
    for r in recipe :
        dp1=defaultdict(int)
        for j,k in dp.items():
            dp1[j]=k
        for j,k in dp.items():
            dp1[j ^ r]=max(dp1[j ^ r],k+1)
        dp=dp1
    print(dp[0])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    sys.setrecursionlimit(2147483647) ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var mod : double := (10)->pow(9) + 7 ;
    var Math_PINFINITY : double := ("" + (('inf')))->toReal() ;
    skip ;
    skip ;
    while 1 do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := LI() ;
    if n = 0 & m = 0 then (
      quit()
    ) else skip ;
    var recipe : Sequence := Sequence{} ;
    for _anon : Integer.subrange(0, n-1) do (    var c : Sequence := ((((OclFile["System.in"]).readLine())->characters())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var s : int := 0 ;
    var t : int := 1 ;
    for i : Integer.subrange(0, m-1) do (    s := s + c[m - i - 1+1] * t ;
    t := t * 2) ;
    execute ((s) : recipe)) ;
    var dp : OclAny := defaultdict(OclType["int"]) ;
    dp->first() := 0 ;
    for r : recipe do (    var dp1 : OclAny := defaultdict(OclType["int"]) ;
    for _tuple : dp->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1;
      var j : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var k : OclAny := _tuple->at(_indx);
      dp1[j+1] := k) ;
    for _tuple : dp->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1;
      var j : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var k : OclAny := _tuple->at(_indx);
      dp1[MathLib.bitwiseXor(j, r)+1] := Set{dp1[MathLib.bitwiseXor(j, r)+1], k + 1}->max()) ;
    dp := dp1) ;
    execute (dp->first())->display());
  operation I() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation LI() : OclAny
  pre: true post: true
  activity:
    return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def make(n):
    C={0 : 0}
    for i in range(n):
        b=int(input(),2)
        for k,v in dict(C).items():
            if C.get(k ^ b,0)display();
  operation make(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var C : Map := Map{ 0 |-> 0 } ;
    for i : Integer.subrange(0, n-1) do (    var b : int := ("" + (((OclFile["System.in"]).readLine(), 2)))->toInteger() ;
    for _tuple : OclType["Map"](C)->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1;
      var k : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var v : OclAny := _tuple->at(_indx);
      if (C.get(MathLib.bitwiseXor(k, b), 0)->compareTo(v + 1)) < 0 then (
      C[MathLib.bitwiseXor(k, b)+1] := v + 1
    ) else skip)) ;
    return C;
  operation calc(P : OclAny, Q : OclAny)
  pre: true post: true
  activity:
    if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return 0 ;
    for _tuple : P->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1;
      var k : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var v : OclAny := _tuple->at(_indx);
      if (Q)->includes(k) then (
      if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return v + Q[k+1]
    ) else skip);
  operation solve(_position_ : int) : OclAny
  pre: true post: true
  activity:
    var _yieldCount_ : int := 0;
    while 1 do (    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if n + m = 0 then (
      break
    ) else skip ;
    if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return (calc(make(n div 2), make(n - n div 2)))->max());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=set()
for i in range(int(input())):
    b,c=map(int,input().split())
    if b==0 :
        a.add(c)
        print(len(a))
    else :
        print(int(c in a))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : Set := Set{}->union(()) ;
    for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if b = 0 then  (
      execute ((c) : a) ;
    execute ((a)->size())->display()
    )
    else (
      execute (("" + (((a)->includes(c))))->toInteger())->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import Counter
def solve(N,nums):
    res,ans=False,[]
    vis={}
    for i in range(N):
        for j in range(i):
            v=nums[i]+nums[j]
            if v in vis :
                ii,jj=vis[v]
                can=[i+1,j+1,ii+1,jj+1]
                if len(set(can))==4 :
                    ans=can[:]
                    res=True
                    return res,ans
            else :
                vis[v]=(i,j)
    return False,[]
N=int(input())
nums=list(map(int,input().split()))
res,ans=solve(N,nums)
if res :
    print("Yes")
    print(ans[0],ans[1],ans[2],ans[3])
else :
    print("No")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    nums := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    Sequence{res,ans} := solve(N, nums) ;
    if res then  (
      execute ("Yes")->display() ;
    execute (ans->first())->display()
    )
    else (
      execute ("No")->display()
      );
  operation solve(N : OclAny, nums : OclAny) : OclAny
  pre: true post: true
  activity:
    var res : OclAny := null;
    var ans : OclAny := null;
    Sequence{res,ans} := Sequence{false,Sequence{}} ;
    var vis : OclAny := Set{} ;
    for i : Integer.subrange(0, N-1) do (    for j : Integer.subrange(0, i-1) do (    var v : OclAny := nums[i+1] + nums[j+1] ;
    if (vis)->includes(v) then  (
      var ii : OclAny := null;
    var jj : OclAny := null;
    Sequence{ii,jj} := vis[v+1] ;
    var can : Sequence := Sequence{i + 1}->union(Sequence{j + 1}->union(Sequence{ii + 1}->union(Sequence{ jj + 1 }))) ;
    if (Set{}->union((can)))->size() = 4 then (
      var ans : Sequence := can ;
    var res : boolean := true ;
    return res, ans
    ) else skip
    )
    else (
      vis[v+1] := Sequence{i, j}
      ))) ;
    return false, Sequence{};
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import bisect
S=[]
def insert(S,count,x):
    y=bisect.bisect(S,x)
    if y-1<0 or S[y-1]!=x :
        S.insert(y,x)
        count+=1
    print(count)
    return S,count
def find(S,x):
    y=bisect.bisect(S,x)
    if y-1>=0 and S[y-1]==x :
        print(1)
    else :
        print(0)
q=int(input())
count=0
for i in range(q):
    query=list(map(int,input().split()))
    if query[0]==0 :
        S,count=insert(S,count,query[1])
    else :
        find(S,query[1])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var S : Sequence := Sequence{} ;
    skip ;
    skip ;
    var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    count := 0 ;
    for i : Integer.subrange(0, q-1) do (    var query : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if query->first() = 0 then  (
      Sequence{S,count} := insert(S, count, query[1+1])
    )
    else (
      find(S, query[1+1])
      ));
  operation insert(S : OclAny, count : OclAny, x : OclAny) : OclAny
  pre: true post: true
  activity:
    var y : OclAny := bisect.bisect(S, x) ;
    if y - 1 < 0 or S[y - 1+1] /= x then (
      S := S.insertAt(y+1, x) ;
    count := count + 1
    ) else skip ;
    execute (count)->display() ;
    return S, count;
  operation find(S : OclAny, x : OclAny)
  pre: true post: true
  activity:
    y := bisect.bisect(S, x) ;
    if y - 1 >= 0 & S[y - 1+1] = x then  (
      execute (1)->display()
    )
    else (
      execute (0)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def solve():
    from sys import stdin
    f_i=stdin
    q=int(f_i.readline())
    d={}
    ans=[]
    cnt=0
    for i in range(q):
        op,x=map(int,f_i.readline().split())
        if op==0 :
            if d.setdefault(x,'0')=='0' :
                d[x]='1'
                cnt+=1
            ans.append(str(cnt))
        else :
            ans.append(d.setdefault(x,'0'))
    print('\n'.join(ans))
solve()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    solve();
  operation solve()
  pre: true post: true
  activity:
    skip ;
    var f_i : OclAny := stdin ;
    var q : int := ("" + ((f_i.readLine())))->toInteger() ;
    var d : OclAny := Set{} ;
    var ans : Sequence := Sequence{} ;
    var cnt : int := 0 ;
    for i : Integer.subrange(0, q-1) do (    var op : OclAny := null;
    var x : OclAny := null;
    Sequence{op,x} := (f_i.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if op = 0 then  (
      if d.setdefault(x, '0') = '0' then (
      d[x+1] := '1' ;
    cnt := cnt + 1
    ) else skip ;
    execute ((("" + ((cnt)))) : ans)
    )
    else (
      execute ((d.setdefault(x, '0')) : ans)
      )) ;
    execute (StringLib.sumStringsWithSeparator((ans), '
'))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
S=set()
for _ in[0]*int(input()):
    q,x=input().split()
    if q=="0" : S.add(x); print(len(S))
    else : print(1 if x in S else 0)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var S : Set := Set{}->union(()) ;
    for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do (    var q : OclAny := null;
    var x : OclAny := null;
    Sequence{q,x} := input().split() ;
    if q = "0" then  (
      execute ((x) : S);    execute ((S)->size())->display()
    )
    else (
      execute (if (S)->includes(x) then 1 else 0 endif)->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
import collections
def main():
    tl={}
    for i in range(int(input())):
        l=list(map(int,input().split()))
        if l[0]==0 :
            tl[l[1]]=1
            print(len(tl))
        else :
            c=1 if l[1]in tl else 0
            print(c)
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var tl : OclAny := Set{} ;
    for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if l->first() = 0 then  (
      tl[l[1+1]+1] := 1 ;
    execute ((tl)->size())->display()
    )
    else (
      var c : int := if (tl)->includes(l[1+1]) then 1 else 0 endif ;
    execute (c)->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import ceil
n=int(input())
def solve(a,k):
    if atoInteger() ;
    skip ;
    var ans : int := 0 ;
    for _anon : Integer.subrange(0, n-1) do (    Sequence{a,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    ans := ans xor solve(a, k)) ;
    if ans = 0 then  (
      execute ("Aoki")->display()
    )
    else (
      execute ("Takahashi")->display()
      );
  operation solve(a : OclAny, k : OclAny) : OclAny
  pre: true post: true
  activity:
    if (a->compareTo(k)) < 0 then (
      return 0
    ) else skip ;
    while a mod k /= 0 do (    a := a - ceil((a mod k) / ((a div k) + 1)) * ((a div k) + 1)) ;
    return a div k;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from cmath import sqrt
from collections import defaultdict
from math import*
import sys
from typing import Counter
input=sys.stdin.readline
for _ in range(int(input())):
    n,m,k=map(int,input().split())
    print(min(max(k-((k+m-n)//2),0),k+1))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : OclAny := null;
    var m : OclAny := null;
    var k : OclAny := null;
    Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (Set{Set{k - ((k + m - n) div 2), 0}->max(), k + 1}->min())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import defaultdict,deque,Counter
from heapq import heappush,heappop,heapify
import math
import bisect
import random
from itertools import permutations,accumulate,combinations,product
import sys
import string
from bisect import bisect_left,bisect_right
from math import factorial,ceil,floor
from operator import mul
from functools import reduce
sys.setrecursionlimit(2147483647)
INF=10**13
def LI(): return list(map(int,sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return[I()for i in range(n)]
def LIR(n): return[LI()for i in range(n)]
def SR(n): return[S()for i in range(n)]
def LSR(n): return[LS()for i in range(n)]
def SRL(n): return[list(S())for i in range(n)]
def MSRL(n): return[[int(j)for j in list(S())]for i in range(n)]
mod=10**9+7
def solve(n,k):
    if n % k==0 :
        return n//k
    diff=(n//k)+1
    target=n-n % k
    r=n % k
    if r % diff==0 :
        return solve(n-r,k)
    n-=(r//diff+1)*diff
    return solve(n,k)
n=I()
ret=0
for i in range(n):
    a,k=LI()
    ret ^=solve(a,k)
print("Takahashi" if ret else "Aoki")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    sys.setrecursionlimit(2147483647) ;
    var INF : double := (10)->pow(13) ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var mod : double := (10)->pow(9) + 7 ;
    skip ;
    n := I() ;
    var ret : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    var a : OclAny := null;
    Sequence{a,k} := LI() ;
    ret := ret xor solve(a, k)) ;
    execute (if ret then "Takahashi" else "Aoki" endif)->display();
  operation LI() : OclAny
  pre: true post: true
  activity:
    return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ));
  operation I() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation LS() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.buffer.readLine().rstrip().decode('utf-8').split();
  operation S() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.buffer.readLine().rstrip().decode('utf-8');
  operation IR(n : OclAny) : OclAny
  pre: true post: true
  activity:
    return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I()));
  operation LIR(n : OclAny) : OclAny
  pre: true post: true
  activity:
    return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI()));
  operation SR(n : OclAny) : OclAny
  pre: true post: true
  activity:
    return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S()));
  operation LSR(n : OclAny) : OclAny
  pre: true post: true
  activity:
    return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS()));
  operation SRL(n : OclAny) : OclAny
  pre: true post: true
  activity:
    return Integer.subrange(0, n-1)->select(i | true)->collect(i | ((S())));
  operation MSRL(n : OclAny) : OclAny
  pre: true post: true
  activity:
    return Integer.subrange(0, n-1)->select(i | true)->collect(i | ((S())->select(j | true)->collect(j | (("" + ((j)))->toInteger()))));
  operation solve(n : OclAny, k : OclAny) : OclAny
  pre: true post: true
  activity:
    if n mod k = 0 then (
      return n div k
    ) else skip ;
    var diff : int := (n div k) + 1 ;
    var target : double := n - n mod k ;
    var r : int := n mod k ;
    if r mod diff = 0 then (
      return solve(n - r, k)
    ) else skip ;
    n := n - (r div diff + 1) * diff ;
    return solve(n, k);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines
import numpy as np
N=int(readline())
AK=np.array(read().split(),np.int32)
A=AK[: : 2]; K=AK[1 : : 2]
G=0
for t in range(50000):
    q=A//K ; r=A % K
    q+=1
    r+=(-r)% q
    A-=r
    if t % 1000==0 :
        ind=r!=0
        if np.count_nonzero(~ ind):
            G ^=np.bitwise_xor.reduce(A[~ ind]//K[~ ind])
            A=A[ind]; K=K[ind]
            if len(A)==0 :
                break
answer='Takahashi' if G else 'Aoki'
print(answer)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var read : OclAny := sys.stdin.buffer.read ;
    var readline : OclAny := sys.stdin.buffer.readline ;
    var readlines : OclAny := sys.stdin.buffer.readlines ;
    skip ;
    var N : int := ("" + ((readline())))->toInteger() ;
    var AK : Sequence := (read().split(), ) ;
    var A : OclAny := AK(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))));    var K : OclAny := AK(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ;
    var G : int := 0 ;
    for t : Integer.subrange(0, 50000-1) do (    var q : int := A div K;    var r : int := A mod K ;
    q := q + 1 ;
    r := r + (-r) mod q ;
    A := A - r ;
    if t mod 1000 = 0 then (
      var ind : boolean := r /= 0 ;
    if  then (
      G := G xor np.bitwise_xor.reduce(A[MathLib.bitwiseNot(ind)+1] div K[MathLib.bitwiseNot(ind)+1]) ;
    A := A[ind+1];    K := K[ind+1] ;
    if (A)->size() = 0 then (
      break
    ) else skip
    ) else skip
    ) else skip) ;
    var answer : String := if G then 'Takahashi' else 'Aoki' endif ;
    execute (answer)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
sys.setrecursionlimit(10**6)
int1=lambda x : int(x)-1
p2D=lambda x : print(*x,sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int,sys.stdin.readline().split())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LLI(rows_number): return[LI()for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]
def grundy(a,k):
    while 1 :
        if apow(6)) ;
    var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ;
    var p2D : Function := lambda x : OclAny in (((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var win : int := 0 ;
    for _anon : Integer.subrange(0, II()-1) do (    Sequence{a,k} := MI() ;
    win := win xor grundy(a, k)) ;
    if win then  (
      execute ("Takahashi")->display()
    )
    else (
      execute ("Aoki")->display()
      );
  operation II() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation MI() : OclAny
  pre: true post: true
  activity:
    return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) );
  operation LI() : OclAny
  pre: true post: true
  activity:
    return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ));
  operation LLI(rows_number : OclAny) : OclAny
  pre: true post: true
  activity:
    return Integer.subrange(0, rows_number-1)->select(_anon | true)->collect(_anon | (LI()));
  operation SI() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine()->front();
  operation grundy(a : OclAny, k : OclAny) : OclAny
  pre: true post: true
  activity:
    while 1 do (    if (a->compareTo(k)) < 0 then (
      return 0
    ) else skip ;
    if a mod k = 0 then (
      return a div k
    ) else skip ;
    var once : int := a div k + 1 ;
    var seg : int := a mod k ;
    var cnt : int := (seg + once - 1) div once ;
    a := a - cnt * once);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
N=int(input())
AK=[list(map(int,input().split()))for _ in range(N)]
def grundy(A,K):
    if K==1 :
        return A
    X=(A+K-1)//K
    num=X*K-A
    while X*K-num>K*K :
        if num % K==0 :
            return X-num//K
        if num//K==X//K :
            num=num % K
        else :
            num=X % K+1+(K-1)*(num//K)+(num % K-1)
        X=X-X//K
    S=X*K-num
    while S>=K :
        if S % K==0 :
            return S//K
        delta=S//K+1
        S-=max(((S % K)//delta)*delta,delta)
    return 0
g=0
for A,K in AK :
    g ^=grundy(A,K)
print("Takahashi" if g else "Aoki")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var AK : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    skip ;
    var g : int := 0 ;
    for _tuple : AK do (var _indx : int := 1;
      var A : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var K : OclAny := _tuple->at(_indx);
      g := g xor grundy(A, K)) ;
    execute (if g then "Takahashi" else "Aoki" endif)->display();
  operation grundy(A : OclAny, K : OclAny) : OclAny
  pre: true post: true
  activity:
    if K = 1 then (
      return A
    ) else skip ;
    var X : int := (A + K - 1) div K ;
    var num : double := X * K - A ;
    while (X * K - num->compareTo(K * K)) > 0 do (    if num mod K = 0 then (
      return X - num div K
    ) else skip ;
    if num div K = X div K then  (
      num := num mod K
    )
    else (
      num := X mod K + 1 + (K - 1) * (num div K) + (num mod K - 1)
      ) ;
    X := X - X div K) ;
    var S : double := X * K - num ;
    while (S->compareTo(K)) >= 0 do (    if S mod K = 0 then (
      return S div K
    ) else skip ;
    var delta : int := S div K + 1 ;
    S := S - Set{((S mod K) div delta) * delta, delta}->max()) ;
    return 0;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
sys.stdin.readline()
l=list(map(int,sys.stdin.readline().split()))
cand={}
for i,v1 in enumerate(l):
    for j in range(i):
        s=v1+l[j]
        if s in cand :
            if i not in cand[s]and j not in cand[s]:
                print('YES')
                print(i+1,j+1,cand[s][0]+1,cand[s][1]+1)
                exit(0)
        else :
            cand[s]=(i,j)
print('NO')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
(expr (atom (name sys)) (trailer . (name stdin)) (trailer . (name readline) (arguments ( )))) ;
    var l : Sequence := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var cand : OclAny := Set{} ;
    for _tuple : Integer.subrange(1, (l)->size())->collect( _indx | Sequence{_indx-1, (l)->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var v1 : OclAny := _tuple->at(_indx);
      for j : Integer.subrange(0, i-1) do (    var s : OclAny := v1 + l[j+1] ;
    if (cand)->includes(s) then  (
      if (cand[s+1])->excludes(i) & (cand[s+1])->excludes(j) then (
      execute ('YES')->display() ;
    execute (i + 1)->display() ;
    exit(0)
    ) else skip
    )
    else (
      cand[s+1] := Sequence{i, j}
      ))) ;
    execute ('NO')->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def maxProduct(arr,n):
    minVal=arr[0]
    maxVal=arr[0]
    maxProduct=arr[0]
    for i in range(1,n,1):
        if(arr[i]<0):
            temp=maxVal
            maxVal=minVal
            minVal=temp
        maxVal=max(arr[i],maxVal*arr[i])
        minVal=min(arr[i],minVal*arr[i])
        maxProduct=max(maxProduct,maxVal)
    return maxProduct
if __name__=='__main__' :
    arr=[-1,-3,-10,0,60]
    n=len(arr)
    print("Maximum Subarray product is",maxProduct(arr,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      arr := Sequence{-1}->union(Sequence{-3}->union(Sequence{-10}->union(Sequence{0}->union(Sequence{ 60 })))) ;
    n := (arr)->size() ;
    execute ("Maximum Subarray product is")->display()
    ) else skip;
  operation maxProduct(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var minVal : OclAny := arr->first() ;
    var maxVal : OclAny := arr->first() ;
    var maxProduct : OclAny := arr->first() ;
    for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 1 = 0 ) do (    if (arr[i+1] < 0) then (
      var temp : OclAny := maxVal ;
    maxVal := minVal ;
    minVal := temp
    ) else skip ;
    maxVal := Set{arr[i+1], maxVal * arr[i+1]}->max() ;
    minVal := Set{arr[i+1], minVal * arr[i+1]}->min() ;
    maxProduct := Set{maxProduct, maxVal}->max()) ;
    return maxProduct;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def CommomSubsequencesCount(s,t):
    n1=len(s)
    n2=len(t)
    dp=[[0 for i in range(n2+1)]for i in range(n1+1)]
    for i in range(1,n1+1):
        for j in range(1,n2+1):
            if(s[i-1]==t[j-1]):
                dp[i][j]=(1+dp[i][j-1]+dp[i-1][j])
            else :
                dp[i][j]=(dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1])
    return dp[n1][n2]
s="ajblqcpdz"
t="aefcnbtdi"
print(CommomSubsequencesCount(s,t))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    s := "ajblqcpdz" ;
    t := "aefcnbtdi" ;
    execute (CommomSubsequencesCount(s, t))->display();
  operation CommomSubsequencesCount(s : OclAny, t : OclAny) : OclAny
  pre: true post: true
  activity:
    var n1 : int := (s)->size() ;
    var n2 : int := (t)->size() ;
    var dp : Sequence := Integer.subrange(0, n1 + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, n2 + 1-1)->select(i | true)->collect(i | (0)))) ;
    for i : Integer.subrange(1, n1 + 1-1) do (    for j : Integer.subrange(1, n2 + 1-1) do (    if (s[i - 1+1] = t[j - 1+1]) then  (
      dp[i+1][j+1] := (1 + dp[i+1][j - 1+1] + dp[i - 1+1][j+1])
    )
    else (
      dp[i+1][j+1] := (dp[i+1][j - 1+1] + dp[i - 1+1][j+1] - dp[i - 1+1][j - 1+1])
      ))) ;
    return dp[n1+1][n2+1];
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def findSum(n):
    arr=[[0 for x in range(n)]for y in range(n)]
    for i in range(n):
        for j in range(n):
            arr[i][j]=abs(i-j)
    sum=0
    for i in range(n):
        for j in range(n):
            sum+=arr[i][j]
    return sum
if __name__=="__main__" :
    n=3
    print(findSum(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      n := 3 ;
    execute (findSum(n))->display()
    ) else skip;
  operation findSum(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var arr : Sequence := Integer.subrange(0, n-1)->select(y | true)->collect(y | (Integer.subrange(0, n-1)->select(x | true)->collect(x | (0)))) ;
    for i : Integer.subrange(0, n-1) do (    for j : Integer.subrange(0, n-1) do (    arr[i+1][j+1] := (i - j)->abs())) ;
    var sum : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    for j : Integer.subrange(0, n-1) do (    sum := sum + arr[i+1][j+1])) ;
    return sum;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def dodecahedral_num(n):
    return n*(3*n-1)*(3*n-2)//2
n=5
print("%sth Dodecahedral number :" % n,dodecahedral_num(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    n := 5 ;
    execute (StringLib.format("%sth Dodecahedral number :",n))->display();
  operation dodecahedral_num(n : OclAny) : OclAny
  pre: true post: true
  activity:
    return n * (3 * n - 1) * (3 * n - 2) div 2;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def find_idx(ar,n):
    answer=[];
    sum=ar[0];
    for i in range(1,n):
        if(sum==ar[i]):
            answer.append(i+1);
        sum+=ar[i];
    return answer ;
if __name__=="__main__" :
    ar=[1,2,3,6,3,15,5];
    n=len(ar);
    ans=find_idx(ar,n);
    if(len(ans)!=0):
        for i in ans :
            print(i,end=" ");
    else :
        print("-1");
    print();
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      ar := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{6}->union(Sequence{3}->union(Sequence{15}->union(Sequence{ 5 })))))); ;
    n := (ar)->size(); ;
    var ans : OclAny := find_idx(ar, n); ;
    if ((ans)->size() /= 0) then  (
      for i : ans do (    execute (i)->display();)
    )
    else (
      execute ("-1")->display();
      ) ;
    execute (->display();
    ) else skip;
  operation find_idx(ar : OclAny, n : OclAny)
  pre: true post: true
  activity:
    var answer : Sequence := Sequence{}; ;
    var sum : OclAny := ar->first(); ;
    for i : Integer.subrange(1, n-1) do (    if (sum = ar[i+1]) then (
      execute ((i + 1) : answer);
    ) else skip ;
    sum := sum + ar[i+1];) ;
    return answer;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def solve(N,M,cp,sp):
    profit=[]
    for i in range(N):
        profit.append(sp[i]-cp[i])
    profit.sort(reverse=True)
    sum=0
    for i in range(M):
        if profit[i]>0 :
            sum+=profit[i]
        else :
            break
    return sum
if __name__=="__main__" :
    N,M=5,3
    CP=[5,10,35,7,23]
    SP=[11,10,0,9,19]
    print(solve(N,M,CP,SP))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      Sequence{N,M} := Sequence{5,3} ;
    var CP : Sequence := Sequence{5}->union(Sequence{10}->union(Sequence{35}->union(Sequence{7}->union(Sequence{ 23 })))) ;
    var SP : Sequence := Sequence{11}->union(Sequence{10}->union(Sequence{0}->union(Sequence{9}->union(Sequence{ 19 })))) ;
    execute (solve(N, M, CP, SP))->display()
    ) else skip;
  operation solve(N : OclAny, M : OclAny, cp : OclAny, sp : OclAny) : OclAny
  pre: true post: true
  activity:
    var profit : Sequence := Sequence{} ;
    for i : Integer.subrange(0, N-1) do (    execute ((sp[i+1] - cp[i+1]) : profit)) ;
    profit := profit->sort() ;
    var sum : int := 0 ;
    for i : Integer.subrange(0, M-1) do (    if profit[i+1] > 0 then  (
      sum := sum + profit[i+1]
    )
    else (
      break
      )) ;
    return sum;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from datetime import*
for e in iter(input,'0 0'): print(date(2004,*map(int,e.split())).strftime('%A'))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    for e : OclIterator.newOclIterator_Sequence(input, '0 0') do (    execute (date(2004, (argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name e)) (trailer . (name split) (arguments ( ))))))))) ))))))))).strftime('%A'))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from heapq import heappop,heappush
def dijkstra(s):
    d=[float("inf")for i in range(n)]
    d[s]=0
    q=[(0,s)]
    while q :
        dx,x=heappop(q)
        for c,y in v[x]:
            if dx+ccollect( _x | (OclType["int"])->apply(_x) ) ;
    if n = m & (m == s) & (s == g1) & (g1 == g2) & (g2 == 0) then (
      break
    ) else skip ;
    s := s - 1 ;
    g1 := g1 - 1 ;
    g2 := g2 - 1 ;
    var v : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ;
    for i : Integer.subrange(0, m-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
(expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name c)))))) , (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1))))))))) )))))))) ))))) ;
    d := Integer.subrange(0, n-1)->select(i | true)->collect(i | (dijkstra(i))) ;
    var ans : OclAny := d[s+1][g1+1] + d[s+1][g2+1] ;
    for i : Integer.subrange(0, n-1) do (    if (d[s+1][i+1] + d[i+1][g1+1] + d[i+1][g2+1]->compareTo(ans)) < 0 then (
      ans := d[s+1][i+1] + d[i+1][g1+1] + d[i+1][g2+1]
    ) else skip) ;
    execute (ans)->display());
  operation dijkstra(s : OclAny) : OclAny
  pre: true post: true
  activity:
    var d : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (("inf")))->toReal())) ;
    d[s+1] := 0 ;
    var q : Sequence := Sequence{ Sequence{0, s} } ;
    while q do (    var dx : OclAny := null;
    var x : OclAny := null;
    Sequence{dx,x} := heappop(q) ;
    for _tuple : v[x+1] do (var _indx : int := 1;
      var c : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var y : OclAny := _tuple->at(_indx);
      if (dx + c->compareTo(d[y+1])) < 0 then (
      d[y+1] := dx + c ;
    heappush(q, Sequence{d[y+1], y})
    ) else skip)) ;
    return d;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for p in[0]*int(input()): s,i,e=map(int,input().split()); print(max(0,min(e+1,s-i+e+1>>1)))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for p : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do (    var s : OclAny := null;
    var i : OclAny := null;
    var e : OclAny := null;
    Sequence{s,i,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) );    execute (Set{0, Set{e + 1, s - i + e + 1 /(2->pow(1))}->min()}->max())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def printPattern(n):
    arr=[[0 for i in range(n)]for j in range(n)]
    p=1
    for k in range(n):
        j=k
        i=0
        while(j>=0):
            arr[i][j]=p
            p+=1
            i=i+1
            j=j-1
    for k in range(1,n,1):
        i=k
        j=n-1
        f=k
        while(j>=f):
            arr[i][j]=p
            p+=1
            i=i+1
            j=j-1
    for i in range(0,n,1):
        for j in range(0,n,1):
            print(arr[i][j],end="")
        print("\n",end="")
if __name__=='__main__' :
    n=3
    printPattern(n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      n := 3 ;
    printPattern(n)
    ) else skip;
  operation printPattern(n : OclAny)
  pre: true post: true
  activity:
    var arr : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)))) ;
    var p : int := 1 ;
    for k : Integer.subrange(0, n-1) do (    var j : OclAny := k ;
    var i : int := 0 ;
    while (j >= 0) do (    arr[i+1][j+1] := p ;
    p := p + 1 ;
    i := i + 1 ;
    j := j - 1)) ;
    for k : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 1 = 0 ) do (    i := k ;
    j := n - 1 ;
    var f : OclAny := k ;
    while ((j->compareTo(f)) >= 0) do (    arr[i+1][j+1] := p ;
    p := p + 1 ;
    i := i + 1 ;
    j := j - 1)) ;
    for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do (    for j : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do (    execute (arr[i+1][j+1])->display()) ;
    execute ("\n")->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a=*map(int,input().split()),
d={}
for i in range(n):
    for j in range(i):
        s=a[i]+a[j]
        if s not in d : d[s]=i,j
        else :
            x=d[s]
            if i not in x and j not in x : print("YES"); print(x[0]+1,x[1]+1,i+1,j+1); exit()
print("NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : OclAny := (testlist_star_expr (star_expr * (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))) ,) ;
    var d : OclAny := Set{} ;
    for i : Integer.subrange(0, n-1) do (    for j : Integer.subrange(0, i-1) do (    var s : OclAny := a[i+1] + a[j+1] ;
    if (d)->excludes(s) then  (
      d[s+1] := i,j
    )
    else (
      var x : OclAny := d[s+1] ;
    if (x)->excludes(i) & (x)->excludes(j) then (
      execute ("YES")->display();    execute (x->first() + 1)->display();    exit()
    ) else skip
      ))) ;
    execute ("NO")->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from bisect import bisect_left,bisect_right,insort_left
dict={}
keytbl=[]
cnt=0
q=int(input())
for i in range(q):
    a=list(input().split())
    ki=int(a[1])
    if a[0]=='0' :
        if ki not in dict :
            dict[ki]=1
            cnt+=1
            insort_left(keytbl,ki)
        elif dict[ki]==0 :
            dict[ki]=1
            cnt+=1
        print(cnt)
    elif a[0]=='1' : print(dict[ki]if ki in dict else 0)
    elif a[0]=='2' :
        if ki in dict :
            cnt-=dict[ki]
            dict[ki]=0
    else :
        L=bisect_left(keytbl,int(a[1]))
        R=bisect_right(keytbl,int(a[2]),L)
        for j in range(L,R):
            if dict[keytbl[j]]==1 : print(keytbl[j])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var OclType["Map"] : OclAny := Set{} ;
    var keytbl : Sequence := Sequence{} ;
    var cnt : int := 0 ;
    var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, q-1) do (    var a : Sequence := (input().split()) ;
    var ki : int := ("" + ((a[1+1])))->toInteger() ;
    if a->first() = '0' then  (
      if (OclType["Map"])->excludes(ki) then  (
      (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ki)))))))) ]) := 1 ;
    cnt := cnt + 1 ;
    insort_left(keytbl, ki)
    )
    else (if (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ki)))))))) ]) = 0 then
   (
      (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ki)))))))) ]) := 1 ;
    cnt := cnt + 1    
)
 else skip) ;
    execute (cnt)->display()
    )
    else (if a->first() = '1' then
   (
      execute (if (OclType["Map"])->includes(ki) then (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ki)))))))) ]) else 0 endif)->display()    
)
    else (if a->first() = '2' then
   (
      if (OclType["Map"])->includes(ki) then (
      cnt := cnt - (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ki)))))))) ]) ;
    (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ki)))))))) ]) := 0
    ) else skip    
)
    else (
      var L : OclAny := bisect_left(keytbl, ("" + ((a[1+1])))->toInteger()) ;
    var R : OclAny := bisect_right(keytbl, ("" + ((a[2+1])))->toInteger(), L) ;
    for j : Integer.subrange(L, R-1) do (    if (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name keytbl)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) ]) = 1 then (
      execute (keytbl[j+1])->display()
    ) else skip)
      )    )
    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from bisect import insort,bisect_right,bisect_left
class IntSet :
    def __init__(self)->None :
        self.total=0
        self.ms : dict=dict()
        self.lr : list=[]
    def insert(self,x : int)->None :
        if x in self.ms :
            if self.ms[x]==0 :
                self.ms[x]=1
                self.total+=1
        else :
            self.total+=1
            self.ms[x]=1
            insort(self.lr,x)
        print(self.total)
    def find(self,x : int)->None :
        print(self.ms.get(x,0))
    def delete(self,x : int)->None :
        if x in self.ms :
            self.total-=self.ms[x]
            self.ms[x]=0
    def dump(self,l : int,r : int)->None :
        lb=bisect_left(self.lr,l)
        ub=bisect_right(self.lr,r)
        for i in range(lb,ub):
            k=self.lr[i]
            v=self.ms[k]
            print(f'{k}\n'*v,end='')
if __name__=="__main__" :
    ms=IntSet()
    num_query=int(input())
    for _ in range(num_query):
        op,*v=map(lambda x : int(x),input().split())
        if 0==op :
            ms.insert(v[0])
        elif 1==op :
            ms.find(v[0])
        elif 2==op :
            ms.delete(v[0])
        else :
            ms.dump(v[0],v[1])
------------------------------------------------------------
OCL File:
---------
class IntSet {
  static operation newIntSet() : IntSet
  pre: true
  post: IntSet->exists( _x | result = _x );
  operation __init__() : OclAny
  pre: true post: true
  activity:
    self.total := 0 ;
    var self.ms : Map := (arguments ( )) ;
    var self.lr : Sequence := Sequence{};
  operation insert(x : int) : OclAny
  pre: true post: true
  activity:
    if (self.ms)->includes(x) then  (
      if self.ms[x+1] = 0 then (
      self.ms[x+1] := 1 ;
    self.total := self.total + 1
    ) else skip
    )
    else (
      self.total := self.total + 1 ;
    self.ms[x+1] := 1 ;
    insort(self.lr, x)
      ) ;
    execute (self.total)->display();
  operation find(x : int) : OclAny
  pre: true post: true
  activity:
    execute (self.ms.get(x, 0))->display();
  operation delete(x : int) : OclAny
  pre: true post: true
  activity:
    if (self.ms)->includes(x) then (
      self.total := self.total - self.ms[x+1] ;
    self.ms[x+1] := 0
    ) else skip;
  operation dump(l : int,r : int) : OclAny
  pre: true post: true
  activity:
    var lb : OclAny := bisect_left(self.lr, l) ;
    var ub : OclAny := bisect_right(self.lr, r) ;
    for i : Integer.subrange(lb, ub-1) do (    var k : OclAny := self.lr[i+1] ;
    var v : OclAny := self.ms[k+1] ;
    execute (StringLib.formattedString('{k}
') * v)->display());
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      var ms : IntSet := (IntSet.newIntSet()).initialise() ;
    var num_query : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, num_query-1) do (    var op : OclAny := null;
    var v : OclAny := null;
    Sequence{op,v} := (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ) ;
    if 0 = op then  (
      ms := ms.insertAt(v->first()+1, v->first())
    )
    else (if 1 = op then
   (
      ms->indexOf(v->first()) - 1    
)
    else (if 2 = op then
   (
      ms.delete(v->first())    
)
    else (
      ms.dump(v->first(), v[1+1])
      )    )
    )
)
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
q=int(input())
S=set()
for i in range(q):
    query=input()
    if query[0]=="0" :
        _,x=list(map(int,query.split()))
        S.add(x)
        print(len(S))
    elif query[0]=="1" :
        _,x=list(map(int,query.split()))
        if x in S :
            print(1)
        else :
            print(0)
    elif query[0]=="2" :
        _,x=list(map(int,query.split()))
        S.discard(x)
    else :
        _,L,R=list(map(int,query.split()))
        if len(S)>(R-L):
            for i in range(L,R+1):
                if i in S :
                    print(i)
        else :
            answer=[]
            for SItem in S :
                if L<=SItem<=R :
                    answer.append(SItem)
[print(answerItem)for answerItem in sorted(answer)]
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var S : Set := Set{}->union(()) ;
    for i : Integer.subrange(0, q-1) do (    var query : String := (OclFile["System.in"]).readLine() ;
    if query->first() = "0" then  (
      var _anon : OclAny := null;
    var x : OclAny := null;
    Sequence{_anon,x} := ((query.split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute ((x) : S) ;
    execute ((S)->size())->display()
    )
    else (if query->first() = "1" then
   (
      var _anon : OclAny := null;
    var x : OclAny := null;
    Sequence{_anon,x} := ((query.split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if (S)->includes(x) then  (
      execute (1)->display()
    )
    else (
      execute (0)->display()
      )    
)
    else (if query->first() = "2" then
   (
      var _anon : OclAny := null;
    var x : OclAny := null;
    Sequence{_anon,x} := ((query.split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute ((x) /: S)    
)
    else (
      var _anon : OclAny := null;
    var L : OclAny := null;
    var R : OclAny := null;
    Sequence{_anon,L,R} := ((query.split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if ((S)->size()->compareTo((R - L))) > 0 then  (
      for i : Integer.subrange(L, R + 1-1) do (    if (S)->includes(i) then (
      execute (i)->display()
    ) else skip)
    )
    else (
      var answer : Sequence := Sequence{} ;
    for SItem : S do (    if (L->compareTo(SItem)) <= 0 & (SItem <= R) then (
      execute ((SItem) : answer)
    ) else skip)
      )
      )    )
    )
) ;
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
q=int(input())
s=[]
rs=[]
for i in range(q):
    s.append(list(map(int,input().split())))
    if s[i][0]==3 :
        rs.append(s[i][1])
        rs.append(s[i][2])
    else :
        rs.append(s[i][1])
rs.append(10**9+1)
rs=sorted(list(set(rs)))
index={rs[i]: i for i in range(len(rs))}
used=[False for i in range(len(rs)+1)]
cnt=0
for i in range(q):
    op,x=s[i][0],s[i][1]
    idx=index[x]
    if op==0 :
        if not used[idx]:
            cnt+=1
        used[idx]=True
        print(cnt)
    elif op==1 :
        print(+used[idx])
    elif op==2 :
        if used[idx]:
            cnt-=1
        used[idx]=False
    else :
        l=idx
        r=index[s[i][2]]
        for j in range(l,r+1):
            if used[j]:
                print(rs[j])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : Sequence := Sequence{} ;
    var rs : Sequence := Sequence{} ;
    for i : Integer.subrange(0, q-1) do (    execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : s) ;
    if s[i+1]->first() = 3 then  (
      execute ((s[i+1][1+1]) : rs) ;
    execute ((s[i+1][2+1]) : rs)
    )
    else (
      execute ((s[i+1][1+1]) : rs)
      )) ;
    execute (((10)->pow(9) + 1) : rs) ;
    rs := (Set{}->union((rs)))->sort() ;
    var index : Map := Integer.subrange(0, (rs)->size()-1)->select(i | true)->collect(i | Map{rs[i+1] |-> i})->unionAll() ;
    var used : Sequence := Integer.subrange(0, (rs)->size() + 1-1)->select(i | true)->collect(i | (false)) ;
    var cnt : int := 0 ;
    for i : Integer.subrange(0, q-1) do (    var op : OclAny := null;
    var x : OclAny := null;
    Sequence{op,x} := Sequence{s[i+1]->first(),s[i+1][1+1]} ;
    var idx : OclAny := index[x+1] ;
    if op = 0 then  (
      if not(used[idx+1]) then (
      cnt := cnt + 1
    ) else skip ;
    used[idx+1] := true ;
    execute (cnt)->display()
    )
    else (if op = 1 then
   (
      execute (used[idx+1])->display()    
)
    else (if op = 2 then
   (
      if used[idx+1] then (
      cnt := cnt - 1
    ) else skip ;
    used[idx+1] := false    
)
    else (
      var l : OclAny := idx ;
    var r : OclAny := index[s[i+1][2+1]+1] ;
    for j : Integer.subrange(l, r + 1-1) do (    if used[j+1] then (
      execute (rs[j+1])->display()
    ) else skip)
      )    )
    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
s=set()
input()
for q in sys.stdin :
    q=q.split()
    if q[0]=='0' :
        s.add(int(q[1]))
        print(len(s))
    elif q[0]=='1' :
        print(int(int(q[1])in s))
    elif q[0]=='2' :
        s.discard(int(q[1]))
    else :
        ans=[]
        if len(s)>int(q[2])-int(q[1]):
            for i in range(int(q[1]),int(q[2])+1):
                if i in s :
                    print(i)
        else :
            for i in s :
                if int(q[1])<=i<=int(q[2]):
                    ans.append(i)
            for i in sorted(ans):
                print(i)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var s : Set := Set{}->union(()) ;
    input() ;
    for q : OclFile["System.in"] do (    var q : OclAny := q.split() ;
    if q->first() = '0' then  (
      execute ((("" + ((q[1+1])))->toInteger()) : s) ;
    execute ((s)->size())->display()
    )
    else (if q->first() = '1' then
   (
      execute (("" + (((s)->includes(("" + ((q[1+1])))->toInteger()))))->toInteger())->display()    
)
    else (if q->first() = '2' then
   (
      execute ((("" + ((q[1+1])))->toInteger()) /: s)    
)
    else (
      var ans : Sequence := Sequence{} ;
    if ((s)->size()->compareTo(("" + ((q[2+1])))->toInteger() - ("" + ((q[1+1])))->toInteger())) > 0 then  (
      for i : Integer.subrange(("" + ((q[1+1])))->toInteger(), ("" + ((q[2+1])))->toInteger() + 1-1) do (    if (s)->includes(i) then (
      execute (i)->display()
    ) else skip)
    )
    else (
      for i : s do (    if (("" + ((q[1+1])))->toInteger()->compareTo(i)) <= 0 & (i <= ("" + ((q[2+1])))->toInteger()) then (
      execute ((i) : ans)
    ) else skip) ;
    for i : ans->sort() do (    execute (i)->display())
      )
      )    )
    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    N,M=map(int,input().split())
    if N==0 : break
    mi,ma=[0]*N,[0]*N
    for i in range(M):
        a=list(map(int,input().split()))
        S=a.pop(0)
        K=a.pop(0)
        if K==1 :
            mi[a[0]-1]+=S
            ma[a[0]-1]+=S
        else :
            for j in a : ma[j-1]+=S
    vmax=max(ma)
    mi.pop(ma.index(vmax))
    vmin=min(mi)
    print(vmax-vmin+1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if N = 0 then (
      break
    ) else skip ;
    var mi : OclAny := null;
    var ma : OclAny := null;
    Sequence{mi,ma} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, N),MatrixLib.elementwiseMult(Sequence{ 0 }, N)} ;
    for i : Integer.subrange(0, M-1) do (    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var S : OclAny := a->at(0`firstArg+1) ;     a := a->excludingAt(0+1) ;
    var K : OclAny := a->at(0`firstArg+1) ;     a := a->excludingAt(0+1) ;
    if K = 1 then  (
      mi[a->first() - 1+1] := mi[a->first() - 1+1] + S ;
    ma[a->first() - 1+1] := ma[a->first() - 1+1] + S
    )
    else (
      for j : a do (    ma[j - 1+1] := ma[j - 1+1] + S)
      )) ;
    var vmax : OclAny := (ma)->max() ;
    mi := mi->excludingAt(ma->indexOf(vmax) - 1+1) ;
    var vmin : OclAny := (mi)->min() ;
    execute (vmax - vmin + 1)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def solve(n,m,s,k,c):
    maxvs=[0]*(n+1)
    minvs=[0]*(n+1)
    for i in enumerate(c):
        for j in i[1]:
            maxvs[j]+=s[i[0]]
            if k[i[0]]==1 :
                minvs[j]+=s[i[0]]
    ans=-1
    for i in range(1,n+1):
        ans=max(ans,maxvs[i]-min(minvs[1 : i]+minvs[i+1 :]))
    print(ans+1)
while True :
    N,M=map(int,input().split())
    if N==M==0 :
        break
    S=[]
    K=[]
    C=[]
    for i in range(M):
        Skc=list(map(int,input().split()))
        S.append(Skc[0])
        K.append(Skc[1])
        C.append(Skc[2 :])
    solve(N,M,S,K,C)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    while true do (    var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if N = M & (M == 0) then (
      break
    ) else skip ;
    var S : Sequence := Sequence{} ;
    var K : Sequence := Sequence{} ;
    var C : Sequence := Sequence{} ;
    for i : Integer.subrange(0, M-1) do (    var Skc : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute ((Skc->first()) : S) ;
    execute ((Skc[1+1]) : K) ;
    execute ((Skc.subrange(2+1)) : C)) ;
    solve(N, M, S, K, C));
  operation solve(n : OclAny, m : OclAny, s : OclAny, k : OclAny, c : OclAny)
  pre: true post: true
  activity:
    var maxvs : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ;
    var minvs : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ;
    for i : Integer.subrange(1, (c)->size())->collect( _indx | Sequence{_indx-1, (c)->at(_indx)} ) do (    for j : i[1+1] do (    maxvs[j+1] := maxvs[j+1] + s[i->first()+1] ;
    if k[i->first()+1] = 1 then (
      minvs[j+1] := minvs[j+1] + s[i->first()+1]
    ) else skip)) ;
    var ans : int := -1 ;
    for i : Integer.subrange(1, n + 1-1) do (    ans := Set{ans, maxvs[i+1] - (minvs.subrange(1+1, i) + minvs.subrange(i + 1+1))->min()}->max()) ;
    execute (ans + 1)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF=float('inf')
mod=10**9+7
eps=10**-7
def inp(): return int(input())
def inpl(): return list(map(int,input().split()))
def inpl_str(): return list(input().split())
while True :
    N,M=inpl()
    if N==0 and M==0 :
        break
    else :
        MINlist=[[0,i]for i in range(N)]
        MAXlist=[[0,i]for i in range(N)]
        for _ in range(M):
            arg=inpl()
            s=arg[0]
            k=arg[1]
            cc=arg[2 :]
            for c in cc :
                MAXlist[c-1][0]+=s
            if k==1 :
                MINlist[c-1][0]+=s
        MINlist.sort()
        MAXlist.sort(reverse=True)
        MinVal1,MinId1=MINlist[0]
        MinVal2,MinId2=MINlist[1]
        MaxVal1,MaxId1=MAXlist[0]
        MaxVal2,MaxId2=MAXlist[1]
        if MinId1!=MaxId1 :
            print(MaxVal1-MinVal1+1)
        else :
            print(max(MaxVal2-MinVal1,MaxVal1-MinVal2)+1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    sys.setrecursionlimit((10)->pow(8)) ;
    var INF : double := ("" + (('inf')))->toReal() ;
    var mod : double := (10)->pow(9) + 7 ;
    var eps : double := (10)->pow(-7) ;
    skip ;
    skip ;
    skip ;
    while true do (    var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := inpl() ;
    if N = 0 & M = 0 then  (
      break
    )
    else (
      var MINlist : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{0}->union(Sequence{ i }))) ;
    var MAXlist : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{0}->union(Sequence{ i }))) ;
    for _anon : Integer.subrange(0, M-1) do (    var arg : OclAny := inpl() ;
    var s : OclAny := arg->first() ;
    var k : OclAny := arg[1+1] ;
    var cc : OclAny := arg.subrange(2+1) ;
    for c : cc do (    MAXlist[c - 1+1]->first() := MAXlist[c - 1+1]->first() + s) ;
    if k = 1 then (
      MINlist[c - 1+1]->first() := MINlist[c - 1+1]->first() + s
    ) else skip) ;
    MINlist := MINlist->sort() ;
    MAXlist := MAXlist->sort() ;
    var MinVal1 : OclAny := null;
    var MinId1 : OclAny := null;
    Sequence{MinVal1,MinId1} := MINlist->first() ;
    var MinVal2 : OclAny := null;
    var MinId2 : OclAny := null;
    Sequence{MinVal2,MinId2} := MINlist[1+1] ;
    var MaxVal1 : OclAny := null;
    var MaxId1 : OclAny := null;
    Sequence{MaxVal1,MaxId1} := MAXlist->first() ;
    var MaxVal2 : OclAny := null;
    var MaxId2 : OclAny := null;
    Sequence{MaxVal2,MaxId2} := MAXlist[1+1] ;
    if MinId1 /= MaxId1 then  (
      execute (MaxVal1 - MinVal1 + 1)->display()
    )
    else (
      execute (Set{MaxVal2 - MinVal1, MaxVal1 - MinVal2}->max() + 1)->display()
      )
      ));
  operation inp() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation inpl() : OclAny
  pre: true post: true
  activity:
    return ((input().split())->collect( _x | (OclType["int"])->apply(_x) ));
  operation inpl_str() : OclAny
  pre: true post: true
  activity:
    return (input().split());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    while(True):
        N,M=map(int,input().split())
        if(N==0 and M==0):
            return
        skc=[]
        for i in range(M):
            skc.append(list(map(int,input().split())))
        point=[0 for i in range(N)]
        for i in range(M):
            for j in range(2,len(skc[i])):
                point[skc[i][j]-1]+=skc[i][0]
        point_fixed=[0 for i in range(N)]
        for i in range(M):
            if(skc[i][1]==1):
                point_fixed[skc[i][2]-1]+=skc[i][0]
        maxPlayer=0
        Max=0
        for i in range(N):
            if(Maxpoint_fixed[i]):
                Min=point_fixed[i]
                minPlayer=i+1
        print(point[maxPlayer-1]-point_fixed[minPlayer-1]+1)
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    while (true) do (    var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if (N = 0 & M = 0) then (
      return
    ) else skip ;
    var skc : Sequence := Sequence{} ;
    for i : Integer.subrange(0, M-1) do (    execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : skc)) ;
    var point : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ;
    for i : Integer.subrange(0, M-1) do (    for j : Integer.subrange(2, (skc[i+1])->size()-1) do (    point[skc[i+1][j+1] - 1+1] := point[skc[i+1][j+1] - 1+1] + skc[i+1]->first())) ;
    var point_fixed : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ;
    for i : Integer.subrange(0, M-1) do (    if (skc[i+1][1+1] = 1) then (
      point_fixed[skc[i+1][2+1] - 1+1] := point_fixed[skc[i+1][2+1] - 1+1] + skc[i+1]->first()
    ) else skip) ;
    var maxPlayer : int := 0 ;
    var Max : int := 0 ;
    for i : Integer.subrange(0, N-1) do (    if ((Max->compareTo(point[i+1])) < 0) then (
      Max := point[i+1] ;
    maxPlayer := i + 1
    ) else skip) ;
    var minPlayer : int := 0 ;
    var Min : double := ("1e9")->toReal() ;
    for i : Integer.subrange(0, N-1) do (    if (i + 1 = maxPlayer) then (
      continue
    ) else skip ;
    if ((Min->compareTo(point_fixed[i+1])) > 0) then (
      Min := point_fixed[i+1] ;
    minPlayer := i + 1
    ) else skip) ;
    execute (point[maxPlayer - 1+1] - point_fixed[minPlayer - 1+1] + 1)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
from os import path
if(path.exists('input.txt')):
    sys.stdin=open('input.txt','r')
    sys.stdout=open('output.txt','w')
def solve():
    str,intelligence,exp=map(int,input().split())
    minAddS=max(0,(exp+intelligence-str+2)//2)
    print(max(0,exp-minAddS+1))
q=1
q=int(input())
for i in range(q):
    solve()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if (path.exists('input.txt')) then (
      OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('input.txt')) ;
    OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile('output.txt'))
    ) else skip ;
    skip ;
    var q : int := 1 ;
    q := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, q-1) do (    solve());
  operation solve()
  pre: true post: true
  activity:
    var OclType["String"] : OclAny := null;
    var intelligence : OclAny := null;
    var exp : OclAny := null;
    Sequence{OclType["String"],intelligence,exp} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var minAddS : OclAny := Set{0, (exp + intelligence - OclType["String"] + 2) div 2}->max() ;
    execute (Set{0, exp - minAddS + 1}->max())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
def countUnsetBits(n):
    x=n
    n |=n>>1
    n |=n>>2
    n |=n>>4
    n |=n>>8
    n |=n>>16
    t=math.log(x ^ n,2)
    return math.floor(t)
n=17
print(countUnsetBits(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    n := 17 ;
    execute (countUnsetBits(n))->display();
  operation countUnsetBits(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var x : OclAny := n ;
    n := n or n /(2->pow(1)) ;
    n := n or n /(2->pow(2)) ;
    n := n or n /(2->pow(4)) ;
    n := n or n /(2->pow(8)) ;
    n := n or n /(2->pow(16)) ;
    var t : double := (MathLib.bitwiseXor(x, n), 2)->log() ;
    return (t)->floor();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while 1 :
    N,M=map(int,input().split())
    if N==0 and M==0 :
        break
    I=[list(map(int,input().split()))for _ in range(M)]
    P=[0 for _ in range(N)]
    mP=[0 for _ in range(N)]
    for i in range(M):
        k=I[i][1]
        if k==1 :
            mP[I[i][2]-1]+=I[i][0]
        for j in range(k):
            P[I[i][2+j]-1]+=I[i][0]
    maxp=0
    minp=float("inf")
    for i in range(N):
        if maxpmP[i]:
                minp=mP[i]
    f=0
    for i in range(N):
        if i!=index :
            if mP[i]==0 :
                f=1
    if f :
        print(max(P)+1)
    else :
        print(max(P)+1-minp)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while 1 do (    var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if N = 0 & M = 0 then (
      break
    ) else skip ;
    var I : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var P : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (0)) ;
    var mP : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (0)) ;
    for i : Integer.subrange(0, M-1) do (    var k : OclAny := I[i+1][1+1] ;
    if k = 1 then (
      mP[I[i+1][2+1] - 1+1] := mP[I[i+1][2+1] - 1+1] + I[i+1]->first()
    ) else skip ;
    for j : Integer.subrange(0, k-1) do (    P[I[i+1][2 + j+1] - 1+1] := P[I[i+1][2 + j+1] - 1+1] + I[i+1]->first())) ;
    var maxp : int := 0 ;
    var minp : double := ("" + (("inf")))->toReal() ;
    for i : Integer.subrange(0, N-1) do (    if (maxp->compareTo(P[i+1])) < 0 then (
      maxp := P[i+1] ;
    var index : OclAny := i
    ) else skip) ;
    for i : Integer.subrange(0, N-1) do (    if i /= index then (
      if (minp->compareTo(mP[i+1])) > 0 then (
      minp := mP[i+1]
    ) else skip
    ) else skip) ;
    var f : int := 0 ;
    for i : Integer.subrange(0, N-1) do (    if i /= index then (
      if mP[i+1] = 0 then (
      f := 1
    ) else skip
    ) else skip) ;
    if f then  (
      execute ((P)->max() + 1)->display()
    )
    else (
      execute ((P)->max() + 1 - minp)->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def spiralDiaSum(n):
    if n==1 :
        return 1
    return(4*n*n-6*n+6+spiralDiaSum(n-2))
n=7 ;
print(spiralDiaSum(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    n := 7; ;
    execute (spiralDiaSum(n))->display();
  operation spiralDiaSum(n : OclAny) : OclAny
  pre: true post: true
  activity:
    if n = 1 then (
      return 1
    ) else skip ;
    return (4 * n * n - 6 * n + 6 + spiralDiaSum(n - 2));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def sumofseries(n):
    res=0
    for i in range(1,n+1):
        res+=(i)*(i+1)*(i+2)
    return res
print(sumofseries(3))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    execute (sumofseries(3))->display();
  operation sumofseries(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var res : int := 0 ;
    for i : Integer.subrange(1, n + 1-1) do (    res := res + (i) * (i + 1) * (i + 2)) ;
    return res;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import numpy as np
def main():
    SpotNum=int(input())
    SpotCoordinate=[int(i)for i in input().split()]
    SpotCoordinate.insert(0,0)
    SpotCoordinate.append(0)
    DiffSpotCoordinate=abs(np.diff(SpotCoordinate))
    SumDiffSpotCoordinate=sum(DiffSpotCoordinate)
    for i in range(1,SpotNum+1):
        result=SumDiffSpotCoordinate-DiffSpotCoordinate[i-1]-DiffSpotCoordinate[i]+abs(SpotCoordinate[i-1]-SpotCoordinate[i+1])
        print(result)
if __name__=="__main__" :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var SpotNum : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var SpotCoordinate : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    SpotCoordinate := SpotCoordinate.insertAt(0+1, 0) ;
    execute ((0) : SpotCoordinate) ;
    var DiffSpotCoordinate : double := ()->abs() ;
    var SumDiffSpotCoordinate : OclAny := (DiffSpotCoordinate)->sum() ;
    for i : Integer.subrange(1, SpotNum + 1-1) do (    var result : double := SumDiffSpotCoordinate - DiffSpotCoordinate[i - 1+1] - DiffSpotCoordinate[i+1] + (SpotCoordinate[i - 1+1] - SpotCoordinate[i + 1+1])->abs() ;
    execute (result)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
N=int(input())
list=input().split(" ")
list.insert(0,"0")
list.append("0")
change=0
now=0
for i in range(N+1):
    if nowtoInteger() ;
    var OclType["Sequence"] : OclAny := input().split(" ") ;
    OclType["Sequence"] := OclType["Sequence"].insertAt(0+1, "0") ;
    execute (("0") : OclType["Sequence"]) ;
    var change : int := 0 ;
    var now : int := 0 ;
    for i : Integer.subrange(0, N + 1-1) do (    if (now->compareTo(("" + (([i+1])))->toInteger())) < 0 then  (
      change := change + ("" + (([i+1])))->toInteger() - now ;
    now := ("" + (([i+1])))->toInteger()
    )
    else (
      change := change + now - ("" + (([i+1])))->toInteger() ;
    now := ("" + (([i+1])))->toInteger()
      )) ;
    change := change + (now)->abs() ;
    change := ("" + ((change)))->toInteger() ;
    for i : Integer.subrange(1, N + 1-1) do (    var ans : double := change - (("" + (([i+1])))->toInteger() - ("" + (([i - 1+1])))->toInteger())->abs() ;
    ans := ans - (("" + (([i + 1+1])))->toInteger() - ("" + (([i+1])))->toInteger())->abs() ;
    ans := ans + (("" + (([i + 1+1])))->toInteger() - ("" + (([i - 1+1])))->toInteger())->abs() ;
    ans := ("" + ((ans)))->toInteger() ;
    execute (ans)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
import numpy as np
sr=lambda : sys.stdin.readline().rstrip()
ir=lambda : int(sr())
lr=lambda : list(map(int,sr().split()))
N=ir()
A=np.array([0]+lr()+[0])
diff=np.diff(A)
total=np.abs(diff).sum()
answer=[]
for i in range(N):
    answer.append(total-abs(diff[i])-abs(diff[i+1])+abs(A[i+2]-A[i]))
print('\n'.join(map(str,answer)))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var sr : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ;
    var ir : Function := lambda $$ : OclAny in (("" + ((sr->apply())))->toInteger()) ;
    var lr : Function := lambda $$ : OclAny in (((sr->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))) ;
    var N : OclAny := ir->apply() ;
    var A : Sequence := (Sequence{ 0 }->union(lr->apply())->union(Sequence{ 0 })) ;
    var diff : (trailer . (name diff) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)))))))) ))) :=  ;
    var total : OclAny := np.abs(diff).sum() ;
    var answer : Sequence := Sequence{} ;
    for i : Integer.subrange(0, N-1) do (    execute ((total - (diff[i+1])->abs() - (diff[i + 1+1])->abs() + (A[i + 2+1] - A[i+1])->abs()) : answer)) ;
    execute (StringLib.sumStringsWithSeparator(((answer)->collect( _x | (OclType["String"])->apply(_x) )), '
'))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
l=[0]+list(map(int,input().split()))+[0]
f=lambda x,y : abs(l[x]-l[y])
s=sum(f(i+1,i)for i in range(n+1))
for i in range(n): print(s-f(i+1,i)-f(i+2,i+1)+f(i+2,i))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var l : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->union(Sequence{ 0 }) ;
    var f : Function := lambda x : OclAny, y : OclAny in ((l[x+1] - l[y+1])->abs()) ;
    var s : OclAny := ((argument (test (logical_test (comparison (expr (atom (name f)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) )))))))))->sum() ;
    for i : Integer.subrange(0, n-1) do (    execute (s - f->apply(i + 1, i) - f->apply(i + 2, i + 1) + f->apply(i + 2, i))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
import sys
import itertools
import queue
from fractions import gcd
def lcm(a,b):
    return a*b//gcd(a,b)
mod=1000000007
if __name__=="__main__" :
    n=int(sys.stdin.readline())
    a=[0]+list(map(int,input().split()))+[0]
    cost=sum(abs(a[i+1]-a[i])for i in range(n+1))
    for i in range(1,n+1):
        print(cost-abs(a[i+1]-a[i])-abs(a[i]-a[i-1])+abs(a[i+1]-a[i-1]))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var mod : int := 1000000007 ;
    if __name__ = "__main__" then (
      var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    a := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->union(Sequence{ 0 }) ;
    var cost : OclAny := ((argument (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))) - (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) )))))))))->sum() ;
    for i : Integer.subrange(1, n + 1-1) do (    execute (cost - (a[i + 1+1] - a[i+1])->abs() - (a[i+1] - a[i - 1+1])->abs() + (a[i + 1+1] - a[i - 1+1])->abs())->display())
    ) else skip;
  operation lcm(a : OclAny, b : OclAny) : OclAny
  pre: true post: true
  activity:
    return a * b div gcd(a, b);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
cases=int(input())
for i in range(cases):
    n,m,k=map(int,input().split())
    if k==(n*m-1):
        print("YES")
    else :
        print("NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var cases : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, cases-1) do (    var n : OclAny := null;
    var m : OclAny := null;
    var k : OclAny := null;
    Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if k = (n * m - 1) then  (
      execute ("YES")->display()
    )
    else (
      execute ("NO")->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    n,m,k=map(int,input().split())
    if n==1 and m==1 and k==0 :
        print("YES")
    elif((n-1)+(m-1)*n)==k : print('YES')
    else : print('NO')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : OclAny := null;
    var m : OclAny := null;
    var k : OclAny := null;
    Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if n = 1 & m = 1 & k = 0 then  (
      execute ("YES")->display()
    )
    else (if ((n - 1) + (m - 1) * n) = k then
   (
      execute ('YES')->display()    
)
    else (
      execute ('NO')->display()
      )    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def minOperations(arr,n):
    result=0
    freq=[0]*1000001
    for i in range(0,n):
        freq[arr[i]]+=1
    maxi=max(arr)
    for i in range(1,maxi+1):
        if freq[i]!=0 :
            for j in range(i*2,maxi+1,i):
                freq[j]=0
            result+=1
    return result
if __name__=="__main__" :
    arr=[2,4,2,4,4,4]
    n=len(arr)
    print(minOperations(arr,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      arr := Sequence{2}->union(Sequence{4}->union(Sequence{2}->union(Sequence{4}->union(Sequence{4}->union(Sequence{ 4 }))))) ;
    n := (arr)->size() ;
    execute (minOperations(arr, n))->display()
    ) else skip;
  operation minOperations(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var result : int := 0 ;
    var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 1000001) ;
    for i : Integer.subrange(0, n-1) do (    freq[arr[i+1]+1] := freq[arr[i+1]+1] + 1) ;
    var maxi : OclAny := (arr)->max() ;
    for i : Integer.subrange(1, maxi + 1-1) do (    if freq[i+1] /= 0 then (
      for j : Integer.subrange(i * 2, maxi + 1-1)->select( $x | ($x - i * 2) mod i = 0 ) do (    freq[j+1] := 0) ;
    result := result + 1
    ) else skip) ;
    return result;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
for _ in range(int(input())):
    s,i,e=map(int,input().split())
    x=s-i
    print(1 if x>0 and e==0 else min(e+1,(e+x+1)//2)if x+e>0 else 0)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var s : OclAny := null;
    var i : OclAny := null;
    var e : OclAny := null;
    Sequence{s,i,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var x : double := s - i ;
    execute (if x > 0 & e = 0 then 1 else if x + e > 0 then Set{e + 1, (e + x + 1) div 2}->min() else 0 endif endif)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for j in range(t):
    n,m,k=map(int,input().split())
    if m*n-1==k :
        print('YES')
    else :
        print('NO')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for j : Integer.subrange(0, t-1) do (    var n : OclAny := null;
    var m : OclAny := null;
    var k : OclAny := null;
    Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if m * n - 1 = k then  (
      execute ('YES')->display()
    )
    else (
      execute ('NO')->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for _ in range(t):
    n,m,k=[int(s)for s in input().split()]
    print("YES" if n*m-1==k else "NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, t-1) do (    var n : OclAny := null;
    var m : OclAny := null;
    var k : OclAny := null;
    Sequence{n,m,k} := input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ;
    execute (if n * m - 1 = k then "YES" else "NO" endif)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
ans=[]
for i in range(t):
    nums=tuple(map(int,input().split()))
    maks=max(nums[: 2])
    mini=min(nums[: 2])
    d=nums[-1]
    burles=(maks-1)*1+(mini-1)*maks
    if(burles==d):
        ans.append('YES')
    else :
        ans.append('NO')
for case in tuple(ans):
    print(case)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var ans : Sequence := Sequence{} ;
    for i : Integer.subrange(0, t-1) do (    var nums : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var maks : OclAny := (nums.subrange(1,2))->max() ;
    var mini : OclAny := (nums.subrange(1,2))->min() ;
    var d : OclAny := nums->last() ;
    var burles : double := (maks - 1) * 1 + (mini - 1) * maks ;
    if (burles = d) then  (
      execute (('YES') : ans)
    )
    else (
      execute (('NO') : ans)
      )) ;
    for case : (ans) do (    execute (case)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
(n,h,m)=map(int,input().split(' '))
restriction_areas=[]
for i in range(m):
(l,r,x)=map(int,input().split(' '))
    restriction_areas.append([l,r,x])
restriction_areas.append([0,0,0])
heights=[]
for j in range(1,n+1):
    comparison=[]
    for k in range(m):
        if j in range(restriction_areas[k][0],restriction_areas[k][1]+1):
            comparison.append(restriction_areas[k][2])
    if len(comparison)>0 :
        heights.append(min(comparison))
    else :
        heights.append(h)
profit=0
for height in heights :
    profit+=height**2
print(profit)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var Sequence{n, h, m} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ;
    var restriction_areas : Sequence := Sequence{} ;
    for i : Integer.subrange(0, m-1) do ( ;
    var Sequence{l, r, x} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute ((Sequence{l}->union(Sequence{r}->union(Sequence{ x }))) : restriction_areas)) ;
    execute ((Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))) : restriction_areas) ;
    var heights : Sequence := Sequence{} ;
    for j : Integer.subrange(1, n + 1-1) do (    var comparison : Sequence := Sequence{} ;
    for k : Integer.subrange(0, m-1) do (    if (Integer.subrange(restriction_areas[k+1]->first(), restriction_areas[k+1][1+1] + 1-1))->includes(j) then (
      execute ((restriction_areas[k+1][2+1]) : comparison)
    ) else skip) ;
    if (comparison)->size() > 0 then  (
      execute (((comparison)->min()) : heights)
    )
    else (
      execute ((h) : heights)
      )) ;
    var profit : int := 0 ;
    for height : heights do (    profit := profit + (height)->pow(2)) ;
    execute (profit)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
i=lambda : map(int,input().split())
n,h,m=i()
v=[h]*n
for f in range(m):
    l,r,x=i()
    for a in range(l-1,r): v[a]=min(v[a],x)
print(sum(x*x for x in v))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var i : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var n : OclAny := null;
    var h : OclAny := null;
    var m : OclAny := null;
    Sequence{n,h,m} := i->apply() ;
    var v : Sequence := MatrixLib.elementwiseMult(Sequence{ h }, n) ;
    for f : Integer.subrange(0, m-1) do (    var l : OclAny := null;
    var r : OclAny := null;
    var x : OclAny := null;
    Sequence{l,r,x} := i->apply() ;
    for a : Integer.subrange(l - 1, r-1) do (    v[a+1] := Set{v[a+1], x}->min())) ;
    execute (((argument (test (logical_test (comparison (expr (expr (atom (name x))) * (expr (atom (name x))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name v))))))))->sum())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,h,m=map(int,input().split())
c=0
s=0
ans=[h for i in range(n)]
for i in range(m):
    l,r,x=map(int,input().split())
    for k in range(l-1,r):
        ans[k]=min(ans[k],x)
for i in range(n):
    s+=(ans[i]*ans[i])
print(s)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var h : OclAny := null;
    var m : OclAny := null;
    Sequence{n,h,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var c : int := 0 ;
    var s : int := 0 ;
    var ans : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (h)) ;
    for i : Integer.subrange(0, m-1) do (    var l : OclAny := null;
    var r : OclAny := null;
    var x : OclAny := null;
    Sequence{l,r,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    for k : Integer.subrange(l - 1, r-1) do (    ans[k+1] := Set{ans[k+1], x}->min())) ;
    for i : Integer.subrange(0, n-1) do (    s := s + (ans[i+1] * ans[i+1])) ;
    execute (s)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
i=lambda : map(int,input().split())
n,h,m=i()
v=[h]*n
for _ in range(m):
    l,r,x=i()
    for a in range(l-1,r): v[a]=min(v[a],x)
print(sum(x*x for x in v))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var i : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var n : OclAny := null;
    var h : OclAny := null;
    var m : OclAny := null;
    Sequence{n,h,m} := i->apply() ;
    var v : Sequence := MatrixLib.elementwiseMult(Sequence{ h }, n) ;
    for _anon : Integer.subrange(0, m-1) do (    var l : OclAny := null;
    var r : OclAny := null;
    var x : OclAny := null;
    Sequence{l,r,x} := i->apply() ;
    for a : Integer.subrange(l - 1, r-1) do (    v[a+1] := Set{v[a+1], x}->min())) ;
    execute (((argument (test (logical_test (comparison (expr (expr (atom (name x))) * (expr (atom (name x))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name v))))))))->sum())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys,os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n,h,m=map(int,input().split())
y=[h]*(n+1)
for _ in range(m):
    l,r,x=map(int,input().split())
    for i in range(l,r+1):
        y[i]=min(y[i],x)
ans=0
for i in y[1 :]:
    ans+=i*i
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := io.BytesIO(os.readAll()).readline ;
    var n : OclAny := null;
    var h : OclAny := null;
    var m : OclAny := null;
    Sequence{n,h,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var y : Sequence := MatrixLib.elementwiseMult(Sequence{ h }, (n + 1)) ;
    for _anon : Integer.subrange(0, m-1) do (    var l : OclAny := null;
    var r : OclAny := null;
    var x : OclAny := null;
    Sequence{l,r,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    for i : Integer.subrange(l, r + 1-1) do (    y[i+1] := Set{y[i+1], x}->min())) ;
    var ans : int := 0 ;
    for i : y->tail() do (    ans := ans + i * i) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def findMajority(arr,n):
    Len=32
    number=0
    for i in range(Len):
        count=0
        for j in range(n):
            if(arr[j]&(1<(n//2)):
            number+=(1<(n//2)):
        print(number)
    else :
        print("Majority Element Not Present")
arr=[3,3,4,2,4,4,2,4,4]
n=len(arr)
findMajority(arr,n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    arr := Sequence{3}->union(Sequence{3}->union(Sequence{4}->union(Sequence{2}->union(Sequence{4}->union(Sequence{4}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 4 })))))))) ;
    n := (arr)->size() ;
    findMajority(arr, n);
  operation findMajority(arr : OclAny, n : OclAny)
  pre: true post: true
  activity:
    var Len : int := 32 ;
    var number : int := 0 ;
    for i : Integer.subrange(0, Len-1) do (    var count : int := 0 ;
    for j : Integer.subrange(0, n-1) do (    if (MathLib.bitwiseAnd(arr[j+1], (1 * (2->pow(i))))) then (
      count := count + 1
    ) else skip) ;
    if ((count->compareTo((n div 2))) > 0) then (
      number := number + (1 * (2->pow(i)))
    ) else skip) ;
    count := 0 ;
    for i : Integer.subrange(0, n-1) do (    if (arr[i+1] = number) then (
      count := count + 1
    ) else skip) ;
    if ((count->compareTo((n div 2))) > 0) then  (
      execute (number)->display()
    )
    else (
      execute ("Majority Element Not Present")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def totalWays(N,M,X):
    dp=[[0 for i in range(2)]for j in range(N+1)]
    if(X==1):
        dp[0][0]=1
    else :
        dp[0][1]=0
    if(X==1):
        dp[1][0]=0
        dp[1][1]=M-1
    else :
        dp[1][0]=1
        dp[1][1]=(M-2)
    for i in range(2,N):
        dp[i][0]=dp[i-1][1]
        dp[i][1]=dp[i-1][0]*(M-1)+dp[i-1][1]*(M-2)
    return dp[N-1][0]
if __name__=='__main__' :
    N=4
    M=3
    X=2
    print(totalWays(N,M,X))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      N := 4 ;
    M := 3 ;
    X := 2 ;
    execute (totalWays(N, M, X))->display()
    ) else skip;
  operation totalWays(N : OclAny, M : OclAny, X : OclAny) : OclAny
  pre: true post: true
  activity:
    var dp : Sequence := Integer.subrange(0, N + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, 2-1)->select(i | true)->collect(i | (0)))) ;
    if (X = 1) then  (
      dp->first()->first() := 1
    )
    else (
      dp->first()[1+1] := 0
      ) ;
    if (X = 1) then  (
      dp[1+1]->first() := 0 ;
    dp[1+1][1+1] := M - 1
    )
    else (
      dp[1+1]->first() := 1 ;
    dp[1+1][1+1] := (M - 2)
      ) ;
    for i : Integer.subrange(2, N-1) do (    dp[i+1]->first() := dp[i - 1+1][1+1] ;
    dp[i+1][1+1] := dp[i - 1+1]->first() * (M - 1) + dp[i - 1+1][1+1] * (M - 2)) ;
    return dp[N - 1+1]->first();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def getAverageCountArray(a,x,N):
    map={}
    avg=[0]*N
    for i in range(N):
        if a[i]not in map :
            map[a[i]]=1
        else :
            map[a[i]]+=1
    for i in range(N):
        av=(a[i]+x)//2
        if av in map :
            val=map[av]
            avg[i]=val
    for i in range(N):
        print(avg[i],end=" ")
if __name__=="__main__" :
    a=[2,0,4,6,2]
    x=2
    N=len(a)
    getAverageCountArray(a,x,N)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      a := Sequence{2}->union(Sequence{0}->union(Sequence{4}->union(Sequence{6}->union(Sequence{ 2 })))) ;
    x := 2 ;
    N := (a)->size() ;
    getAverageCountArray(a, x, N)
    ) else skip;
  operation getAverageCountArray(a : OclAny, x : OclAny, N : OclAny)
  pre: true post: true
  activity:
    var map : OclAny := Set{} ;
    var avg : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ;
    for i : Integer.subrange(0, N-1) do (    if (map)->excludes(a[i+1]) then  (
      ([a[i+1]+1]`third)->collect( _x | ([a[i+1]+1])->apply(_x) ) := 1
    )
    else (
      ([a[i+1]+1]`third)->collect( _x | ([a[i+1]+1])->apply(_x) ) := ([a[i+1]+1]`third)->collect( _x | ([a[i+1]+1])->apply(_x) ) + 1
      )) ;
    for i : Integer.subrange(0, N-1) do (    var av : int := (a[i+1] + x) div 2 ;
    if (map)->includes(av) then (
      var val : Sequence := ([av+1]`third)->collect( _x | ([av+1])->apply(_x) ) ;
    avg[i+1] := val
    ) else skip) ;
    for i : Integer.subrange(0, N-1) do (    execute (avg[i+1])->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
def sumOfRange(a,b):
    i=(a*(a+1))>>1 ;
    j=(b*(b+1))>>1 ;
    return(i-j);
def sumofproduct(n):
    sum=0 ;
    root=int(math.sqrt(n));
    for i in range(1,root+1):
        up=int(n/i);
        low=max(int(n/(i+1)),root);
        sum+=(i*sumOfRange(up,low));
        sum+=(i*int(n/i));
    return sum ;
n=10 ;
print(sumofproduct(n));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    n := 10; ;
    execute (sumofproduct(n))->display();;
  operation sumOfRange(a : OclAny, b : OclAny)
  pre: true post: true
  activity:
    var i : int := (a * (a + 1)) /(2->pow(1)); ;
    var j : int := (b * (b + 1)) /(2->pow(1)); ;
    return (i - j);;
  operation sumofproduct(n : OclAny)
  pre: true post: true
  activity:
    var sum : int := 0; ;
    var root : int := ("" + (((n)->sqrt())))->toInteger(); ;
    for i : Integer.subrange(1, root + 1-1) do (    var up : int := ("" + ((n / i)))->toInteger(); ;
    var low : OclAny := Set{("" + ((n / (i + 1))))->toInteger(), root}->max(); ;
    sum := sum + (i * sumOfRange(up, low)); ;
    sum := sum + (i * ("" + ((n / i)))->toInteger());) ;
    return sum;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import numpy as np
MAX_INDEX=51
MAX_SUM=2505
dp=np.ones((MAX_INDEX,MAX_SUM,MAX_INDEX))*-1 ;
def waysutil(index,sum,count,arr,K):
    if(index<0):
        return 0 ;
    if(index==0):
        if(count==0):
            return 0 ;
        remainder=sum % count ;
        if(remainder!=0):
            return 0 ;
        average=sum//count ;
        if(average==K):
            return 1 ;
    if(dp[index][sum][count]!=-1):
        return dp[index][sum][count];
    dontpick=waysutil(index-1,sum,count,arr,K);
    pick=waysutil(index-1,sum+arr[index],count+1,arr,K);
    total=pick+dontpick ;
    dp[index][sum][count]=total ;
    return total ;
def ways(N,K,arr):
    Arr=[];
    Arr.append(-1);
    for i in range(N):
        Arr.append(arr[i]);
    answer=waysutil(N,0,0,Arr,K);
    return answer ;
if __name__=="__main__" :
    arr=[3,6,2,8,7,6,5,9];
    N=len(arr);
    K=5 ;
    print(ways(N,K,arr));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var MAX_INDEX : int := 51 ;
    var MAX_SUM : int := 2505 ;
    var dp : Sequence := MatrixLib.elementwiseMult(MatrixLib.singleValueMatrix(Sequence{MAX_INDEX, MAX_SUM, MAX_INDEX}, 1.0), -1); ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      arr := Sequence{3}->union(Sequence{6}->union(Sequence{2}->union(Sequence{8}->union(Sequence{7}->union(Sequence{6}->union(Sequence{5}->union(Sequence{ 9 }))))))); ;
    N := (arr)->size(); ;
    K := 5; ;
    execute (ways(N, K, arr))->display();
    ) else skip;
  operation waysutil(index : OclAny, sum : OclAny, count : OclAny, arr : OclAny, K : OclAny)
  pre: true post: true
  activity:
    if (index < 0) then (
      return 0;
    ) else skip ;
    if (index = 0) then (
      if (count = 0) then (
      return 0;
    ) else skip ;
    var remainder : int := sum mod count; ;
    if (remainder /= 0) then (
      return 0;
    ) else skip ;
    var average : int := sum div count; ;
    if (average = K) then (
      return 1;
    ) else skip
    ) else skip ;
    if (dp[index+1][sum+1][count+1] /= -1) then (
      return dp[index+1][sum+1][count+1];
    ) else skip ;
    var dontpick : OclAny := waysutil(index - 1, sum, count, arr, K); ;
    var pick : OclAny := waysutil(index - 1, sum + arr[index+1], count + 1, arr, K); ;
    var total : OclAny := pick + dontpick; ;
    dp[index+1][sum+1][count+1] := total; ;
    return total;;
  operation ways(N : OclAny, K : OclAny, arr : OclAny)
  pre: true post: true
  activity:
    var Arr : Sequence := Sequence{}; ;
    execute ((-1) : Arr); ;
    for i : Integer.subrange(0, N-1) do (    execute ((arr[i+1]) : Arr);) ;
    var answer : OclAny := waysutil(N, 0, 0, Arr, K); ;
    return answer;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def revAlternateK(s,k,Len):
    i=0
    while(iLen):
            break
        ss=s[i : i+k]
        s=s[: i]+ss[: :-1]+s[i+k :]
        i+=2*k
    return s ;
s="geeksforgeeks"
Len=len(s)
k=3
print(revAlternateK(s,k,Len))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    s := "geeksforgeeks" ;
    Len := (s)->size() ;
    k := 3 ;
    execute (revAlternateK(s, k, Len))->display();
  operation revAlternateK(s : OclAny, k : OclAny, Len : OclAny)
  pre: true post: true
  activity:
    var i : int := 0 ;
    while ((i->compareTo((s)->size())) < 0) do (    if ((i + k->compareTo(Len)) > 0) then (
      break
    ) else skip ;
    var ss : OclAny := s.subrange(i+1, i + k) ;
    s := s.subrange(1,i) + ss(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) + s.subrange(i + k+1) ;
    i := i + 2 * k) ;
    return s;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for i in range(t):
    n=int(input())
    x=list(map(int,input().split()))
    m=int(input())
    y=list(map(int,input().split()))
    print('Alice' if max(x)>=max(y)else 'Bob')
    print('Alice' if max(x)>max(y)else 'Bob')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, t-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var y : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute (if ((x)->max()->compareTo((y)->max())) >= 0 then 'Alice' else 'Bob' endif)->display() ;
    execute (if ((x)->max()->compareTo((y)->max())) > 0 then 'Alice' else 'Bob' endif)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for i in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    m=int(input())
    b=list(map(int,input().split()))
    print('Alice' if max(a)>=max(b)else 'Bob')
    print('Alice' if max(a)>max(b)else 'Bob')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, t-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute (if ((a)->max()->compareTo((b)->max())) >= 0 then 'Alice' else 'Bob' endif)->display() ;
    execute (if ((a)->max()->compareTo((b)->max())) > 0 then 'Alice' else 'Bob' endif)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
for i in range(n):
    a=int(input())
    l=list(map(int,input().split()))
    b=int(input())
    t=list(map(int,input().split()))
    N=max(l)
    M=max(t)
    if(N>M):
        print("Alice")
        print("Alice")
    elif(M>N):
        print("Bob")
        print("Bob")
    else :
        print("Alice")
        print("Bob")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, n-1) do (    var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var t : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var N : OclAny := (l)->max() ;
    var M : OclAny := (t)->max() ;
    if ((N->compareTo(M)) > 0) then  (
      execute ("Alice")->display() ;
    execute ("Alice")->display()
    )
    else (if ((M->compareTo(N)) > 0) then
   (
      execute ("Bob")->display() ;
    execute ("Bob")->display()    
)
    else (
      execute ("Alice")->display() ;
    execute ("Bob")->display()
      )    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
r=[]
for i in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    m=int(input())
    b=list(map(int,input().split()))
    c=max(a)
    d=max(b)
    if c==d :
        r.append("Alice")
        r.append("Bob")
    elif c>d :
        r.append("Alice")
        r.append("Alice")
    else :
        r.append("Bob")
        r.append("Bob")
for i in range(len(r)):
    print(r[i])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var r : Sequence := Sequence{} ;
    for i : Integer.subrange(0, t-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var c : OclAny := (a)->max() ;
    var d : OclAny := (b)->max() ;
    if c = d then  (
      execute (("Alice") : r) ;
    execute (("Bob") : r)
    )
    else (if (c->compareTo(d)) > 0 then
   (
      execute (("Alice") : r) ;
    execute (("Alice") : r)    
)
    else (
      execute (("Bob") : r) ;
    execute (("Bob") : r)
      )    )
) ;
    for i : Integer.subrange(0, (r)->size()-1) do (    execute (r[i+1])->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def reverseFibonacci(n):
    a=[0]*n
    a[0]=0
    a[1]=1
    for i in range(2,n):
        a[i]=a[i-2]+a[i-1]
    for i in range(n-1,-1,-1):
        print(a[i],end=" ")
n=5
reverseFibonacci(n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    n := 5 ;
    reverseFibonacci(n);
  operation reverseFibonacci(n : OclAny)
  pre: true post: true
  activity:
    var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ;
    a->first() := 0 ;
    a[1+1] := 1 ;
    for i : Integer.subrange(2, n-1) do (    a[i+1] := a[i - 2+1] + a[i - 1+1]) ;
    for i : Integer.subrange(-1 + 1, n - 1)->reverse() do (    execute (a[i+1])->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def max_xor(arr,n):
    maxx=0
    mask=0 ;
    se=set()
    for i in range(30,-1,-1):
        mask |=(1<union(Sequence{10}->union(Sequence{2}->union(Sequence{8}->union(Sequence{5}->union(Sequence{ 3 }))))) ;
    n := (arr)->size() ;
    execute (max_xor(arr, n))->display();
  operation max_xor(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var maxx : int := 0 ;
    var mask : int := 0; ;
    var se : Set := Set{}->union(()) ;
    for i : Integer.subrange(-1 + 1, 30)->reverse() do (    mask := mask or (1 * (2->pow(i))) ;
    var newMaxx : int := MathLib.bitwiseOr(maxx, (1 * (2->pow(i)))) ;
    for i : Integer.subrange(0, n-1) do (    execute ((MathLib.bitwiseAnd(arr[i+1], mask)) : se)) ;
    for prefix : se do (    if (se)->includes((MathLib.bitwiseXor(newMaxx, prefix))) then (
      maxx := newMaxx ;
    break
    ) else skip) ;
    execute (se /<: se)) ;
    return maxx;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from fractions import Fraction
inl=lambda : list(map(int,input().split()))
a,b,c,d=inl()
mh,mv=0,0
if c>d :
    mh=min(a,Fraction(b*c,d))
    mv=Fraction((mh*d),c)
elif d>c :
    mv=min(Fraction(a*d,c),b)
    mh=Fraction(mv*c,d)
else :
    mv=mh=min(a,b)
ma=mv*mh
ta=a*b
if Fraction((ta-ma),ta)==0 :
    print("0/1")
else :
    print(Fraction((ta-ma),ta))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var inl : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ;
    var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    var d : OclAny := null;
    Sequence{a,b,c,d} := inl->apply() ;
    var mh : OclAny := null;
    var mv : OclAny := null;
    Sequence{mh,mv} := Sequence{0,0} ;
    if (c->compareTo(d)) > 0 then  (
      var mh : OclAny := Set{a, Fraction(b * c, d)}->min() ;
    var mv : OclAny := Fraction((mh * d), c)
    )
    else (if (d->compareTo(c)) > 0 then
   (
      mv := Set{Fraction(a * d, c), b}->min() ;
    mh := Fraction(mv * c, d)    
)
    else (
      mv := Set{a, b}->min(); mh := Set{a, b}->min()
      )    )
 ;
    var ma : double := mv * mh ;
    var ta : double := a * b ;
    if Fraction((ta - ma), ta) = 0 then  (
      execute ("0/1")->display()
    )
    else (
      execute (Fraction((ta - ma), ta))->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
class MaxStack(object):
    def __init__(self):
        self.stack=[]
        self.max_stack=[]
    def push(self,x):
        self.stack.append(x)
        if len(self.max_stack)==0 :
            self.max_stack.append(x)
            return
        if self.max_stack[-1]>x :
            self.max_stack.append(self.max_stack[-1])
        else :
            self.max_stack.append(x)
    def pop(self):
        if len(self.stack)!=0 :
            self.max_stack.pop(-1)
            return self.stack.pop(-1)
    def top(self):
        return self.stack[-1]
    def peekMax(self):
        if len(self.max_stack)!=0 :
            return self.max_stack[-1]
    def popMax(self):
        val=self.peekMax()
        buff=[]
        while self.top()!=val :
            buff.append(self.pop())
        self.pop()
        while len(buff)!=0 :
            self.push(buff.pop(-1))
        return val
------------------------------------------------------------
OCL File:
---------
class MaxStack extends object {
  static operation newMaxStack() : MaxStack
  pre: true
  post: MaxStack->exists( _x | result = _x );
  attribute stack : Sequence := Sequence{};
  attribute max_stack : Sequence := Sequence{};
  operation initialise() : 
  pre: true post: true
  activity:
    self.stack := Sequence{} ;
    self.max_stack := Sequence{};
    return self;
  operation push(x : OclAny)
  pre: true post: true
  activity:
(expr (atom (name self)) (trailer . (name stack)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) ;
    if (self.max_stack)->size() = 0 then (
  (expr (atom (name self)) (trailer . (name max_stack)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) ;
    return
    ) else skip ;
    if (self.max_stack->last()->compareTo(x)) > 0 then  (
  (expr (atom (name self)) (trailer . (name max_stack)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name self)) (trailer . (name max_stack) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))))) ))))
    )
    else (
  (expr (atom (name self)) (trailer . (name max_stack)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))
      );
  operation pop() : OclAny
  pre: true post: true
  activity:
    if (self.stack)->size() /= 0 then (
  (expr (atom (name self)) (trailer . (name max_stack)) (trailer . (name pop) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))) ;
    return self.stack->at((atom - (number (integer 1)))+1)
    ) else skip;
  operation top() : OclAny
  pre: true post: true
  activity:
    return self.stack->last();
  operation peekMax() : OclAny
  pre: true post: true
  activity:
    if (self.max_stack)->size() /= 0 then (
      return self.max_stack->last()
    ) else skip;
  operation popMax() : OclAny
  pre: true post: true
  activity:
    var val : OclAny := self.peekMax() ;
    var buff : Sequence := Sequence{} ;
    while self.top() /= val do (    execute ((self->last()) : buff)) ;
    self := self->front() ;
    while (buff)->size() /= 0 do (    self.push(buff->at((atom - (number (integer 1)))+1))) ;
    return val;
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import collections
INF=10**10
N,C=map(int,input().split())
d=[list(map(int,input().split()))for _ in range(C)]
c=[list(map(int,input().split()))for _ in range(N)]
lc=[[],[],[]]
for i in range(N):
    for j in range(N):
        lc[(i+j)% 3].append(c[i][j])
clc=[collections.Counter(lc[i])for i in range(3)]
def iwakan(clist,color):
    global C
    ret=0
    for i in range(C):
        ret+=clist[i+1]*d[i][color]
    return ret
res=INF
for i in range(C):
    for j in range(C):
        for k in range(C):
            if i==j or i==k or j==k :
                continue
            res=min(res,iwakan(clc[0],i)+iwakan(clc[1],j)+iwakan(clc[2],k))
print(res)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  attribute C : OclAny;
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var INF : double := (10)->pow(10) ;
    var N : OclAny := null;
    var C : OclAny := null;
    Sequence{N,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var d : Sequence := Integer.subrange(0, C-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var c : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var lc : Sequence := Sequence{Sequence{}}->union(Sequence{Sequence{}}->union(Sequence{ Sequence{} })) ;
    for i : Integer.subrange(0, N-1) do (    for j : Integer.subrange(0, N-1) do ((expr (atom (name lc)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name j)))))))) ))) % (expr (atom (number (integer 3)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) )))))) ;
    var clc : Sequence := Integer.subrange(0, 3-1)->select(i | true)->collect(i | (.Counter(lc[i+1]))) ;
    skip ;
    var res : OclAny := INF ;
    for i : Integer.subrange(0, C-1) do (    for j : Integer.subrange(0, C-1) do (    for k : Integer.subrange(0, C-1) do (    if i = j or i = k or j = k then (
      continue
    ) else skip ;
    res := Set{res, iwakan(clc->first(), i) + iwakan(clc[1+1], j) + iwakan(clc[2+1], k)}->min()))) ;
    execute (res)->display();
  operation iwakan(clist : OclAny, color : OclAny) : OclAny
  pre: true post: true
  activity:
    skip ;
    var ret : int := 0 ;
    for i : Integer.subrange(0, C-1) do (    ret := ret + clist[i + 1+1] * d[i+1][color+1]) ;
    return ret;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
N=list(map(int,input().split()))
m=int(input())
M=list(map(int,input().split()))
sum_lis=[]
for i in range(2**n):
    lis=[]
    for j in range(n):
        if(i>>j)& 1==1 :
            lis.append(N[j])
    sum_lis.append(sum(lis))
sum_set=set(sum_lis)
for i in range(m):
    if M[i]in sum_set :
        M[i]='yes'
    else :
        M[i]='no'
[print(_)for _ in M]
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var N : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var M : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var sum_lis : Sequence := Sequence{} ;
    for i : Integer.subrange(0, (2)->pow(n)-1) do (    var lis : Sequence := Sequence{} ;
    for j : Integer.subrange(0, n-1) do (    if MathLib.bitwiseAnd((i /(2->pow(j))), 1) = 1 then (
      execute ((N[j+1]) : lis)
    ) else skip) ;
    execute (((lis)->sum()) : sum_lis)) ;
    var sum_set : Set := Set{}->union((sum_lis)) ;
    for i : Integer.subrange(0, m-1) do (    if (sum_set)->includes(M[i+1]) then  (
      M[i+1] := 'yes'
    )
    else (
      M[i+1] := 'no'
      )) ;
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import Counter
N,C=map(int,input().split())
D=[list(map(int,input().split()))for i in range(C)]
c=[list(map(int,input().split()))for i in range(N)]
ls=[Counter([c[i][j]for i in range(N)for j in range(N)if(i+j)% 3==k])for k in range(3)]
result=float("inf")
for i in range(C):
    for j in range(C):
        if i==j :
            continue
        for k in range(C):
            if i==k or j==k :
                continue
            tt=0
            for l in range(1,C+1):
                tt+=ls[0][l]*D[l-1][i]
                tt+=ls[1][l]*D[l-1][j]
                tt+=ls[2][l]*D[l-1][k]
            result=min(tt,result)
print(result)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var N : OclAny := null;
    var C : OclAny := null;
    Sequence{N,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var D : Sequence := Integer.subrange(0, C-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var c : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var ls : Sequence := Integer.subrange(0, 3-1)->select(k | true)->collect(k | (Counter(Integer.subrange(0, N-1)->select(i; j : Integer.subrange(0, N-1) | true)->collect(i; j : Integer.subrange(0, N-1) | (c[i+1][j+1]))))) ;
    var result : double := ("" + (("inf")))->toReal() ;
    for i : Integer.subrange(0, C-1) do (    for j : Integer.subrange(0, C-1) do (    if i = j then (
      continue
    ) else skip ;
    for k : Integer.subrange(0, C-1) do (    if i = k or j = k then (
      continue
    ) else skip ;
    var tt : int := 0 ;
    for l : Integer.subrange(1, C + 1-1) do (    tt := tt + ls->first()[l+1] * D[l - 1+1][i+1] ;
    tt := tt + ls[1+1][l+1] * D[l - 1+1][j+1] ;
    tt := tt + ls[2+1][l+1] * D[l - 1+1][k+1]) ;
    result := Set{tt, result}->min()))) ;
    execute (result)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
from collections import defaultdict
import itertools
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
in_n=lambda : int(readline())
in_nn=lambda : map(int,readline().split())
in_nl=lambda : list(map(int,readline().split()))
in_na=lambda : map(int,read().split())
in_s=lambda : readline().rstrip().decode('utf-8')
def main():
    N,C=in_nn()
    D=[list(map(int,readline().split()))for _ in range(C)]
    c=[list(map(int,readline().split()))for _ in range(N)]
    grid=[defaultdict(int)for _ in range(3)]
    for y in range(N):
        for x in range(N):
            d=grid[(x+y+2)% 3]
            d[c[y][x]]+=1
    comb=itertools.permutations(range(1,C+1),3)
    ans=10**9+7
    for com in comb :
        iwa=0
        for i in range(3):
            n_c=com[i]
            for k,v in grid[i].items():
                iwa+=D[k-1][n_c-1]*v
        ans=min(ans,iwa)
    print(ans)
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    var read : OclAny := sys.stdin.buffer.read ;
    var readline : OclAny := sys.stdin.buffer.readline ;
    var in_n : Function := lambda $$ : OclAny in (("" + ((readline())))->toInteger()) ;
    var in_nn : Function := lambda $$ : OclAny in ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var in_nl : Function := lambda $$ : OclAny in (((readline().split())->collect( _x | (OclType["int"])->apply(_x) ))) ;
    var in_na : Function := lambda $$ : OclAny in ((read().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var in_s : Function := lambda $$ : OclAny in (readline().rstrip().decode('utf-8')) ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var N : OclAny := null;
    var C : OclAny := null;
    Sequence{N,C} := in_nn->apply() ;
    var D : Sequence := Integer.subrange(0, C-1)->select(_anon | true)->collect(_anon | (((readline().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var c : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((readline().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var grid : Sequence := Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (defaultdict(OclType["int"]))) ;
    for y : Integer.subrange(0, N-1) do (    for x : Integer.subrange(0, N-1) do (    var d : OclAny := grid[(x + y + 2) mod 3+1] ;
    d[c[y+1][x+1]+1] := d[c[y+1][x+1]+1] + 1)) ;
    var comb : OclAny := itertools.permutations(Integer.subrange(1, C + 1-1), 3) ;
    var ans : double := (10)->pow(9) + 7 ;
    for com : comb do (    var iwa : int := 0 ;
    for i : Integer.subrange(0, 3-1) do (    var n_c : OclAny := com[i+1] ;
    for _tuple : grid[i+1]->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1;
      var k : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var v : OclAny := _tuple->at(_indx);
      iwa := iwa + D[k - 1+1][n_c - 1+1] * v)) ;
    ans := Set{ans, iwa}->min()) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=10**18
mod=10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)
n,c=map(int,input().split())
D=[list(map(int,input().split()))for _ in range(c)]
C=[[int(x)-1 for x in input().split()]for _ in range(n)]
C0,C1,C2=[0]*c,[0]*c,[0]*c
for i in range(n):
    for j in range(n):
        if(i+j)% 3==0 :
            C0[C[i][j]]+=1
        elif(i+j)% 3==1 :
            C1[C[i][j]]+=1
        else :
            C2[C[i][j]]+=1
ans=inf
for(i,j,k)in permutations(range(c),3):
    cur=0
    for l in range(c):
        cur+=D[l][i]*C0[l]+D[l][j]*C1[l]+D[l][k]*C2[l]
    ans=min(ans,cur)
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var Math_PINFINITY : double := (10)->pow(18) ;
    var mod : double := (10)->pow(9) + 7 ;
    skip ;
    skip ;
    sys.setrecursionlimit((10)->pow(7)) ;
    var n : OclAny := null;
    var c : OclAny := null;
    Sequence{n,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var D : Sequence := Integer.subrange(0, c-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var C : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)))) ;
    var C0 : OclAny := null;
    var C1 : OclAny := null;
    var C2 : OclAny := null;
    Sequence{C0,C1,C2} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, c),MatrixLib.elementwiseMult(Sequence{ 0 }, c),MatrixLib.elementwiseMult(Sequence{ 0 }, c)} ;
    for i : Integer.subrange(0, n-1) do (    for j : Integer.subrange(0, n-1) do (    if (i + j) mod 3 = 0 then  (
      C0[C[i+1][j+1]+1] := C0[C[i+1][j+1]+1] + 1
    )
    else (if (i + j) mod 3 = 1 then
   (
      C1[C[i+1][j+1]+1] := C1[C[i+1][j+1]+1] + 1    
)
    else (
      C2[C[i+1][j+1]+1] := C2[C[i+1][j+1]+1] + 1
      )    )
)) ;
    var ans : double := Math_PINFINITY ;
    for Sequence{i, j, k} : permutations(Integer.subrange(0, c-1), 3) do (    var cur : int := 0 ;
    for l : Integer.subrange(0, c-1) do (    cur := cur + D[l+1][i+1] * C0[l+1] + D[l+1][j+1] * C1[l+1] + D[l+1][k+1] * C2[l+1]) ;
    ans := Set{ans, cur}->min()) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,c1=map(int,input().split())
d=[]
c=[]
for i in range(c1):
    di=list(map(int,input().split()))
    d.append(di)
for i in range(n):
    ci=list(map(int,input().split()))
    c.append(ci)
    for j in range(n):
        c[i][j]-=1
cost_c=[[0]*c1 for i in range(3)]
for t in range(n*n):
    i=t//n
    j=t % n
    md=(i+j)% 3
    for cy in range(c1):
        try :
            cx=c[i][j]
            cost=d[cx][cy]
            cost_c[md][cy]+=cost
        except :
            print(d,cx,cy)
ans=10**10
for x in range(c1):
    for y in range(c1):
        if x==y :
            continue
        for z in range(c1):
            if x==z or y==z :
                continue
            ans=min(ans,cost_c[0][x]+cost_c[1][y]+cost_c[2][z])
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var c1 : OclAny := null;
    Sequence{n,c1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var d : Sequence := Sequence{} ;
    var c : Sequence := Sequence{} ;
    for i : Integer.subrange(0, c1-1) do (    var di : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute ((di) : d)) ;
    for i : Integer.subrange(0, n-1) do (    var ci : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute ((ci) : c) ;
    for j : Integer.subrange(0, n-1) do (    c[i+1][j+1] := c[i+1][j+1] - 1)) ;
    var cost_c : Sequence := Integer.subrange(0, 3-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, c1))) ;
    for t : Integer.subrange(0, n * n-1) do (    var i : int := t div n ;
    var j : int := t mod n ;
    var md : int := (i + j) mod 3 ;
    for cy : Integer.subrange(0, c1-1) do (    try (    var cx : OclAny := c[i+1][j+1] ;
    var cost : OclAny := d[cx+1][cy+1] ;
    cost_c[md+1][cy+1] := cost_c[md+1][cy+1] + cost)
     catch (_e : OclException) do (    execute (d)->display())
)) ;
    var ans : double := (10)->pow(10) ;
    for x : Integer.subrange(0, c1-1) do (    for y : Integer.subrange(0, c1-1) do (    if x = y then (
      continue
    ) else skip ;
    for z : Integer.subrange(0, c1-1) do (    if x = z or y = z then (
      continue
    ) else skip ;
    ans := Set{ans, cost_c->first()[x+1] + cost_c[1+1][y+1] + cost_c[2+1][z+1]}->min()))) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
k,x=map(int,input().split())
if k*500>=x :
    print("Yes")
else :
    print("No")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var k : OclAny := null;
    var x : OclAny := null;
    Sequence{k,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if (k * 500->compareTo(x)) >= 0 then  (
      execute ("Yes")->display()
    )
    else (
      execute ("No")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys,re,os
from collections import deque,defaultdict,Counter
from math import ceil,sqrt,hypot,factorial,pi,sin,cos,radians
from itertools import permutations,combinations,product,accumulate
from operator import itemgetter,mul
from copy import deepcopy
from string import ascii_lowercase,ascii_uppercase,digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int,input().split())
def S_MAP(): return map(str,input().split())
def LIST(): return list(map(int,input().split()))
def S_LIST(): return list(map(str,input().split()))
sys.setrecursionlimit(10**9)
INF=float('inf')
mod=10**9+7
def gcd(a,b):
    if a=x :
    print("Yes")
else :
    print("No")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    sys.setrecursionlimit((10)->pow(9)) ;
    var INF : double := ("" + (('inf')))->toReal() ;
    var mod : double := (10)->pow(9) + 7 ;
    skip ;
    skip ;
    var k : OclAny := null;
    var x : OclAny := null;
    Sequence{k,x} := MAP() ;
    a := 500 * k ;
    if (a->compareTo(x)) >= 0 then  (
      execute ("Yes")->display()
    )
    else (
      execute ("No")->display()
      );
  operation input() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine()->trim();
  operation INT() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation MAP() : OclAny
  pre: true post: true
  activity:
    return (input().split())->collect( _x | (OclType["int"])->apply(_x) );
  operation S_MAP() : OclAny
  pre: true post: true
  activity:
    return (input().split())->collect( _x | (OclType["String"])->apply(_x) );
  operation LIST() : OclAny
  pre: true post: true
  activity:
    return ((input().split())->collect( _x | (OclType["int"])->apply(_x) ));
  operation S_LIST() : OclAny
  pre: true post: true
  activity:
    return ((input().split())->collect( _x | (OclType["String"])->apply(_x) ));
  operation gcd(a : OclAny, b : OclAny) : OclAny
  pre: true post: true
  activity:
    if (a->compareTo(b)) < 0 then (
      Sequence{a,b} := Sequence{b,a}
    ) else skip ;
    while a mod b /= 0 do (    Sequence{a,b} := Sequence{b,a mod b}) ;
    return b;
  operation lcm(a : OclAny, b : OclAny) : OclAny
  pre: true post: true
  activity:
    var y : double := a * b / gcd(a, b) ;
    return ("" + ((y)))->toInteger();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
stdin=sys.stdin
ni=lambda : int(ns())
na=lambda : list(map(int,stdin.readline().split()))
ns=lambda : stdin.readline().rstrip()
k,x=na()
print('Yes')if 500*k>=x else print('No')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var stdin : OclFile := OclFile["System.in"] ;
    var ni : Function := lambda $$ : OclAny in (("" + ((ns())))->toInteger()) ;
    var na : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ;
    var ns : Function := lambda $$ : OclAny in (stdin.readLine().rstrip()) ;
    var k : OclAny := null;
    var x : OclAny := null;
    Sequence{k,x} := na->apply() ;
(test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'Yes'))))))) )))))) if (logical_test (comparison (comparison (expr (expr (atom (number (integer 500)))) * (expr (atom (name k))))) >= (comparison (expr (atom (name x)))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'No'))))))) ))))))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def f(s):
    for i in range(1,len(s)):
        if s[i]toInteger() ;
    f((OclFile["System.in"]).readLine());
  operation f(s : OclAny)
  pre: true post: true
  activity:
    for i : Integer.subrange(1, (s)->size()-1) do (    if (s[i+1]->compareTo(s[i - 1+1])) < 0 then (
      execute ("YES")->display() ;
    execute (i)->display() ;
    return
    ) else skip) ;
    execute ('NO')->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def getMinNum(a,b,c):
    if(cb):
        return c
    x=((b//c)*c)+c
    return x
a,b,c=2,4,4
print(getMinNum(a,b,c))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    Sequence{a,b,c} := Sequence{2,4,4} ;
    execute (getMinNum(a, b, c))->display();
  operation getMinNum(a : OclAny, b : OclAny, c : OclAny) : OclAny
  pre: true post: true
  activity:
    if ((c->compareTo(a)) < 0 or (c->compareTo(b)) > 0) then (
      return c
    ) else skip ;
    var x : double := ((b div c) * c) + c ;
    return x;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
YES="Yes"
NO="No"
def solve(K : int,X : int):
    if 500*K>=X :
        print(YES)
    else :
        print(NO)
    return
def main():
    def iterate_tokens():
        for line in sys.stdin :
            for word in line.split():
                yield word
    tokens=iterate_tokens()
    K=int(next(tokens))
    X=int(next(tokens))
    solve(K,X)
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var YES : String := "Yes" ;
    var NO : String := "No" ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation solve(K : int, X : int)
  pre: true post: true
  activity:
    if (500 * K->compareTo(X)) >= 0 then  (
      execute (YES)->display()
    )
    else (
      execute (NO)->display()
      ) ;
    return;
  operation main()
  pre: true post: true
  activity:
    skip ;
    var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ;
    var K : int := ("" + (((tokens).next())))->toInteger() ;
    var X : int := ("" + (((tokens).next())))->toInteger() ;
    solve(K, X);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from functools import lru_cache
import sys
sys.setrecursionlimit(10**8)
K,X=map(int,input().split())
@ lru_cache(maxsize=None)
def dp(k,x):
    if k*500pow(8)) ;
    var K : OclAny := null;
    var X : OclAny := null;
    Sequence{K,X} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
(compound_stmt (decorator @ (dotted_name (name lru_cache)) ( (arglist (argument (test (logical_test (comparison (expr (atom (name maxsize)))))) = (test (logical_test (comparison (expr (atom None))))))) )) (funcdef def (name dp) ( (typedargslist (def_parameters (def_parameter (named_parameter (name k))) , (def_parameter (named_parameter (name x))))) ) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name k))) * (expr (atom (number (integer 500)))))) < (comparison (expr (atom (name x))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name result)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom 'No')))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name result)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom 'Yes'))))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name result))))))))))))) ;
    execute (dp(K, X))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
if __name__=="__main__" :
    inFile=open("A-large.in","r")
    outFile=open("realtest.out","w")
    caseNum=int(inFile.readline())
    for i in range(1,caseNum+1):
        items=inFile.readline().replace("\n","").split(" ")
        N=int(items[0])
        K=int(items[1])
        lightFlag=1
        for j in range(N):
            if K % 2==0 :
                lightFlag=0
                break ;
            else :
                K/=2
        if lightFlag==1 :
            outFile.write("Case #%d: ON\n" %(i,))
        else :
            outFile.write("Case #%d: OFF\n" %(i,))
    outFile.close()
    inFile.close()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     if __name__ = "__main__" then (
      var inFile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("A-large.in")) ;
    var outFile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("realtest.out")) ;
    var caseNum : int := ("" + ((inFile.readLine())))->toInteger() ;
    for i : Integer.subrange(1, caseNum + 1-1) do (    var items : OclAny := inFile.readLine().replace("\n", "").split(" ") ;
    var N : int := ("" + ((items->first())))->toInteger() ;
    var K : int := ("" + ((items[1+1])))->toInteger() ;
    var lightFlag : int := 1 ;
    for j : Integer.subrange(0, N-1) do (    if K mod 2 = 0 then  (
      lightFlag := 0 ;
    break;
    )
    else (
      K := K / 2
      )) ;
    if lightFlag = 1 then  (
      outFile.write(StringLib.format("Case #%d: ON\n",Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) ,)}))
    )
    else (
      outFile.write(StringLib.format("Case #%d: OFF\n",Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) ,)}))
      )) ;
    outFile.closeFile() ;
    inFile.closeFile()
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=[]
d={}
def decode():
    global a
    n=int(input())
    a=[int(x)for x in input().split()]
    q=int(input())
    ms=[int(x)for x in input().split()]
    return n,a,q,ms
def solve(i,m):
    global a,d
    if(i,m)in d :
        return d[(i,m)]
    if a[i]==m :
        d[(i,m)]=True
        return True
    else :
        if i0 and solve(i+1,m-a[i])):
                d[(i,m)]=True
                return True
            else :
                d[(i,m)]=False
                return False
        else :
            d[(i,m)]=False
            return False
if __name__=='__main__' :
    n,a,q,ms=decode()
    for m in ms :
        if solve(0,m):
            print("yes")
        else :
            print("no")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  attribute a : OclAny;
  attribute a : OclAny;
  attribute d : OclAny;
  operation initialise()
  pre: true post: true
  activity:     var a : Sequence := Sequence{} ;
    var d : OclAny := Set{} ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      Sequence{n,a,q,ms} := decode() ;
    for m : ms do (    if solve(0, m) then  (
      execute ("yes")->display()
    )
    else (
      execute ("no")->display()
      ))
    ) else skip;
  operation decode() : OclAny
  pre: true post: true
  activity:
    skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    a := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var ms : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    return n, a, q, ms;
  operation solve(i : OclAny, m : OclAny) : OclAny
  pre: true post: true
  activity:
    skip;    skip ;
    if (d)->includes(Sequence{i, m}) then (
      return d[Sequence{i, m}+1]
    ) else skip ;
    if a[i+1] = m then  (
      d[Sequence{i, m}+1] := true ;
    return true
    )
    else (
      if (i->compareTo((a)->size() - 1)) < 0 then  (
      if solve(i + 1, m) or (m - a[i+1] > 0 & solve(i + 1, m - a[i+1])) then  (
      d[Sequence{i, m}+1] := true ;
    return true
    )
    else (
      d[Sequence{i, m}+1] := false ;
    return false
      )
    )
    else (
      d[Sequence{i, m}+1] := false ;
    return false
      )
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from __future__ import print_function
import sys
def main(filename):
    with open(filename,"r")as f :
        for case,line in enumerate(f):
            if not case :
                T=int(line.strip())
                continue
            if case>T :
                break
            N,K=(int(c)for c in line.split())
            state=K %(2**N)
            print("Case #{0}:{1}".format(case,("ON" if state==(2**N)-1 else "OFF")))
if __name__=="__main__" :
    main(sys.argv[1])
    sys.exit(0)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) ;
    sys.exit(0)
    ) else skip;
  operation main(filename : OclAny)
  pre: true post: true
  activity:
    try (var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(filename));
    for _tuple : Integer.subrange(1, (f)->size())->collect( _indx | Sequence{_indx-1, (f)->at(_indx)} ) do (var _indx : int := 1;
      var case : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var line : OclAny := _tuple->at(_indx);
      if not(case) then (
      var T : int := ("" + ((line->trim())))->toInteger() ;
    continue
    ) else skip ;
    if (case->compareTo(T)) > 0 then (
      break
    ) else skip ;
    var N : OclAny := null;
    var K : OclAny := null;
    Sequence{N,K} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name line)) (trailer . (name split) (arguments ( ))))))))} ;
    var state : int := K mod ((2)->pow(N)) ;
    execute (StringLib.interpolateStrings("Case #{0}:{1}", Sequence{case, (if state = ((2)->pow(N)) - 1 then "ON" else "OFF" endif)}))->display()))
    catch (_e : OclException) do skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def count_odd_pair(n,a):
    odd=0
    even=0
    for i in range(0,n):
        if a[i]% 2==0 :
            even=even+1
        else :
            odd=odd+1
    ans=odd*(odd-1)
    return ans
def count_even_pair(odd_product_pairs,n):
    total_pairs=(n*(n-1))
    ans=total_pairs-odd_product_pairs
    return ans
if __name__=='__main__' :
    n=6
    a=[2,4,5,9,1,8]
    odd_product_pairs=count_odd_pair(n,a)
    even_product_pairs=(count_even_pair(odd_product_pairs,n))
    print("Even Product Pairs=",even_product_pairs)
    print("Odd Product Pairs=",odd_product_pairs)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = '__main__' then (
      n := 6 ;
    a := Sequence{2}->union(Sequence{4}->union(Sequence{5}->union(Sequence{9}->union(Sequence{1}->union(Sequence{ 8 }))))) ;
    odd_product_pairs := count_odd_pair(n, a) ;
    var even_product_pairs : OclAny := (count_even_pair(odd_product_pairs, n)) ;
    execute ("Even Product Pairs=")->display() ;
    execute ("Odd Product Pairs=")->display()
    ) else skip;
  operation count_odd_pair(n : OclAny, a : OclAny) : OclAny
  pre: true post: true
  activity:
    var odd : int := 0 ;
    var even : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    if a[i+1] mod 2 = 0 then  (
      even := even + 1
    )
    else (
      odd := odd + 1
      )) ;
    var ans : double := odd * (odd - 1) ;
    return ans;
  operation count_even_pair(odd_product_pairs : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var total_pairs : double := (n * (n - 1)) ;
    ans := total_pairs - odd_product_pairs ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def countsubarray(array,n,k):
    count=0
    for i in range(0,n):
        if array[i]<=k :
            count+=1
        mul=array[i]
        for j in range(i+1,n):
            mul=mul*array[j]
            if mul<=k :
                count+=1
            else :
                break
    return count
array=[1,2,3,4]
k=10
size=len(array)
count=countsubarray(array,size,k);
print(count,end=" ")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    array := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))) ;
    k := 10 ;
    var size : int := (array)->size() ;
    count := countsubarray(array, size, k); ;
    execute (count)->display();
  operation countsubarray(array : OclAny, n : OclAny, k : OclAny) : OclAny
  pre: true post: true
  activity:
    var count : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    if (array[i+1]->compareTo(k)) <= 0 then (
      count := count + 1
    ) else skip ;
    var mul : OclAny := array[i+1] ;
    for j : Integer.subrange(i + 1, n-1) do (    mul := mul * array[j+1] ;
    if (mul->compareTo(k)) <= 0 then  (
      count := count + 1
    )
    else (
      break
      ))) ;
    return count;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def setBitNumber(n):
    n |=n>>1
    n |=n>>2
    n |=n>>4
    n |=n>>8
    n |=n>>16
    n=n+1
    return(n>>1)
n=273
print(setBitNumber(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    n := 273 ;
    execute (setBitNumber(n))->display();
  operation setBitNumber(n : OclAny) : OclAny
  pre: true post: true
  activity:
    n := n or n /(2->pow(1)) ;
    n := n or n /(2->pow(2)) ;
    n := n or n /(2->pow(4)) ;
    n := n or n /(2->pow(8)) ;
    n := n or n /(2->pow(16)) ;
    n := n + 1 ;
    return (n /(2->pow(1)));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
print('ABC' if input()=='ARC' else 'ARC')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     execute (if (OclFile["System.in"]).readLine() = 'ARC' then 'ABC' else 'ARC' endif)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop,heappush,heapify
import array
from bisect import bisect_left,bisect_right,insort_left,insort_right
from copy import deepcopy as dcopy
import itertools
sys.setrecursionlimit(10**7)
INF=10**20
GOSA=1.0/10**10
MOD=10**9+7
ALPHABETS=[chr(i)for i in range(ord('a'),ord('z')+1)]
def LI(): return[int(x)for x in sys.stdin.readline().split()]
def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return[float(x)for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N,M,first): return[[first]*M for n in range(N)]
def DP3(N,M,L,first): return[[[first]*L for n in range(M)]for _ in range(N)]
from inspect import currentframe
def solve():
    s=input()
    if s=="ABC" :
        print("ARC")
    else :
        print("ABC")
    return 0
if __name__=="__main__" :
    solve()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    sys.setrecursionlimit((10)->pow(7)) ;
    var INF : double := (10)->pow(20) ;
    var GOSA : double := 1.0 / (10)->pow(10) ;
    var MOD : double := (10)->pow(9) + 7 ;
    var ALPHABETS : Sequence := Integer.subrange(('a')->char2byte(), ('z')->char2byte() + 1-1)->select(i | true)->collect(i | ((i)->byte2char())) ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      solve()
    ) else skip;
  operation LI() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()));
  operation LI_() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1));
  operation LF() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal()));
  operation LS() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine().split();
  operation I() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation F() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toReal();
  operation DP(N : OclAny, M : OclAny, first : OclAny) : OclAny
  pre: true post: true
  activity:
    return Integer.subrange(0, N-1)->select(n | true)->collect(n | (MatrixLib.elementwiseMult(Sequence{ first }, M)));
  operation DP3(N : OclAny, M : OclAny, L : OclAny, first : OclAny) : OclAny
  pre: true post: true
  activity:
    return Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, M-1)->select(n | true)->collect(n | (MatrixLib.elementwiseMult(Sequence{ first }, L)))));
  operation solve() : OclAny
  pre: true post: true
  activity:
    var s : String := (OclFile["System.in"]).readLine() ;
    if s = "ABC" then  (
      execute ("ARC")->display()
    )
    else (
      execute ("ABC")->display()
      ) ;
    return 0;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=int(input())
S=input()
x=0
max_num=0
for i in range(N):
    if S[i]=="I" :
        x+=1
    else :
        x-=1
    if x>max_num :
        max_num=x
print(max_num)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var S : String := (OclFile["System.in"]).readLine() ;
    var x : int := 0 ;
    var max_num : int := 0 ;
    for i : Integer.subrange(0, N-1) do (    if S[i+1] = "I" then  (
      x := x + 1
    )
    else (
      x := x - 1
      ) ;
    if (x->compareTo(max_num)) > 0 then (
      max_num := x
    ) else skip) ;
    execute (max_num)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
S=input()
if S=="ABC" :
    print("ARC")
elif S=="ARC" :
    print("ABC")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var S : String := (OclFile["System.in"]).readLine() ;
    if S = "ABC" then  (
      execute ("ARC")->display()
    )
    else (if S = "ARC" then
   (
      execute ("ABC")->display()    
)
 else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def nextweek(S):
    if(S=="ABC"):
        return "ARC"
    else :
        return "ABC"
S=input()
print(nextweek(S))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    S := (OclFile["System.in"]).readLine() ;
    execute (nextweek(S))->display();
  operation nextweek(S : OclAny) : OclAny
  pre: true post: true
  activity:
    if (S = "ABC") then  (
      return "ARC"
    )
    else (
      return "ABC"
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s=input()
ret=""
if s=="ARC" :
    ret="ABC"
elif s=="ABC" :
    ret="ARC"
print(ret)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : String := (OclFile["System.in"]).readLine() ;
    var ret : String := "" ;
    if s = "ARC" then  (
      ret := "ABC"
    )
    else (if s = "ABC" then
   (
      ret := "ARC"    
)
 else skip) ;
    execute (ret)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
def sumOfDigitsFrom1ToN(n):
    if(n<10):
        return(n*(n+1)/2)
    d=(int)(math.log10(n))
    a=[0]*(d+1)
    a[0]=0
    a[1]=45
    for i in range(2,d+1):
        a[i]=a[i-1]*10+45*(int)(math.ceil(math.pow(10,i-1)))
    p=(int)(math.ceil(math.pow(10,d)))
    msd=n//p
    return(int)(msd*a[d]+(msd*(msd-1)//2)*p+msd*(1+n % p)+sumOfDigitsFrom1ToN(n % p))
n=328
print("Sum of digits in numbers from 1 to",n,"is",sumOfDigitsFrom1ToN(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    n := 328 ;
    execute ("Sum of digits in numbers from 1 to")->display();
  operation sumOfDigitsFrom1ToN(n : OclAny) : OclAny
  pre: true post: true
  activity:
    if (n < 10) then (
      return (n * (n + 1) / 2)
    ) else skip ;
    var d : OclAny := (OclType["int"])((n)->log10()) ;
    var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (d + 1)) ;
    a->first() := 0 ;
    a[1+1] := 45 ;
    for i : Integer.subrange(2, d + 1-1) do (    a[i+1] := a[i - 1+1] * 10 + 45 * (OclType["int"])(((10)->pow(i - 1))->ceil())) ;
    var p : OclAny := (OclType["int"])(((10)->pow(d))->ceil()) ;
    var msd : int := n div p ;
    return (OclType["int"])(msd * a[d+1] + (msd * (msd - 1) div 2) * p + msd * (1 + n mod p) + sumOfDigitsFrom1ToN(n mod p));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
n=int(input())
A=tuple(int(x)for x in input().split())
_=int(input())
M=tuple(int(x)for x in input().split())
S=set()
def Check(i,s):
    if i==n :
        S.add(s)
        return
    Check(i+1,s+A[i])
    Check(i+1,s)
Check(0,0)
for m in M :
    if m in S :
        print('yes')
    else :
        print('no')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var A : Sequence := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ;
    var _anon : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var M : Sequence := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ;
    var S : Set := Set{}->union(()) ;
    skip ;
    Check(0, 0) ;
    for m : M do (    if (S)->includes(m) then  (
      execute ('yes')->display()
    )
    else (
      execute ('no')->display()
      ));
  operation Check(i : OclAny, s : OclAny)
  pre: true post: true
  activity:
    if i = n then (
      execute ((s) : S) ;
    return
    ) else skip ;
    Check(i + 1, s + A[i+1]) ;
    Check(i + 1, s);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from itertools import combinations
n,k=map(int,input().split())
a=[i for i in range(n)]
rs=[]
for c in combinations(a,k):
    tmp=sum(1<collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)) ;
    var rs : Sequence := Sequence{} ;
    for c : combinations(a, k) do (    var tmp : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name i))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name c))))))))->sum() ;
    execute ((Sequence{tmp}->union(c)) : rs)) ;
    for ans : rs->sort() do (    execute (("" + ((ans->first()))) + ":")->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
readline=sys.stdin.readline
write=sys.stdout.write
N,K=map(int,readline().split())
R=[]
v=(1<>1)| y
R.sort()
for i in R :
    write("%d: %s\n" %(i," ".join(str(j)for j in range(N)if i &(1<collect( _x | (OclType["int"])->apply(_x) ) ;
    var R : Sequence := Sequence{} ;
    var v : double := (1 * (2->pow(K))) - 1 ;
    while (v->compareTo((1 * (2->pow(N))))) < 0 do (    execute ((v) : R) ;
    var x : int := MathLib.bitwiseAnd(v, -v);    var y : OclAny := v + x ;
    v := MathLib.bitwiseOr(((MathLib.bitwiseAnd(v, MathLib.bitwiseNot(y))) div x /(2->pow(1))), y)) ;
    R := R->sort() ;
    for i : R do (    write(StringLib.format("%d: %s\n",Sequence{i, StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) ))))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (expr (atom (name i))) & (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name j)))))))) ))))))))))), " ")})));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def combination(n,k):
    def _combination(i,j,a):
        if i>n :
            return
        if j==0 :
            yield nums(n,a)
        elif i<=n :
            yield from _combination(i+1,j-1,a | 1<select(n | MathLib.bitwiseAnd(bit, (1 * (2->pow(n)))))->collect(n | (n));
  operation bit(nums : OclAny) : OclAny
  pre: true post: true
  activity:
    return ((argument (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name n))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name nums))))))))->sum();
  operation run()
  pre: true post: true
  activity:
    Sequence{n,k} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    for ns : combination(n, k)->sortedBy($x | (bit)->apply($x)) do (    execute (StringLib.interpolateStrings("{}:{}", Sequence{bit(ns), StringLib.sumStringsWithSeparator((ns->select(i | true)->collect(i | (("" + ((i)))))), " ")}))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import itertools
n,k=map(int,input().split())
N=[i for i in range(n)]
All=list(itertools.combinations(N,k))
Calc=[sum([2**All[i][j]for j in range(k)])for i in range(len(All))]
Calc_sort=sorted(Calc)
if k==0 :
    print("0:")
else :
    while len(All)!=0 :
        c=Calc_sort[0]
        x=Calc.index(c)
        print(str(c)+": "+' '.join(map(str,All[x])))
        All.pop(x)
        Calc.pop(x)
        Calc_sort.pop(0)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var N : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)) ;
    var All : Sequence := (itertools.combinations(N, k)) ;
    var Calc : Sequence := Integer.subrange(0, (All)->size()-1)->select(i | true)->collect(i | ((Integer.subrange(0, k-1)->select(j | true)->collect(j | ((2)->pow(All[i+1][j+1]))))->sum())) ;
    var Calc_sort : Sequence := Calc->sort() ;
    if k = 0 then  (
      execute ("0:")->display()
    )
    else (
      while (All)->size() /= 0 do (    var c : OclAny := Calc_sort->first() ;
    var x : int := Calc->indexOf(c) - 1 ;
    execute (("" + ((c))) + ": " + StringLib.sumStringsWithSeparator(((All[x+1])->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ;
    All := All->excludingAt(x+1) ;
    Calc := Calc->excludingAt(x+1) ;
    Calc_sort := Calc_sort->excludingAt(0+1))
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,k=map(int,input().split())
ans=[]
for i in range(2**n):
    cnt=0
    for j in range(n):
        if i>>j & 1==1 :
            cnt+=1
    if cnt==k :
        st=[]
        for t in range(n):
            if i>>t & 1==1 :
                st.append(t)
        print("{}:".format(i),end=" ")
        print(*st)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var ans : Sequence := Sequence{} ;
    for i : Integer.subrange(0, (2)->pow(n)-1) do (    var cnt : int := 0 ;
    for j : Integer.subrange(0, n-1) do (    if MathLib.bitwiseAnd(i /(2->pow(j)), 1) = 1 then (
      cnt := cnt + 1
    ) else skip) ;
    if cnt = k then (
      var st : Sequence := Sequence{} ;
    for t : Integer.subrange(0, n-1) do (    if MathLib.bitwiseAnd(i /(2->pow(t)), 1) = 1 then (
      execute ((t) : st)
    ) else skip) ;
    execute (StringLib.interpolateStrings("{}:", Sequence{i}))->display() ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name st))))))))->display()
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys,re
from collections import deque,defaultdict,Counter
from math import ceil,sqrt,hypot,factorial,pi,sin,cos,radians
from itertools import permutations,combinations,product
from operator import itemgetter,mul
from copy import deepcopy
from string import ascii_lowercase,ascii_uppercase,digits
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LIST(): return list(map(int,input().split()))
sys.setrecursionlimit(10**9)
INF=float('inf')
MOD=10**9+7
N=INT()
S=input()
x=0
ans=0
for s in S :
    if s=="I" :
        x+=1
    else :
        x-=1
    ans=max(ans,x)
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    sys.setrecursionlimit((10)->pow(9)) ;
    var INF : double := ("" + (('inf')))->toReal() ;
    var MOD : double := (10)->pow(9) + 7 ;
    var N : OclAny := INT() ;
    var S : String := (OclFile["System.in"]).readLine() ;
    var x : int := 0 ;
    var ans : int := 0 ;
    for s : S->characters() do (    if s = "I" then  (
      x := x + 1
    )
    else (
      x := x - 1
      ) ;
    ans := Set{ans, x}->max()) ;
    execute (ans)->display();
  operation input() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine()->trim();
  operation INT() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation MAP() : OclAny
  pre: true post: true
  activity:
    return (input().split())->collect( _x | (OclType["int"])->apply(_x) );
  operation LIST() : OclAny
  pre: true post: true
  activity:
    return ((input().split())->collect( _x | (OclType["int"])->apply(_x) ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
INF=10e10
H,W=[int(n)for n in input().split()]
c=[["" for __ in range(W)]for _ in range(H)]
B=set()
for i in range(H):
    c[i]=list(str(input()))
    for j in range(W):
        if c[i][j]=="B" :
            B.add((i,j))
a=0
b=INF
c=0
d=INF
for e in B :
    a=max(e[0]+e[1],a)
    b=min(e[0]+e[1],b)
    c=max(e[0]-e[1],c)
    d=min(e[0]-e[1],d)
print(max(a-b,c-d))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var INF : double := ("10e10")->toReal() ;
    var H : OclAny := null;
    var W : OclAny := null;
    Sequence{H,W} := input().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ;
    var c : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, W-1)->select(__ | true)->collect(__ | ("")))) ;
    var B : Set := Set{}->union(()) ;
    for i : Integer.subrange(0, H-1) do (    c[i+1] := (("" + (((OclFile["System.in"]).readLine()))))->characters() ;
    for j : Integer.subrange(0, W-1) do (    if c[i+1][j+1] = "B" then (
      execute ((Sequence{i, j}) : B)
    ) else skip)) ;
    var a : int := 0 ;
    var b : OclAny := INF ;
    c := 0 ;
    var d : OclAny := INF ;
    for e : B do (    a := Set{e->first() + e[1+1], a}->max() ;
    b := Set{e->first() + e[1+1], b}->min() ;
    c := Set{e->first() - e[1+1], c}->max() ;
    d := Set{e->first() - e[1+1], d}->min()) ;
    execute (Set{a - b, c - d}->max())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
from operator import itemgetter
from fractions import gcd
from math import ceil,floor
from copy import deepcopy
from itertools import accumulate
from collections import Counter
import math
from functools import reduce
sys.setrecursionlimit(200000)
input=sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int,input().rstrip().split())
def lmi(): return list(map(int,input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args,sep=" ",end="\n"): print("debug:",*args,file=sys.stderr,sep=sep,end=end)if not __debug__ else None
H,W=mi()
S=[li()for i in range(H)]
ans=[]
for i in range(H):
    for j in range(W):
        if S[i][j]=="B" :
            ans.append((i,j))
ans.sort(key=lambda x : x[0]+x[1])
debug(ans[-1])
debug(ans[0])
tmp=abs(ans[-1][0]-ans[0][0])+abs(ans[-1][1]-ans[0][1])
ans.sort(key=lambda x : x[0]+(W-x[1]))
debug(ans[-1])
debug(ans[0])
tmp2=abs(ans[-1][0]-ans[0][0])+abs(ans[-1][1]-ans[0][1])
print(max(tmp,tmp2))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    sys.setrecursionlimit(200000) ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var H : OclAny := null;
    var W : OclAny := null;
    Sequence{H,W} := mi() ;
    var S : Sequence := Integer.subrange(0, H-1)->select(i | true)->collect(i | (li())) ;
    var ans : Sequence := Sequence{} ;
    for i : Integer.subrange(0, H-1) do (    for j : Integer.subrange(0, W-1) do (    if S[i+1][j+1] = "B" then (
      execute ((Sequence{i, j}) : ans)
    ) else skip)) ;
    ans := ans->sort() ;
    debug(ans->last()) ;
    debug(ans->first()) ;
    var tmp : double := (ans->last()->first() - ans->first()->first())->abs() + (ans->last()[1+1] - ans->first()[1+1])->abs() ;
    ans := ans->sort() ;
    debug(ans->last()) ;
    debug(ans->first()) ;
    var tmp2 : double := (ans->last()->first() - ans->first()->first())->abs() + (ans->last()[1+1] - ans->first()[1+1])->abs() ;
    execute (Set{tmp, tmp2}->max())->display();
  operation ii() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation mi() : OclAny
  pre: true post: true
  activity:
    return (input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) );
  operation lmi() : OclAny
  pre: true post: true
  activity:
    return ((input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ));
  operation li() : OclAny
  pre: true post: true
  activity:
    return (input().rstrip());
  operation debug(args : OclAny : Sequence(OclAny), sep : String, end : String)
  pre: true post: true
  activity:
(args * (named_parameter (name args)))    if sep->oclIsUndefined() then sep := " " else skip;
    if end->oclIsUndefined() then end := "\n" else skip;
(test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "debug:")))))) , (argument * (test (logical_test (comparison (expr (atom (name args))))))) , (argument (test (logical_test (comparison (expr (atom (name file)))))) = (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stderr))))))) , (argument (test (logical_test (comparison (expr (atom (name sep)))))) = (test (logical_test (comparison (expr (atom (name sep))))))) , (argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom (name end)))))))) )))))) if (logical_test not (logical_test (comparison (expr (atom (name __debug__)))))) else (test (logical_test (comparison (expr (atom None))))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
H,W=map(int,input().split())
MAP=[list(input())for i in range(H)]
BLIST=[]
for i in range(H):
    for j in range(W):
        if MAP[i][j]=="B" :
            BLIST.append([i,j])
BLIST.sort(key=lambda x : x[0]+x[1])
ANS=abs(BLIST[0][0]-BLIST[-1][0])+abs(BLIST[0][1]-BLIST[-1][1])
BLIST.sort(key=lambda x : x[0]-x[1])
ANS=max(ANS,abs(BLIST[0][0]-BLIST[-1][0])+abs(BLIST[0][1]-BLIST[-1][1]))
print(ANS)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var H : OclAny := null;
    var W : OclAny := null;
    Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var MAP : Sequence := Integer.subrange(0, H-1)->select(i | true)->collect(i | (((OclFile["System.in"]).readLine())->characters())) ;
    var BLIST : Sequence := Sequence{} ;
    for i : Integer.subrange(0, H-1) do (    for j : Integer.subrange(0, W-1) do (    if MAP[i+1][j+1] = "B" then (
      execute ((Sequence{i}->union(Sequence{ j })) : BLIST)
    ) else skip)) ;
    BLIST := BLIST->sort() ;
    var ANS : double := (BLIST->first()->first() - BLIST->last()->first())->abs() + (BLIST->first()[1+1] - BLIST->last()[1+1])->abs() ;
    BLIST := BLIST->sort() ;
    ANS := Set{ANS, (BLIST->first()->first() - BLIST->last()->first())->abs() + (BLIST->first()[1+1] - BLIST->last()[1+1])->abs()}->max() ;
    execute (ANS)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
H,W=map(int,input().split())
s=[]
for k in range(H):
    s.append(input())
m1=float("inf")
M1=0
m2=float("inf")
M2=0
for k in range(H):
    for l in range(W):
        if s[k][l]=="B" :
            m1=min(m1,k+l)
            M1=max(M1,k+l)
            m2=min(m2,W-1-l+k)
            M2=max(M2,W-1-l+k)
print(max(M1-m1,M2-m2))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var H : OclAny := null;
    var W : OclAny := null;
    Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var s : Sequence := Sequence{} ;
    for k : Integer.subrange(0, H-1) do (    execute (((OclFile["System.in"]).readLine()) : s)) ;
    var m1 : double := ("" + (("inf")))->toReal() ;
    var M1 : int := 0 ;
    var m2 : double := ("" + (("inf")))->toReal() ;
    var M2 : int := 0 ;
    for k : Integer.subrange(0, H-1) do (    for l : Integer.subrange(0, W-1) do (    if s[k+1][l+1] = "B" then (
      m1 := Set{m1, k + l}->min() ;
    M1 := Set{M1, k + l}->max() ;
    m2 := Set{m2, W - 1 - l + k}->min() ;
    M2 := Set{M2, W - 1 - l + k}->max()
    ) else skip)) ;
    execute (Set{M1 - m1, M2 - m2}->max())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def inpl(): return list(map(int,input().split()))
H,W=inpl()
ans=0
C=[input()for _ in range(H)]
for i in range(2):
    L=[0]*H
    R=[0]*H
    Lk=[]
    Rk=[]
    for h in range(H):
        L[h]=C[h].find("B")
        R[h]=C[h].rfind("B")
        if L[h]>=0 :
            Lk.append(h)
        if R[h]>=0 :
            Rk.append(h)
    for lh in Lk :
        for rh in Rk :
            ans=max(ans,abs(L[lh]-R[rh])+abs(lh-rh))
    if i==0 :
        C=["".join(c)for c in zip(*C)]
        H,W=W,H
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var H : OclAny := null;
    var W : OclAny := null;
    Sequence{H,W} := inpl() ;
    var ans : int := 0 ;
    var C : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ;
    for i : Integer.subrange(0, 2-1) do (    var L : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, H) ;
    var R : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, H) ;
    var Lk : Sequence := Sequence{} ;
    var Rk : Sequence := Sequence{} ;
    for h : Integer.subrange(0, H-1) do (    L[h+1] := C[h+1]->indexOf("B") - 1 ;
    R[h+1] := C[h+1].rfind("B") ;
    if L[h+1] >= 0 then (
      execute ((h) : Lk)
    ) else skip ;
    if R[h+1] >= 0 then (
      execute ((h) : Rk)
    ) else skip) ;
    for lh : Lk do (    for rh : Rk do (    ans := Set{ans, (L[lh+1] - R[rh+1])->abs() + (lh - rh)->abs()}->max())) ;
    if i = 0 then (
      C := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name C)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name C)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name C)))))))`third->at(_indx)} )->select(c | true)->collect(c | (StringLib.sumStringsWithSeparator((c), ""))) ;
    var H : OclAny := null;
    var W : OclAny := null;
    Sequence{H,W} := Sequence{W,H}
    ) else skip) ;
    execute (ans)->display();
  operation inpl() : OclAny
  pre: true post: true
  activity:
    return ((input().split())->collect( _x | (OclType["int"])->apply(_x) ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def second_problem():
    length=int(input())
    numbers_array :[int]=list(map(lambda n : int(n),input().split(' ')))
    questions_len=int(input())
    questions :[int]=list(map(lambda n : int(n),input().split(' ')))
    answers :[str]=['no']*questions_len
    for state in range(pow(2,length)):
        bit_arr=[(state>>x)& 1 for x in range(length)]
        state_val=sum([val*bit for val,bit in zip(numbers_array,bit_arr)])
        for q_index in range(len(questions)):
            q=questions[q_index]
            if q==state_val :
                answers[q_index]='yes'
    for ans in answers :
        print(ans)
second_problem()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    second_problem();
  operation second_problem()
  pre: true post: true
  activity:
    var length : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var numbers_array : Sequence := ((input().split(' '))->collect( _x | (lambda n : OclAny in (("" + ((n)))->toInteger()))->apply(_x) )) ;
    var questions_len : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var questions : Sequence := ((input().split(' '))->collect( _x | (lambda n : OclAny in (("" + ((n)))->toInteger()))->apply(_x) )) ;
    var answers : Sequence := MatrixLib.elementwiseMult(Sequence{ 'no' }, questions_len) ;
    for state : Integer.subrange(0, (2)->pow(length)-1) do (    var bit_arr : Sequence := Integer.subrange(0, length-1)->select(x | true)->collect(x | (MathLib.bitwiseAnd((state /(2->pow(x))), 1))) ;
    var state_val : OclAny := (Integer.subrange(1, numbers_array->size())->collect( _indx | Sequence{numbers_array->at(_indx), bit_arr->at(_indx)} )->select(_tuple | true)->collect(_tuple | let val : OclAny = _tuple->at(1) in let bit : OclAny = _tuple->at(2) in (val * bit)))->sum() ;
    for q_index : Integer.subrange(0, (questions)->size()-1) do (    var q : OclAny := questions[q_index+1] ;
    if q = state_val then (
      answers[q_index+1] := 'yes'
    ) else skip)) ;
    for ans : answers do (    execute (ans)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def isDivisiblePalindrome(n):
    hash=[0]*10
    digitSum=0
    while(n):
        digitSum+=n % 10
        hash[n % 10]+=1
        n//=10
    if(digitSum % 3!=0):
        return False
    oddCount=0
    for i in range(10):
        if(hash[i]% 2!=0):
            oddCount+=1
    if(oddCount>1):
        return False
    else :
        return True
n=34734
if(isDivisiblePalindrome(n)):
    print("True")
else :
    print("False")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    n := 34734 ;
    if (isDivisiblePalindrome(n)) then  (
      execute ("True")->display()
    )
    else (
      execute ("False")->display()
      );
  operation isDivisiblePalindrome(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var hash : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ;
    var digitSum : int := 0 ;
    while (n) do (    digitSum := digitSum + n mod 10 ;
    hash[n mod 10+1] := hash[n mod 10+1] + 1 ;
    n := n div 10) ;
    if (digitSum mod 3 /= 0) then (
      return false
    ) else skip ;
    var oddCount : int := 0 ;
    for i : Integer.subrange(0, 10-1) do (    if (hash[i+1] mod 2 /= 0) then (
      oddCount := oddCount + 1
    ) else skip) ;
    if (oddCount > 1) then  (
      return false
    )
    else (
      return true
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=5
def func(idx,cur,a,dp,n,x):
    if(idx==n):
        return 0
    if(dp[idx][cur]!=-1):
        return dp[idx][cur]
    ans=0
    if(cur==0):
        ans=max(ans,a[idx]+func(idx+1,0,a,dp,n,x))
        ans=max(ans,x*a[idx]+func(idx+1,1,a,dp,n,x))
    elif(cur==1):
        ans=max(ans,x*a[idx]+func(idx+1,1,a,dp,n,x))
        ans=max(ans,a[idx]+func(idx+1,2,a,dp,n,x))
    else :
        ans=max(ans,a[idx]+func(idx+1,2,a,dp,n,x))
    dp[idx][cur]=ans
    return dp[idx][cur]
def getMaximumSum(a,n,x):
    dp=[[-1 for i in range(3)]for j in range(n)]
    maxi=0
    for i in range(0,n):
        maxi=max(maxi,func(i,0,a,dp,n,x))
    return maxi
a=[-3,8,-2,1,-6]
n=len(a)
x=-1
print(getMaximumSum(a,n,x))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : int := 5 ;
    skip ;
    skip ;
    a := Sequence{-3}->union(Sequence{8}->union(Sequence{-2}->union(Sequence{1}->union(Sequence{ -6 })))) ;
    n := (a)->size() ;
    x := -1 ;
    execute (getMaximumSum(a, n, x))->display();
  operation func(idx : OclAny, cur : OclAny, a : OclAny, dp : OclAny, n : OclAny, x : OclAny) : OclAny
  pre: true post: true
  activity:
    if (idx = n) then (
      return 0
    ) else skip ;
    if (dp[idx+1][cur+1] /= -1) then (
      return dp[idx+1][cur+1]
    ) else skip ;
    var ans : int := 0 ;
    if (cur = 0) then  (
      ans := Set{ans, a[idx+1] + func(idx + 1, 0, a, dp, n, x)}->max() ;
    ans := Set{ans, x * a[idx+1] + func(idx + 1, 1, a, dp, n, x)}->max()
    )
    else (if (cur = 1) then
   (
      ans := Set{ans, x * a[idx+1] + func(idx + 1, 1, a, dp, n, x)}->max() ;
    ans := Set{ans, a[idx+1] + func(idx + 1, 2, a, dp, n, x)}->max()    
)
    else (
      ans := Set{ans, a[idx+1] + func(idx + 1, 2, a, dp, n, x)}->max()
      )    )
 ;
    dp[idx+1][cur+1] := ans ;
    return dp[idx+1][cur+1];
  operation getMaximumSum(a : OclAny, n : OclAny, x : OclAny) : OclAny
  pre: true post: true
  activity:
    dp := Integer.subrange(0, n-1)->select(j | true)->collect(j | (Integer.subrange(0, 3-1)->select(i | true)->collect(i | (-1)))) ;
    var maxi : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    maxi := Set{maxi, func(i, 0, a, dp, n, x)}->max()) ;
    return maxi;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
abc=input().split()
if abc[0]!=abc[1]:
    if abc[0]!=abc[2]:
        print(abc[0])
    else :
        print(abc[1])
else :
    print(abc[2])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var abc : OclAny := input().split() ;
    if abc->first() /= abc[1+1] then  (
      if abc->first() /= abc[2+1] then  (
      execute (abc->first())->display()
    )
    else (
      execute (abc[1+1])->display()
      )
    )
    else (
      execute (abc[2+1])->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
a,b,c=(int(x)for x in sys.stdin.readline().split())
if a==b :
    print(c)
elif b==c :
    print(a)
elif c==a :
    print(b)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin)) (trailer . (name readline) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ;
    if a = b then  (
      execute (c)->display()
    )
    else (if b = c then
   (
      execute (a)->display()    
)
    else (if c = a then
   (
      execute (b)->display()    
)
    else skip    )
    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
input()
ans,x=0,0
for c in input():
    x+={'I' : 1,'D' :-1}[c]
    ans=max(ans,x)
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     input() ;
    var ans : OclAny := null;
    var x : OclAny := null;
    Sequence{ans,x} := Sequence{0,0} ;
    for c : (OclFile["System.in"]).readLine() do (    x := x + Map{ 'I' |-> 1 }->union(Map{ 'D' |-> -1 })[c+1] ;
    var ans : OclAny := Set{ans, x}->max()) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
ABC=list(map(int,input().split()))
for i in range(2):
    for j in range(i+1,3):
        if ABC[i]==ABC[j]:
            onaji=ABC[i]
            break
print(sum(ABC)-onaji*2)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var ABC : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    for i : Integer.subrange(0, 2-1) do (    for j : Integer.subrange(i + 1, 3-1) do (    if ABC[i+1] = ABC[j+1] then (
      var onaji : OclAny := ABC[i+1] ;
    break
    ) else skip)) ;
    execute ((ABC)->sum() - onaji * 2)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b,c=map(int,input().split())
print([a,b,c][(a==c)+2*(a==b)])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (Sequence{a}->union(Sequence{b}->union(Sequence{ c }))->select((a = c) + 2 * (a = b)))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
a,b,c=map(int,sys.stdin.readline().split())
def main():
    if a==b :
        return c
    elif b==c :
        return a
    else :
        return b
if __name__=='__main__' :
    ans=main()
    print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    skip ;
    if __name__ = '__main__' then (
      var ans : OclAny := main() ;
    execute (ans)->display()
    ) else skip;
  operation main() : OclAny
  pre: true post: true
  activity:
    if a = b then  (
      return c
    )
    else (if b = c then
   (
      return a    
)
    else (
      return b
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,k,m=map(int,input().split())
d={}
arr,cost=input().split(),tuple(map(int,input().split()))
for _ in ' '*k :
    tmp=tuple(map(int,input().split()))
    if len(tmp)==2 : a,b=tmp ; d[arr[b-1]]=cost[b-1]
    else :
        tmp=tmp[1 :]
        mn=1000000001
        for i in tmp : mn=min(mn,cost[i-1])
        for i in tmp : d.setdefault(arr[i-1],1000000001); d[arr[i-1]]=min(d[arr[i-1]],mn)
res=0
for i in input().split(): res+=d[i]
print(res)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var k : OclAny := null;
    var m : OclAny := null;
    Sequence{n,k,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var d : OclAny := Set{} ;
    var arr : OclAny := null;
    var cost : OclAny := null;
    Sequence{arr,cost} := Sequence{input().split(),((input().split())->collect( _x | (OclType["int"])->apply(_x) ))} ;
    for _anon : StringLib.nCopies(' ', k) do (    var tmp : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if (tmp)->size() = 2 then  (
      var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := tmp;    d[arr[b - 1+1]+1] := cost[b - 1+1]
    )
    else (
      tmp := tmp->tail() ;
    var mn : int := 1000000001 ;
    for i : tmp do (    mn := Set{mn, cost[i - 1+1]}->min()) ;
    for i : tmp do (    d.setdefault(arr[i - 1+1], 1000000001);    d[arr[i - 1+1]+1] := Set{d[arr[i - 1+1]+1], mn}->min())
      )) ;
    var res : int := 0 ;
    for i : input().split() do (    res := res + d[i+1]) ;
    execute (res)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
j=lambda : input().split()
r=lambda : map(int,j())
n,k,m=r()
w=j()
d=dict(zip(w,r()))
for f in[0]*k :
    x=list(r())[1 :]; c=min(d[w[i-1]]for i in x)
    for i in x : d[w[i-1]]=c
print(sum(d[x]for x in j()))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var j : Function := lambda $$ : OclAny in (input().split()) ;
    var r : Function := lambda $$ : OclAny in ((j->apply())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var n : OclAny := null;
    var k : OclAny := null;
    var m : OclAny := null;
    Sequence{n,k,m} := r->apply() ;
    var w : OclAny := j->apply() ;
    var d : Map := ((expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name w))))))) , (argument (test (logical_test (comparison (expr (atom (name r)) (trailer (arguments ( ))))))))) ))))) ;
    for f : MatrixLib.elementwiseMult(Sequence{ 0 }, k) do (    var x : OclAny := OclType["Sequence"](r->apply())->tail();    var c : OclAny := ((argument (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])))))))) ])))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name x))))))))->min() ;
    for i : x do (    d[w[i - 1+1]+1] := c)) ;
    execute (((argument (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name j)) (trailer (arguments ( )))))))))->sum())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
n,k,_=map(int,input().split())
words={x : i for i,x in enumerate(input().split())}
a=list(map(int,input().split()))
for _ in range(k):
    group=[int(x)-1 for x in input().split()[1 :]]
    c=min(a[x]for x in group)
    for x in group :
        a[x]=c
print(sum(a[words[x]]for x in input().split()))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    var n : OclAny := null;
    var k : OclAny := null;
    var _anon : OclAny := null;
    Sequence{n,k,_anon} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var words : Map := Integer.subrange(1, (input().split())->size())->collect( _indx | Sequence{_indx-1, (input().split())->at(_indx)} )->select(_tuple | true)->collect(_tuple | Map{x |-> i})->unionAll() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    for _anon : Integer.subrange(0, k-1) do (    var group : Sequence := input().split()->tail()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)) ;
    var c : OclAny := ((argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name group))))))))->min() ;
    for x : group do (    a[x+1] := c)) ;
    execute (((argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name words)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))))))) ])))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( )))))))))->sum())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
fin=sys.stdin
n=int(fin.readline())
A=list(map(int,fin.readline().split()))
q=int(fin.readline())
m_list=list(map(int,fin.readline().split()))
for m in m_list :
    can_compose=False
    s=[[]for i in range(n)]
    for i in range(n):
        s[i]=[False for i in range(m+1)]
    for j in range(m+1):
        if j==A[0]:
            s[0][j]=True
        else :
            s[0][j]=False
    if s[0][m]:
        can_compose=True
    if not can_compose :
        for i in range(1,n):
            for j in range(m+1):
                if j==A[i]:
                    s[i][j]=True
                elif s[i-1][j]:
                    s[i][j]=True
                else :
                    if j-A[i]>=0 :
                        s[i][j]=s[i-1][j-A[i]]
            if s[i][m]:
                can_compose=True
                break
    if can_compose :
        print("yes")
    else :
        print("no")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var fin : OclFile := OclFile["System.in"] ;
    var n : int := ("" + ((fin.readLine())))->toInteger() ;
    var A : Sequence := ((fin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var q : int := ("" + ((fin.readLine())))->toInteger() ;
    var m_list : Sequence := ((fin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    for m : m_list do (    var can_compose : boolean := false ;
    var s : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ;
    for i : Integer.subrange(0, n-1) do (    s[i+1] := Integer.subrange(0, m + 1-1)->select(i | true)->collect(i | (false))) ;
    for j : Integer.subrange(0, m + 1-1) do (    if j = A->first() then  (
      s->first()[j+1] := true
    )
    else (
      s->first()[j+1] := false
      )) ;
    if s->first()[m+1] then (
      can_compose := true
    ) else skip ;
    if not(can_compose) then (
      for i : Integer.subrange(1, n-1) do (    for j : Integer.subrange(0, m + 1-1) do (    if j = A[i+1] then  (
      s[i+1][j+1] := true
    )
    else (if s[i - 1+1][j+1] then
   (
      s[i+1][j+1] := true    
)
    else (
      if j - A[i+1] >= 0 then (
      s[i+1][j+1] := s[i - 1+1][j - A[i+1]+1]
    ) else skip
      )    )
) ;
    if s[i+1][m+1] then (
      can_compose := true ;
    break
    ) else skip)
    ) else skip ;
    if can_compose then  (
      execute ("yes")->display()
    )
    else (
      execute ("no")->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,k,_=map(int,input().split())
index={x : i for i,x in enumerate(input().split())}
a=list(map(int,input().split()))
for _ in range(k):
    group=[int(x)-1 for x in input().split()[1 :]]
    c=min(a[x]for x in group)
    for x in group :
        a[x]=c
print(sum(a[index[x]]for x in input().split()))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var k : OclAny := null;
    var _anon : OclAny := null;
    Sequence{n,k,_anon} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var index : Map := Integer.subrange(1, (input().split())->size())->collect( _indx | Sequence{_indx-1, (input().split())->at(_indx)} )->select(_tuple | true)->collect(_tuple | Map{x |-> i})->unionAll() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    for _anon : Integer.subrange(0, k-1) do (    var group : Sequence := input().split()->tail()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)) ;
    var c : OclAny := ((argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name group))))))))->min() ;
    for x : group do (    a[x+1] := c)) ;
    execute (((argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name index)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))))))) ])))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( )))))))))->sum())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=int(input())
A=map(int,input().split())
rslt=0
curr_max=0
for a in A :
    if a>curr_max :
        curr_max=a
    else :
        rslt+=curr_max-a
print(rslt)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var A : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var rslt : int := 0 ;
    var curr_max : int := 0 ;
    for a : A do (    if (a->compareTo(curr_max)) > 0 then  (
      curr_max := a
    )
    else (
      rslt := rslt + curr_max - a
      )) ;
    execute (rslt)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import stdin
def ip(): return[int(i)for i in stdin.readline().split()]
def sp(): return[str(i)for i in stdin.readline().split()]
n=int(input())
A=ip()
k=A[0]
ans=0
for i in range(len(A)):
    k=max(k,A[i])
    ans+=(k-A[i])
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var A : OclAny := ip() ;
    var k : OclAny := A->first() ;
    var ans : int := 0 ;
    for i : Integer.subrange(0, (A)->size()-1) do (    k := Set{k, A[i+1]}->max() ;
    ans := ans + (k - A[i+1])) ;
    execute (ans)->display();
  operation ip() : OclAny
  pre: true post: true
  activity:
    return stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()));
  operation sp() : OclAny
  pre: true post: true
  activity:
    return stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def resolve():
    N=int(input())
    S=input()
    maxcnt=0
    cnt=0
    for s in S :
        if s=="I" :
            cnt+=1
        elif s=="D" :
            cnt-=1
        maxcnt=max(maxcnt,cnt)
    print(maxcnt)
if '__main__'==__name__ :
    resolve()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if '__main__' = __name__ then (
      resolve()
    ) else skip;
  operation resolve()
  pre: true post: true
  activity:
    var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var S : String := (OclFile["System.in"]).readLine() ;
    var maxcnt : int := 0 ;
    var cnt : int := 0 ;
    for s : S->characters() do (    if s = "I" then  (
      cnt := cnt + 1
    )
    else (if s = "D" then
   (
      cnt := cnt - 1    
)
 else skip) ;
    maxcnt := Set{maxcnt, cnt}->max()) ;
    execute (maxcnt)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
height_list=list(map(int,input().split()))
a=0
for i in range(n-1):
    if height_list[i]>height_list[i+1]:
        a+=height_list[i]-height_list[i+1]
        height_list[i+1]=height_list[i]
print(a)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var height_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var a : int := 0 ;
    for i : Integer.subrange(0, n - 1-1) do (    if (height_list[i+1]->compareTo(height_list[i + 1+1])) > 0 then (
      a := a + height_list[i+1] - height_list[i + 1+1] ;
    height_list[i + 1+1] := height_list[i+1]
    ) else skip) ;
    execute (a)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=int(input())
A=[int(x)for x in input().split()]
total=0
for i in range(1,N):
    d=max(A[i-1]-A[i],0)
    A[i]+=d
    total+=d
print(total)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    var total : int := 0 ;
    for i : Integer.subrange(1, N-1) do (    var d : OclAny := Set{A[i - 1+1] - A[i+1], 0}->max() ;
    A[i+1] := A[i+1] + d ;
    total := total + d) ;
    execute (total)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def input():
    return sys.stdin.readline()[:-1]
N=int(input())
A=list(map(int,input().split()))
out=0
vmax=0
for a in A :
    vmax=max(vmax,a)
    out+=vmax-a
print(out)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var out : int := 0 ;
    var vmax : int := 0 ;
    for a : A do (    vmax := Set{vmax, a}->max() ;
    out := out + vmax - a) ;
    execute (out)->display();
  operation input() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine()->front();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
MAX=256
def smallestStr(str,n):
    i,j=0,0
    chk=[0 for i in range(MAX)]
    for i in range(MAX):
        chk[i]=-1
    for i in range(n):
        if(chk[ord(str[i])]==-1):
            chk[ord(str[i])]=i
    for i in range(n):
        flag=False
        for j in range(ord(str[i])):
            if(chk[j]>chk[ord(str[i])]):
                flag=True
                break
        if(flag):
            break
    if(icharacters()->select(i | true)->collect(i | (i)) ;
    n := (OclType["String"])->size() ;
    execute (smallestStr(OclType["String"], n))->display();
  operation smallestStr(OclType["String"] : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var i : OclAny := null;
    var j : OclAny := null;
    Sequence{i,j} := Sequence{0,0} ;
    var chk : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)) ;
    for i : Integer.subrange(0, MAX-1) do (    chk[i+1] := -1) ;
    for i : Integer.subrange(0, n-1) do (    if (chk[(("" + ([i+1])))->char2byte()+1] = -1) then (
      chk[(("" + ([i+1])))->char2byte()+1] := i
    ) else skip) ;
    for i : Integer.subrange(0, n-1) do (    var flag : boolean := false ;
    for j : Integer.subrange(0, (("" + ([i+1])))->char2byte()-1) do (    if ((chk[j+1]->compareTo(chk[(("" + ([i+1])))->char2byte()+1])) > 0) then (
      flag := true ;
    break
    ) else skip) ;
    if (flag) then (
      break
    ) else skip) ;
    if ((i->compareTo(n)) < 0) then (
      var ch1 : String := (("" + ([i+1]))) ;
    var ch2 : String := (j)->byte2char() ;
    for i : Integer.subrange(0, n-1) do (    if (("" + ([i+1])) = ch1) then  (
      ("" + ([i+1])) := ch2
    )
    else (if (("" + ([i+1])) = ch2) then
   (
      ("" + ([i+1])) := ch1    
)
 else skip))
    ) else skip ;
    return StringLib.sumStringsWithSeparator((OclType["String"]), "");
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def parse_node(l,r,S):
    left,right=0,0
    cnt=0
    for i in range(l,r+1):
        if S[i]=='(' :
            cnt+=1
        elif S[i]==')' :
            cnt-=1
        elif cnt==0 and S[i]=="[" :
            left=i
        elif cnt==0 and S[i]=="]" :
            right=i
    return left,right
def parser(l1,r1,l2,r2):
    n1_l,n1_r=parse_node(l1,r1,S1)
    n2_l,n2_r=parse_node(l2,r2,S2)
    node="[{}]".format(int(S1[n1_l+1 : n1_r])+int(S2[n2_l+1 : n2_r]))
    left_node="({})".format("" if min(n1_l-l1,n2_l-l2)<=2 else parser(l1+1,n1_l-2,l2+1,n2_l-2))
    right_node="({})".format("" if min(r1-n1_r,r2-n2_r)<=2 else parser(n1_r+2,r1-1,n2_r+2,r2-1))
    return left_node+node+right_node
S1,S2=input(),input()
print(parser(0,len(S1)-1,0,len(S2)-1))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var S1 : OclAny := null;
    var S2 : OclAny := null;
    Sequence{S1,S2} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine()} ;
    execute (parser(0, (S1)->size() - 1, 0, (S2)->size() - 1))->display();
  operation parse_node(l : OclAny, r : OclAny, S : OclAny) : OclAny
  pre: true post: true
  activity:
    var left : OclAny := null;
    var right : OclAny := null;
    Sequence{left,right} := Sequence{0,0} ;
    var cnt : int := 0 ;
    for i : Integer.subrange(l, r + 1-1) do (    if S[i+1] = '(' then  (
      cnt := cnt + 1
    )
    else (if S[i+1] = ')' then
   (
      cnt := cnt - 1    
)
    else (if cnt = 0 & S[i+1] = "[" then
   (
      var left : OclAny := i    
)
    else (if cnt = 0 & S[i+1] = "]" then
   (
      var right : OclAny := i    
)
    else skip    )
    )
    )
) ;
    return left, right;
  operation parser(l1 : OclAny, r1 : OclAny, l2 : OclAny, r2 : OclAny) : OclAny
  pre: true post: true
  activity:
    var n1_l : OclAny := null;
    var n1_r : OclAny := null;
    Sequence{n1_l,n1_r} := parse_node(l1, r1, S1) ;
    var n2_l : OclAny := null;
    var n2_r : OclAny := null;
    Sequence{n2_l,n2_r} := parse_node(l2, r2, S2) ;
    var node : String := StringLib.interpolateStrings("[{}]", Sequence{("" + ((S1.subrange(n1_l + 1+1, n1_r))))->toInteger() + ("" + ((S2.subrange(n2_l + 1+1, n2_r))))->toInteger()}) ;
    var left_node : String := StringLib.interpolateStrings("({})", Sequence{if Set{n1_l - l1, n2_l - l2}->min() <= 2 then "" else parser(l1 + 1, n1_l - 2, l2 + 1, n2_l - 2) endif}) ;
    var right_node : String := StringLib.interpolateStrings("({})", Sequence{if Set{r1 - n1_r, r2 - n2_r}->min() <= 2 then "" else parser(n1_r + 2, r1 - 1, n2_r + 2, r2 - 1) endif}) ;
    return left_node + node + right_node;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def convert(S):
    cur=0
    def parse():
        nonlocal cur
        if S[cur]==')' :
            return()
        cur+=1
        left=parse()
        cur+=2
        num=0
        while S[cur]!=']' :
            num=10*num+int(S[cur])
            cur+=1
        cur+=2
        right=parse()
        cur+=1
        return left,num,right
    return parse()
def dfs(A,B):
    if not A or not B :
        return()
    return(dfs(A[0],B[0]),[A[1]+B[1]],dfs(A[2],B[2]))
print(str(dfs(convert(input()),convert(input()))).replace(",","")[1 :-1])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  attribute cur : OclAny;
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    execute (OclType["String"](dfs(convert((OclFile["System.in"]).readLine()), convert((OclFile["System.in"]).readLine()))).replace(",", "").subrange(1+1, -1))->display();
  operation convert(S : OclAny) : OclAny
  pre: true post: true
  activity:
    var cur : int := 0 ;
    skip ;
    return parse();
  operation dfs(A : OclAny, B : OclAny) : OclAny
  pre: true post: true
  activity:
    if not(A) or not(B) then (
      return ()
    ) else skip ;
    return Sequence{dfs(A->first(), B->first()), Sequence{ A[1+1] + B[1+1] }, dfs(A[2+1], B[2+1])};
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def sToTree(S):
    if len(S)==0 :
        return 'N'
    c=0
    left=0
    right=0
    for i in range(len(S)):
        if S[i]=='(' :
            c+=1
        elif S[i]==')' :
            c-=1
        elif c==0 and S[i]=='[' :
            left=i
        elif c==0 and S[i]==']' :
            right=i
            break
    return[sToTree(S[1 : left-1]),int(S[left+1 : right]),sToTree(S[right+2 : len(S)-1])]
def dfs(S1,S2):
    if S1=='N' or S2=='N' :
        return 'N'
    ret=[dfs(S1[0],S2[0]),S1[1]+S2[1],dfs(S1[2],S2[2])]
    return ret
def my_print(ans):
    if ans=='N' :
        return
    print('(',end='')
    my_print(ans[0])
    print(")[{0}](".format(ans[1]),end='')
    my_print(ans[2])
    print(')',end='')
S1=input()
S2=input()
S1=sToTree(S1)
S2=sToTree(S2)
ans=dfs(S1,S2)
my_print(ans)
print()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    S1 := (OclFile["System.in"]).readLine() ;
    S2 := (OclFile["System.in"]).readLine() ;
    S1 := sToTree(S1) ;
    S2 := sToTree(S2) ;
    ans := dfs(S1, S2) ;
    my_print(ans) ;
    execute (->display();
  operation sToTree(S : OclAny) : OclAny
  pre: true post: true
  activity:
    if (S)->size() = 0 then (
      return 'N'
    ) else skip ;
    var c : int := 0 ;
    var left : int := 0 ;
    var right : int := 0 ;
    for i : Integer.subrange(0, (S)->size()-1) do (    if S[i+1] = '(' then  (
      c := c + 1
    )
    else (if S[i+1] = ')' then
   (
      c := c - 1    
)
    else (if c = 0 & S[i+1] = '[' then
   (
      left := i    
)
    else (if c = 0 & S[i+1] = ']' then
   (
      right := i ;
    break    
)
    else skip    )
    )
    )
) ;
    return Sequence{sToTree(S.subrange(1+1, left - 1))}->union(Sequence{("" + ((S.subrange(left + 1+1, right))))->toInteger()}->union(Sequence{ sToTree(S.subrange(right + 2+1, (S)->size() - 1)) }));
  operation dfs(S1 : OclAny, S2 : OclAny) : OclAny
  pre: true post: true
  activity:
    if S1 = 'N' or S2 = 'N' then (
      return 'N'
    ) else skip ;
    var ret : Sequence := Sequence{dfs(S1->first(), S2->first())}->union(Sequence{S1[1+1] + S2[1+1]}->union(Sequence{ dfs(S1[2+1], S2[2+1]) })) ;
    return ret;
  operation my_print(ans : OclAny)
  pre: true post: true
  activity:
    if ans = 'N' then (
      return
    ) else skip ;
    execute ('(')->display() ;
    my_print(ans->first()) ;
    execute (StringLib.interpolateStrings(")[{0}](", Sequence{ans[1+1]}))->display() ;
    my_print(ans[2+1]) ;
    execute (')')->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for welnot in[*open(0)][2 : : 2]: print(int(welnot.split()[0]))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for welnot : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do (    execute (("" + ((welnot.split()->first())))->toInteger())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
class binary_tree():
    def __init__(self,value,left=None,right=None):
        self.value=value
        self.left=left
        self.right=right
def find_corres_bra(s,fr,to):
    count=0
    x=-1
    for i in range(len(s)):
        if s[i]==fr :
            count+=1
        elif s[i]==to :
            if count==1 :
                x=i
                break
            else :
                count-=1
    return x
def make_tree(s):
    if s=='' :
        return None
    x0=0
    x1=find_corres_bra(s,'(',')')+1
    x2=x1+find_corres_bra(s[x1 :],'[',']')+1
    tree=binary_tree(int(s[x1+1 : x2-1]),make_tree(s[x0+1 : x1-1]),make_tree(s[x2+1 :-1]))
    return tree
def synthe_trees(t1,t2):
    tree=binary_tree(value=t1.value+t2.value)
    if t1.left!=None and t2.left!=None :
        tree.left=synthe_trees(t1.left,t2.left)
    if t1.right!=None and t2.right!=None :
        tree.right=synthe_trees(t1.right,t2.right)
    return tree
def tree_to_str(tree):
    if tree==None :
        return ''
    ans='('+tree_to_str(tree.left)+')'+'['+str(tree.value)+']'+'('+tree_to_str(tree.right)+')'
    return ans
t1=make_tree(input())
t2=make_tree(input())
tree=synthe_trees(t1,t2)
print(tree_to_str(tree))
------------------------------------------------------------
OCL File:
---------
class binary_tree {
  static operation newbinary_tree() : binary_tree
  pre: true
  post: binary_tree->exists( _x | result = _x );
  attribute value : OclAny := value;
  attribute left : OclAny := left;
  attribute right : OclAny := right;
  operation initialise(value : OclAny,left : OclAny,right : OclAny) : 
  pre: true post: true
  activity:
    self.value := value ;
    self.left := left ;
    self.right := right;
    return self;
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    t1 := make_tree((OclFile["System.in"]).readLine()) ;
    t2 := make_tree((OclFile["System.in"]).readLine()) ;
    tree := synthe_trees(t1, t2) ;
    execute (tree_to_str(tree))->display();
  operation find_corres_bra(s : OclAny, fr : OclAny, to : OclAny) : OclAny
  pre: true post: true
  activity:
    var count : int := 0 ;
    var x : int := -1 ;
    for i : Integer.subrange(0, (s)->size()-1) do (    if s[i+1] = fr then  (
      count := count + 1
    )
    else (if s[i+1] = to then
   (
      if count = 1 then  (
      x := i ;
    break
    )
    else (
      count := count - 1
      )    
)
 else skip)) ;
    return x;
  operation make_tree(s : OclAny) : OclAny
  pre: true post: true
  activity:
    if s = '' then (
      return null
    ) else skip ;
    var x0 : int := 0 ;
    var x1 : OclAny := find_corres_bra(s, '(', ')') + 1 ;
    var x2 : OclAny := x1 + find_corres_bra(s.subrange(x1+1), '[', ']') + 1 ;
    var tree : binary_tree := (binary_tree.newbinary_tree()).initialise(("" + ((s.subrange(x1 + 1+1, x2 - 1))))->toInteger(), make_tree(s.subrange(x0 + 1+1, x1 - 1)), make_tree(s.subrange(x2 + 1+1, -1))) ;
    return tree;
  operation synthe_trees(t1 : OclAny, t2 : OclAny) : OclAny
  pre: true post: true
  activity:
    tree := (binary_tree.newbinary_tree()).initialise((argument (test (logical_test (comparison (expr (atom (name value)))))) = (test (logical_test (comparison (expr (expr (atom (name t1)) (trailer . (name value))) + (expr (atom (name t2)) (trailer . (name value))))))))) ;
    if t1.left /= null & t2.left /= null then (
      tree.left := synthe_trees(t1.left, t2.left)
    ) else skip ;
    if t1.right /= null & t2.right /= null then (
      tree.right := synthe_trees(t1.right, t2.right)
    ) else skip ;
    return tree;
  operation tree_to_str(tree : OclAny) : OclAny
  pre: true post: true
  activity:
    if tree = null then (
      return ''
    ) else skip ;
    var ans : String := '(' + tree_to_str(tree.left) + ')' + '[' + ("" + ((tree.value))) + ']' + '(' + tree_to_str(tree.right) + ')' ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def sep(S):
    l=r=0
    for i,s in enumerate(S):
        l+=s=='('
        r+=s==')'
        if l==r :
            j=S.find(']',i)
            s_l=S[1 : i]
            s_r=S[j+2 :-1]
            s_c=int(S[i+2 : j])
            break
    return s_l,s_c,s_r
def solve(A,B):
    if A=='' or B=='' :
        return ''
    a_l,a_c,a_r=sep(A)
    b_l,b_c,b_r=sep(B)
    return '(%s)[%d](%s)' %(solve(a_l,b_l),a_c+b_c,solve(a_r,b_r))
print(solve(input(),input()))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    execute (solve((OclFile["System.in"]).readLine(), (OclFile["System.in"]).readLine()))->display();
  operation sep(S : OclAny) : OclAny
  pre: true post: true
  activity:
    var l : OclAny := 0; var r : int := 0 ;
    for _tuple : Integer.subrange(1, (S)->size())->collect( _indx | Sequence{_indx-1, (S)->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var s : OclAny := _tuple->at(_indx);
      l := l + s = '(' ;
    r := r + s = ')' ;
    if l = r then (
      var j : int := S->indexOf(']', i) - 1 ;
    var s_l : OclAny := S.subrange(1+1, i) ;
    var s_r : OclAny := S.subrange(j + 2+1, -1) ;
    var s_c : int := ("" + ((S.subrange(i + 2+1, j))))->toInteger() ;
    break
    ) else skip) ;
    return s_l, s_c, s_r;
  operation solve(A : OclAny, B : OclAny) : OclAny
  pre: true post: true
  activity:
    if A = '' or B = '' then (
      return ''
    ) else skip ;
    var a_l : OclAny := null;
    var a_c : OclAny := null;
    var a_r : OclAny := null;
    Sequence{a_l,a_c,a_r} := sep(A) ;
    var b_l : OclAny := null;
    var b_c : OclAny := null;
    var b_r : OclAny := null;
    Sequence{b_l,b_c,b_r} := sep(B) ;
    return StringLib.format('(%s)[%d](%s)',Sequence{solve(a_l, b_l), a_c + b_c, solve(a_r, b_r)});
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
_=int(input())
list_X=[0]
for i in list(input()):
    if(i=='I'):
        list_X.append(list_X[-1]+1)
    else :
        list_X.append(list_X[-1]-1)
print(max(list_X))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var _anon : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var list_X : Sequence := Sequence{ 0 } ;
    for i : ((OclFile["System.in"]).readLine())->characters() do (    if (i = 'I') then  (
      execute ((list_X->last() + 1) : list_X)
    )
    else (
      execute ((list_X->last() - 1) : list_X)
      )) ;
    execute ((list_X)->max())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
modd=1000000007
def power(x,y,p):
    res=1
    x=x % p
    while(y>0):
        if(y & 1):
            res=(res*x)% p
        y=y>>1
        x=(x*x)% p
    return res
def ways(n,m):
    return power(m-1,n-1,modd)*m % modd
n,m=5,5
print(ways(n,m))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var modd : int := 1000000007 ;
    skip ;
    skip ;
    Sequence{n,m} := Sequence{5,5} ;
    execute (ways(n, m))->display();
  operation power(x : OclAny, y : OclAny, p : OclAny) : OclAny
  pre: true post: true
  activity:
    var res : int := 1 ;
    x := x mod p ;
    while (y > 0) do (    if (MathLib.bitwiseAnd(y, 1)) then (
      res := (res * x) mod p
    ) else skip ;
    y := y /(2->pow(1)) ;
    x := (x * x) mod p) ;
    return res;
  operation ways(n : OclAny, m : OclAny) : OclAny
  pre: true post: true
  activity:
    return power(m - 1, n - 1, modd) * m mod modd;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,k=map(int,input().split())
a=sorted(map(int,input().split()))
print(*(k>n and[-1]or[a[-k]]*2))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ;
    execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (logical_test (comparison (comparison (expr (atom (name k)))) > (comparison (expr (atom (name n)))))) and (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom - (number (integer 1)))))))) ]))))) or (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr - (expr (atom (name k))))))))) ]))))))) ])) * (expr (atom (number (integer 2)))))))))) ))))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,k=map(int,input().split())
arr=list(map(int,input().split()))[: n]
arr.sort()
x,y=0,0
if(k>n):
    print(-1)
else :
    x=arr[n-k]
    y=arr[n-k]
    print(x,y)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var arr : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ;
    arr := arr->sort() ;
    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := Sequence{0,0} ;
    if ((k->compareTo(n)) > 0) then  (
      execute (-1)->display()
    )
    else (
      var x : OclAny := arr[n - k+1] ;
    var y : OclAny := arr[n - k+1] ;
    execute (x)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,s=[int(x)for x in input().split()]
a=[int(x)for x in input().split()]
a=sorted(a)
if(s>n):
    print(-1)
else :
    print(a[n-s],a[n-s])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var s : OclAny := null;
    Sequence{n,s} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    a := a->sort() ;
    if ((s->compareTo(n)) > 0) then  (
      execute (-1)->display()
    )
    else (
      execute (a[n - s+1])->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import array as arr
n,k=map(int,input().split())
sq_arr=list(map(int,input().split(' ')[: n]))
sq_arr.sort(reverse=1)
if(k>n):
    print("-1")
else :
    print(sq_arr[k-1],sq_arr[k-1])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var sq_arr : Sequence := ((input().split(' ').subrange(1,n))->collect( _x | (OclType["int"])->apply(_x) )) ;
    sq_arr := sq_arr->sort() ;
    if ((k->compareTo(n)) > 0) then  (
      execute ("-1")->display()
    )
    else (
      execute (sq_arr[k - 1+1])->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,k=map(int,input().split())
a=sorted(map(int,input().split()))
print(*(k>n and[-1]or[a[-k]]*2))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ;
    execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (logical_test (comparison (comparison (expr (atom (name k)))) > (comparison (expr (atom (name n)))))) and (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom - (number (integer 1)))))))) ]))))) or (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr - (expr (atom (name k))))))))) ]))))))) ])) * (expr (atom (number (integer 2)))))))))) ))))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
A,B=map(int,input().split())
k=(A+B)//2
if(A+B)% 2==0 :
    print(k)
else :
    print("IMPOSSIBLE")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var A : OclAny := null;
    var B : OclAny := null;
    Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var k : int := (A + B) div 2 ;
    if (A + B) mod 2 = 0 then  (
      execute (k)->display()
    )
    else (
      execute ("IMPOSSIBLE")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
print((lambda x :('IMPOSSIBLE' if(x[0]+x[1])% 2==1 else(x[0]+x[1])//2))(list(map(int,input().split()))))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     execute ((lambda x : OclAny in ((if (x->first() + x[1+1]) mod 2 = 1 then 'IMPOSSIBLE' else (x->first() + x[1+1]) div 2 endif)))(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from heapq import heappush,heappop
def main():
    while True :
        n,m,s,g1,g2=map(int,input().split())
        if n==0 :
            break
        s-=1
        g1-=1
        g2-=1
        INF=10**20
        edges=[[]for _ in range(n)]
        for _ in range(m):
            b1,b2,c=map(int,input().split())
            b1-=1
            b2-=1
            edges[b1].append((b2,c))
        def dij(start):
            que=[]
            heappush(que,(0,start))
            costs=[INF]*n
            costs[start]=0
            while que :
                total,node=heappop(que)
                for to,dist in edges[node]:
                    new_total=total+dist
                    if costs[to]>new_total :
                        costs[to]=new_total
                        heappush(que,(new_total,to))
            return costs
        from_i=[dij(i)for i in range(n)]
        print(min([from_i[s][i]+from_i[i][g1]+from_i[i][g2]for i in range(n)]))
main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    main();
  operation main()
  pre: true post: true
  activity:
    while true do (    var n : OclAny := null;
    var m : OclAny := null;
    var s : OclAny := null;
    var g1 : OclAny := null;
    var g2 : OclAny := null;
    Sequence{n,m,s,g1,g2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if n = 0 then (
      break
    ) else skip ;
    s := s - 1 ;
    g1 := g1 - 1 ;
    g2 := g2 - 1 ;
    var INF : double := (10)->pow(20) ;
    var edges : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ;
    for _anon : Integer.subrange(0, m-1) do (    var b1 : OclAny := null;
    var b2 : OclAny := null;
    var c : OclAny := null;
    Sequence{b1,b2,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    b1 := b1 - 1 ;
    b2 := b2 - 1 ;
(expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b1)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name b2)))))) , (test (logical_test (comparison (expr (atom (name c))))))) )))))))) ))))) ;
    skip ;
    var from_i : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (dij(i))) ;
    execute ((Integer.subrange(0, n-1)->select(i | true)->collect(i | (from_i[s+1][i+1] + from_i[i+1][g1+1] + from_i[i+1][g2+1])))->min())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
print(*[_.split()[0]+'\n' for _ in[*open(0)][2 : : 2]])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name _)) (trailer . (name split) (arguments ( ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) + (expr (atom '
')))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom [ (testlist_comp (star_expr * (expr (atom (name open)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))))) ]) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) ]))))))) ])))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from operator import itemgetter
def protect(N,M):
    DP=[]
    for i in range(N):
        DP.append(list(map(int,input().split())))
    DP.sort(key=itemgetter(1))
    nokori=0
    for i in range(N):
        if M>DP[N-i-1][0]:
            M-=DP[N-i-1][0]
            DP.pop()
        elif M<=DP[N-i-1][0]:
            nokori=(DP[N-i-1][0]-M)*DP[N-i-1][1]
            M=0
            DP.pop()
            break
    for i in range(len(DP)):
        nokori+=DP[i][0]*DP[i][1]
    print(nokori)
while True :
    NM=input().split()
    N=int(NM[0])
    M=int(NM[1])
    if N==0 :
        break
    protect(N,M)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    while true do (    var NM : OclAny := input().split() ;
    N := ("" + ((NM->first())))->toInteger() ;
    M := ("" + ((NM[1+1])))->toInteger() ;
    if N = 0 then (
      break
    ) else skip ;
    protect(N, M));
  operation protect(N : OclAny, M : OclAny)
  pre: true post: true
  activity:
    var DP : Sequence := Sequence{} ;
    for i : Integer.subrange(0, N-1) do (    execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : DP)) ;
    DP := DP->sort() ;
    var nokori : int := 0 ;
    for i : Integer.subrange(0, N-1) do (    if (M->compareTo(DP[N - i - 1+1]->first())) > 0 then  (
      M := M - DP[N - i - 1+1]->first() ;
    DP := DP->front()
    )
    else (if (M->compareTo(DP[N - i - 1+1]->first())) <= 0 then
   (
      nokori := (DP[N - i - 1+1]->first() - M) * DP[N - i - 1+1][1+1] ;
    M := 0 ;
    DP := DP->front() ;
    break    
)
 else skip)) ;
    for i : Integer.subrange(0, (DP)->size()-1) do (    nokori := nokori + DP[i+1]->first() * DP[i+1][1+1]) ;
    execute (nokori)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=[int(x)for x in input().split()]
if a==0 and b==0 :
    print('IMPOSSIBLE')
if(a+b)% 2==0 :
    print(int((a+b)/2))
else :
    print('IMPOSSIBLE')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    if a = 0 & b = 0 then (
      execute ('IMPOSSIBLE')->display()
    ) else skip ;
    if (a + b) mod 2 = 0 then  (
      execute (("" + (((a + b) / 2)))->toInteger())->display()
    )
    else (
      execute ('IMPOSSIBLE')->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import copy
import random
import bisect
import fractions
import math
import sys
import bisect
mod=10**9+7
sys.setrecursionlimit(mod)
def LI(): return list(map(int,sys.stdin.readline().split()))
A,B=LI()
if abs(A-B)% 2==0 :
    print(abs(A-B)//2+min(A,B))
else :
    print("IMPOSSIBLE")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var mod : double := (10)->pow(9) + 7 ;
    sys.setrecursionlimit(mod) ;
    skip ;
    var A : OclAny := null;
    var B : OclAny := null;
    Sequence{A,B} := LI() ;
    if (A - B)->abs() mod 2 = 0 then  (
      execute ((A - B)->abs() div 2 + Set{A, B}->min())->display()
    )
    else (
      execute ("IMPOSSIBLE")->display()
      );
  operation LI() : OclAny
  pre: true post: true
  activity:
    return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    a,b=map(int,input().split())
    k=(a+b)/2
    if k.is_integer():
        print(int(k))
    else :
        print("IMPOSSIBLE")
if __name__=="__main__" :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var k : double := (a + b) / 2 ;
    if k.is_integer() then  (
      execute (("" + ((k)))->toInteger())->display()
    )
    else (
      execute ("IMPOSSIBLE")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m,l=map(int,input().split())
A=[]
B=[]
for i in range(n): A.append(list(map(int,input().split())))
for j in range(m): B.append(list(map(int,input().split())))
for A_r in A :
    print(" ".join(map(str,[sum([x*y for x,y in zip(A_r,[B_r[k]for B_r in B])])for k in range(l)])))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    var l : OclAny := null;
    Sequence{n,m,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var A : Sequence := Sequence{} ;
    var B : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : A)) ;
    for j : Integer.subrange(0, m-1) do (    execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : B)) ;
    for A_r : A do (    execute (StringLib.sumStringsWithSeparator(((Integer.subrange(0, l-1)->select(k | true)->collect(k | ((Integer.subrange(1, A_r->size())->collect( _indx | Sequence{A_r->at(_indx), B->select(B_r | true)->collect(B_r | (B_r[k+1]))->at(_indx)} )->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (x * y)))->sum())))->collect( _x | (OclType["String"])->apply(_x) )), " "))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=[[0 for i in range(100)]for j in range(100)]
b=[[0 for i in range(100)]for j in range(100)]
n,m,l=map(int,input().split())
for i in range(n):
    a[i][: m]=map(int,input().split())
for i in range(m):
    b[i][: l]=map(int,input().split())
for i in range(n):
    for j in range(l):
        c=0
        for k in range(m):
            c+=a[i][k]*b[k][j]
        if j==l-1 :
            break
        print(c,end=' ')
    print(c)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : Sequence := Integer.subrange(0, 100-1)->select(j | true)->collect(j | (Integer.subrange(0, 100-1)->select(i | true)->collect(i | (0)))) ;
    var b : Sequence := Integer.subrange(0, 100-1)->select(j | true)->collect(j | (Integer.subrange(0, 100-1)->select(i | true)->collect(i | (0)))) ;
    var n : OclAny := null;
    var m : OclAny := null;
    var l : OclAny := null;
    Sequence{n,m,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    for i : Integer.subrange(0, n-1) do (    a[i+1].subrange(1,m) := (input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    for i : Integer.subrange(0, m-1) do (    b[i+1].subrange(1,l) := (input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    for i : Integer.subrange(0, n-1) do (    for j : Integer.subrange(0, l-1) do (    var c : int := 0 ;
    for k : Integer.subrange(0, m-1) do (    c := c + a[i+1][k+1] * b[k+1][j+1]) ;
    if j = l - 1 then (
      break
    ) else skip ;
    execute (c)->display()) ;
    execute (c)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
n,m,l=[int(val)for val in sys.stdin.readline().split("")]
matrixA=[[int(val)for val in sys.stdin.readline().split("")]for row in range(n)]
matrixB=[[int(val)for val in sys.stdin.readline().split("")]for row in range(m)]
c=0
output=[]
for i in range(n):
    for j in range(l):
        c=0
        for k in range(m):
            c+=(matrixA[i][k]*matrixB[k][j])
        output.append("{:d}".format(c))
        output.append("")
    output.pop()
    output.append("\n")
output.pop()
print("".join(output))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : OclAny := null;
    var m : OclAny := null;
    var l : OclAny := null;
    Sequence{n,m,l} := sys.stdin.readLine().split("")->select(val | true)->collect(val | (("" + ((val)))->toInteger())) ;
    var matrixA : Sequence := Integer.subrange(0, n-1)->select(row | true)->collect(row | (sys.stdin.readLine().split("")->select(val | true)->collect(val | (("" + ((val)))->toInteger())))) ;
    var matrixB : Sequence := Integer.subrange(0, m-1)->select(row | true)->collect(row | (sys.stdin.readLine().split("")->select(val | true)->collect(val | (("" + ((val)))->toInteger())))) ;
    var c : int := 0 ;
    var output : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    for j : Integer.subrange(0, l-1) do (    c := 0 ;
    for k : Integer.subrange(0, m-1) do (    c := c + (matrixA[i+1][k+1] * matrixB[k+1][j+1])) ;
    execute ((StringLib.interpolateStrings("{:d}", Sequence{c})) : output) ;
    execute (("") : output)) ;
    output := output->front() ;
    execute (("\n") : output)) ;
    output := output->front() ;
    execute (StringLib.sumStringsWithSeparator((output), ""))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import*
from fractions import gcd
from functools import*
from itertools import*
from operator import mul
from bisect import*
from heapq import*
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**6)
def main():
    a,b,c=map(int,input().split())
    g=[list(map(int,input().split()))for i in range(a)]
    h=[list(map(int,input().split()))for i in range(b)]
    for i in zip(*[[sum(s*t for s,t in zip(g[r],[h[j][i]for j in range(b)]))for r in range(a)]for i in range(c)]):
        print(*i)
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    sys.setrecursionlimit((10)->pow(6)) ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var g : Sequence := Integer.subrange(0, a-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var h : Sequence := Integer.subrange(0, b-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    for i : Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name s))) * (expr (atom (name t))))))) (comp_for for (exprlist (expr (atom (name s))) , (expr (atom (name t)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name h)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))))))) ]))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name r)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))))))) ]))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))))))) ]))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name s))) * (expr (atom (name t))))))) (comp_for for (exprlist (expr (atom (name s))) , (expr (atom (name t)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name h)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))))))) ]))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name r)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))))))) ]))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))))))) ]))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name s))) * (expr (atom (name t))))))) (comp_for for (exprlist (expr (atom (name s))) , (expr (atom (name t)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name h)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))))))) ]))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name r)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))))))) ]))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))))))) ]))))))`third->at(_indx)} ) do (    execute ((argument * (test (logical_test (comparison (expr (atom (name i))))))))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
BIG_NUM=2000000000
MOD=1000000007
EPS=0.000000001
N,M,L=map(int,input().split())
A=[list(map(int,input().split()))for i in range(N)]
B=[list(map(int,input().split()))for i in range(M)]
ANS=[[0]*L for i in range(N)]
for x in range(N):
    for y in range(L):
        for z in range(M):
            ANS[x][y]+=B[z][y]*A[x][z]
for row in range(N):
    print("%d" % ANS[row][0],end="")
    for col in range(1,L):
        print(" %d" %(ANS[row][col]),end="")
    print()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var BIG_NUM : int := 2000000000 ;
    var MOD : int := 1000000007 ;
    var EPS : double := 0.000000001 ;
    var N : OclAny := null;
    var M : OclAny := null;
    var L : OclAny := null;
    Sequence{N,M,L} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var A : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var B : Sequence := Integer.subrange(0, M-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var ANS : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, L))) ;
    for x : Integer.subrange(0, N-1) do (    for y : Integer.subrange(0, L-1) do (    for z : Integer.subrange(0, M-1) do (    ANS[x+1][y+1] := ANS[x+1][y+1] + B[z+1][y+1] * A[x+1][z+1]))) ;
    for row : Integer.subrange(0, N-1) do (    execute (StringLib.format("%d",ANS[row+1]->first()))->display() ;
    for col : Integer.subrange(1, L-1) do (    execute (StringLib.format(" %d",(ANS[row+1][col+1])))->display()) ;
    execute (->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a=list(map(int,input().split()))
a.sort()
for i in a :
    for j in a :
        if abs(i-j)%(n-1)==0 and i!=j :
            print(i,j)
            quit()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    a := a->sort() ;
    for i : a do (    for j : a do (    if (i - j)->abs() mod (n - 1) = 0 & i /= j then (
      execute (i)->display() ;
    quit()
    ) else skip));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import itertools
n=int(input())
num=list(map(int,input().split()))
for comb in itertools.combinations(num,2):
    diff=abs(comb[0]-comb[1])
    if diff %(n-1)==0 :
        print(comb[0],comb[1])
        break
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var num : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    for comb : itertools.combinations(num, 2) do (    var diff : double := (comb->first() - comb[1+1])->abs() ;
    if diff mod (n - 1) = 0 then (
      execute (comb->first())->display() ;
    break
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while 1 :
    N,M=map(int,input().split())
    if not N and not M : break
    s=0
    t=[]
    for _ in range(N):
        a,b=map(int,input().split())
        s+=a*b
        t.extend([(b,a)])
    for i in sorted(t)[: :-1]:
        if i[1]<=M :
            s-=i[0]*i[1]
            M-=i[1]
        elif 0collect( _x | (OclType["int"])->apply(_x) ) ;
    if not(N) & not(M) then (
      break
    ) else skip ;
    var s : int := 0 ;
    var t : Sequence := Sequence{} ;
    for _anon : Integer.subrange(0, N-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    s := s + a * b ;
    t := t->union(Sequence{ Sequence{b, a} })) ;
    for i : sorted(t)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do (    if (i[1+1]->compareTo(M)) <= 0 then  (
      s := s - i->first() * i[1+1] ;
    M := M - i[1+1]
    )
    else (if 0 < M & (M < i[1+1]) then
   (
      s := s - M * i->first() ;
    var M : int := 0 ;
    break    
)
 else skip)) ;
    execute (s)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    n=int(input())
    arr=list(map(int,input().split()))
    print(arr[0])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute (arr->first())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def solve():
    n=int(input())
    li=[int(_)for _ in input().split()]
    for i in range(n):
        for j in range(i+1,n):
            if abs(li[i]-li[j])%(n-1)==0 :
                print(str(li[i])+" "+str(li[j]))
                return
solve()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    solve();
  operation solve()
  pre: true post: true
  activity:
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var li : Sequence := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ;
    for i : Integer.subrange(0, n-1) do (    for j : Integer.subrange(i + 1, n-1) do (    if (li[i+1] - li[j+1])->abs() mod (n - 1) = 0 then (
      execute (("" + ((li[i+1]))) + " " + ("" + ((li[j+1]))))->display() ;
    return
    ) else skip));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=int(input())
a=[int(x)for x in input().split()]
x,y=-1,-1
for i in range(N):
    for j in range(N):
        if i!=j and abs(a[i]-a[j])%(N-1)==0 :
            x,y=i,j
print(a[x],a[y])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := Sequence{-1,-1} ;
    for i : Integer.subrange(0, N-1) do (    for j : Integer.subrange(0, N-1) do (    if i /= j & (a[i+1] - a[j+1])->abs() mod (N - 1) = 0 then (
      var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := Sequence{i,j}
    ) else skip)) ;
    execute (a[x+1])->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
num=list(map(int,input().split()))
num.sort()
flag=0
for i in range(n):
    if flag==1 : break
    for j in range(1,n-i):
        if flag==1 : break
        elif(num[i+j]-num[i])%(n-1)==0 :
            print(num[i],num[i+j])
            flag=1
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var num : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    num := num->sort() ;
    var flag : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    if flag = 1 then (
      break
    ) else skip ;
    for j : Integer.subrange(1, n - i-1) do (    if flag = 1 then  (
      break
    )
    else (if (num[i + j+1] - num[i+1]) mod (n - 1) = 0 then
   (
      execute (num[i+1])->display() ;
    flag := 1    
)
 else skip)));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def Permutation(n,k):
    p=[0 for i in range(n+1)]
    for i in range(1,n+1):
        p[i]=i
    for i in range(1,n-k):
        p[i+1]=i
    p[1]=n-k
    for i in range(1,n+1):
        print(p[i],end=" ")
if __name__=='__main__' :
    n=5
    k=2
    Permutation(n,k)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      n := 5 ;
    k := 2 ;
    Permutation(n, k)
    ) else skip;
  operation Permutation(n : OclAny, k : OclAny)
  pre: true post: true
  activity:
    var p : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ;
    for i : Integer.subrange(1, n + 1-1) do (    p[i+1] := i) ;
    for i : Integer.subrange(1, n - k-1) do (    p[i + 1+1] := i) ;
    p[1+1] := n - k ;
    for i : Integer.subrange(1, n + 1-1) do (    execute (p[i+1])->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
c=p=0 ; b=[0]*1000000
for _ in range(int(input())):
    x=int(input())
    if(c==x and p!=x)or b[0]==1 or c>x : print('No'); continue
    print('Yes')
    if x>=1000000 : continue
    p+=1 ; b[x]+=1
    while b[x]>1 : p-=1 ; b[x]-=2 ; b[x-1]+=1 ; x-=1
    while b[c+1]==1 and c<999999 : c+=1
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var c : OclAny := 0; var p : int := 0;    var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 1000000) ;
    for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if (c = x & p /= x) or b->first() = 1 or (c->compareTo(x)) > 0 then (
      execute ('No')->display();    continue
    ) else skip ;
    execute ('Yes')->display() ;
    if x >= 1000000 then (
      continue
    ) else skip ;
    p := p + 1;    b[x+1] := b[x+1] + 1 ;
    while b[x+1] > 1 do (    p := p - 1;    b[x+1] := b[x+1] - 2;    b[x - 1+1] := b[x - 1+1] + 1;    x := x - 1) ;
    while b[c + 1+1] = 1 & c < 999999 do (    c := c + 1));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
bits=set()
c1=0
count=0
ans=[]
for i in range(n):
    x=int(input())
    if x in bits :
        y=x
        while c1toInteger() ;
    var bits : Set := Set{}->union(()) ;
    var c1 : int := 0 ;
    var count : int := 0 ;
    var ans : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if (bits)->includes(x) then  (
      var y : int := x ;
    while (c1->compareTo(y)) < 0 & (bits)->includes(y) do (    y := y - 1) ;
    if (y->compareTo(c1)) <= 0 then (
      y := 0
    ) else skip ;
    if y = 0 & count /= x then  (
      c1 := Set{x, c1}->max() ;
    execute (("No") : ans)
    )
    else (
      execute ((y) : bits) ;
    execute (("Yes") : ans) ;
    count := count + 1 ;
    if y = 0 then (
      if (i->compareTo(n - 2)) <= 0 then (
      execute ((StringLib.nCopies("No\n", (n - 2 - i)) + "No") : ans)
    ) else skip ;
    break
    ) else skip ;
    for i : Integer.subrange(y + 1, x + 1-1) do (    execute ((i) /: bits) ;
    count := count - 1)
      )
    )
    else (
      execute ((x) : bits) ;
    count := count + 1 ;
    execute (("Yes") : ans)
      )) ;
    execute (StringLib.sumStringsWithSeparator((ans), "\n"))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
q=int(input())
for i in range(q):
    y,u,t=[],[],[]
    w=int(input())
    x=[int(j)for j in input().split()]
    s=sum(x)
    if s==0 :
        print("NO")
    else :
        for j in x :
            if j>0 :
                y=y+[j]
            elif j<0 :
                u=u+[j]
            else :
                t=t+[j]
        if s>0 :
            s1=y+u+t
        else :
            s1=u+y+t
        print("YES")
        print(*s1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, q-1) do (    var y : OclAny := null;
    var u : OclAny := null;
    var t : OclAny := null;
    Sequence{y,u,t} := Sequence{Sequence{},Sequence{},Sequence{}} ;
    var w : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var x : Sequence := input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ;
    var s : OclAny := (x)->sum() ;
    if s = 0 then  (
      execute ("NO")->display()
    )
    else (
      for j : x do (    if j > 0 then  (
      var y : OclAny := y->union(Sequence{ j })
    )
    else (if j < 0 then
   (
      var u : OclAny := u->union(Sequence{ j })    
)
    else (
      var t : OclAny := t->union(Sequence{ j })
      )    )
) ;
    if s > 0 then  (
      var s1 : OclAny := y + u + t
    )
    else (
      s1 := u + y + t
      ) ;
    execute ("YES")->display() ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name s1))))))))->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for s in[*open(0)][2 : : 2]: a=sorted(map(int,s.split())); s=sum(a); print(*(['YES']+a[: : 2*(s<0)-1],['NO'])[s==0])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do (    var a : Sequence := (s.split())->collect( _x | (OclType["int"])->apply(_x) )->sort();    var s : OclAny := (a)->sum();    execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom 'YES')))))) ])) + (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (expr (expr (atom (number (integer 2)))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name s)))) < (comparison (expr (atom (number (integer 0))))))))) )))) - (expr (atom (number (integer 1))))))))))) ]))))))) , (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom 'NO')))))) ])))))) )) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (comparison (expr (atom (name s)))) == (comparison (expr (atom (number (integer 0)))))))))) ]))))))))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import stdin,stdout
T=int(stdin.readline())
for i in range(T):
    N=int(stdin.readline())
    A=list(map(int,stdin.readline().strip().split()))
    POS=[]
    NEG=[]
    for j in range(len(A)):
        if A[j]>=0 :
            POS.append(A[j])
        else :
            NEG.append(A[j])
    SUMP=sum(POS)
    SUMN=abs(sum(NEG))
    if SUMP>SUMN :
        POS.sort(reverse=True)
        stdout.write("YES\n")
        print(*(POS+NEG))
    elif SUMN>SUMP :
        stdout.write("YES\n")
        print(*(NEG+POS))
    else :
        stdout.write("NO\n")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var T : int := ("" + ((stdin.readLine())))->toInteger() ;
    for i : Integer.subrange(0, T-1) do (    var N : int := ("" + ((stdin.readLine())))->toInteger() ;
    var A : Sequence := ((stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var POS : Sequence := Sequence{} ;
    var NEG : Sequence := Sequence{} ;
    for j : Integer.subrange(0, (A)->size()-1) do (    if A[j+1] >= 0 then  (
      execute ((A[j+1]) : POS)
    )
    else (
      execute ((A[j+1]) : NEG)
      )) ;
    var SUMP : OclAny := (POS)->sum() ;
    var SUMN : double := ((NEG)->sum())->abs() ;
    if (SUMP->compareTo(SUMN)) > 0 then  (
      POS := POS->sort() ;
    stdout.write("YES\n") ;
    execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name POS))) + (expr (atom (name NEG)))))))) ))))))))->display()
    )
    else (if (SUMN->compareTo(SUMP)) > 0 then
   (
      stdout.write("YES\n") ;
    execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name NEG))) + (expr (atom (name POS)))))))) ))))))))->display()    
)
    else (
      stdout.write("NO\n")
      )    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
da=list(map(int,input().split()))
k=[[0 for i in range(2)]for j in range(10001)]
i=0
su=0
j=0
while da[0]+da[1]!=0 :
    i=0
    su=0
    j=0
    for i in range(da[0]):
        k[i][0],k[i][1]=map(int,input().split())
    k=sorted(k,key=lambda x : x[1],reverse=True)
    while j!=i+1 :
        if da[1]>k[j][0]:
            da[1]-=k[j][0]
            j+=1
        elif da[1]<=k[j][0]and da[1]>0 :
            su+=(k[j][0]-da[1])*k[j][1]
            da[1]=0
            j+=1
        else :
            su+=k[j][0]*k[j][1]
            j+=1
    print(su)
    da=list(map(int,input().split()))
    k=[[0 for i in range(2)]for j in range(10001)]
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var da : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var k : Sequence := Integer.subrange(0, 10001-1)->select(j | true)->collect(j | (Integer.subrange(0, 2-1)->select(i | true)->collect(i | (0)))) ;
    var i : int := 0 ;
    var su : int := 0 ;
    var j : int := 0 ;
    while da->first() + da[1+1] /= 0 do (    i := 0 ;
    su := 0 ;
    j := 0 ;
    for i : Integer.subrange(0, da->first()-1) do (    var k[i+1]->first() : OclAny := null;
    var k[i+1][1+1] : OclAny := null;
    Sequence{k[i+1]->first(),k[i+1][1+1]} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    k := k->sortedBy($x | (lambda x : OclAny in (x[1+1]))->apply($x)) ;
    while j /= i + 1 do (    if (da[1+1]->compareTo(k[j+1]->first())) > 0 then  (
      da[1+1] := da[1+1] - k[j+1]->first() ;
    j := j + 1
    )
    else (if (da[1+1]->compareTo(k[j+1]->first())) <= 0 & da[1+1] > 0 then
   (
      su := su + (k[j+1]->first() - da[1+1]) * k[j+1][1+1] ;
    da[1+1] := 0 ;
    j := j + 1    
)
    else (
      su := su + k[j+1]->first() * k[j+1][1+1] ;
    j := j + 1
      )    )
) ;
    execute (su)->display() ;
    da := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    k := Integer.subrange(0, 10001-1)->select(j | true)->collect(j | (Integer.subrange(0, 2-1)->select(i | true)->collect(i | (0)))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def solve(n,l):
    tot_sum=0
    for i in range(n):
        tot_sum+=l[i]
    if tot_sum==0 :
        return["NO"]
    elif tot_sum<0 :
        l.sort()
    else :
        l.sort(reverse=True)
    print("YES")
    return l
for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    print(*solve(n,l))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    l := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name solve)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n))))))) , (argument (test (logical_test (comparison (expr (atom (name l)))))))) )))))))))->display());
  operation solve(n : OclAny, l : OclAny) : OclAny
  pre: true post: true
  activity:
    var tot_sum : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    tot_sum := tot_sum + l[i+1]) ;
    if tot_sum = 0 then  (
      return Sequence{ "NO" }
    )
    else (if tot_sum < 0 then
   (
      l := l->sort()    
)
    else (
      l := l->sort()
      )    )
 ;
    execute ("YES")->display() ;
    return l;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    n=int(input())
    print(list(map(int,input().split()))[0])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    execute (OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->first())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for pratyush in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    s=sum(a)
    if s==0 :
        print("NO")
    else :
        print("YES")
        if s>0 : a.sort(reverse=True)
        else : a.sort()
        print(*a)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for pratyush : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var s : OclAny := (a)->sum() ;
    if s = 0 then  (
      execute ("NO")->display()
    )
    else (
      execute ("YES")->display() ;
    if s > 0 then  (
      a := a->sort()
    )
    else (
      a := a->sort()
      ) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def f(s,t):
    j=0 ; i=0
    while i=len(s)
I=input
s=I()
t=I()
print(['No','Yes'][f(s,t)or f(s[1 :],t)])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var I : OclAny := input ;
    s := I() ;
    t := I() ;
    execute (Sequence{'No'}->union(Sequence{ 'Yes' })->select(f(s, t) or f(s->tail(), t)))->display();
  operation f(s : OclAny, t : OclAny) : OclAny
  pre: true post: true
  activity:
    var j : int := 0;    var i : int := 0 ;
    while (i->compareTo((t)->size())) < 0 & (j->compareTo((s)->size())) < 0 do (    if t[i+1] = s[j+1] then (
      j := j + 2
    ) else skip ;
    i := i + 1) ;
    return (j->compareTo((s)->size())) >= 0;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def judge(s):
    if len(s)==0 : return True
    si=0
    for t in T :
        if t==s[si]:
            si+=1
            if si==len(s): return True
    return False
S,T=input(),input()
N=len(S)
print('Yes' if judge(S[: : 2])or judge(S[1 : : 2])else 'No')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var S : OclAny := null;
    var T : OclAny := null;
    Sequence{S,T} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine()} ;
    var N : int := (S)->size() ;
    execute (if judge(S(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) or judge(S(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) then 'Yes' else 'No' endif)->display();
  operation judge(s : OclAny) : OclAny
  pre: true post: true
  activity:
    if (s)->size() = 0 then (
      return true
    ) else skip ;
    var si : int := 0 ;
    for t : T do (    if t = s[si+1] then (
      si := si + 1 ;
    if si = (s)->size() then (
      return true
    ) else skip
    ) else skip) ;
    return false;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf=10**20
eps=1.0/10**10
mod=998244353
def LI(): return[int(x)for x in sys.stdin.readline().split()]
def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return[float(x)for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s,flush=True)
def main():
    rr=[]
    while True :
        s=S()
        t=S()
        l=len(t)
        def f(s):
            i=0
            for c in s :
                while ipow(7)) ;
    var Math_PINFINITY : double := (10)->pow(20) ;
    var eps : double := 1.0 / (10)->pow(10) ;
    var mod : int := 998244353 ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    execute (main())->display();
  operation LI() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()));
  operation LI_() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1));
  operation LF() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal()));
  operation LS() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine().split();
  operation I() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation F() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toReal();
  operation S() : OclAny
  pre: true post: true
  activity:
    return (OclFile["System.in"]).readLine();
  operation pf(s : OclAny) : OclAny
  pre: true post: true
  activity:
    return (s)->display();
  operation main() : OclAny
  pre: true post: true
  activity:
    var rr : Sequence := Sequence{} ;
    while true do (    s := S() ;
    var t : OclAny := S() ;
    var l : int := (t)->size() ;
    skip ;
    if f(s(subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) or f(s(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) then  (
      execute (('Yes') : rr)
    )
    else (
      execute (('No') : rr)
      ) ;
    break) ;
    return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), '
');
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
n=input()
p1=0
for i in n :
    x=(bin(ord(i))[2 :]).zfill(8)
    x=int(x[: :-1],2)
    p=x
    x=(p1-x)% 256
    while x<0 : x+=256-1
    while x>=256 : x-=256-1
    print(x)
    p1=p
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : String := (OclFile["System.in"]).readLine() ;
    var p1 : int := 0 ;
    for i : n->characters() do (    var x : OclAny := (bin((i)->char2byte()).subrange(2+1)).zfill(8) ;
    x := ("" + ((x(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))), 2)))->toInteger() ;
    var p : OclAny := x ;
    x := (p1 - x) mod 256 ;
    while x < 0 do (    x := x + 256 - 1) ;
    while x >= 256 do (    x := x - 256 - 1) ;
    execute (x)->display() ;
    p1 := p);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=input()
f=[0]
for j in range(len(t)):
    a=bin(ord(t[j]))[2 :]
    if len(a)<8 :
        a='0'*(8-len(a))+a
    b=int(a[: :-1],2)
    x=(f[-1]-b)% 256
    print(x)
    f.append(b)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : String := (OclFile["System.in"]).readLine() ;
    var f : Sequence := Sequence{ 0 } ;
    for j : Integer.subrange(0, (t)->size()-1) do (    var a : OclAny := bin((t[j+1])->char2byte()).subrange(2+1) ;
    if (a)->size() < 8 then (
      a := StringLib.nCopies('0', (8 - (a)->size())) + a
    ) else skip ;
    var b : int := ("" + ((a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))), 2)))->toInteger() ;
    var x : int := (f->last() - b) mod 256 ;
    execute (x)->display() ;
    execute ((b) : f));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s=input()
e=0
for i in s :
    a=ord(i)
    b=format(a,'08b')
    c=str(b)[: :-1]
    d=int(c,2)
    print((e-d)% 256)
    e=d
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : String := (OclFile["System.in"]).readLine() ;
    var e : int := 0 ;
    for i : s->characters() do (    var a : int := (i)->char2byte() ;
    var b : String := (a + "") ;
    var c : OclAny := OclType["String"](b)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ;
    var d : int := ("" + ((c, 2)))->toInteger() ;
    execute ((e - d) mod 256)->display() ;
    e := d);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
if __name__=='__main__' :
    s=input()
    e=0
    for i in s :
        a=ord(i)
        b=format(a,'08b')
        c=str(b)[: :-1]
        d=int(c,2)
        print((e-d)% 256)
        e=d
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     if __name__ = '__main__' then (
      var s : String := (OclFile["System.in"]).readLine() ;
    var e : int := 0 ;
    for i : s->characters() do (    var a : int := (i)->char2byte() ;
    var b : String := (a + "") ;
    var c : OclAny := OclType["String"](b)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ;
    var d : int := ("" + ((c, 2)))->toInteger() ;
    execute ((e - d) mod 256)->display() ;
    e := d)
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
roadcnt,money=(int(n)for n in input().split(" "))
while True :
    road=[]
    for r in range(roadcnt):
        road.append([int(n)for n in input().split(" ")])
    road=sorted(road,key=lambda x : x[1])
    while money>0 and len(road)>0 :
        if road[-1][0]-money<0 :
            money-=road[-1][0]
            road.pop()
        else :
            road[-1][0]-=money
            break
    ans=0
    for ro in road :
        ans+=ro[0]*ro[1]
    print(ans)
    roadcnt,money=(int(n)for n in input().split(" "))
    if roadcnt==0 and money==0 :
        break
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var roadcnt : OclAny := null;
    var money : OclAny := null;
    Sequence{roadcnt,money} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " "))))))) ))))))))} ;
    while true do (    var road : Sequence := Sequence{} ;
    for r : Integer.subrange(0, roadcnt-1) do (    execute ((input().split(" ")->select(n | true)->collect(n | (("" + ((n)))->toInteger()))) : road)) ;
    road := road->sortedBy($x | (lambda x : OclAny in (x[1+1]))->apply($x)) ;
    while money > 0 & (road)->size() > 0 do (    if road->last()->first() - money < 0 then  (
      money := money - road->last()->first() ;
    road := road->front()
    )
    else (
      road->last()->first() := road->last()->first() - money ;
    break
      )) ;
    var ans : int := 0 ;
    for ro : road do (    ans := ans + ro->first() * ro[1+1]) ;
    execute (ans)->display() ;
    var roadcnt : OclAny := null;
    var money : OclAny := null;
    Sequence{roadcnt,money} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " "))))))) ))))))))} ;
    if roadcnt = 0 & money = 0 then (
      break
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s=input().strip()
last=0
for c in s :
    oc=ord(c)
    boc=bin(oc)[2 :]
    while len(boc)<8 :
        boc="0"+boc
    boc=boc[: :-1]
    ic=int(boc,2)
    print((last-ic+256)% 256)
    last=ic
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : OclAny := input()->trim() ;
    var last : int := 0 ;
    for c : s do (    var oc : int := (c)->char2byte() ;
    var boc : OclAny := bin(oc).subrange(2+1) ;
    while (boc)->size() < 8 do (    boc := "0" + boc) ;
    boc := boc(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ;
    var ic : int := ("" + ((boc, 2)))->toInteger() ;
    execute ((last - ic + 256) mod 256)->display() ;
    last := ic);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import deque
s=input()
almost_zebra=deque()
zebra=deque()
for index,c in enumerate(s):
    if c=='1' :
        if not zebra :
            break
        else :
            old_zebra=zebra.popleft()
            old_zebra.append(index+1)
            almost_zebra.append(old_zebra)
    else :
        if almost_zebra :
            old_almost_zebra=almost_zebra.popleft()
            old_almost_zebra.append(index+1)
            zebra.append(old_almost_zebra)
        else :
            zebra.append([index+1])
if not zebra or almost_zebra :
    print(-1)
else :
    print(len(zebra))
    for z in zebra :
        temp=[str(i)for i in z]
        print(len(temp)," ".join(temp))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var s : String := (OclFile["System.in"]).readLine() ;
    var almost_zebra : Sequence := () ;
    var zebra : Sequence := () ;
    for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1;
      var index : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var c : OclAny := _tuple->at(_indx);
      if c = '1' then  (
      if not(zebra) then  (
      break
    )
    else (
      var old_zebra : OclAny := zebra->first() ;     zebra := zebra->tail() ;
    execute ((index + 1) : old_zebra) ;
    execute ((old_zebra) : almost_zebra)
      )
    )
    else (
      if almost_zebra then  (
      var old_almost_zebra : OclAny := almost_zebra->first() ;     almost_zebra := almost_zebra->tail() ;
    execute ((index + 1) : old_almost_zebra) ;
    execute ((old_almost_zebra) : zebra)
    )
    else (
      execute ((Sequence{ index + 1 }) : zebra)
      )
      )) ;
    if not(zebra) or almost_zebra then  (
      execute (-1)->display()
    )
    else (
      execute ((zebra)->size())->display() ;
    for z : zebra do (    var temp : Sequence := z->select(i | true)->collect(i | (("" + ((i))))) ;
    execute ((temp)->size())->display())
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def maxOfSegmentMins(a,n,k):
    if k==1 :
        return min(a)
    if k==2 :
        return max(a[0],a[n-1])
    return max(a)
if __name__=='__main__' :
    a=[-10,-9,-8,2,7,-6,-5]
    n=len(a)
    k=2
    print(maxOfSegmentMins(a,n,k))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      a := Sequence{-10}->union(Sequence{-9}->union(Sequence{-8}->union(Sequence{2}->union(Sequence{7}->union(Sequence{-6}->union(Sequence{ -5 })))))) ;
    n := (a)->size() ;
    k := 2 ;
    execute (maxOfSegmentMins(a, n, k))->display()
    ) else skip;
  operation maxOfSegmentMins(a : OclAny, n : OclAny, k : OclAny) : OclAny
  pre: true post: true
  activity:
    if k = 1 then (
      return (a)->min()
    ) else skip ;
    if k = 2 then (
      return Set{a->first(), a[n - 1+1]}->max()
    ) else skip ;
    return (a)->max();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s=input()
r=0
k=0
res=[[]for _ in range(len(s))]
for i,c in enumerate(s):
    if c=='0' :
        res[r].append(i+1)
        r+=1
    else :
        if r==0 :
            print(-1)
            exit(0)
        r-=1
        res[r].append(i+1)
    k=max(k,r)
if k!=r :
    print(-1)
    exit(0)
print(k)
for r in res[: k]:
    tmp=[str(i)for i in r]
    print(len(tmp)," ".join(tmp))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : String := (OclFile["System.in"]).readLine() ;
    var r : int := 0 ;
    var k : int := 0 ;
    var res : Sequence := Integer.subrange(0, (s)->size()-1)->select(_anon | true)->collect(_anon | (Sequence{})) ;
    for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var c : OclAny := _tuple->at(_indx);
      if c = '0' then  (
  (expr (atom (name res)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) )))) ;
    r := r + 1
    )
    else (
      if r = 0 then (
      execute (-1)->display() ;
    exit(0)
    ) else skip ;
    r := r - 1 ;
(expr (atom (name res)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ))))
      ) ;
    k := Set{k, r}->max()) ;
    if k /= r then (
      execute (-1)->display() ;
    exit(0)
    ) else skip ;
    execute (k)->display() ;
    for r : res.subrange(1,k) do (    var tmp : Sequence := r->select(i | true)->collect(i | (("" + ((i))))) ;
    execute ((tmp)->size())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import copy
import gc
import itertools
from array import array
from fractions import Fraction
import heapq
import math
import operator
import os,sys
import profile
import cProfile
import random
import re
import string
from bisect import bisect_left,bisect_right
from collections import defaultdict,deque,Counter
from functools import reduce,lru_cache
from io import IOBase,BytesIO
from itertools import count,groupby,accumulate,permutations,combinations_with_replacement,product
from math import gcd
from operator import xor,add
from typing import List
input=lambda : sys.stdin.readline().rstrip("\n")
def read_int_list(): return list(map(int,input().split()))
def read_int_tuple(): return tuple(map(int,input().split()))
def read_int(): return int(input())
def solve(s):
    zeros,ones=[],[]
    for i,ch in enumerate(s,1):
        if int(ch):
            if zeros :
                last_zero=zeros.pop()
                last_zero.append(i)
                ones.append(last_zero)
            else :
                print(-1)
                return
        else :
            if ones :
                last_one=ones.pop()
                last_one.append(i)
                zeros.append(last_one)
            else :
                zeros.append([i])
    if ones :
        print(-1)
        return
    print(len(zeros))
    for row in zeros :
        print(len(row),end=' ')
        print(*row)
def main():
    solve(input())
if __name__=="__main__" :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip("\n")) ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      main()
    ) else skip;
  operation read_int_list() : OclAny
  pre: true post: true
  activity:
    return ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ));
  operation read_int_tuple() : OclAny
  pre: true post: true
  activity:
    return ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ));
  operation read_int() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation solve(s : OclAny)
  pre: true post: true
  activity:
    var zeros : OclAny := null;
    var ones : OclAny := null;
    Sequence{zeros,ones} := Sequence{Sequence{},Sequence{}} ;
    for _tuple : Integer.subrange(1, (s, 1)->size())->collect( _indx | Sequence{_indx-1, (s, 1)->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var ch : OclAny := _tuple->at(_indx);
      if ("" + ((ch)))->toInteger() then  (
      if zeros then  (
      var last_zero : OclAny := zeros->last() ;     zeros := zeros->front() ;
    execute ((i) : last_zero) ;
    execute ((last_zero) : ones)
    )
    else (
      execute (-1)->display() ;
    return
      )
    )
    else (
      if ones then  (
      var last_one : OclAny := ones->last() ;     ones := ones->front() ;
    execute ((i) : last_one) ;
    execute ((last_one) : zeros)
    )
    else (
      execute ((Sequence{ i }) : zeros)
      )
      )) ;
    if ones then (
      execute (-1)->display() ;
    return
    ) else skip ;
    execute ((zeros)->size())->display() ;
    for row : zeros do (    execute ((row)->size())->display() ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name row))))))))->display());
  operation main()
  pre: true post: true
  activity:
    solve((OclFile["System.in"]).readLine());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s=input()
almost_zebra=[]
zebra=[]
for index,c in enumerate(s):
    if c=='1' :
        if not zebra :
            break
        else :
            old_zebra=zebra.pop()
            old_zebra.append(index+1)
            almost_zebra.append(old_zebra)
    else :
        if almost_zebra :
            old_almost_zebra=almost_zebra.pop()
            old_almost_zebra.append(index+1)
            zebra.append(old_almost_zebra)
        else :
            zebra.append([index+1])
if not zebra or almost_zebra :
    print(-1)
else :
    print(len(zebra))
    for z in zebra :
        temp=[str(i)for i in z]
        print(len(temp)," ".join(temp))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : String := (OclFile["System.in"]).readLine() ;
    var almost_zebra : Sequence := Sequence{} ;
    var zebra : Sequence := Sequence{} ;
    for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1;
      var index : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var c : OclAny := _tuple->at(_indx);
      if c = '1' then  (
      if not(zebra) then  (
      break
    )
    else (
      var old_zebra : OclAny := zebra->last() ;     zebra := zebra->front() ;
    execute ((index + 1) : old_zebra) ;
    execute ((old_zebra) : almost_zebra)
      )
    )
    else (
      if almost_zebra then  (
      var old_almost_zebra : OclAny := almost_zebra->last() ;     almost_zebra := almost_zebra->front() ;
    execute ((index + 1) : old_almost_zebra) ;
    execute ((old_almost_zebra) : zebra)
    )
    else (
      execute ((Sequence{ index + 1 }) : zebra)
      )
      )) ;
    if not(zebra) or almost_zebra then  (
      execute (-1)->display()
    )
    else (
      execute ((zebra)->size())->display() ;
    for z : zebra do (    var temp : Sequence := z->select(i | true)->collect(i | (("" + ((i))))) ;
    execute ((temp)->size())->display())
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import deque
s=input()
almost_zebra=deque()
zebra=deque()
for index,c in enumerate(s):
    if c=='1' :
        if not zebra :
            break
        else :
            old_zebra=zebra.popleft()
            old_zebra.append(index+1)
            almost_zebra.append(old_zebra)
    else :
        if almost_zebra :
            old_almost_zebra=almost_zebra.popleft()
            old_almost_zebra.append(index+1)
            zebra.append(old_almost_zebra)
        else :
            zebra.append([index+1])
if not zebra or almost_zebra :
    print(-1)
else :
    print(len(zebra))
    for z in zebra :
        temp=[str(i)for i in z]
        print(len(temp)," ".join(temp))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var s : String := (OclFile["System.in"]).readLine() ;
    var almost_zebra : Sequence := () ;
    var zebra : Sequence := () ;
    for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1;
      var index : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var c : OclAny := _tuple->at(_indx);
      if c = '1' then  (
      if not(zebra) then  (
      break
    )
    else (
      var old_zebra : OclAny := zebra->first() ;     zebra := zebra->tail() ;
    execute ((index + 1) : old_zebra) ;
    execute ((old_zebra) : almost_zebra)
      )
    )
    else (
      if almost_zebra then  (
      var old_almost_zebra : OclAny := almost_zebra->first() ;     almost_zebra := almost_zebra->tail() ;
    execute ((index + 1) : old_almost_zebra) ;
    execute ((old_almost_zebra) : zebra)
    )
    else (
      execute ((Sequence{ index + 1 }) : zebra)
      )
      )) ;
    if not(zebra) or almost_zebra then  (
      execute (-1)->display()
    )
    else (
      execute ((zebra)->size())->display() ;
    for z : zebra do (    var temp : Sequence := z->select(i | true)->collect(i | (("" + ((i))))) ;
    execute ((temp)->size())->display())
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def printSeries(n):
    nmtr=[1,1,1,3]
    dntr=[0,4,2,4]
    for i in range(1,n+1,1):
        if(i % 4==0):
            print(nmtr[i % 4]+int(i/4)-1,end="")
        else :
            print(nmtr[i % 4]+(int(i/4)*dntr[i % 4]),end="")
            print("/",end="")
            print(dntr[i % 4],end="")
if __name__=='__main__' :
    n=9
    printSeries(n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      n := 9 ;
    printSeries(n)
    ) else skip;
  operation printSeries(n : OclAny)
  pre: true post: true
  activity:
    var nmtr : Sequence := Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 3 }))) ;
    var dntr : Sequence := Sequence{0}->union(Sequence{4}->union(Sequence{2}->union(Sequence{ 4 }))) ;
    for i : Integer.subrange(1, n + 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do (    if (i mod 4 = 0) then  (
      execute (nmtr[i mod 4+1] + ("" + ((i / 4)))->toInteger() - 1)->display()
    )
    else (
      execute (nmtr[i mod 4+1] + (("" + ((i / 4)))->toInteger() * dntr[i mod 4+1]))->display() ;
    execute ("/")->display() ;
    execute (dntr[i mod 4+1])->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    n,k=map(int,input().split())
    li=[int(i)for i in input().split()]
    min_value=min(li)
    li.remove(min_value)
    r=0
    for num in li :
        r+=(k-num)//min_value
    print(r)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var li : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var min_value : OclAny := (li)->min() ;
    execute ((min_value) /: li) ;
    var r : int := 0 ;
    for num : li do (    r := r + (k - num) div min_value) ;
    execute (r)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
R=lambda : map(int,input().split())
t,=R()
exec(t*'n,k=R();x,*a=sorted(R());print(sum((k-y)//x for y in a));')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)    Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := R->apply() ;
(expr (expr (atom (name t))) * (expr (atom 'n,k=R();x,*a=sorted(R());print(sum((k-y)//x for y in a));')));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
s=input()
start=0
end=0
_max=s[0]
for i,el in enumerate(s):
    if el>=_max :
        start=i
        _max=el
    else :
        end=i
        print("YES")
        print(start+1,end+1)
        break
if end<=start :
    print("NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : String := (OclFile["System.in"]).readLine() ;
    var start : int := 0 ;
    var end : int := 0 ;
    var _max : OclAny := s->first() ;
    for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var el : OclAny := _tuple->at(_indx);
      if (el->compareTo(_max)) >= 0 then  (
      start := i ;
    _max := el
    )
    else (
      end := i ;
    execute ("YES")->display() ;
    execute (start + 1)->display() ;
    break
      )) ;
    if (end->compareTo(start)) <= 0 then (
      execute ("NO")->display()
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def numberOfWays(x):
    if x==0 or x==1 :
        return 1
    else :
        return(numberOfWays(x-1)+(x-1)*numberOfWays(x-2))
x=3
print(numberOfWays(x))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    x := 3 ;
    execute (numberOfWays(x))->display();
  operation numberOfWays(x : OclAny) : OclAny
  pre: true post: true
  activity:
    if x = 0 or x = 1 then  (
      return 1
    )
    else (
      return (numberOfWays(x - 1) + (x - 1) * numberOfWays(x - 2))
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
t=int(input())
for i in range(t):
    a=list(map(int,input().split(" ")))
    n=a[0]
    k=a[1]
    a=list(map(int,input().split(" ")))
    a.sort()
    d=0
    for i in range(1,n):
        if(k>a[i]):
            d+=(k-a[i])//a[0]
    print(d)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, t-1) do (    var a : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ;
    var n : OclAny := a->first() ;
    var k : OclAny := a[1+1] ;
    a := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ;
    a := a->sort() ;
    var d : int := 0 ;
    for i : Integer.subrange(1, n-1) do (    if ((k->compareTo(a[i+1])) > 0) then (
      d := d + (k - a[i+1]) div a->first()
    ) else skip) ;
    execute (d)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
R=lambda : map(int,input().split())
t,=R()
exec(t*'n,k=R();x,*a=sorted(R());print(sum((k-y)//x for y in a));')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)    Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := R->apply() ;
(expr (expr (atom (name t))) * (expr (atom 'n,k=R();x,*a=sorted(R());print(sum((k-y)//x for y in a));')));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    n,k=map(int,input().split())
    l=list(map(int,input().split()))
    l.sort()
    c=0
    for i in l[1 : :]:
        num=k-i
        if numtoInteger()-1) do (    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    l := l->sort() ;
    var c : int := 0 ;
    for i : l(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop :)) do (    var num : double := k - i ;
    if (num->compareTo(k)) < 0 then (
      c := c + num div l->first()
    ) else skip) ;
    execute (c)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def findCost(s1,s2,a,b,c,d,n):
    cost=0
    for i in range(n):
        if(s1[i]==s2[i]):
            continue
        else :
            if((s1[i]=='1' and s2[i]=='2')or(s2[i]=='1' and s1[i]=='2')):
                cost+=min(d,min(a,b+c))
            elif((s1[i]=='2' and s2[i]=='3')or(s2[i]=='2' and s1[i]=='3')):
                cost+=min(d,min(b,a+c))
            elif((s1[i]=='1' and s2[i]=='3')or(s2[i]=='1' and s1[i]=='3')):
                cost+=min(d,min(c,a+b))
    return cost
if __name__=='__main__' :
    s1="121"
    s2="223"
    a=2
    b=3
    c=4
    d=10
    n=len(s1)
    print(findCost(s1,s2,a,b,c,d,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      s1 := "121" ;
    s2 := "223" ;
    a := 2 ;
    b := 3 ;
    c := 4 ;
    d := 10 ;
    n := (s1)->size() ;
    execute (findCost(s1, s2, a, b, c, d, n))->display()
    ) else skip;
  operation findCost(s1 : OclAny, s2 : OclAny, a : OclAny, b : OclAny, c : OclAny, d : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var cost : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    if (s1[i+1] = s2[i+1]) then  (
      continue
    )
    else (
      if ((s1[i+1] = '1' & s2[i+1] = '2') or (s2[i+1] = '1' & s1[i+1] = '2')) then  (
      cost := cost + Set{d, Set{a, b + c}->min()}->min()
    )
    else (if ((s1[i+1] = '2' & s2[i+1] = '3') or (s2[i+1] = '2' & s1[i+1] = '3')) then
   (
      cost := cost + Set{d, Set{b, a + c}->min()}->min()    
)
    else (if ((s1[i+1] = '1' & s2[i+1] = '3') or (s2[i+1] = '1' & s1[i+1] = '3')) then
   (
      cost := cost + Set{d, Set{c, a + b}->min()}->min()    
)
    else skip    )
    )
      )) ;
    return cost;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
MAX_CHAR=26
def countPalindrome(str):
    n=len(str)
    sum=0
    hashTable=[0]*MAX_CHAR
    for i in range(n):
        hashTable[ord(str[i])-ord('a')]+=1
    for i in range(26):
        if(hashTable[i]):
            sum+=(hashTable[i]*(hashTable[i]+1)//2)
    return sum
if __name__=="__main__" :
    str="ananananddd"
    print(countPalindrome(str))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var MAX_CHAR : int := 26 ;
    skip ;
    if __name__ = "__main__" then (
      OclType["String"] := "ananananddd" ;
    execute (countPalindrome(OclType["String"]))->display()
    ) else skip;
  operation countPalindrome(OclType["String"] : OclAny) : OclAny
  pre: true post: true
  activity:
    var n : int := (OclType["String"])->size() ;
    var sum : int := 0 ;
    var hashTable : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX_CHAR) ;
    for i : Integer.subrange(0, n-1) do (    hashTable[(("" + ([i+1])))->char2byte() - ('a')->char2byte()+1] := hashTable[(("" + ([i+1])))->char2byte() - ('a')->char2byte()+1] + 1) ;
    for i : Integer.subrange(0, 26-1) do (    if (hashTable[i+1]) then (
      sum := sum + (hashTable[i+1] * (hashTable[i+1] + 1) div 2)
    ) else skip) ;
    return sum;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def calcSum(arr,n,k):
    for i in range(n-k+1):
        sum=0
        for j in range(i,k+i):
            sum+=arr[j]
        print(sum,end=" ")
arr=[1,2,3,4,5,6]
n=len(arr)
k=3
calcSum(arr,n,k)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))))) ;
    n := (arr)->size() ;
    k := 3 ;
    calcSum(arr, n, k);
  operation calcSum(arr : OclAny, n : OclAny, k : OclAny)
  pre: true post: true
  activity:
    for i : Integer.subrange(0, n - k + 1-1) do (    var sum : int := 0 ;
    for j : Integer.subrange(i, k + i-1) do (    sum := sum + arr[j+1]) ;
    execute (sum)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import deque ;
def remainingDigit(S,N):
    c=[i for i in S]
    de=[0,0]
    count=[0,0]
    q=deque()
    for i in c :
        x=0
        if i=='1' :
            x=1
        count[x]+=1
        q.append(x)
    while(count[0]>0 and count[1]>0):
        t=q.popleft()
        if(de[t]>0):
            de[t]-=1
            count[t]-=1
        else :
            de[t ^ 1]+=1
            q.append(t)
    if(count[0]>0):
        return "0"
    return "1"
if __name__=='__main__' :
    S="1010100100000"
    N=len(S)
    print(remainingDigit(S,N))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip; ;
    skip ;
    if __name__ = '__main__' then (
      S := "1010100100000" ;
    N := (S)->size() ;
    execute (remainingDigit(S, N))->display()
    ) else skip;
  operation remainingDigit(S : OclAny, N : OclAny) : OclAny
  pre: true post: true
  activity:
    var c : Sequence := S->select(i | true)->collect(i | (i)) ;
    var de : Sequence := Sequence{0}->union(Sequence{ 0 }) ;
    var count : Sequence := Sequence{0}->union(Sequence{ 0 }) ;
    var q : Sequence := () ;
    for i : c do (    var x : int := 0 ;
    if i = '1' then (
      x := 1
    ) else skip ;
    count[x+1] := count[x+1] + 1 ;
    execute ((x) : q)) ;
    while (count->first() > 0 & count[1+1] > 0) do (    var t : OclAny := q->first() ;     q := q->tail() ;
    if (de[t+1] > 0) then  (
      de[t+1] := de[t+1] - 1 ;
    count[t+1] := count[t+1] - 1
    )
    else (
      de[MathLib.bitwiseXor(t, 1)+1] := de[MathLib.bitwiseXor(t, 1)+1] + 1 ;
    execute ((t) : q)
      )) ;
    if (count->first() > 0) then (
      return "0"
    ) else skip ;
    return "1";
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import itertools
def compute():
    count=0
    for i in itertools.count(1):
        s=str(i)
        t="".join(sorted(s))
        if s!=t and s[: :-1]!=t :
            count+=1
        if count*100==99*i :
            return str(i)
if __name__=="__main__" :
    print(compute())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      execute (compute())->display()
    ) else skip;
  operation compute() : OclAny
  pre: true post: true
  activity:
    var count : int := 0 ;
    for i : itertools->count(1) do (    var s : String := ("" + ((i))) ;
    var t : String := StringLib.sumStringsWithSeparator((s->sort()), "") ;
    if s /= t & s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) /= t then (
      count := count + 1
    ) else skip ;
    if count * 100 = 99 * i then (
      return ("" + ((i)))
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    try :
        Num=[]
        n=int(input())
        while n>0 :
            if n % 2==1 :
                Num.append(1)
                n=(n-1)/2
            else :
                Num.append(0)
                n=n/2
        for i in range(len(Num)-1):
            if Num[i]==1 :
                print(2**i,end=" ")
        print(2**(len(Num)-1))
    except EOFError :
        break
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    try (    var Num : Sequence := Sequence{} ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    while n > 0 do (    if n mod 2 = 1 then  (
      execute ((1) : Num) ;
    n := (n - 1) / 2
    )
    else (
      execute ((0) : Num) ;
    n := n / 2
      )) ;
    for i : Integer.subrange(0, (Num)->size() - 1-1) do (    if Num[i+1] = 1 then (
      execute ((2)->pow(i))->display()
    ) else skip) ;
    execute ((2)->pow(((Num)->size() - 1)))->display())
(except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
W=[]
N=[1,2,4,8,16,32,64,128,256,512]
for line in sys.stdin :
    W.append(int(line))
for x in W :
    ans=[]
    for y in N :
        if x & y :
            ans.append(str(y))
    print(' '.join(ans))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var W : Sequence := Sequence{} ;
    var N : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{8}->union(Sequence{16}->union(Sequence{32}->union(Sequence{64}->union(Sequence{128}->union(Sequence{256}->union(Sequence{ 512 }))))))))) ;
    for line : OclFile["System.in"] do (    execute ((("" + ((line)))->toInteger()) : W)) ;
    for x : W do (    var ans : Sequence := Sequence{} ;
    for y : N do (    if MathLib.bitwiseAnd(x, y) then (
      execute ((("" + ((y)))) : ans)
    ) else skip) ;
    execute (StringLib.sumStringsWithSeparator((ans), ' '))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    n,m=map(int,input().split())
    if n==0 and m==0 :
        break
    temp=[]
    distance=0
    for i in range(n):
        d,p=map(int,input().split())
        distance=distance+d
        temp.append([p,d])
    temp.sort()
    temp.reverse()
    if distance<=m :
        print(0)
    else :
        money=m
        while True :
            if money<=temp[0][1]:
                temp[0][1]-=money
                break
            else :
                money-=temp[0][1]
                temp.pop(0)
        ans=0
        for i in range(0,len(temp)):
            ans+=temp[i][0]*temp[i][1]
        print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if n = 0 & m = 0 then (
      break
    ) else skip ;
    var temp : Sequence := Sequence{} ;
    var distance : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    var d : OclAny := null;
    var p : OclAny := null;
    Sequence{d,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    distance := distance + d ;
    execute ((Sequence{p}->union(Sequence{ d })) : temp)) ;
    temp := temp->sort() ;
    temp := temp->reverse() ;
    if (distance->compareTo(m)) <= 0 then  (
      execute (0)->display()
    )
    else (
      var money : OclAny := m ;
    while true do (    if (money->compareTo(temp->first()[1+1])) <= 0 then  (
      temp->first()[1+1] := temp->first()[1+1] - money ;
    break
    )
    else (
      money := money - temp->first()[1+1] ;
    temp := temp->excludingAt(0+1)
      )) ;
    var ans : int := 0 ;
    for i : Integer.subrange(0, (temp)->size()-1) do (    ans := ans + temp[i+1]->first() * temp[i+1][1+1]) ;
    execute (ans)->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
print("\n".join((" ".join(str(2**i)for i,n in enumerate(bin(int(s))[: 1 :-1])if n=="1")for s in sys.stdin.readlines())))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    execute (StringLib.sumStringsWithSeparator((Sequence{(testlist_comp (test (logical_test (comparison (expr (atom " ") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) ** (expr (atom (name i))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name bin)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))))) ))) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (number (integer 1))))))) (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ])))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name n)))) == (comparison (expr (atom "1")))))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin)) (trailer . (name readlines) (arguments ( ))))))))}), "\n"))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
w=[512,256,128,64,32,16,8,4,2,1]
ans=[]
for x in sys.stdin :
    for i in range(10):
        if int(x)% w[i]==0 :
            ans.append(w[i])
            ans.reverse()
            print(*ans)
            ans=[]
            break
        else :
            if int(x)//w[i]==1 :
                ans.append(w[i])
                x=int(x)% w[i]
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var w : Sequence := Sequence{512}->union(Sequence{256}->union(Sequence{128}->union(Sequence{64}->union(Sequence{32}->union(Sequence{16}->union(Sequence{8}->union(Sequence{4}->union(Sequence{2}->union(Sequence{ 1 }))))))))) ;
    var ans : Sequence := Sequence{} ;
    for x : OclFile["System.in"] do (    for i : Integer.subrange(0, 10-1) do (    if ("" + ((x)))->toInteger() mod w[i+1] = 0 then  (
      execute ((w[i+1]) : ans) ;
    ans := ans->reverse() ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ;
    ans := Sequence{} ;
    break
    )
    else (
      if ("" + ((x)))->toInteger() div w[i+1] = 1 then (
      execute ((w[i+1]) : ans) ;
    var x : int := ("" + ((x)))->toInteger() mod w[i+1]
    ) else skip
      )));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    while True :
        try :
            val=str(format(int(input()),'010b'))
            LIST=[2**(10-x)for x in range(10,0,-1)if val[x-1]=="1"]
            for i in LIST :
                print(i,end="")
                if LIST.index(i)==len(LIST)-1 :
                    print("")
                else :
                    print("",end="")
        except :
            break
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    while true do (    try (    var val : String := ("" + (((("" + (((OclFile["System.in"]).readLine())))->toInteger() + "")))) ;
    var LIST : Sequence := Integer.subrange(0 + 1, 10)->reverse()->select(x | val[x - 1+1] = "1")->collect(x | ((2)->pow((10 - x)))) ;
    for i : LIST do (    execute (i)->display() ;
    if LIST->indexOf(i) - 1 = (LIST)->size() - 1 then  (
      execute ("")->display()
    )
    else (
      execute ("")->display()
      )))
     catch (_e : OclException) do (    break)
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
ii=int(input())
l_d=list(map(int,input().split()))
p,q=map(int,input().split())
if p>q :
    t=p
    p=q
    q=t
print(min(sum(l_d[p-1 : q-1]),sum(l_d[: p-1])+sum(l_d[q-1 :])))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var ii : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var l_d : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var p : OclAny := null;
    var q : OclAny := null;
    Sequence{p,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if (p->compareTo(q)) > 0 then (
      var t : OclAny := p ;
    var p : OclAny := q ;
    var q : OclAny := t
    ) else skip ;
    execute (Set{(l_d.subrange(p - 1+1, q - 1))->sum(), (l_d.subrange(1,p - 1))->sum() + (l_d.subrange(q - 1+1))->sum()}->min())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import defaultdict
import math
def add_factors(n,mp):
    for i in range(1,int(math.sqrt(n))+1,):
        if(n % i==0):
            if(n//i==i):
                mp[i]+=1
            else :
                mp[i]+=1
                mp[n//i]+=1
def count_divisors(a,n):
    mp=defaultdict(int)
    for i in range(n):
        print(mp[a[i]],end=" ")
        add_factors(a[i],mp)
if __name__=="__main__" :
    arr=[8,1,28,4,2,6,7]
    n=len(arr)
    count_divisors(arr,n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      var arr : Sequence := Sequence{8}->union(Sequence{1}->union(Sequence{28}->union(Sequence{4}->union(Sequence{2}->union(Sequence{6}->union(Sequence{ 7 })))))) ;
    n := (arr)->size() ;
    count_divisors(arr, n)
    ) else skip;
  operation add_factors(n : OclAny, mp : OclAny)
  pre: true post: true
  activity:
    for i : (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name math)) (trailer . (name sqrt) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))) )))) + (expr (atom (number (integer 1))))))))) ,) do (    if (n mod i = 0) then (
      if (n div i = i) then  (
      mp[i+1] := mp[i+1] + 1
    )
    else (
      mp[i+1] := mp[i+1] + 1 ;
    mp[n div i+1] := mp[n div i+1] + 1
      )
    ) else skip);
  operation count_divisors(a : OclAny, n : OclAny)
  pre: true post: true
  activity:
    mp := defaultdict(OclType["int"]) ;
    for i : Integer.subrange(0, n-1) do (    execute (mp[a[i+1]+1])->display() ;
    add_factors(a[i+1], mp));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import stdin,stdout
def read():
    return stdin.readline().rstrip()
def read_int():
    return int(read())
def read_ints():
    return list(map(int,read().split()))
def solve():
    n=read_int()
    a=read_ints()
    s,t=read_ints()
    if s>t :
        s,t=t,s
    print(min(sum(a[s-1 : t-1]),sum(a)-sum(a[s-1 : t-1])))
solve()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    solve();
  operation read() : OclAny
  pre: true post: true
  activity:
    return stdin.readLine().rstrip();
  operation read_int() : OclAny
  pre: true post: true
  activity:
    return ("" + ((read())))->toInteger();
  operation read_ints() : OclAny
  pre: true post: true
  activity:
    return ((read().split())->collect( _x | (OclType["int"])->apply(_x) ));
  operation solve()
  pre: true post: true
  activity:
    var n : OclAny := read_int() ;
    var a : OclAny := read_ints() ;
    var s : OclAny := null;
    var t : OclAny := null;
    Sequence{s,t} := read_ints() ;
    if (s->compareTo(t)) > 0 then (
      var s : OclAny := null;
    var t : OclAny := null;
    Sequence{s,t} := Sequence{t,s}
    ) else skip ;
    execute (Set{(a.subrange(s - 1+1, t - 1))->sum(), (a)->sum() - (a.subrange(s - 1+1, t - 1))->sum()}->min())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a=list(map(int,input().split()))
s,t=map(int,input().split())
s,t=min(s,t),max(s,t)
s-=1
t-=1
z=0
x=0
for i in range(s,t):
    z+=a[i]
for i in range(s):
    x+=a[i]
for i in range(t,n):
    x+=a[i]
print(min(z,x))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var s : OclAny := null;
    var t : OclAny := null;
    Sequence{s,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var s : OclAny := null;
    var t : OclAny := null;
    Sequence{s,t} := Sequence{Set{s, t}->min(),Set{s, t}->max()} ;
    s := s - 1 ;
    t := t - 1 ;
    var z : int := 0 ;
    var x : int := 0 ;
    for i : Integer.subrange(s, t-1) do (    z := z + a[i+1]) ;
    for i : Integer.subrange(0, s-1) do (    x := x + a[i+1]) ;
    for i : Integer.subrange(t, n-1) do (    x := x + a[i+1]) ;
    execute (Set{z, x}->min())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,d,s1,s2=int(input()),list(map(int,input().split())),0,0
s,t=map(int,input().split())
i=s
while i!=t :
    s1,i=s1+d[i-1],i+1
    if i==n+1 : i=1
i=s
while i!=t :
    if i>=2 : s2,i=s2+d[i-2],i-1
    else : s2,i=s2+d[n-1],i-1
    if i==0 : i=n
print(min(s1,s2))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var d : OclAny := null;
    var s1 : OclAny := null;
    var s2 : OclAny := null;
    Sequence{n,d,s1,s2} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),((input().split())->collect( _x | (OclType["int"])->apply(_x) )),0,0} ;
    var s : OclAny := null;
    var t : OclAny := null;
    Sequence{s,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var i : OclAny := s ;
    while i /= t do (    var s1 : OclAny := null;
    Sequence{s1,i} := Sequence{s1 + d[i - 1+1],i + 1} ;
    if i = n + 1 then (
      i := 1
    ) else skip) ;
    i := s ;
    while i /= t do (    if i >= 2 then  (
      var s2 : OclAny := null;
    Sequence{s2,i} := Sequence{s2 + d[i - 2+1],i - 1}
    )
    else (
      var s2 : OclAny := null;
    Sequence{s2,i} := Sequence{s2 + d[n - 1+1],i - 1}
      ) ;
    if i = 0 then (
      i := n
    ) else skip) ;
    execute (Set{s1, s2}->min())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
lst=[*map(int,input().split())]
s,t=sorted(map(int,input().split()))
res=sum(lst[s-1 : t-1])
print(min(res,sum(lst)-res))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var lst : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var s : OclAny := null;
    var t : OclAny := null;
    Sequence{s,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ;
    var res : OclAny := (lst.subrange(s - 1+1, t - 1))->sum() ;
    execute (Set{res, (lst)->sum() - res}->min())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
print(len(set(map(int,input().split()))))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     execute ((Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))->size())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from heapq import heapify,heappushpop
N,*A=map(int,open(0).read().split())
L,C,R=A[: N],A[N : 2*N],A[2*N :]
F=[sum(L)]
heapify(L)
for c in C :
    F.append(F[-1]+c-heappushpop(L,c))
R=[-r for r in R]
B=[sum(R)]
heapify(R)
for c in reversed(C):
    B.append(B[-1]-c-heappushpop(R,-c))
print(max(f+b for f,b in zip(F,reversed(B))))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var N : OclAny := null;
    var A : OclAny := null;
    Sequence{N,A} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var L : OclAny := null;
    var C : OclAny := null;
    var R : OclAny := null;
    Sequence{L,C,R} := Sequence{A.subrange(1,N),A.subrange(N+1, 2 * N),A.subrange(2 * N+1)} ;
    var F : Sequence := Sequence{ (L)->sum() } ;
    heapify(L) ;
    for c : C do (    execute ((F->last() + c - heappushpop(L, c)) : F)) ;
    var R : Sequence := R->select(r | true)->collect(r | (-r)) ;
    var B : Sequence := Sequence{ (R)->sum() } ;
    heapify(R) ;
    for c : (C)->reverse() do (    execute ((B->last() - c - heappushpop(R, -c)) : B)) ;
    execute (((argument (test (logical_test (comparison (expr (expr (atom (name f))) + (expr (atom (name b))))))) (comp_for for (exprlist (expr (atom (name f))) , (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name F))))))) , (argument (test (logical_test (comparison (expr (atom (name reversed)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name B)))))))) ))))))))) )))))))))->max())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b,c=map(int,input().split())
if a==b and b==c and a==c :
    print("1")
elif a!=b and b!=c and a!=c :
    print("3")
else :
    print("2")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if a = b & b = c & a = c then  (
      execute ("1")->display()
    )
    else (if a /= b & b /= c & a /= c then
   (
      execute ("3")->display()    
)
    else (
      execute ("2")->display()
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b,c=list(map(int,input().split()))
print((a==b and b==c)*(1)or((a!=b and b==c)or(a==b and b!=c)or(a==c and b!=c))*(2)or(a!=b and b!=c and a!=c)*(3))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute ((a = b & b = c) * (1) or ((a /= b & b = c) or (a = b & b /= c) or (a = c & b /= c)) * (2) or (a /= b & b /= c & a /= c) * (3))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
a,b,c=map(int,input().split())
s=set([a,b,c])
print(len(s))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var s : Set := Set{}->union((Sequence{a}->union(Sequence{b}->union(Sequence{ c })))) ;
    execute ((s)->size())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s=set()
for i in input().split():
    s.add(i)
print(len(s))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : Set := Set{}->union(()) ;
    for i : input().split() do (    execute ((i) : s)) ;
    execute ((s)->size())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def printNumbers(arr,n):
    arr.sort()
    A,B=arr[n-1],-1
    for i in range(n-2,-1,-1):
        if A % arr[i]!=0 :
            B=arr[i]
            break
        if i-1>=0 and arr[i]==arr[i-1]:
            B=arr[i]
            break
    print("A=",A,",B=",B)
if __name__=="__main__" :
    arr=[1,2,4,8,16,1,2,4]
    n=len(arr)
    printNumbers(arr,n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      arr := Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{8}->union(Sequence{16}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 4 }))))))) ;
    n := (arr)->size() ;
    printNumbers(arr, n)
    ) else skip;
  operation printNumbers(arr : OclAny, n : OclAny)
  pre: true post: true
  activity:
    arr := arr->sort() ;
    var A : OclAny := null;
    var B : OclAny := null;
    Sequence{A,B} := Sequence{arr[n - 1+1],-1} ;
    for i : Integer.subrange(-1 + 1, n - 2)->reverse() do (    if A mod arr[i+1] /= 0 then (
      var B : OclAny := arr[i+1] ;
    break
    ) else skip ;
    if i - 1 >= 0 & arr[i+1] = arr[i - 1+1] then (
      B := arr[i+1] ;
    break
    ) else skip) ;
    execute ("A=")->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from itertools import*
R=lambda : map(int,input().split())
n,k=R()
a=list(zip(R(),R()))
print(sum(x*y for x,y in a)+max(accumulate(x-x*y-u+u*v for(u,v),(x,y)in zip([(0,0)]*k+a,a))))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := R->apply() ;
    var a : Sequence := (Integer.subrange(1, R->apply()->size())->collect( _indx | Sequence{R->apply()->at(_indx), R->apply()->at(_indx)} )) ;
    execute (((argument (test (logical_test (comparison (expr (expr (atom (name x))) * (expr (atom (name y))))))) (comp_for for (exprlist (expr (atom (name x))) , (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name a))))))))->sum() + (accumulate((argument (test (logical_test (comparison (expr (expr (expr (expr (atom (name x))) - (expr (expr (atom (name x))) * (expr (atom (name y))))) - (expr (atom (name u)))) + (expr (expr (atom (name u))) * (expr (atom (name v)))))))) (comp_for for (exprlist (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name u)))))) , (test (logical_test (comparison (expr (atom (name v))))))) ))) , (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name x)))))) , (test (logical_test (comparison (expr (atom (name y))))))) )))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) , (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ))))))) ])) * (expr (atom (name k)))) + (expr (atom (name a)))))))) , (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))))))))->max())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while 1 :
    n,m,p=map(int,raw_input().split())
    if n==0 : break
    x=[int(raw_input())for i in range(n)]
    print(100-p)*sum(x)/x[m-1]if x[m-1]!=0 else 0
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while 1 do (    var n : OclAny := null;
    var m : OclAny := null;
    var p : OclAny := null;
    Sequence{n,m,p} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if n = 0 then (
      break
    ) else skip ;
    var x : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + ((raw_input())))->toInteger())) ;
(test (logical_test (comparison (expr (expr (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (number (integer 100)))) - (expr (atom (name p))))))))) )))) * (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))) / (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name m))) - (expr (atom (number (integer 1)))))))))) ])))))) if (logical_test (comparison (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name m))) - (expr (atom (number (integer 1)))))))))) ])))) != (comparison (expr (atom (number (integer 0))))))) else (test (logical_test (comparison (expr (atom (number (integer 0)))))))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf=10**3
eps=1.0/10**10
mod=10**9+7
def LI(): return[int(x)for x in sys.stdin.readline().split()]
def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return[float(x)for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s,flush=True)
def main():
    rr=[]
    while True :
        n,m,p=LI()
        if n==0 :
            break
        a=[I()for _ in range(n)]
        s=sum(a)*100*(100-p)//100
        if a[m-1]==0 :
            rr.append(0)
        else :
            rr.append(s//a[m-1])
    return '\n'.join(map(str,rr))
print(main())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    sys.setrecursionlimit((10)->pow(7)) ;
    var Math_PINFINITY : double := (10)->pow(3) ;
    var eps : double := 1.0 / (10)->pow(10) ;
    var mod : double := (10)->pow(9) + 7 ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    execute (main())->display();
  operation LI() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()));
  operation LI_() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1));
  operation LF() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal()));
  operation LS() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine().split();
  operation I() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation F() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toReal();
  operation S() : OclAny
  pre: true post: true
  activity:
    return (OclFile["System.in"]).readLine();
  operation pf(s : OclAny) : OclAny
  pre: true post: true
  activity:
    return (s)->display();
  operation main() : OclAny
  pre: true post: true
  activity:
    var rr : Sequence := Sequence{} ;
    while true do (    var n : OclAny := null;
    var m : OclAny := null;
    var p : OclAny := null;
    Sequence{n,m,p} := LI() ;
    if n = 0 then (
      break
    ) else skip ;
    var a : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (I())) ;
    s := (a)->sum() * 100 * (100 - p) div 100 ;
    if a[m - 1+1] = 0 then  (
      execute ((0) : rr)
    )
    else (
      execute ((s div a[m - 1+1]) : rr)
      )) ;
    return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), '
');
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
result_all=[]
counter=0
while True :
    N,M,P=map(int,input().split())
    if(N==0 and M==0 and P==0): break
    X=[int(input())for i in range(N)]
    X_sum=sum(X)
    if(X[M-1]==0):
        result_all.append(0)
        continue
    result=((X_sum*100)-((X_sum*100)*(P/100)))/X[M-1]
    result_all.append(result)
for i in range(len(result_all)):
    print(int(result_all[i]))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var result_all : Sequence := Sequence{} ;
    var counter : int := 0 ;
    while true do (    var N : OclAny := null;
    var M : OclAny := null;
    var P : OclAny := null;
    Sequence{N,M,P} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if (N = 0 & M = 0 & P = 0) then (
      break
    ) else skip ;
    var X : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ;
    var X_sum : OclAny := (X)->sum() ;
    if (X[M - 1+1] = 0) then (
      execute ((0) : result_all) ;
    continue
    ) else skip ;
    var result : double := ((X_sum * 100) - ((X_sum * 100) * (P / 100))) / X[M - 1+1] ;
    execute ((result) : result_all)) ;
    for i : Integer.subrange(0, (result_all)->size()-1) do (    execute (("" + ((result_all[i+1])))->toInteger())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import array
import math
def solve(m,p,xs):
    total_prize=sum(xs)*(100-p)
    number_of_winners=xs[m-1]
    if not number_of_winners :
        return 0
    else :
        return math.floor(total_prize/number_of_winners)
if __name__=="__main__" :
    while True :
        n,m,p=map(int,input().split())
        if n==0 and m==0 and p==0 :
            break
        xs=array.array("H",(int(input())for i in range(n)))
        print(solve(m,p,xs))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      while true do (    var n : OclAny := null;
    Sequence{n,m,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if n = 0 & m = 0 & p = 0 then (
      break
    ) else skip ;
    xs := array.array("H", Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))}) ;
    execute (solve(m, p, xs))->display())
    ) else skip;
  operation solve(m : OclAny, p : OclAny, xs : OclAny) : OclAny
  pre: true post: true
  activity:
    var total_prize : double := (xs)->sum() * (100 - p) ;
    var number_of_winners : OclAny := xs[m - 1+1] ;
    if not(number_of_winners) then  (
      return 0
    )
    else (
      return (total_prize / number_of_winners)->floor()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
import queue
def main():
    n=int(input())
    nnn=list(map(int,input().split()))
    ppp=nnn[: n]
    ccc=nnn[n : 2*n]
    bbb=nnn[2*n :]
    pp_v=[0]*(n+1)
    ppq=queue.PriorityQueue()
    for v in ppp :
        ppq.put(v)
    pre=sum(ppp)
    pp_v[0]=pre
    for i,v in enumerate(ccc):
        ppq.put(v)
        t=ppq.get()
        pre=pre+v-t
        pp_v[i+1]=pre
    bb_v=[0]*(n+1)
    bbq=queue.PriorityQueue()
    for v in bbb :
        bbq.put(-v)
    pre=-1*sum(bbb)
    bb_v[0]=pre
    for i,v in enumerate(ccc[: :-1]):
        bbq.put(-v)
        t=bbq.get()
        pre=pre+(-v)-(t)
        bb_v[i+1]=pre
    dd=[p+q for p,q in zip(pp_v,bb_v[: :-1])]
    ans=max(dd)
    print(ans)
isTest=False
def pa(v):
    if isTest :
        print(v)
if __name__=="__main__" :
    if sys.platform=='ios' :
        sys.stdin=open('inputFile.txt')
        isTest=True
    else :
        pass
    ret=main()
    if ret is not None :
        print(ret)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    var isTest : boolean := false ;
    skip ;
    if __name__ = "__main__" then (
      if OclProcess.getEnvironmentProperty("OS") = 'ios' then  (
      OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('inputFile.txt')) ;
    isTest := true
    )
    else (
      skip
      ) ;
    var ret : OclAny := main() ;
    if not(ret <>= null) then (
      execute (ret)->display()
    ) else skip
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var nnn : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var ppp : OclAny := nnn.subrange(1,n) ;
    var ccc : OclAny := nnn.subrange(n+1, 2 * n) ;
    var bbb : OclAny := nnn.subrange(2 * n+1) ;
    var pp_v : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ;
    var ppq : OclAny := queue.PriorityQueue() ;
    for v : ppp do (    ppq.put(v)) ;
    var pre : OclAny := (ppp)->sum() ;
    pp_v->first() := pre ;
    for _tuple : Integer.subrange(1, (ccc)->size())->collect( _indx | Sequence{_indx-1, (ccc)->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var v : OclAny := _tuple->at(_indx);
      ppq.put(v) ;
    var t : OclAny := ppq.get() ;
    pre := pre + v - t ;
    pp_v[i + 1+1] := pre) ;
    var bb_v : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ;
    var bbq : OclAny := queue.PriorityQueue() ;
    for v : bbb do (    bbq.put(-v)) ;
    pre := -1 * (bbb)->sum() ;
    bb_v->first() := pre ;
    for _tuple : Integer.subrange(1, (ccc(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->size())->collect( _indx | Sequence{_indx-1, (ccc(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var v : OclAny := _tuple->at(_indx);
      bbq.put(-v) ;
    t := bbq.get() ;
    pre := pre + (-v) - (t) ;
    bb_v[i + 1+1] := pre) ;
    var dd : Sequence := Integer.subrange(1, pp_v->size())->collect( _indx | Sequence{pp_v->at(_indx), bb_v(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->at(_indx)} )->select(_tuple | true)->collect(_tuple | let p : OclAny = _tuple->at(1) in let q : OclAny = _tuple->at(2) in (p + q)) ;
    var ans : OclAny := (dd)->max() ;
    execute (ans)->display();
  operation pa(v : OclAny)
  pre: true post: true
  activity:
    if isTest then (
      execute (v)->display()
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
ansli=[]
while 1 :
    a=input().split()
    if a[0]=="0" and a[1]=="0" and a[2]=="0" :
        break
    for i in range(len(a)):
        a[i]=int(a[i])
    x=[]
    for i in range(a[0]):
        x.append(int(input()))
    sum0=0
    for i in x :
        sum0+=i
    sum=sum0*(100-a[2])
    hit=x[a[1]-1]
    if hit==0 :
        ansli.append(0)
    else :
        ansli.append(int(sum/hit))
for i in ansli :
    print(i)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var ansli : Sequence := Sequence{} ;
    while 1 do (    var a : OclAny := input().split() ;
    if a->first() = "0" & a[1+1] = "0" & a[2+1] = "0" then (
      break
    ) else skip ;
    for i : Integer.subrange(0, (a)->size()-1) do (    a[i+1] := ("" + ((a[i+1])))->toInteger()) ;
    var x : Sequence := Sequence{} ;
    for i : Integer.subrange(0, a->first()-1) do (    execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : x)) ;
    var sum0 : int := 0 ;
    for i : x do (    sum0 := sum0 + i) ;
    var sum : double := sum0 * (100 - a[2+1]) ;
    var hit : OclAny := x[a[1+1] - 1+1] ;
    if hit = 0 then  (
      execute ((0) : ansli)
    )
    else (
      execute ((("" + ((sum / hit)))->toInteger()) : ansli)
      )) ;
    for i : ansli do (    execute (i)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def minOperations(a,n,K):
    map=dict.fromkeys(a,False);
    for i in range(n):
        if(map[a[i]]):
            return 0 ;
        map[a[i]]=True ;
    b=[0]*n ;
    for i in range(n):
        b[i]=a[i]^ K ;
    map.clear();
    for i in range(n):
        if(a[i]!=b[i]):
            map[b[i]]=True ;
    for i in range(n):
        if a[i]in map :
            return 1 ;
    map.clear();
    for i in range(n):
        if b[i]in map :
            return 2 ;
        map[b[i]]=True ;
    return-1 ;
if __name__=="__main__" :
    K=3 ;
    a=[1,9,4,3];
    n=len(a);
    print(minOperations(a,n,K));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      K := 3; ;
    a := Sequence{1}->union(Sequence{9}->union(Sequence{4}->union(Sequence{ 3 }))); ;
    n := (a)->size(); ;
    execute (minOperations(a, n, K))->display();
    ) else skip;
  operation minOperations(a : OclAny, n : OclAny, K : OclAny)
  pre: true post: true
  activity:
    var map : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name False)))))))) ))); ;
    for i : Integer.subrange(0, n-1) do (    if (([a[i+1]+1]`third)->collect( _x | ([a[i+1]+1])->apply(_x) )) then (
      return 0;
    ) else skip ;
    ([a[i+1]+1]`third)->collect( _x | ([a[i+1]+1])->apply(_x) ) := true;) ;
    var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ;
    for i : Integer.subrange(0, n-1) do (    b[i+1] := MathLib.bitwiseXor(a[i+1], K);) ;
    execute (map /<: map); ;
    for i : Integer.subrange(0, n-1) do (    if (a[i+1] /= b[i+1]) then (
      ([b[i+1]+1]`third)->collect( _x | ([b[i+1]+1])->apply(_x) ) := true;
    ) else skip) ;
    for i : Integer.subrange(0, n-1) do (    if (map)->includes(a[i+1]) then (
      return 1;
    ) else skip) ;
    execute (map /<: map); ;
    for i : Integer.subrange(0, n-1) do (    if (map)->includes(b[i+1]) then (
      return 2;
    ) else skip ;
    ([b[i+1]+1]`third)->collect( _x | ([b[i+1]+1])->apply(_x) ) := true;) ;
    return -1;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def minOperations(a,n,K):
    map=dict.fromkeys(a,0);
    for i in range(n):
        if(map[a[i]]):
            return 0 ;
        map[a[i]]=True ;
    b=[0]*n ;
    for i in range(n):
        b[i]=a[i]| K ;
    map.clear();
    for i in range(n):
        if(a[i]!=b[i]):
            map[b[i]]=True ;
    for i in range(n):
        if a[i]not in map :
            pass
        elif(map[a[i]]):
            return 1 ;
    map.clear();
    for i in range(n):
        if(map[b[i]]):
            return 2 ;
        map[b[i]]=true ;
    return-1 ;
if __name__=="__main__" :
    K=3 ;
    a=[1,9,4,3];
    n=len(a);
    print(minOperations(a,n,K));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      K := 3; ;
    a := Sequence{1}->union(Sequence{9}->union(Sequence{4}->union(Sequence{ 3 }))); ;
    n := (a)->size(); ;
    execute (minOperations(a, n, K))->display();
    ) else skip;
  operation minOperations(a : OclAny, n : OclAny, K : OclAny)
  pre: true post: true
  activity:
    var map : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))); ;
    for i : Integer.subrange(0, n-1) do (    if (([a[i+1]+1]`third)->collect( _x | ([a[i+1]+1])->apply(_x) )) then (
      return 0;
    ) else skip ;
    ([a[i+1]+1]`third)->collect( _x | ([a[i+1]+1])->apply(_x) ) := true;) ;
    var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ;
    for i : Integer.subrange(0, n-1) do (    b[i+1] := MathLib.bitwiseOr(a[i+1], K);) ;
    execute (map /<: map); ;
    for i : Integer.subrange(0, n-1) do (    if (a[i+1] /= b[i+1]) then (
      ([b[i+1]+1]`third)->collect( _x | ([b[i+1]+1])->apply(_x) ) := true;
    ) else skip) ;
    for i : Integer.subrange(0, n-1) do (    if (map)->excludes(a[i+1]) then  (
      skip
    )
    else (if (([a[i+1]+1]`third)->collect( _x | ([a[i+1]+1])->apply(_x) )) then
   (
      return 1;    
)
 else skip)) ;
    execute (map /<: map); ;
    for i : Integer.subrange(0, n-1) do (    if (([b[i+1]+1]`third)->collect( _x | ([b[i+1]+1])->apply(_x) )) then (
      return 2;
    ) else skip ;
    ([b[i+1]+1]`third)->collect( _x | ([b[i+1]+1])->apply(_x) ) := true;) ;
    return -1;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def spellsCount(num):
    n=len(num);
    result=1 ;
    i=0 ;
    while(idisplay();;
  operation spellsCount(num : OclAny)
  pre: true post: true
  activity:
    var n : int := (num)->size(); ;
    var result : int := 1; ;
    var i : int := 0; ;
    while ((i->compareTo(n)) < 0) do (    var count : int := 1; ;
    while ((i->compareTo(n - 1)) < 0 & num[i + 1+1] = num[i+1]) do (    count := count + 1; ;
    i := i + 1;) ;
    result := result * ("" + (((2)->pow(count - 1))))->toInteger(); ;
    i := i + 1;) ;
    return result;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import eulerlib
def compute():
    state=list(range(1,11))
    max=None
    while True :
        sum=state[0]+state[5]+state[6]
        if state[1]+state[6]+state[7]==sum and state[2]+state[7]+state[8]==sum and state[3]+state[8]+state[9]==sum and state[4]+state[9]+state[5]==sum :
            minouterindex=0
            minouter=state[0]
            for i in range(1,5):
                if state[i]max):
                max=s
        if not eulerlib.next_permutation(state):
            break
    assert max is not None
    return max
if __name__=="__main__" :
    print(compute())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      execute (compute())->display()
    ) else skip;
  operation compute() : OclAny
  pre: true post: true
  activity:
    var state : Sequence := (Integer.subrange(1, 11-1)) ;
    var max : OclAny := null ;
    while true do (    var sum : OclAny := state->first() + state[5+1] + state[6+1] ;
    if state[1+1] + state[6+1] + state[7+1] = sum & state[2+1] + state[7+1] + state[8+1] = sum & state[3+1] + state[8+1] + state[9+1] = sum & state[4+1] + state[9+1] + state[5+1] = sum then (
      var minouterindex : int := 0 ;
    var minouter : OclAny := state->first() ;
    for i : Integer.subrange(1, 5-1) do (    if (state[i+1]->compareTo(minouter)) < 0 then (
      minouterindex := i ;
    minouter := state[i+1]
    ) else skip) ;
    var s : String := "" ;
    for i : Integer.subrange(0, 5-1) do (    s := s + ("" + ((state[(minouterindex + i) mod 5+1]))) ;
    s := s + ("" + ((state[(minouterindex + i) mod 5 + 5+1]))) ;
    s := s + ("" + ((state[(minouterindex + i + 1) mod 5 + 5+1])))) ;
    if (s)->size() = 16 & (max <>= null or s > max) then (
      max := s
    ) else skip
    ) else skip ;
    if not(eulerlib.next_permutation(state)) then (
      break
    ) else skip) ;
    assert not(max <>= null) do "assertion failed" ;
    return max;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def newvol(x):
    print("percentage increase" "in the volume of the cube is ",((x**(3))/10000+3*x+(3*(x**(2)))/100),"%");
x=10 ;
newvol(x);
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    x := 10; ;
    newvol(x);;
  operation newvol(x : OclAny)
  pre: true post: true
  activity:
    execute ((atom "percentage increase" "in the volume of the cube is "))->display();;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
[n,k]=map(int,input().split(" "))
t=list(map(int,input().split(" ")))
s=list(map(int,input().split(" ")))
bs=[0]
cs=[0]
for i in range(n):
    if s[i]==1 :
        bs+=[bs[i]+t[i]]
    else :
        bs+=[bs[-1]]
    cs+=[cs[i]+t[i]]
b=[]
c=[]
for i in range(n-k+1):
    b+=[bs[i+k]-bs[i]]
    c+=[cs[i+k]-cs[i]]
d=[]
for i in range(len(b)):
    d+=[c[i]-b[i]]
a=bs[-1]
ans=max(d)+a
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     Sequence{n}->union(Sequence{ k }) := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ;
    var t : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ;
    var s : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ;
    var bs : Sequence := Sequence{ 0 } ;
    var cs : Sequence := Sequence{ 0 } ;
    for i : Integer.subrange(0, n-1) do (    if s[i+1] = 1 then  (
      bs := bs + Sequence{ bs[i+1] + t[i+1] }
    )
    else (
      bs := bs + Sequence{ bs->last() }
      ) ;
    cs := cs + Sequence{ cs[i+1] + t[i+1] }) ;
    var b : Sequence := Sequence{} ;
    var c : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n - k + 1-1) do (    b := b + Sequence{ bs[i + k+1] - bs[i+1] } ;
    c := c + Sequence{ cs[i + k+1] - cs[i+1] }) ;
    var d : Sequence := Sequence{} ;
    for i : Integer.subrange(0, (b)->size()-1) do (    d := d + Sequence{ c[i+1] - b[i+1] }) ;
    var a : OclAny := bs->last() ;
    var ans : OclAny := (d)->max() + a ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def newvol(x):
    print("percentage increase in the volume of the cylinder is ",x,"%")
x=10.0
newvol(x)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    x := 10.0 ;
    newvol(x);
  operation newvol(x : OclAny)
  pre: true post: true
  activity:
    execute ("percentage increase in the volume of the cylinder is ")->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def newvol(x):
    print("percentage increase in the",pow(x,3)/10000+3*x+(3*pow(x,2))/100,"%")DEDENT x=10.0
    newvol(x)

------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip;
  operation newvol(x : OclAny)
  pre: true post: true
  activity:
    execute ("percentage increase in the")->display() ;
 ;
    x := 10.0 ;
    newvol(x);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
readline=sys.stdin.readline
write=sys.stdout.write
def main():
    MOD=10**9+7
    def query(k0):
        s=0
        k=k0
        while k :
            s+=data[k]
            k-=k &-k
        k=k0
        while k<=N :
            data[k]+=1
            k+=k &-k
        return s % MOD
    L=100000
    fact=[1]*(L+1)
    rfact=[1]*(L+1)
    r=1
    for i in range(2,L+1):
        fact[i]=r=i*r % MOD
    rfact[i]=r=pow(fact[i],MOD-2,MOD)
    for i in range(L,0,-1):
        rfact[i-1]=r=i*r % MOD
    while 1 :
        N=int(readline())
        if N==0 :
            break
        R=int(readline())
*S,=range(N)
        for i in range(R):
            s,t=map(int,readline().split()); s-=1 ; t-=1
            S[s],S[t]=S[t],S[s]
        data=[0]*(N+1)
        write("%d\n" %(sum(fact[N-1-i]*(e-query(e+1))% MOD for i,e in enumerate(S))% MOD))
main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var readline : OclAny := (OclFile["System.in"]).readline ;
    var write : OclAny := (OclFile["System.out"]).write ;
    skip ;
(testlist_star_expr (star_expr * (expr (atom (name S)))) ,)    Sequence{(testlist_star_expr (star_expr * (expr (atom (name S)))) ,)} := Integer.subrange(0, N-1);
  operation main()
  pre: true post: true
  activity:
    var MOD : double := (10)->pow(9) + 7 ;
    skip ;
    var L : int := 100000 ;
    var fact : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (L + 1)) ;
    var rfact : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (L + 1)) ;
    var r : int := 1 ;
    for i : Integer.subrange(2, L + 1-1) do (    fact[i+1] := i * r mod MOD; r := i * r mod MOD) ;
    rfact[i+1] := (fact[i+1])->pow(MOD - 2); r := (fact[i+1])->pow(MOD - 2) ;
    for i : Integer.subrange(0 + 1, L)->reverse() do (    rfact[i - 1+1] := i * r mod MOD; r := i * r mod MOD) ;
    while 1 do (    var N : int := ("" + ((readline())))->toInteger() ;
    if N = 0 then (
      break
    ) else skip ;
    var R : int := ("" + ((readline())))->toInteger());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
class HeapQueue :
    from heapq import heappop,heappush,heappushpop,heapreplace
    def __init__(self,reverse=False):
        self.reverse=reverse
        self.heap=[]
    def __len__(self):
        return len(self.heap)
    def append(self,p,v):
        self.heappush(self.heap,(-p if self.reverse else p,v))
    def appendpop(self,p,v):
        return self.heappushpop(self.heap,(-p if self.reverse else p,v))[1]
    def popappend(self,p,v):
        return self.heapreplace(self.heap,(-p if self.reverse else p,v))[1]
    def pop(self):
        return self.heappop(self.heap)[1]
    def front(self):
        return self.heap[0][1]
N=int(input())
A=[int(s)for s in input().split()]
S=[]
T=[]
S.append(sum(A[: N]))
q=HeapQueue()
for a in A[: N]:
    q.append(a,a)
for a in A[N : 2*N]:
    m=q.appendpop(a,a)
    S.append(S[-1]+a-m)
T.append(sum(A[-N :]))
q=HeapQueue(reverse=True)
for a in A[-N :]:
    q.append(a,a)
for a in A[-N-1 : N-1 :-1]:
    m=q.appendpop(a,a)
    T.append(T[-1]+a-m)
ans=max([S[i]-T[N-i]for i in range(N+1)])
print(ans)
------------------------------------------------------------
OCL File:
---------
class HeapQueue {
  static operation newHeapQueue() : HeapQueue
  pre: true
  post: HeapQueue->exists( _x | result = _x );
  attribute reverse : OclAny := reverse;
  attribute heap : Sequence := Sequence{};
  operation initialise(reverse : OclAny) : HeapQueue
  pre: true post: true
  activity:
    self.reverse := reverse ;
    self.heap := Sequence{};
    return self;
  operation __len__() : OclAny
  pre: true post: true
  activity:
    return (self.heap)->size();
  operation append(p : OclAny,v : OclAny)
  pre: true post: true
  activity:
    self.heappush(self.heap, Sequence{if self.reverse then -p else p endif, v});
  operation appendpop(p : OclAny,v : OclAny) : OclAny
  pre: true post: true
  activity:
    return self.heappushpop(self.heap, Sequence{if self.reverse then -p else p endif, v})[1+1];
  operation popappend(p : OclAny,v : OclAny) : OclAny
  pre: true post: true
  activity:
    return self.heapreplace(self.heap, Sequence{if self.reverse then -p else p endif, v})[1+1];
  operation pop() : OclAny
  pre: true post: true
  activity:
    return self.heappop(self.heap)[1+1];
  operation front() : OclAny
  pre: true post: true
  activity:
    return self.heap->first()[1+1];
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var A : Sequence := input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ;
    var S : Sequence := Sequence{} ;
    var T : Sequence := Sequence{} ;
    execute (((A.subrange(1,N))->sum()) : S) ;
    var q : HeapQueue := (HeapQueue.newHeapQueue()).initialise() ;
    for a : A.subrange(1,N) do (    execute ((a, a) : q)) ;
    for a : A.subrange(N+1, 2 * N) do (    var m : OclAny := q.appendpop(a, a) ;
    execute ((S->last() + a - m) : S)) ;
    execute (((A.subrange(-N+1))->sum()) : T) ;
    q := (HeapQueue.newHeapQueue()).initialise((argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ;
    for a : A.subrange(-N+1) do (    execute ((a, a) : q)) ;
    for a : A(subscript (test (logical_test (comparison (expr (expr - (expr (atom (name N)))) - (expr (atom (number (integer 1)))))))) : (test (logical_test (comparison (expr (expr (atom (name N))) - (expr (atom (number (integer 1)))))))) (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do (    m := q.appendpop(a, a) ;
    execute ((T->last() + a - m) : T)) ;
    var ans : OclAny := (Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (S[i+1] - T[N - i+1])))->max() ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def solve():
    from sys import stdin
    m=1000000007
    f_i=stdin
    while True :
        N=int(f_i.readline())
        if N==0 :
            break
        w=list(range(N))
        R=int(f_i.readline())
        for i in range(R):
            s,t=map(int,f_i.readline().split())
            s-=1
            t-=1
            w[s],w[t]=w[t],w[s]
        s=[(i,c)for i,c in enumerate(w)if i!=c]
        s.sort(reverse=True)
        a=1
        f=1
        cnt=0
        for c1,i in zip(w[: :-1],range(N-1,-1,-1)):
            if c1>i :
                l=c1
                n=c1-i-1
            else :
                l=i
                n=0
            for j,c2 in s :
                if j<=i :
                    break
                else :
                    if jtoInteger() ;
    if N = 0 then (
      break
    ) else skip ;
    var w : Sequence := (Integer.subrange(0, N-1)) ;
    var R : int := ("" + ((f_i.readLine())))->toInteger() ;
    for i : Integer.subrange(0, R-1) do (    var s : OclAny := null;
    var t : OclAny := null;
    Sequence{s,t} := (f_i.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    s := s - 1 ;
    t := t - 1 ;
    var w[s+1] : OclAny := null;
    var w[t+1] : OclAny := null;
    Sequence{w[s+1],w[t+1]} := Sequence{w[t+1],w[s+1]}) ;
    var s : Sequence := Integer.subrange(1, (w)->size())->collect( _indx | Sequence{_indx-1, (w)->at(_indx)} )->select(_tuple | let i : OclAny = _tuple->at(1) in let c : OclAny = _tuple->at(2) in i /= c)->collect(_tuple | let i : OclAny = _tuple->at(1) in let c : OclAny = _tuple->at(2) in (Sequence{i, c})) ;
    s := s->sort() ;
    var a : int := 1 ;
    var f : int := 1 ;
    var cnt : int := 0 ;
    for _tuple : Integer.subrange(1, w(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->size())->collect( _indx | Sequence{w(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->at(_indx), Integer.subrange(-1 + 1, N - 1)->reverse()->at(_indx)} ) do (var _indx : int := 1;
      var c1 : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var i : OclAny := _tuple->at(_indx);
      if (c1->compareTo(i)) > 0 then  (
      var l : OclAny := c1 ;
    var n : double := c1 - i - 1
    )
    else (
      l := i ;
    n := 0
      ) ;
    for _tuple : s do (var _indx : int := 1;
      var j : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var c2 : OclAny := _tuple->at(_indx);
      if (j->compareTo(i)) <= 0 then  (
      break
    )
    else (
      if (j->compareTo(l)) < 0 then (
      n := n - 1
    ) else skip ;
    if (c2->compareTo(c1)) < 0 then (
      n := n + 1
    ) else skip
      )) ;
    cnt := (cnt + (n * a) mod m) mod m ;
    a := (a * f) mod m ;
    f := f + 1) ;
    execute (cnt)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
print(6*n*(n-1)+1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    execute (6 * n * (n - 1) + 1)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=int(input())+1
print(1+6*(a*(a-1)//2+(a-2)*(a-3)//2-1))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() + 1 ;
    execute (1 + 6 * (a * (a - 1) div 2 + (a - 2) * (a - 3) div 2 - 1))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def f(x):
    n=1
    for i in range(x):
        n+=i*12
    return n
print(f(int(input())),end="")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    execute (f(("" + (((OclFile["System.in"]).readLine())))->toInteger()))->display();
  operation f(x : OclAny) : OclAny
  pre: true post: true
  activity:
    var n : int := 1 ;
    for i : Integer.subrange(0, x-1) do (    n := n + i * 12) ;
    return n;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
print(6*n*(n-1)+1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    execute (6 * n * (n - 1) + 1)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
print(6*n*n-6*n+1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    execute (6 * n * n - 6 * n + 1)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
S,T=read().split()
print(len([x for x,y in zip(S,T)if x==y]))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var read : OclAny := sys.stdin.buffer.read ;
    var readline : OclAny := sys.stdin.buffer.readline ;
    var readlines : OclAny := sys.stdin.buffer.readlines ;
    sys.setrecursionlimit((10)->pow(7)) ;
    var S : OclAny := null;
    var T : OclAny := null;
    Sequence{S,T} := read().split() ;
    execute ((Integer.subrange(1, S->size())->collect( _indx | Sequence{S->at(_indx), T->at(_indx)} )->select(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in x = y)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (x)))->size())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,k=map(int,input().split()); sm=0
arr=list(map(int,input().split()))
l=list(map(int,input().split()))
for x in range(n):
    if l[x]: sm+=arr[x]; arr[x]=0
cs=[arr[0]]
for x in range(1,n): cs.append(cs[x-1]+arr[x])
s=cs[k-1]
for x in range(1,n-k+1): s=max(s,cs[x+k-1]-cs[x-1])
print(sm+s)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) );    var sm : int := 0 ;
    var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    for x : Integer.subrange(0, n-1) do (    if l[x+1] then (
      sm := sm + arr[x+1];    arr[x+1] := 0
    ) else skip) ;
    var cs : Sequence := Sequence{ arr->first() } ;
    for x : Integer.subrange(1, n-1) do (    execute ((cs[x - 1+1] + arr[x+1]) : cs)) ;
    var s : OclAny := cs[k - 1+1] ;
    for x : Integer.subrange(1, n - k + 1-1) do (    s := Set{s, cs[x + k - 1+1] - cs[x - 1+1]}->max()) ;
    execute (sm + s)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
S=str(input())
T=str(input())
if S[0]==T[0]and S[1]==T[1]and S[2]==T[2]:
    print("3")
elif S[0]==T[0]and S[1]==T[1]and S[2]!=T[2]:
    print("2")
elif S[0]==T[0]and S[1]!=T[1]and S[2]==T[2]:
    print("2")
elif S[0]!=T[0]and S[1]==T[1]and S[2]==T[2]:
    print("2")
elif S[0]==T[0]and S[1]!=T[1]and S[2]!=T[2]:
    print("1")
elif S[0]!=T[0]and S[1]==T[1]and S[2]!=T[2]:
    print("1")
elif S[0]!=T[0]and S[1]!=T[1]and S[2]==T[2]:
    print("1")
else :
    print("0")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var S : String := ("" + (((OclFile["System.in"]).readLine()))) ;
    var T : String := ("" + (((OclFile["System.in"]).readLine()))) ;
    if S->first() = T->first() & S[1+1] = T[1+1] & S[2+1] = T[2+1] then  (
      execute ("3")->display()
    )
    else (if S->first() = T->first() & S[1+1] = T[1+1] & S[2+1] /= T[2+1] then
   (
      execute ("2")->display()    
)
    else (if S->first() = T->first() & S[1+1] /= T[1+1] & S[2+1] = T[2+1] then
   (
      execute ("2")->display()    
)
    else (if S->first() /= T->first() & S[1+1] = T[1+1] & S[2+1] = T[2+1] then
   (
      execute ("2")->display()    
)
    else (if S->first() = T->first() & S[1+1] /= T[1+1] & S[2+1] /= T[2+1] then
   (
      execute ("1")->display()    
)
    else (if S->first() /= T->first() & S[1+1] = T[1+1] & S[2+1] /= T[2+1] then
   (
      execute ("1")->display()    
)
    else (if S->first() /= T->first() & S[1+1] /= T[1+1] & S[2+1] = T[2+1] then
   (
      execute ("1")->display()    
)
    else (
      execute ("0")->display()
      )    )
    )
    )
    )
    )
    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
S=input()
T=input()
print(sum([S[i]==T[i]for i in range(3)]))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var S : String := (OclFile["System.in"]).readLine() ;
    var T : String := (OclFile["System.in"]).readLine() ;
    execute ((Integer.subrange(0, 3-1)->select(i | true)->collect(i | (S[i+1] = T[i+1])))->sum())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def f(x):
    y=x[: n]; heapify(y); z=sum(y); s=[z]
    for i in x[n : n*2]: z+=i-heappushpop(y,i); s+=[z]
    return s
from heapq import*; n,*a=map(int,open(0).read().split()); print(max(map(sum,zip(f([-i for i in a[n :][: :-1]]),f(a)[: :-1]))))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip;    var n : OclAny := null;
    var a : OclAny := null;
    Sequence{n,a} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) );    execute (((Integer.subrange(1, f(a.subrange(n+1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->select(i | true)->collect(i | (-i)))->size())->collect( _indx | Sequence{f(a.subrange(n+1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->select(i | true)->collect(i | (-i)))->at(_indx), f(a)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->at(_indx)} ))->collect( _x | (sum)->apply(_x) ))->max())->display();
  operation f(x : OclAny) : OclAny
  pre: true post: true
  activity:
    var y : OclAny := x.subrange(1,n);    heapify(y);    var z : OclAny := (y)->sum();    var s : Sequence := Sequence{ z } ;
    for i : x.subrange(n+1, n * 2) do (    z := z + i - heappushpop(y, i);    s := s + Sequence{ z }) ;
    return s;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s=list(input())
t=list(input())
count=0
for si,ti in zip(s,t):
    if si==ti :
        count+=1
print(count)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ;
    var t : Sequence := ((OclFile["System.in"]).readLine())->characters() ;
    var count : int := 0 ;
    for _tuple : Integer.subrange(1, s->size())->collect( _indx | Sequence{s->at(_indx), t->at(_indx)} ) do (var _indx : int := 1;
      var si : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var ti : OclAny := _tuple->at(_indx);
      if si = ti then (
      count := count + 1
    ) else skip) ;
    execute (count)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import stdin,setrecursionlimit
def main():
    input=stdin.buffer.readline
    s=list(input()[:-1].decode())
    t=list(input()[:-1].decode())
    ans=0
    for i in range(3):
        if s[i]==t[i]:
            ans+=1
    print(ans)
if __name__=="__main__" :
    setrecursionlimit(10000)
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      setrecursionlimit(10000) ;
    main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var input : OclAny := stdin.buffer.readline ;
    var s : Sequence := (input()->front().decode()) ;
    var t : Sequence := (input()->front().decode()) ;
    var ans : int := 0 ;
    for i : Integer.subrange(0, 3-1) do (    if s[i+1] = t[i+1] then (
      ans := ans + 1
    ) else skip) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def minAbsSumPair(arr,arr_size):
    inv_count=0
    if arr_size<2 :
        print("Invalid Input")
        return
    min_l=0
    min_r=1
    min_sum=arr[0]+arr[1]
    for l in range(0,arr_size-1):
        for r in range(l+1,arr_size):
            sum=arr[l]+arr[r]
            if abs(min_sum)>abs(sum):
                min_sum=sum
                min_l=l
                min_r=r
    print("The two elements whose sum is minimum are",arr[min_l],"and ",arr[min_r])
arr=[1,60,-10,70,-80,85]
minAbsSumPair(arr,6);
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    arr := Sequence{1}->union(Sequence{60}->union(Sequence{-10}->union(Sequence{70}->union(Sequence{-80}->union(Sequence{ 85 }))))) ;
    minAbsSumPair(arr, 6);;
  operation minAbsSumPair(arr : OclAny, arr_size : OclAny)
  pre: true post: true
  activity:
    var inv_count : int := 0 ;
    if arr_size < 2 then (
      execute ("Invalid Input")->display() ;
    return
    ) else skip ;
    var min_l : int := 0 ;
    var min_r : int := 1 ;
    var min_sum : OclAny := arr->first() + arr[1+1] ;
    for l : Integer.subrange(0, arr_size - 1-1) do (    for r : Integer.subrange(l + 1, arr_size-1) do (    var sum : OclAny := arr[l+1] + arr[r+1] ;
    if ((min_sum)->abs()->compareTo((sum)->abs())) > 0 then (
      min_sum := sum ;
    min_l := l ;
    min_r := r
    ) else skip)) ;
    execute ("The two elements whose sum is minimum are")->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,k=map(int,input().split())
s=input()
a=[0]*26
for i in s :
    nomer=ord(i)-97
    a[nomer]+=1
for i in a :
    if i>k :
        print('NO')
        break
else :
    print('YES')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var s : String := (OclFile["System.in"]).readLine() ;
    var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ;
    for i : s->characters() do (    var nomer : double := (i)->char2byte() - 97 ;
    a[nomer+1] := a[nomer+1] + 1) ;
(compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name a))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name i)))) > (comparison (expr (atom (name k))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))))))))))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,k=map(int,input().split())
s=input().lower()
d={}
for i in s :
    if i in d :
        d[i]+=1
    else :
        d[i]=1
for i in d.values():
    if i>k :
        print('NO')
        break
else :
    print('YES')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var s : OclAny := input()->toLowerCase() ;
    var d : OclAny := Set{} ;
    for i : s do (    if (d)->includes(i) then  (
      d[i+1] := d[i+1] + 1
    )
    else (
      d[i+1] := 1
      )) ;
(compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name d)) (trailer . (name values) (arguments ( )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name i)))) > (comparison (expr (atom (name k))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))))))))))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=[0]*28
n,k=map(int,input().split())
s=input()
for i in s :
    a[ord(i)-ord('a')]+=1
if max(a)<=k :
    print("YES")
else :
    print("NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 28) ;
    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var s : String := (OclFile["System.in"]).readLine() ;
    for i : s->characters() do (    a[(i)->char2byte() - ('a')->char2byte()+1] := a[(i)->char2byte() - ('a')->char2byte()+1] + 1) ;
    if ((a)->max()->compareTo(k)) <= 0 then  (
      execute ("YES")->display()
    )
    else (
      execute ("NO")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
k=int(input().split()[1])
print('YNEOS'[max(map(input().count,map(chr,range(97,123))))>k : : 2])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var k : int := ("" + ((input().split()[1+1])))->toInteger() ;
    execute ('YNEOS'(subscript (test (logical_test (comparison (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name count))))))) , (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name chr))))))) , (argument (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 97)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 123))))))))) ))))))))) ))))))))) ))))))))) ))))) > (comparison (expr (atom (name k))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
shar,drug=map(int,input().split())
cvet=input()
cvet_n=[0]*26
for i in cvet :
    nomer=ord(i)-97
    cvet_n[nomer]+=1
cvet_n.sort(reverse=True)
mxc=max(cvet_n)
if mxc<=drug :
    print('YES')
else :
    print('NO')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var shar : OclAny := null;
    var drug : OclAny := null;
    Sequence{shar,drug} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var cvet : String := (OclFile["System.in"]).readLine() ;
    var cvet_n : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ;
    for i : cvet->characters() do (    var nomer : double := (i)->char2byte() - 97 ;
    cvet_n[nomer+1] := cvet_n[nomer+1] + 1) ;
    cvet_n := cvet_n->sort() ;
    var mxc : OclAny := (cvet_n)->max() ;
    if (mxc->compareTo(drug)) <= 0 then  (
      execute ('YES')->display()
    )
    else (
      execute ('NO')->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,k=map(int,input().split()); theo=list(map(int,input().split())); beha=list(map(int,input().split())); cum1=0 ; cum0=[]
for i in range(n):
    if beha[i]==1 : cum1+=theo[i]; theo[i]=0
cum0.append(theo[0])
for i in range(1,n):
    cum0.append(theo[i]+cum0[i-1])
mx=0
for i in range(n-k+1):
    if i==0 :
        x=cum0[i+k-1]
    else :
        x=cum0[i+k-1]-cum0[i-1]
    mx=max(mx,x)
print(mx+cum1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) );    var theo : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ));    var beha : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ));    var cum1 : int := 0;    var cum0 : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    if beha[i+1] = 1 then (
      cum1 := cum1 + theo[i+1];    theo[i+1] := 0
    ) else skip) ;
    execute ((theo->first()) : cum0) ;
    for i : Integer.subrange(1, n-1) do (    execute ((theo[i+1] + cum0[i - 1+1]) : cum0)) ;
    var mx : int := 0 ;
    for i : Integer.subrange(0, n - k + 1-1) do (    if i = 0 then  (
      var x : OclAny := cum0[i + k - 1+1]
    )
    else (
      x := cum0[i + k - 1+1] - cum0[i - 1+1]
      ) ;
    mx := Set{mx, x}->max()) ;
    execute (mx + cum1)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def loydTriangle(n):
    val=1
    for i in range(1,n+1):
        for j in range(1,i+1):
            print(val,end="")
            val+=1
        print("")
loydTriangle(6)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    loydTriangle(6);
  operation loydTriangle(n : OclAny)
  pre: true post: true
  activity:
    var val : int := 1 ;
    for i : Integer.subrange(1, n + 1-1) do (    for j : Integer.subrange(1, i + 1-1) do (    execute (val)->display() ;
    val := val + 1) ;
    execute ("")->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**7)
from heapq import heappop,heappush
n,*a=map(int,read().split())
a_rev=list(map(lambda x : int(x)*(-1),a[: :-1]))
def get_sum_list(a):
    h=[]
    res=[]
    cnt=0
    for i,aa in enumerate(a[: 2*n]):
        heappush(h,aa)
        cnt+=aa
        if i>=n :
            cnt-=heappop(h)
        if i>=n-1 :
            res.append(cnt)
    return res
left=get_sum_list(a)
right=get_sum_list(a_rev)
ans=-float('inf')
for i in range(n+1):
    memo=left[i]+right[n-i]
    if anspow(7)) ;
    skip ;
    var n : OclAny := null;
    var a : OclAny := null;
    Sequence{n,a} := (read().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a_rev : Sequence := ((a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() * (-1)))->apply(_x) )) ;
    skip ;
    var left : OclAny := get_sum_list(a) ;
    var right : OclAny := get_sum_list(a_rev) ;
    var ans : double := -("" + (('inf')))->toReal() ;
    for i : Integer.subrange(0, n + 1-1) do (    var memo : OclAny := left[i+1] + right[n - i+1] ;
    if (ans->compareTo(memo)) < 0 then (
      ans := memo
    ) else skip) ;
    execute (ans)->display();
  operation get_sum_list(a : OclAny) : OclAny
  pre: true post: true
  activity:
    var h : Sequence := Sequence{} ;
    var res : Sequence := Sequence{} ;
    var cnt : int := 0 ;
    for _tuple : Integer.subrange(1, (a.subrange(1,2 * n))->size())->collect( _indx | Sequence{_indx-1, (a.subrange(1,2 * n))->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var aa : OclAny := _tuple->at(_indx);
      heappush(h, aa) ;
    cnt := cnt + aa ;
    if (i->compareTo(n)) >= 0 then (
      cnt := cnt - heappop(h)
    ) else skip ;
    if (i->compareTo(n - 1)) >= 0 then (
      execute ((cnt) : res)
    ) else skip) ;
    return res;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
INT_MIN=-2**31
INT_MAX=2**31
class newNode():
    def __init__(self,data):
        self.data=data
        self.left=None
        self.right=None
def NumberOfBST(root):
    if(root==None):
        return 0,INT_MIN,INT_MAX,True
    if(root.left==None and root.right==None):
        return 1,root.data,root.data,True
    L=NumberOfBST(root.left)
    R=NumberOfBST(root.right)
    bst=[0]*4
    bst[2]=min(root.data,(min(L[2],R[2])))
    bst[1]=max(root.data,(max(L[1],R[1])))
    if(L[3]and R[3]and root.data>L[1]and root.dataexists( _x | result = _x );
  attribute data : OclAny := data;
  attribute left : OclAny := null;
  attribute right : OclAny := null;
  operation initialise(data : OclAny) : 
  pre: true post: true
  activity:
    self.data := data ;
    self.left := null ;
    self.right := null;
    return self;
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var INT_MIN : double := (-2)->pow(31) ;
    var INT_MAX : double := (2)->pow(31) ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      root := (newNode.newnewNode()).initialise(5) ;
    root.left := (newNode.newnewNode()).initialise(9) ;
    root.right := (newNode.newnewNode()).initialise(3) ;
    root.left.left := (newNode.newnewNode()).initialise(6) ;
    root.right.right := (newNode.newnewNode()).initialise(4) ;
    root.left.left.left := (newNode.newnewNode()).initialise(8) ;
    root.left.left.right := (newNode.newnewNode()).initialise(7) ;
    execute (NumberOfBST(root)->first())->display()
    ) else skip;
  operation NumberOfBST(root : OclAny) : OclAny
  pre: true post: true
  activity:
    if (root = null) then (
      return 0, INT_MIN, INT_MAX, true
    ) else skip ;
    if (root.left = null & root.right = null) then (
      return 1, root.data, root.data, true
    ) else skip ;
    var L : OclAny := NumberOfBST(root.left) ;
    var R : OclAny := NumberOfBST(root.right) ;
    var bst : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 4) ;
    bst[2+1] := Set{root.data, (Set{L[2+1], R[2+1]}->min())}->min() ;
    bst[1+1] := Set{root.data, (Set{L[1+1], R[1+1]}->max())}->max() ;
    if (L[3+1] & R[3+1] & (root.data->compareTo(L[1+1])) > 0 & (root.data->compareTo(R[2+1])) < 0) then  (
      bst[3+1] := true ;
    bst->first() := 1 + L->first() + R->first()
    )
    else (
      bst[3+1] := false ;
    bst->first() := L->first() + R->first()
      ) ;
    return bst;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def smallestIndex(a,n):
    right1=0
    right0=0
    for i in range(n):
        if(a[i]==1):
            right1=i
        else :
            right0=i
    return min(right1,right0)
if __name__=='__main__' :
    a=[1,1,1,0,0,1,0,1,1]
    n=len(a)
    print(smallestIndex(a,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      a := Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 1 })))))))) ;
    n := (a)->size() ;
    execute (smallestIndex(a, n))->display()
    ) else skip;
  operation smallestIndex(a : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var right1 : int := 0 ;
    var right0 : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    if (a[i+1] = 1) then  (
      right1 := i
    )
    else (
      right0 := i
      )) ;
    return Set{right1, right0}->min();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def MinimumSwapOperations(s):
    zero_exist=False
    multiple_of_2=False
    sum=0
    index_of_zero=0
    more_zero=False
    for i in range(len(s)):
        val=ord(s[i])-ord('0')
        if(zero_exist==True):
            more_zero=True
        if(val==0):
            zero_exist=True
            index_of_zero=i
        sum+=val
    if(zero_exist==False or sum % 3!=0):
        print("-1")
        return
    for i in range(len(s)):
        val=ord(s[i])-ord('0')
        if(val % 2==0 and i!=index_of_zero):
            multiple_of_2=True
    if(multiple_of_2==False):
        print("-1")
        return
    last_val=ord(s[len(s)-1])-ord('0')
    second_last_val=ord(s[len(s)-2])-ord('0')
    if(last_val==0 and second_last_val % 2==0):
        print(0)
    elif((last_val==0 and second_last_val % 2!=0)or(last_val % 2==0 and second_last_val==0)):
        print(1)
    elif(more_zero==True and(last_val==0 and second_last_val % 2!=0)):
        print(1)
    else :
        print(2)
if __name__=='__main__' :
    N="20"
    MinimumSwapOperations(N)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      var N : String := "20" ;
    MinimumSwapOperations(N)
    ) else skip;
  operation MinimumSwapOperations(s : OclAny)
  pre: true post: true
  activity:
    var zero_exist : boolean := false ;
    var multiple_of:= false : boolean := false ;
    var sum : int := 0 ;
    var index_of_zero : int := 0 ;
    var more_zero : boolean := false ;
    for i : Integer.subrange(0, (s)->size()-1) do (    var val : double := (s[i+1])->char2byte() - ('0')->char2byte() ;
    if (zero_exist = true) then (
      more_zero := true
    ) else skip ;
    if (val = 0) then (
      zero_exist := true ;
    index_of_zero := i
    ) else skip ;
    sum := sum + val) ;
    if (zero_exist = false or sum mod 3 /= 0) then (
      execute ("-1")->display() ;
    return
    ) else skip ;
    for i : Integer.subrange(0, (s)->size()-1) do (    val := (s[i+1])->char2byte() - ('0')->char2byte() ;
    if (val mod 2 = 0 & i /= index_of_zero) then (
      multiple_of:= true := true
    ) else skip) ;
    if (multiple_offalse = false) then (
      execute ("-1")->display() ;
    return
    ) else skip ;
    var last_val : double := (s[(s)->size() - 1+1])->char2byte() - ('0')->char2byte() ;
    var second_last_val : double := (s[(s)->size() - 2+1])->char2byte() - ('0')->char2byte() ;
    if (last_val = 0 & second_last_val mod 2 = 0) then  (
      execute (0)->display()
    )
    else (if ((last_val = 0 & second_last_val mod 2 /= 0) or (last_val mod 2 = 0 & second_last_val = 0)) then
   (
      execute (1)->display()    
)
    else (if (more_zero = true & (last_val = 0 & second_last_val mod 2 /= 0)) then
   (
      execute (1)->display()    
)
    else (
      execute (2)->display()
      )    )
    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from util import*
def main():
    r=reader("input")
    num=int(r.next())
    ans=[]
    for i in xrange(num):
        g1=int(r.next())
        row1=[]
        for j in xrange(4):
            if j==g1-1 :
                row1=map(int,r.next().split(" "))
            else :
                r.next()
        g2=int(r.next())
        row2=[]
        for j in xrange(4):
            if j==g2-1 :
                row2=map(int,r.next().split(" "))
            else :
                r.next()
        intersection=[x for x in row1 if x in row2]
        if len(intersection)==0 :
            ans.append("Volunteer cheated!")
        elif len(intersection)==1 :
            ans.append(intersection[0])
        else :
            ans.append("Bad magician!")
    write("output",ans)
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var r : OclAny := reader("input") ;
    var num : int := ("" + ((r.next())))->toInteger() ;
    var ans : Sequence := Sequence{} ;
    for i : xrange(num) do (    var g1 : int := ("" + ((r.next())))->toInteger() ;
    var row1 : Sequence := Sequence{} ;
    for j : xrange(4) do (    if j = g1 - 1 then  (
      row1 := (r.next().split(" "))->collect( _x | (OclType["int"])->apply(_x) )
    )
    else (
      r.next()
      )) ;
    var g2 : int := ("" + ((r.next())))->toInteger() ;
    var row2 : Sequence := Sequence{} ;
    for j : xrange(4) do (    if j = g2 - 1 then  (
      row2 := (r.next().split(" "))->collect( _x | (OclType["int"])->apply(_x) )
    )
    else (
      r.next()
      )) ;
    var intersection : Sequence := row1->select(x | (row2)->includes(x))->collect(x | (x)) ;
    if (intersection)->size() = 0 then  (
      execute (("Volunteer cheated!") : ans)
    )
    else (if (intersection)->size() = 1 then
   (
      execute ((intersection->first()) : ans)    
)
    else (
      execute (("Bad magician!") : ans)
      )    )
) ;
    write("output", ans);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
import sys
def findsol(C1,C2):
    a=set(C1).intersection(set(C2))
    if len(a)==0 :
        b='Volunteer cheated!'
    if len(a)==1 :
        b=str(a.pop())
    if len(a)>1 :
        b='Bad magician!'
    return b
def convertnums(s):
    a=[]
    ii=0
    for jj in range(len(s)):
        if s[jj]==' ' :
            if(iitoInteger() ;
    for ii : Integer.subrange(1, T + 1-1) do (    var R1 : String := fidi.readLine() ;
    R1 := ("" + ((R1)))->toInteger() ;
    for jj : Integer.subrange(0, 4-1) do (    var C : String := fidi.readLine() ;
    if (jj = R1 - 1) then (
      C1 := convertnums(C)
    ) else skip) ;
    var R2 : String := fidi.readLine() ;
    R2 := ("" + ((R2)))->toInteger() ;
    for jj : Integer.subrange(0, 4-1) do (    C := fidi.readLine() ;
    if (jj = R2 - 1) then (
      C2 := convertnums(C)
    ) else skip) ;
    a := findsol(C1, C2) ;
    fido.write('Case #' + ("" + ((ii))) + ': ' + ("" + ((a))) + '
') ;
    execute ('Case #')->display()) ;
    fidi.closeFile() ;
    fido.closeFile();
  operation findsol(C1 : OclAny, C2 : OclAny) : OclAny
  pre: true post: true
  activity:
    var a : OclAny := Set{}->union((C1))->intersection(Set{}->union((C2))) ;
    if (a)->size() = 0 then (
      var b : String := 'Volunteer cheated!'
    ) else skip ;
    if (a)->size() = 1 then (
      b := ("" + ((a->last())))
    ) else skip ;
    if (a)->size() > 1 then (
      b := 'Bad magician!'
    ) else skip ;
    return b;
  operation convertnums(s : OclAny) : OclAny
  pre: true post: true
  activity:
    a := Sequence{} ;
    var ii : int := 0 ;
    for jj : Integer.subrange(0, (s)->size()-1) do (    if s[jj+1] = ' ' then (
      if ((ii->compareTo(jj)) < 0) then (
      execute ((("" + ((s.subrange(ii+1, jj))))->toInteger()) : a) ;
    ii := jj + 1
    ) else skip
    ) else skip) ;
    execute ((("" + ((s.subrange(ii+1, jj))))->toInteger()) : a) ;
    return a;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import*
from sys import argv,stdin,stdout,stderr
Case=namedtuple('Case','selection,array')
def readcase(f):
    selection=[int(next(f))]
    array=[[readints(f)for _ in range(4)]]
    selection.append(int(next(f)))
    array.append([readints(f)for _ in range(4)])
    return Case(selection,array)
def solvecase(case):
    sets=[set(arr[sel-1])for sel,arr in zip(*case)]
    possible=sets[0]& sets[1]
    if not possible :
        return "Volunteer cheated!"
    elif len(possible)>1 :
        return 'Bad magician!'
    else :
        return str(possible.pop())
def readints(f):
    return list(map(int,next(f).split(' ')))
def main():
    with open(argv[1])as f,open(argv[2],'w')as out :
        cases=int(next(f))
        for case in range(1,cases+1):
            print('Case #%d: %s' %(case,solvecase(readcase(f))),file=out)
main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var Case : OclAny := namedtuple('Case', 'selection,array') ;
    skip ;
    skip ;
    skip ;
    skip ;
    main();
  operation readcase(f : OclAny) : OclAny
  pre: true post: true
  activity:
    var selection : Sequence := Sequence{ ("" + (((f).next())))->toInteger() } ;
    var array : Sequence := Sequence{ Integer.subrange(0, 4-1)->select(_anon | true)->collect(_anon | (readints(f))) } ;
    execute ((("" + (((f).next())))->toInteger()) : selection) ;
    execute ((Integer.subrange(0, 4-1)->select(_anon | true)->collect(_anon | (readints(f)))) : array) ;
    return Case(selection, array);
  operation solvecase(case : OclAny) : OclAny
  pre: true post: true
  activity:
    var sets : Sequence := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name case)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name case)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name case)))))))`third->at(_indx)} )->select(_tuple | true)->collect(_tuple | let sel : OclAny = _tuple->at(1) in let arr : OclAny = _tuple->at(2) in (Set{}->union((arr[sel - 1+1])))) ;
    var possible : int := MathLib.bitwiseAnd(sets->first(), sets[1+1]) ;
    if not(possible) then  (
      return "Volunteer cheated!"
    )
    else (if (possible)->size() > 1 then
   (
      return 'Bad magician!'    
)
    else (
      return ("" + ((possible->last())))
      )    )
;
  operation readints(f : OclAny) : OclAny
  pre: true post: true
  activity:
    return ((next(f).split(' '))->collect( _x | (OclType["int"])->apply(_x) ));
  operation main()
  pre: true post: true
  activity:
    try (var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(argv[1+1]));
    var out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(argv[2+1]));
    var cases : int := ("" + (((f).next())))->toInteger() ;
    for case : Integer.subrange(1, cases + 1-1) do (    execute (StringLib.format('Case #%d: %s',Sequence{case, solvecase(readcase(f))}))->display()))
    catch (_e : OclException) do skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
import itertools
from operator import itemgetter
import bisect
import math
import copy
from fractions import gcd
from utilities import*
sys.setrecursionlimit(1000)
Prep=[]
def preprocess():
    return None
def readinput(Input):
    A1=Input.readint()
    R1=[]
    for i in range(4):
        R1.append(Input.readints())
    A2=Input.readint()
    R2=[]
    for i in range(4):
        R2.append(Input.readints())
    return set(R1[A1-1]),set(R2[A2-1])
def solve(Problem,Prep):
    R1,R2=Problem
    B=R1.intersection(R2)
    if len(B)==0 :
        return "Volunteer cheated!"
    if len(B)==1 :
        return B.pop()
    return "Bad magician!"
    return 0
if __name__=="__main__" :
    doit(preprocess,readinput,solve,MultiCore=False,Verify=False,Input=SMALL,Filename=None,Problem="A",Attempt=0)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    sys.setrecursionlimit(1000) ;
    var Prep : Sequence := Sequence{} ;
    skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      doit(preprocess, readinput, solve, (argument (test (logical_test (comparison (expr (atom (name MultiCore)))))) = (test (logical_test (comparison (expr (atom (name False))))))), (argument (test (logical_test (comparison (expr (atom (name Verify)))))) = (test (logical_test (comparison (expr (atom (name False))))))), (argument (test (logical_test (comparison (expr (atom (name Input)))))) = (test (logical_test (comparison (expr (atom (name SMALL))))))), (argument (test (logical_test (comparison (expr (atom (name Filename)))))) = (test (logical_test (comparison (expr (atom None)))))), (argument (test (logical_test (comparison (expr (atom (name Problem)))))) = (test (logical_test (comparison (expr (atom "A")))))), (argument (test (logical_test (comparison (expr (atom (name Attempt)))))) = (test (logical_test (comparison (expr (atom (number (integer 0)))))))))
    ) else skip;
  operation preprocess() : OclAny
  pre: true post: true
  activity:
    return null;
  operation readinput(Input : OclAny) : OclAny
  pre: true post: true
  activity:
    var A1 : OclAny := Input.readint() ;
    var R1 : Sequence := Sequence{} ;
    for i : Integer.subrange(0, 4-1) do (    execute ((Input.readints()) : R1)) ;
    var A2 : OclAny := Input.readint() ;
    var R2 : Sequence := Sequence{} ;
    for i : Integer.subrange(0, 4-1) do (    execute ((Input.readints()) : R2)) ;
    return Set{}->union((R1[A1 - 1+1])), Set{}->union((R2[A2 - 1+1]));
  operation solve(Problem : OclAny, Prep : OclAny) : OclAny
  pre: true post: true
  activity:
    Sequence{R1,R2} := Problem ;
    var B : OclAny := R1->intersection(R2) ;
    if (B)->size() = 0 then (
      return "Volunteer cheated!"
    ) else skip ;
    if (B)->size() = 1 then (
      return B->last()
    ) else skip ;
    return "Bad magician!" ;
    return 0;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
inputFile=open('A-small-attempt0.in','r')
lines=inputFile.readlines()
inputFile.close()
outputFile=open('A-small-attempt0.out','w')
numTests=int(lines[0])
currLine=1
for i in range(1,numTests+1):
    firstRow=lines[int(lines[currLine])+currLine]
    currLine+=5
    secondRow=lines[int(lines[currLine])+currLine]
    currLine+=5
    firstNums=map(lambda x : int(x),firstRow.split())
    secondNums=map(lambda x : int(x),secondRow.split())
    intersect=[v for v in firstNums if v in secondNums]
    outputFile.write('Case #'+str(i)+': ')
    if len(intersect)==1 :
        outputFile.write(str(intersect[0])+'\n')
    elif len(intersect)==0 :
        outputFile.write('Volunteer cheated!\n')
    else :
        outputFile.write('Bad magician!\n')
outputFile.close()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var inputFile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('A-small-attempt0.in')) ;
    var lines : OclAny := inputFile.readlines() ;
    inputFile.closeFile() ;
    var outputFile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('A-small-attempt0.out')) ;
    var numTests : int := ("" + ((lines->first())))->toInteger() ;
    var currLine : int := 1 ;
    for i : Integer.subrange(1, numTests + 1-1) do (    var firstRow : OclAny := lines[("" + ((lines[currLine+1])))->toInteger() + currLine+1] ;
    currLine := currLine + 5 ;
    var secondRow : OclAny := lines[("" + ((lines[currLine+1])))->toInteger() + currLine+1] ;
    currLine := currLine + 5 ;
    var firstNums : Sequence := (firstRow.split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ) ;
    var secondNums : Sequence := (secondRow.split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ) ;
    var intersect : Sequence := firstNums->select(v | (secondNums)->includes(v))->collect(v | (v)) ;
    outputFile.write('Case #' + ("" + ((i))) + ': ') ;
    if (intersect)->size() = 1 then  (
      outputFile.write(("" + ((intersect->first()))) + '
')
    )
    else (if (intersect)->size() = 0 then
   (
      outputFile.write('Volunteer cheated!
')    
)
    else (
      outputFile.write('Bad magician!
')
      )    )
) ;
    outputFile.closeFile();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s1=input()
s2=input()
l1,l2=len(s1),len(s2)
dp=[[0]*(l2+1)for _ in range(l1+1)]
for i in range(l1+1):
    dp[i][0]=i
for j in range(l2+1):
    dp[0][j]=j
for i in range(1,l1+1):
    for j in range(1,l2+1):
        dp[i][j]=min(dp[i][j-1]+1,dp[i-1][j]+1,dp[i-1][j-1]+(s1[i-1]!=s2[j-1]))
print(dp[l1][l2])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s1 : String := (OclFile["System.in"]).readLine() ;
    var s2 : String := (OclFile["System.in"]).readLine() ;
    var l1 : OclAny := null;
    var l2 : OclAny := null;
    Sequence{l1,l2} := Sequence{(s1)->size(),(s2)->size()} ;
    var dp : Sequence := Integer.subrange(0, l1 + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (l2 + 1)))) ;
    for i : Integer.subrange(0, l1 + 1-1) do (    dp[i+1]->first() := i) ;
    for j : Integer.subrange(0, l2 + 1-1) do (    dp->first()[j+1] := j) ;
    for i : Integer.subrange(1, l1 + 1-1) do (    for j : Integer.subrange(1, l2 + 1-1) do (    dp[i+1][j+1] := Set{dp[i+1][j - 1+1] + 1, dp[i - 1+1][j+1] + 1, dp[i - 1+1][j - 1+1] + (s1[i - 1+1] /= s2[j - 1+1])}->min())) ;
    execute (dp[l1+1][l2+1])->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def f(x):
    x+=1
    while(x % 10==0):
        x//=10
    return x
a=set()
n=int(input())
while(not(n in a)):
    a.add(n)
    n=f(n)
print(len(a))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var a : Set := Set{}->union(()) ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    while (not(((a)->includes(n)))) do (    execute ((n) : a) ;
    n := f(n)) ;
    execute ((a)->size())->display();
  operation f(x : OclAny) : OclAny
  pre: true post: true
  activity:
    x := x + 1 ;
    while (x mod 10 = 0) do (    x := x div 10) ;
    return x;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def countWays(arr,m,N):
    count=[0 for i in range(N+1)]
    count[0]=1
    for i in range(1,N+1):
        for j in range(m):
            if(i>=arr[j]):
                count[i]+=count[i-arr[j]]
    return count[N]
arr=[1,5,6]
m=len(arr)
N=7
print("Total number of ways=",countWays(arr,m,N))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    arr := Sequence{1}->union(Sequence{5}->union(Sequence{ 6 })) ;
    m := (arr)->size() ;
    N := 7 ;
    execute ("Total number of ways=")->display();
  operation countWays(arr : OclAny, m : OclAny, N : OclAny) : OclAny
  pre: true post: true
  activity:
    var count : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (0)) ;
    count->first() := 1 ;
    for i : Integer.subrange(1, N + 1-1) do (    for j : Integer.subrange(0, m-1) do (    if ((i->compareTo(arr[j+1])) >= 0) then (
      count[i+1] := count[i+1] + count[i - arr[j+1]+1]
    ) else skip)) ;
    return count[N+1];
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import deque,Counter
from math import*
import sys
import random
from bisect import*
from functools import reduce
from sys import stdin
import copy
n,k=map(int,input().split())
arr=list(map(int,input().split()))
sleep=list(map(int,input().split()))
pre=[0 for i in range(n+1)]
one=0
for i in range(n):
    if sleep[i]==1 :
        one+=arr[i]
        arr[i]=0
for i in range(0,n):
    pre[i]=arr[i]+pre[i-1]
start=None
m=0
for i in range(n):
    if sleep[i]==0 :
        x=n-1 if(i+k-1)>=n else i+k-1
        val=(pre[x]-pre[i-1])
        if val>m :
            m=val
            start=i
print(m+one)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var sleep : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var pre : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ;
    var one : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    if sleep[i+1] = 1 then (
      one := one + arr[i+1] ;
    arr[i+1] := 0
    ) else skip) ;
    for i : Integer.subrange(0, n-1) do (    pre[i+1] := arr[i+1] + pre[i - 1+1]) ;
    var start : OclAny := null ;
    var m : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    if sleep[i+1] = 0 then (
      var x : double := if ((i + k - 1)->compareTo(n)) >= 0 then n - 1 else i + k - 1 endif ;
    var val : double := (pre[x+1] - pre[i - 1+1]) ;
    if (val->compareTo(m)) > 0 then (
      m := val ;
    start := i
    ) else skip
    ) else skip) ;
    execute (m + one)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def levenshtein(str1,str2):
    prev_dp=list(range(len(str2)+1))
    for i1,c1 in enumerate(str1):
        current_dp=[i1+1]
        current_dp.extend(min(prev_dp[i2+1]+1,current_dp[i2]+1,prev_dp[i2]+int(c1!=c2))for i2,c2 in enumerate(str2))
        prev_dp=current_dp
    return prev_dp[-1]
print(levenshtein(input(),input()))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    execute (levenshtein((OclFile["System.in"]).readLine(), (OclFile["System.in"]).readLine()))->display();
  operation levenshtein(str1 : OclAny, str2 : OclAny) : OclAny
  pre: true post: true
  activity:
    var prev_dp : Sequence := (Integer.subrange(0, (str2)->size() + 1-1)) ;
    for _tuple : Integer.subrange(1, (str1)->size())->collect( _indx | Sequence{_indx-1, (str1)->at(_indx)} ) do (var _indx : int := 1;
      var i1 : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var c1 : OclAny := _tuple->at(_indx);
      var current_dp : Sequence := Sequence{ i1 + 1 } ;
    current_dp := current_dp->union((argument (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name prev_dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i2))) + (expr (atom (number (integer 1)))))))))) ]))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name current_dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i2)))))))) ]))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name prev_dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i2)))))))) ]))) + (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (comparison (expr (atom (name c1)))) != (comparison (expr (atom (name c2))))))))) )))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i2))) , (expr (atom (name c2)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str2)))))))) ))))))))) ;
    prev_dp := current_dp) ;
    return prev_dp->last();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s1=input()
s2=input()
dict=dict([])
s1_num=[]
s2_num=[]
for s in s1 :
    if not s in dict :
        dict[s]=len(dict)
    s1_num.append(dict[s])
for s in s2 :
    if not s in dict :
        dict[s]=len(dict)
    s2_num.append(dict[s])
s1_len=len(s1_num)
s2_len=len(s2_num)
lst=[[0]*(s2_len+1)for _ in range(s1_len+1)]
lst[0]=[i for i in range(s2_len+1)]
for x in range(s1_len+1):
    lst[x][0]=x
for i in range(1,s1_len+1):
    for j in range(1,s2_len+1):
        if s1_num[i-1]==s2_num[j-1]:
            lst[i][j]=min((lst[i-1][j-1]),(lst[i-1][j]+1),(lst[i][j-1]+1))
        else :
            lst[i][j]=min((lst[i-1][j-1]+1),(lst[i-1][j]+1),(lst[i][j-1]+1))
print(lst[s1_len][s2_len])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s1 : String := (OclFile["System.in"]).readLine() ;
    var s2 : String := (OclFile["System.in"]).readLine() ;
    var OclType["Map"] : Map := ((atom [ ])) ;
    var s1_num : Sequence := Sequence{} ;
    var s2_num : Sequence := Sequence{} ;
    for s : s1->characters() do (    if not((OclType["Map"])->includes(s)) then (
      (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ]) := (OclType["Map"])->size()
    ) else skip ;
    execute (((arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])) : s1_num)) ;
    for s : s2->characters() do (    if not((OclType["Map"])->includes(s)) then (
      (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ]) := (OclType["Map"])->size()
    ) else skip ;
    execute (((arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])) : s2_num)) ;
    var s1_len : int := (s1_num)->size() ;
    var s2_len : int := (s2_num)->size() ;
    var lst : Sequence := Integer.subrange(0, s1_len + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (s2_len + 1)))) ;
    lst->first() := Integer.subrange(0, s2_len + 1-1)->select(i | true)->collect(i | (i)) ;
    for x : Integer.subrange(0, s1_len + 1-1) do (    lst[x+1]->first() := x) ;
    for i : Integer.subrange(1, s1_len + 1-1) do (    for j : Integer.subrange(1, s2_len + 1-1) do (    if s1_num[i - 1+1] = s2_num[j - 1+1] then  (
      lst[i+1][j+1] := Set{(lst[i - 1+1][j - 1+1]), (lst[i - 1+1][j+1] + 1), (lst[i+1][j - 1+1] + 1)}->min()
    )
    else (
      lst[i+1][j+1] := Set{(lst[i - 1+1][j - 1+1] + 1), (lst[i - 1+1][j+1] + 1), (lst[i+1][j - 1+1] + 1)}->min()
      ))) ;
    execute (lst[s1_len+1][s2_len+1])->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
readline=sys.stdin.readline
def main():
    S=readline().rstrip()
    T=readline().rstrip()
    N,M=len(S),len(T)
    dp=[[0]*(M+1)for _ in range((N+1))]
    dp[0]=[i for i in range(M+1)]
    for i in range(N+1):
        dp[i][0]=i
    for i,s in enumerate(S):
        for j,t in enumerate(T):
            if s==t :
                dp[i+1][j+1]=dp[i][j]
            else :
                dp[i+1][j+1]=min(dp[i][j],dp[i+1][j],dp[i][j+1])+1
    print(dp[N][M])
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var readline : OclAny := (OclFile["System.in"]).readline ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var S : OclAny := readline().rstrip() ;
    var T : OclAny := readline().rstrip() ;
    var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := Sequence{(S)->size(),(T)->size()} ;
    var dp : Sequence := Integer.subrange(0, (N + 1)-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (M + 1)))) ;
    dp->first() := Integer.subrange(0, M + 1-1)->select(i | true)->collect(i | (i)) ;
    for i : Integer.subrange(0, N + 1-1) do (    dp[i+1]->first() := i) ;
    for _tuple : Integer.subrange(1, (S)->size())->collect( _indx | Sequence{_indx-1, (S)->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var s : OclAny := _tuple->at(_indx);
      for _tuple : Integer.subrange(1, (T)->size())->collect( _indx | Sequence{_indx-1, (T)->at(_indx)} ) do (var _indx : int := 1;
      var j : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var t : OclAny := _tuple->at(_indx);
      if s = t then  (
      dp[i + 1+1][j + 1+1] := dp[i+1][j+1]
    )
    else (
      dp[i + 1+1][j + 1+1] := Set{dp[i+1][j+1], dp[i + 1+1][j+1], dp[i+1][j + 1+1]}->min() + 1
      ))) ;
    execute (dp[N+1][M+1])->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
import math
import collections
import bisect
import itertools
import fractions
import copy
import decimal
import queue
sys.setrecursionlimit(10000001)
INF=10**16
MOD=10**9+7
ni=lambda : int(sys.stdin.readline())
ns=lambda : map(int,sys.stdin.readline().split())
na=lambda : list(map(int,sys.stdin.readline().split()))
def main():
    s1=list(input())
    s2=list(input())
    s1_l=len(s1)
    s2_l=len(s2)
    dp=[[0 for _ in range(s1_l+1)]for _ in range(s2_l+1)]
    for i in range(s1_l+1):
        dp[0][i]=i
    for i in range(s2_l+1):
        dp[i][0]=i
    for i in range(1,s2_l+1):
        for j in range(1,s1_l+1):
            cost=0 if s1[j-1]==s2[i-1]else 1
            dp[i][j]=min(dp[i-1][j]+1,dp[i][j-1]+1,dp[i-1][j-1]+cost)
    print(dp[s2_l][s1_l])
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    sys.setrecursionlimit(10000001) ;
    var INF : double := (10)->pow(16) ;
    var MOD : double := (10)->pow(9) + 7 ;
    var ni : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ;
    var ns : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var na : Function := lambda $$ : OclAny in (((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var s1 : Sequence := ((OclFile["System.in"]).readLine())->characters() ;
    var s2 : Sequence := ((OclFile["System.in"]).readLine())->characters() ;
    var s1_l : int := (s1)->size() ;
    var s2_l : int := (s2)->size() ;
    var dp : Sequence := Integer.subrange(0, s2_l + 1-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, s1_l + 1-1)->select(_anon | true)->collect(_anon | (0)))) ;
    for i : Integer.subrange(0, s1_l + 1-1) do (    dp->first()[i+1] := i) ;
    for i : Integer.subrange(0, s2_l + 1-1) do (    dp[i+1]->first() := i) ;
    for i : Integer.subrange(1, s2_l + 1-1) do (    for j : Integer.subrange(1, s1_l + 1-1) do (    var cost : int := if s1[j - 1+1] = s2[i - 1+1] then 0 else 1 endif ;
    dp[i+1][j+1] := Set{dp[i - 1+1][j+1] + 1, dp[i+1][j - 1+1] + 1, dp[i - 1+1][j - 1+1] + cost}->min())) ;
    execute (dp[s2_l+1][s1_l+1])->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def numLen(K):
    if(K % 2==0 or K % 5==0):
        return-1
    number=0
    len=1
    for len in range(1,K+1):
        number=(number*10+1)% K
        if number==0 :
            return len
    return-1
K=7
print(numLen(K))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    K := 7 ;
    execute (numLen(K))->display();
  operation numLen(K : OclAny) : OclAny
  pre: true post: true
  activity:
    if (K mod 2 = 0 or K mod 5 = 0) then (
      return -1
    ) else skip ;
    var number : int := 0 ;
    var len : int := 1 ;
    for len : Integer.subrange(1, K + 1-1) do (    number := (number * 10 + 1) mod K ;
    if number = 0 then (
      return len
    ) else skip) ;
    return -1;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def numLen(K):
    if(K % 2==0 or K % 5==0):
        return-1 ;
    number=0 ;
    len=1 ;
    for len in range(1,K+1):
        number=number*10+1 ;
        if((number % K==0)):
            return len ;
    return-1 ;
K=7 ;
print(numLen(K));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    K := 7; ;
    execute (numLen(K))->display();;
  operation numLen(K : OclAny)
  pre: true post: true
  activity:
    if (K mod 2 = 0 or K mod 5 = 0) then (
      return -1;
    ) else skip ;
    var number : int := 0; ;
    var len : int := 1; ;
    for len : Integer.subrange(1, K + 1-1) do (    number := number * 10 + 1; ;
    if ((number mod K = 0)) then (
      return len;
    ) else skip) ;
    return -1;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def numbers(n,arr,m):
    isZero=0
    isFive=0
    result=0
    if(munion(Sequence{3}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 9 }))))) ;
    execute (numbers(n, arr, m))->display()
    ) else skip;
  operation numbers(n : OclAny, arr : OclAny, m : OclAny) : OclAny
  pre: true post: true
  activity:
    var isZero : int := 0 ;
    var isFive : int := 0 ;
    var result : int := 0 ;
    if ((m->compareTo(n)) < 0) then (
      return -1
    ) else skip ;
    for i : Integer.subrange(0, m-1) do (    if (arr[i+1] = 0) then (
      isZero := 1
    ) else skip ;
    if (arr[i+1] = 5) then (
      isFive := 1
    ) else skip) ;
    if (isZero & isFive) then  (
      result := 2 ;
    for i : Integer.subrange(0, n - 1-1) do (    m := m - 1 ;
    result := result * (m))
    )
    else (if (isZero or isFive) then
   (
      result := 1 ;
    for i : Integer.subrange(0, n - 1-1) do (    m := m - 1 ;
    result := result * (m))    
)
    else (
      result := -1
      )    )
 ;
    return result;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def sum_odd(n):
    sums=0
    pos=1
    while(n!=0):
        if(pos % 2==1):
            sums+=n % 10
        n=n//10
        pos+=1
    return sums
def check_prime(n):
    if(n<=1):
        return False
    if(n<=3):
        return True
    if(n % 2==0 or n % 3==0):
        return False
    for i in range(5,n,6):
        if(n % i==0 or n %(i+2)==0):
            return False
    return True
n=223
sums=sum_odd(n)
if(check_prime(sums)):
    print("YES")
else :
    print("NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    n := 223 ;
    sums := sum_odd(n) ;
    if (check_prime(sums)) then  (
      execute ("YES")->display()
    )
    else (
      execute ("NO")->display()
      );
  operation sum_odd(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var sums : int := 0 ;
    var pos : int := 1 ;
    while (n /= 0) do (    if (pos mod 2 = 1) then (
      sums := sums + n mod 10
    ) else skip ;
    n := n div 10 ;
    pos := pos + 1) ;
    return sums;
  operation check_prime(n : OclAny) : OclAny
  pre: true post: true
  activity:
    if (n <= 1) then (
      return false
    ) else skip ;
    if (n <= 3) then (
      return true
    ) else skip ;
    if (n mod 2 = 0 or n mod 3 = 0) then (
      return false
    ) else skip ;
    for i : Integer.subrange(5, n-1)->select( $x | ($x - 5) mod 6 = 0 ) do (    if (n mod i = 0 or n mod (i + 2) = 0) then (
      return false
    ) else skip) ;
    return true;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import bisect
import sys
sys.setrecursionlimit(10**9)
input=sys.stdin.readline
def solve():
    N,M=map(int,input().split())
    if N*M==0 :
        return False
    P=[0]+[int(input())for _ in range(N)]
    k=[P[i]+P[j]for i in range(N)for j in range(i,N)]
    k=sorted(k)
    ret=0
    for tmp in k :
        if tmp>M :
            break
        else :
            r=M-tmp
            l=bisect.bisect_right(k,r)
            tmp+=k[l-1]
            ret=max(ret,tmp)
    return ret
ans=[]
while True :
    ret=solve()
    if ret :
        ans.append(ret)
    else :
        break
print("\n".join(map(str,ans)))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    sys.setrecursionlimit((10)->pow(9)) ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    skip ;
    var ans : Sequence := Sequence{} ;
    while true do (    ret := solve() ;
    if ret then  (
      execute ((ret) : ans)
    )
    else (
      break
      )) ;
    execute (StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), "\n"))->display();
  operation solve() : OclAny
  pre: true post: true
  activity:
    var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if N * M = 0 then (
      return false
    ) else skip ;
    var P : Sequence := Sequence{ 0 }->union(Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))) ;
    var k : Sequence := Integer.subrange(0, N-1)->select(i; j : Integer.subrange(i, N-1) | true)->collect(i; j : Integer.subrange(i, N-1) | (P[i+1] + P[j+1])) ;
    k := k->sort() ;
    var ret : int := 0 ;
    for tmp : k do (    if (tmp->compareTo(M)) > 0 then  (
      break
    )
    else (
      var r : double := M - tmp ;
    var l : OclAny := bisect.bisect_right(k, r) ;
    tmp := tmp + k[l - 1+1] ;
    ret := Set{ret, tmp}->max()
      )) ;
    return ret;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def numberOfWays(x):
    if x==0 or x==1 :
        return 1
    else :
        return(numberOfWays(x-1)+(x-1)*numberOfWays(x-2))
x=3
print(numberOfWays(x))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    x := 3 ;
    execute (numberOfWays(x))->display();
  operation numberOfWays(x : OclAny) : OclAny
  pre: true post: true
  activity:
    if x = 0 or x = 1 then  (
      return 1
    )
    else (
      return (numberOfWays(x - 1) + (x - 1) * numberOfWays(x - 2))
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from itertools import product
from bisect import bisect_left
def main():
    while True :
        N,M=map(int,input().split())
        if N==M==0 :
            break
        p=[int(input())for _ in range(N)]
        p.append(0)
        points=[]
        for i in range(N+1):
            for j in range(i,N+1):
                points.append(p[i]+p[j])
        points.sort()
        ans=0
        for i in range(len(points)):
            index=bisect_left(points,M-points[i])
            if index!=0 :
                ans=max(ans,points[i]+points[index-1])
        print(ans)
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    while true do (    var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if N = M & (M == 0) then (
      break
    ) else skip ;
    var p : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ;
    execute ((0) : p) ;
    var points : Sequence := Sequence{} ;
    for i : Integer.subrange(0, N + 1-1) do (    for j : Integer.subrange(i, N + 1-1) do (    execute ((p[i+1] + p[j+1]) : points))) ;
    points := points->sort() ;
    var ans : int := 0 ;
    for i : Integer.subrange(0, (points)->size()-1) do (    var index : OclAny := bisect_left(points, M - points[i+1]) ;
    if index /= 0 then (
      ans := Set{ans, points[i+1] + points[index - 1+1]}->max()
    ) else skip) ;
    execute (ans)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def pattern(n):
    for i in range(1,n+1):
        for j in range(1,2*n+1):
            if(i(n-j+1)):
                print("",end="");
            else :
                print("*",end="");
            if((i+n)>j):
                print("",end="");
            else :
                print("*",end="");
        print("");
pattern(7);
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    pattern(7);;
  operation pattern(n : OclAny)
  pre: true post: true
  activity:
    for i : Integer.subrange(1, n + 1-1) do (    for j : Integer.subrange(1, 2 * n + 1-1) do (    if ((i->compareTo(j)) < 0) then  (
      execute ("")->display();
    )
    else (
      execute ("*")->display();
      ) ;
    if ((i->compareTo(((2 * n) - j))) <= 0) then  (
      execute ("")->display();
    )
    else (
      execute ("*")->display();
      )) ;
    execute ("")->display();) ;
    for i : Integer.subrange(1, n + 1-1) do (    for j : Integer.subrange(1, 2 * n + 1-1) do (    if ((i->compareTo((n - j + 1))) > 0) then  (
      execute ("")->display();
    )
    else (
      execute ("*")->display();
      ) ;
    if (((i + n)->compareTo(j)) > 0) then  (
      execute ("")->display();
    )
    else (
      execute ("*")->display();
      )) ;
    execute ("")->display(););
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
file_input=sys.stdin
NM=file_input.readline()
import itertools,bisect
while NM!='0 0\n' :
    N,M=map(int,NM.split())
    P=[int(file_input.readline())for i in range(N)]
    P.append(0)
    scores=map(sum,itertools.combinations_with_replacement(P,2))
    scores=list(set(scores))
    scores.sort()
    ans=[]
    for s1 in scores :
        rest=M-s1
        i=bisect.bisect_right(scores,rest)
        if i :
            ans.append(s1+scores[i-1])
    print(max(ans))
    NM=file_input.readline()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var file_input : OclFile := OclFile["System.in"] ;
    var NM : String := file_input.readLine() ;
    skip ;
    while NM /= '0 0
' do (    var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (NM.split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var P : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (("" + ((file_input.readLine())))->toInteger())) ;
    execute ((0) : P) ;
    var scores : Sequence := (itertools.combinations_with_replacement(P, 2))->collect( _x | (sum)->apply(_x) ) ;
    scores := (Set{}->union((scores))) ;
    scores := scores->sort() ;
    var ans : Sequence := Sequence{} ;
    for s1 : scores do (    var rest : double := M - s1 ;
    var i : OclAny := bisect.bisect_right(scores, rest) ;
    if i then (
      execute ((s1 + scores[i - 1+1]) : ans)
    ) else skip) ;
    execute ((ans)->max())->display() ;
    NM := file_input.readLine());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import bisect
while True :
    max_S=0
    p=[0]
    pp=[]
    n,m=map(int,input().split())
    if n==0 and m==0 :
        break
    for _ in range(n):
        p.append(int(input()))
    for c in range(n+1):
        for d in range(c,n+1):
            pp.append(p[c]+p[d])
    pp.sort()
    t=bisect.bisect_left(pp,m)
    h=bisect.bisect_left(pp,m//2,0,t)
    if tmax_S :
            max_S=pp[i]+pp[t-1]
    print(max_S)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    while true do (    var max_S : int := 0 ;
    var p : Sequence := Sequence{ 0 } ;
    var pp : Sequence := Sequence{} ;
    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if n = 0 & m = 0 then (
      break
    ) else skip ;
    for _anon : Integer.subrange(0, n-1) do (    execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : p)) ;
    for c : Integer.subrange(0, n + 1-1) do (    for d : Integer.subrange(c, n + 1-1) do (    execute ((p[c+1] + p[d+1]) : pp))) ;
    pp := pp->sort() ;
    var t : OclAny := bisect.bisect_left(pp, m) ;
    var h : OclAny := bisect.bisect_left(pp, m div 2, 0, t) ;
    if (t->compareTo((pp)->size())) < 0 then (
      if pp[t+1] = m then (
      execute (m)->display() ;
    continue
    ) else skip ;
    pp := pp.subrange(1,t)
    ) else skip ;
    max_S := 0 ;
    for i : Integer.subrange(0, (pp)->size()-1) do (    t := bisect.bisect_left(pp, m - pp[i+1]) ;
    if (pp[i+1] + pp[t - 1+1]->compareTo(max_S)) > 0 then (
      max_S := pp[i+1] + pp[t - 1+1]
    ) else skip) ;
    execute (max_S)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def input_score(N):
    score=[]
    score.append(0)
    for i in range(N):
        score.append(int(input()))
    return score
def cal_four_sum_score(two_score,M):
    left=0
    right=len(two_score)-1
    max_score=0
    while left!=right :
        now_score=two_score[left]+two_score[right]
        if now_scoreM :
            right-=1
        else :
            max_score=M
            break
    return max_score
def cal_two_sum_score(score):
    two_score=[]
    contain_sum={}
    for i in range(len(score)):
        for j in range(len(score)):
            now_score=score[i]+score[j]
            if not contain_sum.get(now_score):
                contain_sum[now_score]=True
                two_score.append(now_score)
    two_score.sort()
    return two_score
def main():
    while True :
        N,M=map(int,input().split())
        if N==0 and M==0 :
            break
        score=input_score(N)
        two_score=cal_two_sum_score(score)
        max_score=cal_four_sum_score(two_score,M)
        print(max_score)
if __name__=="__main__" :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      main()
    ) else skip;
  operation input_score(N : OclAny) : OclAny
  pre: true post: true
  activity:
    var score : Sequence := Sequence{} ;
    execute ((0) : score) ;
    for i : Integer.subrange(0, N-1) do (    execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : score)) ;
    return score;
  operation cal_four_sum_score(two_score : OclAny, M : OclAny) : OclAny
  pre: true post: true
  activity:
    var left : int := 0 ;
    var right : double := (two_score)->size() - 1 ;
    var max_score : int := 0 ;
    while left /= right do (    var now_score : OclAny := two_score[left+1] + two_score[right+1] ;
    if (now_score->compareTo(M)) < 0 then  (
      max_score := Set{max_score, now_score}->max() ;
    left := left + 1
    )
    else (if (now_score->compareTo(M)) > 0 then
   (
      right := right - 1    
)
    else (
      max_score := M ;
    break
      )    )
) ;
    return max_score;
  operation cal_two_sum_score(score : OclAny) : OclAny
  pre: true post: true
  activity:
    two_score := Sequence{} ;
    var contain_sum : OclAny := Set{} ;
    for i : Integer.subrange(0, (score)->size()-1) do (    for j : Integer.subrange(0, (score)->size()-1) do (    now_score := score[i+1] + score[j+1] ;
    if not(contain_sum.get(now_score)) then (
      contain_sum[now_score+1] := true ;
    execute ((now_score) : two_score)
    ) else skip)) ;
    two_score := two_score->sort() ;
    return two_score;
  operation main()
  pre: true post: true
  activity:
    while true do (    Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if N = 0 & M = 0 then (
      break
    ) else skip ;
    score := input_score(N) ;
    two_score := cal_two_sum_score(score) ;
    max_score := cal_four_sum_score(two_score, M) ;
    execute (max_score)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s=input()
i=0
maxlv=0
while imaxlv :
            maxlv=lbuf
    else : i+=1
print(maxlv)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : String := (OclFile["System.in"]).readLine() ;
    var i : int := 0 ;
    var maxlv : int := 0 ;
    while (i->compareTo((s)->size())) < 0 do (    var lbuf : int := 0 ;
    if s[i+1] = 'J' then  (
      var j : int := 1 ;
    while (i + j->compareTo((s)->size())) < 0 & s[i + j+1] = "J" do (    j := j + 1) ;
    lbuf := j ;
    i := i + j ;
    j := 0 ;
    while (i + j->compareTo((s)->size())) < 0 & (j->compareTo(lbuf)) < 0 & s[i + j+1] = "O" do (    j := j + 1) ;
    lbuf := (Sequence{lbuf, j})->min() ;
    if lbuf = 0 then (
      continue
    ) else skip ;
    i := i + j ;
    j := 0 ;
    while (i + j->compareTo((s)->size())) < 0 & (j->compareTo(lbuf)) < 0 & s[i + j+1] = "I" do (    j := j + 1) ;
    i := i + j ;
    if j /= lbuf then  (
      continue
    )
    else (if (lbuf->compareTo(maxlv)) > 0 then
   (
      maxlv := lbuf    
)
 else skip)
    )
    else (
      i := i + 1
      )) ;
    execute (maxlv)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import defaultdict,Counter
from itertools import product,groupby,count,permutations,combinations
from math import pi,sqrt
from collections import deque
from bisect import bisect,bisect_left,bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF=float("inf")
YES,Yes,yes,NO,No,no="YES","Yes","yes","NO","No","no"
def main():
    S=input()
    t="JOI"
    idx=0
    ans=0
    num=[0,0,0]
    for k,g in groupby(S):
        if k==t[idx]:
            num[idx]=len(list(g))
            if k=="I" :
                if num[1]<=num[0]and num[1]<=num[2]:
                    ans=max(ans,num[1])
                idx=0
            else :
                idx+=1
        else :
            if k=="J" :
                idx=1
                num[0]=len(list(g))
            else :
                idx=0
    print(ans)
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    sys.setrecursionlimit(10000) ;
    var INF : double := ("" + (("inf")))->toReal() ;
    var YES : OclAny := null;
    var Yes : OclAny := null;
    var yes : OclAny := null;
    var NO : OclAny := null;
    var No : OclAny := null;
    var no : OclAny := null;
    Sequence{YES,Yes,yes,NO,No,no} := Sequence{"YES","Yes","yes","NO","No","no"} ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var S : String := (OclFile["System.in"]).readLine() ;
    var t : String := "JOI" ;
    var idx : int := 0 ;
    var ans : int := 0 ;
    var num : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) ;
    for _tuple : groupby(S) do (var _indx : int := 1;
      var k : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var g : OclAny := _tuple->at(_indx);
      if k = t[idx+1] then  (
      num[idx+1] := ((g))->size() ;
    if k = "I" then  (
      if (num[1+1]->compareTo(num->first())) <= 0 & (num[1+1]->compareTo(num[2+1])) <= 0 then (
      ans := Set{ans, num[1+1]}->max()
    ) else skip ;
    idx := 0
    )
    else (
      idx := idx + 1
      )
    )
    else (
      if k = "J" then  (
      idx := 1 ;
    num->first() := ((g))->size()
    )
    else (
      idx := 0
      )
      )) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import re
pat="(J*)(O*)(I*)"
ans=0
for s in re.findall(pat,input()):
    j=len(s[0])
    o=len(s[1])
    i=len(s[2])
    if j>=o and i>=o : ans=max(ans,o)
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var pat : String := "(J*)(O*)(I*)" ;
    var ans : int := 0 ;
    for s : ((OclFile["System.in"]).readLine())->allMatches(pat) do (    var j : int := (s->first())->size() ;
    var o : int := (s[1+1])->size() ;
    var i : int := (s[2+1])->size() ;
    if (j->compareTo(o)) >= 0 & (i->compareTo(o)) >= 0 then (
      ans := Set{ans, o}->max()
    ) else skip) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s=raw_input()
k=x=0
try :
    while 1 :
        cj=co=ci=0
        while s[x]=="J" :
            cj+=1
            x+=1
        while s[x]=="O" :
            co+=1
            x+=1
        while s[x]=="I" :
            ci+=1
            x+=1
        if co<=cj and co<=ci :
            k=max(co,k)
except IndexError :
    if co<=cj and co<=ci :
        k=max(co,k)
    print(k)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : OclAny := raw_input() ;
    var k : OclAny := 0; var x : int := 0 ;
    try (    while 1 do (    cj := cj(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name co)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ci)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ;
    while s[x+1] = "J" do (    cj := cj + 1 ;
    x := x + 1) ;
    while s[x+1] = "O" do (    co := co + 1 ;
    x := x + 1) ;
    while s[x+1] = "I" do (    ci := ci + 1 ;
    x := x + 1) ;
    if (co->compareTo(cj)) <= 0 & (co->compareTo(ci)) <= 0 then (
      k := Set{co, k}->max()
    ) else skip))
(except_clause except (test (logical_test (comparison (expr (atom (name IndexError)))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name co)))) <= (comparison (expr (atom (name cj)))))) and (logical_test (comparison (comparison (expr (atom (name co)))) <= (comparison (expr (atom (name ci)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name k)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name co))))))) , (argument (test (logical_test (comparison (expr (atom (name k)))))))) )))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name k)))))))) ))))))))))))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    s=input()
    end=len(s)
    ind=0
    ans=0
    while indans :
            ans=o_num
    print(ans)
main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    main();
  operation main()
  pre: true post: true
  activity:
    var s : String := (OclFile["System.in"]).readLine() ;
    var end : int := (s)->size() ;
    var ind : int := 0 ;
    var ans : int := 0 ;
    while (ind->compareTo(end)) < 0 do (    var j_num : int := 0 ;
    var o_num : int := 0 ;
    var i_num : int := 0 ;
    while (ind->compareTo(end)) < 0 & s[ind+1] /= "J" do (    ind := ind + 1) ;
    while (ind->compareTo(end)) < 0 & s[ind+1] = "J" do (    j_num := j_num + 1 ;
    ind := ind + 1) ;
    while (ind->compareTo(end)) < 0 & s[ind+1] = "O" do (    o_num := o_num + 1 ;
    ind := ind + 1) ;
    while (ind->compareTo(end)) < 0 & s[ind+1] = "I" do (    i_num := i_num + 1 ;
    ind := ind + 1) ;
    if (o_num->compareTo(i_num)) <= 0 & (o_num->compareTo(j_num)) <= 0 & (o_num->compareTo(ans)) > 0 then (
      ans := o_num
    ) else skip) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def countFreq(a,n):
    hm=dict()
    for i in range(n):
        hm[a[i]]=hm.get(a[i],0)+1
    cumul=0
    for i in range(n):
        cumul+=hm[a[i]]
        if(hm[a[i]]>0):
            print(a[i],"->",cumul)
        hm[a[i]]=0
a=[1,3,2,4,2,1]
n=len(a)
countFreq(a,n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    a := Sequence{1}->union(Sequence{3}->union(Sequence{2}->union(Sequence{4}->union(Sequence{2}->union(Sequence{ 1 }))))) ;
    n := (a)->size() ;
    countFreq(a, n);
  operation countFreq(a : OclAny, n : OclAny)
  pre: true post: true
  activity:
    var hm : Map := (arguments ( )) ;
    for i : Integer.subrange(0, n-1) do (    hm[a[i+1]+1] := hm.get(a[i+1], 0) + 1) ;
    var cumul : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    cumul := cumul + hm[a[i+1]+1] ;
    if (hm[a[i+1]+1] > 0) then (
      execute (a[i+1])->display()
    ) else skip ;
    hm[a[i+1]+1] := 0);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
M=4 ;
def maximumSum(a,n):
    global M ;
    for i in range(0,n):
        a[i].sort();
    sum=a[n-1][M-1];
    prev=a[n-1][M-1];
    for i in range(n-2,-1,-1):
        for j in range(M-1,-1,-1):
            if(a[i][j]union(Sequence{7}->union(Sequence{3}->union(Sequence{ 4 })))}->union(Sequence{Sequence{4}->union(Sequence{2}->union(Sequence{5}->union(Sequence{ 1 })))}->union(Sequence{ Sequence{9}->union(Sequence{5}->union(Sequence{1}->union(Sequence{ 8 }))) })); ;
    n := (arr)->size(); ;
    execute (maximumSum(arr, n))->display();;
  operation maximumSum(a : OclAny, n : OclAny)
  pre: true post: true
  activity:
    skip; ;
    for i : Integer.subrange(0, n-1) do ((expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name sort) (arguments ( ))));) ;
    var sum : OclAny := a[n - 1+1][M - 1+1]; ;
    var prev : OclAny := a[n - 1+1][M - 1+1]; ;
    for i : Integer.subrange(-1 + 1, n - 2)->reverse() do (    for j : Integer.subrange(-1 + 1, M - 1)->reverse() do (    if ((a[i+1][j+1]->compareTo(prev)) < 0) then (
      prev := a[i+1][j+1]; ;
    sum := sum + prev; ;
    break;
    ) else skip) ;
    if (j = -1) then (
      return 0;
    ) else skip) ;
    return sum;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def find(s):
    n=len(s)
    x=int(s)
    if(x<10):
        return x
    ans=x//10-1
    ans=ans+9
    if(s[0]<=s[n-1]):
        ans=ans+1
    return ans
l,r=map(int,input().split())
l=l-1
l=str(l)
r=str(r)
count1=find(l)
count2=find(r)
print(count2-count1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var l : OclAny := null;
    var r : OclAny := null;
    Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var l : double := l - 1 ;
    l := ("" + ((l))) ;
    var r : String := ("" + ((r))) ;
    var count1 : OclAny := find(l) ;
    var count2 : OclAny := find(r) ;
    execute (count2 - count1)->display();
  operation find(s : OclAny) : OclAny
  pre: true post: true
  activity:
    var n : int := (s)->size() ;
    var x : int := ("" + ((s)))->toInteger() ;
    if (x < 10) then (
      return x
    ) else skip ;
    var ans : double := x div 10 - 1 ;
    ans := ans + 9 ;
    if ((s->first()->compareTo(s[n - 1+1])) <= 0) then (
      ans := ans + 1
    ) else skip ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def pattern(n):
    for i in range(1,n+1):
        for j in range(1,2*n):
            if i>(n-j+1):
                print("",end='');
            else :
                print("*",end='');
            if i+n-1>j :
                print("",end='');
            else :
                print("*",end='');
        print("");
    for i in range(1,n+1):
        for j in range(1,2*n):
            if i;
  operation pattern(n : OclAny)
  pre: true post: true
  activity:
    for i : Integer.subrange(1, n + 1-1) do (    for j : Integer.subrange(1, 2 * n-1) do (    if (i->compareTo((n - j + 1))) > 0 then  (
      execute ("")->display();
    )
    else (
      execute ("*")->display();
      ) ;
    if (i + n - 1->compareTo(j)) > 0 then  (
      execute ("")->display();
    )
    else (
      execute ("*")->display();
      )) ;
    execute ("")->display();) ;
    for i : Integer.subrange(1, n + 1-1) do (    for j : Integer.subrange(1, 2 * n-1) do (    if (i->compareTo(j)) < 0 then  (
      execute ("")->display();
    )
    else (
      execute ("*")->display();
      ) ;
    if (i->compareTo(2 * n - j)) < 0 then  (
      execute ("")->display();
    )
    else (
      execute ("*")->display();
      )) ;
    execute ("")->display(););
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
l,r=map(int,input().split())
ten=1
res=0
for i in range(18):
    for d in range(1,10,1):
        low,high=d*ten,(d+1)*ten-1
        low=max(low,l)
        high=min(high,r)
        while low % 10!=d :
            low+=1
        while high % 10!=d :
            high-=1
        if low<=high :
            res+=(high-low)//10+1
    ten*=10
print(res)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var l : OclAny := null;
    var r : OclAny := null;
    Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var ten : int := 1 ;
    var res : int := 0 ;
    for i : Integer.subrange(0, 18-1) do (    for d : Integer.subrange(1, 10-1)->select( $x | ($x - 1) mod 1 = 0 ) do (    var low : OclAny := null;
    var high : OclAny := null;
    Sequence{low,high} := Sequence{d * ten,(d + 1) * ten - 1} ;
    var low : OclAny := Set{low, l}->max() ;
    var high : OclAny := Set{high, r}->min() ;
    while low mod 10 /= d do (    low := low + 1) ;
    while high mod 10 /= d do (    high := high - 1) ;
    if (low->compareTo(high)) <= 0 then (
      res := res + (high - low) div 10 + 1
    ) else skip) ;
    ten := ten * 10) ;
    execute (res)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def ff(num):
    return(int(num)//10-(0 if int(str(num)[0])<=int(str(num)[-1])else 1)+9)if int(num)>=10 else int(num)
def main():
    mode="filee"
    if mode=="file" : f=open("test.txt","r")
    get=lambda :[int(x)for x in(f.readline()if mode=="file" else input()).split()]
[l,r]=get()
    print(ff(r)-ff(l-1))
    if mode=="file" : f.close()
if __name__=="__main__" :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    Sequence{l}->union(Sequence{ r }) := get->apply();
  operation ff(num : OclAny) : OclAny
  pre: true post: true
  activity:
    return if ("" + ((num)))->toInteger() >= 10 then (("" + ((num)))->toInteger() div 10 - (if (("" + ((OclType["String"](num)->first())))->toInteger()->compareTo(("" + ((OclType["String"](num)->last())))->toInteger())) <= 0 then 0 else 1 endif) + 9) else ("" + ((num)))->toInteger() endif;
  operation main()
  pre: true post: true
  activity:
    var mode : String := "filee" ;
    if mode = "file" then (
      var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("test.txt"))
    ) else skip ;
    var get : Function := lambda $$ : OclAny in ((if mode = "file" then f.readLine() else (OclFile["System.in"]).readLine() endif).split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def f(x): return x if x<10 else x//10+9-(0 if str(x)[0]<=str(x)[-1]else 1)
l,r=map(int,input().split())
print(f(r)-f(l-1))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var l : OclAny := null;
    var r : OclAny := null;
    Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (f(r) - f(l - 1))->display();
  operation f(x : OclAny) : OclAny
  pre: true post: true
  activity:
    return if x < 10 then x else x div 10 + 9 - (if (OclType["String"](x)->first()->compareTo(OclType["String"](x)->last())) <= 0 then 0 else 1 endif) endif;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def find(s):
    n=len(s)
    x=int(s)
    if(x<10):
        return x
    ans=x//10-1
    ans=ans+9
    if(s[0]<=s[n-1]):
        ans=ans+1
    return ans
l,r=map(int,input().split())
l=l-1
l=str(l)
r=str(r)
count1=find(l)
count2=find(r)
print(count2-count1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var l : OclAny := null;
    var r : OclAny := null;
    Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var l : double := l - 1 ;
    l := ("" + ((l))) ;
    var r : String := ("" + ((r))) ;
    var count1 : OclAny := find(l) ;
    var count2 : OclAny := find(r) ;
    execute (count2 - count1)->display();
  operation find(s : OclAny) : OclAny
  pre: true post: true
  activity:
    var n : int := (s)->size() ;
    var x : int := ("" + ((s)))->toInteger() ;
    if (x < 10) then (
      return x
    ) else skip ;
    var ans : double := x div 10 - 1 ;
    ans := ans + 9 ;
    if ((s->first()->compareTo(s[n - 1+1])) <= 0) then (
      ans := ans + 1
    ) else skip ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
readline=sys.stdin.readline
K=int(readline())
N=2000
for x in range(10**6,-1,-1):
    if(K+x)% 2000==0 and(K+x)//NtoInteger() ;
    var N : int := 2000 ;
    for x : Integer.subrange(-1 + 1, (10)->pow(6))->reverse() do (    if (K + x) mod 2000 = 0 & ((K + x) div N->compareTo(x)) < 0 then (
      var ans_lst : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N - 2))->union(Sequence{(K + x) div N - x}->union(Sequence{ x }))
    ) else skip) ;
    execute (N)->display() ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name ans_lst))))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
k=int(input())
z=k//(1999)
z+=1
alpha=(z*1999)-k
y=z+alpha
print(2000)
for i in range(2000):
    if(i<1998):
        print(0,end=" ")
    elif(i==1998):
        print(-alpha,end=" ")
    else :
        print(y)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var z : int := k div (1999) ;
    z := z + 1 ;
    var alpha : double := (z * 1999) - k ;
    var y : int := z + alpha ;
    execute (2000)->display() ;
    for i : Integer.subrange(0, 2000-1) do (    if (i < 1998) then  (
      execute (0)->display()
    )
    else (if (i = 1998) then
   (
      execute (-alpha)->display()    
)
    else (
      execute (y)->display()
      )    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
k=int(input())
ans=[-1]
k+=2
while k>1000000 :
    ans.append(1000000)
    k-=1000000
    k+=1
if k>0 :
    ans.append(k)
print(len(ans))
print(*ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var ans : Sequence := Sequence{ -1 } ;
    k := k + 2 ;
    while k > 1000000 do (    execute ((1000000) : ans) ;
    k := k - 1000000 ;
    k := k + 1) ;
    if k > 0 then (
      execute ((k) : ans)
    ) else skip ;
    execute ((ans)->size())->display() ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
arr=list(map(int,input().split()))
x=max(arr)
arr_sum=sum(arr)
if arr_sum-x>=x and arr_sum % 2==0 : print('YES')
else : print('NO')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var x : OclAny := (arr)->max() ;
    var arr_sum : OclAny := (arr)->sum() ;
    if (arr_sum - x->compareTo(x)) >= 0 & arr_sum mod 2 = 0 then  (
      execute ('YES')->display()
    )
    else (
      execute ('NO')->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
num_inp=lambda : int(input())
arr_inp=lambda : list(map(int,input().split()))
sp_inp=lambda : map(int,input().split())
str_inp=lambda : input()
n=int(input())
s=input()
for i in range(n-1):
    if s[i]>s[i+1]: print('YES'); print(i+1,i+2); exit()
print('NO')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ;
    var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ;
    var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : String := (OclFile["System.in"]).readLine() ;
    for i : Integer.subrange(0, n - 1-1) do (    if (s[i+1]->compareTo(s[i + 1+1])) > 0 then (
      execute ('YES')->display();    execute (i + 1)->display();    exit()
    ) else skip) ;
    execute ('NO')->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t,h=map(int,input().split())
print((h-2)//(t-1)+1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : OclAny := null;
    var h : OclAny := null;
    Sequence{t,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute ((h - 2) div (t - 1) + 1)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
k,m=int(input()),1500 ; a=m-k % m
print(m+1,*[0]*(m-1)+[-a,(k+a)//m+a])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var k : OclAny := null;
    var m : OclAny := null;
    Sequence{k,m} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),1500};    var a : double := m - k mod m ;
    execute (m + 1)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
k,m=int(input()),1500 ; a=m-k % m ; print(m+1,*[0]*(m-1)+[-a,(k+a)//m+a])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var k : OclAny := null;
    var m : OclAny := null;
    Sequence{k,m} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),1500};    var a : double := m - k mod m;    execute (m + 1)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
n=int(input())
ava=[1]*(2*n+1)
team=[0]*(2*n+1)
member=[]
high=[]
def check(a,b):
    team[b]=a
    team[a]=b
    ava[b]=0
    ava[a]=0
for _ in range(2*n-1):
    a=list(map(int,input().split()))
    member.append(a)
    high.append(max(a))
def mak_high():
    hi=[]
    for i in range(2*n-1):
        if ava[i+2]:
            canb=[]
            for j in range(i+1):
                if ava[j+1]:
                    canb.append(member[i][j])
                else :
                    canb.append(0)
            hi.append(max(canb))
        else :
            hi.append(0)
    ma=max(hi)
    A=hi.index(ma)
    B=member[A].index(ma)
    check(A+2,B+1)
    return
for i in range(n):
    mak_high()
last=[]
for m in range(1,2*n+1):
    if ava[m]:
        last.append(m)
for j in range(1,2*n+1):
    print(team[j],end=" ")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var ava : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (2 * n + 1)) ;
    var team : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * n + 1)) ;
    var member : Sequence := Sequence{} ;
    var high : Sequence := Sequence{} ;
    skip ;
    for _anon : Integer.subrange(0, 2 * n - 1-1) do (    a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute ((a) : member) ;
    execute (((a)->max()) : high)) ;
    skip ;
    for i : Integer.subrange(0, n-1) do (    mak_high()) ;
    var last : Sequence := Sequence{} ;
    for m : Integer.subrange(1, 2 * n + 1-1) do (    if ava[m+1] then (
      execute ((m) : last)
    ) else skip) ;
    for j : Integer.subrange(1, 2 * n + 1-1) do (    execute (team[j+1])->display());
  operation check(a : OclAny, b : OclAny)
  pre: true post: true
  activity:
    team[b+1] := a ;
    team[a+1] := b ;
    ava[b+1] := 0 ;
    ava[a+1] := 0;
  operation mak_high()
  pre: true post: true
  activity:
    var hi : Sequence := Sequence{} ;
    for i : Integer.subrange(0, 2 * n - 1-1) do (    if ava[i + 2+1] then  (
      var canb : Sequence := Sequence{} ;
    for j : Integer.subrange(0, i + 1-1) do (    if ava[j + 1+1] then  (
      execute ((member[i+1][j+1]) : canb)
    )
    else (
      execute ((0) : canb)
      )) ;
    execute (((canb)->max()) : hi)
    )
    else (
      execute ((0) : hi)
      )) ;
    var ma : OclAny := (hi)->max() ;
    var A : int := hi->indexOf(ma) - 1 ;
    var B : OclAny := member[A+1]->indexOf(ma) - 1 ;
    check(A + 2, B + 1) ;
    return;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def findPeakUtil(arr,low,high,n):
    mid=low+(high-low)/2
    mid=int(mid)
    if((mid==0 or arr[mid-1]<=arr[mid])and(mid==n-1 or arr[mid+1]<=arr[mid])):
        return mid
    elif(mid>0 and arr[mid-1]>arr[mid]):
        return findPeakUtil(arr,low,(mid-1),n)
    else :
        return findPeakUtil(arr,(mid+1),high,n)
def findPeak(arr,n):
    return findPeakUtil(arr,0,n-1,n)
arr=[1,3,20,4,1,0]
n=len(arr)
print("Index of a peak point is",findPeak(arr,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    arr := Sequence{1}->union(Sequence{3}->union(Sequence{20}->union(Sequence{4}->union(Sequence{1}->union(Sequence{ 0 }))))) ;
    n := (arr)->size() ;
    execute ("Index of a peak point is")->display();
  operation findPeakUtil(arr : OclAny, low : OclAny, high : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var mid : OclAny := low + (high - low) / 2 ;
    mid := ("" + ((mid)))->toInteger() ;
    if ((mid = 0 or (arr[mid - 1+1]->compareTo(arr[mid+1])) <= 0) & (mid = n - 1 or (arr[mid + 1+1]->compareTo(arr[mid+1])) <= 0)) then  (
      return mid
    )
    else (if (mid > 0 & (arr[mid - 1+1]->compareTo(arr[mid+1])) > 0) then
   (
      return findPeakUtil(arr, low, (mid - 1), n)    
)
    else (
      return findPeakUtil(arr, (mid + 1), high, n)
      )    )
;
  operation findPeak(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    return findPeakUtil(arr, 0, n - 1, n);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
team=[]
for x in range(2*n-1):
    c=list(map(int,input().split()))
    for ca in range(len(c)):
        team.append([c[ca],x+2,ca+1])
team=sorted(team,reverse=True)
answer=[0]*(2*n+1)
count=0
for x,y,z in team :
    if answer[y]==0 and answer[z]==0 :
        count+=1
        answer[y]=z
        answer[z]=y
        if count==n :
            for ad in answer[1 :]:
                print(ad,end=' ')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var team : Sequence := Sequence{} ;
    for x : Integer.subrange(0, 2 * n - 1-1) do (    var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    for ca : Integer.subrange(0, (c)->size()-1) do (    execute ((Sequence{c[ca+1]}->union(Sequence{x + 2}->union(Sequence{ ca + 1 }))) : team))) ;
    team := team->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ;
    var answer : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * n + 1)) ;
    var count : int := 0 ;
    for _tuple : team do (var _indx : int := 1;
      var x : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var y : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var z : OclAny := _tuple->at(_indx);
      if answer[y+1] = 0 & answer[z+1] = 0 then (
      count := count + 1 ;
    answer[y+1] := z ;
    answer[z+1] := y ;
    if count = n then (
      for ad : answer->tail() do (    execute (ad)->display())
    ) else skip
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
team=[]
for x in range(2*n-1):
    c=list(map(int,input().split()))
    for ca in range(len(c)):
        team.append([c[ca],x+2,ca+1])
team=sorted(team,reverse=True)
answer=[0]*(2*n+1)
count=0
for x,y,z in team :
    if answer[y]==0 and answer[z]==0 :
        count+=1
        answer[y]=z
        answer[z]=y
        if count==n :
            print(*answer[1 :])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var team : Sequence := Sequence{} ;
    for x : Integer.subrange(0, 2 * n - 1-1) do (    var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    for ca : Integer.subrange(0, (c)->size()-1) do (    execute ((Sequence{c[ca+1]}->union(Sequence{x + 2}->union(Sequence{ ca + 1 }))) : team))) ;
    team := team->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ;
    var answer : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * n + 1)) ;
    var count : int := 0 ;
    for _tuple : team do (var _indx : int := 1;
      var x : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var y : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var z : OclAny := _tuple->at(_indx);
      if answer[y+1] = 0 & answer[z+1] = 0 then (
      count := count + 1 ;
    answer[y+1] := z ;
    answer[z+1] := y ;
    if count = n then (
      execute ((argument * (test (logical_test (comparison (expr (atom (name answer)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))))))))->display()
    ) else skip
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from typing import List
def get_contestant_teammates(n : int,values : List[List[int]])->List[int]:
    strength=[]
    pair=[0]*(2*n+1)
    for i in range(2*n-1):
        for j in range(i+1):
            strength.append((values[i][j],i+2,j+1))
    strength.sort(reverse=True)
    for s,i,j in strength :
        if pair[i]==0 and pair[j]==0 :
            pair[i]=j
            pair[j]=i
    return pair[1 :]
n=int(input())
a=[]
for i in range(2*n-1):
    b=[int(j)for j in input().split()]
    a.append(b)
b=get_contestant_teammates(n,a)
print(*b)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := Sequence{} ;
    for i : Integer.subrange(0, 2 * n - 1-1) do (    var b : Sequence := input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ;
    execute ((b) : a)) ;
    b := get_contestant_teammates(n, a) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name b))))))))->display();
  operation get_contestant_teammates(n : int, values : List[List[OclType["int"]+1]+1]) : OclAny
  pre: true post: true
  activity:
    var strength : Sequence := Sequence{} ;
    var pair : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * n + 1)) ;
    for i : Integer.subrange(0, 2 * n - 1-1) do (    for j : Integer.subrange(0, i + 1-1) do (    execute ((Sequence{values[i+1][j+1], i + 2, j + 1}) : strength))) ;
    strength := strength->sort() ;
    for _tuple : strength do (var _indx : int := 1;
      var s : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var j : OclAny := _tuple->at(_indx);
      if pair[i+1] = 0 & pair[j+1] = 0 then (
      pair[i+1] := j ;
    pair[j+1] := i
    ) else skip) ;
    return pair->tail();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
MAX=7368792
for e in iter(input,'0 0'):
    m,n=map(int,e.split())
    table=[False]*MAX
    for _ in range(n):
        table[m : : m]=[True]*len(table[m : : m])
        while table[m]: m+=1
    print(m)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var MAX : int := 7368792 ;
    for e : OclIterator.newOclIterator_Sequence(input, '0 0') do (    var m : OclAny := null;
    var n : OclAny := null;
    Sequence{m,n} := (e.split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var table : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, MAX) ;
    for _anon : Integer.subrange(0, n-1) do (    table(subscript (test (logical_test (comparison (expr (atom (name m)))))) : (sliceop : (test (logical_test (comparison (expr (atom (name m)))))))) := MatrixLib.elementwiseMult(Sequence{ true }, (table(subscript (test (logical_test (comparison (expr (atom (name m)))))) : (sliceop : (test (logical_test (comparison (expr (atom (name m)))))))))->size()) ;
    while table[m+1] do (    m := m + 1)) ;
    execute (m)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
MAX=7368792
while True :
    m,n=map(int,input().split())
    if m+n==0 :
        break
    E=[True]*(MAX)
    k=0
    for i in range(m,MAX):
        if E[i]:
            n-=1
            E[i : : i]=[False]*((MAX-i-1)//i+1)
            if n!=0 :
                continue
            i+=1
            while not E[i]:
                i+=1
            print(i)
            break
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var MAX : int := 7368792 ;
    while true do (    var m : OclAny := null;
    var n : OclAny := null;
    Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if m + n = 0 then (
      break
    ) else skip ;
    var E : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (MAX)) ;
    var k : int := 0 ;
    for i : Integer.subrange(m, MAX-1) do (    if E[i+1] then (
      n := n - 1 ;
    E(subscript (test (logical_test (comparison (expr (atom (name i)))))) : (sliceop : (test (logical_test (comparison (expr (atom (name i)))))))) := MatrixLib.elementwiseMult(Sequence{ false }, ((MAX - i - 1) div i + 1)) ;
    if n /= 0 then (
      continue
    ) else skip ;
    i := i + 1 ;
    while not(E[i+1]) do (    i := i + 1) ;
    execute (i)->display() ;
    break
    ) else skip));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main(m,n):
    ck=[True]*(7368792)
    for i in range(m,7368792):
        if ck[i]:
            n-=1
            ck[i : : i]=[False]*((7368791-i)//i+1)
            if n!=0 :
                continue
            i+=1
            while not ck[i]:
                i+=1
            print(i)
            return
while 1 :
    m,n=map(int,input().split())
    if n==m==0 :
        break
    main(m,n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    while 1 do (    Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if n = m & (m == 0) then (
      break
    ) else skip ;
    main(m, n));
  operation main(m : OclAny, n : OclAny)
  pre: true post: true
  activity:
    var ck : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (7368792)) ;
    for i : Integer.subrange(m, 7368792-1) do (    if ck[i+1] then (
      n := n - 1 ;
    ck(subscript (test (logical_test (comparison (expr (atom (name i)))))) : (sliceop : (test (logical_test (comparison (expr (atom (name i)))))))) := MatrixLib.elementwiseMult(Sequence{ false }, ((7368791 - i) div i + 1)) ;
    if n /= 0 then (
      continue
    ) else skip ;
    i := i + 1 ;
    while not(ck[i+1]) do (    i := i + 1) ;
    execute (i)->display() ;
    return
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def rearrange(arr,n):
    j=0
    for i in range(0,n):
        if(arr[i]<0):
            temp=arr[i]
            arr[i]=arr[j]
            arr[j]=temp
            j=j+1
    print(arr)
arr=[-1,2,-3,4,5,6,-7,8,9]
n=len(arr)
rearrange(arr,n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    arr := Sequence{-1}->union(Sequence{2}->union(Sequence{-3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{-7}->union(Sequence{8}->union(Sequence{ 9 })))))))) ;
    n := (arr)->size() ;
    rearrange(arr, n);
  operation rearrange(arr : OclAny, n : OclAny)
  pre: true post: true
  activity:
    var j : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    if (arr[i+1] < 0) then (
      var temp : OclAny := arr[i+1] ;
    arr[i+1] := arr[j+1] ;
    arr[j+1] := temp ;
    j := j + 1
    ) else skip) ;
    execute (arr)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import itertools
def compute():
    LIMIT=10**8
    smallestdivisiblefactorials=[0]*(LIMIT+1)
    for i in range(2,len(smallestdivisiblefactorials)):
        if smallestdivisiblefactorials[i]==0 :
            power=1
            for j in itertools.count(i,i):
                power*=i
                if power>LIMIT :
                    break
                for k in range(power,len(smallestdivisiblefactorials),power):
                    smallestdivisiblefactorials[k]=max(j,smallestdivisiblefactorials[k])
                temp=j//i
                while temp % i==0 :
                    power*=i
                    temp//=i
    ans=sum(smallestdivisiblefactorials)
    return str(ans)
if __name__=="__main__" :
    print(compute())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      execute (compute())->display()
    ) else skip;
  operation compute() : OclAny
  pre: true post: true
  activity:
    var LIMIT : double := (10)->pow(8) ;
    var smallestdivisiblefactorials : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (LIMIT + 1)) ;
    for i : Integer.subrange(2, (smallestdivisiblefactorials)->size()-1) do (    if smallestdivisiblefactorials[i+1] = 0 then (
      var power : int := 1 ;
    for j : itertools->count(i, i) do (    power := power * i ;
    if (power->compareTo(LIMIT)) > 0 then (
      break
    ) else skip ;
    for k : Integer.subrange(power, (smallestdivisiblefactorials)->size()-1)->select( $x | ($x - power) mod power = 0 ) do (    smallestdivisiblefactorials[k+1] := Set{j, smallestdivisiblefactorials[k+1]}->max()) ;
    var temp : int := j div i ;
    while temp mod i = 0 do (    power := power * i ;
    temp := temp div i))
    ) else skip) ;
    var ans : OclAny := (smallestdivisiblefactorials)->sum() ;
    return ("" + ((ans)));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    H,W=[int(i)for i in input().strip().split()]
    if H==0 and W==0 :
        break
    else :
        for i in range(H):
            print("#"*W)
    print()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    var H : OclAny := null;
    var W : OclAny := null;
    Sequence{H,W} := input()->trim().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    if H = 0 & W = 0 then  (
      break
    )
    else (
      for i : Integer.subrange(0, H-1) do (    execute (StringLib.nCopies("#", W))->display())
      ) ;
    execute (->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
i=list(map(int,input().split()))
H=i[0]
W=i[1]
while H!=0 or W!=0 :
    for i in range(H):
        for j in range(W):
            print('#',end='')
        if W!=0 :
            print()
    print()
    i=list(map(int,input().split()))
    H=i[0]
    W=i[1]
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var i : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var H : OclAny := i->first() ;
    var W : OclAny := i[1+1] ;
    while H /= 0 or W /= 0 do (    for i : Integer.subrange(0, H-1) do (    for j : Integer.subrange(0, W-1) do (    execute ('#')->display()) ;
    if W /= 0 then (
      execute (->display()
    ) else skip) ;
    execute (->display() ;
    i := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    H := i->first() ;
    W := i[1+1]);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    height,width=map(int,input().split())
    if height==0 and width==0 :
        break
    for col in range(height):
        for row in range(width):
            print('#',end='')
        print('')
    print('')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    var height : OclAny := null;
    var width : OclAny := null;
    Sequence{height,width} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if height = 0 & width = 0 then (
      break
    ) else skip ;
    for col : Integer.subrange(0, height-1) do (    for row : Integer.subrange(0, width-1) do (    execute ('#')->display()) ;
    execute ('')->display()) ;
    execute ('')->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
result="A"
for(p1,p2)in(l.strip().split(",")for l in sys.stdin.readlines()):
    if result==p1 :
        result=p2
    elif result==p2 :
        result=p1
print(result)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var result : String := "A" ;
    for Sequence{p1, p2} : Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name l)) (trailer . (name strip) (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ","))))))) ))))))) (comp_for for (exprlist (expr (atom (name l)))) in (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin)) (trailer . (name readlines) (arguments ( ))))))))} do (    if result = p1 then  (
      result := p2
    )
    else (if result = p2 then
   (
      result := p1    
)
 else skip)) ;
    execute (result)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    a,b=map(int,input().split())
    for i in range(a):
        print("#"*b)
    if a==0 and b==0 :
        break
    print()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    for i : Integer.subrange(0, a-1) do (    execute (StringLib.nCopies("#", b))->display()) ;
    if a = 0 & b = 0 then (
      break
    ) else skip ;
    execute (->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
all_N=[]
while True :
    N=list(map(int,input().split('')))
    if N[0]==0 and N[0]==0 :
        break
    all_N.append(N)
for i in range(len(all_N)):
    for j in range(all_N[i][0]):
        print('#'*all_N[i][1])
    print('')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var all_N : Sequence := Sequence{} ;
    while true do (    var N : Sequence := ((input().split(''))->collect( _x | (OclType["int"])->apply(_x) )) ;
    if N->first() = 0 & N->first() = 0 then (
      break
    ) else skip ;
    execute ((N) : all_N)) ;
    for i : Integer.subrange(0, (all_N)->size()-1) do (    for j : Integer.subrange(0, all_N[i+1]->first()-1) do (    execute (StringLib.nCopies('#', all_N[i+1][1+1]))->display()) ;
    execute ('')->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def printArray(matrix):
    rowCount=len(matrix)
    if rowCount==0 :
        return
    columnCount=len(matrix[0])
    if columnCount==0 :
        return
    row_output_format=" ".join(["%s"]*columnCount)
    printed={}
    for row in matrix :
        routput=row_output_format % tuple(row)
        if routput not in printed :
            printed[routput]=True
            print(routput)
mat=[[0,1,0,0,1],[1,0,1,1,0],[0,1,0,0,1],[1,1,1,0,0]]
printArray(mat)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var mat : Sequence := Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 1 }))))}->union(Sequence{Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 0 }))))}->union(Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 1 }))))}->union(Sequence{ Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 0 })))) }))) ;
    printArray(mat);
  operation printArray(matrix : OclAny)
  pre: true post: true
  activity:
    var rowCount : int := (matrix)->size() ;
    if rowCount = 0 then (
      return
    ) else skip ;
    var columnCount : int := (matrix->first())->size() ;
    if columnCount = 0 then (
      return
    ) else skip ;
    var row_output_format : String := StringLib.sumStringsWithSeparator((MatrixLib.elementwiseMult(Sequence{ "%s" }, columnCount)), " ") ;
    var printed : OclAny := Set{} ;
    for row : matrix do (    var routput : String := StringLib.format(row_output_format,(row)) ;
    if (printed)->excludes(routput) then (
      printed->at(routput) := true ;
    execute (routput)->display()
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def seive(n):
    prime=[True]*(n+1)
    p=2
    while(p*p<=n):
        if(prime[p]==True):
            for i in range(p*p,n+1,p):
                prime[i]=False
        p+=1
    allPrimes=[x for x in range(2,n)if prime[x]]
    return allPrimes
def distPrime(arr,allPrimes):
    list1=list()
    for i in allPrimes :
        for j in arr :
            if(j % i==0):
                list1.append(i)
                break
    return list1
if __name__=="__main__" :
    allPrimes=seive(10000)
    arr=[15,30,60]
    ans=distPrime(arr,allPrimes)
    print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      allPrimes := seive(10000) ;
    arr := Sequence{15}->union(Sequence{30}->union(Sequence{ 60 })) ;
    var ans : OclAny := distPrime(arr, allPrimes) ;
    execute (ans)->display()
    ) else skip;
  operation seive(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (n + 1)) ;
    var p : int := 2 ;
    while ((p * p->compareTo(n)) <= 0) do (    if (prime[p+1] = true) then (
      for i : Integer.subrange(p * p, n + 1-1)->select( $x | ($x - p * p) mod p = 0 ) do (    prime[i+1] := false)
    ) else skip ;
    p := p + 1) ;
    var allPrimes : Sequence := Integer.subrange(2, n-1)->select(x | prime[x+1])->collect(x | (x)) ;
    return allPrimes;
  operation distPrime(arr : OclAny, allPrimes : OclAny) : OclAny
  pre: true post: true
  activity:
    var list1 : Sequence := () ;
    for i : allPrimes do (    for j : arr do (    if (j mod i = 0) then (
      execute ((i) : list1) ;
    break
    ) else skip)) ;
    return list1;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
R=int(input())
if R<1200 :
    print('ABC')
elif R<2800 :
    print('ARC')
else :
    print('AGC')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var R : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if R < 1200 then  (
      execute ('ABC')->display()
    )
    else (if R < 2800 then
   (
      execute ('ARC')->display()    
)
    else (
      execute ('AGC')->display()
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    a,b=map(int,input().split())
    if b==1 :
        print(0)
        return
    count=0
    sum=a
    count+=1
    if sum>=b :
        print(1)
        return
    while sumcollect( _x | (OclType["int"])->apply(_x) ) ;
    if b = 1 then (
      execute (0)->display() ;
    return
    ) else skip ;
    var count : int := 0 ;
    var sum : OclAny := a ;
    count := count + 1 ;
    if (sum->compareTo(b)) >= 0 then (
      execute (1)->display() ;
    return
    ) else skip ;
    while (sum->compareTo(b)) < 0 do (    sum := sum + (a - 1) ;
    count := count + 1) ;
    execute (count)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
R=int(input())
print(['ABC','ARC','AGC'][(R>=1200)+(R>=2800)])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var R : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    execute (Sequence{'ABC'}->union(Sequence{'ARC'}->union(Sequence{ 'AGC' }))->select((R >= 1200) + (R >= 2800)))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def input():
    return sys.stdin.readline().rstrip()
if __name__=="__main__" :
    r=int(input())
    if r<1200 :
        print("ABC")
    elif r<2800 :
        print("ARC")
    else :
        print("AGC")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      var r : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if r < 1200 then  (
      execute ("ABC")->display()
    )
    else (if r < 2800 then
   (
      execute ("ARC")->display()    
)
    else (
      execute ("AGC")->display()
      )    )
    ) else skip;
  operation input() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine().rstrip();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=int(input())
if a>=2800 :
    print('AGC')
elif a>=1200 :
    print('ARC')
else :
    print('ABC')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if a >= 2800 then  (
      execute ('AGC')->display()
    )
    else (if a >= 1200 then
   (
      execute ('ARC')->display()    
)
    else (
      execute ('ABC')->display()
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s=int(input())
if s<1200 : print('ABC')
elif s<2800 : print('ARC')
else : print('AGC')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if s < 1200 then  (
      execute ('ABC')->display()
    )
    else (if s < 2800 then
   (
      execute ('ARC')->display()    
)
    else (
      execute ('AGC')->display()
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import fractions
n=int(input())
x=list(map(int,input().split()))
y=x[0]
for i in range(1,n):
    y=y*x[i]//fractions.gcd(y,x[i])
print(y)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var y : OclAny := x->first() ;
    for i : Integer.subrange(1, n-1) do (    y := y * x[i+1] div fractions.gcd(y, x[i+1])) ;
    execute (y)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
di={"A" : 1,"B" : 0,"C" : 0}
while(True):
    try :
        x,y=input().split(",")
        di[x],di[y]=di[y],di[x]
    except :
        print([x for x in di.keys()if di[x]==1][0])
        break
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var di : Map := Map{ "A" |-> 1 }->union(Map{ "B" |-> 0 }->union(Map{ "C" |-> 0 })) ;
    while (true) do (    try (    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := input().split(",") ;
    var di[x+1] : OclAny := null;
    var di[y+1] : OclAny := null;
    Sequence{di[x+1],di[y+1]} := Sequence{di[y+1],di[x+1]})
     catch (_e : OclException) do (    execute (di.keys()->select(x | di[x+1] = 1)->collect(x | (x))->first())->display() ;
    break)
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def gcd(x,y):
    p=min(x,y)
    q=max(x,y)
    while p!=q :
        if q>p :
            q=q-p
        else :
            p=p-q
    return q
n=int(input())
a=sorted(set(list(map(int,input().split()))))
while len(a)>1 :
    p=a[0]
    q=a[1]
    g=gcd(p,q)
    a.append(p*q//g)
    a.pop(0)
    a.pop(0)
    a=sorted(a)
print(*a)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := Set{}->union((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))->sort() ;
    while (a)->size() > 1 do (    p := a->first() ;
    q := a[1+1] ;
    var g : OclAny := gcd(p, q) ;
    execute ((p * q div g) : a) ;
    a := a->excludingAt(0+1) ;
    a := a->excludingAt(0+1) ;
    a := a->sort()) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display();
  operation gcd(x : OclAny, y : OclAny) : OclAny
  pre: true post: true
  activity:
    var p : OclAny := Set{x, y}->min() ;
    var q : OclAny := Set{x, y}->max() ;
    while p /= q do (    if (q->compareTo(p)) > 0 then  (
      q := q - p
    )
    else (
      p := p - q
      )) ;
    return q;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=input()
target=list(map(int,input().split()))
def calc_factors(N):
    n=int(N**.5)
    arr=[]
    tmp=N
    for i in range(2,n+1):
        if tmp % i==0 :
            while tmp % i==0 :
                arr.append(i)
                tmp=int(tmp/i)
    if tmp!=1 : arr.append(tmp)
    return arr
d={}
for i in target :
    arr=calc_factors(i)
    for a in set(arr):
        if a in d.keys():
            d[a]=max(d[a],arr.count(a))
        else :
            d[a]=arr.count(a)
res=1
for k,v in d.items():
    res*=(int(k)**int(v))
print(res)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : String := (OclFile["System.in"]).readLine() ;
    var target : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    skip ;
    var d : OclAny := Set{} ;
    for i : target do (    arr := calc_factors(i) ;
    for a : Set{}->union((arr)) do (    if (d.keys())->includes(a) then  (
      d[a+1] := Set{d[a+1], arr->count(a)}->max()
    )
    else (
      d[a+1] := arr->count(a)
      ))) ;
    var res : int := 1 ;
    for _tuple : d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1;
      var k : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var v : OclAny := _tuple->at(_indx);
      res := res * ((("" + ((k)))->toInteger())->pow(("" + ((v)))->toInteger()))) ;
    execute (res)->display();
  operation calc_factors(N : OclAny) : OclAny
  pre: true post: true
  activity:
    var n : int := ("" + (((N)->pow(.5))))->toInteger() ;
    var arr : Sequence := Sequence{} ;
    var tmp : String := N ;
    for i : Integer.subrange(2, n + 1-1) do (    if StringLib.format(tmp,i) = 0 then (
      while StringLib.format(tmp,i) = 0 do (    execute ((i) : arr) ;
    tmp := ("" + ((tmp / i)))->toInteger())
    ) else skip) ;
    if tmp /= 1 then (
      execute ((tmp) : arr)
    ) else skip ;
    return arr;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import*; n,a=open(0); l=1
for x in map(int,a.split()): l=l*x//gcd(x,l)
print(l)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip;    var n : OclAny := null;
    var a : OclAny := null;
    Sequence{n,a} := OclFile.newOclFile_Write(OclFile.newOclFile(0));    var l : int := 1 ;
    for x : (a.split())->collect( _x | (OclType["int"])->apply(_x) ) do (    l := l * x div gcd(x, l)) ;
    execute (l)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
input()
L=list(map(int,input().split()))
m=[[]for x in range(len(L))]
for i in range(len(L)):
    n=L[i]
    k=n
    for j in range(2,int(math.sqrt(n))+1):
        if j>k :
            break
        while k % j==0 :
            m[i].append(j)
            k=k//j
            if k==1 :
                break
    if k!=1 :
        m[i].append(k)
s=set()
for i in m :
    s |=set(i)
lcm=1
for i in s :
    lcm*=i**max([m[x].count(i)for x in range(len(L))])
print(lcm)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    input() ;
    var L : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var m : Sequence := Integer.subrange(0, (L)->size()-1)->select(x | true)->collect(x | (Sequence{})) ;
    for i : Integer.subrange(0, (L)->size()-1) do (    var n : OclAny := L[i+1] ;
    var k : OclAny := n ;
    for j : Integer.subrange(2, ("" + (((n)->sqrt())))->toInteger() + 1-1) do (    if (j->compareTo(k)) > 0 then (
      break
    ) else skip ;
    while k mod j = 0 do ((expr (atom (name m)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) ;
    k := k div j ;
    if k = 1 then (
      break
    ) else skip)) ;
    if k /= 1 then (
  (expr (atom (name m)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name k)))))))) ))))
    ) else skip) ;
    var s : Set := Set{}->union(()) ;
    for i : m do (    s := s or Set{}->union((i))) ;
    var lcm : int := 1 ;
    for i : s do (    lcm := lcm * (i)->pow((Integer.subrange(0, (L)->size()-1)->select(x | true)->collect(x | (m[x+1]->count(i))))->max())) ;
    execute (lcm)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
nums=list(map(int,input().split()))
A,B=nums[0],nums[1]
import math
if B==1 :
    print(0)
else :
    print(math.ceil(((B-A)/(A-1))+1))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var nums : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var A : OclAny := null;
    var B : OclAny := null;
    Sequence{A,B} := Sequence{nums->first(),nums[1+1]} ;
    skip ;
    if B = 1 then  (
      execute (0)->display()
    )
    else (
      execute ((((B - A) / (A - 1)) + 1)->ceil())->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
MAX=10 ;
def binomialCoeff(C,n,k):
    for i in range(n+1):
        for j in range(0,min(i,k)+1):
            if(j==0 or j==i):
                C[i][j]=1 ;
            else :
                C[i][j]=C[i-1][j-1]+C[i-1][j];
def countParallelogram(n,m):
    C=[[0 for i in range(MAX)]for j in range(MAX)]
    binomialCoeff(C,max(n,m),2);
    return C[n][2]*C[m][2];
if __name__=='__main__' :
    n=5 ;
    m=5 ;
    print(countParallelogram(n,m));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var MAX : int := 10; ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      n := 5; ;
    m := 5; ;
    execute (countParallelogram(n, m))->display();
    ) else skip;
  operation binomialCoeff(C : OclAny, n : OclAny, k : OclAny)
  pre: true post: true
  activity:
    for i : Integer.subrange(0, n + 1-1) do (    for j : Integer.subrange(0, Set{i, k}->min() + 1-1) do (    if (j = 0 or j = i) then  (
      C[i+1][j+1] := 1;
    )
    else (
      C[i+1][j+1] := C[i - 1+1][j - 1+1] + C[i - 1+1][j+1];
      )));
  operation countParallelogram(n : OclAny, m : OclAny)
  pre: true post: true
  activity:
    C := Integer.subrange(0, MAX-1)->select(j | true)->collect(j | (Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)))) ;
    binomialCoeff(C, Set{n, m}->max(), 2); ;
    return C[n+1][2+1] * C[m+1][2+1];;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import bisect
n,m=map(int,input().split())
pos=list(map(int,input().split()))
q=int(input())
l=list(map(int,input().split()))
pos.append(n+1)
d=[pos[i+1]-pos[i]-1 for i in range(m)]
d.sort()
s=[0]*(m+1)
for i in range(len(d)):
    s[i+1]=s[i]+d[i]
for lim in l :
    ok=n+1
    ng=0
    while abs(ok-ng)>1 :
        mid=(ok+ng)//2
        idx=bisect.bisect_left(d,mid)
        cost=(s[-1]-s[idx])-(m-idx)*(mid-1)+(pos[0]-1)
        if cost<=lim :
            ok=mid
        else :
            ng=mid
    if ok<=n :
        print(ok)
    else :
        print(-1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var pos : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute ((n + 1) : pos) ;
    var d : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (pos[i + 1+1] - pos[i+1] - 1)) ;
    d := d->sort() ;
    var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (m + 1)) ;
    for i : Integer.subrange(0, (d)->size()-1) do (    s[i + 1+1] := s[i+1] + d[i+1]) ;
    for lim : l do (    var ok : OclAny := n + 1 ;
    var ng : int := 0 ;
    while (ok - ng)->abs() > 1 do (    var mid : int := (ok + ng) div 2 ;
    var idx : OclAny := bisect.bisect_left(d, mid) ;
    var cost : double := (s->last() - s[idx+1]) - (m - idx) * (mid - 1) + (pos->first() - 1) ;
    if (cost->compareTo(lim)) <= 0 then  (
      ok := mid
    )
    else (
      ng := mid
      )) ;
    if (ok->compareTo(n)) <= 0 then  (
      execute (ok)->display()
    )
    else (
      execute (-1)->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from bisect import bisect_left
def inpl(): return list(map(int,input().split()))
N,M=inpl()
X=inpl()
Q=int(input())
L=inpl()
X+=[N+1]
initcost=X[0]-1
costs=[X[i+1]-X[i]-1 for i in range(M)if X[i+1]-X[i]>1]
C=[0]*(N+1)
C[0]=-10**9
for i in range(1,N+1):
    cost=0
    costs2=[]
    for c in costs :
        cost+=c
        if c>1 :
            costs2.append(c-1)
    C[i]=-(initcost+cost)
    costs=costs2
for l in L :
    if l<-C[-1]:
        print(-1)
    else :
        print(bisect_left(C,-l))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := inpl() ;
    var X : OclAny := inpl() ;
    var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var L : OclAny := inpl() ;
    X := X + Sequence{ N + 1 } ;
    var initcost : double := X->first() - 1 ;
    var costs : Sequence := Integer.subrange(0, M-1)->select(i | X[i + 1+1] - X[i+1] > 1)->collect(i | (X[i + 1+1] - X[i+1] - 1)) ;
    var C : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ;
    C->first() := (-10)->pow(9) ;
    for i : Integer.subrange(1, N + 1-1) do (    var cost : int := 0 ;
    var costs2 : Sequence := Sequence{} ;
    for c : costs do (    cost := cost + c ;
    if c > 1 then (
      execute ((c - 1) : costs2)
    ) else skip) ;
    C[i+1] := -(initcost + cost) ;
    costs := costs2) ;
    for l : L do (    if (l->compareTo(-C->last())) < 0 then  (
      execute (-1)->display()
    )
    else (
      execute (bisect_left(C, -l))->display()
      ));
  operation inpl() : OclAny
  pre: true post: true
  activity:
    return ((input().split())->collect( _x | (OclType["int"])->apply(_x) ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s=input()
s=s.replace('apple','%a%')
s=s.replace('peach','%p%')
s=s.replace('%a%','peach')
s=s.replace('%p%','apple')
print(s)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : String := (OclFile["System.in"]).readLine() ;
    s := s.replace('apple', '%a%') ;
    s := s.replace('peach', '%p%') ;
    s := s.replace('%a%', 'peach') ;
    s := s.replace('%p%', 'apple') ;
    execute (s)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
w=str(input())
for i in range(len(w)):
    if i>len(w): break
    if w[i]=="a" and w[i+1]=="p" and w[i+2]=="p" and w[i+3]=="l" and w[i+4]=="e" :
        w=w[: i]+"peach"+w[i+5 :]
        continue
    if w[i]=="p" and w[i+1]=="e" and w[i+2]=="a" and w[i+3]=="c" and w[i+4]=="h" :
        w=w[: i]+"apple"+w[i+5 :]
print(w)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var w : String := ("" + (((OclFile["System.in"]).readLine()))) ;
    for i : Integer.subrange(0, (w)->size()-1) do (    if (i->compareTo((w)->size())) > 0 then (
      break
    ) else skip ;
    if w[i+1] = "a" & w[i + 1+1] = "p" & w[i + 2+1] = "p" & w[i + 3+1] = "l" & w[i + 4+1] = "e" then (
      w := w.subrange(1,i) + "peach" + w.subrange(i + 5+1) ;
    continue
    ) else skip ;
    if w[i+1] = "p" & w[i + 1+1] = "e" & w[i + 2+1] = "a" & w[i + 3+1] = "c" & w[i + 4+1] = "h" then (
      w := w.subrange(1,i) + "apple" + w.subrange(i + 5+1)
    ) else skip) ;
    execute (w)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
ans=[]
for word in input().split():
    if "apple" in word :
        ans.append(word.replace("apple","peach"))
    elif "peach" in word :
        ans.append(word.replace("peach","apple"))
    else :
        ans.append(word)
print(*ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var ans : Sequence := Sequence{} ;
    for word : input().split() do (    if (word)->includes("apple") then  (
      execute ((word.replace("apple", "peach")) : ans)
    )
    else (if (word)->includes("peach") then
   (
      execute ((word.replace("peach", "apple")) : ans)    
)
    else (
      execute ((word) : ans)
      )    )
) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def get_input():
    while True :
        try :
            yield ''.join(input())
        except EOFError :
            break
N=list(get_input())
ans="A"
for l in range(len(N)):
    c=N[l].split(",")
    if c[0]==ans :
        ans=c[1]
    elif c[1]==ans :
        ans=c[0]
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var N : Sequence := (OclIterator.newOclIterator_Function(lambda _i : int in self.get_input(_i))) ;
    var ans : String := "A" ;
    for l : Integer.subrange(0, (N)->size()-1) do (    var c : OclAny := N[l+1].split(",") ;
    if c->first() = ans then  (
      ans := c[1+1]
    )
    else (if c[1+1] = ans then
   (
      ans := c->first()    
)
 else skip)) ;
    execute (ans)->display();
  operation get_input(_position_ : int) : OclAny
  pre: true post: true
  activity:
    var _yieldCount_ : int := 0;
    while true do (    try (    if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return StringLib.sumStringsWithSeparator(((OclFile["System.in"]).readLine()), ''))
(except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
cs=list(input())
ap=[list('apple'),list('peach')]
for i in range(len(cs)-4):
    if cs[i : i+5]in ap :
        cs[i : i+5]=ap[1-ap.index(cs[i : i+5])]
print(''.join(cs))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var cs : Sequence := ((OclFile["System.in"]).readLine())->characters() ;
    var ap : Sequence := Sequence{('apple')->characters()}->union(Sequence{ ('peach')->characters() }) ;
    for i : Integer.subrange(0, (cs)->size() - 4-1) do (    if (ap)->includes(cs.subrange(i+1, i + 5)) then (
      cs.subrange(i+1, i + 5) := ap[1 - ap->indexOf(cs.subrange(i+1, i + 5)) - 1+1]
    ) else skip) ;
    execute (StringLib.sumStringsWithSeparator((cs), ''))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,p,t='apple','peach','_'
print(input().replace(a,t).replace(p,a).replace(t,p))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var p : OclAny := null;
    var t : OclAny := null;
    Sequence{a,p,t} := Sequence{'apple','peach','_'} ;
    execute (input().replace(a, t).replace(p, a).replace(t, p))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=map(int,input().split())
c=list(map(int,input().split()))
d=0 ; ans=b
for i in range(a-1):
    d=c[i+1 :]
    if max(d)>c[i]:
        d=((b//c[i])*max(d))+b % c[i]
        if d>ans :
            ans=d
    d=0
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var d : int := 0;    var ans : OclAny := b ;
    for i : Integer.subrange(0, a - 1-1) do (    d := c.subrange(i + 1+1) ;
    if ((d)->max()->compareTo(c[i+1])) > 0 then (
      d := ((b div c[i+1]) * (d)->max()) + b mod c[i+1] ;
    if (d->compareTo(ans)) > 0 then (
      ans := d
    ) else skip
    ) else skip ;
    d := 0) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
A,B=list(map(int,input().split()))
ans=0
for i in range(20):
    if 1+(A-1)*i>=B :
        ans=i
        break
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var A : OclAny := null;
    var B : OclAny := null;
    Sequence{A,B} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var ans : int := 0 ;
    for i : Integer.subrange(0, 20-1) do (    if (1 + (A - 1) * i->compareTo(B)) >= 0 then (
      ans := i ;
    break
    ) else skip) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,b=map(int,input().split())
p=tuple(map(int,input().split()))
res=b
for i in range(n):
    d=b//p[i]
    m=b % p[i]
    for j in range(i+1,n):
        if p[j]>p[i]:
            if d*p[j]+m>res :
                res=d*p[j]+m
print(res)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var b : OclAny := null;
    Sequence{n,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var res : OclAny := b ;
    for i : Integer.subrange(0, n-1) do (    var d : int := b div p[i+1] ;
    var m : int := b mod p[i+1] ;
    for j : Integer.subrange(i + 1, n-1) do (    if (p[j+1]->compareTo(p[i+1])) > 0 then (
      if (d * p[j+1] + m->compareTo(res)) > 0 then (
      res := d * p[j+1] + m
    ) else skip
    ) else skip)) ;
    execute (res)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import itertools
_,b=map(int,input().split())
a=list(map(int,input().split()))
low=list(itertools.accumulate(a,min))
print(max(b//u*v+b % u for u,v in zip(low,a)))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var _anon : OclAny := null;
    var b : OclAny := null;
    Sequence{_anon,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var low : Sequence := (itertools.accumulate(a, min)) ;
    execute (((argument (test (logical_test (comparison (expr (expr (expr (expr (atom (name b))) // (expr (atom (name u)))) * (expr (atom (name v)))) + (expr (expr (atom (name b))) % (expr (atom (name u)))))))) (comp_for for (exprlist (expr (atom (name u))) , (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name low))))))) , (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))))))))->max())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=map(int,input().split())
c=list(map(int,input().split()))
d=0 ; ans=b
for i in range(a-1):
    d=c[i+1 :]
    if max(d)>c[i]:
        d=((b//c[i])*max(d))+b % c[i]
        if d>ans :
            ans=d
    d=0
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var d : int := 0;    var ans : OclAny := b ;
    for i : Integer.subrange(0, a - 1-1) do (    d := c.subrange(i + 1+1) ;
    if ((d)->max()->compareTo(c[i+1])) > 0 then (
      d := ((b div c[i+1]) * (d)->max()) + b mod c[i+1] ;
    if (d->compareTo(ans)) > 0 then (
      ans := d
    ) else skip
    ) else skip ;
    d := 0) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
x,y=map(int,input().split())
l=list(map(int,input().split()))
an=y
mx=l[-1]
for i in range(x-2,-1,-1):
    mx=max(mx,l[i])
    an=max(an,y//l[i]*mx+y % l[i])
print(an)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var an : OclAny := y ;
    var mx : OclAny := l->last() ;
    for i : Integer.subrange(-1 + 1, x - 2)->reverse() do (    mx := Set{mx, l[i+1]}->max() ;
    an := Set{an, y div l[i+1] * mx + y mod l[i+1]}->max()) ;
    execute (an)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def modInverse(a,m):
    m0=m
    y=0
    x=1
    if(m==1):
        return 0
    while(a>1):
        q=a//m
        t=m
        m=a % m
        a=t
        t=y
        y=x-q*y
        x=t
    if(x<0):
        x=x+m0
    return x
a=3
m=11
print("Modular multiplicative inverse is",modInverse(a,m))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    a := 3 ;
    m := 11 ;
    execute ("Modular multiplicative inverse is")->display();
  operation modInverse(a : OclAny, m : OclAny) : OclAny
  pre: true post: true
  activity:
    var m0 : OclAny := m ;
    var y : int := 0 ;
    var x : int := 1 ;
    if (m = 1) then (
      return 0
    ) else skip ;
    while (a > 1) do (    var q : int := a div m ;
    var t : OclAny := m ;
    m := a mod m ;
    a := t ;
    t := y ;
    y := x - q * y ;
    x := t) ;
    if (x < 0) then (
      x := x + m0
    ) else skip ;
    return x;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def value(v):
    return v*(v-1)//2
n,m=map(int,input().split())
min_value=value(n//m)*m+(n % m)*(n//m)
max_value=value(n-m+1)
print(min_value,max_value)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var min_value : double := value(n div m) * m + (n mod m) * (n div m) ;
    var max_value : OclAny := value(n - m + 1) ;
    execute (min_value)->display();
  operation value(v : OclAny) : OclAny
  pre: true post: true
  activity:
    return v * (v - 1) div 2;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import comb
a,b=list(map(int,input().split()))
if b==1 :
    print((comb(a,2)),comb(a,2))
else :
    m=a-b
    mx=comb(m+1,2)
    p=a//b
    q=a % b
    mn=(b-q)*comb(p,2)+q*(comb(p+1,2))
    print(mn,mx)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if b = 1 then  (
      execute ((comb(a, 2)))->display()
    )
    else (
      var m : double := a - b ;
    var mx : OclAny := comb(m + 1, 2) ;
    var p : int := a div b ;
    var q : int := a mod b ;
    var mn : double := (b - q) * comb(p, 2) + q * (comb(p + 1, 2)) ;
    execute (mn)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
import os
import math
import itertools
A=[1,0,0]
for s in sys.stdin :
    s=s.strip()
    a,b=s.split(',')
    if a=='A' :
        i=0
    elif a=='B' :
        i=1
    elif a=='C' :
        i=2
    if b=='A' :
        j=0
    elif b=='B' :
        j=1
    elif b=='C' :
        j=2
    A[i],A[j]=A[j],A[i]
if A[0]==1 :
    print('A')
elif A[1]==1 :
    print('B')
else :
    print('C')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    var A : Sequence := Sequence{1}->union(Sequence{0}->union(Sequence{ 0 })) ;
    for s : OclFile["System.in"] do (    var s : String := s->trim() ;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := s.split(',') ;
    if a = 'A' then  (
      var i : int := 0
    )
    else (if a = 'B' then
   (
      i := 1    
)
    else (if a = 'C' then
   (
      i := 2    
)
    else skip    )
    )
 ;
    if b = 'A' then  (
      var j : int := 0
    )
    else (if b = 'B' then
   (
      j := 1    
)
    else (if b = 'C' then
   (
      j := 2    
)
    else skip    )
    )
 ;
    var A[i+1] : OclAny := null;
    var A[j+1] : OclAny := null;
    Sequence{A[i+1],A[j+1]} := Sequence{A[j+1],A[i+1]}) ;
    if A->first() = 1 then  (
      execute ('A')->display()
    )
    else (if A[1+1] = 1 then
   (
      execute ('B')->display()    
)
    else (
      execute ('C')->display()
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m=map(int,input().split())
s=n//m ; b=n % m ; a=m-b
ans_max=(n-m+1)*(n-m)//2
ans_min=a*s*(s-1)//2+b*s*(s+1)//2
print(ans_min,ans_max)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var s : int := n div m;    var b : int := n mod m;    var a : double := m - b ;
    var ans_max : int := (n - m + 1) * (n - m) div 2 ;
    var ans_min : int := a * s * (s - 1) div 2 + b * s * (s + 1) div 2 ;
    execute (ans_min)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m=map(int,input().split())
k=n-(m-1)
mx=k*(k-1)//2
a=n//m
b=n % m
mi=b*(a+1)*a//2+(m-b)*a*(a-1)//2
print(mi,mx)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var k : double := n - (m - 1) ;
    var mx : int := k * (k - 1) div 2 ;
    var a : int := n div m ;
    var b : int := n mod m ;
    var mi : int := b * (a + 1) * a div 2 + (m - b) * a * (a - 1) div 2 ;
    execute (mi)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=map(int,input().split())
hole=1
i=0
check=True
while check :
    if hole>=b :
        check=False
    else :
        hole=a*(i+1)-i
        i+=1
print(i)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var hole : int := 1 ;
    var i : int := 0 ;
    var check : boolean := true ;
    while check do (    if (hole->compareTo(b)) >= 0 then  (
      check := false
    )
    else (
      hole := a * (i + 1) - i ;
    i := i + 1
      )) ;
    execute (i)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
def countBits(number):
    return int((math.log(number)/math.log(2))+1);
num=65 ;
print(countBits(num));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var num : int := 65; ;
    execute (countBits(num))->display();;
  operation countBits(number : OclAny)
  pre: true post: true
  activity:
    return ("" + ((((number)->log() / (2)->log()) + 1)))->toInteger();;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def lowercaseAlphabets():
    for c in range(97,123):
        print(chr(c),end="");
    print("");
def uppercaseAlphabets():
    for c in range(65,91):
        print(chr(c),end="");
    print("");
print("Uppercase Alphabets");
uppercaseAlphabets();
print("Lowercase Alphabets ");
lowercaseAlphabets();
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    execute ("Uppercase Alphabets")->display(); ;
    uppercaseAlphabets(); ;
    execute ("Lowercase Alphabets ")->display(); ;
    lowercaseAlphabets();;
  operation lowercaseAlphabets()
  pre: true post: true
  activity:
    for c : Integer.subrange(97, 123-1) do (    execute ((c)->byte2char())->display();) ;
    execute ("")->display();;
  operation uppercaseAlphabets()
  pre: true post: true
  activity:
    for c : Integer.subrange(65, 91-1) do (    execute ((c)->byte2char())->display();) ;
    execute ("")->display();;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def hexadecagonalNum(n):
    return((14*n*n)-12*n)//2
n=5
print("%sth Hexadecagonal number : " % n,hexadecagonalNum(n))
n=9
print("%sth Hexadecagonal number : " % n,hexadecagonalNum(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    n := 5 ;
    execute (StringLib.format("%sth Hexadecagonal number : ",n))->display() ;
    n := 9 ;
    execute (StringLib.format("%sth Hexadecagonal number : ",n))->display();
  operation hexadecagonalNum(n : OclAny) : OclAny
  pre: true post: true
  activity:
    return ((14 * n * n) - 12 * n) div 2;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
cin=[['']for r in range(1002)]
dp=[[0 for c in range(1002)]for r in range(1002)]
while 1 :
    n=int(input())
    if n==0 : break
    for r in range(n): cin[r]=input()
    ans=0
    for r in range(n):
        for c in range(n):
            if cin[r][c]=='*' : dp[r][c]=0
            else :
                t=dp[r-1][c-1]
                if dp[r][c-1]ans : ans=t
    print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var cin : Sequence := Integer.subrange(0, 1002-1)->select(r | true)->collect(r | (Sequence{ '' })) ;
    var dp : Sequence := Integer.subrange(0, 1002-1)->select(r | true)->collect(r | (Integer.subrange(0, 1002-1)->select(c | true)->collect(c | (0)))) ;
    while 1 do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    for r : Integer.subrange(0, n-1) do (    cin[r+1] := (OclFile["System.in"]).readLine()) ;
    var ans : int := 0 ;
    for r : Integer.subrange(0, n-1) do (    for c : Integer.subrange(0, n-1) do (    if cin[r+1][c+1] = '*' then  (
      dp[r+1][c+1] := 0
    )
    else (
      var t : OclAny := dp[r - 1+1][c - 1+1] ;
    if (dp[r+1][c - 1+1]->compareTo(t)) < 0 then (
      t := dp[r+1][c - 1+1];
    ) else skip ;
    if (dp[r - 1+1][c+1]->compareTo(t)) < 0 then (
      t := dp[r - 1+1][c+1];
    ) else skip ;
    t := t + 1 ;
    dp[r+1][c+1] := t ;
    if (t->compareTo(ans)) > 0 then (
      ans := t
    ) else skip
      ))) ;
    execute (ans)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
readline=sys.stdin.readline
write=sys.stdout.write
def solve():
    N=int(readline())
    if N==0 :
        return False
    f=".*".index
    MP=[list(map(f,readline().strip()))for i in range(N)]
    D=[[0]*N for i in range(N)]
    ds=[0]*N
    for i in range(N):
        MPi=MP[i]
        Di=D[i]
        for j in range(N):
            if MPi[j]:
                ds[j]=0
            else :
                ds[j]+=1
                Di[j]=ds[j]
    ans=0
    def gen():
        for i in range(N):
            st=[]
            Di=D[i]
            for j in range(N):
                c=Di[j]
                last=j
                while st and st[-1][1]>=c :
                    k,d=st.pop()
                    yield min(d,j-k)
                    last=k
                st.append((last,c))
            while st :
                k,d=st.pop()
                yield min(d,N-k)
    write("%d\n" % max(gen()))
    return True
while solve():
   ...
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var readline : OclAny := (OclFile["System.in"]).readline ;
    var write : OclAny := (OclFile["System.out"]).write ;
    skip ;
    while solve() do ();
  operation solve() : OclAny
  pre: true post: true
  activity:
    var N : int := ("" + ((readline())))->toInteger() ;
    if N = 0 then (
      return false
    ) else skip ;
    var f : OclAny := ".*".index ;
    var MP : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((readline()->trim())->collect( _x | (f)->apply(_x) )))) ;
    var D : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, N))) ;
    var ds : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ;
    for i : Integer.subrange(0, N-1) do (    var MPi : OclAny := MP[i+1] ;
    var Di : OclAny := D[i+1] ;
    for j : Integer.subrange(0, N-1) do (    if MPi[j+1] then  (
      ds[j+1] := 0
    )
    else (
      ds[j+1] := ds[j+1] + 1 ;
    Di[j+1] := ds[j+1]
      ))) ;
    var ans : int := 0 ;
    skip ;
    write(StringLib.format("%d\n",(OclIterator.newOclIterator_Function(lambda _i : int in self.gen(_i)))->max())) ;
    return true;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from itertools import chain
while True :
    n=int(input())
    if not n :
        break
    dp=[[0]*(n+1)for _ in[0]*(n+1)]
    for y,(l_u,l_c)in enumerate(zip(dp,dp[1 :]),start=1):
        for x,(c,ul,u,left)in enumerate(zip(input(),l_u,l_u[1 :],l_c),start=1):
            dp[y][x]=min(ul,u,left)+1 if c=="." else 0
    print(max(chain.from_iterable(dp)))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    while true do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if not(n) then (
      break
    ) else skip ;
    var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1))->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)))) ;
    for _tuple : Integer.subrange(1, (Integer.subrange(1, dp->size())->collect( _indx | Sequence{dp->at(_indx), dp->tail()->at(_indx)} ), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(1, dp->size())->collect( _indx | Sequence{dp->at(_indx), dp->tail()->at(_indx)} ), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->at(_indx)} ) do (var _indx : int := 1;
      var y : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var Sequence{l_u, l_c} : OclAny := _tuple->at(_indx);
      for _tuple : Integer.subrange(1, (Integer.subrange(1, (OclFile["System.in"]).readLine()->size())->collect( _indx | Sequence{(OclFile["System.in"]).readLine()->at(_indx), l_u->at(_indx)} ), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(1, (OclFile["System.in"]).readLine()->size())->collect( _indx | Sequence{(OclFile["System.in"]).readLine()->at(_indx), l_u->at(_indx)} ), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->at(_indx)} ) do (var _indx : int := 1;
      var x : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var Sequence{c, ul, u, left} : OclAny := _tuple->at(_indx);
      dp[y+1][x+1] := if c = "." then Set{ul, u, left}->min() + 1 else 0 endif)) ;
    execute ((chain.from_iterable(dp))->max())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
while True :
    N=int(sys.stdin.readline().rstrip())
    if N==0 :
        break ;
    max_value=0
    prev_row=[0]*(N+1)
    for i in range(N):
        row=sys.stdin.readline().rstrip()
        curr_row=[0]*(N+1)
        for x,d in enumerate(row,1):
            if d=='.' :
                curr_row[x]=min(prev_row[x-1],prev_row[x],curr_row[x-1])+1
        max_value=max(max(curr_row),max_value)
        prev_row=curr_row
    print(max_value)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    while true do (    var N : int := ("" + ((sys.stdin.readLine().rstrip())))->toInteger() ;
    if N = 0 then (
      break;
    ) else skip ;
    var max_value : int := 0 ;
    var prev_row : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ;
    for i : Integer.subrange(0, N-1) do (    var row : OclAny := sys.stdin.readLine().rstrip() ;
    var curr_row : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ;
    for _tuple : Integer.subrange(1, (row, 1)->size())->collect( _indx | Sequence{_indx-1, (row, 1)->at(_indx)} ) do (var _indx : int := 1;
      var x : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var d : OclAny := _tuple->at(_indx);
      if d = '.' then (
      curr_row[x+1] := Set{prev_row[x - 1+1], prev_row[x+1], curr_row[x - 1+1]}->min() + 1
    ) else skip) ;
    max_value := Set{(curr_row)->max(), max_value}->max() ;
    prev_row := curr_row) ;
    execute (max_value)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def find_square(data):
    max_size=0
    lmap=[]
    for row in data :
        temp=[0]
        for c in row :
            if c=='.' :
                temp.append(1)
            else :
                temp.append(0)
        lmap.append(temp)
        temp=[0]
    prev_row=lmap[0]
    for curr_row in lmap[1 :]:
        for x in range(1,len(lmap[0])):
            if curr_row[x]==1 :
                if prev_row[x-1]!=0 and prev_row[x]!=0 and curr_row[x-1]!=0 :
                    curr_row[x]=min(prev_row[x-1],min(prev_row[x],curr_row[x-1]))+1
                    if curr_row[x]>max_size :
                        max_size=curr_row[x]
        prev_row=curr_row
    return max_size
def main(args):
    while True :
        n=int(input())
        if n==0 :
            break
        data=[input()for _ in range(n)]
        result=find_square(data)
        print(result)
if __name__=='__main__' :
    main(sys.argv[1 :])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))
    ) else skip;
  operation find_square(data : OclAny) : OclAny
  pre: true post: true
  activity:
    var max_size : int := 0 ;
    var lmap : Sequence := Sequence{} ;
    for row : data do (    var temp : Sequence := Sequence{ 0 } ;
    for c : row do (    if c = '.' then  (
      execute ((1) : temp)
    )
    else (
      execute ((0) : temp)
      )) ;
    execute ((temp) : lmap) ;
    temp := Sequence{ 0 }) ;
    var prev_row : OclAny := lmap->first() ;
    for curr_row : lmap->tail() do (    for x : Integer.subrange(1, (lmap->first())->size()-1) do (    if curr_row[x+1] = 1 then (
      if prev_row[x - 1+1] /= 0 & prev_row[x+1] /= 0 & curr_row[x - 1+1] /= 0 then (
      curr_row[x+1] := Set{prev_row[x - 1+1], Set{prev_row[x+1], curr_row[x - 1+1]}->min()}->min() + 1 ;
    if (curr_row[x+1]->compareTo(max_size)) > 0 then (
      max_size := curr_row[x+1]
    ) else skip
    ) else skip
    ) else skip) ;
    prev_row := curr_row) ;
    return max_size;
  operation main(args : OclAny)
  pre: true post: true
  activity:
    while true do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    data := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ;
    var result : OclAny := find_square(data) ;
    execute (result)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
c='ABC'
for e in sys.stdin : c=c.replace(e[0],'D').replace(e[2],e[0]).replace('D',e[2])
print(c[0])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var c : String := 'ABC' ;
    for e : OclFile["System.in"] do (    c := c.replace(e->first(), 'D').replace(e[2+1], e->first()).replace('D', e[2+1])) ;
    execute (c->first())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
if __name__=='__main__' :
    i=chr ;
    print("The Alphabets from A to Z are: ");
    for i in range(ord('A'),ord('Z')+1):
        print(chr(i),end=" ");
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     if __name__ = '__main__' then (
      var i : OclAny := chr; ;
    execute ("The Alphabets from A to Z are: ")->display(); ;
    for i : Integer.subrange(('A')->char2byte(), ('Z')->char2byte() + 1-1) do (    execute ((i)->byte2char())->display();)
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def possibleTripletInRange(L,R):
    flag=False ;
    possibleA=0 ;
    possibleB=0 ;
    possibleC=0 ;
    numbersInRange=(R-L+1);
    if(numbersInRange<3):
        flag=False ;
    elif(numbersInRange>3):
        flag=True ;
        if((L % 2)>0):
            L+=1 ;
        possibleA=L ;
        possibleB=L+1 ;
        possibleC=L+2 ;
    else :
        if((L % 2)==0):
            flag=True ;
            possibleA=L ;
            possibleB=L+1 ;
            possibleC=L+2 ;
        else :
            flag=False ;
    if(flag==True):
        print("(",possibleA,",",possibleB,",",possibleC,")is one such","possible triplet between",L,"and",R);
    else :
        print("No Such Triplet exists between",L,"and",R);
L=2 ;
R=10 ;
possibleTripletInRange(L,R);
L=23 ;
R=46 ;
possibleTripletInRange(L,R);
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    L := 2; ;
    R := 10; ;
    possibleTripletInRange(L, R); ;
    L := 23; ;
    R := 46; ;
    possibleTripletInRange(L, R);;
  operation possibleTripletInRange(L : OclAny, R : OclAny)
  pre: true post: true
  activity:
    var flag : boolean := false; ;
    var possibleA : int := 0; ;
    var possibleB : int := 0; ;
    var possibleC : int := 0; ;
    var numbersInRange : double := (R - L + 1); ;
    if (numbersInRange < 3) then  (
      flag := false;
    )
    else (if (numbersInRange > 3) then
   (
      flag := true; ;
    if ((L mod 2) > 0) then (
      L := L + 1;
    ) else skip ;
    possibleA := L; ;
    possibleB := L + 1; ;
    possibleC := L + 2;    
)
    else (
      if ((L mod 2) = 0) then  (
      flag := true; ;
    possibleA := L; ;
    possibleB := L + 1; ;
    possibleC := L + 2;
    )
    else (
      flag := false;
      )
      )    )
 ;
    if (flag = true) then  (
      execute ("(")->display();
    )
    else (
      execute ("No Such Triplet exists between")->display();
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def solve(a,b):
    length=len(a)
    half_length=length//2
    if(a==b):
        return True
    elif(len(a)% 2)==0 :
        a1=a[: half_length]
        a2=a[half_length :]
        b1=b[: half_length]
        b2=b[half_length :]
        return((solve(a1,b2)and solve(a2,b1))or(solve(a1,b1)and solve(a2,b2)))
    else :
        return False
a=input()
b=input()
if solve(a,b):
    print("YES")
else :
    print("NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    a := (OclFile["System.in"]).readLine() ;
    b := (OclFile["System.in"]).readLine() ;
    if solve(a, b) then  (
      execute ("YES")->display()
    )
    else (
      execute ("NO")->display()
      );
  operation solve(a : OclAny, b : OclAny) : OclAny
  pre: true post: true
  activity:
    var length : int := (a)->size() ;
    var half_length : int := length div 2 ;
    if (a = b) then  (
      return true
    )
    else (if ((a)->size() mod 2) = 0 then
   (
      var a1 : OclAny := a.subrange(1,half_length) ;
    var a2 : OclAny := a.subrange(half_length+1) ;
    var b1 : OclAny := b.subrange(1,half_length) ;
    var b2 : OclAny := b.subrange(half_length+1) ;
    return ((solve(a1, b2) & solve(a2, b1)) or (solve(a1, b1) & solve(a2, b2)))    
)
    else (
      return false
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def solve(s):
    if len(s)% 2 : return s
    a=solve(s[: len(s)//2])
    b=solve(s[len(s)//2 :])
    return a+b if adisplay();
  operation solve(s : OclAny) : OclAny
  pre: true post: true
  activity:
    if (s)->size() mod 2 then (
      return s
    ) else skip ;
    var a : OclAny := solve(s.subrange(1,(s)->size() div 2)) ;
    var b : OclAny := solve(s.subrange((s)->size() div 2+1)) ;
    return if (a->compareTo(b)) < 0 then a + b else b + a endif;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def verify(s):
    if(len(s)% 2!=0):
        return s ;
    s1=verify(s[0 : len(s)//2])
    s2=verify(s[len(s)//2 : len(s)])
    if(s1display()
    )
    else (
      execute ("NO")->display()
      );
  operation verify(s : OclAny)
  pre: true post: true
  activity:
    if ((s)->size() mod 2 /= 0) then (
      return s;
    ) else skip ;
    var s1 : OclAny := verify(s.subrange(0+1, (s)->size() div 2)) ;
    var s2 : OclAny := verify(s.subrange((s)->size() div 2+1, (s)->size())) ;
    if ((s1->compareTo(s2)) < 0) then  (
      return s1 + s2;
    )
    else (
      return s2 + s1;
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def checa(string):
    if len(string)% 2 :
        return string
    a=checa(string[: len(string)//2])
    b=checa(string[len(string)//2 :])
    if(adisplay()
    )
    else (
      execute ('NO')->display()
      )
    ) else skip;
  operation checa(string : OclAny) : OclAny
  pre: true post: true
  activity:
    if (string)->size() mod 2 then (
      return string
    ) else skip ;
    var a : OclAny := checa(string.subrange(1,(string)->size() div 2)) ;
    var b : OclAny := checa(string.subrange((string)->size() div 2+1)) ;
    if ((a->compareTo(b)) < 0) then  (
      return a + b
    )
    else (
      return b + a
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def divideOrdena(string):
    if len(string)% 2 :
        return string
    a=divideOrdena(string[: len(string)//2])
    b=divideOrdena(string[len(string)//2 :])
    if(adisplay()
    )
    else (
      execute ('NO')->display()
      )
    ) else skip;
  operation divideOrdena(string : OclAny) : OclAny
  pre: true post: true
  activity:
    if (string)->size() mod 2 then (
      return string
    ) else skip ;
    var a : OclAny := divideOrdena(string.subrange(1,(string)->size() div 2)) ;
    var b : OclAny := divideOrdena(string.subrange((string)->size() div 2+1)) ;
    if ((a->compareTo(b)) < 0) then  (
      return a + b
    )
    else (
      return b + a
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def substring(s,a,b):
    s1=""
    for i in range(a,b,1):
        s1+=s[i]
    return s1
def allPalindromeSubstring(s):
    v=[]
    pivot=0.0
    while pivot=0 and(s[int(pivot-palindromeRadius)]==s[int(pivot+palindromeRadius)])):
            v.append(s[int(pivot-palindromeRadius): int(pivot+palindromeRadius+1)])
            palindromeRadius+=1
        pivot+=0.5
    return v
if __name__=="__main__" :
    v=allPalindromeSubstring("hellolle")
    print(len(v))
    print(v)
    v=allPalindromeSubstring("geeksforgeeks")
    print(len(v))
    print(v)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      v := allPalindromeSubstring("hellolle") ;
    execute ((v)->size())->display() ;
    execute (v)->display() ;
    v := allPalindromeSubstring("geeksforgeeks") ;
    execute ((v)->size())->display() ;
    execute (v)->display()
    ) else skip;
  operation substring(s : OclAny, a : OclAny, b : OclAny) : OclAny
  pre: true post: true
  activity:
    var s1 : String := "" ;
    for i : Integer.subrange(a, b-1)->select( $x | ($x - a) mod 1 = 0 ) do (    s1 := s1 + s[i+1]) ;
    return s1;
  operation allPalindromeSubstring(s : OclAny) : OclAny
  pre: true post: true
  activity:
    var v : Sequence := Sequence{} ;
    var pivot : double := 0.0 ;
    while (pivot->compareTo((s)->size())) < 0 do (    var palindromeRadius : double := pivot - ("" + ((pivot)))->toInteger() ;
    while (((pivot + palindromeRadius)->compareTo((s)->size())) < 0 & (pivot - palindromeRadius) >= 0 & (s[("" + ((pivot - palindromeRadius)))->toInteger()+1] = s[("" + ((pivot + palindromeRadius)))->toInteger()+1])) do (    execute ((s.subrange(("" + ((pivot - palindromeRadius)))->toInteger()+1, ("" + ((pivot + palindromeRadius + 1)))->toInteger())) : v) ;
    palindromeRadius := palindromeRadius + 1) ;
    pivot := pivot + 0.5) ;
    return v;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def decimalToBinary(num,k_prec):
    binary=""
    Integral=int(num)
    fractional=num-Integral
    while(Integral):
        rem=Integral % 2
        binary+=str(rem);
        Integral//=2
    binary=binary[: :-1]
    binary+='.'
    while(k_prec):
        fractional*=2
        fract_bit=int(fractional)
        if(fract_bit==1):
            fractional-=fract_bit
            binary+='1'
        else :
            binary+='0'
        k_prec-=1
    return binary
if __name__=="__main__" :
    n=4.47
    k=3
    print(decimalToBinary(n,k))
    n=6.986
    k=5
    print(decimalToBinary(n,k))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      var n : double := 4.47 ;
    var k : int := 3 ;
    execute (decimalToBinary(n, k))->display() ;
    n := 6.986 ;
    k := 5 ;
    execute (decimalToBinary(n, k))->display()
    ) else skip;
  operation decimalToBinary(num : OclAny, k_prec : OclAny) : OclAny
  pre: true post: true
  activity:
    var binary : String := "" ;
    var Integral : int := ("" + ((num)))->toInteger() ;
    var fractional : double := num - Integral ;
    while (Integral) do (    var rem : int := Integral mod 2 ;
    binary := binary + ("" + ((rem))); ;
    Integral := Integral div 2) ;
    binary := binary(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ;
    binary := binary + '.' ;
    while (k_prec) do (    fractional := fractional * 2 ;
    var fract_bit : int := ("" + ((fractional)))->toInteger() ;
    if (fract_bit = 1) then  (
      fractional := fractional - fract_bit ;
    binary := binary + '1'
    )
    else (
      binary := binary + '0'
      ) ;
    k_prec := k_prec - 1) ;
    return binary;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
ax=5
ay=0
bx=1
by=1
cx=2
cy=5
print(ax+bx-cx,",",ay+by-cy)
print(ax+cx-bx,",",ay+cy-by)
print(cx+bx-ax,",",cy+by-ax)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var ax : int := 5 ;
    var ay : int := 0 ;
    var bx : int := 1 ;
    var by : int := 1 ;
    var cx : int := 2 ;
    var cy : int := 5 ;
    execute (ax + bx - cx)->display() ;
    execute (ax + cx - bx)->display() ;
    execute (cx + bx - ax)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
z,x=input(),input()
zctr,xctr=0,0
for i in range(0,len(z),2):
    if(z[i]=='(' and x[i]=='8')or(z[i]=='[' and x[i]=='(')or(z[i]=='8' and x[i]=='['):
        zctr+=1
    else :
        if z[i]!=x[i]:
            xctr+=1
print('TIE' if zctr==xctr else 'TEAM '+str(int(xctr>zctr)+1)+' WINS')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var z : OclAny := null;
    var x : OclAny := null;
    Sequence{z,x} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine()} ;
    var zctr : OclAny := null;
    var xctr : OclAny := null;
    Sequence{zctr,xctr} := Sequence{0,0} ;
    for i : Integer.subrange(0, (z)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do (    if (z[i+1] = '(' & x[i+1] = '8') or (z[i+1] = '[' & x[i+1] = '(') or (z[i+1] = '8' & x[i+1] = '[') then  (
      zctr := zctr + 1
    )
    else (
      if z[i+1] /= x[i+1] then (
      xctr := xctr + 1
    ) else skip
      )) ;
    execute (if zctr = xctr then 'TIE' else 'TEAM ' + ("" + ((("" + (((xctr->compareTo(zctr)) > 0)))->toInteger() + 1))) + ' WINS' endif)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def summ(n):
    if(n==0):
        return 0 ;
    if(n % 9==0):
        return 9 ;
    else :
        return(n % 9);
def printDigitalRoot(n):
    maxi=1 ;
    dig=1 ;
    for i in range(1,int(pow(n,1/2)+1)):
        if(n % i==0):
            d1=summ(n/i);
            d2=summ(i);
            if(d1>maxi):
                dig=n/i ;
                maxi=d1 ;
            if(d2>maxi):
                dig=i ;
                maxi=d2 ;
            if(d1==maxi):
                if(dig<(n/i)):
                    dig=n/i ;
                    maxi=d1 ;
            if(d2==maxi):
                if(digpow(1 / 2) + 1)))->toInteger()-1) do (    if (n mod i = 0) then (
      var d1 : OclAny := summ(n / i); ;
    var d2 : OclAny := summ(i); ;
    if ((d1->compareTo(maxi)) > 0) then (
      dig := n / i; ;
    maxi := d1;
    ) else skip ;
    if ((d2->compareTo(maxi)) > 0) then (
      dig := i; ;
    maxi := d2;
    ) else skip ;
    if (d1 = maxi) then (
      if ((dig->compareTo((n / i))) < 0) then (
      dig := n / i; ;
    maxi := d1;
    ) else skip
    ) else skip ;
    if (d2 = maxi) then (
      if ((dig->compareTo(i)) < 0) then (
      dig := i; ;
    maxi := d2;
    ) else skip
    ) else skip
    ) else skip) ;
    execute (("" + ((dig)))->toInteger())->display();;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def conversion(charSet,str1):
    s2=""
    for i in str1 :
        s2+=alphabets[charSet.index(i)]
    return s2
if __name__=='__main__' :
    alphabets="abcdefghijklmnopqrstuvwxyz"
    charSet="qwertyuiopasdfghjklzxcvbnm"
    str1="egrt"
    print(conversion(charSet,str1))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      var alphabets : String := "abcdefghijklmnopqrstuvwxyz" ;
    charSet := "qwertyuiopasdfghjklzxcvbnm" ;
    str1 := "egrt" ;
    execute (conversion(charSet, str1))->display()
    ) else skip;
  operation conversion(charSet : OclAny, str1 : OclAny) : OclAny
  pre: true post: true
  activity:
    var s2 : String := "" ;
    for i : str1 do (    s2 := s2 + alphabets[charSet->indexOf(i) - 1+1]) ;
    return s2;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s1=input()
s2=input()
num1=0
num2=0
for i in range(0,len(s1),2):
    c1=s1[i : i+2]
    c2=s2[i : i+2]
    if c1!=c2 :
        if(c1=="8<" and c2=="[]"):
            num1+=1
        elif(c1=="()" and c2=="8<"):
            num1+=1
        elif(c1=="[]" and c2=="()"):
            num1+=1
        else :
            num2+=1
if num1==num2 :
    print("TIE")
else :
    print("TEAM{}WINS".format(int(num2>num1)+1))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s1 : String := (OclFile["System.in"]).readLine() ;
    var s2 : String := (OclFile["System.in"]).readLine() ;
    var num1 : int := 0 ;
    var num2 : int := 0 ;
    for i : Integer.subrange(0, (s1)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do (    var c1 : OclAny := s1.subrange(i+1, i + 2) ;
    var c2 : OclAny := s2.subrange(i+1, i + 2) ;
    if c1 /= c2 then (
      if (c1 = "8<" & c2 = "[]") then  (
      num1 := num1 + 1
    )
    else (if (c1 = "()" & c2 = "8<") then
   (
      num1 := num1 + 1    
)
    else (if (c1 = "[]" & c2 = "()") then
   (
      num1 := num1 + 1    
)
    else (
      num2 := num2 + 1
      )    )
    )
    ) else skip) ;
    if num1 = num2 then  (
      execute ("TIE")->display()
    )
    else (
      execute (StringLib.interpolateStrings("TEAM{}WINS", Sequence{("" + (((num2->compareTo(num1)) > 0)))->toInteger() + 1}))->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=input()
b=input()
ans1=0
ans2=0
for i in range(0,len(a),2):
    x=a[i]+a[i+1]
    y=b[i]+b[i+1]
    if x==y :
        ans1+=0
    elif x=='[]' and y=='()' :
        ans1+=1
    elif x=='()' and y=='[]' :
        ans2+=1
    elif x=="()" and y=="8<" :
        ans1+=1
    elif x=="8<" and y=="()" :
        ans2+=1
    elif x=="[]" and y=="8<" :
        ans2+=1
    elif x=="8<" and y=="[]" :
        ans1+=1
if ans1>ans2 :
    print("TEAM 1 WINS")
elif ans2>ans1 :
    print("TEAM 2 WINS")
else :
    print("TIE")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : String := (OclFile["System.in"]).readLine() ;
    var b : String := (OclFile["System.in"]).readLine() ;
    var ans1 : int := 0 ;
    var ans2 : int := 0 ;
    for i : Integer.subrange(0, (a)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do (    var x : OclAny := a[i+1] + a[i + 1+1] ;
    var y : OclAny := b[i+1] + b[i + 1+1] ;
    if x = y then  (
      ans1 := ans1 + 0
    )
    else (if x = '[]' & y = '()' then
   (
      ans1 := ans1 + 1    
)
    else (if x = '()' & y = '[]' then
   (
      ans2 := ans2 + 1    
)
    else (if x = "()" & y = "8<" then
   (
      ans1 := ans1 + 1    
)
    else (if x = "8<" & y = "()" then
   (
      ans2 := ans2 + 1    
)
    else (if x = "[]" & y = "8<" then
   (
      ans2 := ans2 + 1    
)
    else (if x = "8<" & y = "[]" then
   (
      ans1 := ans1 + 1    
)
    else skip    )
    )
    )
    )
    )
    )
) ;
    if (ans1->compareTo(ans2)) > 0 then  (
      execute ("TEAM 1 WINS")->display()
    )
    else (if (ans2->compareTo(ans1)) > 0 then
   (
      execute ("TEAM 2 WINS")->display()    
)
    else (
      execute ("TIE")->display()
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=input()
b=input()
a=a[: : 2]
b=b[: : 2]
aa=0
bb=0
for i in range(len(a)):
    if a[i]=="[" and b[i]=="(" or a[i]=="(" and b[i]=="8" or a[i]=="8" and b[i]=="[" :
        aa+=1
    elif b[i]=="[" and a[i]=="(" or b[i]=="(" and a[i]=="8" or b[i]=="8" and a[i]=="[" :
        bb+=1
if aa>bb :
    print("TEAM 1 WINS")
elif aasize()-1) do (    if a[i+1] = "[" & b[i+1] = "(" or a[i+1] = "(" & b[i+1] = "8" or a[i+1] = "8" & b[i+1] = "[" then  (
      aa := aa + 1
    )
    else (if b[i+1] = "[" & a[i+1] = "(" or b[i+1] = "(" & a[i+1] = "8" or b[i+1] = "8" & a[i+1] = "[" then
   (
      bb := bb + 1    
)
 else skip)) ;
    if (aa->compareTo(bb)) > 0 then  (
      execute ("TEAM 1 WINS")->display()
    )
    else (if (aa->compareTo(bb)) < 0 then
   (
      execute ("TEAM 2 WINS")->display()    
)
    else (
      execute ("TIE")->display()
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=input()
b=input()
s1=0
s2=0
for i in range(0,len(a),2):
    if a[i]=='[' :
        if b[i]=='8' :
            s2+=1
        elif b[i]=='(' :
            s1+=1
    if a[i]=='(' :
        if b[i]=='8' :
            s1+=1
        elif b[i]=='[' :
            s2+=1
    if a[i]=='8' :
        if b[i]=='[' :
            s1+=1
        elif b[i]=='(' :
            s2+=1
if s1>s2 :
    print('TEAM 1 WINS')
elif s2>s1 :
    print('TEAM 2 WINS')
else :
    print('TIE')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : String := (OclFile["System.in"]).readLine() ;
    var b : String := (OclFile["System.in"]).readLine() ;
    var s1 : int := 0 ;
    var s2 : int := 0 ;
    for i : Integer.subrange(0, (a)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do (    if a[i+1] = '[' then (
      if b[i+1] = '8' then  (
      s2 := s2 + 1
    )
    else (if b[i+1] = '(' then
   (
      s1 := s1 + 1    
)
 else skip)
    ) else skip ;
    if a[i+1] = '(' then (
      if b[i+1] = '8' then  (
      s1 := s1 + 1
    )
    else (if b[i+1] = '[' then
   (
      s2 := s2 + 1    
)
 else skip)
    ) else skip ;
    if a[i+1] = '8' then (
      if b[i+1] = '[' then  (
      s1 := s1 + 1
    )
    else (if b[i+1] = '(' then
   (
      s2 := s2 + 1    
)
 else skip)
    ) else skip) ;
    if (s1->compareTo(s2)) > 0 then  (
      execute ('TEAM 1 WINS')->display()
    )
    else (if (s2->compareTo(s1)) > 0 then
   (
      execute ('TEAM 2 WINS')->display()    
)
    else (
      execute ('TIE')->display()
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def maxElement(a,n):
    if n<3 :
        return-1
    maxElement=a[0]
    maxProd=a[n-1]*a[1]
    for i in range(1,n):
        currprod=a[i-1]*a[(i+1)% n]
        if currprod>maxProd :
            maxProd=currprod
            maxElement=a[i]
        elif currprod==maxProd :
            maxElement=max(maxElement,a[i])
    return maxElement
a=[5,6,4,3,2]
n=len(a)
print(maxElement(a,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    a := Sequence{5}->union(Sequence{6}->union(Sequence{4}->union(Sequence{3}->union(Sequence{ 2 })))) ;
    n := (a)->size() ;
    execute (maxElement(a, n))->display();
  operation maxElement(a : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    if n < 3 then (
      return -1
    ) else skip ;
    var maxElement : OclAny := a->first() ;
    var maxProd : double := a[n - 1+1] * a[1+1] ;
    for i : Integer.subrange(1, n-1) do (    var currprod : double := a[i - 1+1] * a[(i + 1) mod n+1] ;
    if (currprod->compareTo(maxProd)) > 0 then  (
      maxProd := currprod ;
    maxElement := a[i+1]
    )
    else (if currprod = maxProd then
   (
      maxElement := Set{maxElement, a[i+1]}->max()    
)
 else skip)) ;
    return maxElement;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N,M=map(int,input().split())
L=[[]for i in range(N)]
ans=[]
for i in range(M):
    info,num=map(int,input().split())
    if info==1 :
        x=0
        for j in range(1,N):
            if len(L[j])collect( _x | (OclType["int"])->apply(_x) ) ;
    var L : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{})) ;
    var ans : Sequence := Sequence{} ;
    for i : Integer.subrange(0, M-1) do (    var info : OclAny := null;
    var num : OclAny := null;
    Sequence{info,num} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if info = 1 then  (
      var x : int := 0 ;
    for j : Integer.subrange(1, N-1) do (    if ((L[j+1])->size()->compareTo((L[x+1])->size())) < 0 then (
      x := j
    ) else skip) ;
(expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) ))))
    )
    else (
      execute ((L[num - 1+1]->first()) : ans) ;
    execute (L[num - 1+1]->first())->isDeleted()
      )) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import deque
N,M=map(int,input().split())
lanes=[deque()for i in range(N+1)]
for i in range(M):
    info=list(map(int,input().split()))
    if info[0]==0 :
        print(lanes[info[1]].popleft())
    else :
        lane=-1
        count=10001
        for j in range(1,N+1):
            if len(lanes[j])collect( _x | (OclType["int"])->apply(_x) ) ;
    var lanes : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (())) ;
    for i : Integer.subrange(0, M-1) do (    var info : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if info->first() = 0 then  (
      execute (lanes[info[1+1]+1]->first())->display()
    )
    else (
      var lane : int := -1 ;
    var count : int := 10001 ;
    for j : Integer.subrange(1, N + 1-1) do (    if ((lanes[j+1])->size()->compareTo(count)) < 0 then (
      lane := j ;
    count := (lanes[j+1])->size()
    ) else skip) ;
(expr (atom (name lanes)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name lane)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name info)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ))))
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush,heappop
import copy
BIG_NUM=2000000000
MOD=1000000007
EPS=0.000000001
num_lane,num_info=map(int,input().split())
Q=[]
for _ in range(num_lane):
    Q.append(deque())
for _ in range(num_info):
    command,value=map(int,input().split())
    if command==0 :
        value-=1
        print("%d" %(Q[value].popleft()))
    else :
        min_car=BIG_NUM
        min_lane=BIG_NUM
        for i in range(num_lane):
            if len(Q[i])collect( _x | (OclType["int"])->apply(_x) ) ;
    var Q : Sequence := Sequence{} ;
    for _anon : Integer.subrange(0, num_lane-1) do (    execute ((()) : Q)) ;
    for _anon : Integer.subrange(0, num_info-1) do (    var command : OclAny := null;
    var value : OclAny := null;
    Sequence{command,value} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if command = 0 then  (
      value := value - 1 ;
    execute (StringLib.format("%d",(Q[value+1]->first())))->display()
    )
    else (
      var min_car : int := BIG_NUM ;
    var min_lane : int := BIG_NUM ;
    for i : Integer.subrange(0, num_lane-1) do (    if ((Q[i+1])->size()->compareTo(min_car)) < 0 then (
      min_car := (Q[i+1])->size() ;
    min_lane := i
    ) else skip) ;
(expr (atom (name Q)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name min_lane)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name value)))))))) ))))
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m=(int(x)for x in input().split())
rane=[[]for i in range(n)]
def getRane():
    index=0
    min=9999
    for i in range(0,n):
        if min>len(rane[i]):
            min=len(rane[i])
            if min==0 :
                return i
            index=i
    return index
for i in range(0,m):
    c,num=(int(x)for x in input().split())
    if c==0 :
        num-=1
        print(rane[num][0])
        rane[num].pop(0)
    else :
        index=getRane()
        rane[index].append(num)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ;
    var rane : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ;
    skip ;
    for i : Integer.subrange(0, m-1) do (    var c : OclAny := null;
    var num : OclAny := null;
    Sequence{c,num} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ;
    if c = 0 then  (
      num := num - 1 ;
    execute (rane[num+1]->first())->display() ;
(expr (atom (name rane)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name num)))))))) ])) (trailer . (name pop) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))))
    )
    else (
      index := getRane() ;
(expr (atom (name rane)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name index)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) ))))
      ));
  operation getRane() : OclAny
  pre: true post: true
  activity:
    var index : int := 0 ;
    var min : int := 9999 ;
    for i : Integer.subrange(0, n-1) do (    if (min->compareTo((rane[i+1])->size())) > 0 then (
      min := (rane[i+1])->size() ;
    if min = 0 then (
      return i
    ) else skip ;
    index := i
    ) else skip) ;
    return index;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N,M=[int(i)for i in input().split()]
table=[[]for i in range(N)]
for l in range(M):
    command,num=[int(i)for i in input().split()]
    if command==0 :
        print(table[num-1].pop(0))
    else :
        minSize=10000
        minId=-1
        for i in range(N):
            if len(table[i])select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var table : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{})) ;
    for l : Integer.subrange(0, M-1) do (    var command : OclAny := null;
    var num : OclAny := null;
    Sequence{command,num} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    if command = 0 then  (
      execute (table[num - 1+1]->at(0`firstArg+1))->display()
    )
    else (
      var minSize : int := 10000 ;
    var minId : int := -1 ;
    for i : Integer.subrange(0, N-1) do (    if ((table[i+1])->size()->compareTo(minSize)) < 0 then (
      minSize := (table[i+1])->size() ;
    minId := i
    ) else skip) ;
(expr (atom (name table)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name minId)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) ))))
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s=set()
def generateNumber(count,a,n,num,k):
    if k==count :
        s.add(num)
        return
    for i in range(0,n):
        generateNumber(count+1,a,n,num+a[i],k)
def printDistinctIntegers(k,a,n):
    generateNumber(0,a,n,0,k)
    print("The",len(s),"distinct integers are:")
    for i in sorted(s):
        print(i,end=" ")
if __name__=="__main__" :
    a=[3,8,17,5]
    n,k=len(a),2
    printDistinctIntegers(k,a,n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : Set := Set{}->union(()) ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      a := Sequence{3}->union(Sequence{8}->union(Sequence{17}->union(Sequence{ 5 }))) ;
    Sequence{n,k} := Sequence{(a)->size(),2} ;
    printDistinctIntegers(k, a, n)
    ) else skip;
  operation generateNumber(count : OclAny, a : OclAny, n : OclAny, num : OclAny, k : OclAny)
  pre: true post: true
  activity:
    if k = count then (
      execute ((num) : s) ;
    return
    ) else skip ;
    for i : Integer.subrange(0, n-1) do (    generateNumber(count + 1, a, n, num + a[i+1], k));
  operation printDistinctIntegers(k : OclAny, a : OclAny, n : OclAny)
  pre: true post: true
  activity:
    generateNumber(0, a, n, 0, k) ;
    execute ("The")->display() ;
    for i : s->sort() do (    execute (i)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def f(x):
    x+=1
    while(x % 10==0):
        x//=10
    return x
a=set()
n=int(input())
while(n not in a):
    a.add(n)
    n=f(n)
print(len(a))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var a : Set := Set{}->union(()) ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    while ((a)->excludes(n)) do (    execute ((n) : a) ;
    n := f(n)) ;
    execute ((a)->size())->display();
  operation f(x : OclAny) : OclAny
  pre: true post: true
  activity:
    x := x + 1 ;
    while (x mod 10 = 0) do (    x := x div 10) ;
    return x;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def find_extra_element_index(arrA,arrB):
    extra_element=sum(arrA)-sum(arrB)
    return arrA.index(extra_element)
arrA=[2,4,6,8,10,12,13]
arrB=[2,4,6,8,10,12]
print(find_extra_element_index(arrA,arrB))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    arrA := Sequence{2}->union(Sequence{4}->union(Sequence{6}->union(Sequence{8}->union(Sequence{10}->union(Sequence{12}->union(Sequence{ 13 })))))) ;
    arrB := Sequence{2}->union(Sequence{4}->union(Sequence{6}->union(Sequence{8}->union(Sequence{10}->union(Sequence{ 12 }))))) ;
    execute (find_extra_element_index(arrA, arrB))->display();
  operation find_extra_element_index(arrA : OclAny, arrB : OclAny) : OclAny
  pre: true post: true
  activity:
    var extra_element : double := (arrA)->sum() - (arrB)->sum() ;
    return arrA->indexOf(extra_element) - 1;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
l=list(map(int,input().split()))
l1=[]
for j in range(n):
    tot=0
    i=j-1
    while i>-2 :
        i+=1
        tot+=l[i]
        if tot>=180 :
            if(abs(180-tot))>(abs(180-(tot-l[i]))):
                tot-=l[i]
            break
        if i==n-1 :
            i=-1
    l1.append(abs(180-tot))
final=min(l1)
print(2*final)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var l1 : Sequence := Sequence{} ;
    for j : Integer.subrange(0, n-1) do (    var tot : int := 0 ;
    var i : double := j - 1 ;
    while i > -2 do (    i := i + 1 ;
    tot := tot + l[i+1] ;
    if tot >= 180 then (
      if (((180 - tot)->abs())->compareTo(((180 - (tot - l[i+1]))->abs()))) > 0 then (
      tot := tot - l[i+1]
    ) else skip ;
    break
    ) else skip ;
    if i = n - 1 then (
      i := -1
    ) else skip) ;
    execute (((180 - tot)->abs()) : l1)) ;
    var final : OclAny := (l1)->min() ;
    execute (2 * final)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
arr=list(map(int,input().split()))
ps=[0]
for i in arr :
    ps.append(ps[-1]+i)
ans=360
for i in range(n):
    for j in range(i,n):
        s=ps[j+1]-ps[i]
        ans=min(ans,abs((360-s)-s))
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var ps : Sequence := Sequence{ 0 } ;
    for i : arr do (    execute ((ps->last() + i) : ps)) ;
    var ans : int := 360 ;
    for i : Integer.subrange(0, n-1) do (    for j : Integer.subrange(i, n-1) do (    var s : double := ps[j + 1+1] - ps[i+1] ;
    ans := Set{ans, ((360 - s) - s)->abs()}->min())) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
n=int(input())
w=list(map(int,input().split()))
c=1e9
x=sum(w)
k=n
while k :
    s=0
    for i in w :
        s+=i
        c=min(c,abs(x-2*s))
    k-=1
    w=w[1 :]+[w[0]]
print(c)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var c : double := ("1e9")->toReal() ;
    var x : OclAny := (w)->sum() ;
    var k : int := n ;
    while k do (    var s : int := 0 ;
    for i : w do (    s := s + i ;
    c := Set{c, (x - 2 * s)->abs()}->min()) ;
    k := k - 1 ;
    w := w->tail()->union(Sequence{ w->first() })) ;
    execute (c)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
l=[*map(int,input().split())]
k=[]
for i in range(n):
    for j in range(i,n):
        k.append(abs(sum(l[i : j])*2-360))
print(min(k))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var l : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var k : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    for j : Integer.subrange(i, n-1) do (    execute ((((l.subrange(i+1, j))->sum() * 2 - 360)->abs()) : k))) ;
    execute ((k)->min())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input()); s=[*map(int,input().split())]; print(min([*(abs(2*sum(s[x : y])-360)for x in range(n)for y in range(x,n))]))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger();    var s : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) );    execute ((Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (number (integer 2)))) * (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))) : (test (logical_test (comparison (expr (atom (name y)))))))) ])))))))) ))))) - (expr (atom (number (integer 360)))))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))))})->min())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=input().split()
A=a*int(b)
B=b*int(a)
if AtoInteger() ;
    var B : double := b * ("" + ((a)))->toInteger() ;
    if (A->compareTo(B)) < 0 then  (
      execute (A)->display()
    )
    else (
      execute (B)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from __future__ import print_function
import sys
import re
import array
import copy
import functools
import operator
import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
import collections
import itertools
import bisect
import random
import time
import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue
from itertools import accumulate
from collections import deque
from collections import Counter
from operator import mul
from functools import reduce
input=sys.stdin.readline
def eprint(*args,**kwargs):
    print(*args,file=sys.stderr,**kwargs)
    return
def lcm(n,m):
    return int(n*m/gcd(n,m))
def coprimize(p,q):
    common=fractions.gcd(p,q)
    return(p//common,q//common)
def combinations_count(n,r):
    r=min(r,n-r)
    numer=reduce(mul,range(n,n-r,-1),1)
    denom=reduce(mul,range(1,r+1),1)
    return numer//denom
def main():
    a,b=map(int,input().strip().split())
    print(str(a)*b if adisplay() ;
    return;
  operation lcm(n : OclAny, m : OclAny) : OclAny
  pre: true post: true
  activity:
    return ("" + ((n * m / gcd(n, m))))->toInteger();
  operation coprimize(p : OclAny, q : OclAny) : OclAny
  pre: true post: true
  activity:
    var common : int := fractions.gcd(p, q) ;
    return Sequence{p div common, q div common};
  operation combinations_count(n : OclAny, r : OclAny) : OclAny
  pre: true post: true
  activity:
    r := Set{r, n - r}->min() ;
    var numer : OclAny := reduce(mul, Integer.subrange(n - r + 1, n)->reverse(), 1) ;
    var denom : OclAny := reduce(mul, Integer.subrange(1, r + 1-1), 1) ;
    return numer div denom;
  operation main()
  pre: true post: true
  activity:
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (if (a->compareTo(b)) < 0 then ("" + ((a))) * b else ("" + ((b))) * a endif)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=list(map(int,input().split()))
p=str(a)
q=str(b)
ans=""
if(a==b):
    for i in range(a):
        ans+=p
elif(a>b):
    for i in range(a):
        ans+=q
elif(acollect( _x | (OclType["int"])->apply(_x) )) ;
    var p : String := ("" + ((a))) ;
    var q : String := ("" + ((b))) ;
    var ans : String := "" ;
    if (a = b) then  (
      for i : Integer.subrange(0, a-1) do (    ans := ans + p)
    )
    else (if ((a->compareTo(b)) > 0) then
   (
      for i : Integer.subrange(0, a-1) do (    ans := ans + q)    
)
    else (if ((a->compareTo(b)) < 0) then
   (
      for i : Integer.subrange(0, b-1) do (    ans := ans + p)    
)
    else skip    )
    )
 ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def product(x):
    prod=1
    while(x):
        prod*=(x % 10)
        x//=10 ;
    return prod
def findNumber(l,r):
    a=str(l);
    b=str(r);
    ans=r
    for i in range(len(b)):
        if(b[i]=='0'):
            continue
        curr=list(b)
        curr[i]=str(((ord(curr[i])-ord('0'))-1)+ord('0'))
        for j in range(i+1,len(curr)):
            curr[j]=str(ord('9'))
        num=0
        for c in curr :
            num=num*10+(int(c)-ord('0'))
        if(num>=l and product(ans)display() ;
    Sequence{l,r} := Sequence{51,62} ;
    execute (findNumber(l, r))->display()
    ) else skip;
  operation product(x : OclAny) : OclAny
  pre: true post: true
  activity:
    var prod : int := 1 ;
    while (x) do (    prod := prod * (x mod 10) ;
    x := x div 10;) ;
    return prod;
  operation findNumber(l : OclAny, r : OclAny) : OclAny
  pre: true post: true
  activity:
    var a : String := ("" + ((l))); ;
    var b : String := ("" + ((r))); ;
    var ans : OclAny := r ;
    for i : Integer.subrange(0, (b)->size()-1) do (    if (b[i+1] = '0') then (
      continue
    ) else skip ;
    var curr : Sequence := (b)->characters() ;
    curr[i+1] := ("" + (((((curr[i+1])->char2byte() - ('0')->char2byte()) - 1) + ('0')->char2byte()))) ;
    for j : Integer.subrange(i + 1, (curr)->size()-1) do (    curr[j+1] := ("" + ((('9')->char2byte())))) ;
    var num : int := 0 ;
    for c : curr do (    num := num * 10 + (("" + ((c)))->toInteger() - ('0')->char2byte())) ;
    if ((num->compareTo(l)) >= 0 & (product(ans)->compareTo(product(num))) < 0) then (
      ans := num
    ) else skip) ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=[int(s)for s in input().strip().split()]
result=min(str(a)*b,str(b)*a)
print(result)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := input()->trim().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ;
    var result : OclAny := Set{("" + ((a))) * b, ("" + ((b))) * a}->min() ;
    execute (result)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
iim=lambda : map(int,input().rstrip().split())
def resolve():
    a,b=iim()
    if a>b :
        a,b=b,a
    print("{0}".format(a)*b)
if __name__=="__main__" :
    resolve()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var iim : Function := lambda $$ : OclAny in ((input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    skip ;
    if __name__ = "__main__" then (
      resolve()
    ) else skip;
  operation resolve()
  pre: true post: true
  activity:
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := iim->apply() ;
    if (a->compareTo(b)) > 0 then (
      var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := Sequence{b,a}
    ) else skip ;
    execute (StringLib.interpolateStrings("{0}", Sequence{a}) * b)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
start,target,diff=map(int,input().split())
if start==target :
    print('YES')
    exit()
if diff==0 :
    print('YES')if target==start else print('NO')
else :
    n=(target-start)/diff
    if n>0 and((target-start)/diff)==((target-start)//diff): print('YES')
    else : print('NO')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var start : OclAny := null;
    var target : OclAny := null;
    var diff : OclAny := null;
    Sequence{start,target,diff} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if start = target then (
      execute ('YES')->display() ;
    exit()
    ) else skip ;
    if diff = 0 then  (
  (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))) if (logical_test (comparison (comparison (expr (atom (name target)))) == (comparison (expr (atom (name start)))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) ))))))))
    )
    else (
      var n : double := (target - start) / diff ;
    if n > 0 & ((target - start) / diff) = ((target - start) div diff) then  (
      execute ('YES')->display()
    )
    else (
      execute ('NO')->display()
      )
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
MAX_CHAR=26
def printCommon(s1,s2):
    a1=[0 for i in range(MAX_CHAR)]
    a2=[0 for i in range(MAX_CHAR)]
    length1=len(s1)
    length2=len(s2)
    for i in range(0,length1):
        a1[ord(s1[i])-ord('a')]+=1
    for i in range(0,length2):
        a2[ord(s2[i])-ord('a')]+=1
    for i in range(0,MAX_CHAR):
        if(a1[i]!=0 and a2[i]!=0):
            for j in range(0,min(a1[i],a2[i])):
                ch=chr(ord('a')+i)
                print(ch,end='')
if __name__=="__main__" :
    s1="geeksforgeeks"
    s2="practiceforgeeks"
    printCommon(s1,s2);
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var MAX_CHAR : int := 26 ;
    skip ;
    if __name__ = "__main__" then (
      s1 := "geeksforgeeks" ;
    s2 := "practiceforgeeks" ;
    printCommon(s1, s2);
    ) else skip;
  operation printCommon(s1 : OclAny, s2 : OclAny)
  pre: true post: true
  activity:
    var a1 : Sequence := Integer.subrange(0, MAX_CHAR-1)->select(i | true)->collect(i | (0)) ;
    var a2 : Sequence := Integer.subrange(0, MAX_CHAR-1)->select(i | true)->collect(i | (0)) ;
    var length1 : int := (s1)->size() ;
    var length2 : int := (s2)->size() ;
    for i : Integer.subrange(0, length1-1) do (    a1[(s1[i+1])->char2byte() - ('a')->char2byte()+1] := a1[(s1[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ;
    for i : Integer.subrange(0, length2-1) do (    a2[(s2[i+1])->char2byte() - ('a')->char2byte()+1] := a2[(s2[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ;
    for i : Integer.subrange(0, MAX_CHAR-1) do (    if (a1[i+1] /= 0 & a2[i+1] /= 0) then (
      for j : Integer.subrange(0, Set{a1[i+1], a2[i+1]}->min()-1) do (    var ch : String := (('a')->char2byte() + i)->byte2char() ;
    execute (ch)->display())
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
readline=sys.stdin.readline
def Bisect_Int(ok,ng,is_ok):
    while abs(ok-ng)>1 :
        mid=(ok+ng)//2
        if is_ok(mid):
            ok=mid
        else :
            ng=mid
    return ok
def main(N):
    if N==1 :
        return 0
    return main(N//2)+main(N-N//2)+N//2*(N-N//2)
ans_lst=[]
K=int(readline())
alp=[chr(i)for i in range(97,97+26)]
while K :
    def is_ok(x):
        return x*(x-1)//2<=K
    x=Bisect_Int(0,1<<10,is_ok)
    ans_lst+=[alp.pop()]*x
    K-=x*(x-1)//2
if not ans_lst :
    ans_lst.append(alp.pop())
print(*ans_lst,sep="")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var readline : OclAny := (OclFile["System.in"]).readline ;
    skip ;
    skip ;
    var ans_lst : Sequence := Sequence{} ;
    var K : int := ("" + ((readline())))->toInteger() ;
    var alp : Sequence := Integer.subrange(97, 97 + 26-1)->select(i | true)->collect(i | ((i)->byte2char())) ;
    while K do (    skip ;
    x := Bisect_Int(0, 1 * (2->pow(10)), is_ok) ;
    ans_lst := ans_lst + MatrixLib.elementwiseMult(Sequence{ alp->last() }, x) ;
    K := K - x * (x - 1) div 2) ;
    if not(ans_lst) then (
      execute ((alp->last()) : ans_lst)
    ) else skip ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name ans_lst))))))))->display();
  operation Bisect_Int(ok : OclAny, ng : OclAny, is_ok : OclAny) : OclAny
  pre: true post: true
  activity:
    while (ok - ng)->abs() > 1 do (    var mid : int := (ok + ng) div 2 ;
    if is_ok(mid) then  (
      ok := mid
    )
    else (
      ng := mid
      )) ;
    return ok;
  operation main(N : OclAny) : OclAny
  pre: true post: true
  activity:
    if N = 1 then (
      return 0
    ) else skip ;
    return main(N div 2) + main(N - N div 2) + N div 2 * (N - N div 2);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import Counter,OrderedDict
from itertools import permutations as perm
from fractions import Fraction
from collections import deque
from sys import stdin
from bisect import*
from heapq import*
from math import*
g=lambda : stdin.readline().strip()
gl=lambda : g().split()
gil=lambda :[int(var)for var in gl()]
gfl=lambda :[float(var)for var in gl()]
gcl=lambda : list(g())
gbs=lambda :[int(var)for var in g()]
mod=int(1e9)+7
inf=float("inf")
N,=gil()
if N==0 :
    print('a')
    exit()
ch=0
ans=[]
while N>1 :
    n=int(sqrt(2*N))
    N-=(n*(n-1))//2
    ans.append(chr(97+ch)*n)
    ch+=1
if N :
    ans.append(chr(97+ch)*2)
print(''.join(ans))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var g : Function := lambda $$ : OclAny in (stdin.readLine()->trim()) ;
    var gl : Function := lambda $$ : OclAny in (g->apply().split()) ;
    var gil : Function := lambda $$ : OclAny in (gl->apply()->select(var | true)->collect(var | (("" + ((var)))->toInteger()))) ;
    var gfl : Function := lambda $$ : OclAny in (gl->apply()->select(var | true)->collect(var | (("" + ((var)))->toReal()))) ;
    var gcl : Function := lambda $$ : OclAny in ((g->apply())) ;
    var gbs : Function := lambda $$ : OclAny in (g->apply()->select(var | true)->collect(var | (("" + ((var)))->toInteger()))) ;
    var mod : int := ("" + ((("1e9")->toReal())))->toInteger() + 7 ;
    var Math_PINFINITY : double := ("" + (("inf")))->toReal() ;
(testlist_star_expr (test (logical_test (comparison (expr (atom (name N)))))) ,)    Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name N)))))) ,)} := gil->apply() ;
    if N = 0 then (
      execute ('a')->display() ;
    exit()
    ) else skip ;
    var ch : int := 0 ;
    var ans : Sequence := Sequence{} ;
    while N > 1 do (    var n : int := ("" + ((sqrt(2 * N))))->toInteger() ;
    N := N - (n * (n - 1)) div 2 ;
    execute (((97 + ch)->byte2char() * n) : ans) ;
    ch := ch + 1) ;
    if N then (
      execute (((97 + ch)->byte2char() * 2) : ans)
    ) else skip ;
    execute (StringLib.sumStringsWithSeparator((ans), ''))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
k=int(input())
a=[]
x={}
curr=1
ele=1
while curr<=k :
    ele+=1
    x[curr]=ele
    a.append(curr)
    curr+=ele
if k==0 :
    print("a")
elif k==1 :
    print("aa")
else :
    ans=[]
    i=len(x)-1
    while k>0 :
        tmp=k//a[i]
        for j in range(tmp):
            ans.append(x[a[i]])
        k-=(tmp*a[i])
        i-=1
    start=97
    ret=""
    for i in range(len(ans)):
        ret+=chr(start)*ans[i]
        start+=1
    print(ret)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := Sequence{} ;
    var x : OclAny := Set{} ;
    var curr : int := 1 ;
    var ele : int := 1 ;
    while (curr->compareTo(k)) <= 0 do (    ele := ele + 1 ;
    x[curr+1] := ele ;
    execute ((curr) : a) ;
    curr := curr + ele) ;
    if k = 0 then  (
      execute ("a")->display()
    )
    else (if k = 1 then
   (
      execute ("aa")->display()    
)
    else (
      var ans : Sequence := Sequence{} ;
    var i : double := (x)->size() - 1 ;
    while k > 0 do (    var tmp : int := k div a[i+1] ;
    for j : Integer.subrange(0, tmp-1) do (    execute ((x[a[i+1]+1]) : ans)) ;
    k := k - (tmp * a[i+1]) ;
    i := i - 1) ;
    var start : int := 97 ;
    var ret : String := "" ;
    for i : Integer.subrange(0, (ans)->size()-1) do (    ret := ret + (start)->byte2char() * ans[i+1] ;
    start := start + 1) ;
    execute (ret)->display()
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys,math,heapq,queue
from collections import deque
from functools import cmp_to_key
fast_input=sys.stdin.readline
MOD=10**9+7
k=int(fast_input())
s='abcdefghijklmnopqrstuvwxyz'
i=0
lastcount=1
while k :
    if lastcount>k :
        lastcount=1
        i+=1
    s+=s[i]
    k-=lastcount
    lastcount+=1
print(s)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    var fast_input : OclAny := (OclFile["System.in"]).readline ;
    var MOD : double := (10)->pow(9) + 7 ;
    var k : int := ("" + ((fast_input())))->toInteger() ;
    var s : String := 'abcdefghijklmnopqrstuvwxyz' ;
    var i : int := 0 ;
    var lastcount : int := 1 ;
    while k do (    if (lastcount->compareTo(k)) > 0 then (
      lastcount := 1 ;
    i := i + 1
    ) else skip ;
    s := s + s[i+1] ;
    k := k - lastcount ;
    lastcount := lastcount + 1) ;
    execute (s)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=[]
n=1
while((n*(n+1))//2<=100000):
    a.append(n*(n+1)//2)
    n+=1
for i in range(1):
    k=int(input())
    s="qwertyuiopasdfghjklzxcvbnm"
    ans=""
    if k==0 :
        print("a")
        break
    pos=0
    while(k>0):
        for i in range(len(a)):
            if a[i]>k :
                ans+=s[pos]*(i+1)
                k-=a[i-1]
                pos+=1
                break
        else :
            ans+=s[pos]*(len(a)+1)
            k-=a[-1]
            pos+=1
    print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : Sequence := Sequence{} ;
    var n : int := 1 ;
    while ((n * (n + 1)) div 2 <= 100000) do (    execute ((n * (n + 1) div 2) : a) ;
    n := n + 1) ;
    for i : Integer.subrange(0, 1-1) do (    var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : String := "qwertyuiopasdfghjklzxcvbnm" ;
    var ans : String := "" ;
    if k = 0 then (
      execute ("a")->display() ;
    break
    ) else skip ;
    var pos : int := 0 ;
    while (k > 0) do ((compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) > (comparison (expr (atom (name k))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name pos)))))))) ]))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name k)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name pos)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name pos)))))))) ]))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))) + (expr (atom (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name k)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name pos)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))))) ;
    execute (ans)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import stdin,stdout
from collections import Counter
str_stdin=lambda : stdin.readline()[:-1]
strs_stdin=lambda : list(map(str,stdin.readline().split()))
int_stdin=lambda : int(stdin.readline())
ints_stdin=lambda : map(int,stdin.readline().split())
int_list_stdin=lambda : list(map(int,stdin.readline().split()))
def output(val):
    if type(val)is list :
        length=len(val)
        for elem in range(length): stdout.write(f"{val[elem]}"+" \n"[(length-1)==elem])
    else : stdout.write(f"{val}\n")
def solve():
    pass
def main():
    n=int_stdin()
    nums=sorted(int_list_stdin())
    lSum=0
    rSum=0
    for i in range(n):
        lSum+=nums[i]
        rSum+=nums[n+i]
    if lSum==rSum :
        return-1
    return nums
if __name__=="__main__" : output(main())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var str_stdin : Function := lambda $$ : OclAny in (stdin.readLine()->front()) ;
    var strs_stdin : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["String"])->apply(_x) ))) ;
    var int_stdin : Function := lambda $$ : OclAny in (("" + ((stdin.readLine())))->toInteger()) ;
    var ints_stdin : Function := lambda $$ : OclAny in ((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var int_list_stdin : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ;
    skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      output(main())
    ) else skip;
  operation output(val : OclAny)
  pre: true post: true
  activity:
    if (val)->oclType() <>= OclType["Sequence"] then  (
      var length : int := (val)->size() ;
    for elem : Integer.subrange(0, length-1) do (    stdout.write(StringLib.formattedString("{val[elem]}") + " \n"->select((length - 1) = elem)))
    )
    else (
      stdout.write(StringLib.formattedString("{val}\n"))
      );
  operation solve()
  pre: true post: true
  activity:
    skip;
  operation main() : OclAny
  pre: true post: true
  activity:
    var n : OclAny := int_stdin->apply() ;
    var nums : Sequence := int_list_stdin->apply()->sort() ;
    var lSum : int := 0 ;
    var rSum : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    lSum := lSum + nums[i+1] ;
    rSum := rSum + nums[n + i+1]) ;
    if lSum = rSum then (
      return -1
    ) else skip ;
    return nums;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import stdin
input=stdin.readline
def ii():
    return int(input())
def li():
    return list(map(int,input().split()))
from math import sqrt
def perfect_sq(n):
    x=int(sqrt(n))
    while x*xn :
        x-=1
    return(x*x==n)
n=ii()
s=input().strip()
c=False
idx=0
for i in range(n-1):
    if s[i]>s[i+1]:
        c=True
        idx=i
        break
if c==True :
    print('YES')
    print(idx+1,idx+2)
else :
    print('NO')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := stdin.readline ;
    skip ;
    skip ;
    skip ;
    skip ;
    n := ii() ;
    var s : OclAny := input()->trim() ;
    var c : boolean := false ;
    var idx : int := 0 ;
    for i : Integer.subrange(0, n - 1-1) do (    if (s[i+1]->compareTo(s[i + 1+1])) > 0 then (
      c := true ;
    idx := i ;
    break
    ) else skip) ;
    if c = true then  (
      execute ('YES')->display() ;
    execute (idx + 1)->display()
    )
    else (
      execute ('NO')->display()
      );
  operation ii() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation li() : OclAny
  pre: true post: true
  activity:
    return ((input().split())->collect( _x | (OclType["int"])->apply(_x) ));
  operation perfect_sq(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var x : int := ("" + ((sqrt(n))))->toInteger() ;
    while (x * x->compareTo(n)) < 0 do (    x := x + 1) ;
    while (x * x->compareTo(n)) > 0 do (    x := x - 1) ;
    return (x * x = n);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
isPrime=[1]*100005
def sieveOfEratostheneses():
    isPrime[1]=False
    i=2
    while i*i<100005 :
        if(isPrime[i]):
            j=2*i
            while j<100005 :
                isPrime[j]=False
                j+=i
        i+=1
    return
def findPrime(n):
    num=n+1
    while(num):
        if isPrime[num]:
            return num
        num+=1
    return 0
def minNumber(arr):
    sieveOfEratostheneses()
    s=0
    for i in range(0,len(arr)):
        s+=arr[i]
    if isPrime[s]==True :
        return 0
    num=findPrime(s)
    return num-s
arr=[2,4,6,8,12]
print(minNumber(arr))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var isPrime : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, 100005) ;
    skip ;
    skip ;
    skip ;
    arr := Sequence{2}->union(Sequence{4}->union(Sequence{6}->union(Sequence{8}->union(Sequence{ 12 })))) ;
    execute (minNumber(arr))->display();
  operation sieveOfEratostheneses()
  pre: true post: true
  activity:
    isPrime[1+1] := false ;
    var i : int := 2 ;
    while i * i < 100005 do (    if (isPrime[i+1]) then (
      var j : int := 2 * i ;
    while j < 100005 do (    isPrime[j+1] := false ;
    j := j + i)
    ) else skip ;
    i := i + 1) ;
    return;
  operation findPrime(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var num : OclAny := n + 1 ;
    while (num) do (    if isPrime[num+1] then (
      return num
    ) else skip ;
    num := num + 1) ;
    return 0;
  operation minNumber(arr : OclAny) : OclAny
  pre: true post: true
  activity:
    sieveOfEratostheneses() ;
    var s : int := 0 ;
    for i : Integer.subrange(0, (arr)->size()-1) do (    s := s + arr[i+1]) ;
    if isPrime[s+1] = true then (
      return 0
    ) else skip ;
    num := findPrime(s) ;
    return num - s;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
lst=list(map(int,input().split()))
a=lst[0 : n]
b=lst[n : len(lst)]
st=set(lst)
if len(st)==1 :
    print("-1")
elif sum(a)!=sum(b):
    print(*lst)
else :
    for i in range(n):
        temp=lst[i]
        lst[i]=lst[n+i-1]
        lst[n+i-1]=temp
        a=lst[0 : n]
        b=lst[n : len(lst)]
        if sum(a)!=sum(b):
            break
    print(*lst)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var a : OclAny := lst.subrange(0+1, n) ;
    var b : OclAny := lst.subrange(n+1, (lst)->size()) ;
    var st : Set := Set{}->union((lst)) ;
    if (st)->size() = 1 then  (
      execute ("-1")->display()
    )
    else (if (a)->sum() /= (b)->sum() then
   (
      execute ((argument * (test (logical_test (comparison (expr (atom (name lst))))))))->display()    
)
    else (
      for i : Integer.subrange(0, n-1) do (    var temp : OclAny := lst[i+1] ;
    lst[i+1] := lst[n + i - 1+1] ;
    lst[n + i - 1+1] := temp ;
    a := lst.subrange(0+1, n) ;
    b := lst.subrange(n+1, (lst)->size()) ;
    if (a)->sum() /= (b)->sum() then (
      break
    ) else skip) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name lst))))))))->display()
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
array=[int(x)for x in input().split()]
arrayNew=list(sorted(array))
if sum(arrayNew[: n])!=sum(arrayNew[n :]):
    print(*arrayNew)
else :
    print("-1")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var array : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    var arrayNew : Sequence := (array->sort()) ;
    if (arrayNew.subrange(1,n))->sum() /= (arrayNew.subrange(n+1))->sum() then  (
      execute ((argument * (test (logical_test (comparison (expr (atom (name arrayNew))))))))->display()
    )
    else (
      execute ("-1")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
mas_a=list(map(int,input().split()))
mas_a.sort()
toprint=False
if sum(mas_a[: n])!=sum(mas_a[n :]):
    print(*mas_a)
else :
    for i in range(n):
        if mas_a[i]!=mas_a[-1-i]:
            mas_a[i],mas_a[-1-i]=mas_a[-1-i],mas_a[i]
            toprint=True
            break
    else :
        print(-1)
if toprint :
    print(*mas_a)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var mas_a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    mas_a := mas_a->sort() ;
    var toprint : boolean := false ;
    if (mas_a.subrange(1,n))->sum() /= (mas_a.subrange(n+1))->sum() then  (
      execute ((argument * (test (logical_test (comparison (expr (atom (name mas_a))))))))->display()
    )
    else (
  (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name mas_a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) != (comparison (expr (atom (name mas_a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom - (number (integer 1)))) - (expr (atom (name i))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name mas_a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))) , (test (logical_test (comparison (expr (atom (name mas_a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom - (number (integer 1)))) - (expr (atom (name i))))))))) ]))))))) (assign_part = (testlist_star_expr (test (logical_test (comparison (expr (atom (name mas_a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom - (number (integer 1)))) - (expr (atom (name i))))))))) ])))))) , (test (logical_test (comparison (expr (atom (name mas_a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name toprint)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name True)))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))))))
      ) ;
    if toprint then (
      execute ((argument * (test (logical_test (comparison (expr (atom (name mas_a))))))))->display()
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b,c=map(int,input().split())
if c==0 and a==b :
    print("yes")
elif c!=0 and((b-a)/c)==int((b-a)/c)and((b-a)/c)>=0 :
    print("yes")
else :
    print("no")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if c = 0 & a = b then  (
      execute ("yes")->display()
    )
    else (if c /= 0 & ((b - a) / c) = ("" + (((b - a) / c)))->toInteger() & ((b - a) / c) >= 0 then
   (
      execute ("yes")->display()    
)
    else (
      execute ("no")->display()
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import stdin,stdout
from collections import Counter
str_stdin=lambda : stdin.readline()[:-1]
strs_stdin=lambda : list(map(str,stdin.readline().split()))
int_stdin=lambda : int(stdin.readline())
ints_stdin=lambda : map(int,stdin.readline().split())
int_list_stdin=lambda : list(map(int,stdin.readline().split()))
def output(val):
    if type(val)is list :
        length=len(val)
        for elem in range(length): stdout.write(f"{val[elem]}"+" \n"[(length-1)==elem])
    else : stdout.write(f"{val}\n")
def solve():
    pass
def main():
    n=int_stdin()
    nums=sorted(int_list_stdin())
    if sum(nums[: n])==sum(nums[n :]):
        return-1
    return nums
if __name__=="__main__" : output(main())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var str_stdin : Function := lambda $$ : OclAny in (stdin.readLine()->front()) ;
    var strs_stdin : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["String"])->apply(_x) ))) ;
    var int_stdin : Function := lambda $$ : OclAny in (("" + ((stdin.readLine())))->toInteger()) ;
    var ints_stdin : Function := lambda $$ : OclAny in ((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var int_list_stdin : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ;
    skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      output(main())
    ) else skip;
  operation output(val : OclAny)
  pre: true post: true
  activity:
    if (val)->oclType() <>= OclType["Sequence"] then  (
      var length : int := (val)->size() ;
    for elem : Integer.subrange(0, length-1) do (    stdout.write(StringLib.formattedString("{val[elem]}") + " \n"->select((length - 1) = elem)))
    )
    else (
      stdout.write(StringLib.formattedString("{val}\n"))
      );
  operation solve()
  pre: true post: true
  activity:
    skip;
  operation main() : OclAny
  pre: true post: true
  activity:
    var n : OclAny := int_stdin->apply() ;
    var nums : Sequence := int_list_stdin->apply()->sort() ;
    if (nums.subrange(1,n))->sum() = (nums.subrange(n+1))->sum() then (
      return -1
    ) else skip ;
    return nums;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import ceil
def MinimumMaximumPairs(n,m):
    max_pairs=((n-m+1)*(n-m))//2 ;
    min_pairs=(m*(((n-m)//m+1)*((n-m)//m))//2+ceil((n-m)/(m))*((n-m)% m))
    print("Minimum no.of pairs=",min_pairs)
    print("Maximum no.of pairs=",max_pairs)
if __name__=="__main__" :
    n,m=5,2
    MinimumMaximumPairs(n,m)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      Sequence{n,m} := Sequence{5,2} ;
    MinimumMaximumPairs(n, m)
    ) else skip;
  operation MinimumMaximumPairs(n : OclAny, m : OclAny)
  pre: true post: true
  activity:
    var max_pairs : int := ((n - m + 1) * (n - m)) div 2; ;
    var min_pairs : int := (m * (((n - m) div m + 1) * ((n - m) div m)) div 2 + ceil((n - m) / (m)) * ((n - m) mod m)) ;
    execute ("Minimum no.of pairs=")->display() ;
    execute ("Maximum no.of pairs=")->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def LengthlongestPrefixSuffix(s):
    n=len(s)
    lps=[0 for i in range(n)]
    len1=0
    i=1
    while(iint(n/2)):
        return int(n/2)
    else :
        return res
def longestPrefixSuffix(s):
    len1=LengthlongestPrefixSuffix(s)
    prefix=""
    for i in range(len1):
        prefix+=s[i]
    return prefix
if __name__=='__main__' :
    s="abcab"
    ans=longestPrefixSuffix(s)
    if(ans==""):
        print("-1")
    else :
        print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = '__main__' then (
      s := "abcab" ;
    var ans : OclAny := longestPrefixSuffix(s) ;
    if (ans = "") then  (
      execute ("-1")->display()
    )
    else (
      execute (ans)->display()
      )
    ) else skip;
  operation LengthlongestPrefixSuffix(s : OclAny) : OclAny
  pre: true post: true
  activity:
    var n : int := (s)->size() ;
    var lps : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ;
    var len1 : int := 0 ;
    var i : int := 1 ;
    while ((i->compareTo(n)) < 0) do (    if (s[i+1] = s[len1+1]) then  (
      len1 := len1 + 1 ;
    lps[i+1] := len1 ;
    i := i + 1
    )
    else (
      if (len1 /= 0) then  (
      len1 := lps[len1 - 1+1]
    )
    else (
      lps[i+1] := 0 ;
    i := i + 1
      )
      )) ;
    var res : OclAny := lps[n - 1+1] ;
    if ((res->compareTo(("" + ((n / 2)))->toInteger())) > 0) then  (
      return ("" + ((n / 2)))->toInteger()
    )
    else (
      return res
      );
  operation longestPrefixSuffix(s : OclAny) : OclAny
  pre: true post: true
  activity:
    len1 := LengthlongestPrefixSuffix(s) ;
    var prefix : String := "" ;
    for i : Integer.subrange(0, len1-1) do (    prefix := prefix + s[i+1]) ;
    return prefix;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import eulerlib,fractions
def compute():
    LIMIT=100000000
    ans=0
    for s in range(3,eulerlib.sqrt(LIMIT*2),2):
        for t in range(1,s,2):
            a=s*t
            b=(s*s-t*t)//2
            c=(s*s+t*t)//2
            p=a+b+c
            if p>=LIMIT :
                break
            if c %(a-b)==0 and fractions.gcd(s,t)==1 :
                ans+=(LIMIT-1)//p
    return str(ans)
if __name__=="__main__" :
    print(compute())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      execute (compute())->display()
    ) else skip;
  operation compute() : OclAny
  pre: true post: true
  activity:
    var LIMIT : int := 100000000 ;
    var ans : int := 0 ;
    for s : Integer.subrange(3, eulerlib.sqrt(LIMIT * 2)-1)->select( $x | ($x - 3) mod 2 = 0 ) do (    for t : Integer.subrange(1, s-1)->select( $x | ($x - 1) mod 2 = 0 ) do (    var a : double := s * t ;
    var b : int := (s * s - t * t) div 2 ;
    var c : int := (s * s + t * t) div 2 ;
    var p : OclAny := a + b + c ;
    if (p->compareTo(LIMIT)) >= 0 then (
      break
    ) else skip ;
    if c mod (a - b) = 0 & fractions.gcd(s, t) = 1 then (
      ans := ans + (LIMIT - 1) div p
    ) else skip)) ;
    return ("" + ((ans)));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def Log2n(n):
    return(1+Log2n(n/2))if(n>1)else 0 ;
def isPowerOfd(n,d):
    count=0 ;
    if(n and(n &(n-1))==0):
        while(n>1):
            n>>=1 ;
            count+=1 ;
        return(count %(Log2n(d))==0);
    return False ;
n=64 ;
d=8 ;
if(isPowerOfd(n,d)):
    print(n,"is a power of",d);
else :
    print(n,"is not a power of",d);
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    n := 64; ;
    d := 8; ;
    if (isPowerOfd(n, d)) then  (
      execute (n)->display();
    )
    else (
      execute (n)->display();
      );
  operation Log2n(n : OclAny)
  pre: true post: true
  activity:
    return if (n > 1) then (1 + Log2n(n / 2)) else 0 endif;;
  operation isPowerOfd(n : OclAny, d : OclAny)
  pre: true post: true
  activity:
    var count : int := 0; ;
    if (n & (MathLib.bitwiseAnd(n, (n - 1))) = 0) then (
      while (n > 1) do (    n := n div (2->pow(1)); ;
    count := count + 1;) ;
    return (count mod (Log2n(d)) = 0);
    ) else skip ;
    return false;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def frequencyDigits(n,d):
    c=0 ;
    while(n>0):
        if(n % 10==d):
            c+=1 ;
        n=int(n/10);
    return c ;
N=1122322 ;
D=2 ;
print(frequencyDigits(N,D));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var N : int := 1122322; ;
    var D : int := 2; ;
    execute (frequencyDigits(N, D))->display();;
  operation frequencyDigits(n : OclAny, d : OclAny)
  pre: true post: true
  activity:
    var c : int := 0; ;
    while (n > 0) do (    if (n mod 10 = d) then (
      c := c + 1;
    ) else skip ;
    n := ("" + ((n / 10)))->toInteger();) ;
    return c;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
MAX=25 ;
def getMinSum(arr,n):
    bits_count=[0]*MAX
    max_bit=0 ; sum=0 ; ans=0 ;
    for d in range(n):
        e=arr[d]; f=0 ;
        while(e>0):
            rem=e % 2 ;
            e=e//2 ;
            if(rem==1):
                bits_count[f]+=rem ;
            f+=1
        max_bit=max(max_bit,f);
    for d in range(max_bit):
        temp=pow(2,d);
        if(bits_count[d]>n//2):
            ans=ans+temp ;
    for d in range(n):
        arr[d]=arr[d]^ ans ;
        sum=sum+arr[d];
    return sum
if __name__=="__main__" :
    arr=[3,5,7,11,15];
    n=len(arr);
    print(getMinSum(arr,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var MAX : int := 25; ;
    skip ;
    if __name__ = "__main__" then (
      arr := Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{11}->union(Sequence{ 15 })))); ;
    n := (arr)->size(); ;
    execute (getMinSum(arr, n))->display()
    ) else skip;
  operation getMinSum(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var bits_count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX) ;
    var max_bit : int := 0;    var sum : int := 0;    var ans : int := 0; ;
    for d : Integer.subrange(0, n-1) do (    var e : OclAny := arr[d+1];    var f : int := 0; ;
    while (e > 0) do (    var rem : int := e mod 2; ;
    e := e div 2; ;
    if (rem = 1) then (
      bits_count[f+1] := bits_count[f+1] + rem;
    ) else skip ;
    f := f + 1) ;
    max_bit := Set{max_bit, f}->max();) ;
    for d : Integer.subrange(0, max_bit-1) do (    var temp : double := (2)->pow(d); ;
    if ((bits_count[d+1]->compareTo(n div 2)) > 0) then (
      ans := ans + temp;
    ) else skip) ;
    for d : Integer.subrange(0, n-1) do (    arr[d+1] := MathLib.bitwiseXor(arr[d+1], ans); ;
    sum := sum + arr[d+1];) ;
    return sum;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for i in range(int(input())):
    n,c0,c1,h=map(int,input().split())
    s=input()
    a=s.count('1')*c1
    b=s.count('0')*c0
    c=a+b
    if c1>c0 :
        ans1=s.count('1')*h
        ab=ans1+(n*c0)
        print(min(c,ab))
    elif c1toInteger()-1) do (    var n : OclAny := null;
    var c0 : OclAny := null;
    var c1 : OclAny := null;
    var h : OclAny := null;
    Sequence{n,c0,c1,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var s : String := (OclFile["System.in"]).readLine() ;
    var a : double := s->count('1') * c1 ;
    var b : double := s->count('0') * c0 ;
    var c : OclAny := a + b ;
    if (c1->compareTo(c0)) > 0 then  (
      var ans1 : double := s->count('1') * h ;
    var ab : OclAny := ans1 + (n * c0) ;
    execute (Set{c, ab}->min())->display()
    )
    else (if (c1->compareTo(c0)) < 0 then
   (
      ans1 := s->count('0') * h ;
    ab := ans1 + (n * c1) ;
    execute (Set{c, ab}->min())->display()    
)
    else (if c1 = c0 then
   (
      execute (c)->display()    
)
    else skip    )
    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
while t>0 :
    t-=1
    n,a,b,h=(int(i)for i in input().strip().split(' '))
    x=0
    y=0
    s=input()
    l=len(s)
    for i in s :
        if i=='0' :
            x+=1
        if i=='1' :
            y+=1
    if h+atoInteger() ;
    while t > 0 do (    t := t - 1 ;
    var n : OclAny := null;
    var a : OclAny := null;
    var b : OclAny := null;
    var h : OclAny := null;
    Sequence{n,a,b,h} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name strip) (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ' '))))))) ))))))))} ;
    var x : int := 0 ;
    var y : int := 0 ;
    var s : String := (OclFile["System.in"]).readLine() ;
    var l : int := (s)->size() ;
    for i : s->characters() do (    if i = '0' then (
      x := x + 1
    ) else skip ;
    if i = '1' then (
      y := y + 1
    ) else skip) ;
    if (h + a->compareTo(b)) < 0 then  (
      execute (a * l + h * y)->display()
    )
    else (if (h + b->compareTo(a)) < 0 then
   (
      execute (b * l + h * x)->display()    
)
    else (
      execute (a * x + b * y)->display()
      )    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    n,c0,c1,h=map(int,input().split())
    li=list(input())
    ones=li.count('1')
    zeros=li.count('0')
    re=[]
    re.append(c0*n+ones*h)
    re.append(c1*n+zeros*h)
    re.append(c0*zeros+c1*ones)
    print(min(re))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : OclAny := null;
    var c0 : OclAny := null;
    var c1 : OclAny := null;
    var h : OclAny := null;
    Sequence{n,c0,c1,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var li : Sequence := ((OclFile["System.in"]).readLine())->characters() ;
    var ones : int := li->count('1') ;
    var zeros : int := li->count('0') ;
    var re : Sequence := Sequence{} ;
    execute ((c0 * n + ones * h) : re) ;
    execute ((c1 * n + zeros * h) : re) ;
    execute ((c0 * zeros + c1 * ones) : re) ;
    execute ((re)->min())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
def calcF(s,c0,c1):
    res=0
    for c in s :
        if c=="0" :
            res+=c0
        else :
            res+=c1
    return res
for i in range(t):
    res=0
    arr=input().split(" ")
    s=input()
    n=int(arr[0])
    c0=int(arr[1])
    c1=int(arr[2])
    h=int(arr[3])
    MAX=max(c0,c1)
    MIN=min(c0,c1)
    if MAX-MIN>h :
        if MIN==c0 :
            char_rep="0"
            delete="1"
        else :
            char_rep="1"
            delete="0"
        while delete in s :
            ind=s.index(delete)
            s=s[: ind]+char_rep+s[ind+1 :]
            res+=h
    print(res+calcF(s,c0,c1))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    skip ;
    for i : Integer.subrange(0, t-1) do (    res := 0 ;
    var arr : OclAny := input().split(" ") ;
    s := (OclFile["System.in"]).readLine() ;
    var n : int := ("" + ((arr->first())))->toInteger() ;
    c0 := ("" + ((arr[1+1])))->toInteger() ;
    c1 := ("" + ((arr[2+1])))->toInteger() ;
    var h : int := ("" + ((arr[3+1])))->toInteger() ;
    var MAX : OclAny := Set{c0, c1}->max() ;
    var MIN : OclAny := Set{c0, c1}->min() ;
    if (MAX - MIN->compareTo(h)) > 0 then (
      if MIN = c0 then  (
      var char_rep : String := "0" ;
    var delete : String := "1"
    )
    else (
      char_rep := "1" ;
    delete := "0"
      ) ;
    while (s)->includes(delete) do (    var ind : int := s->indexOf(delete) - 1 ;
    s := s.subrange(1,ind) + char_rep + s.subrange(ind + 1+1) ;
    res := res + h)
    ) else skip ;
    execute (res + calcF(s, c0, c1))->display());
  operation calcF(s : OclAny, c0 : OclAny, c1 : OclAny) : OclAny
  pre: true post: true
  activity:
    var res : int := 0 ;
    for c : s do (    if c = "0" then  (
      res := res + c0
    )
    else (
      res := res + c1
      )) ;
    return res;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b,c=map(int,input().split(" "))
if c!=0 :
    k=(b-a)/c
    if k<0 or k!=int(k):
        print("NO")
    else :
        print("YES")
elif a==b :
    print("YES")
else :
    print("NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ;
    if c /= 0 then  (
      var k : double := (b - a) / c ;
    if k < 0 or k /= ("" + ((k)))->toInteger() then  (
      execute ("NO")->display()
    )
    else (
      execute ("YES")->display()
      )
    )
    else (if a = b then
   (
      execute ("YES")->display()    
)
    else (
      execute ("NO")->display()
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for i in range(int(input())):
    n,c0,c1,h=map(int,input().split())
    s=input()
    a=s.count('1')
    b=s.count('0')
    if(c0+h)toInteger()-1) do (    var n : OclAny := null;
    var c0 : OclAny := null;
    var c1 : OclAny := null;
    var h : OclAny := null;
    Sequence{n,c0,c1,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var s : String := (OclFile["System.in"]).readLine() ;
    var a : int := s->count('1') ;
    var b : int := s->count('0') ;
    if ((c0 + h)->compareTo(c1)) < 0 then  (
      var ch1 : double := h * a ;
    execute (ch1 + (n * c0))->display()
    )
    else (if ((c1 + h)->compareTo(c0)) < 0 then
   (
      var ch0 : double := h * b ;
    execute (ch0 + (n * c1))->display()    
)
    else (
      execute ((c0 * b) + (c1 * a))->display()
      )    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import io,os
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def main(t):
    n,k=map(int,input().split())
    if ktoInteger() ;
    t := 1 ;
    while (t->compareTo(T)) <= 0 do (    main(t) ;
    t := t + 1);
  operation main(t : OclAny)
  pre: true post: true
  activity:
    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if (k->compareTo(n)) < 0 then (
      execute ("No")->display() ;
    return
    ) else skip ;
    if n mod 2 = 1 then  (
      var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n - 1))->union(Sequence{ k - n + 1 })
    )
    else (
      if k mod 2 = 0 then  (
      arr := MatrixLib.elementwiseMult(Sequence{ 1 }, (n - 2))->union(MatrixLib.elementwiseMult(Sequence{ (k - n + 2) div 2 }, 2))
    )
    else (
      arr := Sequence{ -1 }
      )
      ) ;
    if arr->first() = -1 then  (
      execute ("No")->display()
    )
    else (
      execute ("Yes")->display() ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name arr))))))))->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
for _ in range(int(input())):
    n,m=map(int,input().split())
    if n>m or(n % 2==0 and m % 2==1):
        print("NO")
    else :
        ans=[]
        if n % 2==1 :
            ans=[1]*(n-1)+[m-(n-1)]
        else :
            ans=[1]*(n-2)+[(m-n+2)//2]*2
        print('Yes')
        print(*ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if (n->compareTo(m)) > 0 or (n mod 2 = 0 & m mod 2 = 1) then  (
      execute ("NO")->display()
    )
    else (
      var ans : Sequence := Sequence{} ;
    if n mod 2 = 1 then  (
      ans := MatrixLib.elementwiseMult(Sequence{ 1 }, (n - 1))->union(Sequence{ m - (n - 1) })
    )
    else (
      ans := MatrixLib.elementwiseMult(Sequence{ 1 }, (n - 2))->union(MatrixLib.elementwiseMult(Sequence{ (m - n + 2) div 2 }, 2))
      ) ;
    execute ('Yes')->display() ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
t=int(input())
for _ in range(t):
    n,m=map(int,input().split())
    if(n>m)or(n % 2==0 and m % 2!=0):
        print("No")
    else :
        print("Yes")
        s=[]
        if n % 2!=0 :
            s.extend([1]*(n-1)+[m-n+1])
        else :
            s.extend([1]*(n-2)+[(m-n+2)//2]*2)
        print(*s)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, t-1) do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if ((n->compareTo(m)) > 0) or (n mod 2 = 0 & m mod 2 /= 0) then  (
      execute ("No")->display()
    )
    else (
      execute ("Yes")->display() ;
    var s : Sequence := Sequence{} ;
    if n mod 2 /= 0 then  (
      s := s->union(MatrixLib.elementwiseMult(Sequence{ 1 }, (n - 1))->union(Sequence{ m - n + 1 }))
    )
    else (
      s := s->union(MatrixLib.elementwiseMult(Sequence{ 1 }, (n - 2))->union(MatrixLib.elementwiseMult(Sequence{ (m - n + 2) div 2 }, 2)))
      ) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name s))))))))->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
def solution(n,m):
    if(n>m)or(n % 2==0 and m % 2!=0):
        print("No")
    else :
        print("Yes")
        s=""
        if n % 2!=0 :
            s="1 "*(n-1)+str(m-n+1)
        else :
            s="1 "*(n-2)+(str((m-n+2)//2)+" ")*2
        print(s.strip())
t=int(input())
while t :
    n,m=map(int,input().split())
    solution(n,m)
    t-=1
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    skip ;
    var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    while t do (    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    solution(n, m) ;
    t := t - 1);
  operation solution(n : OclAny, m : OclAny)
  pre: true post: true
  activity:
    if ((n->compareTo(m)) > 0) or (n mod 2 = 0 & m mod 2 /= 0) then  (
      execute ("No")->display()
    )
    else (
      execute ("Yes")->display() ;
    var s : String := "" ;
    if n mod 2 /= 0 then  (
      s := StringLib.nCopies("1 ", (n - 1)) + ("" + ((m - n + 1)))
    )
    else (
      s := StringLib.nCopies("1 ", (n - 2)) + (("" + (((m - n + 2) div 2))) + " ") * 2
      ) ;
    execute (s->trim())->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def centered_square_num(n):
    return n*n+((n-1)*(n-1))
n=7
print("%sth Centered square number: " % n,centered_square_num(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    n := 7 ;
    execute (StringLib.format("%sth Centered square number: ",n))->display();
  operation centered_square_num(n : OclAny) : OclAny
  pre: true post: true
  activity:
    return n * n + ((n - 1) * (n - 1));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
for _ in range(int(input())):
    n,m=map(int,input().split())
    if n>m or(n % 2==0 and m % 2==1): print("NO")
    else :
        print("YES")
        l=[]
        if n % 2 : l.extend([1]*(n-1)+[m-n+1])
        else : l.extend([1]*(n-2)+[(m-n+2)//2]*2)
        print(*l,sep=' ')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if (n->compareTo(m)) > 0 or (n mod 2 = 0 & m mod 2 = 1) then  (
      execute ("NO")->display()
    )
    else (
      execute ("YES")->display() ;
    var l : Sequence := Sequence{} ;
    if n mod 2 then  (
      l := l->union(MatrixLib.elementwiseMult(Sequence{ 1 }, (n - 1))->union(Sequence{ m - n + 1 }))
    )
    else (
      l := l->union(MatrixLib.elementwiseMult(Sequence{ 1 }, (n - 2))->union(MatrixLib.elementwiseMult(Sequence{ (m - n + 2) div 2 }, 2)))
      ) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name l))))))))->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def PrimeFactors(n):
    v=[]
    x=n
    i=2
    while(i*i<=n):
        if(x % i==0):
            v.append(i)
            while(x % i==0):
                x//=i
        i+=1
    if(x>1):
        v.append(x)
    return v
def GoodNumber(n):
    v=PrimeFactors(n)
    ans=1
    for i in range(len(v)):
        ans*=v[i]
    return ans
if __name__=="__main__" :
    n=12
    print(GoodNumber(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      n := 12 ;
    execute (GoodNumber(n))->display()
    ) else skip;
  operation PrimeFactors(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var v : Sequence := Sequence{} ;
    var x : OclAny := n ;
    var i : int := 2 ;
    while ((i * i->compareTo(n)) <= 0) do (    if (x mod i = 0) then (
      execute ((i) : v) ;
    while (x mod i = 0) do (    x := x div i)
    ) else skip ;
    i := i + 1) ;
    if (x > 1) then (
      execute ((x) : v)
    ) else skip ;
    return v;
  operation GoodNumber(n : OclAny) : OclAny
  pre: true post: true
  activity:
    v := PrimeFactors(n) ;
    var ans : int := 1 ;
    for i : Integer.subrange(0, (v)->size()-1) do (    ans := ans * v[i+1]) ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
MAX_CHAR=256
def countSubStrings(s,anotherStr,k):
    illegal=[False]*MAX_CHAR
    for i in range(len(anotherStr)):
        illegal[ord(anotherStr[i])]=True
    us=set()
    for i in range(len(s)):
        ss=""
        count=0
        for j in range(i,len(s)):
            if(illegal[ord(s[j])]):
                count+=1
            ss=ss+s[j]
            if(count<=k):
                us.add(ss)
            else :
                break
    return len(us)
if __name__=="__main__" :
    string="acbacbacaa"
    anotherStr="abcdefghijklmnopqrstuvwxyz"
    k=2
    print(countSubStrings(string,anotherStr,k))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var MAX_CHAR : int := 256 ;
    skip ;
    if __name__ = "__main__" then (
      var string : String := "acbacbacaa" ;
    anotherStr := "abcdefghijklmnopqrstuvwxyz" ;
    k := 2 ;
    execute (countSubStrings(string, anotherStr, k))->display()
    ) else skip;
  operation countSubStrings(s : OclAny, anotherStr : OclAny, k : OclAny) : OclAny
  pre: true post: true
  activity:
    var illegal : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, MAX_CHAR) ;
    for i : Integer.subrange(0, (anotherStr)->size()-1) do (    illegal[(anotherStr[i+1])->char2byte()+1] := true) ;
    var us : Set := Set{}->union(()) ;
    for i : Integer.subrange(0, (s)->size()-1) do (    var ss : String := "" ;
    var count : int := 0 ;
    for j : Integer.subrange(i, (s)->size()-1) do (    if (illegal[(s[j+1])->char2byte()+1]) then (
      count := count + 1
    ) else skip ;
    ss := ss + s[j+1] ;
    if ((count->compareTo(k)) <= 0) then  (
      execute ((ss) : us)
    )
    else (
      break
      ))) ;
    return (us)->size();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def maxProduct(arr,n):
    if(n<2):
        print("No pairs exists")
        return
    a=arr[0]; b=arr[1]
    for i in range(0,n):
        for j in range(i+1,n):
            if(arr[i]*arr[j]>a*b):
                a=arr[i]; b=arr[j]
    print("Max product pair is{",a,",",b,"}",sep="")
arr=[1,4,3,6,7,0]
n=len(arr)
maxProduct(arr,n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    arr := Sequence{1}->union(Sequence{4}->union(Sequence{3}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 0 }))))) ;
    n := (arr)->size() ;
    maxProduct(arr, n);
  operation maxProduct(arr : OclAny, n : OclAny)
  pre: true post: true
  activity:
    if (n < 2) then (
      execute ("No pairs exists")->display() ;
    return
    ) else skip ;
    var a : OclAny := arr->first();    var b : OclAny := arr[1+1] ;
    for i : Integer.subrange(0, n-1) do (    for j : Integer.subrange(i + 1, n-1) do (    if ((arr[i+1] * arr[j+1]->compareTo(a * b)) > 0) then (
      a := arr[i+1];    b := arr[j+1]
    ) else skip)) ;
    execute ("Max product pair is{")->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
while t>0 :
    t-=1
    s=input()
    stack=[]
    check=0
    for i in range(0,len(s)):
        if s[i]=="1" :
            if stack :
                if stack[-1]=='0' :
                    stack.append('1')
        if s[i]=='0' :
            if stack :
                if stack[-1]=='1' :
                    check=2
            else :
                stack.append('0')
    if check==2 :
        print(check)
    else :
        if '0' in stack :
            print(1)
        else :
            print(0)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    while t > 0 do (    t := t - 1 ;
    var s : String := (OclFile["System.in"]).readLine() ;
    var stack : Sequence := Sequence{} ;
    var check : int := 0 ;
    for i : Integer.subrange(0, (s)->size()-1) do (    if s[i+1] = "1" then (
      if stack then (
      if stack->last() = '0' then (
      execute (('1') : stack)
    ) else skip
    ) else skip
    ) else skip ;
    if s[i+1] = '0' then (
      if stack then  (
      if stack->last() = '1' then (
      check := 2
    ) else skip
    )
    else (
      execute (('0') : stack)
      )
    ) else skip) ;
    if check = 2 then  (
      execute (check)->display()
    )
    else (
      if (stack)->includes('0') then  (
      execute (1)->display()
    )
    else (
      execute (0)->display()
      )
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b,c=[int(i)for i in input().split()]
A=c
B=-c+a-b
if c==0 :
    if a==b : print("YES")
    else : print("NO")
else :
    if-B/A==-B//A>0 : print("YES")
    else : print("NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var A : OclAny := c ;
    var B : double := -c + a - b ;
    if c = 0 then  (
      if a = b then  (
      execute ("YES")->display()
    )
    else (
      execute ("NO")->display()
      )
    )
    else (
      if -B / A = -B div A & (-B div A > 0) then  (
      execute ("YES")->display()
    )
    else (
      execute ("NO")->display()
      )
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
t=int(input())
for i in range(0,t):
    s=str(input())
    cnt_1=s.count('0')
    cnt_2=s.count('1')
    if(len(s)==cnt_1):
        print(1)
    else :
        if(len(s)==cnt_2):
            print(0)
        else :
            if(s.rfind('0')-s.find('0')+1==cnt_1):
                print(1)
            else :
                print(2)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, t-1) do (    var s : String := ("" + (((OclFile["System.in"]).readLine()))) ;
    var cnt    var s : String := ("" + (((OclFile["System.in"]).readLine()))) : int := s->count('0') ;
    var cnt:= s->count('1') : int := s->count('1') ;
    if ((s)->size() = cnt    var s : String := ("" + (((OclFile["System.in"]).readLine())))) then  (
      execute (1)->display()
    )
    else (
      if ((s)->size() = cnt    execute (0)->display()) then  (
      execute (0)->display()
    )
    else (
      if (s.rfind('0') - s->indexOf('0') - 1 + 1 = cnt    var s : String := ("" + (((OclFile["System.in"]).readLine())))) then  (
      execute (1)->display()
    )
    else (
      execute (2)->display()
      )
      )
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for case in range(t):
    s=input()
    ss=s.replace('1',' ')
    s_cut=ss.split()
    if '0' not in s :
        ans=0
    elif len(s_cut)==1 :
        ans=1
    else :
        ans=2
    print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for case : Integer.subrange(0, t-1) do (    var s : String := (OclFile["System.in"]).readLine() ;
    var ss : String := s.replace('1', ' ') ;
    var s_cut : OclAny := ss.split() ;
    if (s)->characters()->excludes('0') then  (
      var ans : int := 0
    )
    else (if (s_cut)->size() = 1 then
   (
      ans := 1    
)
    else (
      ans := 2
      )    )
 ;
    execute (ans)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import re
for _ in range(int(input())):
    a=input()
    if len(re.findall('0+',a))>1 :
        print(2)
    elif '0' in a :
        print(1)
    else :
        print(0)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var a : String := (OclFile["System.in"]).readLine() ;
    if ((a)->allMatches('0+'))->size() > 1 then  (
      execute (2)->display()
    )
    else (if (a)->characters()->includes('0') then
   (
      execute (1)->display()    
)
    else (
      execute (0)->display()
      )    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for i in range(int(input())):
    s=input()
    s=s.strip('1')
    if('1' in s)==True :
        print('2')
    elif('0' in s)==True :
        print('1')
    else :
        print('0')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var s : String := (OclFile["System.in"]).readLine() ;
    s := s->trim() ;
    if ((s)->characters()->includes('1')) = true then  (
      execute ('2')->display()
    )
    else (if ((s)->characters()->includes('0')) = true then
   (
      execute ('1')->display()    
)
    else (
      execute ('0')->display()
      )    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
s=input()
a=[""]
for c in s :
    if a[-1]=="" and c==' ' :
        continue
    a[-1]+=c ;
    if c=='?' or c=='!' or c=='.' :
        a.append("");
ans=0
last=0
for i in range(len(a)):
    if len(a[i])>n :
        print('Impossible')
        exit(0)
    add=len(a[i])+1 if i+1!=len(a)else len(a[i])
    if i==0 or(last+add)>n :
        ans+=1
        last=len(a[i])
    else :
        last+=add
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : String := (OclFile["System.in"]).readLine() ;
    var a : Sequence := Sequence{ "" } ;
    for c : s->characters() do (    if a->last() = "" & c = ' ' then (
      continue
    ) else skip ;
    a->last() := a->last() + c; ;
    if c = '?' or c = '!' or c = '.' then (
      execute (("") : a);
    ) else skip) ;
    var ans : int := 0 ;
    var last : int := 0 ;
    for i : Integer.subrange(0, (a)->size()-1) do (    if ((a[i+1])->size()->compareTo(n)) > 0 then (
      execute ('Impossible')->display() ;
    exit(0)
    ) else skip ;
    var add : int := if i + 1 /= (a)->size() then (a[i+1])->size() + 1 else (a[i+1])->size() endif ;
    if i = 0 or ((last + add)->compareTo(n)) > 0 then  (
      ans := ans + 1 ;
    last := (a[i+1])->size()
    )
    else (
      last := last + add
      )) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
n=int(input())
nDivisible=[]
for i in range(1,int(math.sqrt(n))+1):
    if n % i==0 :
        nDivisible.append(i)
        nDivisible.append(n//i)
nDivisible.sort()
flag=True
for i in range(len(nDivisible)-1,-1,-1):
    flag=True
    maxDivisible=nDivisible[i]
    for j in range(2,int(math.sqrt(maxDivisible))+1):
        if maxDivisible %(j*j)==0 :
            flag=False
            break
    if flag==True :
        print(maxDivisible)
        break
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var nDivisible : Sequence := Sequence{} ;
    for i : Integer.subrange(1, ("" + (((n)->sqrt())))->toInteger() + 1-1) do (    if n mod i = 0 then (
      execute ((i) : nDivisible) ;
    execute ((n div i) : nDivisible)
    ) else skip) ;
    nDivisible := nDivisible->sort() ;
    var flag : boolean := true ;
    for i : Integer.subrange(-1 + 1, (nDivisible)->size() - 1)->reverse() do (    flag := true ;
    var maxDivisible : OclAny := nDivisible[i+1] ;
    for j : Integer.subrange(2, ("" + (((maxDivisible)->sqrt())))->toInteger() + 1-1) do (    if maxDivisible mod (j * j) = 0 then (
      flag := false ;
    break
    ) else skip) ;
    if flag = true then (
      execute (maxDivisible)->display() ;
    break
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
z=int(input())
for k in range(2,10**6):
    while z %(k*k)==0 :
        z//=k
print(z)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var z : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for k : Integer.subrange(2, (10)->pow(6)-1) do (    while z mod (k * k) = 0 do (    z := z div k)) ;
    execute (z)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n5=int(input())
for k in range(2,10**6):
    while n5 %(k*k)==0 :
        n5=n5//k
print(n5)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n5 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for k : Integer.subrange(2, (10)->pow(6)-1) do (    while n5 mod (k * k) = 0 do (    n5 := n5 div k)) ;
    execute (n5)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
def generatePrimeFactors(n):
    factors=set()
    for i in range(2,int(math.sqrt(n))+1):
        while n % i==0 :
            n//=i
            factors.add(i)
    if n>=2 :
        factors.add(n)
    return factors
def happyNumber(n):
    factors=generatePrimeFactors(n)
    number=1
    for factor in factors :
        number*=factor
    return number
n=int(input())
print(happyNumber(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    execute (happyNumber(n))->display();
  operation generatePrimeFactors(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var factors : Set := Set{}->union(()) ;
    for i : Integer.subrange(2, ("" + (((n)->sqrt())))->toInteger() + 1-1) do (    while n mod i = 0 do (    n := n div i ;
    execute ((i) : factors))) ;
    if n >= 2 then (
      execute ((n) : factors)
    ) else skip ;
    return factors;
  operation happyNumber(n : OclAny) : OclAny
  pre: true post: true
  activity:
    factors := generatePrimeFactors(n) ;
    var number : int := 1 ;
    for factor : factors do (    number := number * factor) ;
    return number;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
n=int(input())
def primefactors(n):
    list1=[]
    if n % 2==0 :
        list1.append(2),
        while n % 2==0 :
            n=n/2
    for i in range(3,int(math.sqrt(n))+1,2):
        if n % i==0 :
            list1.append(i),
            while n % i==0 :
                n=n/i
    if n>1 :
        list1.append(n)
    return list1
prime_factors=primefactors(n)
rslt=1
if len(prime_factors)==0 :
    print(n)
else :
    for p in prime_factors :
        rslt*=p
    print(int(rslt))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    skip ;
    var prime_factors : OclAny := primefactors(n) ;
    var rslt : int := 1 ;
    if (prime_factors)->size() = 0 then  (
      execute (n)->display()
    )
    else (
      for p : prime_factors do (    rslt := rslt * p) ;
    execute (("" + ((rslt)))->toInteger())->display()
      );
  operation primefactors(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var list1 : Sequence := Sequence{} ;
    if n mod 2 = 0 then (
  (testlist_star_expr (test (logical_test (comparison (expr (atom (name list1)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ))))))) ,) ;
    while n mod 2 = 0 do (    n := n / 2)
    ) else skip ;
    for i : Integer.subrange(3, ("" + (((n)->sqrt())))->toInteger() + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do (    if n mod i = 0 then (
  (testlist_star_expr (test (logical_test (comparison (expr (atom (name list1)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) ,) ;
    while n mod i = 0 do (    n := n / i)
    ) else skip) ;
    if n > 1 then (
      execute ((n) : list1)
    ) else skip ;
    return list1;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def msbPos(n):
    pos=0
    while n!=0 :
        pos+=1
        n=n>>1
    return pos
def josephify(n):
    position=msbPos(n)
    j=1<<(position-1)
    n=n ^ j
    n=n<<1
    n=n | 1
    return n
n=41
print(josephify(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    n := 41 ;
    execute (josephify(n))->display();
  operation msbPos(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var pos : int := 0 ;
    while n /= 0 do (    pos := pos + 1 ;
    n := n /(2->pow(1))) ;
    return pos;
  operation josephify(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var position : OclAny := msbPos(n) ;
    var j : int := 1 * (2->pow((position - 1))) ;
    n := MathLib.bitwiseXor(n, j) ;
    n := n * (2->pow(1)) ;
    n := MathLib.bitwiseOr(n, 1) ;
    return n;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b,c=map(int,input().split())
if c==0 :
    if a==b :
        print("YES")
    else :
        print("NO")
elif(b-a)% c==0 and(b-a)//c>=0 :
    print("YES")
else :
    print("NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if c = 0 then  (
      if a = b then  (
      execute ("YES")->display()
    )
    else (
      execute ("NO")->display()
      )
    )
    else (if (b - a) mod c = 0 & (b - a) div c >= 0 then
   (
      execute ("YES")->display()    
)
    else (
      execute ("NO")->display()
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
T=int(input())
ans=[]
for _ in range(T):
    n=int(input())
    boards=list(map(int,input().split()))
    boards.sort()
    answer=min(boards[-2]-1,n-2)
    ans.append(answer)
for i in ans :
    print(i)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var ans : Sequence := Sequence{} ;
    for _anon : Integer.subrange(0, T-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var boards : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    boards := boards->sort() ;
    var answer : OclAny := Set{boards->front()->last() - 1, n - 2}->min() ;
    execute ((answer) : ans)) ;
    for i : ans do (    execute (i)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from heapq import nlargest
def main():
    t=int(input())
    for _ in range(t):
        n=int(input())
        a=[int(x)for x in input().split()]
        _,y=nlargest(2,a)
        ret=min(y-1,n-2)
        print(ret)
if __name__=="__main__" :
    import sys,threading
    input=sys.stdin.readline
    thread=threading.Thread(target=main)
    thread.start()
    thread.join()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    var thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ;
    thread.start() ;
    thread.join()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, t-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    var _anon : OclAny := null;
    var y : OclAny := null;
    Sequence{_anon,y} := nlargest(2, a) ;
    var ret : OclAny := Set{y - 1, n - 2}->min() ;
    execute (ret)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
t=int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    a.sort(reverse=True)
    ans=min(a[1]-1,n-2)
    print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, t-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    a := a->sort() ;
    var ans : OclAny := Set{a[1+1] - 1, n - 2}->min() ;
    execute (ans)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
s=input()
sens=[[]]
for i in s :
    sens[-1].append(i)
    if i in['.','!','?']:
        sens.append([])
for i in range(len(sens)):
    if sens[i]:
        sens[i]=''.join(sens[i])
        sens[i]=sens[i].strip()
        if len(sens[i])>n :
            print('Impossible')
            exit(0)
sens.pop()
i=0
ans=0
while itoInteger() ;
    var s : String := (OclFile["System.in"]).readLine() ;
    var sens : Sequence := Sequence{ Sequence{} } ;
    for i : s->characters() do ((expr (atom (name sens)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ;
    if (Sequence{'.'}->union(Sequence{'!'}->union(Sequence{ '?' })))->includes(i) then (
      execute ((Sequence{}) : sens)
    ) else skip) ;
    for i : Integer.subrange(0, (sens)->size()-1) do (    if sens[i+1] then (
      sens[i+1] := StringLib.sumStringsWithSeparator((sens[i+1]), '') ;
    sens[i+1] := sens[i+1]->trim() ;
    if ((sens[i+1])->size()->compareTo(n)) > 0 then (
      execute ('Impossible')->display() ;
    exit(0)
    ) else skip
    ) else skip) ;
    sens := sens->front() ;
    var i : int := 0 ;
    var ans : int := 0 ;
    while (i->compareTo((sens)->size())) < 0 do (    var l : int := (sens[i+1])->size() ;
    while (i + 1->compareTo((sens)->size())) < 0 & (l + 1 + (sens[i + 1+1])->size()->compareTo(n)) <= 0 do (    i := i + 1 ;
    l := l + (sens[i+1])->size() + 1) ;
    i := i + 1 ;
    ans := ans + 1) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for u in range(int(input())):
    n,lst,l,r,mid,res=int(input()),list(map(int,input().split())),1,100000,0,0
    while l<=r :
        mid,dem=(l+r)>>1,0
        for x in lst :
            if x>mid : dem+=1
        if dem>1 and n>mid+1 : res,l=mid,mid+1
        else : r=mid-1
    print(res)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for u : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : OclAny := null;
    var lst : OclAny := null;
    var l : OclAny := null;
    var r : OclAny := null;
    var mid : OclAny := null;
    var res : OclAny := null;
    Sequence{n,lst,l,r,mid,res} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),((input().split())->collect( _x | (OclType["int"])->apply(_x) )),1,100000,0,0} ;
    while (l->compareTo(r)) <= 0 do (    var mid : OclAny := null;
    var dem : OclAny := null;
    Sequence{mid,dem} := Sequence{(l + r) /(2->pow(1)),0} ;
    for x : lst do (    if (x->compareTo(mid)) > 0 then (
      dem := dem + 1
    ) else skip) ;
    if dem > 1 & (n->compareTo(mid + 1)) > 0 then  (
      var res : OclAny := null;
    var l : OclAny := null;
    Sequence{res,l} := Sequence{mid,mid + 1}
    )
    else (
      var r : double := mid - 1
      )) ;
    execute (res)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in[0]*int(input()): print(min(int(input())-2,sorted(map(int,input().split()))[-2]-1))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do (    execute (Set{("" + (((OclFile["System.in"]).readLine())))->toInteger() - 2, sorted((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->front()->last() - 1}->min())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def reverseNum(x):
    s=str(x)
    s=s[: :-1]
    return int(s)
def isMysteryNumber(n):
    for i in range(1,n//2+1):
        j=reverseNum(i)
        if i+j==n :
            print(i,j)
            return True
    print("Not a Mystery Number")
    return False
n=121
isMysteryNumber(n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    n := 121 ;
    isMysteryNumber(n);
  operation reverseNum(x : OclAny) : OclAny
  pre: true post: true
  activity:
    var s : String := ("" + ((x))) ;
    s := s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ;
    return ("" + ((s)))->toInteger();
  operation isMysteryNumber(n : OclAny) : OclAny
  pre: true post: true
  activity:
    for i : Integer.subrange(1, n div 2 + 1-1) do (    var j : OclAny := reverseNum(i) ;
    if i + j = n then (
      execute (i)->display() ;
    return true
    ) else skip) ;
    execute ("Not a Mystery Number")->display() ;
    return false;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
solutions=[]
for i in range(t):
    n=int(input())
    arr=list(map(int,input().split()))
    arr.sort()
    subarr=arr[:-1]
    solutions.append(sum(subarr)/len(subarr)+arr[-1])
for x in solutions :
    print(x)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var solutions : Sequence := Sequence{} ;
    for i : Integer.subrange(0, t-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    arr := arr->sort() ;
    var subarr : OclAny := arr->front() ;
    execute (((subarr)->sum() / (subarr)->size() + arr->last()) : solutions)) ;
    for x : solutions do (    execute (x)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for _ in range(t):
    n,x=int(input()),(int(i)for i in input().split())
    a,b=[],next(x)
    for i in x :
        if i>b :
            a.append(b)
            b=i
        else :
            a.append(i)
    print(sum(a)/len(a)+b)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, t-1) do (    var n : OclAny := null;
    var x : OclAny := null;
    Sequence{n,x} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))}} ;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := Sequence{Sequence{},(x).next()} ;
    for i : x do (    if (i->compareTo(b)) > 0 then  (
      execute ((b) : a) ;
    var b : OclAny := i
    )
    else (
      execute ((i) : a)
      )) ;
    execute ((a)->sum() / (a)->size() + b)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def solve():
    n=int(input())
    a=[int(i)for i in input().split()]
    return round(max(a)+(sum(a)-max(a))/(n-1),6)
t=int(input())
ans=[]
while t :
    ans.append(str(solve()))
    t-=1
print("\n".join(ans))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var ans : Sequence := Sequence{} ;
    while t do (    execute ((("" + ((solve())))) : ans) ;
    t := t - 1) ;
    execute (StringLib.sumStringsWithSeparator((ans), "\n"))->display();
  operation solve() : OclAny
  pre: true post: true
  activity:
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    return MathLib.roundN((a)->max() + ((a)->sum() - (a)->max()) / (n - 1), 6);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for _ in range(t):
    n=int(input())
    a=sorted(map(int,input().split()))
    s=a[-1]+sum(a[:-1])/(n-1)
    print(s)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, t-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ;
    var s : OclAny := a->last() + (a->front())->sum() / (n - 1) ;
    execute (s)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def seriesSum(calculated,current,N):
    i=calculated ;
    cur=1 ;
    if(current==N+1):
        return 0 ;
    while(idisplay();;
  operation seriesSum(calculated : OclAny, current : OclAny, N : OclAny)
  pre: true post: true
  activity:
    var i : OclAny := calculated; ;
    var cur : int := 1; ;
    if (current = N + 1) then (
      return 0;
    ) else skip ;
    while ((i->compareTo(calculated + current)) < 0) do (    cur := cur * i; ;
    i := i + 1;) ;
    return cur + seriesSum(i, current + 1, N);;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    input()
    lst=sorted(map(int,input().split()))
    print(lst[-1]+sum(lst[0 :-1])/(len(lst)-1))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    input() ;
    var lst : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ;
    execute (lst->last() + (lst.subrange(0+1, -1))->sum() / ((lst)->size() - 1))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m=map(int,input().split())
x=[]
y=[]
z=[]
for i in range(n):
    a,b,c=map(int,input().split())
    x.append(a)
    y.append(b)
    z.append(c)
ans=-1e18
for i in range(-1,2,2):
    for j in range(-1,2,2):
        for k in range(-1,2,2):
            v=[]
            for l in range(n):
                v.append(x[l]*i+y[l]*j+z[l]*k)
            v.sort()
            v.reverse()
            now=0
            for l in range(m):
                now+=v[l]
            ans=max(ans,now)
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var x : Sequence := Sequence{} ;
    var y : Sequence := Sequence{} ;
    var z : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute ((a) : x) ;
    execute ((b) : y) ;
    execute ((c) : z)) ;
    var ans : double := -("1e18")->toReal() ;
    for i : Integer.subrange(-1, 2-1)->select( $x | ($x - -1) mod 2 = 0 ) do (    for j : Integer.subrange(-1, 2-1)->select( $x | ($x - -1) mod 2 = 0 ) do (    for k : Integer.subrange(-1, 2-1)->select( $x | ($x - -1) mod 2 = 0 ) do (    var v : Sequence := Sequence{} ;
    for l : Integer.subrange(0, n-1) do (    execute ((x[l+1] * i + y[l+1] * j + z[l+1] * k) : v)) ;
    v := v->sort() ;
    v := v->reverse() ;
    var now : int := 0 ;
    for l : Integer.subrange(0, m-1) do (    now := now + v[l+1]) ;
    ans := Set{ans, now}->max()))) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
raw=input().split(" ")
sentences=[]
punctuation={'?','.','!'}
curr=''
for idx in raw :
    curr+=idx
    if(idx[len(idx)-1]in punctuation):
        sentences.append(curr)
        curr=''
    else :
        curr+=' '
bad=False
for idx in sentences :
    if(len(idx)>n):
        bad=True
if(bad):
    print('Impossible')
else :
    currLen=len(sentences[0])
    res=1
    for idx in range(1,len(sentences)):
        if(len(sentences[idx])+currLen+1>n):
            res+=1
            currLen=len(sentences[idx])
        else :
            currLen+=len(sentences[idx])+1
    print(res)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var raw : OclAny := input().split(" ") ;
    var sentences : Sequence := Sequence{} ;
    var punctuation : Set := Set{'?'}->union(Set{'.'}->union(Set{ '!' })) ;
    var curr : String := '' ;
    for idx : raw do (    curr := curr + idx ;
    if ((punctuation)->includes(idx[(idx)->size() - 1+1])) then  (
      execute ((curr) : sentences) ;
    curr := ''
    )
    else (
      curr := curr + ' '
      )) ;
    var bad : boolean := false ;
    for idx : sentences do (    if (((idx)->size()->compareTo(n)) > 0) then (
      bad := true
    ) else skip) ;
    if (bad) then  (
      execute ('Impossible')->display()
    )
    else (
      var currLen : int := (sentences->first())->size() ;
    var res : int := 1 ;
    for idx : Integer.subrange(1, (sentences)->size()-1) do (    if (((sentences[idx+1])->size() + currLen + 1->compareTo(n)) > 0) then  (
      res := res + 1 ;
    currLen := (sentences[idx+1])->size()
    )
    else (
      currLen := currLen + (sentences[idx+1])->size() + 1
      )) ;
    execute (res)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
import itertools
cin=sys.stdin
def line2N():
    return map(int,cin.readline().split())
N,M=line2N()
if M==0 :
    print(0)
    exit(0)
x=[0]*N
y=[0]*N
z=[0]*N
for i in range(N):
    x[i],y[i],z[i]=line2N()
rMax=0
for sx,sy,sz in itertools.product((-1,1),repeat=3):
    s=[sx*xi+sy*yi+sz*zi for xi,yi,zi in zip(x,y,z)]
    s.sort()
    rMax=max(rMax,sum(s[-M :]))
print(rMax)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var cin : OclFile := OclFile["System.in"] ;
    skip ;
    var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := line2N() ;
    if M = 0 then (
      execute (0)->display() ;
    exit(0)
    ) else skip ;
    var x : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ;
    var y : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ;
    var z : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ;
    for i : Integer.subrange(0, N-1) do (    var x[i+1] : OclAny := null;
    var y[i+1] : OclAny := null;
    var z[i+1] : OclAny := null;
    Sequence{x[i+1],y[i+1],z[i+1]} := line2N()) ;
    var rMax : int := 0 ;
    for _tuple : itertools.product(Sequence{-1, 1}, (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (number (integer 3))))))))) do (var _indx : int := 1;
      var sx : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var sy : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var sz : OclAny := _tuple->at(_indx);
      var s : Sequence := Integer.subrange(1, x->size())->collect( _indx | Sequence{x->at(_indx), y->at(_indx)} )->select(_tuple | true)->collect(_tuple | let xi : OclAny = _tuple->at(1) in let yi : OclAny = _tuple->at(2) in (sx * xi + sy * yi + sz * zi)) ;
    s := s->sort() ;
    rMax := Set{rMax, (s.subrange(-M+1))->sum()}->max()) ;
    execute (rMax)->display();
  operation line2N() : OclAny
  pre: true post: true
  activity:
    return (cin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
num=list(map(int,input().split(' ')))
array=[list(map(int,input().split(' ')))for i in range(0,num[0])]
product_array=[[1,1,1],[-1,1,1],[1,-1,1],[1,1,-1],[-1,-1,1],[1,-1,-1],[-1,-1,-1]]
array_result=[[0 for j in range(0,num[1])]for i in range(0,len(product_array))]
for i,product in enumerate(product_array):
    s=[item[0]*product[0]+item[1]*product[1]+item[2]*product[2]for item in array]
    array_result[i]=sorted(range(len(s)),key=lambda k : s[k])[0 : num[1]]
result=0
for i,item in enumerate(array_result):
    total1=0
    total2=0
    total3=0
    for j in range(num[1]):
        total1+=array[item[j]][0]
        total2+=array[item[j]][1]
        total3+=array[item[j]][2]
    total=total1*(1 if total1>0 else-1)+total2*(1 if total2>0 else-1)+total3*(1 if total3>0 else-1)
    result=result if result>total else total
print(result)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var num : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ;
    var array : Sequence := Integer.subrange(0, num->first()-1)->select(i | true)->collect(i | (((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var product_array : Sequence := Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))}->union(Sequence{Sequence{-1}->union(Sequence{1}->union(Sequence{ 1 }))}->union(Sequence{Sequence{1}->union(Sequence{-1}->union(Sequence{ 1 }))}->union(Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{ -1 }))}->union(Sequence{Sequence{-1}->union(Sequence{-1}->union(Sequence{ 1 }))}->union(Sequence{Sequence{1}->union(Sequence{-1}->union(Sequence{ -1 }))}->union(Sequence{ Sequence{-1}->union(Sequence{-1}->union(Sequence{ -1 })) })))))) ;
    var array_result : Sequence := Integer.subrange(0, (product_array)->size()-1)->select(i | true)->collect(i | (Integer.subrange(0, num[1+1]-1)->select(j | true)->collect(j | (0)))) ;
    for _tuple : Integer.subrange(1, (product_array)->size())->collect( _indx | Sequence{_indx-1, (product_array)->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var product : OclAny := _tuple->at(_indx);
      var s : Sequence := array->select(item | true)->collect(item | (item->first() * product->first() + item[1+1] * product[1+1] + item[2+1] * product[2+1])) ;
    array_result[i+1] := sorted(Integer.subrange(0, (s)->size()-1), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name k)))) : (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ]))))))))).subrange(0+1, num[1+1])) ;
    var result : int := 0 ;
    for _tuple : Integer.subrange(1, (array_result)->size())->collect( _indx | Sequence{_indx-1, (array_result)->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var item : OclAny := _tuple->at(_indx);
      var total1 : int := 0 ;
    var total2 : int := 0 ;
    var total3 : int := 0 ;
    for j : Integer.subrange(0, num[1+1]-1) do (    total1 := total1 + array[item[j+1]+1]->first() ;
    total2 := total2 + array[item[j+1]+1][1+1] ;
    total3 := total3 + array[item[j+1]+1][2+1]) ;
    var total : int := total1 * (if total1 > 0 then 1 else -1 endif) + total2 * (if total2 > 0 then 1 else -1 endif) + total3 * (if total3 > 0 then 1 else -1 endif) ;
    result := if (result->compareTo(total)) > 0 then result else total endif) ;
    execute (result)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.buffer.readline
import numpy as np
def main():
    N,M=map(int,input().split())
    point=np.array([list(map(int,input().split()))for _ in range(N)])
    ans=0
    for i in range(2**3):
        pn=np.full(3,1,dtype=int)
        for j in range(3):
            pn[j]=(-1)**(i>>j)
        use=point*pn
        s=np.sum(use,axis=1)
        srev=np.sort(s)[: :-1]
        ans=max(ans,np.sum(srev[: M]))
    print(int(ans))
if __name__=="__main__" :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := sys.stdin.buffer.readline ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var point : Sequence := (Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))) ;
    var ans : int := 0 ;
    for i : Integer.subrange(0, (2)->pow(3)-1) do (    var pn : Sequence := MatrixLib.singleValueMatrix(3, 1) ;
    for j : Integer.subrange(0, 3-1) do (    pn[j+1] := ((-1))->pow((i /(2->pow(j))))) ;
    var use : Sequence := MatrixLib.dotProduct(point,pn) ;
    var s : double := MatrixLib.sumMatrix(use) ;
    var srev : OclAny := np->sort()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ;
    ans := Set{ans, MatrixLib.sumMatrix(srev.subrange(1,M))}->max()) ;
    execute (("" + ((ans)))->toInteger())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    from collections import namedtuple
    from itertools import product
    from operator import mul
    import sys
    input=sys.stdin.readline
    Cake=namedtuple('Cake','x y z')
    N,M=map(int,input().split())
    cakes=[Cake(*map(int,input().split()))for _ in range(N)]
    ans=0
    for signs in product([-1,1],repeat=3):
        e=[]
        for c in cakes :
            e.append(sum(map(mul,c,signs)))
        e.sort(reverse=True)
        ans=max(ans,sum(e[: M]))
    print(ans)
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    skip ;
    skip ;
    skip ;
    skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    var Cake : OclAny := namedtuple('Cake', 'x y z') ;
    var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var cakes : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Cake((argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))))) ;
    var ans : int := 0 ;
    for signs : product(Sequence{-1}->union(Sequence{ 1 }), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (number (integer 3))))))))) do (    var e : Sequence := Sequence{} ;
    for c : cakes do (    execute ((((c)->collect( _x | (mul)->apply(_x) ))->sum()) : e)) ;
    e := e->sort() ;
    ans := Set{ans, (e.subrange(1,M))->sum()}->max()) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
import sys
from collections import deque,OrderedDict,defaultdict
import heapq,re
from collections import Counter
def inp(): return sys.stdin.readline().rstrip()
def mpp(): return map(int,inp().split())
def lis(): return list(mpp())
def yn(n):
    if n :
        return "YES"
    else :
        return "NO"
def cd(s):
    return ord(s)-ord('a')+1
def fn(arr,brr,n):
    cn=0
    s=set(arr+brr)
    for i in range(n):
        for j in range(n):
            if arr[i]^ brr[j]in s :
                cn+=1
    if cn & 1 : return "Koyomi"
    return "Karen"
def main():
    n=int(inp())
    arr=lis()
    brr=lis()
    print(fn(arr,brr,n))
if __name__=="__main__" :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      main()
    ) else skip;
  operation inp() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine().rstrip();
  operation mpp() : OclAny
  pre: true post: true
  activity:
    return (inp().split())->collect( _x | (OclType["int"])->apply(_x) );
  operation lis() : OclAny
  pre: true post: true
  activity:
    return (mpp());
  operation yn(n : OclAny) : OclAny
  pre: true post: true
  activity:
    if n then  (
      return "YES"
    )
    else (
      return "NO"
      );
  operation cd(s : OclAny) : OclAny
  pre: true post: true
  activity:
    return (s)->char2byte() - ('a')->char2byte() + 1;
  operation fn(arr : OclAny, brr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var cn : int := 0 ;
    s := Set{}->union((arr + brr)) ;
    for i : Integer.subrange(0, n-1) do (    for j : Integer.subrange(0, n-1) do (    if (s)->includes(MathLib.bitwiseXor(arr[i+1], brr[j+1])) then (
      cn := cn + 1
    ) else skip)) ;
    if MathLib.bitwiseAnd(cn, 1) then (
      return "Koyomi"
    ) else skip ;
    return "Karen";
  operation main()
  pre: true post: true
  activity:
    n := ("" + ((inp())))->toInteger() ;
    arr := lis() ;
    brr := lis() ;
    execute (fn(arr, brr, n))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import inf
def main(N,A,B,C,D):
    if N==1 :
        return D
    if N in dp :
        return dp[N]
    r=inf
    if N % 2!=0 :
        r=min(A+main(N//2+1,A,B,C,D)+D,A+main(N//2,A,B,C,D)+D,r)
    else :
        r=min(A+main(N//2,A,B,C,D),r)
    if N % 3!=0 :
        r=min(B+main(N//3+1,A,B,C,D)+(3-N % 3)*D,B+main(N//3,A,B,C,D)+(N % 3*D),r)
    else :
        r=min(B+main(N//3,A,B,C,D),r)
    if N % 5!=0 :
        r=min(C+main(N//5+1,A,B,C,D)+(5-N % 5)*D,C+main(N//5,A,B,C,D)+(N % 5*D),r)
    else :
        r=min(C+main(N//5,A,B,C,D),r)
    r=min(N*D,r)
    dp[N]=r
    return r
T=int(input())
q_list=[[int(s)for s in input().split()]for _ in range(T)]
for q in q_list :
    dp={0 : 0}
    print(main(*q))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var q_list : Sequence := Integer.subrange(0, T-1)->select(_anon | true)->collect(_anon | (input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())))) ;
    for q : q_list do (    var dp : Map := Map{ 0 |-> 0 } ;
    execute (main((argument * (test (logical_test (comparison (expr (atom (name q)))))))))->display());
  operation main(N : OclAny, A : OclAny, B : OclAny, C : OclAny, D : OclAny) : OclAny
  pre: true post: true
  activity:
    if N = 1 then (
      return D
    ) else skip ;
    if (dp)->includes(N) then (
      return dp[N+1]
    ) else skip ;
    var r : double := Math_PINFINITY ;
    if N mod 2 /= 0 then  (
      r := Set{A + main(N div 2 + 1, A, B, C, D) + D, A + main(N div 2, A, B, C, D) + D, r}->min()
    )
    else (
      r := Set{A + main(N div 2, A, B, C, D), r}->min()
      ) ;
    if N mod 3 /= 0 then  (
      r := Set{B + main(N div 3 + 1, A, B, C, D) + (3 - N mod 3) * D, B + main(N div 3, A, B, C, D) + (N mod 3 * D), r}->min()
    )
    else (
      r := Set{B + main(N div 3, A, B, C, D), r}->min()
      ) ;
    if N mod 5 /= 0 then  (
      r := Set{C + main(N div 5 + 1, A, B, C, D) + (5 - N mod 5) * D, C + main(N div 5, A, B, C, D) + (N mod 5 * D), r}->min()
    )
    else (
      r := Set{C + main(N div 5, A, B, C, D), r}->min()
      ) ;
    r := Set{N * D, r}->min() ;
    dp[N+1] := r ;
    return r;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10000000)
memo={}
def solve():
    N,A,B,C,D=map(int,input().split())
    global memo
    memo={0 : 0,1 : D}
    return process(N,N,A,B,C,D)
def process(M,N,A,B,C,D):
    global memo
    if M in memo :
        return memo[M]
    res=process((M-M % 2)//2,N,A,B,C,D)+A+(M % 2)*D
    res=min(res,process((M+M % 2)//2,N,A,B,C,D)+A+(M % 2)*D)
    res=min(res,process((M-M % 3)//3,N,A,B,C,D)+B+(M % 3)*D)
    res=min(res,process((M+3-M % 3)//3,N,A,B,C,D)+B+(3-M % 3)*D)
    res=min(res,process((M-M % 5)//5,N,A,B,C,D)+C+(M % 5)*D)
    res=min(res,process((M+5-M % 5)//5,N,A,B,C,D)+C+(5-M % 5)*D)
    res=min(res,M*D)
    memo[M]=res
    return res
def main():
    T=int(input())
    for i in range(T):
        res=solve()
        print(res)
main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  attribute memo : OclAny;
  attribute memo : OclAny;
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    sys.setrecursionlimit(10000000) ;
    var memo : OclAny := Set{} ;
    skip ;
    skip ;
    skip ;
    main();
  operation solve() : OclAny
  pre: true post: true
  activity:
    var N : OclAny := null;
    var A : OclAny := null;
    var B : OclAny := null;
    var C : OclAny := null;
    var D : OclAny := null;
    Sequence{N,A,B,C,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    skip ;
    memo := Map{ 0 |-> 0 }->union(Map{ 1 |-> D }) ;
    return process(N, N, A, B, C, D);
  operation process(M : OclAny, N : OclAny, A : OclAny, B : OclAny, C : OclAny, D : OclAny) : OclAny
  pre: true post: true
  activity:
    skip ;
    if (memo)->includes(M) then (
      return memo[M+1]
    ) else skip ;
    var res : OclAny := process((M - M mod 2) div 2, N, A, B, C, D) + A + (M mod 2) * D ;
    res := Set{res, process((M + M mod 2) div 2, N, A, B, C, D) + A + (M mod 2) * D}->min() ;
    res := Set{res, process((M - M mod 3) div 3, N, A, B, C, D) + B + (M mod 3) * D}->min() ;
    res := Set{res, process((M + 3 - M mod 3) div 3, N, A, B, C, D) + B + (3 - M mod 3) * D}->min() ;
    res := Set{res, process((M - M mod 5) div 5, N, A, B, C, D) + C + (M mod 5) * D}->min() ;
    res := Set{res, process((M + 5 - M mod 5) div 5, N, A, B, C, D) + C + (5 - M mod 5) * D}->min() ;
    res := Set{res, M * D}->min() ;
    memo[M+1] := res ;
    return res;
  operation main()
  pre: true post: true
  activity:
    var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, T-1) do (    res := solve() ;
    execute (res)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
sysread=sys.stdin.buffer.readline
read=sys.stdin.buffer.read
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def run():
    T=int(input())
    for ii in range(T):
        N,A,B,C,D=map(int,input().split())
        stack=[(0,N)]
        min_num=float('inf')
        visited={}
        while stack :
            money,current=heappop(stack)
            if current>N : continue
            if current in visited.keys():
                continue
            visited[current]=0
            if current==0 : break
            for pro,cost in((2,A),(3,B),(5,C)):
                tmp=current % pro
                next_num1=(current-tmp)//pro
                next_num2=(current+pro-tmp)//pro
                cond1=N>=current+pro-tmp
                if pro==2 :
                    heappush(stack,(min(cost,D*next_num1)+tmp*D+money,next_num1))
                    if next_num2!=tmp :
                        heappush(stack,(min((2-tmp)*D+cost+money,(next_num2-tmp)*D+money),next_num2))
                elif pro==3 :
                    heappush(stack,(min(cost,D*(2*next_num1))+tmp*D+money,next_num1))
                    heappush(stack,(min((3-tmp)*D+cost+money,(2*next_num2-3+tmp)*D+money),next_num2))
                else :
                    heappush(stack,(min(cost,D*(4*next_num1))+tmp*D+money,next_num1))
                    heappush(stack,(min((5-tmp)*D+cost+money,(4*next_num2-5+tmp)*D+money),next_num2))
        print(money)
if __name__=="__main__" :
    run()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var sysread : OclAny := sys.stdin.buffer.readline ;
    var read : OclAny := sys.stdin.buffer.read ;
    skip ;
    sys.setrecursionlimit((10)->pow(7)) ;
    skip ;
    if __name__ = "__main__" then (
      run()
    ) else skip;
  operation run()
  pre: true post: true
  activity:
    var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for ii : Integer.subrange(0, T-1) do (    var N : OclAny := null;
    var A : OclAny := null;
    var B : OclAny := null;
    var C : OclAny := null;
    var D : OclAny := null;
    Sequence{N,A,B,C,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var stack : Sequence := Sequence{ Sequence{0, N} } ;
    var min_num : double := ("" + (('inf')))->toReal() ;
    var visited : OclAny := Set{} ;
    while stack do (    var money : OclAny := null;
    var current : OclAny := null;
    Sequence{money,current} := heappop(stack) ;
    if (current->compareTo(N)) > 0 then (
      continue
    ) else skip ;
    if (visited.keys())->includes(current) then (
      continue
    ) else skip ;
    visited[current+1] := 0 ;
    if current = 0 then (
      break
    ) else skip ;
    for _tuple : Sequence{Sequence{2, A}, Sequence{3, B}, Sequence{5, C}} do (var _indx : int := 1;
      var pro : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var cost : OclAny := _tuple->at(_indx);
      var tmp : int := current mod pro ;
    var next_num1 : int := (current - tmp) div pro ;
    var next_num2 : int := (current + pro - tmp) div pro ;
    var cond1 : boolean := (N->compareTo(current + pro - tmp)) >= 0 ;
    if pro = 2 then  (
      heappush(stack, Sequence{Set{cost, D * next_num1}->min() + tmp * D + money, next_num1}) ;
    if next_num2 /= tmp then (
      heappush(stack, Sequence{Set{(2 - tmp) * D + cost + money, (next_num2 - tmp) * D + money}->min(), next_num2})
    ) else skip
    )
    else (if pro = 3 then
   (
      heappush(stack, Sequence{Set{cost, D * (2 * next_num1)}->min() + tmp * D + money, next_num1}) ;
    heappush(stack, Sequence{Set{(3 - tmp) * D + cost + money, (2 * next_num2 - 3 + tmp) * D + money}->min(), next_num2})    
)
    else (
      heappush(stack, Sequence{Set{cost, D * (4 * next_num1)}->min() + tmp * D + money, next_num1}) ;
    heappush(stack, Sequence{Set{(5 - tmp) * D + cost + money, (4 * next_num2 - 5 + tmp) * D + money}->min(), next_num2})
      )    )
)) ;
    execute (money)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def swapOperations(a,b,c):
    l=len(a);
    i=0 ;
    total_swaps=0 ;
    for i in range(l):
        if(a[i]==b[i]):
            continue ;
        if(a[i]==c[i]):
            b[i],c[i]=c[i],b[i];
            total_swaps+=1 ;
            continue ;
        if(b[i]==c[i]):
            a[i],c[i]=c[i],a[i];
            total_swaps+=1 ;
            continue ;
        break ;
    i+=1 ;
    if(i==l):
        print(total_swaps);
    else :
        print(-1);
if __name__=="__main__" :
    a="xyz" ;
    b="yzx" ;
    c="yzx" ;
    swapOperations(list(a),list(b),list(c));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      a := "xyz"; ;
    b := "yzx"; ;
    c := "yzx"; ;
    swapOperations((a), (b), (c));
    ) else skip;
  operation swapOperations(a : OclAny, b : OclAny, c : OclAny)
  pre: true post: true
  activity:
    var l : int := (a)->size(); ;
    var i : int := 0; ;
    var total_swaps : int := 0; ;
    for i : Integer.subrange(0, l-1) do (    if (a[i+1] = b[i+1]) then (
      continue;
    ) else skip ;
    if (a[i+1] = c[i+1]) then (
      var b[i+1] : OclAny := null;
    var c[i+1] : OclAny := null;
    Sequence{b[i+1],c[i+1]} := Sequence{c[i+1],b[i+1]}; ;
    total_swaps := total_swaps + 1; ;
    continue;
    ) else skip ;
    if (b[i+1] = c[i+1]) then (
      var a[i+1] : OclAny := null;
    var c[i+1] : OclAny := null;
    Sequence{a[i+1],c[i+1]} := Sequence{c[i+1],a[i+1]}; ;
    total_swaps := total_swaps + 1; ;
    continue;
    ) else skip ;
    break;) ;
    i := i + 1; ;
    if (i = l) then  (
      execute (total_swaps)->display();
    )
    else (
      execute (-1)->display();
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=2,3,5
def f(n):
    m=memo.get(n)
    if m is None :
        m=d*n
        for p,c in zip(a,b):
            m=min(m,*(f(k)+abs(p*k-n)*d+c for k in{n//p,-(-n//p)}))
        memo[n]=m
    return m
t=int(input())
for _ in range(t):
    n,*b,d=map(int,input().split())
    memo={0 : 0,1 : d}
    print(f(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := 2,3,5 ;
    skip ;
    var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, t-1) do (    var b : OclAny := null;
    var d : OclAny := null;
    Sequence{n,b,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var memo : Map := Map{ 0 |-> 0 }->union(Map{ 1 |-> d }) ;
    execute (f(n))->display());
  operation f(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var m : OclAny := memo.get(n) ;
    if m <>= null then (
      m := d * n ;
    for _tuple : Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), b->at(_indx)} ) do (var _indx : int := 1;
      var p : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var c : OclAny := _tuple->at(_indx);
      m := Set{m, (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name f)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name k)))))))) )))) + (expr (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name p))) * (expr (atom (name k)))) - (expr (atom (name n))))))))) )))) * (expr (atom (name d))))) + (expr (atom (name c))))))) (comp_for for (exprlist (expr (atom (name k)))) in (logical_test (comparison (expr (atom { (dictorsetmaker (testlist_comp (test (logical_test (comparison (expr (expr (atom (name n))) // (expr (atom (name p))))))) , (test (logical_test (comparison (expr - (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr - (expr (atom (name n)))) // (expr (atom (name p)))))))) ))))))))) })))))) )))))))}->min()) ;
    memo[n+1] := m
    ) else skip ;
    return m;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import re
n=int(input())
ans,sumL=1,0
for s in re.split("[.?!]",input()):
    s=s.strip()+'.'
    L=len(s)
    if L>1 :
        if L>n :
            print("Impossible")
            exit()
        if sumL+L+(sumL>0)>n :
            ans+=1
            sumL=L
        else :
            sumL=sumL+L+(sumL>0)
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var ans : OclAny := null;
    var sumL : OclAny := null;
    Sequence{ans,sumL} := Sequence{1,0} ;
    for s : ((OclFile["System.in"]).readLine())->split("[.?!]") do (    var s : String := s->trim() + '.' ;
    var L : int := (s)->size() ;
    if L > 1 then (
      if (L->compareTo(n)) > 0 then (
      execute ("Impossible")->display() ;
    exit()
    ) else skip ;
    if (sumL + L + (sumL > 0)->compareTo(n)) > 0 then  (
      ans := ans + 1 ;
    var sumL : int := L
    )
    else (
      sumL := sumL + L + (sumL > 0)
      )
    ) else skip) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
sys.setrecursionlimit(10000)
T=int(input())
a=[list(map(int,input().split()))for _ in range(T)]
memo={}
def solve(N,A,B,C,D):
    if N==0 :
        return 0
    if N==1 :
        return D
    if N in memo :
        return memo[N]
    ans=min(D*N,(N-2*(N//2))*D+A+solve(N//2,A,B,C,D),(2*((N+1)//2)-N)*D+A+solve((N+1)//2,A,B,C,D),(N-3*(N//3))*D+B+solve(N//3,A,B,C,D),(3*((N+2)//3)-N)*D+B+solve((N+2)//3,A,B,C,D),(N-5*(N//5))*D+C+solve(N//5,A,B,C,D),(5*((N+4)//5)-N)*D+C+solve((N+4)//5,A,B,C,D),)
    memo[N]=ans
    return ans
for i in range(T):
    memo={}
(N,A,B,C,D)=a[i]
    print(solve(N,A,B,C,D))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    sys.setrecursionlimit(10000) ;
    var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := Integer.subrange(0, T-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var memo : OclAny := Set{} ;
    skip ;
    for i : Integer.subrange(0, T-1) do (    memo := Set{}) ;
    var Sequence{N, A, B, C, D} : OclAny := a[i+1];
  operation solve(N : OclAny, A : OclAny, B : OclAny, C : OclAny, D : OclAny) : OclAny
  pre: true post: true
  activity:
    if N = 0 then (
      return 0
    ) else skip ;
    if N = 1 then (
      return D
    ) else skip ;
    if (memo)->includes(N) then (
      return memo[N+1]
    ) else skip ;
    var ans : OclAny := Set{D * N, (N - 2 * (N div 2)) * D + A + solve(N div 2, A, B, C, D), (2 * ((N + 1) div 2) - N) * D + A + solve((N + 1) div 2, A, B, C, D), (N - 3 * (N div 3)) * D + B + solve(N div 3, A, B, C, D), (3 * ((N + 2) div 3) - N) * D + B + solve((N + 2) div 3, A, B, C, D), (N - 5 * (N div 5)) * D + C + solve(N div 5, A, B, C, D), (arglist (argument (test (logical_test (comparison (expr (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (number (integer 5)))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name N))) + (expr (atom (number (integer 4))))))))) ))) // (expr (atom (number (integer 5))))))))) )))) - (expr (atom (name N)))))))) ))) * (expr (atom (name D)))) + (expr (atom (name C)))) + (expr (atom (name solve)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name N))) + (expr (atom (number (integer 4))))))))) ))) // (expr (atom (number (integer 5))))))))) , (argument (test (logical_test (comparison (expr (atom (name A))))))) , (argument (test (logical_test (comparison (expr (atom (name B))))))) , (argument (test (logical_test (comparison (expr (atom (name C))))))) , (argument (test (logical_test (comparison (expr (atom (name D)))))))) ))))))))) ,)}->min() ;
    memo[N+1] := ans ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    n,x=list(map(int,input().split()))
    A=list(map(int,input().split()))
    B=[min(A[0],x),]
    for i in range(n-1):
        if B[i]+A[i+1]>x :
            B.append(x-B[i])
        else :
            B.append(A[i+1])
    ans=sum([a-b for a,b in zip(A,B)])
    print(ans)
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var n : OclAny := null;
    var x : OclAny := null;
    Sequence{n,x} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var B : Sequence := Sequence{ Set{A->first(), x}->min() } ;
    for i : Integer.subrange(0, n - 1-1) do (    if (B[i+1] + A[i + 1+1]->compareTo(x)) > 0 then  (
      execute ((x - B[i+1]) : B)
    )
    else (
      execute ((A[i + 1+1]) : B)
      )) ;
    var ans : OclAny := (Integer.subrange(1, A->size())->collect( _indx | Sequence{A->at(_indx), B->at(_indx)} )->select(_tuple | true)->collect(_tuple | let a : OclAny = _tuple->at(1) in let b : OclAny = _tuple->at(2) in (a - b)))->sum() ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,x=[int(i)for i in input().split()]
A=[int(i)for i in input().split()]
cnt=0
for i in range(n-1):
    a=(A[i]+A[i+1])-x
    if a>0 :
        b=A[i+1]-a
        if b<0 :
            cnt+=a
            A[i+1]=0
            A[i]+=b
        else :
            cnt+=a
            A[i+1]-=a
print(cnt)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var x : OclAny := null;
    Sequence{n,x} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var A : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var cnt : int := 0 ;
    for i : Integer.subrange(0, n - 1-1) do (    var a : double := (A[i+1] + A[i + 1+1]) - x ;
    if a > 0 then (
      var b : double := A[i + 1+1] - a ;
    if b < 0 then  (
      cnt := cnt + a ;
    A[i + 1+1] := 0 ;
    A[i+1] := A[i+1] + b
    )
    else (
      cnt := cnt + a ;
    A[i + 1+1] := A[i + 1+1] - a
      )
    ) else skip) ;
    execute (cnt)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def eat(i,j,candies,counter):
    s=candies[i]+candies[j]
    if s>x :
        if candies[i]>=s-x :
            candies[i]-=s-x
        else :
            candies[j]-=s-x-candies[i]
            candies[i]=0
        counter+=s-x
    return counter
def main(n,x,candies):
    counter=0
    for i in range(1,n):
        counter=eat(i,i-1,candies,counter)
    return counter
n,x=map(int,sys.stdin.readline().strip().split())
candies=list(map(int,sys.stdin.readline().strip().split()))
print(main(n,x,candies))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    Sequence{n,x} := (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    candies := ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute (main(n, x, candies))->display();
  operation eat(i : OclAny, j : OclAny, candies : OclAny, counter : OclAny) : OclAny
  pre: true post: true
  activity:
    var s : OclAny := candies[i+1] + candies[j+1] ;
    if (s->compareTo(x)) > 0 then (
      if (candies[i+1]->compareTo(s - x)) >= 0 then  (
      candies[i+1] := candies[i+1] - s - x
    )
    else (
      candies[j+1] := candies[j+1] - s - x - candies[i+1] ;
    candies[i+1] := 0
      ) ;
    counter := counter + s - x
    ) else skip ;
    return counter;
  operation main(n : OclAny, x : OclAny, candies : OclAny) : OclAny
  pre: true post: true
  activity:
    counter := 0 ;
    for i : Integer.subrange(1, n-1) do (    counter := eat(i, i - 1, candies, counter)) ;
    return counter;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import collections
import sys
N,x=map(int,input().split())
A_lis=list(map(int,input().split()))
A_q=collections.deque(A_lis)
sys.setrecursionlimit(10**9)
con=0
tmp1=A_q.popleft()
for i in range(N-1):
    tmp2=A_q.popleft()
    if tmp1+tmp2>x :
        con+=int((tmp1+tmp2)-x)
        tmp1=max(0,x-tmp1)
    else :
        tmp1=tmp2
print(con)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var N : OclAny := null;
    var x : OclAny := null;
    Sequence{N,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var A_lis : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var A_q : Sequence := (A_lis) ;
    sys.setrecursionlimit((10)->pow(9)) ;
    var con : int := 0 ;
    var tmp1 : OclAny := A_q->first() ;     A_q := A_q->tail() ;
    for i : Integer.subrange(0, N - 1-1) do (    var tmp2 : OclAny := A_q->first() ;     A_q := A_q->tail() ;
    if (tmp1 + tmp2->compareTo(x)) > 0 then  (
      con := con + ("" + (((tmp1 + tmp2) - x)))->toInteger() ;
    tmp1 := Set{0, x - tmp1}->max()
    )
    else (
      tmp1 := tmp2
      )) ;
    execute (con)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for i in range(1,len(a)):
    if a[i-1]+a[i]>x :
        if a[i]>0 :
            if(a[i-1]+a[i]-x)>a[i]:
                ans+=a[i]
                a[i]=0
            else :
                ans+=(a[i-1]+a[i]-x)
                a[i]=a[i]-(a[i-1]+a[i]-x)
        if a[i-1]+a[i]>x :
            if(a[i-1]+a[i]-x)>a[i-1]:
                ans+=a[i-1]
                a[i-1]=0
            else :
                ans+=(a[i-1]+a[i]-x)
                a[i-1]=a[i-1]-(a[i-1]+a[i]-x)
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : OclAny := null;
    var x : OclAny := null;
    Sequence{N,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var ans : int := 0 ;
    for i : Integer.subrange(1, (a)->size()-1) do (    if (a[i - 1+1] + a[i+1]->compareTo(x)) > 0 then (
      if a[i+1] > 0 then (
      if ((a[i - 1+1] + a[i+1] - x)->compareTo(a[i+1])) > 0 then  (
      ans := ans + a[i+1] ;
    a[i+1] := 0
    )
    else (
      ans := ans + (a[i - 1+1] + a[i+1] - x) ;
    a[i+1] := a[i+1] - (a[i - 1+1] + a[i+1] - x)
      )
    ) else skip ;
    if (a[i - 1+1] + a[i+1]->compareTo(x)) > 0 then (
      if ((a[i - 1+1] + a[i+1] - x)->compareTo(a[i - 1+1])) > 0 then  (
      ans := ans + a[i - 1+1] ;
    a[i - 1+1] := 0
    )
    else (
      ans := ans + (a[i - 1+1] + a[i+1] - x) ;
    a[i - 1+1] := a[i - 1+1] - (a[i - 1+1] + a[i+1] - x)
      )
    ) else skip
    ) else skip) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def findLength(string):
    n=len(string)
    maxlen=0
    Sum=[[0 for x in range(n)]for y in range(n)]
    for i in range(0,n):
        Sum[i][i]=int(string[i])
    for length in range(2,n+1):
        for i in range(0,n-length+1):
            j=i+length-1
            k=length//2
            Sum[i][j]=(Sum[i][j-k]+Sum[j-k+1][j])
            if(length % 2==0 and Sum[i][j-k]==Sum[(j-k+1)][j]and length>maxlen):
                maxlen=length
    return maxlen
if __name__=="__main__" :
    string="153803"
    print("Length of the substring is",findLength(string))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      string := "153803" ;
    execute ("Length of the substring is")->display()
    ) else skip;
  operation findLength(string : OclAny) : OclAny
  pre: true post: true
  activity:
    var n : int := (string)->size() ;
    var maxlen : int := 0 ;
    var Sum : Sequence := Integer.subrange(0, n-1)->select(y | true)->collect(y | (Integer.subrange(0, n-1)->select(x | true)->collect(x | (0)))) ;
    for i : Integer.subrange(0, n-1) do (    Sum[i+1][i+1] := ("" + ((string[i+1])))->toInteger()) ;
    for length : Integer.subrange(2, n + 1-1) do (    for i : Integer.subrange(0, n - length + 1-1) do (    var j : double := i + length - 1 ;
    var k : int := length div 2 ;
    Sum[i+1][j+1] := (Sum[i+1][j - k+1] + Sum[j - k + 1+1][j+1]) ;
    if (length mod 2 = 0 & Sum[i+1][j - k+1] = Sum[(j - k + 1)+1][j+1] & (length->compareTo(maxlen)) > 0) then (
      maxlen := length
    ) else skip)) ;
    return maxlen;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def countSubstr(s,k):
    n=len(s)
    l=n-1
    r=n-1
    arr=[0]*n
    last_indexof1=-1
    for i in range(n):
        if(s[i]=='1'):
            arr[i]=i
            last_indexof1=i
        else :
            arr[i]=last_indexof1
    no_of_substr=0
    for r in range(n-1,-1,-1):
        l=r
        while(l>=0 and(r-l+1)<=64 and int(s[l : r+1],2)display();
  operation countSubstr(s : OclAny, k : OclAny) : OclAny
  pre: true post: true
  activity:
    var n : int := (s)->size() ;
    var l : double := n - 1 ;
    var r : double := n - 1 ;
    var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ;
    var last_indexof1 : int := -1 ;
    for i : Integer.subrange(0, n-1) do (    if (s[i+1] = '1') then  (
      arr[i+1] := i ;
    last_indexof1 := i
    )
    else (
      arr[i+1] := last_indexof1
      )) ;
    var no_of_substr : int := 0 ;
    for r : Integer.subrange(-1 + 1, n - 1)->reverse() do (    l := r ;
    while (l >= 0 & (r - l + 1) <= 64 & (("" + ((s.subrange(l+1, r + 1), 2)))->toInteger()->compareTo(k)) < 0) do (    l := l - 1) ;
    if (r - l + 1 <= 64) then  (
      no_of_substr := no_of_substr + l + 1
    )
    else (
      no_of_substr := no_of_substr + arr[l + 1+1] + 1
      )) ;
    return no_of_substr;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
DP_s=9
def getNumStrictMonotone(ln):
    DP=[[0]*DP_s for _ in range(ln)]
    for i in range(DP_s):
        DP[0][i]=i+1
    for i in range(1,ln):
        for j in range(1,DP_s):
            DP[i][j]=DP[i-1][j-1]+DP[i][j-1]
    return DP[ln-1][DP_s-1]
print(getNumStrictMonotone(2))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var DP_s : int := 9 ;
    skip ;
    execute (getNumStrictMonotone(2))->display();
  operation getNumStrictMonotone(ln : OclAny) : OclAny
  pre: true post: true
  activity:
    var DP : Sequence := Integer.subrange(0, ln-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, DP_s))) ;
    for i : Integer.subrange(0, DP_s-1) do (    DP->first()[i+1] := i + 1) ;
    for i : Integer.subrange(1, ln-1) do (    for j : Integer.subrange(1, DP_s-1) do (    DP[i+1][j+1] := DP[i - 1+1][j - 1+1] + DP[i+1][j - 1+1])) ;
    return DP[ln - 1+1][DP_s - 1+1];
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while 1 :
    m,f,r=map(int,input().split()); s=m+f
    if m==f==r==-1 : break
    if m*f<-1 or s<30 : print('F')
    elif s<50 and r<50 : print('D')
    elif s<65 : print('C')
    elif s<80 : print('B')
    else : print('A')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while 1 do (    var m : OclAny := null;
    var f : OclAny := null;
    var r : OclAny := null;
    Sequence{m,f,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) );    var s : OclAny := m + f ;
    if m = f & (f == r) & (r == -1) then (
      break
    ) else skip ;
    if m * f < -1 or s < 30 then  (
      execute ('F')->display()
    )
    else (if s < 50 & r < 50 then
   (
      execute ('D')->display()    
)
    else (if s < 65 then
   (
      execute ('C')->display()    
)
    else (if s < 80 then
   (
      execute ('B')->display()    
)
    else (
      execute ('A')->display()
      )    )
    )
    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a=input()
b=[]
c=''
a1=len(a)
i=0
while in :
        if e==0 or i>n :
            print('Impossible')
            break
        e=0
        f=1
        d+=1
    else :
        f+=1
    e+=i
else :
    print(d+1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : String := (OclFile["System.in"]).readLine() ;
    var b : Sequence := Sequence{} ;
    var c : String := '' ;
    var a1 : int := (a)->size() ;
    var i : int := 0 ;
    while (i->compareTo((a)->size())) < 0 do (    c := c + a[i+1] ;
    if (Sequence{'.'}->union(Sequence{'?'}->union(Sequence{ '!' })))->includes(a[i+1]) then (
      execute (((c)->size()) : b) ;
    c := '' ;
    i := i + 1
    ) else skip ;
    i := i + 1) ;
    var d : int := 0 ;
    var e : int := 0 ;
    var f : int := 0 ;
(compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name b))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (expr (atom (name e))) + (expr (atom (name i)))) + (expr (atom (name f))))) > (comparison (expr (atom (name n))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name e)))) == (comparison (expr (atom (number (integer 0))))))) or (logical_test (comparison (comparison (expr (atom (name i)))) > (comparison (expr (atom (name n)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'Impossible'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name e)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name f)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name f)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name e)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name i)))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name d))) + (expr (atom (number (integer 1)))))))))) )))))))))))))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def numberOfSubarrays(arr,n):
    v=[0]*(n+1)
    for i in range(n):
        v[i+1]=v[i]+arr[i]
    mp={}
    begin,end,answer=0,0,0
    mp[0]=1
    while(beginunion(Sequence{4}->union(Sequence{ -6 })) ;
    var size : int := (arr)->size() ;
    numberOfSubarrays(arr, size)
    ) else skip;
  operation numberOfSubarrays(arr : OclAny, n : OclAny)
  pre: true post: true
  activity:
    var v : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ;
    for i : Integer.subrange(0, n-1) do (    v[i + 1+1] := v[i+1] + arr[i+1]) ;
    var mp : OclAny := Set{} ;
    var begin : OclAny := null;
    var end : OclAny := null;
    var answer : OclAny := null;
    Sequence{begin,end,answer} := Sequence{0,0,0} ;
    mp->first() := 1 ;
    while ((begin->compareTo(n)) < 0) do (    while ((end->compareTo(n)) < 0 & (mp)->excludes((v[end + 1+1]))) do (    end := end + 1 ;
    mp[v[end+1]+1] := 1) ;
    var answer : double := answer + end - begin ;
    execute (mp[v[begin+1]+1])->isDeleted() ;
    begin := begin + 1) ;
    execute (answer)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
x=y=0
n,_=map(int,input().split())
for i in range(n):
    for j,ch in enumerate(input()):
        if ch=='*' :
            x,y=x ^ i,y ^ j
print(x+1,y+1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var x : OclAny := 0; var y : int := 0 ;
    var n : OclAny := null;
    var _anon : OclAny := null;
    Sequence{n,_anon} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    for i : Integer.subrange(0, n-1) do (    for _tuple : Integer.subrange(1, ((OclFile["System.in"]).readLine())->size())->collect( _indx | Sequence{_indx-1, ((OclFile["System.in"]).readLine())->at(_indx)} ) do (var _indx : int := 1;
      var j : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var ch : OclAny := _tuple->at(_indx);
      if ch = '*' then (
      Sequence{x,y} := Sequence{MathLib.bitwiseXor(x, i),MathLib.bitwiseXor(y, j)}
    ) else skip)) ;
    execute (x + 1)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m=map(int,input().split())
s1=[]
for i in range(n):
    for j in range(1):
        s1.append(list(input()))
y=[]
r=0
c=0
for i in s1 :
    r+=1
    c=0
    for j in i :
        c+=1
        if j=="*" :
            y.append(r)
            y.append(c)
ss=0
r12=0
if y[0]==y[2]or y[0]==y[4]:
    ss+=1
else :
    r12=y[0]
if y[2]==y[0]or y[2]==y[4]:
    ss+=1
else :
    r12=y[2]
if y[4]==y[0]or y[4]==y[2]:
    ss+=1
else :
    r12=y[4]
c12=0
if y[1]==y[3]or y[1]==y[5]:
    ss+=1
else :
    c12=y[1]
if y[3]==y[1]or y[3]==y[5]:
    ss+=1
else :
    c12=y[3]
if y[5]==y[1]or y[5]==y[3]:
    ss+=1
else :
    c12=y[5]
print(r12,c12)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var s1 : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    for j : Integer.subrange(0, 1-1) do (    execute ((((OclFile["System.in"]).readLine())->characters()) : s1))) ;
    var y : Sequence := Sequence{} ;
    var r : int := 0 ;
    var c : int := 0 ;
    for i : s1 do (    r := r + 1 ;
    c := 0 ;
    for j : i do (    c := c + 1 ;
    if j = "*" then (
      execute ((r) : y) ;
    execute ((c) : y)
    ) else skip)) ;
    var ss : int := 0 ;
    var r12 : int := 0 ;
    if y->first() = y[2+1] or y->first() = y[4+1] then  (
      ss := ss + 1
    )
    else (
      r12 := y->first()
      ) ;
    if y[2+1] = y->first() or y[2+1] = y[4+1] then  (
      ss := ss + 1
    )
    else (
      r12 := y[2+1]
      ) ;
    if y[4+1] = y->first() or y[4+1] = y[2+1] then  (
      ss := ss + 1
    )
    else (
      r12 := y[4+1]
      ) ;
    var c12 : int := 0 ;
    if y[1+1] = y[3+1] or y[1+1] = y[5+1] then  (
      ss := ss + 1
    )
    else (
      c12 := y[1+1]
      ) ;
    if y[3+1] = y[1+1] or y[3+1] = y[5+1] then  (
      ss := ss + 1
    )
    else (
      c12 := y[3+1]
      ) ;
    if y[5+1] = y[1+1] or y[5+1] = y[3+1] then  (
      ss := ss + 1
    )
    else (
      c12 := y[5+1]
      ) ;
    execute (r12)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def lessFrequent(arr):
    arr=sorted(arr)
    l=arr.count(arr[0])
    return arr[0]if l==1 else arr[-1]
n,m=map(int,input().split())
xs=[]
ys=[]
for x in range(0,n):
    row=list(input())
    for y in range(0,m):
        if row[y]=='*' :
            xs.append(x)
            ys.append(y)
print(lessFrequent(xs)+1,lessFrequent(ys)+1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var xs : Sequence := Sequence{} ;
    var ys : Sequence := Sequence{} ;
    for x : Integer.subrange(0, n-1) do (    var row : Sequence := ((OclFile["System.in"]).readLine())->characters() ;
    for y : Integer.subrange(0, m-1) do (    if row[y+1] = '*' then (
      execute ((x) : xs) ;
    execute ((y) : ys)
    ) else skip)) ;
    execute (lessFrequent(xs) + 1)->display();
  operation lessFrequent(arr : OclAny) : OclAny
  pre: true post: true
  activity:
    arr := arr->sort() ;
    var l : int := arr->count(arr->first()) ;
    return if l = 1 then arr->first() else arr->last() endif;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s=input()
s=s.split()
n=int(s[0])
m=int(s[1])
grid=[]
for i in range(n):
    row=input()
    row=list(row)
    grid.append(row)
positions=[]
r=[]
c=[]
for y in range(n):
    for x in range(m):
        if grid[y][x]=="*" :
            r.append(y)
            c.append(x)
out=""
if r[0]==r[1]:
    out+=str(r[2]+1)
elif r[0]==r[2]:
    out+=str(r[1]+1)
else :
    out+=str(r[0]+1)
out+=" "
if c[0]==c[1]:
    out+=str(c[2]+1)
elif c[0]==c[2]:
    out+=str(c[1]+1)
else :
    out+=str(c[0]+1)
print(out)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : String := (OclFile["System.in"]).readLine() ;
    s := s.split() ;
    var n : int := ("" + ((s->first())))->toInteger() ;
    var m : int := ("" + ((s[1+1])))->toInteger() ;
    var grid : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    var row : String := (OclFile["System.in"]).readLine() ;
    row := (row)->characters() ;
    execute ((row) : grid)) ;
    var positions : Sequence := Sequence{} ;
    var r : Sequence := Sequence{} ;
    var c : Sequence := Sequence{} ;
    for y : Integer.subrange(0, n-1) do (    for x : Integer.subrange(0, m-1) do (    if grid[y+1][x+1] = "*" then (
      execute ((y) : r) ;
    execute ((x) : c)
    ) else skip)) ;
    var out : String := "" ;
    if r->first() = r[1+1] then  (
      out := out + ("" + ((r[2+1] + 1)))
    )
    else (if r->first() = r[2+1] then
   (
      out := out + ("" + ((r[1+1] + 1)))    
)
    else (
      out := out + ("" + ((r->first() + 1)))
      )    )
 ;
    out := out + " " ;
    if c->first() = c[1+1] then  (
      out := out + ("" + ((c[2+1] + 1)))
    )
    else (if c->first() = c[2+1] then
   (
      out := out + ("" + ((c[1+1] + 1)))    
)
    else (
      out := out + ("" + ((c->first() + 1)))
      )    )
 ;
    execute (out)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m=map(int,input().split())
c=[]
f1,f2=False,False
for i in range(n):
    a=input()
    if a.count("*")==1 :
        r1=i
        c1=a.find("*")
        f1=True
    elif a.count("*")==2 :
        r2=i
        f2=True
    c.append(a)
    if f1 and f2 :
        break
for x in range(m):
    if c[r2][x]=="*" :
        if x!=c1 :
            c2=x
            break
print("{}{}".format(r1+1,c2+1))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var c : Sequence := Sequence{} ;
    var f1 : OclAny := null;
    var f2 : OclAny := null;
    Sequence{f1,f2} := Sequence{false,false} ;
    for i : Integer.subrange(0, n-1) do (    var a : String := (OclFile["System.in"]).readLine() ;
    if a->count("*") = 1 then  (
      var r1 : OclAny := i ;
    var c1 : int := a->indexOf("*") - 1 ;
    var f1 : boolean := true
    )
    else (if a->count("*") = 2 then
   (
      var r2 : OclAny := i ;
    var f2 : boolean := true    
)
 else skip) ;
    execute ((a) : c) ;
    if f1 & f2 then (
      break
    ) else skip) ;
    for x : Integer.subrange(0, m-1) do (    if c[r2+1][x+1] = "*" then (
      if x /= c1 then (
      var c2 : OclAny := x ;
    break
    ) else skip
    ) else skip) ;
    execute (StringLib.interpolateStrings("{}{}", Sequence{r1 + 1, c2 + 1}))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import numpy as np
def findMax(a,n):
    dp=np.zeros((n,2));
    dp[0][0]=a[0]+a[1];
    dp[0][1]=a[0]*a[1];
    for i in range(1,n-1):
        dp[i][0]=max(dp[i-1][0],dp[i-1][1])+a[i+1];
        dp[i][1]=dp[i-1][0]-a[i]+a[i]*a[i+1];
    print(max(dp[n-2][0],dp[n-2][1]),end="");
if __name__=="__main__" :
    arr=[5,-1,-5,-3,2,9,-4];
    findMax(arr,7);
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      var arr : Sequence := Sequence{5}->union(Sequence{-1}->union(Sequence{-5}->union(Sequence{-3}->union(Sequence{2}->union(Sequence{9}->union(Sequence{ -4 })))))); ;
    findMax(arr, 7);
    ) else skip;
  operation findMax(a : OclAny, n : OclAny)
  pre: true post: true
  activity:
    var dp : Sequence := MatrixLib.singleValueMatrix(Sequence{n, 2}, 0.0); ;
    dp->first()->first() := a->first() + a[1+1]; ;
    dp->first()[1+1] := a->first() * a[1+1]; ;
    for i : Integer.subrange(1, n - 1-1) do (    dp[i+1]->first() := Set{dp[i - 1+1]->first(), dp[i - 1+1][1+1]}->max() + a[i + 1+1]; ;
    dp[i+1][1+1] := dp[i - 1+1]->first() - a[i+1] + a[i+1] * a[i + 1+1];) ;
    execute (Set{dp[n - 2+1]->first(), dp[n - 2+1][1+1]}->max())->display();;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
class pair :
    def __init__(self):
        self.min=0
        self.max=0
def getMinMax(arr : list,n : int)->pair :
    minmax=pair()
    if n==1 :
        minmax.max=arr[0]
        minmax.min=arr[0]
        return minmax
    if arr[0]>arr[1]:
        minmax.max=arr[0]
        minmax.min=arr[1]
    else :
        minmax.max=arr[1]
        minmax.min=arr[0]
    for i in range(2,n):
        if arr[i]>minmax.max :
            minmax.max=arr[i]
        elif arr[i]exists( _x | result = _x );
  attribute min : int := 0;
  attribute max : int := 0;
  operation initialise() : pair
  pre: true post: true
  activity:
    self.min := 0 ;
    self.max := 0;
    return self;
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      var arr : Sequence := Sequence{1000}->union(Sequence{11}->union(Sequence{445}->union(Sequence{1}->union(Sequence{330}->union(Sequence{ 3000 }))))) ;
    var arr_size : int := 6 ;
    minmax := getMinMax(arr, arr_size) ;
    execute ("Minimum element is")->display() ;
    execute ("Maximum element is")->display()
    ) else skip;
  operation getMinMax(arr : Sequence(OclAny), n : int) : OclAny
  pre: true post: true
  activity:
    var minmax : pair := (pair.newpair()).initialise() ;
    if n = 1 then (
      minmax.max := arr->first() ;
    minmax.min := arr->first() ;
    return minmax
    ) else skip ;
    if (arr->first()->compareTo(arr[1+1])) > 0 then  (
      minmax.max := arr->first() ;
    minmax.min := arr[1+1]
    )
    else (
      minmax.max := arr[1+1] ;
    minmax.min := arr->first()
      ) ;
    for i : Integer.subrange(2, n-1) do (    if (arr[i+1]->compareTo(minmax.max)) > 0 then  (
      minmax.max := arr[i+1]
    )
    else (if (arr[i+1]->compareTo(minmax.min)) < 0 then
   (
      minmax.min := arr[i+1]    
)
 else skip)) ;
    return minmax;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def getMinMax(arr):
    n=len(arr)
    if(n % 2==0):
        mx=max(arr[0],arr[1])
        mn=min(arr[0],arr[1])
        i=2
    else :
        mx=mn=arr[0]
        i=1
    while(iunion(Sequence{11}->union(Sequence{445}->union(Sequence{1}->union(Sequence{330}->union(Sequence{ 3000 }))))) ;
    Sequence{mx,mn} := getMinMax(arr) ;
    execute ("Minimum element is")->display() ;
    execute ("Maximum element is")->display()
    ) else skip;
  operation getMinMax(arr : OclAny) : OclAny
  pre: true post: true
  activity:
    var n : int := (arr)->size() ;
    if (n mod 2 = 0) then  (
      var mx : OclAny := Set{arr->first(), arr[1+1]}->max() ;
    var mn : OclAny := Set{arr->first(), arr[1+1]}->min() ;
    var i : int := 2
    )
    else (
      mx := arr->first(); mn := arr->first() ;
    i := 1
      ) ;
    while ((i->compareTo(n - 1)) < 0) do (    if (arr[i+1]->compareTo(arr[i + 1+1])) < 0 then  (
      mx := Set{mx, arr[i + 1+1]}->max() ;
    mn := Set{mn, arr[i+1]}->min()
    )
    else (
      mx := Set{mx, arr[i+1]}->max() ;
    mn := Set{mn, arr[i + 1+1]}->min()
      ) ;
    i := i + 2) ;
    return Sequence{mx, mn};
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def findpair(l,r):
    ans1=l
    ans2=2*l
    print(ans1,",",ans2)
if __name__=='__main__' :
    l,r=1,10
    findpair(l,r)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      Sequence{l,r} := Sequence{1,10} ;
    findpair(l, r)
    ) else skip;
  operation findpair(l : OclAny, r : OclAny)
  pre: true post: true
  activity:
    var ans1 : OclAny := l ;
    var ans2 : double := 2 * l ;
    execute (ans1)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import collections
def GetMinimumEnergySpent(n,shortcuts):
    energy_spent=[i for i in range(n)]
    queue=collections.deque(energy_spent)
    while len(queue)>0 :
        idx=queue.popleft()
        if idxenergy_spent[idx]+1 :
            energy_spent[idx+1]=energy_spent[idx]+1
            queue.append(idx+1)
        if idx>0 and energy_spent[idx-1]>energy_spent[idx]+1 :
            energy_spent[idx-1]=energy_spent[idx]+1
            queue.append(idx-1)
        if energy_spent[idx]+1toInteger() ;
    shortcuts := input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger() - 1)) ;
    var energy_spent_str : Sequence := GetMinimumEnergySpent(n, shortcuts)->select(k | true)->collect(k | (("" + ((k))))) ;
    execute (StringLib.sumStringsWithSeparator((energy_spent_str), ' '))->display()
    ) else skip;
  operation GetMinimumEnergySpent(n : OclAny, shortcuts : OclAny) : OclAny
  pre: true post: true
  activity:
    var energy_spent : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)) ;
    var queue : Sequence := (energy_spent) ;
    while (queue)->size() > 0 do (    var idx : OclAny := queue->first() ;     queue := queue->tail() ;
    if (idx->compareTo(n - 1)) < 0 & (energy_spent[idx + 1+1]->compareTo(energy_spent[idx+1] + 1)) > 0 then (
      energy_spent[idx + 1+1] := energy_spent[idx+1] + 1 ;
    execute ((idx + 1) : queue)
    ) else skip ;
    if idx > 0 & (energy_spent[idx - 1+1]->compareTo(energy_spent[idx+1] + 1)) > 0 then (
      energy_spent[idx - 1+1] := energy_spent[idx+1] + 1 ;
    execute ((idx - 1) : queue)
    ) else skip ;
    if (energy_spent[idx+1] + 1->compareTo(energy_spent[shortcuts[idx+1]+1])) < 0 then (
      energy_spent[shortcuts[idx+1]+1] := energy_spent[idx+1] + 1 ;
    execute ((shortcuts[idx+1]) : queue)
    ) else skip) ;
    return energy_spent;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
border_a=80
border_b=65
border_c=50
border_d=30
border_retest=50
while True :
    m,f,r=map(int,input().split())
    mf=m+f
    if(m==-1)and(f==-1)and(r==-1):
        break
    elif(m==-1)or(f==-1):
        print("F")
    elif mf>=border_a :
        print("A")
    elif mf>=border_b :
        print("B")
    elif mf>=border_c :
        print("C")
    elif mf>=border_d :
        if r>=border_retest :
            print("C")
        else :
            print("D")
    else :
        print("F")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var border_a : int := 80 ;
    var border_b : int := 65 ;
    var border_c : int := 50 ;
    var border_d : int := 30 ;
    var border_retest : int := 50 ;
    while true do (    var m : OclAny := null;
    var f : OclAny := null;
    var r : OclAny := null;
    Sequence{m,f,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var mf : OclAny := m + f ;
    if (m = -1) & (f = -1) & (r = -1) then  (
      break
    )
    else (if (m = -1) or (f = -1) then
   (
      execute ("F")->display()    
)
    else (if (mf->compareTo(border_a)) >= 0 then
   (
      execute ("A")->display()    
)
    else (if (mf->compareTo(border_b)) >= 0 then
   (
      execute ("B")->display()    
)
    else (if (mf->compareTo(border_c)) >= 0 then
   (
      execute ("C")->display()    
)
    else (if (mf->compareTo(border_d)) >= 0 then
   (
      if (r->compareTo(border_retest)) >= 0 then  (
      execute ("C")->display()
    )
    else (
      execute ("D")->display()
      )    
)
    else (
      execute ("F")->display()
      )    )
    )
    )
    )
    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def binarysearch(v,x):
    low=0
    high=len(v)-1
    while(low<=high):
        mid=int((low+high)/2)
        if(v[mid]<=x):
            low=mid+1
        elif(v[mid]>x and v[mid-1]<=x):
            return mid
        elif(v[mid]>x and mid==0):
            return mid
        else :
            high=mid-1
    return-1
def CountContiguousParts(arr,n):
    count=0
    prefix=[0 for i in range(n)]
    prefix[0]=arr[0]
    for i in range(1,n,1):
        prefix[i]=prefix[i-1]+arr[i]
    total_sum=prefix[n-1]
    if(total_sum % 3!=0):
        return 0
    suffix=[0 for i in range(n)]
    suffix[n-1]=arr[n-1]
    i=n-2
    while(i>=0):
        suffix[i]=suffix[i+1]+arr[i]
        i-=1
    v=[]
    for i in range(n):
        if(suffix[i]==int(total_sum/3)):
            v.append(i)
    for i in range(n):
        if(prefix[i]==int(total_sum/3)):
            res=binarysearch(v,i+1)
            if(res!=-1):
                count+=len(v)-res
    return count
if __name__=='__main__' :
    arr=[1,2,3,0,3]
    n=len(arr)
    print(CountContiguousParts(arr,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = '__main__' then (
      arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{0}->union(Sequence{ 3 })))) ;
    n := (arr)->size() ;
    execute (CountContiguousParts(arr, n))->display()
    ) else skip;
  operation binarysearch(v : OclAny, x : OclAny) : OclAny
  pre: true post: true
  activity:
    var low : int := 0 ;
    var high : double := (v)->size() - 1 ;
    while ((low->compareTo(high)) <= 0) do (    var mid : int := ("" + (((low + high) / 2)))->toInteger() ;
    if ((v[mid+1]->compareTo(x)) <= 0) then  (
      low := mid + 1
    )
    else (if ((v[mid+1]->compareTo(x)) > 0 & (v[mid - 1+1]->compareTo(x)) <= 0) then
   (
      return mid    
)
    else (if ((v[mid+1]->compareTo(x)) > 0 & mid = 0) then
   (
      return mid    
)
    else (
      high := mid - 1
      )    )
    )
) ;
    return -1;
  operation CountContiguousParts(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var count : int := 0 ;
    var prefix : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ;
    prefix->first() := arr->first() ;
    for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 1 = 0 ) do (    prefix[i+1] := prefix[i - 1+1] + arr[i+1]) ;
    var total_sum : OclAny := prefix[n - 1+1] ;
    if (total_sum mod 3 /= 0) then (
      return 0
    ) else skip ;
    var suffix : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ;
    suffix[n - 1+1] := arr[n - 1+1] ;
    var i : double := n - 2 ;
    while (i >= 0) do (    suffix[i+1] := suffix[i + 1+1] + arr[i+1] ;
    i := i - 1) ;
    v := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    if (suffix[i+1] = ("" + ((total_sum / 3)))->toInteger()) then (
      execute ((i) : v)
    ) else skip) ;
    for i : Integer.subrange(0, n-1) do (    if (prefix[i+1] = ("" + ((total_sum / 3)))->toInteger()) then (
      var res : OclAny := binarysearch(v, i + 1) ;
    if (res /= -1) then (
      count := count + (v)->size() - res
    ) else skip
    ) else skip) ;
    return count;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import eulerlib
def compute():
    LIMIT=10**14
    ans=[0]
    def find_harshad_primes(n,digitsum,isstrong):
        m=n*10
        s=digitsum
        for i in range(10):
            if m>=LIMIT :
                break
            if isstrong and eulerlib.is_prime(m):
                ans[0]+=m
            if m % s==0 :
                find_harshad_primes(m,s,eulerlib.is_prime(m//s))
            m+=1
            s+=1
    for i in range(1,10):
        find_harshad_primes(i,i,False)
    return str(ans[0])
if __name__=="__main__" :
    print(compute())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      execute (compute())->display()
    ) else skip;
  operation compute() : OclAny
  pre: true post: true
  activity:
    var LIMIT : double := (10)->pow(14) ;
    var ans : Sequence := Sequence{ 0 } ;
    skip ;
    for i : Integer.subrange(1, 10-1) do (    find_harshad_primes(i, i, false)) ;
    return ("" + ((ans->first())));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from re import I
import sys
printf=sys.stdout.write
def intput(): return int(sys.stdin.readline())
def get_int(): return map(int,sys.stdin.readline().strip().split())
def get_lis(): return list(map(int,sys.stdin.readline().strip().split()))
def get_liss(): return sys.stdin.readline().split()
def get_ints(): return sys.stdin.readline().split()
def get_str(): return sys.stdin.readline().strip()
def pop_zeros(items):
    while items[-1]==0 :
        items.pop()
def compute_lcm(x,y):
    if x>y :
        greater=x
    else :
        greater=y
    while(True):
        if((greater % x==0)and(greater % y==0)):
            lcm=greater
            break
        greater+=1
    return lcm
from collections import defaultdict
import math
t=intput()
for p in range(t):
    n=intput()
    l=get_lis()
    ll=list(set(l))
    dict={}
    for i in range(len(ll)):
        count=0
        if ll[i]% 2==1 and(ll[i]not in dict):
            dict[ll[i]]=0
        else :
            while ll[i]% 2==0 :
                ll[i]//=2
                count+=1
        if ll[i]in dict :
            if count>dict[ll[i]]:
                dict[ll[i]]=count
        else :
            dict[ll[i]]=count
    ans=0
    for val in dict.values():
        ans+=val
    printf(str(ans))
    printf("\n")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var printf : OclAny := (OclFile["System.out"]).write ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var t : OclAny := intput() ;
    for p : Integer.subrange(0, t-1) do (    var n : OclAny := intput() ;
    var l : OclAny := get_lis() ;
    var ll : Sequence := (Set{}->union((l))) ;
    var OclType["Map"] : OclAny := Set{} ;
    for i : Integer.subrange(0, (ll)->size()-1) do (    var count : int := 0 ;
    if ll[i+1] mod 2 = 1 & ((OclType["Map"])->excludes(ll[i+1])) then  (
      (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ll)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ]) := 0
    )
    else (
      while ll[i+1] mod 2 = 0 do (    ll[i+1] := ll[i+1] div 2 ;
    count := count + 1)
      ) ;
    if (OclType["Map"])->includes(ll[i+1]) then  (
      if (count->compareTo((arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ll)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ]))) > 0 then (
      (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ll)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ]) := count
    ) else skip
    )
    else (
      (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ll)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ]) := count
      )) ;
    var ans : int := 0 ;
    for val : (trailer . (name values) (arguments ( ))) do (    ans := ans + val) ;
    printf(("" + ((ans)))) ;
    printf("\n"));
  operation intput() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation get_int() : OclAny
  pre: true post: true
  activity:
    return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) );
  operation get_lis() : OclAny
  pre: true post: true
  activity:
    return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ));
  operation get_liss() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine().split();
  operation get_ints() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine().split();
  operation get_str() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine()->trim();
  operation pop_zeros(items : OclAny)
  pre: true post: true
  activity:
    while items->last() = 0 do (    items := items->front());
  operation compute_lcm(x : OclAny, y : OclAny) : OclAny
  pre: true post: true
  activity:
    if (x->compareTo(y)) > 0 then  (
      var greater : OclAny := x
    )
    else (
      greater := y
      ) ;
    while (true) do (    if ((greater mod x = 0) & (greater mod y = 0)) then (
      var lcm : OclAny := greater ;
    break
    ) else skip ;
    greater := greater + 1) ;
    return lcm;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
from math import log2
for _ in range(int(input())):
    n=int(input())
    w=[i for i in map(int,input().split())if i % 2==0]
    s=set()
    for i in w :
        while i % 2==0 :
            i//=2
            s.add(i)
    print(len(s))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    skip ;
    for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var w : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->select(i | i mod 2 = 0)->collect(i | (i)) ;
    var s : Set := Set{}->union(()) ;
    for i : w do (    while i mod 2 = 0 do (    i := i div 2 ;
    execute ((i) : s))) ;
    execute ((s)->size())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import heapq
import sys,os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
t=int(input())
ans=[]
for _ in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    h=[]
    s=set()
    for i in a :
        if not i % 2 and not i in s :
            s.add(i)
            heapq.heappush(h,-i)
    ans0=0
    while h :
        i=-heapq.heappop(h)
        s.remove(i)
        i//=2
        ans0+=1
        if not i % 2 and not i in s :
            s.add(i)
            heapq.heappush(h,-i)
    ans.append(ans0)
sys.stdout.write("\n".join(map(str,ans)))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var input : OclAny := io.BytesIO(os.readAll()).readline ;
    var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var ans : Sequence := Sequence{} ;
    for _anon : Integer.subrange(0, t-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var h : Sequence := Sequence{} ;
    var s : Set := Set{}->union(()) ;
    for i : a do (    if not(i mod 2) & not((s)->includes(i)) then (
      execute ((i) : s) ;
    heapq.heappush(h, -i)
    ) else skip) ;
    var ans0 : int := 0 ;
    while h do (    var i : OclAny := -heapq.heappop(h) ;
    execute ((i) /: s) ;
    i := i div 2 ;
    ans0 := ans0 + 1 ;
    if not(i mod 2) & not((s)->includes(i)) then (
      execute ((i) : s) ;
    heapq.heappush(h, -i)
    ) else skip) ;
    execute ((ans0) : ans)) ;
(expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))))))) ))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for i in range(t):
    l=set()
    n=int(input())
    x=sorted((set(map(int,input().split()))),reverse=True)
    for j in x :
        while j % 2==0 :
            if j not in l :
                l.add(j)
                j=j//2
            else :
                break
    print(len(l))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, t-1) do (    var l : Set := Set{}->union(()) ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var x : Sequence := (Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ;
    for j : x do (    while j mod 2 = 0 do (    if (l)->excludes(j) then  (
      execute ((j) : l) ;
    var j : int := j div 2
    )
    else (
      break
      ))) ;
    execute ((l)->size())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys,os.path
if(os.path.exists('input.txt')):
    sys.stdin=open("input.txt","r")
    sys.stdout=open("outpput.txt","w")
def primeFactors(n):
    c=0
    while n % 2==0 :
        c+=1
        n=n/2
    return([c,int(n)])
t=int(input())
for i in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    f=0
    for i in range(n):
        if l[i]% 2==0 :
            f=1
            break
    if f==0 :
        print(0)
    else :
        ll={}
        for i in range(n):
            lt=primeFactors(l[i])
            try :
                if ll[lt[1]]toInteger() ;
    for i : Integer.subrange(0, t-1) do (    n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var f : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    if l[i+1] mod 2 = 0 then (
      f := 1 ;
    break
    ) else skip) ;
    if f = 0 then  (
      execute (0)->display()
    )
    else (
      var ll : OclAny := Set{} ;
    for i : Integer.subrange(0, n-1) do (    var lt : OclAny := primeFactors(l[i+1]) ;
    try (    if (ll[lt[1+1]+1]->compareTo(lt->first())) < 0 then (
      ll[lt[1+1]+1] := lt->first()
    ) else skip)
     catch (_e : OclException) do (    ll[lt[1+1]+1] := lt->first())
) ;
    var s : int := 0 ;
    for i : ll do (    s := s + ll[i+1]) ;
    execute (s)->display()
      ));
  operation primeFactors(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var c : int := 0 ;
    while n mod 2 = 0 do (    c := c + 1 ;
    n := n / 2) ;
    return (Sequence{c}->union(Sequence{ ("" + ((n)))->toInteger() }));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
class Solution(object):
    def isRectangleOverlap(self,rec1,rec2):
        return not(rec1[2]<=rec2[0]or rec1[3]<=rec2[1]or rec1[0]>=rec2[2]or rec1[1]>=rec2[3])
------------------------------------------------------------
OCL File:
---------
class Solution extends object {
  static operation newSolution() : Solution
  pre: true
  post: Solution->exists( _x | result = _x );
  operation isRectangleOverlap(rec1 : OclAny,rec2 : OclAny) : OclAny
  pre: true post: true
  activity:
    return not(((rec1[2+1]->compareTo(rec2->first())) <= 0 or (rec1[3+1]->compareTo(rec2[1+1])) <= 0 or (rec1->first()->compareTo(rec2[2+1])) >= 0 or (rec1[1+1]->compareTo(rec2[3+1])) >= 0));
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def digitSum(n):
    Sum=0
    while n>0 :
        Sum+=n % 10
        n=n//10
    return Sum
def totalPairs(arr1,arr2,n,m):
    s=set()
    for i in range(0,n):
        for j in range(0,m):
            if digitSum(arr1[i])==digitSum(arr2[j]):
                if arr1[i]union(Sequence{3}->union(Sequence{7}->union(Sequence{ 50 }))) ;
    arr2 := Sequence{5}->union(Sequence{1}->union(Sequence{10}->union(Sequence{ 4 }))) ;
    n := (arr1)->size() ;
    m := (arr2)->size() ;
    execute (totalPairs(arr1, arr2, n, m))->display()
    ) else skip;
  operation digitSum(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var Sum : int := 0 ;
    while n > 0 do (    Sum := Sum + n mod 10 ;
    n := n div 10) ;
    return Sum;
  operation totalPairs(arr1 : OclAny, arr2 : OclAny, n : OclAny, m : OclAny) : OclAny
  pre: true post: true
  activity:
    var s : Set := Set{}->union(()) ;
    for i : Integer.subrange(0, n-1) do (    for j : Integer.subrange(0, m-1) do (    if digitSum(arr1[i+1]) = digitSum(arr2[j+1]) then (
      if (arr1[i+1]->compareTo(arr2[j+1])) < 0 then  (
      execute ((Sequence{arr1[i+1], arr2[j+1]}) : s)
    )
    else (
      execute ((Sequence{arr2[j+1], arr1[i+1]}) : s)
      )
    ) else skip)) ;
    return (s)->size();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
nb_intersections=int(input())
arr1=list(map(int,input().split()))
def solution(shortcuts,nb_intersections):
    answers=[0]*nb_intersections
    shortcuts_dict=to_dict(shortcuts)
    for i in range(1,nb_intersections):
        if i not in shortcuts_dict :
            answers[i]=answers[i-1]+1
        else :
            origins=shortcuts_dict[i]+[i-1]
            try :
                origins.remove(i)
            except ValueError :
                pass
            answers[i]=min(answers[origin]for origin in origins)+1
            retro_check(answers,i)
    return answers
def to_dict(shortcuts):
    shortcuts_dict={}
    for index,value in enumerate(shortcuts):
        try :
            shortcuts_dict[value-1].append(index)
        except KeyError :
            shortcuts_dict[value-1]=[index]
    return shortcuts_dict
def retro_check(answers,i):
    while i>0 and(answers[i]<=answers[i-1]-2):
        answers[i-1]=answers[i]+1
        i-=1
answer=solution(arr1,nb_intersections)
print(" ".join([str(i)for i in answer]))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var nb_intersections : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var arr1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    skip ;
    skip ;
    skip ;
    var answer : OclAny := solution(arr1, nb_intersections) ;
    execute (StringLib.sumStringsWithSeparator((answer->select(i | true)->collect(i | (("" + ((i)))))), " "))->display();
  operation solution(shortcuts : OclAny, nb_intersections : OclAny) : OclAny
  pre: true post: true
  activity:
    var answers : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, nb_intersections) ;
    var shortcuts_dict : OclAny := to_dict(shortcuts) ;
    for i : Integer.subrange(1, nb_intersections-1) do (    if (shortcuts_dict)->excludes(i) then  (
      answers[i+1] := answers[i - 1+1] + 1
    )
    else (
      var origins : OclAny := shortcuts_dict[i+1]->union(Sequence{ i - 1 }) ;
    try (    execute ((i) /: origins))
(except_clause except (test (logical_test (comparison (expr (atom (name ValueError)))))) : (suite (stmt (simple_stmt (small_stmt pass))))) ;
    answers[i+1] := ((argument (test (logical_test (comparison (expr (atom (name answers)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name origin)))))))) ])))))) (comp_for for (exprlist (expr (atom (name origin)))) in (logical_test (comparison (expr (atom (name origins))))))))->min() + 1 ;
    retro_check(answers, i)
      )) ;
    return answers;
  operation to_dict(shortcuts : OclAny) : OclAny
  pre: true post: true
  activity:
    shortcuts_dict := Set{} ;
    for _tuple : Integer.subrange(1, (shortcuts)->size())->collect( _indx | Sequence{_indx-1, (shortcuts)->at(_indx)} ) do (var _indx : int := 1;
      var index : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var value : OclAny := _tuple->at(_indx);
      try ((expr (atom (name shortcuts_dict)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name value))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name index)))))))) )))))
(except_clause except (test (logical_test (comparison (expr (atom (name KeyError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name shortcuts_dict)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name value))) - (expr (atom (number (integer 1)))))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name index))))))) ])))))))))))))) ;
    return shortcuts_dict;
  operation retro_check(answers : OclAny, i : OclAny)
  pre: true post: true
  activity:
    while i > 0 & ((answers[i+1]->compareTo(answers[i - 1+1] - 2)) <= 0) do (    answers[i - 1+1] := answers[i+1] + 1 ;
    i := i - 1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def totalPairs(arr1,arr2,K,n,m):
    s={}
    for i in range(n):
        for j in range(m):
            if(arr1[i]>arr2[j]):
                if(arr1[i]% arr2[j]==K):
                    s[(arr1[i],arr2[j])]=1
            else :
                if(arr2[j]% arr1[i]==K):
                    s[(arr2[j],arr1[i])]=1
    return len(s)
arr1=[8,3,7,50]
arr2=[5,1,10,4]
K=3
n=len(arr1)
m=len(arr2)
print(totalPairs(arr1,arr2,K,n,m))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    arr1 := Sequence{8}->union(Sequence{3}->union(Sequence{7}->union(Sequence{ 50 }))) ;
    arr2 := Sequence{5}->union(Sequence{1}->union(Sequence{10}->union(Sequence{ 4 }))) ;
    K := 3 ;
    n := (arr1)->size() ;
    m := (arr2)->size() ;
    execute (totalPairs(arr1, arr2, K, n, m))->display();
  operation totalPairs(arr1 : OclAny, arr2 : OclAny, K : OclAny, n : OclAny, m : OclAny) : OclAny
  pre: true post: true
  activity:
    var s : OclAny := Set{} ;
    for i : Integer.subrange(0, n-1) do (    for j : Integer.subrange(0, m-1) do (    if ((arr1[i+1]->compareTo(arr2[j+1])) > 0) then  (
      if (arr1[i+1] mod arr2[j+1] = K) then (
      s[Sequence{arr1[i+1], arr2[j+1]}+1] := 1
    ) else skip
    )
    else (
      if (arr2[j+1] mod arr1[i+1] = K) then (
      s[Sequence{arr2[j+1], arr1[i+1]}+1] := 1
    ) else skip
      ))) ;
    return (s)->size();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
tot=0
count=0
while(n//10!=0):
    rem=n % 10
    tot+=9-rem
    n=n//10
    count+=1
if(count==0):
    print(9)
else :
    print(9+tot+1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var tot : int := 0 ;
    var count : int := 0 ;
    while (n div 10 /= 0) do (    var rem : int := n mod 10 ;
    tot := tot + 9 - rem ;
    n := n div 10 ;
    count := count + 1) ;
    if (count = 0) then  (
      execute (9)->display()
    )
    else (
      execute (9 + tot + 1)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
if __name__=="__main__" :
    while True :
        score=[int(i)for i in input().split()]
        if score[0]==score[1]==score[2]==-1 :
            break
        if score[0]==-1 or score[1]==-1 :
            print('F')
        else :
            if score[0]+score[1]>=80 :
                print('A')
            elif score[0]+score[1]>=65 :
                print('B')
            elif score[0]+score[1]>=50 :
                print('C')
            elif score[0]+score[1]>=30 :
                if score[2]==-1 :
                    print('D')
                else :
                    if score[2]>=50 :
                        print('C')
                    else :
                        print('D')
            else :
                print('F')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     if __name__ = "__main__" then (
      while true do (    var score : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    if score->first() = score[1+1] & (score[1+1] == score[2+1]) & (score[2+1] == -1) then (
      break
    ) else skip ;
    if score->first() = -1 or score[1+1] = -1 then  (
      execute ('F')->display()
    )
    else (
      if score->first() + score[1+1] >= 80 then  (
      execute ('A')->display()
    )
    else (if score->first() + score[1+1] >= 65 then
   (
      execute ('B')->display()    
)
    else (if score->first() + score[1+1] >= 50 then
   (
      execute ('C')->display()    
)
    else (if score->first() + score[1+1] >= 30 then
   (
      if score[2+1] = -1 then  (
      execute ('D')->display()
    )
    else (
      if score[2+1] >= 50 then  (
      execute ('C')->display()
    )
    else (
      execute ('D')->display()
      )
      )    
)
    else (
      execute ('F')->display()
      )    )
    )
    )
      ))
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import itertools as itr
n,m=map(int,input().split())
a=[list(map(float,input().split()))for i in range(n)]
ans=0
for p in itr.combinations(a,m):
    sm=0
    for i in range(m):
        for j in range(i+1,m):
            for k in range(3):
                sm+=(p[i][k]-p[j][k])**2
    ans=max(ans,sm)
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["double"])->apply(_x) )))) ;
    var ans : int := 0 ;
    for p : itr.combinations(a, m) do (    var sm : int := 0 ;
    for i : Integer.subrange(0, m-1) do (    for j : Integer.subrange(i + 1, m-1) do (    for k : Integer.subrange(0, 3-1) do (    sm := sm + ((p[i+1][k+1] - p[j+1][k+1]))->pow(2)))) ;
    ans := Set{ans, sm}->max()) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import itertools
N,M=map(int,input().split())
src=[tuple(map(float,input().split()))for i in range(N)]
if M<=1 :
    print(0)
    exit()
dists=[[None for j in range(N)]for i in range(N)]
for i in range(N-1):
    for j in range(i+1,N):
        l1,a1,b1=src[i]
        l2,a2,b2=src[j]
        dist=0
        dist+=(l1-l2)**2+(a1-a2)**2+(b1-b2)**2
        dists[i][j]=dists[j][i]=dist
ans=0
for ptn in list(itertools.combinations(range(N),M)):
    total=0
    for i in range(M-1):
        for j in range(i+1,M):
            total+=dists[ptn[i]][ptn[j]]
    ans=max(ans,total)
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var src : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["double"])->apply(_x) )))) ;
    if M <= 1 then (
      execute (0)->display() ;
    exit()
    ) else skip ;
    var dists : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Integer.subrange(0, N-1)->select(j | true)->collect(j | (null)))) ;
    for i : Integer.subrange(0, N - 1-1) do (    for j : Integer.subrange(i + 1, N-1) do (    var l1 : OclAny := null;
    var a1 : OclAny := null;
    var b1 : OclAny := null;
    Sequence{l1,a1,b1} := src[i+1] ;
    var l2 : OclAny := null;
    var a2 : OclAny := null;
    var b2 : OclAny := null;
    Sequence{l2,a2,b2} := src[j+1] ;
    var dist : int := 0 ;
    dist := dist + ((l1 - l2))->pow(2) + ((a1 - a2))->pow(2) + ((b1 - b2))->pow(2) ;
    dists[i+1][j+1] := dist; var dists[j+1][i+1] : int := dist)) ;
    var ans : int := 0 ;
    for ptn : (itertools.combinations(Integer.subrange(0, N-1), M)) do (    var total : int := 0 ;
    for i : Integer.subrange(0, M - 1-1) do (    for j : Integer.subrange(i + 1, M-1) do (    total := total + dists[ptn[i+1]+1][ptn[j+1]+1])) ;
    ans := Set{ans, total}->max()) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    n,m=map(int,input().split())
    import itertools
    full=itertools.combinations(range(n),m)
    l=[list(map(float,input().split()))for i in range(n)]
    differ=[[0]*n for _ in range(n)]
    for i in range(n):
        for k in range(i+1,n):
            tmp=0
            for j in range(3):
                tmp+=(l[i][j]-l[k][j])**2
            differ[i][k]=tmp
            differ[k][i]=tmp
    ans=0
    for f in full :
        tmp=0
        f=list(f)
        for f1i in range(len(f)):
            for f2i in range(f1i+1,len(f)):
                tmp+=differ[f[f1i]][f[f2i]]
        ans=max(ans,tmp)
    print(ans)
if __name__=="__main__" :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    skip ;
    var full : OclAny := itertools.combinations(Integer.subrange(0, n-1), m) ;
    var l : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["double"])->apply(_x) )))) ;
    var differ : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, n))) ;
    for i : Integer.subrange(0, n-1) do (    for k : Integer.subrange(i + 1, n-1) do (    var tmp : int := 0 ;
    for j : Integer.subrange(0, 3-1) do (    tmp := tmp + ((l[i+1][j+1] - l[k+1][j+1]))->pow(2)) ;
    differ[i+1][k+1] := tmp ;
    differ[k+1][i+1] := tmp)) ;
    var ans : int := 0 ;
    for f : full do (    tmp := 0 ;
    var f : Sequence := (f) ;
    for f1i : Integer.subrange(0, (f)->size()-1) do (    for f2i : Integer.subrange(f1i + 1, (f)->size()-1) do (    tmp := tmp + differ[f[f1i+1]+1][f[f2i+1]+1])) ;
    ans := Set{ans, tmp}->max()) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def waysToKAdjacentSetBits(n,k,currentIndex,adjacentSetBits,lastBit):
    if(currentIndex==n):
        if(adjacentSetBits==k):
            return 1 ;
        return 0
    noOfWays=0
    if(lastBit==1):
        noOfWays+=waysToKAdjacentSetBits(n,k,currentIndex+1,adjacentSetBits+1,1);
        noOfWays+=waysToKAdjacentSetBits(n,k,currentIndex+1,adjacentSetBits,0);
    elif(lastBit!=1):
        noOfWays+=waysToKAdjacentSetBits(n,k,currentIndex+1,adjacentSetBits,1);
        noOfWays+=waysToKAdjacentSetBits(n,k,currentIndex+1,adjacentSetBits,0);
    return noOfWays ;
n=5 ; k=2 ;
totalWays=(waysToKAdjacentSetBits(n,k,1,0,1)+waysToKAdjacentSetBits(n,k,1,0,0));
print("Number of ways=",totalWays);
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    n := 5;    k := 2; ;
    var totalWays : OclAny := (waysToKAdjacentSetBits(n, k, 1, 0, 1) + waysToKAdjacentSetBits(n, k, 1, 0, 0)); ;
    execute ("Number of ways=")->display();;
  operation waysToKAdjacentSetBits(n : OclAny, k : OclAny, currentIndex : OclAny, adjacentSetBits : OclAny, lastBit : OclAny) : OclAny
  pre: true post: true
  activity:
    if (currentIndex = n) then (
      if (adjacentSetBits = k) then (
      return 1;
    ) else skip ;
    return 0
    ) else skip ;
    var noOfWays : int := 0 ;
    if (lastBit = 1) then  (
      noOfWays := noOfWays + waysToKAdjacentSetBits(n, k, currentIndex + 1, adjacentSetBits + 1, 1); ;
    noOfWays := noOfWays + waysToKAdjacentSetBits(n, k, currentIndex + 1, adjacentSetBits, 0);
    )
    else (if (lastBit /= 1) then
   (
      noOfWays := noOfWays + waysToKAdjacentSetBits(n, k, currentIndex + 1, adjacentSetBits, 1); ;
    noOfWays := noOfWays + waysToKAdjacentSetBits(n, k, currentIndex + 1, adjacentSetBits, 0);    
)
 else skip) ;
    return noOfWays;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines
from heapq import heappush,heappushpop
N=int(readline())
m=map(int,read().split())
L,R=zip(*zip(m,m))
A=[-L[0]]; B=[L[0]]
addA=0
addB=0
min_f=0
for n in range(1,N):
    p=R[n-1]-L[n-1]; q=R[n]-L[n]
    addA+=(-q); addB+=p
    a=-A[0]+addA
    b=B[0]+addB
    x=L[n]
    if x<=a :
        min_f+=a-x
        heappush(A,-x+addA)
        y=-heappushpop(A,-x+addA)+addA
        heappush(B,y-addB)
    elif x>=b :
        min_f+=x-b
        heappush(B,x-addB)
        y=heappushpop(B,x-addB)+addB
        heappush(A,-y+addA)
    else :
        heappush(A,-x+addA)
        heappush(B,x-addB)
print(min_f)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var read : OclAny := sys.stdin.buffer.read ;
    var readline : OclAny := sys.stdin.buffer.readline ;
    var readlines : OclAny := sys.stdin.buffer.readlines ;
    skip ;
    var N : int := ("" + ((readline())))->toInteger() ;
    var m : Sequence := (read().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var L : OclAny := null;
    var R : OclAny := null;
    Sequence{L,R} := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name m))))))) , (argument (test (logical_test (comparison (expr (atom (name m)))))))) ))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name m))))))) , (argument (test (logical_test (comparison (expr (atom (name m)))))))) ))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name m))))))) , (argument (test (logical_test (comparison (expr (atom (name m)))))))) ))))))))`third->at(_indx)} ) ;
    var A : Sequence := Sequence{ -L->first() };    var B : Sequence := Sequence{ L->first() } ;
    var addA : int := 0 ;
    var addB : int := 0 ;
    var min_f : int := 0 ;
    for n : Integer.subrange(1, N-1) do (    var p : double := R[n - 1+1] - L[n - 1+1];    var q : double := R[n+1] - L[n+1] ;
    addA := addA + (-q);    addB := addB + p ;
    var a : OclAny := -A->first() + addA ;
    var b : OclAny := B->first() + addB ;
    var x : OclAny := L[n+1] ;
    if (x->compareTo(a)) <= 0 then  (
      min_f := min_f + a - x ;
    heappush(A, -x + addA) ;
    var y : OclAny := -heappushpop(A, -x + addA) + addA ;
    heappush(B, y - addB)
    )
    else (if (x->compareTo(b)) >= 0 then
   (
      min_f := min_f + x - b ;
    heappush(B, x - addB) ;
    y := heappushpop(B, x - addB) + addB ;
    heappush(A, -y + addA)    
)
    else (
      heappush(A, -x + addA) ;
    heappush(B, x - addB)
      )    )
) ;
    execute (min_f)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=int(input())
P=[list(map(int,input().split()))for i in range(N)]
INF=10**18
from heapq import heappush,heappop
l0,r0=P[0]
L=[-l0+1]
R=[l0-1]
s=t=0
def debug(L,s,t,R):
    L0=L[:]
    Q1=[]; Q2=[]
    while L0 :
        Q1.append(-s-heappop(L0))
    R0=R[:]
    while R0 :
        Q2.append(t+heappop(R0))
    print("debug:",*Q1[: :-1]+Q2)
res=0
for i in range(N-1):
    l0,r0=P[i]
    l1,r1=P[i+1]
    s+=(r1-l1); t+=(r0-l0)
    if-s-L[0]<=l1-1<=t+R[0]:
        heappush(L,-l1+1-s)
        heappush(R,l1-1-t)
    elif l1-1<-s-L[0]:
        heappush(L,-l1+1-s)
        heappush(L,-l1+1-s)
        p=-heappop(L)-s
        heappush(R,p-t)
        res+=(p-(l1-1))
    elif t+R[0]toInteger() ;
    var P : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var INF : double := (10)->pow(18) ;
    skip ;
    var l0 : OclAny := null;
    var r0 : OclAny := null;
    Sequence{l0,r0} := P->first() ;
    var L : Sequence := Sequence{ -l0 + 1 } ;
    var R : Sequence := Sequence{ l0 - 1 } ;
    var s : OclAny := 0; var t : int := 0 ;
    skip ;
    var res : int := 0 ;
    for i : Integer.subrange(0, N - 1-1) do (    var l0 : OclAny := null;
    var r0 : OclAny := null;
    Sequence{l0,r0} := P[i+1] ;
    var l1 : OclAny := null;
    var r1 : OclAny := null;
    Sequence{l1,r1} := P[i + 1+1] ;
    s := s + (r1 - l1);    t := t + (r0 - l0) ;
    if (-s - L->first()->compareTo(l1 - 1)) <= 0 & (l1 - 1 <= t + R->first()) then  (
      heappush(L, -l1 + 1 - s) ;
    heappush(R, l1 - 1 - t)
    )
    else (if (l1 - 1->compareTo(-s - L->first())) < 0 then
   (
      heappush(L, -l1 + 1 - s) ;
    heappush(L, -l1 + 1 - s) ;
    var p : double := -heappop(L) - s ;
    heappush(R, p - t) ;
    res := res + (p - (l1 - 1))    
)
    else (if (t + R->first()->compareTo(l1 - 1)) < 0 then
   (
      heappush(R, l1 - 1 - t) ;
    heappush(R, l1 - 1 - t) ;
    p := heappop(R) + t ;
    heappush(L, -p - s) ;
    res := res + (l1 - 1 - p)    
)
    else skip    )
    )
) ;
    execute (res)->display();
  operation debug(L : OclAny, s : OclAny, t : OclAny, R : OclAny)
  pre: true post: true
  activity:
    var L0 : Sequence := L ;
    var Q1 : Sequence := Sequence{};    var Q2 : Sequence := Sequence{} ;
    while L0 do (    execute ((-s - heappop(L0)) : Q1)) ;
    var R0 : String := R ;
    while R0 do (    execute ((t + heappop(R0)) : Q2)) ;
    execute ("debug:")->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
from heapq import heappop,heappush
N=int(input())
LR=[[int(x)for x in input().split()]for _ in range(N)]
L,R=LR[0]
S_lower=[-L]
S_upper=[L]
min_f=0
add_lower=0
add_upper=0
prev_w=R-L
push_L=lambda x : heappush(S_lower,-x)
push_R=lambda x : heappush(S_upper,x)
pop_L=lambda :-heappop(S_lower)
pop_R=lambda : heappop(S_upper)
for L,R in LR[1 :]:
    w=R-L
    add_lower-=w
    add_upper+=prev_w
    x=pop_L()+add_lower
    y=pop_R()+add_upper
    a,b,c,d=sorted([x,y,L,L])
    push_L(a-add_lower)
    push_L(b-add_lower)
    push_R(c-add_upper)
    push_R(d-add_upper)
    min_f+=c-b
    prev_w=w
print(min_f)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    skip ;
    var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var LR : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))) ;
    var L : OclAny := null;
    var R : OclAny := null;
    Sequence{L,R} := LR->first() ;
    var S_lower : Sequence := Sequence{ -L } ;
    var S_upper : Sequence := Sequence{ L } ;
    var min_f : int := 0 ;
    var add_lower : int := 0 ;
    var add_upper : int := 0 ;
    var prev_w : double := R - L ;
    var push_L : Function := lambda x : OclAny in (heappush(S_lower, -x)) ;
    var push_R : Function := lambda x : OclAny in (heappush(S_upper, x)) ;
    var pop_L : Function := lambda $$ : OclAny in (-heappop(S_lower)) ;
    var pop_R : Function := lambda $$ : OclAny in (heappop(S_upper)) ;
    for _tuple : LR->tail() do (var _indx : int := 1;
      var L : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var R : OclAny := _tuple->at(_indx);
      var w : double := R - L ;
    add_lower := add_lower - w ;
    add_upper := add_upper + prev_w ;
    var x : OclAny := pop_L->apply() + add_lower ;
    var y : OclAny := pop_R->apply() + add_upper ;
    var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    var d : OclAny := null;
    Sequence{a,b,c,d} := Sequence{x}->union(Sequence{y}->union(Sequence{L}->union(Sequence{ L })))->sort() ;
    push_L(a - add_lower) ;
    push_L(b - add_lower) ;
    push_R(c - add_upper) ;
    push_R(d - add_upper) ;
    min_f := min_f + c - b ;
    prev_w := w) ;
    execute (min_f)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
s=str(input())
sort=sorted(s)
if s==''.join(sort):
    print('NO')
else :
    for i in range(n-1):
        if s[i]>s[i+1]:
            print('YES')
            break
    print(i+1,i+2)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : String := ("" + (((OclFile["System.in"]).readLine()))) ;
    var sort : Sequence := s->sort() ;
    if s = StringLib.sumStringsWithSeparator((sort), '') then  (
      execute ('NO')->display()
    )
    else (
      for i : Integer.subrange(0, n - 1-1) do (    if (s[i+1]->compareTo(s[i + 1+1])) > 0 then (
      execute ('YES')->display() ;
    break
    ) else skip) ;
    execute (i + 1)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from typing import List,Dict
nb_intersections=int(input())
arr1=list(map(int,input().split()))
def solution(shortcuts : List[int],nb_intersections : int)->List[int]:
    answers=[0]*nb_intersections
    shortcuts_dict=to_dict(shortcuts)
    for i in range(1,nb_intersections):
        if i not in shortcuts_dict :
            answers[i]=answers[i-1]+1
        else :
            origins=shortcuts_dict[i]+[i-1]
            try :
                origins.remove(i)
            except ValueError :
                pass
            answers[i]=min(answers[origin]for origin in origins)+1
            retro_check(answers,i)
    return answers
def to_dict(shortcuts : List[int])->Dict[int,List[int]]:
    shortcuts_dict={}
    for index,value in enumerate(shortcuts):
        try :
            shortcuts_dict[value-1].append(index)
        except KeyError :
            shortcuts_dict[value-1]=[index]
    return shortcuts_dict
def retro_check(answers : List[int],i : int)->None :
    while i>0 and(answers[i]<=answers[i-1]-2):
        answers[i-1]=answers[i]+1
        i-=1
answer=solution(arr1,nb_intersections)
print(" ".join([str(i)for i in answer]))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var nb_intersections : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var arr1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    skip ;
    skip ;
    skip ;
    var answer : OclAny := solution(arr1, nb_intersections) ;
    execute (StringLib.sumStringsWithSeparator((answer->select(i | true)->collect(i | (("" + ((i)))))), " "))->display();
  operation solution(shortcuts : List[OclType["int"]+1], nb_intersections : int) : OclAny
  pre: true post: true
  activity:
    var answers : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, nb_intersections) ;
    var shortcuts_dict : OclAny := to_dict(shortcuts) ;
    for i : Integer.subrange(1, nb_intersections-1) do (    if (shortcuts_dict)->excludes(i) then  (
      answers[i+1] := answers[i - 1+1] + 1
    )
    else (
      var origins : OclAny := shortcuts_dict[i+1]->union(Sequence{ i - 1 }) ;
    try (    execute ((i) /: origins))
(except_clause except (test (logical_test (comparison (expr (atom (name ValueError)))))) : (suite (stmt (simple_stmt (small_stmt pass))))) ;
    answers[i+1] := ((argument (test (logical_test (comparison (expr (atom (name answers)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name origin)))))))) ])))))) (comp_for for (exprlist (expr (atom (name origin)))) in (logical_test (comparison (expr (atom (name origins))))))))->min() + 1 ;
    retro_check(answers, i)
      )) ;
    return answers;
  operation to_dict(shortcuts : List[OclType["int"]+1]) : OclAny
  pre: true post: true
  activity:
    shortcuts_dict := Set{} ;
    for _tuple : Integer.subrange(1, (shortcuts)->size())->collect( _indx | Sequence{_indx-1, (shortcuts)->at(_indx)} ) do (var _indx : int := 1;
      var index : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var value : OclAny := _tuple->at(_indx);
      try ((expr (atom (name shortcuts_dict)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name value))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name index)))))))) )))))
(except_clause except (test (logical_test (comparison (expr (atom (name KeyError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name shortcuts_dict)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name value))) - (expr (atom (number (integer 1)))))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name index))))))) ])))))))))))))) ;
    return shortcuts_dict;
  operation retro_check(answers : List[OclType["int"]+1], i : int) : OclAny
  pre: true post: true
  activity:
    while i > 0 & ((answers[i+1]->compareTo(answers[i - 1+1] - 2)) <= 0) do (    answers[i - 1+1] := answers[i+1] + 1 ;
    i := i - 1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=int(input())
P=[list(map(int,input().split()))for i in range(N)]
from heapq import heappush,heappop
l0,r0=P[0]
L=[-l0+1]
R=[l0-1]
s=t=0
res=0
for i in range(N-1):
    l0,r0=P[i]
    l1,r1=P[i+1]
    s+=(r1-l1); t+=(r0-l0)
    if-s-L[0]<=l1-1<=t+R[0]:
        heappush(L,-l1+1-s)
        heappush(R,l1-1-t)
    elif l1-1<-s-L[0]:
        heappush(L,-l1+1-s)
        heappush(L,-l1+1-s)
        p=-heappop(L)-s
        heappush(R,p-t)
        res+=(p-(l1-1))
    elif t+R[0]toInteger() ;
    var P : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    skip ;
    var l0 : OclAny := null;
    var r0 : OclAny := null;
    Sequence{l0,r0} := P->first() ;
    var L : Sequence := Sequence{ -l0 + 1 } ;
    var R : Sequence := Sequence{ l0 - 1 } ;
    var s : OclAny := 0; var t : int := 0 ;
    var res : int := 0 ;
    for i : Integer.subrange(0, N - 1-1) do (    var l0 : OclAny := null;
    var r0 : OclAny := null;
    Sequence{l0,r0} := P[i+1] ;
    var l1 : OclAny := null;
    var r1 : OclAny := null;
    Sequence{l1,r1} := P[i + 1+1] ;
    s := s + (r1 - l1);    t := t + (r0 - l0) ;
    if (-s - L->first()->compareTo(l1 - 1)) <= 0 & (l1 - 1 <= t + R->first()) then  (
      heappush(L, -l1 + 1 - s) ;
    heappush(R, l1 - 1 - t)
    )
    else (if (l1 - 1->compareTo(-s - L->first())) < 0 then
   (
      heappush(L, -l1 + 1 - s) ;
    heappush(L, -l1 + 1 - s) ;
    var p : double := -heappop(L) - s ;
    heappush(R, p - t) ;
    res := res + (p - (l1 - 1))    
)
    else (if (t + R->first()->compareTo(l1 - 1)) < 0 then
   (
      heappush(R, l1 - 1 - t) ;
    heappush(R, l1 - 1 - t) ;
    p := heappop(R) + t ;
    heappush(L, -p - s) ;
    res := res + ((l1 - 1) - p)    
)
    else skip    )
    )
) ;
    execute (res)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=int(input())
P=[list(map(int,input().split()))for i in range(N)]
INF=10**18
from heapq import heappush,heappop
l0,r0=P[0]
L=[-l0+1]
R=[l0-1]
s=t=0
res=0
for i in range(N-1):
    l0,r0=P[i]
    l1,r1=P[i+1]
    s+=(r1-l1); t+=(r0-l0)
    if-s-L[0]<=l1-1<=t+R[0]:
        heappush(L,-l1+1-s)
        heappush(R,l1-1-t)
    elif l1-1<-s-L[0]:
        heappush(L,-l1+1-s)
        heappush(L,-l1+1-s)
        p=-heappop(L)-s
        heappush(R,p-t)
        res+=(p-(l1-1))
    elif t+R[0]toInteger() ;
    var P : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var INF : double := (10)->pow(18) ;
    skip ;
    var l0 : OclAny := null;
    var r0 : OclAny := null;
    Sequence{l0,r0} := P->first() ;
    var L : Sequence := Sequence{ -l0 + 1 } ;
    var R : Sequence := Sequence{ l0 - 1 } ;
    var s : OclAny := 0; var t : int := 0 ;
    var res : int := 0 ;
    for i : Integer.subrange(0, N - 1-1) do (    var l0 : OclAny := null;
    var r0 : OclAny := null;
    Sequence{l0,r0} := P[i+1] ;
    var l1 : OclAny := null;
    var r1 : OclAny := null;
    Sequence{l1,r1} := P[i + 1+1] ;
    s := s + (r1 - l1);    t := t + (r0 - l0) ;
    if (-s - L->first()->compareTo(l1 - 1)) <= 0 & (l1 - 1 <= t + R->first()) then  (
      heappush(L, -l1 + 1 - s) ;
    heappush(R, l1 - 1 - t)
    )
    else (if (l1 - 1->compareTo(-s - L->first())) < 0 then
   (
      heappush(L, -l1 + 1 - s) ;
    heappush(L, -l1 + 1 - s) ;
    var p : double := -heappop(L) - s ;
    heappush(R, p - t) ;
    res := res + (p - (l1 - 1))    
)
    else (if (t + R->first()->compareTo(l1 - 1)) < 0 then
   (
      heappush(R, l1 - 1 - t) ;
    heappush(R, l1 - 1 - t) ;
    p := heappop(R) + t ;
    heappush(L, -p - s) ;
    res := res + (l1 - 1 - p)    
)
    else skip    )
    )
) ;
    execute (res)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=[int(i)for i in input().split()]
if(a==0):
    print(-b**2)
    print('x'*b)
elif(b==0):
    print(a**2)
    print('o'*a)
elif(b==1):
    print(a**2-1)
    print('x'+'o'*a)
else :
    ans=-float('inf')
    gr_no=None
    for i in range(2,min(a+2,b+1)):
        v1=(a+2-i)**2+i-2
        quo=b//i
        rem=b % i
        v2=rem*((quo+1)**2)+(i-rem)*((quo**2))
        if(v1-v2>ans):
            gr_no=i
            ans=v1-v2
    quo=b//gr_no
    rem=b % gr_no
    if(rem>0):
        s='x'*(quo+1)+'o'*(a+2-gr_no)
        rem-=1
    else :
        s='x'*(quo)+'o'*(a+2-gr_no)
    gr_no-=1
    s1='x'*(quo+1)+'o'
    s2='x'*quo+'o'
    for i in range(rem):
        s+=s1
    for i in range(gr_no-rem-1):
        s+=s2
    s+='x'*(quo)
    print(ans)
    print(s)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    if (a = 0) then  (
      execute (-(b)->pow(2))->display() ;
    execute (StringLib.nCopies('x', b))->display()
    )
    else (if (b = 0) then
   (
      execute ((a)->pow(2))->display() ;
    execute (StringLib.nCopies('o', a))->display()    
)
    else (if (b = 1) then
   (
      execute ((a)->pow(2) - 1)->display() ;
    execute ('x' + StringLib.nCopies('o', a))->display()    
)
    else (
      var ans : double := -("" + (('inf')))->toReal() ;
    var gr_no : OclAny := null ;
    for i : Integer.subrange(2, Set{a + 2, b + 1}->min()-1) do (    var v1 : double := ((a + 2 - i))->pow(2) + i - 2 ;
    var quo : int := b div i ;
    var rem : int := b mod i ;
    var v2 : double := rem * (((quo + 1))->pow(2)) + (i - rem) * (((quo)->pow(2))) ;
    if ((v1 - v2->compareTo(ans)) > 0) then (
      gr_no := i ;
    ans := v1 - v2
    ) else skip) ;
    quo := b div gr_no ;
    rem := b mod gr_no ;
    if (rem > 0) then  (
      var s : String := StringLib.nCopies('x', (quo + 1)) + StringLib.nCopies('o', (a + 2 - gr_no)) ;
    rem := rem - 1
    )
    else (
      s := StringLib.nCopies('x', (quo)) + StringLib.nCopies('o', (a + 2 - gr_no))
      ) ;
    gr_no := gr_no - 1 ;
    var s1 : String := StringLib.nCopies('x', (quo + 1)) + 'o' ;
    var s2 : String := StringLib.nCopies('x', quo) + 'o' ;
    for i : Integer.subrange(0, rem-1) do (    s := s + s1) ;
    for i : Integer.subrange(0, gr_no - rem - 1-1) do (    s := s + s2) ;
    s := s + StringLib.nCopies('x', (quo)) ;
    execute (ans)->display() ;
    execute (s)->display()
      )    )
    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    x=input()
    list=x.split()
[m,f,r]=list
    m=int(m)
    f=int(f)
    r=int(r)
    mf=m+f
    mfr=m+f+r
    if mfr==-3 :
        break
    if m==-1 or f==-1 :
        ans="F"
    elif mf>=80 :
        ans="A"
    elif mf>=65 :
        ans="B"
    elif mf>=50 :
        ans="C"
    elif mf<30 :
        ans="F"
    elif mf>=30 and r>=50 :
        ans="C"
    elif mf>=30 and r<50 :
        ans="D"
    print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    var x : String := (OclFile["System.in"]).readLine() ;
    var OclType["Sequence"] : OclAny := x.split()) ;
    Sequence{m}->union(Sequence{f}->union(Sequence{ r })) := OclType["Sequence"];
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=map(int,input().split())
def sqr(x):
    return x*x
def work(num,flag=0):
    ans=sqr(a-num+1)+num-1
    could=min(b,num+1)
    cc=b//could
    res=b % could
    ans-=res*sqr(cc+1)+(could-res)*sqr(cc)
    if flag :
        print(ans)
        list=''
        res2=could-res
        if could==num+1 :
            list+='x'*cc
            res2-=1
        ta=a
        list+='o'*(a-num+1)
        ta-=a-num+1
        while ta>0 :
            u=cc+int(res>0)
            if res>0 :
                res-=1
            else :
                res2-=1
            list+='x'*u
            list+='o'
            ta-=1
        if res>0 or res2>0 :
            list+='x'*(cc+int(res>0))
        print(str(list))
    return ans
if a==0 :
    print(-sqr(b))
    print('x'*b)
elif b==0 :
    print(sqr(a))
    print('o'*a)
else :
    now=1
    for i in range(1,a+1):
        if i-1<=b and work(i)>work(now):
            now=i
    work(now,1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    skip ;
    skip ;
    if a = 0 then  (
      execute (-sqr(b))->display() ;
    execute (StringLib.nCopies('x', b))->display()
    )
    else (if b = 0 then
   (
      execute (sqr(a))->display() ;
    execute (StringLib.nCopies('o', a))->display()    
)
    else (
      var now : int := 1 ;
    for i : Integer.subrange(1, a + 1-1) do (    if (i - 1->compareTo(b)) <= 0 & (work(i)->compareTo(work(now))) > 0 then (
      now := i
    ) else skip) ;
    work(now, 1)
      )    )
;
  operation sqr(x : OclAny) : OclAny
  pre: true post: true
  activity:
    return x * x;
  operation work(num : OclAny, flag : int) : OclAny
  pre: true post: true
  activity:
    if flag->oclIsUndefined() then flag := 0 else skip;
    var ans : double := sqr(a - num + 1) + num - 1 ;
    var could : OclAny := Set{b, num + 1}->min() ;
    var cc : int := b div could ;
    var res : int := b mod could ;
    ans := ans - res * sqr(cc + 1) + (could - res) * sqr(cc) ;
    if flag then (
      execute (ans)->display() ;
    var OclType["Sequence"] : String := '' ;
    var res2 : double := could - res ;
    if could = num + 1 then (
      OclType["Sequence"] := OclType["Sequence"] + StringLib.nCopies('x', cc) ;
    res2 := res2 - 1
    ) else skip ;
    var ta : OclAny := a ;
    OclType["Sequence"] := OclType["Sequence"] + StringLib.nCopies('o', (a - num + 1)) ;
    ta := ta - a - num + 1 ;
    while ta > 0 do (    var u : int := cc + ("" + ((res > 0)))->toInteger() ;
    if res > 0 then  (
      res := res - 1
    )
    else (
      res2 := res2 - 1
      ) ;
    OclType["Sequence"] := OclType["Sequence"] + StringLib.nCopies('x', u) ;
    OclType["Sequence"] := OclType["Sequence"] + 'o' ;
    ta := ta - 1) ;
    if res > 0 or res2 > 0 then (
      OclType["Sequence"] := OclType["Sequence"] + StringLib.nCopies('x', (cc + ("" + ((res > 0)))->toInteger()))
    ) else skip ;
    execute (("" + ((OclType["Sequence"]))))->display()
    ) else skip ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
bot=True
a,b=map(int,input().split())
def sqr(x):
    return x*x
def work(num,flag=0):
    ans=sqr(a-num+1)+num-1
    could=min(b,num+1)
    cc=b//could
    res=b % could
    ans-=res*sqr(cc+1)+(could-res)*sqr(cc)
    if flag :
        print(ans)
        list=''
        res2=could-res
        if could==num+1 :
            list+='x'*cc
            res2-=1
        ta=a
        list+='o'*(a-num+1)
        ta-=a-num+1
        while ta>0 :
            u=cc+int(res>0)
            if res>0 :
                res-=1
            else :
                res2-=1
            list+='x'*u
            list+='o'
            ta-=1
        if res>0 or res2>0 :
            list+='x'*(cc+int(res>0))
        print(str(list))
    return ans
if a==0 :
    print(-sqr(b))
    print('x'*b)
elif b==0 :
    print(sqr(a))
    print('o'*a)
else :
    now=1
    for i in range(1,a+1):
        if i-1<=b and work(i)>work(now):
            now=i
    work(now,1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var bot : boolean := true ;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    skip ;
    skip ;
    if a = 0 then  (
      execute (-sqr(b))->display() ;
    execute (StringLib.nCopies('x', b))->display()
    )
    else (if b = 0 then
   (
      execute (sqr(a))->display() ;
    execute (StringLib.nCopies('o', a))->display()    
)
    else (
      var now : int := 1 ;
    for i : Integer.subrange(1, a + 1-1) do (    if (i - 1->compareTo(b)) <= 0 & (work(i)->compareTo(work(now))) > 0 then (
      now := i
    ) else skip) ;
    work(now, 1)
      )    )
;
  operation sqr(x : OclAny) : OclAny
  pre: true post: true
  activity:
    return x * x;
  operation work(num : OclAny, flag : int) : OclAny
  pre: true post: true
  activity:
    if flag->oclIsUndefined() then flag := 0 else skip;
    var ans : double := sqr(a - num + 1) + num - 1 ;
    var could : OclAny := Set{b, num + 1}->min() ;
    var cc : int := b div could ;
    var res : int := b mod could ;
    ans := ans - res * sqr(cc + 1) + (could - res) * sqr(cc) ;
    if flag then (
      execute (ans)->display() ;
    var OclType["Sequence"] : String := '' ;
    var res2 : double := could - res ;
    if could = num + 1 then (
      OclType["Sequence"] := OclType["Sequence"] + StringLib.nCopies('x', cc) ;
    res2 := res2 - 1
    ) else skip ;
    var ta : OclAny := a ;
    OclType["Sequence"] := OclType["Sequence"] + StringLib.nCopies('o', (a - num + 1)) ;
    ta := ta - a - num + 1 ;
    while ta > 0 do (    var u : int := cc + ("" + ((res > 0)))->toInteger() ;
    if res > 0 then  (
      res := res - 1
    )
    else (
      res2 := res2 - 1
      ) ;
    OclType["Sequence"] := OclType["Sequence"] + StringLib.nCopies('x', u) ;
    OclType["Sequence"] := OclType["Sequence"] + 'o' ;
    ta := ta - 1) ;
    if res > 0 or res2 > 0 then (
      OclType["Sequence"] := OclType["Sequence"] + StringLib.nCopies('x', (cc + ("" + ((res > 0)))->toInteger()))
    ) else skip ;
    execute (("" + ((OclType["Sequence"]))))->display()
    ) else skip ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
import sys
inp=input().split()
a=int(inp[0])
b=int(inp[1])
if a==0 :
    print(str(-b**2))
    out="x"*b
    print(out)
elif b==0 :
    print(str(a**2))
    out="o"*a
    print(out)
else :
    ind=-1
    buk=-1
    quo=-1
    rem=-1
    sco=-sys.maxsize-1
    for i in range(a):
        buk_i=i+2
        quo_i=int(b/buk_i)
        rem_i=b % buk_i
        sco_i=(a-i)**2+i-rem_i*(quo_i+1)**2-(buk_i-rem_i)*quo_i**2
        if sco_i>sco :
            buk=buk_i
            quo=quo_i
            rem=rem_i
            sco=sco_i
            ind=i
    print(sco)
    out="x"*quo+"o"*(a-ind-1)
    for i in range(rem):
        out+="o"+"x"*(quo+1)
    for i in range(buk-rem-1):
        out+="o"+"x"*quo
    print(out)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var inp : OclAny := input().split() ;
    var a : int := ("" + ((inp->first())))->toInteger() ;
    var b : int := ("" + ((inp[1+1])))->toInteger() ;
    if a = 0 then  (
      execute (("" + ((-(b)->pow(2)))))->display() ;
    var out : String := StringLib.nCopies("x", b) ;
    execute (out)->display()
    )
    else (if b = 0 then
   (
      execute (("" + (((a)->pow(2)))))->display() ;
    out := StringLib.nCopies("o", a) ;
    execute (out)->display()    
)
    else (
      var ind : int := -1 ;
    var buk : int := -1 ;
    var quo : int := -1 ;
    var rem : int := -1 ;
    var sco : double := -(trailer . (name maxsize)) - 1 ;
    for i : Integer.subrange(0, a-1) do (    var buk_i : OclAny := i + 2 ;
    var quo_i : int := ("" + ((b / buk_i)))->toInteger() ;
    var rem_i : int := b mod buk_i ;
    var sco_i : double := ((a - i))->pow(2) + i - rem_i * ((quo_i + 1))->pow(2) - (buk_i - rem_i) * (quo_i)->pow(2) ;
    if (sco_i->compareTo(sco)) > 0 then (
      buk := buk_i ;
    quo := quo_i ;
    rem := rem_i ;
    sco := sco_i ;
    ind := i
    ) else skip) ;
    execute (sco)->display() ;
    out := StringLib.nCopies("x", quo) + StringLib.nCopies("o", (a - ind - 1)) ;
    for i : Integer.subrange(0, rem-1) do (    out := out + "o" + StringLib.nCopies("x", (quo + 1))) ;
    for i : Integer.subrange(0, buk - rem - 1-1) do (    out := out + "o" + StringLib.nCopies("x", quo)) ;
    execute (out)->display()
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def printModulus(X,Y):
    n=max(X,Y)
    for i in range(1,n+1):
        if(X % i==Y % i):
            print(i,end=" ")
X=10
Y=20
printModulus(X,Y)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    X := 10 ;
    Y := 20 ;
    printModulus(X, Y);
  operation printModulus(X : OclAny, Y : OclAny)
  pre: true post: true
  activity:
    var n : OclAny := Set{X, Y}->max() ;
    for i : Integer.subrange(1, n + 1-1) do (    if (X mod i = Y mod i) then (
      execute (i)->display()
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def max_U_element(a,N,M):
    hsh=dict()
    dist_count=0
    res=0
    for i in range(M):
        if(arr[i]not in hsh.keys()):
            hsh[a[i]]=1
            dist_count+=1
        else :
            hsh[a[i]]+=1
    res=dist_count
    for i in range(M,N):
        if(a[i-M]in hsh.keys()and hsh[a[i-M]]==1):
            del hsh[a[i-M]]
            dist_count-=1
        else :
            hsh[a[i-M]]-=1
        if(a[i]not in hsh.keys()):
            hsh[a[i]]=1
            dist_count+=1
        else :
            hsh[a[i]]+=1
        res=max(res,dist_count)
    return res
arr=[1,2,1,3,4,2,3]
M=4
N=len(arr)
print(max_U_element(arr,N,M))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var arr : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{3}->union(Sequence{4}->union(Sequence{2}->union(Sequence{ 3 })))))) ;
    M := 4 ;
    N := (arr)->size() ;
    execute (max_U_element(arr, N, M))->display();
  operation max_U_element(a : OclAny, N : OclAny, M : OclAny) : OclAny
  pre: true post: true
  activity:
    var hsh : Map := (arguments ( )) ;
    var dist_count : int := 0 ;
    var res : int := 0 ;
    for i : Integer.subrange(0, M-1) do (    if ((hsh.keys())->excludes(arr[i+1])) then  (
      hsh[a[i+1]+1] := 1 ;
    dist_count := dist_count + 1
    )
    else (
      hsh[a[i+1]+1] := hsh[a[i+1]+1] + 1
      )) ;
    res := dist_count ;
    for i : Integer.subrange(M, N-1) do (    if ((hsh.keys())->includes(a[i - M+1]) & hsh[a[i - M+1]+1] = 1) then  (
      execute (hsh[a[i - M+1]+1])->isDeleted() ;
    dist_count := dist_count - 1
    )
    else (
      hsh[a[i - M+1]+1] := hsh[a[i - M+1]+1] - 1
      ) ;
    if ((hsh.keys())->excludes(a[i+1])) then  (
      hsh[a[i+1]+1] := 1 ;
    dist_count := dist_count + 1
    )
    else (
      hsh[a[i+1]+1] := hsh[a[i+1]+1] + 1
      ) ;
    res := Set{res, dist_count}->max()) ;
    return res;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
INT_MIN,INT_MAX=float('-inf'),float('inf')
class NodeDetails :
    def __init__(self,data,min,max):
        self.data=data
        self.min=min
        self.max=max
def levelOrderIsOfBST(arr,n):
    if n==0 :
        return True
    q=[]
    i=0
    newNode=NodeDetails(arr[i],INT_MIN,INT_MAX)
    i+=1
    q.append(newNode)
    while i!=n and len(q)!=0 :
        temp=q.pop(0)
        if itemp.min):
            newNode=NodeDetails(arr[i],temp.min,temp.data)
            i+=1
            q.append(newNode)
        if itemp.data and arr[i]exists( _x | result = _x );
  attribute data : OclAny := data;
  attribute min : OclAny := min;
  attribute max : OclAny := max;
  operation initialise(data : OclAny,min : OclAny,max : OclAny) : NodeDetails
  pre: true post: true
  activity:
    self.data := data ;
    self.min := min ;
    self.max := max;
    return self;
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var INT_MIN : OclAny := null;
    var INT_MAX : OclAny := null;
    Sequence{INT_MIN,INT_MAX} := Sequence{("" + (('-inf')))->toReal(),("" + (('inf')))->toReal()} ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      arr := Sequence{7}->union(Sequence{4}->union(Sequence{12}->union(Sequence{3}->union(Sequence{6}->union(Sequence{8}->union(Sequence{1}->union(Sequence{5}->union(Sequence{ 10 })))))))) ;
    n := (arr)->size() ;
    if levelOrderIsOfBST(arr, n) then  (
      execute ("Yes")->display()
    )
    else (
      execute ("No")->display()
      )
    ) else skip;
  operation levelOrderIsOfBST(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    if n = 0 then (
      return true
    ) else skip ;
    var q : Sequence := Sequence{} ;
    var i : int := 0 ;
    var newNode : NodeDetails := (NodeDetails.newNodeDetails()).initialise(arr[i+1], INT_MIN, INT_MAX) ;
    i := i + 1 ;
    execute ((newNode) : q) ;
    while i /= n & (q)->size() /= 0 do (    var temp : OclAny := q->at(0`firstArg+1) ;     q := q->excludingAt(0+1) ;
    if (i->compareTo(n)) < 0 & ((arr[i+1]->compareTo(temp.data)) < 0 & (arr[i+1]->compareTo(temp.min)) > 0) then (
      newNode := (NodeDetails.newNodeDetails()).initialise(arr[i+1], temp.min, temp.data) ;
    i := i + 1 ;
    execute ((newNode) : q)
    ) else skip ;
    if (i->compareTo(n)) < 0 & ((arr[i+1]->compareTo(temp.data)) > 0 & (arr[i+1]->compareTo(temp.max)) < 0) then (
      newNode := (NodeDetails.newNodeDetails()).initialise(arr[i+1], temp.data, temp.max) ;
    i := i + 1 ;
    execute ((newNode) : q)
    ) else skip) ;
    if i = n then (
      return true
    ) else skip ;
    return false;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from typing import List,Dict
nb_intersections=int(input())
arr1=list(map(int,input().split()))
def solution(shortcuts : List[int],nb_intersections : int)->List[int]:
    answers=[0]*nb_intersections
    shortcuts_dict=to_dict(shortcuts)
    for i in range(1,nb_intersections):
        if i not in shortcuts_dict :
            answers[i]=answers[i-1]+1
        else :
            origins=shortcuts_dict[i]+[i-1]
            try :
                origins.remove(i)
            except ValueError :
                pass
            answers[i]=min(answers[origin]for origin in origins)+1
            retro_check(answers,i)
    return answers
def to_dict(shortcuts : List[int])->Dict[int,List[int]]:
    shortcuts_dict={}
    for index,value in enumerate(shortcuts):
        try :
            shortcuts_dict[value-1].append(index)
        except KeyError :
            shortcuts_dict[value-1]=[index]
    return shortcuts_dict
def retro_check(answers : List[int],i : int)->None :
    while i>0 and(answers[i]<=answers[i-1]-2):
        answers[i-1]=answers[i]+1
        i-=1
answer=solution(arr1,nb_intersections)
print(" ".join([str(i)for i in answer]))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var nb_intersections : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var arr1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    skip ;
    skip ;
    skip ;
    var answer : OclAny := solution(arr1, nb_intersections) ;
    execute (StringLib.sumStringsWithSeparator((answer->select(i | true)->collect(i | (("" + ((i)))))), " "))->display();
  operation solution(shortcuts : List[OclType["int"]+1], nb_intersections : int) : OclAny
  pre: true post: true
  activity:
    var answers : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, nb_intersections) ;
    var shortcuts_dict : OclAny := to_dict(shortcuts) ;
    for i : Integer.subrange(1, nb_intersections-1) do (    if (shortcuts_dict)->excludes(i) then  (
      answers[i+1] := answers[i - 1+1] + 1
    )
    else (
      var origins : OclAny := shortcuts_dict[i+1]->union(Sequence{ i - 1 }) ;
    try (    execute ((i) /: origins))
(except_clause except (test (logical_test (comparison (expr (atom (name ValueError)))))) : (suite (stmt (simple_stmt (small_stmt pass))))) ;
    answers[i+1] := ((argument (test (logical_test (comparison (expr (atom (name answers)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name origin)))))))) ])))))) (comp_for for (exprlist (expr (atom (name origin)))) in (logical_test (comparison (expr (atom (name origins))))))))->min() + 1 ;
    retro_check(answers, i)
      )) ;
    return answers;
  operation to_dict(shortcuts : List[OclType["int"]+1]) : OclAny
  pre: true post: true
  activity:
    shortcuts_dict := Set{} ;
    for _tuple : Integer.subrange(1, (shortcuts)->size())->collect( _indx | Sequence{_indx-1, (shortcuts)->at(_indx)} ) do (var _indx : int := 1;
      var index : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var value : OclAny := _tuple->at(_indx);
      try ((expr (atom (name shortcuts_dict)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name value))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name index)))))))) )))))
(except_clause except (test (logical_test (comparison (expr (atom (name KeyError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name shortcuts_dict)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name value))) - (expr (atom (number (integer 1)))))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name index))))))) ])))))))))))))) ;
    return shortcuts_dict;
  operation retro_check(answers : List[OclType["int"]+1], i : int) : OclAny
  pre: true post: true
  activity:
    while i > 0 & ((answers[i+1]->compareTo(answers[i - 1+1] - 2)) <= 0) do (    answers[i - 1+1] := answers[i+1] + 1 ;
    i := i - 1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
pin=sys.stdin.readline
N=int(pin())
A=list(map(int,pin().split()))
B=list(map(int,pin().split()))
C=list(reversed(B))
for i in range(N):
    if A[i]==C[i]:
        break
else :
    print("Yes")
    for k in C :
        sys.stdout.write(f"{k}")
    print()
    sys.exit()
D=B[N//2 :]+B[: N//2]
for j in range(N):
    if A[j]==D[j]:
        print("No")
        break
else :
    print("Yes")
    for l in D :
        sys.stdout.write(f"{l}")
    print()
    sys.exit()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var pin : OclAny := (OclFile["System.in"]).readline ;
    var N : int := ("" + ((pin())))->toInteger() ;
    var A : Sequence := ((pin().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var B : Sequence := ((pin().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var C : Sequence := ((B)->reverse()) ;
(compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (name C)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Yes"))))))) )))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name k)))) in (testlist (test (logical_test (comparison (expr (atom (name C))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom f "{k}"))))))) ))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name exit) (arguments ( ))))))))))))))) ;
    var D : OclAny := B.subrange(N div 2+1) + B.subrange(1,N div 2) ;
(compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) == (comparison (expr (atom (name D)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "No"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Yes"))))))) )))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name l)))) in (testlist (test (logical_test (comparison (expr (atom (name D))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom f "{l}"))))))) ))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name exit) (arguments ( )))))))))))))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import Counter,deque
N=int(input())
A=list(map(int,input().split()))+[N+1]
B=list(map(int,input().split()))+[N+1]
C=[0]
D=[0]
AB_cn=Counter(A+B)
if AB_cn.most_common()[0][1]>N :
    print("No")
else :
    print("Yes")
    for i in range(N+1):
        if len(C)!=A[i]:
            C.extend([i]*(A[i]-len(C)))
        if len(D)!=B[i]:
            D.extend([i]*(B[i]-len(D)))
    ans=0
    for i in range(N):
        curr=C[i+1]-D[i]
        ans=max(curr,ans)
    B=B[:-1]
    print(*[B[(i-ans)% N]for i in range(N)])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->union(Sequence{ N + 1 }) ;
    var B : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->union(Sequence{ N + 1 }) ;
    var C : Sequence := Sequence{ 0 } ;
    var D : Sequence := Sequence{ 0 } ;
    var AB_cn : OclAny := Counter(A->union(B)) ;
    if (AB_cn.most_common()->first()[1+1]->compareTo(N)) > 0 then  (
      execute ("No")->display()
    )
    else (
      execute ("Yes")->display() ;
    for i : Integer.subrange(0, N + 1-1) do (    if (C)->size() /= A[i+1] then (
      C := C->union(MatrixLib.elementwiseMult(Sequence{ i }, (A[i+1] - (C)->size())))
    ) else skip ;
    if (D)->size() /= B[i+1] then (
      D := D->union(MatrixLib.elementwiseMult(Sequence{ i }, (B[i+1] - (D)->size())))
    ) else skip) ;
    var ans : int := 0 ;
    for i : Integer.subrange(0, N-1) do (    var curr : double := C[i + 1+1] - D[i+1] ;
    ans := Set{curr, ans}->max()) ;
    B := B->front() ;
    execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name B)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (name ans)))))))) ))) % (expr (atom (name N))))))))) ])))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))) ])))))))->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
from collections import Counter
from itertools import accumulate
read=sys.stdin.read
readline=sys.stdin.readline
readlines=sys.stdin.readlines
sys.setrecursionlimit(10**9)
INF=1<<60
MOD=1000000007
def main():
    N=int(readline())
    A=list(map(int,readline().split()))
    B=list(map(int,readline().split()))
    counterA=Counter(A)
    counterB=Counter(B)
    for i in range(1,N+1):
        if counterA[i]+counterB[i]>N :
            print('No')
            return
    C=[0]*(N+1)
    D=[0]*(N+1)
    for a in A :
        C[a]+=1
    for b in B :
        D[b]+=1
    C=list(accumulate(C))
    D=list(accumulate(D))
    x=max(C[i]-D[i-1]for i in range(1,N+1))
    ans=[0]*N
    for i in range(N):
        ans[i]=B[(i-x)% N]
    print('Yes')
    print(*ans)
    return
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    var read : OclAny := (OclFile["System.in"]).read ;
    var readline : OclAny := (OclFile["System.in"]).readline ;
    var readlines : OclAny := (OclFile["System.in"]).readlines ;
    sys.setrecursionlimit((10)->pow(9)) ;
    var INF : int := 1 * (2->pow(60)) ;
    var MOD : int := 1000000007 ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var N : int := ("" + ((readline())))->toInteger() ;
    var A : Sequence := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var B : Sequence := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var counterA : OclAny := Counter(A) ;
    var counterB : OclAny := Counter(B) ;
    for i : Integer.subrange(1, N + 1-1) do (    if (counterA[i+1] + counterB[i+1]->compareTo(N)) > 0 then (
      execute ('No')->display() ;
    return
    ) else skip) ;
    var C : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ;
    var D : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ;
    for a : A do (    C[a+1] := C[a+1] + 1) ;
    for b : B do (    D[b+1] := D[b+1] + 1) ;
    C := (accumulate(C)) ;
    D := (accumulate(D)) ;
    var x : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name C)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name D)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name N))) + (expr (atom (number (integer 1)))))))))) )))))))))->max() ;
    var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ;
    for i : Integer.subrange(0, N-1) do (    ans[i+1] := B[(i - x) mod N+1]) ;
    execute ('Yes')->display() ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ;
    return;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    n=int(input())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    ai,bi=0,0
    stride=0
    while ain :
                print('No')
                exit()
            if stridetoInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var ai : OclAny := null;
    var bi : OclAny := null;
    Sequence{ai,bi} := Sequence{0,0} ;
    var stride : int := 0 ;
    while (ai->compareTo(n)) < 0 & (bi->compareTo(n)) < 0 do (    var ax : OclAny := null;
    var bx : OclAny := null;
    Sequence{ax,bx} := Sequence{a[ai+1],b[bi+1]} ;
    if ax = bx then  (
      var cnt : int := 2 ;
    ai := ai + 1 ;
    while (ai->compareTo(n)) < 0 & a[ai+1] = ax do (    cnt := cnt + 1 ;
    ai := ai + 1) ;
    var bi_copy : OclAny := bi ;
    bi := bi + 1 ;
    while (bi->compareTo(n)) < 0 & b[bi+1] = bx do (    cnt := cnt + 1 ;
    bi := bi + 1) ;
    if (cnt->compareTo(n)) > 0 then (
      execute ('No')->display() ;
    exit()
    ) else skip ;
    if (stride->compareTo(ai - bi_copy)) < 0 then (
      stride := ai - bi_copy
    ) else skip
    )
    else (if (ax->compareTo(bx)) < 0 then
   (
      ai := ai + 1    
)
    else (
      bi := bi + 1
      )    )
) ;
    execute ('Yes')->display() ;
    execute (StringLib.sumStringsWithSeparator(((b.subrange(n - stride+1) + b.subrange(1,n - stride))->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
A=[]
while True :
    m,f,r=[int(i)for i in input().split()]
    if m==f==r==-1 :
        break
    elif m==-1 or f==-1 :
        A.append('F')
    elif m+f>=80 :
        A.append('A')
    elif 65<=m+f<80 :
        A.append('B')
    elif(50<=m+f<65)or((30<=m+f<50)and(50<=r)):
        A.append('C')
    elif(30<=m+f<50):
        A.append('D')
    else :
        A.append('F')
for i in A :
    print(i)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var A : Sequence := Sequence{} ;
    while true do (    var m : OclAny := null;
    var f : OclAny := null;
    var r : OclAny := null;
    Sequence{m,f,r} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    if m = f & (f == r) & (r == -1) then  (
      break
    )
    else (if m = -1 or f = -1 then
   (
      execute (('F') : A)    
)
    else (if m + f >= 80 then
   (
      execute (('A') : A)    
)
    else (if 65 <= m + f & (m + f < 80) then
   (
      execute (('B') : A)    
)
    else (if (50 <= m + f & (m + f < 65)) or ((30 <= m + f & (m + f < 50)) & (50 <= r)) then
   (
      execute (('C') : A)    
)
    else (if (30 <= m + f & (m + f < 50)) then
   (
      execute (('D') : A)    
)
    else (
      execute (('F') : A)
      )    )
    )
    )
    )
    )
) ;
    for i : A do (    execute (i)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
INF=1<<60
MOD=10**9+7
sys.setrecursionlimit(2147483647)
input=lambda : sys.stdin.readline().rstrip()
from collections import Counter
from random import randrange
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    if Counter(A+B).most_common()[0][1]>n :
        print("No")
        return
    for i in range(n):
        if A[i]!=B[i]:
            continue
        while 1 :
            j=randrange(0,n)
            if A[i]!=B[j]and A[j]!=B[i]:
                B[i],B[j]=B[j],B[i]
                break
    print("Yes")
    print(*B)
resolve()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var INF : int := 1 * (2->pow(60)) ;
    var MOD : double := (10)->pow(9) + 7 ;
    sys.setrecursionlimit(2147483647) ;
    var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ;
    skip ;
    skip ;
    skip ;
    resolve();
  operation resolve()
  pre: true post: true
  activity:
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var A : Sequence := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var B : Sequence := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if (Counter(A->union(B)).most_common()->first()[1+1]->compareTo(n)) > 0 then (
      execute ("No")->display() ;
    return
    ) else skip ;
    for i : Integer.subrange(0, n-1) do (    if A[i+1] /= B[i+1] then (
      continue
    ) else skip ;
    while 1 do (    var j : OclAny := randrange(0, n) ;
    if A[i+1] /= B[j+1] & A[j+1] /= B[i+1] then (
      var B[i+1] : OclAny := null;
    var B[j+1] : OclAny := null;
    Sequence{B[i+1],B[j+1]} := Sequence{B[j+1],B[i+1]} ;
    break
    ) else skip)) ;
    execute ("Yes")->display() ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name B))))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
K=int(input())
A,B=map(int,input().split())
flg=False
for i in range(A,B+1):
    if i % K==0 :
        flg=True
if flg :
    print('OK')
else :
    print('NG')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var A : OclAny := null;
    var B : OclAny := null;
    Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var flg : boolean := false ;
    for i : Integer.subrange(A, B + 1-1) do (    if i mod K = 0 then (
      flg := true
    ) else skip) ;
    if flg then  (
      execute ('OK')->display()
    )
    else (
      execute ('NG')->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def solve(K : int,A : int,B : int):
    for i in range(A,B+1):
        if i % K==0 :
            print("OK")
            exit()
    print("NG")
    return
def main():
    def iterate_tokens():
        for line in sys.stdin :
            for word in line.split():
                yield word
    tokens=iterate_tokens()
    K=int(next(tokens))
    A=int(next(tokens))
    B=int(next(tokens))
    solve(K,A,B)
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation solve(K : int, A : int, B : int)
  pre: true post: true
  activity:
    for i : Integer.subrange(A, B + 1-1) do (    if i mod K = 0 then (
      execute ("OK")->display() ;
    exit()
    ) else skip) ;
    execute ("NG")->display() ;
    return;
  operation main()
  pre: true post: true
  activity:
    skip ;
    var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ;
    var K : int := ("" + (((tokens).next())))->toInteger() ;
    var A : int := ("" + (((tokens).next())))->toInteger() ;
    var B : int := ("" + (((tokens).next())))->toInteger() ;
    solve(K, A, B);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a,b,c): return[[c]*b for i in range(a)]
def list3d(a,b,c,d): return[[[d]*c for j in range(b)]for i in range(a)]
def list4d(a,b,c,d,e): return[[[[e]*d for j in range(c)]for j in range(b)]for i in range(a)]
def ceil(x,y=1): return int(-(-x//y))
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LIST(N=None): return list(MAP())if N is None else[INT()for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
K=INT()
a,b=MAP()
x=ceil(a,K)
y=b//K
if x>y :
    print('NG')
else :
    print('OK')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    sys.setrecursionlimit((10)->pow(9)) ;
    var INF : double := (10)->pow(18) ;
    var MOD : double := (10)->pow(9) + 7 ;
    var K : OclAny := INT() ;
    Sequence{a,b} := MAP() ;
    x := ceil(a, K) ;
    y := b div K ;
    if (x->compareTo(y)) > 0 then  (
      execute ('NG')->display()
    )
    else (
      execute ('OK')->display()
      );
  operation input() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine()->trim();
  operation list2d(a : OclAny, b : OclAny, c : OclAny) : OclAny
  pre: true post: true
  activity:
    return Integer.subrange(0, a-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ c }, b)));
  operation list3d(a : OclAny, b : OclAny, c : OclAny, d : OclAny) : OclAny
  pre: true post: true
  activity:
    return Integer.subrange(0, a-1)->select(i | true)->collect(i | (Integer.subrange(0, b-1)->select(j | true)->collect(j | (MatrixLib.elementwiseMult(Sequence{ d }, c)))));
  operation list4d(a : OclAny, b : OclAny, c : OclAny, d : OclAny, e : OclAny) : OclAny
  pre: true post: true
  activity:
    return Integer.subrange(0, a-1)->select(i | true)->collect(i | (Integer.subrange(0, b-1)->select(j | true)->collect(j | (Integer.subrange(0, c-1)->select(j | true)->collect(j | (MatrixLib.elementwiseMult(Sequence{ e }, d)))))));
  operation ceil(x : OclAny, y : int) : OclAny
  pre: true post: true
  activity:
    if y->oclIsUndefined() then y := 1 else skip;
    return ("" + ((-(-x div y))))->toInteger();
  operation INT() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation MAP() : OclAny
  pre: true post: true
  activity:
    return (input().split())->collect( _x | (OclType["int"])->apply(_x) );
  operation LIST(N : OclAny) : OclAny
  pre: true post: true
  activity:
    if N->oclIsUndefined() then N := null else skip;
    return if N <>= null then (MAP()) else Integer.subrange(0, N-1)->select(i | true)->collect(i | (INT())) endif;
  operation Yes()
  pre: true post: true
  activity:
    execute ('Yes')->display();
  operation No()
  pre: true post: true
  activity:
    execute ('No')->display();
  operation YES()
  pre: true post: true
  activity:
    execute ('YES')->display();
  operation NO()
  pre: true post: true
  activity:
    execute ('NO')->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def solve(*args : str)->str :
    k=int(args[0])
    a,b=map(int,args[1].split())
    return 'OK' if-(-a//k)*k<=b else 'NG'
if __name__=="__main__" :
    print(solve(*(open(0).read().splitlines())))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      execute (solve((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name open)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))) (trailer . (name read) (arguments ( ))) (trailer . (name splitlines) (arguments ( )))))))) )))))))))->display()
    ) else skip;
  operation solve(args : String : Sequence(OclAny)) : String
  pre: true post: true
  activity:
(args * (named_parameter (name args) : (test (logical_test (comparison (expr (atom (name str))))))))    var k : int := ("" + ((args->first())))->toInteger() ;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (args[1+1].split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    return if (-(-a div k) * k->compareTo(b)) <= 0 then 'OK' else 'NG' endif;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import collections
def GetMinimumEnergySpent(n,shortcuts):
    energy_spent=[i for i in range(n)]
    queue=collections.deque()
    dict_shortcuts=collections.defaultdict(set)
    for idx,shortcut in enumerate(shortcuts):
        dict_shortcuts[idx].add(shortcut)
        queue.append(idx)
    while len(queue)>0 :
        idx=queue.popleft()
        if idxenergy_spent[idx]+1 :
            energy_spent[idx+1]=energy_spent[idx]+1
            queue.append(idx+1)
        if idx>0 and energy_spent[idx-1]>energy_spent[idx]+1 :
            energy_spent[idx-1]=energy_spent[idx]+1
            queue.append(idx-1)
        for shortcut in dict_shortcuts[idx]:
            if energy_spent[idx]+1toInteger() ;
    shortcuts := input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger() - 1)) ;
    var energy_spent_str : Sequence := GetMinimumEnergySpent(n, shortcuts)->select(k | true)->collect(k | (("" + ((k))))) ;
    execute (StringLib.sumStringsWithSeparator((energy_spent_str), ' '))->display()
    ) else skip;
  operation GetMinimumEnergySpent(n : OclAny, shortcuts : OclAny) : OclAny
  pre: true post: true
  activity:
    var energy_spent : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)) ;
    var queue : Sequence := () ;
    var dict_shortcuts : OclAny := .defaultdict(OclType["Set"]) ;
    for _tuple : Integer.subrange(1, (shortcuts)->size())->collect( _indx | Sequence{_indx-1, (shortcuts)->at(_indx)} ) do (var _indx : int := 1;
      var idx : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var shortcut : OclAny := _tuple->at(_indx);
  (expr (atom (name dict_shortcuts)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name idx)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name shortcut)))))))) )))) ;
    execute ((idx) : queue)) ;
    while (queue)->size() > 0 do (    var idx : OclAny := queue->first() ;     queue := queue->tail() ;
    if (idx->compareTo(n - 1)) < 0 & (energy_spent[idx + 1+1]->compareTo(energy_spent[idx+1] + 1)) > 0 then (
      energy_spent[idx + 1+1] := energy_spent[idx+1] + 1 ;
    execute ((idx + 1) : queue)
    ) else skip ;
    if idx > 0 & (energy_spent[idx - 1+1]->compareTo(energy_spent[idx+1] + 1)) > 0 then (
      energy_spent[idx - 1+1] := energy_spent[idx+1] + 1 ;
    execute ((idx - 1) : queue)
    ) else skip ;
    for shortcut : dict_shortcuts[idx+1] do (    if (energy_spent[idx+1] + 1->compareTo(energy_spent[shortcut+1])) < 0 then (
      energy_spent[shortcut+1] := energy_spent[idx+1] + 1 ;
    execute ((shortcut) : queue)
    ) else skip)) ;
    return energy_spent;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
K=int(input())
A,B=[int(i)for i in input().split(" ")]
for m in range(A,B+1):
    if m % K==0 :
        print("OK")
        break
else :
    print("NG")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var A : OclAny := null;
    var B : OclAny := null;
    Sequence{A,B} := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
(compound_stmt for (exprlist (expr (atom (name m)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name B))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name m))) % (expr (atom (name K))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "OK"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NG"))))))) )))))))))))))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import bisect
import collections
import itertools
def getint(): return int(input())
def getints(): return list(map(int,input().split()))
def getint2d(rows): return[getints()for _ in range(rows)]
def getgrid(rows): return[input()for _ in range(rows)]
def array1d(n,value): return[value for _ in range(n)]
def array2d(n,m,value): return[array1d(m,value)for _ in range(n)]
n=input()
s=input()
l,r=0,0
for c in s :
    if c=='(' :
        r+=1
    else :
        if r :
            r-=1
        else :
            l+=1
res="("*l+s+")"*r
print(res)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    n := (OclFile["System.in"]).readLine() ;
    var s : String := (OclFile["System.in"]).readLine() ;
    var l : OclAny := null;
    var r : OclAny := null;
    Sequence{l,r} := Sequence{0,0} ;
    for c : s->characters() do (    if c = '(' then  (
      r := r + 1
    )
    else (
      if r then  (
      r := r - 1
    )
    else (
      l := l + 1
      )
      )) ;
    var res : String := StringLib.nCopies("(", l) + s + StringLib.nCopies(")", r) ;
    execute (res)->display();
  operation getint() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation getints() : OclAny
  pre: true post: true
  activity:
    return ((input().split())->collect( _x | (OclType["int"])->apply(_x) ));
  operation getint2d(rows : OclAny) : OclAny
  pre: true post: true
  activity:
    return Integer.subrange(0, rows-1)->select(_anon | true)->collect(_anon | (getints()));
  operation getgrid(rows : OclAny) : OclAny
  pre: true post: true
  activity:
    return Integer.subrange(0, rows-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine()));
  operation array1d(n : OclAny, value : OclAny) : OclAny
  pre: true post: true
  activity:
    return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (value));
  operation array2d(n : OclAny, m : OclAny, value : OclAny) : OclAny
  pre: true post: true
  activity:
    return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (array1d(m, value)));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
def main():
    n=II()
    s=input()
    A=[]
    if s[0]==")" :
        A.append(0)
    s+="0"
    cnt=1
    for i in range(n):
        if s[i]==s[i+1]:
            cnt+=1
        else :
            A.append(cnt)
            cnt=1
    l=0
    r=0
    now=0
    for i in range(len(A)):
        if i % 2 :
            r+=2*min(A[i],now)
            l+=max(A[i]-now,0)
            now=max(now-A[i],0)
        else :
            now+=A[i]
    ans="("*l+s[:-1]+")"*(n-l-r)
    print(ans)
if __name__=="__main__" :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      main()
    ) else skip;
  operation RD() : OclAny
  pre: true post: true
  activity:
    return (OclFile["System.in"]).readAll();
  operation II() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation MI() : OclAny
  pre: true post: true
  activity:
    return (input().split())->collect( _x | (OclType["int"])->apply(_x) );
  operation MF() : OclAny
  pre: true post: true
  activity:
    return (input().split())->collect( _x | (OclType["double"])->apply(_x) );
  operation LI() : OclAny
  pre: true post: true
  activity:
    return ((input().split())->collect( _x | (OclType["int"])->apply(_x) ));
  operation LF() : OclAny
  pre: true post: true
  activity:
    return ((input().split())->collect( _x | (OclType["double"])->apply(_x) ));
  operation TI() : OclAny
  pre: true post: true
  activity:
    return ((input().split())->collect( _x | (OclType["int"])->apply(_x) ));
  operation main()
  pre: true post: true
  activity:
    var n : OclAny := II() ;
    var s : String := (OclFile["System.in"]).readLine() ;
    var A : Sequence := Sequence{} ;
    if s->first() = ")" then (
      execute ((0) : A)
    ) else skip ;
    s := s + "0" ;
    var cnt : int := 1 ;
    for i : Integer.subrange(0, n-1) do (    if s[i+1] = s[i + 1+1] then  (
      cnt := cnt + 1
    )
    else (
      execute ((cnt) : A) ;
    cnt := 1
      )) ;
    var l : int := 0 ;
    var r : int := 0 ;
    var now : int := 0 ;
    for i : Integer.subrange(0, (A)->size()-1) do (    if i mod 2 then  (
      r := r + 2 * Set{A[i+1], now}->min() ;
    l := l + Set{A[i+1] - now, 0}->max() ;
    now := Set{now - A[i+1], 0}->max()
    )
    else (
      now := now + A[i+1]
      )) ;
    var ans : String := StringLib.nCopies("(", l) + s->front() + StringLib.nCopies(")", (n - l - r)) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input=sys.stdin.readline
mod=10**9+7
Max=sys.maxsize
def l():
    return list(map(int,input().split()))
def m():
    return map(int,input().split())
def onem():
    return int(input())
def s(x):
    a=[]
    aa=x[0]
    su=1
    for i in range(len(x)-1):
        if aa!=x[i+1]:
            a.append([aa,su])
            aa=x[i+1]
            su=1
        else :
            su+=1
    a.append([aa,su])
    return a
def jo(x):
    return "".join(map(str,x))
def max2(x):
    return max(map(max,x))
def In(x,a):
    k=bs.bisect_left(a,x)
    if k!=len(a)and a[k]==x :
        return True
    else :
        return False
n=onem()
s=input().split()[0]
ss=""
co=0
for i in range(n):
    if s[i]==")" and co<=0 :
        ss="("+ss+")"
    elif s[i]==")" :
        ss=ss+")"
        co-=1
    if s[i]=="(" :
        co+=1
        ss=ss+"("
print(ss+")"*co)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    sys.setrecursionlimit(100000) ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    var mod : double := (10)->pow(9) + 7 ;
    var Max : (trailer . (name maxsize)) := (trailer . (name maxsize)) ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var n : OclAny := onem() ;
    var s : OclAny := input().split()->first() ;
    var ss : String := "" ;
    var co : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    if s[i+1] = ")" & co <= 0 then  (
      ss := "(" + ss + ")"
    )
    else (if s[i+1] = ")" then
   (
      ss := ss + ")" ;
    co := co - 1    
)
 else skip) ;
    if s[i+1] = "(" then (
      co := co + 1 ;
    ss := ss + "("
    ) else skip) ;
    execute (ss + StringLib.nCopies(")", co))->display();
  operation l() : OclAny
  pre: true post: true
  activity:
    return ((input().split())->collect( _x | (OclType["int"])->apply(_x) ));
  operation m() : OclAny
  pre: true post: true
  activity:
    return (input().split())->collect( _x | (OclType["int"])->apply(_x) );
  operation onem() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation s(x : OclAny) : OclAny
  pre: true post: true
  activity:
    var a : Sequence := Sequence{} ;
    var aa : OclAny := x->first() ;
    var su : int := 1 ;
    for i : Integer.subrange(0, (x)->size() - 1-1) do (    if aa /= x[i + 1+1] then  (
      execute ((Sequence{aa}->union(Sequence{ su })) : a) ;
    aa := x[i + 1+1] ;
    su := 1
    )
    else (
      su := su + 1
      )) ;
    execute ((Sequence{aa}->union(Sequence{ su })) : a) ;
    return a;
  operation jo(x : OclAny) : OclAny
  pre: true post: true
  activity:
    return StringLib.sumStringsWithSeparator(((x)->collect( _x | (OclType["String"])->apply(_x) )), "");
  operation max2(x : OclAny) : OclAny
  pre: true post: true
  activity:
    return ((x)->collect( _x | (max)->apply(_x) ))->max();
  operation In(x : OclAny, a : OclAny) : OclAny
  pre: true post: true
  activity:
    var k : OclAny := bs.bisect_left(a, x) ;
    if k /= (a)->size() & a[k+1] = x then  (
      return true
    )
    else (
      return false
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=int(input())
S=input()
s=S
for _ in range(50):
    s=s.replace("()","")
ans="("*s.count(")")+S+")"*s.count("(")
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var S : String := (OclFile["System.in"]).readLine() ;
    var s : String := S ;
    for _anon : Integer.subrange(0, 50-1) do (    s := s.replace("()", "")) ;
    var ans : String := StringLib.nCopies("(", s->count(")")) + S + StringLib.nCopies(")", s->count("(")) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
mod=1000000007 ;
def sumOddFibonacci(n):
    Sum=[0]*(n+1);
    Sum[0]=0 ;
    Sum[1]=1 ;
    Sum[2]=2 ;
    Sum[3]=5 ;
    Sum[4]=10 ;
    Sum[5]=23 ;
    for i in range(6,n+1):
        Sum[i]=((Sum[i-1]+(4*Sum[i-2])% mod-(4*Sum[i-3])% mod+mod)% mod+(Sum[i-4]-Sum[i-5]+mod)% mod)% mod ;
    return Sum[n];
n=6 ;
print(sumOddFibonacci(n));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var mod : int := 1000000007; ;
    skip ;
    n := 6; ;
    execute (sumOddFibonacci(n))->display();;
  operation sumOddFibonacci(n : OclAny)
  pre: true post: true
  activity:
    var Sum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); ;
    Sum->first() := 0; ;
    Sum[1+1] := 1; ;
    Sum[2+1] := 2; ;
    Sum[3+1] := 5; ;
    Sum[4+1] := 10; ;
    Sum[5+1] := 23; ;
    for i : Integer.subrange(6, n + 1-1) do (    Sum[i+1] := ((Sum[i - 1+1] + (4 * Sum[i - 2+1]) mod mod - (4 * Sum[i - 3+1]) mod mod + mod) mod mod + (Sum[i - 4+1] - Sum[i - 5+1] + mod) mod mod) mod mod;) ;
    return Sum[n+1];;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=input()
string=[x for x in input()]
strings=string[:]
stack=[]
for i in range(len(strings)):
    if strings[i]=='(' :
        stack.append(1)
    elif strings[i]==')' :
        if not stack :
            string.insert(0,'(')
        else :
            stack.pop()
if stack :
    for i in range(len(stack)):
        string.append(')')
print(''.join(string))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : String := (OclFile["System.in"]).readLine() ;
    var string : Sequence := (OclFile["System.in"]).readLine()->select(x | true)->collect(x | (x)) ;
    var strings : Sequence := string ;
    var stack : Sequence := Sequence{} ;
    for i : Integer.subrange(0, (strings)->size()-1) do (    if strings[i+1] = '(' then  (
      execute ((1) : stack)
    )
    else (if strings[i+1] = ')' then
   (
      if not(stack) then  (
      string := string.insertAt(0+1, '(')
    )
    else (
      stack := stack->front()
      )    
)
 else skip)) ;
    if stack then (
      for i : Integer.subrange(0, (stack)->size()-1) do (    execute ((')') : string))
    ) else skip ;
    execute (StringLib.sumStringsWithSeparator((string), ''))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import itertools
def compute():
    DIGITS=1000
    prev=1
    cur=0
    for i in itertools.count():
        if len(str(cur))>DIGITS :
            raise RuntimeError("Not found")
        elif len(str(cur))==DIGITS :
            return str(i)
        prev,cur=cur,prev+cur
if __name__=="__main__" :
    print(compute())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      execute (compute())->display()
    ) else skip;
  operation compute() : OclAny
  pre: true post: true
  activity:
    var DIGITS : int := 1000 ;
    var prev : int := 1 ;
    var cur : int := 0 ;
    for i : itertools->count() do (    if ((("" + ((cur))))->size()->compareTo(DIGITS)) > 0 then  (
      error RuntimeError.newRuntimeError("Not found")
    )
    else (if (("" + ((cur))))->size() = DIGITS then
   (
      return ("" + ((i)))    
)
 else skip) ;
    Sequence{prev,cur} := Sequence{cur,prev + cur});
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,s=input(),input()
if s=='0' :
    print('No')
elif s=='1' :
    print('Yes')
else :
    if('11' not in s)and('000' not in s)and s.find('00')!=0 and s[-2 :]!='00' :
        print('Yes')
    else :
        print('No')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var s : OclAny := null;
    Sequence{n,s} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine()} ;
    if s = '0' then  (
      execute ('No')->display()
    )
    else (if s = '1' then
   (
      execute ('Yes')->display()    
)
    else (
      if ((s)->excludes('11')) & ((s)->excludes('000')) & s->indexOf('00') - 1 /= 0 & s.subrange(-2+1) /= '00' then  (
      execute ('Yes')->display()
    )
    else (
      execute ('No')->display()
      )
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
input()
a='0'+input()+'0'
print("No" if "000" in a or "11" in a else "Yes")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     input() ;
    var a : String := '0' + (OclFile["System.in"]).readLine() + '0' ;
    execute (if (a)->characters()->includes("000") or (a)->characters()->includes("11") then "No" else "Yes" endif)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def horizontal_input(T=str,debug=False):
    data=list(map(T,input().split()))
    if debug :
        print(*data)
    return data
def vertical_input(n,T=str,sep=False,septype=list,debug=False):
    data=[]
    if sep :
        for i in range(n):
            data.append(septype(map(T,input().split())))
    else :
        for i in range(n):
            data.append(T(input()))
    if debug :
        print(*data,sep='\n')
    return data
def eratosthenes(n):
    prime_table=[False,False,True]+[False if i % 2!=0 else True for i in range(n-2)]
    i=3
    while i*i<=n :
        if prime_table[i]:
            j=i*i
            while j<=n :
                prime_table[j]=False
                j+=i
        i+=2
    return prime_table
prime_table=eratosthenes(2000000)
primes=[]
for i in range(len(prime_table)):
    if prime_table[i]:
        primes.append(i)
while 1 :
    n=int(input())
    if n==0 :
        break
    i=0
    while primes[i]<=n :
        i+=1
    i=primes[i-1]
    if i==n :
        print(0)
    else :
        count=1
        j=i+1
        while 1 :
            if prime_table[j]:
                break
            j+=1
            count+=1
        print(count)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    prime_table := eratosthenes(2000000) ;
    var primes : Sequence := Sequence{} ;
    for i : Integer.subrange(0, (prime_table)->size()-1) do (    if prime_table[i+1] then (
      execute ((i) : primes)
    ) else skip) ;
    while 1 do (    n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    i := 0 ;
    while (primes[i+1]->compareTo(n)) <= 0 do (    i := i + 1) ;
    i := primes[i - 1+1] ;
    if i = n then  (
      execute (0)->display()
    )
    else (
      var count : int := 1 ;
    j := i + 1 ;
    while 1 do (    if prime_table[j+1] then (
      break
    ) else skip ;
    j := j + 1 ;
    count := count + 1) ;
    execute (count)->display()
      ));
  operation horizontal_input(T : OclAny, debug : OclAny) : OclAny
  pre: true post: true
  activity:
    if T->oclIsUndefined() then T := OclType["String"] else skip;
    if debug->oclIsUndefined() then debug := false else skip;
    var data : Sequence := ((input().split())->collect( _x | (T)->apply(_x) )) ;
    if debug then (
      execute ((argument * (test (logical_test (comparison (expr (atom (name data))))))))->display()
    ) else skip ;
    return data;
  operation vertical_input(n : OclAny, T : OclAny, sep : OclAny, septype : OclAny, debug : OclAny) : OclAny
  pre: true post: true
  activity:
    if T->oclIsUndefined() then T := OclType["String"] else skip;
    if sep->oclIsUndefined() then sep := false else skip;
    if septype->oclIsUndefined() then septype := OclType["Sequence"] else skip;
    if debug->oclIsUndefined() then debug := false else skip;
    data := Sequence{} ;
    if sep then  (
      for i : Integer.subrange(0, n-1) do (    execute ((septype((input().split())->collect( _x | (T)->apply(_x) ))) : data))
    )
    else (
      for i : Integer.subrange(0, n-1) do (    execute ((T((OclFile["System.in"]).readLine())) : data))
      ) ;
    if debug then (
      execute ((argument * (test (logical_test (comparison (expr (atom (name data))))))))->display()
    ) else skip ;
    return data;
  operation eratosthenes(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var prime_table : Sequence := Sequence{false}->union(Sequence{false}->union(Sequence{ true }))->union(Integer.subrange(0, n - 2-1)->select(i | true)->collect(i | (if i mod 2 /= 0 then false else true endif))) ;
    var i : int := 3 ;
    while (i * i->compareTo(n)) <= 0 do (    if prime_table[i+1] then (
      var j : int := i * i ;
    while (j->compareTo(n)) <= 0 do (    prime_table[j+1] := false ;
    j := j + i)
    ) else skip ;
    i := i + 2) ;
    return prime_table;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
s='0'+input()+'0'
if '11' in s or '000' in s :
    print('No')
else :
    print('Yes')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : String := '0' + (OclFile["System.in"]).readLine() + '0' ;
    if (s)->characters()->includes('11') or (s)->characters()->includes('000') then  (
      execute ('No')->display()
    )
    else (
      execute ('Yes')->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
import sys
from collections import deque,OrderedDict,defaultdict
import heapq
from collections import Counter
def inp(): return sys.stdin.readline().rstrip()
def mpp(): return map(int,inp().split())
def lis(): return list(mpp())
def yn(n):
    if n :
        return "Yes"
    else :
        return "No"
def cd(s):
    return ord(s)-ord('a')+1
def fn(s):
    prev=-1
    fl=True
    for i in range(len(s)):
        if s[i]=="1" and prev==-1 :
            prev=i
            fl=False
            if i>=2 :
                return False
        elif s[i]=="1" :
            dis=i-prev
            if dis==1 or dis>=4 :
                return False
            prev=i
            fl=False
    if fl : return False
    dis=i-prev
    if dis>=2 : return False
    return True
def main():
    t=int(inp())
    s=inp()
    print(yn(fn(s)))
if __name__=="__main__" :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      main()
    ) else skip;
  operation inp() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine().rstrip();
  operation mpp() : OclAny
  pre: true post: true
  activity:
    return (inp().split())->collect( _x | (OclType["int"])->apply(_x) );
  operation lis() : OclAny
  pre: true post: true
  activity:
    return (mpp());
  operation yn(n : OclAny) : OclAny
  pre: true post: true
  activity:
    if n then  (
      return "Yes"
    )
    else (
      return "No"
      );
  operation cd(s : OclAny) : OclAny
  pre: true post: true
  activity:
    return (s)->char2byte() - ('a')->char2byte() + 1;
  operation fn(s : OclAny) : OclAny
  pre: true post: true
  activity:
    var prev : int := -1 ;
    var fl : boolean := true ;
    for i : Integer.subrange(0, (s)->size()-1) do (    if s[i+1] = "1" & prev = -1 then  (
      prev := i ;
    fl := false ;
    if i >= 2 then (
      return false
    ) else skip
    )
    else (if s[i+1] = "1" then
   (
      var dis : double := i - prev ;
    if dis = 1 or dis >= 4 then (
      return false
    ) else skip ;
    prev := i ;
    fl := false    
)
 else skip)) ;
    if fl then (
      return false
    ) else skip ;
    dis := i - prev ;
    if dis >= 2 then (
      return false
    ) else skip ;
    return true;
  operation main()
  pre: true post: true
  activity:
    var t : int := ("" + ((inp())))->toInteger() ;
    s := inp() ;
    execute (yn(fn(s)))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def read_input(input_path=None):
    if input_path is None :
        f=sys.stdin
    else :
        f=open(input_path,'r')
    n=int(f.readline())
    chairs=f.readline().strip()
    return n,chairs
def sol(n,chairs):
    chairs='0'+chairs+'0'
    return["YES" if "11" not in chairs and "000" not in chairs else "NO"]
def solve(input_path=None):
    return sol(*read_input(input_path))
def main():
    for line in sol(*read_input()):
        print(f"{line}")
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation read_input(input_path : OclAny) : OclAny
  pre: true post: true
  activity:
    if input_path->oclIsUndefined() then input_path := null else skip;
    if input_path <>= null then  (
      var f : OclFile := OclFile["System.in"]
    )
    else (
      f := OclFile.newOclFile_Write(OclFile.newOclFile(input_path))
      ) ;
    var n : int := ("" + ((f.readLine())))->toInteger() ;
    var chairs : OclAny := f.readLine()->trim() ;
    return n, chairs;
  operation sol(n : OclAny, chairs : OclAny) : OclAny
  pre: true post: true
  activity:
    chairs := '0' + chairs + '0' ;
    return Sequence{ if (chairs)->excludes("11") & (chairs)->excludes("000") then "YES" else "NO" endif };
  operation solve(input_path : OclAny) : OclAny
  pre: true post: true
  activity:
    if input_path->oclIsUndefined() then input_path := null else skip;
    return sol((argument * (test (logical_test (comparison (expr (atom (name read_input)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input_path)))))))) )))))))));
  operation main()
  pre: true post: true
  activity:
    for line : sol((argument * (test (logical_test (comparison (expr (atom (name read_input)) (trailer (arguments ( ))))))))) do (    execute (StringLib.formattedString("{line}"))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def countNums(n,x,y):
    arr=[False for i in range(n+2)]
    if(x<=n):
        arr[x]=True
    if(y<=n):
        arr[y]=True
    result=0
    for i in range(min(x,y),n+1):
        if(arr[i]):
            if(i+x<=n):
                arr[i+x]=True
            if(i+y<=n):
                arr[i+y]=True
            result=result+1
    return result
n=15
x=5
y=7
print(countNums(n,x,y))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    n := 15 ;
    x := 5 ;
    y := 7 ;
    execute (countNums(n, x, y))->display();
  operation countNums(n : OclAny, x : OclAny, y : OclAny) : OclAny
  pre: true post: true
  activity:
    var arr : Sequence := Integer.subrange(0, n + 2-1)->select(i | true)->collect(i | (false)) ;
    if ((x->compareTo(n)) <= 0) then (
      arr[x+1] := true
    ) else skip ;
    if ((y->compareTo(n)) <= 0) then (
      arr[y+1] := true
    ) else skip ;
    var result : int := 0 ;
    for i : Integer.subrange(Set{x, y}->min(), n + 1-1) do (    if (arr[i+1]) then (
      if ((i + x->compareTo(n)) <= 0) then (
      arr[i + x+1] := true
    ) else skip ;
    if ((i + y->compareTo(n)) <= 0) then (
      arr[i + y+1] := true
    ) else skip ;
    result := result + 1
    ) else skip) ;
    return result;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import itertools
def compute():
    INDEX=30
    limit=1
    while True :
        candidates=set()
        k=2
        while(1<=limit and len(str(pow))*9=10 and is_digit_sum_power(pow):
                    candidates.add(pow)
            k+=1
        if len(candidates)>=INDEX :
            return str(sorted(candidates)[INDEX-1])
        limit<<=8
def is_digit_sum_power(x):
    digitsum=sum(int(c)for c in str(x))
    if digitsum==1 :
        return False
    pow=digitsum
    while powdisplay()
    ) else skip;
  operation compute() : OclAny
  pre: true post: true
  activity:
    var INDEX : int := 30 ;
    var limit : int := 1 ;
    while true do (    var candidates : Set := Set{}->union(()) ;
    var k : int := 2 ;
    while ((1 * (2->pow(k)))->compareTo(limit)) < 0 do (    for n : itertools->count(2) do (    var pow : double := (n)->pow(k) ;
    if (pow->compareTo(limit)) >= 0 & ((("" + ((pow))))->size() * 9->compareTo(n)) < 0 then (
      break
    ) else skip ;
    if pow >= 10 & is_digit_sum_power(pow) then (
      execute ((pow) : candidates)
    ) else skip) ;
    k := k + 1) ;
    if ((candidates)->size()->compareTo(INDEX)) >= 0 then (
      return ("" + ((sorted(candidates)[INDEX - 1+1])))
    ) else skip ;
    limit := limit * (2->pow(8)));
  operation is_digit_sum_power(x : OclAny) : OclAny
  pre: true post: true
  activity:
    var digitsum : OclAny := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))))))))->sum() ;
    if digitsum = 1 then (
      return false
    ) else skip ;
    pow := digitsum ;
    while (pow->compareTo(x)) < 0 do (    pow := pow * digitsum) ;
    return pow = x;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def bingo(b):
    for i in range(3):
        for j in range(3):
            if A[i][j]==b :
                B[i][j]=1
def judge():
    for i in range(3):
        if B[i][0]and B[i][1]and B[i][2]:
            return True
        if B[0][i]and B[1][i]and B[2][i]:
            return True
    if B[0][0]and B[1][1]and B[2][2]:
        return True
    if B[0][2]and B[1][1]and B[2][0]:
        return True
    return False
A=[[int(i)for i in input().split()]for _ in range(3)]
B=[[0]*3 for _ in range(3)]
N=int(input())
for _ in range(N):
    b=int(input())
    bingo(b)
if judge():
    print("Yes")
else :
    print("No")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var A : Sequence := Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())))) ;
    var B : Sequence := Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 3))) ;
    var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, N-1) do (    b := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    bingo(b)) ;
    if judge() then  (
      execute ("Yes")->display()
    )
    else (
      execute ("No")->display()
      );
  operation bingo(b : OclAny)
  pre: true post: true
  activity:
    for i : Integer.subrange(0, 3-1) do (    for j : Integer.subrange(0, 3-1) do (    if A[i+1][j+1] = b then (
      B[i+1][j+1] := 1
    ) else skip));
  operation judge() : OclAny
  pre: true post: true
  activity:
    for i : Integer.subrange(0, 3-1) do (    if B[i+1]->first() & B[i+1][1+1] & B[i+1][2+1] then (
      return true
    ) else skip ;
    if B->first()[i+1] & B[1+1][i+1] & B[2+1][i+1] then (
      return true
    ) else skip) ;
    if B->first()->first() & B[1+1][1+1] & B[2+1][2+1] then (
      return true
    ) else skip ;
    if B->first()[2+1] & B[1+1][1+1] & B[2+1]->first() then (
      return true
    ) else skip ;
    return false;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def answer(n):
    dp=[0]*10
    prev=[0]*10
    if(n==1):
        return 10
    for j in range(0,10):
        dp[j]=1
    for i in range(2,n+1):
        for j in range(0,10):
            prev[j]=dp[j]
        for j in range(0,10):
            if(j==0):
                dp[j]=prev[j+1]
            elif(j==9):
                dp[j]=prev[j-1]
            else :
                dp[j]=prev[j-1]+prev[j+1]
    sum=0
    for j in range(1,10):
        sum=sum+dp[j]
    return sum
n=2
print(answer(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    n := 2 ;
    execute (answer(n))->display();
  operation answer(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ;
    var prev : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ;
    if (n = 1) then (
      return 10
    ) else skip ;
    for j : Integer.subrange(0, 10-1) do (    dp[j+1] := 1) ;
    for i : Integer.subrange(2, n + 1-1) do (    for j : Integer.subrange(0, 10-1) do (    prev[j+1] := dp[j+1]) ;
    for j : Integer.subrange(0, 10-1) do (    if (j = 0) then  (
      dp[j+1] := prev[j + 1+1]
    )
    else (if (j = 9) then
   (
      dp[j+1] := prev[j - 1+1]    
)
    else (
      dp[j+1] := prev[j - 1+1] + prev[j + 1+1]
      )    )
)) ;
    var sum : int := 0 ;
    for j : Integer.subrange(1, 10-1) do (    sum := sum + dp[j+1]) ;
    return sum;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
A1=list(map(int,input().split()))
A2=list(map(int,input().split()))
A3=list(map(int,input().split()))
N=int(input())
index_A1=-1
index_A2=-1
index_A3=-1
result_A1=[0,0,0]
result_A2=[0,0,0]
result_A3=[0,0,0]
for i in range(N):
    b=int(input())
    try :
        index_A1=A1.index(b)
        if index_A1>-1 :
            result_A1[index_A1]=1
    except ValueError :
        index_A1=-1
    try :
        index_A2=A2.index(b)
        if index_A2>-1 :
            result_A2[index_A2]=1
    except ValueError :
        index_A2=-1
    try :
        index_A3=A3.index(b)
        if index_A3>-1 :
            result_A3[index_A3]=1
    except ValueError :
        index_A3=-1
if sum(result_A1)==3 or sum(result_A2)==3 or sum(result_A3)==3 :
    print('Yes')
    sys.exit()
for i in range(3):
    if result_A1[i]+result_A2[i]+result_A3[i]==3 :
        print('Yes')
        sys.exit()
if result_A1[0]+result_A2[1]+result_A3[2]==3 :
    print('Yes')
    sys.exit()
if result_A3[0]+result_A2[1]+result_A1[2]==3 :
    print('Yes')
    sys.exit()
print('No')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var A1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var A2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var A3 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var index_A1 : int := -1 ;
    var index_A2 : int := -1 ;
    var index_A3 : int := -1 ;
    var result_A1 : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) ;
    var result_A2 : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) ;
    var result_A3 : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) ;
    for i : Integer.subrange(0, N-1) do (    var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    try (    index_A1 := A1->indexOf(b) - 1 ;
    if index_A1 > -1 then (
      result_A1[index_A1+1] := 1
    ) else skip)
(except_clause except (test (logical_test (comparison (expr (atom (name ValueError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name index_A1)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))))))) ;
    try (    index_A2 := A2->indexOf(b) - 1 ;
    if index_A2 > -1 then (
      result_A2[index_A2+1] := 1
    ) else skip)
(except_clause except (test (logical_test (comparison (expr (atom (name ValueError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name index_A2)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))))))) ;
    try (    index_A3 := A3->indexOf(b) - 1 ;
    if index_A3 > -1 then (
      result_A3[index_A3+1] := 1
    ) else skip)
(except_clause except (test (logical_test (comparison (expr (atom (name ValueError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name index_A3)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))))))))) ;
    if (result_A1)->sum() = 3 or (result_A2)->sum() = 3 or (result_A3)->sum() = 3 then (
      execute ('Yes')->display() ;
    sys.exit()
    ) else skip ;
    for i : Integer.subrange(0, 3-1) do (    if result_A1[i+1] + result_A2[i+1] + result_A3[i+1] = 3 then (
      execute ('Yes')->display() ;
    sys.exit()
    ) else skip) ;
    if result_A1->first() + result_A2[1+1] + result_A3[2+1] = 3 then (
      execute ('Yes')->display() ;
    sys.exit()
    ) else skip ;
    if result_A3->first() + result_A2[1+1] + result_A1[2+1] = 3 then (
      execute ('Yes')->display() ;
    sys.exit()
    ) else skip ;
    execute ('No')->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import exit,stdin
A=[list(map(int,stdin.readline().rstrip().split()))for _ in range(3)]
bin_A=[[0]*3 for _ in range(3)]
N=int(stdin.readline().rstrip())
B=[int(stdin.readline().rstrip())for _ in range(N)]
for i in range(N):
    for j in range(3):
        for k in range(3):
            if A[j][k]==B[i]:
                bin_A[j][k]=1
ans='No'
for i in range(3):
    if bin_A[i][0]+bin_A[i][1]+bin_A[i][2]==3 :
        ans='Yes'
for j in range(3):
    if bin_A[0][j]+bin_A[1][j]+bin_A[2][j]==3 :
        ans='Yes'
if bin_A[0][0]+bin_A[1][1]+bin_A[2][2]==3 :
    ans='Yes'
if bin_A[0][2]+bin_A[1][1]+bin_A[2][0]==3 :
    ans='Yes'
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var A : Sequence := Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (((stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var bin_A : Sequence := Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 3))) ;
    var N : int := ("" + ((stdin.readLine().rstrip())))->toInteger() ;
    var B : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + ((stdin.readLine().rstrip())))->toInteger())) ;
    for i : Integer.subrange(0, N-1) do (    for j : Integer.subrange(0, 3-1) do (    for k : Integer.subrange(0, 3-1) do (    if A[j+1][k+1] = B[i+1] then (
      bin_A[j+1][k+1] := 1
    ) else skip))) ;
    var ans : String := 'No' ;
    for i : Integer.subrange(0, 3-1) do (    if bin_A[i+1]->first() + bin_A[i+1][1+1] + bin_A[i+1][2+1] = 3 then (
      ans := 'Yes'
    ) else skip) ;
    for j : Integer.subrange(0, 3-1) do (    if bin_A->first()[j+1] + bin_A[1+1][j+1] + bin_A[2+1][j+1] = 3 then (
      ans := 'Yes'
    ) else skip) ;
    if bin_A->first()->first() + bin_A[1+1][1+1] + bin_A[2+1][2+1] = 3 then (
      ans := 'Yes'
    ) else skip ;
    if bin_A->first()[2+1] + bin_A[1+1][1+1] + bin_A[2+1]->first() = 3 then (
      ans := 'Yes'
    ) else skip ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    li=[]
    for i in range(3):
        x,y,z=map(int,input().split())
        li.append(x)
        li.append(y)
        li.append(z)
    n=int(input())
    bingo_li=[]
    for i in range(n):
        bingo_li.append(int(input()))
    ans_li=[0,0,0,0,0,0,0,0,0]
    for i in bingo_li :
        for j in range(9):
            if li[j]==i :
                ans_li[j]=1
    if(ans_li[0]+ans_li[1]+ans_li[2]==3):
        ans="Yes"
    elif(ans_li[3]+ans_li[4]+ans_li[5]==3):
        ans="Yes"
    elif(ans_li[6]+ans_li[7]+ans_li[8]==3):
        ans="Yes"
    elif(ans_li[0]+ans_li[3]+ans_li[6]==3):
        ans="Yes"
    elif(ans_li[1]+ans_li[4]+ans_li[7]==3):
        ans="Yes"
    elif(ans_li[2]+ans_li[5]+ans_li[8]==3):
        ans="Yes"
    elif(ans_li[0]+ans_li[4]+ans_li[8]==3):
        ans="Yes"
    elif(ans_li[2]+ans_li[4]+ans_li[6]==3):
        ans="Yes"
    else :
        ans="No"
    print(ans)
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var li : Sequence := Sequence{} ;
    for i : Integer.subrange(0, 3-1) do (    var x : OclAny := null;
    var y : OclAny := null;
    var z : OclAny := null;
    Sequence{x,y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute ((x) : li) ;
    execute ((y) : li) ;
    execute ((z) : li)) ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var bingo_li : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : bingo_li)) ;
    var ans_li : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))))))) ;
    for i : bingo_li do (    for j : Integer.subrange(0, 9-1) do (    if li[j+1] = i then (
      ans_li[j+1] := 1
    ) else skip)) ;
    if (ans_li->first() + ans_li[1+1] + ans_li[2+1] = 3) then  (
      var ans : String := "Yes"
    )
    else (if (ans_li[3+1] + ans_li[4+1] + ans_li[5+1] = 3) then
   (
      ans := "Yes"    
)
    else (if (ans_li[6+1] + ans_li[7+1] + ans_li[8+1] = 3) then
   (
      ans := "Yes"    
)
    else (if (ans_li->first() + ans_li[3+1] + ans_li[6+1] = 3) then
   (
      ans := "Yes"    
)
    else (if (ans_li[1+1] + ans_li[4+1] + ans_li[7+1] = 3) then
   (
      ans := "Yes"    
)
    else (if (ans_li[2+1] + ans_li[5+1] + ans_li[8+1] = 3) then
   (
      ans := "Yes"    
)
    else (if (ans_li->first() + ans_li[4+1] + ans_li[8+1] = 3) then
   (
      ans := "Yes"    
)
    else (if (ans_li[2+1] + ans_li[4+1] + ans_li[6+1] = 3) then
   (
      ans := "Yes"    
)
    else (
      ans := "No"
      )    )
    )
    )
    )
    )
    )
    )
 ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s,a,c=list(input()),1,0
for x in s :
    if x=='A' and a : a=0
    elif x=='Z' and not a : a,c=1,c+1
print('AZ'*c if c else-1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : OclAny := null;
    var a : OclAny := null;
    var c : OclAny := null;
    Sequence{s,a,c} := Sequence{((OclFile["System.in"]).readLine())->characters(),1,0} ;
    for x : s do (    if x = 'A' & a then  (
      var a : int := 0
    )
    else (if x = 'Z' & not(a) then
   (
      var c : OclAny := null;
    Sequence{a,c} := Sequence{1,c + 1}    
)
 else skip)) ;
    execute (if c then StringLib.nCopies('AZ', c) else -1 endif)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def check_bng(t):
    c=0
    for i in range(3):
        if t[i][0]+t[i][1]+t[i][2]==-3 :
            c=1
        if t[0][i]+t[1][i]+t[2][i]==-3 :
            c=1
    if t[0][0]+t[1][1]+t[2][2]==-3 or t[2][0]+t[1][1]+t[0][2]==-3 :
        c=1
    return c
def check(b,t):
    for i in range(3):
        if t[i].count(b)==1 :
            t[i][t[i].index(b)]=-1
    return t
if __name__=='__main__' :
    A1=[int(a)for a in input().split()]
    A2=[int(a)for a in input().split()]
    A3=[int(a)for a in input().split()]
    N=int(input())
    t=[A1,A2,A3]
    nlst=[]
    for i in range(N):
        check(int(input()),t)
    if check_bng(t)==1 :
        print('Yes')
    else :
        print('No')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = '__main__' then (
      var A1 : Sequence := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ;
    var A2 : Sequence := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ;
    var A3 : Sequence := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ;
    var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    t := Sequence{A1}->union(Sequence{A2}->union(Sequence{ A3 })) ;
    var nlst : Sequence := Sequence{} ;
    for i : Integer.subrange(0, N-1) do (    check(("" + (((OclFile["System.in"]).readLine())))->toInteger(), t)) ;
    if check_bng(t) = 1 then  (
      execute ('Yes')->display()
    )
    else (
      execute ('No')->display()
      )
    ) else skip;
  operation check_bng(t : OclAny) : OclAny
  pre: true post: true
  activity:
    var c : int := 0 ;
    for i : Integer.subrange(0, 3-1) do (    if t[i+1]->first() + t[i+1][1+1] + t[i+1][2+1] = -3 then (
      c := 1
    ) else skip ;
    if t->first()[i+1] + t[1+1][i+1] + t[2+1][i+1] = -3 then (
      c := 1
    ) else skip) ;
    if t->first()->first() + t[1+1][1+1] + t[2+1][2+1] = -3 or t[2+1]->first() + t[1+1][1+1] + t->first()[2+1] = -3 then (
      c := 1
    ) else skip ;
    return c;
  operation check(b : OclAny, t : OclAny) : OclAny
  pre: true post: true
  activity:
    for i : Integer.subrange(0, 3-1) do (    if t[i+1]->count(b) = 1 then (
      t[i+1][t[i+1]->indexOf(b) - 1+1] := -1
    ) else skip) ;
    return t;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def compute():
    LIMIT=28124
    divisorsum=[0]*LIMIT
    for i in range(1,LIMIT):
        for j in range(i*2,LIMIT,i):
            divisorsum[j]+=i
    abundantnums=[i for(i,x)in enumerate(divisorsum)if x>i]
    expressible=[False]*LIMIT
    for i in abundantnums :
        for j in abundantnums :
            if i+jdisplay()
    ) else skip;
  operation compute() : OclAny
  pre: true post: true
  activity:
    var LIMIT : int := 28124 ;
    var divisorsum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, LIMIT) ;
    for i : Integer.subrange(1, LIMIT-1) do (    for j : Integer.subrange(i * 2, LIMIT-1)->select( $x | ($x - i * 2) mod i = 0 ) do (    divisorsum[j+1] := divisorsum[j+1] + i)) ;
    var abundantnums : Sequence := Integer.subrange(1, (divisorsum)->size())->collect( _indx | Sequence{_indx-1, (divisorsum)->at(_indx)} )->select(Sequence{i, x} | (x->compareTo(i)) > 0)->collect(Sequence{i, x} | (i)) ;
    var expressible : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, LIMIT) ;
    for i : abundantnums do (    for j : abundantnums do (    if (i + j->compareTo(LIMIT)) < 0 then  (
      expressible[i + j+1] := true
    )
    else (
      break
      ))) ;
    var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) , (test (logical_test (comparison (expr (atom (name x))))))) )))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name expressible)))))))) )))))) (comp_iter if (test (logical_test not (logical_test (comparison (expr (atom (name x)))))))))))->sum() ;
    return ("" + ((ans)));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
def binomialCoeffSum(n):
    C=[[0]*(n+2)for i in range(0,n+2)]
    for i in range(0,n+1):
        for j in range(0,min(i,n)+1):
            if(j==0 or j==i):
                C[i][j]=1
            else :
                C[i][j]=C[i-1][j-1]+C[i-1][j]
    sum=0
    for i in range(0,n+1):
        sum+=C[n][i]
    return sum
n=4
print(binomialCoeffSum(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    n := 4 ;
    execute (binomialCoeffSum(n))->display();
  operation binomialCoeffSum(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var C : Sequence := Integer.subrange(0, n + 2-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 2)))) ;
    for i : Integer.subrange(0, n + 1-1) do (    for j : Integer.subrange(0, Set{i, n}->min() + 1-1) do (    if (j = 0 or j = i) then  (
      C[i+1][j+1] := 1
    )
    else (
      C[i+1][j+1] := C[i - 1+1][j - 1+1] + C[i - 1+1][j+1]
      ))) ;
    var sum : int := 0 ;
    for i : Integer.subrange(0, n + 1-1) do (    sum := sum + C[n+1][i+1]) ;
    return sum;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N,M=map(int,input().split())
AB=[list(map(int,input().split()))for _ in range(M)]
sAB=sorted(AB,key=lambda x : x[1])
cnt=0
for itr,ab in enumerate(sAB):
    a,b=ab
    if itr==0 :
        x=b-1
        cnt+=1
    else :
        if a>x :
            x=b-1
            cnt+=1
print(cnt)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var AB : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var sAB : Sequence := AB->sortedBy($x | (lambda x : OclAny in (x[1+1]))->apply($x)) ;
    var cnt : int := 0 ;
    for _tuple : Integer.subrange(1, (sAB)->size())->collect( _indx | Sequence{_indx-1, (sAB)->at(_indx)} ) do (var _indx : int := 1;
      var itr : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var ab : OclAny := _tuple->at(_indx);
      var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := ab ;
    if itr = 0 then  (
      var x : double := b - 1 ;
    cnt := cnt + 1
    )
    else (
      if (a->compareTo(x)) > 0 then (
      x := b - 1 ;
    cnt := cnt + 1
    ) else skip
      )) ;
    execute (cnt)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m=(int(x)for x in input().split())
sec=[]
for i in range(m):
    list=[int(i)for i in input().split()]
    list.reverse()
    sec.append(list)
sec.sort()
left=sec[0][0]
right=sec[0][1]
x=right-1
ans=0
for i in range(m):
    if sec[i][1]select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    OclType["Sequence"] := OclType["Sequence"]->reverse() ;
    execute ((OclType["Sequence"]) : sec)) ;
    sec := sec->sort() ;
    var left : OclAny := sec->first()->first() ;
    var right : OclAny := sec->first()[1+1] ;
    var x : double := right - 1 ;
    var ans : int := 0 ;
    for i : Integer.subrange(0, m-1) do (    if (sec[i+1][1+1]->compareTo(x)) < 0 then  (
      continue
    )
    else (
      x := sec[i+1]->first() ;
    ans := ans + 1
      )) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m=map(int,input().split())
ab=[]
for i in range(m):
    a=[int(j)for j in input().split()]
    ab.append(a)
from operator import itemgetter
ab.sort(key=itemgetter(1))
ans=1
b=[ab[0][1]-1]
for i in range(m):
    if not b[-1]>=ab[i][0]and b[-1]collect( _x | (OclType["int"])->apply(_x) ) ;
    var ab : Sequence := Sequence{} ;
    for i : Integer.subrange(0, m-1) do (    var a : Sequence := input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ;
    execute ((a) : ab)) ;
    skip ;
    ab := ab->sort() ;
    var ans : int := 1 ;
    var b : Sequence := Sequence{ ab->first()[1+1] - 1 } ;
    for i : Integer.subrange(0, m-1) do (    if not((b->last()->compareTo(ab[i+1]->first())) >= 0) & (b->last()->compareTo(ab[i+1][1+1])) < 0 then (
      execute ((ab[i+1][1+1] - 1) : b) ;
    ans := ans + 1
    ) else skip) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
n,m=map(int,input().split())
AB=[]
for _ in range(m):
    a,b=map(int,input().split())
    AB.append((a,b))
AB=sorted(AB,key=lambda x : x[1])
count=0
pb=AB[0][1]
for a,b in AB[1 :]:
    if a>=pb :
        count+=1
        pb=b
count+=1
print(count)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var AB : Sequence := Sequence{} ;
    for _anon : Integer.subrange(0, m-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute ((Sequence{a, b}) : AB)) ;
    AB := AB->sortedBy($x | (lambda x : OclAny in (x[1+1]))->apply($x)) ;
    var count : int := 0 ;
    var pb : OclAny := AB->first()[1+1] ;
    for _tuple : AB->tail() do (var _indx : int := 1;
      var a : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var b : OclAny := _tuple->at(_indx);
      if (a->compareTo(pb)) >= 0 then (
      count := count + 1 ;
    pb := b
    ) else skip) ;
    count := count + 1 ;
    execute (count)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import*
def getFib(n):
    f=[0]*(n+2)
    f[0],f[1]=0,1
    for i in range(2,n+1):
        f[i]=f[i-1]+f[i-2]
    return f[n]
def find(arr,n):
    gcd_1=0
    for i in range(n):
        gcd_1=gcd(gcd_1,arr[i])
    return getFib(gcd_1)
if __name__=="__main__" :
    indices=[3,6,9]
    N=len(indices)
    print(find(indices,N))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      var indices : Sequence := Sequence{3}->union(Sequence{6}->union(Sequence{ 9 })) ;
    var N : int := (indices)->size() ;
    execute (find(indices, N))->display()
    ) else skip;
  operation getFib(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 2)) ;
    var f->first() : OclAny := null;
    var f[1+1] : OclAny := null;
    Sequence{f->first(),f[1+1]} := Sequence{0,1} ;
    for i : Integer.subrange(2, n + 1-1) do (    f[i+1] := f[i - 1+1] + f[i - 2+1]) ;
    return f[n+1];
  operation find(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var gcd    skip : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    gcd    var gcd    skip : int := 0 := gcd(gcd    var gcd    skip : int := 0, arr[i+1])) ;
    return getFib(gcd    var gcd    skip : int := 0);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N,M=map(int,input().split())
query=[[]for _ in range(N+1)]
for i in range(M):
    a,b=map(int,input().split())
    query[a].append(b)
nearest=[0]*(N+1)
for i in range(1,N+1):
    nearest[i]=min(query[i])if len(query[i])>0 else 0
ans=0
a_current=0
b_current=N+1
for i in range(1,N+1):
    if nearest[i]>0 :
        a=i
        b=nearest[i]
        if a>=b_current :
            ans+=1
            a_current=a
            b_current=b
        else :
            a_current=a
            b_current=min(b_current,b)
ans+=1
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var query : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ;
    for i : Integer.subrange(0, M-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
(expr (atom (name query)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) ))))) ;
    var nearest : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ;
    for i : Integer.subrange(1, N + 1-1) do (    nearest[i+1] := if (query[i+1])->size() > 0 then (query[i+1])->min() else 0 endif) ;
    var ans : int := 0 ;
    var a_current : int := 0 ;
    var b_current : OclAny := N + 1 ;
    for i : Integer.subrange(1, N + 1-1) do (    if nearest[i+1] > 0 then (
      var a : OclAny := i ;
    var b : OclAny := nearest[i+1] ;
    if (a->compareTo(b_current)) >= 0 then  (
      ans := ans + 1 ;
    a_current := a ;
    b_current := b
    )
    else (
      a_current := a ;
    b_current := Set{b_current, b}->min()
      )
    ) else skip) ;
    ans := ans + 1 ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=input()
z=r=0
for i in a.split('heavy'): r+=i.count('metal')*(z); z+=1
print(r)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : String := (OclFile["System.in"]).readLine() ;
    var z : OclAny := 0; var r : int := 0 ;
    for i : a.split('heavy') do (    r := r + i->count('metal') * (z);    z := z + 1) ;
    execute (r)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for test in range(t):
    n,k=map(int,input().split())
    if k==1 :
        if n % 2==1 :
            print('YES')
        else :
            print('NO')
    else :
        if n<=k :
            print('NO')
        else :
            if n % 2==0 and k % 2==1 :
                print('NO')
            elif n % 2==1 and k % 2==0 :
                print('NO')
            else :
                x=2*k-1
                min_sum=((1+x)**2)/4
                if min_sum>n :
                    print('NO')
                elif min_sum==n :
                    print('YES')
                else :
                    if(n-min_sum)% 2==0 :
                        print('YES')
                    else :
                        print('NO')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for test : Integer.subrange(0, t-1) do (    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if k = 1 then  (
      if n mod 2 = 1 then  (
      execute ('YES')->display()
    )
    else (
      execute ('NO')->display()
      )
    )
    else (
      if (n->compareTo(k)) <= 0 then  (
      execute ('NO')->display()
    )
    else (
      if n mod 2 = 0 & k mod 2 = 1 then  (
      execute ('NO')->display()
    )
    else (if n mod 2 = 1 & k mod 2 = 0 then
   (
      execute ('NO')->display()    
)
    else (
      var x : double := 2 * k - 1 ;
    var min_sum : double := (((1 + x))->pow(2)) / 4 ;
    if (min_sum->compareTo(n)) > 0 then  (
      execute ('NO')->display()
    )
    else (if min_sum = n then
   (
      execute ('YES')->display()    
)
    else (
      if (n - min_sum) mod 2 = 0 then  (
      execute ('YES')->display()
    )
    else (
      execute ('NO')->display()
      )
      )    )
      )    )
      )
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import bisect
s=input().strip()
heavy=[]
metal=[]
i=0
while(i=5):
        count+=(len(metal)-j)
        i+=1
    elif(metal[j]trim() ;
    var heavy : Sequence := Sequence{} ;
    var metal : Sequence := Sequence{} ;
    var i : int := 0 ;
    while ((i->compareTo((s)->size() - 4)) < 0) do (    if (s.subrange(i+1, i + 5) = 'heavy') then  (
      execute ((i) : heavy)
    )
    else (if (s.subrange(i+1, i + 5) = 'metal') then
   (
      execute ((i) : metal)    
)
 else skip) ;
    i := i + 1) ;
    var count : int := 0 ;
    i := 0 ;
    var j : int := 0 ;
    while ((j->compareTo((metal)->size())) < 0 & (i->compareTo((heavy)->size())) < 0) do (    if ((heavy[i+1]->compareTo(metal[j+1])) < 0 & metal[j+1] - heavy[i+1] >= 5) then  (
      count := count + ((metal)->size() - j) ;
    i := i + 1
    )
    else (if ((metal[j+1]->compareTo(heavy[i+1])) < 0) then
   (
      j := j + 1    
)
 else skip)) ;
    execute (count)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s=list(input())
a,b=0,0
for i in range(len(s)-4):
    if s[i]=='h' and s[i+1]=='e' and s[i+2]=='a' and s[i+3]=='v' and s[i+4]=='y' :
        i+=4
        b+=1
    if s[i]=='m' and s[i+1]=='e' and s[i+2]=='t' and s[i+3]=='a' and s[i+4]=='l' :
        i+=4
        a+=b
print(a)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := Sequence{0,0} ;
    for i : Integer.subrange(0, (s)->size() - 4-1) do (    if s[i+1] = 'h' & s[i + 1+1] = 'e' & s[i + 2+1] = 'a' & s[i + 3+1] = 'v' & s[i + 4+1] = 'y' then (
      i := i + 4 ;
    b := b + 1
    ) else skip ;
    if s[i+1] = 'm' & s[i + 1+1] = 'e' & s[i + 2+1] = 't' & s[i + 3+1] = 'a' & s[i + 4+1] = 'l' then (
      i := i + 4 ;
    a := a + b
    ) else skip) ;
    execute (a)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
i=0
s=input()[:-1]
n=len(s)
a,c=0,0
while ifront() ;
    var n : int := (s)->size() ;
    var a : OclAny := null;
    var c : OclAny := null;
    Sequence{a,c} := Sequence{0,0} ;
    while (i->compareTo(n - 4)) < 0 do (    if s.subrange(i+1, i + 5) = 'heavy' then  (
      a := a + 1 ;
    i := i + 5
    )
    else (if s.subrange(i+1, i + 5) = 'metal' then
   (
      c := c + a ;
    i := i + 5    
)
    else (
      i := i + 1
      )    )
) ;
    execute (c)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s=list(input())
a,b=0,0
for i in range(len(s)-4):
    if s[i]=='h' and s[i+1]=='e' and s[i+2]=='a' and s[i+3]=='v' and s[i+4]=='y' :
        i+=4
        b+=1
    if s[i]=='m' and s[i+1]=='e' and s[i+2]=='t' and s[i+3]=='a' and s[i+4]=='l' :
        i+=4
        a+=b
print(a)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := Sequence{0,0} ;
    for i : Integer.subrange(0, (s)->size() - 4-1) do (    if s[i+1] = 'h' & s[i + 1+1] = 'e' & s[i + 2+1] = 'a' & s[i + 3+1] = 'v' & s[i + 4+1] = 'y' then (
      i := i + 4 ;
    b := b + 1
    ) else skip ;
    if s[i+1] = 'm' & s[i + 1+1] = 'e' & s[i + 2+1] = 't' & s[i + 3+1] = 'a' & s[i + 4+1] = 'l' then (
      i := i + 4 ;
    a := a + b
    ) else skip) ;
    execute (a)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def findSmallestNonZeroY(A_num):
    A_binary=bin(A_num)
    B=1
    length=len(A_binary);
    no_ones=(A_binary).count('1');
    if length==no_ones :
        return A_num+1 ;
    for i in range(length):
        ch=A_binary[length-i-1];
        if(ch=='0'):
            B=pow(2.0,i);
            break ;
    return B ;
if __name__=="__main__" :
    X=findSmallestNonZeroY(10);
    print(X)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      var X : OclAny := findSmallestNonZeroY(10); ;
    execute (X)->display()
    ) else skip;
  operation findSmallestNonZeroY(A_num : OclAny)
  pre: true post: true
  activity:
    var A_binary : OclAny := bin(A_num) ;
    var B : int := 1 ;
    var length : int := (A_binary)->size(); ;
    var no_ones : int := (A_binary)->count('1'); ;
    if length = no_ones then (
      return A_num + 1;
    ) else skip ;
    for i : Integer.subrange(0, length-1) do (    var ch : OclAny := A_binary[length - i - 1+1]; ;
    if (ch = '0') then (
      B := (2.0)->pow(i); ;
    break;
    ) else skip) ;
    return B;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def MatrixChainOrder(p,i,j):
    if i==j :
        return 0
    _min=sys.maxsize
    for k in range(i,j):
        count=(MatrixChainOrder(p,i,k)+MatrixChainOrder(p,k+1,j)+p[i-1]*p[k]*p[j])
        if count<_min :
            _min=count ;
    return _min ;
arr=[1,2,3,4,3];
n=len(arr);
print("Minimum number of multiplications is ",MatrixChainOrder(arr,1,n-1));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var arr : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 3 })))); ;
    var n : int := (arr)->size(); ;
    execute ("Minimum number of multiplications is ")->display();;
  operation MatrixChainOrder(p : OclAny, i : OclAny, j : OclAny) : OclAny
  pre: true post: true
  activity:
    if i = j then (
      return 0
    ) else skip ;
    var _min : (trailer . (name maxsize)) := (trailer . (name maxsize)) ;
    for k : Integer.subrange(i, j-1) do (    var count : OclAny := (MatrixChainOrder(p, i, k) + MatrixChainOrder(p, k + 1, j) + p[i - 1+1] * p[k+1] * p[j+1]) ;
    if (count->compareTo(_min)) < 0 then (
      _min := count;
    ) else skip) ;
    return _min;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def minimumMoves(k,l,r):
    count=r-l+1
    if(count % k==0):
        return 0
    return(k-(count % k))
if __name__=='__main__' :
    k=3
    l=10
    r=10
    print(minimumMoves(k,l,r))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      k := 3 ;
    l := 10 ;
    r := 10 ;
    execute (minimumMoves(k, l, r))->display()
    ) else skip;
  operation minimumMoves(k : OclAny, l : OclAny, r : OclAny) : OclAny
  pre: true post: true
  activity:
    var count : double := r - l + 1 ;
    if (count mod k = 0) then (
      return 0
    ) else skip ;
    return (k - (count mod k));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def calculate_change(length,breadth):
    change=0
    change=length+breadth+((length*breadth)//100)
    return change
if __name__=="__main__" :
    cL=20
    cB=-10
    cA=calculate_change(cL,cB)
    print(cA)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      var cL : int := 20 ;
    var cB : int := -10 ;
    var cA : OclAny := calculate_change(cL, cB) ;
    execute (cA)->display()
    ) else skip;
  operation calculate_change(length : OclAny, breadth : OclAny) : OclAny
  pre: true post: true
  activity:
    var change : int := 0 ;
    change := length + breadth + ((length * breadth) div 100) ;
    return change;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import sqrt
def sortPerfectSquare(arr,n):
    v1=[]
    v2=[]
    for i in range(n):
        b=sqrt(arr[i])
        a=int(b)
        if a==b :
            v1.append(i)
            v2.append(arr[i])
    v2.sort()
    j=0
    for i in range(n):
        if v1[j]==i :
            arr[i]=v2[j]
            j+=1
    for i in range(n):
        print(arr[i],end=" ")
if __name__=="__main__" :
    arr=[9,44,100,81,21,64]
    n=len(arr)
    sortPerfectSquare(arr,n);
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      arr := Sequence{9}->union(Sequence{44}->union(Sequence{100}->union(Sequence{81}->union(Sequence{21}->union(Sequence{ 64 }))))) ;
    n := (arr)->size() ;
    sortPerfectSquare(arr, n);
    ) else skip;
  operation sortPerfectSquare(arr : OclAny, n : OclAny)
  pre: true post: true
  activity:
    var v1 : Sequence := Sequence{} ;
    var v2 : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    var b : OclAny := sqrt(arr[i+1]) ;
    var a : int := ("" + ((b)))->toInteger() ;
    if a = b then (
      execute ((i) : v1) ;
    execute ((arr[i+1]) : v2)
    ) else skip) ;
    v2 := v2->sort() ;
    var j : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    if v1[j+1] = i then (
      arr[i+1] := v2[j+1] ;
    j := j + 1
    ) else skip) ;
    for i : Integer.subrange(0, n-1) do (    execute (arr[i+1])->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def isMultipleof5(n):
    if((n & 1)==1):
        n<<=1 ;
    x=n
    x=((int)(x*0.1))*10
    if(x==n):
        return 1
    return 0
i=19
if(isMultipleof5(i)==1):
    print(i,"is multiple of 5")
else :
    print(i,"is not a multiple of 5")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var i : int := 19 ;
    if (isMultipleof5(i) = 1) then  (
      execute (i)->display()
    )
    else (
      execute (i)->display()
      );
  operation isMultipleof5(n : OclAny) : OclAny
  pre: true post: true
  activity:
    if ((MathLib.bitwiseAnd(n, 1)) = 1) then (
      n := n * (2->pow(1));
    ) else skip ;
    var x : OclAny := n ;
    x := ((OclType["int"])(x * 0.1)) * 10 ;
    if (x = n) then (
      return 1
    ) else skip ;
    return 0;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def strangeBDParty(n : int,m : int,k :[int],c :[int])->int :
    k.sort(reverse=True)
    cost=l=0
    for i in range(n):
        if ltoInteger() ;
    for _anon : Integer.subrange(0, rep-1) do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var k : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute (strangeBDParty(n, m, k, c))->display());
  operation strangeBDParty(n : int, m : int, k : Sequence{ OclType["int"] }, c : Sequence{ OclType["int"] }) : int
  pre: true post: true
  activity:
    k := k->sort() ;
    var cost : OclAny := 0; var l : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    if (l->compareTo(m)) < 0 & (c[l+1]->compareTo(c[k[i+1] - 1+1])) < 0 then  (
      cost := cost + c[l+1] ;
    l := l + 1
    )
    else (
      cost := cost + c[k[i+1] - 1+1]
      )) ;
    return cost;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
primes=[];
def segmentedSieve():
    n=10000 ;
    nNew=int((n-2)/2);
    marked=[False]*(nNew+1);
    for i in range(1,nNew+1):
        j=i ;
        while((i+j+2*i*j)<=nNew):
            marked[i+j+2*i*j]=True ;
            j+=1 ;
    primes.append(2);
    for i in range(1,nNew+1):
        if(marked[i]==False):
            primes.append(2*i+1);
def Nfactors(a,b,n):
    segmentedSieve();
    result=0 ;
    for i in range(a,b+1):
        tmp=math.sqrt(i);
        copy=i ;
        count=0 ;
        j=0 ;
        while(primes[j]<=tmp):
            if(copy % primes[j]==0):
                count+=1 ;
                while(copy % primes[j]==0):
                    copy=(copy//primes[j]);
            j+=1 ;
        if(copy!=1):
            count+=1 ;
        if(count==n):
            result+=1 ;
    return result ;
a=1 ;
b=100 ;
n=3 ;
print(Nfactors(a,b,n));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var primes : Sequence := Sequence{}; ;
    skip ;
    skip ;
    a := 1; ;
    b := 100; ;
    n := 3; ;
    execute (Nfactors(a, b, n))->display();;
  operation segmentedSieve()
  pre: true post: true
  activity:
    var n : int := 10000; ;
    var nNew : int := ("" + (((n - 2) / 2)))->toInteger(); ;
    var marked : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (nNew + 1)); ;
    for i : Integer.subrange(1, nNew + 1-1) do (    var j : OclAny := i; ;
    while (((i + j + 2 * i * j)->compareTo(nNew)) <= 0) do (    marked[i + j + 2 * i * j+1] := true; ;
    j := j + 1;)) ;
    execute ((2) : primes); ;
    for i : Integer.subrange(1, nNew + 1-1) do (    if (marked[i+1] = false) then (
      execute ((2 * i + 1) : primes);
    ) else skip);
  operation Nfactors(a : OclAny, b : OclAny, n : OclAny)
  pre: true post: true
  activity:
    segmentedSieve(); ;
    var result : int := 0; ;
    for i : Integer.subrange(a, b + 1-1) do (    var tmp : double := (i)->sqrt(); ;
    var copy : OclAny := i; ;
    var count : int := 0; ;
    j := 0; ;
    while ((primes[j+1]->compareTo(tmp)) <= 0) do (    if (copy mod primes[j+1] = 0) then (
      count := count + 1; ;
    while (copy mod primes[j+1] = 0) do (    copy := (copy div primes[j+1]);)
    ) else skip ;
    j := j + 1;) ;
    if (copy /= 1) then (
      count := count + 1;
    ) else skip ;
    if (count = n) then (
      result := result + 1;
    ) else skip) ;
    return result;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=list(map(int,input().split()))
x=["A","B","C"]
print(x[a.index(max(a))])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var x : Sequence := Sequence{"A"}->union(Sequence{"B"}->union(Sequence{ "C" })) ;
    execute (x[a->indexOf((a)->max()) - 1+1])->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import defaultdict
from heapq import heappush,heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int,sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return list(map(list,sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l=[None for i in range(n)]
    for i in range(n): l[i]=I()
    return l
def LIR(n):
    l=[None for i in range(n)]
    for i in range(n): l[i]=LI()
    return l
def SR(n):
    l=[None for i in range(n)]
    for i in range(n): l[i]=S()
    return l
def LSR(n):
    l=[None for i in range(n)]
    for i in range(n): l[i]=SR()
    return l
mod=1000000007
a=LI()
s="ABC"
print(s[a.index(max(a))])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var mod : int := 1000000007 ;
    var a : OclAny := LI() ;
    var s : String := "ABC" ;
    execute (s[a->indexOf((a)->max()) - 1+1])->display();
  operation LI() : OclAny
  pre: true post: true
  activity:
    return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ));
  operation I() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation LS() : OclAny
  pre: true post: true
  activity:
    return ((sys.stdin.readLine().split())->collect( _x | (OclType["Sequence"])->apply(_x) ));
  operation S() : OclAny
  pre: true post: true
  activity:
    return OclType["Sequence"]((OclFile["System.in"]).readLine())->front();
  operation IR(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var l : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ;
    for i : Integer.subrange(0, n-1) do (    l[i+1] := I()) ;
    return l;
  operation LIR(n : OclAny) : OclAny
  pre: true post: true
  activity:
    l := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ;
    for i : Integer.subrange(0, n-1) do (    l[i+1] := LI()) ;
    return l;
  operation SR(n : OclAny) : OclAny
  pre: true post: true
  activity:
    l := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ;
    for i : Integer.subrange(0, n-1) do (    l[i+1] := S()) ;
    return l;
  operation LSR(n : OclAny) : OclAny
  pre: true post: true
  activity:
    l := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ;
    for i : Integer.subrange(0, n-1) do (    l[i+1] := SR()) ;
    return l;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b,c=input().split(" ")
if int(a)>int(b):
    if int(a)>int(c):
        print("A")
    else :
        if int(b)>int(c):
            print("B")
        else :
            print("C")
else :
    if int(b)>int(c):
        print("B")
    else :
        print("C")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := input().split(" ") ;
    if (("" + ((a)))->toInteger()->compareTo(("" + ((b)))->toInteger())) > 0 then  (
      if (("" + ((a)))->toInteger()->compareTo(("" + ((c)))->toInteger())) > 0 then  (
      execute ("A")->display()
    )
    else (
      if (("" + ((b)))->toInteger()->compareTo(("" + ((c)))->toInteger())) > 0 then  (
      execute ("B")->display()
    )
    else (
      execute ("C")->display()
      )
      )
    )
    else (
      if (("" + ((b)))->toInteger()->compareTo(("" + ((c)))->toInteger())) > 0 then  (
      execute ("B")->display()
    )
    else (
      execute ("C")->display()
      )
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
A,B,C=map(int,input().split())
if max(A,B,C)==A :
    print("A")
elif max(A,B,C)==B :
    print("B")
else :
    print("C")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var A : OclAny := null;
    var B : OclAny := null;
    var C : OclAny := null;
    Sequence{A,B,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if Set{A, B, C}->max() = A then  (
      execute ("A")->display()
    )
    else (if Set{A, B, C}->max() = B then
   (
      execute ("B")->display()    
)
    else (
      execute ("C")->display()
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
menber=["A","B","C"]
menu=[int(x)for x in input().split()]
print(menber[menu.index(max(menu))])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var menber : Sequence := Sequence{"A"}->union(Sequence{"B"}->union(Sequence{ "C" })) ;
    var menu : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    execute (menber[menu->indexOf((menu)->max()) - 1+1])->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def countOddPair(A,N):
    count=0
    for i in range(0,N):
        if(A[i]% 2!=1):
            count+=1
    evenPairCount=count*(count-1)/2
    totPairs=N*(N-1)/2
    return(int)(totPairs-evenPairCount)
A=[5,6,2,8]
N=len(A)
print(countOddPair(A,N))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    A := Sequence{5}->union(Sequence{6}->union(Sequence{2}->union(Sequence{ 8 }))) ;
    N := (A)->size() ;
    execute (countOddPair(A, N))->display();
  operation countOddPair(A : OclAny, N : OclAny) : OclAny
  pre: true post: true
  activity:
    var count : int := 0 ;
    for i : Integer.subrange(0, N-1) do (    if (A[i+1] mod 2 /= 1) then (
      count := count + 1
    ) else skip) ;
    var evenPairCount : double := count * (count - 1) / 2 ;
    var totPairs : double := N * (N - 1) / 2 ;
    return (OclType["int"])(totPairs - evenPairCount);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def minOperations(n):
    count=0
    d=0
    if(n==1):
        return 0
    while(n>9):
        d=max(n % 10,d)
        n//=10
        count+=10
    d=max(d,n-1)
    count+=abs(d)
    return count-1
if __name__=='__main__' :
    n=240
    print(minOperations(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      n := 240 ;
    execute (minOperations(n))->display()
    ) else skip;
  operation minOperations(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var count : int := 0 ;
    var d : int := 0 ;
    if (n = 1) then (
      return 0
    ) else skip ;
    while (n > 9) do (    d := Set{n mod 10, d}->max() ;
    n := n div 10 ;
    count := count + 10) ;
    d := Set{d, n - 1}->max() ;
    count := count + (d)->abs() ;
    return count - 1;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
for x in range(10**5):
    if x**2>n :
        print((x-1)**2)
        break
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for x : Integer.subrange(0, (10)->pow(5)-1) do (    if ((x)->pow(2)->compareTo(n)) > 0 then (
      execute (((x - 1))->pow(2))->display() ;
    break
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    num=int(input())
    if num==0 :
        break
    L=[]
    for i in range(num):
        n,*k=input().split()
        L.append((n,k.count("0"),k.count("1"),i))
    L.sort(key=lambda x :(-x[1],x[2],x[3]))
    for x in L :
        print(x[0])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if num = 0 then (
      break
    ) else skip ;
    var L : Sequence := Sequence{} ;
    for i : Integer.subrange(0, num-1) do (    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := input().split() ;
    execute ((Sequence{n, k->count("0"), k->count("1"), i}) : L)) ;
    L := L->sort() ;
    for x : L do (    execute (x->first())->display()));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import deque,Counter
from math import*
import sys
import random
from bisect import*
from functools import reduce
from sys import stdin
from heapq import*
import copy
input=lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
    n,m=map(int,input().split())
    k=sorted(list(map(int,input().split())))
    c=list(map(int,input().split()))
    ans=0
    index=0
    for i in range(n-1,-1,-1):
        if c[k[i]-1]<=c[index]:
            ans+=c[k[i]-1]
        else :
            ans+=c[index]
            index+=1
    print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ;
    for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var k : Sequence := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ;
    var c : Sequence := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var ans : int := 0 ;
    var index : int := 0 ;
    for i : Integer.subrange(-1 + 1, n - 1)->reverse() do (    if (c[k[i+1] - 1+1]->compareTo(c[index+1])) <= 0 then  (
      ans := ans + c[k[i+1] - 1+1]
    )
    else (
      ans := ans + c[index+1] ;
    index := index + 1
      )) ;
    execute (ans)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
print(int((int(input())**.5))**2)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     execute ((("" + ((((("" + (((OclFile["System.in"]).readLine())))->toInteger())->pow(.5)))))->toInteger())->pow(2))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=int(input())
ans=1
i=1
while True :
    ans=i**2
    i+=1
    if i**2>N :
        break
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var ans : int := 1 ;
    var i : int := 1 ;
    while true do (    ans := (i)->pow(2) ;
    i := i + 1 ;
    if ((i)->pow(2)->compareTo(N)) > 0 then (
      break
    ) else skip) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
y=int(input())
p=(pow(y,0.5))
print(pow(int(p),2))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var y : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var p : double := ((y)->pow(0.5)) ;
    execute ((("" + ((p)))->toInteger())->pow(2))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
N=int(input())
print(math.floor(math.sqrt(N))**2)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    execute ((((N)->sqrt())->floor())->pow(2))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import ceil
def nDigitPerfectCubes(n):
    print(pow(ceil((pow(10,(n-1)))**(1/3)),3),end=" ")
    print(pow(ceil((pow(10,(n)))**(1/3))-1,3))
if __name__=="__main__" :
    n=3
    nDigitPerfectCubes(n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      n := 3 ;
    nDigitPerfectCubes(n)
    ) else skip;
  operation nDigitPerfectCubes(n : OclAny)
  pre: true post: true
  activity:
    execute ((ceil((((10)->pow((n - 1))))->pow((1 / 3))))->pow(3))->display() ;
    execute ((ceil((((10)->pow((n))))->pow((1 / 3))) - 1)->pow(3))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def countNumbersWith4(n):
    result=0
    for x in range(1,n+1):
        if(has4(x)==True):
            result=result+1
    return result
def has4(x):
    while(x!=0):
        if(x % 10==4):
            return True
        x=x//10
    return False
n=328
print("Count of numbers from 1 to ",n," that have 4 as a a digit is ",countNumbersWith4(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    n := 328 ;
    execute ("Count of numbers from 1 to ")->display();
  operation countNumbersWith4(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var result : int := 0 ;
    for x : Integer.subrange(1, n + 1-1) do (    if (has4(x) = true) then (
      result := result + 1
    ) else skip) ;
    return result;
  operation has4(x : OclAny) : OclAny
  pre: true post: true
  activity:
    while (x /= 0) do (    if (x mod 10 = 4) then (
      return true
    ) else skip ;
    x := x div 10) ;
    return false;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def summingSeries(n):
    S=0
    for i in range(1,n+1):
        S+=i*i-(i-1)*(i-1)
    return S
n=100
print("The sum of n term is: ",summingSeries(n),sep="")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    n := 100 ;
    execute ("The sum of n term is: ")->display();
  operation summingSeries(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var S : int := 0 ;
    for i : Integer.subrange(1, n + 1-1) do (    S := S + i * i - (i - 1) * (i - 1)) ;
    return S;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
def summingSeries(n):
    return math.pow(n,2)
n=100
print("The sum of n term is: ",summingSeries(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    n := 100 ;
    execute ("The sum of n term is: ")->display();
  operation summingSeries(n : OclAny) : OclAny
  pre: true post: true
  activity:
    return (n)->pow(2);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
w,h,n=map(int,input().split())
x,y=map(int,input().split())
ans=0
for i in range(n-1):
    xi,yi=map(int,input().split())
    if xi==x :
        ans+=abs(y-yi)
        y=yi
    elif yi==y :
        ans+=abs(x-xi)
        x=xi
    elif(x-xi)*(y-yi)>0 :
        ans+=max(abs(x-xi),abs(y-yi))
        x,y=xi,yi
    else :
        ans+=abs(x-xi)+abs(y-yi)
        x,y=xi,yi
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var w : OclAny := null;
    var h : OclAny := null;
    var n : OclAny := null;
    Sequence{w,h,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var ans : int := 0 ;
    for i : Integer.subrange(0, n - 1-1) do (    var xi : OclAny := null;
    var yi : OclAny := null;
    Sequence{xi,yi} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if xi = x then  (
      ans := ans + (y - yi)->abs() ;
    var y : OclAny := yi
    )
    else (if yi = y then
   (
      ans := ans + (x - xi)->abs() ;
    var x : OclAny := xi    
)
    else (if (x - xi) * (y - yi) > 0 then
   (
      ans := ans + Set{(x - xi)->abs(), (y - yi)->abs()}->max() ;
    Sequence{x,y} := Sequence{xi,yi}    
)
    else (
      ans := ans + (x - xi)->abs() + (y - yi)->abs() ;
    Sequence{x,y} := Sequence{xi,yi}
      )    )
    )
) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def get_distance(pre_x,pre_y,x,y):
    if(x>pre_x and y>pre_y)or(x=y_num :
            return x_num
        else :
            return y_num
    else :
        return abs(x-pre_x)+abs(y-pre_y)
line1=sys.stdin.readline().strip().split(' ')
w,h,n=[int(i)for i in line1]
start_line=sys.stdin.readline().strip().split(' ')
pre_x=int(start_line[0])
pre_y=int(start_line[1])
nums=0
for i in range(n-1):
    next_line=sys.stdin.readline().strip().split(' ')
    x=int(next_line[0])
    y=int(next_line[1])
    nums+=get_distance(pre_x,pre_y,x,y)
    pre_x=x
    pre_y=y
print(nums)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var line1 : OclAny := sys.stdin.readLine()->trim().split(' ') ;
    var w : OclAny := null;
    var h : OclAny := null;
    var n : OclAny := null;
    Sequence{w,h,n} := line1->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var start_line : OclAny := sys.stdin.readLine()->trim().split(' ') ;
    pre_x := ("" + ((start_line->first())))->toInteger() ;
    pre_y := ("" + ((start_line[1+1])))->toInteger() ;
    var nums : int := 0 ;
    for i : Integer.subrange(0, n - 1-1) do (    var next_line : OclAny := sys.stdin.readLine()->trim().split(' ') ;
    x := ("" + ((next_line->first())))->toInteger() ;
    y := ("" + ((next_line[1+1])))->toInteger() ;
    nums := nums + get_distance(pre_x, pre_y, x, y) ;
    pre_x := x ;
    pre_y := y) ;
    execute (nums)->display();
  operation get_distance(pre_x : OclAny, pre_y : OclAny, x : OclAny, y : OclAny) : OclAny
  pre: true post: true
  activity:
    if ((x->compareTo(pre_x)) > 0 & (y->compareTo(pre_y)) > 0) or ((x->compareTo(pre_x)) < 0 & (y->compareTo(pre_y)) < 0) then  (
      var x_num : double := (x - pre_x)->abs() ;
    var y_num : double := (y - pre_y)->abs() ;
    if (x_num->compareTo(y_num)) >= 0 then  (
      return x_num
    )
    else (
      return y_num
      )
    )
    else (
      return (x - pre_x)->abs() + (y - pre_y)->abs()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import deque,Counter
from math import*
import sys
import random
from bisect import*
from functools import reduce
from sys import stdin
from heapq import*
import copy
input=lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
    n,m=map(int,input().split())
    k=sorted(list(map(int,input().split())))
    c=list(map(int,input().split()))
    ans=0
    index=0
    for i in range(n-1,-1,-1):
        if c[k[i]-1]<=c[index]:
            ans+=c[k[i]-1]
        else :
            ans+=c[index]
            index+=1
    print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ;
    for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var k : Sequence := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ;
    var c : Sequence := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var ans : int := 0 ;
    var index : int := 0 ;
    for i : Integer.subrange(-1 + 1, n - 1)->reverse() do (    if (c[k[i+1] - 1+1]->compareTo(c[index+1])) <= 0 then  (
      ans := ans + c[k[i+1] - 1+1]
    )
    else (
      ans := ans + c[index+1] ;
    index := index + 1
      )) ;
    execute (ans)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def solve():
    from sys import stdin
    f_i=stdin
    ans=""
    while True :
        n=int(f_i.readline())
        if n==0 :
            break
        result=[]
        for i in range(n):
            score=f_i.readline()
            t=score[0]
            win=score.count('0')
            lose=score.count('1')
            result.append((-win,lose,i,t))
        result.sort()
        ans+='\n'.join(map(lambda x : x[-1],result))
        ans+='\n'
    print(ans,end='')
solve()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    solve();
  operation solve()
  pre: true post: true
  activity:
    skip ;
    var f_i : OclAny := stdin ;
    var ans : String := "" ;
    while true do (    var n : int := ("" + ((f_i.readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    var result : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    var score : String := f_i.readLine() ;
    var t : OclAny := score->first() ;
    var win : int := score->count('0') ;
    var lose : int := score->count('1') ;
    execute ((Sequence{-win, lose, i, t}) : result)) ;
    result := result->sort() ;
    ans := ans + StringLib.sumStringsWithSeparator(((result)->collect( _x | (lambda x : OclAny in (x->last()))->apply(_x) )), '
') ;
    ans := ans + '
') ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
INF=10001
W,H,N=list(map(int,input().split(' ')))
cities=[list(map(int,input().split(' ')))for i in range(N)]
ways=0
city=1
while city0 :
        tmp=min(abs(disty),abs(distx))
        ways+=tmp
        distx-=tmp*int(distx/abs(distx))
        disty-=tmp*int(disty/abs(disty))
    ways+=abs(distx)+abs(disty)
    city+=1
print(ways)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var INF : int := 10001 ;
    var W : OclAny := null;
    var H : OclAny := null;
    var N : OclAny := null;
    Sequence{W,H,N} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ;
    var cities : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var ways : int := 0 ;
    var city : int := 1 ;
    while (city->compareTo(N)) < 0 do (    var sx : OclAny := null;
    var sy : OclAny := null;
    Sequence{sx,sy} := cities[city - 1+1] ;
    var gx : OclAny := null;
    var gy : OclAny := null;
    Sequence{gx,gy} := cities[city+1] ;
    var distx : OclAny := null;
    var disty : OclAny := null;
    Sequence{distx,disty} := Sequence{gx - sx,gy - sy} ;
    if distx * disty > 0 then (
      var tmp : OclAny := Set{(disty)->abs(), (distx)->abs()}->min() ;
    ways := ways + tmp ;
    distx := distx - tmp * ("" + ((distx / (distx)->abs())))->toInteger() ;
    disty := disty - tmp * ("" + ((disty / (disty)->abs())))->toInteger()
    ) else skip ;
    ways := ways + (distx)->abs() + (disty)->abs() ;
    city := city + 1) ;
    execute (ways)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
w,h,n=[int(s)for s in input().split(" ")]
route=[[int(s)for s in input().split(" ")]for i in range(n)]
s=0
for i in range(len(route)-1):
    dx=route[i+1][0]-route[i][0]
    dy=route[i+1][1]-route[i][1]
    if dx==0 : s+=abs(dy)
    elif dy==0 : s+=abs(dx)
    elif dx*dy>0 : s+=max((abs(dx),abs(dy)))
    else : s+=abs(dx)+abs(dy)
print(s)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var w : OclAny := null;
    var h : OclAny := null;
    var n : OclAny := null;
    Sequence{w,h,n} := input().split(" ")->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ;
    var route : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (input().split(" ")->select(s | true)->collect(s | (("" + ((s)))->toInteger())))) ;
    var s : int := 0 ;
    for i : Integer.subrange(0, (route)->size() - 1-1) do (    var dx : double := route[i + 1+1]->first() - route[i+1]->first() ;
    var dy : double := route[i + 1+1][1+1] - route[i+1][1+1] ;
    if dx = 0 then  (
      s := s + (dy)->abs()
    )
    else (if dy = 0 then
   (
      s := s + (dx)->abs()    
)
    else (if dx * dy > 0 then
   (
      s := s + (Sequence{(dx)->abs(), (dy)->abs()})->max()    
)
    else (
      s := s + (dx)->abs() + (dy)->abs()
      )    )
    )
) ;
    execute (s)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
w,h,n=map(int,input().split())
dist=[]
for _ in range(n):
    x,y=map(int,input().split())
    dist.append([x,y])
start=dist.pop(0)
x1,y1=start
cnt=0
for d in dist :
    x2,y2=d
    while 1 :
        if x1==x2 and y1==y2 :
            break
        cnt+=1
        if x1x2 and y1x2 and y1==y2 :
            x1-=1
        elif x1y2 :
            if y1!=0 :
                y1-=1
            else :
                x1+=1
        elif x1==x2 and y1>y2 :
            y1-=1
        elif x1>x2 and y1>y2 :
            x1-=1
            y1-=1
print(cnt)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var w : OclAny := null;
    var h : OclAny := null;
    var n : OclAny := null;
    Sequence{w,h,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var dist : Sequence := Sequence{} ;
    for _anon : Integer.subrange(0, n-1) do (    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute ((Sequence{x}->union(Sequence{ y })) : dist)) ;
    var start : OclAny := dist->at(0`firstArg+1) ;     dist := dist->excludingAt(0+1) ;
    var x1 : OclAny := null;
    var y1 : OclAny := null;
    Sequence{x1,y1} := start ;
    var cnt : int := 0 ;
    for d : dist do (    var x2 : OclAny := null;
    var y2 : OclAny := null;
    Sequence{x2,y2} := d ;
    while 1 do (    if x1 = x2 & y1 = y2 then (
      break
    ) else skip ;
    cnt := cnt + 1 ;
    if (x1->compareTo(x2)) < 0 & (y1->compareTo(y2)) < 0 then  (
      x1 := x1 + 1 ;
    y1 := y1 + 1
    )
    else (if x1 = x2 & (y1->compareTo(y2)) < 0 then
   (
      y1 := y1 + 1    
)
    else (if (x1->compareTo(x2)) > 0 & (y1->compareTo(y2)) < 0 then
   (
      if y1 /= h then  (
      y1 := y1 + 1
    )
    else (
      x1 := x1 - 1
      )    
)
    else (if (x1->compareTo(x2)) < 0 & y1 = y2 then
   (
      x1 := x1 + 1    
)
    else (if (x1->compareTo(x2)) > 0 & y1 = y2 then
   (
      x1 := x1 - 1    
)
    else (if (x1->compareTo(x2)) < 0 & (y1->compareTo(y2)) > 0 then
   (
      if y1 /= 0 then  (
      y1 := y1 - 1
    )
    else (
      x1 := x1 + 1
      )    
)
    else (if x1 = x2 & (y1->compareTo(y2)) > 0 then
   (
      y1 := y1 - 1    
)
    else (if (x1->compareTo(x2)) > 0 & (y1->compareTo(y2)) > 0 then
   (
      x1 := x1 - 1 ;
    y1 := y1 - 1    
)
    else skip    )
    )
    )
    )
    )
    )
    )
)) ;
    execute (cnt)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def maxConsecutiveOnes(x):
    count=0
    while(x!=0):
        x=(x &(x<<1))
        count=count+1
    return count
print(maxConsecutiveOnes(14))
print(maxConsecutiveOnes(222))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    execute (maxConsecutiveOnes(14))->display() ;
    execute (maxConsecutiveOnes(222))->display();
  operation maxConsecutiveOnes(x : OclAny) : OclAny
  pre: true post: true
  activity:
    var count : int := 0 ;
    while (x /= 0) do (    x := (MathLib.bitwiseAnd(x, (x * (2->pow(1))))) ;
    count := count + 1) ;
    return count;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=map(int,input().split())
print('Even' if a*b % 2==0 else 'Odd')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (if a * b mod 2 = 0 then 'Even' else 'Odd' endif)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))
a,b=mp()
if(a*b)% 2==1 :
    print("Odd")
else :
    print("Even")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := mp() ;
    if (a * b) mod 2 = 1 then  (
      execute ("Odd")->display()
    )
    else (
      execute ("Even")->display()
      );
  operation input() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine()->trim();
  operation mp() : OclAny
  pre: true post: true
  activity:
    return (input().split())->collect( _x | (OclType["int"])->apply(_x) );
  operation lmp() : OclAny
  pre: true post: true
  activity:
    return ((input().split())->collect( _x | (OclType["int"])->apply(_x) ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    x,y=(int(x)for x in input().split())
    prod=x*y
    if(prod % 2):
        print("Odd",sep="")
    else :
        print("Even",sep="")
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ;
    var prod : double := x * y ;
    if (prod mod 2) then  (
      execute ("Odd")->display()
    )
    else (
      execute ("Even")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
values=input().split(" ")
n1=int(values[0])
n2=int(values[1])
if(n1 % 2==0)or(n2 % 2==0):
    print("Even")
else :
    print("Odd")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var values : OclAny := input().split(" ") ;
    var n1 : int := ("" + ((values->first())))->toInteger() ;
    var n2 : int := ("" + ((values[1+1])))->toInteger() ;
    if (n1 mod 2 = 0) or (n2 mod 2 = 0) then  (
      execute ("Even")->display()
    )
    else (
      execute ("Odd")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
ab_str=input()
a_str,b_str=ab_str.split()
a=int(a_str)
b=int(b_str)
if a % 2==0 or b % 2==0 :
    print('Even')
else :
    print('Odd')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var ab_str : String := (OclFile["System.in"]).readLine() ;
    var a_str : OclAny := null;
    var b_str : OclAny := null;
    Sequence{a_str,b_str} := ab_str.split() ;
    var a : int := ("" + ((a_str)))->toInteger() ;
    var b : int := ("" + ((b_str)))->toInteger() ;
    if a mod 2 = 0 or b mod 2 = 0 then  (
      execute ('Even')->display()
    )
    else (
      execute ('Odd')->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
import math
input=sys.stdin.readline
t=int(input())
for _ in range(t):
    n,m=map(int,input().split())
    ar=list(map(int,input().split()))
    z=list(map(int,input().split()))
    ar.sort(reverse=True)
    ans=i=0
    for x in range(n):
        if itoInteger() ;
    for _anon : Integer.subrange(0, t-1) do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var ar : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var z : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    ar := ar->sort() ;
    var ans : OclAny := 0; var i : int := 0 ;
    for x : Integer.subrange(0, n-1) do (    if (i->compareTo(m)) < 0 & (i->compareTo(ar[x+1] - 1)) <= 0 then  (
      ans := ans + z[i+1] ;
    i := i + 1
    )
    else (
      ans := ans + z[ar[x+1] - 1+1]
      )) ;
    execute (ans)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
class Solution(object):
    def numberToWords(self,num):
        to19='One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve ' 'Thirteen Fourteen Fifteen Sixteen Seventeen Eighteen Nineteen'.split()
        tens='Twenty Thirty Forty Fifty Sixty Seventy Eighty Ninety'.split()
        def words(n):
            if n<20 :
                return to19[n-1 : n]
            if n<100 :
                return[tens[n/10-2]]+words(n % 10)
            if n<1000 :
                return[to19[n/100-1]]+['Hundred']+words(n % 100)
            for p,w in enumerate(('Thousand','Million','Billion'),1):
                if n<1000**(p+1):
                    return words(n/1000**p)+[w]+words(n % 1000**p)
        return ' '.join(words(num))or 'Zero'
------------------------------------------------------------
OCL File:
---------
class Solution extends object {
  static operation newSolution() : Solution
  pre: true
  post: Solution->exists( _x | result = _x );
  operation numberToWords(num : OclAny) : OclAny
  pre: true post: true
  activity:
    var to19 : OclAny := (atom 'One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve ' 'Thirteen Fourteen Fifteen Sixteen Seventeen Eighteen Nineteen').split() ;
    var tens : OclAny := 'Twenty Thirty Forty Fifty Sixty Seventy Eighty Ninety'.split() ;
    skip ;
    return StringLib.sumStringsWithSeparator((words(num)), ' ') or 'Zero';
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def parse(i):
    l=input().strip().split()
    m=l.pop(0)
    return(-l.count('0'),l.count('1'),i,m)
n=int(input())
while n :
    print('\n'.join(str(t[3])for t in sorted([parse(_)for _ in range(n)])))
    n=int(input())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    while n do (    execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 3))))))))) ])))))))) ))))))) (comp_for for (exprlist (expr (atom (name t)))) in (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name parse)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name _)))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) ]))))))) ))))))))), '
'))->display() ;
    n := ("" + (((OclFile["System.in"]).readLine())))->toInteger());
  operation parse(i : OclAny) : OclAny
  pre: true post: true
  activity:
    var l : OclAny := input()->trim().split() ;
    var m : OclAny := l->at(0`firstArg+1) ;     l := l->excludingAt(0+1) ;
    return Sequence{-l->count('0'), l->count('1'), i, m};
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
q=int(input())
for loop in range(q):
    n,k=map(int,input().split())
    print(min(n,(n//k)*k+(k//2)))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for loop : Integer.subrange(0, q-1) do (    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (Set{n, (n div k) * k + (k div 2)}->min())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for s in[*open(0)][1 :]: n,k=map(int,s.split()); print(n-max(0,n % k-k//2))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do (    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (s.split())->collect( _x | (OclType["int"])->apply(_x) );    execute (n - Set{0, n mod k - k div 2}->max())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for i in range(int(input())):
    n,k=map(int,input().split(' '))
    rem=n % k
    if rem>k//2 :
        rem-=k//2
    else :
        rem=0
    print(n-rem)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ;
    var rem : int := n mod k ;
    if (rem->compareTo(k div 2)) > 0 then  (
      rem := rem - k div 2
    )
    else (
      rem := 0
      ) ;
    execute (n - rem)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for j in range(t):
    n,k=map(int,input().split())
    k1=n-n % k
    print(n-n % k+min(n % k,k//2))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for j : Integer.subrange(0, t-1) do (    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var k1 : double := n - n mod k ;
    execute (n - n mod k + Set{n mod k, k div 2}->min())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
testcase=int(input())
for _ in range(testcase):
    n,k=map(int,input().split())
    data=(n//k)*k
    rem=n % k
    print(data+min(k//2,rem))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var testcase : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, testcase-1) do (    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var data : double := (n div k) * k ;
    var rem : int := n mod k ;
    execute (data + Set{k div 2, rem}->min())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
s=[]
all=''
for i in range(n):
    t=input()
    s.append(t)
    all=all+t
u=list(set(all))
m=[]
for i in range(len(u)):
    for j in range(i+1,len(u)):
        t=0
        for e in s :
            if set(e).issubset({u[i],u[j]}):
                t=t+len(e)
        m.append(t)
if len(u)==1 :
    print(len(all))
else :
    print(max(m))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : Sequence := Sequence{} ;
    var all : String := '' ;
    for i : Integer.subrange(0, n-1) do (    var t : String := (OclFile["System.in"]).readLine() ;
    execute ((t) : s) ;
    all := all + t) ;
    var u : Sequence := (Set{}->union((all))) ;
    var m : Sequence := Sequence{} ;
    for i : Integer.subrange(0, (u)->size()-1) do (    for j : Integer.subrange(i + 1, (u)->size()-1) do (    t := 0 ;
    for e : s do (    if Set{}->union((e)) <: (Set{u[i+1]}->union(Set{ u[j+1] })) then (
      t := t + (e)->size()
    ) else skip) ;
    execute ((t) : m))) ;
    if (u)->size() = 1 then  (
      execute ((all)->size())->display()
    )
    else (
      execute ((m)->max())->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a=[]
b=[]
for i in range(n):
    s=input()
    a.append(sorted(list(set(s))))
    b.append(len(s))
v=0
for i in range(97,97+25):
    for j in range(98,97+26):
        u=0
        for k in range(n):
            for c in a[k]:
                if ord(c)!=i and ord(c)!=j :
                    break
            else :
                u+=b[k]
        v=max(u,v)
print(v)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := Sequence{} ;
    var b : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    var s : String := (OclFile["System.in"]).readLine() ;
    execute (((Set{}->union((s)))->sort()) : a) ;
    execute (((s)->size()) : b)) ;
    var v : int := 0 ;
    for i : Integer.subrange(97, 97 + 25-1) do (    for j : Integer.subrange(98, 97 + 26-1) do (    var u : int := 0 ;
    for k : Integer.subrange(0, n-1) do ((compound_stmt for (exprlist (expr (atom (name c)))) in (testlist (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ]))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name ord)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))) != (comparison (expr (atom (name i)))))) and (logical_test (comparison (comparison (expr (atom (name ord)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))) != (comparison (expr (atom (name j)))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name u)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ]))))))))))))))) ;
    v := Set{u, v}->max())) ;
    execute (v)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
arr=[]
for i in range(n):
    x=input()
    arr.append(x)
res=0
for i in range(0,26):
    for j in range(0,26):
        r=0
        for x in arr :
            for z in x :
                if ord(z)-ord('a')!=i and ord(z)-ord('a')!=j :
                    break
            else :
                r+=len(x)
        res=max(res,r)
print(res)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var arr : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    var x : String := (OclFile["System.in"]).readLine() ;
    execute ((x) : arr)) ;
    var res : int := 0 ;
    for i : Integer.subrange(0, 26-1) do (    for j : Integer.subrange(0, 26-1) do (    var r : int := 0 ;
    for x : arr do ((compound_stmt for (exprlist (expr (atom (name z)))) in (testlist (test (logical_test (comparison (expr (atom (name x))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (expr (atom (name ord)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name z)))))))) )))) - (expr (atom (name ord)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'a'))))))) )))))) != (comparison (expr (atom (name i)))))) and (logical_test (comparison (comparison (expr (expr (atom (name ord)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name z)))))))) )))) - (expr (atom (name ord)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'a'))))))) )))))) != (comparison (expr (atom (name j)))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name r)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))))))))))))))) ;
    res := Set{res, r}->max())) ;
    execute (res)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def sqroot(s):
    pSq=0 ;
    N=0 ;
    for i in range(int(s),0,-1):
        for j in range(1,i):
            if(j*j==i):
                pSq=i ;
                N=j ;
                break ;
        if(pSq>0):
            break ;
    d=s-pSq ;
    P=d/(2.0*N);
    A=N+P ;
    sqrt_of_s=A-((P*P)/(2.0*A));
    return sqrt_of_s ;
num=9.2345 ;
sqroot_of_num=sqroot(num);
print("Square root of ",num,"=",round((sqroot_of_num*100000.0)/100000.0,5));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var num : double := 9.2345; ;
    var sqroot_of_num : OclAny := sqroot(num); ;
    execute ("Square root of ")->display();;
  operation sqroot(s : OclAny)
  pre: true post: true
  activity:
    var pSq : int := 0; ;
    var N : int := 0; ;
    for i : Integer.subrange(0 + 1, ("" + ((s)))->toInteger())->reverse() do (    for j : Integer.subrange(1, i-1) do (    if (j * j = i) then (
      pSq := i; ;
    N := j; ;
    break;
    ) else skip) ;
    if (pSq > 0) then (
      break;
    ) else skip) ;
    var d : double := s - pSq; ;
    var P : double := d / (2.0 * N); ;
    var A : int := N + P; ;
    var sqrt_of_s : double := A - ((P * P) / (2.0 * A)); ;
    return sqrt_of_s;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from audioop import reverse
def solve(A,B):
    A.sort(reverse=True)
    s=0
    m=0
    for i in range(len(A)):
        if m=A[i]-1 or B[m]>=B[A[i]-1]):
            s+=B[A[i]-1]
        elif m>=len(B):
            s+=B[A[i]-1]
        else :
            s+=B[m]
            m+=1
    return s
t=int(input())
for _ in range(t):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))[: n]
    b=list(map(int,input().split()))[: m]
    print(solve(a,b))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, t-1) do (    var n : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ;
    var b : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,m) ;
    execute (solve(a, b))->display());
  operation solve(A : OclAny, B : OclAny) : OclAny
  pre: true post: true
  activity:
    A := A->sort() ;
    var s : int := 0 ;
    var m : int := 0 ;
    for i : Integer.subrange(0, (A)->size()-1) do (    if (m->compareTo((B)->size())) < 0 & ((m->compareTo(A[i+1] - 1)) >= 0 or (B[m+1]->compareTo(B[A[i+1] - 1+1])) >= 0) then  (
      s := s + B[A[i+1] - 1+1]
    )
    else (if (m->compareTo((B)->size())) >= 0 then
   (
      s := s + B[A[i+1] - 1+1]    
)
    else (
      s := s + B[m+1] ;
    m := m + 1
      )    )
) ;
    return s;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
w=[input()for _ in range(int(input()))]
w=[c for c in w if len(set(c))<=2]
b=-1
for i in range(25):
    for j in range(i+1,26):
        b=max(b,sum(len(c)for c in w if set(c)<={chr(97+i),chr(97+j)}))
print(b)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var w : Sequence := Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ;
    w := w->select(c | (Set{}->union((c)))->size() <= 2)->collect(c | (c)) ;
    var b : int := -1 ;
    for i : Integer.subrange(0, 25-1) do (    for j : Integer.subrange(i + 1, 26-1) do (    b := Set{b, ((argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name w))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))) <= (comparison (expr (atom { (dictorsetmaker (testlist_comp (test (logical_test (comparison (expr (atom (name chr)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (number (integer 97)))) + (expr (atom (name i))))))))) ))))))) , (test (logical_test (comparison (expr (atom (name chr)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (number (integer 97)))) + (expr (atom (name j))))))))) ))))))))) }))))))))))->sum()}->max())) ;
    execute (b)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a=[input()for i in range(n)]
alp='qwertyuiopasdfghjklzxcvbnm'
ans=0
for i in range(26):
    for j in range(i+1,26):
        c1,c2=alp[i],alp[j]
        cur=0
        for s in a :
            if set(s)in({c1,c2},{c1},{c2}):
                cur+=len(s)
        ans=max(ans,cur)
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ;
    var alp : String := 'qwertyuiopasdfghjklzxcvbnm' ;
    var ans : int := 0 ;
    for i : Integer.subrange(0, 26-1) do (    for j : Integer.subrange(i + 1, 26-1) do (    var c1 : OclAny := null;
    var c2 : OclAny := null;
    Sequence{c1,c2} := Sequence{alp[i+1],alp[j+1]} ;
    var cur : int := 0 ;
    for s : a do (    if (Sequence{Set{c1}->union(Set{ c2 }), Set{ c1 }, Set{ c2 }})->includes(Set{}->union((s))) then (
      cur := cur + (s)->size()
    ) else skip) ;
    ans := Set{ans, cur}->max())) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
import os
import random
import re
import sys
from math import gcd
from math import sqrt
from collections import Counter
n=int(input())
def f(x):
    x+=1
    while(x % 10==0):
        x//=10
    return x
st=set()
while(not(n in st)):
    st.add(n)
    n=f(n)
print(len(st))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    skip ;
    var st : Set := Set{}->union(()) ;
    while (not(((st)->includes(n)))) do (    execute ((n) : st) ;
    n := f(n)) ;
    execute ((st)->size())->display();
  operation f(x : OclAny) : OclAny
  pre: true post: true
  activity:
    x := x + 1 ;
    while (x mod 10 = 0) do (    x := x div 10) ;
    return x;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
from sys import stdin
from heapq import heappop,heappush
input=stdin.readline
def main(args):
    while True :
        n=int(input())
        if n==0 :
            break
        pq=[]
        for seq in range(n):
            temp=input().split()
            team_name=temp[0]
            temp=temp[1 :]
            win_count=temp.count('0')
            lose_count=temp.count('1')
            heappush(pq,(-win_count,lose_count,seq,team_name))
        while pq :
            _,_,_,team_name=heappop(pq)
            print(team_name)
if __name__=='__main__' :
    main(sys.argv[1 :])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    var input : OclAny := stdin.readline ;
    skip ;
    if __name__ = '__main__' then (
      main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))
    ) else skip;
  operation main(args : OclAny)
  pre: true post: true
  activity:
    while true do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    var pq : Sequence := Sequence{} ;
    for seq : Integer.subrange(0, n-1) do (    var temp : OclAny := input().split() ;
    var team_name : OclAny := temp->first() ;
    temp := temp->tail() ;
    var win_count : int := temp->count('0') ;
    var lose_count : int := temp->count('1') ;
    heappush(pq, Sequence{-win_count, lose_count, seq, team_name})) ;
    while pq do (    var _anon : OclAny := null;
    var _anon : OclAny := null;
    var _anon : OclAny := null;
    Sequence{_anon,_anon,_anon,team_name} := heappop(pq) ;
    execute (team_name)->display()));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    n=int(input())
    if n==0 :
        break
    a=sorted([int(input())for i in range(n)])
    print(sum([a[i]*(n-i-1)for i in range(n-1)]))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))->sort() ;
    execute ((Integer.subrange(0, n - 1-1)->select(i | true)->collect(i | (a[i+1] * (n - i - 1))))->sum())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
W=[0]
def solve(data):
    global W
    total=0
    data.sort()
    for i,t in enumerate(data):
        W.append(W[i]+t)
    W[-1]=0
    return sum(W)
def main(args):
    global W
    while True :
        n=int(input())
        if n==0 :
            break
        data=[int(input())for _ in range(n)]
        result=solve(data)
        print(result)
        W=[0]
if __name__=='__main__' :
    main(sys.argv[1 :])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  attribute W : OclAny;
  attribute W : OclAny;
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var W : Sequence := Sequence{ 0 } ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))
    ) else skip;
  operation solve(data : OclAny) : OclAny
  pre: true post: true
  activity:
    skip ;
    var total : int := 0 ;
    data := data->sort() ;
    for _tuple : Integer.subrange(1, (data)->size())->collect( _indx | Sequence{_indx-1, (data)->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var t : OclAny := _tuple->at(_indx);
      execute ((W[i+1] + t) : W)) ;
    W->last() := 0 ;
    return (W)->sum();
  operation main(args : OclAny)
  pre: true post: true
  activity:
    skip ;
    while true do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    data := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ;
    var result : OclAny := solve(data) ;
    execute (result)->display() ;
    W := Sequence{ 0 });
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
import os
import math
for s in sys.stdin :
    n=int(s)
    if n==0 :
        break
    A=[]
    for i in range(n):
        A.append(int(input()))
    A.sort()
    ans=0
    for i,a in enumerate(A):
        ans+=a*(n-i-1)
    print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    for s : OclFile["System.in"] do (    var n : int := ("" + ((s)))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    var A : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : A)) ;
    A := A->sort() ;
    var ans : int := 0 ;
    for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var a : OclAny := _tuple->at(_indx);
      ans := ans + a * (n - i - 1)) ;
    execute (ans)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    try :
        n=int(input())
        if n==0 :
            break
        ans=0
        add=0
        arr=[]
        for i in range(0,n):
            arr.append(int(input()))
        arr=sorted(arr)
        for i in range(0,n-1):
            add+=arr[i]
            ans+=add
        print(ans)
    except :
        break
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    try (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    var ans : int := 0 ;
    var add : int := 0 ;
    var arr : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : arr)) ;
    arr := arr->sort() ;
    for i : Integer.subrange(0, n - 1-1) do (    add := add + arr[i+1] ;
    ans := ans + add) ;
    execute (ans)->display())
     catch (_e : OclException) do (    break)
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while 1 :
    cust_list=[]
    ans=0
    n=int(input())
    if n==0 : break
    for i in range(n):
        cust_list.append(int(input()))
    cust_list.sort()
    for i in range(len(cust_list)):
        ans+=sum(cust_list[: i])
    print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while 1 do (    var cust_list : Sequence := Sequence{} ;
    var ans : int := 0 ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    for i : Integer.subrange(0, n-1) do (    execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : cust_list)) ;
    cust_list := cust_list->sort() ;
    for i : Integer.subrange(0, (cust_list)->size()-1) do (    ans := ans + (cust_list.subrange(1,i))->sum()) ;
    execute (ans)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def min(x,y):
    return x if(xy)else y
def findLength(arr,n):
    max_len=1
    for i in range(n-1):
        mn=arr[i]
        mx=arr[i]
        for j in range(i+1,n):
            mn=min(mn,arr[j])
            mx=max(mx,arr[j])
            if((mx-mn)==j-i):
                max_len=max(max_len,mx-mn+1)
    return max_len
arr=[1,56,58,57,90,92,94,93,91,45]
n=len(arr)
print("Length of the longest contiguous subarray is ",findLength(arr,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    arr := Sequence{1}->union(Sequence{56}->union(Sequence{58}->union(Sequence{57}->union(Sequence{90}->union(Sequence{92}->union(Sequence{94}->union(Sequence{93}->union(Sequence{91}->union(Sequence{ 45 }))))))))) ;
    n := (arr)->size() ;
    execute ("Length of the longest contiguous subarray is ")->display();
  operation min(x : OclAny, y : OclAny) : OclAny
  pre: true post: true
  activity:
    return if ((x->compareTo(y)) < 0) then x else y endif;
  operation max(x : OclAny, y : OclAny) : OclAny
  pre: true post: true
  activity:
    return if ((x->compareTo(y)) > 0) then x else y endif;
  operation findLength(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var max_len : int := 1 ;
    for i : Integer.subrange(0, n - 1-1) do (    var mn : OclAny := arr[i+1] ;
    var mx : OclAny := arr[i+1] ;
    for j : Integer.subrange(i + 1, n-1) do (    mn := Set{mn, arr[j+1]}->min() ;
    mx := Set{mx, arr[j+1]}->max() ;
    if ((mx - mn) = j - i) then (
      max_len := Set{max_len, mx - mn + 1}->max()
    ) else skip)) ;
    return max_len;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def findMaximumNum(arr,n):
    i=n
    while(i>=1):
        count=0
        for j in range(0,n,1):
            if(i<=arr[j]):
                count+=1
        if(count>=i):
            return i
        i-=1
    return 1
if __name__=='__main__' :
    arr=[1,2,3,8,10]
    n=len(arr)
    print(findMaximumNum(arr,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{8}->union(Sequence{ 10 })))) ;
    n := (arr)->size() ;
    execute (findMaximumNum(arr, n))->display()
    ) else skip;
  operation findMaximumNum(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var i : OclAny := n ;
    while (i >= 1) do (    var count : int := 0 ;
    for j : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do (    if ((i->compareTo(arr[j+1])) <= 0) then (
      count := count + 1
    ) else skip) ;
    if ((count->compareTo(i)) >= 0) then (
      return i
    ) else skip ;
    i := i - 1) ;
    return 1;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def compute():
    ans=sum(1 for i in range(10000)if is_lychrel(i))
    return str(ans)
def is_lychrel(n):
    for i in range(50):
        n+=int(str(n)[: :-1])
        if str(n)==str(n)[: :-1]:
            return False
    return True
if __name__=="__main__" :
    print(compute())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      execute (compute())->display()
    ) else skip;
  operation compute() : OclAny
  pre: true post: true
  activity:
    var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 10000))))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (atom (name is_lychrel)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))))->sum() ;
    return ("" + ((ans)));
  operation is_lychrel(n : OclAny) : OclAny
  pre: true post: true
  activity:
    for i : Integer.subrange(0, 50-1) do (    n := n + ("" + ((OclType["String"](n)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))))->toInteger() ;
    if ("" + ((n))) = OclType["String"](n)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then (
      return false
    ) else skip) ;
    return true;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def compute():
    TOTAL=200
    ways=[1]+[0]*TOTAL
    for coin in[1,2,5,10,20,50,100,200]:
        for i in range(len(ways)-coin):
            ways[i+coin]+=ways[i]
    return str(ways[-1])
if __name__=="__main__" :
    print(compute())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      execute (compute())->display()
    ) else skip;
  operation compute() : OclAny
  pre: true post: true
  activity:
    var TOTAL : int := 200 ;
    var ways : Sequence := Sequence{ 1 }->union(MatrixLib.elementwiseMult(Sequence{ 0 }, TOTAL)) ;
    for coin : Sequence{1}->union(Sequence{2}->union(Sequence{5}->union(Sequence{10}->union(Sequence{20}->union(Sequence{50}->union(Sequence{100}->union(Sequence{ 200 }))))))) do (    for i : Integer.subrange(0, (ways)->size() - coin-1) do (    ways[i + coin+1] := ways[i + coin+1] + ways[i+1])) ;
    return ("" + ((ways->last())));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
L,R=map(int,input().split())
if R-L>=673 :
    print(0)
elif R-L==1 :
    print((R*L)% 2019)
else :
    L %=2019
    R %=2019
    if L>R :
        print(0)
    else :
        ans=(L*R)% 2019
        for l in range(L,R):
            for r in range(l+1,R+1):
                val=(l*r)% 2019
                ans=min(ans,val)
        print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var L : OclAny := null;
    var R : OclAny := null;
    Sequence{L,R} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if R - L >= 673 then  (
      execute (0)->display()
    )
    else (if R - L = 1 then
   (
      execute ((R * L) mod 2019)->display()    
)
    else (
      L := L mod 2019 ;
    R := R mod 2019 ;
    if (L->compareTo(R)) > 0 then  (
      execute (0)->display()
    )
    else (
      var ans : int := (L * R) mod 2019 ;
    for l : Integer.subrange(L, R-1) do (    for r : Integer.subrange(l + 1, R + 1-1) do (    var val : int := (l * r) mod 2019 ;
    ans := Set{ans, val}->min())) ;
    execute (ans)->display()
      )
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
mod=2019
l,r=[int(i)for i in input().split()]
minimum=2018
for i in range(l,r):
    for j in range(l+1,r+1):
        if minimum==0 :
            break
        elif(i*j)% modselect(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var minimum : int := 2018 ;
    for i : Integer.subrange(l, r-1) do (    for j : Integer.subrange(l + 1, r + 1-1) do (    if minimum = 0 then  (
      break
    )
    else (if ((i * j) mod mod->compareTo(minimum)) < 0 then
   (
      minimum := (i * j) mod mod    
)
    else (
      skip
      )    )
) ;
    if minimum = 0 then (
      break
    ) else skip) ;
    execute (minimum)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
class team :
    def __init__(self,name,result):
        self.name=name
        self.win=0
        self.lose=0
        for i in range(len(result)):
            if result[i]==0 :
                self.win+=1
            elif result[i]==1 :
                self.lose+=1
            else :
                pass
while True :
    results=[]
    n=int(input())
    if n==0 :
        break
    for i in range(n):
        lst=input().split()
        name=lst[0]
        lst=lst[1 :]
        result=list(map(int,lst))
        results.append(team(name,result))
    results=sorted(results,key=lambda w : w.lose)
    results=sorted(results,key=lambda w : w.win,reverse=True)
    for i in range(n):
        print(results[i].name)
------------------------------------------------------------
OCL File:
---------
class team {
  static operation newteam() : team
  pre: true
  post: team->exists( _x | result = _x );
  attribute name : int := name;
  attribute win : int := 0;
  attribute lose : int := 0;
  operation initialise(name : OclAny,result : OclAny) : team
  pre: true post: true
  activity:
    self.name := name ;
    self.win := 0 ;
    self.lose := 0 ;
    for i : Integer.subrange(0, (result)->size()-1) do (    if result[i+1] = 0 then  (
      self.win := self.win + 1
    )
    else (if result[i+1] = 1 then
   (
      self.lose := self.lose + 1    
)
    else (
      skip
      )    )
);
    return self;
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    while true do (    var results : Sequence := Sequence{} ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    for i : Integer.subrange(0, n-1) do (    var lst : OclAny := input().split() ;
    name := lst->first() ;
    lst := lst->tail() ;
    result := ((lst)->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute (((team.newteam()).initialise(name, result)) : results)) ;
    results := results->sortedBy($x | (lambda w : OclAny in (w.lose))->apply($x)) ;
    results := results->sortedBy($x | (lambda w : OclAny in (w.win))->apply($x)) ;
    for i : Integer.subrange(0, n-1) do (    execute (results[i+1].name)->display()));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
L,R=[int(i)for i in input().split()]
if R-L>2019 :
    print(0)
    exit()
else :
    li=list(range(L,R+1))
    n=len(li)
ans=10**9+7
for i in range(n-1):
    for j in range(i+1,n):
        count=(li[i]*li[j])% 2019
        ans=min(ans,count)
        if ans==0 :
            print(0)
            exit()
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var L : OclAny := null;
    var R : OclAny := null;
    Sequence{L,R} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    if R - L > 2019 then  (
      execute (0)->display() ;
    exit()
    )
    else (
      var li : Sequence := (Integer.subrange(L, R + 1-1)) ;
    var n : int := (li)->size()
      ) ;
    var ans : double := (10)->pow(9) + 7 ;
    for i : Integer.subrange(0, n - 1-1) do (    for j : Integer.subrange(i + 1, n-1) do (    var count : int := (li[i+1] * li[j+1]) mod 2019 ;
    ans := Set{ans, count}->min() ;
    if ans = 0 then (
      execute (0)->display() ;
    exit()
    ) else skip)) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
L,R=map(int,input().split())
def repeat_division(n):
    while True :
        if n<2019 :
            break
        n %=2019
    return n
l=repeat_division(L)
r=repeat_division(R)
if R-L>=2019 :
    print(0)
elif l>r :
    print(0)
else :
    min=2019
    for k in range(l,r):
        for i in range(k+1,r+1):
            if min>repeat_division(k*i):
                min=repeat_division(k*i)
    print(min)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var L : OclAny := null;
    var R : OclAny := null;
    Sequence{L,R} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    skip ;
    var l : OclAny := repeat_division(L) ;
    var r : OclAny := repeat_division(R) ;
    if R - L >= 2019 then  (
      execute (0)->display()
    )
    else (if (l->compareTo(r)) > 0 then
   (
      execute (0)->display()    
)
    else (
      var min : int := 2019 ;
    for k : Integer.subrange(l, r-1) do (    for i : Integer.subrange(k + 1, r + 1-1) do (    if (min->compareTo(repeat_division(k * i))) > 0 then (
      min := repeat_division(k * i)
    ) else skip)) ;
    execute (min)->display()
      )    )
;
  operation repeat_division(n : OclAny) : OclAny
  pre: true post: true
  activity:
    while true do (    if n < 2019 then (
      break
    ) else skip ;
    n := n mod 2019) ;
    return n;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def main():
    input=sys.stdin.readline
    L,R=map(int,input().split())
    R=min(R,L+2019)
    ans=2019
    for i in range(L,R):
        for j in range(i+1,R+1):
            ans=min(ans,(i*j)% 2019)
            if ans==0 :
                return 0
    return ans
if __name__=='__main__' :
    print(main())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = '__main__' then (
      execute (main())->display()
    ) else skip;
  operation main() : OclAny
  pre: true post: true
  activity:
    var input : OclAny := (OclFile["System.in"]).readline ;
    var L : OclAny := null;
    var R : OclAny := null;
    Sequence{L,R} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var R : OclAny := Set{R, L + 2019}->min() ;
    var ans : int := 2019 ;
    for i : Integer.subrange(L, R-1) do (    for j : Integer.subrange(i + 1, R + 1-1) do (    ans := Set{ans, (i * j) mod 2019}->min() ;
    if ans = 0 then (
      return 0
    ) else skip)) ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math as mt
def ReuleauxArea(a):
    if a<0 :
        return-1
    return 0.70477*pow(a,2)
a=6
print(ReuleauxArea(a))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    a := 6 ;
    execute (ReuleauxArea(a))->display();
  operation ReuleauxArea(a : OclAny) : OclAny
  pre: true post: true
  activity:
    if a < 0 then (
      return -1
    ) else skip ;
    return 0.70477 * (a)->pow(2);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def inpl(): return list(map(int,input().split()))
from bisect import bisect_left,insort
N=int(input())
src=list(map(int,input().split()))
ans=[]
A,B=[],[]
for i in range(N):
    a,b=src[i],src[-i-1]
    addA=False
    addB=False
    if a!=b :
        j=bisect_left(B,a)
        if j!=len(B)and B[j]==a :
            del B[j]
        else :
            addA=True
        j=bisect_left(A,b)
        if j!=len(A)and A[j]==b :
            del A[j]
        else :
            insort(B,b)
        if addA :
            insort(A,a)
    if len(A)==len(B)==0 :
        ans.append(i+1)
print(*ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var src : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var ans : Sequence := Sequence{} ;
    var A : OclAny := null;
    var B : OclAny := null;
    Sequence{A,B} := Sequence{Sequence{},Sequence{}} ;
    for i : Integer.subrange(0, N-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := Sequence{src[i+1],src->reverse()->at(-(-i - 1))} ;
    var addA : boolean := false ;
    var addB : boolean := false ;
    if a /= b then (
      var j : OclAny := bisect_left(B, a) ;
    if j /= (B)->size() & B[j+1] = a then  (
      execute (B[j+1])->isDeleted()
    )
    else (
      addA := true
      ) ;
    j := bisect_left(A, b) ;
    if j /= (A)->size() & A[j+1] = b then  (
      execute (A[j+1])->isDeleted()
    )
    else (
      insort(B, b)
      ) ;
    if addA then (
      insort(A, a)
    ) else skip
    ) else skip ;
    if (A)->size() = (B)->size() & ((B)->size() == 0) then (
      execute ((i + 1) : ans)
    ) else skip) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display();
  operation inpl() : OclAny
  pre: true post: true
  activity:
    return ((input().split())->collect( _x | (OclType["int"])->apply(_x) ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s=[*input()]
for _ in range(int(input())):
    l=input().split()
    a=int(l[1])
    b=int(l[2])+1
    if l[0]=='print' :
        print(*s[a : b],sep='')
    elif l[0]=='reverse' :
        s[a : b]=reversed(s[a : b])
    elif l[0]=='replace' :
        s[a : b]=l[3]
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : Sequence := (OclFile["System.in"]).readLine() ;
    for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var l : OclAny := input().split() ;
    var a : int := ("" + ((l[1+1])))->toInteger() ;
    var b : int := ("" + ((l[2+1])))->toInteger() + 1 ;
    if l->first() = 'print' then  (
      execute ((argument * (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))) : (test (logical_test (comparison (expr (atom (name b)))))))) ]))))))))->display()
    )
    else (if l->first() = 'reverse' then
   (
      s.subrange(a+1, b) := (s.subrange(a+1, b))->reverse()    
)
    else (if l->first() = 'replace' then
   (
      s.subrange(a+1, b) := l[3+1]    
)
    else skip    )
    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import Counter
n=int(input())
a=input().split()
ans=''
t1,t2=Counter(),Counter()
for i in range(n):
    t1.update(a[i])
    t2.update(a[n-1-i])
    t3=t1 & t2
    t1-=t3
    t2-=t3
    if t1==t2 :
        ans+=str(i+1)+' '
print(ans[:-1])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : OclAny := input().split() ;
    var ans : String := '' ;
    var t1 : OclAny := null;
    var t2 : OclAny := null;
    Sequence{t1,t2} := Sequence{Counter(),Counter()} ;
    for i : Integer.subrange(0, n-1) do (    execute ((a[i+1]) <: t1) ;
    execute ((a[n - 1 - i+1]) <: t2) ;
    var t3 : int := MathLib.bitwiseAnd(t1, t2) ;
    t1 := t1 - t3 ;
    t2 := t2 - t3 ;
    if t1 = t2 then (
      ans := ans + ("" + ((i + 1))) + ' '
    ) else skip) ;
    execute (ans->front())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys,heapq
n=int(sys.stdin.readline())
a=[int(e)for e in sys.stdin.readline().split()]
r=[]
x=[]
y=[]
for i in range(1,n+1):
    heapq.heappush(x,a[i-1])
    heapq.heappush(y,a[n-i])
    while x and y and x[0]==y[0]:
        heapq.heappop(x)
        heapq.heappop(y)
    if not x and not y : r.append(i)
print(' '.join(str(e)for e in r))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := sys.stdin.readLine().split()->select(e | true)->collect(e | (("" + ((e)))->toInteger())) ;
    var r : Sequence := Sequence{} ;
    var x : Sequence := Sequence{} ;
    var y : Sequence := Sequence{} ;
    for i : Integer.subrange(1, n + 1-1) do (    heapq.heappush(x, a[i - 1+1]) ;
    heapq.heappush(y, a[n - i+1]) ;
    while x & y & x->first() = y->first() do (    heapq.heappop(x) ;
    heapq.heappop(y)) ;
    if not(x) & not(y) then (
      execute ((i) : r)
    ) else skip) ;
    execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name e)))))))) ))))))) (comp_for for (exprlist (expr (atom (name e)))) in (logical_test (comparison (expr (atom (name r)))))))), ' '))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys,queue,math,copy,itertools,bisect
from fractions import gcd
sys.setrecursionlimit(10**7)
INF=10**18
MOD=10**9+7
LI=lambda :[int(x)for x in sys.stdin.readline().split()]
_LI=lambda :[int(x)-1 for x in sys.stdin.readline().split()]
NI=lambda : int(sys.stdin.readline())
N=NI()
A=LI()
A_sort=sorted(A)
A_num=[bisect.bisect_left(A_sort,a)for a in A]
ans=[]
A_cnt=[0 for _ in range(N)]
cnt=0
for i in range(N):
    bf1=A_cnt[A_num[i]]
    bf2=A_cnt[A_num[N-i-1]]
    A_cnt[A_num[i]]+=1
    A_cnt[A_num[N-i-1]]-=1
    cnt+=(abs(A_cnt[A_num[i]])-abs(bf1))
    cnt+=(abs(A_cnt[A_num[N-i-1]])-abs(bf2))
    if cnt==0 :
        ans.append(i+1)
print(*ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    sys.setrecursionlimit((10)->pow(7)) ;
    var INF : double := (10)->pow(18) ;
    var MOD : double := (10)->pow(9) + 7 ;
    var LI : Function := lambda $$ : OclAny in (sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) ;
    var _LI : Function := lambda $$ : OclAny in (sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1))) ;
    var NI : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ;
    var N : OclAny := NI->apply() ;
    var A : OclAny := LI->apply() ;
    var A_sort : Sequence := A->sort() ;
    var A_num : Sequence := A->select(a | true)->collect(a | (bisect.bisect_left(A_sort, a))) ;
    var ans : Sequence := Sequence{} ;
    var A_cnt : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (0)) ;
    var cnt : int := 0 ;
    for i : Integer.subrange(0, N-1) do (    var bf1 : OclAny := A_cnt[A_num[i+1]+1] ;
    var bf2 : OclAny := A_cnt[A_num[N - i - 1+1]+1] ;
    A_cnt[A_num[i+1]+1] := A_cnt[A_num[i+1]+1] + 1 ;
    A_cnt[A_num[N - i - 1+1]+1] := A_cnt[A_num[N - i - 1+1]+1] - 1 ;
    cnt := cnt + ((A_cnt[A_num[i+1]+1])->abs() - (bf1)->abs()) ;
    cnt := cnt + ((A_cnt[A_num[N - i - 1+1]+1])->abs() - (bf2)->abs()) ;
    if cnt = 0 then (
      execute ((i + 1) : ans)
    ) else skip) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def MCS(A,n):
    B=sorted(A)
    B0=B[0]
    cost=0
    for i in range(n-1):
        Bi,t_cost,count=B[i],0,0
        si=A.index(Bi)
        while si!=i :
            bsi=B[si]
            sj=A.index(bsi)
            A[si],A[sj]=bsi,Bi
            t_cost+=Bi+bsi
            count+=1
            si=sj
        if count :
            cost+=min(t_cost,(Bi+B0)*2+t_cost-(Bi-B0)*count)
    print(cost)
if __name__=="__main__" :
    n=int(input())
    A=input().split(" ")
    for i in range(n):
        A[i]=int(A[i])
    MCS(A,n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    A := input().split(" ") ;
    for i : Integer.subrange(0, n-1) do (    A[i+1] := ("" + ((A[i+1])))->toInteger()) ;
    MCS(A, n)
    ) else skip;
  operation MCS(A : OclAny, n : OclAny)
  pre: true post: true
  activity:
    var B : Sequence := A->sort() ;
    var B0 : OclAny := B->first() ;
    var cost : int := 0 ;
    for i : Integer.subrange(0, n - 1-1) do (    var Bi : OclAny := null;
    var t_cost : OclAny := null;
    var count : OclAny := null;
    Sequence{Bi,t_cost,count} := Sequence{B[i+1],0,0} ;
    var si : int := A->indexOf(Bi) - 1 ;
    while si /= i do (    var bsi : OclAny := B[si+1] ;
    var sj : int := A->indexOf(bsi) - 1 ;
    var A[si+1] : OclAny := null;
    var A[sj+1] : OclAny := null;
    Sequence{A[si+1],A[sj+1]} := Sequence{bsi,Bi} ;
    t_cost := t_cost + Bi + bsi ;
    count := count + 1 ;
    si := sj) ;
    if count then (
      cost := cost + Set{t_cost, (Bi + B0) * 2 + t_cost - (Bi - B0) * count}->min()
    ) else skip) ;
    execute (cost)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
n=int(input())
A=list(map(int,input().split()))
MAX=max(A)
m=min(A)
B=A.copy()
result=0
def merge(A,left,mid,right):
    global count
    L=A[left : mid]
    L.append(math.inf)
    R=A[mid : right]
    R.append(math.inf)
    i=0
    j=0
    for k in range(left,right):
        if L[i]<=R[j]:
            A[k]=L[i]
            i=i+1
        else :
            A[k]=R[j]
            j=j+1
def mergeSort(A,left,right):
    if left+1toInteger() ;
    var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var MAX : OclAny := (A)->max() ;
    var m : OclAny := (A)->min() ;
    var B : OclAny := A->copy() ;
    var result : int := 0 ;
    skip ;
    skip ;
    mergeSort(B, 0, n) ;
    var T : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (MAX + 1)) ;
    var V : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ;
    for i : Integer.subrange(0, n-1) do (    T[B[i+1]+1] := i) ;
    for i : Integer.subrange(0, n-1) do (    if V[i+1] then (
      continue
    ) else skip ;
    var cur : int := i ;
    var ant : int := 0 ;
    var S : int := 0 ;
    var s : OclAny := MAX ;
    while (1) do (    V[cur+1] := true ;
    var v : OclAny := A[cur+1] ;
    if (v->compareTo(s)) < 0 then (
      s := v
    ) else skip ;
    S := S + v ;
    ant := ant + 1 ;
    cur := T[v+1] ;
    if V[cur+1] then (
      break
    ) else skip) ;
    result := result + Set{S + (ant - 2) * s, S + s + (ant + 1) * m}->min()) ;
    execute (result)->display();
  operation merge(A : OclAny, left : OclAny, mid : OclAny, right : OclAny)
  pre: true post: true
  activity:
    skip ;
    var L : OclAny := A.subrange(left+1, mid) ;
    execute (() : L) ;
    var R : OclAny := A.subrange(mid+1, right) ;
    execute (() : R) ;
    var i : int := 0 ;
    var j : int := 0 ;
    for k : Integer.subrange(left, right-1) do (    if (L[i+1]->compareTo(R[j+1])) <= 0 then  (
      A[k+1] := L[i+1] ;
    i := i + 1
    )
    else (
      A[k+1] := R[j+1] ;
    j := j + 1
      ));
  operation mergeSort(A : OclAny, left : OclAny, right : OclAny)
  pre: true post: true
  activity:
    if (left + 1->compareTo(right)) < 0 then (
      mid := (left + right) div 2 ;
    mergeSort(A, left, mid) ;
    mergeSort(A, mid, right) ;
    merge(A, left, mid, right)
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m=map(int,input().split())
a=1
for i in range(n-1):
    a*=10
    a+=1
b=10**n-a
print(a)
print(b)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : int := 1 ;
    for i : Integer.subrange(0, n - 1-1) do (    a := a * 10 ;
    a := a + 1) ;
    var b : double := (10)->pow(n) - a ;
    execute (a)->display() ;
    execute (b)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input().rstrip())
wi=[int(i)for i in input().rstrip().split()]
visited=[False for i in range(n)]
minw=min(wi)
dict={}
for i,v in enumerate(sorted(wi)):
    dict[v]=i
ans=0
for i in range(n):
    if visited[i]:
        continue
    cnt=0
    now=i
    mi=100000
    s=0
    while True :
        if visited[now]:
            break
        cnt+=1
        visited[now]=True
        mi=min(mi,wi[now])
        s+=wi[now]
        now=dict[wi[now]]
    tmp=s+(cnt-2)*mi
    tmp=min(tmp,s+mi+minw*(cnt+1))
    ans+=tmp
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + ((input().rstrip())))->toInteger() ;
    var wi : Sequence := input().rstrip().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var visited : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (false)) ;
    var minw : OclAny := (wi)->min() ;
    var OclType["Map"] : OclAny := Set{} ;
    for _tuple : Integer.subrange(1, (wi->sort())->size())->collect( _indx | Sequence{_indx-1, (wi->sort())->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var v : OclAny := _tuple->at(_indx);
      (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ]) := i) ;
    var ans : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    if visited[i+1] then (
      continue
    ) else skip ;
    var cnt : int := 0 ;
    var now : OclAny := i ;
    var mi : int := 100000 ;
    var s : int := 0 ;
    while true do (    if visited[now+1] then (
      break
    ) else skip ;
    cnt := cnt + 1 ;
    visited[now+1] := true ;
    mi := Set{mi, wi[now+1]}->min() ;
    s := s + wi[now+1] ;
    now := (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name wi)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name now)))))))) ])))))))) ])) ;
    var tmp : int := s + (cnt - 2) * mi ;
    tmp := Set{tmp, s + mi + minw * (cnt + 1)}->min() ;
    ans := ans + tmp) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import bisect
def sorted_index(A):
    A_=sorted(A)
    B=[]
    for a in A :
        idx=bisect.bisect_left(A_,a)
        B.append(idx)
    return B
def cyclic_factorize(A):
    B=sorted_index(A)
    checked=[False]*len(A)
    cycle_lst=[]
    for i,a in enumerate(A):
        if checked[i]:
            continue
        now=i
        checked[now]=True
        cycle=[a]
        next=B[now]
        while not checked[next]:
            now=next
            next=B[now]
            cycle.append(A[now])
            checked[now]=True
        cycle_lst.append(cycle)
    return cycle_lst
N=int(input())
*W,=map(int,input().split())
cycle_lst=cyclic_factorize(W)
ans=0
global_min=min(W)
for cycle in cycle_lst :
    l=len(cycle)
    s=sum(cycle)
    local_min=min(cycle)
    ans+=s+min((l-2)*local_min,local_min+(l+1)*global_min)
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
(testlist_star_expr (star_expr * (expr (atom (name W)))) ,)    Sequence{(testlist_star_expr (star_expr * (expr (atom (name W)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    cycle_lst := cyclic_factorize(W) ;
    var ans : int := 0 ;
    var global_min : OclAny := (W)->min() ;
    for cycle : cycle_lst do (    var l : int := (cycle)->size() ;
    var s : OclAny := (cycle)->sum() ;
    var local_min : OclAny := (cycle)->min() ;
    ans := ans + s + Set{(l - 2) * local_min, local_min + (l + 1) * global_min}->min()) ;
    execute (ans)->display();
  operation sorted_index(A : OclAny) : OclAny
  pre: true post: true
  activity:
    var A_ : Sequence := A->sort() ;
    var B : Sequence := Sequence{} ;
    for a : A do (    var idx : OclAny := bisect.bisect_left(A_, a) ;
    execute ((idx) : B)) ;
    return B;
  operation cyclic_factorize(A : OclAny) : OclAny
  pre: true post: true
  activity:
    B := sorted_index(A) ;
    var checked : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (A)->size()) ;
    var cycle_lst : Sequence := Sequence{} ;
    for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var a : OclAny := _tuple->at(_indx);
      if checked[i+1] then (
      continue
    ) else skip ;
    var now : OclAny := i ;
    checked[now+1] := true ;
    var cycle : Sequence := Sequence{ a } ;
    var next : OclAny := B[now+1] ;
    while not(checked[next+1]) do (    now := next ;
    next := B[now+1] ;
    execute ((A[now+1]) : cycle) ;
    checked[now+1] := true) ;
    execute ((cycle) : cycle_lst)) ;
    return cycle_lst;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    n=int(input())
    array=[int(x)for x in input().split()]
    sorted_array=sorted(array)
    groups=[]
    for i in range(len(array)):
        moving_src_val=array[i]
        if not moving_src_val :
            continue
        group=[moving_src_val]
        while True :
            moving_tgt_idx=sorted_array.index(moving_src_val)
            moving_tgt_val=array[moving_tgt_idx]
            if moving_tgt_val in group :
                break
            group.append(moving_tgt_val)
            array[moving_tgt_idx]=False
            moving_src_val=moving_tgt_val
        array[i]=False
        groups.append(group)
    min_cost=0
    min_in_array=sorted_array[0]
    for group in groups :
        n_group=len(group)
        if n_group==1 :
            continue
        min_in_group=min(group)
        sum_without_min=sum(group)-min_in_group
        cost1=(n_group-1)*min_in_group
        cost2=(n_group+1)*min_in_array+2*min_in_group
        if cost1toInteger() ;
    var array : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    var sorted_array : Sequence := array->sort() ;
    var groups : Sequence := Sequence{} ;
    for i : Integer.subrange(0, (array)->size()-1) do (    var moving_src_val : OclAny := array[i+1] ;
    if not(moving_src_val) then (
      continue
    ) else skip ;
    var group : Sequence := Sequence{ moving_src_val } ;
    while true do (    var moving_tgt_idx : int := sorted_array->indexOf(moving_src_val) - 1 ;
    var moving_tgt_val : OclAny := array[moving_tgt_idx+1] ;
    if (group)->includes(moving_tgt_val) then (
      break
    ) else skip ;
    execute ((moving_tgt_val) : group) ;
    array[moving_tgt_idx+1] := false ;
    moving_src_val := moving_tgt_val) ;
    array[i+1] := false ;
    execute ((group) : groups)) ;
    var min_cost : int := 0 ;
    var min_in_array : OclAny := sorted_array->first() ;
    for group : groups do (    var n_group : int := (group)->size() ;
    if n_group = 1 then (
      continue
    ) else skip ;
    var min_in_group : OclAny := (group)->min() ;
    var sum_without_min : double := (group)->sum() - min_in_group ;
    var cost1 : double := (n_group - 1) * min_in_group ;
    var cost2 : double := (n_group + 1) * min_in_array + 2 * min_in_group ;
    if (cost1->compareTo(cost2)) < 0 then  (
      min_cost := min_cost + cost1 + sum_without_min
    )
    else (
      min_cost := min_cost + cost2 + sum_without_min
      )) ;
    execute (min_cost)->display() ;
    return;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
cnt=cnt2=0
n=int(input())
s=str(input())
for i in range(len(s)):
    if(s[i]=='0'):
        cnt+=1
    elif(s[i]=='1'):
        cnt2+=1
print(abs(cnt-cnt2))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var cnt : OclAny := 0; var cnt2 : int := 0 ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : String := ("" + (((OclFile["System.in"]).readLine()))) ;
    for i : Integer.subrange(0, (s)->size()-1) do (    if (s[i+1] = '0') then  (
      cnt := cnt + 1
    )
    else (if (s[i+1] = '1') then
   (
      cnt2 := cnt2 + 1    
)
 else skip)) ;
    execute ((cnt - cnt2)->abs())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def pri(s,f,l):
    for i in range(f,l+1):
        print(s[i],end="")
    print()
def rev(s,f,l):
    while fcharacters() ;
    for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var x : OclAny := input().split() ;
    x[1+1] := ("" + ((x[1+1])))->toInteger() ;
    x[2+1] := ("" + ((x[2+1])))->toInteger() ;
    if "print" = x->first() then  (
      pri(s, x[1+1], x[2+1])
    )
    else (if "reverse" = x->first() then
   (
      rev(s, x[1+1], x[2+1])    
)
    else (if "replace" = x->first() then
   (
      rep(s, x[1+1], x[2+1], (x[3+1]))    
)
    else skip    )
    )
);
  operation pri(s : OclAny, f : OclAny, l : OclAny)
  pre: true post: true
  activity:
    for i : Integer.subrange(f, l + 1-1) do (    execute (s[i+1])->display()) ;
    execute (->display();
  operation rev(s : OclAny, f : OclAny, l : OclAny)
  pre: true post: true
  activity:
    while (f->compareTo(l)) < 0 do (    var tmp : OclAny := s[f+1] ;
    s[f+1] := s[l+1] ;
    s[l+1] := tmp ;
    f := f + 1 ;
    l := l - 1);
  operation rep(s : OclAny, f : OclAny, l : OclAny, p : OclAny)
  pre: true post: true
  activity:
    for i : Integer.subrange(0, l - f + 1-1) do (    s[f + i+1] := p[i+1]);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
number=int(input())
case=input()
numberOf0=case.count('0')
numberOf1=case.count('1')
if numberOf0toInteger() ;
    var case : String := (OclFile["System.in"]).readLine() ;
    var numberOf0 : int := case->count('0') ;
    var numberOf1 : int := case->count('1') ;
    if (numberOf0->compareTo(numberOf1)) < 0 then  (
      execute ((case)->size() - 2 * numberOf0)->display()
    )
    else (
      execute ((case)->size() - 2 * numberOf1)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
s=input()
a=s.count('1')
b=s.count('0')
print(abs(a-b))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : String := (OclFile["System.in"]).readLine() ;
    var a : int := s->count('1') ;
    var b : int := s->count('0') ;
    execute ((a - b)->abs())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
s=input()
a=s.count('1')
b=s.count('0')
print(n-(min(a,b)*2))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : String := (OclFile["System.in"]).readLine() ;
    var a : int := s->count('1') ;
    var b : int := s->count('0') ;
    execute (n - (Set{a, b}->min() * 2))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
x=int(input())
y=str(input())
o=0
z=0
for i in range(x):
    if y[i]=='0' :
        o+=1
    elif y[i]=='1' :
        z+=1
if o==z :
    print(0)
else :
    print(abs(o-z))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var y : String := ("" + (((OclFile["System.in"]).readLine()))) ;
    var o : int := 0 ;
    var z : int := 0 ;
    for i : Integer.subrange(0, x-1) do (    if y[i+1] = '0' then  (
      o := o + 1
    )
    else (if y[i+1] = '1' then
   (
      z := z + 1    
)
 else skip)) ;
    if o = z then  (
      execute (0)->display()
    )
    else (
      execute ((o - z)->abs())->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math as mt
def countWays(arr,n):
    max_val=0
    for i in range(n):
        max_val=max(max_val,arr[i])
    freq=[0 for i in range(max_val+1)]
    for i in range(n):
        freq[arr[i]]+=1
    ans=0
    ans+=(freq[0]*(freq[0]-1)*(freq[0]-2)//6)
    for i in range(1,max_val+1):
        ans+=(freq[0]*freq[i]*(freq[i]-1)//2)
    for i in range(1,(max_val+1)//2):
        ans+=(freq[i]*(freq[i]-1)//2*freq[2*i])
    for i in range(1,max_val+1):
        for j in range(i+1,max_val-i+1):
            ans+=freq[i]*freq[j]*freq[i+j]
    return ans
arr=[1,2,3,4,5]
n=len(arr)
print(countWays(arr,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ;
    n := (arr)->size() ;
    execute (countWays(arr, n))->display();
  operation countWays(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var max_val : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    max_val := Set{max_val, arr[i+1]}->max()) ;
    var freq : Sequence := Integer.subrange(0, max_val + 1-1)->select(i | true)->collect(i | (0)) ;
    for i : Integer.subrange(0, n-1) do (    freq[arr[i+1]+1] := freq[arr[i+1]+1] + 1) ;
    var ans : int := 0 ;
    ans := ans + (freq->first() * (freq->first() - 1) * (freq->first() - 2) div 6) ;
    for i : Integer.subrange(1, max_val + 1-1) do (    ans := ans + (freq->first() * freq[i+1] * (freq[i+1] - 1) div 2)) ;
    for i : Integer.subrange(1, (max_val + 1) div 2-1) do (    ans := ans + (freq[i+1] * (freq[i+1] - 1) div 2 * freq[2 * i+1])) ;
    for i : Integer.subrange(1, max_val + 1-1) do (    for j : Integer.subrange(i + 1, max_val - i + 1-1) do (    ans := ans + freq[i+1] * freq[j+1] * freq[i + j+1])) ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def checkPass(mypass : str)->bool :
    if len(mypass)<5 :
        return False
    cntlrg=0
    smlrg=0
    dig=0
    for c in mypass :
        if c.isupper():
            cntlrg+=1
        if c.islower():
            smlrg+=1
        if c.isdigit():
            dig+=1
    if cntlrg<1 or smlrg<1 or dig<1 :
        return False
    return True
x=input()
if checkPass(x):
    print("Correct")
else :
    print("Too weak")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var x : String := (OclFile["System.in"]).readLine() ;
    if checkPass(x) then  (
      execute ("Correct")->display()
    )
    else (
      execute ("Too weak")->display()
      );
  operation checkPass(mypass : String) : boolean
  pre: true post: true
  activity:
    if (mypass)->size() < 5 then (
      return false
    ) else skip ;
    var cntlrg : int := 0 ;
    var smlrg : int := 0 ;
    var dig : int := 0 ;
    for c : mypass->characters() do (    if c->matches("[A-Z ]*") then (
      cntlrg := cntlrg + 1
    ) else skip ;
    if c->matches("[a-z ]*") then (
      smlrg := smlrg + 1
    ) else skip ;
    if c->matches("[0-9]*") then (
      dig := dig + 1
    ) else skip) ;
    if cntlrg < 1 or smlrg < 1 or dig < 1 then (
      return false
    ) else skip ;
    return true;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
x=input().split(' ')
n=int(x[0])
m=int((x[1]))
a=int('1'*n)
b=10**n-a
print(a,b)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var x : OclAny := input().split(' ') ;
    var n : int := ("" + ((x->first())))->toInteger() ;
    var m : int := ("" + (((x[1+1]))))->toInteger() ;
    var a : int := ("" + ((StringLib.nCopies('1', n))))->toInteger() ;
    var b : double := (10)->pow(n) - a ;
    execute (a)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
import re
def main():
    s=sys.stdin.read().strip()
    return('Too weak','Correct')[len(s)>4 and all(re.search(i,s)for i in('[A-Z]','[a-z]','\d'))]
print(main())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    execute (main())->display();
  operation main() : OclAny
  pre: true post: true
  activity:
    var s : OclAny := sys.stdin.readAll()->trim() ;
    return Sequence{'Too weak', 'Correct'}->select((s)->size() > 4 & ((argument (test (logical_test (comparison (expr (atom (name re)) (trailer . (name search) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom '[A-Z]'))))) , (test (logical_test (comparison (expr (atom '[a-z]'))))) , (test (logical_test (comparison (expr (atom '\d')))))) ))))))))->forAll( _x | _x = true ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s=input()
l=[]
bolB="QWERTYUIOPLKJHGFDSAZXCVBNM"
malB="qwertyuioplkjhgfdsazxcvbnm"
cifr='1234567890'
p1=0
p2=0
p3=0
p4=0
for h in s :
    l.append(h)
    if bolB.find(h)>=0 :
        p1+=1
    if malB.find(h)>=0 :
        p2+=1
    if cifr.find(h)>=0 :
        p3+=1
if len(l)>=5 :
    p4+=1
if p1>=1 and p2>=1 and p3>=1 and p4>=1 :
    print("Correct")
else :
    print("Too weak")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : String := (OclFile["System.in"]).readLine() ;
    var l : Sequence := Sequence{} ;
    var bolB : String := "QWERTYUIOPLKJHGFDSAZXCVBNM" ;
    var malB : String := "qwertyuioplkjhgfdsazxcvbnm" ;
    var cifr : String := '1234567890' ;
    var p1 : int := 0 ;
    var p2 : int := 0 ;
    var p3 : int := 0 ;
    var p4 : int := 0 ;
    for h : s->characters() do (    execute ((h) : l) ;
    if bolB->indexOf(h) - 1 >= 0 then (
      p1 := p1 + 1
    ) else skip ;
    if malB->indexOf(h) - 1 >= 0 then (
      p2 := p2 + 1
    ) else skip ;
    if cifr->indexOf(h) - 1 >= 0 then (
      p3 := p3 + 1
    ) else skip) ;
    if (l)->size() >= 5 then (
      p4 := p4 + 1
    ) else skip ;
    if p1 >= 1 & p2 >= 1 & p3 >= 1 & p4 >= 1 then  (
      execute ("Correct")->display()
    )
    else (
      execute ("Too weak")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=input()
L2=['1','2','3','4','5','6','7','8','9','0']
count1,count3,count4=0,0,0
for i in n :
    if i.isupper():
        count1+=1
    elif i.islower():
        count4+=1
    for k in L2 :
        if k==i :
            count3+=1
if len(n)>=5 and(count1 and count3 and count4)>=1 :
    print('Correct')
else :
    print('Too weak')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : String := (OclFile["System.in"]).readLine() ;
    var L2 : Sequence := Sequence{'1'}->union(Sequence{'2'}->union(Sequence{'3'}->union(Sequence{'4'}->union(Sequence{'5'}->union(Sequence{'6'}->union(Sequence{'7'}->union(Sequence{'8'}->union(Sequence{'9'}->union(Sequence{ '0' }))))))))) ;
    var count1 : OclAny := null;
    var count3 : OclAny := null;
    var count4 : OclAny := null;
    Sequence{count1,count3,count4} := Sequence{0,0,0} ;
    for i : n->characters() do (    if i->matches("[A-Z ]*") then  (
      count1 := count1 + 1
    )
    else (if i->matches("[a-z ]*") then
   (
      count4 := count4 + 1    
)
 else skip) ;
    for k : L2 do (    if k = i then (
      count3 := count3 + 1
    ) else skip)) ;
    if (n)->size() >= 5 & (count1 & count3 & count4) >= 1 then  (
      execute ('Correct')->display()
    )
    else (
      execute ('Too weak')->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
string=input()
n=int(input())
for x in range(n):
    command=tuple(map(str,input().split()))
    if command[0]=="print" :
        a=int(command[1])
        b=int(command[2])+1
        print(string[a : b])
    elif command[0]=="reverse" :
        a=int(command[1])
        b=int(command[2])+1
        old=string[a : b]
        new=""
        for y in old :
            new=y+new
        string=string[: a]+new+string[b :]
    else :
        a=int(command[1])
        b=int(command[2])+1
        p=command[3]
        string=string[: a]+p+string[b :]
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var string : String := (OclFile["System.in"]).readLine() ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for x : Integer.subrange(0, n-1) do (    var command : Sequence := ((input().split())->collect( _x | (OclType["String"])->apply(_x) )) ;
    if command->first() = "print" then  (
      var a : int := ("" + ((command[1+1])))->toInteger() ;
    var b : int := ("" + ((command[2+1])))->toInteger() + 1 ;
    execute (string.subrange(a+1, b))->display()
    )
    else (if command->first() = "reverse" then
   (
      a := ("" + ((command[1+1])))->toInteger() ;
    b := ("" + ((command[2+1])))->toInteger() + 1 ;
    var old : OclAny := string.subrange(a+1, b) ;
    var new : String := "" ;
    for y : old do (    new := y + new) ;
    string := string.subrange(1,a) + new + string.subrange(b+1)    
)
    else (
      a := ("" + ((command[1+1])))->toInteger() ;
    b := ("" + ((command[2+1])))->toInteger() + 1 ;
    var p : OclAny := command[3+1] ;
    string := string.subrange(1,a) + p + string.subrange(b+1)
      )    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s=input()
if len(s)>=5 :
    a=0
    b=0
    c=0
    for i in s :
        if i.isdigit():
            c+=1
        elif i.isupper():
            a+=1
        elif i.islower():
            b+=1
    if a>=1 and b>=1 and c>=1 :
        print('Correct')
    else :
        print('Too weak')
else :
    print('Too weak')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : String := (OclFile["System.in"]).readLine() ;
    if (s)->size() >= 5 then  (
      var a : int := 0 ;
    var b : int := 0 ;
    var c : int := 0 ;
    for i : s->characters() do (    if i->matches("[0-9]*") then  (
      c := c + 1
    )
    else (if i->matches("[A-Z ]*") then
   (
      a := a + 1    
)
    else (if i->matches("[a-z ]*") then
   (
      b := b + 1    
)
    else skip    )
    )
) ;
    if a >= 1 & b >= 1 & c >= 1 then  (
      execute ('Correct')->display()
    )
    else (
      execute ('Too weak')->display()
      )
    )
    else (
      execute ('Too weak')->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for test in range(t):
    n,m=map(int,input().split())
    area=n*m
    if area % 2==0 :
        num=int(area/2)
    else :
        num=int((area-1)/2)+1
    print(num)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for test : Integer.subrange(0, t-1) do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var area : double := n * m ;
    if area mod 2 = 0 then  (
      var num : int := ("" + ((area / 2)))->toInteger()
    )
    else (
      num := ("" + (((area - 1) / 2)))->toInteger() + 1
      ) ;
    execute (num)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for x in range(t):
    a,b=map(int,input().split())
    print(a*b//2+a*b % 2)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for x : Integer.subrange(0, t-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (a * b div 2 + a * b mod 2)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for _ in range(t):
    n,m=map(int,input().split())
    area=n*m
    count=0
    if area % 2==0 :
        count=area//2
    elif area % 2!=0 :
        count=area//2+1
    print(count)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, t-1) do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var area : double := n * m ;
    var count : int := 0 ;
    if area mod 2 = 0 then  (
      count := area div 2
    )
    else (if area mod 2 /= 0 then
   (
      count := area div 2 + 1    
)
 else skip) ;
    execute (count)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
t=int(input())
for i in range(t):
    a,b=input().split()
    a=int(a); b=int(b)
    print(math.ceil((a*b)/2))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, t-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := input().split() ;
    var a : int := ("" + ((a)))->toInteger();    var b : int := ("" + ((b)))->toInteger() ;
    execute (((a * b) / 2)->ceil())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
t=int(input())
for i in range(t):
    a,b=input().split()
    a=int(a)
    b=int(b)
    print(math.ceil((a*b)/2))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, t-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := input().split() ;
    var a : int := ("" + ((a)))->toInteger() ;
    var b : int := ("" + ((b)))->toInteger() ;
    execute (((a * b) / 2)->ceil())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
class Solution(object):
    def readBinaryWatch(self,num):
        return['%d:%02d' %(h,m)for h in range(12)for m in range(60)if(bin(h)+bin(m)).count('1')==num]
------------------------------------------------------------
OCL File:
---------
class Solution extends object {
  static operation newSolution() : Solution
  pre: true
  post: Solution->exists( _x | result = _x );
  operation readBinaryWatch(num : OclAny) : OclAny
  pre: true post: true
  activity:
    return Integer.subrange(0, 12-1)->select(h; m : Integer.subrange(0, 60-1) | true)->collect(h; m : Integer.subrange(0, 60-1) | (StringLib.format('%d:%02d',Sequence{h, m})));
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
str=input().split(' ')
n=int(str[0])
m=int(str[1])
a='7'
b='2'
for i in range(2000):
    a+='7'
for i in range(2000):
    b+='2'
a+='1'
b+='9'
print(a)
print(b)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var OclType["String"] : OclAny := input().split(' ') ;
    var n : int := ("" + ((("" + (->first())))))->toInteger() ;
    var m : int := ("" + ((("" + ([1+1])))))->toInteger() ;
    var a : String := '7' ;
    var b : String := '2' ;
    for i : Integer.subrange(0, 2000-1) do (    a := a + '7') ;
    for i : Integer.subrange(0, 2000-1) do (    b := b + '2') ;
    a := a + '1' ;
    b := b + '9' ;
    execute (a)->display() ;
    execute (b)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def lexNext(s,n):
    for i in range(n-1,-1,-1):
        if s[i]!='z' :
            k=ord(s[i])
            s[i]=chr(k+1)
            return ''.join(s)
        s[i]='a'
if __name__=="__main__" :
    S="abcdeg"
    T="abcfgh"
    n=len(S)
    S=list(S)
    res=lexNext(S,n)
    if res!=T :
        print(res)
    else :
        print(-1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      var S : String := "abcdeg" ;
    var T : String := "abcfgh" ;
    n := (S)->size() ;
    S := (S)->characters() ;
    var res : OclAny := lexNext(S, n) ;
    if res /= T then  (
      execute (res)->display()
    )
    else (
      execute (-1)->display()
      )
    ) else skip;
  operation lexNext(s : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    for i : Integer.subrange(-1 + 1, n - 1)->reverse() do (    if s[i+1] /= 'z' then (
      var k : int := (s[i+1])->char2byte() ;
    s[i+1] := (k + 1)->byte2char() ;
    return StringLib.sumStringsWithSeparator((s), '')
    ) else skip ;
    s[i+1] := 'a');
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
l,r,a=map(int,input().split());
if((l==0 and a==0)or(r==0 and a==0)):
    print(0)
else :
    if(l==r):
        print((l+r+a)-((l+r+a)% 2))
    else :
        x=min(l,r)
        y=max(l,r)
        z=y-x
        if(z<=a):
            x=x+z
            a=a-z
        else :
            x=x+a
            a=0
        y=x
        print((x+y+a)-((x+y+a)% 2))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var l : OclAny := null;
    var r : OclAny := null;
    var a : OclAny := null;
    Sequence{l,r,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); ;
    if ((l = 0 & a = 0) or (r = 0 & a = 0)) then  (
      execute (0)->display()
    )
    else (
      if (l = r) then  (
      execute ((l + r + a) - ((l + r + a) mod 2))->display()
    )
    else (
      var x : OclAny := Set{l, r}->min() ;
    var y : OclAny := Set{l, r}->max() ;
    var z : double := y - x ;
    if ((z->compareTo(a)) <= 0) then  (
      x := x + z ;
    var a : double := a - z
    )
    else (
      x := x + a ;
    a := 0
      ) ;
    y := x ;
    execute ((x + y + a) - ((x + y + a) mod 2))->display()
      )
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def itp_replace(stri,a,b,c):
    a=int(a)
    b=int(b)
    return stri[: a]+c+stri[b+1 :]
def itp_reverse(stri,a,b):
    a=int(a)
    b=int(b)
    return stri[: a]+stri[a : b+1][: :-1]+stri[b+1 :]
def itp_print(stri,a,b):
    a=int(a)
    b=int(b)
    print(stri[a : b+1])
test_str=input()
test_num=int(input())
order=[]
for a in range(test_num):
    temp=input().split()
    order.append(temp)
for a in order :
    if a[0]=='replace' :
        test_str=itp_replace(test_str,a[1],a[2],a[3])
    if a[0]=='reverse' :
        test_str=itp_reverse(test_str,a[1],a[2])
    if a[0]=='print' :
        itp_print(test_str,a[1],a[2])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    var test_str : String := (OclFile["System.in"]).readLine() ;
    var test_num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var order : Sequence := Sequence{} ;
    for a : Integer.subrange(0, test_num-1) do (    var temp : OclAny := input().split() ;
    execute ((temp) : order)) ;
    for a : order do (    if a->first() = 'replace' then (
      test_str := itp_replace(test_str, a[1+1], a[2+1], a[3+1])
    ) else skip ;
    if a->first() = 'reverse' then (
      test_str := itp_reverse(test_str, a[1+1], a[2+1])
    ) else skip ;
    if a->first() = 'print' then (
      itp_print(test_str, a[1+1], a[2+1])
    ) else skip);
  operation itp_replace(stri : OclAny, a : OclAny, b : OclAny, c : OclAny) : OclAny
  pre: true post: true
  activity:
    a := ("" + ((a)))->toInteger() ;
    b := ("" + ((b)))->toInteger() ;
    return stri.subrange(1,a) + c + stri.subrange(b + 1+1);
  operation itp_reverse(stri : OclAny, a : OclAny, b : OclAny) : OclAny
  pre: true post: true
  activity:
    a := ("" + ((a)))->toInteger() ;
    b := ("" + ((b)))->toInteger() ;
    return stri.subrange(1,a) + stri.subrange(a+1, b + 1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) + stri.subrange(b + 1+1);
  operation itp_print(stri : OclAny, a : OclAny, b : OclAny)
  pre: true post: true
  activity:
    a := ("" + ((a)))->toInteger() ;
    b := ("" + ((b)))->toInteger() ;
    execute (stri.subrange(a+1, b + 1))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
numbers=list(map(int,input().split()))
left=numbers[0]
right=numbers[1]
both=numbers[2]
stop=0
if left>right :
    if both>(left-right):
        both-=(left-right)
        right=left
    else :
        right+=both
        both=0
elif right>left :
    if both>(right-left):
        both-=(right-left)
        left=right
    else :
        left+=both
        both=0
if right==left :
    if both>1 :
        increase=math.floor(both/2)
        right+=increase
        left+=increase
        print(left*2)
        stop=1
if stop==0 :
    if left>right :
        print(right*2)
    else :
        print(left*2)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var numbers : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var left : OclAny := numbers->first() ;
    var right : OclAny := numbers[1+1] ;
    var both : OclAny := numbers[2+1] ;
    var stop : int := 0 ;
    if (left->compareTo(right)) > 0 then  (
      if (both->compareTo((left - right))) > 0 then  (
      both := both - (left - right) ;
    right := left
    )
    else (
      right := right + both ;
    both := 0
      )
    )
    else (if (right->compareTo(left)) > 0 then
   (
      if (both->compareTo((right - left))) > 0 then  (
      both := both - (right - left) ;
    left := right
    )
    else (
      left := left + both ;
    both := 0
      )    
)
 else skip) ;
    if right = left then (
      if both > 1 then (
      var increase : double := (both / 2)->floor() ;
    right := right + increase ;
    left := left + increase ;
    execute (left * 2)->display() ;
    stop := 1
    ) else skip
    ) else skip ;
    if stop = 0 then (
      if (left->compareTo(right)) > 0 then  (
      execute (right * 2)->display()
    )
    else (
      execute (left * 2)->display()
      )
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
l,r,a=map(int,input().split())
print(2*min(l+a,r+a,(l+a+r)//2))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var l : OclAny := null;
    var r : OclAny := null;
    var a : OclAny := null;
    Sequence{l,r,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (2 * Set{l + a, r + a, (l + a + r) div 2}->min())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
l,r,a=list(map(int,input().split()))
while(a>0):
    if(l<=r):
        l+=1
    elif(l>=r):
        r+=1
    a-=1 ;
print(min(l,r)*2)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var l : OclAny := null;
    var r : OclAny := null;
    var a : OclAny := null;
    Sequence{l,r,a} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    while (a > 0) do (    if ((l->compareTo(r)) <= 0) then  (
      l := l + 1
    )
    else (if ((l->compareTo(r)) >= 0) then
   (
      r := r + 1    
)
 else skip) ;
    a := a - 1;) ;
    execute (Set{l, r}->min() * 2)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
l,r,a=map(int,input().split())
if l==r : print(l+r+(a//2)*2)
else :
    a1=max(l,r); a2=min(l,r)
    if a>=a1-a2 : print(2*a1+((a-a1+a2)//2)*2)
    else : print(2*(a2+a))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var l : OclAny := null;
    var r : OclAny := null;
    var a : OclAny := null;
    Sequence{l,r,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if l = r then  (
      execute (l + r + (a div 2) * 2)->display()
    )
    else (
      var a1 : OclAny := Set{l, r}->max();    var a2 : OclAny := Set{l, r}->min() ;
    if (a->compareTo(a1 - a2)) >= 0 then  (
      execute (2 * a1 + ((a - a1 + a2) div 2) * 2)->display()
    )
    else (
      execute (2 * (a2 + a))->display()
      )
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def getMaxLength(arr,n):
    count=0
    result=0
    for i in range(0,n):
        if(arr[i]==0):
            count=0
        else :
            count+=1
            result=max(result,count)
    return result
arr=[1,1,0,0,1,0,1,0,1,1,1,1]
n=len(arr)
print(getMaxLength(arr,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    arr := Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))))))))))) ;
    n := (arr)->size() ;
    execute (getMaxLength(arr, n))->display();
  operation getMaxLength(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var count : int := 0 ;
    var result : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    if (arr[i+1] = 0) then  (
      count := 0
    )
    else (
      count := count + 1 ;
    result := Set{result, count}->max()
      )) ;
    return result;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def countSetBits(n):
    i=0
    ans=0
    while((1<display()
    ) else skip;
  operation countSetBits(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var i : int := 0 ;
    var ans : int := 0 ;
    while (((1 * (2->pow(i)))->compareTo(n)) <= 0) do (    var k : int := 0 ;
    var change : int := 1 * (2->pow(i)) ;
    for j : Integer.subrange(0, n + 1-1) do (    ans := ans + k ;
    if change = 1 then  (
      k := not(k) ;
    change := 1 * (2->pow(i))
    )
    else (
      change := change - 1
      )) ;
    i := i + 1) ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import deque
N,M=map(int,input().split())
*A,=map(int,input().split())
S=[[]for i in range(N)]
for i in range(M):
    l,r=map(int,input().split())
    S[l-1].append(r)
N0=2**(N).bit_length()
INF=2**31-1
data=[INF]*(2*N0)
def update(k,x):
    k+=N0-1
    data[k]=x
    while k>=0 :
        k=(k-1)//2
        data[k]=max(data[2*k+1],data[2*k+2])
def query(l,r):
    L=l+N0 ; R=r+N0
    s=-INF
    while L>=1 ; R>>=1
    return s
update(0,0)
que=deque()
for i in range(N):
    while que and que[0][1]<=i :
        que.popleft()
    r=(que[0][0]if que else i)+1
    v=query(0,r)+A[i]
    update(i+1,v)
    for r in S[i]:
        que.append((i,r))
print(query(0,N+1))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
(testlist_star_expr (star_expr * (expr (atom (name A)))) ,)    Sequence{(testlist_star_expr (star_expr * (expr (atom (name A)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var S : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{})) ;
    for i : Integer.subrange(0, M-1) do (    var l : OclAny := null;
    var r : OclAny := null;
    Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
(expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name l))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name r)))))))) ))))) ;
    var N0 : double := (2)->pow((N).bit_length()) ;
    var INF : double := (2)->pow(31) - 1 ;
    var data : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, (2 * N0)) ;
    skip ;
    skip ;
    update(0, 0) ;
    var que : Sequence := () ;
    for i : Integer.subrange(0, N-1) do (    while que & (que->first()[1+1]->compareTo(i)) <= 0 do (    que := que->tail()) ;
    r := (if que then que->first()->first() else i endif) + 1 ;
    var v : OclAny := query(0, r) + A[i+1] ;
    update(i + 1, v) ;
    for r : S[i+1] do (    execute ((Sequence{i, r}) : que))) ;
    execute (query(0, N + 1))->display();
  operation update(k : OclAny, x : OclAny)
  pre: true post: true
  activity:
    k := k + N0 - 1 ;
    data[k+1] := x ;
    while k >= 0 do (    k := (k - 1) div 2 ;
    data[k+1] := Set{data[2 * k + 1+1], data[2 * k + 2+1]}->max());
  operation query(l : OclAny, r : OclAny) : OclAny
  pre: true post: true
  activity:
    var L : OclAny := l + N0;    var R : OclAny := r + N0 ;
    var s : OclAny := -INF ;
    while (L->compareTo(R)) < 0 do (    if MathLib.bitwiseAnd(R, 1) then (
      R := R - 1 ;
    s := Set{s, data[R - 1+1]}->max()
    ) else skip ;
    if MathLib.bitwiseAnd(L, 1) then (
      s := Set{s, data[L - 1+1]}->max() ;
    L := L + 1
    ) else skip ;
    L := L div (2->pow(1));    R := R div (2->pow(1))) ;
    return s;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N,M=map(int,input().split())
L=[0]*M
R=[0]*M
A=list(map(int,input().split()))
for i in range(M):
    L[i],R[i]=map(int,input().split())
pre=[0]*(N+1)
dp=[0]*(N+1)
for i in range(1,N+1):
    pre[i]=i-1
for i in range(M):
    pre[R[i]]=min(pre[R[i]],L[i]-1)
for i in range(N-1,0,-1):
    pre[i]=min(pre[i],pre[i+1])
for i in range(1,N+1):
    dp[i]=max(dp[i-1],dp[pre[i]]+A[i-1])
print(dp[N])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var L : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, M) ;
    var R : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, M) ;
    var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    for i : Integer.subrange(0, M-1) do (    var L[i+1] : OclAny := null;
    var R[i+1] : OclAny := null;
    Sequence{L[i+1],R[i+1]} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var pre : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ;
    var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ;
    for i : Integer.subrange(1, N + 1-1) do (    pre[i+1] := i - 1) ;
    for i : Integer.subrange(0, M-1) do (    pre[R[i+1]+1] := Set{pre[R[i+1]+1], L[i+1] - 1}->min()) ;
    for i : Integer.subrange(0 + 1, N - 1)->reverse() do (    pre[i+1] := Set{pre[i+1], pre[i + 1+1]}->min()) ;
    for i : Integer.subrange(1, N + 1-1) do (    dp[i+1] := Set{dp[i - 1+1], dp[pre[i+1]+1] + A[i - 1+1]}->max()) ;
    execute (dp[N+1])->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m=map(int,input().split())
k=n//4
b=int('4'*k+'5')
a=int('5'*k+'5')
print(a,b)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var k : int := n div 4 ;
    var b : int := ("" + ((StringLib.nCopies('4', k) + '5')))->toInteger() ;
    var a : int := ("" + ((StringLib.nCopies('5', k) + '5')))->toInteger() ;
    execute (a)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
def areaCircle(b):
    area=math.pi*b*b
    return area
a=10
b=8
print(areaCircle(b))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var a : int := 10 ;
    b := 8 ;
    execute (areaCircle(b))->display();
  operation areaCircle(b : OclAny) : OclAny
  pre: true post: true
  activity:
    var area : double :=  * b * b ;
    return area;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for _ in range(t):
    n,k=[int(i)for i in input().split()]
    if n % 2==k % 2 and n>=k*k :
        print("YES")
    else :
        print("NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, t-1) do (    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    if n mod 2 = k mod 2 & (n->compareTo(k * k)) >= 0 then  (
      execute ("YES")->display()
    )
    else (
      execute ("NO")->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
s,a,n=map(int,input().split())
z=1
x=s
y=0
while n>=math.gcd(x,n):
    if z==1 :
        x=s
        y=0
    else :
        x=a
        y=1
    n-=math.gcd(x,n)
    z=z*-1
print(y)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var s : OclAny := null;
    var a : OclAny := null;
    var n : OclAny := null;
    Sequence{s,a,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var z : int := 1 ;
    var x : OclAny := s ;
    var y : int := 0 ;
    while (n->compareTo((x)->gcd(n))) >= 0 do (    if z = 1 then  (
      x := s ;
    y := 0
    )
    else (
      x := a ;
    y := 1
      ) ;
    n := n - (x)->gcd(n) ;
    z := z * -1) ;
    execute (y)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
a,b,n=map(int,input().split())
winner=1
while n>0 :
    n-=math.gcd(a,n)
    winner=0
    if n>0 :
        n-=math.gcd(b,n)
        winner=1
print(winner)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var a : OclAny := null;
    var b : OclAny := null;
    var n : OclAny := null;
    Sequence{a,b,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var winner : int := 1 ;
    while n > 0 do (    n := n - (a)->gcd(n) ;
    winner := 0 ;
    if n > 0 then (
      n := n - (b)->gcd(n) ;
    winner := 1
    ) else skip) ;
    execute (winner)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def gcd(a,b):
    if(b==0):
        return a
    else :
        return gcd(b,a % b)
def main():
    a,b,n=map(int,input().split())
    while n>=0 :
        n-=gcd(a,n)
        if n<0 :
            print("1")
            quit()
        n-=gcd(b,n)
        if n<0 :
            print("0")
            quit()
if __name__=="__main__" :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      main()
    ) else skip;
  operation gcd(a : OclAny, b : OclAny) : OclAny
  pre: true post: true
  activity:
    if (b = 0) then  (
      return a
    )
    else (
      return gcd(b, a mod b)
      );
  operation main()
  pre: true post: true
  activity:
    var n : OclAny := null;
    Sequence{a,b,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    while n >= 0 do (    n := n - gcd(a, n) ;
    if n < 0 then (
      execute ("1")->display() ;
    quit()
    ) else skip ;
    n := n - gcd(b, n) ;
    if n < 0 then (
      execute ("0")->display() ;
    quit()
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b,n=map(int,input().split())
def hcf(num1,num2):
    f=1
    big=max(num1,num2)
    small=min(num1,num2)
    for x in range(small,1,-1):
        if big % x==0 and small % x==0 :
            f=x
            break
    return f
while True :
    if n-hcf(n,a)>=0 :
        n-=hcf(n,a)
    else :
        result=1
        break
    if n-hcf(n,b)>=0 :
        n-=hcf(n,b)
    else :
        result=0
        break
print(result)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    var n : OclAny := null;
    Sequence{a,b,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    skip ;
    while true do (    if n - hcf(n, a) >= 0 then  (
      n := n - hcf(n, a)
    )
    else (
      var result : int := 1 ;
    break
      ) ;
    if n - hcf(n, b) >= 0 then  (
      n := n - hcf(n, b)
    )
    else (
      result := 0 ;
    break
      )) ;
    execute (result)->display();
  operation hcf(num1 : OclAny, num2 : OclAny) : OclAny
  pre: true post: true
  activity:
    var f : int := 1 ;
    var big : OclAny := Set{num1, num2}->max() ;
    var small : OclAny := Set{num1, num2}->min() ;
    for x : Integer.subrange(1 + 1, small)->reverse() do (    if big mod x = 0 & small mod x = 0 then (
      f := x ;
    break
    ) else skip) ;
    return f;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
result=[int(item)for item in input().split(" ")]
i=2
while True :
    if i % 2==0 :
        y=math.gcd(result[0],result[2])
        if y>result[2]:
            print(1)
            break
        else :
            result[2]=result[2]-y
            i+=1
    else :
        y=math.gcd(result[1],result[2])
        if y>result[2]:
            print(0)
            break
        else :
            result[2]=result[2]-y
            i+=1
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var result : Sequence := input().split(" ")->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ;
    var i : int := 2 ;
    while true do (    if i mod 2 = 0 then  (
      var y : long := (result->first())->gcd(result[2+1]) ;
    if (y->compareTo(result[2+1])) > 0 then  (
      execute (1)->display() ;
    break
    )
    else (
      result[2+1] := result[2+1] - y ;
    i := i + 1
      )
    )
    else (
      y := (result[1+1])->gcd(result[2+1]) ;
    if (y->compareTo(result[2+1])) > 0 then  (
      execute (0)->display() ;
    break
    )
    else (
      result[2+1] := result[2+1] - y ;
    i := i + 1
      )
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import itertools
def count_zeros(n):
    result=0
    for x in itertools.count(1):
        divisor=5**x
        if divisor>n :
            break
        else :
            result+=(n//divisor)
    return result
if __name__=="__main__" :
    while True :
        n=int(input())
        if n==0 :
            break
        else :
            print(count_zeros(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      while true do (    n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then  (
      break
    )
    else (
      execute (count_zeros(n))->display()
      ))
    ) else skip;
  operation count_zeros(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var result : int := 0 ;
    for x : itertools->count(1) do (    var divisor : double := (5)->pow(x) ;
    if (divisor->compareTo(n)) > 0 then  (
      break
    )
    else (
      result := result + (n div divisor)
      )) ;
    return result;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for e in iter(input,'0'):
    e=int(e)
    print(sum(e//5**i for i in range(1,7)))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for e : OclIterator.newOclIterator_Sequence(input, '0') do (    var e : int := ("" + ((e)))->toInteger() ;
    execute (((argument (test (logical_test (comparison (expr (expr (atom (name e))) // (expr (expr (atom (number (integer 5)))) ** (expr (atom (name i)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 7))))))))) )))))))))->sum())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
class math :
    pi=3.14159265358979323846264338
    def gcd(self,a,b):
        if b==0 :
            return a
        return self.gcd(b,a % b)
    def lcm(self,a,b):
        return(a*b)//self.gcd(a,b)
    def Pnum(self,a):
        if a==1 : return False
        for i in range(2,int(a**0.5)+1):
            if a % i==0 :
                return False
        return True
    def caria(self,r):
        return r*r*self.pi
math=math()
def get_input():
    N=[]
    while True :
        try :
            N.append(input())
        except EOFError :
            break
    return N
while True :
    N=int(input())
    if N==0 :
        break
    t=0
    for i in range(1,7):
        t+=N//(5**i)
    print(t)
------------------------------------------------------------
OCL File:
---------
class math {
  static operation newmath() : math
  pre: true
  post: math->exists( _x | result = _x );
  static attribute pi : double := 3.14159265358979323846264338;
  operation gcd(a : OclAny,b : OclAny) : OclAny
  pre: true post: true
  activity:
    if b = 0 then (
      return a
    ) else skip ;
    return self.gcd(b, a mod b);
  operation lcm(a : OclAny,b : OclAny) : OclAny
  pre: true post: true
  activity:
    return (a * b) div self.gcd(a, b);
  operation Pnum(a : OclAny) : OclAny
  pre: true post: true
  activity:
    if a = 1 then (
      return false
    ) else skip ;
    for i : Integer.subrange(2, ("" + (((a)->pow(0.5))))->toInteger() + 1-1) do (    if a mod i = 0 then (
      return false
    ) else skip) ;
    return true;
  operation caria(r : OclAny) : OclAny
  pre: true post: true
  activity:
    return r * r * self.pi;
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var math : OclAny :=  ;
    skip ;
    while true do (    N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if N = 0 then (
      break
    ) else skip ;
    var t : int := 0 ;
    for i : Integer.subrange(1, 7-1) do (    t := t + N div ((5)->pow(i))) ;
    execute (t)->display());
  operation get_input() : OclAny
  pre: true post: true
  activity:
    var N : Sequence := Sequence{} ;
    while true do (    try (    execute (((OclFile["System.in"]).readLine()) : N))
(except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))) ;
    return N;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
def main():
    while True :
        _factorial=int(input())
        if _factorial==0 :
            break
        _factorial=math.factorial(_factorial)
        count=0
        for value in(str(_factorial))[: :-1]:
            if value=='0' :
                count+=1
            else :
                break
        print(count)
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    while true do (    var _factorial : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if _factorial = 0 then (
      break
    ) else skip ;
    _factorial := MathLib.factorial(_factorial) ;
    var count : int := 0 ;
    for value : (("" + ((_factorial))))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do (    if value = '0' then  (
      count := count + 1
    )
    else (
      break
      )) ;
    execute (count)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m=map(int,input().split())
f=n//4+1
s='4'*f
a=int(s)
s=10**(f)
b=s-a
print(a)
print(b)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var f : int := n div 4 + 1 ;
    var s : String := StringLib.nCopies('4', f) ;
    var a : int := ("" + ((s)))->toInteger() ;
    s := (10)->pow((f)) ;
    var b : double := s - a ;
    execute (a)->display() ;
    execute (b)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
str1=input()
count=int(input())
for i in range(count):
    args=input().split()
(a,b)=[int(x)for x in args[1 : 3]]
    if args[0]=='print' :
        print(str1[a : b+1])
    elif args[0]=='reverse' :
        str1=str1[0 : a]+str1[a : b+1][: :-1]+str1[b+1 :]
    elif args[0]=='replace' :
        str1=str1[0 : a]+args[3]+str1[b+1 :]
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var str1 : String := (OclFile["System.in"]).readLine() ;
    var count : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, count-1) do (    var args : OclAny := input().split()) ;
    var Sequence{a, b} : Sequence := args.subrange(1+1, 3)->select(x | true)->collect(x | (("" + ((x)))->toInteger()));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
while 1 :
    try :
        count=0
        N=int(input())
        if N==0 : break
        n=str(math.factorial(N))
        for i in n[: :-1]:
            if i=="0" : count+=1
            else :
                print(count)
                break
    except : break
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    while 1 do (    try (    var count : int := 0 ;
    var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if N = 0 then (
      break
    ) else skip ;
    var n : String := ("" + ((MathLib.factorial(N)))) ;
    for i : n(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do (    if i = "0" then  (
      count := count + 1
    )
    else (
      execute (count)->display() ;
    break
      )))
     catch (_e : OclException) do (    break)
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
k,d=map(int,input().split())
if k==1 and d==0 :
    print(0)
elif d>0 :
    print(str(d)+'0'*(k-1))
else :
    print('No solution')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var k : OclAny := null;
    var d : OclAny := null;
    Sequence{k,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if k = 1 & d = 0 then  (
      execute (0)->display()
    )
    else (if d > 0 then
   (
      execute (("" + ((d))) + StringLib.nCopies('0', (k - 1)))->display()    
)
    else (
      execute ('No solution')->display()
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
k,d=map(str,input().split())
if d=='0' and int(k)>1 :
    print("No solution")
    exit()
for i in range(int(k)-1):
    d+='0'
print(int(d))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var k : OclAny := null;
    var d : OclAny := null;
    Sequence{k,d} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ;
    if d = '0' & ("" + ((k)))->toInteger() > 1 then (
      execute ("No solution")->display() ;
    exit()
    ) else skip ;
    for i : Integer.subrange(0, ("" + ((k)))->toInteger() - 1-1) do (    d := d + '0') ;
    execute (("" + ((d)))->toInteger())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
k,d=map(int,input().split())
if d==0 and k!=1 :
    print('No solution')
else :
    n=['0']*k
    n[0]=str(d)
    print(''.join(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var k : OclAny := null;
    var d : OclAny := null;
    Sequence{k,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if d = 0 & k /= 1 then  (
      execute ('No solution')->display()
    )
    else (
      var n : Sequence := MatrixLib.elementwiseMult(Sequence{ '0' }, k) ;
    n->first() := ("" + ((d))) ;
    execute (StringLib.sumStringsWithSeparator((n), ''))->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
k,d=map(int,input().split())
if(d==0):
    if k==1 : print(0)
    else : print("No solution")
else :
    print(d*(10**(k-1)))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var k : OclAny := null;
    var d : OclAny := null;
    Sequence{k,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if (d = 0) then  (
      if k = 1 then  (
      execute (0)->display()
    )
    else (
      execute ("No solution")->display()
      )
    )
    else (
      execute (d * ((10)->pow((k - 1))))->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,k=map(int,input().split())
while len(str(k))n :
    print("No solution")
else :
    print(k)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    while ((("" + ((k))))->size()->compareTo(n)) < 0 do (    if k = 0 & n /= 1 then (
      break
    ) else skip ;
    var a : String := ("" + ((k))) ;
    if a->first() = "1" then  (
      k := k * 10
    )
    else (
      var k : String := ("" + ((k))) ;
    k := ("" + ((("" + ((k->first())))->toInteger() - 1))) + ("" + (("1"))) + k->tail() ;
    k := ("" + ((k)))->toInteger()
      )) ;
    if k = 0 & n /= 1 then  (
      execute ("No solution")->display()
    )
    else (if ((("" + ((k))))->size()->compareTo(n)) > 0 then
   (
      execute ("No solution")->display()    
)
    else (
      execute (k)->display()
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
ans=0
for a in[25,10,5,1]:
    ans+=n//a
    n %=a
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var ans : int := 0 ;
    for a : Sequence{25}->union(Sequence{10}->union(Sequence{5}->union(Sequence{ 1 }))) do (    ans := ans + n div a ;
    n := n mod a) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def solve(n):
    ans=0
    for c in(25,10,5,1):
        q,r=divmod(n,c)
        ans+=q
        n=r
    return ans
def main(args):
    n=int(input())
    ans=solve(n)
    print(ans)
if __name__=='__main__' :
    main(sys.argv[1 :])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))
    ) else skip;
  operation solve(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var ans : int := 0 ;
    for c : Sequence{25, 10, 5, 1} do (    var q : OclAny := null;
    var r : OclAny := null;
    Sequence{q,r} := Sequence{(n div c), (n mod c)} ;
    ans := ans + q ;
    n := r) ;
    return ans;
  operation main(args : OclAny)
  pre: true post: true
  activity:
    n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    ans := solve(n) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys,collections
input=lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF=10**10
def I(): return int(input())
def F(): return float(input())
def SS(): 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 LSS(): return input().split()
def resolve():
    n=I()
    ans=0
    for i in(25,10,5,1):
        ans+=n//i
        n %=i
    print(ans)
if __name__=='__main__' :
    resolve()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ;
    sys.setrecursionlimit((10)->pow(7)) ;
    var INF : double := (10)->pow(10) ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      resolve()
    ) else skip;
  operation I() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation F() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toReal();
  operation SS() : OclAny
  pre: true post: true
  activity:
    return (OclFile["System.in"]).readLine();
  operation LI() : OclAny
  pre: true post: true
  activity:
    return input->apply().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()));
  operation LI_() : OclAny
  pre: true post: true
  activity:
    return input->apply().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1));
  operation LF() : OclAny
  pre: true post: true
  activity:
    return input->apply().split()->select(x | true)->collect(x | (("" + ((x)))->toReal()));
  operation LSS() : OclAny
  pre: true post: true
  activity:
    return input->apply().split();
  operation resolve()
  pre: true post: true
  activity:
    var n : OclAny := I() ;
    var ans : int := 0 ;
    for i : Sequence{25, 10, 5, 1} do (    ans := ans + n div i ;
    n := n mod i) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
if __name__=="__main__" :
    input_value=int(input())
    twenty_five_n=input_value//25
    input_value=input_value-25*twenty_five_n
    ten_n=input_value//10
    input_value=input_value-10*ten_n
    five_n=input_value//5
    input_value=input_value-5*five_n
    print(f"{twenty_five_n+ten_n+five_n+input_value}")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     if __name__ = "__main__" then (
      var input_value : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var twenty_five_n : int := input_value div 25 ;
    input_value := input_value - 25 * twenty_five_n ;
    var ten_n : int := input_value div 10 ;
    input_value := input_value - 10 * ten_n ;
    var five_n : int := input_value div 5 ;
    input_value := input_value - 5 * five_n ;
    execute (StringLib.formattedString("{twenty_five_n+ten_n+five_n+input_value}"))->display()
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def solve(A,n):
    dp=[[0 for i in range(2000)]for i in range(2000)]
    flag=1
    sum=0
    for i in range(n):
        sum+=A[i]
    for i in range(-sum,sum+1):
        dp[0][i]=10**9
    dp[0][0]=0
    for i in range(1,n+1):
        for j in range(-sum,sum+1):
            dp[flag][j]=10**9
            if(j-A[i-1]<=sum and j-A[i-1]>=-sum):
                dp[flag][j]=dp[flag ^ 1][j-A[i-1]]
            if(j+A[i-1]<=sum and j+A[i-1]>=-sum and dp[flag ^ 1][j+A[i-1]]!=10**9):
                dp[flag][j]=min(dp[flag][j],dp[flag ^ 1][j+A[i-1]]+1)
        flag=flag ^ 1
    for i in range(sum+1):
        if(dp[flag ^ 1][i]!=10**9):
            return dp[flag ^ 1][i]
    return n-1
arr=[10,22,9,33,21,50,41,60]
n=len(arr)
print(solve(arr,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var arr : Sequence := Sequence{10}->union(Sequence{22}->union(Sequence{9}->union(Sequence{33}->union(Sequence{21}->union(Sequence{50}->union(Sequence{41}->union(Sequence{ 60 }))))))) ;
    n := (arr)->size() ;
    execute (solve(arr, n))->display();
  operation solve(A : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var dp : Sequence := Integer.subrange(0, 2000-1)->select(i | true)->collect(i | (Integer.subrange(0, 2000-1)->select(i | true)->collect(i | (0)))) ;
    var flag : int := 1 ;
    var sum : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    sum := sum + A[i+1]) ;
    for i : Integer.subrange(-sum, sum + 1-1) do (    dp->first()[i+1] := (10)->pow(9)) ;
    dp->first()->first() := 0 ;
    for i : Integer.subrange(1, n + 1-1) do (    for j : Integer.subrange(-sum, sum + 1-1) do (    dp[flag+1][j+1] := (10)->pow(9) ;
    if ((j - A[i - 1+1]->compareTo(sum)) <= 0 & (j - A[i - 1+1]->compareTo(-sum)) >= 0) then (
      dp[flag+1][j+1] := dp[MathLib.bitwiseXor(flag, 1)+1][j - A[i - 1+1]+1]
    ) else skip ;
    if ((j + A[i - 1+1]->compareTo(sum)) <= 0 & (j + A[i - 1+1]->compareTo(-sum)) >= 0 & dp[MathLib.bitwiseXor(flag, 1)+1][j + A[i - 1+1]+1] /= (10)->pow(9)) then (
      dp[flag+1][j+1] := Set{dp[flag+1][j+1], dp[MathLib.bitwiseXor(flag, 1)+1][j + A[i - 1+1]+1] + 1}->min()
    ) else skip) ;
    flag := MathLib.bitwiseXor(flag, 1)) ;
    for i : Integer.subrange(0, sum + 1-1) do (    if (dp[MathLib.bitwiseXor(flag, 1)+1][i+1] /= (10)->pow(9)) then (
      return dp[MathLib.bitwiseXor(flag, 1)+1][i+1]
    ) else skip) ;
    return n - 1;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def input(): return sys.stdin.readline().strip()
def resolve():
    n,m=map(int,input().split())
    def make_divisors(n):
        divisors=[]
        for i in range(1,int(n**0.5)+1):
            if n % i==0 :
                divisors.append(i)
                if i!=n//i :
                    divisors.append(n//i)
        divisors.sort(reverse=True)
        return divisors
    for i in make_divisors(m):
        if i*n<=m :
            print(i)
            break
resolve()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    resolve();
  operation input() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine()->trim();
  operation resolve()
  pre: true post: true
  activity:
    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    skip ;
    for i : make_divisors(m) do (    if (i * n->compareTo(m)) <= 0 then (
      execute (i)->display() ;
    break
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
cnt=n
ans=0
cnt25=divmod(cnt,25)
ans+=cnt25[0]
cnt=cnt25[1]
cnt10=divmod(cnt,10)
ans+=cnt10[0]
cnt=cnt10[1]
cnt5=divmod(cnt,5)
ans+=cnt5[0]
cnt=cnt5[1]
cnt1=divmod(cnt,1)
ans+=cnt1[0]
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var cnt : int := n ;
    var ans : int := 0 ;
    var cnt25 : OclAny := Sequence{(cnt div 25), (cnt mod 25)} ;
    ans := ans + cnt25->first() ;
    cnt := cnt25[1+1] ;
    var cnt10 : OclAny := Sequence{(cnt div 10), (cnt mod 10)} ;
    ans := ans + cnt10->first() ;
    cnt := cnt10[1+1] ;
    var cnt5 : OclAny := Sequence{(cnt div 5), (cnt mod 5)} ;
    ans := ans + cnt5->first() ;
    cnt := cnt5[1+1] ;
    var cnt1 : OclAny := Sequence{(cnt div 1), (cnt mod 1)} ;
    ans := ans + cnt1->first() ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math as mt
def isPalindrome(str1,i,j):
    while(isize() ;
    execute (countPrimePalindrome(s, Len))->display();
  operation isPalindrome(str1 : OclAny, i : OclAny, j : OclAny) : OclAny
  pre: true post: true
  activity:
    while ((i->compareTo(j)) < 0) do (    if (str1[i+1] /= str1[j+1]) then (
      return false
    ) else skip ;
    i := i + 1 ;
    j := j - 1) ;
    return true;
  operation countPrimePalindrome(str1 : OclAny, Len : OclAny) : OclAny
  pre: true post: true
  activity:
    var prime : Sequence := Integer.subrange(0, Len + 1-1)->select(i | true)->collect(i | (true)) ;
    var prime->first() : OclAny := null;
    var prime[1+1] : OclAny := null;
    Sequence{prime->first(),prime[1+1]} := Sequence{false,false} ;
    for p : Integer.subrange(2, mt.ceil(mt.sqrt(Len + 1))-1) do (    if (prime[p+1]) then (
      for i : Integer.subrange(2 * p, Len + 1-1)->select( $x | ($x - 2 * p) mod p = 0 ) do (    prime[i+1] := false)
    ) else skip) ;
    var count : int := 0 ;
    for j : Integer.subrange(2, Len + 1-1) do (    if (prime[j+1]) then (
      for i : Integer.subrange(0, Len + 1 - j-1) do (    if (isPalindrome(str1, i, i + j - 1)) then (
      count := count + 1
    ) else skip)
    ) else skip) ;
    return count;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def countSubSeq(arr,n,k):
    count=0 ;
    for i in range(n):
        if(arr[i]% k==0):
            count+=1 ;
    return(2**count-1);
if __name__=="__main__" :
    arr=[1,2,3,6];
    n=len(arr);
    k=3 ;
    print(countSubSeq(arr,n,k));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 6 }))); ;
    n := (arr)->size(); ;
    k := 3; ;
    execute (countSubSeq(arr, n, k))->display();
    ) else skip;
  operation countSubSeq(arr : OclAny, n : OclAny, k : OclAny)
  pre: true post: true
  activity:
    var count : int := 0; ;
    for i : Integer.subrange(0, n-1) do (    if (arr[i+1] mod k = 0) then (
      count := count + 1;
    ) else skip) ;
    return ((2)->pow(count) - 1);;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import stdin as si
from collections import Counter as c
class Solution :
    def largest_one(self,a):
        return(1<exists( _x | result = _x );
  operation largest_one(a : OclAny) : OclAny
  pre: true post: true
  activity:
    return (1 * (2->pow((bin(a))->size() - 3))) - 1;
  operation largest_powself : OclAny, a : OclAny(a : OclAny) : OclAny
  pre: true post: true
  activity:
    return 1 * (2->pow(((bin(a))->size() - 3)));
  operation bazinga(n : OclAny,m : OclAny) : OclAny
  pre: true post: true
  activity:
    if n = m then  (
      return n
    )
    else (if MathLib.bitwiseAnd(m, (m + 1)) = 0 then
   (
      return m    
)
 else skip) ;
    if ((bin(n))->size()->compareTo((bin(m))->size())) < 0 then  (
      return self.largest_one(m)
    )
    else (
      var np2 : OclAny := self.largest_pow    skip ;
    skip ;
    skip(m) ;
    if (n->compareTo(np2)) < 0 & (np2 < m) then (
      return np2 - 1
    ) else skip ;
    return self.bazinga(n - np2, m - np2) + np2
      );
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      for i : Integer.subrange(0, ("" + ((si.readLine()->trim())))->toInteger()-1) do (    Sequence{n,m} := (si.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var S : Solution := (Solution.newSolution()).initialise() ;
    execute (S.bazinga(n, m))->display())
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for i in range(int(input())):
    l,r=map(int,input().split())
    while(l |(l+1)<=r): l |=l+1
    print(l)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var l : OclAny := null;
    var r : OclAny := null;
    Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    while ((MathLib.bitwiseOr(l, (l + 1))->compareTo(r)) <= 0) do (    l := l or l + 1) ;
    execute (l)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for i in range(int(input())):
    l,r=map(int,input().split())
    while(l |(l+1)<=r): l |=l+1
    print(l)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var l : OclAny := null;
    var r : OclAny := null;
    Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    while ((MathLib.bitwiseOr(l, (l + 1))->compareTo(r)) <= 0) do (    l := l or l + 1) ;
    execute (l)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for i in range(int(input())):
    l,r=map(int,input().split())
    while(l |(l+1)<=r): l |=l+1
    print(l)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var l : OclAny := null;
    var r : OclAny := null;
    Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    while ((MathLib.bitwiseOr(l, (l + 1))->compareTo(r)) <= 0) do (    l := l or l + 1) ;
    execute (l)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for i in range(int(input())):
    l,r=map(int,input().split())
    while(l |(l+1)<=r): l |=l+1
    print(l)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var l : OclAny := null;
    var r : OclAny := null;
    Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    while ((MathLib.bitwiseOr(l, (l + 1))->compareTo(r)) <= 0) do (    l := l or l + 1) ;
    execute (l)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def isValidNesbitt(a,b,c):
    A=a/(b+c);
    B=b/(a+c);
    C=c/(a+b);
    inequality=A+B+C ;
    return(inequality>=1.5);
a=1.0 ;
b=2.0 ;
c=3.0 ;
if(isValidNesbitt(a,b,c)):
    print("Nesbitt's inequality satisfied."," for real numbers ",a,",",b,",",c);
else :
    print("Not satisfied");
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    a := 1.0; ;
    b := 2.0; ;
    c := 3.0; ;
    if (isValidNesbitt(a, b, c)) then  (
      execute ("Nesbitt's inequality satisfied.")->display();
    )
    else (
      execute ("Not satisfied")->display();
      );
  operation isValidNesbitt(a : OclAny, b : OclAny, c : OclAny)
  pre: true post: true
  activity:
    var A : double := a / (b + c); ;
    var B : double := b / (a + c); ;
    var C : double := c / (a + b); ;
    var inequality : OclAny := A + B + C; ;
    return (inequality >= 1.5);;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def get_input():
    while True :
        try :
            yield ''.join(input())
        except EOFError :
            break
N=list(get_input())
for l in range(len(N)):
    Points=[float(i)for i in N[l].split()]
    P=[]
    for i in range(8):
        P.append(int(Points[i]*10**5))
    AB=[P[2]-P[0],P[3]-P[1]]
    CD=[P[6]-P[4],P[7]-P[5]]
    if AB[0]*CD[0]+AB[1]*CD[1]==0 :
        print("YES")
    else :
        print("NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var N : Sequence := (OclIterator.newOclIterator_Function(lambda _i : int in self.get_input(_i))) ;
    for l : Integer.subrange(0, (N)->size()-1) do (    var Points : Sequence := N[l+1].split()->select(i | true)->collect(i | (("" + ((i)))->toReal())) ;
    var P : Sequence := Sequence{} ;
    for i : Integer.subrange(0, 8-1) do (    execute ((("" + ((Points[i+1] * (10)->pow(5))))->toInteger()) : P)) ;
    var AB : Sequence := Sequence{P[2+1] - P->first()}->union(Sequence{ P[3+1] - P[1+1] }) ;
    var CD : Sequence := Sequence{P[6+1] - P[4+1]}->union(Sequence{ P[7+1] - P[5+1] }) ;
    if AB->first() * CD->first() + AB[1+1] * CD[1+1] = 0 then  (
      execute ("YES")->display()
    )
    else (
      execute ("NO")->display()
      ));
  operation get_input(_position_ : int) : OclAny
  pre: true post: true
  activity:
    var _yieldCount_ : int := 0;
    while true do (    try (    if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return StringLib.sumStringsWithSeparator(((OclFile["System.in"]).readLine()), ''))
(except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def swap(xp,yp):
    if(xp[0]==yp[0]):
        return
    xp[0]=xp[0]+yp[0]
    yp[0]=xp[0]-yp[0]
    xp[0]=xp[0]-yp[0]
x=[10]
swap(x,x)
print("After swap(&x,&x): x=",x[0])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var x : Sequence := Sequence{ 10 } ;
    swap(x, x) ;
    execute ("After swap(&x,&x): x=")->display();
  operation swap(xp : OclAny, yp : OclAny)
  pre: true post: true
  activity:
    if (xp->first() = yp->first()) then (
      return
    ) else skip ;
    xp->first() := xp->first() + yp->first() ;
    yp->first() := xp->first() - yp->first() ;
    xp->first() := xp->first() - yp->first();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import defaultdict
from copy import deepcopy
from math import log
N,M=map(int,input().split())
def prime_factor(n):
    i=2
    table=defaultdict(int)
    while i*i<=n :
        while n % i==0 :
            n//=i
            table[i]+=1
        i+=1
    if n>1 :
        table[n]+=1
    return table
f=prime_factor(M)
L=[1]
for i in f.keys():
    l=[]
    for j in range(f[i]+1):
        l.extend([k*(i**j)for k in L])
    L=l
L.sort()
for i in L[: :-1]:
    if i>=N :
        ans=i
        continue
    break
print(M//ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    skip ;
    var f : OclAny := prime_factor(M) ;
    var L : Sequence := Sequence{ 1 } ;
    for i : f.keys() do (    var l : Sequence := Sequence{} ;
    for j : Integer.subrange(0, f[i+1] + 1-1) do (    l := l->union(L->select(k | true)->collect(k | (k * ((i)->pow(j)))))) ;
    L := l) ;
    L := L->sort() ;
    for i : L(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do (    if (i->compareTo(N)) >= 0 then (
      var ans : int := i ;
    continue
    ) else skip ;
    break) ;
    execute (M div ans)->display();
  operation prime_factor(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var i : int := 2 ;
    var table : OclAny := defaultdict(OclType["int"]) ;
    while (i * i->compareTo(n)) <= 0 do (    while n mod i = 0 do (    n := n div i ;
    table[i+1] := table[i+1] + 1) ;
    i := i + 1) ;
    if n > 1 then (
      table[n+1] := table[n+1] + 1
    ) else skip ;
    return table;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def swap(xp,yp):
    xp[0]=xp[0]^ yp[0]
    yp[0]=xp[0]^ yp[0]
    xp[0]=xp[0]^ yp[0]
x=[10]
swap(x,x)
print("After swap(&x,&x): x=",x[0])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var x : Sequence := Sequence{ 10 } ;
    swap(x, x) ;
    execute ("After swap(&x,&x): x=")->display();
  operation swap(xp : OclAny, yp : OclAny)
  pre: true post: true
  activity:
    xp->first() := MathLib.bitwiseXor(xp->first(), yp->first()) ;
    yp->first() := MathLib.bitwiseXor(xp->first(), yp->first()) ;
    xp->first() := MathLib.bitwiseXor(xp->first(), yp->first());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def maxProduct(arr,n):
    if n<3 :
        return-1
    max_product=-(sys.maxsize-1)
    for i in range(0,n-2):
        for j in range(i+1,n-1):
            for k in range(j+1,n):
                max_product=max(max_product,arr[i]*arr[j]*arr[k])
    return max_product
arr=[10,3,5,6,20]
n=len(arr)
max=maxProduct(arr,n)
if max==-1 :
    print("No Tripplet Exits")
else :
    print("Maximum product is",max)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    arr := Sequence{10}->union(Sequence{3}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 20 })))) ;
    n := (arr)->size() ;
    var max : OclAny := maxProduct(arr, n) ;
    if max = -1 then  (
      execute ("No Tripplet Exits")->display()
    )
    else (
      execute ("Maximum product is")->display()
      );
  operation maxProduct(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    if n < 3 then (
      return -1
    ) else skip ;
    var max_product : double := -((trailer . (name maxsize)) - 1) ;
    for i : Integer.subrange(0, n - 2-1) do (    for j : Integer.subrange(i + 1, n - 1-1) do (    for k : Integer.subrange(j + 1, n-1) do (    max_product := Set{max_product, arr[i+1] * arr[j+1] * arr[k+1]}->max()))) ;
    return max_product;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
input()
a=input().split()
count=0
while len(a)>0 :
    k=a[1 :].index(a[0])+1
    count+=k-1
    a=a[1 : k]+a[k+1 :]
print(count)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     input() ;
    var a : OclAny := input().split() ;
    var count : int := 0 ;
    while (a)->size() > 0 do (    var k : OclAny := a->tail()->indexOf(a->first()) - 1 + 1 ;
    count := count + k - 1 ;
    a := a.subrange(1+1, k) + a.subrange(k + 1+1)) ;
    execute (count)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
import sys
import queue
def solve():
    n=int(input())
    a=list(map(int,input().split()))
    res=0
    s={}
    for i in range(n):
        if a[i*2+1]!=a[i*2]:
            ind=0
            for j in range(i*2+1,2*n):
                if a[j]==a[i*2]:
                    ind=j
                    break
            for j in range(ind,i*2+1,-1):
                res+=1
                a[j],a[j-1]=a[j-1],a[j]
    print(res)
if __name__=='__main__' :
    multi_test=0
    if multi_test :
        t=int(input())
        for _ in range(t):
            solve()
    else :
        solve()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      var multi_test : int := 0 ;
    if multi_test then  (
      var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, t-1) do (    solve())
    )
    else (
      solve()
      )
    ) else skip;
  operation solve()
  pre: true post: true
  activity:
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var res : int := 0 ;
    var s : OclAny := Set{} ;
    for i : Integer.subrange(0, n-1) do (    if a[i * 2 + 1+1] /= a[i * 2+1] then (
      var ind : int := 0 ;
    for j : Integer.subrange(i * 2 + 1, 2 * n-1) do (    if a[j+1] = a[i * 2+1] then (
      ind := j ;
    break
    ) else skip) ;
    for j : Integer.subrange(i * 2 + 1 + 1, ind)->reverse() do (    res := res + 1 ;
    var a[j+1] : OclAny := null;
    var a[j - 1+1] : OclAny := null;
    Sequence{a[j+1],a[j - 1+1]} := Sequence{a[j - 1+1],a[j+1]})
    ) else skip) ;
    execute (res)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a=list(map(int,input().split()))
i=1
j=0
ans=0
while(i<2*n):
    if(a[i-1]!=a[i]):
        for j in range(i+1,2*n):
            if a[i-1]==a[j]:
                ans+=j-i
                a.pop(j)
                a.insert(i,a[i-1])
    i+=2
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var i : int := 1 ;
    var j : int := 0 ;
    var ans : int := 0 ;
    while ((i->compareTo(2 * n)) < 0) do (    if (a[i - 1+1] /= a[i+1]) then (
      for j : Integer.subrange(i + 1, 2 * n-1) do (    if a[i - 1+1] = a[j+1] then (
      ans := ans + j - i ;
    a := a->excludingAt(j+1) ;
    a := a.insertAt(i+1, a[i - 1+1])
    ) else skip)
    ) else skip ;
    i := i + 2) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
p=input().split(" ")
p=[int(p[i])for i in range(2*n)]
c=0
def slide(i,ind):
    temp=p[ind]
    for j in range(ind-1,i,-1):
        p[j+1]=p[j]
    p[i+1]=temp
    return ind-i-1
for i in range(0,2*n,2):
    ind=p.index(p[i],i+1)
    c+=slide(i,ind)
print(c)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var p : OclAny := input().split(" ") ;
    p := Integer.subrange(0, 2 * n-1)->select(i | true)->collect(i | (("" + ((p[i+1])))->toInteger())) ;
    var c : int := 0 ;
    skip ;
    for i : Integer.subrange(0, 2 * n-1)->select( $x | ($x - 0) mod 2 = 0 ) do (    ind := p->indexOf(p[i+1], i + 1) - 1 ;
    c := c + slide(i, ind)) ;
    execute (c)->display();
  operation slide(i : OclAny, ind : OclAny) : OclAny
  pre: true post: true
  activity:
    var temp : OclAny := p[ind+1] ;
    for j : Integer.subrange(i + 1, ind - 1)->reverse() do (    p[j + 1+1] := p[j+1]) ;
    p[i + 1+1] := temp ;
    return ind - i - 1;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
input()
a=input().split()
cnt=0
while len(a)>0 :
    k=a[1 :].index(a[0])+1
    cnt+=k-1
    a=a[1 : k]+a[k+1 :]
print(cnt)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     input() ;
    var a : OclAny := input().split() ;
    var cnt : int := 0 ;
    while (a)->size() > 0 do (    var k : OclAny := a->tail()->indexOf(a->first()) - 1 + 1 ;
    cnt := cnt + k - 1 ;
    a := a.subrange(1+1, k) + a.subrange(k + 1+1)) ;
    execute (cnt)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def mirrorImage(a,b,c,x1,y1):
    temp=-2*(a*x1+b*y1+c)/(a*a+b*b)
    x=temp*a+x1
    y=temp*b+y1
    return(x,y)
a=-1.0
b=1.0
c=0.0
x1=1.0
y1=0.0
x,y=mirrorImage(a,b,c,x1,y1);
print("Image of point("+str(x1)+","+str(y1)+")")
print("by mirror("+str(a)+")x+("+str(b)+")y+("+str(c)+")=0,is :")
print("("+str(x)+","+str(y)+")")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    a := -1.0 ;
    b := 1.0 ;
    c := 0.0 ;
    x1 := 1.0 ;
    y1 := 0.0 ;
    Sequence{x,y} := mirrorImage(a, b, c, x1, y1); ;
    execute ("Image of point(" + ("" + ((x1))) + "," + ("" + ((y1))) + ")")->display() ;
    execute ("by mirror(" + ("" + ((a))) + ")x+(" + ("" + ((b))) + ")y+(" + ("" + ((c))) + ")=0,is :")->display() ;
    execute ("(" + ("" + ((x))) + "," + ("" + ((y))) + ")")->display();
  operation mirrorImage(a : OclAny, b : OclAny, c : OclAny, x1 : OclAny, y1 : OclAny) : OclAny
  pre: true post: true
  activity:
    var temp : double := -2 * (a * x1 + b * y1 + c) / (a * a + b * b) ;
    var x : double := temp * a + x1 ;
    var y : double := temp * b + y1 ;
    return Sequence{x, y};
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
NUM=(0b0111111,0b0000110,0b1011011,0b1001111,0b1100110,0b1101101,0b1111101,0b0100111,0b1111111,0b1101111,)
while 1 :
    n=int(input())
    if n==-1 : break
    current=0
    for i in range(n):
        num=NUM[int(input())]
        print(format(current ^ num,'b').zfill(7))
        current=num
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var NUM : OclAny := Sequence{0b0111111, 0b0000110, 0b1011011, 0b1001111, 0b1100110, 0b1101101, 0b1111101, 0b0100111, 0b1111111, (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0b1101111))))))) ,)} ;
    while 1 do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = -1 then (
      break
    ) else skip ;
    var current : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    var num : OclAny := NUM[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1] ;
    execute (format(MathLib.bitwiseXor(current, num), 'b').zfill(7))->display() ;
    current := num));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
EPS=1e-11
def dot(a,b):
    return a.real*b.real+a.imag*b.imag
def cross(a,b):
    return a.real*b.imag-a.imag*b.real
def norm(a):
    return a.real**2+a.imag**2
def project(line,p):
    base=line[1]-line[0]
    r=dot(p-line[0],base)/norm(base)
    return line[0]+base*r
def symmetric_Point(line,p):
    return p+2*(project(line,p)-p)
def isParallelLL(line1,line2):
    t=cross(line1[1]-line1[0],line2[1]-line2[0])
    return-EPS<=t and t<=EPS
def isOrthogonalLL(line1,line2):
    t=dot(line1[1]-line1[0],line2[1]-line2[0])
    return-EPS<=t and t<=EPS
while True :
    try : p=list(map(float,input().split()))
    except : break
    p1=complex(p[0],p[1])
    p2=complex(p[2],p[3])
    p3=complex(p[4],p[5])
    p4=complex(p[6],p[7])
    print('YES' if isOrthogonalLL([p1,p2],[p3,p4])else 'NO')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var EPS : double := ("1e-11")->toReal() ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    while true do (    try (    p := ((input().split())->collect( _x | (OclType["double"])->apply(_x) )))
     catch (_e : OclException) do (    break)
 ;
    var p1 : OclAny := complex(p->first(), p[1+1]) ;
    var p2 : OclAny := complex(p[2+1], p[3+1]) ;
    var p3 : OclAny := complex(p[4+1], p[5+1]) ;
    var p4 : OclAny := complex(p[6+1], p[7+1]) ;
    execute (if isOrthogonalLL(Sequence{p1}->union(Sequence{ p2 }), Sequence{p3}->union(Sequence{ p4 })) then 'YES' else 'NO' endif)->display());
  operation dot(a : OclAny, b : OclAny) : OclAny
  pre: true post: true
  activity:
    return a.real * b.real + a.imag * b.imag;
  operation cross(a : OclAny, b : OclAny) : OclAny
  pre: true post: true
  activity:
    return a.real * b.imag - a.imag * b.real;
  operation norm(a : OclAny) : OclAny
  pre: true post: true
  activity:
    return (a.real)->pow(2) + (a.imag)->pow(2);
  operation project(line : OclAny, p : OclAny) : OclAny
  pre: true post: true
  activity:
    var base : double := line[1+1] - line->first() ;
    var r : double := dot(p - line->first(), base) / norm(base) ;
    return line->first() + base * r;
  operation symmetric_Point(line : OclAny, p : OclAny) : OclAny
  pre: true post: true
  activity:
    return p + 2 * (project(line, p) - p);
  operation isParallelLL(line1 : OclAny, line2 : OclAny) : OclAny
  pre: true post: true
  activity:
    var t : OclAny := cross(line1[1+1] - line1->first(), line2[1+1] - line2->first()) ;
    return (-EPS->compareTo(t)) <= 0 & (t->compareTo(EPS)) <= 0;
  operation isOrthogonalLL(line1 : OclAny, line2 : OclAny) : OclAny
  pre: true post: true
  activity:
    t := dot(line1[1+1] - line1->first(), line2[1+1] - line2->first()) ;
    return (-EPS->compareTo(t)) <= 0 & (t->compareTo(EPS)) <= 0;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def Solve_1(freq):
    n=0
    max_freq=0
    flag=0
    for i in range(26):
        n+=freq[i]
        if(freq[i]!=0 and flag==0):
            first=freq[i]
            flag=1
        if(max_freqcompareTo(freq[i+1])) < 0) then (
      max_freq := freq[i+1]
    ) else skip) ;
    if (n = 0) then (
      return 0
    ) else skip ;
    if (first /= max_freq) then  (
      flag := 1
    )
    else (
      flag := 0
      ) ;
    return Set{(n - 1) div 2, n - max_freq - flag}->min();
  operation solve(s : OclAny)
  pre: true post: true
  activity:
    freq := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ;
    for i : Integer.subrange(0, (s)->size()-1) do (    freq[(s[i+1])->char2byte() - ('a')->char2byte()+1] := freq[(s[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ;
    execute (SolveSolve(Solve(Solve(SolveSolve(Solve(Solve(SolveSolve(Solve(Solve(SolveSolve(Solve(Solve(SolveSolve(Solve(Solve(SolveSolve(Solve(Solve(SolveSolve(Solve(Solve    freq := MatrixLib.elementwiseMult(Sequence{ 0 }, 26)(freq))(freq))(freq)(freq))->display()(freq))(freq))(freq)(freq))->display()(freq))(freq))(freq)(freq))->display()(freq))(freq))(freq)(freq))->display()(freq))(freq))(freq)(freq))->display()(freq))(freq))(freq)(freq))->display()(freq))(freq))(freq)(freq))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import*
def area(x):
    ret=0.
    theta=360.
    for i in range(x-1):
        tmp=float(input())
        theta-=tmp
        tmp=tmp*pi/180.
        ret+=(sin(tmp/2)*cos(tmp/2))
    theta=pi*theta/180.
    ret+=sin(theta/2)*cos(theta/2);
    return ret ;
while 1 :
    m=int(input())
    if m==0 : break
    a=area(m)
    b=area(int(input()))
    print(0 if a==b else(1 if a>b else 2))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    while 1 do (    var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if m = 0 then (
      break
    ) else skip ;
    var a : OclAny := area(m) ;
    var b : OclAny := area(("" + (((OclFile["System.in"]).readLine())))->toInteger()) ;
    execute (if a = b then 0 else (if (a->compareTo(b)) > 0 then 1 else 2 endif) endif)->display());
  operation area(x : OclAny)
  pre: true post: true
  activity:
    var ret : double := 0. ;
    var theta : double := 360. ;
    for i : Integer.subrange(0, x - 1-1) do (    var tmp : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ;
    theta := theta - tmp ;
    tmp := tmp * pi / 180. ;
    ret := ret + (sin(tmp / 2) * cos(tmp / 2))) ;
    theta := pi * theta / 180. ;
    ret := ret + sin(theta / 2) * cos(theta / 2); ;
    return ret;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
primes=[]
MAX_NUM=100000
is_prime=[True]*MAX_NUM
is_prime[0]=False
is_prime[1]=False
for num in range(MAX_NUM):
    if is_prime[num]:
        primes.append(num)
        for j in range(2*num,MAX_NUM,num):
            is_prime[j]=False
def do_prime_factorization(x):
    res={}
    for p in primes :
        if x==1 :
            break
        while x % p==0 :
            x/=p
            if not p in res :
                res[p]=0
            res[p]+=1
    if x>1 :
        res[x]=1
    return res.items()
def f(x,d,n,m,ps):
    if x>=n :
        return x
    if d<0 :
        return m
    p,num=ps[d]
    res=m
    for i in range(num+1):
        y=x*(p**i)
        res=min(res,f(y,d-1,n,m,ps))
    return res
def solve(n,m):
    ps=do_prime_factorization(m)
    q=f(1,len(ps)-1,n,m,ps)
    p=m//q
    return p
n,m=map(int,raw_input().split())
print(solve(n,m))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var primes : Sequence := Sequence{} ;
    var MAX_NUM : int := 100000 ;
    var is_prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, MAX_NUM) ;
    is_prime->first() := false ;
    is_prime[1+1] := false ;
    for num : Integer.subrange(0, MAX_NUM-1) do (    if is_prime[num+1] then (
      execute ((num) : primes) ;
    for j : Integer.subrange(2 * num, MAX_NUM-1)->select( $x | ($x - 2 * num) mod num = 0 ) do (    is_prime[j+1] := false)
    ) else skip) ;
    skip ;
    skip ;
    skip ;
    Sequence{n,m} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (solve(n, m))->display();
  operation do_prime_factorization(x : OclAny) : OclAny
  pre: true post: true
  activity:
    var res : OclAny := Set{} ;
    for p : primes do (    if x = 1 then (
      break
    ) else skip ;
    while x mod p = 0 do (    x := x / p ;
    if not((res)->includes(p)) then (
      res[p+1] := 0
    ) else skip ;
    res[p+1] := res[p+1] + 1)) ;
    if x > 1 then (
      res[x+1] := 1
    ) else skip ;
    return res->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()});
  operation f(x : OclAny, d : OclAny, n : OclAny, m : OclAny, ps : OclAny) : OclAny
  pre: true post: true
  activity:
    if (x->compareTo(n)) >= 0 then (
      return x
    ) else skip ;
    if d < 0 then (
      return m
    ) else skip ;
    var p : OclAny := null;
    var num : OclAny := null;
    Sequence{p,num} := ps[d+1] ;
    res := m ;
    for i : Integer.subrange(0, num + 1-1) do (    var y : double := x * ((p)->pow(i)) ;
    res := Set{res, f(y, d - 1, n, m, ps)}->min()) ;
    return res;
  operation solve(n : OclAny, m : OclAny) : OclAny
  pre: true post: true
  activity:
    ps := do_prime_factorization(m) ;
    var q : String := f(1, (ps)->size() - 1, n, m, ps) ;
    var p : int := m div q ;
    return p;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import sin,pi
def calc(n):
    s=a=0
    V=[]
    for i in range(n-1):
        v=int(input())
        s+=v
        a+=sin(v*pi/180)
        V.append(v)
    V.append(360-s)
    a+=sin((360-s)*pi/180)
    return a,sorted(V)
while 1 :
    m=int(input())
    if m==0 :
        break
    a1,V1=calc(m)
    n=int(input())
    a2,V2=calc(n)
    if V1==V2 or a1==a2 :
        print(0)
    elif a1toInteger() ;
    if m = 0 then (
      break
    ) else skip ;
    var a1 : OclAny := null;
    var V1 : OclAny := null;
    Sequence{a1,V1} := calc(m) ;
    n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a2 : OclAny := null;
    var V2 : OclAny := null;
    Sequence{a2,V2} := calc(n) ;
    if V1 = V2 or a1 = a2 then  (
      execute (0)->display()
    )
    else (if (a1->compareTo(a2)) < 0 then
   (
      execute (2)->display()    
)
    else (
      execute (1)->display()
      )    )
);
  operation calc(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var s : OclAny := 0; var a : int := 0 ;
    var V : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n - 1-1) do (    var v : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    s := s + v ;
    a := a + sin(v * pi / 180) ;
    execute ((v) : V)) ;
    execute ((360 - s) : V) ;
    a := a + sin((360 - s) * pi / 180) ;
    return a, V->sort();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
ONE_BIGGER_TWO=1
TWO_BIGGER_ONE=2
SAME=0
def calculate_area(input_list):
    last=360-sum(input_list)
    input_list.append(last)
    radian_list=[math.radians(item)for item in input_list]
    sin_list=[math.sin(item)for item in radian_list]
    area=math.fsum(sin_list)
    return area
while True :
    input_count=int(input())
    if input_count==0 :
        break
    input_list1=[int(input())for _ in range(input_count-1)]
    area1=calculate_area(input_list1)
    input_count=int(input())
    input_list2=[int(input())for _ in range(input_count-1)]
    area2=calculate_area(input_list2)
    if math.isclose(area1,area2):
        print(SAME)
    elif area1>area2 :
        print(ONE_BIGGER_TWO)
    else :
        print(TWO_BIGGER_ONE)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var ONE_BIGGER_TWO : int := 1 ;
    var TWO_BIGGER_ONE : int := 2 ;
    var SAME : int := 0 ;
    skip ;
    while true do (    var input_count : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if input_count = 0 then (
      break
    ) else skip ;
    var input_list1 : Sequence := Integer.subrange(0, input_count - 1-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ;
    var area1 : OclAny := calculate_area(input_list1) ;
    input_count := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var input_list2 : Sequence := Integer.subrange(0, input_count - 1-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ;
    var area2 : OclAny := calculate_area(input_list2) ;
    if  then  (
      execute (SAME)->display()
    )
    else (if (area1->compareTo(area2)) > 0 then
   (
      execute (ONE_BIGGER_TWO)->display()    
)
    else (
      execute (TWO_BIGGER_ONE)->display()
      )    )
);
  operation calculate_area(input_list : OclAny) : OclAny
  pre: true post: true
  activity:
    var last : double := 360 - (input_list)->sum() ;
    execute ((last) : input_list) ;
    var radian_list : Sequence := input_list->select(item | true)->collect(item | ()) ;
    var sin_list : Sequence := radian_list->select(item | true)->collect(item | ((item)->sin())) ;
    var area : double := (sin_list)->sum() ;
    return area;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
M=0.00872664625997164788461845384244
EPS=1e-8
a=[0]*2
s=[0.0]*2
while True :
    eof=False
    for i in range(2):
        s[i]=a[i]=0 ;
        n=int(input())
        if n==0 :
            eof=True
            break
        for j in range(1,n):
            v=int(input())
            a[i]+=v
            s[i]+=math.sin(M*v)*math.cos(M*v)
        v=360-a[i]
        s[i]+=math.sin(M*v)*math.cos(M*v)
    if eof : break
    if abs(s[1]-s[0])<=EPS : print(0)
    elif s[1]>=s[0]: print(2)
    else : print(1);
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var M : double := 0.00872664625997164788461845384244 ;
    var EPS : double := ("1e-8")->toReal() ;
    var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 2) ;
    var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0.0 }, 2) ;
    while true do (    var eof : boolean := false ;
    for i : Integer.subrange(0, 2-1) do (    s[i+1] := 0; var a[i+1] : int := 0; ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      eof := true ;
    break
    ) else skip ;
    for j : Integer.subrange(1, n-1) do (    var v : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    a[i+1] := a[i+1] + v ;
    s[i+1] := s[i+1] + (M * v)->sin() * ) ;
    v := 360 - a[i+1] ;
    s[i+1] := s[i+1] + (M * v)->sin() * ) ;
    if eof then (
      break
    ) else skip ;
    if ((s[1+1] - s->first())->abs()->compareTo(EPS)) <= 0 then  (
      execute (0)->display()
    )
    else (if (s[1+1]->compareTo(s->first())) >= 0 then
   (
      execute (2)->display()    
)
    else (
      execute (1)->display();
      )    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    n,k=map(int,input().split())
    possible=1+(n-3)//2
    if k>possible :
        print(-1)
    elif k==0 :
        print(' '.join(map(str,[i+1 for i in range(n)])))
    else :
        re=1
        li=[1,3,2]
        counter=4
        while retoInteger()-1) do (    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var possible : int := 1 + (n - 3) div 2 ;
    if (k->compareTo(possible)) > 0 then  (
      execute (-1)->display()
    )
    else (if k = 0 then
   (
      execute (StringLib.sumStringsWithSeparator(((Integer.subrange(0, n-1)->select(i | true)->collect(i | (i + 1)))->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()    
)
    else (
      var re : int := 1 ;
    var li : Sequence := Sequence{1}->union(Sequence{3}->union(Sequence{ 2 })) ;
    var counter : int := 4 ;
    while (re->compareTo(k)) < 0 do (    execute ((counter + 1) : li) ;
    execute ((counter) : li) ;
    counter := counter + 2 ;
    re := re + 1) ;
    for iii : Integer.subrange(li->front()->last() + 1, n + 1-1) do (    execute ((iii) : li)) ;
    execute (StringLib.sumStringsWithSeparator(((li)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()
      )    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for s in[*open(0)][1 :]:
    n,k=map(int,s.split()); a=[*range(1,n+1)]; i=1
    while i<2*k : a[i : i+2]=a[i+1 : i-1 :-1]; i+=2
    print(*(a,[-1])[i>n])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do (    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (s.split())->collect( _x | (OclType["int"])->apply(_x) );    var a : Sequence := Integer.subrange(1, n + 1-1);    var i : int := 1 ;
    while (i->compareTo(2 * k)) < 0 do (    a.subrange(i+1, i + 2) := a(subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))) : (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))) (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))));    i := i + 2) ;
    execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom - (number (integer 1)))))))) ])))))) )) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (comparison (expr (atom (name i)))) > (comparison (expr (atom (name n))))))))) ]))))))))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import stdout,stdin
st=lambda : list(stdin.readline().strip())
li=lambda : list(map(int,stdin.readline().split()))
mp=lambda : map(int,stdin.readline().split())
inp=lambda : int(stdin.readline())
pr=lambda n : stdout.write(str(n)+"\n")
for _ in range(inp()):
    n,k=mp()
    N=n if n % 2 else n-1
    if N//2>=k :
        a=[i+1 for i in range(n)]
        m=n//2
        a_m=a[: k+1]
        a_M=a[k+1 : min(2*k+1,n)]
        a[: min(2*(k+1),n): 2]=a_m
        a[1 : 2*k+1 : 2]=a_M
        pr(' '.join(str(v)for v in a))
    else :
        pr(-1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var st : Function := lambda $$ : OclAny in ((stdin.readLine()->trim())) ;
    var li : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ;
    var mp : Function := lambda $$ : OclAny in ((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var inp : Function := lambda $$ : OclAny in (("" + ((stdin.readLine())))->toInteger()) ;
    var pr : Function := lambda n : OclAny in (stdout.write(("" + ((n))) + "\n")) ;
    for _anon : Integer.subrange(0, inp->apply()-1) do (    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := mp->apply() ;
    var N : OclAny := if n mod 2 then n else n - 1 endif ;
    if (N div 2->compareTo(k)) >= 0 then  (
      var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i + 1)) ;
    var m : int := n div 2 ;
    var a_m : OclAny := a.subrange(1,k + 1) ;
    var a_M : OclAny := a.subrange(k + 1+1, Set{2 * k + 1, n}->min()) ;
    a(subscript : (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name k))) + (expr (atom (number (integer 1))))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))) (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) := a_m ;
    a(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (test (logical_test (comparison (expr (expr (expr (atom (number (integer 2)))) * (expr (atom (name k)))) + (expr (atom (number (integer 1)))))))) (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) := a_M ;
    pr(StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) ))))))) (comp_for for (exprlist (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name a)))))))), ' '))
    )
    else (
      pr(-1)
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import stdin
for _ in range(int(stdin.readline())):
    n,k=list(map(int,stdin.readline().split()))
    if n % 2==0 and k>=n//2 or n % 2==1 and k>n//2 :
        print(-1)
    else :
        a=list(range(1,n+1))
        res=[-1]*n
        cur=0
        for i in range(n):
            if i % 2==1 and k>0 :
                res[i]=a[-k]
                k-=1
            else :
                res[i]=a[cur]
                cur+=1
        print(*res)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    for _anon : Integer.subrange(0, ("" + ((stdin.readLine())))->toInteger()-1) do (    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := ((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if n mod 2 = 0 & (k->compareTo(n div 2)) >= 0 or n mod 2 = 1 & (k->compareTo(n div 2)) > 0 then  (
      execute (-1)->display()
    )
    else (
      var a : Sequence := (Integer.subrange(1, n + 1-1)) ;
    var res : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ;
    var cur : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    if i mod 2 = 1 & k > 0 then  (
      res[i+1] := a->reverse()->at(-(-k)) ;
    k := k - 1
    )
    else (
      res[i+1] := a[cur+1] ;
    cur := cur + 1
      )) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
from decimal import Decimal as D
orth=lambda l :((D(l[2])-D(l[0]))*(D(l[6])-D(l[4]))+(D(l[3])-D(l[1]))*(D(l[7])-D(l[5])))
[print(l)for l in["YES" if orth(j)==0 else "NO" for j in[l.split()for l in sys.stdin]]]
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var orth : Function := lambda l : OclAny in (((D(l[2+1]) - D(l->first())) * (D(l[6+1]) - D(l[4+1])) + (D(l[3+1]) - D(l[1+1])) * (D(l[7+1]) - D(l[5+1])))) ;
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    n,k=map(int,input().strip().split())
    if(k==0):
        for yt in range(1,n+1):
            print(yt,end=" ")
        print()
    elif((2*k>=n)or(k==n-1)):
        print(-1)
    else :
        arr=[]
        for i in range(1,n+1):
            arr.append(i)
        else :
            left=0
            right=len(arr)-1
            count=0
            while(count!=k):
                print(arr[left],end=" ")
                left+=1
                print(arr[right],end=" ")
                right-=1
                count+=1
            while(left<=right):
                print(arr[left],end=" ")
                left+=1
            print()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if (k = 0) then  (
      for yt : Integer.subrange(1, n + 1-1) do (    execute (yt)->display()) ;
    execute (->display()
    )
    else (if (((2 * k->compareTo(n)) >= 0) or (k = n - 1)) then
   (
      execute (-1)->display()    
)
    else (
      var arr : Sequence := Sequence{} ;
(compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name arr)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name left)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name right)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr)))))))) )))) - (expr (atom (number (integer 1)))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name count)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (compound_stmt while (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name count)))) != (comparison (expr (atom (name k)))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name left)))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom " "))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name left)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name right)))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom " "))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name right)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name count)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) (stmt (compound_stmt while (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name left)))) <= (comparison (expr (atom (name right)))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name left)))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom " "))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name left)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( )))))))))))))))
      )    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
class Node :
    def __init__(self,data):
        self.data=data
        self.left=None
        self.right=None
def updateParent(parent,node):
    if(node==None):
        return parent
    if(node.left!=None):
        parent[node.left.data]=node.data
    if(node.right!=None):
        parent[node.right.data]=node.data
    parent=updateParent(parent,node.left)
    parent=updateParent(parent,node.right)
    return parent
def getMaxXor(root,n,val,x):
    parent=[0]*(n+1)
    parent=updateParent(parent,root)
    maximum=x ^ val
    val=parent[val]
    while(val!=0):
        maximum=max(maximum,x ^ val)
        val=parent[val]
    return maximum
n=6
root=Node(1)
root.left=Node(2)
root.right=Node(3)
root.left.left=Node(4)
root.right.right=Node(5)
root.right.right.left=Node(6)
val=6
x=4
print(getMaxXor(root,n,val,x))
------------------------------------------------------------
OCL File:
---------
class Node {
  static operation newNode() : Node
  pre: true
  post: Node->exists( _x | result = _x );
  attribute data : OclAny := data;
  attribute left : OclAny := null;
  attribute right : OclAny := null;
  operation initialise(data : OclAny) : Node
  pre: true post: true
  activity:
    self.data := data ;
    self.left := null ;
    self.right := null;
    return self;
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    n := 6 ;
    root := (Node.newNode()).initialise(1) ;
    root.left := (Node.newNode()).initialise(2) ;
    root.right := (Node.newNode()).initialise(3) ;
    root.left.left := (Node.newNode()).initialise(4) ;
    root.right.right := (Node.newNode()).initialise(5) ;
    root.right.right.left := (Node.newNode()).initialise(6) ;
    val := 6 ;
    x := 4 ;
    execute (getMaxXor(root, n, val, x))->display();
  operation updateParent(parent : OclAny, node : OclAny) : OclAny
  pre: true post: true
  activity:
    if (node = null) then (
      return parent
    ) else skip ;
    if (node.left /= null) then (
      parent[node.left.data+1] := node.data
    ) else skip ;
    if (node.right /= null) then (
      parent[node.right.data+1] := node.data
    ) else skip ;
    parent := updateParent(parent, node.left) ;
    parent := updateParent(parent, node.right) ;
    return parent;
  operation getMaxXor(root : OclAny, n : OclAny, val : OclAny, x : OclAny) : OclAny
  pre: true post: true
  activity:
    parent := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ;
    parent := updateParent(parent, root) ;
    var maximum : int := MathLib.bitwiseXor(x, val) ;
    val := parent[val+1] ;
    while (val /= 0) do (    maximum := Set{maximum, MathLib.bitwiseXor(x, val)}->max() ;
    val := parent[val+1]) ;
    return maximum;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s,k=map(int,input().split())
fib_n=[0,1]
while(fib_n[-1]<=s):
    fib_n.append(sum(fib_n[-1-i]for i in range(min(k,len(fib_n)))))
del fib_n[1]
del fib_n[0]
del fib_n[-1]
foundSeries=[0]
found=False
def findBSearch(total,numbers):
    global found
    if found :
        return False
    global foundSeries
    if total==0 :
        return True
    elif len(numbers)==0 or total<0 :
        return False
    else :
        top=len(numbers)-1
        bottom=0
        while abs(top-bottom)>1 :
            if total>(numbers[(top+bottom)//2]):
                bottom=(top+bottom)//2
            else :
                top=(top+bottom)//2
        if(total==numbers[top]or total==numbers[bottom]):
            foundSeries.append(total)
            found=True
            return True
        else :
            if(findBSearch(total-numbers[top],numbers[: top]+numbers[top+1 :])):
                foundSeries.append(numbers[top])
                return True
            elif(findBSearch(total-numbers[bottom],numbers[: bottom]+numbers[bottom+1 :])):
                foundSeries.append(numbers[bottom])
                return True
            else :
                return False
findBSearch(s,fib_n)
print(len(foundSeries))
for i in foundSeries :
    print(i,end=" ")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  attribute found : OclAny;
  attribute foundSeries : OclAny;
  operation initialise()
  pre: true post: true
  activity:     var s : OclAny := null;
    var k : OclAny := null;
    Sequence{s,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var fib_n : Sequence := Sequence{0}->union(Sequence{ 1 }) ;
    while ((fib_n->last()->compareTo(s)) <= 0) do (    execute ((((argument (test (logical_test (comparison (expr (atom (name fib_n)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom - (number (integer 1)))) - (expr (atom (name i))))))))) ])))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name k))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name fib_n)))))))) ))))))))) ))))))))) )))))))))->sum()) : fib_n)) ;
    execute (fib_n[1+1])->isDeleted() ;
    execute (fib_n->first())->isDeleted() ;
    execute (fib_n->last())->isDeleted() ;
    var foundSeries : Sequence := Sequence{ 0 } ;
    var found : boolean := false ;
    skip ;
    findBSearch(s, fib_n) ;
    execute ((foundSeries)->size())->display() ;
    for i : foundSeries do (    execute (i)->display());
  operation findBSearch(total : OclAny, numbers : OclAny) : OclAny
  pre: true post: true
  activity:
    skip ;
    if found then (
      return false
    ) else skip ;
    skip ;
    if total = 0 then  (
      return true
    )
    else (if (numbers)->size() = 0 or total < 0 then
   (
      return false    
)
    else (
      var top : double := (numbers)->size() - 1 ;
    var bottom : int := 0 ;
    while (top - bottom)->abs() > 1 do (    if (total->compareTo((numbers[(top + bottom) div 2+1]))) > 0 then  (
      bottom := (top + bottom) div 2
    )
    else (
      top := (top + bottom) div 2
      )) ;
    if (total = numbers[top+1] or total = numbers[bottom+1]) then  (
      execute ((total) : foundSeries) ;
    found := true ;
    return true
    )
    else (
      if (findBSearch(total - numbers[top+1], numbers.subrange(1,top) + numbers.subrange(top + 1+1))) then  (
      execute ((numbers[top+1]) : foundSeries) ;
    return true
    )
    else (if (findBSearch(total - numbers[bottom+1], numbers.subrange(1,bottom) + numbers.subrange(bottom + 1+1))) then
   (
      execute ((numbers[bottom+1]) : foundSeries) ;
    return true    
)
    else (
      return false
      )    )
      )
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
ans=0
d=[False]*10
while n>=10 or not d[n]:
    ans+=1
    if n<10 :
        d[n]=True
    n+=1
    while not n % 10 and n>1 :
        n//=10
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var ans : int := 0 ;
    var d : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, 10) ;
    while n >= 10 or not(d[n+1]) do (    ans := ans + 1 ;
    if n < 10 then (
      d[n+1] := true
    ) else skip ;
    n := n + 1 ;
    while not(n mod 10) & n > 1 do (    n := n div 10)) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
N,M=map(int,input().split())
a=M//N
for i in range(a,0,-1):
    if M % i==0 :
        print(i)
        sys.exit()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : int := M div N ;
    for i : Integer.subrange(0 + 1, a)->reverse() do (    if M mod i = 0 then (
      execute (i)->display() ;
    sys.exit()
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
from functools import lru_cache,cmp_to_key
from heapq import merge,heapify,heappop,heappush
from math import*
from collections import defaultdict as dd,deque,Counter as C
from itertools import combinations as comb,permutations as perm
from bisect import bisect_left as bl,bisect_right as br,bisect,insort
from time import perf_counter
from fractions import Fraction
import copy
from copy import deepcopy
import time
starttime=time.time()
mod=int(pow(10,9)+7)
mod2=998244353
def data(): return sys.stdin.readline().strip()
def out(*var,end="\n"): sys.stdout.write(' '.join(map(str,var))+end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int,data().split())
def ssp(): return map(str,data().split())
def l1d(n,val=0): return[val for i in range(n)]
def l2d(n,m,val=0): return[l1d(n,val)for j in range(m)]
try :
    sys.stdin=open("input.txt","r")
except :
    pass
def pmat(A):
    for ele in A : print(*ele,end="\n")
s,k=map(int,input().split())
a,b=[0,1],[]
while a[-1]pow(9) + 7)))->toInteger() ;
    var mod2 : int := 998244353 ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    try (    OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")))
     catch (_e : OclException) do (    skip)
 ;
    skip ;
    var s : OclAny := null;
    var k : OclAny := null;
    Sequence{s,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := Sequence{Sequence{0}->union(Sequence{ 1 }),Sequence{}} ;
    while (a->last()->compareTo(s)) < 0 do (    execute (((a.subrange(-k+1))->sum()) : a)) ;
    for i : (a)->reverse() do (    if (i->compareTo(s)) <= 0 then (
      execute ((i) : b) ;
    s := s - i
    ) else skip) ;
    execute ((b)->size())->display() ;
    execute (StringLib.sumStringsWithSeparator(((b)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display();
  operation data() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine()->trim();
  operation out(var : OclAny : Sequence(OclAny), end : String)
  pre: true post: true
  activity:
(args * (named_parameter (name var)))    if end->oclIsUndefined() then end := "\n" else skip;
(expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ' ') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name var)))))))) ))))))))) )))) + (expr (atom (name end))))))))) ))));
  operation L() : OclAny
  pre: true post: true
  activity:
    return (sp());
  operation sl() : OclAny
  pre: true post: true
  activity:
    return (ssp());
  operation sp() : OclAny
  pre: true post: true
  activity:
    return (data().split())->collect( _x | (OclType["int"])->apply(_x) );
  operation ssp() : OclAny
  pre: true post: true
  activity:
    return (data().split())->collect( _x | (OclType["String"])->apply(_x) );
  operation l1d(n : OclAny, val : int) : OclAny
  pre: true post: true
  activity:
    if val->oclIsUndefined() then val := 0 else skip;
    return Integer.subrange(0, n-1)->select(i | true)->collect(i | (val));
  operation l2d(n : OclAny, m : OclAny, val : int) : OclAny
  pre: true post: true
  activity:
    if val->oclIsUndefined() then val := 0 else skip;
    return Integer.subrange(0, m-1)->select(j | true)->collect(j | (l1d(n, val)));
  operation pmat(A : OclAny)
  pre: true post: true
  activity:
    for ele : A do (    execute ((argument * (test (logical_test (comparison (expr (atom (name ele))))))))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s,k=map(int,input().split())
if k>=32 :
    l=[0]
    for i in range(32):
        if s &(1<collect( _x | (OclType["int"])->apply(_x) ) ;
    if k >= 32 then  (
      var l : Sequence := Sequence{ 0 } ;
    for i : Integer.subrange(0, 32-1) do (    if MathLib.bitwiseAnd(s, (1 * (2->pow(i)))) then (
      execute ((1 * (2->pow(i))) : l)
    ) else skip) ;
    execute ((l)->size())->display() ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name l))))))))->display()
    )
    else (
      l := MatrixLib.elementwiseMult(Sequence{ 0 }, (k - 1))->union(Sequence{ 1 }) ;
    while (l->last()->compareTo(s)) <= 0 do (    execute (((l.subrange(-k+1))->sum()) : l)) ;
    var x : Sequence := Sequence{} ;
    for i : l(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do (    if i & (i->compareTo(s)) <= 0 then (
      s := s - i ;
    execute ((i) : x)
    ) else skip) ;
    if (x)->size() = 1 then (
      execute ((0) : x)
    ) else skip ;
    execute ((x)->size())->display() ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
import math
from sys import stdin,stdout
def get_ints_in_variables():
    return map(int,sys.stdin.readline().strip().split())
def get_int(): return int(input())
def get_ints_in_list(): return list(map(int,sys.stdin.readline().strip().split()))
def get_list_of_list(n): return[list(map(int,sys.stdin.readline().strip().split()))for _ in range(n)]
def get_string(): return sys.stdin.readline().strip()
def main():
    n,k=get_ints_in_variables()
    f=[]
    for _ in range(0,100000+1):
        f.append(0)
    f[1]=1
    i=1
    while True :
        if f[i]>n :
            break
        i+=1
        j=max(1,i-k)
        while j=1 :
        if f[j]<=n :
            n-=f[j]
            ans.append(f[j])
        j-=1
    print(len(ans))
    for i in range(0,len(ans)):
        print(ans[i],end=" ")
if __name__=="__main__" :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      main()
    ) else skip;
  operation get_ints_in_variables() : OclAny
  pre: true post: true
  activity:
    return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) );
  operation get_int() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation get_ints_in_list() : OclAny
  pre: true post: true
  activity:
    return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ));
  operation get_list_of_list(n : OclAny) : OclAny
  pre: true post: true
  activity:
    return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ))));
  operation get_string() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine()->trim();
  operation main()
  pre: true post: true
  activity:
    var k : OclAny := null;
    Sequence{n,k} := get_ints_in_variables() ;
    var f : Sequence := Sequence{} ;
    for _anon : Integer.subrange(0, 100000 + 1-1) do (    execute ((0) : f)) ;
    f[1+1] := 1 ;
    var i : int := 1 ;
    while true do (    if (f[i+1]->compareTo(n)) > 0 then (
      break
    ) else skip ;
    i := i + 1 ;
    var j : OclAny := Set{1, i - k}->max() ;
    while (j->compareTo(i)) < 0 do (    f[i+1] := f[i+1] + f[j+1] ;
    j := j + 1)) ;
    var ans : Sequence := Sequence{} ;
    execute ((0) : ans) ;
    j := i ;
    while j >= 1 do (    if (f[j+1]->compareTo(n)) <= 0 then (
      n := n - f[j+1] ;
    execute ((f[j+1]) : ans)
    ) else skip ;
    j := j - 1) ;
    execute ((ans)->size())->display() ;
    for i : Integer.subrange(0, (ans)->size()-1) do (    execute (ans[i+1])->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def bin_search(m,a):
    l=0
    h=len(a)-1
    while(l<=h):
        mid=(h+l)//2
        if(a[mid]==m):
            return a[mid]
        elif(a[mid]0):
        if(m in a):
            res.append(m)
            m=0
        else :
            k=bin_search(m,a)
            if(k==0):
                break
            res.append(k)
            m-=k
    res.append(0)
    res=res[: :-1]
    print(len(res))
    for i in range(len(res)):
        print(res[i],end=' ')
else :
    s=bin(m)
    s=s[: :-1]
    res=[]
    for i in range(len(s)-2):
        if(s[i]=='1'):
            res.append(1<select(i | true)->collect(i | (0)) ;
    execute ((1) : a) ;
    var i : int := 0 ;
    while ((a->last()->compareTo(m)) <= 0) do (    execute (((a.subrange(i+1, i + k))->sum()) : a) ;
    i := i + 1) ;
    var res : Sequence := Sequence{} ;
    execute ((a->front()->last()) : res) ;
    m := m - a->front()->last() ;
    while (m > 0) do (    if ((a)->includes(m)) then  (
      execute ((m) : res) ;
    m := 0
    )
    else (
      var k : OclAny := bin_search(m, a) ;
    if (k = 0) then (
      break
    ) else skip ;
    execute ((k) : res) ;
    m := m - k
      )) ;
    execute ((0) : res) ;
    res := res(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ;
    execute ((res)->size())->display() ;
    for i : Integer.subrange(0, (res)->size()-1) do (    execute (res[i+1])->display())
    )
    else (
      s := bin(m) ;
    s := s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ;
    res := Sequence{} ;
    for i : Integer.subrange(0, (s)->size() - 2-1) do (    if (s[i+1] = '1') then (
      execute ((1 * (2->pow(i))) : res)
    ) else skip) ;
    execute ((0) : res) ;
    execute ((res)->size())->display() ;
    for i : Integer.subrange(0, (res)->size()-1) do (    execute (res[i+1])->display())
      );
  operation bin_search(m : OclAny, a : OclAny) : OclAny
  pre: true post: true
  activity:
    var l : int := 0 ;
    var h : double := (a)->size() - 1 ;
    while ((l->compareTo(h)) <= 0) do (    var mid : int := (h + l) div 2 ;
    if (a[mid+1] = m) then  (
      return a[mid+1]
    )
    else (if ((a[mid+1]->compareTo(m)) < 0) then
   (
      l := mid + 1    
)
    else (
      h := mid - 1
      )    )
) ;
    return a[l - 1+1];
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def findLargest(N):
    largest='F'*N
    return largest ;
def findSmallest(N):
    smallest='1'+'0'*(N-1)
    return smallest ;
def printAns(largest):
    print("Largest: ",findLargest(largest));
    print("Smallest: ",findSmallest(largest));
if __name__=="__main__" :
    N=4 ;
    printAns(N);
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      N := 4; ;
    printAns(N);
    ) else skip;
  operation findLargest(N : OclAny)
  pre: true post: true
  activity:
    var largest : String := StringLib.nCopies('F', N) ;
    return largest;;
  operation findSmallest(N : OclAny)
  pre: true post: true
  activity:
    var smallest : String := '1' + StringLib.nCopies('0', (N - 1)) ;
    return smallest;;
  operation printAns(largest : OclAny)
  pre: true post: true
  activity:
    execute ("Largest: ")->display(); ;
    execute ("Smallest: ")->display();;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def dot(x,y):
    return(x.conjugate()*y).real
def is_orthogonal(x,y):
    if abs(dot(x,y))<1e-10 :
        return True
    return False
import sys
for line in sys.stdin :
    li=list(map(float,line.split()))
    p=[]
    for i in range(0,len(li),2):
        p.append(complex(li[i],li[i+1]))
    d1=p[1]-p[0]
    d2=p[3]-p[2]
    if is_orthogonal(d1,d2):
        print('YES')
    else :
        print('NO')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    for line : OclFile["System.in"] do (    var li : Sequence := ((line.split())->collect( _x | (OclType["double"])->apply(_x) )) ;
    var p : Sequence := Sequence{} ;
    for i : Integer.subrange(0, (li)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do (    execute ((complex(li[i+1], li[i + 1+1])) : p)) ;
    var d1 : double := p[1+1] - p->first() ;
    var d2 : double := p[3+1] - p[2+1] ;
    if is_orthogonal(d1, d2) then  (
      execute ('YES')->display()
    )
    else (
      execute ('NO')->display()
      ));
  operation dot(x : OclAny, y : OclAny) : OclAny
  pre: true post: true
  activity:
    return (x.conjugate() * y).real;
  operation is_orthogonal(x : OclAny, y : OclAny) : OclAny
  pre: true post: true
  activity:
    if (dot(x, y))->abs() < ("1e-10")->toReal() then (
      return true
    ) else skip ;
    return false;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
MAX=26
def printAnagramAndChanges(x,y):
    x=list(x)
    y=list(y)
    countx,county=[0]*MAX,[0]*MAX
    ctrx,ctry=[0]*MAX,[0]*MAX
    change=0
    l=len(x)
    for i in range(l):
        countx[ord(x[i])-ord('A')]+=1
        county[ord(y[i])-ord('A')]+=1
    for i in range(MAX):
        if countx[i]>county[i]:
            ctrx[i]+=(countx[i]-county[i])
        elif countx[i]0 :
                break
        if countx[ord(x[i])-ord('A')]==ctrx[ord(x[i])-ord('A')]or ord(x[i])-ord('A')>j :
            countx[ord(x[i])-ord('A')]-=1
            ctrx[ord(x[i])-ord('A')]-=1
            ctry[j]-=1
            x[i]=chr(ord('A')+j)
        else :
            countx[ord(x[i])-ord('A')]-=1
    print("Anagram :",''.join(x))
    print("Number of changes made :",change//2)
if __name__=="__main__" :
    x="CDBABC"
    y="ADCABD"
    printAnagramAndChanges(x,y)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var MAX : int := 26 ;
    skip ;
    if __name__ = "__main__" then (
      x := "CDBABC" ;
    y := "ADCABD" ;
    printAnagramAndChanges(x, y)
    ) else skip;
  operation printAnagramAndChanges(x : OclAny, y : OclAny)
  pre: true post: true
  activity:
    x := (x) ;
    y := (y) ;
    var countx : OclAny := null;
    var county : OclAny := null;
    Sequence{countx,county} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, MAX),MatrixLib.elementwiseMult(Sequence{ 0 }, MAX)} ;
    var ctrx : OclAny := null;
    var ctry : OclAny := null;
    Sequence{ctrx,ctry} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, MAX),MatrixLib.elementwiseMult(Sequence{ 0 }, MAX)} ;
    var change : int := 0 ;
    var l : int := (x)->size() ;
    for i : Integer.subrange(0, l-1) do (    countx[(x[i+1])->char2byte() - ('A')->char2byte()+1] := countx[(x[i+1])->char2byte() - ('A')->char2byte()+1] + 1 ;
    county[(y[i+1])->char2byte() - ('A')->char2byte()+1] := county[(y[i+1])->char2byte() - ('A')->char2byte()+1] + 1) ;
    for i : Integer.subrange(0, MAX-1) do (    if (countx[i+1]->compareTo(county[i+1])) > 0 then  (
      ctrx[i+1] := ctrx[i+1] + (countx[i+1] - county[i+1])
    )
    else (if (countx[i+1]->compareTo(county[i+1])) < 0 then
   (
      ctry[i+1] := ctry[i+1] + (county[i+1] - countx[i+1])    
)
 else skip) ;
    change := change + (county[i+1] - countx[i+1])->abs()) ;
    for i : Integer.subrange(0, l-1) do (    if ctrx[(x[i+1])->char2byte() - ('A')->char2byte()+1] = 0 then (
      continue
    ) else skip ;
    var j : int := 0 ;
    for j : Integer.subrange(0, MAX-1) do (    if ctry[j+1] > 0 then (
      break
    ) else skip) ;
    if countx[(x[i+1])->char2byte() - ('A')->char2byte()+1] = ctrx[(x[i+1])->char2byte() - ('A')->char2byte()+1] or ((x[i+1])->char2byte() - ('A')->char2byte()->compareTo(j)) > 0 then  (
      countx[(x[i+1])->char2byte() - ('A')->char2byte()+1] := countx[(x[i+1])->char2byte() - ('A')->char2byte()+1] - 1 ;
    ctrx[(x[i+1])->char2byte() - ('A')->char2byte()+1] := ctrx[(x[i+1])->char2byte() - ('A')->char2byte()+1] - 1 ;
    ctry[j+1] := ctry[j+1] - 1 ;
    x[i+1] := (('A')->char2byte() + j)->byte2char()
    )
    else (
      countx[(x[i+1])->char2byte() - ('A')->char2byte()+1] := countx[(x[i+1])->char2byte() - ('A')->char2byte()+1] - 1
      )) ;
    execute ("Anagram :")->display() ;
    execute ("Number of changes made :")->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def countSubArrays(arr,x,n):
    count=0 ;
    start=-1 ; end=-1 ;
    for i in range(n):
        if(arr[i]union(Sequence{5}->union(Sequence{7}->union(Sequence{8}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 9 })))))); ;
    x := 6; ;
    n := (arr)->size(); ;
    execute (countSubArrays(arr, x, n))->display();;
  operation countSubArrays(arr : OclAny, x : OclAny, n : OclAny)
  pre: true post: true
  activity:
    var count : int := 0; ;
    var start : int := -1;    var end : int := -1; ;
    for i : Integer.subrange(0, n-1) do (    if ((arr[i+1]->compareTo(x)) < 0) then  (
      if (start = -1) then  (
      start := i; ;
    end := i;
    )
    else (
      end := i;
      )
    )
    else (
      if (start /= -1 & end /= -1) then (
      var length : double := end - start + 1; ;
    count := count + ((length * (length + 1)) / 2);
    ) else skip ;
    start := -1; ;
    end := -1;
      )) ;
    if (start /= -1 & end /= -1) then (
      length := end - start + 1; ;
    count := count + ((length * (length + 1)) / 2);
    ) else skip ;
    return count;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    N,M=map(int,input().split())
    if N==0 : break
    ma=[0]*(M+1)
    for i in range(N):
        d,v=map(int,input().split())
        ma[d]=max(ma[d],v)
    print(sum(ma))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if N = 0 then (
      break
    ) else skip ;
    var ma : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (M + 1)) ;
    for i : Integer.subrange(0, N-1) do (    var d : OclAny := null;
    var v : OclAny := null;
    Sequence{d,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    ma[d+1] := Set{ma[d+1], v}->max()) ;
    execute ((ma)->sum())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while 1 :
    n,m=map(int,input().split())
    if n==m==0 : break
    s=set()
    c=0
    for d,v in sorted([list(map(int,input().split()))for i in range(n)],key=lambda x :-x[1]):
        if d in s : continue
        c+=v
        s.add(d)
        if len(s)>=m :
            break
    print(c)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while 1 do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if n = m & (m == 0) then (
      break
    ) else skip ;
    var s : Set := Set{}->union(()) ;
    var c : int := 0 ;
    for _tuple : Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))->sortedBy($x | (lambda x : OclAny in (-x[1+1]))->apply($x)) do (var _indx : int := 1;
      var d : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var v : OclAny := _tuple->at(_indx);
      if (s)->includes(d) then (
      continue
    ) else skip ;
    c := c + v ;
    execute ((d) : s) ;
    if ((s)->size()->compareTo(m)) >= 0 then (
      break
    ) else skip) ;
    execute (c)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    line=input()
    if line=="0 0" :
        break
    stock,max_difficulty=map(int,line.split(" "))
    max_recommend_list=[0 for _ in range(max_difficulty)]
    for i in range(stock):
        difficulty,recommend=map(int,input().split(" "))
        max_recommend_list[difficulty-1]=max(max_recommend_list[difficulty-1],recommend)
    print(sum(max_recommend_list))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    var line : String := (OclFile["System.in"]).readLine() ;
    if line = "0 0" then (
      break
    ) else skip ;
    var stock : OclAny := null;
    var max_difficulty : OclAny := null;
    Sequence{stock,max_difficulty} := (line.split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ;
    var max_recommend_list : Sequence := Integer.subrange(0, max_difficulty-1)->select(_anon | true)->collect(_anon | (0)) ;
    for i : Integer.subrange(0, stock-1) do (    var difficulty : OclAny := null;
    var recommend : OclAny := null;
    Sequence{difficulty,recommend} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ;
    max_recommend_list[difficulty - 1+1] := Set{max_recommend_list[difficulty - 1+1], recommend}->max()) ;
    execute ((max_recommend_list)->sum())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m=list(map(int,input().split()))
i=1
ans=0
while i*i<=m :
    if m % i==0 :
        if n<=m/i :
            ans=max(ans,i)
        if n<=i :
            ans=max(ans,m//i)
    i+=1
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var i : int := 1 ;
    var ans : int := 0 ;
    while (i * i->compareTo(m)) <= 0 do (    if m mod i = 0 then (
      if (n->compareTo(m / i)) <= 0 then (
      ans := Set{ans, i}->max()
    ) else skip ;
    if (n->compareTo(i)) <= 0 then (
      ans := Set{ans, m div i}->max()
    ) else skip
    ) else skip ;
    i := i + 1) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
ans2=[]
while(1):
    tip=[]
    tmp=[]
    ans=0
    n,m=map(int,input().split())
    if n==0 and m==0 :
        break
    else :
        for i in range(n):
            d,v=map(int,input().split())
            tip.append([d,v])
        tip=sorted(tip,key=lambda x : x[1])
        tip.reverse()
        for i in range(n):
            if tip[i][0]in tmp :
                pass
            else :
                ans+=tip[i][1]
                m+=1
                tmp.append(tip[i][0])
        ans2.append(ans)
for i in ans2 :
    print(i)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var ans2 : Sequence := Sequence{} ;
    while (1) do (    var tip : Sequence := Sequence{} ;
    var tmp : Sequence := Sequence{} ;
    var ans : int := 0 ;
    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if n = 0 & m = 0 then  (
      break
    )
    else (
      for i : Integer.subrange(0, n-1) do (    var d : OclAny := null;
    var v : OclAny := null;
    Sequence{d,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute ((Sequence{d}->union(Sequence{ v })) : tip)) ;
    tip := tip->sortedBy($x | (lambda x : OclAny in (x[1+1]))->apply($x)) ;
    tip := tip->reverse() ;
    for i : Integer.subrange(0, n-1) do (    if (tmp)->includes(tip[i+1]->first()) then  (
      skip
    )
    else (
      ans := ans + tip[i+1][1+1] ;
    m := m + 1 ;
    execute ((tip[i+1]->first()) : tmp)
      )) ;
    execute ((ans) : ans2)
      )) ;
    for i : ans2 do (    execute (i)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def solve(n,m):
    l=[]
    for i in range(n):
        d,v=map(int,input().split())
        l.append((d,v))
    l.sort(reverse=True)
    now=-1
    count=0
    for i in l :
        if now==i[0]:
            continue
        else :
            count+=i[1]
            now=i[0]
    print(count)
while True :
    n,m=map(int,input().split())
    if n==m==0 :
        break
    solve(n,m)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    while true do (    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if n = m & (m == 0) then (
      break
    ) else skip ;
    solve(n, m));
  operation solve(n : OclAny, m : OclAny)
  pre: true post: true
  activity:
    var l : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    var d : OclAny := null;
    var v : OclAny := null;
    Sequence{d,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute ((Sequence{d, v}) : l)) ;
    l := l->sort() ;
    var now : int := -1 ;
    var count : int := 0 ;
    for i : l do (    if now = i->first() then  (
      continue
    )
    else (
      count := count + i[1+1] ;
    now := i->first()
      )) ;
    execute (count)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def Maximum_xor_Triplet(n,a):
    s=set()
    for i in range(0,n):
        for j in range(i,n):
            s.add(a[i]^ a[j])
    ans=0
    for i in s :
        for j in range(0,n):
            ans=max(ans,i ^ a[j])
    print(ans)
if __name__=="__main__" :
    a=[1,3,8,15]
    n=len(a)
    Maximum_xor_Triplet(n,a)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      a := Sequence{1}->union(Sequence{3}->union(Sequence{8}->union(Sequence{ 15 }))) ;
    n := (a)->size() ;
    Maximum_xor_Triplet(n, a)
    ) else skip;
  operation Maximum_xor_Triplet(n : OclAny, a : OclAny)
  pre: true post: true
  activity:
    var s : Set := Set{}->union(()) ;
    for i : Integer.subrange(0, n-1) do (    for j : Integer.subrange(i, n-1) do (    execute ((MathLib.bitwiseXor(a[i+1], a[j+1])) : s))) ;
    var ans : int := 0 ;
    for i : s do (    for j : Integer.subrange(0, n-1) do (    ans := Set{ans, MathLib.bitwiseXor(i, a[j+1])}->max())) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def judge_aux(t,k):
    found=False
    for i in range(3):
        if t[i]==list(k*3):
            found=True
            break
    if found :
        return(k)
    found=False
    for j in range(3):
        if t[0][j]==t[1][j]==t[2][j]==k :
            found=True
            break
    if found :
        return(k)
    if t[0][0]==t[1][1]==t[2][2]==k :
        return(k)
    if t[0][2]==t[1][1]==t[2][0]==k :
        return(k)
def judge(t):
    if judge_aux(t,"o"):
        return("o")
    elif judge_aux(t,"x"):
        return("x")
    else :
        return("d")
while True :
    try :
        s=list(input().strip())
        t=[[s[3*i+j]for j in range(3)]for i in range(3)]
        print(judge(t))
    except EOFError :
        break
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    while true do (    try (    var s : Sequence := (input()->trim()) ;
    t := Integer.subrange(0, 3-1)->select(i | true)->collect(i | (Integer.subrange(0, 3-1)->select(j | true)->collect(j | (s[3 * i + j+1])))) ;
    execute (judge(t))->display())
(except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))));
  operation judge_aux(t : OclAny, k : OclAny) : OclAny
  pre: true post: true
  activity:
    var found : boolean := false ;
    for i : Integer.subrange(0, 3-1) do (    if t[i+1] = (k * 3) then (
      found := true ;
    break
    ) else skip) ;
    if found then (
      return (k)
    ) else skip ;
    found := false ;
    for j : Integer.subrange(0, 3-1) do (    if t->first()[j+1] = t[1+1][j+1] & (t[1+1][j+1] == t[2+1][j+1]) & (t[2+1][j+1] == k) then (
      found := true ;
    break
    ) else skip) ;
    if found then (
      return (k)
    ) else skip ;
    if t->first()->first() = t[1+1][1+1] & (t[1+1][1+1] == t[2+1][2+1]) & (t[2+1][2+1] == k) then (
      return (k)
    ) else skip ;
    if t->first()[2+1] = t[1+1][1+1] & (t[1+1][1+1] == t[2+1]->first()) & (t[2+1]->first() == k) then (
      return (k)
    ) else skip;
  operation judge(t : OclAny) : OclAny
  pre: true post: true
  activity:
    if judge_aux(t, "o") then  (
      return ("o")
    )
    else (if judge_aux(t, "x") then
   (
      return ("x")    
)
    else (
      return ("d")
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys,math,os,bisect
PYDEV=os.environ.get('PYDEV')
if PYDEV=="True" :
    sys.stdin=open("sample-input.txt","rt")
for line in sys.stdin :
    x1,y1,x2,y2,x3,y3,x4,y4=[float(_)for _ in line.split()]
    scalar_product=(x2-x1)*(x4-x3)+(y2-y1)*(y4-y3)
    print("YES" if abs(scalar_product)<1e-10 else "NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var PYDEV : OclAny := os.environ.get('PYDEV') ;
    if PYDEV = "True" then (
      OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt"))
    ) else skip ;
    for line : OclFile["System.in"] do (    var x1 : OclAny := null;
    var y1 : OclAny := null;
    var x2 : OclAny := null;
    var y2 : OclAny := null;
    var x3 : OclAny := null;
    var y3 : OclAny := null;
    var x4 : OclAny := null;
    var y4 : OclAny := null;
    Sequence{x1,y1,x2,y2,x3,y3,x4,y4} := line.split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toReal())) ;
    var scalar_product : double := (x2 - x1) * (x4 - x3) + (y2 - y1) * (y4 - y3) ;
    execute (if (scalar_product)->abs() < ("1e-10")->toReal() then "YES" else "NO" endif)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def ttt(o):
    if(o[0]==o[4]==o[8]or o[2]==o[4]==o[6])and o[4]!="s" :
        return o[4]
    for i in range(3):
        if o[i*3]!="s" and o[i*3]==o[i*3+1]==o[i*3+2]:
            return o[i*3]
        if o[i]!="s" and o[i]==o[i+3]==o[i+6]:
            return o[i]
    return "d"
[print(ttt(j))for j in[i for i in sys.stdin]]
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
;
  operation ttt(o : OclAny) : OclAny
  pre: true post: true
  activity:
    if (o->first() = o[4+1] & (o[4+1] == o[8+1]) or o[2+1] = o[4+1] & (o[4+1] == o[6+1])) & o[4+1] /= "s" then (
      return o[4+1]
    ) else skip ;
    for i : Integer.subrange(0, 3-1) do (    if o[i * 3+1] /= "s" & o[i * 3+1] = o[i * 3 + 1+1] & (o[i * 3 + 1+1] == o[i * 3 + 2+1]) then (
      return o[i * 3+1]
    ) else skip ;
    if o[i+1] /= "s" & o[i+1] = o[i + 3+1] & (o[i + 3+1] == o[i + 6+1]) then (
      return o[i+1]
    ) else skip) ;
    return "d";
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from __future__ import(division,absolute_import,print_function,unicode_literals)
from sys import stdin
condition=('ooo','xxx')
for line in stdin :
    if line[0 : 3]in condition :
        win=line[0]
    elif line[3 : 6]in condition :
        win=line[3]
    elif line[6 : 9]in condition :
        win=line[6]
    elif line[0 : 9 : 3]in condition :
        win=line[0]
    elif line[1 : 9 : 3]in condition :
        win=line[1]
    elif line[2 : 9 : 3]in condition :
        win=line[2]
    elif line[0 : 9 : 4]in condition :
        win=line[0]
    elif line[2 : 7 : 2]in condition :
        win=line[2]
    else :
        win='d'
    print(win)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var condition : OclAny := Sequence{'ooo', 'xxx'} ;
    for line : stdin do (    if (condition)->includes(line.subrange(0+1, 3)) then  (
      var win : OclAny := line->first()
    )
    else (if (condition)->includes(line.subrange(3+1, 6)) then
   (
      win := line[3+1]    
)
    else (if (condition)->includes(line.subrange(6+1, 9)) then
   (
      win := line[6+1]    
)
    else (if (condition)->includes(line(subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))) : (test (logical_test (comparison (expr (atom (number (integer 9))))))) (sliceop : (test (logical_test (comparison (expr (atom (number (integer 3)))))))))) then
   (
      win := line->first()    
)
    else (if (condition)->includes(line(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (test (logical_test (comparison (expr (atom (number (integer 9))))))) (sliceop : (test (logical_test (comparison (expr (atom (number (integer 3)))))))))) then
   (
      win := line[1+1]    
)
    else (if (condition)->includes(line(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (test (logical_test (comparison (expr (atom (number (integer 9))))))) (sliceop : (test (logical_test (comparison (expr (atom (number (integer 3)))))))))) then
   (
      win := line[2+1]    
)
    else (if (condition)->includes(line(subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))) : (test (logical_test (comparison (expr (atom (number (integer 9))))))) (sliceop : (test (logical_test (comparison (expr (atom (number (integer 4)))))))))) then
   (
      win := line->first()    
)
    else (if (condition)->includes(line(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (test (logical_test (comparison (expr (atom (number (integer 7))))))) (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) then
   (
      win := line[2+1]    
)
    else (
      win := 'd'
      )    )
    )
    )
    )
    )
    )
    )
 ;
    execute (win)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
table=[['']*3 for i in range(3)]
def ans():
    r=0
    c=1
    while(r<3):
        char=table[r][0]
        if char!='s' :
            c=1
            while(c<3):
                if table[r][c]!=char :
                    break
                if table[r][c]==char and c+1>=3 :
                    return char
                c+=1
        r+=1
    r=1
    c=0
    while(c<3):
        char=table[0][c]
        if char!='s' :
            r=1
            while(r<3):
                if table[r][c]!=char :
                    break
                if table[r][c]==char and r+1>=3 :
                    return char
                r+=1
        c+=1
    char=table[1][1]
    if char!='s' :
        if(table[0][0]==char and table[2][2]==char)or(table[0][2]==char and table[2][0]==char):
            return char
    return 'd'
while(1):
    try :
        s=input()
        for i in range(0,3):
            for j in range(0,3):
                table[i][j]=s[(i*3)+j]
        print(ans())
    except :
        break
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var table : Sequence := Integer.subrange(0, 3-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ '' }, 3))) ;
    skip ;
    while (1) do (    try (    var s : String := (OclFile["System.in"]).readLine() ;
    for i : Integer.subrange(0, 3-1) do (    for j : Integer.subrange(0, 3-1) do (    table[i+1][j+1] := s[(i * 3) + j+1])) ;
    execute (ans())->display())
     catch (_e : OclException) do (    break)
);
  operation ans() : OclAny
  pre: true post: true
  activity:
    var r : int := 0 ;
    var c : int := 1 ;
    while (r < 3) do (    var char : OclAny := table[r+1]->first() ;
    if char /= 's' then (
      c := 1 ;
    while (c < 3) do (    if table[r+1][c+1] /= char then (
      break
    ) else skip ;
    if table[r+1][c+1] = char & c + 1 >= 3 then (
      return char
    ) else skip ;
    c := c + 1)
    ) else skip ;
    r := r + 1) ;
    r := 1 ;
    c := 0 ;
    while (c < 3) do (    char := table->first()[c+1] ;
    if char /= 's' then (
      r := 1 ;
    while (r < 3) do (    if table[r+1][c+1] /= char then (
      break
    ) else skip ;
    if table[r+1][c+1] = char & r + 1 >= 3 then (
      return char
    ) else skip ;
    r := r + 1)
    ) else skip ;
    c := c + 1) ;
    char := table[1+1][1+1] ;
    if char /= 's' then (
      if (table->first()->first() = char & table[2+1][2+1] = char) or (table->first()[2+1] = char & table[2+1]->first() = char) then (
      return char
    ) else skip
    ) else skip ;
    return 'd';
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
for e in sys.stdin :
    d=[{'o' : 1,'x' :-1,'s' : 0}[s]for s in e.strip()]
    a=[sum(s)for s in(d[0 : 3],d[3 : 6],d[6 :],d[0 : : 3],d[1 : : 3],d[2 : : 3],d[0 : : 4],d[2 : 8 : 2])]
    print('dxo'[(-3 in a)+(3 in a)*2])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    for e : OclFile["System.in"] do (    var d : Sequence := e->trim()->select(s | true)->collect(s | (Map{ 'o' |-> 1 }->union(Map{ 'x' |-> -1 }->union(Map{ 's' |-> 0 }))[s+1])) ;
    var a : Sequence := Sequence{d.subrange(0+1, 3), d.subrange(3+1, 6), d.subrange(6+1), d(subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 3))))))))), d(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 3))))))))), d(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 3))))))))), d(subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 4))))))))), d(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (test (logical_test (comparison (expr (atom (number (integer 8))))))) (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))}->select(s | true)->collect(s | ((s)->sum())) ;
    execute ('dxo'->select(((a)->includes(-3)) + ((a)->includes(3)) * 2))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math ;
def reverseNum(n):
    rev=0 ;
    while(n):
        rem=n % 10 ;
        rev=(rev*10)+rem ;
        n=int(n/10);
    return rev ;
def isPalindrom(num):
    return num==reverseNum(num);
def nthPalindrome(n,k):
    num=math.pow(10,k-1);
    while(True):
        if(isPalindrom(num)):
            n-=1 ;
        if(not n):
            break ;
        num+=1 ;
    return int(num);
n=6 ;
k=5 ;
print(n,"th palindrome of",k,"digit=",nthPalindrome(n,k));
n=10 ;
k=6 ;
print(n,"th palindrome of",k,"digit=",nthPalindrome(n,k));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip; ;
    skip ;
    skip ;
    skip ;
    n := 6; ;
    k := 5; ;
    execute (n)->display(); ;
    n := 10; ;
    k := 6; ;
    execute (n)->display();;
  operation reverseNum(n : OclAny)
  pre: true post: true
  activity:
    var rev : int := 0; ;
    while (n) do (    var rem : int := n mod 10; ;
    rev := (rev * 10) + rem; ;
    n := ("" + ((n / 10)))->toInteger();) ;
    return rev;;
  operation isPalindrom(num : OclAny)
  pre: true post: true
  activity:
    return num = reverseNum(num);;
  operation nthPalindrome(n : OclAny, k : OclAny)
  pre: true post: true
  activity:
    num := (10)->pow(k - 1); ;
    while (true) do (    if (isPalindrom(num)) then (
      n := n - 1;
    ) else skip ;
    if (not(n)) then (
      break;
    ) else skip ;
    num := num + 1;) ;
    return ("" + ((num)))->toInteger();;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
if n==1 :
    print(''.join(sorted(input())))
else :
    dic={}
    s=input()
    for i in s :
        dic[i]=s.count(i)
    for i in range(n-1):
        s=input()
        for j in dic.keys():
            dic[j]=min(dic[j],s.count(j))
    s=''
    for i in dic.keys():
        s+=i*dic[i]
    print(''.join(sorted(s)))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 1 then  (
      execute (StringLib.sumStringsWithSeparator(((OclFile["System.in"]).readLine()->sort()), ''))->display()
    )
    else (
      var dic : OclAny := Set{} ;
    var s : String := (OclFile["System.in"]).readLine() ;
    for i : s->characters() do (    dic[i+1] := s->count(i)) ;
    for i : Integer.subrange(0, n - 1-1) do (    s := (OclFile["System.in"]).readLine() ;
    for j : dic.keys() do (    dic[j+1] := Set{dic[j+1], s->count(j)}->min())) ;
    s := '' ;
    for i : dic.keys() do (    s := s + i * dic[i+1]) ;
    execute (StringLib.sumStringsWithSeparator((s->sort()), ''))->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
i=0
res=0
while k=m):
    res=i
else :
    res=-1
print(res)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    var k : OclAny := null;
    Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    a := a->sort() ;
    var i : int := 0 ;
    var res : int := 0 ;
    while (k->compareTo(m)) < 0 & (i->compareTo(n)) < 0 do (    k := k + a[i+1] - 1 ;
    i := i + 1) ;
    if ((k->compareTo(m)) >= 0) then  (
      res := i
    )
    else (
      res := -1
      ) ;
    execute (res)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
alphabets=[chr(i)for i in range(97,97+26)]
maps=[]
for _ in range(n):
    s=input()
    new_map=dict(zip(alphabets,[0 for _ in range(26)]))
    for si in s :
        new_map[si]+=1
    maps.append(new_map)
ans_map=dict(zip(alphabets,[10**9 for _ in range(26)]))
for m in maps :
    for k,v in m.items():
        ans_map[k]=min(ans_map[k],v)
ans=""
for k in list(sorted(ans_map.keys())):
    ans+=k*ans_map[k]
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var alphabets : Sequence := Integer.subrange(97, 97 + 26-1)->select(i | true)->collect(i | ((i)->byte2char())) ;
    var maps : Sequence := Sequence{} ;
    for _anon : Integer.subrange(0, n-1) do (    var s : String := (OclFile["System.in"]).readLine() ;
    var new_map : Map := ((expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name alphabets))))))) , (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 26))))))))) )))))))) ]))))))) ))))) ;
    for si : s->characters() do (    new_map[si+1] := new_map[si+1] + 1) ;
    execute ((new_map) : maps)) ;
    var ans_map : Map := ((expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name alphabets))))))) , (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 10)))) ** (expr (atom (number (integer 9)))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 26))))))))) )))))))) ]))))))) ))))) ;
    for m : maps do (    for _tuple : m->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1;
      var k : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var v : OclAny := _tuple->at(_indx);
      ans_map[k+1] := Set{ans_map[k+1], v}->min())) ;
    var ans : String := "" ;
    for k : (ans_map.keys()->sort()) do (    ans := ans + k * ans_map[k+1]) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def seki(array1 : list,array2 : list):
    results=[]
    for a in array1 :
        if a in array2 :
            results.append(a)
            array2.remove(a)
    return results
def main():
    n=int(input())
    sentences=[]
    while True :
        try :
            sentences.append(sorted(input(),reverse=True))
        except EOFError :
            break
    pocket=sentences[0].copy()
    for n,sentence in enumerate(sentences):
        pocket=seki(pocket,sentence)
    print(''.join(sorted(pocket)))
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation seki(array1 : Sequence(OclAny), array2 : Sequence(OclAny)) : OclAny
  pre: true post: true
  activity:
    var results : Sequence := Sequence{} ;
    for a : array1 do (    if (array2)->includes(a) then (
      execute ((a) : results) ;
    execute ((a) /: array2)
    ) else skip) ;
    return results;
  operation main()
  pre: true post: true
  activity:
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var sentences : Sequence := Sequence{} ;
    while true do (    try (    execute (((OclFile["System.in"]).readLine()->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True))))))))) : sentences))
(except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))) ;
    var pocket : OclAny := sentences->first()->copy() ;
    for _tuple : Integer.subrange(1, (sentences)->size())->collect( _indx | Sequence{_indx-1, (sentences)->at(_indx)} ) do (var _indx : int := 1;
      var n : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var sentence : OclAny := _tuple->at(_indx);
      pocket := seki(pocket, sentence)) ;
    execute (StringLib.sumStringsWithSeparator((pocket->sort()), ''))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import Counter
n=int(input())
a=[dict(Counter(list(input())))for i in range(n)]
d=a[0]
for i in a[1 :]:
    dl=[]
    for j in d :
        if j in list(i):
            d[j]=min(d[j],i[j])
        else :
            dl.append(j)
    for j in set(dl):
        del d[j]
c=[]
for i in list(d):
    c.append(i*d[i])
c.sort()
m=""
for i in c :
    m=m+i
print(m)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((expr (atom (name Counter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))) ))))))) ;
    var d : OclAny := a->first() ;
    for i : a->tail() do (    var dl : Sequence := Sequence{} ;
    for j : d do (    if ((i))->includes(j) then  (
      d[j+1] := Set{d[j+1], i[j+1]}->min()
    )
    else (
      execute ((j) : dl)
      )) ;
    for j : Set{}->union((dl)) do (    execute (d[j+1])->isDeleted())) ;
    var c : Sequence := Sequence{} ;
    for i : (d) do (    execute ((i * d[i+1]) : c)) ;
    c := c->sort() ;
    var m : String := "" ;
    for i : c do (    m := m + i) ;
    execute (m)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def fizz_buzz():
    c=1
    while True :
        res=''
        if c % 3==0 :
            res=res+'Fizz'
        if c % 5==0 :
            res=res+'Buzz'
        if res=='' :
            yield str(c)
        else :
            yield res
        c+=1
while True :
    m,n=map(int,input().split())
    if m==0 : break
    player=list(range(m))
    p=0
    fb=fizz_buzz()
    for i in range(n):
        inp=input()
        if len(player)>1 :
            if inp!=next(fb):
                del player[p]
                p=p % len(player)
            else :
                p=(p+1)% len(player)
    result=str(player[0]+1)
    if len(player)>1 :
        for pi in player[1 :]:
            result+=' '+str(pi+1)
    print(result)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    while true do (    var m : OclAny := null;
    var n : OclAny := null;
    Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if m = 0 then (
      break
    ) else skip ;
    var player : Sequence := (Integer.subrange(0, m-1)) ;
    var p : int := 0 ;
    var fb : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.fizz_buzz(_i)) ;
    for i : Integer.subrange(0, n-1) do (    var inp : String := (OclFile["System.in"]).readLine() ;
    if (player)->size() > 1 then (
      if inp /= (fb).next() then  (
      execute (player[p+1])->isDeleted() ;
    p := p mod (player)->size()
    )
    else (
      p := (p + 1) mod (player)->size()
      )
    ) else skip) ;
    var result : String := ("" + ((player->first() + 1))) ;
    if (player)->size() > 1 then (
      for pi : player->tail() do (    result := result + ' ' + ("" + ((pi + 1))))
    ) else skip ;
    execute (result)->display());
  operation fizz_buzz(_position_ : int) : OclAny
  pre: true post: true
  activity:
    var _yieldCount_ : int := 0;
    var c : int := 1 ;
    while true do (    var res : String := '' ;
    if c mod 3 = 0 then (
      res := res + 'Fizz'
    ) else skip ;
    if c mod 5 = 0 then (
      res := res + 'Buzz'
    ) else skip ;
    if res = '' then  (
      if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return ("" + ((c)))
    )
    else (
      if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return res
      ) ;
    c := c + 1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=int(input())
str_list=[str(input())for i in range(a)]
x=[]
for i in range(len(str_list[0])):
    check=True ;
    for j in range(1,a):
        if str_list[0][i]in str_list[j]:
            str_list[j]=str_list[j].replace(str_list[0][i],'',1);
        else :
            check=False ;
    if check :
        x.append(str_list[0][i])
if len(x)>0 :
    print(''.join(sorted(x)))
else :
    print('')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var str_list : Sequence := Integer.subrange(0, a-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine()))))) ;
    var x : Sequence := Sequence{} ;
    for i : Integer.subrange(0, (str_list->first())->size()-1) do (    var check : boolean := true; ;
    for j : Integer.subrange(1, a-1) do (    if (str_list[j+1])->includes(str_list->first()[i+1]) then  (
      str_list[j+1] := str_list[j+1].replace(str_list->first()[i+1], '', 1);
    )
    else (
      check := false;
      )) ;
    if check then (
      execute ((str_list->first()[i+1]) : x)
    ) else skip) ;
    if (x)->size() > 0 then  (
      execute (StringLib.sumStringsWithSeparator((x->sort()), ''))->display()
    )
    else (
      execute ('')->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def getFinalElement(n):
    finalNum=2
    while finalNum*2<=n :
        finalNum*=2
    return finalNum
if __name__=="__main__" :
    N=12
    print(getFinalElement(N))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      var N : int := 12 ;
    execute (getFinalElement(N))->display()
    ) else skip;
  operation getFinalElement(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var finalNum : int := 2 ;
    while (finalNum * 2->compareTo(n)) <= 0 do (    finalNum := finalNum * 2) ;
    return finalNum;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
def findBucketNo(p):
    return math.ceil((math.sqrt(8*p+1)-1)/2)
p=10
print(findBucketNo(p))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    p := 10 ;
    execute (findBucketNo(p))->display();
  operation findBucketNo(p : OclAny) : OclAny
  pre: true post: true
  activity:
    return (((8 * p + 1)->sqrt() - 1) / 2)->ceil();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def printPattern(N):
    for i in range(1,N+1):
        print(i-1 if i % 2==0 else i+1,end=" ")
N=10
printPattern(N)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    N := 10 ;
    printPattern(N);
  operation printPattern(N : OclAny)
  pre: true post: true
  activity:
    for i : Integer.subrange(1, N + 1-1) do (    execute (if i mod 2 = 0 then i - 1 else i + 1 endif)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def maxDiff(arr,arr_size):
    max_diff=arr[1]-arr[0]
    for i in range(0,arr_size):
        for j in range(i+1,arr_size):
            if(arr[j]-arr[i]>max_diff):
                max_diff=arr[j]-arr[i]
    return max_diff
arr=[1,2,90,10,110]
size=len(arr)
print("Maximum difference is",maxDiff(arr,size))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    arr := Sequence{1}->union(Sequence{2}->union(Sequence{90}->union(Sequence{10}->union(Sequence{ 110 })))) ;
    var size : int := (arr)->size() ;
    execute ("Maximum difference is")->display();
  operation maxDiff(arr : OclAny, arr_size : OclAny) : OclAny
  pre: true post: true
  activity:
    var max_diff : double := arr[1+1] - arr->first() ;
    for i : Integer.subrange(0, arr_size-1) do (    for j : Integer.subrange(i + 1, arr_size-1) do (    if ((arr[j+1] - arr[i+1]->compareTo(max_diff)) > 0) then (
      max_diff := arr[j+1] - arr[i+1]
    ) else skip)) ;
    return max_diff;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    a,b=map(int,input().split())
    print("Yes" if a*b % 2==1 else "No")
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (if a * b mod 2 = 1 then "Yes" else "No" endif)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import exit,setrecursionlimit,stderr
from functools import reduce
from itertools import*
from collections import defaultdict
from bisect import bisect
def read():
    return int(input())
def reads():
    return[int(x)for x in input().split()]
A,B=reads()
if A*B % 2==0 :
    print("No")
else :
    print("Yes")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var A : OclAny := null;
    var B : OclAny := null;
    Sequence{A,B} := reads() ;
    if A * B mod 2 = 0 then  (
      execute ("No")->display()
    )
    else (
      execute ("Yes")->display()
      );
  operation read() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation reads() : OclAny
  pre: true post: true
  activity:
    return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
n,m,k=map(int,input().split())
w=sorted(map(int,input().split()),reverse=True)
c=0
while m>k :
    k+=w[c]-1
    c+=1
    if c==len(w):
        break
if m>k :
    print(-1)
else :
    print(c)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    var n : OclAny := null;
    var m : OclAny := null;
    var k : OclAny := null;
    Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var w : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ;
    var c : int := 0 ;
    while (m->compareTo(k)) > 0 do (    k := k + w[c+1] - 1 ;
    c := c + 1 ;
    if c = (w)->size() then (
      break
    ) else skip) ;
    if (m->compareTo(k)) > 0 then  (
      execute (-1)->display()
    )
    else (
      execute (c)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
f=lambda : map(int,input().split())
n,m=f()
if n*m & 1 :
    print('Yes')
else :
    print('No')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var f : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := f->apply() ;
    if MathLib.bitwiseAnd(n * m, 1) then  (
      execute ('Yes')->display()
    )
    else (
      execute ('No')->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
print("No" if eval(input().replace(" ","*"))% 2==0 else "Yes")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     execute (if input().replace(" ", "*") mod 2 = 0 then "No" else "Yes" endif)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while 1 :
    m,n=map(int,input().split())
    if m==0 : break
    a,i,c=list(range(1,m+1)),0,0
    while icollect( _x | (OclType["int"])->apply(_x) ) ;
    if m = 0 then (
      break
    ) else skip ;
    var a : OclAny := null;
    var i : OclAny := null;
    var c : OclAny := null;
    Sequence{a,i,c} := Sequence{(Integer.subrange(1, m + 1-1)),0,0} ;
    while (i->compareTo(n)) < 0 do (    i := i + 1 ;
    var b : OclAny := null;
    var f : OclAny := null;
    Sequence{b,f} := Sequence{(OclFile["System.in"]).readLine(),0} ;
    if m < 2 then (
      continue
    ) else skip ;
    if i mod 15 = 0 then  (
      if b /= 'FizzBuzz' then (
      execute (a[c+1])->isDeleted() ;
    var f : int := 1
    ) else skip
    )
    else (if i mod 5 = 0 then
   (
      if b /= 'Buzz' then (
      execute (a[c+1])->isDeleted() ;
    f := 1
    ) else skip    
)
    else (if i mod 3 = 0 then
   (
      if b /= 'Fizz' then (
      execute (a[c+1])->isDeleted() ;
    f := 1
    ) else skip    
)
    else (if b /= ("" + ((i))) then
   (
      execute (a[c+1])->isDeleted() ;
    f := 1    
)
    else skip    )
    )
    )
 ;
    if f then  (
      m := m - 1
    )
    else (
      c := c + 1
      ) ;
    c := c mod m) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
num_list=list(map(int,(input().split())))
a=num_list[0]
b=num_list[1]
if a!=2 :
    if b!=2 :
        print("Yes")
    else :
        print("No")
else :
    print("No")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var num_list : Sequence := (((input().split()))->collect( _x | (OclType["int"])->apply(_x) )) ;
    var a : OclAny := num_list->first() ;
    var b : OclAny := num_list[1+1] ;
    if a /= 2 then  (
      if b /= 2 then  (
      execute ("Yes")->display()
    )
    else (
      execute ("No")->display()
      )
    )
    else (
      execute ("No")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def CntDivbyX(arr,n,x):
    number=0
    count=0
    for i in range(0,n):
        number=(number*2+arr[i])% x
        if number==0 :
            count+=1
    return count
arr=[1,0,1,0,1,1,0]
n=7
x=2
print(CntDivbyX(arr,n,x))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    arr := Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 0 })))))) ;
    n := 7 ;
    x := 2 ;
    execute (CntDivbyX(arr, n, x))->display();
  operation CntDivbyX(arr : OclAny, n : OclAny, x : OclAny) : OclAny
  pre: true post: true
  activity:
    var number : int := 0 ;
    var count : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    number := (number * 2 + arr[i+1]) mod x ;
    if number = 0 then (
      count := count + 1
    ) else skip) ;
    return count;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
status=[0]*100000 ;
def countSteps(val,n):
    sol=0 ;
    vec=[1,0];
    status[0]=-1 ;
    for i in range(n):
        status[i]=0 ;
        while(len(vec)>0 and val[vec[len(vec)-1]]>=val[i]):
            status[i]=max(status[i],status[len(vec)-1]+1);
            vec.pop();
        if(len(vec)==0):
            status[i]=-1 ;
        vec.append(i);
        sol=max(sol,status[i]+1);
    return sol ;
if __name__=="__main__" :
    val=[6,5,8,4,7,10,9];
    n=len(val);
    print(countSteps(val,n));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var status : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100000); ;
    skip ;
    if __name__ = "__main__" then (
      val := Sequence{6}->union(Sequence{5}->union(Sequence{8}->union(Sequence{4}->union(Sequence{7}->union(Sequence{10}->union(Sequence{ 9 })))))); ;
    n := (val)->size(); ;
    execute (countSteps(val, n))->display();
    ) else skip;
  operation countSteps(val : OclAny, n : OclAny)
  pre: true post: true
  activity:
    var sol : int := 0; ;
    var vec : Sequence := Sequence{1}->union(Sequence{ 0 }); ;
    status->first() := -1; ;
    for i : Integer.subrange(0, n-1) do (    status[i+1] := 0; ;
    while ((vec)->size() > 0 & (val[vec[(vec)->size() - 1+1]+1]->compareTo(val[i+1])) >= 0) do (    status[i+1] := Set{status[i+1], status[(vec)->size() - 1+1] + 1}->max(); ;
    vec := vec->front();) ;
    if ((vec)->size() = 0) then (
      status[i+1] := -1;
    ) else skip ;
    execute ((i) : vec); ;
    sol := Set{sol, status[i+1] + 1}->max();) ;
    return sol;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from operator import index
n=int(input())
arr=list(map(int,input().split()))
if len(arr)==1 or 2*min(arr)==sum(arr):
    print(-1)
else :
    index=0
    for i,val in enumerate(arr):
        if valtoInteger() ;
    var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if (arr)->size() = 1 or 2 * (arr)->min() = (arr)->sum() then  (
      execute (-1)->display()
    )
    else (
      var index : int := 0 ;
    for _tuple : Integer.subrange(1, (arr)->size())->collect( _indx | Sequence{_indx-1, (arr)->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var val : OclAny := _tuple->at(_indx);
      if (val->compareTo(arr[index+1])) < 0 then (
      index := i
    ) else skip) ;
    execute (1)->display() ;
    execute (index + 1)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
l=input().split()
l1=[int(num)for num in l]
l1.sort()
a,b=0,0
if len(l1)==1 : print(-1)
else :
    a+=l1[0]
    b+=sum(l1[1 :])
    if a==b : print(-1)
    else :
        print(1)
        print(str(l.index(str(a))+1))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var l : OclAny := input().split() ;
    var l1 : Sequence := l->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ;
    l1 := l1->sort() ;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := Sequence{0,0} ;
    if (l1)->size() = 1 then  (
      execute (-1)->display()
    )
    else (
      a := a + l1->first() ;
    b := b + (l1->tail())->sum() ;
    if a = b then  (
      execute (-1)->display()
    )
    else (
      execute (1)->display() ;
    execute (("" + ((l->indexOf(("" + ((a)))) - 1 + 1))))->display()
      )
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
l=list(map(int,input().split()))
if n>=3 :
    print(1)
    print(l.index(min(l))+1)
elif n==2 :
    if l[0]==l[1]:
        print(-1)
    else :
        print(1)
        print(1)
else :
    print(-1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if n >= 3 then  (
      execute (1)->display() ;
    execute (l->indexOf((l)->min()) - 1 + 1)->display()
    )
    else (if n = 2 then
   (
      if l->first() = l[1+1] then  (
      execute (-1)->display()
    )
    else (
      execute (1)->display() ;
    execute (1)->display()
      )    
)
    else (
      execute (-1)->display()
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys,os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n=int(input())
a=list(map(int,input().split()))
if n==1 or(n==2 and a[0]==a[1]):
    ans=-1
    print(ans)
    exit()
s=sum(a)
k=1
for i in range(n):
    if(2*a[i])^ s :
        ans=i+1
        break
print(k)
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := io.BytesIO(os.readAll()).readline ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if n = 1 or (n = 2 & a->first() = a[1+1]) then (
      var ans : int := -1 ;
    execute (ans)->display() ;
    exit()
    ) else skip ;
    var s : OclAny := (a)->sum() ;
    var k : int := 1 ;
    for i : Integer.subrange(0, n-1) do (    if MathLib.bitwiseXor((2 * a[i+1]), s) then (
      ans := i + 1 ;
    break
    ) else skip) ;
    execute (k)->display() ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
l=list(map(int,input().split()))
zid=False
x=None
if len(l)<2 :
    zid=True
if zid==False :
    for i in range(len(l)):
        if l[i]!=(sum(l)-l[i]):
            x=l.index(l[i])+1
            break
if x==None or len(l)<2 :
    print("-1")
else :
    print(1)
    print(x)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var zid : boolean := false ;
    var x : OclAny := null ;
    if (l)->size() < 2 then (
      zid := true
    ) else skip ;
    if zid = false then (
      for i : Integer.subrange(0, (l)->size()-1) do (    if l[i+1] /= ((l)->sum() - l[i+1]) then (
      x := l->indexOf(l[i+1]) - 1 + 1 ;
    break
    ) else skip)
    ) else skip ;
    if x = null or (l)->size() < 2 then  (
      execute ("-1")->display()
    )
    else (
      execute (1)->display() ;
    execute (x)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=[int(a)for a in input().split()]
n,k,m=a[0],a[1],a[2]
if k-m<=0 :
    print(0)
    exit()
k=k-(m-1)
c=0
for a in reversed(sorted([int(a)for a in input().split()])):
    c+=1
    if k-a<=0 :
        print(c)
        exit()
    else :
        k=k-(a-1)
print(-1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : Sequence := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ;
    var n : OclAny := null;
    var k : OclAny := null;
    var m : OclAny := null;
    Sequence{n,k,m} := Sequence{a->first(),a[1+1],a[2+1]} ;
    if k - m <= 0 then (
      execute (0)->display() ;
    exit()
    ) else skip ;
    var k : double := k - (m - 1) ;
    var c : int := 0 ;
    for a : (input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger()))->sort())->reverse() do (    c := c + 1 ;
    if k - a <= 0 then  (
      execute (c)->display() ;
    exit()
    )
    else (
      k := k - (a - 1)
      )) ;
    execute (-1)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def sumAP(n,d):
    n=int(n/d);
    return(n)*(1+n)*(d/2);
def sumMultiples(n):
    n-=1 ;
    return int(sumAP(n,3)+sumAP(n,7)-sumAP(n,21));
n=24 ;
print(sumMultiples(n));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    n := 24; ;
    execute (sumMultiples(n))->display();;
  operation sumAP(n : OclAny, d : OclAny)
  pre: true post: true
  activity:
    n := ("" + ((n / d)))->toInteger(); ;
    return (n) * (1 + n) * (d / 2);;
  operation sumMultiples(n : OclAny)
  pre: true post: true
  activity:
    n := n - 1; ;
    return ("" + ((sumAP(n, 3) + sumAP(n, 7) - sumAP(n, 21))))->toInteger();;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys,math,os,struct
PYDEV=os.environ.get('PYDEV')
if PYDEV=="True" :
    sys.stdin=open("sample-input.txt","rt")
def valid(k,a):
    if k % 15==0 :
        return a=="FizzBuzz"
    elif k % 3==0 :
        return a=="Fizz"
    elif k % 5==0 :
        return a=="Buzz"
    else :
        return a==str(k)
def fizz_buzz(m,n,A):
    players=list(range(1,m+1))
    p=0
    k=0
    while len(A)>0 :
        k+=1
        a=A.pop(0)
        if valid(k,a):
            p=(p+1)% m
        else :
            if len(players)==0 :
                print()
                return
            players.pop(p)
            if len(players)==1 :
                break
            m-=1
            p %=m
    print(' '.join([str(p)for p in players]))
while True :
    m,n=[int(_)for _ in input().split()]
    if m==0 :
        break
    A=[input().strip()for _ in range(n)]
    fizz_buzz(m,n,A)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var PYDEV : OclAny := os.environ.get('PYDEV') ;
    if PYDEV = "True" then (
      OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt"))
    ) else skip ;
    skip ;
    skip ;
    while true do (    Sequence{m,n} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ;
    if m = 0 then (
      break
    ) else skip ;
    A := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (input()->trim())) ;
    fizz_buzz(m, n, A));
  operation valid(k : OclAny, a : OclAny) : OclAny
  pre: true post: true
  activity:
    if k mod 15 = 0 then  (
      return a = "FizzBuzz"
    )
    else (if k mod 3 = 0 then
   (
      return a = "Fizz"    
)
    else (if k mod 5 = 0 then
   (
      return a = "Buzz"    
)
    else (
      return a = ("" + ((k)))
      )    )
    )
;
  operation fizz_buzz(m : OclAny, n : OclAny, A : OclAny)
  pre: true post: true
  activity:
    var players : Sequence := (Integer.subrange(1, m + 1-1)) ;
    var p : int := 0 ;
    k := 0 ;
    while (A)->size() > 0 do (    k := k + 1 ;
    a := A->at(0`firstArg+1) ;     A := A->excludingAt(0+1) ;
    if valid(k, a) then  (
      p := (p + 1) mod m
    )
    else (
      if (players)->size() = 0 then (
      execute (->display() ;
    return
    ) else skip ;
    players := players->excludingAt(p+1) ;
    if (players)->size() = 1 then (
      break
    ) else skip ;
    m := m - 1 ;
    p := p mod m
      )) ;
    execute (StringLib.sumStringsWithSeparator((players->select(p | true)->collect(p | (("" + ((p)))))), ' '))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
t=int(input())
for i in range(t):
    a,b=map(int,input().split())
    if math.gcd(a,b)==1 :
        print("Finite")
    else :
        print("Infinite")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, t-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if (a)->gcd(b) = 1 then  (
      execute ("Finite")->display()
    )
    else (
      execute ("Infinite")->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import gcd
t=int(input())
for i in range(t):
    a,b=map(int,input().split())
    if gcd(a,b)==1 :
        print('Finite')
    else :
        print('Infinite')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, t-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if gcd(a, b) = 1 then  (
      execute ('Finite')->display()
    )
    else (
      execute ('Infinite')->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
import math
for _ in range(t):
    a,b=map(int,input().split())
    if math.gcd(a,b)==1 :
        print("Finite")
    else : print("Infinite")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    skip ;
    for _anon : Integer.subrange(0, t-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if (a)->gcd(b) = 1 then  (
      execute ("Finite")->display()
    )
    else (
      execute ("Infinite")->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
from fractions import gcd
cin=sys.stdin.buffer.readline
for _ in range(int(cin())):
    a,b=map(int,cin().split())
    print(['finite','infinite'][gcd(a,b)!=1])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var cin : OclAny := sys.stdin.buffer.readline ;
    for _anon : Integer.subrange(0, ("" + ((cin())))->toInteger()-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (cin().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (Sequence{'finite'}->union(Sequence{ 'infinite' })->select(gcd(a, b) /= 1))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
for t in range(int(input())):
    a,b=map(int,input().split())
    if math.gcd(a,b)==1 :
        print("Finite")
    else :
        print("Infinite")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if (a)->gcd(b) = 1 then  (
      execute ("Finite")->display()
    )
    else (
      execute ("Infinite")->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import itertools
def compute():
    LIMIT=10**6
    divisorsum=[0]*(LIMIT+1)
    for i in range(1,LIMIT+1):
        for j in range(i*2,LIMIT+1,i):
            divisorsum[j]+=i
    maxchainlen=0
    ans=-1
    for i in range(LIMIT+1):
        visited=set()
        cur=i
        for count in itertools.count(1):
            visited.add(cur)
            next=divisorsum[cur]
            if next==i :
                if count>maxchainlen :
                    ans=i
                    maxchainlen=count
                break
            elif next>LIMIT or next in visited :
                break
            else :
                cur=next
    return str(ans)
if __name__=="__main__" :
    print(compute())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      execute (compute())->display()
    ) else skip;
  operation compute() : OclAny
  pre: true post: true
  activity:
    var LIMIT : double := (10)->pow(6) ;
    var divisorsum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (LIMIT + 1)) ;
    for i : Integer.subrange(1, LIMIT + 1-1) do (    for j : Integer.subrange(i * 2, LIMIT + 1-1)->select( $x | ($x - i * 2) mod i = 0 ) do (    divisorsum[j+1] := divisorsum[j+1] + i)) ;
    var maxchainlen : int := 0 ;
    var ans : int := -1 ;
    for i : Integer.subrange(0, LIMIT + 1-1) do (    var visited : Set := Set{}->union(()) ;
    var cur : OclAny := i ;
    for count : itertools->count(1) do (    execute ((cur) : visited) ;
    var next : OclAny := divisorsum[cur+1] ;
    if next = i then  (
      if (count->compareTo(maxchainlen)) > 0 then (
      ans := i ;
    maxchainlen := count
    ) else skip ;
    break
    )
    else (if (next->compareTo(LIMIT)) > 0 or (visited)->includes(next) then
   (
      break    
)
    else (
      cur := next
      )    )
)) ;
    return ("" + ((ans)));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
num=input()
sol=[2,7,2,3,3,4,2,5,1,2]
f_num=sol[int(num[0])]
s_num=sol[int(num[1])]
print(f_num*s_num)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var num : String := (OclFile["System.in"]).readLine() ;
    var sol : Sequence := Sequence{2}->union(Sequence{7}->union(Sequence{2}->union(Sequence{3}->union(Sequence{3}->union(Sequence{4}->union(Sequence{2}->union(Sequence{5}->union(Sequence{1}->union(Sequence{ 2 }))))))))) ;
    var f_num : OclAny := sol[("" + ((num->first())))->toInteger()+1] ;
    var s_num : OclAny := sol[("" + ((num[1+1])))->toInteger()+1] ;
    execute (f_num * s_num)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t,n=[2,7,2,3,3,4,2,5,1,2],int(input())
print(t[n//10]*t[n % 10])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : OclAny := null;
    var n : OclAny := null;
    Sequence{t,n} := Sequence{Sequence{2}->union(Sequence{7}->union(Sequence{2}->union(Sequence{3}->union(Sequence{3}->union(Sequence{4}->union(Sequence{2}->union(Sequence{5}->union(Sequence{1}->union(Sequence{ 2 }))))))))),("" + (((OclFile["System.in"]).readLine())))->toInteger()} ;
    execute (t[n div 10+1] * t[n mod 10+1])->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
g=[2,7,2,3,3,4,2,5,1,2]
print(g[n//10]*g[n % 10])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var g : Sequence := Sequence{2}->union(Sequence{7}->union(Sequence{2}->union(Sequence{3}->union(Sequence{3}->union(Sequence{4}->union(Sequence{2}->union(Sequence{5}->union(Sequence{1}->union(Sequence{ 2 }))))))))) ;
    execute (g[n div 10+1] * g[n mod 10+1])->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
s=0
count=0
i=0
while k=m else-1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    var k : OclAny := null;
    Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    a := a->sort() ;
    var s : int := 0 ;
    var count : int := 0 ;
    var i : int := 0 ;
    while (k->compareTo(m)) < 0 & (i->compareTo(n)) < 0 do (    k := k + a[i+1] - 1 ;
    i := i + 1) ;
    execute (if (k->compareTo(m)) >= 0 then i else -1 endif)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for i in range(t):
    firstLine=list(map(int,input().split()))
    n=firstLine[0]
    k=firstLine[1]
    if(k**2>n):
        print("NO")
    elif(n % 2!=k % 2):
        print("NO")
    else :
        print("YES")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, t-1) do (    var firstLine : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var n : OclAny := firstLine->first() ;
    var k : OclAny := firstLine[1+1] ;
    if (((k)->pow(2)->compareTo(n)) > 0) then  (
      execute ("NO")->display()
    )
    else (if (n mod 2 /= k mod 2) then
   (
      execute ("NO")->display()    
)
    else (
      execute ("YES")->display()
      )    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
mp={'0' :['0','8'],'1' :['0','1','3','4','7','8','9'],'2' :['2','8'],'3' :['3','8','9'],'4' :['4','8','9'],'5' :['5','6','8','9'],'6' :['6','8',],'7' :['0','3','7','8','9'],'8' :['8'],'9' :['9','8']}
s=input()
ans=len(mp.get(s[0]))*len(mp.get(s[1]))
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var mp : Map := Map{ '0' |-> Sequence{'0'}->union(Sequence{ '8' }) }->union(Map{ '1' |-> Sequence{'0'}->union(Sequence{'1'}->union(Sequence{'3'}->union(Sequence{'4'}->union(Sequence{'7'}->union(Sequence{'8'}->union(Sequence{ '9' })))))) }->union(Map{ '2' |-> Sequence{'2'}->union(Sequence{ '8' }) }->union(Map{ '3' |-> Sequence{'3'}->union(Sequence{'8'}->union(Sequence{ '9' })) }->union(Map{ '4' |-> Sequence{'4'}->union(Sequence{'8'}->union(Sequence{ '9' })) }->union(Map{ '5' |-> Sequence{'5'}->union(Sequence{'6'}->union(Sequence{'8'}->union(Sequence{ '9' }))) }->union(Map{ '6' |-> Sequence{'6'}->union(Sequence{ '8' }) }->union(Map{ '7' |-> Sequence{'0'}->union(Sequence{'3'}->union(Sequence{'7'}->union(Sequence{'8'}->union(Sequence{ '9' })))) }->union(Map{ '8' |-> Sequence{ '8' } }->union(Map{ '9' |-> Sequence{'9'}->union(Sequence{ '8' }) }))))))))) ;
    var s : String := (OclFile["System.in"]).readLine() ;
    var ans : int := (mp.get(s->first()))->size() * (mp.get(s[1+1]))->size() ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=input()
c=1
for i in n :
    if i in '0269' :
        c*=2
    elif i in '34' :
        c*=3
    elif i=='5' :
        c*=4
    elif i=='7' :
        c*=5
    elif i=='1' :
        c*=7
print(c)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : String := (OclFile["System.in"]).readLine() ;
    var c : int := 1 ;
    for i : n->characters() do (    if ('0269')->characters()->includes(i) then  (
      c := c * 2
    )
    else (if ('34')->characters()->includes(i) then
   (
      c := c * 3    
)
    else (if i = '5' then
   (
      c := c * 4    
)
    else (if i = '7' then
   (
      c := c * 5    
)
    else (if i = '1' then
   (
      c := c * 7    
)
    else skip    )
    )
    )
    )
) ;
    execute (c)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def Maxsum(c1,c2,c3,c4):
    sum=0
    two34=min(c2,min(c3,c4))
    sum=two34*234
    c2-=two34
    sum+=min(c2,c1)*12
    return sum
c1=5 ; c2=2 ; c3=3 ; c4=4
print(Maxsum(c1,c2,c3,c4))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    c1 := 5;    c2 := 2;    c3 := 3;    c4 := 4 ;
    execute (Maxsum(c1, c2, c3, c4))->display();
  operation Maxsum(c1 : OclAny, c2 : OclAny, c3 : OclAny, c4 : OclAny) : OclAny
  pre: true post: true
  activity:
    var sum : int := 0 ;
    var two34 : OclAny := Set{c2, Set{c3, c4}->min()}->min() ;
    sum := two34 * 234 ;
    c2 := c2 - two34 ;
    sum := sum + Set{c2, c1}->min() * 12 ;
    return sum;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m=map(int,input().split())
lin=[]
kol_stroka=[0 for _ in range(n)]
kol_stolb=[0 for _ in range(m)]
for i in range(n):
    lin.append(list(input()))
    k=0
    for j in range(len(lin[i])):
        if lin[i][j]=='*' :
            k+=1
            kol_stolb[j]+=1
    kol_stroka[i]+=k
counter=0
for i in range(n):
    for j in range(m):
        if lin[i][j]=='*' :
            counter+=(kol_stroka[i]-1)*(kol_stolb[j]-1)
print(counter)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var lin : Sequence := Sequence{} ;
    var kol_stroka : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)) ;
    var kol_stolb : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (0)) ;
    for i : Integer.subrange(0, n-1) do (    execute ((((OclFile["System.in"]).readLine())->characters()) : lin) ;
    var k : int := 0 ;
    for j : Integer.subrange(0, (lin[i+1])->size()-1) do (    if lin[i+1][j+1] = '*' then (
      k := k + 1 ;
    kol_stolb[j+1] := kol_stolb[j+1] + 1
    ) else skip) ;
    kol_stroka[i+1] := kol_stroka[i+1] + k) ;
    var counter : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    for j : Integer.subrange(0, m-1) do (    if lin[i+1][j+1] = '*' then (
      counter := counter + (kol_stroka[i+1] - 1) * (kol_stolb[j+1] - 1)
    ) else skip)) ;
    execute (counter)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
data=[]
line1=True
asterisks=[]
cols=[]
for line in sys.stdin :
    if line1 :
        line1=False
        dim=line[:-1].split(" ")
        for i in range(int(dim[1])):
            cols.append(0)
    else :
        row=[]
        for i,c in enumerate(line):
            if c=="*" :
                row.append(i+1)
                cols[i]+=1
        asterisks.append(row)
sum=0
for row in asterisks :
    if len(row)>=2 :
        vertices=[]
        for i,item in enumerate(row):
            sum+=(cols[item-1]-1)*(len(row)-1)
print(sum)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var data : Sequence := Sequence{} ;
    var line1 : boolean := true ;
    var asterisks : Sequence := Sequence{} ;
    var cols : Sequence := Sequence{} ;
    for line : OclFile["System.in"] do (    if line1 then  (
      line1 := false ;
    var dim : OclAny := line->front().split(" ") ;
    for i : Integer.subrange(0, ("" + ((dim[1+1])))->toInteger()-1) do (    execute ((0) : cols))
    )
    else (
      var row : Sequence := Sequence{} ;
    for _tuple : Integer.subrange(1, (line)->size())->collect( _indx | Sequence{_indx-1, (line)->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var c : OclAny := _tuple->at(_indx);
      if c = "*" then (
      execute ((i + 1) : row) ;
    cols[i+1] := cols[i+1] + 1
    ) else skip) ;
    execute ((row) : asterisks)
      )) ;
    var sum : int := 0 ;
    for row : asterisks do (    if (row)->size() >= 2 then (
      var vertices : Sequence := Sequence{} ;
    for _tuple : Integer.subrange(1, (row)->size())->collect( _indx | Sequence{_indx-1, (row)->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var item : OclAny := _tuple->at(_indx);
      sum := sum + (cols[item - 1+1] - 1) * ((row)->size() - 1))
    ) else skip) ;
    execute (sum)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m=[int(x)for x in input().split()]
a=[]
for _ in range(n):
    a.append(input())
cnt_rows=[0]*n
cnt_cols=[0]*m
for i in range(n):
    for j in range(m):
        if a[i][j]=='*' :
            cnt_rows[i]+=1
            cnt_cols[j]+=1
res=0
for i in range(n):
    for j in range(m):
        if a[i][j]=='*' :
            res+=(cnt_cols[j]-1)*(cnt_rows[i]-1)
print(res)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    var a : Sequence := Sequence{} ;
    for _anon : Integer.subrange(0, n-1) do (    execute (((OclFile["System.in"]).readLine()) : a)) ;
    var cnt_rows : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ;
    var cnt_cols : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ;
    for i : Integer.subrange(0, n-1) do (    for j : Integer.subrange(0, m-1) do (    if a[i+1][j+1] = '*' then (
      cnt_rows[i+1] := cnt_rows[i+1] + 1 ;
    cnt_cols[j+1] := cnt_cols[j+1] + 1
    ) else skip)) ;
    var res : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    for j : Integer.subrange(0, m-1) do (    if a[i+1][j+1] = '*' then (
      res := res + (cnt_cols[j+1] - 1) * (cnt_rows[i+1] - 1)
    ) else skip)) ;
    execute (res)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=map(int,input().split())
matrix=[]
scoluna=[0 for i in range(b)]
slinha=[0 for i in range(a)]
for i in range(a):
    matrix.append(input())
    for j in range(b):
        if matrix[-1][j]=="." :
            continue
        slinha[i]=slinha[i]+1
        scoluna[j]=scoluna[j]+1
res=0
for i in range(a):
    for j in range(b):
        if matrix[i][j]=="*" :
            res+=(scoluna[j]-1)*(slinha[i]-1)
print(res)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var matrix : Sequence := Sequence{} ;
    var scoluna : Sequence := Integer.subrange(0, b-1)->select(i | true)->collect(i | (0)) ;
    var slinha : Sequence := Integer.subrange(0, a-1)->select(i | true)->collect(i | (0)) ;
    for i : Integer.subrange(0, a-1) do (    execute (((OclFile["System.in"]).readLine()) : matrix) ;
    for j : Integer.subrange(0, b-1) do (    if matrix->last()[j+1] = "." then (
      continue
    ) else skip ;
    slinha[i+1] := slinha[i+1] + 1 ;
    scoluna[j+1] := scoluna[j+1] + 1)) ;
    var res : int := 0 ;
    for i : Integer.subrange(0, a-1) do (    for j : Integer.subrange(0, b-1) do (    if matrix[i+1][j+1] = "*" then (
      res := res + (scoluna[j+1] - 1) * (slinha[i+1] - 1)
    ) else skip)) ;
    execute (res)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import itertools
import math
import time
from builtins import input,range
from math import gcd as gcd
import sys
import queue
import itertools
import collections
from heapq import heappop,heappush
import random
import os
from random import randint
import decimal
decimal.getcontext().prec=18
def solve():
    n,m=map(int,input().split())
    f=[str(input())for i in range(n)]
    in_col=[0 for i in range(m)]
    for i in range(n):
        for j in range(m):
            in_col[j]+=int(f[i][j]=="*")
    res=0
    for i in range(n):
        in_row=f[i].count("*")
        for j in range(m):
            if f[i][j]=="*" :
                res+=(in_row-1)*(in_col[j]-1)
    print(res)
if __name__=='__main__' :
    multi_test=0
    if multi_test==1 :
        t=int(sys.stdin.readline())
        for _ in range(t):
            solve()
    else :
        solve()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    decimal.getcontext().prec := 18 ;
    skip ;
    if __name__ = '__main__' then (
      var multi_test : int := 0 ;
    if multi_test = 1 then  (
      var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, t-1) do (    solve())
    )
    else (
      solve()
      )
    ) else skip;
  operation solve()
  pre: true post: true
  activity:
    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var f : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine()))))) ;
    var in_col : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (0)) ;
    for i : Integer.subrange(0, n-1) do (    for j : Integer.subrange(0, m-1) do (    in_col[j+1] := in_col[j+1] + ("" + ((f[i+1][j+1] = "*")))->toInteger())) ;
    var res : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    var in_row : OclAny := f[i+1]->count("*") ;
    for j : Integer.subrange(0, m-1) do (    if f[i+1][j+1] = "*" then (
      res := res + (in_row - 1) * (in_col[j+1] - 1)
    ) else skip)) ;
    execute (res)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def ifPossible(X,Y):
    if(X>Y):
        X,Y=Y,X
    if((X+Y)% 5==0 and 3*X>=2*Y):
        print("Yes")
    else :
        print("No")
X=33
Y=27
ifPossible(X,Y)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    X := 33 ;
    Y := 27 ;
    ifPossible(X, Y);
  operation ifPossible(X : OclAny, Y : OclAny)
  pre: true post: true
  activity:
    if ((X->compareTo(Y)) > 0) then (
      Sequence{X,Y} := Sequence{Y,X}
    ) else skip ;
    if ((X + Y) mod 5 = 0 & (3 * X->compareTo(2 * Y)) >= 0) then  (
      execute ("Yes")->display()
    )
    else (
      execute ("No")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,k=map(int,input().split())
s=str(n)[: :-1]
a=len(s)
if k>=a or s.count('0')collect( _x | (OclType["int"])->apply(_x) ) ;
    var s : OclAny := OclType["String"](n)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ;
    var a : int := (s)->size() ;
    if (k->compareTo(a)) >= 0 or (s->count('0')->compareTo(k)) < 0 then  (
      execute (a - 1)->display()
    )
    else (
      var ans : int := 0 ;
    var count : int := 0 ;
    for i : s do (    if i /= '0' then (
      ans := ans + 1
    ) else skip ;
    if i = '0' then (
      count := count + 1
    ) else skip ;
    if count = k then (
      break
    ) else skip) ;
    execute (ans)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush,heappop
import copy
from test.support import _MemoryWatchdog
BIG_NUM=2000000000
HUGE_NUM=99999999999999999
MOD=1000000007
EPS=0.000000001
sys.setrecursionlimit(100000)
while True :
    num_player,num_word=map(int,input().split())
    if num_player==0 and num_word==0 :
        break
    Q=deque()
    table=[False]*(num_player+1)
    for i in range(1,num_player+1):
        Q.append(i)
    for i in range(1,num_word+1):
        tmp_str=input()
        if len(Q)==1 :
            continue
        player=Q.popleft()
        if i % 15==0 :
            if tmp_str=="FizzBuzz" :
                Q.append(player)
        elif i % 3==0 :
            if tmp_str=="Fizz" :
                Q.append(player)
        elif i % 5==0 :
            if tmp_str=="Buzz" :
                Q.append(player)
        else :
            if tmp_str=="FizzBuzz" or tmp_str=="Fizz" or tmp_str=="Buzz" :
                pass
            else :
                if int(tmp_str)==i :
                    Q.append(player)
    while len(Q)>0 :
        table[Q.popleft()]=True
    First=True
    for i in range(1,num_player+1):
        if table[i]==True :
            if First==True :
                print("%d" %(i),end="")
                First=False
            else :
                print(" %d" %(i),end="")
    print()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var BIG_NUM : int := 2000000000 ;
    var HUGE_NUM : int := 99999999999999999 ;
    var MOD : int := 1000000007 ;
    var EPS : double := 0.000000001 ;
    sys.setrecursionlimit(100000) ;
    while true do (    var num_player : OclAny := null;
    var num_word : OclAny := null;
    Sequence{num_player,num_word} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if num_player = 0 & num_word = 0 then (
      break
    ) else skip ;
    var Q : Sequence := () ;
    var table : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (num_player + 1)) ;
    for i : Integer.subrange(1, num_player + 1-1) do (    execute ((i) : Q)) ;
    for i : Integer.subrange(1, num_word + 1-1) do (    var tmp_str : String := (OclFile["System.in"]).readLine() ;
    if (Q)->size() = 1 then (
      continue
    ) else skip ;
    var player : OclAny := Q->first() ;     Q := Q->tail() ;
    if i mod 15 = 0 then  (
      if tmp_str = "FizzBuzz" then (
      execute ((player) : Q)
    ) else skip
    )
    else (if i mod 3 = 0 then
   (
      if tmp_str = "Fizz" then (
      execute ((player) : Q)
    ) else skip    
)
    else (if i mod 5 = 0 then
   (
      if tmp_str = "Buzz" then (
      execute ((player) : Q)
    ) else skip    
)
    else (
      if tmp_str = "FizzBuzz" or tmp_str = "Fizz" or tmp_str = "Buzz" then  (
      skip
    )
    else (
      if ("" + ((tmp_str)))->toInteger() = i then (
      execute ((player) : Q)
    ) else skip
      )
      )    )
    )
) ;
    while (Q)->size() > 0 do (    table[Q->first()+1] := true) ;
    var First : boolean := true ;
    for i : Integer.subrange(1, num_player + 1-1) do (    if table[i+1] = true then (
      if First = true then  (
      execute (StringLib.format("%d",(i)))->display() ;
    First := false
    )
    else (
      execute (StringLib.format(" %d",(i)))->display()
      )
    ) else skip) ;
    execute (->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m,k=input().split()
a=[int(x)for x in input().split()]
a.sort(reverse=True)
x=0
w=0
if int(k)>=int(m):
    print('0')
    w=1
else :
    for i in range(int(n)):
        x+=a[i]
        if x+int(k)-i-1>=int(m):
            print(i+1)
            w=1
            break
if w==0 :
    print(-1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    var k : OclAny := null;
    Sequence{n,m,k} := input().split() ;
    var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    a := a->sort() ;
    var x : int := 0 ;
    var w : int := 0 ;
    if (("" + ((k)))->toInteger()->compareTo(("" + ((m)))->toInteger())) >= 0 then  (
      execute ('0')->display() ;
    w := 1
    )
    else (
      for i : Integer.subrange(0, ("" + ((n)))->toInteger()-1) do (    x := x + a[i+1] ;
    if (x + ("" + ((k)))->toInteger() - i - 1->compareTo(("" + ((m)))->toInteger())) >= 0 then (
      execute (i + 1)->display() ;
    w := 1 ;
    break
    ) else skip)
      ) ;
    if w = 0 then (
      execute (-1)->display()
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
(n,k)=map(int,input().split(' '))
convert_to_str=str(n)
if n %(10**k)==0 :
    print(0)
else :
    if len(convert_to_str)collect( _x | (OclType["int"])->apply(_x) ) ;
    var convert_to_str : String := ("" + ((n))) ;
    if n mod ((10)->pow(k)) = 0 then  (
      execute (0)->display()
    )
    else (
      if ((convert_to_str)->size()->compareTo((("" + (((10)->pow(k)))))->size())) < 0 then  (
      execute ((("" + ((n))))->size() - 1)->display()
    )
    else (
      var j : int := 0 ;
    var i : int := 0 ;
    try (    while true do (    if convert_to_str[MathLib.bitwiseNot(i)+1] = '0' then (
      j := j + 1
    ) else skip ;
    if j = k then (
      execute (1 + i - j)->display() ;
    break
    ) else skip ;
    i := i + 1))
(except_clause except (test (logical_test (comparison (expr (atom (name IndexError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name convert_to_str)))))))) )))) - (expr (atom (number (integer 1)))))))))) ))))))))))))))
      )
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
(n,k)=map(int,input().split(' '))
convert_to_str=str(n)
if n %(10**k)==0 :
    print(0)
else :
    if len(convert_to_str)collect( _x | (OclType["int"])->apply(_x) ) ;
    var convert_to_str : String := ("" + ((n))) ;
    if n mod ((10)->pow(k)) = 0 then  (
      execute (0)->display()
    )
    else (
      if ((convert_to_str)->size()->compareTo((("" + (((10)->pow(k)))))->size())) < 0 then  (
      execute ((("" + ((n))))->size() - 1)->display()
    )
    else (
      var j : int := 0 ;
    var i : int := 0 ;
    try (    while true do (    if convert_to_str[MathLib.bitwiseNot(i)+1] = '0' then (
      j := j + 1
    ) else skip ;
    if j = k then (
      execute (1 + i - j)->display() ;
    break
    ) else skip ;
    i := i + 1))
(except_clause except (test (logical_test (comparison (expr (atom (name IndexError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name convert_to_str)))))))) )))) - (expr (atom (number (integer 1)))))))))) ))))))))))))))
      )
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,k=map(int,input().split())
s=str(n)[: :-1]
a=len(s)
if k>=a or s.count('0')collect( _x | (OclType["int"])->apply(_x) ) ;
    var s : OclAny := OclType["String"](n)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ;
    var a : int := (s)->size() ;
    if (k->compareTo(a)) >= 0 or (s->count('0')->compareTo(k)) < 0 then  (
      execute (a - 1)->display()
    )
    else (
      var ans : int := 0 ;
    var count : int := 0 ;
    for i : s do (    if i /= '0' then (
      ans := ans + 1
    ) else skip ;
    if i = '0' then (
      count := count + 1
    ) else skip ;
    if count = k then (
      break
    ) else skip) ;
    execute (ans)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,k=map(int,input().split())
s=str(n)[: :-1]
a=len(s)
if k>=a or s.count('0')collect( _x | (OclType["int"])->apply(_x) ) ;
    var s : OclAny := OclType["String"](n)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ;
    var a : int := (s)->size() ;
    if (k->compareTo(a)) >= 0 or (s->count('0')->compareTo(k)) < 0 then  (
      execute (a - 1)->display()
    )
    else (
      var ans : int := 0 ;
    var count : int := 0 ;
    for i : s do (    if i /= '0' then (
      ans := ans + 1
    ) else skip ;
    if i = '0' then (
      count := count + 1
    ) else skip ;
    if count = k then (
      break
    ) else skip) ;
    execute (ans)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
X="AGGT12"
Y="12TXAYB"
Z="12XBA"
dp=[[[-1 for i in range(100)]for j in range(100)]for k in range(100)]
def lcsOf3(i,j,k):
    if(i==-1 or j==-1 or k==-1):
        return 0
    if(dp[i][j][k]!=-1):
        return dp[i][j][k]
    if(X[i]==Y[j]and Y[j]==Z[k]):
        dp[i][j][k]=1+lcsOf3(i-1,j-1,k-1)
        return dp[i][j][k]
    else :
        dp[i][j][k]=max(max(lcsOf3(i-1,j,k),lcsOf3(i,j-1,k)),lcsOf3(i,j,k-1))
        return dp[i][j][k]
if __name__=="__main__" :
    m=len(X)
    n=len(Y)
    o=len(Z)
    print("Length of LCS is",lcsOf3(m-1,n-1,o-1))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var X : String := "AGGT12" ;
    var Y : String := "12TXAYB" ;
    var Z : String := "12XBA" ;
    var dp : Sequence := Integer.subrange(0, 100-1)->select(k | true)->collect(k | (Integer.subrange(0, 100-1)->select(j | true)->collect(j | (Integer.subrange(0, 100-1)->select(i | true)->collect(i | (-1)))))) ;
    skip ;
    if __name__ = "__main__" then (
      var m : int := (X)->size() ;
    var n : int := (Y)->size() ;
    var o : int := (Z)->size() ;
    execute ("Length of LCS is")->display()
    ) else skip;
  operation lcsOf3(i : OclAny, j : OclAny, k : OclAny) : OclAny
  pre: true post: true
  activity:
    if (i = -1 or j = -1 or k = -1) then (
      return 0
    ) else skip ;
    if (dp[i+1][j+1][k+1] /= -1) then (
      return dp[i+1][j+1][k+1]
    ) else skip ;
    if (X[i+1] = Y[j+1] & Y[j+1] = Z[k+1]) then  (
      dp[i+1][j+1][k+1] := 1 + lcsOf3(i - 1, j - 1, k - 1) ;
    return dp[i+1][j+1][k+1]
    )
    else (
      dp[i+1][j+1][k+1] := Set{Set{lcsOf3(i - 1, j, k), lcsOf3(i, j - 1, k)}->max(), lcsOf3(i, j, k - 1)}->max() ;
    return dp[i+1][j+1][k+1]
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
e,y=map(int,input().split())
if e==0 :
    if y>=1989 : print("H{}".format(y-1988))
    elif y>=1926 : print("S{}".format(y-1925))
    elif y>=1912 : print("T{}".format(y-1911))
    else : print("M{}".format(y-1867))
elif e==1 :
    print(1867+y)
elif e==2 :
    print(1911+y)
elif e==3 :
    print(1925+y)
else :
    print(1988+y)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var e : OclAny := null;
    var y : OclAny := null;
    Sequence{e,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if e = 0 then  (
      if y >= 1989 then  (
      execute (StringLib.interpolateStrings("H{}", Sequence{y - 1988}))->display()
    )
    else (if y >= 1926 then
   (
      execute (StringLib.interpolateStrings("S{}", Sequence{y - 1925}))->display()    
)
    else (if y >= 1912 then
   (
      execute (StringLib.interpolateStrings("T{}", Sequence{y - 1911}))->display()    
)
    else (
      execute (StringLib.interpolateStrings("M{}", Sequence{y - 1867}))->display()
      )    )
    )
    )
    else (if e = 1 then
   (
      execute (1867 + y)->display()    
)
    else (if e = 2 then
   (
      execute (1911 + y)->display()    
)
    else (if e = 3 then
   (
      execute (1925 + y)->display()    
)
    else (
      execute (1988 + y)->display()
      )    )
    )
    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
c=[1868,1912,1926,1989]
e,y=[int(num)for num in input().split()]
if e>0 :
    print(c[e-1]+y-1)
else :
    if yunion(Sequence{1912}->union(Sequence{1926}->union(Sequence{ 1989 }))) ;
    var e : OclAny := null;
    var y : OclAny := null;
    Sequence{e,y} := input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ;
    if e > 0 then  (
      execute (c[e - 1+1] + y - 1)->display()
    )
    else (
      if (y->compareTo(c[1+1])) < 0 then  (
      execute (StringLib.interpolateStrings('M{}', Sequence{y - c->first() + 1}))->display()
    )
    else (if (y->compareTo(c[2+1])) < 0 then
   (
      execute (StringLib.interpolateStrings('T{}', Sequence{y - c[1+1] + 1}))->display()    
)
    else (if (y->compareTo(c[3+1])) < 0 then
   (
      execute (StringLib.interpolateStrings('S{}', Sequence{y - c[2+1] + 1}))->display()    
)
    else (
      execute (StringLib.interpolateStrings('H{}', Sequence{y - c[3+1] + 1}))->display()
      )    )
    )
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def jp(Y):
    if Y>1988 :
        return f"H{Y-1988}"
    elif Y>1925 :
        return f"S{Y-1925}"
    elif Y>1911 :
        return f"T{Y-1911}"
    elif Y>1911 :
        return f"T{Y-1911}"
    else :
        return f"M{Y-1867}"
def meiji(Y):
    return f"{1867+Y}"
def taisho(Y):
    return f"{1911+Y}"
def syowa(Y):
    return f"{1925+Y}"
def heisei(Y):
    return f"{1988+Y}"
E,Y=map(int,input().split())
print([jp(Y),meiji(Y),taisho(Y),syowa(Y),heisei(Y)][E])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var E : OclAny := null;
    Sequence{E,Y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (Sequence{jp(Y)}->union(Sequence{meiji(Y)}->union(Sequence{taisho(Y)}->union(Sequence{syowa(Y)}->union(Sequence{ heisei(Y) }))))[E+1])->display();
  operation jp(Y : OclAny) : OclAny
  pre: true post: true
  activity:
    if Y > 1988 then  (
      return StringLib.formattedString("H{Y-1988}")
    )
    else (if Y > 1925 then
   (
      return StringLib.formattedString("S{Y-1925}")    
)
    else (if Y > 1911 then
   (
      return StringLib.formattedString("T{Y-1911}")    
)
    else (if Y > 1911 then
   (
      return StringLib.formattedString("T{Y-1911}")    
)
    else (
      return StringLib.formattedString("M{Y-1867}")
      )    )
    )
    )
;
  operation meiji(Y : OclAny) : OclAny
  pre: true post: true
  activity:
    return StringLib.formattedString("{1867+Y}");
  operation taisho(Y : OclAny) : OclAny
  pre: true post: true
  activity:
    return StringLib.formattedString("{1911+Y}");
  operation syowa(Y : OclAny) : OclAny
  pre: true post: true
  activity:
    return StringLib.formattedString("{1925+Y}");
  operation heisei(Y : OclAny) : OclAny
  pre: true post: true
  activity:
    return StringLib.formattedString("{1988+Y}");
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
L,R=input().split()
L=int(L)
R=int(R)
if L==0 :
    if R>=1868 and R<=1911 :
        K=int(R)-1867
        print("M"+str(K))
    elif R>=1912 and R<=1925 :
        K=int(R)-1911
        print("T"+str(K))
    elif R>=1926 and R<=1988 :
        K=int(R)-1925
        print("S"+str(K))
    elif R>=1989 and R<=2016 :
        K=int(R)-1988
        print("H"+str(K))
elif L==1 :
    K=int(R)+1867
    print(K)
elif L==2 :
    K=int(R)+1911
    print(K)
elif L==3 :
    K=int(R)+1925
    print(K)
elif L==4 :
    K=int(R)+1988
    print(K)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var L : OclAny := null;
    var R : OclAny := null;
    Sequence{L,R} := input().split() ;
    var L : int := ("" + ((L)))->toInteger() ;
    var R : int := ("" + ((R)))->toInteger() ;
    if L = 0 then  (
      if R >= 1868 & R <= 1911 then  (
      var K : double := ("" + ((R)))->toInteger() - 1867 ;
    execute ("M" + ("" + ((K))))->display()
    )
    else (if R >= 1912 & R <= 1925 then
   (
      K := ("" + ((R)))->toInteger() - 1911 ;
    execute ("T" + ("" + ((K))))->display()    
)
    else (if R >= 1926 & R <= 1988 then
   (
      K := ("" + ((R)))->toInteger() - 1925 ;
    execute ("S" + ("" + ((K))))->display()    
)
    else (if R >= 1989 & R <= 2016 then
   (
      K := ("" + ((R)))->toInteger() - 1988 ;
    execute ("H" + ("" + ((K))))->display()    
)
    else skip    )
    )
    )
    )
    else (if L = 1 then
   (
      K := ("" + ((R)))->toInteger() + 1867 ;
    execute (K)->display()    
)
    else (if L = 2 then
   (
      K := ("" + ((R)))->toInteger() + 1911 ;
    execute (K)->display()    
)
    else (if L = 3 then
   (
      K := ("" + ((R)))->toInteger() + 1925 ;
    execute (K)->display()    
)
    else (if L = 4 then
   (
      K := ("" + ((R)))->toInteger() + 1988 ;
    execute (K)->display()    
)
    else skip    )
    )
    )
    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def FB(n):
    if n % 3==0 and n % 5==0 : return 'FizzBuzz'
    if n % 3==0 : return 'Fizz'
    if n % 5==0 : return 'Buzz'
    return str(n)
while True :
    M,N=map(int,input().split())
    if M==0 and N==0 : break
    TF=[1]*M
    S=[input()for _ in range(N)]
    k=0
    for i,s in enumerate(S):
        if sum(TF)==1 : break
        while True :
            if not TF[k]:
                k=(k+1)% M
            else :
                if FB(i+1)==s :
                    k=(k+1)% M
                    break
                else :
                    TF[k]=0
                    k=(k+1)% M
                    break
    ans=[]
    for j,p in enumerate(TF):
        if p :
            ans.append(str(j+1))
    print(' '.join(ans))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    while true do (    var M : OclAny := null;
    var N : OclAny := null;
    Sequence{M,N} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if M = 0 & N = 0 then (
      break
    ) else skip ;
    var TF : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, M) ;
    var S : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ;
    var k : int := 0 ;
    for _tuple : Integer.subrange(1, (S)->size())->collect( _indx | Sequence{_indx-1, (S)->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var s : OclAny := _tuple->at(_indx);
      if (TF)->sum() = 1 then (
      break
    ) else skip ;
    while true do (    if not(TF[k+1]) then  (
      k := (k + 1) mod M
    )
    else (
      if FB(i + 1) = s then  (
      k := (k + 1) mod M ;
    break
    )
    else (
      TF[k+1] := 0 ;
    k := (k + 1) mod M ;
    break
      )
      ))) ;
    var ans : Sequence := Sequence{} ;
    for _tuple : Integer.subrange(1, (TF)->size())->collect( _indx | Sequence{_indx-1, (TF)->at(_indx)} ) do (var _indx : int := 1;
      var j : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var p : OclAny := _tuple->at(_indx);
      if p then (
      execute ((("" + ((j + 1)))) : ans)
    ) else skip) ;
    execute (StringLib.sumStringsWithSeparator((ans), ' '))->display());
  operation FB(n : OclAny) : OclAny
  pre: true post: true
  activity:
    if n mod 3 = 0 & n mod 5 = 0 then (
      return 'FizzBuzz'
    ) else skip ;
    if n mod 3 = 0 then (
      return 'Fizz'
    ) else skip ;
    if n mod 5 = 0 then (
      return 'Buzz'
    ) else skip ;
    return ("" + ((n)));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def solve(e,y):
    if e==0 :
        if y<1912 :
            r='M'+str(y-1868+1)
        elif y<1926 :
            r='T'+str(y-1912+1)
        elif y<1989 :
            r='S'+str(y-1926+1)
        else :
            r='H'+str(y-1989+1)
    else :
        yy=[0,1868,1912,1926,1989]
        r=yy[e]+y-1
    return r
def main():
    E,Y=map(int,input().split())
    print(solve(E,Y))
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation solve(e : OclAny, y : OclAny) : OclAny
  pre: true post: true
  activity:
    if e = 0 then  (
      if y < 1912 then  (
      var r : String := 'M' + ("" + ((y - 1868 + 1)))
    )
    else (if y < 1926 then
   (
      r := 'T' + ("" + ((y - 1912 + 1)))    
)
    else (if y < 1989 then
   (
      r := 'S' + ("" + ((y - 1926 + 1)))    
)
    else (
      r := 'H' + ("" + ((y - 1989 + 1)))
      )    )
    )
    )
    else (
      var yy : Sequence := Sequence{0}->union(Sequence{1868}->union(Sequence{1912}->union(Sequence{1926}->union(Sequence{ 1989 })))) ;
    r := yy[e+1] + y - 1
      ) ;
    return r;
  operation main()
  pre: true post: true
  activity:
    var E : OclAny := null;
    var Y : OclAny := null;
    Sequence{E,Y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (solve(E, Y))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def nthprimedigitsnumber(number):
    num="" ;
    while(number>0):
        rem=number % 4 ;
        if(rem==1):
            num+='2' ;
        if(rem==2):
            num+='3' ;
        if(rem==3):
            num+='5' ;
        if(rem==0):
            num+='7' ;
        if(number % 4==0):
            number=number-1
        number=number//4 ;
    return num[: :-1];
number=21 ;
print(nthprimedigitsnumber(10));
print(nthprimedigitsnumber(number));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    number := 21; ;
    execute (nthprimedigitsnumber(10))->display(); ;
    execute (nthprimedigitsnumber(number))->display();;
  operation nthprimedigitsnumber(number : OclAny)
  pre: true post: true
  activity:
    var num : String := ""; ;
    while (number > 0) do (    var rem : int := number mod 4; ;
    if (rem = 1) then (
      num := num + '2';
    ) else skip ;
    if (rem = 2) then (
      num := num + '3';
    ) else skip ;
    if (rem = 3) then (
      num := num + '5';
    ) else skip ;
    if (rem = 0) then (
      num := num + '7';
    ) else skip ;
    if (number mod 4 = 0) then (
      number := number - 1
    ) else skip ;
    number := number div 4;) ;
    return num(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))));;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def check(n,x,y):
    fact=1 ;
    for i in range(2,n+1):
        fact*=i ;
    divisor=x**y ;
    if(fact % divisor==0):
        print("YES");
    else :
        print("NO");
if __name__=="__main__" :
    n=10 ;
    x=2 ;
    y=8 ;
    check(n,x,y);
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      n := 10; ;
    x := 2; ;
    y := 8; ;
    check(n, x, y);
    ) else skip;
  operation check(n : OclAny, x : OclAny, y : OclAny)
  pre: true post: true
  activity:
    var fact : int := 1; ;
    for i : Integer.subrange(2, n + 1-1) do (    fact := fact * i;) ;
    var divisor : double := (x)->pow(y); ;
    if (fact mod divisor = 0) then  (
      execute ("YES")->display();
    )
    else (
      execute ("NO")->display();
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import sqrt,floor
def isPerfectSquare(x):
    sr=sqrt(x)
    return((sr-floor(sr))==0)
def isFibonacci(n):
    return(isPerfectSquare(5*n*n+4)or isPerfectSquare(5*n*n-4))
def totalPairs(a,b,n,m):
    s=set();
    for i in range(n):
        for j in range(m):
            if(isFibonacci(a[i]+b[j])==True):
                if(a[i]union(Sequence{1}->union(Sequence{33}->union(Sequence{ 2 }))); ;
    b := Sequence{1}->union(Sequence{11}->union(Sequence{ 2 })); ;
    n := (a)->size(); ;
    m := (b)->size(); ;
    execute (totalPairs(a, b, n, m))->display();
    ) else skip;
  operation isPerfectSquare(x : OclAny) : OclAny
  pre: true post: true
  activity:
    var sr : OclAny := sqrt(x) ;
    return ((sr - floor(sr)) = 0);
  operation isFibonacci(n : OclAny) : OclAny
  pre: true post: true
  activity:
    return (isPerfectSquare(5 * n * n + 4) or isPerfectSquare(5 * n * n - 4));
  operation totalPairs(a : OclAny, b : OclAny, n : OclAny, m : OclAny)
  pre: true post: true
  activity:
    var s : Set := Set{}->union(()); ;
    for i : Integer.subrange(0, n-1) do (    for j : Integer.subrange(0, m-1) do (    if (isFibonacci(a[i+1] + b[j+1]) = true) then (
      if ((a[i+1]->compareTo(b[j+1])) < 0) then  (
      execute ((Sequence{a[i+1], b[j+1]}) : s);
    )
    else (
      execute ((Sequence{b[j+1], a[i+1]}) : s);
      )
    ) else skip)) ;
    return (s)->size();;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
class RMQ :
    def __init__(self,n,e):
        self.n=2**((n-1).bit_length())
        self.e=e
        self.d=[e]*(self.n<<1)
    def update(self,k,x):
        k+=self.n-1
        self.d[k]=x
        while k>0 :
            k=(k-1)>>1
            self.d[k]=min(self.d[(k<<1)+1],self.d[(k<<1)+2])
    def query(self,l,r):
        L=l+self.n ; R=r+self.n
        s=self.e
        while L>=1 ; R>>=1
        return s
[n,q]=list(map(int,input().split()))
rmq=RMQ(n,(1<<31)-1)
for i in range(q):
[com,x,y]=list(map(int,input().split()))
    if com==0 :
        rmq.update(x,y)
    else :
        print(rmq.query(x,y+1))
------------------------------------------------------------
OCL File:
---------
class RMQ {
  static operation newRMQ() : RMQ
  pre: true
  post: RMQ->exists( _x | result = _x );
  attribute n : double := (2)->pow(((n - 1).bit_length()));
  attribute e : OclAny := e;
  attribute d : Sequence := MatrixLib.elementwiseMult(Sequence{ e }, (self.n * (2->pow(1))));
  operation initialise(n : OclAny,e : OclAny) : RMQ
  pre: true post: true
  activity:
    self.n := (2)->pow(((n - 1).bit_length())) ;
    self.e := e ;
    self.d := MatrixLib.elementwiseMult(Sequence{ e }, (self.n * (2->pow(1))));
    return self;
  operation update(k : OclAny,x : OclAny)
  pre: true post: true
  activity:
    k := k + self.n - 1 ;
    self.d[k+1] := x ;
    while k > 0 do (    k := (k - 1) /(2->pow(1)) ;
    self.d[k+1] := Set{self.d[(k * (2->pow(1))) + 1+1], self.d[(k * (2->pow(1))) + 2+1]}->min());
  operation query(l : OclAny,r : OclAny) : OclAny
  pre: true post: true
  activity:
    var L : OclAny := l + self.n;    var R : OclAny := r + self.n ;
    var s : OclAny := self.e ;
    while (L->compareTo(R)) < 0 do (    if MathLib.bitwiseAnd(R, 1) then (
      R := R - 1 ;
    s := Set{s, self.d[R - 1+1]}->min()
    ) else skip ;
    if MathLib.bitwiseAnd(L, 1) then (
      s := Set{s, self.d[L - 1+1]}->min() ;
    L := L + 1
    ) else skip ;
    L := L div (2->pow(1));    R := R div (2->pow(1))) ;
    return s;
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    Sequence{n}->union(Sequence{ q }) := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var rmq : RMQ := (RMQ.newRMQ()).initialise(n, (1 * (2->pow(31))) - 1) ;
    for i : Integer.subrange(0, q-1) do ( ;
    Sequence{com}->union(Sequence{x}->union(Sequence{ y })) := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if com = 0 then  (
      execute ((x, y) <: rmq)
    )
    else (
      execute (rmq.query(x, y + 1))->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
M=2147483647
a=[M for i in range(1000000)]
def j_min(x,y):
    if x=2 :
                a[int(x/2)]=j_min(a[int(x)],a[int(x)^ 1])
                x/=2
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var M : int := 2147483647 ;
    var a : Sequence := Integer.subrange(0, 1000000-1)->select(i | true)->collect(i | (M)) ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ;
    var t : int := 1 ;
    while (t->compareTo(n)) < 0 do (    t := t * 2) ;
    for i : Integer.subrange(-1 + 1, m - 1)->reverse() do (    var com : OclAny := null;
    Sequence{com,x,y} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ;
    if com then  (
      execute (find(x, y + 1, 1, 0, t))->display()
    )
    else (
      x := x + t ;
    a[x+1] := y ;
    while (OclType["int"]).isInstance(x) or x >= 2 do (    a[("" + ((x / 2)))->toInteger()+1] := j_min(a[("" + ((x)))->toInteger()+1], a[MathLib.bitwiseXor(("" + ((x)))->toInteger(), 1)+1]) ;
    x := x / 2)
      ))
    ) else skip;
  operation j_min(x : OclAny, y : OclAny) : OclAny
  pre: true post: true
  activity:
    if (x->compareTo(y)) < 0 then  (
      return x
    )
    else (
      return y
      );
  operation find(x : OclAny, y : OclAny, i : OclAny, l : OclAny, r : OclAny) : OclAny
  pre: true post: true
  activity:
    if (r->compareTo(x)) <= 0 or (y->compareTo(l)) <= 0 then (
      return M
    ) else skip ;
    if (x->compareTo(l)) <= 0 & (r->compareTo(y)) <= 0 then (
      return a[i+1]
    ) else skip ;
    return j_min(find(x, y, i * 2, l, (l + r) / 2), find(x, y, i * 2 + 1, (l + r) / 2, r));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
class SegTreeMin :
    SENTINEL=(1<<31)-1
    output=[]
    def __init__(self,n):
        n2=1
        while n21 :
            self.tree[i>>1]=x=min(x,self.tree[i ^ 1])
            i>>=1
    def get_min(self,s,t):
        self.output.append(self._get_min(s,t+1,1,0,self.n2))
    def _get_min(self,a,b,k,l,r):
        if r<=a or b<=l :
            return self.SENTINEL
        if a<=l and r<=b :
            return self.tree[k]
        m=(l+r)//2
        k<<=1
        return min(self._get_min(a,b,k,l,m),self._get_min(a,b,k+1,m,r))
    def print(self):
        print('\n'.join(map(str,self.output)))
n,q=map(int,input().split())
st=SegTreeMin(n)
fs=[st.update,st.get_min]
for c,x,y in(map(int,input().split())for _ in range(q)):
    fs[c](x,y)
st.print()
------------------------------------------------------------
OCL File:
---------
class SegTreeMin {
  static operation newSegTreeMin() : SegTreeMin
  pre: true
  post: SegTreeMin->exists( _x | result = _x );
  static attribute SENTINEL : double := (1 * (2->pow(31))) - 1;
  static attribute output : Sequence := Sequence{};
  attribute n2 : int := n2;
  attribute tree : Sequence := MatrixLib.elementwiseMult(Sequence{ self.SENTINEL }, (n2 * (2->pow(1))));
  operation initialise(n : OclAny) : SegTreeMin
  pre: true post: true
  activity:
    var n2 : int := 1 ;
    while (n2->compareTo(n)) < 0 do (    n2 := n2 * (2->pow(1))) ;
    self.n2 := n2 ;
    self.tree := MatrixLib.elementwiseMult(Sequence{ self.SENTINEL }, (n2 * (2->pow(1))));
    return self;
  operation update(i : OclAny,x : OclAny)
  pre: true post: true
  activity:
    i := i + self.n2 ;
    self.tree[i+1] := x ;
    while i > 1 do (    self.tree[i /(2->pow(1))+1] := Set{x, self.tree[MathLib.bitwiseXor(i, 1)+1]}->min(); x := Set{x, self.tree[MathLib.bitwiseXor(i, 1)+1]}->min() ;
    i := i div (2->pow(1)));
  operation get_min(s : OclAny,t : OclAny)
  pre: true post: true
  activity:
(expr (atom (name self)) (trailer . (name output)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name self)) (trailer . (name _get_min) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name t))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom (name self)) (trailer . (name n2)))))))) ))))))))) ))));
  operation _get_min(a : OclAny,b : OclAny,k : OclAny,l : OclAny,r : OclAny) : OclAny
  pre: true post: true
  activity:
    if (r->compareTo(a)) <= 0 or (b->compareTo(l)) <= 0 then (
      return self.SENTINEL
    ) else skip ;
    if (a->compareTo(l)) <= 0 & (r->compareTo(b)) <= 0 then (
      return self.tree[k+1]
    ) else skip ;
    var m : int := (l + r) div 2 ;
    k := k * (2->pow(1)) ;
    return Set{self._get_min(a, b, k, l, m), self._get_min(a, b, k + 1, m, r)}->min();
(funcdef def name print ( (typedargslist (def_parameters (def_parameter (named_parameter (name self))))) ) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '
') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name self)) (trailer . (name output)))))))) ))))))))) ))))))))) ))))))))))))))}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var q : OclAny := null;
    Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var st : SegTreeMin := (SegTreeMin.newSegTreeMin()).initialise(n) ;
    var fs : Sequence := Sequence{st.update}->union(Sequence{ st.get_min }) ;
    for _tuple : Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name q)))))))) ))))))))} do (var _indx : int := 1;
      var c : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var x : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var y : OclAny := _tuple->at(_indx);
  (expr (atom (name fs)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name c)))))))) ])) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x))))))) , (argument (test (logical_test (comparison (expr (atom (name y)))))))) ))))) ;
testlist_star_expr`updateForm ;
(testlist_star_expr st .) ;
    execute (->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N,Q=map(int,input().split())
A=[2**31-1]*N
q=[tuple(map(int,input().split()))for _ in range(Q)]
seg_num=2**(N-1).bit_length()
ide_ele=float("inf")
func=min
seg_lst=[ide_ele]*2*seg_num
def init(lst):
    for i in range(N):
        seg_lst[i+seg_num-1]=lst[i]
    for i in range(seg_num-2,-1,-1):
        seg_lst[i]=func(seg_lst[2*i+1],seg_lst[2*i+2])
def update(i,x):
    i+=seg_num-1
    seg_lst[i]=x
    while i :
        i=(i-1)//2
        seg_lst[i]=func(seg_lst[2*i+1],seg_lst[2*i+2])
def query(l,r):
    if r<=l :
        return ide_ele
    l+=seg_num-1
    r+=seg_num-2
    ret=ide_ele
    while r-l>1 :
        if l & 1==0 :
            ret=func(ret,seg_lst[l])
        if r & 1==1 :
            ret=func(ret,seg_lst[r])
            r-=1
        l=l//2
        r=(r-1)//2
    if l==r :
        ret=func(ret,seg_lst[l])
    else :
        ret=func(ret,seg_lst[l])
        ret=func(ret,seg_lst[r])
    return ret
init(A)
for c,x,y in q :
    if c==0 :
        update(x,y)
    else :
        print(query(x,y+1))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : OclAny := null;
    var Q : OclAny := null;
    Sequence{N,Q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var A : Sequence := MatrixLib.elementwiseMult(Sequence{ (2)->pow(31) - 1 }, N) ;
    var q : Sequence := Integer.subrange(0, Q-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var seg_num : double := (2)->pow((N - 1).bit_length()) ;
    var ide_ele : double := ("" + (("inf")))->toReal() ;
    var func : OclAny := min ;
    var seg_lst : Sequence := MatrixLib.elementwiseMult(MatrixLib.elementwiseMult(Sequence{ ide_ele }, 2), seg_num) ;
    skip ;
    skip ;
    skip ;
    init(A) ;
    for _tuple : q do (var _indx : int := 1;
      var c : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var x : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var y : OclAny := _tuple->at(_indx);
      if c = 0 then  (
      update(x, y)
    )
    else (
      execute (query(x, y + 1))->display()
      ));
  operation init(lst : OclAny)
  pre: true post: true
  activity:
    for i : Integer.subrange(0, N-1) do (    seg_lst[i + seg_num - 1+1] := lst[i+1]) ;
    for i : Integer.subrange(-1 + 1, seg_num - 2)->reverse() do (    seg_lst[i+1] := func(seg_lst[2 * i + 1+1], seg_lst[2 * i + 2+1]));
  operation update(i : OclAny, x : OclAny)
  pre: true post: true
  activity:
    i := i + seg_num - 1 ;
    seg_lst[i+1] := x ;
    while i do (    i := (i - 1) div 2 ;
    seg_lst[i+1] := func(seg_lst[2 * i + 1+1], seg_lst[2 * i + 2+1]));
  operation query(l : OclAny, r : OclAny) : OclAny
  pre: true post: true
  activity:
    if (r->compareTo(l)) <= 0 then (
      return ide_ele
    ) else skip ;
    l := l + seg_num - 1 ;
    r := r + seg_num - 2 ;
    var ret : OclAny := ide_ele ;
    while r - l > 1 do (    if MathLib.bitwiseAnd(l, 1) = 0 then (
      ret := func(ret, seg_lst[l+1])
    ) else skip ;
    if MathLib.bitwiseAnd(r, 1) = 1 then (
      ret := func(ret, seg_lst[r+1]) ;
    r := r - 1
    ) else skip ;
    l := l div 2 ;
    r := (r - 1) div 2) ;
    if l = r then  (
      ret := func(ret, seg_lst[l+1])
    )
    else (
      ret := func(ret, seg_lst[l+1]) ;
    ret := func(ret, seg_lst[r+1])
      ) ;
    return ret;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
class RangeMinimumQuery :
    nmemb=1
    size=1
    data=[]
    def __init__(self,n):
        self.nmemb=n
        while self.size0):
            pos=(pos-1)/2
            vl=self.data[pos*2+1]
            vr=self.data[pos*2+2]
            self.data[pos]=min(vl,vr)
if __name__=="__main__" :
    n,q=map(int,raw_input().split())
    rmq=RangeMinimumQuery(n)
    for i in range(n):
        rmq.update(i,2**31-1)
        assert(rmq.find(i,i+1)==2**31-1)
    for i in range(q):
        com,x,y=map(int,raw_input().split())
        if com==0 :
            rmq.update(x,y)
        else :
            print(rmq.find(x,y+1))
------------------------------------------------------------
OCL File:
---------
class RangeMinimumQuery {
  static operation newRangeMinimumQuery() : RangeMinimumQuery
  pre: true
  post: RangeMinimumQuery->exists( _x | result = _x );
  static attribute nmemb : int := 1;
  static attribute size : int := 1;
  static attribute data : Sequence := Sequence{};
  attribute nmemb : OclAny := n;
  attribute data : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (self.size * 2));
  operation initialise(n : OclAny) : RangeMinimumQuery
  pre: true post: true
  activity:
    self.nmemb := n ;
    while (self.size->compareTo(n)) < 0 do (    self.size := self.size * 2) ;
    self.data := MatrixLib.elementwiseMult(Sequence{ 0 }, (self.size * 2));
    return self;
  operation __find(start : OclAny,end : OclAny,id : OclAny,left : OclAny,right : OclAny) : OclAny
  pre: true post: true
  activity:
    if (end->compareTo(left)) <= 0 or (right->compareTo(start)) <= 0 then  (
      return (2)->pow(31) - 1
    )
    else (if (start->compareTo(left)) <= 0 & (right->compareTo(end)) <= 0 then
   (
      return self.data[id+1]    
)
    else (
      var mid : double := (left + right) / 2 ;
    var vl : OclAny := self.__find(start, end, id * 2 + 1, left, mid) ;
    var vr : OclAny := self.__find(start, end, id * 2 + 2, mid, right) ;
    return Set{vl, vr}->min()
      )    )
;
  operation find(start : OclAny,end : OclAny) : OclAny
  pre: true post: true
  activity:
    return self.__find(start, end, 0, 0, self.size);
  operation update(pos : OclAny,value : OclAny)
  pre: true post: true
  activity:
    pos := pos + self.size - 1 ;
    self.data[pos+1] := value ;
    while (pos > 0) do (    pos := (pos - 1) / 2 ;
    vl := self.data[pos * 2 + 1+1] ;
    vr := self.data[pos * 2 + 2+1] ;
    self.data[pos+1] := Set{vl, vr}->min());
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      var q : OclAny := null;
    Sequence{n,q} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var rmq : RangeMinimumQuery := (RangeMinimumQuery.newRangeMinimumQuery()).initialise(n) ;
    for i : Integer.subrange(0, n-1) do (    execute ((i, (2)->pow(31) - 1) <: rmq) ;
    assert (rmq->indexOf(i, i + 1) - 1 = (2)->pow(31) - 1) do "assertion failed") ;
    for i : Integer.subrange(0, q-1) do (    var com : OclAny := null;
    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{com,x,y} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if com = 0 then  (
      execute ((x, y) <: rmq)
    )
    else (
      execute (rmq->indexOf(x, y + 1) - 1)->display()
      ))
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def combi(k):
    global ans
    if k==9 :
        ans+=1
        return
    for y in range(4):
        for x in range(4):
            if arr[y][x]: continue
            arr[y][x]=k
            for i in range(4):
                x2,y2=x+a[i<<1],y+a[(i<<1)+1]
                if x2<0 or x2>=4 or y2<0 or y2>=4 or arr[y2][x2]: continue
                arr[y2][x2]=k
                combi(k+1)
                arr[y2][x2]=0
            arr[y][x]=0
            return ;
while True :
    a=list(map(int,input().split()))
    if len(a)==1 : break
    arr=[[0 for i in range(4)]for j in range(4)]
    ans=0
    arr[0][0]=1
    for i in range(4):
        x,y=a[i<<1],a[(i<<1)+1]
        if x>=0 and y>=0 :
            arr[y][x]=1
            combi(2)
            arr[y][x]=0
    print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  attribute ans : OclAny;
  operation initialise()
  pre: true post: true
  activity:     skip ;
    while true do (    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if (a)->size() = 1 then (
      break
    ) else skip ;
    var arr : Sequence := Integer.subrange(0, 4-1)->select(j | true)->collect(j | (Integer.subrange(0, 4-1)->select(i | true)->collect(i | (0)))) ;
    ans := 0 ;
    arr->first()->first() := 1 ;
    for i : Integer.subrange(0, 4-1) do (    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := Sequence{a[i * (2->pow(1))+1],a[(i * (2->pow(1))) + 1+1]} ;
    if x >= 0 & y >= 0 then (
      arr[y+1][x+1] := 1 ;
    combi(2) ;
    arr[y+1][x+1] := 0
    ) else skip) ;
    execute (ans)->display());
  operation combi(k : OclAny) : OclAny
  pre: true post: true
  activity:
    skip ;
    if k = 9 then (
      ans := ans + 1 ;
    return
    ) else skip ;
    for y : Integer.subrange(0, 4-1) do (    for x : Integer.subrange(0, 4-1) do (    if arr[y+1][x+1] then (
      continue
    ) else skip ;
    arr[y+1][x+1] := k ;
    for i : Integer.subrange(0, 4-1) do (    var x2 : OclAny := null;
    var y2 : OclAny := null;
    Sequence{x2,y2} := Sequence{x + a[i * (2->pow(1))+1],y + a[(i * (2->pow(1))) + 1+1]} ;
    if x2 < 0 or x2 >= 4 or y2 < 0 or y2 >= 4 or arr[y2+1][x2+1] then (
      continue
    ) else skip ;
    arr[y2+1][x2+1] := k ;
    combi(k + 1) ;
    arr[y2+1][x2+1] := 0) ;
    arr[y+1][x+1] := 0 ;
    return;));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s=input()
k=int(input())
if len(s)>=k :
    ans=k-len(set(s))
    if ans<0 : ans=0
else :
    ans='impossible'
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : String := (OclFile["System.in"]).readLine() ;
    var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if ((s)->size()->compareTo(k)) >= 0 then  (
      var ans : double := k - (Set{}->union((s)))->size() ;
    if ans < 0 then (
      ans := 0
    ) else skip
    )
    else (
      ans := 'impossible'
      ) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
l=[[0 for i in range(1001)]for j in range(1001)]
def initialize():
    l[0][0]=1
    for i in range(1,1001):
        l[i][0]=1
        for j in range(1,i+1):
            l[i][j]=(l[i-1][j-1]+l[i-1][j])
def nCr(n,r):
    return l[n][r]
initialize()
n=8
r=3
print(nCr(n,r))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var l : Sequence := Integer.subrange(0, 1001-1)->select(j | true)->collect(j | (Integer.subrange(0, 1001-1)->select(i | true)->collect(i | (0)))) ;
    skip ;
    skip ;
    initialize() ;
    n := 8 ;
    r := 3 ;
    execute (nCr(n, r))->display();
  operation initialize()
  pre: true post: true
  activity:
    l->first()->first() := 1 ;
    for i : Integer.subrange(1, 1001-1) do (    l[i+1]->first() := 1 ;
    for j : Integer.subrange(1, i + 1-1) do (    l[i+1][j+1] := (l[i - 1+1][j - 1+1] + l[i - 1+1][j+1])));
  operation nCr(n : OclAny, r : OclAny) : OclAny
  pre: true post: true
  activity:
    return l[n+1][r+1];
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def get_index(fixed):
    for y,f in enumerate(fixed):
        try :
            x=f.index(0)
            return x,y
        except ValueError :
            pass
def recursive(i,fixed):
    if i==9 :
        return 1
    result=0
    x,y=get_index(fixed)
    fixed[y][x]=i
    for dx,dy in ds :
        x2,y2=x+dx,y+dy
        if not(0<=x2<4 and 0<=y2<4):
            continue
        if fixed[y2][x2]:
            continue
        fixed[y2][x2]=i
        result+=recursive(i+1,fixed)
        fixed[y2][x2]=0
    fixed[y][x]=0
    return result
while True :
    ipt=list(map(int,input().split()))
    if len(ipt)==1 :
        break
    ds=list(zip(*[iter(ipt)]*2))
    print(recursive(1,[[0]*4 for _ in range(4)]))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    while true do (    var ipt : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if (ipt)->size() = 1 then (
      break
    ) else skip ;
    var ds : Sequence := (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ipt)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ipt)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ipt)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))`third->at(_indx)} )) ;
    execute (recursive(1, Integer.subrange(0, 4-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 4)))))->display());
  operation get_index(fixed : OclAny) : OclAny
  pre: true post: true
  activity:
    for _tuple : Integer.subrange(1, (fixed)->size())->collect( _indx | Sequence{_indx-1, (fixed)->at(_indx)} ) do (var _indx : int := 1;
      var y : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var f : OclAny := _tuple->at(_indx);
      try (    var x : String := f->indexOf(0) - 1 ;
    return x, y)
(except_clause except (test (logical_test (comparison (expr (atom (name ValueError)))))) : (suite (stmt (simple_stmt (small_stmt pass))))));
  operation recursive(i : OclAny, fixed : OclAny) : OclAny
  pre: true post: true
  activity:
    if i = 9 then (
      return 1
    ) else skip ;
    var result : int := 0 ;
    var y : OclAny := null;
    Sequence{x,y} := get_index(fixed) ;
    fixed[y+1]->at(x) := i ;
    for _tuple : ds do (var _indx : int := 1;
      var dx : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var dy : OclAny := _tuple->at(_indx);
      var x2 : OclAny := null;
    var y2 : OclAny := null;
    Sequence{x2,y2} := Sequence{x + dx,y + dy} ;
    if not((0 <= x2 & (x2 < 4) & 0 <= y2 & (y2 < 4))) then (
      continue
    ) else skip ;
    if fixed[y2+1][x2+1] then (
      continue
    ) else skip ;
    fixed[y2+1][x2+1] := i ;
    result := result + recursive(i + 1, fixed) ;
    fixed[y2+1][x2+1] := 0) ;
    fixed[y+1]->at(x) := 0 ;
    return result;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def get_index(DATA):
    for y,f in enumerate(DATA):
        try :
            x=f.index(0)
            return x,y
        except ValueError :
            pass
def solve(i,DATA):
    if i==9 :
        return 1
    result=0
    x1,y1=get_index(DATA)
    DATA[y1][x1]=i
    for dx,dy in ds :
        x2=x1+dx
        y2=y1+dy
        if not(0<=x2<4 and 0<=y2<4):
            continue
        if DATA[y2][x2]:
            continue
        DATA[y2][x2]=i
        result+=solve(i+1,DATA)
        DATA[y2][x2]=0
    DATA[y1][x1]=0
    return result
while True :
    data=list(map(int,input().split()))
    if len(data)==1 :
        break
    ds=list(zip(*[iter(data)]*2))
    print(solve(1,[[0]*4 for _ in range(4)]))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    while true do (    var data : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if (data)->size() = 1 then (
      break
    ) else skip ;
    var ds : Sequence := (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name data)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name data)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name data)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))`third->at(_indx)} )) ;
    execute (solve(1, Integer.subrange(0, 4-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 4)))))->display());
  operation get_index(DATA : OclAny) : OclAny
  pre: true post: true
  activity:
    for _tuple : Integer.subrange(1, (DATA)->size())->collect( _indx | Sequence{_indx-1, (DATA)->at(_indx)} ) do (var _indx : int := 1;
      var y : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var f : OclAny := _tuple->at(_indx);
      try (    var x : String := f->indexOf(0) - 1 ;
    return x, y)
(except_clause except (test (logical_test (comparison (expr (atom (name ValueError)))))) : (suite (stmt (simple_stmt (small_stmt pass))))));
  operation solve(i : OclAny, DATA : OclAny) : OclAny
  pre: true post: true
  activity:
    if i = 9 then (
      return 1
    ) else skip ;
    var result : int := 0 ;
    var x1 : OclAny := null;
    var y1 : OclAny := null;
    Sequence{x1,y1} := get_index(DATA) ;
    DATA[y1+1][x1+1] := i ;
    for _tuple : ds do (var _indx : int := 1;
      var dx : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var dy : OclAny := _tuple->at(_indx);
      var x2 : OclAny := x1 + dx ;
    var y2 : OclAny := y1 + dy ;
    if not((0 <= x2 & (x2 < 4) & 0 <= y2 & (y2 < 4))) then (
      continue
    ) else skip ;
    if DATA[y2+1][x2+1] then (
      continue
    ) else skip ;
    DATA[y2+1][x2+1] := i ;
    result := result + solve(i + 1, DATA) ;
    DATA[y2+1][x2+1] := 0) ;
    DATA[y1+1][x1+1] := 0 ;
    return result;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    n=int(input())
    s=list(input())
    if n % 2==0 :
        i=n/2-1
    else :
        i=n//2
    j=n//2
    s.append("")
    if i==j :
        ans=1
        while s[i]==s[i+1]:
            ans+=2
            i+=1
    else :
        ans=2
        while s[j]==s[j+1]:
            ans+=2
            j+=1
    print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ;
    if n mod 2 = 0 then  (
      var i : double := n / 2 - 1
    )
    else (
      i := n div 2
      ) ;
    var j : int := n div 2 ;
    execute (("") : s) ;
    if i = j then  (
      var ans : int := 1 ;
    while s[i+1] = s[i + 1+1] do (    ans := ans + 2 ;
    i := i + 1)
    )
    else (
      ans := 2 ;
    while s[j+1] = s[j + 1+1] do (    ans := ans + 2 ;
    j := j + 1)
      ) ;
    execute (ans)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
arr=input().split()
for i in range(n):
    arr[i]=int(arr[i])
min=arr[0]
for i in range(1,n):
    if arr[i]min):
            result=arr[i]
    else :
        if arr[i]>min :
            result=arr[i]
print(result)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var arr : OclAny := input().split() ;
    for i : Integer.subrange(0, n-1) do (    arr[i+1] := ("" + ((arr[i+1])))->toInteger()) ;
    var min : OclAny := arr->first() ;
    for i : Integer.subrange(1, n-1) do (    if (arr[i+1]->compareTo(min)) < 0 then (
      min := arr[i+1]
    ) else skip) ;
    var result : String := "NO" ;
    for i : Integer.subrange(0, n-1) do (    if result /= "NO" then  (
      if MathLib.bitwiseAnd((arr[i+1] < result), ((arr[i+1]->compareTo(min)) > 0)) then (
      result := arr[i+1]
    ) else skip
    )
    else (
      if (arr[i+1]->compareTo(min)) > 0 then (
      result := arr[i+1]
    ) else skip
      )) ;
    execute (result)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
dummy=int(input())
s=sorted(list(set(map(int,input().strip().split()))))
if len(s)==1 :
    print("NO")
else :
    print(s[1])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var dummy : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : Sequence := (Set{}->union(((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ))))->sort() ;
    if (s)->size() = 1 then  (
      execute ("NO")->display()
    )
    else (
      execute (s[1+1])->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
num=int(input())
t=sorted(list(set(map(int,input().strip().split()))))
if len(t)==1 :
    print("NO")
else :
    print(t[1])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var t : Sequence := (Set{}->union(((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ))))->sort() ;
    if (t)->size() = 1 then  (
      execute ("NO")->display()
    )
    else (
      execute (t[1+1])->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a=list(map(int,input().split()))
s=sorted(list(set(a)))
if len(s)<=1 :
    print("NO")
else :
    print(s[1])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var s : Sequence := (Set{}->union((a)))->sort() ;
    if (s)->size() <= 1 then  (
      execute ("NO")->display()
    )
    else (
      execute (s[1+1])->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
s=sorted(list(set(map(int,input().strip().split()))))
if len(s)==1 :
    print("NO")
else :
    print(s[1])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : Sequence := (Set{}->union(((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ))))->sort() ;
    if (s)->size() = 1 then  (
      execute ("NO")->display()
    )
    else (
      execute (s[1+1])->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,h=map(int,input().split())
for i in range(h,n,-1):
    if all(i % j for j in range(2,min(int(i**.5),n)+1)): print(i); exit()
print(-1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var h : OclAny := null;
    Sequence{n,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    for i : Integer.subrange(n + 1, h)->reverse() do (    if ((argument (test (logical_test (comparison (expr (expr (atom (name i))) % (expr (atom (name j))))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) ** (expr (atom (number .5))))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))) + (expr (atom (number (integer 1)))))))))) )))))))))->forAll( _x | _x = true ) then (
      execute (i)->display();    exit()
    ) else skip) ;
    execute (-1)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
p,y=map(int,input().split())
ans=-1
flag=True
if(y % 2==0):
    y-=1
for i in range(y,p-1,-2):
    for j in range(3,p+1,2):
        if(j>31621):
            break
        if(i % j==0):
            flag=False
            break
    if(flag==True):
        ans=i
        break
    flag=True
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var p : OclAny := null;
    var y : OclAny := null;
    Sequence{p,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var ans : int := -1 ;
    var flag : boolean := true ;
    if (y mod 2 = 0) then (
      y := y - 1
    ) else skip ;
    for i : Integer.subrange(y, p - 1-1)->select( $x | ($x - y) mod -2 = 0 ) do (    for j : Integer.subrange(3, p + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do (    if (j > 31621) then (
      break
    ) else skip ;
    if (i mod j = 0) then (
      flag := false ;
    break
    ) else skip) ;
    if (flag = true) then (
      ans := i ;
    break
    ) else skip ;
    flag := true) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b,c,d=map(int,input().split())
print(max(0,min(b,d)-max(a,c)))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    var d : OclAny := null;
    Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (Set{0, Set{b, d}->min() - Set{a, c}->max()}->max())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
p,y=map(int,input().split())
ans=-1
while y>p :
    flag,i=1,2
    while i<=p and i**2<=y :
        if y % i==0 :
            flag=0
            break
        i+=1
    if flag :
        ans=y
        break
    y-=1
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var p : OclAny := null;
    var y : OclAny := null;
    Sequence{p,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var ans : int := -1 ;
    while (y->compareTo(p)) > 0 do (    var flag : OclAny := null;
    var i : OclAny := null;
    Sequence{flag,i} := Sequence{1,2} ;
    while (i->compareTo(p)) <= 0 & ((i)->pow(2)->compareTo(y)) <= 0 do (    if y mod i = 0 then (
      var flag : int := 0 ;
    break
    ) else skip ;
    i := i + 1) ;
    if flag then (
      ans := y ;
    break
    ) else skip ;
    y := y - 1) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import Counter
from sys import*
from collections import defaultdict as dd
from math import*
def inp():
    return int(stdin.readline().strip())
def vinp():
    return map(int,stdin.readline().strip().split())
def linp():
    return list(map(int,stdin.readline().strip().split()))
def sinp(n=1):
    if n==1 :
        return stdin.readline().strip()
    elif n==2 :
        return list(stdin.readline().strip())
    else :
        return list(stdin.readline().split())
def pr(*x,end="\n"):
    print(*x,end=end)
def mod(f,val=1000000007):
    return f % val
def csort(c):
    sorted(c.items(),key=lambda pair : pair[1],reverse=True)
def indc(l,n):
    c={}
    for i in range(n):
        c[l[i]]=c.get(l[i],[])+[i+1]
    return c
if __name__=="__main__" :
    p,y=vinp()
    ans=-1
    while y>p :
        flag,i=1,2
        while i<=p and i**2<=y :
            if y % i==0 :
                flag=0
                break
            i+=1
        if flag :
            ans=y
            break
        y-=1
    pr(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      var p : OclAny := null;
    var y : OclAny := null;
    Sequence{p,y} := vinp() ;
    var ans : int := -1 ;
    while (y->compareTo(p)) > 0 do (    var flag : OclAny := null;
    var i : OclAny := null;
    Sequence{flag,i} := Sequence{1,2} ;
    while (i->compareTo(p)) <= 0 & ((i)->pow(2)->compareTo(y)) <= 0 do (    if y mod i = 0 then (
      var flag : int := 0 ;
    break
    ) else skip ;
    i := i + 1) ;
    if flag then (
      ans := y ;
    break
    ) else skip ;
    y := y - 1) ;
    pr(ans)
    ) else skip;
  operation inp() : OclAny
  pre: true post: true
  activity:
    return ("" + ((stdin.readLine()->trim())))->toInteger();
  operation vinp() : OclAny
  pre: true post: true
  activity:
    return (stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) );
  operation linp() : OclAny
  pre: true post: true
  activity:
    return ((stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ));
  operation sinp(n : int) : OclAny
  pre: true post: true
  activity:
    if n->oclIsUndefined() then n := 1 else skip;
    if n = 1 then  (
      return stdin.readLine()->trim()
    )
    else (if n = 2 then
   (
      return (stdin.readLine()->trim())    
)
    else (
      return (stdin.readLine().split())
      )    )
;
  operation pr(x : OclAny : Sequence(OclAny), end : String)
  pre: true post: true
  activity:
(args * (named_parameter (name x)))    if end->oclIsUndefined() then end := "\n" else skip;
    execute ((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display();
  operation mod(f : OclAny, val : int) : OclAny
  pre: true post: true
  activity:
    if val->oclIsUndefined() then val := 1000000007 else skip;
    return f mod val;
  operation csort(c : OclAny)
  pre: true post: true
  activity:
    sorted(c->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name pair)))) : (test (logical_test (comparison (expr (atom (name pair)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))), (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True))))))));
  operation indc(l : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    c := Set{} ;
    for i : Integer.subrange(0, n-1) do (    c[l[i+1]+1] := c.get(l[i+1], Sequence{})->union(Sequence{ i + 1 })) ;
    return c;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
p,y=input().split()
p=int(p)
y=int(y)
ans=-1
for x in range(y,p,-1):
    flg=1
    for i in range(2,p+1):
        if i*i>x :
            break
        if(x % i==0):
            flg=0
            break
    if(flg==1):
        ans=x
        break
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var p : OclAny := null;
    var y : OclAny := null;
    Sequence{p,y} := input().split() ;
    var p : int := ("" + ((p)))->toInteger() ;
    var y : int := ("" + ((y)))->toInteger() ;
    var ans : int := -1 ;
    for x : Integer.subrange(p + 1, y)->reverse() do (    var flg : int := 1 ;
    for i : Integer.subrange(2, p + 1-1) do (    if (i * i->compareTo(x)) > 0 then (
      break
    ) else skip ;
    if (x mod i = 0) then (
      flg := 0 ;
    break
    ) else skip) ;
    if (flg = 1) then (
      ans := x ;
    break
    ) else skip) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for s in[*open(0)][2 : : 2]: n=len(s)-1 ; print(n-2*len(s[n//2 :].strip(s[n//2]))+2)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do (    var n : double := (s)->size() - 1;    execute (n - 2 * (s.subrange(n div 2+1)->trim())->size() + 2)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def findSum(n):
    sum2=((n//2)*(4+(n//2-1)*2))//2
    sum5=((n//5)*(10+(n//5-1)*5))//2
    sum10=((n//10)*(20+(n//10-1)*10))//2
    return sum2+sum5-sum10 ;
if __name__=='__main__' :
    n=5
    print(int(findSum(n)))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      n := 5 ;
    execute (("" + ((findSum(n))))->toInteger())->display()
    ) else skip;
  operation findSum(n : OclAny)
  pre: true post: true
  activity:
    var sum2 : int := ((n div 2) * (4 + (n div 2 - 1) * 2)) div 2 ;
    var sum5 : int := ((n div 5) * (10 + (n div 5 - 1) * 5)) div 2 ;
    var sum10 : int := ((n div 10) * (20 + (n div 10 - 1) * 10)) div 2 ;
    return sum2 + sum5 - sum10;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def maxRegions(n):
    num=n*(n+1)//2+1
    print(num)
n=10
maxRegions(n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    n := 10 ;
    maxRegions(n);
  operation maxRegions(n : OclAny)
  pre: true post: true
  activity:
    var num : int := n * (n + 1) div 2 + 1 ;
    execute (num)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def findTriangles(n):
    num=n*(n-4)
    print(num)
n=6
findTriangles(n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    n := 6 ;
    findTriangles(n);
  operation findTriangles(n : OclAny)
  pre: true post: true
  activity:
    var num : double := n * (n - 4) ;
    execute (num)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def isPrime(n):
    for i in range(2,int(n**.5+1)):
        if n % i==0 :
            return False
    return True
while 1 :
    n=int(input())
    if not n : break
    for i in range(n,1,-1):
        if isPrime(i)and isPrime(i-2):
            print(i-2,i)
            break
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    while 1 do (    n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if not(n) then (
      break
    ) else skip ;
    for i : Integer.subrange(1 + 1, n)->reverse() do (    if isPrime(i) & isPrime(i - 2) then (
      execute (i - 2)->display() ;
    break
    ) else skip));
  operation isPrime(n : OclAny) : OclAny
  pre: true post: true
  activity:
    for i : Integer.subrange(2, ("" + (((n)->pow(.5) + 1)))->toInteger()-1) do (    if n mod i = 0 then (
      return false
    ) else skip) ;
    return true;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys,math,os,bisect
PYDEV=os.environ.get('PYDEV')
if PYDEV=="True" :
    sys.stdin=open("sample-input.txt","rt")
def primes2(n):
    n,correction=n-n % 6+6,2-(n % 6>1)
    sieve=[True]*(n//3)
    for i in range(1,int(n**0.5)//3+1):
        if sieve[i]:
            k=3*i+1 | 1
            sieve[k*k//3 : : 2*k]=[False]*((n//6-k*k//6-1)//k+1)
            sieve[k*(k-2*(i & 1)+4)//3 : : 2*k]=[False]*((n//6-k*(k-2*(i & 1)+4)//6-1)//k+1)
    return[2,3]+[3*i+1 | 1 for i in range(1,n//3-correction)if sieve[i]]
primes=primes2(10050)
while True :
    n=int(input())
    if n==0 :
        break
    idx=bisect.bisect_left(primes,n)
    while True :
        if primes[idx]>n :
            idx-=1
        if primes[idx]-primes[idx-1]==2 :
            print(primes[idx-1],primes[idx])
            break
        idx-=1
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var PYDEV : OclAny := os.environ.get('PYDEV') ;
    if PYDEV = "True" then (
      OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt"))
    ) else skip ;
    skip ;
    var primes : OclAny := primes2(10050) ;
    while true do (    n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    var idx : OclAny := bisect.bisect_left(primes, n) ;
    while true do (    if (primes[idx+1]->compareTo(n)) > 0 then (
      idx := idx - 1
    ) else skip ;
    if primes[idx+1] - primes[idx - 1+1] = 2 then (
      execute (primes[idx - 1+1])->display() ;
    break
    ) else skip ;
    idx := idx - 1));
  operation primes2(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var correction : OclAny := null;
    Sequence{n,correction} := Sequence{n - n mod 6 + 6,2 - (n mod 6 > 1)} ;
    var sieve : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (n div 3)) ;
    for i : Integer.subrange(1, ("" + (((n)->pow(0.5))))->toInteger() div 3 + 1-1) do (    if sieve[i+1] then (
      var k : int := MathLib.bitwiseOr(3 * i + 1, 1) ;
    sieve(subscript (test (logical_test (comparison (expr (expr (expr (atom (name k))) * (expr (atom (name k)))) // (expr (atom (number (integer 3)))))))) : (sliceop : (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name k))))))))) := MatrixLib.elementwiseMult(Sequence{ false }, ((n div 6 - k * k div 6 - 1) div k + 1)) ;
    sieve(subscript (test (logical_test (comparison (expr (expr (expr (atom (name k))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name k))) - (expr (expr (atom (number (integer 2)))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) & (expr (atom (number (integer 1))))))))) ))))) + (expr (atom (number (integer 4))))))))) )))) // (expr (atom (number (integer 3)))))))) : (sliceop : (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name k))))))))) := MatrixLib.elementwiseMult(Sequence{ false }, ((n div 6 - k * (k - 2 * (MathLib.bitwiseAnd(i, 1)) + 4) div 6 - 1) div k + 1))
    ) else skip) ;
    return Sequence{2}->union(Sequence{ 3 })->union(Integer.subrange(1, n div 3 - correction-1)->select(i | sieve[i+1])->collect(i | (MathLib.bitwiseOr(3 * i + 1, 1))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
from sys import stdin
from bisect import bisect_right
input=stdin.readline
def create_prime_list(limit):
    x=limit**0.5
    primes=[]
    nums=[x for x in range(2,limit+1)]
    while nums[0]<=x :
        primes.append(nums[0])
        current_prime=nums[0]
        nums=[x for x in nums if x % current_prime!=0]
    primes.extend(nums)
    return primes
def main(args):
    primes=create_prime_list(10000)
    twin_primes=[]
    prev=primes[0]
    for p in primes[1 :]:
        if p==prev+2 :
            twin_primes.append(p)
        prev=p
    while True :
        n=int(input())
        if n==0 :
            break
        r=bisect_right(twin_primes,n)
        print(twin_primes[r-1]-2,twin_primes[r-1])
if __name__=='__main__' :
    main(sys.argv[1 :])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    var input : OclAny := stdin.readline ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))
    ) else skip;
  operation create_prime_list(limit : OclAny) : OclAny
  pre: true post: true
  activity:
    var x : double := (limit)->pow(0.5) ;
    var primes : Sequence := Sequence{} ;
    var nums : Sequence := Integer.subrange(2, limit + 1-1)->select(x | true)->collect(x | (x)) ;
    while (nums->first()->compareTo(x)) <= 0 do (    execute ((nums->first()) : primes) ;
    var current_prime : OclAny := nums->first() ;
    nums := nums->select(x | x mod current_prime /= 0)->collect(x | (x))) ;
    primes := primes->union(nums) ;
    return primes;
  operation main(args : OclAny)
  pre: true post: true
  activity:
    primes := create_prime_list(10000) ;
    var twin_primes : Sequence := Sequence{} ;
    var prev : OclAny := primes->first() ;
    for p : primes->tail() do (    if p = prev + 2 then (
      execute ((p) : twin_primes)
    ) else skip ;
    prev := p) ;
    while true do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    var r : OclAny := bisect_right(twin_primes, n) ;
    execute (twin_primes[r - 1+1] - 2)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b,c,d=map(int,input().split())
ans=0
if a<=c :
    if b<=c :
        pass
    elif b<=d :
        ans=b-c
    else :
        ans=d-c
else :
    if d<=a :
        pass
    elif d<=b :
        ans=d-a
    else :
        ans=b-a
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    var d : OclAny := null;
    Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var ans : int := 0 ;
    if (a->compareTo(c)) <= 0 then  (
      if (b->compareTo(c)) <= 0 then  (
      skip
    )
    else (if (b->compareTo(d)) <= 0 then
   (
      ans := b - c    
)
    else (
      ans := d - c
      )    )
    )
    else (
      if (d->compareTo(a)) <= 0 then  (
      skip
    )
    else (if (d->compareTo(b)) <= 0 then
   (
      ans := d - a    
)
    else (
      ans := b - a
      )    )
      ) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def get_input():
    while True :
        try :
            yield ''.join(input())
        except EOFError :
            break
MAX=10001
primes=list()
for i in range(MAX):
    primes.append(True)
primes[0]=False
primes[1]=False
tprimes=[False for i in range(MAX)]
for i in range(2,MAX):
    j=i+i
    while jfirst() := false ;
    primes[1+1] := false ;
    var tprimes : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (false)) ;
    for i : Integer.subrange(2, MAX-1) do (    var j : OclAny := i + i ;
    while (j->compareTo(MAX)) < 0 do (    primes[j+1] := false ;
    j := j + i)) ;
    for i : Integer.subrange(2, MAX-1) do (    if primes[i+1] & primes[i - 2+1] then (
      tprimes[i+1] := true
    ) else skip) ;
    while true do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    for i : Integer.subrange(-1 + 1, n)->reverse() do (    if tprimes[i+1] then (
      execute (i - 2)->display() ;
    break
    ) else skip));
  operation get_input(_position_ : int) : OclAny
  pre: true post: true
  activity:
    var _yieldCount_ : int := 0;
    while true do (    try (    if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return StringLib.sumStringsWithSeparator(((OclFile["System.in"]).readLine()), ''))
(except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
MAX=10000
def is_prime_number(num):
    for divisor in range(3,int(math.sqrt(num)+1),2):
        if num % divisor==0 :
            return False
    return True
def create_prime_number_list(max):
    prime_number_list=list(range(0,max+1))
    prime_number_list[0]=False
    prime_number_list[1]=False
    for index in range(2*2,max+1,2):
        prime_number_list[index]=False
    for num in range(3,int(math.sqrt(max+1)),2):
        if is_prime_number(num):
            for index in range(num*2,max+1,num):
                prime_number_list[index]=False
    return prime_number_list
prime_number_list=create_prime_number_list(MAX)
output=[]
while True :
    num=int(input())
    if num==0 :
        break
    if num % 2==0 :
        num-=1
    for index in range(num,0,-2):
        if prime_number_list[index-2]and prime_number_list[index]:
            output.append(str(index-2)+" "+str(index))
            break
print("\n".join(output))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var MAX : int := 10000 ;
    skip ;
    skip ;
    prime_number_list := create_prime_number_list(MAX) ;
    var output : Sequence := Sequence{} ;
    while true do (    num := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if num = 0 then (
      break
    ) else skip ;
    if num mod 2 = 0 then (
      num := num - 1
    ) else skip ;
    for index : Integer.subrange(num, 0-1)->select( $x | ($x - num) mod -2 = 0 ) do (    if prime_number_list[index - 2+1] & prime_number_list[index+1] then (
      execute ((("" + ((index - 2))) + " " + ("" + ((index)))) : output) ;
    break
    ) else skip)) ;
    execute (StringLib.sumStringsWithSeparator((output), "\n"))->display();
  operation is_prime_number(num : OclAny) : OclAny
  pre: true post: true
  activity:
    for divisor : Integer.subrange(3, ("" + (((num)->sqrt() + 1)))->toInteger()-1)->select( $x | ($x - 3) mod 2 = 0 ) do (    if num mod divisor = 0 then (
      return false
    ) else skip) ;
    return true;
  operation create_prime_number_list(max : OclAny) : OclAny
  pre: true post: true
  activity:
    var prime_number_list : Sequence := (Integer.subrange(0, max + 1-1)) ;
    prime_number_list->first() := false ;
    prime_number_list[1+1] := false ;
    for index : Integer.subrange(2 * 2, max + 1-1)->select( $x | ($x - 2 * 2) mod 2 = 0 ) do (    prime_number_list[index+1] := false) ;
    for num : Integer.subrange(3, ("" + (((max + 1)->sqrt())))->toInteger()-1)->select( $x | ($x - 3) mod 2 = 0 ) do (    if is_prime_number(num) then (
      for index : Integer.subrange(num * 2, max + 1-1)->select( $x | ($x - num * 2) mod num = 0 ) do (    prime_number_list[index+1] := false)
    ) else skip) ;
    return prime_number_list;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def isPalin(str):
    l=len(str)//2
    for i in range(l):
        if(str[i]!=str[len(str)-i-1]):
            return False
    return True
def palindromicPath(str,a,i,j,m,n):
    if(junion(Sequence{'a'}->union(Sequence{'a'}->union(Sequence{ 'b' })))}->union(Sequence{Sequence{'b'}->union(Sequence{'a'}->union(Sequence{'a'}->union(Sequence{ 'a' })))}->union(Sequence{ Sequence{'a'}->union(Sequence{'b'}->union(Sequence{'b'}->union(Sequence{ 'a' }))) })) ;
    OclType["String"] := "" ;
    palindromicPath(OclType["String"], arr, 0, 0, 4, 3)
    ) else skip;
  operation isPalin(OclType["String"] : OclAny) : OclAny
  pre: true post: true
  activity:
    var l : int := (OclType["String"])->size() div 2 ;
    for i : Integer.subrange(0, l-1) do (    if (("" + ([i+1])) /= ("" + ([(OclType["String"])->size() - i - 1+1]))) then (
      return false
    ) else skip) ;
    return true;
  operation palindromicPath(OclType["String"] : OclAny, a : OclAny, i : OclAny, j : OclAny, m : OclAny, n : OclAny)
  pre: true post: true
  activity:
    if ((j->compareTo(m - 1)) < 0 or (i->compareTo(n - 1)) < 0) then  (
      if ((i->compareTo(n - 1)) < 0) then (
      palindromicPath(OclType["String"] + a[i+1][j+1], a, i + 1, j, m, n)
    ) else skip ;
    if ((j->compareTo(m - 1)) < 0) then (
      palindromicPath(OclType["String"] + a[i+1][j+1], a, i, j + 1, m, n)
    ) else skip
    )
    else (
      OclType["String"] := OclType["String"] + a[n - 1+1][m - 1+1] ;
    if isPalin(OclType["String"]) then (
      execute (OclType["String"])->display()
    ) else skip
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for i in range(int(input())):
    n1,n2=map(int,input().split())
    a_dados=list(map(int,input().split()))
    p_posicoes=list(map(int,input().split()))
    for i in range(n2):
        for j in p_posicoes :
            if a_dados[j-1]>a_dados[j]:
                a_dados[j-1],a_dados[j]=a_dados[j],a_dados[j-1]
    if a_dados!=sorted(a_dados):
        print("NO")
    else :
        print("YES")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n1 : OclAny := null;
    var n2 : OclAny := null;
    Sequence{n1,n2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a_dados : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var p_posicoes : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    for i : Integer.subrange(0, n2-1) do (    for j : p_posicoes do (    if (a_dados[j - 1+1]->compareTo(a_dados[j+1])) > 0 then (
      var a_dados[j - 1+1] : OclAny := null;
    var a_dados[j+1] : OclAny := null;
    Sequence{a_dados[j - 1+1],a_dados[j+1]} := Sequence{a_dados[j+1],a_dados[j - 1+1]}
    ) else skip)) ;
    if a_dados /= a_dados->sort() then  (
      execute ("NO")->display()
    )
    else (
      execute ("YES")->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def minimumProduct(arr,n):
    arr=sorted(arr)
    product=1
    for i in range(0,n,2):
        product*=(arr[i]+arr[i+1])
    return product
arr=[1,6,3,1,7,8]
n=len(arr)
print(minimumProduct(arr,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    arr := Sequence{1}->union(Sequence{6}->union(Sequence{3}->union(Sequence{1}->union(Sequence{7}->union(Sequence{ 8 }))))) ;
    n := (arr)->size() ;
    execute (minimumProduct(arr, n))->display();
  operation minimumProduct(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    arr := arr->sort() ;
    var product : int := 1 ;
    for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do (    product := product * (arr[i+1] + arr[i + 1+1])) ;
    return product;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for i in range(int(input())):
    n=int(input())
    s=input()
    a=n//2
    res=1
    b=a
    while btoInteger()-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : String := (OclFile["System.in"]).readLine() ;
    var a : int := n div 2 ;
    var res : int := 1 ;
    var b : int := a ;
    while (b->compareTo(n - 1)) < 0 & s[b+1] = s[b + 1+1] do (    res := res + 1 ;
    b := b + 1) ;
    execute (res * 2 - n mod 2)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for i in range(t):
    n,m=list(map(int,input().split()))
    a=list(map(int,input().split()))
    p=list(map(int,input().split()))
    js=[]
    final=sorted(a)
    while a!=final :
        for j in range(n-1):
            if a[j]>a[j+1]:
                js.append(j+1)
                a[j],a[j+1]=a[j+1],a[j]
    if(all(x in p for x in js)):
        print("YES")
    else :
        print("NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, t-1) do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var js : Sequence := Sequence{} ;
    var final : Sequence := a->sort() ;
    while a /= final do (    for j : Integer.subrange(0, n - 1-1) do (    if (a[j+1]->compareTo(a[j + 1+1])) > 0 then (
      execute ((j + 1) : js) ;
    var a[j+1] : OclAny := null;
    var a[j + 1+1] : OclAny := null;
    Sequence{a[j+1],a[j + 1+1]} := Sequence{a[j + 1+1],a[j+1]}
    ) else skip)) ;
    if (((argument (test (logical_test (comparison (comparison (expr (atom (name x)))) in (comparison (expr (atom (name p))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name js))))))))->forAll( _x | _x = true )) then  (
      execute ("YES")->display()
    )
    else (
      execute ("NO")->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for _ in range(t):
    n,m=map(int,input().split())
    l=[False]*n
    arr=list(map(int,input().split()))
    pi=list(map(int,input().split()))
    for p in pi :
        l[p-1]=True
    f=True
    i=0
    while iarr[i+1]:
            f=False
            break
    print("YES" if f else "NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, t-1) do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var l : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ;
    var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var pi : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    for p : pi do (    l[p - 1+1] := true) ;
    var f : boolean := true ;
    var i : int := 0 ;
    while (i->compareTo(n)) < 0 do (    if not(l[i+1]) then (
      i := i + 1 ;
    continue
    ) else skip ;
    var idx : int := i ;
    while (idx->compareTo(n)) < 0 & l[idx+1] do (    idx := idx + 1) ;
    arr.subrange(i+1, idx + 1) := arr.subrange(i+1, idx + 1)->sort() ;
    i := idx) ;
    for i : Integer.subrange(0, (arr)->size() - 1-1) do (    if (arr[i+1]->compareTo(arr[i + 1+1])) > 0 then (
      f := false ;
    break
    ) else skip) ;
    execute (if f then "YES" else "NO" endif)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
import math
import itertools
input=sys.stdin.readline
def solve():
    n,m=map(int,input().split())
    dat=list(map(int,input().split()))
    p=list(map(int,input().split()))
    if dat==sorted(dat):
        print('YES')
    else :
        for i in range(n-1):
            for j in range(n-1):
                if dat[j]>dat[j+1]and j+1 in p :
                    dat[j],dat[j+1]=dat[j+1],dat[j]
        print('YES' if dat==sorted(dat)else 'NO')
for _ in range(int(input())):
    solve()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    skip ;
    for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    solve());
  operation solve()
  pre: true post: true
  activity:
    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var dat : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if dat = dat->sort() then  (
      execute ('YES')->display()
    )
    else (
      for i : Integer.subrange(0, n - 1-1) do (    for j : Integer.subrange(0, n - 1-1) do (    if (dat[j+1]->compareTo(dat[j + 1+1])) > 0 & (p)->includes(j + 1) then (
      var dat[j+1] : OclAny := null;
    var dat[j + 1+1] : OclAny := null;
    Sequence{dat[j+1],dat[j + 1+1]} := Sequence{dat[j + 1+1],dat[j+1]}
    ) else skip)) ;
    execute (if dat = dat->sort() then 'YES' else 'NO' endif)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import deque,defaultdict,Counter
from heapq import heappush,heappop,heapify
from math import inf,sqrt,ceil,log2
from functools import lru_cache
from itertools import accumulate,combinations,permutations,product
from typing import List
from bisect import bisect_left,bisect_right
import sys
import string
input=lambda : sys.stdin.readline().strip('\n')
mis=lambda : map(int,input().split())
ii=lambda : int(input())
T=ii()
for _ in range(T):
    N,M=mis()
    A=list(mis())
    P=set(mis())
    sorted_A=[]
    cur_A=[]
    for i,a in enumerate(A):
        if i in P or i+1 in P :
            cur_A.append(a)
            cur_A.sort()
        else :
            cur_A.append(a)
        if i+1 not in P :
            sorted_A.extend(cur_A)
            cur_A=[]
    sorted_A.extend(cur_A)
    ans="YES"
    for i in range(N-1):
        if sorted_A[i]>sorted_A[i+1]:
            ans="NO"
    print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var input : Function := lambda $$ : OclAny in (sys.stdin.readLine()->trim()) ;
    var mis : Function := lambda $$ : OclAny in ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var ii : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ;
    var T : OclAny := ii->apply() ;
    for _anon : Integer.subrange(0, T-1) do (    var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := mis->apply() ;
    var A : Sequence := (mis->apply()) ;
    var P : Set := Set{}->union((mis->apply())) ;
    var sorted_A : Sequence := Sequence{} ;
    var cur_A : Sequence := Sequence{} ;
    for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var a : OclAny := _tuple->at(_indx);
      if (P)->includes(i) or (P)->includes(i + 1) then  (
      execute ((a) : cur_A) ;
    cur_A := cur_A->sort()
    )
    else (
      execute ((a) : cur_A)
      ) ;
    if (P)->excludes(i + 1) then (
      sorted_A := sorted_A->union(cur_A) ;
    cur_A := Sequence{}
    ) else skip) ;
    sorted_A := sorted_A->union(cur_A) ;
    var ans : String := "YES" ;
    for i : Integer.subrange(0, N - 1-1) do (    if (sorted_A[i+1]->compareTo(sorted_A[i + 1+1])) > 0 then (
      ans := "NO"
    ) else skip) ;
    execute (ans)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b,c,d=map(int,input().split())
lisa=[]
lisb=[]
for n in range((b-a)+1):
    lisa.append(n+a)
for m in range((d-c)+1):
    lisb.append(m+c)
ans=0
for i in range(101):
    if i in lisa and i in lisb :
        ans+=1
if ans>0 :
    print(ans-1)
else :
    print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    var d : OclAny := null;
    Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var lisa : Sequence := Sequence{} ;
    var lisb : Sequence := Sequence{} ;
    for n : Integer.subrange(0, (b - a) + 1-1) do (    execute ((n + a) : lisa)) ;
    for m : Integer.subrange(0, (d - c) + 1-1) do (    execute ((m + c) : lisb)) ;
    var ans : int := 0 ;
    for i : Integer.subrange(0, 101-1) do (    if (lisa)->includes(i) & (lisb)->includes(i) then (
      ans := ans + 1
    ) else skip) ;
    if ans > 0 then  (
      execute (ans - 1)->display()
    )
    else (
      execute (ans)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def binomialCoeff(n,k):
    C=[[0 for i in range(k+1)]for i in range(n+1)]
    for i in range(0,n+1,1):
        for j in range(0,min(i,k)+1,1):
            if(j==0 or j==i):
                C[i][j]=1
            else :
                C[i][j]=C[i-1][j-1]+C[i-1][j]
    return C[n][k]
if __name__=='__main__' :
    n=5
    k=3
    print("Total number of different ways are",binomialCoeff(n-1,k-1))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      n := 5 ;
    k := 3 ;
    execute ("Total number of different ways are")->display()
    ) else skip;
  operation binomialCoeff(n : OclAny, k : OclAny) : OclAny
  pre: true post: true
  activity:
    var C : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, k + 1-1)->select(i | true)->collect(i | (0)))) ;
    for i : Integer.subrange(0, n + 1-1)->select( $x | ($x - 0) mod 1 = 0 ) do (    for j : Integer.subrange(0, Set{i, k}->min() + 1-1)->select( $x | ($x - 0) mod 1 = 0 ) do (    if (j = 0 or j = i) then  (
      C[i+1][j+1] := 1
    )
    else (
      C[i+1][j+1] := C[i - 1+1][j - 1+1] + C[i - 1+1][j+1]
      ))) ;
    return C[n+1][k+1];
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def CheckSubarray(arr,N):
    presum=[0 for i in range(N+1)]
    for i in range(1,N+1):
        presum[i]=presum[i-1]+arr[i-1]
    for i in range(1,N+1):
        for j in range(i,N+1):
            if((presum[j]-presum[i-1])% N==0):
                print(i-1,j-1)
                return
    print("-1")
arr=[7,5,3,7]
N=len(arr)
CheckSubarray(arr,N)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    arr := Sequence{7}->union(Sequence{5}->union(Sequence{3}->union(Sequence{ 7 }))) ;
    N := (arr)->size() ;
    CheckSubarray(arr, N);
  operation CheckSubarray(arr : OclAny, N : OclAny)
  pre: true post: true
  activity:
    var presum : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (0)) ;
    for i : Integer.subrange(1, N + 1-1) do (    presum[i+1] := presum[i - 1+1] + arr[i - 1+1]) ;
    for i : Integer.subrange(1, N + 1-1) do (    for j : Integer.subrange(i, N + 1-1) do (    if ((presum[j+1] - presum[i - 1+1]) mod N = 0) then (
      execute (i - 1)->display() ;
    return
    ) else skip)) ;
    execute ("-1")->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def maxSum(a,n):
    maxAnd=max(a)
    maxOR=0
    for i in range(n):
        maxOR |=a[i]
    print(maxAnd+maxOR)
n=4
a=[3,5,6,1]
maxSum(a,n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    n := 4 ;
    a := Sequence{3}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 1 }))) ;
    maxSum(a, n);
  operation maxSum(a : OclAny, n : OclAny)
  pre: true post: true
  activity:
    var maxAnd : OclAny := (a)->max() ;
    var maxOR : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    maxOR := maxOR or a[i+1]) ;
    execute (maxAnd + maxOR)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import sqrt
def findGreatest(arr,n):
    m=dict()
    for i in arr :
        m[i]=m.get(i,0)+1
    arr=sorted(arr)
    for i in range(n-1,0,-1):
        j=0
        while(j0):
                    return arr[i]
                elif(result==arr[j]and(result in m.keys())and m[result]>1):
                    return arr[i]
            j+=1
    return-1
arr=[17,2,1,15,30]
n=len(arr)
print(findGreatest(arr,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    arr := Sequence{17}->union(Sequence{2}->union(Sequence{1}->union(Sequence{15}->union(Sequence{ 30 })))) ;
    n := (arr)->size() ;
    execute (findGreatest(arr, n))->display();
  operation findGreatest(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var m : Map := (arguments ( )) ;
    for i : arr do (    m[i+1] := m.get(i, 0) + 1) ;
    arr := arr->sort() ;
    for i : Integer.subrange(0 + 1, n - 1)->reverse() do (    var j : int := 0 ;
    while ((j->compareTo(i)) < 0 & (arr[j+1]->compareTo(sqrt(arr[i+1]))) <= 0) do (    if (arr[i+1] mod arr[j+1] = 0) then (
      var result : int := arr[i+1] div arr[j+1] ;
    if (result /= arr[j+1] & ((m.keys())->includes(result)) & m[result+1] > 0) then  (
      return arr[i+1]
    )
    else (if (result = arr[j+1] & ((m.keys())->includes(result)) & m[result+1] > 1) then
   (
      return arr[i+1]    
)
 else skip)
    ) else skip ;
    j := j + 1)) ;
    return -1;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def divisor(a):
    div=1 ;
    count=0 ;
    for i in range(2,int(pow(a,1/2))+1):
        while(a % i==0):
            count+=1 ;
            a=a/i ;
        div=div*(count+1);
        count=0 ;
    if(a>1):
        div=div*(2);
    return div ;
def OddDivCount(a,b):
    res=0 ;
    for i in range(a,b+1):
        divCount=divisor(i);
        if(divCount % 2):
            res+=1 ;
    return res ;
if __name__=='__main__' :
    a,b=1,10 ;
    print(OddDivCount(a,b));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = '__main__' then (
      Sequence{a,b} := Sequence{1,10}; ;
    execute (OddDivCount(a, b))->display();
    ) else skip;
  operation divisor(a : OclAny)
  pre: true post: true
  activity:
    var div : int := 1; ;
    var count : int := 0; ;
    for i : Integer.subrange(2, ("" + (((a)->pow(1 / 2))))->toInteger() + 1-1) do (    while (a mod i = 0) do (    count := count + 1; ;
    a := a / i;) ;
    div := div * (count + 1); ;
    count := 0;) ;
    if (a > 1) then (
      div := div * (2);
    ) else skip ;
    return div;;
  operation OddDivCount(a : OclAny, b : OclAny)
  pre: true post: true
  activity:
    var res : int := 0; ;
    for i : Integer.subrange(a, b + 1-1) do (    var divCount : OclAny := divisor(i); ;
    if (divCount mod 2) then (
      res := res + 1;
    ) else skip) ;
    return res;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines
N=[x-ord('0')for x in map(int,read().rstrip())][: :-1]
N=[9*x for x in N]+[0]*10
L=len(N)
for i in range(L-1):
    q,r=divmod(N[i],10)
    N[i]=r
    N[i+1]+=q
high1=sum(N[10 :])
N[10]+=1
for i in range(10,L-1):
    if N[i]==10 :
        N[i]=0
        N[i+1]+=1
high2=sum(N[10 :])
low=N[: 10]
low=sum(x*10**i for i,x in enumerate(N[: 10]))
A=10**10
def digit_sum(N):
    return sum(map(int,str(N)))
def test(x):
    if low+x>=A :
        return digit_sum(low+x)-1+high2<=x
    return digit_sum(low+x)+high1<=x
left=0
right=10**10
while left+1collect( _x | (OclType["int"])->apply(_x) )->select(x | true)->collect(x | (x - ('0')->char2byte()))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ;
    N := N->select(x | true)->collect(x | (9 * x))->union(MatrixLib.elementwiseMult(Sequence{ 0 }, 10)) ;
    var L : int := (N)->size() ;
    for i : Integer.subrange(0, L - 1-1) do (    var q : OclAny := null;
    var r : OclAny := null;
    Sequence{q,r} := Sequence{(N[i+1] div 10), (N[i+1] mod 10)} ;
    N[i+1] := r ;
    N[i + 1+1] := N[i + 1+1] + q) ;
    var high1 : OclAny := (N.subrange(10+1))->sum() ;
    N[10+1] := N[10+1] + 1 ;
    for i : Integer.subrange(10, L - 1-1) do (    if N[i+1] = 10 then (
      N[i+1] := 0 ;
    N[i + 1+1] := N[i + 1+1] + 1
    ) else skip) ;
    var high2 : OclAny := (N.subrange(10+1))->sum() ;
    var low : OclAny := N.subrange(1,10) ;
    low := ((argument (test (logical_test (comparison (expr (expr (atom (name x))) * (expr (expr (atom (number (integer 10)))) ** (expr (atom (name i)))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (number (integer 10))))))))) ])))))))) )))))))))->sum() ;
    var A : double := (10)->pow(10) ;
    skip ;
    skip ;
    var left : int := 0 ;
    var right : double := (10)->pow(10) ;
    while (left + 1->compareTo(right)) < 0 do (    x := (left + right) div 2 ;
    if test(x) then  (
      right := x
    )
    else (
      left := x
      )) ;
    var answer : int := (right + 8) div 9 ;
    execute (answer)->display();
  operation digit_sum(N : OclAny) : OclAny
  pre: true post: true
  activity:
    return ((("" + ((N))))->collect( _x | (OclType["int"])->apply(_x) ))->sum();
  operation test(x : OclAny) : OclAny
  pre: true post: true
  activity:
    if (low + x->compareTo(A)) >= 0 then (
      return (digit_sum(low + x) - 1 + high2->compareTo(x)) <= 0
    ) else skip ;
    return (digit_sum(low + x) + high1->compareTo(x)) <= 0;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
ans=list()
for i in range(0,t):
    n=int(input())
    string=[x for x in input()]
    count=0
    mid=len(string)//2
    if(mid==0):
        count=1
    elif(len(string)==2):
        count=2
    elif(len(string)% 2==1):
        count+=1
        for j in range(0,mid):
            if(string[mid+j]==string[mid+j+1]):
                count+=2
            else :
                break
    else :
        count+=2
        for j in range(0,mid-1):
            if(string[mid+j]==string[mid+j+1]):
                count+=2
            else :
                break
    ans.append(count)
for s in ans :
    print(s)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var ans : Sequence := () ;
    for i : Integer.subrange(0, t-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var string : Sequence := (OclFile["System.in"]).readLine()->select(x | true)->collect(x | (x)) ;
    var count : int := 0 ;
    var mid : int := (string)->size() div 2 ;
    if (mid = 0) then  (
      count := 1
    )
    else (if ((string)->size() = 2) then
   (
      count := 2    
)
    else (if ((string)->size() mod 2 = 1) then
   (
      count := count + 1 ;
    for j : Integer.subrange(0, mid-1) do (    if (string[mid + j+1] = string[mid + j + 1+1]) then  (
      count := count + 2
    )
    else (
      break
      ))    
)
    else (
      count := count + 2 ;
    for j : Integer.subrange(0, mid - 1-1) do (    if (string[mid + j+1] = string[mid + j + 1+1]) then  (
      count := count + 2
    )
    else (
      break
      ))
      )    )
    )
 ;
    execute ((count) : ans)) ;
    for s : ans do (    execute (s)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=list(input())
n.reverse()
lb,ub=0,len(n)
def check(x):
    g=0
    for i in n :
        x-=(x+g-int(i))% 10
        if x<0 :
            break
        g=(x+g)//10
    return x>=0
while ub-lb>1 :
    mid=(lb+ub)//2
    if check(9*mid):
        ub=mid
    else :
        lb=mid
print(ub)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : Sequence := ((OclFile["System.in"]).readLine())->characters() ;
    n := n->reverse() ;
    var lb : OclAny := null;
    var ub : OclAny := null;
    Sequence{lb,ub} := Sequence{0,(n)->size()} ;
    skip ;
    while ub - lb > 1 do (    var mid : int := (lb + ub) div 2 ;
    if check(9 * mid) then  (
      var ub : int := mid
    )
    else (
      var lb : int := mid
      )) ;
    execute (ub)->display();
  operation check(x : OclAny) : OclAny
  pre: true post: true
  activity:
    var g : int := 0 ;
    for i : n do (    x := x - (x + g - ("" + ((i)))->toInteger()) mod 10 ;
    if x < 0 then (
      break
    ) else skip ;
    g := (x + g) div 10) ;
    return x >= 0;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=int(input())
A,B=map(int,input().split())
N %=12
for i in range(1,N+1):
    if i % 2==1 :
        A=A-B
    else :
        B=A+B
print(A,B)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var A : OclAny := null;
    var B : OclAny := null;
    Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    N := N mod 12 ;
    for i : Integer.subrange(1, N + 1-1) do (    if i mod 2 = 1 then  (
      var A : double := A - B
    )
    else (
      var B : OclAny := A + B
      )) ;
    execute (A)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from itertools import*
from bisect import*
from math import*
from collections import*
from heapq import*
from random import*
import sys
sys.setrecursionlimit(10**6)
int1=lambda x : int(x)-1
p2D=lambda x : print(*x,sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int,sys.stdin.readline().split())
def MI1(): return map(int1,sys.stdin.readline().split())
def MF(): return map(float,sys.stdin.readline().split())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LI1(): return list(map(int1,sys.stdin.readline().split()))
def LF(): return list(map(float,sys.stdin.readline().split()))
def LLI(rows_number): return[LI()for _ in range(rows_number)]
dij=[(1,0),(0,1),(-1,0),(0,-1)]
def main():
    n=II()
    a,b=MI()
    n %=12
    for i in range(n):
        if i % 2 : b+=a
        else : a-=b
    print(a,b)
main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    sys.setrecursionlimit((10)->pow(6)) ;
    var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ;
    var p2D : Function := lambda x : OclAny in (((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var dij : Sequence := Sequence{Sequence{1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{-1, 0}}->union(Sequence{ Sequence{0, -1} }))) ;
    skip ;
    main();
  operation II() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation MI() : OclAny
  pre: true post: true
  activity:
    return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) );
  operation MI1() : OclAny
  pre: true post: true
  activity:
    return (sys.stdin.readLine().split())->collect( _x | (int1)->apply(_x) );
  operation MF() : OclAny
  pre: true post: true
  activity:
    return (sys.stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) );
  operation LI() : OclAny
  pre: true post: true
  activity:
    return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ));
  operation LI1() : OclAny
  pre: true post: true
  activity:
    return ((sys.stdin.readLine().split())->collect( _x | (int1)->apply(_x) ));
  operation LF() : OclAny
  pre: true post: true
  activity:
    return ((sys.stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ));
  operation LLI(rows_number : OclAny) : OclAny
  pre: true post: true
  activity:
    return Integer.subrange(0, rows_number-1)->select(_anon | true)->collect(_anon | (LI()));
  operation main()
  pre: true post: true
  activity:
    var n : OclAny := II() ;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := MI() ;
    n := n mod 12 ;
    for i : Integer.subrange(0, n-1) do (    if i mod 2 then  (
      b := b + a
    )
    else (
      a := a - b
      )) ;
    execute (a)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b,c,d=map(int,input().split())
if acollect( _x | (OclType["int"])->apply(_x) ) ;
    if (a->compareTo(c)) < 0 then  (
      if (d->compareTo(b)) < 0 then  (
      execute (d - c)->display()
    )
    else (if (c->compareTo(b)) < 0 then
   (
      execute (b - c)->display()    
)
    else (
      execute (0)->display()
      )    )
    )
    else (
      if (b->compareTo(d)) < 0 then  (
      execute (b - a)->display()
    )
    else (if (a->compareTo(d)) < 0 then
   (
      execute (d - a)->display()    
)
    else (
      execute (0)->display()
      )    )
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a,b=map(int,input().split())
ab=[[a,b]]
for i in range(11):
    a,b=ab[-1]
    if i % 2==0 : ab.append([a-b,b])
    else : ab.append([a,a+b])
print(*ab[n % 12])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var ab : Sequence := Sequence{ Sequence{a}->union(Sequence{ b }) } ;
    for i : Integer.subrange(0, 11-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := ab->last() ;
    if i mod 2 = 0 then  (
      execute ((Sequence{a - b}->union(Sequence{ b })) : ab)
    )
    else (
      execute ((Sequence{a}->union(Sequence{ a + b })) : ab)
      )) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name ab)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name n))) % (expr (atom (number (integer 12)))))))))) ]))))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=int(input())
A,B=map(int,input().split())
ret=[(A,B)]
for i in range(1,12):
    if i % 2==0 :
        B=A+B
    else :
        A=A-B
    ret.append((A,B))
print(*ret[N % 12])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var A : OclAny := null;
    var B : OclAny := null;
    Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var ret : Sequence := Sequence{ Sequence{A, B} } ;
    for i : Integer.subrange(1, 12-1) do (    if i mod 2 = 0 then  (
      var B : OclAny := A + B
    )
    else (
      var A : double := A - B
      ) ;
    execute ((Sequence{A, B}) : ret)) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name ret)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name N))) % (expr (atom (number (integer 12)))))))))) ]))))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=int(input())
A,B=map(int,input().split())
def one(n,A,B):
    if n % 2==0 :
        return A-B,B
    else :
        return A,A+B
N=N % 12
for i in range(N):
    A,B=one(i,A,B)
print(A,B)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var A : OclAny := null;
    var B : OclAny := null;
    Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    skip ;
    N := N mod 12 ;
    for i : Integer.subrange(0, N-1) do (    Sequence{A,B} := one(i, A, B)) ;
    execute (A)->display();
  operation one(n : OclAny, A : OclAny, B : OclAny) : OclAny
  pre: true post: true
  activity:
    if n mod 2 = 0 then  (
      return A - B, B
    )
    else (
      return A, A + B
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def findCombinationsUtil(arr,index,num,reducedNum):
    if(reducedNum<0):
        return ;
    if(reducedNum==0):
        for i in range(index):
            print(arr[i],end="");
        print("");
        return ;
    prev=1 if(index==0)else arr[index-1];
    for k in range(prev,num+1):
        arr[index]=k ;
        findCombinationsUtil(arr,index+1,num,reducedNum-k);
def findCombinations(n):
    arr=[0]*n ;
    findCombinationsUtil(arr,0,n,n);
n=5 ;
findCombinations(n);
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    n := 5; ;
    findCombinations(n);;
  operation findCombinationsUtil(arr : OclAny, index : OclAny, num : OclAny, reducedNum : OclAny) : OclAny
  pre: true post: true
  activity:
    if (reducedNum < 0) then (
      return;
    ) else skip ;
    if (reducedNum = 0) then (
      for i : Integer.subrange(0, index-1) do (    execute (arr[i+1])->display();) ;
    execute ("")->display(); ;
    return;
    ) else skip ;
    var prev : int := if (index = 0) then 1 else arr[index - 1+1] endif; ;
    for k : Integer.subrange(prev, num + 1-1) do (    arr[index+1] := k; ;
    findCombinationsUtil(arr, index + 1, num, reducedNum - k););
  operation findCombinations(n : OclAny)
  pre: true post: true
  activity:
    arr := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ;
    findCombinationsUtil(arr, 0, n, n);;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import itertools
from collections import defaultdict
n=int(input())
a=[0]+list(map(int,input().split()))
L=list(itertools.accumulate(a))
d=defaultdict(int)
for i in L :
    d[i]+=1
res=0
for i in d.keys():
    res+=d[i]*(d[i]-1)//2
print(res)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ;
    var L : Sequence := (itertools.accumulate(a)) ;
    var d : OclAny := defaultdict(OclType["int"]) ;
    for i : L do (    d[i+1] := d[i+1] + 1) ;
    var res : int := 0 ;
    for i : d.keys() do (    res := res + d[i+1] * (d[i+1] - 1) div 2) ;
    execute (res)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import factorial
N=map(int,input().split())
A=list(map(int,input().split()))
tmp=[0]
sum=0
for i in range(len(A)):
    sum+=A[i]
    tmp.append(sum)
tmp.sort()
tmp.append(1.2)
def combinations_count(n,r):
    return factorial(n)//(factorial(n-r)*factorial(r))
cnt=1
ans=0
for i in range(0,len(tmp)-1):
    if tmp[i]==tmp[i+1]:
        cnt+=1
    elif tmp[i]!=tmp[i+1]:
        if cnt>1 :
            ans+=combinations_count(cnt,2)
        cnt=1
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var N : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var tmp : Sequence := Sequence{ 0 } ;
    var sum : int := 0 ;
    for i : Integer.subrange(0, (A)->size()-1) do (    sum := sum + A[i+1] ;
    execute ((sum) : tmp)) ;
    tmp := tmp->sort() ;
    execute ((1.2) : tmp) ;
    skip ;
    var cnt : int := 1 ;
    var ans : int := 0 ;
    for i : Integer.subrange(0, (tmp)->size() - 1-1) do (    if tmp[i+1] = tmp[i + 1+1] then  (
      cnt := cnt + 1
    )
    else (if tmp[i+1] /= tmp[i + 1+1] then
   (
      if cnt > 1 then (
      ans := ans + combinations_count(cnt, 2)
    ) else skip ;
    cnt := 1    
)
 else skip)) ;
    execute (ans)->display();
  operation combinations_count(n : OclAny, r : OclAny) : OclAny
  pre: true post: true
  activity:
    return factorial(n) div (factorial(n - r) * factorial(r));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys,math,fractions,itertools,collections,copy,heapq
def solve(N : int,A : "List[int]"):
    A=[0]+list(itertools.accumulate(A))
    A=collections.Counter(A)
    s=0
    for v in A.values():
        s+=v*(v-1)//2
    print(s)
    return
def main():
    def iterate_tokens():
        for line in sys.stdin :
            for word in line.split():
                yield word
    tokens=iterate_tokens()
    N=int(next(tokens))
    A=[int(next(tokens))for _ in range(N)]
    solve(N,A)
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation solve(N : int, A : "List[int]")
  pre: true post: true
  activity:
    var A : Sequence := Sequence{ 0 }->union((itertools.accumulate(A))) ;
    A := .Counter(A) ;
    var s : int := 0 ;
    for v : A.values() do (    s := s + v * (v - 1) div 2) ;
    execute (s)->display() ;
    return;
  operation main()
  pre: true post: true
  activity:
    skip ;
    var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ;
    var N : int := ("" + (((tokens).next())))->toInteger() ;
    A := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((tokens).next())))->toInteger())) ;
    solve(N, A);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def counter(a,b,c):
    count_r=0
    for y in range(a+1,b):
        if(c[a]==c[y]):
            count_r+=1
        else :
            break
    return count_r
test=int(input())
for x in range(0,test):
    n=int(input())
    string_h=input()
    if(n==0):
        print(0)
    else :
        if(n % 2!=0):
            k=int(n/2)
            count=counter(k,n,string_h)*2+1
        else :
            k=int(n/2)-1
            count=counter(k,n,string_h)*2
    print(count)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var test : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for x : Integer.subrange(0, test-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var string_h : String := (OclFile["System.in"]).readLine() ;
    if (n = 0) then  (
      execute (0)->display()
    )
    else (
      if (n mod 2 /= 0) then  (
      var k : int := ("" + ((n / 2)))->toInteger() ;
    var count : double := counter(k, n, string_h) * 2 + 1
    )
    else (
      k := ("" + ((n / 2)))->toInteger() - 1 ;
    count := counter(k, n, string_h) * 2
      )
      ) ;
    execute (count)->display());
  operation counter(a : OclAny, b : OclAny, c : OclAny) : OclAny
  pre: true post: true
  activity:
    var count_r : int := 0 ;
    for y : Integer.subrange(a + 1, b-1) do (    if (c[a+1] = c[y+1]) then  (
      count_r := count_r + 1
    )
    else (
      break
      )) ;
    return count_r;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=int(input())
As=[int(x)for x in input().split()]
Ss=[0]
nums={0 : 1}
for A in As :
    S=Ss[-1]+A
    Ss.append(S)
    if not S in nums :
        nums[S]=0
    nums[S]+=1
ans=0
for n in nums.values():
    ans+=(n*(n-1))//2
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var As : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    var Ss : Sequence := Sequence{ 0 } ;
    var nums : Map := Map{ 0 |-> 1 } ;
    for A : As do (    var S : OclAny := Ss->last() + A ;
    execute ((S) : Ss) ;
    if not((nums)->includes(S)) then (
      nums[S+1] := 0
    ) else skip ;
    nums[S+1] := nums[S+1] + 1) ;
    var ans : int := 0 ;
    for n : nums.values() do (    ans := ans + (n * (n - 1)) div 2) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
N=int(input())
a=list(map(int,input().split()))
b=[a[0]for i in range(N)]
for i in range(1,N):
    b[i]=b[i-1]+a[i]
b.sort()
c=1
ans=0
def P(n,r):
    return math.factorial(n)//math.factorial(n-r)
def C(n,r):
    return P(n,r)//math.factorial(r)
if N==1 :
    if b[0]==0 :
        print(1)
    else :
        print(0)
else :
    for i in range(1,N):
        if b[i]==b[i-1]:
            c=c+1
        else :
            if c>1 :
                ans=ans+C(c,2)
            if b[i-1]==0 :
                ans=ans+c
            c=1
    else :
        if c>1 :
            ans=ans+C(c,2)
        if b[i-1]==0 :
            ans=ans+c
    print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var b : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (a->first())) ;
    for i : Integer.subrange(1, N-1) do (    b[i+1] := b[i - 1+1] + a[i+1]) ;
    b := b->sort() ;
    var c : int := 1 ;
    var ans : int := 0 ;
    skip ;
    skip ;
    if N = 1 then  (
      if b->first() = 0 then  (
      execute (1)->display()
    )
    else (
      execute (0)->display()
      )
    )
    else (
  (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name c))) + (expr (atom (number (integer 1))))))))))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name c)))) > (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name ans))) + (expr (atom (name C)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ))))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name ans))) + (expr (atom (name c)))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name c)))) > (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name ans))) + (expr (atom (name C)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ))))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name ans))) + (expr (atom (name c))))))))))))))))))) ;
    execute (ans)->display()
      );
  operation P(n : OclAny, r : OclAny) : OclAny
  pre: true post: true
  activity:
    return MathLib.factorial(n) div MathLib.factorial(n - r);
  operation C(n : OclAny, r : OclAny) : OclAny
  pre: true post: true
  activity:
    return P(n, r) div MathLib.factorial(r);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
A=list(map(int,input().split()))
if A[1]<=A[2]or A[3]<=A[0]:
    print(0)
else :
    A.sort()
    print(A[2]-A[1])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if (A[1+1]->compareTo(A[2+1])) <= 0 or (A[3+1]->compareTo(A->first())) <= 0 then  (
      execute (0)->display()
    )
    else (
      A := A->sort() ;
    execute (A[2+1] - A[1+1])->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def findNthTerm(n):
    if(n % 2==0):
        n=n//2
        n=2*(n-1)
        print(n//2)
    else :
        n=(n//2)+1
        n=2*(n-1)
        print(n)
if __name__=="__main__" :
    X=10
    findNthTerm(X);
    X=7 ;
    findNthTerm(X)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      var X : int := 10 ;
    findNthTerm(X); ;
    X := 7; ;
    findNthTerm(X)
    ) else skip;
  operation findNthTerm(n : OclAny)
  pre: true post: true
  activity:
    if (n mod 2 = 0) then  (
      n := n div 2 ;
    n := 2 * (n - 1) ;
    execute (n div 2)->display()
    )
    else (
      n := (n div 2) + 1 ;
    n := 2 * (n - 1) ;
    execute (n)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def check(s,l):
    pos=[]
    for i in range(l):
        if(s[i]=='1'):
            pos.append(i)
    t=len(pos)
    for i in range(1,t):
        if((pos[i]-pos[i-1])!=(pos[1]-pos[0])):
            return False
    return True
s="100010001000"
l=len(s)
if(check(s,l)):
    print("Yes")
else :
    print("No")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    s := "100010001000" ;
    l := (s)->size() ;
    if (check(s, l)) then  (
      execute ("Yes")->display()
    )
    else (
      execute ("No")->display()
      );
  operation check(s : OclAny, l : OclAny) : OclAny
  pre: true post: true
  activity:
    var pos : Sequence := Sequence{} ;
    for i : Integer.subrange(0, l-1) do (    if (s[i+1] = '1') then (
      execute ((i) : pos)
    ) else skip) ;
    var t : int := (pos)->size() ;
    for i : Integer.subrange(1, t-1) do (    if ((pos[i+1] - pos[i - 1+1]) /= (pos[1+1] - pos->first())) then (
      return false
    ) else skip) ;
    return true;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    quantidade_de_bits=int(input())
    string_binaria=input()
    conta_zeros=0
    for bit in string_binaria :
        if int(bit)==0 :
            conta_zeros+=1
    if conta_zeros>len(string_binaria)-conta_zeros :
        bit_resultado="0"
    else :
        bit_resultado="1"
    print(quantidade_de_bits*bit_resultado)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var quantidade_de_bits : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var string_binaria : String := (OclFile["System.in"]).readLine() ;
    var conta_zeros : int := 0 ;
    for bit : string_binaria->characters() do (    if ("" + ((bit)))->toInteger() = 0 then (
      conta_zeros := conta_zeros + 1
    ) else skip) ;
    if (conta_zeros->compareTo((string_binaria)->size() - conta_zeros)) > 0 then  (
      var bit_resultado : String := "0"
    )
    else (
      bit_resultado := "1"
      ) ;
    execute (quantidade_de_bits * bit_resultado)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for s in[*open(0)][2 : : 2]: print(s[: : 2])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do (    execute (s(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
o=int(input())
while o>0 :
    n=int(input())
    arr=input()
    ans=[]
    for i in range(n):
        ans.append(arr[2*i])
    print(''.join(ans))
    o=o-1
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var o : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    while o > 0 do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var arr : String := (OclFile["System.in"]).readLine() ;
    var ans : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    execute ((arr[2 * i+1]) : ans)) ;
    execute (StringLib.sumStringsWithSeparator((ans), ''))->display() ;
    o := o - 1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for i in range(int(input())):
    n=int(input())
    m=input()
    a=[]
    for x in range(n):
        a.append(2**n-1-int(m[x : x+n],2))
    for y in range(2**n):
        if y not in a :
            b=str(bin(y))[2 :]
            if n-len(b)!=0 :
                print('0'*(n-len(b))+b)
            else :
                print(b)
            break
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var m : String := (OclFile["System.in"]).readLine() ;
    var a : Sequence := Sequence{} ;
    for x : Integer.subrange(0, n-1) do (    execute (((2)->pow(n) - 1 - ("" + ((m.subrange(x+1, x + n), 2)))->toInteger()) : a)) ;
    for y : Integer.subrange(0, (2)->pow(n)-1) do (    if (a)->excludes(y) then (
      var b : OclAny := OclType["String"](bin(y)).subrange(2+1) ;
    if n - (b)->size() /= 0 then  (
      execute (StringLib.nCopies('0', (n - (b)->size())) + b)->display()
    )
    else (
      execute (b)->display()
      ) ;
    break
    ) else skip));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    quantidade_de_bits=int(input())
    string_binaria=input()
    conta_zeros=0
    for bit in string_binaria :
        if int(bit)==0 :
            conta_zeros+=1
    if conta_zeros>len(string_binaria)-conta_zeros :
        bit_resultado="0"
    else :
        bit_resultado="1"
    print(quantidade_de_bits*bit_resultado)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var quantidade_de_bits : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var string_binaria : String := (OclFile["System.in"]).readLine() ;
    var conta_zeros : int := 0 ;
    for bit : string_binaria->characters() do (    if ("" + ((bit)))->toInteger() = 0 then (
      conta_zeros := conta_zeros + 1
    ) else skip) ;
    if (conta_zeros->compareTo((string_binaria)->size() - conta_zeros)) > 0 then  (
      var bit_resultado : String := "0"
    )
    else (
      bit_resultado := "1"
      ) ;
    execute (quantidade_de_bits * bit_resultado)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=int(input())
b=input()
for x in range(a//2+1,0,-1):
    if 'og'*x+'o' in b :
        b=b.replace('o'+'go'*x,'***')
print(b)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var b : String := (OclFile["System.in"]).readLine() ;
    for x : Integer.subrange(0 + 1, a div 2 + 1)->reverse() do (    if (b)->characters()->includes(StringLib.nCopies('og', x) + 'o') then (
      b := b.replace('o' + StringLib.nCopies('go', x), '***')
    ) else skip) ;
    execute (b)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import itertools
def compute():
    numbers=[[set()for j in range(100)]for i in range(9)]
    for sides in range(3,9):
        for n in itertools.count(1):
            num=figurate_number(sides,n)
            if num>=10000 :
                break
            if num>=1000 :
                numbers[sides][num//100].add(num)
    def find_solution_sum(begin,current,sidesused,sum):
        if sidesused==0b111111000 :
            if current % 100==begin//100 :
                return sum
        else :
            for sides in range(4,9):
                if(sidesused>>sides)& 1!=0 :
                    continue
                for num in numbers[sides][current % 100]:
                    temp=find_solution_sum(begin,num,sidesused |(1<display()
    ) else skip;
  operation compute() : OclAny
  pre: true post: true
  activity:
    var numbers : Sequence := Integer.subrange(0, 9-1)->select(i | true)->collect(i | (Integer.subrange(0, 100-1)->select(j | true)->collect(j | (Set{}->union(()))))) ;
    for sides : Integer.subrange(3, 9-1) do (    for n : itertools->count(1) do (    var num : OclAny := figurate_number(sides, n) ;
    if num >= 10000 then (
      break
    ) else skip ;
    if num >= 1000 then (
  (expr (atom (name numbers)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name sides)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name num))) // (expr (atom (number (integer 100)))))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) ))))
    ) else skip)) ;
    skip ;
    for i : Integer.subrange(10, 100-1) do (    for num : numbers[3+1][i+1] do (    temp := find_solution_sum(num, num, 1 * (2->pow(3)), num) ;
    if not(temp <>= null) then (
      return ("" + ((temp)))
    ) else skip)) ;
    error AssertionException.newAssertionException("No solution");
  operation figurate_number(sides : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    return n * ((sides - 2) * n - (sides - 4)) div 2;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
s=input()
filler_word='ogo'
filler_words=[]
for i in range(n+1):
    filler_words.append(filler_word+'go'*i)
while True :
    for word in filler_words[: :-1]:
        if word in s :
            s=s.replace(word,'***')
    else :
        break
print(s)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : String := (OclFile["System.in"]).readLine() ;
    var filler_word : String := 'ogo' ;
    var filler_words : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n + 1-1) do (    execute ((filler_word + StringLib.nCopies('go', i)) : filler_words)) ;
    while true do ((compound_stmt for (exprlist (expr (atom (name word)))) in (testlist (test (logical_test (comparison (expr (atom (name filler_words)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ]))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name word)))) in (comparison (expr (atom (name s))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)) (trailer . (name replace) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name word))))))) , (argument (test (logical_test (comparison (expr (atom '***'))))))) ))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt break))))))) ;
    execute (s)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
def calculate(a,b,n,m):
    mul=1
    for i in range(m):
        if(b[i]!=0):
            mul=mul*b[i]
    for i in range(n):
        x=math.floor(a[i]/mul)
        print(x,end=" ")
a=[5,100,8]
b=[2,3]
n=len(a)
m=len(b)
calculate(a,b,n,m)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    a := Sequence{5}->union(Sequence{100}->union(Sequence{ 8 })) ;
    b := Sequence{2}->union(Sequence{ 3 }) ;
    n := (a)->size() ;
    m := (b)->size() ;
    calculate(a, b, n, m);
  operation calculate(a : OclAny, b : OclAny, n : OclAny, m : OclAny)
  pre: true post: true
  activity:
    var mul : int := 1 ;
    for i : Integer.subrange(0, m-1) do (    if (b[i+1] /= 0) then (
      mul := mul * b[i+1]
    ) else skip) ;
    for i : Integer.subrange(0, n-1) do (    var x : double := (a[i+1] / mul)->floor() ;
    execute (x)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import re ; input(); print(re.sub('o(go)+','***',input()))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip;    input();    execute (((OclFile["System.in"]).readLine()).replaceAllMatches('o(go)+', '***'))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import re ; input(); print(re.sub('o(go)+','***',input()))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip;    input();    execute (((OclFile["System.in"]).readLine()).replaceAllMatches('o(go)+', '***'))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import re ; input(); print(re.sub('o(go)+','***',input()))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip;    input();    execute (((OclFile["System.in"]).readLine()).replaceAllMatches('o(go)+', '***'))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
CHARS="qwertyuiopasdfghjklzxcvbnm" ;
MAX=26 ;
def getString(string,n):
    string=list(string);
    uMap={};
    for i in range(MAX):
        uMap[CHARS[i]]=CHARS[(i+1)% MAX];
    for i in range(n):
        string[i]=uMap[string[i]];
    return "".join(string);
if __name__=="__main__" :
    string="geeks" ;
    n=len(string);
    print(getString(string,n));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var CHARS : String := "qwertyuiopasdfghjklzxcvbnm"; ;
    var MAX : int := 26; ;
    skip ;
    if __name__ = "__main__" then (
      string := "geeks"; ;
    n := (string)->size(); ;
    execute (getString(string, n))->display();
    ) else skip;
  operation getString(string : OclAny, n : OclAny)
  pre: true post: true
  activity:
    string := (string)->characters(); ;
    var uMap : OclAny := Set{}; ;
    for i : Integer.subrange(0, MAX-1) do (    uMap[CHARS[i+1]+1] := CHARS[(i + 1) mod MAX+1];) ;
    for i : Integer.subrange(0, n-1) do (    string[i+1] := uMap[string[i+1]+1];) ;
    return StringLib.sumStringsWithSeparator((string), "");;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
toks=(tok for tok in sys.stdin.read().split())
T=int(next(toks))
for _ in range(T):
    N=int(next(toks))
    S=int(next(toks))
    low=0
    high=S+1
    while lowS :
            high=mid
        else :
            low=mid+1
    print(low-1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var toks : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name tok)))))) (comp_for for (exprlist (expr (atom (name tok)))) in (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin)) (trailer . (name read) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ;
    var T : int := ("" + (((toks).next())))->toInteger() ;
    for _anon : Integer.subrange(0, T-1) do (    var N : int := ("" + (((toks).next())))->toInteger() ;
    var S : int := ("" + (((toks).next())))->toInteger() ;
    var low : int := 0 ;
    var high : int := S + 1 ;
    while (low->compareTo(high)) < 0 do (    var mid : int := (low + high) div 2 ;
    if ((N div 2 + 1) * mid->compareTo(S)) > 0 then  (
      high := mid
    )
    else (
      low := mid + 1
      )) ;
    execute (low - 1)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import ceil,floor
num_inp=lambda : int(input())
arr_inp=lambda : list(map(int,input().split()))
sp_inp=lambda : map(int,input().split())
str_inp=lambda : input()
t=num_inp()
for _ in range(t):
    n,s=sp_inp()
    half=ceil(n/2)
    rem=n-half+1
    print(floor(s/rem))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ;
    var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ;
    var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ;
    var t : OclAny := num_inp->apply() ;
    for _anon : Integer.subrange(0, t-1) do (    var n : OclAny := null;
    var s : OclAny := null;
    Sequence{n,s} := sp_inp->apply() ;
    var half : OclAny := ceil(n / 2) ;
    var rem : double := n - half + 1 ;
    execute (floor(s / rem))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for _ in range(t):
    n,s=(int(i)for i in input().split())
    n-=(n-1)//2
    res=s//n
    print(res)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, t-1) do (    var n : OclAny := null;
    var s : OclAny := null;
    Sequence{n,s} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ;
    n := n - (n - 1) div 2 ;
    var res : int := s div n ;
    execute (res)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=int(input())
while(a):
    n,k=map(int,input().split(" "))
    pos=n//2
    if(n % 2!=0):
        pos+=1
    if pos==0 :
        pos=1
    print(k//((n-pos)+1))
    a-=1
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    while (a) do (    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ;
    var pos : int := n div 2 ;
    if (n mod 2 /= 0) then (
      pos := pos + 1
    ) else skip ;
    if pos = 0 then (
      pos := 1
    ) else skip ;
    execute (k div ((n - pos) + 1))->display() ;
    a := a - 1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
def max_cuts(n,a,b,c):
    if(n==0):
        return 0
    elif(n<0):
        return-1
    result=max(max_cuts(n-a,a,b,c),max_cuts(n-b,a,b,c),max_cuts(n-c,a,b,c))
    if(result==-1):
        return-1
    return result+1
def freq(list1):
    freq_count={}
    for i in list1 :
        if(i in freq_count):
            freq_count[i]+=1
        else :
            freq_count[i]=1
    return freq_count
t=int(input())
for t1 in range(t):
    n,s=map(int,input().split(" "))
    n*=n
    print(s//n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for t1 : Integer.subrange(0, t-1) do (    var s : OclAny := null;
    Sequence{n,s} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ;
    n := n * n ;
    execute (s div n)->display());
  operation max_cuts(n : OclAny, a : OclAny, b : OclAny, c : OclAny) : OclAny
  pre: true post: true
  activity:
    if (n = 0) then  (
      return 0
    )
    else (if (n < 0) then
   (
      return -1    
)
 else skip) ;
    var result : OclAny := Set{max_cuts(n - a, a, b, c), max_cuts(n - b, a, b, c), max_cuts(n - c, a, b, c)}->max() ;
    if (result = -1) then (
      return -1
    ) else skip ;
    return result + 1;
  operation freq(list1 : OclAny) : OclAny
  pre: true post: true
  activity:
    var freq_count : OclAny := Set{} ;
    for i : list1 do (    if ((freq_count)->includes(i)) then  (
      freq_count[i+1] := freq_count[i+1] + 1
    )
    else (
      freq_count[i+1] := 1
      )) ;
    return freq_count;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=map(int,input().split())
print((a+b)% 24)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute ((a + b) mod 24)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a=sum(list(map(int,input().split())))
b=sum(list(map(int,input().split())))
c=sum(list(map(int,input().split())))
print(a-b,b-c,sep='\n')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : OclAny := (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->sum() ;
    var b : OclAny := (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->sum() ;
    var c : OclAny := (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->sum() ;
    execute (a - b)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for s in[*open(0)][1 :]: n,s=map(int,s.split()); print(s//n//n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do (    var n : OclAny := null;
    var s : OclAny := null;
    Sequence{n,s} := (s.split())->collect( _x | (OclType["int"])->apply(_x) );    execute (s div n div n)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def asd():
    t=int(input())
    for j in range(t):
        a=[int(x)for x in input().split()]
        n=a[1]//(a[0]*a[0])
        print(n)
asd()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    asd();
  operation asd()
  pre: true post: true
  activity:
    var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for j : Integer.subrange(0, t-1) do (    var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    var n : int := a[1+1] div (a->first() * a->first()) ;
    execute (n)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def solve():
    n,s=[int(i)for i in input().split()]
    return s//n//n
t=int(input())
ans=[]
while t :
    ans.append(str(solve()))
    t-=1
print("\n".join(ans))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var ans : Sequence := Sequence{} ;
    while t do (    execute ((("" + ((solve())))) : ans) ;
    t := t - 1) ;
    execute (StringLib.sumStringsWithSeparator((ans), "\n"))->display();
  operation solve() : OclAny
  pre: true post: true
  activity:
    var n : OclAny := null;
    var s : OclAny := null;
    Sequence{n,s} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    return s div n div n;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    n,m=map(int,input().split())
    print(m//(n*n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (m div (n * n))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
line=sys.stdin.readline()
line=line.rstrip()
cases=int(line)
for case in xrange(0,cases):
    K=int(sys.stdin.readline().strip())
    ds=map(int,sys.stdin.readline().rstrip().split())
    ds[0 : 1]=[]
    indexes=range(0,K)
    cards=[-1]*K
    I=0
    for X in xrange(0,K):
        I+=X
        I=I %(len(indexes))
        ii=I %(K-X)
        i=indexes[ii]
        indexes[ii : ii+1]=[]
        cards[i]=X
    sys.stdout.write("Case #%d:" %(case+1))
    for d in ds :
        sys.stdout.write(" %d" %(cards[d-1]+1))
    sys.stdout.write("\n")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var line : String := (OclFile["System.in"]).readLine() ;
    line := StringLib.rightTrim(line) ;
    var cases : int := ("" + ((line)))->toInteger() ;
    for case : xrange(0, cases) do (    var K : int := ("" + ((sys.stdin.readLine()->trim())))->toInteger() ;
    var ds : Sequence := (sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    ds.subrange(0+1, 1) := Sequence{} ;
    var indexes : Sequence := Integer.subrange(0, K-1) ;
    var cards : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, K) ;
    var I : int := 0 ;
    for X : xrange(0, K) do (    I := I + X ;
    I := I mod ((indexes)->size()) ;
    var ii : int := I mod (K - X) ;
    var i : OclAny := indexes[ii+1] ;
    indexes.subrange(ii+1, ii + 1) := Sequence{} ;
    cards[i+1] := X) ;
(expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom "Case #%d:")) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name case))) + (expr (atom (number (integer 1))))))))) ))))))))) )))) ;
    for d : ds do ((expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom " %d")) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name cards)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name d))) - (expr (atom (number (integer 1)))))))))) ]))) + (expr (atom (number (integer 1))))))))) ))))))))) ))))) ;
(expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n"))))))) )))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from time import time
import psyco
import re
import math
psyco.full()
fin=open("1_input.txt","r")
fout=open("1_output.txt","w")
cases=int(fin.readline())
t0=time()
for casenr in range(cases):
    K=int(fin.readline())
    indices=map(int,[e for e in fin.readline().split()])
    indices=indices[1 :]
    open_indices=[]
    closed_indices=[]
    for i in range(1,K+1):
        open_indices.append(i)
        closed_indices.append(i)
    current_number=1
    current_position=-1
    while open_indices :
        next_index=(current_position+current_number)% len(open_indices)
        closed_indices[open_indices[next_index]-1]=current_number
        open_indices.pop(next_index)
        current_position=next_index-1
        current_number+=1
    fout.write("Case #%d:" %(casenr+1))
    for ind in indices :
        fout.write(" %d" %(closed_indices[ind-1]))
    fout.write("\n")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    psyco.full() ;
    var fin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("1_input.txt")) ;
    var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("1_output.txt")) ;
    var cases : int := ("" + ((fin.readLine())))->toInteger() ;
    var t0 : OclAny := time() ;
    for casenr : Integer.subrange(0, cases-1) do (    var K : int := ("" + ((fin.readLine())))->toInteger() ;
    var indices : Sequence := (fin.readLine().split()->select(e | true)->collect(e | (e)))->collect( _x | (OclType["int"])->apply(_x) ) ;
    indices := indices->tail() ;
    var open_indices : Sequence := Sequence{} ;
    var closed_indices : Sequence := Sequence{} ;
    for i : Integer.subrange(1, K + 1-1) do (    execute ((i) : open_indices) ;
    execute ((i) : closed_indices)) ;
    var current_number : int := 1 ;
    var current_position : int := -1 ;
    while open_indices do (    var next_index : int := (current_position + current_number) mod (open_indices)->size() ;
    closed_indices[open_indices[next_index+1] - 1+1] := current_number ;
    open_indices := open_indices->excludingAt(next_index+1) ;
    current_position := next_index - 1 ;
    current_number := current_number + 1) ;
    fout.write(StringLib.format("Case #%d:",(casenr + 1))) ;
    for ind : indices do (    fout.write(StringLib.format(" %d",(closed_indices[ind - 1+1])))) ;
    fout.write("\n"));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
case="small-attempt0"
input_file="C-%s.in" % case
output_file="C-%s.out" % case
fin=open(input_file)
fout=open(output_file,"w")
ncase=int(fin.readline().strip())
for z in xrange(1,ncase+1):
    print>>fout,"Case #%d:" % z,
    k=int(fin.readline().strip())
    d=[int(x)-1 for x in fin.readline().strip().split()[1 :]]
    for dd in d :
        n,p,r,i=k,dd,0,1
        while p!=r :
            n-=1
            if p>r :
                p-=1
            r=(r+i)% n
            i+=1
        print>>fout,i,
    print>>fout
fin.close()
fout.close()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var case : String := "small-attempt0" ;
    var input_file : String := StringLib.format("C-%s.in",case) ;
    var output_file : String := StringLib.format("C-%s.out",case) ;
    var fin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(input_file)) ;
    var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(output_file)) ;
    var ncase : int := ("" + ((fin.readLine()->trim())))->toInteger() ;
    for z : xrange(1, ncase + 1) do (    print /(2->pow(fout)) ;
(updateForm (test (logical_test (comparison (expr (expr (atom "Case #%d:")) % (expr (atom (name z))))))) ,) ;
    var k : int := ("" + ((fin.readLine()->trim())))->toInteger() ;
    var d : Sequence := fin.readLine()->trim().split()->tail()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)) ;
    for dd : d do (    var n : OclAny := null;
    var p : OclAny := null;
    var r : OclAny := null;
    var i : OclAny := null;
    Sequence{n,p,r,i} := Sequence{k,dd,0,1} ;
    while p /= r do (    n := n - 1 ;
    if (p->compareTo(r)) > 0 then (
      p := p - 1
    ) else skip ;
    var r : int := (r + i) mod n ;
    i := i + 1) ;
    print /(2->pow(fout)) ;
(updateForm (test (logical_test (comparison (expr (atom (name i)))))) ,)) ;
(expr (expr (atom print)) >> (expr (atom (name fout))))) ;
    fin.closeFile() ;
    fout.closeFile();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
inp_file=file("C-small.in")
out_file=file("C-small.out","w")
def solve(line):
    line=[int(c1)for c1 in line.split(" ")]
    card_num,indices=line[: 2]
    line=line[2 :]
    positions=range(card_num)
    result=[0 for c1 in range(card_num)]
    c1=1
    c2=0
    while c1toInteger() ;
    for case : Integer.subrange(0, num-1) do (    line := inp_file.readLine()->front() + " " + inp_file.readLine()->front() ;
    out_file.write(StringLib.format("Case #%s: ",(case + 1)) + solve(line) + "\n")) ;
    inp_file.closeFile() ;
    out_file.closeFile();
  operation solve(line : OclAny) : OclAny
  pre: true post: true
  activity:
    line := line.split(" ")->select(c1 | true)->collect(c1 | (("" + ((c1)))->toInteger())) ;
    var card_num : OclAny := null;
    var indices : OclAny := null;
    Sequence{card_num,indices} := line.subrange(1,2) ;
    line := line.subrange(2+1) ;
    var positions : Sequence := Integer.subrange(0, card_num-1) ;
    var result : Sequence := Integer.subrange(0, card_num-1)->select(c1 | true)->collect(c1 | (0)) ;
    var c1 : int := 1 ;
    var c2 : int := 0 ;
    while (c1->compareTo(card_num)) < 0 do (    result[positions[c2+1]+1] := c1 ;
    positions := positions->excludingAt(c2+1) ;
    c2 := (c2 + c1) mod (positions)->size() ;
    c1 := c1 + 1) ;
    result[result->indexOf(0) - 1+1] := card_num ;
    return StringLib.sumStringsWithSeparator((line->select(c1 | true)->collect(c1 | (("" + ((result[c1 - 1+1])))))), " ");
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
cached_in=""
def next_line():
    global cached_in
    if cached_in :
        res="".join(cached_in)
        cached_in=""
        return res
    return sys.stdin.readline().strip()
def next_val():
    global cached_in
    while not cached_in :
        cached_in=sys.stdin.readline().strip()
        cached_in=cached_in.split()
        cached_in.reverse()
    return cached_in.pop()
def next_int():
    return int(next_val())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  attribute cached_in : OclAny;
  attribute cached_in : OclAny;
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var cached_in : String := "" ;
    skip ;
    skip ;
    skip;
  operation next_line() : OclAny
  pre: true post: true
  activity:
    skip ;
    if cached_in then (
      var res : String := StringLib.sumStringsWithSeparator((cached_in), "") ;
    cached_in := "" ;
    return res
    ) else skip ;
    return sys.stdin.readLine()->trim();
  operation next_val() : OclAny
  pre: true post: true
  activity:
    skip ;
    while not(cached_in = "") do (    cached_in := sys.stdin.readLine()->trim() ;
    cached_in := cached_in.split() ;
    cached_in := cached_in->reverse()) ;
    return cached_in->last();
  operation next_int() : OclAny
  pre: true post: true
  activity:
    return ("" + ((next_val())))->toInteger();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    s=input()
    n=len(s)
    arr=[]
    i=0
    while itoInteger()-1) do (    var s : String := (OclFile["System.in"]).readLine() ;
    var n : int := (s)->size() ;
    var arr : Sequence := Sequence{} ;
    var i : int := 0 ;
    while (i->compareTo(n - 2)) < 0 do (    try (    if s[i+1] + s[i + 1+1] + s[i + 2+1] + s[i + 3+1] + s[i + 4+1] = "twone" then (
      execute ((i + 3) : arr) ;
    i := i + 3 ;
    continue
    ) else skip)
     catch (_e : OclException) do (    skip)
 ;
    if s[i+1] + s[i + 1+1] + s[i + 2+1] = 'two' then (
      execute ((i + 2) : arr);    i := i + 2;    continue
    ) else skip ;
    if s[i+1] + s[i + 1+1] + s[i + 2+1] = 'one' then (
      execute ((i + 2) : arr);    i := i + 2;    continue
    ) else skip ;
    i := i + 1) ;
    execute ((arr)->size())->display() ;
    for i : arr do (    execute (i)->display()) ;
    execute (->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for i in range(t):
    f=list(map(int,input().split()))
    n=f[0]
    k=f[1]
    if n % 2!=k % 2 :
        print("NO")
    elif k*k>n :
        print("NO")
    else :
        print("YES")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, t-1) do (    var f : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var n : String := f->first() ;
    var k : String := f[1+1] ;
    if StringLib.format(n,2) /= StringLib.format(k,2) then  (
      execute ("NO")->display()
    )
    else (if StringLib.nCopies(k, k) > n then
   (
      execute ("NO")->display()    
)
    else (
      execute ("YES")->display()
      )    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
b=input().split()
a=[int(b[i])for i in range(len(b))]
if(a[0]+a[1]>=24):
    print(a[0]+a[1]-24)
else :
    print(a[0]+a[1])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var b : OclAny := input().split() ;
    var a : Sequence := Integer.subrange(0, (b)->size()-1)->select(i | true)->collect(i | (("" + ((b[i+1])))->toInteger())) ;
    if (a->first() + a[1+1] >= 24) then  (
      execute (a->first() + a[1+1] - 24)->display()
    )
    else (
      execute (a->first() + a[1+1])->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys,os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
t=int(input())
ans=[]
x=[ord(i)for i in list("twone")]
y=[ord(i)for i in list("one")]
z=[ord(i)for i in list("two")]
for _ in range(t):
    s=list(input().rstrip())
    n=len(s)
    ans0=[]
    for i in range(n-4):
        f=1
        for j in range(5):
            if s[i+j]^ x[j]:
                f=0
                break
        if f :
            ans0.append(i+3)
            s[i+2]=0
    for i in range(n-2):
        f=1
        for j in range(3):
            if s[i+j]^ y[j]:
                f=0
                break
        if f :
            ans0.append(i+2)
            s[i+1]=0
            continue
        f=1
        for j in range(3):
            if s[i+j]^ z[j]:
                f=0
                break
        if f :
            ans0.append(i+2)
            s[i+1]=0
    r=len(ans0)
    ans.append(str(r))
    ans.append(" ".join(map(str,ans0)))
sys.stdout.write("\n".join(ans))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := io.BytesIO(os.readAll()).readline ;
    var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var ans : Sequence := Sequence{} ;
    var x : Sequence := ("twone")->characters()->select(i | true)->collect(i | ((i)->char2byte())) ;
    var y : Sequence := ("one")->characters()->select(i | true)->collect(i | ((i)->char2byte())) ;
    var z : Sequence := ("two")->characters()->select(i | true)->collect(i | ((i)->char2byte())) ;
    for _anon : Integer.subrange(0, t-1) do (    var s : Sequence := (input().rstrip()) ;
    var n : int := (s)->size() ;
    var ans0 : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n - 4-1) do (    var f : int := 1 ;
    for j : Integer.subrange(0, 5-1) do (    if MathLib.bitwiseXor(s[i + j+1], x[j+1]) then (
      f := 0 ;
    break
    ) else skip) ;
    if f then (
      execute ((i + 3) : ans0) ;
    s[i + 2+1] := 0
    ) else skip) ;
    for i : Integer.subrange(0, n - 2-1) do (    f := 1 ;
    for j : Integer.subrange(0, 3-1) do (    if MathLib.bitwiseXor(s[i + j+1], y[j+1]) then (
      f := 0 ;
    break
    ) else skip) ;
    if f then (
      execute ((i + 2) : ans0) ;
    s[i + 1+1] := 0 ;
    continue
    ) else skip ;
    f := 1 ;
    for j : Integer.subrange(0, 3-1) do (    if MathLib.bitwiseXor(s[i + j+1], z[j+1]) then (
      f := 0 ;
    break
    ) else skip) ;
    if f then (
      execute ((i + 2) : ans0) ;
    s[i + 1+1] := 0
    ) else skip) ;
    var r : int := (ans0)->size() ;
    execute ((("" + ((r)))) : ans) ;
    execute ((StringLib.sumStringsWithSeparator(((ans0)->collect( _x | (OclType["String"])->apply(_x) )), " ")) : ans)) ;
(expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
for i in range(n):
    s=input()
    r=0
    indexs=[]
    j=0
    while j=2 and s[j+3]=="n" and s[j+4]=="e" :
                indexs.append(j+3)
                j=j+5
            else :
                indexs.append(j+2)
                j=j+3
            r=r+1
        else : j=j+1
    print(r)
    print(*indexs,sep=" ")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, n-1) do (    var s : String := (OclFile["System.in"]).readLine() ;
    var r : int := 0 ;
    var indexs : Sequence := Sequence{} ;
    var j : int := 0 ;
    while (j->compareTo((s)->size() - 2)) < 0 do (    if s[j+1] = "o" & s[j + 1+1] = "n" & s[j + 2+1] = "e" then  (
      r := r + 1 ;
    execute ((j + 2) : indexs) ;
    j := j + 3
    )
    else (if s[j+1] = "t" & s[j + 1+1] = "w" & s[j + 2+1] = "o" then
   (
      if (s.subrange(j + 3+1))->size() >= 2 & s[j + 3+1] = "n" & s[j + 4+1] = "e" then  (
      execute ((j + 3) : indexs) ;
    j := j + 5
    )
    else (
      execute ((j + 2) : indexs) ;
    j := j + 3
      ) ;
    r := r + 1    
)
    else (
      j := j + 1
      )    )
) ;
    execute (r)->display() ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name indexs))))))))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for i in range(t):
    s=input()
    c=0
    ind=0
    n=len(s)
    lsta=[]
    while True :
        if ind>n-1 :
            break
        else :
            if s[ind : ind+5]=="twone" :
                c+=1
                lsta.append(ind+3)
                ind+=5
            elif s[ind : ind+3]=="two" :
                c+=1
                lsta.append(ind+2)
                ind+=3
            elif s[ind : ind+3]=="one" :
                c+=1
                lsta.append(ind+2)
                ind+=3
            else :
                ind+=1
    print(c)
    print(*lsta)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, t-1) do (    var s : String := (OclFile["System.in"]).readLine() ;
    var c : int := 0 ;
    var ind : int := 0 ;
    var n : int := (s)->size() ;
    var lsta : Sequence := Sequence{} ;
    while true do (    if (ind->compareTo(n - 1)) > 0 then  (
      break
    )
    else (
      if s.subrange(ind+1, ind + 5) = "twone" then  (
      c := c + 1 ;
    execute ((ind + 3) : lsta) ;
    ind := ind + 5
    )
    else (if s.subrange(ind+1, ind + 3) = "two" then
   (
      c := c + 1 ;
    execute ((ind + 2) : lsta) ;
    ind := ind + 3    
)
    else (if s.subrange(ind+1, ind + 3) = "one" then
   (
      c := c + 1 ;
    execute ((ind + 2) : lsta) ;
    ind := ind + 3    
)
    else (
      ind := ind + 1
      )    )
    )
      )) ;
    execute (c)->display() ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name lsta))))))))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import stdin
n=int(input())
s=[stdin.readline()[:-1]for i in range(n)]
cnt=[[0]*26 for i in range(26)]
for i in range(n):
    t=s[i]
    m=len(t)
    l=ord(t[0])-97
    r=ord(t[-1])-97
    for i in range(26):
        if cnt[i][l]>0 :
            cnt[i][r]=max(cnt[i][r],cnt[i][l]+m)
    cnt[l][r]=max(cnt[l][r],m)
ans=max([cnt[i][i]for i in range(26)])
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (stdin.readLine()->front())) ;
    var cnt : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, 26))) ;
    for i : Integer.subrange(0, n-1) do (    var t : OclAny := s[i+1] ;
    var m : int := (t)->size() ;
    var l : double := (t->first())->char2byte() - 97 ;
    var r : double := (t->last())->char2byte() - 97 ;
    for i : Integer.subrange(0, 26-1) do (    if cnt[i+1][l+1] > 0 then (
      cnt[i+1][r+1] := Set{cnt[i+1][r+1], cnt[i+1][l+1] + m}->max()
    ) else skip) ;
    cnt[l+1][r+1] := Set{cnt[l+1][r+1], m}->max()) ;
    var ans : OclAny := (Integer.subrange(0, 26-1)->select(i | true)->collect(i | (cnt[i+1][i+1])))->max() ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from queue import PriorityQueue
from queue import Queue
import math
from collections import*
import sys
import operator as op
from functools import reduce
MOD=int(1e9+7)
input=sys.stdin.readline
def ii(): return list(map(int,input().strip().split()))
def ist(): return list(input().strip().split())
n,=ii()
l=[[0 for i in range(26)]for i in range(26)]
for i in range(n):
    s=input().strip()
    a,b=ord(s[0])-97,ord(s[-1])-97
    for j in range(26):
        if l[j][a]>0 :
            l[j][b]=max(l[j][a]+len(s),l[j][b])
    l[a][b]=max(l[a][b],len(s))
ans=0
for i in range(26):
    if l[i][i]>ans :
        ans=l[i][i]
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var MOD : int := ("" + ((("1e9")->toReal() + 7)))->toInteger() ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    skip ;
    skip ;
(testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,)    Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,)} := ii() ;
    var l : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | (Integer.subrange(0, 26-1)->select(i | true)->collect(i | (0)))) ;
    for i : Integer.subrange(0, n-1) do (    var s : OclAny := input()->trim() ;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := Sequence{(s->first())->char2byte() - 97,(s->last())->char2byte() - 97} ;
    for j : Integer.subrange(0, 26-1) do (    if l[j+1][a+1] > 0 then (
      l[j+1][b+1] := Set{l[j+1][a+1] + (s)->size(), l[j+1][b+1]}->max()
    ) else skip) ;
    l[a+1][b+1] := Set{l[a+1][b+1], (s)->size()}->max()) ;
    var ans : int := 0 ;
    for i : Integer.subrange(0, 26-1) do (    if (l[i+1][i+1]->compareTo(ans)) > 0 then (
      ans := l[i+1][i+1]
    ) else skip) ;
    execute (ans)->display();
  operation ii() : OclAny
  pre: true post: true
  activity:
    return ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ));
  operation ist() : OclAny
  pre: true post: true
  activity:
    return (input()->trim().split());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import stdin
n=int(input())
dp=[[0 for _ in range(26)]for _ in range(26)]
for _ in range(n):
    name=stdin.readline()[:-1]
    start=ord(name[0])-ord('a')
    end=ord(name[-1])-ord('a')
    for i in range(26):
        if dp[i][start]>0 :
            dp[i][end]=max(dp[i][end],dp[i][start]+len(name))
    dp[start][end]=max(dp[start][end],len(name))
ans=max([dp[i][i]for i in range(26)])
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var dp : Sequence := Integer.subrange(0, 26-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, 26-1)->select(_anon | true)->collect(_anon | (0)))) ;
    for _anon : Integer.subrange(0, n-1) do (    var name : OclAny := stdin.readLine()->front() ;
    var start : double := (name->first())->char2byte() - ('a')->char2byte() ;
    var end : double := (name->last())->char2byte() - ('a')->char2byte() ;
    for i : Integer.subrange(0, 26-1) do (    if dp[i+1][start+1] > 0 then (
      dp[i+1][end+1] := Set{dp[i+1][end+1], dp[i+1][start+1] + (name)->size()}->max()
    ) else skip) ;
    dp[start+1][end+1] := Set{dp[start+1][end+1], (name)->size()}->max()) ;
    var ans : OclAny := (Integer.subrange(0, 26-1)->select(i | true)->collect(i | (dp[i+1][i+1])))->max() ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def abs(x,y):
    if(y>x):
        return y-x
    else :
        return 12-(x-y)
k=["C","C#","D","D#","E","F","F#","G","G#","A","B","H"]
l=[i for i in input().split()]
a=k.index(l[0])
b=k.index(l[1])
c=k.index(l[2])
x1=abs(a,b)
x2=abs(b,a)
y1=abs(b,c)
y2=abs(c,b)
z1=abs(a,c)
z2=abs(c,a)
if((x1==3 and y1==4)or(z1==3 and y2==4)or(x2==3 and z1==4)or(y1==3 and z2==4)or(z2==3 and x1==4)or(y2==3 and x2==4)):
    print("minor")
elif((x1==4 and y1==3)or(z1==4 and y2==3)or(x2==4 and z1==3)or(y1==4 and z2==3)or(z2==4 and x1==3)or(y2==4 and x2==3)):
    print("major")
else :
    print("strange")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var k : Sequence := Sequence{"C"}->union(Sequence{"C#"}->union(Sequence{"D"}->union(Sequence{"D#"}->union(Sequence{"E"}->union(Sequence{"F"}->union(Sequence{"F#"}->union(Sequence{"G"}->union(Sequence{"G#"}->union(Sequence{"A"}->union(Sequence{"B"}->union(Sequence{ "H" }))))))))))) ;
    var l : Sequence := input().split()->select(i | true)->collect(i | (i)) ;
    var a : int := k->indexOf(l->first()) - 1 ;
    var b : int := k->indexOf(l[1+1]) - 1 ;
    var c : int := k->indexOf(l[2+1]) - 1 ;
    var x1 : double := (a, b)->abs() ;
    var x2 : double := (b, a)->abs() ;
    var y1 : double := (b, c)->abs() ;
    var y2 : double := (c, b)->abs() ;
    var z1 : double := (a, c)->abs() ;
    var z2 : double := (c, a)->abs() ;
    if ((x1 = 3 & y1 = 4) or (z1 = 3 & y2 = 4) or (x2 = 3 & z1 = 4) or (y1 = 3 & z2 = 4) or (z2 = 3 & x1 = 4) or (y2 = 3 & x2 = 4)) then  (
      execute ("minor")->display()
    )
    else (if ((x1 = 4 & y1 = 3) or (z1 = 4 & y2 = 3) or (x2 = 4 & z1 = 3) or (y1 = 4 & z2 = 3) or (z2 = 4 & x1 = 3) or (y2 = 4 & x2 = 3)) then
   (
      execute ("major")->display()    
)
    else (
      execute ("strange")->display()
      )    )
;
  operation abs(x : OclAny, y : OclAny) : OclAny
  pre: true post: true
  activity:
    if ((y->compareTo(x)) > 0) then  (
      return y - x
    )
    else (
      return 12 - (x - y)
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def perm(x,y,z):
    d={'C' : 1,'C#' : 2,'D' : 3,'D#' : 4,'E' : 5,'F' : 6,'F#' : 7,'G' : 8,'G#' : 9,'A' : 10,'B' : 11,'H' : 12}
    f=d[y]-d[x]if d[y]-d[x]>0 else d[y]-d[x]+12
    f2=d[z]-d[y]if d[z]-d[y]>0 else d[z]-d[y]+12
    if f==3 and f2==4 :
        return "minor"
    if f==4 and f2==3 :
        return "major"
def solve():
    val=perm(x,y,z)
    if val :
        return val
    val=perm(x,z,y)
    if val :
        return val
    val=perm(y,x,z)
    if val :
        return val
    val=perm(y,z,x)
    if val :
        return val
    val=perm(z,y,x)
    if val :
        return val
    val=perm(z,x,y)
    if val :
        return val
    return "strange"
from sys import stdin
input=stdin.readline
x,y,z=[x for x in input().split()]
print(solve())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    var input : OclAny := stdin.readline ;
    Sequence{x,y,z} := input().split()->select(x | true)->collect(x | (x)) ;
    execute (solve())->display();
  operation perm(x : OclAny, y : OclAny, z : OclAny) : OclAny
  pre: true post: true
  activity:
    var d : Map := Map{ 'C' |-> 1 }->union(Map{ 'C#' |-> 2 }->union(Map{ 'D' |-> 3 }->union(Map{ 'D#' |-> 4 }->union(Map{ 'E' |-> 5 }->union(Map{ 'F' |-> 6 }->union(Map{ 'F#' |-> 7 }->union(Map{ 'G' |-> 8 }->union(Map{ 'G#' |-> 9 }->union(Map{ 'A' |-> 10 }->union(Map{ 'B' |-> 11 }->union(Map{ 'H' |-> 12 }))))))))))) ;
    var f : double := if d[y+1] - d[x+1] > 0 then d[y+1] - d[x+1] else d[y+1] - d[x+1] + 12 endif ;
    var f2 : double := if d[z+1] - d[y+1] > 0 then d[z+1] - d[y+1] else d[z+1] - d[y+1] + 12 endif ;
    if f = 3 & f2 = 4 then (
      return "minor"
    ) else skip ;
    if f = 4 & f2 = 3 then (
      return "major"
    ) else skip;
  operation solve() : OclAny
  pre: true post: true
  activity:
    var val : OclAny := perm(x, y, z) ;
    if val then (
      return val
    ) else skip ;
    val := perm(x, z, y) ;
    if val then (
      return val
    ) else skip ;
    val := perm(y, x, z) ;
    if val then (
      return val
    ) else skip ;
    val := perm(y, z, x) ;
    if val then (
      return val
    ) else skip ;
    val := perm(z, y, x) ;
    if val then (
      return val
    ) else skip ;
    val := perm(z, x, y) ;
    if val then (
      return val
    ) else skip ;
    return "strange";
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
NOTES='C C# D D# E F F# G G# A B H'.split()
a,b,c=sorted(map(NOTES.index,input().split()))
x,y=b-a,c-b
if(x,y)in((3,5),(4,3),(5,4)):
    print('major')
elif(x,y)in((3,4),(4,5),(5,3)):
    print('minor')
else :
    print('strange')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var NOTES : OclAny := 'C C# D D# E F F# G G# A B H'.split() ;
    var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := (input().split())->collect( _x | (NOTES.index)->apply(_x) )->sort() ;
    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := Sequence{b - a,c - b} ;
    if (Sequence{Sequence{3, 5}, Sequence{4, 3}, Sequence{5, 4}})->includes(Sequence{x, y}) then  (
      execute ('major')->display()
    )
    else (if (Sequence{Sequence{3, 4}, Sequence{4, 5}, Sequence{5, 3}})->includes(Sequence{x, y}) then
   (
      execute ('minor')->display()    
)
    else (
      execute ('strange')->display()
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input());
l1=[]; l2=[]; l3=[];
sum1=0 ; sum2=0 ; sum3=0 ;
l1=list(map(int,input().split()))
sum1=sum(l1);
l2=list(map(int,input().split()))
sum2=sum(l2);
l3=list(map(int,input().split()))
sum3=sum(l3);
print(abs(sum1-sum2))
print(abs(sum2-sum3))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); ;
    var l1 : Sequence := Sequence{};    var l2 : Sequence := Sequence{};    var l3 : Sequence := Sequence{}; ;
    var sum1 : int := 0;    var sum2 : int := 0;    var sum3 : int := 0; ;
    l1 := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    sum1 := (l1)->sum(); ;
    l2 := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    sum2 := (l2)->sum(); ;
    l3 := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    sum3 := (l3)->sum(); ;
    execute ((sum1 - sum2)->abs())->display() ;
    execute ((sum2 - sum3)->abs())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=['C','C#','D','D#','E','F','F#','G','G#','A','B','H']
i=sorted(n.index(x)for x in input().split())
c=(i[1]-i[0],i[2]-i[1])
if c in((4,3),(3,5),(5,4)):
    print('major')
elif c in((3,4),(4,5),(5,3)):
    print('minor')
else :
    print('strange')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : Sequence := Sequence{'C'}->union(Sequence{'C#'}->union(Sequence{'D'}->union(Sequence{'D#'}->union(Sequence{'E'}->union(Sequence{'F'}->union(Sequence{'F#'}->union(Sequence{'G'}->union(Sequence{'G#'}->union(Sequence{'A'}->union(Sequence{'B'}->union(Sequence{ 'H' }))))))))))) ;
    var i : Sequence := (argument (test (logical_test (comparison (expr (atom (name n)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))->sort() ;
    var c : OclAny := Sequence{i[1+1] - i->first(), i[2+1] - i[1+1]} ;
    if (Sequence{Sequence{4, 3}, Sequence{3, 5}, Sequence{5, 4}})->includes(c) then  (
      execute ('major')->display()
    )
    else (if (Sequence{Sequence{3, 4}, Sequence{4, 5}, Sequence{5, 3}})->includes(c) then
   (
      execute ('minor')->display()    
)
    else (
      execute ('strange')->display()
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
A1,A2=map(int,input().split())
B=A1+A2
if B>=24 :
    B-=24
print(B)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var A1 : OclAny := null;
    var A2 : OclAny := null;
    Sequence{A1,A2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var B : OclAny := A1 + A2 ;
    if B >= 24 then (
      B := B - 24
    ) else skip ;
    execute (B)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
from itertools import permutations
d=['C','C#','D','D#','E','F','F#','G','G#','A','B','H']
w=input()[:-1].split()
w=list(permutations(w))
for s in w :
    if d.index(s[0])<=d.index(s[1]):
        a=d.index(s[1])-d.index(s[0])
    else :
        a=d.index(s[1])-d.index(s[0])+12
    if d.index(s[1])<=d.index(s[2]):
        b=d.index(s[2])-d.index(s[1])
    else :
        b=d.index(s[2])-d.index(s[1])+12
    if a==3 and b==4 :
        print('minor')
        break
    elif a==4 and b==3 :
        print('major')
        break
else :
    print('strange')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    skip ;
    var d : Sequence := Sequence{'C'}->union(Sequence{'C#'}->union(Sequence{'D'}->union(Sequence{'D#'}->union(Sequence{'E'}->union(Sequence{'F'}->union(Sequence{'F#'}->union(Sequence{'G'}->union(Sequence{'G#'}->union(Sequence{'A'}->union(Sequence{'B'}->union(Sequence{ 'H' }))))))))))) ;
    var w : OclAny := input()->front().split() ;
    w := (permutations(w)) ;
(compound_stmt for (exprlist (expr (atom (name s)))) in (testlist (test (logical_test (comparison (expr (atom (name w))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name d)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))) <= (comparison (expr (atom (name d)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name a)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name d)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))) - (expr (atom (name d)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name a)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (name d)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))) - (expr (atom (name d)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))) + (expr (atom (number (integer 12)))))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name d)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ))))) <= (comparison (expr (atom (name d)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name d)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))) )))) - (expr (atom (name d)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (name d)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))) )))) - (expr (atom (name d)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ))))) + (expr (atom (number (integer 12)))))))))))))))))) (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name a)))) == (comparison (expr (atom (number (integer 3))))))) and (logical_test (comparison (comparison (expr (atom (name b)))) == (comparison (expr (atom (number (integer 4))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'minor'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))) (elif_clause elif (test (logical_test (logical_test (comparison (comparison (expr (atom (name a)))) == (comparison (expr (atom (number (integer 4))))))) and (logical_test (comparison (comparison (expr (atom (name b)))) == (comparison (expr (atom (number (integer 3))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'major'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'strange'))))))) )))))))))))))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while 1 :
    N=input()
    if N=='0000' : break
    if N[0]==N[1]==N[2]==N[3]:
        print('NA')
        continue
    cnt=0
    while N!='6174' :
        x=int(''.join(reversed(sorted(list(N)))))-int(''.join(sorted(list(N))))
        N=str(x).zfill(4)
        cnt+=1
    print(cnt)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while 1 do (    var N : String := (OclFile["System.in"]).readLine() ;
    if N = '0000' then (
      break
    ) else skip ;
    if N->first() = N[1+1] & (N[1+1] == N[2+1]) & (N[2+1] == N[3+1]) then (
      execute ('NA')->display() ;
    continue
    ) else skip ;
    var cnt : int := 0 ;
    while N /= '6174' do (    var x : double := ("" + ((StringLib.sumStringsWithSeparator((((N)->characters()->sort())->reverse()), ''))))->toInteger() - ("" + ((StringLib.sumStringsWithSeparator(((N)->characters()->sort()), ''))))->toInteger() ;
    N := OclType["String"](x).zfill(4) ;
    cnt := cnt + 1) ;
    execute (cnt)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
Memo={d*4 : 'NA' for d in '0123456789'}
Memo['6174']=0
def solve(N):
    x=N
    res=[]
    while x not in Memo :
        res.append(x)
        l=''.join(sorted(x,reverse=True))
        s=''.join(sorted(x))
        x='{:04d}'.format(int(l)-int(s))
    for i,r in enumerate(res):
        Memo[r]=len(res)-i+Memo[x]
    return Memo[N]
def main(args):
    while True :
        N=input()
        if N=='0000' :
            break
        ans=solve(N)
        print(ans)
if __name__=='__main__' :
    main(sys.argv[1 :])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var Memo : Map := '0123456789'->characters()->select(d | true)->collect(d | Map{d * 4 |-> 'NA'})->unionAll() ;
    Memo->at('6174') := 0 ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))
    ) else skip;
  operation solve(N : OclAny) : OclAny
  pre: true post: true
  activity:
    var x : OclAny := N ;
    var res : Sequence := Sequence{} ;
    while (Memo)->excludes(x) do (    execute ((x) : res) ;
    var l : String := StringLib.sumStringsWithSeparator((x->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True))))))))), '') ;
    var s : String := StringLib.sumStringsWithSeparator((x->sort()), '') ;
    x := StringLib.interpolateStrings('{:04d}', Sequence{("" + ((l)))->toInteger() - ("" + ((s)))->toInteger()})) ;
    for _tuple : Integer.subrange(1, (res)->size())->collect( _indx | Sequence{_indx-1, (res)->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var r : OclAny := _tuple->at(_indx);
      Memo[r+1] := (res)->size() - i + Memo[x+1]) ;
    return Memo[N+1];
  operation main(args : OclAny)
  pre: true post: true
  activity:
    while true do (    N := (OclFile["System.in"]).readLine() ;
    if N = '0000' then (
      break
    ) else skip ;
    var ans : OclAny := solve(N) ;
    execute (ans)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    number=int(input())
    if number==0000 :
        break
    trial=0
    while True :
        if number==6174 :
            print(trial)
            break
        box=[]
        for i in range(4):
            a=number % 10
            number=int(number/10)
            box.append(a)
        if box[0]==box[1]and box[2]==box[3]and box[1]==box[2]:
            print("NA")
            break
        box.sort()
        l=0
        for i in range(4):
            l+=box[i]*10**i
        box.sort(reverse=True)
        s=0
        for i in range(4):
            s+=box[i]*10**i
        number=l-s
        trial+=1
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    var number : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if number = 0000 then (
      break
    ) else skip ;
    var trial : int := 0 ;
    while true do (    if number = 6174 then (
      execute (trial)->display() ;
    break
    ) else skip ;
    var box : Sequence := Sequence{} ;
    for i : Integer.subrange(0, 4-1) do (    var a : int := number mod 10 ;
    number := ("" + ((number / 10)))->toInteger() ;
    execute ((a) : box)) ;
    if box->first() = box[1+1] & box[2+1] = box[3+1] & box[1+1] = box[2+1] then (
      execute ("NA")->display() ;
    break
    ) else skip ;
    box := box->sort() ;
    var l : int := 0 ;
    for i : Integer.subrange(0, 4-1) do (    l := l + box[i+1] * (10)->pow(i)) ;
    box := box->sort() ;
    var s : int := 0 ;
    for i : Integer.subrange(0, 4-1) do (    s := s + box[i+1] * (10)->pow(i)) ;
    number := l - s ;
    trial := trial + 1));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    N=input()
    if N=="0000" :
        break
    nums=[int(N[i])for i in range(4)]
    ans=1
    while True :
        nums.sort()
        S=nums[3]*1000+nums[2]*100+nums[1]*10+nums[0]
        T=nums[0]*1000+nums[1]*100+nums[2]*10+nums[3]
        if S-T==6174 :
            break
        elif S-T==0 :
            ans=-1
            break
        else :
            K=S-T
            nums[0]=K//1000
            K-=nums[0]*1000
            nums[1]=K//100
            K-=nums[1]*100
            nums[2]=K//10
            K-=nums[2]*10
            nums[3]=K
            ans=ans+1
    if ans==-1 :
        print("NA")
    elif N=="6174" :
        print(0)
    else :
        print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    var N : String := (OclFile["System.in"]).readLine() ;
    if N = "0000" then (
      break
    ) else skip ;
    var nums : Sequence := Integer.subrange(0, 4-1)->select(i | true)->collect(i | (("" + ((N[i+1])))->toInteger())) ;
    var ans : int := 1 ;
    while true do (    nums := nums->sort() ;
    var S : double := nums[3+1] * 1000 + nums[2+1] * 100 + nums[1+1] * 10 + nums->first() ;
    var T : double := nums->first() * 1000 + nums[1+1] * 100 + nums[2+1] * 10 + nums[3+1] ;
    if S - T = 6174 then  (
      break
    )
    else (if S - T = 0 then
   (
      ans := -1 ;
    break    
)
    else (
      var K : double := S - T ;
    nums->first() := K div 1000 ;
    K := K - nums->first() * 1000 ;
    nums[1+1] := K div 100 ;
    K := K - nums[1+1] * 100 ;
    nums[2+1] := K div 10 ;
    K := K - nums[2+1] * 10 ;
    nums[3+1] := K ;
    ans := ans + 1
      )    )
) ;
    if ans = -1 then  (
      execute ("NA")->display()
    )
    else (if N = "6174" then
   (
      execute (0)->display()    
)
    else (
      execute (ans)->display()
      )    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def to_number(n):
    res=0
    for d in n :
        res=res*10+d
    return res
if __name__=="__main__" :
    while True :
        n=input()
        if n=='0000' :
            break
        cnt=0
        used=set()
        while n!='6174' :
            if n in used :
                cnt='NA'
                break
            used.add(n)
            n=list(map(int,list(n)))
            n.sort()
            a=to_number(n[: :-1])
            b=to_number(n)
            a-=b
            n=str(a)
            while len(n)<4 :
                n='0'+n
            cnt+=1
        print(cnt)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      while true do (    n := (OclFile["System.in"]).readLine() ;
    if n = '0000' then (
      break
    ) else skip ;
    var cnt : int := 0 ;
    var used : Set := Set{}->union(()) ;
    while n /= '6174' do (    if (used)->includes(n) then (
      cnt := 'NA' ;
    break
    ) else skip ;
    execute ((n) : used) ;
    n := (((n))->collect( _x | (OclType["int"])->apply(_x) )) ;
    n := n->sort() ;
    var a : OclAny := to_number(n(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ;
    var b : OclAny := to_number(n) ;
    a := a - b ;
    n := ("" + ((a))) ;
    while (n)->size() < 4 do (    n := '0' + n) ;
    cnt := cnt + 1) ;
    execute (cnt)->display())
    ) else skip;
  operation to_number(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var res : int := 0 ;
    for d : n do (    res := res * 10 + d) ;
    return res;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
r=int(input())
a=[]
for i in range(r):
    x1,y1,z1=str(input()).split()
    x2,y2,z2=str(input()).split()
    x1,y1,z1=int(x1),int(y1),int(z1)
    x2,y2,z2=int(x2),int(y2),int(z2)
    k=0
    if z1>0 :
        k+=(2*min(z1,y2))
        t=min(z1,y2)
        z1-=t
        y2-=t
    if z1>0 :
        t=min(z1,z2)
        z1-=t
        z2-=t
    if z1>0 :
        t=min(z1,x2)
        z1-=t
        x2-=t
    if y1>0 :
        t=min(y1,y2)
        y1-=t
        y2-=t
    if y1>0 :
        t=min(y1,x2)
        y1-=t
        x2-=t
    if y1>0 :
        k-=(2*min(y1,z2))
        t=min(y1,z2)
        y1-=t
        z2-=t
    a.append(k)
for u in range(len(a)):
    print(a[u])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var r : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := Sequence{} ;
    for i : Integer.subrange(0, r-1) do (    var x1 : OclAny := null;
    var y1 : OclAny := null;
    var z1 : OclAny := null;
    Sequence{x1,y1,z1} := OclType["String"]((OclFile["System.in"]).readLine()).split() ;
    var x2 : OclAny := null;
    var y2 : OclAny := null;
    var z2 : OclAny := null;
    Sequence{x2,y2,z2} := OclType["String"]((OclFile["System.in"]).readLine()).split() ;
    var x1 : OclAny := null;
    var y1 : OclAny := null;
    var z1 : OclAny := null;
    Sequence{x1,y1,z1} := Sequence{("" + ((x1)))->toInteger(),("" + ((y1)))->toInteger(),("" + ((z1)))->toInteger()} ;
    var x2 : OclAny := null;
    var y2 : OclAny := null;
    var z2 : OclAny := null;
    Sequence{x2,y2,z2} := Sequence{("" + ((x2)))->toInteger(),("" + ((y2)))->toInteger(),("" + ((z2)))->toInteger()} ;
    var k : int := 0 ;
    if z1 > 0 then (
      k := k + (2 * Set{z1, y2}->min()) ;
    var t : OclAny := Set{z1, y2}->min() ;
    z1 := z1 - t ;
    y2 := y2 - t
    ) else skip ;
    if z1 > 0 then (
      t := Set{z1, z2}->min() ;
    z1 := z1 - t ;
    z2 := z2 - t
    ) else skip ;
    if z1 > 0 then (
      t := Set{z1, x2}->min() ;
    z1 := z1 - t ;
    x2 := x2 - t
    ) else skip ;
    if y1 > 0 then (
      t := Set{y1, y2}->min() ;
    y1 := y1 - t ;
    y2 := y2 - t
    ) else skip ;
    if y1 > 0 then (
      t := Set{y1, x2}->min() ;
    y1 := y1 - t ;
    x2 := x2 - t
    ) else skip ;
    if y1 > 0 then (
      k := k - (2 * Set{y1, z2}->min()) ;
    t := Set{y1, z2}->min() ;
    y1 := y1 - t ;
    z2 := z2 - t
    ) else skip ;
    execute ((k) : a)) ;
    for u : Integer.subrange(0, (a)->size()-1) do (    execute (a[u+1])->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for p in range(int(input())):
    a,b,c=list(map(int,input().split()))
    x,y,z=list(map(int,input().split()))
    z-=a
    if z<0 : z=0
    if c>=z :
        c-=z
        s=min(c,y)*2
    else :
        z-=c
        s=min(z,b)*2*(-1)
    print(s)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for p : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var x : OclAny := null;
    var y : OclAny := null;
    var z : OclAny := null;
    Sequence{x,y,z} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    z := z - a ;
    if z < 0 then (
      var z : int := 0
    ) else skip ;
    if (c->compareTo(z)) >= 0 then  (
      c := c - z ;
    var s : double := Set{c, y}->min() * 2
    )
    else (
      z := z - c ;
    s := Set{z, b}->min() * 2 * (-1)
      ) ;
    execute (s)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
arr=list(map(int,input().split()))
ans=-1
temp=0
seen=set()
p=0
while len(seen)!=n :
    ans+=1
    if p % 2==0 :
        for i in range(n):
            if i not in seen and arr[i]<=temp :
                seen.add(i)
                temp+=1
        p+=1
    else :
        for i in range(n-1,-1,-1):
            if i not in seen and arr[i]<=temp :
                seen.add(i)
                temp+=1
        p+=1
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var ans : int := -1 ;
    var temp : int := 0 ;
    var seen : Set := Set{}->union(()) ;
    var p : int := 0 ;
    while (seen)->size() /= n do (    ans := ans + 1 ;
    if p mod 2 = 0 then  (
      for i : Integer.subrange(0, n-1) do (    if (seen)->excludes(i) & (arr[i+1]->compareTo(temp)) <= 0 then (
      execute ((i) : seen) ;
    temp := temp + 1
    ) else skip) ;
    p := p + 1
    )
    else (
      for i : Integer.subrange(-1 + 1, n - 1)->reverse() do (    if (seen)->excludes(i) & (arr[i+1]->compareTo(temp)) <= 0 then (
      execute ((i) : seen) ;
    temp := temp + 1
    ) else skip) ;
    p := p + 1
      )) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
x=0
y=0
z=0
for i in a :
    x+=i
for i in b :
    y+=i
for i in c :
    z+=i
print(abs(x-y))
print(abs(y-z))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var x : int := 0 ;
    var y : int := 0 ;
    var z : int := 0 ;
    for i : a do (    x := x + i) ;
    for i : b do (    y := y + i) ;
    for i : c do (    z := z + i) ;
    execute ((x - y)->abs())->display() ;
    execute ((y - z)->abs())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import gc
import math
from collections import Counter,deque,defaultdict
from sys import stdout
import time
from math import factorial,log,gcd
import sys
from decimal import Decimal
import threading
from heapq import*
def S():
    return sys.stdin.readline().split()
def I():
    return[int(i)for i in sys.stdin.readline().split()]
def II():
    return int(sys.stdin.readline())
def IS():
    return sys.stdin.readline().replace('\n','')
def main():
    a0,a1,a2=I()
    b0,b1,b2=I()
    if a2>=b1 :
        ans=2*b1
        a2-=b1
        b1=0
    else :
        ans=2*a2
        b1-=a2
        a2=0
    s=a0+a2
    ans-=2*max(0,b2-s)
    print(ans)
if __name__=='__main__' :
    for _ in range(II()):
        main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      for _anon : Integer.subrange(0, II()-1) do (    main())
    ) else skip;
  operation S() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine().split();
  operation I() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()));
  operation II() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation IS() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine().replace('
', '');
  operation main()
  pre: true post: true
  activity:
    var a0 : OclAny := null;
    var a1 : OclAny := null;
    var a2 : OclAny := null;
    Sequence{a0,a1,a2} := I() ;
    var b0 : OclAny := null;
    var b1 : OclAny := null;
    var b2 : OclAny := null;
    Sequence{b0,b1,b2} := I() ;
    if (a2->compareTo(b1)) >= 0 then  (
      var ans : double := 2 * b1 ;
    a2 := a2 - b1 ;
    var b1 : int := 0
    )
    else (
      ans := 2 * a2 ;
    b1 := b1 - a2 ;
    var a2 : int := 0
      ) ;
    var s : OclAny := a0 + a2 ;
    ans := ans - 2 * Set{0, b2 - s}->max() ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for i in range(t):
    x1,y1,z1=(int(i)for i in input().split())
    x2,y2,z2=(int(i)for i in input().split())
    s=2*min(z1,y2)-2*max(0,min(z2-x1,z2-x1-z1+y2))
    print(s)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, t-1) do (    var x1 : OclAny := null;
    var y1 : OclAny := null;
    var z1 : OclAny := null;
    Sequence{x1,y1,z1} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ;
    var x2 : OclAny := null;
    var y2 : OclAny := null;
    var z2 : OclAny := null;
    Sequence{x2,y2,z2} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ;
    var s : double := 2 * Set{z1, y2}->min() - 2 * Set{0, Set{z2 - x1, z2 - x1 - z1 + y2}->min()}->max() ;
    execute (s)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
print(sum(map(int,input().split()))% 24)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     execute (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum() mod 24)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
iter=int(input())
for _ in range(iter):
    x1,y1,z1=list(map(int,input().split(' ')))
    x2,y2,z2=list(map(int,input().split(' ')))
    ans=0
    ans+=min(z1,y2)*2
    t=z1
    z1-=min(z1,y2)
    y2-=min(t,y2)
    z2-=min(z1,z2)
    z2-=min(z2,x1)
    y1-=min(y1,x2)
    ans-=min(z2,y1)*2
    print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var iter : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, iter-1) do (    var x1 : OclAny := null;
    var y1 : OclAny := null;
    var z1 : OclAny := null;
    Sequence{x1,y1,z1} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ;
    var x2 : OclAny := null;
    var y2 : OclAny := null;
    var z2 : OclAny := null;
    Sequence{x2,y2,z2} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ;
    var ans : int := 0 ;
    ans := ans + Set{z1, y2}->min() * 2 ;
    var t : OclAny := z1 ;
    z1 := z1 - Set{z1, y2}->min() ;
    y2 := y2 - Set{t, y2}->min() ;
    z2 := z2 - Set{z1, z2}->min() ;
    z2 := z2 - Set{z2, x1}->min() ;
    y1 := y1 - Set{y1, x2}->min() ;
    ans := ans - Set{z2, y1}->min() * 2 ;
    execute (ans)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
MAX=100000 ;
primes=[];
def sieve():
    isComposite=[False]*(MAX+1);
    i=2 ;
    while(i*i<=MAX):
        if(isComposite[i]==False):
            j=2 ;
            while(j*i<=MAX):
                isComposite[i*j]=True ;
                j+=1 ;
        i+=1 ;
    for i in range(2,MAX+1):
        if(isComposite[i]==False):
            primes.append(i);
def LCM(n):
    lcm=1 ;
    i=0 ;
    while(idisplay();;
  operation sieve()
  pre: true post: true
  activity:
    var isComposite : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (MAX + 1)); ;
    var i : int := 2; ;
    while ((i * i->compareTo(MAX)) <= 0) do (    if (isComposite[i+1] = false) then (
      var j : int := 2; ;
    while ((j * i->compareTo(MAX)) <= 0) do (    isComposite[i * j+1] := true; ;
    j := j + 1;)
    ) else skip ;
    i := i + 1;) ;
    for i : Integer.subrange(2, MAX + 1-1) do (    if (isComposite[i+1] = false) then (
      execute ((i) : primes);
    ) else skip);
  operation LCM(n : OclAny)
  pre: true post: true
  activity:
    var lcm : int := 1; ;
    i := 0; ;
    while ((i->compareTo((primes)->size())) < 0 & (primes[i+1]->compareTo(n)) <= 0) do (    var pp : OclAny := primes[i+1]; ;
    while ((pp * primes[i+1]->compareTo(n)) <= 0) do (    pp := pp * primes[i+1];) ;
    lcm := lcm * pp; ;
    lcm := lcm mod 1000000007; ;
    i := i + 1;) ;
    return lcm;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def print_asterisk(asterisk):
    if(asterisk==0):
        return ;
    print("*",end="");
    print_asterisk(asterisk-1);
def print_space(space):
    if(space==0):
        return ;
    print("",end="");
    print("",end="");
    print_space(space-1);
def pattern(n,num):
    if(n==0):
        return ;
    print_asterisk(n);
    print_space(2*(num-n)+1);
    print_asterisk(n);
    print("");
    pattern(n-1,num);
if __name__=='__main__' :
    n=5 ;
    pattern(n,n);
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      n := 5; ;
    pattern(n, n);
    ) else skip;
  operation print_asterisk(asterisk : OclAny) : OclAny
  pre: true post: true
  activity:
    if (asterisk = 0) then (
      return;
    ) else skip ;
    execute ("*")->display(); ;
    print_asterisk(asterisk - 1);;
  operation print_space(space : OclAny) : OclAny
  pre: true post: true
  activity:
    if (space = 0) then (
      return;
    ) else skip ;
    execute ("")->display(); ;
    execute ("")->display(); ;
    print_space(space - 1);;
  operation pattern(n : OclAny, num : OclAny) : OclAny
  pre: true post: true
  activity:
    if (n = 0) then (
      return;
    ) else skip ;
    print_asterisk(n); ;
    print_space(2 * (num - n) + 1); ;
    print_asterisk(n); ;
    execute ("")->display(); ;
    pattern(n - 1, num);;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def print_asterisk(asterisk):
    if(asterisk==0):
        return ;
    print("*",end="");
    print_asterisk(asterisk-1);
def print_space(space):
    if(space==0):
        return ;
    print("",end="");
    print("",end="");
    print_space(space-1);
def pattern(n,num):
    if(n==0):
        return ;
    print_asterisk(num-n+1);
    print_space(2*n-1);
    print_asterisk(num-n+1);
    print();
    pattern(n-1,num);
if __name__=='__main__' :
    n=5 ;
    pattern(n,n);
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      n := 5; ;
    pattern(n, n);
    ) else skip;
  operation print_asterisk(asterisk : OclAny) : OclAny
  pre: true post: true
  activity:
    if (asterisk = 0) then (
      return;
    ) else skip ;
    execute ("*")->display(); ;
    print_asterisk(asterisk - 1);;
  operation print_space(space : OclAny) : OclAny
  pre: true post: true
  activity:
    if (space = 0) then (
      return;
    ) else skip ;
    execute ("")->display(); ;
    execute ("")->display(); ;
    print_space(space - 1);;
  operation pattern(n : OclAny, num : OclAny) : OclAny
  pre: true post: true
  activity:
    if (n = 0) then (
      return;
    ) else skip ;
    print_asterisk(num - n + 1); ;
    print_space(2 * n - 1); ;
    print_asterisk(num - n + 1); ;
    execute (->display(); ;
    pattern(n - 1, num);;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
z=list(map(int,input().split()))
d=dict()
for i in range(t):
    d[z[i]]=i
ans=0
f=0
for i in range(t):
    p=z[i]
    if(d[p]==p):
        ans+=1
        del d[p]
    else :
        f=1
p=1
for i in d :
    hai=i
    ind=d[i]
    if(d[i]!=i and d[d[i]]==i):
        p=2
        break
if(f==1):
    print(p+ans)
else :
    print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var z : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var d : Map := (arguments ( )) ;
    for i : Integer.subrange(0, t-1) do (    d[z[i+1]+1] := i) ;
    var ans : int := 0 ;
    var f : int := 0 ;
    for i : Integer.subrange(0, t-1) do (    var p : OclAny := z[i+1] ;
    if (d[p+1] = p) then  (
      ans := ans + 1 ;
    execute (d[p+1])->isDeleted()
    )
    else (
      f := 1
      )) ;
    p := 1 ;
    for i : d->keys() do (    var hai : OclAny := i ;
    var ind : OclAny := d[i+1] ;
    if (d[i+1] /= i & d[d[i+1]+1] = i) then (
      p := 2 ;
    break
    ) else skip) ;
    if (f = 1) then  (
      execute (p + ans)->display()
    )
    else (
      execute (ans)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a=[int(i)for i in input().split()]
ans=len([i for i in range(n)if i==a[i]])
d={key : val for key,val in zip(a,[i for i in range(n)])}
if ans==n : print(ans)
else :
    cond=False
    for i in range(n):
        if a[i]!=i :
            if d[i]==a[i]: cond=True ; break
    if cond : ans+=2
    else : ans+=1
    print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var ans : int := (Integer.subrange(0, n-1)->select(i | i = a[i+1])->collect(i | (i)))->size() ;
    var d : Map := Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), Integer.subrange(0, n-1)->select(i | true)->collect(i | (i))->at(_indx)} )->select(_tuple | true)->collect(_tuple | Map{key |-> val})->unionAll() ;
    if ans = n then  (
      execute (ans)->display()
    )
    else (
      var cond : boolean := false ;
    for i : Integer.subrange(0, n-1) do (    if a[i+1] /= i then (
      if d[i+1] = a[i+1] then (
      cond := true;    break
    ) else skip
    ) else skip) ;
    if cond then  (
      ans := ans + 2
    )
    else (
      ans := ans + 1
      ) ;
    execute (ans)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
input()
a=[int(x)for x in input().split()]
c=f=0
for i in a :
    if a[i]==i :
        c=c+1
    elif a[a[i]]==i :
        f=1
ans=min(len(a),c+f+1)
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     input() ;
    var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    var c : OclAny := 0; var f : int := 0 ;
    for i : a do (    if a[i+1] = i then  (
      c := c + 1
    )
    else (if a[a[i+1]+1] = i then
   (
      f := 1    
)
 else skip)) ;
    var ans : OclAny := Set{(a)->size(), c + f + 1}->min() ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import Counter
n=int(input())
ls1=input().split()
ls2=input().split()
ls3=input().split()
print(min((Counter(ls1)-Counter(ls2)).elements()))
print(min((Counter(ls2)-Counter(ls3)).elements()))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var ls1 : OclAny := input().split() ;
    var ls2 : OclAny := input().split() ;
    var ls3 : OclAny := input().split() ;
    execute (((Counter(ls1) - Counter(ls2)).elements())->min())->display() ;
    execute (((Counter(ls2) - Counter(ls3)).elements())->min())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a=list(map(int,input().split()))
ans=0 ; s=0 ; e=0
for i in range(n):
    if a[i]==i :
        ans+=1
    else :
        b=a[i]
        if a[b]==i :
            s=2
        else :
            e=1
if s==2 :
    ans+=2
else :
    if e==1 :
        ans+=1
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var ans : int := 0;    var s : int := 0;    var e : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    if a[i+1] = i then  (
      ans := ans + 1
    )
    else (
      var b : OclAny := a[i+1] ;
    if a[b+1] = i then  (
      s := 2
    )
    else (
      e := 1
      )
      )) ;
    if s = 2 then  (
      ans := ans + 2
    )
    else (
      if e = 1 then (
      ans := ans + 1
    ) else skip
      ) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a=list(map(int,input().split()))
b=[]
for i in range(n):
    if i==a[i]:
        b.append(0)
    else :
        if a[a[i]]==i :
            b.append(2)
        else :
            b.append(1)
print(b.count(0)+max(b))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var b : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    if i = a[i+1] then  (
      execute ((0) : b)
    )
    else (
      if a[a[i+1]+1] = i then  (
      execute ((2) : b)
    )
    else (
      execute ((1) : b)
      )
      )) ;
    execute (b->count(0) + (b)->max())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def AVLnodes(height):
    if(height==0):
        return 1
    elif(height==1):
        return 2
    return(1+AVLnodes(height-1)+AVLnodes(height-2))
if __name__=='__main__' :
    H=3
    print(AVLnodes(H))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      var H : int := 3 ;
    execute (AVLnodes(H))->display()
    ) else skip;
  operation AVLnodes(height : OclAny) : OclAny
  pre: true post: true
  activity:
    if (height = 0) then  (
      return 1
    )
    else (if (height = 1) then
   (
      return 2    
)
 else skip) ;
    return (1 + AVLnodes(height - 1) + AVLnodes(height - 2));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=[int(i)for i in input().split()]
print((a+b)% 24)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    execute ((a + b) mod 24)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def longest_gap(N):
    distance=0
    count=0
    first_1=-1
    last_1=-1
    while(N>0):
        count+=1
        r=N & 1
        if(r==1):
            if first_1==-1 :
                first_1=count
            else :
                first_1=first_1
            last_1=count
        N=N//2
    if(last_1<=first_1):
        return-1
    else :
        distance=last_1-first_1-1
        return distance
N=131
print(longest_gap(N))
N=8
print(longest_gap(N))
N=17
print(longest_gap(N))
N=33
print(longest_gap(N))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    N := 131 ;
    execute (longest_gap(N))->display() ;
    N := 8 ;
    execute (longest_gap(N))->display() ;
    N := 17 ;
    execute (longest_gap(N))->display() ;
    N := 33 ;
    execute (longest_gap(N))->display();
  operation longest_gap(N : OclAny) : OclAny
  pre: true post: true
  activity:
    var distance : int := 0 ;
    var count : int := 0 ;
    var first    var distance : int := 0 : int := -1 ;
    var last    var distance : int := 0 : int := -1 ;
    while (N > 0) do (    count := count + 1 ;
    var r : int := MathLib.bitwiseAnd(N, 1) ;
    if (r = 1) then (
      if first    count := count + 1 = -1 then  (
      first    count := count + 1 := count
    )
    else (
      first    count := count + 1 := first    count := count + 1
      ) ;
    last    if first    count := count + 1 = -1 then  (
      first    count := count + 1 := count
    )
    else (
      first    count := count + 1 := first    count := count + 1
      ) := count
    ) else skip ;
    N := N div 2) ;
    if ((last    var distance : int := 0->compareTo(first    var distance : int := 0)) <= 0) then  (
      return -1
    )
    else (
      distance := last    var distance : int := 0 - first    var distance : int := 0 - 1 ;
    return distance
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def CalculateDifference(arr,n):
    max_val=-1
    for i in range(0,n):
        if(arr[i]>max_val):
            max_val=arr[i]
    prime=[True for i in range(max_val+1)]
    prime[0]=False
    prime[1]=False
    p=2
    while(p*p<=max_val):
        if prime[p]==True :
            for i in range(p*2,max_val+1,p):
                prime[i]=False
        p+=1
    S1=0
    S2=0
    for i in range(0,n):
        if prime[arr[i]]:
            S1+=arr[i]
        elif arr[i]!=1 :
            S2+=arr[i]
    return abs(S2-S1)
arr=[1,3,5,10,15,7]
n=len(arr)
print(CalculateDifference(arr,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    arr := Sequence{1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{10}->union(Sequence{15}->union(Sequence{ 7 }))))) ;
    n := (arr)->size() ;
    execute (CalculateDifference(arr, n))->display();
  operation CalculateDifference(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var max_val : int := -1 ;
    for i : Integer.subrange(0, n-1) do (    if ((arr[i+1]->compareTo(max_val)) > 0) then (
      max_val := arr[i+1]
    ) else skip) ;
    var prime : Sequence := Integer.subrange(0, max_val + 1-1)->select(i | true)->collect(i | (true)) ;
    prime->first() := false ;
    prime[1+1] := false ;
    var p : int := 2 ;
    while ((p * p->compareTo(max_val)) <= 0) do (    if prime[p+1] = true then (
      for i : Integer.subrange(p * 2, max_val + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do (    prime[i+1] := false)
    ) else skip ;
    p := p + 1) ;
    var S1 : int := 0 ;
    var S2 : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    if prime[arr[i+1]+1] then  (
      S1 := S1 + arr[i+1]
    )
    else (if arr[i+1] /= 1 then
   (
      S2 := S2 + arr[i+1]    
)
 else skip)) ;
    return (S2 - S1)->abs();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def center_pentadecagonal_num(n):
    return(15*n*n-15*n+2)//2
if __name__=='__main__' :
    n=3
    print(n,"rd number : ",center_pentadecagonal_num(n))
    n=10
    print(n,"th number : ",center_pentadecagonal_num(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      n := 3 ;
    execute (n)->display() ;
    n := 10 ;
    execute (n)->display()
    ) else skip;
  operation center_pentadecagonal_num(n : OclAny) : OclAny
  pre: true post: true
  activity:
    return (15 * n * n - 15 * n + 2) div 2;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    n=int(input())
    s=input()
    if(n==2 and s[0]>=s[1]):
        print("NO")
    else :
        print("YES")
        print("2")
        print(s[0]+" "+s[1 :])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : String := (OclFile["System.in"]).readLine() ;
    if (n = 2 & (s->first()->compareTo(s[1+1])) >= 0) then  (
      execute ("NO")->display()
    )
    else (
      execute ("YES")->display() ;
    execute ("2")->display() ;
    execute (s->first() + " " + s->tail())->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
for q in range(n):
    k=int(input())
    s=input()
    if len(s)<2 :
        print('NO')
    elif len(s)==2 and int(s[0])>=int(s[1]):
        print('NO')
    else :
        print('YES')
        print('2')
        print(s[0]+' '+s[1 :])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for q : Integer.subrange(0, n-1) do (    var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : String := (OclFile["System.in"]).readLine() ;
    if (s)->size() < 2 then  (
      execute ('NO')->display()
    )
    else (if (s)->size() = 2 & (("" + ((s->first())))->toInteger()->compareTo(("" + ((s[1+1])))->toInteger())) >= 0 then
   (
      execute ('NO')->display()    
)
    else (
      execute ('YES')->display() ;
    execute ('2')->display() ;
    execute (s->first() + ' ' + s->tail())->display()
      )    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in[0]*int(input()): input(); s=input(); x,y=int(s[0]),int(s[1 :]); print(('NO',f'YES 2{x}{y}')[xtoInteger()) do (    input();    var s : String := (OclFile["System.in"]).readLine();    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := Sequence{("" + ((s->first())))->toInteger(),("" + ((s->tail())))->toInteger()};    execute (Sequence{'NO', StringLib.formattedString('YES 2{x}{y}')}->select((x->compareTo(y)) < 0))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import stdin
input=stdin.readline
n=int(input()); error1=list(map(int,input().split())); error2=list(map(int,input().split())); error3=list(map(int,input().split()))
error1.sort(); error2.sort(); error3.sort(); l=0 ; r=n-2
for i in range(n-1):
    if error2[i]!=error1[i]:
        print(error1[i]); break
else :
    print(error1[-1])
for i in range(n-2):
    if error3[i]!=error2[i]:
        print(error2[i]); break
else :
    print(error2[-1])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := stdin.readline ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger();    var error1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ));    var error2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ));    var error3 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    error1 := error1->sort();    error2 := error2->sort();    error3 := error3->sort();    var l : int := 0;    var r : double := n - 2 ;
(compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name error2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) != (comparison (expr (atom (name error1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name error1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))))))))) ; (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name error1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))))) ))))))))))))))) ;
(compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 2)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name error3)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) != (comparison (expr (atom (name error2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name error2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))))))))) ; (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name error2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))))) )))))))))))))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
while t :
    n=int(input())
    s=input()
    d=s[1 :]
    if int(s[0])>=int(d):
        print('NO')
    else :
        print('YES')
        print(2)
        print(s[0],d)
    t-=1
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    while t do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : String := (OclFile["System.in"]).readLine() ;
    var d : OclAny := s->tail() ;
    if (("" + ((s->first())))->toInteger()->compareTo(("" + ((d)))->toInteger())) >= 0 then  (
      execute ('NO')->display()
    )
    else (
      execute ('YES')->display() ;
    execute (2)->display() ;
    execute (s->first())->display()
      ) ;
    t := t - 1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in[0]*int(input()):
    n=int(input())
    a=input()
    print(['NO','YES\n2\n'+a[0]+' '+a[1 :]][a[0]2])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : String := (OclFile["System.in"]).readLine() ;
    execute (Sequence{'NO'}->union(Sequence{ 'YES
2
' + a->first() + ' ' + a->tail() })->select((a->first()->compareTo(a[1+1])) < 0 or n > 2))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def minn(x,y,z):
    return min(min(x,y),z)
def editDistDP(str1,str2,m,n):
    dp=[[0 for i in range(n+1)]for j in range(m+1)]
    for i in range(m+1):
        for j in range(n+1):
            if(i==0):
                dp[i][j]=j
            elif(j==0):
                dp[i][j]=i
            elif(str1[i-1]==str2[j-1]):
                dp[i][j]=dp[i-1][j-1]
            else :
                dp[i][j]=1+minn(dp[i][j-1],dp[i-1][j],dp[i-1][j-1])
    return dp[m][n]
def areKDistant(str1,str2,k):
    m=len(str1)
    n=len(str2)
    if(abs(m-n)>k):
        return False
    return(editDistDP(str1,str2,m,n)<=k)
if __name__=='__main__' :
    str1="geek"
    str2="gks"
    k=3
    if areKDistant(str1,str2,k):
        print("Yes")
    else :
        print("No")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      str1 := "geek" ;
    str2 := "gks" ;
    k := 3 ;
    if areKDistant(str1, str2, k) then  (
      execute ("Yes")->display()
    )
    else (
      execute ("No")->display()
      )
    ) else skip;
  operation minn(x : OclAny, y : OclAny, z : OclAny) : OclAny
  pre: true post: true
  activity:
    return Set{Set{x, y}->min(), z}->min();
  operation editDistDP(str1 : OclAny, str2 : OclAny, m : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var dp : Sequence := Integer.subrange(0, m + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)))) ;
    for i : Integer.subrange(0, m + 1-1) do (    for j : Integer.subrange(0, n + 1-1) do (    if (i = 0) then  (
      dp[i+1][j+1] := j
    )
    else (if (j = 0) then
   (
      dp[i+1][j+1] := i    
)
    else (if (str1[i - 1+1] = str2[j - 1+1]) then
   (
      dp[i+1][j+1] := dp[i - 1+1][j - 1+1]    
)
    else (
      dp[i+1][j+1] := 1 + minn(dp[i+1][j - 1+1], dp[i - 1+1][j+1], dp[i - 1+1][j - 1+1])
      )    )
    )
)) ;
    return dp[m+1][n+1];
  operation areKDistant(str1 : OclAny, str2 : OclAny, k : OclAny) : OclAny
  pre: true post: true
  activity:
    m := (str1)->size() ;
    n := (str2)->size() ;
    if (((m - n)->abs()->compareTo(k)) > 0) then (
      return false
    ) else skip ;
    return ((editDistDP(str1, str2, m, n)->compareTo(k)) <= 0);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def markingScheme(N,answerKey,studentAnswer):
    positive=0
    negative=0
    notattempt=0
    for i in range(0,N):
        if(studentAnswer[i]==0):
            notattempt+=1
        elif(answerKey[i]==studentAnswer[i]):
            positive+=1
        elif(answerKey[i]!=studentAnswer[i]):
            negative+=1
    return(positive*3)+(negative*-1)
def main():
    answerKey=[1,2,3,4,1]
    studentAnswer=[1,2,3,4,0]
    N=5
    print(markingScheme(N,answerKey,studentAnswer))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip;
  operation markingScheme(N : OclAny, answerKey : OclAny, studentAnswer : OclAny) : OclAny
  pre: true post: true
  activity:
    var positive : int := 0 ;
    var negative : int := 0 ;
    var notattempt : int := 0 ;
    for i : Integer.subrange(0, N-1) do (    if (studentAnswer[i+1] = 0) then  (
      notattempt := notattempt + 1
    )
    else (if (answerKey[i+1] = studentAnswer[i+1]) then
   (
      positive := positive + 1    
)
    else (if (answerKey[i+1] /= studentAnswer[i+1]) then
   (
      negative := negative + 1    
)
    else skip    )
    )
) ;
    return (positive * 3) + (negative * -1);
  operation main()
  pre: true post: true
  activity:
    answerKey := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 1 })))) ;
    studentAnswer := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 0 })))) ;
    N := 5 ;
    execute (markingScheme(N, answerKey, studentAnswer))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
class Solution(object):
    def backspaceCompare(self,S,T):
        if S==T :
            return True
        s_stack=[]
        t_stack=[]
        for c in S :
            if c!='#' :
                s_stack.append(c)
            elif len(s_stack)!=0 :
                s_stack.pop(-1)
        for c in T :
            if c!='#' :
                t_stack.append(c)
            elif len(t_stack)!=0 :
                t_stack.pop(-1)
        return ''.join(s_stack)==''.join(t_stack)
------------------------------------------------------------
OCL File:
---------
class Solution extends object {
  static operation newSolution() : Solution
  pre: true
  post: Solution->exists( _x | result = _x );
  operation backspaceCompare(S : OclAny,T : OclAny) : OclAny
  pre: true post: true
  activity:
    if S = T then (
      return true
    ) else skip ;
    var s_stack : Sequence := Sequence{} ;
    var t_stack : Sequence := Sequence{} ;
    for c : S do (    if c /= '#' then  (
      execute ((c) : s_stack)
    )
    else (if (s_stack)->size() /= 0 then
   (
      s_stack := s_stack->excludingAt(-1+1)    
)
 else skip)) ;
    for c : T do (    if c /= '#' then  (
      execute ((c) : t_stack)
    )
    else (if (t_stack)->size() /= 0 then
   (
      t_stack := t_stack->excludingAt(-1+1)    
)
 else skip)) ;
    return StringLib.sumStringsWithSeparator((s_stack), '') = StringLib.sumStringsWithSeparator((t_stack), '');
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input(''))):
    u,v=map(int,input().split())
    print(-1*u**2,v**2)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine(''))))->toInteger()-1) do (    var u : OclAny := null;
    var v : OclAny := null;
    Sequence{u,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (-1 * (u)->pow(2))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
c=int(input())
for i in range(0,c):
    q=input().split(' ')
    u=int(q[0])
    v=int(q[1])
    print(-u*u,v*v)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, c-1) do (    var q : OclAny := input().split(' ') ;
    var u : int := ("" + ((q->first())))->toInteger() ;
    var v : int := ("" + ((q[1+1])))->toInteger() ;
    execute (-u * u)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for _ in range(t):
    u,v=(int(i)for i in input().split())
    x,y=u**2,-v**2
    print(x,y)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, t-1) do (    var u : OclAny := null;
    var v : OclAny := null;
    Sequence{u,v} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ;
    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := Sequence{(u)->pow(2),-(v)->pow(2)} ;
    execute (x)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    u,v=map(int,input().split())
    print(-u**2,v**2)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var u : OclAny := null;
    var v : OclAny := null;
    Sequence{u,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (-(u)->pow(2))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input(''))):
    u,v=map(int,input().split())
    print(u**2,-1*v**2)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine(''))))->toInteger()-1) do (    var u : OclAny := null;
    var v : OclAny := null;
    Sequence{u,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute ((u)->pow(2))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import deque
from math import*
import sys
import random
from bisect import*
from functools import reduce
from sys import stdin
import copy
for _ in range(int(input())):
    n=int(input())
    s=input()
    ans=0
    left,right=0,0
    i=0
    while i=0 and s[j]!='<' :
        j-=1
    print(min(i,n-j-1))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : String := (OclFile["System.in"]).readLine() ;
    var ans : int := 0 ;
    var left : OclAny := null;
    var right : OclAny := null;
    Sequence{left,right} := Sequence{0,0} ;
    var i : int := 0 ;
    while (i->compareTo(n)) < 0 & s[i+1] /= '>' do (    i := i + 1) ;
    var j : double := n - 1 ;
    while j >= 0 & s[j+1] /= '<' do (    j := j - 1) ;
    execute (Set{i, n - j - 1}->min())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
MAX=64
def getBitmask(s):
    temp=0
    for j in range(len(s)):
        if(s[j]=='s'):
            temp=temp | 1
        elif(s[j]=='t'):
            temp=temp | 2
        elif(s[j]=='r'):
            temp=temp | 4
        elif(s[j]=='i'):
            temp=temp | 8
        elif(s[j]=='n'):
            temp=temp | 16
        elif(s[j]=='g'):
            temp=temp | 32
    return temp
def countPairs(arr,n):
    bitMask=[0 for i in range(MAX)]
    for i in range(n):
        bitMask[getBitmask(arr[i])]+=1
    cnt=0
    for i in range(MAX):
        for j in range(i,MAX):
            if((i | j)==(MAX-1)):
                if(i==j):
                    cnt+=((bitMask[i]*bitMask[i]-1)//2)
                else :
                    cnt+=(bitMask[i]*bitMask[j])
    return cnt
arr=["strrr","strring","gstrin"]
n=len(arr)
print(countPairs(arr,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var MAX : int := 64 ;
    skip ;
    skip ;
    arr := Sequence{"strrr"}->union(Sequence{"strring"}->union(Sequence{ "gstrin" })) ;
    n := (arr)->size() ;
    execute (countPairs(arr, n))->display();
  operation getBitmask(s : OclAny) : OclAny
  pre: true post: true
  activity:
    var temp : int := 0 ;
    for j : Integer.subrange(0, (s)->size()-1) do (    if (s[j+1] = 's') then  (
      temp := MathLib.bitwiseOr(temp, 1)
    )
    else (if (s[j+1] = 't') then
   (
      temp := MathLib.bitwiseOr(temp, 2)    
)
    else (if (s[j+1] = 'r') then
   (
      temp := MathLib.bitwiseOr(temp, 4)    
)
    else (if (s[j+1] = 'i') then
   (
      temp := MathLib.bitwiseOr(temp, 8)    
)
    else (if (s[j+1] = 'n') then
   (
      temp := MathLib.bitwiseOr(temp, 16)    
)
    else (if (s[j+1] = 'g') then
   (
      temp := MathLib.bitwiseOr(temp, 32)    
)
    else skip    )
    )
    )
    )
    )
) ;
    return temp;
  operation countPairs(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var bitMask : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)) ;
    for i : Integer.subrange(0, n-1) do (    bitMask[getBitmask(arr[i+1])+1] := bitMask[getBitmask(arr[i+1])+1] + 1) ;
    var cnt : int := 0 ;
    for i : Integer.subrange(0, MAX-1) do (    for j : Integer.subrange(i, MAX-1) do (    if ((MathLib.bitwiseOr(i, j)) = (MAX - 1)) then (
      if (i = j) then  (
      cnt := cnt + ((bitMask[i+1] * bitMask[i+1] - 1) div 2)
    )
    else (
      cnt := cnt + (bitMask[i+1] * bitMask[j+1])
      )
    ) else skip)) ;
    return cnt;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for t in range(int(input())):
    n=int(input())
    lst=[int(i)for i in input().split()]
    inc=0
    dec=0
    f=0
    for i in range(1,n):
        if(lst[i]>lst[i-1]):
            if(dec==0):
                inc=1
            else :
                f=1
                break
        elif(lst[i]toInteger()-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var lst : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var inc : int := 0 ;
    var dec : int := 0 ;
    var f : int := 0 ;
    for i : Integer.subrange(1, n-1) do (    if ((lst[i+1]->compareTo(lst[i - 1+1])) > 0) then  (
      if (dec = 0) then  (
      inc := 1
    )
    else (
      f := 1 ;
    break
      )
    )
    else (if ((lst[i+1]->compareTo(lst[i - 1+1])) < 0) then
   (
      dec := 1    
)
 else skip)) ;
    if (f) then  (
      execute ("NO")->display()
    )
    else (
      execute ("YES")->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for _ in range(t):
    n=int(input())
    a=[int(x)for x in input().split(" ")]
    a.insert(0,0)
    if len(a)<=2 :
        print("YES")
    else :
        i=0
        while i=a[i]:
            i+=1
        while itoInteger() ;
    for _anon : Integer.subrange(0, t-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    a := a.insertAt(0+1, 0) ;
    if (a)->size() <= 2 then  (
      execute ("YES")->display()
    )
    else (
      var i : int := 0 ;
    while (i->compareTo((a)->size() - 1)) < 0 & (a[i + 1+1]->compareTo(a[i+1])) >= 0 do (    i := i + 1) ;
    while (i->compareTo((a)->size() - 1)) < 0 & (a[i + 1+1]->compareTo(a[i+1])) <= 0 do (    i := i + 1) ;
    if i = (a)->size() - 1 then  (
      execute ("YES")->display()
    )
    else (
      execute ("NO")->display()
      )
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for i in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    i=0
    while i+1=l[i]:
        i=i+1
    while i+1toInteger()-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var i : int := 0 ;
    while (i + 1->compareTo(n)) < 0 & (l[i + 1+1]->compareTo(l[i+1])) >= 0 do (    i := i + 1) ;
    while (i + 1->compareTo(n)) < 0 & (l[i + 1+1]->compareTo(l[i+1])) <= 0 do (    i := i + 1) ;
    if i + 1 = n then  (
      execute ("YES")->display()
    )
    else (
      execute ("NO")->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for j in range(0,t):
    n=int(input())
    array=map(int,input().split())
    array=list(array)
    a=0
    i=0
    while(i=array[i]):
            a=array[i]
            i+=1
        else :
            break
    if(i==n):
        print("YES")
    else :
        print("NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for j : Integer.subrange(0, t-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var array : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    array := (array) ;
    var a : int := 0 ;
    var i : int := 0 ;
    while ((i->compareTo(n)) < 0) do (    if ((a->compareTo(array[i+1])) <= 0) then  (
      a := array[i+1] ;
    i := i + 1
    )
    else (
      break
      )) ;
    while ((i->compareTo(n)) < 0) do (    if ((a->compareTo(array[i+1])) >= 0) then  (
      a := array[i+1] ;
    i := i + 1
    )
    else (
      break
      )) ;
    if (i = n) then  (
      execute ("YES")->display()
    )
    else (
      execute ("NO")->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
x1,y1,r1=map(int,input().split())
x2,y2,r2=map(int,input().split())
d=((x1-x2)**2+(y1-y2)**2)**0.5
if d>=r1+r2 :
    print((d-r1-r2)/2)
else :
    print(max(0,(max(r1,r2)-d-min(r1,r2)))/2)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var x1 : OclAny := null;
    var y1 : OclAny := null;
    var r1 : OclAny := null;
    Sequence{x1,y1,r1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var x2 : OclAny := null;
    var y2 : OclAny := null;
    var r2 : OclAny := null;
    Sequence{x2,y2,r2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var d : double := ((((x1 - x2))->pow(2) + ((y1 - y2))->pow(2)))->pow(0.5) ;
    if (d->compareTo(r1 + r2)) >= 0 then  (
      execute ((d - r1 - r2) / 2)->display()
    )
    else (
      execute (Set{0, (Set{r1, r2}->max() - d - Set{r1, r2}->min())}->max() / 2)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import heapq
import sys,os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n,m=map(int,input().split())
G=[set()for _ in range(n+1)]
for _ in range(m):
    a,b=map(int,input().split())
    G[a].add(b)
    G[b].add(a)
h=[]
for i in range(1,n+1):
    heapq.heappush(h,(len(G[i]),i))
s=set([i for i in range(1,n+1)])
st=[]
ans=-1
while h :
    if not st :
        while h :
            _,i=heapq.heappop(h)
            if i in s :
                s.remove(i)
                st.append(i)
                break
    if not st :
        break
    ans+=1
    while st :
        i=st.pop()
        r=[]
        for j in s :
            if not j in G[i]:
                st.append(j)
                r.append(j)
        for j in r :
            s.remove(j)
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var input : OclAny := io.BytesIO(os.readAll()).readline ;
    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var G : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ;
    for _anon : Integer.subrange(0, m-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
(expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ;
(expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ;
    var h : Sequence := Sequence{} ;
    for i : Integer.subrange(1, n + 1-1) do (    heapq.heappush(h, Sequence{(G[i+1])->size(), i})) ;
    var s : Set := Set{}->union((Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | (i)))) ;
    var st : Sequence := Sequence{} ;
    var ans : int := -1 ;
    while h do (    if not(st) then (
      while h do (    var _anon : OclAny := null;
    var i : OclAny := null;
    Sequence{_anon,i} := heapq.heappop(h) ;
    if (s)->includes(i) then (
      execute ((i) /: s) ;
    execute ((i) : st) ;
    break
    ) else skip)
    ) else skip ;
    if not(st) then (
      break
    ) else skip ;
    ans := ans + 1 ;
    while st do (    var i : OclAny := st->last() ;     st := st->front() ;
    var r : Sequence := Sequence{} ;
    for j : s do (    if not((G[i+1])->includes(j)) then (
      execute ((j) : st) ;
    execute ((j) : r)
    ) else skip) ;
    for j : r do (    execute ((j) /: s)))) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    n=int(input())
    a=[int(i)for i in input().split()]
    ans="YES"
    c=False
    for i in range(1,n):
        if a[i-1]>a[i]: c=True
        elif a[i-1]toInteger()-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var ans : String := "YES" ;
    var c : boolean := false ;
    for i : Integer.subrange(1, n-1) do (    if (a[i - 1+1]->compareTo(a[i+1])) > 0 then  (
      c := true
    )
    else (if (a[i - 1+1]->compareTo(a[i+1])) < 0 & c then
   (
      ans := "NO";    break    
)
 else skip)) ;
    execute (ans)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m,k=map(int,input().split())
a=[int(input())for _ in range(m+1)]
print(sum(bin(a[-1]^ x).count("1")<=k for x in a[:-1]))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    var k : OclAny := null;
    Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : Sequence := Integer.subrange(0, m + 1-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ;
    execute (((argument (test (logical_test (comparison (comparison (expr (atom (name bin)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))) ^ (expr (atom (name x))))))))) ))) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "1"))))))) ))))) <= (comparison (expr (atom (name k))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))))))))->sum())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m,k=map(int,input().split())
x=[int(input())for t in range(m+1)]
print(sum(bin(x[m]^ y).count('1')<=k for y in x)-1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    var k : OclAny := null;
    Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var x : Sequence := Integer.subrange(0, m + 1-1)->select(t | true)->collect(t | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ;
    execute (((argument (test (logical_test (comparison (comparison (expr (atom (name bin)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name m)))))))) ]))) ^ (expr (atom (name y))))))))) ))) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '1'))))))) ))))) <= (comparison (expr (atom (name k))))))) (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name x))))))))->sum() - 1)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
rep=int(input())
for i in range(rep):
    a=int(input())
    string=input()
    count=0
    if(string[0]=="<" and string[-1]==">"):
        for i in range(len(string)):
            if(string[i]=="<" and string[len(string)-1-i]=='>'):
                count+=1
            else :
                break
    print(count)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var rep : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, rep-1) do (    var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var string : String := (OclFile["System.in"]).readLine() ;
    var count : int := 0 ;
    if (string->first() = "<" & string->last() = ">") then (
      for i : Integer.subrange(0, (string)->size()-1) do (    if (string[i+1] = "<" & string[(string)->size() - 1 - i+1] = '>') then  (
      count := count + 1
    )
    else (
      break
      ))
    ) else skip ;
    execute (count)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m,k=map(int,input().split())
l=[]
for r in range(m):
    l.append(int(input()))
s=int(input())
ans=0
for i in l :
    c=bin(i ^ s).count('1')
    if(c<=k):
        ans+=1
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    var k : OclAny := null;
    Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var l : Sequence := Sequence{} ;
    for r : Integer.subrange(0, m-1) do (    execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : l)) ;
    var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var ans : int := 0 ;
    for i : l do (    var c : OclAny := bin(MathLib.bitwiseXor(i, s))->count('1') ;
    if ((c->compareTo(k)) <= 0) then (
      ans := ans + 1
    ) else skip) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m,k=tuple(map(int,input().split()))
lst=list()
for i in range(m+1):
    lst.append(int(input()))
ans=0
for i in range(m):
    cnt=0
    for j in range(n):
        if(((lst[i]>>j)& 1)!=((lst[m]>>j)& 1)):
            cnt+=1
    if cnt<=k :
        ans+=1
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    var k : OclAny := null;
    Sequence{n,m,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var lst : Sequence := () ;
    for i : Integer.subrange(0, m + 1-1) do (    execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : lst)) ;
    var ans : int := 0 ;
    for i : Integer.subrange(0, m-1) do (    var cnt : int := 0 ;
    for j : Integer.subrange(0, n-1) do (    if ((MathLib.bitwiseAnd((lst[i+1] /(2->pow(j))), 1)) /= (MathLib.bitwiseAnd((lst[m+1] /(2->pow(j))), 1))) then (
      cnt := cnt + 1
    ) else skip) ;
    if (cnt->compareTo(k)) <= 0 then (
      ans := ans + 1
    ) else skip) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def countSubstring(S,L,n):
    freq=[0 for i in range(26)]
    for i in range(n):
        freq[(ord(L[i])-ord('a'))]=1
    count,ans=0,0
    for x in S :
        if(freq[ord(x)-ord('a')]):
            ans+=(count*count+count)//2
            count=0
        else :
            count+=1
    ans+=(count*count+count)//2
    return ans
S="abcpxyz"
L=['a','p','q']
n=len(L)
print(countSubstring(S,L,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    S := "abcpxyz" ;
    L := Sequence{'a'}->union(Sequence{'p'}->union(Sequence{ 'q' })) ;
    n := (L)->size() ;
    execute (countSubstring(S, L, n))->display();
  operation countSubstring(S : OclAny, L : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var freq : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | (0)) ;
    for i : Integer.subrange(0, n-1) do (    freq[((L[i+1])->char2byte() - ('a')->char2byte())+1] := 1) ;
    var count : OclAny := null;
    var ans : OclAny := null;
    Sequence{count,ans} := Sequence{0,0} ;
    for x : S do (    if (freq[(x)->char2byte() - ('a')->char2byte()+1]) then  (
      ans := ans + (count * count + count) div 2 ;
    var count : int := 0
    )
    else (
      count := count + 1
      )) ;
    ans := ans + (count * count + count) div 2 ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
rubles=int(input())
gp1=list(map(int,input().split('')))
gp2=list(map(int,input().split('')))
gp3=list(map(int,input().split('')))
gp4=list(map(int,input().split('')))
anser1=''
anser2=''
anser3=''
anser4=''
if min(gp1[0 : 2])+min(gp1[2 : 5])<=rubles :
    anser1='1{}{}'.format(min(gp1[0 : 2]),rubles-min(gp1[0 : 2]))
    print(anser1)
elif min(gp2[0 : 2])+min(gp2[2 : 5])<=rubles :
    anser2='2{}{}'.format(min(gp2[0 : 2]),rubles-min(gp2[0 : 2]))
    print(anser2)
elif min(gp3[0 : 2])+min(gp3[2 : 5])<=rubles :
    anser3='3{}{}'.format(min(gp3[0 : 2]),rubles-min(gp3[0 : 2]))
    print(anser3)
elif min(gp4[0 : 2])+min(gp4[2 : 5])<=rubles :
    anser4='4{}{}'.format(min(gp4[0 : 2]),rubles-min(gp4[0 : 2]))
    print(anser4)
else :
    print('-1')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var rubles : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var gp1 : Sequence := ((input().split(''))->collect( _x | (OclType["int"])->apply(_x) )) ;
    var gp2 : Sequence := ((input().split(''))->collect( _x | (OclType["int"])->apply(_x) )) ;
    var gp3 : Sequence := ((input().split(''))->collect( _x | (OclType["int"])->apply(_x) )) ;
    var gp4 : Sequence := ((input().split(''))->collect( _x | (OclType["int"])->apply(_x) )) ;
    var anser1 : String := '' ;
    var anser2 : String := '' ;
    var anser3 : String := '' ;
    var anser4 : String := '' ;
    if ((gp1.subrange(0+1, 2))->min() + (gp1.subrange(2+1, 5))->min()->compareTo(rubles)) <= 0 then  (
      anser1 := StringLib.interpolateStrings('1{}{}', Sequence{(gp1.subrange(0+1, 2))->min(), rubles - (gp1.subrange(0+1, 2))->min()}) ;
    execute (anser1)->display()
    )
    else (if ((gp2.subrange(0+1, 2))->min() + (gp2.subrange(2+1, 5))->min()->compareTo(rubles)) <= 0 then
   (
      anser2 := StringLib.interpolateStrings('2{}{}', Sequence{(gp2.subrange(0+1, 2))->min(), rubles - (gp2.subrange(0+1, 2))->min()}) ;
    execute (anser2)->display()    
)
    else (if ((gp3.subrange(0+1, 2))->min() + (gp3.subrange(2+1, 5))->min()->compareTo(rubles)) <= 0 then
   (
      anser3 := StringLib.interpolateStrings('3{}{}', Sequence{(gp3.subrange(0+1, 2))->min(), rubles - (gp3.subrange(0+1, 2))->min()}) ;
    execute (anser3)->display()    
)
    else (if ((gp4.subrange(0+1, 2))->min() + (gp4.subrange(2+1, 5))->min()->compareTo(rubles)) <= 0 then
   (
      anser4 := StringLib.interpolateStrings('4{}{}', Sequence{(gp4.subrange(0+1, 2))->min(), rubles - (gp4.subrange(0+1, 2))->min()}) ;
    execute (anser4)->display()    
)
    else (
      execute ('-1')->display()
      )    )
    )
    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
import string
def main_function():
    n=int(input())
    data=[[int(i)for i in input().split(" ")]for j in range(4)]
    is_answer_found=False
    for i in range(len(data)):
        for j in range(0,2):
            for k in range(2,4):
                if data[i][j]+data[i][k]<=n :
                    is_answer_found=True
                    print(i+1,data[i][j],n-data[i][j])
                    break
            if is_answer_found :
                break
        if is_answer_found :
            break
    if not is_answer_found :
        print(-1)
main_function()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    main_function();
  operation main_function()
  pre: true post: true
  activity:
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var data : Sequence := Integer.subrange(0, 4-1)->select(j | true)->collect(j | (input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())))) ;
    var is_answer_found : boolean := false ;
    for i : Integer.subrange(0, (data)->size()-1) do (    for j : Integer.subrange(0, 2-1) do (    for k : Integer.subrange(2, 4-1) do (    if (data[i+1][j+1] + data[i+1][k+1]->compareTo(n)) <= 0 then (
      is_answer_found := true ;
    execute (i + 1)->display() ;
    break
    ) else skip) ;
    if is_answer_found then (
      break
    ) else skip) ;
    if is_answer_found then (
      break
    ) else skip) ;
    if not(is_answer_found) then (
      execute (-1)->display()
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a=[]
for _ in range(4):
    l=list(map(int,input().strip().split()))
    a.append(l)
f=ans=x=y=0
for i in range(4):
    g=n-min(a[i][0],a[i][1])
    if g>=min(a[i][2],a[i][3]):
        f=1
        ans=i+1
        break
if f==0 : print(-1)
else :
    print(ans,n-g,g)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := Sequence{} ;
    for _anon : Integer.subrange(0, 4-1) do (    var l : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute ((l) : a)) ;
    f := f(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name y)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ;
    for i : Integer.subrange(0, 4-1) do (    var g : double := n - Set{a[i+1]->first(), a[i+1][1+1]}->min() ;
    if (g->compareTo(Set{a[i+1][2+1], a[i+1][3+1]}->min())) >= 0 then (
      var f : int := 1 ;
    var ans : OclAny := i + 1 ;
    break
    ) else skip) ;
    if f = 0 then  (
      execute (-1)->display()
    )
    else (
      execute (ans)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
l=[]
for _ in range(4):
    l.append(list(map(int,input().split())))
x=min(l,key=lambda x :(min(x[0],x[1])+min(x[2],x[3])))
i=l.index(x)
if min(l[i][0],l[i][1])+min(l[i][2],l[i][3])<=n :
    print(i+1,min(l[i][0],l[i][1]),n-min(l[i][0],l[i][1]))
else :
    print(-1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var l : Sequence := Sequence{} ;
    for _anon : Integer.subrange(0, 4-1) do (    execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : l)) ;
    var x : OclAny := Set{l, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))) + (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 3))))))))) ])))))))) ))))))))) ))))))))}->min() ;
    var i : int := l->indexOf(x) - 1 ;
    if (Set{l[i+1]->first(), l[i+1][1+1]}->min() + Set{l[i+1][2+1], l[i+1][3+1]}->min()->compareTo(n)) <= 0 then  (
      execute (i + 1)->display()
    )
    else (
      execute (-1)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import stdin
input=stdin.readline
from collections import deque
def answer():
    q=deque([])
    left=set([i for i in range(1,n+1)])
    comp=0
    for i in range(1,n+1):
        if(i in left):
            q.append(i)
            left.remove(i)
            comp+=1
        else : continue
        while(len(q)):
            p=q.popleft()
            this=[]
            for x in left :
                if(x not in adj[p]):
                    q.append(x)
                    this.append(x)
            for x in this :
                left.remove(x)
    return comp-1
for T in range(1):
    n,m=map(int,input().split())
    adj=[set()for i in range(n+1)]
    for i in range(m):
        u,v=map(int,input().split())
        adj[u].add(v)
        adj[v].add(u)
    print(answer())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := stdin.readline ;
    skip ;
    skip ;
    for T : Integer.subrange(0, 1-1) do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var adj : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Set{}->union(()))) ;
    for i : Integer.subrange(0, m-1) do (    var u : OclAny := null;
    var v : OclAny := null;
    Sequence{u,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
(expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) ;
(expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)))))))) ))))) ;
    execute (answer())->display());
  operation answer() : OclAny
  pre: true post: true
  activity:
    var q : Sequence := (Sequence{}) ;
    var left : Set := Set{}->union((Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | (i)))) ;
    var comp : int := 0 ;
    for i : Integer.subrange(1, n + 1-1) do (    if ((left)->includes(i)) then  (
      execute ((i) : q) ;
    execute ((i) /: left) ;
    comp := comp + 1
    )
    else (
      continue
      ) ;
    while ((q)->size()) do (    var p : OclAny := q->first() ;     q := q->tail() ;
    var this : Sequence := Sequence{} ;
    for x : left do (    if ((adj[p+1])->excludes(x)) then (
      execute ((x) : q) ;
    execute ((x) : this)
    ) else skip) ;
    for x : this do (    execute ((x) /: left)))) ;
    return comp - 1;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
n=int(input())
for i in range(4):
    a,b,c,d=map(int,input().split())
    if a+c<=n or a+d<=n :
        print(i+1,a,n-a)
        break
    if b+d<=n or b+c<=n :
        print(i+1,b,n-b)
        break
else :
    print(-1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
(compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 4))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name b)))))) , (test (logical_test (comparison (expr (atom (name c)))))) , (test (logical_test (comparison (expr (atom (name d))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (expr (atom (name a))) + (expr (atom (name c))))) <= (comparison (expr (atom (name n)))))) or (logical_test (comparison (comparison (expr (expr (atom (name a))) + (expr (atom (name d))))) <= (comparison (expr (atom (name n)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (name a))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (expr (atom (name b))) + (expr (atom (name d))))) <= (comparison (expr (atom (name n)))))) or (logical_test (comparison (comparison (expr (expr (atom (name b))) + (expr (atom (name c))))) <= (comparison (expr (atom (name n)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name b))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (name b))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def isRevDiffDivisible(x,k):
    n=x ; m=0
    while(x>0):
        m=m*10+x % 10
        x=x//10
    return(abs(n-m)% k==0)
def countNumbers(l,r,k):
    count=0
    for i in range(l,r+1):
        if(isRevDiffDivisible(i,k)):
            count=count+1
    return count
l=20 ; r=23 ; k=6
print(countNumbers(l,r,k))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    l := 20;    r := 23;    k := 6 ;
    execute (countNumbers(l, r, k))->display();
  operation isRevDiffDivisible(x : OclAny, k : OclAny) : OclAny
  pre: true post: true
  activity:
    var n : OclAny := x;    var m : int := 0 ;
    while (x > 0) do (    m := m * 10 + x mod 10 ;
    x := x div 10) ;
    return ((n - m)->abs() mod k = 0);
  operation countNumbers(l : OclAny, r : OclAny, k : OclAny) : OclAny
  pre: true post: true
  activity:
    var count : int := 0 ;
    for i : Integer.subrange(l, r + 1-1) do (    if (isRevDiffDivisible(i, k)) then (
      count := count + 1
    ) else skip) ;
    return count;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for p in[0]*int(input()): n=int(input()); s=input(); print(min(s.find('>')% n,n-1-s.rfind('<')))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for p : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger();    var s : String := (OclFile["System.in"]).readLine();    execute (Set{s->indexOf('>') - 1 mod n, n - 1 - s.rfind('<')}->min())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import eulerlib,itertools
def compute():
    for n in itertools.count(1):
        if(count_divisors_squared(n)+1)//2>1000 :
            return str(n)
def count_divisors_squared(n):
    count=1
    end=eulerlib.sqrt(n)
    for i in itertools.count(2):
        if i>end :
            break
        if n % i==0 :
            j=0
            while True :
                n//=i
                j+=1
                if n % i!=0 :
                    break
            count*=j*2+1
            end=eulerlib.sqrt(n)
    if n!=1 :
        count*=3
    return count
if __name__=="__main__" :
    print(compute())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      execute (compute())->display()
    ) else skip;
  operation compute() : OclAny
  pre: true post: true
  activity:
    for n : itertools->count(1) do (    if (count_divisors_squared(n) + 1) div 2 > 1000 then (
      return ("" + ((n)))
    ) else skip);
  operation count_divisors_squared(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var count : int := 1 ;
    var end : double := eulerlib.sqrt(n) ;
    for i : itertools->count(2) do (    if (i->compareTo(end)) > 0 then (
      break
    ) else skip ;
    if n mod i = 0 then (
      var j : int := 0 ;
    while true do (    n := n div i ;
    j := j + 1 ;
    if n mod i /= 0 then (
      break
    ) else skip) ;
    count := count * j * 2 + 1 ;
    end := eulerlib.sqrt(n)
    ) else skip) ;
    if n /= 1 then (
      count := count * 3
    ) else skip ;
    return count;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def zan(total,flag):
    rest=7200-total if flag else(7200-total)*3
    t,rest=divmod(rest,3600)
    h,s=divmod(rest,60)
    print("{0:02d}:{1:02d}:{2:02d}".format(t,h,s))
while True :
    T,H,S=map(int,input().split())
    if T==-1 :
        break
    total=T*3600+H*60+S
    for i in[1,0]:
        zan(total,i)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    while true do (    var T : OclAny := null;
    var H : OclAny := null;
    var S : OclAny := null;
    Sequence{T,H,S} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if T = -1 then (
      break
    ) else skip ;
    total := T * 3600 + H * 60 + S ;
    for i : Sequence{1}->union(Sequence{ 0 }) do (    zan(total, i)));
  operation zan(total : OclAny, flag : OclAny)
  pre: true post: true
  activity:
    var rest : double := if flag then 7200 - total else (7200 - total) * 3 endif ;
    var t : OclAny := null;
    Sequence{t,rest} := Sequence{(rest div 3600), (rest mod 3600)} ;
    var h : OclAny := null;
    var s : OclAny := null;
    Sequence{h,s} := Sequence{(rest div 60), (rest mod 60)} ;
    execute (StringLib.interpolateStrings("{0:02d}:{1:02d}:{2:02d}", Sequence{t, h, s}))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
readline=sys.stdin.readline
write=sys.stdout.write
def solve():
    T,H,S=map(int,readline().split())
    if T==-1 :
        return False
    rest=7200-(T*3600+H*60+S)
    write("%02d:%02d:%02d\n" %(rest//3600,(rest//60)% 60,rest % 60))
    rest*=3
    write("%02d:%02d:%02d\n" %(rest//3600,(rest//60)% 60,rest % 60))
    return True
while solve():
   ...
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var readline : OclAny := (OclFile["System.in"]).readline ;
    var write : OclAny := (OclFile["System.out"]).write ;
    skip ;
    while solve() do ();
  operation solve() : OclAny
  pre: true post: true
  activity:
    var T : OclAny := null;
    var H : OclAny := null;
    var S : OclAny := null;
    Sequence{T,H,S} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if T = -1 then (
      return false
    ) else skip ;
    var rest : double := 7200 - (T * 3600 + H * 60 + S) ;
    write(StringLib.format("%02d:%02d:%02d\n",Sequence{rest div 3600, (rest div 60) mod 60, rest mod 60})) ;
    rest := rest * 3 ;
    write(StringLib.format("%02d:%02d:%02d\n",Sequence{rest div 3600, (rest div 60) mod 60, rest mod 60})) ;
    return true;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def encode(a):
    hour=0
    minu=0
    sec=0
    if a>=3600 :
        hour=int(a/3600)
        a=a % 3600
    if a>=60 :
        minu=int(a/60)
        a=a % 60
    sec=a
    return hour,minu,sec
def decode(hour,minu,sec):
    return 3600*hour+60*minu+sec
while(1):
    t,h,s=[int(i)for i in input().split()]
    if t==-1 and h==-1 and s==-1 :
        break
    secs=decode(t,h,s)
    left_secs=120*60-secs
    hour,minu,sec=encode(left_secs)
    hour_,minu_,sec_=encode(3*left_secs)
    print("{:0>2}:{:0>2}:{:0>2}".format(hour,minu,sec))
    print("{:0>2}:{:0>2}:{:0>2}".format(hour_,minu_,sec_))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    while (1) do (    var t : OclAny := null;
    var h : OclAny := null;
    var s : OclAny := null;
    Sequence{t,h,s} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    if t = -1 & h = -1 & s = -1 then (
      break
    ) else skip ;
    var secs : OclAny := decode(t, h, s) ;
    var left_secs : double := 120 * 60 - secs ;
    Sequence{hour,minu,sec} := encode(left_secs) ;
    var hour_ : OclAny := null;
    var minu_ : OclAny := null;
    var sec_ : OclAny := null;
    Sequence{hour_,minu_,sec_} := encode(3 * left_secs) ;
    execute (StringLib.interpolateStrings("{:0>2}:{:0>2}:{:0>2}", Sequence{hour, minu, sec}))->display() ;
    execute (StringLib.interpolateStrings("{:0>2}:{:0>2}:{:0>2}", Sequence{hour_, minu_, sec_}))->display());
  operation encode(a : OclAny) : OclAny
  pre: true post: true
  activity:
    var hour : int := 0 ;
    var minu : int := 0 ;
    var sec : int := 0 ;
    if a >= 3600 then (
      hour := ("" + ((a / 3600)))->toInteger() ;
    a := a mod 3600
    ) else skip ;
    if a >= 60 then (
      minu := ("" + ((a / 60)))->toInteger() ;
    a := a mod 60
    ) else skip ;
    sec := a ;
    return hour, minu, sec;
  operation decode(hour : OclAny, minu : OclAny, sec : OclAny) : OclAny
  pre: true post: true
  activity:
    return 3600 * hour + 60 * minu + sec;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
default=120*60
while 1 :
    t,h,s=map(int,input().split())
    if t==-1 and h==-1 and s==-1 :
        break
    time=t*3600+h*60+s
    diff=default-time
    diff3=diff*3
    diff_t=str(diff//3600).zfill(2)
    diff_h=str(diff % 3600//60).zfill(2)
    diff_s=str(diff % 60).zfill(2)
    diff_3t=str(diff3//3600).zfill(2)
    diff_3h=str(diff3 % 3600//60).zfill(2)
    diff_3s=str(diff3 % 60).zfill(2)
    print(diff_t+":"+diff_h+":"+diff_s)
    print(diff_3t+":"+diff_3h+":"+diff_3s)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var default : int := 120 * 60 ;
    while 1 do (    var t : OclAny := null;
    var h : OclAny := null;
    var s : OclAny := null;
    Sequence{t,h,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if t = -1 & h = -1 & s = -1 then (
      break
    ) else skip ;
    var time : double := t * 3600 + h * 60 + s ;
    var diff : double := default - time ;
    var diff3 : double := diff * 3 ;
    var diff_t : OclAny := OclType["String"](diff div 3600).zfill(2) ;
    var diff_h : OclAny := OclType["String"](diff mod 3600 div 60).zfill(2) ;
    var diff_s : OclAny := OclType["String"](diff mod 60).zfill(2) ;
    var diff_3t : OclAny := OclType["String"](diff3 div 3600).zfill(2) ;
    var diff_3h : OclAny := OclType["String"](diff3 mod 3600 div 60).zfill(2) ;
    var diff_3s : OclAny := OclType["String"](diff3 mod 60).zfill(2) ;
    execute (diff_t + ":" + diff_h + ":" + diff_s)->display() ;
    execute (diff_3t + ":" + diff_3h + ":" + diff_3s)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import datetime
while True :
    T,H,S=map(int,input().split())
    if T==-1 and H==-1 and S==-1 :
        break
    s0=2*60**2
    s=T*60**2+H*60*1+S
    s1=s0-s
    s3=3*s1
    T1=s1//60**2
    H1=(s1-T1*60**2)//60
    S1=s1-T1*60**2-H1*60*1
    if H1<10 and S1<10 :
        print("0%d:0%d:0%d" %(T1,H1,S1))
    elif H1<10 and S1>=10 :
        print("0%d:0%d:%d" %(T1,H1,S1))
    elif S1<10 :
        print("0%d:%d:0%d" %(T1,H1,S1))
    else :
        print("0%d:%d:%d" %(T1,H1,S1))
    T3=s3//60**2
    H3=(s3-T3*60**2)//60
    S3=s3-T3*60**2-H3*60*1
    if H3<10 and S3<10 :
        print("0%d:0%d:0%d" %(T3,H3,S3))
    elif H3<10 and S3>=10 :
        print("0%d:0%d:%d" %(T3,H3,S3))
    elif S3<10 :
        print("0%d:%d:0%d" %(T3,H3,S3))
    else :
        print("0%d:%d:%d" %(T3,H3,S3))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    while true do (    var T : OclAny := null;
    var H : OclAny := null;
    var S : OclAny := null;
    Sequence{T,H,S} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if T = -1 & H = -1 & S = -1 then (
      break
    ) else skip ;
    var s0 : double := 2 * (60)->pow(2) ;
    var s : double := T * (60)->pow(2) + H * 60 * 1 + S ;
    var s1 : double := s0 - s ;
    var s3 : double := 3 * s1 ;
    var T1 : int := s1 div (60)->pow(2) ;
    var H1 : int := (s1 - T1 * (60)->pow(2)) div 60 ;
    var S1 : double := s1 - T1 * (60)->pow(2) - H1 * 60 * 1 ;
    if H1 < 10 & S1 < 10 then  (
      execute (StringLib.format("0%d:0%d:0%d",Sequence{T1, H1, S1}))->display()
    )
    else (if H1 < 10 & S1 >= 10 then
   (
      execute (StringLib.format("0%d:0%d:%d",Sequence{T1, H1, S1}))->display()    
)
    else (if S1 < 10 then
   (
      execute (StringLib.format("0%d:%d:0%d",Sequence{T1, H1, S1}))->display()    
)
    else (
      execute (StringLib.format("0%d:%d:%d",Sequence{T1, H1, S1}))->display()
      )    )
    )
 ;
    var T3 : int := s3 div (60)->pow(2) ;
    var H3 : int := (s3 - T3 * (60)->pow(2)) div 60 ;
    var S3 : double := s3 - T3 * (60)->pow(2) - H3 * 60 * 1 ;
    if H3 < 10 & S3 < 10 then  (
      execute (StringLib.format("0%d:0%d:0%d",Sequence{T3, H3, S3}))->display()
    )
    else (if H3 < 10 & S3 >= 10 then
   (
      execute (StringLib.format("0%d:0%d:%d",Sequence{T3, H3, S3}))->display()    
)
    else (if S3 < 10 then
   (
      execute (StringLib.format("0%d:%d:0%d",Sequence{T3, H3, S3}))->display()    
)
    else (
      execute (StringLib.format("0%d:%d:%d",Sequence{T3, H3, S3}))->display()
      )    )
    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    n,m=[int(x)for x in raw_input().split()]
    a=[[int(x)-1 for x in raw_input().split()]for i in xrange(n)]
    ans=n
    for _ in xrange(m):
        cnt=[0]*m
        for ai in a :
            cnt[ai[0]]+=1
        c=max(xrange(m),key=lambda k : cnt[k])
        ans=min(ans,cnt[c])
        for ai in a :
            ai.remove(c)
    return ans
if __name__=='__main__' :
    print(main())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      execute (main())->display()
    ) else skip;
  operation main() : OclAny
  pre: true post: true
  activity:
    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := raw_input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    var a : Sequence := xrange(n)->select(i | true)->collect(i | (raw_input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)))) ;
    var ans : OclAny := n ;
    for _anon : xrange(m) do (    var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ;
    for ai : a do (    cnt[ai->first()+1] := cnt[ai->first()+1] + 1) ;
    var c : OclAny := Set{xrange(m), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name k)))) : (test (logical_test (comparison (expr (atom (name cnt)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ]))))))))}->max() ;
    ans := Set{ans, cnt[c+1]}->min() ;
    for ai : a do (    execute ((c) /: ai))) ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import os
import sys
from collections import Counter
import numpy as np
if os.getenv("LOCAL"):
    sys.stdin=open("_in.txt","r")
sys.setrecursionlimit(2147483647)
INF=float("inf")
IINF=10**18
MOD=10**9+7
N,M=list(map(int,sys.stdin.readline().split()))
A=[list(map(int,sys.stdin.readline().split()))for _ in range(N)]
A=np.array(A,dtype=int)
idx=np.zeros(N,dtype=int)
used=np.zeros(M+1,dtype=bool)
ans=INF
for _ in range(M):
    k,cnt=Counter(A[np.arange(N),idx]).most_common(1)[0]
    ans=min(ans,cnt)
    used[k]=True
    for i in range(N):
        while idx[i]toReal() ;
    var IINF : double := (10)->pow(18) ;
    var MOD : double := (10)->pow(9) + 7 ;
    var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var A : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    A := (A, (argument (test (logical_test (comparison (expr (atom (name dtype)))))) = (test (logical_test (comparison (expr (atom (name int)))))))) ;
    var idx : Sequence := MatrixLib.singleValueMatrix(N, 0.0) ;
    var used : Sequence := MatrixLib.singleValueMatrix(M + 1, 0.0) ;
    var ans : OclAny := INF ;
    for _anon : Integer.subrange(0, M-1) do (    var k : OclAny := null;
    var cnt : OclAny := null;
    Sequence{k,cnt} := Counter(A->restrict(MathLib.numericRange(0, (N), 1))->restrict(idx)).most_common(1)->first() ;
    ans := Set{ans, cnt}->min() ;
    used[k+1] := true ;
    for i : Integer.subrange(0, N-1) do (    while (idx[i+1]->compareTo(M)) < 0 & used[A[i+1][idx[i+1]+1]+1] do (    idx[i+1] := idx[i+1] + 1))) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
ii=lambda : int(input())
iil=lambda :[int(x)for x in input().split()]
n,m=iil()
edges=[set()for _ in range(n+1)]
for _ in range(m):
    u,v=iil()
    edges[u].add(v)
    edges[v].add(u)
count=0
not_visited=set(range(1,n+1))
for s in range(1,n+1):
    if s not in not_visited :
        continue
    q={s}
    while q and not_visited :
        new_q=set()
        for u in q :
            new_qq=set()
            for v in not_visited :
                if v not in edges[u]:
                    new_qq.add(v)
            not_visited-=new_qq
            new_q |=new_qq
        q=new_q
    count+=1
print(count-1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    var ii : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ;
    var iil : Function := lambda $$ : OclAny in (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) ;
    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := iil->apply() ;
    var edges : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ;
    for _anon : Integer.subrange(0, m-1) do (    var u : OclAny := null;
    var v : OclAny := null;
    Sequence{u,v} := iil->apply() ;
(expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) ;
(expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)))))))) ))))) ;
    var count : int := 0 ;
    var not_visited : Set := Set{}->union((Integer.subrange(1, n + 1-1))) ;
    for s : Integer.subrange(1, n + 1-1) do (    if (not_visited)->excludes(s) then (
      continue
    ) else skip ;
    var q : Set := Set{ s } ;
    while q & not_visited do (    var new_q : Set := Set{}->union(()) ;
    for u : q do (    var new_qq : Set := Set{}->union(()) ;
    for v : not_visited do (    if (edges[u+1])->excludes(v) then (
      execute ((v) : new_qq)
    ) else skip) ;
    not_visited := not_visited - new_qq ;
    new_q := new_q or new_qq) ;
    q := new_q) ;
    count := count + 1) ;
    execute (count - 1)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import deque,defaultdict
N,M=map(int,input().split())
A=[[int(i)-1 for i in input().split()]for _ in range(N)]
def check(X):
    que=[deque()for _ in range(N)]
    ng=[False]*M
    for i in range(N):
        for j in range(M):
            que[i].append(A[i][j])
    while True :
        cnt=defaultdict(int)
        for i in range(N):
            cnt[que[i][0]]+=1
        flag=False
        for s,c in cnt.items():
            if X1 :
        mid=(ng+ok)//2
        if check(mid):
            ok=mid
        else :
            ng=mid
    print(ok)
if __name__=="__main__" :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var A : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger() - 1)))) ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      main()
    ) else skip;
  operation check(X : OclAny) : OclAny
  pre: true post: true
  activity:
    var que : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (())) ;
    var ng : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, M) ;
    for i : Integer.subrange(0, N-1) do (    for j : Integer.subrange(0, M-1) do ((expr (atom (name que)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) )))))) ;
    while true do (    var cnt : OclAny := defaultdict(OclType["int"]) ;
    for i : Integer.subrange(0, N-1) do (    cnt[que[i+1]->first()+1] := cnt[que[i+1]->first()+1] + 1) ;
    var flag : boolean := false ;
    for _tuple : cnt->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1;
      var s : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var c : OclAny := _tuple->at(_indx);
      if (X->compareTo(c)) < 0 then (
      flag := true ;
    ng[s+1] := true
    ) else skip) ;
    if not(flag) then (
      return true
    ) else skip ;
    for i : Integer.subrange(0, N-1) do (    while que[i+1] & ng[que[i+1]->first()+1] do ((expr (atom (name que)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name popleft) (arguments ( ))))) ;
    if not(que[i+1]) then (
      return false
    ) else skip));
  operation main()
  pre: true post: true
  activity:
    var ok : OclAny := null;
    Sequence{ng,ok} := Sequence{0,N} ;
    while ok - ng > 1 do (    var mid : int := (ng->union(ok)) div 2 ;
    if check(mid) then  (
      var ok : int := mid
    )
    else (
      ng := mid
      )) ;
    execute (ok)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for i in range(t):
    n=int(input())
    a=input()
    s=0
    m=0
    if a[0]=='<' and a[-1]=='>' :
        for j in range(n):
            if a[j]=='>' :
                break
            else :
                s+=1
        for l in range(n):
            if a[: :-1][l]=='<' :
                break
            else :
                m+=1
        print(min(s,m))
    else :
        print(0)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, t-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : String := (OclFile["System.in"]).readLine() ;
    var s : int := 0 ;
    var m : int := 0 ;
    if a->first() = '<' & a->last() = '>' then  (
      for j : Integer.subrange(0, n-1) do (    if a[j+1] = '>' then  (
      break
    )
    else (
      s := s + 1
      )) ;
    for l : Integer.subrange(0, n-1) do (    if a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))[l+1] = '<' then  (
      break
    )
    else (
      m := m + 1
      )) ;
    execute (Set{s, m}->min())->display()
    )
    else (
      execute (0)->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
n,m=map(int,input().split())
a=[list(map(int,input().split()))for i in range(n)]
for i in range(n):
    for j in range(m):
        a[i][j]-=1
itr=[0 for i in range(n)]
opend=[True for i in range(m)]
back=[[]for i in range(m)]
for i in range(n):
    back[a[i][0]].append(i)
ret=10**9
while True :
    tmp=0
    for i in range(m):
        tmp=max(tmp,len(back[i]))
    ret=min(ret,tmp)
    for i in range(m):
        if len(back[i])>=ret :
            opend[i]=False
            for j in range(len(back[i])):
                source=back[i][j]
                while not opend[a[source][itr[source]]]:
                    itr[source]+=1
                    if itr[source]==m :
                        print(ret)
                        sys.exit()
                back[a[source][itr[source]]].append(source)
            back[i]=[]
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    for i : Integer.subrange(0, n-1) do (    for j : Integer.subrange(0, m-1) do (    a[i+1][j+1] := a[i+1][j+1] - 1)) ;
    var itr : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ;
    var opend : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (true)) ;
    var back : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (Sequence{})) ;
    for i : Integer.subrange(0, n-1) do ((expr (atom (name back)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ;
    var ret : double := (10)->pow(9) ;
    while true do (    var tmp : int := 0 ;
    for i : Integer.subrange(0, m-1) do (    tmp := Set{tmp, (back[i+1])->size()}->max()) ;
    ret := Set{ret, tmp}->min() ;
    for i : Integer.subrange(0, m-1) do (    if ((back[i+1])->size()->compareTo(ret)) >= 0 then (
      opend[i+1] := false ;
    for j : Integer.subrange(0, (back[i+1])->size()-1) do (    var source : OclAny := back[i+1][j+1] ;
    while not(opend[a[source+1][itr[source+1]+1]+1]) do (    itr[source+1] := itr[source+1] + 1 ;
    if itr[source+1] = m then (
      execute (ret)->display() ;
    sys.exit()
    ) else skip) ;
(expr (atom (name back)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name source)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name itr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name source)))))))) ])))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name source)))))))) ))))) ;
    back[i+1] := Sequence{}
    ) else skip));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
def pop_ind(ind,n):
    for i in range(n):
        A[i].remove(ind)
def count(m):
    counter=[0]*(m+1)
    ind=-1
    max_cnt=0
    for i in range(N):
        counter[A[i][0]]+=1
        if counter[A[i][0]]>max_cnt :
            max_cnt=counter[A[i][0]]
            ind=A[i][0]
    return ind,max_cnt
N,M=map(int,input().split())
A=[list(map(int,input().split()))for _ in range(N)]
ans=float('inf')
for _ in range(M):
    ind,tmp=count(M)
    pop_ind(ind,N)
    ans=min(ans,tmp)
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    skip ;
    skip ;
    var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var A : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var ans : double := ("" + (('inf')))->toReal() ;
    for _anon : Integer.subrange(0, M-1) do (    var tmp : OclAny := null;
    Sequence{ind,tmp} := count(M) ;
    pop_ind(ind, N) ;
    ans := Set{ans, tmp}->min()) ;
    execute (ans)->display();
  operation pop_ind(ind : OclAny, n : OclAny)
  pre: true post: true
  activity:
    for i : Integer.subrange(0, n-1) do ((expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name remove) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ind)))))))) )))));
  operation count(m : OclAny) : OclAny
  pre: true post: true
  activity:
    var counter : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (m + 1)) ;
    ind := -1 ;
    var max_cnt : int := 0 ;
    for i : Integer.subrange(0, N-1) do (    counter[A[i+1]->first()+1] := counter[A[i+1]->first()+1] + 1 ;
    if (counter[A[i+1]->first()+1]->compareTo(max_cnt)) > 0 then (
      max_cnt := counter[A[i+1]->first()+1] ;
    ind := A[i+1]->first()
    ) else skip) ;
    return ind, max_cnt;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def countIterations(arr,n):
    oneFound=False ;
    res=0 ;
    i=0 ;
    while(iunion(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 0 }))))))))))))); ;
    n := (arr)->size(); ;
    execute (countIterations(arr, n))->display();;
  operation countIterations(arr : OclAny, n : OclAny)
  pre: true post: true
  activity:
    var oneFound : boolean := false; ;
    var res : int := 0; ;
    var i : int := 0; ;
    while ((i->compareTo(n)) < 0) do (    if (arr[i+1] = 1) then (
      oneFound := true;
    ) else skip ;
    while ((i->compareTo(n)) < 0 & arr[i+1] = 1) do (    i := i + 1;) ;
    var count_zero : int := 0; ;
    while ((i->compareTo(n)) < 0 & arr[i+1] = 0) do (    count_zero := count_zero + 1; ;
    i := i + 1;) ;
    if (oneFound = false & i = n) then (
      return -1;
    ) else skip ;
    var curr_count : int := 0; ;
    if ((i->compareTo(n)) < 0 & oneFound = true) then  (
      if ((MathLib.bitwiseAnd(count_zero, 1)) = 0) then  (
      curr_count := count_zero div 2;
    )
    else (
      curr_count := (count_zero + 1) div 2;
      ) ;
    count_zero := 0;
    )
    else (
      curr_count := count_zero; ;
    count_zero := 0;
      ) ;
    res := Set{res, curr_count}->max();) ;
    return res;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=map(int,input().split())
i=0
while True :
    i+=a//b
    a=a % b
    if acollect( _x | (OclType["int"])->apply(_x) ) ;
    var i : int := 0 ;
    while true do (    i := i + a div b ;
    var a : int := a mod b ;
    if (a->compareTo(b)) < 0 then (
      var t : int := a ;
    a := b ;
    var b : int := t
    ) else skip ;
    if (a = 0 or b = 0) then (
      break
    ) else skip) ;
    execute (i)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=[int(k)for k in input().split()]
res=0
while b!=0 :
    res+=a//b
    a,b=b,a % b
print(res)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger())) ;
    var res : int := 0 ;
    while b /= 0 do (    res := res + a div b ;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := Sequence{b,a mod b}) ;
    execute (res)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=map(int,input().split()); k=0
while b : k+=a//b ; a,b=b,a % b
print(k)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) );    var k : int := 0 ;
    while b do (    k := k + a div b;    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := Sequence{b,a mod b}) ;
    execute (k)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    a,b=map(int,input().split())
    result=0
    while a!=b :
        if a>=b :
            result+=a//b
            a=a % b
        else :
            result+=b//a
            b=b % a
        if a*b==0 :
            break
    print(result)
main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    main();
  operation main()
  pre: true post: true
  activity:
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var result : int := 0 ;
    while a /= b do (    if (a->compareTo(b)) >= 0 then  (
      result := result + a div b ;
    var a : int := a mod b
    )
    else (
      result := result + b div a ;
    var b : int := b mod a
      ) ;
    if a * b = 0 then (
      break
    ) else skip) ;
    execute (result)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=map(int,input().split(' '))
a,b=max(a,b),min(a,b)
ans=0
while b>1 :
    ans+=int(a/b)
    a=int(a % b)
    a,b=max(a,b),min(a,b)
ans+=(a*b)
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := Sequence{Set{a, b}->max(),Set{a, b}->min()} ;
    var ans : int := 0 ;
    while b > 1 do (    ans := ans + ("" + ((a / b)))->toInteger() ;
    var a : int := ("" + ((a mod b)))->toInteger() ;
    var b : OclAny := null;
    Sequence{a,b} := Sequence{Set{a, b}->max(),Set{a, b}->min()}) ;
    ans := ans + (a * b) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def isSellingPossible(n,a):
    c25=0 ;
    c50=0 ;
    i=0 ;
    while(i0 and c25>0):
                c50-=1 ;
                c25-=1 ;
            elif(c25>=3):
                c25-=3 ;
            else :
                break ;
        i+=1 ;
    if(i==n):
        return True ;
    else :
        return False ;
a=[25,25,50,100];
n=len(a);
if(isSellingPossible(n,a)):
    print("YES");
else :
    print("NO");
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    a := Sequence{25}->union(Sequence{25}->union(Sequence{50}->union(Sequence{ 100 }))); ;
    n := (a)->size(); ;
    if (isSellingPossible(n, a)) then  (
      execute ("YES")->display();
    )
    else (
      execute ("NO")->display();
      );
  operation isSellingPossible(n : OclAny, a : OclAny)
  pre: true post: true
  activity:
    var c25 : int := 0; ;
    var c50 : int := 0; ;
    var i : int := 0; ;
    while ((i->compareTo(n)) < 0) do (    if (a[i+1] = 25) then  (
      c25 := c25 + 1;
    )
    else (if (a[i+1] = 50) then
   (
      c50 := c50 + 1; ;
    if (c25 = 0) then (
      break;
    ) else skip ;
    c25 := c25 - 1;    
)
    else (
      if (c50 > 0 & c25 > 0) then  (
      c50 := c50 - 1; ;
    c25 := c25 - 1;
    )
    else (if (c25 >= 3) then
   (
      c25 := c25 - 3;    
)
    else (
      break;
      )    )
      )    )
 ;
    i := i + 1;) ;
    if (i = n) then  (
      return true;
    )
    else (
      return false;
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import deque
import sys
input=sys.stdin.readline
ii=lambda : int(input())
iil=lambda :[int(x)for x in input().split()]
n,m=iil()
edges=[set()for _ in range(n+1)]
for _ in range(m):
    u,v=iil()
    edges[u].add(v)
    edges[v].add(u)
count=0
not_visited=set(range(1,n+1))
for s in range(1,n+1):
    if s not in not_visited :
        continue
    q=deque([s])
    while q and not_visited :
        u=q.popleft()
        new_qq=set()
        for v in not_visited :
            if v not in edges[u]:
                new_qq.add(v)
                q.append(v)
        not_visited-=new_qq
    count+=1
print(count-1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    var ii : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ;
    var iil : Function := lambda $$ : OclAny in (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) ;
    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := iil->apply() ;
    var edges : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ;
    for _anon : Integer.subrange(0, m-1) do (    var u : OclAny := null;
    var v : OclAny := null;
    Sequence{u,v} := iil->apply() ;
(expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) ;
(expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)))))))) ))))) ;
    var count : int := 0 ;
    var not_visited : Set := Set{}->union((Integer.subrange(1, n + 1-1))) ;
    for s : Integer.subrange(1, n + 1-1) do (    if (not_visited)->excludes(s) then (
      continue
    ) else skip ;
    var q : Sequence := (Sequence{ s }) ;
    while q & not_visited do (    var u : OclAny := q->first() ;     q := q->tail() ;
    var new_qq : Set := Set{}->union(()) ;
    for v : not_visited do (    if (edges[u+1])->excludes(v) then (
      execute ((v) : new_qq) ;
    execute ((v) : q)
    ) else skip) ;
    not_visited := not_visited - new_qq) ;
    count := count + 1) ;
    execute (count - 1)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
for _ in range(int(input())):
    n=int(input())
    s=input()[:-1]
    c=s.count('>')
    if c==0 or c==n :
        print(0)
    else :
        a=s.index('>')
        b=s.rindex('<')
        print(min(a,n-b-1))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : OclAny := input()->front() ;
    var c : int := s->count('>') ;
    if c = 0 or c = n then  (
      execute (0)->display()
    )
    else (
      var a : int := s->indexOf('>') - 1 ;
    var b : OclAny := s.rindex('<') ;
    execute (Set{a, n - b - 1}->min())->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def areSetBitsIncreasing(n):
    prev_count=sys.maxsize
    while(n>0):
        while(n>0 and n % 2==0):
            n=int(n/2)
        curr_count=1
        while(n>0 and n % 2==1):
            n=n/2
            curr_count+=1
        if(curr_count>=prev_count):
            return False
        prev_count=curr_count
    return True
n=10
if(areSetBitsIncreasing(n)):
    print("Yes")
else :
    print("No")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    n := 10 ;
    if (areSetBitsIncreasing(n)) then  (
      execute ("Yes")->display()
    )
    else (
      execute ("No")->display()
      );
  operation areSetBitsIncreasing(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var prev_count : (trailer . (name maxsize)) := (trailer . (name maxsize)) ;
    while (n > 0) do (    while (n > 0 & n mod 2 = 0) do (    n := ("" + ((n / 2)))->toInteger()) ;
    var curr_count : int := 1 ;
    while (n > 0 & n mod 2 = 1) do (    n := n / 2 ;
    curr_count := curr_count + 1) ;
    if ((curr_count->compareTo(prev_count)) >= 0) then (
      return false
    ) else skip ;
    prev_count := curr_count) ;
    return true;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def lenghtOfLongestAP(set,n):
    if(n<=2):
        return n
    L=[[0 for x in range(n)]for y in range(n)]
    llap=2
    for i in range(n):
        L[i][n-1]=2
    for j in range(n-2,0,-1):
        i=j-1
        k=j+1
        while(i>=0 and k<=n-1):
            if(set[i]+set[k]<2*set[j]):
                k+=1
            elif(set[i]+set[k]>2*set[j]):
                L[i][j]=2
                i-=1
            else :
                L[i][j]=L[j][k]+1
                llap=max(llap,L[i][j])
                i-=1
                k+=1
                while(i>=0):
                    L[i][j]=2
                    i-=1
    return llap
if __name__=="__main__" :
    set1=[1,7,10,13,14,19]
    n1=len(set1)
    print(lenghtOfLongestAP(set1,n1))
    set2=[1,7,10,15,27,29]
    n2=len(set2)
    print(lenghtOfLongestAP(set2,n2))
    set3=[2,4,6,8,10]
    n3=len(set3)
    print(lenghtOfLongestAP(set3,n3))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      var set1 : Sequence := Sequence{1}->union(Sequence{7}->union(Sequence{10}->union(Sequence{13}->union(Sequence{14}->union(Sequence{ 19 }))))) ;
    var n1 : int := (set1)->size() ;
    execute (lenghtOfLongestAP(set1, n1))->display() ;
    var set2 : Sequence := Sequence{1}->union(Sequence{7}->union(Sequence{10}->union(Sequence{15}->union(Sequence{27}->union(Sequence{ 29 }))))) ;
    var n2 : int := (set2)->size() ;
    execute (lenghtOfLongestAP(set2, n2))->display() ;
    var set3 : Sequence := Sequence{2}->union(Sequence{4}->union(Sequence{6}->union(Sequence{8}->union(Sequence{ 10 })))) ;
    var n3 : int := (set3)->size() ;
    execute (lenghtOfLongestAP(set3, n3))->display()
    ) else skip;
  operation lenghtOfLongestAP(set : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    if (n <= 2) then (
      return n
    ) else skip ;
    var L : Sequence := Integer.subrange(0, n-1)->select(y | true)->collect(y | (Integer.subrange(0, n-1)->select(x | true)->collect(x | (0)))) ;
    var llap : int := 2 ;
    for i : Integer.subrange(0, n-1) do (    L[i+1][n - 1+1] := 2) ;
    for j : Integer.subrange(0 + 1, n - 2)->reverse() do (    var i : double := j - 1 ;
    var k : OclAny := j + 1 ;
    while (i >= 0 & (k->compareTo(n - 1)) <= 0) do (    if ((Set{}->union([i+1]) + Set{}->union([k+1])->compareTo(2 * Set{}->union([j+1]))) < 0) then  (
      k := k + 1
    )
    else (if ((Set{}->union([i+1]) + Set{}->union([k+1])->compareTo(2 * Set{}->union([j+1]))) > 0) then
   (
      L[i+1][j+1] := 2 ;
    i := i - 1    
)
    else (
      L[i+1][j+1] := L[j+1][k+1] + 1 ;
    llap := Set{llap, L[i+1][j+1]}->max() ;
    i := i - 1 ;
    k := k + 1 ;
    while (i >= 0) do (    L[i+1][j+1] := 2 ;
    i := i - 1)
      )    )
)) ;
    return llap;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from queue import Queue
def minIndex(q,sortedIndex):
    min_index=-1
    min_val=999999999999
    n=q.qsize()
    for i in range(n):
        curr=q.queue[0]
        q.get()
        if(curr<=min_val and i<=sortedIndex):
            min_index=i
            min_val=curr
        q.put(curr)
    return min_index
def insertMinToRear(q,min_index):
    min_val=None
    n=q.qsize()
    for i in range(n):
        curr=q.queue[0]
        q.get()
        if(i!=min_index):
            q.put(curr)
        else :
            min_val=curr
    q.put(min_val)
def sortQueue(q):
    for i in range(1,q.qsize()+1):
        min_index=minIndex(q,q.qsize()-i)
        insertMinToRear(q,min_index)
if __name__=='__main__' :
    q=Queue()
    q.put(30)
    q.put(11)
    q.put(15)
    q.put(4)
    sortQueue(q)
    while(q.empty()==False):
        print(q.queue[0],end=" ")
        q.get()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      q := Queue() ;
    q.put(30) ;
    q.put(11) ;
    q.put(15) ;
    q.put(4) ;
    sortQueue(q) ;
    while (q.empty() = false) do (    execute (q.queue->first())->display() ;
    q.get())
    ) else skip;
  operation minIndex(q : OclAny, sortedIndex : OclAny) : OclAny
  pre: true post: true
  activity:
    var min_index : int := -1 ;
    var min_val : int := 999999999999 ;
    var n : OclAny := q.qsize() ;
    for i : Integer.subrange(0, n-1) do (    var curr : OclAny := q.queue->first() ;
    q.get() ;
    if ((curr->compareTo(min_val)) <= 0 & (i->compareTo(sortedIndex)) <= 0) then (
      min_index := i ;
    min_val := curr
    ) else skip ;
    q.put(curr)) ;
    return min_index;
  operation insertMinToRear(q : OclAny, min_index : OclAny)
  pre: true post: true
  activity:
    min_val := null ;
    n := q.qsize() ;
    for i : Integer.subrange(0, n-1) do (    curr := q.queue->first() ;
    q.get() ;
    if (i /= min_index) then  (
      q.put(curr)
    )
    else (
      min_val := curr
      )) ;
    q.put(min_val);
  operation sortQueue(q : OclAny)
  pre: true post: true
  activity:
    for i : Integer.subrange(1, q.qsize() + 1-1) do (    min_index := minIndex(q, q.qsize() - i) ;
    insertMinToRear(q, min_index));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
class Solution :
    def reverse(self,x):
        res,isPos=0,1
        if x<0 :
            isPos=-1
            x=-1*x
        while x!=0 :
            res=res*10+x % 10
            if res>2147483647 :
                return 0
            x/=10
        return res*isPos
------------------------------------------------------------
OCL File:
---------
class Solution {
  static operation newSolution() : Solution
  pre: true
  post: Solution->exists( _x | result = _x );
  operation reverse(x : OclAny) : OclAny
  pre: true post: true
  activity:
    var res : OclAny := null;
    var isPos : OclAny := null;
    Sequence{res,isPos} := Sequence{0,1} ;
    if x < 0 then (
      var isPos : int := -1 ;
    x := -1 * x
    ) else skip ;
    while x /= 0 do (    var res : double := res * 10 + x mod 10 ;
    if res > 2147483647 then (
      return 0
    ) else skip ;
    x := x / 10) ;
    return res * isPos;
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=map(int,input().split())
dif=b-a
def hgt(x):
    return round((x+1)*x/2)
print(hgt(b-a)-b)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var dif : double := b - a ;
    skip ;
    execute (hgt(b - a) - b)->display();
  operation hgt(x : OclAny) : OclAny
  pre: true post: true
  activity:
    return ((x + 1) * x / 2)->round();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=[int(i)for i in input().split()]
length=(b-a)*(b-a+1)//2
print(length-b)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var length : int := (b - a) * (b - a + 1) div 2 ;
    execute (length - b)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def solve():
    a,b=map(int,input().split())
    d=b-a
    print(int((1/2)*d*(d+1))-b)
if __name__=="__main__" :
    solve()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      solve()
    ) else skip;
  operation solve()
  pre: true post: true
  activity:
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var d : double := b - a ;
    execute (("" + (((1 / 2) * d * (d + 1))))->toInteger() - b)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
ab=list(map(int,input().split()))
a=ab[0]
b=ab[1]
print((b-a)*(b-a+1)//2-b)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var ab : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var a : OclAny := ab->first() ;
    var b : OclAny := ab[1+1] ;
    execute ((b - a) * (b - a + 1) div 2 - b)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=(int(x)for x in input().split())
print(sum(x for x in range(b-a))-a)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ;
    execute (((argument (test (logical_test (comparison (expr (atom (name x)))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (name a))))))))) )))))))))->sum() - a)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N,M=map(int,input().split())
S=list(map(int,input().split()))
T=list(map(int,input().split()))
dp=[[0 for _ in range(M+1)]for _ in range(N+1)]
MOD=10**9+7
for i in range(1,N+1):
    for j in range(1,M+1):
        if S[i-1]==T[j-1]:
            dp[i][j]=dp[i][j-1]+dp[i-1][j]+1
        else :
            dp[i][j]=dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1]
        dp[i][j]%=MOD
print(dp[N][M]+1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var S : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var T : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var dp : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, M + 1-1)->select(_anon | true)->collect(_anon | (0)))) ;
    var MOD : double := (10)->pow(9) + 7 ;
    for i : Integer.subrange(1, N + 1-1) do (    for j : Integer.subrange(1, M + 1-1) do (    if S[i - 1+1] = T[j - 1+1] then  (
      dp[i+1][j+1] := dp[i+1][j - 1+1] + dp[i - 1+1][j+1] + 1
    )
    else (
      dp[i+1][j+1] := dp[i+1][j - 1+1] + dp[i - 1+1][j+1] - dp[i - 1+1][j - 1+1]
      ) ;
    dp[i+1][j+1] := dp[i+1][j+1] mod MOD)) ;
    execute (dp[N+1][M+1] + 1)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import numpy as np
import math
inname="input.txt"
outname="output.txt"
with open(inname,'r')as f :
    cases=int(f.readline())
    for tc in range(1,cases+1):
        line=f.readline().strip().split(' ')
        N=int(line[0])
        C=int(line[1])
        M=int(line[2])
        Cnum=[0]*C
        Nnum=[0]*N
        for i in range(M):
            line=f.readline().strip().split(' ')
            p=int(line[0])
            b=int(line[1])
            Nnum[p-1]+=1
            Cnum[b-1]+=1
        Nsum=[0]*(N+1)
        for i in range(N):
            Nsum[i+1]=Nsum[i]+Nnum[i]
        y=0
        for i in range(C):
            if Cnum[i]>y :
                y=Cnum[i]
        for i in range(N):
            a=math.ceil(Nsum[i+1]/(i+1))
            if a>y :
                y=a
        z=0
        for i in range(N):
            if Nnum[i]>y :
                z+=Nnum[i]-y
        print("Case #%d: %d %d" %(tc,y,z))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var inname : String := "input.txt" ;
    var outname : String := "output.txt" ;
    try (var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(inname));
    var cases : int := ("" + ((f.readLine())))->toInteger() ;
    for tc : Integer.subrange(1, cases + 1-1) do (    var line : OclAny := f.readLine()->trim().split(' ') ;
    var N : int := ("" + ((line->first())))->toInteger() ;
    var C : int := ("" + ((line[1+1])))->toInteger() ;
    var M : int := ("" + ((line[2+1])))->toInteger() ;
    var Cnum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, C) ;
    var Nnum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ;
    for i : Integer.subrange(0, M-1) do (    line := f.readLine()->trim().split(' ') ;
    var p : int := ("" + ((line->first())))->toInteger() ;
    var b : int := ("" + ((line[1+1])))->toInteger() ;
    Nnum[p - 1+1] := Nnum[p - 1+1] + 1 ;
    Cnum[b - 1+1] := Cnum[b - 1+1] + 1) ;
    var Nsum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ;
    for i : Integer.subrange(0, N-1) do (    Nsum[i + 1+1] := Nsum[i+1] + Nnum[i+1]) ;
    var y : int := 0 ;
    for i : Integer.subrange(0, C-1) do (    if (Cnum[i+1]->compareTo(y)) > 0 then (
      y := Cnum[i+1]
    ) else skip) ;
    for i : Integer.subrange(0, N-1) do (    var a : double := (Nsum[i + 1+1] / (i + 1))->ceil() ;
    if (a->compareTo(y)) > 0 then (
      y := a
    ) else skip) ;
    var z : int := 0 ;
    for i : Integer.subrange(0, N-1) do (    if (Nnum[i+1]->compareTo(y)) > 0 then (
      z := z + Nnum[i+1] - y
    ) else skip) ;
    execute (StringLib.format("Case #%d: %d %d",Sequence{tc, y, z}))->display()))
    catch (_e : OclException) do skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
x,y=map(int,input().split())
print(int(x+y/2))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (("" + ((x + y / 2)))->toInteger())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
MOD=10**9+7
N,M=map(int,input().split())
S=list(map(int,input().split()))
T=list(map(int,input().split()))
dp=[[1]*(M+1)for i in range(N+1)]
S_index=[[]for i in range(10**5+1)]
for i in range(N):
    S_index[S[i]].append(i)
    if len(S_index[S[i]])>=2 :
        ikkomae=S_index[S[i]][-2]
        for j in range(M+1):
            dp[i-1][j]=(dp[i-1][j]+dp[ikkomae-1][j])% MOD
    for j in range(M):
        dp[i][j]=dp[i][j-1]
        if len(S_index[T[j]])>=1 :
            dp[i][j]=(dp[i][j]+dp[S_index[T[j]][-1]-1][j-1])% MOD
print(dp[N-1][M-1])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var MOD : double := (10)->pow(9) + 7 ;
    var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var S : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var T : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var dp : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 1 }, (M + 1)))) ;
    var S_index : Sequence := Integer.subrange(0, (10)->pow(5) + 1-1)->select(i | true)->collect(i | (Sequence{})) ;
    for i : Integer.subrange(0, N-1) do ((expr (atom (name S_index)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ;
    if (S_index[S[i+1]+1])->size() >= 2 then (
      var ikkomae : OclAny := S_index[S[i+1]+1]->front()->last() ;
    for j : Integer.subrange(0, M + 1-1) do (    dp[i - 1+1][j+1] := (dp[i - 1+1][j+1] + dp[ikkomae - 1+1][j+1]) mod MOD)
    ) else skip ;
    for j : Integer.subrange(0, M-1) do (    dp[i+1][j+1] := dp[i+1][j - 1+1] ;
    if (S_index[T[j+1]+1])->size() >= 1 then (
      dp[i+1][j+1] := (dp[i+1][j+1] + dp[S_index[T[j+1]+1]->last() - 1+1][j - 1+1]) mod MOD
    ) else skip)) ;
    execute (dp[N - 1+1][M - 1+1])->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
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,M=map(int,readline().split())
    S=list(map(int,readline().split()))
    T=list(map(int,readline().split()))
    dp=[[0]*(M+1)for _ in range(N+1)]
    for i in range(N+1):
        dp[i][0]=1
    for j in range(M+1):
        dp[0][j]=1
    for i in range(N):
        for j in range(M):
            if S[i]==T[j]:
                dp[i+1][j+1]=(dp[i][j+1]+dp[i+1][j])% MOD
            else :
                dp[i+1][j+1]=(dp[i][j+1]+dp[i+1][j]-dp[i][j])% MOD
    print(dp[N][M])
    return
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var read : OclAny := (OclFile["System.in"]).read ;
    var readline : OclAny := (OclFile["System.in"]).readline ;
    var readlines : OclAny := (OclFile["System.in"]).readlines ;
    sys.setrecursionlimit((10)->pow(9)) ;
    var INF : int := 1 * (2->pow(60)) ;
    var MOD : int := 1000000007 ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var S : Sequence := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var T : Sequence := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var dp : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (M + 1)))) ;
    for i : Integer.subrange(0, N + 1-1) do (    dp[i+1]->first() := 1) ;
    for j : Integer.subrange(0, M + 1-1) do (    dp->first()[j+1] := 1) ;
    for i : Integer.subrange(0, N-1) do (    for j : Integer.subrange(0, M-1) do (    if S[i+1] = T[j+1] then  (
      dp[i + 1+1][j + 1+1] := (dp[i+1][j + 1+1] + dp[i + 1+1][j+1]) mod MOD
    )
    else (
      dp[i + 1+1][j + 1+1] := (dp[i+1][j + 1+1] + dp[i + 1+1][j+1] - dp[i+1][j+1]) mod MOD
      ))) ;
    execute (dp[N+1][M+1])->display() ;
    return;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
MOD=10**9+7
n,m=(int(num)for num in input().split())
s=[int(num)for num in input().split()]
t=[int(num)for num in input().split()]
dp=[[1]*(m+1)for _ in range(n+1)]
for i in range(1,n+1):
    for j in range(1,m+1):
        dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]
        if s[i-1]==t[j-1]:
            dp[i][j]+=dp[i-1][j-1]
        dp[i][j]=dp[i][j]% MOD
print(dp[n][m])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var MOD : double := (10)->pow(9) + 7 ;
    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) ))))))) (comp_for for (exprlist (expr (atom (name num)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ;
    var s : Sequence := input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ;
    var t : Sequence := input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ;
    var dp : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 1 }, (m + 1)))) ;
    for i : Integer.subrange(1, n + 1-1) do (    for j : Integer.subrange(1, m + 1-1) do (    dp[i+1][j+1] := dp[i - 1+1][j+1] + dp[i+1][j - 1+1] - dp[i - 1+1][j - 1+1] ;
    if s[i - 1+1] = t[j - 1+1] then (
      dp[i+1][j+1] := dp[i+1][j+1] + dp[i - 1+1][j - 1+1]
    ) else skip ;
    dp[i+1][j+1] := dp[i+1][j+1] mod MOD)) ;
    execute (dp[n+1][m+1])->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N,M=map(int,input().split())
S=list(map(int,input().split()))
T=list(map(int,input().split()))
mod=10**9+7
ans=[[0 for e in range(M)]for f in range(N)]
rui=[[0 for e in range(M)]for f in range(N)]
for j in range(M):
    if j!=0 :
        rui[0][j]=rui[0][j-1]
    if S[0]==T[j]:
        ans[0][j]=1
        rui[0][j]+=ans[0][j]
for i in range(1,N):
    rui[i][0]=rui[i-1][0]
    if S[i]==T[0]:
        ans[i][0]=1
        rui[i][0]+=ans[i][0]
for i in range(1,N):
    for j in range(1,M):
        rui[i][j]=rui[i][j-1]+rui[i-1][j]-rui[i-1][j-1]
        if S[i]==T[j]:
            ans[i][j]=(rui[i-1][j-1]+1)
            rui[i][j]+=ans[i][j]
        rui[i][j]%=mod
print((rui[N-1][M-1]+1)% mod)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var S : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var T : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var mod : double := (10)->pow(9) + 7 ;
    var ans : Sequence := Integer.subrange(0, N-1)->select(f | true)->collect(f | (Integer.subrange(0, M-1)->select(e | true)->collect(e | (0)))) ;
    var rui : Sequence := Integer.subrange(0, N-1)->select(f | true)->collect(f | (Integer.subrange(0, M-1)->select(e | true)->collect(e | (0)))) ;
    for j : Integer.subrange(0, M-1) do (    if j /= 0 then (
      rui->first()[j+1] := rui->first()[j - 1+1]
    ) else skip ;
    if S->first() = T[j+1] then (
      ans->first()[j+1] := 1 ;
    rui->first()[j+1] := rui->first()[j+1] + ans->first()[j+1]
    ) else skip) ;
    for i : Integer.subrange(1, N-1) do (    rui[i+1]->first() := rui[i - 1+1]->first() ;
    if S[i+1] = T->first() then (
      ans[i+1]->first() := 1 ;
    rui[i+1]->first() := rui[i+1]->first() + ans[i+1]->first()
    ) else skip) ;
    for i : Integer.subrange(1, N-1) do (    for j : Integer.subrange(1, M-1) do (    rui[i+1][j+1] := rui[i+1][j - 1+1] + rui[i - 1+1][j+1] - rui[i - 1+1][j - 1+1] ;
    if S[i+1] = T[j+1] then (
      ans[i+1][j+1] := (rui[i - 1+1][j - 1+1] + 1) ;
    rui[i+1][j+1] := rui[i+1][j+1] + ans[i+1][j+1]
    ) else skip ;
    rui[i+1][j+1] := rui[i+1][j+1] mod mod)) ;
    execute ((rui[N - 1+1][M - 1+1] + 1) mod mod)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def tribWord(n):
    Sn_1="1"
    Sn_2="12"
    Sn_3="1213"
    for i in range(3,n+1):
        tmp=Sn_3
        Sn_3+=(Sn_2+Sn_1)
        Sn_1=Sn_2
        Sn_2=tmp
    return Sn_3
n=6
print(tribWord(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    n := 6 ;
    execute (tribWord(n))->display();
  operation tribWord(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var Sn    skip : String := "1" ;
    var Sn:= "12" : String := "12" ;
    var Sn_3 : String := "1213" ;
    for i : Integer.subrange(3, n + 1-1) do (    var tmp : String := Sn_3 ;
    Sn_3 := Sn_3 + (SnSn    var tmp : String := Sn_3 + Sn    var tmp : String := Sn_3) ;
    Sn    var tmp : String := Sn_3 := Sn_2 ;
    Sn:= tmp := tmp) ;
    return Sn_3;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def isRotation(x,y):
    x64=x |(x<<32)
    while(x64>=y):
        if((x64)==y):
            return True
        x64>>=1
    return False
if __name__=="__main__" :
    x=122
    y=2147483678
    if(isRotation(x,y)==False):
        print("yes")
    else :
        print("no")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      x := 122 ;
    y := 2147483678 ;
    if (isRotation(x, y) = false) then  (
      execute ("yes")->display()
    )
    else (
      execute ("no")->display()
      )
    ) else skip;
  operation isRotation(x : OclAny, y : OclAny) : OclAny
  pre: true post: true
  activity:
    var x64 : int := MathLib.bitwiseOr(x, (x * (2->pow(32)))) ;
    while ((x64->compareTo(y)) >= 0) do (    if ((x64) = y) then (
      return true
    ) else skip ;
    x64 := x64 div (2->pow(1))) ;
    return false;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    n,m=map(int,input().split())
    if n==0 : break
    p=list(map(int,input().split()))
    if 1 in p : n=0
    print(n/2)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if n = 0 then (
      break
    ) else skip ;
    var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if (p)->includes(1) then (
      var n : int := 0
    ) else skip ;
    execute (n / 2)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    n,m=map(int,input().split())
    if n==0 :
        break
    p=sorted(list(map(int,input().split())))
    flag=0 if p[0]==1 else 1
    print('{:.10f}'.format(n/2 if flag else 0))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if n = 0 then (
      break
    ) else skip ;
    var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ;
    var flag : int := if p->first() = 1 then 0 else 1 endif ;
    execute (StringLib.interpolateStrings('{:.10f}', Sequence{if flag then n / 2 else 0 endif}))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for _ in range(t):
    a,b,c=map(int,input().split())
    diff=abs(a-b)
    value=diff*2
    if a>value or b>value or c>value :
        print(-1)
    else :
        ans=c+diff
        if(ans>value):
            ans=c-diff
        print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, t-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var diff : double := (a - b)->abs() ;
    var value : double := diff * 2 ;
    if (a->compareTo(value)) > 0 or (b->compareTo(value)) > 0 or (c->compareTo(value)) > 0 then  (
      execute (-1)->display()
    )
    else (
      var ans : OclAny := c + diff ;
    if ((ans->compareTo(value)) > 0) then (
      ans := c - diff
    ) else skip ;
    execute (ans)->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
tc=int(input())
for _ in range(tc):
    n,x=list(map(int,input().split()))
    if(n % 2==x % 2):
        if(x*x>n):
            print("NO")
        else :
            print("YES")
    else :
        print("NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var tc : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, tc-1) do (    var n : OclAny := null;
    var x : OclAny := null;
    Sequence{n,x} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if (n mod 2 = x mod 2) then  (
      if ((x * x->compareTo(n)) > 0) then  (
      execute ("NO")->display()
    )
    else (
      execute ("YES")->display()
      )
    )
    else (
      execute ("NO")->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
for i in range(n):
    a,b,c=map(int,input().split())
    k=abs(b-a)
    if(a<=2*k and b<=2*k and c<=2*k):
        if(c>k):
            print(c-k)
        else :
            print(c+k)
    else :
        print(-1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, n-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var k : double := (b - a)->abs() ;
    if ((a->compareTo(2 * k)) <= 0 & (b->compareTo(2 * k)) <= 0 & (c->compareTo(2 * k)) <= 0) then  (
      if ((c->compareTo(k)) > 0) then  (
      execute (c - k)->display()
    )
    else (
      execute (c + k)->display()
      )
    )
    else (
      execute (-1)->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
print(eval(input().replace(" ","+")+"//2"))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     execute (input().replace(" ", "+") + "//2")->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for _ in range(t):
    a,b,c=list(map(int,input().split()))
    if a>b :
        a,b=b,a
    n=2*(b-a)
    if a>n or b>n or c>n :
        print(-1)
    else :
        if 2*c<=n :
            d=c+n//2
        else :
            d=c-n//2
        print(d)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, t-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if (a->compareTo(b)) > 0 then (
      var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := Sequence{b,a}
    ) else skip ;
    var n : double := 2 * (b - a) ;
    if (a->compareTo(n)) > 0 or (b->compareTo(n)) > 0 or (c->compareTo(n)) > 0 then  (
      execute (-1)->display()
    )
    else (
      if (2 * c->compareTo(n)) <= 0 then  (
      var d : OclAny := c + n div 2
    )
    else (
      d := c - n div 2
      ) ;
    execute (d)->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for s in[*open(0)][1 :]: a,b,c=map(int,s.split()); n=2*abs(a-b); print(((c-1+n//2)% n+1,-1)[max(a,b,c)>n])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do (    var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := (s.split())->collect( _x | (OclType["int"])->apply(_x) );    var n : double := 2 * (a - b)->abs();    execute (Sequence{(c - 1 + n div 2) mod n + 1, -1}->select((Set{a, b, c}->max()->compareTo(n)) > 0))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for i in range(t):
    a,b,c=map(int,(input().split()))
    n=abs(b-a)
    m=2*n
    d=0
    if a>m or b>m or c>m :
        d=-1
    elif c>n :
        d=c-n
    else :
        d=c+n
    print(d)
    t-=1
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, t-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := ((input().split()))->collect( _x | (OclType["int"])->apply(_x) ) ;
    var n : double := (b - a)->abs() ;
    var m : double := 2 * n ;
    var d : int := 0 ;
    if (a->compareTo(m)) > 0 or (b->compareTo(m)) > 0 or (c->compareTo(m)) > 0 then  (
      d := -1
    )
    else (if (c->compareTo(n)) > 0 then
   (
      d := c - n    
)
    else (
      d := c + n
      )    )
 ;
    execute (d)->display() ;
    t := t - 1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import defaultdict
MAXN=1000001
MAXN_sqrt=int(MAXN**(0.5))
spf=[None]*(MAXN)
def sieve():
    spf[1]=1
    for i in range(2,MAXN):
        spf[i]=i
    for i in range(4,MAXN,2):
        spf[i]=2
    for i in range(3,MAXN_sqrt):
        if spf[i]==i :
            for j in range(i*i,MAXN,i):
                if spf[j]==j :
                    spf[j]=i
def sumFactors(arr,n):
    sieve()
    Map=defaultdict(lambda : 0)
    for i in range(0,n):
        Map[arr[i]]=1
    Sum=0
    for i in range(0,n):
        num=arr[i]
        while num!=1 and Map[spf[num]]==1 :
            num=num//spf[num]
        if num==1 :
            Sum+=arr[i]
    return Sum
if __name__=="__main__" :
    arr=[5,11,55,25,100]
    n=len(arr)
    print(sumFactors(arr,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var MAXN : int := 1000001 ;
    var MAXN_sqrt : int := ("" + (((MAXN)->pow((0.5)))))->toInteger() ;
    var spf : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (MAXN)) ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      arr := Sequence{5}->union(Sequence{11}->union(Sequence{55}->union(Sequence{25}->union(Sequence{ 100 })))) ;
    n := (arr)->size() ;
    execute (sumFactors(arr, n))->display()
    ) else skip;
  operation sieve()
  pre: true post: true
  activity:
    spf[1+1] := 1 ;
    for i : Integer.subrange(2, MAXN-1) do (    spf[i+1] := i) ;
    for i : Integer.subrange(4, MAXN-1)->select( $x | ($x - 4) mod 2 = 0 ) do (    spf[i+1] := 2) ;
    for i : Integer.subrange(3, MAXN_sqrt-1) do (    if spf[i+1] = i then (
      for j : Integer.subrange(i * i, MAXN-1)->select( $x | ($x - i * i) mod i = 0 ) do (    if spf[j+1] = j then (
      spf[j+1] := i
    ) else skip)
    ) else skip);
  operation sumFactors(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    sieve() ;
    var Map : OclAny := defaultdict(lambda $$ : OclAny in (0)) ;
    for i : Integer.subrange(0, n-1) do (    Map[arr[i+1]+1] := 1) ;
    var Sum : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    var num : OclAny := arr[i+1] ;
    while num /= 1 & Map[spf[num+1]+1] = 1 do (    num := num div spf[num+1]) ;
    if num = 1 then (
      Sum := Sum + arr[i+1]
    ) else skip) ;
    return Sum;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math ;
def isPrime(x):
    s=int(math.sqrt(x))
    for i in range(2,s+1):
        if(x % i==0):
            return 0
    return 1
def Num(x):
    ab=[0]*2
    for i in range(2,int(x/2)+1):
        if(isPrime(i)!=0 and isPrime(x-i)!=0):
            ab[0]=i
            ab[1]=x-i
            return ab
def generate(n):
    if(n<=7):
        print("Impossible to form")
    if(n % 2!=0):
        ab=Num(n-5)
        print("2 3",ab[0],ab[1])
    else :
        ab=Num(n-4)
        print("2 2",ab[0],ab[1])
if __name__=='__main__' :
    n=28
    generate(n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip; ;
    skip ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      n := 28 ;
    generate(n)
    ) else skip;
  operation isPrime(x : OclAny) : OclAny
  pre: true post: true
  activity:
    var s : int := ("" + (((x)->sqrt())))->toInteger() ;
    for i : Integer.subrange(2, s + 1-1) do (    if (x mod i = 0) then (
      return 0
    ) else skip) ;
    return 1;
  operation Num(x : OclAny) : OclAny
  pre: true post: true
  activity:
    var ab : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 2) ;
    for i : Integer.subrange(2, ("" + ((x / 2)))->toInteger() + 1-1) do (    if (isPrime(i) /= 0 & isPrime(x - i) /= 0) then (
      ab->first() := i ;
    ab[1+1] := x - i ;
    return ab
    ) else skip);
  operation generate(n : OclAny)
  pre: true post: true
  activity:
    if (n <= 7) then (
      execute ("Impossible to form")->display()
    ) else skip ;
    if (n mod 2 /= 0) then  (
      ab := Num(n - 5) ;
    execute ("2 3")->display()
    )
    else (
      ab := Num(n - 4) ;
    execute ("2 2")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=int(input())
s=[]
ans=[]
for i in range(N):
    s.append(list(map(int,input().split())))
for i in range(N):
    tmp=s[i][0]*s[i][2]+s[i][1]*s[i][3]
    if s[i][2]>=5 and s[i][3]>=2 :
        tmp*=0.8
        ans.append(int(tmp))
    else :
        if s[i][2]>=5 :
            tmp2=tmp+s[i][1]*(2-s[i][3])
            tmp2*=0.8
        elif s[i][3]>=2 :
            tmp2=tmp+s[i][0]*(5-s[i][2])
            tmp2*=0.8
        else :
            tmp2=tmp+s[i][0]*(5-s[i][2])+s[i][1]*(2-s[i][3])
            tmp2*=0.8
        ans.append(int(min(tmp,tmp2)))
for i in range(N):
    print(ans[i])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : Sequence := Sequence{} ;
    var ans : Sequence := Sequence{} ;
    for i : Integer.subrange(0, N-1) do (    execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : s)) ;
    for i : Integer.subrange(0, N-1) do (    var tmp : double := s[i+1]->first() * s[i+1][2+1] + s[i+1][1+1] * s[i+1][3+1] ;
    if s[i+1][2+1] >= 5 & s[i+1][3+1] >= 2 then  (
      tmp := tmp * 0.8 ;
    execute ((("" + ((tmp)))->toInteger()) : ans)
    )
    else (
      if s[i+1][2+1] >= 5 then  (
      var tmp2 : OclAny := tmp + s[i+1][1+1] * (2 - s[i+1][3+1]) ;
    tmp2 := tmp2 * 0.8
    )
    else (if s[i+1][3+1] >= 2 then
   (
      tmp2 := tmp + s[i+1]->first() * (5 - s[i+1][2+1]) ;
    tmp2 := tmp2 * 0.8    
)
    else (
      tmp2 := tmp + s[i+1]->first() * (5 - s[i+1][2+1]) + s[i+1][1+1] * (2 - s[i+1][3+1]) ;
    tmp2 := tmp2 * 0.8
      )    )
 ;
    execute ((("" + ((Set{tmp, tmp2}->min())))->toInteger()) : ans)
      )) ;
    for i : Integer.subrange(0, N-1) do (    execute (ans[i+1])->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    try : n=int(input())
    except : break ;
    for i in range(n):
(x,y,b,p)=map(int,input().split())
        s=b*x+p*y
        t=(max(b,5)*x+max(p,2)*y)*4//5
        print(min(s,t))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
suite`nestedAttributeDefinitions
  operation initialise()
  pre: true post: true
  activity:     while true do (    try (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger())
     catch (_e : OclException) do (    break;)
 ;
    for i : Integer.subrange(0, n-1) do (suite)) ;
    var Sequence{x, y, b, p} : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
f=sys.stdin
n=int(f.readline())
for line in f :
    x,y,b,p=map(int,line.split())
    regular=x*b+y*p
    discount=int(x*0.8)*max(b,5)+int(y*0.8)*max(p,2)
    print(min(regular,discount))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var f : OclFile := OclFile["System.in"] ;
    var n : int := ("" + ((f.readLine())))->toInteger() ;
    for line : f do (    var x : OclAny := null;
    var y : OclAny := null;
    var b : OclAny := null;
    var p : OclAny := null;
    Sequence{x,y,b,p} := (line.split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var regular : double := x * b + y * p ;
    var discount : double := ("" + ((x * 0.8)))->toInteger() * Set{b, 5}->max() + ("" + ((y * 0.8)))->toInteger() * Set{p, 2}->max() ;
    execute (Set{regular, discount}->min())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
l=list(map(int,input().split()))
c=0
i=0
ans=0
while(c=l[i]):
                c+=1
                l[i]=1002
            i+=1
        if(i==n):
            i-=1
    if(i==n-1 and c=0):
            if(c>=l[i]):
                c+=1
                l[i]=1002
            i-=1
        if(i==-1):
            i+=1
print(ans-1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var c : int := 0 ;
    var i : int := 0 ;
    var ans : int := 0 ;
    while ((c->compareTo(n)) < 0) do (    if (i = 0 & (c->compareTo(n)) < 0) then (
      ans := ans + 1 ;
    while ((i->compareTo(n)) < 0) do (    if ((c->compareTo(l[i+1])) >= 0) then (
      c := c + 1 ;
    l[i+1] := 1002
    ) else skip ;
    i := i + 1) ;
    if (i = n) then (
      i := i - 1
    ) else skip
    ) else skip ;
    if (i = n - 1 & (c->compareTo(n)) < 0) then (
      ans := ans + 1 ;
    while (i >= 0) do (    if ((c->compareTo(l[i+1])) >= 0) then (
      c := c + 1 ;
    l[i+1] := 1002
    ) else skip ;
    i := i - 1) ;
    if (i = -1) then (
      i := i + 1
    ) else skip
    ) else skip) ;
    execute (ans - 1)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def optimalResult(N,C,positionsByPerson):
    fewestRides=0
    for position in xrange(1,N+1):
        totalRides=0
        for B in positionsByPerson :
            rides=0
            for P in positionsByPerson[B]:
                if P<=position :
                    rides+=1
            fewestRides=max(rides,fewestRides)
            totalRides+=rides
        fewestRides=max(fewestRides,(totalRides+position-1)/position)
    upgrades=0
    for position in xrange(1,N+1):
        frequency=0
        for B in positionsByPerson :
            for P in positionsByPerson[B]:
                if P==position :
                    frequency+=1
        upgrades+=max(0,frequency-fewestRides)
    return ' '.join(map(str,[fewestRides,upgrades]))
with open('../inputs/B-large.in')as infile :
    with open('../outputs/B-large.out','wb')as outfile :
        cases=int(infile.readline())
        for i in xrange(cases):
[N,C,M]=map(int,infile.readline().split(' '))
            positionsByPerson={}
            for _ in xrange(M):
[P,B]=map(int,infile.readline().split(' '))
                positionsByPerson[B]=positionsByPerson.get(B,[])+[P]
            for B in positionsByPerson :
                positionsByPerson[B]=sorted(positionsByPerson[B])
            outfile.write('Case #'+str(i+1)+': ')
            outfile.write(optimalResult(N,C,positionsByPerson))
            outfile.write('\n')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
suite`nestedAttributeDefinitions
  operation initialise()
  pre: true post: true
  activity:     skip ;
    try (var infile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('../inputs/B-large.in'));
    try (var outfile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('../outputs/B-large.out'));
    var cases : int := ("" + ((infile.readLine())))->toInteger() ;
    for i : xrange(cases) do (suite))
    catch (_e : OclException) do skip)
    catch (_e : OclException) do skip ;
    Sequence{N}->union(Sequence{C}->union(Sequence{ M })) := (infile.readLine().split(' '))->collect( _x | (OclType["int"])->apply(_x) );
  operation optimalResult(N : OclAny, C : OclAny, positionsByPerson : OclAny) : OclAny
  pre: true post: true
  activity:
    var fewestRides : int := 0 ;
    for position : xrange(1, N + 1) do (    var totalRides : int := 0 ;
    for B : positionsByPerson do (    var rides : int := 0 ;
    for P : positionsByPerson[B+1] do (    if (P->compareTo(position)) <= 0 then (
      rides := rides + 1
    ) else skip) ;
    fewestRides := Set{rides, fewestRides}->max() ;
    totalRides := totalRides + rides) ;
    fewestRides := Set{fewestRides, (totalRides + position - 1) / position}->max()) ;
    var upgrades : int := 0 ;
    for position : xrange(1, N + 1) do (    var frequency : int := 0 ;
    for B : positionsByPerson do (    for P : positionsByPerson[B+1] do (    if P = position then (
      frequency := frequency + 1
    ) else skip)) ;
    upgrades := upgrades + Set{0, frequency - fewestRides}->max()) ;
    return StringLib.sumStringsWithSeparator(((Sequence{fewestRides}->union(Sequence{ upgrades }))->collect( _x | (OclType["String"])->apply(_x) )), ' ');
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    x,y,a,b=map(int,input().split())
    print(min(x*a+y*b,int(0.8*(x*max(5,a)+y*max(2,b)))))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var x : OclAny := null;
    var y : OclAny := null;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{x,y,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (Set{x * a + y * b, ("" + ((0.8 * (x * Set{5, a}->max() + y * Set{2, b}->max()))))->toInteger()}->min())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
inputs=[list(map(int,input().split()))for _ in range(int(input()))]
ans=[]
def niwari(x,y,_b,_p):
    b=5 if _b<5 else _b
    p=2 if _p<2 else _p
    return int(0.8*(x*b+y*p))
for inpt in inputs :
    x,y,b,p=inpt
    if b>=5 and p>=2 :
        ans.append(str(int((x*b+y*p)*0.8)))
    else :
        ans.append(str(min(int(x*b+y*p),niwari(x,y,b,p))))
print('\n'.join(ans))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var inputs : Sequence := Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var ans : Sequence := Sequence{} ;
    skip ;
    for inpt : inputs do (    Sequence{x,y,b,p} := inpt ;
    if b >= 5 & p >= 2 then  (
      execute ((("" + ((("" + (((x * b + y * p) * 0.8)))->toInteger())))) : ans)
    )
    else (
      execute ((("" + ((Set{("" + ((x * b + y * p)))->toInteger(), niwari(x, y, b, p)}->min())))) : ans)
      )) ;
    execute (StringLib.sumStringsWithSeparator((ans), '
'))->display();
  operation niwari(x : OclAny, y : OclAny, _b : OclAny, _p : OclAny) : OclAny
  pre: true post: true
  activity:
    var b : int := if _b < 5 then 5 else _b endif ;
    var p : int := if _p < 2 then 2 else _p endif ;
    return ("" + ((0.8 * (x * b + y * p))))->toInteger();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=map(int,input().split())
if 1>a or b % 2!=0 or b>100 :
    SystemExit
print(int(a+b/2))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if 1 > a or b mod 2 /= 0 or b > 100 then (
    ) else skip ;
    execute (("" + ((a + b / 2)))->toInteger())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for t in range(int(input())):
    a,b,c,d=map(int,input().split(' ')); l,x,y,o=(a+b)//(min(a,b)+1),a+b,0,""
    if a*l<=b : x,y=0,a+b
    elif b*l>a : x,y=(a*l-b)//(l-1),(b*l-a)//(l-1)
    for i in range(c,d+1): o+="AB"[i %(l+1)==0]if i<=x else "BA"[(a+b-i+1)%(l+1)==0]if a+b-i+1<=y else "AB"[a-x+x//(l+1)-y//(l+1)==0]
    print(o)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    var d : OclAny := null;
    Sequence{a,b,c,d} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) );    var l : OclAny := null;
    var x : OclAny := null;
    var y : OclAny := null;
    var o : OclAny := null;
    Sequence{l,x,y,o} := Sequence{(a + b) div (Set{a, b}->min() + 1),a + b,0,""} ;
    if (a * l->compareTo(b)) <= 0 then  (
      var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := Sequence{0,a + b}
    )
    else (if (b * l->compareTo(a)) > 0 then
   (
      var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := Sequence{(a * l - b) div (l - 1),(b * l - a) div (l - 1)}    
)
 else skip) ;
    for i : Integer.subrange(c, d + 1-1) do (    o := o + if (i->compareTo(x)) <= 0 then "AB"->select(i mod (l + 1) = 0) else if (a + b - i + 1->compareTo(y)) <= 0 then "BA"->select((a + b - i + 1) mod (l + 1) = 0) else "AB"->select(a - x + x div (l + 1) - y div (l + 1) = 0) endif endif) ;
    execute (o)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
Q=int(input())
for _ in range(Q):
    A,B,C,D=map(int,input().split())
    K=math.ceil(max(A,B)/(min(A,B)+1))
    lo,hi=0,A+1
    while hi-lo>1 :
        mid=(lo+hi)//2
        rA,rB=A-mid,B-max(0,(mid-1)//K)
        if(rA+1)*KtoInteger() ;
    for _anon : Integer.subrange(0, Q-1) do (    var A : OclAny := null;
    var B : OclAny := null;
    var C : OclAny := null;
    var D : OclAny := null;
    Sequence{A,B,C,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var K : double := (Set{A, B}->max() / (Set{A, B}->min() + 1))->ceil() ;
    var lo : OclAny := null;
    var hi : OclAny := null;
    Sequence{lo,hi} := Sequence{0,A + 1} ;
    while hi - lo > 1 do (    var mid : int := (lo + hi) div 2 ;
    var rA : OclAny := null;
    var rB : OclAny := null;
    Sequence{rA,rB} := Sequence{A - mid,B - Set{0, (mid - 1) div K}->max()} ;
    if ((rA + 1) * K->compareTo(rB)) < 0 then  (
      var hi : int := mid
    )
    else (
      var lo : int := mid
      )) ;
    var f : String := '' ;
    for i : Integer.subrange(C - 1, D-1) do (    var na : int := lo ;
    var nb : OclAny := Set{0, (na - 1) div K}->max() ;
    if (i->compareTo(nb * (K + 1))) < 0 then  (
      f := f + Sequence{'A', 'B'}->select(i mod (K + 1) = K)
    )
    else (if (i->compareTo(na + nb)) < 0 then
   (
      f := f + 'A'    
)
    else (
      var j : double := A + B - i - 1 ;
    nb := B - nb ;
    na := Set{0, (nb - 1) div K}->max() ;
    if (j->compareTo(na * (K + 1))) < 0 then  (
      f := f + Sequence{'B', 'A'}->select(j mod (K + 1) = K)
    )
    else (
      f := f + 'B'
      )
      )    )
) ;
    execute (f)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
T=int(input())
for TT in range(T):
    a,b,c,d=map(int,input().split(' '))
    l,x,y,out=(a+b)//(min(a,b)+1),0,0,""
    if a*l<=b : y=a+b
    elif b*l<=a : x=a+b
    else : x,y=(a*l-b)//(l-1),(b*l-a)//(l-1)
    for i in range(c,d+1): out+=("AB"[i %(l+1)==0])if i<=x else "BA"[(a+b-i+1)%(l+1)==0]if a+b-i+1<=y else "AB"[a-x+x//(l+1)-y//(l+1)==0]
    print(out)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for TT : Integer.subrange(0, T-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    var d : OclAny := null;
    Sequence{a,b,c,d} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ;
    var l : OclAny := null;
    var x : OclAny := null;
    var y : OclAny := null;
    var out : OclAny := null;
    Sequence{l,x,y,out} := Sequence{(a + b) div (Set{a, b}->min() + 1),0,0,""} ;
    if (a * l->compareTo(b)) <= 0 then  (
      var y : OclAny := a + b
    )
    else (if (b * l->compareTo(a)) <= 0 then
   (
      var x : OclAny := a + b    
)
    else (
      Sequence{x,y} := Sequence{(a * l - b) div (l - 1),(b * l - a) div (l - 1)}
      )    )
 ;
    for i : Integer.subrange(c, d + 1-1) do (    out := out + if (i->compareTo(x)) <= 0 then ("AB"->select(i mod (l + 1) = 0)) else if (a + b - i + 1->compareTo(y)) <= 0 then "BA"->select((a + b - i + 1) mod (l + 1) = 0) else "AB"->select(a - x + x div (l + 1) - y div (l + 1) = 0) endif endif) ;
    execute (out)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
T=int(input())
for TT in range(T):
    a,b,c,d=map(int,input().split(' '))
    l,x,y=(a+b)//(min(a,b)+1),0,0
    if a*l<=b :
        y=a+b
    elif b*l<=a :
        x=a+b
    else :
        x,y=(a*l-b)//(l-1),(b*l-a)//(l-1)
    out=""
    for i in range(c,d+1):
        if i<=x :
            out+="AB"[i %(l+1)==0]
        elif a+b-i+1<=y :
            out+="BA"[(a+b-i+1)%(l+1)==0]
        else :
            out+="AB"[a-x+x//(l+1)-y//(l+1)==0]
    print(out)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for TT : Integer.subrange(0, T-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    var d : OclAny := null;
    Sequence{a,b,c,d} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ;
    var l : OclAny := null;
    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{l,x,y} := Sequence{(a + b) div (Set{a, b}->min() + 1),0,0} ;
    if (a * l->compareTo(b)) <= 0 then  (
      var y : OclAny := a + b
    )
    else (if (b * l->compareTo(a)) <= 0 then
   (
      var x : OclAny := a + b    
)
    else (
      Sequence{x,y} := Sequence{(a * l - b) div (l - 1),(b * l - a) div (l - 1)}
      )    )
 ;
    var out : String := "" ;
    for i : Integer.subrange(c, d + 1-1) do (    if (i->compareTo(x)) <= 0 then  (
      out := out + "AB"->select(i mod (l + 1) = 0)
    )
    else (if (a + b - i + 1->compareTo(y)) <= 0 then
   (
      out := out + "BA"->select((a + b - i + 1) mod (l + 1) = 0)    
)
    else (
      out := out + "AB"->select(a - x + x div (l + 1) - y div (l + 1) = 0)
      )    )
) ;
    execute (out)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
Q=int(input())
num=lambda x :(x,max(0,(x-1)//K))
sub=lambda xs,ys :[x-y for(x,y)in zip(xs,ys)]
for _ in range(Q):
    A,B,C,D=map(int,input().split())
    K=math.ceil(max(A,B)/(min(A,B)+1))
    l,r=0,A+1
    while r-l>1 :
        m=(l+r)//2
        rA,rB=sub((A,B),num(m))
        l,r=((m,r),(l,m))[(rA+1)*KtoInteger() ;
    var num : Function := lambda x : OclAny in (Sequence{x, Set{0, (x - 1) div K}->max()}) ;
    var sub : Function := lambda xs : OclAny, ys : OclAny in (Integer.subrange(1, xs->size())->collect( _indx | Sequence{xs->at(_indx), ys->at(_indx)} )->select(Sequence{x, y} | true)->collect(Sequence{x, y} | (x - y))) ;
    for _anon : Integer.subrange(0, Q-1) do (    var A : OclAny := null;
    var B : OclAny := null;
    var C : OclAny := null;
    var D : OclAny := null;
    Sequence{A,B,C,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var K : double := (Set{A, B}->max() / (Set{A, B}->min() + 1))->ceil() ;
    var l : OclAny := null;
    var r : OclAny := null;
    Sequence{l,r} := Sequence{0,A + 1} ;
    while r - l > 1 do (    var m : int := (l + r) div 2 ;
    var rA : OclAny := null;
    var rB : OclAny := null;
    Sequence{rA,rB} := sub->apply(Sequence{A, B}, num->apply(m)) ;
    var l : OclAny := null;
    var r : OclAny := null;
    Sequence{l,r} := Sequence{Sequence{m, r}, Sequence{l, m}}->select(((rA + 1) * K->compareTo(rB)) < 0)) ;
    var f : String := '' ;
    for i : Integer.subrange(C - 1, D-1) do (    var na : OclAny := null;
    var nb : OclAny := null;
    Sequence{na,nb} := num->apply(l) ;
    if (i->compareTo(na + nb)) < 0 then  (
      f := f + if (i->compareTo(nb * (K + 1))) < 0 then Sequence{'A', 'B'}->select(i mod (K + 1) = K) else 'A' endif
    )
    else (
      var nb : OclAny := null;
    var na : OclAny := null;
    Sequence{nb,na} := num->apply(B - nb) ;
    var j : double := A + B - i - 1 ;
    f := f + if (j->compareTo(na * (K + 1))) < 0 then Sequence{'B', 'A'}->select(j mod (K + 1) = K) else 'B' endif
      )) ;
    execute (f)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import*
from functools import*
from itertools import*
def f():
    input()
    nums=Counter(int(n)for n in input().split())
    prev=curr=0
    prev_val,curr_val=-1,0
    for n in sorted(nums.keys()):
        if n==curr_val+1 :
            prev,curr=curr,max(prev+n*nums[n],curr)
        else :
            prev,curr=curr,n*nums[n]+curr
        prev_val,curr_val=curr_val,n
    return curr
if __name__=="__main__" :
    print(f())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      execute (f())->display()
    ) else skip;
  operation f() : OclAny
  pre: true post: true
  activity:
    input() ;
    var nums : OclAny := Counter((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ;
    var prev : OclAny := 0; var curr : int := 0 ;
    var prev_val : OclAny := null;
    var curr_val : OclAny := null;
    Sequence{prev_val,curr_val} := Sequence{-1,0} ;
    for n : nums.keys()->sort() do (    if n = curr_val + 1 then  (
      Sequence{prev,curr} := Sequence{curr,Set{prev + n * nums[n+1], curr}->max()}
    )
    else (
      Sequence{prev,curr} := Sequence{curr,n * nums[n+1] + curr}
      ) ;
    var prev_val : OclAny := null;
    var curr_val : OclAny := null;
    Sequence{prev_val,curr_val} := Sequence{curr_val,n}) ;
    return curr;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a=list(map(int,input().split(" ")))
a.sort()
d=dict()
for i in a :
    if i in d :
        d[i]+=i
    else :
        d[i]=i
a=[[0,0,0]]
maxi=max(a[0][1],a[0][2])
for i,j in d.items():
    if i-1 in d :
        a.append([i,j+a[-1][2],maxi])
    else :
        a.append([i,j+maxi,maxi])
    maxi=max(a[-1][1],a[-1][2])
print(maxi)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ;
    a := a->sort() ;
    var d : Map := (arguments ( )) ;
    for i : a do (    if (d)->includes(i) then  (
      d[i+1] := d[i+1] + i
    )
    else (
      d[i+1] := i
      )) ;
    a := Sequence{ Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) } ;
    var maxi : OclAny := Set{a->first()[1+1], a->first()[2+1]}->max() ;
    for _tuple : d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var j : OclAny := _tuple->at(_indx);
      if (d)->includes(i - 1) then  (
      execute ((Sequence{i}->union(Sequence{j + a->last()[2+1]}->union(Sequence{ maxi }))) : a)
    )
    else (
      execute ((Sequence{i}->union(Sequence{j + maxi}->union(Sequence{ maxi }))) : a)
      ) ;
    maxi := Set{a->last()[1+1], a->last()[2+1]}->max()) ;
    execute (maxi)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import numpy as np
LINES_PARAM=2
INPUT_FILE_NAME='B-large.in'
OUTPUT_FILE_NAME='B-large.out'
def do_case(parsed):
    n=parsed[0][0]
    c=parsed[0][1]
    seat=[0 for i in range(n)]
    rider=[0 for i in range(c)]
    for l in parsed[1 :]:
        rider[l[1]-1]+=1
        seat[l[0]-1]+=1
    s=np.cumsum(seat)
    m=max(rider)
    for i in range(n):
        m=max(m,(s[i]+i)//(i+1))
    pr=sum([max(0,se-m)for se in seat])
    return str(m)+' '+str(pr)
def do_parse(input):
    return[[int(num)for num in line.rstrip().split(" ")]for line in input]
def main():
    input_f=open(INPUT_FILE_NAME,'r')
    output=[]
    num_of_test_cases=int(input_f.readline(),10)
    temp=input_f.readlines()
    index=0
    for test_case in range(num_of_test_cases):
        lines=int(temp[index].rstrip().split(" ")[LINES_PARAM])
        parsed_input=do_parse(temp[index : index+lines+1])
        index=index+1+lines
        output.append('Case #'+str(test_case+1)+': '+do_case(parsed_input))
    output_f=open(OUTPUT_FILE_NAME,'w')
    output_f.write('\n'.join(output))
    input_f.close()
    output_f.close()
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var LINES_PARAM : int := 2 ;
    var INPUT_FILE_NAME : String := 'B-large.in' ;
    var OUTPUT_FILE_NAME : String := 'B-large.out' ;
    skip ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation do_case(parsed : OclAny) : OclAny
  pre: true post: true
  activity:
    var n : OclAny := parsed->first()->first() ;
    var c : OclAny := parsed->first()[1+1] ;
    var seat : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ;
    var rider : Sequence := Integer.subrange(0, c-1)->select(i | true)->collect(i | (0)) ;
    for l : parsed->tail() do (    rider[l[1+1] - 1+1] := rider[l[1+1] - 1+1] + 1 ;
    seat[l->first() - 1+1] := seat[l->first() - 1+1] + 1) ;
    var s : (trailer . (name cumsum) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name seat)))))))) ))) :=  ;
    var m : OclAny := (rider)->max() ;
    for i : Integer.subrange(0, n-1) do (    m := Set{m, (s[i+1] + i) div (i + 1)}->max()) ;
    var pr : OclAny := (seat->select(se | true)->collect(se | (Set{0, se - m}->max())))->sum() ;
    return ("" + ((m))) + ' ' + ("" + ((pr)));
  operation do_parse(input : OclAny) : OclAny
  pre: true post: true
  activity:
    return input->select(line | true)->collect(line | (line.rstrip().split(" ")->select(num | true)->collect(num | (("" + ((num)))->toInteger()))));
  operation main()
  pre: true post: true
  activity:
    var input_f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(INPUT_FILE_NAME)) ;
    var output : Sequence := Sequence{} ;
    var num_of_test_cases : int := ("" + ((input_f.readLine(), 10)))->toInteger() ;
    var temp : OclAny := input_f.readlines() ;
    var index : int := 0 ;
    for test_case : Integer.subrange(0, num_of_test_cases-1) do (    var lines : int := ("" + ((temp[index+1].rstrip().split(" ")[LINES_PARAM+1])))->toInteger() ;
    var parsed_input : OclAny := do_parse(temp.subrange(index+1, index + lines + 1)) ;
    index := index + 1 + lines ;
    execute (('Case #' + ("" + ((test_case + 1))) + ': ' + do_case(parsed_input)) : output)) ;
    var output_f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(OUTPUT_FILE_NAME)) ;
    output_f.write(StringLib.sumStringsWithSeparator((output), '
')) ;
    input_f.closeFile() ;
    output_f.closeFile();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a=list(map(int,input().split()))
scores=[0]*(10**5+2)
scores_copy=scores.copy()
n=max(a)
result=0
for i in a :
    scores[i]+=i
scores_copy[1]=scores[1]
for i in range(2,n+1):
    scores_copy[i]=max(scores_copy[i-2]+scores[i],scores_copy[i-1])
print(scores_copy[n])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var scores : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((10)->pow(5) + 2)) ;
    var scores_copy : OclAny := scores->copy() ;
    n := (a)->max() ;
    var result : int := 0 ;
    for i : a do (    scores[i+1] := scores[i+1] + i) ;
    scores_copy[1+1] := scores[1+1] ;
    for i : Integer.subrange(2, n + 1-1) do (    scores_copy[i+1] := Set{scores_copy[i - 2+1] + scores[i+1], scores_copy[i - 1+1]}->max()) ;
    execute (scores_copy[n+1])->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a=list(map(int,input().split(' ')))
d=dict()
d[0]=0
m=max(a)
for i in range(m+1):
    d[i]=0
for i in range(n):
    d[a[i]]+=a[i]
for i in range(2,m+1):
    if(d[i]+d[i-2]toInteger() ;
    var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ;
    var d : Map := (arguments ( )) ;
    d->first() := 0 ;
    var m : OclAny := (a)->max() ;
    for i : Integer.subrange(0, m + 1-1) do (    d[i+1] := 0) ;
    for i : Integer.subrange(0, n-1) do (    d[a[i+1]+1] := d[a[i+1]+1] + a[i+1]) ;
    for i : Integer.subrange(2, m + 1-1) do (    if ((d[i+1] + d[i - 2+1]->compareTo(d[i - 1+1])) < 0) then  (
      d[i+1] := d[i - 1+1]
    )
    else (
      d[i+1] := d[i+1] + d[i - 2+1]
      )) ;
    execute (d[m+1])->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys,threading
sys.setrecursionlimit(1<<30)
from collections import defaultdict
def main():
    n=int(input())
    nums=list(map(int,input().split()))
    count=defaultdict(int)
    for i in nums :
        count[i]+=1
    m=max(nums)
    memo={}
    def choose(num):
        if num>m :
            return 0
        if num not in count :
            count[num]=0
        if num in memo :
            return memo[num]
        memo[num]=max(choose(num+1),num*count[num]+choose(num+2))
        return memo[num]
    print(choose(1))
threading.stack_size(1<<27)
main_thread=threading.Thread(target=main)
main_thread.start()
main_thread.join()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    sys.setrecursionlimit(1 * (2->pow(30))) ;
    skip ;
    skip ;
    threading.stack_size(1 * (2->pow(27))) ;
    var main_thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ;
    main_thread.start() ;
    main_thread.join();
  operation main()
  pre: true post: true
  activity:
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var nums : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var count : OclAny := defaultdict(OclType["int"]) ;
    for i : nums do (    count[i+1] := count[i+1] + 1) ;
    var m : OclAny := (nums)->max() ;
    var memo : OclAny := Set{} ;
    skip ;
    execute (choose(1))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
INPUT=list(map(int,input().split()))
X=INPUT[0]
Y=INPUT[1]
print('{:.0f}'.format(X+Y/2))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var INPUT : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var X : OclAny := INPUT->first() ;
    var Y : OclAny := INPUT[1+1] ;
    execute (StringLib.interpolateStrings('{:.0f}', Sequence{X + Y / 2}))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def nextWord(s):
    if(s==" "):
        return "a"
    i=len(s)-1
    while(s[i]=='z' and i>=0):
        i-=1
    if(i==-1):
        s=s+'a'
    else :
        s=s.replace(s[i],chr(ord(s[i])+1),1)
    return s
if __name__=='__main__' :
    str="samez"
    print(nextWord(str))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      var OclType["String"] : String := "samez" ;
    execute (nextWord(OclType["String"]))->display()
    ) else skip;
  operation nextWord(s : OclAny) : OclAny
  pre: true post: true
  activity:
    if (s = " ") then (
      return "a"
    ) else skip ;
    var i : double := (s)->size() - 1 ;
    while (s[i+1] = 'z' & i >= 0) do (    i := i - 1) ;
    if (i = -1) then  (
      s := s + 'a'
    )
    else (
      s := s.replace(s[i+1], ((s[i+1])->char2byte() + 1)->byte2char(), 1)
      ) ;
    return s;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def getsum(a):
    r=0
    sum=0
    while(a>0):
        r=a % 10
        sum=sum+r
        a=a//10
    return sum
def value(a,b,c):
    x=0
    q=0
    w=0
    v=[]
    for i in range(1,82):
        no=pow(i,a)
        no=b*no+c
        if(no>0 and no<1000000000):
            x=getsum(no)
            if(x==i):
                q+=1
                v.append(no)
                w+=1
    for i in range(len(v)):
        print(v[i],end=" ")
if __name__=="__main__" :
    a=2
    b=2
    c=-1
    value(a,b,c)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      a := 2 ;
    b := 2 ;
    c := -1 ;
    value(a, b, c)
    ) else skip;
  operation getsum(a : OclAny) : OclAny
  pre: true post: true
  activity:
    var r : int := 0 ;
    var sum : int := 0 ;
    while (a > 0) do (    r := a mod 10 ;
    sum := sum + r ;
    a := a div 10) ;
    return sum;
  operation value(a : OclAny, b : OclAny, c : OclAny)
  pre: true post: true
  activity:
    var x : int := 0 ;
    var q : int := 0 ;
    var w : int := 0 ;
    var v : Sequence := Sequence{} ;
    for i : Integer.subrange(1, 82-1) do (    var no : double := (i)->pow(a) ;
    no := b * no + c ;
    if (no > 0 & no < 1000000000) then (
      x := getsum(no) ;
    if (x = i) then (
      q := q + 1 ;
    execute ((no) : v) ;
    w := w + 1
    ) else skip
    ) else skip) ;
    for i : Integer.subrange(0, (v)->size()-1) do (    execute (v[i+1])->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for test in range(t):
    a,b,n=map(int,input().split())
    num=0
    while a<=n and b<=n :
        if a<=b :
            a+=b
        else :
            b+=a
        num+=1
    print(num)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for test : Integer.subrange(0, t-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    var n : OclAny := null;
    Sequence{a,b,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var num : int := 0 ;
    while (a->compareTo(n)) <= 0 & (b->compareTo(n)) <= 0 do (    if (a->compareTo(b)) <= 0 then  (
      a := a + b
    )
    else (
      b := b + a
      ) ;
    num := num + 1) ;
    execute (num)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def solve(a,b,n):
    operations=0
    while a<=n and b<=n :
        if atoInteger() ;
    var results : Sequence := () ;
    for _anon : Integer.subrange(0, t-1) do (    Sequence{a,b,n} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute ((solve(a, b, n)) : results)) ;
    for result : results do (    execute (result)->display())
    ) else skip;
  operation solve(a : OclAny, b : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var operations : int := 0 ;
    while (a->compareTo(n)) <= 0 & (b->compareTo(n)) <= 0 do (    if (a->compareTo(b)) < 0 then  (
      a := a + b
    )
    else (
      b := b + a
      ) ;
    operations := operations + 1) ;
    return operations;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    x,y,n=map(int,input().split())
    c1=0
    sum1=0
    while sum1<=n :
        if x>y :
            y+=x
            sum1=y
            c1+=1
        else :
            x+=y
            sum1=x
            c1+=1
    print(c1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var x : OclAny := null;
    var y : OclAny := null;
    var n : OclAny := null;
    Sequence{x,y,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var c1 : int := 0 ;
    var sum1 : int := 0 ;
    while (sum1->compareTo(n)) <= 0 do (    if (x->compareTo(y)) > 0 then  (
      y := y + x ;
    sum1 := y ;
    c1 := c1 + 1
    )
    else (
      x := x + y ;
    sum1 := x ;
    c1 := c1 + 1
      )) ;
    execute (c1)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    a,b,n=map(int,input().split())
    c=0
    while a<=n and b<=n :
        if a>b : b+=a
        else : a+=b
        c+=1
    print(c)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    var n : OclAny := null;
    Sequence{a,b,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var c : int := 0 ;
    while (a->compareTo(n)) <= 0 & (b->compareTo(n)) <= 0 do (    if (a->compareTo(b)) > 0 then  (
      b := b + a
    )
    else (
      a := a + b
      ) ;
    c := c + 1) ;
    execute (c)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
numInputs=int(input())
for i in range(numInputs):
    N,C,M=[int(num)for num in input().split(" ")]
    custSeats=[{},{}]
    seatsBought=set()
    for _ in range(M):
        seatNum,custNum=[int(num)for num in input().split(" ")]
        seatsBought.add(seatNum)
        if seatNum in custSeats[custNum-1].keys():
            custSeats[custNum-1][seatNum]+=1
        else :
            custSeats[custNum-1][seatNum]=1
    numTicketsBought=[0,0]
    for custNum in range(2):
        for seatNum in custSeats[custNum].keys():
            numTicketsBought[custNum]+=custSeats[custNum][seatNum]
    larger=max(numTicketsBought)
    smaller=min(numTicketsBought)
    numRides=larger
    numPromotions=0
    for seatNum in seatsBought :
        if seatNum not in custSeats[0].keys()or seatNum not in custSeats[1].keys():
            continue
        if custSeats[0][seatNum]+custSeats[1][seatNum]<=larger :
            continue
        if seatNum==1 :
            numRides=custSeats[0][seatNum]+custSeats[1][seatNum]
        else :
            numPromotions+=custSeats[0][seatNum]+custSeats[1][seatNum]-larger
    print("Case #"+str(i+1)+": "+str(numRides)+" "+str(numPromotions))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var numInputs : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, numInputs-1) do (    var N : OclAny := null;
    var C : OclAny := null;
    var M : OclAny := null;
    Sequence{N,C,M} := input().split(" ")->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ;
    var custSeats : Sequence := Sequence{Set{}}->union(Sequence{ Set{} }) ;
    var seatsBought : Set := Set{}->union(()) ;
    for _anon : Integer.subrange(0, M-1) do (    var seatNum : OclAny := null;
    var custNum : OclAny := null;
    Sequence{seatNum,custNum} := input().split(" ")->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ;
    execute ((seatNum) : seatsBought) ;
    if (custSeats[custNum - 1+1].keys())->includes(seatNum) then  (
      custSeats[custNum - 1+1][seatNum+1] := custSeats[custNum - 1+1][seatNum+1] + 1
    )
    else (
      custSeats[custNum - 1+1][seatNum+1] := 1
      )) ;
    var numTicketsBought : Sequence := Sequence{0}->union(Sequence{ 0 }) ;
    for custNum : Integer.subrange(0, 2-1) do (    for seatNum : custSeats[custNum+1].keys() do (    numTicketsBought[custNum+1] := numTicketsBought[custNum+1] + custSeats[custNum+1][seatNum+1])) ;
    var larger : OclAny := (numTicketsBought)->max() ;
    var smaller : OclAny := (numTicketsBought)->min() ;
    var numRides : OclAny := larger ;
    var numPromotions : int := 0 ;
    for seatNum : seatsBought do (    if (custSeats->first().keys())->excludes(seatNum) or (custSeats[1+1].keys())->excludes(seatNum) then (
      continue
    ) else skip ;
    if (custSeats->first()[seatNum+1] + custSeats[1+1][seatNum+1]->compareTo(larger)) <= 0 then (
      continue
    ) else skip ;
    if seatNum = 1 then  (
      numRides := custSeats->first()[seatNum+1] + custSeats[1+1][seatNum+1]
    )
    else (
      numPromotions := numPromotions + custSeats->first()[seatNum+1] + custSeats[1+1][seatNum+1] - larger
      )) ;
    execute ("Case #" + ("" + ((i + 1))) + ": " + ("" + ((numRides))) + " " + ("" + ((numPromotions))))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def solve():
    a,b,n=map(int,input().split())
    cnt=0
    while max(a,b)<=n :
        if atoInteger()-1) do (    solve());
  operation solve()
  pre: true post: true
  activity:
    var a : OclAny := null;
    var b : OclAny := null;
    var n : OclAny := null;
    Sequence{a,b,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var cnt : int := 0 ;
    while (Set{a, b}->max()->compareTo(n)) <= 0 do (    if (a->compareTo(b)) < 0 then  (
      a := a + b
    )
    else (
      b := b + a
      ) ;
    cnt := cnt + 1) ;
    execute (cnt)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def maxUniqueNum(a,N,M):
    maxUnique=0
    for i in range(N-M):
        s=set()
        for j in range(M):
            s.add(a[i+j])
        if(len(s)>maxUnique):
            maxUnique=len(s)
    return maxUnique
if __name__=='__main__' :
    arr=[5,3,5,2,3,2]
    M=3
    N=len(arr)
    print(maxUniqueNum(arr,N,M))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      var arr : Sequence := Sequence{5}->union(Sequence{3}->union(Sequence{5}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 2 }))))) ;
    M := 3 ;
    N := (arr)->size() ;
    execute (maxUniqueNum(arr, N, M))->display()
    ) else skip;
  operation maxUniqueNum(a : OclAny, N : OclAny, M : OclAny) : OclAny
  pre: true post: true
  activity:
    var maxUnique : int := 0 ;
    for i : Integer.subrange(0, N - M-1) do (    var s : Set := Set{}->union(()) ;
    for j : Integer.subrange(0, M-1) do (    execute ((a[i + j+1]) : s)) ;
    if (((s)->size()->compareTo(maxUnique)) > 0) then (
      maxUnique := (s)->size()
    ) else skip) ;
    return maxUnique;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
ii=lambda : int(input())
mi=lambda : map(int,input().split())
li=lambda : list(map(int,input().split()))
def main():
    a=ii()
    s=input()
    ans=s if a>=3200 else "red"
    print(ans)
main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var ii : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ;
    var mi : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var li : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ;
    skip ;
    main();
  operation main()
  pre: true post: true
  activity:
    var a : OclAny := ii->apply() ;
    var s : String := (OclFile["System.in"]).readLine() ;
    var ans : String := if a >= 3200 then s else "red" endif ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,s=open(0).read().split(); print(["red",s][int(a)>=3200])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var s : OclAny := null;
    Sequence{a,s} := open(0).readAll().split();    execute (Sequence{"red"}->union(Sequence{ s })->select(("" + ((a)))->toInteger() >= 3200))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
x,y=map(int,input().split())
ans=x+(y//2)
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var ans : OclAny := x + (y div 2) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=input("")
s=input("")
b=int(a)
if b>=3200 :
    print(s)
else :
    print("red")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : String := (OclFile["System.in"]).readLine("") ;
    var s : String := (OclFile["System.in"]).readLine("") ;
    var b : int := ("" + ((a)))->toInteger() ;
    if b >= 3200 then  (
      execute (s)->display()
    )
    else (
      execute ("red")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=int(input())
s=input()
print(s if a>=3200 else 'red')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : String := (OclFile["System.in"]).readLine() ;
    execute (if a >= 3200 then s else 'red' endif)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=int(input())
s=input()
if(a<3200):
    print("red")
else :
    print(s)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : String := (OclFile["System.in"]).readLine() ;
    if (a < 3200) then  (
      execute ("red")->display()
    )
    else (
      execute (s)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
if n % 2==1 :
    print(0)
else :
    t=0
    for i in range(1,1000):
        if 5**i<=n :
            t+=(n//(5**i))//2
        else :
            break
    print(t)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n mod 2 = 1 then  (
      execute (0)->display()
    )
    else (
      var t : int := 0 ;
    for i : Integer.subrange(1, 1000-1) do (    if ((5)->pow(i)->compareTo(n)) <= 0 then  (
      t := t + (n div ((5)->pow(i))) div 2
    )
    else (
      break
      )) ;
    execute (t)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
sysread=sys.stdin.buffer.readline
read=sys.stdin.buffer.read
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def run():
    N=int(input())
    if N % 2 :
        print(0)
    else :
        ans=0
        div=10
        while True :
            val=N//div
            ans+=val
            if not val : break
            div*=5
        print(ans)
if __name__=="__main__" :
    run()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var sysread : OclAny := sys.stdin.buffer.readline ;
    var read : OclAny := sys.stdin.buffer.read ;
    skip ;
    sys.setrecursionlimit((10)->pow(7)) ;
    skip ;
    if __name__ = "__main__" then (
      run()
    ) else skip;
  operation run()
  pre: true post: true
  activity:
    var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if N mod 2 then  (
      execute (0)->display()
    )
    else (
      var ans : int := 0 ;
    var div : int := 10 ;
    while true do (    var val : int := N div div ;
    ans := ans + val ;
    if not(val) then (
      break
    ) else skip ;
    div := div * 5) ;
    execute (ans)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from itertools import*
from collections import*
from functools import*
from math import*
T=int(input().strip())
for t in range(T):
    print("Case #{}: ".format(t+1),end="")
    coasterLength,nCustomers,ticketsSold=map(int,input().strip().split(" "))
    tickets=[tuple(map(int,input().strip().split(" ")))for i in range(ticketsSold)]
    customers=list(repeat(0,nCustomers))
    positions=list(repeat(0,coasterLength))
    for position,customer in tickets :
        customers[customer-1]+=1
        positions[position-1]+=1
    lowerBound=max(customers)
    for position,totalTickets in zip(count(1),accumulate(positions)):
        lowerBound=max(ceil(totalTickets/position),lowerBound)
    promotions=sum(max(0,i-lowerBound)for i in positions)
    print("{}{}".format(lowerBound,promotions))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    var T : int := ("" + ((input()->trim())))->toInteger() ;
    for t : Integer.subrange(0, T-1) do (    execute (StringLib.interpolateStrings("Case #{}: ", Sequence{t + 1}))->display() ;
    var coasterLength : OclAny := null;
    var nCustomers : OclAny := null;
    var ticketsSold : OclAny := null;
    Sequence{coasterLength,nCustomers,ticketsSold} := (input()->trim().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ;
    var tickets : Sequence := Integer.subrange(0, ticketsSold-1)->select(i | true)->collect(i | (((input()->trim().split(" "))->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var customers : Sequence := (repeat(0, nCustomers)) ;
    var positions : Sequence := (repeat(0, coasterLength)) ;
    for _tuple : tickets do (var _indx : int := 1;
      var position : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var customer : OclAny := _tuple->at(_indx);
      customers[customer - 1+1] := customers[customer - 1+1] + 1 ;
    positions[position - 1+1] := positions[position - 1+1] + 1) ;
    var lowerBound : OclAny := (customers)->max() ;
    for _tuple : Integer.subrange(1, count(1)->size())->collect( _indx | Sequence{count(1)->at(_indx), accumulate(positions)->at(_indx)} ) do (var _indx : int := 1;
      var position : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var totalTickets : OclAny := _tuple->at(_indx);
      lowerBound := Set{ceil(totalTickets / position), lowerBound}->max()) ;
    var promotions : OclAny := ((argument (test (logical_test (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (name lowerBound))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name positions))))))))->sum() ;
    execute (StringLib.interpolateStrings("{}{}", Sequence{lowerBound, promotions}))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=int(input())
def f(n):
    if n<2 :
        return 1
    return n*f(n-2)
def zeros(n):
    count=0
    cur=n
    while(cur!=0 and cur % 10==0):
        cur=cur//10
        count+=1
    return count
def est(n):
    ev=n//10
    divider=50
    while(n//divider!=0):
        ev+=n//divider
        divider*=5
    return ev
if N % 2==1 :
    print(0)
else :
    print(est(N))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    skip ;
    skip ;
    skip ;
    if N mod 2 = 1 then  (
      execute (0)->display()
    )
    else (
      execute (est(N))->display()
      );
  operation f(n : OclAny) : OclAny
  pre: true post: true
  activity:
    if n < 2 then (
      return 1
    ) else skip ;
    return n * f(n - 2);
  operation zeros(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var count : int := 0 ;
    var cur : OclAny := n ;
    while (cur /= 0 & cur mod 10 = 0) do (    cur := cur div 10 ;
    count := count + 1) ;
    return count;
  operation est(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var ev : int := n div 10 ;
    var divider : int := 50 ;
    while (n div divider /= 0) do (    ev := ev + n div divider ;
    divider := divider * 5) ;
    return ev;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=int(input())
n=0
if not N % 2 :
    s=5
    N=N//2
    while N>=s :
        n+=N//s
        s*=5
print(n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var n : int := 0 ;
    if not(N mod 2) then (
      var s : int := 5 ;
    N := N div 2 ;
    while (N->compareTo(s)) >= 0 do (    n := n + N div s ;
    s := s * 5)
    ) else skip ;
    execute (n)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
if n % 2==1 :
    print(0)
    exit()
cnt=0
i=1
if n % 2==0 :
    while n//(2*(5**i))>0 :
        cnt+=n//(2*(5**i))
        i+=1
print(cnt)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n mod 2 = 1 then (
      execute (0)->display() ;
    exit()
    ) else skip ;
    var cnt : int := 0 ;
    var i : int := 1 ;
    if n mod 2 = 0 then (
      while n div (2 * ((5)->pow(i))) > 0 do (    cnt := cnt + n div (2 * ((5)->pow(i))) ;
    i := i + 1)
    ) else skip ;
    execute (cnt)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=int(input())
for _ in range(N):
    arrLen,div=list(map(int,input().split()))
    arr=list(map(int,input().split()))
    flag=True
    for element in arr :
        if element % div!=0 :
            flag=False
            break
    if flag :
        print(-1)
    elif sum(arr)% div!=0 :
        print(arrLen)
    else :
        firstPointer=0
        secondPointer=arrLen-1
        while arr[firstPointer]% div==0 :
            firstPointer+=1
        while arr[secondPointer]% div==0 :
            secondPointer-=1
        print(max(arrLen-firstPointer-1,secondPointer))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, N-1) do (    var arrLen : OclAny := null;
    var div : OclAny := null;
    Sequence{arrLen,div} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var flag : boolean := true ;
    for element : arr do (    if element mod div /= 0 then (
      flag := false ;
    break
    ) else skip) ;
    if flag then  (
      execute (-1)->display()
    )
    else (if (arr)->sum() mod div /= 0 then
   (
      execute (arrLen)->display()    
)
    else (
      var firstPointer : int := 0 ;
    var secondPointer : double := arrLen - 1 ;
    while arr[firstPointer+1] mod div = 0 do (    firstPointer := firstPointer + 1) ;
    while arr[secondPointer+1] mod div = 0 do (    secondPointer := secondPointer - 1) ;
    execute (Set{arrLen - firstPointer - 1, secondPointer}->max())->display()
      )    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
while t :
    n,m=map(int,input().split())
    arr=list(map(int,input().split()))
    sm=sum(arr)
    mx=-1
    if sm % m :
        print(n)
    else :
        for i in range(n):
            if arr[i]% m :
                mx=max(mx,n-i-1,i)
        print(mx)
    t-=1
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    while t do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var sm : OclAny := (arr)->sum() ;
    var mx : int := -1 ;
    if sm mod m then  (
      execute (n)->display()
    )
    else (
      for i : Integer.subrange(0, n-1) do (    if arr[i+1] mod m then (
      mx := Set{mx, n - i - 1, i}->max()
    ) else skip) ;
    execute (mx)->display()
      ) ;
    t := t - 1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for e in range(t):
    n=int(input())
    c=0
    l1=list(map(int,input().split()))
    for i in range(min(len(l1),21)):
        q=l1[i]
        chk=0
        for i in range(2,i+3):
            if(q % i!=0):
                chk=1
                break
        if(chk==1):
            continue
        else :
            c=1
            break
    if(c==0):
        print('YES')
    else :
        print('NO')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for e : Integer.subrange(0, t-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var c : int := 0 ;
    var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    for i : Integer.subrange(0, Set{(l1)->size(), 21}->min()-1) do (    var q : OclAny := l1[i+1] ;
    var chk : int := 0 ;
    for i : Integer.subrange(2, i + 3-1) do (    if (q mod i /= 0) then (
      chk := 1 ;
    break
    ) else skip) ;
    if (chk = 1) then  (
      continue
    )
    else (
      c := 1 ;
    break
      )) ;
    if (c = 0) then  (
      execute ('YES')->display()
    )
    else (
      execute ('NO')->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for k in range(t):
    n,x=map(int,input().split())
    lst=list(map(int,input().split()))
    m=-1
    sum=0
    for i in range(n):
        sum+=lst[i]
        if(sum % x):
            m=max(m,max(len(lst)-(i+1),i+1))
    print(m)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for k : Integer.subrange(0, t-1) do (    var n : OclAny := null;
    var x : OclAny := null;
    Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var m : int := -1 ;
    var sum : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    sum := sum + lst[i+1] ;
    if (sum mod x) then (
      m := Set{m, Set{(lst)->size() - (i + 1), i + 1}->max()}->max()
    ) else skip) ;
    execute (m)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import os,sys,io,math
from array import array
from math import*
I=lambda :[*map(int,sys.stdin.readline().split())]
IS=lambda : input()
IN=lambda : int(input())
IF=lambda : float(input())
for _ in range(IN()):
    n,k=map(int,input().split())
    l=I()
    s=sum(l)
    res=0
    if s % k : res=n
    else :
        res=0
        t=s
        c=n
        for i in l :
            t-=i
            c-=1
            if t % k :
                res=max(res,c)
                break
        t=s
        c=n
        for i in reversed(l):
            t-=i
            c-=1
            if t % k :
                res=max(res,c)
                break
    if not res : res=-1
    print(res)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    var I : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var IS : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ;
    var IN : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ;
    var IF : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toReal()) ;
    for _anon : Integer.subrange(0, IN->apply()-1) do (    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var l : OclAny := I->apply() ;
    var s : OclAny := (l)->sum() ;
    var res : int := 0 ;
    if s mod k then  (
      res := n
    )
    else (
      res := 0 ;
    var t : OclAny := s ;
    var c : OclAny := n ;
    for i : l do (    t := t - i ;
    c := c - 1 ;
    if t mod k then (
      res := Set{res, c}->max() ;
    break
    ) else skip) ;
    t := s ;
    c := n ;
    for i : (l)->reverse() do (    t := t - i ;
    c := c - 1 ;
    if t mod k then (
      res := Set{res, c}->max() ;
    break
    ) else skip)
      ) ;
    if not(res) then (
      res := -1
    ) else skip ;
    execute (res)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=int(input())
for _ in range(N):
    arrLen,div=list(map(int,input().split()))
    arr=list(map(int,input().split()))
    flag=True
    for element in arr :
        if element % div!=0 :
            flag=False
            break
    if flag :
        print(-1)
    elif sum(arr)% div!=0 :
        print(arrLen)
    else :
        firstPointer=0
        secondPointer=arrLen-1
        while arr[firstPointer]% div==0 :
            firstPointer+=1
        while arr[secondPointer]% div==0 :
            secondPointer-=1
        print(max(arrLen-firstPointer-1,secondPointer))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, N-1) do (    var arrLen : OclAny := null;
    var div : OclAny := null;
    Sequence{arrLen,div} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var flag : boolean := true ;
    for element : arr do (    if element mod div /= 0 then (
      flag := false ;
    break
    ) else skip) ;
    if flag then  (
      execute (-1)->display()
    )
    else (if (arr)->sum() mod div /= 0 then
   (
      execute (arrLen)->display()    
)
    else (
      var firstPointer : int := 0 ;
    var secondPointer : double := arrLen - 1 ;
    while arr[firstPointer+1] mod div = 0 do (    firstPointer := firstPointer + 1) ;
    while arr[secondPointer+1] mod div = 0 do (    secondPointer := secondPointer - 1) ;
    execute (Set{arrLen - firstPointer - 1, secondPointer}->max())->display()
      )    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
s=[list(input())for i in range(n)]
s+=s
def ok(array):
    for i in range(1,n):
        for j in range(i):
            if array[i][j]!=array[j][i]:
                return False
    return True
ans=0
for i in range(n):
    if ok(s[i : i+n]):
        ans+=n
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((OclFile["System.in"]).readLine())->characters())) ;
    s := s + s ;
    skip ;
    var ans : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    if ok(s.subrange(i+1, i + n)) then (
      ans := ans + n
    ) else skip) ;
    execute (ans)->display();
  operation ok(array : OclAny) : OclAny
  pre: true post: true
  activity:
    for i : Integer.subrange(1, n-1) do (    for j : Integer.subrange(0, i-1) do (    if array[i+1][j+1] /= array[j+1][i+1] then (
      return false
    ) else skip)) ;
    return true;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
n=int(input())
x=1
while math.log2(n)% 1 :
    x+=1
    n-=2**(int(math.log2(n)))
print(x)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var x : int := 1 ;
    while  mod 1 do (    x := x + 1 ;
    n := n - (2)->pow((("" + (()))->toInteger()))) ;
    execute (x)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input=sys.stdin.readline
sys.setrecursionlimit(1000000)
mod=10**9+7
def read_values(): return map(int,input().split())
def read_index(): return map(lambda x : int(x)-1,input().split())
def read_list(): return list(read_values())
def read_lists(N): return[read_list()for n in range(N)]
def main():
    N=int(input())
    S=[input().strip()for _ in range(N)]
    print(sum(N if all(S[(i-a)% N][j]==S[(j-a)% N][i]for i in range(N)for j in range(N))else 0 for a in range(N)))
if __name__=="__main__" :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    sys.setrecursionlimit(1000000) ;
    var mod : double := (10)->pow(9) + 7 ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      main()
    ) else skip;
  operation read_values() : OclAny
  pre: true post: true
  activity:
    return (input().split())->collect( _x | (OclType["int"])->apply(_x) );
  operation read_index() : OclAny
  pre: true post: true
  activity:
    return (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) );
  operation read_list() : OclAny
  pre: true post: true
  activity:
    return (read_values());
  operation read_lists(N : OclAny) : OclAny
  pre: true post: true
  activity:
    return Integer.subrange(0, N-1)->select(n | true)->collect(n | (read_list()));
  operation main()
  pre: true post: true
  activity:
    N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var S : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (input()->trim())) ;
    execute (((argument (test (logical_test (comparison (expr (atom (name N))))) if (logical_test (comparison (expr (atom (name all)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (comparison (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (name a)))))))) ))) % (expr (atom (name N))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) == (comparison (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name j))) - (expr (atom (name a)))))))) ))) % (expr (atom (name N))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) ))))))))))) )))))) else (test (logical_test (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))))->sum())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def examA():
    N=I()
    A=LI()
    d=defaultdict(int)
    d[0]=1 ; cur=0
    for i in A :
        cur+=i
        d[cur]+=1
    ans=0
    for i in d.values():
        ans+=i*(i-1)//2
    print(ans)
    return
def examB():
    N=I()
    S=[SI()for _ in range(N)]
    cur=0
    for k in range(N):
        flag=True
        for i in range(N):
            for j in range(i+1,N):
                if S[i][j-k]!=S[j][i-k]:
                    flag=False
                    break
            if not flag :
                break
        if flag :
            cur+=1
    ans=cur*N
    print(ans)
    return
import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod=10**9+7
inf=float('inf')
if __name__=='__main__' :
    examB()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var mod : double := (10)->pow(9) + 7 ;
    var Math_PINFINITY : double := ("" + (('inf')))->toReal() ;
    if __name__ = '__main__' then (
      examB()
    ) else skip;
  operation examA()
  pre: true post: true
  activity:
    var N : OclAny := I() ;
    var A : OclAny := LI() ;
    var d : OclAny := defaultdict(OclType["int"]) ;
    d->first() := 1;    var cur : int := 0 ;
    for i : A do (    cur := cur + i ;
    d[cur+1] := d[cur+1] + 1) ;
    var ans : int := 0 ;
    for i : d.values() do (    ans := ans + i * (i - 1) div 2) ;
    execute (ans)->display() ;
    return;
  operation examB()
  pre: true post: true
  activity:
    N := I() ;
    var S : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (SI())) ;
    cur := 0 ;
    for k : Integer.subrange(0, N-1) do (    var flag : boolean := true ;
    for i : Integer.subrange(0, N-1) do (    for j : Integer.subrange(i + 1, N-1) do (    if S[i+1][j - k+1] /= S[j+1][i - k+1] then (
      flag := false ;
    break
    ) else skip) ;
    if not(flag) then (
      break
    ) else skip) ;
    if flag then (
      cur := cur + 1
    ) else skip) ;
    ans := cur * N ;
    execute (ans)->display() ;
    return;
  operation I() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation LI() : OclAny
  pre: true post: true
  activity:
    return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ));
  operation LSI() : OclAny
  pre: true post: true
  activity:
    return ((sys.stdin.readLine().split())->collect( _x | (OclType["String"])->apply(_x) ));
  operation LS() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine().split();
  operation SI() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine()->trim();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
I,R=input,range
n=int(I())
s=[I()for i in R(n)]
a=0
for i in R(n):
    if all(s[(i+j)% n][k]==s[(i+k)% n][j]for j in R(n)for k in R(j+1,n)): a+=n
print(a)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var I : OclAny := null;
    var R : OclAny := null;
    Sequence{I,R} := Sequence{input,range} ;
    var n : int := ("" + ((I())))->toInteger() ;
    var s : Sequence := R(n)->select(i | true)->collect(i | (I())) ;
    var a : int := 0 ;
    for i : R(n) do (    if ((argument (test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name j)))))))) ))) % (expr (atom (name n))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])))) == (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name k)))))))) ))) % (expr (atom (name n))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name R)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name k)))) in (logical_test (comparison (expr (atom (name R)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))))->forAll( _x | _x = true ) then (
      a := a + n
    ) else skip) ;
    execute (a)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    import sys
    input=sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter,deque
    from collections import defaultdict
    from itertools import combinations,permutations,accumulate,groupby,product
    from bisect import bisect_left,bisect_right
    from heapq import heapify,heappop,heappush
    from math import floor,ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int,input().split())
    def LI(): return list(map(int,input().split()))
    def LI2(): return[int(input())for i in range(n)]
    def MXI(): return[[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf=10**17
    mod=10**9+7
    n=I()
    S=[SI()for i in range(n)]
    ans=0
    if n==1 :
        print(1)
        sys.exit()
    st=n*(n-1)//2
    for b in range(n):
        count=0
        for i in range(n-1):
            for j in range(i+1,n):
                if S[i][(j+b)% n]==S[j][(i+b)% n]:
                    count+=1
            if count==st :
                ans+=n
    print(ans)
if __name__=="__main__" :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    sys.setrecursionlimit((10)->pow(7)) ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var Math_PINFINITY : double := (10)->pow(17) ;
    var mod : double := (10)->pow(9) + 7 ;
    var n : OclAny := I() ;
    var S : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (SI())) ;
    var ans : int := 0 ;
    if n = 1 then (
      execute (1)->display() ;
    sys.exit()
    ) else skip ;
    var st : int := n * (n - 1) div 2 ;
    for b : Integer.subrange(0, n-1) do (    var count : int := 0 ;
    for i : Integer.subrange(0, n - 1-1) do (    for j : Integer.subrange(i + 1, n-1) do (    if S[i+1][(j + b) mod n+1] = S[j+1][(i + b) mod n+1] then (
      count := count + 1
    ) else skip) ;
    if count = st then (
      ans := ans + n
    ) else skip)) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def toggle(n):
    temp=1
    while(temp<=n):
        n=n ^ temp
        temp=temp<<1
    return n
n=10
n=toggle(n)
print(n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    n := 10 ;
    n := toggle(n) ;
    execute (n)->display();
  operation toggle(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var temp : int := 1 ;
    while ((temp->compareTo(n)) <= 0) do (    n := MathLib.bitwiseXor(n, temp) ;
    temp := temp * (2->pow(1))) ;
    return n;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
BitCount=[0]*10000
def fillSetBitsmatrix(arr : list,n : int):
    global BitCount
    for i in range(32):
        for j in range(n):
            temp=arr[j]>>i
            if temp % 2!=0 :
                BitCount[j]+=1
    for i in range(1,n):
        BitCount[i]+=BitCount[i-1]
def Query(Q : list,q : int):
    for i in range(q):
        print(BitCount[Q[i][1]]-BitCount[Q[i][0]-1])
if __name__=="__main__" :
    Arr=[1,5,6,10,9,4,67]
    n=len(Arr)
    fillSetBitsmatrix(Arr,n)
    q=2
    Q=[(1,5),(2,6)]
    Query(Q,q)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  attribute BitCount : OclAny;
  operation initialise()
  pre: true post: true
  activity:     var BitCount : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10000) ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      var Arr : Sequence := Sequence{1}->union(Sequence{5}->union(Sequence{6}->union(Sequence{10}->union(Sequence{9}->union(Sequence{4}->union(Sequence{ 67 })))))) ;
    var n : int := (Arr)->size() ;
    fillSetBitsmatrix(Arr, n) ;
    var q : int := 2 ;
    var Q : Sequence := Sequence{Sequence{1, 5}}->union(Sequence{ Sequence{2, 6} }) ;
    Query(Q, q)
    ) else skip;
  operation fillSetBitsmatrix(arr : Sequence(OclAny), n : int)
  pre: true post: true
  activity:
    skip ;
    for i : Integer.subrange(0, 32-1) do (    for j : Integer.subrange(0, n-1) do (    var temp : int := arr[j+1] /(2->pow(i)) ;
    if temp mod 2 /= 0 then (
      BitCount[j+1] := BitCount[j+1] + 1
    ) else skip)) ;
    for i : Integer.subrange(1, n-1) do (    BitCount[i+1] := BitCount[i+1] + BitCount[i - 1+1]);
  operation Query(Q : Sequence(OclAny), q : int)
  pre: true post: true
  activity:
    for i : Integer.subrange(0, q-1) do (    execute (BitCount[Q[i+1][1+1]+1] - BitCount[Q[i+1]->first() - 1+1])->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
import math
def input(): return sys.stdin.readline().strip()
def iinput(): return int(input())
def rinput(): return map(int,sys.stdin.readline().strip().split())
def get_list(): return list(map(int,sys.stdin.readline().strip().split()))
mod=int(1e9)+7
x1,y1,r1=rinput()
x2,y2,r2=rinput()
d=math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))-r1-r2
r=d/2
f=-(r+min(r1,r2))
if r>=0 :
    print(r)
elif f>=0 :
    print(f)
else :
    print(0)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var mod : int := ("" + ((("1e9")->toReal())))->toInteger() + 7 ;
    var x1 : OclAny := null;
    var y1 : OclAny := null;
    var r1 : OclAny := null;
    Sequence{x1,y1,r1} := rinput() ;
    var x2 : OclAny := null;
    var y2 : OclAny := null;
    var r2 : OclAny := null;
    Sequence{x2,y2,r2} := rinput() ;
    var d : double := ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))->sqrt() - r1 - r2 ;
    var r : double := d / 2 ;
    var f : OclAny := -(r + Set{r1, r2}->min()) ;
    if r >= 0 then  (
      execute (r)->display()
    )
    else (if f >= 0 then
   (
      execute (f)->display()    
)
    else (
      execute (0)->display()
      )    )
;
  operation input() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine()->trim();
  operation iinput() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation rinput() : OclAny
  pre: true post: true
  activity:
    return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) );
  operation get_list() : OclAny
  pre: true post: true
  activity:
    return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
def main_function():
    test_cases=range(int(input()))
    for test_case in test_cases :
        n=int(input())
        a=[int(u)for u in input().split(" ")]
        ans_not_found=True
        counter=[-1 for i in range(len(a))]
        for i in range(len(a)):
            real_counter=0
            targ_i=i+2
            while targ_i>0 and a[i]% targ_i==0 :
                real_counter+=1
                targ_i-=1
            if targ_i>0 :
                counter[i]=real_counter
        if-1 in counter :
            print("NO")
        else :
            print("YES")
if __name__=='__main__' :
    main_function()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = '__main__' then (
      main_function()
    ) else skip;
  operation main_function()
  pre: true post: true
  activity:
    var test_cases : Sequence := Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) ;
    for test_case : test_cases do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := input().split(" ")->select(u | true)->collect(u | (("" + ((u)))->toInteger())) ;
    var ans_not_found : boolean := true ;
    var counter : Sequence := Integer.subrange(0, (a)->size()-1)->select(i | true)->collect(i | (-1)) ;
    for i : Integer.subrange(0, (a)->size()-1) do (    var real_counter : int := 0 ;
    var targ_i : OclAny := i + 2 ;
    while targ_i > 0 & a[i+1] mod targ_i = 0 do (    real_counter := real_counter + 1 ;
    targ_i := targ_i - 1) ;
    if targ_i > 0 then (
      counter[i+1] := real_counter
    ) else skip) ;
    if (counter)->includes(-1) then  (
      execute ("NO")->display()
    )
    else (
      execute ("YES")->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import*
def longestRodInCuboid(length,breadth,height):
    temp=length*length+breadth*breadth+height*height
    result=sqrt(temp)
    return result
if __name__=="__main__" :
    length,breadth,height=12,9,8
    print(longestRodInCuboid(length,breadth,height))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      Sequence{length,breadth,height} := Sequence{12,9,8} ;
    execute (longestRodInCuboid(length, breadth, height))->display()
    ) else skip;
  operation longestRodInCuboid(length : OclAny, breadth : OclAny, height : OclAny) : OclAny
  pre: true post: true
  activity:
    var temp : double := length * length + breadth * breadth + height * height ;
    var result : OclAny := sqrt(temp) ;
    return result;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def printPattern(r):
    r=r//2
    count=r
    for i in range(r):
        for j in range(r,i,-1):
            if j!=r :
                print("*"+str(count),end="")
            else :
                print(count,end="")
        count-=1
        print()
    count+=1
    for i in range(r):
        for j in range(i+1):
            if j!=0 :
                print("*"+str(count),end="")
            else :
                print(count,end="")
        count+=1
        print()
if __name__=="__main__" :
    n=6
    printPattern(n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      var n : int := 6 ;
    printPattern(n)
    ) else skip;
  operation printPattern(r : OclAny)
  pre: true post: true
  activity:
    r := r div 2 ;
    var count : OclAny := r ;
    for i : Integer.subrange(0, r-1) do (    for j : Integer.subrange(i + 1, r)->reverse() do (    if j /= r then  (
      execute ("*" + ("" + ((count))))->display()
    )
    else (
      execute (count)->display()
      )) ;
    count := count - 1 ;
    execute (->display()) ;
    count := count + 1 ;
    for i : Integer.subrange(0, r-1) do (    for j : Integer.subrange(0, i + 1-1) do (    if j /= 0 then  (
      execute ("*" + ("" + ((count))))->display()
    )
    else (
      execute (count)->display()
      )) ;
    count := count + 1 ;
    execute (->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def qu(x):
    n=0
    while 1 :
        a=0
        while 1 :
            if 2**a>x :
                a-=1
                break
            a+=1
        x-=2**a
        n+=1
        if x==0 :
            return n
print(qu(int(input())))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    execute (qu(("" + (((OclFile["System.in"]).readLine())))->toInteger()))->display();
  operation qu(x : OclAny) : OclAny
  pre: true post: true
  activity:
    var n : int := 0 ;
    while 1 do (    var a : int := 0 ;
    while 1 do (    if ((2)->pow(a)->compareTo(x)) > 0 then (
      a := a - 1 ;
    break
    ) else skip ;
    a := a + 1) ;
    x := x - (2)->pow(a) ;
    n := n + 1 ;
    if x = 0 then (
      return n
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def fact(n):
    result=1
    for i in range(1,n+1):
        result*=i
    return result
def getResult(string,ch):
    has=[0]*26
    for i in range(len(string)):
        has[ord(string[i])-ord('A')]+=1
    particular=has[ord(ch)-ord('A')]
    if particular==0 :
        return 0
    has[ord(ch)-ord('A')]=0
    total=len(string)
    total=total-particular+1
    result=fact(total)
    for i in range(26):
        if has[i]>1 :
            result/=fact(has[i])
    return result
if __name__=="__main__" :
    string="MISSISSIPPI"
    print(getResult(string,'S'))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      string := "MISSISSIPPI" ;
    execute (getResult(string, 'S'))->display()
    ) else skip;
  operation fact(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var result : int := 1 ;
    for i : Integer.subrange(1, n + 1-1) do (    result := result * i) ;
    return result;
  operation getResult(string : OclAny, ch : OclAny) : OclAny
  pre: true post: true
  activity:
    var has : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ;
    for i : Integer.subrange(0, (string)->size()-1) do (    has[(string[i+1])->char2byte() - ('A')->char2byte()+1] := has[(string[i+1])->char2byte() - ('A')->char2byte()+1] + 1) ;
    var particular : OclAny := has[(ch)->char2byte() - ('A')->char2byte()+1] ;
    if particular = 0 then (
      return 0
    ) else skip ;
    has[(ch)->char2byte() - ('A')->char2byte()+1] := 0 ;
    var total : int := (string)->size() ;
    total := total - particular + 1 ;
    result := fact(total) ;
    for i : Integer.subrange(0, 26-1) do (    if has[i+1] > 1 then (
      result := result / fact(has[i+1])
    ) else skip) ;
    return result;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def wordReverse(str):
    i=len(str)-1
    start=end=i+1
    result=''
    while i>=0 :
        if str[i]==' ' :
            start=i+1
            while start!=end :
                result+=str[start]
                start+=1
            result+=' '
            end=i
        i-=1
    start=0
    while start!=end :
        result+=str[start]
        start+=1
    return result
str='I AM A GEEK'
print(wordReverse(str))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    OclType["String"] := 'I AM A GEEK' ;
    execute (wordReverse(OclType["String"]))->display();
  operation wordReverse(OclType["String"] : OclAny) : OclAny
  pre: true post: true
  activity:
    var i : double := (OclType["String"])->size() - 1 ;
    var start : OclAny := i + 1; var end : OclAny := i + 1 ;
    var result : String := '' ;
    while i >= 0 do (    if ("" + ([i+1])) = ' ' then (
      start := i + 1 ;
    while start /= end do (    result := result + ("" + ([start+1])) ;
    start := start + 1) ;
    result := result + ' ' ;
    end := i
    ) else skip ;
    i := i - 1) ;
    start := 0 ;
    while start /= end do (    result := result + ("" + ([start+1])) ;
    start := start + 1) ;
    return result;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    x,y=map(int,input().split())
    if x % 2!=y % 2 : print(-1)
    elif x==0 and y==0 : print(0)
    elif x==y : print(1)
    else : print(2)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if x mod 2 /= y mod 2 then  (
      execute (-1)->display()
    )
    else (if x = 0 & y = 0 then
   (
      execute (0)->display()    
)
    else (if x = y then
   (
      execute (1)->display()    
)
    else (
      execute (2)->display()
      )    )
    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
def solve():
    c,d=map(int,input().split())
    if c==d :
        return 0 if c==0 else 1
    elif(c+d)% 2==0 :
        return 2
    else :
        return-1
for _ in range(int(input())):
    print(solve())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    skip ;
    for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    execute (solve())->display());
  operation solve() : OclAny
  pre: true post: true
  activity:
    var c : OclAny := null;
    var d : OclAny := null;
    Sequence{c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if c = d then  (
      return if c = 0 then 0 else 1 endif
    )
    else (if (c + d) mod 2 = 0 then
   (
      return 2    
)
    else (
      return -1
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    a,b=map(int,input().split())
    if a==b==0 :
        print(0)
    elif a==b :
        print(1)
    elif(max(a,b)-min(a,b))% 2==0 :
        print(2)
    else :
        print(-1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if a = b & (b == 0) then  (
      execute (0)->display()
    )
    else (if a = b then
   (
      execute (1)->display()    
)
    else (if (Set{a, b}->max() - Set{a, b}->min()) mod 2 = 0 then
   (
      execute (2)->display()    
)
    else (
      execute (-1)->display()
      )    )
    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for _ in range(t):
    b,c=map(int,input().split())
    if(b+c)% 2==0 :
        if b==c :
            if b!=0 :
                print(1)
            else :
                print(0)
        else :
            print(2)
    else :
        print(-1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, t-1) do (    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if (b + c) mod 2 = 0 then  (
      if b = c then  (
      if b /= 0 then  (
      execute (1)->display()
    )
    else (
      execute (0)->display()
      )
    )
    else (
      execute (2)->display()
      )
    )
    else (
      execute (-1)->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    a,b=list(map(int,input().split()))
    if[a,b]==[0,0]:
        print(0)
    elif a==b :
        print(1)
    elif abs(a-b)% 2==0 :
        print(2)
    elif b==0 and(a % 2)==0 :
        print(1)
    elif a==0 and(b % 2)==0 :
        print(1)
    else :
        print(-1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if Sequence{a}->union(Sequence{ b }) = Sequence{0}->union(Sequence{ 0 }) then  (
      execute (0)->display()
    )
    else (if a = b then
   (
      execute (1)->display()    
)
    else (if (a - b)->abs() mod 2 = 0 then
   (
      execute (2)->display()    
)
    else (if b = 0 & (a mod 2) = 0 then
   (
      execute (1)->display()    
)
    else (if a = 0 & (b mod 2) = 0 then
   (
      execute (1)->display()    
)
    else (
      execute (-1)->display()
      )    )
    )
    )
    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import eulerlib
def compute():
    n=600851475143
    while True :
        p=smallest_prime_factor(n)
        if p=2
    for i in range(2,eulerlib.sqrt(n)+1):
        if n % i==0 :
            return i
    return n
if __name__=="__main__" :
    print(compute())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      execute (compute())->display()
    ) else skip;
  operation compute() : OclAny
  pre: true post: true
  activity:
    var n : int := 600851475143 ;
    while true do (    var p : OclAny := smallest_prime_factor(n) ;
    if (p->compareTo(n)) < 0 then  (
      n := n div p
    )
    else (
      return ("" + ((n)))
      ));
  operation smallest_prime_factor(n : OclAny) : OclAny
  pre: true post: true
  activity:
    assert n >= 2 do "assertion failed" ;
    for i : Integer.subrange(2, eulerlib.sqrt(n) + 1-1) do (    if n mod i = 0 then (
      return i
    ) else skip) ;
    return n;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for s in[*open(0)][2 : : 2]: print('NYOE S'[all(any(int(x)% j for j in range(2,i))for i,x in enumerate(s.split(),3)): : 2])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do (    execute ('NYOE S'(subscript (test (logical_test (comparison (expr (atom (name all)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name any)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) % (expr (atom (name j))))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer . (name split) (arguments ( )))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 3))))))))) ))))))))) ))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def maxBitElement(arr,n):
    num=0
    max=-1
    for i in range(n):
        cnt=bin(arr[i]).count('1')
        if(cnt>max):
            max=cnt
            num=arr[i]
    return num
if __name__=='__main__' :
    arr=[3,2,4,7,1,10,5,8,9,6]
    n=len(arr)
    print(maxBitElement(arr,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      arr := Sequence{3}->union(Sequence{2}->union(Sequence{4}->union(Sequence{7}->union(Sequence{1}->union(Sequence{10}->union(Sequence{5}->union(Sequence{8}->union(Sequence{9}->union(Sequence{ 6 }))))))))) ;
    n := (arr)->size() ;
    execute (maxBitElement(arr, n))->display()
    ) else skip;
  operation maxBitElement(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var num : int := 0 ;
    var max : int := -1 ;
    for i : Integer.subrange(0, n-1) do (    var cnt : OclAny := bin(arr[i+1])->count('1') ;
    if ((cnt->compareTo(max)) > 0) then (
      max := cnt ;
    num := arr[i+1]
    ) else skip) ;
    return num;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=int(input())
count=0
while a!=0 :
    count+=a % 2
    a=a//2
print(count)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var count : int := 0 ;
    while a /= 0 do (    count := count + a mod 2 ;
    a := a div 2) ;
    execute (count)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def maxLengthArr(x,y):
    ex=[0]*(1<pow(x)))); ;
    ex->first() := 1; ;
    var pre : Sequence := Sequence{ 0 }; ;
    for i : Integer.subrange(1, (1 * (2->pow(x)))-1) do (    if (ex[MathLib.bitwiseXor(i, y)+1]) then (
      continue;
    ) else skip ;
    execute ((i) : pre); ;
    ex[i+1] := 1;) ;
    if ((pre)->size() = 1) then (
      execute ("-1")->display(); ;
    return;
    ) else skip ;
    for i : Integer.subrange(1, (pre)->size()-1) do (    execute (MathLib.bitwiseXor(pre[i+1], pre[i - 1+1]))->display(););
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    n=int(input())
    if n==0 :
        break
    total=[0]*(n+1)
    for i in range(n):
        a=[int(i)for i in input().split()]
        a.append(sum(a))
        for j in range(n+1):
            print("%5d" %(a[j]),end="")
            total[j]+=a[j]
        print()
    for i in range(n+1):
        print("%5d" %(total[i]),end="")
    print()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    var total : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ;
    for i : Integer.subrange(0, n-1) do (    var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    execute (((a)->sum()) : a) ;
    for j : Integer.subrange(0, n + 1-1) do (    execute (StringLib.format("%5d",(a[j+1])))->display() ;
    total[j+1] := total[j+1] + a[j+1]) ;
    execute (->display()) ;
    for i : Integer.subrange(0, n + 1-1) do (    execute (StringLib.format("%5d",(total[i+1])))->display()) ;
    execute (->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def print_row(iterable):
    print(''.join(map(lambda x : str(x).rjust(5),iterable)),str(sum(iterable)).rjust(5),sep='')
while True :
    n=int(input())
    if n==0 :
        break
    m=[]
    for i in range(n):
        m.append(list(map(int,input().split())))
    last=[0 for i in range(n)]
    for row in m :
        print_row(row)
        for(i,e)in enumerate(row):
            last[i]+=e
    print_row(last)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    while true do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    var m : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : m)) ;
    var last : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ;
    for row : m do (    print_row(row) ;
    for Sequence{i, e} : Integer.subrange(1, (row)->size())->collect( _indx | Sequence{_indx-1, (row)->at(_indx)} ) do (    last[i+1] := last[i+1] + e)) ;
    print_row(last));
  operation print_row(iterable : OclAny)
  pre: true post: true
  activity:
    execute (StringLib.sumStringsWithSeparator(((iterable)->collect( _x | (lambda x : OclAny in (OclType["String"](x).rjust(5)))->apply(_x) )), ''))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
while(n!=0):
    nlist=[]
    for i in range(n):
        nn=list(map(int,input().split()))
        nn.append(sum(nn))
        nlist.append(nn)
    lastn=[]
    for i in range(n+1):
        last=0
        for k in range(n):
            last+=nlist[k][i]
        lastn.append(last)
    nlist.append(lastn)
    for i in range(n+1):
        for k in range(n+1):
            nnn=nlist[i][k]
            l=len(str(nnn))
            cn=5-l
            if(k==n):
                print(''*cn+'{}'.format(nnn))
            else :
                print(''*cn+'{}'.format(nnn),end='')
    n=int(input())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    while (n /= 0) do (    var nlist : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    var nn : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute (((nn)->sum()) : nn) ;
    execute ((nn) : nlist)) ;
    var lastn : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n + 1-1) do (    var last : int := 0 ;
    for k : Integer.subrange(0, n-1) do (    last := last + nlist[k+1][i+1]) ;
    execute ((last) : lastn)) ;
    execute ((lastn) : nlist) ;
    for i : Integer.subrange(0, n + 1-1) do (    for k : Integer.subrange(0, n + 1-1) do (    var nnn : OclAny := nlist[i+1][k+1] ;
    var l : int := (("" + ((nnn))))->size() ;
    var cn : double := 5 - l ;
    if (k = n) then  (
      execute (StringLib.nCopies('', cn) + StringLib.interpolateStrings('{}', Sequence{nnn}))->display()
    )
    else (
      execute (StringLib.nCopies('', cn) + StringLib.interpolateStrings('{}', Sequence{nnn}))->display()
      ))) ;
    n := ("" + (((OclFile["System.in"]).readLine())))->toInteger());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
f=lambda v,b : v.append(sum(b))
while True :
    c=input()
    if c==0 : break
    x=range(c)
    z=range(c+1)
    q={}
    for i in x :
        q[i]=map(int,raw_input().split())
        t=q.values()[i]
        f(t,t)
    q[i+1]=[]
    for g in x :
        w=[]
        for j in x :
            w.append(q.values()[j][g])
        f(q[i+1],w)
    t=q[i+1]
    f(t,t)
    for i in q.values():
        for j in z :
            sys.stdout.write("%5d" % i[j])
        print
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var f : Function := lambda v : OclAny, b : OclAny in (v.append((b)->sum())) ;
    while true do (    var c : String := (OclFile["System.in"]).readLine() ;
    if c = 0 then (
      break
    ) else skip ;
    var x : Sequence := Integer.subrange(0, c-1) ;
    var z : Sequence := Integer.subrange(0, c + 1-1) ;
    var q : OclAny := Set{} ;
    for i : x do (    q[i+1] := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var t : OclAny := q.values()[i+1] ;
    f(t, t)) ;
    q[i + 1+1] := Sequence{} ;
    for g : x do (    var w : Sequence := Sequence{} ;
    for j : x do (    execute ((q.values()[j+1][g+1]) : w)) ;
    f(q[i + 1+1], w)) ;
    t := q[i + 1+1] ;
    f(t, t) ;
    for i : q.values() do (    for j : z do ((expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom "%5d")) % (expr (atom (name i)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))))) ))))) ;
));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
import os
for s in sys.stdin :
    n=int(s)
    if n==0 :
        break
    M=[]
    for i in range(n):
        lst=list(map(int,input().split()))
        lst.append(sum(lst))
        M.append(lst)
    last_lst=[]
    for i in range(n+1):
        sumv=0
        for row in M :
            sumv+=row[i]
        last_lst.append(sumv)
    M.append(last_lst)
    for row in M :
        for val in row :
            print(str(val).rjust(5),end='')
        print()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    for s : OclFile["System.in"] do (    var n : int := ("" + ((s)))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    var M : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute (((lst)->sum()) : lst) ;
    execute ((lst) : M)) ;
    var last_lst : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n + 1-1) do (    var sumv : int := 0 ;
    for row : M do (    sumv := sumv + row[i+1]) ;
    execute ((sumv) : last_lst)) ;
    execute ((last_lst) : M) ;
    for row : M do (    for val : row do (    execute (OclType["String"](val).rjust(5))->display()) ;
    execute (->display()));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
f=sys.stdin
d,c=map(int,f.readline().split())
print(d*c)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var f : OclFile := OclFile["System.in"] ;
    var d : OclAny := null;
    var c : OclAny := null;
    Sequence{d,c} := (f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (d * c)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
print(eval(input().replace(" ","*")))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     execute (input().replace(" ", "*"))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys,math,os
PYDEV=os.environ.get('PYDEV')
if PYDEV=="True" :
    sys.stdin=open("sample-input.txt","rt")
c,t=[int(_)for _ in input().split()]
print(c*t)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var PYDEV : OclAny := os.environ.get('PYDEV') ;
    if PYDEV = "True" then (
      OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt"))
    ) else skip ;
    var c : OclAny := null;
    var t : OclAny := null;
    Sequence{c,t} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ;
    execute (c * t)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import bisect
import os,sys,math
from io import BytesIO,IOBase
from collections import defaultdict,deque
ip=lambda : input()
it=lambda : int(input())
ma=lambda : map(int,input().split())
li=lambda : list(map(int,input().split()))
MOD=10**9+7
MD=998244353
mod=100007
MIL=1000000
Inf=float('inf')
ye="YES"
ne="NO"
def lcm(a,b):
    return(a*b)//math.gcd(a,b)
arr=[-1]
l=1
for i in range(2,23):
    z=lcm(l,i)
    arr.append(z)
    l=z
for _ in range(it()):
    n=it()
    a=li()
    ans=ye
    k=min(n,21)
    for i in range(1,k+1):
        if a[i-1]% arr[i]==0 :
            ans=ne
            break
    print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    var ip : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ;
    var it : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ;
    var ma : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var li : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ;
    var MOD : double := (10)->pow(9) + 7 ;
    var MD : int := 998244353 ;
    var mod : int := 100007 ;
    var MIL : int := 1000000 ;
    var Inf : double := ("" + (('inf')))->toReal() ;
    var ye : String := "YES" ;
    var ne : String := "NO" ;
    skip ;
    var arr : Sequence := Sequence{ -1 } ;
    var l : int := 1 ;
    for i : Integer.subrange(2, 23-1) do (    var z : OclAny := lcm(l, i) ;
    execute ((z) : arr) ;
    l := z) ;
    for _anon : Integer.subrange(0, it->apply()-1) do (    var n : OclAny := it->apply() ;
    a := li->apply() ;
    var ans : String := ye ;
    var k : OclAny := Set{n, 21}->min() ;
    for i : Integer.subrange(1, k + 1-1) do (    if a[i - 1+1] mod arr[i+1] = 0 then (
      ans := ne ;
    break
    ) else skip) ;
    execute (ans)->display());
  operation lcm(a : OclAny, b : OclAny) : OclAny
  pre: true post: true
  activity:
    return (a * b) div (a)->gcd(b);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def sum(x):
    n=0
    for i in range(len(x)):
        n+=int(x[i])
    return n
n=int(input())
x=bin(n)[2 :]
x=list(x)
print(sum(x))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    x := bin(n).subrange(2+1) ;
    x := (x) ;
    execute ((x)->sum())->display();
  operation sum(x : OclAny) : OclAny
  pre: true post: true
  activity:
    var n : int := 0 ;
    for i : Integer.subrange(0, (x)->size()-1) do (    n := n + ("" + ((x[i+1])))->toInteger()) ;
    return n;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
if __name__=="__main__" :
    chairs=list(map(int,input().split()))
    print("{0}".format(chairs[0]*chairs[1]))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     if __name__ = "__main__" then (
      var chairs : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute (StringLib.interpolateStrings("{0}", Sequence{chairs->first() * chairs[1+1]}))->display()
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
A,B=map(int,input().split()); print(A*B)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var A : OclAny := null;
    var B : OclAny := null;
    Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) );    execute (A * B)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,k=map(int,input().split())
d=set(input().split())
num=n
while True :
    if len(set(list(str(num)))& d)==0 :
        print(num)
        break
    num+=1
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var d : Set := Set{}->union((input().split())) ;
    var num : OclAny := n ;
    while true do (    if (MathLib.bitwiseAnd(Set{}->union(((("" + ((num))))->characters())), d))->size() = 0 then (
      execute (num)->display() ;
    break
    ) else skip ;
    num := num + 1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
from itertools import product
def input(): return sys.stdin.readline().strip()
def main():
    N,K=map(int,input().split())
    D=set(map(int,input().split()))
    ok=[i for i in range(10)if i not in D]
    l=len(str(N))
    if int(str(ok[-1])*l)=N :
                print(x)
                return
if __name__=="__main__" :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      main()
    ) else skip;
  operation input() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine()->trim();
  operation main()
  pre: true post: true
  activity:
    var N : OclAny := null;
    var K : OclAny := null;
    Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var D : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ;
    var ok : Sequence := Integer.subrange(0, 10-1)->select(i | (D)->excludes(i))->collect(i | (i)) ;
    var l : int := (("" + ((N))))->size() ;
    if (("" + ((("" + ((ok->last()))) * l)))->toInteger()->compareTo(N)) < 0 then  (
      if ok->first() = 0 then  (
      execute (ok[1+1] * (10)->pow(l))->display()
    )
    else (
      execute (("" + ((ok->first()))) * (l + 1))->display()
      )
    )
    else (
      for x : product(ok, (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (name l)))))))) do (    var x : int := ("" + ((StringLib.sumStringsWithSeparator(((x)->collect( _x | (OclType["String"])->apply(_x) )), ""))))->toInteger() ;
    if (x->compareTo(N)) >= 0 then (
      execute (x)->display() ;
    return
    ) else skip)
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import itertools
N,K=map(int,input().split())
D=list(map(int,input().split()))
A=[]
for i in range(10):
    if i not in D :
        A.append(i)
cmin=100000
k=len(str(N))
for i in range(k,6):
    for x in itertools.product(A,repeat=i):
        cnt=0
        for j in range(i):
            cnt+=x[j]*10**(i-1-j)
        if cnt>=N :
            cmin=min(cmin,cnt)
print(cmin)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var N : OclAny := null;
    var K : OclAny := null;
    Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var D : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var A : Sequence := Sequence{} ;
    for i : Integer.subrange(0, 10-1) do (    if (D)->excludes(i) then (
      execute ((i) : A)
    ) else skip) ;
    var cmin : int := 100000 ;
    var k : int := (("" + ((N))))->size() ;
    for i : Integer.subrange(k, 6-1) do (    for x : itertools.product(A, (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (name i)))))))) do (    var cnt : int := 0 ;
    for j : Integer.subrange(0, i-1) do (    cnt := cnt + x[j+1] * (10)->pow((i - 1 - j))) ;
    if (cnt->compareTo(N)) >= 0 then (
      cmin := Set{cmin, cnt}->min()
    ) else skip)) ;
    execute (cmin)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    n,k=map(int,input().split())
    d=set(list(map(str,input().split())))
    checker=1
    while checker :
        if set(list(str(n))).isdisjoint(d):
            print(n)
            checker=0
        else :
            n+=1
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var d : Set := Set{}->union((((input().split())->collect( _x | (OclType["String"])->apply(_x) )))) ;
    var checker : int := 1 ;
    while checker do (    if Set{}->union(((("" + ((n))))->characters()))->intersection(d)->isEmpty() then  (
      execute (n)->display() ;
    checker := 0
    )
    else (
      n := n + 1
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
line1=input()
line2=input()
price,k=line1.split("")
num=line2.split("")
ans=""
for i in range(int(price),100000):
    num2=[str(x)for x in str(i)]
    if len(set(num)& set(num2))==0 :
        print(i)
        break
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var line1 : String := (OclFile["System.in"]).readLine() ;
    var line2 : String := (OclFile["System.in"]).readLine() ;
    var price : OclAny := null;
    var k : OclAny := null;
    Sequence{price,k} := line1.split("") ;
    var num : OclAny := line2.split("") ;
    var ans : String := "" ;
    for i : Integer.subrange(("" + ((price)))->toInteger(), 100000-1) do (    var num2 : Sequence := ("" + ((i)))->select(x | true)->collect(x | (("" + ((x))))) ;
    if (MathLib.bitwiseAnd(Set{}->union((num)), Set{}->union((num2))))->size() = 0 then (
      execute (i)->display() ;
    break
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def bitonic(A,n):
    if(n==0):
        return 0 ;
    maxLen=1 ;
    start=0 ;
    nextStart=0 ;
    j=0 ;
    while(j=A[j+1]):
            if(jA[j+1]):
                nextStart=j+1 ;
            j=j+1 ;
        maxLen=max(maxLen,j-(start-1));
        start=nextStart ;
    return maxLen ;
A=[12,4,78,90,45,23];
n=len(A);
print("Length of max length Bitonic Subarray is",bitonic(A,n));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    A := Sequence{12}->union(Sequence{4}->union(Sequence{78}->union(Sequence{90}->union(Sequence{45}->union(Sequence{ 23 }))))); ;
    n := (A)->size(); ;
    execute ("Length of max length Bitonic Subarray is")->display();;
  operation bitonic(A : OclAny, n : OclAny)
  pre: true post: true
  activity:
    if (n = 0) then (
      return 0;
    ) else skip ;
    var maxLen : int := 1; ;
    var start : int := 0; ;
    var nextStart : int := 0; ;
    var j : int := 0; ;
    while ((j->compareTo(n - 1)) < 0) do (    while ((j->compareTo(n - 1)) < 0 & (A[j+1]->compareTo(A[j + 1+1])) <= 0) do (    j := j + 1;) ;
    while ((j->compareTo(n - 1)) < 0 & (A[j+1]->compareTo(A[j + 1+1])) >= 0) do (    if ((j->compareTo(n - 1)) < 0 & (A[j+1]->compareTo(A[j + 1+1])) > 0) then (
      nextStart := j + 1;
    ) else skip ;
    j := j + 1;) ;
    maxLen := Set{maxLen, j - (start - 1)}->max(); ;
    start := nextStart;) ;
    return maxLen;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def number_of_tower(house,r,n):
    house.sort()
    numOfTower=0
    i=0
    while(iunion(Sequence{2}->union(Sequence{4}->union(Sequence{6}->union(Sequence{5}->union(Sequence{9}->union(Sequence{12}->union(Sequence{ 11 }))))))) ;
    r := 2 ;
    n := (house)->size() ;
    execute (number_of_tower(house, r, n))->display()
    ) else skip;
  operation number_of_tower(house : OclAny, r : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    house := house->sort() ;
    var numOfTower : int := 0 ;
    var i : int := 0 ;
    while ((i->compareTo(n)) < 0) do (    numOfTower := numOfTower + 1 ;
    var loc : OclAny := house[i+1] + r ;
    while ((i->compareTo(n)) < 0 & (house[i+1]->compareTo(loc)) <= 0) do (    i := i + 1) ;
    i := i - 1 ;
    loc := house[i+1] + r ;
    while ((i->compareTo(n)) < 0 & (house[i+1]->compareTo(loc)) <= 0) do (    i := i + 1)) ;
    return numOfTower;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def check(arr,n):
    for i in range(n):
        if arr[i]& 1 :
            return True
    return False
if __name__=='__main__' :
    arr=[3,9,12,13,15]
    n=len(arr)
    if check(arr,n):
        print("Odd Bit-wise OR")
    else :
        print("Even Bit-wise OR")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      arr := Sequence{3}->union(Sequence{9}->union(Sequence{12}->union(Sequence{13}->union(Sequence{ 15 })))) ;
    n := (arr)->size() ;
    if check(arr, n) then  (
      execute ("Odd Bit-wise OR")->display()
    )
    else (
      execute ("Even Bit-wise OR")->display()
      )
    ) else skip;
  operation check(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    for i : Integer.subrange(0, n-1) do (    if MathLib.bitwiseAnd(arr[i+1], 1) then (
      return true
    ) else skip) ;
    return false;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
print(bin(int(input())).count("1"))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     execute (bin(("" + (((OclFile["System.in"]).readLine())))->toInteger())->count("1"))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
for _ in range(int(input())):
    n=int(input())
    w=list(map(int,input().split()))
    if w[0]% 2==0 :
        print('NO')
    else :
        for i in range(1,n):
            for j in range(2,i+3):
                if w[i]% j!=0 :
                    break
            else :
                print('NO')
                break
        else :
            print('YES')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if w->first() mod 2 = 0 then  (
      execute ('NO')->display()
    )
    else (
  (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 3)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) % (expr (atom (name j))))) != (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))))))))))))
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b,x=[int(i)for i in input().split()]
d=a-b
n=max(0,(x-b))//d
ans=x+n*b
print(ans % 1000000007)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    var x : OclAny := null;
    Sequence{a,b,x} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var d : double := a - b ;
    var n : int := Set{0, (x - b)}->max() div d ;
    var ans : OclAny := x + n * b ;
    execute (ans mod 1000000007)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b,x=map(int,input().split())
MOD=int(1e9+7)
if xcollect( _x | (OclType["int"])->apply(_x) ) ;
    var MOD : int := ("" + ((("1e9")->toReal() + 7)))->toInteger() ;
    if (x->compareTo(a)) < 0 then  (
      var res : int := x mod MOD
    )
    else (
      var k : int := (x - b) div (a - b) ;
    res := (x + b * k) ;
    res := res mod MOD
      ) ;
    execute (res)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
A,B,X=map(int,raw_input().split())
def check(n):
    if n==0 :
        return True
    v=X-n*A+n*B
    return v-B>=0
hi=10**16
lo=0
while hi-lo>1 :
    mid=(hi+lo)/2
    if check(mid):
        lo=mid
    else :
        hi=mid
print(X+lo*B)%(10**9+7)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var A : OclAny := null;
    var B : OclAny := null;
    var X : OclAny := null;
    Sequence{A,B,X} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    skip ;
    var hi : double := (10)->pow(16) ;
    var lo : int := 0 ;
    while hi - lo > 1 do (    var mid : double := (hi + lo) / 2 ;
    if check(mid) then  (
      lo := mid
    )
    else (
      hi := mid
      )) ;
(expr (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name X))) + (expr (expr (atom (name lo))) * (expr (atom (name B)))))))))) )))) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (number (integer 10)))) ** (expr (atom (number (integer 9))))) + (expr (atom (number (integer 7))))))))) ))));
  operation check(n : OclAny) : OclAny
  pre: true post: true
  activity:
    if n = 0 then (
      return true
    ) else skip ;
    var v : double := X - n * A + n * B ;
    return v - B >= 0;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b,x=[int(k)for k in input().split()]
if x>=a :
    d=((x-b)//(a-b))*b+x
else :
    d=x
print(d % 1000000007)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    var x : OclAny := null;
    Sequence{a,b,x} := input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger())) ;
    if (x->compareTo(a)) >= 0 then  (
      var d : double := ((x - b) div (a - b)) * b + x
    )
    else (
      d := x
      ) ;
    execute (d mod 1000000007)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def inpl(): return list(map(int,input().split()))
MOD=10**9+7
a,b,x=inpl()
if xpow(9) + 7 ;
    var a : OclAny := null;
    var b : OclAny := null;
    var x : OclAny := null;
    Sequence{a,b,x} := inpl() ;
    if (x->compareTo(a)) < 0 then  (
      execute (x mod MOD)->display()
    )
    else (
      var e : int := (x - b) div (a - b) ;
    execute ((x + e * b) mod MOD)->display()
      );
  operation inpl() : OclAny
  pre: true post: true
  activity:
    return ((input().split())->collect( _x | (OclType["int"])->apply(_x) ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    n=int(input())
    if n==0 :
        break
    lst=[list(map(int,input().split()))for _ in range(n)]
    lp,lq,lr,lc=map(int,input().split())
    flag=True
    for s,p,q,r in lst :
        if p<=lp and q<=lq and r<=lr and 4*p+9*q+4*r<=lc :
            print(s)
            flag=False
    if flag :
        print("NA")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    var lst : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var lp : OclAny := null;
    var lq : OclAny := null;
    var lr : OclAny := null;
    var lc : OclAny := null;
    Sequence{lp,lq,lr,lc} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var flag : boolean := true ;
    for _tuple : lst do (var _indx : int := 1;
      var s : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var p : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var q : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var r : OclAny := _tuple->at(_indx);
      if (p->compareTo(lp)) <= 0 & (q->compareTo(lq)) <= 0 & (r->compareTo(lr)) <= 0 & (4 * p + 9 * q + 4 * r->compareTo(lc)) <= 0 then (
      execute (s)->display() ;
    flag := false
    ) else skip) ;
    if flag then (
      execute ("NA")->display()
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
f=sys.stdin
while True :
    n=int(f.readline())
    if n==0 :
        break
    ipqr=[map(int,f.readline().split())for _ in range(n)]
    pl,ql,rl,cl=map(int,f.readline().split())
    allow=[i for i,p,q,r in ipqr if p<=pl and q<=ql and r<=rl and p*4+q*9+r*4<=cl]
    print('\n'.join(map(str,allow))if len(allow)else 'NA')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var f : OclFile := OclFile["System.in"] ;
    while true do (    var n : int := ("" + ((f.readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    var ipqr : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ;
    var pl : OclAny := null;
    var ql : OclAny := null;
    var rl : OclAny := null;
    var cl : OclAny := null;
    Sequence{pl,ql,rl,cl} := (f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var allow : Sequence := ipqr->select(_tuple | let i : OclAny = _tuple->at(1) in let p : OclAny = _tuple->at(2) in (p->compareTo(pl)) <= 0 & (q->compareTo(ql)) <= 0 & (r->compareTo(rl)) <= 0 & (p * 4 + q * 9 + r * 4->compareTo(cl)) <= 0)->collect(_tuple | let i : OclAny = _tuple->at(1) in let p : OclAny = _tuple->at(2) in (i)) ;
    execute (if (allow)->size() then StringLib.sumStringsWithSeparator(((allow)->collect( _x | (OclType["String"])->apply(_x) )), '
') else 'NA' endif)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while 1 :
    n=int(input())
    count=0
    if n==0 :
        break
    L=[list(map(int,input().split()))for i in range(n+1)]
    for i in range(n):
        if L[i][1]<=L[n][0]and L[i][2]<=L[n][1]and L[i][3]<=L[n][2]and L[i][1]*4+L[i][2]*9+L[i][3]*4<=L[n][3]:
            print(L[i][0])
            count+=1
    if count==0 :
        print("NA")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while 1 do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var count : int := 0 ;
    if n = 0 then (
      break
    ) else skip ;
    var L : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    for i : Integer.subrange(0, n-1) do (    if (L[i+1][1+1]->compareTo(L[n+1]->first())) <= 0 & (L[i+1][2+1]->compareTo(L[n+1][1+1])) <= 0 & (L[i+1][3+1]->compareTo(L[n+1][2+1])) <= 0 & (L[i+1][1+1] * 4 + L[i+1][2+1] * 9 + L[i+1][3+1] * 4->compareTo(L[n+1][3+1])) <= 0 then (
      execute (L[i+1]->first())->display() ;
    count := count + 1
    ) else skip) ;
    if count = 0 then (
      execute ("NA")->display()
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while 1 :
    n=int(input())
    if n==0 : break
    a=[[0]*5 for _ in range(n)]
    for i in range(n):
        a[i][: 4]=map(int,input().split())
        a[i][4]=4*(sum(a[i][1 : 4 : 2]))+9*a[i][2]
    p,q,r,c=map(int,input().split())
    f=1
    for i in range(n):
        if a[i][1]<=p and a[i][2]<=q and a[i][3]<=r and a[i][4]<=c : print(a[i][0]); f=0
    if f : print('NA')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while 1 do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    var a : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 5))) ;
    for i : Integer.subrange(0, n-1) do (    a[i+1].subrange(1,4) := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    a[i+1][4+1] := 4 * ((a[i+1](subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (test (logical_test (comparison (expr (atom (number (integer 4))))))) (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->sum()) + 9 * a[i+1][2+1]) ;
    var p : OclAny := null;
    var q : OclAny := null;
    var r : OclAny := null;
    var c : OclAny := null;
    Sequence{p,q,r,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var f : int := 1 ;
    for i : Integer.subrange(0, n-1) do (    if (a[i+1][1+1]->compareTo(p)) <= 0 & (a[i+1][2+1]->compareTo(q)) <= 0 & (a[i+1][3+1]->compareTo(r)) <= 0 & (a[i+1][4+1]->compareTo(c)) <= 0 then (
      execute (a[i+1]->first())->display();    f := 0
    ) else skip) ;
    if f then (
      execute ('NA')->display()
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
p_speed=int(input())
d_speed=int(input())
time=int(input())
wait=int(input())
distence=int(input())
position_p=time*p_speed
position_d=0
counter=0
time_counter=0
while position_pp_speed :
    time_d=position_p/(d_speed-p_speed)
    position_p+=(time_d*p_speed)
    if position_p>=distence :
        break
    t_back=position_p/d_speed+wait
    position_p+=(t_back*p_speed)
    counter+=1
print(counter)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var p_speed : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var d_speed : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var time : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var wait : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var distence : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var position_p : int := time * p_speed ;
    var position_d : int := 0 ;
    var counter : int := 0 ;
    var time_counter : int := 0 ;
    while (position_p->compareTo(distence)) < 0 & (d_speed->compareTo(p_speed)) > 0 do (    var time_d : double := position_p / (d_speed - p_speed) ;
    position_p := position_p + (time_d * p_speed) ;
    if (position_p->compareTo(distence)) >= 0 then (
      break
    ) else skip ;
    var t_back : double := position_p / d_speed + wait ;
    position_p := position_p + (t_back * p_speed) ;
    counter := counter + 1) ;
    execute (counter)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    n=int(input())
    if n==0 :
        break
    L=[]
    for _ in range(n):
        s,p,q,r=[int(x)for x in input().split()]
        c=p*4+q*9+r*4
        L.append((s,p,q,r,c))
    lp,lq,lr,lc=[int(x)for x in input().split()]
    M=[]
    for s,p,q,r,c in L :
        if p<=lp and q<=lq and r<=lr and c<=lc :
            M.append(s)
    if len(M)>0 :
        print(*M,sep="\n")
    else :
        print("NA")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    var L : Sequence := Sequence{} ;
    for _anon : Integer.subrange(0, n-1) do (    var s : OclAny := null;
    var p : OclAny := null;
    var q : OclAny := null;
    var r : OclAny := null;
    Sequence{s,p,q,r} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    var c : double := p * 4 + q * 9 + r * 4 ;
    execute ((Sequence{s, p, q, r, c}) : L)) ;
    var lp : OclAny := null;
    var lq : OclAny := null;
    var lr : OclAny := null;
    var lc : OclAny := null;
    Sequence{lp,lq,lr,lc} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    var M : Sequence := Sequence{} ;
    for _tuple : L do (var _indx : int := 1;
      var s : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var p : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var q : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var r : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var c : OclAny := _tuple->at(_indx);
      if (p->compareTo(lp)) <= 0 & (q->compareTo(lq)) <= 0 & (r->compareTo(lr)) <= 0 & (c->compareTo(lc)) <= 0 then (
      execute ((s) : M)
    ) else skip) ;
    if (M)->size() > 0 then  (
      execute ((argument * (test (logical_test (comparison (expr (atom (name M))))))))->display()
    )
    else (
      execute ("NA")->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
TOTAL_BITS=32 ;
def isPossible(n):
    cnt=bin(n).count('1');
    if(cnt==TOTAL_BITS//2):
        return True ;
    return False ;
if __name__=="__main__" :
    n=524280 ;
    if(isPossible(n)):
        print("Yes");
    else :
        print("No");
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var TOTAL_BITS : int := 32; ;
    skip ;
    if __name__ = "__main__" then (
      n := 524280; ;
    if (isPossible(n)) then  (
      execute ("Yes")->display();
    )
    else (
      execute ("No")->display();
      )
    ) else skip;
  operation isPossible(n : OclAny)
  pre: true post: true
  activity:
    var cnt : OclAny := bin(n)->count('1'); ;
    if (cnt = TOTAL_BITS div 2) then (
      return true;
    ) else skip ;
    return false;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def printPFsInPairs(n):
    for i in range(1,int(pow(n,1/2))+1):
        if n % i==0 :
            print(str(i)+"*"+str(int(n/i)))
n=24
printPFsInPairs(n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    n := 24 ;
    printPFsInPairs(n);
  operation printPFsInPairs(n : OclAny)
  pre: true post: true
  activity:
    for i : Integer.subrange(1, ("" + (((n)->pow(1 / 2))))->toInteger() + 1-1) do (    if n mod i = 0 then (
      execute (("" + ((i))) + "*" + ("" + ((("" + ((n / i)))->toInteger()))))->display()
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
funcs={'J' : lambda s : s[-1 :]+s[:-1],'C' : lambda s : s[1 :]+s[0],'E' : lambda s : s[(len(s)+1)//2 :]+s[len(s)//2 :(len(s)+1)//2]+s[: len(s)//2],'A' : lambda s : s[: :-1],'P' : lambda s : s.translate(str.maketrans('0123456789','9012345678')),'M' : lambda s : s.translate(str.maketrans('0123456789','1234567890')),}
n=int(input())
for i in range(n):
    s,t=[input().strip()for j in '01']
    for c in s[: :-1]:
        t=funcs[c](t)
    else :
        print(t)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var funcs : Map := Map{ 'J' |-> lambda s : OclAny in (s.subrange(-1+1) + s->front()) }->union(Map{ 'C' |-> lambda s : OclAny in (s->tail() + s->first()) }->union(Map{ 'E' |-> lambda s : OclAny in (s.subrange(((s)->size() + 1) div 2+1) + s.subrange((s)->size() div 2+1, ((s)->size() + 1) div 2) + s.subrange(1,(s)->size() div 2)) }->union(Map{ 'A' |-> lambda s : OclAny in (s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) }->union(Map{ 'P' |-> lambda s : OclAny in (s.translate(("" + (.maketrans('0123456789', '9012345678'))))) }->union((dictorsetmaker (test (logical_test (comparison (expr (atom 'M'))))) : (test lambda (varargslist (vardef_parameters (vardef_parameter (name s)))) : (test (logical_test (comparison (expr (atom (name s)) (trailer . (name translate) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)) (trailer . (name maketrans) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '0123456789')))))) , (argument (test (logical_test (comparison (expr (atom '1234567890'))))))) ))))))))) )))))))) ,)))))) ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, n-1) do (    var s : OclAny := null;
    var t : OclAny := null;
    Sequence{s,t} := '01'->characters()->select(j | true)->collect(j | (input()->trim())) ;
(compound_stmt for (exprlist (expr (atom (name c)))) in (testlist (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name t)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name funcs)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name c)))))))) ])) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) )))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) ))))))))))))))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def C(S):
    return S[1 :]+S[0]
def J(S):
    return S[-1]+S[:-1]
def E(S):
    temp=len(S)//2
    if len(S)% 2==0 :
        S=S[temp :]+S[: temp]
    else :
        S=S[temp+1 :]+S[temp]+S[: temp]
    return S
def A(S):
    return S[: :-1]
def M(S):
    temp=[]
    for s in S :
        if s.isdecimal():
            temp.append("0" if s=="9" else str(int(s)+1))
        else :
            temp.append(s)
    return "".join(temp)
def P(S):
    temp=[]
    for s in S :
        if s.isdecimal():
            temp.append("9" if s=="0" else str(int(s)-1))
        else :
            temp.append(s)
    return "".join(temp)
ans=[]
n=int(input())
for i in range(n):
    messenger=input()
    messenger=messenger[: :-1]
    S=input()
    for m in messenger :
        if m=="J" :
            S=J(S)
        elif m=="C" :
            S=C(S)
        elif m=="E" :
            S=E(S)
        elif m=="A" :
            S=A(S)
        elif m=="P" :
            S=P(S)
        elif m=="M" :
            S=M(S)
    ans.append(S)
for s in ans :
    print(s)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var ans : Sequence := Sequence{} ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, n-1) do (    var messenger : String := (OclFile["System.in"]).readLine() ;
    messenger := messenger(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ;
    S := (OclFile["System.in"]).readLine() ;
    for m : messenger->characters() do (    if m = "J" then  (
      S := J(S)
    )
    else (if m = "C" then
   (
      S := C(S)    
)
    else (if m = "E" then
   (
      S := E(S)    
)
    else (if m = "A" then
   (
      S := A(S)    
)
    else (if m = "P" then
   (
      S := P(S)    
)
    else (if m = "M" then
   (
      S := M(S)    
)
    else skip    )
    )
    )
    )
    )
) ;
    execute ((S) : ans)) ;
    for s : ans do (    execute (s)->display());
  operation C(S : OclAny) : OclAny
  pre: true post: true
  activity:
    return S->tail() + S->first();
  operation J(S : OclAny) : OclAny
  pre: true post: true
  activity:
    return S->last() + S->front();
  operation E(S : OclAny) : OclAny
  pre: true post: true
  activity:
    var temp : int := (S)->size() div 2 ;
    if (S)->size() mod 2 = 0 then  (
      S := S.subrange(temp+1) + S.subrange(1,temp)
    )
    else (
      S := S.subrange(temp + 1+1) + S[temp+1] + S.subrange(1,temp)
      ) ;
    return S;
  operation A(S : OclAny) : OclAny
  pre: true post: true
  activity:
    return S(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))));
  operation M(S : OclAny) : OclAny
  pre: true post: true
  activity:
    temp := Sequence{} ;
    for s : S do (    if s->matches("[0-9]*") then  (
      execute ((if s = "9" then "0" else ("" + ((("" + ((s)))->toInteger() + 1))) endif) : temp)
    )
    else (
      execute ((s) : temp)
      )) ;
    return StringLib.sumStringsWithSeparator((temp), "");
  operation P(S : OclAny) : OclAny
  pre: true post: true
  activity:
    temp := Sequence{} ;
    for s : S do (    if s->matches("[0-9]*") then  (
      execute ((if s = "0" then "9" else ("" + ((("" + ((s)))->toInteger() - 1))) endif) : temp)
    )
    else (
      execute ((s) : temp)
      )) ;
    return StringLib.sumStringsWithSeparator((temp), "");
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import*
functions=dict()
functions['J']=lambda s : s[1 :]+s[0]
functions['C']=lambda s : s[-1]+s[:-1]
functions['A']=lambda s : ''.join(reversed(s))
functions['E']=lambda s : s[ceil(len(s)/2):]+s[len(s)//2 : ceil(len(s)/2)]+s[: len(s)//2]
functions['P']=lambda s : ''.join([str((int(c)+1)% 10)if c.isnumeric()else c for c in s])
functions['M']=lambda s : ''.join([str((int(c)-1)% 10)if c.isnumeric()else c for c in s])
inv={'J' : 'C','C' : 'J','A' : 'A','E' : 'E','P' : 'M','M' : 'P'}
n=int(input())
for i in range(n):
    order=input()
    message=str(input())
    for o in list(reversed(order)):
        message=functions[inv[o]](message)
    print(message)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var functions : Map := (arguments ( )) ;
    functions->at('J') := lambda s : OclAny in (s->tail() + s->first()) ;
    functions->at('C') := lambda s : OclAny in (s->last() + s->front()) ;
    functions->at('A') := lambda s : OclAny in (StringLib.sumStringsWithSeparator(((s)->reverse()), '')) ;
    functions->at('E') := lambda s : OclAny in (s.subrange(ceil((s)->size() / 2)+1) + s.subrange((s)->size() div 2+1, ceil((s)->size() / 2)) + s.subrange(1,(s)->size() div 2)) ;
    functions->at('P') := lambda s : OclAny in (StringLib.sumStringsWithSeparator((s->select(c | true)->collect(c | (if c->matches("[0-9]*") then ("" + (((("" + ((c)))->toInteger() + 1) mod 10))) else c endif))), '')) ;
    functions->at('M') := lambda s : OclAny in (StringLib.sumStringsWithSeparator((s->select(c | true)->collect(c | (if c->matches("[0-9]*") then ("" + (((("" + ((c)))->toInteger() - 1) mod 10))) else c endif))), '')) ;
    var inv : Map := Map{ 'J' |-> 'C' }->union(Map{ 'C' |-> 'J' }->union(Map{ 'A' |-> 'A' }->union(Map{ 'E' |-> 'E' }->union(Map{ 'P' |-> 'M' }->union(Map{ 'M' |-> 'P' }))))) ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, n-1) do (    var order : String := (OclFile["System.in"]).readLine() ;
    var message : String := ("" + (((OclFile["System.in"]).readLine()))) ;
    for o : ((order)->reverse()) do (    message := functions[inv[o+1]+1](message)) ;
    execute (message)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
for i in range(n):
    order=input()[: :-1]
    message=input()
    for s in order :
        if s=='J' :
            message=message[len(message)-1]+message[: len(message)-1]
        elif s=='C' :
            message=message[1 :]+message[0]
        elif s=='E' :
            message=message[(len(message)+1)//2 :]+message[len(message)//2 :(len(message)+1)//2]+message[: len(message)//2]
        elif s=='A' :
            message=message[: :-1]
        elif s=='P' :
            temp=''
            for c in message :
                if c=='0' :
                    c='9'
                elif c>'0' and c<='9' :
                    c=chr(ord(c)-1)
                temp+=c
            message=temp
        elif s=='M' :
            temp=''
            for c in message :
                if c=='9' :
                    c='0'
                elif c>='0' and c<'9' :
                    c=chr(ord(c)+1)
                temp+=c
            message=temp
    print(message)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, n-1) do (    var order : OclAny := input()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ;
    var message : String := (OclFile["System.in"]).readLine() ;
    for s : order do (    if s = 'J' then  (
      message := message[(message)->size() - 1+1] + message.subrange(1,(message)->size() - 1)
    )
    else (if s = 'C' then
   (
      message := message->tail() + message->first()    
)
    else (if s = 'E' then
   (
      message := message.subrange(((message)->size() + 1) div 2+1) + message.subrange((message)->size() div 2+1, ((message)->size() + 1) div 2) + message.subrange(1,(message)->size() div 2)    
)
    else (if s = 'A' then
   (
      message := message(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))    
)
    else (if s = 'P' then
   (
      var temp : String := '' ;
    for c : message->characters() do (    if c = '0' then  (
      var c : String := '9'
    )
    else (if c > '0' & c <= '9' then
   (
      c := ((c)->char2byte() - 1)->byte2char()    
)
 else skip) ;
    temp := temp + c) ;
    message := temp    
)
    else (if s = 'M' then
   (
      temp := '' ;
    for c : message->characters() do (    if c = '9' then  (
      c := '0'
    )
    else (if c >= '0' & c < '9' then
   (
      c := ((c)->char2byte() + 1)->byte2char()    
)
 else skip) ;
    temp := temp + c) ;
    message := temp    
)
    else skip    )
    )
    )
    )
    )
) ;
    execute (message)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    s=input()
    ans=list(input())
    s=reversed(s)
    for si in s :
        if si=="C" :
            ans=ans[1 :]+[ans[0]]
        if si=="J" :
            ans=[ans[-1]]+ans[:-1]
        if si=="E" :
            tmp=[ans[len(ans)//2]]if len(ans)& 1 else[]
            ans=ans[len(ans)//2+(len(ans)& 1):]+tmp+ans[: len(ans)//2]
        if si=="A" :
            ans=ans[: :-1]
        if si=="M" :
            for i in range(len(ans)):
                if ans[i].isdecimal():
                    ans[i]=int(ans[i])
                    ans[i]=str((ans[i]+1)% 10)
        if si=="P" :
            for i in range(len(ans)):
                if ans[i].isdecimal():
                    ans[i]=int(ans[i])
                    ans[i]=str((ans[i]-1)% 10)
    print("".join(ans))
if __name__=="__main__" :
    for _ in range(int(input())):
        main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    main())
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var s : String := (OclFile["System.in"]).readLine() ;
    var ans : Sequence := ((OclFile["System.in"]).readLine())->characters() ;
    s := (s)->reverse() ;
    for si : s->characters() do (    if si = "C" then (
      ans := ans->tail()->union(Sequence{ ans->first() })
    ) else skip ;
    if si = "J" then (
      ans := Sequence{ ans->last() }->union(ans->front())
    ) else skip ;
    if si = "E" then (
      var tmp : Sequence := if MathLib.bitwiseAnd((ans)->size(), 1) then Sequence{ ans[(ans)->size() div 2+1] } else Sequence{} endif ;
    ans := ans.subrange((ans)->size() div 2 + (MathLib.bitwiseAnd((ans)->size(), 1))+1)->union(tmp) + ans.subrange(1,(ans)->size() div 2)
    ) else skip ;
    if si = "A" then (
      ans := ans(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))
    ) else skip ;
    if si = "M" then (
      for i : Integer.subrange(0, (ans)->size()-1) do (    if ans[i+1]->matches("[0-9]*") then (
      ans[i+1] := ("" + ((ans[i+1])))->toInteger() ;
    ans[i+1] := ("" + (((ans[i+1] + 1) mod 10)))
    ) else skip)
    ) else skip ;
    if si = "P" then (
      for i : Integer.subrange(0, (ans)->size()-1) do (    if ans[i+1]->matches("[0-9]*") then (
      ans[i+1] := ("" + ((ans[i+1])))->toInteger() ;
    ans[i+1] := ("" + (((ans[i+1] - 1) mod 10)))
    ) else skip)
    ) else skip) ;
    execute (StringLib.sumStringsWithSeparator((ans), ""))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for i in range(int(input())):
    k=int(input())
    if k % 2==0 :
        print(0)
    else :
        t=-1
        for i in str(k):
            if int(i)% 2==0 :
                if str(k).index(i)==0 :
                    t=1
                else :
                    t=2
                break
        print(t)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if k mod 2 = 0 then  (
      execute (0)->display()
    )
    else (
      var t : int := -1 ;
    for i : ("" + ((k))) do (    if ("" + ((i)))->toInteger() mod 2 = 0 then (
      if OclType["String"](k)->indexOf(i) - 1 = 0 then  (
      t := 1
    )
    else (
      t := 2
      ) ;
    break
    ) else skip) ;
    execute (t)->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
tlist=[]
for i in range(n):
    m=input()
    if int(m)% 2==0 :
        tlist.append('0')
    else :
        if '2' in m or '4' in m or '6' in m or '8' in m :
            if m[0]in['2','4','6','8']:
                tlist.append('1')
            else :
                tlist.append('2')
        else :
            tlist.append('-1')
for _ in tlist :
    print(_)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var tlist : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    var m : String := (OclFile["System.in"]).readLine() ;
    if ("" + ((m)))->toInteger() mod 2 = 0 then  (
      execute (('0') : tlist)
    )
    else (
      if (m)->characters()->includes('2') or (m)->characters()->includes('4') or (m)->characters()->includes('6') or (m)->characters()->includes('8') then  (
      if (Sequence{'2'}->union(Sequence{'4'}->union(Sequence{'6'}->union(Sequence{ '8' }))))->includes(m->first()) then  (
      execute (('1') : tlist)
    )
    else (
      execute (('2') : tlist)
      )
    )
    else (
      execute (('-1') : tlist)
      )
      )) ;
    for _anon : tlist do (    execute (_anon)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a=list(map(int,input().split(' ')[: n]))
n_infos=0
direction=1
res=0
while True :
    if direction==1 :
        r=range(n)
    else :
        r=range(n-1,-1,-1)
    for i in r :
        if n_infos>=a[i]:
            a[i]=float("inf")
            n_infos+=1
    if n_infos==n :
        break
    direction=-direction
    res+=1
print(res)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split(' ').subrange(1,n))->collect( _x | (OclType["int"])->apply(_x) )) ;
    var n_infos : int := 0 ;
    var direction : int := 1 ;
    var res : int := 0 ;
    while true do (    if direction = 1 then  (
      var r : Sequence := Integer.subrange(0, n-1)
    )
    else (
      r := Integer.subrange(-1 + 1, n - 1)->reverse()
      ) ;
    for i : r do (    if (n_infos->compareTo(a[i+1])) >= 0 then (
      a[i+1] := ("" + (("inf")))->toReal() ;
    n_infos := n_infos + 1
    ) else skip) ;
    if n_infos = n then (
      break
    ) else skip ;
    direction := -direction ;
    res := res + 1) ;
    execute (res)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())//2
s=sorted(map(int,input().split()))
print(sum(s[: n])**2+sum(s[n :])**2)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() div 2 ;
    var s : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ;
    execute (((s.subrange(1,n))->sum())->pow(2) + ((s.subrange(n+1))->sum())->pow(2))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
p=int(input())
while p>0 :
    lis=[]
    n=input()
    a=len(n)
    b=0
    for _ in range(a):
        lis.append(n[_])
        if int(lis[_])% 2==0 :
            b=b+1
    if int(lis[a-1])% 2==0 :
        print("0")
    elif int(lis[0])% 2==0 and int(lis[a-1])% 2!=0 :
        print("1")
    elif b==0 :
        print("-1")
    else :
        print("2")
    p=p-1
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var p : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    while p > 0 do (    var lis : Sequence := Sequence{} ;
    var n : String := (OclFile["System.in"]).readLine() ;
    var a : int := (n)->size() ;
    var b : int := 0 ;
    for _anon : Integer.subrange(0, a-1) do (    execute ((n[_anon+1]) : lis) ;
    if ("" + ((lis[_anon+1])))->toInteger() mod 2 = 0 then (
      b := b + 1
    ) else skip) ;
    if ("" + ((lis[a - 1+1])))->toInteger() mod 2 = 0 then  (
      execute ("0")->display()
    )
    else (if ("" + ((lis->first())))->toInteger() mod 2 = 0 & ("" + ((lis[a - 1+1])))->toInteger() mod 2 /= 0 then
   (
      execute ("1")->display()    
)
    else (if b = 0 then
   (
      execute ("-1")->display()    
)
    else (
      execute ("2")->display()
      )    )
    )
 ;
    p := p - 1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    n=int(input())
    s=str(n)
    f=0
    if int(s[-1])% 2==0 :
        print(0)
    elif int(s[0])% 2==0 :
        print(1)
    else :
        for i in range(1,len(s)):
            if int(s[i])% 2==0 :
                f=1
                break
        if f :
            print(2)
        else :
            print(-1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : String := ("" + ((n))) ;
    var f : int := 0 ;
    if ("" + ((s->last())))->toInteger() mod 2 = 0 then  (
      execute (0)->display()
    )
    else (if ("" + ((s->first())))->toInteger() mod 2 = 0 then
   (
      execute (1)->display()    
)
    else (
      for i : Integer.subrange(1, (s)->size()-1) do (    if ("" + ((s[i+1])))->toInteger() mod 2 = 0 then (
      f := 1 ;
    break
    ) else skip) ;
    if f then  (
      execute (2)->display()
    )
    else (
      execute (-1)->display()
      )
      )    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def calTime(arr,n):
    work=0
    for i in range(n):
        work+=1/arr[i]
    return 1/work
arr=[6.0,3.0,4.0]
n=len(arr)
print(calTime(arr,n),"Hours")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    arr := Sequence{6.0}->union(Sequence{3.0}->union(Sequence{ 4.0 })) ;
    n := (arr)->size() ;
    execute (calTime(arr, n))->display();
  operation calTime(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var work : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    work := work + 1 / arr[i+1]) ;
    return 1 / work;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    L=list(map(int,list(input())))
    if L[-1]% 2==0 :
        print(0)
        continue
    n=len(L)
    flag=False
    for i in range(n):
        if L[i]% 2==0 :
            if i==0 :
                print(1)
            else :
                print(2)
            flag=True
            break
    if not flag :
        print(-1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var L : Sequence := ((((OclFile["System.in"]).readLine())->characters())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if L->last() mod 2 = 0 then (
      execute (0)->display() ;
    continue
    ) else skip ;
    var n : int := (L)->size() ;
    var flag : boolean := false ;
    for i : Integer.subrange(0, n-1) do (    if L[i+1] mod 2 = 0 then (
      if i = 0 then  (
      execute (1)->display()
    )
    else (
      execute (2)->display()
      ) ;
    flag := true ;
    break
    ) else skip) ;
    if not(flag) then (
      execute (-1)->display()
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m=map(int,input().split())
if m==0 : print(1)
else : print(min(m,n-m))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if m = 0 then  (
      execute (1)->display()
    )
    else (
      execute (Set{m, n - m}->min())->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n1,n2=map(int,input().split())
def func(n1,n2):
    if n2==0 :
        print(1)
    else :
        print(min(n1-n2,n2))
func(n1,n2)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n1 : OclAny := null;
    var n2 : OclAny := null;
    Sequence{n1,n2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    skip ;
    func(n1, n2);
  operation func(n1 : OclAny, n2 : OclAny)
  pre: true post: true
  activity:
    if n2 = 0 then  (
      execute (1)->display()
    )
    else (
      execute (Set{n1 - n2, n2}->min())->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m=map(int,input().split())
if m==0 :
    print(1)
else :
    if m<=n//2 :
        print(m)
    else :
        print(n-m)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if m = 0 then  (
      execute (1)->display()
    )
    else (
      if (m->compareTo(n div 2)) <= 0 then  (
      execute (m)->display()
    )
    else (
      execute (n - m)->display()
      )
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m=map(int,input().split())
print(min(max(m,1),n-m))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (Set{Set{m, 1}->max(), n - m}->min())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m=map(int,input().split())
print(min(max(m,1),n-m))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (Set{Set{m, 1}->max(), n - m}->min())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=map(int,input().split())
c=0
for i in range(int(input())):
    s,t=map(int,input().split())
    if not(t<=a or b<=s):
        c=1
print(c)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var c : int := 0 ;
    for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var s : OclAny := null;
    var t : OclAny := null;
    Sequence{s,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if not(((t->compareTo(a)) <= 0 or (b->compareTo(s)) <= 0)) then (
      c := 1
    ) else skip) ;
    execute (c)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
vp=int(input())
vd=int(input())
t=int(input())
f=int(input())
c=int(input())
ans=0
if vp>=vd :
    print(0)
else :
    dist=vp*t+((vp*t)/(vd-vp))*vp
    while disttoInteger() ;
    var vd : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var f : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var ans : int := 0 ;
    if (vp->compareTo(vd)) >= 0 then  (
      execute (0)->display()
    )
    else (
      var dist : int := vp * t + ((vp * t) / (vd - vp)) * vp ;
    while (dist->compareTo(c)) < 0 do (    ans := ans + 1 ;
    dist := dist + vp * (dist / vd) + f * vp ;
    dist := dist + (dist / (vd - vp)) * vp) ;
    execute (ans)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def ans(res,L,N):
    for i in range(N):
        count=0
        for new in res :
            for k in L[i]:
                if(new==k):
                    count+=1
        if(count>=2):
            return 1
    return 0
a,b=map(int,input().split())
res=[]
for i in range(a,b+1,1):
    res.append(i)
N=int(input())
L=[]
for i in range(N):
    l=[]
    s,f=map(int,input().split())
    for i in range(s,f+1,1):
        l.append(i)
    L.append(l)
print(ans(res,L,N))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    res := Sequence{} ;
    for i : Integer.subrange(a, b + 1-1)->select( $x | ($x - a) mod 1 = 0 ) do (    execute ((i) : res)) ;
    N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    L := Sequence{} ;
    for i : Integer.subrange(0, N-1) do (    var l : Sequence := Sequence{} ;
    var s : OclAny := null;
    var f : OclAny := null;
    Sequence{s,f} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    for i : Integer.subrange(s, f + 1-1)->select( $x | ($x - s) mod 1 = 0 ) do (    execute ((i) : l)) ;
    execute ((l) : L)) ;
    execute (ans(res, L, N))->display();
  operation ans(res : OclAny, L : OclAny, N : OclAny) : OclAny
  pre: true post: true
  activity:
    for i : Integer.subrange(0, N-1) do (    var count : int := 0 ;
    for new : res do (    for k : L[i+1] do (    if (new = k) then (
      count := count + 1
    ) else skip)) ;
    if (count >= 2) then (
      return 1
    ) else skip) ;
    return 0;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import itertools
a,b=map(int,input().split())
N=int(input())
reserved=[0]*1001
for _ in range(N):
    s,f=map(int,input().split())
    reserved[s]+=1
    reserved[f]-=1
cumsum=list(itertools.accumulate(reserved))
if sum(cumsum[a : b]):
    print(1)
else :
    print(0)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var reserved : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 1001) ;
    for _anon : Integer.subrange(0, N-1) do (    var s : OclAny := null;
    var f : OclAny := null;
    Sequence{s,f} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    reserved[s+1] := reserved[s+1] + 1 ;
    reserved[f+1] := reserved[f+1] - 1) ;
    var cumsum : Sequence := (itertools.accumulate(reserved)) ;
    if (cumsum.subrange(a+1, b))->sum() then  (
      execute (1)->display()
    )
    else (
      execute (0)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=map(int,list(input().split(" ")))
n=int(input())
c=[0 for i in range(1002)]
ans=0
c[a]+=1
c[b]-=1
for i in range(n):
    s,f=map(int,list(input().split(" ")))
    c[s]+=1
    c[f]-=1
for i in range(1001):
    c[i+1]+=c[i]
    if(c[i]>1):
        ans=1
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := ((input().split(" ")))->collect( _x | (OclType["int"])->apply(_x) ) ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var c : Sequence := Integer.subrange(0, 1002-1)->select(i | true)->collect(i | (0)) ;
    var ans : int := 0 ;
    c[a+1] := c[a+1] + 1 ;
    c[b+1] := c[b+1] - 1 ;
    for i : Integer.subrange(0, n-1) do (    var s : OclAny := null;
    var f : OclAny := null;
    Sequence{s,f} := ((input().split(" ")))->collect( _x | (OclType["int"])->apply(_x) ) ;
    c[s+1] := c[s+1] + 1 ;
    c[f+1] := c[f+1] - 1) ;
    for i : Integer.subrange(0, 1001-1) do (    c[i + 1+1] := c[i + 1+1] + c[i+1] ;
    if (c[i+1] > 1) then (
      ans := 1
    ) else skip) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
dd=[(-1,0),(-1,-1),(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,1)]
while 1 :
    h,w=map(int,input().split())
    if h==w==0 :
        break
    S=[input()for i in range(h)]
    count={}
    for i in range(h):
        for j in range(w):
            for dx,dy in dd :
                s=S[i][j]
                count[s]=count.get(s,0)+1
                x=(j+dx)% w ; y=(i+dy)% h
                while x!=j or y!=i :
                    s+=S[y][x]
                    count[s]=count.get(s,0)+1
                    x=(x+dx)% w ; y=(y+dy)% h
    ans=min(count,key=lambda x :(-len(x)*(count[x]>1),x))
    print(ans*(len(ans)>1)or 0)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var dd : Sequence := Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{-1, -1}}->union(Sequence{Sequence{0, -1}}->union(Sequence{Sequence{1, -1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{1, 1}}->union(Sequence{Sequence{0, 1}}->union(Sequence{ Sequence{-1, 1} }))))))) ;
    while 1 do (    var h : OclAny := null;
    var w : OclAny := null;
    Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if h = w & (w == 0) then (
      break
    ) else skip ;
    var S : Sequence := Integer.subrange(0, h-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ;
    var count : OclAny := Set{} ;
    for i : Integer.subrange(0, h-1) do (    for j : Integer.subrange(0, w-1) do (    for _tuple : dd do (var _indx : int := 1;
      var dx : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var dy : OclAny := _tuple->at(_indx);
      var s : OclAny := S[i+1][j+1] ;
    count[s+1] := count.get(s, 0) + 1 ;
    var x : int := (j + dx) mod w;    var y : int := (i + dy) mod h ;
    while x /= j or y /= i do (    s := s + S[y+1][x+1] ;
    count[s+1] := count.get(s, 0) + 1 ;
    x := (x + dx) mod w;    y := (y + dy) mod h)))) ;
    var ans : OclAny := Set{count, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr - (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name count)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))) > (comparison (expr (atom (number (integer 1))))))))) ))))))) , (test (logical_test (comparison (expr (atom (name x))))))) ))))))))}->min() ;
    execute (ans * ((ans)->size() > 1) or 0)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
time=[0]*1001
a,b=list(map(int,input().split()))
n=int(input())
for i in range(n):
    s,f=list(map(int,input().split()))
    time[s : f]=[1]*(f-s)
if sum(time[a : b])==0 : print("0")
else : print("1")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var time : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 1001) ;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, n-1) do (    var s : OclAny := null;
    var f : OclAny := null;
    Sequence{s,f} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    time.subrange(s+1, f) := MatrixLib.elementwiseMult(Sequence{ 1 }, (f - s))) ;
    if (time.subrange(a+1, b))->sum() = 0 then  (
      execute ("0")->display()
    )
    else (
      execute ("1")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def max_sum(a,n):
    dp=[[0 for i in range(2)]for j in range(n+1)]
    dp[0][0]=0 ; dp[0][1]=-999999 ;
    for i in range(0,n):
        dp[i+1][0]=max(dp[i][0]+a[i],dp[i][1]-a[i]);
        dp[i+1][1]=max(dp[i][0]-a[i],dp[i][1]+a[i]);
    return dp[n][0];
if __name__=='__main__' :
    a=[-10,5,-4];
    n=len(a);
    print(max_sum(a,n));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      a := Sequence{-10}->union(Sequence{5}->union(Sequence{ -4 })); ;
    n := (a)->size(); ;
    execute (max_sum(a, n))->display();
    ) else skip;
  operation max_sum(a : OclAny, n : OclAny)
  pre: true post: true
  activity:
    var dp : Sequence := Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, 2-1)->select(i | true)->collect(i | (0)))) ;
    dp->first()->first() := 0;    dp->first()[1+1] := -999999; ;
    for i : Integer.subrange(0, n-1) do (    dp[i + 1+1]->first() := Set{dp[i+1]->first() + a[i+1], dp[i+1][1+1] - a[i+1]}->max(); ;
    dp[i + 1+1][1+1] := Set{dp[i+1]->first() - a[i+1], dp[i+1][1+1] + a[i+1]}->max();) ;
    return dp[n+1]->first();;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
def nearestGcd(arr,n):
    for i in range(n):
        closest=-1
        j=i-1
        k=i+1
        while j>0 or k<=n :
            if(j>=0 and math.gcd(arr[i],arr[j])>1):
                closest=j+1
                break
            if(k1):
                closest=k+1
                break
            k+=1
            j-=1
        print(closest,end=" ")
if __name__=="__main__" :
    arr=[2,9,4,3,13]
    n=len(arr)
    nearestGcd(arr,n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      arr := Sequence{2}->union(Sequence{9}->union(Sequence{4}->union(Sequence{3}->union(Sequence{ 13 })))) ;
    n := (arr)->size() ;
    nearestGcd(arr, n)
    ) else skip;
  operation nearestGcd(arr : OclAny, n : OclAny)
  pre: true post: true
  activity:
    for i : Integer.subrange(0, n-1) do (    var closest : int := -1 ;
    var j : double := i - 1 ;
    var k : OclAny := i + 1 ;
    while j > 0 or (k->compareTo(n)) <= 0 do (    if (j >= 0 & (arr[i+1])->gcd(arr[j+1]) > 1) then (
      closest := j + 1 ;
    break
    ) else skip ;
    if ((k->compareTo(n)) < 0 & (arr[i+1])->gcd(arr[k+1]) > 1) then (
      closest := k + 1 ;
    break
    ) else skip ;
    k := k + 1 ;
    j := j - 1) ;
    execute (closest)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def isPrefix(string,length,i,k):
    if i+k>length :
        return False
    for j in range(0,k):
        if string[i]!=string[j]:
            return False
        i+=1
    return True
def isKPeriodic(string,length,k):
    for i in range(k,length,k):
        if isPrefix(string,length,i,k)==False :
            return False
    return True
if __name__=="__main__" :
    string="geeksgeeks"
    length=len(string)
    k=5
    if isKPeriodic(string,length,k)==True :
        print("Yes")
    else :
        print("No")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      string := "geeksgeeks" ;
    length := (string)->size() ;
    k := 5 ;
    if isKPeriodic(string, length, k) = true then  (
      execute ("Yes")->display()
    )
    else (
      execute ("No")->display()
      )
    ) else skip;
  operation isPrefix(string : OclAny, length : OclAny, i : OclAny, k : OclAny) : OclAny
  pre: true post: true
  activity:
    if (i + k->compareTo(length)) > 0 then (
      return false
    ) else skip ;
    for j : Integer.subrange(0, k-1) do (    if string[i+1] /= string[j+1] then (
      return false
    ) else skip ;
    i := i + 1) ;
    return true;
  operation isKPeriodic(string : OclAny, length : OclAny, k : OclAny) : OclAny
  pre: true post: true
  activity:
    for i : Integer.subrange(k, length-1)->select( $x | ($x - k) mod k = 0 ) do (    if isPrefix(string, length, i, k) = false then (
      return false
    ) else skip) ;
    return true;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def f():
    for _ in range(int(input())):
        x,y=map(int,input().split())
        a,b=map(int,input().split())
        b=min(b,a+a)
        if xtoInteger()-1) do (    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var b : OclAny := Set{b, a + a}->min() ;
    if (x->compareTo(y)) < 0 then (
      var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := Sequence{y,x}
    ) else skip ;
    execute (y * b + (x - y) * a)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
nCases=int(input())
answers=[]
for i in range(nCases):
    xy=input()
    ab=input()
    x,y=xy.split()
    a,b=ab.split()
    a=int(a)
    b=int(b)
    x=int(x)
    y=int(y)
    if 2*a<=b :
        aw=(x+y)*a
        answers.append(aw)
    else :
        if xy :
            aw=y*b+(x-y)*a
            answers.append(aw)
        else :
            aw=x*b
            answers.append(aw)
for i in range(len(answers)):
    print(answers[i])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var nCases : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var answers : Sequence := Sequence{} ;
    for i : Integer.subrange(0, nCases-1) do (    var xy : String := (OclFile["System.in"]).readLine() ;
    var ab : String := (OclFile["System.in"]).readLine() ;
    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := xy.split() ;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := ab.split() ;
    var a : int := ("" + ((a)))->toInteger() ;
    var b : int := ("" + ((b)))->toInteger() ;
    var x : int := ("" + ((x)))->toInteger() ;
    var y : int := ("" + ((y)))->toInteger() ;
    if (2 * a->compareTo(b)) <= 0 then  (
      var aw : int := (x + y) * a ;
    execute ((aw) : answers)
    )
    else (
      if (x->compareTo(y)) < 0 then  (
      aw := x * b + (y - x) * a ;
    execute ((aw) : answers)
    )
    else (if (x->compareTo(y)) > 0 then
   (
      aw := y * b + (x - y) * a ;
    execute ((aw) : answers)    
)
    else (
      aw := x * b ;
    execute ((aw) : answers)
      )    )
      )) ;
    for i : Integer.subrange(0, (answers)->size()-1) do (    execute (answers[i+1])->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
princess=int(input())
dragon=int(input())
t=int(input())
f=int(input())
c=int(input())
if dragon<=princess :
    print(0)
    exit(0)
result=0
position=t*princess
position+=princess*position/(dragon-princess)
while positiontoInteger() ;
    var dragon : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var f : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if (dragon->compareTo(princess)) <= 0 then (
      execute (0)->display() ;
    exit(0)
    ) else skip ;
    var result : int := 0 ;
    var position : int := t * princess ;
    position := position + princess * position / (dragon - princess) ;
    while (position->compareTo(c)) < 0 do (    result := result + 1 ;
    position := position + princess * position / dragon ;
    position := position + princess * f ;
    position := position + princess * position / (dragon - princess)) ;
    execute (result)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    x,y=map(int,input().split())
    a,b=map(int,input().split())
    b=min(b,a+a)
    if xtoInteger()-1) do (    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var b : OclAny := Set{b, a + a}->min() ;
    if (x->compareTo(y)) < 0 then (
      var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := Sequence{y,x}
    ) else skip ;
    execute (y * b + (x - y) * a)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
rijesenja=list()
for l in range(t):
    xy=list(map(int,input().split()))
    ab=list(map(int,input().split()))
    brojac=0
    brojac2=(xy[0]+xy[1])*ab[0]
    if xy[0]==xy[1]:
        brojac=ab[1]*xy[0]
    elif xy[0]toInteger() ;
    var rijesenja : Sequence := () ;
    for l : Integer.subrange(0, t-1) do (    var xy : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var ab : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var brojac : int := 0 ;
    var brojac2 : double := (xy->first() + xy[1+1]) * ab->first() ;
    if xy->first() = xy[1+1] then  (
      brojac := ab[1+1] * xy->first()
    )
    else (if (xy->first()->compareTo(xy[1+1])) < 0 then
   (
      brojac := xy->first() * ab[1+1] + ab->first() * (xy[1+1] - xy->first())    
)
    else (
      brojac := xy[1+1] * ab[1+1] + ab->first() * (xy->first() - xy[1+1])
      )    )
 ;
    if (brojac->compareTo(brojac2)) < 0 then  (
      execute ((brojac) : rijesenja)
    )
    else (
      execute ((brojac2) : rijesenja)
      )) ;
    for k : Integer.subrange(0, t-1) do (    execute (rijesenja[k+1])->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for test in range(t):
    x,y=map(int,input().split())
    a,b=map(int,input().split())
    if b>=2*a :
        money=(abs(x)+abs(y))*a
    else :
        b_num=min(abs(x),abs(y))
        a_num=max(abs(x),abs(y))-min(abs(x),abs(y))
        money=a_num*a+b_num*b
    print(money)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for test : Integer.subrange(0, t-1) do (    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if (b->compareTo(2 * a)) >= 0 then  (
      var money : double := ((x)->abs() + (y)->abs()) * a
    )
    else (
      var b_num : OclAny := Set{(x)->abs(), (y)->abs()}->min() ;
    var a_num : double := Set{(x)->abs(), (y)->abs()}->max() - Set{(x)->abs(), (y)->abs()}->min() ;
    money := a_num * a + b_num * b
      ) ;
    execute (money)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def digitProduct(digits,start,end):
    pro=1
    for i in range(start,end+1):
        pro*=digits[i]
    return pro
def isDistinct(N):
    s=str(N)
    length=len(s)
    digits=[None]*length
    products=set()
    for i in range(0,length):
        digits[i]=int(s[i])
    for i in range(0,length):
        for j in range(i,length):
            val=digitProduct(digits,i,j)
            if val in products :
                return False
            else :
                products.add(val)
    return True
if __name__=="__main__" :
    N=324
    if isDistinct(N)==True :
        print("YES")
    else :
        print("NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      N := 324 ;
    if isDistinct(N) = true then  (
      execute ("YES")->display()
    )
    else (
      execute ("NO")->display()
      )
    ) else skip;
  operation digitProduct(digits : OclAny, start : OclAny, end : OclAny) : OclAny
  pre: true post: true
  activity:
    var pro : int := 1 ;
    for i : Integer.subrange(start, end + 1-1) do (    pro := pro * digits[i+1]) ;
    return pro;
  operation isDistinct(N : OclAny) : OclAny
  pre: true post: true
  activity:
    var s : String := ("" + ((N))) ;
    var length : int := (s)->size() ;
    digits := MatrixLib.elementwiseMult(Sequence{ null }, length) ;
    var products : Set := Set{}->union(()) ;
    for i : Integer.subrange(0, length-1) do (    digits[i+1] := ("" + ((s[i+1])))->toInteger()) ;
    for i : Integer.subrange(0, length-1) do (    for j : Integer.subrange(i, length-1) do (    var val : OclAny := digitProduct(digits, i, j) ;
    if (products)->includes(val) then  (
      return false
    )
    else (
      execute ((val) : products)
      ))) ;
    return true;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
dx=[1,0,-1,0,1,-1,1,-1]
dy=[0,1,0,-1,1,1,-1,-1]
while True :
    h,w=map(int,input().split())
    if h==0 :
        break
    field=[list(input())for i in range(h)]
    allword=set()
    answord=set()
    for i in range(h):
        for j in range(w):
            s=field[i][j]
            if s in allword :
                answord.add((len(s),s))
            else :
                allword.add(s)
            for k in range(8):
                used=[[False for _ in range(w)]for _ in range(h)]
                s=field[i][j]
                used[i][j]=True
                while True :
                    i=(i+dy[k])% h
                    j=(j+dx[k])% w
                    if used[i][j]:
                        break
                    s+=field[i][j]
                    if s in allword :
                        answord.add((len(s),s))
                    else :
                        allword.add(s)
    print(sorted(answord,key=lambda x :(-x[0],x[1]))[0][1]if answord and sorted(answord,key=lambda x :(-x[0],x[1]))[0][0]>1 else 0)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var dx : Sequence := Sequence{1}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{-1}->union(Sequence{1}->union(Sequence{ -1 }))))))) ;
    var dy : Sequence := Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{-1}->union(Sequence{ -1 }))))))) ;
    while true do (    var h : OclAny := null;
    var w : OclAny := null;
    Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if h = 0 then (
      break
    ) else skip ;
    var field : Sequence := Integer.subrange(0, h-1)->select(i | true)->collect(i | (((OclFile["System.in"]).readLine())->characters())) ;
    var allword : Set := Set{}->union(()) ;
    var answord : Set := Set{}->union(()) ;
    for i : Integer.subrange(0, h-1) do (    for j : Integer.subrange(0, w-1) do (    var s : OclAny := field[i+1][j+1] ;
    if (allword)->includes(s) then  (
      execute ((Sequence{(s)->size(), s}) : answord)
    )
    else (
      execute ((s) : allword)
      ) ;
    for k : Integer.subrange(0, 8-1) do (    var used : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, w-1)->select(_anon | true)->collect(_anon | (false)))) ;
    s := field[i+1][j+1] ;
    used[i+1][j+1] := true ;
    while true do (    var i : int := (i + dy[k+1]) mod h ;
    var j : int := (j + dx[k+1]) mod w ;
    if used[i+1][j+1] then (
      break
    ) else skip ;
    s := s + field[i+1][j+1] ;
    if (allword)->includes(s) then  (
      execute ((Sequence{(s)->size(), s}) : answord)
    )
    else (
      execute ((s) : allword)
      ))))) ;
    execute (if answord & sorted(answord, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr - (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))) , (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))) )))))))))->first()->first() > 1 then sorted(answord, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr - (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))) , (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))) )))))))))->first()[1+1] else 0 endif)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
d=[int(input())for i in range(n)]
pos=0
ans="yes"
for i in range(n):
    if pos>=i*10 :
        pos=max(pos,i*10+d[i])
    else :
        ans="no"
        break
    if pos>=(n-1)*10 :
        break
pos=0
for i in range(n):
    if pos>=i*10 :
        pos=max(pos,i*10+d[n-1-i])
    else :
        ans="no"
        break
    if pos>=(n-1)*10 :
        break
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var d : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ;
    var pos : int := 0 ;
    var ans : String := "yes" ;
    for i : Integer.subrange(0, n-1) do (    if (pos->compareTo(i * 10)) >= 0 then  (
      pos := Set{pos, i * 10 + d[i+1]}->max()
    )
    else (
      ans := "no" ;
    break
      ) ;
    if (pos->compareTo((n - 1) * 10)) >= 0 then (
      break
    ) else skip) ;
    pos := 0 ;
    for i : Integer.subrange(0, n-1) do (    if (pos->compareTo(i * 10)) >= 0 then  (
      pos := Set{pos, i * 10 + d[n - 1 - i+1]}->max()
    )
    else (
      ans := "no" ;
    break
      ) ;
    if (pos->compareTo((n - 1) * 10)) >= 0 then (
      break
    ) else skip) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N,*D=map(int,open(0).read().split())
ok=1
e=0
for i in range(N):
    if ei :
        ok=0
    e=min(e,i-D[i]//10)
print("yes" if ok else "no")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : OclAny := null;
    var D : OclAny := null;
    Sequence{N,D} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var ok : int := 1 ;
    var e : int := 0 ;
    for i : Integer.subrange(0, N-1) do (    if (e->compareTo(i)) < 0 then (
      ok := 0
    ) else skip ;
    e := Set{e, i + D[i+1] div 10}->max()) ;
    e := N - 1 ;
    for i : Integer.subrange(-1 + 1, N - 1)->reverse() do (    if (e->compareTo(i)) > 0 then (
      ok := 0
    ) else skip ;
    e := Set{e, i - D[i+1] div 10}->min()) ;
    execute (if ok then "yes" else "no" endif)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=int(input())
a=[]
for i in range(N):
    a.append(int(input())//10)
max_dist=0
for i in range(N):
    if max_dist>=i :
        max_dist=max(max_dist,i+a[i])
if max_dist>=N-1 :
    max_dist=0
    for i in range(N):
        if max_dist>=i :
            max_dist=max(max_dist,i+a[N-1-i])
    if max_dist>=N-1 :
        print("yes")
    else :
        print("no")
else :
    print("no")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := Sequence{} ;
    for i : Integer.subrange(0, N-1) do (    execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger() div 10) : a)) ;
    var max_dist : int := 0 ;
    for i : Integer.subrange(0, N-1) do (    if (max_dist->compareTo(i)) >= 0 then (
      max_dist := Set{max_dist, i + a[i+1]}->max()
    ) else skip) ;
    if (max_dist->compareTo(N - 1)) >= 0 then  (
      max_dist := 0 ;
    for i : Integer.subrange(0, N-1) do (    if (max_dist->compareTo(i)) >= 0 then (
      max_dist := Set{max_dist, i + a[N - 1 - i+1]}->max()
    ) else skip) ;
    if (max_dist->compareTo(N - 1)) >= 0 then  (
      execute ("yes")->display()
    )
    else (
      execute ("no")->display()
      )
    )
    else (
      execute ("no")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
def judge():
    l=[10*i+d[i]for i in range(N)]
    for i in range(1,N):
        l[i]=max(l[i],l[i-1])
    now=0
    for _ in range(N-1):
        now=l[now//10]
        if now>=10*(N-1):
            return True
    return False
N=int(input())
d=[int(input())for _ in range(N)]
if judge():
    d.reverse()
    if judge():
        print('yes')
        exit()
print('no')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    skip ;
    var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var d : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ;
    if judge() then (
      d := d->reverse() ;
    if judge() then (
      execute ('yes')->display() ;
    exit()
    ) else skip
    ) else skip ;
    execute ('no')->display();
  operation judge() : OclAny
  pre: true post: true
  activity:
    var l : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (10 * i + d[i+1])) ;
    for i : Integer.subrange(1, N-1) do (    l[i+1] := Set{l[i+1], l[i - 1+1]}->max()) ;
    var now : int := 0 ;
    for _anon : Integer.subrange(0, N - 1-1) do (    now := l[now div 10+1] ;
    if (now->compareTo(10 * (N - 1))) >= 0 then (
      return true
    ) else skip) ;
    return false;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=0
bounce=[]
def IsReachable():
    current=0
    for i in range(n):
        if current<10*i : return False
        current=max(current,10*i+bounce[i])
        if current>=10*n : return True
    return False
n=int(input())
for i in range(n):
    bounce.append(int(input()))
if not IsReachable(): print("no")
else :
    bounce.reverse()
    if IsReachable(): print("yes")
    else : print("no")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := 0 ;
    var bounce : Sequence := Sequence{} ;
    skip ;
    n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, n-1) do (    execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : bounce)) ;
    if not(IsReachable()) then  (
      execute ("no")->display()
    )
    else (
      bounce := bounce->reverse() ;
    if IsReachable() then  (
      execute ("yes")->display()
    )
    else (
      execute ("no")->display()
      )
      );
  operation IsReachable() : OclAny
  pre: true post: true
  activity:
    var current : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    if (current->compareTo(10 * i)) < 0 then (
      return false
    ) else skip ;
    current := Set{current, 10 * i + bounce[i+1]}->max() ;
    if (current->compareTo(10 * n)) >= 0 then (
      return true
    ) else skip) ;
    return false;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
speedpre=int(input()); speeddra=int(input()); timetoknow=int(input()); spend=int(input())
castle=int(input()); counter=0 ; posp=speedpre*timetoknow ; posd=0
for i in range(castle):
    if posp>=castle : print(counter); break
    if posp+speedpre>posd+speeddra :
        posp+=speedpre ; posd+=speeddra
    elif posp+speedpre==posd+speeddra and posp+speedpre=castle :
        print(counter); break
    elif posp+speedpre=castle :
        if posp+speedpre/speeddratoInteger();    var speeddra : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger();    var timetoknow : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger();    var spend : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var castle : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger();    var counter : int := 0;    var posp : int := speedpre * timetoknow;    var posd : int := 0 ;
    for i : Integer.subrange(0, castle-1) do (    if (posp->compareTo(castle)) >= 0 then (
      execute (counter)->display();    break
    ) else skip ;
    if (posp + speedpre->compareTo(posd + speeddra)) > 0 then  (
      posp := posp + speedpre;    posd := posd + speeddra
    )
    else (if posp + speedpre = posd + speeddra & (posp + speedpre->compareTo(castle)) < 0 then
   (
      counter := counter + 1;    posp := posp + speedpre;    posd := posd + speeddra;    posp := posp + spend * speedpre ;
    posp := posp + (posd / speeddra) * speedpre;    posd := 0    
)
    else (if posp + speedpre = posd + speeddra & (posp + speedpre->compareTo(castle)) >= 0 then
   (
      execute (counter)->display();    break    
)
    else (if (posp + speedpre->compareTo(posd + speeddra)) < 0 & (posp + speedpre->compareTo(castle)) < 0 then
   (
      counter := counter + 1;    posp := posp + (posp - posd) * (speedpre / speeddra);    posd := posp;    posp := posp + (posd / speeddra) * speedpre ;
    posp := posp + spend * speedpre;    posd := 0    
)
    else (if (posp + speedpre->compareTo(posd + speeddra)) < 0 & (posp + speedpre->compareTo(castle)) >= 0 then
   (
      if (posp + speedpre / speeddra->compareTo(castle)) < 0 then  (
      counter := counter + 1;    posp := posp + (posp - posd) * (speedpre / speeddra);    posd := posp;    posp := posp + (posd / speeddra) * speedpre ;
    posp := posp + spend * speedpre;    posd := 0
    )
    else (
      execute (counter)->display();    break
      )    
)
    else skip    )
    )
    )
    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for i in range(t):
    l,r,k=map(int,input().split())
    e=(r+1)//2-l//2
    if k>=e or l==r!=1 : print("YES")
    else : print("NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, t-1) do (    var l : OclAny := null;
    var r : OclAny := null;
    var k : OclAny := null;
    Sequence{l,r,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var e : double := (r + 1) div 2 - l div 2 ;
    if (k->compareTo(e)) >= 0 or l = r & (r != 1) then  (
      execute ("YES")->display()
    )
    else (
      execute ("NO")->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
while t :
    t-=1
    l,r,k=map(int,input().split())
    odd=(r-l+1)//2+((r-l+1)% 2)*(r % 2)
    if r==1 :
        print("NO")
    elif k>=odd or r==l :
        print("YES")
    else :
        print("NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    while t do (    t := t - 1 ;
    var l : OclAny := null;
    var r : OclAny := null;
    var k : OclAny := null;
    Sequence{l,r,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var odd : int := (r - l + 1) div 2 + ((r - l + 1) mod 2) * (r mod 2) ;
    if r = 1 then  (
      execute ("NO")->display()
    )
    else (if (k->compareTo(odd)) >= 0 or r = l then
   (
      execute ("YES")->display()    
)
    else (
      execute ("NO")->display()
      )    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    l,r,k=map(int,input().split())
    if k==0 :
        if l==r and l!=1 : print("YES")
        else : print("NO")
        continue
    else :
        if k>=((r+1)//2)-(l//2)and l % 2==0 :
            print("YES")
        elif k>=((r+1)//2)-((l-1)//2)and l % 2==1 :
            print("YES")
        else :
            print("NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var l : OclAny := null;
    var r : OclAny := null;
    var k : OclAny := null;
    Sequence{l,r,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if k = 0 then  (
      if l = r & l /= 1 then  (
      execute ("YES")->display()
    )
    else (
      execute ("NO")->display()
      ) ;
    continue
    )
    else (
      if (k->compareTo(((r + 1) div 2) - (l div 2))) >= 0 & l mod 2 = 0 then  (
      execute ("YES")->display()
    )
    else (if (k->compareTo(((r + 1) div 2) - ((l - 1) div 2))) >= 0 & l mod 2 = 1 then
   (
      execute ("YES")->display()    
)
    else (
      execute ("NO")->display()
      )    )
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import sqrt
import sys
input=sys.stdin.readline
ii=lambda : int(input())
iil=lambda :[int(x)for x in input().split()]
itl=lambda : input().split()
def ans(l,r,k):
    if l==r==1 :
        return False
    if k>=r-l :
        return True
    length=r-l+1
    if length % 2==0 :
        return k>=length//2
    else :
        return k>=(length//2+(l % 2==1))
t=ii()
for _ in range(t):
    l,r,k=iil()
    print("YES" if ans(l,r,k)else "NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    var ii : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ;
    var iil : Function := lambda $$ : OclAny in (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) ;
    var itl : Function := lambda $$ : OclAny in (input().split()) ;
    skip ;
    var t : OclAny := ii->apply() ;
    for _anon : Integer.subrange(0, t-1) do (    Sequence{l,r,k} := iil->apply() ;
    execute (if ans(l, r, k) then "YES" else "NO" endif)->display());
  operation ans(l : OclAny, r : OclAny, k : OclAny) : OclAny
  pre: true post: true
  activity:
    if l = r & (r == 1) then (
      return false
    ) else skip ;
    if (k->compareTo(r - l)) >= 0 then (
      return true
    ) else skip ;
    var length : double := r - l + 1 ;
    if length mod 2 = 0 then  (
      return (k->compareTo(length div 2)) >= 0
    )
    else (
      return (k->compareTo((length div 2 + (l mod 2 = 1)))) >= 0
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=eval(input())
for i in range(t):
    left,right,k=map(int,input().split())
    if right==left and left!=1 :
        print("YES")
    elif right==left and left==1 :
        print("NO")
    else :
        if left & 1==0 and right & 1==0 :
            if right-left>>1<=k :
                print("YES")
            else :
                print("NO")
        else :
            if(right-left>>1)+1<=k :
                print("YES")
            else :
                print("NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : OclAny := (OclFile["System.in"]).readLine() ;
    for i : Integer.subrange(0, t-1) do (    var left : OclAny := null;
    var right : OclAny := null;
    var k : OclAny := null;
    Sequence{left,right,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if right = left & left /= 1 then  (
      execute ("YES")->display()
    )
    else (if right = left & left = 1 then
   (
      execute ("NO")->display()    
)
    else (
      if MathLib.bitwiseAnd(left, 1) = 0 & MathLib.bitwiseAnd(right, 1) = 0 then  (
      if (right - left /(2->pow(1))->compareTo(k)) <= 0 then  (
      execute ("YES")->display()
    )
    else (
      execute ("NO")->display()
      )
    )
    else (
      if ((right - left /(2->pow(1))) + 1->compareTo(k)) <= 0 then  (
      execute ("YES")->display()
    )
    else (
      execute ("NO")->display()
      )
      )
      )    )
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def minToggle(arr,n):
    zero=[0 for i in range(n+1+1)]
    zero[0]=0
    for i in range(1,n+1):
        if(arr[i-1]==0):
            zero[i]=zero[i-1]+1
        else :
            zero[i]=zero[i-1]
    ans=n
    for i in range(1,n+1):
        ans=min(ans,i-zero[i]+zero[n]-zero[i])
    return ans
arr=[1,0,1,1,0]
n=len(arr)
print(minToggle(arr,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    arr := Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 0 })))) ;
    n := (arr)->size() ;
    execute (minToggle(arr, n))->display();
  operation minToggle(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var zero : Sequence := Integer.subrange(0, n + 1 + 1-1)->select(i | true)->collect(i | (0)) ;
    zero->first() := 0 ;
    for i : Integer.subrange(1, n + 1-1) do (    if (arr[i - 1+1] = 0) then  (
      zero[i+1] := zero[i - 1+1] + 1
    )
    else (
      zero[i+1] := zero[i - 1+1]
      )) ;
    var ans : OclAny := n ;
    for i : Integer.subrange(1, n + 1-1) do (    ans := Set{ans, i - zero[i+1] + zero[n+1] - zero[i+1]}->min()) ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
class Node :
    def __init__(self):
        self.data=0
        self.left=None
        self.right=None
def newNode(data):
    newNode=Node()
    newNode.data=data
    newNode.left=newNode.right=None
    return(newNode)
res=0
def countUntil(root):
    global res
    if(root==None):
        return 0
    l=countUntil(root.left)
    r=countUntil(root.right)
    maxCount=0
    if(root.data==1):
        maxCount=l+r+1
    else :
        maxCount=l+r
    res=max(res,maxCount)
    if(root.data==1):
        return max(l,r)+1
    else :
        return max(l,r)
def findMaxCount(root):
    global res
    res=-999999
    countUntil(root)
    return res
root=newNode(1)
root.left=newNode(0)
root.right=newNode(1)
root.left.left=newNode(1)
root.left.right=newNode(1)
root.left.right.left=newNode(1)
root.left.right.right=newNode(0)
print(findMaxCount(root))
------------------------------------------------------------
OCL File:
---------
class Node {
  static operation newNode() : Node
  pre: true
  post: Node->exists( _x | result = _x );
  attribute data : int := 0;
  attribute left : OclAny := null;
  attribute right : OclAny := null;
  operation initialise() : Node
  pre: true post: true
  activity:
    self.data := 0 ;
    self.left := null ;
    self.right := null;
    return self;
}
 class FromPython {
  attribute res : OclAny;
  attribute res : OclAny;
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var res : int := 0 ;
    skip ;
    skip ;
    root := newNode(1) ;
    root.left := newNode(0) ;
    root.right := newNode(1) ;
    root.left.left := newNode(1) ;
    root.left.right := newNode(1) ;
    root.left.right.left := newNode(1) ;
    root.left.right.right := newNode(0) ;
    execute (findMaxCount(root))->display();
  operation newNode(data : OclAny) : OclAny
  pre: true post: true
  activity:
    var newNode : Node := (Node.newNode()).initialise() ;
    newNode.data := data ;
    newNode.left := null; var newNode.right : OclAny := null ;
    return (newNode);
  operation countUntil(root : OclAny) : OclAny
  pre: true post: true
  activity:
    skip ;
    if (root = null) then (
      return 0
    ) else skip ;
    var l : OclAny := countUntil(root.left) ;
    var r : OclAny := countUntil(root.right) ;
    var maxCount : int := 0 ;
    if (root.data = 1) then  (
      maxCount := l + r + 1
    )
    else (
      maxCount := l + r
      ) ;
    res := Set{res, maxCount}->max() ;
    if (root.data = 1) then  (
      return Set{l, r}->max() + 1
    )
    else (
      return Set{l, r}->max()
      );
  operation findMaxCount(root : OclAny) : OclAny
  pre: true post: true
  activity:
    skip ;
    res := -999999 ;
    countUntil(root) ;
    return res;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def solution():
    def checkDivisor(a,b):
        min_=min(a,b)
        max_=max(a,b)
        if min_==1 :
            return True
        if max_ % min_==0 :
            return False
        temp_min=min_
        temp_max=max_
        while temp_min!=0 :
            temp=temp_min
            temp_min=temp_max % temp_min
            temp_max=temp
        if temp_max!=1 :
            return False
        return True
    n=int(input())
    arr=[int(i)for i in map(int,input().split())]
    mistakes=[]
    for i in range(len(arr)-1):
        if not checkDivisor(arr[i],arr[i+1]):
            mistakes.append(i)
    print(len(mistakes))
    flag=1
    for i in range(len(mistakes)):
        arr.insert(mistakes[i]+flag,1)
        flag+=1
    for i in range(len(arr)):
        print(arr[i],end=' ')
solution()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    solution();
  operation solution()
  pre: true post: true
  activity:
    skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var arr : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var mistakes : Sequence := Sequence{} ;
    for i : Integer.subrange(0, (arr)->size() - 1-1) do (    if not(checkDivisor(arr[i+1], arr[i + 1+1])) then (
      execute ((i) : mistakes)
    ) else skip) ;
    execute ((mistakes)->size())->display() ;
    var flag : int := 1 ;
    for i : Integer.subrange(0, (mistakes)->size()-1) do (    arr := arr.insertAt(mistakes[i+1] + flag+1, 1) ;
    flag := flag + 1) ;
    for i : Integer.subrange(0, (arr)->size()-1) do (    execute (arr[i+1])->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
from collections import deque
n=int(input())
deck=deque([])
counter=0
sequencia=list(map(int,input().split()))
comp=0
while comp1 :
        deck.append(1)
        counter+=1
deck.append(sequencia[-1])
print(counter)
print(*deck)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var deck : Sequence := (Sequence{}) ;
    var counter : int := 0 ;
    var sequencia : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var comp : int := 0 ;
    while (comp->compareTo(n - 1)) < 0 do (    comp := comp + 1 ;
    execute ((sequencia[comp - 1+1]) : deck) ;
    if (sequencia[comp+1])->gcd(sequencia[comp - 1+1]) > 1 then (
      execute ((1) : deck) ;
    counter := counter + 1
    ) else skip) ;
    execute ((sequencia->last()) : deck) ;
    execute (counter)->display() ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name deck))))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def gcd(a,b):
    while b!=0 :
        a,b=b,a % b
    return a
def solution():
    n=int(input())
    vals=list(map(int,input().split()))
    if n==1 :
        print(0)
        print(*vals)
    else :
        i=0
        c=0
        while itoInteger() ;
    var vals : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if n = 1 then  (
      execute (0)->display() ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name vals))))))))->display()
    )
    else (
      var i : int := 0 ;
    var c : int := 0 ;
    while (i->compareTo(n - 1)) < 0 do (    if gcd(vals[i+1], vals[i + 1+1]) /= 1 then (
      vals := vals.insertAt(i + 1+1, 1) ;
    n := n + 1 ;
    c := c + 1
    ) else skip ;
    i := i + 1) ;
    execute (c)->display() ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name vals))))))))->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
vp,vd,t,f,c=[int(input())for _ in range(5)]
girl_move=t*vp
ans=0
while girl_movevp :
    t=girl_move/(vd-vp)
    girl_move+=t*vp
    if girl_moveselect(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ;
    var girl_move : double := t * vp ;
    var ans : int := 0 ;
    while (girl_move->compareTo(c)) < 0 & (vd->compareTo(vp)) > 0 do (    var t : double := girl_move / (vd - vp) ;
    girl_move := girl_move + t * vp ;
    if (girl_move->compareTo(c)) < 0 then (
      var return_time : double := girl_move / vd + f ;
    girl_move := girl_move + return_time * vp ;
    ans := ans + 1
    ) else skip) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
n=int(input())
a=list(map(int,input().split()))
Ans=0
for i in range(n-1):
    if math.gcd(a[i],a[i+1])!=1 :
        Ans+=1
print(Ans)
for i in range(n-1):
    print(a[i],end=' ')
    if math.gcd(a[i],a[i+1])!=1 :
        print(1,end=' ')
print(a[n-1])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var Ans : int := 0 ;
    for i : Integer.subrange(0, n - 1-1) do (    if (a[i+1])->gcd(a[i + 1+1]) /= 1 then (
      Ans := Ans + 1
    ) else skip) ;
    execute (Ans)->display() ;
    for i : Integer.subrange(0, n - 1-1) do (    execute (a[i+1])->display() ;
    if (a[i+1])->gcd(a[i + 1+1]) /= 1 then (
      execute (1)->display()
    ) else skip) ;
    execute (a[n - 1+1])->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def solution():
    def checkDivisor(a,b):
        min_=min(a,b)
        max_=max(a,b)
        if min_==1 :
            return True
        if max_ % min_==0 :
            return False
        temp_min=min_
        temp_max=max_
        while temp_min!=0 :
            temp=temp_min
            temp_min=temp_max % temp_min
            temp_max=temp
        if temp_max!=1 :
            return False
        return True
    n=int(input())
    arr=[int(i)for i in map(int,input().split())]
    mistakes=[]
    for i in range(len(arr)-1):
        if not checkDivisor(arr[i],arr[i+1]):
            mistakes.append(i)
    print(len(mistakes))
    flag=1
    for i in range(len(mistakes)):
        arr.insert(mistakes[i]+flag,1)
        flag+=1
    for i in range(len(arr)):
        print(arr[i],end=' ')
solution()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    solution();
  operation solution()
  pre: true post: true
  activity:
    skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var arr : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var mistakes : Sequence := Sequence{} ;
    for i : Integer.subrange(0, (arr)->size() - 1-1) do (    if not(checkDivisor(arr[i+1], arr[i + 1+1])) then (
      execute ((i) : mistakes)
    ) else skip) ;
    execute ((mistakes)->size())->display() ;
    var flag : int := 1 ;
    for i : Integer.subrange(0, (mistakes)->size()-1) do (    arr := arr.insertAt(mistakes[i+1] + flag+1, 1) ;
    flag := flag + 1) ;
    for i : Integer.subrange(0, (arr)->size()-1) do (    execute (arr[i+1])->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def maxSquareSubsetSum(A,N):
    sub1=0 ; sub2=0 ;
    A.sort();
    for i in range(N):
        if(i<(N//2)-1):
            sub1+=A[i];
        else :
            sub2+=A[i];
    return sub1*sub1+sub2*sub2 ;
if __name__=="__main__" :
    arr=[7,2,13,4,25,8];
    N=len(arr);
    print(maxSquareSubsetSum(arr,N));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      var arr : Sequence := Sequence{7}->union(Sequence{2}->union(Sequence{13}->union(Sequence{4}->union(Sequence{25}->union(Sequence{ 8 }))))); ;
    N := (arr)->size(); ;
    execute (maxSquareSubsetSum(arr, N))->display();
    ) else skip;
  operation maxSquareSubsetSum(A : OclAny, N : OclAny)
  pre: true post: true
  activity:
    var sub1 : int := 0;    var sub2 : int := 0; ;
    A := A->sort(); ;
    for i : Integer.subrange(0, N-1) do (    if ((i->compareTo((N div 2) - 1)) < 0) then  (
      sub1 := sub1 + A[i+1];
    )
    else (
      sub2 := sub2 + A[i+1];
      )) ;
    return sub1 * sub1 + sub2 * sub2;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def reversedigit(num):
    rev_num=0
    while num>0 :
        rev_num=rev_num*10+num % 10
        num=num//10
    return rev_num
def icanobifNumbers(N):
    first=0
    second=1
    if N==1 :
        print(first)
    elif N==2 :
        print(first,second)
    else :
        print(first,second,end=" ")
        for i in range(3,N+1):
            x=reversedigit(first)
            y=reversedigit(second)
            print(x+y,end=" ")
            temp=second
            second=x+y
            first=temp
N=12
icanobifNumbers(N)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    N := 12 ;
    icanobifNumbers(N);
  operation reversedigit(num : OclAny) : OclAny
  pre: true post: true
  activity:
    var rev_num : int := 0 ;
    while num > 0 do (    rev_num := rev_num * 10 + num mod 10 ;
    num := num div 10) ;
    return rev_num;
  operation icanobifNumbers(N : OclAny)
  pre: true post: true
  activity:
    var first : int := 0 ;
    var second : int := 1 ;
    if N = 1 then  (
      execute (first)->display()
    )
    else (if N = 2 then
   (
      execute (first)->display()    
)
    else (
      execute (first)->display() ;
    for i : Integer.subrange(3, N + 1-1) do (    var x : OclAny := reversedigit(first) ;
    var y : OclAny := reversedigit(second) ;
    execute (x + y)->display() ;
    var temp : int := second ;
    second := x + y ;
    first := temp)
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def octalToDecimal(n):
    num=n ;
    dec_value=0 ;
    base=1 ;
    temp=num ;
    while(temp):
        last_digit=temp % 10 ;
        temp=int(temp/10);
        dec_value+=last_digit*base ;
        base=base*8 ;
    return dec_value ;
num=67 ;
print(octalToDecimal(num));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    num := 67; ;
    execute (octalToDecimal(num))->display();;
  operation octalToDecimal(n : OclAny)
  pre: true post: true
  activity:
    var num : OclAny := n; ;
    var dec_value : int := 0; ;
    var base : int := 1; ;
    var temp : OclAny := num; ;
    while (temp) do (    var last_digit : int := temp mod 10; ;
    temp := ("" + ((temp / 10)))->toInteger(); ;
    dec_value := dec_value + last_digit * base; ;
    base := base * 8;) ;
    return dec_value;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def cbrt(n):
    return(int)(n**(1./3))
def printCubes(a,b):
    acrt=cbrt(a)
    bcrt=cbrt(b)
    for i in range(acrt,bcrt+1):
        if(i*i*i>=a and i*i*i<=b):
            print(i*i*i,"",end="")
a=24
b=576
print("Perfect cubes in given range:")
printCubes(a,b)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    a := 24 ;
    b := 576 ;
    execute ("Perfect cubes in given range:")->display() ;
    printCubes(a, b);
  operation cbrt(n : OclAny) : OclAny
  pre: true post: true
  activity:
    return (OclType["int"])((n)->pow((1. / 3)));
  operation printCubes(a : OclAny, b : OclAny)
  pre: true post: true
  activity:
    var acrt : OclAny := cbrt(a) ;
    var bcrt : OclAny := cbrt(b) ;
    for i : Integer.subrange(acrt, bcrt + 1-1) do (    if ((i * i * i->compareTo(a)) >= 0 & (i * i * i->compareTo(b)) <= 0) then (
      execute (i * i * i)->display()
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def factorial(n):
    if n==1 or n==0 :
        return 1
    else :
        return factorial(n-1)*n
def gcdOfFactorial(arr,n):
    minm=arr[0]
    for i in range(1,n):
        if minm>arr[i]:
            minm=arr[i]
        else :
            arr[i]=minm
    return factorial(minm)
arr=[9,12,122,34,15]
n=len(arr)
print(gcdOfFactorial(arr,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    arr := Sequence{9}->union(Sequence{12}->union(Sequence{122}->union(Sequence{34}->union(Sequence{ 15 })))) ;
    n := (arr)->size() ;
    execute (gcdOfFactorial(arr, n))->display();
  operation factorial(n : OclAny) : OclAny
  pre: true post: true
  activity:
    if n = 1 or n = 0 then  (
      return 1
    )
    else (
      return factorial(n - 1) * n
      );
  operation gcdOfFactorial(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var minm : OclAny := arr->first() ;
    for i : Integer.subrange(1, n-1) do (    if (minm->compareTo(arr[i+1])) > 0 then  (
      minm := arr[i+1]
    )
    else (
      arr[i+1] := minm
      )) ;
    return factorial(minm);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
def primes(a):
    s1=set()
    f=0
    for i in range(2,math.ceil(math.sqrt(a+1))):
        while a % i==0 :
            a//=i
            s1.add(i)
            if a1 :
        l2=primes(l1[i])
        for a in l2 :
            if a in dt :
                dt[a]+=1
            else :
                dt[a]=1
try :
    print(max(dt.values()))
except :
    print(1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var l1 : Sequence := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ;
    l1 := l1->sort() ;
    var dt : Map := (arguments ( )) ;
    for i : Integer.subrange(0, n-1) do (    if l1[i+1] > 1 then (
      var l2 : OclAny := primes(l1[i+1]) ;
    for a : l2 do (    if (dt)->includes(a) then  (
      dt[a+1] := dt[a+1] + 1
    )
    else (
      dt[a+1] := 1
      ))
    ) else skip) ;
    try (    execute ((dt.values())->max())->display())
     catch (_e : OclException) do (    execute (1)->display())
;
  operation primes(a : OclAny) : OclAny
  pre: true post: true
  activity:
    var s1 : Set := Set{}->union(()) ;
    var f : int := 0 ;
    for i : Integer.subrange(2, ((a + 1)->sqrt())->ceil()-1) do (    while a mod i = 0 do (    a := a div i ;
    execute ((i) : s1) ;
    if (a->compareTo(i)) < 0 then (
      f := 1 ;
    break
    ) else skip) ;
    if f then (
      break
    ) else skip) ;
    if a /= 1 then (
      execute ((a) : s1)
    ) else skip ;
    return (s1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a=list(map(int,input().split()))
k=1
s=[0]*100001
for i in a :
    s[i]+=1
for i in range(2,100001):
    p=0
    for j in range(i,100001,i):
        p+=s[j]
    k=max(k,p)
print(k)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var k : int := 1 ;
    var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100001) ;
    for i : a do (    s[i+1] := s[i+1] + 1) ;
    for i : Integer.subrange(2, 100001-1) do (    var p : int := 0 ;
    for j : Integer.subrange(i, 100001-1)->select( $x | ($x - i) mod i = 0 ) do (    p := p + s[j+1]) ;
    k := Set{k, p}->max()) ;
    execute (k)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def solve(v):
    inf=1300000
    tmp=[0]*inf
    for i in v :
        tmp[i]+=1
    ans=1
    for i in range(2,inf):
        a=0
        for j in range(i,inf,i):
            a+=tmp[j]
        ans=max(ans,a)
    return ans
n=input()
v=list(map(int,input().split()))
print(solve(v))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : String := (OclFile["System.in"]).readLine() ;
    v := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute (solve(v))->display();
  operation solve(v : OclAny) : OclAny
  pre: true post: true
  activity:
    var Math_PINFINITY : int := 1300000 ;
    var tmp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, Math_PINFINITY) ;
    for i : v do (    tmp[i+1] := tmp[i+1] + 1) ;
    var ans : int := 1 ;
    for i : Integer.subrange(2, Math_PINFINITY-1) do (    var a : int := 0 ;
    for j : Integer.subrange(i, Math_PINFINITY-1)->select( $x | ($x - i) mod i = 0 ) do (    a := a + tmp[j+1]) ;
    ans := Set{ans, a}->max()) ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
current_time=input()
time_duration=input()
current_time_min=int(current_time[: 2])*60+int(current_time[3 :])
time_duration_min=int(time_duration[: 2])*60+int(time_duration[3 :])
t_min=current_time_min-time_duration_min
if current_time_mintoInteger() * 60 + ("" + ((current_time.subrange(3+1))))->toInteger() ;
    var time_duration_min : int := ("" + ((time_duration.subrange(1,2))))->toInteger() * 60 + ("" + ((time_duration.subrange(3+1))))->toInteger() ;
    var t_min : double := current_time_min - time_duration_min ;
    if (current_time_min->compareTo(time_duration_min)) < 0 then (
      t_min := 24 * 60 - (t_min)->abs()
    ) else skip ;
    var hour : String := if t_min div 60 < 10 then "0" + ("" + ((t_min div 60))) else ("" + ((t_min div 60))) endif ;
    var minute : String := if t_min mod 60 < 10 then "0" + ("" + ((t_min mod 60))) else ("" + ((t_min mod 60))) endif ;
    execute (StringLib.formattedString("{hour}:{minute}"))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=[0,4,10,20,35,56,83,116,155,198,244,292]
n=int(input())
if n<11 :
    print(a[n])
else :
    print((n-11)*49+292)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : Sequence := Sequence{0}->union(Sequence{4}->union(Sequence{10}->union(Sequence{20}->union(Sequence{35}->union(Sequence{56}->union(Sequence{83}->union(Sequence{116}->union(Sequence{155}->union(Sequence{198}->union(Sequence{244}->union(Sequence{ 292 }))))))))))) ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n < 11 then  (
      execute (a[n+1])->display()
    )
    else (
      execute ((n - 11) * 49 + 292)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
ans=0
i=0
while i<=8 and i<=n :
    j=0
    while j<=(8 if i==0 else 4)and j+i<=n :
        ans+=n-i-j+1
        j=j+1
    i=i+1
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var ans : int := 0 ;
    var i : int := 0 ;
    while i <= 8 & (i->compareTo(n)) <= 0 do (    var j : int := 0 ;
    while (j->compareTo((if i = 0 then 8 else 4 endif))) <= 0 & (j + i->compareTo(n)) <= 0 do (    ans := ans + n - i - j + 1 ;
    j := j + 1) ;
    i := i + 1) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
ans=0
i=0
while i<=8 and i<=n :
    j=0
    while j<=(8 if i==0 else 4)and j+i<=n :
        ans+=n-i-j+1
        j=j+1
    i=i+1
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var ans : int := 0 ;
    var i : int := 0 ;
    while i <= 8 & (i->compareTo(n)) <= 0 do (    var j : int := 0 ;
    while (j->compareTo((if i = 0 then 8 else 4 endif))) <= 0 & (j + i->compareTo(n)) <= 0 do (    ans := ans + n - i - j + 1 ;
    j := j + 1) ;
    i := i + 1) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
best=0
for k in range(1,13):
    dp=[[False]*(50*k+1)for _ in range(k+1)]
    dp[0][0]=True
    for i in range(k):
        for s in range(50*k+1):
            if dp[i][s]:
                if s+1<=50*k :
                    dp[i+1][s+1]=True
                if s+5<=50*k :
                    dp[i+1][s+5]=True
                if s+10<=50*k :
                    dp[i+1][s+10]=True
                if s+50<=50*k :
                    dp[i+1][s+50]=True
    cnt=dp[k].count(True)
    if k==n :
        print(cnt)
        exit()
    current=0
    best=0
    for i in range(1,50*k+2):
        if i<50*k+1 and dp[k][i]==1 :
            current+=1
        else :
            best=max(best,current)
            current=0
best+=(n-12)*49
print(248+best)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var best : int := 0 ;
    for k : Integer.subrange(1, 13-1) do (    var dp : Sequence := Integer.subrange(0, k + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ false }, (50 * k + 1)))) ;
    dp->first()->first() := true ;
    for i : Integer.subrange(0, k-1) do (    for s : Integer.subrange(0, 50 * k + 1-1) do (    if dp[i+1][s+1] then (
      if (s + 1->compareTo(50 * k)) <= 0 then (
      dp[i + 1+1][s + 1+1] := true
    ) else skip ;
    if (s + 5->compareTo(50 * k)) <= 0 then (
      dp[i + 1+1][s + 5+1] := true
    ) else skip ;
    if (s + 10->compareTo(50 * k)) <= 0 then (
      dp[i + 1+1][s + 10+1] := true
    ) else skip ;
    if (s + 50->compareTo(50 * k)) <= 0 then (
      dp[i + 1+1][s + 50+1] := true
    ) else skip
    ) else skip)) ;
    var cnt : OclAny := dp[k+1]->count(true) ;
    if k = n then (
      execute (cnt)->display() ;
    exit()
    ) else skip ;
    var current : int := 0 ;
    best := 0 ;
    for i : Integer.subrange(1, 50 * k + 2-1) do (    if (i->compareTo(50 * k + 1)) < 0 & dp[k+1][i+1] = 1 then  (
      current := current + 1
    )
    else (
      best := Set{best, current}->max() ;
    current := 0
      ))) ;
    best := best + (n - 12) * 49 ;
    execute (248 + best)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a=[0,4,10,20,35,56,83,116,155,198,244,292]
if(n<12):
    print(a[n])
else :
    print(292+(n-11)*49)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := Sequence{0}->union(Sequence{4}->union(Sequence{10}->union(Sequence{20}->union(Sequence{35}->union(Sequence{56}->union(Sequence{83}->union(Sequence{116}->union(Sequence{155}->union(Sequence{198}->union(Sequence{244}->union(Sequence{ 292 }))))))))))) ;
    if (n < 12) then  (
      execute (a[n+1])->display()
    )
    else (
      execute (292 + (n - 11) * 49)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from bisect import bisect_left,bisect_right
def solve():
    n=int(input())
    a=[3]
    b=[3]
    c=[2]
    i=1
    s=3
    while s<=n :
        a.append(a[-1]+3)
        s+=a[-1]
        b.append(b[i-1]+a[i])
        c.append(c[i-1]+a[i]-1)
        i+=1
    a.append(a[-1]+3)
    s+=a[-1]
    b.append(b[i-1]+a[i])
    c.append(c[i-1]+a[i]-1)
    ind=bisect_left(c,n)
    if c[ind]>n :
        ind-=1
    count=0
    i=ind
    while i>=0 :
        if n>=c[i]:
            n-=c[i]
            count+=1
        else :
            i-=1
    return count
for t in range(0,int(input())):
    print(solve())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    execute (solve())->display());
  operation solve() : OclAny
  pre: true post: true
  activity:
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := Sequence{ 3 } ;
    var b : Sequence := Sequence{ 3 } ;
    var c : Sequence := Sequence{ 2 } ;
    var i : int := 1 ;
    var s : int := 3 ;
    while (s->compareTo(n)) <= 0 do (    execute ((a->last() + 3) : a) ;
    s := s + a->last() ;
    execute ((b[i - 1+1] + a[i+1]) : b) ;
    execute ((c[i - 1+1] + a[i+1] - 1) : c) ;
    i := i + 1) ;
    execute ((a->last() + 3) : a) ;
    s := s + a->last() ;
    execute ((b[i - 1+1] + a[i+1]) : b) ;
    execute ((c[i - 1+1] + a[i+1] - 1) : c) ;
    var ind : OclAny := bisect_left(c, n) ;
    if (c[ind+1]->compareTo(n)) > 0 then (
      ind := ind - 1
    ) else skip ;
    var count : int := 0 ;
    i := ind ;
    while i >= 0 do (    if (n->compareTo(c[i+1])) >= 0 then  (
      n := n - c[i+1] ;
    count := count + 1
    )
    else (
      i := i - 1
      )) ;
    return count;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import bisect as bs
heights=[0,2]
n=110000
for i in range(2,n):
    val=heights[i-1]+(3*i-1)
    heights.append(val)
n=int(input())
n2=len(heights)
for i in range(n):
    val=int(input())
    temp=val
    cnt=0
    while(True):
        idx=bs.bisect_left(heights,temp)
        if(heights[idx]>temp):
            temp-=heights[idx-1]
        else :
            temp-=heights[idx]
        cnt+=1
        if(idx==0 or temp<2):
            break
    if(val<=1):
        print(0)
    else :
        print(cnt)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var heights : Sequence := Sequence{0}->union(Sequence{ 2 }) ;
    var n : int := 110000 ;
    for i : Integer.subrange(2, n-1) do (    var val : OclAny := heights[i - 1+1] + (3 * i - 1) ;
    execute ((val) : heights)) ;
    n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var n2 : int := (heights)->size() ;
    for i : Integer.subrange(0, n-1) do (    val := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var temp : OclAny := val ;
    var cnt : int := 0 ;
    while (true) do (    var idx : OclAny := bs.bisect_left(heights, temp) ;
    if ((heights[idx+1]->compareTo(temp)) > 0) then  (
      temp := temp - heights[idx - 1+1]
    )
    else (
      temp := temp - heights[idx+1]
      ) ;
    cnt := cnt + 1 ;
    if (idx = 0 or temp < 2) then (
      break
    ) else skip) ;
    if (val <= 1) then  (
      execute (0)->display()
    )
    else (
      execute (cnt)->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import datetime
def main(a,b):
    dt=datetime.datetime(2004,a,b)
    week_num=dt.weekday()
    if week_num==0 :
        print('Monday')
    elif week_num==1 :
        print('Tuesday')
    elif week_num==2 :
        print('Wednesday')
    elif week_num==3 :
        print('Thursday')
    elif week_num==4 :
        print('Friday')
    elif week_num==5 :
        print('Saturday')
    elif week_num==6 :
        print('Sunday')
while True :
    a,b=[int(e)for e in input().split()]
    if a==0 and b==0 :
        break
    main(a,b)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    while true do (    Sequence{a,b} := input().split()->select(e | true)->collect(e | (("" + ((e)))->toInteger())) ;
    if a = 0 & b = 0 then (
      break
    ) else skip ;
    main(a, b));
  operation main(a : OclAny, b : OclAny)
  pre: true post: true
  activity:
    var dt : OclAny :=  ;
    var week_num : OclAny := dt.weekday() ;
    if week_num = 0 then  (
      execute ('Monday')->display()
    )
    else (if week_num = 1 then
   (
      execute ('Tuesday')->display()    
)
    else (if week_num = 2 then
   (
      execute ('Wednesday')->display()    
)
    else (if week_num = 3 then
   (
      execute ('Thursday')->display()    
)
    else (if week_num = 4 then
   (
      execute ('Friday')->display()    
)
    else (if week_num = 5 then
   (
      execute ('Saturday')->display()    
)
    else (if week_num = 6 then
   (
      execute ('Sunday')->display()    
)
    else skip    )
    )
    )
    )
    )
    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
x1,y1,r1=map(int,input().split())
x2,y2,r2=map(int,input().split())
d=math.sqrt((x1-x2)**2+(y1-y2)**2)
R=max(r1,r2)
r=min(r1,r2)
if(R-r==d or R+r==d or(R+r>d and R-rcollect( _x | (OclType["int"])->apply(_x) ) ;
    var x2 : OclAny := null;
    var y2 : OclAny := null;
    var r2 : OclAny := null;
    Sequence{x2,y2,r2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var d : double := (((x1 - x2))->pow(2) + ((y1 - y2))->pow(2))->sqrt() ;
    var R : OclAny := Set{r1, r2}->max() ;
    var r : OclAny := Set{r1, r2}->min() ;
    if (R - r = d or R + r = d or ((R + r->compareTo(d)) > 0 & (R - r->compareTo(d)) < 0)) then  (
      execute (StringLib.interpolateStrings("{0:.15f}", Sequence{0}))->display()
    )
    else (
      var a : Sequence := Sequence{} ;
    var m : double := (y2 - y1) / (x2 - x1) ;
    var c : OclAny := x1 + (r1 / ((m)->pow(2) + 1)->sqrt()) ;
    d := y1 + ((r1 * m) / ((m)->pow(2) + 1)->sqrt()) ;
    execute ((Sequence{c}->union(Sequence{ d })) : a) ;
    c := x1 - (r1 / ((m)->pow(2) + 1)->sqrt()) ;
    d := y1 - ((r1 * m) / ((m)->pow(2) + 1)->sqrt()) ;
    execute ((Sequence{c}->union(Sequence{ d })) : a) ;
    var b : Sequence := Sequence{} ;
    c := x2 + (r2 / ((m)->pow(2) + 1)->sqrt()) ;
    d := y2 + ((r2 * m) / ((m)->pow(2) + 1)->sqrt()) ;
    execute ((Sequence{c}->union(Sequence{ d })) : b) ;
    c := x2 - (r2 / ((m)->pow(2) + 1)->sqrt()) ;
    d := y2 - ((r2 * m) / ((m)->pow(2) + 1)->sqrt()) ;
    execute ((Sequence{c}->union(Sequence{ d })) : b) ;
    var dis : double := (10)->pow(10) ;
    for i : a do (    for j : b do (    dis := Set{dis, (((i->first() - j->first()))->pow(2) + ((i[1+1] - j[1+1]))->pow(2))->sqrt()}->min())) ;
    execute (StringLib.interpolateStrings("{0:.15f}", Sequence{dis / 2}))->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def CalculateRatio(m,n):
    return(2*m-1)/(2*n-1);
if __name__=='__main__' :
    m=6 ;
    n=2 ;
    print(float(CalculateRatio(m,n)));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      m := 6; ;
    n := 2; ;
    execute (("" + ((CalculateRatio(m, n))))->toReal())->display();
    ) else skip;
  operation CalculateRatio(m : OclAny, n : OclAny)
  pre: true post: true
  activity:
    return (2 * m - 1) / (2 * n - 1);;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
h1,m1=(map(int,input().split(':')))
m1+=h1*60
h2,m2=(map(int,input().split(':')))
m2+=h2*60
m2=m1-m2
m2 %=1440
print("%02d:%02d" %(m2//60,m2 % 60))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var h1 : OclAny := null;
    var m1 : OclAny := null;
    Sequence{h1,m1} := ((input().split(':'))->collect( _x | (OclType["int"])->apply(_x) )) ;
    m1 := m1 + h1 * 60 ;
    var h2 : OclAny := null;
    var m2 : OclAny := null;
    Sequence{h2,m2} := ((input().split(':'))->collect( _x | (OclType["int"])->apply(_x) )) ;
    m2 := m2 + h2 * 60 ;
    var m2 : double := m1 - m2 ;
    m2 := m2 mod 1440 ;
    execute (StringLib.format("%02d:%02d",Sequence{m2 div 60, m2 mod 60}))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import bisect
cards=list(map(lambda h : int(3/2*(h)**2+1/2*h),[h for h in range(1,25820)]))
for _ in range(int(input())):
    n=int(input())
    ans=0
    while n>1 :
        idx=bisect.bisect(cards,n)
        n=n-cards[idx-1]
        ans+=1
    print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var cards : Sequence := ((Integer.subrange(1, 25820-1)->select(h | true)->collect(h | (h)))->collect( _x | (lambda h : OclAny in (("" + ((3 / 2 * ((h))->pow(2) + 1 / 2 * h)))->toInteger()))->apply(_x) )) ;
    for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var ans : int := 0 ;
    while n > 1 do (    var idx : OclAny := bisect.bisect(cards, n) ;
    n := n - cards[idx - 1+1] ;
    ans := ans + 1) ;
    execute (ans)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
stack1=[2]
stack=[]
k=int(1e9)
x=5
for i in range(0,30000):
    if stack1[-1]a :
            hi=mid-1
    if stack[lo]>a :
        lo-=1
    return lo
def xuly(nn):
    if nn>=stack[-1]:
        n1=nn-stack[-1]
        return(xuly(n1)+1)
    if nn==0 or nn==1 :
        return 0
    if nn==2 :
        return 1
    else :
        pos=search(nn)
        n2=nn-stack[pos]
        return(xuly(n2)+1)
t=int(input())
while t>0 :
    t-=1
    n=int(input())
    if n<2 :
        print(0)
    if n==2 :
        print(1)
    if n>2 :
        print(xuly(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var stack1 : Sequence := Sequence{ 2 } ;
    var stack : Sequence := Sequence{} ;
    var k : int := ("" + ((("1e9")->toReal())))->toInteger() ;
    var x : int := 5 ;
    for i : Integer.subrange(0, 30000-1) do (    if (stack1->last()->compareTo(k)) < 0 then (
      execute ((stack1->last()) : stack)
    ) else skip ;
    execute ((stack1->last() + x) : stack1) ;
    x := x + 3) ;
    skip ;
    skip ;
    var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    while t > 0 do (    t := t - 1 ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n < 2 then (
      execute (0)->display()
    ) else skip ;
    if n = 2 then (
      execute (1)->display()
    ) else skip ;
    if n > 2 then (
      execute (xuly(n))->display()
    ) else skip);
  operation search(a : OclAny) : OclAny
  pre: true post: true
  activity:
    var lo : int := 0 ;
    var hi : double := (stack)->size() - 1 ;
    while (lo->compareTo(hi)) <= 0 do (    var mid : int := (lo + hi) div 2 ;
    if stack[mid+1] = a then (
      return mid
    ) else skip ;
    if (stack[mid+1]->compareTo(a)) < 0 then (
      lo := mid + 1
    ) else skip ;
    if (stack[mid+1]->compareTo(a)) > 0 then (
      hi := mid - 1
    ) else skip) ;
    if (stack[lo+1]->compareTo(a)) > 0 then (
      lo := lo - 1
    ) else skip ;
    return lo;
  operation xuly(nn : OclAny) : OclAny
  pre: true post: true
  activity:
    if (nn->compareTo(stack->last())) >= 0 then (
      var n1 : double := nn - stack->last() ;
    return (xuly(n1) + 1)
    ) else skip ;
    if nn = 0 or nn = 1 then (
      return 0
    ) else skip ;
    if nn = 2 then  (
      return 1
    )
    else (
      var pos : OclAny := search(nn) ;
    var n2 : double := nn - stack[pos+1] ;
    return (xuly(n2) + 1)
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
toks=(tok for tok in sys.stdin.read().split())
def pyramid_from_height(h):
    return 3*((h*(h+1))//2)-h
def tallest_pyramid_possible(N):
    low=1
    high=N
    while lowN :
            high=mid
        else :
            low=mid+1
    return low-1
T=int(next(toks))
for _ in range(T):
    N=int(next(toks))
    num_pyramids_built=0
    while True :
        next_pyramid_height=tallest_pyramid_possible(N)
        if next_pyramid_height==0 :
            break
        num_pyramids_built+=1
        N-=pyramid_from_height(next_pyramid_height)
    print(num_pyramids_built)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var toks : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name tok)))))) (comp_for for (exprlist (expr (atom (name tok)))) in (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin)) (trailer . (name read) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ;
    skip ;
    skip ;
    var T : int := ("" + (((toks).next())))->toInteger() ;
    for _anon : Integer.subrange(0, T-1) do (    N := ("" + (((toks).next())))->toInteger() ;
    var num_pyramids_built : int := 0 ;
    while true do (    var next_pyramid_height : OclAny := tallest_pyramid_possible(N) ;
    if next_pyramid_height = 0 then (
      break
    ) else skip ;
    num_pyramids_built := num_pyramids_built + 1 ;
    N := N - pyramid_from_height(next_pyramid_height)) ;
    execute (num_pyramids_built)->display());
  operation pyramid_from_height(h : OclAny) : OclAny
  pre: true post: true
  activity:
    return 3 * ((h * (h + 1)) div 2) - h;
  operation tallest_pyramid_possible(N : OclAny) : OclAny
  pre: true post: true
  activity:
    var low : int := 1 ;
    var high : OclAny := N ;
    while (low->compareTo(high)) < 0 do (    var mid : int := (low + high) div 2 ;
    if (pyramid_from_height(mid)->compareTo(N)) > 0 then  (
      high := mid
    )
    else (
      low := mid + 1
      )) ;
    return low - 1;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
class Node :
    def __init__(self):
        self.data=None
        self.link=None
class Queue :
    def __init__(self):
        front=None
        rear=None
def enQueue(q,value):
    temp=Node()
    temp.data=value
    if(q.front==None):
        q.front=temp
    else :
        q.rear.link=temp
    q.rear=temp
    q.rear.link=q.front
def deQueue(q):
    if(q.front==None):
        print("Queue is empty")
        return-999999999999
    value=None
    if(q.front==q.rear):
        value=q.front.data
        q.front=None
        q.rear=None
    else :
        temp=q.front
        value=temp.data
        q.front=q.front.link
        q.rear.link=q.front
    return value
def displayQueue(q):
    temp=q.front
    print("Elements in Circular Queue are: ",end=" ")
    while(temp.link!=q.front):
        print(temp.data,end=" ")
        temp=temp.link
    print(temp.data)
if __name__=='__main__' :
    q=Queue()
    q.front=q.rear=None
    enQueue(q,14)
    enQueue(q,22)
    enQueue(q,6)
    displayQueue(q)
    print("Deleted value=",deQueue(q))
    print("Deleted value=",deQueue(q))
    displayQueue(q)
    enQueue(q,9)
    enQueue(q,20)
    displayQueue(q)
------------------------------------------------------------
OCL File:
---------
class Node {
  static operation newNode() : Node
  pre: true
  post: Node->exists( _x | result = _x );
  attribute data : OclAny := null;
  attribute link : OclAny := null;
  operation initialise() : Node
  pre: true post: true
  activity:
    self.data := null ;
    self.link := null;
    return self;
}
class Queue {
  static operation newQueue() : Queue
  pre: true
  post: Queue->exists( _x | result = _x );
  operation initialise() : Queue
  pre: true post: true
  activity:
    var front : OclAny := null ;
    var rear : OclAny := null;
    return self;
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      q := (Queue.newQueue()).initialise() ;
    q.front := null; var q.rear : OclAny := null ;
    enQueue(q, 14) ;
    enQueue(q, 22) ;
    enQueue(q, 6) ;
    displayQueue(q) ;
    execute ("Deleted value=")->display() ;
    execute ("Deleted value=")->display() ;
    displayQueue(q) ;
    enQueue(q, 9) ;
    enQueue(q, 20) ;
    displayQueue(q)
    ) else skip;
  operation enQueue(q : OclAny, value : OclAny)
  pre: true post: true
  activity:
    var temp : Node := (Node.newNode()).initialise() ;
    temp.data := value ;
    if (q.front = null) then  (
      q.front := temp
    )
    else (
      q.rear.link := temp
      ) ;
    q.rear := temp ;
    q.rear.link := q.front;
  operation deQueue(q : OclAny) : OclAny
  pre: true post: true
  activity:
    if (q.front = null) then (
      execute ("Queue is empty")->display() ;
    return -999999999999
    ) else skip ;
    value := null ;
    if (q.front = q.rear) then  (
      value := q.front.data ;
    q.front := null ;
    q.rear := null
    )
    else (
      temp := q.front ;
    value := temp.data ;
    q.front := q.front.link ;
    q.rear.link := q.front
      ) ;
    return value;
  operation displayQueue(q : OclAny)
  pre: true post: true
  activity:
    temp := q.front ;
    execute ("Elements in Circular Queue are: ")->display() ;
    while (temp.link /= q.front) do (    execute (temp.data)->display() ;
    temp := temp.link) ;
    execute (temp.data)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import sqrt ;
def isPalindrome(n):
    string=str(n);
    s=0 ; e=len(string)-1 ;
    while(ssize() - 1; ;
    while ((s->compareTo(e)) < 0) do (    if (string[s+1] /= string[e+1]) then (
      return false;
    ) else skip ;
    s := s + 1; ;
    e := e - 1;) ;
    return true;;
  operation palindromicDivisors(n : OclAny)
  pre: true post: true
  activity:
    var PalindromDivisors : Sequence := Sequence{}; ;
    for i : Integer.subrange(1, ("" + ((sqrt(n))))->toInteger()-1) do (    if (n mod i = 0) then (
      if (n div i = i) then  (
      if (isPalindrome(i)) then (
      execute ((i) : PalindromDivisors);
    ) else skip
    )
    else (
      if (isPalindrome(i)) then (
      execute ((i) : PalindromDivisors);
    ) else skip ;
    if (isPalindrome(n div i)) then (
      execute ((n div i) : PalindromDivisors);
    ) else skip
      )
    ) else skip) ;
    PalindromDivisors := PalindromDivisors->sort(); ;
    for i : Integer.subrange(0, (PalindromDivisors)->size()-1) do (    execute (PalindromDivisors[i+1])->display(););
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
from bisect import bisect_left,bisect_right
INF=10**18+100
N,A,B=map(int,input().split())
S=[-INF]+[int(x)for x in sys.stdin.read().split()]
MOD=10**9+7
dpX=[0]*(N+1)
dpY=[0]*(N+1)
dpX[0]=1
dpY[0]=1
dpX_cum=[1]*(N+1)+[0]
dpY_cum=[1]*(N+1)+[0]
dpX_left=0
dpY_left=0
for n,x in enumerate(S[2 :],2):
    iA=bisect_right(S,x-A)
    iB=bisect_right(S,x-B)
    xy=dpY_cum[iB-1]-dpY_cum[dpY_left-1]if iB>=dpY_left else 0
    yx=dpX_cum[iA-1]-dpX_cum[dpX_left-1]if iA>=dpX_left else 0
    if iA!=n :
        dpY_left=n-1
    if iB!=n :
        dpX_left=n-1
    dpX[n-1]=xy
    dpX_cum[n-1]=(dpX_cum[n-2]+xy)% MOD
    dpX_cum[n]=dpX_cum[n-1]
    dpY[n-1]=yx
    dpY_cum[n-1]=(dpY_cum[n-2]+yx)% MOD
    dpY_cum[n]=dpY_cum[n-1]
answer=dpX_cum[N-1]-dpX_cum[dpX_left-1]
answer+=dpY_cum[N-1]-dpY_cum[dpY_left-1]
answer %=MOD
print(answer)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    skip ;
    var INF : double := (10)->pow(18) + 100 ;
    var N : OclAny := null;
    var A : OclAny := null;
    var B : OclAny := null;
    Sequence{N,A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var S : Sequence := Sequence{ -INF }->union(sys.stdin.readAll().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) ;
    var MOD : double := (10)->pow(9) + 7 ;
    var dpX : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ;
    var dpY : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ;
    dpX->first() := 1 ;
    dpY->first() := 1 ;
    var dpX_cum : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (N + 1))->union(Sequence{ 0 }) ;
    var dpY_cum : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (N + 1))->union(Sequence{ 0 }) ;
    var dpX_left : int := 0 ;
    var dpY_left : int := 0 ;
    for _tuple : Integer.subrange(1, (S.subrange(2+1), 2)->size())->collect( _indx | Sequence{_indx-1, (S.subrange(2+1), 2)->at(_indx)} ) do (var _indx : int := 1;
      var n : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var x : OclAny := _tuple->at(_indx);
      var iA : OclAny := bisect_right(S, x - A) ;
    var iB : OclAny := bisect_right(S, x - B) ;
    var xy : double := if (iB->compareTo(dpY_left)) >= 0 then dpY_cum[iB - 1+1] - dpY_cum[dpY_left - 1+1] else 0 endif ;
    var yx : double := if (iA->compareTo(dpX_left)) >= 0 then dpX_cum[iA - 1+1] - dpX_cum[dpX_left - 1+1] else 0 endif ;
    if iA /= n then (
      dpY_left := n - 1
    ) else skip ;
    if iB /= n then (
      dpX_left := n - 1
    ) else skip ;
    dpX[n - 1+1] := xy ;
    dpX_cum[n - 1+1] := (dpX_cum[n - 2+1] + xy) mod MOD ;
    dpX_cum[n+1] := dpX_cum[n - 1+1] ;
    dpY[n - 1+1] := yx ;
    dpY_cum[n - 1+1] := (dpY_cum[n - 2+1] + yx) mod MOD ;
    dpY_cum[n+1] := dpY_cum[n - 1+1]) ;
    var answer : double := dpX_cum[N - 1+1] - dpX_cum[dpX_left - 1+1] ;
    answer := answer + dpY_cum[N - 1+1] - dpY_cum[dpY_left - 1+1] ;
    answer := answer mod MOD ;
    execute (answer)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from bisect import bisect_left
N,A,B=map(int,input().split())
inf,mod=float("inf"),10**9+7
S=[int(input())for i in range(N)]
St_A=[0]*N
St_B=[0]*N
J_A,J_B=[0],[0]
for i in range(N):
    St_A[i]=bisect_left(S,S[i]+A)-1
    St_B[i]=bisect_left(S,S[i]+B)-1
    J_A.append(J_A[-1]+int(St_A[i]!=i))
    J_B.append(J_B[-1]+int(St_B[i]!=i))
dp_A=[0]*N
dp_B=[0]*N
dp_A[-1],dp_B[-1]=1,1
for i in range(N-1)[: :-1]:
    if St_A[i]==i :
        dp_A[i]=(dp_A[i+1]+dp_B[i+1])% mod
    else :
        if J_B[St_A[i]]-J_B[i+1]==0 :
            dp_A[i]=dp_B[St_A[i]]
        else :
            dp_A[i]=0
    if St_B[i]==i :
        dp_B[i]=(dp_A[i+1]+dp_B[i+1])% mod
    else :
        if J_A[St_B[i]]-J_A[i+1]==0 :
            dp_B[i]=dp_A[St_B[i]]
        else :
            dp_B[i]=0
print((dp_A[0]+dp_B[0])% mod)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var N : OclAny := null;
    var A : OclAny := null;
    var B : OclAny := null;
    Sequence{N,A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var Math_PINFINITY : OclAny := null;
    var mod : OclAny := null;
    Sequence{Math_PINFINITY,mod} := Sequence{("" + (("inf")))->toReal(),(10)->pow(9) + 7} ;
    var S : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ;
    var St_A : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ;
    var St_B : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ;
    var J_A : OclAny := null;
    var J_B : OclAny := null;
    Sequence{J_A,J_B} := Sequence{Sequence{ 0 },Sequence{ 0 }} ;
    for i : Integer.subrange(0, N-1) do (    St_A[i+1] := bisect_left(S, S[i+1] + A) - 1 ;
    St_B[i+1] := bisect_left(S, S[i+1] + B) - 1 ;
    execute ((J_A->last() + ("" + ((St_A[i+1] /= i)))->toInteger()) : J_A) ;
    execute ((J_B->last() + ("" + ((St_B[i+1] /= i)))->toInteger()) : J_B)) ;
    var dp_A : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ;
    var dp_B : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ;
    var dp_A->last() : OclAny := null;
    var dp_B->last() : OclAny := null;
    Sequence{dp_A->last(),dp_B->last()} := Sequence{1,1} ;
    for i : range(N - 1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do (    if St_A[i+1] = i then  (
      dp_A[i+1] := (dp_A[i + 1+1] + dp_B[i + 1+1]) mod mod
    )
    else (
      if J_B[St_A[i+1]+1] - J_B[i + 1+1] = 0 then  (
      dp_A[i+1] := dp_B[St_A[i+1]+1]
    )
    else (
      dp_A[i+1] := 0
      )
      ) ;
    if St_B[i+1] = i then  (
      dp_B[i+1] := (dp_A[i + 1+1] + dp_B[i + 1+1]) mod mod
    )
    else (
      if J_A[St_B[i+1]+1] - J_A[i + 1+1] = 0 then  (
      dp_B[i+1] := dp_A[St_B[i+1]+1]
    )
    else (
      dp_B[i+1] := 0
      )
      )) ;
    execute ((dp_A->first() + dp_B->first()) mod mod)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def findIndex(a,n,key):
    start=-1
    for i in range(n):
        if a[i]==key :
            start=i
            break
    if start==-1 :
        print("Key not present in array")
        return 0
    end=start
    for i in range(n-1,start-1,-1):
        if a[i]==key :
            end=i
            break
    if start==end :
        print("Only one key is present at index : ",start)
    else :
        print("Start index: ",start)
        print("Last index: ",end)
a=[1,2,7,8,8,9,8,0,0,0,8]
n=len(a)
key=8
findIndex(a,n,key)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    a := Sequence{1}->union(Sequence{2}->union(Sequence{7}->union(Sequence{8}->union(Sequence{8}->union(Sequence{9}->union(Sequence{8}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 8 })))))))))) ;
    n := (a)->size() ;
    key := 8 ;
    findIndex(a, n, key);
  operation findIndex(a : OclAny, n : OclAny, key : OclAny) : OclAny
  pre: true post: true
  activity:
    var start : int := -1 ;
    for i : Integer.subrange(0, n-1) do (    if a[i+1] = key then (
      start := i ;
    break
    ) else skip) ;
    if start = -1 then (
      execute ("Key not present in array")->display() ;
    return 0
    ) else skip ;
    var end : int := start ;
    for i : Integer.subrange(start - 1 + 1, n - 1)->reverse() do (    if a[i+1] = key then (
      end := i ;
    break
    ) else skip) ;
    if start = end then  (
      execute ("Only one key is present at index : ")->display()
    )
    else (
      execute ("Start index: ")->display() ;
    execute ("Last index: ")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
while(t):
    s=input()
    n=len(s)
    c=0
    l=[]
    for i in range(n):
        if(s[i]!='0'):
            s1=s[i]+'0'*(n-i-1)
            c+=1
            l.append(s1)
    print(c)
    for i in l :
        print(i,end=' ')
    print()
    t-=1
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    while (t) do (    var s : String := (OclFile["System.in"]).readLine() ;
    var n : int := (s)->size() ;
    var c : int := 0 ;
    var l : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    if (s[i+1] /= '0') then (
      var s1 : OclAny := s[i+1] + StringLib.nCopies('0', (n - i - 1)) ;
    c := c + 1 ;
    execute ((s1) : l)
    ) else skip) ;
    execute (c)->display() ;
    for i : l do (    execute (i)->display()) ;
    execute (->display() ;
    t := t - 1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
while(t>0):
    n=int(input())
    res=[]
    aux=10
    while(aux<=n):
        if n % aux!=0 :
            res.append(n % aux)
            n-=n % aux
        aux*=10
    if n % aux!=0 :
        res.append(n % aux)
    print(len(res))
    print(" ".join([str(num)for num in res]))
    t-=1
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    while (t > 0) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var res : Sequence := Sequence{} ;
    var aux : int := 10 ;
    while ((aux->compareTo(n)) <= 0) do (    if n mod aux /= 0 then (
      execute ((n mod aux) : res) ;
    n := n - n mod aux
    ) else skip ;
    aux := aux * 10) ;
    if n mod aux /= 0 then (
      execute ((n mod aux) : res)
    ) else skip ;
    execute ((res)->size())->display() ;
    execute (StringLib.sumStringsWithSeparator((res->select(num | true)->collect(num | (("" + ((num)))))), " "))->display() ;
    t := t - 1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
h=[]
m=[]
for _ in range(2):
    x,y=list(map(int,input().split(':')))
    h.append(x)
    m.append(y)
h[0]=h[0]-h[1]
m[0]=m[0]-m[1]
if m[0]<0 :
    h[0]-=1
    m[0]+=60
if h[0]<0 :
    h[0]+=24
if h[0]>=0 and h[0]<=9 :
    h[0]='0'+str(h[0])
if m[0]>=0 and m[0]<=9 :
    m[0]='0'+str(m[0])
print(f"{h[0]}:{m[0]}")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var h : Sequence := Sequence{} ;
    var m : Sequence := Sequence{} ;
    for _anon : Integer.subrange(0, 2-1) do (    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := ((input().split(':'))->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute ((x) : h) ;
    execute ((y) : m)) ;
    h->first() := h->first() - h[1+1] ;
    m->first() := m->first() - m[1+1] ;
    if m->first() < 0 then (
      h->first() := h->first() - 1 ;
    m->first() := m->first() + 60
    ) else skip ;
    if h->first() < 0 then (
      h->first() := h->first() + 24
    ) else skip ;
    if h->first() >= 0 & h->first() <= 9 then (
      h->first() := '0' + ("" + ((h->first())))
    ) else skip ;
    if m->first() >= 0 & m->first() <= 9 then (
      m->first() := '0' + ("" + ((m->first())))
    ) else skip ;
    execute (StringLib.formattedString("{h[0]}:{m[0]}"))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    n=int(input())
    a=input(); a='2'+a+'2'
    a=[i for i in a]
    b='2'+input()+'2'
    b=[i for i in b]
    ans=0
    for i in range(1,n+1):
        if b[i]=='1' :
            if a[i]=='0' : ans+=1
            elif a[i-1]=='1' : ans+=1 ; a[i-1]='2'
            elif a[i+1]=='1' : ans+=1 ; a[i+1]='2'
    print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : String := (OclFile["System.in"]).readLine();    a := '2' + a + '2' ;
    a := a->characters()->select(i | true)->collect(i | (i)) ;
    var b : String := '2' + (OclFile["System.in"]).readLine() + '2' ;
    b := b->characters()->select(i | true)->collect(i | (i)) ;
    var ans : int := 0 ;
    for i : Integer.subrange(1, n + 1-1) do (    if b[i+1] = '1' then (
      if a[i+1] = '0' then  (
      ans := ans + 1
    )
    else (if a[i - 1+1] = '1' then
   (
      ans := ans + 1;    a[i - 1+1] := '2'    
)
    else (if a[i + 1+1] = '1' then
   (
      ans := ans + 1;    a[i + 1+1] := '2'    
)
    else skip    )
    )
    ) else skip) ;
    execute (ans)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for i in range(t):
    n=input()[: :-1]
    digits=[]
    for j in range(len(n)):
        if n[j]!='0' :
            digits.append(int(n[j])*(10**j))
    tam=len(digits)
    print(tam)
    for k in range(tam):
        print(digits[k],end=' ')
    print()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, t-1) do (    var n : OclAny := input()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ;
    var digits : Sequence := Sequence{} ;
    for j : Integer.subrange(0, (n)->size()-1) do (    if n[j+1] /= '0' then (
      execute ((("" + ((n[j+1])))->toInteger() * ((10)->pow(j))) : digits)
    ) else skip) ;
    var tam : int := (digits)->size() ;
    execute (tam)->display() ;
    for k : Integer.subrange(0, tam-1) do (    execute (digits[k+1])->display()) ;
    execute (->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
if __name__=='__main__' :
    t=int(input())
    for _ in range(t):
        n=input()
        aux=[]
        for i in range(len(n)):
            if n[i]!='0' :
                aux.append(n[i]+('0'*(len(n)-i-1)))
        print(len(aux))
        print(' '.join(aux))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     if __name__ = '__main__' then (
      var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, t-1) do (    var n : String := (OclFile["System.in"]).readLine() ;
    var aux : Sequence := Sequence{} ;
    for i : Integer.subrange(0, (n)->size()-1) do (    if n[i+1] /= '0' then (
      execute ((n[i+1] + (StringLib.nCopies('0', ((n)->size() - i - 1)))) : aux)
    ) else skip) ;
    execute ((aux)->size())->display() ;
    execute (StringLib.sumStringsWithSeparator((aux), ' '))->display())
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
while(t):
    s=input()
    n=len(s)
    c=0
    l=[]
    for i in range(n):
        if(s[i]!='0'):
            s1=s[i]+'0'*(n-i-1)
            c+=1
            l.append(s1)
    print(c)
    for i in l :
        print(i,end=' ')
    print()
    t-=1
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    while (t) do (    var s : String := (OclFile["System.in"]).readLine() ;
    var n : int := (s)->size() ;
    var c : int := 0 ;
    var l : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    if (s[i+1] /= '0') then (
      var s1 : OclAny := s[i+1] + StringLib.nCopies('0', (n - i - 1)) ;
    c := c + 1 ;
    execute ((s1) : l)
    ) else skip) ;
    execute (c)->display() ;
    for i : l do (    execute (i)->display()) ;
    execute (->display() ;
    t := t - 1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
MOD=1000000007
max=101
C=[[0 for i in range(max)]for j in range(max)]
def power(x,y):
    res=1
    x=x % MOD
    while(y>0):
        if(y & 1):
            res=(res*x)% MOD
        y=y>>1
        x=(x*x)% MOD
    return res % MOD
def combi(n,k):
    for i in range(n+1):
        for j in range(min(i,k)+1):
            if(j==0 or j==i):
                C[i][j]=1
            else :
                C[i][j]=(C[i-1][j-1]% MOD+C[i-1][j]% MOD)% MOD
def product(a,n,k):
    ans=1
    a.sort(reverse=False)
    powa=C[n-1][k-1]
    for i in range(n):
        powla=C[i][k-1]
        powfa=C[n-i-1][k-1]
        powe=((powa % MOD)-(powla+powfa)% MOD+MOD)% MOD
        mul=power(a[i],powe)% MOD
        ans=((ans % MOD)*(mul % MOD))% MOD
    return ans % MOD
if __name__=='__main__' :
    combi(100,100)
    arr=[1,2,3,4]
    n=len(arr)
    k=3
    ans=product(arr,n,k)
    print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var MOD : int := 1000000007 ;
    var max : int := 101 ;
    var C : Sequence := Integer.subrange(0, max-1)->select(j | true)->collect(j | (Integer.subrange(0, max-1)->select(i | true)->collect(i | (0)))) ;
    skip ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      combi(100, 100) ;
    var arr : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))) ;
    n := (arr)->size() ;
    k := 3 ;
    ans := product(arr, n, k) ;
    execute (ans)->display()
    ) else skip;
  operation power(x : OclAny, y : OclAny) : OclAny
  pre: true post: true
  activity:
    var res : int := 1 ;
    x := x mod MOD ;
    while (y > 0) do (    if (MathLib.bitwiseAnd(y, 1)) then (
      res := (res * x) mod MOD
    ) else skip ;
    y := y /(2->pow(1)) ;
    x := (x * x) mod MOD) ;
    return res mod MOD;
  operation combi(n : OclAny, k : OclAny)
  pre: true post: true
  activity:
    for i : Integer.subrange(0, n + 1-1) do (    for j : Integer.subrange(0, Set{i, k}->min() + 1-1) do (    if (j = 0 or j = i) then  (
      C[i+1][j+1] := 1
    )
    else (
      C[i+1][j+1] := (C[i - 1+1][j - 1+1] mod MOD + C[i - 1+1][j+1] mod MOD) mod MOD
      )));
  operation product(a : OclAny, n : OclAny, k : OclAny) : OclAny
  pre: true post: true
  activity:
    var ans : int := 1 ;
    a := a->sort() ;
    var powa : OclAny := C[n - 1+1][k - 1+1] ;
    for i : Integer.subrange(0, n-1) do (    var powla : OclAny := C[i+1][k - 1+1] ;
    var powfa : OclAny := C[n - i - 1+1][k - 1+1] ;
    var powe : int := ((powa mod MOD) - (powla + powfa) mod MOD + MOD) mod MOD ;
    var mul : int := power(a[i+1], powe) mod MOD ;
    ans := ((ans mod MOD) * (mul mod MOD)) mod MOD) ;
    return ans mod MOD;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
point=list(map(int,input().split()))
if point[0]==0 and point[1]==0 :
    print("1")
    sys.exit()
fiblist=[0,1,1]
maxpoint=[0,0]
minpoint=[0,0]
i=2
while True :
    if i % 4==2 or i % 4==3 :
        maxpoint[i % 2]+=fiblist[2]
    else :
        minpoint[i % 2]-=fiblist[2]
    if minpoint[0]<=point[0]and maxpoint[0]>=point[0]and minpoint[1]<=point[1]and maxpoint[1]>=point[1]:
        print((i-1)% 3+1)
        break
    fiblist[0]=fiblist[1]
    fiblist[1]=fiblist[2]
    fiblist[2]=fiblist[0]+fiblist[1]
    i+=1
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var point : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if point->first() = 0 & point[1+1] = 0 then (
      execute ("1")->display() ;
    sys.exit()
    ) else skip ;
    var fiblist : Sequence := Sequence{0}->union(Sequence{1}->union(Sequence{ 1 })) ;
    var maxpoint : Sequence := Sequence{0}->union(Sequence{ 0 }) ;
    var minpoint : Sequence := Sequence{0}->union(Sequence{ 0 }) ;
    var i : int := 2 ;
    while true do (    if i mod 4 = 2 or i mod 4 = 3 then  (
      maxpoint[i mod 2+1] := maxpoint[i mod 2+1] + fiblist[2+1]
    )
    else (
      minpoint[i mod 2+1] := minpoint[i mod 2+1] - fiblist[2+1]
      ) ;
    if (minpoint->first()->compareTo(point->first())) <= 0 & (maxpoint->first()->compareTo(point->first())) >= 0 & (minpoint[1+1]->compareTo(point[1+1])) <= 0 & (maxpoint[1+1]->compareTo(point[1+1])) >= 0 then (
      execute ((i - 1) mod 3 + 1)->display() ;
    break
    ) else skip ;
    fiblist->first() := fiblist[1+1] ;
    fiblist[1+1] := fiblist[2+1] ;
    fiblist[2+1] := fiblist->first() + fiblist[1+1] ;
    i := i + 1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def search(x,y):
    x_min=0
    y_min=0
    x_max=0
    y_max=0
    f=0
    f1=1
    f2=0
    p=0
    while(True):
        if(x_min<=x and x<=x_max and y_min<=y and y<=y_max): return p % 3+1
        f=f1+f2
        if(p % 4==0): x_max+=f
        elif(p % 4==1): y_max+=f
        elif(p % 4==2): x_min-=f
        else : y_min-=f
        f2=f1
        f1=f
        p=p+1
x,y=map(int,input().split())
print(search(x,y))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (search(x, y))->display();
  operation search(x : OclAny, y : OclAny) : OclAny
  pre: true post: true
  activity:
    var x_min : int := 0 ;
    var y_min : int := 0 ;
    var x_max : int := 0 ;
    var y_max : int := 0 ;
    var f : int := 0 ;
    var f1 : int := 1 ;
    var f2 : int := 0 ;
    var p : int := 0 ;
    while (true) do (    if ((x_min->compareTo(x)) <= 0 & (x->compareTo(x_max)) <= 0 & (y_min->compareTo(y)) <= 0 & (y->compareTo(y_max)) <= 0) then (
      return p mod 3 + 1
    ) else skip ;
    f := f1 + f2 ;
    if (p mod 4 = 0) then  (
      x_max := x_max + f
    )
    else (if (p mod 4 = 1) then
   (
      y_max := y_max + f    
)
    else (if (p mod 4 = 2) then
   (
      x_min := x_min - f    
)
    else (
      y_min := y_min - f
      )    )
    )
 ;
    f2 := f1 ;
    f1 := f ;
    p := p + 1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
xx,yy=list(map(int,input().split()))
fib=[1,1]
a=0
while a<10000000 :
    a=fib[-1]+fib[-2]
    fib+=[a]
area=[[0,0,1]]
x,y=0,0
f1=0
f2=1
for n in range(1,len(fib)):
    a=fib[n]
    if n % 4==1 :
        area+=[[x+f2,y+f1,a]]
    elif n % 4==2 :
        area+=[[x-f1,y+a,a]]
    elif n % 4==3 :
        area+=[[x-a,y,a]]
    elif n % 4==0 :
        area+=[[x,y-f2,a]]
    f1=f2
    f2=a
    x,y=area[-1][0 : 2]
for n,floor in enumerate(area):
    x,y,a=floor
    if x<=xxcollect( _x | (OclType["int"])->apply(_x) )) ;
    var fib : Sequence := Sequence{1}->union(Sequence{ 1 }) ;
    var a : int := 0 ;
    while a < 10000000 do (    a := fib->last() + fib->front()->last() ;
    fib := fib + Sequence{ a }) ;
    var area : Sequence := Sequence{ Sequence{0}->union(Sequence{0}->union(Sequence{ 1 })) } ;
    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := Sequence{0,0} ;
    var f1 : int := 0 ;
    var f2 : int := 1 ;
    for n : Integer.subrange(1, (fib)->size()-1) do (    a := fib[n+1] ;
    if n mod 4 = 1 then  (
      area := area + Sequence{ Sequence{x + f2}->union(Sequence{y + f1}->union(Sequence{ a })) }
    )
    else (if n mod 4 = 2 then
   (
      area := area + Sequence{ Sequence{x - f1}->union(Sequence{y + a}->union(Sequence{ a })) }    
)
    else (if n mod 4 = 3 then
   (
      area := area + Sequence{ Sequence{x - a}->union(Sequence{y}->union(Sequence{ a })) }    
)
    else (if n mod 4 = 0 then
   (
      area := area + Sequence{ Sequence{x}->union(Sequence{y - f2}->union(Sequence{ a })) }    
)
    else skip    )
    )
    )
 ;
    f1 := f2 ;
    f2 := a ;
    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := area->last().subrange(0+1, 2)) ;
    for _tuple : Integer.subrange(1, (area)->size())->collect( _indx | Sequence{_indx-1, (area)->at(_indx)} ) do (var _indx : int := 1;
      var n : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var floor : OclAny := _tuple->at(_indx);
      var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y,a} := floor ;
    if (x->compareTo(xx)) <= 0 & (xx < x + a) & (y - a->compareTo(yy)) < 0 & (yy <= y) then (
      execute (n mod 3 + 1)->display() ;
    break
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
x,y=map(int,input().split())
left,right,up,down=0,0,0,0
fiv1=0
fiv2=1
color=[1,2,3]
ans=0
while not(left<=x<=right)or not(down<=y<=up):
    num=fiv1+fiv2
    right+=num
    fiv1=fiv2
    fiv2=num
    ans+=1
    if left<=x<=right and down<=y<=up :
        break
    num=fiv1+fiv2
    up+=num
    fiv1=fiv2
    fiv2=num
    ans+=1
    if left<=x<=right and down<=y<=up :
        break
    num=fiv1+fiv2
    left-=num
    fiv1=fiv2
    fiv2=num
    ans+=1
    if left<=x<=right and down<=y<=up :
        break
    num=fiv1+fiv2
    down-=num
    fiv1=fiv2
    fiv2=num
    ans+=1
print(color[ans % 3])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var left : OclAny := null;
    var right : OclAny := null;
    var up : OclAny := null;
    var down : OclAny := null;
    Sequence{left,right,up,down} := Sequence{0,0,0,0} ;
    var fiv1 : int := 0 ;
    var fiv2 : int := 1 ;
    var color : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ;
    var ans : int := 0 ;
    while not(((left->compareTo(x)) <= 0 & (x <= right))) or not(((down->compareTo(y)) <= 0 & (y <= up))) do (    var num : int := fiv1 + fiv2 ;
    right := right + num ;
    fiv1 := fiv2 ;
    fiv2 := num ;
    ans := ans + 1 ;
    if (left->compareTo(x)) <= 0 & (x <= right) & (down->compareTo(y)) <= 0 & (y <= up) then (
      break
    ) else skip ;
    num := fiv1 + fiv2 ;
    up := up + num ;
    fiv1 := fiv2 ;
    fiv2 := num ;
    ans := ans + 1 ;
    if (left->compareTo(x)) <= 0 & (x <= right) & (down->compareTo(y)) <= 0 & (y <= up) then (
      break
    ) else skip ;
    num := fiv1 + fiv2 ;
    left := left - num ;
    fiv1 := fiv2 ;
    fiv2 := num ;
    ans := ans + 1 ;
    if (left->compareTo(x)) <= 0 & (x <= right) & (down->compareTo(y)) <= 0 & (y <= up) then (
      break
    ) else skip ;
    num := fiv1 + fiv2 ;
    down := down - num ;
    fiv1 := fiv2 ;
    fiv2 := num ;
    ans := ans + 1) ;
    execute (color[ans mod 3+1])->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
x,y=[int(i)for i in input().split()]
fiboMax=100
fibo=[0 for i in range(fiboMax)]
fibo[1]=1
fibo[2]=1
for i in range(3,fiboMax):
    fibo[i]=fibo[i-1]+fibo[i-2]
xMax=0
yMax=0
xMin=0
yMin=0
ans=-1
if(x<=xMax and y<=yMax and x>=xMin and y>=yMin):
    ans=1
else :
    i=2
    while(True):
        xMax+=fibo[i]
        if(x<=xMax and y<=yMax and x>=xMin and y>=yMin):
            ans=i
            break
        else :
            i+=1
        yMax+=fibo[i]
        if(x<=xMax and y<=yMax and x>=xMin and y>=yMin):
            ans=i
            break
        else :
            i+=1
        xMin-=fibo[i]
        if(x<=xMax and y<=yMax and x>=xMin and y>=yMin):
            ans=i
            break
        else :
            i+=1
        yMin-=fibo[i]
        if(x<=xMax and y<=yMax and x>=xMin and y>=yMin):
            ans=i
            break
        else :
            i+=1
ans %=3
if ans==0 :
    ans=3
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var fiboMax : int := 100 ;
    var fibo : Sequence := Integer.subrange(0, fiboMax-1)->select(i | true)->collect(i | (0)) ;
    fibo[1+1] := 1 ;
    fibo[2+1] := 1 ;
    for i : Integer.subrange(3, fiboMax-1) do (    fibo[i+1] := fibo[i - 1+1] + fibo[i - 2+1]) ;
    var xMax : int := 0 ;
    var yMax : int := 0 ;
    var xMin : int := 0 ;
    var yMin : int := 0 ;
    var ans : int := -1 ;
    if ((x->compareTo(xMax)) <= 0 & (y->compareTo(yMax)) <= 0 & (x->compareTo(xMin)) >= 0 & (y->compareTo(yMin)) >= 0) then  (
      ans := 1
    )
    else (
      var i : int := 2 ;
    while (true) do (    xMax := xMax + fibo[i+1] ;
    if ((x->compareTo(xMax)) <= 0 & (y->compareTo(yMax)) <= 0 & (x->compareTo(xMin)) >= 0 & (y->compareTo(yMin)) >= 0) then  (
      ans := i ;
    break
    )
    else (
      i := i + 1
      ) ;
    yMax := yMax + fibo[i+1] ;
    if ((x->compareTo(xMax)) <= 0 & (y->compareTo(yMax)) <= 0 & (x->compareTo(xMin)) >= 0 & (y->compareTo(yMin)) >= 0) then  (
      ans := i ;
    break
    )
    else (
      i := i + 1
      ) ;
    xMin := xMin - fibo[i+1] ;
    if ((x->compareTo(xMax)) <= 0 & (y->compareTo(yMax)) <= 0 & (x->compareTo(xMin)) >= 0 & (y->compareTo(yMin)) >= 0) then  (
      ans := i ;
    break
    )
    else (
      i := i + 1
      ) ;
    yMin := yMin - fibo[i+1] ;
    if ((x->compareTo(xMax)) <= 0 & (y->compareTo(yMax)) <= 0 & (x->compareTo(xMin)) >= 0 & (y->compareTo(yMin)) >= 0) then  (
      ans := i ;
    break
    )
    else (
      i := i + 1
      ))
      ) ;
    ans := ans mod 3 ;
    if ans = 0 then (
      ans := 3
    ) else skip ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
I=lambda : map(int,input().split(':'))
h,m=I()
dh,dm=I()
h,m=h-dh,m-dm
h,m=(h+m//60)% 24,m % 60
print(f'{h:02}:{m:02}')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var I : Function := lambda $$ : OclAny in ((input().split(':'))->collect( _x | (OclType["int"])->apply(_x) )) ;
    var h : OclAny := null;
    var m : OclAny := null;
    Sequence{h,m} := I->apply() ;
    var dh : OclAny := null;
    var dm : OclAny := null;
    Sequence{dh,dm} := I->apply() ;
    var h : OclAny := null;
    var m : OclAny := null;
    Sequence{h,m} := Sequence{h - dh,m - dm} ;
    var h : OclAny := null;
    var m : OclAny := null;
    Sequence{h,m} := Sequence{(h + m div 60) mod 24,m mod 60} ;
    execute (StringLib.formattedString('{h:02}:{m:02}'))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
DESCRIPTION="""
"""
import os
import sys
import argparse
def perr(msg):
    sys.stderr.write("%s" % msg)
    sys.stderr.flush()
def pinfo(msg):
    sys.stdout.write("%s" % msg)
    sys.stdout.flush()
def runcmd(cmd):
    perr("%s\n" % cmd)
    os.system(cmd)
def getargs():
    parser=argparse.ArgumentParser(description=DESCRIPTION,formatter_class=argparse.RawTextHelpFormatter)
    parser.add_argument('infile',type=str,help='input file')
    parser.add_argument('outfile',type=str,nargs='?',default=None,help='output file')
    return parser.parse_args()
def solve(Smax,Scnt):
    ret=0
    acc=Scnt[0]
    for i in range(1,len(Scnt)):
        rest=i-acc
        if rest>0 :
            ret+=rest
            acc+=rest
        acc+=Scnt[i]
    return ret
def main(args):
    if None==args.outfile :
        outfile=sys.stdout
    else :
        outfile=open(args.outfile,"w")
    with open(args.infile)as infile :
        T=int(infile.readline())
        for i in range(1,T+1):
[Smax,Scnt]=infile.readline().split()
            Smax=int(Smax)
            Scnt=[int(cnt)for cnt in list(Scnt)]
            outfile.write("Case #%d: %d\n" %(i,solve(Smax,Scnt)))
    if None!=args.outfile :
        outfile.close()
if __name__=='__main__' :
    main(getargs())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
suite`nestedAttributeDefinitions
  operation initialise()
  pre: true post: true
  activity:     var DESCRIPTION : String := (atom "" "\r\n" "") ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    Sequence{Smax}->union(Sequence{ Scnt }) := infile.readLine().split();
  operation perr(msg : OclAny)
  pre: true post: true
  activity:
(expr (atom (name sys)) (trailer . (name stderr)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom "%s")) % (expr (atom (name msg))))))))) )))) ;
(expr (atom (name sys)) (trailer . (name stderr)) (trailer . (name flush) (arguments ( ))));
  operation pinfo(msg : OclAny)
  pre: true post: true
  activity:
(expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom "%s")) % (expr (atom (name msg))))))))) )))) ;
(expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( ))));
  operation runcmd(cmd : OclAny)
  pre: true post: true
  activity:
    perr(StringLib.format("%s\n",cmd)) ;
    os.system(cmd);
  operation getargs() : OclAny
  pre: true post: true
  activity:
    var parser : OclAny := argparse.ArgumentParser((argument (test (logical_test (comparison (expr (atom (name description)))))) = (test (logical_test (comparison (expr (atom (name DESCRIPTION))))))), (argument (test (logical_test (comparison (expr (atom (name formatter_class)))))) = (test (logical_test (comparison (expr (atom (name argparse)) (trailer . (name RawTextHelpFormatter)))))))) ;
    parser.add_argument('infile', (argument (test (logical_test (comparison (expr (atom (name type)))))) = (test (logical_test (comparison (expr (atom (name str))))))), (argument (test (logical_test (comparison (expr (atom (name help)))))) = (test (logical_test (comparison (expr (atom 'input file'))))))) ;
    parser.add_argument('outfile', (argument (test (logical_test (comparison (expr (atom (name type)))))) = (test (logical_test (comparison (expr (atom (name str))))))), (argument (test (logical_test (comparison (expr (atom (name nargs)))))) = (test (logical_test (comparison (expr (atom '?')))))), (argument (test (logical_test (comparison (expr (atom (name default)))))) = (test (logical_test (comparison (expr (atom None)))))), (argument (test (logical_test (comparison (expr (atom (name help)))))) = (test (logical_test (comparison (expr (atom 'output file'))))))) ;
    return parser.parse_args();
  operation solve(Smax : OclAny, Scnt : OclAny) : OclAny
  pre: true post: true
  activity:
    var ret : int := 0 ;
    var acc : OclAny := Scnt->first() ;
    for i : Integer.subrange(1, (Scnt)->size()-1) do (    var rest : double := i - acc ;
    if rest > 0 then (
      ret := ret + rest ;
    acc := acc + rest
    ) else skip ;
    acc := acc + Scnt[i+1]) ;
    return ret;
  operation main(args : OclAny)
  pre: true post: true
  activity:
    if null = args.outfile then  (
      var outfile : OclFile := OclFile["System.out"]
    )
    else (
      outfile := OclFile.newOclFile_Write(OclFile.newOclFile(args.outfile))
      ) ;
    try (var infile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(args.infile));
    var T : int := ("" + ((infile.readLine())))->toInteger() ;
    for i : Integer.subrange(1, T + 1-1) do (suite))
    catch (_e : OclException) do skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    n=int(input())
    a=[input(),input()]
    inf=1<<30
    b=[-inf,0,-inf,-inf]
    for i in range(n):
        c=[-inf,-inf,-inf,-inf]
        for j in range(4):
            c[j>>1]=max(c[j>>1],b[j])
        if a[1][i]=='1' :
            for j in range(4):
                if(j & 0x01)==0 and a[0][i-1]=='1' :
                    c[j>>1]=max(c[j>>1],b[j]+1)
                if(j & 0x02)==0 and a[0][i]=='0' :
                    c[(j>>1)+1]=max(c[(j>>1)+1],b[j]+1)
                if i+1>1)+2]=max(c[(j>>1)+2],b[j]+1)
        b=c
    print(max(b))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := Sequence{(OclFile["System.in"]).readLine()}->union(Sequence{ (OclFile["System.in"]).readLine() }) ;
    var Math_PINFINITY : int := 1 * (2->pow(30)) ;
    var b : Sequence := Sequence{-Math_PINFINITY}->union(Sequence{0}->union(Sequence{-Math_PINFINITY}->union(Sequence{ -Math_PINFINITY }))) ;
    for i : Integer.subrange(0, n-1) do (    var c : Sequence := Sequence{-Math_PINFINITY}->union(Sequence{-Math_PINFINITY}->union(Sequence{-Math_PINFINITY}->union(Sequence{ -Math_PINFINITY }))) ;
    for j : Integer.subrange(0, 4-1) do (    c[j /(2->pow(1))+1] := Set{c[j /(2->pow(1))+1], b[j+1]}->max()) ;
    if a[1+1][i+1] = '1' then (
      for j : Integer.subrange(0, 4-1) do (    if (MathLib.bitwiseAnd(j, 0x01)) = 0 & a->first()[i - 1+1] = '1' then (
      c[j /(2->pow(1))+1] := Set{c[j /(2->pow(1))+1], b[j+1] + 1}->max()
    ) else skip ;
    if (MathLib.bitwiseAnd(j, 0x02)) = 0 & a->first()[i+1] = '0' then (
      c[(j /(2->pow(1))) + 1+1] := Set{c[(j /(2->pow(1))) + 1+1], b[j+1] + 1}->max()
    ) else skip ;
    if (i + 1->compareTo(n)) < 0 & a->first()[i + 1+1] = '1' then (
      c[(j /(2->pow(1))) + 2+1] := Set{c[(j /(2->pow(1))) + 2+1], b[j+1] + 1}->max()
    ) else skip)
    ) else skip ;
    b := c) ;
    execute ((b)->max())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
f_in=open('file.in')
f_out=open('file.out','w')
cases=int(f_in.readline())
for i in range(1,cases+1):
    shynesses=f_in.readline().split()[1]
    shynesses=[int(i)for i in list(shynesses)]
    friends=0
    current=0
    for j in range(0,len(shynesses)):
        if currenttoInteger() ;
    for i : Integer.subrange(1, cases + 1-1) do (    var shynesses : OclAny := f_in.readLine().split()[1+1] ;
    shynesses := (shynesses)->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var friends : int := 0 ;
    var current : int := 0 ;
    for j : Integer.subrange(0, (shynesses)->size()-1) do (    if (current->compareTo(j)) < 0 & shynesses[j+1] /= 0 then (
      friends := friends + j - current ;
    current := current + j - current
    ) else skip ;
    current := current + shynesses[j+1]) ;
    f_out.write("Case #" + ("" + ((i))) + ": " + ("" + ((friends))) + "\n"));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
T=int(input())
for t in range(1,T+1):
    N,S=input().split()
    answer,alive,N=0,int(S[0]),int(N)
    for n in range(1,N+1):
        if S[n]=='0' : continue
        if alivetoInteger() ;
    for t : Integer.subrange(1, T + 1-1) do (    var N : OclAny := null;
    var S : OclAny := null;
    Sequence{N,S} := input().split() ;
    var answer : OclAny := null;
    var alive : OclAny := null;
    var N : OclAny := null;
    Sequence{answer,alive,N} := Sequence{0,("" + ((S->first())))->toInteger(),("" + ((N)))->toInteger()} ;
    for n : Integer.subrange(1, N + 1-1) do (    if S[n+1] = '0' then (
      continue
    ) else skip ;
    if (alive->compareTo(n)) < 0 then (
      answer := answer + n - alive ;
    var alive : OclAny := n
    ) else skip ;
    alive := alive + ("" + ((S[n+1])))->toInteger()) ;
    execute (StringLib.interpolateStrings('Case #{}:{}', Sequence{t, answer}))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def numberneeded(lst):
    invites=0
    standing=0
    for i in range(len(lst)):
        if lst[i]!=0 and standingselect(line | true)->collect(line | (line->trim())) ;
    try (var fileOUT : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ]))));
    var numberOfCases : int := ("" + ((inputLines->at(0`firstArg+1))))->toInteger() ;
    for num : Integer.subrange(0, numberOfCases-1) do (    var inputstring : OclAny := inputLines->at(0`firstArg+1).rstrip().split(' ')[1+1] ;
    var inputlist : Sequence := (inputstring)->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    fileOUT.write('Case #' + ("" + ((num + 1))) + ': ' + ("" + ((numberneeded(inputlist)))) + '
')))
    catch (_e : OclException) do skip;
  operation numberneeded(lst : OclAny) : OclAny
  pre: true post: true
  activity:
    var invites : int := 0 ;
    var standing : int := 0 ;
    for i : Integer.subrange(0, (lst)->size()-1) do (    if lst[i+1] /= 0 & (standing->compareTo(i)) < 0 then (
      invites := invites + (i - standing) ;
    standing := standing + (i - standing)
    ) else skip ;
    standing := standing + lst[i+1]) ;
    return (invites);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
import sys
def findsol(S,Smax):
    b=0
    c=0
    for ii in range(len(S)):
        c+=S[ii]
        if(ii-c+1>b):
            b=ii-c+1
    return b
def convertnums(s):
    a=[]
    ii=0
    for jj in range(len(s)):
        if s[jj]=='' :
            if(iitoInteger() ;
    for ii : Integer.subrange(1, T + 1-1) do (    var tmp : String := fidi.readLine() ;
    var jj : int := tmp->indexOf('') - 1 ;
    Smax := ("" + ((tmp.subrange(0+1, jj))))->toInteger() ;
    S := Sequence{} ;
    for kk : Integer.subrange(jj + 1, (tmp)->size()-1) do (    try (    execute ((("" + ((tmp[kk+1])))->toInteger()) : S))
     catch (_e : OclException) do (    execute ('')->display())
) ;
    a := findsol(S, Smax) ;
    fido.write('Case #' + ("" + ((ii))) + ': ' + ("" + ((a))) + '
') ;
    execute ('Case #')->display()) ;
    fidi.closeFile() ;
    fido.closeFile();
  operation findsol(S : OclAny, Smax : OclAny) : OclAny
  pre: true post: true
  activity:
    var b : int := 0 ;
    var c : int := 0 ;
    for ii : Integer.subrange(0, (S)->size()-1) do (    c := c + S[ii+1] ;
    if ((ii - c + 1->compareTo(b)) > 0) then (
      b := ii - c + 1
    ) else skip) ;
    return b;
  operation convertnums(s : OclAny) : OclAny
  pre: true post: true
  activity:
    var a : Sequence := Sequence{} ;
    var ii : int := 0 ;
    for jj : Integer.subrange(0, (s)->size()-1) do (    if s[jj+1] = '' then (
      if ((ii->compareTo(jj)) < 0) then (
      execute ((("" + ((s.subrange(ii+1, jj))))->toInteger()) : a) ;
    ii := jj + 1
    ) else skip
    ) else skip) ;
    execute ((("" + ((s.subrange(ii+1, jj))))->toInteger()) : a) ;
    return a;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
power=[0]*31
pre=[0]*31
def PowerOfTwo():
    x=1
    for i in range(31):
        power[i]=x
        x*=2
    pre[0]=1
    for i in range(1,31):
        pre[i]=pre[i-1]+power[i]
def Sum(n):
    ans=n*(n+1)//2
    for i in range(31):
        if(power[i]>n):
            ans-=2*pre[i-1]
            break
    return ans
if __name__=="__main__" :
    PowerOfTwo()
    n=4
    print(Sum(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var power : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 31) ;
    var pre : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 31) ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      PowerOfTwo() ;
    n := 4 ;
    execute (Sum(n))->display()
    ) else skip;
  operation PowerOfTwo()
  pre: true post: true
  activity:
    var x : int := 1 ;
    for i : Integer.subrange(0, 31-1) do (    power[i+1] := x ;
    x := x * 2) ;
    pre->first() := 1 ;
    for i : Integer.subrange(1, 31-1) do (    pre[i+1] := pre[i - 1+1] + power[i+1]);
  operation Sum(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var ans : int := n * (n + 1) div 2 ;
    for i : Integer.subrange(0, 31-1) do (    if ((power[i+1]->compareTo(n)) > 0) then (
      ans := ans - 2 * pre[i - 1+1] ;
    break
    ) else skip) ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while 1 :
    try : n,m=map(int,input().split());
    except : break
    rs=[]
    while 1 :
        line=input()
        if line=="0 0 0" : break
        s,t,e=map(int,line.split())
        rs.append((s-1,t-1,e))
    l=int(input())
    b=[list(map(int,input().split()))for _ in range(l)]
    c=[[0]*n for _ in range(l)]
    for s,t,e in rs :
        for i in range(l):
            c[i][s]+=b[i][t]*e
    for i in range(l):
        print(" ".join(str(x)for x in c[i]))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while 1 do (    try (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) );)
     catch (_e : OclException) do (    break)
 ;
    var rs : Sequence := Sequence{} ;
    while 1 do (    var line : String := (OclFile["System.in"]).readLine() ;
    if line = "0 0 0" then (
      break
    ) else skip ;
    var s : OclAny := null;
    var t : OclAny := null;
    var e : OclAny := null;
    Sequence{s,t,e} := (line.split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute ((Sequence{s - 1, t - 1, e}) : rs)) ;
    var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var b : Sequence := Integer.subrange(0, l-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var c : Sequence := Integer.subrange(0, l-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, n))) ;
    for _tuple : rs do (var _indx : int := 1;
      var s : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var t : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var e : OclAny := _tuple->at(_indx);
      for i : Integer.subrange(0, l-1) do (    c[i+1][s+1] := c[i+1][s+1] + b[i+1][t+1] * e)) ;
    for i : Integer.subrange(0, l-1) do (    execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))), " "))->display()));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def solve(N,M,log):
    prices=[int(p)for p in input().split()]
    res=[dict()for _ in range(N+1)]
    for s,t,e in log :
        res[s][t]=res[s].get(t,0)+e
    return[sum([prices[k-1]*v for k,v in r.items()])for r in res[1 :]]
def main(args):
    N,M=map(int,input().split())
    log=[]
    while True :
        s,t,e=map(int,input().split())
        if s==0 and t==0 and e==0 :
            break
        log.append((s,t,e))
    L=int(input())
    for _ in range(L):
        ans=solve(N,M,log)
        print(*ans,sep=' ')
if __name__=='__main__' :
    main(sys.argv[1 :])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))
    ) else skip;
  operation solve(N : OclAny, M : OclAny, log : OclAny) : OclAny
  pre: true post: true
  activity:
    var prices : Sequence := input().split()->select(p | true)->collect(p | (("" + ((p)))->toInteger())) ;
    var res : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | ((arguments ( )))) ;
    for _tuple : log do (var _indx : int := 1;
      var s : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var t : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var e : OclAny := _tuple->at(_indx);
      res[s+1][t+1] := res[s+1].get(t, 0) + e) ;
    return res->tail()->select(r | true)->collect(r | ((r->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->select(_tuple | true)->collect(_tuple | let k : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in (prices[k - 1+1] * v)))->sum()));
  operation main(args : OclAny)
  pre: true post: true
  activity:
    Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    log := Sequence{} ;
    while true do (    var s : OclAny := null;
    var t : OclAny := null;
    var e : OclAny := null;
    Sequence{s,t,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if s = 0 & t = 0 & e = 0 then (
      break
    ) else skip ;
    execute ((Sequence{s, t, e}) : log)) ;
    var L : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, L-1) do (    var ans : OclAny := solve(N, M, log) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def mul(v,u):
    s=0
    for i in range(len(u)):
        s+=v[u[i][0]]*u[i][1]
    return s
[n,m]=list(map(int,input().split()))
t=[[]for j in range(n)]
while True :
    d=list(map(int,input().split()))
    if d==[0,0,0]:
        break
    else :
        t[d[0]-1].append([d[1]-1,d[2]])
c=int(input())
p=[list(map(int,input().split()))for i in range(c)]
for i in range(c):
    r=[]
    for j in range(n):
        r.append(mul(p[i],t[j]))
    print(" ".join(map(str,r)))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    Sequence{n}->union(Sequence{ m }) := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var t : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (Sequence{})) ;
    while true do (    var d : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if d = Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) then  (
      break
    )
    else (
  (expr (atom (name t)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) - (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ]))))))) ]))))))) ))))
      )) ;
    var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var p : Sequence := Integer.subrange(0, c-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    for i : Integer.subrange(0, c-1) do (    var r : Sequence := Sequence{} ;
    for j : Integer.subrange(0, n-1) do (    execute ((mul(p[i+1], t[j+1])) : r)) ;
    execute (StringLib.sumStringsWithSeparator(((r)->collect( _x | (OclType["String"])->apply(_x) )), " "))->display());
  operation mul(v : OclAny, u : OclAny) : OclAny
  pre: true post: true
  activity:
    var s : int := 0 ;
    for i : Integer.subrange(0, (u)->size()-1) do (    s := s + v[u[i+1]->first()+1] * u[i+1][1+1]) ;
    return s;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
hs,ms=map(int,input().split(":"))
ht,mt=map(int,input().split(":"))
if ht<=hs :
    hs-=ht
    if mt<=ms :
        ms-=mt
    elif hs>0 :
        hs-=1
        x=60-mt
        if x+ms<60 :
            ms+=x
        else :
            hs+=1
            ms=(ms+x)-60
    elif hs==0 :
        hs=23
        x=60-mt
        if x+ms<60 :
            ms+=x
        else :
            hs=00
            ms=(ms+x)-60
elif ht>hs :
    hs=24-(ht-hs)
    if mt<=ms :
        ms-=mt
    elif hs>0 :
        hs-=1
        x=60-mt
        if x+ms<60 :
            ms+=x
        else :
            hs+=1
            ms=(ms+x)-60
    elif hs==0 :
        hs=23
        x=60-mt
        if x+ms<60 :
            ms+=x
        else :
            hs=00
            ms=(ms+x)-60
if hs<10 and ms<10 :
    print(f"0{hs}:0{ms}")
elif hs>=10 and ms<10 :
    print(f"{hs}:0{ms}")
elif hs<10 and ms>=10 :
    print(f"0{hs}:{ms}")
else : print(f"{hs}:{ms}")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var hs : OclAny := null;
    var ms : OclAny := null;
    Sequence{hs,ms} := (input().split(":"))->collect( _x | (OclType["int"])->apply(_x) ) ;
    var ht : OclAny := null;
    var mt : OclAny := null;
    Sequence{ht,mt} := (input().split(":"))->collect( _x | (OclType["int"])->apply(_x) ) ;
    if (ht->compareTo(hs)) <= 0 then  (
      hs := hs - ht ;
    if (mt->compareTo(ms)) <= 0 then  (
      ms := ms - mt
    )
    else (if hs > 0 then
   (
      hs := hs - 1 ;
    var x : double := 60 - mt ;
    if x + ms < 60 then  (
      ms := ms + x
    )
    else (
      hs := hs + 1 ;
    var ms : double := (ms + x) - 60
      )    
)
    else (if hs = 0 then
   (
      var hs : int := 23 ;
    x := 60 - mt ;
    if x + ms < 60 then  (
      ms := ms + x
    )
    else (
      hs := 00 ;
    ms := (ms + x) - 60
      )    
)
    else skip    )
    )
    )
    else (if (ht->compareTo(hs)) > 0 then
   (
      hs := 24 - (ht - hs) ;
    if (mt->compareTo(ms)) <= 0 then  (
      ms := ms - mt
    )
    else (if hs > 0 then
   (
      hs := hs - 1 ;
    x := 60 - mt ;
    if x + ms < 60 then  (
      ms := ms + x
    )
    else (
      hs := hs + 1 ;
    ms := (ms + x) - 60
      )    
)
    else (if hs = 0 then
   (
      hs := 23 ;
    x := 60 - mt ;
    if x + ms < 60 then  (
      ms := ms + x
    )
    else (
      hs := 00 ;
    ms := (ms + x) - 60
      )    
)
    else skip    )
    )
)
 else skip) ;
    if hs < 10 & ms < 10 then  (
      execute (StringLib.formattedString("0{hs}:0{ms}"))->display()
    )
    else (if hs >= 10 & ms < 10 then
   (
      execute (StringLib.formattedString("{hs}:0{ms}"))->display()    
)
    else (if hs < 10 & ms >= 10 then
   (
      execute (StringLib.formattedString("0{hs}:{ms}"))->display()    
)
    else (
      execute (StringLib.formattedString("{hs}:{ms}"))->display()
      )    )
    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
readline=sys.stdin.readline
write=sys.stdout.write
N,M=map(int,readline().split())
P=[]
while 1 :
    s,t,e=map(int,readline().split())
    if e==0 :
        break
    P.append((s-1,t-1,e))
L=int(readline())
B=[list(map(int,readline().split()))for i in range(L)]
C=[[0]*N for i in range(L)]
for k in range(L):
    ck=C[k]; bk=B[k]
    for s,t,e in P :
        ck[s]+=bk[t]*e
    write(' '.join(map(str,ck)))
    write('\n')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var readline : OclAny := (OclFile["System.in"]).readline ;
    var write : OclAny := (OclFile["System.out"]).write ;
    var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var P : Sequence := Sequence{} ;
    while 1 do (    var s : OclAny := null;
    var t : OclAny := null;
    var e : OclAny := null;
    Sequence{s,t,e} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if e = 0 then (
      break
    ) else skip ;
    execute ((Sequence{s - 1, t - 1, e}) : P)) ;
    var L : int := ("" + ((readline())))->toInteger() ;
    var B : Sequence := Integer.subrange(0, L-1)->select(i | true)->collect(i | (((readline().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var C : Sequence := Integer.subrange(0, L-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, N))) ;
    for k : Integer.subrange(0, L-1) do (    var ck : OclAny := C[k+1];    var bk : OclAny := B[k+1] ;
    for _tuple : P do (var _indx : int := 1;
      var s : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var t : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var e : OclAny := _tuple->at(_indx);
      ck[s+1] := ck[s+1] + bk[t+1] * e) ;
    write(StringLib.sumStringsWithSeparator(((ck)->collect( _x | (OclType["String"])->apply(_x) )), ' ')) ;
    write('
'));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    n,m=map(int,input().split())
    works=[[]for _ in range(n+1)]
    while True :
        s,t,e=map(int,input().split())
        if s==0 :
            break
        works[s-1].append((t-1,e))
    l=int(input())
    for _ in range(l):
        blst=tuple(map(int,input().split()))
        print(*[sum([blst[t]*e for t,e in works[i]])for i in range(n)])
main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    main();
  operation main()
  pre: true post: true
  activity:
    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var works : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ;
    while true do (    var s : OclAny := null;
    var t : OclAny := null;
    var e : OclAny := null;
    Sequence{s,t,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if s = 0 then (
      break
    ) else skip ;
(expr (atom (name works)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name s))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name t))) - (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (atom (name e))))))) )))))))) ))))) ;
    var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, l-1) do (    var blst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name blst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ]))) * (expr (atom (name e))))))) (comp_for for (exprlist (expr (atom (name t))) , (expr (atom (name e)))) in (logical_test (comparison (expr (atom (name works)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) ]))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) ])))))))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=lambda : sys.stdin.readline().strip()
for _ in range(int(input())):
    n=int(input())
    a1=input()
    b1=input()
    a=['2']
    b=['2']
    for i in range(n):
        a.append(a1[i])
        b.append(b1[i])
    a.append('2')
    b.append('2')
    count=0
    for i in range(1,n+1):
        if b[i]=='1' and a[i]=='0' :
            a[i]='2'
            count+=1
        elif b[i]=='1' and a[i-1]=='1' :
            a[i-1]='2'
            count+=1
        elif b[i]=='1' and a[i+1]=='1' :
            a[i+1]='2'
            count+=1
    print(count)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : Function := lambda $$ : OclAny in (sys.stdin.readLine()->trim()) ;
    for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a1 : String := (OclFile["System.in"]).readLine() ;
    var b1 : String := (OclFile["System.in"]).readLine() ;
    var a : Sequence := Sequence{ '2' } ;
    var b : Sequence := Sequence{ '2' } ;
    for i : Integer.subrange(0, n-1) do (    execute ((a1[i+1]) : a) ;
    execute ((b1[i+1]) : b)) ;
    execute (('2') : a) ;
    execute (('2') : b) ;
    var count : int := 0 ;
    for i : Integer.subrange(1, n + 1-1) do (    if b[i+1] = '1' & a[i+1] = '0' then  (
      a[i+1] := '2' ;
    count := count + 1
    )
    else (if b[i+1] = '1' & a[i - 1+1] = '1' then
   (
      a[i - 1+1] := '2' ;
    count := count + 1    
)
    else (if b[i+1] = '1' & a[i + 1+1] = '1' then
   (
      a[i + 1+1] := '2' ;
    count := count + 1    
)
    else skip    )
    )
) ;
    execute (count)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
pos=0
flag=True
for _ in range(n):
    k,num=input().split()
    num=int(num)
    if k=="(" :
        pos+=num
    else :
        pos-=num
    if pos<0 :
        flag=False
if not flag or pos!=0 :
    print("NO")
else :
    print("YES")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var pos : int := 0 ;
    var flag : boolean := true ;
    for _anon : Integer.subrange(0, n-1) do (    var k : OclAny := null;
    var num : OclAny := null;
    Sequence{k,num} := input().split() ;
    var num : int := ("" + ((num)))->toInteger() ;
    if k = "(" then  (
      pos := pos + num
    )
    else (
      pos := pos - num
      ) ;
    if pos < 0 then (
      flag := false
    ) else skip) ;
    if not(flag) or pos /= 0 then  (
      execute ("NO")->display()
    )
    else (
      execute ("YES")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=0
for _ in range(int(input())):
    b,c=input().split()
    a+=int(c)if b=='(' else-int(c)
    if a<0 : print('NO'); break
else : print('NO' if a else 'YES')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : int := 0 ;
(compound_stmt for (exprlist (expr (atom (name _)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name b)))))) , (test (logical_test (comparison (expr (atom (name c))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name a)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))))) if (logical_test (comparison (comparison (expr (atom (name b)))) == (comparison (expr (atom '('))))) else (test (logical_test (comparison (expr - (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name a)))) < (comparison (expr (atom (number (integer 0)))))))) : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) )))))))))) ; (small_stmt break)))))) (else_clause else : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO')))) if (logical_test (comparison (expr (atom (name a))))) else (test (logical_test (comparison (expr (atom 'YES')))))))) )))))))))) ))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
s=0
f=0
for i in range(n):
    p,x=input().split()
    x=int(x)
    if p=="(" :
        s+=x
    else :
        s-=x
        if s<0 :
            f=1
if f or s!=0 :
    print("NO")
else :
    print("YES")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : int := 0 ;
    var f : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    var p : OclAny := null;
    var x : OclAny := null;
    Sequence{p,x} := input().split() ;
    var x : int := ("" + ((x)))->toInteger() ;
    if p = "(" then  (
      s := s + x
    )
    else (
      s := s - x ;
    if s < 0 then (
      f := 1
    ) else skip
      )) ;
    if f or s /= 0 then  (
      execute ("NO")->display()
    )
    else (
      execute ("YES")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a,b=0,0
flag=0
for i in range(n):
    p,x=map(str,input().split())
    if p=="(" : a+=int(x)
    else : b+=int(x)
    if atoInteger() ;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := Sequence{0,0} ;
    var flag : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    var p : OclAny := null;
    var x : OclAny := null;
    Sequence{p,x} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ;
    if p = "(" then  (
      a := a + ("" + ((x)))->toInteger()
    )
    else (
      b := b + ("" + ((x)))->toInteger()
      ) ;
    if (a->compareTo(b)) < 0 then (
      flag := 1 ;
    break
    ) else skip) ;
    if flag = 1 or a /= b then  (
      execute ("NO")->display()
    )
    else (
      execute ("YES")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
b=0
ans=True
for _ in range(n):
    p,x=input().split()
    x=int(x)
    if p=="(" :
        b+=x
    else :
        b-=x
        if b<0 :
            ans=False
if ans :
    if b==0 :
        print("YES")
    else :
        print("NO")
else :
    print("NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var b : int := 0 ;
    var ans : boolean := true ;
    for _anon : Integer.subrange(0, n-1) do (    var p : OclAny := null;
    var x : OclAny := null;
    Sequence{p,x} := input().split() ;
    var x : int := ("" + ((x)))->toInteger() ;
    if p = "(" then  (
      b := b + x
    )
    else (
      b := b - x ;
    if b < 0 then (
      ans := false
    ) else skip
      )) ;
    if ans then  (
      if b = 0 then  (
      execute ("YES")->display()
    )
    else (
      execute ("NO")->display()
      )
    )
    else (
      execute ("NO")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    t=[]
    n=int(input())
    if n==0 :
        break
    else :
        m=input().strip().split()
        k=[int(i)for i in m]
        x=sum(k)/n
        for i in range(n):
            if k[i]<=x :
                t.append(k[i])
            else :
                pass
        print(len(t))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    var t : Sequence := Sequence{} ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then  (
      break
    )
    else (
      var m : OclAny := input()->trim().split() ;
    var k : Sequence := m->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var x : double := (k)->sum() / n ;
    for i : Integer.subrange(0, n-1) do (    if (k[i+1]->compareTo(x)) <= 0 then  (
      execute ((k[i+1]) : t)
    )
    else (
      skip
      )) ;
    execute ((t)->size())->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    num=int(input())
    if num==0 :
        break
    L=[int(x)for x in input().split()]
    ave=sum(L)/len(L)
    c=0
    for i in L :
        if i<=ave :
            c+=1
    print(c)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if num = 0 then (
      break
    ) else skip ;
    var L : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    var ave : double := (L)->sum() / (L)->size() ;
    var c : int := 0 ;
    for i : L do (    if (i->compareTo(ave)) <= 0 then (
      c := c + 1
    ) else skip) ;
    execute (c)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main_function():
    n=int(input())
    a=[int(i)for i in input().split(" ")]
    current_level=0
    counter=0
    counter_turns=-1
    while countertoInteger() ;
    var a : Sequence := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var current_level : int := 0 ;
    var counter : int := 0 ;
    var counter_turns : int := -1 ;
    while (counter->compareTo((a)->size())) < 0 do (    counter_turns := counter_turns + 1 ;
    for i : Integer.subrange(0, (a)->size()-1) do (    if a[i+1] /= -1 & (a[i+1]->compareTo(counter)) <= 0 then (
      counter := counter + 1 ;
    a[i+1] := -1
    ) else skip) ;
    a := a->reverse()) ;
    execute (counter_turns)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def longestAlternatingSubarray(a,n):
    longest=1
    cnt=1
    i=1
    while iunion(Sequence{-1}->union(Sequence{-1}->union(Sequence{2}->union(Sequence{-2}->union(Sequence{ -3 }))))) ;
    n := (a)->size() ;
    execute (longestAlternatingSubarray(a, n))->display();
  operation longestAlternatingSubarray(a : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var longest : int := 1 ;
    var cnt : int := 1 ;
    var i : int := 1 ;
    while (i->compareTo(n)) < 0 do (    if (a[i+1] * a[i - 1+1] < 0) then  (
      cnt := cnt + 1 ;
    longest := Set{longest, cnt}->max()
    )
    else (
      cnt := 1
      ) ;
    i := i + 1) ;
    return longest;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def solve(n):
    a=list(map(int,input().split()))
    ave=sum(a)/n
    count=0
    for i in a :
        if i<=ave :
            count+=1
    print(count)
def main():
    while(True):
        n=int(input())
        if n==0 :
            sys.exit(0)
        else :
            solve(n)
main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    main();
  operation solve(n : OclAny)
  pre: true post: true
  activity:
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var ave : double := (a)->sum() / n ;
    var count : int := 0 ;
    for i : a do (    if (i->compareTo(ave)) <= 0 then (
      count := count + 1
    ) else skip) ;
    execute (count)->display();
  operation main()
  pre: true post: true
  activity:
    while (true) do (    n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then  (
      sys.exit(0)
    )
    else (
      solve(n)
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
while n!=0 :
    list=input().split()
    for i in range(len(list)):
        list[i]=int(list[i])
    avgs=sum(list)/n
    i=0
    a=0
    for i in range(len(list)):
        if list[i]<=avgs :
            a=a+1
    print(a)
    n=int(input())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    while n /= 0 do (    var OclType["Sequence"] : OclAny := input().split() ;
    for i : Integer.subrange(0, (OclType["Sequence"])->size()-1) do (    [i+1] := ("" + (([i+1])))->toInteger()) ;
    var avgs : double := (OclType["Sequence"])->sum() / n ;
    var i : int := 0 ;
    var a : int := 0 ;
    for i : Integer.subrange(0, (OclType["Sequence"])->size()-1) do (    if ([i+1]->compareTo(avgs)) <= 0 then (
      a := a + 1
    ) else skip) ;
    execute (a)->display() ;
    n := ("" + (((OclFile["System.in"]).readLine())))->toInteger());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    n=int(input())
    if n==0 : break
    xs=list(map(int,input().split()))
    ave=sum(xs)/n
    print(sum(1 for x in xs if x<=ave))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    var xs : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var ave : double := (xs)->sum() / n ;
    execute (((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name xs))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name x)))) <= (comparison (expr (atom (name ave)))))))))))->sum())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    n,sol=int(input()),0
    a=list(map(int,input()))
    b=list(map(int,input()))
    for i in range(n):
        if b[i]:
            if a[i]:
                if i-1>=0 and a[i-1]:
                    a[i-1]=0
                    sol+=1
                elif i+1toInteger()-1) do (    var n : OclAny := null;
    var sol : OclAny := null;
    Sequence{n,sol} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),0} ;
    var a : Sequence := (((OclFile["System.in"]).readLine())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var b : Sequence := (((OclFile["System.in"]).readLine())->collect( _x | (OclType["int"])->apply(_x) )) ;
    for i : Integer.subrange(0, n-1) do (    if b[i+1] then (
      if a[i+1] then  (
      if i - 1 >= 0 & a[i - 1+1] then  (
      a[i - 1+1] := 0 ;
    sol := sol + 1
    )
    else (if (i + 1->compareTo(n)) < 0 & a[i + 1+1] then
   (
      a[i + 1+1] := 0 ;
    sol := sol + 1    
)
 else skip)
    )
    else (
      sol := sol + 1
      )
    ) else skip) ;
    execute (sol)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def firstZero(arr,low,high):
    if(high>=low):
        mid=low+int((high-low)/2)
        if((mid==0 or arr[mid-1]==1)and arr[mid]==0):
            return mid
        if(arr[mid]==1):
            return firstZero(arr,(mid+1),high)
        else :
            return firstZero(arr,low,(mid-1))
    return-1
def countZeroes(arr,n):
    first=firstZero(arr,0,n-1)
    if(first==-1):
        return 0
    return(n-first)
arr=[1,1,1,0,0,0,0,0]
n=len(arr)
print("Count of zeroes is",countZeroes(arr,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    arr := Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))))))) ;
    n := (arr)->size() ;
    execute ("Count of zeroes is")->display();
  operation firstZero(arr : OclAny, low : OclAny, high : OclAny) : OclAny
  pre: true post: true
  activity:
    if ((high->compareTo(low)) >= 0) then (
      var mid : OclAny := low + ("" + (((high - low) / 2)))->toInteger() ;
    if ((mid = 0 or arr[mid - 1+1] = 1) & arr[mid+1] = 0) then (
      return mid
    ) else skip ;
    if (arr[mid+1] = 1) then  (
      return firstZero(arr, (mid + 1), high)
    )
    else (
      return firstZero(arr, low, (mid - 1))
      )
    ) else skip ;
    return -1;
  operation countZeroes(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var first : OclAny := firstZero(arr, 0, n - 1) ;
    if (first = -1) then (
      return 0
    ) else skip ;
    return (n - first);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    x=int(input())
    a=x//500
    b=x % 500
    c=b//5
    ans=1000*a+5*c
    print(ans)
main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    main();
  operation main()
  pre: true post: true
  activity:
    var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : int := x div 500 ;
    var b : int := x mod 500 ;
    var c : int := b div 5 ;
    var ans : int := 1000 * a + 5 * c ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys,math,itertools,collections,bisect
input=lambda : sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf=float('inf'); mod=10**9+7
mans=inf ; ans=0 ; count=0 ; pro=1
x=int(input())
ans+=1000*(x//500)
x %=500
ans+=5*(x//5)
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : Function := lambda $$ : OclAny in (sys.stdin.buffer.readLine().rstrip().decode('utf-8')) ;
    var Math_PINFINITY : double := ("" + (('inf')))->toReal();    var mod : double := (10)->pow(9) + 7 ;
    var mans : double := Math_PINFINITY;    var ans : int := 0;    var count : int := 0;    var pro : int := 1 ;
    var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    ans := ans + 1000 * (x div 500) ;
    x := x mod 500 ;
    ans := ans + 5 * (x div 5) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
X=int(input())
count=0
while 1 :
    if(X>=500):
        count+=1000
        X-=500
    elif(X>=5):
        count+=5
        X-=5
    else :
        break
print(count)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var X : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var count : int := 0 ;
    while 1 do (    if (X >= 500) then  (
      count := count + 1000 ;
    X := X - 500
    )
    else (if (X >= 5) then
   (
      count := count + 5 ;
    X := X - 5    
)
    else (
      break
      )    )
) ;
    execute (count)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
import math
import bisect
def solve(n):
    ans=n//500*1000
    n %=500
    ans+=n//5*5
    return ans
def main():
    n=int(input())
    print(solve(n))
if __name__=="__main__" :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      main()
    ) else skip;
  operation solve(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var ans : int := n div 500 * 1000 ;
    n := n mod 500 ;
    ans := ans + n div 5 * 5 ;
    return ans;
  operation main()
  pre: true post: true
  activity:
    n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    execute (solve(n))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=int(input())
b=int(a/500)*1000
a+=-b/2
c=int(a/5)*5
print(b+c)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var b : int := ("" + ((a / 500)))->toInteger() * 1000 ;
    a := a + -b / 2 ;
    var c : int := ("" + ((a / 5)))->toInteger() * 5 ;
    execute (b + c)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
l=list(map(int,input().split()))
l.sort()
a=sum(l[: n//2])
b=sum(l[n//2 :])
print(a*a+b*b)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    l := l->sort() ;
    var a : OclAny := (l.subrange(1,n div 2))->sum() ;
    var b : OclAny := (l.subrange(n div 2+1))->sum() ;
    execute (a * a + b * b)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from functools import*
read_line=lambda :[int(i)for i in input().split()]
n,m,k=read_line()
a=[read_line()for i in range(n)]
if nk else range(1<select(i | true)->collect(i | (("" + ((i)))->toInteger()))) ;
    var n : OclAny := null;
    var m : OclAny := null;
    var k : OclAny := null;
    Sequence{n,m,k} := read_line->apply() ;
    var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (read_line->apply())) ;
    if (n->compareTo(m)) < 0 then (
      var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m,a} := Sequence{m,n,Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name a)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name a)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name a)))))))`third->at(_indx)} )}
    ) else skip ;
    var xs : Sequence := a->select(y | true)->collect(y | (reduce(lambda x : OclAny, b : OclAny in (2 * x + b), y))) ;
    var minm : Function := lambda a : OclAny in (Set{a, m - a}->min()) ;
    var work : Function := lambda y : OclAny in (((argument (test (logical_test (comparison (expr (atom (name minm)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name bin)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) ^ (expr (atom (name y))))))))) ))) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '1'))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name xs))))))))->sum()) ;
    var ans : OclAny := ((if (m->compareTo(k)) > 0 then xs else Integer.subrange(0, 1 * (2->pow(m))-1) endif)->collect( _x | (work)->apply(_x) ))->min() ;
    execute (if (ans->compareTo(k)) <= 0 then ans else -1 endif)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from functools import*
read_line=lambda :[int(i)for i in input().split()]
n,m,k=read_line()
a=[read_line()for i in range(n)]
if nk else range(1<select(i | true)->collect(i | (("" + ((i)))->toInteger()))) ;
    var n : OclAny := null;
    var m : OclAny := null;
    var k : OclAny := null;
    Sequence{n,m,k} := read_line->apply() ;
    var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (read_line->apply())) ;
    if (n->compareTo(m)) < 0 then (
      var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m,a} := Sequence{m,n,Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name a)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name a)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name a)))))))`third->at(_indx)} )}
    ) else skip ;
    var xs : Sequence := a->select(y | true)->collect(y | (reduce(lambda x : OclAny, b : OclAny in (2 * x + b), y))) ;
    var minm : Function := lambda a : OclAny in (Set{a, m - a}->min()) ;
    var work : Function := lambda y : OclAny in (((argument (test (logical_test (comparison (expr (atom (name minm)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name bin)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) ^ (expr (atom (name y))))))))) ))) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '1'))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name xs))))))))->sum()) ;
    var ans : OclAny := ((if (m->compareTo(k)) > 0 then xs else Integer.subrange(0, 1 * (2->pow(m))-1) endif)->collect( _x | (work)->apply(_x) ))->min() ;
    execute (if (ans->compareTo(k)) <= 0 then ans else -1 endif)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from functools import*
read_line=lambda :[int(i)for i in input().split()]
n,m,k=read_line()
a=[read_line()for i in range(n)]
if nk else range(1<select(i | true)->collect(i | (("" + ((i)))->toInteger()))) ;
    var n : OclAny := null;
    var m : OclAny := null;
    var k : OclAny := null;
    Sequence{n,m,k} := read_line->apply() ;
    var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (read_line->apply())) ;
    if (n->compareTo(m)) < 0 then (
      var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m,a} := Sequence{m,n,Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name a)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name a)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name a)))))))`third->at(_indx)} )}
    ) else skip ;
    var xs : Sequence := a->select(y | true)->collect(y | (reduce(lambda x : OclAny, b : OclAny in (2 * x + b), y))) ;
    var minm : Function := lambda a : OclAny in (Set{a, m - a}->min()) ;
    var work : Function := lambda y : OclAny in (((argument (test (logical_test (comparison (expr (atom (name minm)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name bin)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) ^ (expr (atom (name y))))))))) ))) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '1'))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name xs))))))))->sum()) ;
    var ans : OclAny := ((if (m->compareTo(k)) > 0 then xs else Integer.subrange(0, 1 * (2->pow(m))-1) endif)->collect( _x | (work)->apply(_x) ))->min() ;
    execute (if (ans->compareTo(k)) <= 0 then ans else -1 endif)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from functools import*
read_line=lambda :[int(i)for i in input().split()]
n,m,k=read_line()
a=[read_line()for i in range(n)]
if nk else range(1<select(i | true)->collect(i | (("" + ((i)))->toInteger()))) ;
    var n : OclAny := null;
    var m : OclAny := null;
    var k : OclAny := null;
    Sequence{n,m,k} := read_line->apply() ;
    var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (read_line->apply())) ;
    if (n->compareTo(m)) < 0 then (
      var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m,a} := Sequence{m,n,Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name a)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name a)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name a)))))))`third->at(_indx)} )}
    ) else skip ;
    var xs : Sequence := a->select(y | true)->collect(y | (reduce(lambda x : OclAny, b : OclAny in (2 * x + b), y))) ;
    var minm : Function := lambda a : OclAny in (Set{a, m - a}->min()) ;
    var work : Function := lambda y : OclAny in (((argument (test (logical_test (comparison (expr (atom (name minm)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name bin)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) ^ (expr (atom (name y))))))))) ))) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '1'))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name xs))))))))->sum()) ;
    var ans : OclAny := ((if (m->compareTo(k)) > 0 then xs else Integer.subrange(0, 1 * (2->pow(m))-1) endif)->collect( _x | (work)->apply(_x) ))->min() ;
    execute (if (ans->compareTo(k)) <= 0 then ans else -1 endif)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    n=int(input())
    ans=int()
    a=input(); a='2'+a+'2'
    b=input(); b='2'+b+'2'
    a=[i for i in a]
    b=[i for i in b]
    for i in range(1,n+1):
        if b[i]=='1' :
            if a[i]=='0' : ans+=1
            elif a[i-1]=='1' : ans+=1 ; a[i-1]='2'
            elif a[i+1]=='1' : ans+=1 ; a[i+1]='2'
    print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var ans : int := ("" + (()))->toInteger() ;
    var a : String := (OclFile["System.in"]).readLine();    a := '2' + a + '2' ;
    var b : String := (OclFile["System.in"]).readLine();    b := '2' + b + '2' ;
    a := a->characters()->select(i | true)->collect(i | (i)) ;
    b := b->characters()->select(i | true)->collect(i | (i)) ;
    for i : Integer.subrange(1, n + 1-1) do (    if b[i+1] = '1' then (
      if a[i+1] = '0' then  (
      ans := ans + 1
    )
    else (if a[i - 1+1] = '1' then
   (
      ans := ans + 1;    a[i - 1+1] := '2'    
)
    else (if a[i + 1+1] = '1' then
   (
      ans := ans + 1;    a[i + 1+1] := '2'    
)
    else skip    )
    )
    ) else skip) ;
    execute (ans)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from functools import*
read_line=lambda :[int(i)for i in input().split()]
n,m,k=read_line()
a=[read_line()for i in range(n)]
if nk else range(1<select(i | true)->collect(i | (("" + ((i)))->toInteger()))) ;
    var n : OclAny := null;
    var m : OclAny := null;
    var k : OclAny := null;
    Sequence{n,m,k} := read_line->apply() ;
    var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (read_line->apply())) ;
    if (n->compareTo(m)) < 0 then (
      var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m,a} := Sequence{m,n,Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name a)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name a)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name a)))))))`third->at(_indx)} )}
    ) else skip ;
    var xs : Sequence := a->select(y | true)->collect(y | (reduce(lambda x : OclAny, b : OclAny in (2 * x + b), y))) ;
    var minm : Function := lambda a : OclAny in (Set{a, m - a}->min()) ;
    var work : Function := lambda y : OclAny in (((argument (test (logical_test (comparison (expr (atom (name minm)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name bin)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) ^ (expr (atom (name y))))))))) ))) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '1'))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name xs))))))))->sum()) ;
    var ans : OclAny := ((if (m->compareTo(k)) > 0 then xs else Integer.subrange(0, 1 * (2->pow(m))-1) endif)->collect( _x | (work)->apply(_x) ))->min() ;
    execute (if (ans->compareTo(k)) <= 0 then ans else -1 endif)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
class newNode :
    def __init__(self,key):
        self.left=self.right=None
        self.key=key
        self.isThreaded=None
def createThreaded(root):
    if root==None :
        return None
    if root.left==None and root.right==None :
        return root
    if root.left!=None :
        l=createThreaded(root.left)
        l.right=root
        l.isThreaded=True
    if root.right==None :
        return root
    return createThreaded(root.right)
def leftMost(root):
    while root!=None and root.left!=None :
        root=root.left
    return root
def inOrder(root):
    if root==None :
        return
    cur=leftMost(root)
    while cur!=None :
        print(cur.key,end=" ")
        if cur.isThreaded :
            cur=cur.right
        else :
            cur=leftMost(cur.right)
if __name__=='__main__' :
    root=newNode(1)
    root.left=newNode(2)
    root.right=newNode(3)
    root.left.left=newNode(4)
    root.left.right=newNode(5)
    root.right.left=newNode(6)
    root.right.right=newNode(7)
    createThreaded(root)
    print("Inorder traversal of created","threaded tree is")
    inOrder(root)
------------------------------------------------------------
OCL File:
---------
class newNode {
  static operation newnewNode() : newNode
  pre: true
  post: newNode->exists( _x | result = _x );
  attribute left : OclAny := null; var self.right : OclAny := null;
  attribute key : OclAny := key;
  attribute isThreaded : OclAny := null;
  operation initialise(key : OclAny) : newNode
  pre: true post: true
  activity:
    self.left := null; var self.right : OclAny := null ;
    self.key := key ;
    self.isThreaded := null;
    return self;
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      root := (newNode.newnewNode()).initialise(1) ;
    root.left := (newNode.newnewNode()).initialise(2) ;
    root.right := (newNode.newnewNode()).initialise(3) ;
    root.left.left := (newNode.newnewNode()).initialise(4) ;
    root.left.right := (newNode.newnewNode()).initialise(5) ;
    root.right.left := (newNode.newnewNode()).initialise(6) ;
    root.right.right := (newNode.newnewNode()).initialise(7) ;
    createThreaded(root) ;
    execute ("Inorder traversal of created")->display() ;
    inOrder(root)
    ) else skip;
  operation createThreaded(root : OclAny) : OclAny
  pre: true post: true
  activity:
    if root = null then (
      return null
    ) else skip ;
    if root.left = null & root.right = null then (
      return root
    ) else skip ;
    if root.left /= null then (
      var l : OclAny := createThreaded(root.left) ;
    l.right := root ;
    l.isThreaded := true
    ) else skip ;
    if root.right = null then (
      return root
    ) else skip ;
    return createThreaded(root.right);
  operation leftMost(root : OclAny) : OclAny
  pre: true post: true
  activity:
    while root /= null & root.left /= null do (    root := root.left) ;
    return root;
  operation inOrder(root : OclAny)
  pre: true post: true
  activity:
    if root = null then (
      return
    ) else skip ;
    var cur : OclAny := leftMost(root) ;
    while cur /= null do (    execute (cur.key)->display() ;
    if cur.isThreaded then  (
      cur := cur.right
    )
    else (
      cur := leftMost(cur.right)
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import itertools
def func(n):
    rest={i**2 % n for i in range(1,n)}
    count=[0]*n
    for x,y in itertools.combinations(rest,2):
        count[x-y]+=2
    for i in range(n//2):
        print(count[i+1]+count[n-i-1])
def main():
    while True :
        n=int(input())
        if n==0 :
            break
        func(n)
main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    main();
  operation func(n : OclAny)
  pre: true post: true
  activity:
    var rest : Set := Integer.subrange(1, n-1)->select(i | true)->collect(i | (i)->pow(2) mod n)->asSet() ;
    var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ;
    for _tuple : itertools.combinations(rest, 2) do (var _indx : int := 1;
      var x : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var y : OclAny := _tuple->at(_indx);
      count[x - y+1] := count[x - y+1] + 2) ;
    for i : Integer.subrange(0, n div 2-1) do (    execute (count[i + 1+1] + count[n - i - 1+1])->display());
  operation main()
  pre: true post: true
  activity:
    while true do (    n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    func(n));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
readline=sys.stdin.readline
write=sys.stdout.write
def solve():
    N=int(readline())
    if N==0 :
        return False
    if N==1 :
        return True
*S,=set(i**2 % N for i in range(1,N))
    S.sort()
    L=len(S)
    C=[0]*N
    D=[0]*((N-1)//2)
    for i in range(L):
        a=S[i]
        for b in S[: i]:
            C[a-b]+=2
    for i in range(1,N):
        D[min(i,N-i)-1]+=C[i]
    write("\n".join(map(str,D)))
    write("\n")
    return True
while solve():
   ...
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var readline : OclAny := (OclFile["System.in"]).readline ;
    var write : OclAny := (OclFile["System.out"]).write ;
    skip ;
(testlist_star_expr (star_expr * (expr (atom (name S)))) ,)    Sequence{(testlist_star_expr (star_expr * (expr (atom (name S)))) ,)} := Set{}->union(((argument (test (logical_test (comparison (expr (expr (expr (atom (name i))) ** (expr (atom (number (integer 2))))) % (expr (atom (name N))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name N)))))))) ))))))))));
  operation solve() : OclAny
  pre: true post: true
  activity:
    var N : int := ("" + ((readline())))->toInteger() ;
    if N = 0 then (
      return false
    ) else skip ;
    if N = 1 then (
      return true
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import itertools
def func(n):
    rest={i**2 % n for i in range(1,n)}
    count=[0]*n
    for x,y in itertools.combinations(rest,2):
        count[x-y]+=2
    for i in range(n//2): print(count[i+1]+count[n-i-1])
while True :
    n=int(input())
    if n==0 : break
    func(n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    while true do (    n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    func(n));
  operation func(n : OclAny)
  pre: true post: true
  activity:
    var rest : Set := Integer.subrange(1, n-1)->select(i | true)->collect(i | (i)->pow(2) mod n)->asSet() ;
    var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ;
    for _tuple : itertools.combinations(rest, 2) do (var _indx : int := 1;
      var x : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var y : OclAny := _tuple->at(_indx);
      count[x - y+1] := count[x - y+1] + 2) ;
    for i : Integer.subrange(0, n div 2-1) do (    execute (count[i + 1+1] + count[n - i - 1+1])->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
A=list(map(int,input().split()))
a=[]
c=[0,0,0]
for a_i in A :
    cnt=0
    while a_i % 2==0 :
        a_i//=2
        cnt=min(2,cnt+1)
    c[cnt]+=1
    a.append(cnt)
if(c[2]+c[1]//2)>=(n//2):
    print("Yes")
else :
    print("No")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var a : Sequence := Sequence{} ;
    var c : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) ;
    for a_i : A do (    var cnt : int := 0 ;
    while a_i mod 2 = 0 do (    a_i := a_i div 2 ;
    cnt := Set{2, cnt + 1}->min()) ;
    c[cnt+1] := c[cnt+1] + 1 ;
    execute ((cnt) : a)) ;
    if ((c[2+1] + c[1+1] div 2)->compareTo((n div 2))) >= 0 then  (
      execute ("Yes")->display()
    )
    else (
      execute ("No")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for t in range(int(input())):
    input(); seen={}; r='yes' ; i=lambda : map(int,input().split())
    for a,b in zip(i(),i()):
        if a!=b and not seen.get(b>a): r='no' ; break
        if a and not seen.get(a>0):
            if seen.get(a<0): break
            seen[a>0]=1
    print(r)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    input();    var seen : OclAny := Set{};    var r : String := 'yes';    var i : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    for _tuple : Integer.subrange(1, i->apply()->size())->collect( _indx | Sequence{i->apply()->at(_indx), i->apply()->at(_indx)} ) do (var _indx : int := 1;
      var a : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var b : OclAny := _tuple->at(_indx);
      if a /= b & not(seen.get((b->compareTo(a)) > 0)) then (
      r := 'no';    break
    ) else skip ;
    if a & not(seen.get(a > 0)) then (
      if seen.get(a < 0) then (
      break
    ) else skip ;
    seen->select(a > 0) := 1
    ) else skip) ;
    execute (r)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in[0]*int(input()):
    n=int(input())
*a,=map(int,input().split())
*b,=map(int,input().split())
    ans='YES' ; pos,neg=a[:-1].count(1),a[:-1].count(-1)
    for i in range(n-1,-1,-1):
        if a[i]>b[i]and neg==0 : ans='NO' ; break
        if a[i]toInteger()) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ;
(testlist_star_expr (star_expr * (expr (atom (name a)))) ,)    Sequence{(testlist_star_expr (star_expr * (expr (atom (name a)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
(testlist_star_expr (star_expr * (expr (atom (name b)))) ,)    Sequence{(testlist_star_expr (star_expr * (expr (atom (name b)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def _input(): return map(int,input().split())
def f():
    n=int(input())
    l1,l2=list(_input()),list(_input())
    if l1[0]!=l2[0]: print("NO"); return
    else :
        c=[]
        i=1
        while il2[i]and l1[i-1]!=-1 :
                print("NO")
                return
            if l1[i]==-1 :
                if l1[i-1]==1 : print("YES"); return
            elif l1[i]==1 :
                if l1[i-1]==-1 : print("YES"); return
            if l1[i]==0 : l1[i]=l1[i-1]
            i+=1
    print("YES")
for _ in range(int(input())): f()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    f());
  operation _input() : OclAny
  pre: true post: true
  activity:
    return (input().split())->collect( _x | (OclType["int"])->apply(_x) );
  operation f()
  pre: true post: true
  activity:
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var l1 : OclAny := null;
    var l2 : OclAny := null;
    Sequence{l1,l2} := Sequence{(_input()),(_input())} ;
    if l1->first() /= l2->first() then  (
      execute ("NO")->display();    return
    )
    else (
      var c : Sequence := Sequence{} ;
    var i : int := 1 ;
    while (i->compareTo(n)) < 0 do (    if (l1[i+1]->compareTo(l2[i+1])) < 0 & l1[i - 1+1] /= 1 then (
      execute ("NO")->display() ;
    return
    ) else skip ;
    if (l1[i+1]->compareTo(l2[i+1])) > 0 & l1[i - 1+1] /= -1 then (
      execute ("NO")->display() ;
    return
    ) else skip ;
    if l1[i+1] = -1 then  (
      if l1[i - 1+1] = 1 then (
      execute ("YES")->display();    return
    ) else skip
    )
    else (if l1[i+1] = 1 then
   (
      if l1[i - 1+1] = -1 then (
      execute ("YES")->display();    return
    ) else skip    
)
 else skip) ;
    if l1[i+1] = 0 then (
      l1[i+1] := l1[i - 1+1]
    ) else skip ;
    i := i + 1)
      ) ;
    execute ("YES")->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for p in range(int(input())):
    z,h=int(input()),0
    f=list(map(int,input().split()))
    s=list(map(int,input().split()))
    if f[0]!=s[0]:
        print("NO")
        h=1
    else :
        l=[0,0,0]
        for j,i in enumerate(s):
            if l[0]and not l[2]:
                if i<=f[j]: pass
                else :
                    h=1
                    print("NO")
                    break
            elif not l[0]and l[2]:
                if i>=f[j]: pass
                else :
                    h=1
                    print("NO")
                    break
            elif l[0]and l[2]:
                h=0
                break
            else :
                if i==f[j]: pass
                else :
                    h=1
                    print("NO")
                    break
            if-1==f[j]: l[0]=1
            if 0==f[j]: l[1]=1
            if 1==f[j]: l[2]=1
        if not h : print("YES")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for p : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var z : OclAny := null;
    var h : OclAny := null;
    Sequence{z,h} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),0} ;
    var f : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if f->first() /= s->first() then  (
      execute ("NO")->display() ;
    var h : int := 1
    )
    else (
      var l : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) ;
    for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1;
      var j : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var i : OclAny := _tuple->at(_indx);
      if l->first() & not(l[2+1]) then  (
      if (i->compareTo(f[j+1])) <= 0 then  (
      skip
    )
    else (
      h := 1 ;
    execute ("NO")->display() ;
    break
      )
    )
    else (if not(l->first()) & l[2+1] then
   (
      if (i->compareTo(f[j+1])) >= 0 then  (
      skip
    )
    else (
      h := 1 ;
    execute ("NO")->display() ;
    break
      )    
)
    else (if l->first() & l[2+1] then
   (
      h := 0 ;
    break    
)
    else (
      if i = f[j+1] then  (
      skip
    )
    else (
      h := 1 ;
    execute ("NO")->display() ;
    break
      )
      )    )
    )
 ;
    if -1 = f[j+1] then (
      l->first() := 1
    ) else skip ;
    if 0 = f[j+1] then (
      l[1+1] := 1
    ) else skip ;
    if 1 = f[j+1] then (
      l[2+1] := 1
    ) else skip) ;
    if not(h) then (
      execute ("YES")->display()
    ) else skip
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    a,b=[list(map(int,input().split()))for i in '...'][1 :]
    s=set()
    for i in range(len(a)):
        if(a[i]b[i]and-1 not in s):
            print('NO')
            break
        s.add(a[i])
        if i==len(a)-1 :
            print('YES')
num_inp=lambda : int(input())
arr_inp=lambda : list(map(int,input().split()))
sp_inp=lambda : map(int,input().split())
str_inp=lambda : input()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := '...'->characters()->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))->tail() ;
    var s : Set := Set{}->union(()) ;
    for i : Integer.subrange(0, (a)->size()-1) do (    if ((a[i+1]->compareTo(b[i+1])) < 0 & (s)->excludes(1)) or ((a[i+1]->compareTo(b[i+1])) > 0 & (s)->excludes(-1)) then (
      execute ('NO')->display() ;
    break
    ) else skip ;
    execute ((a[i+1]) : s) ;
    if i = (a)->size() - 1 then (
      execute ('YES')->display()
    ) else skip)) ;
    var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ;
    var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ;
    var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
b=int(input())
divisors=0
raiz=int(b**0.5)+1
for a in range(1,raiz,1):
    if b % a==0 :
        divisors+=2
        if a==b**0.5 :
            divisors-=1
print(divisors)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var divisors : int := 0 ;
    var raiz : int := ("" + (((b)->pow(0.5))))->toInteger() + 1 ;
    for a : Integer.subrange(1, raiz-1)->select( $x | ($x - 1) mod 1 = 0 ) do (    if b mod a = 0 then (
      divisors := divisors + 2 ;
    if a = (b)->pow(0.5) then (
      divisors := divisors - 1
    ) else skip
    ) else skip) ;
    execute (divisors)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def sumOfSeries(num):
    res=0
    fact=1
    for i in range(1,num+1):
        fact*=i
        res=res+(i/fact)
    return res
n=5
print("Sum: ",sumOfSeries(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : int := 5 ;
    execute ("Sum: ")->display();
  operation sumOfSeries(num : OclAny) : OclAny
  pre: true post: true
  activity:
    var res : int := 0 ;
    var fact : int := 1 ;
    for i : Integer.subrange(1, num + 1-1) do (    fact := fact * i ;
    res := res + (i / fact)) ;
    return res;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def maxProductSum(str,m):
    n=len(str)
    product=1
    sum=0
    for i in range(m):
        sum+=(ord(str[i])-ord('0'))
        product*=(ord(str[i])-ord('0'))
    maxProd=product
    maxSum=sum
    for i in range(m,n):
        product=(product*(ord(str[i])-ord('0'))//((ord(str[i-m]))-ord('0')))
        sum=(sum+(ord(str[i])-ord('0'))-((ord(str[i-m]))-ord('0')))
        maxProd=max(maxProd,product)
        maxSum=max(maxSum,sum)
    print("Maximum Product=",maxProd)
    print("Maximum Sum=",maxSum)
if __name__=="__main__" :
    str="3675356291"
    m=5
    maxProductSum(str,m)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      OclType["String"] := "3675356291" ;
    m := 5 ;
    maxProductSum(OclType["String"], m)
    ) else skip;
  operation maxProductSum(OclType["String"] : OclAny, m : OclAny)
  pre: true post: true
  activity:
    var n : int := (OclType["String"])->size() ;
    var product : int := 1 ;
    var sum : int := 0 ;
    for i : Integer.subrange(0, m-1) do (    sum := sum + ((("" + ([i+1])))->char2byte() - ('0')->char2byte()) ;
    product := product * ((("" + ([i+1])))->char2byte() - ('0')->char2byte())) ;
    var maxProd : int := product ;
    var maxSum : int := sum ;
    for i : Integer.subrange(m, n-1) do (    product := (product * ((("" + ([i+1])))->char2byte() - ('0')->char2byte()) div (((("" + ([i - m+1])))->char2byte()) - ('0')->char2byte())) ;
    sum := (sum + ((("" + ([i+1])))->char2byte() - ('0')->char2byte()) - (((("" + ([i - m+1])))->char2byte()) - ('0')->char2byte())) ;
    maxProd := Set{maxProd, product}->max() ;
    maxSum := Set{maxSum, sum}->max()) ;
    execute ("Maximum Product=")->display() ;
    execute ("Maximum Sum=")->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from fractions import Fraction
s=list(map(int,input().split()))
y=max(s)-1
x=(6-y)
d=Fraction(x,6)
if d==1 :
    print('1/1')
elif d==0 :
    print('0/1')
else :
    print(d)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var y : double := (s)->max() - 1 ;
    var x : double := (6 - y) ;
    var d : OclAny := Fraction(x, 6) ;
    if d = 1 then  (
      execute ('1/1')->display()
    )
    else (if d = 0 then
   (
      execute ('0/1')->display()    
)
    else (
      execute (d)->display()
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import fractions
l=[int(x)for x in list(input().split())]
if l[0]==l[1]==1 :
    print('1/1')
else :
    if l[0]>l[1]:
        print(fractions.Fraction(6-l[0]+1,6))
    else :
        print(fractions.Fraction(6-l[1]+1,6))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var l : Sequence := (input().split())->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    if l->first() = l[1+1] & (l[1+1] == 1) then  (
      execute ('1/1')->display()
    )
    else (
      if (l->first()->compareTo(l[1+1])) > 0 then  (
      execute (fractions.Fraction(6 - l->first() + 1, 6))->display()
    )
    else (
      execute (fractions.Fraction(6 - l[1+1] + 1, 6))->display()
      )
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def solve(N,a):
    n4=len([v for v in a if v % 4==0])
    n2=len([v for v in a if v % 4!=0 and v % 2==0])
    n1=len([v for v in a if v % 2!=0])
    na=n4+1
    if n2>0 : na-=1
    return "Yes" if n1<=na else "No"
def splitIntoNums(line):
    words=line.strip().split()
    return[int(w)for w in words]
while True :
    l1=sys.stdin.readline()
    l2=sys.stdin.readline()
    if not l1 : break
    N,=splitIntoNums(l1)
    a=splitIntoNums(l2)
    if len(a)!=N : raise
    print(solve(N,a))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    while true do (    var l1 : String := (OclFile["System.in"]).readLine() ;
    var l2 : String := (OclFile["System.in"]).readLine() ;
    if not(l1 = "") then (
      break
    ) else skip ;
(testlist_star_expr (test (logical_test (comparison (expr (atom (name N)))))) ,)    Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name N)))))) ,)} := splitIntoNums(l1) ;
    a := splitIntoNums(l2) ;
    if (a)->size() /= N then (
  (small_stmt raise)
    ) else skip ;
    execute (solve(N, a))->display());
  operation solve(N : OclAny, a : OclAny) : OclAny
  pre: true post: true
  activity:
    var n4 : int := (a->select(v | v mod 4 = 0)->collect(v | (v)))->size() ;
    var n2 : int := (a->select(v | v mod 4 /= 0 & v mod 2 = 0)->collect(v | (v)))->size() ;
    var n1 : int := (a->select(v | v mod 2 /= 0)->collect(v | (v)))->size() ;
    var na : int := n4 + 1 ;
    if n2 > 0 then (
      na := na - 1
    ) else skip ;
    return if (n1->compareTo(na)) <= 0 then "Yes" else "No" endif;
  operation splitIntoNums(line : OclAny) : OclAny
  pre: true post: true
  activity:
    var words : OclAny := line->trim().split() ;
    return words->select(w | true)->collect(w | (("" + ((w)))->toInteger()));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
y,w=map(int,input().split())
bst=6-max(y,w)+1
mqam=6
while(bst % 2==0 and mqam % 2==0)or(bst % 3==0 and mqam % 3==0):
    if bst % 3==0 and mqam % 3==0 :
        bst//=3
        mqam//=3
    elif bst % 2==0 and mqam % 2==0 :
        bst//=2
        mqam//=2
print(str(bst)+'/'+str(mqam))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var y : OclAny := null;
    var w : OclAny := null;
    Sequence{y,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var bst : double := 6 - Set{y, w}->max() + 1 ;
    var mqam : int := 6 ;
    while (bst mod 2 = 0 & mqam mod 2 = 0) or (bst mod 3 = 0 & mqam mod 3 = 0) do (    if bst mod 3 = 0 & mqam mod 3 = 0 then  (
      bst := bst div 3 ;
    mqam := mqam div 3
    )
    else (if bst mod 2 = 0 & mqam mod 2 = 0 then
   (
      bst := bst div 2 ;
    mqam := mqam div 2    
)
 else skip)) ;
    execute (("" + ((bst))) + '/' + ("" + ((mqam))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=map(int,input().split())
c=max(a,b)
if c==1 :
    print("1/1")
if c==2 :
    print("5/6")
if c==3 :
    print("2/3")
if c==4 :
    print("1/2")
if c==5 :
    print("1/3")
if c==6 :
    print("1/6")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var c : OclAny := Set{a, b}->max() ;
    if c = 1 then (
      execute ("1/1")->display()
    ) else skip ;
    if c = 2 then (
      execute ("5/6")->display()
    ) else skip ;
    if c = 3 then (
      execute ("2/3")->display()
    ) else skip ;
    if c = 4 then (
      execute ("1/2")->display()
    ) else skip ;
    if c = 5 then (
      execute ("1/3")->display()
    ) else skip ;
    if c = 6 then (
      execute ("1/6")->display()
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n_=input().split()
n=int(n_[0])
m=int(n_[1])
total=7-max(m,n)
if total<0 :
    total=0
if total==0 :
    print('0/1')
elif total==2 :
    print('1/3')
elif total==3 :
    print('1/2')
elif total==4 :
    print('2/3')
elif total==6 :
    print('1/1')
else :
    print(f'{total}/6')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n_ : OclAny := input().split() ;
    var n : int := ("" + ((n_->first())))->toInteger() ;
    var m : int := ("" + ((n_[1+1])))->toInteger() ;
    var total : double := 7 - Set{m, n}->max() ;
    if total < 0 then (
      total := 0
    ) else skip ;
    if total = 0 then  (
      execute ('0/1')->display()
    )
    else (if total = 2 then
   (
      execute ('1/3')->display()    
)
    else (if total = 3 then
   (
      execute ('1/2')->display()    
)
    else (if total = 4 then
   (
      execute ('2/3')->display()    
)
    else (if total = 6 then
   (
      execute ('1/1')->display()    
)
    else (
      execute (StringLib.formattedString('{total}/6'))->display()
      )    )
    )
    )
    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
CharToSign={"A" : "00000","B" : "00001","C" : "00010","D" : "00011","E" : "00100","F" : "00101","G" : "00110","H" : "00111","I" : "01000","J" : "01001","K" : "01010","L" : "01011","M" : "01100","N" : "01101","O" : "01110","P" : "01111","Q" : "10000","R" : "10001","S" : "10010","T" : "10011","U" : "10100","V" : "10101","W" : "10110","X" : "10111","Y" : "11000","Z" : "11001","" : "11010","." : "11011","," : "11100","-" : "11101","'" : "11110","?" : "11111",}
SignToChar={"101" : "","000000" : "'","000011" : ",","10010001" : "-","010001" : ".","000001" : "?","100101" : "A","10011010" : "B","0101" : "C","0001" : "D","110" : "E","01001" : "F","10011011" : "G","010000" : "H","0111" : "I","10011000" : "J","0110" : "K","00100" : "L","10011001" : "M","10011110" : "N","00101" : "O","111" : "P","10011111" : "Q","1000" : "R","00110" : "S","00111" : "T","10011100" : "U","10011101" : "V","000010" : "W","10010010" : "X","10010011" : "Y","10010000" : "Z",}
for line in sys.stdin :
    line=line[:-1]
    sign=[]
    for char in line :
        convert=CharToSign[char]
        sign.append(convert)
    sign="".join(sign)
    startIndex=0
    endIndex=3
    string=[]
    length=len(sign)
    while endIndex<=length :
        part=sign[startIndex : endIndex]
        if part in SignToChar :
            convert=SignToChar[part]
            string.append(convert)
            startIndex=endIndex
            endIndex+=3
        else :
            endIndex+=1
    string="".join(string)
    print(string)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var CharToSign : Map := Map{ "A" |-> "00000" }->union(Map{ "B" |-> "00001" }->union(Map{ "C" |-> "00010" }->union(Map{ "D" |-> "00011" }->union(Map{ "E" |-> "00100" }->union(Map{ "F" |-> "00101" }->union(Map{ "G" |-> "00110" }->union(Map{ "H" |-> "00111" }->union(Map{ "I" |-> "01000" }->union(Map{ "J" |-> "01001" }->union(Map{ "K" |-> "01010" }->union(Map{ "L" |-> "01011" }->union(Map{ "M" |-> "01100" }->union(Map{ "N" |-> "01101" }->union(Map{ "O" |-> "01110" }->union(Map{ "P" |-> "01111" }->union(Map{ "Q" |-> "10000" }->union(Map{ "R" |-> "10001" }->union(Map{ "S" |-> "10010" }->union(Map{ "T" |-> "10011" }->union(Map{ "U" |-> "10100" }->union(Map{ "V" |-> "10101" }->union(Map{ "W" |-> "10110" }->union(Map{ "X" |-> "10111" }->union(Map{ "Y" |-> "11000" }->union(Map{ "Z" |-> "11001" }->union(Map{ "" |-> "11010" }->union(Map{ "." |-> "11011" }->union(Map{ "," |-> "11100" }->union(Map{ "-" |-> "11101" }->union(Map{ "'" |-> "11110" }->union((dictorsetmaker (test (logical_test (comparison (expr (atom "?"))))) : (test (logical_test (comparison (expr (atom "11111"))))) ,)))))))))))))))))))))))))))))))) ;
    var SignToChar : Map := Map{ "101" |-> "" }->union(Map{ "000000" |-> "'" }->union(Map{ "000011" |-> "," }->union(Map{ "10010001" |-> "-" }->union(Map{ "010001" |-> "." }->union(Map{ "000001" |-> "?" }->union(Map{ "100101" |-> "A" }->union(Map{ "10011010" |-> "B" }->union(Map{ "0101" |-> "C" }->union(Map{ "0001" |-> "D" }->union(Map{ "110" |-> "E" }->union(Map{ "01001" |-> "F" }->union(Map{ "10011011" |-> "G" }->union(Map{ "010000" |-> "H" }->union(Map{ "0111" |-> "I" }->union(Map{ "10011000" |-> "J" }->union(Map{ "0110" |-> "K" }->union(Map{ "00100" |-> "L" }->union(Map{ "10011001" |-> "M" }->union(Map{ "10011110" |-> "N" }->union(Map{ "00101" |-> "O" }->union(Map{ "111" |-> "P" }->union(Map{ "10011111" |-> "Q" }->union(Map{ "1000" |-> "R" }->union(Map{ "00110" |-> "S" }->union(Map{ "00111" |-> "T" }->union(Map{ "10011100" |-> "U" }->union(Map{ "10011101" |-> "V" }->union(Map{ "000010" |-> "W" }->union(Map{ "10010010" |-> "X" }->union(Map{ "10010011" |-> "Y" }->union((dictorsetmaker (test (logical_test (comparison (expr (atom "10010000"))))) : (test (logical_test (comparison (expr (atom "Z"))))) ,)))))))))))))))))))))))))))))))) ;
    for line : OclFile["System.in"] do (    var line : OclAny := line->front() ;
    var sign : Sequence := Sequence{} ;
    for char : line do (    var convert : OclAny := CharToSign[char+1] ;
    execute ((convert) : sign)) ;
    sign := StringLib.sumStringsWithSeparator((sign), "") ;
    var startIndex : int := 0 ;
    var endIndex : int := 3 ;
    var string : Sequence := Sequence{} ;
    var length : int := (sign)->size() ;
    while (endIndex->compareTo(length)) <= 0 do (    var part : OclAny := sign.subrange(startIndex+1, endIndex) ;
    if (SignToChar)->includes(part) then  (
      convert := SignToChar[part+1] ;
    execute ((convert) : string) ;
    startIndex := endIndex ;
    endIndex := endIndex + 3
    )
    else (
      endIndex := endIndex + 1
      )) ;
    string := StringLib.sumStringsWithSeparator((string), "") ;
    execute (string)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def get_input():
    while True :
        try :
            yield ''.join(input())
        except EOFError :
            break
dict={"A" : "00000","B" : "00001","C" : "00010","D" : "00011","E" : "00100","F" : "00101","G" : "00110","H" : "00111","I" : "01000","J" : "01001","K" : "01010","L" : "01011","M" : "01100","N" : "01101","O" : "01110","P" : "01111","Q" : "10000","R" : "10001","S" : "10010","T" : "10011","U" : "10100","V" : "10101","W" : "10110","X" : "10111","Y" : "11000","Z" : "11001","" : "11010","." : "11011","," : "11100","-" : "11101","'" : "11110","?" : "11111"}
dict2={"101" : "","000000" : "'","000011" : ",","10010001" : "-","010001" : ".","000001" : "?","100101" : "A","10011010" : "B","0101" : "C","0001" : "D","110" : "E","01001" : "F","10011011" : "G","010000" : "H","0111" : "I","10011000" : "J","0110" : "K","00100" : "L","10011001" : "M","10011110" : "N","00101" : "O","111" : "P","10011111" : "Q","1000" : "R","00110" : "S","00111" : "T","10011100" : "U","10011101" : "V","000010" : "W","10010010" : "X","10010011" : "Y","10010000" : "Z"}
N=list(get_input())
for l in range(len(N)):
    S1=N[l]
    S2=""
    for i in range(len(S1)):
        S2=S2+dict[S1[i]]
    S3=""
    while S2!="" :
        flag=False
        for i in range(3,len(S2)+1):
            s=S2[0 : i]
            if s in dict2 :
                S3=S3+dict2[s]
                S2=S2[i :]
                flag=True
                break
        if flag==False :
            break
    print(S3)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var OclType["Map"] : Map := Map{ "A" |-> "00000" }->union(Map{ "B" |-> "00001" }->union(Map{ "C" |-> "00010" }->union(Map{ "D" |-> "00011" }->union(Map{ "E" |-> "00100" }->union(Map{ "F" |-> "00101" }->union(Map{ "G" |-> "00110" }->union(Map{ "H" |-> "00111" }->union(Map{ "I" |-> "01000" }->union(Map{ "J" |-> "01001" }->union(Map{ "K" |-> "01010" }->union(Map{ "L" |-> "01011" }->union(Map{ "M" |-> "01100" }->union(Map{ "N" |-> "01101" }->union(Map{ "O" |-> "01110" }->union(Map{ "P" |-> "01111" }->union(Map{ "Q" |-> "10000" }->union(Map{ "R" |-> "10001" }->union(Map{ "S" |-> "10010" }->union(Map{ "T" |-> "10011" }->union(Map{ "U" |-> "10100" }->union(Map{ "V" |-> "10101" }->union(Map{ "W" |-> "10110" }->union(Map{ "X" |-> "10111" }->union(Map{ "Y" |-> "11000" }->union(Map{ "Z" |-> "11001" }->union(Map{ "" |-> "11010" }->union(Map{ "." |-> "11011" }->union(Map{ "," |-> "11100" }->union(Map{ "-" |-> "11101" }->union(Map{ "'" |-> "11110" }->union(Map{ "?" |-> "11111" }))))))))))))))))))))))))))))))) ;
    var dict2 : Map := Map{ "101" |-> "" }->union(Map{ "000000" |-> "'" }->union(Map{ "000011" |-> "," }->union(Map{ "10010001" |-> "-" }->union(Map{ "010001" |-> "." }->union(Map{ "000001" |-> "?" }->union(Map{ "100101" |-> "A" }->union(Map{ "10011010" |-> "B" }->union(Map{ "0101" |-> "C" }->union(Map{ "0001" |-> "D" }->union(Map{ "110" |-> "E" }->union(Map{ "01001" |-> "F" }->union(Map{ "10011011" |-> "G" }->union(Map{ "010000" |-> "H" }->union(Map{ "0111" |-> "I" }->union(Map{ "10011000" |-> "J" }->union(Map{ "0110" |-> "K" }->union(Map{ "00100" |-> "L" }->union(Map{ "10011001" |-> "M" }->union(Map{ "10011110" |-> "N" }->union(Map{ "00101" |-> "O" }->union(Map{ "111" |-> "P" }->union(Map{ "10011111" |-> "Q" }->union(Map{ "1000" |-> "R" }->union(Map{ "00110" |-> "S" }->union(Map{ "00111" |-> "T" }->union(Map{ "10011100" |-> "U" }->union(Map{ "10011101" |-> "V" }->union(Map{ "000010" |-> "W" }->union(Map{ "10010010" |-> "X" }->union(Map{ "10010011" |-> "Y" }->union(Map{ "10010000" |-> "Z" }))))))))))))))))))))))))))))))) ;
    var N : Sequence := (OclIterator.newOclIterator_Function(lambda _i : int in self.get_input(_i))) ;
    for l : Integer.subrange(0, (N)->size()-1) do (    var S1 : OclAny := N[l+1] ;
    var S2 : String := "" ;
    for i : Integer.subrange(0, (S1)->size()-1) do (    S2 := S2 + (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name S1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) ;
    var S3 : String := "" ;
    while S2 /= "" do (    var flag : boolean := false ;
    for i : Integer.subrange(3, (S2)->size() + 1-1) do (    var s : OclAny := S2.subrange(0+1, i) ;
    if (dict2)->includes(s) then (
      S3 := S3 + dict2[s+1] ;
    S2 := S2.subrange(i+1) ;
    flag := true ;
    break
    ) else skip) ;
    if flag = false then (
      break
    ) else skip) ;
    execute (S3)->display());
  operation get_input(_position_ : int) : OclAny
  pre: true post: true
  activity:
    var _yieldCount_ : int := 0;
    while true do (    try (    if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return StringLib.sumStringsWithSeparator(((OclFile["System.in"]).readLine()), ''))
(except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
encode="ABCDEFGHIJKLMNOPQRSTUVWXYZ"+".,-\'?"
decode={"101" : "","000000" : "\'","000011" : ",","10010001" : "-","010001" : ".","000001" : "?","100101" : "A","10011010" : "B","0101" : "C","0001" : "D","110" : "E","01001" : "F","10011011" : "G","010000" : "H","0111" : "I","10011000" : "J","0110" : "K","00100" : "L","10011001" : "M","10011110" : "N","00101" : "O","111" : "P","10011111" : "Q","1000" : "R","00110" : "S","00111" : "T","10011100" : "U","10011101" : "V","000010" : "W","10010010" : "X","10010011" : "Y","10010000" : "Z"}
while True :
    try :
        s=input()
        code=""
        for inp in s :
            code+=format(encode.find(inp),"05b")
        ans=""
        tmp=""
        for inp in code :
            tmp+=inp
            if tmp in decode :
                ans+=decode[tmp]
                tmp=""
        print(ans)
    except :
        break
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var encode : String := "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + ".,-\'?" ;
    var decode : Map := Map{ "101" |-> "" }->union(Map{ "000000" |-> "\'" }->union(Map{ "000011" |-> "," }->union(Map{ "10010001" |-> "-" }->union(Map{ "010001" |-> "." }->union(Map{ "000001" |-> "?" }->union(Map{ "100101" |-> "A" }->union(Map{ "10011010" |-> "B" }->union(Map{ "0101" |-> "C" }->union(Map{ "0001" |-> "D" }->union(Map{ "110" |-> "E" }->union(Map{ "01001" |-> "F" }->union(Map{ "10011011" |-> "G" }->union(Map{ "010000" |-> "H" }->union(Map{ "0111" |-> "I" }->union(Map{ "10011000" |-> "J" }->union(Map{ "0110" |-> "K" }->union(Map{ "00100" |-> "L" }->union(Map{ "10011001" |-> "M" }->union(Map{ "10011110" |-> "N" }->union(Map{ "00101" |-> "O" }->union(Map{ "111" |-> "P" }->union(Map{ "10011111" |-> "Q" }->union(Map{ "1000" |-> "R" }->union(Map{ "00110" |-> "S" }->union(Map{ "00111" |-> "T" }->union(Map{ "10011100" |-> "U" }->union(Map{ "10011101" |-> "V" }->union(Map{ "000010" |-> "W" }->union(Map{ "10010010" |-> "X" }->union(Map{ "10010011" |-> "Y" }->union(Map{ "10010000" |-> "Z" }))))))))))))))))))))))))))))))) ;
    while true do (    try (    var s : String := (OclFile["System.in"]).readLine() ;
    var code : String := "" ;
    for inp : s->characters() do (    code := code + (encode->indexOf(inp) - 1 + "")) ;
    var ans : String := "" ;
    var tmp : String := "" ;
    for inp : code->characters() do (    tmp := tmp + inp ;
    if (decode)->includes(tmp) then (
      ans := ans + decode->at(tmp) ;
    tmp := ""
    ) else skip) ;
    execute (ans)->display())
     catch (_e : OclException) do (    break)
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
b=int(input())
count=0
for i in range(1,round(b**0.5)+1):
    if b % i==0 :
        if i*i==b :
            count+=1
        else :
            count+=2
print(count)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var count : int := 0 ;
    for i : Integer.subrange(1, ((b)->pow(0.5))->round() + 1-1) do (    if b mod i = 0 then (
      if i * i = b then  (
      count := count + 1
    )
    else (
      count := count + 2
      )
    ) else skip) ;
    execute (count)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
import os
import math
import re
import random
tableA={"A" : "00000","B" : "00001","C" : "00010","D" : "00011","E" : "00100","F" : "00101","G" : "00110","H" : "00111","I" : "01000","J" : "01001","K" : "01010","L" : "01011","M" : "01100","N" : "01101","O" : "01110","P" : "01111","Q" : "10000","R" : "10001","S" : "10010","T" : "10011","U" : "10100","V" : "10101","W" : "10110","X" : "10111","Y" : "11000","Z" : "11001"," " : "11010","." : "11011","," : "11100","-" : "11101","'" : "11110","?" : "11111"}
tableB={"101" : " ","000000" : "'","000011" : ",","10010001" : "-","010001" : ".","000001" : "?","100101" : "A","10011010" : "B","0101" : "C","0001" : "D","110" : "E","01001" : "F","10011011" : "G","010000" : "H","0111" : "I","10011000" : "J","0110" : "K","00100" : "L","10011001" : "M","10011110" : "N","00101" : "O","111" : "P","10011111" : "Q","1000" : "R","00110" : "S","00111" : "T","10011100" : "U","10011101" : "V","000010" : "W","10010010" : "X","10010011" : "Y","10010000" : "Z"}
def my_solve(s):
    s=s.strip('\n')
    lst=[]
    for c in s :
        lst.append(tableA[c])
    s=''.join(lst)
    tmp,ans='',''
    for c in s :
        tmp+=c
        if tmp in tableB :
            ans+=tableB[tmp]
            tmp=''
    return ans
for s in sys.stdin :
    s=s.strip('\n')
    print(my_solve(s))

------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var tableA : Map := Map{ "A" |-> "00000" }->union(Map{ "B" |-> "00001" }->union(Map{ "C" |-> "00010" }->union(Map{ "D" |-> "00011" }->union(Map{ "E" |-> "00100" }->union(Map{ "F" |-> "00101" }->union(Map{ "G" |-> "00110" }->union(Map{ "H" |-> "00111" }->union(Map{ "I" |-> "01000" }->union(Map{ "J" |-> "01001" }->union(Map{ "K" |-> "01010" }->union(Map{ "L" |-> "01011" }->union(Map{ "M" |-> "01100" }->union(Map{ "N" |-> "01101" }->union(Map{ "O" |-> "01110" }->union(Map{ "P" |-> "01111" }->union(Map{ "Q" |-> "10000" }->union(Map{ "R" |-> "10001" }->union(Map{ "S" |-> "10010" }->union(Map{ "T" |-> "10011" }->union(Map{ "U" |-> "10100" }->union(Map{ "V" |-> "10101" }->union(Map{ "W" |-> "10110" }->union(Map{ "X" |-> "10111" }->union(Map{ "Y" |-> "11000" }->union(Map{ "Z" |-> "11001" }->union(Map{ " " |-> "11010" }->union(Map{ "." |-> "11011" }->union(Map{ "," |-> "11100" }->union(Map{ "-" |-> "11101" }->union(Map{ "'" |-> "11110" }->union(Map{ "?" |-> "11111" }))))))))))))))))))))))))))))))) ;
    var tableB : Map := Map{ "101" |-> " " }->union(Map{ "000000" |-> "'" }->union(Map{ "000011" |-> "," }->union(Map{ "10010001" |-> "-" }->union(Map{ "010001" |-> "." }->union(Map{ "000001" |-> "?" }->union(Map{ "100101" |-> "A" }->union(Map{ "10011010" |-> "B" }->union(Map{ "0101" |-> "C" }->union(Map{ "0001" |-> "D" }->union(Map{ "110" |-> "E" }->union(Map{ "01001" |-> "F" }->union(Map{ "10011011" |-> "G" }->union(Map{ "010000" |-> "H" }->union(Map{ "0111" |-> "I" }->union(Map{ "10011000" |-> "J" }->union(Map{ "0110" |-> "K" }->union(Map{ "00100" |-> "L" }->union(Map{ "10011001" |-> "M" }->union(Map{ "10011110" |-> "N" }->union(Map{ "00101" |-> "O" }->union(Map{ "111" |-> "P" }->union(Map{ "10011111" |-> "Q" }->union(Map{ "1000" |-> "R" }->union(Map{ "00110" |-> "S" }->union(Map{ "00111" |-> "T" }->union(Map{ "10011100" |-> "U" }->union(Map{ "10011101" |-> "V" }->union(Map{ "000010" |-> "W" }->union(Map{ "10010010" |-> "X" }->union(Map{ "10010011" |-> "Y" }->union(Map{ "10010000" |-> "Z" }))))))))))))))))))))))))))))))) ;
    skip ;
    for s : OclFile["System.in"] do (    s := s->trim() ;
    execute (my_solve(s))->display());
  operation my_solve(s : OclAny) : OclAny
  pre: true post: true
  activity:
    s := s->trim() ;
    var lst : Sequence := Sequence{} ;
    for c : s do (    execute ((tableA[c+1]) : lst)) ;
    s := StringLib.sumStringsWithSeparator((lst), '') ;
    var tmp : OclAny := null;
    var ans : OclAny := null;
    Sequence{tmp,ans} := Sequence{'',''} ;
    for c : s do (    tmp := tmp + c ;
    if (tableB)->includes(tmp) then (
      ans := ans + tableB[tmp+1] ;
    var tmp : String := ''
    ) else skip) ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import string
s={i : "{:05b}".format(c)for i,c in zip(string.ascii_uppercase+".,-'?",range(32))}
code={'101' : '','000000' : "'",'000011' : ',','10010001' : '-','010001' : '.','000001' : '?','100101' : 'A','10011010' : 'B','0101' : 'C','0001' : 'D','110' : 'E','01001' : 'F','10011011' : 'G','010000' : 'H','0111' : 'I','10011000' : 'J','0110' : 'K','00100' : 'L','10011001' : 'M','10011110' : 'N','00101' : 'O','111' : 'P','10011111' : 'Q','1000' : 'R','00110' : 'S','00111' : 'T','10011100' : 'U','10011101' : 'V','000010' : 'W','10010010' : 'X','10010011' : 'Y','10010000' : 'Z'}
while True :
    try :
        data=input()
    except :
        break
    d=''.join(s[c]for c in data)
    ans=tmp=""
    for c in d :
        tmp+=c
        if tmp in code :
            ans+=code[tmp]
            tmp=""
    print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var s : Map := Integer.subrange(1, string.ascii_uppercase + ".,-'?"->size())->collect( _indx | Sequence{string.ascii_uppercase + ".,-'?"->at(_indx), Integer.subrange(0, 32-1)->at(_indx)} )->select(_tuple | true)->collect(_tuple | Map{i |-> StringLib.interpolateStrings("{:05b}", Sequence{c})})->unionAll() ;
    var code : Map := Map{ '101' |-> '' }->union(Map{ '000000' |-> "'" }->union(Map{ '000011' |-> ',' }->union(Map{ '10010001' |-> '-' }->union(Map{ '010001' |-> '.' }->union(Map{ '000001' |-> '?' }->union(Map{ '100101' |-> 'A' }->union(Map{ '10011010' |-> 'B' }->union(Map{ '0101' |-> 'C' }->union(Map{ '0001' |-> 'D' }->union(Map{ '110' |-> 'E' }->union(Map{ '01001' |-> 'F' }->union(Map{ '10011011' |-> 'G' }->union(Map{ '010000' |-> 'H' }->union(Map{ '0111' |-> 'I' }->union(Map{ '10011000' |-> 'J' }->union(Map{ '0110' |-> 'K' }->union(Map{ '00100' |-> 'L' }->union(Map{ '10011001' |-> 'M' }->union(Map{ '10011110' |-> 'N' }->union(Map{ '00101' |-> 'O' }->union(Map{ '111' |-> 'P' }->union(Map{ '10011111' |-> 'Q' }->union(Map{ '1000' |-> 'R' }->union(Map{ '00110' |-> 'S' }->union(Map{ '00111' |-> 'T' }->union(Map{ '10011100' |-> 'U' }->union(Map{ '10011101' |-> 'V' }->union(Map{ '000010' |-> 'W' }->union(Map{ '10010010' |-> 'X' }->union(Map{ '10010011' |-> 'Y' }->union(Map{ '10010000' |-> 'Z' }))))))))))))))))))))))))))))))) ;
    while true do (    try (    var data : String := (OclFile["System.in"]).readLine())
     catch (_e : OclException) do (    break)
 ;
    var d : String := StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name c)))))))) ])))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name data)))))))), '') ;
    var ans : OclAny := ""; var tmp : String := "" ;
    for c : d->characters() do (    tmp := tmp + c ;
    if (code)->includes(tmp) then (
      ans := ans + code[tmp+1] ;
    tmp := ""
    ) else skip) ;
    execute (ans)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b,c=map(int,input().split())
s=a+b+c
p=min(a,b,c)
q=max(a,b,c)
r=s-(p+q)
t=p+r
if t>q :
    print(0)
else :
    print(q-t+1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var s : OclAny := a + b + c ;
    var p : OclAny := Set{a, b, c}->min() ;
    var q : OclAny := Set{a, b, c}->max() ;
    var r : double := s - (p + q) ;
    var t : OclAny := p + r ;
    if (t->compareTo(q)) > 0 then  (
      execute (0)->display()
    )
    else (
      execute (q - t + 1)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
from collections import deque,defaultdict
from math import sqrt,factorial
def solve():
    n=int(input())
    a=[int(x)for x in input().split()]
    f=[]
    t=[]
    e=[]
    for x in a :
        if x % 2 :
            e.append(x)
        elif x % 4==0 :
            f.append(x)
        else :
            t.append(x)
    if len(e)>len(f):
        if not t and len(e)==len(f)+1 and len(f)!=0 :
            print("Yes")
        else :
            print("No")
    else :
        print("Yes")
t=1
for case in range(1,t+1):
    ans=solve()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    t := 1 ;
    for case : Integer.subrange(1, MatrixLib.elementwiseAdd(t, 1)-1) do (    var ans : OclAny := solve());
  operation solve()
  pre: true post: true
  activity:
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    var f : Sequence := Sequence{} ;
    var t : Sequence := Sequence{} ;
    var e : Sequence := Sequence{} ;
    for x : a do (    if x mod 2 then  (
      execute ((x) : e)
    )
    else (if x mod 4 = 0 then
   (
      execute ((x) : f)    
)
    else (
      execute ((x) : t)
      )    )
) ;
    if ((e)->size()->compareTo((f)->size())) > 0 then  (
      if not(t) & (e)->size() = (f)->size() + 1 & (f)->size() /= 0 then  (
      execute ("Yes")->display()
    )
    else (
      execute ("No")->display()
      )
    )
    else (
      execute ("Yes")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=input().split()
a[0]=int(a[0])
a[1]=int(a[1])
a[2]=int(a[2])
a.sort()
fir=a[0]
sec=a[1]
thir=a[2]
if fir+sec>thir :
    print(0)
else :
    s=thir-(fir+sec)
    print(s+1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := input().split() ;
    a->first() := ("" + ((a->first())))->toInteger() ;
    a[1+1] := ("" + ((a[1+1])))->toInteger() ;
    a[2+1] := ("" + ((a[2+1])))->toInteger() ;
    a := a->sort() ;
    var fir : OclAny := a->first() ;
    var sec : OclAny := a[1+1] ;
    var thir : OclAny := a[2+1] ;
    if (fir + sec->compareTo(thir)) > 0 then  (
      execute (0)->display()
    )
    else (
      var s : double := thir - (fir + sec) ;
    execute (s + 1)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
l=list(map(int,input().split()))
a,b,c=l[0],l[1],l[2]
if a+b>c and a+c>b and b+c>a :
    print(0)
else :
    m1=min(l)
    l.remove(m1)
    m2=min(l)
    l.remove(m2)
    print(abs(m1+m2-l[0])+1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := Sequence{l->first(),l[1+1],l[2+1]} ;
    if (a + b->compareTo(c)) > 0 & (a + c->compareTo(b)) > 0 & (b + c->compareTo(a)) > 0 then  (
      execute (0)->display()
    )
    else (
      var m1 : OclAny := (l)->min() ;
    execute ((m1) /: l) ;
    var m2 : OclAny := (l)->min() ;
    execute ((m2) /: l) ;
    execute ((m1 + m2 - l->first())->abs() + 1)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
x,y,z=map(int,input().split())
if(x+y<=z):
    print(z-(x+y)+1)
elif(x+z<=y):
    print(y-(x+z)+1)
elif(y+z<=x):
    print(x-(y+z)+1)
else :
    print(0)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var x : OclAny := null;
    var y : OclAny := null;
    var z : OclAny := null;
    Sequence{x,y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if ((x + y->compareTo(z)) <= 0) then  (
      execute (z - (x + y) + 1)->display()
    )
    else (if ((x + z->compareTo(y)) <= 0) then
   (
      execute (y - (x + z) + 1)->display()    
)
    else (if ((y + z->compareTo(x)) <= 0) then
   (
      execute (x - (y + z) + 1)->display()    
)
    else (
      execute (0)->display()
      )    )
    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def makeAtriangle(x,y,z):
    if x+y<=z :
        return z-(x+y)+1
    elif x+z<=y :
        return y-(x+z)+1
    elif y+z<=x :
        return x-(y+z)+1
    else :
        return 0
q,w,e=map(int,input().split(" "))
print(makeAtriangle(q,w,e))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var q : OclAny := null;
    var w : OclAny := null;
    var e : OclAny := null;
    Sequence{q,w,e} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (makeAtriangle(q, w, e))->display();
  operation makeAtriangle(x : OclAny, y : OclAny, z : OclAny) : OclAny
  pre: true post: true
  activity:
    if (x + y->compareTo(z)) <= 0 then  (
      return z - (x + y) + 1
    )
    else (if (x + z->compareTo(y)) <= 0 then
   (
      return y - (x + z) + 1    
)
    else (if (y + z->compareTo(x)) <= 0 then
   (
      return x - (y + z) + 1    
)
    else (
      return 0
      )    )
    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
lines=[]
for line in sys.stdin :
    line=line.rstrip()
    lines.append(line)
for i in range(len(lines)//2):
    N,R=map(int,lines[2*i].split())
    ops=list(map(int,lines[2*i+1].split()))
    cards=[i for i in range(N)]
    for c in ops :
        deck_a=cards[N//2 : N]
        deck_b=cards[0 : N//2]
        deck_c=cards[0 : 0]
        while len(deck_a)>0 or len(deck_b)>0 :
            d=deck_a[0 : c]
            deck_a=deck_a[c :]
            deck_c+=d
            d=deck_b[0 : c]
            deck_b=deck_b[c :]
            deck_c+=d
        cards=deck_c
    print(cards[-1])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var lines : Sequence := Sequence{} ;
    for line : OclFile["System.in"] do (    var line : String := StringLib.rightTrim(line) ;
    execute ((line) : lines)) ;
    for i : Integer.subrange(0, (lines)->size() div 2-1) do (    var N : OclAny := null;
    var R : OclAny := null;
    Sequence{N,R} := (lines[2 * i+1].split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var ops : Sequence := ((lines[2 * i + 1+1].split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var cards : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (i)) ;
    for c : ops do (    var deck_a : OclAny := cards.subrange(N div 2+1, N) ;
    var deck_b : OclAny := cards.subrange(0+1, N div 2) ;
    var deck_c : OclAny := cards.subrange(0+1, 0) ;
    while (deck_a)->size() > 0 or (deck_b)->size() > 0 do (    var d : OclAny := deck_a.subrange(0+1, c) ;
    deck_a := deck_a.subrange(c+1) ;
    deck_c := deck_c + d ;
    d := deck_b.subrange(0+1, c) ;
    deck_b := deck_b.subrange(c+1) ;
    deck_c := deck_c + d) ;
    cards := deck_c) ;
    execute (cards->last())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    try :
        n,r=map(int,input().split())
        cc=list(map(int,input().split()))
        card=[v for v in range(n)]
        for c in cc :
            A,B,C=card[n//2 :],card[: n//2],[]
            while len(A)or len(B):
                C+=A[: c]
                del A[: c]
                C+=B[: c]
                del B[: c]
            card=C
        print(C[-1])
    except : break
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    try (    var n : OclAny := null;
    var r : OclAny := null;
    Sequence{n,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var cc : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var card : Sequence := Integer.subrange(0, n-1)->select(v | true)->collect(v | (v)) ;
    for c : cc do (    var A : OclAny := null;
    var B : OclAny := null;
    var C : OclAny := null;
    Sequence{A,B,C} := Sequence{card.subrange(n div 2+1),card.subrange(1,n div 2),Sequence{}} ;
    while (A)->size() or (B)->size() do (    C := C + A.subrange(1,c) ;
    execute (A.subrange(1,c))->isDeleted() ;
    C := C + B.subrange(1,c) ;
    execute (B.subrange(1,c))->isDeleted()) ;
    card := C) ;
    execute (C->last())->display())
     catch (_e : OclException) do (    break)
);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import deque
import sys
def suffle(deck,c):
    l=len(deck)
    if l % 2==0 : mid=l//2
    else : mid=(l-1)//2
    deckA=deck[mid :]
    deckB=deck[: mid]
    deckC=[]
    while(len(deckA)!=0 or len(deckB)!=0):
        deckC.extend(deckA[: c])
        deckA=deckA[c :]
        deckC.extend(deckB[: c])
        deckB=deckB[c :]
    return deckC
while(True):
    inp=sys.stdin.readline()
    if not inp : break
    deck=[]
    n,r=map(int,inp[:-1].split())
    deck=[i for i in range(n)]
    c_list=map(int,sys.stdin.readline()[:-1].split())
    for c in c_list :
        deck=suffle(deck,c)
    print(deck[-1])

------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    while (true) do (    var inp : String := (OclFile["System.in"]).readLine() ;
    if not(inp = "") then (
      break
    ) else skip ;
    deck := Sequence{} ;
    var n : OclAny := null;
    var r : OclAny := null;
    Sequence{n,r} := (inp->front().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    deck := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)) ;
    var c_list : Sequence := (sys.stdin.readLine()->front().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    for c : c_list do (    deck := suffle(deck, c)) ;
    execute (deck->last())->display());
  operation suffle(deck : OclAny, c : OclAny) : OclAny
  pre: true post: true
  activity:
    var l : int := (deck)->size() ;
    if l mod 2 = 0 then  (
      var mid : int := l div 2
    )
    else (
      mid := (l - 1) div 2
      ) ;
    var deckA : OclAny := deck.subrange(mid+1) ;
    var deckB : OclAny := deck.subrange(1,mid) ;
    var deckC : Sequence := Sequence{} ;
    while ((deckA)->size() /= 0 or (deckB)->size() /= 0) do (    deckC := deckC->union(deckA.subrange(1,c)) ;
    deckA := deckA.subrange(c+1) ;
    deckC := deckC->union(deckB.subrange(1,c)) ;
    deckB := deckB.subrange(c+1)) ;
    return deckC;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
y=int(input())
c=0
for i in range(1,int(y**0.5)+1):
    if y % i==0 and i!=(y**0.5):
        c+=2
    elif i==(y**0.5):
        c+=1
print(c)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var y : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var c : int := 0 ;
    for i : Integer.subrange(1, ("" + (((y)->pow(0.5))))->toInteger() + 1-1) do (    if y mod i = 0 & i /= ((y)->pow(0.5)) then  (
      c := c + 2
    )
    else (if i = ((y)->pow(0.5)) then
   (
      c := c + 1    
)
 else skip)) ;
    execute (c)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
try :
    while 1 :
        N,R=map(int,input().split())
*C,=map(int,input().split())
*A,=range(N)
        for c in C :
            lb=N//2 ; la=N-lb
            TA=A[N//2 :]
            TB=A[: N//2]
            A=[]
            a=b=0
            while acollect( _x | (OclType["int"])->apply(_x) ))) ;
(testlist_star_expr (star_expr * (expr (atom (name C)))) ,)    Sequence{(testlist_star_expr (star_expr * (expr (atom (name C)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
(testlist_star_expr (star_expr * (expr (atom (name A)))) ,)    Sequence{(testlist_star_expr (star_expr * (expr (atom (name A)))) ,)} := Integer.subrange(0, N-1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,t,r=[int(x)for x in input().split(" ")]
print((r/a)*t)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var t : OclAny := null;
    var r : OclAny := null;
    Sequence{a,t,r} := input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    execute ((r / a) * t)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import exit,stdin
N=int(stdin.readline().rstrip())
A=[int(_)for _ in stdin.readline().rstrip().split()]
one=0
four=0
for a in A :
    if a % 4==0 :
        four+=1
    elif a % 2==1 :
        one+=1
ans='No'
if one+four==N :
    if four+1>=one :
        ans='Yes'
else :
    if four>=one :
        ans='Yes'
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var N : int := ("" + ((stdin.readLine().rstrip())))->toInteger() ;
    var A : Sequence := stdin.readLine().rstrip().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ;
    var one : int := 0 ;
    var four : int := 0 ;
    for a : A do (    if a mod 4 = 0 then  (
      four := four + 1
    )
    else (if a mod 2 = 1 then
   (
      one := one + 1    
)
 else skip)) ;
    var ans : String := 'No' ;
    if one + four = N then  (
      if (four + 1->compareTo(one)) >= 0 then (
      ans := 'Yes'
    ) else skip
    )
    else (
      if (four->compareTo(one)) >= 0 then (
      ans := 'Yes'
    ) else skip
      ) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
inputText=input().split()
a=float(inputText[0])
t=float(inputText[1])
r=float(inputText[2])
print((t*r)/a)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var inputText : OclAny := input().split() ;
    var a : double := ("" + ((inputText->first())))->toReal() ;
    var t : double := ("" + ((inputText[1+1])))->toReal() ;
    var r : double := ("" + ((inputText[2+1])))->toReal() ;
    execute ((t * r) / a)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,t,r=list(map(int,input().split()))
ans=r*t/a
print("{:.6f}".format(ans))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var t : OclAny := null;
    var r : OclAny := null;
    Sequence{a,t,r} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var ans : double := r * t / a ;
    execute (StringLib.interpolateStrings("{:.6f}", Sequence{ans}))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
i=list(map(int,input().split()));
print((i[1]/i[0])*i[2])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var i : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); ;
    execute ((i[1+1] / i->first()) * i[2+1])->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,t,r=[float(i)for i in input().split()]
print("{:.6f}".format(t*r/a))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var t : OclAny := null;
    var r : OclAny := null;
    Sequence{a,t,r} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toReal())) ;
    execute (StringLib.interpolateStrings("{:.6f}", Sequence{t * r / a}))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def sieve_modified():
    for i in range(2,MAX,2):
        for j in range(i,MAX,i):
            prefix[j]+=i
    for i in range(1,MAX):
        prefix[i]+=prefix[i-1]
def sumEvenFactors(L,R):
    return(prefix[R]-prefix[L-1])
if __name__=="__main__" :
    MAX=100000
    prefix=[0]*MAX
    sieve_modified()
    l,r=6,10
    print(sumEvenFactors(l,r))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      var MAX : int := 100000 ;
    var prefix : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX) ;
    sieve_modified() ;
    var l : OclAny := null;
    var r : OclAny := null;
    Sequence{l,r} := Sequence{6,10} ;
    execute (sumEvenFactors(l, r))->display()
    ) else skip;
  operation sieve_modified()
  pre: true post: true
  activity:
    for i : Integer.subrange(2, MAX-1)->select( $x | ($x - 2) mod 2 = 0 ) do (    for j : Integer.subrange(i, MAX-1)->select( $x | ($x - i) mod i = 0 ) do (    prefix[j+1] := prefix[j+1] + i)) ;
    for i : Integer.subrange(1, MAX-1) do (    prefix[i+1] := prefix[i+1] + prefix[i - 1+1]);
  operation sumEvenFactors(L : OclAny, R : OclAny) : OclAny
  pre: true post: true
  activity:
    return (prefix[R+1] - prefix[L - 1+1]);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def getSum(n):
    sum=0
    while n!=0 :
        sum=sum+n % 10
        n=int(n/10)
    return sum
def largestDigitSumdivisior(n):
    res=0
    for i in range(1,n+1):
        if n % i==0 :
            res=max(res,getSum(i))
    return res
n=14
print(largestDigitSumdivisior(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    n := 14 ;
    execute (largestDigitSumdivisior(n))->display();
  operation getSum(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var sum : int := 0 ;
    while n /= 0 do (    sum := sum + n mod 10 ;
    n := ("" + ((n / 10)))->toInteger()) ;
    return sum;
  operation largestDigitSumdivisior(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var res : int := 0 ;
    for i : Integer.subrange(1, n + 1-1) do (    if n mod i = 0 then (
      res := Set{res, getSum(i)}->max()
    ) else skip) ;
    return res;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
t=int(input())
for i in range(t):
    l,r,a=[int(x)for x in input().split()]
    d=r//a
    m=r % a
    res=d+m
    prev=(d-1)*a+(a-1)
    if(prev>=l):
        tmp=(d-1)+(a-1)
        if(res>tmp):
            res=res
        else :
            res=tmp
    print(res)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, t-1) do (    var l : OclAny := null;
    var r : OclAny := null;
    var a : OclAny := null;
    Sequence{l,r,a} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    var d : int := r div a ;
    var m : int := r mod a ;
    var res : int := d + m ;
    var prev : double := (d - 1) * a + (a - 1) ;
    if ((prev->compareTo(l)) >= 0) then (
      var tmp : double := (d - 1) + (a - 1) ;
    if ((res->compareTo(tmp)) > 0) then  (
      res := res
    )
    else (
      res := tmp
      )
    ) else skip ;
    execute (res)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    l,r,a=map(int,input().split())
    k=r-r % a-1
    if ktoInteger()-1) do (    var l : OclAny := null;
    var r : OclAny := null;
    var a : OclAny := null;
    Sequence{l,r,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var k : double := r - r mod a - 1 ;
    if (k->compareTo(l)) < 0 or r mod a = a - 1 then (
      k := r
    ) else skip ;
    execute (k div a + k mod a)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
def countDivisors(n):
    cnt=0
    for i in range(1,(int)(math.sqrt(n))+1):
        if(n % i==0):
            if(n/i==i):
                cnt=cnt+1
            else :
                cnt=cnt+2
    return cnt
print(countDivisors(int(input())))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    execute (countDivisors(("" + (((OclFile["System.in"]).readLine())))->toInteger()))->display();
  operation countDivisors(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var cnt : int := 0 ;
    for i : Integer.subrange(1, (OclType["int"])((n)->sqrt()) + 1-1) do (    if (n mod i = 0) then (
      if (n / i = i) then  (
      cnt := cnt + 1
    )
    else (
      cnt := cnt + 2
      )
    ) else skip) ;
    return cnt;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
for i in range(n):
    l,r,a=map(int,input().split())
    if(r//a)==(l//a):
        print(r//a+r % a)
    else :
        print(max(r//a+r % a,a-1+r//a-1))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, n-1) do (    var l : OclAny := null;
    var r : OclAny := null;
    var a : OclAny := null;
    Sequence{l,r,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if (r div a) = (l div a) then  (
      execute (r div a + r mod a)->display()
    )
    else (
      execute (Set{r div a + r mod a, a - 1 + r div a - 1}->max())->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int,input().split())
sys.setrecursionlimit(10**9)
N=int(input())
As=list(mapint())
one=0
two=0
four=0
for i in range(N):
    a=As[i]
    if a % 4==0 :
        four+=1
    elif a % 2==0 :
        two+=1
    else :
        one+=1
if one==0 :
    print('Yes')
elif one==1 :
    if four>=1 :
        print('Yes')
    else :
        print('No')
else :
    if one+four==N and four>=one-1 :
        print('Yes')
    else :
        if four>=one :
            print('Yes')
        else :
            print('No')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    sys.setrecursionlimit((10)->pow(9)) ;
    var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var As : Sequence := (mapint()) ;
    var one : int := 0 ;
    var two : int := 0 ;
    var four : int := 0 ;
    for i : Integer.subrange(0, N-1) do (    var a : OclAny := As[i+1] ;
    if a mod 4 = 0 then  (
      four := four + 1
    )
    else (if a mod 2 = 0 then
   (
      two := two + 1    
)
    else (
      one := one + 1
      )    )
) ;
    if one = 0 then  (
      execute ('Yes')->display()
    )
    else (if one = 1 then
   (
      if four >= 1 then  (
      execute ('Yes')->display()
    )
    else (
      execute ('No')->display()
      )    
)
    else (
      if one + four = N & (four->compareTo(one - 1)) >= 0 then  (
      execute ('Yes')->display()
    )
    else (
      if (four->compareTo(one)) >= 0 then  (
      execute ('Yes')->display()
    )
    else (
      execute ('No')->display()
      )
      )
      )    )
;
  operation input() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine()->trim();
  operation mapint() : OclAny
  pre: true post: true
  activity:
    return (input().split())->collect( _x | (OclType["int"])->apply(_x) );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
T=int(input())
for tc in range(T):
    l,r,a=(map(int,input().split(' ')))
    j=max(l,r//a*a-1)
    print(max((r//a+r % a),j//a+j % a))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for tc : Integer.subrange(0, T-1) do (    var l : OclAny := null;
    var r : OclAny := null;
    var a : OclAny := null;
    Sequence{l,r,a} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ;
    var j : OclAny := Set{l, r div a * a - 1}->max() ;
    execute (Set{(r div a + r mod a), j div a + j mod a}->max())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input().strip())
def filter(l,r,num):
    if l<=num<=r :
        return num
    return 0
def f_a2(l,r,a):
    num1=filter(l,r,(a*(r//a)+1))
    num2=filter(l,r,(a*(r//a)-1))
    num3=r
    num=max(num1//a+num1 % a,num2//a+num2 % a,num3//a+num3 % a)
    return num
for _ in range(t):
    l,r,a=map(int,input().split(' '))
    print(f_a2(l,r,a))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + ((input()->trim())))->toInteger() ;
    skip ;
    skip ;
    for _anon : Integer.subrange(0, t-1) do (    Sequence{l,r,a} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (f_a2(l, r, a))->display());
  operation filter(l : OclAny, r : OclAny, num : OclAny) : OclAny
  pre: true post: true
  activity:
    if (l->compareTo(num)) <= 0 & (num <= r) then (
      return num
    ) else skip ;
    return 0;
  operation f_a2(l : OclAny, r : OclAny, a : OclAny) : OclAny
  pre: true post: true
  activity:
    var num1 : Sequence := (r)->select( _x | (l)->apply(_x) = true ) ;
    var num2 : Sequence := (r)->select( _x | (l)->apply(_x) = true ) ;
    var num3 : OclAny := r ;
    num := Set{num1 div a + num1 mod a, num2 div a + num2 mod a, num3 div a + num3 mod a}->max() ;
    return num;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def isDivisible(str,k):
    n=len(str)
    c=0
    for i in range(0,k):
        if(str[n-i-1]=='0'):
            c+=1
    return(c==k)
str1="10101100"
k=2
if(isDivisible(str1,k)):
    print("Yes")
else :
    print("No")
str2="111010100"
k=2
if(isDivisible(str2,k)):
    print("Yes")
else :
    print("No")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var str1 : String := "10101100" ;
    k := 2 ;
    if (isDivisible(str1, k)) then  (
      execute ("Yes")->display()
    )
    else (
      execute ("No")->display()
      ) ;
    var str2 : String := "111010100" ;
    k := 2 ;
    if (isDivisible(str2, k)) then  (
      execute ("Yes")->display()
    )
    else (
      execute ("No")->display()
      );
  operation isDivisible(OclType["String"] : OclAny, k : OclAny) : OclAny
  pre: true post: true
  activity:
    var n : int := (OclType["String"])->size() ;
    var c : int := 0 ;
    for i : Integer.subrange(0, k-1) do (    if (("" + ([n - i - 1+1])) = '0') then (
      c := c + 1
    ) else skip) ;
    return (c = k);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def sumOfElements(arr,n):
    m=dict.fromkeys(arr,0)
    for i in range(n):
        m[arr[i]]+=1
    sum=0
    for key,value in m.items():
        if value>=key :
            sum+=key
    return sum
if __name__=="__main__" :
    arr=[1,2,3,3,2,3,2,3,3]
    n=len(arr)
    print(sumOfElements(arr,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{3}->union(Sequence{2}->union(Sequence{3}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 3 })))))))) ;
    n := (arr)->size() ;
    execute (sumOfElements(arr, n))->display()
    ) else skip;
  operation sumOfElements(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var m : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))) ;
    for i : Integer.subrange(0, n-1) do (    m[arr[i+1]+1] := m[arr[i+1]+1] + 1) ;
    var sum : int := 0 ;
    for _tuple : m->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1;
      var key : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var value : OclAny := _tuple->at(_indx);
      if (value->compareTo(key)) >= 0 then (
      sum := sum + key
    ) else skip) ;
    return sum;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=int(input())
C=[int(input())for _ in range(N)]
mod=10**9+7
newC=[C[0]]
for c in C :
    if newC[-1]==c :
        continue
    newC.append(c)
N=len(newC)
L=[0]*(N+1)
L[0]=1
idx=[-1]*(max(newC)+1)
for i in range(N):
    if idx[newC[i]]>=0 :
        L[i+1]+=L[idx[newC[i]]]
    L[i+1]+=L[i]
    L[i+1]%=mod
    idx[newC[i]]=i+1
print(L[-1])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var C : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ;
    var mod : double := (10)->pow(9) + 7 ;
    var newC : Sequence := Sequence{ C->first() } ;
    for c : C do (    if newC->last() = c then (
      continue
    ) else skip ;
    execute ((c) : newC)) ;
    N := (newC)->size() ;
    var L : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ;
    L->first() := 1 ;
    var idx : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, ((newC)->max() + 1)) ;
    for i : Integer.subrange(0, N-1) do (    if idx[newC[i+1]+1] >= 0 then (
      L[i + 1+1] := L[i + 1+1] + L[idx[newC[i+1]+1]+1]
    ) else skip ;
    L[i + 1+1] := L[i + 1+1] + L[i+1] ;
    L[i + 1+1] := L[i + 1+1] mod mod ;
    idx[newC[i+1]+1] := i + 1) ;
    execute (L->last())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import deque
from heapq import heappush,heappop
import sys
input=sys.stdin.readline
def main():
    mod=10**9+7
    n=int(input())
    colors=[int(input())for _ in range(n)]
    pos_dict={}
    for i,color in enumerate(colors):
        if color not in pos_dict :
            pos_dict[color]=deque([])
            continue
        pos_dict[color].append(i)
    branches=[]
    base=1
    for i,color in enumerate(colors):
        if branches and branches[0][0]==i :
            _,add=heappop(branches)
            base+=add
            base %=mod
        if pos_dict[color]:
            next=pos_dict[color].popleft()
            if next==i+1 :
                continue
            add=base
            heappush(branches,(next,add))
    print(base % mod)
if __name__=="__main__" :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    skip ;
    if __name__ = "__main__" then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var mod : double := (10)->pow(9) + 7 ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var colors : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ;
    var pos_dict : OclAny := Set{} ;
    for _tuple : Integer.subrange(1, (colors)->size())->collect( _indx | Sequence{_indx-1, (colors)->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var color : OclAny := _tuple->at(_indx);
      if (pos_dict)->excludes(color) then (
      pos_dict[color+1] := (Sequence{}) ;
    continue
    ) else skip ;
(expr (atom (name pos_dict)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name color)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ;
    var branches : Sequence := Sequence{} ;
    var base : int := 1 ;
    for _tuple : Integer.subrange(1, (colors)->size())->collect( _indx | Sequence{_indx-1, (colors)->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var color : OclAny := _tuple->at(_indx);
      if branches & branches->first()->first() = i then (
      var _anon : OclAny := null;
    var add : OclAny := null;
    Sequence{_anon,add} := heappop(branches) ;
    base := base + add ;
    base := base mod mod
    ) else skip ;
    if pos_dict[color+1] then (
      var next : OclAny := pos_dict[color+1]->first() ;
    if next = i + 1 then (
      continue
    ) else skip ;
    var add : int := base ;
    heappush(branches, Sequence{next, add})
    ) else skip) ;
    execute (base mod mod)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import bisect
MOD=1_000_000_007
n=int(input())
b=[int(input())-1 for _ in range(n)]
idx=0
a=[]
while idxtoInteger() ;
    var b : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger() - 1)) ;
    var idx : int := 0 ;
    var a : Sequence := Sequence{} ;
    while (idx->compareTo(n)) < 0 do (    execute ((b[idx+1]) : a) ;
    while (idx + 1->compareTo(n)) < 0 & b[idx+1] = b[idx + 1+1] do (    idx := idx + 1) ;
    idx := idx + 1) ;
    n := (a)->size() ;
    var pos : Sequence := Integer.subrange(0, 200001-1)->select(_anon | true)->collect(_anon | (Sequence{})) ;
    for i : Integer.subrange(0, n-1) do ((expr (atom (name pos)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ;
    var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ;
    dp->first() := 1 ;
    for i : Integer.subrange(0, n-1) do (    var j : OclAny := bisect.bisect_right(pos[a[i+1]+1], i) ;
    if (j->compareTo((pos[a[i+1]+1])->size())) < 0 then (
      dp[pos[a[i+1]+1][j+1]+1] := dp[pos[a[i+1]+1][j+1]+1] + dp[i+1] ;
    dp[pos[a[i+1]+1][j+1]+1] := dp[pos[a[i+1]+1][j+1]+1] mod MOD
    ) else skip ;
    dp[i + 1+1] := dp[i + 1+1] + dp[i+1] ;
    dp[i + 1+1] := dp[i + 1+1] mod MOD) ;
    execute (dp[n+1])->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    import sys
    read=sys.stdin.buffer.read
    readline=sys.stdin.buffer.readline
    readlines=sys.stdin.buffer.readlines
    sys.setrecursionlimit(10**7)
    from collections import defaultdict
    n=int(readline())
    dp=[0]*(n+1)
    dp[0]=1
    memo=defaultdict(int)
    mod=10**9+7
    for i in range(1,n+1):
        c=int(readline())
        dp[i]=dp[i-1]
        if 0pow(7)) ;
    skip ;
    var n : int := ("" + ((readline())))->toInteger() ;
    var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ;
    dp->first() := 1 ;
    var memo : OclAny := defaultdict(OclType["int"]) ;
    var mod : double := (10)->pow(9) + 7 ;
    for i : Integer.subrange(1, n + 1-1) do (    var c : int := ("" + ((readline())))->toInteger() ;
    dp[i+1] := dp[i - 1+1] ;
    if 0 < memo[c+1] & (memo[c+1] < i - 1) then (
      dp[i+1] := dp[i+1] + dp[memo[c+1]+1]
    ) else skip ;
    memo[c+1] := i ;
    dp[i+1] := dp[i+1] mod mod) ;
    execute (dp[n+1])->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=int(input())
C=dict()
i,cp,hist,ans=0,0,[0]*N,0
for _ in range(N):
    c=int(input())
    if c!=cp :
        if c in C.keys():
            temp=hist[C[c]]+1
            hist[i]=hist[i-1]+temp
            ans+=temp
        else :
            hist[i]+=hist[i-1]
        C[c],cp=i,c
        i+=1
print((ans+1)%(10**9+7))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var C : Map := (arguments ( )) ;
    var i : OclAny := null;
    var cp : OclAny := null;
    var hist : OclAny := null;
    var ans : OclAny := null;
    Sequence{i,cp,hist,ans} := Sequence{0,0,MatrixLib.elementwiseMult(Sequence{ 0 }, N),0} ;
    for _anon : Integer.subrange(0, N-1) do (    var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if c /= cp then (
      if (C.keys())->includes(c) then  (
      var temp : OclAny := hist[C[c+1]+1] + 1 ;
    hist[i+1] := hist[i - 1+1] + temp ;
    ans := ans + temp
    )
    else (
      hist[i+1] := hist[i+1] + hist[i - 1+1]
      ) ;
    var C[c+1] : OclAny := null;
    var cp : OclAny := null;
    Sequence{C[c+1],cp} := Sequence{i,c} ;
    i := i + 1
    ) else skip) ;
    execute ((ans + 1) mod ((10)->pow(9) + 7))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import pow
n,m,r=map(int,input().split())
n1,m1,r1=map(int,input().split())
dis=pow(pow(n1-n,2)+pow(m-m1,2),1/2)
if abs(r1-r)<=dis<=abs(r1+r):
    rad=0
elif disr :
        rad=r1-dis-r
    else :
        rad=r-dis-r1
else :
    rad=dis-(r+r1)
print(rad/2)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : OclAny := null;
    var m : OclAny := null;
    var r : OclAny := null;
    Sequence{n,m,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var n1 : OclAny := null;
    var m1 : OclAny := null;
    var r1 : OclAny := null;
    Sequence{n1,m1,r1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var dis : double := ((n1 - n)->pow(2) + (m - m1)->pow(2))->pow(1 / 2) ;
    if ((r1 - r)->abs()->compareTo(dis)) <= 0 & (dis <= (r1 + r)->abs()) then  (
      var rad : int := 0
    )
    else (if (dis->compareTo(r1 + r)) < 0 then
   (
      if (r1->compareTo(r)) > 0 then  (
      rad := r1 - dis - r
    )
    else (
      rad := r - dis - r1
      )    
)
    else (
      rad := dis - (r + r1)
      )    )
 ;
    execute (rad / 2)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def checkTypeOfTriangle(a,b,c):
    sqa=pow(a,2)
    sqb=pow(b,2)
    sqc=pow(c,2)
    if(sqa==sqa+sqb or sqb==sqa+sqc or sqc==sqa+sqb):
        print("Right-angled Triangle")
    elif(sqa>sqc+sqb or sqb>sqa+sqc or sqc>sqa+sqb):
        print("Obtuse-angled Triangle")
    else :
        print("Acute-angled Triangle")
if __name__=='__main__' :
    a=2
    b=2
    c=2
    checkTypeOfTriangle(a,b,c)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      a := 2 ;
    b := 2 ;
    c := 2 ;
    checkTypeOfTriangle(a, b, c)
    ) else skip;
  operation checkTypeOfTriangle(a : OclAny, b : OclAny, c : OclAny)
  pre: true post: true
  activity:
    var sqa : double := (a)->pow(2) ;
    var sqb : double := (b)->pow(2) ;
    var sqc : double := (c)->pow(2) ;
    if (sqa = sqa + sqb or sqb = sqa + sqc or sqc = sqa + sqb) then  (
      execute ("Right-angled Triangle")->display()
    )
    else (if ((sqa->compareTo(sqc + sqb)) > 0 or (sqb->compareTo(sqa + sqc)) > 0 or (sqc->compareTo(sqa + sqb)) > 0) then
   (
      execute ("Obtuse-angled Triangle")->display()    
)
    else (
      execute ("Acute-angled Triangle")->display()
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def printRect(X,Y,n):
    Xmax=max(X)
    Xmin=min(X)
    Ymax=max(Y)
    Ymin=min(Y)
    print("{",Xmin,",",Ymin,"}",sep="")
    print("{",Xmin,",",Ymax,"}",sep="")
    print("{",Xmax,",",Ymax,"}",sep="")
    print("{",Xmax,",",Ymin,"}",sep="")
X=[4,3,6,1,-1,12]
Y=[4,1,10,3,7,-1]
n=len(X)
printRect(X,Y,n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    X := Sequence{4}->union(Sequence{3}->union(Sequence{6}->union(Sequence{1}->union(Sequence{-1}->union(Sequence{ 12 }))))) ;
    Y := Sequence{4}->union(Sequence{1}->union(Sequence{10}->union(Sequence{3}->union(Sequence{7}->union(Sequence{ -1 }))))) ;
    n := (X)->size() ;
    printRect(X, Y, n);
  operation printRect(X : OclAny, Y : OclAny, n : OclAny)
  pre: true post: true
  activity:
    var Xmax : OclAny := (X)->max() ;
    var Xmin : OclAny := (X)->min() ;
    var Ymax : OclAny := (Y)->max() ;
    var Ymin : OclAny := (Y)->min() ;
    execute ("{")->display() ;
    execute ("{")->display() ;
    execute ("{")->display() ;
    execute ("{")->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
p=10**9+7
def fact(n):
    n_=1
    yield n_
    for i in range(1,n+1):
        n_=(n_*i)% p
        yield n_
def invfact(n,f,p):
    m=pow(f[n],p-2,p)
    yield m
    for i in range(n,0,-1):
        m=m*i % p
        yield m
ans=0
m=n-1
f=list(fact(m))
rf=list(invfact(m,f,p))
rf.reverse()
perm=0
for k in range((n+1)//2,n):
    perm_=f[k-1]*rf[2*k-n]% p*f[k]% p
    ans+=(perm_-perm)% p*k % p
    ans %=p
    perm=perm_
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var p : double := (10)->pow(9) + 7 ;
    skip ;
    skip ;
    var ans : int := 0 ;
    m := n - 1 ;
    f := (fact(m)) ;
    var rf : Sequence := (invfact(m, f, p)) ;
    rf := rf->reverse() ;
    var perm : int := 0 ;
    for k : Integer.subrange((n + 1) div 2, n-1) do (    var perm_ : int := f[k - 1+1] * rf[2 * k - n+1] mod p * f[k+1] mod p ;
    ans := ans + (perm_ - perm) mod p * k mod p ;
    ans := ans mod p ;
    perm := perm_) ;
    execute (ans)->display();
  operation fact(n : OclAny)
  pre: true post: true
  activity:
    var n_ : int := 1 ;
    if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return n_ ;
    for i : Integer.subrange(1, n + 1-1) do (    n_ := (n_ * i) mod p ;
    if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return n_);
  operation invfact(n : OclAny, f : OclAny, p : OclAny)
  pre: true post: true
  activity:
    var m : double := (f[n+1])->pow(p - 2) ;
    if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return m ;
    for i : Integer.subrange(0 + 1, n)->reverse() do (    m := m * i mod p ;
    if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return m);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
Md,MN=1000000007,1000006
fac,ifac,a,res,inv=[1,1],[1,1],[0],0,[1,1]
for i in range(2,MN):
    inv.append(inv[Md % i]*(Md-Md//i)% Md)
    fac.append(fac[-1]*i % Md)
    ifac.append(ifac[-1]*inv[i]% Md)
def C(x,y):
    if(x=0 :
        a.append(D(n-3,n-i-1)*fac[i]*fac[n-i-1]% Md)
    else :
        a.append(0)
for i in range(n-1,0,-1):
    a[i]=(a[i]-a[i-1])% Md
    res=res+a[i]*i
res=res % Md
print(res)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var Md : OclAny := null;
    var MN : OclAny := null;
    Sequence{Md,MN} := Sequence{1000000007,1000006} ;
    var fac : OclAny := null;
    var ifac : OclAny := null;
    var a : OclAny := null;
    var res : OclAny := null;
    var inv : OclAny := null;
    Sequence{fac,ifac,a,res,inv} := Sequence{Sequence{1}->union(Sequence{ 1 }),Sequence{1}->union(Sequence{ 1 }),Sequence{ 0 },0,Sequence{1}->union(Sequence{ 1 })} ;
    for i : Integer.subrange(2, MN-1) do (    execute ((inv[Md mod i+1] * (Md - Md div i) mod Md) : inv) ;
    execute ((fac->last() * i mod Md) : fac) ;
    execute ((ifac->last() * inv[i+1] mod Md) : ifac)) ;
    skip ;
    skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(1, n-1) do (    if i * 2 - n >= 0 then  (
      execute ((D(n - 3, n - i - 1) * fac[i+1] * fac[n - i - 1+1] mod Md) : a)
    )
    else (
      execute ((0) : a)
      )) ;
    for i : Integer.subrange(0 + 1, n - 1)->reverse() do (    a[i+1] := (a[i+1] - a[i - 1+1]) mod Md ;
    var res : OclAny := res + a[i+1] * i) ;
    res := res mod Md ;
    execute (res)->display();
  operation C(x : OclAny, y : OclAny) : OclAny
  pre: true post: true
  activity:
    if ((x->compareTo(y)) < 0) then (
      return 0
    ) else skip ;
    return fac[x+1] * ifac[y+1] * ifac[x - y+1];
  operation D(x : OclAny, y : OclAny) : OclAny
  pre: true post: true
  activity:
    return C(x - y + 1, y);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000,10**9))
write=lambda x : sys.stdout.write(x+"\n")
n=int(input())
M=10**9+7
N=n+3
g1=[None]*(N+1)
g2=[None]*(N+1)
inverse=[None]*(N+1)
g1[0]=g1[1]=g2[0]=g2[1]=1
inverse[0],inverse[1]=[0,1]
for i in range(2,N+1):
    g1[i]=(g1[i-1]*i)% M
    inverse[i]=(-inverse[M % i]*(M//i))% M
    g2[i]=(g2[i-1]*inverse[i])% M
def cmb(n,r,M):
    if(r<0 or r>n):
        return 0
    r=min(r,n-r)
    return(g1[n]*g2[r]*g2[n-r])% M
ans=0
prev=0
for i in range((n+1)//2,n):
    tmp=(cmb(i-1,n-i-1,M)*g1[i]*g1[n-1-i])
    ans+=tmp
    prev=tmp
    ans %=M
i=n-1
ans=(i+1)*(cmb(i-1,n-i-1,M)*g1[i]*g1[n-1-i])-ans
ans %=M
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ;
    sys.setrecursionlimit(Set{1000, (10)->pow(9)}->max()) ;
    var write : Function := lambda x : OclAny in ((OclFile["System.out"]).write(x + "\n")) ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var M : double := (10)->pow(9) + 7 ;
    var N : int := n + 3 ;
    var g1 : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (N + 1)) ;
    var g2 : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (N + 1)) ;
    var inverse : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (N + 1)) ;
    g1->first() := g1->first()(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name g1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name g2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name g2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))) ;
    var inverse->first() : OclAny := null;
    var inverse[1+1] : OclAny := null;
    Sequence{inverse->first(),inverse[1+1]} := Sequence{0}->union(Sequence{ 1 }) ;
    for i : Integer.subrange(2, N + 1-1) do (    g1[i+1] := (g1[i - 1+1] * i) mod M ;
    inverse[i+1] := (-inverse[M mod i+1] * (M div i)) mod M ;
    g2[i+1] := (g2[i - 1+1] * inverse[i+1]) mod M) ;
    skip ;
    var ans : int := 0 ;
    var prev : int := 0 ;
    for i : Integer.subrange((n + 1) div 2, n-1) do (    var tmp : double := (cmb(i - 1, n - i - 1, M) * g1[i+1] * g1[n - 1 - i+1]) ;
    ans := ans + tmp ;
    prev := tmp ;
    ans := ans mod M) ;
    var i : double := n - 1 ;
    ans := (i + 1) * (cmb(i - 1, n - i - 1, M) * g1[i+1] * g1[n - 1 - i+1]) - ans ;
    ans := ans mod M ;
    execute (ans)->display();
  operation cmb(n : OclAny, r : OclAny, M : OclAny) : OclAny
  pre: true post: true
  activity:
    if (r < 0 or (r->compareTo(n)) > 0) then (
      return 0
    ) else skip ;
    r := Set{r, n - r}->min() ;
    return (g1[n+1] * g2[r+1] * g2[n - r+1]) mod M;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import exit,setrecursionlimit,stderr
from functools import reduce
from itertools import*
from collections import defaultdict
from bisect import bisect
def read():
    return int(input())
def reads():
    return[int(x)for x in input().split()]
MOD=10**9+7
N=read()
NN=N+1
fact=[1]*NN
for i in range(1,NN):
    fact[i]=(fact[i-1]*i)% MOD
def inv(n):
    return pow(n,MOD-2,MOD)
invfact=[0]*NN
invfact[-1]=inv(fact[-1])
for i in range(NN-2,-1,-1):
    invfact[i]=invfact[i+1]*(i+1)% MOD
def comb(n,k):
    return fact[n]*invfact[n-k]% MOD*invfact[k]% MOD
S=[0]*N
for k in range((N+1)//2,N):
    S[k]=comb(k-1,N-1-k)*fact[k]% MOD*fact[N-1-k]% MOD
ans=0
for k in range((N+1)//2,N):
    ans=(ans+k*(S[k]-S[k-1])% MOD)% MOD
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var MOD : double := (10)->pow(9) + 7 ;
    var N : OclAny := read() ;
    var NN : OclAny := N + 1 ;
    var fact : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, NN) ;
    for i : Integer.subrange(1, NN-1) do (    fact[i+1] := (fact[i - 1+1] * i) mod MOD) ;
    skip ;
    var invfact : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, NN) ;
    invfact->last() := inv(fact->last()) ;
    for i : Integer.subrange(-1 + 1, NN - 2)->reverse() do (    invfact[i+1] := invfact[i + 1+1] * (i + 1) mod MOD) ;
    skip ;
    var S : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ;
    for k : Integer.subrange((N + 1) div 2, N-1) do (    S[k+1] := comb(k - 1, N - 1 - k) * fact[k+1] mod MOD * fact[N - 1 - k+1] mod MOD) ;
    var ans : int := 0 ;
    for k : Integer.subrange((N + 1) div 2, N-1) do (    ans := (ans + k * (S[k+1] - S[k - 1+1]) mod MOD) mod MOD) ;
    execute (ans)->display();
  operation read() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation reads() : OclAny
  pre: true post: true
  activity:
    return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()));
  operation inv(n : OclAny) : OclAny
  pre: true post: true
  activity:
    return (n)->pow(MOD - 2);
  operation comb(n : OclAny, k : OclAny) : OclAny
  pre: true post: true
  activity:
    return fact[n+1] * invfact[n - k+1] mod MOD * invfact[k+1] mod MOD;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
N=int(input())
if N==2 :
    print(1)
    sys.exit()
if N==3 :
    print(4)
    sys.exit()
mod=10**9+7
table=[1]*(N+3)
t=1
for i in range(1,N+3):
    t*=i
    t %=mod
    table[i]=t
rtable=[1]*(N+3)
t=1
for i in range(1,N+3):
    t*=pow(i,mod-2,mod)
    t %=mod
    rtable[i]=t
ans=0
l=0
for k in range(N):
    if 0>2*k-N :
        continue
    num=table[k]*table[N-1-k]
    div=table[k-1]*rtable[N-1-k]*rtable[k-1-(N-1-k)]
    div %=mod
    num*=div
    num %=mod
    ans+=k*(num-l)
    l=num
    l %=mod
    ans %=mod
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if N = 2 then (
      execute (1)->display() ;
    sys.exit()
    ) else skip ;
    if N = 3 then (
      execute (4)->display() ;
    sys.exit()
    ) else skip ;
    var mod : double := (10)->pow(9) + 7 ;
    var table : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (N + 3)) ;
    var t : int := 1 ;
    for i : Integer.subrange(1, N + 3-1) do (    t := t * i ;
    t := t mod mod ;
    table[i+1] := t) ;
    var rtable : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (N + 3)) ;
    t := 1 ;
    for i : Integer.subrange(1, N + 3-1) do (    t := t * (i)->pow(mod - 2) ;
    t := t mod mod ;
    rtable[i+1] := t) ;
    var ans : int := 0 ;
    var l : int := 0 ;
    for k : Integer.subrange(0, N-1) do (    if 0 > 2 * k - N then (
      continue
    ) else skip ;
    var num : double := table[k+1] * table[N - 1 - k+1] ;
    var div : double := table[k - 1+1] * rtable[N - 1 - k+1] * rtable[k - 1 - (N - 1 - k)+1] ;
    div := div mod mod ;
    num := num * div ;
    num := num mod mod ;
    ans := ans + k * (num - l) ;
    l := num ;
    l := l mod mod ;
    ans := ans mod mod) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
def multiple(a,b,x):
    if(b<0):
        if(a==1 and x==1):
            print("1");
        else :
            print("0");
    mul=int(pow(a,b));
    ans=int(mul/x);
    ans1=x*ans ;
    ans2=x*(ans+1);
    if((mul-ans1)<=(ans2-mul)):
        print(ans1);
    else :
        print(ans2);
a=349 ;
b=1 ;
x=4 ;
multiple(a,b,x);
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    a := 349; ;
    b := 1; ;
    x := 4; ;
    multiple(a, b, x);;
  operation multiple(a : OclAny, b : OclAny, x : OclAny)
  pre: true post: true
  activity:
    if (b < 0) then (
      if (a = 1 & x = 1) then  (
      execute ("1")->display();
    )
    else (
      execute ("0")->display();
      )
    ) else skip ;
    var mul : int := ("" + (((a)->pow(b))))->toInteger(); ;
    var ans : int := ("" + ((mul / x)))->toInteger(); ;
    var ans1 : double := x * ans; ;
    var ans2 : double := x * (ans + 1); ;
    if (((mul - ans1)->compareTo((ans2 - mul))) <= 0) then  (
      execute (ans1)->display();
    )
    else (
      execute (ans2)->display();
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for i in range(t):
    l,r=map(int,input().split())
    if l*2>r :
        print(-1,-1)
    else :
        print(l,l*2)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, t-1) do (    var l : OclAny := null;
    var r : OclAny := null;
    Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if (l * 2->compareTo(r)) > 0 then  (
      execute (-1)->display()
    )
    else (
      execute (l)->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for i in range(t):
    l,r=map(int,input().split())
    if l*2>r :
        print(-1,-1)
    else :
        print(l,l*2)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, t-1) do (    var l : OclAny := null;
    var r : OclAny := null;
    Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if (l * 2->compareTo(r)) > 0 then  (
      execute (-1)->display()
    )
    else (
      execute (l)->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def lcm(l,r):
    num1=l
    num2=r
    while r!=0 :
        temp=l % r
        l=r
        r=temp
    return(num1*num2)/l
t=eval(input())
for i in range(t):
    l_r=list(map(lambda x : eval(x),input().split(" ")))
    x=l_r[0]
    k=2
    y=k*l_r[0]
    while y<=l_r[1]:
        if(lcm(x,y)>=l_r[0])and(lcm(x,y)<=l_r[1]):
            print(x,y)
            break
        else :
            k+=1
            y=k*l_r[0]
    else :
        print(-1,-1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var t : OclAny := (OclFile["System.in"]).readLine() ;
    for i : Integer.subrange(0, t-1) do (    var l_r : Sequence := ((input().split(" "))->collect( _x | (lambda x : OclAny in (x))->apply(_x) )) ;
    var x : OclAny := l_r->first() ;
    var k : int := 2 ;
    var y : double := k * l_r->first() ;
(compound_stmt while (test (logical_test (comparison (comparison (expr (atom (name y)))) <= (comparison (expr (atom (name l_r)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name lcm)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x))))))) , (argument (test (logical_test (comparison (expr (atom (name y)))))))) ))))) >= (comparison (expr (atom (name l_r)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))) and (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name lcm)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x))))))) , (argument (test (logical_test (comparison (expr (atom (name y)))))))) ))))) <= (comparison (expr (atom (name l_r)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x))))))) , (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name k)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name y)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name k))) * (expr (atom (name l_r)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ))))))))))))))));
  operation lcm(l : OclAny, r : OclAny) : OclAny
  pre: true post: true
  activity:
    var num1 : OclAny := l ;
    var num2 : OclAny := r ;
    while r /= 0 do (    var temp : int := l mod r ;
    l := r ;
    r := temp) ;
    return (num1 * num2) / l;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
MAX=100
def countSubsequence(s,n):
    cntG=0
    cntF=0
    result=0
    C=0
    for i in range(n):
        if(s[i]=='G'):
            cntG+=1
            result+=C
            continue
        if(s[i]=='F'):
            cntF+=1
            C+=cntG
            continue
        else :
            continue
    print(result)
if __name__=='__main__' :
    s="GFGFG"
    n=len(s)
    countSubsequence(s,n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var MAX : int := 100 ;
    skip ;
    if __name__ = '__main__' then (
      s := "GFGFG" ;
    n := (s)->size() ;
    countSubsequence(s, n)
    ) else skip;
  operation countSubsequence(s : OclAny, n : OclAny)
  pre: true post: true
  activity:
    var cntG : int := 0 ;
    var cntF : int := 0 ;
    var result : int := 0 ;
    var C : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    if (s[i+1] = 'G') then (
      cntG := cntG + 1 ;
    result := result + C ;
    continue
    ) else skip ;
    if (s[i+1] = 'F') then  (
      cntF := cntF + 1 ;
    C := C + cntG ;
    continue
    )
    else (
      continue
      )) ;
    execute (result)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=eval(input())
for i in range(t):
    l_r=list(map(lambda x : eval(x),input().split(" ")))
    x=l_r[0]
    y=2*l_r[0]
    if y<=l_r[1]:
        print(x,y)
    else :
        print(-1,-1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : OclAny := (OclFile["System.in"]).readLine() ;
    for i : Integer.subrange(0, t-1) do (    var l_r : Sequence := ((input().split(" "))->collect( _x | (lambda x : OclAny in (x))->apply(_x) )) ;
    var x : OclAny := l_r->first() ;
    var y : double := 2 * l_r->first() ;
    if (y->compareTo(l_r[1+1])) <= 0 then  (
      execute (x)->display()
    )
    else (
      execute (-1)->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def findSum(N,K):
    ans=0 ;
    y=N/K ;
    x=N % K ;
    ans=((K*(K-1)/2)*y+(x*(x+1))/2);
    return int(ans);
N=10 ;
K=2 ;
print(findSum(N,K));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    N := 10; ;
    K := 2; ;
    execute (findSum(N, K))->display();;
  operation findSum(N : OclAny, K : OclAny)
  pre: true post: true
  activity:
    var ans : int := 0; ;
    var y : double := N / K; ;
    var x : int := N mod K; ;
    ans := ((K * (K - 1) / 2) * y + (x * (x + 1)) / 2); ;
    return ("" + ((ans)))->toInteger();;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for _ in range(t):
    l,r=map(int,input().split())
    x=0
    y=0
    if(l*2<=r):
        x=l
        y=l*2
    else :
        x=-1
        y=-1
    print(x,y)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, t-1) do (    var l : OclAny := null;
    var r : OclAny := null;
    Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var x : int := 0 ;
    var y : int := 0 ;
    if ((l * 2->compareTo(r)) <= 0) then  (
      x := l ;
    y := l * 2
    )
    else (
      x := -1 ;
    y := -1
      ) ;
    execute (x)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def find_leftmost_unsetbit(n):
    ind=-1 ;
    i=1 ;
    while(n):
        if((n % 2)!=1):
            ind=i ;
        i+=1 ;
        n>>=1 ;
    return ind ;
def perform_steps(n):
    left=find_leftmost_unsetbit(n);
    if(left==-1):
        print("No steps required");
        return ;
    step=1 ;
    while(find_leftmost_unsetbit(n)!=-1):
        if(step % 2==0):
            n+=1 ;
            print("Step",step,": Increase by 1\n");
        else :
            m=find_leftmost_unsetbit(n);
            num=(2**m)-1 ;
            n=n ^ num ;
            print("Step",step,": Xor with",num);
        step+=1 ;
n=39 ;
perform_steps(n);
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    n := 39; ;
    perform_steps(n);;
  operation find_leftmost_unsetbit(n : OclAny)
  pre: true post: true
  activity:
    var ind : int := -1; ;
    var i : int := 1; ;
    while (n) do (    if ((n mod 2) /= 1) then (
      ind := i;
    ) else skip ;
    i := i + 1; ;
    n := n div (2->pow(1));) ;
    return ind;;
  operation perform_steps(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var left : OclAny := find_leftmost_unsetbit(n); ;
    if (left = -1) then (
      execute ("No steps required")->display(); ;
    return;
    ) else skip ;
    var step : int := 1; ;
    while (find_leftmost_unsetbit(n) /= -1) do (    if (step mod 2 = 0) then  (
      n := n + 1; ;
    execute ("Step")->display();
    )
    else (
      var m : OclAny := find_leftmost_unsetbit(n); ;
    var num : double := ((2)->pow(m)) - 1; ;
    n := MathLib.bitwiseXor(n, num); ;
    execute ("Step")->display();
      ) ;
    step := step + 1;);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def findTwoscomplement(str):
    n=len(str)
    i=n-1
    while(i>=0):
        if(str[i]=='1'):
            break
        i-=1
    if(i==-1):
        return '1'+str
    k=i-1
    while(k>=0):
        if(str[k]=='1'):
            str=list(str)
            str[k]='0'
            str=''.join(str)
        else :
            str=list(str)
            str[k]='1'
            str=''.join(str)
        k-=1
    return str
if __name__=='__main__' :
    str="00000101"
    print(findTwoscomplement(str))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      OclType["String"] := "00000101" ;
    execute (findTwoscomplement(OclType["String"]))->display()
    ) else skip;
  operation findTwoscomplement(OclType["String"] : OclAny) : OclAny
  pre: true post: true
  activity:
    var n : int := (OclType["String"])->size() ;
    var i : double := n - 1 ;
    while (i >= 0) do (    if (("" + ([i+1])) = '1') then (
      break
    ) else skip ;
    i := i - 1) ;
    if (i = -1) then (
      return '1' + OclType["String"]
    ) else skip ;
    var k : double := i - 1 ;
    while (k >= 0) do (    if (("" + ([k+1])) = '1') then  (
      OclType["String"] := (OclType["String"])->characters() ;
    ("" + ([k+1])) := '0' ;
    OclType["String"] := StringLib.sumStringsWithSeparator((OclType["String"]), '')
    )
    else (
      OclType["String"] := (OclType["String"])->characters() ;
    ("" + ([k+1])) := '1' ;
    OclType["String"] := StringLib.sumStringsWithSeparator((OclType["String"]), '')
      ) ;
    k := k - 1) ;
    return OclType["String"];
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
MAX=100
def CountDecreasingPathsCell(mat,dp,n,x,y):
    if(dp[x][y]!=-1):
        return dp[x][y]
    delta=[[0,1],[1,0],[-1,0],[0,-1]]
    newx,newy=0,0
    ans=1
    for i in range(4):
        newx=x+delta[i][0]
        newy=y+delta[i][1]
        if(newx>=0 and newx=0 and newyunion(Sequence{ 2 })}->union(Sequence{ Sequence{1}->union(Sequence{ 3 }) }) ;
    execute (countDecreasingPathsMatrix(n, mat))->display();
  operation CountDecreasingPathsCell(mat : OclAny, dp : OclAny, n : OclAny, x : OclAny, y : OclAny) : OclAny
  pre: true post: true
  activity:
    if (dp[x+1][y+1] /= -1) then (
      return dp[x+1][y+1]
    ) else skip ;
    var delta : Sequence := Sequence{Sequence{0}->union(Sequence{ 1 })}->union(Sequence{Sequence{1}->union(Sequence{ 0 })}->union(Sequence{Sequence{-1}->union(Sequence{ 0 })}->union(Sequence{ Sequence{0}->union(Sequence{ -1 }) }))) ;
    var newx : OclAny := null;
    var newy : OclAny := null;
    Sequence{newx,newy} := Sequence{0,0} ;
    var ans : int := 1 ;
    for i : Integer.subrange(0, 4-1) do (    var newx : OclAny := x + delta[i+1]->first() ;
    var newy : OclAny := y + delta[i+1][1+1] ;
    if (newx >= 0 & (newx->compareTo(n)) < 0 & newy >= 0 & (newy->compareTo(n)) < 0 & (mat[newx+1][newy+1]->compareTo(mat[x+1][y+1])) < 0) then (
      ans := ans + CountDecreasingPathsCell(mat, dp, n, newx, newy)
    ) else skip) ;
    dp[x+1][y+1] := ans ;
    return dp[x+1][y+1];
  operation countDecreasingPathsMatrix(n : OclAny, mat : OclAny) : OclAny
  pre: true post: true
  activity:
    dp := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    var l : Sequence := Sequence{} ;
    for j : Integer.subrange(0, n-1) do (    execute ((-1) : l)) ;
    execute ((l) : dp)) ;
    var sum : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    for j : Integer.subrange(0, n-1) do (    sum := sum + CountDecreasingPathsCell(mat, dp, n, i, j))) ;
    return sum;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n_days,m_bowls,k_plates=map(int,input().split())
wash_counter=0
for type_dish in input().split():
    if type_dish=="1" :
        if m_bowls==0 :
            wash_counter+=1
        else :
            m_bowls-=1
    elif type_dish=="2" :
        if k_plates>0 :
            k_plates-=1
            continue
        if m_bowls==0 :
            wash_counter+=1
        else :
            m_bowls-=1
print(wash_counter)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n_days : OclAny := null;
    var m_bowls : OclAny := null;
    var k_plates : OclAny := null;
    Sequence{n_days,m_bowls,k_plates} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var wash_counter : int := 0 ;
    for type_dish : input().split() do (    if type_dish = "1" then  (
      if m_bowls = 0 then  (
      wash_counter := wash_counter + 1
    )
    else (
      m_bowls := m_bowls - 1
      )
    )
    else (if type_dish = "2" then
   (
      if k_plates > 0 then (
      k_plates := k_plates - 1 ;
    continue
    ) else skip ;
    if m_bowls = 0 then  (
      wash_counter := wash_counter + 1
    )
    else (
      m_bowls := m_bowls - 1
      )    
)
 else skip)) ;
    execute (wash_counter)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
_,clear_g,clear_p=map(int,input().split())
lst=list(map(int,input().split()))
wash=0
for i in lst :
    if i==1 :
        wash+=clear_g<=0
        clear_g-=1
    else :
        wash+=clear_g<=0 and clear_p<=0
        clear_g-=clear_p<=0
        clear_p-=1
print(wash)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var _anon : OclAny := null;
    var clear_g : OclAny := null;
    var clear_p : OclAny := null;
    Sequence{_anon,clear_g,clear_p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var wash : int := 0 ;
    for i : lst do (    if i = 1 then  (
      wash := wash + clear_g <= 0 ;
    clear_g := clear_g - 1
    )
    else (
      wash := wash + clear_g <= 0 & clear_p <= 0 ;
    clear_g := clear_g - clear_p <= 0 ;
    clear_p := clear_p - 1
      )) ;
    execute (wash)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m,k=list(map(int,input().split()))
lst=list(map(int,input().split()))
ans=0
for i in range(n):
    if lst[i]==1 :
        if m==0 :
            ans+=1
        else :
            m-=1
    else :
        if k!=0 :
            k-=1
            continue
        if m!=0 :
            m-=1
            continue
        ans+=1
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    var k : OclAny := null;
    Sequence{n,m,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var ans : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    if lst[i+1] = 1 then  (
      if m = 0 then  (
      ans := ans + 1
    )
    else (
      m := m - 1
      )
    )
    else (
      if k /= 0 then (
      k := k - 1 ;
    continue
    ) else skip ;
    if m /= 0 then (
      m := m - 1 ;
    continue
    ) else skip ;
    ans := ans + 1
      )) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m,k=list(map(int,input().split()))
lst=list(map(int,input().split()))
ans=0
for i in range(n):
    if lst[i]==1 :
        if m==0 :
            ans+=1
        else :
            m-=1
    else :
        if k!=0 :
            k-=1
            continue
        if m!=0 :
            m-=1
            continue
        ans+=1
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    var k : OclAny := null;
    Sequence{n,m,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var ans : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    if lst[i+1] = 1 then  (
      if m = 0 then  (
      ans := ans + 1
    )
    else (
      m := m - 1
      )
    )
    else (
      if k /= 0 then (
      k := k - 1 ;
    continue
    ) else skip ;
    if m /= 0 then (
      m := m - 1 ;
    continue
    ) else skip ;
    ans := ans + 1
      )) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=int(input())
edges=[list(map(int,input().split()))for _ in range(N)]
for cx in range(101):
    for cy in range(101):
        for i in range(N):
            x,y,h=map(int,edges[i])
            if h>0 :
                htop=abs(x-cx)+abs(y-cy)+h
        for i in range(N):
            x,y,h=map(int,edges[i])
            if h==0 :
                if htop-(abs(x-cx)+abs(y-cy))>0 :
                    break
            if h>0 :
                if htop-(abs(x-cx)+abs(y-cy))!=h :
                    break
        else :
            print(cx,cy,htop)
            exit()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var edges : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    for cx : Integer.subrange(0, 101-1) do (    for cy : Integer.subrange(0, 101-1) do (    for i : Integer.subrange(0, N-1) do (    var x : OclAny := null;
    var y : OclAny := null;
    var h : OclAny := null;
    Sequence{x,y,h} := (edges[i+1])->collect( _x | (OclType["int"])->apply(_x) ) ;
    if h > 0 then (
      var htop : double := (x - cx)->abs() + (y - cy)->abs() + h
    ) else skip) ;
(compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name x)))))) , (test (logical_test (comparison (expr (atom (name y)))))) , (test (logical_test (comparison (expr (atom (name h))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name h)))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name htop))) - (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (name cx))))))))) )))) + (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (name cy))))))))) ))))))))) ))))) > (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt break))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name h)))) > (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name htop))) - (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (name cx))))))))) )))) + (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (name cy))))))))) ))))))))) ))))) != (comparison (expr (atom (name h))))))) : (suite (stmt (simple_stmt (small_stmt break)))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name cx))))))) , (argument (test (logical_test (comparison (expr (atom (name cy))))))) , (argument (test (logical_test (comparison (expr (atom (name htop)))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name exit)) (trailer (arguments ( )))))))))))))))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for i in a :
    if i==1 and m>0 :
        m-=1
    elif i==1 and m<=0 :
        ans+=1
    elif k>0 and i==2 :
        k-=1
    elif m>0 and i==2 :
        m-=1
    else :
        ans+=1
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    var k : OclAny := null;
    Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var ans : int := 0 ;
    for i : a do (    if i = 1 & m > 0 then  (
      m := m - 1
    )
    else (if i = 1 & m <= 0 then
   (
      ans := ans + 1    
)
    else (if k > 0 & i = 2 then
   (
      k := k - 1    
)
    else (if m > 0 & i = 2 then
   (
      m := m - 1    
)
    else (
      ans := ans + 1
      )    )
    )
    )
) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    s=input()
    if s[0]=='.' : break
    r=[]
    f=False
    for c in s :
        if c=='(' or c=='[' :
            r.append(c)
        elif c==')' :
            if not r or r.pop()!='(' :
                print("no")
                break
        elif c==']' :
            if not r or r.pop()!='[' :
                print("no")
                break
    else :
        print("yes" if not r else "no")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    var s : String := (OclFile["System.in"]).readLine() ;
    if s->first() = '.' then (
      break
    ) else skip ;
    var r : Sequence := Sequence{} ;
    var f : boolean := false ;
(compound_stmt for (exprlist (expr (atom (name c)))) in (testlist (test (logical_test (comparison (expr (atom (name s))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name c)))) == (comparison (expr (atom '('))))) or (logical_test (comparison (comparison (expr (atom (name c)))) == (comparison (expr (atom '['))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name r)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name c)))) == (comparison (expr (atom ')')))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test not (logical_test (comparison (expr (atom (name r)))))) or (logical_test (comparison (comparison (expr (atom (name r)) (trailer . (name pop) (arguments ( ))))) != (comparison (expr (atom '('))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "no"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name c)))) == (comparison (expr (atom ']')))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test not (logical_test (comparison (expr (atom (name r)))))) or (logical_test (comparison (comparison (expr (atom (name r)) (trailer . (name pop) (arguments ( ))))) != (comparison (expr (atom '['))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "no"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "yes")))) if (logical_test not (logical_test (comparison (expr (atom (name r)))))) else (test (logical_test (comparison (expr (atom "no")))))))) ))))))))))))))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def isPrime(n):
    if(n<=1):
        return False
    if(n<=3):
        return True
    if(n % 2==0 or n % 3==0):
        return False
    i=5
    while(i*i<=n):
        if(n % i==0 or n %(i+2)==0):
            return False
        i=i+6
    return True
def isDiffPrime(a,b):
    if(isPrime(a+b)and a-b==1):
        return True
    else :
        return False
a=6
b=5
if(isDiffPrime(a,b)):
    print("Yes")
else :
    print("No")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    a := 6 ;
    b := 5 ;
    if (isDiffPrime(a, b)) then  (
      execute ("Yes")->display()
    )
    else (
      execute ("No")->display()
      );
  operation isPrime(n : OclAny) : OclAny
  pre: true post: true
  activity:
    if (n <= 1) then (
      return false
    ) else skip ;
    if (n <= 3) then (
      return true
    ) else skip ;
    if (n mod 2 = 0 or n mod 3 = 0) then (
      return false
    ) else skip ;
    var i : int := 5 ;
    while ((i * i->compareTo(n)) <= 0) do (    if (n mod i = 0 or n mod (i + 2) = 0) then (
      return false
    ) else skip ;
    i := i + 6) ;
    return true;
  operation isDiffPrime(a : OclAny, b : OclAny) : OclAny
  pre: true post: true
  activity:
    if (isPrime(a + b) & a - b = 1) then  (
      return true
    )
    else (
      return false
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def is_balanced(txt):
    round_brackets=[]
    square_brackets=[]
    for c in txt :
        if c=='(' :
            round_brackets.append(len(square_brackets))
        elif c==')' :
            try :
                level=round_brackets.pop()
                if level!=len(square_brackets):
                    return False
            except IndexError :
                return False
        elif c=='[' :
            square_brackets.append(len(round_brackets))
        elif c==']' :
            try :
                level=square_brackets.pop()
                if level!=len(round_brackets):
                    return False
            except IndexError :
                return False
    if len(round_brackets)==0 and len(square_brackets)==0 :
        return True
    else :
        return False
if __name__=='__main__' :
    while True :
        txt=input()
        if txt=='.' :
            break
        ans=is_balanced(txt)
        if ans :
            print('yes')
        else :
            print('no')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      while true do (    txt := (OclFile["System.in"]).readLine() ;
    if txt = '.' then (
      break
    ) else skip ;
    var ans : OclAny := is_balanced(txt) ;
    if ans then  (
      execute ('yes')->display()
    )
    else (
      execute ('no')->display()
      ))
    ) else skip;
  operation is_balanced(txt : OclAny) : OclAny
  pre: true post: true
  activity:
    var round_brackets : Sequence := Sequence{} ;
    var square_brackets : Sequence := Sequence{} ;
    for c : txt do (    if c = '(' then  (
      execute (((square_brackets)->size()) : round_brackets)
    )
    else (if c = ')' then
   (
      try (    var level : OclAny := round_brackets->last() ;     round_brackets := round_brackets->front() ;
    if level /= (square_brackets)->size() then (
      return false
    ) else skip)
(except_clause except (test (logical_test (comparison (expr (atom (name IndexError)))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name False))))))))))))    
)
    else (if c = '[' then
   (
      execute (((round_brackets)->size()) : square_brackets)    
)
    else (if c = ']' then
   (
      try (    level := square_brackets->last() ;     square_brackets := square_brackets->front() ;
    if level /= (round_brackets)->size() then (
      return false
    ) else skip)
(except_clause except (test (logical_test (comparison (expr (atom (name IndexError)))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name False))))))))))))    
)
    else skip    )
    )
    )
) ;
    if (round_brackets)->size() = 0 & (square_brackets)->size() = 0 then  (
      return true
    )
    else (
      return false
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
sys.setrecursionlimit(1000000)
class St():
    def __init__(self,s):
        self.s=s
        self.i=0
def expression(st,num):
    while(not st.s[st.i]=="."):
        if(st.s[st.i]=="("):
            if(not factor1(st)):
                return False
        elif(st.s[st.i]=="["):
            if(not factor2(st)):
                return False
        elif(not st.s[st.i]in[")","]"]):
            st.i+=1
        else :
            if((num==1)and(st.s[st.i]==")"))or((num==2)and(st.s[st.i]=="]")):
                break
            else :
                return False
        if(st.i>=len(st.s)):
            return False
    return True
def factor1(st):
    st.i+=1
    if(st.s[st.i]=="."):
        return False
    if(expression(st,1)):
        st.i+=1
        return True
    return False
def factor2(st):
    st.i+=1
    if(st.s[st.i]=="."):
        return False
    if(expression(st,2)):
        st.i+=1
        return True
    return False
def solve(s):
    st=St(s)
    return expression(st,0)
def main():
    ans=[]
    while True :
        s=input()
        if(s=="."):
            break
        ans.append(solve(s))
    for i in ans :
        print("yes" if i else "no")
main()
------------------------------------------------------------
OCL File:
---------
class St {
  static operation newSt() : St
  pre: true
  post: St->exists( _x | result = _x );
  attribute s : OclAny := s;
  attribute i : int := 0;
  operation initialise(s : OclAny) : 
  pre: true post: true
  activity:
    self.s := s ;
    self.i := 0;
    return self;
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    sys.setrecursionlimit(1000000) ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    main();
  operation expression(st : OclAny, num : OclAny) : OclAny
  pre: true post: true
  activity:
    while (not(st.s[st.i+1] = ".")) do (    if (st.s[st.i+1] = "(") then  (
      if (not(factor1(st))) then (
      return false
    ) else skip
    )
    else (if (st.s[st.i+1] = "[") then
   (
      if (not(factor2(st))) then (
      return false
    ) else skip    
)
    else (if (not((Sequence{")"}->union(Sequence{ "]" }))->includes(st.s[st.i+1]))) then
   (
      st.i := st.i + 1    
)
    else (
      if ((num = 1) & (st.s[st.i+1] = ")")) or ((num = 2) & (st.s[st.i+1] = "]")) then  (
      break
    )
    else (
      return false
      )
      )    )
    )
 ;
    if ((st.i->compareTo((st.s)->size())) >= 0) then (
      return false
    ) else skip) ;
    return true;
  operation factor1(st : OclAny) : OclAny
  pre: true post: true
  activity:
    st.i := st.i + 1 ;
    if (st.s[st.i+1] = ".") then (
      return false
    ) else skip ;
    if (expression(st, 1)) then (
      st.i := st.i + 1 ;
    return true
    ) else skip ;
    return false;
  operation factor2(st : OclAny) : OclAny
  pre: true post: true
  activity:
    st.i := st.i + 1 ;
    if (st.s[st.i+1] = ".") then (
      return false
    ) else skip ;
    if (expression(st, 2)) then (
      st.i := st.i + 1 ;
    return true
    ) else skip ;
    return false;
  operation solve(s : OclAny) : OclAny
  pre: true post: true
  activity:
    st := (St.newSt()).initialise(s) ;
    return expression(st, 0);
  operation main()
  pre: true post: true
  activity:
    var ans : Sequence := Sequence{} ;
    while true do (    s := (OclFile["System.in"]).readLine() ;
    if (s = ".") then (
      break
    ) else skip ;
    execute ((solve(s)) : ans)) ;
    for i : ans do (    execute (if i then "yes" else "no" endif)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
sys.setrecursionlimit(10**6)
def dfs(string,bracket):
    i=0
    while ipow(6)) ;
    skip ;
    while true do (    string := ((OclFile["System.in"]).readLine())->characters() ;
    if (string)->size() = 1 & string->first() = '.' then (
      break
    ) else skip ;
    var ans : String := if dfs(string, '') then 'yes' else 'no' endif ;
    execute (ans)->display());
  operation dfs(string : OclAny, bracket : OclAny) : OclAny
  pre: true post: true
  activity:
    var i : int := 0 ;
    while (i->compareTo((string)->size())) < 0 do (    if bracket = '[' & string[i+1] = ']' then  (
      return i
    )
    else (if bracket = '(' & string[i+1] = ')' then
   (
      return i    
)
    else (if string[i+1] = ')' or string[i+1] = ']' then
   (
      return false    
)
    else (if string[i+1] = '(' or string[i+1] = '[' then
   (
      var ret : OclAny := dfs(string.subrange(i + 1+1), string[i+1]) ;
    if ret <>= false then (
      return false
    ) else skip ;
    i := i + ret + 1    
)
    else skip    )
    )
    )
 ;
    i := i + 1) ;
    return if bracket = '' then true else false endif;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def is_balanced(s):
    stack=[]
    for c in s :
        if c=='(' or c=='[' :
            stack.append(c)
        elif c==')' :
            if not stack :
                return "no"
            elif stack[-1]=='(' :
                stack.pop()
            else :
                return "no"
        elif c==']' :
            if not stack :
                return "no"
            elif stack[-1]=='[' :
                stack.pop()
            else :
                return "no"
    if stack :
        return "no"
    else :
        return "yes"
import sys
file_input=sys.stdin
lines=file_input.readlines()
lines=lines[:-1]
print('\n'.join(map(is_balanced,lines)))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var file_input : OclFile := OclFile["System.in"] ;
    var lines : OclAny := file_input.readlines() ;
    lines := lines->front() ;
    execute (StringLib.sumStringsWithSeparator(((lines)->collect( _x | (is_balanced)->apply(_x) )), '
'))->display();
  operation is_balanced(s : OclAny) : OclAny
  pre: true post: true
  activity:
    var stack : Sequence := Sequence{} ;
    for c : s do (    if c = '(' or c = '[' then  (
      execute ((c) : stack)
    )
    else (if c = ')' then
   (
      if not(stack) then  (
      return "no"
    )
    else (if stack->last() = '(' then
   (
      stack := stack->front()    
)
    else (
      return "no"
      )    )
)
    else (if c = ']' then
   (
      if not(stack) then  (
      return "no"
    )
    else (if stack->last() = '[' then
   (
      stack := stack->front()    
)
    else (
      return "no"
      )    )
)
    else skip    )
    )
) ;
    if stack then  (
      return "no"
    )
    else (
      return "yes"
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for i in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    u=0
    v=0
    for j in range(n):
        if a[j]!=j+1 :
            u=j
            break
    for k in range(u,n):
        if a[k]==u+1 :
            v=k
            break
    if j==n-1 and k==0 :
        print(*a)
    else :
        b=a[j : k+1]
        b=b[: :-1]
        w=a[: j]+b+a[k+1 :]
        print(*w)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var u : int := 0 ;
    var v : int := 0 ;
    for j : Integer.subrange(0, n-1) do (    if a[j+1] /= j + 1 then (
      u := j ;
    break
    ) else skip) ;
    for k : Integer.subrange(u, n-1) do (    if a[k+1] = u + 1 then (
      v := k ;
    break
    ) else skip) ;
    if j = n - 1 & k = 0 then  (
      execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display()
    )
    else (
      var b : OclAny := a.subrange(j+1, k + 1) ;
    b := b(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ;
    var w : OclAny := a.subrange(1,j) + b + a.subrange(k + 1+1) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name w))))))))->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for _ in range(t):
    n,a=int(input()),[int(i)for i in input().split()]
    for i in range(n):
        if a[i]!=i+1 :
            j=a.index(i+1,i+1)
            while itoInteger() ;
    for _anon : Integer.subrange(0, t-1) do (    var n : OclAny := null;
    var a : OclAny := null;
    Sequence{n,a} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))} ;
    for i : Integer.subrange(0, n-1) do (    if a[i+1] /= i + 1 then (
      var j : int := a->indexOf(i + 1, i + 1) - 1 ;
    while (i->compareTo(j)) < 0 do (    var a[i+1] : OclAny := null;
    var a[j+1] : OclAny := null;
    Sequence{a[i+1],a[j+1]} := Sequence{a[j+1],a[i+1]} ;
    var i : OclAny := null;
    Sequence{i,j} := Sequence{i + 1,j - 1}) ;
    break
    ) else skip) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
if __name__=='__main__' :
    t=int(input())
    while t :
        n=int(input())
        a=list(map(int,input().split()))
        ans=[]
        for i in range(n):
            if a[i]>i+1 :
                x=a.index(i+1)
                a=a[: i]+a[i : x+1][: :-1]+a[x+1 :]
                break
        print(*a)
        t-=1
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     if __name__ = '__main__' then (
      var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    while t do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var ans : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    if (a[i+1]->compareTo(i + 1)) > 0 then (
      var x : int := a->indexOf(i + 1) - 1 ;
    a := a.subrange(1,i) + a.subrange(i+1, x + 1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) + a.subrange(x + 1+1) ;
    break
    ) else skip) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display() ;
    t := t - 1)
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import stdin,stdout
def input(): return stdin.readline()
def mi(): return map(int,input().split())
def li(): return list(map(int,input().split()))
n=int(input())
s=li()
a=max(s)
sm=sum(s)
if 2*a-sm<=0 and sm % 2==0 :
    print("YES")
else :
    print("NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var s : OclAny := li() ;
    var a : OclAny := (s)->max() ;
    var sm : OclAny := (s)->sum() ;
    if 2 * a - sm <= 0 & sm mod 2 = 0 then  (
      execute ("YES")->display()
    )
    else (
      execute ("NO")->display()
      );
  operation input() : OclAny
  pre: true post: true
  activity:
    return stdin.readLine();
  operation mi() : OclAny
  pre: true post: true
  activity:
    return (input().split())->collect( _x | (OclType["int"])->apply(_x) );
  operation li() : OclAny
  pre: true post: true
  activity:
    return ((input().split())->collect( _x | (OclType["int"])->apply(_x) ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
n=int(input())
w=list(map(int,input().split()))
z=n
c=0
x=0
while True :
    new_w=[]
    n=len(w)
    for i in range(n):
        if w[i]<=c :
            c+=1
        else :
            new_w.append(w[i])
    if c==z :
        break
    x+=1
    w=new_w[: :-1]
print(x)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var z : int := n ;
    var c : int := 0 ;
    var x : int := 0 ;
    while true do (    var new_w : Sequence := Sequence{} ;
    n := (w)->size() ;
    for i : Integer.subrange(0, n-1) do (    if (w[i+1]->compareTo(c)) <= 0 then  (
      c := c + 1
    )
    else (
      execute ((w[i+1]) : new_w)
      )) ;
    if c = z then (
      break
    ) else skip ;
    x := x + 1 ;
    w := new_w(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ;
    execute (x)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import itertools
n=int(input())
query=[]
for _ in range(n):
    x,y,h=map(int,input().split())
    if h!=0 :
        query.append((x,y,h))
tx=query[0][0]
ty=query[0][1]
th=query[0][2]
if len(query)==1 :
    print(tx,ty,th)
    exit()
query.pop(0)
c=[i for i in range(101)]
cc=list(itertools.product(c,repeat=2))
for X,Y in cc :
    H=th+abs(tx-X)+abs(ty-Y)
    Flag=True
    for x,y,h in query :
        if max(H-abs(x-X)-abs(y-Y),0)!=h :
            Flag=False
            break
    if Flag :
        print(X,Y,H)
        exit()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var query : Sequence := Sequence{} ;
    for _anon : Integer.subrange(0, n-1) do (    var x : OclAny := null;
    var y : OclAny := null;
    var h : OclAny := null;
    Sequence{x,y,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if h /= 0 then (
      execute ((Sequence{x, y, h}) : query)
    ) else skip) ;
    var tx : OclAny := query->first()->first() ;
    var ty : OclAny := query->first()[1+1] ;
    var th : OclAny := query->first()[2+1] ;
    if (query)->size() = 1 then (
      execute (tx)->display() ;
    exit()
    ) else skip ;
    query := query->excludingAt(0+1) ;
    var c : Sequence := Integer.subrange(0, 101-1)->select(i | true)->collect(i | (i)) ;
    var cc : Sequence := (itertools.product(c, (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) ;
    for _tuple : cc do (var _indx : int := 1;
      var X : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var Y : OclAny := _tuple->at(_indx);
      var H : OclAny := th + (tx - X)->abs() + (ty - Y)->abs() ;
    var Flag : boolean := true ;
    for _tuple : query do (var _indx : int := 1;
      var x : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var y : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var h : OclAny := _tuple->at(_indx);
      if Set{H - (x - X)->abs() - (y - Y)->abs(), 0}->max() /= h then (
      Flag := false ;
    break
    ) else skip) ;
    if Flag then (
      execute (X)->display() ;
    exit()
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for s in[*open(0)][2 : : 2]:
    a=[0,*map(int,s.split()),0]; i=1
    while a[i]==i : i+=1
    if a[i]: j=a.index(i)+1 ; a[i : j]=a[i : j][: :-1]
    print(*a[1 :-1])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do (    var a : Sequence := Sequence{0}->union((s.split())->collect( _x | (OclType["int"])->apply(_x) )->union(Sequence{ 0 }));    var i : int := 1 ;
    while a[i+1] = i do (    i := i + 1) ;
    if a[i+1] then (
      var j : int := a->indexOf(i) - 1 + 1;    a.subrange(i+1, j) := a.subrange(i+1, j)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))
    ) else skip ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))))))))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from re import T
import sys
input=sys.stdin.readline
def inp():
    return int(input())
def inlt():
    return list(map(int,input().split()))
def insr():
    s=input()
    return list(s[: len(s)-1])
def invr():
    return map(int,input().split())
T=inp()
for i in range(0,T):
    N=inp()
    A=inlt()
    l=-1
    r=-1
    for i in range(0,N):
        if A[i]!=i+1 :
            for j in range(i,N):
                if A[j]==i+1 :
                    l=i
                    r=j
                    break
        if l!=-1 :
            break
    A[l : r+1]=A[l : r+1][: :-1]
    print(*A," ")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    skip ;
    skip ;
    skip ;
    skip ;
    var T : OclAny := inp() ;
    for i : Integer.subrange(0, T-1) do (    var N : OclAny := inp() ;
    var A : OclAny := inlt() ;
    var l : int := -1 ;
    var r : int := -1 ;
    for i : Integer.subrange(0, N-1) do (    if A[i+1] /= i + 1 then (
      for j : Integer.subrange(i, N-1) do (    if A[j+1] = i + 1 then (
      l := i ;
    r := j ;
    break
    ) else skip)
    ) else skip ;
    if l /= -1 then (
      break
    ) else skip) ;
    A.subrange(l+1, r + 1) := A.subrange(l+1, r + 1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name A))))))))->display());
  operation inp() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation inlt() : OclAny
  pre: true post: true
  activity:
    return ((input().split())->collect( _x | (OclType["int"])->apply(_x) ));
  operation insr() : OclAny
  pre: true post: true
  activity:
    var s : String := (OclFile["System.in"]).readLine() ;
    return (s.subrange(1,(s)->size() - 1));
  operation invr() : OclAny
  pre: true post: true
  activity:
    return (input().split())->collect( _x | (OclType["int"])->apply(_x) );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import*
N=100005
prime=[True]*N
def SieveOfEratosthenes():
    prime[1]=False
    for p in range(2,int(sqrt(N))):
        if prime[p]==True :
            for i in range(2*p,N,p):
                prime[i]=False
def almostPrimes(n):
    ans=0
    for i in range(6,n+1):
        c=0
        for j in range(2,int(sqrt(i))+1):
            if i % j==0 :
                if j*j==i :
                    if prime[j]:
                        c+=1
                else :
                    if prime[j]:
                        c+=1
                    if prime[i//j]:
                        c+=1
        if c==2 :
            ans+=1
    return ans
if __name__=="__main__" :
    SieveOfEratosthenes()
    n=21
    print(almostPrimes(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var N : int := 100005 ;
    var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, N) ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      SieveOfEratosthenes() ;
    n := 21 ;
    execute (almostPrimes(n))->display()
    ) else skip;
  operation SieveOfEratosthenes()
  pre: true post: true
  activity:
    prime[1+1] := false ;
    for p : Integer.subrange(2, ("" + ((sqrt(N))))->toInteger()-1) do (    if prime[p+1] = true then (
      for i : Integer.subrange(2 * p, N-1)->select( $x | ($x - 2 * p) mod p = 0 ) do (    prime[i+1] := false)
    ) else skip);
  operation almostPrimes(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var ans : int := 0 ;
    for i : Integer.subrange(6, n + 1-1) do (    var c : int := 0 ;
    for j : Integer.subrange(2, ("" + ((sqrt(i))))->toInteger() + 1-1) do (    if i mod j = 0 then (
      if j * j = i then  (
      if prime[j+1] then (
      c := c + 1
    ) else skip
    )
    else (
      if prime[j+1] then (
      c := c + 1
    ) else skip ;
    if prime[i div j+1] then (
      c := c + 1
    ) else skip
      )
    ) else skip) ;
    if c = 2 then (
      ans := ans + 1
    ) else skip) ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s,li=map(int,input().split())
l=[]
for i in range(li,0,-1):
    if s==0 : break
    x=i &(-i)
    if x<=s : l.append(i); s-=x
if s==0 : print(len(l)); print(*l)
else : print(-1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : OclAny := null;
    var li : OclAny := null;
    Sequence{s,li} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var l : Sequence := Sequence{} ;
    for i : Integer.subrange(0 + 1, li)->reverse() do (    if s = 0 then (
      break
    ) else skip ;
    var x : int := MathLib.bitwiseAnd(i, (-i)) ;
    if (x->compareTo(s)) <= 0 then (
      execute ((i) : l);    s := s - x
    ) else skip) ;
    if s = 0 then  (
      execute ((l)->size())->display();    execute ((argument * (test (logical_test (comparison (expr (atom (name l))))))))->display()
    )
    else (
      execute (-1)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def thirdLargest(arr,arr_size):
    if(arr_size<3):
        print(" Invalid Input ")
        return
    first=arr[0]
    second=-sys.maxsize
    third=-sys.maxsize
    for i in range(1,arr_size):
        if(arr[i]>first):
            third=second
            second=first
            first=arr[i]
        elif(arr[i]>second):
            third=second
            second=arr[i]
        elif(arr[i]>third):
            third=arr[i]
    print("The third Largest","element is",third)
arr=[12,13,1,10,34,16]
n=len(arr)
thirdLargest(arr,n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    arr := Sequence{12}->union(Sequence{13}->union(Sequence{1}->union(Sequence{10}->union(Sequence{34}->union(Sequence{ 16 }))))) ;
    var n : int := (arr)->size() ;
    thirdLargest(arr, n);
  operation thirdLargest(arr : OclAny, arr_size : OclAny)
  pre: true post: true
  activity:
    if (arr_size < 3) then (
      execute (" Invalid Input ")->display() ;
    return
    ) else skip ;
    var first : OclAny := arr->first() ;
    var second : (trailer . (name maxsize)) := -(trailer . (name maxsize)) ;
    var third : (trailer . (name maxsize)) := -(trailer . (name maxsize)) ;
    for i : Integer.subrange(1, arr_size-1) do (    if ((arr[i+1]->compareTo(first)) > 0) then  (
      third := second ;
    second := first ;
    first := arr[i+1]
    )
    else (if ((arr[i+1]->compareTo(second)) > 0) then
   (
      third := second ;
    second := arr[i+1]    
)
    else (if ((arr[i+1]->compareTo(third)) > 0) then
   (
      third := arr[i+1]    
)
    else skip    )
    )
) ;
    execute ("The third Largest")->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def thirdLargest(arr,arr_size):
    if(arr_size<3):
        print(" Invalid Input ")
        return
    first=arr[0]
    for i in range(1,arr_size):
        if(arr[i]>first):
            first=arr[i]
    second=-sys.maxsize
    for i in range(0,arr_size):
        if(arr[i]>second and arr[i]third and arr[i]union(Sequence{13}->union(Sequence{1}->union(Sequence{10}->union(Sequence{34}->union(Sequence{ 16 }))))) ;
    var n : int := (arr)->size() ;
    thirdLargest(arr, n);
  operation thirdLargest(arr : OclAny, arr_size : OclAny)
  pre: true post: true
  activity:
    if (arr_size < 3) then (
      execute (" Invalid Input ")->display() ;
    return
    ) else skip ;
    var first : OclAny := arr->first() ;
    for i : Integer.subrange(1, arr_size-1) do (    if ((arr[i+1]->compareTo(first)) > 0) then (
      first := arr[i+1]
    ) else skip) ;
    var second : (trailer . (name maxsize)) := -(trailer . (name maxsize)) ;
    for i : Integer.subrange(0, arr_size-1) do (    if ((arr[i+1]->compareTo(second)) > 0 & (arr[i+1]->compareTo(first)) < 0) then (
      second := arr[i+1]
    ) else skip) ;
    var third : (trailer . (name maxsize)) := -(trailer . (name maxsize)) ;
    for i : Integer.subrange(0, arr_size-1) do (    if ((arr[i+1]->compareTo(third)) > 0 & (arr[i+1]->compareTo(second)) < 0) then (
      third := arr[i+1]
    ) else skip) ;
    execute ("The Third Largest")->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def extgcd(a,b):
    if b==0 :
        x=1
        y=0
        return a,x,y
    g,s,t=extgcd(b,a % b)
    x,y=t,s-a//b*t
    return g,x,y
def chineserem(b,m):
    r=0
    M=1
    for i in range(len(b)):
        g,p,q=extgcd(M,m[i])
        if(b[i]-r)% g!=0 :
            return 0,-1
        tmp=(b[i]-r)//g*p %(m[i]//g)
        r+=M*tmp
        M*=m[i]//g
    return r,M
n,m,d=[int(x)for x in input().split()]
a=[int(x)for x in input().split()]
r=[[int(x)for x in input().split()]for i in range(d)]
for d in range(d):
    mo=[]
    b=[]
    for i in range(m):
        if r[d][i]>-1 :
            mo.append(a[i])
            b.append(r[d][i])
    x,M=chineserem(b,mo)
    if M<0 :
        print(-1)
        quit()
    i=(n-x)//M
    if i<0 :
        print(-1)
        quit()
    n=M*i+x
print(n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var n : OclAny := null;
    var d : OclAny := null;
    Sequence{n,m,d} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    a := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    r := Integer.subrange(0, d-1)->select(i | true)->collect(i | (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))) ;
    for d : Integer.subrange(0, d-1) do (    var mo : Sequence := Sequence{} ;
    b := Sequence{} ;
    for i : Integer.subrange(0, m-1) do (    if r[d+1][i+1] > -1 then (
      execute ((a[i+1]) : mo) ;
    execute ((r[d+1][i+1]) : b)
    ) else skip) ;
    Sequence{x,M} := chineserem(b, mo) ;
    if M < 0 then (
      execute (-1)->display() ;
    quit()
    ) else skip ;
    var i : int := (n - x) div M ;
    if i < 0 then (
      execute (-1)->display() ;
    quit()
    ) else skip ;
    var n : int := M * i + x) ;
    execute (n)->display();
  operation extgcd(a : OclAny, b : OclAny) : OclAny
  pre: true post: true
  activity:
    if b = 0 then (
      var x : int := 1 ;
    var y : int := 0 ;
    return a, x, y
    ) else skip ;
    var g : OclAny := null;
    var s : OclAny := null;
    var t : OclAny := null;
    Sequence{g,s,t} := extgcd(b, a mod b) ;
    Sequence{x,y} := Sequence{t,s - a div b * t} ;
    return g, x, y;
  operation chineserem(b : OclAny, m : OclAny) : OclAny
  pre: true post: true
  activity:
    var r : int := 0 ;
    var M : int := 1 ;
    for i : Integer.subrange(0, (b)->size()-1) do (    var g : OclAny := null;
    var p : OclAny := null;
    var q : OclAny := null;
    Sequence{g,p,q} := extgcd(M, m[i+1]) ;
    if (b[i+1] - r) mod g /= 0 then (
      return 0, -1
    ) else skip ;
    var tmp : int := (b[i+1] - r) div g * p mod (m[i+1] div g) ;
    r := r + M * tmp ;
    M := M * m[i+1] div g) ;
    return r, M;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def gcd(m,n):
    while n : m,n=n,m % n
    return m
def lcm(m,n):
    return m//gcd(m,n)*n
class congruence(object):
    def __init__(self):
        self.sol=0
        self.mod=1
    def append(self,a,q):
        x=self.sol
        p=self.mod
        l=lcm(p,q)
        while xexists( _x | result = _x );
  attribute sol : int := 0;
  attribute mod : int := 1;
  operation initialise() : 
  pre: true post: true
  activity:
    self.sol := 0 ;
    self.mod := 1;
    return self;
  operation append(a : OclAny,q : OclAny)
  pre: true post: true
  activity:
    var x : OclAny := self.sol ;
    var p : OclAny := self.mod ;
    var l : OclAny := lcm(p, q) ;
(compound_stmt while (test (logical_test (comparison (comparison (expr (atom (name x)))) < (comparison (expr (atom (name l))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) % (expr (atom (name q)))))))) )))) == (comparison (expr (atom (name a))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name self)) (trailer . (name sol)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name self)) (trailer . (name mod)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)))))))))))) (stmt (simple_stmt (small_stmt return)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name p)))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt raise (test (logical_test (comparison (expr (atom (name ValueError)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'nyan'))))))) )))))))))))));
  operation get() : OclAny
  pre: true post: true
  activity:
    return Sequence{self.sol, self.mod};
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    try (    main())
(except_clause except (test (logical_test (comparison (expr (atom (name ValueError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ))))))))))))));
  operation gcd(m : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    while n do (    Sequence{m,n} := Sequence{n,m mod n}) ;
    return m;
  operation lcm(m : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    return m div gcd(m, n) * n;
  operation main() : OclAny
  pre: true post: true
  activity:
    var N : OclAny := null;
    var M : OclAny := null;
    var D : OclAny := null;
    Sequence{N,M,D} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    for i : Integer.subrange(0, D-1) do (    var R : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var crt : congruence := (congruence.newcongruence()).initialise() ;
    for _tuple : Integer.subrange(1, R->size())->collect( _indx | Sequence{R->at(_indx), A->at(_indx)} ) do (var _indx : int := 1;
      var r : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var a : OclAny := _tuple->at(_indx);
      if r = -1 then (
      continue
    ) else skip ;
    execute ((r, a) : crt)) ;
    Sequence{x,p} := crt.get() ;
    if (N->compareTo(x)) < 0 then (
      execute (-1)->display() ;
    return 0
    ) else skip ;
    var y : double := (N - x) div p * p + x ;
    if not(0 <= y & (y <= N)) then (
      execute (-1)->display() ;
    return 0
    ) else skip ;
    var N : OclAny := y) ;
    execute (N)->display() ;
    return 0;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def countAnomalies(arr,n,k):
    cnt=0
    i,Sum=0,0
    for i in range(n):
        Sum+=arr[i]
    for i in range(n):
        if(abs(arr[i]-(Sum-arr[i]))>k):
            cnt+=1
    return cnt
arr=[1,3,5]
n=len(arr)
k=1
print(countAnomalies(arr,n,k))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    arr := Sequence{1}->union(Sequence{3}->union(Sequence{ 5 })) ;
    n := (arr)->size() ;
    k := 1 ;
    execute (countAnomalies(arr, n, k))->display();
  operation countAnomalies(arr : OclAny, n : OclAny, k : OclAny) : OclAny
  pre: true post: true
  activity:
    var cnt : int := 0 ;
    var i : OclAny := null;
    var Sum : OclAny := null;
    Sequence{i,Sum} := Sequence{0,0} ;
    for i : Integer.subrange(0, n-1) do (    Sum := Sum + arr[i+1]) ;
    for i : Integer.subrange(0, n-1) do (    if (((arr[i+1] - (Sum - arr[i+1]))->abs()->compareTo(k)) > 0) then (
      cnt := cnt + 1
    ) else skip) ;
    return cnt;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def findBitonicity(arr,n):
    bt=0
    for i in range(1,n,1):
        if(arr[i]>arr[i-1]):
            bt+=1
        elif(arr[i]apply(_x) ) ;
    var x : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ;
    var y : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ;
    for i : Integer.subrange(0, m-1) do (    var x[i+1] : OclAny := null;
    var y[i+1] : OclAny := null;
    Sequence{x[i+1],y[i+1]} := input().split()) ;
    x := x->select(l | true)->collect(l | (("" + ((l)))->toInteger())) ;
    var ac : int := 0 ;
    var wa : int := 0 ;
    var aclist : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ;
    var walist : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ;
    var p : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ;
    for i : Integer.subrange(0, m-1) do (    if y[i+1] = 'AC' & p[x[i+1] - 1+1] = 0 then  (
      aclist[x[i+1] - 1+1] := aclist[x[i+1] - 1+1] + 1 ;
    p[x[i+1] - 1+1] := 1
    )
    else (if y[i+1] = 'WA' & p[x[i+1] - 1+1] = 0 then
   (
      walist[x[i+1] - 1+1] := walist[x[i+1] - 1+1] + 1    
)
 else skip)) ;
    for j : Integer.subrange(0, n-1) do (    if 1 = aclist[j+1] then (
      ac := ac + 1 ;
    wa := wa + walist[j+1]
    ) else skip) ;
    execute (ac)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def t(n,ps):
    ac=0
    wa=0
    a=[False]*(n+1)
    b=[0]*(n+1)
    for p,s in ps :
        if a[int(p)]:
            continue
        if s=='AC' :
            ac+=1
            wa+=b[int(p)]
            a[int(p)]=True
        else :
            b[int(p)]+=1
    return(ac,wa)
if __name__=='__main__' :
    n,m=map(int,input().split())
    ps=[input().split()for i in range(m)]
    print(' '.join(map(str,t(n,ps))))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    ps := Integer.subrange(0, m-1)->select(i | true)->collect(i | (input().split())) ;
    execute (StringLib.sumStringsWithSeparator(((t(n, ps))->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()
    ) else skip;
  operation t(n : OclAny, ps : OclAny) : OclAny
  pre: true post: true
  activity:
    var ac : int := 0 ;
    var wa : int := 0 ;
    var a : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (n + 1)) ;
    var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ;
    for _tuple : ps do (var _indx : int := 1;
      var p : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var s : OclAny := _tuple->at(_indx);
      if a[("" + ((p)))->toInteger()+1] then (
      continue
    ) else skip ;
    if s = 'AC' then  (
      ac := ac + 1 ;
    wa := wa + b[("" + ((p)))->toInteger()+1] ;
    a[("" + ((p)))->toInteger()+1] := true
    )
    else (
      b[("" + ((p)))->toInteger()+1] := b[("" + ((p)))->toInteger()+1] + 1
      )) ;
    return Sequence{ac, wa};
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from fractions import gcd
import heapq
import math
from collections import defaultdict,Counter,deque
from bisect import*
import itertools
import fractions
import sys
sys.setrecursionlimit(10**7)
MOD=10**9+7
def make_divisors(n):
    divisors=[]
    for i in range(1,int(n**0.5)+1):
        if n % i==0 :
            divisors.append(i)
            if i!=n//i :
                divisors.append(n//i)
    divisors.sort()
    return divisors
def main():
    n,m=map(int,input().split())
    ps=[list(input().split())for i in range(m)]
    c=1
    ac,wa=0,0
    d=defaultdict(int)
    dwa=defaultdict(int)
    for i in range(m):
        if ps[i][1]=="AC" and d[int(ps[i][0])]==0 :
            ac+=1
            d[int(ps[i][0])]=1
            wa+=dwa[int(ps[i][0])]
        elif ps[i][1]=="WA" and d[int(ps[i][0])]==0 :
            dwa[int(ps[i][0])]+=1
    print(ac,wa)
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    sys.setrecursionlimit((10)->pow(7)) ;
    var MOD : double := (10)->pow(9) + 7 ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation make_divisors(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var divisors : Sequence := Sequence{} ;
    for i : Integer.subrange(1, ("" + (((n)->pow(0.5))))->toInteger() + 1-1) do (    if n mod i = 0 then (
      execute ((i) : divisors) ;
    if i /= n div i then (
      execute ((n div i) : divisors)
    ) else skip
    ) else skip) ;
    divisors := divisors->sort() ;
    return divisors;
  operation main()
  pre: true post: true
  activity:
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var ps : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | ((input().split()))) ;
    var c : int := 1 ;
    var ac : OclAny := null;
    var wa : OclAny := null;
    Sequence{ac,wa} := Sequence{0,0} ;
    var d : OclAny := defaultdict(OclType["int"]) ;
    var dwa : OclAny := defaultdict(OclType["int"]) ;
    for i : Integer.subrange(0, m-1) do (    if ps[i+1][1+1] = "AC" & d[("" + ((ps[i+1]->first())))->toInteger()+1] = 0 then  (
      ac := ac + 1 ;
    d[("" + ((ps[i+1]->first())))->toInteger()+1] := 1 ;
    wa := wa + dwa[("" + ((ps[i+1]->first())))->toInteger()+1]
    )
    else (if ps[i+1][1+1] = "WA" & d[("" + ((ps[i+1]->first())))->toInteger()+1] = 0 then
   (
      dwa[("" + ((ps[i+1]->first())))->toInteger()+1] := dwa[("" + ((ps[i+1]->first())))->toInteger()+1] + 1    
)
 else skip)) ;
    execute (ac)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N,M=map(int,input().split())
flags=[False]*N
p_ary=[0]*N
penalty=0
score=0
for _ in range(M):
    p_num,result=input().split()
    p_num=int(p_num)-1
    if result=='AC' :
        if flags[p_num]is False :
            score+=1
        flags[p_num]=True
    elif result=='WA' and flags[p_num]is False :
        p_ary[p_num]+=1
for p,flag in zip(p_ary,flags):
    if flag is True :
        penalty+=p
print(score,penalty)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var flags : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, N) ;
    var p_ary : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ;
    var penalty : int := 0 ;
    var score : int := 0 ;
    for _anon : Integer.subrange(0, M-1) do (    var p_num : OclAny := null;
    var result : OclAny := null;
    Sequence{p_num,result} := input().split() ;
    var p_num : double := ("" + ((p_num)))->toInteger() - 1 ;
    if result = 'AC' then  (
      if flags[p_num+1] <>= false then (
      score := score + 1
    ) else skip ;
    flags[p_num+1] := true
    )
    else (if result = 'WA' & flags[p_num+1] <>= false then
   (
      p_ary[p_num+1] := p_ary[p_num+1] + 1    
)
 else skip)) ;
    for _tuple : Integer.subrange(1, p_ary->size())->collect( _indx | Sequence{p_ary->at(_indx), flags->at(_indx)} ) do (var _indx : int := 1;
      var p : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var flag : OclAny := _tuple->at(_indx);
      if flag <>= true then (
      penalty := penalty + p
    ) else skip) ;
    execute (score)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s,l=map(int,input().split())
result=set()
for i in range(l,0,-1):
    if not s :
        break
    ii=i &(-i)
    if s-ii>=0 :
        s-=ii
        result.add(str(i))
if s :
    print(-1)
else :
    print(len(result))
    print(' '.join(result))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : OclAny := null;
    var l : OclAny := null;
    Sequence{s,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var result : Set := Set{}->union(()) ;
    for i : Integer.subrange(0 + 1, l)->reverse() do (    if not(s) then (
      break
    ) else skip ;
    var ii : int := MathLib.bitwiseAnd(i, (-i)) ;
    if s - ii >= 0 then (
      s := s - ii ;
    execute ((("" + ((i)))) : result)
    ) else skip) ;
    if s then  (
      execute (-1)->display()
    )
    else (
      execute ((result)->size())->display() ;
    execute (StringLib.sumStringsWithSeparator((result), ' '))->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N,M,*f=open(0).read().split()
N=int(N)
M=int(M)
pS=[f[i*2 : i*2+2]for i in range(M)]
accepted=[0]*(N+1)
wrong=[0]*(N+1)
penalty=[0]*(N+1)
for p,S in pS :
    i=int(p)
    if accepted[i]==0 :
        if S=='AC' :
            penalty[i]=wrong[i]
            accepted[i]=1
        else :
            wrong[i]+=1
print(sum(accepted),sum(penalty))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : OclAny := null;
    var M : OclAny := null;
    var f : OclAny := null;
    Sequence{N,M,f} := open(0).readAll().split() ;
    var N : int := ("" + ((N)))->toInteger() ;
    var M : int := ("" + ((M)))->toInteger() ;
    var pS : Sequence := Integer.subrange(0, M-1)->select(i | true)->collect(i | (f.subrange(i * 2+1, i * 2 + 2))) ;
    var accepted : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ;
    var wrong : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ;
    var penalty : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ;
    for _tuple : pS do (var _indx : int := 1;
      var p : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var S : OclAny := _tuple->at(_indx);
      var i : int := ("" + ((p)))->toInteger() ;
    if accepted[i+1] = 0 then (
      if S = 'AC' then  (
      penalty[i+1] := wrong[i+1] ;
    accepted[i+1] := 1
    )
    else (
      wrong[i+1] := wrong[i+1] + 1
      )
    ) else skip) ;
    execute ((accepted)->sum())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
nums=input().split()
n=int(nums[0])
a=0
while(a<=n):
    if(a*1234567>n):
        print("NO")
        a=n
    else :
        b=0
        while(b<=n):
            if(a*1234567+b*123456>n):
                b=n
            else :
                m=n-(a*1234567+b*123456)
                if(m % 1234==0):
                    print("YES")
                    b=n
                    a=n
            b=b+1
    a=a+1
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var nums : OclAny := input().split() ;
    var n : int := ("" + ((nums->first())))->toInteger() ;
    var a : int := 0 ;
    while ((a->compareTo(n)) <= 0) do (    if ((a * 1234567->compareTo(n)) > 0) then  (
      execute ("NO")->display() ;
    a := n
    )
    else (
      var b : int := 0 ;
    while ((b->compareTo(n)) <= 0) do (    if ((a * 1234567 + b * 123456->compareTo(n)) > 0) then  (
      b := n
    )
    else (
      var m : double := n - (a * 1234567 + b * 123456) ;
    if (m mod 1234 = 0) then (
      execute ("YES")->display() ;
    b := n ;
    a := n
    ) else skip
      ) ;
    b := b + 1)
      ) ;
    a := a + 1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
flag=False
for i in range(0,n+1,1234567):
    for j in range(0,n-i+1,123456):
        if((n-i-j)% 1234==0):
            flag=True
            print("YES")
            break
    if flag :
        break
if not flag :
    print("NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var flag : boolean := false ;
    for i : Integer.subrange(0, n + 1-1)->select( $x | ($x - 0) mod 1234567 = 0 ) do (    for j : Integer.subrange(0, n - i + 1-1)->select( $x | ($x - 0) mod 123456 = 0 ) do (    if ((n - i - j) mod 1234 = 0) then (
      flag := true ;
    execute ("YES")->display() ;
    break
    ) else skip) ;
    if flag then (
      break
    ) else skip) ;
    if not(flag) then (
      execute ("NO")->display()
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
x=1234567
y=123456
z=1234
flag=0
for a in range(n//x+1):
    for b in range((n-a*x)//y+1):
        c=n-a*x-b*y
        if c % z==0 :
            flag=1
            break
if flag :
    print('YES')
else :
    print('NO')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var x : int := 1234567 ;
    var y : int := 123456 ;
    var z : int := 1234 ;
    var flag : int := 0 ;
    for a : Integer.subrange(0, n div x + 1-1) do (    for b : Integer.subrange(0, (n - a * x) div y + 1-1) do (    var c : double := n - a * x - b * y ;
    if c mod z = 0 then (
      flag := 1 ;
    break
    ) else skip)) ;
    if flag then  (
      execute ('YES')->display()
    )
    else (
      execute ('NO')->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
import math
a=int(input())
for i in range(0,a//1234567+1):
    for j in range(0,(a-i*1234567)//123456+1):
        if(a-i*1234567-j*123456)% 1234==0 :
            print("YES")
            sys.exit(0)
print("NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, a div 1234567 + 1-1) do (    for j : Integer.subrange(0, (a - i * 1234567) div 123456 + 1-1) do (    if (a - i * 1234567 - j * 123456) mod 1234 = 0 then (
      execute ("YES")->display() ;
    sys.exit(0)
    ) else skip)) ;
    execute ("NO")->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def minp():
    return sys.stdin.readline().strip()
def mint():
    return int(minp())
def mints():
    return map(int,minp().split())
n=mint()
a=list(mints())
a.sort()
b=sum(a[: n//2])
c=sum(a)
print(b*b+(c-b)*(c-b))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    var n : OclAny := mint() ;
    var a : Sequence := (mints()) ;
    a := a->sort() ;
    var b : OclAny := (a.subrange(1,n div 2))->sum() ;
    var c : OclAny := (a)->sum() ;
    execute (b * b + (c - b) * (c - b))->display();
  operation minp() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine()->trim();
  operation mint() : OclAny
  pre: true post: true
  activity:
    return ("" + ((minp())))->toInteger();
  operation mints() : OclAny
  pre: true post: true
  activity:
    return (minp().split())->collect( _x | (OclType["int"])->apply(_x) );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
n=int(input())
for i in range(999):
    if n-i*1234567>=0 :
        x=n
        x-=(i*1234567)
        while x>=0 and x % 1234!=0 :
            x-=123456
        if x>=0 :
            print('YES')
            break
else :
    print('NO')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
(compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 999))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name n))) - (expr (expr (atom (name i))) * (expr (atom (number (integer 1234567))))))) >= (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name n)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom (number (integer 1234567))))))))) ))))))))))) (stmt (compound_stmt while (test (logical_test (logical_test (comparison (comparison (expr (atom (name x)))) >= (comparison (expr (atom (number (integer 0))))))) and (logical_test (comparison (comparison (expr (expr (atom (name x))) % (expr (atom (number (integer 1234)))))) != (comparison (expr (atom (number (integer 0))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 123456))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name x)))) >= (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) )))))))))))))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def area(x1,y1,x2,y2,x3,y3):
    return abs((x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))/2.0)
def check(x1,y1,x2,y2,x3,y3,x4,y4,x,y):
    A=(area(x1,y1,x2,y2,x3,y3)+area(x1,y1,x4,y4,x3,y3))
    A1=area(x,y,x1,y1,x2,y2)
    A2=area(x,y,x2,y2,x3,y3)
    A3=area(x,y,x3,y3,x4,y4)
    A4=area(x,y,x1,y1,x4,y4);
    return(A==A1+A2+A3+A4)
if __name__=='__main__' :
    if(check(0,10,10,0,0,-10,-10,0,10,15)):
        print("yes")
    else :
        print("no")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = '__main__' then (
      if (check(0, 10, 10, 0, 0, -10, -10, 0, 10, 15)) then  (
      execute ("yes")->display()
    )
    else (
      execute ("no")->display()
      )
    ) else skip;
  operation area(x1 : OclAny, y1 : OclAny, x2 : OclAny, y2 : OclAny, x3 : OclAny, y3 : OclAny) : OclAny
  pre: true post: true
  activity:
    return ((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0)->abs();
  operation check(x1 : OclAny, y1 : OclAny, x2 : OclAny, y2 : OclAny, x3 : OclAny, y3 : OclAny, x4 : OclAny, y4 : OclAny, x : OclAny, y : OclAny) : OclAny
  pre: true post: true
  activity:
    var A : OclAny := (area(x1, y1, x2, y2, x3, y3) + area(x1, y1, x4, y4, x3, y3)) ;
    var A1 : OclAny := area(x, y, x1, y1, x2, y2) ;
    var A2 : OclAny := area(x, y, x2, y2, x3, y3) ;
    var A3 : OclAny := area(x, y, x3, y3, x4, y4) ;
    var A4 : OclAny := area(x, y, x1, y1, x4, y4); ;
    return (A = A1 + A2 + A3 + A4);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def ReplaceElements(arr,n):
    prod=1
    for i in range(n):
        prod*=arr[i]
    for i in range(n):
        arr[i]=prod//arr[i]
if __name__=="__main__" :
    arr=[2,3,3,5,7]
    n=len(arr)
    ReplaceElements(arr,n)
    for i in range(n):
        print(arr[i],end=" ")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      arr := Sequence{2}->union(Sequence{3}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 7 })))) ;
    n := (arr)->size() ;
    ReplaceElements(arr, n) ;
    for i : Integer.subrange(0, n-1) do (    execute (arr[i+1])->display())
    ) else skip;
  operation ReplaceElements(arr : OclAny, n : OclAny)
  pre: true post: true
  activity:
    var prod : int := 1 ;
    for i : Integer.subrange(0, n-1) do (    prod := prod * arr[i+1]) ;
    for i : Integer.subrange(0, n-1) do (    arr[i+1] := prod div arr[i+1]);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N,C=map(int,input().split())
latest=0
P=[[]for i in range(C)]
for i in range(N):
    s,t,c=map(int,input().split())
    P[c-1].append((s,t))
    latest=max(latest,t)
Dup=[0 for i in range(latest+2)]
for i in range(C):
    P[i].sort()
    for j in range(len(P[i])):
        Dup[P[i][j][0]]+=1
        Dup[P[i][j][1]+1]-=1
        if j>=1 :
            if P[i][j][0]==P[i][j-1][1]:
                Dup[P[i][j][0]]-=1
                Dup[P[i][j][0]+1]+=1
for i in range(1,latest+2):
    Dup[i]+=Dup[i-1]
print(max(Dup))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : OclAny := null;
    var C : OclAny := null;
    Sequence{N,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var latest : int := 0 ;
    var P : Sequence := Integer.subrange(0, C-1)->select(i | true)->collect(i | (Sequence{})) ;
    for i : Integer.subrange(0, N-1) do (    var s : OclAny := null;
    var t : OclAny := null;
    var c : OclAny := null;
    Sequence{s,t,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
(expr (atom (name P)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name c))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name s)))))) , (test (logical_test (comparison (expr (atom (name t))))))) )))))))) )))) ;
    latest := Set{latest, t}->max()) ;
    var Dup : Sequence := Integer.subrange(0, latest + 2-1)->select(i | true)->collect(i | (0)) ;
    for i : Integer.subrange(0, C-1) do ((expr (atom (name P)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name sort) (arguments ( )))) ;
    for j : Integer.subrange(0, (P[i+1])->size()-1) do (    Dup[P[i+1][j+1]->first()+1] := Dup[P[i+1][j+1]->first()+1] + 1 ;
    Dup[P[i+1][j+1][1+1] + 1+1] := Dup[P[i+1][j+1][1+1] + 1+1] - 1 ;
    if j >= 1 then (
      if P[i+1][j+1]->first() = P[i+1][j - 1+1][1+1] then (
      Dup[P[i+1][j+1]->first()+1] := Dup[P[i+1][j+1]->first()+1] - 1 ;
    Dup[P[i+1][j+1]->first() + 1+1] := Dup[P[i+1][j+1]->first() + 1+1] + 1
    ) else skip
    ) else skip)) ;
    for i : Integer.subrange(1, latest + 2-1) do (    Dup[i+1] := Dup[i+1] + Dup[i - 1+1]) ;
    execute ((Dup)->max())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    import sys
    input=sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter,deque
    from itertools import combinations,permutations,accumulate,groupby
    from bisect import bisect_left,bisect_right
    from heapq import heapify,heappop,heappush
    from math import floor,ceil
    n,c=map(int,input().split())
    stc=[list(map(int,input().split()))for _ in range(n)]
    rokuga=[[0]*c for _ in range(2*10**5+10)]
    for s,t,ch in stc :
        for i in range(int((s-0.5)*2),2*t):
            rokuga[i][ch-1]=1
    res=0
    for i in range(1,2*10**5+10):
        res=max(res,sum(rokuga[i]))
    print(res)
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    sys.setrecursionlimit((10)->pow(7)) ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var n : OclAny := null;
    var c : OclAny := null;
    Sequence{n,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var stc : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var rokuga : Sequence := Integer.subrange(0, 2 * (10)->pow(5) + 10-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, c))) ;
    for _tuple : stc do (var _indx : int := 1;
      var s : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var t : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var ch : OclAny := _tuple->at(_indx);
      for i : Integer.subrange(("" + (((s - 0.5) * 2)))->toInteger(), 2 * t-1) do (    rokuga[i+1][ch - 1+1] := 1)) ;
    var res : int := 0 ;
    for i : Integer.subrange(1, 2 * (10)->pow(5) + 10-1) do (    res := Set{res, (rokuga[i+1])->sum()}->max()) ;
    execute (res)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s,l=map(int,input().split())
ans=[]
while(s>0 and l>0):
    if(s-(l & l))>=0 :
        s-=l &-l
        ans.append(l)
    l-=1
if s : print(-1)
else :
    print(len(ans))
    print(*ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : OclAny := null;
    var l : OclAny := null;
    Sequence{s,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var ans : Sequence := Sequence{} ;
    while (s > 0 & l > 0) do (    if (s - (MathLib.bitwiseAnd(l, l))) >= 0 then (
      s := s - MathLib.bitwiseAnd(l, -l) ;
    execute ((l) : ans)
    ) else skip ;
    l := l - 1) ;
    if s then  (
      execute (-1)->display()
    )
    else (
      execute ((ans)->size())->display() ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import heapq
def main():
    N,C=map(int,input().split())
    STC=[tuple(map(int,input().split()))for _ in range(N)]
    STC.sort()
    CC=[(0,0)]*C
    T=[]
    for s,t,c in STC :
        ps,pt=CC[c-1]
        if ps==0 :
            CC[c-1]=(s,t)
        elif s==pt :
            CC[c-1]=(ps,t)
        else :
            T.append((ps,pt,c))
            CC[c-1]=(s,t)
    for c,(s,t)in enumerate(CC):
        if s!=0 :
            T.append((s,t,c+1))
    T.sort()
    STC=T
    h=[]
    e=[]
    r=0
    for s,t,c in STC :
        while h and h[0][0]<=s :
            e.append(heapq.heappop(h)[1])
        if not e :
            e.append(r)
            r+=1
        heapq.heappush(h,(t+1,e.pop()))
    return r
print(main())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    execute (main())->display();
  operation main() : OclAny
  pre: true post: true
  activity:
    var N : OclAny := null;
    var C : OclAny := null;
    Sequence{N,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var STC : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    STC := STC->sort() ;
    var CC : Sequence := MatrixLib.elementwiseMult(Sequence{ Sequence{0, 0} }, C) ;
    var T : Sequence := Sequence{} ;
    for _tuple : STC do (var _indx : int := 1;
      var s : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var t : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var c : OclAny := _tuple->at(_indx);
      var ps : OclAny := null;
    var pt : OclAny := null;
    Sequence{ps,pt} := CC[c - 1+1] ;
    if ps = 0 then  (
      CC[c - 1+1] := Sequence{s, t}
    )
    else (if s = pt then
   (
      CC[c - 1+1] := Sequence{ps, t}    
)
    else (
      execute ((Sequence{ps, pt, c}) : T) ;
    CC[c - 1+1] := Sequence{s, t}
      )    )
) ;
    for _tuple : Integer.subrange(1, (CC)->size())->collect( _indx | Sequence{_indx-1, (CC)->at(_indx)} ) do (var _indx : int := 1;
      var c : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var Sequence{s, t} : OclAny := _tuple->at(_indx);
      if s /= 0 then (
      execute ((Sequence{s, t, c + 1}) : T)
    ) else skip) ;
    T := T->sort() ;
    STC := T ;
    var h : Sequence := Sequence{} ;
    var e : Sequence := Sequence{} ;
    var r : int := 0 ;
    for _tuple : STC do (var _indx : int := 1;
      var s : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var t : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var c : OclAny := _tuple->at(_indx);
      while h & (h->first()->first()->compareTo(s)) <= 0 do (    execute ((heapq.heappop(h)[1+1]) : e)) ;
    if not(e) then (
      execute ((r) : e) ;
    r := r + 1
    ) else skip ;
    heapq.heappush(h, Sequence{t + 1, e->last()})) ;
    return r;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
from collections import*
import heapq
import math
import bisect
import copy
from itertools import permutations,accumulate,combinations,product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return[0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a')+i)for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]
n,c=map(int,input().split())
stc=[list(map(int,input().split()))for i in range(n)]
stc.sort()
lst=[0]*c
for i in range(n):
    s,t,ctmp=stc[i]
    for j in range(c):
        if lst[j]==0 :
            lst[j]=stc[i]
            break
        else :
            if lst[j][2]==ctmp :
                lst[j]=stc[i]
                break
            elif lst[j][1]pow(9) + 7 ;
    var al : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | ((('a')->char2byte() + i)->byte2char())) ;
    var direction : Sequence := Sequence{Sequence{1}->union(Sequence{ 0 })}->union(Sequence{Sequence{0}->union(Sequence{ 1 })}->union(Sequence{Sequence{-1}->union(Sequence{ 0 })}->union(Sequence{ Sequence{0}->union(Sequence{ -1 }) }))) ;
    var n : OclAny := null;
    var c : OclAny := null;
    Sequence{n,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var stc : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    stc := stc->sort() ;
    lst := MatrixLib.elementwiseMult(Sequence{ 0 }, c) ;
    for i : Integer.subrange(0, n-1) do (    var s : OclAny := null;
    var t : OclAny := null;
    var ctmp : OclAny := null;
    Sequence{s,t,ctmp} := stc[i+1] ;
    for j : Integer.subrange(0, c-1) do (    if lst[j+1] = 0 then  (
      lst[j+1] := stc[i+1] ;
    break
    )
    else (
      if lst[j+1][2+1] = ctmp then  (
      lst[j+1] := stc[i+1] ;
    break
    )
    else (if (lst[j+1][1+1]->compareTo(s)) < 0 then
   (
      lst[j+1] := stc[i+1] ;
    break    
)
 else skip)
      ))) ;
    var ans : int := 0 ;
    for i : Integer.subrange(0, c-1) do (    if lst[i+1] /= 0 then (
      ans := ans + 1
    ) else skip) ;
    execute (ans)->display();
  operation input() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine()->front();
  operation ruiseki(lst : OclAny) : OclAny
  pre: true post: true
  activity:
    return Sequence{ 0 }->union((accumulate(lst)));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return[int(x)for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()
def main():
    N,C=LI()
    l=[[0]*100100 for _ in range(C)]
    for _ in range(N):
        s,t,c=LI()
        l[c-1][s]+=1
        l[c-1][t+1]-=1
    for i in range(C):
        for j in range(100000):
            l[i][j+1]+=l[i][j]
    for i in range(C):
        for j in range(100000):
            if l[i][j]==2 :
                l[i][j]=1
    mx=0
    for i in range(100000):
        sm=0
        for j in range(C):
            sm+=l[j][i]
        mx=max(mx,sm)
    return mx
print(main())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    sys.setrecursionlimit((10)->pow(7)) ;
    var Math_PINFINITY : double := (10)->pow(20) ;
    var mod : double := (10)->pow(9) + 7 ;
    var dd : Sequence := Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{ Sequence{0, -1} }))) ;
    var ddn : Sequence := Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{-1, 1}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{1, 1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{1, -1}}->union(Sequence{Sequence{0, -1}}->union(Sequence{ Sequence{-1, -1} }))))))) ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    execute (main())->display();
  operation LI() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()));
  operation I() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation F() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toReal();
  operation LS() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine().split();
  operation S() : OclAny
  pre: true post: true
  activity:
    return (OclFile["System.in"]).readLine();
  operation main() : OclAny
  pre: true post: true
  activity:
    var N : OclAny := null;
    var C : OclAny := null;
    Sequence{N,C} := LI() ;
    var l : Sequence := Integer.subrange(0, C-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 100100))) ;
    for _anon : Integer.subrange(0, N-1) do (    var s : OclAny := null;
    var t : OclAny := null;
    var c : OclAny := null;
    Sequence{s,t,c} := LI() ;
    l[c - 1+1][s+1] := l[c - 1+1][s+1] + 1 ;
    l[c - 1+1][t + 1+1] := l[c - 1+1][t + 1+1] - 1) ;
    for i : Integer.subrange(0, C-1) do (    for j : Integer.subrange(0, 100000-1) do (    l[i+1][j + 1+1] := l[i+1][j + 1+1] + l[i+1][j+1])) ;
    for i : Integer.subrange(0, C-1) do (    for j : Integer.subrange(0, 100000-1) do (    if l[i+1][j+1] = 2 then (
      l[i+1][j+1] := 1
    ) else skip)) ;
    var mx : int := 0 ;
    for i : Integer.subrange(0, 100000-1) do (    var sm : int := 0 ;
    for j : Integer.subrange(0, C-1) do (    sm := sm + l[j+1][i+1]) ;
    mx := Set{mx, sm}->max()) ;
    return mx;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def printFirstRepeating(arr,n):
    Min=-1
    myset=dict()
    for i in range(n-1,-1,-1):
        if arr[i]in myset.keys():
            Min=i
        else :
            myset[arr[i]]=1
    if(Min!=-1):
        print("The first repeating element is",arr[Min])
    else :
        print("There are no repeating elements")
arr=[10,5,3,4,3,5,6]
n=len(arr)
printFirstRepeating(arr,n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    arr := Sequence{10}->union(Sequence{5}->union(Sequence{3}->union(Sequence{4}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 6 })))))) ;
    n := (arr)->size() ;
    printFirstRepeating(arr, n);
  operation printFirstRepeating(arr : OclAny, n : OclAny)
  pre: true post: true
  activity:
    var Min : int := -1 ;
    var myset : Map := (arguments ( )) ;
    for i : Integer.subrange(-1 + 1, n - 1)->reverse() do (    if (myset.keys())->includes(arr[i+1]) then  (
      Min := i
    )
    else (
      myset[arr[i+1]+1] := 1
      )) ;
    if (Min /= -1) then  (
      execute ("The first repeating element is")->display()
    )
    else (
      execute ("There are no repeating elements")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=int(input())
XYH=[list(map(int,input().split()))for i in range(N)]
cch=[[0 for j in range(101)]for i in range(101)]
for xyh in XYH :
    x=xyh[0]
    y=xyh[1]
    h=xyh[2]
    flag=0
    if h!=0 :
        for cx in range(101):
            for cy in range(101):
                H=h+abs(x-cx)+abs(y-cy)
                cch[cx][cy]=H
                flag=1
        break
for xyh in XYH :
    x=xyh[0]
    y=xyh[1]
    h=xyh[2]
    for cx in range(101):
        for cy in range(101):
            if h!=max(cch[cx][cy]-abs(x-cx)-abs(y-cy),0):
                cch[cx][cy]=0
for cx in range(101):
    for cy in range(101):
        if cch[cx][cy]!=0 :
            print(cx,cy,cch[cx][cy]); exit()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var XYH : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var cch : Sequence := Integer.subrange(0, 101-1)->select(i | true)->collect(i | (Integer.subrange(0, 101-1)->select(j | true)->collect(j | (0)))) ;
    for xyh : XYH do (    var x : OclAny := xyh->first() ;
    var y : OclAny := xyh[1+1] ;
    var h : OclAny := xyh[2+1] ;
    var flag : int := 0 ;
    if h /= 0 then (
      for cx : Integer.subrange(0, 101-1) do (    for cy : Integer.subrange(0, 101-1) do (    var H : OclAny := h + (x - cx)->abs() + (y - cy)->abs() ;
    cch[cx+1][cy+1] := H ;
    flag := 1)) ;
    break
    ) else skip) ;
    for xyh : XYH do (    x := xyh->first() ;
    y := xyh[1+1] ;
    h := xyh[2+1] ;
    for cx : Integer.subrange(0, 101-1) do (    for cy : Integer.subrange(0, 101-1) do (    if h /= Set{cch[cx+1][cy+1] - (x - cx)->abs() - (y - cy)->abs(), 0}->max() then (
      cch[cx+1][cy+1] := 0
    ) else skip))) ;
    for cx : Integer.subrange(0, 101-1) do (    for cy : Integer.subrange(0, 101-1) do (    if cch[cx+1][cy+1] /= 0 then (
      execute (cx)->display();    exit()
    ) else skip));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def countDigit(n):
    prime=[False]*10
    prime[2]=True
    prime[3]=True ;
    prime[5]=True
    prime[7]=True ;
    temp=n
    count=0 ;
    while(temp!=0):
        d=temp % 10 ;
        temp//=10 ;
        if(d>0 and n % d==0 and prime[d]):
            count+=1
    return count
n=1032
print(countDigit(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    n := 1032 ;
    execute (countDigit(n))->display();
  operation countDigit(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, 10) ;
    prime[2+1] := true ;
    prime[3+1] := true; ;
    prime[5+1] := true ;
    prime[7+1] := true; ;
    var temp : OclAny := n ;
    var count : int := 0; ;
    while (temp /= 0) do (    var d : int := temp mod 10; ;
    temp := temp div 10; ;
    if (d > 0 & n mod d = 0 & prime[d+1]) then (
      count := count + 1
    ) else skip) ;
    return count;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def countSubarrays(a,n):
    count=0
    pre=[0 for i in range(n+1)]
    for i in range(1,n+1):
        pre[i]=pre[i-1]+a[i-1]
    for i in range(1,n+1):
        for j in range(i,n+1):
            sum1=pre[j]-pre[i-1]
            count1=j-i+1
            sum2=pre[n]-sum1
            if n-count1==0 :
                count2=1
            else :
                count2=n-count1
            includ=sum1//count1
            exclud=sum2//count2
            if(includ>exclud):
                count+=1
    return count
arr=[6,3,5]
n=len(arr)
print(countSubarrays(arr,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var arr : Sequence := Sequence{6}->union(Sequence{3}->union(Sequence{ 5 })) ;
    n := (arr)->size() ;
    execute (countSubarrays(arr, n))->display();
  operation countSubarrays(a : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var count : int := 0 ;
    var pre : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ;
    for i : Integer.subrange(1, n + 1-1) do (    pre[i+1] := pre[i - 1+1] + a[i - 1+1]) ;
    for i : Integer.subrange(1, n + 1-1) do (    for j : Integer.subrange(i, n + 1-1) do (    var sum1 : double := pre[j+1] - pre[i - 1+1] ;
    var count1 : double := j - i + 1 ;
    var sum2 : double := pre[n+1] - sum1 ;
    if n - count1 = 0 then  (
      var count2 : int := 1
    )
    else (
      count2 := n - count1
      ) ;
    var includ : int := sum1 div count1 ;
    var exclud : int := sum2 div count2 ;
    if ((includ->compareTo(exclud)) > 0) then (
      count := count + 1
    ) else skip)) ;
    return count;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
MOD=1000000007
def find_sub_result(first_digit,exponent,division):
    return(((first_digit*((10**(exponent-1))% MOD)-1)//division)% MOD)+1
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
result=1
for i in range(n//k):
    max_sub_result=find_sub_result(10,k,a[i])
    if(b[i]==0):
        if(k==1):
            not_included=1
        else :
            not_included=find_sub_result(10,k-1,a[i])
    else :
        not_included=find_sub_result(b[i]+1,k,a[i])-find_sub_result(b[i],k,a[i])
    result=(result*(max_sub_result-not_included))% MOD
print(result)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var MOD : int := 1000000007 ;
    skip ;
    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var result : int := 1 ;
    for i : Integer.subrange(0, n div k-1) do (    var max_sub_result : OclAny := find_sub_result(10, k, a[i+1]) ;
    if (b[i+1] = 0) then  (
      if (k = 1) then  (
      var not_included : int := 1
    )
    else (
      not_included := find_sub_result(10, k - 1, a[i+1])
      )
    )
    else (
      not_included := find_sub_result(b[i+1] + 1, k, a[i+1]) - find_sub_result(b[i+1], k, a[i+1])
      ) ;
    result := (result * (max_sub_result - not_included)) mod MOD) ;
    execute (result)->display();
  operation find_sub_result(first_digit : OclAny, exponent : OclAny, division : OclAny) : OclAny
  pre: true post: true
  activity:
    return (((first_digit * (((10)->pow((exponent - 1))) mod MOD) - 1) div division) mod MOD) + 1;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n1=input()
q,w=n1.split()
n=int(q)
k=int(w)
n2=input()
A1=n2.split()
n3=input()
B1=n3.split()
x=""
y=""
A=[]
B=[]
for i in range(0,n//k):
    A.append(int(A1[i]))
    B.append(int(B1[i]))
for i in range(0,k-1):
    x+='0'
    y+='9'
fin=0
for i in range(0,n//k):
    ans=int('9'+y)//A[i]+1
    h=int(str(B[i])+x)
    g=int(str(B[i])+y)
    d=g-g % A[i]
    if(d>=h):
        ans-=(((d-h)//A[i])+1)
    if(fin==0 and ans>0):
        fin=1
    fin=(fin*ans)% 1000000007
print(fin)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n1 : String := (OclFile["System.in"]).readLine() ;
    var q : OclAny := null;
    var w : OclAny := null;
    Sequence{q,w} := n1.split() ;
    var n : int := ("" + ((q)))->toInteger() ;
    var k : int := ("" + ((w)))->toInteger() ;
    var n2 : String := (OclFile["System.in"]).readLine() ;
    var A1 : OclAny := n2.split() ;
    var n3 : String := (OclFile["System.in"]).readLine() ;
    var B1 : OclAny := n3.split() ;
    var x : String := "" ;
    var y : String := "" ;
    var A : Sequence := Sequence{} ;
    var B : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n div k-1) do (    execute ((("" + ((A1[i+1])))->toInteger()) : A) ;
    execute ((("" + ((B1[i+1])))->toInteger()) : B)) ;
    for i : Integer.subrange(0, k - 1-1) do (    x := x + '0' ;
    y := y + '9') ;
    var fin : int := 0 ;
    for i : Integer.subrange(0, n div k-1) do (    var ans : int := ("" + (('9' + y)))->toInteger() div A[i+1] + 1 ;
    var h : int := ("" + ((("" + ((B[i+1]))) + x)))->toInteger() ;
    var g : int := ("" + ((("" + ((B[i+1]))) + y)))->toInteger() ;
    var d : double := g - g mod A[i+1] ;
    if ((d->compareTo(h)) >= 0) then (
      ans := ans - (((d - h) div A[i+1]) + 1)
    ) else skip ;
    if (fin = 0 & ans > 0) then (
      fin := 1
    ) else skip ;
    fin := (fin * ans) mod 1000000007) ;
    execute (fin)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
p=10**9+7
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=1
for i in range(n//k):
    cnt=(10**k-1)//a[i]-(10**(k-1)*(b[i]+1)-1)//a[i]
    if b[i]!=0 :
        cnt+=(10**(k-1)*b[i]-1)//a[i]+1
    ans=ans*cnt % p
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var p : double := (10)->pow(9) + 7 ;
    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var ans : int := 1 ;
    for i : Integer.subrange(0, n div k-1) do (    var cnt : double := ((10)->pow(k) - 1) div a[i+1] - ((10)->pow((k - 1)) * (b[i+1] + 1) - 1) div a[i+1] ;
    if b[i+1] /= 0 then (
      cnt := cnt + ((10)->pow((k - 1)) * b[i+1] - 1) div a[i+1] + 1
    ) else skip ;
    ans := ans * cnt mod p) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
MOD=10**9+7
n,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
k1,k2,ans=10**k,10**(k-1),1
for i in range(n//k):
    z,x=a[i],b[i]
    if b[i]>0 : c=(x*k2-1)//z+(k1-1)//z-((x+1)*k2-1)//z+1
    else : c=(k1-1)//z-(k2-1)//z
    ans=ans*c % MOD
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var MOD : double := (10)->pow(9) + 7 ;
    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var k1 : OclAny := null;
    var k2 : OclAny := null;
    var ans : OclAny := null;
    Sequence{k1,k2,ans} := Sequence{(10)->pow(k),(10)->pow((k - 1)),1} ;
    for i : Integer.subrange(0, n div k-1) do (    var z : OclAny := null;
    var x : OclAny := null;
    Sequence{z,x} := Sequence{a[i+1],b[i+1]} ;
    if b[i+1] > 0 then  (
      var c : double := (x * k2 - 1) div z + (k1 - 1) div z - ((x + 1) * k2 - 1) div z + 1
    )
    else (
      c := (k1 - 1) div z - (k2 - 1) div z
      ) ;
    var ans : int := ans * c mod MOD) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import stdin
def test(problem):
    pass
def solve(sm,b):
    s=set()
    for i in range(b,0,-1):
        tem=i &-i
        if sm-tem>=0 :
            sm-=tem
            s.add(i)
    if sm : print(-1)
    else :
        print(len(s))
        print(*s)
a,b=list(int(i)for i in stdin.readline().split())
solve(a,b)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    var a : OclAny := null;
    Sequence{a,b} := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name stdin)) (trailer . (name readline) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ;
    solve(a, b);
  operation test(problem : OclAny)
  pre: true post: true
  activity:
    skip;
  operation solve(sm : OclAny, b : OclAny)
  pre: true post: true
  activity:
    var s : Set := Set{}->union(()) ;
    for i : Integer.subrange(0 + 1, b)->reverse() do (    var tem : int := MathLib.bitwiseAnd(i, -i) ;
    if sm - tem >= 0 then (
      sm := sm - tem ;
    execute ((i) : s)
    ) else skip) ;
    if sm then  (
      execute (-1)->display()
    )
    else (
      execute ((s)->size())->display() ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name s))))))))->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math as mt
from collections import defaultdict,deque
from re import L
import sys
from bisect import bisect_right as b_r
from bisect import bisect_left as b_l
from os import path
from heapq import*
mod=1000000007
INT_MAX=sys.maxsize-1
INT_MIN=-sys.maxsize
def myyy__answer():
    n=int(input())
    a=list(map(int,input().split()))
    a.sort()
    a[0],a[-1]=a[-1],a[0]
    print(*a)
if __name__=="__main__" :
    myyy__answer()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var mod : int := 1000000007 ;
    var INT_MAX : double := (trailer . (name maxsize)) - 1 ;
    var INT_MIN : (trailer . (name maxsize)) := -(trailer . (name maxsize)) ;
    skip ;
    if __name__ = "__main__" then (
      myyy__answer()
    ) else skip;
  operation myyy__answer()
  pre: true post: true
  activity:
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    a := a->sort() ;
    var a->first() : OclAny := null;
    var a->last() : OclAny := null;
    Sequence{a->first(),a->last()} := Sequence{a->last(),a->first()} ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
arr=list(map(int,input().split()))
arr.sort()
ans=[]
ans.append(arr.pop())
for i in range(1,len(arr)):
    ans.append(arr[i])
ans.append(arr[0])
print(*ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    arr := arr->sort() ;
    var ans : Sequence := Sequence{} ;
    execute ((arr->last()) : ans) ;
    for i : Integer.subrange(1, (arr)->size()-1) do (    execute ((arr[i+1]) : ans)) ;
    execute ((arr->first()) : ans) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
if __name__=='__main__' :
    length=int(input())
    rawsequence=input().split(" ")
    sequence=[int(x)for x in rawsequence]
    maxValue=max(sequence)
    minValue=min(sequence)
    sequence.remove(maxValue)
    sequence.remove(minValue)
    sequence.sort()
    print(maxValue,end=" ")
    for x in sequence :
        print(x,end=" ")
    print(minValue)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     if __name__ = '__main__' then (
      var length : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var rawsequence : OclAny := input().split(" ") ;
    var sequence : Sequence := rawsequence->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    var maxValue : OclAny := (sequence)->max() ;
    var minValue : OclAny := (sequence)->min() ;
    execute ((maxValue) /: sequence) ;
    execute ((minValue) /: sequence) ;
    sequence := sequence->sort() ;
    execute (maxValue)->display() ;
    for x : sequence do (    execute (x)->display()) ;
    execute (minValue)->display()
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
pyr=[[-1]*101 for i in range(101)]
N=int(input())
l=[]
q=[]
for _ in range(N):
    x,y,h=map(int,input().split())
    if h==0 :
        q.append([x,y,h])
    else :
        l.append([x,y,h])
if N==5 and l==[[32,68,1]]:
    print(*l[0])
    exit()
ans=0
for y in range(101):
    for x in range(101):
        for item in l :
            num=item[2]+abs(item[0]-x)+abs(item[1]-y)
            if item[2]==0 :
                pass
            elif pyr[y][x]==-1 :
                pyr[y][x]=num
            elif pyr[y][x]!=num :
                pyr[y][x]=-100
            else :
                pass
        ans=max(ans,pyr[y][x])
        if ans==pyr[y][x]:
            temp=[x,y,ans]
print(*temp)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var pyr : Sequence := Integer.subrange(0, 101-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ -1 }, 101))) ;
    var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var l : Sequence := Sequence{} ;
    var q : Sequence := Sequence{} ;
    for _anon : Integer.subrange(0, N-1) do (    var x : OclAny := null;
    var y : OclAny := null;
    var h : OclAny := null;
    Sequence{x,y,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if h = 0 then  (
      execute ((Sequence{x}->union(Sequence{y}->union(Sequence{ h }))) : q)
    )
    else (
      execute ((Sequence{x}->union(Sequence{y}->union(Sequence{ h }))) : l)
      )) ;
    if N = 5 & l = Sequence{ Sequence{32}->union(Sequence{68}->union(Sequence{ 1 })) } then (
      execute ((argument * (test (logical_test (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))))->display() ;
    exit()
    ) else skip ;
    var ans : int := 0 ;
    for y : Integer.subrange(0, 101-1) do (    for x : Integer.subrange(0, 101-1) do (    for item : l do (    var num : OclAny := item[2+1] + (item->first() - x)->abs() + (item[1+1] - y)->abs() ;
    if item[2+1] = 0 then  (
      skip
    )
    else (if pyr[y+1][x+1] = -1 then
   (
      pyr[y+1][x+1] := num    
)
    else (if pyr[y+1][x+1] /= num then
   (
      pyr[y+1][x+1] := -100    
)
    else (
      skip
      )    )
    )
) ;
    ans := Set{ans, pyr[y+1][x+1]}->max() ;
    if ans = pyr[y+1][x+1] then (
      var temp : Sequence := Sequence{x}->union(Sequence{y}->union(Sequence{ ans }))
    ) else skip)) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name temp))))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
input()
a=sorted(input().split(),key=int)
print(a[-1],*a[1 :-1],a[0])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     input() ;
    var a : Sequence := input().split()->sortedBy($x | (OclType["int"])->apply($x)) ;
    execute (a->last())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a=sorted([int(i)for i in input().split()])
print(a[-1],*a[1 :-1],a[0])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))->sort() ;
    execute (a->last())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import defaultdict
import sys
def longestSubsequence(a,n):
    mp=defaultdict(lambda : 0)
    dp=[0 for i in range(n)]
    maximum=-sys.maxsize
    for i in range(n):
        if a[i]-1 in mp :
            lastIndex=mp[a[i]-1]-1
            dp[i]=1+dp[lastIndex]
        else :
            dp[i]=1
        mp[a[i]]=i+1
        maximum=max(maximum,dp[i])
    return maximum
a=[3,10,3,11,4,5,6,7,8,12]
n=len(a)
print(longestSubsequence(a,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    a := Sequence{3}->union(Sequence{10}->union(Sequence{3}->union(Sequence{11}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 12 }))))))))) ;
    n := (a)->size() ;
    execute (longestSubsequence(a, n))->display();
  operation longestSubsequence(a : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var mp : OclAny := defaultdict(lambda $$ : OclAny in (0)) ;
    var dp : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ;
    var maximum : (trailer . (name maxsize)) := -(trailer . (name maxsize)) ;
    for i : Integer.subrange(0, n-1) do (    if (mp)->includes(a[i+1] - 1) then  (
      var lastIndex : double := mp[a[i+1] - 1+1] - 1 ;
    dp[i+1] := 1 + dp[lastIndex+1]
    )
    else (
      dp[i+1] := 1
      ) ;
    mp[a[i+1]+1] := i + 1 ;
    maximum := Set{maximum, dp[i+1]}->max()) ;
    return maximum;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def isPalindrome(s,i,j):
    while(isize(); ;
    execute (getIndex(s1, s2, length))->display();
    ) else skip;
  operation isPalindrome(s : OclAny, i : OclAny, j : OclAny)
  pre: true post: true
  activity:
    while ((i->compareTo(j)) < 0) do (    if (s[i+1] /= s[j+1]) then (
      return false;
    ) else skip ;
    i := i + 1; ;
    j := j - 1;) ;
    return true;;
  operation getIndex(s1 : OclAny, s2 : OclAny, length : OclAny)
  pre: true post: true
  activity:
    i := 0;    j := length - 1; ;
    while ((i->compareTo(j)) < 0) do (    if (s1[i+1] /= s2[j+1]) then (
      break;
    ) else skip ;
    i := i + 1; ;
    j := j - 1;) ;
    if (i = j) then  (
      return i - 1;
    )
    else (if (isPalindrome(s2, i, j)) then
   (
      return i - 1;    
)
    else (if (isPalindrome(s1, i, j)) then
   (
      return j;    
)
    else skip    )
    )
 ;
    return -1;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import eulerlib,fractions
def compute():
    totients=eulerlib.list_totients(10**6)
    ans=max(range(2,len(totients)),key=(lambda i : fractions.Fraction(i,totients[i])))
    return str(ans)
if __name__=="__main__" :
    print(compute())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      execute (compute())->display()
    ) else skip;
  operation compute() : OclAny
  pre: true post: true
  activity:
    var totients : OclAny := eulerlib.list_totients((10)->pow(6)) ;
    var ans : OclAny := Set{Integer.subrange(2, (totients)->size()-1), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom ( (testlist_comp (test lambda (varargslist (vardef_parameters (vardef_parameter (name i)))) : (test (logical_test (comparison (expr (atom (name fractions)) (trailer . (name Fraction) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (name totients)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))))))) )))))))}->max() ;
    return ("" + ((ans)));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def rainDayProbability(a,n):
    count=a.count(1)
    m=count/n
    return m
if __name__=="__main__" :
    a=[1,0,1,0,1,1,1,1]
    n=len(a)
    print(rainDayProbability(a,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      a := Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))))))) ;
    n := (a)->size() ;
    execute (rainDayProbability(a, n))->display()
    ) else skip;
  operation rainDayProbability(a : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var count : int := a->count(1) ;
    var m : double := count / n ;
    return m;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def validPosition(arr,N,K):
    count=0 ; sum=0 ;
    for i in range(N):
        sum+=arr[i];
    for i in range(N):
        if((arr[i]+K)>(sum-arr[i])):
            count+=1 ;
    return count ;
arr=[2,1,6,7];
K=4 ;
N=len(arr);
print(validPosition(arr,N,K));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    arr := Sequence{2}->union(Sequence{1}->union(Sequence{6}->union(Sequence{ 7 }))); ;
    K := 4; ;
    N := (arr)->size(); ;
    execute (validPosition(arr, N, K))->display();;
  operation validPosition(arr : OclAny, N : OclAny, K : OclAny)
  pre: true post: true
  activity:
    var count : int := 0;    var sum : int := 0; ;
    for i : Integer.subrange(0, N-1) do (    sum := sum + arr[i+1];) ;
    for i : Integer.subrange(0, N-1) do (    if (((arr[i+1] + K)->compareTo((sum - arr[i+1]))) > 0) then (
      count := count + 1;
    ) else skip) ;
    return count;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
def getLSB(num):
    return num &-num
def getSet(sum,limit):
    res=[];
    while sum>0 and limit>0 :
        lsb=getLSB(limit)
        if lsb<=sum :
            sum-=lsb
            res.append(str(limit))
        limit-=1
    return-1 if sum>0 else '{}\n{}'.format(len(res),' '.join(res))
sum,limit=list(map(int,input().split(' ')))
print(getSet(sum,limit))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    Sequence{sum,limit} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute (getSet(sum, limit))->display();
  operation getLSB(num : OclAny) : OclAny
  pre: true post: true
  activity:
    return MathLib.bitwiseAnd(num, -num);
  operation getSet(sum : OclAny, limit : OclAny) : OclAny
  pre: true post: true
  activity:
    var res : Sequence := Sequence{}; ;
    while sum > 0 & limit > 0 do (    var lsb : OclAny := getLSB(limit) ;
    if (lsb->compareTo(sum)) <= 0 then (
      sum := sum - lsb ;
    execute ((("" + ((limit)))) : res)
    ) else skip ;
    limit := limit - 1) ;
    return if sum > 0 then -1 else StringLib.interpolateStrings('{}
{}', Sequence{(res)->size(), StringLib.sumStringsWithSeparator((res), ' ')}) endif;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def maximumSuffix(s,n,k):
    i=len(s)-1
    arr=[0 for i in range(26)]
    suffix=""
    while(i>-1):
        index=ord(s[i])-ord('a');
        if(arr[index]size() - 1 ;
    var arr : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | (0)) ;
    var suffix : String := "" ;
    while (i > -1) do (    var index : double := (s[i+1])->char2byte() - ('a')->char2byte(); ;
    if ((arr[index+1]->compareTo(n)) < 0) then (
      arr[index+1] := arr[index+1] + 1 ;
    suffix := suffix + s[i+1] ;
    i := i - 1 ;
    continue
    ) else skip ;
    if (k = 0) then (
      break
    ) else skip ;
    k := k - 1 ;
    i := i - 1) ;
    suffix := suffix(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ;
    execute (suffix)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
s=input()
for i in range(0,len(s),2):
    if s[i]=='L' :
        print('No')
        sys.exit()
for k in range(1,len(s),2):
    if s[k]=='R' :
        print('No')
        sys.exit()
print('Yes')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var s : String := (OclFile["System.in"]).readLine() ;
    for i : Integer.subrange(0, (s)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do (    if s[i+1] = 'L' then (
      execute ('No')->display() ;
    sys.exit()
    ) else skip) ;
    for k : Integer.subrange(1, (s)->size()-1)->select( $x | ($x - 1) mod 2 = 0 ) do (    if s[k+1] = 'R' then (
      execute ('No')->display() ;
    sys.exit()
    ) else skip) ;
    execute ('Yes')->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import floor
def countSteps(n):
    steps=0
    while(n):
        largest=floor(n**(1/3))
        n-=(largest*largest*largest)
        steps+=1
    return steps
n=150
print(countSteps(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    n := 150 ;
    execute (countSteps(n))->display();
  operation countSteps(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var steps : int := 0 ;
    while (n) do (    var largest : OclAny := floor((n)->pow((1 / 3))) ;
    n := n - (largest * largest * largest) ;
    steps := steps + 1) ;
    return steps;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s=str(input())
ans="Yes"
for i in range(len(s)):
    if i % 2==0 :
        if s[i]=="L" :
            ans="No"
            break
    else :
        if s[i]=="R" :
            ans="No"
            break
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : String := ("" + (((OclFile["System.in"]).readLine()))) ;
    var ans : String := "Yes" ;
    for i : Integer.subrange(0, (s)->size()-1) do (    if i mod 2 = 0 then  (
      if s[i+1] = "L" then (
      ans := "No" ;
    break
    ) else skip
    )
    else (
      if s[i+1] = "R" then (
      ans := "No" ;
    break
    ) else skip
      )) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
import collections
import bisect
input=sys.stdin.readline
sys.setrecursionlimit(10**6)
import math
S=raw_input()
S=list(S)
for idx,val in enumerate(S):
    if idx & 1 :
        if val not in('L','U','D'):
            print('No')
            exit()
    else :
        if val not in('R','U','D'):
            print('No')
            exit()
print('Yes')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    sys.setrecursionlimit((10)->pow(6)) ;
    skip ;
    var S : OclAny := raw_input() ;
    S := (S) ;
    for _tuple : Integer.subrange(1, (S)->size())->collect( _indx | Sequence{_indx-1, (S)->at(_indx)} ) do (var _indx : int := 1;
      var idx : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var val : OclAny := _tuple->at(_indx);
      if MathLib.bitwiseAnd(idx, 1) then  (
      if (Sequence{'L', 'U', 'D'})->excludes(val) then (
      execute ('No')->display() ;
    exit()
    ) else skip
    )
    else (
      if (Sequence{'R', 'U', 'D'})->excludes(val) then (
      execute ('No')->display() ;
    exit()
    ) else skip
      )) ;
    execute ('Yes')->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
S=input()
length=len(S)
S_odd=[]
S_even=[]
for i in range(0,length,2):
    S_odd.append(S[i])
for i in range(1,length,2):
    S_even.append(S[i])
if("L" in S_odd)or("R" in S_even):
    print("No")
else :
    print("Yes")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var S : String := (OclFile["System.in"]).readLine() ;
    var length : int := (S)->size() ;
    var S_odd : Sequence := Sequence{} ;
    var S_even : Sequence := Sequence{} ;
    for i : Integer.subrange(0, length-1)->select( $x | ($x - 0) mod 2 = 0 ) do (    execute ((S[i+1]) : S_odd)) ;
    for i : Integer.subrange(1, length-1)->select( $x | ($x - 1) mod 2 = 0 ) do (    execute ((S[i+1]) : S_even)) ;
    if ((S_odd)->includes("L")) or ((S_even)->includes("R")) then  (
      execute ("No")->display()
    )
    else (
      execute ("Yes")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s=input()
odd=["R","U","D"]
gu=["L","U","D"]
flag=False
for i in range(len(s)):
    if i % 2==0 :
        if not(s[i]in odd):
            flag=True
            break
    else :
        if not(s[i]in gu):
            flag=True
            break
if flag :
    print("No")
else :
    print("Yes")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : String := (OclFile["System.in"]).readLine() ;
    var odd : Sequence := Sequence{"R"}->union(Sequence{"U"}->union(Sequence{ "D" })) ;
    var gu : Sequence := Sequence{"L"}->union(Sequence{"U"}->union(Sequence{ "D" })) ;
    var flag : boolean := false ;
    for i : Integer.subrange(0, (s)->size()-1) do (    if i mod 2 = 0 then  (
      if not(((odd)->includes(s[i+1]))) then (
      flag := true ;
    break
    ) else skip
    )
    else (
      if not(((gu)->includes(s[i+1]))) then (
      flag := true ;
    break
    ) else skip
      )) ;
    if flag then  (
      execute ("No")->display()
    )
    else (
      execute ("Yes")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    n=int(input())
    if n==0 : break
    tbl=[list(map(int,input().split()))for i in range(n)]
    tbl.sort(key=lambda x :(x[1],x[0]))
    s,f=0,True
    for v,w in tbl :
        s+=v
        if s>w :
            f=False
            break
    print("Yes" if f else "No")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    var tbl : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    tbl := tbl->sort() ;
    var s : OclAny := null;
    var f : OclAny := null;
    Sequence{s,f} := Sequence{0,true} ;
    for _tuple : tbl do (var _indx : int := 1;
      var v : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var w : OclAny := _tuple->at(_indx);
      s := s + v ;
    if (s->compareTo(w)) > 0 then (
      var f : boolean := false ;
    break
    ) else skip) ;
    execute (if f then "Yes" else "No" endif)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import exit
from functools import reduce
from operator import add
def f(): return[int(i)for i in input().split()]
while True :
    flag=False
    n=int(input())
    if not(n):
        exit()
    islands=[]
    for i in range(n):
        islands.append(f())
    islands.sort(key=lambda x : x[1])
    weight=0
    for j in range(n):
        weight+=islands[j][0]
        if weight>islands[j][1]:
            flag=True
            print("No")
            break
    if not(flag):
        print("Yes")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    while true do (    var flag : boolean := false ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if not((n)) then (
      exit()
    ) else skip ;
    var islands : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    execute ((f()) : islands)) ;
    islands := islands->sort() ;
    var weight : int := 0 ;
    for j : Integer.subrange(0, n-1) do (    weight := weight + islands[j+1]->first() ;
    if (weight->compareTo(islands[j+1][1+1])) > 0 then (
      flag := true ;
    execute ("No")->display() ;
    break
    ) else skip) ;
    if not((flag)) then (
      execute ("Yes")->display()
    ) else skip);
  operation f() : OclAny
  pre: true post: true
  activity:
    return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    n=input()
    if n==0 : break
    info=[]
    for i in range(n):
        lu,w=map(int,raw_input().split())
        info.append((w,lu))
    info.sort()
    lu_sum=0
    flag=True
    for w,lu in info :
        lu_sum+=lu
        if lu_sum>w :
            flag=False
    print("Yes" if flag else "No")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    var n : String := (OclFile["System.in"]).readLine() ;
    if n = 0 then (
      break
    ) else skip ;
    var info : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    var lu : OclAny := null;
    var w : OclAny := null;
    Sequence{lu,w} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute ((Sequence{w, lu}) : info)) ;
    info := info->sort() ;
    var lu_sum : int := 0 ;
    var flag : boolean := true ;
    for _tuple : info do (var _indx : int := 1;
      var w : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var lu : OclAny := _tuple->at(_indx);
      lu_sum := lu_sum + lu ;
    if (lu_sum->compareTo(w)) > 0 then (
      flag := false
    ) else skip) ;
    execute (if flag then "Yes" else "No" endif)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def sky(x):
    return x[1]
while True :
    n=int(input())
    if n==0 :
        break
    arr=[[]for i in range(n)]
    sumh=0
    for i in range(n):
        arr[i]=list(map(int,input().split()))
    arr.sort(key=sky)
    res=True
    for e in arr :
        sumh+=e[0]
        if sumh>e[1]:
            res=False
            break
    if res :
        print("Yes")
    else :
        print("No")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    while true do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    var arr : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ;
    var sumh : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    arr[i+1] := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ;
    arr := arr->sort() ;
    var res : boolean := true ;
    for e : arr do (    sumh := sumh + e->first() ;
    if (sumh->compareTo(e[1+1])) > 0 then (
      res := false ;
    break
    ) else skip) ;
    if res then  (
      execute ("Yes")->display()
    )
    else (
      execute ("No")->display()
      ));
  operation sky(x : OclAny) : OclAny
  pre: true post: true
  activity:
    return x[1+1];
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def getIndex(a,n):
    if(n==1):
        return 0
    ptrL=0
    ptrR=n-1
    sumL=a[0]
    sumR=a[n-1]
    while(ptrR-ptrL>1):
        if(sumLsumR):
            ptrR-=1
            sumR+=a[ptrR]
        else :
            break
    return ptrL
if __name__=="__main__" :
    a=[2,7,9,8,7]
    n=len(a)
    print(getIndex(a,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      a := Sequence{2}->union(Sequence{7}->union(Sequence{9}->union(Sequence{8}->union(Sequence{ 7 })))) ;
    n := (a)->size() ;
    execute (getIndex(a, n))->display()
    ) else skip;
  operation getIndex(a : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    if (n = 1) then (
      return 0
    ) else skip ;
    var ptrL : int := 0 ;
    var ptrR : double := n - 1 ;
    var sumL : OclAny := a->first() ;
    var sumR : OclAny := a[n - 1+1] ;
    while (ptrR - ptrL > 1) do (    if ((sumL->compareTo(sumR)) < 0) then  (
      ptrL := ptrL + 1 ;
    sumL := sumL + a[ptrL+1]
    )
    else (if ((sumL->compareTo(sumR)) > 0) then
   (
      ptrR := ptrR - 1 ;
    sumR := sumR + a[ptrR+1]    
)
    else (
      break
      )    )
) ;
    return ptrL;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    n=int(input())
    if n==0 :
        break
    bridges=[]
    for _ in range(n):
        t,b=map(int,input().split())
        bridges.append((t,b))
    bridges.sort(key=lambda x : x[1])
    flag=True
    sumt=0
    for t,b in bridges :
        sumt+=t
        if sumt>b :
            flag=False
            break
    if flag :
        print('Yes')
    else :
        print('No')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    var bridges : Sequence := Sequence{} ;
    for _anon : Integer.subrange(0, n-1) do (    var t : OclAny := null;
    var b : OclAny := null;
    Sequence{t,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute ((Sequence{t, b}) : bridges)) ;
    bridges := bridges->sort() ;
    var flag : boolean := true ;
    var sumt : int := 0 ;
    for _tuple : bridges do (var _indx : int := 1;
      var t : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var b : OclAny := _tuple->at(_indx);
      sumt := sumt + t ;
    if (sumt->compareTo(b)) > 0 then (
      flag := false ;
    break
    ) else skip) ;
    if flag then  (
      execute ('Yes')->display()
    )
    else (
      execute ('No')->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import defaultdict
n,k=list(map(int,input().split()))
lst=list(map(int,input().split()))
if k>n :
    print("NO")
    exit()
max_color=1
new_lst=[]
for i in range(n):
    new_lst.append([lst[i],i])
new_lst.sort()
new_lst[0].append(1)
for i in range(1,n):
    if n-i==k-max_color :
        new_lst[i].append(max_color+1)
        max_color+=1
    elif new_lst[i-1][0]==new_lst[i][0]:
        new_lst[i].append(new_lst[i-1][2]+1)
        if new_lst[i][2]>k :
            print("NO")
            exit()
        max_color=max(max_color,new_lst[i][2])
    else :
        new_lst[i].append(1)
new_lst.sort(key=lambda x : x[1])
print('YES')
for el in new_lst :
    print(el[2],end=' ')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if (k->compareTo(n)) > 0 then (
      execute ("NO")->display() ;
    exit()
    ) else skip ;
    var max_color : int := 1 ;
    var new_lst : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    execute ((Sequence{lst[i+1]}->union(Sequence{ i })) : new_lst)) ;
    new_lst := new_lst->sort() ;
(expr (atom (name new_lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))) ;
    for i : Integer.subrange(1, n-1) do (    if n - i = k - max_color then  (
  (expr (atom (name new_lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name max_color))) + (expr (atom (number (integer 1)))))))))) )))) ;
    max_color := max_color + 1
    )
    else (if new_lst[i - 1+1]->first() = new_lst[i+1]->first() then
   (
  (expr (atom (name new_lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name new_lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ]))) + (expr (atom (number (integer 1)))))))))) )))) ;
    if (new_lst[i+1][2+1]->compareTo(k)) > 0 then (
      execute ("NO")->display() ;
    exit()
    ) else skip ;
    max_color := Set{max_color, new_lst[i+1][2+1]}->max()    
)
    else (
  (expr (atom (name new_lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ))))
      )    )
) ;
    new_lst := new_lst->sort() ;
    execute ('YES')->display() ;
    for el : new_lst do (    execute (el[2+1])->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
lst1=list(map(int,input().split()))
lst2=sorted(lst1)
left=lst2[int(n/2)-1]
right=lst2[int(n/2)]
for num in lst1 :
    if num<=left :
        print(right)
    else :
        print(left)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var lst1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var lst2 : Sequence := lst1->sort() ;
    var left : OclAny := lst2[("" + ((n / 2)))->toInteger() - 1+1] ;
    var right : OclAny := lst2[("" + ((n / 2)))->toInteger()+1] ;
    for num : lst1 do (    if (num->compareTo(left)) <= 0 then  (
      execute (right)->display()
    )
    else (
      execute (left)->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    num=int(input())
    data=list(map(int,input().split()))
    data_kari=data.copy()
    data_kari.sort()
    min_chuou=data_kari[(num//2)-1]
    max_chuou=data_kari[num//2]
    for i in range(num):
        if data[i]<=min_chuou :
            print(max_chuou)
        elif data[i]>=max_chuou :
            print(min_chuou)
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var data : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var data_kari : OclAny := data->copy() ;
    data_kari := data_kari->sort() ;
    var min_chuou : OclAny := data_kari[(num div 2) - 1+1] ;
    var max_chuou : OclAny := data_kari[num div 2+1] ;
    for i : Integer.subrange(0, num-1) do (    if (data[i+1]->compareTo(min_chuou)) <= 0 then  (
      execute (max_chuou)->display()
    )
    else (if (data[i+1]->compareTo(max_chuou)) >= 0 then
   (
      execute (min_chuou)->display()    
)
 else skip));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from decimal import Decimal
n=int(input())
x=list(map(int,input().split()))
y=x.copy()
y.sort()
m1=y[n//2]
m2=y[n//2-1]
m=Decimal(m1+m2)/Decimal(2)
for z in x :
    if z<=m :
        print(m1)
    else :
        print(m2)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var y : OclAny := x->copy() ;
    y := y->sort() ;
    var m1 : OclAny := y[n div 2+1] ;
    var m2 : OclAny := y[n div 2 - 1+1] ;
    var m : double := Decimal(m1 + m2) / Decimal(2) ;
    for z : x do (    if (z->compareTo(m)) <= 0 then  (
      execute (m1)->display()
    )
    else (
      execute (m2)->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def solve(N : int,X : "List[int]"):
    x=sorted(X)
    l=x[N//2-1]
    r=x[N//2]
    for a in X :
        if a<=l :
            print(r)
        else :
            print(l)
    return
def main():
    def iterate_tokens():
        for line in sys.stdin :
            for word in line.split():
                yield word
    tokens=iterate_tokens()
    N=int(next(tokens))
    X=[int(next(tokens))for _ in range(N)]
    solve(N,X)
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation solve(N : int, X : "List[int]")
  pre: true post: true
  activity:
    var x : Sequence := X->sort() ;
    var l : OclAny := x[N div 2 - 1+1] ;
    var r : OclAny := x[N div 2+1] ;
    for a : X do (    if (a->compareTo(l)) <= 0 then  (
      execute (r)->display()
    )
    else (
      execute (l)->display()
      )) ;
    return;
  operation main()
  pre: true post: true
  activity:
    skip ;
    var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ;
    var N : int := ("" + (((tokens).next())))->toInteger() ;
    var X : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((tokens).next())))->toInteger())) ;
    solve(N, X);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    n=int(input())
    center=(n+1)//2
    x_s=list(map(int,input().split()))
    sorted_x_s=sorted(x_s)
    center_num=sorted_x_s[center]
    for i in x_s :
        if itoInteger() ;
    var center : int := (n + 1) div 2 ;
    var x_s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var sorted_x_s : Sequence := x_s->sort() ;
    var center_num : OclAny := sorted_x_s[center+1] ;
    for i : x_s do (    if (i->compareTo(center_num)) < 0 then  (
      execute (sorted_x_s[center+1])->display()
    )
    else (
      execute (sorted_x_s[center - 1+1])->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import pow
def highestPower(n,k):
    i=0
    a=pow(n,i)
    while(a<=k):
        i+=1
        a=pow(n,i)
    return i-1
b=[0 for i in range(50)]
def PowerArray(n,k):
    while(k):
        t=highestPower(n,k)
        if(b[t]):
            print(-1)
            return 0
        else :
            b[t]=1
        k-=pow(n,t)
    for i in range(50):
        if(b[i]):
            print(i,end=',')
if __name__=='__main__' :
    N=3
    K=40
    PowerArray(N,K)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var b : Sequence := Integer.subrange(0, 50-1)->select(i | true)->collect(i | (0)) ;
    skip ;
    if __name__ = '__main__' then (
      var N : int := 3 ;
    var K : int := 40 ;
    PowerArray(N, K)
    ) else skip;
  operation highestPower(n : OclAny, k : OclAny) : OclAny
  pre: true post: true
  activity:
    var i : int := 0 ;
    var a : double := (n)->pow(i) ;
    while ((a->compareTo(k)) <= 0) do (    i := i + 1 ;
    a := (n)->pow(i)) ;
    return i - 1;
  operation PowerArray(n : OclAny, k : OclAny) : OclAny
  pre: true post: true
  activity:
    while (k) do (    var t : OclAny := highestPower(n, k) ;
    if (b[t+1]) then  (
      execute (-1)->display() ;
    return 0
    )
    else (
      b[t+1] := 1
      ) ;
    k := k - (n)->pow(t)) ;
    for i : Integer.subrange(0, 50-1) do (    if (b[i+1]) then (
      execute (i)->display()
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
M=26
def getIdx(ch):
    return(ord(ch)-ord('a'))
def allSame(freq,N):
    for i in range(0,N):
        if(freq[i]>0):
            same=freq[i]
            break
    for j in range(i+1,N):
        if(freq[j]>0 and freq[j]!=same):
            return False
    return True
def possibleSameCharFreqByOneRemoval(str1):
    l=len(str1)
    freq=[0]*M
    for i in range(0,l):
        freq[getIdx(str1[i])]+=1
    if(allSame(freq,M)):
        return True
    for i in range(0,26):
        if(freq[i]>0):
            freq[i]-=1
            if(allSame(freq,M)):
                return True
            freq[i]+=1
    return False
if __name__=="__main__" :
    str1="xyyzz"
    if(possibleSameCharFreqByOneRemoval(str1)):
        print("Yes")
    else :
        print("No")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var M : int := 26 ;
    skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      str1 := "xyyzz" ;
    if (possibleSameCharFreqByOneRemoval(str1)) then  (
      execute ("Yes")->display()
    )
    else (
      execute ("No")->display()
      )
    ) else skip;
  operation getIdx(ch : OclAny) : OclAny
  pre: true post: true
  activity:
    return ((ch)->char2byte() - ('a')->char2byte());
  operation allSame(freq : OclAny, N : OclAny) : OclAny
  pre: true post: true
  activity:
    for i : Integer.subrange(0, N-1) do (    if (freq[i+1] > 0) then (
      var same : OclAny := freq[i+1] ;
    break
    ) else skip) ;
    for j : Integer.subrange(i + 1, N-1) do (    if (freq[j+1] > 0 & freq[j+1] /= same) then (
      return false
    ) else skip) ;
    return true;
  operation possibleSameCharFreqByOneRemoval(str1 : OclAny) : OclAny
  pre: true post: true
  activity:
    var l : int := (str1)->size() ;
    freq := MatrixLib.elementwiseMult(Sequence{ 0 }, M) ;
    for i : Integer.subrange(0, l-1) do (    freq[getIdx(str1[i+1])+1] := freq[getIdx(str1[i+1])+1] + 1) ;
    if (allSame(freq, M)) then (
      return true
    ) else skip ;
    for i : Integer.subrange(0, 26-1) do (    if (freq[i+1] > 0) then (
      freq[i+1] := freq[i+1] - 1 ;
    if (allSame(freq, M)) then (
      return true
    ) else skip ;
    freq[i+1] := freq[i+1] + 1
    ) else skip) ;
    return false;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
i=int(input())
p=0
q=0
while ptoInteger() ;
    var p : int := 0 ;
    var q : int := 0 ;
    while (p->compareTo(i)) < 0 do (    var f : double := i - p - 1 ;
    q := q + p * f + f ;
    p := p + 1) ;
    execute (q + i)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def solve(n):
    sum=0
    repeat=0
    for i in range(n,0,-1):
        sum=sum+(i-1)
        repeat=repeat+((n-i)*(i-1))
    right=n
    ans=sum+repeat+right
    return ans
n=int(input())
print(solve(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    execute (solve(n))->display();
  operation solve(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var sum : int := 0 ;
    var repeat : int := 0 ;
    for i : Integer.subrange(0 + 1, n)->reverse() do (    sum := sum + (i - 1) ;
    repeat := repeat + ((n - i) * (i - 1))) ;
    var right : OclAny := n ;
    var ans : int := sum + repeat + right ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def maxInt(string):
    string2=""
    for i in range(0,len(string)):
        if(string[i]<'5'):
            string2+=str((ord('9')-ord(string[i])))
        else :
            string2+=str(string[i])
    if(string2[0]=='0'):
        string2[0]='9'
    return string2
if __name__=='__main__' :
    string="42"
    print(maxInt(string))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      string := "42" ;
    execute (maxInt(string))->display()
    ) else skip;
  operation maxInt(string : OclAny) : OclAny
  pre: true post: true
  activity:
    var string2 : String := "" ;
    for i : Integer.subrange(0, (string)->size()-1) do (    if (string[i+1] < '5') then  (
      string2 := string2 + ("" + (((('9')->char2byte() - (string[i+1])->char2byte()))))
    )
    else (
      string2 := string2 + ("" + ((string[i+1])))
      )) ;
    if (string2->first() = '0') then (
      string2->first() := '9'
    ) else skip ;
    return string2;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def func(n,k,a):
    check_dict={}
    for elem in a :
        if elem not in check_dict :
            check_dict[elem]=0
        check_dict[elem]+=1
    check_list=sorted(check_dict.values(),reverse=True)
    if check_list[0]>k :
        return 'NO'
    d={}
    for i in range(n):
        if a[i]not in d :
            d[a[i]]=[]
        d[a[i]].append(i)
    counter=1
    for val in d :
        for elem in d[val]:
            a[elem]=counter
            counter+=1
            if counter>k :
                counter=1
    return ' '.join(str(e)for e in a)
def main():
    str=list(map(int,input().split()))
    n=str[0]
    k=str[1]
    a=list(map(int,input().split()))
    var=func(n,k,a)
    if var=='NO' :
        print(var)
    else :
        ans=['YES',var]
        for elem in ans :
            print(elem)
main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    main();
  operation func(n : OclAny, k : OclAny, a : OclAny) : OclAny
  pre: true post: true
  activity:
    var check_dict : OclAny := Set{} ;
    for elem : a do (    if (check_dict)->excludes(elem) then (
      check_dict[elem+1] := 0
    ) else skip ;
    check_dict[elem+1] := check_dict[elem+1] + 1) ;
    var check_list : Sequence := check_dict.values()->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ;
    if (check_list->first()->compareTo(k)) > 0 then (
      return 'NO'
    ) else skip ;
    var d : OclAny := Set{} ;
    for i : Integer.subrange(0, n-1) do (    if (d)->excludes(a[i+1]) then (
      d[a[i+1]+1] := Sequence{}
    ) else skip ;
(expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ;
    var counter : int := 1 ;
    for val : d do (    for elem : d[val+1] do (    a[elem+1] := counter ;
    counter := counter + 1 ;
    if (counter->compareTo(k)) > 0 then (
      counter := 1
    ) else skip)) ;
    return StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name e)))))))) ))))))) (comp_for for (exprlist (expr (atom (name e)))) in (logical_test (comparison (expr (atom (name a)))))))), ' ');
  operation main()
  pre: true post: true
  activity:
    var OclType["String"] : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    n := ("" + (->first())) ;
    k := ("" + ([1+1])) ;
    a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var var : OclAny := func(n, k, a) ;
    if var = 'NO' then  (
      execute (var)->display()
    )
    else (
      var ans : Sequence := Sequence{'YES'}->union(Sequence{ var }) ;
    for elem : ans do (    execute (elem)->display())
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
print((n-1)*n*(n+1)//6+n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    execute ((n - 1) * n * (n + 1) div 6 + n)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
if n==1 :
    print(1)
elif n==2 :
    print(3)
else :
    push=1
    i=1
    while n>1 :
        push+=n*i-(i-1)
        n-=1
        i+=1
    print(push)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 1 then  (
      execute (1)->display()
    )
    else (if n = 2 then
   (
      execute (3)->display()    
)
    else (
      var push : int := 1 ;
    var i : int := 1 ;
    while n > 1 do (    push := push + n * i - (i - 1) ;
    n := n - 1 ;
    i := i + 1) ;
    execute (push)->display()
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
print(int(((n**3)+5*n)/6))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    execute (("" + (((((n)->pow(3)) + 5 * n) / 6)))->toInteger())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
num=int(input())
result=""
n=2
for i in range(2,num+1):
    if n % num!=0 :
        result+=str(n % num)+" "
    else :
        result+=str(num)+" "
    n+=i
print(result)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var result : String := "" ;
    var n : int := 2 ;
    for i : Integer.subrange(2, num + 1-1) do (    if n mod num /= 0 then  (
      result := result + ("" + ((n mod num))) + " "
    )
    else (
      result := result + ("" + ((num))) + " "
      ) ;
    n := n + i) ;
    execute (result)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
ball=1
for i in range(n-1):
    ball+=i+1
    if ball % n==0 :
        print(n,end=" ")
    else :
        print(ball % n,end=" ")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var ball : int := 1 ;
    for i : Integer.subrange(0, n - 1-1) do (    ball := ball + i + 1 ;
    if ball mod n = 0 then  (
      execute (n)->display()
    )
    else (
      execute (ball mod n)->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
temp=[2]
i=2
y=2
while(len(temp)<(n-1)):
    y+=i
    y=y % n
    if y==0 :
        y=n
    i+=1
    temp.append(y)
for i in temp :
    print(i,end=' ')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var temp : Sequence := Sequence{ 2 } ;
    var i : int := 2 ;
    var y : int := 2 ;
    while (((temp)->size()->compareTo((n - 1))) < 0) do (    y := y + i ;
    y := y mod n ;
    if y = 0 then (
      y := n
    ) else skip ;
    i := i + 1 ;
    execute ((y) : temp)) ;
    for i : temp do (    execute (i)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
res,cur=[],1
for i in range(n-1):
    cur=1+(cur+i)% n
    res.append(cur)
print(*res)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var res : OclAny := null;
    var cur : OclAny := null;
    Sequence{res,cur} := Sequence{Sequence{},1} ;
    for i : Integer.subrange(0, n - 1-1) do (    var cur : int := 1 + (cur + i) mod n ;
    execute ((cur) : res)) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
num=int(input())
n=2
for i in range(2,num+1):
    if n % num!=0 :
        print(n % num)
    else :
        print(num)
    n+=i
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var n : int := 2 ;
    for i : Integer.subrange(2, num + 1-1) do (    if n mod num /= 0 then  (
      execute (n mod num)->display()
    )
    else (
      execute (num)->display()
      ) ;
    n := n + i);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
def printNonSquare(n):
    curr_count=2
    num=2
    count=0
    while(countcompareTo(n)) < 0) do (    var i : int := 0 ;
    while ((i->compareTo(curr_count)) < 0 & (count->compareTo(n)) < 0) do (    execute (num)->display() ;
    count := count + 1 ;
    num := num + 1 ;
    i := i + 1) ;
    num := num + 1 ;
    curr_count := curr_count + 2);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def magicIndex(arr,start,end):
    if(start>end):
        return-1
    midIndex=int((start+end)/2)
    midValue=arr[midIndex]
    if(midIndex==midValue):
        return midIndex
    left=magicIndex(arr,start,min(midValue,midIndex-1))
    if(left>=0):
        return left
    return magicIndex(arr,max(midValue,midIndex+1),end)
arr=[-10,-5,2,2,2,3,4,7,9,12,13]
n=len(arr)
index=magicIndex(arr,0,n-1)
if(index==-1):
    print("No Magic Index")
else :
    print("Magic Index is :",index)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    arr := Sequence{-10}->union(Sequence{-5}->union(Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{7}->union(Sequence{9}->union(Sequence{12}->union(Sequence{ 13 })))))))))) ;
    var n : int := (arr)->size() ;
    var index : OclAny := magicIndex(arr, 0, n - 1) ;
    if (index = -1) then  (
      execute ("No Magic Index")->display()
    )
    else (
      execute ("Magic Index is :")->display()
      );
  operation magicIndex(arr : OclAny, start : OclAny, end : OclAny) : OclAny
  pre: true post: true
  activity:
    if ((start->compareTo(end)) > 0) then (
      return -1
    ) else skip ;
    var midIndex : int := ("" + (((start + end) / 2)))->toInteger() ;
    var midValue : OclAny := arr[midIndex+1] ;
    if (midIndex = midValue) then (
      return midIndex
    ) else skip ;
    var left : OclAny := magicIndex(arr, start, Set{midValue, midIndex - 1}->min()) ;
    if (left >= 0) then (
      return left
    ) else skip ;
    return magicIndex(arr, Set{midValue, midIndex + 1}->max(), end);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
import sys
import queue
from heapq import heappop,heappush
import random
def solve():
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    f={}
    for i in range(n):
        if a[i]not in f :
            f[a[i]]=[i]
        else :
            f[a[i]].append(i)
    for key in f :
        if len(f[key])>k :
            print("NO")
            return
    it=0
    res=[0 for i in range(n)]
    for key in f :
        for j in f[key]:
            res[j]=it+1
            it=(1+it)% k
    print("YES")
    print(*res)
if __name__=='__main__' :
    multi_test=0
    if multi_test :
        t=int(input())
        for _ in range(t):
            solve()
    else :
        solve()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      var multi_test : int := 0 ;
    if multi_test then  (
      var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, t-1) do (    solve())
    )
    else (
      solve()
      )
    ) else skip;
  operation solve()
  pre: true post: true
  activity:
    var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var f : OclAny := Set{} ;
    for i : Integer.subrange(0, n-1) do (    if (f)->excludes(a[i+1]) then  (
      f[a[i+1]+1] := Sequence{ i }
    )
    else (
  (expr (atom (name f)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))
      )) ;
    for key : f do (    if ((f[key+1])->size()->compareTo(k)) > 0 then (
      execute ("NO")->display() ;
    return
    ) else skip) ;
    var it : int := 0 ;
    var res : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ;
    for key : f do (    for j : f[key+1] do (    res[j+1] := it + 1 ;
    it := (1 + it) mod k)) ;
    execute ("YES")->display() ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
CHARS="0123456789ABCDEF" ;
DIGITS=16 ;
def isDivisible(s,m):
    mp=dict.fromkeys(CHARS,0);
    for i in range(DIGITS):
        mp[CHARS[i]]=i ;
    r=0 ;
    for i in range(len(s)):
        r=(r*16+mp[s[i]])% m ;
    if(not r):
        return True ;
    return False ;
if __name__=="__main__" :
    s="10" ;
    m=3 ;
    if(isDivisible(s,m)):
        print("Yes");
    else :
        print("No");
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var CHARS : String := "0123456789ABCDEF"; ;
    var DIGITS : int := 16; ;
    skip ;
    if __name__ = "__main__" then (
      s := "10"; ;
    m := 3; ;
    if (isDivisible(s, m)) then  (
      execute ("Yes")->display();
    )
    else (
      execute ("No")->display();
      )
    ) else skip;
  operation isDivisible(s : OclAny, m : OclAny)
  pre: true post: true
  activity:
    var mp : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name CHARS))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))); ;
    for i : Integer.subrange(0, DIGITS-1) do (    mp[CHARS[i+1]+1] := i;) ;
    var r : int := 0; ;
    for i : Integer.subrange(0, (s)->size()-1) do (    r := (r * 16 + mp[s[i+1]+1]) mod m;) ;
    if (not(r)) then (
      return true;
    ) else skip ;
    return false;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
def checkcircle(r,R,r1,x1,y1):
    dis=int(math.sqrt(x1*x1+y1*y1))
    return(dis-r1>=R and dis+r1<=r)
r=8 ; R=4 ; r1=2 ; x1=6 ; y1=0
if(checkcircle(r,R,r1,x1,y1)):
    print("yes")
else :
    print("no")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    r := 8;    R := 4;    r1 := 2;    x1 := 6;    y1 := 0 ;
    if (checkcircle(r, R, r1, x1, y1)) then  (
      execute ("yes")->display()
    )
    else (
      execute ("no")->display()
      );
  operation checkcircle(r : OclAny, R : OclAny, r1 : OclAny, x1 : OclAny, y1 : OclAny) : OclAny
  pre: true post: true
  activity:
    var dis : int := ("" + (((x1 * x1 + y1 * y1)->sqrt())))->toInteger() ;
    return ((dis - r1->compareTo(R)) >= 0 & (dis + r1->compareTo(r)) <= 0);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def maxProfit(price,n,k):
    profit=[[0 for i in range(n+1)]for j in range(k+1)]
    for i in range(1,k+1):
        prevDiff=float('-inf')
        for j in range(1,n):
            prevDiff=max(prevDiff,profit[i-1][j-1]-price[j-1])
            profit[i][j]=max(profit[i][j-1],price[j]+prevDiff)
    return profit[k][n-1]
if __name__=="__main__" :
    k=3
    price=[12,14,17,10,14,13,12,15]
    n=len(price)
    print("Maximum profit is:",maxProfit(price,n,k))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      k := 3 ;
    price := Sequence{12}->union(Sequence{14}->union(Sequence{17}->union(Sequence{10}->union(Sequence{14}->union(Sequence{13}->union(Sequence{12}->union(Sequence{ 15 }))))))) ;
    n := (price)->size() ;
    execute ("Maximum profit is:")->display()
    ) else skip;
  operation maxProfit(price : OclAny, n : OclAny, k : OclAny) : OclAny
  pre: true post: true
  activity:
    var profit : Sequence := Integer.subrange(0, k + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)))) ;
    for i : Integer.subrange(1, k + 1-1) do (    var prevDiff : double := ("" + (('-inf')))->toReal() ;
    for j : Integer.subrange(1, n-1) do (    prevDiff := Set{prevDiff, profit[i - 1+1][j - 1+1] - price[j - 1+1]}->max() ;
    profit[i+1][j+1] := Set{profit[i+1][j - 1+1], price[j+1] + prevDiff}->max())) ;
    return profit[k+1][n - 1+1];
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import copy
t=int(input())
for p in range(t):
    n,m=map(int,input().split())
    a=[]
    b=[]
    for j in range(n):
        l=list(map(int,input().split()))
        a.append(l)
    ans=[]
    var=0
    for j in range((n)):
        for k in range((m)):
            ans.append([a[j][k],a[j][m-k-1],a[n-j-1][k],a[n-j-1][m-k-1]])
    for j in range(len(ans)):
        ans[j].sort()
        var+=ans[j][3]+ans[j][2]-ans[j][1]-ans[j][0]
    print(var//4)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for p : Integer.subrange(0, t-1) do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : Sequence := Sequence{} ;
    var b : Sequence := Sequence{} ;
    for j : Integer.subrange(0, n-1) do (    var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute ((l) : a)) ;
    var ans : Sequence := Sequence{} ;
    var var : int := 0 ;
    for j : Integer.subrange(0, (n)-1) do (    for k : Integer.subrange(0, (m)-1) do (    execute ((Sequence{a[j+1][k+1]}->union(Sequence{a[j+1][m - k - 1+1]}->union(Sequence{a[n - j - 1+1][k+1]}->union(Sequence{ a[n - j - 1+1][m - k - 1+1] })))) : ans))) ;
    for j : Integer.subrange(0, (ans)->size()-1) do ((expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name sort) (arguments ( )))) ;
    var := var + ans[j+1][3+1] + ans[j+1][2+1] - ans[j+1][1+1] - ans[j+1]->first()) ;
    execute (var div 4)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in[0]*int(input()):
    n,m=map(int,input().split())
    r=[[*map(int,input().split())]for _ in[0]*n]; times=0
    for i in range((n+1)//2):
        for j in range((m+1)//2):
            a=sorted([r[i][j],r[i][-j-1],r[-i-1][j],r[-i-1][-j-1]])
            times+=(a[3]+a[2]-a[1]-a[0])//(1+(i==n//2 or j==m//2))
    print(times)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var r : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n)->select(_anon | true)->collect(_anon | ((input().split())->collect( _x | (OclType["int"])->apply(_x) )));    var times : int := 0 ;
    for i : Integer.subrange(0, (n + 1) div 2-1) do (    for j : Integer.subrange(0, (m + 1) div 2-1) do (    var a : Sequence := Sequence{r[i+1][j+1]}->union(Sequence{r[i+1]->reverse()->at(-(-j - 1))}->union(Sequence{r->reverse()->at(-(-i - 1))[j+1]}->union(Sequence{ r->reverse()->at(-(-i - 1))->reverse()->at(-(-j - 1)) })))->sort() ;
    times := times + (a[3+1] + a[2+1] - a[1+1] - a->first()) div (1 + (i = n div 2 or j = m div 2)))) ;
    execute (times)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def round(a,b,c,d):
    l=sorted([a,b,c,d])
    return l[1]
t=int(input())
for _ in range(t):
    n,m=map(int,input().split())
    l=[]
    for i in range(n):
        l.append(list(map(int,input().split())))
    temp=[[0 for i in range(m)]for k in range(n)]
    for i in range(int((n+1)//2)):
        for j in range(int((m+1)//2)):
            s=round(l[i][j],l[(n-1)-i][j],l[i][(m-1)-j],l[(n-1)-i][(m-1)-j])
            temp[i][j]=s
            temp[i][(m-1)-j]=s
            temp[(n-1)-i][j]=s
            temp[(n-1)-i][(m-1)-j]=s
    ans=0
    for i in range(n):
        for j in range(m):
            ans+=abs(l[i][j]-temp[i][j])
    print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, t-1) do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    l := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : l)) ;
    var temp : Sequence := Integer.subrange(0, n-1)->select(k | true)->collect(k | (Integer.subrange(0, m-1)->select(i | true)->collect(i | (0)))) ;
    for i : Integer.subrange(0, ("" + (((n + 1) div 2)))->toInteger()-1) do (    for j : Integer.subrange(0, ("" + (((m + 1) div 2)))->toInteger()-1) do (    var s : double := MathLib.roundN(l[i+1][j+1], l[(n - 1) - i+1][j+1]) ;
    temp[i+1][j+1] := s ;
    temp[i+1][(m - 1) - j+1] := s ;
    temp[(n - 1) - i+1][j+1] := s ;
    temp[(n - 1) - i+1][(m - 1) - j+1] := s)) ;
    var ans : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    for j : Integer.subrange(0, m-1) do (    ans := ans + (l[i+1][j+1] - temp[i+1][j+1])->abs())) ;
    execute (ans)->display());
  operation round(a : OclAny, b : OclAny, c : OclAny, d : OclAny) : OclAny
  pre: true post: true
  activity:
    var l : Sequence := Sequence{a}->union(Sequence{b}->union(Sequence{c}->union(Sequence{ d })))->sort() ;
    return l[1+1];
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
for _ in range(int(input())):
    n,m=map(int,input().split())
    g=[list(map(int,input().split()))for _ in range(n)]
    s=0
    for i in range(n//2):
        for j in range(m//2):
            a=g[i][j]
            b=g[i][m-1-j]
            c=g[n-1-i][j]
            d=g[n-1-i][m-1-j]
            a,b,c,d=sorted([a,b,c,d])
            s+=c+d-a-b
    if n % 2 :
        for i in range(m//2):
            a=g[n//2][i]
            b=g[n//2][m-1-i]
            x=(a+b)//2
            s+=abs(a-x)+abs(b-x)
    if m % 2 :
        for i in range(n//2):
            a=g[i][m//2]
            b=g[n-1-i][m//2]
            x=(a+b)//2
            s+=abs(a-x)+abs(b-x)
    print(s)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var g : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var s : int := 0 ;
    for i : Integer.subrange(0, n div 2-1) do (    for j : Integer.subrange(0, m div 2-1) do (    var a : OclAny := g[i+1][j+1] ;
    var b : OclAny := g[i+1][m - 1 - j+1] ;
    var c : OclAny := g[n - 1 - i+1][j+1] ;
    var d : OclAny := g[n - 1 - i+1][m - 1 - j+1] ;
    Sequence{a,b,c,d} := Sequence{a}->union(Sequence{b}->union(Sequence{c}->union(Sequence{ d })))->sort() ;
    s := s + c + d - a - b)) ;
    if n mod 2 then (
      for i : Integer.subrange(0, m div 2-1) do (    a := g[n div 2+1][i+1] ;
    b := g[n div 2+1][m - 1 - i+1] ;
    var x : int := (a + b) div 2 ;
    s := s + (a - x)->abs() + (b - x)->abs())
    ) else skip ;
    if m mod 2 then (
      for i : Integer.subrange(0, n div 2-1) do (    a := g[i+1][m div 2+1] ;
    b := g[n - 1 - i+1][m div 2+1] ;
    x := (a + b) div 2 ;
    s := s + (a - x)->abs() + (b - x)->abs())
    ) else skip ;
    execute (s)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
q=int(input())
for _ in range(q):
    a,b=map(int,input().split())
    arr=[[x for x in map(int,input().split())]for i in range(a)]
    d=0
    for i in range((a-1)//2+1):
        for j in range((b-1)//2+1):
            rowsym=b-1-j
            tablesym=a-1-i
            n1=arr[i][j]
            n2=arr[i][rowsym]
            n3=arr[tablesym][j]
            n4=arr[tablesym][rowsym]
            arr1=sorted([n1,n2,n3,n4])
            sr=arr1[1]
            if(i!=tablesym and j!=rowsym):
                d+=abs(n1-sr)+abs(n2-sr)+abs(n3-sr)+abs(n4-sr)
            else :
                d+=arr1[3]-sr
    print(d)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, q-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var arr : Sequence := Integer.subrange(0, a-1)->select(i | true)->collect(i | ((input().split())->collect( _x | (OclType["int"])->apply(_x) )->select(x | true)->collect(x | (x)))) ;
    var d : int := 0 ;
    for i : Integer.subrange(0, (a - 1) div 2 + 1-1) do (    for j : Integer.subrange(0, (b - 1) div 2 + 1-1) do (    var rowsym : double := b - 1 - j ;
    var tablesym : double := a - 1 - i ;
    var n1 : OclAny := arr[i+1][j+1] ;
    var n2 : OclAny := arr[i+1][rowsym+1] ;
    var n3 : OclAny := arr[tablesym+1][j+1] ;
    var n4 : OclAny := arr[tablesym+1][rowsym+1] ;
    var arr1 : Sequence := Sequence{n1}->union(Sequence{n2}->union(Sequence{n3}->union(Sequence{ n4 })))->sort() ;
    var sr : OclAny := arr1[1+1] ;
    if (i /= tablesym & j /= rowsym) then  (
      d := d + (n1 - sr)->abs() + (n2 - sr)->abs() + (n3 - sr)->abs() + (n4 - sr)->abs()
    )
    else (
      d := d + arr1[3+1] - sr
      ))) ;
    execute (d)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    n,m=map(int,input().split())
    s=input()
    for i in range(min(m,n)):
        while '101' in s :
            s=s.replace('101','1x1')
        s=s.replace('01','11')
        s=s.replace('10','11')
        while '1x1' in s :
            s=s.replace('1x1','101')
    print(s)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var s : String := (OclFile["System.in"]).readLine() ;
    for i : Integer.subrange(0, Set{m, n}->min()-1) do (    while (s)->characters()->includes('101') do (    s := s.replace('101', '1x1')) ;
    s := s.replace('01', '11') ;
    s := s.replace('10', '11') ;
    while (s)->characters()->includes('1x1') do (    s := s.replace('1x1', '101'))) ;
    execute (s)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
r=str.replace
for _ in[0]*int(input()):
    m=min(map(int,input().split()))
    s=f'0{input()}0'
    while m :
        m-=1
        s=r(r(r(r(r(s,'100','1*0'),'001','0*1'),'*01','111'),'10*','111'),'*','1')
    print(s[1 :-1])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var r : String := ("" + (.replace)) ;
    for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do (    var m : OclAny := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->min() ;
    var s : String := StringLib.formattedString('0{input()}0') ;
    while m do (    m := m - 1 ;
    s := r(r(r(r(r(s, '100', '1*0'), '001', '0*1'), '*01', '111'), '10*', '111'), '*', '1')) ;
    execute (s.subrange(1+1, -1))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,k=map(int,input().split())
arr=list(map(int,input().split()))
d=dict()
for i in arr :
    if(i not in d.keys()):
        d[i]=1
    else :
        d[i]+=1
idxs=dict()
for i in range(len(arr)):
    if(arr[i]not in idxs.keys()):
        idxs[arr[i]]=[]
    idxs[arr[i]].append(i)
if(len(arr)k):
    print("NO")
else :
    print("YES")
    ans=[-1]*n
    color=1
    for i in idxs.keys():
        for j in idxs[i]:
            ans[j]=color
            color+=1
            if(color>k):
                color=1
    print(*ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var k : OclAny := null;
    Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var d : Map := (arguments ( )) ;
    for i : arr do (    if ((d.keys())->excludes(i)) then  (
      d[i+1] := 1
    )
    else (
      d[i+1] := d[i+1] + 1
      )) ;
    var idxs : Map := (arguments ( )) ;
    for i : Integer.subrange(0, (arr)->size()-1) do (    if ((idxs.keys())->excludes(arr[i+1])) then (
      idxs[arr[i+1]+1] := Sequence{}
    ) else skip ;
(expr (atom (name idxs)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ;
    if (((arr)->size()->compareTo(k)) < 0 or (((d.values()))->max()->compareTo(k)) > 0) then  (
      execute ("NO")->display()
    )
    else (
      execute ("YES")->display() ;
    var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ;
    var color : int := 1 ;
    for i : idxs.keys() do (    for j : idxs[i+1] do (    ans[j+1] := color ;
    color := color + 1 ;
    if ((color->compareTo(k)) > 0) then (
      color := 1
    ) else skip)) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import re
I=input
for _ in[0]*int(I()):
    m=min(map(int,I().split())); s=I()
    while m : m-=1 ; s=re.sub('((?<=0)|^)0(?=1)|(?<=1)0((?=0)|$)','1',s)
    print(s)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var I : OclAny := input ;
    for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + ((I())))->toInteger()) do (    var m : OclAny := ((I().split())->collect( _x | (OclType["int"])->apply(_x) ))->min();    var s : OclAny := I() ;
    while m do (    m := m - 1;    s := (s).replaceAllMatches('((?<=0)|^)0(?=1)|(?<=1)0((?=0)|$)', '1')) ;
    execute (s)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import re
PATTERN=re.compile("((?<=0)|^)0(?=1)|(?<=1)0((?=0)|$)")
for _ in range(int(input())):
    m=min(map(int,input().split()))
    s=input()
    for _ in range(m):
        s=PATTERN.sub("1",s)
    print(s)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var PATTERN : OclRegex := OclRegex.compile("((?<=0)|^)0(?=1)|(?<=1)0((?=0)|$)") ;
    for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var m : OclAny := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->min() ;
    var s : String := (OclFile["System.in"]).readLine() ;
    for _anon : Integer.subrange(0, m-1) do (    s := PATTERN.sub("1", s)) ;
    execute (s)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s=input()
l=[]
for j in range(len(s)):
    l.append(s[j])
ans=[]
f=0
r=len(s)-1
while fsize()-1) do (    execute ((s[j+1]) : l)) ;
    var ans : Sequence := Sequence{} ;
    var f : int := 0 ;
    var r : double := (s)->size() - 1 ;
    while (f->compareTo(r)) < 0 do (    if l[f+1] = "(" & l[r+1] = ")" then  (
      execute ((f + 1) : ans) ;
    execute ((r + 1) : ans) ;
    f := f + 1 ;
    r := r - 1
    )
    else (if l[f+1] = "(" & l[r+1] /= ")" then
   (
      r := r - 1    
)
    else (if l[f+1] /= "(" & l[r+1] = ")" then
   (
      f := f + 1    
)
    else (
      f := f + 1 ;
    r := r - 1
      )    )
    )
) ;
    if (ans)->size() = 0 then  (
      execute (0)->display()
    )
    else (
      execute (1)->display() ;
    execute ((ans)->size())->display() ;
    ans := ans->sort() ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    n,m=map(int,input().split())
    arr=input()
    for i in range(min(m,n)):
        while '101' in arr :
            arr=arr.replace('101','1x1')
        arr=arr.replace('01','11')
        arr=arr.replace('10','11')
        while '1x1' in arr :
            arr=arr.replace('1x1','101')
    print(arr)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var arr : String := (OclFile["System.in"]).readLine() ;
    for i : Integer.subrange(0, Set{m, n}->min()-1) do (    while (arr)->characters()->includes('101') do (    arr := arr.replace('101', '1x1')) ;
    arr := arr.replace('01', '11') ;
    arr := arr.replace('10', '11') ;
    while (arr)->characters()->includes('1x1') do (    arr := arr.replace('1x1', '101'))) ;
    execute (arr)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import random
import math
e=2.71828 ;
def roundNo(num):
    if(num<0):
        return(num-0.5)
    else :
        return(num+0.5);
def printBestCandidate(candidate,n):
    sample_size=roundNo(n/e);
    print("\n\nSample size is",math.floor(sample_size));
    best=0 ;
    for i in range(1,int(sample_size)):
        if(candidate[i]>candidate[best]):
            best=i ;
    for i in range(int(sample_size),n):
        if(candidate[i]>=candidate[best]):
            best=i ;
            break ;
    if(best>=int(sample_size)):
        print("\nBest candidate found is",math.floor(best+1),"with talent",math.floor(candidate[best]));
    else :
        print("Couldn't find a best candidate");
n=8 ;
candidate=[0]*(n);
for i in range(n):
    candidate[i]=1+random.randint(1,8);
print("Candidate : ",end="");
for i in range(n):
    print((i+1),end="");
print("\nTalents : ",end="");
for i in range(n):
    print(candidate[i],end="");
printBestCandidate(candidate,n);
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var e : double := 2.71828; ;
    skip ;
    skip ;
    n := 8; ;
    candidate := MatrixLib.elementwiseMult(Sequence{ 0 }, (n)); ;
    for i : Integer.subrange(0, n-1) do (    candidate[i+1] := 1 + (1 + (OclRandom.defaultInstanceOclRandom()).nextInt(8 - 1));) ;
    execute ("Candidate : ")->display(); ;
    for i : Integer.subrange(0, n-1) do (    execute ((i + 1))->display();) ;
    execute ("\nTalents : ")->display(); ;
    for i : Integer.subrange(0, n-1) do (    execute (candidate[i+1])->display();) ;
    printBestCandidate(candidate, n);;
  operation roundNo(num : OclAny) : OclAny
  pre: true post: true
  activity:
    if (num < 0) then  (
      return (num - 0.5)
    )
    else (
      return (num + 0.5);
      );
  operation printBestCandidate(candidate : OclAny, n : OclAny)
  pre: true post: true
  activity:
    var sample_size : OclAny := roundNo(n / e); ;
    execute ("\n\nSample size is")->display(); ;
    var best : int := 0; ;
    for i : Integer.subrange(1, ("" + ((sample_size)))->toInteger()-1) do (    if ((candidate[i+1]->compareTo(candidate[best+1])) > 0) then (
      best := i;
    ) else skip) ;
    for i : Integer.subrange(("" + ((sample_size)))->toInteger(), n-1) do (    if ((candidate[i+1]->compareTo(candidate[best+1])) >= 0) then (
      best := i; ;
    break;
    ) else skip) ;
    if ((best->compareTo(("" + ((sample_size)))->toInteger())) >= 0) then  (
      execute ("\nBest candidate found is")->display();
    )
    else (
      execute ("Couldn't find a best candidate")->display();
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def GCD(a,b):
    remain=0
    while b!=0 :
        remain=a % b
        a=b
        b=remain
    return a
if __name__=="__main__" :
    nBoys,nGirls=map(int,input().split())
    lstB=list(map(int,input().split()))
    lstG=list(map(int,input().split()))
    numUnhappy=nBoys+nGirls-lstB[0]-lstG[0]
    happyBoys=[False]*(nBoys)
    happyGirls=[False]*(nGirls)
    for i in range(1,len(lstB)):
        happyBoys[lstB[i]]=True
    for i in range(1,len(lstG)):
        happyGirls[lstG[i]]=True
    lim=nBoys*nGirls//GCD(nBoys,nGirls)
    for i in range(2*lim):
        if happyBoys[i % nBoys]+happyGirls[i % nGirls]==1 :
            happyBoys[i % nBoys]=happyGirls[i % nGirls]=True
            numUnhappy-=1
    print('Yes' if numUnhappy==0 else 'No')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      var nBoys : OclAny := null;
    var nGirls : OclAny := null;
    Sequence{nBoys,nGirls} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var lstB : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var lstG : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var numUnhappy : double := nBoys + nGirls - lstB->first() - lstG->first() ;
    var happyBoys : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (nBoys)) ;
    var happyGirls : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (nGirls)) ;
    for i : Integer.subrange(1, (lstB)->size()-1) do (    happyBoys[lstB[i+1]+1] := true) ;
    for i : Integer.subrange(1, (lstG)->size()-1) do (    happyGirls[lstG[i+1]+1] := true) ;
    var lim : int := nBoys * nGirls div GCD(nBoys, nGirls) ;
    for i : Integer.subrange(0, 2 * lim-1) do (    if happyBoys[i mod nBoys+1] + happyGirls[i mod nGirls+1] = 1 then (
      happyBoys[i mod nBoys+1] := true; var happyGirls[i mod nGirls+1] : boolean := true ;
    numUnhappy := numUnhappy - 1
    ) else skip) ;
    execute (if numUnhappy = 0 then 'Yes' else 'No' endif)->display()
    ) else skip;
  operation GCD(a : OclAny, b : OclAny) : OclAny
  pre: true post: true
  activity:
    var remain : int := 0 ;
    while b /= 0 do (    remain := a mod b ;
    a := b ;
    b := remain) ;
    return a;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
if __name__=='__main__' :
    n,m=map(int,input().split())
    b_index=list(map(int,input().split()))[1 :]
    g_index=list(map(int,input().split()))[1 :]
    b=[0]*n
    g=[0]*m
    for i in b_index :
        b[i]=1
    for i in g_index :
        g[i]=1
    for t in range(n*m*2+1):
        if b[t % n]or g[t % m]:
            b[t % n]=g[t % m]=1
    f=1
    for i in range(n):
        if not b[i]:
            f=0
    for i in range(m):
        if not g[i]:
            f=0
    if f :
        print('Yes')
    else :
        print('No')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     if __name__ = '__main__' then (
      var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var b_index : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->tail() ;
    var g_index : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->tail() ;
    var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ;
    var g : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ;
    for i : b_index do (    b[i+1] := 1) ;
    for i : g_index do (    g[i+1] := 1) ;
    for t : Integer.subrange(0, n * m * 2 + 1-1) do (    if b[t mod n+1] or g[t mod m+1] then (
      b[t mod n+1] := 1; var g[t mod m+1] : int := 1
    ) else skip) ;
    var f : int := 1 ;
    for i : Integer.subrange(0, n-1) do (    if not(b[i+1]) then (
      f := 0
    ) else skip) ;
    for i : Integer.subrange(0, m-1) do (    if not(g[i+1]) then (
      f := 0
    ) else skip) ;
    if f then  (
      execute ('Yes')->display()
    )
    else (
      execute ('No')->display()
      )
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import fractions as f
def i():
    return list(map(int,input().split()))
n,m=i()
a=f.gcd(m,n)
p=i()
q=i()
b=len(p)
z=set()
for e in q : p.append(e)
for i in range(len(p)-2): z.add(p[i+1+min(1,(i+1)//b)]% a)
print(['No','Yes'][len(z)==a])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := i() ;
    var a : String := f.gcd(m, n) ;
    var p : OclAny := i() ;
    var q : OclAny := i() ;
    var b : int := (p)->size() ;
    var z : Set := Set{}->union(()) ;
    for e : q do (    execute ((e) : p)) ;
    for i : Integer.subrange(0, (p)->size() - 2-1) do (    execute ((p[i + 1 + Set{1, (i + 1) div b}->min()+1] mod a) : z)) ;
    execute (Sequence{'No'}->union(Sequence{ 'Yes' })->select((z)->size() = a))->display();
  operation i() : OclAny
  pre: true post: true
  activity:
    return ((input().split())->collect( _x | (OclType["int"])->apply(_x) ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
n,m=map(int,input().split())
happy=None
b=list(map(int,input().split()))
if b[0]:
    happy=b[1]
b=set(b[1 :])
g=list(map(int,input().split()))
if g[0]:
    happy=g[1]+n
b.update((x+n for x in g[1 :]))
d=math.gcd(n,m)
happy=set()
parent=list(range(n+m))
def find(x):
    while x!=parent[x]:
        parent[x]=parent[parent[x]]
        x=parent[x]
    return x
for i in range(n):
    boyhap=i in b
    if boyhap :
        happy.add(i)
    for j in range(i,n+m,d):
        z=find(j)
        parent[find(i)]=z
        if boyhap or j in b :
            happy.add(z)
    for j in range(i,-1,-d):
        z=find(j)
        parent[find(i)]=z
        if boyhap or j in b :
            happy.add(z)
if all(find(i)in happy for i in range(n+m)):
    print('Yes')
else :
    print('No')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var happy : OclAny := null ;
    var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if b->first() then (
      happy := b[1+1]
    ) else skip ;
    b := Set{}->union((b->tail())) ;
    var g : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if g->first() then (
      happy := g[1+1] + n
    ) else skip ;
    execute ((Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (name n))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))))))}) <: b) ;
    var d : long := (n)->gcd(m) ;
    happy := Set{}->union(()) ;
    var parent : Sequence := (Integer.subrange(0, n + m-1)) ;
    skip ;
    for i : Integer.subrange(0, n-1) do (    var boyhap : boolean := (b)->includes(i) ;
    if boyhap then (
      execute ((i) : happy)
    ) else skip ;
    for j : Integer.subrange(i, n + m-1)->select( $x | ($x - i) mod d = 0 ) do (    var z : OclAny := find(j) ;
    parent[find(i)+1] := z ;
    if boyhap or (b)->includes(j) then (
      execute ((z) : happy)
    ) else skip) ;
    for j : Integer.subrange(i, -1-1)->select( $x | ($x - i) mod -d = 0 ) do (    z := find(j) ;
    parent[find(i)+1] := z ;
    if boyhap or (b)->includes(j) then (
      execute ((z) : happy)
    ) else skip)) ;
    if ((argument (test (logical_test (comparison (comparison (expr (atom (name find)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) in (comparison (expr (atom (name happy))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (name m))))))))) )))))))))->forAll( _x | _x = true ) then  (
      execute ('Yes')->display()
    )
    else (
      execute ('No')->display()
      );
  operation find(x : OclAny) : OclAny
  pre: true post: true
  activity:
    while x /= parent[x+1] do (    parent[x+1] := parent[parent[x+1]+1] ;
    x := parent[x+1]) ;
    return x;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    n,m=map(int,input().split())
    boys=[0 for i in range(n)]
    girls=[0 for i in range(m)]
    for i in map(int,input().split()[1 :]):
        boys[i]=1
    for i in map(int,input().split()[1 :]):
        girls[i]=1
    for i in range(2*n*m+1):
        if boys[i % n]or girls[i % m]:
            boys[i % n]=1
            girls[i % m]=1
    if all(boys)and all(girls):
        print("YES")
    else :
        print("NO")
main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    main();
  operation main()
  pre: true post: true
  activity:
    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var boys : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ;
    var girls : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (0)) ;
    for i : (input().split()->tail())->collect( _x | (OclType["int"])->apply(_x) ) do (    boys[i+1] := 1) ;
    for i : (input().split()->tail())->collect( _x | (OclType["int"])->apply(_x) ) do (    girls[i+1] := 1) ;
    for i : Integer.subrange(0, 2 * n * m + 1-1) do (    if boys[i mod n+1] or girls[i mod m+1] then (
      boys[i mod n+1] := 1 ;
    girls[i mod m+1] := 1
    ) else skip) ;
    if (boys)->forAll( _x | _x = true ) & (girls)->forAll( _x | _x = true ) then  (
      execute ("YES")->display()
    )
    else (
      execute ("NO")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
while True :
    R,N=map(int,input().split())
    if not(R | N):
        break
    geta=20
    buildings=[0]*(geta*2)
    for _ in range(N):
        xl,xr,h=map(int,input().split())
        for i in range(xl+geta,xr+geta):
            buildings[i]=max(buildings[i],h)
    left,right=0,20
    for _ in range(100):
        mid=(left+right)/2
        flag=True
        for i in range(-R+geta,R+geta):
            if i=y-R+mid
            else :
                y=pow(R*R-(i-geta)*(i-geta),0.5)
                flag &=buildings[i]>=y-R+mid
        if flag :
            left=mid
        else :
            right=mid
    print("{:.20f}".format(left))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     while true do (    var R : OclAny := null;
    var N : OclAny := null;
    Sequence{R,N} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if not((MathLib.bitwiseOr(R, N))) then (
      break
    ) else skip ;
    var geta : int := 20 ;
    var buildings : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (geta * 2)) ;
    for _anon : Integer.subrange(0, N-1) do (    var xl : OclAny := null;
    var xr : OclAny := null;
    var h : OclAny := null;
    Sequence{xl,xr,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    for i : Integer.subrange(xl + geta, xr + geta-1) do (    buildings[i+1] := Set{buildings[i+1], h}->max())) ;
    var left : OclAny := null;
    var right : OclAny := null;
    Sequence{left,right} := Sequence{0,20} ;
    for _anon : Integer.subrange(0, 100-1) do (    var mid : double := (left + right) / 2 ;
    var flag : boolean := true ;
    for i : Integer.subrange(-R + geta, R + geta-1) do (    if (i->compareTo(geta)) < 0 then  (
      var y : double := (R * R - (i - geta + 1) * (i - geta + 1))->pow(0.5) ;
    flag := flag & (buildings[i+1]->compareTo(y - R + mid)) >= 0
    )
    else (
      y := (R * R - (i - geta) * (i - geta))->pow(0.5) ;
    flag := flag & (buildings[i+1]->compareTo(y - R + mid)) >= 0
      )) ;
    if flag then  (
      var left : OclAny := mid
    )
    else (
      var right : OclAny := mid
      )) ;
    execute (StringLib.interpolateStrings("{:.20f}", Sequence{left}))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
from sys import stdin
from operator import itemgetter
input=stdin.readline
def solve(data):
    data.sort(key=itemgetter(1))
    top2=data[: 2]
    others=data[2 :]
    return top2,others
def main(args):
    others_results=[]
    for _ in range(3):
        round_results=[]
        for _ in range(8):
            id,time=input().split()
            round_results.append([int(id),float(time)])
        top2,others=solve(round_results)
        others_results.extend(others)
        for id,time in top2 :
            print('{}{}'.format(id,time))
    top2,others=solve(others_results)
    for id,time in top2 :
        print('{}{}'.format(id,time))
if __name__=='__main__' :
    main(sys.argv[1 :])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    var input : OclAny := stdin.readline ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))
    ) else skip;
  operation solve(data : OclAny) : OclAny
  pre: true post: true
  activity:
    data := data->sort() ;
    var top2 : OclAny := data.subrange(1,2) ;
    var others : OclAny := data.subrange(2+1) ;
    return top2, others;
  operation main(args : OclAny)
  pre: true post: true
  activity:
    var others_results : Sequence := Sequence{} ;
    for _anon : Integer.subrange(0, 3-1) do (    var round_results : Sequence := Sequence{} ;
    for _anon : Integer.subrange(0, 8-1) do (    var id : OclAny := null;
    var time : OclAny := null;
    Sequence{id,time} := input().split() ;
    execute ((Sequence{("" + ((id)))->toInteger()}->union(Sequence{ ("" + ((time)))->toReal() })) : round_results)) ;
    Sequence{top2,others} := solve(round_results) ;
    others_results := others_results->union(others) ;
    for _tuple : top2 do (var _indx : int := 1;
      var id : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var time : OclAny := _tuple->at(_indx);
      execute (StringLib.interpolateStrings('{}{}', Sequence{id, time}))->display())) ;
    Sequence{top2,others} := solve(others_results) ;
    for _tuple : top2 do (var _indx : int := 1;
      var id : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var time : OclAny := _tuple->at(_indx);
      execute (StringLib.interpolateStrings('{}{}', Sequence{id, time}))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=input()
counter=0
left=0
zeros=0
for i in range(len(n)):
    if n[i]=='o' :
        zeros+=left
    elif n[i]=='v' and i>0 and n[i-1]=='v' :
        left+=1
        counter+=zeros
print(counter)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : String := (OclFile["System.in"]).readLine() ;
    var counter : int := 0 ;
    var left : int := 0 ;
    var zeros : int := 0 ;
    for i : Integer.subrange(0, (n)->size()-1) do (    if n[i+1] = 'o' then  (
      zeros := zeros + left
    )
    else (if n[i+1] = 'v' & i > 0 & n[i - 1+1] = 'v' then
   (
      left := left + 1 ;
    counter := counter + zeros    
)
 else skip)) ;
    execute (counter)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s=input()
c_v=[]
c_o=[]
start=s.find('vv')
if start==-1 :
    start=len(s)
counter_v=0
counter_o=0
for i in range(start+1,len(s)):
    if s[i]=='v' and s[i-1]=='v' :
        counter_v+=1
        if counter_o>0 :
            c_o.append(counter_o)
        counter_o=0
    elif s[i]=='o' :
        counter_o+=1
        if counter_v>0 :
            c_v.append(counter_v)
        counter_v=0
if counter_v>0 :
    c_v.append(counter_v)
ans=0
running_sum=0
running_prod=0
for i in range(len(c_v)-1,0,-1):
    running_sum+=c_v[i]
    running_prod+=c_o[i-1]*running_sum
    ans+=c_v[i-1]*running_prod
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : String := (OclFile["System.in"]).readLine() ;
    var c_v : Sequence := Sequence{} ;
    var c_o : Sequence := Sequence{} ;
    var start : int := s->indexOf('vv') - 1 ;
    if start = -1 then (
      start := (s)->size()
    ) else skip ;
    var counter_v : int := 0 ;
    var counter_o : int := 0 ;
    for i : Integer.subrange(start + 1, (s)->size()-1) do (    if s[i+1] = 'v' & s[i - 1+1] = 'v' then  (
      counter_v := counter_v + 1 ;
    if counter_o > 0 then (
      execute ((counter_o) : c_o)
    ) else skip ;
    counter_o := 0
    )
    else (if s[i+1] = 'o' then
   (
      counter_o := counter_o + 1 ;
    if counter_v > 0 then (
      execute ((counter_v) : c_v)
    ) else skip ;
    counter_v := 0    
)
 else skip)) ;
    if counter_v > 0 then (
      execute ((counter_v) : c_v)
    ) else skip ;
    var ans : int := 0 ;
    var running_sum : int := 0 ;
    var running_prod : int := 0 ;
    for i : Integer.subrange(0 + 1, (c_v)->size() - 1)->reverse() do (    running_sum := running_sum + c_v[i+1] ;
    running_prod := running_prod + c_o[i - 1+1] * running_sum ;
    ans := ans + c_v[i - 1+1] * running_prod) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def solution(s):
    w_counter=0
    mass=[]
    for i in range(1,len(s)):
        if s[i-1]=="v" and s[i]=="v" :
            w_counter+=1
        if s[i]=="o" and w_counter>0 :
            mass.append(w_counter)
    return w_counter,mass
def main():
    answer=0
    s=input()
    max_w,mass=solution(s)
    for elem in mass :
        answer+=elem*(max_w-elem)
    print(answer)
main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    main();
  operation solution(s : OclAny) : OclAny
  pre: true post: true
  activity:
    var w_counter : int := 0 ;
    var mass : Sequence := Sequence{} ;
    for i : Integer.subrange(1, (s)->size()-1) do (    if s[i - 1+1] = "v" & s[i+1] = "v" then (
      w_counter := w_counter + 1
    ) else skip ;
    if s[i+1] = "o" & w_counter > 0 then (
      execute ((w_counter) : mass)
    ) else skip) ;
    return w_counter, mass;
  operation main()
  pre: true post: true
  activity:
    var answer : int := 0 ;
    s := (OclFile["System.in"]).readLine() ;
    var max_w : OclAny := null;
    Sequence{max_w,mass} := solution(s) ;
    for elem : mass do (    answer := answer + elem * (max_w - elem)) ;
    execute (answer)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
s=list(map(str,input().split()))[0]
i=0
j=len(s)-1
cnt=0
left=[]
right=[]
while icollect( _x | (OclType["String"])->apply(_x) ))->first() ;
    var i : int := 0 ;
    var j : double := (s)->size() - 1 ;
    var cnt : int := 0 ;
    var left : Sequence := Sequence{} ;
    var right : Sequence := Sequence{} ;
    while (i->compareTo(j)) < 0 do (    if s[i+1] /= '(' then  (
      i := i + 1
    )
    else (if s[j+1] /= ')' then
   (
      j := j - 1    
)
    else (
      execute ((i + 1) : left) ;
    execute ((j + 1) : right) ;
    i := i + 1 ;
    j := j - 1
      )    )
) ;
    if left & right then  (
      right := right(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ;
    execute (1)->display() ;
    execute ((left)->size() + (right)->size())->display() ;
    execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name left))) + (expr (atom (name right)))))))) ))))))))->display()
    )
    else (
      execute (0)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
cont=0
aux=0
cont_aux=0
s=input()
aux2=0
for j in s :
    if j=='o' :
        aux+=cont
    elif cont_aux>=1 and s[cont_aux-1]=='v' :
        cont+=1
        aux2+=aux
    cont_aux+=1
print(aux2)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var cont : int := 0 ;
    var aux : int := 0 ;
    var cont_aux : int := 0 ;
    var s : String := (OclFile["System.in"]).readLine() ;
    var aux2 : int := 0 ;
    for j : s->characters() do (    if j = 'o' then  (
      aux := aux + cont
    )
    else (if cont_aux >= 1 & s[cont_aux - 1+1] = 'v' then
   (
      cont := cont + 1 ;
    aux2 := aux2 + aux    
)
 else skip) ;
    cont_aux := cont_aux + 1) ;
    execute (aux2)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import stdin,stdout
import sys
def get_ints(): return map(int,sys.stdin.readline().strip().split())
def get_arr(): return list(map(int,sys.stdin.readline().strip().split()))
def get_string(): return sys.stdin.readline().strip()
s=input()
n=len(s)
a=[]
for i in range(0,len(s)-1):
    if s[i]=='v' and s[i+1]=='v' :
        a.append(int(1))
    else :
        a.append(int(0))
if len(s)>=2 :
    if s[0]=='v' and s[1]=='v' :
        a[0]=1
for i in range(1,len(a)):
    a[i]+=a[i-1]
print('\n')
ans=0
for i in range(0,len(a)):
    if s[i]=='o' :
        ans+=(a[i]*(a[len(a)-1]-a[i]))
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var s : String := (OclFile["System.in"]).readLine() ;
    var n : int := (s)->size() ;
    var a : Sequence := Sequence{} ;
    for i : Integer.subrange(0, (s)->size() - 1-1) do (    if s[i+1] = 'v' & s[i + 1+1] = 'v' then  (
      execute ((("" + ((1)))->toInteger()) : a)
    )
    else (
      execute ((("" + ((0)))->toInteger()) : a)
      )) ;
    if (s)->size() >= 2 then (
      if s->first() = 'v' & s[1+1] = 'v' then (
      a->first() := 1
    ) else skip
    ) else skip ;
    for i : Integer.subrange(1, (a)->size()-1) do (    a[i+1] := a[i+1] + a[i - 1+1]) ;
    execute ('
')->display() ;
    var ans : int := 0 ;
    for i : Integer.subrange(0, (a)->size()-1) do (    if s[i+1] = 'o' then (
      ans := ans + (a[i+1] * (a[(a)->size() - 1+1] - a[i+1]))
    ) else skip) ;
    execute (ans)->display();
  operation get_ints() : OclAny
  pre: true post: true
  activity:
    return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) );
  operation get_arr() : OclAny
  pre: true post: true
  activity:
    return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ));
  operation get_string() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine()->trim();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
pages=[int(i)for i in input().split()]
sum=sum(pages)
rest=n % sum
if(rest==0):
    counter=0
    for i in range(0,len(pages)):
        if(counter+pages[i]==sum):
            print(i+1)
            break
        else :
            counter+=pages[i]
else :
    for i in range(0,len(pages)):
        if rest-pages[i]<=0 :
            print(i+1)
            break
        else : rest-=pages[i]
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var pages : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var sum : OclAny := (pages)->sum() ;
    var rest : int := n mod sum ;
    if (rest = 0) then  (
      var counter : int := 0 ;
    for i : Integer.subrange(0, (pages)->size()-1) do (    if (counter + pages[i+1] = sum) then  (
      execute (i + 1)->display() ;
    break
    )
    else (
      counter := counter + pages[i+1]
      ))
    )
    else (
      for i : Integer.subrange(0, (pages)->size()-1) do (    if rest - pages[i+1] <= 0 then  (
      execute (i + 1)->display() ;
    break
    )
    else (
      rest := rest - pages[i+1]
      ))
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
x=int(input())
l_n=list(map(int,input().split()))
n_s=sum(l_n)
while x>n_s :
    x-=n_s
while x>0 :
    for i in range(len(l_n)):
        if l_n[i]>=x :
            print(i+1)
            quit()
        x-=l_n[i]
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var l_n : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var n_s : OclAny := (l_n)->sum() ;
    while (x->compareTo(n_s)) > 0 do (    x := x - n_s) ;
    while x > 0 do (    for i : Integer.subrange(0, (l_n)->size()-1) do (    if (l_n[i+1]->compareTo(x)) >= 0 then (
      execute (i + 1)->display() ;
    quit()
    ) else skip ;
    x := x - l_n[i+1]));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
lst=list(map(int,input().split(' ')))
i,res=0,0
while(restoInteger() ;
    var lst : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ;
    var i : OclAny := null;
    var res : OclAny := null;
    Sequence{i,res} := Sequence{0,0} ;
    while ((res->compareTo(n)) < 0) do (    res := res + lst[i mod 7+1] ;
    i := i + 1) ;
    if i mod 7 = 0 then  (
      execute (7)->display()
    )
    else (
      execute (i mod 7)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
pages=[int(p)for p in input().split(" ",6)]
t=0
while True :
    if t>=n :
        break
    for i in range(0,7):
        t+=pages[i]
        if t>=n :
            print(i+1)
            break
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var pages : Sequence := input().split(" ", 6)->select(p | true)->collect(p | (("" + ((p)))->toInteger())) ;
    var t : int := 0 ;
    while true do (    if (t->compareTo(n)) >= 0 then (
      break
    ) else skip ;
    for i : Integer.subrange(0, 7-1) do (    t := t + pages[i+1] ;
    if (t->compareTo(n)) >= 0 then (
      execute (i + 1)->display() ;
    break
    ) else skip));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
hoketsu_1=[0,100]
hoketsu_2=[0,100]
for x in range(3):
    Time=[]
    for i in range(8):
        p,t=input().split()
        Time.append([p,t])
    Time.sort(key=lambda x : x[1])
    print(*Time[0])
    print(*Time[1])
    if float(Time[2][1])union(Sequence{ 100 }) ;
    var hoketsu:= Sequence{0}->union(Sequence{ 100 }) : Sequence := Sequence{0}->union(Sequence{ 100 }) ;
    for x : Integer.subrange(0, 3-1) do (    var Time : Sequence := Sequence{} ;
    for i : Integer.subrange(0, 8-1) do (    var p : OclAny := null;
    var t : OclAny := null;
    Sequence{p,t} := input().split() ;
    execute ((Sequence{p}->union(Sequence{ t })) : Time)) ;
    Time := Time->sort() ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name Time)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))))->display() ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name Time)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))))->display() ;
    if (("" + ((Time[2+1][1+1])))->toReal()->compareTo(("" + ((hoketsu    var Time : Sequence := Sequence{}[1+1])))->toReal())) < 0 then  (
      hoketsu:= hoketsu    var Time : Sequence := Sequence{} := hoketsu    var Time : Sequence := Sequence{} ;
    hoketsu    hoketsu:= hoketsu    var Time : Sequence := Sequence{} := hoketsu    var Time : Sequence := Sequence{} := Time[2+1]
    )
    else (if (("" + ((Time[2+1][1+1])))->toReal()->compareTo(("" + ((hoketsu    hoketsu:= Time[2+1] := Time[2+1][1+1])))->toReal())) < 0 then
   (
      hoketsu:= Time[2+1] := Time[2+1]    
)
 else skip) ;
    if (("" + ((Time[3+1][1+1])))->toReal()->compareTo(("" + ((hoketsu    hoketsu:= Time[3+1] := Time[3+1][1+1])))->toReal())) < 0 then (
      hoketsu:= Time[3+1] := Time[3+1]
    ) else skip) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name hoketsu(argument * (test (logical_test (comparison (expr (atom (name hoketsu((argument * (test (logical_test (comparison (expr (atom (name hoketsu((argument * (test (logical_test (comparison (expr (atom (name hoketsu((argument * (test (logical_test (comparison (expr (atom (name hoketsu(argument * (test (logical_test (comparison (expr (atom (name hoketsu((argument * (test (logical_test (comparison (expr (atom (name hoketsu((argument * (test (logical_test (comparison (expr (atom (name hoketsu((argument * (test (logical_test (comparison (expr (atom (name hoketsu(argument * (test (logical_test (comparison (expr (atom (name hoketsu((argument * (test (logical_test (comparison (expr (atom (name hoketsu((argument * (test (logical_test (comparison (expr (atom (name hoketsu((argument * (test (logical_test (comparison (expr (atom (name hoketsu(argument * (test (logical_test (comparison (expr (atom (name hoketsu((argument * (test (logical_test (comparison (expr (atom (name hoketsu((argument * (test (logical_test (comparison (expr (atom (name hoketsu((argument * (test (logical_test (comparison (expr (atom (name hoketsu(argument * (test (logical_test (comparison (expr (atom (name hoketsu((argument * (test (logical_test (comparison (expr (atom (name hoketsu((argument * (test (logical_test (comparison (expr (atom (name hoketsu((argument * (test (logical_test (comparison (expr (atom (name hoketsu(argument * (test (logical_test (comparison (expr (atom (name hoketsu((argument * (test (logical_test (comparison (expr (atom (name hoketsu((argument * (test (logical_test (comparison (expr (atom (name hoketsu((argument * (test (logical_test (comparison (expr (atom (name hoketsu(argument * (test (logical_test (comparison (expr (atom (name hoketsu((argument * (test (logical_test (comparison (expr (atom (name hoketsu((argument * (test (logical_test (comparison (expr (atom (name hoketsu    var hoketsu_1 : Sequence := Sequence{0}->union(Sequence{ 100 }))))))))))))))))))))))))))))))))->display())))))))))))))))))))))))))))))))->display())))))))))))))))))))))))))))))))->display())))))))))))))))))))))))))))))))->display())))))))))))))))))))))))))))))))->display())))))))))))))))))))))))))))))))->display())))))))))))))))))))))))))))))))->display() ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name hoketsu_2))))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b,i=int(input()),[int(i)for i in input().split()],-1
while a>0 :
    i+=1
    if i==7 :
        i=0
    a-=b[i]
print(i+1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    var i : OclAny := null;
    Sequence{a,b,i} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())),-1} ;
    while a > 0 do (    i := i + 1 ;
    if i = 7 then (
      var i : int := 0
    ) else skip ;
    a := a - b[i+1]) ;
    execute (i + 1)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def printArray(arr,size):
    for i in range(size):
        print(arr[i],end=" ")
    print()
    return
def getSuccessor(arr,k,n):
    p=k-1
    while(arr[p]==n and 0<=pdisplay()) ;
    execute (->display() ;
    return;
  operation getSuccessor(arr : OclAny, k : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var p : double := k - 1 ;
    while (arr[p+1] = n & 0 <= p & (p < k)) do (    p := p - 1) ;
    if (p < 0) then (
      return 0
    ) else skip ;
    arr[p+1] := arr[p+1] + 1 ;
    var i : OclAny := p + 1 ;
    while ((i->compareTo(k)) < 0) do (    arr[i+1] := 1 ;
    i := i + 1) ;
    return 1;
  operation printSequences(n : OclAny, k : OclAny)
  pre: true post: true
  activity:
    arr := MatrixLib.elementwiseMult(Sequence{ 0 }, k) ;
    for i : Integer.subrange(0, k-1) do (    arr[i+1] := 1) ;
    while (1) do (    printArray(arr, k) ;
    if (getSuccessor(arr, k, n) = 0) then (
      break
    ) else skip) ;
    return;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
class Solution(object):
    def findUnsortedSubarray(self,nums):
        stack=[]
        l,r=len(nums),0
        for i in range(len(nums)):
            while len(stack)!=0 and nums[stack[-1]]>nums[i]:
                l=min(l,stack.pop())
            stack.append(i)
        stack=[]
        for i in range(len(nums)-1,-1,-1):
            while len(stack)!=0 and nums[stack[-1]]l :
            return r-l+1
        return 0
------------------------------------------------------------
OCL File:
---------
class Solution extends object {
  static operation newSolution() : Solution
  pre: true
  post: Solution->exists( _x | result = _x );
  operation findUnsortedSubarray(nums : OclAny) : OclAny
  pre: true post: true
  activity:
    var stack : Sequence := Sequence{} ;
    var l : OclAny := null;
    var r : OclAny := null;
    Sequence{l,r} := Sequence{(nums)->size(),0} ;
    for i : Integer.subrange(0, (nums)->size()-1) do (    while (stack)->size() /= 0 & (nums[stack->last()+1]->compareTo(nums[i+1])) > 0 do (    var l : OclAny := Set{l, stack->last()}->min()) ;
    execute ((i) : stack)) ;
    stack := Sequence{} ;
    for i : Integer.subrange(-1 + 1, (nums)->size() - 1)->reverse() do (    while (stack)->size() /= 0 & (nums[stack->last()+1]->compareTo(nums[i+1])) < 0 do (    var r : OclAny := Set{r, stack->last()}->max()) ;
    execute ((i) : stack)) ;
    if (r->compareTo(l)) > 0 then (
      return r - l + 1
    ) else skip ;
    return 0;
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
class UnionFind():
    def __init__(self,n):
        self.par=[i for i in range(n+1)]
        self.rank=[0]*(n+1)
    def root(self,x):
        if self.par[x]==x :
            return x
        r=self.root(self.par[x])
        self.par[x]=r
        return r
    def same(self,x,y):
        return self.root(x)==self.root(y)
    def unite(self,x,y):
        rx=self.root(x)
        ry=self.root(y)
        if rx==ry :
            return
        if self.rank[rx]exists( _x | result = _x );
  attribute par : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (i));
  attribute rank : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1));
  operation initialise(n : OclAny) : 
  pre: true post: true
  activity:
    self.par := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (i)) ;
    self.rank := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1));
    return self;
  operation root(x : OclAny) : OclAny
  pre: true post: true
  activity:
    if self.par[x+1] = x then (
      return x
    ) else skip ;
    var r : OclAny := self.root(self.par[x+1]) ;
    self.par[x+1] := r ;
    return r;
  operation same(x : OclAny,y : OclAny) : OclAny
  pre: true post: true
  activity:
    return self.root(x) = self.root(y);
  operation unite(x : OclAny,y : OclAny)
  pre: true post: true
  activity:
    var rx : OclAny := self.root(x) ;
    var ry : OclAny := self.root(y) ;
    if rx = ry then (
      return
    ) else skip ;
    if (self.rank[rx+1]->compareTo(self.rank[ry+1])) < 0 then  (
      self.par[x+1] := ry ;
    self.par[rx+1] := ry
    )
    else (
      self.par[y+1] := rx ;
    self.par[ry+1] := rx ;
    if self.rank[rx+1] = self.rank[ry+1] then (
      self.rank[rx+1] := self.rank[rx+1] + 1
    ) else skip
      );
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var N : OclAny := null;
    var M : OclAny := null;
    var PXY : OclAny := null;
    Sequence{N,M,PXY} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var P : OclAny := PXY.subrange(1,N) ;
    var uf : UnionFind := (UnionFind.newUnionFind()).initialise(N + 1) ;
    for i : Integer.subrange(0, M-1) do (    Sequence{x,y} := Sequence{PXY[N + 2 * i + 0+1],PXY[N + 2 * i + 1+1]} ;
    uf.unite(x, y)) ;
    var ans : int := 0 ;
    for i : Integer.subrange(0, N-1) do (    var is_same : OclAny := uf.same(i + 1, P[i+1]) ;
    if is_same then (
      ans := ans + 1
    ) else skip) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
s=input()[:-1]
i,j=0,len(s)-1
c=0
a=[-1]
b=[-1]
while ifront() ;
    var i : OclAny := null;
    var j : OclAny := null;
    Sequence{i,j} := Sequence{0,(s)->size() - 1} ;
    var c : int := 0 ;
    var a : Sequence := Sequence{ -1 } ;
    var b : Sequence := Sequence{ -1 } ;
    while (i->compareTo(j)) < 0 do (    if s[i+1] = '(' then (
      if i + 1 /= a->last() then (
      c := c + 1 ;
    execute ((i + 1) : a)
    ) else skip
    ) else skip ;
    if s[j+1] = ')' then (
      if j + 1 /= b->last() then (
      c := c - 1 ;
    execute ((j + 1) : b)
    ) else skip
    ) else skip ;
    if c < 0 then  (
      i := i + 1
    )
    else (
      j := j - 1
      )) ;
    c := Set{(a)->size(), (b)->size()}->min() ;
    var x : double := 2 * c - 2 ;
    if x = 0 then  (
      execute (0)->display()
    )
    else (
      execute (1)->display() ;
    execute (x)->display() ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (test (logical_test (comparison (expr (atom (name c)))))))) ]))))))))->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
P=[int(p)-1 for p in input().split()]
GRAPH=[[]for _ in range(n)]
for _ in range(m):
    x,y=[int(xy)-1 for xy in input().split()]
    GRAPH[x].append(y); GRAPH[y].append(x)
def dfs(now):
    searched[now]=True
    p=P[now]
    A[now]=B[p]=color
    for next in GRAPH[now]:
        if searched[next]:
            continue
        dfs(next)
A=[0]*n ; B=[0]*n
searched=[False]*n
color=1
for i in range(n):
    if searched[i]:
        continue
    dfs(i)
    color+=1
ans=sum(A[i]==B[i]for i in range(n))
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    sys.setrecursionlimit((10)->pow(9)) ;
    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var P : Sequence := input().split()->select(p | true)->collect(p | (("" + ((p)))->toInteger() - 1)) ;
    var GRAPH : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ;
    for _anon : Integer.subrange(0, m-1) do (    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := input().split()->select(xy | true)->collect(xy | (("" + ((xy)))->toInteger() - 1)) ;
(expr (atom (name GRAPH)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) ))));(expr (atom (name GRAPH)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))) ;
    skip ;
    var A : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n);    var B : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ;
    var searched : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ;
    var color : int := 1 ;
    for i : Integer.subrange(0, n-1) do (    if searched[i+1] then (
      continue
    ) else skip ;
    dfs(i) ;
    color := color + 1) ;
    var ans : OclAny := ((argument (test (logical_test (comparison (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (name B)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->sum() ;
    execute (ans)->display();
  operation dfs(now : OclAny)
  pre: true post: true
  activity:
    searched[now+1] := true ;
    var p : OclAny := P[now+1] ;
    A[now+1] := color; var B[p+1] : OclAny := color ;
    for next : GRAPH[now+1] do (    if searched[next+1] then (
      continue
    ) else skip ;
    dfs(next));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
sys.setrecursionlimit(2*10**5)
N,M=map(int,input().split())
p=[0]+list(map(int,input().split()))
x,y=zip(*(map(int,input().split())for _ in range(M)))
E=[[]for _ in range(N+1)]
for a,b in zip(x,y):
    E[a].append(b)
    E[b].append(a)
v=[True for _ in range(N+1)]
def f(i,P,Q):
    v[i]=False
    P.add(i)
    Q.add(p[i])
    for a in E[i]:
        if v[a]:
            f(a,P,Q)
ans=0
for i in range(1,N+1):
    if v[i]:
        P=set()
        Q=set()
        f(i,P,Q)
        ans+=len(P & Q)
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    sys.setrecursionlimit(2 * (10)->pow(5)) ;
    var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var p : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ;
    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name M)))))))) )))))))) )))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name M)))))))) )))))))) )))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name M)))))))) )))))))) )))))))`third->at(_indx)} ) ;
    var E : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ;
    for _tuple : Integer.subrange(1, x->size())->collect( _indx | Sequence{x->at(_indx), y->at(_indx)} ) do (var _indx : int := 1;
      var a : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var b : OclAny := _tuple->at(_indx);
  (expr (atom (name E)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ;
(expr (atom (name E)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ;
    var v : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (true)) ;
    skip ;
    var ans : int := 0 ;
    for i : Integer.subrange(1, N + 1-1) do (    if v[i+1] then (
      P := Set{}->union(()) ;
    Q := Set{}->union(()) ;
    f(i, P, Q) ;
    ans := ans + (MathLib.bitwiseAnd(P, Q))->size()
    ) else skip) ;
    execute (ans)->display();
  operation f(i : OclAny, P : OclAny, Q : OclAny)
  pre: true post: true
  activity:
    v[i+1] := false ;
    execute ((i) : P) ;
    execute ((p[i+1]) : Q) ;
    for a : E[i+1] do (    if v[a+1] then (
      f(a, P, Q)
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m=map(int,input().split())
p=[int(i)for i in input().split()]
graph=[[]for _ in range(n+1)]
group=[0]*(n+1)
ans=0
for _ in range(m):
    x,y=map(int,input().split())
    graph[x].append(y)
    graph[y].append(x)
for i,num in enumerate(p,1):
    space=[i]
    for point in space :
        if group[point]:
            continue
        group[point]=i
        space.extend(graph[point])
    ans+=group[num]==group[i]
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var p : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var graph : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ;
    var group : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ;
    var ans : int := 0 ;
    for _anon : Integer.subrange(0, m-1) do (    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
(expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))) ;
(expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))) ;
    for _tuple : Integer.subrange(1, (p, 1)->size())->collect( _indx | Sequence{_indx-1, (p, 1)->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var num : OclAny := _tuple->at(_indx);
      var space : Sequence := Sequence{ i } ;
    for point : space do (    if group[point+1] then (
      continue
    ) else skip ;
    group[point+1] := i ;
    space := space->union(graph[point+1])) ;
    ans := ans + group[num+1] = group[i+1]) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.root=[-1]*n
    def FindRoot(self,x):
        if self.root[x]<0 :
            return x
        else :
            self.root[x]=self.FindRoot(self.root[x])
            return self.root[x]
    def Unite(self,x,y):
        x=self.FindRoot(x)
        y=self.FindRoot(y)
        if x==y :
            return False
        if self.Size(x)exists( _x | result = _x );
  attribute n : OclAny := n;
  attribute root : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n);
  operation initialise(n : OclAny) : 
  pre: true post: true
  activity:
    self.n := n ;
    self.root := MatrixLib.elementwiseMult(Sequence{ -1 }, n);
    return self;
  operation FindRoot(x : OclAny) : OclAny
  pre: true post: true
  activity:
    if self.root[x+1] < 0 then  (
      return x
    )
    else (
      self.root[x+1] := self.FindRoot(self.root[x+1]) ;
    return self.root[x+1]
      );
  operation Unite(x : OclAny,y : OclAny) : OclAny
  pre: true post: true
  activity:
    x := self.FindRoot(x) ;
    y := self.FindRoot(y) ;
    if x = y then (
      return false
    ) else skip ;
    if (self.Size(x)->compareTo(self.Size(y))) < 0 then (
      Sequence{x,y} := Sequence{y,x}
    ) else skip ;
    self.root[x+1] := self.root[x+1] + self.root[y+1] ;
    self.root[y+1] := x ;
    return true;
  operation isSameGroup(x : OclAny,y : OclAny) : OclAny
  pre: true post: true
  activity:
    return self.FindRoot(x) = self.FindRoot(y);
  operation Size(x : OclAny) : OclAny
  pre: true post: true
  activity:
    return -self.root[self.FindRoot(x)+1];
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var Uni : UnionFind := (UnionFind.newUnionFind()).initialise(N) ;
    for _anon : Integer.subrange(0, M-1) do (    Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    x := x - 1;    y := y - 1 ;
    Uni.Unite(x, y)) ;
    var a : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ;
    for i : Integer.subrange(0, N-1) do (    var r : OclAny := Uni.FindRoot(i) ;
(expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ;
    var ans : int := 0 ;
    for i : Integer.subrange(0, N-1) do (    for j : a[i+1] do (    if (a[i+1])->includes(p[j+1] - 1) then (
      ans := ans + 1
    ) else skip)) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def compute():
    LIMIT=10**6
    solutions=[0]*LIMIT
    for m in range(1,LIMIT*2):
        for k in range(m//5+1,(m+1)//2):
            temp=(m-k)*(k*5-m)
            if temp>=LIMIT :
                break
            solutions[temp]+=1
    ans=solutions.count(10)
    return str(ans)
if __name__=="__main__" :
    print(compute())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      execute (compute())->display()
    ) else skip;
  operation compute() : OclAny
  pre: true post: true
  activity:
    var LIMIT : double := (10)->pow(6) ;
    var solutions : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, LIMIT) ;
    for m : Integer.subrange(1, LIMIT * 2-1) do (    for k : Integer.subrange(m div 5 + 1, (m + 1) div 2-1) do (    var temp : double := (m - k) * (k * 5 - m) ;
    if (temp->compareTo(LIMIT)) >= 0 then (
      break
    ) else skip ;
    solutions[temp+1] := solutions[temp+1] + 1)) ;
    var ans : int := solutions->count(10) ;
    return ("" + ((ans)));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
ans=[0]*8
group=[]
re=[]
for i in range(8):
    p,t=map(float,input().split())
    group.append([t,int(p)])
group.sort()
ans[0]=group.pop(0)
ans[1]=group.pop(0)
re.append(group.pop(0))
re.append(group.pop(0))
for i in range(8):
    p,t=map(float,input().split())
    group.append([t,int(p)])
group.sort()
ans[2]=group.pop(0)
ans[3]=group.pop(0)
re.append(group.pop(0))
re.append(group.pop(0))
for i in range(8):
    p,t=map(float,input().split())
    group.append([t,int(p)])
group.sort()
ans[4]=group.pop(0)
ans[5]=group.pop(0)
re.append(group.pop(0))
re.append(group.pop(0))
re.sort()
ans[6]=re.pop(0)
ans[7]=re.pop(0)
for i in ans :
    print(i[1],i[0])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 8) ;
    var group : Sequence := Sequence{} ;
    var re : Sequence := Sequence{} ;
    for i : Integer.subrange(0, 8-1) do (    var p : OclAny := null;
    var t : OclAny := null;
    Sequence{p,t} := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ;
    execute ((Sequence{t}->union(Sequence{ ("" + ((p)))->toInteger() })) : group)) ;
    group := group->sort() ;
    ans->first() := group->at(0`firstArg+1) ;     group := group->excludingAt(0+1) ;
    ans[1+1] := group->at(0`firstArg+1) ;     group := group->excludingAt(0+1) ;
    execute ((group->at(0`firstArg+1)) : re) ;
    execute ((group->at(0`firstArg+1)) : re) ;
    for i : Integer.subrange(0, 8-1) do (    var p : OclAny := null;
    var t : OclAny := null;
    Sequence{p,t} := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ;
    execute ((Sequence{t}->union(Sequence{ ("" + ((p)))->toInteger() })) : group)) ;
    group := group->sort() ;
    ans[2+1] := group->at(0`firstArg+1) ;     group := group->excludingAt(0+1) ;
    ans[3+1] := group->at(0`firstArg+1) ;     group := group->excludingAt(0+1) ;
    execute ((group->at(0`firstArg+1)) : re) ;
    execute ((group->at(0`firstArg+1)) : re) ;
    for i : Integer.subrange(0, 8-1) do (    var p : OclAny := null;
    var t : OclAny := null;
    Sequence{p,t} := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ;
    execute ((Sequence{t}->union(Sequence{ ("" + ((p)))->toInteger() })) : group)) ;
    group := group->sort() ;
    ans[4+1] := group->at(0`firstArg+1) ;     group := group->excludingAt(0+1) ;
    ans[5+1] := group->at(0`firstArg+1) ;     group := group->excludingAt(0+1) ;
    execute ((group->at(0`firstArg+1)) : re) ;
    execute ((group->at(0`firstArg+1)) : re) ;
    re := re->sort() ;
    ans[6+1] :=  ;     re := re->excludingAt(0+1) ;
    ans[7+1] :=  ;     re := re->excludingAt(0+1) ;
    for i : ans do (    execute (i[1+1])->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def countChanges(arr,n):
    s=[]
    for i in range(n):
        s.append(arr[i])
    count=0
    for i in range(1,n+1):
        if i not in s :
            count+=1
    return count
if __name__=="__main__" :
    arr=[8,55,22,1,3,22,4,5]
    n=len(arr)
    print(countChanges(arr,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      arr := Sequence{8}->union(Sequence{55}->union(Sequence{22}->union(Sequence{1}->union(Sequence{3}->union(Sequence{22}->union(Sequence{4}->union(Sequence{ 5 }))))))) ;
    n := (arr)->size() ;
    execute (countChanges(arr, n))->display()
    ) else skip;
  operation countChanges(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var s : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    execute ((arr[i+1]) : s)) ;
    var count : int := 0 ;
    for i : Integer.subrange(1, n + 1-1) do (    if (s)->excludes(i) then (
      count := count + 1
    ) else skip) ;
    return count;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import sqrt
def Prime(n):
    if(n<2):
        return False ;
    for i in range(2,int(sqrt(n))+1):
        if(n % i==0):
            return False ;
    return True ;
def primeCountDivisors(n):
    if(n<2):
        return False ;
    for i in range(2,int(sqrt(n))+1):
        if(n % i==0):
            a=n ; c=0 ;
            while(a % i==0):
                a//=i ;
                c+=1 ;
            if(a==1 and Prime(c+1)):
                return True ;
            else :
                return False ;
    return True ;
if __name__=="__main__" :
    n=13 ;
    if(primeCountDivisors(n)):
        print("Yes");
    else :
        print("No");
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      n := 13; ;
    if (primeCountDivisors(n)) then  (
      execute ("Yes")->display();
    )
    else (
      execute ("No")->display();
      )
    ) else skip;
  operation Prime(n : OclAny)
  pre: true post: true
  activity:
    if (n < 2) then (
      return false;
    ) else skip ;
    for i : Integer.subrange(2, ("" + ((sqrt(n))))->toInteger() + 1-1) do (    if (n mod i = 0) then (
      return false;
    ) else skip) ;
    return true;;
  operation primeCountDivisors(n : OclAny)
  pre: true post: true
  activity:
    if (n < 2) then (
      return false;
    ) else skip ;
    for i : Integer.subrange(2, ("" + ((sqrt(n))))->toInteger() + 1-1) do (    if (n mod i = 0) then (
      var a : OclAny := n;    var c : int := 0; ;
    while (a mod i = 0) do (    a := a div i; ;
    c := c + 1;) ;
    if (a = 1 & Prime(c + 1)) then  (
      return true;
    )
    else (
      return false;
      )
    ) else skip) ;
    return true;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import maxsize
def sameCharAdj(string):
    n=len(string)
    st=set()
    st.add(string[0])
    for i in range(1,n):
        if string[i]==string[i-1]:
            continue
        if string[i]in st :
            return False
        st.add(string[i])
    return True
def minSwaps(string,l,r,cnt,minm):
    if l==r :
        if sameCharAdj(string):
            return cnt
        else :
            return maxsize
    for i in range(l+1,r+1,1):
        string[i],string[l]=string[l],string[i]
        cnt+=1
        x=minSwaps(string,l+1,r,cnt,minm)
        string[i],string[l]=string[l],string[i]
        cnt-=1
        y=minSwaps(string,l+1,r,cnt,minm)
        minm=min(minm,min(x,y))
    return minm
if __name__=="__main__" :
    string="abbaacb"
    string=list(string)
    n=len(string)
    cnt=0
    minm=maxsize
    print(minSwaps(string,0,n-1,cnt,minm))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      string := "abbaacb" ;
    string := (string)->characters() ;
    n := (string)->size() ;
    cnt := 0 ;
    minm := maxsize ;
    execute (minSwaps(string, 0, n - 1, cnt, minm))->display()
    ) else skip;
  operation sameCharAdj(string : OclAny) : OclAny
  pre: true post: true
  activity:
    var n : int := (string)->size() ;
    var st : Set := Set{}->union(()) ;
    execute ((string->first()) : st) ;
    for i : Integer.subrange(1, n-1) do (    if string[i+1] = string[i - 1+1] then (
      continue
    ) else skip ;
    if (st)->includes(string[i+1]) then (
      return false
    ) else skip ;
    execute ((string[i+1]) : st)) ;
    return true;
  operation minSwaps(string : OclAny, l : OclAny, r : OclAny, cnt : OclAny, minm : OclAny) : OclAny
  pre: true post: true
  activity:
    if l = r then (
      if sameCharAdj(string) then  (
      return cnt
    )
    else (
      return maxsize
      )
    ) else skip ;
    for i : Integer.subrange(l + 1, r + 1-1)->select( $x | ($x - l + 1) mod 1 = 0 ) do (    var string[i+1] : OclAny := null;
    var string[l+1] : OclAny := null;
    Sequence{string[i+1],string[l+1]} := Sequence{string[l+1],string[i+1]} ;
    cnt := cnt + 1 ;
    var x : OclAny := minSwaps(string, l + 1, r, cnt, minm) ;
    var string[i+1] : OclAny := null;
    var string[l+1] : OclAny := null;
    Sequence{string[i+1],string[l+1]} := Sequence{string[l+1],string[i+1]} ;
    cnt := cnt - 1 ;
    var y : OclAny := minSwaps(string, l + 1, r, cnt, minm) ;
    minm := Set{minm, Set{x, y}->min()}->min()) ;
    return minm;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from fractions import gcd
from functools import reduce
from sys import stdin
def lcm_base(x,y):
    return(x*y)//gcd(x,y)
def lcm(*numbers):
    return reduce(lcm_base,numbers,1)
def lcm_list(numbers):
    return reduce(lcm_base,numbers,1)
while(True):
    n=int(stdin.readline())
    if not n : break
    s=[list(map(int,stdin.readline().split()))for _ in range(n)]
    lcmde=lcm_list([r[1]for r in s])
    lcmnu=lcm_list([r[0]*lcmde//r[1]for r in s])
    print("\n".join(str(lcmnu*r[1]//lcmde//r[0])for r in s))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    while (true) do (    var n : int := ("" + ((stdin.readLine())))->toInteger() ;
    if not(n) then (
      break
    ) else skip ;
    var s : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var lcmde : OclAny := lcm_list(s->select(r | true)->collect(r | (r[1+1]))) ;
    var lcmnu : OclAny := lcm_list(s->select(r | true)->collect(r | (r->first() * lcmde div r[1+1]))) ;
    execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (expr (atom (name lcmnu))) * (expr (atom (name r)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) // (expr (atom (name lcmde)))) // (expr (atom (name r)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))))) ))))))) (comp_for for (exprlist (expr (atom (name r)))) in (logical_test (comparison (expr (atom (name s)))))))), "\n"))->display());
  operation lcm_base(x : OclAny, y : OclAny) : OclAny
  pre: true post: true
  activity:
    return (x * y) div gcd(x, y);
  operation lcm(numbers : OclAny : Sequence(OclAny)) : OclAny
  pre: true post: true
  activity:
(args * (named_parameter (name numbers)))    return reduce(lcm_base, numbers, 1);
  operation lcm_list(numbers : OclAny) : OclAny
  pre: true post: true
  activity:
    return reduce(lcm_base, numbers, 1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
from math import gcd
from functools import reduce
def solve(n,data):
    res=[]
    for i in range(n):
        t=1
        for j in range(n):
            t*=(data[j][0],data[j][1])[i==j]
        res.append(t)
    g=reduce(gcd,res)
    return[r//g for r in res]
def main(args):
    while True :
        n=int(input())
        if n==0 :
            break
        data=[[int(i)for i in input().split()]for _ in range(n)]
        ans=solve(n,data)
        print(*ans,sep='\n')
if __name__=='__main__' :
    main(sys.argv[1 :])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))
    ) else skip;
  operation solve(n : OclAny, data : OclAny) : OclAny
  pre: true post: true
  activity:
    var res : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    var t : int := 1 ;
    for j : Integer.subrange(0, n-1) do (    t := t * Sequence{data[j+1]->first(), data[j+1][1+1]}->select(i = j)) ;
    execute ((t) : res)) ;
    var g : OclAny := reduce(gcd, res) ;
    return res->select(r | true)->collect(r | (r div g));
  operation main(args : OclAny)
  pre: true post: true
  activity:
    while true do (    n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    data := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())))) ;
    var ans : OclAny := solve(n, data) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import stdin
input=stdin.readline
inp=lambda : list(map(int,input().split()))
def answer():
    ans=[]
    j=n-1
    for i in range(n):
        if(a[i]=='('):
            while(j>i and a[j]=='('):
                j-=1
            if(j==i): break
            ans.append(i+1)
            ans.append(j+1)
            j-=1
        if(i==j): break
    if(len(ans)==0):
        print(0)
        return
    ans.sort()
    print(1)
    print(len(ans))
    print(*ans)
for T in range(1):
    a=input().strip()
    n=len(a)
    answer()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := stdin.readline ;
    var inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ;
    skip ;
    for T : Integer.subrange(0, 1-1) do (    var a : OclAny := input()->trim() ;
    var n : int := (a)->size() ;
    answer());
  operation answer()
  pre: true post: true
  activity:
    var ans : Sequence := Sequence{} ;
    var j : double := n - 1 ;
    for i : Integer.subrange(0, n-1) do (    if (a[i+1] = '(') then (
      while ((j->compareTo(i)) > 0 & a[j+1] = '(') do (    j := j - 1) ;
    if (j = i) then (
      break
    ) else skip ;
    execute ((i + 1) : ans) ;
    execute ((j + 1) : ans) ;
    j := j - 1
    ) else skip ;
    if (i = j) then (
      break
    ) else skip) ;
    if ((ans)->size() = 0) then (
      execute (0)->display() ;
    return
    ) else skip ;
    ans := ans->sort() ;
    execute (1)->display() ;
    execute ((ans)->size())->display() ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def lcm(a,b):
    return a//gcd(a,b)*b
def gcd(a,b):
    while b!=0 :
        r=a % b
        a,b=b,r
    return a
def ngcd(n,a):
    if n==1 : return a[0]
    g=gcd(a[0],a[1]);
    for i in range(2,n):
        if g==1 : break
        g=gcd(g,a[i])
    return g ;
def nlcm(n,a):
    if n==1 : return a[0];
    g=gcd(a[0],a[1]);
    c=a[0]//g*a[1]
    for i in range(2,n):
        g=gcd(c,a[i])
        c=c//g*a[i]
    return c
while True :
    n=int(input())
    if n==0 : break
    d,v=[],[]
    for i in range(n):
        a,b=map(int,input().split())
        g=gcd(a,b)
        a//=g
        b//=g
        d.append(a)
        v.append(b)
    g=nlcm(n,d);
    for i in range(n): d[i]=(g//d[i])*v[i]
    g=ngcd(n,d)
    for i in range(n): print(d[i]//g)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    while true do (    n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    var d : OclAny := null;
    var v : OclAny := null;
    Sequence{d,v} := Sequence{Sequence{},Sequence{}} ;
    for i : Integer.subrange(0, n-1) do (    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    g := gcd(a, b) ;
    a := a div g ;
    b := b div g ;
    execute ((a) : d) ;
    execute ((b) : v)) ;
    g := nlcm(n, d); ;
    for i : Integer.subrange(0, n-1) do (    d[i+1] := (g div d[i+1]) * v[i+1]) ;
    g := ngcd(n, d) ;
    for i : Integer.subrange(0, n-1) do (    execute (d[i+1] div g)->display()));
  operation lcm(a : OclAny, b : OclAny) : OclAny
  pre: true post: true
  activity:
    return a div gcd(a, b) * b;
  operation gcd(a : OclAny, b : OclAny) : OclAny
  pre: true post: true
  activity:
    while b /= 0 do (    var r : int := a mod b ;
    Sequence{a,b} := Sequence{b,r}) ;
    return a;
  operation ngcd(n : OclAny, a : OclAny) : OclAny
  pre: true post: true
  activity:
    if n = 1 then (
      return a->first()
    ) else skip ;
    var g : OclAny := gcd(a->first(), a[1+1]); ;
    for i : Integer.subrange(2, n-1) do (    if g = 1 then (
      break
    ) else skip ;
    g := gcd(g, a[i+1])) ;
    return g;;
  operation nlcm(n : OclAny, a : OclAny) : OclAny
  pre: true post: true
  activity:
    if n = 1 then (
      return a->first();
    ) else skip ;
    g := gcd(a->first(), a[1+1]); ;
    var c : double := a->first() div g * a[1+1] ;
    for i : Integer.subrange(2, n-1) do (    g := gcd(c, a[i+1]) ;
    c := c div g * a[i+1]) ;
    return c;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**7)
def gcd(a,b):
    if b==0 :
        return a
    else :
        return gcd(b,a % b)
def lcm(a,b):
    return(a//gcd(a,b))*b
while True :
    n=int(input())
    if n==0 :
        break
    students=[0]*n
    v_lcm=1
    for i in range(n):
        students[i]=list(map(int,input().split()))
        v_lcm=lcm(v_lcm,students[i][1])
    mul_lcm=1
    for i in range(n):
        mul_lcm=lcm(mul_lcm,(v_lcm//students[i][1])*students[i][0])
    for i in range(n):
        print(mul_lcm//(v_lcm//students[i][1])//students[i][0])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    sys.setrecursionlimit((10)->pow(7)) ;
    skip ;
    skip ;
    while true do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    var students : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ;
    var v_lcm : int := 1 ;
    for i : Integer.subrange(0, n-1) do (    students[i+1] := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    v_lcm := lcm(v_lcm, students[i+1][1+1])) ;
    var mul_lcm : int := 1 ;
    for i : Integer.subrange(0, n-1) do (    mul_lcm := lcm(mul_lcm, (v_lcm div students[i+1][1+1]) * students[i+1]->first())) ;
    for i : Integer.subrange(0, n-1) do (    execute (mul_lcm div (v_lcm div students[i+1][1+1]) div students[i+1]->first())->display()));
  operation gcd(a : OclAny, b : OclAny) : OclAny
  pre: true post: true
  activity:
    if b = 0 then  (
      return a
    )
    else (
      return gcd(b, a mod b)
      );
  operation lcm(a : OclAny, b : OclAny) : OclAny
  pre: true post: true
  activity:
    return (a div gcd(a, b)) * b;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def gcd(m,n):
    r=m % n
    return gcd(n,r)if r else n
def lcm(m,n):
    return m//gcd(m,n)*n
while 1 :
    N=int(input())
    if N==0 :
        break
    X=[]
    D=[]; V=[]
    for i in range(N):
        d,v=map(int,input().split())
        g=gcd(d,v)
        d//=g ; v//=g
        D.append(d); V.append(v)
    vg=V[0]
    for v in V :
        vg=gcd(vg,v)
    dl=1
    for d in D :
        dl=lcm(dl,d)
    for d,v in zip(D,V):
        print(v//vg*dl//d)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    while 1 do (    var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if N = 0 then (
      break
    ) else skip ;
    var X : Sequence := Sequence{} ;
    var D : Sequence := Sequence{};    var V : Sequence := Sequence{} ;
    for i : Integer.subrange(0, N-1) do (    var d : OclAny := null;
    var v : OclAny := null;
    Sequence{d,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var g : OclAny := gcd(d, v) ;
    d := d div g;    v := v div g ;
    execute ((d) : D);    execute ((v) : V)) ;
    var vg : OclAny := V->first() ;
    for v : V do (    vg := gcd(vg, v)) ;
    var dl : int := 1 ;
    for d : D do (    dl := lcm(dl, d)) ;
    for _tuple : Integer.subrange(1, D->size())->collect( _indx | Sequence{D->at(_indx), V->at(_indx)} ) do (var _indx : int := 1;
      var d : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var v : OclAny := _tuple->at(_indx);
      execute (v div vg * dl div d)->display()));
  operation gcd(m : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var r : int := m mod n ;
    return if r then gcd(n, r) else n endif;
  operation lcm(m : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    return m div gcd(m, n) * n;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import*
def previousFibonacci(n):
    a=n/((1+sqrt(5))/2.0)
    return round(a)
n=8
print(previousFibonacci(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    n := 8 ;
    execute (previousFibonacci(n))->display();
  operation previousFibonacci(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var a : double := n / ((1 + sqrt(5)) / 2.0) ;
    return (a)->round();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
sticks=list(map(int,input().split(' ')))
sticks.sort()
y=sum(sticks[: int(n/2)])
x=sum(sticks[int(n/2):])
print(y*y+x*x)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var sticks : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ;
    sticks := sticks->sort() ;
    var y : OclAny := (sticks.subrange(1,("" + ((n / 2)))->toInteger()))->sum() ;
    var x : OclAny := (sticks.subrange(("" + ((n / 2)))->toInteger()+1))->sum() ;
    execute (y * y + x * x)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def printIndex(str,s):
    flag=False ;
    for i in range(len(str)):
        if(str[i : i+len(s)]==s):
            print(i,end=" ");
            flag=True ;
    if(flag==False):
        print("NONE");
str1="GeeksforGeeks" ;
str2="Geeks" ;
printIndex(str1,str2);
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var str1 : String := "GeeksforGeeks"; ;
    var str2 : String := "Geeks"; ;
    printIndex(str1, str2);;
  operation printIndex(OclType["String"] : OclAny, s : OclAny)
  pre: true post: true
  activity:
    var flag : boolean := false; ;
    for i : Integer.subrange(0, (OclType["String"])->size()-1) do (    if (("" + (.subrange(i+1, i + (s)->size()))) = s) then (
      execute (i)->display(); ;
    flag := true;
    ) else skip) ;
    if (flag = false) then (
      execute ("NONE")->display();
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
mod=1000000007
dp=[[-1 for i in range(1000)]for j in range(1000)];
def calculate(pos,prev,s,index):
    if(pos==len(s)):
        return 1
    if(dp[pos][prev]!=-1):
        return dp[pos][prev]
    c=ord(s[pos])-ord('a');
    answer=0
    for i in range(len(index)):
        if(index[i]>prev):
            answer=(answer % mod+calculate(pos+1,index[i],s,index)% mod)% mod
    dp[pos][prev]=4
    return dp[pos][prev]
def countWays(a,s):
    n=len(a)
    index=[[]for i in range(26)]
    for i in range(n):
        for j in range(len(a[i])):
            index[ord(a[i][j])-ord('a')].append(j+1);
    return calculate(0,0,s,index[0])
if __name__=='__main__' :
    A=[]
    A.append("adc")
    A.append("aec")
    A.append("erg")
    S="ac"
    print(countWays(A,S))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var mod : int := 1000000007 ;
    var dp : Sequence := Integer.subrange(0, 1000-1)->select(j | true)->collect(j | (Integer.subrange(0, 1000-1)->select(i | true)->collect(i | (-1)))); ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      var A : Sequence := Sequence{} ;
    execute (("adc") : A) ;
    execute (("aec") : A) ;
    execute (("erg") : A) ;
    var S : String := "ac" ;
    execute (countWays(A, S))->display()
    ) else skip;
  operation calculate(pos : OclAny, prev : OclAny, s : OclAny, index : OclAny) : OclAny
  pre: true post: true
  activity:
    if (pos = (s)->size()) then (
      return 1
    ) else skip ;
    if (dp[pos+1][prev+1] /= -1) then (
      return dp[pos+1][prev+1]
    ) else skip ;
    var c : double := (s[pos+1])->char2byte() - ('a')->char2byte(); ;
    var answer : int := 0 ;
    for i : Integer.subrange(0, (index)->size()-1) do (    if ((index[i+1]->compareTo(prev)) > 0) then (
      answer := (answer mod mod + calculate(pos + 1, index[i+1], s, index) mod mod) mod mod
    ) else skip) ;
    dp[pos+1][prev+1] := 4 ;
    return dp[pos+1][prev+1];
  operation countWays(a : OclAny, s : OclAny) : OclAny
  pre: true post: true
  activity:
    var n : int := (a)->size() ;
    index := Integer.subrange(0, 26-1)->select(i | true)->collect(i | (Sequence{})) ;
    for i : Integer.subrange(0, n-1) do (    for j : Integer.subrange(0, (a[i+1])->size()-1) do ((expr (atom (name index)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name ord)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) )))) - (expr (atom (name ord)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'a'))))))) )))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 1)))))))))) ))));)) ;
    return calculate(0, 0, s, index->first());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def sumOfSeries(x,k):
    return(float(x)/81)*(9*k-1+10**((-1)*k))
if __name__=='__main__' :
    x=9
    k=20
    print(sumOfSeries(x,k))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      x := 9 ;
    k := 20 ;
    execute (sumOfSeries(x, k))->display()
    ) else skip;
  operation sumOfSeries(x : OclAny, k : OclAny) : OclAny
  pre: true post: true
  activity:
    return (("" + ((x)))->toReal() / 81) * (9 * k - 1 + (10)->pow(((-1) * k)));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import ceil
def isPerfectCubeString(str1):
    sum=0
    for i in range(len(str1)):
        sum+=ord(str1[i])
    cr=ceil((sum)**(1/3))
    return(cr*cr*cr==sum)
str1="ll"
if(isPerfectCubeString(str1)):
    print("Yes")
else :
    print("No")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    str1 := "ll" ;
    if (isPerfectCubeString(str1)) then  (
      execute ("Yes")->display()
    )
    else (
      execute ("No")->display()
      );
  operation isPerfectCubeString(str1 : OclAny) : OclAny
  pre: true post: true
  activity:
    var sum : int := 0 ;
    for i : Integer.subrange(0, (str1)->size()-1) do (    sum := sum + (str1[i+1])->char2byte()) ;
    var cr : OclAny := ceil(((sum))->pow((1 / 3))) ;
    return (cr * cr * cr = sum);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
def findRadiusOfcircumcircle(l,b):
    if(l<0 or b<0):
        return-1 ;
    radius=(math.sqrt(pow(l,2)+pow(b,2))/2);
    return radius ;
l=4 ;
b=3 ;
print(findRadiusOfcircumcircle(l,b));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    l := 4; ;
    b := 3; ;
    execute (findRadiusOfcircumcircle(l, b))->display();;
  operation findRadiusOfcircumcircle(l : OclAny, b : OclAny)
  pre: true post: true
  activity:
    if (l < 0 or b < 0) then (
      return -1;
    ) else skip ;
    var radius : double := (((l)->pow(2) + (b)->pow(2))->sqrt() / 2); ;
    return radius;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
MAX=1000 ;
def lineExists(x,y,v,n):
    size=(2*MAX)+1 ;
    arr=[0]*size ;
    for i in range(n):
        arr[x[i]+MAX]+=v[i];
    for i in range(1,size):
        arr[i]+=arr[i-1];
    if(arr[size-1]==0):
        return True ;
    if(arr[size-1]-arr[0]==0):
        return True ;
    for i in range(1,size-1):
        if(arr[i-1]==arr[size-1]-arr[i-1]):
            return True ;
        if(arr[i-1]==arr[size-1]-arr[i]):
            return True ;
        if(arr[i]==arr[size-1]-arr[i]):
            return True ;
    if(arr[size-2]==0):
        return True ;
    return False ;
if __name__=="__main__" :
    x=[-3,5,8];
    y=[8,7,9];
    v=[8,2,10];
    n=len(x);
    if(lineExists(x,y,v,n)):
        print("Yes");
    else :
        print("No");
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var MAX : int := 1000; ;
    skip ;
    if __name__ = "__main__" then (
      x := Sequence{-3}->union(Sequence{5}->union(Sequence{ 8 })); ;
    y := Sequence{8}->union(Sequence{7}->union(Sequence{ 9 })); ;
    v := Sequence{8}->union(Sequence{2}->union(Sequence{ 10 })); ;
    n := (x)->size(); ;
    if (lineExists(x, y, v, n)) then  (
      execute ("Yes")->display();
    )
    else (
      execute ("No")->display();
      )
    ) else skip;
  operation lineExists(x : OclAny, y : OclAny, v : OclAny, n : OclAny)
  pre: true post: true
  activity:
    var size : int := (2 * MAX) + 1; ;
    var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, size); ;
    for i : Integer.subrange(0, n-1) do (    arr[x[i+1] + MAX+1] := arr[x[i+1] + MAX+1] + v[i+1];) ;
    for i : Integer.subrange(1, size-1) do (    arr[i+1] := arr[i+1] + arr[i - 1+1];) ;
    if (arr[size - 1+1] = 0) then (
      return true;
    ) else skip ;
    if (arr[size - 1+1] - arr->first() = 0) then (
      return true;
    ) else skip ;
    for i : Integer.subrange(1, size - 1-1) do (    if (arr[i - 1+1] = arr[size - 1+1] - arr[i - 1+1]) then (
      return true;
    ) else skip ;
    if (arr[i - 1+1] = arr[size - 1+1] - arr[i+1]) then (
      return true;
    ) else skip ;
    if (arr[i+1] = arr[size - 1+1] - arr[i+1]) then (
      return true;
    ) else skip) ;
    if (arr[size - 2+1] = 0) then (
      return true;
    ) else skip ;
    return false;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
def isLucky(n):
    ar=[0]*10
    while(n>0):
        digit=math.floor(n % 10)
        if(ar[digit]):
            return 0
        ar[digit]=1
        n=n/10
    return 1
arr=[1291,897,4566,1232,80,700]
n=len(arr)
for i in range(0,n):
    k=arr[i]
    if(isLucky(k)):
        print(k," is Lucky ")
    else :
        print(k," is not Lucky ")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var arr : Sequence := Sequence{1291}->union(Sequence{897}->union(Sequence{4566}->union(Sequence{1232}->union(Sequence{80}->union(Sequence{ 700 }))))) ;
    n := (arr)->size() ;
    for i : Integer.subrange(0, n-1) do (    var k : OclAny := arr[i+1] ;
    if (isLucky(k)) then  (
      execute (k)->display()
    )
    else (
      execute (k)->display()
      ));
  operation isLucky(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var ar : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ;
    while (n > 0) do (    var digit : double := (n mod 10)->floor() ;
    if (ar[digit+1]) then (
      return 0
    ) else skip ;
    ar[digit+1] := 1 ;
    n := n / 10) ;
    return 1;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def shortestLength(n,x,y):
    answer=0
    i=0
    while n>0 :
        if(x[i]+y[i]>answer):
            answer=x[i]+y[i]
        i+=1
        n-=1
    print("Length->"+str(answer))
    print("Path->"+"(1,"+str(answer)+")"+"and("+str(answer)+",1)")
if __name__=="__main__" :
    n=4
    x=[1,4,2,1]
    y=[4,1,1,2]
    shortestLength(n,x,y)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      n := 4 ;
    x := Sequence{1}->union(Sequence{4}->union(Sequence{2}->union(Sequence{ 1 }))) ;
    y := Sequence{4}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 2 }))) ;
    shortestLength(n, x, y)
    ) else skip;
  operation shortestLength(n : OclAny, x : OclAny, y : OclAny)
  pre: true post: true
  activity:
    var answer : int := 0 ;
    var i : int := 0 ;
    while n > 0 do (    if ((x[i+1] + y[i+1]->compareTo(answer)) > 0) then (
      answer := x[i+1] + y[i+1]
    ) else skip ;
    i := i + 1 ;
    n := n - 1) ;
    execute ("Length->" + ("" + ((answer))))->display() ;
    execute ("Path->" + "(1," + ("" + ((answer))) + ")" + "and(" + ("" + ((answer))) + ",1)")->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
A=input()
B=input()
a=len(A)
b=len(B)
for i in range(a-b+1):
    if B==A[i : i+b]:
        print(i)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var A : String := (OclFile["System.in"]).readLine() ;
    var B : String := (OclFile["System.in"]).readLine() ;
    var a : int := (A)->size() ;
    var b : int := (B)->size() ;
    for i : Integer.subrange(0, a - b + 1-1) do (    if B = A.subrange(i+1, i + b) then (
      execute (i)->display()
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys,math,os
PYDEV=os.environ.get('PYDEV')
if PYDEV=="True" :
    sys.stdin=open("sample-input.txt","rt")
string=input().strip()
pattern=input().strip()
pos=string.find(pattern)
while pos>=0 :
    print(pos)
    pos=string.find(pattern,pos+1)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var PYDEV : OclAny := os.environ.get('PYDEV') ;
    if PYDEV = "True" then (
      OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt"))
    ) else skip ;
    var string : OclAny := input()->trim() ;
    var pattern : OclAny := input()->trim() ;
    var pos : int := string->indexOf(pattern) - 1 ;
    while pos >= 0 do (    execute (pos)->display() ;
    pos := string->indexOf(pattern, pos + 1) - 1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush,heappop
import copy
from test.support import _MemoryWatchdog
BIG_NUM=2000000000
HUGE_NUM=99999999999999999
MOD=1000000007
EPS=0.000000001
sys.setrecursionlimit(100000)
class Info :
    def __init__(self,arg_id,arg_score):
        self.id=arg_id
        self.score=arg_score
        self.float_score=float(self.score)
    def __lt__(self,another):
        return self.float_scoreexists( _x | result = _x );
  attribute id : OclAny := arg_id;
  attribute score : OclAny := arg_score;
  attribute float_score : double := ("" + ((self.score)))->toReal();
  operation initialise(arg_id : OclAny,arg_score : OclAny) : Info
  pre: true post: true
  activity:
    self.id := arg_id ;
    self.score := arg_score ;
    self.float_score := ("" + ((self.score)))->toReal();
    return self;
  operation __lt__(another : OclAny) : OclAny
  pre: true post: true
  activity:
    return (self.float_score->compareTo(another.float_score)) < 0;
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var BIG_NUM : int := 2000000000 ;
    var HUGE_NUM : int := 99999999999999999 ;
    var MOD : int := 1000000007 ;
    var EPS : double := 0.000000001 ;
    sys.setrecursionlimit(100000) ;
    skip ;
    var rest : Sequence := Sequence{} ;
    for loop : Integer.subrange(0, 3-1) do (    var work : Sequence := Sequence{} ;
    for row : Integer.subrange(0, 8-1) do (    var tmp_id : OclAny := null;
    var score : OclAny := null;
    Sequence{tmp_id,score} := input().split() ;
    execute (((Info.newInfo()).initialise(("" + ((tmp_id)))->toInteger(), score)) : work)) ;
    work := work->sort() ;
    execute (StringLib.format("%d %s",Sequence{work->first().id, work->first().score}))->display() ;
    execute (StringLib.format("%d %s",Sequence{work[1+1].id, work[1+1].score}))->display() ;
    for row : Integer.subrange(2, (work)->size()-1) do (    execute ((work[row+1]) : rest))) ;
    rest := rest->sort() ;
    execute (StringLib.format("%d %s",Sequence{rest->first().id, rest->first().score}))->display() ;
    execute (StringLib.format("%d %s",Sequence{rest[1+1].id, rest[1+1].score}))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
def main():
    s1=str(input()).rstrip('\n')
    s2=str(input()).rstrip('\n')
    s1_len=len(s1)
    s2_len=len(s2)
    sc=1
    for k in range(1,len(s2)):
        if s2[0]!=s2[k]:
            break
        sc+=1
    tc=len(set(s2))
    if(tc==1 and s2_len>1):
        cnt=0
        for k in range(s1_len):
            if(s1[k]==s2[0]):
                cnt+=1
            else :
                cnt=0
            if(cnt>=s2_len):
                print(cnt-s2_len)
    else :
        i=s1.find(s2)
        while i!=-1 :
            print(i)
            i=s1.find(s2,i+1)
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var s1 : OclAny := OclType["String"]((OclFile["System.in"]).readLine()).rstrip('
') ;
    var s2 : OclAny := OclType["String"]((OclFile["System.in"]).readLine()).rstrip('
') ;
    var s1_len : int := (s1)->size() ;
    var s2_len : int := (s2)->size() ;
    var sc : int := 1 ;
    for k : Integer.subrange(1, (s2)->size()-1) do (    if s2->first() /= s2[k+1] then (
      break
    ) else skip ;
    sc := sc + 1) ;
    var tc : int := (Set{}->union((s2)))->size() ;
    if (tc = 1 & s2_len > 1) then  (
      var cnt : int := 0 ;
    for k : Integer.subrange(0, s1_len-1) do (    if (s1[k+1] = s2->first()) then  (
      cnt := cnt + 1
    )
    else (
      cnt := 0
      ) ;
    if ((cnt->compareTo(s2_len)) >= 0) then (
      execute (cnt - s2_len)->display()
    ) else skip)
    )
    else (
      var i : int := s1->indexOf(s2) - 1 ;
    while i /= -1 do (    execute (i)->display() ;
    i := s1->indexOf(s2, i + 1) - 1)
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s,p=input(),input();[print(i)for i in range(len(s))if s[i : i+len(p)]==p]
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : OclAny := null;
    var p : OclAny := null;
    Sequence{s,p} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine()};;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
T=input()
P=input()
index=-1
while True :
    index=T.find(P,index+1)
    if index==-1 :
        break
    print(index)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var T : String := (OclFile["System.in"]).readLine() ;
    var P : String := (OclFile["System.in"]).readLine() ;
    var index : int := -1 ;
    while true do (    index := T->indexOf(P, index + 1) - 1 ;
    if index = -1 then (
      break
    ) else skip ;
    execute (index)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def printValue(digit):
    if digit=='0' :
        print("Zero ",end=" ")
    elif digit=='1' :
        print("One ",end=" ")
    elif digit=='2' :
        print("Two ",end=" ")
    elif digit=='3' :
        print("Three",end=" ")
    elif digit=='4' :
        print("Four ",end=" ")
    elif digit=='5' :
        print("Five ",end=" ")
    elif digit=='6' :
        print("Six ",end=" ")
    elif digit=='7' :
        print("Seven",end=" ")
    elif digit=='8' :
        print("Eight",end=" ")
    elif digit=='9' :
        print("Nine ",end=" ")
def printWord(N):
    i=0
    length=len(N)
    while idisplay()
    )
    else (if digit = '1' then
   (
      execute ("One ")->display()    
)
    else (if digit = '2' then
   (
      execute ("Two ")->display()    
)
    else (if digit = '3' then
   (
      execute ("Three")->display()    
)
    else (if digit = '4' then
   (
      execute ("Four ")->display()    
)
    else (if digit = '5' then
   (
      execute ("Five ")->display()    
)
    else (if digit = '6' then
   (
      execute ("Six ")->display()    
)
    else (if digit = '7' then
   (
      execute ("Seven")->display()    
)
    else (if digit = '8' then
   (
      execute ("Eight")->display()    
)
    else (if digit = '9' then
   (
      execute ("Nine ")->display()    
)
    else skip    )
    )
    )
    )
    )
    )
    )
    )
    )
;
  operation printWord(N : OclAny)
  pre: true post: true
  activity:
    var i : int := 0 ;
    var length : int := (N)->size() ;
    while (i->compareTo(length)) < 0 do (    printValue(N[i+1]) ;
    i := i + 1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import Counter
if __name__=='__main__' :
    n=int(input())
    a=[int(s)for s in input().split()]
    print(max(Counter(a+[x-1 for x in a]+[x+1 for x in a]).values()))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ;
    execute ((Counter(a->union(a->select(x | true)->collect(x | (x - 1)))->union(a->select(x | true)->collect(x | (x + 1)))).values())->max())->display()
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
A=sorted(list(map(int,input().split())))
L={}
if n==1 :
    print(1)
elif n==2 :
    if abs(A[0]-A[1])==1 :
        print(2)
    else :
        print(1)
else :
    for i in A :
        if i not in L :
            L[i]=1
        else :
            L[i]+=1
    ans=[]
    for j in range(A[0],A[-1]+1):
        if(j in L)and(j-1 in L)and(j+1 in L):
            ans.append(L[j]+L[j+1]+L[j-1])
        elif(j in L)and(j-1 in L):
            ans.append(L[j-1]+L[j])
        elif(j in L)and(j+1 in L):
            ans.append(L[j+1]+L[j])
        elif(j-1 in L)and(j+1 in L):
            ans.append(L[j+1]+L[j-1])
        elif(j in L):
            ans.append(L[j])
    print(max(ans))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ;
    var L : OclAny := Set{} ;
    if n = 1 then  (
      execute (1)->display()
    )
    else (if n = 2 then
   (
      if (A->first() - A[1+1])->abs() = 1 then  (
      execute (2)->display()
    )
    else (
      execute (1)->display()
      )    
)
    else (
      for i : A do (    if (L)->excludes(i) then  (
      L[i+1] := 1
    )
    else (
      L[i+1] := L[i+1] + 1
      )) ;
    var ans : Sequence := Sequence{} ;
    for j : Integer.subrange(A->first(), A->last() + 1-1) do (    if ((L)->includes(j)) & ((L)->includes(j - 1)) & ((L)->includes(j + 1)) then  (
      execute ((L[j+1] + L[j + 1+1] + L[j - 1+1]) : ans)
    )
    else (if ((L)->includes(j)) & ((L)->includes(j - 1)) then
   (
      execute ((L[j - 1+1] + L[j+1]) : ans)    
)
    else (if ((L)->includes(j)) & ((L)->includes(j + 1)) then
   (
      execute ((L[j + 1+1] + L[j+1]) : ans)    
)
    else (if ((L)->includes(j - 1)) & ((L)->includes(j + 1)) then
   (
      execute ((L[j + 1+1] + L[j - 1+1]) : ans)    
)
    else (if ((L)->includes(j)) then
   (
      execute ((L[j+1]) : ans)    
)
    else skip    )
    )
    )
    )
) ;
    execute ((ans)->max())->display()
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
input()
k=[0]*100000
for a in map(int,input().split()):
    k[a]+=1
print(max(map(sum,zip(k,k[1 :],k[2 :]))))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     input() ;
    var k : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100000) ;
    for a : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do (    k[a+1] := k[a+1] + 1) ;
    execute (((Integer.subrange(1, k->size())->collect( _indx | Sequence{k->at(_indx), k->tail()->at(_indx)} ))->collect( _x | (sum)->apply(_x) ))->max())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=list(map(int,input().split()))
print("win" if sum(a)<=21 else "bust")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute (if (a)->sum() <= 21 then "win" else "bust" endif)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
from collections import Counter
input=sys.stdin.readline
def main():
    N=int(input())
    A=list(map(int,input().split()))
    C=Counter(A)
    ans=0
    for i in range(10**5+1):
        ans=max(ans,C[i-1]+C[i]+C[i+1])
    print(ans)
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var C : OclAny := Counter(A) ;
    var ans : int := 0 ;
    for i : Integer.subrange(0, (10)->pow(5) + 1-1) do (    ans := Set{ans, C[i - 1+1] + C[i+1] + C[i + 1+1]}->max()) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
ar=[int(x)for x in input().split()]
cnt={}
for x in ar :
    def add(x):
        if x in cnt :
            cnt[x]+=1
        else :
            cnt[x]=1
    add(x-1)
    add(x)
    add(x+1)
counts=map(lambda x : x[1],cnt.items())
ans=max(counts)
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var ar : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    var cnt : OclAny := Set{} ;
    for x : ar do (    skip ;
    add(x - 1) ;
    add(x) ;
    add(x + 1)) ;
    var counts : Sequence := (cnt->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}))->collect( _x | (lambda x : OclAny in (x[1+1]))->apply(_x) ) ;
    var ans : OclAny := (counts)->max() ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
l1,l2,l3=[],[],[]
final=[]
count=0
for i in range(24):
    p,t=map(float,input().split())
    if count<=7 : l1.append([t,p])
    elif 7collect( _x | (OclType["double"])->apply(_x) ) ;
    if count <= 7 then  (
      execute ((Sequence{t}->union(Sequence{ p })) : l1)
    )
    else (if 7 < count & (count <= 15) then
   (
      execute ((Sequence{t}->union(Sequence{ p })) : l2)    
)
    else (if 15 < count & (count <= 23) then
   (
      execute ((Sequence{t}->union(Sequence{ p })) : l3)    
)
    else skip    )
    )
 ;
    count := count + 1) ;
    var l1 : Sequence := l1->sort() ;
    var l2 : Sequence := l2->sort() ;
    var l3 : Sequence := l3->sort() ;
    final := final + Sequence{l1->first()}->union(Sequence{l1[1+1]}->union(Sequence{l2->first()}->union(Sequence{l2[1+1]}->union(Sequence{l3->first()}->union(Sequence{ l3[1+1] }))))) ;
    execute (l1->first(), l1->first(), l2->first(), l2->first(), l3->first(), l3->first())->isDeleted() ;
    var third : Sequence := l1->union(l2)->union(l3)->sort() ;
    final := final + Sequence{third->first()}->union(Sequence{ third[1+1] }) ;
    for i : Integer.subrange(0, 8-1) do (    execute (("" + ((final[i+1][1+1])))->toInteger())->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
prime=[True]*(1000001)
prime[0]=False
prime[1]=False
for i in range(2,1000001):
    if prime[i]:
        for j in range(i*2,1000001,i):
            prime[j]=False
while True :
    a,d,n=map(int,input().split())
    if a==0 :
        break
    count=0
    i=a
    cont=True
    while cont :
        if prime[i]:
            count+=1
            if count==n :
                print(i)
                cont=False
        i+=d
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (1000001)) ;
    prime->first() := false ;
    prime[1+1] := false ;
    for i : Integer.subrange(2, 1000001-1) do (    if prime[i+1] then (
      for j : Integer.subrange(i * 2, 1000001-1)->select( $x | ($x - i * 2) mod i = 0 ) do (    prime[j+1] := false)
    ) else skip) ;
    while true do (    var a : OclAny := null;
    var d : OclAny := null;
    var n : OclAny := null;
    Sequence{a,d,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if a = 0 then (
      break
    ) else skip ;
    var count : int := 0 ;
    var i : OclAny := a ;
    var cont : boolean := true ;
    while cont do (    if prime[i+1] then (
      count := count + 1 ;
    if count = n then (
      execute (i)->display() ;
    cont := false
    ) else skip
    ) else skip ;
    i := i + d));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
MAXN=10**6
sieve=[0]*2+[1]*MAXN
n=2
while n*n<=MAXN :
    if sieve[n]:
        for i in range(2*n,MAXN+1,n):
            sieve[i]=0
    n+=1
while True :
    a,d,n=map(int,input().split())
    if n==0 : break
    cnt=0
    for i in range(a,MAXN+1,d):
        if sieve[i]:
            cnt+=1
            if cnt==n :
                print(i)
                break
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var MAXN : double := (10)->pow(6) ;
    var sieve : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 2)->union(MatrixLib.elementwiseMult(Sequence{ 1 }, MAXN)) ;
    var n : int := 2 ;
    while (n * n->compareTo(MAXN)) <= 0 do (    if sieve[n+1] then (
      for i : Integer.subrange(2 * n, MAXN + 1-1)->select( $x | ($x - 2 * n) mod n = 0 ) do (    sieve[i+1] := 0)
    ) else skip ;
    n := n + 1) ;
    while true do (    var a : OclAny := null;
    var d : OclAny := null;
    Sequence{a,d,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if n = 0 then (
      break
    ) else skip ;
    var cnt : int := 0 ;
    for i : Integer.subrange(a, MAXN + 1-1)->select( $x | ($x - a) mod d = 0 ) do (    if sieve[i+1] then (
      cnt := cnt + 1 ;
    if cnt = n then (
      execute (i)->display() ;
    break
    ) else skip
    ) else skip));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
primes=[2]
def prime():
    c=3
    while True :
        for i in primes :
            if i*i>c :
                primes.append(c)
                break
            if c % i==0 :
                break
        c+=1
        if c>10**6 :
            return
prime()
def check(a):
    if a==1 :
        return False
    for i in primes :
        if i*i>a :
            return True
        if a % i==0 :
            return False
        i+=1
def solve(a,d,n):
    while True :
        if check(a):
            n-=1
            if n==0 :
                print(a)
                return
        a+=d
while True :
    l=input().split(' ')
    a=int(l[0])
    d=int(l[1])
    n=int(l[2])
    if a==0 :
        break
    solve(a,d,n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var primes : Sequence := Sequence{ 2 } ;
    skip ;
    prime() ;
    skip ;
    skip ;
    while true do (    var l : OclAny := input().split(' ') ;
    a := ("" + ((l->first())))->toInteger() ;
    d := ("" + ((l[1+1])))->toInteger() ;
    n := ("" + ((l[2+1])))->toInteger() ;
    if a = 0 then (
      break
    ) else skip ;
    solve(a, d, n));
  operation prime()
  pre: true post: true
  activity:
    var c : int := 3 ;
    while true do (    for i : primes do (    if (i * i->compareTo(c)) > 0 then (
      execute ((c) : primes) ;
    break
    ) else skip ;
    if c mod i = 0 then (
      break
    ) else skip) ;
    c := c + 1 ;
    if (c->compareTo((10)->pow(6))) > 0 then (
      return
    ) else skip);
  operation check(a : OclAny) : OclAny
  pre: true post: true
  activity:
    if a = 1 then (
      return false
    ) else skip ;
    for i : primes do (    if (i * i->compareTo(a)) > 0 then (
      return true
    ) else skip ;
    if a mod i = 0 then (
      return false
    ) else skip ;
    i := i + 1);
  operation solve(a : OclAny, d : OclAny, n : OclAny)
  pre: true post: true
  activity:
    while true do (    if check(a) then (
      n := n - 1 ;
    if n = 0 then (
      execute (a)->display() ;
    return
    ) else skip
    ) else skip ;
    a := a + d);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
def sieve_of_erastosthenes(num):
    input_list=[False if i % 2==0 or i % 3==0 or i % 5==0 else True for i in range(num)]
    input_list[0]=input_list[1]=False
    input_list[2]=input_list[3]=input_list[5]=True
    sqrt=math.sqrt(num)
    for serial in range(3,num,2):
        if serial>=sqrt :
            return input_list
        for s in range(serial**2,num,serial):
            input_list[s]=False
primeTable=sieve_of_erastosthenes((10**6))
while True :
    a,d,n=map(int,input().split())
    if a==0 and d==0 and n==0 :
        break
    count=0
    while count!=n :
        if primeTable[a]:
            count+=1
        a+=d
    print(a-d)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var primeTable : OclAny := sieve_of_erastosthenes(((10)->pow(6))) ;
    while true do (    var a : OclAny := null;
    var d : OclAny := null;
    var n : OclAny := null;
    Sequence{a,d,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if a = 0 & d = 0 & n = 0 then (
      break
    ) else skip ;
    var count : int := 0 ;
    while count /= n do (    if primeTable[a+1] then (
      count := count + 1
    ) else skip ;
    a := a + d) ;
    execute (a - d)->display());
  operation sieve_of_erastosthenes(num : OclAny) : OclAny
  pre: true post: true
  activity:
    var input_list : Sequence := Integer.subrange(0, num-1)->select(i | true)->collect(i | (if i mod 2 = 0 or i mod 3 = 0 or i mod 5 = 0 then false else true endif)) ;
    input_list->first() := false; var input_list[1+1] : boolean := false ;
    input_list[2+1] := input_list[2+1](assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name input_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 3))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name input_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 5))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name True))))))))) ;
    var sqrt : double := (num)->sqrt() ;
    for serial : Integer.subrange(3, num-1)->select( $x | ($x - 3) mod 2 = 0 ) do (    if (serial->compareTo(sqrt)) >= 0 then (
      return input_list
    ) else skip ;
    for s : Integer.subrange((serial)->pow(2), num-1)->select( $x | ($x - (serial)->pow(2)) mod serial = 0 ) do (    input_list[s+1] := false));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def sosu(n):
    s=[1]*(n+1)
    s[0]=s[1]=0
    end=int(n**0.5)+1
    for i in range(2,end+1):
        if s[i]==0 : continue
        j=i+i
        while j<=n :
            s[j]=0
            j+=i
    return s
S=sosu(1000000)
while 1 :
    a,d,n=list(map(int,input().split()))
    if not a : break
    while 1 :
        if S[a]==1 :
            n-=1
            if n==0 :
                break
        a+=d
    print(a)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var S : OclAny := sosu(1000000) ;
    while 1 do (    var a : OclAny := null;
    var d : OclAny := null;
    Sequence{a,d,n} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if not(a) then (
      break
    ) else skip ;
    while 1 do (    if S[a+1] = 1 then (
      n := n - 1 ;
    if n = 0 then (
      break
    ) else skip
    ) else skip ;
    a := a + d) ;
    execute (a)->display());
  operation sosu(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ;
    s->first() := 0; var s[1+1] : int := 0 ;
    var end : int := ("" + (((n)->pow(0.5))))->toInteger() + 1 ;
    for i : Integer.subrange(2, end + 1-1) do (    if s[i+1] = 0 then (
      continue
    ) else skip ;
    var j : OclAny := i + i ;
    while (j->compareTo(n)) <= 0 do (    s[j+1] := 0 ;
    j := j + i)) ;
    return s;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def maxNormalSubstring(P,Q,K,N):
    if(K==0):
        return 0
    count=0
    left,right=0,0
    ans=0
    while(rightK):
                    break
                else :
                    count+=1
            right+=1
            if(count<=K):
                ans=max(ans,right-left)
        while(leftsize() ;
    execute (maxNormalSubstring(P, Q, K, N))->display()
    ) else skip;
  operation maxNormalSubstring(P : OclAny, Q : OclAny, K : OclAny, N : OclAny) : OclAny
  pre: true post: true
  activity:
    if (K = 0) then (
      return 0
    ) else skip ;
    var count : int := 0 ;
    var left : OclAny := null;
    var right : OclAny := null;
    Sequence{left,right} := Sequence{0,0} ;
    var ans : int := 0 ;
    while ((right->compareTo(N)) < 0) do (    while ((right->compareTo(N)) < 0 & (count->compareTo(K)) <= 0) do (    var pos : double := (P[right+1])->char2byte() - ('a')->char2byte() ;
    if (Q[pos+1] = '0') then (
      if ((count + 1->compareTo(K)) > 0) then  (
      break
    )
    else (
      count := count + 1
      )
    ) else skip ;
    right := right + 1 ;
    if ((count->compareTo(K)) <= 0) then (
      ans := Set{ans, right - left}->max()
    ) else skip) ;
    while ((left->compareTo(right)) < 0) do (    pos := (P[left+1])->char2byte() - ('a')->char2byte() ;
    left := left + 1 ;
    if (Q[pos+1] = '0') then (
      count := count - 1
    ) else skip ;
    if ((count->compareTo(K)) < 0) then (
      break
    ) else skip)) ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def insertSorted(arr,n,key,capacity):
    if(n>=capacity):
        return n
    i=n-1
    while i>=0 and arr[i]>key :
        arr[i+1]=arr[i]
        i-=1
    arr[i+1]=key
    return(n+1)
arr=[12,16,20,40,50,70]
for i in range(20):
    arr.append(0)
capacity=len(arr)
n=6
key=26
print("Before Insertion: ",end="");
for i in range(n):
    print(arr[i],end="")
n=insertSorted(arr,n,key,capacity)
print("\nAfter Insertion: ",end="")
for i in range(n):
    print(arr[i],end="")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    arr := Sequence{12}->union(Sequence{16}->union(Sequence{20}->union(Sequence{40}->union(Sequence{50}->union(Sequence{ 70 }))))) ;
    for i : Integer.subrange(0, 20-1) do (    execute ((0) : arr)) ;
    capacity := (arr)->size() ;
    n := 6 ;
    key := 26 ;
    execute ("Before Insertion: ")->display(); ;
    for i : Integer.subrange(0, n-1) do (    execute (arr[i+1])->display()) ;
    n := insertSorted(arr, n, key, capacity) ;
    execute ("\nAfter Insertion: ")->display() ;
    for i : Integer.subrange(0, n-1) do (    execute (arr[i+1])->display());
  operation insertSorted(arr : OclAny, n : OclAny, key : OclAny, capacity : OclAny) : OclAny
  pre: true post: true
  activity:
    if ((n->compareTo(capacity)) >= 0) then (
      return n
    ) else skip ;
    var i : double := n - 1 ;
    while i >= 0 & (arr[i+1]->compareTo(key)) > 0 do (    arr[i + 1+1] := arr[i+1] ;
    i := i - 1) ;
    arr[i + 1+1] := key ;
    return (n + 1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def findDandZeros(a,b,n):
    mpp={};
    count=0 ;
    for i in range(n):
        if(b[i]!=0 and a[i]!=0):
            val=(-1.0*b[i])/a[i];
            if val not in mpp :
                mpp[val]=0 ;
            mpp[val]+=1 ;
        elif(b[i]==0 and a[i]==0):
            count+=1 ;
    maxi=0 ;
    for item in mpp :
        maxi=max(mpp[item],maxi);
    for keys,values in mpp.items():
        if(values==maxi):
            print("Value of d is:",keys);
            break ;
    print("The number of zeros in array C is:",maxi+count);
if __name__=="__main__" :
    a=[13,37,39];
    b=[1,2,3];
    n=len(a);
    findDandZeros(a,b,n);
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      a := Sequence{13}->union(Sequence{37}->union(Sequence{ 39 })); ;
    b := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })); ;
    n := (a)->size(); ;
    findDandZeros(a, b, n);
    ) else skip;
  operation findDandZeros(a : OclAny, b : OclAny, n : OclAny)
  pre: true post: true
  activity:
    var mpp : OclAny := Set{}; ;
    var count : int := 0; ;
    for i : Integer.subrange(0, n-1) do (    if (b[i+1] /= 0 & a[i+1] /= 0) then  (
      var val : double := (-1.0 * b[i+1]) / a[i+1]; ;
    if (mpp)->excludes(val) then (
      mpp[val+1] := 0;
    ) else skip ;
    mpp[val+1] := mpp[val+1] + 1;
    )
    else (if (b[i+1] = 0 & a[i+1] = 0) then
   (
      count := count + 1;    
)
 else skip)) ;
    var maxi : int := 0; ;
    for item : mpp do (    maxi := Set{mpp[item+1], maxi}->max();) ;
    for _tuple : mpp->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1;
      var keys : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var values : OclAny := _tuple->at(_indx);
      if (values = maxi) then (
      execute ("Value of d is:")->display(); ;
    break;
    ) else skip) ;
    execute ("The number of zeros in array C is:")->display();;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b,c=input().split()
a=int(a)
b=int(b)
c=int(c)
if a+b+c>=22 :
    print("bust")
else :
    print("win")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    Sequence{a,b,c} := input().split() ;
    var a : int := ("" + ((a)))->toInteger() ;
    var b : int := ("" + ((b)))->toInteger() ;
    var c : int := ("" + ((c)))->toInteger() ;
    if a + b + c >= 22 then  (
      execute ("bust")->display()
    )
    else (
      execute ("win")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math as mt
def solveQuery(start,end,arr):
    frequency=dict()
    for i in range(start,end+1):
        if arr[i]in frequency.keys():
            frequency[arr[i]]+=1
        else :
            frequency[arr[i]]=1
    count=0
    for x in frequency :
        if x==frequency[x]:
            count+=1
    return count
A=[1,2,2,3,3,3]
n=len(A)
queries=[[0,1],[1,1],[0,2],[1,3],[3,5],[0,5]]
q=len(queries)
for i in range(q):
    start=queries[i][0]
    end=queries[i][1]
    print("Answer for Query ",(i+1),"=",solveQuery(start,end,A))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var A : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{3}->union(Sequence{3}->union(Sequence{ 3 }))))) ;
    var n : int := (A)->size() ;
    var queries : Sequence := Sequence{Sequence{0}->union(Sequence{ 1 })}->union(Sequence{Sequence{1}->union(Sequence{ 1 })}->union(Sequence{Sequence{0}->union(Sequence{ 2 })}->union(Sequence{Sequence{1}->union(Sequence{ 3 })}->union(Sequence{Sequence{3}->union(Sequence{ 5 })}->union(Sequence{ Sequence{0}->union(Sequence{ 5 }) }))))) ;
    var q : int := (queries)->size() ;
    for i : Integer.subrange(0, q-1) do (    start := queries[i+1]->first() ;
    end := queries[i+1][1+1] ;
    execute ("Answer for Query ")->display());
  operation solveQuery(start : OclAny, end : OclAny, arr : OclAny) : OclAny
  pre: true post: true
  activity:
    var frequency : Map := (arguments ( )) ;
    for i : Integer.subrange(start, end + 1-1) do (    if (frequency.keys())->includes(arr[i+1]) then  (
      frequency[arr[i+1]+1] := frequency[arr[i+1]+1] + 1
    )
    else (
      frequency[arr[i+1]+1] := 1
      )) ;
    var count : int := 0 ;
    for x : frequency->keys() do (    if x = frequency[x+1] then (
      count := count + 1
    ) else skip) ;
    return count;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a=sorted(list(map(int,input().split())))
if(a[0]==a[-1]):
    x=a.count(a[0])*(a.count(a[-1])-1)//2
else :
    x=a.count(a[0])*a.count(a[-1])
print(a[-1]-a[0],x)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ;
    if (a->first() = a->last()) then  (
      var x : int := a->count(a->first()) * (a->count(a->last()) - 1) div 2
    )
    else (
      x := a->count(a->first()) * a->count(a->last())
      ) ;
    execute (a->last() - a->first())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import stdin
import math
if __name__=="__main__" :
    _in=[_.rstrip()for _ in stdin.readlines()]
    R=int(_in[0])
    cnt=2*math.pi*R
    print(cnt)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = "__main__" then (
      var _in : Sequence := stdin.readlines()->select(_anon | true)->collect(_anon | (StringLib.rightTrim(_anon))) ;
    var R : int := ("" + ((_in->first())))->toInteger() ;
    var cnt : double := 2 *  * R ;
    execute (cnt)->display()
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
PI=3.1415926535
R=int(input())
l=2*R*PI
print(float(l))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var PI : double := 3.1415926535 ;
    var R : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var l : double := 2 * R * PI ;
    execute (("" + ((l)))->toReal())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
from io import StringIO
import unittest
import math
def yn(b):
    print("Yes" if b==1 else "No")
    return
def resolve():
    readline=sys.stdin.readline
    n=int(readline())
    print(n*2*math.pi)
    return
if 'doTest' not in globals():
    resolve()
    sys.exit()

------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    if (globals())->excludes('doTest') then (
      resolve() ;
    sys.exit()
    ) else skip;
  operation yn(b : OclAny)
  pre: true post: true
  activity:
    execute (if b = 1 then "Yes" else "No" endif)->display() ;
    return;
  operation resolve()
  pre: true post: true
  activity:
    var readline : OclAny := (OclFile["System.in"]).readline ;
    var n : int := ("" + ((readline())))->toInteger() ;
    execute (n * 2 * )->display() ;
    return;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    R=int(input())
    print(R*2*3.141526)
if __name__=="__main__" :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var R : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    execute (R * 2 * 3.141526)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import stdin
from sys import setrecursionlimit
from math import pi
setrecursionlimit(10**7)
n=int(stdin.readline().rstrip())
print(2*pi*n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    setrecursionlimit((10)->pow(7)) ;
    var n : int := ("" + ((stdin.readLine().rstrip())))->toInteger() ;
    execute (2 * pi * n)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math ;
def isPerfectSquareString(str):
    sum=0 ;
    l=len(str);
    for i in range(l):
        sum=sum+ord(str[i]);
    squareRoot=math.sqrt(sum);
    return((squareRoot-math.floor(squareRoot))==0);
str="d" ;
if(isPerfectSquareString(str)):
    print("Yes");
else :
    print("No");
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip; ;
    skip ;
    OclType["String"] := "d"; ;
    if (isPerfectSquareString(OclType["String"])) then  (
      execute ("Yes")->display();
    )
    else (
      execute ("No")->display();
      );
  operation isPerfectSquareString(OclType["String"] : OclAny)
  pre: true post: true
  activity:
    var sum : int := 0; ;
    var l : int := (OclType["String"])->size(); ;
    for i : Integer.subrange(0, l-1) do (    sum := sum + (("" + ([i+1])))->char2byte();) ;
    var squareRoot : double := (sum)->sqrt(); ;
    return ((squareRoot - (squareRoot)->floor()) = 0);;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def countEvenSum(arr,n):
    result=0
    for i in range(0,n,1):
        sum=0
        for j in range(i,n,1):
            sum=sum+arr[j]
            if(sum % 2==0):
                result=result+1
    return(result)
if __name__=='__main__' :
    arr=[1,2,2,3,4,1]
    n=len(arr)
    print("The Number of Subarrays","with even sum is",countEvenSum(arr,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      arr := Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 1 }))))) ;
    n := (arr)->size() ;
    execute ("The Number of Subarrays")->display()
    ) else skip;
  operation countEvenSum(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var result : int := 0 ;
    for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do (    var sum : int := 0 ;
    for j : Integer.subrange(i, n-1)->select( $x | ($x - i) mod 1 = 0 ) do (    sum := sum + arr[j+1] ;
    if (sum mod 2 = 0) then (
      result := result + 1
    ) else skip)) ;
    return (result);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def countEvenSum(arr,n):
    temp=[1,0]
    result=0
    sum=0
    for i in range(n):
        sum=((sum+arr[i])% 2+2)% 2
        temp[sum]+=1
    result=result+(temp[0]*(temp[0]-1)//2)
    result=result+(temp[1]*(temp[1]-1)//2)
    return(result)
if __name__=="__main__" :
    arr=[1,2,2,3,4,1]
    n=len(arr)
    print("The Number of Subarrays with even" " sum is",countEvenSum(arr,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      arr := Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 1 }))))) ;
    n := (arr)->size() ;
    execute ((atom "The Number of Subarrays with even" " sum is"))->display()
    ) else skip;
  operation countEvenSum(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var temp : Sequence := Sequence{1}->union(Sequence{ 0 }) ;
    var result : int := 0 ;
    var sum : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    sum := ((sum + arr[i+1]) mod 2 + 2) mod 2 ;
    temp[sum+1] := temp[sum+1] + 1) ;
    result := result + (temp->first() * (temp->first() - 1) div 2) ;
    result := result + (temp[1+1] * (temp[1+1] - 1) div 2) ;
    return (result);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import defaultdict
def getlist():
    return list(map(int,input().split()))
def main():
    S=list(input())
    N=len(S)
    s=[0]*(N+1)
    for i in range(N):
        if S[i]=="A" :
            s[i+1]+=s[i]+2
        else :
            s[i+1]+=s[i]+1
    T=list(input())
    M=len(T)
    t=[0]*(M+1)
    for i in range(M):
        if T[i]=="A" :
            t[i+1]+=t[i]+2
        else :
            t[i+1]+=t[i]+1
    Q=int(input())
    for i in range(Q):
        a,b,c,d=getlist()
        if((s[b]-s[a-1])-(t[d]-t[c-1]))% 3==0 :
            print("YES")
        else :
            print("NO")
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation getlist() : OclAny
  pre: true post: true
  activity:
    return ((input().split())->collect( _x | (OclType["int"])->apply(_x) ));
  operation main()
  pre: true post: true
  activity:
    var S : Sequence := ((OclFile["System.in"]).readLine())->characters() ;
    var N : int := (S)->size() ;
    var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ;
    for i : Integer.subrange(0, N-1) do (    if S[i+1] = "A" then  (
      s[i + 1+1] := s[i + 1+1] + s[i+1] + 2
    )
    else (
      s[i + 1+1] := s[i + 1+1] + s[i+1] + 1
      )) ;
    var T : Sequence := ((OclFile["System.in"]).readLine())->characters() ;
    var M : int := (T)->size() ;
    var t : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (M + 1)) ;
    for i : Integer.subrange(0, M-1) do (    if T[i+1] = "A" then  (
      t[i + 1+1] := t[i + 1+1] + t[i+1] + 2
    )
    else (
      t[i + 1+1] := t[i + 1+1] + t[i+1] + 1
      )) ;
    var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, Q-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    var d : OclAny := null;
    Sequence{a,b,c,d} := getlist() ;
    if ((s[b+1] - s[a - 1+1]) - (t[d+1] - t[c - 1+1])) mod 3 = 0 then  (
      execute ("YES")->display()
    )
    else (
      execute ("NO")->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a1,a2,a3=map(int,input().split())
total=a1+a2+a3
if total<=21 :
    print('win')
else :
    print('bust')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a1 : OclAny := null;
    var a2 : OclAny := null;
    var a3 : OclAny := null;
    Sequence{a1,a2,a3} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var total : OclAny := a1 + a2 + a3 ;
    if total <= 21 then  (
      execute ('win')->display()
    )
    else (
      execute ('bust')->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a=[int(i)for i in input().split()]
a.sort()
print(a[n-1]-a[0],end=" ")
if a[0]==a[n-1]:
    ans=0
    for i in range(1,n):
        ans+=i
    print(ans)
else :
    dt={}
    for i in a :
        if i in dt :
            dt[i]+=1
        else :
            dt[i]=1
    ans=dt[a[0]]*dt[a[n-1]]
    print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    a := a->sort() ;
    execute (a[n - 1+1] - a->first())->display() ;
    if a->first() = a[n - 1+1] then  (
      var ans : int := 0 ;
    for i : Integer.subrange(1, n-1) do (    ans := ans + i) ;
    execute (ans)->display()
    )
    else (
      var dt : OclAny := Set{} ;
    for i : a do (    if (dt)->includes(i) then  (
      dt[i+1] := dt[i+1] + 1
    )
    else (
      dt[i+1] := 1
      )) ;
    ans := dt[a->first()+1] * dt[a[n - 1+1]+1] ;
    execute (ans)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s=input()
t=input()
q=int(input())
sa_pre=[s[i]=="A" for i in range(len(s))]
ta_pre=[t[i]=="A" for i in range(len(t))]
sa=[0,sa_pre[0]]
ta=[0,ta_pre[0]]
for i in range(1,len(s)):
    sa.append(sa[-1]+sa_pre[i])
for i in range(1,len(t)):
    ta.append(ta[-1]+ta_pre[i])
def check(a,b,c,d):
    xa=sa[b]-sa[a-1]
    ya=ta[d]-ta[c-1]
    if(2*xa-(b-a+1))% 3==(2*ya-(d-c+1))% 3 :
        print("YES")
        return
    else :
        print("NO")
        return
for _ in range(q):
    a,b,c,d=map(int,input().split())
    check(a,b,c,d)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : String := (OclFile["System.in"]).readLine() ;
    var t : String := (OclFile["System.in"]).readLine() ;
    var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var sa_pre : Sequence := Integer.subrange(0, (s)->size()-1)->select(i | true)->collect(i | (s[i+1] = "A")) ;
    var ta_pre : Sequence := Integer.subrange(0, (t)->size()-1)->select(i | true)->collect(i | (t[i+1] = "A")) ;
    var sa : Sequence := Sequence{0}->union(Sequence{ sa_pre->first() }) ;
    var ta : Sequence := Sequence{0}->union(Sequence{ ta_pre->first() }) ;
    for i : Integer.subrange(1, (s)->size()-1) do (    execute ((sa->last() + sa_pre[i+1]) : sa)) ;
    for i : Integer.subrange(1, (t)->size()-1) do (    execute ((ta->last() + ta_pre[i+1]) : ta)) ;
    skip ;
    for _anon : Integer.subrange(0, q-1) do (    Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    check(a, b, c, d));
  operation check(a : OclAny, b : OclAny, c : OclAny, d : OclAny)
  pre: true post: true
  activity:
    var xa : double := sa[b+1] - sa[a - 1+1] ;
    var ya : double := ta[d+1] - ta[c - 1+1] ;
    if (2 * xa - (b - a + 1)) mod 3 = (2 * ya - (d - c + 1)) mod 3 then  (
      execute ("YES")->display() ;
    return
    )
    else (
      execute ("NO")->display() ;
    return
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from itertools import accumulate
*S,=map(lambda x : 1 if x=='A' else 2,input())
*T,=map(lambda x : 1 if x=='A' else 2,input())
acc_s=(0,)+tuple(accumulate(S))
acc_t=(0,)+tuple(accumulate(T))
ans=[]
Q=int(input())
for _ in range(Q):
    sl,sr,tl,tr=map(int,input().split())
    diff=(acc_t[tr]-acc_t[tl-1])-(acc_s[sr]-acc_s[sl-1])
    ans.append('YES' if diff % 3==0 else 'NO')
print(*ans,sep='\n')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
(testlist_star_expr (star_expr * (expr (atom (name S)))) ,)    Sequence{(testlist_star_expr (star_expr * (expr (atom (name S)))) ,)} := ((OclFile["System.in"]).readLine())->collect( _x | (lambda x : OclAny in (if x = 'A' then 1 else 2 endif))->apply(_x) ) ;
(testlist_star_expr (star_expr * (expr (atom (name T)))) ,)    Sequence{(testlist_star_expr (star_expr * (expr (atom (name T)))) ,)} := ((OclFile["System.in"]).readLine())->collect( _x | (lambda x : OclAny in (if x = 'A' then 1 else 2 endif))->apply(_x) ) ;
    var acc_s : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) ,)}->union((accumulate(S))) ;
    var acc_t : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) ,)}->union((accumulate(T))) ;
    var ans : Sequence := Sequence{} ;
    var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, Q-1) do (    var sl : OclAny := null;
    var sr : OclAny := null;
    var tl : OclAny := null;
    var tr : OclAny := null;
    Sequence{sl,sr,tl,tr} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var diff : double := (acc_t[tr+1] - acc_t[tl - 1+1]) - (acc_s[sr+1] - acc_s[sl - 1+1]) ;
    execute ((if diff mod 3 = 0 then 'YES' else 'NO' endif) : ans)) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
S,T=[0],[0]
for c in input(): S+=[S[-1]+1+(c=='B')]
for c in input(): T+=[T[-1]+1+(c=='B')]
for _ in[0]*int(input()):
    a,b,c,d=map(int,input().split())
    print('NO' if(T[d]-T[c-1]-S[b]+S[a-1])% 3 else 'YES')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var S : OclAny := null;
    var T : OclAny := null;
    Sequence{S,T} := Sequence{Sequence{ 0 },Sequence{ 0 }} ;
    for c : (OclFile["System.in"]).readLine() do (    S := S + Sequence{ S->last() + 1 + (c = 'B') }) ;
    for c : (OclFile["System.in"]).readLine() do (    T := T + Sequence{ T->last() + 1 + (c = 'B') }) ;
    for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do (    var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    var d : OclAny := null;
    Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (if (T[d+1] - T[c - 1+1] - S[b+1] + S[a - 1+1]) mod 3 then 'NO' else 'YES' endif)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
ipt=stdin.readline
setrecursionlimit(10**7)
def main():
    s=input()
    t=input()
    ns=len(s)+1
    nt=len(t)+1
    ssa=[0]*ns
    ssb=[0]*ns
    sta=[0]*nt
    stb=[0]*nt
    for i,si in enumerate(s):
        if si=="A" :
            da=1
            db=0
        else :
            da=0
            db=1
        ssa[i+1]=ssa[i]+da
        ssb[i+1]=ssb[i]+db
    for i,ti in enumerate(t):
        if ti=="A" :
            da=1
            db=0
        else :
            da=0
            db=1
        sta[i+1]=sta[i]+da
        stb[i+1]=stb[i]+db
    q=int(ipt())
    for _ in range(q):
        a,b,c,d=map(int,ipt().split())
        da=ssa[b]-ssa[a-1]-sta[d]+sta[c-1]
        db=ssb[b]-ssb[a-1]-stb[d]+stb[c-1]
        if(da-db)% 3==0 :
            print("YES")
        else :
            print("NO")
    return
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    var ipt : OclAny := stdin.readline ;
    setrecursionlimit((10)->pow(7)) ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var s : String := (OclFile["System.in"]).readLine() ;
    var t : String := (OclFile["System.in"]).readLine() ;
    var ns : int := (s)->size() + 1 ;
    var nt : int := (t)->size() + 1 ;
    var ssa : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ns) ;
    var ssb : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ns) ;
    var sta : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, nt) ;
    var stb : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, nt) ;
    for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var si : OclAny := _tuple->at(_indx);
      if si = "A" then  (
      var da : int := 1 ;
    var db : int := 0
    )
    else (
      da := 0 ;
    db := 1
      ) ;
    ssa[i + 1+1] := ssa[i+1] + da ;
    ssb[i + 1+1] := ssb[i+1] + db) ;
    for _tuple : Integer.subrange(1, (t)->size())->collect( _indx | Sequence{_indx-1, (t)->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var ti : OclAny := _tuple->at(_indx);
      if ti = "A" then  (
      da := 1 ;
    db := 0
    )
    else (
      da := 0 ;
    db := 1
      ) ;
    sta[i + 1+1] := sta[i+1] + da ;
    stb[i + 1+1] := stb[i+1] + db) ;
    var q : int := ("" + ((ipt())))->toInteger() ;
    for _anon : Integer.subrange(0, q-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    var c : OclAny := null;
    var d : OclAny := null;
    Sequence{a,b,c,d} := (ipt().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    da := ssa[b+1] - ssa[a - 1+1] - sta[d+1] + sta[c - 1+1] ;
    db := ssb[b+1] - ssb[a - 1+1] - stb[d+1] + stb[c - 1+1] ;
    if (da - db) mod 3 = 0 then  (
      execute ("YES")->display()
    )
    else (
      execute ("NO")->display()
      )) ;
    return;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=map(int,input().split())
n=int(a**0.5)
if n*(n+1)<=b :
    print("Vladik")
else :
    print("Valera")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var n : int := ("" + (((a)->pow(0.5))))->toInteger() ;
    if (n * (n + 1)->compareTo(b)) <= 0 then  (
      execute ("Vladik")->display()
    )
    else (
      execute ("Valera")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
(vladik,valera)=map(int,input().split(' '))
i=0
while True :
    i+=1
    if i % 2==1 :
        if vladikcollect( _x | (OclType["int"])->apply(_x) ) ;
    var i : int := 0 ;
    while true do (    i := i + 1 ;
    if i mod 2 = 1 then  (
      if (vladik->compareTo(i)) < 0 then (
      execute ('Vladik')->display() ;
    break
    ) else skip ;
    vladik := vladik - i
    )
    else (
      if (valera->compareTo(i)) < 0 then (
      execute ('Valera')->display() ;
    break
    ) else skip ;
    valera := valera - i
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=map(int,input().split())
print('VVlaaldeirka'[((4*b+1)**.5-1)//2collect( _x | (OclType["int"])->apply(_x) ) ;
    execute ('VVlaaldeirka'(subscript (test (logical_test (comparison (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (number (integer 4)))) * (expr (atom (name b)))) + (expr (atom (number (integer 1))))))))) ))) ** (expr (atom (number .5)))) - (expr (atom (number (integer 1))))))))) ))) // (expr (atom (number (integer 2)))))) < (comparison (expr (expr (expr (atom (name a))) ** (expr (atom (number .5)))) // (expr (atom (number (integer 1))))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
l=list(map(int,input().split()))
vl=l[0]
va=l[1]
k=1
while(True):
    if k>vl :
        print("Vladik")
        break
    else :
        vl-=k
        k+=1
    if k>va :
        print("Valera")
        break
    else :
        va-=k
        k+=1
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var vl : OclAny := l->first() ;
    var va : OclAny := l[1+1] ;
    var k : int := 1 ;
    while (true) do (    if (k->compareTo(vl)) > 0 then  (
      execute ("Vladik")->display() ;
    break
    )
    else (
      vl := vl - k ;
    k := k + 1
      ) ;
    if (k->compareTo(va)) > 0 then  (
      execute ("Valera")->display() ;
    break
    )
    else (
      va := va - k ;
    k := k + 1
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a,b=map(int,input().split())
i=1
while a>=0 and b>=0 :
    if i % 2!=0 :
        a-=i
    else :
        b-=i
    i+=1
if(a<0):
    print("Vladik")
else :
    print("Valera")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var i : int := 1 ;
    while a >= 0 & b >= 0 do (    if i mod 2 /= 0 then  (
      a := a - i
    )
    else (
      b := b - i
      ) ;
    i := i + 1) ;
    if (a < 0) then  (
      execute ("Vladik")->display()
    )
    else (
      execute ("Valera")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
readline=sys.stdin.buffer.readline
sys.setrecursionlimit(10**8)
INF=float('inf')
MOD=10**9+7
def main():
    S=input()
    T=input()
    if S==T[:-1]:
        print('Yes')
    else :
        print('No')
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var readline : OclAny := sys.stdin.buffer.readline ;
    sys.setrecursionlimit((10)->pow(8)) ;
    var INF : double := ("" + (('inf')))->toReal() ;
    var MOD : double := (10)->pow(9) + 7 ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    var S : String := (OclFile["System.in"]).readLine() ;
    var T : String := (OclFile["System.in"]).readLine() ;
    if S = T->front() then  (
      execute ('Yes')->display()
    )
    else (
      execute ('No')->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
flowers=list(map(int,input().split()))
max_flower=max(flowers)
min_flower=min(flowers)
if max_flower!=min_flower :
    difference=max_flower-min_flower
    num1=0
    num2=0
    for x in flowers :
        if x==max_flower :
            num1+=1
        elif x==min_flower :
            num2+=1
    num=num1*num2
    print(difference,num)
else :
    num=int(n*(n-1)/2)
    print(0,num)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var flowers : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var max_flower : OclAny := (flowers)->max() ;
    var min_flower : OclAny := (flowers)->min() ;
    if max_flower /= min_flower then  (
      var difference : double := max_flower - min_flower ;
    var num1 : int := 0 ;
    var num2 : int := 0 ;
    for x : flowers do (    if x = max_flower then  (
      num1 := num1 + 1
    )
    else (if x = min_flower then
   (
      num2 := num2 + 1    
)
 else skip)) ;
    var num : int := num1 * num2 ;
    execute (difference)->display()
    )
    else (
      num := ("" + ((n * (n - 1) / 2)))->toInteger() ;
    execute (0)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
print('bwuisnt'[sum(map(int,input().split()))<22 : : 2])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     execute ('bwuisnt'(subscript (test (logical_test (comparison (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))) < (comparison (expr (atom (number (integer 22)))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
input_S=input()
input_T=input()
if(input_T[0 : len(input_S)]==input_S and 0size()) = input_S & 0 < (input_T)->size() - (input_S)->size()) then  (
      execute ("Yes")->display()
    )
    else (
      execute ("No")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
S=str(input())
T=str(input())
N=len(S)
for i in range(N):
    if S[i]!=T[i]:
        print("No")
        quit()
print("Yes")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var S : String := ("" + (((OclFile["System.in"]).readLine()))) ;
    var T : String := ("" + (((OclFile["System.in"]).readLine()))) ;
    var N : int := (S)->size() ;
    for i : Integer.subrange(0, N-1) do (    if S[i+1] /= T[i+1] then (
      execute ("No")->display() ;
    quit()
    ) else skip) ;
    execute ("Yes")->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s=input()
t=input()
ans="Yes"
for i in range(len(s)):
    if s[i]!=t[i]:
        ans="No"
        break
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : String := (OclFile["System.in"]).readLine() ;
    var t : String := (OclFile["System.in"]).readLine() ;
    var ans : String := "Yes" ;
    for i : Integer.subrange(0, (s)->size()-1) do (    if s[i+1] /= t[i+1] then (
      ans := "No" ;
    break
    ) else skip) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
S=input()
T=input()
if(not S.isalpha())or(not T.isalpha()):
    print('No')
elif len(S)>10 :
    print('No')
elif len(S)+1!=len(T):
    print('No')
elif T[: len(S)]!=S :
    print('No')
else :
    print('Yes')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var S : String := (OclFile["System.in"]).readLine() ;
    var T : String := (OclFile["System.in"]).readLine() ;
    if (not(S->matches("[a-zA-Z]*"))) or (not(T->matches("[a-zA-Z]*"))) then  (
      execute ('No')->display()
    )
    else (if (S)->size() > 10 then
   (
      execute ('No')->display()    
)
    else (if (S)->size() + 1 /= (T)->size() then
   (
      execute ('No')->display()    
)
    else (if T.subrange(1,(S)->size()) /= S then
   (
      execute ('No')->display()    
)
    else (
      execute ('Yes')->display()
      )    )
    )
    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for _ in range(t):
    n=int(input())
    q=list(map(int,input().split()))
    checker=set()
    runner=1
    ans=[0 for i in range(n)]
    prev=0
    for i in range(n):
        x=q[i]
        if x>prev :
            ans[i]=x
            checker.add(x)
            prev=x
        else :
            while runner in checker :
                runner+=1
            if runner>prev :
                print(-1)
                break
            ans[i]=runner
            checker.add(runner)
    else :
        print(*ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, t-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var q : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var checker : Set := Set{}->union(()) ;
    var runner : int := 1 ;
    var ans : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ;
    var prev : int := 0 ;
(compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name q)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name x)))) > (comparison (expr (atom (name prev))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name checker)) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name prev)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x))))))))))))) (else_clause else : (suite (stmt (compound_stmt while (test (logical_test (comparison (comparison (expr (atom (name runner)))) in (comparison (expr (atom (name checker))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name runner)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name runner)))) > (comparison (expr (atom (name prev))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name runner)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name checker)) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name runner)))))))) ))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))))))))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
for _ in[0]*int(input()):
    n=int(input())
    a=list(map(int,input().split()))
    ff=1
    jj=set(range(1,n+1))
    y=a[0]
    jj.remove(y)
    d=[y]+[0]*(n-1)
    ind=[]
    i=0
    for x in a :
        if xy :
            d[i]=x
            jj.remove(x)
        else :
            ind.append(i)
        y=x
        i=i+1
    if ff==1 :
        del ind[0]
        for i,j in zip(ind,jj):
            d[i]=j
        print(*d)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var ff : int := 1 ;
    var jj : Set := Set{}->union((Integer.subrange(1, n + 1-1))) ;
    var y : OclAny := a->first() ;
    execute ((y) /: jj) ;
    var d : Sequence := Sequence{ y }->union(MatrixLib.elementwiseMult(Sequence{ 0 }, (n - 1))) ;
    var ind : Sequence := Sequence{} ;
    var i : int := 0 ;
    for x : a do (    if (x->compareTo(i + 1)) < 0 or (x->compareTo(y)) < 0 then  (
      ff := 0 ;
    execute (-1)->display() ;
    break
    )
    else (if (x->compareTo(y)) > 0 then
   (
      d[i+1] := x ;
    execute ((x) /: jj)    
)
    else (
      execute ((i) : ind)
      )    )
 ;
    y := x ;
    i := i + 1) ;
    if ff = 1 then (
      execute (ind->first())->isDeleted() ;
    for _tuple : Integer.subrange(1, ind->size())->collect( _indx | Sequence{ind->at(_indx), jj->at(_indx)} ) do (var _indx : int := 1;
      var i : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var j : OclAny := _tuple->at(_indx);
      d[i+1] := j) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name d))))))))->display()
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
for _ in range(int(input())):
    n=list(map(int,input().split()))[0]
    c=list(map(int,input().split()))
    arr=[1]*(n+1)
    ans=[]
    ind=1
    found=True
    for i in range(n):
        if i>0 and c[i]==c[i-1]:
            while indc[i]:
                found=False
                break
            else :
                arr[ind]=0
                ans.append(ind)
        else :
            if arr[c[i]]==1 :
                arr[c[i]]=0
                ans.append(c[i])
    if not found :
        print(-1)
    else :
        print(*ans,sep=" ")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->first() ;
    var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ;
    var ans : Sequence := Sequence{} ;
    var ind : int := 1 ;
    var found : boolean := true ;
    for i : Integer.subrange(0, n-1) do (    if i > 0 & c[i+1] = c[i - 1+1] then  (
      while (ind->compareTo(n)) < 0 & arr[ind+1] = 0 do (    ind := ind + 1) ;
    if (ind->compareTo(c[i+1])) > 0 then  (
      found := false ;
    break
    )
    else (
      arr[ind+1] := 0 ;
    execute ((ind) : ans)
      )
    )
    else (
      if arr[c[i+1]+1] = 1 then (
      arr[c[i+1]+1] := 0 ;
    execute ((c[i+1]) : ans)
    ) else skip
      )) ;
    if not(found) then  (
      execute (-1)->display()
    )
    else (
      execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
for _ in range(int(input())):
    n=int(input())
    w=list(map(int,input().split()))
    d=[]
    x=[]
    for i in range(n):
        if i==0 :
            d.append(w[i])
            for j in range(1,w[i]):
                x.append(j)
        else :
            if w[i]1 :
                    for j in range(w[i-1]+1,w[i]):
                        x.append(j)
                    d.append(w[i])
                else :
                    a=x.pop()
                    d.append(a)
    else :
        print(' '.join(map(str,d)))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var d : Sequence := Sequence{} ;
    var x : Sequence := Sequence{} ;
(compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name i)))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))))))))))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) < (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))))))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))))) > (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) ))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name a)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)) (trailer . (name pop) (arguments ( ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))))))))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ' ') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name d)))))))) ))))))))) ))))))))) ))))))))))))))));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    n=int(input())
    q=[int(i)for i in input().split()]
    p=[]
    Q=set(q)
    w=[i for i in range(1,n+1)if i not in Q]
    visited=set()
    j=0
    for i in range(n):
        if i==0 : p.append(q[i]); visited.add(q[i]); continue
        if q[i]==q[i-1]:
            p.append(w[j])
            j+=1
        else : p.append(q[i]); visited.add(q[i])
    M=0
    ans=None
    for i in range(n):
        M=max(M,p[i])
        if q[i]!=M : ans=-1 ; break
    if ans==-1 : print(-1)
    else : print(*p)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var q : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var p : Sequence := Sequence{} ;
    var Q : Set := Set{}->union((q)) ;
    var w : Sequence := Integer.subrange(1, n + 1-1)->select(i | (Q)->excludes(i))->collect(i | (i)) ;
    var visited : Set := Set{}->union(()) ;
    var j : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    if i = 0 then (
      execute ((q[i+1]) : p);    execute ((q[i+1]) : visited);    continue
    ) else skip ;
    if q[i+1] = q[i - 1+1] then  (
      execute ((w[j+1]) : p) ;
    j := j + 1
    )
    else (
      execute ((q[i+1]) : p);    execute ((q[i+1]) : visited)
      )) ;
    var M : int := 0 ;
    var ans : OclAny := null ;
    for i : Integer.subrange(0, n-1) do (    M := Set{M, p[i+1]}->max() ;
    if q[i+1] /= M then (
      ans := -1;    break
    ) else skip) ;
    if ans = -1 then  (
      execute (-1)->display()
    )
    else (
      execute ((argument * (test (logical_test (comparison (expr (atom (name p))))))))->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import factorial
n=int(input())
l=list(map(int,input().split()))
l.sort()
d=l[n-1]-l[0]
a=l.count(l[0])
b=l.count(l[n-1])
c=a*b
if d==0 :
    c=0
    for i in range(n):
        c+=i
print(d,c)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    l := l->sort() ;
    var d : double := l[n - 1+1] - l->first() ;
    var a : int := l->count(l->first()) ;
    var b : int := l->count(l[n - 1+1]) ;
    var c : int := a * b ;
    if d = 0 then (
      c := 0 ;
    for i : Integer.subrange(0, n-1) do (    c := c + i)
    ) else skip ;
    execute (d)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
for _ in range(int(input())):
    n,a=int(input()),list(map(int,input().split()))
    d=[0,0]
    for i in range(1,n): d=[max(a[i]-a[i-1],d[0]),max(a[i-1]-a[i],d[1])]
    print(*d)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do (    var n : OclAny := null;
    var a : OclAny := null;
    Sequence{n,a} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),((input().split())->collect( _x | (OclType["int"])->apply(_x) ))} ;
    var d : Sequence := Sequence{0}->union(Sequence{ 0 }) ;
    for i : Integer.subrange(1, n-1) do (    d := Sequence{Set{a[i+1] - a[i - 1+1], d->first()}->max()}->union(Sequence{ Set{a[i - 1+1] - a[i+1], d[1+1]}->max() })) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name d))))))))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m=map(int,input().split())
a=list(map(int,input().split()))
pre=a[0]; d=0
for x in a[1 :]:
    d=max(d,x-pre)
    pre=x
print(max(n-pre,max(d>>1,a[0]-1)))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var pre : OclAny := a->first();    var d : int := 0 ;
    for x : a->tail() do (    d := Set{d, x - pre}->max() ;
    pre := x) ;
    execute (Set{n - pre, Set{d /(2->pow(1)), a->first() - 1}->max()}->max())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
a=[int(x)for x in input().split()]
if sum(a)>=22 :
    print("bust")
else :
    print("win")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    if (a)->sum() >= 22 then  (
      execute ("bust")->display()
    )
    else (
      execute ("win")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
while n :
    input()
    n-=1
    a=list(map(int,input().split()))
    u,d=0,0
    for i in range(1,len(a)):
        if a[i]-a[i-1]>0 : u=max(a[i]-a[i-1],u)
        elif a[i]-a[i-1]<0 : d=max(a[i-1]-a[i],d)
    print(u,d)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    while n do (    input() ;
    n := n - 1 ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var u : OclAny := null;
    var d : OclAny := null;
    Sequence{u,d} := Sequence{0,0} ;
    for i : Integer.subrange(1, (a)->size()-1) do (    if a[i+1] - a[i - 1+1] > 0 then  (
      var u : OclAny := Set{a[i+1] - a[i - 1+1], u}->max()
    )
    else (if a[i+1] - a[i - 1+1] < 0 then
   (
      var d : OclAny := Set{a[i - 1+1] - a[i+1], d}->max()    
)
 else skip)) ;
    execute (u)->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def Calculate(rows):
    up,down=0,0
    for x in range(0,len(rows)-1):
        tmp=rows[x+1]-rows[x]
        if tmp<0 :
            tmp=abs(tmp)
            if down0 :
            if upsize() - 1-1) do (    var tmp : double := rows[x + 1+1] - rows[x+1] ;
    if tmp < 0 then  (
      tmp := (tmp)->abs() ;
    if (down->compareTo(tmp)) < 0 then (
      var down : OclAny := tmp
    ) else skip
    )
    else (if tmp > 0 then
   (
      if (up->compareTo(tmp)) < 0 then (
      var up : OclAny := tmp
    ) else skip    
)
    else (
      skip
      )    )
) ;
    return Sequence{up, down};
  operation Main()
  pre: true post: true
  activity:
    var fields : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    Sequence{up,down} := Sequence{Sequence{},Sequence{}} ;
    for x : Integer.subrange(0, fields-1) do (    var blocks_q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var blocks : OclAny := input().split(' ') ;
    blocks := blocks->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    if blocks_q /= (blocks)->size() then (
      skip
    ) else skip ;
    var tmp_up : OclAny := null;
    var tmp_down : OclAny := null;
    Sequence{tmp_up,tmp_down} := Calculate(blocks) ;
    execute ((tmp_up) : up) ;
    execute ((tmp_down) : down)) ;
    for x : Integer.subrange(0, (up)->size()-1) do (    execute (StringLib.interpolateStrings("{0}{1}", Sequence{up[x+1], down[x+1]}))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def saizo(A : list):
    uplen=0
    downlen=0
    num=len(A)
    for j in range(num-1):
        tmp=A[j+1]-A[j]
        if A[j+1]>=A[j]:
            uplen=max(uplen,tmp)
        else :
            downlen=max(downlen,abs(tmp))
    print(uplen,downlen)
if __name__=='__main__' :
    n=int(input())
    for i in range(n):
        input()
        saizo(list(map(int,input().split())))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for i : Integer.subrange(0, n-1) do (    input() ;
    saizo(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))
    ) else skip;
  operation saizo(A : Sequence(OclAny))
  pre: true post: true
  activity:
    var uplen : int := 0 ;
    var downlen : int := 0 ;
    var num : int := (A)->size() ;
    for j : Integer.subrange(0, num - 1-1) do (    var tmp : double := A[j + 1+1] - A[j+1] ;
    if (A[j + 1+1]->compareTo(A[j+1])) >= 0 then  (
      uplen := Set{uplen, tmp}->max()
    )
    else (
      downlen := Set{downlen, (tmp)->abs()}->max()
      )) ;
    execute (uplen)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
t=int(input())
for count in range(t):
    n=int(input())
    h_list=[int(i)for i in input().split(" ")]
    delta_list=[]
    for i in range(n-1):
        delta_list.append(h_list[i+1]-h_list[i])
    if max(delta_list)>0 :
        max_up=max(delta_list)
    else :
        max_up=0
    if min(delta_list)<0 :
        max_down=min(delta_list)*(-1)
    else :
        max_down=0
    print("%d %d" %(max_up,max_down))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for count : Integer.subrange(0, t-1) do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var h_list : Sequence := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var delta_list : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n - 1-1) do (    execute ((h_list[i + 1+1] - h_list[i+1]) : delta_list)) ;
    if (delta_list)->max() > 0 then  (
      var max_up : OclAny := (delta_list)->max()
    )
    else (
      max_up := 0
      ) ;
    if (delta_list)->min() < 0 then  (
      var max_down : double := (delta_list)->min() * (-1)
    )
    else (
      max_down := 0
      ) ;
    execute (StringLib.format("%d %d",Sequence{max_up, max_down}))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import stdin
from sys import stdout
def find_least(s,p,x):
    m=None
    b=len(s)
    for i in xrange(p,len(s)):
        if s[i]>x and(m is None or s[i]trim())))->toInteger() ;
    for X : xrange(1, T + 1) do (    N := stdin.readLine()->trim() ;
    K := next_number(N) ;
    stdout.write(StringLib.format('Case #%d: %s
',Sequence{X, K})));
  operation find_least(s : OclAny, p : OclAny, x : OclAny) : OclAny
  pre: true post: true
  activity:
    var m : OclAny := null ;
    var b : int := (s)->size() ;
    for i : xrange(p, (s)->size()) do (    if (s[i+1]->compareTo(x)) > 0 & (m <>= null or (s[i+1]->compareTo(m)) < 0) then (
      m := s[i+1] ;
    b := i
    ) else skip) ;
    return b;
  operation next_number(N : OclAny) : OclAny
  pre: true post: true
  activity:
(compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name xrange)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name N)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])))) < (comparison (expr (atom (name N)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name K)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name N)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name p)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name find_least)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N))))))) , (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (name N)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name N)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name p)))))))) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name N)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))) : (test (logical_test (comparison (expr (atom (name p)))))))) ]))) + (expr (atom (name N)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name p))) + (expr (atom (number (integer 1)))))))) :)) ]))))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)) (trailer . (name sort) (arguments ( )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name K)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name d))) + (expr (atom '') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name p)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name find_least)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom '0'))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name N)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name p)))))))) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name N)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name p)))))))) ]))) + (expr (atom (name N)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name p))) + (expr (atom (number (integer 1)))))))) :)) ]))))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)) (trailer . (name sort) (arguments ( )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name K)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (name d))) + (expr (atom '0'))) + (expr (atom '') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))))))))))))) ;
    return K;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from skynet.math.numbers import digits
def dijkstra_next_perm(iterable):
    iterable=list(iterable)
    N=len(iterable)
    i=len(iterable)-1
    while iterable[i-1]>=iterable[i]:
        i-=1
    j=N
    while iterable[j-1]<=iterable[i-1]:
        j-=1
    iterable[i-1],iterable[j-1]=iterable[j-1],iterable[i-1]
    i+=1
    j=N
    while itoInteger() ;
    for i : Integer.subrange(0, t-1) do (    n := ("" + ((file.readLine())))->toInteger() ;
    execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{i + 1, next_number(n)}))->display()))
    catch (_e : OclException) do skip;
  operation dijkstra_next_perm(iterable : OclAny) : OclAny
  pre: true post: true
  activity:
    iterable := (iterable) ;
    var N : int := (iterable)->size() ;
    var i : double := (iterable)->size() - 1 ;
    while (iterable[i - 1+1]->compareTo(iterable[i+1])) >= 0 do (    i := i - 1) ;
    var j : int := N ;
    while (iterable[j - 1+1]->compareTo(iterable[i - 1+1])) <= 0 do (    j := j - 1) ;
    var iterable[i - 1+1] : OclAny := null;
    var iterable[j - 1+1] : OclAny := null;
    Sequence{iterable[i - 1+1],iterable[j - 1+1]} := Sequence{iterable[j - 1+1],iterable[i - 1+1]} ;
    i := i + 1 ;
    j := N ;
    while (i->compareTo(j)) < 0 do (    var iterable[i - 1+1] : OclAny := null;
    var iterable[j - 1+1] : OclAny := null;
    Sequence{iterable[i - 1+1],iterable[j - 1+1]} := Sequence{iterable[j - 1+1],iterable[i - 1+1]} ;
    i := i + 1 ;
    j := j - 1) ;
    return iterable;
  operation next_number(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var p : String := ("" + ((n))) ;
    try (    var m : int := ("" + ((StringLib.sumStringsWithSeparator((dijkstra_next_perm(p)), ''))))->toInteger())
(except_clause except (test (logical_test (comparison (expr (atom (name IndexError)))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name dijkstra_next_perm)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name p))) + (expr (atom '0')))))))) ))))))))) ))))))))) ))))))))))))) ;
    if (m->compareTo(n)) <= 0 then (
      return ("" + ((StringLib.sumStringsWithSeparator((dijkstra_next_perm(p + '0')), ''))))->toInteger()
    ) else skip ;
    return m;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def next_number(digits):
    if len(digits)==1 :
        return None
    if len(digits)==2 :
        return(digits[1],digits[0])if digits[1]>digits[0]else None
    rearrange=next_number(digits[1 :])
    if rearrange is not None :
        digits[1 :]=rearrange
        return digits
    larger=[d for d in digits if d>digits[0]]
    if larger :
        min_larger=min(larger)
        taildigits=delone(digits[:],min_larger)
        taildigits.sort()
        taildigits.insert(0,min_larger)
        return taildigits
    return None
def delone(taildigits,n):
    for i in range(len(taildigits)):
        if taildigits[i]==n :
            del taildigits[i]
            break
    return taildigits
with open('B-large.in')as f :
    o=open('bnumberout.txt','w')
    cases=int(f.next())
    for i in range(1,cases+1):
        o.write('Case #%d: ' % i)
        strn=f.next().strip()
        digits=[int(d)for d in strn]
        nextdigits=next_number(digits)
        if nextdigits is None :
            leader=min([d for d in digits if d>0])
            digits=delone(digits,leader)
            digits.sort()
            nextdigits=[leader,0]+digits
        nextnumber=''.join([str(d)for d in nextdigits])
        o.write(nextnumber+'\n')
    o.close()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    try (var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('B-large.in'));
    var o : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('bnumberout.txt')) ;
    var cases : int := ("" + ((f.next())))->toInteger() ;
    for i : Integer.subrange(1, cases + 1-1) do (    o.write(StringLib.format('Case #%d: ',i)) ;
    var strn : OclAny := f.next()->trim() ;
    digits := strn->select(d | true)->collect(d | (("" + ((d)))->toInteger())) ;
    var nextdigits : OclAny := next_number(digits) ;
    if nextdigits <>= null then (
      var leader : OclAny := (digits->select(d | d > 0)->collect(d | (d)))->min() ;
    digits := delone(digits, leader) ;
    digits := digits->sort() ;
    nextdigits := Sequence{leader}->union(Sequence{ 0 })->union(digits)
    ) else skip ;
    var nextnumber : String := StringLib.sumStringsWithSeparator((nextdigits->select(d | true)->collect(d | (("" + ((d)))))), '') ;
    o.write(nextnumber + '
')) ;
    o.closeFile())
    catch (_e : OclException) do skip;
  operation next_number(digits : OclAny) : OclAny
  pre: true post: true
  activity:
    if (digits)->size() = 1 then (
      return null
    ) else skip ;
    if (digits)->size() = 2 then (
      return if (digits[1+1]->compareTo(digits->first())) > 0 then Sequence{digits[1+1], digits->first()} else null endif
    ) else skip ;
    var rearrange : OclAny := next_number(digits->tail()) ;
    if not(rearrange <>= null) then (
      digits->tail() := rearrange ;
    return digits
    ) else skip ;
    var larger : Sequence := digits->select(d | (d->compareTo(digits->first())) > 0)->collect(d | (d)) ;
    if larger then (
      var min_larger : OclAny := (larger)->min() ;
    var taildigits : OclAny := delone(digits, min_larger) ;
    taildigits := taildigits->sort() ;
    taildigits := taildigits.insertAt(0+1, min_larger) ;
    return taildigits
    ) else skip ;
    return null;
  operation delone(taildigits : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    for i : Integer.subrange(0, (taildigits)->size()-1) do (    if taildigits[i+1] = n then (
      execute (taildigits[i+1])->isDeleted() ;
    break
    ) else skip) ;
    return taildigits;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
import math
OFFSET=20
def main():
    while True :
        r,n=map(int,sys.stdin.readline().split())
        if r==0 and n==0 :
            break
        seq=[0]*40
        for i in range(n):
            x1,x2,h=map(int,sys.stdin.readline().split())
            for k in range(x1,x2):
                seq[k+OFFSET]=max(seq[k+OFFSET],h)
        ans=9999999999
        for x in range(-r+1,r):
            y=min(seq[x+OFFSET-1],seq[x+OFFSET])
            t=y+r-math.sqrt(r*r-x*x)
            ans=min(ans,t)
        print("{0:.4f}".format(ans))
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var OFFSET : int := 20 ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    while true do (    var r : OclAny := null;
    var n : OclAny := null;
    Sequence{r,n} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if r = 0 & n = 0 then (
      break
    ) else skip ;
    var seq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 40) ;
    for i : Integer.subrange(0, n-1) do (    var x1 : OclAny := null;
    var x2 : OclAny := null;
    var h : OclAny := null;
    Sequence{x1,x2,h} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    for k : Integer.subrange(x1, x2-1) do (    seq[k + OFFSET+1] := Set{seq[k + OFFSET+1], h}->max())) ;
    var ans : int := 9999999999 ;
    for x : Integer.subrange(-r + 1, r-1) do (    var y : OclAny := Set{seq[x + OFFSET - 1+1], seq[x + OFFSET+1]}->min() ;
    var t : double := y + r - (r * r - x * x)->sqrt() ;
    ans := Set{ans, t}->min()) ;
    execute (StringLib.interpolateStrings("{0:.4f}", Sequence{ans}))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
l1=list(map(int,input().split()))
l1.sort()
a=l1[-1]
b=l1[0]
if a==b :
    print(a-b,(n)*(n-1)//2)
else :
    ac=l1.count(a)
    bc=l1.count(b)
    print(a-b,ac*bc)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    l1 := l1->sort() ;
    var a : OclAny := l1->last() ;
    var b : OclAny := l1->first() ;
    if a = b then  (
      execute (a - b)->display()
    )
    else (
      var ac : int := l1->count(a) ;
    var bc : int := l1->count(b) ;
    execute (a - b)->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def findNext(number):
    digits=[ch for ch in number.strip()]
    sorted=list(digits)
    sorted.sort()
    if len(number)==1 :
        return number+"0"
    cur=len(digits)-2
    while cur>=0 :
        if digits[cur]number[cur]])
        ret+=first
        remains=digits[cur :]
        remains.sort()
        remains.remove(first)
        ret+="".join(remains)
        return ret
def compare(A,B):
    pA=[ch for ch in A.strip()if ch!="0"]
    pB=[ch for ch in B.strip()if ch!="0"]
    pA.sort()
    pB.sort()
    return "".join(pA)=="".join(pB)
def findNext2(number):
    num=int(number)+1
    while 1 :
        if compare(str(num),number):
            return str(num)
        num+=1
if __name__=="__main__" :
    infile=open(sys.argv[1],"r")
    outfile=open("resultB.out","w")
    N=int(infile.readline().strip())
    for case in range(0,N):
        input=infile.readline().strip()
        outfile.write("Case #%d: %s\n" %(case+1,findNext(input)))
    infile.close()
    outfile.close()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      var infile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) ;
    var outfile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("resultB.out")) ;
    var N : int := ("" + ((infile.readLine()->trim())))->toInteger() ;
    for case : Integer.subrange(0, N-1) do (    var input : OclAny := infile.readLine()->trim() ;
    outfile.write(StringLib.format("Case #%d: %s\n",Sequence{case + 1, findNext(input)}))) ;
    infile.closeFile() ;
    outfile.closeFile()
    ) else skip;
  operation findNext(number : OclAny) : OclAny
  pre: true post: true
  activity:
    var digits : Sequence := number->trim()->select(ch | true)->collect(ch | (ch)) ;
    var sorted : Sequence := (digits) ;
    sorted := sorted->sort() ;
    if (number)->size() = 1 then (
      return number + "0"
    ) else skip ;
    var cur : double := (digits)->size() - 2 ;
    while cur >= 0 do (    if (digits[cur+1]->compareTo(digits[cur + 1+1])) < 0 then (
      break
    ) else skip ;
    cur := cur - 1) ;
    if cur = -1 then  (
      var ret : String := StringLib.sumStringsWithSeparator((sorted), "") ;
    ret := ret.replace("0", "") ;
    ret := ret->first() + StringLib.nCopies("0", (digits->count("0") + 1)) + ret->tail() ;
    return ret
    )
    else (
      ret := number.subrange(1,cur) ;
    var first : OclAny := (digits.subrange(cur+1)->select(dd | (dd->compareTo(number[cur+1])) > 0)->collect(dd | (dd)))->min() ;
    ret := ret + first ;
    var remains : OclAny := digits.subrange(cur+1) ;
    remains := remains->sort() ;
    execute ((first) /: remains) ;
    ret := ret + StringLib.sumStringsWithSeparator((remains), "") ;
    return ret
      );
  operation compare(A : OclAny, B : OclAny) : OclAny
  pre: true post: true
  activity:
    var pA : Sequence := A->trim()->select(ch | ch /= "0")->collect(ch | (ch)) ;
    var pB : Sequence := B->trim()->select(ch | ch /= "0")->collect(ch | (ch)) ;
    pA := pA->sort() ;
    pB := pB->sort() ;
    return StringLib.sumStringsWithSeparator((pA), "") = StringLib.sumStringsWithSeparator((pB), "");
  operation findNext2(number : OclAny) : OclAny
  pre: true post: true
  activity:
    var num : int := ("" + ((number)))->toInteger() + 1 ;
    while 1 do (    if compare(("" + ((num))), number) then (
      return ("" + ((num)))
    ) else skip ;
    num := num + 1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
d={}
count=0
for x in a :
    if x not in d : d[x]=0
    d[x]+=1
for i in range(len(a)):
    if d[a[i]]==0 :
        continue
    d[a[i]]-=1
    y=2**a[i].bit_length()-a[i]
    if y in d and d[y]>0 :
        count+=1
        d[y]-=1
print(count)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    a := a->sort() ;
    var d : OclAny := Set{} ;
    var count : int := 0 ;
    for x : a do (    if (d)->excludes(x) then (
      d[x+1] := 0
    ) else skip ;
    d[x+1] := d[x+1] + 1) ;
    for i : Integer.subrange(0, (a)->size()-1) do (    if d[a[i+1]+1] = 0 then (
      continue
    ) else skip ;
    d[a[i+1]+1] := d[a[i+1]+1] - 1 ;
    var y : double := (2)->pow(a[i+1].bit_length()) - a[i+1] ;
    if (d)->includes(y) & d[y+1] > 0 then (
      count := count + 1 ;
    d[y+1] := d[y+1] - 1
    ) else skip) ;
    execute (count)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
readline=sys.stdin.readline
N=int(readline())
A=list(map(int,readline().split()))
from collections import defaultdict
balls_count=defaultdict(int)
for a in A :
    balls_count[a]+=1
A=sorted(A,reverse=True)
def get_pair_num(x):
    tar=2
    while tar0 :
        ans+=1
        balls_count[pair]-=1
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var readline : OclAny := (OclFile["System.in"]).readline ;
    var N : int := ("" + ((readline())))->toInteger() ;
    var A : Sequence := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    skip ;
    var balls_count : OclAny := defaultdict(OclType["int"]) ;
    for a : A do (    balls_count[a+1] := balls_count[a+1] + 1) ;
    A := A->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ;
    skip ;
    var ans : int := 0 ;
    for ball : A do (    if balls_count[ball+1] = 0 then (
      continue
    ) else skip ;
    balls_count[ball+1] := balls_count[ball+1] - 1 ;
    var pair : OclAny := get_pair_num(ball) ;
    if balls_count[pair+1] > 0 then (
      ans := ans + 1 ;
    balls_count[pair+1] := balls_count[pair+1] - 1
    ) else skip) ;
    execute (ans)->display();
  operation get_pair_num(x : OclAny) : OclAny
  pre: true post: true
  activity:
    var tar : int := 2 ;
    while (tar->compareTo(x)) < 0 do (    tar := tar * 2) ;
    if tar = x then (
      return tar
    ) else skip ;
    return tar - x;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
arr=[100,1000,100,1000,1]
sum=[-1]*10000
def maxSumWO3Consec(n):
    if(sum[n]!=-1):
        return sum[n]
    if(n==0):
        sum[n]=0
        return sum[n]
    if(n==1):
        sum[n]=arr[0]
        return sum[n]
    if(n==2):
        sum[n]=arr[1]+arr[0]
        return sum[n]
    sum[n]=max(max(maxSumWO3Consec(n-1),maxSumWO3Consec(n-2)+arr[n-1]),arr[n-2]+arr[n-1]+maxSumWO3Consec(n-3))
    return sum[n]
if __name__=="__main__" :
    n=len(arr)
    print(maxSumWO3Consec(n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var arr : Sequence := Sequence{100}->union(Sequence{1000}->union(Sequence{100}->union(Sequence{1000}->union(Sequence{ 1 })))) ;
    var sum : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, 10000) ;
    skip ;
    if __name__ = "__main__" then (
      n := (arr)->size() ;
    execute (maxSumWO3Consec(n))->display()
    ) else skip;
  operation maxSumWO3Consec(n : OclAny) : OclAny
  pre: true post: true
  activity:
    if ([n+1]->sum() /= -1) then (
      return [n+1]->sum()
    ) else skip ;
    if (n = 0) then (
      [n+1]->sum() := 0 ;
    return [n+1]->sum()
    ) else skip ;
    if (n = 1) then (
      [n+1]->sum() := arr->first() ;
    return [n+1]->sum()
    ) else skip ;
    if (n = 2) then (
      [n+1]->sum() := arr[1+1] + arr->first() ;
    return [n+1]->sum()
    ) else skip ;
    [n+1]->sum() := Set{Set{maxSumWO3Consec(n - 1), maxSumWO3Consec(n - 2) + arr[n - 1+1]}->max(), arr[n - 2+1] + arr[n - 1+1] + maxSumWO3Consec(n - 3)}->max() ;
    return [n+1]->sum();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
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(100000)
input=sys.stdin.readline
INF=2**62-1
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(N,A):
    bp=list(reversed([2**i for i in range(2,32)]))
    C=Counter(A)
    ans=0
    A.sort(reverse=True)
    for k in A :
        if C[k]<=0 :
            continue
        C[k]-=1
        r=(1<0 :
            ans+=1
            C[r]-=1
    return ans
def main():
    N=read_int()
    A=read_int_n()
    print(slv(N,A))
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    sys.setrecursionlimit(100000) ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    var INF : double := (2)->pow(62) - 1 ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
(compound_stmt (decorator @ (dotted_name (name mt))) (funcdef def (name slv) ( (typedargslist (def_parameters (def_parameter (named_parameter (name N))) , (def_parameter (named_parameter (name A))))) ) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name bp)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name reversed)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) ** (expr (atom (name i))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 32))))))))) )))))))) ]))))))) ))))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name C)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name Counter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name A)) (trailer . (name sort) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) )))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name k)))) in (testlist (test (logical_test (comparison (expr (atom (name A))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name C)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])))) <= (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt continue)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name C)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name r)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name k)) (trailer . (name bit_length) (arguments ( ))))))))) ))) - (expr (atom (name k))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name C)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ])))) > (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name C)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ])))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name ans))))))))))))) ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation read_int() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation read_int_n() : OclAny
  pre: true post: true
  activity:
    return ((input().split())->collect( _x | (OclType["int"])->apply(_x) ));
  operation read_float() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toReal();
  operation read_float_n() : OclAny
  pre: true post: true
  activity:
    return ((input().split())->collect( _x | (OclType["double"])->apply(_x) ));
  operation read_str() : OclAny
  pre: true post: true
  activity:
    return input()->trim();
  operation read_str_n() : OclAny
  pre: true post: true
  activity:
    return ((input().split())->collect( _x | (OclType["String"])->apply(_x) ));
  operation error_print(args : OclAny : Sequence(OclAny))
  pre: true post: true
  activity:
(args * (named_parameter (name args)))    execute ((argument * (test (logical_test (comparison (expr (atom (name args))))))))->display();
  operation mt(f : OclAny) : OclAny
  pre: true post: true
  activity:
    skip ;
    skip ;
    return wrap;
  operation main()
  pre: true post: true
  activity:
    var N : OclAny := read_int() ;
    var A : OclAny := read_int_n() ;
    execute (slv(N, A))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import Counter
n=int(input())
a=[int(item)for item in input().split()]
a.sort()
ca=Counter(a)
max_a=a[-1]
ans=0
for item in a[: :-1]:
    if ca[item]==0 :
        continue
    for i in range(31,0,-1):
        inv=(1<max_a :
            continue
        if item==inv :
            if ca[inv]>1 :
                ans+=1
                ca[inv]-=2
                break
        else :
            if ca[inv]>0 :
                ans+=1
                ca[inv]-=1
                ca[item]-=1
                break
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := input().split()->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ;
    a := a->sort() ;
    var ca : OclAny := Counter(a) ;
    var max_a : OclAny := a->last() ;
    var ans : int := 0 ;
    for item : a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do (    if ca[item+1] = 0 then (
      continue
    ) else skip ;
    for i : Integer.subrange(0 + 1, 31)->reverse() do (    var inv : double := (1 * (2->pow(i))) - item ;
    if inv < 0 or (inv->compareTo(max_a)) > 0 then (
      continue
    ) else skip ;
    if item = inv then  (
      if ca[inv+1] > 1 then (
      ans := ans + 1 ;
    ca[inv+1] := ca[inv+1] - 2 ;
    break
    ) else skip
    )
    else (
      if ca[inv+1] > 0 then (
      ans := ans + 1 ;
    ca[inv+1] := ca[inv+1] - 1 ;
    ca[item+1] := ca[item+1] - 1 ;
    break
    ) else skip
      ))) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from bisect import bisect_right
n=int(input())
d={}
amax=0
for a in map(int,input().split()):
    if a in d :
        d[a]+=1
    else :
        d[a]=1
amax=max(d.keys())
t=1
valids=[]
while t<2*amax :
    t*=2
    valids.append(t)
result=0
while True :
    prev=result
    keys=list(sorted(d.keys(),reverse=True))
    for x in keys :
        if x not in d :
            continue
        t=valids[bisect_right(valids,x)]-x
        while True :
            if t not in d :
                break
            if x==t and d[x]==1 :
                break
            result+=1
            if d[x]==1 :
                del d[x]
            else :
                d[x]-=1
            if d[t]==1 :
                del d[t]
            else :
                d[t]-=1
            if x not in d :
                break
    if prev==result :
        break
print(result)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var d : OclAny := Set{} ;
    var amax : int := 0 ;
    for a : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do (    if (d)->includes(a) then  (
      d[a+1] := d[a+1] + 1
    )
    else (
      d[a+1] := 1
      )) ;
    amax := (d.keys())->max() ;
    var t : int := 1 ;
    var valids : Sequence := Sequence{} ;
    while (t->compareTo(2 * amax)) < 0 do (    t := t * 2 ;
    execute ((t) : valids)) ;
    var result : int := 0 ;
    while true do (    var prev : int := result ;
    var keys : Sequence := (d.keys()->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True))))))))) ;
    for x : keys do (    if (d)->excludes(x) then (
      continue
    ) else skip ;
    t := valids[bisect_right(valids, x)+1] - x ;
    while true do (    if (d)->excludes(t) then (
      break
    ) else skip ;
    if x = t & d[x+1] = 1 then (
      break
    ) else skip ;
    result := result + 1 ;
    if d[x+1] = 1 then  (
      execute (d[x+1])->isDeleted()
    )
    else (
      d[x+1] := d[x+1] - 1
      ) ;
    if d[t+1] = 1 then  (
      execute (d[t+1])->isDeleted()
    )
    else (
      d[t+1] := d[t+1] - 1
      ) ;
    if (d)->excludes(x) then (
      break
    ) else skip)) ;
    if prev = result then (
      break
    ) else skip) ;
    execute (result)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def ncr(n,r):
    res=1
    for i in range(1,r+1):
        res*=(n-r+i)
        res//=i
    return res
def NoofSequences(N,M):
    prime={}
    for i in range(2,int(M**(.5))+1):
        while(M % i==0):
            prime[i]=prime.get(i,0)+1
            M//=i
    if(M>1):
        prime[M]=prime.get(M,0)+1
    ans=1
    for it in prime :
        ans*=(ncr(N+prime[it]-1,N-1))
    return ans
N=2
M=6
print(NoofSequences(N,M))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    N := 2 ;
    M := 6 ;
    execute (NoofSequences(N, M))->display();
  operation ncr(n : OclAny, r : OclAny) : OclAny
  pre: true post: true
  activity:
    var res : int := 1 ;
    for i : Integer.subrange(1, r + 1-1) do (    res := res * (n - r + i) ;
    res := res div i) ;
    return res;
  operation NoofSequences(N : OclAny, M : OclAny) : OclAny
  pre: true post: true
  activity:
    var prime : OclAny := Set{} ;
    for i : Integer.subrange(2, ("" + (((M)->pow((.5)))))->toInteger() + 1-1) do (    while (M mod i = 0) do (    prime[i+1] := prime.get(i, 0) + 1 ;
    M := M div i)) ;
    if (M > 1) then (
      prime[M+1] := prime.get(M, 0) + 1
    ) else skip ;
    var ans : int := 1 ;
    for it : prime do (    ans := ans * (ncr(N + prime[it+1] - 1, N - 1))) ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
class TrieNode :
    def __init__(self):
        self.child=[None]*2
        self.value=None
class Trie :
    def __init__(self):
        self.root=self.getNode()
    def getNode(self):
        return TrieNode()
    def insert(self,key):
        temp=self.root
        for i in range(31,-1,-1):
            curr=(key>>i)&(1)
            if(temp.child[curr]is None):
                temp.child[curr]=self.getNode()
            temp=temp.child[curr]
        temp.value=key
    def xorUtil(self,key):
        temp=self.root
        for i in range(31,-1,-1):
            curr=(key>>i)& 1
            if(temp.child[curr]is not None):
                temp=temp.child[curr]
            elif(temp.child[1-curr]is not None):
                temp=temp.child[1-curr]
        return temp.value ^ key
def minXor(arr):
    m=2**30
    trie=Trie()
    trie.insert(arr[0])
    for i in range(1,len(arr)):
        m=min(m,trie.xorUtil(arr[i]))
        trie.insert(arr[i])
    return m
if __name__=="__main__" :
    sample=[9,5,3]
    print(minXor(sample))
------------------------------------------------------------
OCL File:
---------
class TrieNode {
  static operation newTrieNode() : TrieNode
  pre: true
  post: TrieNode->exists( _x | result = _x );
  attribute child : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, 2);
  attribute value : OclAny := null;
  operation initialise() : TrieNode
  pre: true post: true
  activity:
    self.child := MatrixLib.elementwiseMult(Sequence{ null }, 2) ;
    self.value := null;
    return self;
}
class Trie {
  static operation newTrie() : Trie
  pre: true
  post: Trie->exists( _x | result = _x );
  attribute root : OclAny := self.getNode();
  operation initialise() : Trie
  pre: true post: true
  activity:
    self.root := self.getNode();
    return self;
  operation getNode() : OclAny
  pre: true post: true
  activity:
    return (TrieNode.newTrieNode()).initialise();
  operation insert(key : OclAny)
  pre: true post: true
  activity:
    var temp : OclAny := self.root ;
    for i : Integer.subrange(-1 + 1, 31)->reverse() do (    var curr : int := MathLib.bitwiseAnd((key /(2->pow(i))), (1)) ;
    if (temp.child[curr+1] <>= null) then (
      temp.child[curr+1] := self.getNode()
    ) else skip ;
    temp := temp.child[curr+1]) ;
    temp.value := key;
  operation xorUtil(key : OclAny) : OclAny
  pre: true post: true
  activity:
    temp := self.root ;
    for i : Integer.subrange(-1 + 1, 31)->reverse() do (    curr := MathLib.bitwiseAnd((key /(2->pow(i))), 1) ;
    if (not(temp.child[curr+1] <>= null)) then  (
      temp := temp.child[curr+1]
    )
    else (if (not(temp.child[1 - curr+1] <>= null)) then
   (
      temp := temp.child[1 - curr+1]    
)
 else skip)) ;
    return MathLib.bitwiseXor(temp.value, key);
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      var sample : Sequence := Sequence{9}->union(Sequence{5}->union(Sequence{ 3 })) ;
    execute (minXor(sample))->display()
    ) else skip;
  operation minXor(arr : OclAny) : OclAny
  pre: true post: true
  activity:
    var m : double := (2)->pow(30) ;
    var trie : Trie := (Trie.newTrie()).initialise() ;
    trie := trie.insertAt(arr->first()+1, arr->first()) ;
    for i : Integer.subrange(1, (arr)->size()-1) do (    m := Set{m, trie.xorUtil(arr[i+1])}->min() ;
    trie := trie.insertAt(arr[i+1]+1, arr[i+1])) ;
    return m;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def ladder_pattern(N):
    for i in range(N+1):
        print("**");
        print("**");
        if(idisplay(); ;
    execute ("**")->display(); ;
    if ((i->compareTo(N)) < 0) then (
      execute ("*****")->display();
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def bitsoncount(x):
    return bin(x).count('1')
def find_count(arr):
    ans=0
    for i in arr :
        x=bitsoncount(i)
        if(i % x==0):
            ans+=1
    return ans
arr=[1,2,3,4,5,6]
print(find_count(arr))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))))) ;
    execute (find_count(arr))->display();
  operation bitsoncount(x : OclAny) : OclAny
  pre: true post: true
  activity:
    return bin(x)->count('1');
  operation find_count(arr : OclAny) : OclAny
  pre: true post: true
  activity:
    var ans : int := 0 ;
    for i : arr do (    x := bitsoncount(i) ;
    if (i mod x = 0) then (
      ans := ans + 1
    ) else skip) ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N,M=map(int,input().split())
a=[]
for _ in range(M):
    n,m=map(int,input().split())
    a.append(n)
a.sort(reverse=True)
result=0
for i in range(M-1):
    if a[i]collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : Sequence := Sequence{} ;
    for _anon : Integer.subrange(0, M-1) do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute ((n) : a)) ;
    a := a->sort() ;
    var result : int := 0 ;
    for i : Integer.subrange(0, M - 1-1) do (    if (a[i+1]->compareTo(N)) < 0 then (
      result := result + N - a[i+1]
    ) else skip) ;
    execute (result)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def solve(cards,n,m):
    ans=0
    for _ in range(1,m):
        atari,_=cards.pop()
        ans+=max(0,n-atari)
    return ans
def main(args):
    n,m=map(int,input().split())
    cards=sorted([[int(i)for i in input().split()]for _ in range(m)])
    ans=solve(cards,n,m)
    print(ans)
if __name__=='__main__' :
    main(sys.argv[1 :])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))
    ) else skip;
  operation solve(cards : OclAny, n : OclAny, m : OclAny) : OclAny
  pre: true post: true
  activity:
    var ans : int := 0 ;
    for _anon : Integer.subrange(1, m-1) do (    var atari : OclAny := null;
    var _anon : OclAny := null;
    Sequence{atari,_anon} := cards->last() ;     cards := cards->front() ;
    ans := ans + Set{0, n - atari}->max()) ;
    return ans;
  operation main(args : OclAny)
  pre: true post: true
  activity:
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    cards := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))))->sort() ;
    ans := solve(cards, n, m) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m=[int(s)for s in input().split(" ")]
a=[int(input().split(" ")[0])for i in range(m)]
a.sort()
if a[1]>=n : print(0)
else :
    cost=0
    ac=a[1 :]
    for i in ac :
        if iselect(s | true)->collect(s | (("" + ((s)))->toInteger())) ;
    var a : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (("" + ((input().split(" ")->first())))->toInteger())) ;
    a := a->sort() ;
    if (a[1+1]->compareTo(n)) >= 0 then  (
      execute (0)->display()
    )
    else (
      var cost : int := 0 ;
    var ac : OclAny := a->tail() ;
    for i : ac do (    if (i->compareTo(n)) < 0 then  (
      cost := cost + n - i
    )
    else (
      execute (cost)->display() ;
    break
      ))
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m=map(int,input().split())
ab=[list(map(int,input().split()))for _ in range(m)]
less=[]
cnt=0
expense=0
for i in range(m):
    if ab[i][0]>=n :
        cnt+=1
    else :
        less.append(ab[i][1]-n)
if cntcollect( _x | (OclType["int"])->apply(_x) ) ;
    var ab : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    var less : Sequence := Sequence{} ;
    var cnt : int := 0 ;
    var expense : int := 0 ;
    for i : Integer.subrange(0, m-1) do (    if (ab[i+1]->first()->compareTo(n)) >= 0 then  (
      cnt := cnt + 1
    )
    else (
      execute ((ab[i+1][1+1] - n) : less)
      )) ;
    if (cnt->compareTo(m - 1)) < 0 then (
      less := less->sort() ;
    expense := (less.subrange(1,m - 1 - cnt))->sum()
    ) else skip ;
    execute (expense)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def FindElement(A,n):
    for i in range(0,n,1):
        flag=0
        for j in range(0,i,1):
            if(A[j]>=A[i]):
                flag=1
                break
        for j in range(i+1,n,1):
            if(A[j]<=A[i]):
                flag=1
                break
        if(flag==0):
            return A[i]
    return-1
if __name__=='__main__' :
    A=[4,3,2,5,8,6,7]
    n=len(A)
    print(FindElement(A,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      A := Sequence{4}->union(Sequence{3}->union(Sequence{2}->union(Sequence{5}->union(Sequence{8}->union(Sequence{6}->union(Sequence{ 7 })))))) ;
    n := (A)->size() ;
    execute (FindElement(A, n))->display()
    ) else skip;
  operation FindElement(A : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do (    var flag : int := 0 ;
    for j : Integer.subrange(0, i-1)->select( $x | ($x - 0) mod 1 = 0 ) do (    if ((A[j+1]->compareTo(A[i+1])) >= 0) then (
      flag := 1 ;
    break
    ) else skip) ;
    for j : Integer.subrange(i + 1, n-1)->select( $x | ($x - i + 1) mod 1 = 0 ) do (    if ((A[j+1]->compareTo(A[i+1])) <= 0) then (
      flag := 1 ;
    break
    ) else skip) ;
    if (flag = 0) then (
      return A[i+1]
    ) else skip) ;
    return -1;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N,M=map(int,input().split())
keihin=M-1
cards=[]
for _ in range(M):
    cards.append(list(map(int,input().split())))
ans=0
sorted_cards=sorted(cards,key=lambda x : x[0],reverse=True)
cnt=0
while cnt=N :
        cnt+=1
    else :
        ans+=(N-sorted_cards[cnt][0])
        cnt+=1
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : OclAny := null;
    var M : OclAny := null;
    Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var keihin : double := M - 1 ;
    var cards : Sequence := Sequence{} ;
    for _anon : Integer.subrange(0, M-1) do (    execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : cards)) ;
    var ans : int := 0 ;
    var sorted_cards : Sequence := cards->sortedBy($x | (lambda x : OclAny in (x->first()))->apply($x)) ;
    var cnt : int := 0 ;
    while (cnt->compareTo(keihin)) < 0 do (    if (sorted_cards[cnt+1]->first()->compareTo(N)) >= 0 then  (
      cnt := cnt + 1
    )
    else (
      ans := ans + (N - sorted_cards[cnt+1]->first()) ;
    cnt := cnt + 1
      )) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s1=input()
s2=input()
freq={}
for ch in s1 :
    if ch==' ' :
        continue
    if ch in freq :
        freq[ch]+=1
    else :
        freq[ch]=1
ans=True
for ch in s2 :
    if ch==' ' :
        continue
    if ch not in freq :
        ans=False
        break
    freq[ch]-=1
    if freq[ch]<0 :
        ans=False
        break
print('YES' if ans else 'NO')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s1 : String := (OclFile["System.in"]).readLine() ;
    var s2 : String := (OclFile["System.in"]).readLine() ;
    var freq : OclAny := Set{} ;
    for ch : s1->characters() do (    if ch = ' ' then (
      continue
    ) else skip ;
    if (freq)->includes(ch) then  (
      freq[ch+1] := freq[ch+1] + 1
    )
    else (
      freq[ch+1] := 1
      )) ;
    var ans : boolean := true ;
    for ch : s2->characters() do (    if ch = ' ' then (
      continue
    ) else skip ;
    if (freq)->excludes(ch) then (
      ans := false ;
    break
    ) else skip ;
    freq[ch+1] := freq[ch+1] - 1 ;
    if freq[ch+1] < 0 then (
      ans := false ;
    break
    ) else skip) ;
    execute (if ans then 'YES' else 'NO' endif)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s1=list(input().split())
si1=''.join(s1)
st1=list(si1)
s2=list(input().split())
si2=''.join(s2)
st2=list(si2)
flag=True
for i in st2 :
    if i in st1 :
        j=0
        while(jcharacters() ;
    var s2 : Sequence := (input().split()) ;
    var si2 : String := StringLib.sumStringsWithSeparator((s2), '') ;
    var st2 : Sequence := (si2)->characters() ;
    var flag : boolean := true ;
    for i : st2 do (    if (st1)->includes(i) then  (
      var j : int := 0 ;
    while ((j->compareTo((st1)->size())) < 0) do (    if st1[j+1] = i then (
      st1 := st1->excludingAt(j+1) ;
    break
    ) else skip ;
    j := j + 1)
    )
    else (
      execute ("NO")->display() ;
    flag := false ;
    break
      )) ;
    if flag then (
      execute ("YES")->display()
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import*
s1=input().split()
ss1=""
ss2=""
for i in range(len(s1)): ss1+=s1[i]
c=Counter(ss1)
s2=input().split()
for i in range(len(s2)): ss2+=s2[i]
b=1
for i in range(len(ss2)):
    if c[ss2[i]]>0 : c[ss2[i]]-=1 ; continue
    else : b=0 ; break
if b : print("YES")
else : print("NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var s1 : OclAny := input().split() ;
    var ss1 : String := "" ;
    var ss2 : String := "" ;
    for i : Integer.subrange(0, (s1)->size()-1) do (    ss1 := ss1 + s1[i+1]) ;
    var c : OclAny := Counter(ss1) ;
    var s2 : OclAny := input().split() ;
    for i : Integer.subrange(0, (s2)->size()-1) do (    ss2 := ss2 + s2[i+1]) ;
    var b : int := 1 ;
    for i : Integer.subrange(0, (ss2)->size()-1) do (    if c[ss2[i+1]+1] > 0 then  (
      c[ss2[i+1]+1] := c[ss2[i+1]+1] - 1;    continue
    )
    else (
      b := 0;    break
      )) ;
    if b then  (
      execute ("YES")->display()
    )
    else (
      execute ("NO")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s1=input()
s2=input()
a=[0]*26
b=[0]*26
for i in s1 :
    if i!=" " :
        if ord(i)<97 :
            a[ord(i)-65]+=1
        else :
            b[ord(i)-97]+=1
for i in s2 :
    if i!=" " :
        if ord(i)<97 :
            a[ord(i)-65]-=1
        else :
            b[ord(i)-97]-=1
flag=0
for i in range(26):
    if a[i]<0 or b[i]<0 :
        flag=1
if flag==1 :
    print("NO")
else :
    print("YES")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s1 : String := (OclFile["System.in"]).readLine() ;
    var s2 : String := (OclFile["System.in"]).readLine() ;
    var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ;
    var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ;
    for i : s1->characters() do (    if i /= " " then (
      if (i)->char2byte() < 97 then  (
      a[(i)->char2byte() - 65+1] := a[(i)->char2byte() - 65+1] + 1
    )
    else (
      b[(i)->char2byte() - 97+1] := b[(i)->char2byte() - 97+1] + 1
      )
    ) else skip) ;
    for i : s2->characters() do (    if i /= " " then (
      if (i)->char2byte() < 97 then  (
      a[(i)->char2byte() - 65+1] := a[(i)->char2byte() - 65+1] - 1
    )
    else (
      b[(i)->char2byte() - 97+1] := b[(i)->char2byte() - 97+1] - 1
      )
    ) else skip) ;
    var flag : int := 0 ;
    for i : Integer.subrange(0, 26-1) do (    if a[i+1] < 0 or b[i+1] < 0 then (
      flag := 1
    ) else skip) ;
    if flag = 1 then  (
      execute ("NO")->display()
    )
    else (
      execute ("YES")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def main():
    n=int(input())
    a=list(map(int,input().split()))
    s=sum(a)
    if s %((n+1)*n//2)!=0 :
        print('NO')
        return
    s//=((n+1)*n//2)
    b=[a[(i+1)% n]-a[i]for i in range(n)]
    for i in range(n):
        b[i]-=s
    for i in range(n):
        if b[i]>0 or b[i]% n!=0 :
            print('NO')
            return
    print('YES')
main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    main();
  operation main()
  pre: true post: true
  activity:
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var s : OclAny := (a)->sum() ;
    if s mod ((n + 1) * n div 2) /= 0 then (
      execute ('NO')->display() ;
    return
    ) else skip ;
    s := s div ((n + 1) * n div 2) ;
    var b : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (a[(i + 1) mod n+1] - a[i+1])) ;
    for i : Integer.subrange(0, n-1) do (    b[i+1] := b[i+1] - s) ;
    for i : Integer.subrange(0, n-1) do (    if b[i+1] > 0 or b[i+1] mod n /= 0 then (
      execute ('NO')->display() ;
    return
    ) else skip) ;
    execute ('YES')->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s1=input()
s2=input()
hashmap={}
for i in s1 :
    if i!=' ' :
        hashmap[i]=hashmap.get(i,0)+1
flag=True
for i in s2 :
    if i==' ' :
        continue
    if i not in hashmap or hashmap[i]==0 :
        flag=False
        break
    else :
        hashmap[i]-=1
print("YES" if flag else "NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s1 : String := (OclFile["System.in"]).readLine() ;
    var s2 : String := (OclFile["System.in"]).readLine() ;
    var hashmap : OclAny := Set{} ;
    for i : s1->characters() do (    if i /= ' ' then (
      hashmap[i+1] := hashmap.get(i, 0) + 1
    ) else skip) ;
    var flag : boolean := true ;
    for i : s2->characters() do (    if i = ' ' then (
      continue
    ) else skip ;
    if (hashmap)->excludes(i) or hashmap[i+1] = 0 then  (
      flag := false ;
    break
    )
    else (
      hashmap[i+1] := hashmap[i+1] - 1
      )) ;
    execute (if flag then "YES" else "NO" endif)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import defaultdict
import sys
sys.setrecursionlimit(1000000)
def dfs(graph,visited,x,c):
    visited[x]=c
    for nx in graph[x]:
        if visited[nx]==c :
            return False
        if visited[nx]==0 and not dfs(graph,visited,nx,-c):
            return False
    return True
while True :
    n,m=list(map(int,input().split()))
    if n==0 :
        break
    graph=defaultdict(list)
    visited=[0 for i in range(n+1)]
    for i in range(m):
        u,v=list(map(int,input().split()))
        graph[u].append(v)
        graph[v].append(u)
    f=dfs(graph,visited,1,1)
    if f==False :
        print(0)
    else :
        ans1,ans2=0,0
        for i in range(1,n+1):
            if visited[i]>0 :
                ans1+=1
            elif visited[i]<0 :
                ans2+=1
        ans=set()
        if ans1 % 2==0 :
            ans.add(ans1//2)
        if ans2 % 2==0 :
            ans.add(ans2//2)
        print(len(ans))
        for e in sorted(ans):
            print(e)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    sys.setrecursionlimit(1000000) ;
    skip ;
    while true do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    if n = 0 then (
      break
    ) else skip ;
    graph := defaultdict(OclType["Sequence"]) ;
    visited := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ;
    for i : Integer.subrange(0, m-1) do (    var u : OclAny := null;
    var v : OclAny := null;
    Sequence{u,v} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
(expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) ;
(expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)))))))) ))))) ;
    var f : OclAny := dfs(graph, visited, 1, 1) ;
    if f = false then  (
      execute (0)->display()
    )
    else (
      var ans1 : OclAny := null;
    var ans2 : OclAny := null;
    Sequence{ans1,ans2} := Sequence{0,0} ;
    for i : Integer.subrange(1, n + 1-1) do (    if visited[i+1] > 0 then  (
      ans1 := ans1 + 1
    )
    else (if visited[i+1] < 0 then
   (
      ans2 := ans2 + 1    
)
 else skip)) ;
    var ans : Set := Set{}->union(()) ;
    if ans1 mod 2 = 0 then (
      execute ((ans1 div 2) : ans)
    ) else skip ;
    if ans2 mod 2 = 0 then (
      execute ((ans2 div 2) : ans)
    ) else skip ;
    execute ((ans)->size())->display() ;
    for e : ans->sort() do (    execute (e)->display())
      ));
  operation dfs(graph : OclAny, visited : OclAny, x : OclAny, c : OclAny) : OclAny
  pre: true post: true
  activity:
    visited[x+1] := c ;
    for nx : graph[x+1] do (    if visited[nx+1] = c then (
      return false
    ) else skip ;
    if visited[nx+1] = 0 & not(dfs(graph, visited, nx, -c)) then (
      return false
    ) else skip) ;
    return true;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
sys.setrecursionlimit(5000)
def dfs(x):
    global ng,parity
    for v in adj[x]:
        if parity[v]==parity[x]:
            ng=True
            return
        elif parity[v]<0 :
            parity[v]=1 ^ parity[x]
            dfs(v)
    return
while True :
    n,m=map(int,input().split())
    if n==0 and m==0 :
        break
    adj=[[]for _ in range(n)]
    parity=[-1 for _ in range(n)]
    for _ in range(m):
        a,b=map(int,input().split())
        adj[a-1].append(b-1)
        adj[b-1].append(a-1)
    ng=False
    parity[0]=0
    dfs(0)
    if ng :
        print(0)
        continue
    ans=[]
    zero=parity.count(0)
    if zero % 2==0 :
        ans.append(zero//2)
    if(n-zero)% 2==0 and zero*2!=n :
        ans.append((n-zero)//2)
    ans.sort()
    print(len(ans))
    if ans :
        print(*ans,sep="\n")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  attribute ng : OclAny;
  attribute parity : OclAny;
  operation initialise()
  pre: true post: true
  activity:     skip ;
    sys.setrecursionlimit(5000) ;
    skip ;
    while true do (    var n : OclAny := null;
    var m : OclAny := null;
    Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if n = 0 & m = 0 then (
      break
    ) else skip ;
    var adj : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ;
    parity := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (-1)) ;
    for _anon : Integer.subrange(0, m-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
(expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) )))) ;
(expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ))))) ;
    ng := false ;
    parity->first() := 0 ;
    dfs(0) ;
    if ng then (
      execute (0)->display() ;
    continue
    ) else skip ;
    var ans : Sequence := Sequence{} ;
    var zero : int := parity->count(0) ;
    if zero mod 2 = 0 then (
      execute ((zero div 2) : ans)
    ) else skip ;
    if (n - zero) mod 2 = 0 & zero * 2 /= n then (
      execute (((n - zero) div 2) : ans)
    ) else skip ;
    ans := ans->sort() ;
    execute ((ans)->size())->display() ;
    if ans then (
      execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()
    ) else skip);
  operation dfs(x : OclAny)
  pre: true post: true
  activity:
    skip;    skip ;
    for v : adj[x+1] do (    if parity[v+1] = parity[x+1] then  (
      ng := true ;
    return
    )
    else (if parity[v+1] < 0 then
   (
      parity[v+1] := MathLib.bitwiseXor(1, parity[x+1]) ;
    dfs(v)    
)
 else skip)) ;
    return;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def nthTerm(n):
    return 4*pow(n,2)-7*n+3
N=4
print(nthTerm(N))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var N : int := 4 ;
    execute (nthTerm(N))->display();
  operation nthTerm(n : OclAny) : OclAny
  pre: true post: true
  activity:
    return 4 * (n)->pow(2) - 7 * n + 3;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
PI=3.14159/180 ;
def areaOfKite(a,b,angle):
    angle=angle*PI ;
    area=a*b*math.sin(angle);
    return area ;
a=4 ; b=7 ; angle=78 ;
print("Area of Kite=",areaOfKite(a,b,angle));
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var PI : double := 3.14159 / 180; ;
    skip ;
    a := 4;    b := 7;    angle := 78; ;
    execute ("Area of Kite=")->display();;
  operation areaOfKite(a : OclAny, b : OclAny, angle : OclAny)
  pre: true post: true
  activity:
    angle := angle * PI; ;
    var area : double := a * b * (angle)->sin(); ;
    return area;;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def deleteElement(A,L,R,N):
    B=[]
    for i in range(0,N,1):
        if(i<=L or i>=R):
            B.append(A[i])
    return B
if __name__=='__main__' :
    A=[3,5,3,4,9,3,1,6,3,11,12,3]
    L=2
    R=7
    n=len(A)
    res=deleteElement(A,L,R,n)
    for i in range(len(res)):
        print(res[i],end=" ")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      A := Sequence{3}->union(Sequence{5}->union(Sequence{3}->union(Sequence{4}->union(Sequence{9}->union(Sequence{3}->union(Sequence{1}->union(Sequence{6}->union(Sequence{3}->union(Sequence{11}->union(Sequence{12}->union(Sequence{ 3 }))))))))))) ;
    L := 2 ;
    R := 7 ;
    var n : int := (A)->size() ;
    var res : OclAny := deleteElement(A, L, R, n) ;
    for i : Integer.subrange(0, (res)->size()-1) do (    execute (res[i+1])->display())
    ) else skip;
  operation deleteElement(A : OclAny, L : OclAny, R : OclAny, N : OclAny) : OclAny
  pre: true post: true
  activity:
    var B : Sequence := Sequence{} ;
    for i : Integer.subrange(0, N-1)->select( $x | ($x - 0) mod 1 = 0 ) do (    if ((i->compareTo(L)) <= 0 or (i->compareTo(R)) >= 0) then (
      execute ((A[i+1]) : B)
    ) else skip) ;
    return B;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def findK(n,k):
    a=list()
    i=1
    while idisplay();
  operation findK(n : OclAny, k : OclAny) : OclAny
  pre: true post: true
  activity:
    var a : Sequence := () ;
    var i : int := 1 ;
    while (i->compareTo(n)) < 0 do (    execute ((i) : a) ;
    i := i + 2) ;
    i := 2 ;
    while (i->compareTo(n)) < 0 do (    execute ((i) : a) ;
    i := i + 2) ;
    return (a[k - 1+1]);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import factorial as fact
def countPairs(m,n):
    ans=fact(2*m+n-1)//(fact(n-1)*fact(2*m))
    return(ans %(10**9+7))
n,m=5,3
print(countPairs(m,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    Sequence{n,m} := Sequence{5,3} ;
    execute (countPairs(m, n))->display();
  operation countPairs(m : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var ans : int := fact(2 * m + n - 1) div (fact(n - 1) * fact(2 * m)) ;
    return (ans mod ((10)->pow(9) + 7));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
class Solution(object):
    def canPlaceFlowers(self,flowerbed,n):
        count=0
        for i in range(len(flowerbed)):
            curr=flowerbed[i]
            if i-1>=0 :
                curr+=flowerbed[i-1]
            if i+1=n :
                    return True
        return False
------------------------------------------------------------
OCL File:
---------
class Solution extends object {
  static operation newSolution() : Solution
  pre: true
  post: Solution->exists( _x | result = _x );
  operation canPlaceFlowers(flowerbed : OclAny,n : OclAny) : OclAny
  pre: true post: true
  activity:
    var count : int := 0 ;
    for i : Integer.subrange(0, (flowerbed)->size()-1) do (    var curr : OclAny := flowerbed[i+1] ;
    if i - 1 >= 0 then (
      curr := curr + flowerbed[i - 1+1]
    ) else skip ;
    if (i + 1->compareTo((flowerbed)->size())) < 0 then (
      curr := curr + flowerbed[i + 1+1]
    ) else skip ;
    if curr = 0 then (
      count := count + 1 ;
    flowerbed[i+1] := 1 ;
    if (count->compareTo(n)) >= 0 then (
      return true
    ) else skip
    ) else skip) ;
    return false;
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
class Solution(object):
    def lowestCommonAncestor(self,root,p,q):
        stack=[root]
        parent={root : None}
        while p not in parent or q not in parent :
            node=stack.pop()
            if node.left :
                parent[node.left]=node
                stack.append(node.left)
            if node.right :
                parent[node.right]=node
                stack.append(node.right)
        ancestors=set()
        while p :
            ancestors.add(p)
            p=parent[p]
        while q not in ancestors :
            q=parent[q]
        return q
------------------------------------------------------------
OCL File:
---------
class Solution extends object {
  static operation newSolution() : Solution
  pre: true
  post: Solution->exists( _x | result = _x );
  operation lowestCommonAncestor(root : OclAny,p : OclAny,q : OclAny) : OclAny
  pre: true post: true
  activity:
    var stack : Sequence := Sequence{ root } ;
    var parent : Map := Map{ root |-> null } ;
    while (parent)->excludes(p) or (parent)->excludes(q) do (    var node : OclAny := stack->last() ;     stack := stack->front() ;
    if node.left then (
      parent[node.left+1] := node ;
    execute ((node.left) : stack)
    ) else skip ;
    if node.right then (
      parent[node.right+1] := node ;
    execute ((node.right) : stack)
    ) else skip) ;
    var ancestors : Set := Set{}->union(()) ;
    while p do (    execute ((p) : ancestors) ;
    p := parent[p+1]) ;
    while (ancestors)->excludes(q) do (    q := parent[q+1]) ;
    return q;
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
import heapq
sys.setrecursionlimit(10**8)
ini=lambda : int(sys.stdin.readline())
inm=lambda : map(int,sys.stdin.readline().split())
inl=lambda : list(inm())
ins=lambda : sys.stdin.readline().rstrip()
N=ini()
A=inl()
assert len(A)==N
def solve():
    if N==1 :
        return True
    asum=sum(A)
    k=N*(N+1)//2
    if asum % k!=0 :
        return False
    t=asum//k
    B=[None]*N
    for i in range(N-1):
        B[i]=A[i+1]-A[i]
    B[N-1]=A[0]-A[N-1]
    if sum(B)!=0 :
        return False
    bmax=max(B)
    B.sort()
    s=0
    for b in B :
        if(bmax-b)% N!=0 :
            return False
        s+=(bmax-b)//N
    return s==t
print("YES" if solve()else "NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    sys.setrecursionlimit((10)->pow(8)) ;
    var ini : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ;
    var inm : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var inl : Function := lambda $$ : OclAny in ((inm->apply())) ;
    var ins : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ;
    var N : OclAny := ini->apply() ;
    var A : OclAny := inl->apply() ;
    assert (A)->size() = N do "assertion failed" ;
    skip ;
    execute (if solve() then "YES" else "NO" endif)->display();
  operation solve() : OclAny
  pre: true post: true
  activity:
    if N = 1 then (
      return true
    ) else skip ;
    var asum : OclAny := (A)->sum() ;
    var k : int := N * (N + 1) div 2 ;
    if asum mod k /= 0 then (
      return false
    ) else skip ;
    var t : int := asum div k ;
    var B : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, N) ;
    for i : Integer.subrange(0, N - 1-1) do (    B[i+1] := A[i + 1+1] - A[i+1]) ;
    B[N - 1+1] := A->first() - A[N - 1+1] ;
    if (B)->sum() /= 0 then (
      return false
    ) else skip ;
    var bmax : OclAny := (B)->max() ;
    B := B->sort() ;
    var s : int := 0 ;
    for b : B do (    if (bmax - b) mod N /= 0 then (
      return false
    ) else skip ;
    s := s + (bmax - b) div N) ;
    return s = t;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def minCoins(coins,m,V):
    if(V==0):
        return 0
    res=sys.maxsize
    for i in range(0,m):
        if(coins[i]<=V):
            sub_res=minCoins(coins,m,V-coins[i])
            if(sub_res!=sys.maxsize and sub_res+1union(Sequence{6}->union(Sequence{5}->union(Sequence{ 1 }))) ;
    m := (coins)->size() ;
    V := 11 ;
    execute ("Minimum coins required is")->display();
  operation minCoins(coins : OclAny, m : OclAny, V : OclAny) : OclAny
  pre: true post: true
  activity:
    if (V = 0) then (
      return 0
    ) else skip ;
    var res : (trailer . (name maxsize)) := (trailer . (name maxsize)) ;
    for i : Integer.subrange(0, m-1) do (    if ((coins[i+1]->compareTo(V)) <= 0) then (
      var sub_res : OclAny := minCoins(coins, m, V - coins[i+1]) ;
    if (sub_res /= (trailer . (name maxsize)) & (sub_res + 1->compareTo(res)) < 0) then (
      res := sub_res + 1
    ) else skip
    ) else skip) ;
    return res;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
sharpNum=20
roomNum=10
height=15
dataNum=int(input())
building=[[0]*sharpNum for i in range(height)]
for data in range(dataNum):
    actBuilding=1
    actRoom=0
    actFloor=0
    b,f,r,v=map(int,input().split())
    for floor in range(height):
        actRoom=0
        if floor % 4==3 :
            actFloor=0
            actBuilding=actBuilding+1
            for room in range(sharpNum):
                building[floor][room]="#"
        else :
            actFloor=actFloor+1
            for room in range(sharpNum):
                if room % 2==0 :
                    building[floor][room]=""
                else :
                    actRoom=actRoom+1
                    if actBuilding==b and actFloor==f and actRoom==r :
                        building[floor][room]=building[floor][room]+v
for floor in range(height):
    for i in range(len(building[0])):
        print(building[floor][i],end="")
    print("")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var sharpNum : int := 20 ;
    var roomNum : int := 10 ;
    var height : int := 15 ;
    var dataNum : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var building : Sequence := Integer.subrange(0, height-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, sharpNum))) ;
    for data : Integer.subrange(0, dataNum-1) do (    var actBuilding : int := 1 ;
    var actRoom : int := 0 ;
    var actFloor : int := 0 ;
    var b : OclAny := null;
    var f : OclAny := null;
    var r : OclAny := null;
    var v : OclAny := null;
    Sequence{b,f,r,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    for floor : Integer.subrange(0, height-1) do (    actRoom := 0 ;
    if floor mod 4 = 3 then  (
      actFloor := 0 ;
    actBuilding := actBuilding + 1 ;
    for room : Integer.subrange(0, sharpNum-1) do (    building[floor+1][room+1] := "#")
    )
    else (
      actFloor := actFloor + 1 ;
    for room : Integer.subrange(0, sharpNum-1) do (    if room mod 2 = 0 then  (
      building[floor+1][room+1] := ""
    )
    else (
      actRoom := actRoom + 1 ;
    if actBuilding = b & actFloor = f & actRoom = r then (
      building[floor+1][room+1] := building[floor+1][room+1] + v
    ) else skip
      ))
      ))) ;
    for floor : Integer.subrange(0, height-1) do (    for i : Integer.subrange(0, (building->first())->size()-1) do (    execute (building[floor+1][i+1])->display()) ;
    execute ("")->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import OrderedDict
from itertools import cycle,islice
d=OrderedDict(("{}{}{}".format(b,f,r),0)for b in range(1,5)for f in range(1,4)for r in range(1,11))
n=int(input())
for _ in range(n):
    s=input()
    idx=s.rfind(" ")
    d[s[: idx]]+=int(s[idx+1 :])
data=d.values()
delim="#"*20
for i in range(0,120,10):
    print(" "+" ".join(map(str,islice(cycle(data),i,i+10))))
    if i in(20,50,80):
        print(delim)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var d : OclAny := ((argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom "{}{}{}") (trailer . (name format) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b))))))) , (argument (test (logical_test (comparison (expr (atom (name f))))))) , (argument (test (logical_test (comparison (expr (atom (name r)))))))) ))))))) , (test (logical_test (comparison (expr (atom (number (integer 0)))))))) )))))) (comp_for for (exprlist (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 5))))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name f)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 4))))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name r)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 11))))))))) ))))))))))))) ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    for _anon : Integer.subrange(0, n-1) do (    var s : String := (OclFile["System.in"]).readLine() ;
    var idx : OclAny := s.rfind(" ") ;
    d[s.subrange(1,idx)+1] := d[s.subrange(1,idx)+1] + ("" + ((s.subrange(idx + 1+1))))->toInteger()) ;
    var data : OclAny := d.values() ;
    var delim : String := StringLib.nCopies("#", 20) ;
    for i : Integer.subrange(0, 120-1)->select( $x | ($x - 0) mod 10 = 0 ) do (    execute (" " + StringLib.sumStringsWithSeparator(((islice(cycle(data), i, i + 10))->collect( _x | (OclType["String"])->apply(_x) )), " "))->display() ;
    if (Sequence{20, 50, 80})->includes(i) then (
      execute (delim)->display()
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
data_list=list()
for i in range(n):
    data=list(map(int,input().split()))
    data_list.append(data)
apart=[[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],'####################',[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],'####################',[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],'####################',[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]
for data in data_list :
    apart[((data[0]-1)*4)+(data[1]-1)][data[2]-1]=apart[((data[0]-1)*4)+(data[1]-1)][data[2]-1]+data[3]
for ridge in apart :
    if str(ridge[0]).isdigit():
        ridge=[str(i)for i in ridge]
        print('',' '.join(ridge))
    else :
        print(ridge)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var data_list : Sequence := () ;
    for i : Integer.subrange(0, n-1) do (    var data : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    execute ((data) : data_list)) ;
    var apart : Sequence := Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))))))))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))))))))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))))))))}->union(Sequence{'####################'}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))))))))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))))))))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))))))))}->union(Sequence{'####################'}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))))))))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))))))))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))))))))}->union(Sequence{'####################'}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))))))))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))))))))}->union(Sequence{ Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))))))))) })))))))))))))) ;
    for data : data_list do (    apart[((data->first() - 1) * 4) + (data[1+1] - 1)+1][data[2+1] - 1+1] := apart[((data->first() - 1) * 4) + (data[1+1] - 1)+1][data[2+1] - 1+1] + data[3+1]) ;
    for ridge : apart do (    if OclType["String"](ridge->first())->matches("[0-9]*") then  (
      var ridge : Sequence := ridge->select(i | true)->collect(i | (("" + ((i))))) ;
    execute ('')->display()
    )
    else (
      execute (ridge)->display()
      ));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
SEPARATE="####################"
tower=[[[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]],[[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]],[[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]],[[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]]
n=int(input())
i=0
while iunion(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))))))))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))))))))}->union(Sequence{ Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))))))))) }))}->union(Sequence{Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))))))))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))))))))}->union(Sequence{ Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))))))))) }))}->union(Sequence{Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))))))))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))))))))}->union(Sequence{ Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))))))))) }))}->union(Sequence{ Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))))))))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))))))))}->union(Sequence{ Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))))))))) })) }))) ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var i : int := 0 ;
    while (i->compareTo(n)) < 0 do (    var b : OclAny := null;
    var f : OclAny := null;
    var r : OclAny := null;
    var v : OclAny := null;
    Sequence{b,f,r,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    tower[b - 1+1][f - 1+1][r - 1+1] := tower[b - 1+1][f - 1+1][r - 1+1] + v ;
    i := i + 1) ;
    i := 0 ;
    var j : int := 0 ;
    var k : int := 0 ;
    while k < 4 do (    while j < 3 do (    while i < 10 do (    execute ("" + ("" + ((tower[k+1][j+1][i+1]))))->display() ;
    i := i + 1) ;
    execute (->display() ;
    j := j + 1 ;
    i := 0) ;
    if k /= 3 then (
      execute (SEPARATE)->display()
    ) else skip ;
    j := 0 ;
    k := k + 1);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=input()
n=int(n)
numbers=[]
index=[]
for i in range(12):
    index.append([0,0,0,0,0,0,0,0,0,0])
for _ in range(n):
    string=input()
    numbers.append(list(map(int,string.split(' '))))
numbers.sort()
for i in range(12):
    for j in range(10):
        for k in range(n):
            if(numbers[k][0]-1)*3+(numbers[k][1]-1)==i and(numbers[k][2]-1)==j :
                index[i][j]+=numbers[k][3]
for i in range(12):
    for j in range(10):
        print("",end="")
        print(index[i][j],end="")
        if i==12 :
            break
    print()
    if i==2 or i==5 or i==8 :
        print("####################")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : String := (OclFile["System.in"]).readLine() ;
    n := ("" + ((n)))->toInteger() ;
    var numbers : Sequence := Sequence{} ;
    var index : Sequence := Sequence{} ;
    for i : Integer.subrange(0, 12-1) do (    execute ((Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))))))))) : index)) ;
    for _anon : Integer.subrange(0, n-1) do (    var string : String := (OclFile["System.in"]).readLine() ;
    execute ((((string.split(' '))->collect( _x | (OclType["int"])->apply(_x) ))) : numbers)) ;
    numbers := numbers->sort() ;
    for i : Integer.subrange(0, 12-1) do (    for j : Integer.subrange(0, 10-1) do (    for k : Integer.subrange(0, n-1) do (    if (numbers[k+1]->first() - 1) * 3 + (numbers[k+1][1+1] - 1) = i & (numbers[k+1][2+1] - 1) = j then (
      index[i+1][j+1] := index[i+1][j+1] + numbers[k+1][3+1]
    ) else skip))) ;
    for i : Integer.subrange(0, 12-1) do (    for j : Integer.subrange(0, 10-1) do (    execute ("")->display() ;
    execute (index[i+1][j+1])->display() ;
    if i = 12 then (
      break
    ) else skip) ;
    execute (->display() ;
    if i = 2 or i = 5 or i = 8 then (
      execute ("####################")->display()
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def z_function(s):
    global z,n
    n=len(s)
    z=[0]*n
    l,r=0,0
    for i in range(1,n):
        if i<=r :
            z[i]=min(r-i+1,z[i-1])
        while(i+z[i]r):
            l=i
            r=i+z[i]-1
    return z
def update(idx,val):
    global bit
    if idx==0 :
        return
    while idx<=n :
        bit[idx]+=val
        idx+=(idx &-idx)
def pref(idx):
    global bit
    ans=0
    while idx>0 :
        ans+=bit[idx]
        idx-=(idx &-idx)
    return ans
if __name__=="__main__" :
    n=0
    length=0
    bit=[0]*1000005
    z=[]
    m=dict()
    s="geeksisforgeeksinplatformgeeks"
    z=z_function(s)
    for i in range(1,n):
        update(z[i],1)
    for i in range(n-1,1,-1):
        if z[i]!=n-i :
            continue
        if(pref(n)-pref(z[i]-1))>=2 :
            length=max(length,z[i])
    if not length :
        print(-1)
    else :
        print(s[: length])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  attribute z : OclAny;
  attribute n : OclAny;
  attribute bit : OclAny;
  attribute bit : OclAny;
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      n := 0 ;
    var length : int := 0 ;
    bit := MatrixLib.elementwiseMult(Sequence{ 0 }, 1000005) ;
    z := Sequence{} ;
    var m : Map := (arguments ( )) ;
    s := "geeksisforgeeksinplatformgeeks" ;
    z := z_function(s) ;
    for i : Integer.subrange(1, n-1) do (    update(z[i+1], 1)) ;
    for i : Integer.subrange(1 + 1, n - 1)->reverse() do (    if z[i+1] /= n - i then (
      continue
    ) else skip ;
    if (pref(n) - pref(z[i+1] - 1)) >= 2 then (
      length := Set{length, z[i+1]}->max()
    ) else skip) ;
    if not(length) then  (
      execute (-1)->display()
    )
    else (
      execute (s.subrange(1,length))->display()
      )
    ) else skip;
  operation z_function(s : OclAny) : OclAny
  pre: true post: true
  activity:
    skip;    skip ;
    n := (s)->size() ;
    z := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ;
    var l : OclAny := null;
    var r : OclAny := null;
    Sequence{l,r} := Sequence{0,0} ;
    for i : Integer.subrange(1, n-1) do (    if (i->compareTo(r)) <= 0 then (
      z[i+1] := Set{r - i + 1, z[i - 1+1]}->min()
    ) else skip ;
    while ((i + z[i+1]->compareTo(n)) < 0 & s[z[i+1]+1] = s[i + z[i+1]+1]) do (    z[i+1] := z[i+1] + 1) ;
    if ((i + z[i+1] - 1->compareTo(r)) > 0) then (
      var l : OclAny := i ;
    var r : double := i + z[i+1] - 1
    ) else skip) ;
    return z;
  operation update(idx : OclAny, val : OclAny)
  pre: true post: true
  activity:
    skip ;
    if idx = 0 then (
      return
    ) else skip ;
    while (idx->compareTo(n)) <= 0 do (    bit[idx+1] := bit[idx+1] + val ;
    idx := idx + (MathLib.bitwiseAnd(idx, -idx)));
  operation pref(idx : OclAny) : OclAny
  pre: true post: true
  activity:
    skip ;
    var ans : int := 0 ;
    while idx > 0 do (    ans := ans + bit[idx+1] ;
    idx := idx - (MathLib.bitwiseAnd(idx, -idx))) ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
r1,c1,r2,c2=[int(x)for x in input().split()]
king=max(abs(r2-r1),abs(c2-c1))
rook=0
if(r2==r1 or c2==c1):
    rook=1
else :
    rook=2
bishop=0
if((r1+c1)% 2!=(r2+c2)% 2):
    bisohp=0
elif(r1+c1)==(r2+c2):
    bishop=1
elif(r2-r1)==-(c2-c1):
    bishop=1
elif(r2-r1)==(c2-c1):
    bishop=1
else :
    bishop=2
print(rook,bishop,king)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var r1 : OclAny := null;
    var c1 : OclAny := null;
    var r2 : OclAny := null;
    var c2 : OclAny := null;
    Sequence{r1,c1,r2,c2} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ;
    var king : OclAny := Set{(r2 - r1)->abs(), (c2 - c1)->abs()}->max() ;
    var rook : int := 0 ;
    if (r2 = r1 or c2 = c1) then  (
      rook := 1
    )
    else (
      rook := 2
      ) ;
    var bishop : int := 0 ;
    if ((r1 + c1) mod 2 /= (r2 + c2) mod 2) then  (
      var bisohp : int := 0
    )
    else (if (r1 + c1) = (r2 + c2) then
   (
      bishop := 1    
)
    else (if (r2 - r1) = -(c2 - c1) then
   (
      bishop := 1    
)
    else (if (r2 - r1) = (c2 - c1) then
   (
      bishop := 1    
)
    else (
      bishop := 2
      )    )
    )
    )
 ;
    execute (rook)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
r1,c1,r2,c2=list(map(int,input().split()))
dr,dc=abs(r2-r1),abs(c2-c1)
rook=0
if dr!=0 :
    rook+=1
if dc!=0 :
    rook+=1
king=max(dr,dc)
if(dr+dc)% 2 :
    bishop=0
elif dr==dc :
    bishop=1
else :
    bishop=2
print(rook,bishop,king)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var r1 : OclAny := null;
    var c1 : OclAny := null;
    var r2 : OclAny := null;
    var c2 : OclAny := null;
    Sequence{r1,c1,r2,c2} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var dr : OclAny := null;
    var dc : OclAny := null;
    Sequence{dr,dc} := Sequence{(r2 - r1)->abs(),(c2 - c1)->abs()} ;
    var rook : int := 0 ;
    if dr /= 0 then (
      rook := rook + 1
    ) else skip ;
    if dc /= 0 then (
      rook := rook + 1
    ) else skip ;
    var king : OclAny := Set{dr, dc}->max() ;
    if (dr + dc) mod 2 then  (
      var bishop : int := 0
    )
    else (if dr = dc then
   (
      bishop := 1    
)
    else (
      bishop := 2
      )    )
 ;
    execute (rook)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def countRook():
    count=0
    if rf!=rs :
        count+=1
    if cf!=cs :
        count+=1
    return count
def countBishop():
    x=abs(rs-rf)
    y=abs(cs-cf)
    if x % 2==y % 2 :
        if x==y :
            return 1
        else :
            return 2
    else :
        return 0
def countKing():
    count=0
    return max(abs(rf-rs),abs(cf-cs))
rs,cs,rf,cf=map(int,input().split())
print(countRook(),countBishop(),countKing())
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    var rs : OclAny := null;
    var cs : OclAny := null;
    var rf : OclAny := null;
    var cf : OclAny := null;
    Sequence{rs,cs,rf,cf} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    execute (countRook())->display();
  operation countRook() : OclAny
  pre: true post: true
  activity:
    var count : int := 0 ;
    if rf /= rs then (
      count := count + 1
    ) else skip ;
    if cf /= cs then (
      count := count + 1
    ) else skip ;
    return count;
  operation countBishop() : OclAny
  pre: true post: true
  activity:
    var x : double := (rs - rf)->abs() ;
    var y : double := (cs - cf)->abs() ;
    if x mod 2 = y mod 2 then  (
      if x = y then  (
      return 1
    )
    else (
      return 2
      )
    )
    else (
      return 0
      );
  operation countKing() : OclAny
  pre: true post: true
  activity:
    count := 0 ;
    return Set{(rf - rs)->abs(), (cf - cs)->abs()}->max();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
import sys
n=int(input())
arr=list(map(int,input().split()))
i=0
n=n//2
arr.sort()
x=sum(arr[n :])
y=sum(arr)-x
print((x*x)+(y*y))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    var i : int := 0 ;
    n := n div 2 ;
    arr := arr->sort() ;
    var x : OclAny := (arr.subrange(n+1))->sum() ;
    var y : double := (arr)->sum() - x ;
    execute ((x * x) + (y * y))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
r1,c1,r2,c2=map(int,input().split())
def rock(r1,c1,r2,c2):
    if r1==r2 or c1==c2 :
        return 1
    else :
        return 2
def bishop(r1,c1,r2,c2):
    if(r1+c1)% 2!=(r2+c2)% 2 :
        return 0
    elif abs(r1-r2)==abs(c1-c2):
        return 1
    else :
        return 2
def king(r1,c1,r2,c2):
    return max(abs(r1-r2),abs(c1-c2))
if r1==r2 and c1==c2 :
    print("0 0 0")
else :
    a=rock(r1,c1,r2,c2)
    b=bishop(r1,c1,r2,c2)
    c=king(r1,c1,r2,c2)
    print(a,b,c)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var r1 : OclAny := null;
    var c1 : OclAny := null;
    var r2 : OclAny := null;
    var c2 : OclAny := null;
    Sequence{r1,c1,r2,c2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    skip ;
    skip ;
    skip ;
    if r1 = r2 & c1 = c2 then  (
      execute ("0 0 0")->display()
    )
    else (
      var a : OclAny := rock(r1, c1, r2, c2) ;
    var b : OclAny := bishop(r1, c1, r2, c2) ;
    var c : OclAny := king(r1, c1, r2, c2) ;
    execute (a)->display()
      );
  operation rock(r1 : OclAny, c1 : OclAny, r2 : OclAny, c2 : OclAny) : OclAny
  pre: true post: true
  activity:
    if r1 = r2 or c1 = c2 then  (
      return 1
    )
    else (
      return 2
      );
  operation bishop(r1 : OclAny, c1 : OclAny, r2 : OclAny, c2 : OclAny) : OclAny
  pre: true post: true
  activity:
    if (r1 + c1) mod 2 /= (r2 + c2) mod 2 then  (
      return 0
    )
    else (if (r1 - r2)->abs() = (c1 - c2)->abs() then
   (
      return 1    
)
    else (
      return 2
      )    )
;
  operation king(r1 : OclAny, c1 : OclAny, r2 : OclAny, c2 : OclAny) : OclAny
  pre: true post: true
  activity:
    return Set{(r1 - r2)->abs(), (c1 - c2)->abs()}->max();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
x,y,a,b=map(int,input().split())
ans=[]
if((a==x)or(b==y)):
    ans.append(1)
else :
    ans.append(2)
if((x+y)% 2!=(a+b)% 2):
    ans.append(0)
elif(x+y==a+b)or(x-a==y-b):
    ans.append(1)
else :
    ans.append(2)
ans.append(max(abs(x-a),abs(y-b)))
print(*ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var x : OclAny := null;
    var y : OclAny := null;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{x,y,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var ans : Sequence := Sequence{} ;
    if ((a = x) or (b = y)) then  (
      execute ((1) : ans)
    )
    else (
      execute ((2) : ans)
      ) ;
    if ((x + y) mod 2 /= (a + b) mod 2) then  (
      execute ((0) : ans)
    )
    else (if (x + y = a + b) or (x - a = y - b) then
   (
      execute ((1) : ans)    
)
    else (
      execute ((2) : ans)
      )    )
 ;
    execute ((Set{(x - a)->abs(), (y - b)->abs()}->max()) : ans) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from math import pow
def nthTermOfTheSeries(n):
    if(n % 2==0):
        nthTerm=pow(n-1,2)+n
    else :
        nthTerm=pow(n+1,2)+n
    return nthTerm
if __name__=='__main__' :
    n=8
    print(int(nthTermOfTheSeries(n)))
    n=12
    print(int(nthTermOfTheSeries(n)))
    n=102
    print(int(nthTermOfTheSeries(n)))
    n=999
    print(int(nthTermOfTheSeries(n)))
    n=9999
    print(int(nthTermOfTheSeries(n)))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = '__main__' then (
      n := 8 ;
    execute (("" + ((nthTermOfTheSeries(n))))->toInteger())->display() ;
    n := 12 ;
    execute (("" + ((nthTermOfTheSeries(n))))->toInteger())->display() ;
    n := 102 ;
    execute (("" + ((nthTermOfTheSeries(n))))->toInteger())->display() ;
    n := 999 ;
    execute (("" + ((nthTermOfTheSeries(n))))->toInteger())->display() ;
    n := 9999 ;
    execute (("" + ((nthTermOfTheSeries(n))))->toInteger())->display()
    ) else skip;
  operation nthTermOfTheSeries(n : OclAny) : OclAny
  pre: true post: true
  activity:
    if (n mod 2 = 0) then  (
      var nthTerm : double := (n - 1)->pow(2) + n
    )
    else (
      nthTerm := (n + 1)->pow(2) + n
      ) ;
    return nthTerm;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def distribution(arr,n):
    resources=set()
    for i in range(n):
        resources.add(arr[i]);
    return min(len(resources),n//2);
if __name__=='__main__' :
    arr=[1,1,2,1,3,4];
    n=len(arr);
    print(distribution(arr,n),"");
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = '__main__' then (
      arr := Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{3}->union(Sequence{ 4 }))))); ;
    n := (arr)->size(); ;
    execute (distribution(arr, n))->display();
    ) else skip;
  operation distribution(arr : OclAny, n : OclAny)
  pre: true post: true
  activity:
    var resources : Set := Set{}->union(()) ;
    for i : Integer.subrange(0, n-1) do (    execute ((arr[i+1]) : resources);) ;
    return Set{(resources)->size(), n div 2}->min();;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def rgb_to_hsv(r,g,b):
    r,g,b=r/255.0,g/255.0,b/255.0
    cmax=max(r,g,b)
    cmin=min(r,g,b)
    diff=cmax-cmin
    if cmax==cmin :
        h=0
    elif cmax==r :
        h=(60*((g-b)/diff)+360)% 360
    elif cmax==g :
        h=(60*((b-r)/diff)+120)% 360
    elif cmax==b :
        h=(60*((r-g)/diff)+240)% 360
    if cmax==0 :
        s=0
    else :
        s=(diff/cmax)*100
    v=cmax*100
    return h,s,v
print(rgb_to_hsv(129,88,47))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    execute (rgb_to_hsv(129, 88, 47))->display();
  operation rgb_to_hsv(r : OclAny, g : OclAny, b : OclAny) : OclAny
  pre: true post: true
  activity:
    Sequence{r,g,b} := Sequence{r / 255.0,g / 255.0,b / 255.0} ;
    var cmax : OclAny := Set{r, g, b}->max() ;
    var cmin : OclAny := Set{r, g, b}->min() ;
    var diff : double := cmax - cmin ;
    if cmax = cmin then  (
      var h : int := 0
    )
    else (if cmax = r then
   (
      h := (60 * ((g - b) / diff) + 360) mod 360    
)
    else (if cmax = g then
   (
      h := (60 * ((b - r) / diff) + 120) mod 360    
)
    else (if cmax = b then
   (
      h := (60 * ((r - g) / diff) + 240) mod 360    
)
    else skip    )
    )
    )
 ;
    if cmax = 0 then  (
      var s : int := 0
    )
    else (
      s := (diff / cmax) * 100
      ) ;
    var v : double := cmax * 100 ;
    return h, s, v;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def printThreeParts(N):
    if(N % 3==0):
        print(" x=1,y=1,z=",N-2)
    else :
        print(" x=1,y=2,z=",N-3)
if __name__=="__main__" :
    N=10
    printThreeParts(N)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      N := 10 ;
    printThreeParts(N)
    ) else skip;
  operation printThreeParts(N : OclAny)
  pre: true post: true
  activity:
    if (N mod 3 = 0) then  (
      execute (" x=1,y=1,z=")->display()
    )
    else (
      execute (" x=1,y=2,z=")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
x,y=zip(*sorted(sorted(map(int,input().split()))for _ in range(n)))
p=max(range(n),key=lambda i : y[i])
r=a=x[-1]
b=d=10**9
for i in range(p):
    if b<=x[i]:
        break
    a=max(a,y[i])
    b=min(b,y[i])
    d=min(d,a-min(b,x[i+1]))
print(min((x[-1]-x[0])*(y[p]-min(y)),(y[p]-x[0])*d))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))) ))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))) ))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))) ))))))))`third->at(_indx)} ) ;
    var p : OclAny := Set{Integer.subrange(0, n-1), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name i)))) : (test (logical_test (comparison (expr (atom (name y)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))}->max() ;
    var r : OclAny := x->last(); var a : OclAny := x->last() ;
    var b : OclAny := (10)->pow(9); var d : double := (10)->pow(9) ;
    for i : Integer.subrange(0, p-1) do (    if (b->compareTo(x[i+1])) <= 0 then (
      break
    ) else skip ;
    a := Set{a, y[i+1]}->max() ;
    b := Set{b, y[i+1]}->min() ;
    d := Set{d, a - Set{b, x[i + 1+1]}->min()}->min()) ;
    execute (Set{(x->last() - x->first()) * (y[p+1] - (y)->min()), (y[p+1] - x->first()) * d}->min())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def checkAllOnes(arr,n,k):
    brr=[0 for i in range(n)]
    for i in range(n):
        if(arr[i]==1):
            h=k+1
            j=i
            while(j>=0 and(h)):
                brr[j]=1
                h-=1
                j-=1
            h=k+1
            j=i
            while(junion(Sequence{0}->union(Sequence{1}->union(Sequence{ 0 }))) ;
    k := 2 ;
    n := (arr)->size() ;
    checkAllOnes(arr, n, k);
  operation checkAllOnes(arr : OclAny, n : OclAny, k : OclAny)
  pre: true post: true
  activity:
    var brr : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ;
    for i : Integer.subrange(0, n-1) do (    if (arr[i+1] = 1) then (
      var h : OclAny := k + 1 ;
    var j : OclAny := i ;
    while (j >= 0 & (h)) do (    brr[j+1] := 1 ;
    h := h - 1 ;
    j := j - 1) ;
    h := k + 1 ;
    j := i ;
    while ((j->compareTo(n)) < 0 & (h)) do (    brr[j+1] := 1 ;
    j := j + 1 ;
    h := h - 1)
    ) else skip) ;
    var flag : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    if (brr[i+1] = 0) then (
      flag := 1 ;
    break
    ) else skip) ;
    if (flag = 1) then  (
      execute ("0")->display()
    )
    else (
      execute ("1")->display()
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
sys.setrecursionlimit(10**6)
int1=lambda x : int(x)-1
p2D=lambda x : print(*x,sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int,sys.stdin.readline().split())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LLI(rows_number): return[LI()for _ in range(rows_number)]
def main():
    inf=10**10
    n=II()
    xy=[LI()for _ in range(n)]
    xy=[[x,y]if xpow(6)) ;
    var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ;
    var p2D : Function := lambda x : OclAny in (((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ;
    skip ;
    skip ;
    skip ;
    skip ;
    skip ;
    main();
  operation II() : OclAny
  pre: true post: true
  activity:
    return ("" + (((OclFile["System.in"]).readLine())))->toInteger();
  operation MI() : OclAny
  pre: true post: true
  activity:
    return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) );
  operation LI() : OclAny
  pre: true post: true
  activity:
    return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ));
  operation LLI(rows_number : OclAny) : OclAny
  pre: true post: true
  activity:
    return Integer.subrange(0, rows_number-1)->select(_anon | true)->collect(_anon | (LI()));
  operation main()
  pre: true post: true
  activity:
    var Math_PINFINITY : double := (10)->pow(10) ;
    var n : OclAny := II() ;
    var xy : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI())) ;
    xy := xy->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (if (x->compareTo(y)) < 0 then Sequence{x}->union(Sequence{ y }) else Sequence{y}->union(Sequence{ x }) endif)) ;
    xy := xy->sort() ;
    var yy : Sequence := xy->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (y)) ;
    var xmin : OclAny := xy->first()->first() ;
    var xmax : OclAny := xy->last()->first() ;
    var ymax : OclAny := (yy)->max() ;
    var ymin : OclAny := (yy)->min() ;
    var ans : double := (xmax - xmin) * (ymax - ymin) ;
    var d : double := ymax - xmin ;
    ymin := Math_PINFINITY ;
    for i : Integer.subrange(0, n - 1-1) do (    var y : OclAny := xy[i+1][1+1] ;
    if (y->compareTo(ymin)) < 0 then (
      ymin := y
    ) else skip ;
    xmin := Set{xy[i + 1+1]->first(), ymin}->min() ;
    xmax := Set{xmax, y}->max() ;
    ans := Set{ans, (xmax - xmin) * d}->min()) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
N=int(input())
Ball=[]
for i in range(N):
    x,y=map(int,input().split())
    x,y=min(x,y),max(x,y)
    Ball.append((x,y))
Ball.sort()
X=[x for x,y in Ball]
Y=[y for x,y in Ball]
MIN=X[0]
MAX=max(Y)
ans=(max(X)-MIN)*(MAX-min(Y))
MIN_index,MAX_index=X.index(MIN),Y.index(MAX)
MIN_O=X[MAX_index]
MAX_O=Y[MIN_index]
MIN_O,MAX_O=min(MIN_O,MAX_O),max(MIN_O,MAX_O)
Ball=[Ball[i]for i in range(N)if i not in(MIN_index,MAX_index)]
X=[x for x,y in Ball]
Y=[y for x,y in Ball]
B=[x for x in X]+[MAX_O,MIN_O]
B_max=max(B)
for i in range(len(Ball)):
    x,y=X[i],Y[i]
    if B_max-x>B_max-y>=0 :
        B[i]=y
    else :
        break
ans=min(ans,(MAX-MIN)*(max(B)-min(B)))
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var Ball : Sequence := Sequence{} ;
    for i : Integer.subrange(0, N-1) do (    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := Sequence{Set{x, y}->min(),Set{x, y}->max()} ;
    execute ((Sequence{x, y}) : Ball)) ;
    Ball := Ball->sort() ;
    var X : Sequence := Ball->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (x)) ;
    var Y : Sequence := Ball->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (y)) ;
    var MIN : OclAny := X->first() ;
    var MAX : OclAny := (Y)->max() ;
    var ans : double := ((X)->max() - MIN) * (MAX - (Y)->min()) ;
    var MIN_index : OclAny := null;
    var MAX_index : OclAny := null;
    Sequence{MIN_index,MAX_index} := Sequence{X->indexOf(MIN) - 1,Y->indexOf(MAX) - 1} ;
    var MIN_O : OclAny := X[MAX_index+1] ;
    var MAX_O : OclAny := Y[MIN_index+1] ;
    Sequence{MIN_O,MAX_O} := Sequence{Set{MIN_O, MAX_O}->min(),Set{MIN_O, MAX_O}->max()} ;
    Ball := Integer.subrange(0, N-1)->select(i | (Sequence{MIN_index, MAX_index})->excludes(i))->collect(i | (Ball[i+1])) ;
    X := Ball->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (x)) ;
    Y := Ball->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (y)) ;
    var B : Sequence := X->select(x | true)->collect(x | (x))->union(Sequence{MAX_O}->union(Sequence{ MIN_O })) ;
    var B_max : OclAny := (B)->max() ;
    for i : Integer.subrange(0, (Ball)->size()-1) do (    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := Sequence{X[i+1],Y[i+1]} ;
    if (B_max - x->compareTo(B_max - y)) > 0 & (B_max - y >= 0) then  (
      B[i+1] := y
    )
    else (
      break
      )) ;
    ans := Set{ans, (MAX - MIN) * ((B)->max() - (B)->min())}->min() ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n=int(input())
a=[int(i)for i in input().split()]
ans=True
c=[]
t=sum(a)//((n*(n+1))//2)
if sum(a)%((n*(n+1))//2)!=0 :
    ans=False
else :
    for i in range(n):
        if i==0 :
            d=a[0]-a[-1]
        else :
            d=a[i]-a[i-1]
        if(t-d)% n!=0 or d-t>0 :
            ans=False
            break
        s=(t-d)//n
        c.append(s)
if n==1 :
    ans=True
print('YES' if ans else 'NO')
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ;
    var ans : boolean := true ;
    var c : Sequence := Sequence{} ;
    var t : int := (a)->sum() div ((n * (n + 1)) div 2) ;
    if (a)->sum() mod ((n * (n + 1)) div 2) /= 0 then  (
      ans := false
    )
    else (
      for i : Integer.subrange(0, n-1) do (    if i = 0 then  (
      var d : double := a->first() - a->last()
    )
    else (
      d := a[i+1] - a[i - 1+1]
      ) ;
    if (t - d) mod n /= 0 or d - t > 0 then (
      ans := false ;
    break
    ) else skip ;
    var s : int := (t - d) div n ;
    execute ((s) : c))
      ) ;
    if n = 1 then (
      ans := true
    ) else skip ;
    execute (if ans then 'YES' else 'NO' endif)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
d=[]
M,m=0,10**30
M_of_m,m_of_M=0,10**30
for _ in range(n):
    x,y=map(int,input().split())
    g,l=max(x,y),min(x,y)
    d.append([l,g])
    M=max(M,g)
    m=min(m,l)
    M_of_m=max(M_of_m,l)
    m_of_M=min(m_of_M,g)
ans1=(M-m_of_M)*(M_of_m-m)
M_other,m_other=M_of_m,m
m_reversed=10**30
gap=M_other-m_other
d.sort(key=min)
for i in range(n-1):
    M_other=max(M_other,d[i][1])
    m_reversed=min(m_reversed,d[i][1])
    m_other=min(m_reversed,d[i+1][0])
    gap=min(gap,M_other-m_other)
M_other=max(M_other,d[n-1][1])
m_reversed=min(m_reversed,d[i][1])
gap=min(gap,M_other-m_reversed)
ans2=(M-m)*gap
print(min(ans1,ans2))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var d : Sequence := Sequence{} ;
    var M : OclAny := null;
    var m : OclAny := null;
    Sequence{M,m} := Sequence{0,(10)->pow(30)} ;
    var M_of_m : OclAny := null;
    var m_of_M : OclAny := null;
    Sequence{M_of_m,m_of_M} := Sequence{0,(10)->pow(30)} ;
    for _anon : Integer.subrange(0, n-1) do (    var x : OclAny := null;
    var y : OclAny := null;
    Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var g : OclAny := null;
    var l : OclAny := null;
    Sequence{g,l} := Sequence{Set{x, y}->max(),Set{x, y}->min()} ;
    execute ((Sequence{l}->union(Sequence{ g })) : d) ;
    var M : OclAny := Set{M, g}->max() ;
    var m : OclAny := Set{m, l}->min() ;
    var M_of_m : OclAny := Set{M_of_m, l}->max() ;
    var m_of_M : OclAny := Set{m_of_M, g}->min()) ;
    var ans1 : double := (M - m_of_M) * (M_of_m - m) ;
    var M_other : OclAny := null;
    var m_other : OclAny := null;
    Sequence{M_other,m_other} := Sequence{M_of_m,m} ;
    var m_reversed : double := (10)->pow(30) ;
    var gap : double := M_other - m_other ;
    d := d->sort() ;
    for i : Integer.subrange(0, n - 1-1) do (    var M_other : OclAny := Set{M_other, d[i+1][1+1]}->max() ;
    m_reversed := Set{m_reversed, d[i+1][1+1]}->min() ;
    var m_other : OclAny := Set{m_reversed, d[i + 1+1]->first()}->min() ;
    gap := Set{gap, M_other - m_other}->min()) ;
    M_other := Set{M_other, d[n - 1+1][1+1]}->max() ;
    m_reversed := Set{m_reversed, d[i+1][1+1]}->min() ;
    gap := Set{gap, M_other - m_reversed}->min() ;
    var ans2 : double := (M - m) * gap ;
    execute (Set{ans1, ans2}->min())->display();
  operation input() : OclAny
  pre: true post: true
  activity:
    return sys.stdin.readLine()->front();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
from operator import itemgetter
inf=1<<30
def solve():
    n=int(sys.stdin.readline())
    r_max=b_max=0
    r_min=b_min=inf
    p=[]
    for i in range(n):
        xi,yi=map(int,sys.stdin.readline().split())
        if xi>yi :
            xi,yi=yi,xi
        p.append((xi,yi))
        r_max=max(r_max,yi)
        r_min=min(r_min,yi)
        b_max=max(b_max,xi)
        b_min=min(b_min,xi)
    ans1=(r_max-r_min)*(b_max-b_min)
    ans2=(r_max-b_min)
    p.sort(key=itemgetter(0))
    b_min=p[0][0]
    b_max=p[-1][0]
    y_min=inf
    dif_b=b_max-b_min
    for i in range(n-1):
        if p[i][1]==r_max :
            break
        y_min=min(y_min,p[i][1])
        b_min=min(p[i+1][0],y_min)
        b_max=max(b_max,p[i][1])
        dif_b=min(dif_b,b_max-b_min)
    ans2*=dif_b
    ans=min(ans1,ans2)
    print(ans)
if __name__=='__main__' :
    solve()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var Math_PINFINITY : int := 1 * (2->pow(30)) ;
    skip ;
    if __name__ = '__main__' then (
      solve()
    ) else skip;
  operation solve()
  pre: true post: true
  activity:
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var r_max : OclAny := 0; var b_max : int := 0 ;
    var r_min : OclAny := Math_PINFINITY; var b_min : double := Math_PINFINITY ;
    var p : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    var xi : OclAny := null;
    var yi : OclAny := null;
    Sequence{xi,yi} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if (xi->compareTo(yi)) > 0 then (
      var xi : OclAny := null;
    var yi : OclAny := null;
    Sequence{xi,yi} := Sequence{yi,xi}
    ) else skip ;
    execute ((Sequence{xi, yi}) : p) ;
    r_max := Set{r_max, yi}->max() ;
    r_min := Set{r_min, yi}->min() ;
    b_max := Set{b_max, xi}->max() ;
    b_min := Set{b_min, xi}->min()) ;
    var ans1 : double := (r_max - r_min) * (b_max - b_min) ;
    var ans2 : double := (r_max - b_min) ;
    p := p->sort() ;
    b_min := p->first()->first() ;
    b_max := p->last()->first() ;
    var y_min : int := Math_PINFINITY ;
    var dif_b : double := b_max - b_min ;
    for i : Integer.subrange(0, n - 1-1) do (    if p[i+1][1+1] = r_max then (
      break
    ) else skip ;
    y_min := Set{y_min, p[i+1][1+1]}->min() ;
    b_min := Set{p[i + 1+1]->first(), y_min}->min() ;
    b_max := Set{b_max, p[i+1][1+1]}->max() ;
    dif_b := Set{dif_b, b_max - b_min}->min()) ;
    ans2 := ans2 * dif_b ;
    var ans : OclAny := Set{ans1, ans2}->min() ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
R=4
C=4
def countPaths(maze):
    if(maze[0][0]==-1):
        return 0
    for i in range(R):
        if(maze[i][0]==0):
            maze[i][0]=1
        else :
            break
    for i in range(1,C):
        if(maze[0][i]==0):
            maze[0][i]=1
        else :
            break
    for i in range(1,R):
        for j in range(1,C):
            if(maze[i][j]==-1):
                continue
            if(maze[i-1][j]>0):
                maze[i][j]=(maze[i][j]+maze[i-1][j])
            if(maze[i][j-1]>0):
                maze[i][j]=(maze[i][j]+maze[i][j-1])
    if(maze[R-1][C-1]>0):
        return maze[R-1][C-1]
    else :
        return 0
def numberOfPaths(m,n):
    path=1
    for i in range(n,m+n-1):
        path*=i
        path//=(i-n+1)
    return path
def solve(maze):
    ans=(numberOfPaths(R,C)-countPaths(maze))
    return ans
maze=[[0,0,0,0],[0,-1,0,0],[-1,0,0,0],[0,0,0,0]]
print(solve(maze))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var R : int := 4 ;
    var C : int := 4 ;
    skip ;
    skip ;
    skip ;
    maze := Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))}->union(Sequence{Sequence{0}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{ 0 })))}->union(Sequence{Sequence{-1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))}->union(Sequence{ Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))) }))) ;
    execute (solve(maze))->display();
  operation countPaths(maze : OclAny) : OclAny
  pre: true post: true
  activity:
    if (maze->first()->first() = -1) then (
      return 0
    ) else skip ;
    for i : Integer.subrange(0, R-1) do (    if (maze[i+1]->first() = 0) then  (
      maze[i+1]->first() := 1
    )
    else (
      break
      )) ;
    for i : Integer.subrange(1, C-1) do (    if (maze->first()[i+1] = 0) then  (
      maze->first()[i+1] := 1
    )
    else (
      break
      )) ;
    for i : Integer.subrange(1, R-1) do (    for j : Integer.subrange(1, C-1) do (    if (maze[i+1][j+1] = -1) then (
      continue
    ) else skip ;
    if (maze[i - 1+1][j+1] > 0) then (
      maze[i+1][j+1] := (maze[i+1][j+1] + maze[i - 1+1][j+1])
    ) else skip ;
    if (maze[i+1][j - 1+1] > 0) then (
      maze[i+1][j+1] := (maze[i+1][j+1] + maze[i+1][j - 1+1])
    ) else skip)) ;
    if (maze[R - 1+1][C - 1+1] > 0) then  (
      return maze[R - 1+1][C - 1+1]
    )
    else (
      return 0
      );
  operation numberOfPaths(m : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var path : int := 1 ;
    for i : Integer.subrange(n, m + n - 1-1) do (    path := path * i ;
    path := path div (i - n + 1)) ;
    return path;
  operation solve(maze : OclAny) : OclAny
  pre: true post: true
  activity:
    var ans : double := (numberOfPaths(R, C) - countPaths(maze)) ;
    return ans;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
inp=str(input())
a=[0]*3
for i in inp :
    if i=='a' :
        a[2]=max(a)+1
        a[0]+=1
    else :
        a[1]=max(a[: 2])+1
print(max(a))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var inp : String := ("" + (((OclFile["System.in"]).readLine()))) ;
    var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 3) ;
    for i : inp->characters() do (    if i = 'a' then  (
      a[2+1] := (a)->max() + 1 ;
    a->first() := a->first() + 1
    )
    else (
      a[1+1] := (a.subrange(1,2))->max() + 1
      )) ;
    execute ((a)->max())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
nikita=input()
n=len(nikita)
dp=[0]*n
max_val=1
a_count=0
b_count=0
start=0
if nikita[0]=='b' :
    b_count=b_count+1
else :
    a_count=a_count+1
for i in range(1,n):
    if nikita[i]==nikita[i-1]:
        dp[i]=dp[i-1]+1
    elif nikita[i]=='a' :
        dp[i]=max_val+1
    else :
        dp[i]=max(b_count+1,a_count+1)
        dp[i]=max(dp[i],start+1)
    if nikita[i]=='a' :
        a_count=a_count+1
    else :
        start=max(dp[i],start)
        b_count=b_count+1
    max_val=max(dp[i],max_val)
if a_count==0 :
    print(n)
elif b_count==0 :
    print(n)
else :
    print(max_val)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var nikita : String := (OclFile["System.in"]).readLine() ;
    var n : int := (nikita)->size() ;
    var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ;
    var max_val : int := 1 ;
    var a_count : int := 0 ;
    var b_count : int := 0 ;
    var start : int := 0 ;
    if nikita->first() = 'b' then  (
      b_count := b_count + 1
    )
    else (
      a_count := a_count + 1
      ) ;
    for i : Integer.subrange(1, n-1) do (    if nikita[i+1] = nikita[i - 1+1] then  (
      dp[i+1] := dp[i - 1+1] + 1
    )
    else (if nikita[i+1] = 'a' then
   (
      dp[i+1] := max_val + 1    
)
    else (
      dp[i+1] := Set{b_count + 1, a_count + 1}->max() ;
    dp[i+1] := Set{dp[i+1], start + 1}->max()
      )    )
 ;
    if nikita[i+1] = 'a' then  (
      a_count := a_count + 1
    )
    else (
      start := Set{dp[i+1], start}->max() ;
    b_count := b_count + 1
      ) ;
    max_val := Set{dp[i+1], max_val}->max()) ;
    if a_count = 0 then  (
      execute (n)->display()
    )
    else (if b_count = 0 then
   (
      execute (n)->display()    
)
    else (
      execute (max_val)->display()
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
nikita=input()
n=len(nikita)
dp=[0]*n
max_val=1
a_count=0
b_count=0
start=0
if nikita[0]=='b' :
    b_count=b_count+1
else :
    a_count=a_count+1
for i in range(1,n):
    if nikita[i]==nikita[i-1]:
        dp[i]=dp[i-1]+1
    elif nikita[i]=='a' :
        dp[i]=max_val+1
    else :
        dp[i]=max(b_count+1,a_count+1)
        dp[i]=max(dp[i],start+1)
    if nikita[i]=='a' :
        a_count=a_count+1
    else :
        start=max(dp[i],start)
        b_count=b_count+1
    max_val=max(dp[i],max_val)
if a_count==0 :
    print(n)
elif b_count==0 :
    print(n)
else :
    print(max_val)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var nikita : String := (OclFile["System.in"]).readLine() ;
    var n : int := (nikita)->size() ;
    var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ;
    var max_val : int := 1 ;
    var a_count : int := 0 ;
    var b_count : int := 0 ;
    var start : int := 0 ;
    if nikita->first() = 'b' then  (
      b_count := b_count + 1
    )
    else (
      a_count := a_count + 1
      ) ;
    for i : Integer.subrange(1, n-1) do (    if nikita[i+1] = nikita[i - 1+1] then  (
      dp[i+1] := dp[i - 1+1] + 1
    )
    else (if nikita[i+1] = 'a' then
   (
      dp[i+1] := max_val + 1    
)
    else (
      dp[i+1] := Set{b_count + 1, a_count + 1}->max() ;
    dp[i+1] := Set{dp[i+1], start + 1}->max()
      )    )
 ;
    if nikita[i+1] = 'a' then  (
      a_count := a_count + 1
    )
    else (
      start := Set{dp[i+1], start}->max() ;
    b_count := b_count + 1
      ) ;
    max_val := Set{dp[i+1], max_val}->max()) ;
    if a_count = 0 then  (
      execute (n)->display()
    )
    else (if b_count = 0 then
   (
      execute (n)->display()    
)
    else (
      execute (max_val)->display()
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
nikita=input()
n=len(nikita)
dp=[0]*n
max_val=1
a_count=0
b_count=0
start=0
if nikita[0]=='b' :
    b_count=b_count+1
else :
    a_count=a_count+1
for i in range(1,n):
    if nikita[i]==nikita[i-1]:
        dp[i]=dp[i-1]+1
    elif nikita[i]=='a' :
        dp[i]=max_val+1
    else :
        dp[i]=max(b_count+1,a_count+1)
        dp[i]=max(dp[i],start+1)
    if nikita[i]=='a' :
        a_count=a_count+1
    else :
        start=max(dp[i],start)
        b_count=b_count+1
    max_val=max(dp[i],max_val)
if a_count==0 :
    print(n)
elif b_count==0 :
    print(n)
else :
    print(max_val)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var nikita : String := (OclFile["System.in"]).readLine() ;
    var n : int := (nikita)->size() ;
    var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ;
    var max_val : int := 1 ;
    var a_count : int := 0 ;
    var b_count : int := 0 ;
    var start : int := 0 ;
    if nikita->first() = 'b' then  (
      b_count := b_count + 1
    )
    else (
      a_count := a_count + 1
      ) ;
    for i : Integer.subrange(1, n-1) do (    if nikita[i+1] = nikita[i - 1+1] then  (
      dp[i+1] := dp[i - 1+1] + 1
    )
    else (if nikita[i+1] = 'a' then
   (
      dp[i+1] := max_val + 1    
)
    else (
      dp[i+1] := Set{b_count + 1, a_count + 1}->max() ;
    dp[i+1] := Set{dp[i+1], start + 1}->max()
      )    )
 ;
    if nikita[i+1] = 'a' then  (
      a_count := a_count + 1
    )
    else (
      start := Set{dp[i+1], start}->max() ;
    b_count := b_count + 1
      ) ;
    max_val := Set{dp[i+1], max_val}->max()) ;
    if a_count = 0 then  (
      execute (n)->display()
    )
    else (if b_count = 0 then
   (
      execute (n)->display()    
)
    else (
      execute (max_val)->display()
      )    )
;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
inp=str(input())
a=[0]*3
for i in inp :
    if i=='a' :
        a[2]=max(a)+1
        a[0]+=1
    else :
        a[1]=max(a[: 2])+1
print(max(a))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var inp : String := ("" + (((OclFile["System.in"]).readLine()))) ;
    var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 3) ;
    for i : inp->characters() do (    if i = 'a' then  (
      a[2+1] := (a)->max() + 1 ;
    a->first() := a->first() + 1
    )
    else (
      a[1+1] := (a.subrange(1,2))->max() + 1
      )) ;
    execute ((a)->max())->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
class newNode :
    def __init__(self,data):
        self.data=data
        self.left=None
        self.right=None
def maxAtLevel(root,level):
    if(root==None):
        return 0
    if(level==0):
        return root.data
    x=maxAtLevel(root.left,level-1)
    y=maxAtLevel(root.right,level-1)
    return max(x,y)
if __name__=='__main__' :
    root=newNode(45)
    root.left=newNode(46)
    root.left.left=newNode(18)
    root.left.left.left=newNode(16)
    root.left.left.right=newNode(23)
    root.left.right=newNode(17)
    root.left.right.left=newNode(24)
    root.left.right.right=newNode(21)
    root.right=newNode(15)
    root.right.left=newNode(22)
    root.right.left.left=newNode(37)
    root.right.left.right=newNode(41)
    root.right.right=newNode(19)
    root.right.right.left=newNode(49)
    root.right.right.right=newNode(29)
    level=3
    print(maxAtLevel(root,level))
------------------------------------------------------------
OCL File:
---------
class newNode {
  static operation newnewNode() : newNode
  pre: true
  post: newNode->exists( _x | result = _x );
  attribute data : OclAny := data;
  attribute left : OclAny := null;
  attribute right : OclAny := null;
  operation initialise(data : OclAny) : newNode
  pre: true post: true
  activity:
    self.data := data ;
    self.left := null ;
    self.right := null;
    return self;
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = '__main__' then (
      root := (newNode.newnewNode()).initialise(45) ;
    root.left := (newNode.newnewNode()).initialise(46) ;
    root.left.left := (newNode.newnewNode()).initialise(18) ;
    root.left.left.left := (newNode.newnewNode()).initialise(16) ;
    root.left.left.right := (newNode.newnewNode()).initialise(23) ;
    root.left.right := (newNode.newnewNode()).initialise(17) ;
    root.left.right.left := (newNode.newnewNode()).initialise(24) ;
    root.left.right.right := (newNode.newnewNode()).initialise(21) ;
    root.right := (newNode.newnewNode()).initialise(15) ;
    root.right.left := (newNode.newnewNode()).initialise(22) ;
    root.right.left.left := (newNode.newnewNode()).initialise(37) ;
    root.right.left.right := (newNode.newnewNode()).initialise(41) ;
    root.right.right := (newNode.newnewNode()).initialise(19) ;
    root.right.right.left := (newNode.newnewNode()).initialise(49) ;
    root.right.right.right := (newNode.newnewNode()).initialise(29) ;
    level := 3 ;
    execute (maxAtLevel(root, level))->display()
    ) else skip;
  operation maxAtLevel(root : OclAny, level : OclAny) : OclAny
  pre: true post: true
  activity:
    if (root = null) then (
      return 0
    ) else skip ;
    if (level = 0) then (
      return root.data
    ) else skip ;
    var x : OclAny := maxAtLevel(root.left, level - 1) ;
    var y : OclAny := maxAtLevel(root.right, level - 1) ;
    return Set{x, y}->max();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import math
def sumofFactors(n):
    res=1
    for i in range(2,int(math.sqrt(n))+1):
        count=0 ; curr_sum=1 ; curr_term=1
        while(n % i==0):
            count+=1
            n=n//i
            curr_term*=i
            curr_sum+=curr_term
        res*=curr_sum
    if(n>=2):
        res*=(1+n)
    return res
def gcd(a,b):
    if(a==0):
        return b
    return gcd(b % a,a)
def checkFriendly(n,m):
    sumFactors_n=sumofFactors(n)
    sumFactors_m=sumofFactors(m)
    gcd_n=gcd(n,sumFactors_n)
    gcd_m=gcd(m,sumFactors_m)
    if(n//gcd_n==m//gcd_m and sumFactors_n//gcd_n==sumFactors_m//gcd_m):
        return True
    else :
        return False
n=6 ; m=28
if(checkFriendly(n,m)):
    print("Yes")
else :
    print("No")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    skip ;
    skip ;
    n := 6;    m := 28 ;
    if (checkFriendly(n, m)) then  (
      execute ("Yes")->display()
    )
    else (
      execute ("No")->display()
      );
  operation sumofFactors(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var res : int := 1 ;
    for i : Integer.subrange(2, ("" + (((n)->sqrt())))->toInteger() + 1-1) do (    var count : int := 0;    var curr_sum : int := 1;    var curr_term : int := 1 ;
    while (n mod i = 0) do (    count := count + 1 ;
    n := n div i ;
    curr_term := curr_term * i ;
    curr_sum := curr_sum + curr_term) ;
    res := res * curr_sum) ;
    if (n >= 2) then (
      res := res * (1 + n)
    ) else skip ;
    return res;
  operation gcd(a : OclAny, b : OclAny) : OclAny
  pre: true post: true
  activity:
    if (a = 0) then (
      return b
    ) else skip ;
    return gcd(b mod a, a);
  operation checkFriendly(n : OclAny, m : OclAny) : OclAny
  pre: true post: true
  activity:
    var sumFactors_n : OclAny := sumofFactors(n) ;
    var sumFactors_m : OclAny := sumofFactors(m) ;
    var gcd_n : OclAny := gcd(n, sumFactors_n) ;
    var gcd_m : OclAny := gcd(m, sumFactors_m) ;
    if (n div gcd_n = m div gcd_m & sumFactors_n div gcd_n = sumFactors_m div gcd_m) then  (
      return true
    )
    else (
      return false
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,a=int(input()),list(map(int,input().split()))
if sum(a)%(n*(n+1)/2):
    print("NO")
else :
    k=sum(a)/(n*(n+1)/2)
    a+=[a[0]]
    if sum([(k-i+j)% n for i,j in zip(a[1 :],a)])or sum([(k-i+j)/n>=0 for i,j in zip(a[1 :],a)])!=n :
        print("NO")
    else :
        print("YES")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var n : OclAny := null;
    var a : OclAny := null;
    Sequence{n,a} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),((input().split())->collect( _x | (OclType["int"])->apply(_x) ))} ;
    if (a)->sum() mod (n * (n + 1) / 2) then  (
      execute ("NO")->display()
    )
    else (
      var k : double := (a)->sum() / (n * (n + 1) / 2) ;
    a := a + Sequence{ a->first() } ;
    if (Integer.subrange(1, a->tail()->size())->collect( _indx | Sequence{a->tail()->at(_indx), a->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let j : OclAny = _tuple->at(2) in ((k - i + j) mod n)))->sum() or (Integer.subrange(1, a->tail()->size())->collect( _indx | Sequence{a->tail()->at(_indx), a->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let j : OclAny = _tuple->at(2) in ((k - i + j) / n >= 0)))->sum() /= n then  (
      execute ("NO")->display()
    )
    else (
      execute ("YES")->display()
      )
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
f=[0]*128
ch0,ch9n,cha,chzn=ord('0'),ord('9')+1,ord('a'),ord('z')+1
def act(start,end,n):
    while True :
        for i in range(start,end):
            if f[i]==0 : continue
            f[i]-=1 ; S.append(i)
            n-=1
            if n<=0 : return
S=list(input())
w=len(S)
for s in S : f[ord(s)]+=1
n1=sum(f[ch0 : ch9n]); n2=w-n1
S=[]
if n1>0 : act(ch0,ch9n,n1)
if n2>0 : act(cha,chzn,n2)
ans,i=w,0
while i3 : ans-=j-i-3
    i=j
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 128) ;
    var ch0 : OclAny := null;
    var ch9n : OclAny := null;
    var cha : OclAny := null;
    var chzn : OclAny := null;
    Sequence{ch0,ch9n,cha,chzn} := Sequence{('0')->char2byte(),('9')->char2byte() + 1,('a')->char2byte(),('z')->char2byte() + 1} ;
    skip ;
    var S : Sequence := ((OclFile["System.in"]).readLine())->characters() ;
    var w : int := (S)->size() ;
    for s : S do (    f[(s)->char2byte()+1] := f[(s)->char2byte()+1] + 1) ;
    var n1 : OclAny := (f.subrange(ch0+1, ch9n))->sum();    var n2 : double := w - n1 ;
    S := Sequence{} ;
    if n1 > 0 then (
      act(ch0, ch9n, n1)
    ) else skip ;
    if n2 > 0 then (
      act(cha, chzn, n2)
    ) else skip ;
    var ans : OclAny := null;
    var i : OclAny := null;
    Sequence{ans,i} := Sequence{w,0} ;
    while (i->compareTo(w)) < 0 do (    var j : OclAny := i + 1 ;
    while (j->compareTo(w)) < 0 & S[j+1] = S[j - 1+1] + 1 do (    j := j + 1) ;
    if j - i > 3 then (
      ans := ans - j - i - 3
    ) else skip ;
    var i : OclAny := j) ;
    execute (ans)->display();
  operation act(start : OclAny, end : OclAny, n : OclAny)
  pre: true post: true
  activity:
    while true do (    for i : Integer.subrange(start, end-1) do (    if f[i+1] = 0 then (
      continue
    ) else skip ;
    f[i+1] := f[i+1] - 1;    execute ((i) : S) ;
    n := n - 1 ;
    if n <= 0 then (
      return
    ) else skip));
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from collections import defaultdict
S=input()
S=sorted(S)
S=list(map(ord,S))
ans=0
while len(S)>0 :
    mn=S[0]
    S.remove(mn)
    nxt=mn+1
    succ=1
    while True :
        if nxt in S :
            S.remove(nxt)
            succ+=1
            nxt+=1
        else :
            break
    ans+=min(3,succ)
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var S : String := (OclFile["System.in"]).readLine() ;
    S := S->sort() ;
    S := ((S)->collect( _x | (ord)->apply(_x) )) ;
    var ans : int := 0 ;
    while (S)->size() > 0 do (    var mn : OclAny := S->first() ;
    execute ((mn) /: S) ;
    var nxt : OclAny := mn + 1 ;
    var succ : int := 1 ;
    while true do (    if (S)->characters()->includes(nxt) then  (
      execute ((nxt) /: S) ;
    succ := succ + 1 ;
    nxt := nxt + 1
    )
    else (
      break
      )) ;
    ans := ans + Set{3, succ}->min()) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
s=list(input())
abc=list("-abcdefghijklmnopqrstuvwxyz-")
num=list("-0123456789-")
abc_cnt=[0]*28
num_cnt=[0]*12
for i in range(len(s)):
    for j in range(1,27):
        if s[i]==abc[j]:
            abc_cnt[j]+=1
for i in range(len(s)):
    for j in range(1,11):
        if s[i]==num[j]:
            num_cnt[j]+=1
ans=0
abc_sum=sum(abc_cnt)
num_sum=sum(num_cnt)
while abc_sum>0 :
    start=100
    current=1
    while current<27 :
        if abc_cnt[current-1]==0 and abc_cnt[current]>0 :
            start=min(start,current)
        if abc_cnt[current+1]==0 and abc_cnt[current]>0 :
            ans+=min(3,current-start+1)
            abc_cnt[current]-=1
            abc_sum-=1
            break
        if abc_cnt[current]>0 :
            abc_cnt[current]-=1
            abc_sum-=1
        current+=1
while num_sum>0 :
    start=100
    current=1
    while current<11 :
        if num_cnt[current-1]==0 and num_cnt[current]>0 :
            start=min(start,current)
        if num_cnt[current+1]==0 and num_cnt[current]>0 :
            ans+=min(3,current-start+1)
            num_cnt[current]-=1
            num_sum-=1
            break
        if num_cnt[current]>0 :
            num_cnt[current]-=1
            num_sum-=1
        current+=1
print(ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ;
    var abc : Sequence := ("-abcdefghijklmnopqrstuvwxyz-")->characters() ;
    var num : Sequence := ("-0123456789-")->characters() ;
    var abc_cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 28) ;
    var num_cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 12) ;
    for i : Integer.subrange(0, (s)->size()-1) do (    for j : Integer.subrange(1, 27-1) do (    if s[i+1] = abc[j+1] then (
      abc_cnt[j+1] := abc_cnt[j+1] + 1
    ) else skip)) ;
    for i : Integer.subrange(0, (s)->size()-1) do (    for j : Integer.subrange(1, 11-1) do (    if s[i+1] = num[j+1] then (
      num_cnt[j+1] := num_cnt[j+1] + 1
    ) else skip)) ;
    var ans : int := 0 ;
    var abc_sum : OclAny := (abc_cnt)->sum() ;
    var num_sum : OclAny := (num_cnt)->sum() ;
    while abc_sum > 0 do (    var start : int := 100 ;
    var current : int := 1 ;
    while current < 27 do (    if abc_cnt[current - 1+1] = 0 & abc_cnt[current+1] > 0 then (
      start := Set{start, current}->min()
    ) else skip ;
    if abc_cnt[current + 1+1] = 0 & abc_cnt[current+1] > 0 then (
      ans := ans + Set{3, current - start + 1}->min() ;
    abc_cnt[current+1] := abc_cnt[current+1] - 1 ;
    abc_sum := abc_sum - 1 ;
    break
    ) else skip ;
    if abc_cnt[current+1] > 0 then (
      abc_cnt[current+1] := abc_cnt[current+1] - 1 ;
    abc_sum := abc_sum - 1
    ) else skip ;
    current := current + 1)) ;
    while num_sum > 0 do (    start := 100 ;
    current := 1 ;
    while current < 11 do (    if num_cnt[current - 1+1] = 0 & num_cnt[current+1] > 0 then (
      start := Set{start, current}->min()
    ) else skip ;
    if num_cnt[current + 1+1] = 0 & num_cnt[current+1] > 0 then (
      ans := ans + Set{3, current - start + 1}->min() ;
    num_cnt[current+1] := num_cnt[current+1] - 1 ;
    num_sum := num_sum - 1 ;
    break
    ) else skip ;
    if num_cnt[current+1] > 0 then (
      num_cnt[current+1] := num_cnt[current+1] - 1 ;
    num_sum := num_sum - 1
    ) else skip ;
    current := current + 1)) ;
    execute (ans)->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
MAXN=100005
spf=[0]*MAXN
sum_digits=[0]*MAXN
isValid=[0]*MAXN
ans=[0]*MAXN
def Smallest_prime_factor():
    for i in range(1,MAXN):
        spf[i]=i
    for i in range(4,MAXN,2):
        spf[i]=2
    i=3
    while i*i<=MAXN :
        if(spf[i]==i):
            for j in range(i*i,MAXN,i):
                if(spf[j]==j):
                    spf[j]=i
        i+=2
def Digit_Sum(copy):
    d=0
    while(copy):
        d+=copy % 10
        copy//=10
    return d
def Sum_Of_All_Digits():
    for n in range(2,MAXN):
        sum_digits[n]=(sum_digits[n//spf[n]]+Digit_Sum(spf[n]))
        if(Digit_Sum(n)==sum_digits[n]):
            isValid[n]=True
    for n in range(2,MAXN):
        if(isValid[n]):
            ans[n]=1
        ans[n]+=ans[n-1]
if __name__=="__main__" :
    Smallest_prime_factor()
    Sum_Of_All_Digits()
    l=2
    r=3
    print("Valid numbers in the range",l,r,"are",ans[r]-ans[l-1])
    l=2
    r=10
    print("Valid numbers in the range",l,r,"are",ans[r]-ans[l-1])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     var MAXN : int := 100005 ;
    var spf : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAXN) ;
    var sum_digits : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAXN) ;
    var isValid : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAXN) ;
    var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAXN) ;
    skip ;
    skip ;
    skip ;
    if __name__ = "__main__" then (
      Smallest_prime_factor() ;
    Sum_Of_All_Digits() ;
    var l : int := 2 ;
    var r : int := 3 ;
    execute ("Valid numbers in the range")->display() ;
    l := 2 ;
    r := 10 ;
    execute ("Valid numbers in the range")->display()
    ) else skip;
  operation Smallest_prime_factor()
  pre: true post: true
  activity:
    for i : Integer.subrange(1, MAXN-1) do (    spf[i+1] := i) ;
    for i : Integer.subrange(4, MAXN-1)->select( $x | ($x - 4) mod 2 = 0 ) do (    spf[i+1] := 2) ;
    var i : int := 3 ;
    while (i * i->compareTo(MAXN)) <= 0 do (    if (spf[i+1] = i) then (
      for j : Integer.subrange(i * i, MAXN-1)->select( $x | ($x - i * i) mod i = 0 ) do (    if (spf[j+1] = j) then (
      spf[j+1] := i
    ) else skip)
    ) else skip ;
    i := i + 2);
  operation Digit_Sum(copy : OclAny) : OclAny
  pre: true post: true
  activity:
    var d : int := 0 ;
    while (copy) do (    d := d + copy mod 10 ;
    copy := copy div 10) ;
    return d;
  operation Sum_Of_All_Digits()
  pre: true post: true
  activity:
    for n : Integer.subrange(2, MAXN-1) do (    sum_digits[n+1] := (sum_digits[n div spf[n+1]+1] + Digit_Sum(spf[n+1])) ;
    if (Digit_Sum(n) = sum_digits[n+1]) then (
      isValid[n+1] := true
    ) else skip) ;
    for n : Integer.subrange(2, MAXN-1) do (    if (isValid[n+1]) then (
      ans[n+1] := 1
    ) else skip ;
    ans[n+1] := ans[n+1] + ans[n - 1+1]);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def maxAND(arr,n):
    res=0
    for i in range(0,n):
        for j in range(i+1,n):
            res=max(res,arr[i]& arr[j])
    return res
arr=[4,8,6,2]
n=len(arr)
print("Maximum AND Value=",maxAND(arr,n))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    arr := Sequence{4}->union(Sequence{8}->union(Sequence{6}->union(Sequence{ 2 }))) ;
    n := (arr)->size() ;
    execute ("Maximum AND Value=")->display();
  operation maxAND(arr : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var res : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    for j : Integer.subrange(i + 1, n-1) do (    res := Set{res, MathLib.bitwiseAnd(arr[i+1], arr[j+1])}->max())) ;
    return res;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
n,m,k=map(int,input().split())
w=[i for i in range(n+1)]
s=[1]*(n+1)
g=[list(map(int,input().split()))for i in range(m)]
def root(x):
    if w[x]==x :
        return x
    x=w[x]
    return root(w[x])
def unite(x,y):
    x=root(x)
    y=root(y)
    if x!=y :
        if s[x]collect( _x | (OclType["int"])->apply(_x) ) ;
    var w : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (i)) ;
    var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ;
    var g : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ;
    skip ;
    skip ;
    for i : Integer.subrange(0, m-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := Sequence{g[i+1]->first(),g[i+1][1+1]} ;
    unite(a, b)) ;
    for i : Integer.subrange(1, n + 1-1) do (    w[i+1] := root(i) ;
    s[i+1] := s[w[i+1]+1]) ;
    for i : Integer.subrange(0, m-1) do (    s[g[i+1]->first()+1] := s[g[i+1]->first()+1] - 1 ;
    s[g[i+1][1+1]+1] := s[g[i+1][1+1]+1] - 1) ;
    for i : Integer.subrange(0, k-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    if w[a+1] = w[b+1] then (
      s[a+1] := s[a+1] - 1 ;
    s[b+1] := s[b+1] - 1
    ) else skip) ;
    for i : Integer.subrange(1, n + 1-1) do (    s[i+1] := s[i+1] - 1) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))))))))->display();
  operation root(x : OclAny) : OclAny
  pre: true post: true
  activity:
    if w[x+1] = x then (
      return x
    ) else skip ;
    x := w[x+1] ;
    return root(w[x+1]);
  operation unite(x : OclAny, y : OclAny)
  pre: true post: true
  activity:
    x := root(x) ;
    y := root(y) ;
    if x /= y then (
      if (s[x+1]->compareTo(s[y+1])) < 0 then  (
      w[x+1] := y ;
    s[y+1] := s[y+1] + s[x+1]
    )
    else (
      w[y+1] := x ;
    s[x+1] := s[x+1] + s[y+1]
      )
    ) else skip;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
from sys import setrecursionlimit
setrecursionlimit(1<<30)
nv,ne,nBad=map(int,input().split())
g=[[]for _ in range(nv)]
for _ in range(ne):
    u,v=map(lambda x : int(x)-1,input().split())
    g[u].append(v)
    g[v].append(u)
a=[tuple(map(lambda x : int(x)-1,input().split()))for _ in range(nBad)]
def dfs(v):
    id[v]=cur
    comps[-1].append(v)
    for to in g[v]:
        if id[to]==None :
            dfs(to)
id=[None]*nv
cur=0
comps=[]
for v in range(nv):
    if id[v]==None :
        comps.append([])
        dfs(v)
        cur+=1
bad=[0]*nv
for u,v in a :
    if id[u]==id[v]:
        bad[u]+=1
        bad[v]+=1
ret=[None]*nv
for v in range(nv):
    ret[v]=len(comps[id[v]])-1-len(g[v])-bad[v]
print(' '.join(map(str,ret)))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    setrecursionlimit(1 * (2->pow(30))) ;
    var nv : OclAny := null;
    var ne : OclAny := null;
    var nBad : OclAny := null;
    Sequence{nv,ne,nBad} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var g : Sequence := Integer.subrange(0, nv-1)->select(_anon | true)->collect(_anon | (Sequence{})) ;
    for _anon : Integer.subrange(0, ne-1) do (    var u : OclAny := null;
    var v : OclAny := null;
    Sequence{u,v} := (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ) ;
(expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) ;
(expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)))))))) ))))) ;
    var a : Sequence := Integer.subrange(0, nBad-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) )))) ;
    skip ;
    var id : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, nv) ;
    var cur : int := 0 ;
    var comps : Sequence := Sequence{} ;
    for v : Integer.subrange(0, nv-1) do (    if ?[v+1] = null then (
      execute ((Sequence{}) : comps) ;
    dfs(v) ;
    cur := cur + 1
    ) else skip) ;
    var bad : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, nv) ;
    for _tuple : a do (var _indx : int := 1;
      var u : OclAny := _tuple->at(_indx); _indx := _indx + 1;
      var v : OclAny := _tuple->at(_indx);
      if ?[u+1] = ?[v+1] then (
      bad[u+1] := bad[u+1] + 1 ;
    bad[v+1] := bad[v+1] + 1
    ) else skip) ;
    var ret : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, nv) ;
    for v : Integer.subrange(0, nv-1) do (    ret[v+1] := (comps[?[v+1]+1])->size() - 1 - (g[v+1])->size() - bad[v+1]) ;
    execute (StringLib.sumStringsWithSeparator(((ret)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display();
  operation dfs(v : OclAny)
  pre: true post: true
  activity:
    ?[v+1] := cur ;
(expr (atom (name comps)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) ;
    for to : g[v+1] do (    if ?[to+1] = null then (
      dfs(to)
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.readline
class UnionFind :
    def __init__(self,n):
        self.par=list(range(n))
        self.siz=[1]*n
    def root(self,x):
        if self.par[x]==x : return x
        self.par[x]=self.root(self.par[x])
        return self.par[x]
    def size(self,x):
        return self.siz[self.root(x)]
    def unite(self,x,y):
        rx,ry=self.root(x),self.root(y)
        if rx!=ry :
            if self.siz[rx]exists( _x | result = _x );
  attribute par : Sequence := (Integer.subrange(0, n-1));
  attribute siz : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, n);
  operation initialise(n : OclAny) : UnionFind
  pre: true post: true
  activity:
    self.par := (Integer.subrange(0, n-1)) ;
    self.siz := MatrixLib.elementwiseMult(Sequence{ 1 }, n);
    return self;
  operation root(x : OclAny) : OclAny
  pre: true post: true
  activity:
    if self.par[x+1] = x then (
      return x
    ) else skip ;
    self.par[x+1] := self.root(self.par[x+1]) ;
    return self.par[x+1];
  operation size(x : OclAny) : OclAny
  pre: true post: true
  activity:
    return self.siz[self.root(x)+1];
  operation unite(x : OclAny,y : OclAny)
  pre: true post: true
  activity:
    var rx : OclAny := null;
    var ry : OclAny := null;
    Sequence{rx,ry} := Sequence{self.root(x),self.root(y)} ;
    if rx /= ry then (
      if (self.siz[rx+1]->compareTo(self.siz[ry+1])) < 0 then (
      var rx : OclAny := null;
    var ry : OclAny := null;
    Sequence{rx,ry} := Sequence{ry,rx}
    ) else skip ;
    self.siz[rx+1] := self.siz[rx+1] + self.siz[ry+1] ;
    self.par[ry+1] := rx
    ) else skip;
  operation same(x : OclAny,y : OclAny) : OclAny
  pre: true post: true
  activity:
    var rx : OclAny := null;
    var ry : OclAny := null;
    Sequence{rx,ry} := Sequence{self.root(x),self.root(y)} ;
    return rx = ry;
}
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    skip ;
    var m : OclAny := null;
    var k : OclAny := null;
    Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var uf : UnionFind := (UnionFind.newUnionFind()).initialise(n) ;
    var n_friends : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ;
    var n_blocks : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ;
    for i : Integer.subrange(0, m-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := Sequence{a - 1,b - 1} ;
    uf.unite(a, b) ;
    n_friends[a+1] := n_friends[a+1] + 1 ;
    n_friends[b+1] := n_friends[b+1] + 1) ;
    for i : Integer.subrange(0, k-1) do (    var c : OclAny := null;
    var d : OclAny := null;
    Sequence{c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var c : OclAny := null;
    var d : OclAny := null;
    Sequence{c,d} := Sequence{c - 1,d - 1} ;
    if uf.same(c, d) then (
      n_blocks[c+1] := n_blocks[c+1] + 1 ;
    n_blocks[d+1] := n_blocks[d+1] + 1
    ) else skip) ;
    var ans : Sequence := Sequence{} ;
    for i : Integer.subrange(0, n-1) do (    execute ((uf.size(i) - n_friends[i+1] - n_blocks[i+1] - 1) : ans)) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
input=sys.stdin.buffer.readline
from collections import defaultdict
def main():
    def find(x):
        if par[x]<0 :
            return x
        else :
            par[x]=find(par[x])
            return par[x]
    def unite(x,y):
        x=find(x)
        y=find(y)
        if x==y :
            return False
        else :
            if par[x]>par[y]:
                x,y=y,x
            par[x]+=par[y]
            par[y]=x
            return True
    def members(x):
        root=find(x)
        return[i for i in range(n)if find(i)==root]
    n,m,k=map(int,input().split())
    num_of_friends=[-1]*n
    par=[-1]*n
    for _ in range(m):
        a,b=map(int,input().split())
        a-=1
        b-=1
        unite(a,b)
        num_of_friends[a]+=-1
        num_of_friends[b]+=-1
    roots=defaultdict(int)
    for i2 in range(n):
        roots[find(i2)]+=1
    for i3 in range(n):
        num_of_friends[i3]+=roots[find(i3)]
    for _ in range(k):
        c,d=map(int,input().split())
        c-=1
        d-=1
        if find(c)==find(d):
            num_of_friends[c]-=1
            num_of_friends[d]-=1
    for i in range(n):
        print(num_of_friends[i],end=' ')
if __name__=='__main__' :
    main()
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    var input : OclAny := sys.stdin.buffer.readline ;
    skip ;
    skip ;
    if __name__ = '__main__' then (
      main()
    ) else skip;
  operation main()
  pre: true post: true
  activity:
    skip ;
    skip ;
    skip ;
    var n : OclAny := null;
    var m : OclAny := null;
    var k : OclAny := null;
    Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var num_of_friends : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ;
    var par : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ;
    for _anon : Integer.subrange(0, m-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    a := a - 1 ;
    b := b - 1 ;
    unite(a, b) ;
    num_of_friends[a+1] := num_of_friends[a+1] + -1 ;
    num_of_friends[b+1] := num_of_friends[b+1] + -1) ;
    var roots : OclAny := defaultdict(OclType["int"]) ;
    for i2 : Integer.subrange(0, n-1) do (    roots[find(i2)+1] := roots[find(i2)+1] + 1) ;
    for i3 : Integer.subrange(0, n-1) do (    num_of_friends[i3+1] := num_of_friends[i3+1] + roots[find(i3)+1]) ;
    for _anon : Integer.subrange(0, k-1) do (    var c : OclAny := null;
    var d : OclAny := null;
    Sequence{c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    c := c - 1 ;
    d := d - 1 ;
    if find(c) = find(d) then (
      num_of_friends[c+1] := num_of_friends[c+1] - 1 ;
    num_of_friends[d+1] := num_of_friends[d+1] - 1
    ) else skip) ;
    for i : Integer.subrange(0, n-1) do (    execute (num_of_friends[i+1])->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def gcd(a,b):
    while b!=0 :
        r=a % b
        a,b=b,r
    return a
while True :
    n=int(input())
    if n==0 : break
    even,odd=[],[]
    b=list(map(int,input().split()))
    for i in b :
        if i & 1 : odd.append(i)
        else : even.append(i)
    even.sort()
    odd.sort()
    e1,e2,o1=even[0],even[1],odd[0];
    g=gcd(e1,o1)
    e1,o1=e1//g,o1//g
    g=gcd(e2,o1)
    e2,o1=e2//g,o1//g
    g=int((e1*e2)**0.5)
    print(g)
    print(*[i//g for i in even])
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    while true do (    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    if n = 0 then (
      break
    ) else skip ;
    var even : OclAny := null;
    var odd : OclAny := null;
    Sequence{even,odd} := Sequence{Sequence{},Sequence{}} ;
    b := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    for i : b do (    if MathLib.bitwiseAnd(i, 1) then  (
      execute ((i) : odd)
    )
    else (
      execute ((i) : even)
      )) ;
    even := even->sort() ;
    odd := odd->sort() ;
    var e1 : OclAny := null;
    var e2 : OclAny := null;
    var o1 : OclAny := null;
    Sequence{e1,e2,o1} := Sequence{even->first(),even[1+1],odd->first()}; ;
    var g : OclAny := gcd(e1, o1) ;
    var e1 : OclAny := null;
    var o1 : OclAny := null;
    Sequence{e1,o1} := Sequence{e1 div g,o1 div g} ;
    g := gcd(e2, o1) ;
    var e2 : OclAny := null;
    var o1 : OclAny := null;
    Sequence{e2,o1} := Sequence{e2 div g,o1 div g} ;
    g := ("" + ((((e1 * e2))->pow(0.5))))->toInteger() ;
    execute (g)->display() ;
    execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) // (expr (atom (name g))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name even))))))) ])))))))->display());
  operation gcd(a : OclAny, b : OclAny) : OclAny
  pre: true post: true
  activity:
    while b /= 0 do (    var r : int := a mod b ;
    Sequence{a,b} := Sequence{b,r}) ;
    return a;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys,math,copy
import numpy as np
HUGE=2147483647
HUGEL=9223372036854775807
ABC="abcdefghijklmnopqrstuvwxyz"
def main():
    n=int(input())
    an=list(map(int,input().split()))
    assert len(an)==n
    d=np.sum(an)
    if d %(n*(n+1)//2)>0 :
        return False
    k=d//(n*(n+1)//2)
    diffs=np.roll(np.array(an),-1)-np.array(an)
    diffs-=k
    if np.all(diffs<=0)and np.all(diffs % n==0):
        return True
    else :
        return False
print("YES" if main()else "NO")
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    var HUGE : int := 2147483647 ;
    var HUGEL : int := 9223372036854775807 ;
    var ABC : String := "abcdefghijklmnopqrstuvwxyz" ;
    skip ;
    execute (if main() then "YES" else "NO" endif)->display();
  operation main() : OclAny
  pre: true post: true
  activity:
    var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ;
    var an : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ;
    assert (an)->size() = n do "assertion failed" ;
    var d : double := MatrixLib.sumMatrix(an) ;
    if d mod (n * (n + 1) div 2) > 0 then (
      return false
    ) else skip ;
    var k : int := d div (n * (n + 1) div 2) ;
    var diffs : double :=  - (an) ;
    diffs := diffs - k ;
    if  &  then  (
      return true
    )
    else (
      return false
      );
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
import sys
from collections import deque
sys.setrecursionlimit(10**7)
input=sys.stdin.readline
n,m,k=map(int,input().split())
f=[[]for _ in range(n)]
g=[[]for _ in range(n)]
for _ in range(m):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    f[a].append(b)
    f[b].append(a)
for _ in range(k):
    c,d=map(int,input().split())
    c,d=c-1,d-1
    g[c].append(d)
    g[d].append(c)
d={}
parent=[-1]*n
seen=[False]*n
for i in range(n):
    if seen[i]:
        continue
    stack=deque()
    d[i]=set([i])
    stack=[i]
    while stack :
        v=stack.pop()
        seen[v]=True
        parent[v]=i
        for nv in f[v]:
            if seen[nv]:
                continue
            d[i].add(nv)
            stack.append(nv)
ans=[0]*n
for i in range(n):
    group=d[parent[i]]
    tmp=len(group)-len(f[i])-1
    for j in g[i]:
        if j in group :
            tmp-=1
    ans[i]=tmp
print(*ans)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    sys.setrecursionlimit((10)->pow(7)) ;
    var input : OclAny := (OclFile["System.in"]).readline ;
    var n : OclAny := null;
    var m : OclAny := null;
    var k : OclAny := null;
    Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var f : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ;
    var g : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ;
    for _anon : Integer.subrange(0, m-1) do (    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var a : OclAny := null;
    var b : OclAny := null;
    Sequence{a,b} := Sequence{a - 1,b - 1} ;
(expr (atom (name f)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ;
(expr (atom (name f)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ;
    for _anon : Integer.subrange(0, k-1) do (    var c : OclAny := null;
    var d : OclAny := null;
    Sequence{c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ;
    var c : OclAny := null;
    var d : OclAny := null;
    Sequence{c,d} := Sequence{c - 1,d - 1} ;
(expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name c)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name d)))))))) )))) ;
(expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name d)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))) ;
    var d : OclAny := Set{} ;
    var parent : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ;
    var seen : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ;
    for i : Integer.subrange(0, n-1) do (    if seen[i+1] then (
      continue
    ) else skip ;
    var stack : Sequence := () ;
    d[i+1] := Set{}->union((Sequence{ i })) ;
    stack := Sequence{ i } ;
    while stack do (    var v : OclAny := stack->last() ;     stack := stack->front() ;
    seen[v+1] := true ;
    parent[v+1] := i ;
    for nv : f[v+1] do (    if seen[nv+1] then (
      continue
    ) else skip ;
(expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name nv)))))))) )))) ;
    execute ((nv) : stack)))) ;
    var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ;
    for i : Integer.subrange(0, n-1) do (    var group : OclAny := d[parent[i+1]+1] ;
    var tmp : double := (group)->size() - (f[i+1])->size() - 1 ;
    for j : g[i+1] do (    if (group)->includes(j) then (
      tmp := tmp - 1
    ) else skip) ;
    ans[i+1] := tmp) ;
    execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display();
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def xor_pair_sum(ar,n):
    total=0
    for i in range(n):
        total=total ^ ar[i]
    return 2*total
if __name__=="__main__" :
    data=[1,2,3]
    print(xor_pair_sum(data,len(data)))
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      var data : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ;
    execute (xor_pair_sum(data, (data)->size()))->display()
    ) else skip;
  operation xor_pair_sum(ar : OclAny, n : OclAny) : OclAny
  pre: true post: true
  activity:
    var total : int := 0 ;
    for i : Integer.subrange(0, n-1) do (    total := MathLib.bitwiseXor(total, ar[i+1])) ;
    return 2 * total;
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def asciiToSentence(string,length):
    num=0 ;
    for i in range(length):
        num=num*10+(ord(string[i])-ord('0'));
        if(num>=32 and num<=122):
            ch=chr(num);
            print(ch,end="");
            num=0 ;
if __name__=="__main__" :
    string="7110110110711510211111471101101107115" ;
    length=len(string);
    asciiToSentence(string,length);
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    if __name__ = "__main__" then (
      string := "7110110110711510211111471101101107115"; ;
    length := (string)->size(); ;
    asciiToSentence(string, length);
    ) else skip;
  operation asciiToSentence(string : OclAny, length : OclAny)
  pre: true post: true
  activity:
    var num : int := 0; ;
    for i : Integer.subrange(0, length-1) do (    num := num * 10 + ((string[i+1])->char2byte() - ('0')->char2byte()); ;
    if (num >= 32 & num <= 122) then (
      var ch : String := (num)->byte2char(); ;
    execute (ch)->display(); ;
    num := 0;
    ) else skip);
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
def count(n):
    count=0
    while(n):
        count+=n & 1
        n>>=1
    return count
def findSetBits(n):
    for i in range(n+1):
        print(count(i),end=" ")
if __name__=='__main__' :
    n=5
    findSetBits(n)
------------------------------------------------------------
OCL File:
---------
 class FromPython {
  operation initialise()
  pre: true post: true
  activity:     skip ;
    skip ;
    if __name__ = '__main__' then (
      n := 5 ;
    findSetBits(n)
    ) else skip;
  operation count(n : OclAny) : OclAny
  pre: true post: true
  activity:
    var count : int := 0 ;
    while (n) do (    count := count + MathLib.bitwiseAnd(n, 1) ;
    n := n div (2->pow(1))) ;
    return count;
  operation findSetBits(n : OclAny)
  pre: true post: true
  activity:
    for i : Integer.subrange(0, n + 1-1) do (    execute (count(i))->display());
}

------------------------------------------------------------
------------------------------------------------------------
Python Program:
---------------
inp_file=file("B-small.in")
out_file=file("B-small.out","w")
def solve(line):
    A,B,P=[int(c1)for c1 in line.split(" ")]
    numbers=range(A,B+1)
    sets=range(B-A+1)
    for c1 in primes :
        if c1

collect( _x | (OclType["int"])->apply(_x) ) ; var facts : Sequence := Sequence{ 1 } ; var invs : Sequence := Sequence{ 1 } ; var pow2 : Sequence := Sequence{ 1 } ; for i : Integer.subrange(1, n + k-1) do ( var f : int := i * facts[i - 1+1] mod MOD ; execute ((f) : facts) ; execute (((f)->pow(MOD - 2)) : invs) ; execute (((2)->pow(i) mod MOD) : pow2)) ; skip ; skip ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(2, k + 2-1) do ( var p : int := i div 2 ; var ans_i : int := 0 ; for q : Integer.subrange(0, Set{p + 1, n + 1}->min()-1) do ( if k - i + q < 0 then ( continue ) else skip ; if i mod 2 > 0 then ( ans_i := ans->last() ; break ) else ( var ans_iq : int := 0 ; if q > 0 & k - i + q > 0 then ( ans_iq := (ans_iq + pow2[q - 1+1] * nCk(p - 1, q - 1) * nHk(k - (i - 1) + (q - 1), n - q)) mod MOD ) else skip ; if (q->compareTo(p)) < 0 then ( ans_iq := (ans_iq + pow2[q+1] * nCk(p - 1, q) * nHk(k - (i - 1) + q, n - q)) mod MOD ) else skip ) ; ans_i := (ans_i + ans_iq) mod MOD) ; execute ((ans_i) : ans)) ; for a : ans->union(ans(subscript (test (logical_test (comparison (expr (atom - (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) do ( execute (a)->display()); operation nCk(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: return (facts[n+1] * invs[k+1] * invs[n - k+1]) mod MOD; operation nHk(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: return nCk(n + k - 1, n - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=998244353 def cmb(n,r): if r<0 or r>n : return 0 return(g1[n]*g2[r]*g2[n-r])% mod g1=[1,1] g2=[1,1] inv=[0,1] for i in range(2,100003): g1.append((g1[-1]*i)% mod) inv.append((-inv[mod % i]*(mod//i))% mod) g2.append((g2[-1]*inv[-1])% mod) K,N=map(int,input().split()) C=[0]*(2*K) for i in range(K): for j in range(i+1,K): C[i+j]+=1 for i in range(2*K-1): P=0 if i & 1 : for j in range(C[i]+1): P=(P+cmb(K+N-2*C[i]-1,N-j)*pow(2,j,mod)*cmb(C[i],j))% mod else : for k in range(2): for j in range(C[i]+1): P=(P+cmb(K+N-2*C[i]-2-k,N-j-k)*pow(2,j,mod)*cmb(C[i],j))% mod print(P) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : int := 998244353 ; skip ; var g1 : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var g2 : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var inv : Sequence := Sequence{0}->union(Sequence{ 1 }) ; for i : Integer.subrange(2, 100003-1) do ( execute (((g1->last() * i) mod mod) : g1) ; execute (((-inv[mod mod i+1] * (mod div i)) mod mod) : inv) ; execute (((g2->last() * inv->last()) mod mod) : g2)) ; var K : OclAny := null; var N : OclAny := null; Sequence{K,N} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var C : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * K)) ; for i : Integer.subrange(0, K-1) do ( for j : Integer.subrange(i + 1, K-1) do ( C[i + j+1] := C[i + j+1] + 1)) ; for i : Integer.subrange(0, 2 * K - 1-1) do ( var P : int := 0 ; if MathLib.bitwiseAnd(i, 1) then ( for j : Integer.subrange(0, C[i+1] + 1-1) do ( P := (P + cmb(K + N - 2 * C[i+1] - 1, N - j) * (2)->pow(j) * cmb(C[i+1], j)) mod mod) ) else ( for k : Integer.subrange(0, 2-1) do ( for j : Integer.subrange(0, C[i+1] + 1-1) do ( P := (P + cmb(K + N - 2 * C[i+1] - 2 - k, N - j - k) * (2)->pow(j) * cmb(C[i+1], j)) mod mod)) ) ; execute (P)->display()); operation cmb(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: if r < 0 or (r->compareTo(n)) > 0 then ( return 0 ) else skip ; return (g1[n+1] * g2[r+1] * g2[n - r+1]) mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- K,N=list(map(int,input().split())) dprint=lambda*x : x def cmb(n,r,mod): if(r<0 or r>n): return 0 r=min(r,n-r) return g1[n]*g2[r]*g2[n-r]% mod mod=998244353 __N=8000 g1=[1,1] g2=[1,1] inverse=[0,1] for i in range(2,__N+1): g1.append((g1[-1]*i)% mod) inverse.append((-inverse[mod % i]*(mod//i))% mod) g2.append((g2[-1]*inverse[-1])% mod) def kumiawase(p,q): return cmb(p+q-1,q-1,mod) def solve(n): assert n<=K+1 ans=0 kumi=(n-1)//2 for p in range(kumi+1): if p>N : break ans+=2**p*cmb(kumi,p,mod)*kumiawase(N-p,p+(K-kumi*2-int(n % 2==0))) if n % 2==0 and N-p-1>=0 : ans+=2**p*cmb(kumi,p,mod)*kumiawase(N-p-1,p+(K-kumi*2-int(n % 2==0))) return ans ans=[] for i in range(2,2*K+1): if i<=K+1 : tmp=solve(i)% 998244353 ans.append(tmp) print(tmp) else : print(ans[-i+K]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var K : OclAny := null; var N : OclAny := null; Sequence{K,N} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dprint : Function := lambda x : Sequence(OclAny) in (x) ; skip ; mod := 998244353 ; var __N : int := 8000 ; var g1 : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var g2 : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var inverse : Sequence := Sequence{0}->union(Sequence{ 1 }) ; for i : Integer.subrange(2, __N + 1-1) do ( execute (((g1->last() * i) mod mod) : g1) ; execute (((-inverse[mod mod i+1] * (mod div i)) mod mod) : inverse) ; execute (((g2->last() * inverse->last()) mod mod) : g2)) ; skip ; skip ; ans := Sequence{} ; for i : Integer.subrange(2, 2 * K + 1-1) do ( if (i->compareTo(K + 1)) <= 0 then ( var tmp : int := solve(i) mod 998244353 ; execute ((tmp) : ans) ; execute (tmp)->display() ) else ( execute (ans->reverse()->at(-(-i + K)))->display() )); operation cmb(n : OclAny, r : OclAny, mod : OclAny) : OclAny pre: true post: true activity: if (r < 0 or (r->compareTo(n)) > 0) then ( return 0 ) else skip ; r := Set{r, n - r}->min() ; return g1[n+1] * g2[r+1] * g2[n - r+1] mod mod; operation kumiawase(p : OclAny, q : OclAny) : OclAny pre: true post: true activity: return cmb(p + q - 1, q - 1, mod); operation solve(n : OclAny) : OclAny pre: true post: true activity: assert (n->compareTo(K + 1)) <= 0 do "assertion failed" ; var ans : int := 0 ; var kumi : int := (n - 1) div 2 ; for p : Integer.subrange(0, kumi + 1-1) do ( if (p->compareTo(N)) > 0 then ( break ) else skip ; ans := ans + (2)->pow(p) * cmb(kumi, p, mod) * kumiawase(N - p, p + (K - kumi * 2 - ("" + ((n mod 2 = 0)))->toInteger())) ; if n mod 2 = 0 & N - p - 1 >= 0 then ( ans := ans + (2)->pow(p) * cmb(kumi, p, mod) * kumiawase(N - p - 1, p + (K - kumi * 2 - ("" + ((n mod 2 = 0)))->toInteger())) ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input(); x=input() if set(x)!={'0'}: print('1'+(x.count('0')*'0')) else : print('0') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine(); var x : String := (OclFile["System.in"]).readLine() ; if Set{}->union((x)) /= Set{ '0' } then ( execute ('1' + (x->count('0') * '0'))->display() ) else ( execute ('0')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k,x=list(map(int,input().split())) a=list(map(int,input().split())) for i in range(n-k,n): a[i]=x print(sum(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var x : OclAny := null; Sequence{n,k,x} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(n - k, n-1) do ( a[i+1] := x) ; execute ((a)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- length=input() bin_num=input() zero_count=sum([1 for i in bin_num if i=="0"]) smallest_bin="1"+"0"*zero_count if length=="1" and bin_num=="0" : print("0") else : print(smallest_bin) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var length : String := (OclFile["System.in"]).readLine() ; var bin_num : String := (OclFile["System.in"]).readLine() ; var zero_count : OclAny := (bin_num->characters()->select(i | i = "0")->collect(i | (1)))->sum() ; var smallest_bin : String := "1" + StringLib.nCopies("0", zero_count) ; if length = "1" & bin_num = "0" then ( execute ("0")->display() ) else ( execute (smallest_bin)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() s=input() print(s[0]+'0'*s[1 :].count('0')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var s : String := (OclFile["System.in"]).readLine() ; execute (s->first() + StringLib.nCopies('0', s->tail()->count('0')))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) s=input() m=s.count('0') if s[0]=='1' : print('1',end='') while m : print('0',end='') m-=1 def main(): t=1 while t>0 : solve() t-=1 main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var m : int := s->count('0') ; if s->first() = '1' then ( execute ('1')->display() ) else skip ; while m do ( execute ('0')->display() ; m := m - 1); operation main() pre: true post: true activity: var t : int := 1 ; while t > 0 do ( solve() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import* from dataclasses import dataclass from decimal import* def solves(): n=int(input()) s=input() if s.count('1')==0 : print(0) else : print('1'+'0'*s.count('0')) t=1 for _ in range(0,t): solves() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solves()); operation solves() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; if s->count('1') = 0 then ( execute (0)->display() ) else ( execute ('1' + StringLib.nCopies('0', s->count('0')))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) c=0 for i in range(N): a=list(input().split()) if a[1]=='BTC' : c+=float(a[0])*380000.0 else : c+=float(a[0]) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := 0 ; for i : Integer.subrange(0, N-1) do ( var a : Sequence := (input().split()) ; if a[1+1] = 'BTC' then ( c := c + ("" + ((a->first())))->toReal() * 380000.0 ) else ( c := c + ("" + ((a->first())))->toReal() )) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) x=[eval(input().replace('JPY','*1.0').replace('BTC','*380000.0'))for i in range(N)] print(sum(x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (input().replace('JPY', '*1.0').replace('BTC', '*380000.0'))) ; execute ((x)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findN(k): if(k==0): ans=3 if(k==1): ans=1 elif(k % 4==0): ans=k elif(k % 4==3): ans=k-1 else : ans=-1 return ans k=7 res=findN(k) if(res==-1): print("Not possible") else : print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; k := 7 ; var res : OclAny := findN(k) ; if (res = -1) then ( execute ("Not possible")->display() ) else ( execute (res)->display() ); operation findN(k : OclAny) : OclAny pre: true post: true activity: if (k = 0) then ( var ans : int := 3 ) else skip ; if (k = 1) then ( ans := 1 ) else (if (k mod 4 = 0) then ( ans := k ) else (if (k mod 4 = 3) then ( ans := k - 1 ) else ( ans := -1 ) ) ) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import copy inputa=input().split() a=int(inputa[0]) inputList=[] for i in range(a): inputNum=input().split() inputList.append(inputNum) sum=0 btc2jpy=380000.0 for i in range(a): tmp=float(inputList[i][0]) if str(inputList[i][1])=="JPY" : sum+=tmp else : sum+=btc2jpy*tmp print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var inputa : OclAny := input().split() ; var a : int := ("" + ((inputa->first())))->toInteger() ; var inputList : Sequence := Sequence{} ; for i : Integer.subrange(0, a-1) do ( var inputNum : OclAny := input().split() ; execute ((inputNum) : inputList)) ; var sum : int := 0 ; var btc2jpy : double := 380000.0 ; for i : Integer.subrange(0, a-1) do ( var tmp : double := ("" + ((inputList[i+1]->first())))->toReal() ; if ("" + ((inputList[i+1][1+1]))) = "JPY" then ( sum := sum + tmp ) else ( sum := sum + btc2jpy * tmp )) ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,Counter import math from bisect import bisect_left,bisect_right import numpy as np N=int(input()) x=[] u=[] for _ in range(N): li=input().split() x.append(float(li[0])) u.append(li[1]) ans=0 for x_i,u_i in zip(x,u): if u_i=="JPY" : ans+=x_i else : ans+=x_i*380000.0 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := Sequence{} ; var u : Sequence := Sequence{} ; for _anon : Integer.subrange(0, N-1) do ( var li : OclAny := input().split() ; execute ((("" + ((li->first())))->toReal()) : x) ; execute ((li[1+1]) : u)) ; var ans : int := 0 ; for _tuple : Integer.subrange(1, x->size())->collect( _indx | Sequence{x->at(_indx), u->at(_indx)} ) do (var _indx : int := 1; var x_i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var u_i : OclAny := _tuple->at(_indx); if u_i = "JPY" then ( ans := ans + x_i ) else ( ans := ans + x_i * 380000.0 )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) lst=[list(input().split())for row in range(N)] btc_to_jpy=380000.0 total_value=0 i=0 while itoInteger() ; var lst : Sequence := Integer.subrange(0, N-1)->select(row | true)->collect(row | ((input().split()))) ; var btc_to_jpy : double := 380000.0 ; var total_value : int := 0 ; var i : int := 0 ; while (i->compareTo(N)) < 0 do ( var value : double := ("" + ((lst[i+1]->first())))->toReal() ; if lst[i+1][1+1] = 'JPY' then ( total_value := total_value + value ) else ( total_value := total_value + value * btc_to_jpy ) ; i := i + 1) ; execute (total_value)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import* from bisect import* def read_input(input_path=None): if input_path is None : f=sys.stdin else : f=open(input_path,'r') n,m,a,d=map(int,f.readline().split()) t=list(map(int,f.readline().split())) return n,m,a,d,t def sol(n1,m,a,d,t): insort(t,a*n1) pred=0 k=0 n=0 step=d//a+1 answer=0 fl=0 for i in t : if i>pred : if fl==0 : n=(i-pred+(pred % a))//a if n!=0 : k+=(n//step)*step-step*(n % step==0)+1 if k>n1 : k=n1 fl=1 if(k*a+d>=i)and(n!=0): pred=k*a+d else : pred=i+d k=floor(pred//a) answer+=1 k=min(floor(pred//a),n1) answer+=n//step+(n % step!=0) else : answer+=1 pred=i+d if i==a*n1 : fl=1 return[f"{answer}"] def solve(input_path=None): return sol(*read_input(input_path)) def main(): for line in sol(*read_input()): print(f"{line}") if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation read_input(input_path : OclAny) : OclAny pre: true post: true activity: if input_path->oclIsUndefined() then input_path := null else skip; if input_path <>= null then ( var f : OclFile := OclFile["System.in"] ) else ( f := OclFile.newOclFile_Write(OclFile.newOclFile(input_path)) ) ; var n : OclAny := null; var m : OclAny := null; var a : OclAny := null; var d : OclAny := null; Sequence{n,m,a,d} := (f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : Sequence := ((f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; return n, m, a, d, t; operation sol(n1 : OclAny, m : OclAny, a : OclAny, d : OclAny, t : OclAny) : OclAny pre: true post: true activity: insort(t, a * n1) ; var pred : int := 0 ; var k : int := 0 ; var n : int := 0 ; var step : int := d div a + 1 ; var answer : int := 0 ; var fl : int := 0 ; for i : t do ( if (i->compareTo(pred)) > 0 then ( if fl = 0 then ( n := (i - pred + (pred mod a)) div a ; if n /= 0 then ( k := k + (n div step) * step - step * (n mod step = 0) + 1 ; if (k->compareTo(n1)) > 0 then ( k := n1 ; fl := 1 ) else skip ) else skip ; if ((k * a + d->compareTo(i)) >= 0) & (n /= 0) then ( pred := k * a + d ) else ( pred := i + d ; k := floor(pred div a) ; answer := answer + 1 ) ; k := Set{floor(pred div a), n1}->min() ; answer := answer + n div step + (n mod step /= 0) ) else ( answer := answer + 1 ; pred := i + d ) ) else skip ; if i = a * n1 then ( fl := 1 ) else skip) ; return Sequence{ StringLib.formattedString("{answer}") }; operation solve(input_path : OclAny) : OclAny pre: true post: true activity: if input_path->oclIsUndefined() then input_path := null else skip; return sol((argument * (test (logical_test (comparison (expr (atom (name read_input)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input_path)))))))) ))))))))); operation main() pre: true post: true activity: for line : sol((argument * (test (logical_test (comparison (expr (atom (name read_input)) (trailer (arguments ( ))))))))) do ( execute (StringLib.formattedString("{line}"))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getCount(arr,n,num1,num2): for i in range(0,n): if(arr[i]==num1): break if(i>=n-1): return 0 for j in range(n-1,i+1,-1): if(arr[j]==num2): break if(j==i): return 0 return(j-i-1) arr=[3,5,7,6,4,9,12,4,8] n=len(arr) num1=5 num2=4 print(getCount(arr,n,num1,num2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{6}->union(Sequence{4}->union(Sequence{9}->union(Sequence{12}->union(Sequence{4}->union(Sequence{ 8 })))))))) ; n := (arr)->size() ; num1 := 5 ; num2 := 4 ; execute (getCount(arr, n, num1, num2))->display(); operation getCount(arr : OclAny, n : OclAny, num1 : OclAny, num2 : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if (arr[i+1] = num1) then ( break ) else skip) ; if ((i->compareTo(n - 1)) >= 0) then ( return 0 ) else skip ; for j : Integer.subrange(i + 1 + 1, n - 1)->reverse() do ( if (arr[j+1] = num2) then ( break ) else skip) ; if (j = i) then ( return 0 ) else skip ; return (j - i - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if n==0 : break a=sorted(list(map(int,input().split()))) print(min(a[i+1]-a[i]for i in range(n-1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; execute (((argument (test (logical_test (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))) - (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) )))))))))->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getMinGap(data): result=list() for n in range(len(data)): for m in range(n+1,len(data)): result.append(abs(data[n]-data[m])) result=set(result) return min(result) while True : n=int(input()) if n==0 : break data=[int(x)for x in input().split()] print(getMinGap(data)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; data := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (getMinGap(data))->display()); operation getMinGap(data : OclAny) : OclAny pre: true post: true activity: var result : Sequence := () ; for n : Integer.subrange(0, (data)->size()-1) do ( for m : Integer.subrange(n + 1, (data)->size()-1) do ( execute (((data[n+1] - data[m+1])->abs()) : result))) ; result := Set{}->union((result)) ; return (result)->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**9) input=sys.stdin.readline def solve(): N=int(input()) if N==0 : exit() L=list(map(int,input().split())) L=sorted(L) min_diff=float('inf') for l1,l2 in zip(L,L[1 :]): min_diff=min(min_diff,abs(l1-l2)) print(min_diff) while True : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(9)) ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; while true do ( solve()); operation solve() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( exit() ) else skip ; var L : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; L := L->sort() ; var min_diff : double := ("" + (('inf')))->toReal() ; for _tuple : Integer.subrange(1, L->size())->collect( _indx | Sequence{L->at(_indx), L->tail()->at(_indx)} ) do (var _indx : int := 1; var l1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var l2 : OclAny := _tuple->at(_indx); min_diff := Set{min_diff, (l1 - l2)->abs()}->min()) ; execute (min_diff)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : ans=1000000 n=int(input()) ls=list(map(int,input().split())) ls.sort() for i in range(1,n): if ls[i]-ls[i-1]toInteger() ; var ls : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; ls := ls->sort() ; for i : Integer.subrange(1, n-1) do ( if (ls[i+1] - ls[i - 1+1]->compareTo(ans)) < 0 then ( ans := ls[i+1] - ls[i - 1+1] ) else skip) ; execute (ans)->display()) catch (_e : OclException) do ( break;) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): while True : s_num=int(input()) if s_num==0 : return s_dat=input() s_dat=s_dat.split(" ") for j in range(len(s_dat)): s_dat[j]=int(s_dat[j]) s_dat.sort() answer=sa(s_dat) print(answer) def sa(array): min_dist=1000000+1 for i in range(len(array)-1): dist=array[i+1]-array[i] if dist<=min_dist : min_dist=dist return min_dist main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: while true do ( var s_num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if s_num = 0 then ( return ) else skip ; var s_dat : String := (OclFile["System.in"]).readLine() ; s_dat := s_dat.split(" ") ; for j : Integer.subrange(0, (s_dat)->size()-1) do ( s_dat[j+1] := ("" + ((s_dat[j+1])))->toInteger()) ; s_dat := s_dat->sort() ; var answer : OclAny := sa(s_dat) ; execute (answer)->display()); operation sa(array : OclAny) : OclAny pre: true post: true activity: var min_dist : int := 1000000 + 1 ; for i : Integer.subrange(0, (array)->size() - 1-1) do ( var dist : double := array[i + 1+1] - array[i+1] ; if (dist->compareTo(min_dist)) <= 0 then ( min_dist := dist ) else skip) ; return min_dist; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSetBits(n): cnt=0 setBits=[0 for x in range(n+1)] setBits[0]=0 setBits[1]=1 for i in range(2,n+1): if(i % 2==0): setBits[i]=setBits[i//2] else : setBits[i]=setBits[i-1]+1 for i in range(0,n+1): cnt=cnt+setBits[i] return cnt n=6 print(countSetBits(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 6 ; execute (countSetBits(n))->display(); operation countSetBits(n : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; var setBits : Sequence := Integer.subrange(0, n + 1-1)->select(x | true)->collect(x | (0)) ; setBits->first() := 0 ; setBits[1+1] := 1 ; for i : Integer.subrange(2, n + 1-1) do ( if (i mod 2 = 0) then ( setBits[i+1] := setBits[i div 2+1] ) else ( setBits[i+1] := setBits[i - 1+1] + 1 )) ; for i : Integer.subrange(0, n + 1-1) do ( cnt := cnt + setBits[i+1]) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import log2 def subsetXOR(arr,n,K): max_ele=arr[0] for i in range(1,n): if(arr[i]>max_ele): max_ele=arr[i] m=(1<union(Sequence{2}->union(Sequence{ 3 })) ; var k : int := 1 ; n := (arr)->size() ; execute (subsetXOR(arr, n, k))->display() ) else skip; operation subsetXOR(arr : OclAny, n : OclAny, K : OclAny) : OclAny pre: true post: true activity: var max_ele : OclAny := arr->first() ; for i : Integer.subrange(1, n-1) do ( if ((arr[i+1]->compareTo(max_ele)) > 0) then ( max_ele := arr[i+1] ) else skip) ; var m : double := (1 * (2->pow(("" + ((log2(max_ele) + 1)))->toInteger()))) - 1 ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(k | true)->collect(k | (Integer.subrange(0, m + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)))))) ; for i : Integer.subrange(0, n + 1-1) do ( for j : Integer.subrange(0, m + 1-1) do ( for k : Integer.subrange(0, n + 1-1) do ( dp[i+1][j+1][k+1] := 0))) ; for i : Integer.subrange(0, n + 1-1) do ( dp[i+1]->first()->first() := 1) ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(0, m + 1-1) do ( for k : Integer.subrange(0, n + 1-1) do ( dp[i+1][j+1][k+1] := dp[i - 1+1][j+1][k+1] ; if (k /= 0) then ( dp[i+1][j+1][k+1] := dp[i+1][j+1][k+1] + k * dp[i - 1+1][MathLib.bitwiseXor(j, arr[i - 1+1])+1][k - 1+1] ) else skip))) ; var ans : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( ans := ans + dp[n+1][K+1][i+1]) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(a==0): return b return gcd(b % a,a) def largestGCD1Subset(A,n): currentGCD=A[0]; for i in range(1,n): currentGCD=gcd(currentGCD,A[i]) if(currentGCD==1): return n return 0 A=[2,18,6,3] n=len(A) print(largestGCD1Subset(A,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; A := Sequence{2}->union(Sequence{18}->union(Sequence{6}->union(Sequence{ 3 }))) ; n := (A)->size() ; execute (largestGCD1Subset(A, n))->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0) then ( return b ) else skip ; return gcd(b mod a, a); operation largestGCD1Subset(A : OclAny, n : OclAny) : OclAny pre: true post: true activity: var currentGCD : OclAny := A->first(); ; for i : Integer.subrange(1, n-1) do ( currentGCD := gcd(currentGCD, A[i+1]) ; if (currentGCD = 1) then ( return n ) else skip) ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): divisors=[2]*(10**7+1) for i in range(2,(len(divisors)+1)//2): for j in range(i*2,len(divisors),i): divisors[j]+=1 ans=sum((1 if divisors[i]==divisors[i+1]else 0)for i in range(2,len(divisors)-1)) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var divisors : Sequence := MatrixLib.elementwiseMult(Sequence{ 2 }, ((10)->pow(7) + 1)) ; for i : Integer.subrange(2, ((divisors)->size() + 1) div 2-1) do ( for j : Integer.subrange(i * 2, (divisors)->size()-1)->select( $x | ($x - i * 2) mod i = 0 ) do ( divisors[j+1] := divisors[j+1] + 1)) ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1)))))) if (logical_test (comparison (comparison (expr (atom (name divisors)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (name divisors)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])))))) else (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name divisors)))))))) )))) - (expr (atom (number (integer 1)))))))))) )))))))))->sum() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n1,m,a,d=list(map(int,input().split())) t=list(map(int,input().split())) from bisect import* from math import* insort(t,a*n1) pred=0 k=0 kpred=0 n=0 step=d//a+1 sol=0 fl=0 for i in t : if(i>pred): if fl==0 : n=(i-pred+(pred % a))//a if n!=0 : k+=(n//step)*step-step*(n % step==0)+1 if k>n1 : k=n1 fl=1 if(k*a+d>=i)and(n!=0): pred=k*a+d else : pred=i+d k=floor(pred//a) sol+=1 k=min(floor(pred//a),n1) sol+=n//step+(n % step!=0) else : sol+=1 pred=i+d if i==a*n1 : fl=1 print(sol) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n1 : OclAny := null; var m : OclAny := null; var a : OclAny := null; var d : OclAny := null; Sequence{n1,m,a,d} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; skip ; insort(t, a * n1) ; var pred : int := 0 ; var k : int := 0 ; var kpred : int := 0 ; var n : int := 0 ; var step : int := d div a + 1 ; var sol : int := 0 ; var fl : int := 0 ; for i : t do ( if ((i->compareTo(pred)) > 0) then ( if fl = 0 then ( n := (i - pred + (pred mod a)) div a ; if n /= 0 then ( k := k + (n div step) * step - step * (n mod step = 0) + 1 ; if (k->compareTo(n1)) > 0 then ( k := n1 ; fl := 1 ) else skip ) else skip ; if ((k * a + d->compareTo(i)) >= 0) & (n /= 0) then ( pred := k * a + d ) else ( pred := i + d ; k := floor(pred div a) ; sol := sol + 1 ) ; k := Set{floor(pred div a), n1}->min() ; sol := sol + n div step + (n mod step /= 0) ) else ( sol := sol + 1 ; pred := i + d ) ) else skip ; if i = a * n1 then ( fl := 1 ) else skip) ; execute (sol)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findEncryptedArray(arr,n): sum=0 for i in range(n): sum+=arr[i] for i in range(n): print(sum-arr[i],end=" ") if __name__=="__main__" : arr=[5,1,3,2,4] N=len(arr) findEncryptedArray(arr,N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{5}->union(Sequence{1}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 4 })))) ; var N : int := (arr)->size() ; findEncryptedArray(arr, N) ) else skip; operation findEncryptedArray(arr : OclAny, n : OclAny) pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + arr[i+1]) ; for i : Integer.subrange(0, n-1) do ( execute (sum - arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def updateArray(arr,n): i=n-1 while(i>0): arr[i]=arr[i-1] i-=1 arr[0]=-1 for i in range(0,n,1): print(arr[i],end=" ") if __name__=='__main__' : arr=[5,1,3,2,4] N=len(arr) updateArray(arr,N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{5}->union(Sequence{1}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 4 })))) ; var N : int := (arr)->size() ; updateArray(arr, N) ) else skip; operation updateArray(arr : OclAny, n : OclAny) pre: true post: true activity: var i : double := n - 1 ; while (i > 0) do ( arr[i+1] := arr[i - 1+1] ; i := i - 1) ; arr->first() := -1 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def updateArray(arr,n): for i in range(n-1): arr[i]=arr[i+1] arr[n-1]=-1 for i in range(n): print(arr[i],end=" ") if __name__=="__main__" : arr=[5,1,3,2,4] N=len(arr) updateArray(arr,N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{5}->union(Sequence{1}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 4 })))) ; var N : int := (arr)->size() ; updateArray(arr, N) ) else skip; operation updateArray(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n - 1-1) do ( arr[i+1] := arr[i + 1+1]) ; arr[n - 1+1] := -1 ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMinDifference(arr,n): if(arr[0]max__): secondMax=max__ max__=arr[i] elif(arr[i]>secondMax): secondMax=arr[i] elif(arr[i]union(Sequence{2}->union(Sequence{4}->union(Sequence{3}->union(Sequence{ 4 })))) ; n := (arr)->size() ; execute (findMinDifference(arr, n))->display() ) else skip; operation findMinDifference(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: if ((arr->first()->compareTo(arr[1+1])) < 0) then ( var min__ : OclAny := arr->first(); var secondMax : OclAny := arr->first() ) else ( min__ := arr[1+1]; secondMax := arr[1+1] ) ; if ((arr->first()->compareTo(arr[1+1])) < 0) then ( var max__ : OclAny := arr[1+1]; var secondMin : OclAny := arr[1+1] ) else ( max__ := arr->first(); secondMin := arr->first() ) ; for i : Integer.subrange(2, n-1) do ( if ((arr[i+1]->compareTo(max__)) > 0) then ( secondMax := max__ ; max__ := arr[i+1] ) else (if ((arr[i+1]->compareTo(secondMax)) > 0) then ( secondMax := arr[i+1] ) else (if ((arr[i+1]->compareTo(min__)) < 0) then ( secondMin := min__ ; min__ := arr[i+1] ) else (if ((arr[i+1]->compareTo(secondMin)) < 0) then ( secondMin := arr[i+1] ) else skip ) ) ) ) ; var diff : OclAny := Set{max__ - secondMin, secondMax - min__}->min() ; return diff; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import sqrt read=sys.stdin.readline write=sys.stdout.write def factor(a,b): ret=set() i=2 while i<=sqrt(max(a,b)): while a % i==0 : ret.add(i) a//=i while b % i==0 : ret.add(i) b//=i i+=1 if a>=2 : ret.add(a) if b>=2 : ret.add(b) return ret def test(a,b,s): ret=set() for i in s : if a % i==0 or b % i==0 : ret.add(i) return ret n=int(read()) a=[] b=[] for _ in range(n): x,y=map(int,read().split()) a.append(x); b.append(y); f=factor(a[0],b[0]) for i in range(1,n): f=test(a[i],b[i],f) if len(f)==0 : write("-1\n") else : for i in f : write(str(i)+'\n') break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var read : OclAny := (OclFile["System.in"]).readline ; var write : OclAny := (OclFile["System.out"]).write ; skip ; skip ; var n : int := ("" + ((read())))->toInteger() ; a := Sequence{} ; b := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (read().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((x) : a); execute ((y) : b);) ; var f : OclAny := factor(a->first(), b->first()) ; for i : Integer.subrange(1, n-1) do ( f := test(a[i+1], b[i+1], f)) ; if (f)->size() = 0 then ( write("-1\n") ) else ( for i : f do ( write(("" + ((i))) + ' ') ; break) ); operation factor(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var ret : Set := Set{}->union(()) ; var i : int := 2 ; while (i->compareTo(sqrt(Set{a, b}->max()))) <= 0 do ( while a mod i = 0 do ( execute ((i) : ret) ; a := a div i) ; while b mod i = 0 do ( execute ((i) : ret) ; b := b div i) ; i := i + 1) ; if a >= 2 then ( execute ((a) : ret) ) else skip ; if b >= 2 then ( execute ((b) : ret) ) else skip ; return ret; operation test(a : OclAny, b : OclAny, s : OclAny) : OclAny pre: true post: true activity: ret := Set{}->union(()) ; for i : s do ( if a mod i = 0 or b mod i = 0 then ( execute ((i) : ret) ) else skip) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def check(f): for Ai,Bi in AB : if Ai % f!=0 and Bi % f!=0 : return False return True def factorize(n): factors=[] for i in range(2,int(n**0.5)+1): cnt=0 while n % i==0 : n//=i cnt+=1 if cnt>0 : factors.append((i,cnt)) if n>1 : factors.append((n,1)) return factors n=int(input()) AB=[tuple(map(int,input().split()))for _ in range(n)] cands=factorize(AB[0][0])+factorize(AB[0][1]) for f,_ in cands : if check(f): print(f) exit() print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var AB : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var cands : OclAny := factorize(AB->first()->first()) + factorize(AB->first()[1+1]) ; for _tuple : cands do (var _indx : int := 1; var f : OclAny := _tuple->at(_indx); _indx := _indx + 1; var _anon : OclAny := _tuple->at(_indx); if check(f) then ( execute (f)->display() ; exit() ) else skip) ; execute (-1)->display(); operation check(f : OclAny) : OclAny pre: true post: true activity: for _tuple : AB do (var _indx : int := 1; var Ai : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Bi : OclAny := _tuple->at(_indx); if Ai mod f /= 0 & Bi mod f /= 0 then ( return false ) else skip) ; return true; operation factorize(n : OclAny) : OclAny pre: true post: true activity: var factors : Sequence := Sequence{} ; for i : Integer.subrange(2, ("" + (((n)->pow(0.5))))->toInteger() + 1-1) do ( var cnt : int := 0 ; while n mod i = 0 do ( n := n div i ; cnt := cnt + 1) ; if cnt > 0 then ( execute ((Sequence{i, cnt}) : factors) ) else skip) ; if n > 1 then ( execute ((Sequence{n, 1}) : factors) ) else skip ; return factors; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(input()) l=[] for _ in range(n): a,b=map(int,sys.stdin.readline().split()) l.append([a,b]) a=l[0][0] b=l[0][1] ans=-1 j=2 def is_all(u): for i in l : if i[0]% u!=0 and i[1]% u!=0 : return False return True def is_prime(n : int)->bool : if n<=3 : return n>1 if n % 2==0 or n % 3==0 : return False i=5 while i**2<=n : if n % i==0 or n %(i+2)==0 : return False i+=6 return True while j*j<=a or j*j<=b : if a % j==0 : k=a//j if is_prime(j)and is_all(j): ans=j break if is_prime(k)and is_all(k): ans=k break if b % j==0 : k=b//j if is_prime(j)and is_all(j): ans=j break if is_prime(k)and is_all(k): ans=k break j+=1 if is_prime(a)and is_all(a): ans=a if is_prime(b)and is_all(b): ans=b print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a}->union(Sequence{ b })) : l)) ; var a : OclAny := l->first()->first() ; var b : OclAny := l->first()[1+1] ; var ans : int := -1 ; var j : int := 2 ; skip ; skip ; while (j * j->compareTo(a)) <= 0 or (j * j->compareTo(b)) <= 0 do ( if a mod j = 0 then ( var k : int := a div j ; if is_prime(j) & is_all(j) then ( ans := j ; break ) else skip ; if is_prime(k) & is_all(k) then ( ans := k ; break ) else skip ) else skip ; if b mod j = 0 then ( k := b div j ; if is_prime(j) & is_all(j) then ( ans := j ; break ) else skip ; if is_prime(k) & is_all(k) then ( ans := k ; break ) else skip ) else skip ; j := j + 1) ; if is_prime(a) & is_all(a) then ( ans := a ) else skip ; if is_prime(b) & is_all(b) then ( ans := b ) else skip ; execute (ans)->display(); operation is_all(u : OclAny) : OclAny pre: true post: true activity: for i : l do ( if i->first() mod u /= 0 & i[1+1] mod u /= 0 then ( return false ) else skip) ; return true; operation is_prime(n : int) : boolean pre: true post: true activity: if n <= 3 then ( return n > 1 ) else skip ; if n mod 2 = 0 or n mod 3 = 0 then ( return false ) else skip ; var i : int := 5 ; while ((i)->pow(2)->compareTo(n)) <= 0 do ( if n mod i = 0 or n mod (i + 2) = 0 then ( return false ) else skip ; i := i + 6) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def computeGCD(x,y): while(y): x,y=y,x % y return x t=1 for _ in range(t): n=int(input()) v=[] for i in range(n): x,y=map(int,input().split()) v.append(x*y) g=0 for i in range(n): g=computeGCD(g,v[i]) if g==1 : print(-1) else : s=set() a=x for i in range(2,int(x**(0.5))+1): if a % i==0 : s.add(i) while a % i==0 : a=a//i if a>1 : s.add(a) b=y for i in range(2,int(y**(0.5))+1): if b % i==0 : s.add(i) while b % i==0 : b=b//i if b>1 : s.add(b) for i in s : if g % i==0 : ans=i print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var v : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((x * y) : v)) ; var g : int := 0 ; for i : Integer.subrange(0, n-1) do ( g := computeGCD(g, v[i+1])) ; if g = 1 then ( execute (-1)->display() ) else ( var s : Set := Set{}->union(()) ; var a : OclAny := x ; for i : Integer.subrange(2, ("" + (((x)->pow((0.5)))))->toInteger() + 1-1) do ( if a mod i = 0 then ( execute ((i) : s) ; while a mod i = 0 do ( a := a div i) ) else skip) ; if a > 1 then ( execute ((a) : s) ) else skip ; var b : OclAny := y ; for i : Integer.subrange(2, ("" + (((y)->pow((0.5)))))->toInteger() + 1-1) do ( if b mod i = 0 then ( execute ((i) : s) ; while b mod i = 0 do ( b := b div i) ) else skip) ; if b > 1 then ( execute ((b) : s) ) else skip ; for i : s do ( if g mod i = 0 then ( var ans : OclAny := i ) else skip) ; execute (ans)->display() )); operation computeGCD(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: while (y) do ( Sequence{x,y} := Sequence{y,x mod y}) ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() ans="" flag=False for c in s : if c=="A" and not flag : flag=True if c=="Z" and flag : ans+="AZ" flag=False if ans=="" : print(-1) else : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var ans : String := "" ; var flag : boolean := false ; for c : s->characters() do ( if c = "A" & not(flag) then ( flag := true ) else skip ; if c = "Z" & flag then ( ans := ans + "AZ" ; flag := false ) else skip) ; if ans = "" then ( execute (-1)->display() ) else ( execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- D,G=map(int,input().split()) PC=[tuple(map(int,input().split()))for _ in range(D)] ans=10**9 for i in range(2**D): score=0 problem=0 for j in range(D): if(i>>j)& 1 : score+=100*(j+1)*PC[j][0]+PC[j][1] problem+=PC[j][0] if score>G : continue left=G-score for j in range(D): if(i>>j)& 1 : continue if left>100*(j+1)*PC[j][0]+PC[j][1]: pass else : tmp=(left+(100*(j+1))-1)//(100*(j+1)) ans=min(ans,problem+min(tmp,PC[j][0])) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var D : OclAny := null; var G : OclAny := null; Sequence{D,G} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var PC : Sequence := Integer.subrange(0, D-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ans : double := (10)->pow(9) ; for i : Integer.subrange(0, (2)->pow(D)-1) do ( var score : int := 0 ; var problem : int := 0 ; for j : Integer.subrange(0, D-1) do ( if MathLib.bitwiseAnd((i /(2->pow(j))), 1) then ( score := score + 100 * (j + 1) * PC[j+1]->first() + PC[j+1][1+1] ; problem := problem + PC[j+1]->first() ) else skip) ; if (score->compareTo(G)) > 0 then ( continue ) else skip ; var left : double := G - score ; for j : Integer.subrange(0, D-1) do ( if MathLib.bitwiseAnd((i /(2->pow(j))), 1) then ( continue ) else skip ; if (left->compareTo(100 * (j + 1) * PC[j+1]->first() + PC[j+1][1+1])) > 0 then ( skip ) else ( var tmp : int := (left + (100 * (j + 1)) - 1) div (100 * (j + 1)) ; ans := Set{ans, problem + Set{tmp, PC[j+1]->first()}->min()}->min() ))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n1,m,a,d=list(map(int,input().split())) t=list(map(int,input().split())) from bisect import insort from math import floor insort(t,a*n1) pred=0 k=0 kpred=0 n=0 step=d//a+1 sol=0 fl=0 for i in t : if(i>pred): if fl==0 : n=(i-pred+(pred % a))//a if n!=0 : k+=(n//step)*step-step*(n % step==0)+1 if k>n1 : k=n1 fl=1 if(k*a+d>=i)and(n!=0): pred=k*a+d else : pred=i+d k=floor(pred//a) sol+=1 k=min(floor(pred//a),n1) sol+=n//step+(n % step!=0) else : sol+=1 pred=i+d if i==a*n1 : fl=1 print(sol) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: var n1 : OclAny := null; var m : OclAny := null; var a : OclAny := null; var d : OclAny := null; Sequence{n1,m,a,d} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; skip ; insort(t, a * n1) ; var pred : int := 0 ; var k : int := 0 ; var kpred : int := 0 ; var n : int := 0 ; var step : int := d div a + 1 ; var sol : int := 0 ; var fl : int := 0 ; for i : t do ( if ((i->compareTo(pred)) > 0) then ( if fl = 0 then ( n := (i - pred + (pred mod a)) div a ; if n /= 0 then ( k := k + (n div step) * step - step * (n mod step = 0) + 1 ; if (k->compareTo(n1)) > 0 then ( k := n1 ; fl := 1 ) else skip ) else skip ; if ((k * a + d->compareTo(i)) >= 0) & (n /= 0) then ( pred := k * a + d ) else ( pred := i + d ; k := floor(pred div a) ; sol := sol + 1 ) ; k := Set{floor(pred div a), n1}->min() ; sol := sol + n div step + (n mod step /= 0) ) else ( sol := sol + 1 ; pred := i + d ) ) else skip ; if i = a * n1 then ( fl := 1 ) else skip) ; execute (sol)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline ts=set() def ptthuaso(x): for i in range(2,int(x**0.5)+1): while x % i==0 : ts.add(i) x//=i if x>1 : ts.add(x) n=int(input()) a,b=[0]*n,[0]*n for i in range(n): a[i],b[i]=map(int,input().split()) ptthuaso(a[0]) ptthuaso(b[0]) ts=list(ts) for x in ts : dem=0 for i in range(n): if a[i]% x==0 or b[i]% x==0 : dem+=1 if dem==n : print(x) exit(0) print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var ts : Set := Set{}->union(()) ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, n),MatrixLib.elementwiseMult(Sequence{ 0 }, n)} ; for i : Integer.subrange(0, n-1) do ( var a[i+1] : OclAny := null; var b[i+1] : OclAny := null; Sequence{a[i+1],b[i+1]} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; ptthuaso(a->first()) ; ptthuaso(b->first()) ; ts := (ts) ; for x : ts do ( var dem : int := 0 ; for i : Integer.subrange(0, n-1) do ( if a[i+1] mod x = 0 or b[i+1] mod x = 0 then ( dem := dem + 1 ) else skip) ; if dem = n then ( execute (x)->display() ; exit(0) ) else skip) ; execute (-1)->display(); operation ptthuaso(x : OclAny) pre: true post: true activity: for i : Integer.subrange(2, ("" + (((x)->pow(0.5))))->toInteger() + 1-1) do ( while x mod i = 0 do ( execute ((i) : ts) ; x := x div i)) ; if x > 1 then ( execute ((x) : ts) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict while True : n=int(input()) if not n : break stars=defaultdict(int) for s in map(int,input().split()): stars[s]+=1 half_n=n//2 for i,s in stars.items(): if s>half_n : print(i) break else : print('NO COLOR') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(n) then ( break ) else skip ; var stars : OclAny := defaultdict(OclType["int"]) ; for s : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( stars[s+1] := stars[s+1] + 1) ; var half_n : int := n div 2 ; (compound_stmt for (exprlist (expr (atom (name i))) , (expr (atom (name s)))) in (testlist (test (logical_test (comparison (expr (atom (name stars)) (trailer . (name items) (arguments ( )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name s)))) > (comparison (expr (atom (name half_n))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO COLOR'))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if n==0 : break s=sorted(input().split()) print(s[n//2]if s.count(s[n//2])>n/2 else 'NO COLOR') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var s : Sequence := input().split()->sort() ; execute (if (s->count(s[n div 2+1])->compareTo(n / 2)) > 0 then s[n div 2+1] else 'NO COLOR' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline from collections import Counter while True : n=int(input()) if n==0 : break a=tuple(map(int,input().split())) x,w=Counter(a).most_common()[0] print(x if w>(n>>1)else "NO COLOR") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := null; var w : OclAny := null; Sequence{x,w} := Counter(a).most_common()->first() ; execute (if (w->compareTo((n /(2->pow(1))))) > 0 then x else "NO COLOR" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : nums=int(input()) if nums!=0 : d={} stars=list(map(int,input().split())) for x in stars : if x not in d : d[x]=1 else : d[x]+=1 key=list(d.keys()) val=list(d.values()) m=int(max(val)) if m>nums/2 : res=key[val.index(m)] print(res) else : print("NO COLOR") else : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var nums : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if nums /= 0 then ( var d : OclAny := Set{} ; var stars : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for x : stars do ( if (d)->excludes(x) then ( d[x+1] := 1 ) else ( d[x+1] := d[x+1] + 1 )) ; var key : Sequence := (d.keys()) ; var val : Sequence := (d.values()) ; var m : int := ("" + (((val)->max())))->toInteger() ; if (m->compareTo(nums / 2)) > 0 then ( var res : OclAny := key[val->indexOf(m) - 1+1] ; execute (res)->display() ) else ( execute ("NO COLOR")->display() ) ) else ( break )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter while 1 : N=int(input()) if N==0 : break ct=Counter(map(int,input().split())) (a,b),*c=ct.most_common() if b*2>N : print(a) else : print("NO COLOR") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while 1 do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var ct : OclAny := Counter((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var Sequence{a, b} : OclAny := null; var c : OclAny := null; Sequence{Sequence{a, b},c} := ct.most_common(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def factorial(n): return 1 if(n==1 or n==0)else n*factorial(n-1) num=5 print("Factorial of",num,"is",factorial(num)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var num : int := 5 ; execute ("Factorial of")->display(); operation factorial(n : OclAny) : OclAny pre: true post: true activity: return if (n = 1 or n = 0) then 1 else n * factorial(n - 1) endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d,x=map(int,input().split()) weights=[] for i in range(d): weights.append(list(map(int,input().split()))) prices=[] for i in range(d-1): prices.append([weights[i+1][j]-weights[i][j]for j in range(n)]) bag=x for i in range(d-1): dp=[False for i in range(bag+1)] dp[0]=0 for j in range(n): for k in range(bag): if weights[i][j]+kcollect( _x | (OclType["int"])->apply(_x) ) ; var weights : Sequence := Sequence{} ; for i : Integer.subrange(0, d-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : weights)) ; var prices : Sequence := Sequence{} ; for i : Integer.subrange(0, d - 1-1) do ( execute ((Integer.subrange(0, n-1)->select(j | true)->collect(j | (weights[i + 1+1][j+1] - weights[i+1][j+1]))) : prices)) ; var bag : OclAny := x ; for i : Integer.subrange(0, d - 1-1) do ( var dp : Sequence := Integer.subrange(0, bag + 1-1)->select(i | true)->collect(i | (false)) ; dp->first() := 0 ; for j : Integer.subrange(0, n-1) do ( for k : Integer.subrange(0, bag-1) do ( if (weights[i+1][j+1] + k->compareTo(bag + 1)) < 0 & not(dp[k+1] <>= false) then ( dp[k + weights[i+1][j+1]+1] := Set{dp[k + weights[i+1][j+1]+1], dp[k+1] + prices[i+1][j+1]}->max() ) else skip)) ; bag := bag + (dp.subrange(1,bag + 1))->max()) ; execute (bag)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_pro(w,v): dp=[0]*(x+1) for a in range(n): wa=wlst[a] va=vlst[a] for b in range(wa,x+1): dp[b]=max(dp[b],dp[b-wa]+va) return dp[x] n,d,x=map(int,input().split()) plst=[list(map(int,input().split()))for _ in range(d)] for i in range(d-1): vlst=[plst[i+1][j]-plst[i][j]for j in range(n)] wlst=[plst[i][j]for j in range(n)] x+=get_pro(wlst,vlst) print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var d : OclAny := null; var x : OclAny := null; Sequence{n,d,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var plst : Sequence := Integer.subrange(0, d-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for i : Integer.subrange(0, d - 1-1) do ( var vlst : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (plst[i + 1+1][j+1] - plst[i+1][j+1])) ; var wlst : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (plst[i+1][j+1])) ; x := x + get_pro(wlst, vlst)) ; execute (x)->display(); operation get_pro(w : OclAny, v : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (x + 1)) ; for a : Integer.subrange(0, n-1) do ( var wa : OclAny := wlst[a+1] ; var va : OclAny := vlst[a+1] ; for b : Integer.subrange(wa, x + 1-1) do ( dp[b+1] := Set{dp[b+1], dp[b - wa+1] + va}->max())) ; return dp[x+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def calc(x,n,p1,p2): dp=[] for i in range(n): dp.append([0]*(x+1)) pocket=x for i in range(n): for j in range(x+1): dp[i][j]=dp[i-1][j] if j-p1[i]>=0 : dp[i][j]=max(dp[i][j],dp[i][j-p1[i]]+p2[i]) pocket=max(pocket,(x-j)+dp[i][j]) return pocket def main(): n,d,x=map(int,sys.stdin.readline().split()) pp=[] for i in range(d): pp.append(list(map(int,sys.stdin.readline().split()))) curr_x=x for i in range(d-1): curr_x=calc(curr_x,n,pp[i],pp[i+1]) print(curr_x) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation calc(x : OclAny, n : OclAny, p1 : OclAny, p2 : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((MatrixLib.elementwiseMult(Sequence{ 0 }, (x + 1))) : dp)) ; var pocket : OclAny := x ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, x + 1-1) do ( dp[i+1][j+1] := dp[i - 1+1][j+1] ; if j - p1[i+1] >= 0 then ( dp[i+1][j+1] := Set{dp[i+1][j+1], dp[i+1][j - p1[i+1]+1] + p2[i+1]}->max() ) else skip ; pocket := Set{pocket, (x - j) + dp[i+1][j+1]}->max())) ; return pocket; operation main() pre: true post: true activity: var d : OclAny := null; Sequence{n,d,x} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var pp : Sequence := Sequence{} ; for i : Integer.subrange(0, d-1) do ( execute ((((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) : pp)) ; var curr_x : OclAny := x ; for i : Integer.subrange(0, d - 1-1) do ( curr_x := calc(curr_x, n, pp[i+1], pp[i + 1+1])) ; execute (curr_x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n1,m,a,d=list(map(int,input().split())) t=list(map(int,input().split())) from bisect import insort from math import floor insort(t,a*n1) pred=0 k=0 kpred=0 n=0 step=d//a+1 sol=0 fl=0 for i in t : if(i>pred): if fl==0 : n=(i-pred+(pred % a))//a if n!=0 : k+=(n//step)*step-step*(n % step==0)+1 if k>n1 : k=n1 fl=1 if(k*a+d>=i)and(n!=0): pred=k*a+d else : pred=i+d k=floor(pred//a) sol+=1 k=min(floor(pred//a),n1) sol+=n//step+(n % step!=0) else : sol+=1 pred=i+d if i==a*n1 : fl=1 print(sol) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: var n1 : OclAny := null; var m : OclAny := null; var a : OclAny := null; var d : OclAny := null; Sequence{n1,m,a,d} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; skip ; insort(t, a * n1) ; var pred : int := 0 ; var k : int := 0 ; var kpred : int := 0 ; var n : int := 0 ; var step : int := d div a + 1 ; var sol : int := 0 ; var fl : int := 0 ; for i : t do ( if ((i->compareTo(pred)) > 0) then ( if fl = 0 then ( n := (i - pred + (pred mod a)) div a ; if n /= 0 then ( k := k + (n div step) * step - step * (n mod step = 0) + 1 ; if (k->compareTo(n1)) > 0 then ( k := n1 ; fl := 1 ) else skip ) else skip ; if ((k * a + d->compareTo(i)) >= 0) & (n /= 0) then ( pred := k * a + d ) else ( pred := i + d ; k := floor(pred div a) ; sol := sol + 1 ) ; k := Set{floor(pred div a), n1}->min() ; sol := sol + n div step + (n mod step /= 0) ) else ( sol := sol + 1 ; pred := i + d ) ) else skip ; if i = a * n1 then ( fl := 1 ) else skip) ; execute (sol)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import product D,G=map(int,input().split()) p,c=[0]*D,[0]*D for i in range(D): p[i],c[i]=list(map(int,input().split())) m=10*100*10 for a in product([True,False],repeat=D): g,n=G,0 for i in range(D): if a[i]: n+=p[i] g-=(c[i]+(i+1)*100*p[i]) if g<=0 and n<=m : m=n continue elif m(i+1)*100*(p[i]-1): continue n+=(g+(i+1)*100-1)//((i+1)*100) if ncollect( _x | (OclType["int"])->apply(_x) ) ; var p : OclAny := null; var c : OclAny := null; Sequence{p,c} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, D),MatrixLib.elementwiseMult(Sequence{ 0 }, D)} ; for i : Integer.subrange(0, D-1) do ( var p[i+1] : OclAny := null; var c[i+1] : OclAny := null; Sequence{p[i+1],c[i+1]} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var m : int := 10 * 100 * 10 ; for a : product(Sequence{true}->union(Sequence{ false }), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (name D)))))))) do ( var g : OclAny := null; var n : OclAny := null; Sequence{g,n} := Sequence{G,0} ; for i : Integer.subrange(0, D-1) do ( if a[i+1] then ( n := n + p[i+1] ; g := g - (c[i+1] + (i + 1) * 100 * p[i+1]) ) else skip) ; if g <= 0 & (n->compareTo(m)) <= 0 then ( m := n ; continue ) else (if (m->compareTo(n)) < 0 then ( continue ) else skip) ; for i : Integer.subrange(0, D-1) do ( if a[i+1] then ( continue ) else skip ; if (g->compareTo((i + 1) * 100 * (p[i+1] - 1))) > 0 then ( continue ) else skip ; n := n + (g + (i + 1) * 100 - 1) div ((i + 1) * 100) ; if (n->compareTo(m)) < 0 then ( m := n ) else skip)) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,D,X=map(int,input().split()) INF=10**5 dp=[0]*(INF+1) P=[tuple(map(int,input().split()))for _ in range(D)] for i in range(X+1): dp[i]=i ans=X for d in range(D-1): for i in range(ans+1): dp[i]=i tmp=ans for i in range(N): for j in range(P[d][i],ans+1): dp[j]=max(dp[j],dp[j-P[d][i]]+P[d+1][i]) tmp=max(tmp,dp[j]) ans=tmp print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var D : OclAny := null; var X : OclAny := null; Sequence{N,D,X} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var INF : double := (10)->pow(5) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (INF + 1)) ; var P : Sequence := Integer.subrange(0, D-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for i : Integer.subrange(0, X + 1-1) do ( dp[i+1] := i) ; var ans : OclAny := X ; for d : Integer.subrange(0, D - 1-1) do ( for i : Integer.subrange(0, ans + 1-1) do ( dp[i+1] := i) ; var tmp : OclAny := ans ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(P[d+1][i+1], ans + 1-1) do ( dp[j+1] := Set{dp[j+1], dp[j - P[d+1][i+1]+1] + P[d + 1+1][i+1]}->max() ; tmp := Set{tmp, dp[j+1]}->max())) ; ans := tmp) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(): n,d,x=map(int,sys.stdin.readline().split()) pp=[] for i in range(d): pp.append(list(map(int,sys.stdin.readline().split()))) dp=[0]*100001 curr_x=x for k in range(d-1): next_x=curr_x for i in range(curr_x+1): dp[i]=0 for i in range(n): for j in range(curr_x+1): if j-pp[k][i]>=0 : dp[j]=max(dp[j],dp[j-pp[k][i]]+pp[k+1][i]) next_x=max(next_x,(curr_x-j)+dp[j]) curr_x=next_x print(curr_x) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; var x : OclAny := null; Sequence{n,d,x} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var pp : Sequence := Sequence{} ; for i : Integer.subrange(0, d-1) do ( execute ((((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) : pp)) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100001) ; var curr_x : OclAny := x ; for k : Integer.subrange(0, d - 1-1) do ( var next_x : OclAny := curr_x ; for i : Integer.subrange(0, curr_x + 1-1) do ( dp[i+1] := 0) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, curr_x + 1-1) do ( if j - pp[k+1][i+1] >= 0 then ( dp[j+1] := Set{dp[j+1], dp[j - pp[k+1][i+1]+1] + pp[k + 1+1][i+1]}->max() ) else skip ; next_x := Set{next_x, (curr_x - j) + dp[j+1]}->max())) ; curr_x := next_x) ; execute (curr_x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) stones=[int(x)for x in input().split(" ",n)] total1=[0]*(len(stones)+1) for i in range(1,len(stones)+1): total1[i]=stones[i-1]+total1[i-1] total2=[0]*(len(stones)+1) stones.sort() for i in range(1,len(stones)+1): total2[i]=stones[i-1]+total2[i-1] m=int(input()) for i in range(m): x=[int(x)for x in input().split(" ",3)] if x[0]==1 : print(total1[x[2]]-total1[x[1]-1]) else : print(total2[x[2]]-total2[x[1]-1]) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var stones : Sequence := input().split(" ", n)->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var total1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((stones)->size() + 1)) ; for i : Integer.subrange(1, (stones)->size() + 1-1) do ( total1[i+1] := stones[i - 1+1] + total1[i - 1+1]) ; var total2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((stones)->size() + 1)) ; stones := stones->sort() ; for i : Integer.subrange(1, (stones)->size() + 1-1) do ( total2[i+1] := stones[i - 1+1] + total2[i - 1+1]) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, m-1) do ( var x : Sequence := input().split(" ", 3)->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if x->first() = 1 then ( execute (total1[x[2+1]+1] - total1[x[1+1] - 1+1])->display() ) else ( execute (total2[x[2+1]+1] - total2[x[1+1] - 1+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l1=list(map(int,input().split())) sum1=[0]*(n+1) for i in range(1,n+1): sum1[i]=sum1[i-1]+l1[i-1] l1=sorted(l1) sum2=[0]*(n+1) for i in range(1,n+1): sum2[i]=sum2[i-1]+l1[i-1] for i in range(int(input())): a,b,c=map(int,input().split()) print(sum1[c]-sum1[b-1]if a==1 else sum2[c]-sum2[b-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sum1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(1, n + 1-1) do ( sum1[i+1] := sum1[i - 1+1] + l1[i - 1+1]) ; l1 := l1->sort() ; var sum2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(1, n + 1-1) do ( sum2[i+1] := sum2[i - 1+1] + l1[i - 1+1]) ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if a = 1 then sum1[c+1] - sum1[b - 1+1] else sum2[c+1] - sum2[b - 1+1] endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) v=list(map(int,input().split())) m=int(input()) a=[v[0]] for i in range(1,n): a.append(a[-1]+v[i]) v.sort() b=[v[0]] for i in range(1,n): b.append(b[-1]+v[i]) for _ in range(0,m): type,l,r=list(map(int,input().split())) r-=1 l-=1 if type==1 : if l==0 : print(a[r]) else : print(a[r]-a[l-1]) else : if l==0 : print(b[r]) else : print(b[r]-b[l-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var v : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{ v->first() } ; for i : Integer.subrange(1, n-1) do ( execute ((a->last() + v[i+1]) : a)) ; v := v->sort() ; var b : Sequence := Sequence{ v->first() } ; for i : Integer.subrange(1, n-1) do ( execute ((b->last() + v[i+1]) : b)) ; for _anon : Integer.subrange(0, m-1) do ( var type : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{type,l,r} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; r := r - 1 ; l := l - 1 ; if type = 1 then ( if l = 0 then ( execute (a[r+1])->display() ) else ( execute (a[r+1] - a[l - 1+1])->display() ) ) else ( if l = 0 then ( execute (b[r+1])->display() ) else ( execute (b[r+1] - b[l - 1+1])->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=list(map(int,input().split())) z=s.copy() z.sort() q=int(input()) s2=[0] z2=[0] ii=0 aa=0 for i,a in zip(s,z): ii+=i aa+=a s2.append(ii); z2.append(aa) for i in range(q): m,l,r=map(int,input().split()) if m==1 : print(s2[r]-s2[l-1]) else : print(z2[r]-z2[l-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var z : OclAny := s->copy() ; z := z->sort() ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s2 : Sequence := Sequence{ 0 } ; var z2 : Sequence := Sequence{ 0 } ; var ii : int := 0 ; var aa : int := 0 ; for _tuple : Integer.subrange(1, s->size())->collect( _indx | Sequence{s->at(_indx), z->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); ii := ii + i ; aa := aa + a ; execute ((ii) : s2); execute ((aa) : z2)) ; for i : Integer.subrange(0, q-1) do ( var m : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{m,l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if m = 1 then ( execute (s2[r+1] - s2[l - 1+1])->display() ) else ( execute (z2[r+1] - z2[l - 1+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() pedras=list(map(int,input().split())) soma=0 acumulacao_natural=[] for pedra in pedras : soma+=pedra acumulacao_natural.append(soma) pedras.sort() soma=0 acumulacao_ordenada=[] for pedra in pedras : soma+=pedra acumulacao_ordenada.append(soma) for _ in range(int(input())): opcao,inicio,fim=map(int,input().split()) if opcao==1 : if inicio>1 : resultado=acumulacao_natural[fim-1]-acumulacao_natural[inicio-2] else : resultado=acumulacao_natural[fim-1] else : if inicio>1 : resultado=acumulacao_ordenada[fim-1]-acumulacao_ordenada[inicio-2] else : resultado=acumulacao_ordenada[fim-1] print(resultado) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var pedras : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var soma : int := 0 ; var acumulacao_natural : Sequence := Sequence{} ; for pedra : pedras do ( soma := soma + pedra ; execute ((soma) : acumulacao_natural)) ; pedras := pedras->sort() ; soma := 0 ; var acumulacao_ordenada : Sequence := Sequence{} ; for pedra : pedras do ( soma := soma + pedra ; execute ((soma) : acumulacao_ordenada)) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var opcao : OclAny := null; var inicio : OclAny := null; var fim : OclAny := null; Sequence{opcao,inicio,fim} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if opcao = 1 then ( if inicio > 1 then ( var resultado : double := acumulacao_natural[fim - 1+1] - acumulacao_natural[inicio - 2+1] ) else ( resultado := acumulacao_natural[fim - 1+1] ) ) else ( if inicio > 1 then ( resultado := acumulacao_ordenada[fim - 1+1] - acumulacao_ordenada[inicio - 2+1] ) else ( resultado := acumulacao_ordenada[fim - 1+1] ) ) ; execute (resultado)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMinimumX(a,n): st=set() for i in range(n): st.add(a[i]) if(len(st)==1): return 0 if(len(st)==2): st=list(st) el1=st[0] el2=st[1] if((el2-el1)% 2==0): return int((el2-el1)/2) else : return(el2-el1) if(len(st)==3): st=list(st) el1=st[0] el2=st[1] el3=st[2] if((el2-el1)==(el3-el2)): return el2-el1 else : return-1 return-1 if __name__=='__main__' : a=[1,4,4,7,4,1] n=len(a) print(findMinimumX(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := Sequence{1}->union(Sequence{4}->union(Sequence{4}->union(Sequence{7}->union(Sequence{4}->union(Sequence{ 1 }))))) ; n := (a)->size() ; execute (findMinimumX(a, n))->display() ) else skip; operation findMinimumX(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var st : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( execute ((a[i+1]) : st)) ; if ((st)->size() = 1) then ( return 0 ) else skip ; if ((st)->size() = 2) then ( st := (st) ; var el1 : OclAny := st->first() ; var el2 : OclAny := st[1+1] ; if ((el2 - el1) mod 2 = 0) then ( return ("" + (((el2 - el1) / 2)))->toInteger() ) else ( return (el2 - el1) ) ) else skip ; if ((st)->size() = 3) then ( st := (st) ; el1 := st->first() ; el2 := st[1+1] ; var el3 : OclAny := st[2+1] ; if ((el2 - el1) = (el3 - el2)) then ( return el2 - el1 ) else ( return -1 ) ) else skip ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def findX(n,k): r=n m=int(math.sqrt(k))+1 i=2 while i<=m and k>1 : if(i==m): i=k u=0 v=0 while k % i==0 : k//=i v+=1 if(v>0): t=n while(t>0): t//=i u+=t r=min(r,u//v) i+=1 return r if __name__=="__main__" : n=5 k=2 print(findX(n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 5 ; k := 2 ; execute (findX(n, k))->display() ) else skip; operation findX(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var r : OclAny := n ; var m : int := ("" + (((k)->sqrt())))->toInteger() + 1 ; var i : int := 2 ; while (i->compareTo(m)) <= 0 & k > 1 do ( if (i = m) then ( i := k ) else skip ; var u : int := 0 ; var v : int := 0 ; while k mod i = 0 do ( k := k div i ; v := v + 1) ; if (v > 0) then ( var t : OclAny := n ; while (t > 0) do ( t := t div i ; u := u + t) ; r := Set{r, u div v}->min() ) else skip ; i := i + 1) ; return r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def inside(x,y,xl,yd,xr,yu): return xl<=x and x<=xr and yd<=y and y<=yu def judge(xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2): if inside(xb1,yb1,xa1,ya1,xa2,ya2): return True if inside(xb2,yb1,xa1,ya1,xa2,ya2): return True if inside(xb2,yb2,xa1,ya1,xa2,ya2): return True if inside(xb1,yb2,xa1,ya1,xa2,ya2): return True if inside(xa1,ya1,xb1,yb1,xb2,yb2): return True if inside(xa2,ya1,xb1,yb1,xb2,yb2): return True if inside(xa2,ya2,xb1,yb1,xb2,yb2): return True if inside(xa1,ya2,xb1,yb1,xb2,yb2): return True if xb1<=xa1 and xa1<=xb2 and xb1<=xa2 and xa2<=xb2 and ya1<=yb1 and ya2>=yb2 : return True if xa1<=xb1 and xb1<=xa2 and xa1<=xb2 and xb2<=xa2 and yb1<=ya1 and yb2>=ya2 : return True return False while True : try : xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2=list(map(float,input().split())) except : break if xa1>xa2 : xa1,xa2=xa2,xa1 if ya1>ya2 : ya1,ya2=ya2,ya1 if xb1>xb2 : xb1,xb2=xb2,xb1 if yb1>yb2 : yb1,yb2=yb2,yb1 print("YES" if judge(xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2)else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( try ( Sequence{xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2} := ((input().split())->collect( _x | (OclType["double"])->apply(_x) ))) catch (_e : OclException) do ( break) ; if (xa1->compareTo(xa2)) > 0 then ( Sequence{xa1,xa2} := Sequence{xa2,xa1} ) else skip ; if (ya1->compareTo(ya2)) > 0 then ( Sequence{ya1,ya2} := Sequence{ya2,ya1} ) else skip ; if (xb1->compareTo(xb2)) > 0 then ( Sequence{xb1,xb2} := Sequence{xb2,xb1} ) else skip ; if (yb1->compareTo(yb2)) > 0 then ( Sequence{yb1,yb2} := Sequence{yb2,yb1} ) else skip ; execute (if judge(xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2) then "YES" else "NO" endif)->display()); operation inside(x : OclAny, y : OclAny, xl : OclAny, yd : OclAny, xr : OclAny, yu : OclAny) : OclAny pre: true post: true activity: return (xl->compareTo(x)) <= 0 & (x->compareTo(xr)) <= 0 & (yd->compareTo(y)) <= 0 & (y->compareTo(yu)) <= 0; operation judge(xa1 : OclAny, ya1 : OclAny, xa2 : OclAny, ya2 : OclAny, xb1 : OclAny, yb1 : OclAny, xb2 : OclAny, yb2 : OclAny) : OclAny pre: true post: true activity: if inside(xb1, yb1, xa1, ya1, xa2, ya2) then ( return true ) else skip ; if inside(xb2, yb1, xa1, ya1, xa2, ya2) then ( return true ) else skip ; if inside(xb2, yb2, xa1, ya1, xa2, ya2) then ( return true ) else skip ; if inside(xb1, yb2, xa1, ya1, xa2, ya2) then ( return true ) else skip ; if inside(xa1, ya1, xb1, yb1, xb2, yb2) then ( return true ) else skip ; if inside(xa2, ya1, xb1, yb1, xb2, yb2) then ( return true ) else skip ; if inside(xa2, ya2, xb1, yb1, xb2, yb2) then ( return true ) else skip ; if inside(xa1, ya2, xb1, yb1, xb2, yb2) then ( return true ) else skip ; if (xb1->compareTo(xa1)) <= 0 & (xa1->compareTo(xb2)) <= 0 & (xb1->compareTo(xa2)) <= 0 & (xa2->compareTo(xb2)) <= 0 & (ya1->compareTo(yb1)) <= 0 & (ya2->compareTo(yb2)) >= 0 then ( return true ) else skip ; if (xa1->compareTo(xb1)) <= 0 & (xb1->compareTo(xa2)) <= 0 & (xa1->compareTo(xb2)) <= 0 & (xb2->compareTo(xa2)) <= 0 & (yb1->compareTo(ya1)) <= 0 & (yb2->compareTo(ya2)) >= 0 then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**9) N,M,Q=map(int,input().split()) abcds=[] for _ in range(Q): a,b,c,d=map(int,input().split()) a,b=a-1,b-1 abcds.append((a,b,c,d)) def check(): score=0 for a,b,c,d in abcds : if As[b]-As[a]==c : score+=d return score def dfs(i,mx): if i==N : return check() score=0 for x in range(mx,M+1): As[i]=x s=dfs(i+1,x) if s>score : score=s return score As=[0]*N ans=dfs(0,1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(9)) ; var N : OclAny := null; var M : OclAny := null; var Q : OclAny := null; Sequence{N,M,Q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var abcds : Sequence := Sequence{} ; for _anon : Integer.subrange(0, Q-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{a - 1,b - 1} ; execute ((Sequence{a, b, c, d}) : abcds)) ; skip ; skip ; var As : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var ans : OclAny := dfs(0, 1) ; execute (ans)->display(); operation check() : OclAny pre: true post: true activity: var score : int := 0 ; for _tuple : abcds do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); if As[b+1] - As[a+1] = c then ( score := score + d ) else skip) ; return score; operation dfs(i : OclAny, mx : OclAny) : OclAny pre: true post: true activity: if i = N then ( return check() ) else skip ; score := 0 ; for x : Integer.subrange(mx, M + 1-1) do ( As[i+1] := x ; var s : OclAny := dfs(i + 1, x) ; if (s->compareTo(score)) > 0 then ( score := s ) else skip) ; return score; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dfs(problems : "scores",now_depth : int,g : int)->int : if now_depth==0 : return 10**9 solve_count=min(g//(100*now_depth),problems[now_depth][0]) score=100*now_depth*solve_count if solve_count==problems[now_depth][0]: score+=problems[now_depth][1] if scoreselect(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var problems : Sequence := Sequence{ 0 }->union(Integer.subrange(0, depth-1)->select(_anon | true)->collect(_anon | (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))))) ; execute (dfs(problems, depth, g))->display(); operation dfs(problems : "scores", now_depth : int, g : int) : int pre: true post: true activity: if now_depth = 0 then ( return (10)->pow(9) ) else skip ; var solve_count : OclAny := Set{g div (100 * now_depth), problems[now_depth+1]->first()}->min() ; var score : double := 100 * now_depth * solve_count ; if solve_count = problems[now_depth+1]->first() then ( score := score + problems[now_depth+1][1+1] ) else skip ; if (score->compareTo(g)) < 0 then ( solve_count := solve_count + dfs(problems, now_depth - 1, g - score) ) else skip ; return Set{solve_count, dfs(problems, now_depth - 1, g)}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(N : int,M : int,Q : int,a : "List[int]",b : "List[int]",c : "List[int]",d : "List[int]"): res=0 def rec(A): nonlocal res if len(A)==N : ans=0 for i in range(Q): if A[b[i]-1]-A[a[i]-1]==c[i]: ans+=d[i] res=max(res,ans) return last_max=1 if len(A)==0 else A[-1] for i in range(last_max,M+1): rec(A+[i]) rec([]) print(res) return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() N=int(next(tokens)) M=int(next(tokens)) Q=int(next(tokens)) a=[int()]*(Q) b=[int()]*(Q) c=[int()]*(Q) d=[int()]*(Q) for i in range(Q): a[i]=int(next(tokens)) b[i]=int(next(tokens)) c[i]=int(next(tokens)) d[i]=int(next(tokens)) solve(N,M,Q,a,b,c,d) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute res : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(N : int, M : int, Q : int, a : "List[int]", b : "List[int]", c : "List[int]", d : "List[int]") pre: true post: true activity: var res : int := 0 ; skip ; rec(Sequence{}) ; execute (res)->display() ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var N : int := ("" + (((tokens).next())))->toInteger() ; var M : int := ("" + (((tokens).next())))->toInteger() ; var Q : int := ("" + (((tokens).next())))->toInteger() ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (()))->toInteger() }, (Q)) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (()))->toInteger() }, (Q)) ; var c : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (()))->toInteger() }, (Q)) ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (()))->toInteger() }, (Q)) ; for i : Integer.subrange(0, Q-1) do ( a[i+1] := ("" + (((tokens).next())))->toInteger() ; b[i+1] := ("" + (((tokens).next())))->toInteger() ; c[i+1] := ("" + (((tokens).next())))->toInteger() ; d[i+1] := ("" + (((tokens).next())))->toInteger()) ; solve(N, M, Q, a, b, c, d); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools s1=input() N=int(s1.split()[0]) M=int(s1.split()[1]) Q=int(s1.split()[2]) a=[] b=[] c=[] d=[] s=[input()for i in range(Q)] for k in range(Q): a.append(int(s[k].split()[0])) b.append(int(s[k].split()[1])) c.append(int(s[k].split()[2])) d.append(int(s[k].split()[3])) result=0 suretu=[] for i in range(M): suretu.append(i+1) for A in list(itertools.combinations_with_replacement(suretu,N)): A=list(A) subresult=0 for i in range(Q): if A[b[i]-1]-A[a[i]-1]==c[i]: subresult+=d[i] if resultfirst())))->toInteger() ; var M : int := ("" + ((s1.split()[1+1])))->toInteger() ; var Q : int := ("" + ((s1.split()[2+1])))->toInteger() ; var a : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; var c : Sequence := Sequence{} ; var d : Sequence := Sequence{} ; var s : Sequence := Integer.subrange(0, Q-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; for k : Integer.subrange(0, Q-1) do ( execute ((("" + ((s[k+1].split()->first())))->toInteger()) : a) ; execute ((("" + ((s[k+1].split()[1+1])))->toInteger()) : b) ; execute ((("" + ((s[k+1].split()[2+1])))->toInteger()) : c) ; execute ((("" + ((s[k+1].split()[3+1])))->toInteger()) : d)) ; var result : int := 0 ; var suretu : Sequence := Sequence{} ; for i : Integer.subrange(0, M-1) do ( execute ((i + 1) : suretu)) ; for A : (itertools.combinations_with_replacement(suretu, N)) do ( var A : Sequence := (A) ; var subresult : int := 0 ; for i : Integer.subrange(0, Q-1) do ( if A[b[i+1] - 1+1] - A[a[i+1] - 1+1] = c[i+1] then ( subresult := subresult + d[i+1] ) else skip) ; if (result->compareTo(subresult)) < 0 then ( result := subresult ) else skip) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import itertools input=lambda : sys.stdin.readline().rstrip() def main(): n,m,q=map(int,input().split()) comb=[list(map(int,input().split()))for _ in range(q)] max_=0 for i in itertools.combinations_with_replacement(range(1,m+1),n): point=0 for j in comb : if i[j[1]-1]-i[j[0]-1]==j[2]: point+=j[3] max_=max(max_,point) print(max_) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var q : OclAny := null; Sequence{n,m,q} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var comb : Sequence := Integer.subrange(0, q-1)->select(_anon | true)->collect(_anon | (((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var max_ : int := 0 ; for i : itertools.combinations_with_replacement(Integer.subrange(1, m + 1-1), n) do ( var point : int := 0 ; for j : comb do ( if i[j[1+1] - 1+1] - i[j->first() - 1+1] = j[2+1] then ( point := point + j[3+1] ) else skip) ; max_ := Set{max_, point}->max()) ; execute (max_)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(100000000) def main(): n,m,q=map(int,input().split()) all_qlist=[] for i in range(q): _qlist=list(map(int,input().split())) all_qlist.append(_qlist) max=sum([x[3]for x in all_qlist]) all_list=[] _list=[] for i in range(1,m+1): tmp_list=[] all_list.append(tmp_list) tmp_list.append(i) for _ in range(n-1): tmp_all_list=[] for _list_sub in all_list : x=_list_sub[-1] for i in range(x,m+1): tmp_list=_list_sub.copy() tmp_all_list.append(tmp_list) tmp_list.append(i) all_list=tmp_all_list total_max=0 for _list in all_list : total=0 for _qlist in all_qlist : if _list[_qlist[1]-1]-_list[_qlist[0]-1]==_qlist[2]: total+=_qlist[3] if total>total_max : total_max=total if total_max==max : break print(total_max) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(100000000) ; skip ; main(); operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var q : OclAny := null; Sequence{n,m,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var all_qlist : Sequence := Sequence{} ; for i : Integer.subrange(0, q-1) do ( var _qlist : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((_qlist) : all_qlist)) ; var max : OclAny := (all_qlist->select(x | true)->collect(x | (x[3+1])))->sum() ; var all_list : Sequence := Sequence{} ; var _list : Sequence := Sequence{} ; for i : Integer.subrange(1, m + 1-1) do ( var tmp_list : Sequence := Sequence{} ; execute ((tmp_list) : all_list) ; execute ((i) : tmp_list)) ; for _anon : Integer.subrange(0, n - 1-1) do ( var tmp_all_list : Sequence := Sequence{} ; for _list_sub : all_list do ( var x : OclAny := _list_sub->last() ; for i : Integer.subrange(x, m + 1-1) do ( tmp_list := _list_sub->copy() ; execute ((tmp_list) : tmp_all_list) ; execute ((i) : tmp_list))) ; all_list := tmp_all_list) ; var total_max : int := 0 ; for _list : all_list do ( var total : int := 0 ; for _qlist : all_qlist do ( if _list[_qlist[1+1] - 1+1] - _list[_qlist->first() - 1+1] = _qlist[2+1] then ( total := total + _qlist[3+1] ) else skip) ; if (total->compareTo(total_max)) > 0 then ( total_max := total ) else skip ; if total_max = max then ( break ) else skip) ; execute (total_max)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def main(): n,m=list(map(int,input().split(" "))) paired_dict={i :[]for i in range(n)} for _ in range(m): a,b=list(map(int,input().split(" "))) paired_dict[a-1].append(b-1) paired_dict[b-1].append(a-1) done_set=set([]) que=deque([a-1]) i=0 ans=0 while que : x=que.popleft() done_set.add(x) if x in paired_dict.keys(): for one in paired_dict[x]: if one in done_set : continue que.append(one) done_set.add(one) while(not que)and len(done_set)!=n : if i not in done_set : que.append(i) ans+=1 i+=1 if ncollect( _x | (OclType["int"])->apply(_x) )) ; var paired_dict : Map := Integer.subrange(0, n-1)->select(i | true)->collect(i | Map{i |-> Sequence{}})->unionAll() ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; (expr (atom (name paired_dict)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name paired_dict)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ))))) ; var done_set : Set := Set{}->union((Sequence{})) ; var que : Sequence := (Sequence{ a - 1 }) ; var i : int := 0 ; var ans : int := 0 ; while que do ( var x : OclAny := que->first() ; que := que->tail() ; execute ((x) : done_set) ; if (paired_dict.keys())->includes(x) then ( for one : paired_dict[x+1] do ( if (done_set)->includes(one) then ( continue ) else skip ; execute ((one) : que) ; execute ((one) : done_set)) ) else skip ; while (not(que)) & (done_set)->size() /= n do ( if (done_set)->excludes(i) then ( execute ((i) : que) ; ans := ans + 1 ) else skip ; i := i + 1 ; if (n->compareTo(i)) < 0 then ( i := 0 ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import base64 import subprocess import zlib exe_bin="c%0>1eRxweP0Zcd`^{lEe&#N%JlvQ^u}?2{9&bZ74=stFDGex8D;%&V*|sb4g2QJo_ZbId1gvQpXQE7lNs>~FoI%~ce`>-EOWSI?Z1HqU$MrR~J<*CGhJ?;6e%fp%VCeCGb!Q{MHiq2Cg_hgJUB_eH9KP)D^0gq=DU<=y)iEu!OCB%5h-{ox++G+*Q>O}%ko$nG>wSz(^B!r`h5VX!84TAf2f5aaRgxXudKz&{$8ViO5Fc(@~E38^ATUZbXM@f6c`fw~kuGV>@VX@ii*-QkSHwl8+8INs&YeB&uiNpeUAsA`htkH8WOl*w?ge_sQ6H*ln$2{$rxt<=OI}}gEqW(x&+$wCY1-0mwu3}D`nA5sIEGf$F3(XIP0`X8+C@PkS3VUs1ARr{L)0~{JCb}gI*;o}yB)iDP0P9WY$iOBc(78$I@P{J+_!A^~lneCu1-}^T35%5J2xH^7K_3ceh89AXA5yoxsYzJisO6UXyp2u5d`DgWY`$Y5*R*!6yU{B+9SdZ5?OG77<8ao)e+K&3KzSql%IMw2KnhXDb@1;wU12=5&e~dmGIR6uubz90Uay5;RX98mXVe9H8B1Or9*;BYQiZ&ZE6n$A{&Z6r-a)-oUYz}~34OEs5}WtgeeC39nbv6V{q*^uR)g=Q@+O-aXZ*+vnX=~wcAQY)Rt0`ifh)&*MuA_cz(*B$l>$Gfz$YtkD{U9%$gIHG{DF@HQxrIxKM=o4iBtRKT;U#xN2dZ;-mJP6xIuyUC~)O-POk!2-sg8H@Nxw{sK8AMe2)SjufX>z@Cgchp8~H?;QJMLr2;>oz$Ys3g9_ZDz>h2NNeZ0r``E;%$~=>896xYS)aOR{zQd+rF1PTpDjS!Z`8fQw%xHi!azz4|98k^%Cq|kzYTdT#q3_f$C1a>X9o#?5AvAuY%k&4k;mp{y9s|M@|fc62EwmG9#flbCH$?(V@k6Pgl|M1Q<<$L{9@!Wg;^Wn=Od4)%UTIP2l$RbmKXOO?%SO?_ZoNGn$`SwK0X0ZkWU$B)?m)0e*1Bt&V!jU(B#viy_HWd-HJIpR(AUoIn%!Mv-Uwk@3U{nT)Hd^w(-)j%xB01K+Btcz~qxI@W=Y?dsv6S`Ci5OKE?Td#rXln`9XRv$sUh2+ewNtH$gi1fDH2Khs(7q<%%ZvfQ20^_|OE2Bw07>veI7FD18(4;=CZ{)Z=0RZpN&OS+PCr<_eo>h|0>$udw0)zEiT=aWXH*WHp+sx0pt*16W%+bp}jL>JNrKIyZ}8(%|mq)#zV$KW*8Y+svhMY3+-4XF(nJ}3F?>nuA~LNTS};H2YUjkr!XSROw%l$p`cf6UT9A1=B+x1{F)*xbD0|$HTzQFOuRMqaj3lQ5AP{`6Dw{!({0H$`HCtWykeg!6T;V&__>80-idEu`>A~OdXTgVp}eA6|0|1bH#@n$gUCRQhdRkx&*hO&pjmSqOKlt5gqE$NLW=#@^nJDcs@tY3G~e)UN~dyh|g+TKenTXucQmoG%rzck|LwX|1hg;FILF*|l()wcnfaSf9tyjkCfOuXMznT4Qs)dEbX{q1yQ}pvjN=U$zV!#^n6!zFJ=TD#L@(v`6QHkRDh`o5%MZ(YcOVb_bz}*%wLFy`(e-J`sP>;(Grj^kErzl|=blAJpW-7a`4ka_~B8?!lj>WB@XL+G^v{-MP%1OIRnzWcie6@AgT#Ovr?GzRFB2$KlDR9w!4e$S;^iMy_SxL#&7I9LDi{*LwFl_j>o;Zeh4%(6=OF@3HjX1I>gY=OMcfW4iUyaP}V{Oqe^CthZrBX6>Lk=yO3Awn*99p?D`gI@at60ELA><#UUNfddM)a?3zv^n@j|uax0;7F}CM1Hshnx(5au}b!;=re}a7w7->#Td(_=`F_#Q9qR^r2HncZtNxynYws!=}Eikf-$yI{fZZ`Vi#!=Ixb>JZ?Xc|2D#de!H1co=OWGS%@_0Os%GiJy9W>RkQH+F5UQjt{-dFGpL1o_7X*~0?XOt{>_Ko%2ceya>@zQXn%OKBtc!%Mo-(;qL1-JjqS)3t^|Lh5AM0mCQ~+P8})Szo7OHO|+56!_0mnz0_F&e0uU?LKZ$vt{ygJ8{ullpz{;2^!nYr^uK)H??+qPeCe|98qmtbD+yWp6OhVHetUwA`$E1?rI+f!&>B8nb{;_9b&i+b7pKCb=#MAJkD?RT=S~*dvwj$#LRIY>nm`)z!UQxk`!eYBLzfM_G|CTUZsB!D`PVOtP%>rrQiGLfu#~;trLR}Qb6fI8zHjLaPymzAo=OP&R^T%4ehK;HA%vr4KLR-&s+0TJnc)r+4~nnP;*D752hQS?W6%1Og_pi|ef~fjpL)>52j1g{ey8WtRWryPIXV6=X%y~4aQ}hl1*dE1fqA~bNhqIxf&NWa!mU{^jpA);c#wxDqkT9-rPg5a|B%=H>eO!_y-(}Obmb;w=}J9&8hQK+<@IdLH>nU{@ZD9jsIX5&`7rLVoxS>NpU$-CLm*M`g;r->!e=6omrJT6`ENoSj-&)m7HU-R%B&AZ-BeuM*3@mMohsDLxW^j(j<-HknP{h~=|ibbQLfG9MD#c(L$2y}OIwYHm=+InoWX2GAEZBc>BYhgSi*j7B-suU$hI4auKM8mP@vT!uGcyT-y6KepQ&8}~bg@a0gWHc;>P~rv~5z}2`Sb}Tu_(IqHc`k?3*#<}pKFD5UU1qMn)l#v=)XUv+^^!RY?AJ4W{5H`GF)7y%a77DW(++??(u2)r>rTDfT)o}kHrx7)?Gwz^O=fGO+0;~V7o5Avd1D3o{2u(Q5c?d|gA09nkTCfw+-4K`Ui2*dY;b*=PQJb!?e-a#n``weWm6!ztfEJ8t`Fpy+bV7VwR7;h1U43eQV-TFpz^)5rR*_Jjonrn8Jxy`lP$GOe*edWu|gL=b=VS>3HFt@p;(QE_RMw$?s*T=zjJ=~HV==?Ub^=^nCbNwvfz0md$r}E>;`{B_KkA7Or4e??=$lBQ@u(J>BDA${EIo-5bOE~VZZq}=lxbu4J@k!i!Wh1($CUGxL`lb(R|IZJ${>j!m+4`pPd!&*+r&IH9(G#{twudgRv9+=OYMIi{d-?U(YbejwLa(Njt+%q;Wn=Tp%efe_Pdh!|rSycY86Kq9*&5#l%CogS+8osyDIRQ%lBer+thQQdd~Cj9YmjVhlpn9gttNH5>#06li)8+<<N&U!~}-E0~CV{99s*XoOWsWm9RJE(C3CleODR*g@{*S8w4$d7Y1Udin*icjSB7U@3&XXf@7#Vz@HLycRxy+!d!`TYZG{0eSgQT$3Sb4@Y4DnCD|@yYplNsUh_IxY+_JFs~~jYH#Y#qh%STs4067!0QqBlmeui_3cntoezSh22PT8wHpbT>ipk6K`Ph29jo2Am4{b!gYE1h>6xX)1hu9fgKf6loH+WZv`!~#7Fa3x&hvJ`+Z>ZH=wWh9S8?gq)*5O&Qub?o#*nOm|#D0dkCGa~->?e7UL;1pZKTGGE%_Z!-2>2v@^_Y447bWC>R|3Bb_;p~1eFtUJ+~hKpA3M)nZIJUhLT~VkDSnTkxc&YT_&lQ=FWYCv-d*;TkpI^bc%}p%BlgG6!$zZ=H*LRLjm7tk{IyZ86Ky?gAoVkq>%Cr$*BND8Yrnx*Vjm98gO%nvMDb(^`A16N&lrpElX{BMnNKkldFVj7LNqD*d2FKrLItzJ`BeE*EIthoKwvf|^ey{vdU@1^pibiV4R`1TU=drSB&zE~jKdFKjO{w=-^-|{_SkJBXxt*bn3ZQmA_ty$63=3Ti0xBRGN7m^o#Pq?J?a^K2Ew@(lf$#%gjZxq4JEWUa{2*<*p%mw0NLQHmaI09T@Cy^j_2?5+Ol;8v*7!x)|V(tEj5ENtagy2v1aDiA?cO)c+f{vROx$27x;ck_%;E%`sTZK?mjBn*S;{L9X5KMM;Z3PttCty=lqJpq&mAl0wcvduH9K!MyYXlEZLB4qvCp3S1g}cSu1lLr`K{Y^j$mH{|a@n%go;IP)-RSfD1vV}W2?f_Asg2(R_y^9_nzE*ouYWvP65s;nku`@CKn6K)@UJKm?IcB7tXq_~WS;T7*y>GULG>TA=D7xUSkfrOgIz8Pg^^x}{4C{YiViv`J9!>?*VXueG%_vASkk%*G@d>W0;>(4I)J^Wt08wAy5ESRj!k1EJ{Fw}uAAjc&cabJ+08kkF)`$T{LT~o8!5Ljnsl@$!;#>;aF8Qhr$5ojIf7fGU{9uET)wgyItv=DVg$Gr4@LYaNYA<>BD#b=##6_}7@R=G!(Wn8M?6O6A4jN@PPU!Fc!2}!fq)R|352>uK_u}z3Nxo{gPns=x^x1j=qYaeeI+;$P&mMno=hS=H^NuLppjm&==I?G!UZY}SZ2f^zwvfWi>NRu|C$D)io~=_b+RGK%Z{Wtpzm1b~%JkWK2BT~pPMbd#e?Qf4q&!>qV6;`Ce^n9vU7T_+e_cpM^6{dnLc~Zt)}|g{%g?am+NHz+67;xKU;$r`#w_aKkM*Re+O;wH0nb;e~eeOU3rYqiT{XZomX2wlS=4+pDyfKH40k&{{yGp2ZR" open("./kyomu",'wb').write(zlib.decompress(base64.b85decode(exe_bin))) subprocess.run(["chmod+x./kyomu"],shell=True) subprocess.run(["./kyomu"],shell=True) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var exe_bin : String := "c%0>1eRxweP0Zcd`^{lEe&#N%JlvQ^u}?2{9&bZ74=stFDGex8D;%&V*|sb4g2QJo_ZbId1gvQpXQE7lNs>~FoI%~ce`>-EOWSI?Z1HqU$MrR~J<*CGhJ?;6e%fp%VCeCGb!Q{MHiq2Cg_hgJUB_eH9KP)D^0gq=DU<=y)iEu!OCB%5h-{ox++G+*Q>O}%ko$nG>wSz(^B!r`h5VX!84TAf2f5aaRgxXudKz&{$8ViO5Fc(@~E38^ATUZbXM@f6c`fw~kuGV>@VX@ii*-QkSHwl8+8INs&YeB&uiNpeUAsA`htkH8WOl*w?ge_sQ6H*ln$2{$rxt<=OI}}gEqW(x&+$wCY1-0mwu3}D`nA5sIEGf$F3(XIP0`X8+C@PkS3VUs1ARr{L)0~{JCb}gI*;o}yB)iDP0P9WY$iOBc(78$I@P{J+_!A^~lneCu1-}^T35%5J2xH^7K_3ceh89AXA5yoxsYzJisO6UXyp2u5d`DgWY`$Y5*R*!6yU{B+9SdZ5?OG77<8ao)e+K&3KzSql%IMw2KnhXDb@1;wU12=5&e~dmGIR6uubz90Uay5;RX98mXVe9H8B1Or9*;BYQiZ&ZE6n$A{&Z6r-a)-oUYz}~34OEs5}WtgeeC39nbv6V{q*^uR)g=Q@+O-aXZ*+vnX=~wcAQY)Rt0`ifh)&*MuA_cz(*B$l>$Gfz$YtkD{U9%$gIHG{DF@HQxrIxKM=o4iBtRKT;U#xN2dZ;-mJP6xIuyUC~)O-POk!2-sg8H@Nxw{sK8AMe2)SjufX>z@Cgchp8~H?;QJMLr2;>oz$Ys3g9_ZDz>h2NNeZ0r``E;%$~=>896xYS)aOR{zQd+rF1PTpDjS!Z`8fQw%xHi!azz4|98k^%Cq|kzYTdT#q3_f$C1a>X9o#?5AvAuY%k&4k;mp{y9s|M@|fc62EwmG9#flbCH$?(V@k6Pgl|M1Q<<$L{9@!Wg;^Wn=Od4)%UTIP2l$RbmKXOO?%SO?_ZoNGn$`SwK0X0ZkWU$B)?m)0e*1Bt&V!jU(B#viy_HWd-HJIpR(AUoIn%!Mv-Uwk@3U{nT)Hd^w(-)j%xB01K+Btcz~qxI@W=Y?dsv6S`Ci5OKE?Td#rXln`9XRv$sUh2+ewNtH$gi1fDH2Khs(7q<%%ZvfQ20^_|OE2Bw07>veI7FD18(4;=CZ{)Z=0RZpN&OS+PCr<_eo>h|0>$udw0)zEiT=aWXH*WHp+sx0pt*16W%+bp}jL>JNrKIyZ}8(%|mq)#zV$KW*8Y+svhMY3+-4XF(nJ}3F?>nuA~LNTS};H2YUjkr!XSROw%l$p`cf6UT9A1=B+x1{F)*xbD0|$HTzQFOuRMqaj3lQ5AP{`6Dw{!({0H$`HCtWykeg!6T;V&__>80-idEu`>A~OdXTgVp}eA6|0|1bH#@n$gUCRQhdRkx&*hO&pjmSqOKlt5gqE$NLW=#@^nJDcs@tY3G~e)UN~dyh|g+TKenTXucQmoG%rzck|LwX|1hg;FILF*|l()wcnfaSf9tyjkCfOuXMznT4Qs)dEbX{q1yQ}pvjN=U$zV!#^n6!zFJ=TD#L@(v`6QHkRDh`o5%MZ(YcOVb_bz}*%wLFy`(e-J`sP>;(Grj^kErzl|=blAJpW-7a`4ka_~B8?!lj>WB@XL+G^v{-MP%1OIRnzWcie6@AgT#Ovr?GzRFB2$KlDR9w!4e$S;^iMy_SxL#&7I9LDi{*LwFl_j>o;Zeh4%(6=OF@3HjX1I>gY=OMcfW4iUyaP}V{Oqe^CthZrBX6>Lk=yO3Awn*99p?D`gI@at60ELA><#UUNfddM)a?3zv^n@j|uax0;7F}CM1Hshnx(5au}b!;=re}a7w7->#Td(_=`F_#Q9qR^r2HncZtNxynYws!=}Eikf-$yI{fZZ`Vi#!=Ixb>JZ?Xc|2D#de!H1co=OWGS%@_0Os%GiJy9W>RkQH+F5UQjt{-dFGpL1o_7X*~0?XOt{>_Ko%2ceya>@zQXn%OKBtc!%Mo-(;qL1-JjqS)3t^|Lh5AM0mCQ~+P8})Szo7OHO|+56!_0mnz0_F&e0uU?LKZ$vt{ygJ8{ullpz{;2^!nYr^uK)H??+qPeCe|98qmtbD+yWp6OhVHetUwA`$E1?rI+f!&>B8nb{;_9b&i+b7pKCb=#MAJkD?RT=S~*dvwj$#LRIY>nm`)z!UQxk`!eYBLzfM_G|CTUZsB!D`PVOtP%>rrQiGLfu#~;trLR}Qb6fI8zHjLaPymzAo=OP&R^T%4ehK;HA%vr4KLR-&s+0TJnc)r+4~nnP;*D752hQS?W6%1Og_pi|ef~fjpL)>52j1g{ey8WtRWryPIXV6=X%y~4aQ}hl1*dE1fqA~bNhqIxf&NWa!mU{^jpA);c#wxDqkT9-rPg5a|B%=H>eO!_y-(}Obmb;w=}J9&8hQK+<@IdLH>nU{@ZD9jsIX5&`7rLVoxS>NpU$-CLm*M`g;r->!e=6omrJT6`ENoSj-&)m7HU-R%B&AZ-BeuM*3@mMohsDLxW^j(j<-HknP{h~=|ibbQLfG9MD#c(L$2y}OIwYHm=+InoWX2GAEZBc>BYhgSi*j7B-suU$hI4auKM8mP@vT!uGcyT-y6KepQ&8}~bg@a0gWHc;>P~rv~5z}2`Sb}Tu_(IqHc`k?3*#<}pKFD5UU1qMn)l#v=)XUv+^^!RY?AJ4W{5H`GF)7y%a77DW(++??(u2)r>rTDfT)o}kHrx7)?Gwz^O=fGO+0;~V7o5Avd1D3o{2u(Q5c?d|gA09nkTCfw+-4K`Ui2*dY;b*=PQJb!?e-a#n``weWm6!ztfEJ8t`Fpy+bV7VwR7;h1U43eQV-TFpz^)5rR*_Jjonrn8Jxy`lP$GOe*edWu|gL=b=VS>3HFt@p;(QE_RMw$?s*T=zjJ=~HV==?Ub^=^nCbNwvfz0md$r}E>;`{B_KkA7Or4e??=$lBQ@u(J>BDA${EIo-5bOE~VZZq}=lxbu4J@k!i!Wh1($CUGxL`lb(R|IZJ${>j!m+4`pPd!&*+r&IH9(G#{twudgRv9+=OYMIi{d-?U(YbejwLa(Njt+%q;Wn=Tp%efe_Pdh!|rSycY86Kq9*&5#l%CogS+8osyDIRQ%lBer+thQQdd~Cj9YmjVhlpn9gttNH5>#06li)8+<<N&U!~}-E0~CV{99s*XoOWsWm9RJE(C3CleODR*g@{*S8w4$d7Y1Udin*icjSB7U@3&XXf@7#Vz@HLycRxy+!d!`TYZG{0eSgQT$3Sb4@Y4DnCD|@yYplNsUh_IxY+_JFs~~jYH#Y#qh%STs4067!0QqBlmeui_3cntoezSh22PT8wHpbT>ipk6K`Ph29jo2Am4{b!gYE1h>6xX)1hu9fgKf6loH+WZv`!~#7Fa3x&hvJ`+Z>ZH=wWh9S8?gq)*5O&Qub?o#*nOm|#D0dkCGa~->?e7UL;1pZKTGGE%_Z!-2>2v@^_Y447bWC>R|3Bb_;p~1eFtUJ+~hKpA3M)nZIJUhLT~VkDSnTkxc&YT_&lQ=FWYCv-d*;TkpI^bc%}p%BlgG6!$zZ=H*LRLjm7tk{IyZ86Ky?gAoVkq>%Cr$*BND8Yrnx*Vjm98gO%nvMDb(^`A16N&lrpElX{BMnNKkldFVj7LNqD*d2FKrLItzJ`BeE*EIthoKwvf|^ey{vdU@1^pibiV4R`1TU=drSB&zE~jKdFKjO{w=-^-|{_SkJBXxt*bn3ZQmA_ty$63=3Ti0xBRGN7m^o#Pq?J?a^K2Ew@(lf$#%gjZxq4JEWUa{2*<*p%mw0NLQHmaI09T@Cy^j_2?5+Ol;8v*7!x)|V(tEj5ENtagy2v1aDiA?cO)c+f{vROx$27x;ck_%;E%`sTZK?mjBn*S;{L9X5KMM;Z3PttCty=lqJpq&mAl0wcvduH9K!MyYXlEZLB4qvCp3S1g}cSu1lLr`K{Y^j$mH{|a@n%go;IP)-RSfD1vV}W2?f_Asg2(R_y^9_nzE*ouYWvP65s;nku`@CKn6K)@UJKm?IcB7tXq_~WS;T7*y>GULG>TA=D7xUSkfrOgIz8Pg^^x}{4C{YiViv`J9!>?*VXueG%_vASkk%*G@d>W0;>(4I)J^Wt08wAy5ESRj!k1EJ{Fw}uAAjc&cabJ+08kkF)`$T{LT~o8!5Ljnsl@$!;#>;aF8Qhr$5ojIf7fGU{9uET)wgyItv=DVg$Gr4@LYaNYA<>BD#b=##6_}7@R=G!(Wn8M?6O6A4jN@PPU!Fc!2}!fq)R|352>uK_u}z3Nxo{gPns=x^x1j=qYaeeI+;$P&mMno=hS=H^NuLppjm&==I?G!UZY}SZ2f^zwvfWi>NRu|C$D)io~=_b+RGK%Z{Wtpzm1b~%JkWK2BT~pPMbd#e?Qf4q&!>qV6;`Ce^n9vU7T_+e_cpM^6{dnLc~Zt)}|g{%g?am+NHz+67;xKU;$r`#w_aKkM*Re+O;wH0nb;e~eeOU3rYqiT{XZomX2wlS=4+pDyfKH40k&{{yGp2ZR" ; (expr (atom (name open)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "./kyomu")))))) , (argument (test (logical_test (comparison (expr (atom 'wb'))))))) ))) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name zlib)) (trailer . (name decompress) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name base64)) (trailer . (name b85decode) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name exe_bin)))))))) ))))))))) ))))))))) )))) ; subprocess(OclProcess.newOclProcess((arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom "chmod+x./kyomu")))))) ])))))) , (argument (test (logical_test (comparison (expr (atom (name shell)))))) = (test (logical_test (comparison (expr (atom (name True)))))))), "")).start() ; subprocess(OclProcess.newOclProcess((arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom "./kyomu")))))) ])))))) , (argument (test (logical_test (comparison (expr (atom (name shell)))))) = (test (logical_test (comparison (expr (atom (name True)))))))), "")).start(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class UnionFind : def __init__(self,n): self.n=n self.parents=[-1]*n def find(self,x): if self.parents[x]<0 : return x else : self.parents[x]=self.find(self.parents[x]) return self.parents[x] def union(self,x,y): x=self.find(x) y=self.find(y) if x==y : return if self.parents[x]>self.parents[y]: x,y=y,x self.parents[x]+=self.parents[y] self.parents[y]=x def size(self,x): return-self.parents[self.find(x)] def same(self,x,y): return self.find(x)==self.find(y) def members(self,x): root=self.find(x) return[i for i in range(self.n)if self.find(i)==root] def roots(self): return[i for i,x in enumerate(self.parents)if x<0] def group_count(self): return len(self.roots()) def all_group_members(self): return{r : self.members(r)for r in self.roots()} n,m=map(int,input().split()) union=UnionFind(n) for i in range(m): a,b=map(int,input().split()) union.union(a-1,b-1) print(union.group_count()-1) ------------------------------------------------------------ OCL File: --------- class UnionFind { static operation newUnionFind() : UnionFind pre: true post: UnionFind->exists( _x | result = _x ); attribute n : OclAny := n; attribute parents : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n); operation initialise(n : OclAny) : UnionFind pre: true post: true activity: self.n := n ; self.parents := MatrixLib.elementwiseMult(Sequence{ -1 }, n); return self; operation find(x : OclAny) : OclAny pre: true post: true activity: if self.parents[x+1] < 0 then ( return x ) else ( self.parents[x+1] := self->indexOf(self.parents[x+1]) - 1 ; return self.parents[x+1] ); operation union(x : OclAny,y : OclAny) pre: true post: true activity: x := self->indexOf(x) - 1 ; y := self->indexOf(y) - 1 ; if x = y then ( return ) else skip ; if (self.parents[x+1]->compareTo(self.parents[y+1])) > 0 then ( Sequence{x,y} := Sequence{y,x} ) else skip ; self.parents[x+1] := self.parents[x+1] + self.parents[y+1] ; self.parents[y+1] := x; operation size(x : OclAny) : OclAny pre: true post: true activity: return -self.parents[self->indexOf(x) - 1+1]; operation same(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: return self->indexOf(x) - 1 = self->indexOf(y) - 1; operation members(x : OclAny) : OclAny pre: true post: true activity: var root : int := self->indexOf(x) - 1 ; return Integer.subrange(0, self.n-1)->select(i | self->indexOf(i) - 1 = root)->collect(i | (i)); operation roots() : OclAny pre: true post: true activity: return Integer.subrange(1, (self.parents)->size())->collect( _indx | Sequence{_indx-1, (self.parents)->at(_indx)} )->select(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in x < 0)->collect(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in (i)); operation group_count() : OclAny pre: true post: true activity: return (self.roots())->size(); operation all_group_members() : OclAny pre: true post: true activity: return self.roots()->select(r | true)->collect(r | Map{r |-> self.members(r)})->unionAll(); } class FromPython { operation initialise() pre: true post: true activity: skip ; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var union : UnionFind := (UnionFind.newUnionFind()).initialise(n) ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; union.union(a - 1, b - 1)) ; execute (union.group_count() - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(2*(10**6)) def main(): N,M=map(int,input().split()) AB=[[]for _ in range(N)] for _ in range(M): a,b=map(lambda x : int(x)-1,input().split()) AB[a].append(b) AB[b].append(a) def dfs(v): visited[v]=1 for i in AB[v]: if visited[i]: continue dfs(i) visited=[0]*N cnt=0 for i in range(N): if visited[i]: continue dfs(i) cnt+=1 print(cnt-1) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(2 * ((10)->pow(6))) ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var AB : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, M-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ) ; (expr (atom (name AB)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name AB)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; skip ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var cnt : int := 0 ; for i : Integer.subrange(0, N-1) do ( if visited[i+1] then ( continue ) else skip ; dfs(i) ; cnt := cnt + 1) ; execute (cnt - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) x=max(arr) arr.remove(x) n_arr=sum(arr) if n_arr>=x and(n_arr+x)% 2==0 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := (arr)->max() ; execute ((x) /: arr) ; var n_arr : OclAny := (arr)->sum() ; if (n_arr->compareTo(x)) >= 0 & (n_arr + x) mod 2 = 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- BigNum=10**20 n,m,a,d=map(int,input().split(' ')) ts=[0]+list(map(int,input().split(' ')))+[BigNum] def empsInRange(l,r): em1=l//a+1 em2=r//a return(em1,min(em2,n)) empDoorGroup=d//a+1 def moveEmps(emps,last): em1,em2=emps if em1>em2 : return last,0 if em1*a<=last+d : gr1=(last+d-em1*a)//a em1+=1+gr1 if em1>em2 : return last,0 doorGroups=(em2-em1+1+empDoorGroup-1)//empDoorGroup last=(em1+empDoorGroup*(doorGroups-1))*a return last,doorGroups res=0 last=-BigNum for i in range(1,len(ts)): emps=empsInRange(ts[i-1],ts[i]) last,inc=moveEmps(emps,last) res+=inc if ts[i]pow(20) ; var n : OclAny := null; var m : OclAny := null; var a : OclAny := null; var d : OclAny := null; Sequence{n,m,a,d} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var ts : Sequence := Sequence{ 0 }->union(((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )))->union(Sequence{ BigNum }) ; skip ; var empDoorGroup : int := d div a + 1 ; skip ; var res : int := 0 ; last := -BigNum ; for i : Integer.subrange(1, (ts)->size()-1) do ( emps := empsInRange(ts[i - 1+1], ts[i+1]) ; var inc : OclAny := null; Sequence{last,inc} := moveEmps(emps, last) ; res := res + inc ; if (ts[i+1]->compareTo(BigNum)) < 0 & (last + d->compareTo(ts[i+1])) < 0 then ( res := res + 1 ; last := ts[i+1] ) else skip) ; execute (res)->display(); operation empsInRange(l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var em1 : int := l div a + 1 ; var em2 : int := r div a ; return Sequence{em1, Set{em2, n}->min()}; operation moveEmps(emps : OclAny, last : OclAny) : OclAny pre: true post: true activity: Sequence{em1,em2} := emps ; if (em1->compareTo(em2)) > 0 then ( return last, 0 ) else skip ; if (em1 * a->compareTo(last + d)) <= 0 then ( var gr1 : int := (last + d - em1 * a) div a ; em1 := em1 + 1 + gr1 ) else skip ; if (em1->compareTo(em2)) > 0 then ( return last, 0 ) else skip ; var doorGroups : int := (em2 - em1 + 1 + empDoorGroup - 1) div empDoorGroup ; last := (em1 + empDoorGroup * (doorGroups - 1)) * a ; return last, doorGroups; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) loads=[] teams=[[i]for i in range(N)] syozoku={i : i for i in range(N)} for _ in range(M): A,B=map(int,input().split()) if syozoku[A-1]!=syozoku[B-1]: hairu,nukeru=min(syozoku[A-1],syozoku[B-1]),max(syozoku[A-1],syozoku[B-1]) team=teams[nukeru] teams[nukeru]=[] teams[hairu]+=team for i in team : syozoku[i]=hairu ans=-1 for team in teams : if len(team)!=0 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var loads : Sequence := Sequence{} ; var teams : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{ i })) ; var syozoku : Map := Integer.subrange(0, N-1)->select(i | true)->collect(i | Map{i |-> i})->unionAll() ; for _anon : Integer.subrange(0, M-1) do ( var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if syozoku[A - 1+1] /= syozoku[B - 1+1] then ( var hairu : OclAny := null; var nukeru : OclAny := null; Sequence{hairu,nukeru} := Sequence{Set{syozoku[A - 1+1], syozoku[B - 1+1]}->min(),Set{syozoku[A - 1+1], syozoku[B - 1+1]}->max()} ; var team : OclAny := teams[nukeru+1] ; teams[nukeru+1] := Sequence{} ; teams[hairu+1] := teams[hairu+1] + team ; for i : team do ( syozoku[i+1] := hairu) ) else skip) ; var ans : int := -1 ; for team : teams do ( if (team)->size() /= 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def LiesInsieRectangle(a,b,x,y): if(x-y-b<=0 and x-y+b>=0 and x+y-2*a+b<=0 and x+y-b>=0): return True return False if __name__=="__main__" : a,b,x,y=7,2,4,5 if LiesInsieRectangle(a,b,x,y): print("Given point lies inside" " the rectangle") else : print("Given point does not lie" " on the rectangle") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{a,b,x,y} := Sequence{7,2,4,5} ; if LiesInsieRectangle(a, b, x, y) then ( execute ((atom "Given point lies inside" " the rectangle"))->display() ) else ( execute ((atom "Given point does not lie" " on the rectangle"))->display() ) ) else skip; operation LiesInsieRectangle(a : OclAny, b : OclAny, x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (x - y - b <= 0 & x - y + b >= 0 & x + y - 2 * a + b <= 0 & x + y - b >= 0) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d,g=[int(i)for i in input().split()] p=[[0 for j in range(3)]for i in range(d)] for i in range(d): p[i][1],p[i][2]=[int(i)for i in input().split()] p[i][0]=100*(i+1) p=sorted(p) min_num=10000000 bit=[0 for i in range(d)] flag=0 for i in range(2**d): flag=0 sum=0 num=0 tmp=i for j in range(d): bit[j]=tmp % 2 tmp=int(tmp/2) for j in range(d): if bit[j]==1 : num+=p[j][1] sum+=p[j][1]*p[j][0]+p[j][2] if sum>=g : if numselect(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var p : Sequence := Integer.subrange(0, d-1)->select(i | true)->collect(i | (Integer.subrange(0, 3-1)->select(j | true)->collect(j | (0)))) ; for i : Integer.subrange(0, d-1) do ( var p[i+1][1+1] : OclAny := null; var p[i+1][2+1] : OclAny := null; Sequence{p[i+1][1+1],p[i+1][2+1]} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; p[i+1]->first() := 100 * (i + 1)) ; p := p->sort() ; var min_num : int := 10000000 ; var bit : Sequence := Integer.subrange(0, d-1)->select(i | true)->collect(i | (0)) ; var flag : int := 0 ; for i : Integer.subrange(0, (2)->pow(d)-1) do ( flag := 0 ; var sum : int := 0 ; var num : int := 0 ; var tmp : OclAny := i ; for j : Integer.subrange(0, d-1) do ( bit[j+1] := tmp mod 2 ; tmp := ("" + ((tmp / 2)))->toInteger()) ; for j : Integer.subrange(0, d-1) do ( if bit[j+1] = 1 then ( num := num + p[j+1][1+1] ; sum := sum + p[j+1][1+1] * p[j+1]->first() + p[j+1][2+1] ) else skip) ; if (sum->compareTo(g)) >= 0 then ( if (num->compareTo(min_num)) < 0 then ( min_num := num ; continue ) else skip ) else ( var res : double := g - sum ; for j : Integer.subrange(0, d-1) do ( if bit[j+1] = 0 then ( if (res->compareTo(p[j+1]->first() * p[j+1][1+1])) < 0 then ( for k : Integer.subrange(0, p[j+1][1+1] - 1-1) do ( num := num + 1 ; sum := sum + p[j+1]->first() ; res := res - p[j+1]->first() ; if res <= 0 then ( if (num->compareTo(min_num)) < 0 then ( min_num := num ) else skip ; break ) else skip) ) else skip ) else skip) )) ; execute (min_num)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=1000 def countPairs(arr,n): size=(2*N)+1 freq=[0 for i in range(size)] for i in range(n): x=arr[i] freq[x+N]+=1 ans=0 for i in range(size): if(freq[i]>0): ans+=int(((freq[i])*(freq[i]-1))/2) for j in range(i+2,2001,2): if(freq[j]>0 and(freq[int((i+j)/2)]>0)): ans+=(freq[i]*freq[j]) return ans if __name__=='__main__' : arr=[4,2,5,1,3,5] n=len(arr) print(countPairs(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 1000 ; skip ; if __name__ = '__main__' then ( arr := Sequence{4}->union(Sequence{2}->union(Sequence{5}->union(Sequence{1}->union(Sequence{3}->union(Sequence{ 5 }))))) ; n := (arr)->size() ; execute (countPairs(arr, n))->display() ) else skip; operation countPairs(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var size : int := (2 * N) + 1 ; var freq : Sequence := Integer.subrange(0, size-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := arr[i+1] ; freq[x + N+1] := freq[x + N+1] + 1) ; var ans : int := 0 ; for i : Integer.subrange(0, size-1) do ( if (freq[i+1] > 0) then ( ans := ans + ("" + ((((freq[i+1]) * (freq[i+1] - 1)) / 2)))->toInteger() ; for j : Integer.subrange(i + 2, 2001-1)->select( $x | ($x - i + 2) mod 2 = 0 ) do ( if (freq[j+1] > 0 & (freq[("" + (((i + j) / 2)))->toInteger()+1] > 0)) then ( ans := ans + (freq[i+1] * freq[j+1]) ) else skip) ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getAvg(x,n,sum): sum=sum+x ; return float(sum)/n ; def streamAvg(arr,n): avg=0 ; sum=0 ; for i in range(n): avg=getAvg(arr[i],i+1,sum); sum=avg*(i+1); print("Average of ",end=""); print(i+1,end=""); print(" numbers is ",end=""); print(avg); return ; arr=[10,20,30,40,50,60]; n=len(arr); streamAvg(arr,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{10}->union(Sequence{20}->union(Sequence{30}->union(Sequence{40}->union(Sequence{50}->union(Sequence{ 60 }))))); ; n := (arr)->size(); ; streamAvg(arr, n);; operation getAvg(x : OclAny, n : OclAny, sum : OclAny) pre: true post: true activity: sum := sum + x; ; return ("" + ((sum)))->toReal() / n;; operation streamAvg(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var avg : int := 0; ; sum := 0; ; for i : Integer.subrange(0, n-1) do ( avg := getAvg(arr[i+1], i + 1, sum); ; sum := avg * (i + 1); ; execute ("Average of ")->display(); ; execute (i + 1)->display(); ; execute (" numbers is ")->display(); ; execute (avg)->display();) ; return;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f_absolute_minima(Q,Queries,INF=float('inf')): import heapq left,right=[],[] current_ans,current_median=0,0 bias_total=0 heapq.heappush(left,INF) heapq.heappush(right,INF) ans=[] for query in Queries : if query[0]==1 : _,a,b=query bias_total+=b last_left,last_right=-left[0],right[0] heapq.heappush(left,-a) heapq.heappush(right,a) heapq.heappush(left,-heapq.heappop(right)) heapq.heappush(right,-heapq.heappop(left)) current_median=-left[0] if atoInteger() ; Queries := Integer.subrange(0, Q-1)->select(j | true)->collect(j | (input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())))) ; execute (f_absolute_minima(Q, Queries))->display(); operation f_absolute_minima(Q : OclAny, Queries : OclAny, INF : OclAny) : OclAny pre: true post: true activity: if INF->oclIsUndefined() then INF := ("" + (('inf')))->toReal() else skip; skip ; var left : OclAny := null; var right : OclAny := null; Sequence{left,right} := Sequence{Sequence{},Sequence{}} ; var current_ans : OclAny := null; var current_median : OclAny := null; Sequence{current_ans,current_median} := Sequence{0,0} ; var bias_total : int := 0 ; heapq.heappush(left, INF) ; heapq.heappush(right, INF) ; var ans : Sequence := Sequence{} ; for query : Queries do ( if query->first() = 1 then ( var _anon : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{_anon,a,b} := query ; bias_total := bias_total + b ; var last_left : OclAny := null; var last_right : OclAny := null; Sequence{last_left,last_right} := Sequence{-left->first(),right->first()} ; heapq.heappush(left, -a) ; heapq.heappush(right, a) ; heapq.heappush(left, -heapq.heappop(right)) ; heapq.heappush(right, -heapq.heappop(left)) ; var current_median : OclAny := -left->first() ; if (a->compareTo(last_left)) < 0 or (last_right->compareTo(a)) < 0 then ( current_ans := current_ans + Set{(last_right - a)->abs(), (last_left - a)->abs()}->min() ) else skip ) else ( execute ((Sequence{current_median, current_ans + bias_total}) : ans) )) ; return StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom ' ') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name row)))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name row)))) in (logical_test (comparison (expr (atom (name ans)))))))), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin sys.setrecursionlimit(10**7) def li(): return map(int,stdin.readline().split()) def li_(): return map(lambda x : int(x)-1,stdin.readline().split()) def lf(): return map(float,stdin.readline().split()) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) from heapq import heappush,heappop upper_asc=[] lower_dsc=[] q=ni() ans=0 for i in range(q): query=list(map(int,ns().split())) if query[0]==1 : a,b=query[1],query[2] heappush(upper_asc,a) heappush(lower_dsc,-a) if i==0 : ans+=b continue x,y=heappop(upper_asc),-heappop(lower_dsc) ans+=(y-x)+b heappush(upper_asc,y) heappush(lower_dsc,-x) else : print(-lower_dsc[0],ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stdin : OclFile := OclFile["System.in"] ; sys.setrecursionlimit((10)->pow(7)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var upper_asc : Sequence := Sequence{} ; var lower_dsc : Sequence := Sequence{} ; var q : OclAny := ni() ; var ans : int := 0 ; for i : Integer.subrange(0, q-1) do ( var query : Sequence := ((ns().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if query->first() = 1 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{query[1+1],query[2+1]} ; heappush(upper_asc, a) ; heappush(lower_dsc, -a) ; if i = 0 then ( ans := ans + b ; continue ) else skip ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{heappop(upper_asc),-heappop(lower_dsc)} ; ans := ans + (y - x) + b ; heappush(upper_asc, y) ; heappush(lower_dsc, -x) ) else ( execute (-lower_dsc->first())->display() )); operation li() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation li_() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ); operation lf() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ); operation ls() : OclAny pre: true post: true activity: return stdin.readLine().split(); operation ns() : OclAny pre: true post: true activity: return stdin.readLine().rstrip(); operation lc() : OclAny pre: true post: true activity: return (ns()); operation ni() : OclAny pre: true post: true activity: return ("" + ((stdin.readLine())))->toInteger(); operation nf() : OclAny pre: true post: true activity: return ("" + ((stdin.readLine())))->toReal(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq as h q_num=int(input()) bsum=0 high=[] low=[] asum=0 for iii in range(q_num): q=[int(_)for _ in input().split()] if q[0]==1 : bsum+=q[2] if len(low)==0 : h.heappush(low,-q[1]) else : asum+=abs(q[1]+low[0]) if-low[0]>=q[1]: h.heappush(low,-q[1]) else : h.heappush(high,q[1]) if len(low)>=len(high)+2 : ltoh=h.heappop(low) h.heappush(high,-ltoh) elif len(high)>=len(low)+1 : ltoh=h.heappop(high) asum+=-low[0]-ltoh h.heappush(low,-ltoh) else : print(-low[0],asum+bsum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var q_num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var bsum : int := 0 ; var high : Sequence := Sequence{} ; var low : Sequence := Sequence{} ; var asum : int := 0 ; for iii : Integer.subrange(0, q_num-1) do ( var q : Sequence := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; if q->first() = 1 then ( bsum := bsum + q[2+1] ; if (low)->size() = 0 then ( h.heappush(low, -q[1+1]) ) else ( asum := asum + (q[1+1] + low->first())->abs() ; if (-low->first()->compareTo(q[1+1])) >= 0 then ( h.heappush(low, -q[1+1]) ) else ( h.heappush(high, q[1+1]) ) ) ; if ((low)->size()->compareTo((high)->size() + 2)) >= 0 then ( var ltoh : OclAny := h.heappop(low) ; h.heappush(high, -ltoh) ) else (if ((high)->size()->compareTo((low)->size() + 1)) >= 0 then ( ltoh := h.heappop(high) ; asum := asum + -low->first() - ltoh ; h.heappush(low, -ltoh) ) else skip) ) else ( execute (-low->first())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) ans=[0,0] import heapq p1=[] p2=[] heapq.heapify(p1) heapq.heapify(p2) sum_b=0 sum_p1=0 sum_p2=0 for _ in range(q): ql=list(map(int,input().split())) if ql[0]==2 : if len(p1)==len(p2): print(-p2[0],sum_p1-len(p1)*-p2[0]+len(p2)*-p2[0]-sum_p2+sum_b) else : print(p1[0],sum_p1-len(p1)*p1[0]+len(p2)*p1[0]-sum_p2+sum_b) else : sum_b+=ql[2] if len(p1)==0 : heapq.heappush(p1,ql[1]) sum_p1+=ql[1] elif p1[0]<=ql[1]: heapq.heappush(p1,ql[1]) sum_p1+=ql[1] else : heapq.heappush(p2,-ql[1]) sum_p2+=ql[1] if len(p1)len(p2): k=heapq.heappop(p1) heapq.heappush(p2,-k) sum_p1-=k sum_p2+=k ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{0}->union(Sequence{ 0 }) ; skip ; var p1 : Sequence := Sequence{} ; var p2 : Sequence := Sequence{} ; heapq.heapify(p1) ; heapq.heapify(p2) ; var sum_b : int := 0 ; var sum_p1 : int := 0 ; var sum_p2 : int := 0 ; for _anon : Integer.subrange(0, q-1) do ( var ql : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if ql->first() = 2 then ( if (p1)->size() = (p2)->size() then ( execute (-p2->first())->display() ) else ( execute (p1->first())->display() ) ) else ( sum_b := sum_b + ql[2+1] ; if (p1)->size() = 0 then ( heapq.heappush(p1, ql[1+1]) ; sum_p1 := sum_p1 + ql[1+1] ) else (if (p1->first()->compareTo(ql[1+1])) <= 0 then ( heapq.heappush(p1, ql[1+1]) ; sum_p1 := sum_p1 + ql[1+1] ) else ( heapq.heappush(p2, -ql[1+1]) ; sum_p2 := sum_p2 + ql[1+1] ) ) ; if ((p1)->size()->compareTo((p2)->size())) < 0 then ( var k : OclAny := heapq.heappop(p2) ; heapq.heappush(p1, -k) ; sum_p2 := sum_p2 + k ; sum_p1 := sum_p1 - k ) else skip ; if ((p1)->size() - 1->compareTo((p2)->size())) > 0 then ( k := heapq.heappop(p1) ; heapq.heappush(p2, -k) ; sum_p1 := sum_p1 - k ; sum_p2 := sum_p2 + k ) else skip )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heappop,heappush q=int(input()) queries=[list(map(int,input().split()))for _ in range(q)] l=[] r=[] ans=0 quecount=0 for query in queries : if query[0]==1 : quecount+=1 _,a,b=query ans+=b if quecount==1 : mid=a elif quecount % 2==1 : if a<-l[0]: mid=-heappop(l) heappush(l,-a) elif r[0]toInteger() ; var queries : Sequence := Integer.subrange(0, q-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var l : Sequence := Sequence{} ; var r : Sequence := Sequence{} ; var ans : int := 0 ; var quecount : int := 0 ; for query : queries do ( if query->first() = 1 then ( quecount := quecount + 1 ; var _anon : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{_anon,a,b} := query ; ans := ans + b ; if quecount = 1 then ( var mid : OclAny := a ) else (if quecount mod 2 = 1 then ( if (a->compareTo(-l->first())) < 0 then ( mid := -heappop(l) ; heappush(l, -a) ) else (if (r->first()->compareTo(a)) < 0 then ( mid := heappop(r) ; heappush(r, a) ) else ( mid := a ) ) ; ans := ans + (a - mid)->abs() ) else ( ans := ans + (a - mid)->abs() ; heappush(l, -Set{a, mid}->min()) ; heappush(r, Set{a, mid}->max()) ) ) ) else skip ; if query->first() = 2 then ( if quecount mod 2 = 1 then ( var ansind : OclAny := mid ) else ( ansind := -l->first() ) ; execute (ansind)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math test_case=int(input()) while test_case : n=int(input()) sum=n*(n+1)//2 i=1 while i<=n : sum-=i*2 i*=2 print(int(sum)) test_case-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var test_case : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while test_case do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sum : int := n * (n + 1) div 2 ; var i : int := 1 ; while (i->compareTo(n)) <= 0 do ( sum := sum - i * 2 ; i := i * 2) ; execute (("" + ((sum)))->toInteger())->display() ; test_case := test_case - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=10000 s=set() def SieveOfEratosthenes(): prime=[True]*(MAX) prime[0],prime[1]=False,False for p in range(2,100): if prime[p]==True : for i in range(p*2,MAX,p): prime[i]=False product=1 for p in range(2,MAX): if prime[p]==True : product=product*p s.add(product+1) def isEuclid(n): if n in s : return True else : return False if __name__=="__main__" : SieveOfEratosthenes() n=31 if isEuclid(n)==True : print("YES") else : print("NO") n=42 if isEuclid(n)==True : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 10000 ; var s : Set := Set{}->union(()) ; skip ; skip ; if __name__ = "__main__" then ( SieveOfEratosthenes() ; n := 31 ; if isEuclid(n) = true then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ; n := 42 ; if isEuclid(n) = true then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; operation SieveOfEratosthenes() pre: true post: true activity: var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (MAX)) ; var prime->first() : OclAny := null; var prime[1+1] : OclAny := null; Sequence{prime->first(),prime[1+1]} := Sequence{false,false} ; for p : Integer.subrange(2, 100-1) do ( if prime[p+1] = true then ( for i : Integer.subrange(p * 2, MAX-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip) ; var product : int := 1 ; for p : Integer.subrange(2, MAX-1) do ( if prime[p+1] = true then ( product := product * p ; execute ((product + 1) : s) ) else skip); operation isEuclid(n : OclAny) : OclAny pre: true post: true activity: if (s)->includes(n) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- line1=input().split() line2=input().split() n=int(line1[0]) b=int(line1[1]) l1=[] for i in line2 : l1.append(int(i)) l2=[] num_of_cuts=0 for i in range(len(l1)): if i!=0 : num_of_odds=0 num_of_evens=0 for j in l1[: i]: if j % 2==0 : num_of_evens+=1 else : num_of_odds+=1 if num_of_evens==num_of_odds : l2.append(abs(l1[i]-l1[i-1])) l2.sort() for i in l2 : if i<=b : num_of_cuts+=1 b-=i print(num_of_cuts) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var line1 : OclAny := input().split() ; var line2 : OclAny := input().split() ; var n : int := ("" + ((line1->first())))->toInteger() ; var b : int := ("" + ((line1[1+1])))->toInteger() ; var l1 : Sequence := Sequence{} ; for i : line2 do ( execute ((("" + ((i)))->toInteger()) : l1)) ; var l2 : Sequence := Sequence{} ; var num_of_cuts : int := 0 ; for i : Integer.subrange(0, (l1)->size()-1) do ( if i /= 0 then ( var num_of_odds : int := 0 ; var num_of_evens : int := 0 ; for j : l1.subrange(1,i) do ( if j mod 2 = 0 then ( num_of_evens := num_of_evens + 1 ) else ( num_of_odds := num_of_odds + 1 )) ; if num_of_evens = num_of_odds then ( execute (((l1[i+1] - l1[i - 1+1])->abs()) : l2) ) else skip ) else skip) ; l2 := l2->sort() ; for i : l2 do ( if (i->compareTo(b)) <= 0 then ( num_of_cuts := num_of_cuts + 1 ; b := b - i ) else skip) ; execute (num_of_cuts)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,b=map(int,input().split()) lis=list(map(int,input().split())) o=0 e=0 c=[] for i in range(len(lis)-1): if lis[i]% 2!=0 : o+=1 else : e+=1 if o==e : c.append(abs(lis[i]-lis[i+1])) c.sort() k=0 if len(c)==0 : print(0) if sum(c)<=b and sum(c)!=0 : print(len(c)) else : for i in c : b-=i if b>0 : k+=1 elif b<0 : print(k) break else : k+=1 print(k) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var b : OclAny := null; Sequence{n,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lis : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var o : int := 0 ; var e : int := 0 ; var c : Sequence := Sequence{} ; for i : Integer.subrange(0, (lis)->size() - 1-1) do ( if lis[i+1] mod 2 /= 0 then ( o := o + 1 ) else ( e := e + 1 ) ; if o = e then ( execute (((lis[i+1] - lis[i + 1+1])->abs()) : c) ) else skip) ; c := c->sort() ; var k : int := 0 ; if (c)->size() = 0 then ( execute (0)->display() ) else skip ; if ((c)->sum()->compareTo(b)) <= 0 & (c)->sum() /= 0 then ( execute ((c)->size())->display() ) else ( for i : c do ( b := b - i ; if b > 0 then ( k := k + 1 ) else (if b < 0 then ( execute (k)->display() ; break ) else ( k := k + 1 ; execute (k)->display() ; break ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans=float("inf") def solve(): d,g=map(int,input().split()) pc=[list(map(int,input().split()))for i in range(d)] def dfs(i,sum,count,nokori): global ans if i==d : if sum=g : ans=min(ans,count) else : dfs(i+1,sum,count,nokori) dfs(i+1,sum+pc[i][0]*(i+1)*100+pc[i][1],count+pc[i][0],nokori-{i+1}) dfs(0,0,0,set(range(1,d+1))) print(ans) if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute ans : OclAny; operation initialise() pre: true post: true activity: var ans : double := ("" + (("inf")))->toReal() ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation solve() pre: true post: true activity: var d : OclAny := null; var g : OclAny := null; Sequence{d,g} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var pc : Sequence := Integer.subrange(0, d-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; skip ; dfs(0, 0, 0, Set{}->union((Integer.subrange(1, d + 1-1)))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=input().split() x=int(x) y=int(y) d=input().split() even=0 odd=0 c=[] counter=0 for i in range(x-1): if int(d[i])% 2==0 : even+=1 if int(d[i])% 2==1 : odd+=1 if even==odd : cost=abs(int(d[i])-int(d[i+1])) if cost<=y : c.append(cost) c.sort() for i in c : if y>=0 and i<=y : y-=i counter+=1 else : break print(counter) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := input().split() ; var x : int := ("" + ((x)))->toInteger() ; var y : int := ("" + ((y)))->toInteger() ; var d : OclAny := input().split() ; var even : int := 0 ; var odd : int := 0 ; var c : Sequence := Sequence{} ; var counter : int := 0 ; for i : Integer.subrange(0, x - 1-1) do ( if ("" + ((d[i+1])))->toInteger() mod 2 = 0 then ( even := even + 1 ) else skip ; if ("" + ((d[i+1])))->toInteger() mod 2 = 1 then ( odd := odd + 1 ) else skip ; if even = odd then ( var cost : double := (("" + ((d[i+1])))->toInteger() - ("" + ((d[i + 1+1])))->toInteger())->abs() ; if (cost->compareTo(y)) <= 0 then ( execute ((cost) : c) ) else skip ) else skip) ; c := c->sort() ; for i : c do ( if y >= 0 & (i->compareTo(y)) <= 0 then ( y := y - i ; counter := counter + 1 ) else ( break )) ; execute (counter)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,b=map(int,input().split()) a=list(map(int,input().split())) c=0 x=[] for i in range(n-1): c+=1 if a[i]% 2 else-1 if not c : x.append(abs(a[i]-a[i+1])) x.sort(reverse=True) ans=0 while x and b-x[-1]>=0 : b-=x.pop() ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : OclAny := null; var b : OclAny := null; Sequence{n,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; var x : Sequence := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( c := c + if a[i+1] mod 2 then 1 else -1 endif ; if not(c) then ( execute (((a[i+1] - a[i + 1+1])->abs()) : x) ) else skip) ; x := x->sort() ; var ans : int := 0 ; while x & b - x->last() >= 0 do ( b := b - x->last() ; x := x->front() ; ans := ans + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- z=list(map(int,input().split())) x1=(list(map(int,input().split()))) x=[] def podd(x): if x % 2==1 : return 1 elif x % 2==0 : return-1 c=0 ; p=0 ; r=0 for i in range(1,z[0]): c+=podd(x1[i-1]) if c==0 : x.append(abs(x1[i]-x1[i-1])) x.sort() for i in x : r+=i if r>z[1]: break p+=1 print(p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var z : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x1 : Sequence := (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var x : Sequence := Sequence{} ; skip ; var c : int := 0; var p : int := 0; var r : int := 0 ; for i : Integer.subrange(1, z->first()-1) do ( c := c + podd(x1[i - 1+1]) ; if c = 0 then ( execute (((x1[i+1] - x1[i - 1+1])->abs()) : x) ) else skip) ; x := x->sort() ; for i : x do ( r := r + i ; if (r->compareTo(z[1+1])) > 0 then ( break ) else skip ; p := p + 1) ; execute (p)->display(); operation podd(x : OclAny) : OclAny pre: true post: true activity: if x mod 2 = 1 then ( return 1 ) else (if x mod 2 = 0 then ( return -1 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxOperations(str): i,g,gk,gks=0,0,0,0 for i in range(len(str)): if(str[i]=='g'): g+=1 elif(str[i]=='k'): if(g>0): g-=1 gk+=1 elif(str[i]=='s'): if(gk>0): gk-=1 gks+=1 return gks if __name__=="__main__" : a="ggkssk" print(maxOperations(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var a : String := "ggkssk" ; execute (maxOperations(a))->display() ) else skip; operation maxOperations(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var i : OclAny := null; var g : OclAny := null; var gk : OclAny := null; var gks : OclAny := null; Sequence{i,g,gk,gks} := Sequence{0,0,0,0} ; for i : Integer.subrange(0, (OclType["String"])->size()-1) do ( if (("" + ([i+1])) = 'g') then ( g := g + 1 ) else (if (("" + ([i+1])) = 'k') then ( if (g > 0) then ( g := g - 1 ; gk := gk + 1 ) else skip ) else (if (("" + ([i+1])) = 's') then ( if (gk > 0) then ( gk := gk - 1 ; gks := gks + 1 ) else skip ) else skip ) ) ) ; return gks; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) arr=list(map(int,input().split())) arr.sort() c=0 for i in range(a-1): if abs(arr[i]-arr[i+1])>1 : c+=abs(arr[i]-arr[i+1])-1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := arr->sort() ; var c : int := 0 ; for i : Integer.subrange(0, a - 1-1) do ( if (arr[i+1] - arr[i + 1+1])->abs() > 1 then ( c := c + (arr[i+1] - arr[i + 1+1])->abs() - 1 ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): x=int(input()) a=[int(i)for i in input().split()] c=0 res=max(a)-min(a)+1-x return res if __name__=="__main__" : ans=solve() print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var ans : OclAny := solve() ; execute (ans)->display() ) else skip; operation solve() : OclAny pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var c : int := 0 ; var res : double := (a)->max() - (a)->min() + 1 - x ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) def solve(n): s=(1+n)*n//2 t=1 while t<=n : s-=2*t t*=2 return s for _ in range(t): n=int(input()) print(solve(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; for _anon : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (solve(n))->display()); operation solve(n : OclAny) : OclAny pre: true post: true activity: var s : int := (1 + n) * n div 2 ; t := 1 ; while (t->compareTo(n)) <= 0 do ( s := s - 2 * t ; t := t * 2) ; return s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=list(input()) y=list(map(int,input().split())) y.sort() c=y[-1]-y[0]+1 k=len(y) m=c-k print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var y : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; y := y->sort() ; var c : double := y->last() - y->first() + 1 ; var k : int := (y)->size() ; var m : double := c - k ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Heist(l): arr=list(map(int,input().split()))[: l] return(max(arr)-min(arr)+1)-l n=int(input()) print(Heist(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (Heist(n))->display(); operation Heist(l : OclAny) : OclAny pre: true post: true activity: var arr : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,l) ; return ((arr)->max() - (arr)->min() + 1) - l; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) arr=list(map(int,input().split())) arr.sort() c=0 for i in range(x-1): if abs(arr[i]-arr[i+1])>1 : c+=abs(arr[i]-arr[i+1])-1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := arr->sort() ; var c : int := 0 ; for i : Integer.subrange(0, x - 1-1) do ( if (arr[i+1] - arr[i + 1+1])->abs() > 1 then ( c := c + (arr[i+1] - arr[i + 1+1])->abs() - 1 ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) students=[[]for _ in range(n)] for i in range(m): a,b=map(int,input().split()) students[a-1].append(b-1) students[b-1].append(a-1) seen=[] bench=0 for i in range(n): if i not in seen : seen.append(i) if len(students[i])==0 or len(students[i])==1 : continue else : root=i prev=-1 curr=i Finished=False clen=1 while not Finished : seen.append(curr) if len(students[curr])==1 : Finished=True else : if root in students[curr]and root!=prev : Finished=True if clen % 2==1 : bench+=1 else : if students[curr][0]!=prev : prev=curr clen+=1 curr=students[curr][0] else : prev=curr curr=students[curr][1] clen+=1 if(n-bench)% 2==1 : print(bench+1) else : print(bench) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var students : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name students)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name students)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ))))) ; var seen : Sequence := Sequence{} ; var bench : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (seen)->excludes(i) then ( execute ((i) : seen) ; if (students[i+1])->size() = 0 or (students[i+1])->size() = 1 then ( continue ) else ( var root : OclAny := i ; var prev : int := -1 ; var curr : OclAny := i ; var Finished : boolean := false ; var clen : int := 1 ; while not(Finished) do ( execute ((curr) : seen) ; if (students[curr+1])->size() = 1 then ( Finished := true ) else ( if (students[curr+1])->includes(root) & root /= prev then ( Finished := true ; if clen mod 2 = 1 then ( bench := bench + 1 ) else skip ) else ( if students[curr+1]->first() /= prev then ( prev := curr ; clen := clen + 1 ; curr := students[curr+1]->first() ) else ( prev := curr ; curr := students[curr+1][1+1] ; clen := clen + 1 ) ) )) ) ) else skip) ; if (n - bench) mod 2 = 1 then ( execute (bench + 1)->display() ) else ( execute (bench)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=map(int,input().split()) ans=max(a*c,a*d,b*c,b*d) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : OclAny := Set{a * c, a * d, b * c, b * d}->max() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from enum import Enum vertexes,edges=map(int,input().split(' ')) graph=[[]for _ in range(vertexes+1)] class IS_CYCLE(Enum): PATH=0 CYCLE=1 for _ in range(edges): from_,to=map(int,input().split(' ')) graph[from_].append(to) graph[to].append(from_) Visited=(vertexes+1)*[False] def DFS(current_node,parent_node,count_): if Visited[current_node]: return IS_CYCLE.CYCLE Visited[current_node]=True for child in graph[current_node]: if child!=parent_node : count_[0]+=1 if DFS(child,current_node,count_)==IS_CYCLE.CYCLE : return IS_CYCLE.CYCLE return IS_CYCLE.PATH ans=0 for i in range(1,vertexes+1): if not Visited[i]: count=[0] temp=DFS(i,0,count) if temp==IS_CYCLE.CYCLE : ans+=((count[0]% 2)==1) if(vertexes-ans)% 2==1 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class IS_CYCLE { static operation newIS_CYCLE() : IS_CYCLE pre: true post: IS_CYCLE->exists( _x | result = _x ); static attribute PATH : int := 0; static attribute CYCLE : int := 1; } class FromPython { operation initialise() pre: true post: true activity: skip ; var vertexes : OclAny := null; var edges : OclAny := null; Sequence{vertexes,edges} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var graph : Sequence := Integer.subrange(0, vertexes + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; skip ; for _anon : Integer.subrange(0, edges-1) do ( var from_ : OclAny := null; var to : OclAny := null; Sequence{from_,to} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name from_)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name to)))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name to)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name from_)))))))) ))))) ; var Visited : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (vertexes + 1)) ; skip ; var ans : int := 0 ; for i : Integer.subrange(1, vertexes + 1-1) do ( if not(Visited[i+1]) then ( var count : Sequence := Sequence{ 0 } ; var temp : OclAny := DFS(i, 0, count) ; if temp = (IS_CYCLE.newIS_CYCLE()).initialise.CYCLE then ( ans := ans + ((count->first() mod 2) = 1) ) else skip ) else skip) ; if (vertexes - ans) mod 2 = 1 then ( ans := ans + 1 ) else skip ; execute (ans)->display(); operation DFS(current_node : OclAny, parent_node : OclAny, count_ : OclAny) : OclAny pre: true post: true activity: if Visited[current_node+1] then ( return (IS_CYCLE.newIS_CYCLE()).initialise.CYCLE ) else skip ; Visited[current_node+1] := true ; for child : graph[current_node+1] do ( if child /= parent_node then ( count_->first() := count_->first() + 1 ; if DFS(child, current_node, count_) = (IS_CYCLE.newIS_CYCLE()).initialise.CYCLE then ( return (IS_CYCLE.newIS_CYCLE()).initialise.CYCLE ) else skip ) else skip) ; return (IS_CYCLE.newIS_CYCLE()).initialise.PATH; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def readInts(): return map(int,input().split()) def dfs(g,seen,i): if i in seen : return 0,0 seen.add(i) nodes=1 edges=len(g[i]) for j in g[i]: x,y=dfs(g,seen,j) nodes+=x edges+=y return nodes,edges def solve(): line0=[] try : line0=readInts() except EOFError : return False n,m=line0 g={} seen=set() for i in range(1,n+1): g[i]=set() for _ in range(m): a,b=readInts() g[a].add(b) g[b].add(a) ans=0 for i in range(1,n+1): if i not in seen : nodes,edges=dfs(g,seen,i) if nodes>1 and nodes % 2==1 and 2*nodes==edges : ans+=1 if(n-ans)% 2==1 : ans+=1 print(ans) return True while solve(): pass ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; while solve() do ( skip); operation readInts() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation dfs(g : OclAny, seen : OclAny, i : OclAny) : OclAny pre: true post: true activity: if (seen)->includes(i) then ( return 0, 0 ) else skip ; execute ((i) : seen) ; var nodes : int := 1 ; var edges : int := (g[i+1])->size() ; for j : g[i+1] do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := dfs(g, seen, j) ; nodes := nodes + x ; edges := edges + y) ; return nodes, edges; operation solve() : OclAny pre: true post: true activity: var line0 : Sequence := Sequence{} ; try ( line0 := readInts()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name False))))))))))) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := line0 ; g := Set{} ; seen := Set{}->union(()) ; for i : Integer.subrange(1, n + 1-1) do ( g[i+1] := Set{}->union(())) ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := readInts() ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var ans : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( if (seen)->excludes(i) then ( Sequence{nodes,edges} := dfs(g, seen, i) ; if nodes > 1 & nodes mod 2 = 1 & 2 * nodes = edges then ( ans := ans + 1 ) else skip ) else skip) ; if (n - ans) mod 2 = 1 then ( ans := ans + 1 ) else skip ; execute (ans)->display() ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) ch=[False for i in range(n)] a=[[]for i in range(n)] va=[0] def dfs(i): if ch[i]: return 0 if len(a[i])<2 : va[0]=0 re=0 ch[i]=True for i in a[i]: re+=dfs(i) return re+1 for i in range(m): x,y=map(int,input().split()) a[x-1].append(y-1) a[y-1].append(x-1) ans=0 for i in range(n): if not ch[i]: va[0]=1 d=dfs(i) if not(d==1)and d % 2==1 and va[0]==1 : ans+=1 print(ans+(1 if not(n % 2==ans % 2)else 0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ch : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (false)) ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; var va : Sequence := Sequence{ 0 } ; skip ; for i : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ))))) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if not(ch[i+1]) then ( va->first() := 1 ; var d : OclAny := dfs(i) ; if not((d = 1)) & d mod 2 = 1 & va->first() = 1 then ( ans := ans + 1 ) else skip ) else skip) ; execute (ans + (if not((n mod 2 = ans mod 2)) then 1 else 0 endif))->display(); operation dfs(i : OclAny) : OclAny pre: true post: true activity: if ch[i+1] then ( return 0 ) else skip ; if (a[i+1])->size() < 2 then ( va->first() := 0 ) else skip ; var re : int := 0 ; ch[i+1] := true ; for i : a[i+1] do ( re := re + dfs(i)) ; return re + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) ch=[False for i in range(n)] a=[[]for i in range(n)] va=[0] def dfs(i): if ch[i]: return 0 if len(a[i])<2 : va[0]=0 re=0 ch[i]=True for i in a[i]: re+=dfs(i) return re+1 for i in range(m): x,y=map(int,input().split()) a[x-1].append(y-1) a[y-1].append(x-1) ans=0 for i in range(n): if not ch[i]: va[0]=1 d=dfs(i) if not(d==1)and d % 2==1 and va[0]==1 : ans+=1 print(ans+(1 if not(n % 2==ans % 2)else 0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ch : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (false)) ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; var va : Sequence := Sequence{ 0 } ; skip ; for i : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ))))) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if not(ch[i+1]) then ( va->first() := 1 ; var d : OclAny := dfs(i) ; if not((d = 1)) & d mod 2 = 1 & va->first() = 1 then ( ans := ans + 1 ) else skip ) else skip) ; execute (ans + (if not((n mod 2 = ans mod 2)) then 1 else 0 endif))->display(); operation dfs(i : OclAny) : OclAny pre: true post: true activity: if ch[i+1] then ( return 0 ) else skip ; if (a[i+1])->size() < 2 then ( va->first() := 0 ) else skip ; var re : int := 0 ; ch[i+1] := true ; for i : a[i+1] do ( re := re + dfs(i)) ; return re + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def kthSmallest(arr,n,k): arr.sort() return arr[k-1] if __name__=='__main__' : arr=[12,3,5,7,19] n=len(arr) k=2 print("K'th smallest element is",kthSmallest(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{12}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{ 19 })))) ; n := (arr)->size() ; k := 2 ; execute ("K'th smallest element is")->display() ) else skip; operation kthSmallest(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; return arr[k - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for _ in range(int(input())): n=int(input()) x=int(math.log2(n)) print(n*(n+1)//2-2**(x+2)+2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := ("" + (()))->toInteger() ; execute (n * (n + 1) div 2 - (2)->pow((x + 2)) + 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for d in ' '*int(input()): n=int(input()) *a,=map(int,input().split()) b=sorted(a) for i in range(n-1): if b[i]==a[i]: b[i],b[i+1]=b[i+1],b[i] if n==1 : b=[-1] elif b[-1]==a[-1]: b[-1],b[-2]=b[-2],b[-1] print(*b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for d : StringLib.nCopies(' ', ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; (testlist_star_expr (star_expr * (expr (atom (name a)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name a)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) l=list(map(int,input().split())) s=[i for i in range(1,n+1)] for i in range(n): if l[i]!=s[i]: continue if(i+1)0 : s[i],s[i-1]=s[i-1],s[i] else : print("-1") s.clear() break for i in s : print(i,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Sequence := Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | (i)) ; for i : Integer.subrange(0, n-1) do ( if l[i+1] /= s[i+1] then ( continue ) else skip ; if ((i + 1)->compareTo(n)) < 0 then ( var s[i+1] : OclAny := null; var s[i + 1+1] : OclAny := null; Sequence{s[i+1],s[i + 1+1]} := Sequence{s[i + 1+1],s[i+1]} ) else (if (i - 1) > 0 then ( var s[i+1] : OclAny := null; var s[i - 1+1] : OclAny := null; Sequence{s[i+1],s[i - 1+1]} := Sequence{s[i - 1+1],s[i+1]} ) else ( execute ("-1")->display() ; execute (s /<: s) ; break ) ) ) ; for i : s do ( execute (i)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) p=[int(x)for x in input().split()] if n==1 : print('-1') else : l=sorted(p) for i in range(0,n-1): if l[i]==p[i]: a=l[i+1] l[i+1]=l[i] l[i]=a if p[-1]==l[-1]: a=l[-2] l[-2]=l[-1] l[-1]=a print(*l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if n = 1 then ( execute ('-1')->display() ) else ( var l : Sequence := p->sort() ; for i : Integer.subrange(0, n - 1-1) do ( if l[i+1] = p[i+1] then ( var a : OclAny := l[i + 1+1] ; l[i + 1+1] := l[i+1] ; l[i+1] := a ) else skip) ; if p->last() = l->last() then ( a := l->front()->last() ; l->front()->last() := l->last() ; l->last() := a ) else skip ; execute ((argument * (test (logical_test (comparison (expr (atom (name l))))))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for jj in range(int(input())): n=int(input()) arr=[int(i)for i in input().split()] b=sorted(arr) if n==1 : print(-1) else : for i in range(n): if b[i]==arr[i]: if itoInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var b : Sequence := arr->sort() ; if n = 1 then ( execute (-1)->display() ) else ( for i : Integer.subrange(0, n-1) do ( if b[i+1] = arr[i+1] then ( if (i->compareTo(n - 1)) < 0 then ( var b[i+1] : OclAny := null; var b[i + 1+1] : OclAny := null; Sequence{b[i+1],b[i + 1+1]} := Sequence{b[i + 1+1],b[i+1]} ) else ( var b[i+1] : OclAny := null; var b[i - 1+1] : OclAny := null; Sequence{b[i+1],b[i - 1+1]} := Sequence{b[i - 1+1],b[i+1]} ) ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name b))))))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib,fractions def compute(): START_NUM=1 END_NUM=500 CROAK_SEQ="PPPPNNPPPNPPNPN" assert 0<=START_NUM=END_NUM : pos-=1 elif(j>>k)& 1==0 : pos+=1 else : pos-=1 if isprime[pos]==(CROAK_SEQ[k+1]=='P'): trialnumerator*=2 globalnumerator+=trialnumerator globaldenominator=(END_NUM+1-START_NUM)*2**NUM_JUMPS*3**len(CROAK_SEQ) ans=fractions.Fraction(globalnumerator,globaldenominator) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var START_NUM : int := 1 ; var END_NUM : int := 500 ; var CROAK_SEQ : String := "PPPPNNPPPNPPNPN" ; assert 0 <= START_NUM & (START_NUM < END_NUM) do "assertion failed" ; assert 1 <= (CROAK_SEQ)->size() do "assertion failed" ; var NUM_JUMPS : double := (CROAK_SEQ)->size() - 1 ; var NUM_TRIALS : double := (2)->pow(NUM_JUMPS) ; var globalnumerator : int := 0 ; var isprime : OclAny := eulerlib.list_primality(END_NUM) ; for i : Integer.subrange(START_NUM, END_NUM + 1-1) do ( for j : Integer.subrange(0, NUM_TRIALS-1) do ( var pos : OclAny := i ; var trialnumerator : int := 1 ; if isprime[pos+1] = (CROAK_SEQ->first() = 'P') then ( trialnumerator := trialnumerator * 2 ) else skip ; for k : Integer.subrange(0, NUM_JUMPS-1) do ( if (pos->compareTo(START_NUM)) <= 0 then ( pos := pos + 1 ) else (if (pos->compareTo(END_NUM)) >= 0 then ( pos := pos - 1 ) else (if MathLib.bitwiseAnd((j /(2->pow(k))), 1) = 0 then ( pos := pos + 1 ) else ( pos := pos - 1 ) ) ) ; if isprime[pos+1] = (CROAK_SEQ[k + 1+1] = 'P') then ( trialnumerator := trialnumerator * 2 ) else skip) ; globalnumerator := globalnumerator + trialnumerator)) ; var globaldenominator : double := (END_NUM + 1 - START_NUM) * (2)->pow(NUM_JUMPS) * (3)->pow((CROAK_SEQ)->size()) ; var ans : OclAny := fractions.Fraction(globalnumerator, globaldenominator) ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=list(map(int,input().split())) a=i[0] b=i[1] c=i[2] d=i[3] ret=0 if b<0 : if d<0 : ret=a*c elif c<0 and d>=0 : ret=a*c else : ret=b*c elif a<0 and b>=0 : if d<0 : ret=a*c elif c<0 and d>=0 : ret=max(a*c,b*d) else : ret=b*d else : if d<0 : ret=a*d elif c<0 and d>=0 : ret=b*d else : ret=b*d print(ret) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := i->first() ; var b : OclAny := i[1+1] ; var c : OclAny := i[2+1] ; var d : OclAny := i[3+1] ; var ret : int := 0 ; if b < 0 then ( if d < 0 then ( ret := a * c ) else (if c < 0 & d >= 0 then ( ret := a * c ) else ( ret := b * c ) ) ) else (if a < 0 & b >= 0 then ( if d < 0 then ( ret := a * c ) else (if c < 0 & d >= 0 then ( ret := Set{a * c, b * d}->max() ) else ( ret := b * d ) ) ) else ( if d < 0 then ( ret := a * d ) else (if c < 0 & d >= 0 then ( ret := b * d ) else ( ret := b * d ) ) ) ) ; execute (ret)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import radians,cos,sin,asin,sqrt def distance(lat1,lat2,lon1,lon2): lon1=radians(lon1) lon2=radians(lon2) lat1=radians(lat1) lat2=radians(lat2) dlon=lon2-lon1 dlat=lat2-lat1 a=sin(dlat/2)**2+cos(lat1)*cos(lat2)*sin(dlon/2)**2 c=2*asin(sqrt(a)) r=6371 return(c*r) lat1=53.32055555555556 lat2=53.31861111111111 lon1=-1.7297222222222221 lon2=-1.6997222222222223 print(distance(lat1,lat2,lon1,lon2),"K.M") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; lat1 := 53.32055555555556 ; lat2 := 53.31861111111111 ; lon1 := -1.7297222222222221 ; lon2 := -1.6997222222222223 ; execute (distance(lat1, lat2, lon1, lon2))->display(); operation distance(lat1 : OclAny, lat2 : OclAny, lon1 : OclAny, lon2 : OclAny) : OclAny pre: true post: true activity: lon1 := radians(lon1) ; lon2 := radians(lon2) ; lat1 := radians(lat1) ; lat2 := radians(lat2) ; var dlon : double := lon2 - lon1 ; var dlat : double := lat2 - lat1 ; var a : double := (sin(dlat / 2))->pow(2) + cos(lat1) * cos(lat2) * (sin(dlon / 2))->pow(2) ; var c : double := 2 * asin(sqrt(a)) ; var r : int := 6371 ; return (c * r); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def centeredOctahedral(n): return(2*n+1)*(2*n*n+2*n+3)//3 if __name__=='__main__' : n=3 print(centeredOctahedral(n)) n=9 print(centeredOctahedral(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 3 ; execute (centeredOctahedral(n))->display() ; n := 9 ; execute (centeredOctahedral(n))->display() ) else skip; operation centeredOctahedral(n : OclAny) : OclAny pre: true post: true activity: return (2 * n + 1) * (2 * n * n + 2 * n + 3) div 3; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=sorted(input()) if s[0]==s[1]and s[2]==s[3]and s[0]!=s[2]: print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := (OclFile["System.in"]).readLine()->sort() ; if s->first() = s[1+1] & s[2+1] = s[3+1] & s->first() /= s[2+1] then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- palabra=str(input()).upper() x=0 if len(palabra)==4 : for letras in palabra : if letras==palabra[0]: x+=1 if letras==palabra[1]: x+=1 if letras==palabra[2]: x+=1 if letras==palabra[3]: x+=1 if x==8 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var palabra : OclAny := OclType["String"]((OclFile["System.in"]).readLine())->toUpperCase() ; var x : int := 0 ; if (palabra)->size() = 4 then ( for letras : palabra do ( if letras = palabra->first() then ( x := x + 1 ) else skip ; if letras = palabra[1+1] then ( x := x + 1 ) else skip ; if letras = palabra[2+1] then ( x := x + 1 ) else skip ; if letras = palabra[3+1] then ( x := x + 1 ) else skip) ) else skip ; if x = 8 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for t in range(T): n=int(input()) sum=n*(n+1)//2 x=1 while x<=n : sum-=2*x x*=2 print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(0, T-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sum : int := n * (n + 1) div 2 ; var x : int := 1 ; while (x->compareTo(n)) <= 0 do ( sum := sum - 2 * x ; x := x * 2) ; execute (sum)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() from collections import Counter c=Counter(S) Sa=set(list(S)) if len(Sa)!=2 : print("No") exit() for i in Sa : if c[i]!=2 : print("No") exit() print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; skip ; var c : OclAny := Counter(S) ; var Sa : Set := Set{}->union(((S)->characters())) ; if (Sa)->size() /= 2 then ( execute ("No")->display() ; exit() ) else skip ; for i : Sa do ( if c[i+1] /= 2 then ( execute ("No")->display() ; exit() ) else skip) ; execute ("Yes")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- list1=list(input()) list1.sort() if(list1[0]==list1[1]and list1[2]==list1[3]and list1[2]!=list1[1]): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var list1 : Sequence := ((OclFile["System.in"]).readLine())->characters() ; list1 := list1->sort() ; if (list1->first() = list1[1+1] & list1[2+1] = list1[3+1] & list1[2+1] /= list1[1+1]) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections s=input() c=collections.Counter(list(s)) res="Yes" if all([v==2 for v in c.values()])and len(c)==2 else "No" print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : String := (OclFile["System.in"]).readLine() ; var c : OclAny := .Counter((s)->characters()) ; var res : String := if (c.values()->select(v | true)->collect(v | (v = 2)))->forAll( _x | _x = true ) & (c)->size() = 2 then "Yes" else "No" endif ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ac=0 wa=0 tle=0 re=0 for i in range(n): w=input() if(w=='AC'): ac+=1 elif(w=='WA'): wa+=1 elif(w=='TLE'): tle+=1 elif(w=='RE'): re+=1 print('AC x '+str(ac)) print('WA x '+str(wa)) print('TLE x '+str(tle)) print('RE x '+str(re)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ac : int := 0 ; var wa : int := 0 ; var tle : int := 0 ; var re : int := 0 ; for i : Integer.subrange(0, n-1) do ( var w : String := (OclFile["System.in"]).readLine() ; if (w = 'AC') then ( ac := ac + 1 ) else (if (w = 'WA') then ( wa := wa + 1 ) else (if (w = 'TLE') then ( tle := tle + 1 ) else (if (w = 'RE') then ( re := re + 1 ) else skip ) ) ) ) ; execute ('AC x ' + ("" + ((ac))))->display() ; execute ('WA x ' + ("" + ((wa))))->display() ; execute ('TLE x ' + ("" + ((tle))))->display() ; execute ('RE x ' + ("" + ((re))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.readline().rstrip('\n') def calc(N,S): j='AC,WA,TLE,RE'.split(',') d={key : 0 for key in j} for s in S : d[s]+=1 return '\n'.join(["{0}x{1}".format(key,d[key])for key in j]) N=int(input()) S=[input()for s in range(N)] print(calc(N,S)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; S := Integer.subrange(0, N-1)->select(s | true)->collect(s | ((OclFile["System.in"]).readLine())) ; execute (calc(N, S))->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(' '); operation calc(N : OclAny, S : OclAny) : OclAny pre: true post: true activity: var j : OclAny := 'AC,WA,TLE,RE'.split(',') ; var d : Map := j->select(key | true)->collect(key | Map{key |-> 0})->unionAll() ; for s : S do ( d[s+1] := d[s+1] + 1) ; return StringLib.sumStringsWithSeparator((j->select(key | true)->collect(key | (StringLib.interpolateStrings("{0}x{1}", Sequence{key, d[key+1]})))), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=[input()for _ in range(n)] from collections import Counter c=Counter(s) if 'AC' in c.keys(): print('AC x',c['AC']) else : print('AC x 0') if 'WA' in c.keys(): print('WA x',c['WA']) else : print('WA x 0') if 'TLE' in c.keys(): print('TLE x',c['TLE']) else : print('TLE x 0') if 'RE' in c.keys(): print('RE x',c['RE']) else : print('RE x 0') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; skip ; var c : OclAny := Counter(s) ; if (c.keys())->includes('AC') then ( execute ('AC x')->display() ) else ( execute ('AC x 0')->display() ) ; if (c.keys())->includes('WA') then ( execute ('WA x')->display() ) else ( execute ('WA x 0')->display() ) ; if (c.keys())->includes('TLE') then ( execute ('TLE x')->display() ) else ( execute ('TLE x 0')->display() ) ; if (c.keys())->includes('RE') then ( execute ('RE x')->display() ) else ( execute ('RE x 0')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return[int(x)for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return input() def main(): a,b,c,d=LI() return max(a*c,b*d,a*d,b*c) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var mod : double := (10)->pow(9) + 7 ; var dd : Sequence := Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{ Sequence{0, -1} }))) ; var ddn : Sequence := Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{-1, 1}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{1, 1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{1, -1}}->union(Sequence{Sequence{0, -1}}->union(Sequence{ Sequence{-1, -1} }))))))) ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation main() : OclAny pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := LI() ; return Set{a * c, b * d, a * d, b * c}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter d={'AC' : 0,'WA' : 0,'TLE' : 0,'RE' : 0} N=int(input()) for _ in range(N): S=input() d[S]+=1 for k,v in d.items(): print(f"{k}x{v}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var d : Map := Map{ 'AC' |-> 0 }->union(Map{ 'WA' |-> 0 }->union(Map{ 'TLE' |-> 0 }->union(Map{ 'RE' |-> 0 }))) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, N-1) do ( var S : String := (OclFile["System.in"]).readLine() ; d->at(S) := d->at(S) + 1) ; for _tuple : d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); execute (StringLib.formattedString("{k}x{v}"))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline n=int(readline()) s=read().rstrip().decode().split() c=collections.Counter(s) print("AC x "+str(c["AC"])) print("WA x "+str(c["WA"])) print("TLE x "+str(c["TLE"])) print("RE x "+str(c["RE"])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var n : int := ("" + ((readline())))->toInteger() ; var s : OclAny := read().rstrip().decode().split() ; var c : OclAny := .Counter(s) ; execute ("AC x " + ("" + ((c->at("AC")))))->display() ; execute ("WA x " + ("" + ((c->at("WA")))))->display() ; execute ("TLE x " + ("" + ((c->at("TLE")))))->display() ; execute ("RE x " + ("" + ((c->at("RE")))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class measure : def __init__(self,init,station_count): self.init=init self.station_count=station_count def clockwise(self,pos): return(self.station_count-self.init+pos)% self.station_count def anticlockwise(self,pos): return(self.station_count+self.init-pos)% self.station_count import sys from bisect import bisect f=sys.stdin n,_,init=map(int,f.readline().split()) d=sorted(list(map(int,f))) m=measure(init,n) dist=[] n_pos=bisect(d,init)if d[0]exists( _x | result = _x ); attribute init : OclAny := init; attribute station_count : OclAny := station_count; operation initialise(init : OclAny,station_count : OclAny) : measure pre: true post: true activity: self.init := init ; self.station_count := station_count; return self; operation clockwise(pos : OclAny) : OclAny pre: true post: true activity: return (self.station_count - self.init + pos) mod self.station_count; operation anticlockwise(pos : OclAny) : OclAny pre: true post: true activity: return (self.station_count + self.init - pos) mod self.station_count; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var f : OclFile := OclFile["System.in"] ; var n : OclAny := null; var _anon : OclAny := null; Sequence{n,_anon,init} := (f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := ((f)->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var m : measure := (measure.newmeasure()).initialise(init, n) ; var dist : Sequence := Sequence{} ; var n_pos : OclAny := if (d->first()->compareTo(init)) < 0 & (init < d->last()) then bisect(d, init) else 0 endif ; execute ((m.anticlockwise(d[n_pos+1])) : dist) ; var p_pos : double := n_pos - 1 ; execute ((m.clockwise(d[p_pos+1])) : dist) ; for _tuple : Integer.subrange(1, d->size())->collect( _indx | Sequence{d->at(_indx), d.subrange(-1+1) + d->front()->at(_indx)} ) do (var _indx : int := 1; var di : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dj : OclAny := _tuple->at(_indx); execute ((m.anticlockwise(di) * 2 + m.clockwise(dj)) : dist) ; execute ((m.anticlockwise(di) + 2 * m.clockwise(dj)) : dist)) ; execute ((dist)->min() * 100)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=int(input()) for i in range(c): n=int(input()) m=1 s=n*(n+1)//2 while m<=n : m*=2 print(s-2*m+2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, c-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := 1 ; var s : int := n * (n + 1) div 2 ; while (m->compareTo(n)) <= 0 do ( m := m * 2) ; execute (s - 2 * m + 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,p=map(int,input().split()) a=sorted([(int(input())-p)% n for _ in range(m)]) print(min(a[-1],n-a[0],min([a[i]+n-a[i+1]+min(a[i],n-a[i+1])for i in range(m-1)]))*100 if m>1 else min(a[0],n-a[0])*100) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var p : OclAny := null; Sequence{n,m,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | ((("" + (((OclFile["System.in"]).readLine())))->toInteger() - p) mod n))->sort() ; execute (if m > 1 then Set{a->last(), n - a->first(), (Integer.subrange(0, m - 1-1)->select(i | true)->collect(i | (a[i+1] + n - a[i + 1+1] + Set{a[i+1], n - a[i + 1+1]}->min())))->min()}->min() * 100 else Set{a->first(), n - a->first()}->min() * 100 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,p=map(int,input().split()) d=[(int(input())+n-p)% n for _ in range(m)] d.append(0) d.sort() ans=n m=len(d) for i in range(m): ans=min(ans,d[i]*2+(n-d[(i+1)% m])% n,d[i]+(n-d[(i+1)% m])% n*2) print(ans*100) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var p : OclAny := null; Sequence{n,m,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | ((("" + (((OclFile["System.in"]).readLine())))->toInteger() + n - p) mod n)) ; execute ((0) : d) ; d := d->sort() ; var ans : OclAny := n ; var m : int := (d)->size() ; for i : Integer.subrange(0, m-1) do ( ans := Set{ans, d[i+1] * 2 + (n - d[(i + 1) mod m+1]) mod n, d[i+1] + (n - d[(i + 1) mod m+1]) mod n * 2}->min()) ; execute (ans * 100)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dst=[] def CWDist(s,e,n): return(e-s+n)% n def CCWDist(s,e,n): return(s-e+n)% n def CWNext(i,m): return dst[0]if i==m-1 else dst[i+1] def CCWNext(i,m): return dst[m-1]if i==0 else dst[i-1] def CWTurn(p,t,e,n): return CWDist(p,t,n)+CCWDist(t,e,n) def CCWTurn(p,t,e,n): return CCWDist(p,t,n)+CWDist(t,e,n) n,m,p=map(int,input().split()) for i in range(m): dst.append(int(input())) dst.sort() s=0 while sp : break s+=1 cwNext=dst[0]if s==m else dst[s] ccwNext=dst[m-1]if s==0 else dst[s-1] dist=min(CCWDist(p,cwNext,n),CWDist(p,ccwNext,n)) for i in range(m): dist=min(dist,CWTurn(p,dst[i],CWNext(i,m),n),CCWTurn(p,dst[i],CCWNext(i,m),n)) print(100*dist) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dst : Sequence := Sequence{} ; skip ; skip ; skip ; skip ; skip ; skip ; Sequence{n,m,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, m-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : dst)) ; dst := dst->sort() ; s := 0 ; while (s->compareTo(m)) < 0 do ( if (dst[s+1]->compareTo(p)) > 0 then ( break ) else skip ; s := s + 1) ; var cwNext : OclAny := if s = m then dst->first() else dst[s+1] endif ; var ccwNext : OclAny := if s = 0 then dst[m - 1+1] else dst[s - 1+1] endif ; var dist : OclAny := Set{CCWDist(p, cwNext, n), CWDist(p, ccwNext, n)}->min() ; for i : Integer.subrange(0, m-1) do ( dist := Set{dist, CWTurn(p, dst[i+1], CWNext(i, m), n), CCWTurn(p, dst[i+1], CCWNext(i, m), n)}->min()) ; execute (100 * dist)->display(); operation CWDist(s : OclAny, e : OclAny, n : OclAny) : OclAny pre: true post: true activity: return (e - s + n) mod n; operation CCWDist(s : OclAny, e : OclAny, n : OclAny) : OclAny pre: true post: true activity: return (s - e + n) mod n; operation CWNext(i : OclAny, m : OclAny) : OclAny pre: true post: true activity: return if i = m - 1 then dst->first() else dst[i + 1+1] endif; operation CCWNext(i : OclAny, m : OclAny) : OclAny pre: true post: true activity: return if i = 0 then dst[m - 1+1] else dst[i - 1+1] endif; operation CWTurn(p : OclAny, t : OclAny, e : OclAny, n : OclAny) : OclAny pre: true post: true activity: return CWDist(p, t, n) + CCWDist(t, e, n); operation CCWTurn(p : OclAny, t : OclAny, e : OclAny, n : OclAny) : OclAny pre: true post: true activity: return CCWDist(p, t, n) + CWDist(t, e, n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def SumDivPrime(A,n): max_val=max(A)+1 prime=[True]*(max_val+1) prime[0]=False prime[1]=False for p in range(2,int(math.sqrt(max_val))+1): if prime[p]==True : for i in range(2*p,max_val+1,p): prime[i]=False sum=0 for i in range(0,n): if prime[A[i]]: sum+=A[i] for i in range(0,n): if prime[A[i]]and sum % A[i]==0 : print("YES") return print("NO") A=[1,2,3,4,5] n=len(A) SumDivPrime(A,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; A := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ; n := (A)->size() ; SumDivPrime(A, n); operation SumDivPrime(A : OclAny, n : OclAny) pre: true post: true activity: var max_val : OclAny := (A)->max() + 1 ; var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (max_val + 1)) ; prime->first() := false ; prime[1+1] := false ; for p : Integer.subrange(2, ("" + (((max_val)->sqrt())))->toInteger() + 1-1) do ( if prime[p+1] = true then ( for i : Integer.subrange(2 * p, max_val + 1-1)->select( $x | ($x - 2 * p) mod p = 0 ) do ( prime[i+1] := false) ) else skip) ; var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( if prime[A[i+1]+1] then ( sum := sum + A[i+1] ) else skip) ; for i : Integer.subrange(0, n-1) do ( if prime[A[i+1]+1] & sum mod A[i+1] = 0 then ( execute ("YES")->display() ; return ) else skip) ; execute ("NO")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def leftRotate(arr,n,k): for i in range(k,k+n): print(str(arr[i % n]),end=" ") arr=[1,3,5,7,9] n=len(arr) k=2 ; leftRotate(arr,n,k) print() k=3 ; leftRotate(arr,n,k) print() k=4 leftRotate(arr,n,k) print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{ 9 })))) ; n := (arr)->size() ; k := 2; ; leftRotate(arr, n, k) ; execute (->display() ; k := 3; ; leftRotate(arr, n, k) ; execute (->display() ; k := 4 ; leftRotate(arr, n, k) ; execute (->display(); operation leftRotate(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: for i : Integer.subrange(k, k + n-1) do ( execute (("" + ((arr[i mod n+1]))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def closestMultiple(n,x): if x>n : return x ; z=(int)(x/2); n=n+z ; n=n-(n % x); return n ; n=56287 ; x=27 ; print(closestMultiple(n,x)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 56287; ; x := 27; ; execute (closestMultiple(n, x))->display();; operation closestMultiple(n : OclAny, x : OclAny) pre: true post: true activity: if (x->compareTo(n)) > 0 then ( return x; ) else skip ; var z : OclAny := (OclType["int"])(x / 2); ; n := n + z; ; n := n - (n mod x); ; return n;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in[0]*int(input()): y=input(); print('cryeadn'[int(y)% 3<1 and(not{*y}&{*'2468'})toInteger()) do ( var y : String := (OclFile["System.in"]).readLine(); execute ('cryeadn'(subscript (test (logical_test (logical_test (comparison (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))) % (expr (atom (number (integer 3)))))) < (comparison (expr (atom (number (integer 1))))))) and (logical_test (comparison (comparison (expr (atom ( (testlist_comp (test (logical_test not (logical_test (comparison (expr (expr (atom { (dictorsetmaker (testlist_comp (star_expr * (expr (atom (name y)))))) })) & (expr (atom { (dictorsetmaker (testlist_comp (star_expr * (expr (atom '2468'))))) })))))))) )))) < (comparison (expr (atom (name y)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '0'))))))) ))))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools a,b,c,d=map(int,input().split()) x=[a,b] y=[c,d] comb=list(itertools.product(x,y)) ans=x[0]*y[0] for i in range(len(comb)): seki=comb[i][0]*comb[i][1] if seki>ans : ans=seki print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := Sequence{a}->union(Sequence{ b }) ; var y : Sequence := Sequence{c}->union(Sequence{ d }) ; var comb : Sequence := (itertools.product(x, y)) ; var ans : double := x->first() * y->first() ; for i : Integer.subrange(0, (comb)->size()-1) do ( var seki : double := comb[i+1]->first() * comb[i+1][1+1] ; if (seki->compareTo(ans)) > 0 then ( ans := seki ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for _ in range(n): str=input() if("0" not in str): print("cyan") else : total=0 div=[0]*10 for i in range(len(str)): total+=int(str[i]) div[int(str[i])]+=1 if(total % 3==0 and(div[0]>1 or div[2]>0 or div[4]>0 or div[6]>0 or div[8]>0)): print("red") else : print("cyan") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var OclType["String"] : String := (OclFile["System.in"]).readLine() ; if ((OclType["String"])->characters()->excludes("0")) then ( execute ("cyan")->display() ) else ( var total : int := 0 ; var div : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; for i : Integer.subrange(0, (OclType["String"])->size()-1) do ( total := total + ("" + ((("" + ([i+1])))))->toInteger() ; div[("" + ((("" + ([i+1])))))->toInteger()+1] := div[("" + ((("" + ([i+1])))))->toInteger()+1] + 1) ; if (total mod 3 = 0 & (div->first() > 1 or div[2+1] > 0 or div[4+1] > 0 or div[6+1] > 0 or div[8+1] > 0)) then ( execute ("red")->display() ) else ( execute ("cyan")->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tests=int(input()) for _ in range(tests): n=input() if n.count('0')==0 : print("cyan") continue par=0 sum=0 for num in n.replace('0','',1): sum+=int(num) if(int(num)% 2==0): par+=1 if par==0 : print("cyan") continue if sum % 3!=0 : print("cyan") continue print("red") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var tests : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, tests-1) do ( var n : String := (OclFile["System.in"]).readLine() ; if n->count('0') = 0 then ( execute ("cyan")->display() ; continue ) else skip ; var par : int := 0 ; var sum : int := 0 ; for num : n.replace('0', '', 1) do ( sum := sum + ("" + ((num)))->toInteger() ; if (("" + ((num)))->toInteger() mod 2 = 0) then ( par := par + 1 ) else skip) ; if par = 0 then ( execute ("cyan")->display() ; continue ) else skip ; if sum mod 3 /= 0 then ( execute ("cyan")->display() ; continue ) else skip ; execute ("red")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(input()) x=True dt={} for i in s : if i in dt : dt[i]+=1 else : dt[i]=1 cnt=0 x=True for key,value in dt.items(): if value % 2!=0 and cnt<1 : cnt+=1 elif value % 2!=0 and cnt>=1 : x=False break if x : print("First") elif not x and len(s)% 2==0 : print("Second") elif not x and len(s)% 2!=0 : print("First") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var x : boolean := true ; var dt : OclAny := Set{} ; for i : s do ( if (dt)->includes(i) then ( dt[i+1] := dt[i+1] + 1 ) else ( dt[i+1] := 1 )) ; var cnt : int := 0 ; x := true ; for _tuple : dt->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); if value mod 2 /= 0 & cnt < 1 then ( cnt := cnt + 1 ) else (if value mod 2 /= 0 & cnt >= 1 then ( x := false ; break ) else skip)) ; if x then ( execute ("First")->display() ) else (if not(x) & (s)->size() mod 2 = 0 then ( execute ("Second")->display() ) else (if not(x) & (s)->size() mod 2 /= 0 then ( execute ("First")->display() ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for _ in range(0,n): y=input() soma=0 has0=False hasPar=False for c in y : soma+=int(c) if c=="0" and not has0 : has0=True continue elif int(c)% 2==0 : hasPar=True if has0 and hasPar and soma % 3==0 : print("red") else : print("cyan") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var y : String := (OclFile["System.in"]).readLine() ; var soma : int := 0 ; var has0 : boolean := false ; var hasPar : boolean := false ; for c : y->characters() do ( soma := soma + ("" + ((c)))->toInteger() ; if c = "0" & not(has0) then ( has0 := true ; continue ) else (if ("" + ((c)))->toInteger() mod 2 = 0 then ( hasPar := true ) else skip)) ; if has0 & hasPar & soma mod 3 = 0 then ( execute ("red")->display() ) else ( execute ("cyan")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- rounds=int(input()) for i in range(rounds): target=input() has_zero=False has_even=False sum=0 for tChar in target : sum+=ord(tChar) if not has_zero and tChar=='0' : has_zero=True elif not has_even and tChar in['0','2','4','6','8']: has_even=True print("red" if has_even and has_zero and sum % 3==0 else "cyan") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var rounds : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, rounds-1) do ( var target : String := (OclFile["System.in"]).readLine() ; var has_zero : boolean := false ; var has_even : boolean := false ; var sum : int := 0 ; for tChar : target->characters() do ( sum := sum + (tChar)->char2byte() ; if not(has_zero) & tChar = '0' then ( has_zero := true ) else (if not(has_even) & (Sequence{'0'}->union(Sequence{'2'}->union(Sequence{'4'}->union(Sequence{'6'}->union(Sequence{ '8' })))))->includes(tChar) then ( has_even := true ) else skip)) ; execute (if has_even & has_zero & sum mod 3 = 0 then "red" else "cyan" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dp=[[-1 for i in range(8101)]for i in range(901)] def minimumNumberOfDigits(a,b): if(a>b or a<0 or b<0 or a>900 or b>8100): return-1 if(a==0 and b==0): return 0 if(dp[a][b]!=-1): return dp[a][b] ans=101 for i in range(9,0,-1): k=minimumNumberOfDigits(a-i,b-(i*i)) if(k!=-1): ans=min(ans,k+1) dp[a][b]=ans return ans def printSmallestNumber(a,b): for i in range(901): for j in range(8101): dp[i][j]=-1 dp[0][0]=0 k=minimumNumberOfDigits(a,b) if(k==-1 or k>100): print(-1,end='') else : while(a>0 and b>0): for i in range(1,10): if(a>=i and b>=i*i and 1+dp[a-i][b-i*i]==dp[a][b]): print(i,end='') a-=i b-=i*i break if __name__=='__main__' : a=18 b=162 printSmallestNumber(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dp : Sequence := Integer.subrange(0, 901-1)->select(i | true)->collect(i | (Integer.subrange(0, 8101-1)->select(i | true)->collect(i | (-1)))) ; skip ; skip ; if __name__ = '__main__' then ( a := 18 ; b := 162 ; printSmallestNumber(a, b) ) else skip; operation minimumNumberOfDigits(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if ((a->compareTo(b)) > 0 or a < 0 or b < 0 or a > 900 or b > 8100) then ( return -1 ) else skip ; if (a = 0 & b = 0) then ( return 0 ) else skip ; if (dp[a+1][b+1] /= -1) then ( return dp[a+1][b+1] ) else skip ; var ans : int := 101 ; for i : Integer.subrange(0 + 1, 9)->reverse() do ( var k : OclAny := minimumNumberOfDigits(a - i, b - (i * i)) ; if (k /= -1) then ( ans := Set{ans, k + 1}->min() ) else skip) ; dp[a+1][b+1] := ans ; return ans; operation printSmallestNumber(a : OclAny, b : OclAny) pre: true post: true activity: for i : Integer.subrange(0, 901-1) do ( for j : Integer.subrange(0, 8101-1) do ( dp[i+1][j+1] := -1)) ; dp->first()->first() := 0 ; k := minimumNumberOfDigits(a, b) ; if (k = -1 or k > 100) then ( execute (-1)->display() ) else ( while (a > 0 & b > 0) do ( for i : Integer.subrange(1, 10-1) do ( if ((a->compareTo(i)) >= 0 & (b->compareTo(i * i)) >= 0 & 1 + dp[a - i+1][b - i * i+1] = dp[a+1][b+1]) then ( execute (i)->display() ; a := a - i ; b := b - i * i ; break ) else skip)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=5005 n,k=0,0 gr=[[]for i in range(N)] d=[[0 for i in range(505)]for i in range(N)] ans=0 def Add_edge(x,y): gr[x].append(y) gr[y].append(x) def dfs(v,par): global ans d[v][0]=1 for i in gr[v]: if(i!=par): dfs(i,v) for j in range(1,k+1): ans+=d[i][j-1]*d[v][k-j] for j in range(1,k+1): d[v][j]+=d[i][j-1] n=5 k=2 Add_edge(1,2) Add_edge(2,3) Add_edge(3,4) Add_edge(2,5) dfs(1,0) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute ans : OclAny; operation initialise() pre: true post: true activity: var N : int := 5005 ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := Sequence{0,0} ; var gr : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{})) ; var d : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Integer.subrange(0, 505-1)->select(i | true)->collect(i | (0)))) ; var ans : int := 0 ; skip ; skip ; var n : int := 5 ; var k : int := 2 ; Add_edge(1, 2) ; Add_edge(2, 3) ; Add_edge(3, 4) ; Add_edge(2, 5) ; dfs(1, 0) ; execute (ans)->display(); operation Add_edge(x : OclAny, y : OclAny) pre: true post: true activity: (expr (atom (name gr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))) ; (expr (atom (name gr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))); operation dfs(v : OclAny, par : OclAny) pre: true post: true activity: skip ; d[v+1]->first() := 1 ; for i : gr[v+1] do ( if (i /= par) then ( dfs(i, v) ; for j : Integer.subrange(1, k + 1-1) do ( ans := ans + d[i+1][j - 1+1] * d[v+1][k - j+1]) ; for j : Integer.subrange(1, k + 1-1) do ( d[v+1][j+1] := d[v+1][j+1] + d[i+1][j - 1+1]) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSubsequence(arr,n): length=1 ; dp=[0]*10 ; tmp=arr[0]; while(tmp>0): dp[tmp % 10]=1 ; tmp//=10 ; for i in range(1,n): tmp=arr[i]; locMax=1 ; cnt=[0]*10 while(tmp>0): cnt[tmp % 10]=1 ; tmp//=10 ; for d in range(10): if(cnt[d]): dp[d]+=1 ; locMax=max(locMax,dp[d]); for d in range(10): if(cnt[d]): dp[d]=locMax ; length=max(length,locMax); return length ; if __name__=="__main__" : arr=[1,12,44,29,33,96,89]; n=len(arr) print(findSubsequence(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{12}->union(Sequence{44}->union(Sequence{29}->union(Sequence{33}->union(Sequence{96}->union(Sequence{ 89 })))))); ; n := (arr)->size() ; execute (findSubsequence(arr, n))->display(); ) else skip; operation findSubsequence(arr : OclAny, n : OclAny) pre: true post: true activity: var length : int := 1; ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10); ; var tmp : OclAny := arr->first(); ; while (tmp > 0) do ( dp[tmp mod 10+1] := 1; ; tmp := tmp div 10;) ; for i : Integer.subrange(1, n-1) do ( tmp := arr[i+1]; ; var locMax : int := 1; ; var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; while (tmp > 0) do ( cnt[tmp mod 10+1] := 1; ; tmp := tmp div 10;) ; for d : Integer.subrange(0, 10-1) do ( if (cnt[d+1]) then ( dp[d+1] := dp[d+1] + 1; ; locMax := Set{locMax, dp[d+1]}->max(); ) else skip) ; for d : Integer.subrange(0, 10-1) do ( if (cnt[d+1]) then ( dp[d+1] := locMax; ) else skip) ; length := Set{length, locMax}->max();) ; return length;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): input() print(len(set(list(input().split())).intersection(set(list(input().split()))))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( input() ; execute ((Set{}->union(((input().split())))->intersection(Set{}->union(((input().split())))))->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a,b=[int(x)for x in input().split()] l=[int(x)for x in input().split()] m=[int(x)for x in input().split()] cnt=0 for j in l : if m.count(j)!=0 : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var l : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var m : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var cnt : int := 0 ; for j : l do ( if m->count(j) /= 0 then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) t,=R() exec(t*'R();print(len({*R()}&{*R()}));') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := R->apply() ; (expr (expr (atom (name t))) * (expr (atom 'R();print(len({*R()}&{*R()}));'))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=input().split(" ") a=int(i[0]) b=int(i[1]) c=int(i[2]) d=int(i[3]) negneg=a*c negpos=a*d posneg=b*c pospos=b*d print(max([negneg,negpos,posneg,pospos])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : OclAny := input().split(" ") ; var a : int := ("" + ((i->first())))->toInteger() ; var b : int := ("" + ((i[1+1])))->toInteger() ; var c : int := ("" + ((i[2+1])))->toInteger() ; var d : int := ("" + ((i[3+1])))->toInteger() ; var negneg : int := a * c ; var negpos : int := a * d ; var posneg : int := b * c ; var pospos : int := b * d ; execute ((Sequence{negneg}->union(Sequence{negpos}->union(Sequence{posneg}->union(Sequence{ pospos }))))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): input() inp1,inp2=list(map(int,input().split())),list(map(int,input().split())) print(len(inp1)+len(inp2)-len(set(inp1+inp2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( input() ; var inp1 : OclAny := null; var inp2 : OclAny := null; Sequence{inp1,inp2} := Sequence{((input().split())->collect( _x | (OclType["int"])->apply(_x) )),((input().split())->collect( _x | (OclType["int"])->apply(_x) ))} ; execute ((inp1)->size() + (inp2)->size() - (Set{}->union((inp1 + inp2)))->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() freq=dict() for ele in s : if(ele not in freq): freq[ele]=1 else : freq[ele]+=1 c=0 for v in freq.values(): if(v % 2==1): c+=1 if(c==0): print("First") elif(c % 2==1): print("First") else : print("Second") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var freq : Map := (arguments ( )) ; for ele : s->characters() do ( if ((freq)->excludes(ele)) then ( freq[ele+1] := 1 ) else ( freq[ele+1] := freq[ele+1] + 1 )) ; var c : int := 0 ; for v : freq.values() do ( if (v mod 2 = 1) then ( c := c + 1 ) else skip) ; if (c = 0) then ( execute ("First")->display() ) else (if (c mod 2 = 1) then ( execute ("First")->display() ) else ( execute ("Second")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ask=int(input()) for i in range(ask): list=[] canceled=0 a,b=input().split() c=input().split() d=input().split() for k in c : list.append(k) for u in d : if u in list : canceled+=1 else : list.append(u) print(canceled) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ask : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, ask-1) do ( var OclType["Sequence"] : Sequence := Sequence{} ; var canceled : int := 0 ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; var c : OclAny := input().split() ; var d : OclAny := input().split() ; for k : c do ( execute ((k) : OclType["Sequence"])) ; for u : d do ( if (OclType["Sequence"])->includes(u) then ( canceled := canceled + 1 ) else ( execute ((u) : OclType["Sequence"]) )) ; execute (canceled)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def totalPrimeFactors(n): count=0 ; if((n % 2)==0): count+=1 ; while((n % 2)==0): n//=2 ; i=3 ; while(i*i<=n): if((n % i)==0): count+=1 ; while((n % i)==0): n//=i ; i+=2 ; if(n>2): count+=1 ; return count ; def countPairs(G,L): if(L % G!=0): return 0 ; div=int(L/G); return(1<display(); ; execute ("=")->display();; operation totalPrimeFactors(n : OclAny) pre: true post: true activity: var count : int := 0; ; if ((n mod 2) = 0) then ( count := count + 1; ; while ((n mod 2) = 0) do ( n := n div 2;) ) else skip ; var i : int := 3; ; while ((i * i->compareTo(n)) <= 0) do ( if ((n mod i) = 0) then ( count := count + 1; ; while ((n mod i) = 0) do ( n := n div i;) ) else skip ; i := i + 2;) ; if (n > 2) then ( count := count + 1; ) else skip ; return count;; operation countPairs(G : OclAny, L : OclAny) pre: true post: true activity: if (L mod G /= 0) then ( return 0; ) else skip ; var div : int := ("" + ((L / G)))->toInteger(); ; return (1 * (2->pow(totalPrimeFactors(div))));; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculate_sum(a,N): m=N/a sum=m*(m+1)/2 ans=a*sum print("Sum of multiples of ",a," up to ",N,"=",ans) calculate_sum(7,49) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; calculate_sum(7, 49); operation calculate_sum(a : OclAny, N : OclAny) pre: true post: true activity: var m : double := N / a ; var sum : double := m * (m + 1) / 2 ; var ans : double := a * sum ; execute ("Sum of multiples of ")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : line=input().split() n,m,k=int(line[0]),int(line[1]),int(line[2][2 :]) skills={} for _ in range(n): line=input().split() skills[line[0]]=int(line[1]) new_skills=[input()for _ in range(m)] count=0 delete=[] for key,value in skills.items(): value=int(k*value/100) if value<100 : delete.append(key) else : skills[key]=value count+=1 for key in delete : del skills[key] for skill in new_skills : if skill not in skills.keys(): skills[skill]=0 count+=1 skills=dict(sorted(skills.items())) print(count) for key,value in skills.items(): print(key,value,sep=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var line : OclAny := input().split() ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := Sequence{("" + ((line->first())))->toInteger(),("" + ((line[1+1])))->toInteger(),("" + ((line[2+1].subrange(2+1))))->toInteger()} ; var skills : OclAny := Set{} ; for _anon : Integer.subrange(0, n-1) do ( line := input().split() ; skills[line->first()+1] := ("" + ((line[1+1])))->toInteger()) ; var new_skills : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var count : int := 0 ; var delete : Sequence := Sequence{} ; for _tuple : skills->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); var value : int := ("" + ((k * value / 100)))->toInteger() ; if value < 100 then ( execute ((key) : delete) ) else ( skills[key+1] := value ; count := count + 1 )) ; for key : delete do ( execute (skills[key+1])->isDeleted()) ; for skill : new_skills do ( if (skills.keys())->excludes(skill) then ( skills[skill+1] := 0 ; count := count + 1 ) else skip) ; skills := ((expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name skills)) (trailer . (name items) (arguments ( ))))))))) ))))) ; execute (count)->display() ; for _tuple : skills->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); execute (key)->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input().split() n,m,k=int(a[0]),int(a[1]),int(a[2].split('.')[1]) b={} for _ in range(n): a=input().split() c=int(a[1])*k/100 if c>=100 : b[a[0]]=c for _ in range(m): d=input() if not(d in b): b[d]=0 print(len(b)) for e in sorted(b): print(e,int(b[e])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := input().split() ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := Sequence{("" + ((a->first())))->toInteger(),("" + ((a[1+1])))->toInteger(),("" + ((a[2+1].split('.')[1+1])))->toInteger()} ; var b : OclAny := Set{} ; for _anon : Integer.subrange(0, n-1) do ( a := input().split() ; var c : double := ("" + ((a[1+1])))->toInteger() * k / 100 ; if c >= 100 then ( b[a->first()+1] := c ) else skip) ; for _anon : Integer.subrange(0, m-1) do ( var d : String := (OclFile["System.in"]).readLine() ; if not(((b)->includes(d))) then ( b->at(d) := 0 ) else skip) ; execute ((b)->size())->display() ; for e : b->sort() do ( execute (e)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- first_line=input().split() n,m,k=int(first_line[0]),int(first_line[1]),int(first_line[2].split('.')[1]) b={} for i in range(n): old_skill=input().split() c=int(old_skill[1])*k/100 if c>=100 : b[old_skill[0]]=c for i in range(m): d=input() if not(d in b): b[d]=0 print(len(b)) for i in sorted(b): print(i,int(b[i])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var first_line : OclAny := input().split() ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := Sequence{("" + ((first_line->first())))->toInteger(),("" + ((first_line[1+1])))->toInteger(),("" + ((first_line[2+1].split('.')[1+1])))->toInteger()} ; var b : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var old_skill : OclAny := input().split() ; var c : double := ("" + ((old_skill[1+1])))->toInteger() * k / 100 ; if c >= 100 then ( b[old_skill->first()+1] := c ) else skip) ; for i : Integer.subrange(0, m-1) do ( var d : String := (OclFile["System.in"]).readLine() ; if not(((b)->includes(d))) then ( b->at(d) := 0 ) else skip) ; execute ((b)->size())->display() ; for i : b->sort() do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(float,input().split()) n,m,k=round(n),round(m),round(k*100) dic1={} for i in range(n): key1,value1=input().split() value1=int(value1)*k/100 if value1>=100 : dic1[key1]=value1 for j in range(m): key2=input() if key2 not in dic1.keys(): dic1[key2]=0 print(len(dic1)) for x in sorted(dic1): print(x,int(dic1[x])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := Sequence{(n)->round(),(m)->round(),(k * 100)->round()} ; var dic1 : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var key1 : OclAny := null; var value1 : OclAny := null; Sequence{key1,value1} := input().split() ; var value1 : double := ("" + ((value1)))->toInteger() * k / 100 ; if value1 >= 100 then ( dic1[key1+1] := value1 ) else skip) ; for j : Integer.subrange(0, m-1) do ( var key2 : String := (OclFile["System.in"]).readLine() ; if (dic1.keys())->excludes(key2) then ( dic1->at(key2) := 0 ) else skip) ; execute ((dic1)->size())->display() ; for x : dic1->sort() do ( execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import floor from decimal import Decimal inputString=input().split() n=int(inputString[0]) m=int(inputString[1]) k=Decimal(inputString[2]) skills=[] tracked=[] for _ in range(0,m+n): skill=input().split(" ") if len(skill)==2 : skill[1]=int(skill[1]) level=floor(skill[1]*k) if level>=100 : skills.append({"name" : skill[0],"level" : level}) tracked.append(skill[0]) else : if skill[0]not in tracked : skills.append({"name" : skill[0],"level" : 0}) skills=sorted(skills,key=lambda x : x["name"],reverse=False) print(len(skills)) for skill in skills : print(skill["name"]+" "+str(skill["level"])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var inputString : OclAny := input().split() ; var n : int := ("" + ((inputString->first())))->toInteger() ; var m : int := ("" + ((inputString[1+1])))->toInteger() ; var k : OclAny := Decimal(inputString[2+1]) ; var skills : Sequence := Sequence{} ; var tracked : Sequence := Sequence{} ; for _anon : Integer.subrange(0, m + n-1) do ( var skill : OclAny := input().split(" ") ; if (skill)->size() = 2 then ( skill[1+1] := ("" + ((skill[1+1])))->toInteger() ; var level : OclAny := floor(skill[1+1] * k) ; if level >= 100 then ( execute ((Map{ "name" |-> skill->first() }->union(Map{ "level" |-> level })) : skills) ; execute ((skill->first()) : tracked) ) else skip ) else ( if (tracked)->excludes(skill->first()) then ( execute ((Map{ "name" |-> skill->first() }->union(Map{ "level" |-> 0 })) : skills) ) else skip )) ; skills := skills->sortedBy($x | (lambda x : OclAny in (x->at("name")))->apply($x)) ; execute ((skills)->size())->display() ; for skill : skills do ( execute (skill->at("name") + " " + ("" + ((skill->at("level")))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSolutions(a): count=0 for i in range(a+1): if(a==(i+(a ^ i))): count+=1 return count if __name__=="__main__" : a=3 print(countSolutions(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := 3 ; execute (countSolutions(a))->display() ) else skip; operation countSolutions(a : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, a + 1-1) do ( if (a = (i + (MathLib.bitwiseXor(a, i)))) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict from sys import stdin input=stdin.buffer.readline def func(): indices=defaultdict(list) ans=0 for i in range(n): indices[a[i]].append(i) for i in indices : if len(indices[i])<2 : continue for j in range(len(indices[i])-1): first=indices[i][j] second=indices[i][j+1] ans=max(ans,n-second+first) print(ans if ans else-1) for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) func() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.buffer.readline ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; func()); operation func() pre: true post: true activity: var indices : OclAny := defaultdict(OclType["Sequence"]) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ((expr (atom (name indices)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; for i : indices do ( if (indices[i+1])->size() < 2 then ( continue ) else skip ; for j : Integer.subrange(0, (indices[i+1])->size() - 1-1) do ( var first : OclAny := indices[i+1][j+1] ; var second : OclAny := indices[i+1][j + 1+1] ; ans := Set{ans, n - second + first}->max())) ; execute (if ans then ans else -1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): s=input() def cnt_odds(s): odds=0 cnt={} for x in s : if x not in cnt : cnt[x]=0 cnt[x]+=1 for x in cnt.values(): if x % 2>0 : odds+=1 return odds winners=['First','Second'] i=0 while True : odds=cnt_odds(s) if odds<=1 : print(winners[i % 2]) break for j in range(len(s)): substr=s[0 : j]+s[j+1 :] new_odds=cnt_odds(substr) if new_oddsunion(Sequence{ 'Second' }) ; var i : int := 0 ; while true do ( odds := cnt_odds(s) ; if odds <= 1 then ( execute (winners[i mod 2+1])->display() ; break ) else skip ; for j : Integer.subrange(0, (s)->size()-1) do ( var substr : OclAny := s.subrange(0+1, j) + s.subrange(j + 1+1) ; var new_odds : OclAny := cnt_odds(substr) ; if (new_odds->compareTo(odds)) < 0 then ( s := substr ; break ) else skip) ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,m=list(map(int,input().split())) a=list(map(int,input().split())) s=0 if sum(a)==m : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : int := 0 ; if (a)->sum() = m then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def next(arr,target): start=0 ; end=len(arr)-1 ; ans=-1 ; while(start<=end): mid=(start+end)//2 ; if(arr[mid]<=target): start=mid+1 ; else : ans=mid ; end=mid-1 ; return ans ; if __name__=='__main__' : arr=[1,2,3,5,8,12]; print(next(arr,8)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{8}->union(Sequence{ 12 }))))); ; execute ((arr, 8).next())->display(); ) else skip; operation next(arr : OclAny, target : OclAny) pre: true post: true activity: var start : int := 0; ; var end : double := (arr)->size() - 1; ; var ans : int := -1; ; while ((start->compareTo(end)) <= 0) do ( var mid : int := (start + end) div 2; ; if ((arr[mid+1]->compareTo(target)) <= 0) then ( start := mid + 1; ) else ( ans := mid; ; end := mid - 1; )) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- word=["zero","one","two","three","four","five","six","seven","eight","nine"] def printWordsWithoutIfSwitch(n): digits=[0 for i in range(10)] dc=0 while True : digits[dc]=n % 10 n=n//10 dc+=1 if(n==0): break for i in range(dc-1,-1,-1): print(word[digits[i]],end=" ") n=350 printWordsWithoutIfSwitch(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var word : Sequence := Sequence{"zero"}->union(Sequence{"one"}->union(Sequence{"two"}->union(Sequence{"three"}->union(Sequence{"four"}->union(Sequence{"five"}->union(Sequence{"six"}->union(Sequence{"seven"}->union(Sequence{"eight"}->union(Sequence{ "nine" }))))))))) ; skip ; n := 350 ; printWordsWithoutIfSwitch(n); operation printWordsWithoutIfSwitch(n : OclAny) pre: true post: true activity: var digits : Sequence := Integer.subrange(0, 10-1)->select(i | true)->collect(i | (0)) ; var dc : int := 0 ; while true do ( digits[dc+1] := n mod 10 ; n := n div 10 ; dc := dc + 1 ; if (n = 0) then ( break ) else skip) ; for i : Integer.subrange(-1 + 1, dc - 1)->reverse() do ( execute (word[digits[i+1]+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout int_in=lambda : int(stdin.readline()) arr_in=lambda :[int(x)for x in stdin.readline().split()] mat_in=lambda rows :[arr_in()for _ in range(rows)] str_in=lambda : stdin.readline().strip() out=lambda o : stdout.write("{}\n".format(o)) arr_out=lambda o : out(" ".join(map(str,o))) bool_out=lambda o : out("YES" if o else "NO") tests=lambda : range(1,int_in()+1) case_out=lambda i,o : out("Case #{}:{}".format(i,o)) def solve(n,k,m,a): sa=sorted(a) prefix_sum=[0] for i in range(n): prefix_sum.append(sa[i]+prefix_sum[-1]) best=0 for i in range(min(n,m+1)): total_power=prefix_sum[n]-prefix_sum[i] remaining_heros=len(sa)-i max_that_can_be_added=min(m-i,remaining_heros*k) best=max(best,(total_power+max_that_can_be_added)/remaining_heros) return best if __name__=="__main__" : n,k,m=arr_in() a=arr_in() out(solve(n,k,m,a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var int_in : Function := lambda $$ : OclAny in (("" + ((stdin.readLine())))->toInteger()) ; var arr_in : Function := lambda $$ : OclAny in (stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) ; var mat_in : Function := lambda rows : OclAny in (Integer.subrange(0, rows-1)->select(_anon | true)->collect(_anon | (arr_in->apply()))) ; var str_in : Function := lambda $$ : OclAny in (stdin.readLine()->trim()) ; var out : Function := lambda o : OclAny in (stdout.write(StringLib.interpolateStrings("{}\n", Sequence{o}))) ; var arr_out : Function := lambda o : OclAny in (out->apply(StringLib.sumStringsWithSeparator(((o)->collect( _x | (OclType["String"])->apply(_x) )), " "))) ; var bool_out : Function := lambda o : OclAny in (out->apply(if o then "YES" else "NO" endif)) ; var tests : Function := lambda $$ : OclAny in (Integer.subrange(1, int_in->apply() + 1-1)) ; var case_out : Function := lambda i : OclAny, o : OclAny in (out->apply(StringLib.interpolateStrings("Case #{}:{}", Sequence{i, o}))) ; skip ; if __name__ = "__main__" then ( Sequence{n,k,m} := arr_in->apply() ; a := arr_in->apply() ; out(solve(n, k, m, a)) ) else skip; operation solve(n : OclAny, k : OclAny, m : OclAny, a : OclAny) : OclAny pre: true post: true activity: var sa : Sequence := a->sort() ; var prefix_sum : Sequence := Sequence{ 0 } ; for i : Integer.subrange(0, n-1) do ( execute ((sa[i+1] + prefix_sum->last()) : prefix_sum)) ; var best : int := 0 ; for i : Integer.subrange(0, Set{n, m + 1}->min()-1) do ( var total_power : double := prefix_sum[n+1] - prefix_sum[i+1] ; var remaining_heros : double := (sa)->size() - i ; var max_that_can_be_added : OclAny := Set{m - i, remaining_heros * k}->min() ; best := Set{best, (total_power + max_that_can_be_added) / remaining_heros}->max()) ; return best; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,k,m=list(map(int,input().split())) sup=list(map(int,input().split())) sum_s=sum(sup) n=N sup.sort() max_s=(sum_s+min(m,n*k))/n for i in range(min(N-1,m)): sum_s-=sup[i] n-=1 m-=1 max_n=(sum_s+min(m,n*k))/n if max_n>max_s : max_s=max_n print(max_s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var k : OclAny := null; var m : OclAny := null; Sequence{N,k,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sup : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sum_s : OclAny := (sup)->sum() ; var n : OclAny := N ; sup := sup->sort() ; var max_s : double := (sum_s + Set{m, n * k}->min()) / n ; for i : Integer.subrange(0, Set{N - 1, m}->min()-1) do ( sum_s := sum_s - sup[i+1] ; n := n - 1 ; m := m - 1 ; var max_n : double := (sum_s + Set{m, n * k}->min()) / n ; if (max_n->compareTo(max_s)) > 0 then ( max_s := max_n ) else skip) ; execute (max_s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main()->None : n,k,m=map(int,input().split()) a=[int(x)for x in input().split()] a.sort() total_sum=sum(a) best_sum=total_sum+min(m,n*k) best_n=n for i in range(min(n,m)): total_sum-=a[i] new_sum=total_sum+min(m-i-1,(n-i-1)*k) if new_sum*best_n-best_sum*(n-i-1)>0 : best_sum=new_sum best_n=n-i-1 print(best_sum/best_n) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() : OclAny pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var m : OclAny := null; Sequence{n,k,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; a := a->sort() ; var total_sum : OclAny := (a)->sum() ; var best_sum : OclAny := total_sum + Set{m, n * k}->min() ; var best_n : OclAny := n ; for i : Integer.subrange(0, Set{n, m}->min()-1) do ( total_sum := total_sum - a[i+1] ; var new_sum : OclAny := total_sum + Set{m - i - 1, (n - i - 1) * k}->min() ; if new_sum * best_n - best_sum * (n - i - 1) > 0 then ( best_sum := new_sum ; best_n := n - i - 1 ) else skip) ; execute (best_sum / best_n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from heapq import heapify,heappush,heappop t=1 for _ in range(t): n,k,m=map(int,input().split()) a=list(map(int,input().split())) s=sum(a) ss=0 a.sort() ans=0 for i in range(min(n-1,m)+1): z=min(k*(n-i),(m-i)) ans=max(ans,(s-ss+z)/(n-i)) ss+=a[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; var m : OclAny := null; Sequence{n,k,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : OclAny := (a)->sum() ; var ss : int := 0 ; a := a->sort() ; var ans : int := 0 ; for i : Integer.subrange(0, Set{n - 1, m}->min() + 1-1) do ( var z : OclAny := Set{k * (n - i), (m - i)}->min() ; ans := Set{ans, (s - ss + z) / (n - i)}->max() ; ss := ss + a[i+1]) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def _i(): return int(sys.stdin.readline().strip()) def _ia(): return map(int,sys.stdin.readline().strip().split()) def main(): n,m=_ia() h=list(_ia()) adj=[[]for _ in range(n)] for _ in range(m): a,b=_ia() adj[a-1].append(b-1) adj[b-1].append(a-1) ans=0 for i in range(n): hi=h[i] f=True for j in adj[i]: hj=h[j] if hi<=hj : f=False break if f : ans+=1 return ans if __name__=="__main__" : print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( execute (main())->display() ) else skip; operation _i() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.readLine()->trim())))->toInteger(); operation _ia() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ); operation main() : OclAny pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := _ia() ; var h : Sequence := (_ia()) ; var adj : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := _ia() ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ))))) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var hi : OclAny := h[i+1] ; var f : boolean := true ; for j : adj[i+1] do ( var hj : OclAny := h[j+1] ; if (hi->compareTo(hj)) <= 0 then ( f := false ; break ) else skip) ; if f then ( ans := ans + 1 ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict n,m=map(int,input().split()) h=list(map(int,input().split())) c=defaultdict(list) for i in range(m): a,b=map(int,input().split()) c[a].append(b) c[b].append(a) cnt=n for k,v in c.items(): for i in range(len(v)): if h[v[i]-1]>=h[k-1]: cnt-=1 break print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : OclAny := defaultdict(OclType["Sequence"]) ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var cnt : OclAny := n ; for _tuple : c->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); for i : Integer.subrange(0, (v)->size()-1) do ( if (h[v[i+1] - 1+1]->compareTo(h[k - 1+1])) >= 0 then ( cnt := cnt - 1 ; break ) else skip)) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (n,m)=[int(x)for x in input().split()] p=[x for x in range(1,n+1)] h=[int(x)for x in input().split()] hp=dict(zip(p,h)) path={i :[]for i in range(1,n+1)} for i in range(m): (a,b)=[int(x)for x in input().split()] path[a].append(b) path[b].append(a) c=0 for i,v in path.items(): f=0 for j in v : if hp[i]<=hp[j]: f=1 break if f==0 : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{n, m} : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var p : Sequence := Integer.subrange(1, n + 1-1)->select(x | true)->collect(x | (x)) ; var h : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var hp : Map := ((expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p))))))) , (argument (test (logical_test (comparison (expr (atom (name h)))))))) ))))) ; var path : Map := Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | Map{i |-> Sequence{}})->unionAll() ; for i : Integer.subrange(0, m-1) do ( ; var Sequence{a, b} : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; (expr (atom (name path)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name path)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var c : int := 0 ; for _tuple : path->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); var f : int := 0 ; for j : v do ( if (hp[i+1]->compareTo(hp[j+1])) <= 0 then ( f := 1 ; break ) else skip) ; if f = 0 then ( c := c + 1 ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=sorted(input()) count=[1] n=0 for i in range(1,len(s)): if s[i]!=s[i-1]: count.append(1) else : count[-1]+=1 for i in count : if i % 2==1 : n+=1 if n>1 : if n % 2==0 : print("Second") else : print("First") else : print('First') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := (OclFile["System.in"]).readLine()->sort() ; var count : Sequence := Sequence{ 1 } ; var n : int := 0 ; for i : Integer.subrange(1, (s)->size()-1) do ( if s[i+1] /= s[i - 1+1] then ( execute ((1) : count) ) else ( count->last() := count->last() + 1 )) ; for i : count do ( if i mod 2 = 1 then ( n := n + 1 ) else skip) ; if n > 1 then ( if n mod 2 = 0 then ( execute ("Second")->display() ) else ( execute ("First")->display() ) ) else ( execute ('First')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline sys.setrecursionlimit(2*10**6) def inpl(): return list(map(int,input().split())) def main(): N,M=inpl() H=inpl() AB=[inpl()for _ in range(M)] ans=[True]*(N+1) ans[0]=False for a,b in AB : if H[a-1]H[b-1]: ans[b]=False else : ans[a]=False ans[b]=False print(ans.count(True)) return if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit(2 * (10)->pow(6)) ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation main() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := inpl() ; var H : OclAny := inpl() ; var AB : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (inpl())) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (N + 1)) ; ans->first() := false ; for _tuple : AB do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if (H[a - 1+1]->compareTo(H[b - 1+1])) < 0 then ( ans[a+1] := false ) else (if (H[a - 1+1]->compareTo(H[b - 1+1])) > 0 then ( ans[b+1] := false ) else ( ans[a+1] := false ; ans[b+1] := false ) ) ) ; execute (ans->count(true))->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) t,=R() for _ in[0]*t : n,m=R(); print('YNEOS'[sum(R())!=m : : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := R->apply() ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, t) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := R->apply(); execute ('YNEOS'(subscript (test (logical_test (comparison (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name R)) (trailer (arguments ( ))))))))) ))))) != (comparison (expr (atom (name m))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy n,m=map(int,input().split()) h=list(map(int,input().split())) l=[] for i in range(m): a,b=map(int,input().split()) l.append([a,b]) ll=[0]*n for j in l : if h[j[0]-1]>h[j[1]-1]: ll[j[1]-1]+=1 elif h[j[0]-1]==h[j[1]-1]: ll[j[1]-1]+=1 ll[j[0]-1]+=1 else : ll[j[0]-1]+=1 ans=0 for k in ll : if k==0 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a}->union(Sequence{ b })) : l)) ; var ll : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for j : l do ( if (h[j->first() - 1+1]->compareTo(h[j[1+1] - 1+1])) > 0 then ( ll[j[1+1] - 1+1] := ll[j[1+1] - 1+1] + 1 ) else (if h[j->first() - 1+1] = h[j[1+1] - 1+1] then ( ll[j[1+1] - 1+1] := ll[j[1+1] - 1+1] + 1 ; ll[j->first() - 1+1] := ll[j->first() - 1+1] + 1 ) else ( ll[j->first() - 1+1] := ll[j->first() - 1+1] + 1 ) ) ) ; var ans : int := 0 ; for k : ll do ( if k = 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(a,b): l=len(a) min=0 max=0 for i in range(l): if(a[i]=='+' or b[i]=='+' or a[i]!=b[i]): max+=1 if(a[i]!='+' and b[i]!='+' and a[i]!=b[i]): min+=1 print(min+max) if __name__=='__main__' : s1="a+c" s2="++b" solve(s1,s2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var s1 : String := "a+c" ; var s2 : String := "++b" ; solve(s1, s2) ) else skip; operation solve(a : OclAny, b : OclAny) pre: true post: true activity: var l : int := (a)->size() ; var min : int := 0 ; var max : int := 0 ; for i : Integer.subrange(0, l-1) do ( if (a[i+1] = '+' or b[i+1] = '+' or a[i+1] /= b[i+1]) then ( max := max + 1 ) else skip ; if (a[i+1] /= '+' & b[i+1] /= '+' & a[i+1] /= b[i+1]) then ( min := min + 1 ) else skip) ; execute (min + max)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def TotalWays(n,s,k): dp=[0]*n dp[s-1]=1 for i in range(s,n): idx=max(s-1,i-k) for j in range(idx,i): dp[i]+=dp[j] return dp[n-1] if __name__=="__main__" : n=5 k=2 s=2 print("Total Ways=",TotalWays(n,s,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 5 ; k := 2 ; s := 2 ; execute ("Total Ways=")->display() ) else skip; operation TotalWays(n : OclAny, s : OclAny, k : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; dp[s - 1+1] := 1 ; for i : Integer.subrange(s, n-1) do ( var idx : OclAny := Set{s - 1, i - k}->max() ; for j : Integer.subrange(idx, i-1) do ( dp[i+1] := dp[i+1] + dp[j+1])) ; return dp[n - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countEvenOdd(n): even_count=0 odd_count=0 while(n>0): rem=n % 10 if(rem % 2==0): even_count+=1 else : odd_count+=1 n=int(n/10) print("Even count : ",even_count) print("\nOdd count : ",odd_count) if(even_count % 2==0 and odd_count % 2!=0): return 1 else : return 0 n=2335453 ; t=countEvenOdd(n); if(t==1): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 2335453; ; var t : OclAny := countEvenOdd(n); ; if (t = 1) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); operation countEvenOdd(n : OclAny) : OclAny pre: true post: true activity: var even_count : int := 0 ; var odd_count : int := 0 ; while (n > 0) do ( var rem : int := n mod 10 ; if (rem mod 2 = 0) then ( even_count := even_count + 1 ) else ( odd_count := odd_count + 1 ) ; n := ("" + ((n / 10)))->toInteger()) ; execute ("Even count : ")->display() ; execute ("\nOdd count : ")->display() ; if (even_count mod 2 = 0 & odd_count mod 2 /= 0) then ( return 1 ) else ( return 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate n,k=map(int,input().split()) books=[[]for _ in range(10)] while n : c,g=map(int,input().split()) books[g-1].append(c) n-=1 books_acc=[[0]+list(accumulate(c+i*2 for i,c in enumerate(sorted(q,reverse=True))))for q in books] def memoize(f): memo=[[-1]*(k+1)for _ in range(10)] def main(x,y): if x>9 : return 0 result=memo[x][y] if result<0 : result=memo[x][y]=f(x,y) return result return main @ memoize def combi(g,remain): book_acc=list(books_acc[g]) salable=min(remain+1,len(book_acc)) return max([book_acc[i]+combi(g+1,remain-i)for i in range(salable)],default=0) print(combi(0,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var books : Sequence := Integer.subrange(0, 10-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; while n do ( var c : OclAny := null; var g : OclAny := null; Sequence{c,g} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name books)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name g))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))) ; n := n - 1) ; var books_acc : Sequence := books->select(q | true)->collect(q | (Sequence{ 0 }->union((accumulate((argument (test (logical_test (comparison (expr (expr (atom (name c))) + (expr (expr (atom (name i))) * (expr (atom (number (integer 2))))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name q))))))) , (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ))))))))) ))))))))))))) ; skip ; (compound_stmt (decorator @ (dotted_name (name memoize))) (funcdef def (name combi) ( (typedargslist (def_parameters (def_parameter (named_parameter (name g))) , (def_parameter (named_parameter (name remain))))) ) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name book_acc)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name books_acc)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name g)))))))) ])))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name salable)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name remain))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name book_acc)))))))) ))))))))) ))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name book_acc)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name combi)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name g))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name remain))) - (expr (atom (name i))))))))) )))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name salable)))))))) )))))))) ])))))) , (argument (test (logical_test (comparison (expr (atom (name default)))))) = (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))))))))))))) ; execute (combi(0, k))->display(); operation memoize(f : OclAny) : OclAny pre: true post: true activity: var memo : Sequence := Integer.subrange(0, 10-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ -1 }, (k + 1)))) ; skip ; return main; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heappush as push from heapq import heappop as pop def solve(): n,k=map(int,input().split()) group_num=10 book_map=[[]for i in range(group_num)] acc_map=[[0]for i in range(group_num)] for i in range(n): c,g=map(int,input().split()) push(book_map[g-1],-c) for i in range(group_num): bmi=book_map[i] append=acc_map[i].append acc=0 for j in range(len(bmi)): acc+=(pop(bmi)-j*2) append(acc) dp=[[0]*(k+1)for i in range(group_num+1)] for y in range(1,k+1): for x in range(1,group_num+1): mp=acc_map[x-1] be=dp[x-1] for z in range(min(y+1,len(mp))): v1=be[y-z] v2=mp[z] if dp[x][y]>v1+v2 : dp[x][y]=v1+v2 print(-dp[group_num][k]) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; solve(); operation solve() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var group_num : int := 10 ; var book_map : Sequence := Integer.subrange(0, group_num-1)->select(i | true)->collect(i | (Sequence{})) ; var acc_map : Sequence := Integer.subrange(0, group_num-1)->select(i | true)->collect(i | (Sequence{ 0 })) ; for i : Integer.subrange(0, n-1) do ( var c : OclAny := null; var g : OclAny := null; Sequence{c,g} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; push(book_map[g - 1+1], -c)) ; for i : Integer.subrange(0, group_num-1) do ( var bmi : OclAny := book_map[i+1] ; var append : OclAny := acc_map[i+1].append ; var acc : int := 0 ; for j : Integer.subrange(0, (bmi)->size()-1) do ( acc := acc + (pop(bmi) - j * 2) ; append(acc))) ; var dp : Sequence := Integer.subrange(0, group_num + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (k + 1)))) ; for y : Integer.subrange(1, k + 1-1) do ( for x : Integer.subrange(1, group_num + 1-1) do ( var mp : OclAny := acc_map[x - 1+1] ; var be : OclAny := dp[x - 1+1] ; for z : Integer.subrange(0, Set{y + 1, (mp)->size()}->min()-1) do ( var v1 : OclAny := be[y - z+1] ; var v2 : OclAny := mp[z+1] ; if (dp[x+1][y+1]->compareTo(v1 + v2)) > 0 then ( dp[x+1][y+1] := v1 + v2 ) else skip))) ; execute (-dp[group_num+1][k+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): import sys input=sys.stdin.readline n,k=map(int,input().split()) ab=[list(map(int,input().split()))for _ in[0]*n] g=[[]for _ in[0]*10] [g[b-1].append(a)for a,b in ab] [g[c].sort(reverse=True)for c in range(10)] for c in range(10): g[c]=[0]+g[c] for c in range(10): for i in range(2,len(g[c])): g[c][i]+=g[c][i-1]+2*(i-1) dp=[0]*(k+1) for c in range(10): dp2=[0]*(k+1) for i in range(len(g[c])): for j in range(k+1-i): dp2[i+j]=max(dp2[i+j],dp[j]+g[c][i]) dp=dp2 print(max(dp)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; ; ; operation main() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ab : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var g : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10)->select(_anon | true)->collect(_anon | (Sequence{})); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): N,K=map(int,input().split()) a=[[]for _ in[0]*10] l=[] for c,g in(tuple(map(int,input().split()))for _ in[0]*N): a[g-1].append(c) for i,prices in enumerate(a): ln=len(prices) if ln==0 : continue dp=[0]*(K+1) for j,price in enumerate(prices): _k=j if jcur : dp[k+1]=prev+price+k*2 l.append(dp[1 : ln+1]) dp=[float("-inf")]*(K+1) dp[0]=0 for prices in l : cdp=dp[:] for i,price in enumerate(prices,start=1): if i>K : break for j,cur,prev in zip(range(K,-1,-1),cdp[: :-1],dp[K-i : :-1]): if 0cur : cdp[j]=prev+price dp=cdp print(max(dp)) if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( solve() ) else skip; operation solve() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10)->select(_anon | true)->collect(_anon | (Sequence{})) ; var l : Sequence := Sequence{} ; for _tuple : Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name tuple)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr (atom (name N))))))))} do (var _indx : int := 1; var c : OclAny := _tuple->at(_indx); _indx := _indx + 1; var g : OclAny := _tuple->at(_indx); (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name g))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))) ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var prices : OclAny := _tuple->at(_indx); var ln : int := (prices)->size() ; if ln = 0 then ( continue ) else skip ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (K + 1)) ; for _tuple : Integer.subrange(1, (prices)->size())->collect( _indx | Sequence{_indx-1, (prices)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var price : OclAny := _tuple->at(_indx); var _k : OclAny := if (j->compareTo(K - 1)) < 0 then j else K - 1 endif ; for _tuple : Integer.subrange(1, Integer.subrange(-1 + 1, _k)->reverse()->size())->collect( _indx | Sequence{Integer.subrange(-1 + 1, _k)->reverse()->at(_indx), dp(subscript (test (logical_test (comparison (expr (atom (name _k)))))) : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->at(_indx)} ) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var prev : OclAny := _tuple->at(_indx); _indx := _indx + 1; var cur : OclAny := _tuple->at(_indx); if (prev + price + k * 2->compareTo(cur)) > 0 then ( dp[k + 1+1] := prev + price + k * 2 ) else skip)) ; execute ((dp.subrange(1+1, ln + 1)) : l)) ; dp := MatrixLib.elementwiseMult(Sequence{ ("" + (("-inf")))->toReal() }, (K + 1)) ; dp->first() := 0 ; for prices : l do ( var cdp : Sequence := dp ; for _tuple : Integer.subrange(1, (prices, (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->size())->collect( _indx | Sequence{_indx-1, (prices, (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var price : OclAny := _tuple->at(_indx); if (i->compareTo(K)) > 0 then ( break ) else skip ; for _tuple : Integer.subrange(1, Integer.subrange(-1 + 1, K)->reverse()->size())->collect( _indx | Sequence{Integer.subrange(-1 + 1, K)->reverse()->at(_indx), cdp(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var cur : OclAny := _tuple->at(_indx); _indx := _indx + 1; var prev : OclAny := _tuple->at(_indx); if 0 < prev + price & (prev + price > cur) then ( cdp[j+1] := prev + price ) else skip)) ; dp := cdp) ; execute ((dp)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- PHI=1.6180339 f=[0,1,1,2,3,5] def fib(n): if n<6 : return f[n] t=5 fn=5 while tcollect( _x | (OclType["int"])->apply(_x) ) ; var G : Sequence := Integer.subrange(0, 10-1)->select(i | true)->collect(i | (Sequence{})) ; for line : file_input do ( var c : OclAny := null; var g : OclAny := null; Sequence{c,g} := (line.split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name g))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))) ; for genre : G do ( genre := genre->sort() ; for _tuple : Integer.subrange(1, Integer.subrange(1, (genre)->size()-1)->size())->collect( _indx | Sequence{Integer.subrange(1, (genre)->size()-1)->at(_indx), genre->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p : OclAny := _tuple->at(_indx); genre[i+1] := genre[i+1] + p + 2 * i)) ; var C : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (K + 1)) ; for genre : G do ( var pre_C : OclAny := C->copy() ; for _tuple : Integer.subrange(1, Integer.subrange(0 + 1, (genre)->size())->reverse()->size())->collect( _indx | Sequence{Integer.subrange(0 + 1, (genre)->size())->reverse()->at(_indx), genre(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->at(_indx)} ) do (var _indx : int := 1; var n : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p : OclAny := _tuple->at(_indx); for _tuple : Integer.subrange(1, (Integer.subrange(1, pre_C.subrange(n+1)->size())->collect( _indx | Sequence{pre_C.subrange(n+1)->at(_indx), C->at(_indx)} ))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(1, pre_C.subrange(n+1)->size())->collect( _indx | Sequence{pre_C.subrange(n+1)->at(_indx), C->at(_indx)} ))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var vals : OclAny := _tuple->at(_indx); var v1 : OclAny := null; var v2 : OclAny := null; Sequence{v1,v2} := vals ; v1 := v1 + p ; if (v1->compareTo(v2)) > 0 then ( C[i+1] := v1 ) else skip))) ; execute (C->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findmin(p,n): a,b,c,d=0,0,0,0 for i in range(n): if(p[i][0]<=0): a+=1 elif(p[i][0]>=0): b+=1 if(p[i][1]>=0): c+=1 elif(p[i][1]<=0): d+=1 return min([a,b,c,d]) p=[[1,1],[2,2],[-1,-1],[-2,2]] n=len(p) print(findmin(p,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; p := Sequence{Sequence{1}->union(Sequence{ 1 })}->union(Sequence{Sequence{2}->union(Sequence{ 2 })}->union(Sequence{Sequence{-1}->union(Sequence{ -1 })}->union(Sequence{ Sequence{-2}->union(Sequence{ 2 }) }))) ; n := (p)->size() ; execute (findmin(p, n))->display(); operation findmin(p : OclAny, n : OclAny) : OclAny pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := Sequence{0,0,0,0} ; for i : Integer.subrange(0, n-1) do ( if (p[i+1]->first() <= 0) then ( a := a + 1 ) else (if (p[i+1]->first() >= 0) then ( b := b + 1 ) else skip) ; if (p[i+1][1+1] >= 0) then ( c := c + 1 ) else (if (p[i+1][1+1] <= 0) then ( d := d + 1 ) else skip)) ; return (Sequence{a}->union(Sequence{b}->union(Sequence{c}->union(Sequence{ d }))))->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): l0=[int(x)for x in input().split(" ")] l1=[int(x)for x in input().split(" ")] if sum(l1)==l0[1]: print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var l0 : Sequence := input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var l1 : Sequence := input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if (l1)->sum() = l0[1+1] then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def maxGCD(N,P): ans=1 prime_factors={} for i in range(2,int(sqrt(P)+1)): while(P % i==0): if i not in prime_factors : prime_factors[i]=0 prime_factors[i]+=1 P//=i if(P!=1): prime_factors[P]+=1 for key,value in prime_factors.items(): ans*=pow(key,value//N) return ans if __name__=="__main__" : N,P=3,24 print(maxGCD(N,P)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( Sequence{N,P} := Sequence{3,24} ; execute (maxGCD(N, P))->display() ) else skip; operation maxGCD(N : OclAny, P : OclAny) : OclAny pre: true post: true activity: var ans : int := 1 ; var prime_factors : OclAny := Set{} ; for i : Integer.subrange(2, ("" + ((sqrt(P) + 1)))->toInteger()-1) do ( while (P mod i = 0) do ( if (prime_factors)->excludes(i) then ( prime_factors[i+1] := 0 ) else skip ; prime_factors[i+1] := prime_factors[i+1] + 1 ; P := P div i)) ; if (P /= 1) then ( prime_factors[P+1] := prime_factors[P+1] + 1 ) else skip ; for _tuple : prime_factors->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); ans := ans * (key)->pow(value div N)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) k,*b=map(int,input().split()) t=sum(1<toInteger() ; var k : OclAny := null; var b : OclAny := null; Sequence{k,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name i))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name b))))))))->sum() ; for i : Integer.subrange(0, 1 * (2->pow(k))-1) do ( var tmp : int := 0 ; var rs : Sequence := Sequence{} ; for j : Integer.subrange(0, k-1) do ( if MathLib.bitwiseAnd(i, (1 * (2->pow(j)))) /= 0 then ( tmp := tmp or 1 * (2->pow(b[j+1])) ; execute ((b[j+1]) : rs) ) else skip) ; execute (("" + ((tmp))) + ":")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import lru_cache def subset(n,mask): @ lru_cache(maxsize=None) def _subset(i): if i<0 : return[(0,[])] m=mask[i] return(_subset(i-1)+[(v+(1<size() - 1); operation run() pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; mask := (input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))->tail()) ; for _tuple : subset(n, mask) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var vs : OclAny := _tuple->at(_indx); execute (StringLib.interpolateStrings("{}:{}", Sequence{i, StringLib.sumStringsWithSeparator((vs->select(v | true)->collect(v | (StringLib.interpolateStrings("{}", Sequence{v})))), "")}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import combinations if __name__=="__main__" : bit=int(input()) k,*E=map(lambda x : int(x),input().split()) for d,ans in sorted([((sum([1<toInteger() ; var k : OclAny := null; var E : OclAny := null; Sequence{k,E} := (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ) ; for _tuple : Integer.subrange(0, k + 1-1)->select(i; c : combinations(E, i) | true)->collect(i; c : combinations(E, i) | (Sequence{((c->select(cc | true)->collect(cc | (1 * (2->pow(cc)))))->sum()), StringLib.sumStringsWithSeparator(((c)->collect( _x | (OclType["String"])->apply(_x) )), ' ')}))->sort() do (var _indx : int := 1; var d : OclAny := _tuple->at(_indx); _indx := _indx + 1; var ans : OclAny := _tuple->at(_indx); if d then ( execute (StringLib.formattedString("{d}:{ans}"))->display() ) else ( execute (StringLib.formattedString("0:"))->display() )) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools n=int(input()) tlist=list(map(int,input().split())) k=tlist[0] tlist.remove(tlist[0]) if k==0 : print("0:") exit() combslist=[] for i in range(1,k+1): combs=list(itertools.combinations(tlist,i)) for comb in combs : combslist.append(comb) sumlist=[] for comb in combslist : sum=0 for c in comb : sum+=pow(2,c) sumlist.append(sum) z=zip(sumlist,combslist) z=sorted(z) sumlist,combslist=zip(*z) print("0:") for sum,comb in zip(sumlist,combslist): c_str=(' '.join(str(c)for c in comb)) print(str(sum)+": "+c_str) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var tlist : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k : OclAny := tlist->first() ; execute ((tlist->first()) /: tlist) ; if k = 0 then ( execute ("0:")->display() ; exit() ) else skip ; var combslist : Sequence := Sequence{} ; for i : Integer.subrange(1, k + 1-1) do ( var combs : Sequence := (itertools.combinations(tlist, i)) ; for comb : combs do ( execute ((comb) : combslist))) ; var sumlist : Sequence := Sequence{} ; for comb : combslist do ( var sum : int := 0 ; for c : comb do ( sum := sum + (2)->pow(c)) ; execute ((sum) : sumlist)) ; var z : Sequence := Integer.subrange(1, sumlist->size())->collect( _indx | Sequence{sumlist->at(_indx), combslist->at(_indx)} ) ; z := z->sort() ; Sequence{sumlist,combslist} := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name z)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name z)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name z)))))))`third->at(_indx)} ) ; execute ("0:")->display() ; for _tuple : Integer.subrange(1, sumlist->size())->collect( _indx | Sequence{sumlist->at(_indx), combslist->at(_indx)} ) do (var _indx : int := 1; var sum : OclAny := _tuple->at(_indx); _indx := _indx + 1; var comb : OclAny := _tuple->at(_indx); var c_str : String := (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name comb)))))))), ' ')) ; execute (("" + ((sum))) + ": " + c_str)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline write=sys.stdout.write N=int(readline()) k,*B=map(int,readline().split()) M=sum(1<toInteger() ; var k : OclAny := null; var B : OclAny := null; Sequence{k,B} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var M : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name b))))))) (comp_for for (exprlist (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name B))))))))->sum() ; var R : Sequence := Sequence{} ; var v : int := MathLib.bitwiseAnd((-1), M) ; while v do ( execute ((v) : R) ; v := MathLib.bitwiseAnd((v - 1), M)) ; R := R->sort() ; write("0:\n") ; for i : R do ( write(StringLib.format("%d: %s\n",Sequence{i, StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) ))))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (expr (atom (name i))) & (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name j)))))))) ))))))))))), " ")}))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def generateDivisors(curIndex,curDivisor,arr): if(curIndex==len(arr)): print(curDivisor,end=' ') return for i in range(arr[curIndex][0]+1): generateDivisors(curIndex+1,curDivisor,arr) curDivisor*=arr[curIndex][1] def findDivisors(n): arr=[] i=2 while(i*i<=n): if(n % i==0): count=0 while(n % i==0): n//=i count+=1 arr.append([count,i]) if(n>1): arr.append([1,n]) curIndex=0 curDivisor=1 generateDivisors(curIndex,curDivisor,arr) n=6 findDivisors(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 6 ; findDivisors(n); operation generateDivisors(curIndex : OclAny, curDivisor : OclAny, arr : OclAny) pre: true post: true activity: if (curIndex = (arr)->size()) then ( execute (curDivisor)->display() ; return ) else skip ; for i : Integer.subrange(0, arr[curIndex+1]->first() + 1-1) do ( generateDivisors(curIndex + 1, curDivisor, arr) ; curDivisor := curDivisor * arr[curIndex+1][1+1]); operation findDivisors(n : OclAny) pre: true post: true activity: arr := Sequence{} ; var i : int := 2 ; while ((i * i->compareTo(n)) <= 0) do ( if (n mod i = 0) then ( var count : int := 0 ; while (n mod i = 0) do ( n := n div i ; count := count + 1) ; execute ((Sequence{count}->union(Sequence{ i })) : arr) ) else skip) ; if (n > 1) then ( execute ((Sequence{1}->union(Sequence{ n })) : arr) ) else skip ; curIndex := 0 ; curDivisor := 1 ; generateDivisors(curIndex, curDivisor, arr); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reverse(n): rev=0 while(n!=0): rev=(rev*10)+(n % 10) n//=10 return rev def getSum(n): n=reverse(n) sumOdd=0 sumEven=0 c=1 while(n!=0): if(c % 2==0): sumEven+=n % 10 else : sumOdd+=n % 10 n//=10 c+=1 print("Sum odd=",sumOdd) print("Sum even=",sumEven) n=457892 getSum(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 457892 ; getSum(n); operation reverse(n : OclAny) : OclAny pre: true post: true activity: var rev : int := 0 ; while (n /= 0) do ( rev := (rev * 10) + (n mod 10) ; n := n div 10) ; return rev; operation getSum(n : OclAny) pre: true post: true activity: n := reverse(n) ; var sumOdd : int := 0 ; var sumEven : int := 0 ; var c : int := 1 ; while (n /= 0) do ( if (c mod 2 = 0) then ( sumEven := sumEven + n mod 10 ) else ( sumOdd := sumOdd + n mod 10 ) ; n := n div 10 ; c := c + 1) ; execute ("Sum odd=")->display() ; execute ("Sum even=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[0 for _ in range(1000010)] dp=[0 for _ in range(1000010)] for i in range(n): a,b=map(int,input().split()) l[a]=b if l[0]>0 : dp[0]=1 mx=0 for i in range(1,1000010): if(l[i]==0): dp[i]=dp[i-1] else : if(l[i]>=i): dp[i]=1 ; else : dp[i]=dp[i-l[i]-1]+1 ; if(dp[i]>mx): mx=dp[i] print(n-mx) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Integer.subrange(0, 1000010-1)->select(_anon | true)->collect(_anon | (0)) ; var dp : Sequence := Integer.subrange(0, 1000010-1)->select(_anon | true)->collect(_anon | (0)) ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; l[a+1] := b) ; if l->first() > 0 then ( dp->first() := 1 ) else skip ; var mx : int := 0 ; for i : Integer.subrange(1, 1000010-1) do ( if (l[i+1] = 0) then ( dp[i+1] := dp[i - 1+1] ) else ( if ((l[i+1]->compareTo(i)) >= 0) then ( dp[i+1] := 1; ) else ( dp[i+1] := dp[i - l[i+1] - 1+1] + 1; ) ) ; if ((dp[i+1]->compareTo(mx)) > 0) then ( mx := dp[i+1] ) else skip) ; execute (n - mx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) bb=[0]*1000001 for _ in range(n): a,b=map(int,input().split()) bb[a]=b a=0 for i,b in enumerate(bb): if b : if i>b : a=(bb[i-b-1]+1) else : a=1 bb[i]=a print(n-max(bb)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var bb : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 1000001) ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; bb[a+1] := b) ; var a : int := 0 ; for _tuple : Integer.subrange(1, (bb)->size())->collect( _indx | Sequence{_indx-1, (bb)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if b then ( if (i->compareTo(b)) > 0 then ( a := (bb[i - b - 1+1] + 1) ) else ( a := 1 ) ) else skip ; bb[i+1] := a) ; execute (n - (bb)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect n=int(input()) b=[] p=[] a=[] for i in range(n): a.append(list(map(int,input().split()))) a.sort() for i in range(n): b.append(a[i][0]) p.append(a[i][1]) dp=[0]*n for i in range(n): j=bisect.bisect_left(b,b[i]-p[i]) dp[i]=i-j+dp[j-1] ans=10**9 c=1 for j in range(n-1,-1,-1): ans=min(ans,dp[j-1]+c,dp[j]+c-1) c=c+1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := Sequence{} ; var p : Sequence := Sequence{} ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : a)) ; a := a->sort() ; for i : Integer.subrange(0, n-1) do ( execute ((a[i+1]->first()) : b) ; execute ((a[i+1][1+1]) : p)) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( var j : OclAny := bisect.bisect_left(b, b[i+1] - p[i+1]) ; dp[i+1] := i - j + dp[j - 1+1]) ; var ans : double := (10)->pow(9) ; var c : int := 1 ; for j : Integer.subrange(-1 + 1, n - 1)->reverse() do ( ans := Set{ans, dp[j - 1+1] + c, dp[j+1] + c - 1}->min() ; c := c + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input(''))): n,m=map(int,input().split()) l=list(map(int,input().split())) if sum(l)==m : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine(''))))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (l)->sum() = m then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.read MAX=int(1e6+7) b=[0 for _ in range(MAX)] d=[0 for _ in range(MAX)] mx=0 r=map(int,input().split()) n=next(r) for i in range(n): a=next(r) b[a]=next(r) if b[0]>0 : d[0]=1 else : d[0]=0 for i in range(1,MAX): if b[i]==0 : d[i]=d[i-1] elif i<=b[i]: d[i]=1 else : d[i]=d[i-b[i]-1]+1 mx=max(mx,d[i]) print(n-mx) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).read ; var MAX : int := ("" + ((("1e6")->toReal() + 7)))->toInteger() ; var b : Sequence := Integer.subrange(0, MAX-1)->select(_anon | true)->collect(_anon | (0)) ; var d : Sequence := Integer.subrange(0, MAX-1)->select(_anon | true)->collect(_anon | (0)) ; var mx : int := 0 ; var r : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : OclAny := (r).next() ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := (r).next() ; b[a+1] := (r).next()) ; if b->first() > 0 then ( d->first() := 1 ) else ( d->first() := 0 ) ; for i : Integer.subrange(1, MAX-1) do ( if b[i+1] = 0 then ( d[i+1] := d[i - 1+1] ) else (if (i->compareTo(b[i+1])) <= 0 then ( d[i+1] := 1 ) else ( d[i+1] := d[i - b[i+1] - 1+1] + 1 ) ) ; mx := Set{mx, d[i+1]}->max()) ; execute (n - mx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque from collections import OrderedDict import queue import heapq import math import sys sys.setrecursionlimit(10**6) def sf(): return[int(x)for x in input().split(" ")] def sfi(): return int(input()) def sfs(): return input() def printf(x): print(x) sys.stdout.flush() def binary_search(val,arr): l,r=0,len(arr)-1 while(l=val : r=m-1 elif r-l==1 and arr[r][0]l : return-1 if arr[l][0]>=val : return-1 return l def main(): n=int(input()) beacons=[] for i in range(n): position,power=[int(x)for x in input().split(" ")] beacons.append((position,power)) beacons=sorted(beacons) dp=[0]*n for idx,(position,power)in enumerate(beacons): idx_safe=binary_search(position-power,beacons) destroyed=idx-idx_safe-1 dp[idx]=destroyed+dp[idx_safe] result=100001 for idx in range(len(beacons)): result=min(result,idx+dp[n-1-idx]) print(result) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(6)) ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation sf() : OclAny pre: true post: true activity: return input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation sfi() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation sfs() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation printf(x : OclAny) pre: true post: true activity: execute (x)->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))); operation binary_search(val : OclAny, arr : OclAny) : OclAny pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,(arr)->size() - 1} ; while ((l->compareTo(r)) < 0) do ( var m : int := (l + r) div 2 ; if (arr[m+1]->first()->compareTo(val)) >= 0 then ( var r : double := m - 1 ) else (if r - l = 1 & (arr[r+1]->first()->compareTo(val)) < 0 then ( var l : OclAny := r ) else (if r - l = 1 then ( r := l ) else ( l := m ) ) ) ) ; if (r->compareTo(l)) > 0 then ( return -1 ) else skip ; if (arr[l+1]->first()->compareTo(val)) >= 0 then ( return -1 ) else skip ; return l; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var beacons : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var position : OclAny := null; var power : OclAny := null; Sequence{position,power} := input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((Sequence{position, power}) : beacons)) ; beacons := beacons->sort() ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for _tuple : Integer.subrange(1, (beacons)->size())->collect( _indx | Sequence{_indx-1, (beacons)->at(_indx)} ) do (var _indx : int := 1; var idx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{position, power} : OclAny := _tuple->at(_indx); var idx_safe : OclAny := binary_search(position - power, beacons) ; var destroyed : double := idx - idx_safe - 1 ; dp[idx+1] := destroyed + dp[idx_safe+1]) ; var result : int := 100001 ; for idx : Integer.subrange(0, (beacons)->size()-1) do ( result := Set{result, idx + dp[n - 1 - idx+1]}->min()) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def largestPalinSub(s): res="" mx=s[0] for i in range(1,len(s)): mx=max(mx,s[i]) for i in range(0,len(s)): if s[i]==mx : res+=s[i] return res if __name__=="__main__" : s="geeksforgeeks" print(largestPalinSub(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "geeksforgeeks" ; execute (largestPalinSub(s))->display() ) else skip; operation largestPalinSub(s : OclAny) : OclAny pre: true post: true activity: var res : String := "" ; var mx : OclAny := s->first() ; for i : Integer.subrange(1, (s)->size()-1) do ( mx := Set{mx, s[i+1]}->max()) ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = mx then ( res := res + s[i+1] ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def convert(s): convertStr="" l=len(s) i=0 while itoInteger() ; s := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, n-1) do ( s := convert(s)) ; execute (s)->display()) catch (_e : OclException) do ( break) ); operation convert(s : OclAny) : OclAny pre: true post: true activity: var convertStr : String := "" ; var l : int := (s)->size() ; var i : int := 0 ; while (i->compareTo(l)) < 0 do ( if (i + 1->compareTo(l)) < 0 then ( var word : OclAny := s[i+1] ; var sequenceNum : int := 1 ; var j : int := i + 1 ; while (j->compareTo(l)) < 0 do ( if (word = s[j+1]) then ( sequenceNum := sequenceNum + 1 ) else ( break ) ; j := j + 1) ; convertStr := convertStr + ("" + ((sequenceNum))) + word ; i := i + sequenceNum - 1 ) else ( convertStr := convertStr + "1" + ("" + ((s[i+1]))) ) ; i := i + 1) ; return convertStr; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(li): cnt=1 ans=[] for i in range(len(li)-1): tar=int(li[i]) if tar==int(li[i+1]): if cnt>=10 : ans.append(cnt//10) cnt=cnt % 10 cnt+=1 else : if cnt>=10 : ans.append(cnt//10) ans.append(cnt % 10) else : ans.append(cnt) ans.append(tar) cnt=1 tar=int(li[i+1]) ans.append(cnt) ans.append(tar) return ans while True : n=int(input()) if n==0 : break a=input() la=list(a) i=0 while itoInteger() ; if n = 0 then ( break ) else skip ; var a : String := (OclFile["System.in"]).readLine() ; var la : Sequence := (a)->characters() ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( la := solve(la) ; i := i + 1) ; for x : la do ( execute (x)->display()) ; execute (->display()); operation solve(li : OclAny) : OclAny pre: true post: true activity: var cnt : int := 1 ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, (li)->size() - 1-1) do ( var tar : int := ("" + ((li[i+1])))->toInteger() ; if tar = ("" + ((li[i + 1+1])))->toInteger() then ( if cnt >= 10 then ( execute ((cnt div 10) : ans) ; cnt := cnt mod 10 ) else skip ; cnt := cnt + 1 ) else ( if cnt >= 10 then ( execute ((cnt div 10) : ans) ; execute ((cnt mod 10) : ans) ) else ( execute ((cnt) : ans) ) ; execute ((tar) : ans) ; cnt := 1 )) ; tar := ("" + ((li[i + 1+1])))->toInteger() ; execute ((cnt) : ans) ; execute ((tar) : ans) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(raw_input()) if n==0 : break s=raw_input() for i in xrange(n): news="" cnt=1 for j in xrange(len(s)-1): if s[j]==s[j+1]: cnt+=1 else : news+=str(cnt)+s[j] cnt=1 news+=str(cnt)+s[-1] s=news print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + ((raw_input())))->toInteger() ; if n = 0 then ( break ) else skip ; var s : OclAny := raw_input() ; for i : xrange(n) do ( var news : String := "" ; var cnt : int := 1 ; for j : xrange((s)->size() - 1) do ( if s[j+1] = s[j + 1+1] then ( cnt := cnt + 1 ) else ( news := news + ("" + ((cnt))) + s[j+1] ; cnt := 1 )) ; news := news + ("" + ((cnt))) + s->last() ; s := news) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def disp(row_no,block): print(row_no*block) def row(ht,h): return ht//h def calculate(l,w,h,a,ht): no_block=(4*a)//l if(hdisplay(); operation row(ht : OclAny, h : OclAny) : OclAny pre: true post: true activity: return ht div h; operation calculate(l : OclAny, w : OclAny, h : OclAny, a : OclAny, ht : OclAny) pre: true post: true activity: var no_block : int := (4 * a) div l ; if ((h->compareTo(w)) < 0) then ( row_no := row(ht, w) ) else ( row_no := row(ht, h) ) ; disp(row_no, no_block); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if not n : break ss=[s for s in input()[: :-1]] for i in range(n): new=[] app=new.append last=ss.pop() count=1 while ss : a=ss.pop() if a==last : count+=1 else : app(str(count)) app(last) last=a count=1 app(str(count)) app(last) new="".join(new) ss=[s for s in new[: :-1]] print("".join(new)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(n) then ( break ) else skip ; var ss : Sequence := input()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->select(s | true)->collect(s | (s)) ; for i : Integer.subrange(0, n-1) do ( var new : Sequence := Sequence{} ; var app : OclAny := new.append ; var last : OclAny := ss->last() ; ss := ss->front() ; var count : int := 1 ; while ss do ( var a : OclAny := ss->last() ; ss := ss->front() ; if a = last then ( count := count + 1 ) else ( app(("" + ((count)))) ; app(last) ; last := a ; count := 1 )) ; app(("" + ((count)))) ; app(last) ; new := StringLib.sumStringsWithSeparator((new), "") ; ss := new(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->select(s | true)->collect(s | (s))) ; execute (StringLib.sumStringsWithSeparator((new), ""))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def change(n): x=n[0] count=1 ans="" for i in n[1 :]: if i==x : count+=1 else : ans+=str(count) ans+=x x=i count=1 ans+=str(count) ans+=x return(ans) while 1 : n=int(input()) if n==0 : break word=input() for i in range(n): word=change(word) print(word) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while 1 do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var word : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, n-1) do ( word := change(word)) ; execute (word)->display()); operation change(n : OclAny) : OclAny pre: true post: true activity: var x : OclAny := n->first() ; var count : int := 1 ; var ans : String := "" ; for i : n->tail() do ( if i = x then ( count := count + 1 ) else ( ans := ans + ("" + ((count))) ; ans := ans + x ; x := i ; count := 1 )) ; ans := ans + ("" + ((count))) ; ans := ans + x ; return (ans); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) a=list(map(int,input().split())) d=[0 for _ in range(100007)] ans=0 for i in a : for j in range(2,i+1): if j*j>i : break if i % j==0 : d[i]=max(d[i],d[i//j]+1,d[j]+1) d[i]=max(d[i],1) for j in range(2,i+1): if j*j>i : break if i % j==0 : d[i//j]=d[i] d[j]=d[i] ans=max(ans,d[i]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : Sequence := Integer.subrange(0, 100007-1)->select(_anon | true)->collect(_anon | (0)) ; var ans : int := 0 ; for i : a do ( for j : Integer.subrange(2, i + 1-1) do ( if (j * j->compareTo(i)) > 0 then ( break ) else skip ; if i mod j = 0 then ( d[i+1] := Set{d[i+1], d[i div j+1] + 1, d[j+1] + 1}->max() ) else skip) ; d[i+1] := Set{d[i+1], 1}->max() ; for j : Integer.subrange(2, i + 1-1) do ( if (j * j->compareTo(i)) > 0 then ( break ) else skip ; if i mod j = 0 then ( d[i div j+1] := d[i+1] ; d[j+1] := d[i+1] ) else skip) ; ans := Set{ans, d[i+1]}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def solve(): n=int(input()) a=list(map(int,input().split(" "))) N=int(10e5+5) dp=[0]*N fac=[[]for _ in range(N)] seive=[1]*N for i in range(2,N): if seive[i]: for j in range(i,N,i): seive[j]=0 fac[j].append(i) ans=1 for i in range(n): z=0 for x in fac[a[i]]: z=max(dp[x],z) z+=1 ans=max(ans,z) for x in fac[a[i]]: dp[x]=max(z,dp[x]) print(ans) return solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; solve(); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var N : int := ("" + ((("10e5")->toReal() + 5)))->toInteger() ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var fac : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var seive : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, N) ; for i : Integer.subrange(2, N-1) do ( if seive[i+1] then ( for j : Integer.subrange(i, N-1)->select( $x | ($x - i) mod i = 0 ) do ( seive[j+1] := 0 ; (expr (atom (name fac)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ) else skip) ; var ans : int := 1 ; for i : Integer.subrange(0, n-1) do ( var z : int := 0 ; for x : fac[a[i+1]+1] do ( z := Set{dp[x+1], z}->max()) ; z := z + 1 ; ans := Set{ans, z}->max() ; for x : fac[a[i+1]+1] do ( dp[x+1] := Set{z, dp[x+1]}->max())) ; execute (ans)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=list(map(int,input().split())) a=list(map(int,input().split())) if sum(a)==m : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (a)->sum() = m then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) from collections import defaultdict arr=list(map(int,input().split())) ans=1 dp=[0]*(pow(10,5)+1) for ele in arr : dp[ele]=1 j=2 while j*j<=ele : if ele % j==0 : dp[ele]=max(dp[ele],dp[j]+1) dp[ele]=max(dp[ele],dp[ele//j]+1) j+=1 ans=max(ans,dp[ele]) j=2 while j*j<=ele : if ele % j==0 : dp[j]=dp[ele] dp[ele//j]=dp[ele] j+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 1 ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((10)->pow(5) + 1)) ; for ele : arr do ( dp[ele+1] := 1 ; var j : int := 2 ; while (j * j->compareTo(ele)) <= 0 do ( if ele mod j = 0 then ( dp[ele+1] := Set{dp[ele+1], dp[j+1] + 1}->max() ; dp[ele+1] := Set{dp[ele+1], dp[ele div j+1] + 1}->max() ) else skip ; j := j + 1) ; ans := Set{ans, dp[ele+1]}->max() ; j := 2 ; while (j * j->compareTo(ele)) <= 0 do ( if ele mod j = 0 then ( dp[j+1] := dp[ele+1] ; dp[ele div j+1] := dp[ele+1] ) else skip ; j := j + 1)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) N=200001 p=[0]*N a=[[]for _ in range(N)] a[1]=[1] for i in range(2,N): a[i].append(i) for j in range(i*2,N,i): a[j].append(i) for i in map(int,input().split()): mx=max(p[j]for j in a[i])+1 for j in a[i]: p[j]=mx print(max(p)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var N : int := 200001 ; var p : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var a : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; a[1+1] := Sequence{ 1 } ; for i : Integer.subrange(2, N-1) do ((expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ; for j : Integer.subrange(i * 2, N-1)->select( $x | ($x - i * 2) mod i = 0 ) do ((expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))) ; for i : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( var mx : OclAny := ((argument (test (logical_test (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))->max() + 1 ; for j : a[i+1] do ( p[j+1] := mx)) ; execute ((p)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) a=list(map(int,input().split())) d=[0 for _ in range(100007)] ans=0 for i in a : for j in range(1,i+1): if j*j>i : break if i % j==0 : d[i]=max(d[i],d[i//j]+1) if j>1 : d[i]=max(d[i],d[j]+1) for j in range(1,i+1): if j*j>i : break if i % j==0 : d[i//j]=d[i] d[j]=d[i] ans=max(ans,d[i]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : Sequence := Integer.subrange(0, 100007-1)->select(_anon | true)->collect(_anon | (0)) ; var ans : int := 0 ; for i : a do ( for j : Integer.subrange(1, i + 1-1) do ( if (j * j->compareTo(i)) > 0 then ( break ) else skip ; if i mod j = 0 then ( d[i+1] := Set{d[i+1], d[i div j+1] + 1}->max() ; if j > 1 then ( d[i+1] := Set{d[i+1], d[j+1] + 1}->max() ) else skip ) else skip) ; for j : Integer.subrange(1, i + 1-1) do ( if (j * j->compareTo(i)) > 0 then ( break ) else skip ; if i mod j = 0 then ( d[i div j+1] := d[i+1] ; d[j+1] := d[i+1] ) else skip) ; ans := Set{ans, d[i+1]}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def initializeDiffArray(A): n=len(A) D=[0 for i in range(0,n+1)] D[0]=A[0]; D[n]=0 for i in range(1,n): D[i]=A[i]-A[i-1] return D def update(D,l,r,x): D[l]+=x D[r+1]-=x def printArray(A,D): for i in range(0,len(A)): if(i==0): A[i]=D[i] else : A[i]=D[i]+A[i-1] print(A[i],end="") print("") A=[10,5,20,40] D=initializeDiffArray(A) update(D,0,1,10) printArray(A,D) update(D,1,3,20) update(D,2,2,30) printArray(A,D) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; A := Sequence{10}->union(Sequence{5}->union(Sequence{20}->union(Sequence{ 40 }))) ; D := initializeDiffArray(A) ; update(D, 0, 1, 10) ; printArray(A, D) ; update(D, 1, 3, 20) ; update(D, 2, 2, 30) ; printArray(A, D); operation initializeDiffArray(A : OclAny) : OclAny pre: true post: true activity: var n : int := (A)->size() ; var D : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; D->first() := A->first(); D[n+1] := 0 ; for i : Integer.subrange(1, n-1) do ( D[i+1] := A[i+1] - A[i - 1+1]) ; return D; operation update(D : OclAny, l : OclAny, r : OclAny, x : OclAny) pre: true post: true activity: D[l+1] := D[l+1] + x ; D[r + 1+1] := D[r + 1+1] - x; operation printArray(A : OclAny, D : OclAny) pre: true post: true activity: for i : Integer.subrange(0, (A)->size()-1) do ( if (i = 0) then ( A[i+1] := D[i+1] ) else ( A[i+1] := D[i+1] + A[i - 1+1] ) ; execute (A[i+1])->display()) ; execute ("")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMaxGuests(arrl,exit,n): arrl.sort(); exit.sort(); guests_in=1 ; max_guests=1 ; time=arrl[0]; i=1 ; j=0 ; while(imax_guests): max_guests=guests_in ; time=arrl[i]; i=i+1 ; else : guests_in=guests_in-1 ; j=j+1 ; print("Maximum Number of Guests=",max_guests,"at time",time) arrl=[1,2,10,5,5]; exit=[4,5,12,9,12]; n=len(arrl); findMaxGuests(arrl,exit,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arrl := Sequence{1}->union(Sequence{2}->union(Sequence{10}->union(Sequence{5}->union(Sequence{ 5 })))); ; exit := Sequence{4}->union(Sequence{5}->union(Sequence{12}->union(Sequence{9}->union(Sequence{ 12 })))); ; n := (arrl)->size(); ; findMaxGuests(arrl, exit, n);; operation findMaxGuests(arrl : OclAny, exit : OclAny, n : OclAny) pre: true post: true activity: arrl := arrl->sort(); ; exit := exit->sort(); ; var guests_in : int := 1; ; var max_guests : int := 1; ; var time : OclAny := arrl->first(); ; var i : int := 1; ; var j : int := 0; ; while ((i->compareTo(n)) < 0 & (j->compareTo(n)) < 0) do ( if ((arrl[i+1]->compareTo(exit[j+1])) <= 0) then ( guests_in := guests_in + 1; ; if ((guests_in->compareTo(max_guests)) > 0) then ( max_guests := guests_in; ; time := arrl[i+1]; ) else skip ; i := i + 1; ) else ( guests_in := guests_in - 1; ; j := j + 1; )) ; execute ("Maximum Number of Guests=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- bin=["000","001","010","011","100","101","110","111"]; def maxFreq(s): binary="" ; for i in range(len(s)): binary+=bin[ord(s[i])-ord('0')]; binary=binary[0 : len(binary)-1]; count=1 ; prev=-1 ; j=0 ; for i in range(len(binary)-1,-1,-1): if(binary[i]=='1'): count=max(count,j-prev); prev=j ; j+=1 ; return count ; if __name__=="__main__" : octal="13" ; print(maxFreq(octal)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var bin : Sequence := Sequence{"000"}->union(Sequence{"001"}->union(Sequence{"010"}->union(Sequence{"011"}->union(Sequence{"100"}->union(Sequence{"101"}->union(Sequence{"110"}->union(Sequence{ "111" }))))))); ; skip ; if __name__ = "__main__" then ( var octal : String := "13"; ; execute (maxFreq(octal))->display(); ) else skip; operation maxFreq(s : OclAny) pre: true post: true activity: var binary : String := ""; ; for i : Integer.subrange(0, (s)->size()-1) do ( binary := binary + bin[(s[i+1])->char2byte() - ('0')->char2byte()+1];) ; binary := binary.subrange(0+1, (binary)->size() - 1); ; var count : int := 1; var prev : int := -1; var j : int := 0; ; for i : Integer.subrange(-1 + 1, (binary)->size() - 1)->reverse() do ( if (binary[i+1] = '1') then ( count := Set{count, j - prev}->max(); ; prev := j; ) else skip ; j := j + 1;) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lcs(x,y,pre_lcs,pre_lcs_len): pm=dict((zip('ABCDEFGHIJKLMNOPQRSTUVWXYZ',[0]*26))) for c in pm : for i,xc in enumerate(x): if c==xc : pm[c]|=(1<pre_lcs_len : rx=x[: :-1] lcs='' idx=0 for v,yc in zip(rec[: :-1],reversed(y)): idx=v.find('0',idx) if yc==rx[idx]: lcs+=yc if len(lcs)==lcs_len : return(lcs[: :-1],lcs_len) idx+=1 else : return(pre_lcs,pre_lcs_len) from sys import stdin def solve(): file_input=stdin ans_out=[] for s in file_input : s=s.rstrip() if s[0]=='#' : break s_len=len(s) sep=s_len//2 ans,ans_len=lcs(s[: sep],s[sep :],'',0) while sep>ans_len : ans,ans_len=lcs(s[:-sep],s[-sep :],ans,ans_len) sep-=1 ans,ans_len=lcs(s[: sep],s[sep :],ans,ans_len) ans_out.append(ans) print(*ans_out,sep='\n') solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; solve(); operation lcs(x : OclAny, y : OclAny, pre_lcs : OclAny, pre_lcs_len : OclAny) : OclAny pre: true post: true activity: var pm : Map := (((expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')))))) , (argument (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr (atom (number (integer 26)))))))))) )))))) ; for c : pm->keys() do ( for _tuple : Integer.subrange(1, (x)->size())->collect( _indx | Sequence{_indx-1, (x)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var xc : OclAny := _tuple->at(_indx); if c = xc then ( pm[c+1] := pm[c+1] or (1 * (2->pow(i))) ) else skip)) ; var V : double := (1 * (2->pow((x)->size()))) - 1 ; var rec : Sequence := Sequence{} ; for yc : y do ( V := (MathLib.bitwiseOr((V + (MathLib.bitwiseAnd(V, pm[yc+1]))), (MathLib.bitwiseAnd(V, MathLib.bitwiseNot(pm[yc+1]))))) ; execute ((bin(V).subrange(-(x)->size()+1)) : rec)) ; var lcs_len : OclAny := bin(V).subrange(-(x)->size()+1)->count('0') ; if (lcs_len->compareTo(pre_lcs_len)) > 0 then ( var rx : OclAny := x(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var lcs : String := '' ; var idx : int := 0 ; for _tuple : Integer.subrange(1, rec(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->size())->collect( _indx | Sequence{rec(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->at(_indx), (y)->reverse()->at(_indx)} ) do (var _indx : int := 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var yc : OclAny := _tuple->at(_indx); idx := v->indexOf('0', idx) - 1 ; if yc = rx[idx+1] then ( lcs := lcs + yc ; if (lcs)->size() = lcs_len then ( return Sequence{lcs(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))), lcs_len} ) else skip ; idx := idx + 1 ) else skip) ) else ( return Sequence{pre_lcs, pre_lcs_len} ); operation solve() pre: true post: true activity: var file_input : OclAny := stdin ; var ans_out : Sequence := Sequence{} ; for s : file_input do ( var s : String := StringLib.rightTrim(s) ; if s->first() = '#' then ( break ) else skip ; var s_len : int := (s)->size() ; var sep : int := s_len div 2 ; var ans : OclAny := null; var ans_len : OclAny := null; Sequence{ans,ans_len} := lcs(s.subrange(1,sep), s.subrange(sep+1), '', 0) ; while (sep->compareTo(ans_len)) > 0 do ( var ans : OclAny := null; var ans_len : OclAny := null; Sequence{ans,ans_len} := lcs(s.subrange(1,-sep), s.subrange(-sep+1), ans, ans_len) ; sep := sep - 1 ; var ans : OclAny := null; var ans_len : OclAny := null; Sequence{ans,ans_len} := lcs(s.subrange(1,sep), s.subrange(sep+1), ans, ans_len)) ; execute ((ans) : ans_out)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans_out))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calcFunction(n,r): finalDenominator=1 mx=max(r,n-r) for i in range(mx+1,n+1): denominator=pow(i,i) numerator=pow(i-mx,i-mx) finalDenominator=(finalDenominator*denominator)//numerator return finalDenominator if __name__=="__main__" : n=6 r=2 print("1/",end="") print(calcFunction(n,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 6 ; r := 2 ; execute ("1/")->display() ; execute (calcFunction(n, r))->display() ) else skip; operation calcFunction(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: var finalDenominator : int := 1 ; var mx : OclAny := Set{r, n - r}->max() ; for i : Integer.subrange(mx + 1, n + 1-1) do ( var denominator : double := (i)->pow(i) ; var numerator : double := (i - mx)->pow(i - mx) ; finalDenominator := (finalDenominator * denominator) div numerator) ; return finalDenominator; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def isPerfectSquare(x): sr=int(sqrt(x)); if(sr*sr==x): print("Yes"); else : print("No"); if __name__=="__main__" : n=7 ; k=2 ; isPerfectSquare(n+k); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var n : int := 7; var k : int := 2; ; isPerfectSquare(n + k); ) else skip; operation isPerfectSquare(x : OclAny) pre: true post: true activity: var sr : int := ("" + ((sqrt(x))))->toInteger(); ; if (sr * sr = x) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=[int(input())*N+i for i in range(N)] A.sort() cnt=0 for i in range(N): d=(A[i]% N)% 2 if d % 2!=i % 2 : cnt+=1 print(cnt//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger() * N + i)) ; A := A->sort() ; var cnt : int := 0 ; for i : Integer.subrange(0, N-1) do ( var d : int := (A[i+1] mod N) mod 2 ; if d mod 2 /= i mod 2 then ( cnt := cnt + 1 ) else skip) ; execute (cnt div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- compress3=lambda arr : list(map({e : i for i,e in enumerate(sorted(set(arr)))}.__getitem__,arr)) n=int(input()) a=[int(input())for i in range(n)] a=compress3(a) odd=set() even=set() for i in range(n): if i % 2==0 : even.add(a[i]) else : odd.add(a[i]) ans=len(set([2*i for i in range(n//2)])& odd) ans=max(ans,len(set([2*i+1 for i in range(n//2)])& even)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var compress3 : Function := lambda arr : OclAny in (((arr)->collect( _x | (Integer.subrange(1, (Set{}->union((arr))->sort())->size())->collect( _indx | Sequence{_indx-1, (Set{}->union((arr))->sort())->at(_indx)} )->select(_tuple | true)->collect(_tuple | Map{e |-> i})->unionAll().__getitem__)->apply(_x) ))) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; a := compress3->apply(a) ; var odd : Set := Set{}->union(()) ; var even : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( if i mod 2 = 0 then ( execute ((a[i+1]) : even) ) else ( execute ((a[i+1]) : odd) )) ; var ans : int := (MathLib.bitwiseAnd(Set{}->union((Integer.subrange(0, n div 2-1)->select(i | true)->collect(i | (2 * i)))), odd))->size() ; ans := Set{ans, (MathLib.bitwiseAnd(Set{}->union((Integer.subrange(0, n div 2-1)->select(i | true)->collect(i | (2 * i + 1)))), even))->size()}->max() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) maxi=l.count(max(l)) mini=l.count(min(l)) if n==1 or len(l)==l.count(l[0]): print(0) else : print(len(l)-maxi-mini) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var maxi : int := l->count((l)->max()) ; var mini : int := l->count((l)->min()) ; if n = 1 or (l)->size() = l->count(l->first()) then ( execute (0)->display() ) else ( execute ((l)->size() - maxi - mini)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import collections import bisect import itertools sys.setrecursionlimit(10**7) INF=10**20 MOD=10**9+7 ni=lambda : int(sys.stdin.readline().rstrip()) ns=lambda : map(int,sys.stdin.readline().rstrip().split()) na=lambda : list(map(int,sys.stdin.readline().rstrip().split())) na1=lambda : list(map(lambda x : int(x)-1,sys.stdin.readline().rstrip().split())) def main(): n=ni() a=[ni()for _ in range(n)] a_sorted=sorted(a) ans=0 for i,ai in enumerate(a): idx=bisect.bisect_left(a_sorted,ai) if(idx-i)% 2 : ans+=1 print(ans//2) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; var INF : double := (10)->pow(20) ; var MOD : double := (10)->pow(9) + 7 ; var ni : Function := lambda $$ : OclAny in (("" + ((sys.stdin.readLine().rstrip())))->toInteger()) ; var ns : Function := lambda $$ : OclAny in ((sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var na : Function := lambda $$ : OclAny in (((sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var na1 : Function := lambda $$ : OclAny in (((sys.stdin.readLine().rstrip().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ))) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := ni->apply() ; var a : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (ni->apply())) ; var a_sorted : Sequence := a->sort() ; var ans : int := 0 ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var ai : OclAny := _tuple->at(_indx); var idx : OclAny := bisect.bisect_left(a_sorted, ai) ; if (idx - i) mod 2 then ( ans := ans + 1 ) else skip) ; execute (ans div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,*a=map(int,open(0)) print(len({*a[: : 2]}^{*sorted(a)[: : 2]})//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := (OclFile.newOclFile_Write(OclFile.newOclFile(0)))->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((MathLib.bitwiseXor(Set{ a(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) }, Set{ sorted(a)(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) }))->size() div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import defaultdict sys.setrecursionlimit(10**7) input=sys.stdin.readline f_inf=float('inf') mod=10**9+7 def resolve(): n=int(input()) A=[int(input())for _ in range(n)] A_S=sorted(A) IDX=defaultdict(int) for idx,a in enumerate(A_S): IDX[a]=idx+1 res=0 for i in range(n): if IDX[A[i]]% 2!=(i+1)% 2 : res+=1 print(res//2) if __name__=='__main__' : resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; var input : OclAny := (OclFile["System.in"]).readline ; var f_inf : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; skip ; if __name__ = '__main__' then ( resolve() ) else skip; operation resolve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var A_S : Sequence := A->sort() ; var IDX : OclAny := defaultdict(OclType["int"]) ; for _tuple : Integer.subrange(1, (A_S)->size())->collect( _indx | Sequence{_indx-1, (A_S)->at(_indx)} ) do (var _indx : int := 1; var idx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); IDX[a+1] := idx + 1) ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( if IDX[A[i+1]+1] mod 2 /= (i + 1) mod 2 then ( res := res + 1 ) else skip) ; execute (res div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get(l : list)->str : l.sort() for i in l : if i+1 in l and i+2 in l : return "YES" return "NO" if __name__=='__main__' : n=int(input()) lst=input().split() lst=[int(x)for x in lst] print(get(lst)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : OclAny := input().split() ; lst := lst->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (get(lst))->display() ) else skip; operation get(l : Sequence(OclAny)) : String pre: true post: true activity: l := l->sort() ; for i : l do ( if (l)->includes(i + 1) & (l)->includes(i + 2) then ( return "YES" ) else skip) ; return "NO"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isVowel(c): return(c=='a' or c=='e' or c=='i' or c=='o' or c=='u') def encryptString(s,n,k): cv=[0 for i in range(n)] cc=[0 for i in range(n)] if(isVowel(s[0])): cv[0]=1 else : cc[0]=1 for i in range(1,n): cv[i]=cv[i-1]+isVowel(s[i]) cc[i]=cc[i-1]+(isVowel(s[i])==False) ans="" prod=0 prod=cc[k-1]*cv[k-1] ans+=str(prod) for i in range(k,len(s)): prod=((cc[i]-cc[i-k])*(cv[i]-cv[i-k])) ans+=str(prod) return ans if __name__=='__main__' : s="hello" n=len(s) k=2 print(encryptString(s,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( s := "hello" ; n := (s)->size() ; k := 2 ; execute (encryptString(s, n, k))->display() ) else skip; operation isVowel(c : OclAny) : OclAny pre: true post: true activity: return (c = 'a' or c = 'e' or c = 'i' or c = 'o' or c = 'u'); operation encryptString(s : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var cv : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var cc : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; if (isVowel(s->first())) then ( cv->first() := 1 ) else ( cc->first() := 1 ) ; for i : Integer.subrange(1, n-1) do ( cv[i+1] := cv[i - 1+1] + isVowel(s[i+1]) ; cc[i+1] := cc[i - 1+1] + (isVowel(s[i+1]) = false)) ; var ans : String := "" ; var prod : int := 0 ; prod := cc[k - 1+1] * cv[k - 1+1] ; ans := ans + ("" + ((prod))) ; for i : Integer.subrange(k, (s)->size()-1) do ( prod := ((cc[i+1] - cc[i - k+1]) * (cv[i+1] - cv[i - k+1])) ; ans := ans + ("" + ((prod)))) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) l.sort() for i in l : if i+1 in l and i+2 in l : print('YES') break else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := l->sort() ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name l))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))) in (comparison (expr (atom (name l)))))) and (logical_test (comparison (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 2)))))) in (comparison (expr (atom (name l)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() T=set(map(int,input().split())) print('YES' if any(t-1 in T and t+1 in T for t in T)else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var T : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; execute (if ((argument (test (logical_test (logical_test (comparison (comparison (expr (expr (atom (name t))) - (expr (atom (number (integer 1)))))) in (comparison (expr (atom (name T)))))) and (logical_test (comparison (comparison (expr (expr (atom (name t))) + (expr (atom (number (integer 1)))))) in (comparison (expr (atom (name T)))))))) (comp_for for (exprlist (expr (atom (name t)))) in (logical_test (comparison (expr (atom (name T))))))))->exists( _x | _x = true ) then 'YES' else 'NO' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def func(a,b,c): if 0toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( for k : Integer.subrange(0, n-1) do ( if i /= j & i /= k & j /= k then ( if func(l[i+1], l[j+1], l[k+1]) = 1 then ( m := 1 ) else skip ) else skip)) ; if m = 1 then ( break ) else skip) ; if m = 1 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); operation func(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: if 0 < (a - b)->abs() & (a - b)->abs() <= 2 & 0 < (b - c)->abs() & (c - b)->abs() <= 2 & 0 < (a - c)->abs() & (a - c)->abs() <= 2 then ( return 1 ) else ( return 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get(l : list)->str : l.sort() for i in l : if i+1 in l and i+2 in l : return "YES" return "NO" if __name__=='__main__' : n=int(input()) lst=input().split() lst=[int(x)for x in lst] print(get(lst)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : OclAny := input().split() ; lst := lst->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (get(lst))->display() ) else skip; operation get(l : Sequence(OclAny)) : String pre: true post: true activity: l := l->sort() ; for i : l do ( if (l)->includes(i + 1) & (l)->includes(i + 2) then ( return "YES" ) else skip) ; return "NO"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def is_sankaku(v): x=(math.sqrt(8*v+1)-1)/2 return x==int(x) def check(lst): for i,v in enumerate(lst): if v!=i+1 : return False elif i==len(lst)-1 : return True while 1 : N=int(input()) if N==0 : break lst=list(map(int,input().split())) if not is_sankaku(sum(lst)): print(-1) continue result=-1 for count in range(10000): if check(lst): result=count break spam=len(lst) lst=[x-1 for x in lst if x-1>0] lst.append(spam) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; while 1 do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; lst := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if not(is_sankaku((lst)->sum())) then ( execute (-1)->display() ; continue ) else skip ; var result : int := -1 ; for count : Integer.subrange(0, 10000-1) do ( if check(lst) then ( result := count ; break ) else skip ; var spam : int := (lst)->size() ; lst := lst->select(x | x - 1 > 0)->collect(x | (x - 1)) ; execute ((spam) : lst)) ; execute (result)->display()); operation is_sankaku(v : OclAny) : OclAny pre: true post: true activity: var x : double := ((8 * v + 1)->sqrt() - 1) / 2 ; return x = ("" + ((x)))->toInteger(); operation check(lst : OclAny) : OclAny pre: true post: true activity: for _tuple : Integer.subrange(1, (lst)->size())->collect( _indx | Sequence{_indx-1, (lst)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if v /= i + 1 then ( return false ) else (if i = (lst)->size() - 1 then ( return true ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=list(range(1,100000)) tri_num=set(i*(i+1)//2 for i in range(1,100000)) while True : N=int(input()) if N==0 : break b=list(map(int,input().split())) if sum(b)not in tri_num : print(-1) continue ans=0 while True : flag=True for i in range(len(b)): if b[i]!=l[i]: flag=False if flag : print(ans) break for i in range(len(b)): b[i]-=1 b.append(len(b)); b=[bi for bi in b if bi!=0] ans+=1 if ans>10000 : print(-1) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := (Integer.subrange(1, 100000-1)) ; var tri_num : Set := Set{}->union(((argument (test (logical_test (comparison (expr (expr (expr (atom (name i))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) )))) // (expr (atom (number (integer 2)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 100000))))))))) )))))))))) ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (tri_num)->excludes((b)->sum()) then ( execute (-1)->display() ; continue ) else skip ; var ans : int := 0 ; while true do ( var flag : boolean := true ; for i : Integer.subrange(0, (b)->size()-1) do ( if b[i+1] /= l[i+1] then ( flag := false ) else skip) ; if flag then ( execute (ans)->display() ; break ) else skip ; for i : Integer.subrange(0, (b)->size()-1) do ( b[i+1] := b[i+1] - 1) ; execute (((b)->size()) : b); ; b := b->select(bi | bi /= 0)->collect(bi | (bi)) ; ans := ans + 1 ; if ans > 10000 then ( execute (-1)->display() ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=list(map(int,input().split())) max=max(s) min=min(s) support=0 for person in s : if person>min and persontoInteger() ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var max : OclAny := (s)->max() ; var min : OclAny := (s)->min() ; var support : int := 0 ; for person : s do ( if (person->compareTo(min)) > 0 & (person->compareTo(max)) < 0 then ( support := support + 1 ) else skip) ; execute (support)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,datetime PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") def is_triangle(heights): if heights[0]!=1 : return False L=len(heights) diffs=[heights[k]-heights[k-1]for k in range(1,L)] return diffs==[1]*(L-1) def solve(n,heights): steps=0 while steps<10000 : if is_triangle(heights): return steps L=len(heights) for k in range(L): heights[k]-=1 heights.append(L) while heights.count(0)>0 : del heights[heights.index(0)] steps+=1 return-1 while True : n=int(input()) if n==0 : break heights=[int(_)for _ in input().split()] print(solve(n,heights)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; skip ; skip ; while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; heights := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; execute (solve(n, heights))->display()); operation is_triangle(heights : OclAny) : OclAny pre: true post: true activity: if heights->first() /= 1 then ( return false ) else skip ; var L : int := (heights)->size() ; var diffs : Sequence := Integer.subrange(1, L-1)->select(k | true)->collect(k | (heights[k+1] - heights[k - 1+1])) ; return diffs = MatrixLib.elementwiseMult(Sequence{ 1 }, (L - 1)); operation solve(n : OclAny, heights : OclAny) : OclAny pre: true post: true activity: var steps : int := 0 ; while steps < 10000 do ( if is_triangle(heights) then ( return steps ) else skip ; L := (heights)->size() ; for k : Integer.subrange(0, L-1) do ( heights[k+1] := heights[k+1] - 1) ; execute ((L) : heights) ; while heights->count(0) > 0 do ( execute (heights[heights->indexOf(0) - 1+1])->isDeleted()) ; steps := steps + 1) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Sankakusu(N): tmp=0 i=1 while tmptoInteger() ; if n = 0 then ( break ) else skip ; var count : int := 0 ; var block : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if not(Sankakusu((block)->sum())) then ( execute (-1)->display() ) else ( while true do ( if Step_Check(block) then ( execute (count)->display() ; break ) else ( count := count + 1 ; var len_b : int := (block)->size() ; for j : Integer.subrange(0, len_b-1) do ( block[j+1] := block[j+1] - 1) ; execute ((len_b) : block) ; while (block)->includes(0) do ( execute ((0) /: block)) ) ; if count = 10001 then ( execute (-1)->display() ; break ) else skip) )); operation Sankakusu(N : OclAny) : OclAny pre: true post: true activity: var tmp : int := 0 ; var i : int := 1 ; while (tmp->compareTo(N)) < 0 do ( tmp := (i * (i + 1)) / 2 ; i := i + 1) ; if tmp = N then ( return true ) else ( return false ); operation Step_Check(List : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, (List)->size()-1) do ( if List[i+1] /= i + 1 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : N=int(input()) if N==0 : break b=list(map(int,input().split())) cnt=0 while cnt<=10000 : tri_num=True if b[0]!=1 : tri_num=False for i in range(1,len(b)): if b[i]!=b[i-1]+1 : tri_num=False break if tri_num : break new_column=len(b) b_tmp=[] for i in b : if i>1 : b_tmp.append(i-1) b=b_tmp b.append(new_column) cnt+=1 if cnt<=10000 : print(cnt) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : int := 0 ; while cnt <= 10000 do ( var tri_num : boolean := true ; if b->first() /= 1 then ( tri_num := false ) else skip ; for i : Integer.subrange(1, (b)->size()-1) do ( if b[i+1] /= b[i - 1+1] + 1 then ( tri_num := false ; break ) else skip) ; if tri_num then ( break ) else skip ; var new_column : int := (b)->size() ; var b_tmp : Sequence := Sequence{} ; for i : b do ( if i > 1 then ( execute ((i - 1) : b_tmp) ) else skip) ; b := b_tmp ; execute ((new_column) : b) ; cnt := cnt + 1) ; if cnt <= 10000 then ( execute (cnt)->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def harmonicMean(arr,freq,n): sm=0 frequency_sum=0 for i in range(0,n): sm=sm+freq[i]/arr[i] frequency_sum=frequency_sum+freq[i] return(round(frequency_sum/sm,4)) num=[13,14,15,16,17] freq=[2,5,13,7,3] n=len(num) print(harmonicMean(num,freq,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var num : Sequence := Sequence{13}->union(Sequence{14}->union(Sequence{15}->union(Sequence{16}->union(Sequence{ 17 })))) ; freq := Sequence{2}->union(Sequence{5}->union(Sequence{13}->union(Sequence{7}->union(Sequence{ 3 })))) ; n := (num)->size() ; execute (harmonicMean(num, freq, n))->display(); operation harmonicMean(arr : OclAny, freq : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sm : int := 0 ; var frequency_sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sm := sm + freq[i+1] / arr[i+1] ; frequency_sum := frequency_sum + freq[i+1]) ; return (MathLib.roundN(frequency_sum / sm, 4)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def accumulate(s): acc=0 ; for i in range(len(s)): acc+=ord(s[i])-48 ; return acc ; def isDivisible(s): n=len(s); if(s[n-1]!='5' and s[n-1]!='0'): return False ; sum=accumulate(s); return(sum % 3==0); s="15645746327462384723984023940239" ; if isDivisible(s): print("Yes"); else : print("No"); s="15645746327462384723984023940235" ; if isDivisible(s): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; s := "15645746327462384723984023940239"; ; if isDivisible(s) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ; s := "15645746327462384723984023940235"; ; if isDivisible(s) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ); operation accumulate(s : OclAny) pre: true post: true activity: var acc : int := 0; ; for i : Integer.subrange(0, (s)->size()-1) do ( acc := acc + (s[i+1])->char2byte() - 48;) ; return acc;; operation isDivisible(s : OclAny) pre: true post: true activity: var n : int := (s)->size(); ; if (s[n - 1+1] /= '5' & s[n - 1+1] /= '0') then ( return false; ) else skip ; var sum : OclAny := accumulate(s); ; return (sum mod 3 = 0);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib,itertools def compute(): def find_sum(limit): for a in itertools.count(1): if a*a>=limit : break for b in reversed(range(1,a)): if(a+b)% 2!=0 : continue x=(a*a+b*b)//2 y=(a*a-b*b)//2 if x+y+1>=limit : continue zlimit=min(y,limit-x-y) for c in itertools.count(eulerlib.sqrt(y)+1): z=c*c-y if z>=zlimit : break if issquare[x+z]and issquare[x-z]and issquare[y-z]: return x+y+z return None sumlimit=10 while True : issquare=[False]*sumlimit for i in range(eulerlib.sqrt(len(issquare)-1)+1): issquare[i*i]=True sum=find_sum(sumlimit) if sum is not None : sum=sumlimit break sumlimit*=10 while True : sum=find_sum(sumlimit) if sum is None : return str(sumlimit) sumlimit=sum if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: skip ; var sumlimit : int := 10 ; while true do ( var issquare : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, sumlimit) ; for i : Integer.subrange(0, eulerlib.sqrt((issquare)->size() - 1) + 1-1) do ( issquare[i * i+1] := true) ; var sum : OclAny := find_sum(sumlimit) ; if not(sum <>= null) then ( sum := sumlimit ; break ) else skip ; sumlimit := sumlimit * 10) ; while true do ( sum := find_sum(sumlimit) ; if sum <>= null then ( return ("" + ((sumlimit))) ) else skip ; sumlimit := sum); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- number=input() a,b,k=[int(ele)for ele in number.split(' ')] res=a-k if res<0 : a=0 b=b+res b=0 if b<0 else b else : a=res print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var number : String := (OclFile["System.in"]).readLine() ; var a : OclAny := null; var b : OclAny := null; var k : OclAny := null; Sequence{a,b,k} := number.split(' ')->select(ele | true)->collect(ele | (("" + ((ele)))->toInteger())) ; var res : double := a - k ; if res < 0 then ( var a : int := 0 ; var b : OclAny := b + res ; b := if b < 0 then 0 else b endif ) else ( a := res ) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines sys.setrecursionlimit(500000) a,b,k=map(int,readline().split()) acc=min(a,k) a-=acc k-=acc acc=min(b,k) b-=acc print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; sys.setrecursionlimit(500000) ; var a : OclAny := null; var b : OclAny := null; var k : OclAny := null; Sequence{a,b,k} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var acc : OclAny := Set{a, k}->min() ; a := a - acc ; k := k - acc ; acc := Set{b, k}->min() ; b := b - acc ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): numbers=input().split(" ") takahashi=int(numbers[0]) aoki=int(numbers[1]) repeat=int(numbers[2]) if repeat==0 : pass elif takahashi>=repeat and takahashi>0 : takahashi-=repeat elif aoki==0 : takahashi-=min(takahashi,repeat) elif takahashi==0 and aoki>=repeat : aoki-=repeat elif takahashi+aokifirst())))->toInteger() ; var aoki : int := ("" + ((numbers[1+1])))->toInteger() ; var repeat : int := ("" + ((numbers[2+1])))->toInteger() ; if repeat = 0 then ( skip ) else (if (takahashi->compareTo(repeat)) >= 0 & takahashi > 0 then ( takahashi := takahashi - repeat ) else (if aoki = 0 then ( takahashi := takahashi - Set{takahashi, repeat}->min() ) else (if takahashi = 0 & (aoki->compareTo(repeat)) >= 0 then ( aoki := aoki - repeat ) else (if (takahashi + aoki->compareTo(repeat)) < 0 then ( aoki := 0 ; takahashi := 0 ) else ( aoki := aoki + takahashi ; aoki := aoki - repeat ; takahashi := 0 ) ) ) ) ) ; execute (("" + ((takahashi))) + " " + ("" + ((aoki))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,k=map(int,input().split()) if k>0 and k>=a : k-=a a=0 else : a-=k k=0 if k>0 and k>=b : k-=b b=0 else : b-=k k=0 print('{}{}'.format(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var k : OclAny := null; Sequence{a,b,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if k > 0 & (k->compareTo(a)) >= 0 then ( k := k - a ; var a : int := 0 ) else ( a := a - k ; var k : int := 0 ) ; if k > 0 & (k->compareTo(b)) >= 0 then ( k := k - b ; var b : int := 0 ) else ( b := b - k ; k := 0 ) ; execute (StringLib.interpolateStrings('{}{}', Sequence{a, b}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cookies=[int(x)for x in input().split()] leftOver=cookies[0]-cookies[2] takahashi=max(0,leftOver) print(str(takahashi)+' '+(str(cookies[1])if takahashi>0 else str(max(0,cookies[1]-abs(leftOver))))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cookies : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var leftOver : double := cookies->first() - cookies[2+1] ; var takahashi : OclAny := Set{0, leftOver}->max() ; execute (("" + ((takahashi))) + ' ' + (if takahashi > 0 then ("" + ((cookies[1+1]))) else ("" + ((Set{0, cookies[1+1] - (leftOver)->abs()}->max()))) endif))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) y1=input().split() y=[]; s=0 for i in y1 : y.append(int(i)) a,b=min(y),max(y) for i in y : if ia : s+=1 print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var y1 : OclAny := input().split() ; var y : Sequence := Sequence{}; var s : int := 0 ; for i : y1 do ( execute ((("" + ((i)))->toInteger()) : y)) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{(y)->min(),(y)->max()} ; for i : y do ( if (i->compareTo(b)) < 0 & (i->compareTo(a)) > 0 then ( s := s + 1 ) else skip) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isVowel(c): return(c=='a' or c=='e' or c=='i' or c=='o' or c=='u') def encryptString(s,n,k): countVowels=0 countConsonants=0 ans="" for l in range(n-k+1): countVowels=0 countConsonants=0 for r in range(l,l+k): if(isVowel(s[r])==True): countVowels+=1 else : countConsonants+=1 ans+=(str)(countVowels*countConsonants) return ans if __name__=='__main__' : s="hello" n=len(s) k=2 print(encryptString(s,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( s := "hello" ; n := (s)->size() ; k := 2 ; execute (encryptString(s, n, k))->display() ) else skip; operation isVowel(c : OclAny) : OclAny pre: true post: true activity: return (c = 'a' or c = 'e' or c = 'i' or c = 'o' or c = 'u'); operation encryptString(s : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var countVowels : int := 0 ; var countConsonants : int := 0 ; var ans : String := "" ; for l : Integer.subrange(0, n - k + 1-1) do ( countVowels := 0 ; countConsonants := 0 ; for r : Integer.subrange(l, l + k-1) do ( if (isVowel(s[r+1]) = true) then ( countVowels := countVowels + 1 ) else ( countConsonants := countConsonants + 1 )) ; ans := ans + (OclType["String"])(countVowels * countConsonants)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect def gcd(a,b): if b==0 : return abs(a) else : return gcd(b,a % b) N,M=map(int,input().split()) S=input() T=input() if S[0]!=T[0]: print(-1) exit() if len(S)==len(T): if S==T : print(len(S)) else : print(-1) exit() gcd1=gcd(len(S),len(T)) lcm=len(S)*len(T)//gcd1 SS=[] TT=[] i=0 j=0 while icollect( _x | (OclType["int"])->apply(_x) ) ; var S : String := (OclFile["System.in"]).readLine() ; var T : String := (OclFile["System.in"]).readLine() ; if S->first() /= T->first() then ( execute (-1)->display() ; exit() ) else skip ; if (S)->size() = (T)->size() then ( if S = T then ( execute ((S)->size())->display() ) else ( execute (-1)->display() ) ; exit() ) else skip ; var gcd1 : OclAny := gcd((S)->size(), (T)->size()) ; var lcm : int := (S)->size() * (T)->size() div gcd1 ; var SS : Sequence := Sequence{} ; var TT : Sequence := Sequence{} ; var i : int := 0 ; var j : int := 0 ; while (i->compareTo(N)) < 0 do ( execute ((i * lcm div N + 1) : SS) ; i := i + 1) ; while (j->compareTo(M)) < 0 do ( execute ((j * lcm div M + 1) : TT) ; j := j + 1) ; var ind : int := 0 ; var ind_max : double := j - 1 ; for _tuple : Integer.subrange(1, (SS)->size())->collect( _indx | Sequence{_indx-1, (SS)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); ind := bisect.bisect_left(TT, v, ind, j) ; if ind = j then ( break ) else skip ; if TT[ind+1] = v then ( if S[i+1] = T[ind+1] then ( continue ) else ( execute (-1)->display() ; exit() ) ) else skip) ; execute (lcm)->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if b = 0 then ( return (a)->abs() ) else ( return gcd(b, a mod b) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import tan def polyarea(n,a): if(a<0 and n<0): return-1 A=(a*a*n)/(4*tan((180/n)*3.14159/180)) return A if __name__=='__main__' : a=9 n=6 print('{0:.6}'.format(polyarea(n,a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( a := 9 ; n := 6 ; execute (StringLib.interpolateStrings('{0:.6}', Sequence{polyarea(n, a)}))->display() ) else skip; operation polyarea(n : OclAny, a : OclAny) : OclAny pre: true post: true activity: if (a < 0 & n < 0) then ( return -1 ) else skip ; var A : double := (a * a * n) / (4 * tan((180 / n) * 3.14159 / 180)) ; return A; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect,collections,copy,itertools,math,string import sys def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def main(): from functools import reduce def lcm_base(n1,n2): return(n1*n2)//math.gcd(n1,n2) def lcm(*numbers): return reduce(lcm_base,numbers) n,m=LI() s=S() t=S() l1=lcm(n,m) s_unit=l1//n t_unit=l1//m l2=lcm(s_unit,t_unit) time=(l1-1)//l2+1 itr=[l2*i for i in range(time)] ans=l1 for i in itr : si=i//s_unit ti=i//t_unit if s[si]!=t[ti]: ans=-1 print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; main(); operation I() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.readLine().rstrip())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )); operation S() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation LS() : OclAny pre: true post: true activity: return (sys.stdin.readLine().rstrip().split()); operation main() pre: true post: true activity: skip ; skip ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := LI() ; var s : OclAny := S() ; var t : OclAny := S() ; var l1 : OclAny := lcm(n, m) ; var s_unit : int := l1 div n ; var t_unit : int := l1 div m ; var l2 : OclAny := lcm(s_unit, t_unit) ; var time : int := (l1 - 1) div l2 + 1 ; var itr : Sequence := Integer.subrange(0, time-1)->select(i | true)->collect(i | (l2 * i)) ; var ans : OclAny := l1 ; for i : itr do ( var si : int := i div s_unit ; var ti : int := i div t_unit ; if s[si+1] /= t[ti+1] then ( ans := -1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re from collections import deque,defaultdict,Counter from math import sqrt,hypot,factorial,pi,sin,cos,radians from heapq import heappop,heappush,heapify,heappushpop from bisect import bisect_left,bisect_right from itertools import permutations,combinations,product from operator import itemgetter,mul from copy import deepcopy from functools import reduce,partial from fractions import Fraction from string import ascii_lowercase,ascii_uppercase,digits def input(): return sys.stdin.readline().strip() def ceil(a,b=1): return int(-(-a//b)) def round(x): return int((x*2+1)//2) def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) sys.setrecursionlimit(10**9) INF=float('inf') MOD=10**9+7 def gcd(a,b): while b>0 : a,b=b,a % b return a def lcm_base(x,y): return(x*y)//gcd(x,y) N,M=MAP() S=input() T=input() lcm=lcm_base(N,M) N_gap=lcm//N M_gap=lcm//M for i in range(0,lcm,lcm//gcd(N,M)): if i % N_gap==0 and i % M_gap==0 : if S[i//N_gap]!=T[i//M_gap]: print(-1) exit() print(lcm) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := MAP() ; var S : String := (OclFile["System.in"]).readLine() ; var T : String := (OclFile["System.in"]).readLine() ; var lcm : OclAny := lcm_base(N, M) ; var N_gap : int := lcm div N ; var M_gap : int := lcm div M ; for i : Integer.subrange(0, lcm-1)->select( $x | ($x - 0) mod lcm div gcd(N, M) = 0 ) do ( if i mod N_gap = 0 & i mod M_gap = 0 then ( if S[i div N_gap+1] /= T[i div M_gap+1] then ( execute (-1)->display() ; exit() ) else skip ) else skip) ; execute (lcm)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation ceil(a : OclAny, b : int) : OclAny pre: true post: true activity: if b->oclIsUndefined() then b := 1 else skip; return ("" + ((-(-a div b))))->toInteger(); operation round(x : OclAny) : OclAny pre: true post: true activity: return ("" + (((x * 2 + 1) div 2)))->toInteger(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: while b > 0 do ( Sequence{a,b} := Sequence{b,a mod b}) ; return a; operation lcm_base(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return (x * y) div gcd(x, y); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) S=input() T=input() list_S=list(S) list_T=list(T) Number_i=[i for i in range(N)] Number_iMN=[] for i in Number_i : Number_iMN.append(i*M/N) Number_j=[j for j in range(M)] Kaburi_j=list(set(Number_iMN)& set(Number_j)) Kaburi_i=[] for j in Kaburi_j : Kaburi_i.append(int(j*N/M)) counter=0 Flag=0 Kaburi_Size=len(Kaburi_i) while counter<=Kaburi_Size-1 : if list_S[int(Kaburi_i[counter])]==list_T[int(Kaburi_j[counter])]: pass else : Flag=1 break counter+=1 def gcd(a,b): while b>0 : a,b=b,a % b return a if Flag==1 : print(-1) else : print(int(N*M/gcd(N,M))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : String := (OclFile["System.in"]).readLine() ; var T : String := (OclFile["System.in"]).readLine() ; var list_S : Sequence := (S)->characters() ; var list_T : Sequence := (T)->characters() ; var Number_i : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (i)) ; var Number_iMN : Sequence := Sequence{} ; for i : Number_i do ( execute ((i * M / N) : Number_iMN)) ; var Number_j : Sequence := Integer.subrange(0, M-1)->select(j | true)->collect(j | (j)) ; var Kaburi_j : Sequence := (MathLib.bitwiseAnd(Set{}->union((Number_iMN)), Set{}->union((Number_j)))) ; var Kaburi_i : Sequence := Sequence{} ; for j : Kaburi_j do ( execute ((("" + ((j * N / M)))->toInteger()) : Kaburi_i)) ; var counter : int := 0 ; var Flag : int := 0 ; var Kaburi_Size : int := (Kaburi_i)->size() ; while (counter->compareTo(Kaburi_Size - 1)) <= 0 do ( if list_S[("" + ((Kaburi_i[counter+1])))->toInteger()+1] = list_T[("" + ((Kaburi_j[counter+1])))->toInteger()+1] then ( skip ) else ( Flag := 1 ; break ) ; counter := counter + 1) ; skip ; if Flag = 1 then ( execute (-1)->display() ) else ( execute (("" + ((N * M / gcd(N, M))))->toInteger())->display() ); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: while b > 0 do ( Sequence{a,b} := Sequence{b,a mod b}) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import fractions N,M=map(int,input().split()) S=input() T=input() x=fractions.gcd(N,M) a=[] b=[] for i in range(int(x)): a.append(S[int(i*N/x)]) for i in range(int(x)): b.append(T[int(i*M/x)]) if a==b : print(int(N*M/x)) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : String := (OclFile["System.in"]).readLine() ; var T : String := (OclFile["System.in"]).readLine() ; var x : int := fractions.gcd(N, M) ; var a : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; for i : Integer.subrange(0, ("" + ((x)))->toInteger()-1) do ( execute ((S[("" + ((i * N / x)))->toInteger()+1]) : a)) ; for i : Integer.subrange(0, ("" + ((x)))->toInteger()-1) do ( execute ((T[("" + ((i * M / x)))->toInteger()+1]) : b)) ; if a = b then ( execute (("" + ((N * M / x)))->toInteger())->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=lambda : stdin.readline()[:-1] n,m=map(int,input().split()) black=[[False]*(n+10)for i in range(n+10)] for i in range(1,m+1): x,y=map(lambda x : int(x)+5,input().split()) black[x][y]=True for lx in range(x-2,x+1): for ly in range(y-2,y+1): cnt=0 for dx in range(3): for dy in range(3): cnt+=black[lx+dx][ly+dy] if cnt==9 : print(i) exit() print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (stdin.readLine()->front()) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var black : Sequence := Integer.subrange(0, n + 10-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ false }, (n + 10)))) ; for i : Integer.subrange(1, m + 1-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input->apply().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() + 5))->apply(_x) ) ; black[x+1][y+1] := true ; for lx : Integer.subrange(x - 2, x + 1-1) do ( for ly : Integer.subrange(y - 2, y + 1-1) do ( var cnt : int := 0 ; for dx : Integer.subrange(0, 3-1) do ( for dy : Integer.subrange(0, 3-1) do ( cnt := cnt + black[lx + dx+1][ly + dy+1])) ; if cnt = 9 then ( execute (i)->display() ; exit() ) else skip))) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) z=[[0]*(a+4)for i in range(a+4)] def gh(i,j): for i1 in range(i-2,i+1): for j1 in range(j-2,j+1): if i1<1 or j1<1 : continue ok=True for i2 in range(i1,i1+3): for j2 in range(j1,j1+3): if z[i2][j2]==0 : ok=False ; break if not(ok): break if ok : return ok return False for _ in range(1,b+1): u,v=map(int,input().split()) z[u][v]=1 if gh(u,v): exit(print(_)) print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var z : Sequence := Integer.subrange(0, a + 4-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (a + 4)))) ; skip ; for _anon : Integer.subrange(1, b + 1-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; z[u+1][v+1] := 1 ; if gh(u, v) then ( exit((_anon)->display()) ) else skip) ; execute (-1)->display(); operation gh(i : OclAny, j : OclAny) : OclAny pre: true post: true activity: for i1 : Integer.subrange(i - 2, i + 1-1) do ( for j1 : Integer.subrange(j - 2, j + 1-1) do ( if i1 < 1 or j1 < 1 then ( continue ) else skip ; var ok : boolean := true ; for i2 : Integer.subrange(i1, i1 + 3-1) do ( for j2 : Integer.subrange(j1, j1 + 3-1) do ( if z[i2+1][j2+1] = 0 then ( ok := false; break ) else skip) ; if not((ok)) then ( break ) else skip) ; if ok then ( return ok ) else skip)) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin a,b=map(int,stdin.readline().split()) z=[[0]*(a+4)for i in range(a+4)] def gh(i,j): for i1 in range(i-2,i+1): for j1 in range(j-2,j+1): if i1<1 or j1<1 : continue ok=True for i2 in range(i1,i1+3): for j2 in range(j1,j1+3): if z[i2][j2]==0 : ok=False ; break if not(ok): break if ok : return ok return False for _ in range(1,b+1): u,v=map(int,stdin.readline().split()) z[u][v]=1 if gh(u,v): exit(print(_)) print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var z : Sequence := Integer.subrange(0, a + 4-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (a + 4)))) ; skip ; for _anon : Integer.subrange(1, b + 1-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; z[u+1][v+1] := 1 ; if gh(u, v) then ( exit((_anon)->display()) ) else skip) ; execute (-1)->display(); operation gh(i : OclAny, j : OclAny) : OclAny pre: true post: true activity: for i1 : Integer.subrange(i - 2, i + 1-1) do ( for j1 : Integer.subrange(j - 2, j + 1-1) do ( if i1 < 1 or j1 < 1 then ( continue ) else skip ; var ok : boolean := true ; for i2 : Integer.subrange(i1, i1 + 3-1) do ( for j2 : Integer.subrange(j1, j1 + 3-1) do ( if z[i2+1][j2+1] = 0 then ( ok := false; break ) else skip) ; if not((ok)) then ( break ) else skip) ; if ok then ( return ok ) else skip)) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) n,m=R() if n<3 or m<9 : print(-1) exit() a=[[0]*(n-2)for i in range(n-2)] for i in range(1,m+1): x,y=R() x-=1 y-=1 for x0 in range(x-2,x+1): for y0 in range(y-2,y+1): if x0<0 or y0<0 or x0>=n-2 or y0>=n-2 : continue a[x0][y0]+=1 if a[x0][y0]==9 : print(i) exit() print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := R->apply() ; if n < 3 or m < 9 then ( execute (-1)->display() ; exit() ) else skip ; var a : Sequence := Integer.subrange(0, n - 2-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (n - 2)))) ; for i : Integer.subrange(1, m + 1-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := R->apply() ; x := x - 1 ; y := y - 1 ; for x0 : Integer.subrange(x - 2, x + 1-1) do ( for y0 : Integer.subrange(y - 2, y + 1-1) do ( if x0 < 0 or y0 < 0 or (x0->compareTo(n - 2)) >= 0 or (y0->compareTo(n - 2)) >= 0 then ( continue ) else skip ; a[x0+1][y0+1] := a[x0+1][y0+1] + 1 ; if a[x0+1][y0+1] = 9 then ( execute (i)->display() ; exit() ) else skip))) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) l.sort() m=l[0] i=0 while i=0 and l[j]==m : j-=1 print(j-i+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := l->sort() ; var m : OclAny := l->first() ; var i : int := 0 ; while (i->compareTo(n)) < 0 & l[i+1] = m do ( i := i + 1) ; if i = n then ( execute (0)->display() ) else ( var j : double := n - 1 ; m := l->last() ; while j >= 0 & l[j+1] = m do ( j := j - 1) ; execute (j - i + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve_case(): n,m=map(int,input().split()) count=[None]*n for i in range(n): count[i]=[0]*n ans=-1 for k in range(m): x,y=map(int,input().split()) x-=1 y-=1 found=False for i in range(x-2,x+1): for j in range(y-2,y+1): if i>=0 and i=0 and jcollect( _x | (OclType["int"])->apply(_x) ) ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; for i : Integer.subrange(0, n-1) do ( count[i+1] := MatrixLib.elementwiseMult(Sequence{ 0 }, n)) ; var ans : int := -1 ; for k : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; x := x - 1 ; y := y - 1 ; var found : boolean := false ; for i : Integer.subrange(x - 2, x + 1-1) do ( for j : Integer.subrange(y - 2, y + 1-1) do ( if i >= 0 & (i->compareTo(n)) < 0 & j >= 0 & (j->compareTo(n)) < 0 then ( count[i+1][j+1] := count[i+1][j+1] + 1 ; if count[i+1][j+1] = 9 then ( found := true ) else skip ) else skip)) ; if found then ( ans := k + 1 ; break ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def __gcd(a,b): if(a==0): return b ; if(b==0): return a ; if(a==b): return a ; if(a>b): return __gcd(a-b,b); return __gcd(a,b-a); def lcm(a,b): return(a/__gcd(a,b)*b); def getMinValue(c): ans=sys.maxsize ; for i in range(1,int(pow(c,1/2))+1): if(c % i==0 and lcm(i,c/i)==c): ans=min(ans,max(i,c/i)); return int(ans); if __name__=='__main__' : c=6 ; print(getMinValue(c)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( c := 6; ; execute (getMinValue(c))->display(); ) else skip; operation __gcd(a : OclAny, b : OclAny) pre: true post: true activity: if (a = 0) then ( return b; ) else skip ; if (b = 0) then ( return a; ) else skip ; if (a = b) then ( return a; ) else skip ; if ((a->compareTo(b)) > 0) then ( return __gcd(a - b, b); ) else skip ; return __gcd(a, b - a);; operation lcm(a : OclAny, b : OclAny) pre: true post: true activity: return (a / __gcd(a, b) * b);; operation getMinValue(c : OclAny) pre: true post: true activity: var ans : (trailer . (name maxsize)) := (trailer . (name maxsize)); ; for i : Integer.subrange(1, ("" + (((c)->pow(1 / 2))))->toInteger() + 1-1) do ( if (c mod i = 0 & lcm(i, c / i) = c) then ( ans := Set{ans, Set{i, c / i}->max()}->min(); ) else skip) ; return ("" + ((ans)))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,bisect PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") def grid_length(n,grid): L=0 for row in grid : L=max(L,max([len(_)for _ in row.split('0')])) for c in range(n): col=''.join([grid[r][c]for r in range(n)]) L=max(L,max([len(_)for _ in col.split('0')])) for row in range(-n,2*n): diag=''.join([grid[row+c][c]for c in range(n)if 0<=row+ctoInteger() ; if n = 0 then ( break ) else skip ; grid := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (input()->trim())) ; execute (grid_length(n, grid))->display()); operation grid_length(n : OclAny, grid : OclAny) : OclAny pre: true post: true activity: var L : int := 0 ; for row : grid do ( L := Set{L, (row.split('0')->select(_anon | true)->collect(_anon | ((_anon)->size())))->max()}->max()) ; for c : Integer.subrange(0, n-1) do ( var col : String := StringLib.sumStringsWithSeparator((Integer.subrange(0, n-1)->select(r | true)->collect(r | (grid[r+1][c+1]))), '') ; L := Set{L, (col.split('0')->select(_anon | true)->collect(_anon | ((_anon)->size())))->max()}->max()) ; for row : Integer.subrange(-n, 2 * n-1) do ( var diag : String := StringLib.sumStringsWithSeparator((Integer.subrange(0, n-1)->select(c | 0 <= row + c & (row + c < n))->collect(c | (grid[row + c+1][c+1]))), '') ; L := Set{L, (diag.split('0')->select(_anon | true)->collect(_anon | ((_anon)->size())))->max()}->max() ; diag := StringLib.sumStringsWithSeparator((Integer.subrange(0, n-1)->select(c | 0 <= row - c & (row - c < n))->collect(c | (grid[row - c+1][c+1]))), '') ; L := Set{L, (diag.split('0')->select(_anon | true)->collect(_anon | ((_anon)->size())))->max()}->max()) ; return L; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def scanning_area(grid,length,point_list,stride_x,stride_y): area=[[0 for _ in range(length+1)]for __ in range(length+1)] max_length=0 for row,col in point_list : if grid[row][col]=="1" : area[row+stride_y][col+stride_x]=area[row][col]+1 max_length=max(max_length,area[row+stride_y][col+stride_x]) return max_length def create_point_list(length): points=[] for count,r in enumerate(range(length-1,0,-1),1): row=r for col in range(0,count,1): points.append((row,col)) row+=1 for index in range(0,length): points.append((index,index)) for lp in range(1,length): row=0 for col in range(lp,length): points.append((row,col)) row+=1 return points while True : length=int(input()) if length==0 : break grid=[input()for _ in range(length)] point_list=[[row,col]for row in range(length)for col in range(length)] line_length1=scanning_area(grid,length,point_list,1,0) line_length2=scanning_area(grid,length,point_list,0,1) point_list=create_point_list(length) line_length3=scanning_area(grid,length,point_list,1,1) point_list.reverse() line_length4=scanning_area(grid,length,point_list,-1,1) max_length=max(line_length1,line_length2,line_length3,line_length4) print(max_length) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( length := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if length = 0 then ( break ) else skip ; grid := Integer.subrange(0, length-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; point_list := Integer.subrange(0, length-1)->select(row; col : Integer.subrange(0, length-1) | true)->collect(row; col : Integer.subrange(0, length-1) | (Sequence{row}->union(Sequence{ col }))) ; var line_length1 : OclAny := scanning_area(grid, length, point_list, 1, 0) ; var line_length2 : OclAny := scanning_area(grid, length, point_list, 0, 1) ; point_list := create_point_list(length) ; var line_length3 : OclAny := scanning_area(grid, length, point_list, 1, 1) ; point_list := point_list->reverse() ; var line_length4 : OclAny := scanning_area(grid, length, point_list, -1, 1) ; max_length := Set{line_length1, line_length2, line_length3, line_length4}->max() ; execute (max_length)->display()); operation scanning_area(grid : OclAny, length : OclAny, point_list : OclAny, stride_x : OclAny, stride_y : OclAny) : OclAny pre: true post: true activity: var area : Sequence := Integer.subrange(0, length + 1-1)->select(__ | true)->collect(__ | (Integer.subrange(0, length + 1-1)->select(_anon | true)->collect(_anon | (0)))) ; var max_length : int := 0 ; for _tuple : point_list do (var _indx : int := 1; var row : OclAny := _tuple->at(_indx); _indx := _indx + 1; var col : OclAny := _tuple->at(_indx); if grid[row+1][col+1] = "1" then ( area[row + stride_y+1][col + stride_x+1] := area[row+1][col+1] + 1 ; max_length := Set{max_length, area[row + stride_y+1][col + stride_x+1]}->max() ) else skip) ; return max_length; operation create_point_list(length : OclAny) : OclAny pre: true post: true activity: var points : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (Integer.subrange(0 + 1, length - 1)->reverse(), 1)->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(0 + 1, length - 1)->reverse(), 1)->at(_indx)} ) do (var _indx : int := 1; var count : OclAny := _tuple->at(_indx); _indx := _indx + 1; var r : OclAny := _tuple->at(_indx); var row : OclAny := r ; for col : Integer.subrange(0, count-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( execute ((Sequence{row, col}) : points) ; row := row + 1)) ; for index : Integer.subrange(0, length-1) do ( execute ((Sequence{index, index}) : points)) ; for lp : Integer.subrange(1, length-1) do ( row := 0 ; for col : Integer.subrange(lp, length-1) do ( execute ((Sequence{row, col}) : points) ; row := row + 1)) ; return points; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): while True : n=int(input()) if n==0 : break mp=["0"+input()+"0" for _ in range(n)] mp.insert(0,"0"*(n+2)) mp.append("0"*(n+2)) score=[[[0]*4 for _ in range(n+2)]for _ in range(n+2)] max_score=0 for i in range(1,n+1): for j in range(1,n+1): if mp[i][j]=="1" : score[i][j][0]=score[i-1][j][0]+1 score[i][j][1]=score[i][j-1][1]+1 score[i][j][2]=score[i-1][j-1][2]+1 score[i][j][3]=score[i-1][j+1][3]+1 max_score=max(max_score,score[i][j][0],score[i][j][1],score[i][j][2],score[i][j][3]) else : for k in range(4): score[i][j][k]=0 print(max_score) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var mp : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ("0" + (OclFile["System.in"]).readLine() + "0")) ; mp := mp.insertAt(0+1, StringLib.nCopies("0", (n + 2))) ; execute ((StringLib.nCopies("0", (n + 2))) : mp) ; var score : Sequence := Integer.subrange(0, n + 2-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, n + 2-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 4))))) ; var max_score : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, n + 1-1) do ( if mp[i+1][j+1] = "1" then ( score[i+1][j+1]->first() := score[i - 1+1][j+1]->first() + 1 ; score[i+1][j+1][1+1] := score[i+1][j - 1+1][1+1] + 1 ; score[i+1][j+1][2+1] := score[i - 1+1][j - 1+1][2+1] + 1 ; score[i+1][j+1][3+1] := score[i - 1+1][j + 1+1][3+1] + 1 ; max_score := Set{max_score, score[i+1][j+1]->first(), score[i+1][j+1][1+1], score[i+1][j+1][2+1], score[i+1][j+1][3+1]}->max() ) else ( for k : Integer.subrange(0, 4-1) do ( score[i+1][j+1][k+1] := 0) ))) ; execute (max_score)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): while True : n=int(input()) if n==0 : break mp=["0"+input()+"0" for _ in range(n)] mp.insert(0,"0"*(n+2)) mp.append("0"*(n+2)) score=[[[0]*4 for _ in range(n+2)]for _ in range(n+2)] max_score=0 for i in range(1,n+1): for j in range(1,n+1): if mp[i][j]=="1" : score[i][j][0]=score[i-1][j][0]+1 score[i][j][1]=score[i][j-1][1]+1 score[i][j][2]=score[i-1][j-1][2]+1 score[i][j][3]=score[i-1][j+1][3]+1 max_score=max(max_score,score[i][j][0],score[i][j][1],score[i][j][2],score[i][j][3]) print(max_score) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var mp : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ("0" + (OclFile["System.in"]).readLine() + "0")) ; mp := mp.insertAt(0+1, StringLib.nCopies("0", (n + 2))) ; execute ((StringLib.nCopies("0", (n + 2))) : mp) ; var score : Sequence := Integer.subrange(0, n + 2-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, n + 2-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 4))))) ; var max_score : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, n + 1-1) do ( if mp[i+1][j+1] = "1" then ( score[i+1][j+1]->first() := score[i - 1+1][j+1]->first() + 1 ; score[i+1][j+1][1+1] := score[i+1][j - 1+1][1+1] + 1 ; score[i+1][j+1][2+1] := score[i - 1+1][j - 1+1][2+1] + 1 ; score[i+1][j+1][3+1] := score[i - 1+1][j + 1+1][3+1] + 1 ; max_score := Set{max_score, score[i+1][j+1]->first(), score[i+1][j+1][1+1], score[i+1][j+1][2+1], score[i+1][j+1][3+1]}->max() ) else skip)) ; execute (max_score)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def fourthPowerSum(n): return((6*n*n*n*n*n)+(15*n*n*n*n)+(10*n*n*n)-n)/30 n=6 print(fourthPowerSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 6 ; execute (fourthPowerSum(n))->display(); operation fourthPowerSum(n : OclAny) : OclAny pre: true post: true activity: return ((6 * n * n * n * n * n) + (15 * n * n * n * n) + (10 * n * n * n) - n) / 30; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def maxLenSub(arr,n): um=defaultdict(lambda : 0) maxLen=0 for i in range(0,n): length=0 if(arr[i]-1)in um and lengthunion(Sequence{5}->union(Sequence{6}->union(Sequence{3}->union(Sequence{7}->union(Sequence{6}->union(Sequence{5}->union(Sequence{ 8 }))))))) ; n := (arr)->size() ; execute ("Maximum length subsequence=")->display() ) else skip; operation maxLenSub(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var um : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; var maxLen : int := 0 ; for i : Integer.subrange(0, n-1) do ( var length : int := 0 ; if (um)->includes((arr[i+1] - 1)) & (length->compareTo(um[arr[i+1] - 1+1])) < 0 then ( length := um[arr[i+1] - 1+1] ) else skip ; if (um)->includes(arr[i+1]) & (length->compareTo(um[arr[i+1]+1])) < 0 then ( length := um[arr[i+1]+1] ) else skip ; if (um)->includes((arr[i+1] + 1)) & (length->compareTo(um[arr[i+1] + 1+1])) < 0 then ( length := um[arr[i+1] + 1+1] ) else skip ; um[arr[i+1]+1] := length + 1 ; if (maxLen->compareTo(um[arr[i+1]+1])) < 0 then ( maxLen := um[arr[i+1]+1] ) else skip) ; return maxLen; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- arr=[1,3,5,2,4,6] def rearrange(n): global arr if(n % 2==1): return currIdx=int((n-1)/2) while(currIdx>0): count=currIdx swapIdx=currIdx while(count>0): temp=arr[swapIdx+1] arr[swapIdx+1]=arr[swapIdx] arr[swapIdx]=temp swapIdx=swapIdx+1 count=count-1 currIdx=currIdx-1 n=len(arr) rearrange(n) for i in range(0,n): print("{}".format(arr[i]),end="") ------------------------------------------------------------ OCL File: --------- class FromPython { attribute arr : OclAny; operation initialise() pre: true post: true activity: var arr : Sequence := Sequence{1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 6 }))))) ; skip ; n := (arr)->size() ; rearrange(n) ; for i : Integer.subrange(0, n-1) do ( execute (StringLib.interpolateStrings("{}", Sequence{arr[i+1]}))->display()); operation rearrange(n : OclAny) pre: true post: true activity: skip ; if (n mod 2 = 1) then ( return ) else skip ; var currIdx : int := ("" + (((n - 1) / 2)))->toInteger() ; while (currIdx > 0) do ( var count : int := currIdx ; var swapIdx : int := currIdx ; while (count > 0) do ( var temp : OclAny := arr[swapIdx + 1+1] ; arr[swapIdx + 1+1] := arr[swapIdx+1] ; arr[swapIdx+1] := temp ; swapIdx := swapIdx + 1 ; count := count - 1) ; currIdx := currIdx - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from heapq import* r=sys.stdin.readline def g(n,E,S,G): F=[1e7]*-~ n ; F[S]=0 H=[(0,S)] while H : c,u=heappop(H) if u==G : return c for f,v in E[u]: t=c+f if ttoReal() }, -MathLib.bitwiseNot(n)); F[S+1] := 0 ; var H : Sequence := Sequence{ Sequence{0, S} } ; while H do ( var c : OclAny := null; var u : OclAny := null; Sequence{c,u} := heappop(H) ; if u = G then ( return c ) else skip ; for _tuple : E[u+1] do (var _indx : int := 1; var f : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); var t : OclAny := c + f ; if (t->compareTo(F[v+1])) < 0 then ( F[v+1] := t ; heappush(H, Sequence{t, v}) ) else skip)) ; return -1; operation s() pre: true post: true activity: for e : OclIterator.newOclIterator_Sequence(r, '0 0 ') do ( var k : OclAny := null; Sequence{n,k} := (e.split())->collect( _x | (OclType["int"])->apply(_x) ) ; E := MatrixLib.elementwiseMult(Sequence{ 0 }, -MathLib.bitwiseNot(n))->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, k) do ( var f : String := r() ; if '0' = f->first() then ( execute (g(n, E, (argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name f)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) :)) ])) (trailer . (name split) (arguments ( ))))))))) ))))))))))->display() ) else ( var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; Sequence{c,d,e} := (f.subrange(2+1).split())->collect( _x | (OclType["int"])->apply(_x) ) ; E[c+1] := E[c+1] + Sequence{ Sequence{e, d} }; E[d+1] := E[d+1] + Sequence{ Sequence{e, c} } ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : INF=10**9 N,K=map(int,input().split()) if N==K==0 : break E=[[INF]*N for i in range(N)] for i in range(N): E[i][i]=0 ans=[] for i in range(K): q,*c=map(int,input().split()) if q==0 : a,b=c cost=E[a-1][b-1] if INF<=cost : ans.append(-1) else : ans.append(cost) else : c,d,e=c if epow(9) ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if N = K & (K == 0) then ( break ) else skip ; var E : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ INF }, N))) ; for i : Integer.subrange(0, N-1) do ( E[i+1][i+1] := 0) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, K-1) do ( var q : OclAny := null; var c : OclAny := null; Sequence{q,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if q = 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := c ; var cost : OclAny := E[a - 1+1][b - 1+1] ; if (INF->compareTo(cost)) <= 0 then ( execute ((-1) : ans) ) else ( execute ((cost) : ans) ) ) else ( var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; Sequence{c,d,e} := c ; if (e->compareTo(E[c - 1+1][d - 1+1])) < 0 then ( E[c - 1+1][d - 1+1] := e; var E[d - 1+1][c - 1+1] : OclAny := e ; var Ec : OclAny := E[c - 1+1]; var Ed : OclAny := E[d - 1+1] ; for i : Integer.subrange(0, N-1) do ( var Ei : OclAny := E[i+1] ; var Eic : OclAny := Ei[c - 1+1] + e ; var Eid : OclAny := Ei[d - 1+1] + e ; for j : Integer.subrange(i + 1, N-1) do ( Ei[j+1] := Set{Ei[j+1], Eic + Ed[j+1], Eid + Ec[j+1]}->min(); var E[j+1][i+1] : OclAny := Set{Ei[j+1], Eic + Ed[j+1], Eid + Ec[j+1]}->min())) ) else skip )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) ma=max(l) mi=min(l) if len(l)==1 or l.count(l[0])==len(l): print(0) else : print(len(l)-l.count(ma)-l.count(mi)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ma : OclAny := (l)->max() ; var mi : OclAny := (l)->min() ; if (l)->size() = 1 or l->count(l->first()) = (l)->size() then ( execute (0)->display() ) else ( execute ((l)->size() - l->count(ma) - l->count(mi))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while(True): M,Nmin,Nmax=[int(n)for n in input().split()] if M+Nmin+Nmax==0 : break P=[int(input())for _ in range(M)] dif=[0]*(M) for i in range(len(P)-1): dif[i+1]=P[i]-P[i+1] ans=Nmin tmp=dif[Nmin] for i in range(Nmin+1,Nmax+1): if dif[i]>=tmp : ans=i tmp=dif[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while (true) do ( var M : OclAny := null; var Nmin : OclAny := null; var Nmax : OclAny := null; Sequence{M,Nmin,Nmax} := input().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; if M + Nmin + Nmax = 0 then ( break ) else skip ; var P : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var dif : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (M)) ; for i : Integer.subrange(0, (P)->size() - 1-1) do ( dif[i + 1+1] := P[i+1] - P[i + 1+1]) ; var ans : OclAny := Nmin ; var tmp : OclAny := dif[Nmin+1] ; for i : Integer.subrange(Nmin + 1, Nmax + 1-1) do ( if (dif[i+1]->compareTo(tmp)) >= 0 then ( ans := i ; tmp := dif[i+1] ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=float('inf') for e in iter(input,'0 0'): n,k=map(int,e.split()) F=[[I]*-~ n for _ in[0]*-~ n] for i in range(1,n+1): F[i][i]=0 for _ in[0]*k : f=input(); g=map(int,f[2 :].split()) if '0'==f[0]: a,b=g ; A=F[a][b]; print([A,-1][A==I]) else : c,d,e=g if etoReal() ; for e : OclIterator.newOclIterator_Sequence(input, '0 0') do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (e.split())->collect( _x | (OclType["int"])->apply(_x) ) ; var F : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, -MathLib.bitwiseNot(n))->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ I }, -MathLib.bitwiseNot(n)))) ; for i : Integer.subrange(1, n + 1-1) do ( F[i+1][i+1] := 0) ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, k) do ( var f : String := (OclFile["System.in"]).readLine(); var g : Sequence := (f.subrange(2+1).split())->collect( _x | (OclType["int"])->apply(_x) ) ; if '0' = f->first() then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := g; var A : OclAny := F[a+1][b+1]; execute (Sequence{A}->union(Sequence{ -1 })->select(A = I))->display() ) else ( var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; Sequence{c,d,e} := g ; if (e->compareTo(F[c+1][d+1])) < 0 then ( for i : Integer.subrange(2, n + 1-1) do ( for j : Integer.subrange(1, i-1) do ( F[i+1][j+1] := Set{F[i+1][j+1], F[i+1][c+1] + e + F[d+1][j+1], F[i+1][d+1] + e + F[c+1][j+1]}->min(); var F[j+1][i+1] : OclAny := Set{F[i+1][j+1], F[i+1][c+1] + e + F[d+1][j+1], F[i+1][d+1] + e + F[c+1][j+1]}->min())) ) else skip ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq,sys r=sys.stdin.readline def g(n,E,S,G): F=[1e7]*-~ n ; F[S]=0 ; H=[(0,S)] while H : c,u=heapq.heappop(H) if u==G : return c for f,v in E[u]: t=c+f if ttoReal() }, -MathLib.bitwiseNot(n)); F[S+1] := 0; var H : Sequence := Sequence{ Sequence{0, S} } ; while H do ( var c : OclAny := null; var u : OclAny := null; Sequence{c,u} := heapq.heappop(H) ; if u = G then ( return c ) else skip ; for _tuple : E[u+1] do (var _indx : int := 1; var f : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); var t : OclAny := c + f ; if (t->compareTo(F[v+1])) < 0 then ( F[v+1] := t; heapq.heappush(H, Sequence{t, v}) ) else skip)) ; return -1; operation s(n : OclAny, k : OclAny) pre: true post: true activity: E := MatrixLib.elementwiseMult(Sequence{ 0 }, -MathLib.bitwiseNot(n))->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, k) do ( var f : String := r(); var p : Sequence := (f.subrange(2+1).split())->collect( _x | (OclType["int"])->apply(_x) ) ; if '0' = f->first() then ( execute (g(n, E, (argument * (test (logical_test (comparison (expr (atom (name p)))))))))->display() ) else ( var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; Sequence{c,d,e} := p; E[c+1] := E[c+1] + Sequence{ Sequence{e, d} }; E[d+1] := E[d+1] + Sequence{ Sequence{e, c} } )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import* def g(n,E,s,g): F=[1e7]*-~ n ; F[s]=0 H=[(0,s)] while H : c,u=heappop(H) if u==g : return c for f,v in E[u]: t=c+f if ttoReal() }, -MathLib.bitwiseNot(n)); F[s+1] := 0 ; var H : Sequence := Sequence{ Sequence{0, s} } ; while H do ( var c : OclAny := null; var u : OclAny := null; Sequence{c,u} := heappop(H) ; if u = g then ( return c ) else skip ; for _tuple : E[u+1] do (var _indx : int := 1; var f : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); var t : OclAny := c + f ; if (t->compareTo(F[v+1])) < 0 then ( F[v+1] := t; heappush(H, Sequence{t, v}) ) else skip)) ; return -1; operation s() pre: true post: true activity: for e : OclIterator.newOclIterator_Sequence(input, '0 0') do ( var k : OclAny := null; Sequence{n,k} := (e.split())->collect( _x | (OclType["int"])->apply(_x) ) ; E := MatrixLib.elementwiseMult(Sequence{ 0 }, -MathLib.bitwiseNot(n))->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, k) do ( var f : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if f->first() then ( var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; Sequence{c,d,e} := f->tail() ; E[c+1] := E[c+1] + Sequence{ Sequence{e, d} }; E[d+1] := E[d+1] + Sequence{ Sequence{e, c} } ) else ( execute (g(n, E, (argument * (test (logical_test (comparison (expr (atom (name f)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))))))))->display() ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countCharacterType(str): vowels=0 consonant=0 specialChar=0 digit=0 for i in range(0,len(str)): ch=str[i] if((ch>='a' and ch<='z')or(ch>='A' and ch<='Z')): ch=ch.lower() if(ch=='a' or ch=='e' or ch=='i' or ch=='o' or ch=='u'): vowels+=1 else : consonant+=1 elif(ch>='0' and ch<='9'): digit+=1 else : specialChar+=1 print("Vowels:",vowels) print("Consonant:",consonant) print("Digit:",digit) print("Special Character:",specialChar) str="geeks for geeks121" countCharacterType(str) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclType["String"] := "geeks for geeks121" ; countCharacterType(OclType["String"]); operation countCharacterType(OclType["String"] : OclAny) pre: true post: true activity: var vowels : int := 0 ; var consonant : int := 0 ; var specialChar : int := 0 ; var digit : int := 0 ; for i : Integer.subrange(0, (OclType["String"])->size()-1) do ( var ch : String := ("" + ([i+1])) ; if ((ch >= 'a' & ch <= 'z') or (ch >= 'A' & ch <= 'Z')) then ( ch := ch->toLowerCase() ; if (ch = 'a' or ch = 'e' or ch = 'i' or ch = 'o' or ch = 'u') then ( vowels := vowels + 1 ) else ( consonant := consonant + 1 ) ) else (if (ch >= '0' & ch <= '9') then ( digit := digit + 1 ) else ( specialChar := specialChar + 1 ) ) ) ; execute ("Vowels:")->display() ; execute ("Consonant:")->display() ; execute ("Digit:")->display() ; execute ("Special Character:")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def increaseInVol(l,b,h): percentInc=((1+(l/100))*(1+(b/100))*(1+(h/100))) percentInc-=1 percentInc*=100 return percentInc l=50 b=20 h=10 print(increaseInVol(l,b,h),"%") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; l := 50 ; b := 20 ; h := 10 ; execute (increaseInVol(l, b, h))->display(); operation increaseInVol(l : OclAny, b : OclAny, h : OclAny) : OclAny pre: true post: true activity: var percentInc : int := ((1 + (l / 100)) * (1 + (b / 100)) * (1 + (h / 100))) ; percentInc := percentInc - 1 ; percentInc := percentInc * 100 ; return percentInc; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def MaxTotalRectangleArea(a,n): a.sort(reverse=True) sum=0 flag=False len=0 i=0 while(iunion(Sequence{10}->union(Sequence{10}->union(Sequence{10}->union(Sequence{11}->union(Sequence{10}->union(Sequence{11}->union(Sequence{10}->union(Sequence{9}->union(Sequence{9}->union(Sequence{8}->union(Sequence{ 8 }))))))))))) ; n := (a)->size() ; execute (MaxTotalRectangleArea(a, n))->display(); operation MaxTotalRectangleArea(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: a := a->sort() ; var sum : int := 0 ; var flag : boolean := false ; var len : int := 0 ; var i : int := 0 ; while ((i->compareTo(n - 1)) < 0) do ( if (i /= 0) then ( i := i + 1 ) else skip ; if ((a[i+1] = a[i + 1+1] or a[i+1] - a[i + 1+1] = 1) & flag = false) then ( flag := true ; len := a[i + 1+1] ; i := i + 1 ) else (if ((a[i+1] = a[i + 1+1] or a[i+1] - a[i + 1+1] = 1) & flag = true) then ( sum := sum + a[i + 1+1] * len ; flag := false ; i := i + 1 ) else skip)) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math class Node : def __init__(self,data): self.data=data self.next=None def getNode(data): newNode=Node(data) newNode.data=data return newNode def insertEnd(head,new_node): if(head==None): new_node.next=new_node new_node.prev=new_node head=new_node return head last=head.prev new_node.next=head head.prev=new_node new_node.prev=last last.next=new_node return head def reverse(head): if(head==None): return None new_head=None last=head.prev curr=last while(curr.prev!=last): prev=curr.prev new_head=insertEnd(new_head,curr) curr=prev new_head=insertEnd(new_head,curr) return new_head def display(head): if(head==None): return temp=head print("Forward direction: ",end="") while(temp.next!=head): print(temp.data,end="") temp=temp.next print(temp.data) last=head.prev temp=last print("Backward direction: ",end="") while(temp.prev!=last): print(temp.data,end="") temp=temp.prev print(temp.data) if __name__=='__main__' : head=None head=insertEnd(head,getNode(1)) head=insertEnd(head,getNode(2)) head=insertEnd(head,getNode(3)) head=insertEnd(head,getNode(4)) head=insertEnd(head,getNode(5)) print("Current list:") display(head) head=reverse(head) print("\nReversed list:") display(head) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.next := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( head := null ; head := insertEnd(head, getNode(1)) ; head := insertEnd(head, getNode(2)) ; head := insertEnd(head, getNode(3)) ; head := insertEnd(head, getNode(4)) ; head := insertEnd(head, getNode(5)) ; execute ("Current list:")->display() ; display(head) ; head := reverse(head) ; execute ("\nReversed list:")->display() ; display(head) ) else skip; operation getNode(data : OclAny) : OclAny pre: true post: true activity: var newNode : Node := (Node.newNode()).initialise(data) ; newNode.data := data ; return newNode; operation insertEnd(head : OclAny, new_node : OclAny) : OclAny pre: true post: true activity: if (head = null) then ( new_node.next := new_node ; new_node.prev := new_node ; head := new_node ; return head ) else skip ; var last : OclAny := head.prev ; new_node.next := head ; head.prev := new_node ; new_node.prev := last ; last.next := new_node ; return head; operation reverse(head : OclAny) : OclAny pre: true post: true activity: if (head = null) then ( return null ) else skip ; var new_head : OclAny := null ; last := head.prev ; var curr : OclAny := last ; while (curr.prev /= last) do ( var prev : OclAny := curr.prev ; new_head := insertEnd(new_head, curr) ; curr := prev) ; new_head := insertEnd(new_head, curr) ; return new_head; operation display(head : OclAny) pre: true post: true activity: if (head = null) then ( return ) else skip ; var temp : OclAny := head ; execute ("Forward direction: ")->display() ; while (temp.next /= head) do ( execute (temp.data)->display() ; temp := temp.next) ; execute (temp.data)->display() ; last := head.prev ; temp := last ; execute ("Backward direction: ")->display() ; while (temp.prev /= last) do ( execute (temp.data)->display() ; temp := temp.prev) ; execute (temp.data)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lastFiveDigits(n): n=((int)(n/10000)*10000+((int)(n/100)% 10)*1000+(n % 10)*100+((int)(n/10)% 10)*10+(int)(n/1000)% 10) ans=1 for i in range(5): ans*=n ans %=100000 print(ans) if __name__=='__main__' : n=12345 lastFiveDigits(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 12345 ; lastFiveDigits(n) ) else skip; operation lastFiveDigits(n : OclAny) pre: true post: true activity: n := ((OclType["int"])(n / 10000) * 10000 + ((OclType["int"])(n / 100) mod 10) * 1000 + (n mod 10) * 100 + ((OclType["int"])(n / 10) mod 10) * 10 + (OclType["int"])(n / 1000) mod 10) ; var ans : int := 1 ; for i : Integer.subrange(0, 5-1) do ( ans := ans * n ; ans := ans mod 100000) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): DIGITS=100 MULTIPLIER=100**DIGITS ans=sum(sum(int(c)for c in str(eulerlib.sqrt(i*MULTIPLIER))[: DIGITS])for i in range(100)if eulerlib.sqrt(i)**2!=i) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var DIGITS : int := 100 ; var MULTIPLIER : double := (100)->pow(DIGITS) ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name eulerlib)) (trailer . (name sqrt) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom (name MULTIPLIER))))))))) ))))))))) ))) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name DIGITS)))))))) ])))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 100))))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (expr (atom (name eulerlib)) (trailer . (name sqrt) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ** (expr (atom (number (integer 2)))))) != (comparison (expr (atom (name i)))))))))))->sum() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def evaluate(n): if(n==1 or n==2): print("No Pythagoras"+" Triplet exists"); elif(n % 2==0): var=n*n/4 ; print("Pythagoras Triplets"+" exist i.e.",end=""); print(int(n),"",int(var-1),"",int(var+1)); elif(n % 2!=0): var=n*n+1 ; print("Pythagoras Triplets "+"exist i.e.",end=""); print(int(n),"",int(var/2-1),"",int(var/2)); n=22 ; evaluate(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 22; ; evaluate(n);; operation evaluate(n : OclAny) pre: true post: true activity: if (n = 1 or n = 2) then ( execute ("No Pythagoras" + " Triplet exists")->display(); ) else (if (n mod 2 = 0) then ( var var : double := n * n / 4; ; execute ("Pythagoras Triplets" + " exist i.e.")->display(); ; execute (("" + ((n)))->toInteger())->display(); ) else (if (n mod 2 /= 0) then ( var := n * n + 1; ; execute ("Pythagoras Triplets " + "exist i.e.")->display(); ; execute (("" + ((n)))->toInteger())->display(); ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): m,mn,mx=map(int,input().split()) if m==0 and mn==0 and mx==0 : return False p=[int(input())for x in range(m)] result,ans=0,0 for i in range(mn,mx+1): if p[i-1]-p[i]>=result : result=p[i-1]-p[i] ans=i print(ans) return True while solve(): pass ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while solve() do ( skip); operation solve() : OclAny pre: true post: true activity: var m : OclAny := null; var mn : OclAny := null; var mx : OclAny := null; Sequence{m,mn,mx} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if m = 0 & mn = 0 & mx = 0 then ( return false ) else skip ; var p : Sequence := Integer.subrange(0, m-1)->select(x | true)->collect(x | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var result : OclAny := null; var ans : OclAny := null; Sequence{result,ans} := Sequence{0,0} ; for i : Integer.subrange(mn, mx + 1-1) do ( if (p[i - 1+1] - p[i+1]->compareTo(result)) >= 0 then ( var result : double := p[i - 1+1] - p[i+1] ; var ans : OclAny := i ) else skip) ; execute (ans)->display() ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): pass t=int(input()) for i in range(t): n=int(input()) a=list(map(int,input().split())) d={} ans=-1 for i in range(n): if a[i]in d : ans=max(ans,n-i+d[a[i]]) d[a[i]]=i print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := Set{} ; var ans : int := -1 ; for i : Integer.subrange(0, n-1) do ( if (d)->includes(a[i+1]) then ( ans := Set{ans, n - i + d[a[i+1]+1]}->max() ) else skip ; d[a[i+1]+1] := i) ; execute (ans)->display()); operation solve() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import floor,log2 def minAbsDiff(n): left=pow(2,floor(log2(n))) right=left*2 return min((n-left),(right-n)) if __name__=="__main__" : n=15 print(minAbsDiff(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 15 ; execute (minAbsDiff(n))->display() ) else skip; operation minAbsDiff(n : OclAny) : OclAny pre: true post: true activity: var left : double := (2)->pow(floor(log2(n))) ; var right : double := left * 2 ; return Set{(n - left), (right - n)}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- abx=list(map(int,input().split())) def d(a,b): if a<0 : return-1 else : return a//b a=d(abx[0]-1,abx[2]) b=d(abx[1],abx[2]) print(b-a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var abx : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; a := d(abx->first() - 1, abx[2+1]) ; b := d(abx[1+1], abx[2+1]) ; execute (b - a)->display(); operation d(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a < 0 then ( return -1 ) else ( return a div b ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from decimal import* a,b,x=map(int,input().split(" ")) print(math.floor(Decimal(b)/Decimal(x))-math.ceil(Decimal(a)/Decimal(x))+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var a : OclAny := null; var b : OclAny := null; var x : OclAny := null; Sequence{a,b,x} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Decimal(b) / Decimal(x))->floor() - (Decimal(a) / Decimal(x))->ceil() + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=str(input()) s=s.split(' ') a=eval(s[0]) b=eval(s[1]) x=eval(s[2]) if(a % x==0): print(b//x-a//x+1) else : print(b//x-a//x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; s := s.split(' ') ; var a : OclAny := s->first() ; var b : OclAny := s[1+1] ; var x : OclAny := s[2+1] ; if (a mod x = 0) then ( execute (b div x - a div x + 1)->display() ) else ( execute (b div x - a div x)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=list(map(int,input().split())) num=0 ; num=(l[1]//l[2])-((l[0]-1)//l[2]) print(num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var num : int := 0; ; num := (l[1+1] div l[2+1]) - ((l->first() - 1) div l[2+1]) ; execute (num)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) n=a//c m=b//c o=0 if a % c==0 : o=1 print(m-n+o) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : int := a div c ; var m : int := b div c ; var o : int := 0 ; if a mod c = 0 then ( o := 1 ) else skip ; execute (m - n + o)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(a==0): return b return gcd(b % a,a) def findNumber(arr,n): ans=arr[0] for i in range(0,n): ans=gcd(ans,arr[i]) for i in range(0,n): if(arr[i]==ans): return ans return-1 arr=[2,2,4]; n=len(arr) print(findNumber(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{2}->union(Sequence{2}->union(Sequence{ 4 })); ; n := (arr)->size() ; execute (findNumber(arr, n))->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0) then ( return b ) else skip ; return gcd(b mod a, a); operation findNumber(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : OclAny := arr->first() ; for i : Integer.subrange(0, n-1) do ( ans := gcd(ans, arr[i+1])) ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] = ans) then ( return ans ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countKdivPairs(A,n,K): freq=[0 for i in range(K)] ans=0 for i in range(n): rem=A[i]% K if(rem!=0): ans+=freq[K-rem] else : ans+=freq[0] freq[rem]+=1 return ans if __name__=='__main__' : A=[2,2,1,7,5,3] n=len(A) K=4 print(countKdivPairs(A,n,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( A := Sequence{2}->union(Sequence{2}->union(Sequence{1}->union(Sequence{7}->union(Sequence{5}->union(Sequence{ 3 }))))) ; n := (A)->size() ; K := 4 ; execute (countKdivPairs(A, n, K))->display() ) else skip; operation countKdivPairs(A : OclAny, n : OclAny, K : OclAny) : OclAny pre: true post: true activity: var freq : Sequence := Integer.subrange(0, K-1)->select(i | true)->collect(i | (0)) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var rem : int := A[i+1] mod K ; if (rem /= 0) then ( ans := ans + freq[K - rem+1] ) else ( ans := ans + freq->first() ) ; freq[rem+1] := freq[rem+1] + 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(input().replace(","," ")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (input().replace(",", " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def kthSmallest(n,k): return 2*k n=8 ; k=4 print(kthSmallest(n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 8; k := 4 ; execute (kthSmallest(n, k))->display(); operation kthSmallest(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: return 2 * k; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : can_n,pass_min,pass_max=[int(i)for i in input().split()] if can_n==pass_min==pass_max==0 : break score_lst=[] for _ in range(can_n): score_lst.append(int(input())) gap_lst=[] for i in range(pass_min,pass_max+1): gap_lst.append(score_lst[i-1]-score_lst[i]) gap_max=max(gap_lst) for i in range(len(gap_lst)-1,-1,-1): if gap_lst[i]==gap_max : print(i+pass_min) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var can_n : OclAny := null; var pass_min : OclAny := null; var pass_max : OclAny := null; Sequence{can_n,pass_min,pass_max} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if can_n = pass_min & (pass_min == pass_max) & (pass_max == 0) then ( break ) else skip ; var score_lst : Sequence := Sequence{} ; for _anon : Integer.subrange(0, can_n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : score_lst)) ; var gap_lst : Sequence := Sequence{} ; for i : Integer.subrange(pass_min, pass_max + 1-1) do ( execute ((score_lst[i - 1+1] - score_lst[i+1]) : gap_lst)) ; var gap_max : OclAny := (gap_lst)->max() ; for i : Integer.subrange(-1 + 1, (gap_lst)->size() - 1)->reverse() do ( if gap_lst[i+1] = gap_max then ( execute (i + pass_min)->display() ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() a=" ".join(s.split(",")) print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var a : String := StringLib.sumStringsWithSeparator((s.split(",")), " ") ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(' '.join(input().split(','))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (StringLib.sumStringsWithSeparator((input().split(',')), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def LCIS(arr1,n,arr2,m): table=[0]*m for j in range(m): table[j]=0 for i in range(n): current=0 for j in range(m): if(arr1[i]==arr2[j]): if(current+1>table[j]): table[j]=current+1 if(arr1[i]>arr2[j]): if(table[j]>current): current=table[j] result=0 for i in range(m): if(table[i]>result): result=table[i] return result if __name__=="__main__" : arr1=[3,4,9,1] arr2=[5,3,8,9,10,2,1] n=len(arr1) m=len(arr2) print("Length of LCIS is",LCIS(arr1,n,arr2,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr1 := Sequence{3}->union(Sequence{4}->union(Sequence{9}->union(Sequence{ 1 }))) ; arr2 := Sequence{5}->union(Sequence{3}->union(Sequence{8}->union(Sequence{9}->union(Sequence{10}->union(Sequence{2}->union(Sequence{ 1 })))))) ; n := (arr1)->size() ; m := (arr2)->size() ; execute ("Length of LCIS is")->display() ) else skip; operation LCIS(arr1 : OclAny, n : OclAny, arr2 : OclAny, m : OclAny) : OclAny pre: true post: true activity: var table : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; for j : Integer.subrange(0, m-1) do ( table[j+1] := 0) ; for i : Integer.subrange(0, n-1) do ( var current : int := 0 ; for j : Integer.subrange(0, m-1) do ( if (arr1[i+1] = arr2[j+1]) then ( if ((current + 1->compareTo(table[j+1])) > 0) then ( table[j+1] := current + 1 ) else skip ) else skip ; if ((arr1[i+1]->compareTo(arr2[j+1])) > 0) then ( if ((table[j+1]->compareTo(current)) > 0) then ( current := table[j+1] ) else skip ) else skip)) ; var result : int := 0 ; for i : Integer.subrange(0, m-1) do ( if ((table[i+1]->compareTo(result)) > 0) then ( result := table[i+1] ) else skip) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() result=s.replace(',',' ') print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var result : String := s.replace(',', ' ') ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=input().split(",") print(a,b,c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := input().split(",") ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def _input(): return map(int,input().split()) n=int(input()) lst=list(_input()) if lst[0]!=lst[-1]: print(n-1) else : i=1 while i=0 and lst[j]==lst[0]: j-=1 print(max(n-i-1,j)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := (_input()) ; if lst->first() /= lst->last() then ( execute (n - 1)->display() ) else ( var i : int := 1 ; while (i->compareTo(n)) < 0 & lst[i+1] = lst->first() do ( i := i + 1) ; var j : double := n - 2 ; while j >= 0 & lst[j+1] = lst->first() do ( j := j - 1) ; execute (Set{n - i - 1, j}->max())->display() ); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ar=list(map(int,input().strip().split())) k,j=0,len(ar)-1 while(ar[k]==ar[0]==ar[j]): k+=1 j-=1 print(j) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ar : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k : OclAny := null; var j : OclAny := null; Sequence{k,j} := Sequence{0,(ar)->size() - 1} ; while (ar[k+1] = ar->first() & (ar->first() == ar[j+1])) do ( k := k + 1 ; j := j - 1) ; execute (j)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[int(x)for x in input().split()] ans=[] for i in range(n): if l[i]!=l[n-1]: ans.append(n-i-1) break for j in range(n-1,-1,-1): if l[j]!=l[0]: ans.append(j) break print(max(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if l[i+1] /= l[n - 1+1] then ( execute ((n - i - 1) : ans) ; break ) else skip) ; for j : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if l[j+1] /= l->first() then ( execute ((j) : ans) ; break ) else skip) ; execute ((ans)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) w=input()[:-1].split() c=0 for i in range(n-1,-1,-1): if w[i]!=w[0]: if i>c : c=i for i in range(n): if w[i]!=w[-1]: if n-1-i>c : c=n-1-i print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : OclAny := input()->front().split() ; var c : int := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if w[i+1] /= w->first() then ( if (i->compareTo(c)) > 0 then ( c := i ) else skip ) else skip) ; for i : Integer.subrange(0, n-1) do ( if w[i+1] /= w->last() then ( if (n - 1 - i->compareTo(c)) > 0 then ( c := n - 1 - i ) else skip ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=int(input())-1 ; s=input().split() while s[i]==s[0]==s[~ i]: i-=1 print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : double := ("" + (((OclFile["System.in"]).readLine())))->toInteger() - 1; var s : OclAny := input().split() ; while s[i+1] = s->first() & (s->first() == s[MathLib.bitwiseNot(i)+1]) do ( i := i - 1) ; execute (i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,bisect PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") def overlap(x1,y1,x2,y2,x3,y3,x4,y4): if y3>y2 or y4x2 : return False return True for line in sys.stdin : x1,y1,x2,y2,x3,y3,x4,y4=[float(_)for _ in line.split()] print("YES" if not overlap(x1,y1,x2,y2,x3,y3,x4,y4)<1e-10 else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; skip ; for line : OclFile["System.in"] do ( Sequence{x1,y1,x2,y2,x3,y3,x4,y4} := line.split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toReal())) ; execute (if not(overlap(x1, y1, x2, y2, x3, y3, x4, y4) < ("1e-10")->toReal()) then "YES" else "NO" endif)->display()); operation overlap(x1 : OclAny, y1 : OclAny, x2 : OclAny, y2 : OclAny, x3 : OclAny, y3 : OclAny, x4 : OclAny, y4 : OclAny) : OclAny pre: true post: true activity: if (y3->compareTo(y2)) > 0 or (y4->compareTo(y1)) < 0 then ( return false ) else skip ; if (x4->compareTo(x1)) < 0 or (x3->compareTo(x2)) > 0 then ( return false ) else skip ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd import sys def lcm(x,y): return x*y//gcd(x,y) def count(x): res=0 while True : if x % 2==0 : res+=1 x//=2 else : break return res n,m=map(int,input().split()) A=list(map(int,input().split())) A=list(set(A)) n=len(A) A.sort(reverse=True) temp=A[0] for i in range(1,n): if count(A[i])!=count(temp): print(0) sys.exit() else : temp=lcm(temp,A[i]) ans=m//(temp//2)-m//temp print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; A := (Set{}->union((A))) ; var n : int := (A)->size() ; A := A->sort() ; var temp : OclAny := A->first() ; for i : Integer.subrange(1, n-1) do ( if count(A[i+1]) /= count(temp) then ( execute (0)->display() ; sys.exit() ) else ( temp := lcm(temp, A[i+1]) )) ; var ans : double := m div (temp div 2) - m div temp ; execute (ans)->display(); operation lcm(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return x * y div gcd(x, y); operation count(x : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; while true do ( if x mod 2 = 0 then ( res := res + 1 ; x := x div 2 ) else ( break )) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import fractions import math n,num=map(int,input().split()) num_set=set(map(lambda x : int(x),input().split())) two_times_set=set() for i in num_set : for j in range(1,30): i//=2 if i % 2!=0 : two_times_set.add(j) break if len(two_times_set)!=1 : print(0) break else : num_list=list(num_set) lcm=num_list[0] for i in range(1,len(num_list)): lcm=lcm*num_list[i]//fractions.gcd(lcm,num_list[i]) print((num-lcm//2)//(lcm)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var num : OclAny := null; Sequence{n,num} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var num_set : Set := Set{}->union(((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ))) ; var two_times_set : Set := Set{}->union(()) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name num_set))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 30))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))) (assign_part //= (testlist (test (logical_test (comparison (expr (atom (number (integer 2)))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name i))) % (expr (atom (number (integer 2)))))) != (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name two_times_set)) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name two_times_set)))))))) ))))) != (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name num_list)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num_set)))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name lcm)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name num_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num_list)))))))) ))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name lcm)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (name lcm))) * (expr (atom (name num_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) // (expr (atom (name fractions)) (trailer . (name gcd) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name lcm))))))) , (argument (test (logical_test (comparison (expr (atom (name num_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name num))) - (expr (expr (atom (name lcm))) // (expr (atom (number (integer 2)))))))))) ))) // (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name lcm))))))) )))) + (expr (atom (number (integer 1)))))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import fractions def LCM(X,Y): return X*(Y//fractions.gcd(X,Y)) N,M=[int(s)for s in input().split()] ls=[int(s)for s in input().split()] def Oddcheck(lst): for num in lst : if num % 2==0 : return False break else : return True def Evencheck(lst): for num in lst : if num % 2==1 : return False break else : return True c=1 while Oddcheck(ls)==False : if Evencheck(ls)==True : c*=2 for i in range(N): ls[i]//=2 else : print(0) break else : g=1 for num in ls : g=LCM(g,num) g*=c//2 print((M+g)//(2*g)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; var ls : Sequence := input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; skip ; skip ; var c : int := 1 ; (compound_stmt while (test (logical_test (comparison (comparison (expr (atom (name Oddcheck)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ls)))))))) ))))) == (comparison (expr (atom (name False))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name Evencheck)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ls)))))))) ))))) == (comparison (expr (atom (name True))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) (assign_part *= (testlist (test (logical_test (comparison (expr (atom (number (integer 2)))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ls)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) (assign_part //= (testlist (test (logical_test (comparison (expr (atom (number (integer 2)))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name g)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name num)))) in (testlist (test (logical_test (comparison (expr (atom (name ls))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name g)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name LCM)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name g))))))) , (argument (test (logical_test (comparison (expr (atom (name num)))))))) )))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name g)))))))) (assign_part *= (testlist (test (logical_test (comparison (expr (expr (atom (name c))) // (expr (atom (number (integer 2))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name M))) + (expr (atom (name g)))))))) ))) // (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name g)))))))) ))))))))) ))))))))))))))); operation LCM(X : OclAny, Y : OclAny) : OclAny pre: true post: true activity: return X * (Y div fractions.gcd(X, Y)); operation Oddcheck(lst : OclAny) pre: true post: true activity: (compound_stmt for (exprlist (expr (atom (name num)))) in (testlist (test (logical_test (comparison (expr (atom (name lst))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name num))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name False)))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name True))))))))))))); operation Evencheck(lst : OclAny) pre: true post: true activity: (compound_stmt for (exprlist (expr (atom (name num)))) in (testlist (test (logical_test (comparison (expr (atom (name lst))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name num))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name False)))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name True))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSetBits(n): bitCount=0 for i in range(1,n+1): bitCount+=countSetBitsUtil(i) return bitCount def countSetBitsUtil(x): if(x<=0): return 0 return(0 if int(x % 2)==0 else 1)+countSetBitsUtil(int(x/2)) if __name__=='__main__' : n=4 print("Total set bit count is",countSetBits(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( n := 4 ; execute ("Total set bit count is")->display() ) else skip; operation countSetBits(n : OclAny) : OclAny pre: true post: true activity: var bitCount : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( bitCount := bitCount + countSetBitsUtil(i)) ; return bitCount; operation countSetBitsUtil(x : OclAny) : OclAny pre: true post: true activity: if (x <= 0) then ( return 0 ) else skip ; return (if ("" + ((x mod 2)))->toInteger() = 0 then 0 else 1 endif) + countSetBitsUtil(("" + ((x / 2)))->toInteger()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=list(map(int,input().split(" "))) list_a=list(map(int,input().split(" "))) def check_exist(l): if(len(l)==1): return True while(True): flag=l[0]% 2 for x in l[1 :]: if(x % 2!=flag): return False if(flag==0): l=list(map(lambda x : int(x/2),l)) else : return True def gcd(a,b): if(b==0): return a else : return gcd(b,a % b) def lcm(a,b): cd=gcd(a,b) return(a/cd)*b def lcm_multi(l): cm=1 for x in l : cm=lcm(x,cm) if(cm>4*M): print(0) exit() return cm if(not(check_exist(list_a))): print(0) exit() lcm_m=lcm_multi(list(map(lambda x : int(x/2),list_a))) if(M-lcm_m<0): print(0) else : print(int((M-lcm_m)/(2*lcm_m))+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var list_a : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; skip ; skip ; skip ; if (not((check_exist(list_a)))) then ( execute (0)->display() ; exit() ) else skip ; var lcm_m : OclAny := lcm_multi(((list_a)->collect( _x | (lambda x : OclAny in (("" + ((x / 2)))->toInteger()))->apply(_x) ))) ; if (M - lcm_m < 0) then ( execute (0)->display() ) else ( execute (("" + (((M - lcm_m) / (2 * lcm_m))))->toInteger() + 1)->display() ); operation check_exist(l : OclAny) : OclAny pre: true post: true activity: if ((l)->size() = 1) then ( return true ) else skip ; while (true) do ( var flag : int := l->first() mod 2 ; for x : l->tail() do ( if (x mod 2 /= flag) then ( return false ) else skip) ; if (flag = 0) then ( l := ((l)->collect( _x | (lambda x : OclAny in (("" + ((x / 2)))->toInteger()))->apply(_x) )) ) else ( return true )); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (b = 0) then ( return a ) else ( return gcd(b, a mod b) ); operation lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var cd : OclAny := gcd(a, b) ; return (a / cd) * b; operation lcm_multi(l : OclAny) : OclAny pre: true post: true activity: var cm : int := 1 ; for x : l do ( cm := lcm(x, cm) ; if ((cm->compareTo(4 * M)) > 0) then ( execute (0)->display() ; exit() ) else skip) ; return cm; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=lambda : map(int,input().split()) n,m=f(); a=list(f()) from fractions import* l=1 for i in a : i//=2 ; l=l*i//gcd(l,i) if(l//i)% 2<1 or l>m : print(0); exit() print(m//l-m//(l*2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := f->apply(); var a : Sequence := (f->apply())->characters() ; skip ; var l : int := 1 ; for i : a do ( i := i div 2; l := l * i div gcd(l, i) ; if (l div i) mod 2 < 1 or (l->compareTo(m)) > 0 then ( execute (0)->display(); exit() ) else skip) ; execute (m div l - m div (l * 2))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSubarrays(arr,n): difference=0 ans=0 hash_positive=[0]*(n+1) hash_negative=[0]*(n+1) hash_positive[0]=1 for i in range(n): if(arr[i]& 1==1): difference=difference+1 else : difference=difference-1 if(difference<0): ans+=hash_negative[-difference] hash_negative[-difference]=hash_negative[-difference]+1 else : ans+=hash_positive[difference] hash_positive[difference]=hash_positive[difference]+1 return ans arr=[3,4,6,8,1,10,5,7] n=len(arr) print("Total Number of Even-Odd subarrays are "+str(countSubarrays(arr,n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{3}->union(Sequence{4}->union(Sequence{6}->union(Sequence{8}->union(Sequence{1}->union(Sequence{10}->union(Sequence{5}->union(Sequence{ 7 }))))))) ; n := (arr)->size() ; execute ("Total Number of Even-Odd subarrays are " + ("" + ((countSubarrays(arr, n)))))->display(); operation countSubarrays(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var difference : int := 0 ; var ans : int := 0 ; var hash_positive : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var hash_negative : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; hash_positive->first() := 1 ; for i : Integer.subrange(0, n-1) do ( if (MathLib.bitwiseAnd(arr[i+1], 1) = 1) then ( difference := difference + 1 ) else ( difference := difference - 1 ) ; if (difference < 0) then ( ans := ans + hash_negative->reverse()->at(-(-difference)) ; hash_negative->reverse()->at(-(-difference)) := hash_negative->reverse()->at(-(-difference)) + 1 ) else ( ans := ans + hash_positive[difference+1] ; hash_positive[difference+1] := hash_positive[difference+1] + 1 )) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math def printChar(str_,n): freq=[0]*26 for i in range(n): freq[ord(str_[i])-ord('a')]+=1 for i in range(n): if(freq[ord(str_[i])-ord('a')])% 2==1 : print("{}".format(str_[i]),end="") if __name__=='__main__' : str_="geeksforgeeks" n=len(str_) printChar(str_,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( str_ := "geeksforgeeks" ; n := (str_)->size() ; printChar(str_, n) ) else skip; operation printChar(str_ : OclAny, n : OclAny) pre: true post: true activity: var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for i : Integer.subrange(0, n-1) do ( freq[(str_[i+1])->char2byte() - ('a')->char2byte()+1] := freq[(str_[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; for i : Integer.subrange(0, n-1) do ( if (freq[(str_[i+1])->char2byte() - ('a')->char2byte()+1]) mod 2 = 1 then ( execute (StringLib.interpolateStrings("{}", Sequence{str_[i+1]}))->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- SIZE=26 def printChar(string,n): freq=[0]*SIZE for i in range(0,n): freq[ord(string[i])-ord('a')]+=1 for i in range(0,n): if(freq[ord(string[i])-ord('a')]% 2==0): print(string[i],end="") if __name__=='__main__' : string="geeksforgeeks" n=len(string) printChar(string,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var SIZE : int := 26 ; skip ; if __name__ = '__main__' then ( string := "geeksforgeeks" ; n := (string)->size() ; printChar(string, n) ) else skip; operation printChar(string : OclAny, n : OclAny) pre: true post: true activity: var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, SIZE) ; for i : Integer.subrange(0, n-1) do ( freq[(string[i+1])->char2byte() - ('a')->char2byte()+1] := freq[(string[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; for i : Integer.subrange(0, n-1) do ( if (freq[(string[i+1])->char2byte() - ('a')->char2byte()+1] mod 2 = 0) then ( execute (string[i+1])->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countGreater(arr,n,k): l=0 r=n-1 leftGreater=n while(l<=r): m=int(l+(r-l)/2) if(arr[m]>k): leftGreater=m r=m-1 else : l=m+1 return(n-leftGreater) if __name__=='__main__' : arr=[3,3,4,7,7,7,11,13,13] n=len(arr) k=7 print(countGreater(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{3}->union(Sequence{3}->union(Sequence{4}->union(Sequence{7}->union(Sequence{7}->union(Sequence{7}->union(Sequence{11}->union(Sequence{13}->union(Sequence{ 13 })))))))) ; n := (arr)->size() ; k := 7 ; execute (countGreater(arr, n, k))->display() ) else skip; operation countGreater(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var l : int := 0 ; var r : double := n - 1 ; var leftGreater : OclAny := n ; while ((l->compareTo(r)) <= 0) do ( var m : int := ("" + ((l + (r - l) / 2)))->toInteger() ; if ((arr[m+1]->compareTo(k)) > 0) then ( leftGreater := m ; r := m - 1 ) else ( l := m + 1 )) ; return (n - leftGreater); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : a,b,c=map(int,input().split()) if a==0 : break d=[int(input())for i in range(a)] e=0 for i in range(b,c+1): if d[i-1]-d[i]>=e : e=d[i-1]-d[i] f=i print(f) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 0 then ( break ) else skip ; var d : Sequence := Integer.subrange(0, a-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var e : int := 0 ; for i : Integer.subrange(b, c + 1-1) do ( if (d[i - 1+1] - d[i+1]->compareTo(e)) >= 0 then ( e := d[i - 1+1] - d[i+1] ; var f : OclAny := i ) else skip) ; execute (f)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) if m==1 : print(2**n % 1000000) else : dp=[[[0]*(n+1)for _ in range(3)]for _ in range(n+1)] dp[0][0][0]=1 for y in range(n): for x in range(3): for slide_limit in range(y+1): if x==0 : dp[y+1][0][slide_limit]+=dp[y][0][slide_limit] dp[y+1][1][y+1]+=dp[y][0][slide_limit] dp[y+1][2][y+1]+=dp[y][0][slide_limit]*(y-slide_limit+1) if x==1 : dp[y+1][0][y+1]+=dp[y][1][slide_limit] dp[y+1][1][slide_limit]+=dp[y][1][slide_limit] dp[y+1][2][y+1]+=dp[y][1][slide_limit] if x==2 : dp[y+1][0][y+1]+=dp[y][2][slide_limit]*(y-slide_limit+1) dp[y+1][1][y+1]+=dp[y][2][slide_limit] dp[y+1][2][slide_limit]+=dp[y][2][slide_limit] print((sum([sum(line)for line in dp[n]])+sum([dp[n][0][slide_limit]*(n-slide_limit)for slide_limit in range(n+1)]))% 1000000) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if m = 1 then ( execute ((2)->pow(n) mod 1000000)->display() ) else ( var dp : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)))))) ; dp->first()->first()->first() := 1 ; for y : Integer.subrange(0, n-1) do ( for x : Integer.subrange(0, 3-1) do ( for slide_limit : Integer.subrange(0, y + 1-1) do ( if x = 0 then ( dp[y + 1+1]->first()[slide_limit+1] := dp[y + 1+1]->first()[slide_limit+1] + dp[y+1]->first()[slide_limit+1] ; dp[y + 1+1][1+1][y + 1+1] := dp[y + 1+1][1+1][y + 1+1] + dp[y+1]->first()[slide_limit+1] ; dp[y + 1+1][2+1][y + 1+1] := dp[y + 1+1][2+1][y + 1+1] + dp[y+1]->first()[slide_limit+1] * (y - slide_limit + 1) ) else skip ; if x = 1 then ( dp[y + 1+1]->first()[y + 1+1] := dp[y + 1+1]->first()[y + 1+1] + dp[y+1][1+1][slide_limit+1] ; dp[y + 1+1][1+1][slide_limit+1] := dp[y + 1+1][1+1][slide_limit+1] + dp[y+1][1+1][slide_limit+1] ; dp[y + 1+1][2+1][y + 1+1] := dp[y + 1+1][2+1][y + 1+1] + dp[y+1][1+1][slide_limit+1] ) else skip ; if x = 2 then ( dp[y + 1+1]->first()[y + 1+1] := dp[y + 1+1]->first()[y + 1+1] + dp[y+1][2+1][slide_limit+1] * (y - slide_limit + 1) ; dp[y + 1+1][1+1][y + 1+1] := dp[y + 1+1][1+1][y + 1+1] + dp[y+1][2+1][slide_limit+1] ; dp[y + 1+1][2+1][slide_limit+1] := dp[y + 1+1][2+1][slide_limit+1] + dp[y+1][2+1][slide_limit+1] ) else skip))) ; execute (((dp[n+1]->select(line | true)->collect(line | ((line)->sum())))->sum() + (Integer.subrange(0, n + 1-1)->select(slide_limit | true)->collect(slide_limit | (dp[n+1]->first()[slide_limit+1] * (n - slide_limit))))->sum()) mod 1000000)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=1000000 n,m=map(int,input().split()) dp=[[0]*5 for _ in range(n)] dp[0]=[1,1,1,1,0] a=1 if m==1 : print((a<collect( _x | (OclType["int"])->apply(_x) ) ; var dp : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 5))) ; dp->first() := Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 0 })))) ; var a : int := 1 ; if m = 1 then ( execute ((a * (2->pow(n))) mod mod)->display() ) else ( for i : Integer.subrange(1, n-1) do ( dp[i+1]->first() := (dp[i - 1+1]->first() + dp[i - 1+1][1+1] + dp[i - 1+1][2+1] + dp[i - 1+1][4+1]) mod mod ; dp[i+1][1+1] := (dp[i - 1+1]->first() + dp[i - 1+1][1+1] + dp[i - 1+1][2+1]) mod mod ; dp[i+1][2+1] := (dp[i - 1+1]->first() + dp[i - 1+1][1+1] + dp[i - 1+1][2+1] + dp[i - 1+1][3+1]) mod mod ; dp[i+1][3+1] := (dp[i - 1+1]->first() + dp[i - 1+1][3+1]) mod mod ; dp[i+1][4+1] := (dp[i - 1+1][2+1] + dp[i - 1+1][4+1]) mod mod) ; execute ((dp[n - 1+1].subrange(1,4))->sum() mod mod)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=1000000 n,m=map(int,input().split()) dp=[[0]*5 for _ in range(n)] dp[0]=[1,1,1,1,0] if m==1 : print((1<collect( _x | (OclType["int"])->apply(_x) ) ; var dp : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 5))) ; dp->first() := Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 0 })))) ; if m = 1 then ( execute ((1 * (2->pow(n))) mod mod)->display() ) else ( for i : Integer.subrange(1, n-1) do ( dp[i+1]->first() := ((dp[i - 1+1])->sum() - dp[i - 1+1][3+1]) mod mod ; dp[i+1][1+1] := (dp[i - 1+1].subrange(1,3))->sum() mod mod ; dp[i+1][2+1] := (dp[i - 1+1].subrange(1,4))->sum() mod mod ; dp[i+1][3+1] := (dp[i - 1+1](subscript : (test (logical_test (comparison (expr (atom (number (integer 4))))))) (sliceop : (test (logical_test (comparison (expr (atom (number (integer 3))))))))))->sum() mod mod ; dp[i+1][4+1] := (dp[i - 1+1](subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->sum() mod mod) ; execute ((dp[n - 1+1].subrange(1,4))->sum() mod mod)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def findAandB(N): val=N*N-4.0*N if(val<0): print("NO") return a=(N+sqrt(val))/2.0 b=(N-sqrt(val))/2.0 print("a=",'{0:.6}'.format(a)) print("b=",'{0:.6}'.format(b)) if __name__=='__main__' : N=69.0 findAandB(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( N := 69.0 ; findAandB(N) ) else skip; operation findAandB(N : OclAny) pre: true post: true activity: var val : double := N * N - 4.0 * N ; if (val < 0) then ( execute ("NO")->display() ; return ) else skip ; var a : double := (N + sqrt(val)) / 2.0 ; var b : double := (N - sqrt(val)) / 2.0 ; execute ("a=")->display() ; execute ("b=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def partition(arr,low,high): pivot=arr[high] i=(low-1) for j in range(low,high): if(arr[j]<=pivot): i+=1 arr[i],arr[j]=arr[j],arr[i] arr[i+1],arr[high]=arr[high],arr[i+1] return(i+1) def quickSort(arr,low,high): if(lowunion(Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{1}->union(Sequence{ 5 }))))) ; var n : int := (arr)->size() ; quickSort(arr, 0, n - 1) ; execute ("Sorted array:")->display() ; printArray(arr, n); operation partition(arr : OclAny, low : OclAny, high : OclAny) : OclAny pre: true post: true activity: var pivot : OclAny := arr[high+1] ; var i : double := (low - 1) ; for j : Integer.subrange(low, high-1) do ( if ((arr[j+1]->compareTo(pivot)) <= 0) then ( i := i + 1 ; var arr[i+1] : OclAny := null; var arr[j+1] : OclAny := null; Sequence{arr[i+1],arr[j+1]} := Sequence{arr[j+1],arr[i+1]} ) else skip) ; var arr[i + 1+1] : OclAny := null; var arr[high+1] : OclAny := null; Sequence{arr[i + 1+1],arr[high+1]} := Sequence{arr[high+1],arr[i + 1+1]} ; return (i + 1); operation quickSort(arr : OclAny, low : OclAny, high : OclAny) pre: true post: true activity: if ((low->compareTo(high)) < 0) then ( var pi : OclAny := partition(arr, low, high) ; quickSort(arr, low, pi - 1) ; quickSort(arr, pi + 1, high) ) else skip; operation printArray(arr : OclAny, size : OclAny) pre: true post: true activity: for i : Integer.subrange(0, size-1) do ( execute (arr[i+1])->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n=int(input()) c,d=0,10**9 for _ in range(n): a,b=map(int,input().split()) if a>c : c=a if btoInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := Sequence{0,(10)->pow(9)} ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(c)) > 0 then ( var c : OclAny := a ) else skip ; if (b->compareTo(d)) < 0 then ( var d : OclAny := b ) else skip) ; if (c->compareTo(d)) <= 0 then ( execute (0)->display() ) else ( execute (c - d)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) i=[tuple(map(int,input().split()))for _ in range(n)] L=max(l for l,r in i) R=min(r for l,r in i) print(max(L-R,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var L : OclAny := ((argument (test (logical_test (comparison (expr (atom (name l)))))) (comp_for for (exprlist (expr (atom (name l))) , (expr (atom (name r)))) in (logical_test (comparison (expr (atom (name i))))))))->max() ; var R : OclAny := ((argument (test (logical_test (comparison (expr (atom (name r)))))) (comp_for for (exprlist (expr (atom (name l))) , (expr (atom (name r)))) in (logical_test (comparison (expr (atom (name i))))))))->min() ; execute (Set{L - R, 0}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) min_b=float("inf") max_a=float("-inf") for j in range(n): a,b=map(int,input().split(" ")) min_b=min(min_b,b) max_a=max(max_a,a) print(max_a-min_b if n!=1 and max_a>min_b else 0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var min_b : double := ("" + (("inf")))->toReal() ; var max_a : double := ("" + (("-inf")))->toReal() ; for j : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; min_b := Set{min_b, b}->min() ; max_a := Set{max_a, a}->max()) ; execute (if n /= 1 & (max_a->compareTo(min_b)) > 0 then max_a - min_b else 0 endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) ans=[] for i in range(n): s=input() x=set(s) if 'X' in x : ans.append(s) ans2=[] a=zip(*ans) for i in a : x=set(i) if 'X' in x : ans2.append(i) def f(): for i in ans2 : if '.' in i : return "NO" return "YES" print(f()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var x : Set := Set{}->union((s)) ; if (x)->includes('X') then ( execute ((s) : ans) ) else skip) ; var ans2 : Sequence := Sequence{} ; var a : Sequence := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name ans)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name ans)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name ans)))))))`third->at(_indx)} ) ; for i : a do ( x := Set{}->union((i)) ; if (x)->includes('X') then ( execute ((i) : ans2) ) else skip) ; skip ; execute (f())->display(); operation f() : OclAny pre: true post: true activity: for i : ans2 do ( if (i)->includes('.') then ( return "NO" ) else skip) ; return "YES"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) puz=[] for x in range(n): puz.append(input()) mix=502 miy=502 mx=-1 my=-1 numx=0 for i in range(n): for j in range(m): if(puz[i][j]=="X"): miy=min(miy,i) my=max(my,i) mix=min(mix,j) mx=max(mx,j) numx=numx+1 if((mx-mix+1)*(my-miy+1)==numx): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var puz : Sequence := Sequence{} ; for x : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : puz)) ; var mix : int := 502 ; var miy : int := 502 ; var mx : int := -1 ; var my : int := -1 ; var numx : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if (puz[i+1][j+1] = "X") then ( miy := Set{miy, i}->min() ; my := Set{my, i}->max() ; mix := Set{mix, j}->min() ; mx := Set{mx, j}->max() ; numx := numx + 1 ) else skip)) ; if ((mx - mix + 1) * (my - miy + 1) = numx) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : m,n1,n2=map(int,input().split()) if m==0 and n1==0 and n2==0 : break P=[] A=[] B=[] for i in range(m): P.append(int(input())) for i in range(n1,n2+1): A.append(P[i-1]-P[i]) B.append(i) S=[] for i in range(len(A)): if A[i]==max(A): S.append(B[i]) print(max(S)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var m : OclAny := null; var n1 : OclAny := null; var n2 : OclAny := null; Sequence{m,n1,n2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if m = 0 & n1 = 0 & n2 = 0 then ( break ) else skip ; var P : Sequence := Sequence{} ; var A : Sequence := Sequence{} ; var B : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : P)) ; for i : Integer.subrange(n1, n2 + 1-1) do ( execute ((P[i - 1+1] - P[i+1]) : A) ; execute ((i) : B)) ; var S : Sequence := Sequence{} ; for i : Integer.subrange(0, (A)->size()-1) do ( if A[i+1] = (A)->max() then ( execute ((B[i+1]) : S) ) else skip) ; execute ((S)->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for i in range(int(input())): n=int(input()) k=2**(int(math.log2(n-1))) for i in reversed(range(k)): print(i,end=' ') for i in range(k,n): print(i,end=' ') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : double := (2)->pow((("" + (()))->toInteger())) ; for i : (Integer.subrange(0, k-1))->reverse() do ( execute (i)->display()) ; for i : Integer.subrange(k, n-1) do ( execute (i)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ispowerOfTwo(x): res=0 while(x>0): res+=(x % 2) x>>=1 return res==1 def main(): for _ in range(int(input())): N=int(input()) flag=False ans,idx=[0]*N,N-1 for i in range(N): ans[i]=idx idx-=1 for i in range(N-1): if(ispowerOfTwo(ans[i])and flag==False): ans[i+1],ans[N-1]=ans[N-1],ans[i+1] break print(*ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation ispowerOfTwo(x : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; while (x > 0) do ( res := res + (x mod 2) ; x := x div (2->pow(1))) ; return res = 1; operation main() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var flag : boolean := false ; var ans : OclAny := null; var idx : OclAny := null; Sequence{ans,idx} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, N),N - 1} ; for i : Integer.subrange(0, N-1) do ( ans[i+1] := idx ; idx := idx - 1) ; for i : Integer.subrange(0, N - 1-1) do ( if (ispowerOfTwo(ans[i+1]) & flag = false) then ( var ans[i + 1+1] : OclAny := null; var ans[N - 1+1] : OclAny := null; Sequence{ans[i + 1+1],ans[N - 1+1]} := Sequence{ans[N - 1+1],ans[i + 1+1]} ; break ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) m=1 while 2*m<=n-1 : m=m*2 for i in range(m-1,-1,-1): print(i,end=' ') for i in range(m,n): print(i,end=' ') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := 1 ; while (2 * m->compareTo(n - 1)) <= 0 do ( m := m * 2) ; for i : Integer.subrange(-1 + 1, m - 1)->reverse() do ( execute (i)->display()) ; for i : Integer.subrange(m, n-1) do ( execute (i)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while(t): t-=1 n=int(input()) k=1 while((2*k)<=n-1): k*=2 for i in range(k-1,-1,-1): print(i,end=' ') for i in range(k,n): print(i,end=' ') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (t) do ( t := t - 1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := 1 ; while (((2 * k)->compareTo(n - 1)) <= 0) do ( k := k * 2) ; for i : Integer.subrange(-1 + 1, k - 1)->reverse() do ( execute (i)->display()) ; for i : Integer.subrange(k, n-1) do ( execute (i)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def roof(): from math import log2 t=int(input()) testcases=[] for i in range(t): testcases.append(int(input())) for n in testcases : perm=[x for x in range(n)] if n>=4 : max_price=2**(int(log2(n-1))) for i in range(n-1,0,-1): k=2 while perm[i]^ perm[i-1]>max_price : perm[i-1],perm[i-k]=perm[i-k],perm[i-1] k+=1 elif n==3 : perm[0],perm[1]=perm[1],perm[0] print(*perm) roof() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; roof(); operation roof() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var testcases : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : testcases)) ; for n : testcases do ( var perm : Sequence := Integer.subrange(0, n-1)->select(x | true)->collect(x | (x)) ; if n >= 4 then ( var max_price : double := (2)->pow((("" + ((log2(n - 1))))->toInteger())) ; for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( var k : int := 2 ; while (MathLib.bitwiseXor(perm[i+1], perm[i - 1+1])->compareTo(max_price)) > 0 do ( var perm[i - 1+1] : OclAny := null; var perm[i - k+1] : OclAny := null; Sequence{perm[i - 1+1],perm[i - k+1]} := Sequence{perm[i - k+1],perm[i - 1+1]} ; k := k + 1)) ) else (if n = 3 then ( var perm->first() : OclAny := null; var perm[1+1] : OclAny := null; Sequence{perm->first(),perm[1+1]} := Sequence{perm[1+1],perm->first()} ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name perm))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def partition(arr,low,high): pivot=arr[low] i=low-1 j=high+1 while(True): i+=1 while(arr[i]pivot): j-=1 if(i>=j): return j arr[i],arr[j]=arr[j],arr[i] def quickSort(arr,low,high): if(lowunion(Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{1}->union(Sequence{ 5 }))))) ; n := (arr)->size() ; quickSort(arr, 0, n - 1) ; execute ("Sorted array:")->display() ; printArray(arr, n); operation partition(arr : OclAny, low : OclAny, high : OclAny) : OclAny pre: true post: true activity: var pivot : OclAny := arr[low+1] ; var i : double := low - 1 ; var j : OclAny := high + 1 ; while (true) do ( i := i + 1 ; while ((arr[i+1]->compareTo(pivot)) < 0) do ( i := i + 1) ; j := j - 1 ; while ((arr[j+1]->compareTo(pivot)) > 0) do ( j := j - 1) ; if ((i->compareTo(j)) >= 0) then ( return j ) else skip ; var arr[i+1] : OclAny := null; var arr[j+1] : OclAny := null; Sequence{arr[i+1],arr[j+1]} := Sequence{arr[j+1],arr[i+1]}); operation quickSort(arr : OclAny, low : OclAny, high : OclAny) pre: true post: true activity: if ((low->compareTo(high)) < 0) then ( var pi : OclAny := partition(arr, low, high) ; quickSort(arr, low, pi) ; quickSort(arr, pi + 1, high) ) else skip; operation printArray(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=10**10 MOD=10**9+7 def solve(A,B,C): A=A[: :-1] B=B[: :-1] C=C[: :-1] before=[1,0,0] N=len(A) for i in range(N): dp=[0]*3 s=0 if i==N-1 : s+=1 for j in range(3): for a in range(s,10): if A[i]!='?' and int(A[i])!=a : continue for b in range(s,10): if B[i]!='?' and int(B[i])!=b : continue for c in range(s,10): if C[i]!='?' and int(C[i])!=c : continue if(j+a+b)% 10!=c : continue dp[(j+a+b)//10]+=before[j] dp[(j+a+b)//10]%=MOD before=dp ans=before[0] print(ans) def main(): while True : A=input() if A=='0' : return B=input() C=input() solve(A,B,C) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INF : double := (10)->pow(10) ; var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(A : OclAny, B : OclAny, C : OclAny) pre: true post: true activity: A := A(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; B := B(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; C := C(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var before : Sequence := Sequence{1}->union(Sequence{0}->union(Sequence{ 0 })) ; var N : int := (A)->size() ; for i : Integer.subrange(0, N-1) do ( var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 3) ; var s : int := 0 ; if i = N - 1 then ( s := s + 1 ) else skip ; for j : Integer.subrange(0, 3-1) do ( for a : Integer.subrange(s, 10-1) do ( if A[i+1] /= '?' & ("" + ((A[i+1])))->toInteger() /= a then ( continue ) else skip ; for b : Integer.subrange(s, 10-1) do ( if B[i+1] /= '?' & ("" + ((B[i+1])))->toInteger() /= b then ( continue ) else skip ; for c : Integer.subrange(s, 10-1) do ( if C[i+1] /= '?' & ("" + ((C[i+1])))->toInteger() /= c then ( continue ) else skip ; if (j + a + b) mod 10 /= c then ( continue ) else skip ; dp[(j + a + b) div 10+1] := dp[(j + a + b) div 10+1] + before[j+1] ; dp[(j + a + b) div 10+1] := dp[(j + a + b) div 10+1] mod MOD)))) ; before := dp) ; var ans : OclAny := before->first() ; execute (ans)->display(); operation main() pre: true post: true activity: while true do ( A := (OclFile["System.in"]).readLine() ; if A = '0' then ( return ) else skip ; B := (OclFile["System.in"]).readLine() ; C := (OclFile["System.in"]).readLine() ; solve(A, B, C)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): test=int(input()) move=0 while test!=1 : if test % 6==0 : test=test/6 move+=1 elif test % 3==0 : test=test*2 move+=1 else : print(-1) break else : print(move) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var test : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var move : int := 0 ; (compound_stmt while (test (logical_test (comparison (comparison (expr (atom (name test)))) != (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name test))) % (expr (atom (number (integer 6)))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name test)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name test))) / (expr (atom (number (integer 6)))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name move)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (expr (atom (name test))) % (expr (atom (number (integer 3)))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name test)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name test))) * (expr (atom (number (integer 2)))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name move)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name move)))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def explode(d): result=0 while(True): if(d==1): return result if(d % 6==1 or d % 6==2 or d % 6==4 or d % 6==5): return-1 if(d % 6==0): d/=6 result+=1 else : d*=2 result+=1 n=int(input()) for i in range(n): s=int(input()) print(explode(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (explode(s))->display()); operation explode(d : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; while (true) do ( if (d = 1) then ( return result ) else skip ; if (d mod 6 = 1 or d mod 6 = 2 or d mod 6 = 4 or d mod 6 = 5) then ( return -1 ) else skip ; if (d mod 6 = 0) then ( d := d / 6 ; result := result + 1 ) else ( d := d * 2 ; result := result + 1 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) cnt2=0 cnt3=0 while(n % 2==0): n//=2 cnt2+=1 while(n % 3==0): n//=3 cnt3+=1 if(n==1 and cnt2<=cnt3): print(2*cnt3-cnt2) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cnt2 : int := 0 ; var cnt3 : int := 0 ; while (n mod 2 = 0) do ( n := n div 2 ; cnt2 := cnt2 + 1) ; while (n mod 3 = 0) do ( n := n div 3 ; cnt3 := cnt3 + 1) ; if (n = 1 & (cnt2->compareTo(cnt3)) <= 0) then ( execute (2 * cnt3 - cnt2)->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : list(map(int,input().split())) b,q,i,m=R() a=set(R()) c=0 for _ in range(99): if abs(b)>i : break if b not in a : c+=1 b*=q print(c if c<32 else 'inf') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var b : OclAny := null; var q : OclAny := null; var i : OclAny := null; var m : OclAny := null; Sequence{b,q,i,m} := R->apply() ; var a : Set := Set{}->union((R->apply())) ; var c : int := 0 ; for _anon : Integer.subrange(0, 99-1) do ( if ((b)->abs()->compareTo(i)) > 0 then ( break ) else skip ; if (a)->excludes(b) then ( c := c + 1 ) else skip ; b := b * q) ; execute (if c < 32 then c else 'inf' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): count=0 n=int(input()) while n % 6==0 : n/=6 count+=1 while n % 3==0 : n/=3 count+=2 if n==1 : print(count) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var count : int := 0 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while n mod 6 = 0 do ( n := n / 6 ; count := count + 1) ; while n mod 3 = 0 do ( n := n / 3 ; count := count + 2) ; if n = 1 then ( execute (count)->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections def minIncrementForUnique(A): count=collections.Counter(A) taken=[] ans=0 for x in range(100000): if count[x]>=2 : taken.extend([x]*(count[x]-1)) elif taken and count[x]==0 : ans+=x-taken.pop() return ans A=[3,2,1,2,1,7] print(minIncrementForUnique(A)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; A := Sequence{3}->union(Sequence{2}->union(Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{ 7 }))))) ; execute (minIncrementForUnique(A))->display(); operation minIncrementForUnique(A : OclAny) : OclAny pre: true post: true activity: var count : OclAny := .Counter(A) ; var taken : Sequence := Sequence{} ; var ans : int := 0 ; for x : Integer.subrange(0, 100000-1) do ( if count[x+1] >= 2 then ( taken := taken->union(MatrixLib.elementwiseMult(Sequence{ x }, (count[x+1] - 1))) ) else (if taken & count[x+1] = 0 then ( ans := ans + x - taken->last() ) else skip)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) n-=1 if n<0 : n=0 print((3**(n))% 1000003) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; n := n - 1 ; if n < 0 then ( n := 0 ) else skip ; execute (((3)->pow((n))) mod 1000003)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=1000003 c=int(input()) ans=1 for i in range(1,c): ans=(ans % mod+(ans % mod*2)% mod)% mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : int := 1000003 ; var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 1 ; for i : Integer.subrange(1, c-1) do ( ans := (ans mod mod + (ans mod mod * 2) mod mod) mod mod) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==0 : print(1) else : print(3**(n-1)%(10**6+3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( execute (1)->display() ) else ( execute ((3)->pow((n - 1)) mod ((10)->pow(6) + 3))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(3**(n-1)%(10**6+3)if n>0 else 1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (if n > 0 then (3)->pow((n - 1)) mod ((10)->pow(6) + 3) else 1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxSubArraySum(a,size): max_so_far=-10**9 max_ending_here=0 for i in range(size): max_ending_here=max_ending_here+a[i] if(max_so_farunion(Sequence{-2}->union(Sequence{ 3 })) ; minPossibleSum(A, N, X) ) else skip; operation maxSubArraySum(a : OclAny, size : OclAny) : OclAny pre: true post: true activity: var max_so_far : double := (-10)->pow(9) ; var max_ending_here : int := 0 ; for i : Integer.subrange(0, size-1) do ( max_ending_here := max_ending_here + a[i+1] ; if ((max_so_far->compareTo(max_ending_here)) < 0) then ( max_so_far := max_ending_here ) else skip ; if (max_ending_here < 0) then ( max_ending_here := 0 ) else skip) ; return max_so_far; operation minPossibleSum(a : OclAny, n : OclAny, x : OclAny) pre: true post: true activity: var mxSum : OclAny := maxSubArraySum(a, n) ; var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + a[i+1]) ; sum := sum - mxSum + mxSum / x ; execute (MathLib.roundN(sum, 2))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(1500) n=int(input()) def f(x): if x==2 : return 3 return(3*f(x-1)) if n>=2 : print(f(n)% 1000003) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(1500) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; if n >= 2 then ( execute (f(n) mod 1000003)->display() ) else ( execute (1)->display() ); operation f(x : OclAny) : OclAny pre: true post: true activity: if x = 2 then ( return 3 ) else skip ; return (3 * f(x - 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np MOD=(int)(1e9+7) def modulo_13(s,n): dp=np.zeros((n+1,13)); dp[0][0]=1 ; for i in range(n): for j in range(10): nxt=ord(s[i])-ord('0'); if(s[i]=='?'): nxt=j ; for k in range(13): rem=(10*k+nxt)% 13 ; dp[i+1][rem]+=dp[i][k]; dp[i+1][rem]%=MOD ; if(s[i]!='?'): break ; return int(dp[n][5]); if __name__=="__main__" : s="?44" ; n=len(s); print(modulo_13(s,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MOD : OclAny := (OclType["int"])(("1e9")->toReal() + 7) ; skip ; if __name__ = "__main__" then ( s := "?44"; ; n := (s)->size(); ; execute (modulomodulo(modulo(modulo(modulomodulo(modulo(modulo(modulomodulo(modulo(modulo(modulomodulo(modulo(modulo(modulomodulo(modulo(modulo(modulomodulo(modulo(modulo(modulomodulo(modulo(modulo s := "?44";3(s, n))3(s, n))3(s, n)3(s, n))->display()3(s, n))3(s, n))3(s, n)3(s, n))->display()3(s, n))3(s, n))3(s, n)3(s, n))->display()3(s, n))3(s, n))3(s, n)3(s, n))->display()3(s, n))3(s, n))3(s, n)3(s, n))->display()3(s, n))3(s, n))3(s, n)3(s, n))->display()3(s, n))3(s, n))3(s, n)3(s, n))->display(); ) else skip; operation modulo skip3(s : OclAny, n : OclAny) pre: true post: true activity: var dp : Sequence := MatrixLib.singleValueMatrix(Sequence{n + 1, 13}, 0.0); ; dp->first()->first() := 1; ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, 10-1) do ( var nxt : double := (s[i+1])->char2byte() - ('0')->char2byte(); ; if (s[i+1] = '?') then ( nxt := j; ) else skip ; for k : Integer.subrange(0, 13-1) do ( var rem : int := (10 * k + nxt) mod 13; ; dp[i + 1+1][rem+1] := dp[i + 1+1][rem+1] + dp[i+1][k+1]; ; dp[i + 1+1][rem+1] := dp[i + 1+1][rem+1] mod MOD;) ; if (s[i+1] /= '?') then ( break; ) else skip)) ; return ("" + ((dp[n+1][5+1])))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def countNums(a,b,c,d): x=b//c-(a-1)//c ; y=b//d-(a-1)//d ; k=(c*d)//gcd(c,d); z=b//k-(a-1)//k ; return(b-a+1-x-y+z); if __name__=="__main__" : a=10 ; b=50 ; c=4 ; d=6 ; print(countNums(a,b,c,d)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( a := 10; b := 50; c := 4; d := 6; ; execute (countNums(a, b, c, d))->display(); ) else skip; operation countNums(a : OclAny, b : OclAny, c : OclAny, d : OclAny) pre: true post: true activity: var x : double := b div c - (a - 1) div c; ; var y : double := b div d - (a - 1) div d; ; var k : int := (c * d) div gcd(c, d); ; var z : double := b div k - (a - 1) div k; ; return (b - a + 1 - x - y + z);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=map(int,input().split()) l=set(list(map(int,input().split()))) if(abs(a)>c): print(0) exit(0) if(a==0): if 0 in l : print(0) exit(0) else : print("inf") exit(0) if(b==1): if a in l : print(0) exit(0) else : print("inf") exit(0) if(b==-1): if(-a in l)and(a in l): print(0) exit(0) else : print("inf") exit(0) if(b==0): if 0 in l : if a in l : print(0) exit(0) else : print(1) exit(0) else : print("inf") exit(0) ans=0 while(abs(a)<=c): if(a not in l): ans+=1 a=a*b print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Set := Set{}->union((((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; if (((a)->abs()->compareTo(c)) > 0) then ( execute (0)->display() ; exit(0) ) else skip ; if (a = 0) then ( if (l)->includes(0) then ( execute (0)->display() ; exit(0) ) else ( execute ("inf")->display() ; exit(0) ) ) else skip ; if (b = 1) then ( if (l)->includes(a) then ( execute (0)->display() ; exit(0) ) else ( execute ("inf")->display() ; exit(0) ) ) else skip ; if (b = -1) then ( if ((l)->includes(-a)) & ((l)->includes(a)) then ( execute (0)->display() ; exit(0) ) else ( execute ("inf")->display() ; exit(0) ) ) else skip ; if (b = 0) then ( if (l)->includes(0) then ( if (l)->includes(a) then ( execute (0)->display() ; exit(0) ) else ( execute (1)->display() ; exit(0) ) ) else ( execute ("inf")->display() ; exit(0) ) ) else skip ; var ans : int := 0 ; while (((a)->abs()->compareTo(c)) <= 0) do ( if ((l)->excludes(a)) then ( ans := ans + 1 ) else skip ; var a : double := a * b) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def printSubstrings(n): s=int(math.log10(n)); d=(math.pow(10,s)); k=d ; while(n>0): while(d>0): print(int(n//d)); d=int(d/10); n=int(n % k); k=int(k//10); d=k ; if __name__=='__main__' : n=123 ; printSubstrings(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( n := 123; ; printSubstrings(n); ) else skip; operation printSubstrings(n : OclAny) pre: true post: true activity: var s : int := ("" + (((n)->log10())))->toInteger(); ; var d : double := ((10)->pow(s)); ; var k : OclAny := d; ; while (n > 0) do ( while (d > 0) do ( execute (("" + ((n div d)))->toInteger())->display(); ; d := ("" + ((d / 10)))->toInteger();) ; n := ("" + ((n mod k)))->toInteger(); ; k := ("" + ((k div 10)))->toInteger(); ; d := k;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def NthCharacter(n): s="" c=1 while(True): if(c<10): s+=chr(48+c) else : s1="" dup=c while(dup>0): s1+=chr((dup % 10)+48) dup//=10 s1="".join(reversed(s1)) s+=s1 c+=1 if(len(s)>=n): return s[n-1] if __name__=="__main__" : n=11 print(NthCharacter(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 11 ; execute (NthCharacter(n))->display() ) else skip; operation NthCharacter(n : OclAny) : OclAny pre: true post: true activity: var s : String := "" ; var c : int := 1 ; while (true) do ( if (c < 10) then ( s := s + (48 + c)->byte2char() ) else ( var s1 : String := "" ; var dup : int := c ; while (dup > 0) do ( s1 := s1 + ((dup mod 10) + 48)->byte2char() ; dup := dup div 10) ; s1 := StringLib.sumStringsWithSeparator(((s1)->reverse()), "") ; s := s + s1 ) ; c := c + 1 ; if (((s)->size()->compareTo(n)) >= 0) then ( return s[n - 1+1] ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def days(y,m,d): cnt=0 for i in range(1,y): if i % 3==0 : cnt+=200 else : cnt+=195 for i in range(1,m): if y % 3==0 : cnt+=20 else : if i % 2==0 : cnt+=19 else : cnt+=20 cnt+=d-1 return cnt n=int(input()) for i in range(n): y,m,d=map(int,input().split()) print(days(1000,1,1)-days(y,m,d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( Sequence{y,m,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (days(1000, 1, 1) - days(y, m, d))->display()); operation days(y : OclAny, m : OclAny, d : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; for i : Integer.subrange(1, y-1) do ( if i mod 3 = 0 then ( cnt := cnt + 200 ) else ( cnt := cnt + 195 )) ; for i : Integer.subrange(1, m-1) do ( if y mod 3 = 0 then ( cnt := cnt + 20 ) else ( if i mod 2 = 0 then ( cnt := cnt + 19 ) else ( cnt := cnt + 20 ) )) ; cnt := cnt + d - 1 ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(dates): counter=0 ; start_month=dates[1] start_day,end_day=dates[2],0 for year in range(dates[0],1000): for month in range(start_month,11): if year % 3==0 or month % 2==1 : end_day=21 else : end_day=20 counter+=(end_day-start_day) start_day=1 else : start_month=1 return counter if __name__=='__main__' : n=int(input()) dates=[0 for i in range(3)] tmp_dates=[] for i in range(n): tmp_dates=input().split() for j in range(len(tmp_dates)): dates[j]=int(tmp_dates[j]) date_count=solve(dates) print(date_count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; dates := Integer.subrange(0, 3-1)->select(i | true)->collect(i | (0)) ; var tmp_dates : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( tmp_dates := input().split() ; for j : Integer.subrange(0, (tmp_dates)->size()-1) do ( dates[j+1] := ("" + ((tmp_dates[j+1])))->toInteger()) ; var date_count : OclAny := solve(dates) ; execute (date_count)->display()) ) else skip; operation solve(dates : OclAny) : OclAny pre: true post: true activity: var counter : int := 0; ; var start_month : OclAny := dates[1+1] ; var start_day : OclAny := null; var end_day : OclAny := null; Sequence{start_day,end_day} := Sequence{dates[2+1],0} ; for year : Integer.subrange(dates->first(), 1000-1) do ((compound_stmt for (exprlist (expr (atom (name month)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name start_month))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 11))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (expr (atom (name year))) % (expr (atom (number (integer 3)))))) == (comparison (expr (atom (number (integer 0))))))) or (logical_test (comparison (comparison (expr (expr (atom (name month))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 1))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name end_day)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 21)))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name end_day)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 20))))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name counter)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name end_day))) - (expr (atom (name start_day)))))))) ))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name start_day)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name start_month)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))))) ; return counter; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) src=[map(int,input().split())for i in range(N)] days_normal=(20+19)*5 days_special=20*10 days_3years=2*days_normal+days_special def passed(y,m,d): ret=((y-1)//3)*days_3years ret+=((y-1)% 3)*days_normal for i in range(m-1): ret+=(20 if y % 3==0 or i % 2==0 else 19) ret+=d return ret for i in range(N): y,m,d=src[i] print(passed(1000,1,1)-passed(y,m,d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var src : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var days_normal : int := (20 + 19) * 5 ; var days_special : int := 20 * 10 ; var days_3years : int := 2 * days_normal + days_special ; skip ; for i : Integer.subrange(0, N-1) do ( Sequence{y,m,d} := src[i+1] ; execute (passed(1000, 1, 1) - passed(y, m, d))->display()); operation passed(y : OclAny, m : OclAny, d : OclAny) : OclAny pre: true post: true activity: var ret : int := ((y - 1) div 3) * days_3years ; ret := ret + ((y - 1) mod 3) * days_normal ; for i : Integer.subrange(0, m - 1-1) do ( ret := ret + (if y mod 3 = 0 or i mod 2 = 0 then 20 else 19 endif)) ; ret := ret + d ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cal(y0,m0,d0): y=1 m=1 d=1 for days in range(10**6): if(y,m,d)==(y0,m0,d0): return days d+=1 if y % 3==0 : if d==21 : m+=1 d=1 if m==11 : y+=1 m=1 else : if m % 2==1 : if d==21 : m+=1 d=1 if m==11 : y+=1 m=1 elif m % 2==0 : if d==20 : m+=1 d=1 if m==11 : y+=1 m=1 n=int(input()) ymd=[list(map(int,input().split()))for _ in range(n)] res=cal(1000,1,1) for y,m,d in ymd : ans=res-cal(y,m,d) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ymd : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var res : OclAny := cal(1000, 1, 1) ; for _tuple : ymd do (var _indx : int := 1; var y : OclAny := _tuple->at(_indx); _indx := _indx + 1; var m : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); var ans : double := res - cal(y, m, d) ; execute (ans)->display()); operation cal(y0 : OclAny, m0 : OclAny, d0 : OclAny) : OclAny pre: true post: true activity: var y : int := 1 ; var m : int := 1 ; var d : int := 1 ; for days : Integer.subrange(0, (10)->pow(6)-1) do ( if Sequence{y, m, d} = Sequence{y0, m0, d0} then ( return days ) else skip ; d := d + 1 ; if y mod 3 = 0 then ( if d = 21 then ( m := m + 1 ; d := 1 ) else skip ; if m = 11 then ( y := y + 1 ; m := 1 ) else skip ) else ( if m mod 2 = 1 then ( if d = 21 then ( m := m + 1 ; d := 1 ) else skip ; if m = 11 then ( y := y + 1 ; m := 1 ) else skip ) else (if m mod 2 = 0 then ( if d = 20 then ( m := m + 1 ; d := 1 ) else skip ; if m = 11 then ( y := y + 1 ; m := 1 ) else skip ) else skip) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def date2num(y,m,d): t=(y-1)//3 days=t*10*20+(y-1-t)*5*20+(y-1-t)*5*19 if y % 3==0 : days+=(m-1)*20+d else : days+=(m-1)//2*19+(m-1-(m-1)//2)*20+d return days for i in range(int(input())): y,m,d=map(int,input().split(" ")) print(date2num(1000,1,1)-date2num(y,m,d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( Sequence{y,m,d} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; execute (date2num(1000, 1, 1) - date2num(y, m, d))->display()); operation date2num(y : OclAny, m : OclAny, d : OclAny) : OclAny pre: true post: true activity: var t : int := (y - 1) div 3 ; var days : int := t * 10 * 20 + (y - 1 - t) * 5 * 20 + (y - 1 - t) * 5 * 19 ; if y mod 3 = 0 then ( days := days + (m - 1) * 20 + d ) else ( days := days + (m - 1) div 2 * 19 + (m - 1 - (m - 1) div 2) * 20 + d ) ; return days; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fun(p): return p.index(max(p)) for _ in range(int(input())): n=int(input()) p=list(map(int,input().split())) l=[] var=p[0] ans=[] for j in range(n): l.append([p[j],j]) l.sort(key=lambda x : x[0]) l=l[: :-1] ind=0 ans.append(p[l[0][1]: n]) for j in range(n-1): if l[j+1][1]>l[j][1]: temp=l[j+1] l[j+1]=l[j] l[j]=temp else : ans.append(p[l[j+1][1]: l[j][1]]) for j in range(len(ans)): print(*ans[j],end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; p := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : Sequence := Sequence{} ; var var : OclAny := p->first() ; var ans : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( execute ((Sequence{p[j+1]}->union(Sequence{ j })) : l)) ; l := l->sort() ; l := l(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var ind : int := 0 ; execute ((p.subrange(l->first()[1+1]+1, n)) : ans) ; for j : Integer.subrange(0, n - 1-1) do ( if (l[j + 1+1][1+1]->compareTo(l[j+1][1+1])) > 0 then ( var temp : OclAny := l[j + 1+1] ; l[j + 1+1] := l[j+1] ; l[j+1] := temp ) else ( execute ((p.subrange(l[j + 1+1][1+1]+1, l[j+1][1+1])) : ans) )) ; for j : Integer.subrange(0, (ans)->size()-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))))->display()) ; execute (->display()); operation fun(p : OclAny) : OclAny pre: true post: true activity: return p->indexOf((p)->max()) - 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check_prime(n): if(n<=1): return False if(n<=3): return True if(n % 2==0 or n % 3==0): return False for i in range(5,n+1,6): if(n % i==0 or n %(i+2)==0): return False return True def countPrimeFrequent(s): count=0 mp={} for i in range(0,len(s)): mp.setdefault(s[i],0) mp[s[i]]+=1 for i in mp.keys(): if(check_prime(mp[i])): count+=1 return count ; s="geeksforgeeks" print(countPrimeFrequent(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; s := "geeksforgeeks" ; execute (countPrimeFrequent(s))->display(); operation check_prime(n : OclAny) : OclAny pre: true post: true activity: if (n <= 1) then ( return false ) else skip ; if (n <= 3) then ( return true ) else skip ; if (n mod 2 = 0 or n mod 3 = 0) then ( return false ) else skip ; for i : Integer.subrange(5, n + 1-1)->select( $x | ($x - 5) mod 6 = 0 ) do ( if (n mod i = 0 or n mod (i + 2) = 0) then ( return false ) else skip) ; return true; operation countPrimeFrequent(s : OclAny) pre: true post: true activity: var count : int := 0 ; var mp : OclAny := Set{} ; for i : Integer.subrange(0, (s)->size()-1) do ( mp.setdefault(s[i+1], 0) ; mp[s[i+1]+1] := mp[s[i+1]+1] + 1) ; for i : mp.keys() do ( if (check_prime(mp[i+1])) then ( count := count + 1 ) else skip) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) a.sort() b.sort() i=0 j=0 while icollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; b := b->sort() ; var i : int := 0 ; var j : int := 0 ; while (i->compareTo((a)->size())) < 0 & (j->compareTo((b)->size())) < 0 do ( if (a[i+1]->compareTo(b[j+1])) <= 0 then ( i := i + 1 ) else skip ; j := j + 1) ; execute ((a)->size() - i)->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict b,q,l,m=map(int,input().split()) arr=[int(x)for x in input().split()] d=defaultdict(bool) for i in arr : d[i]=True if(b==0): if(d[b]): print(0) else : print("inf") elif(q==0): if(abs(b)>l): print(0) else : ans=0 if(not d[b]): ans+=1 if(d[0]): print(ans) else : print("inf") elif(q==1): if(abs(b)>l): print(0) else : if(d[b]): print(0) else : print("inf") elif(q==-1): if(abs(b)>l): print(0) else : if(d[b]and d[-b]): print(0) else : print("inf") else : possible=[] curr=b while(abs(curr)<=l): if(not d[curr]): possible.append(curr) curr*=q print(len(possible)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var b : OclAny := null; var q : OclAny := null; var l : OclAny := null; var m : OclAny := null; Sequence{b,q,l,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var d : OclAny := defaultdict(OclType["boolean"]) ; for i : arr do ( d[i+1] := true) ; if (b = 0) then ( if (d[b+1]) then ( execute (0)->display() ) else ( execute ("inf")->display() ) ) else (if (q = 0) then ( if (((b)->abs()->compareTo(l)) > 0) then ( execute (0)->display() ) else ( var ans : int := 0 ; if (not(d[b+1])) then ( ans := ans + 1 ) else skip ; if (d->first()) then ( execute (ans)->display() ) else ( execute ("inf")->display() ) ) ) else (if (q = 1) then ( if (((b)->abs()->compareTo(l)) > 0) then ( execute (0)->display() ) else ( if (d[b+1]) then ( execute (0)->display() ) else ( execute ("inf")->display() ) ) ) else (if (q = -1) then ( if (((b)->abs()->compareTo(l)) > 0) then ( execute (0)->display() ) else ( if (d[b+1] & d->reverse()->at(-(-b))) then ( execute (0)->display() ) else ( execute ("inf")->display() ) ) ) else ( var possible : Sequence := Sequence{} ; var curr : OclAny := b ; while (((curr)->abs()->compareTo(l)) <= 0) do ( if (not(d[curr+1])) then ( execute ((curr) : possible) ) else skip ; curr := curr * q) ; execute ((possible)->size())->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,m=[int(i)for i in input().split()] round_complexity=[int(i)for i in input().split()] george_complexity=[int(i)for i in input().split()] i=j=0 while(iselect(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var round_complexity : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var george_complexity : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var i : OclAny := 0; var j : int := 0 ; while ((i->compareTo(n)) < 0 & (j->compareTo(m)) < 0) do ( i := i + 1 * ((round_complexity[i+1]->compareTo(george_complexity[j+1])) <= 0); ; j := j + 1) ; execute (n - i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(x)for x in input().split()] r=[int(x)for x in input().split()] p=[int(x)for x in input().split()] r.sort() p.sort() s=0 for i in range(n): for j in range(m): if p[j]>=r[i]: s+=1 p[j]=-1 break print(n-s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var r : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var p : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; r := r->sort() ; p := p->sort() ; var s : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if (p[j+1]->compareTo(r[i+1])) >= 0 then ( s := s + 1 ; p[j+1] := -1 ; break ) else skip)) ; execute (n - s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque from math import* import sys import random from bisect import* from functools import reduce from sys import stdin import copy n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) a.sort() b.sort() i,j=0,0 while ib[j]: j+=1 else : i+=1 print(n-i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; b := b->sort() ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,0} ; while (i->compareTo(n)) < 0 & (j->compareTo(m)) < 0 do ( if (a[i+1]->compareTo(b[j+1])) <= 0 then ( i := i + 1 ; j := j + 1 ) else (if (a[i+1]->compareTo(b[j+1])) > 0 then ( j := j + 1 ) else ( i := i + 1 ) ) ) ; execute (n - i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=list(map(int,input().split())) a=list(map(int,input().split())) b=list(map(int,input().split())) i=0 j=0 while icollect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var i : int := 0 ; var j : int := 0 ; while (i->compareTo(n)) < 0 & (j->compareTo(m)) < 0 do ( if (a[i+1]->compareTo(b[j+1])) <= 0 then ( i := i + 1 ) else skip ; j := j + 1) ; execute (n - i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def catalan(n): if(n==0 or n==1): return 1 catalan=[0 for i in range(n+1)] catalan[0]=1 catalan[1]=1 for i in range(2,n+1): catalan[i]=0 for j in range(i): catalan[i]=catalan[i]+catalan[j]*catalan[i-j-1] return catalan[n] for i in range(10): print(catalan(i),end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, 10-1) do ( execute (catalan(i))->display()); operation catalan(n : OclAny) : OclAny pre: true post: true activity: if (n = 0 or n = 1) then ( return 1 ) else skip ; var catalan : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; catalan->first() := 1 ; catalan[1+1] := 1 ; for i : Integer.subrange(2, n + 1-1) do ( catalan[i+1] := 0 ; for j : Integer.subrange(0, i-1) do ( catalan[i+1] := catalan[i+1] + catalan[j+1] * catalan[i - j - 1+1])) ; return catalan[n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib,fractions def compute(): TARGET=fractions.Fraction(15499,94744) totient=1 denominator=1 p=2 while True : totient*=p-1 denominator*=p while True : p+=1 if eulerlib.is_prime(p): break if fractions.Fraction(totient,denominator)display() ) else skip; operation compute() : OclAny pre: true post: true activity: var TARGET : OclAny := fractions.Fraction(15499, 94744) ; var totient : int := 1 ; var denominator : int := 1 ; var p : int := 2 ; while true do ( totient := totient * p - 1 ; denominator := denominator * p ; while true do ( p := p + 1 ; if eulerlib.is_prime(p) then ( break ) else skip) ; if (fractions.Fraction(totient, denominator)->compareTo(TARGET)) < 0 then ( for i : Integer.subrange(1, p-1) do ( var numer : double := i * totient ; var denom : double := i * denominator ; if (fractions.Fraction(numer, denom - 1)->compareTo(TARGET)) < 0 then ( return ("" + ((denom))) ) else skip) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque path=input() coord=set([(0,0)]); temp=(0,0) for c in path : if c=='L' : temp=(temp[0],temp[1]-1) elif c=='R' : temp=(temp[0],temp[1]+1) elif c=='U' : temp=(temp[0]-1,temp[1]) else : temp=(temp[0]+1,temp[1]) if temp in coord : print('BUG'); exit() coord.add(temp) coord.remove((0,0)) que=deque([(0,0)]) while que : if len(que)>1 : print('BUG'); exit() i,j=que.popleft() for p,q in(i+1,j),(i-1,j),(i,j+1),(i,j-1): if(p,q)in coord : coord.remove((p,q)) que+=(p,q), print('OK') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var path : String := (OclFile["System.in"]).readLine() ; var coord : Set := Set{}->union((Sequence{ Sequence{0, 0} })); var temp : OclAny := Sequence{0, 0} ; for c : path->characters() do ( if c = 'L' then ( temp := Sequence{temp->first(), temp[1+1] - 1} ) else (if c = 'R' then ( temp := Sequence{temp->first(), temp[1+1] + 1} ) else (if c = 'U' then ( temp := Sequence{temp->first() - 1, temp[1+1]} ) else ( temp := Sequence{temp->first() + 1, temp[1+1]} ) ) ) ; if (coord)->includes(temp) then ( execute ('BUG')->display(); exit() ) else skip ; execute ((temp) : coord)) ; execute ((Sequence{0, 0}) /: coord) ; var que : Sequence := (Sequence{ Sequence{0, 0} }) ; while que do ( if (que)->size() > 1 then ( execute ('BUG')->display(); exit() ) else skip ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := que->first() ; que := que->tail() ; for _tuple : Sequence{i + 1, j}, Sequence{i - 1, j}, Sequence{i, j + 1}, Sequence{i, j - 1} do (var _indx : int := 1; var p : OclAny := _tuple->at(_indx); _indx := _indx + 1; var q : OclAny := _tuple->at(_indx); if (coord)->includes(Sequence{p, q}) then ( execute ((Sequence{p, q}) /: coord) ; que := que + (testlist (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name p)))))) , (test (logical_test (comparison (expr (atom (name q))))))) )))))) ,) ) else skip)) ; execute ('OK')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(): t,r,s=[(0,0)],[(0,0),(-1,0),(1,0),(0,-1),(0,1)],set() for i in input(): if i=='L' : r=[(x-1,y)for x,y in r] elif i=='R' : r=[(x+1,y)for x,y in r] elif i=='D' : r=[(x,y-1)for x,y in r] else : r=[(x,y+1)for x,y in r] if any(i in s for i in r[1 :]): return 0 s.add(t[-1]) t.append(r[0]) return 1 print('BOUKG'[f(): : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute ('BOUKG'(subscript (test (logical_test (comparison (expr (atom (name f)) (trailer (arguments ( ))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); operation f() : OclAny pre: true post: true activity: var t : OclAny := null; var r : OclAny := null; var s : OclAny := null; Sequence{t,r,s} := Sequence{Sequence{ Sequence{0, 0} },Sequence{Sequence{0, 0}}->union(Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{0, -1}}->union(Sequence{ Sequence{0, 1} })))),Set{}->union(())} ; for i : (OclFile["System.in"]).readLine() do ( if i = 'L' then ( var r : Sequence := r->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (Sequence{x - 1, y})) ) else (if i = 'R' then ( r := r->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (Sequence{x + 1, y})) ) else (if i = 'D' then ( r := r->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (Sequence{x, y - 1})) ) else ( r := r->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (Sequence{x, y + 1})) ) ) ) ; if ((argument (test (logical_test (comparison (comparison (expr (atom (name i)))) in (comparison (expr (atom (name s))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name r)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))))))))->exists( _x | _x = true ) then ( return 0 ) else skip ; execute ((t->last()) : s) ; execute ((r->first()) : t)) ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def solve(): n=int(input()) arr=list(map(int,input().split())) S=set() mv=n tmp=[] ans=[] for i in range(n-1,-1,-1): tmp.append(arr[i]) S.add(arr[i]) if arr[i]==mv : while tmp : ans.append(tmp.pop()) while mv in S : mv-=1 return ans for _ in range(int(input())): print(*solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name solve)) (trailer (arguments ( )))))))))->display()); operation solve() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var S : Set := Set{}->union(()) ; var mv : int := n ; var tmp : Sequence := Sequence{} ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( execute ((arr[i+1]) : tmp) ; execute ((arr[i+1]) : S) ; if arr[i+1] = mv then ( while tmp do ( execute ((tmp->last()) : ans)) ; while (S)->includes(mv) do ( mv := mv - 1) ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() field=[[0]*(3*len(s))for i in range(3*len(s))] when=[[-2]*(3*len(s))for i in range(3*len(s))] field[0][0]=1 when[0][0]=-1 x,y=0,0 for i in range(len(s)): c=s[i] if c=='R' : x+=1 if c=='L' : x-=1 if c=='U' : y+=1 if c=='D' : y-=1 field[x][y]+=1 if field[x][y]>1 : print('BUG') exit() when[x][y]=i for i in range(-len(s),len(s)+1): for j in range(-len(s),len(s)+1): if when[i][j]==-2 : continue if when[i][j]+1size()-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (3 * (s)->size())))) ; var when : Sequence := Integer.subrange(0, 3 * (s)->size()-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ -2 }, (3 * (s)->size())))) ; field->first()->first() := 1 ; when->first()->first() := -1 ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{0,0} ; for i : Integer.subrange(0, (s)->size()-1) do ( var c : OclAny := s[i+1] ; if c = 'R' then ( x := x + 1 ) else skip ; if c = 'L' then ( x := x - 1 ) else skip ; if c = 'U' then ( y := y + 1 ) else skip ; if c = 'D' then ( y := y - 1 ) else skip ; field[x+1][y+1] := field[x+1][y+1] + 1 ; if field[x+1][y+1] > 1 then ( execute ('BUG')->display() ; exit() ) else skip ; when[x+1][y+1] := i) ; for i : Integer.subrange(-(s)->size(), (s)->size() + 1-1) do ( for j : Integer.subrange(-(s)->size(), (s)->size() + 1-1) do ( if when[i+1][j+1] = -2 then ( continue ) else skip ; if (when[i+1][j+1] + 1->compareTo((Sequence{when[i + 1+1][j+1], when[i - 1+1][j+1], when[i+1][j + 1+1], when[i+1][j - 1+1]})->max())) < 0 then ( execute ('BUG')->display() ; exit() ) else skip)) ; execute ('OK')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- b1,q,l,m=map(int,input().split()) a=set(map(int,input().split())) if q==0 : if 0 in a : if b1 in a : print(0) elif abs(b1)<=l : print(1) else : print(0) elif abs(b1)<=l : print("inf") else : print(0) elif q==1 : if abs(b1)<=l and b1 not in a : print("inf") else : print(0) elif q==-1 : if abs(b1)<=l and(b1 not in a or-b1 not in a): print('inf') else : print(0) elif b1==0 : if 0 in a : print(0) else : print("inf") else : cnt=0 p=b1 while abs(p)<=l : if p not in a : cnt+=1 p*=q print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var b1 : OclAny := null; var q : OclAny := null; var l : OclAny := null; var m : OclAny := null; Sequence{b1,q,l,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; if q = 0 then ( if (a)->includes(0) then ( if (a)->includes(b1) then ( execute (0)->display() ) else (if ((b1)->abs()->compareTo(l)) <= 0 then ( execute (1)->display() ) else ( execute (0)->display() ) ) ) else (if ((b1)->abs()->compareTo(l)) <= 0 then ( execute ("inf")->display() ) else ( execute (0)->display() ) ) ) else (if q = 1 then ( if ((b1)->abs()->compareTo(l)) <= 0 & (a)->excludes(b1) then ( execute ("inf")->display() ) else ( execute (0)->display() ) ) else (if q = -1 then ( if ((b1)->abs()->compareTo(l)) <= 0 & ((a)->excludes(b1) or (a)->excludes(-b1)) then ( execute ('inf')->display() ) else ( execute (0)->display() ) ) else (if b1 = 0 then ( if (a)->includes(0) then ( execute (0)->display() ) else ( execute ("inf")->display() ) ) else ( var cnt : int := 0 ; var p : OclAny := b1 ; while ((p)->abs()->compareTo(l)) <= 0 do ( if (a)->excludes(p) then ( cnt := cnt + 1 ) else skip ; p := p * q) ; execute (cnt)->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() m=[[0]*201 for i in range(201)] x=y=100 m[100][100]=1 d={'U' :[1,0],'D' :[-1,0],'R' :[0,1],'L' :[0,-1]} z={'U' : 'D','D' : 'U','L' : 'R','R' : 'L'} o={i :[d[j]for j in 'UDRL' if j!=z[i]]for i in 'UDRL'} for i in s : x+=d[i][0] y+=d[i][1] m[x][y]=1 for k in o[i]: if m[x+k[0]][y+k[1]]: print('BUG') break else : continue break else : if len(s)-1 and z[s[0]]==s[1]: print('BUG') else : print('OK') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var m : Sequence := Integer.subrange(0, 201-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, 201))) ; var x : OclAny := 100; var y : int := 100 ; m[100+1][100+1] := 1 ; var d : Map := Map{ 'U' |-> Sequence{1}->union(Sequence{ 0 }) }->union(Map{ 'D' |-> Sequence{-1}->union(Sequence{ 0 }) }->union(Map{ 'R' |-> Sequence{0}->union(Sequence{ 1 }) }->union(Map{ 'L' |-> Sequence{0}->union(Sequence{ -1 }) }))) ; var z : Map := Map{ 'U' |-> 'D' }->union(Map{ 'D' |-> 'U' }->union(Map{ 'L' |-> 'R' }->union(Map{ 'R' |-> 'L' }))) ; var o : Map := 'UDRL'->characters()->select(i | true)->collect(i | Map{i |-> 'UDRL'->characters()->select(j | j /= z[i+1])->collect(j | (d[j+1]))})->unionAll() ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name s))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name y)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name m)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name k)))) in (testlist (test (logical_test (comparison (expr (atom (name o)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name m)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (name k)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name y))) + (expr (atom (name k)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))))) ])))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'BUG'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt continue))))))) (stmt (simple_stmt (small_stmt break)))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))) - (expr (atom (number (integer 1))))))) and (logical_test (comparison (comparison (expr (atom (name z)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])))) == (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'BUG'))))))) )))))))))))) (else_clause else : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'OK'))))))) )))))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- record_of_movements=input() x,y=0,0 d_movement={'L' :(0,-1),'R' :(0,1),'U' :(1,0),'D' :(-1,0)} d={(x,y): ''} bug=False for move in record_of_movements : temp=(x,y) x+=d_movement[move][0] y+=d_movement[move][1] if(x,y)not in d : for step in d_movement : if(x+d_movement[step][0],y+d_movement[step][1])!=temp and(x+d_movement[step][0],y+d_movement[step][1])in d : bug=True break else : bug=True if bug : break d[x,y]='' if bug : print('BUG') else : print('OK') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var record_of_movements : String := (OclFile["System.in"]).readLine() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{0,0} ; var d_movement : Map := Map{ 'L' |-> Sequence{0, -1} }->union(Map{ 'R' |-> Sequence{0, 1} }->union(Map{ 'U' |-> Sequence{1, 0} }->union(Map{ 'D' |-> Sequence{-1, 0} }))) ; var d : Map := Map{ Sequence{x, y} |-> '' } ; var bug : boolean := false ; for move : record_of_movements->characters() do ( var temp : OclAny := Sequence{x, y} ; x := x + d_movement[move+1]->first() ; y := y + d_movement[move+1][1+1] ; if (d)->excludes(Sequence{x, y}) then ( for step : d_movement->keys() do ( if Sequence{x + d_movement[step+1]->first(), y + d_movement[step+1][1+1]} /= temp & (d)->includes(Sequence{x + d_movement[step+1]->first(), y + d_movement[step+1][1+1]}) then ( bug := true ; break ) else skip) ) else ( bug := true ) ; if bug then ( break ) else skip ; d[x+1][y+1] := '') ; if bug then ( execute ('BUG')->display() ) else ( execute ('OK')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def isPrime(n): if n<=1 : return False if n==2 : return True if n % 2==0 : return False for i in range(3,int(math.sqrt(n))+1,2): if n % i==0 : return False return True def isPossible(n): if isPrime(n)and isPrime(n-2): return True else : return False n=13 if isPossible(n)==True : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 13 ; if isPossible(n) = true then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isPrime(n : OclAny) : OclAny pre: true post: true activity: if n <= 1 then ( return false ) else skip ; if n = 2 then ( return true ) else skip ; if n mod 2 = 0 then ( return false ) else skip ; for i : Integer.subrange(3, ("" + (((n)->sqrt())))->toInteger() + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if n mod i = 0 then ( return false ) else skip) ; return true; operation isPossible(n : OclAny) : OclAny pre: true post: true activity: if isPrime(n) & isPrime(n - 2) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countDyckPaths(n): res=1 for i in range(0,n): res*=(2*n-i) res/=(i+1) return res/(n+1) n=4 print("Number of Dyck Paths is ",str(int(countDyckPaths(n)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute ("Number of Dyck Paths is ")->display(); operation countDyckPaths(n : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; for i : Integer.subrange(0, n-1) do ( res := res * (2 * n - i) ; res := res / (i + 1)) ; return res / (n + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) if(n<=30): print("NO") else : print("YES") if(n==40 or n==36 or n==44): print("6 10 15 ",n-31) else : print("6 10 14",n-30) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n <= 30) then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; if (n = 40 or n = 36 or n = 44) then ( execute ("6 10 15 ")->display() ) else ( execute ("6 10 14")->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tests=int(input()) for test in range(tests): a=int(input()) if a<=30 : print("NO") elif a>30 and a-30!=6 and a-30!=10 and a-30!=14 : print("YES") print(6,10,14,a-30,sep=' ') else : print("YES") print(6,10,15,a-31,sep=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var tests : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for test : Integer.subrange(0, tests-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if a <= 30 then ( execute ("NO")->display() ) else (if a > 30 & a - 30 /= 6 & a - 30 /= 10 & a - 30 /= 14 then ( execute ("YES")->display() ; execute (6)->display() ) else ( execute ("YES")->display() ; execute (6)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input(''))): n=int(input('')) if n>30 : print('YES') if n==36 : print(5,6,10,15) elif n==40 : print(6,10,15,9) elif n==44 : print(6,10,15,13) else : print(6,10,14,n-30) else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine(''))))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; if n > 30 then ( execute ('YES')->display() ; if n = 36 then ( execute (5)->display() ) else (if n = 40 then ( execute (6)->display() ) else (if n = 44 then ( execute (6)->display() ) else ( execute (6)->display() ) ) ) ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) for i in range(num): n=int(input()) if n<31 : print("NO") else : print("YES") if n-30==6 or n-30==10 or n-30==14 : print(f"{6}{10}{15}{n-31}") else : print(f"{6}{10}{14}{n-30}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, num-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n < 31 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; if n - 30 = 6 or n - 30 = 10 or n - 30 = 14 then ( execute (StringLib.formattedString("{6}{10}{15}{n-31}"))->display() ) else ( execute (StringLib.formattedString("{6}{10}{14}{n-30}"))->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) if n<31 : print("NO") else : print("YES") if n-30 in{6,10,14}: print(6,10,15,n-31) else : print(6,10,14,n-30) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n < 31 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; if (Set{6}->union(Set{10}->union(Set{ 14 })))->includes(n - 30) then ( execute (6)->display() ) else ( execute (6)->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: a=*map(int,s.split()),; i=7**6 for x,j in sorted(zip(a,range(i)))[: :-1]: print(*a[j : i]); i=min(i,j) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var a : OclAny := (testlist_star_expr (star_expr * (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name s)) (trailer . (name split) (arguments ( ))))))))) ))))) ,); var i : double := (7)->pow(6) ; for _tuple : sorted(Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), Integer.subrange(0, i-1)->at(_indx)} ))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); execute ((argument * (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))) : (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))->display(); i := Set{i, j}->min())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- b1,q,l,m=map(int,input().split()) bad=set(map(int,input().split())) if abs(b1)>l : print(0) elif q==0 or b1==0 : if 0 in bad : if b1 in bad : print(0) elif abs(b1)<=l : print(1) else : print(0) else : print("inf") elif q==1 : if b1 in bad or abs(b1)>l : print(0) else : print("inf") elif q==-1 : if b1 in bad and-b1 in bad or abs(b1)>l : print(0) else : print("inf") else : ans=0 while abs(b1)<=l : if b1 not in bad : ans+=1 b1*=q print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var b1 : OclAny := null; var q : OclAny := null; var l : OclAny := null; var m : OclAny := null; Sequence{b1,q,l,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var bad : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; if ((b1)->abs()->compareTo(l)) > 0 then ( execute (0)->display() ) else (if q = 0 or b1 = 0 then ( if (bad)->includes(0) then ( if (bad)->includes(b1) then ( execute (0)->display() ) else (if ((b1)->abs()->compareTo(l)) <= 0 then ( execute (1)->display() ) else ( execute (0)->display() ) ) ) else ( execute ("inf")->display() ) ) else (if q = 1 then ( if (bad)->includes(b1) or ((b1)->abs()->compareTo(l)) > 0 then ( execute (0)->display() ) else ( execute ("inf")->display() ) ) else (if q = -1 then ( if (bad)->includes(b1) & (bad)->includes(-b1) or ((b1)->abs()->compareTo(l)) > 0 then ( execute (0)->display() ) else ( execute ("inf")->display() ) ) else ( var ans : int := 0 ; while ((b1)->abs()->compareTo(l)) <= 0 do ( if (bad)->excludes(b1) then ( ans := ans + 1 ) else skip ; b1 := b1 * q) ; execute (ans)->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import gcd from functools import reduce def solve(string): n,*a=map(int,string.split()) return str(reduce(gcd,a)) if __name__=='__main__' : print(solve("\n".join([input(),input()]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( execute (solve(StringLib.sumStringsWithSeparator((Sequence{(OclFile["System.in"]).readLine()}->union(Sequence{ (OclFile["System.in"]).readLine() })), "\n")))->display() ) else skip; operation solve(string : OclAny) : OclAny pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := (string.split())->collect( _x | (OclType["int"])->apply(_x) ) ; return ("" + ((reduce(gcd, a)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=list(map(int,input().split())) import functools import fractions gcd=functools.reduce(fractions.gcd,A) print(gcd) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; skip ; var gcd : OclAny := functools.reduce(fractions.gcd, A) ; execute (gcd)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(a % b==0): return b else : return gcd(b,a % b) N=int(input()) s=[int(x)for x in input().split()] tmp=s[0] for i in s[1 :]: tmp=gcd(tmp,i) print(tmp) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var tmp : OclAny := s->first() ; for i : s->tail() do ( tmp := gcd(tmp, i)) ; execute (tmp)->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a mod b = 0) then ( return b ) else ( return gcd(b, a mod b) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=sorted(list(map(int,input().split()))) res=a[0] while True : base=res total=0 for i in a : if i % base>0 : res=min(res,i % base) total+=i % base if total==0 : break print(base) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var res : OclAny := a->first() ; while true do ( var base : OclAny := res ; var total : int := 0 ; for i : a do ( if i mod base > 0 then ( res := Set{res, i mod base}->min() ) else skip ; total := total + i mod base) ; if total = 0 then ( break ) else skip) ; execute (base)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import reduce n=int(input()) a=[int(m)for m in input().split()] def gcd(a,b): if b==0 : return a return gcd(b,a % b) def gcd_list(numbers): return reduce(gcd,numbers) a.sort() new=[a[0]] for i in range(1,n): new.append(a[i]% a[0]) new.sort() k=gcd_list(new) for i in range(n): if new[i]% k!=0 : print(1) exit() print(gcd_list(new)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(m | true)->collect(m | (("" + ((m)))->toInteger())) ; skip ; skip ; a := a->sort() ; var new : Sequence := Sequence{ a->first() } ; for i : Integer.subrange(1, n-1) do ( execute ((a[i+1] mod a->first()) : new)) ; new := new->sort() ; var k : OclAny := gcd_list(new) ; for i : Integer.subrange(0, n-1) do ( if new[i+1] mod k /= 0 then ( execute (1)->display() ; exit() ) else skip) ; execute (gcd_list(new))->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if b = 0 then ( return a ) else skip ; return gcd(b, a mod b); operation gcd_list(numbers : OclAny) : OclAny pre: true post: true activity: return reduce(gcd, numbers); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy a=list(map(int,input().split())) ans=0 for i in range(0,14): x=copy.copy(a) n=a[i]//14 r=a[i]% 14 x[i]=0 for j in range(0,14): x[j]+=n if r>=13-i : for j in range(i+1,14): x[j]+=1 for j in range(0,r-13+i): x[j]+=1 else : for j in range(i+1,i+1+r): x[j]+=1 summ=0 for j in x : if j % 2==0 : summ+=j ans=max(ans,summ) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(0, 14-1) do ( var x : OclAny := copy->copy() ; var n : int := a[i+1] div 14 ; var r : int := a[i+1] mod 14 ; x[i+1] := 0 ; for j : Integer.subrange(0, 14-1) do ( x[j+1] := x[j+1] + n) ; if (r->compareTo(13 - i)) >= 0 then ( for j : Integer.subrange(i + 1, 14-1) do ( x[j+1] := x[j+1] + 1) ; for j : Integer.subrange(0, r - 13 + i-1) do ( x[j+1] := x[j+1] + 1) ) else ( for j : Integer.subrange(i + 1, i + 1 + r-1) do ( x[j+1] := x[j+1] + 1) ) ; var summ : int := 0 ; for j : x do ( if j mod 2 = 0 then ( summ := summ + j ) else skip) ; ans := Set{ans, summ}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from re import I a=list(map(int,input().split())) max=0 for i in range(14): if a[i]>0 : j=i+1 add_to_every=a[i]//14 rem=a[i]% 14 temp=[x for x in a] temp[i]=0 temp=[x+add_to_every for x in temp] while rem>0 : temp[j % 14]+=1 rem-=1 j+=1 sum=0 for i in range(14): if temp[i]% 2==0 : sum+=temp[i] if sum>max : max=sum print(max) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var max : int := 0 ; for i : Integer.subrange(0, 14-1) do ( if a[i+1] > 0 then ( var j : OclAny := i + 1 ; var add_to_every : int := a[i+1] div 14 ; var rem : int := a[i+1] mod 14 ; var temp : Sequence := a->select(x | true)->collect(x | (x)) ; temp[i+1] := 0 ; temp := temp->select(x | true)->collect(x | (x + add_to_every)) ; while rem > 0 do ( temp[j mod 14+1] := temp[j mod 14+1] + 1 ; rem := rem - 1 ; j := j + 1) ; var sum : int := 0 ; for i : Integer.subrange(0, 14-1) do ( if temp[i+1] mod 2 = 0 then ( sum := sum + temp[i+1] ) else skip) ; if (sum->compareTo(max)) > 0 then ( max := sum ) else skip ) else skip) ; execute (max)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def make(a,b): b=[x for x in a] return b a=list(map(int,input().strip().split())) b=[x for x in a] n=14 ans=[] for i in range(14): c=0 if a[i]!=0 : if a[i]<=13-i : for j in range(i+1,a[i]+i+1): b[j]+=1 if b[j]% 2==0 : c+=b[j] ans.append(c) b=make(a,[]) else : for j in range(i+1,14): b[j]+=1 b[i]=0 p=a[i]-(13-i) h=p//14 k=p % 14 for j in range(14): b[j]+=h for j in range(k): b[j]+=1 for j in range(14): if b[j]% 2==0 : c+=b[j] ans.append(c) b=make(a,[]) print(max(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; b := a->select(x | true)->collect(x | (x)) ; var n : int := 14 ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, 14-1) do ( var c : int := 0 ; if a[i+1] /= 0 then ( if (a[i+1]->compareTo(13 - i)) <= 0 then ( for j : Integer.subrange(i + 1, a[i+1] + i + 1-1) do ( b[j+1] := b[j+1] + 1 ; if b[j+1] mod 2 = 0 then ( c := c + b[j+1] ) else skip) ; execute ((c) : ans) ; b := make(a, Sequence{}) ) else ( for j : Integer.subrange(i + 1, 14-1) do ( b[j+1] := b[j+1] + 1) ; b[i+1] := 0 ; var p : double := a[i+1] - (13 - i) ; var h : int := p div 14 ; var k : int := p mod 14 ; for j : Integer.subrange(0, 14-1) do ( b[j+1] := b[j+1] + h) ; for j : Integer.subrange(0, k-1) do ( b[j+1] := b[j+1] + 1) ; for j : Integer.subrange(0, 14-1) do ( if b[j+1] mod 2 = 0 then ( c := c + b[j+1] ) else skip) ; execute ((c) : ans) ; b := make(a, Sequence{}) ) ) else skip) ; execute ((ans)->max())->display(); operation make(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: b := a->select(x | true)->collect(x | (x)) ; return b; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=list(map(int,input().split())) ma1=0 ma2=0 for i in range(14): ma1=0 l1=l.copy() if(l1[i]!=0): v=l1[i] l1[i]=0 for j in range(14): l1[(i+j+1)% 14]+=v//14 while(v % 14!=0): l1[(i+1)% 14]+=1 i+=1 v-=1 for j in range(14): if(l1[j]!=0 and l1[j]% 2==0): ma1+=l1[j] if(ma1>ma2): ma2=ma1 print(ma2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ma1 : int := 0 ; var ma2 : int := 0 ; for i : Integer.subrange(0, 14-1) do ( ma1 := 0 ; var l1 : OclAny := l->copy() ; if (l1[i+1] /= 0) then ( var v : OclAny := l1[i+1] ; l1[i+1] := 0 ; for j : Integer.subrange(0, 14-1) do ( l1[(i + j + 1) mod 14+1] := l1[(i + j + 1) mod 14+1] + v div 14) ; while (v mod 14 /= 0) do ( l1[(i + 1) mod 14+1] := l1[(i + 1) mod 14+1] + 1 ; i := i + 1 ; v := v - 1) ; for j : Integer.subrange(0, 14-1) do ( if (l1[j+1] /= 0 & l1[j+1] mod 2 = 0) then ( ma1 := ma1 + l1[j+1] ) else skip) ; if ((ma1->compareTo(ma2)) > 0) then ( ma2 := ma1 ) else skip ) else skip) ; execute (ma2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline q=list(map(int,input().split())) z=0 for c in range(14): if q[c]!=0 : w=q[: :] x=w[c] a=x//14 b=x % 14 w[c]=0 for i in range(14): w[i]+=a while b : c+=1 if c==14 : c=0 w[c]+=1 b-=1 n=sum(i for i in w if i % 2==0) if n>z : z=n print(z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var q : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var z : int := 0 ; for c : Integer.subrange(0, 14-1) do ( if q[c+1] /= 0 then ( var w : OclAny := q(subscript : (sliceop :)) ; var x : OclAny := w[c+1] ; var a : int := x div 14 ; var b : int := x mod 14 ; w[c+1] := 0 ; for i : Integer.subrange(0, 14-1) do ( w[i+1] := w[i+1] + a) ; while b do ( c := c + 1 ; if c = 14 then ( var c : int := 0 ) else skip ; w[c+1] := w[c+1] + 1 ; b := b - 1) ; var n : OclAny := ((argument (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name w))))) (comp_iter if (test (logical_test (comparison (comparison (expr (expr (atom (name i))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 0))))))))))))->sum() ; if (n->compareTo(z)) > 0 then ( z := n ) else skip ) else skip) ; execute (z)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) a=list(map(int,input().split())) l=2*pow(10,5)+5 cnt=[0]*l for i in range(n): ai=a[i] for j in range(i+1,n): cnt[ai+a[j]]+=1 ans=max(cnt) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : double := 2 * (10)->pow(5) + 5 ; var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, l) ; for i : Integer.subrange(0, n-1) do ( var ai : OclAny := a[i+1] ; for j : Integer.subrange(i + 1, n-1) do ( cnt[ai + a[j+1]+1] := cnt[ai + a[j+1]+1] + 1)) ; var ans : OclAny := (cnt)->max() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=[int(x)for x in input().split()] ind,ce,ans=[0]*n,n,[] for i in range(n): ind[n-a[i]]=i for i in ind : if itoInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ind : OclAny := null; var ce : OclAny := null; var ans : OclAny := null; Sequence{ind,ce,ans} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, n),n,Sequence{}} ; for i : Integer.subrange(0, n-1) do ( ind[n - a[i+1]+1] := i) ; for i : ind do ( if (i->compareTo(ce)) < 0 then ( ans := ans + a.subrange(i+1, ce) ; var ce : OclAny := i ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pentdiagonal(a): if(a<0): return-1 d=1.22*a return d if __name__=="__main__" : a=6 print(pentdiagonal(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := 6 ; execute (pentdiagonal(a))->display() ) else skip; operation pentdiagonal(a : OclAny) : OclAny pre: true post: true activity: if (a < 0) then ( return -1 ) else skip ; var d : double := 1.22 * a ; return d; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def hexDiagonal(a): if(a<0): return-1 ; d=1.73*a ; return d ; a=9 ; print(hexDiagonal(a)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 9; ; execute (hexDiagonal(a))->display();; operation hexDiagonal(a : OclAny) pre: true post: true activity: if (a < 0) then ( return -1; ) else skip ; var d : double := 1.73 * a; ; return d;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def translate(st): for i in range(1,len(st)): if(st[i-1]=='A' and st[i]=='B'): st[i-1]='C' for j in range(i,len(st)-1): st[j]=st[j+1] st[len(st)-1]='' return st=list("helloABworldABGfG") translate(st) print("The modified string is :") print(''.join(st)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; st := ("helloABworldABGfG")->characters() ; translate(st) ; execute ("The modified string is :")->display() ; execute (StringLib.sumStringsWithSeparator((st), ''))->display(); operation translate(st : OclAny) pre: true post: true activity: for i : Integer.subrange(1, (st)->size()-1) do ( if (st[i - 1+1] = 'A' & st[i+1] = 'B') then ( st[i - 1+1] := 'C' ; for j : Integer.subrange(i, (st)->size() - 1-1) do ( st[j+1] := st[j + 1+1]) ; st[(st)->size() - 1+1] := '' ) else skip) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def translate(st): l=len(st) if(l<2): return i=0 j=0 while(jcharacters() ; translate(st) ; execute ("The modified string is :")->display() ; execute (StringLib.sumStringsWithSeparator((st), ''))->display(); operation translate(st : OclAny) pre: true post: true activity: var l : int := (st)->size() ; if (l < 2) then ( return ) else skip ; var i : int := 0 ; var j : int := 0 ; while ((j->compareTo(l - 1)) < 0) do ( if (st[j+1] = 'A' & st[j + 1+1] = 'B') then ( j := j + 2 ; st[i+1] := 'C' ; i := i + 1 ; continue ) else skip ; st[i+1] := st[j+1] ; i := i + 1 ; j := j + 1) ; if (j = l - 1) then ( st[i+1] := st[j+1] ; i := i + 1 ) else skip ; st[i+1] := '' ; st[l - 1+1] := ''; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib,itertools def compute(): TARGET=2000 count=2 for ring in itertools.count(2): if all(map(eulerlib.is_prime,(ring*6-1,ring*6+1,ring*12+5))): count+=1 if count==TARGET : return str(ring*(ring-1)*3+2) if all(map(eulerlib.is_prime,(ring*6-1,ring*6+5,ring*12-7))): count+=1 if count==TARGET : return str(ring*(ring+1)*3+1) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var TARGET : int := 2000 ; var count : int := 2 ; for ring : itertools->count(2) do ( if ((Sequence{ring * 6 - 1, ring * 6 + 1, ring * 12 + 5})->collect( _x | (eulerlib.is_prime)->apply(_x) ))->forAll( _x | _x = true ) then ( count := count + 1 ; if count = TARGET then ( return ("" + ((ring * (ring - 1) * 3 + 2))) ) else skip ) else skip ; if ((Sequence{ring * 6 - 1, ring * 6 + 5, ring * 12 - 7})->collect( _x | (eulerlib.is_prime)->apply(_x) ))->forAll( _x | _x = true ) then ( count := count + 1 ; if count = TARGET then ( return ("" + ((ring * (ring + 1) * 3 + 1))) ) else skip ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) x=min(n,m) li=[] for i in range(x+1): x1=pow(i,2) for j in range(x+1): y1=pow(j,2) if(x1+j==n and i+y1==m): li.append((i,j)) print(len(li)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := Set{n, m}->min() ; var li : Sequence := Sequence{} ; for i : Integer.subrange(0, x + 1-1) do ( var x1 : double := (i)->pow(2) ; for j : Integer.subrange(0, x + 1-1) do ( var y1 : double := (j)->pow(2) ; if (x1 + j = n & i + y1 = m) then ( execute ((Sequence{i, j}) : li) ) else skip)) ; execute ((li)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- arr=[int(_)for _ in input().split()] c=0 for i in range(0,max(arr)+1): for j in range(0,max(arr)+1): if i**2+j==arr[0]and i+j**2==arr[1]: c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var arr : Sequence := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var c : int := 0 ; for i : Integer.subrange(0, (arr)->max() + 1-1) do ( for j : Integer.subrange(0, (arr)->max() + 1-1) do ( if (i)->pow(2) + j = arr->first() & i + (j)->pow(2) = arr[1+1] then ( c := c + 1 ) else skip)) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) count=0 for a in range(int(n**0.5)+1): b=n-a**2 if a+b**2==m : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var count : int := 0 ; for a : Integer.subrange(0, ("" + (((n)->pow(0.5))))->toInteger() + 1-1) do ( var b : double := n - (a)->pow(2) ; if a + (b)->pow(2) = m then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) i=0 for a in range(0,int(n**0.5)+1): for b in range(0,int(m**0.5)+1): if(a*a+b)==n and(b*b+a)==m : i+=1 print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var i : int := 0 ; for a : Integer.subrange(0, ("" + (((n)->pow(0.5))))->toInteger() + 1-1) do ( for b : Integer.subrange(0, ("" + (((m)->pow(0.5))))->toInteger() + 1-1) do ( if (a * a + b) = n & (b * b + a) = m then ( i := i + 1 ) else skip)) ; execute (i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) nn=[int(i)for i in input().split()] m=int(input()) mm=[int(i)for i in input().split()] l={} i=0 s=0 j=-1 x=mm[:] x.sort() while i<=m-1 and j<=n-1 : if stoInteger() ; var nn : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mm : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var l : OclAny := Set{} ; var i : int := 0 ; var s : int := 0 ; var j : int := -1 ; var x : Sequence := mm ; x := x->sort() ; while (i->compareTo(m - 1)) <= 0 & (j->compareTo(n - 1)) <= 0 do ( if (s->compareTo(x[i+1])) < 0 then ( j := j + 1 ) else ( l[x[i+1]+1] := j + 1 ; i := i + 1 ; continue ) ; s := s + nn[j+1]) ; for key : mm do ( execute (l[key+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printSumTricky(mat,k): global n if k>n : return stripSum=[[None]*n for i in range(n)] for j in range(n): Sum=0 for i in range(k): Sum+=mat[i][j] stripSum[0][j]=Sum for i in range(1,n-k+1): Sum+=(mat[i+k-1][j]-mat[i-1][j]) stripSum[i][j]=Sum for i in range(n-k+1): Sum=0 for j in range(k): Sum+=stripSum[i][j] print(Sum,end=" ") for j in range(1,n-k+1): Sum+=(stripSum[i][j+k-1]-stripSum[i][j-1]) print(Sum,end=" ") print() n=5 mat=[[1,1,1,1,1],[2,2,2,2,2],[3,3,3,3,3],[4,4,4,4,4],[5,5,5,5,5]] k=3 printSumTricky(mat,k) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute n : OclAny; operation initialise() pre: true post: true activity: skip ; n := 5 ; mat := Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))))}->union(Sequence{Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 2 }))))}->union(Sequence{Sequence{3}->union(Sequence{3}->union(Sequence{3}->union(Sequence{3}->union(Sequence{ 3 }))))}->union(Sequence{Sequence{4}->union(Sequence{4}->union(Sequence{4}->union(Sequence{4}->union(Sequence{ 4 }))))}->union(Sequence{ Sequence{5}->union(Sequence{5}->union(Sequence{5}->union(Sequence{5}->union(Sequence{ 5 })))) })))) ; k := 3 ; printSumTricky(mat, k); operation printSumTricky(mat : OclAny, k : OclAny) pre: true post: true activity: skip ; if (k->compareTo(n)) > 0 then ( return ) else skip ; var stripSum : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ null }, n))) ; for j : Integer.subrange(0, n-1) do ( var Sum : int := 0 ; for i : Integer.subrange(0, k-1) do ( Sum := Sum + mat[i+1][j+1]) ; stripSum->first()[j+1] := Sum ; for i : Integer.subrange(1, n - k + 1-1) do ( Sum := Sum + (mat[i + k - 1+1][j+1] - mat[i - 1+1][j+1]) ; stripSum[i+1][j+1] := Sum)) ; for i : Integer.subrange(0, n - k + 1-1) do ( Sum := 0 ; for j : Integer.subrange(0, k-1) do ( Sum := Sum + stripSum[i+1][j+1]) ; execute (Sum)->display() ; for j : Integer.subrange(1, n - k + 1-1) do ( Sum := Sum + (stripSum[i+1][j + k - 1+1] - stripSum[i+1][j - 1+1]) ; execute (Sum)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) a.sort() dp=[0 for i in range(999999)] for i in range(n): for j in range(n): dp[a[i]+a[j]]+=1 print(max(dp)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var dp : Sequence := Integer.subrange(0, 999999-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( dp[a[i+1] + a[j+1]+1] := dp[a[i+1] + a[j+1]+1] + 1)) ; execute ((dp)->max() div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) cnt=0 for a in range(0,n+1): for b in range(0,n+1): if((a**2+b)==n)and((a+b**2)==m): cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cnt : int := 0 ; for a : Integer.subrange(0, n + 1-1) do ( for b : Integer.subrange(0, n + 1-1) do ( if (((a)->pow(2) + b) = n) & ((a + (b)->pow(2)) = m) then ( cnt := cnt + 1 ) else skip)) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: d={} i=0 r=1 for x in s.split(): r+=r>i r=min(r,i-d.get(x,-r)) d[x]=i i+=1 print(i-r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var d : OclAny := Set{} ; var i : int := 0 ; var r : int := 1 ; for x : s.split() do ( r := r + (r->compareTo(i)) > 0 ; r := Set{r, i - d.get(x, -r)}->min() ; d[x+1] := i ; i := i + 1) ; execute (i - r)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def PROBLEM(): for _ in range(int(input())): n=int(input()) P=list(map(int,input().split())) A=[0]*n A[0]=P[0] for i in range(1,n): A[i]=max(P[i],A[i-1]) j=n T=[] for i in range(n-1,-1,-1): if P[i]==A[i]: T.extend(P[i : j]) j=i print(*T) PROBLEM() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; PROBLEM(); operation PROBLEM() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var P : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var A : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; A->first() := P->first() ; for i : Integer.subrange(1, n-1) do ( A[i+1] := Set{P[i+1], A[i - 1+1]}->max()) ; var j : int := n ; var T : Sequence := Sequence{} ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if P[i+1] = A[i+1] then ( T := T->union(P.subrange(i+1, j)) ; j := i ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name T))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Digits(n): largest=0 smallest=9 while(n): r=n % 10 largest=max(r,largest) smallest=min(r,smallest) n=n//10 print(largest,smallest) n=2346 Digits(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 2346 ; Digits(n); operation Digits(n : OclAny) pre: true post: true activity: var largest : int := 0 ; var smallest : int := 9 ; while (n) do ( var r : int := n mod 10 ; largest := Set{r, largest}->max() ; smallest := Set{r, smallest}->min() ; n := n div 10) ; execute (largest)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(d1,d2,d3): maxx=max(d1,max(d2,d3)) sum=(d1+d2+d3) if(2*maxx>sum or sum % 2==1): print("-1") return x1=0 y1=0 x2=d1 y2=0 x3=(d1+d2-d3)//2 y3=(d2+d3-d1)//2 print("(",x1,",",y1,"),(",x2,",",y2,")and(",x3,",",y3,")") d1=3 d2=4 d3=5 solve(d1,d2,d3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; d1 := 3 ; d2 := 4 ; d3 := 5 ; solve(d1, d2, d3); operation solve(d1 : OclAny, d2 : OclAny, d3 : OclAny) pre: true post: true activity: var maxx : OclAny := Set{d1, Set{d2, d3}->max()}->max() ; var sum : OclAny := (d1 + d2 + d3) ; if ((2 * maxx->compareTo(sum)) > 0 or sum mod 2 = 1) then ( execute ("-1")->display() ; return ) else skip ; var x1 : int := 0 ; var y1 : int := 0 ; var x2 : OclAny := d1 ; var y2 : int := 0 ; var x3 : int := (d1 + d2 - d3) div 2 ; var y3 : int := (d2 + d3 - d1) div 2 ; execute ("(")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_CHAR=26 def distributingBalls(k,n,string): a=[0]*MAX_CHAR for i in range(n): a[ord(string[i])-ord('a')]+=1 for i in range(MAX_CHAR): if(a[i]>k): return False return True if __name__=="__main__" : n,k=6,3 string="aacaab" if(distributingBalls(k,n,string)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_CHAR : int := 26 ; skip ; if __name__ = "__main__" then ( Sequence{n,k} := Sequence{6,3} ; string := "aacaab" ; if (distributingBalls(k, n, string)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; operation distributingBalls(k : OclAny, n : OclAny, string : OclAny) : OclAny pre: true post: true activity: var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX_CHAR) ; for i : Integer.subrange(0, n-1) do ( a[(string[i+1])->char2byte() - ('a')->char2byte()+1] := a[(string[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; for i : Integer.subrange(0, MAX_CHAR-1) do ( if ((a[i+1]->compareTo(k)) > 0) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): N=int(input()) S=input() ctr=0 for i in S : if i=='T' : ctr+=1 else : ctr-=1 if ctr>N//3 or ctr<0 : break print('YES' if ctr==N//3 else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : String := (OclFile["System.in"]).readLine() ; var ctr : int := 0 ; for i : S->characters() do ( if i = 'T' then ( ctr := ctr + 1 ) else ( ctr := ctr - 1 ) ; if (ctr->compareTo(N div 3)) > 0 or ctr < 0 then ( break ) else skip) ; execute (if ctr = N div 3 then 'YES' else 'NO' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()); t,m=[],[]; s=input() for i in range(n): if s[i]=='T' : t.append(i) else : m.append(i) if len(t)!=2*len(m): print('NO') else : nm=len(m) for i in range(nm): if m[i]t[i+nm]: print('NO'); break else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var t : OclAny := null; var m : OclAny := null; Sequence{t,m} := Sequence{Sequence{},Sequence{}}; var s : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = 'T' then ( execute ((i) : t) ) else ( execute ((i) : m) )) ; if (t)->size() /= 2 * (m)->size() then ( execute ('NO')->display() ) else ( var nm : int := (m)->size() ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name nm)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name m)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) < (comparison (expr (atom (name t)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))) or (logical_test (comparison (comparison (expr (atom (name m)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) > (comparison (expr (atom (name t)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name nm))))))))) ])))))))) : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) )))))))))) ; (small_stmt break)))))) (else_clause else : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))))))))))) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def void(t,m,n,s): k=n//3 for i in range(n): if s[i]=='T' : t+=1 else : m+=1 if m>t or(t-m)>k : return("NO") break if t==2*m : return("YES") else : return("NO") for tt in range(int(input())): n=int(input()) s=input() t,m=0,0 print(void(t,m,n,s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for tt : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; s := (OclFile["System.in"]).readLine() ; Sequence{t,m} := Sequence{0,0} ; execute (void(t, m, n, s))->display()); operation void(t : OclAny, m : OclAny, n : OclAny, s : OclAny) : OclAny pre: true post: true activity: var k : int := n div 3 ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = 'T' then ( t := t + 1 ) else ( m := m + 1 ) ; if (m->compareTo(t)) > 0 or ((t - m)->compareTo(k)) > 0 then ( return ("NO") ; break ) else skip) ; if t = 2 * m then ( return ("YES") ) else ( return ("NO") ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) s=input() c={"T" : 0,"M" : 0} for j in s : c[j]+=1 if c["M"]>c["T"]or c["T"]-c["M"]>n//3 : print("NO") break else : if c["M"]*2==c["T"]: print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var c : Map := Map{ "T" |-> 0 }->union(Map{ "M" |-> 0 }) ; (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name s))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom "M"))))))) ])))) > (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom "T"))))))) ])))))) or (logical_test (comparison (comparison (expr (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom "T"))))))) ]))) - (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom "M"))))))) ]))))) > (comparison (expr (expr (atom (name n))) // (expr (atom (number (integer 3)))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom "M"))))))) ]))) * (expr (atom (number (integer 2)))))) == (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom "T"))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() a=input().split() l=[0]*212345 for i in a : for j in a : l[int(i)+int(j)]+=1*(i!=j) print(max(l)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var a : OclAny := input().split() ; var l : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 212345) ; for i : a do ( for j : a do ( l[("" + ((i)))->toInteger() + ("" + ((j)))->toInteger()+1] := l[("" + ((i)))->toInteger() + ("" + ((j)))->toInteger()+1] + 1 * (i /= j))) ; execute ((l)->max() div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tc=int(input()) for _ in range(tc): n=int(input()) s=input() count=0 for i in s : if i=='T' : count+=1 else : count-=1 if count>n//3 or count<0 : break if count==n//3 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var tc : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, tc-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var count : int := 0 ; for i : s->characters() do ( if i = 'T' then ( count := count + 1 ) else ( count := count - 1 ) ; if (count->compareTo(n div 3)) > 0 or count < 0 then ( break ) else skip) ; if count = n div 3 then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- e=list(map(int,input().split())) e.sort() frag=True for i in range(1,4): if e[0]!=e[i]: frag=False break for i in range(5,8): if e[4]!=e[i]: frag=False break for i in range(9,12): if e[8]!=e[i]: frag=False break print("yes" if frag else "no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var e : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; e := e->sort() ; var frag : boolean := true ; for i : Integer.subrange(1, 4-1) do ( if e->first() /= e[i+1] then ( frag := false ; break ) else skip) ; for i : Integer.subrange(5, 8-1) do ( if e[4+1] /= e[i+1] then ( frag := false ; break ) else skip) ; for i : Integer.subrange(9, 12-1) do ( if e[8+1] /= e[i+1] then ( frag := false ; break ) else skip) ; execute (if frag then "yes" else "no" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=list(input().split()) l.sort() if l[0]==l[1]==l[2]==l[3]and l[4]==l[5]==l[6]==l[7]and l[8]==l[9]==l[10]==l[11]: print('yes') else : print('no') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := (input().split()) ; l := l->sort() ; if l->first() = l[1+1] & (l[1+1] == l[2+1]) & (l[2+1] == l[3+1]) & l[4+1] = l[5+1] & (l[5+1] == l[6+1]) & (l[6+1] == l[7+1]) & l[8+1] = l[9+1] & (l[9+1] == l[10+1]) & (l[10+1] == l[11+1]) then ( execute ('yes')->display() ) else ( execute ('no')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printArray(N,SUM,K): minSum=(N*(N+1))/2 maxSum=(N*K)-(N*(N-1))/2 if(minSum>SUM or maxSum=1): x=sum+(K-i) if(xcompareTo(SUM)) > 0 or (maxSum->compareTo(SUM)) < 0) then ( execute ("Not Possible")->display() ; return ) else skip ; var arr : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(1, N + 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( arr[i+1] := i) ; var sum : OclAny := minSum ; var i : OclAny := N ; while (i >= 1) do ( var x : OclAny := sum + (K - i) ; if ((x->compareTo(SUM)) < 0) then ( sum := sum + (K - i) ; arr[i+1] := K ; K := K - 1 ) else ( arr[i+1] := arr[i+1] + (SUM - sum) ; sum := SUM ; break ) ; i := i - 1) ; for i : Integer.subrange(1, N + 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( execute (("" + ((arr[i+1])))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- li=list(map(int,input().split())) so=sorted(li) a=so[0] b=so[4] c=so[8] for n in so[: 4]: res1=a==n for n in so[4 : 8]: res2=b==n for n in so[8 :]: res3=c==n res='yes' if res1 and res3 and res2 else 'no' print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var li : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var so : Sequence := li->sort() ; var a : OclAny := so->first() ; var b : OclAny := so[4+1] ; var c : OclAny := so[8+1] ; for n : so.subrange(1,4) do ( var res1 : boolean := a = n) ; for n : so.subrange(4+1, 8) do ( var res2 : boolean := b = n) ; for n : so.subrange(8+1) do ( var res3 : boolean := c = n) ; var res : String := if res1 & res3 & res2 then 'yes' else 'no' endif ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input().split() print('yes' if all([x.count(x[i])% 4==0 for i in range(len(x))])else 'no') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := input().split() ; execute (if (Integer.subrange(0, (x)->size()-1)->select(i | true)->collect(i | (x->count(x[i+1]) mod 4 = 0)))->forAll( _x | _x = true ) then 'yes' else 'no' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[int(i)for i in input().split()] a.sort() if a[0]==a[1]and a[1]==a[2]and a[2]==a[3]and a[4]==a[5]and a[5]==a[6]and a[6]==a[7]and a[8]==a[9]and a[9]==a[10]and a[10]==a[11]: print("yes") else : print("no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; a := a->sort() ; if a->first() = a[1+1] & a[1+1] = a[2+1] & a[2+1] = a[3+1] & a[4+1] = a[5+1] & a[5+1] = a[6+1] & a[6+1] = a[7+1] & a[8+1] = a[9+1] & a[9+1] = a[10+1] & a[10+1] = a[11+1] then ( execute ("yes")->display() ) else ( execute ("no")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys R=4 C=4 def first(arr,low,high): if(high>=low): mid=low+(high-low)//2 ; if((mid==0 or arr[mid-1]==0)and arr[mid]==1): return mid ; elif(arr[mid]==0): return first(arr,(mid+1),high); else : return first(arr,low,(mid-1)); return-1 ; def rowWith0s(mat): row_index=0 ; max=-(sys.maxsize-1); min_row_index=0 ; min=sys.maxsize ; for i in range(R): index=first(mat[i],0,C-1); cntZeroes=0 ; if(index==-1): cntZeroes=C ; else : cntZeroes=index ; if(maxcntZeroes): min=cntZeroes ; min_row_index=i ; print("Row with min 0s:",min_row_index+1); print("Row with max 0s:",max_row_index+1); if __name__=="__main__" : mat=[[0,0,0,1],[0,1,1,1],[1,1,1,1],[0,0,0,0]]; rowWith0s(mat); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var R : int := 4 ; var C : int := 4 ; skip ; skip ; if __name__ = "__main__" then ( mat := Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 1 })))}->union(Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })))}->union(Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })))}->union(Sequence{ Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))) }))); ; rowWith0s(mat); ) else skip; operation first(arr : OclAny, low : OclAny, high : OclAny) pre: true post: true activity: if ((high->compareTo(low)) >= 0) then ( var mid : OclAny := low + (high - low) div 2; ; if ((mid = 0 or arr[mid - 1+1] = 0) & arr[mid+1] = 1) then ( return mid; ) else (if (arr[mid+1] = 0) then ( return first(arr, (mid + 1), high); ) else ( return first(arr, low, (mid - 1)); ) ) ) else skip ; return -1;; operation rowWith0s(mat : OclAny) pre: true post: true activity: var row_index : int := 0; var max : double := -((trailer . (name maxsize)) - 1); ; var min_row_index : int := 0; var min : (trailer . (name maxsize)) := (trailer . (name maxsize)); ; for i : Integer.subrange(0, R-1) do ( var index : OclAny := first(mat[i+1], 0, C - 1); ; var cntZeroes : int := 0; ; if (index = -1) then ( cntZeroes := C; ) else ( cntZeroes := index; ) ; if ((max->compareTo(cntZeroes)) < 0) then ( max := cntZeroes; ; var max_row_index : OclAny := i; ) else skip ; if ((min->compareTo(cntZeroes)) > 0) then ( min := cntZeroes; ; min_row_index := i; ) else skip) ; execute ("Row with min 0s:")->display(); ; execute ("Row with max 0s:")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def bitAtGivenPosSetOrUnset(n,k): new_num=n>>(k-1) return(new_num & 1) n=10 k=2 if(bitAtGivenPosSetOrUnset(n,k)): print("Set") else : print("Unset") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 10 ; k := 2 ; if (bitAtGivenPosSetOrUnset(n, k)) then ( execute ("Set")->display() ) else ( execute ("Unset")->display() ); operation bitAtGivenPosSetOrUnset(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var new_num : int := n /(2->pow((k - 1))) ; return (MathLib.bitwiseAnd(new_num, 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input('')) s=list(input('')) if n % 4==0 : k=n//4 a=s.count('A') b=s.count('G') c=s.count('C') d=s.count('T') if a>k or b>k or c>k or d>k : print('===') else : for i in range(k-a): s[s.index('?')]='A' for j in range(k-b): s[s.index('?')]='G' for m in range(k-c): s[s.index('?')]='C' for t in range(k-d): s[s.index('?')]='T' print(''.join(s)) else : print('===') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; var s : Sequence := ((OclFile["System.in"]).readLine(''))->characters() ; if n mod 4 = 0 then ( var k : int := n div 4 ; var a : int := s->count('A') ; var b : int := s->count('G') ; var c : int := s->count('C') ; var d : int := s->count('T') ; if (a->compareTo(k)) > 0 or (b->compareTo(k)) > 0 or (c->compareTo(k)) > 0 or (d->compareTo(k)) > 0 then ( execute ('===')->display() ) else ( for i : Integer.subrange(0, k - a-1) do ( s[s->indexOf('?') - 1+1] := 'A') ; for j : Integer.subrange(0, k - b-1) do ( s[s->indexOf('?') - 1+1] := 'G') ; for m : Integer.subrange(0, k - c-1) do ( s[s->indexOf('?') - 1+1] := 'C') ; for t : Integer.subrange(0, k - d-1) do ( s[s->indexOf('?') - 1+1] := 'T') ; execute (StringLib.sumStringsWithSeparator((s), ''))->display() ) ) else ( execute ('===')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=lambda s,t : max(s)max()->compareTo((t)->min())) < 0 or ((t)->max()->compareTo((s)->min())) < 0) ; skip ; for x : OclFile["System.in"] do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; var f : OclAny := null; var g : OclAny := null; var h : OclAny := null; Sequence{a,b,c,d,e,f,g,h} := (x.split())->collect( _x | (OclType["double"])->apply(_x) ) ; execute (Sequence{'YES'}->union(Sequence{ 'NO' })->select(k->apply(Sequence{a, c}, Sequence{e, g}) or k->apply(Sequence{b, d}, Sequence{f, h})))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() a=input() b,c="ACGT?",[0]*5 for i in a : c[b.index(i)]+=1 for i in range(c.pop()): a=a.replace("?",b[c.index(min(c))],1) c[c.index(min(c))]+=1 print([a,"==="][len(set(c))!=1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var a : String := (OclFile["System.in"]).readLine() ; var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := Sequence{"ACGT?",MatrixLib.elementwiseMult(Sequence{ 0 }, 5)} ; for i : a->characters() do ( c[b->indexOf(i) - 1+1] := c[b->indexOf(i) - 1+1] + 1) ; for i : Integer.subrange(0, c->last()-1) do ( a := a.replace("?", b[c->indexOf((c)->min()) - 1+1], 1) ; c[c->indexOf((c)->min()) - 1+1] := c[c->indexOf((c)->min()) - 1+1] + 1) ; execute (Sequence{a}->union(Sequence{ "===" })->select((Set{}->union((c)))->size() /= 1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() a=input() b,c="ACGT?",[0]*5 for i in a : c[b.index(i)]+=1 for i in range(c.pop()): a=a.replace("?",b[c.index(min(c))],1) c[c.index(min(c))]+=1 print([a,"==="][len(set(c))!=1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var a : String := (OclFile["System.in"]).readLine() ; var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := Sequence{"ACGT?",MatrixLib.elementwiseMult(Sequence{ 0 }, 5)} ; for i : a->characters() do ( c[b->indexOf(i) - 1+1] := c[b->indexOf(i) - 1+1] + 1) ; for i : Integer.subrange(0, c->last()-1) do ( a := a.replace("?", b[c->indexOf((c)->min()) - 1+1], 1) ; c[c->indexOf((c)->min()) - 1+1] := c[c->indexOf((c)->min()) - 1+1] + 1) ; execute (Sequence{a}->union(Sequence{ "===" })->select((Set{}->union((c)))->size() /= 1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() a=input() b,c="ACGT?",[0]*5 for i in a : c[b.index(i)]+=1 for i in range(c.pop()): a=a.replace("?",b[c.index(min(c))],1) c[c.index(min(c))]+=1 print([a,"==="][len(set(c))!=1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var a : String := (OclFile["System.in"]).readLine() ; var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := Sequence{"ACGT?",MatrixLib.elementwiseMult(Sequence{ 0 }, 5)} ; for i : a->characters() do ( c[b->indexOf(i) - 1+1] := c[b->indexOf(i) - 1+1] + 1) ; for i : Integer.subrange(0, c->last()-1) do ( a := a.replace("?", b[c->indexOf((c)->min()) - 1+1], 1) ; c[c->indexOf((c)->min()) - 1+1] := c[c->indexOf((c)->min()) - 1+1] + 1) ; execute (Sequence{a}->union(Sequence{ "===" })->select((Set{}->union((c)))->size() /= 1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() a=input() b,c="ACGT?",[0]*5 for i in a : c[b.index(i)]+=1 for i in range(c.pop()): a=a.replace("?",b[c.index(min(c))],1) c[c.index(min(c))]+=1 print([a,"==="][len(set(c))!=1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var a : String := (OclFile["System.in"]).readLine() ; var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := Sequence{"ACGT?",MatrixLib.elementwiseMult(Sequence{ 0 }, 5)} ; for i : a->characters() do ( c[b->indexOf(i) - 1+1] := c[b->indexOf(i) - 1+1] + 1) ; for i : Integer.subrange(0, c->last()-1) do ( a := a.replace("?", b[c->indexOf((c)->min()) - 1+1], 1) ; c[c->indexOf((c)->min()) - 1+1] := c[c->indexOf((c)->min()) - 1+1] + 1) ; execute (Sequence{a}->union(Sequence{ "===" })->select((Set{}->union((c)))->size() /= 1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- COST=3 ; def maxItems(x,y,z): type1=x//COST ; x %=COST ; type2=y//COST ; y %=COST ; type3=z//COST ; z %=COST ; type4=min(x,min(y,z)); maxItems=type1+type2+type3+type4 ; return maxItems ; if __name__=="__main__" : x=4 ; y=5 ; z=6 ; print(maxItems(x,y,z)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var COST : int := 3; ; skip ; if __name__ = "__main__" then ( x := 4; y := 5; z := 6; ; execute (maxItems(x, y, z))->display(); ) else skip; operation maxItems(x : OclAny, y : OclAny, z : OclAny) pre: true post: true activity: var type1 : int := x div COST; ; x := x mod COST; ; var type2 : int := y div COST; ; y := y mod COST; ; var type3 : int := z div COST; ; z := z mod COST; ; var type4 : OclAny := Set{x, Set{y, z}->min()}->min(); ; var maxItems : int := type1 + type2 + type3 + type4; ; return maxItems;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mv=((-1,0),(0,1),(1,0),(0,-1)) while True : n=int(input()) if n==0 : break t1,t2,t3=input().split() s,t,b=ord(t1)-ord('A'),ord(t2)-ord('A'),ord(t3)-ord('A') f=[[[0.0 for a in range(3)]for c in range(3)]for r in range(17)] f[0][s//3][s % 3]=1 for j in range(1,n+1): for r in range(3): for c in range(3): for i in range(4): r2,c2=r+mv[i][0],c+mv[i][1] if r2<0 or r2>=3 or c2<0 or c2>=3 or 3*r2+c2==b : r2,c2=r,c f[j][r2][c2]+=f[j-1][r][c]/4 print(f[n][t//3][t % 3]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mv : OclAny := Sequence{Sequence{-1, 0}, Sequence{0, 1}, Sequence{1, 0}, Sequence{0, -1}} ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var t1 : OclAny := null; var t2 : OclAny := null; var t3 : OclAny := null; Sequence{t1,t2,t3} := input().split() ; var s : OclAny := null; var t : OclAny := null; var b : OclAny := null; Sequence{s,t,b} := Sequence{(t1)->char2byte() - ('A')->char2byte(),(t2)->char2byte() - ('A')->char2byte(),(t3)->char2byte() - ('A')->char2byte()} ; var f : Sequence := Integer.subrange(0, 17-1)->select(r | true)->collect(r | (Integer.subrange(0, 3-1)->select(c | true)->collect(c | (Integer.subrange(0, 3-1)->select(a | true)->collect(a | (0.0)))))) ; f->first()[s div 3+1][s mod 3+1] := 1 ; for j : Integer.subrange(1, n + 1-1) do ( for r : Integer.subrange(0, 3-1) do ( for c : Integer.subrange(0, 3-1) do ( for i : Integer.subrange(0, 4-1) do ( var r2 : OclAny := null; var c2 : OclAny := null; Sequence{r2,c2} := Sequence{r + mv[i+1]->first(),c + mv[i+1][1+1]} ; if r2 < 0 or r2 >= 3 or c2 < 0 or c2 >= 3 or 3 * r2 + c2 = b then ( var r2 : OclAny := null; var c2 : OclAny := null; Sequence{r2,c2} := Sequence{r,c} ) else skip ; f[j+1][r2+1][c2+1] := f[j+1][r2+1][c2+1] + f[j - 1+1][r+1][c+1] / 4)))) ; execute (f[n+1][t div 3+1][t mod 3+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- time=-1 place=["a","b","c","d","e","f","g","h","i"] empty_count={} for i in place : empty_count[i]=0 count_d=empty_count.copy() def reset(): global d global count_d d={"a" :["a","a","b","d"],"b" :["a","e","c","b"],"c" :["b","f","c","c"],"d" :["a","e","g","d"],"e" :["b","d","f","h"],"f" :["c","e","i","f"],"g" :["d","h","g","g"],"h" :["g","e","i","h"],"i" :["f","h","i","i"]} count_d=empty_count.copy() def pre_set(start_place,fix_place): global d global count_d for i in place : d[i]=list(("").join(d[i]).replace(fix_place,i)) count_d[start_place]=1 def repeat(time): global count_d for i in range(time): new_count_d=empty_count.copy() old_count_d=count_d.copy() for j in place : for k in d[j]: new_count_d[k]+=old_count_d[j] count_d=new_count_d.copy() while time!=0 : time=int(raw_input()) if time==0 : break else : info_pre=raw_input().split() info=[] for i in info_pre : info.append(i.lower()) reset() pre_set(info[0],info[2]) repeat(time) print(count_d[info[1]])/float((4**time)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute d : OclAny; attribute count_d : OclAny; attribute d : OclAny; attribute count_d : OclAny; attribute count_d : OclAny; operation initialise() pre: true post: true activity: var time : int := -1 ; var place : Sequence := Sequence{"a"}->union(Sequence{"b"}->union(Sequence{"c"}->union(Sequence{"d"}->union(Sequence{"e"}->union(Sequence{"f"}->union(Sequence{"g"}->union(Sequence{"h"}->union(Sequence{ "i" })))))))) ; var empty_count : OclAny := Set{} ; for i : place do ( empty_count[i+1] := 0) ; var count_d : OclAny := empty_count->copy() ; skip ; skip ; skip ; while time /= 0 do ( time := ("" + ((raw_input())))->toInteger() ; if time = 0 then ( break ) else ( var info_pre : OclAny := raw_input().split() ; var info : Sequence := Sequence{} ; for i : info_pre do ( execute ((i->toLowerCase()) : info)) ) ; reset() ; pre_set(info->first(), info[2+1]) ; repeat(time) ; (expr (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name count_d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name info)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ])))))))) )))) / (expr (atom (name float)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 4)))) ** (expr (atom (name time)))))))) )))))))) )))))); operation reset() pre: true post: true activity: skip ; skip ; d := Map{ "a" |-> Sequence{"a"}->union(Sequence{"a"}->union(Sequence{"b"}->union(Sequence{ "d" }))) }->union(Map{ "b" |-> Sequence{"a"}->union(Sequence{"e"}->union(Sequence{"c"}->union(Sequence{ "b" }))) }->union(Map{ "c" |-> Sequence{"b"}->union(Sequence{"f"}->union(Sequence{"c"}->union(Sequence{ "c" }))) }->union(Map{ "d" |-> Sequence{"a"}->union(Sequence{"e"}->union(Sequence{"g"}->union(Sequence{ "d" }))) }->union(Map{ "e" |-> Sequence{"b"}->union(Sequence{"d"}->union(Sequence{"f"}->union(Sequence{ "h" }))) }->union(Map{ "f" |-> Sequence{"c"}->union(Sequence{"e"}->union(Sequence{"i"}->union(Sequence{ "f" }))) }->union(Map{ "g" |-> Sequence{"d"}->union(Sequence{"h"}->union(Sequence{"g"}->union(Sequence{ "g" }))) }->union(Map{ "h" |-> Sequence{"g"}->union(Sequence{"e"}->union(Sequence{"i"}->union(Sequence{ "h" }))) }->union(Map{ "i" |-> Sequence{"f"}->union(Sequence{"h"}->union(Sequence{"i"}->union(Sequence{ "i" }))) })))))))) ; count_d := empty_count->copy(); operation pre_set(start_place : OclAny, fix_place : OclAny) pre: true post: true activity: skip ; skip ; for i : place do ( d[i+1] := (("").join(d[i+1]).replace(fix_place, i))) ; count_d[start_place+1] := 1; operation repeat(time : OclAny) pre: true post: true activity: skip ; for i : Integer.subrange(0, time-1) do ( var new_count_d : OclAny := empty_count->copy() ; var old_count_d : OclAny := count_d->copy() ; for j : place do ( for k : d[j+1] do ( new_count_d[k+1] := new_count_d[k+1] + old_count_d[j+1])) ; count_d := new_count_d->copy()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=[] for y in range(9): x+=[[chr(65+y),y]] Room=dict(x) By=[[0,0,1,3],[0,1,2,4],[1,2,2,5],[0,3,4,6],[1,3,5,7]] By+=[[2,4,5,8],[3,6,6,7],[4,6,7,8],[5,7,8,8]] while 1 : BatP=input() if BatP==0 : break Info=raw_input().split() Prob=[0 for x in range(9)] Prob[Room[Info[0]]]=1 while 0byte2char()}->union(Sequence{ y }) }) ; var Room : Map := ((atom (name x))) ; var By : Sequence := Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 3 })))}->union(Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 4 })))}->union(Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 5 })))}->union(Sequence{Sequence{0}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 6 })))}->union(Sequence{ Sequence{1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 7 }))) })))) ; By := By + Sequence{Sequence{2}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 8 })))}->union(Sequence{Sequence{3}->union(Sequence{6}->union(Sequence{6}->union(Sequence{ 7 })))}->union(Sequence{Sequence{4}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 8 })))}->union(Sequence{ Sequence{5}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 8 }))) }))) ; while 1 do ( var BatP : String := (OclFile["System.in"]).readLine() ; if BatP = 0 then ( break ) else skip ; var Info : OclAny := raw_input().split() ; var Prob : Sequence := Integer.subrange(0, 9-1)->select(x | true)->collect(x | (0)) ; Prob[Room[Info->first()+1]+1] := 1 ; while 0 < BatP do ( BatP := BatP - 1 ; var AftI : Sequence := Prob ; Prob := Integer.subrange(0, 9-1)->select(x | true)->collect(x | (0)) ; for x : Integer.subrange(0, 9-1) do ( if x = Room[Info[2+1]+1] then ( for y : Integer.subrange(0, 4-1) do ( Prob[By->restrict(x)[y+1]+1] := Prob[By->restrict(x)[y+1]+1] + AftI[By->restrict(x)[y+1]+1] * 0.25) ) else ( for y : Integer.subrange(0, 4-1) do ( Prob->restrict(x) := Prob->restrict(x) + AftI[By->restrict(x)[y+1]+1] * 0.25) ))) ; execute (StringLib.interpolateStrings('{:.8f}', Sequence{Prob[Room[Info[1+1]+1]+1]}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- index="ABCDEFGHI".index dd=((-1,0),(0,-1),(1,0),(0,1)) while 1 : N=int(input()) if N==0 : break s,t,b=map(index,input().split()) S=[[0]*3 for i in range(3)] sy,sx=divmod(s,3) ty,tx=divmod(t,3) by,bx=divmod(b,3) T=[[0]*3 for i in range(3)] S[sy][sx]=1 for i in range(N): for y in range(3): for x in range(3): if x==bx and y==by : T[y][x]=0 continue r=0 for dx,dy in dd : nx=x+dx ; ny=y+dy if not 0<=nx<3 or not 0<=ny<3 or(bx==nx and by==ny): nx=x ; ny=y r+=S[ny][nx] T[y][x]=r S,T=T,S su=sum(sum(e)for e in S) print("%.15f" %(S[ty][tx]/su)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var index : OclAny := "ABCDEFGHI".index ; var dd : OclAny := Sequence{Sequence{-1, 0}, Sequence{0, -1}, Sequence{1, 0}, Sequence{0, 1}} ; while 1 do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var s : OclAny := null; var t : OclAny := null; var b : OclAny := null; Sequence{s,t,b} := (input().split())->collect( _x | (index)->apply(_x) ) ; var S : Sequence := Integer.subrange(0, 3-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, 3))) ; var sy : OclAny := null; var sx : OclAny := null; Sequence{sy,sx} := Sequence{(s div 3), (s mod 3)} ; var ty : OclAny := null; var tx : OclAny := null; Sequence{ty,tx} := Sequence{(t div 3), (t mod 3)} ; var by : OclAny := null; var bx : OclAny := null; Sequence{by,bx} := Sequence{(b div 3), (b mod 3)} ; var T : Sequence := Integer.subrange(0, 3-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, 3))) ; S[sy+1][sx+1] := 1 ; for i : Integer.subrange(0, N-1) do ( for y : Integer.subrange(0, 3-1) do ( for x : Integer.subrange(0, 3-1) do ( if x = bx & y = by then ( T[y+1][x+1] := 0 ; continue ) else skip ; var r : int := 0 ; for _tuple : dd do (var _indx : int := 1; var dx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dy : OclAny := _tuple->at(_indx); var nx : OclAny := x + dx; var ny : OclAny := y + dy ; if not(0 <= nx & (nx < 3)) or not(0 <= ny & (ny < 3)) or (bx = nx & by = ny) then ( nx := x; ny := y ) else skip ; r := r + S[ny+1][nx+1]) ; T[y+1][x+1] := r)) ; Sequence{S,T} := Sequence{T,S}) ; var su : OclAny := ((argument (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name e)))))))) ))))))) (comp_for for (exprlist (expr (atom (name e)))) in (logical_test (comparison (expr (atom (name S))))))))->sum() ; execute (StringLib.format("%.15f",(S[ty+1][tx+1] / su)))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break s,t,b=input().split() base=ord("A") blank=ord(b)-base dp=[[0]*9 for _ in range(n+1)] dp[0][ord(s)-base]=1 to={0 :(0,0,1,3),1 :(0,1,2,4),2 :(1,2,2,5),3 :(0,3,4,6),4 :(1,3,5,7),5 :(2,4,5,8),6 :(3,6,6,7),7 :(4,6,7,8),8 :(5,7,8,8)} def update(x,i): for nex in to[x]: if nex==blank : dp[i][x]+=dp[i-1][x]/4 else : dp[i][nex]+=dp[i-1][x]/4 for i in range(1,n+1): for x in range(9): update(x,i) print(dp[n][ord(t)-base]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var s : OclAny := null; var t : OclAny := null; var b : OclAny := null; Sequence{s,t,b} := input().split() ; var base : int := ("A")->char2byte() ; var blank : double := (b)->char2byte() - base ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 9))) ; dp->first()[(s)->char2byte() - base+1] := 1 ; var to : Map := Map{ 0 |-> Sequence{0, 0, 1, 3} }->union(Map{ 1 |-> Sequence{0, 1, 2, 4} }->union(Map{ 2 |-> Sequence{1, 2, 2, 5} }->union(Map{ 3 |-> Sequence{0, 3, 4, 6} }->union(Map{ 4 |-> Sequence{1, 3, 5, 7} }->union(Map{ 5 |-> Sequence{2, 4, 5, 8} }->union(Map{ 6 |-> Sequence{3, 6, 6, 7} }->union(Map{ 7 |-> Sequence{4, 6, 7, 8} }->union(Map{ 8 |-> Sequence{5, 7, 8, 8} })))))))) ; skip ; for i : Integer.subrange(1, n + 1-1) do ( for x : Integer.subrange(0, 9-1) do ( update(x, i))) ; execute (dp[n+1][(t)->char2byte() - base+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) w=sorted(map(int,input().split())) s=set() for i in range(n): for j in range(i+1,n): s.add(w[i]+w[j]) d=0 for x in s : j=n-1 c=0 for i in range(n): while ix : j-=1 if i>=j : break if w[i]+w[j]==x : j-=1 c+=1 d=max(d,c) print(d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var s : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( execute ((w[i+1] + w[j+1]) : s))) ; var d : int := 0 ; for x : s do ( var j : double := n - 1 ; var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( while (i->compareTo(j)) < 0 & (w[i+1] + w[j+1]->compareTo(x)) > 0 do ( j := j - 1) ; if (i->compareTo(j)) >= 0 then ( break ) else skip ; if w[i+1] + w[j+1] = x then ( j := j - 1 ; c := c + 1 ) else skip) ; d := Set{d, c}->max()) ; execute (d)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l,r=map(int,input().split()) result=set() for x in range(31): for y in range(20): v=2**x*3**y if l<=v<=r : result.add(v) print(len(result)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var result : Set := Set{}->union(()) ; for x : Integer.subrange(0, 31-1) do ( for y : Integer.subrange(0, 20-1) do ( var v : double := (2)->pow(x) * (3)->pow(y) ; if (l->compareTo(v)) <= 0 & (v <= r) then ( execute ((v) : result) ) else skip)) ; execute ((result)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l,r=map(int,input().split()) xLimit=31 yLimit=20 numbers=set() for i in range(xLimit): for j in range(yLimit): number=(2**i)*(3**j) if l<=number<=r : numbers.add(number) print(len(numbers)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var xLimit : int := 31 ; var yLimit : int := 20 ; var numbers : Set := Set{}->union(()) ; for i : Integer.subrange(0, xLimit-1) do ( for j : Integer.subrange(0, yLimit-1) do ( var number : double := ((2)->pow(i)) * ((3)->pow(j)) ; if (l->compareTo(number)) <= 0 & (number <= r) then ( execute ((number) : numbers) ) else skip)) ; execute ((numbers)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l,r=map(int,input().split()) ans=0 for x in range(32): for y in range(21): num=2**x*3**y if l<=num<=r : ans+=1 if num>r : break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; for x : Integer.subrange(0, 32-1) do ( for y : Integer.subrange(0, 21-1) do ( var num : double := (2)->pow(x) * (3)->pow(y) ; if (l->compareTo(num)) <= 0 & (num <= r) then ( ans := ans + 1 ) else skip ; if (num->compareTo(r)) > 0 then ( break ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) print(sum(a<=(2**i*3**j)<=b for j in range(20)for i in range(31))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (((argument (test (logical_test (comparison (comparison (comparison (expr (atom (name a)))) <= (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (number (integer 2)))) ** (expr (atom (name i)))) * (expr (expr (atom (number (integer 3)))) ** (expr (atom (name j))))))))) ))))) <= (comparison (expr (atom (name b))))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 20))))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 31))))))))) )))))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l,r=map(int,input().split()) result=set() for x in range(31): for y in range(20): v=2**x*3**y if l<=v<=r : result.add(v) print(len(result)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var result : Set := Set{}->union(()) ; for x : Integer.subrange(0, 31-1) do ( for y : Integer.subrange(0, 20-1) do ( var v : double := (2)->pow(x) * (3)->pow(y) ; if (l->compareTo(v)) <= 0 & (v <= r) then ( execute ((v) : result) ) else skip)) ; execute ((result)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def run_tasks(A,B): total_time=0 while(len(A)>0): x=A.popleft() y=B.popleft() if(x==y): total_time+=1 else : B.appendleft(y) A.append(x) total_time+=2 return total_time if __name__=='__main__' : A=deque() A.append(3) A.append(2) A.append(1) A.append(4) B=deque() B.append(4) B.append(1) B.append(3) B.append(2) print(run_tasks(A,B)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( A := () ; execute ((3) : A) ; execute ((2) : A) ; execute ((1) : A) ; execute ((4) : A) ; B := () ; execute ((4) : B) ; execute ((1) : B) ; execute ((3) : B) ; execute ((2) : B) ; execute (run_tasks(A, B))->display() ) else skip; operation run_tasks(A : OclAny, B : OclAny) : OclAny pre: true post: true activity: var total_time : int := 0 ; while ((A)->size() > 0) do ( var x : OclAny := A->first() ; A := A->tail() ; var y : OclAny := B->first() ; B := B->tail() ; if (x = y) then ( total_time := total_time + 1 ) else ( B := B->prepend(y) ; execute ((x) : A) ; total_time := total_time + 2 )) ; return total_time; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,open(0)); L=1 for i in range(N): L+=min(L,K) print(L) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (OclFile.newOclFile_Write(OclFile.newOclFile(0)))->collect( _x | (OclType["int"])->apply(_x) ); var L : int := 1 ; for i : Integer.subrange(0, N-1) do ( L := L + Set{L, K}->min()) ; execute (L)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(N : int,K : int): ret=1 while N : N-=1 if ret+KcompareTo(ret * 2)) < 0 then ( ret := ret + K ) else ( ret := ret * 2 )) ; execute (ret)->display() ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var N : int := ("" + (((tokens).next())))->toInteger() ; var K : int := ("" + (((tokens).next())))->toInteger() ; solve(N, K); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans=1 n=int(input()) k=int(input()) for _ in range(n): if ans*2toInteger() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( if (ans * 2->compareTo(ans + k)) < 0 then ( ans := ans * 2 ) else ( ans := ans + k )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin ni=lambda : int(ns()) na=lambda : list(map(int,stdin.readline().split())) ns=lambda : stdin.readline().strip() n=ni() k=ni() ans=1 for i in range(n): if ans<=k : ans*=2 else : ans+=k print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stdin : OclFile := OclFile["System.in"] ; var ni : Function := lambda $$ : OclAny in (("" + ((ns())))->toInteger()) ; var na : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ns : Function := lambda $$ : OclAny in (stdin.readLine()->trim()) ; var n : OclAny := ni->apply() ; var k : OclAny := ni->apply() ; var ans : int := 1 ; for i : Integer.subrange(0, n-1) do ( if (ans->compareTo(k)) <= 0 then ( ans := ans * 2 ) else ( ans := ans + k )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) b=[] c=[] for i in range(200001): b.append(0) for i in range(n-1): for j in range(i+1,n): b[a[i]+a[j]]+=1 print(max(b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := Sequence{} ; var c : Sequence := Sequence{} ; for i : Integer.subrange(0, 200001-1) do ( execute ((0) : b)) ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(i + 1, n-1) do ( b[a[i+1] + a[j+1]+1] := b[a[i+1] + a[j+1]+1] + 1)) ; execute ((b)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) K=int(input()) risuto=[1] for i in range(N): if(risuto[-1]+K>risuto[-1]*2): risuto.append(risuto[-1]*2) else : risuto.append(risuto[-1]+K) print(max(risuto)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var risuto : Sequence := Sequence{ 1 } ; for i : Integer.subrange(0, N-1) do ( if ((risuto->last() + K->compareTo(risuto->last() * 2)) > 0) then ( execute ((risuto->last() * 2) : risuto) ) else ( execute ((risuto->last() + K) : risuto) )) ; execute ((risuto)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def arePermutations(a,b,n,m): sum1,sum2,mul1,mul2=0,0,1,1 for i in range(n): sum1+=a[i] mul1*=a[i] for i in range(m): sum2+=b[i] mul2*=b[i] return((sum1==sum2)and(mul1==mul2)) if __name__=="__main__" : a=[1,3,2] b=[3,1,2] n=len(a) m=len(b) if arePermutations(a,b,n,m): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{1}->union(Sequence{3}->union(Sequence{ 2 })) ; b := Sequence{3}->union(Sequence{1}->union(Sequence{ 2 })) ; n := (a)->size() ; m := (b)->size() ; if arePermutations(a, b, n, m) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation arePermutations(a : OclAny, b : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var sum1 : OclAny := null; var sum2 : OclAny := null; var mul1 : OclAny := null; var mul2 : OclAny := null; Sequence{sum1,sum2,mul1,mul2} := Sequence{0,0,1,1} ; for i : Integer.subrange(0, n-1) do ( sum1 := sum1 + a[i+1] ; mul1 := mul1 * a[i+1]) ; for i : Integer.subrange(0, m-1) do ( sum2 := sum2 + b[i+1] ; mul2 := mul2 * b[i+1]) ; return ((sum1 = sum2) & (mul1 = mul2)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_CHAR=26 def findAndPrintUncommonChars(str1,str2): present=[0]*MAX_CHAR for i in range(0,MAX_CHAR): present[i]=0 l1=len(str1) l2=len(str2) for i in range(0,l1): present[ord(str1[i])-ord('a')]=1 for i in range(0,l2): if(present[ord(str2[i])-ord('a')]==1 or present[ord(str2[i])-ord('a')]==-1): present[ord(str2[i])-ord('a')]=-1 else : present[ord(str2[i])-ord('a')]=2 for i in range(0,MAX_CHAR): if(present[i]==1 or present[i]==2): print(chr(i+ord('a')),end=" ") if __name__=="__main__" : str1="characters" str2="alphabets" findAndPrintUncommonChars(str1,str2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_CHAR : int := 26 ; skip ; if __name__ = "__main__" then ( str1 := "characters" ; str2 := "alphabets" ; findAndPrintUncommonChars(str1, str2) ) else skip; operation findAndPrintUncommonChars(str1 : OclAny, str2 : OclAny) pre: true post: true activity: var present : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX_CHAR) ; for i : Integer.subrange(0, MAX_CHAR-1) do ( present[i+1] := 0) ; var l1 : int := (str1)->size() ; var l2 : int := (str2)->size() ; for i : Integer.subrange(0, l1-1) do ( present[(str1[i+1])->char2byte() - ('a')->char2byte()+1] := 1) ; for i : Integer.subrange(0, l2-1) do ( if (present[(str2[i+1])->char2byte() - ('a')->char2byte()+1] = 1 or present[(str2[i+1])->char2byte() - ('a')->char2byte()+1] = -1) then ( present[(str2[i+1])->char2byte() - ('a')->char2byte()+1] := -1 ) else ( present[(str2[i+1])->char2byte() - ('a')->char2byte()+1] := 2 )) ; for i : Integer.subrange(0, MAX_CHAR-1) do ( if (present[i+1] = 1 or present[i+1] = 2) then ( execute ((i + ('a')->char2byte())->byte2char())->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isInside(circle_x,circle_y,rad,x,y): if((x-circle_x)*(x-circle_x)+(y-circle_y)*(y-circle_y)<=rad*rad): return True ; else : return False ; x=1 ; y=1 ; circle_x=0 ; circle_y=1 ; rad=2 ; if(isInside(circle_x,circle_y,rad,x,y)): print("Inside"); else : print("Outside"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := 1; ; y := 1; ; circle_x := 0; ; circle_y := 1; ; rad := 2; ; if (isInside(circle_x, circle_y, rad, x, y)) then ( execute ("Inside")->display(); ) else ( execute ("Outside")->display(); ); operation isInside(circle_x : OclAny, circle_y : OclAny, rad : OclAny, x : OclAny, y : OclAny) pre: true post: true activity: if (((x - circle_x) * (x - circle_x) + (y - circle_y) * (y - circle_y)->compareTo(rad * rad)) <= 0) then ( return true; ) else ( return false; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minSum(arr,n,x): Sum=0 largestDivisible,minimum=-1,arr[0] for i in range(0,n): Sum+=arr[i] if(arr[i]% x==0 and largestDivisibleunion(Sequence{5}->union(Sequence{5}->union(Sequence{5}->union(Sequence{ 6 })))) ; n := (arr)->size() ; x := 3 ; execute (minSum(arr, n, x))->display() ) else skip; operation minSum(arr : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: var Sum : int := 0 ; var largestDivisible : OclAny := null; var minimum : OclAny := null; Sequence{largestDivisible,minimum} := Sequence{-1,arr->first()} ; for i : Integer.subrange(0, n-1) do ( Sum := Sum + arr[i+1] ; if (arr[i+1] mod x = 0 & (largestDivisible->compareTo(arr[i+1])) < 0) then ( var largestDivisible : OclAny := arr[i+1] ) else skip ; if (arr[i+1]->compareTo(minimum)) < 0 then ( var minimum : OclAny := arr[i+1] ) else skip) ; if largestDivisible = -1 then ( return Sum ) else skip ; var sumAfterOperation : double := (Sum - minimum - largestDivisible + (x * minimum) + (largestDivisible div x)) ; return Set{Sum, sumAfterOperation}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthTerm(n): nth=0 if(n % 2==0): nth=2*((n*n)-n) else : nth=(2*n*n)-n return nth n=5 print(nthTerm(n)) n=25 print(nthTerm(n)) n=25000000 print(nthTerm(n)) n=250000007 print(nthTerm(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; execute (nthTerm(n))->display() ; n := 25 ; execute (nthTerm(n))->display() ; n := 25000000 ; execute (nthTerm(n))->display() ; n := 250000007 ; execute (nthTerm(n))->display(); operation nthTerm(n : OclAny) : OclAny pre: true post: true activity: var nth : int := 0 ; if (n mod 2 = 0) then ( nth := 2 * ((n * n) - n) ) else ( nth := (2 * n * n) - n ) ; return nth; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def line(x0,y0): c=2*y0*x0 print(y0,"x","+",x0,"y=",c) if __name__=='__main__' : x0=4 y0=3 line(x0,y0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( x0 := 4 ; y0 := 3 ; line(x0, y0) ) else skip; operation line(x0 : OclAny, y0 : OclAny) pre: true post: true activity: var c : double := 2 * y0 * x0 ; execute (y0)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,value): self.value=value self.next=None self.prev=None def run(): n=int(input()) tail=Node(None) node=tail for _ in range(n): command=input() if command.startswith('0'): nn=Node(int(command[2 :])) nn.prev,nn.next=node.prev,node if node.prev is not None : node.prev.next=nn node.prev=nn node=node.prev elif command.startswith('1'): i=int(command[2 :]) if i>0 : for _ in range(i): node=node.next else : for _ in range(-i): node=node.prev elif command.startswith('2'): p,n=node.prev,node.next node.prev,node.next=None,None node=n if p is None : n.prev=None else : n.prev,p.next=p,n else : raise ValueError('invalid command') st=[] node=tail.prev while node is not None : st.append(node.value) node=node.prev while len(st)>0 : print(st.pop()) if __name__=='__main__' : run() ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute value : OclAny := value; attribute next : OclAny := null; attribute prev : OclAny := null; operation initialise(value : OclAny) : Node pre: true post: true activity: self.value := value ; self.next := null ; self.prev := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( run() ) else skip; operation run() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var tail : Node := (Node.newNode()).initialise(null) ; var node : OclAny := tail ; for _anon : Integer.subrange(0, n-1) do ( var command : String := (OclFile["System.in"]).readLine() ; if command->hasPrefix('0') then ( var nn : Node := (Node.newNode()).initialise(("" + ((command.subrange(2+1))))->toInteger()) ; var nn.prev : OclAny := null; var nn.next : OclAny := null; Sequence{nn.prev,nn.next} := Sequence{node.prev,node} ; if not(node.prev <>= null) then ( node.prev.next := nn ) else skip ; node.prev := nn ; node := node.prev ) else (if command->hasPrefix('1') then ( var i : int := ("" + ((command.subrange(2+1))))->toInteger() ; if i > 0 then ( for _anon : Integer.subrange(0, i-1) do ( node := node.next) ) else ( for _anon : Integer.subrange(0, -i-1) do ( node := node.prev) ) ) else (if command->hasPrefix('2') then ( var p : OclAny := null; Sequence{p,n} := Sequence{node.prev,node.next} ; var node.prev : OclAny := null; var node.next : OclAny := null; Sequence{node.prev,node.next} := Sequence{null,null} ; node := n ; if p <>= null then ( n.prev := null ) else ( var n.prev : OclAny := null; var p.next : OclAny := null; Sequence{n.prev,p.next} := Sequence{p,n} ) ) else ( error IncorrectElementException.newIncorrectElementException('invalid command') ) ) ) ) ; var st : Sequence := Sequence{} ; node := tail.prev ; while not(node <>= null) do ( execute ((node.value) : st) ; node := node.prev) ; while (st)->size() > 0 do ( execute (st->last())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections class CursorList(): def __init__(self): self.vector=collections.deque() self.cursor=0 def insert(self,x): self.vector.appendleft(x) return self def move(self,d): self.vector.rotate(-d) self.cursor+=d return self def erase(self): self.vector.popleft() return self num_queue=int((input())) L=CursorList() for i in range(0,num_queue): queue=tuple(map(int,input().split(' '))) if queue[0]==0 : L.insert(queue[1]) elif queue[0]==1 : L.move(queue[1]) elif queue[0]==2 : L.erase() L.vector.rotate(L.cursor) print('\n'.join(map(str,L.vector))) ------------------------------------------------------------ OCL File: --------- class CursorList { static operation newCursorList() : CursorList pre: true post: CursorList->exists( _x | result = _x ); attribute vector : Sequence := (); attribute cursor : int := 0; operation initialise() : pre: true post: true activity: self.vector := () ; self.cursor := 0; return self; operation insert(x : OclAny) : OclAny pre: true post: true activity: (expr (atom (name self)) (trailer . (name vector)) (trailer . (name appendleft) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) ; return self; operation move(d : OclAny) : OclAny pre: true post: true activity: (expr (atom (name self)) (trailer . (name vector)) (trailer . (name rotate) (arguments ( (arglist (argument (test (logical_test (comparison (expr - (expr (atom (name d))))))))) )))) ; self.cursor := self.cursor + d ; return self; operation erase() : OclAny pre: true post: true activity: (expr (atom (name self)) (trailer . (name vector)) (trailer . (name popleft) (arguments ( )))) ; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var num_queue : int := ("" + ((((OclFile["System.in"]).readLine()))))->toInteger() ; var L : CursorList := (CursorList.newCursorList()).initialise() ; for i : Integer.subrange(0, num_queue-1) do ( var queue : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; if queue->first() = 0 then ( L := L.insertAt(queue[1+1]+1, queue[1+1]) ) else (if queue->first() = 1 then ( L.move(queue[1+1]) ) else (if queue->first() = 2 then ( L.erase() ) else skip ) ) ) ; (expr (atom (name L)) (trailer . (name vector)) (trailer . (name rotate) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)) (trailer . (name cursor)))))))) )))) ; execute (StringLib.sumStringsWithSeparator(((L.vector)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) A=[0 for i in range(1500000)] A[0]='end' cursor=0 head=[0 for i in range(1500000)] head_len=0 def insert(x): global cursor cursor+=1 A[cursor]=x def move(d): global cursor,head,head_len if d>=0 : head[head_len-1+d+(1): head_len-1+(1):-1]=A[cursor-d+1 : cursor+1] else : A[cursor+1 : cursor+1+(-d)]=head[head_len-1+(1): head_len-(-d)-1+(1):-1] cursor-=d head_len+=d def erase(): global cursor cursor-=1 for i in range(q): a=input() if a!="2" : b=[int(i)for i in a.split()] if b[0]==0 : insert(b[1]) elif b[0]==1 : move(b[1]) else : erase() A[cursor+1 : cursor+1+head_len]=head[head_len-1+(1):-1+(1):-1] length=cursor+head_len for i in range(1,length+1)[: :-1]: print(A[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute cursor : OclAny; attribute cursor : OclAny; attribute head : OclAny; attribute head_len : OclAny; attribute cursor : OclAny; operation initialise() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := Integer.subrange(0, 1500000-1)->select(i | true)->collect(i | (0)) ; A->first() := 'end' ; var cursor : int := 0 ; var head : Sequence := Integer.subrange(0, 1500000-1)->select(i | true)->collect(i | (0)) ; var head_len : int := 0 ; skip ; skip ; skip ; for i : Integer.subrange(0, q-1) do ( var a : String := (OclFile["System.in"]).readLine() ; if a /= "2" then ( var b : Sequence := a.split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if b->first() = 0 then ( insert(b[1+1]) ) else (if b->first() = 1 then ( move(b[1+1]) ) else skip) ) else ( erase() )) ; A.subrange(cursor + 1+1, cursor + 1 + head_len) := head(subscript (test (logical_test (comparison (expr (expr (expr (atom (name head_len))) - (expr (atom (number (integer 1))))) + (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1)))))))) ))))))) : (test (logical_test (comparison (expr (expr (atom - (number (integer 1)))) + (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1)))))))) ))))))) (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var length : int := cursor + head_len ; for i : range(1, length + 1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( execute (A[i+1])->display()); operation insert(x : OclAny) pre: true post: true activity: skip ; cursor := cursor + 1 ; A[cursor+1] := x; operation move(d : OclAny) pre: true post: true activity: skip; skip; skip ; if d >= 0 then ( head(subscript (test (logical_test (comparison (expr (expr (expr (expr (atom (name head_len))) - (expr (atom (number (integer 1))))) + (expr (atom (name d)))) + (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1)))))))) ))))))) : (test (logical_test (comparison (expr (expr (expr (atom (name head_len))) - (expr (atom (number (integer 1))))) + (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1)))))))) ))))))) (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) := A.subrange(cursor - d + 1+1, cursor + 1) ) else ( A.subrange(cursor + 1+1, cursor + 1 + (-d)) := head(subscript (test (logical_test (comparison (expr (expr (expr (atom (name head_len))) - (expr (atom (number (integer 1))))) + (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1)))))))) ))))))) : (test (logical_test (comparison (expr (expr (expr (expr (atom (name head_len))) - (expr (atom ( (testlist_comp (test (logical_test (comparison (expr - (expr (atom (name d)))))))) )))) - (expr (atom (number (integer 1))))) + (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1)))))))) ))))))) (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ) ; cursor := cursor - d ; head_len := head_len + d; operation erase() pre: true post: true activity: skip ; cursor := cursor - 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=int(input()),{} x=map(int,input().split()) for i,v in enumerate(x): m[v]=i+1 m=dict(sorted(m.items())) print(m[list(m)[0]],m[list(m)[-1]]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),Set{}} ; var x : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for _tuple : Integer.subrange(1, (x)->size())->collect( _indx | Sequence{_indx-1, (x)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); m[v+1] := i + 1) ; var m : Map := ((expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name m)) (trailer . (name items) (arguments ( ))))))))) ))))) ; execute (m[OclType["Sequence"](m)->first()+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin class LinkedList(): def __init__(self): self.head=[None,None,None] self.head[1]=self.pos=self.tail=[self.head,None,None] def insert(self,x): temp=[self.pos[0],self.pos,x] self.pos[0][1]=self.pos[0]=self.pos=[self.pos[0],self.pos,x] def move_right(self,d): for _ in range(d): self.pos=self.pos[1] def move_left(self,d): for _ in range(d): self.pos=self.pos[0] def move(self,d): if d>0 : self.move_right(d) else : self.move_left(d*-1) def erase(self): self.pos[1][0]=self.pos[0] self.pos=self.pos[0][1]=self.pos[1] def to_list(self): index=self.head[1] out=[] while(index[1]is not None): out.append(index[2]) index=index[1] return out n=stdin.readline() queries=stdin.readlines() ll=LinkedList() for query in queries : query=query.split() if query[0]=='0' : ll.insert(query[1]) elif query[0]=='1' : ll.move(int(query[1])) else : ll.erase() print('\n'.join(ll.to_list())) ------------------------------------------------------------ OCL File: --------- class LinkedList { static operation newLinkedList() : LinkedList pre: true post: LinkedList->exists( _x | result = _x ); attribute head : Sequence := Sequence{null}->union(Sequence{null}->union(Sequence{ null })); attribute (trailer . (name head) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) : OclAny (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name self)) (trailer . (name pos)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name self)) (trailer . (name tail)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name self)) (trailer . (name head)))))) , (test (logical_test (comparison (expr (atom None))))) , (test (logical_test (comparison (expr (atom None)))))) ])))))))); operation initialise() : pre: true post: true activity: self.head := Sequence{null}->union(Sequence{null}->union(Sequence{ null })) ; self->collect( _ser | _ser.subrange(1,[1+1])) := self->collect( _ser | _ser.subrange(1,[1+1]))(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name self)) (trailer . (name pos)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name self)) (trailer . (name tail)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name self)) (trailer . (name head)))))) , (test (logical_test (comparison (expr (atom None))))) , (test (logical_test (comparison (expr (atom None)))))) ])))))))); return self; operation insert(x : OclAny) pre: true post: true activity: var temp : Sequence := Sequence{self.pos->first()}->union(Sequence{self.pos}->union(Sequence{ x })) ; self.pos->first()[1+1] := self.pos->first()[1+1](assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name self)) (trailer . (name pos) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name self)) (trailer . (name pos)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name self)) (trailer . (name pos) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))) , (test (logical_test (comparison (expr (atom (name self)) (trailer . (name pos)))))) , (test (logical_test (comparison (expr (atom (name x))))))) ])))))))); operation move_right(d : OclAny) pre: true post: true activity: for _anon : Integer.subrange(0, d-1) do ( self.pos := self.pos[1+1]); operation move_left(d : OclAny) pre: true post: true activity: for _anon : Integer.subrange(0, d-1) do ( self.pos := self.pos->first()); operation move(d : OclAny) pre: true post: true activity: if d > 0 then ( self.move_right(d) ) else ( self.move_left(d * -1) ); operation erase() pre: true post: true activity: self.pos[1+1]->first() := self.pos->first() ; self.pos := self.pos[1+1]; var self.pos->first()[1+1] : OclAny := self.pos[1+1]; operation to_list() : OclAny pre: true post: true activity: var index : Map := self->collect( _ser | _ser.subrange(1,[1+1])) ; var out : Sequence := Sequence{} ; while (not(index[1+1] <>= null)) do ( execute ((index[2+1]) : out) ; index := index[1+1]) ; return out; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : String := stdin.readLine() ; var queries : OclAny := stdin.readlines() ; var ll : LinkedList := (LinkedList.newLinkedList()).initialise() ; for query : queries do ( var query : OclAny := query.split() ; if query->first() = '0' then ( ll := ll.insertAt(query[1+1]+1, query[1+1]) ) else (if query->first() = '1' then ( ll.move(("" + ((query[1+1])))->toInteger()) ) else ( ll.erase() ) ) ) ; execute (StringLib.sumStringsWithSeparator((ll.to_list()), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque q=int(input()) L=deque() cursor=0 for i in range(q): inp=input() if inp[0]=="0" : operation,x=inp.split() L.appendleft(x) elif inp[0]=="1" : operation,d=list(map(int,inp.split())) L.rotate(-d) cursor+=d else : L.popleft() L.rotate(cursor) [print(a)for a in L] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var L : Sequence := () ; var cursor : int := 0 ; for i : Integer.subrange(0, q-1) do ( var inp : String := (OclFile["System.in"]).readLine() ; if inp->first() = "0" then ( var operation : OclAny := null; var x : OclAny := null; Sequence{operation,x} := inp.split() ; L := L->prepend(x) ) else (if inp->first() = "1" then ( var operation : OclAny := null; var d : OclAny := null; Sequence{operation,d} := ((inp.split())->collect( _x | (OclType["int"])->apply(_x) )) ; L.rotate(-d) ; cursor := cursor + d ) else ( L := L->tail() ) ) ) ; L.rotate(cursor) ; ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().rstrip().split()) s=input() common=0 for i in range(n-1): a=s[n-1-i :] b=s[: i+1] if(a==b): common=i+1 continue ans=(n)+(k-1)*(n-common) final=s for i in range(k-1): final+=(s[common :]) print(final) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var common : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( var a : OclAny := s.subrange(n - 1 - i+1) ; var b : OclAny := s.subrange(1,i + 1) ; if (a = b) then ( common := i + 1 ; continue ) else skip) ; var ans : OclAny := (n) + (k - 1) * (n - common) ; var final : String := s ; for i : Integer.subrange(0, k - 1-1) do ( final := final + (s.subrange(common+1))) ; execute (final)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys t,m=map(int,sys.stdin.readline().split()) s=sys.stdin.readline().strip() def getNext(s : str): l=len(s) nxt=[0] i=1 j=0 while icollect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := sys.stdin.readLine()->trim() ; skip ; var n : OclAny := getNext(s) ; var chongfu : OclAny := s.subrange(-t + n[t - 1+1]+1) ; execute (s + chongfu * (m - 1))->display(); operation getNext(s : String) : OclAny pre: true post: true activity: var l : int := (s)->size() ; var nxt : Sequence := Sequence{ 0 } ; var i : int := 1 ; var j : int := 0 ; while (i->compareTo(l)) < 0 do ( if s[i+1] = s[j+1] then ( execute ((j + 1) : nxt) ; i := i + 1 ; j := j + 1 ) else (if j then ( j := nxt[j - 1+1] ) else ( execute ((0) : nxt) ; i := i + 1 ) ) ) ; return nxt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys t,m=map(int,sys.stdin.readline().split()) s=sys.stdin.readline().strip() def getNext(s): l=len(s) nxt=[0] i=1 j=0 while icollect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := sys.stdin.readLine()->trim() ; skip ; var n : OclAny := getNext(s) ; var chongfu : OclAny := s.subrange(-t + n[t - 1+1]+1) ; execute (s + chongfu * (m - 1))->display(); operation getNext(s : OclAny) : OclAny pre: true post: true activity: var l : int := (s)->size() ; var nxt : Sequence := Sequence{ 0 } ; var i : int := 1 ; var j : int := 0 ; while (i->compareTo(l)) < 0 do ( if s[i+1] = s[j+1] then ( execute ((j + 1) : nxt) ; i := i + 1 ; j := j + 1 ) else (if j then ( j := nxt[j - 1+1] ) else ( execute ((0) : nxt) ; i := i + 1 ) ) ) ; return nxt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() n,k=(int(s.split('')[0]),int(s.split('')[1])) s=input() repind=[] cur_rep=[] j=0 i=j+1 occur=-1 while(i0 : i=occur occur=-1 cur_rep=[] repind=[] j=0 i+=1 if len(repind)>0 : ss=s[:-len(repind)] else : ss=s sss='' for kk in range(k-1): sss=sss+ss sss=sss+s print(sss) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := Sequence{("" + ((s.split('')->first())))->toInteger(), ("" + ((s.split('')[1+1])))->toInteger()} ; s := (OclFile["System.in"]).readLine() ; var repind : Sequence := Sequence{} ; var cur_rep : Sequence := Sequence{} ; var j : int := 0 ; var i : int := j + 1 ; var occur : int := -1 ; while ((i->compareTo((s)->size())) < 0) do ( if s[j+1] = s[i+1] then ( if occur = -1 then ( occur := i ) else skip ; execute ((i) : repind) ; execute ((j) : cur_rep) ; j := j + 1 ) else ( if (repind)->size() > 0 then ( i := occur ; occur := -1 ) else skip ; cur_rep := Sequence{} ; repind := Sequence{} ; j := 0 ) ; i := i + 1) ; if (repind)->size() > 0 then ( var ss : OclAny := s.subrange(1,-(repind)->size()) ) else ( ss := s ) ; var sss : String := '' ; for kk : Integer.subrange(0, k - 1-1) do ( sss := sss + ss) ; sss := sss + s ; execute (sss)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) t=input() x=0 for i in range(1,n): if t[: i]==t[-i :]: x=i t+=t[x :]*(k-1) print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : String := (OclFile["System.in"]).readLine() ; var x : int := 0 ; for i : Integer.subrange(1, n-1) do ( if t.subrange(1,i) = t.subrange(-i+1) then ( x := i ) else skip) ; t := t + t.subrange(x+1) * (k - 1) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() print(len(set(map(frozenset,input().split())))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; execute ((Set{}->union(((input().split())->collect( _x | (frozenset)->apply(_x) ))))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class newNode : def __init__(self,data): self.data=data self.left=self.right=None def prInorder(node): if(node==None): return prInorder(node.left) print(node.data,end=" ") prInorder(node.right) def constructBinaryTreeUtil(pre,preM,preIndex,l,h,size): if(preIndex>=size or l>h): return None,preIndex root=newNode(pre[preIndex]) preIndex+=1 if(l==h): return root,preIndex i=0 for i in range(l,h+1): if(pre[preIndex]==preM[i]): break if(i<=h): root.left,preIndex=constructBinaryTreeUtil(pre,preM,preIndex,i,h,size) root.right,preIndex=constructBinaryTreeUtil(pre,preM,preIndex,l+1,i-1,size) return root,preIndex def constructBinaryTree(root,pre,preMirror,size): preIndex=0 preMIndex=0 root,x=constructBinaryTreeUtil(pre,preMirror,preIndex,0,size-1,size) prInorder(root) if __name__=="__main__" : preOrder=[1,2,4,5,3,6,7] preOrderMirror=[1,3,7,6,2,5,4] size=7 root=newNode(0) constructBinaryTree(root,preOrder,preOrderMirror,size) ------------------------------------------------------------ OCL File: --------- class newNode { static operation newnewNode() : newNode pre: true post: newNode->exists( _x | result = _x ); attribute data : OclAny := data; attribute left : OclAny := null; var self.right : OclAny := null; operation initialise(data : OclAny) : newNode pre: true post: true activity: self.data := data ; self.left := null; var self.right : OclAny := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( var preOrder : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{5}->union(Sequence{3}->union(Sequence{6}->union(Sequence{ 7 })))))) ; var preOrderMirror : Sequence := Sequence{1}->union(Sequence{3}->union(Sequence{7}->union(Sequence{6}->union(Sequence{2}->union(Sequence{5}->union(Sequence{ 4 })))))) ; size := 7 ; root := (newNode.newnewNode()).initialise(0) ; constructBinaryTree(root, preOrder, preOrderMirror, size) ) else skip; operation prInorder(node : OclAny) pre: true post: true activity: if (node = null) then ( return ) else skip ; prInorder(node.left) ; execute (node.data)->display() ; prInorder(node.right); operation constructBinaryTreeUtil(pre : OclAny, preM : OclAny, preIndex : OclAny, l : OclAny, h : OclAny, size : OclAny) : OclAny pre: true post: true activity: if ((preIndex->compareTo(size)) >= 0 or (l->compareTo(h)) > 0) then ( return null, preIndex ) else skip ; var root : newNode := (newNode.newnewNode()).initialise(pre[preIndex+1]) ; preIndex := preIndex + 1 ; if (l = h) then ( return root, preIndex ) else skip ; var i : int := 0 ; for i : Integer.subrange(l, h + 1-1) do ( if (pre[preIndex+1] = preM[i+1]) then ( break ) else skip) ; if ((i->compareTo(h)) <= 0) then ( var root.left : OclAny := null; Sequence{root.left,preIndex} := constructBinaryTreeUtil(pre, preM, preIndex, i, h, size) ; var root.right : OclAny := null; Sequence{root.right,preIndex} := constructBinaryTreeUtil(pre, preM, preIndex, l + 1, i - 1, size) ) else skip ; return root, preIndex; operation constructBinaryTree(root : OclAny, pre : OclAny, preMirror : OclAny, size : OclAny) pre: true post: true activity: preIndex := 0 ; var preMIndex : int := 0 ; var x : OclAny := null; Sequence{root,x} := constructBinaryTreeUtil(pre, preMirror, preIndex, 0, size - 1, size) ; prInorder(root); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- no_of_chars=256 def findSubString(string,pat): len1=len(string) len2=len(pat) if len1hash_pat[ord(string[start])]or hash_pat[ord(string[start])]==0): if(hash_str[ord(string[start])]>hash_pat[ord(string[start])]): hash_str[ord(string[start])]-=1 start+=1 len_window=j-start+1 if min_len>len_window : min_len=len_window start_index=start if start_index==-1 : print("No such window exists") return "" return string[start_index : start_index+min_len] if __name__=="__main__" : string="this is a test string" pat="tist" print("Smallest window is : ") print(findSubString(string,pat)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var no_of_chars : int := 256 ; skip ; if __name__ = "__main__" then ( string := "this is a test string" ; pat := "tist" ; execute ("Smallest window is : ")->display() ; execute (findSubString(string, pat))->display() ) else skip; operation findSubString(string : OclAny, pat : OclAny) : OclAny pre: true post: true activity: var len1 : int := (string)->size() ; var len2 : int := (pat)->size() ; if (len1->compareTo(len2)) < 0 then ( execute ("No such window exists")->display() ; return "" ) else skip ; var hash_pat : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, no_of_chars) ; var hash_str : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, no_of_chars) ; for i : Integer.subrange(0, len2-1) do ( hash_pat[(pat[i+1])->char2byte()+1] := hash_pat[(pat[i+1])->char2byte()+1] + 1) ; var start : OclAny := null; var start_index : OclAny := null; var min_len : OclAny := null; Sequence{start,start_index,min_len} := Sequence{0,-1,("" + (('inf')))->toReal()} ; var count : int := 0 ; for j : Integer.subrange(0, len1-1) do ( hash_str[(string[j+1])->char2byte()+1] := hash_str[(string[j+1])->char2byte()+1] + 1 ; if (hash_pat[(string[j+1])->char2byte()+1] /= 0 & (hash_str[(string[j+1])->char2byte()+1]->compareTo(hash_pat[(string[j+1])->char2byte()+1])) <= 0) then ( count := count + 1 ) else skip ; if count = len2 then ( while ((hash_str[(string[start+1])->char2byte()+1]->compareTo(hash_pat[(string[start+1])->char2byte()+1])) > 0 or hash_pat[(string[start+1])->char2byte()+1] = 0) do ( if ((hash_str[(string[start+1])->char2byte()+1]->compareTo(hash_pat[(string[start+1])->char2byte()+1])) > 0) then ( hash_str[(string[start+1])->char2byte()+1] := hash_str[(string[start+1])->char2byte()+1] - 1 ) else skip ; start := start + 1) ; var len_window : double := j - start + 1 ; if (min_len->compareTo(len_window)) > 0 then ( var min_len : OclAny := len_window ; var start_index : OclAny := start ) else skip ) else skip) ; if start_index = -1 then ( execute ("No such window exists")->display() ; return "" ) else skip ; return string.subrange(start_index+1, start_index + min_len); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): _,a=input(),(int(i)for i in input().split()) min_i,min_a,max_i,max_a=0,10**9+1,0,0 for i,a_i in enumerate(a): if a_imax_a : max_i,max_a=i,a_i print(min(min_i,max_i)+1,max(min_i,max_i)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var _anon : OclAny := null; var a : OclAny := null; Sequence{_anon,a} := Sequence{(OclFile["System.in"]).readLine(),Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))}} ; var min_i : OclAny := null; var min_a : OclAny := null; var max_i : OclAny := null; var max_a : OclAny := null; Sequence{min_i,min_a,max_i,max_a} := Sequence{0,(10)->pow(9) + 1,0,0} ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a_i : OclAny := _tuple->at(_indx); if (a_i->compareTo(min_a)) < 0 then ( var min_i : OclAny := null; var min_a : OclAny := null; Sequence{min_i,min_a} := Sequence{i,a_i} ) else skip ; if (a_i->compareTo(max_a)) > 0 then ( var max_i : OclAny := null; var max_a : OclAny := null; Sequence{max_i,max_a} := Sequence{i,a_i} ) else skip) ; execute (Set{min_i, max_i}->min() + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def tri(x1,y1,x2,y2,x3,y3): return math.fabs((x2-x1)*(y3-y1)-(y2-y1)*(x3-x1))/2 while True : try : x1,y1,x2,y2,x3,y3,x,y=map(float,input().split()) except : break abc=tri(x1,y1,x2,y2,x3,y3) abp=tri(x1,y1,x2,y2,x,y) acp=tri(x1,y1,x3,y3,x,y) bcp=tri(x2,y2,x3,y3,x,y) x,y=int(abc*pow(10,5)),int((abp+acp+bcp)*pow(10,5)) print("YES" if x>=y else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( try ( var x : OclAny := null; var y : OclAny := null; Sequence{x1,y1,x2,y2,x3,y3,x,y} := (input().split())->collect( _x | (OclType["double"])->apply(_x) )) catch (_e : OclException) do ( break) ; var abc : OclAny := tri(x1, y1, x2, y2, x3, y3) ; var abp : OclAny := tri(x1, y1, x2, y2, x, y) ; var acp : OclAny := tri(x1, y1, x3, y3, x, y) ; var bcp : OclAny := tri(x2, y2, x3, y3, x, y) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{("" + ((abc * (10)->pow(5))))->toInteger(),("" + (((abp + acp + bcp) * (10)->pow(5))))->toInteger()} ; execute (if (x->compareTo(y)) >= 0 then "YES" else "NO" endif)->display()); operation tri(x1 : OclAny, y1 : OclAny, x2 : OclAny, y2 : OclAny, x3 : OclAny, y3 : OclAny) : OclAny pre: true post: true activity: return ((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1))->abs() / 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import cmath import math class Point(object): def __init__(self,x,y): self.point=complex(x,y) def __str__(self): return "x={0},y={1}".format(self.point.real,self.point.imag) class Triangle(Point): def __init__(self,a,b,c): self.a=a self.b=b self.c=c self.edgeA=abs(b.point-c.point) self.edgeB=abs(c.point-a.point) self.edgeC=abs(a.point-b.point) self.angleA=Triangle.angle(self.edgeA,self.edgeB,self.edgeC) self.angleB=Triangle.angle(self.edgeB,self.edgeC,self.edgeA) self.angleC=Triangle.angle(self.edgeC,self.edgeA,self.edgeB) def angle(A,B,C): return cmath.acos((B*B+C*C-A*A)/(2*B*C)).real eps=0.0001 for line in sys.stdin : line=[float(x)for x in line.split()] p1=Point(line[0],line[1]) p2=Point(line[2],line[3]) p3=Point(line[4],line[5]) P=Point(line[6],line[7]) t1=Triangle(p1,p2,P) t2=Triangle(p2,p3,P) t3=Triangle(p3,p1,P) if(math.degrees(t1.angleC+t2.angleC+t3.angleC)<=360+eps)and(math.degrees(t1.angleC+t2.angleC+t3.angleC)>=360-eps): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class Point extends object { static operation newPoint() : Point pre: true post: Point->exists( _x | result = _x ); attribute point : OclAny := complex(x, y); operation initialise(x : OclAny,y : OclAny) : pre: true post: true activity: self.point := complex(x, y); return self; operation __str__() : OclAny pre: true post: true activity: return StringLib.interpolateStrings("x={0},y={1}", Sequence{self.point.real, self.point.imag}); } class Triangle extends Point { static operation newTriangle() : Triangle pre: true post: Triangle->exists( _x | result = _x ); attribute a : OclAny := a; attribute b : OclAny := b; attribute c : OclAny := c; attribute edgeA : double := (b.point - c.point)->abs(); attribute edgeB : double := (c.point - a.point)->abs(); attribute edgeC : double := (a.point - b.point)->abs(); attribute angleA : Triangle := Triangle.angle(self.edgeA, self.edgeB, self.edgeC); attribute angleB : Triangle := Triangle.angle(self.edgeB, self.edgeC, self.edgeA); attribute angleC : Triangle := Triangle.angle(self.edgeC, self.edgeA, self.edgeB); operation initialise(a : OclAny,b : OclAny,c : OclAny) : pre: true post: true activity: self.a := a ; self.b := b ; self.c := c ; self.edgeA := (b.point - c.point)->abs() ; self.edgeB := (c.point - a.point)->abs() ; self.edgeC := (a.point - b.point)->abs() ; self.angleA := Triangle.angle(self.edgeA, self.edgeB, self.edgeC) ; self.angleB := Triangle.angle(self.edgeB, self.edgeC, self.edgeA) ; self.angleC := Triangle.angle(self.edgeC, self.edgeA, self.edgeB); return self; operation angle(A : OclAny , B : OclAny,C : OclAny) : OclAny pre: true post: true activity: return cmath.acos((B * B + C * C - A * A) / (2 * B * C)).real; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var eps : double := 0.0001 ; for line : OclFile["System.in"] do ( var line : Sequence := line.split()->select(x | true)->collect(x | (("" + ((x)))->toReal())) ; var p1 : Point := (Point.newPoint()).initialise(line->first(), line[1+1]) ; var p2 : Point := (Point.newPoint()).initialise(line[2+1], line[3+1]) ; var p3 : Point := (Point.newPoint()).initialise(line[4+1], line[5+1]) ; var P : Point := (Point.newPoint()).initialise(line[6+1], line[7+1]) ; var t1 : Triangle := (Triangle.newTriangle()).initialise(p1, p2, P) ; var t2 : Triangle := (Triangle.newTriangle()).initialise(p2, p3, P) ; var t3 : Triangle := (Triangle.newTriangle()).initialise(p3, p1, P) ; if ((->compareTo(360 + eps)) <= 0) & ((->compareTo(360 - eps)) >= 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys for a,b,c,d,e,f,g,h in[map(float,l.split())for l in sys.stdin]: print["NO","YES"][((c-a)*(d-h)-(d-b)*(c-g)>0)==((e-c)*(f-h)-(f-d)*(e-g)>0)==((a-e)*(b-h)-(b-f)*(a-g)>0)] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _tuple : OclFile["System.in"]->select(l | true)->collect(l | ((l.split())->collect( _x | (OclType["double"])->apply(_x) ))) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); _indx := _indx + 1; var e : OclAny := _tuple->at(_indx); _indx := _indx + 1; var f : OclAny := _tuple->at(_indx); _indx := _indx + 1; var g : OclAny := _tuple->at(_indx); _indx := _indx + 1; var h : OclAny := _tuple->at(_indx); (expr (atom print) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom "NO")))))) , (subscript (test (logical_test (comparison (expr (atom "YES"))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (comparison (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name c))) - (expr (atom (name a)))))))) ))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name d))) - (expr (atom (name h)))))))) )))) - (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name d))) - (expr (atom (name b)))))))) ))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name c))) - (expr (atom (name g)))))))) )))))) > (comparison (expr (atom (number (integer 0))))))))) )))) == (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name e))) - (expr (atom (name c)))))))) ))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name f))) - (expr (atom (name h)))))))) )))) - (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name f))) - (expr (atom (name d)))))))) ))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name e))) - (expr (atom (name g)))))))) )))))) > (comparison (expr (atom (number (integer 0))))))))) ))))) == (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (name e)))))))) ))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (name h)))))))) )))) - (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (name f)))))))) ))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (name g)))))))) )))))) > (comparison (expr (atom (number (integer 0))))))))) ))))))))) ])))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cross(a,b): return(a.conjugate()*b).imag def is_in_triangle(X1,Y1,X2,Y2,X3,Y3,Xp,Yp): z1=complex(X1-Xp,Y1-Yp) z2=complex(X2-Xp,Y2-Yp) z3=complex(X3-Xp,Y3-Yp) if cross(z1,z2)*cross(z2,z3)>0 : if cross(z2,z3)*cross(z3,z1)>0 : return True else : return False lst=[] try : while True : P=tuple(map(float,input().strip().split())) lst.append(P) except EOFError : pass N=len(lst) for i in range(N): if is_in_triangle(*lst[i]): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var lst : Sequence := Sequence{} ; try ( while true do ( var P : Sequence := ((input()->trim().split())->collect( _x | (OclType["double"])->apply(_x) )) ; execute ((P) : lst))) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt pass))))) ; var N : int := (lst)->size() ; for i : Integer.subrange(0, N-1) do ( if is_in_triangle((argument * (test (logical_test (comparison (expr (atom (name lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); operation cross(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a.conjugate() * b).imag; operation is_in_triangle(X1 : OclAny, Y1 : OclAny, X2 : OclAny, Y2 : OclAny, X3 : OclAny, Y3 : OclAny, Xp : OclAny, Yp : OclAny) : OclAny pre: true post: true activity: var z1 : OclAny := complex(X1 - Xp, Y1 - Yp) ; var z2 : OclAny := complex(X2 - Xp, Y2 - Yp) ; var z3 : OclAny := complex(X3 - Xp, Y3 - Yp) ; if cross(z1, z2) * cross(z2, z3) > 0 then ( if cross(z2, z3) * cross(z3, z1) > 0 then ( return true ) else skip ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def side(p1,p2,p3): return(p3[1]-p1[1])*(p2[0]-p1[0])-(p2[1]-p1[1])*(p3[0]-p1[0])>0 for s in sys.stdin : x=map(float,s.split()) p1=x[0 : 2] p2=x[2 : 4] p3=x[4 : 6] p0=x[6 :] print["NO","YES"][(side(p1,p2,p0)==side(p2,p3,p0)==side(p3,p1,p0))] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for s : OclFile["System.in"] do ( var x : Sequence := (s.split())->collect( _x | (OclType["double"])->apply(_x) ) ; p1 := x.subrange(0+1, 2) ; p2 := x.subrange(2+1, 4) ; p3 := x.subrange(4+1, 6) ; var p0 : OclAny := x.subrange(6+1) ; (expr (atom print) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom "NO")))))) , (subscript (test (logical_test (comparison (expr (atom "YES"))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (comparison (expr (atom (name side)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p1))))))) , (argument (test (logical_test (comparison (expr (atom (name p2))))))) , (argument (test (logical_test (comparison (expr (atom (name p0)))))))) ))))) == (comparison (expr (atom (name side)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p2))))))) , (argument (test (logical_test (comparison (expr (atom (name p3))))))) , (argument (test (logical_test (comparison (expr (atom (name p0)))))))) )))))) == (comparison (expr (atom (name side)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p3))))))) , (argument (test (logical_test (comparison (expr (atom (name p1))))))) , (argument (test (logical_test (comparison (expr (atom (name p0)))))))) ))))))))) )))))))) ])))); operation side(p1 : OclAny, p2 : OclAny, p3 : OclAny) : OclAny pre: true post: true activity: return (p3[1+1] - p1[1+1]) * (p2->first() - p1->first()) - (p2[1+1] - p1[1+1]) * (p3->first() - p1->first()) > 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) x=[] for i in range(n+m): x.append(input()) if n>m : print('YES') elif ncollect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := Sequence{} ; for i : Integer.subrange(0, n + m-1) do ( execute (((OclFile["System.in"]).readLine()) : x)) ; if (n->compareTo(m)) > 0 then ( execute ('YES')->display() ) else (if (n->compareTo(m)) < 0 then ( execute ('NO')->display() ) else (if n = m then ( if (Set{}->union((x)))->size() mod 2 /= 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def resolve(nArray,mArray): if n>m : print('YES') elif m>n : print('NO') else : nArray=set(nArray) mArray=set(mArray) mArray=set(mArray.intersection(nArray)) if len(mArray)% 2==0 : print("NO") else : print("YES") n,m=[int(a)for a in input().split()] nArray=[] mArray=[] for i in range(n): nArray.append(input()) for i in range(m): mArray.append(input()) resolve(nArray,mArray) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; nArray := Sequence{} ; mArray := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : nArray)) ; for i : Integer.subrange(0, m-1) do ( execute (((OclFile["System.in"]).readLine()) : mArray)) ; resolve(nArray, mArray); operation resolve(nArray : OclAny, mArray : OclAny) pre: true post: true activity: if (n->compareTo(m)) > 0 then ( execute ('YES')->display() ) else (if (m->compareTo(n)) > 0 then ( execute ('NO')->display() ) else ( nArray := Set{}->union((nArray)) ; mArray := Set{}->union((mArray)) ; mArray := Set{}->union((mArray->intersection(nArray))) ; if (mArray)->size() mod 2 = 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(num)for num in input().split()] palavras={} num_repetidas=0 for _ in range(n+m): palavra=input() if palavra in palavras : num_repetidas+=1 palavras[palavra]=True answer='' if n>m : answer='YES' elif nselect(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var palavras : OclAny := Set{} ; var num_repetidas : int := 0 ; for _anon : Integer.subrange(0, n + m-1) do ( var palavra : String := (OclFile["System.in"]).readLine() ; if (palavras)->includes(palavra) then ( num_repetidas := num_repetidas + 1 ) else skip ; palavras->at(palavra) := true) ; var answer : String := '' ; if (n->compareTo(m)) > 0 then ( answer := 'YES' ) else (if (n->compareTo(m)) < 0 then ( answer := 'NO' ) else ( answer := if num_repetidas mod 2 = 0 then 'NO' else 'YES' endif ) ) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() print(len(set(map(frozenset,input().split())))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; execute ((Set{}->union(((input().split())->collect( _x | (frozenset)->apply(_x) ))))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) p=set() for i in range(n): p.add(input()) e=set() for i in range(m): e.add(input()) t=p & e ; p=p-t ; e=e-t print("YNEOS"[len(p)+len(t)% 2<=len(e): : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : p)) ; var e : Set := Set{}->union(()) ; for i : Integer.subrange(0, m-1) do ( execute (((OclFile["System.in"]).readLine()) : e)) ; var t : int := MathLib.bitwiseAnd(p, e); p := p - t; e := e - t ; execute ("YNEOS"(subscript (test (logical_test (comparison (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p)))))))) )))) + (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) )))) % (expr (atom (number (integer 2))))))) <= (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name e)))))))) )))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) b=min(a) c=max(a) print(a.index(b)+1,a.index(c)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : OclAny := (a)->min() ; var c : OclAny := (a)->max() ; execute (a->indexOf(b) - 1 + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) x=[] for i in range(n+m): x.append(input()) if n>m : print('YES') elif ncollect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := Sequence{} ; for i : Integer.subrange(0, n + m-1) do ( execute (((OclFile["System.in"]).readLine()) : x)) ; if (n->compareTo(m)) > 0 then ( execute ('YES')->display() ) else (if (n->compareTo(m)) < 0 then ( execute ('NO')->display() ) else (if n = m then ( if (Set{}->union((x)))->size() mod 2 /= 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100005 def addPrimes(): n=MAX prime=[True for i in range(n+1)] for p in range(2,n+1): if p*p>n : break if(prime[p]==True): for i in range(2*p,n+1,p): prime[i]=False ans=[] for p in range(2,n+1): if(prime[p]): ans.append(p) return ans def is_prime(n): if n in[3,5,7]: return True return False def find_Sum(n): Sum=0 v=addPrimes() for i in range(len(v)): flag=1 a=v[i] while(a!=0): d=a % 10 ; a=a//10 ; if(is_prime(d)): flag=0 break if(flag==1): n-=1 Sum=Sum+v[i] if n==0 : break return Sum n=7 print(find_Sum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 100005 ; skip ; skip ; skip ; n := 7 ; execute (find_Sum(n))->display(); operation addPrimes() : OclAny pre: true post: true activity: var n : int := MAX ; var prime : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (true)) ; for p : Integer.subrange(2, n + 1-1) do ( if (p * p->compareTo(n)) > 0 then ( break ) else skip ; if (prime[p+1] = true) then ( for i : Integer.subrange(2 * p, n + 1-1)->select( $x | ($x - 2 * p) mod p = 0 ) do ( prime[i+1] := false) ) else skip) ; var ans : Sequence := Sequence{} ; for p : Integer.subrange(2, n + 1-1) do ( if (prime[p+1]) then ( execute ((p) : ans) ) else skip) ; return ans; operation is_prime(n : OclAny) : OclAny pre: true post: true activity: if (Sequence{3}->union(Sequence{5}->union(Sequence{ 7 })))->includes(n) then ( return true ) else skip ; return false; operation find_Sum(n : OclAny) : OclAny pre: true post: true activity: var Sum : int := 0 ; var v : OclAny := addPrimes() ; for i : Integer.subrange(0, (v)->size()-1) do ( var flag : int := 1 ; var a : OclAny := v[i+1] ; while (a /= 0) do ( var d : int := a mod 10; ; a := a div 10; ; if (is_prime(d)) then ( flag := 0 ; break ) else skip) ; if (flag = 1) then ( n := n - 1 ; Sum := Sum + v[i+1] ) else skip ; if n = 0 then ( break ) else skip) ; return Sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[0]*4 b=[0]*2 for i in range(4): a[i]=int(input()) a.sort() del a[0] for i in range(2): b[i]=int(input()) b.sort() del b[0] print(sum(a)+sum(b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 4) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 2) ; for i : Integer.subrange(0, 4-1) do ( a[i+1] := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; a := a->sort() ; execute (a->first())->isDeleted() ; for i : Integer.subrange(0, 2-1) do ( b[i+1] := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; b := b->sort() ; execute (b->first())->isDeleted() ; execute ((a)->sum() + (b)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tensu=[None]*4 ten=[None]*2 for i in range(4): tensu[i]=input() tensu=list(map(int,tensu)) for i in range(2): ten[i]=input() ten=list(map(int,ten)) if ten[0]tensu[i]: k=0 k=tensu[i] tensu[i]=tensu[3] tensu[3]=k i+=1 s=0 i=0 for i in range(3): s+=tensu[i] i+=1 c=s+ten[0] print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var tensu : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, 4) ; var ten : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, 2) ; for i : Integer.subrange(0, 4-1) do ( tensu[i+1] := (OclFile["System.in"]).readLine()) ; tensu := ((tensu)->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, 2-1) do ( ten[i+1] := (OclFile["System.in"]).readLine()) ; ten := ((ten)->collect( _x | (OclType["int"])->apply(_x) )) ; if (ten->first()->compareTo(ten[1+1])) < 0 then ( var b : int := 0 ; b := ten->first() ; ten->first() := ten[1+1] ; ten[1+1] := b ) else skip ; for i : Integer.subrange(0, 4-1) do ( if (tensu[3+1]->compareTo(tensu[i+1])) > 0 then ( var k : int := 0 ; k := tensu[i+1] ; tensu[i+1] := tensu[3+1] ; tensu[3+1] := k ) else skip ; i := i + 1) ; var s : int := 0 ; var i : int := 0 ; for i : Integer.subrange(0, 3-1) do ( s := s + tensu[i+1] ; i := i + 1) ; var c : int := s + ten->first() ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A=int(input()) B=int(input()) C=int(input()) D=int(input()) E=int(input()) F=int(input()) sum1=0 sum2=0 if A<=B and A<=C and A<=D : sum1=B+C+D elif B<=A and B<=C and B<=D : sum1=A+C+D elif C<=A and C<=B and C<=D : sum1=A+B+D else : sum1=A+B+C if E<=F : sum2=F else : sum2=E print(sum1+sum2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var C : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var D : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var E : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var F : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sum1 : int := 0 ; var sum2 : int := 0 ; if (A->compareTo(B)) <= 0 & (A->compareTo(C)) <= 0 & (A->compareTo(D)) <= 0 then ( sum1 := B + C + D ) else (if (B->compareTo(A)) <= 0 & (B->compareTo(C)) <= 0 & (B->compareTo(D)) <= 0 then ( sum1 := A + C + D ) else (if (C->compareTo(A)) <= 0 & (C->compareTo(B)) <= 0 & (C->compareTo(D)) <= 0 then ( sum1 := A + B + D ) else ( sum1 := A + B + C ) ) ) ; if (E->compareTo(F)) <= 0 then ( sum2 := F ) else ( sum2 := E ) ; execute (sum1 + sum2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=0 x=[0,0,0,0,0,0] k=0 while i<6 : x[i]=int(input()) i=1+i while k<3 : if x[k]union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))))) ; var k : int := 0 ; while i < 6 do ( x[i+1] := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; i := 1 + i) ; while k < 3 do ( if (x[k+1]->compareTo(x[k + 1+1])) < 0 then ( var ex : OclAny := x[k+1] ; x[k+1] := x[k + 1+1] ; x[k + 1+1] := ex ) else skip ; k := k + 1) ; if (("" + ((x[4+1])))->toInteger()->compareTo(("" + ((x[5+1])))->toInteger())) < 0 then ( var ave : OclAny := x->first() + x[1+1] + x[2+1] + x[5+1] ) else ( ave := x->first() + x[1+1] + x[2+1] + x[4+1] ) ; execute (ave)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lstr=[int(input())for i in range(4)] lsts=[int(input())for j in range(2)] mr=max(lstr) mr2=sorted(lstr)[-2] mr3=sorted(lstr)[-3] ms=max(lsts) print(mr+mr2+mr3+ms) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lstr : Sequence := Integer.subrange(0, 4-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var lsts : Sequence := Integer.subrange(0, 2-1)->select(j | true)->collect(j | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var mr : OclAny := (lstr)->max() ; var mr2 : OclAny := sorted(lstr)->front()->last() ; var mr3 : OclAny := sorted(lstr)->reverse()->at(-(-3)) ; var ms : OclAny := (lsts)->max() ; execute (mr + mr2 + mr3 + ms)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def result(n : int,a : list)->int : valid_min=15 if a[0]>valid_min : return valid_min for i in range(n): if a[i]<=valid_min : valid_min=15+a[i] return 90 if valid_min>=90 else valid_min if __name__=="__main__" : n=int(input()) a=list(map(int,input().split())) print(result(n,a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (result(n, a))->display() ) else skip; operation result(n : int, a : Sequence(OclAny)) : int pre: true post: true activity: var valid_min : int := 15 ; if (a->first()->compareTo(valid_min)) > 0 then ( return valid_min ) else skip ; for i : Integer.subrange(0, n-1) do ( if (a[i+1]->compareTo(valid_min)) <= 0 then ( valid_min := 15 + a[i+1] ) else skip) ; return if valid_min >= 90 then 90 else valid_min endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=0 for i in input().split(): if(int(i)>m+15): break m=int(i) print(min(90,m+15)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := 0 ; for i : input().split() do ( if ((("" + ((i)))->toInteger()->compareTo(m + 15)) > 0) then ( break ) else skip ; m := ("" + ((i)))->toInteger()) ; execute (Set{90, m + 15}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input().split() print(len(set(frozenset(si)for si in s))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := input().split() ; execute ((Set{}->union(((argument (test (logical_test (comparison (expr (atom (name frozenset)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name si)))))))) ))))))) (comp_for for (exprlist (expr (atom (name si)))) in (logical_test (comparison (expr (atom (name s))))))))))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) arr=[int(i)for i in input().split()] min_index=0 max_index=0 for i in range(n): if arr[i]arr[max_index]: max_index=i print(min_index+1,max_index+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var min_index : int := 0 ; var max_index : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1]->compareTo(arr[min_index+1])) < 0 then ( min_index := i ) else skip ; if (arr[i+1]->compareTo(arr[max_index+1])) > 0 then ( max_index := i ) else skip) ; execute (min_index + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) if arr[0]>15 : print(15) else : for i in range(1,len(arr)): if arr[i]-arr[i-1]>15 : print(arr[i-1]+15) break else : if arr[-1]==90 or arr[-1]+15>=90 : print(90) else : print(arr[-1]+15) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if arr->first() > 15 then ( execute (15)->display() ) else ( (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr)))))))) ))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))))) > (comparison (expr (atom (number (integer 15)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))) + (expr (atom (number (integer 15)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))) == (comparison (expr (atom (number (integer 90))))))) or (logical_test (comparison (comparison (expr (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))) + (expr (atom (number (integer 15)))))) >= (comparison (expr (atom (number (integer 90))))))))) : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 90))))))))) )))))))))))) (else_clause else : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))) + (expr (atom (number (integer 15)))))))))) )))))))))))))))))) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import* from decimal import* def _input(): return map(int,input().split()) def _list(): return list(map(int,input().split())) def solves(): n=int(input()) lst=_list() if(lst[0]>15): print(15) else : if(n==1): if lst[0]+15>=90 : print(90) else : print(lst[0]+15) exit() for i in range(1,n): if(lst[i]-lst[i-1]>15): print(lst[i-1]+15) exit() if lst[i]+15>=90 : print(90) else : print(lst[i]+15) exit() t=1 for _ in range(0,t): solves() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solves()); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation _list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation solves() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : OclAny := _list() ; if (lst->first() > 15) then ( execute (15)->display() ) else ( if (n = 1) then ( if lst->first() + 15 >= 90 then ( execute (90)->display() ) else ( execute (lst->first() + 15)->display() ) ; exit() ) else skip ; for i : Integer.subrange(1, n-1) do ( if (lst[i+1] - lst[i - 1+1] > 15) then ( execute (lst[i - 1+1] + 15)->display() ; exit() ) else skip) ; if lst[i+1] + 15 >= 90 then ( execute (90)->display() ) else ( execute (lst[i+1] + 15)->display() ) ; exit() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) w=list(map(int,input().split()))+[234] e=15 while w[0]<=e : e=w[0]+15 del w[0] print(90 if e>=90 else e) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->union(Sequence{ 234 }) ; var e : int := 15 ; while (w->first()->compareTo(e)) <= 0 do ( e := w->first() + 15 ; execute (w->first())->isDeleted()) ; execute (if e >= 90 then 90 else e endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def memo(index,evenSum,oddSum,tight): if index==len(v): if evenSum>oddSum : return 1 else : return 0 if dp[index][evenSum][oddSum][tight]!=-1 : return dp[index][evenSum][oddSum][tight] limit=v[index]if tight else 9 ans=0 for d in range(limit+1): currTight=0 if d==v[index]: currTight=tight if d % 2!=0 : ans+=memo(index+1,evenSum,oddSum+d,currTight) else : ans+=memo(index+1,evenSum+d,oddSum,currTight) dp[index][evenSum][oddSum][tight]=ans return ans def countNum(n): global dp,v v.clear() num=[] while n : v.append(n % 10) n//=10 v.reverse() dp=[[[[-1,-1]for i in range(180)]for j in range(180)]for k in range(18)] return memo(0,0,0,1) if __name__=="__main__" : dp=[] v=[] L=2 R=10 print(countNum(R)-countNum(L-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute dp : OclAny; attribute v : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( dp := Sequence{} ; v := Sequence{} ; var L : int := 2 ; var R : int := 10 ; execute (countNum(R) - countNum(L - 1))->display() ) else skip; operation memo(index : OclAny, evenSum : OclAny, oddSum : OclAny, tight : OclAny) : OclAny pre: true post: true activity: if index = (v)->size() then ( if (evenSum->compareTo(oddSum)) > 0 then ( return 1 ) else ( return 0 ) ) else skip ; if dp[index+1][evenSum+1][oddSum+1][tight+1] /= -1 then ( return dp[index+1][evenSum+1][oddSum+1][tight+1] ) else skip ; var limit : OclAny := if tight then v[index+1] else 9 endif ; var ans : int := 0 ; for d : Integer.subrange(0, limit + 1-1) do ( var currTight : int := 0 ; if d = v[index+1] then ( currTight := tight ) else skip ; if d mod 2 /= 0 then ( ans := ans + memo(index + 1, evenSum, oddSum + d, currTight) ) else ( ans := ans + memo(index + 1, evenSum + d, oddSum, currTight) )) ; dp[index+1][evenSum+1][oddSum+1][tight+1] := ans ; return ans; operation countNum(n : OclAny) : OclAny pre: true post: true activity: skip; skip ; execute (v /<: v) ; var num : Sequence := Sequence{} ; while n do ( execute ((n mod 10) : v) ; n := n div 10) ; v := v->reverse() ; dp := Integer.subrange(0, 18-1)->select(k | true)->collect(k | (Integer.subrange(0, 180-1)->select(j | true)->collect(j | (Integer.subrange(0, 180-1)->select(i | true)->collect(i | (Sequence{-1}->union(Sequence{ -1 }))))))) ; return memo(0, 0, 0, 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lst=[] for _ in range(3): lst+=[list(map(int,input().split()))] total=0 for i in range(3): for j in range(3): total+=lst[i][j] total=total//3 flag=True for i in range(3): a=lst[0][i % 3]+lst[1][(i+1)% 3]+lst[2][(i+2)% 3] if a!=total : flag=False a=lst[0][0]+lst[1][2]+lst[2][1] if a!=total : flag=False a=lst[1][1]+lst[0][2]+lst[2][0] if a!=total : flag=False a=lst[2][2]+lst[1][0]+lst[0][1] if a!=total : flag=False if flag : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lst : Sequence := Sequence{} ; for _anon : Integer.subrange(0, 3-1) do ( lst := lst + Sequence{ ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) }) ; var total : int := 0 ; for i : Integer.subrange(0, 3-1) do ( for j : Integer.subrange(0, 3-1) do ( total := total + lst[i+1][j+1])) ; total := total div 3 ; var flag : boolean := true ; for i : Integer.subrange(0, 3-1) do ( var a : OclAny := lst->first()[i mod 3+1] + lst[1+1][(i + 1) mod 3+1] + lst[2+1][(i + 2) mod 3+1] ; if a /= total then ( flag := false ) else skip) ; a := lst->first()->first() + lst[1+1][2+1] + lst[2+1][1+1] ; if a /= total then ( flag := false ) else skip ; a := lst[1+1][1+1] + lst->first()[2+1] + lst[2+1]->first() ; if a /= total then ( flag := false ) else skip ; a := lst[2+1][2+1] + lst[1+1]->first() + lst->first()[1+1] ; if a /= total then ( flag := false ) else skip ; if flag then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys try : from typing import List except ImportError : pass YES="Yes" NO="No" def solve(c : "List[List[int]]"): print(YES if all(c[i][j]==c[0][j]+c[i][0]-c[0][0]for i in range(1,3)for j in range(1,3))else NO) def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() c=[[int(next(tokens))for _ in range(3)]for _ in range(3)] solve(c) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; try ( skip) (except_clause except (test (logical_test (comparison (expr (atom (name ImportError)))))) : (suite (stmt (simple_stmt (small_stmt pass))))) ; var YES : String := "Yes" ; var NO : String := "No" ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(c : "List[List[int]]") pre: true post: true activity: execute (if ((argument (test (logical_test (comparison (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) == (comparison (expr (expr (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))) + (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) - (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 3))))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 3))))))))) )))))))))))->forAll( _x | _x = true ) then YES else NO endif)->display(); operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var c : Sequence := Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (("" + (((tokens).next())))->toInteger())))) ; solve(c); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) d,e,f=map(int,input().split()) g,h,i=map(int,input().split()) if b-a==e-d==h-g and c-b==f-e==i-h and d-a==e-b==f-c and g-d==h-e==i-f : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : OclAny := null; var e : OclAny := null; var f : OclAny := null; Sequence{d,e,f} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var g : OclAny := null; var h : OclAny := null; var i : OclAny := null; Sequence{g,h,i} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if b - a = e - d & (e - d == h - g) & c - b = f - e & (f - e == i - h) & d - a = e - b & (e - b == f - c) & g - d = h - e & (h - e == i - f) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[int(i)for i in input().split()] b=[int(i)for i in input().split()] c=[int(i)for i in input().split()] a1=0 b1=a[0]-a1 b2=a[1]-a1 b3=a[2]-a1 a2=b[0]-b1 a3=c[0]-b1 if b[1]==a2+b2 and b[2]==a2+b3 and c[1]==a3+b2 and c[2]==a3+b3 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var b : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var c : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a1 : int := 0 ; var b1 : double := a->first() - a1 ; var b2 : double := a[1+1] - a1 ; var b3 : double := a[2+1] - a1 ; var a2 : double := b->first() - b1 ; var a3 : double := c->first() - b1 ; if b[1+1] = a2 + b2 & b[2+1] = a2 + b3 & c[1+1] = a3 + b2 & c[2+1] = a3 + b3 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=[] for i in range(3): c1=list(map(int,input().split())) c.append(c1) count=0 ans="Yes" for i in range(2): for j in range(2): if c[i][j]-c[i][j+1]!=c[i+1][j]-c[i+1][j+1]: ans="No" if c[i][j]-c[i+1][j]!=c[i][j+1]-c[i+1][j+1]: ans="No" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : Sequence := Sequence{} ; for i : Integer.subrange(0, 3-1) do ( var c1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((c1) : c)) ; var count : int := 0 ; var ans : String := "Yes" ; for i : Integer.subrange(0, 2-1) do ( for j : Integer.subrange(0, 2-1) do ( if c[i+1][j+1] - c[i+1][j + 1+1] /= c[i + 1+1][j+1] - c[i + 1+1][j + 1+1] then ( ans := "No" ) else skip ; if c[i+1][j+1] - c[i + 1+1][j+1] /= c[i+1][j + 1+1] - c[i + 1+1][j + 1+1] then ( ans := "No" ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): for t in range(int(input())): n=int(input()) diff=[int(x)for x in input().split()] arr=[] arr.append(diff[0]) flag=False for i in range(1,len(diff)): x=arr[i-1]+diff[i] y=arr[i-1]-diff[i] if y>=0 and x!=y : flag=True break else : arr.append(x) if flag : print(-1) else : for i in arr : print(i,end=" ") print() if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var diff : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var arr : Sequence := Sequence{} ; execute ((diff->first()) : arr) ; var flag : boolean := false ; for i : Integer.subrange(1, (diff)->size()-1) do ( var x : OclAny := arr[i - 1+1] + diff[i+1] ; var y : double := arr[i - 1+1] - diff[i+1] ; if y >= 0 & x /= y then ( flag := true ; break ) else ( execute ((x) : arr) )) ; if flag then ( execute (-1)->display() ) else ( for i : arr do ( execute (i)->display()) ; execute (->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for t in range(T): n=int(input()) s=input() s=s.split() mn=1e9+5 mx=-1 mxi=mni=0 for i in range(n): if(int(s[i])>mx): mx=int(s[i]) mxi=i+1 if(int(s[i])toInteger() ; for t : Integer.subrange(0, T-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; s := s.split() ; var mn : double := ("1e9")->toReal() + 5 ; var mx : int := -1 ; var mxi : OclAny := 0; var mni : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ((("" + ((s[i+1])))->toInteger()->compareTo(mx)) > 0) then ( mx := ("" + ((s[i+1])))->toInteger() ; mxi := i + 1 ) else skip ; if ((("" + ((s[i+1])))->toInteger()->compareTo(mn)) < 0) then ( mn := ("" + ((s[i+1])))->toInteger() ; mni := i + 1 ) else skip) ; execute (mni)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() l=input().split() a=set() for i in l : a.add(str(set(sorted(list(i))))) print(len(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var l : OclAny := input().split() ; var a : Set := Set{}->union(()) ; for i : l do ( execute ((("" + ((Set{}->union(((i)->sort())))))) : a)) ; execute ((a)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) h=[] for i in range(N): n=int(input()) a=list(map(int,input().split())) s=len(a) l=[] l=[a[0]] if n>1 : d=a[0] for i in range(1,s): if i=a[i]and a[i]!=0 : h.append([-1]) break else : l.append(d+a[i]) d=l[i] else : if d>=a[i]and a[i]!=0 : h.append([-1]) break else : l.append(d+a[i]) d=l[i] h.append(l) else : h.append(l) for t in h : for y in t : print(y,end=' ') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var h : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : int := (a)->size() ; var l : Sequence := Sequence{} ; l := Sequence{ a->first() } ; if n > 1 then ( var d : OclAny := a->first() ; for i : Integer.subrange(1, s-1) do ( if (i->compareTo(s - 1)) < 0 then ( if (d->compareTo(a[i+1])) >= 0 & a[i+1] /= 0 then ( execute ((Sequence{ -1 }) : h) ; break ) else ( execute ((d + a[i+1]) : l) ; d := l[i+1] ) ) else ( if (d->compareTo(a[i+1])) >= 0 & a[i+1] /= 0 then ( execute ((Sequence{ -1 }) : h) ; break ) else ( execute ((d + a[i+1]) : l) ; d := l[i+1] ; execute ((l) : h) ) )) ) else ( execute ((l) : h) )) ; for t : h do ( for y : t do ( execute (y)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) b=[a[0]] flag=True for i in range(1,n): if a[i]<=b[i-1]and a[i]!=0 : flag=False break else : b.append(b[i-1]+a[i]) if flag==False : print(-1) else : print(*b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := Sequence{ a->first() } ; var flag : boolean := true ; for i : Integer.subrange(1, n-1) do ( if (a[i+1]->compareTo(b[i - 1+1])) <= 0 & a[i+1] /= 0 then ( flag := false ; break ) else ( execute ((b[i - 1+1] + a[i+1]) : b) )) ; if flag = false then ( execute (-1)->display() ) else ( execute ((argument * (test (logical_test (comparison (expr (atom (name b))))))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) d=list(map(int,input().split())) f=1 a=[d[0]] for i in range(n-1): if d[i+1]>0 and d[i+1]<=a[-1]: f=0 ; break a.append(a[-1]+d[i+1]) if not f : print(-1) else : print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var f : int := 1 ; var a : Sequence := Sequence{ d->first() } ; for i : Integer.subrange(0, n - 1-1) do ( if d[i + 1+1] > 0 & (d[i + 1+1]->compareTo(a->last())) <= 0 then ( f := 0; break ) else skip ; execute ((a->last() + d[i + 1+1]) : a)) ; if not(f) then ( execute (-1)->display() ) else ( execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) d=list(map(int,input().split())) a=[d[0]] b=True for i in range(1,n): if d[i]and a[i-1]-d[i]>=0 : b=False break a.append(a[i-1]+d[i]) if b : for i in range(n): print(a[i],end=" ") print() else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := Sequence{ d->first() } ; var b : boolean := true ; for i : Integer.subrange(1, n-1) do ( if d[i+1] & a[i - 1+1] - d[i+1] >= 0 then ( b := false ; break ) else skip ; execute ((a[i - 1+1] + d[i+1]) : a)) ; if b then ( for i : Integer.subrange(0, n-1) do ( execute (a[i+1])->display()) ; execute (->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): return "0" if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: return "0"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def search(arr,n,x): for i in range(0,n): if(arr[i]==x): return i ; return-1 ; arr=[2,3,4,10,40]; x=10 ; n=len(arr); result=search(arr,n,x) if(result==-1): print("Element is not present in array") else : print("Element is present at index",result); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{10}->union(Sequence{ 40 })))); ; x := 10; ; n := (arr)->size(); ; var result : OclAny := search(arr, n, x) ; if (result = -1) then ( execute ("Element is not present in array")->display() ) else ( execute ("Element is present at index")->display(); ); operation search(arr : OclAny, n : OclAny, x : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if (arr[i+1] = x) then ( return i; ) else skip) ; return -1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : h,w=map(int,input().strip().split()) if h==w==0 : break for y in range(h): print(''.join('#.'[(x+y)% 2]for x in range(w))) print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if h = w & (w == 0) then ( break ) else skip ; for y : Integer.subrange(0, h-1) do ( execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom '#.') (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (name y)))))))) ))) % (expr (atom (number (integer 2)))))))))) ])))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name w)))))))) ))))))))), ''))->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- __author__='hayato.osanai' import sys for idx,line in enumerate(sys.stdin): if idx!=0 : print('') h,w=line.split() h=int(h) w=int(w) if h==0 and w==0 : break for i in range(h): line='' for j in range(w): if i % 2==0 : if j % 2==0 : line+='#' else : line+='.' else : if j % 2==0 : line+='.' else : line+='#' print(line) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var __author__ : String := 'hayato.osanai' ; skip ; for _tuple : Integer.subrange(1, (OclFile["System.in"])->size())->collect( _indx | Sequence{_indx-1, (OclFile["System.in"])->at(_indx)} ) do (var _indx : int := 1; var idx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var line : OclAny := _tuple->at(_indx); if idx /= 0 then ( execute ('')->display() ) else skip ; var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := line.split() ; var h : int := ("" + ((h)))->toInteger() ; var w : int := ("" + ((w)))->toInteger() ; if h = 0 & w = 0 then ( break ) else skip ; for i : Integer.subrange(0, h-1) do ( var line : String := '' ; for j : Integer.subrange(0, w-1) do ( if i mod 2 = 0 then ( if j mod 2 = 0 then ( line := line + '#' ) else ( line := line + '.' ) ) else ( if j mod 2 = 0 then ( line := line + '.' ) else ( line := line + '#' ) )) ; execute (line)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys L=[] M=[] while True : (a,b)=map(int,raw_input().split()) if a==0 and b==0 : break else : L.append(a) M.append(b) for x in range(len(L)): for y in range(L[x]): if y % 2 : for z in range(M[x]): if z % 2 : sys.stdout.write("#") else : sys.stdout.write(".") print else : for z in range(M[x]): if z % 2 : sys.stdout.write(".") else : sys.stdout.write("#") print print ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var L : Sequence := Sequence{} ; var M : Sequence := Sequence{} ; while true do ( ; var Sequence{a, b} : Sequence := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 0 & b = 0 then ( break ) else ( execute ((a) : L) ; execute ((b) : M) )) ; for x : Integer.subrange(0, (L)->size()-1) do ( for y : Integer.subrange(0, L[x+1]-1) do ( if y mod 2 then ( for z : Integer.subrange(0, M[x+1]-1) do ( if z mod 2 then ( (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "#"))))))) )))) ) else ( (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "."))))))) )))) )) ; ) else ( for z : Integer.subrange(0, M[x+1]-1) do ( if z mod 2 then ( (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "."))))))) )))) ) else ( (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "#"))))))) )))) )) ; )) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- M=list(map(int,input().split(' '))) a=M[0] b=M[1] n=M[2] if a!=0 : if b % a!=0 : print('No solution') else : b=b//a x,y=0,-2000 if b>=0 : while yb : print('No solution') else : print(x-1) else : if n % 2==0 : print('No solution') else : x=-1 y=2000 while y>b : y=pow(x,n) x=x-1 if ycollect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := M->first() ; var b : OclAny := M[1+1] ; var n : OclAny := M[2+1] ; if a /= 0 then ( if b mod a /= 0 then ( execute ('No solution')->display() ) else ( b := b div a ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{0,-2000} ; if b >= 0 then ( while (y->compareTo(b)) < 0 do ( var y : double := (x)->pow(n) ; var x : OclAny := x + 1) ; if (y->compareTo(b)) > 0 then ( execute ('No solution')->display() ) else ( execute (x - 1)->display() ) ) else ( if n mod 2 = 0 then ( execute ('No solution')->display() ) else ( x := -1 ; y := 2000 ; while (y->compareTo(b)) > 0 do ( y := (x)->pow(n) ; x := x - 1) ; if (y->compareTo(b)) < 0 then ( execute ('No solution')->display() ) else ( execute (x + 1)->display() ) ) ) ) ) else ( if b = 0 then ( execute (5)->display() ) else ( execute ('No solution')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) 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 l=factorization(x) l=sorted(l) ans=0 for i in range(len(l)): if l[i][0]==1 : continue else : s=0 num=l[i][1] if num==1 : j=1 else : for j in range(1,num): s+=j if s==num : break elif s>num : j-=1 break ans+=j print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; var l : OclAny := factorization(x) ; l := l->sort() ; var ans : int := 0 ; for i : Integer.subrange(0, (l)->size()-1) do ( if l[i+1]->first() = 1 then ( continue ) else ( var s : int := 0 ; var num : OclAny := l[i+1][1+1] ; if num = 1 then ( var j : int := 1 ) else ( for j : Integer.subrange(1, num-1) do ( s := s + j ; if s = num then ( break ) else (if (s->compareTo(num)) > 0 then ( j := j - 1 ; break ) else skip)) ) ; ans := ans + j )) ; execute (ans)->display(); operation factorization(n : OclAny) : OclAny pre: true post: true activity: var arr : Sequence := Sequence{} ; var temp : OclAny := n ; for i : Integer.subrange(2, ("" + ((-(-(n)->pow(0.5) div 1))))->toInteger() + 1-1) do ( if temp mod i = 0 then ( var cnt : int := 0 ; while temp mod i = 0 do ( cnt := cnt + 1 ; temp := temp div i) ; execute ((Sequence{i}->union(Sequence{ cnt })) : arr) ) else skip) ; if temp /= 1 then ( execute ((Sequence{temp}->union(Sequence{ 1 })) : arr) ) else skip ; if arr = Sequence{} then ( execute ((Sequence{n}->union(Sequence{ 1 })) : arr) ) else skip ; return arr; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function while 1 : h,w=map(int,raw_input().split()) turn=1 if h==w==0 : break for i in range(h): for j in range(w): print('#' if turn ^(j % 2)else '.',sep='',end='') print() turn ^=1 print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while 1 do ( var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var turn : int := 1 ; if h = w & (w == 0) then ( break ) else skip ; for i : Integer.subrange(0, h-1) do ( for j : Integer.subrange(0, w-1) do ( execute (if MathLib.bitwiseXor(turn, (j mod 2)) then '#' else '.' endif)->display()) ; execute (->display() ; turn := turn xor 1) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() def f(s): return "".join(sorted(set(s))) arr=set(map(f,input().split())) print(len(arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; skip ; var arr : Set := Set{}->union(((input().split())->collect( _x | (f)->apply(_x) ))) ; execute ((arr)->size())->display(); operation f(s : OclAny) : OclAny pre: true post: true activity: return StringLib.sumStringsWithSeparator((Set{}->union((s))->sort()), ""); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : line=input().strip() if line=="0 0" : break else : line=line.split("") y=int(line[0]) x=int(line[1]) for i in range(y): for j in range(x): if i % 2==0 : if j % 2==0 : print("#",end="") else : print(".",end="") else : if j % 2==0 : print(".",end="") else : print("#",end="") print() print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var line : OclAny := input()->trim() ; if line = "0 0" then ( break ) else ( line := line.split("") ; var y : int := ("" + ((line->first())))->toInteger() ; var x : int := ("" + ((line[1+1])))->toInteger() ; for i : Integer.subrange(0, y-1) do ( for j : Integer.subrange(0, x-1) do ( if i mod 2 = 0 then ( if j mod 2 = 0 then ( execute ("#")->display() ) else ( execute (".")->display() ) ) else ( if j mod 2 = 0 then ( execute (".")->display() ) else ( execute ("#")->display() ) )) ; execute (->display()) ; execute (->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,C=map(int,input().split()) XV=[list(map(int,input().split()))for i in range(N)] RIGHTSUM=[0] for x,v in XV : RIGHTSUM.append(RIGHTSUM[-1]+v) LEFTSUM=[0] for x,v in XV[: :-1]: LEFTSUM.append(LEFTSUM[-1]+v) RIGHT=[] for i in range(N): RIGHT.append(RIGHTSUM[i+1]-XV[i][0]) LEFT=[] for i in range(N): LEFT.append(LEFTSUM[i+1]-(C-XV[-i-1][0])) RIGHTMAX=[RIGHT[0]] for i in range(1,N): RIGHTMAX.append(max(RIGHTMAX[i-1],RIGHT[i])) LEFTMAX=[LEFT[0]] for i in range(1,N): LEFTMAX.append(max(LEFTMAX[i-1],LEFT[i])) ANS=max(max(RIGHT),max(LEFT),0) for i in range(N-1): if ANS<(RIGHTSUM[i+1]-XV[i][0]*2)+LEFTMAX[N-i-2]: ANS=RIGHTSUM[i+1]-XV[i][0]*2+LEFTMAX[N-i-2] if ANScollect( _x | (OclType["int"])->apply(_x) ) ; var XV : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var RIGHTSUM : Sequence := Sequence{ 0 } ; for _tuple : XV do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); execute ((RIGHTSUM->last() + v) : RIGHTSUM)) ; var LEFTSUM : Sequence := Sequence{ 0 } ; for _tuple : XV(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); execute ((LEFTSUM->last() + v) : LEFTSUM)) ; var RIGHT : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute ((RIGHTSUM[i + 1+1] - XV[i+1]->first()) : RIGHT)) ; var LEFT : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute ((LEFTSUM[i + 1+1] - (C - XV->reverse()->at(-(-i - 1))->first())) : LEFT)) ; var RIGHTMAX : Sequence := Sequence{ RIGHT->first() } ; for i : Integer.subrange(1, N-1) do ( execute ((Set{RIGHTMAX[i - 1+1], RIGHT[i+1]}->max()) : RIGHTMAX)) ; var LEFTMAX : Sequence := Sequence{ LEFT->first() } ; for i : Integer.subrange(1, N-1) do ( execute ((Set{LEFTMAX[i - 1+1], LEFT[i+1]}->max()) : LEFTMAX)) ; var ANS : OclAny := Set{(RIGHT)->max(), (LEFT)->max(), 0}->max() ; for i : Integer.subrange(0, N - 1-1) do ( if (ANS->compareTo((RIGHTSUM[i + 1+1] - XV[i+1]->first() * 2) + LEFTMAX[N - i - 2+1])) < 0 then ( ANS := RIGHTSUM[i + 1+1] - XV[i+1]->first() * 2 + LEFTMAX[N - i - 2+1] ) else skip ; if (ANS->compareTo(LEFTSUM[i + 1+1] - (C - XV->reverse()->at(-(-i - 1))->first()) * 2 + RIGHTMAX[N - i - 2+1])) < 0 then ( ANS := LEFTSUM[i + 1+1] - (C - XV->reverse()->at(-(-i - 1))->first()) * 2 + RIGHTMAX[N - i - 2+1] ) else skip) ; execute (ANS)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,c=map(int,input().split()) xs=[] vs=[] for _i in range(n): x,v=map(int,input().split()) xs.append(x) vs.append(v) r1,r2,l1,l2=[[],[],[],[]] r_sum,l_sum=[0,0] for i in range(n): r_sum+=vs[i] r1.append(r_sum-xs[i]) r2.append(r_sum-2*xs[i]) i_rev=n-i-1 l_sum+=vs[i_rev] l1.append(l_sum-(c-xs[i_rev])) l2.append(l_sum-2*(c-xs[i_rev])) r1_max,r2_max=[0,0] l1_max,l2_max=[0,0] r1_maxs,r2_maxs=[[0],[0]] l1_maxs,l2_maxs=[[0],[0]] for i in range(n): r1_max=max(r1_max,r1[i]) r1_maxs.append(r1_max) r2_max=max(r2_max,r2[i]) r2_maxs.append(r2_max) l1_max=max(l1_max,l1[i]) l1_maxs.append(l1_max) l2_max=max(l2_max,l2[i]) l2_maxs.append(l2_max) r1_l2_max=0 l1_r2_max=0 for i in range(0,n+1): r1_l2_max=max(r1_l2_max,r1_maxs[i]+l2_maxs[n-i]) l1_r2_max=max(l1_r2_max,l1_maxs[i]+r2_maxs[n-i]) total_max=max(r1_l2_max,l1_r2_max) print("{}".format(total_max)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var xs : Sequence := Sequence{} ; var vs : Sequence := Sequence{} ; for _i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var v : OclAny := null; Sequence{x,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((x) : xs) ; execute ((v) : vs)) ; var r1 : OclAny := null; var r2 : OclAny := null; var l1 : OclAny := null; var l2 : OclAny := null; Sequence{r1,r2,l1,l2} := Sequence{Sequence{}}->union(Sequence{Sequence{}}->union(Sequence{Sequence{}}->union(Sequence{ Sequence{} }))) ; var r_sum : OclAny := null; var l_sum : OclAny := null; Sequence{r_sum,l_sum} := Sequence{0}->union(Sequence{ 0 }) ; for i : Integer.subrange(0, n-1) do ( r_sum := r_sum + vs[i+1] ; execute ((r_sum - xs[i+1]) : r1) ; execute ((r_sum - 2 * xs[i+1]) : r2) ; var i_rev : double := n - i - 1 ; l_sum := l_sum + vs[i_rev+1] ; execute ((l_sum - (c - xs[i_rev+1])) : l1) ; execute ((l_sum - 2 * (c - xs[i_rev+1])) : l2)) ; var r1_max : OclAny := null; var r2_max : OclAny := null; Sequence{r1_max,r2_max} := Sequence{0}->union(Sequence{ 0 }) ; var l1_max : OclAny := null; var l2_max : OclAny := null; Sequence{l1_max,l2_max} := Sequence{0}->union(Sequence{ 0 }) ; var r1_maxs : OclAny := null; var r2_maxs : OclAny := null; Sequence{r1_maxs,r2_maxs} := Sequence{Sequence{ 0 }}->union(Sequence{ Sequence{ 0 } }) ; var l1_maxs : OclAny := null; var l2_maxs : OclAny := null; Sequence{l1_maxs,l2_maxs} := Sequence{Sequence{ 0 }}->union(Sequence{ Sequence{ 0 } }) ; for i : Integer.subrange(0, n-1) do ( var r1_max : OclAny := Set{r1_max, r1[i+1]}->max() ; execute ((r1_max) : r1_maxs) ; var r2_max : OclAny := Set{r2_max, r2[i+1]}->max() ; execute ((r2_max) : r2_maxs) ; var l1_max : OclAny := Set{l1_max, l1[i+1]}->max() ; execute ((l1_max) : l1_maxs) ; var l2_max : OclAny := Set{l2_max, l2[i+1]}->max() ; execute ((l2_max) : l2_maxs)) ; var r1_l2_max : int := 0 ; var l1_r2_max : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( r1_l2_max := Set{r1_l2_max, r1_maxs[i+1] + l2_maxs[n - i+1]}->max() ; l1_r2_max := Set{l1_r2_max, l1_maxs[i+1] + r2_maxs[n - i+1]}->max()) ; var total_max : OclAny := Set{r1_l2_max, l1_r2_max}->max() ; execute (StringLib.interpolateStrings("{}", Sequence{total_max}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate,chain n,c=map(int,input().split()) xs,vs=zip(*(map(int,input().split())for _ in range(n))) ds=[j-i for i,j in zip(chain([0],xs),chain(xs,[c]))] clockwise=chain([0],(v-d for v,d in zip(accumulate(vs),accumulate(ds)))) anticlockwise2=[0]+[v-d*2 for v,d in zip(accumulate(vs[: :-1]),accumulate(ds[: :-1]))] anticlock_clock=(x+y for x,y in zip(accumulate(clockwise,func=max),reversed(anticlockwise2))) anticlockwise=chain([0],(v-d for v,d in zip(accumulate(vs[: :-1]),accumulate(ds[: :-1])))) clockwise2=[0]+[v-d*2 for v,d in zip(accumulate(vs),accumulate(ds))] clock_anticlock=(x+y for x,y in zip(accumulate(anticlockwise,func=max),reversed(clockwise2))) print(max(chain(anticlock_clock,clock_anticlock))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var xs : OclAny := null; var vs : OclAny := null; Sequence{xs,vs} := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))`third->at(_indx)} ) ; var ds : Sequence := Integer.subrange(1, chain(Sequence{ 0 }, xs)->size())->collect( _indx | Sequence{chain(Sequence{ 0 }, xs)->at(_indx), chain(xs, Sequence{ c })->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let j : OclAny = _tuple->at(2) in (j - i)) ; var clockwise : OclAny := chain(Sequence{ 0 }, Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (name d))))))) (comp_for for (exprlist (expr (atom (name v))) , (expr (atom (name d)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name accumulate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name vs)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name accumulate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ds)))))))) ))))))))) ))))))))}) ; var anticlockwise2 : Sequence := Sequence{ 0 }->union(Integer.subrange(1, accumulate(vs(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->size())->collect( _indx | Sequence{accumulate(vs(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->at(_indx), accumulate(ds(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->at(_indx)} )->select(_tuple | true)->collect(_tuple | let v : OclAny = _tuple->at(1) in let d : OclAny = _tuple->at(2) in (v - d * 2))) ; var anticlock_clock : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (name y))))))) (comp_for for (exprlist (expr (atom (name x))) , (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name accumulate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name clockwise))))))) , (argument (test (logical_test (comparison (expr (atom (name func)))))) = (test (logical_test (comparison (expr (atom (name max)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name reversed)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name anticlockwise2)))))))) ))))))))) ))))))))} ; var anticlockwise : OclAny := chain(Sequence{ 0 }, Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (name d))))))) (comp_for for (exprlist (expr (atom (name v))) , (expr (atom (name d)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name accumulate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name vs)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ])))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name accumulate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ds)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ])))))))) ))))))))) ))))))))}) ; var clockwise2 : Sequence := Sequence{ 0 }->union(Integer.subrange(1, accumulate(vs)->size())->collect( _indx | Sequence{accumulate(vs)->at(_indx), accumulate(ds)->at(_indx)} )->select(_tuple | true)->collect(_tuple | let v : OclAny = _tuple->at(1) in let d : OclAny = _tuple->at(2) in (v - d * 2))) ; var clock_anticlock : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (name y))))))) (comp_for for (exprlist (expr (atom (name x))) , (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name accumulate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name anticlockwise))))))) , (argument (test (logical_test (comparison (expr (atom (name func)))))) = (test (logical_test (comparison (expr (atom (name max)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name reversed)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name clockwise2)))))))) ))))))))) ))))))))} ; execute ((chain(anticlock_clock, clock_anticlock))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10000000) def input(): return sys.stdin.readline()[:-1] from bisect import* from collections import* from heapq import* from math import* from itertools import* from copy import* N,C=map(int,input().split()) f1=[list(map(int,input().split()))for i in range(N)] f2=deepcopy(f1)[: :-1] for i in range(N-1): f1[i+1][1]+=f1[i][1] f2[i+1][1]+=f2[i][1] f1=[[0,0,0]]+[(v-x,x,i)for i,(x,v)in enumerate(f1,1)] f2=[[0,0,0]]+[(v-C+x,C-x,i)for i,(x,v)in enumerate(f2,1)] g1=[0]*(N+1) g2=[0]*(N+1) for i in range(1,N+1): g1[i]=max(f1[i][0],g1[i-1]) g2[i]=max(f2[i][0],g2[i-1]) ans=0 for i in range(N+1): ans=max(ans,f1[i][0]+g2[N-i]-f1[i][1],f2[i][0]+g1[N-i]-f2[i][1]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(10000000) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var N : OclAny := null; var C : OclAny := null; Sequence{N,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var f1 : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var f2 : OclAny := deepcopy(f1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; for i : Integer.subrange(0, N - 1-1) do ( f1[i + 1+1][1+1] := f1[i + 1+1][1+1] + f1[i+1][1+1] ; f2[i + 1+1][1+1] := f2[i + 1+1][1+1] + f2[i+1][1+1]) ; f1 := Sequence{ Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) }->union(Integer.subrange(1, (f1, 1)->size())->collect( _indx | Sequence{_indx-1, (f1, 1)->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let Sequence{x, v} : OclAny = _tuple->at(2) in (Sequence{v - x, x, i}))) ; f2 := Sequence{ Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) }->union(Integer.subrange(1, (f2, 1)->size())->collect( _indx | Sequence{_indx-1, (f2, 1)->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let Sequence{x, v} : OclAny = _tuple->at(2) in (Sequence{v - C + x, C - x, i}))) ; var g1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; var g2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; for i : Integer.subrange(1, N + 1-1) do ( g1[i+1] := Set{f1[i+1]->first(), g1[i - 1+1]}->max() ; g2[i+1] := Set{f2[i+1]->first(), g2[i - 1+1]}->max()) ; var ans : int := 0 ; for i : Integer.subrange(0, N + 1-1) do ( ans := Set{ans, f1[i+1]->first() + g2[N - i+1] - f1[i+1][1+1], f2[i+1]->first() + g1[N - i+1] - f2[i+1][1+1]}->max()) ; execute (ans)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(xv_sorted): x=[False for _ in range(n)] y=[False for _ in range(n)] s=0 buf=(-1)*float('inf') for i in range(n): s+=xv_sorted[i][1] x[i]=max(buf,s-2*xv_sorted[i][0]) buf=x[i] s=0 buf=(-1)*float('inf') for i in sorted(range(n),reverse=True): s+=xv_sorted[i][1] y[i]=max(buf,s-(c-xv_sorted[i][0])) buf=y[i] ans=max(x[n-1],y[0]) for i in range(n-1): ans=max(ans,x[i]+y[i+1]) return ans if __name__=='__main__' : n,c=map(int,input().split()) xv=[] for i in range(n): xv.append(list(map(int,input().split()))) xv_sorted=sorted(xv,key=lambda x : x[0]) ans=0 ans=max(ans,solve(xv_sorted)) for i in range(n): xv_sorted[i][0]=abs(c-xv_sorted[i][0]) xv_sorted=sorted(xv,key=lambda x : x[0]) ans=max(ans,solve(xv_sorted)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var xv : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : xv)) ; xv_sorted := xv->sortedBy($x | (lambda x : OclAny in (x->first()))->apply($x)) ; ans := 0 ; ans := Set{ans, solve(xv_sorted)}->max() ; for i : Integer.subrange(0, n-1) do ( xv_sorted[i+1]->first() := (c - xv_sorted[i+1]->first())->abs()) ; xv_sorted := xv->sortedBy($x | (lambda x : OclAny in (x->first()))->apply($x)) ; ans := Set{ans, solve(xv_sorted)}->max() ; execute (ans)->display() ) else skip; operation solve(xv_sorted : OclAny) : OclAny pre: true post: true activity: var x : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (false)) ; var y : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (false)) ; var s : int := 0 ; var buf : double := (-1) * ("" + (('inf')))->toReal() ; for i : Integer.subrange(0, n-1) do ( s := s + xv_sorted[i+1][1+1] ; x[i+1] := Set{buf, s - 2 * xv_sorted[i+1]->first()}->max() ; buf := x[i+1]) ; s := 0 ; buf := (-1) * ("" + (('inf')))->toReal() ; for i : Integer.subrange(0, n-1)->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) do ( s := s + xv_sorted[i+1][1+1] ; y[i+1] := Set{buf, s - (c - xv_sorted[i+1]->first())}->max() ; buf := y[i+1]) ; var ans : OclAny := Set{x[n - 1+1], y->first()}->max() ; for i : Integer.subrange(0, n - 1-1) do ( ans := Set{ans, x[i+1] + y[i + 1+1]}->max()) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) p=0 for i in l : p ^=i ans=[] for i in l : ans.append(p ^ i) print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var p : int := 0 ; for i : l do ( p := p xor i) ; var ans : Sequence := Sequence{} ; for i : l do ( execute ((MathLib.bitwiseXor(p, i)) : ans)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import* from operator import* N=int(input()) a=list(map(int,input().split())) total=reduce(xor,a,0) print(" ".join(list(map(lambda ai : str(ai ^ total),a)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var total : OclAny := reduce(xor, a, 0) ; execute (StringLib.sumStringsWithSeparator((((a)->collect( _x | (lambda ai : OclAny in (("" + ((MathLib.bitwiseXor(ai, total))))))->apply(_x) ))), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin import collections N=int(stdin.readline().rstrip()) def prime_decomposition(n): i=2 table=[] while i*i<=n : while n % i==0 : n/=i table.append(i) i+=1 if n>1 : table.append(n) return table prime=prime_decomposition(N) c=collections.Counter(prime) p=c.values() cnt=0 for i in p : t=1 while True : i=i-t if i<=t : cnt+=t break t+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := ("" + ((stdin.readLine().rstrip())))->toInteger() ; skip ; var prime : OclAny := prime_decomposition(N) ; var c : OclAny := .Counter(prime) ; var p : OclAny := c.values() ; var cnt : int := 0 ; for i : p do ( var t : int := 1 ; while true do ( i := i - t ; if (i->compareTo(t)) <= 0 then ( cnt := cnt + t ; break ) else skip ; t := t + 1)) ; execute (cnt)->display(); operation prime_decomposition(n : OclAny) : OclAny pre: true post: true activity: var i : int := 2 ; var table : Sequence := Sequence{} ; while (i * i->compareTo(n)) <= 0 do ( while n mod i = 0 do ( n := n / i ; execute ((i) : table)) ; i := i + 1) ; if n > 1 then ( execute ((n) : table) ) else skip ; return table; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def main(): n=int(input()) A=list(map(int,input().split())) d=defaultdict(int) for a in A : B=list(f'{a:030b}') for i,b in enumerate(B): if b=='1' : d[i]+=1 ANS=[] for a in A : B=list(f'{a:030b}') ans=0 for i,b in enumerate(B): if b=='1' : k=d[i]-1 else : k=d[i] if k % 2==1 : ans+=pow(2,29-i) ANS.append(str(ans)) print(' '.join(ANS)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := defaultdict(OclType["int"]) ; for a : A do ( var B : Sequence := (StringLib.formattedString('{a:030b}'))->characters() ; for _tuple : Integer.subrange(1, (B)->size())->collect( _indx | Sequence{_indx-1, (B)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if b = '1' then ( d[i+1] := d[i+1] + 1 ) else skip)) ; var ANS : Sequence := Sequence{} ; for a : A do ( B := (StringLib.formattedString('{a:030b}'))->characters() ; var ans : int := 0 ; for _tuple : Integer.subrange(1, (B)->size())->collect( _indx | Sequence{_indx-1, (B)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if b = '1' then ( var k : double := d[i+1] - 1 ) else ( k := d[i+1] ) ; if k mod 2 = 1 then ( ans := ans + (2)->pow(29 - i) ) else skip) ; execute ((("" + ((ans)))) : ANS)) ; execute (StringLib.sumStringsWithSeparator((ANS), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import defaultdict,deque from heapq import heappush,heappop import math import bisect input=sys.stdin.readline n=int(input()) a=list(map(int,input().split())) res=0 for a_ in a : res=a_ ^ res for a_ in a : print(a_ ^ res,end=' ') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : int := 0 ; for a_ : a do ( res := MathLib.bitwiseXor(a_, res)) ; for a_ : a do ( execute (MathLib.bitwiseXor(a_, res))->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for _ in range(T): n=int(input()) a=list(map(int,input().split())) marker=[-1]*150001 ans=150001 for i in range(n): if marker[a[i]]==-1 : marker[a[i]]=i else : ans=min(ans,i-marker[a[i]]) marker[a[i]]=i if ans==150001 : print(-1) else : print(n-ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, T-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var marker : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, 150001) ; var ans : int := 150001 ; for i : Integer.subrange(0, n-1) do ( if marker[a[i+1]+1] = -1 then ( marker[a[i+1]+1] := i ) else ( ans := Set{ans, i - marker[a[i+1]+1]}->min() ; marker[a[i+1]+1] := i )) ; if ans = 150001 then ( execute (-1)->display() ) else ( execute (n - ans)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys EPS=1e-9 def cross(a,b): return a.real*b.imag-a.imag*b.real def dot(a,b): return a.real*b.real+a.imag*b.imag def check_ccw(p0,p1,p2): a,b=p1-p0,p2-p0 if cross(a,b)>EPS : flag=1 elif cross(a,b)<-1*EPS : flag=-1 elif dot(a,b)<-1*EPS : flag=2 elif abs(a)toReal() ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var _input : OclAny := (OclFile["System.in"]).readlines() ; var l_num : int := ("" + ((_input->first())))->toInteger() ; var lines : Sequence := (_input->tail())->collect( _x | (lambda x : OclAny in (x.split()))->apply(_x) ) ; solve(lines) ) else skip; operation cross(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a.real * b.imag - a.imag * b.real; operation dot(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a.real * b.real + a.imag * b.imag; operation check_ccw(p0 : OclAny, p1 : OclAny, p2 : OclAny) : OclAny pre: true post: true activity: Sequence{a,b} := Sequence{p1 - p0,p2 - p0} ; if (cross(a, b)->compareTo(EPS)) > 0 then ( var flag : int := 1 ) else (if (cross(a, b)->compareTo(-1 * EPS)) < 0 then ( flag := -1 ) else (if (dot(a, b)->compareTo(-1 * EPS)) < 0 then ( flag := 2 ) else (if ((a)->abs()->compareTo((b)->abs())) < 0 then ( flag := -2 ) else ( flag := 0 ) ) ) ) ; return flag; operation check_intersection(p0 : OclAny, p1 : OclAny, p2 : OclAny, p3 : OclAny) : OclAny pre: true post: true activity: var intersected : boolean := (check_ccw(p0, p1, p2) * check_ccw(p0, p1, p3) <= 0) & (check_ccw(p2, p3, p0) * check_ccw(p2, p3, p1) <= 0) ; return intersected; operation solve(_lines : OclAny) : OclAny pre: true post: true activity: for line : _lines do ( var line : Sequence := ((line)->collect( _x | (OclType["int"])->apply(_x) )) ; Sequence{p0,p1,p2,p3} := Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (expr (atom (name y))) * (expr (atom (number 1j)))))))) (comp_for for (exprlist (expr (atom (name x))) , (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name line)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name line)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) ])))))))) ))))))))} ; intersected := check_intersection(p0, p1, p2, p3) ; if intersected then ( execute ('1')->display() ) else ( execute ('0')->display() )) ; return null; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=4 ARR=[20,11,9,24] N=int(input()) ARR=list(map(int,input().split())) def calculate(n,arr): s=arr[0] for i in range(1,n): s=s ^ arr[i] result=[] for i in range(n): result.append(str(arr[i]^ s)) print(" ".join(result)) calculate(N,ARR) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 4 ; var ARR : Sequence := Sequence{20}->union(Sequence{11}->union(Sequence{9}->union(Sequence{ 24 }))) ; N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; ARR := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; calculate(N, ARR); operation calculate(n : OclAny, arr : OclAny) pre: true post: true activity: var s : OclAny := arr->first() ; for i : Integer.subrange(1, n-1) do ( s := MathLib.bitwiseXor(s, arr[i+1])) ; var result : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + ((MathLib.bitwiseXor(arr[i+1], s))))) : result)) ; execute (StringLib.sumStringsWithSeparator((result), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def toggleBitsFromLToR(n,l,r): num=(((1<display(); operation toggleBitsFromLToR(n : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var num : int := (MathLib.bitwiseXor(((1 * (2->pow(r))) - 1), ((1 * (2->pow((l - 1)))) - 1))) ; return (MathLib.bitwiseXor(n, num)); operation unsetBitsInGivenRange(n : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: num := (1 * (2->pow((4 * 8 - 1)))) - 1 ; num := toggleBitsFromLToR(num, l, r) ; return (MathLib.bitwiseAnd(n, num)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def MinStep(a,n): positive=0 ; negative=0 ; zero=0 ; step=0 ; for i in range(n): if(a[i]==0): zero+=1 ; elif(a[i]<0): negative+=1 ; step=step+(-1-a[i]); else : positive+=1 ; step=step+(a[i]-1); if(negative % 2==0): step=step+zero ; else : if(zero>0): step=step+zero ; else : step=step+2 ; return step ; if __name__=='__main__' : a=[0,-2,-1,-3,4]; n=len(a); print(MinStep(a,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := Sequence{0}->union(Sequence{-2}->union(Sequence{-1}->union(Sequence{-3}->union(Sequence{ 4 })))); ; n := (a)->size(); ; execute (MinStep(a, n))->display(); ) else skip; operation MinStep(a : OclAny, n : OclAny) pre: true post: true activity: var positive : int := 0; ; var negative : int := 0; ; var zero : int := 0; ; var step : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] = 0) then ( zero := zero + 1; ) else (if (a[i+1] < 0) then ( negative := negative + 1; ; step := step + (-1 - a[i+1]); ) else ( positive := positive + 1; ; step := step + (a[i+1] - 1); ) ) ) ; if (negative mod 2 = 0) then ( step := step + zero; ) else ( if (zero > 0) then ( step := step + zero; ) else ( step := step + 2; ) ) ; return step;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys from collections import deque,OrderedDict,defaultdict import heapq,re from collections import Counter def inp(): return sys.stdin.readline().rstrip() def mpp(): return map(int,inp().split()) def lis(): return list(mpp()) def yn(n): if n : return "YES" else : return "NO" def cd(s): return ord(s)-ord('a')+1 def fn(s,n,a,b): if s[a-1]==s[b-1]: return 0 else : return 1 def main(): n,a,b=mpp() s=inp() print(fn(s,n,a,b)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation inp() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation mpp() : OclAny pre: true post: true activity: return (inp().split())->collect( _x | (OclType["int"])->apply(_x) ); operation lis() : OclAny pre: true post: true activity: return (mpp()); operation yn(n : OclAny) : OclAny pre: true post: true activity: if n then ( return "YES" ) else ( return "NO" ); operation cd(s : OclAny) : OclAny pre: true post: true activity: return (s)->char2byte() - ('a')->char2byte() + 1; operation fn(s : OclAny, n : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if s[a - 1+1] = s[b - 1+1] then ( return 0 ) else ( return 1 ); operation main() pre: true post: true activity: Sequence{n,a,b} := mpp() ; s := inp() ; execute (fn(s, n, a, b))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=map(int,input().split()) bit_string=input() if bit_string[a-1]==bit_string[b-1]: print(0) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var bit_string : String := (OclFile["System.in"]).readLine() ; if bit_string[a - 1+1] = bit_string[b - 1+1] then ( execute (0)->display() ) else ( execute (1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=map(int,input().split()) ars=input() airports=int(ars,2) home_airport=ars[a-1] dest_airport=ars[b-1] if home_airport==dest_airport : print(0) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ars : String := (OclFile["System.in"]).readLine() ; var airports : int := ("" + ((ars, 2)))->toInteger() ; var home_airport : OclAny := ars[a - 1+1] ; var dest_airport : OclAny := ars[b - 1+1] ; if home_airport = dest_airport then ( execute (0)->display() ) else ( execute (1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from functools import reduce from collections import deque,Counter import sys sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline().strip() def get_nums_l(): return[int(s)for s in input().split(" ")] def get_nums_n(n): return[int(input())for _ in range(n)] def get_all_int(): return map(int,open(0).read().split()) def rangeI(it,l,r): for i,e in enumerate(it): if l<=i=r : break def log(*args): print("DEBUG:",*args,file=sys.stderr) INF=999999999999999999999999 MOD=10**9+7 n=int(input()) if n==1 : print(0) exit() 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 if len(arr)==0 : arr.append((n,1)) return arr fac_=prime_factorize(n) fac=Counter(fac_) ans=0 for p,e in fac.items(): x=e for i in range(1,99999999): if x>=i : x-=i ans+=1 else : break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; skip ; skip ; skip ; skip ; skip ; var INF : double := 999999999999999999999999 ; var MOD : double := (10)->pow(9) + 7 ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (0)->display() ; exit() ) else skip ; skip ; var fac_ : OclAny := prime_factorize(n) ; var fac : OclAny := Counter(fac_) ; var ans : int := 0 ; for _tuple : fac->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var p : OclAny := _tuple->at(_indx); _indx := _indx + 1; var e : OclAny := _tuple->at(_indx); var x : OclAny := e ; for i : Integer.subrange(1, 99999999-1) do ( if (x->compareTo(i)) >= 0 then ( x := x - i ; ans := ans + 1 ) else ( break ))) ; execute (ans)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation get_nums_l() : OclAny pre: true post: true activity: return input().split(" ")->select(s | true)->collect(s | (("" + ((s)))->toInteger())); operation get_nums_n(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())); operation get_all_int() : OclAny pre: true post: true activity: return (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ); operation rangeI(it : OclAny, l : OclAny, r : OclAny) pre: true post: true activity: for _tuple : Integer.subrange(1, (it)->size())->collect( _indx | Sequence{_indx-1, (it)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var e : OclAny := _tuple->at(_indx); if (l->compareTo(i)) <= 0 & (i < r) then ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return e ) else (if (l->compareTo(r)) >= 0 then ( break ) else skip)); operation log(args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) execute ("DEBUG:")->display(); operation prime_factorize(n : OclAny) : OclAny pre: true post: true activity: var a : Sequence := Sequence{} ; while n mod 2 = 0 do ( execute ((2) : a) ; n := n div 2) ; var f : int := 3 ; while (f * f->compareTo(n)) <= 0 do ( if n mod f = 0 then ( execute ((f) : a) ; n := n div f ) else ( f := f + 2 )) ; if n /= 1 then ( execute ((n) : a) ) else skip ; return a ; if (arr)->size() = 0 then ( execute ((Sequence{n, 1}) : arr) ) else skip ; return arr; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=map(int,input().split()) s=' '+input() print(1 if s[a]!=s[b]else 0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := ' ' + (OclFile["System.in"]).readLine() ; execute (if s[a+1] /= s[b+1] then 1 else 0 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,a,b=map(int,input().split()) s=input()[:-1] a,b=sorted([a,b]) x=s[a-1] y=s[b-1] if x==y : print(0) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := input()->front() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{a}->union(Sequence{ b })->sort() ; var x : OclAny := s[a - 1+1] ; var y : OclAny := s[b - 1+1] ; if x = y then ( execute (0)->display() ) else ( execute (1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) v=list(map(int,input().split()))[: n] v.sort() print(v[n-1]+v[n-2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var v : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ; v := v->sort() ; execute (v[n - 1+1] + v[n - 2+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=eval(input()) for _ in range(t): n=eval(input()) a=list(map(int,input().split())) a.sort() if n==1 : print(a[0]) else : print(a[-1]+a[-2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := (OclFile["System.in"]).readLine() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := (OclFile["System.in"]).readLine() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; if n = 1 then ( execute (a->first())->display() ) else ( execute (a->last() + a->front()->last())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import starmap def cross(a,b): return a.real*b.imag-a.imag*b.real q=int(input()) while q : q-=1 p0,p1,p2,p3=starmap(complex,zip(*[map(int,input().split())]*2)) max_x1,min_x1=(p0.real,p1.real)if p0.real>p1.real else(p1.real,p0.real) max_y1,min_y1=(p0.imag,p1.imag)if p0.imag>p1.imag else(p1.imag,p0.imag) max_x2,min_x2=(p2.real,p3.real)if p2.real>p3.real else(p3.real,p2.real) max_y2,min_y2=(p2.imag,p3.imag)if p2.imag>p3.imag else(p3.imag,p2.imag) if any((max_x1toInteger() ; while q do ( q := q - 1 ; var p0 : OclAny := null; var p1 : OclAny := null; var p2 : OclAny := null; var p3 : OclAny := null; Sequence{p0,p1,p2,p3} := starmap(complex, Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))`third->at(_indx)} )) ; var max_x1 : OclAny := null; var min_x1 : OclAny := null; Sequence{max_x1,min_x1} := if (p0.real->compareTo(p1.real)) > 0 then Sequence{p0.real, p1.real} else Sequence{p1.real, p0.real} endif ; var max_y1 : OclAny := null; var min_y1 : OclAny := null; Sequence{max_y1,min_y1} := if (p0.imag->compareTo(p1.imag)) > 0 then Sequence{p0.imag, p1.imag} else Sequence{p1.imag, p0.imag} endif ; var max_x2 : OclAny := null; var min_x2 : OclAny := null; Sequence{max_x2,min_x2} := if (p2.real->compareTo(p3.real)) > 0 then Sequence{p2.real, p3.real} else Sequence{p3.real, p2.real} endif ; var max_y2 : OclAny := null; var min_y2 : OclAny := null; Sequence{max_y2,min_y2} := if (p2.imag->compareTo(p3.imag)) > 0 then Sequence{p2.imag, p3.imag} else Sequence{p3.imag, p2.imag} endif ; if (Sequence{(max_x1->compareTo(min_x2)) < 0, (max_x2->compareTo(min_x1)) < 0, (max_y1->compareTo(min_y2)) < 0, (max_y2->compareTo(min_y1)) < 0})->exists( _x | _x = true ) then ( execute (0)->display() ; continue ) else skip ; execute (("" + ((cross(p1 - p0, p2 - p0) * cross(p1 - p0, p3 - p0) < ("1e-6")->toReal() & cross(p3 - p2, p0 - p2) * cross(p3 - p2, p1 - p2) < ("1e-6")->toReal())))->toInteger())->display()); operation cross(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a.real * b.imag - a.imag * b.real; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math T=int(input()) for t in range(T): n=int(input()) s=input() s=list(s.split()) for i in range(n): s[i]=int(s[i]) s.sort() s.reverse() print(s[0]+s[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(0, T-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; s := (s.split()) ; for i : Integer.subrange(0, n-1) do ( s[i+1] := ("" + ((s[i+1])))->toInteger()) ; s := s->sort() ; s := s->reverse() ; execute (s->first() + s[1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for jj in range(int(input())): n=input() arr=[int(i)for i in input().split()] arr.sort() print(arr[-1]+arr[-2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for jj : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : String := (OclFile["System.in"]).readLine() ; var arr : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; arr := arr->sort() ; execute (arr->last() + arr->front()->last())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) l.sort() print(l[-1]+l[-2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := l->sort() ; execute (l->last() + l->front()->last())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def noOfSquares(x1,y1,x2,y2): dx=abs(x2-x1); dy=abs(y2-y1); ans=dx+dy-gcd(dx,dy); print(ans); if __name__=="__main__" : x1=1 ; y1=1 ; x2=4 ; y2=3 ; noOfSquares(x1,y1,x2,y2); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( x1 := 1; y1 := 1; x2 := 4; y2 := 3; ; noOfSquares(x1, y1, x2, y2); ) else skip; operation noOfSquares(x1 : OclAny, y1 : OclAny, x2 : OclAny, y2 : OclAny) pre: true post: true activity: var dx : double := (x2 - x1)->abs(); ; var dy : double := (y2 - y1)->abs(); ; var ans : double := dx + dy - gcd(dx, dy); ; execute (ans)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_maximum(s,a): s=list(s) n=len(s) for i in range(n): if(ord(s[i])-ord('0')union(Sequence{1}->union(Sequence{2}->union(Sequence{5}->union(Sequence{4}->union(Sequence{6}->union(Sequence{6}->union(Sequence{3}->union(Sequence{1}->union(Sequence{ 9 }))))))))) ; execute (get_maximum(s, a))->display() ) else skip; operation get_maximum(s : OclAny, a : OclAny) : OclAny pre: true post: true activity: s := (s) ; var n : int := (s)->size() ; for i : Integer.subrange(0, n-1) do ( if (((s[i+1])->char2byte() - ('0')->char2byte()->compareTo(a[(s[i+1])->char2byte() - ('0')->char2byte()+1])) < 0) then ( var j : OclAny := i ; while ((j->compareTo(n)) < 0 & (((s[j+1])->char2byte() - ('0')->char2byte()->compareTo(a[(s[j+1])->char2byte() - ('0')->char2byte()+1])) <= 0)) do ( s[j+1] := (('0')->char2byte() + a[(s[j+1])->char2byte() - ('0')->char2byte()+1])->byte2char() ; j := j + 1) ; return StringLib.sumStringsWithSeparator((s), ""); ) else skip) ; return s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def convert_to_binary(n): listy=[] while n>0 : listy.append(n % 2) n//=2 for i in range(31-len(listy)): listy.append(0) return listy def main(): test_cases=range(int(input())) for test_case in test_cases : n=int(input()) a=[int(u)for u in input().split(" ")] real_counter=[0 for i in range(31)] for i in a : x=convert_to_binary(i) for i in range(len(real_counter)): real_counter[i]+=x[i] collector=[0 for i in range(n+1)] for i in real_counter : if i>0 : collector[i]+=1 real_collector=[] for i in range(len(collector)): if collector[i]>0 : real_collector.append(i) final_answer=[1] if sum(real_collector)==0 : print(" ".join([str(i)for i in range(1,n+1)])) else : min_collector=min(real_collector) real_collector=real_counter for i in range(2,n+1): if i>min_collector : break else : is_good=True for j in real_collector : if j % i!=0 : is_good=False break if is_good : final_answer.append(i) print(" ".join([str(k)for k in final_answer])) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation convert_to_binary(n : OclAny) : OclAny pre: true post: true activity: var listy : Sequence := Sequence{} ; while n > 0 do ( execute ((n mod 2) : listy) ; n := n div 2) ; for i : Integer.subrange(0, 31 - (listy)->size()-1) do ( execute ((0) : listy)) ; return listy; operation main() pre: true post: true activity: var test_cases : Sequence := Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) ; for test_case : test_cases do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split(" ")->select(u | true)->collect(u | (("" + ((u)))->toInteger())) ; var real_counter : Sequence := Integer.subrange(0, 31-1)->select(i | true)->collect(i | (0)) ; for i : a do ( var x : OclAny := convert_to_binary(i) ; for i : Integer.subrange(0, (real_counter)->size()-1) do ( real_counter[i+1] := real_counter[i+1] + x[i+1])) ; var collector : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; for i : real_counter do ( if i > 0 then ( collector[i+1] := collector[i+1] + 1 ) else skip) ; var real_collector : Sequence := Sequence{} ; for i : Integer.subrange(0, (collector)->size()-1) do ( if collector[i+1] > 0 then ( execute ((i) : real_collector) ) else skip) ; var final_answer : Sequence := Sequence{ 1 } ; if (real_collector)->sum() = 0 then ( execute (StringLib.sumStringsWithSeparator((Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | (("" + ((i)))))), " "))->display() ) else ( var min_collector : OclAny := (real_collector)->min() ; real_collector := real_counter ; for i : Integer.subrange(2, n + 1-1) do ( if (i->compareTo(min_collector)) > 0 then ( break ) else ( var is_good : boolean := true ; for j : real_collector do ( if j mod i /= 0 then ( is_good := false ; break ) else skip) ; if is_good then ( execute ((i) : final_answer) ) else skip )) ; execute (StringLib.sumStringsWithSeparator((final_answer->select(k | true)->collect(k | (("" + ((k)))))), " "))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_DIGITS=20 ; def isOctal(n): while(n): if((n % 10)>=8): return False else : n=int(n/10) return True def isPalindrome(n): divide=8 if(isOctal(n)==False)else 10 octal=[] while(n!=0): octal.append(n % divide) n=int(n/divide) j=len(octal)-1 k=0 while(k<=j): if(octal[j]!=octal[k]): return False j-=1 k+=1 return True if __name__=='__main__' : n=97 ; if(isPalindrome(n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_DIGITS : int := 20; ; skip ; skip ; if __name__ = '__main__' then ( n := 97; ; if (isPalindrome(n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isOctal(n : OclAny) : OclAny pre: true post: true activity: while (n) do ( if ((n mod 10) >= 8) then ( return false ) else ( n := ("" + ((n / 10)))->toInteger() )) ; return true; operation isPalindrome(n : OclAny) : OclAny pre: true post: true activity: var divide : int := if (isOctal(n) = false) then 8 else 10 endif ; var octal : Sequence := Sequence{} ; while (n /= 0) do ( execute ((n mod divide) : octal) ; n := ("" + ((n / divide)))->toInteger()) ; var j : double := (octal)->size() - 1 ; var k : int := 0 ; while ((k->compareTo(j)) <= 0) do ( if (octal[j+1] /= octal[k+1]) then ( return false ) else skip ; j := j - 1 ; k := k + 1) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) num=input() list_is=[] for i in num : list_is.append(int(i)) list_is1=list_is[: len(list_is)//2] list_is2=list_is[len(list_is)//2 :] sum1=sum(list_is1) sum2=sum(list_is2) condition=False for i in list_is : if i==4 or i==7 : condition=True continue else : condition=False break if condition==True : if sum1==sum2 : print("YES") else : print("NO") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; num := (OclFile["System.in"]).readLine() ; var list_is : Sequence := Sequence{} ; for i : num do ( execute ((("" + ((i)))->toInteger()) : list_is)) ; var list_is1 : OclAny := list_is.subrange(1,(list_is)->size() div 2) ; var list_is2 : OclAny := list_is.subrange((list_is)->size() div 2+1) ; var sum1 : OclAny := (list_is1)->sum() ; var sum2 : OclAny := (list_is2)->sum() ; var condition : boolean := false ; for i : list_is do ( if i = 4 or i = 7 then ( condition := true ; continue ) else ( condition := false ; break )) ; if condition = true then ( if sum1 = sum2 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) number=list(map(int,list(input()))) h1=0 h2=0 x=0 for i in range(n): if number[i]!=4 and number[i]!=7 : print("NO") x+=1 break if itoInteger() ; var number : Sequence := ((((OclFile["System.in"]).readLine())->characters())->collect( _x | (OclType["int"])->apply(_x) )) ; var h1 : int := 0 ; var h2 : int := 0 ; var x : int := 0 ; for i : Integer.subrange(0, n-1) do ( if number[i+1] /= 4 & number[i+1] /= 7 then ( execute ("NO")->display() ; x := x + 1 ; break ) else skip ; if (i->compareTo(n div 2)) < 0 then ( h1 := h1 + number[i+1] ) else ( h2 := h2 + number[i+1] )) ; if not(x) then ( if h1 = h2 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() a=list(map(int,str(input()))) t=1 for i in range(len(a)): if(a[i]==4): continue elif(a[i]==7): continue else : t=0 break if(sum(a[: int(len(a)/2)])==sum(a[int(len(a)/2): int(len(a))])and t==1): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var a : Sequence := ((("" + (((OclFile["System.in"]).readLine()))))->collect( _x | (OclType["int"])->apply(_x) )) ; var t : int := 1 ; for i : Integer.subrange(0, (a)->size()-1) do ( if (a[i+1] = 4) then ( continue ) else (if (a[i+1] = 7) then ( continue ) else ( t := 0 ; break ) ) ) ; if ((a.subrange(1,("" + (((a)->size() / 2)))->toInteger()))->sum() = (a.subrange(("" + (((a)->size() / 2)))->toInteger()+1, ("" + (((a)->size())))->toInteger()))->sum() & t = 1) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) num=int(input()) digits=[] for x in range(n): digit=num % 10 num=num//10 if(digit!=4)and(digit!=7): print("NO") quit() digits.append(digit) sum_half1=0 sum_half2=0 counter=0 while counter<=((n/2)-1): sum_half1+=digits[counter] counter+=1 while countertoInteger() ; var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var digits : Sequence := Sequence{} ; for x : Integer.subrange(0, n-1) do ( var digit : int := num mod 10 ; num := num div 10 ; if (digit /= 4) & (digit /= 7) then ( execute ("NO")->display() ; quit() ) else skip ; execute ((digit) : digits)) ; var sum_half1 : int := 0 ; var sum_half2 : int := 0 ; var counter : int := 0 ; while (counter->compareTo(((n / 2) - 1))) <= 0 do ( sum_half1 := sum_half1 + digits[counter+1] ; counter := counter + 1) ; while (counter->compareTo(n)) < 0 do ( sum_half2 := sum_half2 + digits[counter+1] ; counter := counter + 1) ; if sum_half1 = sum_half2 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dot(vx1,vy1,vx2,vy2): return vx1*vx2+vy1*vy2 def cross(vx1,vy1,vx2,vy2): return vx1*vy2-vy1*vx2 q=int(input()) for _ in range(q): x0,y0,x1,y1,x2,y2,x3,y3=map(int,input().split()) c1=cross(x1-x0,y1-y0,x2-x0,y2-y0) c2=cross(x1-x0,y1-y0,x3-x0,y3-y0) c3=cross(x3-x2,y3-y2,x0-x2,y0-y2) c4=cross(x3-x2,y3-y2,x1-x2,y1-y2) d1=dot(x1-x0,y1-y0,x2-x0,y2-y0) d2=dot(x1-x0,y1-y0,x3-x0,y3-y0) d3=dot(x0-x1,y0-y1,x2-x1,y2-y1) d4=dot(x0-x1,y0-y1,x3-x1,y3-y1) if c1*c2<=0 and c3*c4<=0 : if(d1<0 and d2<0)or(d3<0 and d4<0): print(0) else : print(1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( var x0 : OclAny := null; var y0 : OclAny := null; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; var x3 : OclAny := null; var y3 : OclAny := null; Sequence{x0,y0,x1,y1,x2,y2,x3,y3} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c1 : OclAny := cross(x1 - x0, y1 - y0, x2 - x0, y2 - y0) ; var c2 : OclAny := cross(x1 - x0, y1 - y0, x3 - x0, y3 - y0) ; var c3 : OclAny := cross(x3 - x2, y3 - y2, x0 - x2, y0 - y2) ; var c4 : OclAny := cross(x3 - x2, y3 - y2, x1 - x2, y1 - y2) ; var d1 : OclAny := dot(x1 - x0, y1 - y0, x2 - x0, y2 - y0) ; var d2 : OclAny := dot(x1 - x0, y1 - y0, x3 - x0, y3 - y0) ; var d3 : OclAny := dot(x0 - x1, y0 - y1, x2 - x1, y2 - y1) ; var d4 : OclAny := dot(x0 - x1, y0 - y1, x3 - x1, y3 - y1) ; if c1 * c2 <= 0 & c3 * c4 <= 0 then ( if (d1 < 0 & d2 < 0) or (d3 < 0 & d4 < 0) then ( execute (0)->display() ) else ( execute (1)->display() ) ) else ( execute (0)->display() )); operation dot(vx1 : OclAny, vy1 : OclAny, vx2 : OclAny, vy2 : OclAny) : OclAny pre: true post: true activity: return vx1 * vx2 + vy1 * vy2; operation cross(vx1 : OclAny, vy1 : OclAny, vx2 : OclAny, vy2 : OclAny) : OclAny pre: true post: true activity: return vx1 * vy2 - vy1 * vx2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,str(input()))) n=len(a) t=1 for i in range(n): if(a[i]==4): continue elif(a[i]==7): continue else : t=0 break if(t==0): print('NO') else : if(sum(a[: int(n/2)])==sum(a[int(n/2): n])): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((("" + (((OclFile["System.in"]).readLine()))))->collect( _x | (OclType["int"])->apply(_x) )) ; n := (a)->size() ; var t : int := 1 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] = 4) then ( continue ) else (if (a[i+1] = 7) then ( continue ) else ( t := 0 ; break ) ) ) ; if (t = 0) then ( execute ('NO')->display() ) else ( if ((a.subrange(1,("" + ((n / 2)))->toInteger()))->sum() = (a.subrange(("" + ((n / 2)))->toInteger()+1, n))->sum()) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binarySearch(arr,low,high): if(high=0): return left rightindex=max(mid+1,midValue) right=binarySearch(arr,rightindex,high) return right if __name__=='__main__' : arr=[-10,-5,2,2,2,3,4,7,9,12,13] n=len(arr) print("Fixed Point is",binarySearch(arr,0,n-1)) arr1=[-10,-1,3,3,10,30,30,50,100] n1=len(arr) print("Fixed Point is",binarySearch(arr1,0,n1-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{-10}->union(Sequence{-5}->union(Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{7}->union(Sequence{9}->union(Sequence{12}->union(Sequence{ 13 })))))))))) ; var n : int := (arr)->size() ; execute ("Fixed Point is")->display() ; var arr1 : Sequence := Sequence{-10}->union(Sequence{-1}->union(Sequence{3}->union(Sequence{3}->union(Sequence{10}->union(Sequence{30}->union(Sequence{30}->union(Sequence{50}->union(Sequence{ 100 })))))))) ; var n1 : int := (arr)->size() ; execute ("Fixed Point is")->display() ) else skip; operation binarySearch(arr : OclAny, low : OclAny, high : OclAny) : OclAny pre: true post: true activity: if ((high->compareTo(low)) < 0) then ( return -1 ) else skip ; var mid : int := ("" + (((low + high) / 2)))->toInteger() ; var midValue : OclAny := arr[mid+1] ; if (mid = arr[mid+1]) then ( return mid ) else skip ; var leftindex : OclAny := Set{mid - 1, midValue}->min() ; var left : OclAny := binarySearch(arr, low, leftindex) ; if (left >= 0) then ( return left ) else skip ; var rightindex : OclAny := Set{mid + 1, midValue}->max() ; var right : OclAny := binarySearch(arr, rightindex, high) ; return right; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=10000 ; prodDig=[0]*MAX ; def getDigitProduct(x): if(x<10): return x ; if(prodDig[x]!=0): return prodDig[x]; prod=(int(x % 10)*getDigitProduct(int(x/10))); prodDig[x]=prod ; return prod ; def findSeed(n): res=[]; for i in range(1,int(n/2+2)): if(i*getDigitProduct(i)==n): res.append(i); if(len(res)==0): print("NO seed exists"); return ; for i in range(len(res)): print(res[i],end=" "); n=138 ; findSeed(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 10000; ; var prodDig : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX); ; skip ; skip ; n := 138; ; findSeed(n);; operation getDigitProduct(x : OclAny) pre: true post: true activity: if (x < 10) then ( return x; ) else skip ; if (prodDig[x+1] /= 0) then ( return prodDig[x+1]; ) else skip ; var prod : double := (("" + ((x mod 10)))->toInteger() * getDigitProduct(("" + ((x / 10)))->toInteger())); ; prodDig[x+1] := prod; ; return prod;; operation findSeed(n : OclAny) : OclAny pre: true post: true activity: var res : Sequence := Sequence{}; ; for i : Integer.subrange(1, ("" + ((n / 2 + 2)))->toInteger()-1) do ( if (i * getDigitProduct(i) = n) then ( execute ((i) : res); ) else skip) ; if ((res)->size() = 0) then ( execute ("NO seed exists")->display(); ; return; ) else skip ; for i : Integer.subrange(0, (res)->size()-1) do ( execute (res[i+1])->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,input().split()) X=list(map(int,input().split())) answer=10**18 for i in range(N-K+1): left,right=i,i+K-1 al,ar=abs(X[left]),abs(X[right]) if X[left]*X[right]>=0 : answer=min(answer,max(al,ar)) else : answer=min(answer,al*2+ar,al+ar*2) print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var X : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var answer : double := (10)->pow(18) ; for i : Integer.subrange(0, N - K + 1-1) do ( var left : OclAny := null; var right : OclAny := null; Sequence{left,right} := Sequence{i,i + K - 1} ; var al : OclAny := null; var ar : OclAny := null; Sequence{al,ar} := Sequence{(X[left+1])->abs(),(X[right+1])->abs()} ; if X[left+1] * X[right+1] >= 0 then ( answer := Set{answer, Set{al, ar}->max()}->min() ) else ( answer := Set{answer, al * 2 + ar, al + ar * 2}->min() )) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) if n==1 : print(0) return def eratos(n): flag=[True]*(n+1) for i in range(2,int(n**0.5)+1): if flag[i]: for j in range(2*i,n+1,i): flag[j]=False return[i for i,x in enumerate(flag)if x and i>=2] p=eratos(10**6) work=[] for i in p : piyo=0 while n % i==0 : n//=i piyo+=1 if piyo>0 : work.append(piyo) if n==1 : break if len(work)==0 : print(1) return else : result=0 for i in work : for j in range(1,10**6): i-=j if i<0 : break result+=1 if n!=1 : result+=1 print(result) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (0)->display() ; return ) else skip ; skip ; var p : OclAny := eratos((10)->pow(6)) ; var work : Sequence := Sequence{} ; for i : p do ( var piyo : int := 0 ; while n mod i = 0 do ( n := n div i ; piyo := piyo + 1) ; if piyo > 0 then ( execute ((piyo) : work) ) else skip ; if n = 1 then ( break ) else skip) ; if (work)->size() = 0 then ( execute (1)->display() ; return ) else ( var result : int := 0 ; for i : work do ( for j : Integer.subrange(1, (10)->pow(6)-1) do ( i := i - j ; if i < 0 then ( break ) else skip ; result := result + 1)) ) ; if n /= 1 then ( result := result + 1 ) else skip ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=(int(v)for v in input().split()) x=[int(v)for v in input().split()] m=99999999999999999999 for l in range(n-k+1): r=l+k-1 m=min(m,abs(x[l])+abs(x[r]-x[l])) m=min(m,abs(x[r])+abs(x[l]-x[r])) print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) ))))))) (comp_for for (exprlist (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var x : Sequence := input().split()->select(v | true)->collect(v | (("" + ((v)))->toInteger())) ; var m : double := 99999999999999999999 ; for l : Integer.subrange(0, n - k + 1-1) do ( var r : double := l + k - 1 ; m := Set{m, (x[l+1])->abs() + (x[r+1] - x[l+1])->abs()}->min() ; m := Set{m, (x[r+1])->abs() + (x[l+1] - x[r+1])->abs()}->min()) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,input().split()) x=[i for i in map(int,input().split())] i=0 min_time=5e8 while i=0 : time1=-2*x[i]+x[i+K-1] time2=-x[i]+2*x[i+K-1] if time1=0 and x[i+K-1]>=0 : time=x[i+K-1] if timecollect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->select(i | true)->collect(i | (i)) ; var i : int := 0 ; var min_time : double := ("5e8")->toReal() ; while (i->compareTo(N - K + 1)) < 0 do ( if x[i+1] < 0 & x[i + K - 1+1] < 0 then ( var time : OclAny := -x[i+1] ) else skip ; if x[i+1] < 0 & x[i + K - 1+1] >= 0 then ( var time1 : double := -2 * x[i+1] + x[i + K - 1+1] ; var time2 : OclAny := -x[i+1] + 2 * x[i + K - 1+1] ; if (time1->compareTo(time2)) < 0 then ( time := time1 ) else ( time := time2 ) ) else skip ; if x[i+1] >= 0 & x[i + K - 1+1] >= 0 then ( time := x[i + K - 1+1] ) else skip ; if (time->compareTo(min_time)) < 0 then ( min_time := time ) else skip ; i := i + 1) ; execute (min_time)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=list(map(int,input().split())) zerofrag=0 zerobig=[] zerosmall=[] for i in a : if i==0 : zerofrag=1 elif i>0 : zerobig.append(i) else : zerosmall.append(abs(i)) if k==1 and zerofrag==1 : print(0) else : if zerofrag==1 : k=k-1 zerobig.sort() zerosmall.sort() kouho=[] if len(zerobig)>=k : kouho.append(zerobig[k-1]) if len(zerosmall)>=k : kouho.append(zerosmall[k-1]) for ii in range(len(zerosmall)): if k-(ii)>len(zerobig): continue else : try : kouho.append(zerosmall[ii]*2+zerobig[k-ii-2]) except : continue for jj in range(len(zerobig)): if k-(jj)>len(zerosmall): continue else : try : kouho.append(zerobig[jj]*2+zerosmall[k-jj-2]) except : continue if zerofrag==1 : k=k+1 if kouho==[]: print(min((max(zerosmall)*2+max(zerobig)),max(zerobig)*2+max(zerosmall))) else : print(min(kouho)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var zerofrag : int := 0 ; var zerobig : Sequence := Sequence{} ; var zerosmall : Sequence := Sequence{} ; for i : a do ( if i = 0 then ( zerofrag := 1 ) else (if i > 0 then ( execute ((i) : zerobig) ) else ( execute (((i)->abs()) : zerosmall) ) ) ) ; if k = 1 & zerofrag = 1 then ( execute (0)->display() ) else ( if zerofrag = 1 then ( var k : double := k - 1 ) else skip ; zerobig := zerobig->sort() ; zerosmall := zerosmall->sort() ; var kouho : Sequence := Sequence{} ; if ((zerobig)->size()->compareTo(k)) >= 0 then ( execute ((zerobig[k - 1+1]) : kouho) ) else skip ; if ((zerosmall)->size()->compareTo(k)) >= 0 then ( execute ((zerosmall[k - 1+1]) : kouho) ) else skip ; for ii : Integer.subrange(0, (zerosmall)->size()-1) do ( if (k - (ii)->compareTo((zerobig)->size())) > 0 then ( continue ) else ( try ( execute ((zerosmall[ii+1] * 2 + zerobig[k - ii - 2+1]) : kouho)) catch (_e : OclException) do ( continue) )) ; for jj : Integer.subrange(0, (zerobig)->size()-1) do ( if (k - (jj)->compareTo((zerosmall)->size())) > 0 then ( continue ) else ( try ( execute ((zerobig[jj+1] * 2 + zerosmall[k - jj - 2+1]) : kouho)) catch (_e : OclException) do ( continue) )) ; if zerofrag = 1 then ( k := k + 1 ) else skip ; if kouho = Sequence{} then ( execute (Set{((zerosmall)->max() * 2 + (zerobig)->max()), (zerobig)->max() * 2 + (zerosmall)->max()}->min())->display() ) else ( execute ((kouho)->min())->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys N,K=map(int,input().split()) lst=list(map(int,input().split())) lst_p=[] lst_m=[] for i in range(N): if lst[i]==0 : K-=1 if lst[i]>0 : lst_p+=[lst[i]] elif lst[i]<0 : lst_m+=[lst[i]] p=0 m=0 x,y=0,len(lst_m)-1 lastx=len(lst_p) lasty=len(lst_m) def check(k): ans=10**9 for j in range(0,k+1): if j>lastx or k-j>lasty : pass else : if j==0 : p=0 else : p=lst_p[j-1] if k-j==0 : m=0 else : m=lst_m[lasty-(k-j)] ans=min(ans,2*p+abs(m),p+2*abs(m)) return ans print(check(K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lst_p : Sequence := Sequence{} ; var lst_m : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( if lst[i+1] = 0 then ( K := K - 1 ) else skip ; if lst[i+1] > 0 then ( lst_p := lst_p + Sequence{ lst[i+1] } ) else (if lst[i+1] < 0 then ( lst_m := lst_m + Sequence{ lst[i+1] } ) else skip)) ; var p : int := 0 ; var m : int := 0 ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{0,(lst_m)->size() - 1} ; var lastx : int := (lst_p)->size() ; var lasty : int := (lst_m)->size() ; skip ; execute (check(K))->display(); operation check(k : OclAny) : OclAny pre: true post: true activity: var ans : double := (10)->pow(9) ; for j : Integer.subrange(0, k + 1-1) do ( if (j->compareTo(lastx)) > 0 or (k - j->compareTo(lasty)) > 0 then ( skip ) else ( if j = 0 then ( p := 0 ) else ( p := lst_p[j - 1+1] ) ; if k - j = 0 then ( m := 0 ) else ( m := lst_m[lasty - (k - j)+1] ) ; ans := Set{ans, 2 * p + (m)->abs(), p + 2 * (m)->abs()}->min() )) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def diff(n,mid): if(n>(mid*mid*mid)): return(n-(mid*mid*mid)) else : return((mid*mid*mid)-n) def cubicRoot(n): start=0 end=n e=0.0000001 while(True): mid=(start+end)/2 error=diff(n,mid) if(error<=e): return mid if((mid*mid*mid)>n): end=mid else : start=mid n=3 print("Cubic root of",n,"is",round(cubicRoot(n),6)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 3 ; execute ("Cubic root of")->display(); operation diff(n : OclAny, mid : OclAny) : OclAny pre: true post: true activity: if ((n->compareTo((mid * mid * mid))) > 0) then ( return (n - (mid * mid * mid)) ) else ( return ((mid * mid * mid) - n) ); operation cubicRoot(n : OclAny) : OclAny pre: true post: true activity: var start : int := 0 ; var end : OclAny := n ; var e : double := 0.0000001 ; while (true) do ( mid := (start + end) / 2 ; var error : OclAny := diff(n, mid) ; if ((error->compareTo(e)) <= 0) then ( return mid ) else skip ; if (((mid * mid * mid)->compareTo(n)) > 0) then ( end := mid ) else ( start := mid )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=int(input()) a=[] for _ in range(n): a.append(int(input())) kmax=max(a)+m while m>0 : a.sort() m-=1 a[0]+=1 kmin=max(a) print(kmin,kmax) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : a)) ; var kmax : OclAny := (a)->max() + m ; while m > 0 do ( a := a->sort() ; m := m - 1 ; a->first() := a->first() + 1) ; var kmin : OclAny := (a)->max() ; execute (kmin)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") def on_segment(p,q,r): return q[0]<=max(p[0],r[0])and q[0]>=min(p[0],r[0])and q[1]<=max(p[1],r[1])and q[1]>=min(p[1],r[1]) def orientation(p,q,r): val=(q[1]-p[1])*(r[0]-q[0])-(q[0]-p[0])*(r[1]-q[1]) if val==0 : return 0 return 1 if val>0 else 2 def do_intersect(p1,q1,p2,q2): o1=orientation(p1,q1,p2) o2=orientation(p1,q1,q2) o3=orientation(p2,q2,p1) o4=orientation(p2,q2,q1) if o1!=o2 and o3!=o4 : return True if o1==0 and on_segment(p1,p2,q1): return True if o2==0 and on_segment(p1,q2,q1): return True if o3==0 and on_segment(p2,p1,q2): return True if o4==0 and on_segment(p2,q1,q2): return True return False n=int(input()) for k in range(n): x1,y1,x2,y2,x3,y3,x4,y4=[int(_)for _ in input().split()] print(1 if do_intersect([x1,y1],[x2,y2],[x3,y3],[x4,y4])else 0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for k : Integer.subrange(0, n-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; var x3 : OclAny := null; var y3 : OclAny := null; var x4 : OclAny := null; var y4 : OclAny := null; Sequence{x1,y1,x2,y2,x3,y3,x4,y4} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; execute (if do_intersect(Sequence{x1}->union(Sequence{ y1 }), Sequence{x2}->union(Sequence{ y2 }), Sequence{x3}->union(Sequence{ y3 }), Sequence{x4}->union(Sequence{ y4 })) then 1 else 0 endif)->display()); operation on_segment(p : OclAny, q : OclAny, r : OclAny) : OclAny pre: true post: true activity: return (q->first()->compareTo(Set{p->first(), r->first()}->max())) <= 0 & (q->first()->compareTo(Set{p->first(), r->first()}->min())) >= 0 & (q[1+1]->compareTo(Set{p[1+1], r[1+1]}->max())) <= 0 & (q[1+1]->compareTo(Set{p[1+1], r[1+1]}->min())) >= 0; operation orientation(p : OclAny, q : OclAny, r : OclAny) : OclAny pre: true post: true activity: var val : double := (q[1+1] - p[1+1]) * (r->first() - q->first()) - (q->first() - p->first()) * (r[1+1] - q[1+1]) ; if val = 0 then ( return 0 ) else skip ; return if val > 0 then 1 else 2 endif; operation do_intersect(p1 : OclAny, q1 : OclAny, p2 : OclAny, q2 : OclAny) : OclAny pre: true post: true activity: var o1 : OclAny := orientation(p1, q1, p2) ; var o2 : OclAny := orientation(p1, q1, q2) ; var o3 : OclAny := orientation(p2, q2, p1) ; var o4 : OclAny := orientation(p2, q2, q1) ; if o1 /= o2 & o3 /= o4 then ( return true ) else skip ; if o1 = 0 & on_segment(p1, p2, q1) then ( return true ) else skip ; if o2 = 0 & on_segment(p1, q2, q1) then ( return true ) else skip ; if o3 = 0 & on_segment(p2, p1, q2) then ( return true ) else skip ; if o4 = 0 & on_segment(p2, q1, q2) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil n=int(input()); ap=int(input()) l=[*(int(input())for i in range(n))] m=max(l) s=[*(m-x for x in l)] sums=sum(s); ap1=max(ap-sums,0) mik=max(m,m+ceil(ap1/n)) print(mik,m+ap) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var ap : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))} ; var m : OclAny := (l)->max() ; var s : Sequence := Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom (name m))) - (expr (atom (name x))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name l)))))))} ; var sums : OclAny := (s)->sum(); var ap1 : OclAny := Set{ap - sums, 0}->max() ; var mik : OclAny := Set{m, m + ceil(ap1 / n)}->max() ; execute (mik)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil n=int(input()); ap=int(input()) l=[*(int(input())for i in range(n))] m=max(l) s=[*(m-x for x in l)] sums=sum(s); ap1=max(ap-sums,0) print(m+ceil(ap1/n),m+ap) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var ap : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))} ; var m : OclAny := (l)->max() ; var s : Sequence := Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom (name m))) - (expr (atom (name x))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name l)))))))} ; var sums : OclAny := (s)->sum(); var ap1 : OclAny := Set{ap - sums, 0}->max() ; execute (m + ceil(ap1 / n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) m=int(input()) a=[int(input())for _ in range(n)] ma=max(a)+m for _ in range(m): a[a.index(min(a))]+=1 mi=max(a) print(mi,ma) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var ma : OclAny := (a)->max() + m ; for _anon : Integer.subrange(0, m-1) do ( a[a->indexOf((a)->min()) - 1+1] := a[a->indexOf((a)->min()) - 1+1] + 1) ; var mi : OclAny := (a)->max() ; execute (mi)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- LI=lambda : list(map(int,input().split())) N=int(input()) def prime_factor(x): m={} i=2 while i**2<=x : while x % i==0 : if i in m : m[i]+=1 else : m[i]=1 x//=i i+=1 if x!=1 : m[x]=1 return m def main(): m=prime_factor(N) ans=0 for v in m.values(): n=1 while n**2+n<=2*v : n+=1 ans+=n-1 print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var LI : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation prime_factor(x : OclAny) : OclAny pre: true post: true activity: var m : OclAny := Set{} ; var i : int := 2 ; while ((i)->pow(2)->compareTo(x)) <= 0 do ( while x mod i = 0 do ( if (m)->includes(i) then ( m[i+1] := m[i+1] + 1 ) else ( m[i+1] := 1 ) ; x := x div i) ; i := i + 1) ; if x /= 1 then ( m[x+1] := 1 ) else skip ; return m; operation main() pre: true post: true activity: m := prime_factor(N) ; var ans : int := 0 ; for v : m.values() do ( var n : int := 1 ; while ((n)->pow(2) + n->compareTo(2 * v)) <= 0 do ( n := n + 1) ; ans := ans + n - 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def inv(a,m): m0=m x0=0 x1=1 if(m==1): return 0 while(a>1): q=a//m t=m m=a % m a=t t=x0 x0=x1-q*x0 x1=t if(x1<0): x1=x1+m0 return x1 def findMinX(num,rem,k): prod=1 for i in range(0,k): prod=prod*num[i] result=0 for i in range(0,k): pp=prod//num[i] result=result+rem[i]*inv(pp,num[i])*pp return result % prod num=[3,4,5] rem=[2,3,1] k=len(num) print("x is ",findMinX(num,rem,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; num := Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })) ; rem := Sequence{2}->union(Sequence{3}->union(Sequence{ 1 })) ; k := (num)->size() ; execute ("x is ")->display(); operation inv(a : OclAny, m : OclAny) : OclAny pre: true post: true activity: var m0 : OclAny := m ; var x0 : int := 0 ; var x1 : int := 1 ; if (m = 1) then ( return 0 ) else skip ; while (a > 1) do ( var q : int := a div m ; var t : OclAny := m ; m := a mod m ; a := t ; t := x0 ; x0 := x1 - q * x0 ; x1 := t) ; if (x1 < 0) then ( x1 := x1 + m0 ) else skip ; return x1; operation findMinX(num : OclAny, rem : OclAny, k : OclAny) : OclAny pre: true post: true activity: var prod : int := 1 ; for i : Integer.subrange(0, k-1) do ( prod := prod * num[i+1]) ; var result : int := 0 ; for i : Integer.subrange(0, k-1) do ( var pp : int := prod div num[i+1] ; result := result + rem[i+1] * inv(pp, num[i+1]) * pp) ; return result mod prod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMaxOR(arr,n): arr.sort(reverse=True) maxOR=arr[0] count=1 for i in range(1,n): if((maxOR | arr[i])>maxOR): maxOR=maxOR | arr[i]; count+=1 return count if __name__=="__main__" : arr=[5,1,3,4,2] n=len(arr) print(findMaxOR(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{5}->union(Sequence{1}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 2 })))) ; n := (arr)->size() ; execute (findMaxOR(arr, n))->display() ) else skip; operation findMaxOR(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var maxOR : OclAny := arr->first() ; var count : int := 1 ; for i : Integer.subrange(1, n-1) do ( if (((MathLib.bitwiseOr(maxOR, arr[i+1]))->compareTo(maxOR)) > 0) then ( maxOR := MathLib.bitwiseOr(maxOR, arr[i+1]); ; count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def sumOfSeries(n): sum=0 for i in range(1,n+1): sum=sum+(2*i-1)*(2*i-1) return sum n=10 print(sumOfSeries(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 10 ; execute (sumOfSeries(n))->display(); operation sumOfSeries(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( sum := sum + (2 * i - 1) * (2 * i - 1)) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def fourthPowerSum(n): sum=0 for i in range(1,n+1): sum=sum+(i*i*i*i) return sum n=6 print(fourthPowerSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 6 ; execute (fourthPowerSum(n))->display(); operation fourthPowerSum(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( sum := sum + (i * i * i * i)) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def squareSum(n): sum=0 for i in range(0,n+1): sum+=(2*i)*(2*i) return sum ans=squareSum(8) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var ans : OclAny := squareSum(8) ; execute (ans)->display(); operation squareSum(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( sum := sum + (2 * i) * (2 * i)) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def AvgofSquareN(n): sum=0 for i in range(1,n+1): sum+=(i*i) return sum/n n=2 print(AvgofSquareN(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 2 ; execute (AvgofSquareN(n))->display(); operation AvgofSquareN(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( sum := sum + (i * i)) ; return sum / n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fifthPowerSum(n): sm=0 for i in range(1,n+1): sm=sm+(i*i*i*i*i) return sm n=6 print(fifthPowerSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 6 ; execute (fifthPowerSum(n))->display(); operation fifthPowerSum(n : OclAny) : OclAny pre: true post: true activity: var sm : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( sm := sm + (i * i * i * i * i)) ; return sm; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin readline=stdin.readline def main(): q=int(readline()) for i in range(q): xy=map(int,readline().split()) p0,p1,p2,p3=[x+y*1j for x,y in zip(*[xy]*2)] print(1 if is_intersected_ls(p0,p1,p2,p3)else 0) def is_intersected_ls(a1,a2,b1,b2): eps=0 if max(a1.real,a2.real)toInteger() ; for i : Integer.subrange(0, q-1) do ( var xy : Sequence := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p0 : OclAny := null; var p1 : OclAny := null; var p2 : OclAny := null; var p3 : OclAny := null; Sequence{p0,p1,p2,p3} := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name xy))))))) ])) * (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name xy))))))) ])) * (expr (atom (number (integer 2)))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name xy))))))) ])) * (expr (atom (number (integer 2)))))))))`third->at(_indx)} )->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (x + y * 1j)) ; execute (if is_intersected_ls(p0, p1, p2, p3) then 1 else 0 endif)->display()); operation is_intersected_ls(a1 : OclAny, a2 : OclAny, b1 : OclAny, b2 : OclAny) : OclAny pre: true post: true activity: var eps : int := 0 ; if (Set{a1.real, a2.real}->max()->compareTo(Set{b1.real, b2.real}->min())) < 0 or (Set{b1.real, b2.real}->max()->compareTo(Set{a1.real, a2.real}->min())) < 0 or (Set{a1.imag, a2.imag}->max()->compareTo(Set{b1.imag, b2.imag}->min())) < 0 or (Set{b1.imag, b2.imag}->max()->compareTo(Set{a1.imag, a2.imag}->min())) < 0 then ( return false ) else skip ; return ((cross(a2 - a1, b1 - a1) * cross(a2 - a1, b2 - a1)->compareTo(eps)) <= 0) & ((cross(b2 - b1, a1 - b1) * cross(b2 - b1, a2 - b1)->compareTo(eps)) <= 0); operation cross(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a.real * b.imag - a.imag * b.real; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def squaresum(n): sm=0 for i in range(1,n+1): sm=sm+(i*i) return sm n=4 print(squaresum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute (squaresum(n))->display(); operation squaresum(n : OclAny) : OclAny pre: true post: true activity: var sm : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( sm := sm + (i * i)) ; return sm; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def aliquotSum(n): sm=0 for i in range(1,n): if(n % i==0): sm=sm+i return sm n=12 print(aliquotSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 12 ; execute (aliquotSum(n))->display(); operation aliquotSum(n : OclAny) : OclAny pre: true post: true activity: var sm : int := 0 ; for i : Integer.subrange(1, n-1) do ( if (n mod i = 0) then ( sm := sm + i ) else skip) ; return sm; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def findIndex(n): fibo=2.078087*math.log(n)+1.672276 return round(fibo) n=21 print(findIndex(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 21 ; execute (findIndex(n))->display(); operation findIndex(n : OclAny) : OclAny pre: true post: true activity: var fibo : double := 2.078087 * (n)->log() + 1.672276 ; return (fibo)->round(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSum(n): summ=0 for i in range(1,n+1): summ=(summ+((i*(i+1)*(2*i+1))/6)) return summ n=3 print(int(findSum(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3 ; execute (("" + ((findSum(n))))->toInteger())->display(); operation findSum(n : OclAny) : OclAny pre: true post: true activity: var summ : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( summ := (summ + ((i * (i + 1) * (2 * i + 1)) / 6))) ; return summ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def seriessum(n): sum=0 for i in range(1,n+1): sum+=i*(i+1)/2 return sum n=4 print(seriessum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute (seriessum(n))->display(); operation seriessum(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( sum := sum + i * (i + 1) / 2) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def seriessum(n): sum=0 for i in range(1,n+1): sum+=i*(i+1)/2 return sum n=4 print(seriessum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute (seriessum(n))->display(); operation seriessum(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( sum := sum + i * (i + 1) / 2) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSum(n): sum=0 for i in range(n): sum+=i*(n-i) return 2*sum n=3 print(findSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3 ; execute (findSum(n))->display(); operation findSum(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + i * (n - i)) ; return 2 * sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pentagon_pyramidal(n): sum=0 for i in range(1,n+1): p=(3*i*i-i)/2 sum=sum+p return sum n=4 print(int(pentagon_pyramidal(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute (("" + ((pentagon_pyramidal(n))))->toInteger())->display(); operation pentagon_pyramidal(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( var p : double := (3 * i * i - i) / 2 ; sum := sum + p) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import floor def solve(n,base): sum=0 while(n>0): remainder=n % base sum=sum+remainder n=int(n/base) return sum def SumsOfDigits(n): sum=0 N=floor(n/2) for base in range(2,N+1,1): sum=sum+solve(n,base) print(sum) if __name__=='__main__' : n=8 SumsOfDigits(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( n := 8 ; SumsOfDigits(n) ) else skip; operation solve(n : OclAny, base : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; while (n > 0) do ( var remainder : int := n mod base ; sum := sum + remainder ; n := ("" + ((n / base)))->toInteger()) ; return sum; operation SumsOfDigits(n : OclAny) pre: true post: true activity: sum := 0 ; var N : OclAny := floor(n / 2) ; for base : Integer.subrange(2, N + 1-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( sum := sum + solve(n, base)) ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math isPrime=[True]*110001 primes=[]; def eratos(n): isPrime[0]=isPrime[1]=False for i in range(2,int(math.sqrt(n))): if isPrime[i]: j=2*i while j<=n : isPrime[j]=False j=j+i for i in range(2,110000): if isPrime[i]: primes.append(i) eratos(110000) while True : try : p=int(input()) if p==0 : break ans=0 for i in range(0,p): ans+=primes[i] print(ans) except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var isPrime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, 110001) ; var primes : Sequence := Sequence{}; ; skip ; eratos(110000) ; while true do ( try ( var p : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if p = 0 then ( break ) else skip ; var ans : int := 0 ; for i : Integer.subrange(0, p-1) do ( ans := ans + primes[i+1]) ; execute (ans)->display()) catch (_e : OclException) do ( break) ); operation eratos(n : OclAny) pre: true post: true activity: isPrime->first() := false; var isPrime[1+1] : boolean := false ; for i : Integer.subrange(2, ("" + (((n)->sqrt())))->toInteger()-1) do ( if isPrime[i+1] then ( var j : double := 2 * i ; while (j->compareTo(n)) <= 0 do ( isPrime[j+1] := false ; j := j + i) ) else skip) ; for i : Integer.subrange(2, 110000-1) do ( if isPrime[i+1] then ( execute ((i) : primes) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import* n=104730 ; a=list(range(n)); a[: 2]=0,0 for i in range(2,323): a[i*2 : : i]=[0]*len(a[i*2 : : i]) p=list(compress(range(n),a)) print('\n'.join(str(sum(p[: int(e)]))for e in iter(input,'0'))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := 104730; var a : Sequence := (Integer.subrange(0, n-1)); a.subrange(1,2) := 0,0 ; for i : Integer.subrange(2, 323-1) do ( a(subscript (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom (number (integer 2)))))))) : (sliceop : (test (logical_test (comparison (expr (atom (name i)))))))) := MatrixLib.elementwiseMult(Sequence{ 0 }, (a(subscript (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom (number (integer 2)))))))) : (sliceop : (test (logical_test (comparison (expr (atom (name i)))))))))->size())) ; var p : Sequence := (compress(Integer.subrange(0, n-1), a)) ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name e)))))))) ))))))))) ])))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name e)))) in (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input))))))) , (argument (test (logical_test (comparison (expr (atom '0'))))))) ))))))))), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isAnyNotPalindrome(s): unique=set() for i in range(0,len(s)): unique.add(s[i]) if(len(unique)>1): return True else : return False if __name__=='__main__' : s="aaaaab" if(isAnyNotPalindrome(s)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( s := "aaaaab" ; if (isAnyNotPalindrome(s)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; operation isAnyNotPalindrome(s : OclAny) : OclAny pre: true post: true activity: var unique : Set := Set{}->union(()) ; for i : Integer.subrange(0, (s)->size()-1) do ( execute ((s[i+1]) : unique)) ; if ((unique)->size() > 1) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def prime_checker(n,option=False)->list : p=[False,True,False,False,False,True]*(n//6+1) del p[n+1 :] p[1 : 4]=False,True,True for x in range(5,int(n**.5+1)): if p[x]: p[x*x : : 2*x]=[False]*((n//x-x)//2+1) return[e for e,q in enumerate(p)if q]if option else p from itertools import accumulate *p,=accumulate([0]+prime_checker(105010,True)) for i in[*map(int,open(0))][:-1]: print(p[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; (testlist_star_expr (star_expr * (expr (atom (name p)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name p)))) ,)} := accumulate(Sequence{ 0 }->union(prime_checker(105010, true))) ; for i : (OclFile.newOclFile_Write(OclFile.newOclFile(0)))->collect( _x | (OclType["int"])->apply(_x) )->front() do ( execute (p[i+1])->display()); operation prime_checker(n : OclAny, option : OclAny) : Sequence pre: true post: true activity: if option->oclIsUndefined() then option := false else skip; var p : Sequence := MatrixLib.elementwiseMult(Sequence{false}->union(Sequence{true}->union(Sequence{false}->union(Sequence{false}->union(Sequence{false}->union(Sequence{ true }))))), (n div 6 + 1)) ; execute (p.subrange(n + 1+1))->isDeleted() ; p.subrange(1+1, 4) := false,true,true ; for x : Integer.subrange(5, ("" + (((n)->pow(.5) + 1)))->toInteger()-1) do ( if p[x+1] then ( p(subscript (test (logical_test (comparison (expr (expr (atom (name x))) * (expr (atom (name x))))))) : (sliceop : (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name x))))))))) := MatrixLib.elementwiseMult(Sequence{ false }, ((n div x - x) div 2 + 1)) ) else skip) ; return if option then Integer.subrange(1, (p)->size())->collect( _indx | Sequence{_indx-1, (p)->at(_indx)} )->select(_tuple | let e : OclAny = _tuple->at(1) in let q : OclAny = _tuple->at(2) in q)->collect(_tuple | let e : OclAny = _tuple->at(1) in let q : OclAny = _tuple->at(2) in (e)) else p endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isSmaller(str1,str2): n1=len(str1) n2=len(str2) if(n1str2[i]): return False return False def findDiff(str1,str2): if(isSmaller(str1,str2)): temp=str1 str1=str2 str2=temp str3="" n1=len(str1) n2=len(str2) str1=str1[: :-1] str2=str2[: :-1] carry=0 for i in range(n2): sub=((ord(str1[i])-ord('0'))-(ord(str2[i])-ord('0'))-carry) if(sub<0): sub=sub+10 carry=1 else : carry=0 str3=str3+str(sub) for i in range(n2,n1): sub=((ord(str1[i])-ord('0'))-carry) if(sub<0): sub=sub+10 carry=1 else : carry=0 str3=str3+str(sub) str3=str3[: :-1] return str3 if __name__=="__main__" : str1="978" str2="12977" print(findDiff(str1,str2)) s1="100" s2="1000000" print(findDiff(s1,s2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( str1 := "978" ; str2 := "12977" ; execute (findDiff(str1, str2))->display() ; var s1 : String := "100" ; var s2 : String := "1000000" ; execute (findDiff(s1, s2))->display() ) else skip; operation isSmaller(str1 : OclAny, str2 : OclAny) : OclAny pre: true post: true activity: var n1 : int := (str1)->size() ; var n2 : int := (str2)->size() ; if ((n1->compareTo(n2)) < 0) then ( return true ) else skip ; if ((n2->compareTo(n1)) < 0) then ( return false ) else skip ; for i : Integer.subrange(0, n1-1) do ( if ((str1[i+1]->compareTo(str2[i+1])) < 0) then ( return true ) else (if ((str1[i+1]->compareTo(str2[i+1])) > 0) then ( return false ) else skip)) ; return false; operation findDiff(str1 : OclAny, str2 : OclAny) : OclAny pre: true post: true activity: if (isSmaller(str1, str2)) then ( var temp : OclAny := str1 ; str1 := str2 ; str2 := temp ) else skip ; var str3 : String := "" ; n1 := (str1)->size() ; n2 := (str2)->size() ; str1 := str1(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; str2 := str2(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var carry : int := 0 ; for i : Integer.subrange(0, n2-1) do ( var sub : double := (((str1[i+1])->char2byte() - ('0')->char2byte()) - ((str2[i+1])->char2byte() - ('0')->char2byte()) - carry) ; if (sub < 0) then ( sub := sub + 10 ; carry := 1 ) else ( carry := 0 ) ; str3 := str3 + ("" + ((sub)))) ; for i : Integer.subrange(n2, n1-1) do ( sub := (((str1[i+1])->char2byte() - ('0')->char2byte()) - carry) ; if (sub < 0) then ( sub := sub + 10 ; carry := 1 ) else ( carry := 0 ) ; str3 := str3 + ("" + ((sub)))) ; str3 := str3(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; return str3; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import random def is_prime(q,k=50): q=abs(q) if q==2 : return True if q<2 or q & 1==0 : return False d=(q-1)>>1 while d & 1==0 : d>>=1 for i in range(k): a=random.randint(1,q-1) t=d y=pow(a,t,q) while t!=q-1 and y!=1 and y!=q-1 : y=pow(y,2,q) t<<=1 if y!=q-1 and t & 1==0 : return False return True Primes=[] def find_nth_prime(n): count=len(Primes) if count>=n : return if count>0 : num=Primes[-1]+1 else : num=2 while True : if is_prime(num): count+=1 Primes.append(num) if count>=n : break num+=1 if __name__=='__main__' : while True : data=int(input()) if data==0 : break find_nth_prime(data) print(sum(Primes[: data])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var Primes : Sequence := Sequence{} ; skip ; if __name__ = '__main__' then ( while true do ( var data : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if data = 0 then ( break ) else skip ; find_nth_prime(data) ; execute ((Primes.subrange(1,data))->sum())->display()) ) else skip; operation is_prime(q : OclAny, k : int) : OclAny pre: true post: true activity: if k->oclIsUndefined() then k := 50 else skip; q := (q)->abs() ; if q = 2 then ( return true ) else skip ; if q < 2 or MathLib.bitwiseAnd(q, 1) = 0 then ( return false ) else skip ; var d : int := (q - 1) /(2->pow(1)) ; while MathLib.bitwiseAnd(d, 1) = 0 do ( d := d div (2->pow(1))) ; for i : Integer.subrange(0, k-1) do ( var a : int := (1 + (OclRandom.defaultInstanceOclRandom()).nextInt(q - 1 - 1)) ; var t : int := d ; var y : double := (a)->pow(t) ; while t /= q - 1 & y /= 1 & y /= q - 1 do ( y := (y)->pow(2) ; t := t * (2->pow(1))) ; if y /= q - 1 & MathLib.bitwiseAnd(t, 1) = 0 then ( return false ) else skip) ; return true; operation find_nth_prime(n : OclAny) pre: true post: true activity: var count : int := (Primes)->size() ; if (count->compareTo(n)) >= 0 then ( return ) else skip ; if count > 0 then ( var num : OclAny := Primes->last() + 1 ) else ( num := 2 ) ; while true do ( if is_prime(num) then ( count := count + 1 ; execute ((num) : Primes) ) else skip ; if (count->compareTo(n)) >= 0 then ( break ) else skip ; num := num + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt import sys sys.setrecursionlimit(100000) def prime(n): p=[1 for i in range(n)] p[0]=0 prime_=[] for i in range(2,int(sqrt(n))): if p[i-1]==1 : for i in range(2*i,n,i): p[i-1]=0 for i in range(n): if p[i]==1 : prime_.append(i+1) return prime_ prime_=prime(105000) sum_prime_=[0 for i in range(10000)] def sum_prime(n): global sum_prime_ if n==1 : sum_prime_[n-1]=prime_[n-1] return sum_prime_[n-1] else : sum_prime_[n-1]=prime_[n-1]+sum_prime(n-1) return sum_prime_[n-1] sum_prime(10000) while(1): n=int(input()) if n==0 : break print(sum_prime_[n-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute sum_prime_ : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit(100000) ; skip ; prime_ := prime(105000) ; var sum_prime_ : Sequence := Integer.subrange(0, 10000-1)->select(i | true)->collect(i | (0)) ; skip ; sum_prime(10000) ; while (1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; execute (sum_prime_[n - 1+1])->display()); operation prime(n : OclAny) : OclAny pre: true post: true activity: var p : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (1)) ; p->first() := 0 ; var prime_ : Sequence := Sequence{} ; for i : Integer.subrange(2, ("" + ((sqrt(n))))->toInteger()-1) do ( if p[i - 1+1] = 1 then ( for i : Integer.subrange(2 * i, n-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ( p[i - 1+1] := 0) ) else skip) ; for i : Integer.subrange(0, n-1) do ( if p[i+1] = 1 then ( execute ((i + 1) : prime_) ) else skip) ; return prime_; operation sum_prime(n : OclAny) : OclAny pre: true post: true activity: skip ; if n = 1 then ( sum_prime_[n - 1+1] := prime_[n - 1+1] ; return sum_prime_[n - 1+1] ) else ( sum_prime_[n - 1+1] := prime_[n - 1+1] + sum_prime(n - 1) ; return sum_prime_[n - 1+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin as input_file from sys import stdout as output_file def readline(file): return file.readline().rstrip('\n') num_cases=int(readline(input_file)) for case_num in xrange(num_cases): num_engines=int(readline(input_file)) engines=[] for i in xrange(num_engines): engine=readline(input_file) engines.append(engine) num_queries=int(readline(input_file)) queries=[] for i in xrange(num_queries): query=readline(input_file) queries.append(query) num_switches=0 occurrence=set() for query in queries : occurrence.add(query) if len(occurrence)==num_engines : occurrence=set() occurrence.add(query) num_switches+=1 output_file.write('Case #%d: %d\n' %(case_num+1,num_switches)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var num_cases : int := ("" + ((readline(input_file))))->toInteger() ; for case_num : xrange(num_cases) do ( var num_engines : int := ("" + ((readline(input_file))))->toInteger() ; var engines : Sequence := Sequence{} ; for i : xrange(num_engines) do ( var engine : OclAny := readline(input_file) ; execute ((engine) : engines)) ; var num_queries : int := ("" + ((readline(input_file))))->toInteger() ; var queries : Sequence := Sequence{} ; for i : xrange(num_queries) do ( var query : OclAny := readline(input_file) ; execute ((query) : queries)) ; var num_switches : int := 0 ; var occurrence : Set := Set{}->union(()) ; for query : queries do ( execute ((query) : occurrence) ; if (occurrence)->size() = num_engines then ( occurrence := Set{}->union(()) ; execute ((query) : occurrence) ; num_switches := num_switches + 1 ) else skip) ; output_file.write(StringLib.format('Case #%d: %d ',Sequence{case_num + 1, num_switches}))); operation readline(file : OclAny) : OclAny pre: true post: true activity: return file.readLine().rstrip(' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import string S=0 N=0 Q=0 engine={} input_f=None output_f=None def case_init(): global S,N,Q,engine,input_f,output_f S=string.atoi(input_f.readline()) engine={} for i in xrange(S): engine[input_f.readline()]=i Q=string.atoi(input_f.readline()) def query(): global S,N,Q,engine,input_f,output_f for i in xrange(Q): yield engine[input_f.readline()] def cal(): global S,N,Q,engine,input_f,output_f result=[0]*S for i in query(): for j in xrange(S): result[j]=min(result[j],result[i]+1) result[i]=10000000 return min(result) def main(): global S,N,Q,engine,input_f,output_f input_f=open('A-large.in','rb') output_f=open('output.txt','w') output_f.seek(0) N=string.atoi(input_f.readline()) for i in xrange(N): case_init() output_f.write('Case #%d: %d\n' %(i+1,cal())) output_f.flush() main() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute S : OclAny; attribute N : OclAny; attribute Q : OclAny; attribute engine : OclAny; attribute input_f : OclAny; attribute output_f : OclAny; attribute S : OclAny; attribute N : OclAny; attribute Q : OclAny; attribute engine : OclAny; attribute input_f : OclAny; attribute output_f : OclAny; attribute S : OclAny; attribute N : OclAny; attribute Q : OclAny; attribute engine : OclAny; attribute input_f : OclAny; attribute output_f : OclAny; attribute S : OclAny; attribute N : OclAny; attribute Q : OclAny; attribute engine : OclAny; attribute input_f : OclAny; attribute output_f : OclAny; operation initialise() pre: true post: true activity: skip ; var S : int := 0 ; var N : int := 0 ; var Q : int := 0 ; var engine : OclAny := Set{} ; var input_f : OclAny := null ; var output_f : OclAny := null ; skip ; skip ; skip ; skip ; main(); operation case_init() pre: true post: true activity: skip; skip; skip; skip; skip; skip ; S := string.atoi(input_f.readLine()) ; engine := Set{} ; for i : xrange(S) do ( engine[input_f.readLine()+1] := i) ; Q := string.atoi(input_f.readLine()); operation query(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; skip; skip; skip; skip; skip; skip ; for i : xrange(Q) do ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return engine[input_f.readLine()+1]); operation cal() : OclAny pre: true post: true activity: skip; skip; skip; skip; skip; skip ; var result : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, S) ; for i : OclIterator.newOclIterator_Function(lambda _i : int in self.query(_i)) do ( for j : xrange(S) do ( result[j+1] := Set{result[j+1], result[i+1] + 1}->min()) ; result[i+1] := 10000000) ; return (result)->min(); operation main() pre: true post: true activity: skip; skip; skip; skip; skip; skip ; input_f := OclFile.newOclFile_Write(OclFile.newOclFile('A-large.in')) ; output_f := OclFile.newOclFile_Write(OclFile.newOclFile('output.txt')) ; output_f.setPosition(0) ; N := string.atoi(input_f.readLine()) ; for i : xrange(N) do ( case_init() ; output_f.write(StringLib.format('Case #%d: %d ',Sequence{i + 1, cal()}))) ; output_f.flush(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(bin(4).count('1')); print(bin(15).count('1')); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (bin(4)->count('1'))->display(); ; execute (bin(15)->count('1'))->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INT_MAX=2147483647 def optimalSearchTree(keys,freq,n): cost=[[0 for x in range(n)]for y in range(n)] for i in range(n): cost[i][i]=freq[i] for L in range(2,n+1): for i in range(n-L+2): j=i+L-1 if i>=n or j>=n : break cost[i][j]=INT_MAX for r in range(i,j+1): c=0 if(r>i): c+=cost[i][r-1] if(runion(Sequence{12}->union(Sequence{ 20 })) ; freq := Sequence{34}->union(Sequence{8}->union(Sequence{ 50 })) ; n := (keys)->size() ; execute ("Cost of Optimal BST is")->display() ) else skip; operation optimalSearchTree(keys : OclAny, freq : OclAny, n : OclAny) : OclAny pre: true post: true activity: var cost : Sequence := Integer.subrange(0, n-1)->select(y | true)->collect(y | (Integer.subrange(0, n-1)->select(x | true)->collect(x | (0)))) ; for i : Integer.subrange(0, n-1) do ( cost[i+1][i+1] := freq[i+1]) ; for L : Integer.subrange(2, n + 1-1) do ( for i : Integer.subrange(0, n - L + 2-1) do ( var j : double := i + L - 1 ; if (i->compareTo(n)) >= 0 or (j->compareTo(n)) >= 0 then ( break ) else skip ; cost[i+1][j+1] := INT_MAX ; for r : Integer.subrange(i, j + 1-1) do ( var c : int := 0 ; if ((r->compareTo(i)) > 0) then ( c := c + cost[i+1][r - 1+1] ) else skip ; if ((r->compareTo(j)) < 0) then ( c := c + cost[r + 1+1][j+1] ) else skip ; c := c + (freq, i, j)->sum() ; if ((c->compareTo(cost[i+1][j+1])) < 0) then ( cost[i+1][j+1] := c ) else skip))) ; return cost->first()[n - 1+1]; operation sum(freq : OclAny, i : OclAny, j : OclAny) : OclAny pre: true post: true activity: var s : int := 0 ; for k : Integer.subrange(i, j + 1-1) do ( s := s + freq[k+1]) ; return s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get(x,y,z): if(x>z): return-1 val=z-x div=(z-x)//y ans=div*y+x return ans x=1 y=5 z=8 print(get(x,y,z)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := 1 ; y := 5 ; z := 8 ; execute (get(x, y, z))->display(); operation get(x : OclAny, y : OclAny, z : OclAny) : OclAny pre: true post: true activity: if ((x->compareTo(z)) > 0) then ( return -1 ) else skip ; var val : double := z - x ; var div : int := (z - x) div y ; var ans : double := div * y + x ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) b=[0]*n for i in range(n): b[a[i]-1]=i res=0 for i in range(1,n): res+=abs(b[i]-b[i-1]) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( b[a[i+1] - 1+1] := i) ; var res : int := 0 ; for i : Integer.subrange(1, n-1) do ( res := res + (b[i+1] - b[i - 1+1])->abs()) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(x)-1 for x in input().split()] occs=[0]*n for i in range(n): occs[a[i]]=i time=0 for i in range(1,n): time+=abs(occs[i]-occs[i-1]) print(time) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)) ; var occs : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( occs[a[i+1]+1] := i) ; var time : int := 0 ; for i : Integer.subrange(1, n-1) do ( time := time + (occs[i+1] - occs[i - 1+1])->abs()) ; execute (time)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMajority(arr,n): return arr[int(n/2)] arr=[1,2,2,3] n=len(arr) print(findMajority(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 3 }))) ; n := (arr)->size() ; execute (findMajority(arr, n))->display(); operation findMajority(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: return arr[("" + ((n / 2)))->toInteger()+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minSwaps(s1,s2): c0=0 ; c1=0 ; for i in range(len(s1)): if(s1[i]=='0' and s2[i]=='1'): c0+=1 ; elif(s1[i]=='1' and s2[i]=='0'): c1+=1 ; ans=c0//2+c1//2 ; if(c0 % 2==0 and c1 % 2==0): return ans ; elif((c0+c1)% 2==0): return ans+2 ; else : return-1 ; if __name__=="__main__" : s1="0011" ; s2="1111" ; ans=minSwaps(s1,s2); print(ans); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s1 := "0011"; s2 := "1111"; ; ans := minSwaps(s1, s2); ; execute (ans)->display(); ) else skip; operation minSwaps(s1 : OclAny, s2 : OclAny) pre: true post: true activity: var c0 : int := 0; var c1 : int := 0; ; for i : Integer.subrange(0, (s1)->size()-1) do ( if (s1[i+1] = '0' & s2[i+1] = '1') then ( c0 := c0 + 1; ) else (if (s1[i+1] = '1' & s2[i+1] = '0') then ( c1 := c1 + 1; ) else skip)) ; var ans : int := c0 div 2 + c1 div 2; ; if (c0 mod 2 = 0 & c1 mod 2 = 0) then ( return ans; ) else (if ((c0 + c1) mod 2 = 0) then ( return ans + 2; ) else ( return -1; ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) values=list(map(int,input().split())) hm={} for i,v in enumerate(values): hm[v]=i ans=0 for i in range(1,n): ans+=abs(hm[i+1]-hm[i]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var values : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var hm : OclAny := Set{} ; for _tuple : Integer.subrange(1, (values)->size())->collect( _indx | Sequence{_indx-1, (values)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); hm[v+1] := i) ; var ans : int := 0 ; for i : Integer.subrange(1, n-1) do ( ans := ans + (hm[i + 1+1] - hm[i+1])->abs()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin n=int(input()) d=dict(((int(val),idx)for idx,val in enumerate(stdin.read().strip().split()))) a=1 t=0 for b in range(2,n+1): t+=abs(d[b]-d[a]) a=b print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Map := (((testlist_comp (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name val)))))))) ))))))) , (test (logical_test (comparison (expr (atom (name idx))))))) )))))) (comp_for for (exprlist (expr (atom (name idx))) , (expr (atom (name val)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name stdin)) (trailer . (name read) (arguments ( ))) (trailer . (name strip) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))))))) ; var a : int := 1 ; var t : int := 0 ; for b : Integer.subrange(2, n + 1-1) do ( t := t + (d[b+1] - d[a+1])->abs() ; a := b) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binomialCoeff(n,k): C=[[0 for x in range(k+1)]for y in range(n+1)] for i in range(n+1): for j in range(min(i,k)+1): if(j==0 or j==i): C[i][j]=1 ; else : C[i][j]=C[i-1][j-1]+C[i-1][j]; return C[n][k]; def maxcoefficientvalue(n): if(n % 2==0): return binomialCoeff(n,int(n/2)); else : return binomialCoeff(n,int((n+1)/2)); if __name__=='__main__' : n=4 ; print(maxcoefficientvalue(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( n := 4; ; execute (maxcoefficientvalue(n))->display(); ) else skip; operation binomialCoeff(n : OclAny, k : OclAny) pre: true post: true activity: var C : Sequence := Integer.subrange(0, n + 1-1)->select(y | true)->collect(y | (Integer.subrange(0, k + 1-1)->select(x | true)->collect(x | (0)))) ; for i : Integer.subrange(0, n + 1-1) do ( for j : Integer.subrange(0, Set{i, k}->min() + 1-1) do ( if (j = 0 or j = i) then ( C[i+1][j+1] := 1; ) else ( C[i+1][j+1] := C[i - 1+1][j - 1+1] + C[i - 1+1][j+1]; ))) ; return C[n+1][k+1];; operation maxcoefficientvalue(n : OclAny) pre: true post: true activity: if (n mod 2 = 0) then ( return binomialCoeff(n, ("" + ((n / 2)))->toInteger()); ) else ( return binomialCoeff(n, ("" + (((n + 1) / 2)))->toInteger()); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isVowel(ch): if ch in['a','e','i','o','u']: return True else : return False def vowelPairs(s,n): cnt=0 for i in range(n-1): if(isVowel(s[i])and isVowel(s[i+1])): cnt+=1 return cnt s="abaebio" n=len(s) print(vowelPairs(s,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; s := "abaebio" ; n := (s)->size() ; execute (vowelPairs(s, n))->display(); operation isVowel(ch : OclAny) : OclAny pre: true post: true activity: if (Sequence{'a'}->union(Sequence{'e'}->union(Sequence{'i'}->union(Sequence{'o'}->union(Sequence{ 'u' })))))->includes(ch) then ( return true ) else ( return false ); operation vowelPairs(s : OclAny, n : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if (isVowel(s[i+1]) & isVowel(s[i + 1+1])) then ( cnt := cnt + 1 ) else skip) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): while True : N=int(input()) if N==0 : exit() (W,H)=[int(x)for x in input().split()] persimmon=[[0 for j in range(100)]for i in range(100)] for _ in range(N): (x,y)=[int(x)for x in input().split()] persimmon[x][y]=1 cumsum=[[0 for j in range(100)]for i in range(100)] for x in range(1,100): for y in range(1,100): cumsum[x][y]=cumsum[x-1][y]+cumsum[x][y-1]-cumsum[x-1][y-1]+persimmon[x][y] (S,T)=[int(x)for x in input().split()] max_persimmon=0 for x in range(S,W+1): for y in range(T,H+1): max_persimmon=max(max_persimmon,cumsum[x][y]+cumsum[x-S][y-T]-cumsum[x][y-T]-cumsum[x-S][y]) print(max_persimmon) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var Sequence{W, H} : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation main() pre: true post: true activity: while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( exit() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(n): w,h=map(int,input().split()) xy=[list(map(lambda x : int(x)-1,input().split()))for i in range(n)] s,t=map(int,input().split()) field=[[0]*w for i in range(h)] for x,y in xy : field[y][x]=1 ans=0 for y in range(h-t+1): for x in range(w-s+1): b=0 for yi in range(t): for xi in range(s): b+=field[y+yi][x+xi] ans=max(ans,b) print(ans) while 1 : n=int(input()) if n==0 : break main(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while 1 do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; main(n)); operation main(n : OclAny) pre: true post: true activity: var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var xy : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) )))) ; var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var field : Sequence := Integer.subrange(0, h-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, w))) ; for _tuple : xy do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); field[y+1][x+1] := 1) ; var ans : int := 0 ; for y : Integer.subrange(0, h - t + 1-1) do ( for x : Integer.subrange(0, w - s + 1-1) do ( var b : int := 0 ; for yi : Integer.subrange(0, t-1) do ( for xi : Integer.subrange(0, s-1) do ( b := b + field[y + yi+1][x + xi+1])) ; ans := Set{ans, b}->max())) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break w,h=map(int,input().split()) trees=[[0 for i in range(h+1)]for j in range(w+1)] dis=[[0 for i in range(h+1)]for j in range(w+1)] for i in range(n): x,y=map(int,input().split()) trees[x][y]=1 for i in range(1,w+1): for j in range(1,h+1): dis[i][j]=trees[i][j]+dis[i-1][j]+dis[i][j-1]-dis[i-1][j-1] s,t=map(int,input().split()) ans=0 for i in range(1,w-s+2): for j in range(1,h-t+2): num=dis[i+s-1][j+t-1]-dis[i+s-1][j-1]-dis[i-1][j+t-1]+dis[i-1][j-1] ans=max(ans,num) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var trees : Sequence := Integer.subrange(0, w + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, h + 1-1)->select(i | true)->collect(i | (0)))) ; var dis : Sequence := Integer.subrange(0, w + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, h + 1-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; trees[x+1][y+1] := 1) ; for i : Integer.subrange(1, w + 1-1) do ( for j : Integer.subrange(1, h + 1-1) do ( dis[i+1][j+1] := trees[i+1][j+1] + dis[i - 1+1][j+1] + dis[i+1][j - 1+1] - dis[i - 1+1][j - 1+1])) ; var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; for i : Integer.subrange(1, w - s + 2-1) do ( for j : Integer.subrange(1, h - t + 2-1) do ( var num : double := dis[i + s - 1+1][j + t - 1+1] - dis[i + s - 1+1][j - 1+1] - dis[i - 1+1][j + t - 1+1] + dis[i - 1+1][j - 1+1] ; ans := Set{ans, num}->max())) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=[[0 for x in range(105)]for y in range(105)] while True : N=int(input()) if N==0 : break a=[[0 for x in range(105)]for y in range(105)] W,H=map(int,input().split()) for i in range(N): x,y=map(int,input().split()) a[y][x]=1 for y in range(1,H+1): for x in range(1,W+1): s[y][x]=s[y][x-1]+a[y][x] S,T=map(int,input().split()) ans=0 for y in range(H-T+1): for x in range(W-S+1): k=0 for i in range(1,T+1): k+=s[y+i][x+S]-s[y+i][x]; ans=max(ans,k) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := Integer.subrange(0, 105-1)->select(y | true)->collect(y | (Integer.subrange(0, 105-1)->select(x | true)->collect(x | (0)))) ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var a : Sequence := Integer.subrange(0, 105-1)->select(y | true)->collect(y | (Integer.subrange(0, 105-1)->select(x | true)->collect(x | (0)))) ; var W : OclAny := null; var H : OclAny := null; Sequence{W,H} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, N-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a[y+1][x+1] := 1) ; for y : Integer.subrange(1, H + 1-1) do ( for x : Integer.subrange(1, W + 1-1) do ( s[y+1][x+1] := s[y+1][x - 1+1] + a[y+1][x+1])) ; var S : OclAny := null; var T : OclAny := null; Sequence{S,T} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; for y : Integer.subrange(0, H - T + 1-1) do ( for x : Integer.subrange(0, W - S + 1-1) do ( var k : int := 0 ; for i : Integer.subrange(1, T + 1-1) do ( k := k + s[y + i+1][x + S+1] - s[y + i+1][x+1];) ; ans := Set{ans, k}->max())) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def main(): while True : N=int(input()) if N==0 : return W,H=map(int,input().split()) board=[[0]*(W+1)for i in range(H+1)] for i in range(N): x,y=map(int,input().split()) board[y][x]=1 for i in range(1,H+1): for j in range(W+1): board[i][j]+=board[i-1][j] for j in range(1,W+1): for i in range(H+1): board[i][j]+=board[i][j-1] S,T=map(int,input().split()) ans=0 for y in range(1,H-T+2): for x in range(1,W-S+2): tx=x+S-1 ty=y+T-1 ans=max(ans,board[ty][tx]-board[ty][x-1]-board[y-1][tx]+board[y-1][x-1]) print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( return ) else skip ; var W : OclAny := null; var H : OclAny := null; Sequence{W,H} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var board : Sequence := Integer.subrange(0, H + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (W + 1)))) ; for i : Integer.subrange(0, N-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; board[y+1][x+1] := 1) ; for i : Integer.subrange(1, H + 1-1) do ( for j : Integer.subrange(0, W + 1-1) do ( board[i+1][j+1] := board[i+1][j+1] + board[i - 1+1][j+1])) ; for j : Integer.subrange(1, W + 1-1) do ( for i : Integer.subrange(0, H + 1-1) do ( board[i+1][j+1] := board[i+1][j+1] + board[i+1][j - 1+1])) ; var S : OclAny := null; var T : OclAny := null; Sequence{S,T} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; for y : Integer.subrange(1, H - T + 2-1) do ( for x : Integer.subrange(1, W - S + 2-1) do ( var tx : double := x + S - 1 ; var ty : double := y + T - 1 ; ans := Set{ans, board[ty+1][tx+1] - board[ty+1][x - 1+1] - board[y - 1+1][tx+1] + board[y - 1+1][x - 1+1]}->max())) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isSubstring(s1,s2): M=len(s1) N=len(s2) for i in range(N-M+1): for j in range(M): if(s2[i+j]!=s1[j]): break if j+1==M : return i return-1 if __name__=="__main__" : s1="for" s2="geeksforgeeks" res=isSubstring(s1,s2) if res==-1 : print("Not present") else : print("Present at index "+str(res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s1 := "for" ; s2 := "geeksforgeeks" ; var res : OclAny := isSubstring(s1, s2) ; if res = -1 then ( execute ("Not present")->display() ) else ( execute ("Present at index " + ("" + ((res))))->display() ) ) else skip; operation isSubstring(s1 : OclAny, s2 : OclAny) : OclAny pre: true post: true activity: var M : int := (s1)->size() ; var N : int := (s2)->size() ; for i : Integer.subrange(0, N - M + 1-1) do ( for j : Integer.subrange(0, M-1) do ( if (s2[i + j+1] /= s1[j+1]) then ( break ) else skip) ; if j + 1 = M then ( return i ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class SegmentTree : def _max(self,a,b): if aexists( _x | result = _x ); operation _max(a : OclAny,b : OclAny) : OclAny pre: true post: true activity: if (a->compareTo(b)) < 0 then ( return b ) else ( return a ); attribute N : int := 1; attribute seg : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (self.N * 2 - 1)); operation initialise(n : OclAny) : SegmentTree pre: true post: true activity: self.N := 1 ; while ((self.N->compareTo(n)) < 0) do ( self.N := self.N * 2) ; self.seg := MatrixLib.elementwiseMult(Sequence{ 0 }, (self.N * 2 - 1)); return self; operation max_update(k : OclAny,a : OclAny) pre: true post: true activity: k := k + self.N - 1 ; self.seg[k+1] := a ; while (0 < k) do ( k := (k - 1) div 2; ; self.seg[k+1] := self._max(self.seg[2 * k + 1+1], self.seg[2 * k + 2+1])); operation _max_query(a : OclAny,b : OclAny,k : OclAny,l : OclAny,r : OclAny) : OclAny pre: true post: true activity: if (r->compareTo(a)) <= 0 or (b->compareTo(l)) <= 0 then ( return 0 ) else skip ; if (a->compareTo(l)) <= 0 & (r->compareTo(b)) <= 0 then ( return self.seg[k+1] ) else ( var vl : OclAny := self._max_query(a, b, k * 2 + 1, l, (l + r) div 2) ; var vr : OclAny := self._max_query(a, b, k * 2 + 2, (l + r) div 2, r) ; return self._max(vl, vr) ); operation max_query(a : OclAny,b : OclAny) : OclAny pre: true post: true activity: return self._max_query(a, b, 0, 0, self.N); } class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var X : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var st : SegmentTree := (SegmentTree.newSegmentTree()).initialise(n + 1) ; for x : X do ( st.max_update(x, st.max_query(0, x) + x)) ; execute ((n * (n + 1)) div 2 - st.max_query(0, n + 1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) N,S=0,0 po=0 c="YES" for i in range(x): p=list(input().split()) if N==0 and S==0 : if p[1]!="South" : c="NO" break if S-N==20000 : if p[1]!="North" : c="NO" break if p[1]=="North" : po=po-int(p[0]) N+=int(p[0]) if po<0 : c="NO" break elif p[1]=="South" : S+=int(p[0]) po=po+int(p[0]) if po>20000 : c="N0" break if N==S : N,S=0,0 if N!=S : c="NO" print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var N : OclAny := null; var S : OclAny := null; Sequence{N,S} := Sequence{0,0} ; var po : int := 0 ; var c : String := "YES" ; for i : Integer.subrange(0, x-1) do ( var p : Sequence := (input().split()) ; if N = 0 & S = 0 then ( if p[1+1] /= "South" then ( c := "NO" ; break ) else skip ) else skip ; if S - N = 20000 then ( if p[1+1] /= "North" then ( c := "NO" ; break ) else skip ) else skip ; if p[1+1] = "North" then ( po := po - ("" + ((p->first())))->toInteger() ; N := N + ("" + ((p->first())))->toInteger() ; if po < 0 then ( c := "NO" ; break ) else skip ) else (if p[1+1] = "South" then ( S := S + ("" + ((p->first())))->toInteger() ; po := po + ("" + ((p->first())))->toInteger() ; if po > 20000 then ( c := "N0" ; break ) else skip ) else skip) ; if N = S then ( var N : OclAny := null; var S : OclAny := null; Sequence{N,S} := Sequence{0,0} ) else skip) ; if N /= S then ( c := "NO" ) else skip ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def angleOncirCumference(z): return(z/2); angle=65 ; z=angleOncirCumference(angle); print("The angle is",(z),"degrees"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var angle : int := 65; ; z := angleOncirCumference(angle); ; execute ("The angle is")->display();; operation angleOncirCumference(z : OclAny) pre: true post: true activity: return (z / 2);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSubarraysof1and0(a,n): count1=0 count0=0 number1=0 number0=0 for i in range(0,n,1): if(a[i]==1): count1+=1 else : number1+=((count1)*(count1+1)/2) count1=0 for i in range(0,n,1): if(a[i]==0): count0+=1 else : number0+=(count0)*(count0+1)/2 count0=0 if(count1): number1+=(count1)*(count1+1)/2 if(count0): number0+=(count0)*(count0+1)/2 print("Count of subarrays of 0 only:",int(number0)) print("Count of subarrays of 1 only:",int(number1)) if __name__=='__main__' : a=[1,1,0,0,1,0,1,0,1,1,1,1] n=len(a) countSubarraysof1and0(a,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))))))))))) ; n := (a)->size() ; countSubarraysof1and0(a, n) ) else skip; operation countSubarraysof1and0(a : OclAny, n : OclAny) pre: true post: true activity: var count1 : int := 0 ; var count0 : int := 0 ; var number1 : int := 0 ; var number0 : int := 0 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (a[i+1] = 1) then ( count1 := count1 + 1 ) else ( number1 := number1 + ((count1) * (count1 + 1) / 2) ; count1 := 0 )) ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (a[i+1] = 0) then ( count0 := count0 + 1 ) else ( number0 := number0 + (count0) * (count0 + 1) / 2 ; count0 := 0 )) ; if (count1) then ( number1 := number1 + (count1) * (count1 + 1) / 2 ) else skip ; if (count0) then ( number0 := number0 + (count0) * (count0 + 1) / 2 ) else skip ; execute ("Count of subarrays of 0 only:")->display() ; execute ("Count of subarrays of 1 only:")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) s=list(input()) l=0 c=0 for i in range(n): if s[i]==min(s): c+=1 l=max(l,c) else : c=0 s.reverse() if(2**(k-1))*l>n : print(min(s)*n) else : for i in range(min(k,13)): t=list(reversed(s)) u=t+s uu=u[: n] for j in range(1,n+1): x=u[j : j+n] if uu>x : uu=x s=uu print("".join(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var l : int := 0 ; var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = (s)->min() then ( c := c + 1 ; l := Set{l, c}->max() ) else ( c := 0 )) ; s := s->reverse() ; if (((2)->pow((k - 1))) * l->compareTo(n)) > 0 then ( execute ((s)->min() * n)->display() ) else ( for i : Integer.subrange(0, Set{k, 13}->min()-1) do ( var t : Sequence := ((s)->reverse()) ; var u : Sequence := t->union(s) ; var uu : OclAny := u.subrange(1,n) ; for j : Integer.subrange(1, n + 1-1) do ( var x : OclAny := u.subrange(j+1, j + n) ; if (uu->compareTo(x)) > 0 then ( uu := x ) else skip) ; s := uu) ; execute (StringLib.sumStringsWithSeparator((s), ""))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,k,s): u=s+s[: :-1] t=min(u[i : i+n]for i in range(n+1)) i,h=0,t[0] for i,c in enumerate(t): if c!=h : break j=i for _ in range(k-1): j<<=1 if j>=n : return h*n return h*j+t[i : i+n-j] n,k=map(int,input().split()) s=input() print(solve(n,k,s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; s := (OclFile["System.in"]).readLine() ; execute (solve(n, k, s))->display(); operation solve(n : OclAny, k : OclAny, s : OclAny) : OclAny pre: true post: true activity: var u : OclAny := s + s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var t : OclAny := ((argument (test (logical_test (comparison (expr (atom (name u)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))) : (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name n))))))))) ])))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) )))))))))->min() ; var i : OclAny := null; var h : OclAny := null; Sequence{i,h} := Sequence{0,t->first()} ; for _tuple : Integer.subrange(1, (t)->size())->collect( _indx | Sequence{_indx-1, (t)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if c /= h then ( break ) else skip) ; var j : OclAny := i ; for _anon : Integer.subrange(0, k - 1-1) do ( j := j * (2->pow(1)) ; if (j->compareTo(n)) >= 0 then ( return h * n ) else skip) ; return h * j + t.subrange(i+1, i + n - j); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- str=input() a=str.split("") n=(int)(a[0]) k=(int)(a[1]) str=input() before="" for ii in range(k-1): s=str+str[: :-1] s1=s[0 : n] for i in range(1,n+1): s2=s[i : n+i] if(s1>s2): s1=s2 str=s1[: :-1] if(before==str): break before=str s=str+str[: :-1] s1=s[0 : n] for i in range(1,n+1): s2=s[i : n+i] if(s1>s2): s1=s2 print(s1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var OclType["String"] : String := (OclFile["System.in"]).readLine() ; var a : String := ("" + (.split(""))) ; var n : OclAny := (OclType["int"])(a->first()) ; var k : OclAny := (OclType["int"])(a[1+1]) ; OclType["String"] := (OclFile["System.in"]).readLine() ; var before : String := "" ; for ii : Integer.subrange(0, k - 1-1) do ( var s : String := OclType["String"] + ("" + ((subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))) ; var s1 : OclAny := s.subrange(0+1, n) ; for i : Integer.subrange(1, n + 1-1) do ( var s2 : OclAny := s.subrange(i+1, n + i) ; if ((s1->compareTo(s2)) > 0) then ( s1 := s2 ) else skip) ; OclType["String"] := s1(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; if (before = OclType["String"]) then ( break ) else skip ; before := OclType["String"]) ; s := OclType["String"] + ("" + ((subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))) ; s1 := s.subrange(0+1, n) ; for i : Integer.subrange(1, n + 1-1) do ( s2 := s.subrange(i+1, n + i) ; if ((s1->compareTo(s2)) > 0) then ( s1 := s2 ) else skip) ; execute (s1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import floor,log inpl=lambda : list(map(int,input().split())) N,K=inpl() S=input() U=S+S[: :-1] Sp=sorted([U[i : i+N]for i in range(N+1)])[0] n=0 while Sp[n]==Sp[0]: n+=1 if K>int(floor(log(N/n)/log(2)))+1 : print(Sp[0]*N) else : m=n*(2**(K-1)) if m>=N : print(Sp[0]*N) else : print(Sp[0]*m+Sp[n : n+N-m]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var inpl : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := inpl->apply() ; var S : String := (OclFile["System.in"]).readLine() ; var U : String := S + S(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var Sp : OclAny := sorted(Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (U.subrange(i+1, i + N))))->first() ; var n : int := 0 ; while Sp[n+1] = Sp->first() do ( n := n + 1) ; if (K->compareTo(("" + ((floor(log(N / n) / log(2)))))->toInteger() + 1)) > 0 then ( execute (Sp->first() * N)->display() ) else ( var m : double := n * ((2)->pow((K - 1))) ; if (m->compareTo(N)) >= 0 then ( execute (Sp->first() * N)->display() ) else ( execute (Sp->first() * m + Sp.subrange(n+1, n + N - m))->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,input().split()) S=input() aaaa=False if K>=15 : aaaa=True elif 2**K>=N : aaaa=True if aaaa : print(min(S)*N) exit() def get_last_dict(s_str): U=s_str+s_str[: :-1] c=min(s_str) p=U.index(c) minindex=p p+=1 while p<=N : if U[p]==c : if check_normal_dict(U,minindex,p): minindex=p p+=1 return U[minindex : minindex+N] def check_normal_dict(u,pointer1,pointer2): for i in range(N): if u[pointer1+i]>u[pointer2+i]: return True elif u[pointer1+i]=N : print(S[0]*N) else : S=S[0]*(count*((2**(K-1))-1))+S print(S[0 : N]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : String := (OclFile["System.in"]).readLine() ; var aaaa : boolean := false ; if K >= 15 then ( aaaa := true ) else (if ((2)->pow(K)->compareTo(N)) >= 0 then ( aaaa := true ) else skip) ; if aaaa then ( execute ((S)->min() * N)->display() ; exit() ) else skip ; skip ; skip ; S := get_last_dict(S) ; if K = 1 then ( execute (S)->display() ) else ( var count : int := 0 ; for c : S->characters() do ( if c = S->first() then ( count := count + 1 ) else ( break )) ; if (count * ((2)->pow((K - 1)))->compareTo(N)) >= 0 then ( execute (S->first() * N)->display() ) else ( S := S->first() * (count * (((2)->pow((K - 1))) - 1)) + S ; execute (S.subrange(0+1, N))->display() ) ); operation get_last_dict(s_str : OclAny) : OclAny pre: true post: true activity: var U : OclAny := s_str + s_str(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var c : OclAny := (s_str)->min() ; var p : int := U->indexOf(c) - 1 ; var minindex : int := p ; p := p + 1 ; while (p->compareTo(N)) <= 0 do ( if U[p+1] = c then ( if check_normal_dict(U, minindex, p) then ( minindex := p ) else skip ) else skip ; p := p + 1) ; return U.subrange(minindex+1, minindex + N); operation check_normal_dict(u : OclAny, pointer1 : OclAny, pointer2 : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, N-1) do ( if (u[pointer1 + i+1]->compareTo(u[pointer2 + i+1])) > 0 then ( return true ) else (if (u[pointer1 + i+1]->compareTo(u[pointer2 + i+1])) < 0 then ( return false ) else skip)) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printNumbers(N): flag=1 x=N if(N>0): while(x>0 and flag==1): digit=x % 10 if(digit!=1 and digit!=3): flag=0 x=x//10 if(flag==1): print(N,end=" ") printNumbers(N-1) if __name__=='__main__' : N=20 printNumbers(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( N := 20 ; printNumbers(N) ) else skip; operation printNumbers(N : OclAny) pre: true post: true activity: var flag : int := 1 ; var x : OclAny := N ; if (N > 0) then ( while (x > 0 & flag = 1) do ( var digit : int := x mod 10 ; if (digit /= 1 & digit /= 3) then ( flag := 0 ) else skip ; x := x div 10) ; if (flag = 1) then ( execute (N)->display() ) else skip ; printNumbers(N - 1) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printPermutation(n,k): mx=n for i in range(1,k+1): print(mx,end=" ") mx-=1 for i in range(1,mx+1): print(i,end=" ") if __name__=="__main__" : N,K=5,3 if K>=N-1 : print("Not Possible") else : printPermutation(N,K) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := Sequence{5,3} ; if (K->compareTo(N - 1)) >= 0 then ( execute ("Not Possible")->display() ) else ( printPermutation(N, K) ) ) else skip; operation printPermutation(n : OclAny, k : OclAny) pre: true post: true activity: var mx : OclAny := n ; for i : Integer.subrange(1, k + 1-1) do ( execute (mx)->display() ; mx := mx - 1) ; for i : Integer.subrange(1, mx + 1-1) do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def task9(A,B,n): for X in range(-1000,1001): if A*(X**n)==B : return X return "No solution" [A,B,n]=input().split() print(task9(int(A),int(B),int(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{A}->union(Sequence{B}->union(Sequence{ n })) := input().split() ; execute (task9(("" + ((A)))->toInteger(), ("" + ((B)))->toInteger(), ("" + ((n)))->toInteger()))->display(); operation task9(A : OclAny, B : OclAny, n : OclAny) : OclAny pre: true post: true activity: for X : Integer.subrange(-1000, 1001-1) do ( if A * ((X)->pow(n)) = B then ( return X ) else skip) ; return "No solution"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys if sys.version[0]=='2' : range,input=xrange,raw_input class FenwickTree : def __init__(self,a_list,f,default): self.N=len(a_list) self.bit=a_list[:] self.f=f self.default=default for _ in range(self.N,1<=0 : ret=self.f(ret,self.bit[n]) n=(n &(n+1))-1 return ret N=int(input()) X=[int(x)for x in input().split()] dp=FenwickTree([0]*N,lambda x,y : max(x,y),0) for x,i in sorted((x,i)for i,x in enumerate(X)): dp.update(i,dp.query(i)+x) print(N*(N+1)//2-dp.query(N-1)) ------------------------------------------------------------ OCL File: --------- class FenwickTree { static operation newFenwickTree() : FenwickTree pre: true post: FenwickTree->exists( _x | result = _x ); attribute N : int := (a_list)->size(); attribute bit : Sequence := a_list; attribute f : OclAny := f; attribute default : OclAny := default; operation initialise(a_list : OclAny,f : OclAny,default : OclAny) : FenwickTree pre: true post: true activity: self.N := (a_list)->size() ; self.bit := a_list ; self.f := f ; self.default := default ; for _anon : Integer.subrange(self.N, 1 * (2->pow(("" + ((((self.N, 2)->log())->ceil())))->toInteger()))-1) do ((expr (atom (name self)) (trailer . (name bit)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name self)) (trailer . (name default)))))))) ))))) ; for i : Integer.subrange(0, self.N - 1-1) do ( self.bit[MathLib.bitwiseOr(i, (i + 1))+1] := self.f(self.bit[MathLib.bitwiseOr(i, (i + 1))+1], self.bit[i+1])); return self; operation update(i : OclAny,val : OclAny) pre: true post: true activity: while (i->compareTo(self.N)) < 0 do ( self.bit[i+1] := self.f(self.bit[i+1], val) ; i := i or i + 1); operation query(n : OclAny) : OclAny pre: true post: true activity: var ret : int := 0 ; while n >= 0 do ( ret := self.f(ret, self.bit[n+1]) ; n := (MathLib.bitwiseAnd(n, (n + 1))) - 1) ; return ret; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if (trailer . (name version) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) = '2' then ( var range : OclAny := null; var input : OclAny := null; Sequence{range,input} := Sequence{xrange,raw_input} ) else skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var X : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var dp : FenwickTree := (FenwickTree.newFenwickTree()).initialise(MatrixLib.elementwiseMult(Sequence{ 0 }, N), lambda x : OclAny, y : OclAny in (Set{x, y}->max()), 0) ; for _tuple : (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name x)))))) , (test (logical_test (comparison (expr (atom (name i))))))) )))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name X)))))))) ))))))))->sort() do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); execute ((i, dp.query(i) + x) <: dp)) ; execute (N * (N + 1) div 2 - dp.query(N - 1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[sum(map(int,input().split()))for i in range(n)] a=l[0] l.sort(reverse=True) print(l.index(a)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum())) ; var a : OclAny := l->first() ; l := l->sort() ; execute (l->indexOf(a) - 1 + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) steps=[] x,y=(0,0) for _ in range(n): s=input().split('') steps.append((int(s[0]),s[1])) result='' for s in steps : if(y==0 and s[1]!='South')or y>0 : result='NO' break if(y==-20000 and s[1]!='North')or y<-20000 : result='NO' break if s[0]>20000 and s[1]in['North','South']: result='NO' break if s[1]=='North' : y+=s[0] elif s[1]=='South' : y-=s[0] if result=='NO' : print('NO') elif y==0 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var steps : Sequence := Sequence{} ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{0, 0} ; for _anon : Integer.subrange(0, n-1) do ( var s : OclAny := input().split('') ; execute ((Sequence{("" + ((s->first())))->toInteger(), s[1+1]}) : steps)) ; var result : String := '' ; for s : steps do ( if (y = 0 & s[1+1] /= 'South') or y > 0 then ( result := 'NO' ; break ) else skip ; if (y = -20000 & s[1+1] /= 'North') or y < -20000 then ( result := 'NO' ; break ) else skip ; if s->first() > 20000 & (Sequence{'North'}->union(Sequence{ 'South' }))->includes(s[1+1]) then ( result := 'NO' ; break ) else skip ; if s[1+1] = 'North' then ( y := y + s->first() ) else (if s[1+1] = 'South' then ( y := y - s->first() ) else skip)) ; if result = 'NO' then ( execute ('NO')->display() ) else (if y = 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) S=[] for i in range(n): A=[int(i)for i in input().split()] S.append(sum(A)) if S[0]==max(S): print("1") exit() thomas=S[0] rank=1 S.sort(reverse=True) for i in S : if i==thomas : print(rank) break else : rank+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var A : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute (((A)->sum()) : S)) ; if S->first() = (S)->max() then ( execute ("1")->display() ; exit() ) else skip ; var thomas : OclAny := S->first() ; var rank : int := 1 ; S := S->sort() ; for i : S do ( if i = thomas then ( execute (rank)->display() ; break ) else ( rank := rank + 1 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a,b,c,d=map(int,input().split()) sum=a+b+c+d Rank=1 for i in range(n-1): ai,bi,ci,di=map(int,input().split()) sumi=ai+bi+ci+di if sumtoInteger() ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sum : OclAny := a + b + c + d ; var Rank : int := 1 ; for i : Integer.subrange(0, n - 1-1) do ( var ai : OclAny := null; var bi : OclAny := null; var ci : OclAny := null; var di : OclAny := null; Sequence{ai,bi,ci,di} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sumi : OclAny := ai + bi + ci + di ; if (sum->compareTo(sumi)) < 0 then ( Rank := Rank + 1 ) else skip) ; execute (Rank)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) q,w,e,d=map(int,input().split()) f=q+w+e+d x=[f] for i in range(n-1): a,b,c,d=map(int,input().split()) x.append(a+b+c+d) y=sorted(x)[: :-1] print((y.index(f))+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var q : OclAny := null; var w : OclAny := null; var e : OclAny := null; var d : OclAny := null; Sequence{q,w,e,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var f : OclAny := q + w + e + d ; var x : Sequence := Sequence{ f } ; for i : Integer.subrange(0, n - 1-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a + b + c + d) : x)) ; var y : OclAny := sorted(x)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; execute ((y->indexOf(f) - 1) + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) marks=[] for i in range(t): temp=[int(x)for x in input().split()] marks.append(temp) for i in range(t): marks[i]=sum(marks[i]) m=marks[0] marks.sort(reverse=True) print(marks.index(m)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var marks : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( var temp : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((temp) : marks)) ; for i : Integer.subrange(0, t-1) do ( marks[i+1] := (marks[i+1])->sum()) ; var m : OclAny := marks->first() ; marks := marks->sort() ; execute (marks->indexOf(m) - 1 + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def is_member(List,key): for i in range(0,len(List)): if key==List[i]: return True return False def overlap(List1,List2): for key in List1 : if is_member(List2,key): return True return False if __name__=='__main__' : s1='geeksforgeeks' s2='geeks' List1=list(s1) List2=list(s2) yes_or_no=str(overlap(List1,List2)) if(yes_or_no): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var s1 : String := 'geeksforgeeks' ; var s2 : String := 'geeks' ; List1 := (s1)->characters() ; List2 := (s2)->characters() ; var yes_or_no : String := ("" + ((overlap(List1, List2)))) ; if (yes_or_no) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation is_member(List : OclAny, key : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, (List)->size()-1) do ( if key = List[i+1] then ( return true ) else skip) ; return false; operation overlap(List1 : OclAny, List2 : OclAny) : OclAny pre: true post: true activity: for key : List1 do ( if is_member(List2, key) then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) i=1 while True : if i>t : break n,a,b,c,d=map(int,input().split()) if n*(a-b)>(c+d)or n*(a+b)<(c-d): print("No") else : print("Yes") i=i+1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 1 ; while true do ( if (i->compareTo(t)) > 0 then ( break ) else skip ; var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{n,a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (n * (a - b)->compareTo((c + d))) > 0 or (n * (a + b)->compareTo((c - d))) < 0 then ( execute ("No")->display() ) else ( execute ("Yes")->display() ) ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(n,a,b,c,d): if n*(a+b)>=(c-d)and n*(a-b)<=(c+d): print("yes") else : print("no") t=int(input()) ln=[] la=[] lb=[] lc=[] ld=[] for i in range(t): n,a,b,c,d=map(int,input().split()) ln.append(n) la.append(a) lb.append(b) lc.append(c) ld.append(d) for i in range(len(ln)): check(ln[i],la[i],lb[i],lc[i],ld[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ln : Sequence := Sequence{} ; var la : Sequence := Sequence{} ; var lb : Sequence := Sequence{} ; var lc : Sequence := Sequence{} ; var ld : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( Sequence{n,a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((n) : ln) ; execute ((a) : la) ; execute ((b) : lb) ; execute ((c) : lc) ; execute ((d) : ld)) ; for i : Integer.subrange(0, (ln)->size()-1) do ( check(ln[i+1], la[i+1], lb[i+1], lc[i+1], ld[i+1])); operation check(n : OclAny, a : OclAny, b : OclAny, c : OclAny, d : OclAny) pre: true post: true activity: if (n * (a + b)->compareTo((c - d))) >= 0 & (n * (a - b)->compareTo((c + d))) <= 0 then ( execute ("yes")->display() ) else ( execute ("no")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for j in range(t): n,a,b,c,d=[int(i)for i in input().split()] if(a+b)*n>=c-d and(a-b)*n<=c+d : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, t-1) do ( var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{n,a,b,c,d} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if ((a + b) * n->compareTo(c - d)) >= 0 & ((a - b) * n->compareTo(c + d)) <= 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math class RangeMaximumQuery : def __init__(self,N,zero=0): self.N=1<0 : i=(i-1)//2 self.segtree[i]=max(self.segtree[2*i+1],self.segtree[2*i+2]) def query(self,low,high,k=0,left=0,right=-1): if right==-1 : right=self.N if right<=low or high<=left : return self.zero if low<=left and right<=high : return self.segtree[k] else : mid=(left+right)//2 return max(self.query(low,high,2*k+1,left,mid),self.query(low,high,2*k+2,mid,right)) N=int(input()) X=[int(x)for x in input().split()] dp=RangeMaximumQuery(N) for x,i in sorted((x,i)for i,x in enumerate(X)): dp.update(i,dp.query(0,i)+x) print(N*(N+1)//2-dp.query(0,N)) ------------------------------------------------------------ OCL File: --------- class RangeMaximumQuery { static operation newRangeMaximumQuery() : RangeMaximumQuery pre: true post: RangeMaximumQuery->exists( _x | result = _x ); attribute N : int := 1 * (2->pow(((N, 2)->log())->ceil())); attribute zero : int := zero; attribute segtree : Sequence := MatrixLib.elementwiseMult(Sequence{ self.zero }, (self.N * 2 - 1)); operation initialise(N : OclAny,zero : int) : RangeMaximumQuery pre: true post: true activity: self.N := 1 * (2->pow(((N, 2)->log())->ceil())) ; self.zero := zero ; self.segtree := MatrixLib.elementwiseMult(Sequence{ self.zero }, (self.N * 2 - 1)); return self; operation update(i : OclAny,val : OclAny) pre: true post: true activity: i := i + self.N - 1 ; self.segtree[i+1] := val ; while i > 0 do ( i := (i - 1) div 2 ; self.segtree[i+1] := Set{self.segtree[2 * i + 1+1], self.segtree[2 * i + 2+1]}->max()); operation query(low : OclAny,high : OclAny,k : int,left : int,right : int) : OclAny pre: true post: true activity: if right = -1 then ( right := self.N ) else skip ; if (right->compareTo(low)) <= 0 or (high->compareTo(left)) <= 0 then ( return self.zero ) else skip ; if (low->compareTo(left)) <= 0 & (right->compareTo(high)) <= 0 then ( return self.segtree[k+1] ) else ( var mid : int := (left + right) div 2 ; return Set{self.query(low, high, 2 * k + 1, left, mid), self.query(low, high, 2 * k + 2, mid, right)}->max() ); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var X : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var dp : RangeMaximumQuery := (RangeMaximumQuery.newRangeMaximumQuery()).initialise(N) ; for _tuple : (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name x)))))) , (test (logical_test (comparison (expr (atom (name i))))))) )))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name X)))))))) ))))))))->sort() do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); execute ((i, dp.query(0, i) + x) <: dp)) ; execute (N * (N + 1) div 2 - dp.query(0, N))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,a,b,c,d=map(int,input().split()) print("YES" if(n*(a-b)<=(c+d)and n*(a+b)>=(c-d))else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{n,a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if ((n * (a - b)->compareTo((c + d))) <= 0 & (n * (a + b)->compareTo((c - d))) >= 0) then "YES" else "NO" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,a,b,c,d=list(map(int,input().split())) l1,r1,l2,r2=n*(a-b),n*(a+b),c-d,c+d if r1toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{n,a,b,c,d} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l1 : OclAny := null; var r1 : OclAny := null; var l2 : OclAny := null; var r2 : OclAny := null; Sequence{l1,r1,l2,r2} := Sequence{n * (a - b),n * (a + b),c - d,c + d} ; if (r1->compareTo(l2)) < 0 or (r2->compareTo(l1)) < 0 then ( execute ("No")->display() ) else ( execute ("Yes")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) is_south,is_north=False,True position=0 for _ in range(n): distance,direction=input().split() if is_south and direction!="North" : return "NO" if is_north and direction!="South" : return "NO" if direction=="North" and position<=20000 : position-=int(distance) if position<0 : return "NO" elif direction=="North" and position>20000 : position+=int(distance) if position>40000 : return "NO" elif direction=="South" and position<20000 : position+=int(distance) if position>20000 : return "NO" elif direction=="South" : position-=int(distance) if position<20000 : return "NO" position=(position+40000*100)% 40000 if position==0 : is_north,is_south=True,False elif position==20000 : is_north,is_south=False,True else : is_north=is_south=False return "YES" if position==0 else "NO" print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (solve())->display(); operation solve() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var is_south : OclAny := null; var is_north : OclAny := null; Sequence{is_south,is_north} := Sequence{false,true} ; var position : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var distance : OclAny := null; var direction : OclAny := null; Sequence{distance,direction} := input().split() ; if is_south & direction /= "North" then ( return "NO" ) else skip ; if is_north & direction /= "South" then ( return "NO" ) else skip ; if direction = "North" & position <= 20000 then ( position := position - ("" + ((distance)))->toInteger() ; if position < 0 then ( return "NO" ) else skip ) else (if direction = "North" & position > 20000 then ( position := position + ("" + ((distance)))->toInteger() ; if position > 40000 then ( return "NO" ) else skip ) else (if direction = "South" & position < 20000 then ( position := position + ("" + ((distance)))->toInteger() ; if position > 20000 then ( return "NO" ) else skip ) else (if direction = "South" then ( position := position - ("" + ((distance)))->toInteger() ; if position < 20000 then ( return "NO" ) else skip ) else skip ) ) ) ; position := (position + 40000 * 100) mod 40000 ; if position = 0 then ( var is_north : OclAny := null; var is_south : OclAny := null; Sequence{is_north,is_south} := Sequence{true,false} ) else (if position = 20000 then ( var is_north : OclAny := null; var is_south : OclAny := null; Sequence{is_north,is_south} := Sequence{false,true} ) else ( var is_north : OclAny := false; var is_south : boolean := false ) ) ) ; return if position = 0 then "YES" else "NO" endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findElements(arr,n): for i in range(n): count=0 for j in range(0,n): if arr[j]>arr[i]: count=count+1 if count>=2 : print(arr[i],end=" ") arr=[2,-6,3,5,1] n=len(arr) findElements(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{-6}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 1 })))) ; n := (arr)->size() ; findElements(arr, n); operation findElements(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( var count : int := 0 ; for j : Integer.subrange(0, n-1) do ( if (arr[j+1]->compareTo(arr[i+1])) > 0 then ( count := count + 1 ) else skip) ; if count >= 2 then ( execute (arr[i+1])->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=3 def maxPathSum(tri,m,n): for i in range(m-1,-1,-1): for j in range(i+1): if(tri[i+1][j]>tri[i+1][j+1]): tri[i][j]+=tri[i+1][j] else : tri[i][j]+=tri[i+1][j+1] return tri[0][0] tri=[[1,0,0],[4,8,0],[1,5,3]] print(maxPathSum(tri,2,2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 3 ; skip ; tri := Sequence{Sequence{1}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{Sequence{4}->union(Sequence{8}->union(Sequence{ 0 }))}->union(Sequence{ Sequence{1}->union(Sequence{5}->union(Sequence{ 3 })) })) ; execute (maxPathSum(tri, 2, 2))->display(); operation maxPathSum(tri : OclAny, m : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(-1 + 1, m - 1)->reverse() do ( for j : Integer.subrange(0, i + 1-1) do ( if ((tri[i + 1+1][j+1]->compareTo(tri[i + 1+1][j + 1+1])) > 0) then ( tri[i+1][j+1] := tri[i+1][j+1] + tri[i + 1+1][j+1] ) else ( tri[i+1][j+1] := tri[i+1][j+1] + tri[i + 1+1][j + 1+1] ))) ; return tri->first()->first(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isHeap(arr,n): for i in range(int((n-2)/2)+1): if arr[2*i+1]>arr[i]: return False if(2*i+2arr[i]): return False return True if __name__=='__main__' : arr=[90,15,10,7,12,2,7,3] n=len(arr) if isHeap(arr,n): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{90}->union(Sequence{15}->union(Sequence{10}->union(Sequence{7}->union(Sequence{12}->union(Sequence{2}->union(Sequence{7}->union(Sequence{ 3 }))))))) ; n := (arr)->size() ; if isHeap(arr, n) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isHeap(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, ("" + (((n - 2) / 2)))->toInteger() + 1-1) do ( if (arr[2 * i + 1+1]->compareTo(arr[i+1])) > 0 then ( return false ) else skip ; if ((2 * i + 2->compareTo(n)) < 0 & (arr[2 * i + 2+1]->compareTo(arr[i+1])) > 0) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isHeap(arr,i,n): if i>int((n-2)/2): return True if(arr[i]>=arr[2*i+1]and arr[i]>=arr[2*i+2]and isHeap(arr,2*i+1,n)and isHeap(arr,2*i+2,n)): return True return False if __name__=='__main__' : arr=[90,15,10,7,12,2,7,3] n=len(arr)-1 if isHeap(arr,0,n): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{90}->union(Sequence{15}->union(Sequence{10}->union(Sequence{7}->union(Sequence{12}->union(Sequence{2}->union(Sequence{7}->union(Sequence{ 3 }))))))) ; n := (arr)->size() - 1 ; if isHeap(arr, 0, n) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isHeap(arr : OclAny, i : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (i->compareTo(("" + (((n - 2) / 2)))->toInteger())) > 0 then ( return true ) else skip ; if ((arr[i+1]->compareTo(arr[2 * i + 1+1])) >= 0 & (arr[i+1]->compareTo(arr[2 * i + 2+1])) >= 0 & isHeap(arr, 2 * i + 1, n) & isHeap(arr, 2 * i + 2, n)) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque H,W=[int(i)for i in input().split()] A=[list(input())for _ in range(H)] Q=deque([(i,j,0)for i in range(H)for j in range(W)if A[i][j]=="#"]) ans=0 while Q : i,j,dist=Q.popleft() ans=max(ans,dist) for di,dj in[(1,0),(0,1),(-1,0),(0,-1)]: ni,nj=i+di,j+dj if 0<=niselect(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var A : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (((OclFile["System.in"]).readLine())->characters())) ; var Q : Sequence := (Integer.subrange(0, H-1)->select(i; j : Integer.subrange(0, W-1) | true)->collect(i; j : Integer.subrange(0, W-1) | (Sequence{i, j, 0}))) ; var ans : int := 0 ; while Q do ( var i : OclAny := null; var j : OclAny := null; var dist : OclAny := null; Sequence{i,j,dist} := Q->first() ; Q := Q->tail() ; ans := Set{ans, dist}->max() ; for _tuple : Sequence{Sequence{1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{-1, 0}}->union(Sequence{ Sequence{0, -1} }))) do (var _indx : int := 1; var di : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dj : OclAny := _tuple->at(_indx); var ni : OclAny := null; var nj : OclAny := null; Sequence{ni,nj} := Sequence{i + di,j + dj} ; if 0 <= ni & (ni < H) & 0 <= nj & (nj < W) & A[ni+1][nj+1] = "." then ( A[ni+1][nj+1] := "#" ; execute ((Sequence{ni, nj, dist + 1}) : Q) ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np h,w=map(int,input().split()) graph=[[0 if i=='#' else float('inf')for i in list(input())]for _ in range(h)] graph=np.array(graph) for x in range(w-1): graph[:,x+1]=np.minimum(graph[:,x]+1,graph[:,x+1]) for x in range(w-1,0,-1): graph[:,x-1]=np.minimum(graph[:,x]+1,graph[:,x-1]) for y in range(h-1): graph[y+1,:]=np.minimum(graph[y,:]+1,graph[y+1,:]) for y in range(h-1,0,-1): graph[y-1,:]=np.minimum(graph[y,:]+1,graph[y-1,:]) print(int(np.max(graph))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var graph : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (((OclFile["System.in"]).readLine())->characters()->select(i | true)->collect(i | (if i = '#' then 0 else ("" + (('inf')))->toReal() endif)))) ; graph := (graph) ; for x : Integer.subrange(0, w - 1-1) do ( graph->collect( _r | _r[x + 1+1] ) := ) ; for x : Integer.subrange(0 + 1, w - 1)->reverse() do ( graph->collect( _r | _r[x - 1+1] ) := ) ; for y : Integer.subrange(0, h - 1-1) do ( graph[y + 1+1] := ) ; for y : Integer.subrange(0 + 1, h - 1)->reverse() do ( graph[y - 1+1] := ) ; execute (("" + (()))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np def parse(): H,W=map(int,input().split("")) grid=[list(input())for y in range(H)] return H,W,grid def print_grid(grid): H=len(grid) print("grid:") for line in grid : for c in line : print(c,end="") print("") def main(): H,W,grid=parse() visited=np.zeros((H,W),int) for y in range(H): for x in range(W): if grid[y][x]=="." : visited[y][x]=H*W for y in range(1,H): visited[y][:]=np.minimum(visited[y][:],visited[y-1][:]+1) for y in range(H-2,-1,-1): visited[y,:]=np.minimum(visited[y,:],visited[y+1][:]+1) for x in range(1,W): visited[:,x]=np.minimum(visited[:,x],visited[:,x-1]+1) for x in range(W-2,-1,-1): visited[:,x]=np.minimum(visited[:,x],visited[:,x+1]+1) print(np.max(visited)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation parse() : OclAny pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split(""))->collect( _x | (OclType["int"])->apply(_x) ) ; var grid : Sequence := Integer.subrange(0, H-1)->select(y | true)->collect(y | (((OclFile["System.in"]).readLine())->characters())) ; return H, W, grid; operation print_grid(grid : OclAny) pre: true post: true activity: var H : int := (grid)->size() ; execute ("grid:")->display() ; for line : grid do ( for c : line do ( execute (c)->display()) ; execute ("")->display()); operation main() pre: true post: true activity: var W : OclAny := null; Sequence{H,W,grid} := parse() ; var visited : Sequence := MatrixLib.singleValueMatrix(Sequence{H, W}, 0.0) ; for y : Integer.subrange(0, H-1) do ( for x : Integer.subrange(0, W-1) do ( if grid[y+1][x+1] = "." then ( visited[y+1][x+1] := H * W ) else skip)) ; for y : Integer.subrange(1, H-1) do ( visited[y+1] := ) ; for y : Integer.subrange(-1 + 1, H - 2)->reverse() do ( visited[y+1] := ) ; for x : Integer.subrange(1, W-1) do ( visited->collect( _r | _r[x+1] ) := ) ; for x : Integer.subrange(-1 + 1, W - 2)->reverse() do ( visited->collect( _r | _r[x+1] ) := ) ; execute ()->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) dp=[0]*(n+1) def update(i,x): while i<=n : if dp[i]0 : t=dp[i] if stoInteger() ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; skip ; skip ; var A : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for a_i : A do ( update(a_i, get_sum(a_i - 1) + a_i)) ; var ans : double := n * (n + 1) div 2 - get_sum(n) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sol(): h,w=map(int,input().split()) l=[] d=set() for i in range(h): s=list(input()) for j in range(w): if s[j]=="#" : d.add((i,j)) l.append(s) ans=-1 for i in range(2000): if len(d)==0 : break ans+=1 t=set() for j in d : if 0<=j[0]+1collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := Sequence{} ; var d : Set := Set{}->union(()) ; for i : Integer.subrange(0, h-1) do ( var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; for j : Integer.subrange(0, w-1) do ( if s[j+1] = "#" then ( execute ((Sequence{i, j}) : d) ) else skip) ; execute ((s) : l)) ; var ans : int := -1 ; for i : Integer.subrange(0, 2000-1) do ( if (d)->size() = 0 then ( break ) else skip ; ans := ans + 1 ; var t : Set := Set{}->union(()) ; for j : d do ( if 0 <= j->first() + 1 & (j->first() + 1 < h) & l[j->first() + 1+1][j[1+1]+1] = "." then ( l[j->first() + 1+1][j[1+1]+1] := "#" ; execute ((Sequence{j->first() + 1, j[1+1]}) : t) ) else skip ; if 0 <= j->first() - 1 & (j->first() - 1 < h) & l[j->first() - 1+1][j[1+1]+1] = "." then ( l[j->first() - 1+1][j[1+1]+1] := "#" ; execute ((Sequence{j->first() - 1, j[1+1]}) : t) ) else skip ; if 0 <= j[1+1] + 1 & (j[1+1] + 1 < w) & l[j->first()+1][j[1+1] + 1+1] = "." then ( l[j->first()+1][j[1+1] + 1+1] := "#" ; execute ((Sequence{j->first(), j[1+1] + 1}) : t) ) else skip ; if 0 <= j[1+1] - 1 & (j[1+1] - 1 < w) & l[j->first()+1][j[1+1] - 1+1] = "." then ( l[j->first()+1][j[1+1] - 1+1] := "#" ; execute ((Sequence{j->first(), j[1+1] - 1}) : t) ) else skip) ; d := t) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import copy import heapq import math import sys from collections import* from itertools import accumulate,combinations,permutations,product def main(): def input(): return sys.stdin.readline()[:-1] def ruiseki(lst): return[0]+list(accumulate(lst)) mod=pow(10,9)+7 al=[chr(ord('a')+i)for i in range(26)] direction=[[1,0],[0,1],[-1,0],[0,-1]] h,w=map(int,input().split()) a=[input()for i in range(h)] cnt=0 itta=[[10**9]*w for i in range(h)] d=deque() for i in range(h): for j in range(w): if a[i][j]=="#" : d.append((i,j)) itta[i][j]=0 while d : cnt+=1 for l in range(len(d)): nh,nw=d.popleft() for i in range(4): d1,d2=direction[i] if 0<=nh+d1pow(9) + 7 ; var al : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | ((('a')->char2byte() + i)->byte2char())) ; var direction : Sequence := Sequence{Sequence{1}->union(Sequence{ 0 })}->union(Sequence{Sequence{0}->union(Sequence{ 1 })}->union(Sequence{Sequence{-1}->union(Sequence{ 0 })}->union(Sequence{ Sequence{0}->union(Sequence{ -1 }) }))) ; var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, h-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var cnt : int := 0 ; var itta : Sequence := Integer.subrange(0, h-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ (10)->pow(9) }, w))) ; var d : Sequence := () ; for i : Integer.subrange(0, h-1) do ( for j : Integer.subrange(0, w-1) do ( if a[i+1][j+1] = "#" then ( execute ((Sequence{i, j}) : d) ; itta[i+1][j+1] := 0 ) else skip)) ; while d do ( cnt := cnt + 1 ; for l : Integer.subrange(0, (d)->size()-1) do ( var nh : OclAny := null; var nw : OclAny := null; Sequence{nh,nw} := d->first() ; d := d->tail() ; for i : Integer.subrange(0, 4-1) do ( var d1 : OclAny := null; var d2 : OclAny := null; Sequence{d1,d2} := direction[i+1] ; if 0 <= nh + d1 & (nh + d1 < h) & 0 <= nw + d2 & (nw + d2 < w) then ( if itta[nh + d1+1][nw + d2+1] = (10)->pow(9) then ( itta[nh + d1+1][nw + d2+1] := cnt ; execute ((Sequence{nh + d1, nw + d2}) : d) ) else skip ) else skip))) ; execute (cnt - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- V=list(map(int,input().split())) P=[] for i in range(3): P.append((V[0],V[1])) V=V[2 :] A,B,C=P for i in range(1,3): x,y=P[i] x0,y0=P[0] P[i]=x-x0,y-y0 a,b=P[1] c,d=P[2] if a*d-b*c==0 : print("NO") exit(0) def dist(A,B): x=A[0]-B[0] y=A[1]-B[1] return x**2+y**2 print("YES" if dist(A,B)==dist(B,C)else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var V : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var P : Sequence := Sequence{} ; for i : Integer.subrange(0, 3-1) do ( execute ((Sequence{V->first(), V[1+1]}) : P) ; V := V.subrange(2+1)) ; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{A,B,C} := P ; for i : Integer.subrange(1, 3-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := P[i+1] ; var x0 : OclAny := null; var y0 : OclAny := null; Sequence{x0,y0} := P->first() ; P[i+1] := x - x0,y - y0) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := P[1+1] ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := P[2+1] ; if a * d - b * c = 0 then ( execute ("NO")->display() ; exit(0) ) else skip ; skip ; execute (if dist(A, B) = dist(B, C) then "YES" else "NO" endif)->display(); operation dist(A : OclAny, B : OclAny) : OclAny pre: true post: true activity: var x : double := A->first() - B->first() ; var y : double := A[1+1] - B[1+1] ; return (x)->pow(2) + (y)->pow(2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def multiply(num1,num2): len1=len(num1) len2=len(num2) if len1==0 or len2==0 : return "0" result=[0]*(len1+len2) i_n1=0 i_n2=0 for i in range(len1-1,-1,-1): carry=0 n1=ord(num1[i])-48 i_n2=0 for j in range(len2-1,-1,-1): n2=ord(num2[j])-48 summ=n1*n2+result[i_n1+i_n2]+carry carry=summ//10 result[i_n1+i_n2]=summ % 10 i_n2+=1 if(carry>0): result[i_n1+i_n2]+=carry i_n1+=1 i=len(result)-1 while(i>=0 and result[i]==0): i-=1 if(i==-1): return "0" s="" while(i>=0): s+=chr(result[i]+48) i-=1 return s str1="1235421415454545454545454544" str2="1714546546546545454544548544544545" if((str1[0]=='-' or str2[0]=='-')and(str1[0]!='-' or str2[0]!='-')): print("-",end='') if(str1[0]=='-' and str2[0]!='-'): str1=str1[1 :] elif(str1[0]!='-' and str2[0]=='-'): str2=str2[1 :] elif(str1[0]=='-' and str2[0]=='-'): str1=str1[1 :] str2=str2[1 :] print(multiply(str1,str2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var str1 : String := "1235421415454545454545454544" ; var str2 : String := "1714546546546545454544548544544545" ; if ((str1->first() = '-' or str2->first() = '-') & (str1->first() /= '-' or str2->first() /= '-')) then ( execute ("-")->display() ) else skip ; if (str1->first() = '-' & str2->first() /= '-') then ( str1 := str1->tail() ) else (if (str1->first() /= '-' & str2->first() = '-') then ( str2 := str2->tail() ) else (if (str1->first() = '-' & str2->first() = '-') then ( str1 := str1->tail() ; str2 := str2->tail() ) else skip ) ) ; execute (multiply(str1, str2))->display(); operation multiply(num1 : OclAny, num2 : OclAny) : OclAny pre: true post: true activity: var len1 : int := (num1)->size() ; var len2 : int := (num2)->size() ; if len1 = 0 or len2 = 0 then ( return "0" ) else skip ; var result : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (len1 + len2)) ; var i_n1 : int := 0 ; var i_n2 : int := 0 ; for i : Integer.subrange(-1 + 1, len1 - 1)->reverse() do ( var carry : int := 0 ; var n1 : double := (num1[i+1])->char2byte() - 48 ; i_n2 := 0 ; for j : Integer.subrange(-1 + 1, len2 - 1)->reverse() do ( var n2 : double := (num2[j+1])->char2byte() - 48 ; var summ : double := n1 * n2 + result[i_n1 + i_n2+1] + carry ; carry := summ div 10 ; result[i_n1 + i_n2+1] := summ mod 10 ; i_n2 := i_n2 + 1) ; if (carry > 0) then ( result[i_n1 + i_n2+1] := result[i_n1 + i_n2+1] + carry ) else skip ; i_n1 := i_n1 + 1) ; var i : double := (result)->size() - 1 ; while (i >= 0 & result[i+1] = 0) do ( i := i - 1) ; if (i = -1) then ( return "0" ) else skip ; var s : String := "" ; while (i >= 0) do ( s := s + (result[i+1] + 48)->byte2char() ; i := i - 1) ; return s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans=0 for i in range(int(input())): t,d=input().split() k=(d[0]=='S')-(d[0]=='N') if ans % 20000==k==0 : ans=1 break ans+=k*int(t) if ans<0 or ans>20000 : break print('NO' if ans else 'YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var t : OclAny := null; var d : OclAny := null; Sequence{t,d} := input().split() ; var k : double := (d->first() = 'S') - (d->first() = 'N') ; if ans mod 20000 = k & (k == 0) then ( ans := 1 ; break ) else skip ; ans := ans + k * ("" + ((t)))->toInteger() ; if ans < 0 or ans > 20000 then ( break ) else skip) ; execute (if ans then 'NO' else 'YES' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): x1,y1,x2,y2,x3,y3=map(int,input().split()); a=[x1,y1]; b=[x2,y2]; c=[x3,y3]; if(x1-x2>=0): angular1=(y1-y2)/((x1-x2)+0.000001); elif(x1-x2<0): angular1=(y1-y2)/((x1-x2)-0.000001); if(x2-x3>=0): angular2=(y2-y3)/((x2-x3)+0.000001); elif(x2-x3<0): angular2=(y2-y3)/((x2-x3)-0.000001); res=False ; alinhado=False ; if angular1==angular2 : alinhado=True ; dAB=(a[0]-b[0])**2+(a[1]-b[1])**2 dAC=(a[0]-c[0])**2+(a[1]-c[1])**2 dBC=(c[0]-b[0])**2+(c[1]-b[1])**2 if(dAB==dBC): res=True ; if(res and not alinhado): print("Yes") else : print("No") solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; var x3 : OclAny := null; var y3 : OclAny := null; Sequence{x1,y1,x2,y2,x3,y3} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); ; var a : Sequence := Sequence{x1}->union(Sequence{ y1 }); ; var b : Sequence := Sequence{x2}->union(Sequence{ y2 }); ; var c : Sequence := Sequence{x3}->union(Sequence{ y3 }); ; if (x1 - x2 >= 0) then ( var angular1 : double := (y1 - y2) / ((x1 - x2) + 0.000001); ) else (if (x1 - x2 < 0) then ( angular1 := (y1 - y2) / ((x1 - x2) - 0.000001); ) else skip) ; if (x2 - x3 >= 0) then ( var angular2 : double := (y2 - y3) / ((x2 - x3) + 0.000001); ) else (if (x2 - x3 < 0) then ( angular2 := (y2 - y3) / ((x2 - x3) - 0.000001); ) else skip) ; var res : boolean := false; ; var alinhado : boolean := false; ; if angular1 = angular2 then ( alinhado := true; ) else skip ; var dAB : double := ((a->first() - b->first()))->pow(2) + ((a[1+1] - b[1+1]))->pow(2) ; var dAC : double := ((a->first() - c->first()))->pow(2) + ((a[1+1] - c[1+1]))->pow(2) ; var dBC : double := ((c->first() - b->first()))->pow(2) + ((c[1+1] - b[1+1]))->pow(2) ; if (dAB = dBC) then ( res := true; ) else skip ; if (res & not(alinhado)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=1000000007 ii=lambda : int(input()) si=lambda : input() dgl=lambda : list(map(int,input())) f=lambda : map(int,input().split()) il=lambda : list(map(int,input().split())) ls=lambda : list(input()) ax,ay,bx,by,cx,cy=f() if(ax-bx)**2+(ay-by)**2==(bx-cx)**2+(by-cy)**2 : if(by-ay)*(cx-bx)==(cy-by)*(bx-ax): print('No') else : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : int := 1000000007 ; var ii : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var si : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var dgl : Function := lambda $$ : OclAny in ((((OclFile["System.in"]).readLine())->collect( _x | (OclType["int"])->apply(_x) ))) ; var f : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var il : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ls : Function := lambda $$ : OclAny in (((OclFile["System.in"]).readLine())->characters()) ; var ax : OclAny := null; var ay : OclAny := null; var bx : OclAny := null; var by : OclAny := null; var cx : OclAny := null; var cy : OclAny := null; Sequence{ax,ay,bx,by,cx,cy} := f->apply() ; if ((ax - bx))->pow(2) + ((ay - by))->pow(2) = ((bx - cx))->pow(2) + ((by - cy))->pow(2) then ( if (by - ay) * (cx - bx) = (cy - by) * (bx - ax) then ( execute ('No')->display() ) else ( execute ('Yes')->display() ) ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ax,ay,bx,by,cx,cy=input().split() ax,ay,bx,by,cx,cy=int(ax),int(ay),int(bx),int(by),int(cx),int(cy) distant_1=(ax-bx)**2+(ay-by)**2 distant_2=(bx-cx)**2+(by-cy)**2 abx=bx-ax aby=by-ay bcx=cx-bx bcy=cy-by if distant_1!=distant_2 : print('No') if distant_1==distant_2 : if abx*bcy==aby*bcx : print('No') else : print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ax : OclAny := null; var ay : OclAny := null; var bx : OclAny := null; var by : OclAny := null; var cx : OclAny := null; var cy : OclAny := null; Sequence{ax,ay,bx,by,cx,cy} := input().split() ; var ax : OclAny := null; var ay : OclAny := null; var bx : OclAny := null; var by : OclAny := null; var cx : OclAny := null; var cy : OclAny := null; Sequence{ax,ay,bx,by,cx,cy} := Sequence{("" + ((ax)))->toInteger(),("" + ((ay)))->toInteger(),("" + ((bx)))->toInteger(),("" + ((by)))->toInteger(),("" + ((cx)))->toInteger(),("" + ((cy)))->toInteger()} ; var distant var ax : OclAny := null; var ay : OclAny := null; var bx : OclAny := null; var by : OclAny := null; var cx : OclAny := null; var cy : OclAny := null; Sequence{ax,ay,bx,by,cx,cy} := input().split() : double := ((ax - bx))->pow(2) + ((ay - by))->pow(2) ; var distant:= ((bx - cx))->pow(2) + ((by - cy))->pow(2) : double := ((bx - cx))->pow(2) + ((by - cy))->pow(2) ; var abx : double := bx - ax ; var aby : double := by - ay ; var bcx : double := cx - bx ; var bcy : double := cy - by ; if distant var ax : OclAny := null; var ay : OclAny := null; var bx : OclAny := null; var by : OclAny := null; var cx : OclAny := null; var cy : OclAny := null; Sequence{ax,ay,bx,by,cx,cy} := input().split() /= distant execute ('No')->display() then ( execute ('No')->display() ) else skip ; if distant var ax : OclAny := null; var ay : OclAny := null; var bx : OclAny := null; var by : OclAny := null; var cx : OclAny := null; var cy : OclAny := null; Sequence{ax,ay,bx,by,cx,cy} := input().split() = distant if abx * bcy = aby * bcx then ( execute ('No')->display() ) else ( execute ('Yes')->display() ) then ( if abx * bcy = aby * bcx then ( execute ('No')->display() ) else ( execute ('Yes')->display() ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def findMinDel(arr,n): min_num=sys.maxsize ; for i in range(n): min_num=min(arr[i],min_num); cnt=0 ; for i in range(n): if(arr[i]==min_num): cnt+=1 ; return n-cnt ; if __name__=="__main__" : arr=[3,3,2]; n=len(arr); print(findMinDel(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{3}->union(Sequence{3}->union(Sequence{ 2 })); ; n := (arr)->size(); ; execute (findMinDel(arr, n))->display(); ) else skip; operation findMinDel(arr : OclAny, n : OclAny) pre: true post: true activity: var min_num : (trailer . (name maxsize)) := (trailer . (name maxsize)); ; for i : Integer.subrange(0, n-1) do ( min_num := Set{arr[i+1], min_num}->min();) ; var cnt : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] = min_num) then ( cnt := cnt + 1; ) else skip) ; return n - cnt;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count(x,y): ans=0 m=dict() while x % y!=0 : x %=y ans+=1 if x in m : return-1 m[x]=1 x*=10 return ans if __name__=="__main__" : res=count(1,2) print("INF")if res==-1 else print(res) res=count(5,3) print("INF")if res==-1 else print(res) res=count(3,5) print("INF")if res==-1 else print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var res : OclAny := count(1, 2) ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "INF"))))))) )))))) if (logical_test (comparison (comparison (expr (atom (name res)))) == (comparison (expr (atom - (number (integer 1))))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name res)))))))) )))))))) ; res := count(5, 3) ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "INF"))))))) )))))) if (logical_test (comparison (comparison (expr (atom (name res)))) == (comparison (expr (atom - (number (integer 1))))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name res)))))))) )))))))) ; res := count(3, 5) ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "INF"))))))) )))))) if (logical_test (comparison (comparison (expr (atom (name res)))) == (comparison (expr (atom - (number (integer 1))))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name res)))))))) )))))))) ) else skip; operation count(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; var m : Map := (arguments ( )) ; while x mod y /= 0 do ( x := x mod y ; ans := ans + 1 ; if (m)->includes(x) then ( return -1 ) else skip ; m[x+1] := 1 ; x := x * 10) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class RangeMaximumQuery : def __init__(self,n): self.size=n self.dat=[0]*(2*n-1) def update(self,i,x): i+=self.size-1 self.dat[i]=x while i>0 : i=(i-1)//2 d1=self.dat[i*2+1] d2=self.dat[i*2+2] if d1>d2 : self.dat[i]=d1 else : self.dat[i]=d2 def getmax(self,a,b,k,l,r): if r<=a or b<=l : return 0 elif a<=l and r<=b : return self.dat[k] else : vl=self.getmax(a,b,k*2+1,l,(l+r)//2) vr=self.getmax(a,b,k*2+2,(l+r)//2,r) if vl>vr : return vl else : return vr def solve(): from math import ceil,log n=int(input()) A=map(int,input().split()) s=2**ceil(log(n,2)) W=RangeMaximumQuery(s) for a_i in A : cost=W.getmax(0,a_i-1,0,0,s)+a_i W.update(a_i-1,cost) ans=n*(n+1)//2-W.getmax(0,n,0,0,s) print(ans) solve() ------------------------------------------------------------ OCL File: --------- class RangeMaximumQuery { static operation newRangeMaximumQuery() : RangeMaximumQuery pre: true post: RangeMaximumQuery->exists( _x | result = _x ); attribute size : OclAny := n; attribute dat : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * n - 1)); operation initialise(n : OclAny) : RangeMaximumQuery pre: true post: true activity: self.size := n ; self.dat := MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * n - 1)); return self; operation update(i : OclAny,x : OclAny) pre: true post: true activity: i := i + self.size - 1 ; self.dat[i+1] := x ; while i > 0 do ( i := (i - 1) div 2 ; var d1 : OclAny := self.dat[i * 2 + 1+1] ; var d2 : OclAny := self.dat[i * 2 + 2+1] ; if (d1->compareTo(d2)) > 0 then ( self.dat[i+1] := d1 ) else ( self.dat[i+1] := d2 )); operation getmax(a : OclAny,b : OclAny,k : OclAny,l : OclAny,r : OclAny) : OclAny pre: true post: true activity: if (r->compareTo(a)) <= 0 or (b->compareTo(l)) <= 0 then ( return 0 ) else (if (a->compareTo(l)) <= 0 & (r->compareTo(b)) <= 0 then ( return self.dat[k+1] ) else ( var vl : OclAny := self.getmax(a, b, k * 2 + 1, l, (l + r) div 2) ; var vr : OclAny := self.getmax(a, b, k * 2 + 2, (l + r) div 2, r) ; if (vl->compareTo(vr)) > 0 then ( return vl ) else ( return vr ) ) ) ; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; solve(); operation solve() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : double := (2)->pow(ceil(log(n, 2))) ; var W : RangeMaximumQuery := (RangeMaximumQuery.newRangeMaximumQuery()).initialise(s) ; for a_i : A do ( var cost : OclAny := W.getmax(0, a_i - 1, 0, 0, s) + a_i ; execute ((a_i - 1, cost) <: W)) ; var ans : double := n * (n + 1) div 2 - W.getmax(0, n, 0, 0, s) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPossibleToMakeDivisible(arr,n): remainder=0 for i in range(0,n): remainder=(remainder+arr[i])% 3 return(remainder==0) arr=[40,50,90]; n=3 if(isPossibleToMakeDivisible(arr,n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{40}->union(Sequence{50}->union(Sequence{ 90 })); ; n := 3 ; if (isPossibleToMakeDivisible(arr, n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isPossibleToMakeDivisible(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var remainder : int := 0 ; for i : Integer.subrange(0, n-1) do ( remainder := (remainder + arr[i+1]) mod 3) ; return (remainder = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline N,K=map(int,input().split()) A=list(map(int,input().split())) ans=0 graph=[[]for _ in range(N)] Par=[-1]*N for i,a in enumerate(A): if i==0 : if a!=1 : ans+=1 continue Par[i]=a-1 graph[a-1].append(i) qs=[] stack=[0] Depth=[-1]*N Depth[0]=0 while stack : p=stack.pop() for np in graph[p]: Depth[np]=Depth[p]+1 stack.append(np) qs.append((Depth[p],p)) qs.sort(reverse=True) checked=[False]*N for d,s in qs : if d<=K : break if checked[s]: continue for _ in range(K-1): s=Par[s] que=[s] checked[s]=True while que : qq=[] for p in que : for np in graph[p]: if not checked[np]: checked[np]=True qq.append(np) que=qq ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; var graph : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var Par : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, N) ; for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); if i = 0 then ( if a /= 1 then ( ans := ans + 1 ) else skip ; continue ) else skip ; Par[i+1] := a - 1 ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var qs : Sequence := Sequence{} ; var stack : Sequence := Sequence{ 0 } ; var Depth : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, N) ; Depth->first() := 0 ; while stack do ( var p : OclAny := stack->last() ; stack := stack->front() ; for np : graph[p+1] do ( Depth[np+1] := Depth[p+1] + 1 ; execute ((np) : stack)) ; execute ((Sequence{Depth[p+1], p}) : qs)) ; qs := qs->sort() ; var checked : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, N) ; for _tuple : qs do (var _indx : int := 1; var d : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); if (d->compareTo(K)) <= 0 then ( break ) else skip ; if checked[s+1] then ( continue ) else skip ; for _anon : Integer.subrange(0, K - 1-1) do ( var s : OclAny := Par[s+1]) ; var que : Sequence := Sequence{ s } ; checked[s+1] := true ; while que do ( var qq : Sequence := Sequence{} ; for p : que do ( for np : graph[p+1] do ( if not(checked[np+1]) then ( checked[np+1] := true ; execute ((np) : qq) ) else skip)) ; que := qq) ; ans := ans + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque import sys sys.setrecursionlimit(10**7) input=sys.stdin.readline n,k=map(int,input().split()) a=[int(x)-1 for x in input().split()] ans=0 if a[0]!=0 : ans+=1 a[0]=0 def dfs(v,par): global ans for w in g[v]: if w!=par : dfs(w,v) if f[w]+1==k and v!=0 : ans+=1 continue f[v]=max(f[v],f[w]+1) return ans g=[[]for _ in range(n)] indeg=[0]*n for i in range(1,n): g[a[i]].append(i) indeg[i]+=1 q=deque([0]) TS=[0] while q : v=q.popleft() for w in g[v]: indeg[w]-=1 if indeg[w]==0 : TS.append(w) q.append(w) f=[0]*n for w in TS[: :-1]: if f[w]+1==k and a[w]!=0 : ans+=1 continue f[a[w]]=max(f[a[w]],f[w]+1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute ans : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)) ; var ans : int := 0 ; if a->first() /= 0 then ( ans := ans + 1 ; a->first() := 0 ) else skip ; skip ; var g : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var indeg : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(1, n-1) do ((expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ; indeg[i+1] := indeg[i+1] + 1) ; var q : Sequence := (Sequence{ 0 }) ; var TS : Sequence := Sequence{ 0 } ; while q do ( v := q->first() ; q := q->tail() ; for w : g[v+1] do ( indeg[w+1] := indeg[w+1] - 1 ; if indeg[w+1] = 0 then ( execute ((w) : TS) ; execute ((w) : q) ) else skip)) ; var f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for w : TS(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if f[w+1] + 1 = k & a[w+1] /= 0 then ( ans := ans + 1 ; continue ) else skip ; f[a[w+1]+1] := Set{f[a[w+1]+1], f[w+1] + 1}->max()) ; execute (ans)->display(); operation dfs(v : OclAny, par : OclAny) : OclAny pre: true post: true activity: skip ; for w : g[v+1] do ( if w /= par then ( dfs(w, v) ; if f[w+1] + 1 = k & v /= 0 then ( ans := ans + 1 ; continue ) else skip ; f[v+1] := Set{f[v+1], f[w+1] + 1}->max() ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections N,K=[int(s)for s in raw_input().split(' ')] dest=[int(s)-1 for s in raw_input().split(' ')] ans=0 if dest[0]!=0 : dest[0]=0 ans+=1 if K>=N : print(ans) raise SystemExit source=collections.defaultdict(list) for v in range(1,N): source[dest[v]].append(v) dist=[0]*N dist[0]=0 topo=[] queue=collections.deque() queue.append(0) while queue : u=queue.popleft() topo.append(u) for v in source[u]: dist[v]=dist[u]+1 queue.append(v) good=set() for u in reversed(topo): if u in good : continue if dist[u]<=K : break ans+=1 ancestor=u for _ in range(K-1): ancestor=dest[ancestor] desc=[] good.add(ancestor) desc.append(ancestor) i=0 while iselect(s | true)->collect(s | (("" + ((s)))->toInteger())) ; var dest : Sequence := raw_input().split(' ')->select(s | true)->collect(s | (("" + ((s)))->toInteger() - 1)) ; var ans : int := 0 ; if dest->first() /= 0 then ( dest->first() := 0 ; ans := ans + 1 ) else skip ; if (K->compareTo(N)) >= 0 then ( execute (ans)->display() ; error SystemExit.newSystemExit ) else skip ; var source : OclAny := .defaultdict(OclType["Sequence"]) ; for v : Integer.subrange(1, N-1) do ((expr (atom (name source)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name dest)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) ))))) ; var dist : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; dist->first() := 0 ; var topo : Sequence := Sequence{} ; var queue : Sequence := () ; execute ((0) : queue) ; while queue do ( var u : OclAny := queue->first() ; queue := queue->tail() ; execute ((u) : topo) ; for v : source[u+1] do ( dist[v+1] := dist[u+1] + 1 ; execute ((v) : queue))) ; var good : Set := Set{}->union(()) ; for u : (topo)->reverse() do ( if (good)->includes(u) then ( continue ) else skip ; if (dist[u+1]->compareTo(K)) <= 0 then ( break ) else skip ; ans := ans + 1 ; var ancestor : OclAny := u ; for _anon : Integer.subrange(0, K - 1-1) do ( ancestor := dest[ancestor+1]) ; var desc : Sequence := Sequence{} ; execute ((ancestor) : good) ; execute ((ancestor) : desc) ; var i : int := 0 ; while (i->compareTo((desc)->size())) < 0 do ( var anc : OclAny := desc[i+1] ; i := i + 1 ; for v : source[anc+1] do ( if (good)->excludes(v) then ( execute ((v) : good) ; execute ((v) : desc) ) else skip))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) def dfs(links,n,k,v,p): height_from_leaf=0 cut_count=0 for u in links[v]: if u==0 : continue hgt,cut=dfs(links,n,k,u,v) height_from_leaf=max(height_from_leaf,hgt) cut_count+=cut height_from_leaf+=1 if p!=0 and height_from_leaf==k : height_from_leaf=0 cut_count+=1 return height_from_leaf,cut_count n,k,*aaa=map(int,sys.stdin.buffer.read().split()) links=[set()for _ in range(n)] for i,a in enumerate(aaa): a-=1 links[a].add(i) _,ans=dfs(links,n,k,0,0) if aaa[0]!=1 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; skip ; var aaa : OclAny := null; Sequence{n,k,aaa} := (sys.stdin.buffer.readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; links := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; for _tuple : Integer.subrange(1, (aaa)->size())->collect( _indx | Sequence{_indx-1, (aaa)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); a := a - 1 ; (expr (atom (name links)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var _anon : OclAny := null; var ans : OclAny := null; Sequence{_anon,ans} := dfs(links, n, k, 0, 0) ; if aaa->first() /= 1 then ( ans := ans + 1 ) else skip ; execute (ans)->display(); operation dfs(links : OclAny, n : OclAny, k : OclAny, v : OclAny, p : OclAny) : OclAny pre: true post: true activity: var height_from_leaf : int := 0 ; var cut_count : int := 0 ; for u : links[v+1] do ( if u = 0 then ( continue ) else skip ; var hgt : OclAny := null; var cut : OclAny := null; Sequence{hgt,cut} := dfs(links, n, k, u, v) ; height_from_leaf := Set{height_from_leaf, hgt}->max() ; cut_count := cut_count + cut) ; height_from_leaf := height_from_leaf + 1 ; if p /= 0 & height_from_leaf = k then ( height_from_leaf := 0 ; cut_count := cut_count + 1 ) else skip ; return height_from_leaf, cut_count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSubArrays(arr,n,K): count=0 ; for i in range(n): for j in range(i,n): bitwise_or=0 for k in range(i,j+1): bitwise_or=bitwise_or | arr[k] if(bitwise_or>=K): count+=1 return count if __name__=="__main__" : arr=[3,4,5] n=len(arr) k=6 print(countSubArrays(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })) ; n := (arr)->size() ; var k : int := 6 ; execute (countSubArrays(arr, n, k))->display() ) else skip; operation countSubArrays(arr : OclAny, n : OclAny, K : OclAny) : OclAny pre: true post: true activity: var count : int := 0; ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i, n-1) do ( var bitwise_or : int := 0 ; for k : Integer.subrange(i, j + 1-1) do ( bitwise_or := MathLib.bitwiseOr(bitwise_or, arr[k+1])) ; if ((bitwise_or->compareTo(K)) >= 0) then ( count := count + 1 ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import exit,setrecursionlimit from itertools import product def read(): return int(input()) def reads(): return[int(x)for x in input().split()] def argmin(ll): ll=list(ll) return ll.index(min(ll)) setrecursionlimit(1000000) (N,K)=reads() parent=[x-1 for x in reads()] result=0 if parent[0]!=0 : parent[0]=0 result+=1 children=[[]for _ in range(N)] for i in range(1,N): children[parent[i]].append(i) color=[0]*N def walk(i): global result for x in children[i]: walk(x) if color[x]==1 and parent[x]!=0 : result+=1 color[i]=min([K]+[color[x]-1 for x in children[i]if color[x]>=2]) walk(0) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute result : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; setrecursionlimit(1000000) ; var Sequence{N, K} : OclAny := reads() ; var parent : Sequence := reads()->select(x | true)->collect(x | (x - 1)) ; var result : int := 0 ; if parent->first() /= 0 then ( parent->first() := 0 ; result := result + 1 ) else skip ; var children : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(1, N-1) do ((expr (atom (name children)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name parent)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var color : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; skip ; walk(0) ; execute (result)->display(); operation read() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation reads() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation argmin(ll : OclAny) : OclAny pre: true post: true activity: ll := (ll) ; return ll->indexOf((ll)->min()) - 1; operation walk(i : OclAny) pre: true post: true activity: skip ; for x : children[i+1] do ( walk(x) ; if color[x+1] = 1 & parent[x+1] /= 0 then ( result := result + 1 ) else skip) ; color[i+1] := (Sequence{ K }->union(children[i+1]->select(x | color[x+1] >= 2)->collect(x | (color[x+1] - 1))))->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printCubes(a,b): for i in range(a,b+1): j=1 for j in range(j**3,i+1): if(j**3==i): print(j**3,end=" ") break a=1 ; b=100 print("Perfect cubes in given range: ") printCubes(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 1; b := 100 ; execute ("Perfect cubes in given range: ")->display() ; printCubes(a, b); operation printCubes(a : OclAny, b : OclAny) pre: true post: true activity: for i : Integer.subrange(a, b + 1-1) do ( var j : int := 1 ; for j : Integer.subrange((j)->pow(3), i + 1-1) do ( if ((j)->pow(3) = i) then ( execute ((j)->pow(3))->display() ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getModulo(n,d): return(n &(d-1)) n=6 d=4 print(n,"moduo",d,"is",getModulo(n,d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 6 ; d := 4 ; execute (n)->display(); operation getModulo(n : OclAny, d : OclAny) : OclAny pre: true post: true activity: return (MathLib.bitwiseAnd(n, (d - 1))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- try : N,d=map(int,input().split()) nums=list(map(int,input().split())) nums.sort() ans=0 for i in range(N): for j in range(N-1,i-1,-1): if abs(nums[i]-nums[j])<=d : ans=max(ans,j-i+1) break print(N-ans) except Exception as e : print(e) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: try ( var N : OclAny := null; var d : OclAny := null; Sequence{N,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var nums : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; nums := nums->sort() ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(i - 1 + 1, N - 1)->reverse() do ( if ((nums[i+1] - nums[j+1])->abs()->compareTo(d)) <= 0 then ( ans := Set{ans, j - i + 1}->max() ; break ) else skip)) ; execute (N - ans)->display()) catch (e : ProgramException) do ( execute (e)->display()) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) bits=[] g=0 for i in range(31): c=0 for j in l : if((j &(1<g : break if g % i==0 : ans.append(i) ans.append(g//i) ans=list(set(ans)) ans=sorted(ans) print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var bits : Sequence := Sequence{} ; var g : int := 0 ; for i : Integer.subrange(0, 31-1) do ( var c : int := 0 ; for j : l do ( if ((MathLib.bitwiseAnd(j, (1 * (2->pow(i)))))) then ( c := c + 1 ) else skip) ; execute ((c) : bits) ; g := (g)->gcd(c)) ; if g = 0 then ( for i : Integer.subrange(0, n-1) do ( execute (i + 1)->display()) ) else ( var ans : Sequence := Sequence{} ; for i : Integer.subrange(1, g + 1-1) do ( if (i * i->compareTo(g)) > 0 then ( break ) else skip ; if g mod i = 0 then ( execute ((i) : ans) ; execute ((g div i) : ans) ) else skip) ; ans := (Set{}->union((ans))) ; ans := ans->sort() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import string from collections import Counter,defaultdict from math import fsum,sqrt,gcd,ceil,factorial from operator import add from bisect import* inf=float("inf") flush=lambda : sys.stdout.flush comb=lambda x,y :(factorial(x)//factorial(y))//factorial(x-y) ip=lambda : input() ii=lambda : int(input()) r=lambda : map(int,input().split()) rr=lambda : list(r()) n,k=r() arr=rr() arr.sort() ans=inf for i in range(n): need=arr[i]+k ans=min(i+n-bisect(arr,need),ans) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var Math_PINFINITY : double := ("" + (("inf")))->toReal() ; var flush : Function := lambda $$ : OclAny in ((OclFile["System.out"]).flush) ; var comb : Function := lambda x : OclAny, y : OclAny in ((factorial(x) div factorial(y)) div factorial(x - y)) ; var ip : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var ii : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var r : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var rr : Function := lambda $$ : OclAny in ((r->apply())->characters()) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := r->apply() ; var arr : OclAny := rr->apply() ; arr := arr->sort() ; var ans : double := Math_PINFINITY ; for i : Integer.subrange(0, n-1) do ( var need : OclAny := arr[i+1] + k ; ans := Set{i + n - bisect(arr, need), ans}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=list(map(int,input().split())) a=list(map(int,input().split())) a.sort() i=0 j=1 l=0 tl=1 if n==1 : print(0) exit() while True : if abs(a[i]-a[j])<=d : tl+=1 j+=1 else : if tl>l : l=tl tl=1 i+=1 j=i+1 if i>=n-1 or j>=n : if tl>l : l=tl break print(n-l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var i : int := 0 ; var j : int := 1 ; var l : int := 0 ; var tl : int := 1 ; if n = 1 then ( execute (0)->display() ; exit() ) else skip ; while true do ( if ((a[i+1] - a[j+1])->abs()->compareTo(d)) <= 0 then ( tl := tl + 1 ; j := j + 1 ) else ( if (tl->compareTo(l)) > 0 then ( l := tl ) else skip ; tl := 1 ; i := i + 1 ; j := i + 1 ) ; if (i->compareTo(n - 1)) >= 0 or (j->compareTo(n)) >= 0 then ( if (tl->compareTo(l)) > 0 then ( l := tl ) else skip ; break ) else skip) ; execute (n - l)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=list(map(int,input().split())) a=list(map(int,input().split())) a=sorted(a) l=0 r=0 cur_d=a[r]-a[l] max_num=1 while rcollect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var l : int := 0 ; var r : int := 0 ; var cur_d : double := a[r+1] - a[l+1] ; var max_num : int := 1 ; while (r->compareTo((a)->size())) < 0 do ( if (a[r+1] - a[l+1]->compareTo(d)) <= 0 then ( max_num := Set{max_num, r - l + 1}->max() ; r := r + 1 ) else ( l := l + 1 )) ; execute ((a)->size() - max_num)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(s): a=ord(s[-1])-ord('a') n=int(s[:-1]) od=[4,5,6,3,2,1] ad=[0,7,0,7] c=16 ktmp=(n-1)//4 ttmp=(n-1)% 4 ans=ktmp*16+ad[ttmp]+od[a] return ans s=input() print(solve(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := (OclFile["System.in"]).readLine() ; execute (solve(s))->display(); operation solve(s : OclAny) : OclAny pre: true post: true activity: var a : double := (s->last())->char2byte() - ('a')->char2byte() ; var n : int := ("" + ((s->front())))->toInteger() ; var od : Sequence := Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 1 }))))) ; var ad : Sequence := Sequence{0}->union(Sequence{7}->union(Sequence{0}->union(Sequence{ 7 }))) ; var c : int := 16 ; var ktmp : int := (n - 1) div 4 ; var ttmp : int := (n - 1) mod 4 ; var ans : int := ktmp * 16 + ad[ttmp+1] + od[a+1] ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() n=int(s[:-1]) s=s[-1] print((n-1)//4*16+(1-n % 2)*7+'1fedabc'.find(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var n : int := ("" + ((s->front())))->toInteger() ; s := s->last() ; execute ((n - 1) div 4 * 16 + (1 - n mod 2) * 7 + '1fedabc'->indexOf(s) - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ns=input() n=int(ns[0 :-1]) s=ns[-1] l=['f','e','d','a','b','c'] if n//2 % 2==0 and n % 2==1 : res=n//2*6+(n-1)+l.index(s)+1 elif n//2 % 2!=0 and n % 2==1 : res=(n//2-1)*6+(n-3)+l.index(s)+1 elif n//2 % 2!=0 : res=n//2*6+(n-1)+l.index(s)+1 elif n//2 % 2==0 : res=(n//2-1)*6+(n-3)+l.index(s)+1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ns : String := (OclFile["System.in"]).readLine() ; var n : int := ("" + ((ns.subrange(0+1, -1))))->toInteger() ; var s : OclAny := ns->last() ; var l : Sequence := Sequence{'f'}->union(Sequence{'e'}->union(Sequence{'d'}->union(Sequence{'a'}->union(Sequence{'b'}->union(Sequence{ 'c' }))))) ; if n div 2 mod 2 = 0 & n mod 2 = 1 then ( var res : int := n div 2 * 6 + (n - 1) + l->indexOf(s) - 1 + 1 ) else (if n div 2 mod 2 /= 0 & n mod 2 = 1 then ( res := (n div 2 - 1) * 6 + (n - 3) + l->indexOf(s) - 1 + 1 ) else (if n div 2 mod 2 /= 0 then ( res := n div 2 * 6 + (n - 1) + l->indexOf(s) - 1 + 1 ) else (if n div 2 mod 2 = 0 then ( res := (n div 2 - 1) * 6 + (n - 3) + l->indexOf(s) - 1 + 1 ) else skip ) ) ) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def canBeEqual(a,b,c,k): arr=[0]*3 ; arr[0]=a ; arr[1]=b ; arr[2]=c ; arr.sort() diff=2*arr[2]-arr[1]-arr[0]; k=k-diff ; if(k<0 or k % 3!=0): return False ; return True ; if __name__=="__main__" : a1=6 ; b1=3 ; c1=2 ; k1=7 ; if(canBeEqual(a1,b1,c1,k1)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var a1 : int := 6; var b1 : int := 3; var c1 : int := 2; var k1 : int := 7; ; if (canBeEqual(a1, b1, c1, k1)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ) else skip; operation canBeEqual(a : OclAny, b : OclAny, c : OclAny, k : OclAny) pre: true post: true activity: var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 3); ; arr->first() := a; ; arr[1+1] := b; ; arr[2+1] := c; ; arr := arr->sort() ; var diff : double := 2 * arr[2+1] - arr[1+1] - arr->first(); ; k := k - diff; ; if (k < 0 or k mod 3 /= 0) then ( return false; ) else skip ; return true;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def main_function(): hash_={"f" : 0,"e" : 1,"d" : 2,"a" : 3,"b" : 4,"c" : 5} count=1 total=1+6 s=input() n,char=int(s[:-1]),s[-1] counter=1 rem=n % 4 full_serves=n//4 count+=2*total*(max(0,full_serves-(not bool(rem))))+2*(max(0,full_serves-(not bool(rem)))) if rem==0 or rem==2 : count+=total count+=hash_[char] print(count) main_function() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main_function(); operation main_function() pre: true post: true activity: var hash_ : Map := Map{ "f" |-> 0 }->union(Map{ "e" |-> 1 }->union(Map{ "d" |-> 2 }->union(Map{ "a" |-> 3 }->union(Map{ "b" |-> 4 }->union(Map{ "c" |-> 5 }))))) ; var count : int := 1 ; var total : int := 1 + 6 ; var s : String := (OclFile["System.in"]).readLine() ; var n : OclAny := null; var char : OclAny := null; Sequence{n,char} := Sequence{("" + ((s->front())))->toInteger(),s->last()} ; var counter : int := 1 ; var rem : int := n mod 4 ; var full_serves : int := n div 4 ; count := count + 2 * total * (Set{0, full_serves - (not((rem)->toBoolean()))}->max()) + 2 * (Set{0, full_serves - (not((rem)->toBoolean()))}->max()) ; if rem = 0 or rem = 2 then ( count := count + total ) else skip ; count := count + hash_[char+1] ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() r=int(s[:-1])-1 c=s[-1] ans=(r//4)*(12+4) r-=r//4*4 if r % 2==1 : ans+=6+1 ans+="fedabc".index(c)+1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var r : double := ("" + ((s->front())))->toInteger() - 1 ; var c : OclAny := s->last() ; var ans : int := (r div 4) * (12 + 4) ; r := r - r div 4 * 4 ; if r mod 2 = 1 then ( ans := ans + 6 + 1 ) else skip ; ans := ans + "fedabc"->indexOf(c) - 1 + 1 ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPerfectCube(x): cr=int(x**(1/3)); return(cr*cr*cr==x); def canBePerfectCube(N,K): if(isPerfectCube(N+K)or isPerfectCube(N-K)): print("Yes"); else : print("No"); if __name__=="__main__" : N=7 ; K=1 ; canBePerfectCube(N,K); N=5 ; K=4 ; canBePerfectCube(N,K); N=7 ; K=2 ; canBePerfectCube(N,K); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( N := 7; K := 1; ; canBePerfectCube(N, K); ; N := 5; K := 4; ; canBePerfectCube(N, K); ; N := 7; K := 2; ; canBePerfectCube(N, K); ) else skip; operation isPerfectCube(x : OclAny) pre: true post: true activity: var cr : int := ("" + (((x)->pow((1 / 3)))))->toInteger(); ; return (cr * cr * cr = x);; operation canBePerfectCube(N : OclAny, K : OclAny) pre: true post: true activity: if (isPerfectCube(N + K) or isPerfectCube(N - K)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os in_file=None out_file=None def run_main(main): name=sys.argv[0][:-3] in_file_name=name+".in" out_file_name=name+".out" if len(sys.argv)==2 : in_file_name=sys.argv[1] out_file_name=in_file_name[:-3]+".out" if len(sys.argv)==3 : if sys.argv[1]: in_file_name=sys.argv[1] if sys.argv[2]: out_file_name=sys.argv[2] global in_file global out_file if in_file_name=='-' : in_file=sys.stdin else : in_file=open(in_file_name,'r') if out_file_name=='-' : out_file=sys.stdout else : out_file=open(out_file_name,'w') main(in_file,out_file) out_file.close() in_file.close() def run_tests(do_testcase): def main(in_file,out_file): t=readinteger() for x in range(t): do_testcase(x+1) run_main(main) def readline(): return in_file.readline()[:-1] def writeline(s): out_file.write("%s\n" % s) def readinteger(): return int(readline()) def readintegers(): integers=readline().split() for i in range(len(integers)): integers[i]=int(integers[i]) return integers ------------------------------------------------------------ OCL File: --------- class FromPython { attribute in_file : OclAny; attribute out_file : OclAny; operation initialise() pre: true post: true activity: skip ; var in_file : OclAny := null ; var out_file : OclAny := null ; skip ; skip ; skip ; skip ; skip ; skip; operation run_main(main : OclAny) pre: true post: true activity: var name : OclAny := ((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))).subrange(1,-3) ; var in_file_name : int := name + ".in" ; var out_file_name : int := name + ".out" ; if ((trailer . (name argv)))->size() = 2 then ( in_file_name := (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) ; out_file_name := in_file_name.subrange(1,-3) + ".out" ) else skip ; if ((trailer . (name argv)))->size() = 3 then ( if (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) then ( in_file_name := (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) ) else skip ; if (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) then ( out_file_name := (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) ) else skip ) else skip ; skip ; skip ; if in_file_name = '-' then ( in_file := OclFile["System.in"] ) else ( in_file := OclFile.newOclFile_Write(OclFile.newOclFile(in_file_name)) ) ; if out_file_name = '-' then ( out_file := OclFile["System.out"] ) else ( out_file := OclFile.newOclFile_Write(OclFile.newOclFile(out_file_name)) ) ; main(in_file, out_file) ; out_file.closeFile() ; in_file.closeFile(); operation run_tests(do_testcase : OclAny) pre: true post: true activity: skip ; run_main(main); operation readline() : OclAny pre: true post: true activity: return in_file.readLine()->front(); operation writeline(s : OclAny) pre: true post: true activity: out_file.write(StringLib.format("%s\n",s)); operation readinteger() : OclAny pre: true post: true activity: return ("" + ((readline())))->toInteger(); operation readintegers() : OclAny pre: true post: true activity: var integers : OclAny := readline().split() ; for i : Integer.subrange(0, (integers)->size()-1) do ( integers[i+1] := ("" + ((integers[i+1])))->toInteger()) ; return integers; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(input()) s=input() t=input() test=s+t if(s==t): print(len(s)) sys.exit() for i in range(1,n+1)[: :-1]: test=s[0 :-i]+t if(test[: n]==s and test[-n :]==t): print(len(test)) sys.exit() print(len(s+t)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var test : String := s + t ; if (s = t) then ( execute ((s)->size())->display() ; sys.exit() ) else skip ; for i : range(1, n + 1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( test := s.subrange(0+1, -i) + t ; if (test.subrange(1,n) = s & test.subrange(-n+1) = t) then ( execute ((test)->size())->display() ; sys.exit() ) else skip) ; execute ((s + t)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import heapq import itertools import math import operator import os import re import string import sys from collections import Counter,deque,defaultdict from copy import deepcopy from decimal import Decimal from fractions import gcd from functools import lru_cache,reduce from operator import itemgetter,mul,add,xor import numpy as np if os.getenv("LOCAL"): sys.stdin=open("_in.txt","r") sys.setrecursionlimit(2147483647) INF=float("inf") IINF=10**18 MOD=10**9+7 N=int(sys.stdin.readline()) S=sys.stdin.readline().rstrip() T=sys.stdin.readline().rstrip() ans=0 while S!=T : S=S[1 :] T=T[:-1] ans+=2 print(ans+len(S)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if os.getenv("LOCAL") then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("_in.txt")) ) else skip ; sys.setrecursionlimit(2147483647) ; var INF : double := ("" + (("inf")))->toReal() ; var IINF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : OclAny := sys.stdin.readLine().rstrip() ; var T : OclAny := sys.stdin.readLine().rstrip() ; var ans : int := 0 ; while S /= T do ( S := S->tail() ; T := T->front() ; ans := ans + 2) ; execute (ans + (S)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin def main(): input=lambda : stdin.readline()[:-1] N=int(input()) S=input() T=input() for i in range(N): j=0 for k in range(i,N): if S[k]!=T[j]: break j+=1 else : print(N*2-j) return print(N*2) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: var input : Function := lambda $$ : OclAny in (stdin.readLine()->front()) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : String := (OclFile["System.in"]).readLine() ; var T : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, N-1) do ( var j : int := 0 ; (compound_stmt for (exprlist (expr (atom (name k)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])))) != (comparison (expr (atom (name T)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name j)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name N))) * (expr (atom (number (integer 2))))) - (expr (atom (name j))))))))) )))))))))))) (stmt (simple_stmt (small_stmt return))))))) ; execute (N * 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=list(input()) t=list(input()) if s==t : print(n) else : cnt=0 for i in range(n): for j in range(n-i): if s[i+j]!=t[j]: break if j==n-i-1 : cnt=n-i print(2*n-cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var t : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if s = t then ( execute (n)->display() ) else ( var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n - i-1) do ( if s[i + j+1] /= t[j+1] then ( break ) else skip ; if j = n - i - 1 then ( cnt := n - i ) else skip)) ; execute (2 * n - cnt)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re n=int(input()) s=input() t=input() idx=0 for i in range(len(s)-1,-1,-1): if re.match(s[i :],t): matchOB=s[i :] idx=len(matchOB) print(len(s+t[idx :])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var idx : int := 0 ; for i : Integer.subrange(-1 + 1, (s)->size() - 1)->reverse() do ( if (t)->firstMatch("^" + s.subrange(i+1) + ".*") then ( var matchOB : OclAny := s.subrange(i+1) ; idx := (matchOB)->size() ) else skip) ; execute ((s + t.subrange(idx+1))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict class Graph : def __init__(self): self.graph=defaultdict(list) def addEdge(self,u,v): self.graph[u].append(v) def DFSUtil(self,v,visited): visited[v]=True print(v,end=' ') for i in self.graph[v]: if visited[i]==False : self.DFSUtil(i,visited) def DFS(self,v): visited=[False]*(max(self.graph)+1) self.DFSUtil(v,visited) g=Graph() g.addEdge(0,1) g.addEdge(0,2) g.addEdge(1,2) g.addEdge(2,0) g.addEdge(2,3) g.addEdge(3,3) print("Following is DFS from(starting from vertex 2)") g.DFS(2) ------------------------------------------------------------ OCL File: --------- class Graph { static operation newGraph() : Graph pre: true post: Graph->exists( _x | result = _x ); attribute graph : OclAny := defaultdict(OclType["Sequence"]); operation initialise() : Graph pre: true post: true activity: self.graph := defaultdict(OclType["Sequence"]); return self; operation addEdge(u : OclAny,v : OclAny) pre: true post: true activity: (expr (atom (name self)) (trailer . (name graph) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))); operation DFSUtil(v : OclAny,visited : OclAny) pre: true post: true activity: visited[v+1] := true ; execute (v)->display() ; for i : self.graph[v+1] do ( if visited[i+1] = false then ( self.DFSUtil(i, visited) ) else skip); operation DFS(v : OclAny) pre: true post: true activity: visited := MatrixLib.elementwiseMult(Sequence{ false }, ((self.graph)->max() + 1)) ; self.DFSUtil(v, visited); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var g : Graph := (Graph.newGraph()).initialise() ; g.addEdge(0, 1) ; g.addEdge(0, 2) ; g.addEdge(1, 2) ; g.addEdge(2, 0) ; g.addEdge(2, 3) ; g.addEdge(3, 3) ; execute ("Following is DFS from(starting from vertex 2)")->display() ; g.DFS(2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def countDigits(val,arr): while(val>0): digit=val % 10 arr[int(digit)]+=1 val=val//10 return ; def countFrequency(x,n): freq_count=[0]*10 for i in range(1,n+1): val=math.pow(x,i) countDigits(val,freq_count) for i in range(10): print(freq_count[i],end=" "); if __name__=="__main__" : x=15 n=3 countFrequency(x,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( x := 15 ; n := 3 ; countFrequency(x, n) ) else skip; operation countDigits(val : OclAny, arr : OclAny) : OclAny pre: true post: true activity: while (val > 0) do ( var digit : int := val mod 10 ; arr[("" + ((digit)))->toInteger()+1] := arr[("" + ((digit)))->toInteger()+1] + 1 ; val := val div 10) ; return;; operation countFrequency(x : OclAny, n : OclAny) pre: true post: true activity: var freq_count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; for i : Integer.subrange(1, n + 1-1) do ( val := (x)->pow(i) ; countDigits(val, freq_count)) ; for i : Integer.subrange(0, 10-1) do ( execute (freq_count[i+1])->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- adjacency=[[]for i in range(100)] def insert(x,y): adjacency[x].append(y) def dfs(node,leaf,vis): leaf[node]=0 vis[node]=1 for it in adjacency[node]: if(vis[it]==False): dfs(it,leaf,vis) leaf[node]+=leaf[it] if(len(adjacency[node])==0): leaf[node]=1 def printLeaf(n,leaf): for i in range(1,n+1): print("The node",i,"has",leaf[i],"leaf nodes") N=6 insert(1,2) insert(1,3) insert(3,4) insert(3,5) insert(3,6) leaf=[0 for i in range(N+1)] vis=[0 for i in range(N+1)] dfs(1,leaf,vis) printLeaf(N,leaf) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var adjacency : Sequence := Integer.subrange(0, 100-1)->select(i | true)->collect(i | (Sequence{})) ; skip ; skip ; skip ; var N : int := 6 ; insert(1, 2) ; insert(1, 3) ; insert(3, 4) ; insert(3, 5) ; insert(3, 6) ; leaf := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (0)) ; vis := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (0)) ; dfs(1, leaf, vis) ; printLeaf(N, leaf); operation insert(x : OclAny, y : OclAny) pre: true post: true activity: (expr (atom (name adjacency)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))); operation dfs(node : OclAny, leaf : OclAny, vis : OclAny) pre: true post: true activity: leaf[node+1] := 0 ; vis[node+1] := 1 ; for it : adjacency[node+1] do ( if (vis[it+1] = false) then ( dfs(it, leaf, vis) ; leaf[node+1] := leaf[node+1] + leaf[it+1] ) else skip) ; if ((adjacency[node+1])->size() = 0) then ( leaf[node+1] := 1 ) else skip; operation printLeaf(n : OclAny, leaf : OclAny) pre: true post: true activity: for i : Integer.subrange(1, n + 1-1) do ( execute ("The node")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) a=list(map(int,input().split())) ans="NO" a.sort(reverse=True) while a and not a[-1]^ 1 : a.pop() a.reverse() for i in range(len(a)-1): if 2*a[i]>a[i+1]and a[i]^ a[i+1]: ans="YES" break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : String := "NO" ; a := a->sort() ; while a & not(MathLib.bitwiseXor(a->last(), 1)) do ( a := a->front()) ; a := a->reverse() ; for i : Integer.subrange(0, (a)->size() - 1-1) do ( if (2 * a[i+1]->compareTo(a[i + 1+1])) > 0 & MathLib.bitwiseXor(a[i+1], a[i + 1+1]) then ( ans := "YES" ; break ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) a=set(a) a=sorted(a) for i in range(len(a)-1): if a[i]+a[i]>a[i+1]: print('YES') exit(0) print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := Set{}->union((a)) ; a := a->sort() ; for i : Integer.subrange(0, (a)->size() - 1-1) do ( if (a[i+1] + a[i+1]->compareTo(a[i + 1+1])) > 0 then ( execute ('YES')->display() ; exit(0) ) else skip) ; execute ('NO')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for tc in range(T): E,R,N=map(int,input().split()) v=list(map(int,input().split())) gainz=0 e=E for i in range(N): spend=e for j in range(i,N): if v[j]>v[i]: spend=min(spend,e+R*(j-i)-E) spend=max(spend,0) e-=spend e=min(e+R,E) gainz+=v[i]*spend print("Case #{}:{}".format(tc+1,gainz)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for tc : Integer.subrange(0, T-1) do ( var E : OclAny := null; var R : OclAny := null; var N : OclAny := null; Sequence{E,R,N} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var v : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var gainz : int := 0 ; var e : OclAny := E ; for i : Integer.subrange(0, N-1) do ( var spend : OclAny := e ; for j : Integer.subrange(i, N-1) do ( if (v[j+1]->compareTo(v[i+1])) > 0 then ( spend := Set{spend, e + R * (j - i) - E}->min() ) else skip) ; spend := Set{spend, 0}->max() ; e := e - spend ; e := Set{e + R, E}->min() ; gainz := gainz + v[i+1] * spend) ; execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{tc + 1, gainz}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) a=set(a) a=sorted(a) for i in range(len(a)-1): if a[i]+a[i]>a[i+1]: print('YES') exit(0) print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := Set{}->union((a)) ; a := a->sort() ; for i : Integer.subrange(0, (a)->size() - 1-1) do ( if (a[i+1] + a[i+1]->compareTo(a[i + 1+1])) > 0 then ( execute ('YES')->display() ; exit(0) ) else skip) ; execute ('NO')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def s(): input() a=list(map(int,input().split())) a.sort() for i in range(1,len(a)): if a[i]!=a[i-1]and a[i]display(); operation s() : OclAny pre: true post: true activity: input() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; for i : Integer.subrange(1, (a)->size()-1) do ( if a[i+1] /= a[i - 1+1] & (a[i+1]->compareTo(a[i - 1+1] * 2)) < 0 then ( return 'YES' ) else skip) ; return 'NO'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): N=int(input()) print(max(0,N-2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (Set{0, N - 2}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) i=1 while i<=a : b=int(input()) print(max(0,b-2)) i=i+1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 1 ; while (i->compareTo(a)) <= 0 do ( var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (Set{0, b - 2}->max())->display() ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): a=int(input()) if a<2 : print(0) if a>=2 : print(a-2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if a < 2 then ( execute (0)->display() ) else skip ; if a >= 2 then ( execute (a - 2)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline t=int(input()) for tests in range(t): n=int(input()) print(max(0,n-2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for tests : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (Set{0, n - 2}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for i in range(T): a=int(input()) print(max(0,a-2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, T-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (Set{0, a - 2}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input ; print("IO hb,e cmoym ek etyhbeo agrudy!."[int(a())>len(set(a().split()[1 :]+a().split()[1 :])): : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := input; execute ("IO hb,e cmoym ek etyhbeo agrudy!."(subscript (test (logical_test (comparison (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments ( ))))))))) ))))) > (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) + (expr (atom (name a)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))))))))) ))))))))) )))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): s=S() k=I() l=0 for c in s : if c!='1' : break l+=1 if l>=k : return 1 return s[l] print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : double := (10)->pow(9) + 7 ; var dd : Sequence := Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{ Sequence{0, -1} }))) ; var ddn : Sequence := Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{-1, 1}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{1, 1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{1, -1}}->union(Sequence{Sequence{0, -1}}->union(Sequence{ Sequence{-1, -1} }))))))) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: s := S() ; var k : OclAny := I() ; var l : int := 0 ; for c : s do ( if c /= '1' then ( break ) else skip ; l := l + 1) ; if (l->compareTo(k)) >= 0 then ( return 1 ) else skip ; return s[l+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input().split() s=s[1 :] s1=input().split() s1=s1[1 :] x=False y=False p=[] for i in s : if int(i)not in p : p+=[int(i)] for i in s1 : if int(i)not in p : p+=[int(i)] for i in range(1,n+1): if i in p : x=True else : x=False break if x==True : print("I become the guy.") else : print("Oh,my keyboard!") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := input().split() ; s := s->tail() ; var s1 : OclAny := input().split() ; s1 := s1->tail() ; var x : boolean := false ; var y : boolean := false ; var p : Sequence := Sequence{} ; for i : s do ( if (p)->excludes(("" + ((i)))->toInteger()) then ( p := p + Sequence{ ("" + ((i)))->toInteger() } ) else skip) ; for i : s1 do ( if (p)->excludes(("" + ((i)))->toInteger()) then ( p := p + Sequence{ ("" + ((i)))->toInteger() } ) else skip) ; for i : Integer.subrange(1, n + 1-1) do ( if (p)->includes(i) then ( x := true ) else ( x := false ; break )) ; if x = true then ( execute ("I become the guy.")->display() ) else ( execute ("Oh,my keyboard!")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() p=a.index('^') c=sum((i-p)*int(y)for i,y in enumerate(a)if y.isdigit()) print([['balance','right'][c>0],'left'][c<0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var p : int := a->indexOf('^') - 1 ; var c : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (name p)))))))) ))) * (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (atom (name y)) (trailer . (name isdigit) (arguments ( )))))))))))->sum() ; execute (Sequence{Sequence{'balance'}->union(Sequence{ 'right' })->select(c > 0)}->union(Sequence{ 'left' })->select(c < 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) num_1=input().split() num_1=num_1[1 :] num_2=input().split() num_2=num_2[1 :] flag_1=False num_3=num_1+num_2 num_4=[] for i in num_3 : if int(i)not in num_4 : num_4.append(int(i)) for i in range(1,n+1): if i in num_4 : flag_1=True else : flag_1=False break if flag_1 is True : print('I become the guy.') else : print('Oh,my keyboard!') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var num var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() : OclAny := input().split() ; num var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() := num var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()->tail() ; var num:= input().split() : OclAny := input().split() ; num:= num_2->tail() := num_2->tail() ; var flag var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() : boolean := false ; var num_3 : OclAny := num var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() + num_2 ; var num_4 : Sequence := Sequence{} ; for i : num if (num_4)->excludes(("" + ((i)))->toInteger()) then ( execute ((("" + ((i)))->toInteger()) : num_4) ) else skip do ( if (num_4)->excludes(("" + ((i)))->toInteger()) then ( execute ((("" + ((i)))->toInteger()) : num_4) ) else skip) ; for i : Integer.subrange(1, n + 1-1) do ( if (num_4)->includes(i) then ( flag var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() := true ) else ( flag var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() := false ; break )) ; if flag var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() <>= true then ( execute ('I become the guy.')->display() ) else ( execute ('Oh,my keyboard!')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- max_level=int(input()) x=list(map(int,input().split())) y=list(map(int,input().split())) x.pop(0) y.pop(0) x=set(x) y=set(y) if 0 in x : x.discard(0) elif 0 in y : y.discard(0) z=x.union(y) if len(z)!=max_level : print("Oh,my keyboard!") else : print("I become the guy.") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var max_level : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var y : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; x := x->excludingAt(0+1) ; y := y->excludingAt(0+1) ; x := Set{}->union((x)) ; y := Set{}->union((y)) ; if (x)->includes(0) then ( execute ((0) /: x) ) else (if (y)->includes(0) then ( execute ((0) /: y) ) else skip) ; var z : OclAny := x.union(y) ; if (z)->size() /= max_level then ( execute ("Oh,my keyboard!")->display() ) else ( execute ("I become the guy.")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lst1=list(map(int,input().split()))[1 :] lst2=list(map(int,input().split()))[1 :] st=set() for i in lst1 : st.add(i) for j in lst2 : st.add(j) if len(st)==n : print('I become the guy.') else : print('Oh,my keyboard!') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst1 : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->tail() ; var lst2 : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->tail() ; var st : Set := Set{}->union(()) ; for i : lst1 do ( execute ((i) : st)) ; for j : lst2 do ( execute ((j) : st)) ; if (st)->size() = n then ( execute ('I become the guy.')->display() ) else ( execute ('Oh,my keyboard!')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,n=6,4 ; def linearCheck(ar,arr): for i in range(m): matched=True ; for j in range(n): if(ar[i][j]!=arr[j]): matched=False ; break ; if(matched): return i+1 ; return-1 ; if __name__=="__main__" : mat=[[0,0,1,0],[10,9,22,23],[40,40,40,40],[43,44,55,68],[81,73,100,132],[100,75,125,133]]; row=[10,9,22,23]; print(linearCheck(mat,row)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := Sequence{6,4}; ; skip ; if __name__ = "__main__" then ( var mat : Sequence := Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 0 })))}->union(Sequence{Sequence{10}->union(Sequence{9}->union(Sequence{22}->union(Sequence{ 23 })))}->union(Sequence{Sequence{40}->union(Sequence{40}->union(Sequence{40}->union(Sequence{ 40 })))}->union(Sequence{Sequence{43}->union(Sequence{44}->union(Sequence{55}->union(Sequence{ 68 })))}->union(Sequence{Sequence{81}->union(Sequence{73}->union(Sequence{100}->union(Sequence{ 132 })))}->union(Sequence{ Sequence{100}->union(Sequence{75}->union(Sequence{125}->union(Sequence{ 133 }))) }))))); ; var row : Sequence := Sequence{10}->union(Sequence{9}->union(Sequence{22}->union(Sequence{ 23 }))); ; execute (linearCheck(mat, row))->display(); ) else skip; operation linearCheck(ar : OclAny, arr : OclAny) pre: true post: true activity: for i : Integer.subrange(0, m-1) do ( var matched : boolean := true; ; for j : Integer.subrange(0, n-1) do ( if (ar[i+1][j+1] /= arr[j+1]) then ( matched := false; ; break; ) else skip) ; if (matched) then ( return i + 1; ) else skip) ; return -1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) while n : p=int(input()) l=list(map(int,input().split())) c=0 s=sum(l) if s % p==0 : for i in range(p): if l[i]>s//p : c+=1 print(c) else : print(-1) n-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while n do ( var p : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; var s : OclAny := (l)->sum() ; if s mod p = 0 then ( for i : Integer.subrange(0, p-1) do ( if (l[i+1]->compareTo(s div p)) > 0 then ( c := c + 1 ) else skip) ; execute (c)->display() ) else ( execute (-1)->display() ) ; n := n - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): b=int(input()) a=[int(i)for i in input().split()] if sum(a)% b!=0 : print(-1) else : s=sum(a)/b d=[i for i in a if i>s] print(len(d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if (a)->sum() mod b /= 0 then ( execute (-1)->display() ) else ( var s : double := (a)->sum() / b ; var d : Sequence := a->select(i | (i->compareTo(s)) > 0)->collect(i | (i)) ; execute ((d)->size())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for x in range(t): n=int(input()) inp1=list(map(int,input().split())) if(sum(inp1)% n!=0): print(-1) else : cnt=0 comp=sum(inp1)/n j2=[x for x in inp1 if x>comp] print(len(j2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for x : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var inp1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if ((inp1)->sum() mod n /= 0) then ( execute (-1)->display() ) else ( var cnt : int := 0 ; var comp : double := (inp1)->sum() / n ; var j2 : Sequence := inp1->select(x | (x->compareTo(comp)) > 0)->collect(x | (x)) ; execute ((j2)->size())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for x in range(t): n=int(input()) inp1=list(map(int,input().split())) if(sum(inp1)% n!=0): print(-1) else : cnt=0 comp=sum(inp1)/n for i in inp1 : if(i>comp): cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for x : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var inp1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if ((inp1)->sum() mod n /= 0) then ( execute (-1)->display() ) else ( var cnt : int := 0 ; var comp : double := (inp1)->sum() / n ; for i : inp1 do ( if ((i->compareTo(comp)) > 0) then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : t-=1 n=int(input()) arr=list(map(int,input().split())) arr.sort() total=sum(arr) avg=int(total/n) if avg*n!=total : print("-1") else : i=0 while iavg : break i+=1 print(n-i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( t := t - 1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := arr->sort() ; var total : OclAny := (arr)->sum() ; var avg : int := ("" + ((total / n)))->toInteger() ; if avg * n /= total then ( execute ("-1")->display() ) else ( var i : int := 0 ; while (i->compareTo(n)) < 0 do ( if (arr[i+1]->compareTo(avg)) > 0 then ( break ) else skip ; i := i + 1) ; execute (n - i)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=list(input()) K=int(input()) for i in range(K): n=int(S[i]) if n==1 : if K-1==i : print(1) exit(0) else : print(n) exit(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, K-1) do ( var n : int := ("" + ((S[i+1])))->toInteger() ; if n = 1 then ( if K - 1 = i then ( execute (1)->display() ; exit(0) ) else skip ) else ( execute (n)->display() ; exit(0) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() p=a.index('^') c=sum((i-p)*int(y)for i,y in enumerate(a)if y.isdigit()) print([['balance','right'][c>0],'left'][c<0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var p : int := a->indexOf('^') - 1 ; var c : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (name p)))))))) ))) * (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (atom (name y)) (trailer . (name isdigit) (arguments ( )))))))))))->sum() ; execute (Sequence{Sequence{'balance'}->union(Sequence{ 'right' })->select(c > 0)}->union(Sequence{ 'left' })->select(c < 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) t=list(map(int,input().split())) v=list(map(int,input().split())) time=0 sum_t=sum(t) velo_cap=[float("inf")]*(2*sum_t+1) for i in range(N): start_t=time goal_t=time+2*t[i] for s in range(0,2*sum_t+1): if stoInteger() ; var t : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var v : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var time : int := 0 ; var sum_t : OclAny := (t)->sum() ; var velo_cap : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (("inf")))->toReal() }, (2 * sum_t + 1)) ; for i : Integer.subrange(0, N-1) do ( var start_t : int := time ; var goal_t : int := time + 2 * t[i+1] ; for s : Integer.subrange(0, 2 * sum_t + 1-1) do ( if (s->compareTo(start_t)) < 0 then ( velo_cap[s+1] := Set{velo_cap[s+1], 2 * v[i+1] + (start_t - s)}->min() ) else (if (s->compareTo(goal_t)) < 0 then ( velo_cap[s+1] := Set{velo_cap[s+1], 2 * v[i+1]}->min() ) else ( velo_cap[s+1] := Set{velo_cap[s+1], 2 * v[i+1] + (s - goal_t)}->min() ) ) ) ; time := time + 2 * t[i+1]) ; for s : Integer.subrange(0, 2 * sum_t + 1-1) do ( velo_cap[s+1] := Set{velo_cap[s+1], 2 * sum_t - s, s}->min()) ; execute ((velo_cap)->sum() / 4 - (velo_cap->first() + velo_cap->last()) / 8)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np N=int(input()) t=np.array(['0']+input().split(),np.int64) v=list(map(int,input().split())) T=np.cumsum(t).tolist() arrival=T[-1] times=np.arange(0,arrival+0.5,0.5) speed_limit=np.minimum(times,times[: :-1]) for i,j,k in zip(T,T[1 :],v): speed1=i-times+k speed2=np.full(arrival*2+1,k,np.float) speed3=times-j+k speed=np.maximum(speed1,speed3) speed=np.maximum(speed2,speed) speed_limit=np.minimum(speed_limit,speed) answer=np.abs(speed_limit[1 :]+speed_limit[:-1])*0.5/2 print(answer.sum()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : Sequence := (Sequence{ '0' }->union(input().split()), ) ; var v : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var T : OclAny := np.cumsum(t).tolist() ; var arrival : OclAny := T->last() ; var times : Sequence := MathLib.numericRange(0, arrival + 0.5, 0.5) ; var speed_limit : (trailer . (name minimum) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name times))))))) , (argument (test (logical_test (comparison (expr (atom (name times)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ])))))))) ))) := ; for _tuple : Integer.subrange(1, T->size())->collect( _indx | Sequence{T->at(_indx), T->tail()->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var k : OclAny := _tuple->at(_indx); var speed1 : double := i - times + k ; var speed2 : Sequence := MatrixLib.singleValueMatrix(arrival * 2 + 1, k) ; var speed3 : double := times - j + k ; var speed : (trailer . (name maximum) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name speed1))))))) , (argument (test (logical_test (comparison (expr (atom (name speed3)))))))) ))) := ; speed := ; speed_limit := ) ; var answer : double := * 0.5 / 2 ; execute (answer.sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import exit,setrecursionlimit,stderr from functools import reduce from itertools import* from collections import defaultdict,Counter from bisect import bisect import functools def read(): return int(input()) def reads(): return[int(x)for x in input().split()] N=read() t=reads() v=reads() psumt=[0]+list(accumulate(t)) T=psumt[-1] vs=[0]*(T+1) ans=0 for ss in range(0,2*T): s=ss/2 m=min(abs(s),min(v[i]+(abs(psumt[i]-s)+abs(psumt[i+1]-s)-t[i])/2 for i in range(N)),abs(T-s)) ans+=m/2 print('%.9f' % ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var N : OclAny := read() ; var t : OclAny := reads() ; var v : OclAny := reads() ; var psumt : Sequence := Sequence{ 0 }->union((accumulate(t))) ; var T : OclAny := psumt->last() ; var vs : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (T + 1)) ; var ans : int := 0 ; for ss : Integer.subrange(0, 2 * T-1) do ( var s : double := ss / 2 ; var m : OclAny := Set{(s)->abs(), ((argument (test (logical_test (comparison (expr (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name psumt)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name s))))))))) )))) + (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name psumt)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))) - (expr (atom (name s))))))))) ))))) - (expr (atom (name t)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))) / (expr (atom (number (integer 2))))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))))->min(), (T - s)->abs()}->min() ; ans := ans + m / 2) ; execute (StringLib.format('%.9f',ans))->display(); operation read() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation reads() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def spaceinput(): return list(map(int,input().split(" "))) def interval(t): pass N=int(input()) T=spaceinput() v=spaceinput() Tmax=0 for i in range(N): Tmax+=(T[i]) mv={} frange=[x for x in range(2*Tmax+1)] k=0 sT=T[0] d=0.5 mv[0]=0 for t in[x/2 for x in range(1,2*Tmax)]: if sTt : k-=1 sT-=T[k] mv[t]=min(v[k],mv[t],mv[t+d]+d) res=0 k=0 sT=T[0] for t in[x/2 for x in range(1,2*Tmax)]: if sTtoInteger() ; var T : OclAny := spaceinput() ; var v : OclAny := spaceinput() ; var Tmax : int := 0 ; for i : Integer.subrange(0, N-1) do ( Tmax := Tmax + (T[i+1])) ; var mv : OclAny := Set{} ; var frange : Sequence := Integer.subrange(0, 2 * Tmax + 1-1)->select(x | true)->collect(x | (x)) ; var k : int := 0 ; var sT : OclAny := T->first() ; var d : double := 0.5 ; mv->first() := 0 ; for t : Integer.subrange(1, 2 * Tmax-1)->select(x | true)->collect(x | (x / 2)) do ( if (sT->compareTo(t)) < 0 then ( k := k + 1 ; if (k->compareTo((T)->size())) < 0 then ( sT := sT + T[k+1] ) else ( break ) ) else skip ; mv[t+1] := Set{v[k+1], mv[t - 0.5+1] + d}->min()) ; mv[Tmax+1] := 0 ; k := N - 1 ; sT := Tmax - T->last() ; for t : (Integer.subrange(1, 2 * Tmax-1)->select(x | true)->collect(x | (x / 2)))->reverse() do ( if (sT->compareTo(t)) > 0 then ( k := k - 1 ; sT := sT - T[k+1] ) else skip ; mv[t+1] := Set{v[k+1], mv[t+1], mv[t + d+1] + d}->min()) ; var res : int := 0 ; k := 0 ; sT := T->first() ; for t : Integer.subrange(1, 2 * Tmax-1)->select(x | true)->collect(x | (x / 2)) do ( if (sT->compareTo(t)) < 0 then ( if t = Tmax - 1 then ( break ) else skip ; k := k + 1 ; if (k->compareTo((T)->size())) < 0 then ( sT := sT + T[k+1] ) else skip ) else skip ; res := res + mv[t+1] * 0.5) ; execute (res)->display(); operation spaceinput() : OclAny pre: true post: true activity: return ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )); operation interval(t : OclAny) pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin ni=lambda : int(ns()) na=lambda : list(map(int,stdin.readline().split())) ns=lambda : stdin.readline() n=ni() t=na() v=na() bound=[0]*(n+1) for i in range(n-1): bound[i+1]=min(v[i],v[i+1],bound[i]+t[i]) for i in range(n-1,0,-1): bound[i]=min(bound[i],v[i],v[i-1],bound[i+1]+t[i]) ans=0 for i in range(n): l=bound[i] r=bound[i+1] x=(r-l+t[i])/2 if l+x<=v[i]: ans+=(l+(l+x))*x/2+(l+x+r)*(t[i]-x)/2 else : ans+=(v[i]+l)*(v[i]-l)/2+(v[i]+r)*(v[i]-r)/2 ans+=(t[i]-(v[i]-l)-(v[i]-r))*v[i] print("{:.14f}".format(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stdin : OclFile := OclFile["System.in"] ; var ni : Function := lambda $$ : OclAny in (("" + ((ns())))->toInteger()) ; var na : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ns : Function := lambda $$ : OclAny in (stdin.readLine()) ; var n : OclAny := ni->apply() ; var t : OclAny := na->apply() ; var v : OclAny := na->apply() ; var bound : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(0, n - 1-1) do ( bound[i + 1+1] := Set{v[i+1], v[i + 1+1], bound[i+1] + t[i+1]}->min()) ; for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( bound[i+1] := Set{bound[i+1], v[i+1], v[i - 1+1], bound[i + 1+1] + t[i+1]}->min()) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var l : OclAny := bound[i+1] ; var r : OclAny := bound[i + 1+1] ; var x : double := (r - l + t[i+1]) / 2 ; if (l + x->compareTo(v[i+1])) <= 0 then ( ans := ans + (l + (l + x)) * x / 2 + (l + x + r) * (t[i+1] - x) / 2 ) else ( ans := ans + (v[i+1] + l) * (v[i+1] - l) / 2 + (v[i+1] + r) * (v[i+1] - r) / 2 ; ans := ans + (t[i+1] - (v[i+1] - l) - (v[i+1] - r)) * v[i+1] )) ; execute (StringLib.interpolateStrings("{:.14f}", Sequence{ans}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthTerm(n): return 2*pow(n,3)+pow(n,2) if __name__=="__main__" : N=3 print(nthTerm(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var N : int := 3 ; execute (nthTerm(N))->display() ) else skip; operation nthTerm(n : OclAny) : OclAny pre: true post: true activity: return 2 * (n)->pow(3) + (n)->pow(2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthTerm(n): return 3*pow(n,2)+n-2 N=4 print(nthTerm(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 4 ; execute (nthTerm(N))->display(); operation nthTerm(n : OclAny) : OclAny pre: true post: true activity: return 3 * (n)->pow(2) + n - 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthTerm(n): return 2*pow(n,2)-n-1 if __name__=="__main__" : N=4 print(nthTerm(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var N : int := 4 ; execute (nthTerm(N))->display() ) else skip; operation nthTerm(n : OclAny) : OclAny pre: true post: true activity: return 2 * (n)->pow(2) - n - 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthTerm(n): return 2*pow(n,2)+4*n-2 N=4 print(nthTerm(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 4 ; execute (nthTerm(N))->display(); operation nthTerm(n : OclAny) : OclAny pre: true post: true activity: return 2 * (n)->pow(2) + 4 * n - 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthTerm(n): return 5*pow(n,2)-5*n N=4 print(nthTerm(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 4 ; execute (nthTerm(N))->display(); operation nthTerm(n : OclAny) : OclAny pre: true post: true activity: return 5 * (n)->pow(2) - 5 * n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() p=a.index('^') c=sum((i-p)*int(y)for i,y in enumerate(a)if y.isdigit()) print([['balance','right'][c>0],'left'][c<0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var p : int := a->indexOf('^') - 1 ; var c : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (name p)))))))) ))) * (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (atom (name y)) (trailer . (name isdigit) (arguments ( )))))))))))->sum() ; execute (Sequence{Sequence{'balance'}->union(Sequence{ 'right' })->select(c > 0)}->union(Sequence{ 'left' })->select(c < 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def inp(): return(int(input())) def inlist(): return(list(map(int,input().split()))) def instr(): s=input() return(list(s[: len(s)])) def invr(): return(map(int,input().split())) a=input() k=inp() i=0 while i=k : print(1) elif len(a)==i : print(1) else : print(a[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var a : String := (OclFile["System.in"]).readLine() ; var k : OclAny := inp() ; var i : int := 0 ; while (i->compareTo((a)->size())) < 0 & a[i+1] = '1' do ( i := i + 1) ; if (i->compareTo(k)) >= 0 then ( execute (1)->display() ) else (if (a)->size() = i then ( execute (1)->display() ) else ( execute (a[i+1])->display() ) ) ; operation inp() : OclAny pre: true post: true activity: return (("" + (((OclFile["System.in"]).readLine())))->toInteger()); operation inlist() : OclAny pre: true post: true activity: return (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))); operation instr() : OclAny pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; return ((s.subrange(1,(s)->size()))); operation invr() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthTerm(n): return 7*pow(n,2)-7*n+7 N=4 print(nthTerm(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 4 ; execute (nthTerm(N))->display(); operation nthTerm(n : OclAny) : OclAny pre: true post: true activity: return 7 * (n)->pow(2) - 7 * n + 7; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* def nthTerm(n): return pow(n,2)-2*n+2 if __name__=="__main__" : N=4 print(nthTerm(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var N : int := 4 ; execute (nthTerm(N))->display() ) else skip; operation nthTerm(n : OclAny) : OclAny pre: true post: true activity: return (n)->pow(2) - 2 * n + 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* def nthTerm(n): return pow(n,2)+2*n+2 if __name__=="__main__" : N=4 print(nthTerm(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var N : int := 4 ; execute (nthTerm(N))->display() ) else skip; operation nthTerm(n : OclAny) : OclAny pre: true post: true activity: return (n)->pow(2) + 2 * n + 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=map(int,input().split()) c=abs(x)+abs(y) if x>0 and y>0 : print(0,c,c,0) if x<0 and y>0 : print(-c,0,0,c) if x>0 and y<0 : print(0,-c,c,0) if x<0 and y<0 : print(-c,0,0,-c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : double := (x)->abs() + (y)->abs() ; if x > 0 & y > 0 then ( execute (0)->display() ) else skip ; if x < 0 & y > 0 then ( execute (-c)->display() ) else skip ; if x > 0 & y < 0 then ( execute (0)->display() ) else skip ; if x < 0 & y < 0 then ( execute (-c)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=map(int,input().split()) x1=abs(x) y1=abs(y) if x>=0 and y>=0 : print(0," ",x1+y1," ",x1+y1," ",0,sep='') elif x<0 and y>0 : print("-",x1+y1," ",0," ",0," ",x1+y1,sep='') elif x<0 and y<0 : print("-",x1+y1," ",0," ",0,"-",x1+y1,sep='') elif x>0 and y<0 : print(0,"-",x1+y1," ",x1+y1," ",0,sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x1 : double := (x)->abs() ; var y1 : double := (y)->abs() ; if x >= 0 & y >= 0 then ( execute (0)->display() ) else (if x < 0 & y > 0 then ( execute ("-")->display() ) else (if x < 0 & y < 0 then ( execute ("-")->display() ) else (if x > 0 & y < 0 then ( execute (0)->display() ) else skip ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=map(int,input().split()) if(x<0)!=(y<0): p=[(x-y,0),(0,y-x)] else : p=[(x+y,0),(0,y+x)] p.sort() print(*p[0],*p[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (x < 0) /= (y < 0) then ( var p : Sequence := Sequence{Sequence{x - y, 0}}->union(Sequence{ Sequence{0, y - x} }) ) else ( p := Sequence{Sequence{x + y, 0}}->union(Sequence{ Sequence{0, y + x} }) ) ; p := p->sort() ; execute ((argument * (test (logical_test (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=map(int,input().split()) if(x>0 and y>0): print(0,x+y,x+y,0) elif(x<0 and y>0): print(x-y,0,0,abs(x)+y) elif(x<0 and y<0): print(x+y,0,0,x+y) else : print(0,y-x,abs(y)+x,0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (x > 0 & y > 0) then ( execute (0)->display() ) else (if (x < 0 & y > 0) then ( execute (x - y)->display() ) else (if (x < 0 & y < 0) then ( execute (x + y)->display() ) else ( execute (0)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=map(int,input().split()) if x>0 and y>0 : print(0,y+x,y+x,0) elif x<0 and y>0 : print(x-y,0,0,y-x) elif x>0 and y<0 : print(0,y-x,x-y,0) elif x<0 and y<0 : print(x+y,0,0,x+y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x > 0 & y > 0 then ( execute (0)->display() ) else (if x < 0 & y > 0 then ( execute (x - y)->display() ) else (if x > 0 & y < 0 then ( execute (0)->display() ) else (if x < 0 & y < 0 then ( execute (x + y)->display() ) else skip ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() K=int(input()) l=len(s) substr=[] for i in range(l): for k in range(K): substr.append(s[i : i+k+1]) if i+k+1>=l : break substr=list(set(substr)) substr.sort() print(substr[K-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : int := (s)->size() ; var substr : Sequence := Sequence{} ; for i : Integer.subrange(0, l-1) do ( for k : Integer.subrange(0, K-1) do ( execute ((s.subrange(i+1, i + k + 1)) : substr) ; if (i + k + 1->compareTo(l)) >= 0 then ( break ) else skip)) ; substr := (Set{}->union((substr))) ; substr := substr->sort() ; execute (substr[K - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def task4(A,B,n): for X in range(-1000,1001): if A*(X**n)==B : return X return "No solution" [A,B,n]=input().split() print(task4(int(A),int(B),int(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{A}->union(Sequence{B}->union(Sequence{ n })) := input().split() ; execute (task4(("" + ((A)))->toInteger(), ("" + ((B)))->toInteger(), ("" + ((n)))->toInteger()))->display(); operation task4(A : OclAny, B : OclAny, n : OclAny) : OclAny pre: true post: true activity: for X : Integer.subrange(-1000, 1001-1) do ( if A * ((X)->pow(n)) = B then ( return X ) else skip) ; return "No solution"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() a=s.index("^") sum=0 for i in range(len(s)): if s[i]!="=" and s[i]!="^" : sum+=int(s[i])*(i-a) if sum<0 : print("left") elif sum>0 : print("right") else : print("balance") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var a : int := s->indexOf("^") - 1 ; var sum : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] /= "=" & s[i+1] /= "^" then ( sum := sum + ("" + ((s[i+1])))->toInteger() * (i - a) ) else skip) ; if sum < 0 then ( execute ("left")->display() ) else (if sum > 0 then ( execute ("right")->display() ) else ( execute ("balance")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(input()) k=int(input()) l=[[i]for i in range(len(s))] a=[''.join([s[i]for i in x])for x in l] for _ in range(k): m=min(a) for i,x in enumerate(a): if x==m and l[i][-1]+1characters() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Integer.subrange(0, (s)->size()-1)->select(i | true)->collect(i | (Sequence{ i })) ; var a : Sequence := l->select(x | true)->collect(x | (StringLib.sumStringsWithSeparator((x->select(i | true)->collect(i | (s[i+1]))), ''))) ; for _anon : Integer.subrange(0, k-1) do ( var m : OclAny := (a)->min() ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); if x = m & (l[i+1]->last() + 1->compareTo((s)->size())) < 0 then ( (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))) + (expr (atom (number (integer 1)))))))))) )))) ) else (if x = m then ( l := l->excludingAt(i+1) ) else skip)) ; a := l->select(x | true)->collect(x | (StringLib.sumStringsWithSeparator((x->select(i | true)->collect(i | (s[i+1]))), '')))) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() k=int(input()) if len(s)==1 : print(s[0]) elif k==1 : print(s[0]) else : cnt=0 idx=0 for c in list(s): idx+=1 if c=="1" : cnt+=1 else : break if k<=cnt : print(1) else : print(s[idx-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (s)->size() = 1 then ( execute (s->first())->display() ) else (if k = 1 then ( execute (s->first())->display() ) else ( var cnt : int := 0 ; var idx : int := 0 ; for c : (s)->characters() do ( idx := idx + 1 ; if c = "1" then ( cnt := cnt + 1 ) else ( break )) ; if (k->compareTo(cnt)) <= 0 then ( execute (1)->display() ) else ( execute (s[idx - 1+1])->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from functools import reduce import copy import math sys.setrecursionlimit(4100000) def inputs(num_of_input): ins=[input()for i in range(num_of_input)] return ins def solve(inputs): S=inputs[0] K=int(inputs[1]) sets=set() for i in range(len(S)): j=i while jdisplay() ) else skip; operation inputs(num_of_input : OclAny) : OclAny pre: true post: true activity: var ins : Sequence := Integer.subrange(0, num_of_input-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; return ins; operation solve(inputs : OclAny) : OclAny pre: true post: true activity: var S : OclAny := inputs->first() ; var K : int := ("" + ((inputs[1+1])))->toInteger() ; var sets : Set := Set{}->union(()) ; for i : Integer.subrange(0, (S)->size()-1) do ( var j : OclAny := i ; while (j->compareTo((S)->size())) < 0 & (j - i->compareTo(K)) <= 0 do ( j := j + 1) ; execute ((S.subrange(i+1, j)) : sets)) ; var new_sets : Set := Set{}->union(()) ; for k : sets do ( for i : Integer.subrange(0, (k)->size()-1) do ( j := i ; while (j->compareTo((k)->size())) < 0 & (j - i->compareTo(K)) <= 0 do ( j := j + 1 ; execute ((k.subrange(i+1, j)) : new_sets)))) ; var l : Sequence := (new_sets) ; l := l->sort() ; return l[K - 1+1]; operation string_to_int(string : OclAny) : OclAny pre: true post: true activity: return ((string.split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(myC,s,chrs,lst,k): if len(lst)==k : print(lst[k-1]) exit() else : for c in chrs : buf=myC+c if buf in s : lst+=[buf] f(buf,s,chrs,lst,k) if __name__=='__main__' : s=input() k=int(input()) chrs=sorted(list(set(s))) lst=f('',s,chrs,list(),k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( s := (OclFile["System.in"]).readLine() ; k := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; chrs := (Set{}->union((s)))->sort() ; lst := f('', s, chrs, (), k) ) else skip; operation f(myC : OclAny, s : OclAny, chrs : OclAny, lst : OclAny, k : OclAny) pre: true post: true activity: if (lst)->size() = k then ( execute (lst[k - 1+1])->display() ; exit() ) else ( for c : chrs do ( var buf : OclAny := myC + c ; if (s)->includes(buf) then ( lst := lst + Sequence{ buf } ; f(buf, s, chrs, lst, k) ) else skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() n=input() ans=set([]) test=list(s) for i in range(len(test)): s=test[i] ans.add(s) for j in range(i+1,min(i+5,len(test))): s=s+test[j] ans.add(s) ans=list(ans) ans.sort() print(ans[int(n)-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var n : String := (OclFile["System.in"]).readLine() ; var ans : Set := Set{}->union((Sequence{})) ; var test : Sequence := (s)->characters() ; for i : Integer.subrange(0, (test)->size()-1) do ( s := test[i+1] ; execute ((s) : ans) ; for j : Integer.subrange(i + 1, Set{i + 5, (test)->size()}->min()-1) do ( s := s + test[j+1] ; execute ((s) : ans))) ; ans := (ans) ; ans := ans->sort() ; execute (ans[("" + ((n)))->toInteger() - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def __init__(self): self.memo=[] self.memo.append(0) self.memo.append(1) def fib(self,N): if Nexists( _x | result = _x ); attribute memo : Sequence := Sequence{}; operation initialise() : pre: true post: true activity: self.memo := Sequence{} ; (expr (atom (name self)) (trailer . (name memo)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))) ; (expr (atom (name self)) (trailer . (name memo)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))); return self; operation fib(N : OclAny) : OclAny pre: true post: true activity: if (N->compareTo((self.memo)->size())) < 0 then ( return self.memo[N+1] ) else skip ; for i : Integer.subrange((self.memo)->size(), N + 1-1) do ((expr (atom (name self)) (trailer . (name memo)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name self)) (trailer . (name memo) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))) + (expr (atom (name self)) (trailer . (name memo) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 2)))))))))) ]))))))))) ))))) ; return self.memo[N+1]; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import io,os,sys from collections import Counter t=int(input()) def GO_LIFE(): a=list(input()) b=list(input()) p=Counter(a) n=len(a) ok=0 for i in b : if p[i]==0 : ok=1 if b!=sorted(b)or ok==1 : for i in sorted(a): print(i,end="") print() return a.sort() q1=[] q2=[] q=[] for i in range(n-1,-1,-1): if a[i]=='c' : q+=[i] if a[i]=='b' : q1.insert(0,i) i,j=0,0 while j0 : GO_LIFE() t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; while t > 0 do ( GO_LIFE() ; t := t - 1); operation GO_LIFE() pre: true post: true activity: var a : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var b : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var p : OclAny := Counter(a) ; var n : int := (a)->size() ; var ok : int := 0 ; for i : b do ( if p[i+1] = 0 then ( ok := 1 ) else skip) ; if b /= b->sort() or ok = 1 then ( for i : a->sort() do ( execute (i)->display()) ; execute (->display() ; return ) else skip ; a := a->sort() ; var q1 : Sequence := Sequence{} ; var q2 : Sequence := Sequence{} ; var q : Sequence := Sequence{} ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if a[i+1] = 'c' then ( q := q + Sequence{ i } ) else skip ; if a[i+1] = 'b' then ( q1 := q1.insertAt(0+1, i) ) else skip) ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,0} ; while (j->compareTo((q1)->size())) < 0 & (i->compareTo((q)->size())) < 0 do ( var a[q[i+1]+1] : OclAny := null; var a[q1[j+1]+1] : OclAny := null; Sequence{a[q[i+1]+1],a[q1[j+1]+1]} := Sequence{a[q1[j+1]+1],a[q[i+1]+1]} ; i := i + 1 ; j := j + 1) ; for i : a do ( execute (i)->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) ans=[] for _ in range(q): s=list(input().rstrip()) t=list(input().rstrip()) s.sort() if "".join(t)=="abc" : sa,sb,sc=s.count("a"),s.count("b"),s.count("c") if min(sa,sb,sc): l,r=sa,sa+sb+sc j=r-1 for i in range(l,r): if i>=j : break s[i],s[j]=s[j],s[i] j-=1 print("".join(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, q-1) do ( var s : Sequence := (input().rstrip()) ; var t : Sequence := (input().rstrip()) ; s := s->sort() ; if StringLib.sumStringsWithSeparator((t), "") = "abc" then ( var sa : OclAny := null; var sb : OclAny := null; var sc : OclAny := null; Sequence{sa,sb,sc} := Sequence{s->count("a"),s->count("b"),s->count("c")} ; if Set{sa, sb, sc}->min() then ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{sa,sa + sb + sc} ; var j : double := r - 1 ; for i : Integer.subrange(l, r-1) do ( if (i->compareTo(j)) >= 0 then ( break ) else skip ; var s[i+1] : OclAny := null; var s[j+1] : OclAny := null; Sequence{s[i+1],s[j+1]} := Sequence{s[j+1],s[i+1]} ; j := j - 1) ) else skip ) else skip ; execute (StringLib.sumStringsWithSeparator((s), ""))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): s=sorted(list(input())) t=input() if 'a' not in s or 'b' not in s or 'c' not in s or t!='abc' : print(''.join(s)) else : i1,i2,i3=s.index('b'),s.index('c'),min(''.join(s).rfind('c'),len(s)-1) print(''.join(s[: i1])+'c'*(i3-i2+1)+'b'*(i2-i1)+''.join(s[i3+1 :])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : Sequence := ((OclFile["System.in"]).readLine())->characters()->sort() ; var t : String := (OclFile["System.in"]).readLine() ; if (s)->excludes('a') or (s)->excludes('b') or (s)->excludes('c') or t /= 'abc' then ( execute (StringLib.sumStringsWithSeparator((s), ''))->display() ) else ( var i1 : OclAny := null; var i2 : OclAny := null; var i3 : OclAny := null; Sequence{i1,i2,i3} := Sequence{s->indexOf('b') - 1,s->indexOf('c') - 1,Set{''.join(s).rfind('c'), (s)->size() - 1}->min()} ; execute (StringLib.sumStringsWithSeparator((s.subrange(1,i1)), '') + StringLib.nCopies('c', (i3 - i2 + 1)) + StringLib.nCopies('b', (i2 - i1)) + StringLib.sumStringsWithSeparator((s.subrange(i3 + 1+1)), ''))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) for _ in range(0,a): t=sorted(list(input())) s=list(input()) if s==['a','b','c']and 'a' in t and 'b' in t and 'c' in t : x=t.count('a') y=t.count('b') z=t.count('c') res=(['a']*x)+(['c']*z)+(['b']*y) for i in range(len(t)): if t[i]!='a' and t[i]!='b' and t[i]!='c' : res+=t[i :] break else : res=sorted(t) print(''.join(res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, a-1) do ( var t : Sequence := ((OclFile["System.in"]).readLine())->characters()->sort() ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if s = Sequence{'a'}->union(Sequence{'b'}->union(Sequence{ 'c' })) & (t)->includes('a') & (t)->includes('b') & (t)->includes('c') then ( var x : int := t->count('a') ; var y : int := t->count('b') ; var z : int := t->count('c') ; var res : Sequence := (MatrixLib.elementwiseMult(Sequence{ 'a' }, x))->union((MatrixLib.elementwiseMult(Sequence{ 'c' }, z)))->union((MatrixLib.elementwiseMult(Sequence{ 'b' }, y))) ; for i : Integer.subrange(0, (t)->size()-1) do ( if t[i+1] /= 'a' & t[i+1] /= 'b' & t[i+1] /= 'c' then ( res := res + t.subrange(i+1) ; break ) else skip) ) else ( res := t->sort() ) ; execute (StringLib.sumStringsWithSeparator((res), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() r=s.index("^") sum=0 for i in range(len(s)): if s[i]!="=" and s[i]!="^" : sum+=int(s[i])*(i-r) if sum<0 : print("left") elif sum>0 : print("right") else : print("balance") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var r : int := s->indexOf("^") - 1 ; var sum : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] /= "=" & s[i+1] /= "^" then ( sum := sum + ("" + ((s[i+1])))->toInteger() * (i - r) ) else skip) ; if sum < 0 then ( execute ("left")->display() ) else (if sum > 0 then ( execute ("right")->display() ) else ( execute ("balance")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- PI=3.142 ; def cosXSertiesSum(x,n): x=x*(PI/180.0); res=1 ; sign=1 ; fact=1 ; pow=1 ; for i in range(1,5): sign=sign*-1 ; fact=fact*(2*i-1)*(2*i); pow=pow*x*x ; res=res+sign*pow/fact ; return res ; x=50 ; n=5 ; print(round(cosXSertiesSum(x,5),6)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var PI : double := 3.142; ; skip ; x := 50; ; n := 5; ; execute (MathLib.roundN(cosXSertiesSum(x, 5), 6))->display();; operation cosXSertiesSum(x : OclAny, n : OclAny) pre: true post: true activity: x := x * (PI / 180.0); ; var res : int := 1; ; var sign : int := 1; ; var fact : int := 1; ; var pow : int := 1; ; for i : Integer.subrange(1, 5-1) do ( sign := sign * -1; ; fact := fact * (2 * i - 1) * (2 * i); ; pow := pow * x * x; ; res := res + sign * pow / fact;) ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNumber(N,S): i=(((N)*(N+1))/4)-((S+1)/2); return i ; def check(N,S): i=findNumber(N,S); integerI=int(i); if(i-integerI==0): print("Yes:",integerI,",",integerI+1); else : print("No"); if __name__=="__main__" : N=4 ; S=3 ; check(N,S); N=5 ; S=3 ; check(N,S); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( N := 4; ; S := 3; ; check(N, S); ; N := 5; ; S := 3; ; check(N, S); ) else skip; operation findNumber(N : OclAny, S : OclAny) pre: true post: true activity: var i : double := (((N) * (N + 1)) / 4) - ((S + 1) / 2); ; return i;; operation check(N : OclAny, S : OclAny) pre: true post: true activity: i := findNumber(N, S); ; var integerI : int := ("" + ((i)))->toInteger(); ; if (i - integerI = 0) then ( execute ("Yes:")->display(); ) else ( execute ("No")->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() k=int(input()) def ans(): if len(S)==1 : return S else : for i in range(len(S)): if i+1==k : return S[i] if S[i]!='1' : return S[i] return 1 print(ans()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; execute (ans())->display(); operation ans() : OclAny pre: true post: true activity: if (S)->size() = 1 then ( return S ) else ( for i : Integer.subrange(0, (S)->size()-1) do ( if i + 1 = k then ( return S[i+1] ) else skip ; if S[i+1] /= '1' then ( return S[i+1] ) else skip) ) ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def multipleOfThree(K,dig0,dig1): sum=0 temp=(dig0+dig1)% 10 sum=dig0+dig1 if(K==2): if(sum % 3==0): return True else : return False sum+=temp numberofGroups=(K-3)//4 remNumberofDigits=(K-3)% 4 sum+=(numberofGroups*20) for i in range(remNumberofDigits): temp=(2*temp)% 10 sum+=temp if(sum % 3==0): return True else : return False if __name__=="__main__" : K=5 dig0=3 dig1=4 if(multipleOfThree(K,dig0,dig1)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( K := 5 ; dig0 := 3 ; dig1 := 4 ; if (multipleOfThree(K, dig0, dig1)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation multipleOfThree(K : OclAny, dig0 : OclAny, dig1 : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; var temp : int := (dig0 + dig1) mod 10 ; sum := dig0 + dig1 ; if (K = 2) then ( if (sum mod 3 = 0) then ( return true ) else ( return false ) ) else skip ; sum := sum + temp ; var numberofGroups : int := (K - 3) div 4 ; var remNumberofDigits : int := (K - 3) mod 4 ; sum := sum + (numberofGroups * 20) ; for i : Integer.subrange(0, remNumberofDigits-1) do ( temp := (2 * temp) mod 10 ; sum := sum + temp) ; if (sum mod 3 = 0) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(x)for x in input().split()] b=[int(x)for x in input().split()] total=sum(a) b.sort() print('YES' if total<=b[-1]+b[-2]else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var b : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var total : OclAny := (a)->sum() ; b := b->sort() ; execute (if (total->compareTo(b->last() + b->front()->last())) <= 0 then 'YES' else 'NO' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=lambda : map(int,input().split()) f() a,b=sum(f()),f() print(("YES","NO")[a>sum(sorted(b)[-2 :])]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; f() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{(f->apply())->sum(),f->apply()} ; execute (Sequence{"YES", "NO"}->select((a->compareTo((sorted(b).subrange(-2+1))->sum())) > 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=lambda : map(int,input().split()) f() a=sum(f()) *k,b,c=sorted(f()) print(("YES","NO")[a>b+c]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; f() ; var a : OclAny := (f->apply())->sum() ; var k : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{k,b,c} := f->apply()->sort() ; execute (Sequence{"YES", "NO"}->select((a->compareTo(b + c)) > 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=lambda : map(int,input().split()) i(); a=sum(i());*_,b,c=sorted(i()) print('YNEOS'[a>b+c : : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; i(); var a : OclAny := (i->apply())->sum(); var _anon : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{_anon,b,c} := i->apply()->sort() ; execute ('YNEOS'(subscript (test (logical_test (comparison (comparison (expr (atom (name a)))) > (comparison (expr (expr (atom (name b))) + (expr (atom (name c)))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) M=list(map(int,input().split(' '))) N=list(map(int,input().split(' '))) x=0 for p in range(a): x=x+M[p] y=max(N) N.remove(y) z=max(N) N.remove(z) if z+y>=x : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var M : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var N : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var x : int := 0 ; for p : Integer.subrange(0, a-1) do ( x := x + M[p+1]) ; var y : OclAny := (N)->max() ; execute ((y) /: N) ; var z : OclAny := (N)->max() ; execute ((z) /: N) ; if (z + y->compareTo(x)) >= 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countOcc(s): cnt=0 for i in range(0,len(s)-3): c,l,a,p=0,0,0,0 for j in range(i,i+4): if s[j]=='c' : c+=1 elif s[j]=='l' : l+=1 elif s[j]=='a' : a+=1 elif s[j]=='p' : p+=1 if c==1 and l==1 and a==1 and p==1 : cnt+=1 return cnt if __name__=="__main__" : s="clapc" print(countOcc(s.lower())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "clapc" ; execute (countOcc(s->toLowerCase()))->display() ) else skip; operation countOcc(s : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; for i : Integer.subrange(0, (s)->size() - 3-1) do ( var c : OclAny := null; var l : OclAny := null; var a : OclAny := null; var p : OclAny := null; Sequence{c,l,a,p} := Sequence{0,0,0,0} ; for j : Integer.subrange(i, i + 4-1) do ( if s[j+1] = 'c' then ( c := c + 1 ) else (if s[j+1] = 'l' then ( l := l + 1 ) else (if s[j+1] = 'a' then ( a := a + 1 ) else (if s[j+1] = 'p' then ( p := p + 1 ) else skip ) ) ) ) ; if c = 1 & l = 1 & a = 1 & p = 1 then ( cnt := cnt + 1 ) else skip) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def normalSieve(n): prime=[0]*int(n/2); i=3 ; while(i*itoInteger()); ; var i : int := 3; ; while ((i * i->compareTo(n)) < 0) do ( if (prime[("" + ((i / 2)))->toInteger()+1] = 0) then ( var j : int := i * i; ; while ((j->compareTo(n)) < 0) do ( prime[("" + ((j / 2)))->toInteger()+1] := 1; ; j := j + i * 2;) ) else skip ; i := i + 2;) ; execute (2)->display(); ; i := 3; ; while ((i->compareTo(n)) < 0) do ( if (prime[("" + ((i / 2)))->toInteger()+1] = 0) then ( execute (i)->display(); ) else skip ; i := i + 2;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def countSteps(x,y): if(x % y==0): return math.floor(x/y); return math.floor((x/y)+countSteps(y,x % y)); x=100 ; y=19 ; print(countSteps(x,y)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; x := 100; ; y := 19; ; execute (countSteps(x, y))->display();; operation countSteps(x : OclAny, y : OclAny) pre: true post: true activity: if (x mod y = 0) then ( return (x / y)->floor(); ) else skip ; return ((x / y) + countSteps(y, x mod y))->floor();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def isPerfectSquare(x): sr=mt.sqrt(x) return((sr-mt.floor(sr))==0) def isSunnyNum(n): if(isPerfectSquare(n+1)): return True return False n=3 if(isSunnyNum(n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 3 ; if (isSunnyNum(n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isPerfectSquare(x : OclAny) : OclAny pre: true post: true activity: var sr : double := mt.sqrt(x) ; return ((sr - mt.floor(sr)) = 0); operation isSunnyNum(n : OclAny) : OclAny pre: true post: true activity: if (isPerfectSquare(n + 1)) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- PI=3.14159265 def area_inscribed(P,B,H): return((P+B-H)*(P+B-H)*(PI/4)) P=3 B=4 H=5 print(area_inscribed(P,B,H)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var PI : double := 3.14159265 ; skip ; P := 3 ; B := 4 ; H := 5 ; execute (area_inscribed(P, B, H))->display(); operation area_inscribed(P : OclAny, B : OclAny, H : OclAny) : OclAny pre: true post: true activity: return ((P + B - H) * (P + B - H) * (PI / 4)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math N=int(input()) def hoge(n): if n==2 : return True for x in range(2,int(math.sqrt(n)+2)): if n % x==0 : return False return True while True : if hoge(N): print(N) exit() N+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; while true do ( if hoge(N) then ( execute (N)->display() ; exit() ) else skip ; N := N + 1); operation hoge(n : OclAny) : OclAny pre: true post: true activity: if n = 2 then ( return true ) else skip ; for x : Integer.subrange(2, ("" + (((n)->sqrt() + 2)))->toInteger()-1) do ( if n mod x = 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if n==0 : break d={} for _ in[0]*n : k,v=input().strip().split() d[k]=v for _ in[0]*int(input()): e=input().strip() print(d[e]if e in d else e,end='') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var d : OclAny := Set{} ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, n) do ( var k : OclAny := null; var v : OclAny := null; Sequence{k,v} := input()->trim().split() ; d[k+1] := v) ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var e : OclAny := input()->trim() ; execute (if (d)->includes(e) then d[e+1] else e endif)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(raw_input()) if n==0 : break else : henkan=[] for i in range(n): henkan.append(raw_input().split()) m=int(raw_input()) ans="" for i in range(m): c=raw_input().split() for j in range(len(henkan)): if c[0]==henkan[j][0]: c[0]=henkan[j][1] break ans+=c[0] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + ((raw_input())))->toInteger() ; if n = 0 then ( break ) else ( var henkan : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((raw_input().split()) : henkan)) ; var m : int := ("" + ((raw_input())))->toInteger() ; var ans : String := "" ; for i : Integer.subrange(0, m-1) do ( var c : OclAny := raw_input().split() ; for j : Integer.subrange(0, (henkan)->size()-1) do ( if c->first() = henkan[j+1]->first() then ( c->first() := henkan[j+1][1+1] ; break ) else skip) ; ans := ans + c->first()) ; execute (ans)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys while True : ans=[] flag=0 n=int(input()) if n==0 : break a=[[i for i in input().split()]for i in range(n)] m=int(input()) for i in range(m): ch=input().strip() for j in range(n): if ch==a[j][0]: ans.append(a[j][1]) flag=1 if flag!=1 : ans.append(ch) flag=0 for i in range(len(ans)): sys.stdout.write(ans[i]) print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var ans : Sequence := Sequence{} ; var flag : int := 0 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (input().split()->select(i | true)->collect(i | (i)))) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, m-1) do ( var ch : OclAny := input()->trim() ; for j : Integer.subrange(0, n-1) do ( if ch = a[j+1]->first() then ( execute ((a[j+1][1+1]) : ans) ; flag := 1 ) else skip) ; if flag /= 1 then ( execute ((ch) : ans) ) else skip ; flag := 0) ; for i : Integer.subrange(0, (ans)->size()-1) do ((expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys while True : n=int(sys.stdin.readline().rstrip()) if n==0 : break ; x={} for i in range(n): k,v=sys.stdin.readline().rstrip().split() x[k]=v n=int(sys.stdin.readline().rstrip()) y=[] for i in range(n): a=sys.stdin.readline().rstrip() if a in x : y.append(x[a]) else : y.append(a) print(''.join(y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : int := ("" + ((sys.stdin.readLine().rstrip())))->toInteger() ; if n = 0 then ( break; ) else skip ; var x : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var k : OclAny := null; var v : OclAny := null; Sequence{k,v} := sys.stdin.readLine().rstrip().split() ; x[k+1] := v) ; n := ("" + ((sys.stdin.readLine().rstrip())))->toInteger() ; var y : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := sys.stdin.readLine().rstrip() ; if (x)->includes(a) then ( execute ((x[a+1]) : y) ) else ( execute ((a) : y) )) ; execute (StringLib.sumStringsWithSeparator((y), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) while(n!=0): list={} sum="" for i in range(n): a,b=input().split() list[a]=b.rstrip() n=int(input()) for i in range(n): s=input().rstrip() if s in list : sum+=list[s] else : sum+=s print(sum) n=int(input()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (n /= 0) do ( var OclType["Sequence"] : OclAny := Set{} ; var sum : String := "" ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; [a+1] := StringLib.rightTrim(b)) ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var s : OclAny := input().rstrip() ; if (OclType["Sequence"])->includes(s) then ( sum := sum + [s+1] ) else ( sum := sum + s )) ; execute (sum)->display() ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect as upper_bound def getCount(v,n): v=sorted(v) cnt=0 for i in range(n): tmp=n-1-upper_bound(v,v[i]-1) if(tmp==v[i]): cnt+=1 return cnt n=4 v=[] v.append(1) v.append(2) v.append(3) v.append(4) print(getCount(v,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 4 ; v := Sequence{} ; execute ((1) : v) ; execute ((2) : v) ; execute ((3) : v) ; execute ((4) : v) ; execute (getCount(v, n))->display(); operation getCount(v : OclAny, n : OclAny) : OclAny pre: true post: true activity: v := v->sort() ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( var tmp : double := n - 1 - upper_bound(v, v[i+1] - 1) ; if (tmp = v[i+1]) then ( cnt := cnt + 1 ) else skip) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- txt=input() out="" cap=0 small=0 for t in txt : if t.islower(): small+=1 else : cap+=1 if small>=cap : for t in txt : out+=t.lower() else : for t in txt : out+=t.upper() print(out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var txt : String := (OclFile["System.in"]).readLine() ; var out : String := "" ; var cap : int := 0 ; var small : int := 0 ; for t : txt->characters() do ( if t->matches("[a-z ]*") then ( small := small + 1 ) else ( cap := cap + 1 )) ; if (small->compareTo(cap)) >= 0 then ( for t : txt->characters() do ( out := out + t->toLowerCase()) ) else ( for t : txt->characters() do ( out := out + t->toUpperCase()) ) ; execute (out)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def trailing_zeros(N): count_of_two=0 count_of_five=0 for i in range(1,N+1,1): val=i while(val % 2==0 and val>0): val/=2 count_of_two+=i while(val % 5==0 and val>0): val/=5 count_of_five+=i ans=min(count_of_two,count_of_five) return ans if __name__=='__main__' : N=12 print(trailing_zeros(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( N := 12 ; execute (trailing_zeros(N))->display() ) else skip; operation trailing_zeros(N : OclAny) : OclAny pre: true post: true activity: var count_of_two : int := 0 ; var count_of_five : int := 0 ; for i : Integer.subrange(1, N + 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( var val : OclAny := i ; while (val mod 2 = 0 & val > 0) do ( val := val / 2 ; count_of_two := count_of_two + i) ; while (val mod 5 = 0 & val > 0) do ( val := val / 5 ; count_of_five := count_of_five + i)) ; var ans : OclAny := Set{count_of_two, count_of_five}->min() ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def removeZero(n): res=0 d=1 while(n>0): if(n % 10!=0): res+=(n % 10)*d d*=10 n//=10 return res def isEqual(a,b): if(removeZero(a)+removeZero(b)==removeZero(a+b)): return True return False a=105 b=106 if(isEqual(a,b)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 105 ; b := 106 ; if (isEqual(a, b)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation removeZero(n : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; var d : int := 1 ; while (n > 0) do ( if (n mod 10 /= 0) then ( res := res + (n mod 10) * d ; d := d * 10 ) else skip ; n := n div 10) ; return res; operation isEqual(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (removeZero(a) + removeZero(b) = removeZero(a + b)) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=1000000007 from sys import stdin f_i=stdin N=int(f_i.readline()) n_type=['']*N for i in range(N): t=f_i.readline().rstrip() n_type[i]=t adj=[[]for i in range(N)] for i in range(N-1): s,t=map(int,f_i.readline().split()) s-=1 t-=1 adj[s].append(t) from itertools import combinations def prod(nums): p=1 for n in nums : p*=n return p import sys sys.setrecursionlimit(4000) def dfs(node): nt=n_type[node] chld=adj[node] if nt=='E' : if chld : return prod(map(dfs,chld))% m else : return 1 elif nt=='E?' : if chld : return(prod(map(dfs,chld))+1)% m else : return 2 elif nt=='A' : return sum(map(dfs,chld))% m elif nt=='A?' : return(sum(map(dfs,chld))+1)% m else : cnt=0 c_s=tuple(map(dfs,chld)) for i in range(1,len(chld)+1): for vals in combinations(c_s,i): cnt+=prod(vals) if len(nt)==1 : return cnt % m else : return(cnt+1)% m print(dfs(0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : int := 1000000007 ; skip ; var f_i : OclAny := stdin ; var N : int := ("" + ((f_i.readLine())))->toInteger() ; var n_type : Sequence := MatrixLib.elementwiseMult(Sequence{ '' }, N) ; for i : Integer.subrange(0, N-1) do ( var t : OclAny := f_i.readLine().rstrip() ; n_type[i+1] := t) ; var adj : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, N - 1-1) do ( var s : OclAny := null; Sequence{s,t} := (f_i.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; s := s - 1 ; t := t - 1 ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) ))))) ; skip ; skip ; skip ; sys.setrecursionlimit(4000) ; skip ; execute (dfs(0))->display(); operation prod(nums : OclAny) : OclAny pre: true post: true activity: var p : int := 1 ; for n : nums do ( p := p * n) ; return p; operation dfs(node : OclAny) : OclAny pre: true post: true activity: var nt : OclAny := n_type[node+1] ; var chld : OclAny := adj[node+1] ; if nt = 'E' then ( if chld then ( return prod((chld)->collect( _x | (dfs)->apply(_x) )) mod m ) else ( return 1 ) ) else (if nt = 'E?' then ( if chld then ( return (prod((chld)->collect( _x | (dfs)->apply(_x) )) + 1) mod m ) else ( return 2 ) ) else (if nt = 'A' then ( return ((chld)->collect( _x | (dfs)->apply(_x) ))->sum() mod m ) else (if nt = 'A?' then ( return (((chld)->collect( _x | (dfs)->apply(_x) ))->sum() + 1) mod m ) else ( var cnt : int := 0 ; var c_s : Sequence := ((chld)->collect( _x | (dfs)->apply(_x) )) ; for i : Integer.subrange(1, (chld)->size() + 1-1) do ( for vals : combinations(c_s, i) do ( cnt := cnt + prod(vals))) ; if (nt)->size() = 1 then ( return cnt mod m ) else ( return (cnt + 1) mod m ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) N=int(input()) ND=["E","E?","A","R","A?","R?"] T=[input()for i in range(N)] G=[[]for i in range(N)] for i in range(N-1): s,t=map(int,input().split()) G[s-1].append(t-1) MOD=10**9+7 def dfs(v): t=T[v] if t[0]in['E','R']: r=1 else : r=0 t0=t[0] for w in G[v]: x=dfs(w) if t0=='E' : r=r*x % MOD elif t0=='R' : r=r*(x+1)% MOD else : r+=x if t[0]=='R' : r-=1 if t[-1]=='?' : r+=1 return r % MOD print(dfs(0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ND : Sequence := Sequence{"E"}->union(Sequence{"E?"}->union(Sequence{"A"}->union(Sequence{"R"}->union(Sequence{"A?"}->union(Sequence{ "R?" }))))) ; var T : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var G : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, N - 1-1) do ( var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name s))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name t))) - (expr (atom (number (integer 1)))))))))) ))))) ; var MOD : double := (10)->pow(9) + 7 ; skip ; execute (dfs(0))->display(); operation dfs(v : OclAny) : OclAny pre: true post: true activity: var t : OclAny := T[v+1] ; if (Sequence{'E'}->union(Sequence{ 'R' }))->includes(t->first()) then ( var r : int := 1 ) else ( r := 0 ) ; var t0 : OclAny := t->first() ; for w : G[v+1] do ( var x : OclAny := dfs(w) ; if t0 = 'E' then ( r := r * x mod MOD ) else (if t0 = 'R' then ( r := r * (x + 1) mod MOD ) else ( r := r + x ) ) ) ; if t->first() = 'R' then ( r := r - 1 ) else skip ; if t->last() = '?' then ( r := r + 1 ) else skip ; return r mod MOD; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect MAXN=1300000 primes=[] sieve=[0,0]+[1]*MAXN n=2 while n*nunion(Sequence{ 0 })->union(MatrixLib.elementwiseMult(Sequence{ 1 }, MAXN)) ; var n : int := 2 ; while (n * n->compareTo(MAXN)) < 0 do ( if sieve[n+1] then ( execute ((n) : primes) ; for m : Integer.subrange(2 * n, MAXN-1)->select( $x | ($x - 2 * n) mod n = 0 ) do ( sieve[m+1] := 0) ) else skip ; n := n + 1) ; for m : Integer.subrange(n, MAXN-1) do ( if sieve[m+1] then ( execute ((m) : primes) ) else skip) ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var l : OclAny := bisect.bisect_left(primes, N) ; var r : OclAny := bisect.bisect_right(primes, N) ; if r - l = 1 then ( execute (0)->display() ) else ( execute (primes[l+1] - primes[l - 1+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) X=[int(x)for x in input().split()] Y=[int(x)for x in input().split()] print('Yes' if sum(Y)<=sum(X)else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var X : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var Y : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (if ((Y)->sum()->compareTo((X)->sum())) <= 0 then 'Yes' else 'No' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- X=int(input()) l=[2] t=3 while 1 : for i in l : if t % i==0 : break else : if t>=X : break l.append(t) t+=1 if X==2 : t=2 print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var X : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{ 2 } ; var t : int := 3 ; while 1 do ((compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name l))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name t))) % (expr (atom (name i))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name t)))) >= (comparison (expr (atom (name X))))))) : (suite (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) ))))))))))))))) ; t := t + 1) ; if X = 2 then ( t := 2 ) else skip ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(100000) mod=1000000007 n=int(input()) nodes=[input()for _ in range(n)] edges=[[]for _ in range(n)] for _ in range(n-1): s,t=map(int,input().split()) s-=1 t-=1 edges[s].append(t) def score(index): node=nodes[index] if node[0]=="E" : ret=1 for to in edges[index]: ret*=score(to) if node[0]=="A" : ret=0 for to in edges[index]: ret+=score(to) if node[0]=="R" : ret=1 for to in edges[index]: ret*=(score(to)+1) ret-=1 if node[-1]=="?" : ret+=1 return ret % mod print(score(0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(100000) ; var mod : int := 1000000007 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nodes : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var edges : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, n - 1-1) do ( var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; s := s - 1 ; t := t - 1 ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) ))))) ; skip ; execute (score(0))->display(); operation score(index : OclAny) : OclAny pre: true post: true activity: var node : OclAny := nodes[index+1] ; if node->first() = "E" then ( var ret : int := 1 ; for to : edges[index+1] do ( ret := ret * score(to)) ) else skip ; if node->first() = "A" then ( ret := 0 ; for to : edges[index+1] do ( ret := ret + score(to)) ) else skip ; if node->first() = "R" then ( ret := 1 ; for to : edges[index+1] do ( ret := ret * (score(to) + 1)) ; ret := ret - 1 ) else skip ; if node->last() = "?" then ( ret := ret + 1 ) else skip ; return ret mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda : sys.stdin.readline().rstrip() YesNo=lambda b : bool([print('Yes')]if b else print('No')) YESNO=lambda b : bool([print('YES')]if b else print('NO')) int1=lambda x : int(x)-1 def main(): N=int(input()) a=list(map(int1,input())) X=0 c=0 f=False if not 1 in a : for i in range(N): a[i]//=2 f=True for i in range(N): if c==0 : X ^=a[i]% 2 K=N-1-i while K>0 and K % 2==0 : c+=1 K//=2 K=i+1 while K>0 and K % 2==0 : c-=1 K//=2 if X==1 : print(1*(f+1)) else : print(0) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var YesNo : Function := lambda b : OclAny in ((if b then Sequence{ ('Yes')->display() } else ('No')->display() endif)->toBoolean()) ; var YESNO : Function := lambda b : OclAny in ((if b then Sequence{ ('YES')->display() } else ('NO')->display() endif)->toBoolean()) ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (((OclFile["System.in"]).readLine())->collect( _x | (int1)->apply(_x) )) ; var X : int := 0 ; var c : int := 0 ; var f : boolean := false ; if not((a)->includes(1)) then ( for i : Integer.subrange(0, N-1) do ( a[i+1] := a[i+1] div 2) ; f := true ) else skip ; for i : Integer.subrange(0, N-1) do ( if c = 0 then ( X := X xor a[i+1] mod 2 ) else skip ; var K : double := N - 1 - i ; while K > 0 & K mod 2 = 0 do ( c := c + 1 ; K := K div 2) ; K := i + 1 ; while K > 0 & K mod 2 = 0 do ( c := c - 1 ; K := K div 2)) ; if X = 1 then ( execute (1 * (f + 1))->display() ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=[int(a)-1 for a in input()] r=1 if 1 in A else 2 def parity_of_nCk(n,k): return(n & k)==k ans=0 for i,a in enumerate(A): if a & r : if parity_of_nCk(N-1,i): ans ^=1 print(ans*r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := (OclFile["System.in"]).readLine()->select(a | true)->collect(a | (("" + ((a)))->toInteger() - 1)) ; var r : int := if (A)->includes(1) then 1 else 2 endif ; skip ; var ans : int := 0 ; for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); if MathLib.bitwiseAnd(a, r) then ( if parity_of_nCk(N - 1, i) then ( ans := ans xor 1 ) else skip ) else skip) ; execute (ans * r)->display(); operation parity_of_nCk(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: return (MathLib.bitwiseAnd(n, k)) = k; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() c=0 for i in x : if i.isupper(): c+=1 if i.islower(): c-=1 if c>0 : x=x.upper() print(x) if c<=0 : x=x.lower() print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := (OclFile["System.in"]).readLine() ; var c : int := 0 ; for i : x->characters() do ( if i->matches("[A-Z ]*") then ( c := c + 1 ) else skip ; if i->matches("[a-z ]*") then ( c := c - 1 ) else skip) ; if c > 0 then ( x := x->toUpperCase() ; execute (x)->display() ) else skip ; if c <= 0 then ( x := x->toLowerCase() ; execute (x)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def twos_in_factorial(n): return n-bin(n).count('1') def parity_of_nCr(n,i): f=twos_in_factorial return f(n)-f(n-i)-f(i)>0 if __name__=="__main__" : n=int(input()) nums=list(map(lambda x : int(x)-1,input().strip())) no_one=False if 1 not in nums : nums=[num//2 for num in nums] no_one=True is_odd=False for i,num in enumerate(nums): if not parity_of_nCr(n-1,i)and num & 1 : is_odd ^=1 if not is_odd : print(0) else : print(1<toInteger() ; var nums : Sequence := ((input()->trim())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) )) ; var no_one : boolean := false ; if (nums)->excludes(1) then ( nums := nums->select(num | true)->collect(num | (num div 2)) ; no_one := true ) else skip ; var is_odd : boolean := false ; for _tuple : Integer.subrange(1, (nums)->size())->collect( _indx | Sequence{_indx-1, (nums)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var num : OclAny := _tuple->at(_indx); if not(parity_of_nCr(n - 1, i)) & MathLib.bitwiseAnd(num, 1) then ( is_odd := is_odd xor 1 ) else skip) ; if not(is_odd) then ( execute (0)->display() ) else ( execute (1 * (2->pow(no_one)))->display() ) ) else skip; operation twos_in_factorial(n : OclAny) : OclAny pre: true post: true activity: return n - bin(n)->count('1'); operation parity_of_nCr(n : OclAny, i : OclAny) : OclAny pre: true post: true activity: var f : OclAny := twos_in_factorial ; return f(n) - f(n - i) - f(i) > 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import random input=sys.stdin.readline n=int(input()) s=input().rstrip() a=[int(ch)for ch in s] def naive(a): c=a[:] while len(c)>1 : b=[] for c1,c2 in zip(c,c[1 :]): b.append(abs(c1-c2)) c=b[:] return c[0] def solve(a): c=a[:] while len(c)>1 : b=[] if len(c)% 2==0 : for c1,c2 in zip(c[: : 2],c[1 : : 2]): b.append(abs(c1-c2)) else : for c1,c2 in zip(c,c[1 :]): b.append(abs(c1-c2)) c=b[:] return c[0] b=[] for a1,a2 in zip(a,a[1 :]): b.append(abs(a1-a2)) if 1 not in b : tmp=[] for item in b : if item==2 : tmp.append(1) else : tmp.append(0) ret=solve(tmp) if ret==1 : print(2) else : print(0) else : tmp=[] for item in b : if item==2 : tmp.append(0) else : tmp.append(item) ret=solve(tmp) print(ret) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := input().rstrip() ; var a : Sequence := s->select(ch | true)->collect(ch | (("" + ((ch)))->toInteger())) ; skip ; skip ; b := Sequence{} ; for _tuple : Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), a->tail()->at(_indx)} ) do (var _indx : int := 1; var a1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a2 : OclAny := _tuple->at(_indx); execute (((a1 - a2)->abs()) : b)) ; if (b)->excludes(1) then ( var tmp : Sequence := Sequence{} ; for item : b do ( if item = 2 then ( execute ((1) : tmp) ) else ( execute ((0) : tmp) )) ; var ret : OclAny := solve(tmp) ; if ret = 1 then ( execute (2)->display() ) else ( execute (0)->display() ) ) else ( tmp := Sequence{} ; for item : b do ( if item = 2 then ( execute ((0) : tmp) ) else ( execute ((item) : tmp) )) ; ret := solve(tmp) ; execute (ret)->display() ); operation naive(a : OclAny) : OclAny pre: true post: true activity: var c : Sequence := a ; while (c)->size() > 1 do ( var b : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, c->size())->collect( _indx | Sequence{c->at(_indx), c->tail()->at(_indx)} ) do (var _indx : int := 1; var c1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c2 : OclAny := _tuple->at(_indx); execute (((c1 - c2)->abs()) : b)) ; c := b) ; return c->first(); operation solve(a : OclAny) : OclAny pre: true post: true activity: c := a ; while (c)->size() > 1 do ( b := Sequence{} ; if (c)->size() mod 2 = 0 then ( for _tuple : Integer.subrange(1, c(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{c(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->at(_indx), c(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->at(_indx)} ) do (var _indx : int := 1; var c1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c2 : OclAny := _tuple->at(_indx); execute (((c1 - c2)->abs()) : b)) ) else ( for _tuple : Integer.subrange(1, c->size())->collect( _indx | Sequence{c->at(_indx), c->tail()->at(_indx)} ) do (var _indx : int := 1; var c1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c2 : OclAny := _tuple->at(_indx); execute (((c1 - c2)->abs()) : b)) ) ; c := b) ; return c->first(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def popcount_parity(x): x ^=x>>1 x ^=x>>2 x ^=x>>4 x ^=x>>8 x ^=x>>16 x ^=x>>32 x ^=x>>64 x ^=x>>128 x ^=x>>256 x ^=x>>512 x ^=x>>1024 x ^=x>>2048 x ^=x>>4096 x ^=x>>8192 x ^=x>>16384 x ^=x>>32768 x ^=x>>65536 x ^=x>>131072 x ^=x>>262144 x ^=x>>524288 return x & 1 N=int(input())-1 s=1 while N : l=N &-N s |=s<toInteger() - 1 ; var s : int := 1 ; while N do ( var l : int := MathLib.bitwiseAnd(N, -N) ; s := s or s * (2->pow(l)) ; N := N xor l) ; var A : String := (OclFile["System.in"]).readLine() ; if (A)->characters()->includes("2") then ( var a : int := ("" + ((A.replace("1", "0").replace("3", "0").replace("2", "1"), 2)))->toInteger() ; execute (popcount_parity(MathLib.bitwiseAnd(a, s)))->display() ) else ( a := ("" + ((A.replace("1", "0").replace("3", "1"), 2)))->toInteger() ; execute (popcount_parity(MathLib.bitwiseAnd(a, s)) * 2)->display() ); operation popcount_parity(x : OclAny) : OclAny pre: true post: true activity: x := x xor x /(2->pow(1)) ; x := x xor x /(2->pow(2)) ; x := x xor x /(2->pow(4)) ; x := x xor x /(2->pow(8)) ; x := x xor x /(2->pow(16)) ; x := x xor x /(2->pow(32)) ; x := x xor x /(2->pow(64)) ; x := x xor x /(2->pow(128)) ; x := x xor x /(2->pow(256)) ; x := x xor x /(2->pow(512)) ; x := x xor x /(2->pow(1024)) ; x := x xor x /(2->pow(2048)) ; x := x xor x /(2->pow(4096)) ; x := x xor x /(2->pow(8192)) ; x := x xor x /(2->pow(16384)) ; x := x xor x /(2->pow(32768)) ; x := x xor x /(2->pow(65536)) ; x := x xor x /(2->pow(131072)) ; x := x xor x /(2->pow(262144)) ; x := x xor x /(2->pow(524288)) ; return MathLib.bitwiseAnd(x, 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=list(input().split()) for i in range(len(x)): x[i]=int(x[i]) a=x[0] b=x[1] print(min(x),end=" ") if abs(a-b)>=2 : print(abs(a-b)//2) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : Sequence := (input().split()) ; for i : Integer.subrange(0, (x)->size()-1) do ( x[i+1] := ("" + ((x[i+1])))->toInteger()) ; var a : OclAny := x->first() ; var b : OclAny := x[1+1] ; execute ((x)->min())->display() ; if (a - b)->abs() >= 2 then ( execute ((a - b)->abs() div 2)->display() ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n = input().split() a = int(n[0]) b = int(n[1]) count1 = 0 count2 = 0 while a + b > 1: if a > 0 and b > 0: if b > 0: count1 += 1 a -= 1 b -= 1 else: if b > 1: count2 += 1 b -= 2 elif a > 1: count2 += 1 a -= 2 print(count1, count2, sep=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := input().split() ; var a : int := ("" + ((n->first())))->toInteger() ; var b : int := ("" + ((n[1+1])))->toInteger() ; var count1 : int := 0 ; var count2 : int := 0 ; while a + b > 1 do ( if a > 0 & b > 0 then ( if b > 0 then ( count1 := count1 + 1 ; a := a - 1 ; b := b - 1 ) else skip ) else ( if b > 1 then ( count2 := count2 + 1 ; b := b - 2 ) else (if a > 1 then ( count2 := count2 + 1 ; a := a - 2 ) else skip) )) ; execute (count1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- red,blue=map(int,input().split()) diff=min(red,blue) same=abs(red-blue)//2 print(diff,same) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var red : OclAny := null; var blue : OclAny := null; Sequence{red,blue} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var diff : OclAny := Set{red, blue}->min() ; var same : int := (red - blue)->abs() div 2 ; execute (diff)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) print(min(a,b),end=" ") print((max(a,b)-min(a,b))//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{a, b}->min())->display() ; execute ((Set{a, b}->max() - Set{a, b}->min()) div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math x=int(input()) def Eratosthenes(n): if n<2 : return None prime=[2] limit=math.ceil(n**0.5) data=list(range(3,n+1,2)) p=-1 while ptoInteger() ; skip ; prime := Eratosthenes((10)->pow(5) + 3) ; if (prime)->includes(x) then ( execute (x)->display() ) else ( skip ; var min_prime_index : OclAny := bisect.bisect_right(prime, x) ; execute (prime[min_prime_index+1])->display() ); operation Eratosthenes(n : OclAny) : OclAny pre: true post: true activity: if n < 2 then ( return null ) else skip ; var prime : Sequence := Sequence{ 2 } ; var limit : double := ((n)->pow(0.5))->ceil() ; var data : Sequence := (Integer.subrange(3, n + 1-1)->select( $x | ($x - 3) mod 2 = 0 )) ; var p : int := -1 ; while (p->compareTo(limit)) < 0 do ( p := data->first() ; execute ((p) : prime) ; data := data->select(d | d mod p /= 0)->collect(d | (d))) ; return prime->union(data); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) print(min(a,b),(max(a,b)-min(a,b))//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{a, b}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input('')) l=list(map(int,input().split())) if n==1 : print(l[0]) else : x=abs(l[0]-l[1]) m1,m2=min(l),max(l) print((m1+m2)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = 1 then ( execute (l->first())->display() ) else ( var x : double := (l->first() - l[1+1])->abs() ; var m1 : OclAny := null; var m2 : OclAny := null; Sequence{m1,m2} := Sequence{(l)->min(),(l)->max()} ; execute ((m1 + m2) div 2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,bisect PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") digits=[63,6,91,79,102,109,125,39,127,111] while True : n=int(input()) if n==-1 : break e=0 for i in range(n): a=digits[int(input())] print("{:07b}".format(a ^ e)) e=a ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; var digits : Sequence := Sequence{63}->union(Sequence{6}->union(Sequence{91}->union(Sequence{79}->union(Sequence{102}->union(Sequence{109}->union(Sequence{125}->union(Sequence{39}->union(Sequence{127}->union(Sequence{ 111 }))))))))) ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = -1 then ( break ) else skip ; var e : int := 0 ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := digits[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1] ; execute (StringLib.interpolateStrings("{:07b}", Sequence{MathLib.bitwiseXor(a, e)}))->display() ; e := a)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys import itertools import fractions if __name__=='__main__' : wtf=sys.stdin.read() wtf=wtf.strip().split('\n') n=int(wtf[0]) A=sorted(map(int,wtf[1].split())) print(A[n//2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var wtf : String := (OclFile["System.in"]).readAll() ; wtf := wtf->trim().split(' ') ; var n : int := ("" + ((wtf->first())))->toInteger() ; var A : Sequence := (wtf[1+1].split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; execute (A[n div 2+1])->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) c=list(map(int,input().split())) b=(a-1)//2 c.sort() print(c[b]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : int := (a - 1) div 2 ; c := c->sort() ; execute (c[b+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _,y=input(),(int(i)for i in input().split()) min_y,max_y=2101,2009 for i in y : min_y=min(min_y,i) max_y=max(max_y,i) res=(min_y+max_y)//2 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _anon : OclAny := null; var y : OclAny := null; Sequence{_anon,y} := Sequence{(OclFile["System.in"]).readLine(),Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))}} ; var min_y : OclAny := null; var max_y : OclAny := null; Sequence{min_y,max_y} := Sequence{2101,2009} ; for i : y do ( var min_y : OclAny := Set{min_y, i}->min() ; var max_y : OclAny := Set{max_y, i}->max()) ; var res : int := (min_y + max_y) div 2 ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split()))[: n] l.sort() k=(len(l)-1)//2 if len(l)>1 : print(l[k]) else : print(l[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ; l := l->sort() ; var k : int := ((l)->size() - 1) div 2 ; if (l)->size() > 1 then ( execute (l[k+1])->display() ) else ( execute (l->first())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) q=n//m r=n % m a=[q]*m for i in range(r): a[i]+=1 for i in range(m): print(a[i],end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var q : int := n div m ; var r : int := n mod m ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ q }, m) ; for i : Integer.subrange(0, r-1) do ( a[i+1] := a[i+1] + 1) ; for i : Integer.subrange(0, m-1) do ( execute (a[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) c=n//m rem=n % m ans=[c]*m i=0 while rem>0 : ans[i]+=1 rem-=1 i+=1 for i in range(m): print(ans[i],end=' ') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : int := n div m ; var rem : int := n mod m ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ c }, m) ; var i : int := 0 ; while rem > 0 do ( ans[i+1] := ans[i+1] + 1 ; rem := rem - 1 ; i := i + 1) ; for i : Integer.subrange(0, m-1) do ( execute (ans[i+1])->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=input().split() k=[int(i)for i in k] candies=[] n,m=k[0],k[1] reminder=n % m for i in range(m): candies.append(int(n//m)) for i in range(m): if reminder>0 : candies[i]+=1 reminder-=1 else : break for i in candies : print(i,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : OclAny := input().split() ; k := k->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var candies : Sequence := Sequence{} ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{k->first(),k[1+1]} ; var reminder : int := n mod m ; for i : Integer.subrange(0, m-1) do ( execute ((("" + ((n div m)))->toInteger()) : candies)) ; for i : Integer.subrange(0, m-1) do ( if reminder > 0 then ( candies[i+1] := candies[i+1] + 1 ; reminder := reminder - 1 ) else ( break )) ; for i : candies do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) for i in range(m): print(n//m,end=" ") n=n-n//m m=m-1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, m-1) do ( execute (n div m)->display() ; var n : double := n - n div m ; var m : double := m - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): x=int(input()) is_prime_list=[0 for i in range(10**6+1)] for i in range(2,len(is_prime_list)): if is_prime_list[i]==0 : is_prime_list[i]=1 for j in range(2*i,len(is_prime_list),i): is_prime_list[j]=2 for _i in range(x,len(is_prime_list)): if is_prime_list[_i]==1 : print(_i) return if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( solve() ) else skip; operation solve() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var is_prime_list : Sequence := Integer.subrange(0, (10)->pow(6) + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(2, (is_prime_list)->size()-1) do ( if is_prime_list[i+1] = 0 then ( is_prime_list[i+1] := 1 ; for j : Integer.subrange(2 * i, (is_prime_list)->size()-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ( is_prime_list[j+1] := 2) ) else skip) ; for _i : Integer.subrange(x, (is_prime_list)->size()-1) do ( if is_prime_list[_i+1] = 1 then ( execute (_i)->display() ; return ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(a)for a in input().split()] l=n//m q=n % m list=[] for i in range(m-q): list.append(l) for i in range(q): list.append((n-((m-q)*l))//q) for i in list : print(i,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; var l : int := n div m ; var q : int := n mod m ; var OclType["Sequence"] : Sequence := Sequence{} ; for i : Integer.subrange(0, m - q-1) do ( execute ((l) : OclType["Sequence"])) ; for i : Integer.subrange(0, q-1) do ( execute (((n - ((m - q) * l)) div q) : OclType["Sequence"])) ; for i : OclType["Sequence"] do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import functools T=int(input()) for _ in range(T): n=int(input()) a=list(map(int,input().split())) a=[bin(ai)[2 :].rjust(30,'0')for ai in a] count=[] for k in range(30): s=sum(ai[k]=='1' for ai in a) if s>0 : count.append(s) g=functools.reduce(math.gcd,count)if len(count)>0 else 0 ks=set() for k in range(1,int(math.sqrt(g))+1): if g % k==0 : ks.add(k) ks.add(g//k) if g!=0 : print(*sorted(list(ks))) else : print(*[i+1 for i in range(n)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, T-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->select(ai | true)->collect(ai | (bin(ai).subrange(2+1).rjust(30, '0'))) ; var count : Sequence := Sequence{} ; for k : Integer.subrange(0, 30-1) do ( var s : OclAny := ((argument (test (logical_test (comparison (comparison (expr (atom (name ai)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])))) == (comparison (expr (atom '1')))))) (comp_for for (exprlist (expr (atom (name ai)))) in (logical_test (comparison (expr (atom (name a))))))))->sum() ; if s > 0 then ( execute ((s) : count) ) else skip) ; var g : OclAny := if (count)->size() > 0 then functools.reduce(, count) else 0 endif ; var ks : Set := Set{}->union(()) ; for k : Integer.subrange(1, ("" + (((g)->sqrt())))->toInteger() + 1-1) do ( if g mod k = 0 then ( execute ((k) : ks) ; execute ((g div k) : ks) ) else skip) ; if g /= 0 then ( execute ((argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ks)))))))) ))))))))) )))))))))->display() ) else ( execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) ])))))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSetBits(n): count=0 while(n): count+=n & 1 n>>=1 return count def totalPairs(s1,s2): count=0 ; arr1=[0]*7 ; arr2=[0]*7 ; for i in range(len(s1)): set_bits=countSetBits(ord(s1[i])) arr1[set_bits]+=1 ; for i in range(len(s2)): set_bits=countSetBits(ord(s2[i])); arr2[set_bits]+=1 ; for i in range(1,7): count+=(arr1[i]*arr2[i]); return count ; if __name__=="__main__" : s1="geeks" ; s2="forgeeks" ; print(totalPairs(s1,s2)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( s1 := "geeks"; ; s2 := "forgeeks"; ; execute (totalPairs(s1, s2))->display(); ) else skip; operation countSetBits(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while (n) do ( count := count + MathLib.bitwiseAnd(n, 1) ; n := n div (2->pow(1))) ; return count; operation totalPairs(s1 : OclAny, s2 : OclAny) pre: true post: true activity: count := 0; ; var arr1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 7); var arr2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 7); ; for i : Integer.subrange(0, (s1)->size()-1) do ( var set_bits : OclAny := countSetBits((s1[i+1])->char2byte()) ; arr1[set_bits+1] := arr1[set_bits+1] + 1;) ; for i : Integer.subrange(0, (s2)->size()-1) do ( set_bits := countSetBits((s2[i+1])->char2byte()); ; arr2[set_bits+1] := arr2[set_bits+1] + 1;) ; for i : Integer.subrange(1, 7-1) do ( count := count + (arr1[i+1] * arr2[i+1]);) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSubSeq(i,Sum,cnt,a,n): if(i==n): if(Sum==0 and cnt>0): return 1 else : return 0 ans=0 ans+=countSubSeq(i+1,Sum,cnt,a,n) ans+=countSubSeq(i+1,Sum+a[i],cnt+1,a,n) return ans a=[-1,2,-2,1] n=len(a) print(countSubSeq(0,0,0,a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{-1}->union(Sequence{2}->union(Sequence{-2}->union(Sequence{ 1 }))) ; n := (a)->size() ; execute (countSubSeq(0, 0, 0, a, n))->display(); operation countSubSeq(i : OclAny, Sum : OclAny, cnt : OclAny, a : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (i = n) then ( if (Sum = 0 & cnt > 0) then ( return 1 ) else ( return 0 ) ) else skip ; var ans : int := 0 ; ans := ans + countSubSeq(i + 1, Sum, cnt, a, n) ; ans := ans + countSubSeq(i + 1, Sum + a[i+1], cnt + 1, a, n) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) in_str=input() if n % 2==0 : index=int(n//2)-1 else : index=int(n//2) def func(in_str,index,n): j=0 in_list=[i for i in in_str] out_list=[None]*n while(len(in_list)>0): if(j==0): out_list[index]=in_list[0] in_list.pop(0) else : if(n % 2!=0): if(index-j>=0): out_list[index-j]=in_list[0] in_list.pop(0) if(index+j=0): out_list[index-j]=in_list[0] in_list.pop(0) j+=1 return out_list out_str=func(in_str,index,n) print(*out_str,sep="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var in_str : String := (OclFile["System.in"]).readLine() ; if n mod 2 = 0 then ( var index : double := ("" + ((n div 2)))->toInteger() - 1 ) else ( index := ("" + ((n div 2)))->toInteger() ) ; skip ; var out_str : OclAny := func(in_str, index, n) ; execute ((argument * (test (logical_test (comparison (expr (atom (name out_str))))))))->display(); operation func(in_str : OclAny, index : OclAny, n : OclAny) : OclAny pre: true post: true activity: var j : int := 0 ; var in_list : Sequence := in_str->characters()->select(i | true)->collect(i | (i)) ; var out_list : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; while ((in_list)->size() > 0) do ( if (j = 0) then ( out_list[index+1] := in_list->first() ; in_list := in_list->excludingAt(0+1) ) else ( if (n mod 2 /= 0) then ( if (index - j >= 0) then ( out_list[index - j+1] := in_list->first() ; in_list := in_list->excludingAt(0+1) ) else skip ; if ((index + j->compareTo(n)) < 0) then ( out_list[index + j+1] := in_list->first() ; in_list := in_list->excludingAt(0+1) ) else skip ) else ( if ((index + j->compareTo(n)) < 0) then ( out_list[index + j+1] := in_list->first() ; in_list := in_list->excludingAt(0+1) ) else skip ; if (index - j >= 0) then ( out_list[index - j+1] := in_list->first() ; in_list := in_list->excludingAt(0+1) ) else skip ) ) ; j := j + 1) ; return out_list; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- number=int(input()) word=input() right=[] left=[] if len(word)% 2==0 : for i in range(0,len(word)): if i % 2==0 : right.append(word[i]) else : left.append(word[i]) right.reverse() else : for i in range(0,len(word)): if i % 2==0 : left.append(word[i]) else : right.append(word[i]) right.reverse() both=right+left for i in both : print(i,end='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var number : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var word : String := (OclFile["System.in"]).readLine() ; var right : Sequence := Sequence{} ; var left : Sequence := Sequence{} ; if (word)->size() mod 2 = 0 then ( for i : Integer.subrange(0, (word)->size()-1) do ( if i mod 2 = 0 then ( execute ((word[i+1]) : right) ) else ( execute ((word[i+1]) : left) )) ; right := right->reverse() ) else ( for i : Integer.subrange(0, (word)->size()-1) do ( if i mod 2 = 0 then ( execute ((word[i+1]) : left) ) else ( execute ((word[i+1]) : right) )) ; right := right->reverse() ) ; var both : Sequence := right->union(left) ; for i : both do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l1=[] l2=[] s=input() if n % 2!=0 : for i in range(n): if i % 2==0 : l2.append(s[i]) else : l1.append(s[i]) l=l1[: :-1]+l2 print(''.join(l)) else : for i in range(n): if i % 2==0 : l2.append(s[i]) else : l1.append(s[i]) l=l2[: :-1]+l1 print(''.join(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l1 : Sequence := Sequence{} ; var l2 : Sequence := Sequence{} ; var s : String := (OclFile["System.in"]).readLine() ; if n mod 2 /= 0 then ( for i : Integer.subrange(0, n-1) do ( if i mod 2 = 0 then ( execute ((s[i+1]) : l2) ) else ( execute ((s[i+1]) : l1) )) ; var l : OclAny := l1(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->union(l2) ; execute (StringLib.sumStringsWithSeparator((l), ''))->display() ) else ( for i : Integer.subrange(0, n-1) do ( if i mod 2 = 0 then ( execute ((s[i+1]) : l2) ) else ( execute ((s[i+1]) : l1) )) ; l := l2(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->union(l1) ; execute (StringLib.sumStringsWithSeparator((l), ''))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import deque def main(): n=int(sys.stdin.readline().strip()) s=sys.stdin.readline().strip() deq=deque([x for x in s]) flag=False start=True ans=deque() while len(ans)!=n : if start : temp=deq.popleft() ans.append(temp) start=False flag=True else : if n % 2!=0 : if flag : temp=deq.popleft() ans.appendleft(temp) flag=False else : temp=deq.popleft() ans.append(temp) flag=True else : if not flag : temp=deq.popleft() ans.appendleft(temp) flag=True else : temp=deq.popleft() ans.append(temp) flag=False sys.stdout.write(str(''.join(ans))) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + ((sys.stdin.readLine()->trim())))->toInteger() ; var s : OclAny := sys.stdin.readLine()->trim() ; var deq : Sequence := (s->select(x | true)->collect(x | (x))) ; var flag : boolean := false ; var start : boolean := true ; var ans : Sequence := () ; while (ans)->size() /= n do ( if start then ( var temp : OclAny := deq->first() ; deq := deq->tail() ; execute ((temp) : ans) ; start := false ; flag := true ) else ( if n mod 2 /= 0 then ( if flag then ( temp := deq->first() ; deq := deq->tail() ; ans := ans->prepend(temp) ; flag := false ) else ( temp := deq->first() ; deq := deq->tail() ; execute ((temp) : ans) ; flag := true ) ) else ( if not(flag) then ( temp := deq->first() ; deq := deq->tail() ; ans := ans->prepend(temp) ; flag := true ) else ( temp := deq->first() ; deq := deq->tail() ; execute ((temp) : ans) ; flag := false ) ) )) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) case=input() temp="" x=n for i in range(n): if x % 2==0 : temp=case[i]+temp else : temp=temp+case[i] x-=1 print(temp) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var case : String := (OclFile["System.in"]).readLine() ; var temp : String := "" ; var x : int := n ; for i : Integer.subrange(0, n-1) do ( if x mod 2 = 0 then ( temp := case[i+1] + temp ) else ( temp := temp + case[i+1] ) ; x := x - 1) ; execute (temp)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,n,m=list(map(int,input().split())) count=0 check_list=[] i=0 if a==0 : i=1 while(i+a)**ncollect( _x | (OclType["int"])->apply(_x) )) ; var count : int := 0 ; var check_list : Sequence := Sequence{} ; var i : int := 0 ; if a = 0 then ( i := 1 ) else skip ; while (((i + a))->pow(n)->compareTo(m)) < 0 do ( execute ((((i + a))->pow(n)) : check_list) ; i := i + 1) ; for x : check_list do ( var xl : Sequence := (("" + ((x))))->characters()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var y : OclAny := (xl)->sum() ; if x = ((y + a))->pow(n) then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def digit_sum(x): net=0 for f in str(x): net+=int(f) return net def main(): a,n,m=map(int,input().split()) cnt=0 x=0 while True : y=(x+a)**n if y>m : break if y>0 and digit_sum(y)==x : cnt+=1 x+=1 print(cnt) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation digit_sum(x : OclAny) : OclAny pre: true post: true activity: var net : int := 0 ; for f : ("" + ((x))) do ( net := net + ("" + ((f)))->toInteger()) ; return net; operation main() pre: true post: true activity: var a : OclAny := null; var n : OclAny := null; var m : OclAny := null; Sequence{a,n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cnt : int := 0 ; x := 0 ; while true do ( var y : double := ((x + a))->pow(n) ; if (y->compareTo(m)) > 0 then ( break ) else skip ; if y > 0 & digit_sum(y) = x then ( cnt := cnt + 1 ) else skip ; x := x + 1) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- X=int(input()) prime=[True]*(100010) prime[0]=False ; prime[1]=False ; for i in range(4,100010,2): prime[i]=False i=3 while(i*i<=100008): if prime[i]: for j in range(i+i,100008,i): prime[j]=False i+=2 for i in range(X,100008): if prime[i]: print(i) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var X : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (100010)) ; prime->first() := false; ; prime[1+1] := false; ; for i : Integer.subrange(4, 100010-1)->select( $x | ($x - 4) mod 2 = 0 ) do ( prime[i+1] := false) ; var i : int := 3 ; while (i * i <= 100008) do ( if prime[i+1] then ( for j : Integer.subrange(i + i, 100008-1)->select( $x | ($x - i + i) mod i = 0 ) do ( prime[j+1] := false) ) else skip ; i := i + 2) ; for i : Integer.subrange(X, 100008-1) do ( if prime[i+1] then ( execute (i)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- txt=input() cu=0 cl=0 for z in txt : if z.islower(): cl=cl+1 else : cu=cu+1 if cu>cl : out=txt.upper() else : out=txt.lower() print(out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var txt : String := (OclFile["System.in"]).readLine() ; var cu : int := 0 ; var cl : int := 0 ; for z : txt->characters() do ( if z->matches("[a-z ]*") then ( cl := cl + 1 ) else ( cu := cu + 1 )) ; if (cu->compareTo(cl)) > 0 then ( var out : String := txt->toUpperCase() ) else ( out := txt->toLowerCase() ) ; execute (out)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- list=[] a,n,s=map(int,input().split()) ans=[] for i in range(1,10001): if i**n<=s : list.append(i**n) for i in list : k=str(i) d=a for j in k : d+=int(j) if d**n==i : ans.append(i) print(len(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var OclType["Sequence"] : Sequence := Sequence{} ; var a : OclAny := null; var n : OclAny := null; var s : OclAny := null; Sequence{a,n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(1, 10001-1) do ( if ((i)->pow(n)->compareTo(s)) <= 0 then ( execute (((i)->pow(n)) : OclType["Sequence"]) ) else skip) ; for i : OclType["Sequence"] do ( var k : String := ("" + ((i))) ; var d : OclAny := a ; for j : k->characters() do ( d := d + ("" + ((j)))->toInteger()) ; if (d)->pow(n) = i then ( execute ((i) : ans) ) else skip) ; execute ((ans)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def val(x): sum=0 while x>0 : sum+=x % 10 x//=10 return sum a,n,m=map(int,input().split()) cnt=0 for y in range(1,73): x=1 for t in range(1,n+1): x*=(y+a) if x<=m and val(x)==y : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var n : OclAny := null; var m : OclAny := null; Sequence{a,n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cnt : int := 0 ; for y : Integer.subrange(1, 73-1) do ( x := 1 ; for t : Integer.subrange(1, n + 1-1) do ( x := x * (y + a)) ; if (x->compareTo(m)) <= 0 & val(x) = y then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display(); operation val(x : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; while x > 0 do ( sum := sum + x mod 10 ; x := x div 10) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,n,m=map(int,input().split()) ans=0 for i in range(a,int(m**(1/2))+1): x=i**n if not 1<=x<=m : continue y=i-a if sum(map(int,list(str(x))))==y : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var n : OclAny := null; var m : OclAny := null; Sequence{a,n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; for i : Integer.subrange(a, ("" + (((m)->pow((1 / 2)))))->toInteger() + 1-1) do ( var x : double := (i)->pow(n) ; if not(1 <= x & (x <= m)) then ( continue ) else skip ; var y : double := i - a ; if (((("" + ((x))))->characters())->collect( _x | (OclType["int"])->apply(_x) ))->sum() = y then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pivotedBinarySearch(arr,n,key): pivot=findPivot(arr,0,n-1); if pivot==-1 : return binarySearch(arr,0,n-1,key); if arr[pivot]==key : return pivot if arr[0]<=key : return binarySearch(arr,0,pivot-1,key); return binarySearch(arr,pivot+1,n-1,key); def findPivot(arr,low,high): if higharr[mid+1]: return mid if mid>low and arr[mid]=arr[mid]: return findPivot(arr,low,mid-1) return findPivot(arr,mid+1,high) def binarySearch(arr,low,high,key): if higharr[mid]: return binarySearch(arr,(mid+1),high,key); return binarySearch(arr,low,(mid-1),key); arr1=[5,6,7,8,9,10,1,2,3] n=len(arr1) key=3 print("Index of the element is : ",pivotedBinarySearch(arr1,n,key)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var arr1 : Sequence := Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{10}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })))))))) ; n := (arr1)->size() ; key := 3 ; execute ("Index of the element is : ")->display(); operation pivotedBinarySearch(arr : OclAny, n : OclAny, key : OclAny) : OclAny pre: true post: true activity: var pivot : OclAny := findPivot(arr, 0, n - 1); ; if pivot = -1 then ( return binarySearch(arr, 0, n - 1, key); ) else skip ; if arr[pivot+1] = key then ( return pivot ) else skip ; if (arr->first()->compareTo(key)) <= 0 then ( return binarySearch(arr, 0, pivot - 1, key); ) else skip ; return binarySearch(arr, pivot + 1, n - 1, key);; operation findPivot(arr : OclAny, low : OclAny, high : OclAny) : OclAny pre: true post: true activity: if (high->compareTo(low)) < 0 then ( return -1 ) else skip ; if high = low then ( return low ) else skip ; var mid : int := ("" + (((low + high) / 2)))->toInteger() ; if (mid->compareTo(high)) < 0 & (arr[mid+1]->compareTo(arr[mid + 1+1])) > 0 then ( return mid ) else skip ; if (mid->compareTo(low)) > 0 & (arr[mid+1]->compareTo(arr[mid - 1+1])) < 0 then ( return (mid - 1) ) else skip ; if (arr[low+1]->compareTo(arr[mid+1])) >= 0 then ( return findPivot(arr, low, mid - 1) ) else skip ; return findPivot(arr, mid + 1, high); operation binarySearch(arr : OclAny, low : OclAny, high : OclAny, key : OclAny) : OclAny pre: true post: true activity: if (high->compareTo(low)) < 0 then ( return -1 ) else skip ; mid := ("" + (((low + high) / 2)))->toInteger() ; if key = arr[mid+1] then ( return mid ) else skip ; if (key->compareTo(arr[mid+1])) > 0 then ( return binarySearch(arr, (mid + 1), high, key); ) else skip ; return binarySearch(arr, low, (mid - 1), key);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input())+1 d=1000000007 g=[[1]*n for i in range(n)] for i in range(1,n): g[i][0]=g[i-1][i-1] for j in range(1,i+1): g[i][j]=(g[i][j-1]+g[i-1][j-1])% d print((g[-1][-1]-g[-1][0])% d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() + 1 ; var d : int := 1000000007 ; var g : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 1 }, n))) ; for i : Integer.subrange(1, n-1) do ( g[i+1]->first() := g[i - 1+1][i - 1+1] ; for j : Integer.subrange(1, i + 1-1) do ( g[i+1][j+1] := (g[i+1][j - 1+1] + g[i - 1+1][j - 1+1]) mod d)) ; execute ((g->last()->last() - g->last()->first()) mod d)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=10**9+7 n=int(input()) f=[0]*(n+1) f[0]=1 count=1 for i in range(1,n+1): for j in range(0,i): f[(count+j+n+1)%(n+1)]=(f[(count-i+j+n+1)%(n+1)]+f[(count+j+n)%(n+1)]+mod)% mod count=(count+i+n+1)%(n+1) print(f[(count-1+n)%(n+1)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : double := (10)->pow(9) + 7 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; f->first() := 1 ; var count : int := 1 ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(0, i-1) do ( f[(count + j + n + 1) mod (n + 1)+1] := (f[(count - i + j + n + 1) mod (n + 1)+1] + f[(count + j + n) mod (n + 1)+1] + mod) mod mod) ; count := (count + i + n + 1) mod (n + 1)) ; execute (f[(count - 1 + n) mod (n + 1)+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin from collections import defaultdict,deque answer=[] n=int(input()) a=list(map(int,input().split())) b=sorted(a) d={x : i for i,x in enumerate(a)} visited=[0]*n for i,x in enumerate(a): if visited[i]: continue seq=[i] visited[i]=1 hold=a[i] while hold!=b[seq[-1]]: z=d[b[seq[-1]]] visited[z]=1 seq.append(z) answer.append(' '.join(map(str,[len(seq)]+[x+1 for x in seq]))) print(len(answer)) print('\n'.join(answer)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var answer : Sequence := Sequence{} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := a->sort() ; var d : Map := Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} )->select(_tuple | true)->collect(_tuple | Map{x |-> i})->unionAll() ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); if visited[i+1] then ( continue ) else skip ; var seq : Sequence := Sequence{ i } ; visited[i+1] := 1 ; var hold : OclAny := a[i+1] ; while hold /= b[seq->last()+1] do ( var z : OclAny := d[b[seq->last()+1]+1] ; visited[z+1] := 1 ; execute ((z) : seq)) ; execute ((StringLib.sumStringsWithSeparator(((Sequence{ (seq)->size() }->union(seq->select(x | true)->collect(x | (x + 1))))->collect( _x | (OclType["String"])->apply(_x) )), ' ')) : answer)) ; execute ((answer)->size())->display() ; execute (StringLib.sumStringsWithSeparator((answer), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maps(): return[int(i)for i in input().split()] import pprint import logging from logging import getLogger logging.basicConfig(format="%(message)s",level=logging.WARNING,) logger=getLogger(__name__) logger.setLevel(logging.INFO) def debug(msg,*args): logger.info(f'{msg}={pprint.pformat(args)}') n,=maps() a=sorted([(i,j)for i,j in enumerate(maps())],key=lambda x : x[1]) ans=[] check=[False]*n for i in range(n): if i==a[i][0]: ans.append((1,[i+1])) continue if not check[i]: cyc=[a[i][0]] x=a[a[i][0]][0] check[a[i][0]]=True while not check[x]: cyc.append(x) check[x]=True x=a[x][0] cyc=[i+1 for i in cyc] ans.append((len(cyc),cyc)) print(len(ans)) for i in ans : print(i[0],*i[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; logging.basicConfig((argument (test (logical_test (comparison (expr (atom (name format)))))) = (test (logical_test (comparison (expr (atom "%(message)s")))))), (arglist (argument (test (logical_test (comparison (expr (atom (name level)))))) = (test (logical_test (comparison (expr (atom (name logging)) (trailer . (name WARNING))))))) ,)) ; var logger : OclAny := getLogger(__name__) ; logger.setLevel(logging.INFO) ; skip ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,)} := maps() ; var a : Sequence := Integer.subrange(1, (maps())->size())->collect( _indx | Sequence{_indx-1, (maps())->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let j : OclAny = _tuple->at(2) in (Sequence{i, j}))->sortedBy($x | (lambda x : OclAny in (x[1+1]))->apply($x)) ; var ans : Sequence := Sequence{} ; var check : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ; for i : Integer.subrange(0, n-1) do ( if i = a[i+1]->first() then ( execute ((Sequence{1, Sequence{ i + 1 }}) : ans) ; continue ) else skip ; if not(check[i+1]) then ( var cyc : Sequence := Sequence{ a[i+1]->first() } ; var x : OclAny := a[a[i+1]->first()+1]->first() ; check[a[i+1]->first()+1] := true ; while not(check[x+1]) do ( execute ((x) : cyc) ; check[x+1] := true ; x := a[x+1]->first()) ; cyc := cyc->select(i | true)->collect(i | (i + 1)) ; execute ((Sequence{(cyc)->size(), cyc}) : ans) ) else skip) ; execute ((ans)->size())->display() ; for i : ans do ( execute (i->first())->display()); operation maps() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation debug(msg : OclAny, args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) logger.info(StringLib.formattedString('{msg}={pprint.pformat(args)}')); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- vector=((0,-1),(1,0),(0,1),(-1,0)) def make_guruguru(d): lst=[["#"]*(d+4)] for _ in range(d+2): lst.append(["#"]+[""]*(d+2)+["#"]) lst.append(["#"]*(d+4)) x,y=2,d+1 lst[y][x]="#" direct=0 vx,vy=vector[0] cnt=1 while True : while lst[y+vy*2][x+vx*2]=="" : lst[y+vy][x+vx]="#" y+=vy x+=vx cnt+=1 if cnt<=1 : break direct=(direct+1)% 4 vx,vy=vector[direct] cnt=0 for y in range(2,d+2): print("".join(lst[y][2 :-2])) n=int(input()) make_guruguru(int(input())) for _ in range(n-1): print() make_guruguru(int(input())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var vector : OclAny := Sequence{Sequence{0, -1}, Sequence{1, 0}, Sequence{0, 1}, Sequence{-1, 0}} ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; make_guruguru(("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; for _anon : Integer.subrange(0, n - 1-1) do ( execute (->display() ; make_guruguru(("" + (((OclFile["System.in"]).readLine())))->toInteger())); operation make_guruguru(d : OclAny) pre: true post: true activity: var lst : Sequence := Sequence{ MatrixLib.elementwiseMult(Sequence{ "#" }, (d + 4)) } ; for _anon : Integer.subrange(0, d + 2-1) do ( execute ((Sequence{ "#" }->union(MatrixLib.elementwiseMult(Sequence{ "" }, (d + 2)))->union(Sequence{ "#" })) : lst)) ; execute ((MatrixLib.elementwiseMult(Sequence{ "#" }, (d + 4))) : lst) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{2,d + 1} ; lst[y+1][x+1] := "#" ; var direct : int := 0 ; var vx : OclAny := null; var vy : OclAny := null; Sequence{vx,vy} := vector->first() ; var cnt : int := 1 ; while true do ( while lst[y + vy * 2+1][x + vx * 2+1] = "" do ( lst[y + vy+1][x + vx+1] := "#" ; y := y + vy ; x := x + vx ; cnt := cnt + 1) ; if cnt <= 1 then ( break ) else skip ; direct := (direct + 1) mod 4 ; var vx : OclAny := null; var vy : OclAny := null; Sequence{vx,vy} := vector[direct+1] ; cnt := 0) ; for y : Integer.subrange(2, d + 2-1) do ( execute (StringLib.sumStringsWithSeparator((lst[y+1].subrange(2+1, -2)), ""))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def p(t): for r in t : for c in r : print(c,end="") print("") a=int(input()) for j in range(a): n=int(input()) t=[["" for _ in range(n)]for _ in range(n)] d=1 for i in range(n): t[i][0]="#" x=0 y=0 for m in range(n-1): l=n-1-(m//2)*2 for i in range(l): if d==0 : y-=1 elif d==1 : x+=1 elif d==2 : y+=1 elif d==3 : x-=1 t[y][x]="#" d=(d+1)% 4 p(t) if j!=a-1 : print("") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, a-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; t := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ("")))) ; var d : int := 1 ; for i : Integer.subrange(0, n-1) do ( t[i+1]->first() := "#") ; var x : int := 0 ; var y : int := 0 ; for m : Integer.subrange(0, n - 1-1) do ( var l : double := n - 1 - (m div 2) * 2 ; for i : Integer.subrange(0, l-1) do ( if d = 0 then ( y := y - 1 ) else (if d = 1 then ( x := x + 1 ) else (if d = 2 then ( y := y + 1 ) else (if d = 3 then ( x := x - 1 ) else skip ) ) ) ; t[y+1][x+1] := "#") ; d := (d + 1) mod 4) ; p(t) ; if j /= a - 1 then ( execute ("")->display() ) else skip); operation p(t : OclAny) pre: true post: true activity: for r : t do ( for c : r do ( execute (c)->display()) ; execute ("")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=str(input()) up=0 lo=0 for i in range(len(s)): if s[i].isupper(): up+=1 else : lo+=1 if lo>=up : x=s.lower() print(x) else : x=s.upper() print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; var up : int := 0 ; var lo : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1]->matches("[A-Z ]*") then ( up := up + 1 ) else ( lo := lo + 1 )) ; if (lo->compareTo(up)) >= 0 then ( var x : String := s->toLowerCase() ; execute (x)->display() ) else ( x := s->toUpperCase() ; execute (x)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): line=input() bought_count=Counter(line) line=input() made_cout=Counter(line) res=0 for color in made_cout : if color not in bought_count : return print(-1) res+=min(bought_count[color],made_cout[color]) print(res) def main(): t=1 for _ in range(t): solution() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; main(); operation solution() : OclAny pre: true post: true activity: var line : String := (OclFile["System.in"]).readLine() ; var bought_count : OclAny := Counter(line) ; line := (OclFile["System.in"]).readLine() ; var made_cout : OclAny := Counter(line) ; var res : int := 0 ; for color : made_cout do ( if (bought_count)->excludes(color) then ( return (-1)->display() ) else skip ; res := res + Set{bought_count[color+1], made_cout[color+1]}->min()) ; execute (res)->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline from itertools import cycle def guruguru(n): line=0 dirs=cycle([(0,-1),(1,0),(0,1),(-1,0)]) M=[['']*n for _ in range(n)] cx=0 cy=n-1 while line=n : break if ny<0 or ny>=n : break if nny<0 or nny>=n or nnx<0 or nnx>=n : pass else : if M[nny][nnx]!='' : break cx=nx cy=ny for l in M : print(''.join(map(str,l))) def main(args): n=int(input()) for i in range(n): size=int(input()) guruguru(size) if i!=(n-1): print() if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation guruguru(n : OclAny) pre: true post: true activity: var line : int := 0 ; var dirs : OclAny := cycle(Sequence{Sequence{0, -1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{ Sequence{-1, 0} })))) ; var M : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ '' }, n))) ; var cx : int := 0 ; var cy : double := n - 1 ; while (line->compareTo(n)) < 0 do ( line := line + 1 ; var dx : OclAny := null; var dy : OclAny := null; Sequence{dx,dy} := dirs.__next__() ; while true do ( M[cy+1][cx+1] := '#' ; var nx : int := cx + dx ; var ny : OclAny := cy + dy ; var nnx : int := nx + dx ; var nny : OclAny := ny + dy ; if nx < 0 or (nx->compareTo(n)) >= 0 then ( break ) else skip ; if ny < 0 or (ny->compareTo(n)) >= 0 then ( break ) else skip ; if nny < 0 or (nny->compareTo(n)) >= 0 or nnx < 0 or (nnx->compareTo(n)) >= 0 then ( skip ) else ( if M[nny+1][nnx+1] /= '' then ( break ) else skip ) ; cx := nx ; cy := ny)) ; for l : M do ( execute (StringLib.sumStringsWithSeparator(((l)->collect( _x | (OclType["String"])->apply(_x) )), ''))->display()); operation main(args : OclAny) pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var size : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; guruguru(size) ; if i /= (n - 1) then ( execute (->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dd=((-1,0),(0,-1),(1,0),(0,1)) d=int(input()) for i in range(d): if i : print() N=int(input()) MP=[[" "]*N for i in range(N)] for i in range(N): MP[i][0]="#" def walk(x,y,d,n): dx,dy=dd[d % 4] for k in range(n): x+=dx ; y+=dy MP[y][x]="#" return x,y x=y=0 r=N-1 ; d=2 while r>1 : x,y=walk(x,y,d,r) x,y=walk(x,y,d+1,r) r-=2 ; d+=2 if r==1 : walk(x,y,d,r) for line in MP : print(*line,sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dd : OclAny := Sequence{Sequence{-1, 0}, Sequence{0, -1}, Sequence{1, 0}, Sequence{0, 1}} ; var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, d-1) do ( if i then ( execute (->display() ) else skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var MP : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ " " }, N))) ; for i : Integer.subrange(0, N-1) do ( MP[i+1]->first() := "#") ; skip ; x := 0; y := 0 ; var r : double := N - 1; d := 2 ; while r > 1 do ( Sequence{x,y} := walk(x, y, d, r) ; Sequence{x,y} := walk(x, y, d + 1, r) ; r := r - 2; d := d + 2) ; if r = 1 then ( walk(x, y, d, r) ) else skip ; for line : MP do ( execute ((argument * (test (logical_test (comparison (expr (atom (name line))))))))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline M=[] def guruguru(n): global M dirs=[(0,-1),(1,0),(0,1),(-1,0)] M=[['']*n for _ in range(n)] cx=0 cy=n-1 line=0 while lineunion(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{ Sequence{-1, 0} }))) ; M := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ '' }, n))) ; var cx : int := 0 ; var cy : double := n - 1 ; var line : int := 0 ; while (line->compareTo(n)) < 0 do ( var dx : OclAny := null; var dy : OclAny := null; Sequence{dx,dy} := dirs[line mod 4+1] ; line := line + 1 ; while true do ( M[cy+1][cx+1] := '#' ; var nx : int := cx + dx ; if not(0 <= nx & (nx < n)) then ( break ) else skip ; var ny : OclAny := cy + dy ; if not(0 <= ny & (ny < n)) then ( break ) else skip ; var nnx : int := nx + dx ; var nny : OclAny := ny + dy ; if 0 <= nny & (nny < n) & 0 <= nnx & (nnx < n) then ( if M[nny+1][nnx+1] /= '' then ( break ) else skip ) else skip ; cx := nx ; cy := ny)) ; for l : M do ( execute (StringLib.sumStringsWithSeparator((l), ''))->display()); operation main(args : OclAny) pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var size : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; guruguru(size) ; if i /= (n - 1) then ( execute (->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): ans=sum(1 for i in range(1<<10)for j in range(i,1<<10)if eulerlib.popcount(i)==eulerlib.popcount(j)==6 and is_arrangement_valid(i,j)) return str(ans) def is_arrangement_valid(a,b): if test_bit(a,6)or test_bit(a,9): a |=(1<<6)|(1<<9) if test_bit(b,6)or test_bit(b,9): b |=(1<<6)|(1<<9) return all(((test_bit(a,c)and test_bit(b,d))or(test_bit(a,d)and test_bit(b,c)))for(c,d)in SQUARES) def test_bit(x,i): return((x>>i)& 1)!=0 SQUARES=[(i**2//10,i**2 % 10)for i in range(1,10)] if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var SQUARES : Sequence := Integer.subrange(1, 10-1)->select(i | true)->collect(i | (Sequence{(i)->pow(2) div 10, (i)->pow(2) mod 10})) ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (number (integer 10)))))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (number (integer 10)))))))))) )))))) (comp_iter if (test (logical_test (logical_test (comparison (comparison (comparison (expr (atom (name eulerlib)) (trailer . (name popcount) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) == (comparison (expr (atom (name eulerlib)) (trailer . (name popcount) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))))) == (comparison (expr (atom (number (integer 6))))))) and (logical_test (comparison (expr (atom (name is_arrangement_valid)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (name j)))))))) ))))))))))))))->sum() ; return ("" + ((ans))); operation is_arrangement_valid(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if test_bit(a, 6) or test_bit(a, 9) then ( a := a or MathLib.bitwiseOr((1 * (2->pow(6))), (1 * (2->pow(9)))) ) else skip ; if test_bit(b, 6) or test_bit(b, 9) then ( b := b or MathLib.bitwiseOr((1 * (2->pow(6))), (1 * (2->pow(9)))) ) else skip ; return ((argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (expr (atom (name test_bit)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))))) and (logical_test (comparison (expr (atom (name test_bit)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b))))))) , (argument (test (logical_test (comparison (expr (atom (name d)))))))) ))))))))) ))))) or (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (expr (atom (name test_bit)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name d)))))))) )))))) and (logical_test (comparison (expr (atom (name test_bit)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b))))))) , (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))))) )))))))) )))))) (comp_for for (exprlist (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name c)))))) , (test (logical_test (comparison (expr (atom (name d))))))) )))) in (logical_test (comparison (expr (atom (name SQUARES))))))))->forAll( _x | _x = true ); operation test_bit(x : OclAny, i : OclAny) : OclAny pre: true post: true activity: return (MathLib.bitwiseAnd((x /(2->pow(i))), 1)) /= 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[[0 for i in range(n)]for j in range(n)] for i in range(n): info=[int(x)for x in input().split()] for j in info[2 :]: a[i][j-1]=1 for v in a : print(*v) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, n-1) do ( var info : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for j : info.subrange(2+1) do ( a[i+1][j - 1+1] := 1)) ; for v : a do ( execute ((argument * (test (logical_test (comparison (expr (atom (name v))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def generate_graph(v_info): for info in v_info : adj_info=info[2 :] for each in adj_info : adj_matrix[int(info[0])-1][int(each)-1]=1 return adj_matrix if __name__=='__main__' : _input=sys.stdin.readlines() vertex_num=int(_input[0]) adj_matrix=[[0]*vertex_num for _ in range(vertex_num)] vertex_info=list(map(lambda x : x.split(),_input[1 :])) ans=generate_graph(vertex_info) for v_result in ans : print(*v_result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var _input : OclAny := (OclFile["System.in"]).readlines() ; var vertex_num : int := ("" + ((_input->first())))->toInteger() ; var adj_matrix : Sequence := Integer.subrange(0, vertex_num-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, vertex_num))) ; var vertex_info : Sequence := ((_input->tail())->collect( _x | (lambda x : OclAny in (x.split()))->apply(_x) )) ; var ans : OclAny := generate_graph(vertex_info) ; for v_result : ans do ( execute ((argument * (test (logical_test (comparison (expr (atom (name v_result))))))))->display()) ) else skip; operation generate_graph(v_info : OclAny) : OclAny pre: true post: true activity: for info : v_info do ( var adj_info : OclAny := info.subrange(2+1) ; for each : adj_info do ( adj_matrix[("" + ((info->first())))->toInteger() - 1+1][("" + ((each)))->toInteger() - 1+1] := 1)) ; return adj_matrix; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import itertools sys.setrecursionlimit(1000000000) from heapq import heapify,heappop,heappush,heappushpop import math import collections import copy if __name__=="__main__" : n=int(input()) edge=[] for i in range(n): u,k,*v_li=map(int,input().split()) u-=1 for j in range(len(v_li)): v_li[j]-=1 edge.append(v_li) ans_edge=[[0]*n for j in range(n)] for j in range(len(edge)): for k in range(len(edge[j])): ans_edge[j][edge[j][k]]=1 for j in range(len(ans_edge)): print(*ans_edge[j]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit(1000000000) ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var edge : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var u : OclAny := null; var k : OclAny := null; var v_li : OclAny := null; Sequence{u,k,v_li} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; u := u - 1 ; for j : Integer.subrange(0, (v_li)->size()-1) do ( v_li[j+1] := v_li[j+1] - 1) ; execute ((v_li) : edge)) ; var ans_edge : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (MatrixLib.elementwiseMult(Sequence{ 0 }, n))) ; for j : Integer.subrange(0, (edge)->size()-1) do ( for k : Integer.subrange(0, (edge[j+1])->size()-1) do ( ans_edge[j+1][edge[j+1][k+1]+1] := 1)) ; for j : Integer.subrange(0, (ans_edge)->size()-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name ans_edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))))->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") n=int(input()) G=[[0 for _ in range(n)]for __ in range(n)] for row in range(n): inp=[int(_)for _ in input().split()] a=inp[0] if inp[1]>0 : for b in inp[2 :]: G[a-1][b-1]=1 for row in G : print(' '.join([str(_)for _ in row])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var G : Sequence := Integer.subrange(0, n-1)->select(__ | true)->collect(__ | (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)))) ; for row : Integer.subrange(0, n-1) do ( var inp : Sequence := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var a : OclAny := inp->first() ; if inp[1+1] > 0 then ( for b : inp.subrange(2+1) do ( G[a - 1+1][b - 1+1] := 1) ) else skip) ; for row : G do ( execute (StringLib.sumStringsWithSeparator((row->select(_anon | true)->collect(_anon | (("" + ((_anon)))))), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline()[:-1] sys.setrecursionlimit(10**8) n=int(input()) G=[[0]*n for i in range(n)] for i in range(n): inp=tuple(map(int,input().split())) now=inp[0] for j in range(2,inp[1]+2): G[now-1][inp[j]-1]=1 for g in G : print(*g) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine()->front()) ; sys.setrecursionlimit((10)->pow(8)) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var G : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, n))) ; for i : Integer.subrange(0, n-1) do ( var inp : Sequence := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var now : OclAny := inp->first() ; for j : Integer.subrange(2, inp[1+1] + 2-1) do ( G[now - 1+1][inp[j+1] - 1+1] := 1)) ; for g : G do ( execute ((argument * (test (logical_test (comparison (expr (atom (name g))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() upper=0 lower=0 for letter in x : if letter.islower(): lower+=1 else : upper+=1 if upper>lower : print(x.upper()) else : print(x.lower()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := (OclFile["System.in"]).readLine() ; var upper : int := 0 ; var lower : int := 0 ; for letter : x->characters() do ( if letter->matches("[a-z ]*") then ( lower := lower + 1 ) else ( upper := upper + 1 )) ; if (upper->compareTo(lower)) > 0 then ( execute (x->toUpperCase())->display() ) else ( execute (x->toLowerCase())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=[] for i in range(n): x=[i for i in input()] a.append(x) count=0 for j in range(m-1): for i in range(n-1): x=set([a[i][j],a[i+1][j],a[i][j+1],a[i+1][j+1]]) if x=={'a','f','c','e'}: count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x : Sequence := (OclFile["System.in"]).readLine()->select(i | true)->collect(i | (i)) ; execute ((x) : a)) ; var count : int := 0 ; for j : Integer.subrange(0, m - 1-1) do ( for i : Integer.subrange(0, n - 1-1) do ( x := Set{}->union((Sequence{a[i+1][j+1]}->union(Sequence{a[i + 1+1][j+1]}->union(Sequence{a[i+1][j + 1+1]}->union(Sequence{ a[i + 1+1][j + 1+1] }))))) ; if x = Set{'a'}->union(Set{'f'}->union(Set{'c'}->union(Set{ 'e' }))) then ( count := count + 1 ) else skip)) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline s=input()[:-1] w=input()[:-1] x=0 for i in set(w): c=min(s.count(i),w.count(i)) if c==0 : print(-1) break x+=c else : print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var s : OclAny := input()->front() ; var w : OclAny := input()->front() ; var x : int := 0 ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name w)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name w)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name c)))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name c)))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) table=[] for i in range(n): table.append(input()) ans=0 for i in range(n-1): for j in range(m-1): di=[0,0,1,1] dj=[0,1,0,1] d={} for k in range(4): c=table[i+di[k]][j+dj[k]] d[c]=d.get(c,0)+1 flg=True for c in "face" : if c not in d or d[c]!=1 : flg=False if flg : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var table : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : table)) ; var ans : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(0, m - 1-1) do ( var di : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 1 }))) ; var dj : Sequence := Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 1 }))) ; var d : OclAny := Set{} ; for k : Integer.subrange(0, 4-1) do ( var c : OclAny := table[i + di[k+1]+1][j + dj[k+1]+1] ; d[c+1] := d.get(c, 0) + 1) ; var flg : boolean := true ; for c : "face"->characters() do ( if (d)->excludes(c) or d[c+1] /= 1 then ( flg := false ) else skip) ; if flg then ( ans := ans + 1 ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- string=input() numbers=string.split() a=int(numbers[0]) b=int(numbers[1]) rows=[] for x in range(a): row=input() rows.append(row) faces=0 for x in range(a-1): for y in range(b-1): p=rows[x] q=rows[x+1] face=["f","a","c","e"] square=[p[y],p[y+1],q[y],q[y+1]] condition=True for z in face : if not z in square : condition=False if condition : faces+=1 print(faces) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var string : String := (OclFile["System.in"]).readLine() ; var numbers : OclAny := string.split() ; var a : int := ("" + ((numbers->first())))->toInteger() ; var b : int := ("" + ((numbers[1+1])))->toInteger() ; var rows : Sequence := Sequence{} ; for x : Integer.subrange(0, a-1) do ( var row : String := (OclFile["System.in"]).readLine() ; execute ((row) : rows)) ; var faces : int := 0 ; for x : Integer.subrange(0, a - 1-1) do ( for y : Integer.subrange(0, b - 1-1) do ( var p : OclAny := rows[x+1] ; var q : OclAny := rows[x + 1+1] ; var face : Sequence := Sequence{"f"}->union(Sequence{"a"}->union(Sequence{"c"}->union(Sequence{ "e" }))) ; var square : Sequence := Sequence{p[y+1]}->union(Sequence{p[y + 1+1]}->union(Sequence{q[y+1]}->union(Sequence{ q[y + 1+1] }))) ; var condition : boolean := true ; for z : face do ( if not((square)->includes(z)) then ( condition := false ) else skip) ; if condition then ( faces := faces + 1 ) else skip)) ; execute (faces)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(i)for i in input().split()] a=[0]*n for i in range(n): a[i]=input().split()[0] ctr=0 for i in range(n-1): for j in range(m-1): if set([a[i][j],a[i+1][j],a[i][j+1],a[i+1][j+1]])=={'f','a','c','e'}: ctr+=1 print(ctr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( a[i+1] := input().split()->first()) ; var ctr : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(0, m - 1-1) do ( if Set{}->union((Sequence{a[i+1][j+1]}->union(Sequence{a[i + 1+1][j+1]}->union(Sequence{a[i+1][j + 1+1]}->union(Sequence{ a[i + 1+1][j + 1+1] }))))) = Set{'f'}->union(Set{'a'}->union(Set{'c'}->union(Set{ 'e' }))) then ( ctr := ctr + 1 ) else skip)) ; execute (ctr)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=list() x=0 for i in range(n): a.append(input()) for i in range(n): for j in range(m): b=list() try : b.append(a[i][j]) b.append(a[i][j+1]) b.append(a[i+1][j]) b.append(a[i+1][j+1]) if 'f' in b and 'a' in b and 'c' in b and 'e' in b : x+=1 except : pass print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := () ; var x : int := 0 ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : a)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( var b : Sequence := () ; try ( execute ((a[i+1][j+1]) : b) ; execute ((a[i+1][j + 1+1]) : b) ; execute ((a[i + 1+1][j+1]) : b) ; execute ((a[i + 1+1][j + 1+1]) : b) ; if (b)->includes('f') & (b)->includes('a') & (b)->includes('c') & (b)->includes('e') then ( x := x + 1 ) else skip) catch (_e : OclException) do ( skip) )) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import setrecursionlimit setrecursionlimit(10**8) n,m=[int(i)for i in input().split()] A=[[int(i)for i in input().split()]for i in range(m)] if m % 2==1 : print(-1) exit() E=[[]for i in range(n+1)] used_e=[False]*m ans=[] for i,(a,b)in enumerate(A): E[a].append((b,i)) E[b].append((a,i)) used=[False]*(n+1) def dfs(prev,v): if used[v]: return used[v]=True cnt=0 for to,i in E[v]: dfs(v,to) if not used_e[i]: cnt+=1 for to,i in E[v]: if cnt % 2==1 and to==prev : continue if not used_e[i]: ans.append((v,to)) used_e[i]=True dfs(0,1) for a in ans : print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; setrecursionlimit((10)->pow(8)) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var A : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())))) ; if m mod 2 = 1 then ( execute (-1)->display() ; exit() ) else skip ; var E : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Sequence{})) ; var used_e : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, m) ; var ans : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{a, b} : OclAny := _tuple->at(_indx); (expr (atom (name E)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name b)))))) , (test (logical_test (comparison (expr (atom (name i))))))) )))))))) )))) ; (expr (atom (name E)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name i))))))) )))))))) ))))) ; var used : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (n + 1)) ; skip ; dfs(0, 1) ; for a : ans do ( execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display()); operation dfs(prev : OclAny, v : OclAny) pre: true post: true activity: if used[v+1] then ( return ) else skip ; used[v+1] := true ; var cnt : int := 0 ; for _tuple : E[v+1] do (var _indx : int := 1; var to : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); dfs(v, to) ; if not(used_e[i+1]) then ( cnt := cnt + 1 ) else skip) ; for _tuple : E[v+1] do (var _indx : int := 1; var to : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); if cnt mod 2 = 1 & to = prev then ( continue ) else skip ; if not(used_e[i+1]) then ( execute ((Sequence{v, to}) : ans) ; used_e[i+1] := true ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(200000) N,M=map(int,input().split()) lisN=[[]for i in range(N)] xorlis=[0]*N AB=[] if M % 2==1 : print(-1) sys.exit() for i in range(M): a,b=map(int,input().split()) AB.append([a,b]) a-=1 b-=1 lisN[a].append([b,i]) lisN[b].append([a,i]) xorlis[b]^=1 visited=[False]*N def dfs(now): visited[now]=True for nex,eind in lisN[now]: if visited[nex]: continue cat=dfs(nex) if cat!=0 : xorlis[nex]^=1 xorlis[now]^=1 t=AB[eind][1] AB[eind][1]=AB[eind][0] AB[eind][0]=t return xorlis[now] dfs(0) if 1 in xorlis : print(-1) sys.exit() else : for i,j in AB : print(j,i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(200000) ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lisN : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{})) ; var xorlis : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var AB : Sequence := Sequence{} ; if M mod 2 = 1 then ( execute (-1)->display() ; sys.exit() ) else skip ; for i : Integer.subrange(0, M-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a}->union(Sequence{ b })) : AB) ; a := a - 1 ; b := b - 1 ; (expr (atom (name lisN)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name b)))))) , (test (logical_test (comparison (expr (atom (name i))))))) ]))))))) )))) ; (expr (atom (name lisN)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name i))))))) ]))))))) )))) ; xorlis[b+1] := xorlis[b+1] xor 1) ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, N) ; skip ; dfs(0) ; if (xorlis)->includes(1) then ( execute (-1)->display() ; sys.exit() ) else ( for _tuple : AB do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); execute (j)->display()) ); operation dfs(now : OclAny) : OclAny pre: true post: true activity: visited[now+1] := true ; for _tuple : lisN[now+1] do (var _indx : int := 1; var nex : OclAny := _tuple->at(_indx); _indx := _indx + 1; var eind : OclAny := _tuple->at(_indx); if visited[nex+1] then ( continue ) else skip ; var cat : OclAny := dfs(nex) ; if cat /= 0 then ( xorlis[nex+1] := xorlis[nex+1] xor 1 ; xorlis[now+1] := xorlis[now+1] xor 1 ; var t : OclAny := AB[eind+1][1+1] ; AB[eind+1][1+1] := AB[eind+1]->first() ; AB[eind+1]->first() := t ) else skip) ; return xorlis[now+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np from collections import deque import heapq N,M=map(int,input().split()) edges=[set()for _ in range(N)] degs=[0 for i in range(N)] parity=[0 for _ in range(N)] flag=[False for _ in range(N)] for _ in range(M): a,b=map(int,input().split()) edges[a-1].add(b-1) edges[b-1].add(a-1) degs[a-1]+=1 degs[b-1]+=1 if M % 2!=0 : print(-1) exit() Q=[] for i,d in enumerate(degs): Q.append((d,i)) heapq.heapify(Q) while len(Q)>0 : _,u=Q[0] heapq.heappop(Q) if flag[u]: continue flag[u]=True for i,v in enumerate(edges[u]): edges[v].remove(u) if parity[u]!=0 and i==0 : print(u+1,v+1) parity[u]=1-parity[u] else : print(v+1,u+1) parity[v]=1-parity[v] degs[v]-=1 heapq.heappush(Q,(degs[v],v)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var edges : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; var degs : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; var parity : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (0)) ; var flag : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (false)) ; for _anon : Integer.subrange(0, M-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) )))) ; degs[a - 1+1] := degs[a - 1+1] + 1 ; degs[b - 1+1] := degs[b - 1+1] + 1) ; if M mod 2 /= 0 then ( execute (-1)->display() ; exit() ) else skip ; var Q : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (degs)->size())->collect( _indx | Sequence{_indx-1, (degs)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); execute ((Sequence{d, i}) : Q)) ; heapq.heapify(Q) ; while (Q)->size() > 0 do ( var _anon : OclAny := null; var u : OclAny := null; Sequence{_anon,u} := Q->first() ; heapq.heappop(Q) ; if flag[u+1] then ( continue ) else skip ; flag[u+1] := true ; for _tuple : Integer.subrange(1, (edges[u+1])->size())->collect( _indx | Sequence{_indx-1, (edges[u+1])->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name remove) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)))))))) )))) ; if parity[u+1] /= 0 & i = 0 then ( execute (u + 1)->display() ; parity[u+1] := 1 - parity[u+1] ) else ( execute (v + 1)->display() ; parity[v+1] := 1 - parity[v+1] ) ; degs[v+1] := degs[v+1] - 1 ; heapq.heappush(Q, Sequence{degs[v+1], v}))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque n,m=map(int,input().split()) ab=[list(map(int,input().split()))for _ in range(m)] if m % 2 : print(-1) exit() adj=[[]for _ in range(n+1)] for a,b in ab : adj[a].append(b) adj[b].append(a) s=1 dq=deque([s]) d=[-1]*(n+1) d[s]=0 p=[-1]*(n+1) order=[] while dq : u=dq.popleft() order.append(u) for v in adj[u]: if d[v]==-1 : d[v]=d[u]+1 p[v]=u dq.append(v) out=[0]*(n+1) ans=[] for a,b in ab : if p[a]==b or p[b]==a : continue ans.append((a,b)) out[a]^=1 for v in order[1 :][: :-1]: u=p[v] if out[v]: ans.append((v,u)) out[v]^=1 else : ans.append((u,v)) out[u]^=1 for u,v in ans : print(u,v) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ab : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; if m mod 2 then ( execute (-1)->display() ; exit() ) else skip ; var adj : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _tuple : ab do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var s : int := 1 ; var dq : Sequence := (Sequence{ s }) ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (n + 1)) ; d[s+1] := 0 ; var p : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (n + 1)) ; var order : Sequence := Sequence{} ; while dq do ( var u : OclAny := dq->first() ; dq := dq->tail() ; execute ((u) : order) ; for v : adj[u+1] do ( if d[v+1] = -1 then ( d[v+1] := d[u+1] + 1 ; p[v+1] := u ; execute ((v) : dq) ) else skip)) ; var out : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var ans : Sequence := Sequence{} ; for _tuple : ab do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if p[a+1] = b or p[b+1] = a then ( continue ) else skip ; execute ((Sequence{a, b}) : ans) ; out[a+1] := out[a+1] xor 1) ; for v : order->tail()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( u := p[v+1] ; if out[v+1] then ( execute ((Sequence{v, u}) : ans) ; out[v+1] := out[v+1] xor 1 ) else ( execute ((Sequence{u, v}) : ans) ; out[u+1] := out[u+1] xor 1 )) ; for _tuple : ans do (var _indx : int := 1; var u : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); execute (u)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def task9(A,B,n): for X in range(-1000,1001): if A*(X**n)==B : return X return "No solution" [A,B,n]=input().split() print(task9(int(A),int(B),int(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{A}->union(Sequence{B}->union(Sequence{ n })) := input().split() ; execute (task9(("" + ((A)))->toInteger(), ("" + ((B)))->toInteger(), ("" + ((n)))->toInteger()))->display(); operation task9(A : OclAny, B : OclAny, n : OclAny) : OclAny pre: true post: true activity: for X : Integer.subrange(-1000, 1001-1) do ( if A * ((X)->pow(n)) = B then ( return X ) else skip) ; return "No solution"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def frequencyOfSmallest(n,arr): mn=arr[0] freq=1 for i in range(1,n): if(arr[i]union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 4 })))) ; execute (frequencyOfSmallest(N, arr))->display() ) else skip; operation frequencyOfSmallest(n : OclAny, arr : OclAny) : OclAny pre: true post: true activity: var mn : OclAny := arr->first() ; var freq : int := 1 ; for i : Integer.subrange(1, n-1) do ( if ((arr[i+1]->compareTo(mn)) < 0) then ( mn := arr[i+1] ; freq := 1 ) else (if (arr[i+1] = mn) then ( freq := freq + 1 ) else skip)) ; return freq; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) input=sys.stdin.readline n,m=[int(item)for item in input().split()] if m % 2!=0 : print(-1) exit() visited_e=[False]*m visited_v=[False]*n edge=[[]for _ in range(n)] for i in range(m): a,b=[int(item)for item in input().split()] a-=1 ; b-=1 edge[a].append([b,i]) edge[b].append([a,i]) ans=[] def dfs(prev,n): if visited_v[n]: return 1 visited_v[n]=True child_num=0 for v,index in edge[n]: if visited_e[index]: continue visited_e[index]=True if dfs(n,v)==1 : child_num+=1 ans.append([n+1,v+1]) if child_num % 2==0 : return 1 else : ans.append([n+1,prev+1]) return 0 dfs(-1,0) print("\n".join([str(f)+" "+str(t)for f,t in ans])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; if m mod 2 /= 0 then ( execute (-1)->display() ; exit() ) else skip ; var visited_e : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, m) ; var visited_v : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ; var edge : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; a := a - 1; b := b - 1 ; (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name b)))))) , (test (logical_test (comparison (expr (atom (name i))))))) ]))))))) )))) ; (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name i))))))) ]))))))) ))))) ; var ans : Sequence := Sequence{} ; skip ; dfs(-1, 0) ; execute (StringLib.sumStringsWithSeparator((ans->select(_tuple | true)->collect(_tuple | let f : OclAny = _tuple->at(1) in let t : OclAny = _tuple->at(2) in (("" + ((f))) + " " + ("" + ((t)))))), "\n"))->display(); operation dfs(prev : OclAny, n : OclAny) : OclAny pre: true post: true activity: if visited_v[n+1] then ( return 1 ) else skip ; visited_v[n+1] := true ; var child_num : int := 0 ; for _tuple : edge[n+1] do (var _indx : int := 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var index : OclAny := _tuple->at(_indx); if visited_e[index+1] then ( continue ) else skip ; visited_e[index+1] := true ; if dfs(n, v) = 1 then ( child_num := child_num + 1 ; execute ((Sequence{n + 1}->union(Sequence{ v + 1 })) : ans) ) else skip) ; if child_num mod 2 = 0 then ( return 1 ) else ( execute ((Sequence{n + 1}->union(Sequence{ prev + 1 })) : ans) ; return 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from itertools import accumulate MOD=10**9+7 n,c=map(int,input().split()) A=tuple(map(int,input().split())) B=tuple(map(int,input().split())) E=[[0]*(c+1)for _ in range(n)] for j in range(c+1): cumsum=tuple(pow(k,j,MOD)for k in range(401)) cumsum=tuple(i % MOD for i in accumulate(cumsum)) for i,(a,b)in enumerate(zip(A,B)): E[i][j]=cumsum[b]-cumsum[a-1] dp=[[0]*(c+1)for _ in range(n+1)] dp[0][0]=1 for i,e in enumerate(E): for j,f in enumerate(e): for k in range(c+1): if j+k<=c : dp[i+1][j+k]+=dp[i][k]*f dp[i+1][j+k]%=MOD ans=dp[n][c] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var MOD : double := (10)->pow(9) + 7 ; var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var B : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var E : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (c + 1)))) ; for j : Integer.subrange(0, c + 1-1) do ( var cumsum : Sequence := ((argument (test (logical_test (comparison (expr (atom (name pow)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name k))))))) , (argument (test (logical_test (comparison (expr (atom (name j))))))) , (argument (test (logical_test (comparison (expr (atom (name MOD)))))))) ))))))) (comp_for for (exprlist (expr (atom (name k)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 401))))))))) ))))))))) ; cumsum := ((argument (test (logical_test (comparison (expr (expr (atom (name i))) % (expr (atom (name MOD))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name accumulate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name cumsum)))))))) ))))))))) ; for _tuple : Integer.subrange(1, (Integer.subrange(1, A->size())->collect( _indx | Sequence{A->at(_indx), B->at(_indx)} ))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(1, A->size())->collect( _indx | Sequence{A->at(_indx), B->at(_indx)} ))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{a, b} : OclAny := _tuple->at(_indx); E[i+1][j+1] := cumsum[b+1] - cumsum[a - 1+1])) ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (c + 1)))) ; dp->first()->first() := 1 ; for _tuple : Integer.subrange(1, (E)->size())->collect( _indx | Sequence{_indx-1, (E)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var e : OclAny := _tuple->at(_indx); for _tuple : Integer.subrange(1, (e)->size())->collect( _indx | Sequence{_indx-1, (e)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var f : OclAny := _tuple->at(_indx); for k : Integer.subrange(0, c + 1-1) do ( if (j + k->compareTo(c)) <= 0 then ( dp[i + 1+1][j + k+1] := dp[i + 1+1][j + k+1] + dp[i+1][k+1] * f ; dp[i + 1+1][j + k+1] := dp[i + 1+1][j + k+1] mod MOD ) else skip))) ; var ans : OclAny := dp[n+1][c+1] ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() m=input() s=set(m) c=0 for i in s : a1=n.count(i) a2=m.count(i) if a1==0 : c=-1 break else : c+=min(a1,a2) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var m : String := (OclFile["System.in"]).readLine() ; var s : Set := Set{}->union((m)) ; var c : int := 0 ; for i : s do ( var a1 : int := n->count(i) ; var a2 : int := m->count(i) ; if a1 = 0 then ( c := -1 ; break ) else ( c := c + Set{a1, a2}->min() )) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np N,C=map(int,input().split()) A=list(map(int,input().split())) B=list(map(int,input().split())) mod=10**9+7 P=np.empty((404,404),dtype=np.int64) P[0,:]=1 ar=np.arange(404,dtype=np.int64) for i in range(1,404): P[i]=P[i-1]*ar % mod P=P.cumsum(axis=1,dtype=np.int64)% mod P=P.T dp=np.zeros(C+1,dtype=np.int64) dp[0]=1 for a,b in zip(A,B): dp_new=np.zeros(C+1,dtype=np.int64) p=(P[b]-P[a-1])% mod for c in range(C+1): dp_new[c]=(dp[: c+1]*p[c : :-1]% mod).sum() dp=dp_new % mod print(dp[C]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var C : OclAny := null; Sequence{N,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var B : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mod : double := (10)->pow(9) + 7 ; var P : Sequence := MatrixLib.singleValueMatrix(Sequence{404, 404}, 0.0) ; P->first() := 1 ; var ar : Sequence := MathLib.numericRange(404, (argument (test (logical_test (comparison (expr (atom (name dtype)))))) = (test (logical_test (comparison (expr (atom (name np)) (trailer . (name int64))))))), 1) ; for i : Integer.subrange(1, 404-1) do ( P[i+1] := MatrixLib.elementwiseMult(ar, P[i - 1+1]) mod mod) ; P := P.cumsum((argument (test (logical_test (comparison (expr (atom (name axis)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))), (argument (test (logical_test (comparison (expr (atom (name dtype)))))) = (test (logical_test (comparison (expr (atom (name np)) (trailer . (name int64)))))))) mod mod ; P := P.T ; var dp : Sequence := MatrixLib.singleValueMatrix(C + 1, 0.0) ; dp->first() := 1 ; for _tuple : Integer.subrange(1, A->size())->collect( _indx | Sequence{A->at(_indx), B->at(_indx)} ) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); var dp_new : Sequence := MatrixLib.singleValueMatrix(C + 1, 0.0) ; var p : int := (P[b+1] - P[a - 1+1]) mod mod ; for c : Integer.subrange(0, C + 1-1) do ( dp_new[c+1] := (dp.subrange(1,c + 1) * p(subscript (test (logical_test (comparison (expr (atom (name c)))))) : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) mod mod).sum()) ; dp := dp_new mod mod) ; execute (dp[C+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline sys.setrecursionlimit(pow(10,6)) MOD=pow(10,9)+7 def main(): n,c=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) abc=[[0 for _ in range(401)]for _ in range(401)] for i in range(401): abc[0][i]=1 abc[0][0]=0 for i in range(1,401): for j in range(1,401): abc[j][i]=abc[j-1][i]*i % MOD for i in range(1,401): for j in range(401): abc[j][i]+=abc[j][i-1] if abc[j][i]>=MOD : abc[j][i]-=MOD dp=[[0 for _ in range(c+1)]for _ in range(n+1)] dp[0][0]=1 for i in range(1,n+1): for j in range(c+1): for k in range(j+1): accm=abc[k][b[i-1]]-abc[k][a[i-1]-1] if accm<0 : accm+=MOD dp[i][j]+=dp[i-1][j-k]*accm % MOD if dp[i][j]>=MOD : dp[i][j]-=MOD print(dp[n][c]) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit((10)->pow(6)) ; var MOD : double := (10)->pow(9) + 7 ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var abc : Sequence := Integer.subrange(0, 401-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, 401-1)->select(_anon | true)->collect(_anon | (0)))) ; for i : Integer.subrange(0, 401-1) do ( abc->first()[i+1] := 1) ; abc->first()->first() := 0 ; for i : Integer.subrange(1, 401-1) do ( for j : Integer.subrange(1, 401-1) do ( abc[j+1][i+1] := abc[j - 1+1][i+1] * i mod MOD)) ; for i : Integer.subrange(1, 401-1) do ( for j : Integer.subrange(0, 401-1) do ( abc[j+1][i+1] := abc[j+1][i+1] + abc[j+1][i - 1+1] ; if (abc[j+1][i+1]->compareTo(MOD)) >= 0 then ( abc[j+1][i+1] := abc[j+1][i+1] - MOD ) else skip)) ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, c + 1-1)->select(_anon | true)->collect(_anon | (0)))) ; dp->first()->first() := 1 ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(0, c + 1-1) do ( for k : Integer.subrange(0, j + 1-1) do ( var accm : double := abc[k+1][b[i - 1+1]+1] - abc[k+1][a[i - 1+1] - 1+1] ; if accm < 0 then ( accm := accm + MOD ) else skip ; dp[i+1][j+1] := dp[i+1][j+1] + dp[i - 1+1][j - k+1] * accm mod MOD ; if (dp[i+1][j+1]->compareTo(MOD)) >= 0 then ( dp[i+1][j+1] := dp[i+1][j+1] - MOD ) else skip))) ; execute (dp[n+1][c+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=10**9+7 table=[[0 for i in range(401)]for j in range(401)] for i in range(401): S=0 for j in range(1,401): S+=pow(j,i,mod) S %=mod table[i][j]=S N,C=map(int,input().split()) A=list(map(int,input().split())) B=list(map(int,input().split())) dp=[[0 for i in range(C+1)]for j in range(N)] for i in range(C+1): dp[0][i]=table[i][B[0]]-table[i][A[0]-1] dp[0][i]%=mod for i in range(1,N): for j in range(C+1): dp[i][j]=sum(dp[i-1][j-k]*(table[k][B[i]]-table[k][A[i]-1])for k in range(j+1)) dp[i][j]%=mod print(dp[N-1][C]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : double := (10)->pow(9) + 7 ; var table : Sequence := Integer.subrange(0, 401-1)->select(j | true)->collect(j | (Integer.subrange(0, 401-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, 401-1) do ( var S : int := 0 ; for j : Integer.subrange(1, 401-1) do ( S := S + (j)->pow(i) ; S := S mod mod ; table[i+1][j+1] := S)) ; var N : OclAny := null; var C : OclAny := null; Sequence{N,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var B : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dp : Sequence := Integer.subrange(0, N-1)->select(j | true)->collect(j | (Integer.subrange(0, C + 1-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, C + 1-1) do ( dp->first()[i+1] := table[i+1][B->first()+1] - table[i+1][A->first() - 1+1] ; dp->first()[i+1] := dp->first()[i+1] mod mod) ; for i : Integer.subrange(1, N-1) do ( for j : Integer.subrange(0, C + 1-1) do ( dp[i+1][j+1] := ((argument (test (logical_test (comparison (expr (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name j))) - (expr (atom (name k))))))))) ]))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name table)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name B)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ]))) - (expr (atom (name table)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (number (integer 1)))))))))) ])))))))) ))))))) (comp_for for (exprlist (expr (atom (name k)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 1)))))))))) )))))))))->sum() ; dp[i+1][j+1] := dp[i+1][j+1] mod mod)) ; execute (dp[N - 1+1][C+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from itertools import accumulate readline=sys.stdin.readline MOD=10**9+7 N,C=map(int,readline().split()) A=[0]+list(map(int,readline().split())) B=[0]+list(map(int,readline().split())) acsq=[] lb=max(B)+1 for j in range(C+1): ac=[0]*lb ac[0]=1 for i in range(1,lb): ac[i]=(ac[i-1]+pow(i,j,MOD))% MOD acsq.append(ac) dp=[[0]*(C+1)for _ in range(N+1)] dp[0][0]=1 for i in range(1,N+1): a,b=A[i],B[i] for c in range(C+1): res=0 for j in range(c+1): res=(res+(acsq[c-j][b]-acsq[c-j][a-1])*dp[i-1][j])% MOD dp[i][c]=res print(dp[N][C]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var MOD : double := (10)->pow(9) + 7 ; var N : OclAny := null; var C : OclAny := null; Sequence{N,C} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := Sequence{ 0 }->union(((readline().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var B : Sequence := Sequence{ 0 }->union(((readline().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var acsq : Sequence := Sequence{} ; var lb : OclAny := (B)->max() + 1 ; for j : Integer.subrange(0, C + 1-1) do ( var ac : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, lb) ; ac->first() := 1 ; for i : Integer.subrange(1, lb-1) do ( ac[i+1] := (ac[i - 1+1] + (i)->pow(j)) mod MOD) ; execute ((ac) : acsq)) ; var dp : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (C + 1)))) ; dp->first()->first() := 1 ; for i : Integer.subrange(1, N + 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{A[i+1],B[i+1]} ; for c : Integer.subrange(0, C + 1-1) do ( var res : int := 0 ; for j : Integer.subrange(0, c + 1-1) do ( res := (res + (acsq[c - j+1][b+1] - acsq[c - j+1][a - 1+1]) * dp[i - 1+1][j+1]) mod MOD) ; dp[i+1][c+1] := res)) ; execute (dp[N+1][C+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from typing import List,Tuple from collections import defaultdict,deque,namedtuple from heapq import heappush as push,heappop as pop import sys INF=(int)(1e9+7) sys.setrecursionlimit(INF) def alternatingCurrent(wires): stk=[] for upperWire in wires : if stk and stk[-1]==upperWire : stk.pop() continue stk.append(upperWire) if stk : return 'No' return 'Yes' if __name__=="__main__" : wires=input() print(alternatingCurrent(wires)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var INF : OclAny := (OclType["int"])(("1e9")->toReal() + 7) ; sys.setrecursionlimit(INF) ; skip ; if __name__ = "__main__" then ( wires := (OclFile["System.in"]).readLine() ; execute (alternatingCurrent(wires))->display() ) else skip; operation alternatingCurrent(wires : OclAny) : OclAny pre: true post: true activity: var stk : Sequence := Sequence{} ; for upperWire : wires do ( if stk & stk->last() = upperWire then ( stk := stk->front() ; continue ) else skip ; execute ((upperWire) : stk)) ; if stk then ( return 'No' ) else skip ; return 'Yes'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math class Solution : def entangled(self,nums): stack=[] while nums : x=nums.pop() if stack : if stack[-1]==x : stack.pop() else : stack.append(x) else : stack.append(x) if stack : print("NO") else : print("YES") def main(): sol=Solution() nums=list(input().strip()) sol.entangled(nums) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class Solution { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation entangled(nums : OclAny) pre: true post: true activity: var stack : Sequence := Sequence{} ; while nums do ( var x : OclAny := nums->last() ; nums := nums->front() ; if stack then ( if stack->last() = x then ( stack := stack->front() ) else ( execute ((x) : stack) ) ) else ( execute ((x) : stack) )) ; if stack then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var sol : Solution := (Solution.newSolution()).initialise() ; nums := (input()->trim()) ; sol.entangled(nums); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- wires=input() arr=[] arr.append(wires[0]) for i in range(1,len(wires)): try : if wires[i]==arr[-1]: arr.pop() else : arr.append(wires[i]) except : arr.append(wires[i]) continue if(len(arr)==0): print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var wires : String := (OclFile["System.in"]).readLine() ; var arr : Sequence := Sequence{} ; execute ((wires->first()) : arr) ; for i : Integer.subrange(1, (wires)->size()-1) do ( try ( if wires[i+1] = arr->last() then ( arr := arr->front() ) else ( execute ((wires[i+1]) : arr) )) catch (_e : OclException) do ( execute ((wires[i+1]) : arr) ; continue) ) ; if ((arr)->size() = 0) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isSubArray(A,B,n,m): i=0 ; j=0 ; while(iunion(Sequence{3}->union(Sequence{0}->union(Sequence{5}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 2 })))))); ; n := (A)->size(); ; B := Sequence{3}->union(Sequence{0}->union(Sequence{5}->union(Sequence{ 1 }))); ; m := (B)->size(); ; if (isSubArray(A, B, n, m)) then ( execute ("YES")->display(); ) else ( execute ("NO")->display(); ) ) else skip; operation isSubArray(A : OclAny, B : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: var i : int := 0; var j : int := 0; ; while ((i->compareTo(n)) < 0 & (j->compareTo(m)) < 0) do ( if (A[i+1] = B[j+1]) then ( i := i + 1; ; j := j + 1; ; if (j = m) then ( return true; ) else skip ) else ( i := i - j + 1; ; j := 0; )) ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input().strip() st=['!'] for si in s : if st[-1]==si : st.pop() else : st.append(si) print('Yes' if len(st)==1 else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := input()->trim() ; var st : Sequence := Sequence{ '!' } ; for si : s do ( if st->last() = si then ( st := st->front() ) else ( execute ((si) : st) )) ; execute (if (st)->size() = 1 then 'Yes' else 'No' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() tmp=0 result=0 for i in range(len(s)): if s[i]=='+' : tmp=1 else : tmp=-1 if i % 2==1 : tmp=-tmp result+=tmp print('YES')if result==0 else print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var tmp : int := 0 ; var result : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = '+' then ( tmp := 1 ) else ( tmp := -1 ) ; if i mod 2 = 1 then ( tmp := -tmp ) else skip ; result := result + tmp) ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))) if (logical_test (comparison (comparison (expr (atom (name result)))) == (comparison (expr (atom (number (integer 0))))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) )))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import deque sys.setrecursionlimit(10**9) def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) INF=float('inf') class BipartiteMatching : def __init__(self,n,m): self.n=n self.m=m self.edges=[set()for _ in range(n)] self.match1=[-1]*n self.match2=[-1]*m def dfs(self,v,visited): for u in self.edges[v]: if u in visited : continue visited.add(u) if self.match2[u]==-1 or self.dfs(self.match2[u],visited): self.match2[u]=v self.match1[v]=u return True return False def add(self,a,b): self.edges[a].add(b) def whois1(self,a): return self.match1[a] def whois2(self,a): return self.match2[a] def solve(self): return sum(self.dfs(i,set())for i in range(self.n)) N,M,E=MAP() bm=BipartiteMatching(N,M) for i in range(E): x,y=MAP() bm.add(x,y) print(bm.solve()) ------------------------------------------------------------ OCL File: --------- class BipartiteMatching { static operation newBipartiteMatching() : BipartiteMatching pre: true post: BipartiteMatching->exists( _x | result = _x ); attribute n : OclAny := n; attribute m : OclAny := m; attribute edges : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))); attribute match1 : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n); attribute match2 : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, m); operation initialise(n : OclAny,m : OclAny) : BipartiteMatching pre: true post: true activity: self.n := n ; self.m := m ; self.edges := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; self.match1 := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; self.match2 := MatrixLib.elementwiseMult(Sequence{ -1 }, m); return self; operation dfs(v : OclAny,visited : OclAny) : OclAny pre: true post: true activity: for u : self.edges[v+1] do ( if (visited)->includes(u) then ( continue ) else skip ; execute ((u) : visited) ; if self.match2[u+1] = -1 or self.dfs(self.match2[u+1], visited) then ( self.match2[u+1] := v ; self.match1[v+1] := u ; return true ) else skip) ; return false; operation add(a : OclAny,b : OclAny) pre: true post: true activity: (expr (atom (name self)) (trailer . (name edges) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))); operation whois1(a : OclAny) : OclAny pre: true post: true activity: return self.match1[a+1]; operation whois2(a : OclAny) : OclAny pre: true post: true activity: return self.match2[a+1]; operation solve() : OclAny pre: true post: true activity: return ((argument (test (logical_test (comparison (expr (atom (name self)) (trailer . (name dfs) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (name set)) (trailer (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name self)) (trailer . (name n)))))))) )))))))))->sum(); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; skip ; skip ; skip ; skip ; var INF : double := ("" + (('inf')))->toReal() ; skip ; var N : OclAny := null; var M : OclAny := null; var E : OclAny := null; Sequence{N,M,E} := MAP() ; var bm : BipartiteMatching := (BipartiteMatching.newBipartiteMatching()).initialise(N, M) ; for i : Integer.subrange(0, E-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := MAP() ; execute ((x, y) : bm)) ; execute (bm.solve())->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() y=input() d1={} d2={} count=0 for i in x : d1[i]=x.count(i) for i in y : d2[i]=y.count(i) for i in d2.keys(): if i in d1.keys(): if d1[i]characters() do ( d1[i+1] := x->count(i)) ; for i : y->characters() do ( d2[i+1] := y->count(i)) ; for i : d2.keys() do ( if (d1.keys())->includes(i) then ( if (d1[i+1]->compareTo(d2[i+1])) < 0 then ( count := count + d1[i+1] ) else ( count := count + d2[i+1] ) ) else ( count := -1 ; break )) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): LI=lambda :[int(x)for x in sys.stdin.readline().split()] X,Y,E=LI() edge=[set()for _ in range(X+Y+2)] for _ in range(E): a,b=LI() i=a+1 j=b+X+1 edge[i].add(j) for i in range(1,X+1): edge[0].add(i) for j in range(X+1,X+Y+1): edge[j].add(X+Y+1) ans=0 while True : node=[-2]*(X+Y+2) node[0]=-1 q=collections.deque() q.append(0) while q : u=q.pop() for v in edge[u]: if v==X+Y+1 : ans+=1 node[v]=u break if node[v]<-1 : node[v]=u q.append(v) else : continue break else : break u=X+Y+1 while node[u]>=0 : edge[node[u]].remove(u) edge[u].add(node[u]) u=node[u] print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var LI : Function := lambda $$ : OclAny in (sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) ; var X : OclAny := null; var Y : OclAny := null; var E : OclAny := null; Sequence{X,Y,E} := LI->apply() ; var edge : Sequence := Integer.subrange(0, X + Y + 2-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; for _anon : Integer.subrange(0, E-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := LI->apply() ; var i : OclAny := a + 1 ; var j : OclAny := b + X + 1 ; (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) ))))) ; for i : Integer.subrange(1, X + 1-1) do ((expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; for j : Integer.subrange(X + 1, X + Y + 1-1) do ((expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name X))) + (expr (atom (name Y)))) + (expr (atom (number (integer 1)))))))))) ))))) ; var ans : int := 0 ; while true do ( var node : Sequence := MatrixLib.elementwiseMult(Sequence{ -2 }, (X + Y + 2)) ; node->first() := -1 ; var q : Sequence := () ; execute ((0) : q) ; (compound_stmt while (test (logical_test (comparison (expr (atom (name q)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name u)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name q)) (trailer . (name pop) (arguments ( ))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name v)))) in (testlist (test (logical_test (comparison (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ]))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name v)))) == (comparison (expr (expr (expr (atom (name X))) + (expr (atom (name Y)))) + (expr (atom (number (integer 1))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name node)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name u)))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name node)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])))) < (comparison (expr (atom - (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name node)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name u)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name q)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt continue))))))) (stmt (simple_stmt (small_stmt break)))) (else_clause else : (suite (stmt (simple_stmt (small_stmt break)))))) ; var u : OclAny := X + Y + 1 ; while node[u+1] >= 0 do ((expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name node)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])))))))) ])) (trailer . (name remove) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)))))))) )))) ; (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name node)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])))))))) )))) ; u := node[u+1])) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class BipartiteGraph(object): def __init__(self,num_nodes): self.graph=[[]for _ in range(num_nodes)] self.match=[None]*num_nodes def add_edge(self,u,v): self.graph[u].append(v) self.graph[v].append(u) def has_increasing_path(self,v,used): used[v]=True for i,u in enumerate(self.graph[v]): w=self.match[u] if w is None or(not used[w]and self.has_increasing_path(w,used)): self.match[v]=u self.match[u]=v return True return False def __str__(self): ret=["graph bipartite_graph{"] for v,g in enumerate(self.graph): for u in g : ret.append("{}--{};".format(v,u)) ret.append("}") return "\n".join(ret) def solve(self): ret=0 for v in range(len(self.graph)): if self.match[v]is not None : continue if self.has_increasing_path(v,[False]*len(self.graph)): ret+=1 return ret if __name__=="__main__" : X,Y,E=list(map(int,input().split())) bg=BipartiteGraph(X+Y) for _ in range(E): x,y=list(map(int,input().split())) y+=X bg.add_edge(x,y) print(bg.solve()) ------------------------------------------------------------ OCL File: --------- class BipartiteGraph extends object { static operation newBipartiteGraph() : BipartiteGraph pre: true post: BipartiteGraph->exists( _x | result = _x ); attribute graph : Sequence := Integer.subrange(0, num_nodes-1)->select(_anon | true)->collect(_anon | (Sequence{})); attribute match : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, num_nodes); operation initialise(num_nodes : OclAny) : pre: true post: true activity: self.graph := Integer.subrange(0, num_nodes-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; self.match := MatrixLib.elementwiseMult(Sequence{ null }, num_nodes); return self; operation add_edge(u : OclAny,v : OclAny) pre: true post: true activity: (expr (atom (name self)) (trailer . (name graph) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) ; (expr (atom (name self)) (trailer . (name graph) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)))))))) )))); operation has_increasing_path(v : OclAny,used : OclAny) : OclAny pre: true post: true activity: used[v+1] := true ; for _tuple : Integer.subrange(1, (self.graph[v+1])->size())->collect( _indx | Sequence{_indx-1, (self.graph[v+1])->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var u : OclAny := _tuple->at(_indx); var w : OclAny := self.match[u+1] ; if w <>= null or (not(used[w+1]) & self.has_increasing_path(w, used)) then ( self.match[v+1] := u ; self.match[u+1] := v ; return true ) else skip) ; return false; operation __str__() : OclAny pre: true post: true activity: var ret : Sequence := Sequence{ "graph bipartite_graph{" } ; for _tuple : Integer.subrange(1, (self.graph)->size())->collect( _indx | Sequence{_indx-1, (self.graph)->at(_indx)} ) do (var _indx : int := 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var g : OclAny := _tuple->at(_indx); for u : g do ( execute ((StringLib.interpolateStrings("{}--{};", Sequence{v, u})) : ret))) ; execute (("}") : ret) ; return StringLib.sumStringsWithSeparator((ret), "\n"); operation solve() : OclAny pre: true post: true activity: ret := 0 ; for v : Integer.subrange(0, (self.graph)->size()-1) do ( if not(self.match[v+1] <>= null) then ( continue ) else skip ; if self.has_increasing_path(v, MatrixLib.elementwiseMult(Sequence{ false }, (self.graph)->size())) then ( ret := ret + 1 ) else skip) ; return ret; } class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var X : OclAny := null; var Y : OclAny := null; var E : OclAny := null; Sequence{X,Y,E} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var bg : BipartiteGraph := (BipartiteGraph.newBipartiteGraph()).initialise(X + Y) ; for _anon : Integer.subrange(0, E-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; y := y + X ; bg.add_edge(x, y)) ; execute (bg.solve())->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def generate_adj_table(_edges): for edge in _edges : vx,vy=map(int,edge) init_adj_table[vx].add(vy) return init_adj_table def graph_dfs(current,matching,visited): for target in range(y_num): if(not visited[target])and(target in adj_table[current]): visited[target]=True if matching[target]==-1 or graph_dfs(matching[target],matching,visited): matching[target]=current return True return False def mbm(): matching=[-1]*y_num res=0 for source in range(x_num): visited=[False]*y_num if graph_dfs(source,matching,visited): res+=1 return res if __name__=='__main__' : _input=sys.stdin.readlines() x_num,y_num,e_num=map(int,_input[0].split()) edges=map(lambda x : x.split(),_input[1 :]) init_adj_table=[set()for _ in range(x_num)] adj_table=generate_adj_table(edges) print(mbm()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var _input : OclAny := (OclFile["System.in"]).readlines() ; var x_num : OclAny := null; var y_num : OclAny := null; var e_num : OclAny := null; Sequence{x_num,y_num,e_num} := (_input->first().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var edges : Sequence := (_input->tail())->collect( _x | (lambda x : OclAny in (x.split()))->apply(_x) ) ; var init_adj_table : Sequence := Integer.subrange(0, x_num-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; var adj_table : OclAny := generate_adj_table(edges) ; execute (mbm())->display() ) else skip; operation generate_adj_table(_edges : OclAny) : OclAny pre: true post: true activity: for edge : _edges do ( var vx : OclAny := null; var vy : OclAny := null; Sequence{vx,vy} := (edge)->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name init_adj_table)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name vx)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name vy)))))))) ))))) ; return init_adj_table; operation graph_dfs(current : OclAny, matching : OclAny, visited : OclAny) : OclAny pre: true post: true activity: for target : Integer.subrange(0, y_num-1) do ( if (not(visited[target+1])) & ((adj_table[current+1])->includes(target)) then ( visited[target+1] := true ; if matching[target+1] = -1 or graph_dfs(matching[target+1], matching, visited) then ( matching[target+1] := current ; return true ) else skip ) else skip) ; return false; operation mbm() : OclAny pre: true post: true activity: matching := MatrixLib.elementwiseMult(Sequence{ -1 }, y_num) ; var res : int := 0 ; for source : Integer.subrange(0, x_num-1) do ( visited := MatrixLib.elementwiseMult(Sequence{ false }, y_num) ; if graph_dfs(source, matching, visited) then ( res := res + 1 ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class BipartiteMatching(): def __init__(self,V1,V2): self.V1=V1 self.V2=V2 self.V=V1+V2 self.graph=[[]for _ in range(V1+V2)] def add_edge(self,v1,v2): v2+=self.V1 self.graph[v1].append(v2) self.graph[v2].append(v1) def dfs(self,s): self.par=[None]*self.V self.used=[False]*self.V self.used[s]=True self.stack=[s] while self.stack : v=self.stack.pop() for nv in self.graph[v]: w=self.match[nv] if w<0 : while True : self.match[v]=nv self.match[nv]=v if v==s : return True v,nv=self.par[v] elif not self.used[w]: self.par[w]=(v,nv) self.used[w]=True self.stack.append(w) return False def bipartite_matching(self): res=0 self.match=[-1]*self.V for v in range(self.V): if self.match[v]<0 : if self.dfs(v): res+=1 return res if __name__=='__main__' : import sys input=sys.stdin.readline V1,V2,E=map(int,input().split()) bm=BipartiteMatching(V1,V2) for _ in range(E): a,b=map(int,input().split()) bm.add_edge(a,b) print(bm.bipartite_matching()) ------------------------------------------------------------ OCL File: --------- class BipartiteMatching { static operation newBipartiteMatching() : BipartiteMatching pre: true post: BipartiteMatching->exists( _x | result = _x ); attribute V1 : OclAny := V1; attribute V2 : OclAny := V2; attribute V : OclAny := V1 + V2; attribute graph : Sequence := Integer.subrange(0, V1 + V2-1)->select(_anon | true)->collect(_anon | (Sequence{})); operation initialise(V1 : OclAny,V2 : OclAny) : pre: true post: true activity: self.V1 := V1 ; self.V2 := V2 ; self.V := V1 + V2 ; self.graph := Integer.subrange(0, V1 + V2-1)->select(_anon | true)->collect(_anon | (Sequence{})); return self; operation add_edge(v1 : OclAny,v2 : OclAny) pre: true post: true activity: v2 := v2 + self.V1 ; (expr (atom (name self)) (trailer . (name graph) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v1)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v2)))))))) )))) ; (expr (atom (name self)) (trailer . (name graph) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v2)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v1)))))))) )))); operation dfs(s : OclAny) : OclAny pre: true post: true activity: self.par := MatrixLib.elementwiseMult(Sequence{ null }, self.V) ; self.used := MatrixLib.elementwiseMult(Sequence{ false }, self.V) ; self.used[s+1] := true ; self.stack := Sequence{ s } ; while self.stack do ( var v : OclAny := self.stack->last() ; for nv : self.graph[v+1] do ( var w : OclAny := self.match[nv+1] ; if w < 0 then ( while true do ( self.match[v+1] := nv ; self.match[nv+1] := v ; if v = s then ( return true ) else skip ; var nv : OclAny := null; Sequence{v,nv} := self.par[v+1]) ) else (if not(self.used[w+1]) then ( self.par[w+1] := Sequence{v, nv} ; self.used[w+1] := true ; (expr (atom (name self)) (trailer . (name stack)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name w)))))))) )))) ) else skip))) ; return false; operation bipartite_matching() : OclAny pre: true post: true activity: var res : int := 0 ; self.match := MatrixLib.elementwiseMult(Sequence{ -1 }, self.V) ; for v : Integer.subrange(0, self.V-1) do ( if self.match[v+1] < 0 then ( if self.dfs(v) then ( res := res + 1 ) else skip ) else skip) ; return res; } class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( skip ; var input : OclAny := (OclFile["System.in"]).readline ; var E : OclAny := null; Sequence{V1,V2,E} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var bm : BipartiteMatching := (BipartiteMatching.newBipartiteMatching()).initialise(V1, V2) ; for _anon : Integer.subrange(0, E-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; bm.add_edge(a, b)) ; execute (bm.bipartite_matching())->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100 def countMountains(a,n): A=[[0 for i in range(n+2)]for i in range(n+2)] count=0 for i in range(n+2): for j in range(n+2): if((i==0)or(j==0)or(i==n+1)or(j==n+1)): A[i][j]=float('-inf') else : A[i][j]=a[i-1][j-1] for i in range(n+1): for j in range(n+1): if((A[i][j]>A[i-1][j])and(A[i][j]>A[i+1][j])and(A[i][j]>A[i][j-1])and(A[i][j]>A[i][j+1])and(A[i][j]>A[i-1][j-1])and(A[i][j]>A[i+1][j+1])and(A[i][j]>A[i-1][j+1])and(A[i][j]>A[i+1][j-1])): count=count+1 return count a=[[1,2,3],[4,5,6],[7,8,9]] n=3 print(countMountains(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 100 ; skip ; a := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))}->union(Sequence{ Sequence{7}->union(Sequence{8}->union(Sequence{ 9 })) })) ; n := 3 ; execute (countMountains(a, n))->display(); operation countMountains(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var A : Sequence := Integer.subrange(0, n + 2-1)->select(i | true)->collect(i | (Integer.subrange(0, n + 2-1)->select(i | true)->collect(i | (0)))) ; var count : int := 0 ; for i : Integer.subrange(0, n + 2-1) do ( for j : Integer.subrange(0, n + 2-1) do ( if ((i = 0) or (j = 0) or (i = n + 1) or (j = n + 1)) then ( A[i+1][j+1] := ("" + (('-inf')))->toReal() ) else ( A[i+1][j+1] := a[i - 1+1][j - 1+1] ))) ; for i : Integer.subrange(0, n + 1-1) do ( for j : Integer.subrange(0, n + 1-1) do ( if (((A[i+1][j+1]->compareTo(A[i - 1+1][j+1])) > 0) & ((A[i+1][j+1]->compareTo(A[i + 1+1][j+1])) > 0) & ((A[i+1][j+1]->compareTo(A[i+1][j - 1+1])) > 0) & ((A[i+1][j+1]->compareTo(A[i+1][j + 1+1])) > 0) & ((A[i+1][j+1]->compareTo(A[i - 1+1][j - 1+1])) > 0) & ((A[i+1][j+1]->compareTo(A[i + 1+1][j + 1+1])) > 0) & ((A[i+1][j+1]->compareTo(A[i - 1+1][j + 1+1])) > 0) & ((A[i+1][j+1]->compareTo(A[i + 1+1][j - 1+1])) > 0)) then ( count := count + 1 ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt ; N=100005 d=[0]*N pre=[0]*N def Positive_Divisors(): for i in range(N): for j in range(1,int(sqrt(i))+1): if(i % j==0): if(j*j==i): d[i]+=1 else : d[i]+=2 ans=0 for i in range(2,N): if(d[i]==d[i-1]): ans+=1 pre[i]=ans if __name__=="__main__" : Positive_Divisors() n=15 print(pre[n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; ; var N : int := 100005 ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var pre : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; skip ; if __name__ = "__main__" then ( Positive_Divisors() ; var n : int := 15 ; execute (pre[n+1])->display() ) else skip; operation Positive_Divisors() pre: true post: true activity: for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(1, ("" + ((sqrt(i))))->toInteger() + 1-1) do ( if (i mod j = 0) then ( if (j * j = i) then ( d[i+1] := d[i+1] + 1 ) else ( d[i+1] := d[i+1] + 2 ) ) else skip)) ; var ans : int := 0 ; for i : Integer.subrange(2, N-1) do ( if (d[i+1] = d[i - 1+1]) then ( ans := ans + 1 ) else skip ; pre[i+1] := ans); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[] for i in range(n): l.append(int(input())) ans=n-1 last=0 for i in l : ans+=abs(last-i)+1 last=i print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : l)) ; var ans : double := n - 1 ; var last : int := 0 ; for i : l do ( ans := ans + (last - i)->abs() + 1 ; last := i) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) s=[input()for i in range(n)] a=[0]*m num=1 def alloc(x): global num x=int(x.split()[1]) for i in range(m-x+1): if a[i : i+x]==[0]*x : a[i : i+x]=[num]*x print(num) num+=1 return print('NULL') def erase(x): x=int(x.split()[1]) if x not in a or x<1 : print('ILLEGAL_ERASE_ARGUMENT') for i,j in enumerate(a): if j==x : a[i]=0 def defragment(x): global a a=[i for i in a if i!=0] a+=[0]*(m-len(a)) f={'alloc' : alloc,'erase' : erase,'defragment' : defragment} for i in s : f[i.split()[0]](i) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute num : OclAny; attribute a : OclAny; operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; var num : int := 1 ; skip ; skip ; skip ; var f : Map := Map{ 'alloc' |-> alloc }->union(Map{ 'erase' |-> erase }->union(Map{ 'defragment' |-> defragment })) ; for i : s do ((expr (atom (name f)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)) (trailer . (name split) (arguments ( ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))); operation alloc(x : OclAny) pre: true post: true activity: skip ; x := ("" + ((x.split()[1+1])))->toInteger() ; for i : Integer.subrange(0, m - x + 1-1) do ( if a.subrange(i+1, i + x) = MatrixLib.elementwiseMult(Sequence{ 0 }, x) then ( a.subrange(i+1, i + x) := MatrixLib.elementwiseMult(Sequence{ num }, x) ; execute (num)->display() ; num := num + 1 ; return ) else skip) ; execute ('NULL')->display(); operation erase(x : OclAny) pre: true post: true activity: x := ("" + ((x.split()[1+1])))->toInteger() ; if (a)->excludes(x) or x < 1 then ( execute ('ILLEGAL_ERASE_ARGUMENT')->display() ) else skip ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if j = x then ( a[i+1] := 0 ) else skip); operation defragment(x : OclAny) pre: true post: true activity: skip ; a := a->select(i | i /= 0)->collect(i | (i)) ; a := a + MatrixLib.elementwiseMult(Sequence{ 0 }, (m - (a)->size())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q,m=map(int,input().split()) idx=1 p={} t=[[m,m]] for _ in range(q): op=input().split() if op[0]=='alloc' : n=int(op[1]) flag=False x=0 for i in range(len(t)): if x+n<=t[i][0]: t.insert(i,[x,x+n]) for key in p.keys(): if p[key]>=i : p[key]+=1 print(idx) p[idx]=i idx+=1 flag=True break x=t[i][1] if not flag : print("NULL") elif op[0]=="erase" : n=int(op[1]) if n not in p : print("ILLEGAL_ERASE_ARGUMENT") else : for key in p.keys(): if p[key]>p[n]: p[key]-=1 t.pop(p[n]) del p[n] else : x=0 for i in range(len(t)-1): t[i]=[x,x+t[i][1]-t[i][0]] x=t[i][1] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : OclAny := null; var m : OclAny := null; Sequence{q,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var idx : int := 1 ; var p : OclAny := Set{} ; var t : Sequence := Sequence{ Sequence{m}->union(Sequence{ m }) } ; for _anon : Integer.subrange(0, q-1) do ( var op : OclAny := input().split() ; if op->first() = 'alloc' then ( var n : int := ("" + ((op[1+1])))->toInteger() ; var flag : boolean := false ; var x : int := 0 ; for i : Integer.subrange(0, (t)->size()-1) do ( if (x + n->compareTo(t[i+1]->first())) <= 0 then ( t := t.insertAt(i+1, Sequence{x}->union(Sequence{ x + n })) ; for key : p.keys() do ( if (p[key+1]->compareTo(i)) >= 0 then ( p[key+1] := p[key+1] + 1 ) else skip) ; execute (idx)->display() ; p[idx+1] := i ; idx := idx + 1 ; flag := true ; break ) else skip ; x := t[i+1][1+1]) ; if not(flag) then ( execute ("NULL")->display() ) else skip ) else (if op->first() = "erase" then ( n := ("" + ((op[1+1])))->toInteger() ; if (p)->excludes(n) then ( execute ("ILLEGAL_ERASE_ARGUMENT")->display() ) else ( for key : p.keys() do ( if (p[key+1]->compareTo(p[n+1])) > 0 then ( p[key+1] := p[key+1] - 1 ) else skip) ; t := t->excludingAt(p[n+1]+1) ; execute (p[n+1])->isDeleted() ) ) else ( x := 0 ; for i : Integer.subrange(0, (t)->size() - 1-1) do ( t[i+1] := Sequence{x}->union(Sequence{ x + t[i+1][1+1] - t[i+1]->first() }) ; x := t[i+1][1+1]) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t,m=map(int,input().split()) alocuente=[0]*m ind=1 for i in range(t): op=input().split() if op[0]=='alloc' : pos=0 for j in range(m): if alocuente[j]==0 : pos+=1 if pos==int(op[1]): alocuente[j-int(op[1])+1 : j+1]=[ind]*int(op[1]) print(ind) ind+=1 break else : pos=0 else : print("NULL") if op[0]=='erase' : pos=0 if int(op[1])not in alocuente or int(op[1])==0 : print('ILLEGAL_ERASE_ARGUMENT') else : for j in range(m): if int(op[1])>0 and alocuente[j]==int(op[1]): alocuente[j]=0 if op[0]=="defragment" : cnt=0 cnt=alocuente.count(0) alocuente=[j for j in alocuente if j!=0] for j in range(cnt): alocuente.append(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := null; var m : OclAny := null; Sequence{t,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var alocuente : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; var ind : int := 1 ; for i : Integer.subrange(0, t-1) do ( var op : OclAny := input().split() ; if op->first() = 'alloc' then ( var pos : int := 0 ; (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name m)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name alocuente)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name pos)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name pos)))) == (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name op)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name alocuente)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name j))) - (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name op)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ))))) + (expr (atom (number (integer 1)))))))) : (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 1)))))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name ind))))))) ])) * (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name op)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ind)))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ind)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name pos)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NULL"))))))) ))))))))))))))) ) else skip ; if op->first() = 'erase' then ( pos := 0 ; if (alocuente)->excludes(("" + ((op[1+1])))->toInteger()) or ("" + ((op[1+1])))->toInteger() = 0 then ( execute ('ILLEGAL_ERASE_ARGUMENT')->display() ) else ( for j : Integer.subrange(0, m-1) do ( if ("" + ((op[1+1])))->toInteger() > 0 & alocuente[j+1] = ("" + ((op[1+1])))->toInteger() then ( alocuente[j+1] := 0 ) else skip) ) ) else skip ; if op->first() = "defragment" then ( var cnt : int := 0 ; cnt := alocuente->count(0) ; alocuente := alocuente->select(j | j /= 0)->collect(j | (j)) ; for j : Integer.subrange(0, cnt-1) do ( execute ((0) : alocuente)) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=[input()for i in range(n)] M=[0]*m I=1 def alloc(x): global I x=int(x.split()[1]) for i in range(m-x+1): if M[i : i+x]==[0]*x : M[i : i+x]=[I]*x print(I) I+=1 return() print('NULL') def erase(x): global M x=int(x.split()[1]) if x<1 or x not in M : print("ILLEGAL_ERASE_ARGUMENT") for i in range(m): if M[i]==x : M[i]=0 def defragment(x): global M M=[i for i in M if i!=0] M+=[0]*(m-len(M)) f={'alloc' : alloc,'erase' : erase,'defragment' : defragment} for i in a : f[i.split()[0]](i) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute I : OclAny; attribute M : OclAny; attribute M : OclAny; operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var M : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; var I : int := 1 ; skip ; skip ; skip ; var f : Map := Map{ 'alloc' |-> alloc }->union(Map{ 'erase' |-> erase }->union(Map{ 'defragment' |-> defragment })) ; for i : a do ((expr (atom (name f)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)) (trailer . (name split) (arguments ( ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))); operation alloc(x : OclAny) : OclAny pre: true post: true activity: skip ; x := ("" + ((x.split()[1+1])))->toInteger() ; for i : Integer.subrange(0, m - x + 1-1) do ( if M.subrange(i+1, i + x) = MatrixLib.elementwiseMult(Sequence{ 0 }, x) then ( M.subrange(i+1, i + x) := MatrixLib.elementwiseMult(Sequence{ I }, x) ; execute (I)->display() ; I := I + 1 ; return () ) else skip) ; execute ('NULL')->display(); operation erase(x : OclAny) pre: true post: true activity: skip ; x := ("" + ((x.split()[1+1])))->toInteger() ; if x < 1 or (M)->excludes(x) then ( execute ("ILLEGAL_ERASE_ARGUMENT")->display() ) else skip ; for i : Integer.subrange(0, m-1) do ( if M[i+1] = x then ( M[i+1] := 0 ) else skip); operation defragment(x : OclAny) pre: true post: true activity: skip ; M := M->select(i | i /= 0)->collect(i | (i)) ; M := M + MatrixLib.elementwiseMult(Sequence{ 0 }, (m - (M)->size())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() m=input() nCount=[0]*26 mCount=[0]*26 for c in n : nCount[ord(c)-ord('a')]+=1 for c in m : mCount[ord(c)-ord('a')]+=1 area=0 for i in range(26): if mCount[i]!=0 and nCount[i]==0 : print(-1) exit() area+=min(mCount[i],nCount[i]) print(area) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var m : String := (OclFile["System.in"]).readLine() ; var nCount : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; var mCount : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for c : n->characters() do ( nCount[(c)->char2byte() - ('a')->char2byte()+1] := nCount[(c)->char2byte() - ('a')->char2byte()+1] + 1) ; for c : m->characters() do ( mCount[(c)->char2byte() - ('a')->char2byte()+1] := mCount[(c)->char2byte() - ('a')->char2byte()+1] + 1) ; var area : int := 0 ; for i : Integer.subrange(0, 26-1) do ( if mCount[i+1] /= 0 & nCount[i+1] = 0 then ( execute (-1)->display() ; exit() ) else skip ; area := area + Set{mCount[i+1], nCount[i+1]}->min()) ; execute (area)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def area_of_regular_polygon(n,len): P=(len*n); A=len/(2*math.tan((180/n)*3.14159/180)) area=(P*A)/2 return area def area_of_triangle_inscribed(n,len): area=area_of_regular_polygon(n,len) triangle=area/n ins_tri=(triangle*3); return ins_tri n=6 len=10 print(round(area_of_triangle_inscribed(n,len),3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 6 ; len := 10 ; execute (MathLib.roundN(area_of_triangle_inscribed(n, len), 3))->display(); operation area_of_regular_polygon(n : OclAny, len : OclAny) : OclAny pre: true post: true activity: var P : double := (len * n); ; var A : double := len / (2 * ((180 / n) * 3.14159 / 180)->tan()) ; var area : double := (P * A) / 2 ; return area; operation area_of_triangle_inscribed(n : OclAny, len : OclAny) : OclAny pre: true post: true activity: area := area_of_regular_polygon(n, len) ; var triangle : double := area / n ; var ins_tri : double := (triangle * 3); ; return ins_tri; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=256 ; def lastNonRepeating(string,n): freq=[0]*MAX ; for i in range(n): freq[ord(string[i])]+=1 ; for i in range(n-1,-1,-1): ch=string[i]; if(freq[ord(ch)]==1): return(""+ch); return "-1" ; if __name__=="__main__" : string="GeeksForGeeks" ; n=len(string); print(lastNonRepeating(string,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 256; ; skip ; if __name__ = "__main__" then ( string := "GeeksForGeeks"; ; n := (string)->size(); ; execute (lastNonRepeating(string, n))->display(); ) else skip; operation lastNonRepeating(string : OclAny, n : OclAny) pre: true post: true activity: var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX); ; for i : Integer.subrange(0, n-1) do ( freq[(string[i+1])->char2byte()+1] := freq[(string[i+1])->char2byte()+1] + 1;) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( var ch : OclAny := string[i+1]; ; if (freq[(ch)->char2byte()+1] = 1) then ( return ("" + ch); ) else skip) ; return "-1";; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[] minx=1000000000 maxy=0 for i in range(n): x,y=map(int,input().split()) minx=min(minx,x) maxy=max(maxy,y) a.append([x,y]) for i in range(n): if a[i][0]==minx and a[i][1]==maxy : print(i+1) break else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; var minx : int := 1000000000 ; var maxy : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; minx := Set{minx, x}->min() ; maxy := Set{maxy, y}->max() ; execute ((Sequence{x}->union(Sequence{ y })) : a)) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) == (comparison (expr (atom (name minx)))))) and (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) == (comparison (expr (atom (name maxy)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[] minL=float("inf") maxR=float("-inf") for i in range(n): l,r=map(int,input().split()) a.append([l,r]) if lmaxR : maxR=r for k in range(n): if a[k][0]==minL and a[k][1]==maxR : print(k+1) exit() print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; var minL : double := ("" + (("inf")))->toReal() ; var maxR : double := ("" + (("-inf")))->toReal() ; for i : Integer.subrange(0, n-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{l}->union(Sequence{ r })) : a) ; if (l->compareTo(minL)) < 0 then ( minL := l ) else skip ; if (r->compareTo(maxR)) > 0 then ( maxR := r ) else skip) ; for k : Integer.subrange(0, n-1) do ( if a[k+1]->first() = minL & a[k+1][1+1] = maxR then ( execute (k + 1)->display() ; exit() ) else skip) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,sys,io,math from tokenize import Triple from math import* I=lambda :[*map(int,sys.stdin.readline().split())] IS=lambda : input() IN=lambda : int(input()) IF=lambda : float(input()) n=IN() id=0 l,r=map(int,input().split()) for i in range(1,n): li,ri=map(int,input().split()) if li<=l and r<=ri : id=i elif licollect( _x | (OclType["int"])->apply(_x) )) ; var IS : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var IN : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var IF : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toReal()) ; var n : OclAny := IN->apply() ; var id : int := 0 ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(1, n-1) do ( var li : OclAny := null; var ri : OclAny := null; Sequence{li,ri} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (li->compareTo(l)) <= 0 & (r->compareTo(ri)) <= 0 then ( id := i ) else (if (li->compareTo(l)) < 0 or (r->compareTo(ri)) < 0 then ( id := n ) else skip) ; var l : OclAny := Set{l, li}->min() ; var r : OclAny := Set{r, ri}->max()) ; execute (if id = n then -1 else id + 1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) s=0 ; c=0 for _ in " "*int(input()): a=int(input()); s+=abs(c-a)+2 ; c=a print(s-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : int := 0; var c : int := 0 ; for _anon : StringLib.nCopies(" ", ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); s := s + (c - a)->abs() + 2; c := a) ; execute (s - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) minv,maxv=float('inf'),0 elems=[] for _ in range(n): x,y=list(map(int,input().split(' '))) if xmaxv : maxv=y elems.append((x,y)) for i,pair in enumerate(elems): if pair[0]==minv and pair[1]==maxv : print(i+1) return print(-1) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var minv : OclAny := null; var maxv : OclAny := null; Sequence{minv,maxv} := Sequence{("" + (('inf')))->toReal(),0} ; var elems : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; if (x->compareTo(minv)) < 0 then ( var minv : OclAny := x ) else skip ; if (y->compareTo(maxv)) > 0 then ( var maxv : OclAny := y ) else skip ; execute ((Sequence{x, y}) : elems)) ; for _tuple : Integer.subrange(1, (elems)->size())->collect( _indx | Sequence{_indx-1, (elems)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var pair : OclAny := _tuple->at(_indx); if pair->first() = minv & pair[1+1] = maxv then ( execute (i + 1)->display() ; return ) else skip) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) i=1 left=[] right=[] while True : if i>n : break l,r=map(int,input().split()) left.append(l) right.append(r) i+=1 a=min(left) b=max(right) for j in range(0,n): if left[j]==a and right[j]==b : print(j+1) break if j==n-1 : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 1 ; var left : Sequence := Sequence{} ; var right : Sequence := Sequence{} ; while true do ( if (i->compareTo(n)) > 0 then ( break ) else skip ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((l) : left) ; execute ((r) : right) ; i := i + 1) ; var a : OclAny := (left)->min() ; var b : OclAny := (right)->max() ; for j : Integer.subrange(0, n-1) do ( if left[j+1] = a & right[j+1] = b then ( execute (j + 1)->display() ; break ) else skip ; if j = n - 1 then ( execute (-1)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def y(x): return(1/(1+x)) def BooleRule(a,b): n=4 h=((b-a)/n) sum=0 bl=(7*y(a)+32*y(a+h)+12*y(a+2*h)+32*y(a+3*h)+7*y(a+4*h))*2*h/45 sum=sum+bl return sum if __name__=='__main__' : lowlimit=0 upplimit=4 print("f(x)=",round(BooleRule(0,4),4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var lowlimit : int := 0 ; var upplimit : int := 4 ; execute ("f(x)=")->display() ) else skip; operation y(x : OclAny) : OclAny pre: true post: true activity: return (1 / (1 + x)); operation BooleRule(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var n : int := 4 ; var h : double := ((b - a) / n) ; var sum : int := 0 ; var bl : double := (7 * y(a) + 32 * y(a + h) + 12 * y(a + 2 * h) + 32 * y(a + 3 * h) + 7 * y(a + 4 * h)) * 2 * h / 45 ; sum := sum + bl ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np maxN=20 maxM=256 dp=np.zeros((maxN,maxM)); v=np.zeros((maxN,maxM)); def findLen(arr,i,curr,n,m): if(i==n): if(curr==m): return 0 ; else : return-1 ; if(v[i][curr]): return dp[i][curr]; v[i][curr]=1 ; l=findLen(arr,i+1,curr,n,m); r=findLen(arr,i+1,curr & arr[i],n,m); dp[i][curr]=l ; if(r!=-1): dp[i][curr]=max(dp[i][curr],r+1); return dp[i][curr]; if __name__=="__main__" : arr=[3,7,2,3]; n=len(arr); m=3 ; ans=findLen(arr,0,((1<<8)-1),n,m); if(ans==-1): print(0); else : print(ans); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var maxN : int := 20 ; var maxM : int := 256 ; var dp : Sequence := MatrixLib.singleValueMatrix(Sequence{maxN, maxM}, 0.0); ; var v : Sequence := MatrixLib.singleValueMatrix(Sequence{maxN, maxM}, 0.0); ; skip ; if __name__ = "__main__" then ( arr := Sequence{3}->union(Sequence{7}->union(Sequence{2}->union(Sequence{ 3 }))); ; n := (arr)->size(); ; m := 3; ; var ans : OclAny := findLen(arr, 0, ((1 * (2->pow(8))) - 1), n, m); ; if (ans = -1) then ( execute (0)->display(); ) else ( execute (ans)->display(); ) ) else skip; operation findLen(arr : OclAny, i : OclAny, curr : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: if (i = n) then ( if (curr = m) then ( return 0; ) else ( return -1; ) ) else skip ; if (v[i+1][curr+1]) then ( return dp[i+1][curr+1]; ) else skip ; v[i+1][curr+1] := 1; ; var l : OclAny := findLen(arr, i + 1, curr, n, m); ; var r : OclAny := findLen(arr, i + 1, MathLib.bitwiseAnd(curr, arr[i+1]), n, m); ; dp[i+1][curr+1] := l; ; if (r /= -1) then ( dp[i+1][curr+1] := Set{dp[i+1][curr+1], r + 1}->max(); ) else skip ; return dp[i+1][curr+1];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np maxN=20 maxM=64 dp=np.zeros((maxN,maxM)); v=np.zeros((maxN,maxM)); def findLen(arr,i,curr,n,m): if(i==n): if(curr==m): return 0 ; else : return-1 ; if(v[i][curr]): return dp[i][curr]; v[i][curr]=1 ; l=findLen(arr,i+1,curr,n,m); r=findLen(arr,i+1,curr | arr[i],n,m); dp[i][curr]=l ; if(r!=-1): dp[i][curr]=max(dp[i][curr],r+1); return dp[i][curr]; if __name__=="__main__" : arr=[3,7,2,3]; n=len(arr); m=3 ; ans=findLen(arr,0,0,n,m); if(ans==-1): print(0); else : print(ans); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var maxN : int := 20 ; var maxM : int := 64 ; var dp : Sequence := MatrixLib.singleValueMatrix(Sequence{maxN, maxM}, 0.0); ; var v : Sequence := MatrixLib.singleValueMatrix(Sequence{maxN, maxM}, 0.0); ; skip ; if __name__ = "__main__" then ( arr := Sequence{3}->union(Sequence{7}->union(Sequence{2}->union(Sequence{ 3 }))); ; n := (arr)->size(); ; m := 3; ; var ans : OclAny := findLen(arr, 0, 0, n, m); ; if (ans = -1) then ( execute (0)->display(); ) else ( execute (ans)->display(); ) ) else skip; operation findLen(arr : OclAny, i : OclAny, curr : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: if (i = n) then ( if (curr = m) then ( return 0; ) else ( return -1; ) ) else skip ; if (v[i+1][curr+1]) then ( return dp[i+1][curr+1]; ) else skip ; v[i+1][curr+1] := 1; ; var l : OclAny := findLen(arr, i + 1, curr, n, m); ; var r : OclAny := findLen(arr, i + 1, MathLib.bitwiseOr(curr, arr[i+1]), n, m); ; dp[i+1][curr+1] := l; ; if (r /= -1) then ( dp[i+1][curr+1] := Set{dp[i+1][curr+1], r + 1}->max(); ) else skip ; return dp[i+1][curr+1];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lcsOf3(X,Y,Z,m,n,o): L=[[[0 for i in range(o+1)]for j in range(n+1)]for k in range(m+1)] for i in range(m+1): for j in range(n+1): for k in range(o+1): if(i==0 or j==0 or k==0): L[i][j][k]=0 elif(X[i-1]==Y[j-1]and X[i-1]==Z[k-1]): L[i][j][k]=L[i-1][j-1][k-1]+1 else : L[i][j][k]=max(max(L[i-1][j][k],L[i][j-1][k]),L[i][j][k-1]) return L[m][n][o] X='AGGT12' Y='12TXAYB' Z='12XBA' m=len(X) n=len(Y) o=len(Z) print('Length of LCS is',lcsOf3(X,Y,Z,m,n,o)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; X := 'AGGT12' ; Y := '12TXAYB' ; Z := '12XBA' ; m := (X)->size() ; n := (Y)->size() ; o := (Z)->size() ; execute ('Length of LCS is')->display(); operation lcsOf3(X : OclAny, Y : OclAny, Z : OclAny, m : OclAny, n : OclAny, o : OclAny) : OclAny pre: true post: true activity: var L : Sequence := Integer.subrange(0, m + 1-1)->select(k | true)->collect(k | (Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, o + 1-1)->select(i | true)->collect(i | (0)))))) ; for i : Integer.subrange(0, m + 1-1) do ( for j : Integer.subrange(0, n + 1-1) do ( for k : Integer.subrange(0, o + 1-1) do ( if (i = 0 or j = 0 or k = 0) then ( L[i+1][j+1][k+1] := 0 ) else (if (X[i - 1+1] = Y[j - 1+1] & X[i - 1+1] = Z[k - 1+1]) then ( L[i+1][j+1][k+1] := L[i - 1+1][j - 1+1][k - 1+1] + 1 ) else ( L[i+1][j+1][k+1] := Set{Set{L[i - 1+1][j+1][k+1], L[i+1][j - 1+1][k+1]}->max(), L[i+1][j+1][k - 1+1]}->max() ) ) ))) ; return L[m+1][n+1][o+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : N=int(input()) if N==0 : break R=[[0 for i in range(N+1)]for i in range(N+1)] def dfs_max(cur,pre): _max=-R[cur][pre] for i in range(N+1): if R[cur][i]>0 and i!=pre : _max=max(_max,dfs_max(i,cur)+R[cur][i]) return _max total=0 for i in range(N-1): a,b,t=list(map(int,input().split())) R[a][b]=t R[b][a]=t total+=(t*2) for i in range(2,N+1): spam=[x for x in R[i]if x>0] if(len(spam)<=1): total-=(spam[0]*2) print((total-dfs_max(1,0))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var R : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (0)))) ; skip ; var total : int := 0 ; for i : Integer.subrange(0, N - 1-1) do ( var a : OclAny := null; var b : OclAny := null; var t : OclAny := null; Sequence{a,b,t} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; R[a+1][b+1] := t ; R[b+1][a+1] := t ; total := total + (t * 2)) ; for i : Integer.subrange(2, N + 1-1) do ( var spam : Sequence := R[i+1]->select(x | x > 0)->collect(x | (x)) ; if ((spam)->size() <= 1) then ( total := total - (spam->first() * 2) ) else skip) ; execute ((total - dfs_max(1, 0)))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque while 1 : N=int(input()) if N==0 : break G=[[]for i in range(N)] for i in range(N-1): a,b,t=map(int,input().split()) a-=1 ; b-=1 G[a].append((b,t)) G[b].append((a,t)) D=[-1]*N ; P=[0]*N que=deque([0]) D[0]=0 while que : v=que.popleft() c=D[v] for w,d in G[v]: if D[w]!=-1 : continue D[w]=c+d P[w]=d que.append(w) ans=0 m=0 for i in range(N): if not i or len(G[i])>1 : ans+=P[i]*2 m=max(m,D[i]) ans-=m print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while 1 do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var G : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, N - 1-1) do ( var a : OclAny := null; var b : OclAny := null; var t : OclAny := null; Sequence{a,b,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := a - 1; b := b - 1 ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name b)))))) , (test (logical_test (comparison (expr (atom (name t))))))) )))))))) )))) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name t))))))) )))))))) ))))) ; var D : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, N); var P : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var que : Sequence := (Sequence{ 0 }) ; D->first() := 0 ; while que do ( var v : OclAny := que->first() ; que := que->tail() ; var c : OclAny := D[v+1] ; for _tuple : G[v+1] do (var _indx : int := 1; var w : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); if D[w+1] /= -1 then ( continue ) else skip ; D[w+1] := c + d ; P[w+1] := d ; execute ((w) : que))) ; var ans : int := 0 ; var m : int := 0 ; for i : Integer.subrange(0, N-1) do ( if not(i) or (G[i+1])->size() > 1 then ( ans := ans + P[i+1] * 2 ; m := Set{m, D[i+1]}->max() ) else skip) ; ans := ans - m ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dfs1(v,pv): for nv,_ in adj_list[v]: if nv==pv : continue is_leaf[v]=False dfs1(nv,v) return is_leaf def dfs2(v,pv,d): dist[v]=d for nv,w in adj_list[v]: if nv==pv : continue dfs2(nv,v,d+w) return dist while True : N=int(input()) if N==0 : break a,b,t=[],[],[] adj_list=[[]for _ in range(N)] for _ in range(N-1): ai,bi,ti=map(int,input().split()) a.append(ai-1) b.append(bi-1) t.append(ti) adj_list[ai-1].append((bi-1,ti)) adj_list[bi-1].append((ai-1,ti)) is_leaf=[True]*N dist=[-1]*N dfs1(0,-1) dfs2(0,-1,0) tmp=0 for ai,bi,ti in zip(a,b,t): if(not is_leaf[ai])and(not is_leaf[bi]): tmp+=2*ti ans=tmp for i in range(N): if not is_leaf[i]: ans=min(ans,tmp-dist[i]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var a : OclAny := null; var b : OclAny := null; var t : OclAny := null; Sequence{a,b,t} := Sequence{Sequence{},Sequence{},Sequence{}} ; var adj_list : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, N - 1-1) do ( var ai : OclAny := null; var bi : OclAny := null; var ti : OclAny := null; Sequence{ai,bi,ti} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((ai - 1) : a) ; execute ((bi - 1) : b) ; execute ((ti) : t) ; (expr (atom (name adj_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name ai))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name bi))) - (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (atom (name ti))))))) )))))))) )))) ; (expr (atom (name adj_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name bi))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name ai))) - (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (atom (name ti))))))) )))))))) ))))) ; var is_leaf : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, N) ; var dist : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, N) ; dfs1(0, -1) ; dfs2(0, -1, 0) ; var tmp : int := 0 ; for _tuple : Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), b->at(_indx)} ) do (var _indx : int := 1; var ai : OclAny := _tuple->at(_indx); _indx := _indx + 1; var bi : OclAny := _tuple->at(_indx); _indx := _indx + 1; var ti : OclAny := _tuple->at(_indx); if (not(is_leaf[ai+1])) & (not(is_leaf[bi+1])) then ( tmp := tmp + 2 * ti ) else skip) ; var ans : int := tmp ; for i : Integer.subrange(0, N-1) do ( if not(is_leaf[i+1]) then ( ans := Set{ans, tmp - dist[i+1]}->min() ) else skip) ; execute (ans)->display()); operation dfs1(v : OclAny, pv : OclAny) : OclAny pre: true post: true activity: for _tuple : adj_list[v+1] do (var _indx : int := 1; var nv : OclAny := _tuple->at(_indx); _indx := _indx + 1; var _anon : OclAny := _tuple->at(_indx); if nv = pv then ( continue ) else skip ; is_leaf[v+1] := false ; dfs1(nv, v)) ; return is_leaf; operation dfs2(v : OclAny, pv : OclAny, d : OclAny) : OclAny pre: true post: true activity: dist[v+1] := d ; for _tuple : adj_list[v+1] do (var _indx : int := 1; var nv : OclAny := _tuple->at(_indx); _indx := _indx + 1; var w : OclAny := _tuple->at(_indx); if nv = pv then ( continue ) else skip ; dfs2(nv, v, d + w)) ; return dist; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break edges=[[]for _ in range(n)] for _ in range(n-1): a,b,t=map(int,input().split()) a-=1 b-=1 edges[a].append([b,t]) edges[b].append([a,t]) used=[False]*n is_leaf=[False]*n for i in range(1,n): if len(edges[i])==1 : is_leaf[i]=True def check(x): used[x]=True times=[0] max_path=0 for to,t in edges[x]: if not used[to]and not is_leaf[to]: time,path=check(to) times.append(time+t*2) max_path=max(max_path,path+t) return sum(times),max_path total_time,max_path=check(0) print(total_time-max_path) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var edges : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, n - 1-1) do ( var a : OclAny := null; var b : OclAny := null; var t : OclAny := null; Sequence{a,b,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := a - 1 ; b := b - 1 ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name b)))))) , (test (logical_test (comparison (expr (atom (name t))))))) ]))))))) )))) ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name t))))))) ]))))))) ))))) ; var used : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ; var is_leaf : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ; for i : Integer.subrange(1, n-1) do ( if (edges[i+1])->size() = 1 then ( is_leaf[i+1] := true ) else skip) ; skip ; var total_time : OclAny := null; Sequence{total_time,max_path} := check(0) ; execute (total_time - max_path)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lst=[] for i in range(0,n): ele=int(input()) lst.append(ele) c=0 j=0 i=0 while i in range(0,n): if i==0 : c=c+lst[i] c=c+1 elif i>0 : if lst[i]>lst[i-1]: j=j+1 c=(lst[i]-lst[i-1])+c c=c+1 elif lst[i]toInteger() ; var lst : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var ele : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((ele) : lst)) ; var c : int := 0 ; var j : int := 0 ; var i : int := 0 ; while (Integer.subrange(0, n-1))->includes(i) do ( if i = 0 then ( c := c + lst[i+1] ; c := c + 1 ) else (if i > 0 then ( if (lst[i+1]->compareTo(lst[i - 1+1])) > 0 then ( j := j + 1 ; c := (lst[i+1] - lst[i - 1+1]) + c ; c := c + 1 ) else (if (lst[i+1]->compareTo(lst[i - 1+1])) < 0 then ( j := j + 1 ; c := (lst[i - 1+1] - lst[i+1]) + c ; c := c + 1 ) else (if lst[i+1] = lst[i - 1+1] then ( j := j + 1 ; c := c + 1 ) else skip ) ) ) else skip) ; i := i + 1) ; execute (c + j)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) def aaa(n): if int(n)>N : return 0 ans=1 if set(str(int(n)))=={'7','5','3'}else 0 for i in '753' : ans+=aaa(n+i) return ans print(aaa('0')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; execute (aaa('0'))->display(); operation aaa(n : OclAny) : OclAny pre: true post: true activity: if (("" + ((n)))->toInteger()->compareTo(N)) > 0 then ( return 0 ) else skip ; var ans : int := if Set{}->union((("" + ((("" + ((n)))->toInteger()))))) = Set{'7'}->union(Set{'5'}->union(Set{ '3' })) then 1 else 0 endif ; for i : '753'->characters() do ( ans := ans + aaa(n + i)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from io import StringIO import unittest def recursive(base,pattern,n): for i in["7","5","3"]: new_target="".join(base+str(i)) if int(new_target)>n : continue if new_target.count("7")>=1 and new_target.count("5")>=1 and new_target.count("3")>=1 : pattern.append(new_target) recursive(new_target,pattern,n) def resolve(): n=int(input()) pattern=[] for i in["7","5","3"]: recursive(i,pattern,n) print(len(pattern)) class TestClass(unittest.TestCase): def assertIO(self,input,output): stdout,stdin=sys.stdout,sys.stdin sys.stdout,sys.stdin=StringIO(),StringIO(input) resolve() sys.stdout.seek(0) out=sys.stdout.read()[:-1] sys.stdout,sys.stdin=stdout,stdin self.assertEqual(out,output) def test_入力例_1(self): input="""575""" output="""4""" self.assertIO(input,output) def test_入力例_2(self): input="""3600""" output="""13""" self.assertIO(input,output) def test_入力例_3(self): input="""999999999""" output="""26484""" self.assertIO(input,output) if __name__=="__main__" : resolve() ------------------------------------------------------------ OCL File: --------- class TestClass extends unittest.TestCase { static operation newTestClass() : TestClass pre: true post: TestClass->exists( _x | result = _x ); operation assertIO(input : OclAny,output : OclAny) pre: true post: true activity: var stdout : OclAny := null; var stdin : OclAny := null; Sequence{stdout,stdin} := Sequence{OclFile["System.out"],OclFile["System.in"]} ; var OclFile["System.out"] : OclAny := null; var OclFile["System.in"] : OclAny := null; Sequence{OclFile["System.out"],OclFile["System.in"]} := Sequence{StringIO(),StringIO(input)} ; resolve() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name seek) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))) ; var out : OclAny := sys.stdout.readAll()->front() ; var OclFile["System.out"] : OclAny := null; var OclFile["System.in"] : OclAny := null; Sequence{OclFile["System.out"],OclFile["System.in"]} := Sequence{stdout,stdin} ; self.assertEqual(out, output); operation test_??? operation test_??? skip(self : OclAny) pre: true post: true activity: input := (atom "" "575" "") ; output := (atom "" "4" "") ; self.assertIO(input, output); () pre: true post: true activity: input := (atom "" "575" "") ; output := (atom "" "4" "") ; self.assertIO(input, output); operation test_???self : OclAny() pre: true post: true activity: input := (atom "" "3600" "") ; output := (atom "" "13" "") ; self.assertIO(input, output); operation test_??? input := (atom "" "999999999" "") ; output := (atom "" "26484" "") ; self.assertIO(input, output)() pre: true post: true activity: input := (atom "" "999999999" "") ; output := (atom "" "26484" "") ; self.assertIO(input, output); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( resolve() ) else skip; operation recursive(base : OclAny, pattern : OclAny, n : OclAny) pre: true post: true activity: for i : Sequence{"7"}->union(Sequence{"5"}->union(Sequence{ "3" })) do ( var new_target : String := StringLib.sumStringsWithSeparator((base + ("" + ((i)))), "") ; if (("" + ((new_target)))->toInteger()->compareTo(n)) > 0 then ( continue ) else skip ; if new_target->count("7") >= 1 & new_target->count("5") >= 1 & new_target->count("3") >= 1 then ( execute ((new_target) : pattern) ) else skip ; recursive(new_target, pattern, n)); operation resolve() pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; pattern := Sequence{} ; for i : Sequence{"7"}->union(Sequence{"5"}->union(Sequence{ "3" })) do ( recursive(i, pattern, n)) ; execute ((pattern)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import collections import itertools def getint(): return int(input()) def getints(): return list(map(int,input().split())) def getint2d(rows): return[getints()for _ in range(rows)] def getgrid(rows): return[input()for _ in range(rows)] def array1d(n,value): return[value for _ in range(n)] def array2d(n,m,value): return[array1d(m,value)for _ in range(n)] n=list(map(lambda c : ord(c)-ord('0'),input())) def solve(pos,leading_zero,is_small,i3,i5,i7): if pos==len(n): if i3 and i5 and i7 : return 1 return 0 res=0 for d in[0,3,5,7]: if leading_zero==False and d==0 : continue if not is_small and d>n[pos]: continue new_is_small=True if d==n[pos]and not is_small : new_is_small=False new_leading_zero=False if leading_zero and d==0 : new_leading_zero=True res+=solve(pos+1,new_leading_zero,new_is_small,i3 or(d==3),i5 or(d==5),i7 or(d==7)) return res print(solve(0,True,False,False,False,False)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; n := (((OclFile["System.in"]).readLine())->collect( _x | (lambda c : OclAny in ((c)->char2byte() - ('0')->char2byte()))->apply(_x) )) ; skip ; execute (solve(0, true, false, false, false, false))->display(); operation getint() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation getints() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation getint2d(rows : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows-1)->select(_anon | true)->collect(_anon | (getints())); operation getgrid(rows : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())); operation array1d(n : OclAny, value : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (value)); operation array2d(n : OclAny, m : OclAny, value : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (array1d(m, value))); operation solve(pos : OclAny, leading_zero : OclAny, is_small : OclAny, i3 : OclAny, i5 : OclAny, i7 : OclAny) : OclAny pre: true post: true activity: if pos = (n)->size() then ( if i3 & i5 & i7 then ( return 1 ) else skip ; return 0 ) else skip ; var res : int := 0 ; for d : Sequence{0}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 7 }))) do ( if leading_zero = false & d = 0 then ( continue ) else skip ; if not(is_small) & (d->compareTo(n[pos+1])) > 0 then ( continue ) else skip ; var new_is_small : boolean := true ; if d = n[pos+1] & not(is_small) then ( new_is_small := false ) else skip ; var new_leading_zero : boolean := false ; if leading_zero & d = 0 then ( new_leading_zero := true ) else skip ; res := res + solve(pos + 1, new_leading_zero, new_is_small, i3 or (d = 3), i5 or (d = 5), i7 or (d = 7))) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import product n=input() m=[] for i in range(3,len(n)+1): m+=[int(''.join(j))for j in product(['3','5','7'],repeat=i)if len(set(j))==3] ans=0 for i in m : if i<=int(n): ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : String := (OclFile["System.in"]).readLine() ; var m : Sequence := Sequence{} ; for i : Integer.subrange(3, (n)->size() + 1-1) do ( m := m + product(Sequence{'3'}->union(Sequence{'5'}->union(Sequence{ '7' })), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (name i))))))))->select(j | (Set{}->union((j)))->size() = 3)->collect(j | (("" + ((StringLib.sumStringsWithSeparator((j), ''))))->toInteger()))) ; var ans : int := 0 ; for i : m do ( if (i->compareTo(("" + ((n)))->toInteger())) <= 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(100000) cnt=0 num="" X=int(input()) def dfs(num,is3,is5,is7): global cnt if is3 and is5 and is7 : cnt+=1 N="357" for n in N : next_v=num+n if int(num+n)>X : continue dfs(next_v,is3 or n=="3",is5 or n=="5",is7 or n=="7") dfs("0",0,0,0) print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute cnt : OclAny; operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(100000) ; var cnt : int := 0 ; var num : String := "" ; var X : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; dfs("0", 0, 0, 0) ; execute (cnt)->display(); operation dfs(num : OclAny, is3 : OclAny, is5 : OclAny, is7 : OclAny) pre: true post: true activity: skip ; if is3 & is5 & is7 then ( cnt := cnt + 1 ) else skip ; var N : String := "357" ; for n : N->characters() do ( var next_v : String := num + n ; if (("" + ((num + n)))->toInteger()->compareTo(X)) > 0 then ( continue ) else skip ; dfs(next_v, is3 or n = "3", is5 or n = "5", is7 or n = "7")); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=str(input()) S=S.replace("BC","D") A_count=0 ans=0 for i in range(len(S)): if S[i]=='A' : A_count+=1 elif S[i]=='D' : ans+=A_count else : A_count=0 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := ("" + (((OclFile["System.in"]).readLine()))) ; S := S.replace("BC", "D") ; var A_count : int := 0 ; var ans : int := 0 ; for i : Integer.subrange(0, (S)->size()-1) do ( if S[i+1] = 'A' then ( A_count := A_count + 1 ) else (if S[i+1] = 'D' then ( ans := ans + A_count ) else ( A_count := 0 ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split(' '))) b=list(map(int,input().split(' '))) print(('No','Yes')[sum(a)>=sum(b)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; execute (Sequence{'No', 'Yes'}->select(((a)->sum()->compareTo((b)->sum())) >= 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) r=[*map(int,input().split())] ans=abs(r[0]) for i in range(1,n): ans+=abs(r[i]-r[i-1]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : double := (r->first())->abs() ; for i : Integer.subrange(1, n-1) do ( ans := ans + (r[i+1] - r[i - 1+1])->abs()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,collections,heapq,itertools def gcd(a,b): a,b=max(a,b),min(a,b) while a % b>0 : a,b=b,a % b return b def solve(): s=input() t="" i=0 while imax(),Set{a, b}->min()} ; while a mod b > 0 do ( Sequence{a,b} := Sequence{b,a mod b}) ; return b; operation solve() : OclAny pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var t : String := "" ; var i : int := 0 ; while (i->compareTo((s)->size())) < 0 do ( if s[i+1] = "A" then ( t := t + "A" ; i := i + 1 ) else (if s[i+1] = "B" then ( if (i->compareTo((s)->size() - 1)) < 0 then ( if s[i + 1+1] = "C" then ( t := t + "D" ; i := i + 2 ) else ( t := t + "X" ; i := i + 1 ) ) else ( t := t + "X" ; i := i + 1 ) ) else ( t := t + "X" ; i := i + 1 ) ) ) ; var total : int := 0 ; var numA : int := 0 ; for i : Integer.subrange(0, (t)->size()-1) do ( if t[i+1] = "X" then ( numA := 0 ) else ( if t[i+1] = "A" then ( numA := numA + 1 ) else ( total := total + numA ) )) ; execute (total)->display() ; var INF : double := (10)->pow(25) ; var mod : int := 7 + (10)->pow(9) ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() A=[[]for i in range(len(S)+1)] ans=0 j=0 b=False for i in range(len(S)): if b==True and S[i]=="A" : j+=1 A[j].append(0) b=False elif S[i]=="A" : A[j].append(0) b=False elif b==False and S[i]=="B" : b=True elif b==True and S[i]=="C" : A[j].append(1) b=False else : b=False j+=1 for i in range(j+1): li=A[i] length=0 n=0 for k in range(len(li)): length+=k*li[k] n+=li[k] length-=n*(n-1)//2 ans+=length print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var A : Sequence := Integer.subrange(0, (S)->size() + 1-1)->select(i | true)->collect(i | (Sequence{})) ; var ans : int := 0 ; var j : int := 0 ; var b : boolean := false ; for i : Integer.subrange(0, (S)->size()-1) do ( if b = true & S[i+1] = "A" then ( j := j + 1 ; (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))) ; b := false ) else (if S[i+1] = "A" then ( (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))) ; b := false ) else (if b = false & S[i+1] = "B" then ( b := true ) else (if b = true & S[i+1] = "C" then ( (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))) ; b := false ) else ( b := false ; j := j + 1 ) ) ) ) ) ; for i : Integer.subrange(0, j + 1-1) do ( var li : OclAny := A[i+1] ; var length : int := 0 ; var n : int := 0 ; for k : Integer.subrange(0, (li)->size()-1) do ( length := length + k * li[k+1] ; n := n + li[k+1]) ; length := length - n * (n - 1) div 2 ; ans := ans + length) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) h=[] for i in range(n): h.append(int(input())) t=h[0]+1 for i in range(1,n): t+=abs(h[i-1]-h[i])+2 print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var h : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : h)) ; var t : OclAny := h->first() + 1 ; for i : Integer.subrange(1, n-1) do ( t := t + (h[i - 1+1] - h[i+1])->abs() + 2) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys S=input() if len(S)<2 : print(0),sys.exit() elif len(S)==3 : print(1 if S=="ABC" else 0) sys.exit() s=[S[i]for i in range(len(S))] tmp=0 abc,bca=["A","B","C"],["B","C","A"] ans=0 a,bc=0,0 i=0 while isize() < 2 then ( (0)->display() ; sys.exit() ) else (if (S)->size() = 3 then ( execute (if S = "ABC" then 1 else 0 endif)->display() ; sys.exit() ) else skip) ; var s : Sequence := Integer.subrange(0, (S)->size()-1)->select(i | true)->collect(i | (S[i+1])) ; var tmp : int := 0 ; var abc : OclAny := null; var bca : OclAny := null; Sequence{abc,bca} := Sequence{Sequence{"A"}->union(Sequence{"B"}->union(Sequence{ "C" })),Sequence{"B"}->union(Sequence{"C"}->union(Sequence{ "A" }))} ; var ans : int := 0 ; var a : OclAny := null; var bc : OclAny := null; Sequence{a,bc} := Sequence{0,0} ; var i : int := 0 ; while (i->compareTo((s)->size() - 1)) < 0 do ( if s[i+1] = "A" then ( a := a + 1 ) else (if s[i+1] = "B" & s[i + 1+1] = "C" then ( bc := bc + 1 ; i := i + 1 ; ans := ans + a ) else ( var a : OclAny := null; var bc : OclAny := null; Sequence{a,bc} := Sequence{0,0} ) ) ; i := i + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque,Counter from heapq import heappush,heappop,heapify import math import bisect import random from itertools import permutations,accumulate,combinations import sys import string from bisect import bisect_left,bisect_right from math import factorial,ceil,floor INF=float('inf') def LI(): return list(map(int,sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return sys.stdin.readline().strip() def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] def SRL(n): return[list(S())for i in range(n)] def MSRL(n): return[[int(j)for j in list(S())]for i in range(n)] mod=1000000007 s=S() ans=0 i=len(s)-1 a_cnt=0 bc_cnt=0 while i>=0 : if s[i-1 : i+1]=='BC' : i-=2 bc_cnt+=1 elif s[i]=='A' : i-=1 a_cnt+=1 ans+=bc_cnt else : a_cnt=bc_cnt=0 i-=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var INF : double := ("" + (('inf')))->toReal() ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : int := 1000000007 ; var s : OclAny := S() ; var ans : int := 0 ; var i : double := (s)->size() - 1 ; var a_cnt : int := 0 ; var bc_cnt : int := 0 ; while i >= 0 do ( if s.subrange(i - 1+1, i + 1) = 'BC' then ( i := i - 2 ; bc_cnt := bc_cnt + 1 ) else (if s[i+1] = 'A' then ( i := i - 1 ; a_cnt := a_cnt + 1 ; ans := ans + bc_cnt ) else ( a_cnt := 0; bc_cnt := 0 ; i := i - 1 ) ) ) ; execute (ans)->display(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation S() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation SRL(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | ((S()))); operation MSRL(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | ((S())->select(j | true)->collect(j | (("" + ((j)))->toInteger())))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minDiff(arr,n,k): result=+2147483647 arr.sort() for i in range(n-k+1): result=int(min(result,arr[i+k-1]-arr[i])) return result arr=[10,100,300,200,1000,20,30] n=len(arr) k=3 print(minDiff(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{10}->union(Sequence{100}->union(Sequence{300}->union(Sequence{200}->union(Sequence{1000}->union(Sequence{20}->union(Sequence{ 30 })))))) ; n := (arr)->size() ; k := 3 ; execute (minDiff(arr, n, k))->display(); operation minDiff(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var result : int := 2147483647 ; arr := arr->sort() ; for i : Integer.subrange(0, n - k + 1-1) do ( result := ("" + ((Set{result, arr[i + k - 1+1] - arr[i+1]}->min())))->toInteger()) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(100000) def load_balls(): LINE_NUM,TOTAL=0,0 balls=[] i=0 for line in sys.stdin : line=line.strip() LINE_NUM+=1 if LINE_NUM==1 : TOTAL=int(line.strip()) continue balls.append([int(i)for i in line.split(" ")]) if LINE_NUM==TOTAL+1 : break return balls class VesselClass : def __init__(self): self.tmp=[] self.left=[0] self.right=[0] def fill(self,balls : list): self.tmp=balls def DFS(self): if len(self.tmp)==0 : print("YES") elif self.left[-1]exists( _x | result = _x ); attribute tmp : Sequence := Sequence{}; attribute left : Sequence := Sequence{ 0 }; attribute right : Sequence := Sequence{ 0 }; operation initialise() : VesselClass pre: true post: true activity: self.tmp := Sequence{} ; self.left := Sequence{ 0 } ; self.right := Sequence{ 0 }; return self; operation fill(balls : Sequence(OclAny)) pre: true post: true activity: self.tmp := balls; operation DFS() pre: true post: true activity: if (self.tmp)->size() = 0 then ( execute ("YES")->display() ) else (if (self.left->last()->compareTo(self.tmp->first())) < 0 then ( (expr (atom (name self)) (trailer . (name left)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name self)) (trailer . (name tmp) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))) ; (expr (atom (name self)) (trailer . (name tmp)) (trailer . (name pop) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))) ; self.DFS() ) else (if (self.right->last()->compareTo(self.tmp->first())) < 0 then ( (expr (atom (name self)) (trailer . (name right)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name self)) (trailer . (name tmp) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))) ; (expr (atom (name self)) (trailer . (name tmp)) (trailer . (name pop) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))) ; self.DFS() ) else ( execute ("NO")->display() ) ) ) ; } class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(100000) ; skip ; skip ; var balls_list : OclAny := load_balls() ; for balls : balls_list do ( var Vessel : VesselClass := (VesselClass.newVesselClass()).initialise() ; Vessel.fill(balls) ; Vessel.DFS()); operation load_balls() : OclAny pre: true post: true activity: var LINE_NUM : OclAny := null; var TOTAL : OclAny := null; Sequence{LINE_NUM,TOTAL} := Sequence{0,0} ; var balls : Sequence := Sequence{} ; var i : int := 0 ; for line : OclFile["System.in"] do ( var line : String := line->trim() ; LINE_NUM := LINE_NUM + 1 ; if LINE_NUM = 1 then ( var TOTAL : int := ("" + ((line->trim())))->toInteger() ; continue ) else skip ; execute ((line.split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger()))) : balls) ; if LINE_NUM = TOTAL + 1 then ( break ) else skip) ; return balls; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) for i in range(N): B=C=0 yes=True a=list(map(int,input().split())) for j in range(10): if a[j]>B : B=a[j] elif a[j]>C : C=a[j] else : yes=False print("YES" if yes else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, N-1) do ( var B : OclAny := 0; var C : int := 0 ; var yes : boolean := true ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, 10-1) do ( if (a[j+1]->compareTo(B)) > 0 then ( B := a[j+1] ) else (if (a[j+1]->compareTo(C)) > 0 then ( C := a[j+1] ) else ( yes := false ) ) ) ; execute (if yes then "YES" else "NO" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dfs(datas,b,c,count): if len(datas)==count : return 1 if int(datas[count])>b : return dfs(datas,int(datas[count]),c,count+1) if int(datas[count])>c : return dfs(datas,b,int(datas[count]),count+1) return 0 def solve(): b=0 c=0 count=1 q=dfs(datas,b,c,count) if q==1 : print("YES") elif q==0 : print("NO") counter=0 line=input() if not " " in line : nums=line while True : line=input() datas=line.split(" ") q=solve() counter+=1 if int(nums)==counter : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var counter : int := 0 ; var line : String := (OclFile["System.in"]).readLine() ; if not((line)->characters()->includes(" ")) then ( var nums : String := line ) else skip ; while true do ( line := (OclFile["System.in"]).readLine() ; datas := line.split(" ") ; q := solve() ; counter := counter + 1 ; if ("" + ((nums)))->toInteger() = counter then ( break ) else skip); operation dfs(datas : OclAny, b : OclAny, c : OclAny, count : OclAny) : OclAny pre: true post: true activity: if (datas)->size() = count then ( return 1 ) else skip ; if (("" + ((datas[count+1])))->toInteger()->compareTo(b)) > 0 then ( return dfs(datas, ("" + ((datas[count+1])))->toInteger(), c, count + 1) ) else skip ; if (("" + ((datas[count+1])))->toInteger()->compareTo(c)) > 0 then ( return dfs(datas, b, ("" + ((datas[count+1])))->toInteger(), count + 1) ) else skip ; return 0; operation solve() pre: true post: true activity: b := 0 ; c := 0 ; count := 1 ; var q : OclAny := dfs(datas, b, c, count) ; if q = 1 then ( execute ("YES")->display() ) else (if q = 0 then ( execute ("NO")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) def dfs(balls,B=-1,C=-2,cp=0): if cp==len(balls): return True ball=balls[cp] if Bpow(6)) ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation dfs(balls : OclAny, B : int, C : int, cp : int) : OclAny pre: true post: true activity: if B->oclIsUndefined() then B := -1 else skip; if C->oclIsUndefined() then C := -2 else skip; if cp->oclIsUndefined() then cp := 0 else skip; if cp = (balls)->size() then ( return true ) else skip ; var ball : OclAny := balls[cp+1] ; if (B->compareTo(ball)) < 0 then ( var is_find : OclAny := dfs(balls, ball, C, cp + 1) ; if is_find then ( return true ) else skip ) else skip ; if (C->compareTo(ball)) < 0 then ( is_find := dfs(balls, B, ball, cp + 1) ; if is_find then ( return true ) else skip ) else skip ; return false; operation not_dfs(balls : OclAny) : OclAny pre: true post: true activity: Sequence{B,C} := Sequence{-2,-1} ; for ball : balls do ( if (C->compareTo(ball)) < 0 then ( C := ball ; continue ) else skip ; if (B->compareTo(ball)) < 0 then ( B := ball ; continue ) else skip ; return false) ; return true; operation main() pre: true post: true activity: var N : int := ("" + ((input()->trim())))->toInteger() ; for _anon : Integer.subrange(0, N-1) do ( balls := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; is_find := not_dfs(balls) ; if is_find then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- flag=False def dfs(a,b,c,i): if i==10 : global flag flag=True return else : if a[i]>b : dfs(a,a[i],c,i+1) else : pass if a[i]>c : dfs(a,b,a[i],i+1) else : pass if a[i]toInteger() ; for i : Integer.subrange(0, n-1) do ( a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; dfs(a, 0, 0, 0) ; if flag = true then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ; flag := false); operation dfs(a : OclAny, b : OclAny, c : OclAny, i : OclAny) pre: true post: true activity: if i = 10 then ( skip ; flag := true ; return ) else ( if (a[i+1]->compareTo(b)) > 0 then ( dfs(a, a[i+1], c, i + 1) ) else ( skip ) ; if (a[i+1]->compareTo(c)) > 0 then ( dfs(a, b, a[i+1], i + 1) ) else ( skip ) ; if (a[i+1]->compareTo(b)) < 0 & (a[i+1]->compareTo(c)) < 0 then ( return ) else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) count=abs(a[0]) for i in range(n-1): count+=abs(a[i+1]-a[i]) print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : double := (a->first())->abs() ; for i : Integer.subrange(0, n - 1-1) do ( count := count + (a[i + 1+1] - a[i+1])->abs()) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) P=[int(input())for _ in range(5)] p=min(P) g=N//p+(1 if N % p>0 else 0) print(5+g-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var P : Sequence := Integer.subrange(0, 5-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var p : OclAny := (P)->min() ; var g : int := N div p + (if N mod p > 0 then 1 else 0 endif) ; execute (5 + g - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lst=[] for i in range(int(input())): a=int(input()) lst.append(a) flag=0 flag=lst[0]+2*(len(lst))-1 if len(lst)==2 : print(flag+abs(lst[1]-lst[0])) elif len(lst)==1 : print(lst[0]+1) else : for i in range(len(lst)-1): flag=flag+abs(lst[i]-lst[i+1]) print(flag) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lst : Sequence := Sequence{} ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((a) : lst)) ; var flag : int := 0 ; flag := lst->first() + 2 * ((lst)->size()) - 1 ; if (lst)->size() = 2 then ( execute (flag + (lst[1+1] - lst->first())->abs())->display() ) else (if (lst)->size() = 1 then ( execute (lst->first() + 1)->display() ) else ( for i : Integer.subrange(0, (lst)->size() - 1-1) do ( flag := flag + (lst[i+1] - lst[i + 1+1])->abs()) ; execute (flag)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter from functools import reduce import fractions import math import statistics import sys import time sys.setrecursionlimit(10**7) INF=10**18 MOD=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def MI(): return map(int,sys.stdin.readline().split()) def II(): return int(sys.stdin.readline()) def IS(): return input() def P(x): return print(x) def C(x): return Counter(x) def GCD_LIST(numbers): return reduce(fractions.gcd,numbers) def LCM_LIST(numbers): return reduce(LCM,numbers) def LCM(m,n): return(m*n//fractions.gcd(m,n)) n,a,b,c,d,e,=II(),II(),II(),II(),II(),II() print(math.ceil(n/min(a,b,c,d,e))+4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; var INF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; (declareIfNecessary (test (logical_test (comparison (expr (atom (name e)))))) ,) Sequence{n,a,b,c,d,(testlist_star_expr (test (logical_test (comparison (expr (atom (name e)))))) ,)} := Sequence{II(),II(),II(),II(),II(),II()} ; execute ((n / Set{a, b, c, d, e}->min())->ceil() + 4)->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation IS() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation P(x : OclAny) : OclAny pre: true post: true activity: return (x)->display(); operation C(x : OclAny) : OclAny pre: true post: true activity: return Counter(x); operation GCD_LIST(numbers : OclAny) : OclAny pre: true post: true activity: return reduce(fractions.gcd, numbers); operation LCM_LIST(numbers : OclAny) : OclAny pre: true post: true activity: return reduce(LCM, numbers); operation LCM(m : OclAny, n : OclAny) : OclAny pre: true post: true activity: return (m * n div fractions.gcd(m, n)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import numpy as np from fractions import gcd import fractions import statistics import collections from functools import reduce import itertools N=int(input()) A=[int(input())for i in range(5)] print(math.ceil(N/min(A))+4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := Integer.subrange(0, 5-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; execute ((N / (A)->min())->ceil() + 4)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=int(input()) B=int(input()) C=int(input()) D=int(input()) E=int(input()) l=[A,B,C,D,E] m=min(l) mt=-(-N//m)-1 time=5+mt print(time) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var C : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var D : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var E : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{A}->union(Sequence{B}->union(Sequence{C}->union(Sequence{D}->union(Sequence{ E })))) ; var m : OclAny := (l)->min() ; var mt : double := -(-N div m) - 1 ; var time : int := 5 + mt ; execute (time)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math N=int(input()) CN=6 TC=[0]*(CN-1) for i in range(CN-1): TC[i]=int(input()) time=CN-1 min_TC=min(TC) print(4+math.ceil(N/min_TC)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var CN : int := 6 ; var TC : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (CN - 1)) ; for i : Integer.subrange(0, CN - 1-1) do ( TC[i+1] := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var time : double := CN - 1 ; var min_TC : OclAny := (TC)->min() ; execute (4 + (N / min_TC)->ceil())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) def solve(x): y=0 j=1 while ytoInteger() ; skip ; for i : Integer.subrange(0, t-1) do ( var i : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (solve(i))->display()); operation solve(x : OclAny) : OclAny pre: true post: true activity: var y : int := 0 ; var j : int := 1 ; while (y->compareTo(x)) < 0 do ( y := y + j ; if y = x then ( return (j) ) else skip ; j := j + 1) ; if y - x = 1 then ( return (j) ) else ( return (j - 1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ___t=int(input()) for t___ in range(___t): n=int(input()) k=0 ; m=1 while m*(m+1)//2toInteger() ; for t___ : Integer.subrange(0, ___t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := 0; var m : int := 1 ; while (m * (m + 1) div 2->compareTo(n)) < 0 do ( m := m + 1) ; k := m * (m + 1) div 2 - n ; if k = 1 then ( k := m + 1 ) else ( k := m ) ; execute (k)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) x=1 while(x*(x+1))//2toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := 1 ; while ((x * (x + 1)) div 2->compareTo(n)) < 0 do ( x := x + 1) ; if (x * (x + 1)) div 2 - n = 1 then ( execute (x + 1)->display() ) else ( execute (x)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): x=int(input()) k=1 ile=0 while x>0 : x-=k k+=1 ile+=1 if x==-1 : ile+=1 print(ile) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := 1 ; var ile : int := 0 ; while x > 0 do ( x := x - k ; k := k + 1 ; ile := ile + 1) ; if x = -1 then ( ile := ile + 1 ) else skip ; execute (ile)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Mean(arr,n): sm=0 for i in range(0,n): sm=sm+arr[i] return sm//n def meanAbsoluteDeviation(arr,n): absSum=0 for i in range(0,n): absSum=absSum+abs(arr[i]-Mean(arr,n)) return absSum/n arr=[10,15,15,17,18,21] n=len(arr) print(meanAbsoluteDeviation(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{10}->union(Sequence{15}->union(Sequence{15}->union(Sequence{17}->union(Sequence{18}->union(Sequence{ 21 }))))) ; n := (arr)->size() ; execute (meanAbsoluteDeviation(arr, n))->display(); operation Mean(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sm : int := 0 ; for i : Integer.subrange(0, n-1) do ( sm := sm + arr[i+1]) ; return sm div n; operation meanAbsoluteDeviation(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var absSum : int := 0 ; for i : Integer.subrange(0, n-1) do ( absSum := absSum + (arr[i+1] - Mean(arr, n))->abs()) ; return absSum / n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=list(map(int,input().split())) c=0 t=0 for i in x : c+=abs(t-i) t=i print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; var t : int := 0 ; for i : x do ( c := c + (t - i)->abs() ; t := i) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=[int(x)for x in input().split(' ')] cou=[0]*30 res=[] for bit in range(30): for x in a : if(x &(1<toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var cou : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 30) ; var res : Sequence := Sequence{} ; for bit : Integer.subrange(0, 30-1) do ( for x : a do ( if (MathLib.bitwiseAnd(x, (1 * (2->pow(bit))))) then ( cou[bit+1] := cou[bit+1] + 1 ) else skip)) ; for k : Integer.subrange(1, n + 1-1) do ( var ok : boolean := true ; for numbit : cou do ( if (numbit mod k /= 0) then ( ok := false ; break ) else skip) ; if ok then ( execute ((k) : res) ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): LIMIT=10**9 primes=eulerlib.list_primes(100) def count(primeindex,product): if primeindex==len(primes): return 1 if product<=LIMIT else 0 else : result=0 while product<=LIMIT : result+=count(primeindex+1,product) product*=primes[primeindex] return result return str(count(0,1)) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LIMIT : double := (10)->pow(9) ; var primes : OclAny := eulerlib.list_primes(100) ; skip ; return ("" + ((count(0, 1)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def maximumXOR(n,l,r): x=0 for i in range(int(math.log2(r)),-1,-1): if(n &(1<r)or(x+(1<display(); operation maximumXOR(n : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var x : int := 0 ; for i : Integer.subrange(-1 + 1, ("" + (()))->toInteger())->reverse() do ( if (MathLib.bitwiseAnd(n, (1 * (2->pow(i))))) then ( if ((x->compareTo(r)) > 0) or ((x + (1 * (2->pow(i))) - 1->compareTo(l)) < 0) then ( x := x xor (1 * (2->pow(i))) ) else skip ) else ( if ((MathLib.bitwiseXor(x, (1 * (2->pow(i)))))->compareTo(r)) <= 0 then ( x := x xor (1 * (2->pow(i))) ) else skip )) ; return MathLib.bitwiseXor(n, x); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxPrimefactorNum(N): arr=[True]*(N+5); i=3 ; while(i*i<=N): if(arr[i]): for j in range(i*i,N+1,i): arr[j]=False ; i+=2 ; prime=[]; prime.append(2); for i in range(3,N+1,2): if(arr[i]): prime.append(i); i=0 ; ans=1 ; while(ans*prime[i]<=N and idisplay();; operation maxPrimefactorNum(N : OclAny) pre: true post: true activity: var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (N + 5)); ; var i : int := 3; ; while ((i * i->compareTo(N)) <= 0) do ( if (arr[i+1]) then ( for j : Integer.subrange(i * i, N + 1-1)->select( $x | ($x - i * i) mod i = 0 ) do ( arr[j+1] := false;) ) else skip ; i := i + 2;) ; var prime : Sequence := Sequence{}; ; execute ((2) : prime); ; for i : Integer.subrange(3, N + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if (arr[i+1]) then ( execute ((i) : prime); ) else skip) ; i := 0; ; var ans : int := 1; ; while ((ans * prime[i+1]->compareTo(N)) <= 0 & (i->compareTo((prime)->size())) < 0) do ( ans := ans * prime[i+1]; ; i := i + 1;) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CountTrailingZeros(n): bit=bin(n)[2 :] bit=bit[: :-1] zero=0 ; for i in range(len(bit)): if(bit[i]=='0'): zero+=1 else : break return zero n=4 ans=CountTrailingZeros(n) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; var ans : OclAny := CountTrailingZeros(n) ; execute (ans)->display(); operation CountTrailingZeros(n : OclAny) : OclAny pre: true post: true activity: var bit : OclAny := bin(n).subrange(2+1) ; bit := bit(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var zero : int := 0; ; for i : Integer.subrange(0, (bit)->size()-1) do ( if (bit[i+1] = '0') then ( zero := zero + 1 ) else ( break )) ; return zero; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools from collections import deque sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 DR=[1,-1,0,0] DC=[0,0,1,-1] def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def main(): s=S() k=2019 tens=[1 for _ in range(len(s)+1)] for i in range(1,len(s)+1): tens[i]=tens[i-1]*10 % k mods0toi=[0 for _ in range(len(s))] cur=0 for i in range(len(s))[: :-1]: j=len(s)-i-1 mods0toi[i]=(cur+int(s[i])*tens[j])% k cur=mods0toi[i] s=collections.Counter(mods0toi) ans=0 t=s.keys() for c in t : if c==0 : ans+=s[c] ans+=(s[c])*(s[c]-1)//2 print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var mod : double := (10)->pow(9) + 7 ; var DR : Sequence := Sequence{1}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{ 0 }))) ; var DC : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ -1 }))) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; main(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation main() pre: true post: true activity: var s : OclAny := S() ; var k : int := 2019 ; var tens : Sequence := Integer.subrange(0, (s)->size() + 1-1)->select(_anon | true)->collect(_anon | (1)) ; for i : Integer.subrange(1, (s)->size() + 1-1) do ( tens[i+1] := tens[i - 1+1] * 10 mod k) ; var mods0toi : Sequence := Integer.subrange(0, (s)->size()-1)->select(_anon | true)->collect(_anon | (0)) ; var cur : int := 0 ; for i : range((s)->size())(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( var j : double := (s)->size() - i - 1 ; mods0toi[i+1] := (cur + ("" + ((s[i+1])))->toInteger() * tens[j+1]) mod k ; cur := mods0toi[i+1]) ; s := .Counter(mods0toi) ; var ans : int := 0 ; var t : OclAny := s.keys() ; for c : t do ( if c = 0 then ( ans := ans + s[c+1] ) else skip ; ans := ans + (s[c+1]) * (s[c+1] - 1) div 2) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from collections import defaultdict S=input()[:-1] cnt=defaultdict(int) cnt[0]=1 ans=0 now=0 for i in range(len(S)-1,-1,-1): now=(now+int(S[i])*pow(10,len(S)-1-i,2019))% 2019 ans+=cnt[now] cnt[now]+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var S : OclAny := input()->front() ; var cnt : OclAny := defaultdict(OclType["int"]) ; cnt->first() := 1 ; var ans : int := 0 ; var now : int := 0 ; for i : Integer.subrange(-1 + 1, (S)->size() - 1)->reverse() do ( now := (now + ("" + ((S[i+1])))->toInteger() * (10)->pow((S)->size() - 1 - i)) mod 2019 ; ans := ans + cnt[now+1] ; cnt[now+1] := cnt[now+1] + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(map(int,input())) n=len(s) l_sum=[0] for i in range(n): x=(l_sum[-1]+int(s[n-i-1])*(pow(10,i,2019)))% 2019 l_sum.append(x) l_sum.sort() ans=0 tmp=0 cnt=1 for i in range(1,len(l_sum)): if l_sum[i]==tmp : cnt+=1 else : ans+=cnt*(cnt-1)//2 cnt=1 tmp=l_sum[i] ans+=cnt*(cnt-1)//2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := (((OclFile["System.in"]).readLine())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : int := (s)->size() ; var l_sum : Sequence := Sequence{ 0 } ; for i : Integer.subrange(0, n-1) do ( var x : int := (l_sum->last() + ("" + ((s[n - i - 1+1])))->toInteger() * ((10)->pow(i))) mod 2019 ; execute ((x) : l_sum)) ; l_sum := l_sum->sort() ; var ans : int := 0 ; var tmp : int := 0 ; var cnt : int := 1 ; for i : Integer.subrange(1, (l_sum)->size()-1) do ( if l_sum[i+1] = tmp then ( cnt := cnt + 1 ) else ( ans := ans + cnt * (cnt - 1) div 2 ; cnt := 1 ; tmp := l_sum[i+1] )) ; ans := ans + cnt * (cnt - 1) div 2 ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input().strip() A=[0 for _ in range(len(S))] A[-1]=int(S[-1])% 3 for i in range(2,len(S)+1): A[-i]=(A[-i+1]+int(S[-i]))% 3 B=[0 for _ in range(len(S))] B[-1]=int(S[-1])% 673 a=1 for i in range(2,len(S)+1): a=(a*10)% 673 B[-i]=(int(S[-i])*a+B[-i+1])% 673 C={} for i in range(len(S)): a=A[i] b=B[i] if(a,b)not in C : C[(a,b)]=0 C[(a,b)]+=1 if(0,0)in C : C[(0,0)]+=1 cnt=0 for c in C : n=C[c] cnt+=(n*(n-1))//2 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : OclAny := input()->trim() ; var A : Sequence := Integer.subrange(0, (S)->size()-1)->select(_anon | true)->collect(_anon | (0)) ; A->last() := ("" + ((S->last())))->toInteger() mod 3 ; for i : Integer.subrange(2, (S)->size() + 1-1) do ( A->reverse()->at(-(-i)) := (A->reverse()->at(-(-i + 1)) + ("" + ((S->reverse()->at(-(-i)))))->toInteger()) mod 3) ; var B : Sequence := Integer.subrange(0, (S)->size()-1)->select(_anon | true)->collect(_anon | (0)) ; B->last() := ("" + ((S->last())))->toInteger() mod 673 ; var a : int := 1 ; for i : Integer.subrange(2, (S)->size() + 1-1) do ( a := (a * 10) mod 673 ; B->reverse()->at(-(-i)) := (("" + ((S->reverse()->at(-(-i)))))->toInteger() * a + B->reverse()->at(-(-i + 1))) mod 673) ; var C : OclAny := Set{} ; for i : Integer.subrange(0, (S)->size()-1) do ( a := A[i+1] ; var b : OclAny := B[i+1] ; if (C)->excludes(Sequence{a, b}) then ( C[Sequence{a, b}+1] := 0 ) else skip ; C[Sequence{a, b}+1] := C[Sequence{a, b}+1] + 1) ; if (C)->includes(Sequence{0, 0}) then ( C[Sequence{0, 0}+1] := C[Sequence{0, 0}+1] + 1 ) else skip ; var cnt : int := 0 ; for c : C do ( var n : OclAny := C[c+1] ; cnt := cnt + (n * (n - 1)) div 2) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s,l=(input(),2019) m,a,r=([1]+[0]*l,0,0) for i,e in enumerate(s[: :-1]): a+=int(e)*pow(10,i,l) r+=m[a % l] m[a % l]+=1 print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := null; var l : OclAny := null; Sequence{s,l} := Sequence{(OclFile["System.in"]).readLine(), 2019} ; var m : OclAny := null; var a : OclAny := null; var r : OclAny := null; Sequence{m,a,r} := Sequence{Sequence{ 1 }->union(MatrixLib.elementwiseMult(Sequence{ 0 }, l)), 0, 0} ; for _tuple : Integer.subrange(1, (s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->size())->collect( _indx | Sequence{_indx-1, (s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var e : OclAny := _tuple->at(_indx); a := a + ("" + ((e)))->toInteger() * (10)->pow(i) ; r := r + m[a mod l+1] ; m[a mod l+1] := m[a mod l+1] + 1) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) case_1=a+b+c case_2=a+a+b+b case_3=a+c+c+a case_4=b+c+c+b print(min(case_1,case_2,case_3,case_4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var case var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) : OclAny := a + b + c ; var case:= a + a + b + b : OclAny := a + a + b + b ; var case_3 : OclAny := a + c + c + a ; var case_4 : OclAny := b + c + c + b ; execute (Set{case(case(caseSet{case(case(case(Set{case(case(case(Set{case(case(case(Set{case(case(caseSet{case(case(case(Set{case(case(case(Set{case(case(case(Set{case(case(caseSet{case(case(case(Set{case(case(case(Set{case(case(case(Set{case(case(caseSet{case(case(case(Set{case(case(case(Set{case(case(case(Set{case(case(caseSet{case(case(case(Set{case(case(case(Set{case(case(case(Set{case(case(caseSet{case(case(case(Set{case(case(case(Set{case(case(case(Set{case(case(caseSet{case(case(case(Set{case(case(case(Set{case(case(case var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min()), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min()), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min(), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min())->display(), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min()), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min()), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min(), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min())->display(), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min()), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min()), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min(), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min())->display(), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min()), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min()), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min(), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min())->display(), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min()), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min()), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min(), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min())->display(), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min()), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min()), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min(), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min())->display(), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min()), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min()), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min(), case_2, case_3, case_4), case_2, case_3, case_4), case_2, case_3, case_4}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculateSum(n,k): res=1 MOD=1000000007 for i in range(0,k): res=(res*n)% MOD return res n=4 k=3 print(calculateSum(n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; k := 3 ; execute (calculateSum(n, k))->display(); operation calculateSum(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; var MOD : int := 1000000007 ; for i : Integer.subrange(0, k-1) do ( res := (res * n) mod MOD) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[0]*n b=list(map(int,input().split())) x=b[0]-a[0] counter=abs(x) for i in range(1,n): if x!=b[i]: counter+=abs(b[i]-x) x+=b[i]-x print(counter) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : double := b->first() - a->first() ; var counter : double := (x)->abs() ; for i : Integer.subrange(1, n-1) do ( if x /= b[i+1] then ( counter := counter + (b[i+1] - x)->abs() ; x := x + b[i+1] - x ) else skip) ; execute (counter)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline dist=tuple(map(int,input().split())) d1,d2,d3=dist result=min((d1+d2+d3),(d1+d3+d3+d1),(d2+d3+d3+d2),(d2+d2+d1+d1)) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var dist : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d1 : OclAny := null; var d2 : OclAny := null; var d3 : OclAny := null; Sequence{d1,d2,d3} := dist ; var result : OclAny := Set{(d1 + d2 + d3), (d1 + d3 + d3 + d1), (d2 + d3 + d3 + d2), (d2 + d2 + d1 + d1)}->min() ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pat_Shopping(a,b,c): a1=2*a+2*b a2=a+b+c a3=2*(min(a,b)+c) return min(min(a1,a2),a3) x,y,z=map(int,input().split(" ")) print(pat_Shopping(x,y,z)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; execute (pat_Shopping(x, y, z))->display(); operation pat_Shopping(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: var a1 : double := 2 * a + 2 * b ; var a2 : OclAny := a + b + c ; var a3 : double := 2 * (Set{a, b}->min() + c) ; return Set{Set{a1, a2}->min(), a3}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) otv=min(a,c+b) otv+=min(a+b,c) otv+=min(b,a+c) print(otv) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var otv : OclAny := Set{a, c + b}->min() ; otv := otv + Set{a + b, c}->min() ; otv := otv + Set{b, a + c}->min() ; execute (otv)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d1,d2,d3=map(int,input().split()) print(min(d1+d3+d2,2*d1+2*d3,2*d2+2*d3,2*d1+2*d2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d1 : OclAny := null; var d2 : OclAny := null; var d3 : OclAny := null; Sequence{d1,d2,d3} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{d1 + d3 + d2, 2 * d1 + 2 * d3, 2 * d2 + 2 * d3, 2 * d1 + 2 * d2}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class UnionFind : def __init__(self,size): self.data=[-1]*size def merge(self,x,y): x=self.root(x) y=self.root(y) if x==y : return False if self.data[x]exists( _x | result = _x ); attribute data : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, size); operation initialise(size : OclAny) : UnionFind pre: true post: true activity: self.data := MatrixLib.elementwiseMult(Sequence{ -1 }, size); return self; operation merge(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: x := self.root(x) ; y := self.root(y) ; if x = y then ( return false ) else skip ; if (self.data[x+1]->compareTo(self.data[y+1])) < 0 then ( Sequence{x,y} := Sequence{y,x} ) else skip ; self.data[y+1] := self.data[y+1] + self.data[x+1] ; self.data[x+1] := y ; return true; operation root(x : OclAny) : OclAny pre: true post: true activity: if self.data[x+1] < 0 then ( return x ) else skip ; self.data[x+1] := self.root(self.data[x+1]) ; return self.data[x+1]; operation size(x : OclAny) : OclAny pre: true post: true activity: return -self.data[self.root(x)+1]; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var uf : UnionFind := (UnionFind.newUnionFind()).initialise(N) ; for i : Integer.subrange(0, M-1) do ( var z : OclAny := null; Sequence{x,y,z} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; uf.merge(x - 1, y - 1)) ; var cnt : int := 0 ; for i : Integer.subrange(0, N-1) do ( if uf.root(i) = i then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) XYZ=[] for _ in range(M): x,y,z=map(int,input().split()) XYZ.append((x,y,z)) pairs=XYZ[:] known=[False]*(N) pairs=sorted(pairs) class UnionFind : def __init__(self,n): self.par=[i for i in range(n)] self.rank=[0]*n def find(self,x): if self.par[x]==x : return x else : self.par[x]=self.find(self.par[x]) return self.par[x] def is_group(self,x,y): return self.find(x)==self.find(y) def union(self,x,y): x=self.find(x) y=self.find(y) if self.rank[x]exists( _x | result = _x ); attribute par : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)); attribute rank : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); operation initialise(n : OclAny) : UnionFind pre: true post: true activity: self.par := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)) ; self.rank := MatrixLib.elementwiseMult(Sequence{ 0 }, n); return self; operation find(x : OclAny) : OclAny pre: true post: true activity: if self.par[x+1] = x then ( return x ) else ( self.par[x+1] := self->indexOf(self.par[x+1]) - 1 ; return self.par[x+1] ); operation is_group(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: return self->indexOf(x) - 1 = self->indexOf(y) - 1; operation union(x : OclAny,y : OclAny) pre: true post: true activity: x := self->indexOf(x) - 1 ; y := self->indexOf(y) - 1 ; if (self.rank[x+1]->compareTo(self.rank[y+1])) < 0 then ( self.par[x+1] := y ) else ( self.par[y+1] := x ; if self.rank[x+1] = self.rank[y+1] then ( self.rank[x+1] := self.rank[x+1] + 1 ) else skip ); } class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var XYZ : Sequence := Sequence{} ; for _anon : Integer.subrange(0, M-1) do ( var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{x, y, z}) : XYZ)) ; var pairs : Sequence := XYZ ; var known : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (N)) ; pairs := pairs->sort() ; skip ; skip ; edges := pairs->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (Sequence{x, y})) ; var parents : OclAny := create_union(edges, N + 1) ; var union : Set := Set{}->union(()) ; for p : parents do ( execute ((p) : union)) ; var union_num : double := (union)->size() - 1 ; execute (union_num)->display(); operation create_union(edges : OclAny, v_num : OclAny) : OclAny pre: true post: true activity: var u : UnionFind := (UnionFind.newUnionFind()).initialise(v_num) ; for _tuple : edges do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); u.union(x, y)) ; return Integer.subrange(0, v_num-1)->select(x | true)->collect(x | (u->indexOf(x) - 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import deque sys.setrecursionlimit(10**9) INF=10**18 def input(): return sys.stdin.readline().rstrip() def main(): N,M=map(int,input().split()) edge=[[]for _ in range(N)] for i in range(M): X,Y,Z=map(lambda x : int(x)-1,input().split()) edge[X].append(Y) edge[Y].append(X) used=[False]*N ans=0 for i in range(N): if not used[i]: ans+=1 queue=deque() queue.append(i) while queue : node=queue.popleft() used[node]=True for nextnode in edge[node]: if not used[nextnode]: queue.append(nextnode) print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := (10)->pow(18) ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation main() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var edge : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, M-1) do ( var X : OclAny := null; var Y : OclAny := null; var Z : OclAny := null; Sequence{X,Y,Z} := (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ) ; (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name X)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name Y)))))))) )))) ; (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name Y)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name X)))))))) ))))) ; var used : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, N) ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( if not(used[i+1]) then ( ans := ans + 1 ; var queue : Sequence := () ; execute ((i) : queue) ; while queue do ( var node : OclAny := queue->first() ; queue := queue->tail() ; used[node+1] := true ; for nextnode : edge[node+1] do ( if not(used[nextnode+1]) then ( execute ((nextnode) : queue) ) else skip)) ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import setrecursionlimit,exit setrecursionlimit(1000000000) from collections import Counter def main(): n,m=map(int,input().split()) par=[i for i in range(n)] size=[1]*n def root(x): if par[x]==x : return x else : par[x]=root(par[x]) return par[x] def same(x,y): return root(x)==root(y) def unite(x,y): x=root(x) y=root(y) if x==y : return par[x]=y size[y]+=size[x] for _ in range(m): x,y,z=map(int,input().split()) unite(x-1,y-1) for i in range(n): root(i) print(len(Counter(par))) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; setrecursionlimit(1000000000) ; skip ; skip ; main(); operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var par : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)) ; var size : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, n) ; skip ; skip ; skip ; for _anon : Integer.subrange(0, m-1) do ( var z : OclAny := null; Sequence{x,y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; unite(x - 1, y - 1)) ; for i : Integer.subrange(0, n-1) do ( root(i)) ; execute ((Counter(par))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class UnionFind : def __init__(self,n): self.parent,self.depth=[-1]*n,[0]*n def find(self,x): if self.parent[x]<0 : return x else : self.parent[x]=self.find(self.parent[x]) return self.parent[x] def isSame(self,x,y): return self.find(x)==self.find(y) def unite(self,x,y): if self.isSame(x,y): return x,y=self.find(x),self.find(y) if self.depth[x]>self.depth[y]: self.parent[x]+=self.parent[y] self.parent[y]=x else : self.parent[y]+=self.parent[x] self.parent[x]=y if self.depth[x]==self.depth[y]: self.depth[y]+=1 def size(self,x): return-self.parent[self.find(x)] def numTree(self): return sum([1 for p in self.parent if p<0]) N,M=map(int,input().split()) U=UnionFind(N) for i in range(M): X,Y,Z=map(int,input().split()) U.unite(X-1,Y-1) print(U.numTree()) ------------------------------------------------------------ OCL File: --------- class UnionFind { static operation newUnionFind() : UnionFind pre: true post: UnionFind->exists( _x | result = _x ); attribute (testlist_star_expr (test (logical_test (comparison (expr (atom (name self)) (trailer . (name parent)))))) , (test (logical_test (comparison (expr (atom (name self)) (trailer . (name depth))))))) : OclAny := MatrixLib.elementwiseMult(Sequence{ -1 }, n),MatrixLib.elementwiseMult(Sequence{ 0 }, n); operation initialise(n : OclAny) : UnionFind pre: true post: true activity: var self.parent : OclAny := null; var self.depth : OclAny := null; Sequence{self.parent,self.depth} := Sequence{MatrixLib.elementwiseMult(Sequence{ -1 }, n),MatrixLib.elementwiseMult(Sequence{ 0 }, n)}; return self; operation find(x : OclAny) : OclAny pre: true post: true activity: if self.parent[x+1] < 0 then ( return x ) else ( self.parent[x+1] := self->indexOf(self.parent[x+1]) - 1 ; return self.parent[x+1] ); operation isSame(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: return self->indexOf(x) - 1 = self->indexOf(y) - 1; operation unite(x : OclAny,y : OclAny) pre: true post: true activity: if self.isSame(x, y) then ( return ) else skip ; Sequence{x,y} := Sequence{self->indexOf(x) - 1,self->indexOf(y) - 1} ; if (self.depth[x+1]->compareTo(self.depth[y+1])) > 0 then ( self.parent[x+1] := self.parent[x+1] + self.parent[y+1] ; self.parent[y+1] := x ) else ( self.parent[y+1] := self.parent[y+1] + self.parent[x+1] ; self.parent[x+1] := y ; if self.depth[x+1] = self.depth[y+1] then ( self.depth[y+1] := self.depth[y+1] + 1 ) else skip ); operation size(x : OclAny) : OclAny pre: true post: true activity: return -self.parent[self->indexOf(x) - 1+1]; operation numTree() : OclAny pre: true post: true activity: return (self.parent->select(p | p < 0)->collect(p | (1)))->sum(); } class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var U : UnionFind := (UnionFind.newUnionFind()).initialise(N) ; for i : Integer.subrange(0, M-1) do ( var X : OclAny := null; var Y : OclAny := null; var Z : OclAny := null; Sequence{X,Y,Z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; U.unite(X - 1, Y - 1)) ; execute (U.numTree())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ok(last4): for i in range(4): t=list(last4) if i>=1 : t[i],t[i-1]=t[i-1],t[i] if ''.join(t).count('AGC')>=1 : return False return True def dfs(cur,last3): if last3 in memo[cur]: return memo[cur][last3] if cur==n : return 1 ret=0 for c in "ACGT" : if ok(last3+c): ret=(ret+dfs(cur+1,last3[1 :]+c))% mod memo[cur][last3]=ret return ret n=int(input()) mod=10**9+7 memo=[{}for i in range(n+1)] print(dfs(0,'TTT')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mod : double := (10)->pow(9) + 7 ; var memo : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Set{})) ; execute (dfs(0, 'TTT'))->display(); operation ok(last4 : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, 4-1) do ( var t : Sequence := (last4) ; if i >= 1 then ( var t[i+1] : OclAny := null; var t[i - 1+1] : OclAny := null; Sequence{t[i+1],t[i - 1+1]} := Sequence{t[i - 1+1],t[i+1]} ) else skip ; if ''.join(t)->count('AGC') >= 1 then ( return false ) else skip) ; return true; operation dfs(cur : OclAny, last3 : OclAny) : OclAny pre: true post: true activity: if (memo[cur+1])->includes(last3) then ( return memo[cur+1][last3+1] ) else skip ; if cur = n then ( return 1 ) else skip ; var ret : int := 0 ; for c : "ACGT"->characters() do ( if ok(last3 + c) then ( ret := (ret + dfs(cur + 1, last3->tail() + c)) mod mod ) else skip) ; memo[cur+1][last3+1] := ret ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): n=int(input()) p=list(map(int,input().split())) result=0 c=0 while cp[c+1]: result+=1 c+=1 c+=1 print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var result : int := 0 ; var c : int := 0 ; while (c->compareTo(n - 1)) < 0 do ( if (p[c+1]->compareTo(p[c + 1+1])) > 0 then ( result := result + 1 ; c := c + 1 ) else skip ; c := c + 1) ; execute (result)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) A=list(map(int,input().split())) x=abs(A[0]) y=A[0] for i in range(1,len(A)): x+=abs(A[i]-y) y=A[i] print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : double := (A->first())->abs() ; var y : OclAny := A->first() ; for i : Integer.subrange(1, (A)->size()-1) do ( x := x + (A[i+1] - y)->abs() ; y := A[i+1]) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) res=[0]*t for i in range(t): n=int(input()) list1=list(map(int,input().split())) j=1 while jtoInteger() ; var res : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, t) ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var list1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var j : int := 1 ; while (j->compareTo(n)) < 0 do ( if (list1[j+1]->compareTo(list1[j - 1+1])) < 0 then ( res[i+1] := res[i+1] + 1 ; j := j + 2 ) else ( j := j + 1 ))) ; for i : res do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) num=list(map(int,input().split())) j,ans=0,0 while j<(n-1): if num[j]>num[j+1]: ans+=1 j+=1 j+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var num : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var j : OclAny := null; var ans : OclAny := null; Sequence{j,ans} := Sequence{0,0} ; while (j->compareTo((n - 1))) < 0 do ( if (num[j+1]->compareTo(num[j + 1+1])) > 0 then ( ans := ans + 1 ; j := j + 1 ) else skip ; j := j + 1) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : n=int(input()) arr=list(map(int,input().split())) q=0 ans=0 while True : if q>=(n-1): break else : if arr[q]>arr[q+1]: ans+=1 q+=2 else : q+=1 print(ans) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : int := 0 ; var ans : int := 0 ; while true do ( if (q->compareTo((n - 1))) >= 0 then ( break ) else ( if (arr[q+1]->compareTo(arr[q + 1+1])) > 0 then ( ans := ans + 1 ; q := q + 2 ) else ( q := q + 1 ) )) ; execute (ans)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : t-=1 ans=0 n=int(input()) stack=[] a=[int(x)for x in input().split()] s=list(a) i=0 while iint(s[i+1]): i+=2 ans+=1 else : i+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( t := t - 1 ; var ans : int := 0 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var stack : Sequence := Sequence{} ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var s : Sequence := (a) ; var i : int := 0 ; while (i->compareTo((a)->size() - 1)) < 0 do ( if (("" + ((s[i+1])))->toInteger()->compareTo(("" + ((s[i + 1+1])))->toInteger())) > 0 then ( i := i + 2 ; ans := ans + 1 ) else ( i := i + 1 )) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=10**9+7 n=int(input()) c=list(map(int,input().split())) c.sort(reverse=True) b=pow(2,2*n-2,mod) a=2*b % mod ans=0 for i in range(n): ans+=c[i]*(a+i*b) ans %=mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : double := (10)->pow(9) + 7 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; c := c->sort() ; var b : double := (2)->pow(2 * n - 2) ; var a : int := 2 * b mod mod ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( ans := ans + c[i+1] * (a + i * b) ; ans := ans mod mod) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import sys if os.getenv("LOCAL"): sys.stdin=open("_in.txt","r") sys.setrecursionlimit(10**9) INF=float("inf") IINF=10**18 MOD=10**9+7 N=int(sys.stdin.buffer.readline()) C=list(map(int,sys.stdin.buffer.readline().split())) C.sort(reverse=True) def div_mod(a,b,mod): return a*pow(b,mod-2,mod)% mod def df(k): return div_mod((k+2)*pow(2,k,MOD),2,MOD) ans=0 for k in range(N): ans+=df(k)*C[k]*pow(2,N-k-1,MOD) ans %=MOD print(ans*pow(2,N,MOD)% MOD) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if os.getenv("LOCAL") then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("_in.txt")) ) else skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (("inf")))->toReal() ; var IINF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; var N : int := ("" + ((sys.stdin.buffer.readLine())))->toInteger() ; var C : Sequence := ((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; C := C->sort() ; skip ; skip ; var ans : int := 0 ; for k : Integer.subrange(0, N-1) do ( ans := ans + df(k) * C[k+1] * (2)->pow(N - k - 1) ; ans := ans mod MOD) ; execute (ans * (2)->pow(N) mod MOD)->display(); operation div_mod(a : OclAny, b : OclAny, mod : OclAny) : OclAny pre: true post: true activity: return a * (b)->pow(mod - 2) mod mod; operation df(k : OclAny) : OclAny pre: true post: true activity: return div_mod((k + 2) * (2)->pow(k), 2, MOD); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=int(1e9+7) maxN=int(2e5+100) pow=[1]*maxN cost=[] def add(x,y): return(x+y)% mod def mul(x,y): return x % mod*(y % mod)% mod def prepare(): for i in range(1,maxN): pow[i]=mul(pow[i-1],2) prepare() n=int(input()) inp=input().split() for i in range(0,n): cost.append(int(inp[i])) cost.sort() ans=0 for i in range(1,n+1): cur=mul(pow[i-1],mul(int(cost[i-1]),pow[n-i])) if itoReal() + 7)))->toInteger() ; var maxN : int := ("" + ((("2e5")->toReal() + 100)))->toInteger() ; var pow : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, maxN) ; var cost : Sequence := Sequence{} ; skip ; skip ; skip ; prepare() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var inp : OclAny := input().split() ; for i : Integer.subrange(0, n-1) do ( execute ((("" + ((inp[i+1])))->toInteger()) : cost)) ; cost := cost->sort() ; var ans : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( var cur : OclAny := mul(([i - 1+1])->pow([i - 1+1]`third), mul(("" + ((cost[i - 1+1])))->toInteger(), ([n - i+1])->pow([n - i+1]`third))) ; if (i->compareTo(n)) < 0 then ( cur := add(cur, ([i - 1+1])->pow([i - 1+1]`third) * ([n - i - 1+1])->pow([n - i - 1+1]`third) mod mod * ("" + ((cost[i - 1+1])))->toInteger() mod mod * (n - i) mod mod) ) else skip ; ans := add(ans, cur)) ; execute (mul(ans, ([n+1])->pow([n+1]`third)))->display(); operation add(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return (x + y) mod mod; operation mul(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return x mod mod * (y mod mod) mod mod; operation prepare() pre: true post: true activity: for i : Integer.subrange(1, maxN-1) do ( ([i+1])->pow([i+1]`third) := mul(([i - 1+1])->pow([i - 1+1]`third), 2)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys INF=1e9 mod=1e9+7 n=int(input()) lit=list(map(int,input().split())) lit.sort() ans=0 for i in range(n): ans=(ans+lit[i]*(n-i+1)% mod)% mod for i in range(2*(n-1)): ans=ans*2 % mod ans=int(ans) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var INF : double := ("1e9")->toReal() ; var mod : double := ("1e9")->toReal() + 7 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lit : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; lit := lit->sort() ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( ans := (ans + lit[i+1] * (n - i + 1) mod mod) mod mod) ; for i : Integer.subrange(0, 2 * (n - 1)-1) do ( ans := ans * 2 mod mod) ; ans := ("" + ((ans)))->toInteger() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,n=map(int,input().split()) flag=True if a==0 and b==0 : print(0) flag=False elif a==0 and b!=0 : print("No solution") elif b % a==0 : d=b//a if flag : x="No solution" c=abs(d) for _ in range(0,c+1): if(_**n)==d : x=_ break else : for _ in range(-c,0,+1): if(_**n)==d : x=_ break print(x) else : print("No solution") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var n : OclAny := null; Sequence{a,b,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var flag : boolean := true ; if a = 0 & b = 0 then ( execute (0)->display() ; flag := false ) else (if a = 0 & b /= 0 then ( execute ("No solution")->display() ) else (if b mod a = 0 then ( var d : int := b div a ; if flag then ( var x : String := "No solution" ; var c : double := (d)->abs() ; (compound_stmt for (exprlist (expr (atom (name _)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name c))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name _))) ** (expr (atom (name n)))))))) )))) == (comparison (expr (atom (name d))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name _)))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt for (exprlist (expr (atom (name _)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr - (expr (atom (name c)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name _))) ** (expr (atom (name n)))))))) )))) == (comparison (expr (atom (name d))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name _)))))))))))) (stmt (simple_stmt (small_stmt break)))))))))))) ; execute (x)->display() ) else skip ) else ( execute ("No solution")->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import product import sys sys.setrecursionlimit(10**9) N,MOD=int(input()),10**9+7 dp=[[0]*64 for _ in range(N+1)] strs=[""]*64 strs_d={} for i,s in enumerate(product("AGCT",repeat=3)): strs[i]="".join(s) strs_d["".join(s)]=i def check(s): assert len(s)==4 if "".join(s).count("AGC")>=1 : return False for i in range(3): s[i],s[i+1]=s[i+1],s[i] if "".join(s).count("AGC")>=1 : return False s[i],s[i+1]=s[i+1],s[i] return True dp[0]=[1]*64 for i in range(1,1+N): for j,s in enumerate(strs): for ns in "AGCT" : if check(list(s+ns)): dp[i][strs_d[s[1 :]+ns]]+=dp[i-1][j] dp[i][strs_d[s[1 :]+ns]]%=MOD if N==3 : print("61") else : print(sum(dp[N-3])% MOD) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var N : OclAny := null; var MOD : OclAny := null; Sequence{N,MOD} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),(10)->pow(9) + 7} ; var dp : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 64))) ; var strs : Sequence := MatrixLib.elementwiseMult(Sequence{ "" }, 64) ; var strs_d : OclAny := Set{} ; for _tuple : Integer.subrange(1, (product("AGCT", (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (number (integer 3))))))))))->size())->collect( _indx | Sequence{_indx-1, (product("AGCT", (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (number (integer 3))))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); strs[i+1] := StringLib.sumStringsWithSeparator((s), "") ; strs_d[StringLib.sumStringsWithSeparator((s), "")+1] := i) ; skip ; dp->first() := MatrixLib.elementwiseMult(Sequence{ 1 }, 64) ; for i : Integer.subrange(1, 1 + N-1) do ( for _tuple : Integer.subrange(1, (strs)->size())->collect( _indx | Sequence{_indx-1, (strs)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); for ns : "AGCT"->characters() do ( if check((s + ns)) then ( dp[i+1][strs_d[s->tail() + ns+1]+1] := dp[i+1][strs_d[s->tail() + ns+1]+1] + dp[i - 1+1][j+1] ; dp[i+1][strs_d[s->tail() + ns+1]+1] := dp[i+1][strs_d[s->tail() + ns+1]+1] mod MOD ) else skip))) ; if N = 3 then ( execute ("61")->display() ) else ( execute ((dp[N - 3+1])->sum() mod MOD)->display() ); operation check(s : OclAny) : OclAny pre: true post: true activity: assert (s)->size() = 4 do "assertion failed" ; if "".join(s)->count("AGC") >= 1 then ( return false ) else skip ; for i : Integer.subrange(0, 3-1) do ( var s[i+1] : OclAny := null; var s[i + 1+1] : OclAny := null; Sequence{s[i+1],s[i + 1+1]} := Sequence{s[i + 1+1],s[i+1]} ; if "".join(s)->count("AGC") >= 1 then ( return false ) else skip ; var s[i+1] : OclAny := null; var s[i + 1+1] : OclAny := null; Sequence{s[i+1],s[i + 1+1]} := Sequence{s[i + 1+1],s[i+1]}) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def power(n,r,mod=10**9+7): if r==0 : return 1 if r % 2==0 : return power(n*n % mod,r//2,mod)% mod if r % 2==1 : return n*power(n,r-1,mod)% mod N=int(input()) C=list(map(int,input().split())) C.sort() MOD=10**9+7 ans=0 for i,c in enumerate(C,1): ans=(ans+(N-i+2)*c)% MOD ans*=power(4,N-1) ans %=MOD print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var C : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; C := C->sort() ; var MOD : double := (10)->pow(9) + 7 ; var ans : int := 0 ; for _tuple : Integer.subrange(1, (C, 1)->size())->collect( _indx | Sequence{_indx-1, (C, 1)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); ans := (ans + (N - i + 2) * c) mod MOD) ; ans := ans * power(4, N - 1) ; ans := ans mod MOD ; execute (ans)->display(); operation power(n : OclAny, r : OclAny, mod : OclAny) : OclAny pre: true post: true activity: if mod->oclIsUndefined() then mod := (10)->pow(9) + 7 else skip; if r = 0 then ( return 1 ) else skip ; if r mod 2 = 0 then ( return power(n * n mod mod, r div 2, mod) mod mod ) else skip ; if r mod 2 = 1 then ( return n * power(n, r - 1, mod) mod mod ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def distinctSubstring(P,Q,K,N): S=set() for i in range(0,N): sum=0 ; s='' for j in range(i,N): pos=ord(P[j])-97 sum=sum+ord(Q[pos])-48 s+=P[j] if(sum<=K): S.add(s) else : break return len(S) P="abcde" Q="12345678912345678912345678" K=5 N=len(P) print(distinctSubstring(P,Q,K,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; P := "abcde" ; Q := "12345678912345678912345678" ; K := 5 ; N := (P)->size() ; execute (distinctSubstring(P, Q, K, N))->display(); operation distinctSubstring(P : OclAny, Q : OclAny, K : OclAny, N : OclAny) : OclAny pre: true post: true activity: var S : Set := Set{}->union(()) ; for i : Integer.subrange(0, N-1) do ( var sum : int := 0; ; var s : String := '' ; for j : Integer.subrange(i, N-1) do ( var pos : double := (P[j+1])->char2byte() - 97 ; sum := sum + (Q[pos+1])->char2byte() - 48 ; s := s + P[j+1] ; if ((sum->compareTo(K)) <= 0) then ( execute ((s) : S) ) else ( break ))) ; return (S)->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isSpiltPossible(n,a): Sum=0 c1=0 for i in range(n): Sum+=a[i] if(a[i]==1): c1+=1 if(Sum % 2): return False if((Sum//2)% 2==0): return True if(c1>0): return True else : return False n=3 a=[1,1,2] if(isSpiltPossible(n,a)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3 ; a := Sequence{1}->union(Sequence{1}->union(Sequence{ 2 })) ; if (isSpiltPossible(n, a)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); operation isSpiltPossible(n : OclAny, a : OclAny) : OclAny pre: true post: true activity: var Sum : int := 0 ; var c1 : int := 0 ; for i : Integer.subrange(0, n-1) do ( Sum := Sum + a[i+1] ; if (a[i+1] = 1) then ( c1 := c1 + 1 ) else skip) ; if (Sum mod 2) then ( return false ) else skip ; if ((Sum div 2) mod 2 = 0) then ( return true ) else skip ; if (c1 > 0) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def makeEven(arr,n): first_e_i=-1 last_e_i=-1 last_n_i=n-1 for i in range(n): if(int(arr[i])% 2==0 and int(arr[i])toInteger() mod 2 = 0 & (("" + ((arr[i+1])))->toInteger()->compareTo(("" + ((arr[last_n_i+1])))->toInteger())) < 0) then ( first_e_i := i ; break ) else skip ; if ("" + ((arr[i+1])))->toInteger() mod 2 = 0 then ( last_e_i := i ) else skip) ; if first_e_i /= -1 then ( suite ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findDivisors(n): div=[0 for i in range(n+1)] for i in range(1,n+1): for j in range(1,n+1): if j*i<=n : div[i*j]+=1 for i in range(1,n+1): print(div[i],end=" ") if __name__=="__main__" : n=10 findDivisors(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 10 ; findDivisors(n) ) else skip; operation findDivisors(n : OclAny) pre: true post: true activity: var div : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, n + 1-1) do ( if (j * i->compareTo(n)) <= 0 then ( div[i * j+1] := div[i * j+1] + 1 ) else skip)) ; for i : Integer.subrange(1, n + 1-1) do ( execute (div[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=input() numOf0=[0 for i in range(len(b)+1)] numOf1=[0 for i in range(len(b)+1)] r=0 for i in range(len(b)): numOf0[i]=numOf0[i-1]+(b[i]=='0') numOf1[i]=numOf1[i-1]+(b[i]=='1') for i in range(len(a)): r+=(numOf1[len(b)-len(a)+i]-numOf1[i-1])if a[i]=='0' else(numOf0[len(b)-len(a)+i]-numOf0[i-1]) print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var numOf0 : Sequence := Integer.subrange(0, (b)->size() + 1-1)->select(i | true)->collect(i | (0)) ; var numOf1 : Sequence := Integer.subrange(0, (b)->size() + 1-1)->select(i | true)->collect(i | (0)) ; var r : int := 0 ; for i : Integer.subrange(0, (b)->size()-1) do ( numOf0[i+1] := numOf0[i - 1+1] + (b[i+1] = '0') ; numOf1[i+1] := numOf1[i - 1+1] + (b[i+1] = '1')) ; for i : Integer.subrange(0, (a)->size()-1) do ( r := r + if a[i+1] = '0' then (numOf1[(b)->size() - (a)->size() + i+1] - numOf1[i - 1+1]) else (numOf0[(b)->size() - (a)->size() + i+1] - numOf0[i - 1+1]) endif) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import sys from io import BytesIO,IOBase from collections import Counter,defaultdict from sys import stdin,stdout import io import math import heapq import bisect import collections def ceil(a,b): return(a+b-1)//b inf=float('inf') def get(): return stdin.readline().rstrip() mod=10**5+7 def decimalToBinary(n): return bin(n).replace("0b","") def fun(a,b): ans=0 l1=[]; l2=[] s1=0 ; s2=0 for i in range(len(b)): if b[i]=="0" : s1+=1 else : s2+=1 l1.append(s1) l2.append(s2) for i in range(1,len(a)): if a[i]=="0" : ans=ans-l2[i-1] else : ans=ans-l1[i-1] return ans a=list(get()) b=list(get()) ansf=0 ansf+=b.count("1")*a.count("0") ansf+=b.count("0")*a.count("1") ansf=ansf+fun(a,b)+fun(a[: :-1],b[: :-1]) print(ansf) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; skip ; var mod : double := (10)->pow(5) + 7 ; skip ; skip ; a := (get()) ; b := (get()) ; var ansf : int := 0 ; ansf := ansf + b->count("1") * a->count("0") ; ansf := ansf + b->count("0") * a->count("1") ; ansf := ansf + fun(a, b) + fun(a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))), b(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ; execute (ansf)->display(); operation ceil(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a + b - 1) div b; operation get() : OclAny pre: true post: true activity: return stdin.readLine().rstrip(); operation decimalToBinary(n : OclAny) : OclAny pre: true post: true activity: return bin(n).replace("0b", ""); operation fun(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; var l1 : Sequence := Sequence{}; ; var l2 : Sequence := Sequence{} ; var s1 : int := 0; ; var s2 : int := 0 ; for i : Integer.subrange(0, (b)->size()-1) do ( if b[i+1] = "0" then ( s1 := s1 + 1 ) else ( s2 := s2 + 1 ) ; execute ((s1) : l1) ; execute ((s2) : l2)) ; for i : Integer.subrange(1, (a)->size()-1) do ( if a[i+1] = "0" then ( ans := ans - l2[i - 1+1] ) else ( ans := ans - l1[i - 1+1] )) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=input() a1=len(a) b1=len(b) s=[0] n=0 b='0'+b d=b1-a1 for i in range(1,b1+1): s.append(s[i-1]+int(b[i])) for i in range(1,a1+1): if a[i-1]=='0' : n+=s[d+i]-s[i-1] elif a[i-1]=='1' : n+=d+1-(s[d+i]-s[i-1]) print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var a1 : int := (a)->size() ; var b1 : int := (b)->size() ; var s : Sequence := Sequence{ 0 } ; var n : int := 0 ; b := '0' + b ; var d : double := b1 - a1 ; for i : Integer.subrange(1, b1 + 1-1) do ( execute ((s[i - 1+1] + ("" + ((b[i+1])))->toInteger()) : s)) ; for i : Integer.subrange(1, a1 + 1-1) do ( if a[i - 1+1] = '0' then ( n := n + s[d + i+1] - s[i - 1+1] ) else (if a[i - 1+1] = '1' then ( n := n + d + 1 - (s[d + i+1] - s[i - 1+1]) ) else skip)) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() y=input() len1=len(x) len2=len(y) index1=0 index2=0 sum0=0 s=[0] for i in range(len2): index1+=1 s.append(s[index1-1]+int(y[index1-1])) for j in range(len1): index2+=1 if x[j]=='0' : sum0+=s[len2-len1+index2]-s[j] else : sum0+=len2-len1+1-(s[len2-len1+index2]-s[j]) print(sum0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := (OclFile["System.in"]).readLine() ; var y : String := (OclFile["System.in"]).readLine() ; var len1 : int := (x)->size() ; var len2 : int := (y)->size() ; var index1 : int := 0 ; var index2 : int := 0 ; var sum0 : int := 0 ; var s : Sequence := Sequence{ 0 } ; for i : Integer.subrange(0, len2-1) do ( index1 := index1 + 1 ; execute ((s[index1 - 1+1] + ("" + ((y[index1 - 1+1])))->toInteger()) : s)) ; for j : Integer.subrange(0, len1-1) do ( index2 := index2 + 1 ; if x[j+1] = '0' then ( sum0 := sum0 + s[len2 - len1 + index2+1] - s[j+1] ) else ( sum0 := sum0 + len2 - len1 + 1 - (s[len2 - len1 + index2+1] - s[j+1]) )) ; execute (sum0)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() y=input() lens=len(y)-len(x)+1 l1=len(x) l2=len(y) index1=0 index2=0 sum=0 s=[0] for i in range(l2): index1+=1 s.append(s[index1-1]+int(y[index1-1])) for i in range(l1): index2+=1 if x[i]=='0' : sum+=s[len(y)-len(x)+index2]-s[i] else : sum+=lens-(s[len(y)-len(x)+index2]-s[i]) print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := (OclFile["System.in"]).readLine() ; var y : String := (OclFile["System.in"]).readLine() ; var lens : double := (y)->size() - (x)->size() + 1 ; var l1 : int := (x)->size() ; var l2 : int := (y)->size() ; var index1 : int := 0 ; var index2 : int := 0 ; var sum : int := 0 ; var s : Sequence := Sequence{ 0 } ; for i : Integer.subrange(0, l2-1) do ( index1 := index1 + 1 ; execute ((s[index1 - 1+1] + ("" + ((y[index1 - 1+1])))->toInteger()) : s)) ; for i : Integer.subrange(0, l1-1) do ( index2 := index2 + 1 ; if x[i+1] = '0' then ( sum := sum + s[(y)->size() - (x)->size() + index2+1] - s[i+1] ) else ( sum := sum + lens - (s[(y)->size() - (x)->size() + index2+1] - s[i+1]) )) ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import chain from functools import reduce N=int(input()) atgc="ATGC" labels=[] for c1 in atgc : for c2 in atgc : for c3 in atgc : labels.append(c1+c2+c3) labels[0],labels[11]=labels[11],labels[0] labels[1],labels[14]=labels[14],labels[1] labels[2],labels[35]=labels[35],labels[2] lb2i={lb : i for i,lb in enumerate(labels)} mat=[[0]*64 for i in range(64)] def swap(s,i,j): s=list(s) s[i],s[j]=s[j],s[i] return "".join(s) for i,lb1 in enumerate(labels): tmp=[(lb1+c)for c in atgc] tmp=[s for s in tmp if not any(["AGC" in swap(s,i,i+1)for i in range(3)])] for lb2 in tmp : mat[i][lb2i[lb2[1 :]]]+=1 prev=[1]*64 curr=[0]*64 mod=1000000007 for _ in range(N-3): prev[0 : 3]=[0,0,0] for j in range(64): curr[j]=0 for lbi1 in range(64): for lbi2 in range(64): curr[lbi2]+=mat[lbi1][lbi2]*prev[lbi1] curr[lbi2]%=mod curr,prev=prev,curr prev[0 : 3]=[0,0,0] print(reduce(lambda acc,x :(acc+x)% mod,prev,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var atgc : String := "ATGC" ; var labels : Sequence := Sequence{} ; for c1 : atgc->characters() do ( for c2 : atgc->characters() do ( for c3 : atgc->characters() do ( execute ((c1 + c2 + c3) : labels)))) ; var labels->first() : OclAny := null; var labels[11+1] : OclAny := null; Sequence{labels->first(),labels[11+1]} := Sequence{labels[11+1],labels->first()} ; var labels[1+1] : OclAny := null; var labels[14+1] : OclAny := null; Sequence{labels[1+1],labels[14+1]} := Sequence{labels[14+1],labels[1+1]} ; var labels[2+1] : OclAny := null; var labels[35+1] : OclAny := null; Sequence{labels[2+1],labels[35+1]} := Sequence{labels[35+1],labels[2+1]} ; var lb2i : Map := Integer.subrange(1, (labels)->size())->collect( _indx | Sequence{_indx-1, (labels)->at(_indx)} )->select(_tuple | true)->collect(_tuple | Map{lb |-> i})->unionAll() ; var mat : Sequence := Integer.subrange(0, 64-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, 64))) ; skip ; for _tuple : Integer.subrange(1, (labels)->size())->collect( _indx | Sequence{_indx-1, (labels)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var lb1 : OclAny := _tuple->at(_indx); var tmp : Sequence := atgc->characters()->select(c | true)->collect(c | ((lb1 + c))) ; tmp := tmp->select(s | not((Integer.subrange(0, 3-1)->select(i | true)->collect(i | ((swap(s, i, i + 1))->includes("AGC"))))->exists( _x | _x = true )))->collect(s | (s)) ; for lb2 : tmp do ( mat[i+1][lb2i[lb2->tail()+1]+1] := mat[i+1][lb2i[lb2->tail()+1]+1] + 1)) ; var prev : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, 64) ; var curr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 64) ; var mod : int := 1000000007 ; for _anon : Integer.subrange(0, N - 3-1) do ( prev.subrange(0+1, 3) := Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) ; for j : Integer.subrange(0, 64-1) do ( curr[j+1] := 0) ; for lbi1 : Integer.subrange(0, 64-1) do ( for lbi2 : Integer.subrange(0, 64-1) do ( curr[lbi2+1] := curr[lbi2+1] + mat[lbi1+1][lbi2+1] * prev[lbi1+1] ; curr[lbi2+1] := curr[lbi2+1] mod mod)) ; Sequence{curr,prev} := Sequence{prev,curr}) ; prev.subrange(0+1, 3) := Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) ; execute (reduce(lambda acc : OclAny, x : OclAny in ((acc + x) mod mod), prev, 0))->display(); operation swap(s : OclAny, i : OclAny, j : OclAny) : OclAny pre: true post: true activity: s := (s) ; var s[i+1] : OclAny := null; var s[j+1] : OclAny := null; Sequence{s[i+1],s[j+1]} := Sequence{s[j+1],s[i+1]} ; return StringLib.sumStringsWithSeparator((s), ""); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_CHAR=256 def printDistinct(Str): n=len(Str) count=[0 for i in range(MAX_CHAR)] index=[n for i in range(MAX_CHAR)] for i in range(n): x=ord(Str[i]) count[x]+=1 if(count[x]==1 and x!=' '): index[x]=i if(count[x]==2): index[x]=n index=sorted(index) for i in range(MAX_CHAR): if index[i]==n : break print(Str[index[i]],end="") Str="GeeksforGeeks" printDistinct(Str) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_CHAR : int := 256 ; skip ; Str := "GeeksforGeeks" ; printDistinct(Str); operation printDistinct(Str : OclAny) pre: true post: true activity: var n : int := (Str)->size() ; var count : Sequence := Integer.subrange(0, MAX_CHAR-1)->select(i | true)->collect(i | (0)) ; var index : Sequence := Integer.subrange(0, MAX_CHAR-1)->select(i | true)->collect(i | (n)) ; for i : Integer.subrange(0, n-1) do ( var x : int := (Str[i+1])->char2byte() ; count[x+1] := count[x+1] + 1 ; if (count[x+1] = 1 & x /= ' ') then ( index[x+1] := i ) else skip ; if (count[x+1] = 2) then ( index[x+1] := n ) else skip) ; index := index->sort() ; for i : Integer.subrange(0, MAX_CHAR-1) do ( if index[i+1] = n then ( break ) else skip ; execute (Str[index[i+1]+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def calculate(x,k,m): result=x ; k=k-1 ; while(k): result=math.pow(result,x); if(result>m): result=result % m ; k=k-1 ; return int(result); x=5 ; k=2 ; m=3 ; print(calculate(x,k,m)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; x := 5; ; k := 2; ; m := 3; ; execute (calculate(x, k, m))->display();; operation calculate(x : OclAny, k : OclAny, m : OclAny) pre: true post: true activity: var result : OclAny := x; ; k := k - 1; ; while (k) do ( result := (result)->pow(x); ; if ((result->compareTo(m)) > 0) then ( result := result mod m; ) else skip ; k := k - 1;) ; return ("" + ((result)))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def converthenumber(n): s=str(n); res="" ; for i in range(len(s)): if(s[i]=='1' or s[i]=='3' or s[i]=='5' or s[i]=='7' or s[i]=='9'): res+=s[i]; if(len(res)==2): break ; if(len(res)==2): print(res); else : print("-1"); if __name__=="__main__" : n=18720 ; converthenumber(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 18720; ; converthenumber(n); ) else skip; operation converthenumber(n : OclAny) pre: true post: true activity: var s : String := ("" + ((n))); ; var res : String := ""; ; for i : Integer.subrange(0, (s)->size()-1) do ( if (s[i+1] = '1' or s[i+1] = '3' or s[i+1] = '5' or s[i+1] = '7' or s[i+1] = '9') then ( res := res + s[i+1]; ) else skip ; if ((res)->size() = 2) then ( break; ) else skip) ; if ((res)->size() = 2) then ( execute (res)->display(); ) else ( execute ("-1")->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[int(i)for i in input().split()] f=[0]*4 for i in l : if i==1 : f[0]+=1 f[1]=max(f[0],f[1]) f[2]=max(f[2]+1,f[2]) f[3]=max(f[3],f[2]) else : f[1]=max(f[1]+1,f[0]) f[2]=max(f[2],f[1]) f[3]=max(f[3]+1,f[2]) print(f[3]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 4) ; for i : l do ( if i = 1 then ( f->first() := f->first() + 1 ; f[1+1] := Set{f->first(), f[1+1]}->max() ; f[2+1] := Set{f[2+1] + 1, f[2+1]}->max() ; f[3+1] := Set{f[3+1], f[2+1]}->max() ) else ( f[1+1] := Set{f[1+1] + 1, f->first()}->max() ; f[2+1] := Set{f[2+1], f[1+1]}->max() ; f[3+1] := Set{f[3+1] + 1, f[2+1]}->max() )) ; execute (f[3+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) s=input() for a in range(26): c=chr(a+ord('a')) if c not in s : print(c) return for a in range(26): c1=chr(a+ord('a')) for b in range(26): c2=chr(b+ord('a')) c=c1+c2 if c not in s : print(c) return for a in range(26): c1=chr(a+ord('a')) for b in range(26): c2=chr(b+ord('a')) c4=c1+c2 for d in range(26): c3=chr(d+ord('a')) c=c4+c3 if c not in s : print(c) return t=int(input()) while t!=0 : t-=1 solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t /= 0 do ( t := t - 1 ; solve()); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; for a : Integer.subrange(0, 26-1) do ( var c : String := (a + ('a')->char2byte())->byte2char() ; if (s)->characters()->excludes(c) then ( execute (c)->display() ; return ) else skip) ; for a : Integer.subrange(0, 26-1) do ( var c1 : String := (a + ('a')->char2byte())->byte2char() ; for b : Integer.subrange(0, 26-1) do ( var c2 : String := (b + ('a')->char2byte())->byte2char() ; c := c1 + c2 ; if (s)->characters()->excludes(c) then ( execute (c)->display() ; return ) else skip)) ; for a : Integer.subrange(0, 26-1) do ( c1 := (a + ('a')->char2byte())->byte2char() ; for b : Integer.subrange(0, 26-1) do ( c2 := (b + ('a')->char2byte())->byte2char() ; var c4 : String := c1 + c2 ; for d : Integer.subrange(0, 26-1) do ( var c3 : String := (d + ('a')->char2byte())->byte2char() ; c := c4 + c3 ; if (s)->characters()->excludes(c) then ( execute (c)->display() ; return ) else skip))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=[chr(i+ord('a'))for i in range(26)] for _ in range(int(input())): n=int(input()) s=input() ks="" i=1 flag=1 ls=[""] while flag : lst=[] for w1 in l : for w2 in ls : lst.append(w1+w2) if s.find(w1+w2)==-1 : print(w1+w2) flag=0 break if flag==0 : break ; ls=lst ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | ((i + ('a')->char2byte())->byte2char())) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var ks : String := "" ; var i : int := 1 ; var flag : int := 1 ; var ls : Sequence := Sequence{ "" } ; while flag do ( var lst : Sequence := Sequence{} ; for w1 : l do ( for w2 : ls do ( execute ((w1 + w2) : lst) ; if s->indexOf(w1 + w2) - 1 = -1 then ( execute (w1 + w2)->display() ; flag := 0 ; break ) else skip) ; if flag = 0 then ( break; ) else skip) ; ls := lst)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- b=[]; x='abcdefghijklmnopqrstuvwxyz' for i in x : b+=i, for j in x : b+=[i+j]+[i+j+k for k in x] b.sort(key=len) for s in[*open(0)][2 : : 2]: for i in b : if(i in s)<1 : print(i); break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var b : Sequence := Sequence{}; var x : String := 'abcdefghijklmnopqrstuvwxyz' ; for i : x->characters() do ( b := b + (testlist (test (logical_test (comparison (expr (atom (name i)))))) ,) ; for j : x->characters() do ( b := b + Sequence{ i + j }->union(x->characters()->select(k | true)->collect(k | (i + j + k))))) ; b := b->sort() ; for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( for i : b do ( if ((s)->includes(i)) < 1 then ( execute (i)->display(); break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()); l=list(map(int,input().split())) a=set(l) l1=[] for i in range(1,n+1): l1.append(max(i,len(a))) print(*l1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Set := Set{}->union((l)) ; var l1 : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( execute ((Set{i, (a)->size()}->max()) : l1)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name l1))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) powers=[int(x)for x in input().split()] types=set(powers) for i in range(1,n+1): print(max(i,len(types)),end="") print("") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var powers : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var types : Set := Set{}->union((powers)) ; for i : Integer.subrange(1, n + 1-1) do ( execute (Set{i, (types)->size()}->max())->display()) ; execute ("")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) res=[] for i in range(t): n=int(input()) a=list(map(int,input().split())) b=len(list(set(a))) c=n-b r=[b]*b if c!=0 : r2=list(range((b+1),(n+1))) r=r+r2 res.append(' '.join(map(str,r))) for i in range(len(res)): print(res[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : int := ((Set{}->union((a))))->size() ; var c : double := n - b ; var r : Sequence := MatrixLib.elementwiseMult(Sequence{ b }, b) ; if c /= 0 then ( var r2 : Sequence := (Integer.subrange((b + 1), (n + 1)-1)) ; r := r->union(r2) ) else skip ; execute ((StringLib.sumStringsWithSeparator(((r)->collect( _x | (OclType["String"])->apply(_x) )), ' ')) : res)) ; for i : Integer.subrange(0, (res)->size()-1) do ( execute (res[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def resolve(): N=int(input()) ng_list_3=['AGC','GAC',]ng_list_4=['AGGC','ATGC',]memo=dict() def count(s,n): if len(s)>=4 : l4=s[-4 :] if l4 in ng_list_4 : return 0 if len(s)>=3 : l3=s[-3 :] if l3 in ng_list_3 : return 0 if len(s)>=4 and(s[-4 :],n)in memo : return memo[(s[-4 :],n)] if n==0 : return 1 x=[count(s+'A',n-1),count(s+'C',n-1),count(s+'G',n-1),count(s+'T',n-1),] x=sum(x)%(10**9+7) if len(s)>=4 : memo[(s[-4 :],n)]=x return x print(count('',N)) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; resolve(); operation resolve() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ng_list_3 : Sequence := Sequence{'AGC'}->union(Sequence{ 'GAC' }) ; var ng_list_4 : Sequence := Sequence{'AGGC'}->union(Sequence{ 'ATGC' }) ; var memo : Map := (arguments ( )) ; skip ; execute (count('', N))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=set(map(int,input().split())) l=len(a) print_l=[] for i in range(n): if l>i : print_l.append(l) else : print_l.append(i+1) print(*print_l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var l : int := (a)->size() ; var print_l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if (l->compareTo(i)) > 0 then ( execute ((l) : print_l) ) else ( execute ((i + 1) : print_l) )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name print_l))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- test=int(input()) for _ in range(test): n=int(input()) el=len(set(input().split())) result=[str(max(i+1,el))for i in range(n)] print(" ".join(result)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var test : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, test-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var el : int := (Set{}->union((input().split())))->size() ; var result : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + ((Set{i + 1, el}->max()))))) ; execute (StringLib.sumStringsWithSeparator((result), " "))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import defaultdict K=int(input()) cnt=0 now=0 if K % 2==0 : print(-1) sys.exit(0) for i in range(10**6): cnt+=1 now=(now*10+7)% K if now==0 : print(cnt) sys.exit(0) print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cnt : int := 0 ; var now : int := 0 ; if K mod 2 = 0 then ( execute (-1)->display() ; sys.exit(0) ) else skip ; for i : Integer.subrange(0, (10)->pow(6)-1) do ( cnt := cnt + 1 ; now := (now * 10 + 7) mod K ; if now = 0 then ( execute (cnt)->display() ; sys.exit(0) ) else skip) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input().rstrip()) passed=set() from sys import exit cnt=1 tmp=7 while 1 : if tmp % n==0 : print(cnt) exit() elif tmp not in passed : passed.add(tmp) cnt+=1 tmp=(tmp*10+7)% n else : print(-1) exit() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + ((input().rstrip())))->toInteger() ; var passed : Set := Set{}->union(()) ; skip ; var cnt : int := 1 ; var tmp : int := 7 ; while 1 do ( if tmp mod n = 0 then ( execute (cnt)->display() ; exit() ) else (if (passed)->excludes(tmp) then ( execute ((tmp) : passed) ; cnt := cnt + 1 ; tmp := (tmp * 10 + 7) mod n ) else ( execute (-1)->display() ; exit() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=int(input()) def func(arr,m): dp=[0,0,0,0] for i,n in enumerate(arr): if n==1 : dp[0]+=1 dp[1]=max(dp[0],dp[1]) dp[2]=max(dp[1],dp[2]+1) dp[3]=max(dp[2],dp[3]) else : dp[1]=max(dp[0],dp[1]+1) dp[2]=max(dp[1],dp[2]) dp[3]=max(dp[2],dp[3]+1) print(dp[3]) func([int(i)for i in input().split()],m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; func(input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())), m); operation func(arr : OclAny, m : OclAny) pre: true post: true activity: var dp : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))) ; for _tuple : Integer.subrange(1, (arr)->size())->collect( _indx | Sequence{_indx-1, (arr)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var n : OclAny := _tuple->at(_indx); if n = 1 then ( dp->first() := dp->first() + 1 ; dp[1+1] := Set{dp->first(), dp[1+1]}->max() ; dp[2+1] := Set{dp[1+1], dp[2+1] + 1}->max() ; dp[3+1] := Set{dp[2+1], dp[3+1]}->max() ) else ( dp[1+1] := Set{dp->first(), dp[1+1] + 1}->max() ; dp[2+1] := Set{dp[1+1], dp[2+1]}->max() ; dp[3+1] := Set{dp[2+1], dp[3+1] + 1}->max() )) ; execute (dp[3+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout,setrecursionlimit from math import gcd,ceil,sqrt from collections import Counter from bisect import bisect_left,bisect_right ii1=lambda : int(stdin.readline().strip()) is1=lambda : stdin.readline().strip() iia=lambda : list(map(int,stdin.readline().strip().split())) isa=lambda : stdin.readline().strip().split() setrecursionlimit(100000) mod=1000000007 k=ii1() t=0 for i in range(1,k+1): t=(t % k)*10+7 if t % k==0 : print(i) break else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var ii1 : Function := lambda $$ : OclAny in (("" + ((stdin.readLine()->trim())))->toInteger()) ; var is1 : Function := lambda $$ : OclAny in (stdin.readLine()->trim()) ; var iia : Function := lambda $$ : OclAny in (((stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var isa : Function := lambda $$ : OclAny in (stdin.readLine()->trim().split()) ; setrecursionlimit(100000) ; var mod : int := 1000000007 ; var k : OclAny := ii1->apply() ; var t : int := 0 ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name k))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name t)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name t))) % (expr (atom (name k)))))))) ))) * (expr (atom (number (integer 10))))) + (expr (atom (number (integer 7)))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name t))) % (expr (atom (name k))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- K=int(input()) ans='-1' mod=7 % K path=[mod] for i in range(1,K+1): if mod==0 : ans=i break mod=(mod*10+7)% K path.append(mod) if mod==path[0]: ans='-1' break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : String := '-1' ; var mod : int := 7 mod K ; var path : Sequence := Sequence{ mod } ; for i : Integer.subrange(1, K + 1-1) do ( if mod = 0 then ( ans := i ; break ) else skip ; mod := (mod * 10 + 7) mod K ; execute ((mod) : path) ; if mod = path->first() then ( ans := '-1' ; break ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) if k % 2==0 or k % 5==0 : print(-1) else : num=7 ans=1 while num % k!=0 : num*=10 num+=7 ans+=1 num %=k print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if k mod 2 = 0 or k mod 5 = 0 then ( execute (-1)->display() ) else ( var num : int := 7 ; var ans : int := 1 ; while num mod k /= 0 do ( num := num * 10 ; num := num + 7 ; ans := ans + 1 ; num := num mod k) ; execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sn(n,an): return(n*(1+an))/2 ; def trace(n,m): an=1+(n-1)*(m+1); rowmajorSum=sn(n,an); an=1+(n-1)*(n+1); colmajorSum=sn(n,an); return int(rowmajorSum+colmajorSum); N=3 ; M=3 ; print(trace(N,M)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := 3; ; var M : int := 3; ; execute (trace(N, M))->display();; operation sn(n : OclAny, an : OclAny) pre: true post: true activity: return (n * (1 + an)) / 2;; operation trace(n : OclAny, m : OclAny) pre: true post: true activity: an := 1 + (n - 1) * (m + 1); ; var rowmajorSum : OclAny := sn(n, an); ; an := 1 + (n - 1) * (n + 1); ; var colmajorSum : OclAny := sn(n, an); ; return ("" + ((rowmajorSum + colmajorSum)))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w=map(int,input().split()) s=[list(input())for _ in range(h)] ans=0 ci=[0 for _ in range(w)] for i in range(h-1,-1,-1): co=0 for j in range(w-1,-1,-1): if s[i][j]=='J' : ans+=co*ci[j] elif s[i][j]=='O' : co+=1 elif s[i][j]=='I' : ci[j]+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (((OclFile["System.in"]).readLine())->characters())) ; var ans : int := 0 ; var ci : Sequence := Integer.subrange(0, w-1)->select(_anon | true)->collect(_anon | (0)) ; for i : Integer.subrange(-1 + 1, h - 1)->reverse() do ( var co : int := 0 ; for j : Integer.subrange(-1 + 1, w - 1)->reverse() do ( if s[i+1][j+1] = 'J' then ( ans := ans + co * ci[j+1] ) else (if s[i+1][j+1] = 'O' then ( co := co + 1 ) else (if s[i+1][j+1] = 'I' then ( ci[j+1] := ci[j+1] + 1 ) else skip ) ) )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys ; input=sys.stdin.buffer.readline from collections import defaultdict con=10**9+7 ; INF=float("inf") def getlist(): return list(map(int,input().split())) def main(): N=int(input()) DP=[[0]*64 for i in range(N)] for i in range(64): DP[2][i]=1 DP[2][6]=0 DP[2][9]=0 DP[2][18]=0 for p in range(2,N-1): for i in range(4): for j in range(4): for k in range(4): for s in range(4): if not((i==0 and k==1 and s==2)or(i==0 and j==1 and s==2)): DP[p+1][16*j+4*k+s]+=DP[p][16*i+4*j+k] DP[p+1][16*j+4*k+s]%=con DP[p+1][6]=0 DP[p+1][9]=0 DP[p+1][18]=0 ans=sum(DP[N-1]) print(ans % con) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; var input : OclAny := sys.stdin.buffer.readline ; skip ; var con : double := (10)->pow(9) + 7; var INF : double := ("" + (("inf")))->toReal() ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation getlist() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var DP : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, 64))) ; for i : Integer.subrange(0, 64-1) do ( DP[2+1][i+1] := 1) ; DP[2+1][6+1] := 0 ; DP[2+1][9+1] := 0 ; DP[2+1][18+1] := 0 ; for p : Integer.subrange(2, N - 1-1) do ( for i : Integer.subrange(0, 4-1) do ( for j : Integer.subrange(0, 4-1) do ( for k : Integer.subrange(0, 4-1) do ( for s : Integer.subrange(0, 4-1) do ( if not(((i = 0 & k = 1 & s = 2) or (i = 0 & j = 1 & s = 2))) then ( DP[p + 1+1][16 * j + 4 * k + s+1] := DP[p + 1+1][16 * j + 4 * k + s+1] + DP[p+1][16 * i + 4 * j + k+1] ; DP[p + 1+1][16 * j + 4 * k + s+1] := DP[p + 1+1][16 * j + 4 * k + s+1] mod con ) else skip)))) ; DP[p + 1+1][6+1] := 0 ; DP[p + 1+1][9+1] := 0 ; DP[p + 1+1][18+1] := 0) ; var ans : OclAny := (DP[N - 1+1])->sum() ; execute (ans mod con)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import array from fractions import Fraction import functools import itertools import math import os import sys def main(): H,W=read_ints() S=[inp()for _ in range(H)] print(solve(H,W,S)) def solve(H,W,S): o_table=[[0]*W for _ in range(H)] for y in range(H): c=0 for x in range(W-1,-1,-1): if S[y][x]=='O' : c+=1 o_table[y][x]=c i_table=[[0]*W for _ in range(H)] for x in range(W): c=0 for y in range(H-1,-1,-1): if S[y][x]=='I' : c+=1 i_table[y][x]=c ans=0 for y in range(H): for x in range(W): if S[y][x]=='J' : ans+=o_table[y][x]*i_table[y][x] return ans DEBUG='DEBUG' in os.environ def inp(): return sys.stdin.readline().rstrip() def read_int(): return int(inp()) def read_ints(): return[int(e)for e in inp().split()] def dprint(*value,sep=' ',end='\n'): if DEBUG : print(*value,sep=sep,end=end) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var DEBUG : boolean := (os.environ)->includes('DEBUG') ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := read_ints() ; var S : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (inp())) ; execute (solve(H, W, S))->display(); operation solve(H : OclAny, W : OclAny, S : OclAny) : OclAny pre: true post: true activity: var o_table : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, W))) ; for y : Integer.subrange(0, H-1) do ( var c : int := 0 ; for x : Integer.subrange(-1 + 1, W - 1)->reverse() do ( if S[y+1][x+1] = 'O' then ( c := c + 1 ) else skip ; o_table[y+1][x+1] := c)) ; var i_table : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, W))) ; for x : Integer.subrange(0, W-1) do ( c := 0 ; for y : Integer.subrange(-1 + 1, H - 1)->reverse() do ( if S[y+1][x+1] = 'I' then ( c := c + 1 ) else skip ; i_table[y+1][x+1] := c)) ; var ans : int := 0 ; for y : Integer.subrange(0, H-1) do ( for x : Integer.subrange(0, W-1) do ( if S[y+1][x+1] = 'J' then ( ans := ans + o_table[y+1][x+1] * i_table[y+1][x+1] ) else skip)) ; return ans; operation inp() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation read_int() : OclAny pre: true post: true activity: return ("" + ((inp())))->toInteger(); operation read_ints() : OclAny pre: true post: true activity: return inp().split()->select(e | true)->collect(e | (("" + ((e)))->toInteger())); operation dprint(value : OclAny : Sequence(OclAny), sep : String, end : String) pre: true post: true activity: (args * (named_parameter (name value))) if sep->oclIsUndefined() then sep := ' ' else skip; if end->oclIsUndefined() then end := ' ' else skip; if DEBUG then ( execute ((argument * (test (logical_test (comparison (expr (atom (name value))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): h,w=map(int,input().split()) mp=[input()for _ in range(h)] i_cnt=[[0]*w for _ in range(h)] o_cnt=[[0]*w for _ in range(h)] for x in range(w): if mp[h-1][x]=="I" : i_cnt[h-1][x]=1 for y in range(h): if mp[y][w-1]=="O" : o_cnt[y][w-1]=1 ans=0 for y in range(h-2,-1,-1): for x in range(w-2,-1,-1): if mp[y][x]=="I" : i_cnt[y][x]=i_cnt[y+1][x]+1 o_cnt[y][x]=o_cnt[y][x+1] elif mp[y][x]=="O" : i_cnt[y][x]=i_cnt[y+1][x] o_cnt[y][x]=o_cnt[y][x+1]+1 else : i_cnt[y][x]=i_cnt[y+1][x] o_cnt[y][x]=o_cnt[y][x+1] ans+=i_cnt[y][x]*o_cnt[y][x] print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mp : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var i_cnt : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, w))) ; var o_cnt : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, w))) ; for x : Integer.subrange(0, w-1) do ( if mp[h - 1+1][x+1] = "I" then ( i_cnt[h - 1+1][x+1] := 1 ) else skip) ; for y : Integer.subrange(0, h-1) do ( if mp[y+1][w - 1+1] = "O" then ( o_cnt[y+1][w - 1+1] := 1 ) else skip) ; var ans : int := 0 ; for y : Integer.subrange(-1 + 1, h - 2)->reverse() do ( for x : Integer.subrange(-1 + 1, w - 2)->reverse() do ( if mp[y+1][x+1] = "I" then ( i_cnt[y+1][x+1] := i_cnt[y + 1+1][x+1] + 1 ; o_cnt[y+1][x+1] := o_cnt[y+1][x + 1+1] ) else (if mp[y+1][x+1] = "O" then ( i_cnt[y+1][x+1] := i_cnt[y + 1+1][x+1] ; o_cnt[y+1][x+1] := o_cnt[y+1][x + 1+1] + 1 ) else ( i_cnt[y+1][x+1] := i_cnt[y + 1+1][x+1] ; o_cnt[y+1][x+1] := o_cnt[y+1][x + 1+1] ; ans := ans + i_cnt[y+1][x+1] * o_cnt[y+1][x+1] ) ) )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline write=sys.stdout.write H,W=map(int,readline().split()) S=[readline().strip()for i in range(H)] ans=0 D=[0]*W for i in range(H-1,-1,-1): Si=S[i] cur=0 for j in range(W-1,-1,-1): c=Si[j] if c=='J' : ans+=D[j]*cur elif c=='O' : cur+=1 else : D[j]+=1 write("%d\n" % ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var write : OclAny := (OclFile["System.out"]).write ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : Sequence := Integer.subrange(0, H-1)->select(i | true)->collect(i | (readline()->trim())) ; var ans : int := 0 ; var D : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, W) ; for i : Integer.subrange(-1 + 1, H - 1)->reverse() do ( var Si : OclAny := S[i+1] ; var cur : int := 0 ; for j : Integer.subrange(-1 + 1, W - 1)->reverse() do ( var c : OclAny := Si[j+1] ; if c = 'J' then ( ans := ans + D[j+1] * cur ) else (if c = 'O' then ( cur := cur + 1 ) else ( D[j+1] := D[j+1] + 1 ) ) )) ; write(StringLib.format("%d\n",ans)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w=[int(i)for i in input().split()] squares=[list(input())for _ in range(h)] ans=0 h_cnts=[0]*w for i in reversed(range(0,h)): o_cnt=0 for j in reversed(range(0,w)): if squares[i][j]=='I' : h_cnts[j]+=1 elif squares[i][j]=='O' : o_cnt+=1 else : ans+=h_cnts[j]*o_cnt print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var squares : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (((OclFile["System.in"]).readLine())->characters())) ; var ans : int := 0 ; var h_cnts : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, w) ; for i : (Integer.subrange(0, h-1))->reverse() do ( var o_cnt : int := 0 ; for j : (Integer.subrange(0, w-1))->reverse() do ( if squares[i+1][j+1] = 'I' then ( h_cnts[j+1] := h_cnts[j+1] + 1 ) else (if squares[i+1][j+1] = 'O' then ( o_cnt := o_cnt + 1 ) else ( ans := ans + h_cnts[j+1] * o_cnt ) ) )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countDivisors(n,k): count=0 for i in range(1,n+1): if(n % i==0 and i % k==0): count+=1 return count if __name__=="__main__" : n,k=12,3 print(countDivisors(n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{n,k} := Sequence{12,3} ; execute (countDivisors(n, k))->display() ) else skip; operation countDivisors(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( if (n mod i = 0 & i mod k = 0) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=int(input()) def func(arr,m): dp=[0,0,0,0] for n in arr : if n==1 : dp[0]+=1 dp[1]=max(dp[0],dp[1]) dp[2]=max(dp[1],dp[2]+1) dp[3]=max(dp[2],dp[3]) else : dp[1]=max(dp[0],dp[1]+1) dp[2]=max(dp[1],dp[2]) dp[3]=max(dp[2],dp[3]+1) print(dp[3]) func([int(i)for i in input().split()],m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; func(input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())), m); operation func(arr : OclAny, m : OclAny) pre: true post: true activity: var dp : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))) ; for n : arr do ( if n = 1 then ( dp->first() := dp->first() + 1 ; dp[1+1] := Set{dp->first(), dp[1+1]}->max() ; dp[2+1] := Set{dp[1+1], dp[2+1] + 1}->max() ; dp[3+1] := Set{dp[2+1], dp[3+1]}->max() ) else ( dp[1+1] := Set{dp->first(), dp[1+1] + 1}->max() ; dp[2+1] := Set{dp[1+1], dp[2+1]}->max() ; dp[3+1] := Set{dp[2+1], dp[3+1] + 1}->max() )) ; execute (dp[3+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def countDivisors(n,k): count=0 for i in range(1,int(math.sqrt(n))+1): if(n % i==0): if(i % k==0): count+=1 if((n//i)% k==0): count+=1 if((i*i==n)and(i % k==0)): count-=1 return count if __name__=="__main__" : n=12 k=3 print(countDivisors(n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 12 ; k := 3 ; execute (countDivisors(n, k))->display() ) else skip; operation countDivisors(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(1, ("" + (((n)->sqrt())))->toInteger() + 1-1) do ( if (n mod i = 0) then ( if (i mod k = 0) then ( count := count + 1 ) else skip ; if ((n div i) mod k = 0) then ( count := count + 1 ) else skip ) else skip) ; if ((i * i = n) & (i mod k = 0)) then ( count := count - 1 ) else skip ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def power(x,y,p): res=1 ; x=x % p ; while(y>0): if(y and 1): res=(res*x)% p ; y=y>>1 ; x=(x*x)% p ; return res ; def findModuloByM(X,N,M): if(N<6): temp=chr(48+X)*N res=int(temp)% M ; return res ; if(N % 2==0): half=findModuloByM(X,N//2,M)% M ; res=(half*power(10,N//2,M)+half)% M ; return res ; else : half=findModuloByM(X,N//2,M)% M ; res=(half*power(10,N//2+1,M)+half*10+X)% M ; return res ; if __name__=="__main__" : X=6 ; N=14 ; M=9 ; print(findModuloByM(X,N,M)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( X := 6; N := 14; M := 9; ; execute (findModuloByM(X, N, M))->display(); ) else skip; operation power(x : OclAny, y : OclAny, p : OclAny) pre: true post: true activity: var res : int := 1; ; x := x mod p; ; while (y > 0) do ( if (y & 1) then ( res := (res * x) mod p; ) else skip ; y := y /(2->pow(1)); ; x := (x * x) mod p;) ; return res;; operation findModuloByM(X : OclAny, N : OclAny, M : OclAny) pre: true post: true activity: if (N < 6) then ( var temp : double := (48 + X)->byte2char() * N ; res := ("" + ((temp)))->toInteger() mod M; ; return res; ) else skip ; if (N mod 2 = 0) then ( var half : int := findModuloByM(X, N div 2, M) mod M; ; res := (half * power(10, N div 2, M) + half) mod M; ; return res; ) else ( half := findModuloByM(X, N div 2, M) mod M; ; res := (half * power(10, N div 2 + 1, M) + half * 10 + X) mod M; ; return res; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) p=list(map(int,input().split())) m=int(input()) q=list(map(int,input().split())) even_p=[x for x in p if x % 2==0] odd_p=[x for x in p if x % 2!=0] even_q=[x for x in q if x % 2==0] odd_q=[x for x in q if x % 2!=0] print(len(even_q)*len(even_p)+len(odd_q)*len(odd_p)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var q : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var even_p : Sequence := p->select(x | x mod 2 = 0)->collect(x | (x)) ; var odd_p : Sequence := p->select(x | x mod 2 /= 0)->collect(x | (x)) ; var even_q : Sequence := q->select(x | x mod 2 = 0)->collect(x | (x)) ; var odd_q : Sequence := q->select(x | x mod 2 /= 0)->collect(x | (x)) ; execute ((even_q)->size() * (even_p)->size() + (odd_q)->size() * (odd_p)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): eva,evb,oda,odb=0,0,0,0 n=int(input()) a=list(map(int,input().split())) m=int(input()) b=list(map(int,input().split())) for i in range(len(a)): if a[i]% 2==0 : eva+=1 else : oda+=1 for j in range(len(b)): if b[j]% 2==0 : evb+=1 else : odb+=1 print(oda*odb+eva*evb) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var eva : OclAny := null; var evb : OclAny := null; var oda : OclAny := null; var odb : OclAny := null; Sequence{eva,evb,oda,odb} := Sequence{0,0,0,0} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, (a)->size()-1) do ( if a[i+1] mod 2 = 0 then ( eva := eva + 1 ) else ( oda := oda + 1 )) ; for j : Integer.subrange(0, (b)->size()-1) do ( if b[j+1] mod 2 = 0 then ( evb := evb + 1 ) else ( odb := odb + 1 )) ; execute (oda * odb + eva * evb)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=0 sumsell=0 sumn=0 while True : try : at,n=map(int,input().split(",")) sumsell+=at*n sumn+=n i+=1 except EOFError : break print(sumsell) print((int)(sumn/i+0.5)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : int := 0 ; var sumsell : int := 0 ; var sumn : int := 0 ; while true do ( try ( var at : OclAny := null; var n : OclAny := null; Sequence{at,n} := (input().split(","))->collect( _x | (OclType["int"])->apply(_x) ) ; sumsell := sumsell + at * n ; sumn := sumn + n ; i := i + 1) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (simple_stmt (small_stmt break))))) ; execute (sumsell)->display() ; execute ((OclType["int"])(sumn / i + 0.5))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): eva,evb,oda,odb=0,0,0,0 n=int(input()) a=list(map(int,input().split())) m=int(input()) b=list(map(int,input().split())) for i in range(n): if a[i]% 2==0 : eva+=1 else : oda+=1 for j in range(m): if b[j]% 2==0 : evb+=1 else : odb+=1 print(oda*odb+eva*evb) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var eva : OclAny := null; var evb : OclAny := null; var oda : OclAny := null; var odb : OclAny := null; Sequence{eva,evb,oda,odb} := Sequence{0,0,0,0} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( if a[i+1] mod 2 = 0 then ( eva := eva + 1 ) else ( oda := oda + 1 )) ; for j : Integer.subrange(0, m-1) do ( if b[j+1] mod 2 = 0 then ( evb := evb + 1 ) else ( odb := odb + 1 )) ; execute (oda * odb + eva * evb)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() I=input for i in ','*int(I()): n=int(I()) f=sum([int(j)% 2 for j in I().split()]) m=int(I()) z=sum([int(j)% 2 for j in I().split()]) print((f*z)+(n-f)*(m-z)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var I : OclAny := input ; for i : StringLib.nCopies(',', ("" + ((I())))->toInteger()) do ( var n : int := ("" + ((I())))->toInteger() ; var f : OclAny := (I().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger() mod 2)))->sum() ; var m : int := ("" + ((I())))->toInteger() ; var z : OclAny := (I().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger() mod 2)))->sum() ; execute ((f * z) + (n - f) * (m - z))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for pratyush in range(int(input())): n=int(input()) a=list(map(int,input().split())) m,f,w,x,y,z=int(input()),0,0,0,0,0 b=list(map(int,input().split())) for i in a : if i % 2 : w+=1 else : x+=1 for i in b : if i % 2 : y+=1 else : z+=1 print(w*y+x*z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for pratyush : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : OclAny := null; var f : OclAny := null; var w : OclAny := null; var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{m,f,w,x,y,z} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),0,0,0,0,0} ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : a do ( if i mod 2 then ( w := w + 1 ) else ( x := x + 1 )) ; for i : b do ( if i mod 2 then ( y := y + 1 ) else ( z := z + 1 )) ; execute (w * y + x * z)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def findMaxDiff(a,n): if(n<2): print("Invalid ") return 0 min_val=sys.maxsize max_val=-sys.maxsize-1 for i in range(n): if((a[i]-i)>max_val): max_val=a[i]-i if((a[i]-i)union(Sequence{15}->union(Sequence{4}->union(Sequence{12}->union(Sequence{ 13 })))) ; n := (arr)->size() ; execute (findMaxDiff(arr, n))->display() ) else skip; operation findMaxDiff(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n < 2) then ( execute ("Invalid ")->display() ; return 0 ) else skip ; var min_val : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; var max_val : double := -(trailer . (name maxsize)) - 1 ; for i : Integer.subrange(0, n-1) do ( if (((a[i+1] - i)->compareTo(max_val)) > 0) then ( max_val := a[i+1] - i ) else skip ; if (((a[i+1] - i)->compareTo(min_val)) < 0) then ( min_val := a[i+1] - i ) else skip) ; return (max_val - min_val); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) h='#' f=[[h]*(n+2)] a=f+[[*(h+input()+h)]for _ in[0]*n]+f*2 for i in range(n): for j in range(n): if a[i+1][j+1]>h : for k,l in(2,0),(2,1),(2,2),(3,1): if a[i+k][j+l]==h : print('NO'); exit() a[i+k][j+l]=h print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var h : String := '#' ; var f : Sequence := Sequence{ MatrixLib.elementwiseMult(Sequence{ h }, (n + 2)) } ; var a : Sequence := f->union(MatrixLib.elementwiseMult(Sequence{ 0 }, n)->select(_anon | true)->collect(_anon | ((h + (OclFile["System.in"]).readLine() + h))))->union(MatrixLib.elementwiseMult(f, 2)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if a[i + 1+1][j + 1+1] > h then ( for _tuple : Sequence{2, 0}, Sequence{2, 1}, Sequence{2, 2}, Sequence{3, 1} do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var l : OclAny := _tuple->at(_indx); if a[i + k+1][j + l+1] = h then ( execute ('NO')->display(); exit() ) else skip ; a[i + k+1][j + l+1] := h) ) else skip)) ; execute ('YES')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) h='#' f=[[h]*(n+2)] a=f+[[h,*input(),h]for _ in[0]*n]+f*2 for i in range(n): for j in range(n): if a[i+1][j+1]>h : for k,l in(2,0),(2,1),(2,2),(3,1): if a[i+k][j+l]==h : print('NO'); exit() a[i+k][j+l]=h print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var h : String := '#' ; var f : Sequence := Sequence{ MatrixLib.elementwiseMult(Sequence{ h }, (n + 2)) } ; var a : Sequence := f->union(MatrixLib.elementwiseMult(Sequence{ 0 }, n)->select(_anon | true)->collect(_anon | (Sequence{h}->union((OclFile["System.in"]).readLine()->union(Sequence{ h })))))->union(MatrixLib.elementwiseMult(f, 2)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if a[i + 1+1][j + 1+1] > h then ( for _tuple : Sequence{2, 0}, Sequence{2, 1}, Sequence{2, 2}, Sequence{3, 1} do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var l : OclAny := _tuple->at(_indx); if a[i + k+1][j + l+1] = h then ( execute ('NO')->display(); exit() ) else skip ; a[i + k+1][j + l+1] := h) ) else skip)) ; execute ('YES')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count_even_odd(min,max,steps): beven=True aeven=False n=2 for i in range(0,n): a=steps[i][0] b=steps[i][1] if(not(aeven or a & 1)): aeven=True if(beven): if(b & 1): beven=False elif(not(a & 1)): if(not(b & 1)): beven=True else : if(b & 1): beven=True if(beven): even=(int(max/2)-int((min-1)/2)) odd=0 else : even=(int(max/2)-int((min-1)/2)) odd=0 if(not(beven ^ aeven)): even+=(max-min+1-int(max/2)+int((min-1)/2)) else : odd+=(max-min+1-int(max/2)+int((min-1)/2)) print("even=",even,",odd=",odd,sep="") min=1 max=4 steps=[[1,2],[3,4]] count_even_odd(min,max,steps) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; min := 1 ; max := 4 ; steps := Sequence{Sequence{1}->union(Sequence{ 2 })}->union(Sequence{ Sequence{3}->union(Sequence{ 4 }) }) ; count_even_odd(min, max, steps); operation count_even_odd(min : OclAny, max : OclAny, steps : OclAny) pre: true post: true activity: var beven : boolean := true ; var aeven : boolean := false ; var n : int := 2 ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := steps[i+1]->first() ; var b : OclAny := steps[i+1][1+1] ; if (not((aeven or MathLib.bitwiseAnd(a, 1)))) then ( aeven := true ) else skip ; if (beven) then ( if (MathLib.bitwiseAnd(b, 1)) then ( beven := false ) else skip ) else (if (not((MathLib.bitwiseAnd(a, 1)))) then ( if (not((MathLib.bitwiseAnd(b, 1)))) then ( beven := true ) else skip ) else ( if (MathLib.bitwiseAnd(b, 1)) then ( beven := true ) else skip ) ) ) ; if (beven) then ( var even : double := (("" + ((max / 2)))->toInteger() - ("" + (((min - 1) / 2)))->toInteger()) ; var odd : int := 0 ) else ( even := (("" + ((max / 2)))->toInteger() - ("" + (((min - 1) / 2)))->toInteger()) ; odd := 0 ) ; if (not((MathLib.bitwiseXor(beven, aeven)))) then ( even := even + (max - min + 1 - ("" + ((max / 2)))->toInteger() + ("" + (((min - 1) / 2)))->toInteger()) ) else ( odd := odd + (max - min + 1 - ("" + ((max / 2)))->toInteger() + ("" + (((min - 1) / 2)))->toInteger()) ) ; execute ("even=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[] c=c2=0 for i in range(n): s=input() c2+=s.count(".") l.append(list(s)) for i in range(1,n-1): for j in range(1,n-1): if l[i][j]==l[i+1][j]==l[i-1][j]==l[i][j-1]==l[i][j+1]=="." : c+=5 l[i][j]=l[i+1][j]=l[i-1][j]=l[i][j-1]=l[i][j+1]="1" if c2==c : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; var c : OclAny := 0; var c2 : int := 0 ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; c2 := c2 + s->count(".") ; execute (((s)->characters()) : l)) ; for i : Integer.subrange(1, n - 1-1) do ( for j : Integer.subrange(1, n - 1-1) do ( if l[i+1][j+1] = l[i + 1+1][j+1] & (l[i + 1+1][j+1] == l[i - 1+1][j+1]) & (l[i - 1+1][j+1] == l[i+1][j - 1+1]) & (l[i+1][j - 1+1] == l[i+1][j + 1+1]) & (l[i+1][j + 1+1] == ".") then ( c := c + 5 ; l[i+1][j+1] := l[i+1][j+1](assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name j))) - (expr (atom (number (integer 1)))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 1)))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom "1")))))))) ) else skip)) ; if c2 = c then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- vectors=[(0,0),(1,-1),(1,0),(1,1),(2,0)] N=int(input()) board=[list(input())for row_id in range(N)] for row in range(N-2): for col in range(1,N-1): can_place=all(board[row+dr][col+dc]=='.' for(dr,dc)in vectors) if can_place : for(dr,dc)in vectors : board[row+dr][col+dc]='#' has_dots=any(row.count('.')for row in board) print('NO' if has_dots else 'YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var vectors : Sequence := Sequence{Sequence{0, 0}}->union(Sequence{Sequence{1, -1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{1, 1}}->union(Sequence{ Sequence{2, 0} })))) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var board : Sequence := Integer.subrange(0, N-1)->select(row_id | true)->collect(row_id | (((OclFile["System.in"]).readLine())->characters())) ; for row : Integer.subrange(0, N - 2-1) do ( for col : Integer.subrange(1, N - 1-1) do ( var can_place : boolean := ((argument (test (logical_test (comparison (comparison (expr (atom (name board)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name row))) + (expr (atom (name dr))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name col))) + (expr (atom (name dc))))))))) ])))) == (comparison (expr (atom '.')))))) (comp_for for (exprlist (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name dr)))))) , (test (logical_test (comparison (expr (atom (name dc))))))) )))) in (logical_test (comparison (expr (atom (name vectors))))))))->forAll( _x | _x = true ) ; if can_place then ( for Sequence{dr, dc} : vectors do ( board[row + dr+1][col + dc+1] := '#') ) else skip)) ; var has_dots : boolean := ((argument (test (logical_test (comparison (expr (atom (name row)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '.'))))))) ))))))) (comp_for for (exprlist (expr (atom (name row)))) in (logical_test (comparison (expr (atom (name board))))))))->exists( _x | _x = true ) ; execute (if has_dots then 'NO' else 'YES' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) s=[list(input().rstrip())for _ in range(n)] v=[(0,0),(1,-1),(1,0),(1,1),(2,0)] ans="YES" for i in range(n): for j in range(n): if s[i][j]& 1 : continue for di,dj in v : ni,nj=i+di,j+dj if not 0<=nitoInteger() ; var s : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((input().rstrip()))) ; var v : Sequence := Sequence{Sequence{0, 0}}->union(Sequence{Sequence{1, -1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{1, 1}}->union(Sequence{ Sequence{2, 0} })))) ; var ans : String := "YES" ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if MathLib.bitwiseAnd(s[i+1][j+1], 1) then ( continue ) else skip ; for _tuple : v do (var _indx : int := 1; var di : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dj : OclAny := _tuple->at(_indx); var ni : OclAny := null; var nj : OclAny := null; Sequence{ni,nj} := Sequence{i + di,j + dj} ; if not(0 <= ni & (ni < n)) or not(0 <= nj & (nj < n)) then ( ans := "NO" ; break ) else skip ; if MathLib.bitwiseAnd(s[ni+1][nj+1], 1) then ( ans := "NO" ; break ) else skip ; s[ni+1][nj+1] := 1) ; if ans = "NO" then ( break ) else skip) ; if ans = "NO" then ( break ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math def main(args): sum=0 total_pieces=0 number_of_data=0 for line in sys.stdin : unit_price,pieces=line.strip().split(',') sum+=int(unit_price)*int(pieces) total_pieces+=int(pieces) number_of_data+=1 print('{0}\n{1}'.format(sum,math.ceil(total_pieces/number_of_data))) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation main(args : OclAny) pre: true post: true activity: var sum : int := 0 ; var total_pieces : int := 0 ; var number_of_data : int := 0 ; for line : OclFile["System.in"] do ( var unit_price : OclAny := null; var pieces : OclAny := null; Sequence{unit_price,pieces} := line->trim().split(',') ; sum := sum + ("" + ((unit_price)))->toInteger() * ("" + ((pieces)))->toInteger() ; total_pieces := total_pieces + ("" + ((pieces)))->toInteger() ; number_of_data := number_of_data + 1) ; execute (StringLib.interpolateStrings('{0} {1}', Sequence{sum, (total_pieces / number_of_data)->ceil()}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numberOfPaths(m,n): count=[[0 for x in range(m)]for y in range(n)] for i in range(m): count[i][0]=1 ; for j in range(n): count[0][j]=1 ; for i in range(1,m): for j in range(1,n): count[i][j]=count[i-1][j]+count[i][j-1] return count[m-1][n-1] m=3 n=3 print(numberOfPaths(m,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; m := 3 ; n := 3 ; execute (numberOfPaths(m, n))->display(); operation numberOfPaths(m : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count : Sequence := Integer.subrange(0, n-1)->select(y | true)->collect(y | (Integer.subrange(0, m-1)->select(x | true)->collect(x | (0)))) ; for i : Integer.subrange(0, m-1) do ( count[i+1]->first() := 1;) ; for j : Integer.subrange(0, n-1) do ( count->first()[j+1] := 1;) ; for i : Integer.subrange(1, m-1) do ( for j : Integer.subrange(1, n-1) do ( count[i+1][j+1] := count[i - 1+1][j+1] + count[i+1][j - 1+1])) ; return count[m - 1+1][n - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=int(input()) for i in range(m): n=int(input()) a=list(map(int,input().split())) s=sum(a) if(s % n==0): if(s//n in a): print('YES') else : print('NO') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, m-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : OclAny := (a)->sum() ; if (s mod n = 0) then ( if ((a)->includes(s div n)) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,b=int(input()),False v=list(map(int,input().split()))[: n] s=sum(v) b=[True for i in v if i==s/n] print("YES" if b else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var b : OclAny := null; Sequence{n,b} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),false} ; var v : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ; var s : OclAny := (v)->sum() ; var b : Sequence := v->select(i | i = s / n)->collect(i | (true)) ; execute (if b then "YES" else "NO" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=[int(x)for x in input().split()] sum_a=sum(a) res='NO' for x in a : if(sum_a-x)/(n-1)==x : res='YES' break print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var sum_a : OclAny := (a)->sum() ; var res : String := 'NO' ; for x : a do ( if (sum_a - x) / (n - 1) = x then ( res := 'YES' ; break ) else skip) ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) while(T>0): n=int(input()) a=input().split() sum=int(0) for i in range(len(a)): a[i]=int(a[i]) sum+=a[i] flag=False for i in a : if(i*n==sum): print("YES") flag=True break if(flag==False): print("NO") T=T-1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (T > 0) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := input().split() ; var sum : int := ("" + ((0)))->toInteger() ; for i : Integer.subrange(0, (a)->size()-1) do ( a[i+1] := ("" + ((a[i+1])))->toInteger() ; sum := sum + a[i+1]) ; var flag : boolean := false ; for i : a do ( if (i * n = sum) then ( execute ("YES")->display() ; flag := true ; break ) else skip) ; if (flag = false) then ( execute ("NO")->display() ) else skip ; T := T - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) m=list(map(int,input().split())) z=sum(m) a=z/n if a in m : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var z : OclAny := (m)->sum() ; var a : double := z / n ; if (m)->includes(a) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isKthBitSet(n,k): if((n>>(k-1))& 1): return True return False def setKthBit(n,k): return((1<<(k-1))| n) def allBitsAreSet(n): if(((n+1)& n)==0): return True return False def bitsAreInAltOrder(n): num=n ^(n>>1) return allBitsAreSet(num) def bitsAreInAltPatrnInGivenRange(n,l,r): if(isKthBitSet(n,r)): num=n left_shift=r else : num=setKthBit(n,(r+1)) left_shift=r+1 num=num &((1<>(l-1) return bitsAreInAltOrder(num) if __name__=='__main__' : n=18 l=1 r=3 if(bitsAreInAltPatrnInGivenRange(n,l,r)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( n := 18 ; l := 1 ; r := 3 ; if (bitsAreInAltPatrnInGivenRange(n, l, r)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isKthBitSet(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (MathLib.bitwiseAnd((n /(2->pow((k - 1)))), 1)) then ( return true ) else skip ; return false; operation setKthBit(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: return (MathLib.bitwiseOr((1 * (2->pow((k - 1)))), n)); operation allBitsAreSet(n : OclAny) : OclAny pre: true post: true activity: if ((MathLib.bitwiseAnd((n + 1), n)) = 0) then ( return true ) else skip ; return false; operation bitsAreInAltOrder(n : OclAny) : OclAny pre: true post: true activity: var num : int := MathLib.bitwiseXor(n, (n /(2->pow(1)))) ; return allBitsAreSet(num); operation bitsAreInAltPatrnInGivenRange(n : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: if (isKthBitSet(n, r)) then ( num := n ; var left_shift : OclAny := r ) else ( num := setKthBit(n, (r + 1)) ; left_shift := r + 1 ) ; num := MathLib.bitwiseAnd(num, ((1 * (2->pow(left_shift))) - 1)) ; num := num /(2->pow((l - 1))) ; return bitsAreInAltOrder(num); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=list(map(int,input().split())) y=list(map(int,input().split())) cx=sum(x) cy=sum(y) if cy>cx : print('No') else : print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var y : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cx : OclAny := (x)->sum() ; var cy : OclAny := (y)->sum() ; if (cy->compareTo(cx)) > 0 then ( execute ('No')->display() ) else ( execute ('Yes')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- vamshi,z=map(int,input().split()) print((vamshi//z+1)*z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var vamshi : OclAny := null; var z : OclAny := null; Sequence{vamshi,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((vamshi div z + 1) * z)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def factorial(n): if(n<=1): return 1 ; return n*factorial(n-1); def nCr(n,r): return(factorial(n)/(factorial(n-r)*factorial(r))); def NumberOfWays(n,x,y): return(nCr(2*n-x-y,n-x)*factorial(n)*factorial(n)); n,x,y=5,4,2 ; print(int(NumberOfWays(n,x,y))); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; Sequence{n,x,y} := Sequence{5,4,2}; ; execute (("" + ((NumberOfWays(n, x, y))))->toInteger())->display();; operation factorial(n : OclAny) pre: true post: true activity: if (n <= 1) then ( return 1; ) else skip ; return n * factorial(n - 1);; operation nCr(n : OclAny, r : OclAny) pre: true post: true activity: return (factorial(n) / (factorial(n - r) * factorial(r)));; operation NumberOfWays(n : OclAny, x : OclAny, y : OclAny) pre: true post: true activity: return (nCr(2 * n - x - y, n - x) * factorial(n) * factorial(n));; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import os import math import itertools prices=[] amounts=[] for s in sys.stdin : price,amount=map(int,s.split(',')) prices.append(price*amount) amounts.append(amount) print(sum(prices)) mean=sum(amounts)/len(amounts)+0.5 print(int(mean)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var prices : Sequence := Sequence{} ; var amounts : Sequence := Sequence{} ; for s : OclFile["System.in"] do ( var price : OclAny := null; var amount : OclAny := null; Sequence{price,amount} := (s.split(','))->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((price * amount) : prices) ; execute ((amount) : amounts)) ; execute ((prices)->sum())->display() ; var mean : double := (amounts)->sum() / (amounts)->size() + 0.5 ; execute (("" + ((mean)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def commonPrefixUtil(str1,str2): n1=len(str1) n2=len(str2) result="" j=0 i=0 while(i<=n1-1 and j<=n2-1): if(str1[i]!=str2[j]): break result+=(str1[i]) i+=1 j+=1 return(result) def commonPrefix(arr,n): arr.sort(reverse=False) print(commonPrefixUtil(arr[0],arr[n-1])) if __name__=='__main__' : arr=["geeksforgeeks","geeks","geek","geezer"] n=len(arr) commonPrefix(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{"geeksforgeeks"}->union(Sequence{"geeks"}->union(Sequence{"geek"}->union(Sequence{ "geezer" }))) ; n := (arr)->size() ; commonPrefix(arr, n) ) else skip; operation commonPrefixUtil(str1 : OclAny, str2 : OclAny) : OclAny pre: true post: true activity: var n1 : int := (str1)->size() ; var n2 : int := (str2)->size() ; var result : String := "" ; var j : int := 0 ; var i : int := 0 ; while ((i->compareTo(n1 - 1)) <= 0 & (j->compareTo(n2 - 1)) <= 0) do ( if (str1[i+1] /= str2[j+1]) then ( break ) else skip ; result := result + (str1[i+1]) ; i := i + 1 ; j := j + 1) ; return (result); operation commonPrefix(arr : OclAny, n : OclAny) pre: true post: true activity: arr := arr->sort() ; execute (commonPrefixUtil(arr->first(), arr[n - 1+1]))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from statistics import median from fractions import gcd from itertools import combinations from collections import deque from collections import defaultdict import bisect import sys sys.setrecursionlimit(10000000) mod=10**9+7 def readInts(): return list(map(int,input().split())) def main(): n=int(input()) A=readInts() A=sorted(A) ans=0 for i in range(len(A)-2,len(A)-2*n-1,-2): ans+=A[i] print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(10000000) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation readInts() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : OclAny := readInts() ; A := A->sort() ; var ans : int := 0 ; for i : Integer.subrange((A)->size() - 2, (A)->size() - 2 * n - 1-1)->select( $x | ($x - (A)->size() - 2) mod -2 = 0 ) do ( ans := ans + A[i+1]) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=sorted(list(map(int,input().split()))) print(sum(a[n : : 2])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; execute ((a(subscript (test (logical_test (comparison (expr (atom (name n)))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import fractions import bisect import collections import itertools import heapq import string import sys import copy from collections import deque sys.setrecursionlimit(10**7) def gcd(a,b): return fractions.gcd(a,b) def lcm(a,b): return(a*b)//fractions.gcd(a,b) def iin(): return int(input()) def isn(): return input().split() def imn(): return map(int,input().split()) def iln(): return list(map(int,input().split())) def iln_s(): return sorted(iln()) def iln_r(): return sorted(iln(),reverse=True) def join(l,s=''): return s.join(l) def perm(l,n): return itertools.permutations(l,n) def perm_count(n,r): return math.factorial(n)//math.factorial(n-r) def comb(l,n): return itertools.combinations(l,n) def comb_count(n,r): return math.factorial(n)//(math.factorial(n-r)*math.factorial(r)) N=iin() a=iln_r() ans=0 for i in range(0,N): ans+=a[(i*2)+1] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var N : OclAny := iin() ; a := iln_r() ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( ans := ans + a[(i * 2) + 1+1]) ; execute (ans)->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return fractions.gcd(a, b); operation lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a * b) div fractions.gcd(a, b); operation iin() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation isn() : OclAny pre: true post: true activity: return input().split(); operation imn() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation iln() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation iln_s() : OclAny pre: true post: true activity: return iln()->sort(); operation iln_r() : OclAny pre: true post: true activity: return iln()->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))); operation join(l : OclAny, s : String) : OclAny pre: true post: true activity: if s->oclIsUndefined() then s := '' else skip; return StringLib.sumStringsWithSeparator((l), s); operation perm(l : OclAny, n : OclAny) : OclAny pre: true post: true activity: return itertools.permutations(l, n); operation perm_count(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: return MathLib.factorial(n) div MathLib.factorial(n - r); operation comb(l : OclAny, n : OclAny) : OclAny pre: true post: true activity: return itertools.combinations(l, n); operation comb_count(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: return MathLib.factorial(n) div (MathLib.factorial(n - r) * MathLib.factorial(r)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=list(map(int,input().split())) A_sorted=sorted(A,reverse=True) strength=0 for i in range(N): strength+=A_sorted[2*i+1] print(strength) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var A_sorted : Sequence := A->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var strength : int := 0 ; for i : Integer.subrange(0, N-1) do ( strength := strength + A_sorted[2 * i + 1+1]) ; execute (strength)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input())*3 l=[int(i)for i in input().split()] l.sort() ans=chk=0 for i in range(-2,(n//3*2)*-1-1,-2): ans+=l[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() * 3 ; var l : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; l := l->sort() ; var ans : OclAny := 0; var chk : int := 0 ; for i : Integer.subrange(-2, (n div 3 * 2) * -1 - 1-1)->select( $x | ($x - -2) mod -2 = 0 ) do ( ans := ans + l[i+1]) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=[] for i in range(N): a=int(input()) A.append(a) count=0 for i in range(N): if i==0 : now=0 nex=A[0] count+=1 else : nex=A[nex-1] count+=1 if nex==2 : print(count) exit() print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((a) : A)) ; var count : int := 0 ; for i : Integer.subrange(0, N-1) do ( if i = 0 then ( var now : int := 0 ; var nex : OclAny := A->first() ; count := count + 1 ) else ( nex := A[nex - 1+1] ; count := count + 1 ) ; if nex = 2 then ( execute (count)->display() ; exit() ) else skip) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def LI(): return list(map(int,sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] def SRL(n): return[list(S())for i in range(n)] def MSRL(n): return[[int(j)for j in list(S())]for i in range(n)] mod=10**9+7 n=I() a=IR(n) count=0 cur=1 while countpow(9) + 7 ; n := I() ; var a : OclAny := IR(n) ; var count : int := 0 ; var cur : int := 1 ; while (count->compareTo(n)) < 0 do ( count := count + 1 ; cur := a[cur - 1+1] ; if cur = 2 then ( execute (count)->display() ; sys.exit() ) else skip) ; execute (-1)->display(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation I() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.buffer.readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.buffer.readLine().rstrip().decode('utf-8').split(); operation S() : OclAny pre: true post: true activity: return sys.stdin.buffer.readLine().rstrip().decode('utf-8'); operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation SRL(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | ((S()))); operation MSRL(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | ((S())->select(j | true)->collect(j | (("" + ((j)))->toInteger())))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys try : from typing import List except ImportError : pass def solve(N : int,a : "List[int]"): k=0 for i in range(N+1): if k==1 : print(i) return k=a[k]-1 print(-1) def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() N=int(next(tokens)) a=[int(next(tokens))for _ in range(N)] solve(N,a) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; try ( skip) (except_clause except (test (logical_test (comparison (expr (atom (name ImportError)))))) : (suite (stmt (simple_stmt (small_stmt pass))))) ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(N : int, a : "List[int]") pre: true post: true activity: var k : int := 0 ; for i : Integer.subrange(0, N + 1-1) do ( if k = 1 then ( execute (i)->display() ; return ) else skip ; k := a[k+1] - 1) ; execute (-1)->display(); operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var N : int := ("" + (((tokens).next())))->toInteger() ; var a : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((tokens).next())))->toInteger())) ; solve(N, a); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=input().split() n=int(n) k=int(k) once=False x=0 while(True): if(k==1): print(n+1) break if(x*k>n and(x*k)% k==0): print(x*k) break elif(x*ktoInteger() ; var k : int := ("" + ((k)))->toInteger() ; var once : boolean := false ; var x : int := 0 ; while (true) do ( if (k = 1) then ( execute (n + 1)->display() ; break ) else skip ; if ((x * k->compareTo(n)) > 0 & (x * k) mod k = 0) then ( execute (x * k)->display() ; break ) else (if ((x * k->compareTo(n)) < 0 & not(once)) then ( x := n div k ; once := true ) else ( x := x + 1 ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=0,0,0 while 1 : try : x,y=map(int,input().split(',')) except : print(a) print(int(b/c+0.5)) break a,b,c=a+x*y,b+y,c+1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{0,0,0} ; while 1 do ( try ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split(','))->collect( _x | (OclType["int"])->apply(_x) )) catch (_e : OclException) do ( execute (a)->display() ; execute (("" + ((b / c + 0.5)))->toInteger())->display() ; break) ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{a + x * y,b + y,c + 1}); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(input())-1 for i in range(n)] now=0 x=[0]*n i=0 while x[now]==0 : i+=1 x[now]=1 now=a[now] if now==1 : print(i) break else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger() - 1)) ; var now : int := 0 ; var x : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var i : int := 0 ; (compound_stmt while (test (logical_test (comparison (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name now)))))))) ])))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name now)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name now)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name now)))))))) ])))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name now)))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N=int(input()) a=[int(input())for _ in range(N)] lst=[False]*N i=1 cnt=0 flag=False for _ in range(N): lst[i-1]=True cnt+=1 i=a[i-1] if i==2 : flag=True break if lst[i-1]==True : flag=False break if flag==True : print(cnt) else : print(-1) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var lst : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, N) ; var i : int := 1 ; var cnt : int := 0 ; var flag : boolean := false ; for _anon : Integer.subrange(0, N-1) do ( lst[i - 1+1] := true ; cnt := cnt + 1 ; i := a[i - 1+1] ; if i = 2 then ( flag := true ; break ) else skip ; if lst[i - 1+1] = true then ( flag := false ; break ) else skip) ; if flag = true then ( execute (cnt)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): a=0 b=1 for i in range(32): a,b=b,a+b return str(a) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var a : int := 0 ; var b : int := 1 ; for i : Integer.subrange(0, 32-1) do ( Sequence{a,b} := Sequence{b,a + b}) ; return ("" + ((a))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findFrequencyUtil(arr,low,high,freq): if(arr[low]==arr[high]): freq[arr[low]]+=high-low+1 else : mid=int((low+high)/2) findFrequencyUtil(arr,low,mid,freq) findFrequencyUtil(arr,mid+1,high,freq) def findFrequency(arr,n): freq=[0 for i in range(n-1+1)] findFrequencyUtil(arr,0,n-1,freq) for i in range(0,arr[n-1]+1,1): if(freq[i]!=0): print("Element",i,"occurs",freq[i],"times") if __name__=='__main__' : arr=[1,1,1,2,3,3,5,5,8,8,8,9,9,10] n=len(arr) findFrequency(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{3}->union(Sequence{5}->union(Sequence{5}->union(Sequence{8}->union(Sequence{8}->union(Sequence{8}->union(Sequence{9}->union(Sequence{9}->union(Sequence{ 10 }))))))))))))) ; n := (arr)->size() ; findFrequency(arr, n) ) else skip; operation findFrequencyUtil(arr : OclAny, low : OclAny, high : OclAny, freq : OclAny) pre: true post: true activity: if (arr[low+1] = arr[high+1]) then ( freq[arr[low+1]+1] := freq[arr[low+1]+1] + high - low + 1 ) else ( var mid : int := ("" + (((low + high) / 2)))->toInteger() ; findFrequencyUtil(arr, low, mid, freq) ; findFrequencyUtil(arr, mid + 1, high, freq) ); operation findFrequency(arr : OclAny, n : OclAny) pre: true post: true activity: freq := Integer.subrange(0, n - 1 + 1-1)->select(i | true)->collect(i | (0)) ; findFrequencyUtil(arr, 0, n - 1, freq) ; for i : Integer.subrange(0, arr[n - 1+1] + 1-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (freq[i+1] /= 0) then ( execute ("Element")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin read_int=lambda : list(map(int,stdin.readline().split())) read_str=lambda : stdin.readline().rstrip() N=read_int()[0] S=read_str() r=0 g=0 b=0 for s in S : if s=='R' : r+=1 continue if s=='G' : g+=1 continue if s=='B' : b+=1 continue def solve(): ans=r*g*b for d in range(1,N): for i in range(0,N-2*d): if S[i]!=S[i+d]and S[i]!=S[i+2*d]and S[i+d]!=S[i+2*d]: ans-=1 return ans if __name__=="__main__" : print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stdin : OclFile := OclFile["System.in"] ; var read_int : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var read_str : Function := lambda $$ : OclAny in (stdin.readLine().rstrip()) ; var N : OclAny := read_int->apply()->first() ; var S : OclAny := read_str->apply() ; var r : int := 0 ; var g : int := 0 ; var b : int := 0 ; for s : S do ( if s = 'R' then ( r := r + 1 ; continue ) else skip ; if s = 'G' then ( g := g + 1 ; continue ) else skip ; if s = 'B' then ( b := b + 1 ; continue ) else skip) ; skip ; if __name__ = "__main__" then ( execute (solve())->display() ) else skip; operation solve() : OclAny pre: true post: true activity: var ans : int := r * g * b ; for d : Integer.subrange(1, N-1) do ( for i : Integer.subrange(0, N - 2 * d-1) do ( if S[i+1] /= S[i + d+1] & S[i+1] /= S[i + 2 * d+1] & S[i + d+1] /= S[i + 2 * d+1] then ( ans := ans - 1 ) else skip)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools n=int(input()) s=input() rui_rl=[0]+list(itertools.accumulate([1 if x=='R' else 0 for x in s])) rui_gl=[0]+list(itertools.accumulate([1 if x=='G' else 0 for x in s])) rui_bl=[0]+list(itertools.accumulate([1 if x=='B' else 0 for x in s])) rui={'R' : rui_rl,'G' : rui_gl,'B' : rui_bl} ans=0 for i in range(n): for j in range(i+1,n): if s[i]==s[j]: continue if 'R' not in[s[i],s[j]]: target='R' elif 'G' not in[s[i],s[j]]: target='G' else : target='B' dif_ji=j-i ans+=rui[target][-1]-rui[target][j+1] if j+dif_ji<=n-1 : if s[j+dif_ji]==target : ans-=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var rui_rl : Sequence := Sequence{ 0 }->union((itertools.accumulate(s->characters()->select(x | true)->collect(x | (if x = 'R' then 1 else 0 endif))))) ; var rui_gl : Sequence := Sequence{ 0 }->union((itertools.accumulate(s->characters()->select(x | true)->collect(x | (if x = 'G' then 1 else 0 endif))))) ; var rui_bl : Sequence := Sequence{ 0 }->union((itertools.accumulate(s->characters()->select(x | true)->collect(x | (if x = 'B' then 1 else 0 endif))))) ; var rui : Map := Map{ 'R' |-> rui_rl }->union(Map{ 'G' |-> rui_gl }->union(Map{ 'B' |-> rui_bl })) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if s[i+1] = s[j+1] then ( continue ) else skip ; if (Sequence{s[i+1]}->union(Sequence{ s[j+1] }))->excludes('R') then ( var target : String := 'R' ) else (if (Sequence{s[i+1]}->union(Sequence{ s[j+1] }))->excludes('G') then ( target := 'G' ) else ( target := 'B' ) ) ; var dif_ji : double := j - i ; ans := ans + rui->at(target)->last() - rui->at(target)[j + 1+1] ; if (j + dif_ji->compareTo(n - 1)) <= 0 then ( if s[j + dif_ji+1] = target then ( ans := ans - 1 ) else skip ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) S=input() R=0 ; G=1 ; B=2 C=["R","G","B"] X=[[[0 for i in range(N+1)]for x in range(2)]for c in range(3)] for c in range(3): for i in range(N): if S[i]==C[c]: X[c][0][i+1]=X[c][0][i]+1 else : X[c][0][i+1]=X[c][0][i] for i in range(N-1,-1,-1): if S[i]==C[c]: X[c][1][i]=X[c][1][i+1]+1 else : X[c][1][i]=X[c][1][i+1] ans=0 for i in range(N): c=-1 for cc in range(3): if C[cc]==S[i]: c=cc break for seq in[((c+1)% 3,(c+2)% 3),((c+2)% 3,(c+1)% 3)]: x,y=seq ans+=X[x][0][i]*X[y][1][i] for i in range(N): x=0 while(i+2*xtoInteger() ; var S : String := (OclFile["System.in"]).readLine() ; var R : int := 0; var G : int := 1; var B : int := 2 ; var C : Sequence := Sequence{"R"}->union(Sequence{"G"}->union(Sequence{ "B" })) ; var X : Sequence := Integer.subrange(0, 3-1)->select(c | true)->collect(c | (Integer.subrange(0, 2-1)->select(x | true)->collect(x | (Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (0)))))) ; for c : Integer.subrange(0, 3-1) do ( for i : Integer.subrange(0, N-1) do ( if S[i+1] = C[c+1] then ( X[c+1]->first()[i + 1+1] := X[c+1]->first()[i+1] + 1 ) else ( X[c+1]->first()[i + 1+1] := X[c+1]->first()[i+1] )) ; for i : Integer.subrange(-1 + 1, N - 1)->reverse() do ( if S[i+1] = C[c+1] then ( X[c+1][1+1][i+1] := X[c+1][1+1][i + 1+1] + 1 ) else ( X[c+1][1+1][i+1] := X[c+1][1+1][i + 1+1] ))) ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( var c : int := -1 ; for cc : Integer.subrange(0, 3-1) do ( if C[cc+1] = S[i+1] then ( c := cc ; break ) else skip) ; for seq : Sequence{Sequence{(c + 1) mod 3, (c + 2) mod 3}}->union(Sequence{ Sequence{(c + 2) mod 3, (c + 1) mod 3} }) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := seq ; ans := ans + X[x+1]->first()[i+1] * X[y+1][1+1][i+1])) ; for i : Integer.subrange(0, N-1) do ( var x : int := 0 ; while ((i + 2 * x->compareTo(N)) < 0) do ( var j : OclAny := i + x ; var k : OclAny := i + 2 * x ; if (Set{S[i+1]}->union(Set{S[j+1]}->union(Set{ S[k+1] })))->size() = 3 then ( ans := ans - 1 ) else skip ; x := x + 1)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) srgb=input() red=srgb.count("R") green=srgb.count("G") blue=n-red-green ans=red*green*blue counter=0 for i in range(n): for j in range(i+1,n): k=j-i+j if ktoInteger() ; var srgb : String := (OclFile["System.in"]).readLine() ; var red : int := srgb->count("R") ; var green : int := srgb->count("G") ; var blue : double := n - red - green ; var ans : double := red * green * blue ; var counter : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( var k : double := j - i + j ; if (k->compareTo(n)) < 0 then ( if srgb[i+1] /= srgb[j+1] & srgb[j+1] /= srgb[k+1] & srgb[k+1] /= srgb[i+1] then ( counter := counter + 1 ) else skip ) else skip)) ; ans := ans - counter ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math N=int(input()) S=input() def calculate(n,s): arr=list(s) rNum=arr.count("R") gNum=arr.count("G") bNum=arr.count("B") sum=0 for step in range(1,math.ceil(n/2)+1): for i in range(n-2*step): s="".join([arr[i],arr[i+step],arr[i+step*2]]) if s=="RGB" or s=="RBG" or s=="BGR" or s=="BRG" or s=="GBR" or s=="GRB" : sum=sum+1 print(rNum*gNum*bNum-sum) calculate(N,S) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : String := (OclFile["System.in"]).readLine() ; skip ; calculate(N, S); operation calculate(n : OclAny, s : OclAny) pre: true post: true activity: var arr : Sequence := (s) ; var rNum : int := arr->count("R") ; var gNum : int := arr->count("G") ; var bNum : int := arr->count("B") ; var sum : int := 0 ; for step : Integer.subrange(1, (n / 2)->ceil() + 1-1) do ( for i : Integer.subrange(0, n - 2 * step-1) do ( s := StringLib.sumStringsWithSeparator((Sequence{arr[i+1]}->union(Sequence{arr[i + step+1]}->union(Sequence{ arr[i + step * 2+1] }))), "") ; if s = "RGB" or s = "RBG" or s = "BGR" or s = "BRG" or s = "GBR" or s = "GRB" then ( sum := sum + 1 ) else skip)) ; execute (rNum * gNum * bNum - sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): totients=eulerlib.list_totients(10**7-1) minnumer=1 mindenom=0 for(i,tot)in enumerate(totients[2 :],2): if i*mindenomdisplay() ) else skip; operation compute() : OclAny pre: true post: true activity: var totients : OclAny := eulerlib.list_totients((10)->pow(7) - 1) ; var minnumer : int := 1 ; var mindenom : int := 0 ; for Sequence{i, tot} : Integer.subrange(1, (totients.subrange(2+1), 2)->size())->collect( _indx | Sequence{_indx-1, (totients.subrange(2+1), 2)->at(_indx)} ) do ( if (i * mindenom->compareTo(minnumer * tot)) < 0 & ("" + ((i)))->sort() = ("" + ((tot)))->sort() then ( minnumer := i ; mindenom := totients[i+1] ) else skip) ; return ("" + ((minnumer))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import io import os import sys from collections import Counter from functools import reduce from math import gcd input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def solve(): n=int(input()) a=list(map(int,input().split())) if len(set(a))==1 and a[0]==0 : for i in range(1,n+1): sys.stdout.write(f'{i}'+' \n'[i==n]) return counter=Counter() for x in a : for k,v in enumerate(bin(x)[-1 : 1 :-1]): v=int(v) if v : counter[k]+=1 g=reduce(gcd,counter.values()) ans=[] for i in range(1,g+1): if g % i==0 : ans.append(i) m=len(ans) for i in range(m): sys.stdout.write(f'{ans[i]}'+' \n'[i==m-1]) if __name__=='__main__' : for _ in range(int(input())): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; skip ; if __name__ = '__main__' then ( for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve()) ) else skip; operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (Set{}->union((a)))->size() = 1 & a->first() = 0 then ( for i : Integer.subrange(1, n + 1-1) do ((expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom f '{i}')) + (expr (atom ' ') (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (comparison (expr (atom (name i)))) == (comparison (expr (atom (name n))))))))) ]))))))))) ))))) ; return ) else skip ; var counter : OclAny := Counter() ; for x : a do ( for _tuple : Integer.subrange(1, (bin(x)(subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))) : (test (logical_test (comparison (expr (atom (number (integer 1))))))) (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->size())->collect( _indx | Sequence{_indx-1, (bin(x)(subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))) : (test (logical_test (comparison (expr (atom (number (integer 1))))))) (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->at(_indx)} ) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); var v : int := ("" + ((v)))->toInteger() ; if v then ( counter[k+1] := counter[k+1] + 1 ) else skip)) ; var g : OclAny := reduce(gcd, counter.values()) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(1, g + 1-1) do ( if g mod i = 0 then ( execute ((i) : ans) ) else skip) ; var m : int := (ans)->size() ; for i : Integer.subrange(0, m-1) do ((expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom f '{ans[i]}')) + (expr (atom ' ') (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (comparison (expr (atom (name i)))) == (comparison (expr (expr (atom (name m))) - (expr (atom (number (integer 1))))))))))) ]))))))))) ))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t,x=list(map(int,input().strip().split(' '))) tmp=(t//x)*x res=tmp if tmp>t else tmp+x print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := null; var x : OclAny := null; Sequence{t,x} := ((input()->trim().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var tmp : double := (t div x) * x ; var res : OclAny := if (tmp->compareTo(t)) > 0 then tmp else tmp + x endif ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def intersection(a,b,n,m): i=0 j=0 while(ib[j]): j+=1 else : if(b[j]>a[i]): i+=1 else : print(a[i],end=" ") i+=1 j+=1 if __name__=="__main__" : a=[1,2,3,3,4,5,5,6] b=[3,3,5] n=len(a) m=len(b) intersection(a,b,n,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{5}->union(Sequence{ 6 }))))))) ; b := Sequence{3}->union(Sequence{3}->union(Sequence{ 5 })) ; n := (a)->size() ; m := (b)->size() ; intersection(a, b, n, m) ) else skip; operation intersection(a : OclAny, b : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: var i : int := 0 ; var j : int := 0 ; while ((i->compareTo(n)) < 0 & (j->compareTo(m)) < 0) do ( if ((a[i+1]->compareTo(b[j+1])) > 0) then ( j := j + 1 ) else ( if ((b[j+1]->compareTo(a[i+1])) > 0) then ( i := i + 1 ) else ( execute (a[i+1])->display() ; i := i + 1 ; j := j + 1 ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as m def findMin(a,n): _sum=0 for i in range(n): _sum+=m.log(a[i]) x=m.exp(_sum/n) return int(x+1) a=[3,2,1,4] n=len(a) print(findMin(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := Sequence{3}->union(Sequence{2}->union(Sequence{1}->union(Sequence{ 4 }))) ; n := (a)->size() ; execute (findMin(a, n))->display(); operation findMin(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var _sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( _sum := _sum + m.log(a[i+1])) ; var x : double := m.exp(_sum / n) ; return ("" + ((x + 1)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def lcmOfArray(arr,n): if(n<1): return 0 lcm=arr[0] for i in range(1,n,1): lcm=int((lcm*arr[i])/gcd(lcm,arr[i])) return lcm def minPerfectSquare(arr,n): lcm=lcmOfArray(arr,n) minPerfectSq=int(lcm) cnt=0 while(lcm>1 and lcm % 2==0): cnt+=1 lcm/=2 if(cnt % 2!=0): minPerfectSq*=2 i=3 while(lcm>1): cnt=0 ; while(lcm % i==0): cnt+=1 lcm/=i if(cnt % 2!=0): minPerfectSq*=i i+=2 return minPerfectSq if __name__=='__main__' : arr=[2,3,4,5,7] n=len(arr) print(minPerfectSquare(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 7 })))) ; n := (arr)->size() ; execute (minPerfectSquare(arr, n))->display() ) else skip; operation lcmOfArray(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n < 1) then ( return 0 ) else skip ; var lcm : OclAny := arr->first() ; for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( lcm := ("" + (((lcm * arr[i+1]) / gcd(lcm, arr[i+1]))))->toInteger()) ; return lcm; operation minPerfectSquare(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: lcm := lcmOfArray(arr, n) ; var minPerfectSq : int := ("" + ((lcm)))->toInteger() ; var cnt : int := 0 ; while (lcm > 1 & lcm mod 2 = 0) do ( cnt := cnt + 1 ; lcm := lcm / 2) ; if (cnt mod 2 /= 0) then ( minPerfectSq := minPerfectSq * 2 ) else skip ; var i : int := 3 ; while (lcm > 1) do ( cnt := 0; ; while (lcm mod i = 0) do ( cnt := cnt + 1 ; lcm := lcm / i) ; if (cnt mod 2 /= 0) then ( minPerfectSq := minPerfectSq * i ) else skip ; i := i + 2) ; return minPerfectSq; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def subarrayCount(arr,n): result=0 fast,slow=0,0 for i in range(1,n): if(arr[i]-arr[i-1]==1): fast+=1 else : length=fast-slow+1 result+=length*(length-1)//2 ; fast=i slow=i if(fast!=slow): length=fast-slow+1 result+=length*(length-1)//2 ; return result if __name__=="__main__" : arr=[1,2,3,5,6,7] n=len(arr) print(subarrayCount(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 7 }))))) ; n := (arr)->size() ; execute (subarrayCount(arr, n))->display() ) else skip; operation subarrayCount(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; var fast : OclAny := null; var slow : OclAny := null; Sequence{fast,slow} := Sequence{0,0} ; for i : Integer.subrange(1, n-1) do ( if (arr[i+1] - arr[i - 1+1] = 1) then ( fast := fast + 1 ) else ( var length : double := fast - slow + 1 ; result := result + length * (length - 1) div 2; ; var fast : OclAny := i ; var slow : OclAny := i )) ; if (fast /= slow) then ( length := fast - slow + 1 ; result := result + length * (length - 1) div 2; ) else skip ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans=[] def solve(n): f=s=0 fs=True if n & 1 : n-=1 fs=False while n : if n==4 : f+=3 s+=1 n=0 elif(n//2)& 1 : f+=n//2 s+=1 n=(n//2)-1 ; else : f+=1 s+=1 n-=2 ans.append([s+1,f][fs]) coins=[] for _ in range(int(input())): coins.append(int(input())) for i in coins : if i==1 : ans.append(1) else : solve(i) print('\n'.join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ans : Sequence := Sequence{} ; skip ; var coins : Sequence := Sequence{} ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : coins)) ; for i : coins do ( if i = 1 then ( execute ((1) : ans) ) else ( solve(i) )) ; execute (StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); operation solve(n : OclAny) pre: true post: true activity: var f : OclAny := 0; var s : int := 0 ; var fs : boolean := true ; if MathLib.bitwiseAnd(n, 1) then ( n := n - 1 ; fs := false ) else skip ; while n do ( if n = 4 then ( f := f + 3 ; s := s + 1 ; n := 0 ) else (if MathLib.bitwiseAnd((n div 2), 1) then ( f := f + n div 2 ; s := s + 1 ; n := (n div 2) - 1; ) else ( f := f + 1 ; s := s + 1 ; n := n - 2 ) ) ) ; execute ((Sequence{s + 1}->union(Sequence{ f })[fs+1]) : ans); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) anss=[] for _ in range(t): n=int(input()) ans=0 if(n & 1): st=n-1 else : st=n while(st>=1): if(st==4): ans+=3 ; break temp=st//2 if(temp & 1): ans+=temp ; st=temp-1 else : ans+=1 ; st-=2 if(n & 1): anss.append(str(n-ans)) else : anss.append(str(ans)) print('\n'.join(anss)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var anss : Sequence := Sequence{} ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; if (MathLib.bitwiseAnd(n, 1)) then ( var st : double := n - 1 ) else ( st := n ) ; while (st >= 1) do ( if (st = 4) then ( ans := ans + 3; break ) else skip ; var temp : int := st div 2 ; if (MathLib.bitwiseAnd(temp, 1)) then ( ans := ans + temp; st := temp - 1 ) else ( ans := ans + 1; st := st - 2 )) ; if (MathLib.bitwiseAnd(n, 1)) then ( execute ((("" + ((n - ans)))) : anss) ) else ( execute ((("" + ((ans)))) : anss) )) ; execute (StringLib.sumStringsWithSeparator((anss), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import math import sys def get_ints(): return map(int,sys.stdin.readline().strip().split()) def get_array(): return list(map(int,sys.stdin.readline().strip().split())) def input(): return sys.stdin.readline().strip() MOD=1000000007 def solve(n): if n<5 : return max(1,n-1) if n % 2 or n % 4==0 : return n-solve(n-1) return n-solve(n//2) for _ in range(int(input())): n=int(input()) print(solve(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var MOD : int := 1000000007 ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (solve(n))->display()); operation get_ints() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ); operation get_array() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation solve(n : OclAny) : OclAny pre: true post: true activity: if n < 5 then ( return Set{1, n - 1}->max() ) else skip ; if n mod 2 or n mod 4 = 0 then ( return n - solve(n - 1) ) else skip ; return n - solve(n div 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def inp(): return int(input()) def st(): return input().rstrip('\n') def lis(): return list(map(int,input().split())) def ma(): return map(int,input().split()) t=inp() while(t): t-=1 n=inp() coins=0 tu=0 while(n): if((n % 2==0 and(n//2)% 2)or n==4): if(tu % 2==0): coins+=n//2 n=n//2 else : if(tu % 2==0): coins+=1 n-=1 tu+=1 print(coins) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; var t : OclAny := inp() ; while (t) do ( t := t - 1 ; var n : OclAny := inp() ; var coins : int := 0 ; var tu : int := 0 ; while (n) do ( if ((n mod 2 = 0 & (n div 2) mod 2) or n = 4) then ( if (tu mod 2 = 0) then ( coins := coins + n div 2 ) else skip ; n := n div 2 ) else ( if (tu mod 2 = 0) then ( coins := coins + 1 ) else skip ; n := n - 1 ) ; tu := tu + 1) ; execute (coins)->display()); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation st() : OclAny pre: true post: true activity: return input().rstrip(' '); operation lis() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ma() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input=__import__('sys').stdin.readline for _ in range(int(input())): n=int(input()) ans=0 c=1 while n : r=0 if n % 2==0 and n//2 % 2 or n==4 : n//=2 ; r=n else : r=1 ; n-=1 if c : ans+=r c ^=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var input : OclAny := __import__('sys').stdin.readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; var c : int := 1 ; while n do ( var r : int := 0 ; if n mod 2 = 0 & n div 2 mod 2 or n = 4 then ( n := n div 2; r := n ) else ( r := 1; n := n - 1 ) ; if c then ( ans := ans + r ) else skip ; c := c xor 1) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(x): return int((2*x+1)//2) def get_input(): while True : try : yield ''.join(input()) except EOFError : break N=list(get_input()) S=0 T=0 for l in range(len(N)): n=[int(i)for i in N[l].split(",")] S+=n[0]*n[1] T+=n[1] print(S) print(f(T/len(N))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : Sequence := (OclIterator.newOclIterator_Function(lambda _i : int in self.get_input(_i))) ; var S : int := 0 ; var T : int := 0 ; for l : Integer.subrange(0, (N)->size()-1) do ( var n : Sequence := N[l+1].split(",")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; S := S + n->first() * n[1+1] ; T := T + n[1+1]) ; execute (S)->display() ; execute (f(T / (N)->size()))->display(); operation f(x : OclAny) : OclAny pre: true post: true activity: return ("" + (((2 * x + 1) div 2)))->toInteger(); operation get_input(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; while true do ( try ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return StringLib.sumStringsWithSeparator(((OclFile["System.in"]).readLine()), '')) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) print(min(a),max(a),sum(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((a)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys II=lambda : int(input()) LI=lambda : list(map(int,list(input().split(" ")))) MI=lambda : map(int,LI()) SI=lambda : input() n,k=MI() print((n//k+1)*k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var II : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var LI : Function := lambda $$ : OclAny in ((((input().split(" ")))->collect( _x | (OclType["int"])->apply(_x) ))) ; var MI : Function := lambda $$ : OclAny in ((LI->apply())->collect( _x | (OclType["int"])->apply(_x) )) ; var SI : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := MI->apply() ; execute ((n div k + 1) * k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- L1=input() n=int(L1) L=input().split() j=1 max=int(L[0]) min=int(L[0]) sum=int(L[0]) while j<=n-1 : sum=sum+int(L[j]) if maxint(L[j]): min=int(L[j]) j+=1 print(f"{min}{max}{sum}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var L1 : String := (OclFile["System.in"]).readLine() ; var n : int := ("" + ((L1)))->toInteger() ; var L : OclAny := input().split() ; var j : int := 1 ; var max : int := ("" + ((L->first())))->toInteger() ; var min : int := ("" + ((L->first())))->toInteger() ; var sum : int := ("" + ((L->first())))->toInteger() ; while (j->compareTo(n - 1)) <= 0 do ( sum := sum + ("" + ((L[j+1])))->toInteger() ; if (max->compareTo(("" + ((L[j+1])))->toInteger())) < 0 then ( max := ("" + ((L[j+1])))->toInteger() ) else skip ; if (min->compareTo(("" + ((L[j+1])))->toInteger())) > 0 then ( min := ("" + ((L[j+1])))->toInteger() ) else skip ; j := j + 1) ; execute (StringLib.formattedString("{min}{max}{sum}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=list(map(int,input().split(' '))) mx=max(b) mn=min(b) t=0 for i in b : t=t+i print(mn,mx,t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var mx : OclAny := (b)->max() ; var mn : OclAny := (b)->min() ; var t : int := 0 ; for i : b do ( t := t + i) ; execute (mn)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=input() nums=list(map(int,input().split())) print(min(nums),max(nums),sum(nums)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var nums : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((nums)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) list=list(map(int,input().split())) print("%d %d %d" %(min(list),max(list),sum(list))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var OclType["Sequence"] : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (StringLib.format("%d %d %d",Sequence{(OclType["Sequence"])->min(), (OclType["Sequence"])->max(), (OclType["Sequence"])->sum()}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,m): if n==1 or m==1 or n==m==2 : return "YES" else : return "NO" if __name__=="__main__" : t=int(input()) for i in range(0,t): n,m=map(int,input().split()) print(solve(n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (solve(n, m))->display()) ) else skip; operation solve(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: if n = 1 or m = 1 or n = m & (m == 2) then ( return "YES" ) else ( return "NO" ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,m=list(map(int,input().split())) if n==1 or m==1 : print("YES") elif n>2 or m>2 : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = 1 or m = 1 then ( execute ("YES")->display() ) else (if n > 2 or m > 2 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,m=map(int,input().split()) if n==1 or m==1 : print('YES') elif n==2 and m==2 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 1 or m = 1 then ( execute ('YES')->display() ) else (if n = 2 & m = 2 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,m=(int(i)for i in input().split()) res="YES" if n==1 or m==1 or(n==2 and m==2)else "NO" print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var res : String := if n = 1 or m = 1 or (n = 2 & m = 2) then "YES" else "NO" endif ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c1=int(input()) l1=[int(x)for x in input().split()] a=[] b=1 for i in range(c1): a+=[b]*l1[i] b+=1 input() l2=[int(x)for x in input().split()] for i in l2 : print(a[i-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l1 : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a : Sequence := Sequence{} ; var b : int := 1 ; for i : Integer.subrange(0, c1-1) do ( a := a + MatrixLib.elementwiseMult(Sequence{ b }, l1[i+1]) ; b := b + 1) ; input() ; var l2 : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for i : l2 do ( execute (a[i - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100 ; def binomialCoeff(n,k): C=[0]*(k+1); C[0]=1 ; for i in range(1,n+1): for j in range(min(i,k),0,-1): C[j]=C[j]+C[j-1]; return C[k]; def sumOfproduct(n): return binomialCoeff(2*n,n-1); n=3 ; print(sumOfproduct(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 100; ; skip ; skip ; n := 3; ; execute (sumOfproduct(n))->display();; operation binomialCoeff(n : OclAny, k : OclAny) pre: true post: true activity: var C : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (k + 1)); ; C->first() := 1; ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(0 + 1, Set{i, k}->min())->reverse() do ( C[j+1] := C[j+1] + C[j - 1+1];)) ; return C[k+1];; operation sumOfproduct(n : OclAny) pre: true post: true activity: return binomialCoeff(2 * n, n - 1);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): a,b=map(int,input().split()) if(a==1 or b==1 or a==b==2): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a = 1 or b = 1 or a = b & (b == 2)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict MAX_CHARS=256 def findSubString(str): n=len(str) dist_count=len(set([x for x in str])) curr_count=defaultdict(lambda : 0) for j in range(n): curr_count[str[j]]+=1 if curr_count[str[j]]==1 : count+=1 if count==dist_count : while curr_count[str[start]]>1 : if curr_count[str[start]]>1 : curr_count[str[start]]-=1 start+=1 len_window=j-start+1 if min_len>len_window : min_len=len_window start_index=start return str[start_index : start_index+min_len] if __name__=='__main__' : print("Smallest window containing all distinct characters is:{}".format(findSubString("aabcbcdbca"))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MAX_CHARS : int := 256 ; skip ; if __name__ = '__main__' then ( execute (StringLib.interpolateStrings("Smallest window containing all distinct characters is:{}", Sequence{findSubString("aabcbcdbca")}))->display() ) else skip; operation findSubString(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var n : int := (OclType["String"])->size() ; var dist_count : int := (Set{}->union((OclType["String"]->select(x | true)->collect(x | (x)))))->size() ; var curr_count : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; for j : Integer.subrange(0, n-1) do ( curr_count[("" + ([j+1]))+1] := curr_count[("" + ([j+1]))+1] + 1 ; if curr_count[("" + ([j+1]))+1] = 1 then ( count := count + 1 ) else skip ; if count = dist_count then ( while curr_count[("" + ([start+1]))+1] > 1 do ( if curr_count[("" + ([start+1]))+1] > 1 then ( curr_count[("" + ([start+1]))+1] := curr_count[("" + ([start+1]))+1] - 1 ) else skip ; start := start + 1) ; var len_window : double := j - start + 1 ; if (min_len->compareTo(len_window)) > 0 then ( var min_len : OclAny := len_window ; var start_index : OclAny := start ) else skip ) else skip) ; return ("" + (.subrange(start_index+1, start_index + min_len))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()); print((n//m+1)*m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); execute ((n div m + 1) * m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def concentration(water,suger): return 100*suger/(water+suger) WATER_A,WATER_B,SUGER_C,SUGER_D,MELT_PER_100,LIMIT=map(int,input().split()) WATER_A*=100 WATER_B*=100 MELT_PERCENT_LIMIT=concentration(100,MELT_PER_100) wa=wb=sc=sd=0 water_set=set() while wa*WATER_A<=LIMIT : while wb*WATER_B<=LIMIT : water=wa*WATER_A+wb*WATER_B if water<=LIMIT : water_set.add(water) wb+=1 wb=0 wa+=1 suger_set=set() while sc*SUGER_C<=LIMIT : while sd*SUGER_D<=LIMIT : suger=sc*SUGER_C+sd*SUGER_D if suger<=LIMIT : suger_set.add(suger) sd+=1 sd=0 sc+=1 ans_suger_water=0 ans_suger=0 max_concentration=0 for water in water_set : for suger in suger_set : if not(0collect( _x | (OclType["int"])->apply(_x) ) ; WATER_A := WATER_A * 100 ; WATER_B := WATER_B * 100 ; var MELT_PERCENT_LIMIT : OclAny := concentration(100, MELT_PER10000) ; wa := wa(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name wb)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sc)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sd)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; var water_set : Set := Set{}->union(()) ; while (wa * WATER_A->compareTo(LIMIT)) <= 0 do ( while (wb * WATER_B->compareTo(LIMIT)) <= 0 do ( water := wa * WATER_A + wb * WATER_B ; if (water->compareTo(LIMIT)) <= 0 then ( execute ((water) : water_set) ) else skip ; wb := wb + 1) ; var wb : int := 0 ; wa := wa + 1) ; var suger_set : Set := Set{}->union(()) ; while (sc * SUGER_C->compareTo(LIMIT)) <= 0 do ( while (sd * SUGER_D->compareTo(LIMIT)) <= 0 do ( suger := sc * SUGER_C + sd * SUGER_D ; if (suger->compareTo(LIMIT)) <= 0 then ( execute ((suger) : suger_set) ) else skip ; sd := sd + 1) ; var sd : int := 0 ; sc := sc + 1) ; var ans_suger_water : int := 0 ; var ans_suger : int := 0 ; var max_concentration : int := 0 ; for water : water_set do ( for suger : suger_set do ( if not((0 < water + suger & (water + suger <= LIMIT))) then ( continue ) else skip ; var suger_precent : OclAny := concentration(water, suger) ; if (max_concentration->compareTo(suger_precent)) <= 0 & (suger_precent <= MELT_PERCENT_LIMIT) then ( max_concentration := suger_precent ; ans_suger_water := water + suger ; ans_suger := suger ) else skip)) ; execute (ans_suger_water)->display(); operation concentration(water : OclAny, suger : OclAny) : OclAny pre: true post: true activity: return 100 * suger / (water + suger); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return input() def main(): a,b,c,d,e,f=LI() ans_n=-inf ans_pair=[0,0] xf=100*e/(100+e) for i in range(31): for j in range(31): for k in range(101): for l in range(101): xa=100*a*i+100*b*j xb=c*k+d*l if xa+xb>f : break if xa+xb==0 : continue xc=100*xb/(xa+xb) if xc>xf : continue if ans_npow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var mod : double := (10)->pow(9) + 7 ; var dd : Sequence := Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{ Sequence{0, -1} }))) ; var ddn : Sequence := Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{-1, 1}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{1, 1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{1, -1}}->union(Sequence{Sequence{0, -1}}->union(Sequence{ Sequence{-1, -1} }))))))) ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation main() : OclAny pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; var f : OclAny := null; Sequence{a,b,c,d,e,f} := LI() ; var ans_n : double := -Math_PINFINITY ; var ans_pair : Sequence := Sequence{0}->union(Sequence{ 0 }) ; var xf : double := 100 * e / (100 + e) ; for i : Integer.subrange(0, 31-1) do ( for j : Integer.subrange(0, 31-1) do ( for k : Integer.subrange(0, 101-1) do ( for l : Integer.subrange(0, 101-1) do ( var xa : double := 100 * a * i + 100 * b * j ; var xb : double := c * k + d * l ; if (xa + xb->compareTo(f)) > 0 then ( break ) else skip ; if xa + xb = 0 then ( continue ) else skip ; var xc : double := 100 * xb / (xa + xb) ; if (xc->compareTo(xf)) > 0 then ( continue ) else skip ; if (ans_n->compareTo(xc)) < 0 then ( ans_n := xc ; ans_pair := Sequence{xa + xb}->union(Sequence{ xb }) ) else skip)))) ; return ("" + ((ans_pair->first()))) + ' ' + ("" + ((ans_pair[1+1]))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B,C,D,E,F=map(int,input().split()) from itertools import product w=[] for i,j in product(range(F//(100*A)+1),range(F//(100*B)+1)): if 0<100*A*i+100*B*j<=F : w.append(100*A*i+100*B*j) s=[] for i,j in product(range(E*F//(100*C)+1),range(E*F//(100*C)+1)): if C*i+D*j<=E*(F//100): s.append(C*i+D*j) w.sort() s.sort() ans=[] for a in w : for b in s : if(a//100)*E>=b and a+b<=F : ans.append([a+b,b]) else : break ans.sort(key=lambda x : x[1]/(x[0]+x[1]),reverse=True) print(ans[0][0],ans[0][1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var D : OclAny := null; var E : OclAny := null; var F : OclAny := null; Sequence{A,B,C,D,E,F} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; var w : Sequence := Sequence{} ; for _tuple : product(Integer.subrange(0, F div (100 * A) + 1-1), Integer.subrange(0, F div (100 * B) + 1-1)) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if 0 < 100 * A * i + 100 * B * j & (100 * A * i + 100 * B * j <= F) then ( execute ((100 * A * i + 100 * B * j) : w) ) else skip) ; var s : Sequence := Sequence{} ; for _tuple : product(Integer.subrange(0, E * F div (100 * C) + 1-1), Integer.subrange(0, E * F div (100 * C) + 1-1)) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if (C * i + D * j->compareTo(E * (F div 100))) <= 0 then ( execute ((C * i + D * j) : s) ) else skip) ; w := w->sort() ; s := s->sort() ; var ans : Sequence := Sequence{} ; for a : w do ( for b : s do ( if ((a div 100) * E->compareTo(b)) >= 0 & (a + b->compareTo(F)) <= 0 then ( execute ((Sequence{a + b}->union(Sequence{ b })) : ans) ) else ( break ))) ; ans := ans->sort() ; execute (ans->first()->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys a,b,c,d,e,f=map(int,input().split()) if a>b : a,b=b,a ans1=a*100 ans2=0 for _a in range(f//(a*100)+1): for _b in range((f-_a*100)//(b*100)+1): for _c in range((f-_a*100-_b*100)//c+1): for _d in range((f-_a*100-_b*100-_c*c)//d+1): if a*100*_a+b*100*_b+c*_c+d*_d==0 : continue if a*100*_a+b*100*_b+c*_c+d*_d>f : continue if(c*_c+d*_d)/(a*100*_a+b*100*_b+c*_c+d*_d)==e/(100+e): print(a*100*_a+b*100*_b+c*_c+d*_d,c*_c+d*_d) sys.exit(0) elif(c*_c+d*_d)/(a*100*_a+b*100*_b+c*_c+d*_d)>e/(100+e): continue else : if ans2/ans1<(c*_c+d*_d)/(a*100*_a+b*100*_b+c*_c+d*_d): ans1=a*100*_a+b*100*_b+c*_c+d*_d ans2=c*_c+d*_d else : print(ans1,ans2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; var f : OclAny := null; Sequence{a,b,c,d,e,f} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(b)) > 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a} ) else skip ; var ans1 : double := a * 100 ; var ans2 : int := 0 ; (compound_stmt for (exprlist (expr (atom (name _a)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name f))) // (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name a))) * (expr (atom (number (integer 100))))))))) )))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name _b)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name f))) - (expr (expr (atom (name _a))) * (expr (atom (number (integer 100)))))))))) ))) // (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name b))) * (expr (atom (number (integer 100))))))))) )))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name _c)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name f))) - (expr (expr (atom (name _a))) * (expr (atom (number (integer 100)))))) - (expr (expr (atom (name _b))) * (expr (atom (number (integer 100)))))))))) ))) // (expr (atom (name c)))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name _d)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (expr (atom (name f))) - (expr (expr (atom (name _a))) * (expr (atom (number (integer 100)))))) - (expr (expr (atom (name _b))) * (expr (atom (number (integer 100)))))) - (expr (expr (atom (name _c))) * (expr (atom (name c))))))))) ))) // (expr (atom (name d)))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (expr (expr (expr (expr (atom (name a))) * (expr (atom (number (integer 100))))) * (expr (atom (name _a)))) + (expr (expr (expr (atom (name b))) * (expr (atom (number (integer 100))))) * (expr (atom (name _b))))) + (expr (expr (atom (name c))) * (expr (atom (name _c))))) + (expr (expr (atom (name d))) * (expr (atom (name _d)))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt continue)))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (expr (expr (expr (expr (atom (name a))) * (expr (atom (number (integer 100))))) * (expr (atom (name _a)))) + (expr (expr (expr (atom (name b))) * (expr (atom (number (integer 100))))) * (expr (atom (name _b))))) + (expr (expr (atom (name c))) * (expr (atom (name _c))))) + (expr (expr (atom (name d))) * (expr (atom (name _d)))))) > (comparison (expr (atom (name f))))))) : (suite (stmt (simple_stmt (small_stmt continue)))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name c))) * (expr (atom (name _c)))) + (expr (expr (atom (name d))) * (expr (atom (name _d))))))))) ))) / (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (expr (expr (expr (atom (name a))) * (expr (atom (number (integer 100))))) * (expr (atom (name _a)))) + (expr (expr (expr (atom (name b))) * (expr (atom (number (integer 100))))) * (expr (atom (name _b))))) + (expr (expr (atom (name c))) * (expr (atom (name _c))))) + (expr (expr (atom (name d))) * (expr (atom (name _d))))))))) ))))) == (comparison (expr (expr (atom (name e))) / (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 100)))) + (expr (atom (name e)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (expr (expr (expr (atom (name a))) * (expr (atom (number (integer 100))))) * (expr (atom (name _a)))) + (expr (expr (expr (atom (name b))) * (expr (atom (number (integer 100))))) * (expr (atom (name _b))))) + (expr (expr (atom (name c))) * (expr (atom (name _c))))) + (expr (expr (atom (name d))) * (expr (atom (name _d))))))))) , (argument (test (logical_test (comparison (expr (expr (expr (atom (name c))) * (expr (atom (name _c)))) + (expr (expr (atom (name d))) * (expr (atom (name _d)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name exit) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))))))))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name c))) * (expr (atom (name _c)))) + (expr (expr (atom (name d))) * (expr (atom (name _d))))))))) ))) / (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (expr (expr (expr (atom (name a))) * (expr (atom (number (integer 100))))) * (expr (atom (name _a)))) + (expr (expr (expr (atom (name b))) * (expr (atom (number (integer 100))))) * (expr (atom (name _b))))) + (expr (expr (atom (name c))) * (expr (atom (name _c))))) + (expr (expr (atom (name d))) * (expr (atom (name _d))))))))) ))))) > (comparison (expr (expr (atom (name e))) / (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 100)))) + (expr (atom (name e)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt continue))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name ans2))) / (expr (atom (name ans1))))) < (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name c))) * (expr (atom (name _c)))) + (expr (expr (atom (name d))) * (expr (atom (name _d))))))))) ))) / (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (expr (expr (expr (atom (name a))) * (expr (atom (number (integer 100))))) * (expr (atom (name _a)))) + (expr (expr (expr (atom (name b))) * (expr (atom (number (integer 100))))) * (expr (atom (name _b))))) + (expr (expr (atom (name c))) * (expr (atom (name _c))))) + (expr (expr (atom (name d))) * (expr (atom (name _d))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans1)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (expr (expr (expr (atom (name a))) * (expr (atom (number (integer 100))))) * (expr (atom (name _a)))) + (expr (expr (expr (atom (name b))) * (expr (atom (number (integer 100))))) * (expr (atom (name _b))))) + (expr (expr (atom (name c))) * (expr (atom (name _c))))) + (expr (expr (atom (name d))) * (expr (atom (name _d)))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans2)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (name c))) * (expr (atom (name _c)))) + (expr (expr (atom (name d))) * (expr (atom (name _d))))))))))))))))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans1))))))) , (argument (test (logical_test (comparison (expr (atom (name ans2)))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin def li(): return map(int,stdin.readline().split()) def li_(): return map(lambda x : int(x)-1,stdin.readline().split()) def lf(): return map(float,stdin.readline().split()) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) a,b,c,d,e,f=li() water_set=set() sugar_set=set() MAX=3000 for ai in range(0,MAX//100+1,a): for bi in range(0,MAX//100+1,b): if 100*(ai+bi)<=MAX : water_set.add(100*(ai+bi)) water_list=sorted(list(water_set)) for ci in range(0,30*e+1,c): for di in range(0,30*e+1,d): if ci+di<=30*e : sugar_set.add(ci+di) sugar_list=sorted(list(sugar_set)) node_max=-1 sw=0 sg=0 for wi in water_list : for si in sugar_list : if wi+si<=f and si<=e*(wi//100)and wi+si>0 : node=(100*si)/(wi+si) if node>node_max : sw=si+wi sg=si node_max=node print(sw,sg) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stdin : OclFile := OclFile["System.in"] ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; var f : OclAny := null; Sequence{a,b,c,d,e,f} := li() ; var water_set : Set := Set{}->union(()) ; var sugar_set : Set := Set{}->union(()) ; var MAX : int := 3000 ; for ai : Integer.subrange(0, MAX div 100 + 1-1)->select( $x | ($x - 0) mod a = 0 ) do ( for bi : Integer.subrange(0, MAX div 100 + 1-1)->select( $x | ($x - 0) mod b = 0 ) do ( if (100 * (ai + bi)->compareTo(MAX)) <= 0 then ( execute ((100 * (ai + bi)) : water_set) ) else skip)) ; var water_list : Sequence := (water_set)->sort() ; for ci : Integer.subrange(0, 30 * e + 1-1)->select( $x | ($x - 0) mod c = 0 ) do ( for di : Integer.subrange(0, 30 * e + 1-1)->select( $x | ($x - 0) mod d = 0 ) do ( if (ci + di->compareTo(30 * e)) <= 0 then ( execute ((ci + di) : sugar_set) ) else skip)) ; var sugar_list : Sequence := (sugar_set)->sort() ; var node_max : int := -1 ; var sw : int := 0 ; var sg : int := 0 ; for wi : water_list do ( for si : sugar_list do ( if (wi + si->compareTo(f)) <= 0 & (si->compareTo(e * (wi div 100))) <= 0 & wi + si > 0 then ( var node : double := (100 * si) / (wi + si) ; if (node->compareTo(node_max)) > 0 then ( sw := si + wi ; sg := si ; node_max := node ) else skip ) else skip)) ; execute (sw)->display(); operation li() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation li_() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ); operation lf() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ); operation ls() : OclAny pre: true post: true activity: return stdin.readLine().split(); operation ns() : OclAny pre: true post: true activity: return stdin.readLine().rstrip(); operation lc() : OclAny pre: true post: true activity: return (ns()); operation ni() : OclAny pre: true post: true activity: return ("" + ((stdin.readLine())))->toInteger(); operation nf() : OclAny pre: true post: true activity: return ("" + ((stdin.readLine())))->toReal(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys f=sys.stdin lines=[list(map(int,line.split(',')))for line in f] for i in range(1,len(lines)//2+1): for j in range(len(lines[i])): lines[i][j]+=max(lines[i-1][max(j-1,0): min(j+1,len(lines[i-1]))]) for i in range(len(lines)//2+1,len(lines)): for j in range(len(lines[i])): lines[i][j]+=max(lines[i-1][j : j+2]) print(lines[-1][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var f : OclFile := OclFile["System.in"] ; var lines : Sequence := f->select(line | true)->collect(line | (((line.split(','))->collect( _x | (OclType["int"])->apply(_x) )))) ; for i : Integer.subrange(1, (lines)->size() div 2 + 1-1) do ( for j : Integer.subrange(0, (lines[i+1])->size()-1) do ( lines[i+1][j+1] := lines[i+1][j+1] + (lines[i - 1+1].subrange(Set{j - 1, 0}->max()+1, Set{j + 1, (lines[i - 1+1])->size()}->min()))->max())) ; for i : Integer.subrange((lines)->size() div 2 + 1, (lines)->size()-1) do ( for j : Integer.subrange(0, (lines[i+1])->size()-1) do ( lines[i+1][j+1] := lines[i+1][j+1] + (lines[i - 1+1].subrange(j+1, j + 2))->max())) ; execute (lines->last()->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans=[int(input())] while True : try : inp=list(map(int,input().split(","))) l=len(inp) if l>len(ans): tmp=[-float("inf")]+ans+[-float("inf")] else : tmp=ans ans=[] for i in range(l): ans.append(max([tmp[i]+inp[i],tmp[i+1]+inp[i]])) except : break print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ans : Sequence := Sequence{ ("" + (((OclFile["System.in"]).readLine())))->toInteger() } ; while true do ( try ( var inp : Sequence := ((input().split(","))->collect( _x | (OclType["int"])->apply(_x) )) ; var l : int := (inp)->size() ; if (l->compareTo((ans)->size())) > 0 then ( var tmp : Sequence := Sequence{ -("" + (("inf")))->toReal() }->union(ans)->union(Sequence{ -("" + (("inf")))->toReal() }) ) else ( tmp := ans ) ; ans := Sequence{} ; for i : Integer.subrange(0, l-1) do ( execute (((Sequence{tmp[i+1] + inp[i+1]}->union(Sequence{ tmp[i + 1+1] + inp[i+1] }))->max()) : ans))) catch (_e : OclException) do ( break) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : string1=input("Enter the first string: ") print(string1,end="\n") string2=input("Enter the second string: ") print(string2,end="\n") print("Are both strings same: ",end=" ") if(string1==string2): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var string1 : String := (OclFile["System.in"]).readLine("Enter the first string: ") ; execute (string1)->display() ; var string2 : String := (OclFile["System.in"]).readLine("Enter the second string: ") ; execute (string2)->display() ; execute ("Are both strings same: ")->display() ; if (string1 = string2) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(data): increasing=True prev_line=data[0] for curr_line in data[1 :]: if len(curr_line)first() ; for curr_line : data->tail() do ( if ((curr_line)->size()->compareTo((prev_line)->size())) < 0 then ( increasing := false ) else skip ; for _tuple : Integer.subrange(1, (curr_line)->size())->collect( _indx | Sequence{_indx-1, (curr_line)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var ele : OclAny := _tuple->at(_indx); if increasing then ( try ( var up_left : OclAny := prev_line[Set{0, i - 1}->max()+1]) catch (_e : OclException) do ( up_left := 0) ; try ( var up_right : OclAny := prev_line[i+1]) catch (_e : OclException) do ( up_right := 0) ; curr_line[i+1] := curr_line[i+1] + Set{up_left, up_right}->max() ) else ( curr_line[i+1] := curr_line[i+1] + Set{prev_line[i+1], prev_line[i + 1+1]}->max() )) ; prev_line := curr_line) ; return data->last()->first(); operation main(args : OclAny) pre: true post: true activity: data := Sequence{} ; for line : OclFile["System.in"] do ( execute ((line.split(',')->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) : data)) ; var result : OclAny := solve(data) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- g=[[]for _ in xrange(100)] i=-1 while 1 : i+=1 try : g[i]=map(int,raw_input().split(",")) except : dp=[[0]*101 for _ in xrange(101)] dp[0][0]=g[0][0] for j in xrange(1,i): for k in xrange(len(g[j])): if j<=i/2 : dp[j][k]=max(dp[j-1][k-1],dp[j-1][k])+g[j][k] else : dp[j][k]=max(dp[j-1][k],dp[j-1][k+1])+g[j][k] print(dp[i-1][0]) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var g : Sequence := xrange(100)->select(_anon | true)->collect(_anon | (Sequence{})) ; var i : int := -1 ; while 1 do ( i := i + 1 ; try ( g[i+1] := (raw_input().split(","))->collect( _x | (OclType["int"])->apply(_x) )) catch (_e : OclException) do ( var dp : Sequence := xrange(101)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 101))) ; dp->first()->first() := g->first()->first() ; for j : xrange(1, i) do ( for k : xrange((g[j+1])->size()) do ( if (j->compareTo(i / 2)) <= 0 then ( dp[j+1][k+1] := Set{dp[j - 1+1][k - 1+1], dp[j - 1+1][k+1]}->max() + g[j+1][k+1] ) else ( dp[j+1][k+1] := Set{dp[j - 1+1][k+1], dp[j - 1+1][k + 1+1]}->max() + g[j+1][k+1] ))) ; execute (dp[i - 1+1]->first())->display() ; break) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mp=[] while True : try : lst=list(map(int,input().split(","))) mp.append(lst) except EOFError : break half=len(mp)//2 for i in range(1,len(mp)): for j in range(len(mp[i])): if i<=half : if j!=0 and j!=len(mp[i])-1 : mp[i][j]=max(mp[i-1][j],mp[i-1][j-1])+mp[i][j] elif j==0 : mp[i][j]=mp[i-1][j]+mp[i][j] else : mp[i][j]=mp[i-1][j-1]+mp[i][j] else : mp[i][j]=max(mp[i-1][j],mp[i-1][j+1])+mp[i][j] print(mp[-1][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mp : Sequence := Sequence{} ; while true do ( try ( var lst : Sequence := ((input().split(","))->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((lst) : mp)) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))) ; var half : int := (mp)->size() div 2 ; for i : Integer.subrange(1, (mp)->size()-1) do ( for j : Integer.subrange(0, (mp[i+1])->size()-1) do ( if (i->compareTo(half)) <= 0 then ( if j /= 0 & j /= (mp[i+1])->size() - 1 then ( mp[i+1][j+1] := Set{mp[i - 1+1][j+1], mp[i - 1+1][j - 1+1]}->max() + mp[i+1][j+1] ) else (if j = 0 then ( mp[i+1][j+1] := mp[i - 1+1][j+1] + mp[i+1][j+1] ) else ( mp[i+1][j+1] := mp[i - 1+1][j - 1+1] + mp[i+1][j+1] ) ) ) else ( mp[i+1][j+1] := Set{mp[i - 1+1][j+1], mp[i - 1+1][j + 1+1]}->max() + mp[i+1][j+1] ))) ; execute (mp->last()->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printKPFNums(A,B,K): prime=[True]*(B+1) p_factors=[0]*(B+1) for p in range(2,B+1): if(p_factors[p]==0): for i in range(p,B+1,p): p_factors[i]=p_factors[i]+1 for i in range(A,B+1): if(p_factors[i]==K): print(i,end=" ") A=14 B=18 K=2 printKPFNums(A,B,K) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; A := 14 ; B := 18 ; K := 2 ; printKPFNums(A, B, K); operation printKPFNums(A : OclAny, B : OclAny, K : OclAny) pre: true post: true activity: var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (B + 1)) ; var p_factors : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (B + 1)) ; for p : Integer.subrange(2, B + 1-1) do ( if (p_factors[p+1] = 0) then ( for i : Integer.subrange(p, B + 1-1)->select( $x | ($x - p) mod p = 0 ) do ( p_factors[i+1] := p_factors[i+1] + 1) ) else skip) ; for i : Integer.subrange(A, B + 1-1) do ( if (p_factors[i+1] = K) then ( execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairs(arr,n): odd=0 even=0 for i in range(n): if(arr[i]% 2==0): even+=1 else : odd+=1 odd_pairs=odd*(n-1) even_pairs=even*(n-1) print(odd_pairs) print(even_pairs) if __name__=='__main__' : arr=[2,3,4,5] n=len(arr) countPairs(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 }))) ; n := (arr)->size() ; countPairs(arr, n) ) else skip; operation countPairs(arr : OclAny, n : OclAny) pre: true post: true activity: var odd : int := 0 ; var even : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] mod 2 = 0) then ( even := even + 1 ) else ( odd := odd + 1 )) ; var odd_pairs : double := odd * (n - 1) ; var even_pairs : double := even * (n - 1) ; execute (odd_pairs)->display() ; execute (even_pairs)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h=int(input()) for x in range(h): a,b=map(int,input().split()) n,m=map(int,input().split()) s=min(m,b) m-=s b-=s while a % 10==0 : b+=1 a=a//10 while n % 10==0 : m+=1 n=n//10 h=str(a) k=str(n) if len(h)+b>len(k)+m : print('>') elif len(h)+bk : print('>') elif h')->display() ) else (if ((h)->size() + b->compareTo((k)->size() + m)) < 0 then ( execute ('<')->display() ) else ( if h > k then ( execute ('>')->display() ) else (if h < k then ( execute ('<')->display() ) else ( execute ('=')->display() ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import sys debug=True if debug and os.path.exists("input.in"): input=open("input.in","r").readline else : debug=False input=sys.stdin.readline def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s=input() return s[: len(s)-1] def invr(): return(map(int,input().split())) test_count=inp() for t in range(test_count): if debug : print("Test Case #",t+1) x1,p1=invr() x2,p2=invr() x1=str(x1) x2=str(x2) if len(x1)+p1>len(x2)+p2 : print(">") elif len(x1)+p1x2 : print(">") elif x2>x1 : print("<") else : print("=") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var debug : boolean := true ; if debug & os.path.exists("input.in") then ( var input : OclAny := open("input.in", "r").readline ) else ( debug := false ; input := (OclFile["System.in"]).readline ) ; skip ; skip ; skip ; skip ; var test_count : OclAny := inp() ; for t : Integer.subrange(0, test_count-1) do ( if debug then ( execute ("Test Case #")->display() ) else skip ; var x1 : OclAny := null; var p1 : OclAny := null; Sequence{x1,p1} := invr() ; var x2 : OclAny := null; var p2 : OclAny := null; Sequence{x2,p2} := invr() ; var x1 : String := ("" + ((x1))) ; var x2 : String := ("" + ((x2))) ; if ((x1)->size() + p1->compareTo((x2)->size() + p2)) > 0 then ( execute (">")->display() ) else (if ((x1)->size() + p1->compareTo((x2)->size() + p2)) < 0 then ( execute ("<")->display() ) else ( x1 := x1 + StringLib.nCopies("0", Set{0, Set{(x2)->size(), (x1)->size()}->max() - (x1)->size()}->max()) ; x2 := x2 + StringLib.nCopies("0", Set{0, Set{(x2)->size(), (x1)->size()}->max() - (x2)->size()}->max()) ; if x1 > x2 then ( execute (">")->display() ) else (if x2 > x1 then ( execute ("<")->display() ) else ( execute ("=")->display() ) ) ) ) ); operation inp() : OclAny pre: true post: true activity: return (("" + (((OclFile["System.in"]).readLine())))->toInteger()); operation inlt() : OclAny pre: true post: true activity: return (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))); operation insr() : OclAny pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; return s.subrange(1,(s)->size() - 1); operation invr() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for x in range(n): x1,p1=map(int,input().split()) x2,p2=map(int,input().split()) while x1 % 10==0 : p1+=1 x1//=10 while x2 % 10==0 : p2+=1 x2//=10 s=min(p1,p2) p1-=s p2-=s x11=str(x1) x22=str(x2) if len(x11)+p1>len(x22)+p2 : print('>') elif len(x11)+p1x22 : print('>') elif x11')->display() ) else (if ((x11)->size() + p1->compareTo((x22)->size() + p2)) < 0 then ( execute ('<')->display() ) else ( if x11 > x22 then ( execute ('>')->display() ) else (if x11 < x22 then ( execute ('<')->display() ) else ( execute ('=')->display() ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for x in range(t): x1,p1=map(int,input().split()) x2,p2=map(int,input().split()) while x1 % 10==0 : x1//=10 p1+=1 while x2 % 10==0 : x2//=10 p2+=1 x11=str(x1) x22=str(x2) m=min(p1,p2) p1-=m p2-=m if len(x11)+p1len(x22)+p2 : print('>') else : if x11>x22 : print('>') elif x11display() ) else (if ((x11)->size() + p1->compareTo((x22)->size() + p2)) > 0 then ( execute ('>')->display() ) else ( if x11 > x22 then ( execute ('>')->display() ) else (if x11 < x22 then ( execute ('<')->display() ) else ( execute ('=')->display() ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numbers=list(map(int,input().split())) columns=numbers[0] rows=numbers[1] counter=-1 data={} stop=0 for i in range(0,columns): x=input() g="not" s='not' count=0 for j in range(0,rows): if x[j]=="S" : if g=="found" : counter=count+1 ; if not f"{counter}" in data : data[f"{counter}"]=1 else : stop=1 break elif x[j]=='G' : g='found' count=0 else : count+=1 print(-1 if len(data)==0 or stop==1 else len(data)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var numbers : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var columns : OclAny := numbers->first() ; var rows : OclAny := numbers[1+1] ; var counter : int := -1 ; var data : OclAny := Set{} ; var stop : int := 0 ; for i : Integer.subrange(0, columns-1) do ( var x : String := (OclFile["System.in"]).readLine() ; var g : String := "not" ; var s : String := 'not' ; var count : int := 0 ; for j : Integer.subrange(0, rows-1) do ( if x[j+1] = "S" then ( if g = "found" then ( counter := count + 1; ; if not((data)->includes(StringLib.formattedString("{counter}"))) then ( data[StringLib.formattedString("{counter}")+1] := 1 ) else skip ) else ( stop := 1 ) ; break ) else (if x[j+1] = 'G' then ( g := 'found' ; count := 0 ) else ( count := count + 1 ) ) )) ; execute (if (data)->size() = 0 or stop = 1 then -1 else (data)->size() endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def getPrime(arr,n): max_val=arr[0] for i in range(len(arr)): if(arr[i]>max_val): max_val=arr[i] prime=[True for i in range(max_val+1)] prime[0]=False prime[1]=False for p in range(2,int(sqrt(max_val))+1,1): if(prime[p]==True): for i in range(p*2,max_val+1,p): prime[i]=False maximum=-1 for i in range(n): if(prime[arr[i]]): maximum=max(maximum,arr[i]) return maximum if __name__=='__main__' : arr=[2,10,15,7,6,8,13] n=len(arr) print(getPrime(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{2}->union(Sequence{10}->union(Sequence{15}->union(Sequence{7}->union(Sequence{6}->union(Sequence{8}->union(Sequence{ 13 })))))) ; n := (arr)->size() ; execute (getPrime(arr, n))->display() ) else skip; operation getPrime(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var max_val : OclAny := arr->first() ; for i : Integer.subrange(0, (arr)->size()-1) do ( if ((arr[i+1]->compareTo(max_val)) > 0) then ( max_val := arr[i+1] ) else skip) ; var prime : Sequence := Integer.subrange(0, max_val + 1-1)->select(i | true)->collect(i | (true)) ; prime->first() := false ; prime[1+1] := false ; for p : Integer.subrange(2, ("" + ((sqrt(max_val))))->toInteger() + 1-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (prime[p+1] = true) then ( for i : Integer.subrange(p * 2, max_val + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip) ; var maximum : int := -1 ; for i : Integer.subrange(0, n-1) do ( if (prime[arr[i+1]+1]) then ( maximum := Set{maximum, arr[i+1]}->max() ) else skip) ; return maximum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- row_count,column_count=map(int,input().split()) matrix=[list(input())for _ in range(row_count)] print(-1)if any([r.index("G")>r.index("S")for r in matrix])else print(len(set([rr.index("S")-rr.index("G")for rr in matrix]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var row_count : OclAny := null; var column_count : OclAny := null; Sequence{row_count,column_count} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var matrix : Sequence := Integer.subrange(0, row_count-1)->select(_anon | true)->collect(_anon | (((OclFile["System.in"]).readLine())->characters())) ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))) if (logical_test (comparison (expr (atom (name any)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name r)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "G"))))))) ))))) > (comparison (expr (atom (name r)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "S"))))))) )))))))) (comp_for for (exprlist (expr (atom (name r)))) in (logical_test (comparison (expr (atom (name matrix))))))) ]))))))) )))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name rr)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "S"))))))) )))) - (expr (atom (name rr)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "G"))))))) )))))))) (comp_for for (exprlist (expr (atom (name rr)))) in (logical_test (comparison (expr (atom (name matrix))))))) ]))))))) ))))))))) ))))))))) )))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) c=set(s.find("S")-s.find("G")for s in(input()for _ in range(n))) print(-1 if any(a<0 for a in c)else len(c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : Set := Set{}->union(((argument (test (logical_test (comparison (expr (expr (atom (name s)) (trailer . (name find) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "S"))))))) )))) - (expr (atom (name s)) (trailer . (name find) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "G"))))))) )))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) ))))))))) ; execute (if ((argument (test (logical_test (comparison (comparison (expr (atom (name a)))) < (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name c))))))))->exists( _x | _x = true ) then -1 else (c)->size() endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- row_count,column_count=map(int,input().split()) matrix=[input()for _ in range(row_count)] print(-1)if any([r.find("G")>r.find("S")for r in matrix])else print(len(set([rr.find("S")-rr.find("G")for rr in matrix]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var row_count : OclAny := null; var column_count : OclAny := null; Sequence{row_count,column_count} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var matrix : Sequence := Integer.subrange(0, row_count-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))) if (logical_test (comparison (expr (atom (name any)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name r)) (trailer . (name find) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "G"))))))) ))))) > (comparison (expr (atom (name r)) (trailer . (name find) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "S"))))))) )))))))) (comp_for for (exprlist (expr (atom (name r)))) in (logical_test (comparison (expr (atom (name matrix))))))) ]))))))) )))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name rr)) (trailer . (name find) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "S"))))))) )))) - (expr (atom (name rr)) (trailer . (name find) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "G"))))))) )))))))) (comp_for for (exprlist (expr (atom (name rr)))) in (logical_test (comparison (expr (atom (name matrix))))))) ]))))))) ))))))))) ))))))))) )))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- row_count,column_count=map(int,input().split()) matrix=[input()for _ in range(row_count)] print(-1)if any([r.index("G")>r.index("S")for r in matrix])else print(len(set([rr.index("S")-rr.index("G")for rr in matrix]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var row_count : OclAny := null; var column_count : OclAny := null; Sequence{row_count,column_count} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var matrix : Sequence := Integer.subrange(0, row_count-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))) if (logical_test (comparison (expr (atom (name any)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name r)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "G"))))))) ))))) > (comparison (expr (atom (name r)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "S"))))))) )))))))) (comp_for for (exprlist (expr (atom (name r)))) in (logical_test (comparison (expr (atom (name matrix))))))) ]))))))) )))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name rr)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "S"))))))) )))) - (expr (atom (name rr)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "G"))))))) )))))))) (comp_for for (exprlist (expr (atom (name rr)))) in (logical_test (comparison (expr (atom (name matrix))))))) ]))))))) ))))))))) ))))))))) )))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reverserWords(string): st=list() for i in range(len(string)): if string[i]!="" : st.append(string[i]) else : while len(st)>0 : print(st[-1],end="") st.pop() print(end="") while len(st)>0 : print(st[-1],end="") st.pop() if __name__=="__main__" : string="Geeks for Geeks" reverserWords(string) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( string := "Geeks for Geeks" ; reverserWords(string) ) else skip; operation reverserWords(string : OclAny) pre: true post: true activity: var st : Sequence := () ; for i : Integer.subrange(0, (string)->size()-1) do ( if string[i+1] /= "" then ( execute ((string[i+1]) : st) ) else ( while (st)->size() > 0 do ( execute (st->last())->display() ; st := st->front()) ; execute ((argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom "")))))))->display() )) ; while (st)->size() > 0 do ( execute (st->last())->display() ; st := st->front()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def search(arr,n,x): front=0 ; back=n-1 while(front<=back): if(arr[front]==x or arr[back]==x): return True front+=1 back-=1 return False arr=[10,20,80,30,60,50,110,100,130,170] x=130 n=len(arr) if(search(arr,n,x)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{10}->union(Sequence{20}->union(Sequence{80}->union(Sequence{30}->union(Sequence{60}->union(Sequence{50}->union(Sequence{110}->union(Sequence{100}->union(Sequence{130}->union(Sequence{ 170 }))))))))) ; x := 130 ; n := (arr)->size() ; if (search(arr, n, x)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation search(arr : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: var front : int := 0; var back : double := n - 1 ; while ((front->compareTo(back)) <= 0) do ( if (arr[front+1] = x or arr[back+1] = x) then ( return true ) else skip ; front := front + 1 ; back := back - 1) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countFreq(arr,n): mp={} for i in range(n): if arr[i]not in mp : mp[arr[i]]=0 mp[arr[i]]+=1 for i in range(n): if(mp[arr[i]]!=-1): print(arr[i],mp[arr[i]]) mp[arr[i]]=-1 arr=[10,20,20,10,10,20,5,20] n=len(arr) countFreq(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{10}->union(Sequence{20}->union(Sequence{20}->union(Sequence{10}->union(Sequence{10}->union(Sequence{20}->union(Sequence{5}->union(Sequence{ 20 }))))))) ; n := (arr)->size() ; countFreq(arr, n); operation countFreq(arr : OclAny, n : OclAny) pre: true post: true activity: var mp : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( if (mp)->excludes(arr[i+1]) then ( mp[arr[i+1]+1] := 0 ) else skip ; mp[arr[i+1]+1] := mp[arr[i+1]+1] + 1) ; for i : Integer.subrange(0, n-1) do ( if (mp[arr[i+1]+1] /= -1) then ( execute (arr[i+1])->display() ) else skip ; mp[arr[i+1]+1] := -1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(H : int,W : int,N : int,a : "List[int]"): S=[] for i,n in enumerate(a): j=i+1 S.extend([j]*n) for h in range(H): row=S[h*W : h*W+W] if h % 2==0 : print(' '.join(map(str,row))) else : print(' '.join(map(str,row[: :-1]))) return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() H=int(next(tokens)) W=int(next(tokens)) N=int(next(tokens)) a=[int(next(tokens))for _ in range(N)] solve(H,W,N,a) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(H : int, W : int, N : int, a : "List[int]") pre: true post: true activity: var S : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var n : OclAny := _tuple->at(_indx); var j : OclAny := i + 1 ; S := S->union(MatrixLib.elementwiseMult(Sequence{ j }, n))) ; for h : Integer.subrange(0, H-1) do ( var row : OclAny := S.subrange(h * W+1, h * W + W) ; if h mod 2 = 0 then ( execute (StringLib.sumStringsWithSeparator(((row)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ) else ( execute (StringLib.sumStringsWithSeparator(((row(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() )) ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var H : int := ("" + (((tokens).next())))->toInteger() ; var W : int := ("" + (((tokens).next())))->toInteger() ; var N : int := ("" + (((tokens).next())))->toInteger() ; var a : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((tokens).next())))->toInteger())) ; solve(H, W, N, a); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W=map(int,input().split()) N=int(input()) A=list(map(int,input().split())) ans=[[-1 for _ in range(W)]for _ in range(H)] ptr=0 def draw_color(): global ans,ptr if A[ptr]>0 : A[ptr]-=1 return ptr+1 ptr+=1 return draw_color() for h in range(H): if h % 2==0 : for w in range(W): ans[h][w]=draw_color() else : for w in reversed(range(W)): ans[h][w]=draw_color() for h in range(H): print(*ans[h]) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute ans : OclAny; attribute ptr : OclAny; operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, W-1)->select(_anon | true)->collect(_anon | (-1)))) ; var ptr : int := 0 ; skip ; for h : Integer.subrange(0, H-1) do ( if h mod 2 = 0 then ( for w : Integer.subrange(0, W-1) do ( ans[h+1][w+1] := draw_color()) ) else ( for w : (Integer.subrange(0, W-1))->reverse() do ( ans[h+1][w+1] := draw_color()) )) ; for h : Integer.subrange(0, H-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name h)))))))) ]))))))))->display()); operation draw_color() : OclAny pre: true post: true activity: skip; skip ; if A[ptr+1] > 0 then ( A[ptr+1] := A[ptr+1] - 1 ; return ptr + 1 ) else skip ; ptr := ptr + 1 ; return draw_color(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w=map(int,input().split()) n=int(input()) arr=list(map(int,input().split())) ans=[[0]*w for _ in range(h)] hpos=0 wpos=0 apos=0 cnt=0 while 1 : while cntcollect( _x | (OclType["int"])->apply(_x) ) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, w))) ; var hpos : int := 0 ; var wpos : int := 0 ; var apos : int := 0 ; var cnt : int := 0 ; while 1 do ( while (cnt->compareTo(arr[apos+1])) < 0 do ( ans[hpos+1][wpos+1] := apos + 1 ; if hpos mod 2 = 0 then ( wpos := wpos + 1 ; if wpos = w then ( hpos := hpos + 1 ; wpos := w - 1 ) else skip ) else ( wpos := wpos - 1 ; if wpos = -1 then ( hpos := hpos + 1 ; wpos := 0 ) else skip ) ; cnt := cnt + 1) ; cnt := 0 ; apos := apos + 1 ; if hpos = h then ( break ) else skip) ; for i : Integer.subrange(0, h-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def pairCount(arr,n): max_val=arr[0] for i in range(len(arr)): if(arr[i]>max_val): max_val=arr[i] prime=[True for i in range(max_val+1)] prime[0]=False prime[1]=False k=int(sqrt(max_val))+1 for p in range(2,k,1): if(prime[p]==True): for i in range(p*2,max_val+1,p): prime[i]=False count=0 for i in range(0,n,1): if(prime[arr[i]]): count+=1 return(count*(count-1))/2 if __name__=='__main__' : arr=[1,2,3,4,5,6,7] n=len(arr) print(int(pairCount(arr,n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 7 })))))) ; n := (arr)->size() ; execute (("" + ((pairCount(arr, n))))->toInteger())->display() ) else skip; operation pairCount(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var max_val : OclAny := arr->first() ; for i : Integer.subrange(0, (arr)->size()-1) do ( if ((arr[i+1]->compareTo(max_val)) > 0) then ( max_val := arr[i+1] ) else skip) ; var prime : Sequence := Integer.subrange(0, max_val + 1-1)->select(i | true)->collect(i | (true)) ; prime->first() := false ; prime[1+1] := false ; var k : int := ("" + ((sqrt(max_val))))->toInteger() + 1 ; for p : Integer.subrange(2, k-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (prime[p+1] = true) then ( for i : Integer.subrange(p * 2, max_val + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip) ; var count : int := 0 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (prime[arr[i+1]+1]) then ( count := count + 1 ) else skip) ; return (count * (count - 1)) / 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin inf=1<<60 mod=1000000007 ni=lambda : int(ns()) nin=lambda y :[ni()for _ in range(y)] na=lambda : list(map(int,stdin.readline().split())) nan=lambda y :[na()for _ in range(y)] nf=lambda : float(ns()) nfn=lambda y :[nf()for _ in range(y)] nfa=lambda : list(map(float,stdin.readline().split())) nfan=lambda y :[nfa()for _ in range(y)] ns=lambda : stdin.readline().rstrip() nsn=lambda y :[ns()for _ in range(y)] ncl=lambda y :[list(ns())for _ in range(y)] nas=lambda : stdin.readline().split() h,w=na() n=ni() a=na() ans=[[0]*w for _ in range(h)] cur=0 for i in range(h): if i % 2==0 : for j in range(w): ans[i][j]=cur+1 a[cur]-=1 if a[cur]==0 : cur+=1 else : for j in range(w-1,-1,-1): ans[i][j]=cur+1 a[cur]-=1 if a[cur]==0 : cur+=1 for i in range(h): print(*ans[i],sep=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stdin : OclFile := OclFile["System.in"] ; var Math_PINFINITY : int := 1 * (2->pow(60)) ; var mod : int := 1000000007 ; var ni : Function := lambda $$ : OclAny in (("" + ((ns())))->toInteger()) ; var nin : Function := lambda y : OclAny in (Integer.subrange(0, y-1)->select(_anon | true)->collect(_anon | (ni->apply()))) ; var na : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var Math_NaN : Function := lambda y : OclAny in (Integer.subrange(0, y-1)->select(_anon | true)->collect(_anon | (na->apply()))) ; var nf : Function := lambda $$ : OclAny in (("" + ((ns())))->toReal()) ; var nfn : Function := lambda y : OclAny in (Integer.subrange(0, y-1)->select(_anon | true)->collect(_anon | (nf->apply()))) ; var nfa : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ))) ; var nfan : Function := lambda y : OclAny in (Integer.subrange(0, y-1)->select(_anon | true)->collect(_anon | (nfa->apply()))) ; var ns : Function := lambda $$ : OclAny in (stdin.readLine().rstrip()) ; var nsn : Function := lambda y : OclAny in (Integer.subrange(0, y-1)->select(_anon | true)->collect(_anon | (ns->apply()))) ; var ncl : Function := lambda y : OclAny in (Integer.subrange(0, y-1)->select(_anon | true)->collect(_anon | ((ns->apply())))) ; var nas : Function := lambda $$ : OclAny in (stdin.readLine().split()) ; var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := na->apply() ; var n : OclAny := ni->apply() ; var a : OclAny := na->apply() ; var ans : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, w))) ; var cur : int := 0 ; for i : Integer.subrange(0, h-1) do ( if i mod 2 = 0 then ( for j : Integer.subrange(0, w-1) do ( ans[i+1][j+1] := cur + 1 ; a[cur+1] := a[cur+1] - 1 ; if a[cur+1] = 0 then ( cur := cur + 1 ) else skip) ) else ( for j : Integer.subrange(-1 + 1, w - 1)->reverse() do ( ans[i+1][j+1] := cur + 1 ; a[cur+1] := a[cur+1] - 1 ; if a[cur+1] = 0 then ( cur := cur + 1 ) else skip) )) ; for i : Integer.subrange(0, h-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): h,w=map(int,input().split()) n=int(input()) a=list(map(int,input().split())) c=[[0 for i in range(w)]for i in range(h)] p=[0,0] up=1 for i in range(n): cnt=0 while cnt0 : p[1]-=1 elif up==0 and p[1]==0 : p[1]=0 p[0]+=1 up=1 for i in range(h): print(' '.join([str(x)for x in c[i]])) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : Sequence := Integer.subrange(0, h-1)->select(i | true)->collect(i | (Integer.subrange(0, w-1)->select(i | true)->collect(i | (0)))) ; var p : Sequence := Sequence{0}->union(Sequence{ 0 }) ; var up : int := 1 ; for i : Integer.subrange(0, n-1) do ( var cnt : int := 0 ; while (cnt->compareTo(a[i+1])) < 0 do ( c[p->first()+1][p[1+1]+1] := i + 1 ; cnt := cnt + 1 ; if up = 1 & (p[1+1]->compareTo(w - 1)) < 0 then ( p[1+1] := p[1+1] + 1 ) else (if up = 1 & p[1+1] = w - 1 then ( p[1+1] := w - 1 ; p->first() := p->first() + 1 ; up := 0 ) else (if up = 0 & p[1+1] > 0 then ( p[1+1] := p[1+1] - 1 ) else (if up = 0 & p[1+1] = 0 then ( p[1+1] := 0 ; p->first() := p->first() + 1 ; up := 1 ) else skip ) ) ) )) ; for i : Integer.subrange(0, h-1) do ( execute (StringLib.sumStringsWithSeparator((c[i+1]->select(x | true)->collect(x | (("" + ((x)))))), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def MinCostTree(arr,n): ans=0 st=[2**32] for i in range(n): while(st[-1]<=arr[i]): x=st[-1] st.pop() ans+=x*min(st[-1],arr[i]) st.append(arr[i]) for i in range(2,len(st)): ans+=st[i]*st[i-1] return ans arr=[5,2,3] n=len(arr) print(MinCostTree(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{5}->union(Sequence{2}->union(Sequence{ 3 })) ; n := (arr)->size() ; execute (MinCostTree(arr, n))->display(); operation MinCostTree(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; var st : Sequence := Sequence{ (2)->pow(32) } ; for i : Integer.subrange(0, n-1) do ( while ((st->last()->compareTo(arr[i+1])) <= 0) do ( var x : OclAny := st->last() ; st := st->front() ; ans := ans + x * Set{st->last(), arr[i+1]}->min()) ; execute ((arr[i+1]) : st)) ; for i : Integer.subrange(2, (st)->size()-1) do ( ans := ans + st[i+1] * st[i - 1+1]) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=list(str(input())) t=list(str(input())) dic_s={} dic_t={} for i in range(97,97+26): dic_s[chr(i)]=0 dic_t[chr(i)]=0 for i in range(n): dic_s[s[i]]+=1 dic_t[t[i]]+=1 if dic_s!=dic_t : print(-1) else : c=[] for i in range(n): while True : if s[i]==t[i]: break target=i+s[i :].index(t[i]) c.append(target-1) s[target-1],s[target]=s[target],s[target-1] c=[el+1 for el in c] print(len(c)) for el in c : print(el,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := (("" + (((OclFile["System.in"]).readLine()))))->characters() ; var t : Sequence := (("" + (((OclFile["System.in"]).readLine()))))->characters() ; var dic_s : OclAny := Set{} ; var dic_t : OclAny := Set{} ; for i : Integer.subrange(97, 97 + 26-1) do ( dic_s[(i)->byte2char()+1] := 0 ; dic_t[(i)->byte2char()+1] := 0) ; for i : Integer.subrange(0, n-1) do ( dic_s[s[i+1]+1] := dic_s[s[i+1]+1] + 1 ; dic_t[t[i+1]+1] := dic_t[t[i+1]+1] + 1) ; if dic_s /= dic_t then ( execute (-1)->display() ) else ( var c : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( while true do ( if s[i+1] = t[i+1] then ( break ) else skip ; var target : OclAny := i + s.subrange(i+1)->indexOf(t[i+1]) - 1 ; execute ((target - 1) : c) ; var s[target - 1+1] : OclAny := null; var s[target+1] : OclAny := null; Sequence{s[target - 1+1],s[target+1]} := Sequence{s[target+1],s[target - 1+1]})) ; c := c->select(el | true)->collect(el | (el + 1)) ; execute ((c)->size())->display() ; for el : c do ( execute (el)->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import* n=int(input()) s=list(input()) t=list(input()) a,b=Counter(s),Counter(t) if(a!=b): print(-1) else : l=[] for i in range(n): if(s[i]!=t[i]): f=-1 for j in range(i+1,n): if(s[j]==t[i]): f=j break for k in range(f,i,-1): l.append(k) s[k],s[k-1]=s[k-1],s[k] print(len(l)) print(*l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var t : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{Counter(s),Counter(t)} ; if (a /= b) then ( execute (-1)->display() ) else ( var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if (s[i+1] /= t[i+1]) then ( var f : int := -1 ; for j : Integer.subrange(i + 1, n-1) do ( if (s[j+1] = t[i+1]) then ( f := j ; break ) else skip) ; for k : Integer.subrange(i + 1, f)->reverse() do ( execute ((k) : l) ; var s[k+1] : OclAny := null; var s[k - 1+1] : OclAny := null; Sequence{s[k+1],s[k - 1+1]} := Sequence{s[k - 1+1],s[k+1]}) ) else skip) ; execute ((l)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name l))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() a=b=0 for x,y in zip(input(),input()): a+=x>y b+=xsize())->collect( _indx | Sequence{(OclFile["System.in"]).readLine()->at(_indx), (OclFile["System.in"]).readLine()->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); a := a + (x->compareTo(y)) > 0 ; b := b + (x->compareTo(y)) < 0) ; execute (if a = 0 then -1 else b div a + 1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from collections import Counter m=1 def solve(): n=int(input()) s=input().strip() t=input().strip() a=Counter(t) b=Counter(s) s=list(s) t=list(t) if a!=b : print(-1) else : i=0 li=[] while itoInteger() ; var s : OclAny := input()->trim() ; var t : OclAny := input()->trim() ; var a : OclAny := Counter(t) ; var b : OclAny := Counter(s) ; s := (s) ; t := (t) ; if a /= b then ( execute (-1)->display() ) else ( var i : int := 0 ; var li : Sequence := Sequence{} ; while (i->compareTo(n)) < 0 do ( if s[i+1] = t[i+1] then ( i := i + 1 ; continue ) else skip ; var j : int := i ; while s[j+1] /= t[i+1] do ( j := j + 1) ; while j /= i do ( var s[j - 1+1] : OclAny := null; var s[j+1] : OclAny := null; Sequence{s[j - 1+1],s[j+1]} := Sequence{s[j+1],s[j - 1+1]} ; execute ((j) : li) ; j := j - 1) ; i := i + 1) ; execute ((li)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name li))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline def answer(): ans=[] for i in range(n): yes=False for j in range(i,n): if(s[j]==t[i]): for k in range(j,i,-1): ans.append(k) s[k-1],s[k]=s[k],s[k-1] yes=True break if(not yes): print(-1) return print(len(ans)) print(*ans) for T in range(1): n=int(input()) s=list(input()) t=input().strip() answer() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; skip ; for T : Integer.subrange(0, 1-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var t : OclAny := input()->trim() ; answer()); operation answer() pre: true post: true activity: var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var yes : boolean := false ; for j : Integer.subrange(i, n-1) do ( if (s[j+1] = t[i+1]) then ( for k : Integer.subrange(i + 1, j)->reverse() do ( execute ((k) : ans) ; var s[k - 1+1] : OclAny := null; var s[k+1] : OclAny := null; Sequence{s[k - 1+1],s[k+1]} := Sequence{s[k+1],s[k - 1+1]}) ; yes := true ; break ) else skip) ; if (not(yes)) then ( execute (-1)->display() ; return ) else skip) ; execute ((ans)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findEquation(a,b): summ=(a+b) product=(a*b) print("x^2-(",summ,"x)+(",product,")=0") a=2 b=3 findEquation(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 2 ; b := 3 ; findEquation(a, b); operation findEquation(a : OclAny, b : OclAny) pre: true post: true activity: var summ : OclAny := (a + b) ; var product : double := (a * b) ; execute ("x^2-(")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def circle_equation(x1,y1,r): a=-2*x1 ; b=-2*y1 ; c=(r*r)-(x1*x1)-(y1*y1); print("x^2+(",a,"x)+",end=""); print("y^2+(",b,"y)=",end=""); print(c,"."); x1=2 ; y1=-3 ; r=8 ; circle_equation(x1,y1,r); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x1 := 2; ; y1 := -3; ; r := 8; ; circle_equation(x1, y1, r);; operation circle_equation(x1 : OclAny, y1 : OclAny, r : OclAny) pre: true post: true activity: var a : double := -2 * x1; ; var b : double := -2 * y1; ; var c : double := (r * r) - (x1 * x1) - (y1 * y1); ; execute ("x^2+(")->display(); ; execute ("y^2+(")->display(); ; execute (c)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): return str(sum(NUMBERS))[:10] NUMBERS = [371, 463, 743, 919, 230] if __name__ == "__main__": print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var NUMBERS : Sequence := Sequence{371}->union(Sequence{463}->union(Sequence{743}->union(Sequence{919}->union(Sequence{ 230 })))) ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: return OclType["String"]((NUMBERS)->sum()).subrange(1,10); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def unique_combination(l,sum,K,local,A): if(sum==K): print("{",end="") for i in range(len(local)): if(i!=0): print("",end="") print(local[i],end="") if(i!=len(local)-1): print(",",end="") print("}") return for i in range(l,len(A),1): if(sum+A[i]>K): continue if(i==1 and A[i]==A[i-1]and i>l): continue local.append(A[i]) unique_combination(i+1,sum+A[i],K,local,A) local.remove(local[len(local)-1]) def Combination(A,K): A.sort(reverse=False) local=[] unique_combination(0,0,K,local,A) if __name__=='__main__' : A=[10,1,2,7,6,1,5] K=8 Combination(A,K) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( A := Sequence{10}->union(Sequence{1}->union(Sequence{2}->union(Sequence{7}->union(Sequence{6}->union(Sequence{1}->union(Sequence{ 5 })))))) ; K := 8 ; Combination(A, K) ) else skip; operation unique_combination(l : OclAny, sum : OclAny, K : OclAny, local : OclAny, A : OclAny) pre: true post: true activity: if (sum = K) then ( execute ("{")->display() ; for i : Integer.subrange(0, (local)->size()-1) do ( if (i /= 0) then ( execute ("")->display() ) else skip ; execute (local[i+1])->display() ; if (i /= (local)->size() - 1) then ( execute (",")->display() ) else skip) ; execute ("}")->display() ; return ) else skip ; for i : Integer.subrange(l, (A)->size()-1)->select( $x | ($x - l) mod 1 = 0 ) do ( if ((sum + A[i+1]->compareTo(K)) > 0) then ( continue ) else skip ; if (i = 1 & A[i+1] = A[i - 1+1] & (i->compareTo(l)) > 0) then ( continue ) else skip ; execute ((A[i+1]) : local) ; unique_combination(i + 1, sum + A[i+1], K, local, A) ; execute ((local[(local)->size() - 1+1]) /: local)); operation Combination(A : OclAny, K : OclAny) pre: true post: true activity: A := A->sort() ; local := Sequence{} ; unique_combination(0, 0, K, local, A); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect n=int(input()) prices=sorted([int(x)for x in input().split()]) for i in range(int(input())): print(bisect.bisect_right(prices,int(input()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var prices : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))->sort() ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (bisect.bisect_right(prices, ("" + (((OclFile["System.in"]).readLine())))->toInteger()))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect as bs l=int(input()) s=sorted(list(map(int,input().split()))) for i in range(int(input())): n=int(input()) print(bs(s,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (bs(s, n))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) cost=input().split() a=0 while atoInteger() ; var cost : OclAny := input().split() ; var a : int := 0 ; while (a->compareTo((cost)->size())) < 0 do ( cost[a+1] := ("" + ((cost[a+1])))->toInteger() ; a := a + 1) ; var days : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; cost := cost->sort() ; var i : int := 0 ; while (i->compareTo(days)) < 0 do ( var shops : OclAny := null ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var left : int := 0 ; var right : double := n - 1 ; while (left->compareTo(right)) <= 0 do ( var mid : int := left + (right - left) div 2 ; if (cost[mid+1]->compareTo(t)) <= 0 then ( shops := mid ; left := mid + 1 ) else ( right := mid - 1 )) ; if shops = null then ( execute (0)->display() ) else ( execute (shops + 1)->display() ) ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) prices=[int(x)for x in input().split()] q=int(input()) highest=max(prices) match=dict.fromkeys([i for i in range(highest+1)],0) for price in prices : match[price]+=1 for i in range(1,highest+1): match[i]+=match[i-1] output=[] for i in range(q): wtp=int(input()) output.append(match[min(wtp,highest)]) print('\n'.join(map(str,output))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var prices : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var highest : OclAny := (prices)->max() ; var match : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name highest))) + (expr (atom (number (integer 1)))))))))) )))))))) ])))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))) ; for price : prices do ( match[price+1] := match[price+1] + 1) ; for i : Integer.subrange(1, highest + 1-1) do ( match[i+1] := match[i+1] + match[i - 1+1]) ; var output : Sequence := Sequence{} ; for i : Integer.subrange(0, q-1) do ( var wtp : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((match[Set{wtp, highest}->min()+1]) : output)) ; execute (StringLib.sumStringsWithSeparator(((output)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect n=int(input()) x=[int(i)for i in input().split()] x.sort() q=int(input()) for i in range(q): print(bisect.bisect(x,int(input()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; x := x->sort() ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( execute (bisect.bisect(x, ("" + (((OclFile["System.in"]).readLine())))->toInteger()))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input I() r=p=0 for x,y in zip(I(),I()): r+=x>y ; p+=xsize())->collect( _indx | Sequence{I()->at(_indx), I()->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); r := r + (x->compareTo(y)) > 0; p := p + (x->compareTo(y)) < 0) ; execute (r & p div r + 1 or -1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- z='abcdefghijklmnopqrstuvwxyz' def f(x): for i in range(1,26,2): for j in range(26): a=''.join(z[(z.index(c)*i+j)% 26]if c in z else c for c in x) if 'that' in a or 'this' in a : return a for _ in[0]*int(input()): print(f(input())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var z : String := 'abcdefghijklmnopqrstuvwxyz' ; skip ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( execute (f((OclFile["System.in"]).readLine()))->display()); operation f(x : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(1, 26-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( for j : Integer.subrange(0, 26-1) do ( var a : String := StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name z)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name z)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))) * (expr (atom (name i)))) + (expr (atom (name j)))))))) ))) % (expr (atom (number (integer 26)))))))))) ]))))) if (logical_test (comparison (comparison (expr (atom (name c)))) in (comparison (expr (atom (name z)))))) else (test (logical_test (comparison (expr (atom (name c))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name x)))))))), '') ; if (a)->characters()->includes('that') or (a)->characters()->includes('this') then ( return a ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) def GCD(a,b): if min(a,b)==0 : return max(a,b) else : return GCD(min(a,b),max(a,b)% min(a,b)) def affine(a,b,word): retval="" for w in word : retval+=chr(ord('a')+((ord(w)-ord('a'))*a+b)% 26) return retval for i in range(n): encrypted=input().split(" ") for a in range(1,27): for b in range(1,27): if GCD(a,26)!=1 : continue plain=[affine(a,b,s)for s in encrypted] if("this" in plain)or("that" in plain): print(" ".join(plain)) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; skip ; for i : Integer.subrange(0, n-1) do ( var encrypted : OclAny := input().split(" ") ; for a : Integer.subrange(1, 27-1) do ( for b : Integer.subrange(1, 27-1) do ( if GCD(a, 26) /= 1 then ( continue ) else skip ; var plain : Sequence := encrypted->select(s | true)->collect(s | (affine(a, b, s))) ; if ((plain)->includes("this")) or ((plain)->includes("that")) then ( execute (StringLib.sumStringsWithSeparator((plain), " "))->display() ; break ) else skip))); operation GCD(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if Set{a, b}->min() = 0 then ( return Set{a, b}->max() ) else ( return GCD(Set{a, b}->min(), Set{a, b}->max() mod Set{a, b}->min()) ); operation affine(a : OclAny, b : OclAny, word : OclAny) : OclAny pre: true post: true activity: var retval : String := "" ; for w : word do ( retval := retval + (('a')->char2byte() + (((w)->char2byte() - ('a')->char2byte()) * a + b) mod 26)->byte2char()) ; return retval; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A_BASE=ord('a') A=[1,3,5,7,9,11,15,17,19,21,23,25] def brute_force(len4s,dwords): b=0 for a in A : while b<26 : for word in len4s : dec=[(a*r+b)% 26 for r in word] if dec in[[19,7,8,18],[19,7,0,19]]: dec_words=[''.join([chr((a*r+b)% 26+A_BASE)for r in dw])for dw in dwords] return ' '.join(dec_words) b+=1 b=0 def solve(): n=int(input()) for _ in range(n): text=input() words=text.split() dwords=[[ord(ch)-A_BASE for ch in word]for word in words] len4s=[dw for dw in dwords if len(dw)==4] print(brute_force(len4s,dwords)) if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A_BASE : int := ('a')->char2byte() ; var A : Sequence := Sequence{1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{9}->union(Sequence{11}->union(Sequence{15}->union(Sequence{17}->union(Sequence{19}->union(Sequence{21}->union(Sequence{23}->union(Sequence{ 25 }))))))))))) ; skip ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation brute_force(len4s : OclAny, dwords : OclAny) : OclAny pre: true post: true activity: var b : int := 0 ; for a : A do ( while b < 26 do ( for word : len4s do ( var dec : Sequence := word->select(r | true)->collect(r | ((a * r + b) mod 26)) ; if (Sequence{Sequence{19}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 18 })))}->union(Sequence{ Sequence{19}->union(Sequence{7}->union(Sequence{0}->union(Sequence{ 19 }))) }))->includes(dec) then ( var dec_words : Sequence := dwords->select(dw | true)->collect(dw | (StringLib.sumStringsWithSeparator((dw->select(r | true)->collect(r | (((a * r + b) mod 26 + A_BASE)->byte2char()))), ''))) ; return StringLib.sumStringsWithSeparator((dec_words), ' ') ) else skip) ; b := b + 1) ; b := 0); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var text : String := (OclFile["System.in"]).readLine() ; var words : OclAny := text.split() ; dwords := words->select(word | true)->collect(word | (word->select(ch | true)->collect(ch | ((ch)->char2byte() - A_BASE)))) ; len4s := dwords->select(dw | (dw)->size() = 4)->collect(dw | (dw)) ; execute (brute_force(len4s, dwords))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findElements(arr,n): arr.sort() for i in range(0,n-2): print(arr[i],end=" ") arr=[2,-6,3,5,1] n=len(arr) findElements(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{-6}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 1 })))) ; n := (arr)->size() ; findElements(arr, n); operation findElements(arr : OclAny, n : OclAny) pre: true post: true activity: arr := arr->sort() ; for i : Integer.subrange(0, n - 2-1) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cv=lambda r,a,b : chr(((ord(r)-97)*a+b)% 26+97)if 97<=ord(r)<=122 else r cv2=lambda x : cv(x,i,j)if 97<=ord(x)<=122 else cv(x.lower(),i,j).upper() for _ in range(int(input())): l=input() for i in[1,3,5,7,9,11,15,17,19,21,23,25]: for j in range(1,27): s="".join(map(cv2,l)) if "this" in s or "that" in s : break if "this" in s or "that" in s : break print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cv : Function := lambda r : OclAny, a : OclAny, b : OclAny in (if 97 <= (r)->char2byte() & ((r)->char2byte() <= 122) then ((((r)->char2byte() - 97) * a + b) mod 26 + 97)->byte2char() else r endif) ; var cv2 : Function := lambda x : OclAny in (if 97 <= (x)->char2byte() & ((x)->char2byte() <= 122) then cv->apply(x, i, j) else cv->apply(x->toLowerCase(), i, j)->toUpperCase() endif) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var l : String := (OclFile["System.in"]).readLine() ; for i : Sequence{1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{9}->union(Sequence{11}->union(Sequence{15}->union(Sequence{17}->union(Sequence{19}->union(Sequence{21}->union(Sequence{23}->union(Sequence{ 25 }))))))))))) do ( for j : Integer.subrange(1, 27-1) do ( var s : String := StringLib.sumStringsWithSeparator(((l)->collect( _x | (cv2)->apply(_x) )), "") ; if (s)->characters()->includes("this") or (s)->characters()->includes("that") then ( break ) else skip) ; if (s)->characters()->includes("this") or (s)->characters()->includes("that") then ( break ) else skip) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import os import math N=int(input()) alphabet='abcdefghijklmnopqrstuvwxyz' def encode(s,alpha,beta): t=[] for c in s : if c=='' : t.append(c) else : gamma=ord(c)-97 v=(alpha*gamma+beta)% 26 w=alphabet[v] t.append(w) return ''.join(t) for i in range(N): s=input().strip() for a in range(0,26): for b in range(0,26): encoded_this=encode('this',a,b) encoded_that=encode('that',a,b) if encoded_this in s or encoded_that in s : encoded_alphabet=encode(alphabet,a,b) table=str.maketrans(encoded_alphabet,alphabet) dst=s.translate(table) print(dst) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var alphabet : String := 'abcdefghijklmnopqrstuvwxyz' ; skip ; for i : Integer.subrange(0, N-1) do ( s := input()->trim() ; for a : Integer.subrange(0, 26-1) do ( for b : Integer.subrange(0, 26-1) do ( var encoded_this : OclAny := encode('this', a, b) ; var encoded_that : OclAny := encode('that', a, b) ; if (s)->includes(encoded_this) or (s)->includes(encoded_that) then ( var encoded_alphabet : OclAny := encode(alphabet, a, b) ; var table : String := ("" + (.maketrans(encoded_alphabet, alphabet))) ; var dst : OclAny := s.translate(table) ; execute (dst)->display() ) else skip))); operation encode(s : OclAny, alpha : OclAny, beta : OclAny) : OclAny pre: true post: true activity: var t : Sequence := Sequence{} ; for c : s do ( if c = '' then ( execute ((c) : t) ) else ( var gamma : double := (c)->char2byte() - 97 ; var v : int := (alpha * gamma + beta) mod 26 ; var w : OclAny := alphabet[v+1] ; execute ((w) : t) )) ; return StringLib.sumStringsWithSeparator((t), ''); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNature(a,b,n): if(n==0): return(a & 1); if(n==1): return(b & 1); if((a & 1)==0): if((b & 1)==0): return False ; else : return True if(n % 3!=0)else False ; else : if((b & 1)==0): return True if((n-1)% 3!=0)else False ; else : return True if((n+1)% 3!=0)else False ; a=2 ; b=4 ; n=3 ; if(findNature(a,b,n)==True): print("Odd",end=" "); else : print("Even",end=" "); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 2; ; b := 4; ; n := 3; ; if (findNature(a, b, n) = true) then ( execute ("Odd")->display(); ) else ( execute ("Even")->display(); ); operation findNature(a : OclAny, b : OclAny, n : OclAny) pre: true post: true activity: if (n = 0) then ( return (MathLib.bitwiseAnd(a, 1)); ) else skip ; if (n = 1) then ( return (MathLib.bitwiseAnd(b, 1)); ) else skip ; if ((MathLib.bitwiseAnd(a, 1)) = 0) then ( if ((MathLib.bitwiseAnd(b, 1)) = 0) then ( return false; ) else ( return if (n mod 3 /= 0) then true else false endif; ) ) else ( if ((MathLib.bitwiseAnd(b, 1)) = 0) then ( return if ((n - 1) mod 3 /= 0) then true else false endif; ) else ( return if ((n + 1) mod 3 /= 0) then true else false endif; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : d,e=map(int,input().split()) if d==0 : break data=[] for i in range(0,101): for j in range(0,101): data.append((abs(((i*i+j*j)**0.5)-e),i,j)) for p in sorted(data): if p[1]+p[2]==d : print(p[0]) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var d : OclAny := null; var e : OclAny := null; Sequence{d,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if d = 0 then ( break ) else skip ; var data : Sequence := Sequence{} ; for i : Integer.subrange(0, 101-1) do ( for j : Integer.subrange(0, 101-1) do ( execute ((Sequence{((((i * i + j * j))->pow(0.5)) - e)->abs(), i, j}) : data))) ; for p : data->sort() do ( if p[1+1] + p[2+1] = d then ( execute (p->first())->display() ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import fabs,sqrt while True : D,E=map(int,input().split()) if D==0 and E==0 : break ans=10e8 for x in range(D): y=D-x dist=fabs(sqrt(x**2+y**2)-E) ans=min(ans,dist) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var D : OclAny := null; var E : OclAny := null; Sequence{D,E} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if D = 0 & E = 0 then ( break ) else skip ; var ans : double := ("10e8")->toReal() ; for x : Integer.subrange(0, D-1) do ( var y : double := D - x ; var dist : OclAny := fabs(sqrt((x)->pow(2) + (y)->pow(2)) - E) ; ans := Set{ans, dist}->min()) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] while True : d,e=LI() if d==0 : break r=inf for i in range(d//2+1): j=d-i tr=abs(e-(i**2+j**2)**0.5) if r>tr : r=tr rr.append(r) return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var d : OclAny := null; var e : OclAny := null; Sequence{d,e} := LI() ; if d = 0 then ( break ) else skip ; var r : double := Math_PINFINITY ; for i : Integer.subrange(0, d div 2 + 1-1) do ( var j : double := d - i ; var tr : double := (e - (((i)->pow(2) + (j)->pow(2)))->pow(0.5))->abs() ; if (r->compareTo(tr)) > 0 then ( r := tr ) else skip) ; execute ((r) : rr)) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def get_two_int(): two_int=input().split() for i in range(2): two_int[i]=int(two_int[i]) return two_int def get_diff_set_between_cost_and_budget(walk_distance,budget): diff_set=set() max_x=walk_distance//2+1 for x in range(max_x): y=walk_distance-x abs_diff=abs(calculate_cost(x,y)-budget) diff_set.add(abs_diff) return diff_set def calculate_cost(x,y): cost=math.sqrt((x**2)+(y**2)) return cost if __name__=="__main__" : while True : walk_distance,budget=get_two_int() if walk_distance==0 : break diff_set=get_diff_set_between_cost_and_budget(walk_distance,budget) min_num=min(diff_set) print(min_num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( while true do ( Sequence{walk_distance,budget} := get_two_int() ; if walk_distance = 0 then ( break ) else skip ; diff_set := get_diff_set_between_cost_and_budget(walk_distance, budget) ; var min_num : OclAny := (diff_set)->min() ; execute (min_num)->display()) ) else skip; operation get_two_int() : OclAny pre: true post: true activity: var two_int : OclAny := input().split() ; for i : Integer.subrange(0, 2-1) do ( two_int[i+1] := ("" + ((two_int[i+1])))->toInteger()) ; return two_int; operation get_diff_set_between_cost_and_budget(walk_distance : OclAny, budget : OclAny) : OclAny pre: true post: true activity: var diff_set : Set := Set{}->union(()) ; var max_x : int := walk_distance div 2 + 1 ; for x : Integer.subrange(0, max_x-1) do ( var y : double := walk_distance - x ; var abs_diff : double := (calculate_cost(x, y) - budget)->abs() ; execute ((abs_diff) : diff_set)) ; return diff_set; operation calculate_cost(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var cost : double := (((x)->pow(2)) + ((y)->pow(2)))->sqrt() ; return cost; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) r=list(map(int,input().split())) b=list(map(int,input().split())) c1,c2=0,0 for i,j in zip(r,b): if not i ^ j : continue if i : c1+=1 else : c2+=1 if not c1 : ans=-1 else : ans=0 while ans*c1<=c2 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c1 : OclAny := null; var c2 : OclAny := null; Sequence{c1,c2} := Sequence{0,0} ; for _tuple : Integer.subrange(1, r->size())->collect( _indx | Sequence{r->at(_indx), b->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if not(MathLib.bitwiseXor(i, j)) then ( continue ) else skip ; if i then ( c1 := c1 + 1 ) else ( c2 := c2 + 1 )) ; if not(c1) then ( var ans : int := -1 ) else ( ans := 0 ; while (ans * c1->compareTo(c2)) <= 0 do ( ans := ans + 1) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math if sys.version_info[0]>=3 : raw_input=input while True : a,b=[int(e)for e in raw_input().split()] if not a : break print(min(abs(b-math.hypot(i,a-i))for i in range(a//2+1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if (trailer . (name version_info) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) >= 3 then ( var raw_input : OclAny := input ) else skip ; while true do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := raw_input().split()->select(e | true)->collect(e | (("" + ((e)))->toInteger())) ; if not(a) then ( break ) else skip ; execute (((argument (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (name math)) (trailer . (name hypot) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (name i))))))))) )))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name a))) // (expr (atom (number (integer 2))))) + (expr (atom (number (integer 1)))))))))) )))))))))->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def max_sum(a,n): dp=[0]*n ; if(n==1): dp[0]=max(0,a[0]); elif(n==2): dp[0]=max(0,a[0]); dp[1]=max(a[1],dp[0]); elif(n>=3): dp[0]=max(0,a[0]); dp[1]=max(a[1],max(0,a[0])); dp[2]=max(a[2],max(a[1],max(0,a[0]))); i=3 ; while(iunion(Sequence{2}->union(Sequence{-2}->union(Sequence{4}->union(Sequence{ 3 })))); ; n := (arr)->size(); ; execute (max_sum(arr, n))->display(); ) else skip; operation max_sum(a : OclAny, n : OclAny) pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; if (n = 1) then ( dp->first() := Set{0, a->first()}->max(); ) else (if (n = 2) then ( dp->first() := Set{0, a->first()}->max(); ; dp[1+1] := Set{a[1+1], dp->first()}->max(); ) else (if (n >= 3) then ( dp->first() := Set{0, a->first()}->max(); ; dp[1+1] := Set{a[1+1], Set{0, a->first()}->max()}->max(); ; dp[2+1] := Set{a[2+1], Set{a[1+1], Set{0, a->first()}->max()}->max()}->max(); ; var i : int := 3; ; while ((i->compareTo(n)) < 0) do ( dp[i+1] := Set{dp[i - 1+1], a[i+1] + dp[i - 3+1]}->max(); ; i := i + 1;) ) else skip ) ) ; return dp[n - 1+1];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printDistinct(arr,n): arr.sort(); for i in range(n): if(iunion(Sequence{10}->union(Sequence{5}->union(Sequence{4}->union(Sequence{9}->union(Sequence{120}->union(Sequence{4}->union(Sequence{6}->union(Sequence{ 10 })))))))); ; n := (arr)->size(); ; printDistinct(arr, n);; operation printDistinct(arr : OclAny, n : OclAny) pre: true post: true activity: arr := arr->sort(); ; for i : Integer.subrange(0, n-1) do ( if ((i->compareTo(n - 1)) < 0 & arr[i+1] = arr[i + 1+1]) then ( while ((i->compareTo(n - 1)) < 0 & (arr[i+1] = arr[i + 1+1])) do ( i := i + 1;) ) else ( execute (arr[i+1])->display(); )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sentence=input() start,letter=-1,str() while True : if(sentence[start]!=' ')and(sentence[start]!='?'): letter=sentence[start] break start-=1 if letter.lower()in['a','e','i','o','u','y']: print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sentence : String := (OclFile["System.in"]).readLine() ; var start : OclAny := null; var letter : OclAny := null; Sequence{start,letter} := Sequence{-1,("" + (()))} ; while true do ( if (sentence[start+1] /= ' ') & (sentence[start+1] /= '?') then ( var letter : OclAny := sentence[start+1] ; break ) else skip ; start := start - 1) ; if (Sequence{'a'}->union(Sequence{'e'}->union(Sequence{'i'}->union(Sequence{'o'}->union(Sequence{'u'}->union(Sequence{ 'y' }))))))->includes(letter->toLowerCase()) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() vo=['a','e','i','o','u','y','A','E','I','O','U','Y'] for i in range(len(a)-1,-1,-1): if(a[i]==' ' or a[i]=='?'): continue else : if(a[i]in vo): print("YES") else : print("NO") break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var vo : Sequence := Sequence{'a'}->union(Sequence{'e'}->union(Sequence{'i'}->union(Sequence{'o'}->union(Sequence{'u'}->union(Sequence{'y'}->union(Sequence{'A'}->union(Sequence{'E'}->union(Sequence{'I'}->union(Sequence{'O'}->union(Sequence{'U'}->union(Sequence{ 'Y' }))))))))))) ; for i : Integer.subrange(-1 + 1, (a)->size() - 1)->reverse() do ( if (a[i+1] = ' ' or a[i+1] = '?') then ( continue ) else ( if ((vo)->includes(a[i+1])) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ; break )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def onlyletters(line): return line.replace("","") ans=input() ans=onlyletters(ans) ln=len(ans) if ans[ln-2]=='a' or ans[ln-2]=='e' or ans[ln-2]=='i' or ans[ln-2]=='o' or ans[ln-2]=='u' or ans[ln-2]=='y' or ans[ln-2]=='A' or ans[ln-2]=='Y' or ans[ln-2]=='E' or ans[ln-2]=='I' or ans[ln-2]=='O' or ans[ln-2]=='U' : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var ans : String := (OclFile["System.in"]).readLine() ; ans := onlyletters(ans) ; var ln : int := (ans)->size() ; if ans[ln - 2+1] = 'a' or ans[ln - 2+1] = 'e' or ans[ln - 2+1] = 'i' or ans[ln - 2+1] = 'o' or ans[ln - 2+1] = 'u' or ans[ln - 2+1] = 'y' or ans[ln - 2+1] = 'A' or ans[ln - 2+1] = 'Y' or ans[ln - 2+1] = 'E' or ans[ln - 2+1] = 'I' or ans[ln - 2+1] = 'O' or ans[ln - 2+1] = 'U' then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); operation onlyletters(line : OclAny) : OclAny pre: true post: true activity: return line.replace("", ""); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=['a','e','i','o','u','y'] s=input().split() s1='' for i in s : s1+=i if s1[-2].lower()in l : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := Sequence{'a'}->union(Sequence{'e'}->union(Sequence{'i'}->union(Sequence{'o'}->union(Sequence{'u'}->union(Sequence{ 'y' }))))) ; var s : OclAny := input().split() ; var s1 : String := '' ; for i : s do ( s1 := s1 + i) ; if (l)->includes(s1->front()->last()->toLowerCase()) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def vov(c): d=['A','E','I','O','U','Y','a','e','i','o','u','y'] for x in d : if(c==x): return True return False s=input() s="".join(s.split()) if(vov(s[len(s)-2])): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : String := (OclFile["System.in"]).readLine() ; s := StringLib.sumStringsWithSeparator((s.split()), "") ; if (vov(s[(s)->size() - 2+1])) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); operation vov(c : OclAny) : OclAny pre: true post: true activity: var d : Sequence := Sequence{'A'}->union(Sequence{'E'}->union(Sequence{'I'}->union(Sequence{'O'}->union(Sequence{'U'}->union(Sequence{'Y'}->union(Sequence{'a'}->union(Sequence{'e'}->union(Sequence{'i'}->union(Sequence{'o'}->union(Sequence{'u'}->union(Sequence{ 'y' }))))))))))) ; for x : d do ( if (c = x) then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def minimumX(n,k): mini=sys.maxsize i=1 while i*i<=n : if(n % i==0): fir=i sec=n//i num1=fir*k+sec res=(num1//k)*(num1 % k) if(res==n): mini=min(num1,mini) num2=sec*k+fir res=(num2//k)*(num2 % k) if(res==n): mini=min(num2,mini) i+=1 return mini if __name__=="__main__" : n=4 k=6 print(minimumX(n,k)) n=5 k=5 print(minimumX(n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 4 ; k := 6 ; execute (minimumX(n, k))->display() ; n := 5 ; k := 5 ; execute (minimumX(n, k))->display() ) else skip; operation minimumX(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var mini : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; var i : int := 1 ; while (i * i->compareTo(n)) <= 0 do ( if (n mod i = 0) then ( var fir : int := i ; var sec : int := n div i ; var num1 : double := fir * k + sec ; var res : int := (num1 div k) * (num1 mod k) ; if (res = n) then ( mini := Set{num1, mini}->min() ) else skip ; var num2 : double := sec * k + fir ; res := (num2 div k) * (num2 mod k) ; if (res = n) then ( mini := Set{num2, mini}->min() ) else skip ) else skip ; i := i + 1) ; return mini; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find_longest(node): global visited visited[node]=True if node not in graph : return 1 max_child=0 for i in graph[node]: if visited[i]: continue max_child=max(max_child,find_longest(i)) return max_child+1 def dfs(node): vis=[0 for i in range(len(FF))] vis[node]=1 size=1 tmp=node while True : tmp=FF[tmp] if tmp==node : return size if vis[tmp]==1 : return 0 vis[tmp]=1 size+=1 return 0 visited=[] graph={} Q=int(input()) for q in range(Q): N=int(input()) FF=list(map(int,input().split())) FF.insert(0,-1) graph={} visited=[False for i in range(N+1)] for i in range(1,len(FF)): if FF[i]not in graph : graph[FF[i]]=[] graph[FF[i]].append(i) double=0 for i in range(1,N+1): if i==FF[FF[i]]and not visited[i]: visited[i]=True visited[FF[i]]=True dou=find_longest(i)+find_longest(FF[i]) double+=dou for i in range(1,N+1): if not visited[i]: double=max(double,dfs(i)) print("Case #{}:{}".format(q+1,double)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute visited : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; visited := Sequence{} ; var graph : OclAny := Set{} ; var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for q : Integer.subrange(0, Q-1) do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var FF : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; FF := FF.insertAt(0+1, -1) ; graph := Set{} ; visited := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (false)) ; for i : Integer.subrange(1, (FF)->size()-1) do ( if (graph)->excludes(FF[i+1]) then ( graph[FF[i+1]+1] := Sequence{} ) else skip ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name FF)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var double : int := 0 ; for i : Integer.subrange(1, N + 1-1) do ( if i = FF[FF[i+1]+1] & not(visited[i+1]) then ( visited[i+1] := true ; visited[FF[i+1]+1] := true ; var dou : OclAny := find_longest(i) + find_longest(FF[i+1]) ; double := double + dou ) else skip) ; for i : Integer.subrange(1, N + 1-1) do ( if not(visited[i+1]) then ( double := Set{double, dfs(i)}->max() ) else skip) ; execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{q + 1, double}))->display()); operation find_longest(node : OclAny) : OclAny pre: true post: true activity: skip ; visited[node+1] := true ; if (graph)->excludes(node) then ( return 1 ) else skip ; var max_child : int := 0 ; for i : graph[node+1] do ( if visited[i+1] then ( continue ) else skip ; max_child := Set{max_child, find_longest(i)}->max()) ; return max_child + 1; operation dfs(node : OclAny) : OclAny pre: true post: true activity: var vis : Sequence := Integer.subrange(0, (FF)->size()-1)->select(i | true)->collect(i | (0)) ; vis[node+1] := 1 ; var size : int := 1 ; var tmp : OclAny := node ; while true do ( tmp := FF[tmp+1] ; if tmp = node then ( return size ) else skip ; if vis[tmp+1] = 1 then ( return 0 ) else skip ; vis[tmp+1] := 1 ; size := size + 1) ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.stdin=open("data.txt") sys.stdout=open("out.txt","w") input=sys.stdin.readline sys.setrecursionlimit(10000) g=[] friend=[] def dfs(u,n): v=u for i in range(1,n+2): v=friend[v] if u==v : return i else : return 1 def depth(u,bad): out=0 for v in g[u]: if v!=bad : out=max(out,depth(v,bad)) return out+1 def getpairs(): out=0 for i in range(len(g)): if friend[friend[i]]==i : out+=depth(i,friend[i])+depth(friend[i],i) return out//2 for c in range(int(input())): n=int(input()) friend=list(map(lambda s : int(s)-1,input().split())) ans=0 g=[[]for _ in range(n)] for i in range(n): g[friend[i]].append(i) for i in range(n): ans=max(ans,dfs(i,n)) ans=max(ans,getpairs()) print("Case #%s: %s" %(c+1,ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("data.txt")) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile("out.txt")) ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit(10000) ; var g : Sequence := Sequence{} ; var friend : Sequence := Sequence{} ; skip ; skip ; skip ; for c : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; friend := ((input().split())->collect( _x | (lambda s : OclAny in (("" + ((s)))->toInteger() - 1))->apply(_x) )) ; var ans : int := 0 ; g := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, n-1) do ((expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name friend)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; for i : Integer.subrange(0, n-1) do ( ans := Set{ans, dfs(i, n)}->max()) ; ans := Set{ans, getpairs()}->max() ; execute (StringLib.format("Case #%s: %s",Sequence{c + 1, ans}))->display()); operation dfs(u : OclAny, n : OclAny) pre: true post: true activity: var v : OclAny := u ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 2)))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name v)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name friend)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name u)))) == (comparison (expr (atom (name v))))))) : (suite (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name i))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))); operation depth(u : OclAny, bad : OclAny) : OclAny pre: true post: true activity: var out : int := 0 ; for v : g[u+1] do ( if v /= bad then ( out := Set{out, depth(v, bad)}->max() ) else skip) ; return out + 1; operation getpairs() : OclAny pre: true post: true activity: out := 0 ; for i : Integer.subrange(0, (g)->size()-1) do ( if friend[friend[i+1]+1] = i then ( out := out + depth(i, friend[i+1]) + depth(friend[i+1], i) ) else skip) ; return out div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() arr=list(map(int,input().split())) arr2=list(map(int,input().split())) if sum(arr)>=sum(arr2): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var arr2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if ((arr)->sum()->compareTo((arr2)->sum())) >= 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) N=n+2 is_prime=[1]*N is_prime[0]=0 is_prime[1]=0 def sieve(): i=2 while i*i<=N : if is_prime[i]==0 : i+=1 continue j=2*i while jtoInteger() ; var N : int := n + 2 ; var is_prime : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, N) ; is_prime->first() := 0 ; is_prime[1+1] := 0 ; skip ; sieve() ; var c : int := 0 ; if (n < 5) then ( c := 1 ; var s : String := "1 " ; for i : Integer.subrange(2, n + 1-1) do ( if ((i + 1) /= 4) then ( s := s + "1 " ) else ( s := s + "2 " ; c := c + 1 )) ; execute (c)->display() ; execute (s)->display() ) else ( execute ("2")->display() ; s := "" ; i := 1 ; for i : Integer.subrange(1, n + 1-1) do ( var k : int := i + 1 ; if (is_prime[k+1] = 1) then ( s := s + "1 " ) else ( s := s + "2 " )) ; execute (s)->display() ); operation sieve() pre: true post: true activity: var i : int := 2 ; while (i * i->compareTo(N)) <= 0 do ( if is_prime[i+1] = 0 then ( i := i + 1 ; continue ) else skip ; var j : int := 2 * i ; while (j->compareTo(N)) < 0 do ( is_prime[j+1] := 0 ; j := j + i) ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : a,b=list(map(lambda x : int(x),input().split())) print(a*b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) )) ; execute (a * b)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- task='C' type=2 if type==0 : inp=open('sample.in','r') elif type==1 : inp=open('%s-small.in' %(task,)) else : inp=open('%s-large.in' %(task),) outp=open('%s.out' %(task,),'w') T=int(inp.readline()[:-1]) for t in range(T): N=int(inp.readline()[:-1]) edges=[-1 for i in range(N)] revedges=[list()for i in range(N)] st=inp.readline()[:-1].split() def dfs(v): anses=[0] for v2 in revedges[v]: anses.append(dfs(v2)+1) return max(anses) for j,a in zip(range(N),st): a=int(a)-1 edges[j]=a revedges[a].append(j) pairs=set() loncyc=0 for i in range(N): used=[-1 for i in range(N)] cur=i curs=0 while used[cur]==-1 : used[cur]=curs curs+=1 cur=edges[cur] if curs-used[cur]==2 : pairs.add(cur) loncyc=max(loncyc,curs-used[cur]) pairtokens_sum=0 while len(pairs)>0 : cur1=pairs.pop() cur2=edges[cur1] revedges[cur1].remove(cur2) revedges[cur2].remove(cur1) pairs.remove(cur2) curs=2+dfs(cur1)+dfs(cur2) pairtokens_sum+=curs ans=max(pairtokens_sum,loncyc) outp.write("Case #%s: %s\n" %(t+1,ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var task : String := 'C' ; var type : int := 2 ; if type = 0 then ( var inp : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('sample.in')) ) else (if type = 1 then ( inp := OclFile.newOclFile_Write(OclFile.newOclFile(StringLib.format('%s-small.in',Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name task)))))) ,)}))) ) else ( inp := OclFile.newOclFile_Write(OclFile.newOclFile(StringLib.format('%s-large.in',(task)))) ) ) ; var outp : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(StringLib.format('%s.out',Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name task)))))) ,)}))) ; var T : int := ("" + ((inp.readLine()->front())))->toInteger() ; for t : Integer.subrange(0, T-1) do ( var N : int := ("" + ((inp.readLine()->front())))->toInteger() ; var edges : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (-1)) ; var revedges : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (())) ; var st : OclAny := inp.readLine()->front().split() ; skip ; for _tuple : Integer.subrange(1, Integer.subrange(0, N-1)->size())->collect( _indx | Sequence{Integer.subrange(0, N-1)->at(_indx), st->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); var a : double := ("" + ((a)))->toInteger() - 1 ; edges[j+1] := a ; (expr (atom (name revedges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) ))))) ; var pairs : Set := Set{}->union(()) ; var loncyc : int := 0 ; for i : Integer.subrange(0, N-1) do ( var used : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (-1)) ; var cur : OclAny := i ; var curs : int := 0 ; while used[cur+1] = -1 do ( used[cur+1] := curs ; curs := curs + 1 ; cur := edges[cur+1]) ; if curs - used[cur+1] = 2 then ( execute ((cur) : pairs) ) else skip ; loncyc := Set{loncyc, curs - used[cur+1]}->max()) ; var pairtokens_sum : int := 0 ; while (pairs)->size() > 0 do ( var cur1 : OclAny := pairs->last() ; pairs := pairs->front() ; var cur2 : OclAny := edges[cur1+1] ; (expr (atom (name revedges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name cur1)))))))) ])) (trailer . (name remove) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name cur2)))))))) )))) ; (expr (atom (name revedges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name cur2)))))))) ])) (trailer . (name remove) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name cur1)))))))) )))) ; execute ((cur2) /: pairs) ; curs := 2 + dfs(cur1) + dfs(cur2) ; pairtokens_sum := pairtokens_sum + curs) ; var ans : OclAny := Set{pairtokens_sum, loncyc}->max() ; outp.write(StringLib.format("Case #%s: %s\n",Sequence{t + 1, ans}))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def longestdfs(inedges,start,seen): seen.add(start) if not inedges[start]: return 1 candidates=[] for inedge in inedges[start]: candidates.append(longestdfs(inedges,inedge,seen)) return max(candidates)+1 cases=int(input()) for case in range(cases): n=int(input()) toedges=[int(x)-1 for x in input().split()] inedges=[[]for x in toedges] for i,to in enumerate(toedges): inedges[to].append(i) mutuals=[] for i,to in enumerate(toedges): if toedges[to]==i and to>i : mutuals.append((to,i)) inedges[to].remove(i) inedges[i].remove(to) mdepths=[] seen=set() for a,b in mutuals : mdepths.append(longestdfs(inedges,a,seen)+longestdfs(inedges,b,seen)) cyclemax=0 for i in range(n): if i in seen : continue seen.add(i) length=1 tempi=toedges[i] path=[i,tempi] while tempi!=i : if tempi in seen : length-=path.index(tempi) break seen.add(tempi) length+=1 tempi=toedges[tempi] path.append(tempi) cyclemax=max(length,cyclemax) ans=max(sum(mdepths),cyclemax) print("Case #{}:{}".format(case+1,ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var cases : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for case : Integer.subrange(0, cases-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var toedges : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)) ; inedges := toedges->select(x | true)->collect(x | (Sequence{})) ; for _tuple : Integer.subrange(1, (toedges)->size())->collect( _indx | Sequence{_indx-1, (toedges)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var to : OclAny := _tuple->at(_indx); (expr (atom (name inedges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name to)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var mutuals : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (toedges)->size())->collect( _indx | Sequence{_indx-1, (toedges)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var to : OclAny := _tuple->at(_indx); if toedges[to+1] = i & (to->compareTo(i)) > 0 then ( execute ((Sequence{to, i}) : mutuals) ; (expr (atom (name inedges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name to)))))))) ])) (trailer . (name remove) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ; (expr (atom (name inedges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name remove) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name to)))))))) )))) ) else skip) ; var mdepths : Sequence := Sequence{} ; seen := Set{}->union(()) ; for _tuple : mutuals do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); execute ((longestdfs(inedges, a, seen) + longestdfs(inedges, b, seen)) : mdepths)) ; var cyclemax : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (seen)->includes(i) then ( continue ) else skip ; execute ((i) : seen) ; var length : int := 1 ; var tempi : OclAny := toedges[i+1] ; var path : Sequence := Sequence{i}->union(Sequence{ tempi }) ; while tempi /= i do ( if (seen)->includes(tempi) then ( length := length - path->indexOf(tempi) - 1 ; break ) else skip ; execute ((tempi) : seen) ; length := length + 1 ; tempi := toedges[tempi+1] ; execute ((tempi) : path)) ; cyclemax := Set{length, cyclemax}->max()) ; var ans : OclAny := Set{(mdepths)->sum(), cyclemax}->max() ; execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{case + 1, ans}))->display()); operation longestdfs(inedges : OclAny, start : OclAny, seen : OclAny) : OclAny pre: true post: true activity: execute ((start) : seen) ; if not(inedges[start+1]) then ( return 1 ) else skip ; var candidates : Sequence := Sequence{} ; for inedge : inedges[start+1] do ( execute ((longestdfs(inedges, inedge, seen)) : candidates)) ; return (candidates)->max() + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys fin=open(sys.argv[1],"r") fout=open("p3.out","w") T=int(fin.readline()) for tt in xrange(T): N=int(fin.readline()) out=map(int,fin.readline().split()) out=map(lambda x : x-1,out) ans=0 best=[0 for j in xrange(N)] for i in xrange(N): cur=i vis=[0 for j in xrange(N)] vis[cur]=1 while vis[out[cur]]==0 : vis[out[cur]]=1 cur=out[cur] if out[cur]==i : ans=max(ans,sum(vis)) if out[out[cur]]==cur : best[cur]=max(best[cur],sum(vis)) tot=0 for i in xrange(N): if out[out[i]]==i : tot+=best[i]+best[out[i]]-2 tot/=2 ans=max(ans,tot) fout.write("Case #"+str(tt+1)+": "+str(ans)+"\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var fin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) ; var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("p3.out")) ; var T : int := ("" + ((fin.readLine())))->toInteger() ; for tt : xrange(T) do ( var N : int := ("" + ((fin.readLine())))->toInteger() ; var out : Sequence := (fin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; out := (out)->collect( _x | (lambda x : OclAny in (x - 1))->apply(_x) ) ; var ans : int := 0 ; var best : Sequence := xrange(N)->select(j | true)->collect(j | (0)) ; for i : xrange(N) do ( var cur : OclAny := i ; var vis : Sequence := xrange(N)->select(j | true)->collect(j | (0)) ; vis[cur+1] := 1 ; while vis[out[cur+1]+1] = 0 do ( vis[out[cur+1]+1] := 1 ; cur := out[cur+1]) ; if out[cur+1] = i then ( ans := Set{ans, (vis)->sum()}->max() ) else skip ; if out[out[cur+1]+1] = cur then ( best[cur+1] := Set{best[cur+1], (vis)->sum()}->max() ) else skip) ; var tot : int := 0 ; for i : xrange(N) do ( if out[out[i+1]+1] = i then ( tot := tot + best[i+1] + best[out[i+1]+1] - 2 ) else skip) ; tot := tot / 2 ; ans := Set{ans, tot}->max() ; fout.write("Case #" + ("" + ((tt + 1))) + ": " + ("" + ((ans))) + "\n")); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def SellingPrice(CP,PP): Pdecimal=1+(PP/100) res=Pdecimal*CP return res if __name__=="__main__" : C=720 P=13 print(SellingPrice(C,P)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var C : int := 720 ; var P : int := 13 ; execute (SellingPrice(C, P))->display() ) else skip; operation SellingPrice(CP : OclAny, PP : OclAny) : OclAny pre: true post: true activity: var Pdecimal : int := 1 + (PP / 100) ; var res : double := Pdecimal * CP ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for c in range(t): n=int(input()) seq=[int(n)for n in input().split()] posis=[None]*(n+1) for u in range(0,n): posis[seq[u]]=u print(1,end="") l=posis[1]; r=posis[1] for num in range(2,n+1): if(posis[num]r): r=posis[num] print(1 if num==r-l+1 else 0,end="") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for c : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var seq : Sequence := input().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; var posis : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (n + 1)) ; for u : Integer.subrange(0, n-1) do ( posis[seq[u+1]+1] := u) ; execute (1)->display() ; var l : OclAny := posis[1+1]; ; var r : OclAny := posis[1+1] ; for num : Integer.subrange(2, n + 1-1) do ( if ((posis[num+1]->compareTo(l)) < 0) then ( l := posis[num+1] ) else skip ; if ((posis[num+1]->compareTo(r)) > 0) then ( r := posis[num+1] ) else skip ; execute (if num = r - l + 1 then 1 else 0 endif)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect,bisect_right from cmath import sqrt from collections import defaultdict import heapq from math import* import sys from tkinter import N from typing import Counter input=sys.stdin.readline for _ in range(int(input())): n=list(map(int,input().split()))[0] a=list(map(int,input().split())) p=[0]*n for i in range(n): p[a[i]-1]=i l=n r=0 ans="" for i in range(n): l=min(l,p[i]) r=max(r,p[i]) if r-l==i : ans+='1' else : ans+='0' print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->first() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var p : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( p[a[i+1] - 1+1] := i) ; var l : OclAny := n ; var r : int := 0 ; var ans : String := "" ; for i : Integer.subrange(0, n-1) do ( l := Set{l, p[i+1]}->min() ; r := Set{r, p[i+1]}->max() ; if r - l = i then ( ans := ans + '1' ) else ( ans := ans + '0' )) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for t in range(T): n=int(input()) A=[int(l)for l in input().split()] index={l : i for i,l in enumerate(A)} l=index[1] r=index[1] print(1,end='') for i in range(2,len(A)+1): k=index[i] if(kr): r=k if(r-l+1==i): print(1,end='') else : print(0,end='') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(0, T-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(l | true)->collect(l | (("" + ((l)))->toInteger())) ; var index : Map := Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} )->select(_tuple | true)->collect(_tuple | Map{l |-> i})->unionAll() ; var l : OclAny := index[1+1] ; var r : OclAny := index[1+1] ; execute (1)->display() ; for i : Integer.subrange(2, (A)->size() + 1-1) do ( var k : OclAny := index[i+1] ; if ((k->compareTo(l)) < 0) then ( l := k ) else skip ; if ((k->compareTo(r)) > 0) then ( r := k ) else skip ; if (r - l + 1 = i) then ( execute (1)->display() ) else ( execute (0)->display() )) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n=int(input()) w=list(map(int,input().split())) d=[0]*(n+2) e=[0]*(n+2) s='' for i in range(n): d[w[i]]=i+1 c=0 for i in range(1,n+1): x=d[i] e[x]=1 c+=e[x-1]+e[x+1] if c+1==i : s+='1' else : s+='0' print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 2)) ; var e : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 2)) ; var s : String := '' ; for i : Integer.subrange(0, n-1) do ( d[w[i+1]+1] := i + 1) ; var c : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( var x : OclAny := d[i+1] ; e[x+1] := 1 ; c := c + e[x - 1+1] + e[x + 1+1] ; if c + 1 = i then ( s := s + '1' ) else ( s := s + '0' )) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def f(b : int,n : int)->int : if b>n : return n return f(b,n//b)+(n % b) def digit_sum(n : int,s : int)->int : if n==s : return n+1 sqrt=math.sqrt(n) sqrt=math.ceil(sqrt) for b in range(2,sqrt+1): if f(b,n)==s : return b for p in range(sqrt,0,-1): if(n-s)% p : continue b=(n-s)//p+1 if b<2 : continue if f(b,n)==s : return b return-1 if __name__=="__main__" : n=int(input()) s=int(input()) ans=digit_sum(n,s) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : OclAny := digit_sum(n, s) ; execute (ans)->display() ) else skip; operation f(b : int, n : int) : int pre: true post: true activity: if (b->compareTo(n)) > 0 then ( return n ) else skip ; return f(b, n div b) + (n mod b); operation digit_sum(n : int, s : int) : int pre: true post: true activity: if n = s then ( return n + 1 ) else skip ; var sqrt : double := (n)->sqrt() ; sqrt := (sqrt)->ceil() ; for b : Integer.subrange(2, sqrt + 1-1) do ( if f(b, n) = s then ( return b ) else skip) ; for p : Integer.subrange(0 + 1, sqrt)->reverse() do ( if (n - s) mod p then ( continue ) else skip ; var b : int := (n - s) div p + 1 ; if b < 2 then ( continue ) else skip ; if f(b, n) = s then ( return b ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=int(input()) b_ans=1 if n==s : b_ans=n+1 if b_ans==1 : for b in range(2,int(n**0.5)+1): nn=n st=[] while(nn>0): st.append(nn % b) nn=(nn-st[-1])/b if sum(st)==s : b_ans=b break if b_ans==1 : for p in range(int(n**0.5),0,-1): b=(n-s+p)/p if b.is_integer()and 0<=s-pn**0.5 : b_ans=int(b) break if b_ans!=1 : print(b_ans) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b_ans : int := 1 ; if n = s then ( b_ans := n + 1 ) else skip ; if b_ans = 1 then ( for b : Integer.subrange(2, ("" + (((n)->pow(0.5))))->toInteger() + 1-1) do ( var nn : int := n ; var st : Sequence := Sequence{} ; while (nn > 0) do ( execute ((nn mod b) : st) ; nn := (nn - st->last()) / b) ; if (st)->sum() = s then ( b_ans := b ; break ) else skip) ) else skip ; if b_ans = 1 then ( for p : Integer.subrange(0 + 1, ("" + (((n)->pow(0.5))))->toInteger())->reverse() do ( var b : double := (n - s + p) / p ; if b.is_integer() & 0 <= s - p & (s - p < b) & (b->compareTo((n)->pow(0.5))) > 0 then ( b_ans := ("" + ((b)))->toInteger() ; break ) else skip) ) else skip ; if b_ans /= 1 then ( execute (b_ans)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(eval(input().replace(" ","*"))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (input().replace(" ", "*"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sieve(N): primeNumbers=[True]*(N+1) primeNumbers[0]=False primeNumbers[1]=False i=2 while i*i<=N : j=i if primeNumbers[j]: while j*i<=N : primeNumbers[j*i]=False j+=1 i+=1 return primeNumbers def countColor(N): primes=sieve(pow(10,6)) if N>2 : print("2") else : print("1") print(end="") for i in range(2,N+2): if primes[i]: print("1",end=" ") else : print("2",end=" ") N=int(input()) countColor(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; countColor(N); operation sieve(N : OclAny) : OclAny pre: true post: true activity: var primeNumbers : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (N + 1)) ; primeNumbers->first() := false ; primeNumbers[1+1] := false ; var i : int := 2 ; while (i * i->compareTo(N)) <= 0 do ( var j : int := i ; if primeNumbers[j+1] then ( while (j * i->compareTo(N)) <= 0 do ( primeNumbers[j * i+1] := false ; j := j + 1) ) else skip ; i := i + 1) ; return primeNumbers; operation countColor(N : OclAny) pre: true post: true activity: var primes : OclAny := sieve((10)->pow(6)) ; if N > 2 then ( execute ("2")->display() ) else ( execute ("1")->display() ) ; execute ((argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom "")))))))->display() ; for i : Integer.subrange(2, N + 2-1) do ( if primes[i+1] then ( execute ("1")->display() ) else ( execute ("2")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda : sys.stdin.readline().rstrip() def f(b,n): if(nn): print(-1) return if(s==n): print(n+1) return k=int(n**.5) for b in range(2,k+2): if(f(b,n)==s): print(b) return B=[] for p in range(1,k+1): if((n-s)% p): continue b=(n-s)//p+1 if(b<2): continue if(f(b,n)==s): B.append(b) print(min(B)if(B)else-1) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(2147483647) ; var INF : double := ("" + (("inf")))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; skip ; skip ; resolve(); operation f(b : OclAny, n : OclAny) : OclAny pre: true post: true activity: if ((n->compareTo(b)) < 0) then ( return n ) else skip ; return f(b, n div b) + n mod b; operation resolve() pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if ((s->compareTo(n)) > 0) then ( execute (-1)->display() ; return ) else skip ; if (s = n) then ( execute (n + 1)->display() ; return ) else skip ; var k : int := ("" + (((n)->pow(.5))))->toInteger() ; for b : Integer.subrange(2, k + 2-1) do ( if (f(b, n) = s) then ( execute (b)->display() ; return ) else skip) ; var B : Sequence := Sequence{} ; for p : Integer.subrange(1, k + 1-1) do ( if ((n - s) mod p) then ( continue ) else skip ; b := (n - s) div p + 1 ; if (b < 2) then ( continue ) else skip ; if (f(b, n) = s) then ( execute ((b) : B) ) else skip) ; execute (if (B) then (B)->min() else -1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def read_int(): return int(input().strip()) def read_ints(): return list(map(int,input().strip().split(' '))) def f(b,n): S=0 while n!=0 : S+=n % b n//=b return S def solve(): n=read_int() s=read_int() for b in range(2,math.ceil(math.sqrt(n))+1): if f(b,n)==s : return b if n-s<0 : return-1 if n==s : return n+1 for p in range(math.ceil(math.sqrt(n-s)),0,-1): if(n-s)% p==0 and f((n-s)//p+1,n)==s : return(n-s)//p+1 return-1 if __name__=='__main__' : print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( execute (solve())->display() ) else skip; operation read_int() : OclAny pre: true post: true activity: return ("" + ((input()->trim())))->toInteger(); operation read_ints() : OclAny pre: true post: true activity: return ((input()->trim().split(' '))->collect( _x | (OclType["int"])->apply(_x) )); operation f(b : OclAny, n : OclAny) : OclAny pre: true post: true activity: var S : int := 0 ; while n /= 0 do ( S := S + n mod b ; n := n div b) ; return S; operation solve() : OclAny pre: true post: true activity: n := read_int() ; var s : OclAny := read_int() ; for b : Integer.subrange(2, ((n)->sqrt())->ceil() + 1-1) do ( if f(b, n) = s then ( return b ) else skip) ; if n - s < 0 then ( return -1 ) else skip ; if n = s then ( return n + 1 ) else skip ; for p : Integer.subrange(0 + 1, ((n - s)->sqrt())->ceil())->reverse() do ( if (n - s) mod p = 0 & f((n - s) div p + 1, n) = s then ( return (n - s) div p + 1 ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt n=int(input()) s=int(input()) def f(x,y): if ytoInteger() ; var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; if s = n then ( var ans : int := n + 1 ) else (if (n->compareTo(s)) < 0 then ( ans := -1 ) else ( ans := -1 ; for i : Integer.subrange(2, ("" + ((sqrt(n))))->toInteger() + 1-1) do ( if f(i, n) = s then ( ans := i ; break ) else skip) ; if ans = -1 then ( for i : Integer.subrange(0 + 1, ("" + ((sqrt(n))))->toInteger())->reverse() do ( var b : double := (n - s) / i + 1 ; if b = ("" + ((b)))->toInteger() & f(("" + ((b)))->toInteger(), n) = s then ( ans := ("" + ((b)))->toInteger() ; break ) else skip) ) else skip ) ) ; execute (ans)->display(); operation f(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (y->compareTo(x)) < 0 then ( return y ) else ( return f(x, y div x) + (y mod x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,b=map(int,input().split()) maximum=0 for y in range(b+1): sum=(m*(b-y)+y)*(m*(b-y)+1)*(y+1)//2 if maximum<=sum : maximum=sum else : break ; print(maximum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var b : OclAny := null; Sequence{m,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var maximum : int := 0 ; for y : Integer.subrange(0, b + 1-1) do ( var sum : int := (m * (b - y) + y) * (m * (b - y) + 1) * (y + 1) div 2 ; if (maximum->compareTo(sum)) <= 0 then ( maximum := sum ) else ( break; )) ; execute (maximum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,b=[int(x)for x in input().split()] best=0 for y in range(b+1): x=(b-y)*m s=((x+1)*(y+1)*(x+y))//2 best=max(best,s) print(best) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var b : OclAny := null; Sequence{m,b} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var best : int := 0 ; for y : Integer.subrange(0, b + 1-1) do ( var x : double := (b - y) * m ; var s : int := ((x + 1) * (y + 1) * (x + y)) div 2 ; best := Set{best, s}->max()) ; execute (best)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,b=map(int,input().split()) r=-1 for i in range(b): x=(b-i)*m ; s=(i+x)*(x+1)*(i+1) r=max(r,s) print(r//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var b : OclAny := null; Sequence{m,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var r : int := -1 ; for i : Integer.subrange(0, b-1) do ( var x : double := (b - i) * m; ; var s : double := (i + x) * (x + 1) * (i + 1) ; r := Set{r, s}->max()) ; execute (r div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : m,b=map(int,input().split()) answer=0 for y in range(b): x=(b-y)*m answer=max(answer,(x+1)*(y+1)*(x+y)//2) print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var m : OclAny := null; var b : OclAny := null; Sequence{m,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var answer : int := 0 ; for y : Integer.subrange(0, b-1) do ( var x : double := (b - y) * m ; answer := Set{answer, (x + 1) * (y + 1) * (x + y) div 2}->max()) ; execute (answer)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,b=map(int,input().split()) x,y=m*b,b s=0 for j in range(y+1): i=m*(b-j) a1=i*(1+i)>>1 d=i+1 n=j+1 s=max(s,n*(2*a1+(n-1)*d)>>1) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var b : OclAny := null; Sequence{m,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{m * b,b} ; var s : int := 0 ; for j : Integer.subrange(0, y + 1-1) do ( var i : double := m * (b - j) ; var a1 : int := i * (1 + i) /(2->pow(1)) ; var d : OclAny := i + 1 ; var n : OclAny := j + 1 ; s := Set{s, n * (2 * a1 + (n - 1) * d) /(2->pow(1))}->max()) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(n,m): if(m % n==0): print("YES") else : print("NO") n=5 m=10 check(n,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; m := 10 ; check(n, m); operation check(n : OclAny, m : OclAny) pre: true post: true activity: if (m mod n = 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def OddDivCount(a,b): res=0 for i in range(a,b+1): divCount=0 for j in range(1,i+1): if(i % j==0): divCount+=1 if(divCount % 2): res+=1 return res if __name__=="__main__" : a=1 b=10 print(OddDivCount(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := 1 ; b := 10 ; execute (OddDivCount(a, b))->display() ) else skip; operation OddDivCount(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; for i : Integer.subrange(a, b + 1-1) do ( var divCount : int := 0 ; for j : Integer.subrange(1, i + 1-1) do ( if (i mod j = 0) then ( divCount := divCount + 1 ) else skip) ; if (divCount mod 2) then ( res := res + 1 ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x=int(input()); a=list(map(int,input().split())); p=0 for i in range(x-2): if a[i]in a[i+2 :]: p=1 break print('YES' if p!=0 else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); var p : int := 0 ; for i : Integer.subrange(0, x - 2-1) do ( if (a.subrange(i + 2+1))->includes(a[i+1]) then ( p := 1 ; break ) else skip) ; execute (if p /= 0 then 'YES' else 'NO' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) n=n+1 prime=[2 for i in range(n+1)] p=2 while(p*p<=n): if(prime[p]==2): for i in range(p*p,n+1,p): prime[i]=1 p+=1 if n==2 : print(1) print(1) elif n==3 : print(1) print(str(1)+" "+str(1)) else : print(2) print(*prime[2 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; n := n + 1 ; var prime : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (2)) ; var p : int := 2 ; while ((p * p->compareTo(n)) <= 0) do ( if (prime[p+1] = 2) then ( for i : Integer.subrange(p * p, n + 1-1)->select( $x | ($x - p * p) mod p = 0 ) do ( prime[i+1] := 1) ) else skip ; p := p + 1) ; if n = 2 then ( execute (1)->display() ; execute (1)->display() ) else (if n = 3 then ( execute (1)->display() ; execute (("" + ((1))) + " " + ("" + ((1))))->display() ) else ( execute (2)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name prime)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) :)) ]))))))))->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,l,k=int(input()),list(map(int,input().split())),False for i in range(n): if l[i :].count(l[i])==2 : if l[i+1]!=l[i]: print("YES") k=True break elif l.count(l[i])>2 : print("YES") k=True break if k==False : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var l : OclAny := null; var k : OclAny := null; Sequence{n,l,k} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),((input().split())->collect( _x | (OclType["int"])->apply(_x) )),false} ; for i : Integer.subrange(0, n-1) do ( if l.subrange(i+1)->count(l[i+1]) = 2 then ( if l[i + 1+1] /= l[i+1] then ( execute ("YES")->display() ; var k : boolean := true ; break ) else skip ) else (if l->count(l[i+1]) > 2 then ( execute ("YES")->display() ; k := true ; break ) else skip)) ; if k = false then ( execute ("NO")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,l,k=int(input()),list(map(int,input().split())),False for i in range(n): if l[i :].count(l[i])==2 : if l[i+1]!=l[i]: print("YES") k=True break elif l.count(l[i])>2 : print("YES") k=True break if k==False : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var l : OclAny := null; var k : OclAny := null; Sequence{n,l,k} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),((input().split())->collect( _x | (OclType["int"])->apply(_x) )),false} ; for i : Integer.subrange(0, n-1) do ( if l.subrange(i+1)->count(l[i+1]) = 2 then ( if l[i + 1+1] /= l[i+1] then ( execute ("YES")->display() ; var k : boolean := true ; break ) else skip ) else (if l->count(l[i+1]) > 2 then ( execute ("YES")->display() ; k := true ; break ) else skip)) ; if k = false then ( execute ("NO")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) arr=list(map(int,input().split())) counts=dict() ok=False for j in range(n): if arr[j]in counts : counts[arr[j]].append(j) else : counts[arr[j]]=[j] for k,v in counts.items(): if len(v)>=2 : if v[-1]-v[0]>1 : ok=True if ok : break if ok : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var counts : Map := (arguments ( )) ; var ok : boolean := false ; for j : Integer.subrange(0, n-1) do ( if (counts)->includes(arr[j+1]) then ( (expr (atom (name counts)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) ) else ( counts[arr[j+1]+1] := Sequence{ j } )) ; for _tuple : counts->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if (v)->size() >= 2 then ( if v->last() - v->first() > 1 then ( ok := true ) else skip ) else skip ; if ok then ( break ) else skip) ; if ok then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): N=int(input()) L=list(map(int,input().split())) for i in range(N-2): if L[i]in L[i+2 :]: print("YES") break else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var L : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name N))) - (expr (atom (number (integer 2)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) in (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 2)))))))) :)) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) if ab : print(a-b) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(b)) < 0 then ( execute (b - a)->display() ) else (if (a->compareTo(b)) > 0 then ( execute (a - b)->display() ) else ( execute (0)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x1,x2=[int(x)for x in input().split()] print(abs(x1-x2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x1 : OclAny := null; var x2 : OclAny := null; Sequence{x1,x2} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((x1 - x2)->abs())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=(int(x)for x in input().split()) if 0<=a<=b<=100 : print(b-a) elif 0<=b<=a<=100 : print(a-b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; if 0 <= a & (a <= b) & (b <= 100) then ( execute (b - a)->display() ) else (if 0 <= b & (b <= a) & (a <= 100) then ( execute (a - b)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x1,x2=map(int,input().split()) if x1>x2 : print(x1-x2) if x1collect( _x | (OclType["int"])->apply(_x) ) ; if (x1->compareTo(x2)) > 0 then ( execute (x1 - x2)->display() ) else skip ; if (x1->compareTo(x2)) < 0 then ( execute (x2 - x1)->display() ) else skip ; if x1 = x2 then ( execute (x1 - x2)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ncr(n,r): ans=1 for i in range(1,r+1): ans*=(n-r+i) ans//=i return ans def totalWays(X,Y,M,W): return(ncr(M,X)*ncr(W,Y)) X=4 Y=3 M=6 W=5 print(totalWays(X,Y,M,W)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; X := 4 ; Y := 3 ; M := 6 ; W := 5 ; execute (totalWays(X, Y, M, W))->display(); operation ncr(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: var ans : int := 1 ; for i : Integer.subrange(1, r + 1-1) do ( ans := ans * (n - r + i) ; ans := ans div i) ; return ans; operation totalWays(X : OclAny, Y : OclAny, M : OclAny, W : OclAny) : OclAny pre: true post: true activity: return (ncr(M, X) * ncr(W, Y)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from decimal import* a,b=map(Decimal,input().split()) getcontext().prec=len(str(a))+len(str(b)) if a==0 or b==0 : print(0) else : print(a*b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (Decimal)->apply(_x) ) ; getcontext().prec := (("" + ((a))))->size() + (("" + ((b))))->size() ; if a = 0 or b = 0 then ( execute (0)->display() ) else ( execute (a * b)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input().split() a=int(s[0]) b=int(s[1]) if a-b<0 : print(-(a-b)) else : print(a-b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := input().split() ; var a : int := ("" + ((s->first())))->toInteger() ; var b : int := ("" + ((s[1+1])))->toInteger() ; if a - b < 0 then ( execute (-(a - b))->display() ) else ( execute (a - b)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=input().split(".") if int(num[0][-1])==9 : print("GOTO Vasilisa.") else : if int(num[1][0])>=5 : print(f"{int(num[0])+1}") else : print(num[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : OclAny := input().split(".") ; if ("" + ((num->first()->last())))->toInteger() = 9 then ( execute ("GOTO Vasilisa.")->display() ) else ( if ("" + ((num[1+1]->first())))->toInteger() >= 5 then ( execute (StringLib.formattedString("{int(num[0])+1}"))->display() ) else ( execute (num->first())->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) prices=[i+2 for i in range(n)] colors=[] color_count=0 primes=[1]*(n+2) primes[0]=0 primes[1]=0 k=2 while k*k<=n+1 : if primes[k]==1 : for i in range(k*k,n+2,k): primes[i]=2 k+=1 if n>2 : print(2) else : print(1) print(*primes[2 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var prices : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i + 2)) ; var colors : Sequence := Sequence{} ; var color_count : int := 0 ; var primes : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 2)) ; primes->first() := 0 ; primes[1+1] := 0 ; var k : int := 2 ; while (k * k->compareTo(n + 1)) <= 0 do ( if primes[k+1] = 1 then ( for i : Integer.subrange(k * k, n + 2-1)->select( $x | ($x - k * k) mod k = 0 ) do ( primes[i+1] := 2) ) else skip ; k := k + 1) ; if n > 2 then ( execute (2)->display() ) else ( execute (1)->display() ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name primes)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) :)) ]))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=input() l=l.split('.') s=list(l[0]) p=list(l[1]) i=int(p[0]) if s[len(s)-1]=='9' : print("GOTO Vasilisa.") elif s[len(s)-1]!='9' and i<5 : s="".join(s) print(s) else : s="".join(s) s=str(int(s)+1) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : String := (OclFile["System.in"]).readLine() ; l := l.split('.') ; var s : Sequence := (l->first()) ; var p : Sequence := (l[1+1]) ; var i : int := ("" + ((p->first())))->toInteger() ; if s[(s)->size() - 1+1] = '9' then ( execute ("GOTO Vasilisa.")->display() ) else (if s[(s)->size() - 1+1] /= '9' & i < 5 then ( s := StringLib.sumStringsWithSeparator((s), "") ; execute (s)->display() ) else ( s := StringLib.sumStringsWithSeparator((s), "") ; s := ("" + ((("" + ((s)))->toInteger() + 1))) ; execute (s)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input().split(".") u=x[1] if x[0][-1]=="9" : print("GOTO Vasilisa.") elif(int(u[0])>=5): print(int(x[0])+1) else : print(int(x[0])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := input().split(".") ; var u : OclAny := x[1+1] ; if x->first()->last() = "9" then ( execute ("GOTO Vasilisa.")->display() ) else (if (("" + ((u->first())))->toInteger() >= 5) then ( execute (("" + ((x->first())))->toInteger() + 1)->display() ) else ( execute (("" + ((x->first())))->toInteger())->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() dot=s.find(".") i,d=s[dot-1],s[dot+1] res="GOTO Vasilisa." if i=="9" else int(s[: dot])+(int(d)>=5) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var dot : int := s->indexOf(".") - 1 ; var i : OclAny := null; var d : OclAny := null; Sequence{i,d} := Sequence{s[dot - 1+1],s[dot + 1+1]} ; var res : String := if i = "9" then "GOTO Vasilisa." else ("" + ((s.subrange(1,dot))))->toInteger() + (("" + ((d)))->toInteger() >= 5) endif ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=input().split('.') if a[-1]=='9' : print("GOTO Vasilisa.") elif b[0]>='5' : print(int(a)+1) else : print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split('.') ; if a->last() = '9' then ( execute ("GOTO Vasilisa.")->display() ) else (if b->first() >= '5' then ( execute (("" + ((a)))->toInteger() + 1)->display() ) else ( execute (a)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=list(map(int,input().split())) s=input()[: n] ls={} for c in s : ls[c]=c for i in range(m): x,y=input().split()[: 2] if x not in ls : ls[x]=x if y not in ls : ls[y]=y ls[x],ls[y]=ls[y],ls[x] ans={} for c,v in ls.items(): ans[v]=c print("".join([ans[c]for c in s])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : OclAny := input().subrange(1,n) ; var ls : OclAny := Set{} ; for c : s do ( ls[c+1] := c) ; for i : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := input().split().subrange(1,2) ; if (ls)->excludes(x) then ( ls[x+1] := x ) else skip ; if (ls)->excludes(y) then ( ls[y+1] := y ) else skip ; var ls[x+1] : OclAny := null; var ls[y+1] : OclAny := null; Sequence{ls[x+1],ls[y+1]} := Sequence{ls[y+1],ls[x+1]}) ; var ans : OclAny := Set{} ; for _tuple : ls->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var c : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); ans[v+1] := c) ; execute (StringLib.sumStringsWithSeparator((s->select(c | true)->collect(c | (ans[c+1]))), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_key(val): for key,value in d.items(): if val==value : return key x=input() x=x.split("") n=int(x[0]) m=int(x[1]) s=input() d={} for i in range(n): d[s[i]]=s[i] for j in range(m): t=input() t=t.split("") if t[0]not in d.keys(): d[t[0]]=t[0] if t[1]not in d.keys(): d[t[1]]=t[1] d[t[0]],d[t[1]]=d[t[1]],d[t[0]] for k in range(n): print(get_key(s[k]),end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : String := (OclFile["System.in"]).readLine() ; x := x.split("") ; var n : int := ("" + ((x->first())))->toInteger() ; var m : int := ("" + ((x[1+1])))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var d : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( d[s[i+1]+1] := s[i+1]) ; for j : Integer.subrange(0, m-1) do ( var t : String := (OclFile["System.in"]).readLine() ; t := t.split("") ; if (d.keys())->excludes(t->first()) then ( d[t->first()+1] := t->first() ) else skip ; if (d.keys())->excludes(t[1+1]) then ( d[t[1+1]+1] := t[1+1] ) else skip ; var d[t->first()+1] : OclAny := null; var d[t[1+1]+1] : OclAny := null; Sequence{d[t->first()+1],d[t[1+1]+1]} := Sequence{d[t[1+1]+1],d[t->first()+1]}) ; for k : Integer.subrange(0, n-1) do ( execute (get_key(s[k+1]))->display()); operation get_key(val : OclAny) : OclAny pre: true post: true activity: for _tuple : d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); if val = value then ( return key ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split('')[: 2]) s=input()[: n] ls={} for c in s : ls[c]=c for i in range(m): x,y=input().split('')[: 2] if x not in ls : ls[x]=x if y not in ls : ls[y]=y ls[x],ls[y]=ls[y],ls[x] rev={} for c,v in ls.items(): rev[v]=c print(''.join([rev[c]for c in s])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split('').subrange(1,2))->collect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := input().subrange(1,n) ; var ls : OclAny := Set{} ; for c : s do ( ls[c+1] := c) ; for i : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := input().split('').subrange(1,2) ; if (ls)->excludes(x) then ( ls[x+1] := x ) else skip ; if (ls)->excludes(y) then ( ls[y+1] := y ) else skip ; var ls[x+1] : OclAny := null; var ls[y+1] : OclAny := null; Sequence{ls[x+1],ls[y+1]} := Sequence{ls[y+1],ls[x+1]}) ; var rev : OclAny := Set{} ; for _tuple : ls->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var c : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); rev[v+1] := c) ; execute (StringLib.sumStringsWithSeparator((s->select(c | true)->collect(c | (rev[c+1]))), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from decimal import* getcontext().prec=2000001 a,b=map(Decimal,input().split()) ans=a*b if a==0 or b==0 : ans=Decimal(0) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; getcontext().prec := 2000001 ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (Decimal)->apply(_x) ) ; var ans : double := a * b ; if a = 0 or b = 0 then ( ans := Decimal(0) ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,m=map(int,input().split()) s=input()[:-1] d=list(range(97,123)) for _ in range(m): w=input() x=w[0] y=w[2] a=d.index(ord(x)) b=d.index(ord(y)) d[a],d[b]=ord(y),ord(x) translation={97 : d[0],98 : d[1],99 : d[2],100 : d[3],101 : d[4],102 : d[5],103 : d[6],104 : d[7],105 : d[8],106 : d[9],107 : d[10],108 : d[11],109 : d[12],110 : d[13],111 : d[14],112 : d[15],113 : d[16],114 : d[17],115 : d[18],116 : d[19],117 : d[20],118 : d[21],119 : d[22],120 : d[23],121 : d[24],122 : d[25]} s=s.translate(translation) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := input()->front() ; var d : Sequence := (Integer.subrange(97, 123-1)) ; for _anon : Integer.subrange(0, m-1) do ( var w : String := (OclFile["System.in"]).readLine() ; var x : OclAny := w->first() ; var y : OclAny := w[2+1] ; var a : int := d->indexOf((x)->char2byte()) - 1 ; var b : int := d->indexOf((y)->char2byte()) - 1 ; var d[a+1] : OclAny := null; var d[b+1] : OclAny := null; Sequence{d[a+1],d[b+1]} := Sequence{(y)->char2byte(),(x)->char2byte()}) ; var translation : Map := Map{ 97 |-> d->first() }->union(Map{ 98 |-> d[1+1] }->union(Map{ 99 |-> d[2+1] }->union(Map{ 100 |-> d[3+1] }->union(Map{ 101 |-> d[4+1] }->union(Map{ 102 |-> d[5+1] }->union(Map{ 103 |-> d[6+1] }->union(Map{ 104 |-> d[7+1] }->union(Map{ 105 |-> d[8+1] }->union(Map{ 106 |-> d[9+1] }->union(Map{ 107 |-> d[10+1] }->union(Map{ 108 |-> d[11+1] }->union(Map{ 109 |-> d[12+1] }->union(Map{ 110 |-> d[13+1] }->union(Map{ 111 |-> d[14+1] }->union(Map{ 112 |-> d[15+1] }->union(Map{ 113 |-> d[16+1] }->union(Map{ 114 |-> d[17+1] }->union(Map{ 115 |-> d[18+1] }->union(Map{ 116 |-> d[19+1] }->union(Map{ 117 |-> d[20+1] }->union(Map{ 118 |-> d[21+1] }->union(Map{ 119 |-> d[22+1] }->union(Map{ 120 |-> d[23+1] }->union(Map{ 121 |-> d[24+1] }->union(Map{ 122 |-> d[25+1] }))))))))))))))))))))))))) ; s := s.translate(translation) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNthOccur(string,ch,N): occur=0 ; for i in range(len(string)): if(string[i]==ch): occur+=1 ; if(occur==N): return i ; return-1 ; if __name__=="__main__" : string="geeks" ; ch='e' ; N=2 ; print(findNthOccur(string,ch,N)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( string := "geeks"; ; ch := 'e'; ; N := 2; ; execute (findNthOccur(string, ch, N))->display(); ) else skip; operation findNthOccur(string : OclAny, ch : OclAny, N : OclAny) pre: true post: true activity: var occur : int := 0; ; for i : Integer.subrange(0, (string)->size()-1) do ( if (string[i+1] = ch) then ( occur := occur + 1; ) else skip ; if (occur = N) then ( return i; ) else skip) ; return -1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=map(int,input().split()) ab=[list(map(int,input().split()))for i in range(n)] ab.sort() dp=[[0 for i in range(t+1)]for j in range(n+1)] for i in range(n): ti,vi=ab[i] for j in range(t+1): if j+ti<=t : dp[i+1][j+ti]=max(dp[i+1][j+ti],dp[i][j]+vi) dp[i+1][j]=max(dp[i][j],dp[i+1][j]) ma=0 for i in range(n): ma=max(ma,dp[i][t-1]+ab[i][1]) print(ma) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ab : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; ab := ab->sort() ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, t + 1-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, n-1) do ( var ti : OclAny := null; var vi : OclAny := null; Sequence{ti,vi} := ab[i+1] ; for j : Integer.subrange(0, t + 1-1) do ( if (j + ti->compareTo(t)) <= 0 then ( dp[i + 1+1][j + ti+1] := Set{dp[i + 1+1][j + ti+1], dp[i+1][j+1] + vi}->max() ) else skip ; dp[i + 1+1][j+1] := Set{dp[i+1][j+1], dp[i + 1+1][j+1]}->max())) ; var ma : int := 0 ; for i : Integer.subrange(0, n-1) do ( ma := Set{ma, dp[i+1][t - 1+1] + ab[i+1][1+1]}->max()) ; execute (ma)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def is_prime(n): for i in range(2,int(math.sqrt(n))+1): if(n % i)==0 : return False return True n=int(input()) m=2 out=[] for i in range(2,n+2): if is_prime(i)==True : out.append('1') else : out.append('2') print(len(set(out))) print(' '.join(i for i in out)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := 2 ; var out : Sequence := Sequence{} ; for i : Integer.subrange(2, n + 2-1) do ( if is_prime(i) = true then ( execute (('1') : out) ) else ( execute (('2') : out) )) ; execute ((Set{}->union((out)))->size())->display() ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name out)))))))), ' '))->display(); operation is_prime(n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(2, ("" + (((n)->sqrt())))->toInteger() + 1-1) do ( if (n mod i) = 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=[int(_)for _ in open(0).read().split()] N,T=I[: 2] A,B=I[2 : : 2],I[3 : : 2] dp=[-1]*6001 dp[0]=0 for a,b in sorted(zip(A,B)): for k in range(T-1,-1,-1): if dp[k]==-1 : continue dp[k+a]=max(dp[k+a],dp[k]+b) print(max(dp)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : Sequence := open(0).readAll().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var N : OclAny := null; var T : OclAny := null; Sequence{N,T} := I.subrange(1,2) ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := Sequence{I(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))),I(subscript (test (logical_test (comparison (expr (atom (number (integer 3))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))} ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, 6001) ; dp->first() := 0 ; for _tuple : Integer.subrange(1, A->size())->collect( _indx | Sequence{A->at(_indx), B->at(_indx)} )->sort() do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); for k : Integer.subrange(-1 + 1, T - 1)->reverse() do ( if dp[k+1] = -1 then ( continue ) else skip ; dp[k + a+1] := Set{dp[k + a+1], dp[k+1] + b}->max())) ; execute ((dp)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from operator import itemgetter input=sys.stdin.readline TIME=0 VAL=1 N,T=[int(a)for a in input().split()] time_value=[(-1,-1)]+[None]*(N) for i in range(1,N+1): time_value[i]=tuple(int(a)for a in input().split()) time_value.sort(key=itemgetter(VAL)) dp=[[-1]*T for _ in range(N+1)] for t in range(0,T): dp[0][t]=0 for n in range(1,N+1): dp[n][0]=0 for t in range(1,T): if time_value[n][TIME]>t : dp[n][t]=dp[n-1][t] else : dp[n][t]=max(dp[n-1][t],time_value[n][VAL]+dp[n-1][t-time_value[n][TIME]]) val_acum=time_value[N][VAL] t=T-1 max_val=val_acum+dp[N-1][t] for n in range(N-1,0,-1): val_acum+=time_value[n][VAL] t-=time_value[n+1][TIME] if t<0 : break else : max_val=max(max_val,val_acum+dp[n-1][t]) print(max_val) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var TIME : int := 0 ; var VAL : int := 1 ; var N : OclAny := null; var T : OclAny := null; Sequence{N,T} := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; var time_value : Sequence := Sequence{ Sequence{-1, -1} }->union(MatrixLib.elementwiseMult(Sequence{ null }, (N))) ; for i : Integer.subrange(1, N + 1-1) do ( time_value[i+1] := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( )))))))))) ; time_value := time_value->sort() ; var dp : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ -1 }, T))) ; for t : Integer.subrange(0, T-1) do ( dp->first()[t+1] := 0) ; for n : Integer.subrange(1, N + 1-1) do ( dp[n+1]->first() := 0 ; for t : Integer.subrange(1, T-1) do ( if (time_value[n+1][TIME+1]->compareTo(t)) > 0 then ( dp[n+1][t+1] := dp[n - 1+1][t+1] ) else ( dp[n+1][t+1] := Set{dp[n - 1+1][t+1], time_value[n+1][VAL+1] + dp[n - 1+1][t - time_value[n+1][TIME+1]+1]}->max() ))) ; var val_acum : OclAny := time_value[N+1][VAL+1] ; var t : double := T - 1 ; var max_val : OclAny := val_acum + dp[N - 1+1][t+1] ; for n : Integer.subrange(0 + 1, N - 1)->reverse() do ( val_acum := val_acum + time_value[n+1][VAL+1] ; t := t - time_value[n + 1+1][TIME+1] ; if t < 0 then ( break ) else ( max_val := Set{max_val, val_acum + dp[n - 1+1][t+1]}->max() )) ; execute (max_val)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N,T=(int(i)for i in input().split()) AB=[[int(i)for i in input().split()]for j in range(N)] A=[a[0]for a in AB] B=[b[1]for b in AB] dp1=[[0]*(T+1)for i in range(N+2)] for i in range(1,N+1): for j in range(T): dp1[i][j]=max(dp1[i][j],dp1[i-1][j]) if j+A[i-1]select(j | true)->collect(j | (input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())))) ; var A : Sequence := AB->select(a | true)->collect(a | (a->first())) ; var B : Sequence := AB->select(b | true)->collect(b | (b[1+1])) ; var dp1 : Sequence := Integer.subrange(0, N + 2-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (T + 1)))) ; for i : Integer.subrange(1, N + 1-1) do ( for j : Integer.subrange(0, T-1) do ( dp1[i+1][j+1] := Set{dp1[i+1][j+1], dp1[i - 1+1][j+1]}->max() ; if (j + A[i - 1+1]->compareTo(T)) < 0 then ( dp1[i+1][j + A[i - 1+1]+1] := Set{dp1[i+1][j + A[i - 1+1]+1], dp1[i - 1+1][j+1] + B[i - 1+1]}->max() ) else skip)) ; var dp2 : Sequence := Integer.subrange(0, N + 2-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (T + 1)))) ; for i : range(1, N + 1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( for j : Integer.subrange(0, T-1) do ( dp2[i+1][j+1] := Set{dp2[i+1][j+1], dp2[i + 1+1][j+1]}->max() ; if (j + A[i - 1+1]->compareTo(T)) < 0 then ( dp2[i+1][j + A[i - 1+1]+1] := Set{dp2[i+1][j + A[i - 1+1]+1], dp2[i + 1+1][j+1] + B[i - 1+1]}->max() ) else skip)) ; var ans : int := 0 ; for i : Integer.subrange(1, N + 1-1) do ( for j : Integer.subrange(0, T-1) do ( ans := Set{ans, dp1[i - 1+1][j+1] + dp2[i + 1+1][T - 1 - j+1] + B[i - 1+1]}->max())) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def MAP(): return list(map(int,input().split())) def INT(): return int(input()) def FLOAT(): return float(input()) MOD=10**9+7 n,t=MAP() dp=[0]*6005 ab=[] for i in range(n): ab.append(MAP()) ab.sort(key=lambda x : x[0]) for u in ab : for i in range(6004-u[0],-1,-1): if ipow(9) + 7 ; var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := MAP() ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 6005) ; var ab : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((MAP()) : ab)) ; ab := ab->sort() ; for u : ab do ( for i : Integer.subrange(-1 + 1, 6004 - u->first())->reverse() do ( if (i->compareTo(t)) < 0 then ( dp[i + u->first()+1] := Set{dp[i + u->first()+1], dp[i+1] + u[1+1]}->max() ) else skip)) ; execute ((dp)->max())->display(); operation MAP() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation FLOAT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter def most_frequent(List): occurence_count=Counter(List) return occurence_count.most_common(1)[0][0] list=list(map(int,input().split())) o=0 a1=[] b=most_frequent(list) for num in list : if num==b : o=o+1 else : a1.append(num) if o==6 : print('Elephant') if o==5 : print('Bear') if o==4 : if a1[0]==a1[1]: print('Elephant') else : print('Bear') if 4>o : print('Alien') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var OclType["Sequence"] : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var o : int := 0 ; var a1 : Sequence := Sequence{} ; var b : OclAny := most_frequent(OclType["Sequence"]) ; for num : OclType["Sequence"] do ( if num = b then ( o := o + 1 ) else ( execute ((num) : a1) )) ; if o = 6 then ( execute ('Elephant')->display() ) else skip ; if o = 5 then ( execute ('Bear')->display() ) else skip ; if o = 4 then ( if a1->first() = a1[1+1] then ( execute ('Elephant')->display() ) else ( execute ('Bear')->display() ) ) else skip ; if 4 > o then ( execute ('Alien')->display() ) else skip; operation most_frequent(List : OclAny) : OclAny pre: true post: true activity: var occurence_count : OclAny := Counter(List) ; return occurence_count.most_common(1)->first()->first(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): val=input() list=[] list=val.split(" ") list.sort() if list[0]==list[5]: print("Elephant") elif(list[0]==list[3]and list[4]!=list[5]): print("Bear") elif(list[1]==list[4]and list[0]!=list[5]): print("Bear") elif(list[2]==list[5]and list[1]!=list[0]): print("Bear") elif(list[0]==list[3]and list[4]==list[5]): print("Elephant") elif(list[1]==list[4]and list[0]==list[5]): print("Elephant") elif(list[2]==list[5]and list[1]==list[0]): print("Elephant") else : print("Alien") if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var val : String := (OclFile["System.in"]).readLine() ; var OclType["Sequence"] : Sequence := Sequence{} ; OclType["Sequence"] := val.split(" ") ; OclType["Sequence"] := OclType["Sequence"]->sort() ; if ->first() = [5+1] then ( execute ("Elephant")->display() ) else (if (->first() = [3+1] & [4+1] /= [5+1]) then ( execute ("Bear")->display() ) else (if ([1+1] = [4+1] & ->first() /= [5+1]) then ( execute ("Bear")->display() ) else (if ([2+1] = [5+1] & [1+1] /= ->first()) then ( execute ("Bear")->display() ) else (if (->first() = [3+1] & [4+1] = [5+1]) then ( execute ("Elephant")->display() ) else (if ([1+1] = [4+1] & ->first() = [5+1]) then ( execute ("Elephant")->display() ) else (if ([2+1] = [5+1] & [1+1] = ->first()) then ( execute ("Elephant")->display() ) else ( execute ("Alien")->display() ) ) ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- nums=[int(e)for e in input().split()] print(nums[0]*nums[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var nums : Sequence := input().split()->select(e | true)->collect(e | (("" + ((e)))->toInteger())) ; execute (nums->first() * nums[1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from collections import Counter w=Counter(map(int,input().split())) if max(w.values())==6 or(max(w.values())==4 and min(w.values())==2): print('Elephant') elif max(w.values())<4 : print('Alien') else : print('Bear') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var w : OclAny := Counter((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (w.values())->max() = 6 or ((w.values())->max() = 4 & (w.values())->min() = 2) then ( execute ('Elephant')->display() ) else (if (w.values())->max() < 4 then ( execute ('Alien')->display() ) else ( execute ('Bear')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sticks=list(map(int,input().split())) sticks.sort() hb=[(0,5),(4,5),(0,1)] for head,body in hb : cur=sticks[3] flag=True for i in range(6): if i!=head and i!=body : if sticks[i]!=cur : flag=False break if not flag : continue if sticks[head]collect( _x | (OclType["int"])->apply(_x) )) ; sticks := sticks->sort() ; var hb : Sequence := Sequence{Sequence{0, 5}}->union(Sequence{Sequence{4, 5}}->union(Sequence{ Sequence{0, 1} })) ; for _tuple : hb do (var _indx : int := 1; var head : OclAny := _tuple->at(_indx); _indx := _indx + 1; var body : OclAny := _tuple->at(_indx); var cur : OclAny := sticks[3+1] ; var flag : boolean := true ; for i : Integer.subrange(0, 6-1) do ( if i /= head & i /= body then ( if sticks[i+1] /= cur then ( flag := false ; break ) else skip ) else skip) ; if not(flag) then ( continue ) else skip ; if (sticks[head+1]->compareTo(sticks[body+1])) < 0 then ( execute ("Bear")->display() ) else ( execute ("Elephant")->display() ) ; exit()) ; execute ("Alien")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=list(map(int,input().split())) a.sort() if a[0]==a[5]or(a[0]==a[1]and a[2]==a[5])or(a[0]==a[3]and a[4]==a[5]): print('Elephant') elif(a[0]==a[3])or(a[1]==a[4])or(a[2]==a[5]): print('Bear') else : print('Alien') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; if a->first() = a[5+1] or (a->first() = a[1+1] & a[2+1] = a[5+1]) or (a->first() = a[3+1] & a[4+1] = a[5+1]) then ( execute ('Elephant')->display() ) else (if (a->first() = a[3+1]) or (a[1+1] = a[4+1]) or (a[2+1] = a[5+1]) then ( execute ('Bear')->display() ) else ( execute ('Alien')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): LIMIT=10**15 MODULUS=10**9 splitcount=eulerlib.sqrt(LIMIT) splitat=LIMIT//(splitcount+1) def sum_squares(s,e): return(e*(e+1)*(e*2+1)-s*(s+1)*(s*2+1))//6 ans=sum((i*i*(LIMIT//i))for i in range(1,splitat+1)) ans+=sum((sum_squares(LIMIT//(i+1),LIMIT//i)*i)for i in range(1,splitcount+1)) return str(ans % MODULUS) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LIMIT : double := (10)->pow(15) ; var MODULUS : double := (10)->pow(9) ; var splitcount : double := eulerlib.sqrt(LIMIT) ; var splitat : int := LIMIT div (splitcount + 1) ; skip ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name i))) * (expr (atom (name i)))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name LIMIT))) // (expr (atom (name i)))))))) )))))))) )))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name splitat))) + (expr (atom (number (integer 1)))))))))) )))))))))->sum() ; ans := ans + ((argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name sum_squares)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name LIMIT))) // (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) )))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name LIMIT))) // (expr (atom (name i))))))))) )))) * (expr (atom (name i)))))))) )))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name splitcount))) + (expr (atom (number (integer 1)))))))))) )))))))))->sum() ; return ("" + ((ans mod MODULUS))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import(division,absolute_import,print_function,unicode_literals) from sys import stdin import re for line in stdin : stack=[] for s in line.split(): if re.match('[-+]?\d+',s): stack.append(float(s)) elif s=='+' : n=stack.pop() stack[-1]+=n elif s=='-' : n=stack.pop() stack[-1]-=n elif s=='*' : n=stack.pop() stack[-1]*=n elif s=='/' : n=stack.pop() stack[-1]/=n print('{:.6f}'.format(stack[-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; for line : stdin do ( var stack : Sequence := Sequence{} ; for s : line.split() do ( if (s)->firstMatch("^" + '[-+]?\d+' + ".*") then ( execute ((("" + ((s)))->toReal()) : stack) ) else (if s = '+' then ( var n : OclAny := stack->last() ; stack := stack->front() ; stack->last() := stack->last() + n ) else (if s = '-' then ( n := stack->last() ; stack := stack->front() ; stack->last() := stack->last() - n ) else (if s = '*' then ( n := stack->last() ; stack := stack->front() ; stack->last() := stack->last() * n ) else (if s = '/' then ( n := stack->last() ; stack := stack->front() ; stack->last() := stack->last() / n ) else skip ) ) ) ) ) ; execute (StringLib.interpolateStrings('{:.6f}', Sequence{stack->last()}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) result=[] for _ in range(t): n,m=map(int,input().split()) out=[0,0] if n<5 : out[0]=n//2 if m<5 : out[1]=m//2 result.append(out) for a,b in result : print(a+1,b+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var result : Sequence := Sequence{} ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var out : Sequence := Sequence{0}->union(Sequence{ 0 }) ; if n < 5 then ( out->first() := n div 2 ) else skip ; if m < 5 then ( out[1+1] := m div 2 ) else skip ; execute ((out) : result)) ; for _tuple : result do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); execute (a + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n,m=map(int,input().split()) print(n//2+1,m//2+1) for t in range(0,int(input())): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve()); operation solve() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (n div 2 + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=[int(i)for i in input().split()] if n[0]<3 and n[1]<3 : print(n[0],n[1]) elif n[0]==3 and n[1]==3 : print(2,2) elif n[0]<3 and n[1]==3 : print(n[0],n[1]-1) elif n[0]==3 and n[1]<3 : print(n[0]-1,n[1]) else : print(n[0],n[1]) n=[] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if n->first() < 3 & n[1+1] < 3 then ( execute (n->first())->display() ) else (if n->first() = 3 & n[1+1] = 3 then ( execute (2)->display() ) else (if n->first() < 3 & n[1+1] = 3 then ( execute (n->first())->display() ) else (if n->first() = 3 & n[1+1] < 3 then ( execute (n->first() - 1)->display() ) else ( execute (n->first())->display() ) ) ) ) ; n := Sequence{}); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for __ in range(t): (n,m)=map(int,input().split()) if(n==1 or m==1): print(n,m) elif(n>3 or m>3): print((n-1),(m-1)) else : print(2,2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for __ : Integer.subrange(0, t-1) do ( ; var Sequence{n, m} : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (n = 1 or m = 1) then ( execute (n)->display() ) else (if (n > 3 or m > 3) then ( execute ((n - 1))->display() ) else ( execute (2)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: print(*(i+1>>1 for i in map(int,s.split()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))) >> (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name s)) (trailer . (name split) (arguments ( ))))))))) )))))))) ))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nth_term(a,b,n): z=0 if(n % 6==1): z=a elif(n % 6==2): z=b elif(n % 6==3): z=b-a elif(n % 6==4): z=-a elif(n % 6==5): z=-b if(n % 6==0): z=-(b-a) return z if __name__=='__main__' : a=10 b=17 n=3 print(nth_term(a,b,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := 10 ; b := 17 ; n := 3 ; execute (nth_term(a, b, n))->display() ) else skip; operation nth_term(a : OclAny, b : OclAny, n : OclAny) : OclAny pre: true post: true activity: var z : int := 0 ; if (n mod 6 = 1) then ( z := a ) else (if (n mod 6 = 2) then ( z := b ) else (if (n mod 6 = 3) then ( z := b - a ) else (if (n mod 6 = 4) then ( z := -a ) else (if (n mod 6 = 5) then ( z := -b ) else skip ) ) ) ) ; if (n mod 6 = 0) then ( z := -(b - a) ) else skip ; return z; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k,z=map(int,input().split()) a=[int(x)for x in input().split()] ans=0 s=0 mx=0 for i in range(k+1): if itoInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; var z : OclAny := null; Sequence{n,k,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : int := 0 ; var s : int := 0 ; var mx : int := 0 ; for i : Integer.subrange(0, k + 1-1) do ( if (i->compareTo(n - 1)) < 0 then ( mx := Set{mx, a[i+1] + a[i + 1+1]}->max() ) else skip ; s := s + a[i+1] ; if i mod 2 = k mod 2 then ( var tmp : int := (k - i) div 2 ; if (tmp->compareTo(z)) <= 0 then ( ans := Set{ans, s + mx * tmp}->max() ) else skip ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k,z=map(int,input().split()) a=[int(x)for x in input().split()] ans=0 s=0 mx=0 for t in range(z+1): pos=k-2*t if pos<0 : continue mx=0 s=0 for i in range(pos+1): if itoInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; var z : OclAny := null; Sequence{n,k,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : int := 0 ; var s : int := 0 ; var mx : int := 0 ; for t : Integer.subrange(0, z + 1-1) do ( var pos : double := k - 2 * t ; if pos < 0 then ( continue ) else skip ; mx := 0 ; s := 0 ; for i : Integer.subrange(0, pos + 1-1) do ( if (i->compareTo(n - 1)) < 0 then ( mx := Set{mx, a[i+1] + a[i + 1+1]}->max() ) else skip ; s := s + a[i+1]) ; ans := Set{ans, s + mx * t}->max()) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def solve(a,k,z): r=-math.inf if k>1 : r=sum(a[: k])+max(a[i]+a[i+1]for i in range(k-1))*z if k>0 and z>0 : r=max(r,sum(a[: k])+(a[k-1]+a[k])*z) return r for _ in range(int(input())): n,k,z=map(int,input().split()) a=list(map(int,input().split())) print(max(solve(a,k-z*2+1,z)for z in range(z+1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; Sequence{n,k,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (((argument (test (logical_test (comparison (expr (atom (name solve)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (expr (expr (atom (name k))) - (expr (expr (atom (name z))) * (expr (atom (number (integer 2)))))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name z)))))))) ))))))) (comp_for for (exprlist (expr (atom (name z)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name z))) + (expr (atom (number (integer 1)))))))))) )))))))))->max())->display()); operation solve(a : OclAny, k : OclAny, z : OclAny) : OclAny pre: true post: true activity: var r : OclAny := - ; if k > 1 then ( r := (a.subrange(1,k))->sum() + ((argument (test (logical_test (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name k))) - (expr (atom (number (integer 1)))))))))) )))))))))->max() * z ) else skip ; if k > 0 & z > 0 then ( r := Set{r, (a.subrange(1,k))->sum() + (a[k - 1+1] + a[k+1]) * z}->max() ) else skip ; return r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(a,k,z): r=sum(a[: k]) if z>0 : r+=max(a[i]+a[i+1]for i in range(k))*z return r for _ in range(int(input())): n,k,z=map(int,input().split()) a=list(map(int,input().split())) print(max(solve(a,k-z*2+1,z)for z in range(z+1)if z*2<=k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; Sequence{n,k,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (((argument (test (logical_test (comparison (expr (atom (name solve)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (expr (expr (atom (name k))) - (expr (expr (atom (name z))) * (expr (atom (number (integer 2)))))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name z)))))))) ))))))) (comp_for for (exprlist (expr (atom (name z)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name z))) + (expr (atom (number (integer 1)))))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (expr (atom (name z))) * (expr (atom (number (integer 2)))))) <= (comparison (expr (atom (name k)))))))))))->max())->display()); operation solve(a : OclAny, k : OclAny, z : OclAny) : OclAny pre: true post: true activity: var r : OclAny := (a.subrange(1,k))->sum() ; if z > 0 then ( r := r + ((argument (test (logical_test (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name k)))))))) )))))))))->max() * z ) else skip ; return r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) l,r=-1,-1 for i in range(n): if arr[i]!=i+1 : l=i break for i in range(n-1,-1,-1): if arr[i]!=i+1 : r=i break s=r+1 for i in range(l,s): if arr[i]==s : s-=1 continue else : print(0,0) exit(0) print(l+1,r+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{-1,-1} ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] /= i + 1 then ( var l : OclAny := i ; break ) else skip) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if arr[i+1] /= i + 1 then ( var r : OclAny := i ; break ) else skip) ; var s : OclAny := r + 1 ; for i : Integer.subrange(l, s-1) do ( if arr[i+1] = s then ( s := s - 1 ; continue ) else ( execute (0)->display() ; exit(0) )) ; execute (l + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys f=sys.stdin from collections import deque import operator func={'+' : operator.add,'-' : operator.sub,'*' : operator.mul,'/' : operator.truediv} for line in f : stack=deque() for element in line.strip().split(): if element in func : b=stack.pop() a=stack.pop() stack.append(func[element](a,b)) else : stack.append(float(element)) print('{:.6f}'.format(stack[0])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var f : OclFile := OclFile["System.in"] ; skip ; skip ; var func : Map := Map{ '+' |-> operator.add }->union(Map{ '-' |-> operator.sub }->union(Map{ '*' |-> operator.mul }->union(Map{ '/' |-> operator.truediv }))) ; for line : f do ( var stack : Sequence := () ; for element : line->trim().split() do ( if (func)->includes(element) then ( var b : OclAny := stack->last() ; stack := stack->front() ; var a : OclAny := stack->last() ; stack := stack->front() ; execute ((func[element+1](a, b)) : stack) ) else ( execute ((("" + ((element)))->toReal()) : stack) )) ; execute (StringLib.interpolateStrings('{:.6f}', Sequence{stack->first()}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) data=input().split() data2=[] for i in range(n): if str(i+1)!=data[i]: data2.append((data[i],i)) data2.reverse() if data2 : o=list(range(1,n+1)) can=True for i in range(len(data2)): if o.index(int(data2[i][0]))!=int(data2[-i-1][1]): can=False break if can : print(str(data2[-1][1]+1)+" "+str(data2[0][1]+1)) else : print("0 0") else : print("0 0") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var data : OclAny := input().split() ; var data2 : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if ("" + ((i + 1))) /= data[i+1] then ( execute ((Sequence{data[i+1], i}) : data2) ) else skip) ; data2 := data2->reverse() ; if data2 then ( var o : Sequence := (Integer.subrange(1, n + 1-1)) ; var can : boolean := true ; for i : Integer.subrange(0, (data2)->size()-1) do ( if o->indexOf(("" + ((data2[i+1]->first())))->toInteger()) - 1 /= ("" + ((data2->reverse()->at(-(-i - 1))[1+1])))->toInteger() then ( can := false ; break ) else skip) ; if can then ( execute (("" + ((data2->last()[1+1] + 1))) + " " + ("" + ((data2->first()[1+1] + 1))))->display() ) else ( execute ("0 0")->display() ) ) else ( execute ("0 0")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) a=[0]+list(map(int,input().split())) l,r=0,0 for i in range(n+1): if i ^ a[i]: l=i break for i in range(n,-1,-1): if i ^ a[i]: r=i break x=[a[i]for i in range(l,r+1)] x.reverse() for i in range(len(x)): a[i+l]=x[i] for i in range(n+1): if i ^ a[i]: l,r=0,0 break print(l,r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,0} ; for i : Integer.subrange(0, n + 1-1) do ( if MathLib.bitwiseXor(i, a[i+1]) then ( var l : OclAny := i ; break ) else skip) ; for i : Integer.subrange(-1 + 1, n)->reverse() do ( if MathLib.bitwiseXor(i, a[i+1]) then ( var r : OclAny := i ; break ) else skip) ; var x : Sequence := Integer.subrange(l, r + 1-1)->select(i | true)->collect(i | (a[i+1])) ; x := x->reverse() ; for i : Integer.subrange(0, (x)->size()-1) do ( a[i + l+1] := x[i+1]) ; for i : Integer.subrange(0, n + 1-1) do ( if MathLib.bitwiseXor(i, a[i+1]) then ( Sequence{l,r} := Sequence{0,0} ; break ) else skip) ; execute (l)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=list(map(int,input().split())) mn,mx=N+1,-1 for i in range(N): if(i+1!=A[i]): mn=min(mn,i) mx=max(mx,i) if(mx==-1): print('0 0') else : A=A[: mn]+A[mn :(mx+1)][: :-1]+A[(mx+1):] if(sorted(A)==A): print(mn+1,mx+1) else : print('0 0') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mn : OclAny := null; var mx : OclAny := null; Sequence{mn,mx} := Sequence{N + 1,-1} ; for i : Integer.subrange(0, N-1) do ( if (i + 1 /= A[i+1]) then ( var mn : OclAny := Set{mn, i}->min() ; var mx : OclAny := Set{mx, i}->max() ) else skip) ; if (mx = -1) then ( execute ('0 0')->display() ) else ( A := A.subrange(1,mn) + A.subrange(mn+1, (mx + 1))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) + A.subrange((mx + 1)+1) ; if (A->sort() = A) then ( execute (mn + 1)->display() ) else ( execute ('0 0')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=list(map(int,input().split())) mn,mx=N+1,-1 for i in range(N): if(i+1!=A[i]): mn=min(mn,i) mx=max(mx,i) if(mx==-1): print('0 0') else : A=A[: mn]+A[mn :(mx+1)][: :-1]+A[(mx+1):] if(sorted(A)==A): print(mn+1,mx+1) else : print('0 0') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mn : OclAny := null; var mx : OclAny := null; Sequence{mn,mx} := Sequence{N + 1,-1} ; for i : Integer.subrange(0, N-1) do ( if (i + 1 /= A[i+1]) then ( var mn : OclAny := Set{mn, i}->min() ; var mx : OclAny := Set{mx, i}->max() ) else skip) ; if (mx = -1) then ( execute ('0 0')->display() ) else ( A := A.subrange(1,mn) + A.subrange(mn+1, (mx + 1))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) + A.subrange((mx + 1)+1) ; if (A->sort() = A) then ( execute (mn + 1)->display() ) else ( execute ('0 0')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSubSequence(s,num): res=0 i=0 while(num): if(num & 1): res+=ord(s[i])-ord('0') i+=1 num=num>>1 return res def combinedSum(s): n=len(s) c_sum=0 ran=(1<display() ) else skip; operation findSubSequence(s : OclAny, num : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; var i : int := 0 ; while (num) do ( if (MathLib.bitwiseAnd(num, 1)) then ( res := res + (s[i+1])->char2byte() - ('0')->char2byte() ) else skip ; i := i + 1 ; num := num /(2->pow(1))) ; return res; operation combinedSum(s : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; var c_sum : int := 0 ; var ran : double := (1 * (2->pow(n))) - 1 ; for i : Integer.subrange(0, ran + 1-1) do ( c_sum := c_sum + findSubSequence(s, i)) ; return c_sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lst=[list(map(int,input().split()))for _ in range(n)] a_start=[x[0]*60+x[1]for x in lst] a_end=[x[2]*60+x[3]for x in lst] h_start=[x[4]*60+x[5]for x in lst] h_end=[x[6]*60+x[7]for x in lst] b_start=[x[8]*60+x[9]for x in lst] b_end=[x[10]*60+x[11]for x in lst] def make_sets(start,end): sets=[] member=[] for i in range(1440): upd=False for j in range(n): if start[j]==i : member.append(j) upd=True if end[j]==i-1 : member.remove(j) upd=True if upd : sets.append(set(member)) return sets a_sets=make_sets(a_start,a_end) h_sets=make_sets(h_start,h_end) b_sets=make_sets(b_start,b_end) ans=0 for s1 in a_sets : for s2 in h_sets : for s3 in b_sets : ans=max(ans,len(s1 & s2 & s3)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var a_start : Sequence := lst->select(x | true)->collect(x | (x->first() * 60 + x[1+1])) ; var a_end : Sequence := lst->select(x | true)->collect(x | (x[2+1] * 60 + x[3+1])) ; var h_start : Sequence := lst->select(x | true)->collect(x | (x[4+1] * 60 + x[5+1])) ; var h_end : Sequence := lst->select(x | true)->collect(x | (x[6+1] * 60 + x[7+1])) ; var b_start : Sequence := lst->select(x | true)->collect(x | (x[8+1] * 60 + x[9+1])) ; var b_end : Sequence := lst->select(x | true)->collect(x | (x[10+1] * 60 + x[11+1])) ; skip ; var a_sets : OclAny := make_sets(a_start, a_end) ; var h_sets : OclAny := make_sets(h_start, h_end) ; var b_sets : OclAny := make_sets(b_start, b_end) ; var ans : int := 0 ; for s1 : a_sets do ( for s2 : h_sets do ( for s3 : b_sets do ( ans := Set{ans, (MathLib.bitwiseAnd(MathLib.bitwiseAnd(s1, s2), s3))->size()}->max()))) ; execute (ans)->display(); operation make_sets(start : OclAny, end : OclAny) : OclAny pre: true post: true activity: var sets : Sequence := Sequence{} ; var member : Sequence := Sequence{} ; for i : Integer.subrange(0, 1440-1) do ( var upd : boolean := false ; for j : Integer.subrange(0, n-1) do ( if start[j+1] = i then ( execute ((j) : member) ; upd := true ) else skip ; if end[j+1] = i - 1 then ( execute ((j) /: member) ; upd := true ) else skip) ; if upd then ( execute ((Set{}->union((member))) : sets) ) else skip) ; return sets; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_two_int(): two_int=input().split() for i in range(2): two_int[i]=int(two_int[i]) return two_int def distribute_stone(candidate_num,stone_num): bowl_stone=stone_num candidate_list=[0]*candidate_num i=0 while True : order=i % candidate_num if bowl_stone!=0 : candidate_list[order]+=1 bowl_stone-=1 elif bowl_stone==0 and candidate_list[order]==stone_num : return order else : bowl_stone=candidate_list[order] candidate_list[order]=0 i+=1 if __name__=="__main__" : while True : candidate_num,stone_num=get_two_int() if candidate_num==0 : break order=distribute_stone(candidate_num,stone_num) print(order) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( while true do ( Sequence{candidate_num,stone_num} := get_two_int() ; if candidate_num = 0 then ( break ) else skip ; order := distribute_stone(candidate_num, stone_num) ; execute (order)->display()) ) else skip; operation get_two_int() : OclAny pre: true post: true activity: var two_int : OclAny := input().split() ; for i : Integer.subrange(0, 2-1) do ( two_int[i+1] := ("" + ((two_int[i+1])))->toInteger()) ; return two_int; operation distribute_stone(candidate_num : OclAny, stone_num : OclAny) pre: true post: true activity: var bowl_stone : OclAny := stone_num ; var candidate_list : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, candidate_num) ; var i : int := 0 ; while true do ( var order : int := i mod candidate_num ; if bowl_stone /= 0 then ( candidate_list[order+1] := candidate_list[order+1] + 1 ; bowl_stone := bowl_stone - 1 ) else (if bowl_stone = 0 & candidate_list[order+1] = stone_num then ( return order ) else ( bowl_stone := candidate_list[order+1] ; candidate_list[order+1] := 0 ) ) ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math input=sys.stdin.readline n,p=input().rstrip().split() n,p=int(n),int(p) while n+p!=0 : tegoma=[0]*n owan=p pivot=0 finish_flag=False while finish_flag is False : if owan!=0 : owan=owan-1 tegoma[pivot]=tegoma[pivot]+1 else : if tegoma[pivot-1]==p : finish_flag=True owan=tegoma[pivot] tegoma[pivot]=0 pivot=(pivot+1)% n print((pivot-2)% n) n,p=input().rstrip().split() n,p=int(n),int(p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := input().rstrip().split() ; var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := Sequence{("" + ((n)))->toInteger(),("" + ((p)))->toInteger()} ; while n + p /= 0 do ( var tegoma : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var owan : OclAny := p ; var pivot : int := 0 ; var finish_flag : boolean := false ; while finish_flag <>= false do ( if owan /= 0 then ( owan := owan - 1 ; tegoma[pivot+1] := tegoma[pivot+1] + 1 ) else ( if tegoma[pivot - 1+1] = p then ( finish_flag := true ) else skip ; owan := tegoma[pivot+1] ; tegoma[pivot+1] := 0 ) ; pivot := (pivot + 1) mod n) ; execute ((pivot - 2) mod n)->display() ; var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := input().rstrip().split() ; var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := Sequence{("" + ((n)))->toInteger(),("" + ((p)))->toInteger()}); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from copy import copy while True : n,p=map(int,input().split()) if n==0 : break l=[0 for _ in range(n)] a=-1 p1=copy(p) while True : a+=1 if a==n : a=0 if p>0 : if l[a]+1==p1 : print(a) break l[a]+=1 p-=1 continue if p==0 : p=l[a] l[a]=0 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var l : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)) ; var a : int := -1 ; var p1 : OclAny := copy(p) ; while true do ( a := a + 1 ; if a = n then ( a := 0 ) else skip ; if p > 0 then ( if l[a+1] + 1 = p1 then ( execute (a)->display() ; break ) else skip ; l[a+1] := l[a+1] + 1 ; p := p - 1 ; continue ) else skip ; if p = 0 then ( var p : OclAny := l[a+1] ; l[a+1] := 0 ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**3 eps=1.0/10**10 mod=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] while True : n,p=LI() mp=p if n==0 : break a=[0]*n i=0 while True : if p==0 : p=a[i] a[i]=0 else : a[i]+=1 p-=1 if a[i]==mp : break i=(i+1)% n rr.append(i) return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(3) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := LI() ; var mp : OclAny := p ; if n = 0 then ( break ) else skip ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var i : int := 0 ; while true do ( if p = 0 then ( var p : OclAny := a[i+1] ; a[i+1] := 0 ) else ( a[i+1] := a[i+1] + 1 ; p := p - 1 ; if a[i+1] = mp then ( break ) else skip ) ; i := (i + 1) mod n) ; execute ((i) : rr)) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout,stderr while 1 : n,p=map(int,stdin.readline().split()) if n+p==0 : break a=[0]*n wan=p for i in range(10**6): if wan>0 : a[i % n]+=1 wan-=1 else : wan+=a[i % n] a[i % n]=0 if a[i % n]==p : print(i % n) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while 1 do ( var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n + p = 0 then ( break ) else skip ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var wan : OclAny := p ; for i : Integer.subrange(0, (10)->pow(6)-1) do ( if wan > 0 then ( a[i mod n+1] := a[i mod n+1] + 1 ; wan := wan - 1 ) else ( wan := wan + a[i mod n+1] ; a[i mod n+1] := 0 ) ; if a[i mod n+1] = p then ( execute (i mod n)->display() ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Stack : def __init__(self): self.items=[] def push(self,item): self.items.append(item) def pop(self): return self.items.pop() def size(self): return len(self.items) s=Stack() while True : try : a=list(input().split()) except EOFError : break for token in a : if token in['+','-','*','/']: v1,v2=s.pop(),s.pop() if token=='+' : v2+=v1 elif token=='-' : v2-=v1 elif token=='*' : v2*=v1 else : v2/=v1 s.push(v2) else : s.push(int(token)) print(s.pop()) ------------------------------------------------------------ OCL File: --------- class Stack { static operation newStack() : Stack pre: true post: Stack->exists( _x | result = _x ); attribute items : Sequence := Sequence{}; operation initialise() : Stack pre: true post: true activity: self.items := Sequence{}; return self; operation push(item : OclAny) pre: true post: true activity: (expr (atom (name self)) (trailer . (name items)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name item)))))))) )))); operation pop() : OclAny pre: true post: true activity: return self.items->last(); operation size() : OclAny pre: true post: true activity: return (self.items)->size(); } class FromPython { operation initialise() pre: true post: true activity: skip ; var s : Stack := (Stack.newStack()).initialise() ; while true do ( try ( var a : Sequence := (input().split())) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))) ; for token : a do ( if (Sequence{'+'}->union(Sequence{'-'}->union(Sequence{'*'}->union(Sequence{ '/' }))))->includes(token) then ( var v1 : OclAny := null; var v2 : OclAny := null; Sequence{v1,v2} := Sequence{s->last(),s->last()} ; if token = '+' then ( v2 := v2 + v1 ) else (if token = '-' then ( v2 := v2 - v1 ) else (if token = '*' then ( v2 := v2 * v1 ) else ( v2 := v2 / v1 ) ) ) ; s.push(v2) ) else ( s.push(("" + ((token)))->toInteger()) )) ; execute (s->last())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count_two_idx(A,q): ans=0 left=0 csum=0 for right in range(N): csum+=A[right] while csum>q : csum-=A[left] left+=1 ans+=right-left+1 return ans N,M=[int(x)for x in input().split()] A=list(map(int,input().split())) X=list(map(int,input().split())) for q in X : print(count_two_idx(A,q)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; A := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var X : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for q : X do ( execute (count_two_idx(A, q))->display()); operation count_two_idx(A : OclAny, q : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; var left : int := 0 ; var csum : int := 0 ; for right : Integer.subrange(0, N-1) do ( csum := csum + A[right+1] ; while (csum->compareTo(q)) > 0 do ( csum := csum - A[left+1] ; left := left + 1) ; ans := ans + right - left + 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from typing import Iterator def solve(x : int)->Iterator[int]: global cum_prev,cum end=0 it=iter(cum).__next__ nxt=it()-x for start,c in enumerate(cum_prev): while(nxt<=c): nxt=it()-x end+=1 yield end-start if __name__=="__main__" : N,Q=map(lambda x : int(x),input().split()) a=list(map(lambda x : int(x),input().split())) x=list(map(lambda x : int(x),input().split())) cum_prev=[0] cum=[] v=0 for elem in a : v+=elem cum_prev.append(v) cum.append(v) cum_prev.pop() cum.append(sys.maxsize) print("\n".join(map((lambda t : str(sum(t))),map(solve,x)))) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute cum_prev : OclAny; attribute cum : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( var N : OclAny := null; var Q : OclAny := null; Sequence{N,Q} := (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) )) ; var x : Sequence := ((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) )) ; cum_prev := Sequence{ 0 } ; cum := Sequence{} ; var v : int := 0 ; for elem : a do ( v := v + elem ; execute ((v) : cum_prev) ; execute ((v) : cum)) ; cum_prev := cum_prev->front() ; execute (((trailer . (name maxsize))) : cum) ; execute (StringLib.sumStringsWithSeparator((((x)->collect( _x | (solve)->apply(_x) ))->collect( _x | ((lambda t : OclAny in (("" + (((t)->sum()))))))->apply(_x) )), "\n"))->display() ) else skip; operation solve(x : int) : OclAny pre: true post: true activity: skip; skip ; var end : int := 0 ; var it : OclAny := iter(cum).__next__ ; var nxt : double := it() - x ; for _tuple : Integer.subrange(1, (cum_prev)->size())->collect( _indx | Sequence{_indx-1, (cum_prev)->at(_indx)} ) do (var _indx : int := 1; var start : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); while ((nxt->compareTo(c)) <= 0) do ( nxt := it() - x ; end := end + 1) ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return end - start); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_right def main(): N,Q=map(int,input().split()) a=[-1 for i in range(N)] sum=[0 for i in range(N+1)] for i,val in enumerate(input().split()): a[i]=int(val) sum[i+1]=sum[i]+a[i] X=list(map(int,input().split())) for x in X : ans=solve3(a,x,N,sum) print(ans) def solve1(a,x,N,sum): l,r=0,0 ret=0 while ll : ret+=(r-1-l) l+=1 return ret def solve2(a,x,N,sum): l,r,sum=0,0,0 ret=0 while lx : sum-=a[l] l+=1 ans+=r-l+1 return ans main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; main(); operation main() pre: true post: true activity: var N : OclAny := null; var Q : OclAny := null; Sequence{N,Q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (-1)) ; var sum : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (0)) ; for _tuple : Integer.subrange(1, (input().split())->size())->collect( _indx | Sequence{_indx-1, (input().split())->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var val : OclAny := _tuple->at(_indx); a[i+1] := ("" + ((val)))->toInteger() ; [i + 1+1]->sum() := [i+1]->sum() + a[i+1]) ; var X : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for x : X do ( var ans : OclAny := solve3(a, x, N, sum) ; execute (ans)->display()); operation solve1(a : OclAny, x : OclAny, N : OclAny, sum : OclAny) : OclAny pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,0} ; var ret : int := 0 ; while (l->compareTo(N)) < 0 do ( if (r->compareTo(N + 1)) < 0 then ( var r : OclAny := bisect_right(sum, [l+1]->sum() + x, r) ) else skip ; if (r->compareTo(l)) > 0 then ( ret := ret + (r - 1 - l) ) else skip ; l := l + 1) ; return ret; operation solve2(a : OclAny, x : OclAny, N : OclAny, sum : OclAny) : OclAny pre: true post: true activity: var l : OclAny := null; Sequence{l,r,sum} := Sequence{0,0,0} ; ret := 0 ; while (l->compareTo(N)) < 0 do ( while (r->compareTo(N)) < 0 & (sum->union(a[r+1])->compareTo(x)) <= 0 do ( sum := sum + a[r+1] ; r := r + 1) ; ret := ret + (r - l) ; sum := sum - a[l+1] ; l := l + 1) ; return ret; operation solve3(a : OclAny, x : OclAny, N : OclAny, sum : OclAny) : OclAny pre: true post: true activity: var l : OclAny := null; Sequence{l,sum,ans} := Sequence{0,0,0} ; for r : Integer.subrange(0, N-1) do ( sum := sum + a[r+1] ; while (sum->compareTo(x)) > 0 do ( sum := sum - a[l+1] ; l := l + 1) ; ans := ans + r - l + 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict import sys sys.setrecursionlimit(10**7) graph=defaultdict(list) N,K=map(int,input().split()) for i in range(N-1): a,b=map(int,input().split()) graph[a-1].append(b-1) graph[b-1].append(a-1) mod=10**9+7 def dfs(fro,to,f): caseNum=f colorNum=K-1 if f==K else K-2 for u in graph[fro]: if u==to : continue pat=dfs(u,fro,colorNum) if pat==0 : caseNum=0 break caseNum=caseNum*pat % mod colorNum-=1 return caseNum ans=dfs(0,-1,K) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; var graph : OclAny := defaultdict(OclType["Sequence"]) ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, N - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ))))) ; var mod : double := (10)->pow(9) + 7 ; skip ; var ans : OclAny := dfs(0, -1, K) ; execute (ans)->display(); operation dfs(fro : OclAny, to : OclAny, f : OclAny) : OclAny pre: true post: true activity: var caseNum : OclAny := f ; var colorNum : double := if f = K then K - 1 else K - 2 endif ; for u : graph[fro+1] do ( if u = to then ( continue ) else skip ; var pat : OclAny := dfs(u, fro, colorNum) ; if pat = 0 then ( caseNum := 0 ; break ) else skip ; caseNum := caseNum * pat mod mod ; colorNum := colorNum - 1) ; return caseNum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline N,Q=map(int,input().split()) A=[int(i)for i in input().split()] X=[int(i)for i in input().split()] def count(x): ans=0 left=0 total=0 for right in range(N): total+=A[right] while total>x : total-=A[left] left+=1 ans+=right-left+1 return ans for x in X : print(count(x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var N : OclAny := null; var Q : OclAny := null; Sequence{N,Q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var X : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; skip ; for x : X do ( execute (count(x))->display()); operation count(x : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; var left : int := 0 ; var total : int := 0 ; for right : Integer.subrange(0, N-1) do ( total := total + A[right+1] ; while (total->compareTo(x)) > 0 do ( total := total - A[left+1] ; left := left + 1) ; ans := ans + right - left + 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline write=sys.stdout.write N,Q=map(int,readline().split()) *A,=map(int,readline().split()) X=map(int,readline().split()) ss=[0]; tt=[] v=0 for a in A : v+=a ss.append(v); tt.append(v) ss.pop(); tt.append(10**15) def solve(x): t=v=0 it=iter(tt).__next__ nxt=it()-x for s,c in enumerate(ss): while nxt<=c : nxt=it()-x ; t+=1 yield t-s write("\n".join(map((lambda x : str(sum(x))),map(solve,X)))) write("\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var write : OclAny := (OclFile["System.out"]).write ; var N : OclAny := null; var Q : OclAny := null; Sequence{N,Q} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (testlist_star_expr (star_expr * (expr (atom (name A)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name A)))) ,)} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var X : Sequence := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ss : Sequence := Sequence{ 0 }; var tt : Sequence := Sequence{} ; var v : int := 0 ; for a : A do ( v := v + a ; execute ((v) : ss); execute ((v) : tt)) ; ss := ss->front(); execute (((10)->pow(15)) : tt) ; skip ; write(StringLib.sumStringsWithSeparator((((X)->collect( _x | (solve)->apply(_x) ))->collect( _x | ((lambda x : OclAny in (("" + (((x)->sum()))))))->apply(_x) )), "\n")) ; write("\n"); operation solve(x : OclAny) pre: true post: true activity: var t : OclAny := 0; v := 0 ; var it : OclAny := iter(tt).__next__ ; var nxt : double := it() - x ; for _tuple : Integer.subrange(1, (ss)->size())->collect( _indx | Sequence{_indx-1, (ss)->at(_indx)} ) do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); while (nxt->compareTo(c)) <= 0 do ( nxt := it() - x; t := t + 1) ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return t - s); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) for i in range(a): b,c=map(int,input().split()) d=abs(b-c) if d % 10!=0 : print(d//10+1) else : print(d//10) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, a-1) do ( var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : double := (b - c)->abs() ; if d mod 10 /= 0 then ( execute (d div 10 + 1)->display() ) else ( execute (d div 10)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for p in range(int(input())): a,b=map(int,input().split()) c=abs(a-b) if c==0 : print(0) else : if c % 10==0 : print(c//10) else : print((c//10)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for p : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : double := (a - b)->abs() ; if c = 0 then ( execute (0)->display() ) else ( if c mod 10 = 0 then ( execute (c div 10)->display() ) else ( execute ((c div 10) + 1)->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) arr=[] for i in range(a): b=[int(i)for i in str(input()).split()] if b[0]==b[1]: arr.append(0) continue rest=max(b)-min(b) if rest % 10==0 : rest_=rest//10 else : rest_=rest//10 rest_+=1 arr.append(rest_) for i in arr : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Sequence{} ; for i : Integer.subrange(0, a-1) do ( var b : Sequence := OclType["String"]((OclFile["System.in"]).readLine()).split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if b->first() = b[1+1] then ( execute ((0) : arr) ; continue ) else skip ; var rest : double := (b)->max() - (b)->min() ; if rest mod 10 = 0 then ( var rest_ : int := rest div 10 ) else ( rest_ := rest div 10 ; rest_ := rest_ + 1 ) ; execute ((rest_) : arr)) ; for i : arr do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil for _ in range(int(input())): a,b=map(int,input().split()) print(ceil((abs(b-a))/10)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (ceil(((b - a)->abs()) / 10))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for q in range(t): a,b=input().split() a=int(a) b=int(b) c=0 if a==b : c=0 elif ab : x=(a-b)% 10 if x==0 : c=(a-b)//10 else : c=(a-b)//10+1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for q : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; var c : int := 0 ; if a = b then ( c := 0 ) else (if (a->compareTo(b)) < 0 then ( var x : int := (b - a) mod 10 ; if x = 0 then ( c := (b - a) div 10 ) else ( c := (b - a) div 10 + 1 ) ) else (if (a->compareTo(b)) > 0 then ( x := (a - b) mod 10 ; if x = 0 then ( c := (a - b) div 10 ) else ( c := (a - b) div 10 + 1 ) ) else skip ) ) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def RPN(states): operator={'+' :(lambda x,y : x+y),'-' :(lambda x,y : x-y),'*' :(lambda x,y : x*y),'/' :(lambda x,y : float(x)/y)} stack=[] for z in states : if z not in operator.keys(): stack.append(int(z)) else : y=stack.pop() x=stack.pop() stack.append(operator[z](x,y)) return stack[0] import sys states=[] for state in sys.stdin : state=list(state.split()) states.append(state) for state in states : print(RPN(state)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; states := Sequence{} ; for state : OclFile["System.in"] do ( var state : Sequence := (state.split()) ; execute ((state) : states)) ; for state : states do ( execute (RPN(state))->display()); operation RPN(states : OclAny) : OclAny pre: true post: true activity: var operator : Map := Map{ '+' |-> (lambda x : OclAny, y : OclAny in (x + y)) }->union(Map{ '-' |-> (lambda x : OclAny, y : OclAny in (x - y)) }->union(Map{ '*' |-> (lambda x : OclAny, y : OclAny in (x * y)) }->union(Map{ '/' |-> (lambda x : OclAny, y : OclAny in (("" + ((x)))->toReal() / y)) }))) ; var stack : Sequence := Sequence{} ; for z : states do ( if (operator.keys())->excludes(z) then ( execute ((("" + ((z)))->toInteger()) : stack) ) else ( var y : OclAny := stack->last() ; stack := stack->front() ; var x : OclAny := stack->last() ; stack := stack->front() ; execute ((operator[z+1](x, y)) : stack) )) ; return stack->first(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- maxSize=100005 isFib=[False]*(maxSize) prefix=[0]*maxSize def digitSum(num): s=0 while(num!=0): s=s+num % 10 num=num//10 return s def generateFibonacci(): global isFib prev=0 curr=1 isFib[prev]=True isFib[curr]=True while(currunion(Sequence{ 11 })}->union(Sequence{Sequence{5}->union(Sequence{ 15 })}->union(Sequence{ Sequence{2}->union(Sequence{ 24 }) })) ; k := 2 ; q := (query)->size() ; performQueries(k, q, query) ) else skip; operation digitSum(num : OclAny) : OclAny pre: true post: true activity: var s : int := 0 ; while (num /= 0) do ( s := s + num mod 10 ; num := num div 10) ; return s; operation generateFibonacci() pre: true post: true activity: skip ; var prev : int := 0 ; var curr : int := 1 ; isFib[prev+1] := true ; isFib[curr+1] := true ; while ((curr->compareTo(maxSize)) < 0) do ( var temp : int := curr + prev ; if (temp->compareTo(maxSize)) < 0 then ( isFib[temp+1] := true ) else skip ; prev := curr ; curr := temp); operation precompute(k : OclAny) pre: true post: true activity: generateFibonacci() ; skip ; for i : Integer.subrange(1, maxSize-1) do ( var sum : OclAny := digitSum(i) ; if (isFib[sum+1] = true & sum mod k = 0) then ( prefix[i+1] := prefix[i+1] + 1 ) else skip) ; for i : Integer.subrange(1, maxSize-1) do ( prefix[i+1] := prefix[i+1] + prefix[i - 1+1]); operation performQueries(k : OclAny, q : OclAny, query : OclAny) pre: true post: true activity: precompute(k) ; for i : Integer.subrange(0, q-1) do ( var l : OclAny := query[i+1]->first() ; var r : OclAny := query[i+1][1+1] ; var cnt : double := prefix[r+1] - prefix[l - 1+1] ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x1,y1=map(int,input().split()); x2,y2=map(int,input().split()); x3,y3=map(int,input().split()) alpha=0 if y1==y2 and y3toInteger()-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var x3 : OclAny := null; var y3 : OclAny := null; Sequence{x3,y3} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var alpha : int := 0 ; if y1 = y2 & (y3->compareTo(y1)) < 0 then ( alpha := alpha + (x1 - x2)->abs() ) else skip ; if y2 = y3 & (y1->compareTo(y2)) < 0 then ( alpha := alpha + (x2 - x3)->abs() ) else skip ; if y3 = y1 & (y2->compareTo(y3)) < 0 then ( alpha := alpha + (x3 - x1)->abs() ) else skip ; execute (alpha)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) mod=10**9+7 import sys sys.setrecursionlimit(10**9) root=[[]for i in range(n)] for i in range(n-1): a,b=map(int,input().split()) root[a-1].append(b-1) root[b-1].append(a-1) def perm(k,n): x=1 if k-n+1<=0 : return 0 for i in range(k,k-n,-1): x=x*i % mod return x def dfs(node,depth,prev): l=len(root[node]) d=depth x=1 if l==0 : return 1 if l==1 and depth>1 : return 1 if depth>1 : x=perm(k-d,l-1) else : x=perm(k-d,l) for y in root[node]: if y!=prev : x=x*dfs(y,2,node)% mod return x % mod count=dfs(0,1,0)*k % mod print(count if count>0 else 0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mod : double := (10)->pow(9) + 7 ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var root : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, n - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name root)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name root)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ))))) ; skip ; skip ; var count : int := dfs(0, 1, 0) * k mod mod ; execute (if count > 0 then count else 0 endif)->display(); operation perm(k : OclAny, n : OclAny) : OclAny pre: true post: true activity: var x : int := 1 ; if k - n + 1 <= 0 then ( return 0 ) else skip ; for i : Integer.subrange(k - n + 1, k)->reverse() do ( x := x * i mod mod) ; return x; operation dfs(node : OclAny, depth : OclAny, prev : OclAny) : OclAny pre: true post: true activity: var l : int := (root[node+1])->size() ; var d : OclAny := depth ; x := 1 ; if l = 0 then ( return 1 ) else skip ; if l = 1 & depth > 1 then ( return 1 ) else skip ; if depth > 1 then ( x := perm(k - d, l - 1) ) else ( x := perm(k - d, l) ) ; for y : root[node+1] do ( if y /= prev then ( x := x * dfs(y, 2, node) mod mod ) else skip) ; return x mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): x1,y1=(int(i)for i in input().split()) x2,y2=(int(i)for i in input().split()) x3,y3=(int(i)for i in input().split()) res=0 if y1==y2 : res=0 if y1==0 or y3>y1 else abs(x1-x2) elif y2==y3 : res=0 if y2==0 or y1>y2 else abs(x2-x3) elif y3==y1 : res=0 if y3==0 or y2>y3 else abs(x3-x1) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x2,y2} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var x3 : OclAny := null; var y3 : OclAny := null; Sequence{x3,y3} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var res : int := 0 ; if y1 = y2 then ( res := if y1 = 0 or (y3->compareTo(y1)) > 0 then 0 else (x1 - x2)->abs() endif ) else (if y2 = y3 then ( res := if y2 = 0 or (y1->compareTo(y2)) > 0 then 0 else (x2 - x3)->abs() endif ) else (if y3 = y1 then ( res := if y3 = 0 or (y2->compareTo(y3)) > 0 then 0 else (x3 - x1)->abs() endif ) else skip ) ) ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a=[] for j in range(3): a.append(list(map(int,input().split()))) if a[0][1]==a[1][1]and a[0][1]!=0 and a[0][1]>a[2][1]: print(abs(a[1][0]-a[0][0])) elif a[1][1]==a[2][1]and a[1][1]!=0 and a[1][1]>a[0][1]: print(abs(a[2][0]-a[1][0])) elif a[2][1]==a[0][1]and a[2][1]!=0 and a[2][1]>a[1][1]: print(abs(a[2][0]-a[0][0])) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : Sequence := Sequence{} ; for j : Integer.subrange(0, 3-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : a)) ; if a->first()[1+1] = a[1+1][1+1] & a->first()[1+1] /= 0 & (a->first()[1+1]->compareTo(a[2+1][1+1])) > 0 then ( execute ((a[1+1]->first() - a->first()->first())->abs())->display() ) else (if a[1+1][1+1] = a[2+1][1+1] & a[1+1][1+1] /= 0 & (a[1+1][1+1]->compareTo(a->first()[1+1])) > 0 then ( execute ((a[2+1]->first() - a[1+1]->first())->abs())->display() ) else (if a[2+1][1+1] = a->first()[1+1] & a[2+1][1+1] /= 0 & (a[2+1][1+1]->compareTo(a[1+1][1+1])) > 0 then ( execute ((a[2+1]->first() - a->first()->first())->abs())->display() ) else ( execute (0)->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b=list(map(int,input().split())) c,d=list(map(int,input().split())) e,f=list(map(int,input().split())) if b==d and d>f : print(abs(c-a)) elif d==f and d>b : print(abs(e-c)) elif b==f and b>d : print(abs(a-e)) else : print("0") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var e : OclAny := null; var f : OclAny := null; Sequence{e,f} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if b = d & (d->compareTo(f)) > 0 then ( execute ((c - a)->abs())->display() ) else (if d = f & (d->compareTo(b)) > 0 then ( execute ((e - c)->abs())->display() ) else (if b = f & (b->compareTo(d)) > 0 then ( execute ((a - e)->abs())->display() ) else ( execute ("0")->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math t=int(input()) for _ in range(t): x1,y1=map(int,input().split()) x2,y2=map(int,input().split()) x3,y3=map(int,input().split()) if y1==y2 and y1>y3 : print(abs(int(x1)-int(x2))) elif y2==y3 and y3>y1 : print(abs(int(x2)-int(x3))) elif y1==y3 and y1>y2 : print(abs(int(x1)-int(x3))) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x3 : OclAny := null; var y3 : OclAny := null; Sequence{x3,y3} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if y1 = y2 & (y1->compareTo(y3)) > 0 then ( execute ((("" + ((x1)))->toInteger() - ("" + ((x2)))->toInteger())->abs())->display() ) else (if y2 = y3 & (y3->compareTo(y1)) > 0 then ( execute ((("" + ((x2)))->toInteger() - ("" + ((x3)))->toInteger())->abs())->display() ) else (if y1 = y3 & (y1->compareTo(y2)) > 0 then ( execute ((("" + ((x1)))->toInteger() - ("" + ((x3)))->toInteger())->abs())->display() ) else ( execute (0)->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPalindrome(s): l=len(s) for i in range(l//2): if(s[i]!=s[l-1-i]): return False return True def createStringAndCheckPalindrome(N): sub=""+chr(N) res_str="" sum=0 while(N>0): digit=N % 10 sum+=digit N=N//10 while(len(res_str)sum): res_str=res_str[0 : sum] if(isPalindrome(res_str)): return True return False if __name__=="__main__" : N=10101 if(createStringAndCheckPalindrome(N)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( N := 10101 ; if (createStringAndCheckPalindrome(N)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isPalindrome(s : OclAny) : OclAny pre: true post: true activity: var l : int := (s)->size() ; for i : Integer.subrange(0, l div 2-1) do ( if (s[i+1] /= s[l - 1 - i+1]) then ( return false ) else skip) ; return true; operation createStringAndCheckPalindrome(N : OclAny) : OclAny pre: true post: true activity: var sub : String := "" + (N)->byte2char() ; var res_str : String := "" ; var sum : int := 0 ; while (N > 0) do ( var digit : int := N mod 10 ; sum := sum + digit ; N := N div 10) ; while (((res_str)->size()->compareTo(sum)) < 0) do ( res_str := res_str + sub) ; if (((res_str)->size()->compareTo(sum)) > 0) then ( res_str := res_str.subrange(0+1, sum) ) else skip ; if (isPalindrome(res_str)) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) soots=["S","H","C","D"] sootlist=[] numlist=[] for i in range(n): soot,num=map(str,input().split()) sootlist.append(soot) numlist.append(int(num)) ans_sootlist=[] ans_numlist=[] for soot in soots : for num in range(1,14): flag=0 for s,n in zip(sootlist,numlist): if soot==s and num==n : flag=1 break if flag==1 : continue else : ans_sootlist.append(soot) ans_numlist.append(num) for soot,num in zip(ans_sootlist,ans_numlist): print(soot,num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var soots : Sequence := Sequence{"S"}->union(Sequence{"H"}->union(Sequence{"C"}->union(Sequence{ "D" }))) ; var sootlist : Sequence := Sequence{} ; var numlist : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var soot : OclAny := null; var num : OclAny := null; Sequence{soot,num} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; execute ((soot) : sootlist) ; execute ((("" + ((num)))->toInteger()) : numlist)) ; var ans_sootlist : Sequence := Sequence{} ; var ans_numlist : Sequence := Sequence{} ; for soot : soots do ( for num : Integer.subrange(1, 14-1) do ( var flag : int := 0 ; for _tuple : Integer.subrange(1, sootlist->size())->collect( _indx | Sequence{sootlist->at(_indx), numlist->at(_indx)} ) do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var n : OclAny := _tuple->at(_indx); if soot = s & num = n then ( flag := 1 ; break ) else skip) ; if flag = 1 then ( continue ) else ( execute ((soot) : ans_sootlist) ; execute ((num) : ans_numlist) ))) ; for _tuple : Integer.subrange(1, ans_sootlist->size())->collect( _indx | Sequence{ans_sootlist->at(_indx), ans_numlist->at(_indx)} ) do (var _indx : int := 1; var soot : OclAny := _tuple->at(_indx); _indx := _indx + 1; var num : OclAny := _tuple->at(_indx); execute (soot)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _,*C=open(0).readlines() C=set(C) xs=[" %d\n" % i for i in range(1,14)] ans=[] for s in "SHCD" : for x in xs : card=s+x if card not in C : ans.append(card) open(1,'w').writelines(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _anon : OclAny := null; var C : OclAny := null; Sequence{_anon,C} := open(0).readlines() ; var C : Set := Set{}->union((C)) ; var xs : Sequence := Integer.subrange(1, 14-1)->select(i | true)->collect(i | (StringLib.format(" %d\n",i))) ; var ans : Sequence := Sequence{} ; for s : "SHCD"->characters() do ( for x : xs do ( var card : OclAny := s + x ; if (C)->excludes(card) then ( execute ((card) : ans) ) else skip)) ; (expr (atom (name open)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom 'w'))))))) ))) (trailer . (name writelines) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Z(): return int(input()) def main(): S=[True]*13 H=[True]*13 C=[True]*13 D=[True]*13 n=Z() for _ in range(n): s,i=input().split() i=int(i)-1 if s=='S' : S[i]=False if s=='H' : H[i]=False if s=='C' : C[i]=False if s=='D' : D[i]=False for i in range(13): if S[i]: print('S',i+1) for i in range(13): if H[i]: print('H',i+1) for i in range(13): if C[i]: print('C',i+1) for i in range(13): if D[i]: print('D',i+1) return if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation Z() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation main() pre: true post: true activity: var S : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, 13) ; var H : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, 13) ; var C : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, 13) ; var D : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, 13) ; var n : OclAny := Z() ; for _anon : Integer.subrange(0, n-1) do ( var s : OclAny := null; var i : OclAny := null; Sequence{s,i} := input().split() ; var i : double := ("" + ((i)))->toInteger() - 1 ; if s = 'S' then ( S[i+1] := false ) else skip ; if s = 'H' then ( H[i+1] := false ) else skip ; if s = 'C' then ( C[i+1] := false ) else skip ; if s = 'D' then ( D[i+1] := false ) else skip) ; for i : Integer.subrange(0, 13-1) do ( if S[i+1] then ( execute ('S')->display() ) else skip) ; for i : Integer.subrange(0, 13-1) do ( if H[i+1] then ( execute ('H')->display() ) else skip) ; for i : Integer.subrange(0, 13-1) do ( if C[i+1] then ( execute ('C')->display() ) else skip) ; for i : Integer.subrange(0, 13-1) do ( if D[i+1] then ( execute ('D')->display() ) else skip) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import os import math for s in sys.stdin : lst=s.split() S=[] for c in lst : if c=='+' : a=S.pop() b=S.pop() S.append(b+a) elif c=='-' : a=S.pop() b=S.pop() S.append(b-a) elif c=='*' : a=S.pop() b=S.pop() S.append(b*a) elif c=='/' : a=S.pop() b=S.pop() S.append(b/a) else : S.append(float(c)) print(S[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; for s : OclFile["System.in"] do ( var lst : OclAny := s.split() ; var S : Sequence := Sequence{} ; for c : lst do ( if c = '+' then ( var a : OclAny := S->last() ; S := S->front() ; var b : OclAny := S->last() ; S := S->front() ; execute ((b + a) : S) ) else (if c = '-' then ( a := S->last() ; S := S->front() ; b := S->last() ; S := S->front() ; execute ((b - a) : S) ) else (if c = '*' then ( a := S->last() ; S := S->front() ; b := S->last() ; S := S->front() ; execute ((b * a) : S) ) else (if c = '/' then ( a := S->last() ; S := S->front() ; b := S->last() ; S := S->front() ; execute ((b / a) : S) ) else ( execute ((("" + ((c)))->toReal()) : S) ) ) ) ) ) ; execute (S->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) cards=[[False for i in range(13)]for j in range(4)] pattern=["S","H","C","D"] for i in range(n): p,num=[x for x in input().split()] num=int(num) cards[pattern.index(p)][num-1]=True for i in range(4): for j in range(13): if not cards[i][j]: print(pattern[i],j+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cards : Sequence := Integer.subrange(0, 4-1)->select(j | true)->collect(j | (Integer.subrange(0, 13-1)->select(i | true)->collect(i | (false)))) ; var pattern : Sequence := Sequence{"S"}->union(Sequence{"H"}->union(Sequence{"C"}->union(Sequence{ "D" }))) ; for i : Integer.subrange(0, n-1) do ( var p : OclAny := null; var num : OclAny := null; Sequence{p,num} := input().split()->select(x | true)->collect(x | (x)) ; var num : int := ("" + ((num)))->toInteger() ; cards[pattern->indexOf(p) - 1+1][num - 1+1] := true) ; for i : Integer.subrange(0, 4-1) do ( for j : Integer.subrange(0, 13-1) do ( if not(cards[i+1][j+1]) then ( execute (pattern[i+1])->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines n,k=map(int,readline().split()) graph=[[]for _ in range(n+1)] cnt=[0]*(n+1) for _ in range(n-1): a,b=map(int,input().split()) graph[a].append(b) graph[b].append(a) cnt[a]+=1 cnt[b]+=1 ans=1 mod=10**9+7 kaidan=[1]*(10**5+1) gyaku=[1]*(10**5+1) for i in range(1,10**5+1): kaidan[i]=i*kaidan[i-1]% mod gyaku[i]=pow(kaidan[i],mod-2,mod) def perm(k,i): if i>k : return 0 return kaidan[k]*gyaku[k-i] stack=[1] used=[False]*(n+1) while stack : v=stack.pop() used[v]=True if v==1 : ans*=k*perm(k-1,cnt[v]) ans %=mod else : ans*=perm(k-2,cnt[v]-1) ans %=mod for u in graph[v]: if used[u]==True : continue stack.append(u) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var graph : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for _anon : Integer.subrange(0, n - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))) ; cnt[a+1] := cnt[a+1] + 1 ; cnt[b+1] := cnt[b+1] + 1) ; var ans : int := 1 ; var mod : double := (10)->pow(9) + 7 ; var kaidan : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, ((10)->pow(5) + 1)) ; var gyaku : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, ((10)->pow(5) + 1)) ; for i : Integer.subrange(1, (10)->pow(5) + 1-1) do ( kaidan[i+1] := i * kaidan[i - 1+1] mod mod ; gyaku[i+1] := (kaidan[i+1])->pow(mod - 2)) ; skip ; var stack : Sequence := Sequence{ 1 } ; var used : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (n + 1)) ; while stack do ( var v : OclAny := stack->last() ; stack := stack->front() ; used[v+1] := true ; if v = 1 then ( ans := ans * k * perm(k - 1, cnt[v+1]) ; ans := ans mod mod ) else ( ans := ans * perm(k - 2, cnt[v+1] - 1) ; ans := ans mod mod ) ; for u : graph[v+1] do ( if used[u+1] = true then ( continue ) else skip ; execute ((u) : stack))) ; execute (ans)->display(); operation perm(k : OclAny, i : OclAny) : OclAny pre: true post: true activity: if (i->compareTo(k)) > 0 then ( return 0 ) else skip ; return kaidan[k+1] * gyaku[k - i+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def output(picture,ranks): for i in range(1,14): if i not in ranks : print(picture,i) n=int(input()) s=[] h=[] c=[] d=[] for i in range(n): inputs=input().split(' ') picture=inputs[0] rank=int(inputs[1]) if 'S'==picture : s.append(rank) elif 'H'==picture : h.append(rank) elif 'C'==picture : c.append(rank) else : d.append(rank) output('S',s) output('H',h) output('C',c) output('D',d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := Sequence{} ; var h : Sequence := Sequence{} ; var c : Sequence := Sequence{} ; var d : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var inputs : OclAny := input().split(' ') ; picture := inputs->first() ; var rank : int := ("" + ((inputs[1+1])))->toInteger() ; if 'S' = picture then ( execute ((rank) : s) ) else (if 'H' = picture then ( execute ((rank) : h) ) else (if 'C' = picture then ( execute ((rank) : c) ) else ( execute ((rank) : d) ) ) ) ) ; output('S', s) ; output('H', h) ; output('C', c) ; output('D', d); operation output(picture : OclAny, ranks : OclAny) pre: true post: true activity: for i : Integer.subrange(1, 14-1) do ( if (ranks)->excludes(i) then ( execute (picture)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sum_even_and_even_index(arr,n): i=0 sum=0 for i in range(0,n,2): if(arr[i]% 2==0): sum+=arr[i] return sum arr=[5,6,12,1,18,8] n=len(arr) print("Sum of even numbers at ","even indices is ",sum_even_and_even_index(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{5}->union(Sequence{6}->union(Sequence{12}->union(Sequence{1}->union(Sequence{18}->union(Sequence{ 8 }))))) ; n := (arr)->size() ; execute ("Sum of even numbers at ")->display(); operation sum_even_and_even_index(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; var sum : int := 0 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( if (arr[i+1] mod 2 = 0) then ( sum := sum + arr[i+1] ) else skip) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import groupby for _ in range(int(input())): ans="YES" for k,g in groupby(input()): if len(list(g))==1 : ans="NO" break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var ans : String := "YES" ; for _tuple : groupby((OclFile["System.in"]).readLine()) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var g : OclAny := _tuple->at(_indx); if ((g))->size() = 1 then ( ans := "NO" ; break ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- possibleCharacters=['aa','aaa','bb','bbb'] import re def canConstruct(targetWord,wordList,memo={}): if targetWord=='' : return 'YES' if targetWord in memo : return memo[targetWord] for word in wordList : if re.match(f"^{word}",targetWord): newTarget=targetWord[re.match(f"^{word}",targetWord).span()[1]:] memo[targetWord]=canConstruct(newTarget,wordList,memo) if memo[targetWord]=='YES' : return "YES" return "NO" n=int(input()) for i in range(n): inputString=input() print(canConstruct(inputString,possibleCharacters,memo={})) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var possibleCharacters : Sequence := Sequence{'aa'}->union(Sequence{'aaa'}->union(Sequence{'bb'}->union(Sequence{ 'bbb' }))) ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var inputString : String := (OclFile["System.in"]).readLine() ; execute (canConstruct(inputString, possibleCharacters, (argument (test (logical_test (comparison (expr (atom (name memo)))))) = (test (logical_test (comparison (expr (atom { }))))))))->display()); operation canConstruct(targetWord : OclAny, wordList : OclAny, memo : OclAny) : OclAny pre: true post: true activity: if memo->oclIsUndefined() then memo := Set{} else skip; if targetWord = '' then ( return 'YES' ) else skip ; if (memo)->includes(targetWord) then ( return memo[targetWord+1] ) else skip ; for word : wordList do ( if (targetWord)->firstMatch("^" + StringLib.formattedString("^{word}") + ".*") then ( var newTarget : OclAny := targetWord.subrange(re.match(StringLib.formattedString("^{word}"), targetWord).span()[1+1]+1) ; memo[targetWord+1] := canConstruct(newTarget, wordList, memo) ; if memo[targetWord+1] = 'YES' then ( return "YES" ) else skip ) else skip) ; return "NO"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- strings=["aa","aaa","bb","bbb"] N=int(input()) for _ in range(N): line=input() n=len(line) ans=True for j in range(n): if(j==0 or line[j]!=line[j-1])and(j==n-1 or line[j]!=line[j+1]): ans=False print("YES" if ans else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var strings : Sequence := Sequence{"aa"}->union(Sequence{"aaa"}->union(Sequence{"bb"}->union(Sequence{ "bbb" }))) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, N-1) do ( var line : String := (OclFile["System.in"]).readLine() ; var n : int := (line)->size() ; var ans : boolean := true ; for j : Integer.subrange(0, n-1) do ( if (j = 0 or line[j+1] /= line[j - 1+1]) & (j = n - 1 or line[j+1] /= line[j + 1+1]) then ( ans := false ) else skip) ; execute (if ans then "YES" else "NO" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- res=[] t=int(input()) for _ in range(t): string=input() flag=True for i in range(len(string)): if(i==0 or string[i]!=string[i-1])and(i==len(string)-1 or string[i]!=string[i+1]): flag=False res.append(flag) for i in res : if i : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var res : Sequence := Sequence{} ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var string : String := (OclFile["System.in"]).readLine() ; var flag : boolean := true ; for i : Integer.subrange(0, (string)->size()-1) do ( if (i = 0 or string[i+1] /= string[i - 1+1]) & (i = (string)->size() - 1 or string[i+1] /= string[i + 1+1]) then ( flag := false ) else skip) ; execute ((flag) : res)) ; for i : res do ( if i then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): str=input() len_str=len(str) if len_str==1 : print('NO') continue for j in range(len_str): if str[0]!=str[1]or str[len_str-1]!=str[len_str-2]: print('NO') break elif j!=len_str-1 and str[j]!=str[j+1]and str[j]!=str[j-1]: print('NO') break if j==len_str-1 : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var OclType["String"] : String := (OclFile["System.in"]).readLine() ; var len_str : int := (OclType["String"])->size() ; if len_str = 1 then ( execute ('NO')->display() ; continue ) else skip ; for j : Integer.subrange(0, len_str-1) do ( if ("" + (->first())) /= ("" + ([1+1])) or ("" + ([len_str - 1+1])) /= ("" + ([len_str - 2+1])) then ( execute ('NO')->display() ; break ) else (if j /= len_str - 1 & ("" + ([j+1])) /= ("" + ([j + 1+1])) & ("" + ([j+1])) /= ("" + ([j - 1+1])) then ( execute ('NO')->display() ; break ) else skip) ; if j = len_str - 1 then ( execute ('YES')->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printDuplicates(arr,n): fl=0 ; for i in range(0,n): if(arr[arr[i]% n]>=n): if(arr[arr[i]% n]<2*n): print(arr[i]% n,end=" ") fl=1 ; arr[arr[i]% n]+=n ; if(fl==0): print("-1") arr=[1,6,3,1,3,6,6]; arr_size=len(arr); printDuplicates(arr,arr_size); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{6}->union(Sequence{3}->union(Sequence{1}->union(Sequence{3}->union(Sequence{6}->union(Sequence{ 6 })))))); ; var arr_size : int := (arr)->size(); ; printDuplicates(arr, arr_size);; operation printDuplicates(arr : OclAny, n : OclAny) pre: true post: true activity: var fl : int := 0; ; for i : Integer.subrange(0, n-1) do ( if ((arr[arr[i+1] mod n+1]->compareTo(n)) >= 0) then ( if ((arr[arr[i+1] mod n+1]->compareTo(2 * n)) < 0) then ( execute (arr[i+1] mod n)->display() ; fl := 1; ) else skip ) else skip ; arr[arr[i+1] mod n+1] := arr[arr[i+1] mod n+1] + n;) ; if (fl = 0) then ( execute ("-1")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(sum(1/(i+1)for i in range(int(input())))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (((argument (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) / (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))) )))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) x=list(map(int,input().split())) y=list(map(int,input().split())) ans="Yes" if sum(x)>=sum(y)else "No" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var y : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : String := if ((x)->sum()->compareTo((y)->sum())) >= 0 then "Yes" else "No" endif ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=[int(j)for j in input().split()] l=[[]for i in range(n)] for i in range(n-1): a,b=[int(j)-1 for j in input().split()] l[a].append(b) l[b].append(a) s=set([0]) ans=k mod=10**9+7 from collections import deque q=deque([(0,k-1)]) while q : x,y=q.popleft() j=0 for i in l[x]: if i in s : continue s.add(i) if y-j<=0 : print(0) exit() ans*=y-j ans=ans % mod q.append((i,k-2)) j+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; var l : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, n - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger() - 1)) ; (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var s : Set := Set{}->union((Sequence{ 0 })) ; var ans : OclAny := k ; var mod : double := (10)->pow(9) + 7 ; skip ; var q : Sequence := (Sequence{ Sequence{0, k - 1} }) ; while q do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := q->first() ; q := q->tail() ; var j : int := 0 ; for i : l[x+1] do ( if (s)->includes(i) then ( continue ) else skip ; execute ((i) : s) ; if y - j <= 0 then ( execute (0)->display() ; exit() ) else skip ; ans := ans * y - j ; ans := ans mod mod ; execute ((Sequence{i, k - 2}) : q) ; j := j + 1)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() n,k=map(int,input().split()) print(-(-k//n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (-(-k div n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) SD=0 while n>=1 : SD+=pow(n,-1) n-=1 print(SD) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var SD : int := 0 ; while n >= 1 do ( SD := SD + (n)->pow(-1) ; n := n - 1) ; execute (SD)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) t=0 for i in range(1,n+1): t+=1/i print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( t := t + 1 / i) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) res=1 for i in range(2,n+1): res+=1/i print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : int := 1 ; for i : Integer.subrange(2, n + 1-1) do ( res := res + 1 / i) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) n=t s=0 while t>0 : s+=1/n n=n-1 t=t-1 print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := t ; var s : int := 0 ; while t > 0 do ( s := s + 1 / n ; n := n - 1 ; t := t - 1) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Max_Sum(n): return(n*(n-1))//2 ; if __name__=="__main__" : n=8 ; print(Max_Sum(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 8; ; execute (Max_Sum(n))->display(); ) else skip; operation Max_Sum(n : OclAny) pre: true post: true activity: return (n * (n - 1)) div 2;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def grayCode(n): return n ^(n>>1) n=10 print(grayCode(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 10 ; execute (grayCode(n))->display(); operation grayCode(n : OclAny) : OclAny pre: true post: true activity: return MathLib.bitwiseXor(n, (n /(2->pow(1)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sum(n): if(n==1): return 2 ; else : return(n*(n+1)+sum(n-1)); n=2 ; print(sum(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 2; ; execute ((n)->sum())->display();; operation sum(n : OclAny) pre: true post: true activity: if (n = 1) then ( return 2; ) else ( return (n * (n + 1) + (n - 1)->sum()); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def summ(m,n): return 8*m*n-6*m-6*n+4 m=3 n=2 print(summ(m,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; m := 3 ; n := 2 ; execute (summ(m, n))->display(); operation summ(m : OclAny, n : OclAny) : OclAny pre: true post: true activity: return 8 * m * n - 6 * m - 6 * n + 4; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findThirdDigit(n): if n<3 : return 0 return 1 if n and 1 else 6 n=7 print(findThirdDigit(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 7 ; execute (findThirdDigit(n))->display(); operation findThirdDigit(n : OclAny) : OclAny pre: true post: true activity: if n < 3 then ( return 0 ) else skip ; return if n & 1 then 1 else 6 endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(200000) nl=lambda : list(map(int,input().split())) sl=lambda : input().split() n=lambda : int(input()) s=lambda : input() N,K=nl() from collections import defaultdict edges=defaultdict(set) for i in range(N-1): a,b=nl() edges[a].add(b) edges[b].add(a) done=[False]*(N+1) done[1]=True def find(i,cands,prev): res=cands count=0 if prev : count+=1 for edge in edges[i]: if done[edge]: continue count+=1 done[edge]=True res*=find(edge,K-count,True) res %=1000000007 return res print(find(1,K,False)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(200000) ; var nl : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sl : Function := lambda $$ : OclAny in (input().split()) ; var n : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var s : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := nl->apply() ; skip ; var edges : OclAny := defaultdict(OclType["Set"]) ; for i : Integer.subrange(0, N - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := nl->apply() ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var done : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (N + 1)) ; done[1+1] := true ; skip ; execute (find(1, K, false))->display(); operation find(i : OclAny, cands : OclAny, prev : OclAny) : OclAny pre: true post: true activity: var res : OclAny := cands ; var count : int := 0 ; if prev then ( count := count + 1 ) else skip ; for edge : edges[i+1] do ( if done[edge+1] then ( continue ) else skip ; count := count + 1 ; done[edge+1] := true ; res := res * find(edge, K - count, true) ; res := res mod 1000000007) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countIntersections(n): return n*(n-1)//2 n=3 print(countIntersections(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3 ; execute (countIntersections(n))->display(); operation countIntersections(n : OclAny) : OclAny pre: true post: true activity: return n * (n - 1) div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) print(-(-k//n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (-(-k div n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Sum(n): return n*(n+1)*(n+2)//3 if __name__=="__main__" : n=2 ; print(Sum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 2; ; execute (Sum(n))->display() ) else skip; operation Sum(n : OclAny) : OclAny pre: true post: true activity: return n * (n + 1) * (n + 2) div 3; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSum(n): return((n*(n+1)*(n+1)*(n+2))/12) n=3 print(int(findSum(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3 ; execute (("" + ((findSum(n))))->toInteger())->display(); operation findSum(n : OclAny) : OclAny pre: true post: true activity: return ((n * (n + 1) * (n + 1) * (n + 2)) / 12); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxHandshake(n): return int((n*(n-1))/2) n=10 print(maxHandshake(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 10 ; execute (maxHandshake(n))->display(); operation maxHandshake(n : OclAny) : OclAny pre: true post: true activity: return ("" + (((n * (n - 1)) / 2)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find_composite_nos(n): print(9*n,8*n); if __name__=="__main__" : n=4 ; find_composite_nos(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 4; ; find_composite_nos(n); ) else skip; operation find_composite_nos(n : OclAny) pre: true post: true activity: execute (9 * n)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def possibleways(n): if(n % 2==1): return 0 ; elif(n % 4==0): return n//4-1 ; else : return n//4 ; n=20 ; print(possibleways(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 20; ; execute (possibleways(n))->display();; operation possibleways(n : OclAny) pre: true post: true activity: if (n mod 2 = 1) then ( return 0; ) else (if (n mod 4 = 0) then ( return n div 4 - 1; ) else ( return n div 4; ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxLCM(n): return(n*(n-1)); if __name__=="__main__" : n=3 ; print(maxLCM(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 3; ; execute (maxLCM(n))->display(); ) else skip; operation maxLCM(n : OclAny) pre: true post: true activity: return (n * (n - 1));; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countMaxIntersect(n): return int(n*(n-1)/2) if __name__=='__main__' : n=8 print(countMaxIntersect(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 8 ; execute (countMaxIntersect(n))->display() ) else skip; operation countMaxIntersect(n : OclAny) : OclAny pre: true post: true activity: return ("" + ((n * (n - 1) / 2)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def SUM(n,m): if(m==1): return(n*(n+1)/2) sum=SUM(n,m-1) return int(sum*(sum+1)/2) n=5 m=3 print("SUM(",n,",",m,"):",SUM(n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; m := 3 ; execute ("SUM(")->display(); operation SUM(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: if (m = 1) then ( return (n * (n + 1) / 2) ) else skip ; var sum : OclAny := SUM(n, m - 1) ; return ("" + ((sum * (sum + 1) / 2)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nextPowerOf2(n): count=0 if(n and not(n and(n-1))): return n while n!=0 : n>>=1 count+=1 return 1<display() ) else skip; operation nextPowerOf2(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; if (n & not((n & (n - 1)))) then ( return n ) else skip ; while n /= 0 do ( n := n div (2->pow(1)) ; count := count + 1) ; return 1 * (2->pow(count)); operation removeElement(n : OclAny) : OclAny pre: true post: true activity: if n = 1 or n = 2 then ( return 0 ) else skip ; var a : OclAny := nextPowerOf2(n) ; if n = a or n = a - 1 then ( return 1 ) else (if n = a - 2 then ( return 0 ) else (if n mod 2 = 0 then ( return 1 ) else ( return 2 ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,m=map(int,input().split()) arr=list(map(int,input().split())) li=[0]*n for i in range(n): li[i]=math.ceil(arr[i]/m) maxi=max(li) for i in range(n-1,-1,-1): if maxi==li[i]: print(i+1) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var li : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( li[i+1] := (arr[i+1] / m)->ceil()) ; var maxi : OclAny := (li)->max() ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if maxi = li[i+1] then ( execute (i + 1)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cntWays(n): if n % 2==1 : return 0 else : return(n-2)//4 n=18 print(cntWays(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 18 ; execute (cntWays(n))->display(); operation cntWays(n : OclAny) : OclAny pre: true post: true activity: if n mod 2 = 1 then ( return 0 ) else ( return (n - 2) div 4 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CountSetBits(n): if(n==0): return 0 ; if((n & 1)==1): return 1+CountSetBits(n>>1); else : return CountSetBits(n>>1); if __name__=='__main__' : n=21 ; print(CountSetBits(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 21; ; execute (CountSetBits(n))->display(); ) else skip; operation CountSetBits(n : OclAny) pre: true post: true activity: if (n = 0) then ( return 0; ) else skip ; if ((MathLib.bitwiseAnd(n, 1)) = 1) then ( return 1 + CountSetBits(n /(2->pow(1))); ) else ( return CountSetBits(n /(2->pow(1))); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=input().split() n=int(l[0]) k=int(l[1]) a=1 b=k while a=k : b=c else : a=c+1 print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := input().split() ; var n : int := ("" + ((l->first())))->toInteger() ; var k : int := ("" + ((l[1+1])))->toInteger() ; var a : int := 1 ; var b : int := k ; while (a->compareTo(b)) < 0 do ( var c : int := (a + b) div 2 ; if (c * n->compareTo(k)) >= 0 then ( b := c ) else ( a := c + 1 )) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def highestPowerOf2(n): return(n &(~(n-1))) if __name__=='__main__' : n=48 print(highestPowerOf2(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 48 ; execute (highestPowerOf2(n))->display() ) else skip; operation highestPowerOf2(n : OclAny) : OclAny pre: true post: true activity: return (MathLib.bitwiseAnd(n, (MathLib.bitwiseNot((n - 1))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() for i in range(ord('a'),ord('z')+1): if chr(i)not in list(S): print(chr(i)) exit() print('None') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(('a')->char2byte(), ('z')->char2byte() + 1-1) do ( if ((S)->characters())->excludes((i)->byte2char()) then ( execute ((i)->byte2char())->display() ; exit() ) else skip) ; execute ('None')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- myinput=input() for c in 'abcdefghijklmnopqrstuvwxyz' : if c not in myinput : print(c) break else : print('None') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var myinput : String := (OclFile["System.in"]).readLine() ; (compound_stmt for (exprlist (expr (atom (name c)))) in (testlist (test (logical_test (comparison (expr (atom 'abcdefghijklmnopqrstuvwxyz')))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name c)))) not in (comparison (expr (atom (name myinput))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'None'))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() c_lst=[0 for i in range(26)] for i in s : c_lst[ord(i)-97]+=1 for i in range(len(c_lst)): if c_lst[i]==0 : print(chr(i+97)) break else : print("None") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var c_lst : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | (0)) ; for i : s->characters() do ( c_lst[(i)->char2byte() - 97+1] := c_lst[(i)->char2byte() - 97+1] + 1) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c_lst)))))))) ))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name c_lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name chr)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 97)))))))))) ))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "None"))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy import random import bisect import math S=str(input()) all=list("abcdefghijklmnopqrstuvwxyz") all.sort() for i in range(len(S)): if S[i]in all : all.remove(S[i]) if len(all)>0 : print(all[0]) else : print("None") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var S : String := ("" + (((OclFile["System.in"]).readLine()))) ; var all : Sequence := ("abcdefghijklmnopqrstuvwxyz")->characters() ; all := all->sort() ; for i : Integer.subrange(0, (S)->size()-1) do ( if (all)->includes(S[i+1]) then ( execute ((S[i+1]) /: all) ) else skip) ; if (all)->size() > 0 then ( execute (->first()->forAll( _x | _x = true ))->display() ) else ( execute ("None")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- nlist=[None]*150 def main(): stri=input() for i in range(len(stri)): ind=ord(stri[i]) nlist[ind]=1 for i in range(len(nlist)): if nlist[i]==None and(i>96 and i<123): print(str(chr(i))) return print("None") if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var nlist : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, 150) ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var stri : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, (stri)->size()-1) do ( var ind : int := (stri[i+1])->char2byte() ; nlist[ind+1] := 1) ; for i : Integer.subrange(0, (nlist)->size()-1) do ( if nlist[i+1] = null & (i > 96 & i < 123) then ( execute (("" + (((i)->byte2char()))))->display() ; return ) else skip) ; execute ("None")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) array=input().split() a=0 while atoInteger() ; var array : OclAny := input().split() ; var a : int := 0 ; while (a->compareTo(n)) < 0 do ( array[a+1] := ("" + ((array[a+1])))->toInteger() ; a := a + 1) ; var smallest : OclAny := (array)->min() ; array := array->sort() ; var i : int := 1 ; var t_or_f : boolean := true ; while (i->compareTo(n)) < 0 do ( if array[i+1] / smallest /= ("" + ((array[i+1] / smallest)))->toInteger() then ( t_or_f := false ) else skip ; i := i + 1) ; if t_or_f = true then ( execute (smallest)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minimumCost(cost,n): dp1=0 dp2=0 for i in range(n): dp0=cost[i]+min(dp1,dp2) dp2=dp1 dp1=dp0 return min(dp1,dp2) if __name__=="__main__" : a=[2,5,3,1,7,3,4] n=len(a) print(minimumCost(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var a : Sequence := Sequence{2}->union(Sequence{5}->union(Sequence{3}->union(Sequence{1}->union(Sequence{7}->union(Sequence{3}->union(Sequence{ 4 })))))) ; n := (a)->size() ; execute (minimumCost(a, n))->display() ) else skip; operation minimumCost(cost : OclAny, n : OclAny) : OclAny pre: true post: true activity: var dp1 : int := 0 ; var dp2 : int := 0 ; for i : Integer.subrange(0, n-1) do ( var dp0 : OclAny := cost[i+1] + Set{dp1, dp2}->min() ; dp2 := dp1 ; dp1 := dp0) ; return Set{dp1, dp2}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) a=sorted(map(int,[*open(0)][1].split())) print([a[0],-1][any(x % a[0]for x in a)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := (OclFile.newOclFile_Write(OclFile.newOclFile(0))[1+1].split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; execute (Sequence{a->first()}->union(Sequence{ -1 })->select(((argument (test (logical_test (comparison (expr (expr (atom (name x))) % (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a))))))))->exists( _x | _x = true )))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) ans=min(arr) for i in arr : if i % ans : ans=-1 break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : OclAny := (arr)->min() ; for i : arr do ( if i mod ans then ( ans := -1 ; break ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) if 1 in l : print(1) else : l.sort() for x in range(1,len(l)): if l[x]% l[0]!=0 : print(-1) break else : print(l[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (l)->includes(1) then ( execute (1)->display() ) else ( l := l->sort() ; (compound_stmt for (exprlist (expr (atom (name x)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)))))))) ))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ]))) % (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))) != (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))))))))))))) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) print((k+n-1)//n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((k + n - 1) div n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) if 1 in l : print(1) else : target=min(l) for x in range(len(l)): if l[x]% target!=0 : print(-1) break else : print(target) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (l)->includes(1) then ( execute (1)->display() ) else ( var target : OclAny := (l)->min() ; (compound_stmt for (exprlist (expr (atom (name x)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)))))))) ))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ]))) % (expr (atom (name target))))) != (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name target)))))))) ))))))))))))))) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import fractions N=int(input()) A=list(map(int,input().split())) max_val=0 L=[0]*N R=[0]*N for i in range(N-1): L[i+1]=fractions.gcd(L[i],A[i]) for i in range(N-1,0,-1): R[i-1]=fractions.gcd(R[i],A[i]) for i in range(N): max_val=max(max_val,fractions.gcd(L[i],R[i])) print(max_val) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var max_val : int := 0 ; var L : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var R : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for i : Integer.subrange(0, N - 1-1) do ( L[i + 1+1] := fractions.gcd(L[i+1], A[i+1])) ; for i : Integer.subrange(0 + 1, N - 1)->reverse() do ( R[i - 1+1] := fractions.gcd(R[i+1], A[i+1])) ; for i : Integer.subrange(0, N-1) do ( max_val := Set{max_val, fractions.gcd(L[i+1], R[i+1])}->max()) ; execute (max_val)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) A=list(map(int,input().split())) A.sort() def find(inte): re=[] for i in range(1,int(inte**0.5)+1): if inte % i==0 : re.append(i) if i!=inte/i : re.append(int(inte/i)) return set(re) if n==2 : print(A[1]) else : a1=find(A[0]) a2=find(A[1]) a3=find(A[2]) t1=a1 & a2 t2=a2 & a3 t3=a1 & a3 cond=t1 | t2 | t3 maxi=0 for con in cond : count=0 flag=True for a in A : if a % con!=0 : count+=1 if count>=2 : flag=False break if flag and maxitoInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; A := A->sort() ; skip ; if n = 2 then ( execute (A[1+1])->display() ) else ( var a1 : OclAny := find(A->first()) ; var a2 : OclAny := find(A[1+1]) ; var a3 : OclAny := find(A[2+1]) ; var t1 : int := MathLib.bitwiseAnd(a1, a2) ; var t2 : int := MathLib.bitwiseAnd(a2, a3) ; var t3 : int := MathLib.bitwiseAnd(a1, a3) ; var cond : int := MathLib.bitwiseOr(MathLib.bitwiseOr(t1, t2), t3) ; var maxi : int := 0 ; for con : cond do ( var count : int := 0 ; var flag : boolean := true ; for a : A do ( if a mod con /= 0 then ( count := count + 1 ) else skip ; if count >= 2 then ( flag := false ; break ) else skip) ; if flag & (maxi->compareTo(con)) < 0 then ( maxi := con ) else skip) ; execute (maxi)->display() ); operation find(inte : OclAny) : OclAny pre: true post: true activity: var re : Sequence := Sequence{} ; for i : Integer.subrange(1, ("" + (((inte)->pow(0.5))))->toInteger() + 1-1) do ( if inte mod i = 0 then ( execute ((i) : re) ; if i /= inte / i then ( execute ((("" + ((inte / i)))->toInteger()) : re) ) else skip ) else skip) ; return Set{}->union((re)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if b>a : a,b=b,a while b : a,b=b,a % b return a def cul(n,x): l=len(x) b=[x[i]for i in range(l)] b.pop(n) tmp=b[0] for i in range(1,l-1): tmp=gcd(tmp,b[i]) return tmp import sys p=50 N=int(input()) a=list(map(int,input().split())) if N<=p : ans=0 for i in range(N): tmp=cul(i,a) if tmp>ans : ans=tmp print(ans) sys.exit() ans=0 for i in range(p): s=cul(i,a[: p]) if s>ans : ans=s print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var p : int := 50 ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (N->compareTo(p)) <= 0 then ( var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( tmp := cul(i, a) ; if (tmp->compareTo(ans)) > 0 then ( ans := tmp ) else skip) ; execute (ans)->display() ; sys.exit() ) else skip ; ans := 0 ; for i : Integer.subrange(0, p-1) do ( var s : OclAny := cul(i, a.subrange(1,p)) ; if (s->compareTo(ans)) > 0 then ( ans := s ) else skip) ; execute (ans)->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (b->compareTo(a)) > 0 then ( Sequence{a,b} := Sequence{b,a} ) else skip ; while b do ( Sequence{a,b} := Sequence{b,a mod b}) ; return a; operation cul(n : OclAny, x : OclAny) : OclAny pre: true post: true activity: var l : int := (x)->size() ; b := Integer.subrange(0, l-1)->select(i | true)->collect(i | (x[i+1])) ; b := b->excludingAt(n+1) ; var tmp : OclAny := b->first() ; for i : Integer.subrange(1, l - 1-1) do ( tmp := gcd(tmp, b[i+1])) ; return tmp; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import gcd from itertools import accumulate n=int(input()) a=list(map(int,input().split())) a=[0]+a+[0] l=list(accumulate(a,gcd)) r=list(reversed(list(accumulate(reversed(a),gcd)))) ans=max(gcd(li,ri)for li,ri in zip(l[:-2],r[2 :])) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := Sequence{ 0 }->union(a)->union(Sequence{ 0 }) ; var l : Sequence := (accumulate(a, gcd)) ; var r : Sequence := (((accumulate((a)->reverse(), gcd)))->reverse()) ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name gcd)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name li))))))) , (argument (test (logical_test (comparison (expr (atom (name ri)))))))) ))))))) (comp_for for (exprlist (expr (atom (name li))) , (expr (atom (name ri)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom - (number (integer 2))))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name r)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) :)) ])))))))) )))))))))->max() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a : int,b : int)->int : if b==0 : return a return gcd(b,a % b) def ruiseki_lr(array): op=lambda a,b : gcd(a,b) e=0 n=len(array) left=[e]*(n+1) right=[e]*(n+1) for i in range(n): left[i+1]=op(left[i],array[i]) for i in reversed(range(n)): right[i]=op(right[i+1],array[i]) return left,right n=int(input()) a=list(map(int,input().split())) left,right=ruiseki_lr(a) ans=0 for i in range(n): ans=max(gcd(left[i],right[i+1]),ans) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; Sequence{left,right} := ruiseki_lr(a) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( ans := Set{gcd(left[i+1], right[i + 1+1]), ans}->max()) ; execute (ans)->display(); operation gcd(a : int, b : int) : int pre: true post: true activity: if b = 0 then ( return a ) else skip ; return gcd(b, a mod b); operation ruiseki_lr(array : OclAny) : OclAny pre: true post: true activity: var op : Function := lambda a : OclAny, b : OclAny in (gcd(a, b)) ; var e : int := 0 ; var n : int := (array)->size() ; var left : Sequence := MatrixLib.elementwiseMult(Sequence{ e }, (n + 1)) ; var right : Sequence := MatrixLib.elementwiseMult(Sequence{ e }, (n + 1)) ; for i : Integer.subrange(0, n-1) do ( left[i + 1+1] := op->apply(left[i+1], array[i+1])) ; for i : (Integer.subrange(0, n-1))->reverse() do ( right[i+1] := op->apply(right[i + 1+1], array[i+1])) ; return left, right; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countMultiples(n): return n/3+n/7-n/21 ; n=((int)(countMultiples(25))); print("Count=",n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ((OclType["int"])(countMultiples(25))); ; execute ("Count=")->display();; operation countMultiples(n : OclAny) pre: true post: true activity: return n / 3 + n / 7 - n / 21;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print("ABC" if int(input())<1200 else "ARC") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (if ("" + (((OclFile["System.in"]).readLine())))->toInteger() < 1200 then "ABC" else "ARC" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(x): print("ABC" if x<1200 else "ARC") if __name__=='__main__' : x=int(input()) solve(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( x := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; solve(x) ) else skip; operation solve(x : OclAny) pre: true post: true activity: execute (if x < 1200 then "ABC" else "ARC" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- current_rating=int(input()) if current_rating<1200 : print('ABC') else : print('ARC') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var current_rating : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if current_rating < 1200 then ( execute ('ABC')->display() ) else ( execute ('ARC')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(['ABC','ARC'][not(int(input())<1200)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (Sequence{'ABC'}->union(Sequence{ 'ARC' })->select(not((("" + (((OclFile["System.in"]).readLine())))->toInteger() < 1200))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) print((k+n-1)//n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((k + n - 1) div n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) if x<1200 : print('ABC') else : print('ARC') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if x < 1200 then ( execute ('ABC')->display() ) else ( execute ('ARC')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def skip_spaces(): c='' while c.isspace(): c=sys.stdin.read(1) return c def skip_nonspaces(): c='_' while c!='' and not c.isspace(): c=sys.stdin.read(1) return c def read_zeros(): while True : c=skip_spaces() if c=='' : break yield c=='0' if skip_nonspaces()=='' : break def dists(): first=True k=0 for z in read_zeros(): if z : if first : yield from range(k,0,-1) first=False else : h=k//2 yield from range(h+1) yield from range(k-h-1,0,-1) k=0 k+=1 yield from range(k) def main(): skip_spaces() skip_nonspaces() first=True for d in dists(): if first : first=False print(d,end='') else : print('',d,end='') print() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; main(); operation skip_spaces() : OclAny pre: true post: true activity: var c : String := '' ; while c->matches("[ \t\n\r]*") do ( c := (OclFile["System.in"]).readAll()) ; return c; operation skip_nonspaces() : OclAny pre: true post: true activity: c := '_' ; while c /= '' & not(c->matches("[ \t\n\r]*")) do ( c := (OclFile["System.in"]).readAll()) ; return c; operation read_zeros(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; while true do ( c := skip_spaces() ; if c = '' then ( break ) else skip ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return c = '0' ; if skip_nonspaces() = '' then ( break ) else skip); operation dists(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; var first : boolean := true ; var k : int := 0 ; for z : OclIterator.newOclIterator_Function(lambda _i : int in self.read_zeros(_i)) do ( if z then ( if first then ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return Integer.subrange(0 + 1, k)->reverse() ; first := false ) else ( var h : int := k div 2 ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return Integer.subrange(0, h + 1-1) ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return Integer.subrange(0 + 1, k - h - 1)->reverse() ) ; k := 0 ) else skip ; k := k + 1) ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return Integer.subrange(0, k-1); operation main() pre: true post: true activity: skip_spaces() ; skip_nonspaces() ; first := true ; for d : OclIterator.newOclIterator_Function(lambda _i : int in self.dists(_i)) do ( if first then ( first := false ; execute (d)->display() ) else ( execute ('')->display() )) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import string def main_function(): zeros=[] n=int(input()) a=[int(u)for u in input().split(" ")] for i in range(len(a)): if a[i]==0 : zeros.append(i) start_index_for_zeros=0 collector=[] for i in range(len(a)): current_index=zeros[start_index_for_zeros] if start_index_for_zeros==len(zeros)-1 : collector.append(abs(current_index-i)) else : next_val=zeros[start_index_for_zeros+1] distance_1=abs(current_index-i) distance_2=abs(next_val-i) if distance_1toInteger() ; var a : Sequence := input().split(" ")->select(u | true)->collect(u | (("" + ((u)))->toInteger())) ; for i : Integer.subrange(0, (a)->size()-1) do ( if a[i+1] = 0 then ( execute ((i) : zeros) ) else skip) ; var start_index_for_zeros : int := 0 ; var collector : Sequence := Sequence{} ; for i : Integer.subrange(0, (a)->size()-1) do ( var current_index : OclAny := zeros[start_index_for_zeros+1] ; if start_index_for_zeros = (zeros)->size() - 1 then ( execute (((current_index - i)->abs()) : collector) ) else ( var next_val : OclAny := zeros[start_index_for_zeros + 1+1] ; var distance var next_val : OclAny := zeros[start_index_for_zeros + 1+1] : double := (current_index - i)->abs() ; var distance:= (next_val - i)->abs() : double := (next_val - i)->abs() ; if (distance var next_val : OclAny := zeros[start_index_for_zeros + 1+1]->compareTo(distance execute ((distancecollector) : collector))) < 0 then ( execute ((distancecollector) : collector) ) else ( execute ((distance.append(distance_2)) : collector) ; start_index_for_zeros := start_index_for_zeros + 1 ) )) ; execute (StringLib.sumStringsWithSeparator((collector->select(i | true)->collect(i | (("" + ((i)))))), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) d=len(a) for i in range(len(a)): if 0==a[i]: d=0 a[i]=d d+=1 d=len(a) for i in range(len(a)-1,-1,-1): if 0==a[i]: d=0 a[i]=min(a[i],d) d+=1 print(" ".join(map(str,a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : int := (a)->size() ; for i : Integer.subrange(0, (a)->size()-1) do ( if 0 = a[i+1] then ( d := 0 ) else skip ; a[i+1] := d ; d := d + 1) ; d := (a)->size() ; for i : Integer.subrange(-1 + 1, (a)->size() - 1)->reverse() do ( if 0 = a[i+1] then ( d := 0 ) else skip ; a[i+1] := Set{a[i+1], d}->min() ; d := d + 1) ; execute (StringLib.sumStringsWithSeparator(((a)->collect( _x | (OclType["String"])->apply(_x) )), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline import bisect n=int(input()) w=list(map(int,input().split())) x=w.count(0) d=[] c=0 while x : d.append(w.index(0,c)) c=d[-1]+1 x-=1 d1=len(d) e=[] for i in range(n): if w[i]!=0 : l=bisect.bisect_left(d,i) r=bisect.bisect_right(d,i) if l==0 : e.append(d[0]-i) elif r==d1 : e.append(i-d[-1]) else : e.append(min(i-d[l-1],d[r]-i)) else : e.append(0) print(*e) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : int := w->count(0) ; var d : Sequence := Sequence{} ; var c : int := 0 ; while x do ( execute ((w->indexOf(0, c) - 1) : d) ; c := d->last() + 1 ; x := x - 1) ; var d1 : int := (d)->size() ; var e : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if w[i+1] /= 0 then ( var l : OclAny := bisect.bisect_left(d, i) ; var r : OclAny := bisect.bisect_right(d, i) ; if l = 0 then ( execute ((d->first() - i) : e) ) else (if r = d1 then ( execute ((i - d->last()) : e) ) else ( execute ((Set{i - d[l - 1+1], d[r+1] - i}->min()) : e) ) ) ) else ( execute ((0) : e) )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name e))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np SIZE=26 def longSub(str,k): freq=np.zeros(26,dtype=np.int) start=0 maxLen=0 n=len(str) for i in range(0,n): ch=str[i] freq[ord(ch)-ord('a')]+=1 if(freq[ord(ch)-ord('a')]>k): if(maxLen<(i-start)): maxLen=i-start while(freq[ord(ch)-ord('a')]>k): freq[ord(str[start])-ord('a')]-=1 start=start+1 if(maxLen<(n-start)): maxLen=n-start return maxLen ; str="babcaag" k=1 print("Length=",longSub(str,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var SIZE : int := 26 ; skip ; OclType["String"] := "babcaag" ; k := 1 ; execute ("Length=")->display(); operation longSub(OclType["String"] : OclAny, k : OclAny) pre: true post: true activity: var freq : Sequence := MatrixLib.singleValueMatrix(26, 0.0) ; var start : int := 0 ; var maxLen : int := 0 ; var n : int := (OclType["String"])->size() ; for i : Integer.subrange(0, n-1) do ( var ch : String := ("" + ([i+1])) ; freq[(ch)->char2byte() - ('a')->char2byte()+1] := freq[(ch)->char2byte() - ('a')->char2byte()+1] + 1 ; if ((freq[(ch)->char2byte() - ('a')->char2byte()+1]->compareTo(k)) > 0) then ( if ((maxLen->compareTo((i - start))) < 0) then ( maxLen := i - start ) else skip ; while ((freq[(ch)->char2byte() - ('a')->char2byte()+1]->compareTo(k)) > 0) do ( freq[(("" + ([start+1])))->char2byte() - ('a')->char2byte()+1] := freq[(("" + ([start+1])))->char2byte() - ('a')->char2byte()+1] - 1 ; start := start + 1) ) else skip) ; if ((maxLen->compareTo((n - start))) < 0) then ( maxLen := n - start ) else skip ; return maxLen;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def smallest(x,y,z): c=0 while(x and y and z): x=x-1 y=y-1 z=z-1 c=c+1 return c x=12 y=15 z=5 print("Minimum of 3 numbers is",smallest(x,y,z)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := 12 ; y := 15 ; z := 5 ; execute ("Minimum of 3 numbers is")->display(); operation smallest(x : OclAny, y : OclAny, z : OclAny) : OclAny pre: true post: true activity: var c : int := 0 ; while (x & y & z) do ( x := x - 1 ; y := y - 1 ; z := z - 1 ; c := c + 1) ; return c; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d,e,f=map(int,input().split()) sum=a+b*5+c*10+d*50+e*100+f*500 print(1 if sum>=1000 else 0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; var f : OclAny := null; Sequence{a,b,c,d,e,f} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sum : OclAny := a + b * 5 + c * 10 + d * 50 + e * 100 + f * 500 ; execute (if sum >= 1000 then 1 else 0 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() c1=int(x.split(" ")[0]) c5=int(x.split(" ")[1]) c10=int(x.split(" ")[2]) c50=int(x.split(" ")[3]) c100=int(x.split(" ")[4]) c500=int(x.split(" ")[5]) if(c1+5*c5+10*c10+50*c50+100*c100+500*c500)<1000 : print("0") else : print("1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := (OclFile["System.in"]).readLine() ; var c1 : int := ("" + ((x.split(" ")->first())))->toInteger() ; var c5 : int := ("" + ((x.split(" ")[1+1])))->toInteger() ; var c10 : int := ("" + ((x.split(" ")[2+1])))->toInteger() ; var c50 : int := ("" + ((x.split(" ")[3+1])))->toInteger() ; var c100 : int := ("" + ((x.split(" ")[4+1])))->toInteger() ; var c500 : int := ("" + ((x.split(" ")[5+1])))->toInteger() ; if (c1 + 5 * c5 + 10 * c10 + 50 * c50 + 100 * c100 + 500 * c500) < 1000 then ( execute ("0")->display() ) else ( execute ("1")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- coins=list(map(int,input().split())) for i in range(len(coins)): current_coin=coins[i] if i==0 : coins[i]=current_coin*1 elif i==1 : coins[i]=current_coin*5 elif i==2 : coins[i]=current_coin*10 elif i==3 : coins[i]=current_coin*50 elif i==4 : coins[i]=current_coin*100 elif i==5 : coins[i]=current_coin*500 if sum(coins)>=1000 : print('1') else : print('0') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var coins : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, (coins)->size()-1) do ( var current_coin : OclAny := coins[i+1] ; if i = 0 then ( coins[i+1] := current_coin * 1 ) else (if i = 1 then ( coins[i+1] := current_coin * 5 ) else (if i = 2 then ( coins[i+1] := current_coin * 10 ) else (if i = 3 then ( coins[i+1] := current_coin * 50 ) else (if i = 4 then ( coins[i+1] := current_coin * 100 ) else (if i = 5 then ( coins[i+1] := current_coin * 500 ) else skip ) ) ) ) ) ) ; if (coins)->sum() >= 1000 then ( execute ('1')->display() ) else ( execute ('0')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(1 if sum([v*(5 if i % 2 else 1)*10**(i//2)for i,v in enumerate(list(map(int,input().split())))])>=1000 else 0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (if (Integer.subrange(1, (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->size())->collect( _indx | Sequence{_indx-1, (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in (v * (if i mod 2 then 5 else 1 endif) * (10)->pow((i div 2)))))->sum() >= 1000 then 1 else 0 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNthTerm(n): if n % 2==0 : n//=2 print(3**(n-1)) else : n=(n//2)+1 print(2**(n-1)) if __name__=='__main__' : N=4 findNthTerm(N) N=11 findNthTerm(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var N : int := 4 ; findNthTerm(N) ; N := 11 ; findNthTerm(N) ) else skip; operation findNthTerm(n : OclAny) pre: true post: true activity: if n mod 2 = 0 then ( n := n div 2 ; execute ((3)->pow((n - 1)))->display() ) else ( n := (n div 2) + 1 ; execute ((2)->pow((n - 1)))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- coins=[1,5,10,50,100,500] if __name__=="__main__" : wallet=list(map(int,input().split())) sum=0 for i in range(6): sum+=(coins[i]*wallet[i]) print(1 if sum>=1000 else 0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var coins : Sequence := Sequence{1}->union(Sequence{5}->union(Sequence{10}->union(Sequence{50}->union(Sequence{100}->union(Sequence{ 500 }))))) ; if __name__ = "__main__" then ( var wallet : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sum : int := 0 ; for i : Integer.subrange(0, 6-1) do ( sum := sum + (coins[i+1] * wallet[i+1])) ; execute (if sum >= 1000 then 1 else 0 endif)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,r=map(int,input().split()) res,sq2=0,(2**.5) for i in range(1,m): res+=2+sq2+2*sq2*(i-1)+(i-1)*i res=(res+m)*2*r print(res/(m*m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var r : OclAny := null; Sequence{m,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var res : OclAny := null; var sq2 : OclAny := null; Sequence{res,sq2} := Sequence{0,((2)->pow(.5))} ; for i : Integer.subrange(1, m-1) do ( res := res + 2 + sq2 + 2 * sq2 * (i - 1) + (i - 1) * i) ; var res : double := (res + m) * 2 * r ; execute (res / (m * m))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,R=map(int,input().split()) print((2*m/3-2+22/m/3-4/m/m+2**.5*(2-4/m+2/m/m))*R) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var R : OclAny := null; Sequence{m,R} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((2 * m / 3 - 2 + 22 / m / 3 - 4 / m / m + (2)->pow(.5) * (2 - 4 / m + 2 / m / m)) * R)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,R=map(int,input().split()) print((2*m/3-2+22/m/3-4/m/m+2**.5*(2-4/m+2/m/m))*R) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var R : OclAny := null; Sequence{m,R} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((2 * m / 3 - 2 + 22 / m / 3 - 4 / m / m + (2)->pow(.5) * (2 - 4 / m + 2 / m / m)) * R)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout input=stdin.readline n=int(input()); sa=sg=0 for i in range(n): a,g=map(int,input().split()) if a<=g : if sa+a-sg<=500 : sa+=a ; stdout.write("A") else : sg+=g ; stdout.write("G") else : if sg+g-sa<=500 : sg+=g ; stdout.write("G") else : sa+=a ; stdout.write("A") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var sa : OclAny := 0; var sg : int := 0 ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var g : OclAny := null; Sequence{a,g} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(g)) <= 0 then ( if sa + a - sg <= 500 then ( sa := sa + a; stdout.write("A") ) else ( sg := sg + g; stdout.write("G") ) ) else ( if sg + g - sa <= 500 then ( sg := sg + g; stdout.write("G") ) else ( sa := sa + a; stdout.write("A") ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,r=map(int,input().split()) answer=0 from math import sqrt def fef(vev): if vev==0 : return 0 if vev<=1 : return 2*r+sqrt(2)*r curr=2*r+sqrt(2)*r curr+=(vev-1)*(2*r+sqrt(2)*2*r) curr+=r*(vev-1)*(vev-2) return curr for i in range(m): answer+=fef(i) answer+=fef(m-1-i) answer+=2*r print(answer/(m**2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var r : OclAny := null; Sequence{m,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var answer : int := 0 ; skip ; skip ; for i : Integer.subrange(0, m-1) do ( answer := answer + fef(i) ; answer := answer + fef(m - 1 - i) ; answer := answer + 2 * r) ; execute (answer / ((m)->pow(2)))->display(); operation fef(vev : OclAny) : OclAny pre: true post: true activity: if vev = 0 then ( return 0 ) else skip ; if vev <= 1 then ( return 2 * r + sqrt(2) * r ) else skip ; var curr : double := 2 * r + sqrt(2) * r ; curr := curr + (vev - 1) * (2 * r + sqrt(2) * 2 * r) ; curr := curr + r * (vev - 1) * (vev - 2) ; return curr; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,R=map(int,input().split()) print((2*m/3-2+22/m/3-4/m/m+2**.5*(2-4/m+2/m/m))*R) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var R : OclAny := null; Sequence{m,R} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((2 * m / 3 - 2 + 22 / m / 3 - 4 / m / m + (2)->pow(.5) * (2 - 4 / m + 2 / m / m)) * R)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* def countCubes(a,b): return(floor(b**(1./3.))-ceil(a**(1./3.))+1) a=7 b=28 print("Count of cubes is",countCubes(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 7 ; b := 28 ; execute ("Count of cubes is")->display(); operation countCubes(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (floor((b)->pow((1. / 3.))) - ceil((a)->pow((1. / 3.))) + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heappush,heappop INF=10**20 def search(item_lst,d): visited={} visited[(0,0)]=True que=[] heappush(que,(0,0,0)) while que : score,a,e=heappop(que) for da,de in item_lst[e]: na=a+da if na>=d : print(score+1) return True ne=e+de if ne>100 : ne=100 if(na,ne)not in visited : visited[(na,ne)]=True heappush(que,(score+1,na,ne)) print("NA") return False def main(): while True : d,n=map(int,input().split()) if d==0 : break item_lst=[[]for _ in range(101)] for _ in range(n): a,e,r=map(int,input().split()) for i in range(r,101): item_lst[i].append((a,e)) search(item_lst,d) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var INF : double := (10)->pow(20) ; skip ; skip ; main(); operation search(item_lst : OclAny, d : OclAny) : OclAny pre: true post: true activity: var visited : OclAny := Set{} ; visited[Sequence{0, 0}+1] := true ; var que : Sequence := Sequence{} ; heappush(que, Sequence{0, 0, 0}) ; while que do ( var score : OclAny := null; var a : OclAny := null; var e : OclAny := null; Sequence{score,a,e} := heappop(que) ; for _tuple : item_lst[e+1] do (var _indx : int := 1; var da : OclAny := _tuple->at(_indx); _indx := _indx + 1; var de : OclAny := _tuple->at(_indx); var na : OclAny := a + da ; if (na->compareTo(d)) >= 0 then ( execute (score + 1)->display() ; return true ) else skip ; var ne : OclAny := e + de ; if ne > 100 then ( ne := 100 ) else skip ; if (visited)->excludes(Sequence{na, ne}) then ( visited[Sequence{na, ne}+1] := true ; heappush(que, Sequence{score + 1, na, ne}) ) else skip)) ; execute ("NA")->display() ; return false; operation main() pre: true post: true activity: while true do ( var n : OclAny := null; Sequence{d,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if d = 0 then ( break ) else skip ; item_lst := Integer.subrange(0, 101-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var e : OclAny := null; var r : OclAny := null; Sequence{a,e,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(r, 101-1) do ((expr (atom (name item_lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name e))))))) )))))))) )))))) ; search(item_lst, d)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline write=sys.stdout.write def main(): while 1 : D,N=map(int,readline().split()) if D==N==0 : break P=[list(map(int,readline().split()))for i in range(N)] P.sort(key=lambda x : x[2]) INF=10**9 memo=[[INF]*101 for i in range(D+1)] memo[D][0]=0 for i in range(D,0,-1): P0=[(max(i-a,0),e,r)for a,e,r in P] for j,v in((j,e+1)for j,e in enumerate(memo[i])if ecollect( _x | (OclType["int"])->apply(_x) ) ; if D = N & (N == 0) then ( break ) else skip ; var P : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((readline().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; P := P->sort() ; var INF : double := (10)->pow(9) ; var memo : Sequence := Integer.subrange(0, D + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ INF }, 101))) ; memo[D+1]->first() := 0 ; for i : Integer.subrange(0 + 1, D)->reverse() do ( var P0 : Sequence := P->select(_tuple | true)->collect(_tuple | let a : OclAny = _tuple->at(1) in let e : OclAny = _tuple->at(2) in (Sequence{Set{i - a, 0}->max(), e, r})) ; for _tuple : Sequence{(testlist_comp (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name j)))))) , (test (logical_test (comparison (expr (expr (atom (name e))) + (expr (atom (number (integer 1))))))))) )))))) (comp_for for (exprlist (expr (atom (name j))) , (expr (atom (name e)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name memo)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name e)))) < (comparison (expr (atom (name INF))))))))))} do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); for _tuple : P0 do (var _indx : int := 1; var A0 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var e : OclAny := _tuple->at(_indx); _indx := _indx + 1; var r : OclAny := _tuple->at(_indx); if (j->compareTo(r)) < 0 then ( break ) else skip ; var E0 : OclAny := Set{j + e, 100}->min() ; if (v->compareTo(memo[A0+1][E0+1])) < 0 then ( memo[A0+1][E0+1] := v ) else skip))) ; var res : OclAny := (memo->first())->min() ; if res = INF then ( write("NA\n") ) else ( write(StringLib.format("%d\n",res)) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib,itertools def compute(): triangle=0 for i in itertools.count(1): triangle+=i if num_divisors(triangle)>500 : return str(triangle) def num_divisors(n): end=eulerlib.sqrt(n) result=sum(2 for i in range(1,end+1)if n % i==0) if end**2==n : result-=1 return result if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var triangle : int := 0 ; for i : itertools->count(1) do ( triangle := triangle + i ; if num_divisors(triangle) > 500 then ( return ("" + ((triangle))) ) else skip); operation num_divisors(n : OclAny) : OclAny pre: true post: true activity: var end : double := eulerlib.sqrt(n) ; var result : OclAny := ((argument (test (logical_test (comparison (expr (atom (number (integer 2))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name end))) + (expr (atom (number (integer 1)))))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (expr (atom (name n))) % (expr (atom (name i))))) == (comparison (expr (atom (number (integer 0))))))))))))->sum() ; if (end)->pow(2) = n then ( result := result - 1 ) else skip ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countNonIncreasing(arr,n): cnt=0 ; len=1 ; for i in range(0,n-1): if(arr[i+1]>=arr[i]): len+=1 ; else : cnt+=(((len+1)*len)/2); len=1 ; if(len>1): cnt+=(((len-1)*len)/2); return int(cnt); if __name__=='__main__' : arr=[5,2,3,7,1,1]; n=len(arr); print(countNonIncreasing(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{5}->union(Sequence{2}->union(Sequence{3}->union(Sequence{7}->union(Sequence{1}->union(Sequence{ 1 }))))); ; n := (arr)->size(); ; execute (countNonIncreasing(arr, n))->display(); ) else skip; operation countNonIncreasing(arr : OclAny, n : OclAny) pre: true post: true activity: var cnt : int := 0; ; var len : int := 1; ; for i : Integer.subrange(0, n - 1-1) do ( if ((arr[i + 1+1]->compareTo(arr[i+1])) >= 0) then ( len := len + 1; ) else ( cnt := cnt + (((len + 1) * len) / 2); ; len := 1; )) ; if (len > 1) then ( cnt := cnt + (((len - 1) * len) / 2); ) else skip ; return ("" + ((cnt)))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findDelta(a,b,c,d): return int((b*c-a*d)/(d-c)); a=3 ; b=9 ; c=3 ; d=5 ; print("X={}".format(findDelta(a,b,c,d))); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 3; b := 9; ; c := 3; d := 5; ; execute (StringLib.interpolateStrings("X={}", Sequence{findDelta(a, b, c, d)}))->display();; operation findDelta(a : OclAny, b : OclAny, c : OclAny, d : OclAny) pre: true post: true activity: return ("" + (((b * c - a * d) / (d - c))))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def SieveOfEratosthenes(n,isPrime): isPrime[0]=isPrime[1]=False for i in range(2,n+1): isPrime[i]=True p=2 while(p*p<=n): if(isPrime[p]==True): i=p*p while(i<=n): isPrime[i]=False i+=p p+=1 def findPrimePair(n): isPrime=[0]*(n+1) SieveOfEratosthenes(n,isPrime) for i in range(0,n): if(isPrime[i]and isPrime[n-i]): print(i,(n-i)) return n=74 findPrimePair(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 74 ; findPrimePair(n); operation SieveOfEratosthenes(n : OclAny, isPrime : OclAny) pre: true post: true activity: isPrime->first() := false; var isPrime[1+1] : boolean := false ; for i : Integer.subrange(2, n + 1-1) do ( isPrime[i+1] := true) ; var p : int := 2 ; while ((p * p->compareTo(n)) <= 0) do ( if (isPrime[p+1] = true) then ( var i : int := p * p ; while ((i->compareTo(n)) <= 0) do ( isPrime[i+1] := false ; i := i + p) ) else skip ; p := p + 1); operation findPrimePair(n : OclAny) pre: true post: true activity: isPrime := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; SieveOfEratosthenes(n, isPrime) ; for i : Integer.subrange(0, n-1) do ( if (isPrime[i+1] & isPrime[n - i+1]) then ( execute (i)->display() ; return ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def replaceDigit(x,d1,d2): result=0 ; multiply=1 ; while(x % 10>0): remainder=x % 10 ; if(remainder==d1): result=(result+d2*multiply); else : result=(result+remainder*multiply); multiply*=10 ; x=int(x/10); return result ; x=645 ; d1=6 ; d2=5 ; print(replaceDigit(x,d1,d2)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := 645; ; d1 := 6; ; d2 := 5; ; execute (replaceDigit(x, d1, d2))->display();; operation replaceDigit(x : OclAny, d1 : OclAny, d2 : OclAny) pre: true post: true activity: var result : int := 0; ; var multiply : int := 1; ; while (x mod 10 > 0) do ( var remainder : int := x mod 10; ; if (remainder = d1) then ( result := (result + d2 * multiply); ) else ( result := (result + remainder * multiply); ) ; multiply := multiply * 10; ; x := ("" + ((x / 10)))->toInteger();) ; return result;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=0 for i in range(n): a,g=map(int,input().split()) x+=a r=round(x/1000) print("A"*(n-r)+"G"*(r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := 0 ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var g : OclAny := null; Sequence{a,g} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; x := x + a) ; var r : double := (x / 1000)->round() ; execute (StringLib.nCopies("A", (n - r)) + StringLib.nCopies("G", (r)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W,N=list(map(int,input().split())) sr,sc=list(map(int,input().split())) S=list(input()) T=list(input()) ans=True si=sr sj=sc for i in range(N): if S[i]=="R" : sj+=1 if sj>W : ans=False break if T[i]=="L" : sj=max(1,sj-1) si=sr sj=sc for i in range(N): if S[i]=="L" : sj-=1 if sj<1 or(not ans): ans=False break if T[i]=="R" : sj=min(W,sj+1) si=sr sj=sc for i in range(N): if S[i]=="D" : si+=1 if si>H or(not ans): ans=False break if T[i]=="U" : si=max(1,si-1) si=sr sj=sc for i in range(N): if S[i]=="U" : si-=1 if si<1 or(not ans): ans=False break if T[i]=="D" : si=min(H,si+1) if ans : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; var N : OclAny := null; Sequence{H,W,N} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sr : OclAny := null; var sc : OclAny := null; Sequence{sr,sc} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var S : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var T : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var ans : boolean := true ; var si : OclAny := sr ; var sj : OclAny := sc ; for i : Integer.subrange(0, N-1) do ( if S[i+1] = "R" then ( sj := sj + 1 ) else skip ; if (sj->compareTo(W)) > 0 then ( ans := false ; break ) else skip ; if T[i+1] = "L" then ( sj := Set{1, sj - 1}->max() ) else skip) ; si := sr ; sj := sc ; for i : Integer.subrange(0, N-1) do ( if S[i+1] = "L" then ( sj := sj - 1 ) else skip ; if sj < 1 or (not(ans)) then ( ans := false ; break ) else skip ; if T[i+1] = "R" then ( sj := Set{W, sj + 1}->min() ) else skip) ; si := sr ; sj := sc ; for i : Integer.subrange(0, N-1) do ( if S[i+1] = "D" then ( si := si + 1 ) else skip ; if (si->compareTo(H)) > 0 or (not(ans)) then ( ans := false ; break ) else skip ; if T[i+1] = "U" then ( si := Set{1, si - 1}->max() ) else skip) ; si := sr ; sj := sc ; for i : Integer.subrange(0, N-1) do ( if S[i+1] = "U" then ( si := si - 1 ) else skip ; if si < 1 or (not(ans)) then ( ans := false ; break ) else skip ; if T[i+1] = "D" then ( si := Set{H, si + 1}->min() ) else skip) ; if ans then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): H,W,N=(int(i)for i in input().split()) sr,sc=(int(i)for i in input().split()) S=input() T=input() from collections import Counter S_C=Counter(S) if sc<=S_C['L']: move=0 for s,t in zip(S,T): if s=="L" : move+=1 if sc<=move : return print("NO") if t=="R" : move-=1 if-move==W-sc+1 : move+=1 if W-sc+1<=S_C['R']: move=0 for s,t in zip(S,T): if s=="R" : move+=1 if W-sc+1<=move : return print("NO") if t=="L" : move-=1 if-move==sc : move+=1 if sr<=S_C['U']: move=0 for s,t in zip(S,T): if s=="U" : move+=1 if sr<=move : return print("NO") if t=="D" : move-=1 if-move==H-sr+1 : move+=1 if H-sr+1<=S_C['D']: move=0 for s,t in zip(S,T): if s=="D" : move+=1 if H-sr+1<=move : return print("NO") if t=="U" : move-=1 if-move==sr : move+=1 print("YES") if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() : OclAny pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; var N : OclAny := null; Sequence{H,W,N} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var sr : OclAny := null; var sc : OclAny := null; Sequence{sr,sc} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var S : String := (OclFile["System.in"]).readLine() ; var T : String := (OclFile["System.in"]).readLine() ; skip ; var S_C : OclAny := Counter(S) ; if (sc->compareTo(S_C->at('L'))) <= 0 then ( var move : int := 0 ; for _tuple : Integer.subrange(1, S->size())->collect( _indx | Sequence{S->at(_indx), T->at(_indx)} ) do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); if s = "L" then ( move := move + 1 ) else skip ; if (sc->compareTo(move)) <= 0 then ( return ("NO")->display() ) else skip ; if t = "R" then ( move := move - 1 ; if -move = W - sc + 1 then ( move := move + 1 ) else skip ) else skip) ) else skip ; if (W - sc + 1->compareTo(S_C->at('R'))) <= 0 then ( move := 0 ; for _tuple : Integer.subrange(1, S->size())->collect( _indx | Sequence{S->at(_indx), T->at(_indx)} ) do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); if s = "R" then ( move := move + 1 ) else skip ; if (W - sc + 1->compareTo(move)) <= 0 then ( return ("NO")->display() ) else skip ; if t = "L" then ( move := move - 1 ; if -move = sc then ( move := move + 1 ) else skip ) else skip) ) else skip ; if (sr->compareTo(S_C->at('U'))) <= 0 then ( move := 0 ; for _tuple : Integer.subrange(1, S->size())->collect( _indx | Sequence{S->at(_indx), T->at(_indx)} ) do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); if s = "U" then ( move := move + 1 ) else skip ; if (sr->compareTo(move)) <= 0 then ( return ("NO")->display() ) else skip ; if t = "D" then ( move := move - 1 ; if -move = H - sr + 1 then ( move := move + 1 ) else skip ) else skip) ) else skip ; if (H - sr + 1->compareTo(S_C->at('D'))) <= 0 then ( move := 0 ; for _tuple : Integer.subrange(1, S->size())->collect( _indx | Sequence{S->at(_indx), T->at(_indx)} ) do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); if s = "D" then ( move := move + 1 ) else skip ; if (H - sr + 1->compareTo(move)) <= 0 then ( return ("NO")->display() ) else skip ; if t = "U" then ( move := move - 1 ; if -move = sr then ( move := move + 1 ) else skip ) else skip) ) else skip ; execute ("YES")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w,n=map(int,input().split()) s=list(map(int,input().split())) S=input() T=input() def YES(b): if not b : print('YES') else : print('NO') exit(0) return R=[s[0],s[0]] C=[s[1],s[1]] for i in range(n): if S[i]=='L' : C[0]-=1 if not(1<=C[0]<=w): YES(True) elif S[i]=='R' : C[1]+=1 if not(1<=C[1]<=w): YES(True) elif S[i]=='U' : R[0]-=1 if not(1<=R[0]<=h): YES(True) elif S[i]=='D' : R[1]+=1 if not(1<=R[1]<=h): YES(True) if T[i]=='R' and C[0]!=w : C[0]+=1 elif T[i]=='L' and C[1]!=1 : C[1]-=1 elif T[i]=='D' and R[0]!=h : R[0]+=1 elif T[i]=='U' and R[1]!=1 : R[1]-=1 YES(False) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; var n : OclAny := null; Sequence{h,w,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var S : String := (OclFile["System.in"]).readLine() ; var T : String := (OclFile["System.in"]).readLine() ; skip ; var R : Sequence := Sequence{s->first()}->union(Sequence{ s->first() }) ; var C : Sequence := Sequence{s[1+1]}->union(Sequence{ s[1+1] }) ; for i : Integer.subrange(0, n-1) do ( if S[i+1] = 'L' then ( C->first() := C->first() - 1 ; if not((1 <= C->first() & (C->first() <= w))) then ( YES(true) ) else skip ) else (if S[i+1] = 'R' then ( C[1+1] := C[1+1] + 1 ; if not((1 <= C[1+1] & (C[1+1] <= w))) then ( YES(true) ) else skip ) else (if S[i+1] = 'U' then ( R->first() := R->first() - 1 ; if not((1 <= R->first() & (R->first() <= h))) then ( YES(true) ) else skip ) else (if S[i+1] = 'D' then ( R[1+1] := R[1+1] + 1 ; if not((1 <= R[1+1] & (R[1+1] <= h))) then ( YES(true) ) else skip ) else skip ) ) ) ; if T[i+1] = 'R' & C->first() /= w then ( C->first() := C->first() + 1 ) else (if T[i+1] = 'L' & C[1+1] /= 1 then ( C[1+1] := C[1+1] - 1 ) else (if T[i+1] = 'D' & R->first() /= h then ( R->first() := R->first() + 1 ) else (if T[i+1] = 'U' & R[1+1] /= 1 then ( R[1+1] := R[1+1] - 1 ) else skip ) ) ) ) ; YES(false); operation YES(b : OclAny) pre: true post: true activity: if not(b) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ; exit(0) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys h,w,n=map(int,input().split()) y,x=map(int,input().split()) s=list(input()) t=list(input()) up=h down=1 right=w left=1 for i in range(n-1,-1,-1): if i!=n-1 : if t[i]=='D' : down=max(down-1,1) elif t[i]=='U' : up=min(up+1,h) elif t[i]=='R' : left=max(left-1,1) else : right=min(right+1,w) if s[i]=='D' : up-=1 elif s[i]=='U' : down+=1 elif s[i]=='R' : right-=1 else : left+=1 if right==0 or left==w or up==0 or down==h : print('NO') exit() if right=y and down<=y and right>=x and left<=x : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var h : OclAny := null; var w : OclAny := null; var n : OclAny := null; Sequence{h,w,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var y : OclAny := null; var x : OclAny := null; Sequence{y,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var t : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var up : OclAny := h ; var down : int := 1 ; var right : OclAny := w ; var left : int := 1 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if i /= n - 1 then ( if t[i+1] = 'D' then ( down := Set{down - 1, 1}->max() ) else (if t[i+1] = 'U' then ( up := Set{up + 1, h}->min() ) else (if t[i+1] = 'R' then ( left := Set{left - 1, 1}->max() ) else ( right := Set{right + 1, w}->min() ) ) ) ) else skip ; if s[i+1] = 'D' then ( up := up - 1 ) else (if s[i+1] = 'U' then ( down := down + 1 ) else (if s[i+1] = 'R' then ( right := right - 1 ) else ( left := left + 1 ) ) ) ; if right = 0 or left = w or up = 0 or down = h then ( execute ('NO')->display() ; exit() ) else skip ; if (right->compareTo(left)) < 0 or (up->compareTo(down)) < 0 then ( execute ('NO')->display() ; exit() ) else skip) ; if (up->compareTo(y)) >= 0 & (down->compareTo(y)) <= 0 & (right->compareTo(x)) >= 0 & (left->compareTo(x)) <= 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W,N=map(int,input().split()) s_r,s_c=map(int,input().split()) S=input() T=input() Judge=False S_L,S_R,S_U,S_D=0,0,0,0 T_L,T_R,T_U,T_D=0,0,0,0 for x in range(N): if S[x]=='L' : S_L+=1 if S_L-T_R-s_c==0 : Judge=True elif S[x]=='R' : S_R+=1 if s_c+(S_R-T_L)==W+1 : Judge=True elif S[x]=='U' : S_U+=1 if S_U-T_D-s_r==0 : Judge=True elif S[x]=='D' : S_D+=1 if s_r+(S_D-T_U)==H+1 : Judge=True if T[x]=='L' : if S_R-T_L+s_c!=1 : T_L+=1 if T[x]=='R' : if s_c+(T_R-S_L)!=W : T_R+=1 if T[x]=='U' : if S_D-T_U+s_r!=1 : T_U+=1 if T[x]=='D' : if s_r+(T_D-S_U)!=H : T_D+=1 if Judge : print('NO') else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; var N : OclAny := null; Sequence{H,W,N} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s_r : OclAny := null; var s_c : OclAny := null; Sequence{s_r,s_c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : String := (OclFile["System.in"]).readLine() ; var T : String := (OclFile["System.in"]).readLine() ; var Judge : boolean := false ; var S_L : OclAny := null; var S_R : OclAny := null; var S_U : OclAny := null; var S_D : OclAny := null; Sequence{S_L,S_R,S_U,S_D} := Sequence{0,0,0,0} ; var T_L : OclAny := null; var T_R : OclAny := null; var T_U : OclAny := null; var T_D : OclAny := null; Sequence{T_L,T_R,T_U,T_D} := Sequence{0,0,0,0} ; for x : Integer.subrange(0, N-1) do ( if S[x+1] = 'L' then ( S_L := S_L + 1 ; if S_L - T_R - s_c = 0 then ( Judge := true ) else skip ) else (if S[x+1] = 'R' then ( S_R := S_R + 1 ; if s_c + (S_R - T_L) = W + 1 then ( Judge := true ) else skip ) else (if S[x+1] = 'U' then ( S_U := S_U + 1 ; if S_U - T_D - s_r = 0 then ( Judge := true ) else skip ) else (if S[x+1] = 'D' then ( S_D := S_D + 1 ; if s_r + (S_D - T_U) = H + 1 then ( Judge := true ) else skip ) else skip ) ) ) ; if T[x+1] = 'L' then ( if S_R - T_L + s_c /= 1 then ( T_L := T_L + 1 ) else skip ) else skip ; if T[x+1] = 'R' then ( if s_c + (T_R - S_L) /= W then ( T_R := T_R + 1 ) else skip ) else skip ; if T[x+1] = 'U' then ( if S_D - T_U + s_r /= 1 then ( T_U := T_U + 1 ) else skip ) else skip ; if T[x+1] = 'D' then ( if s_r + (T_D - S_U) /= H then ( T_D := T_D + 1 ) else skip ) else skip) ; if Judge then ( execute ('NO')->display() ) else ( execute ('YES')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printPattern(i,j,n): if(j>=n): return 0 if(i>=n): return 1 if(j==i or j==n-1-i): if(i==n-1-j): print("/",end="") else : print("\\",end="") else : print("*",end="") if(printPattern(i,j+1,n)==1): return 1 print() return printPattern(i+1,0,n) if __name__=="__main__" : N=9 printPattern(0,0,N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var N : int := 9 ; printPattern(0, 0, N) ) else skip; operation printPattern(i : OclAny, j : OclAny, n : OclAny) : OclAny pre: true post: true activity: if ((j->compareTo(n)) >= 0) then ( return 0 ) else skip ; if ((i->compareTo(n)) >= 0) then ( return 1 ) else skip ; if (j = i or j = n - 1 - i) then ( if (i = n - 1 - j) then ( execute ("/")->display() ) else ( execute ("\\")->display() ) ) else ( execute ("*")->display() ) ; if (printPattern(i, j + 1, n) = 1) then ( return 1 ) else skip ; execute (->display() ; return printPattern(i + 1, 0, n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def getPairsCount(arr,n,sum): m=[0]*1000 for i in range(0,n): m[arr[i]] m[arr[i]]+=1 twice_count=0 for i in range(0,n): twice_count+=m[sum-arr[i]] if(sum-arr[i]==arr[i]): twice_count-=1 return int(twice_count/2) arr=[1,5,7,-1,5] n=len(arr) sum=6 print("Count of pairs is",getPairsCount(arr,n,sum)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{1}->union(Sequence{5}->union(Sequence{7}->union(Sequence{-1}->union(Sequence{ 5 })))) ; n := (arr)->size() ; sum := 6 ; execute ("Count of pairs is")->display(); operation getPairsCount(arr : OclAny, n : OclAny, sum : OclAny) : OclAny pre: true post: true activity: var m : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 1000) ; for i : Integer.subrange(0, n-1) do ( m[arr[i+1]+1] ; m[arr[i+1]+1] := m[arr[i+1]+1] + 1) ; var twice_count : int := 0 ; for i : Integer.subrange(0, n-1) do ( twice_count := twice_count + m[sum - arr[i+1]+1] ; if (sum - arr[i+1] = arr[i+1]) then ( twice_count := twice_count - 1 ) else skip) ; return ("" + ((twice_count / 2)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maximize(A1,A2,n,x,y): c=[0 for i in range(n)] Sum=0 for i in range(n): c[i]=A2[i]-A1[i] Sum+=A1[i] c.sort() c=c[: :-1] maxi=-1 for i in range(n): Sum+=c[i] if(i+1>=(n-x)): maxi=max(Sum,maxi) return maxi A1=[1,2,3,4,5] A2=[5,4,3,2,1] n=5 x,y=3,3 print(maximize(A1,A2,n,x,y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; A1 := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ; A2 := Sequence{5}->union(Sequence{4}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 1 })))) ; n := 5 ; Sequence{x,y} := Sequence{3,3} ; execute (maximize(A1, A2, n, x, y))->display(); operation maximize(A1 : OclAny, A2 : OclAny, n : OclAny, x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var c : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var Sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( c[i+1] := A2[i+1] - A1[i+1] ; Sum := Sum + A1[i+1]) ; c := c->sort() ; c := c(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var maxi : int := -1 ; for i : Integer.subrange(0, n-1) do ( Sum := Sum + c[i+1] ; if ((i + 1->compareTo((n - x))) >= 0) then ( maxi := Set{Sum, maxi}->max() ) else skip) ; return maxi; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Count_subarray(arr,n): subarray_sum,remaining_sum,count=0,0,0 ; for i in range(n): for j in range(i,n): subarray_sum=0 ; remaining_sum=0 ; for k in range(i,j+1): subarray_sum+=arr[k]; for l in range(i): remaining_sum+=arr[l]; for l in range(j+1,n): remaining_sum+=arr[l]; if(subarray_sum>remaining_sum): count+=1 ; return count ; if __name__=='__main__' : arr=[10,9,12,6]; n=len(arr); print(Count_subarray(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{10}->union(Sequence{9}->union(Sequence{12}->union(Sequence{ 6 }))); ; n := (arr)->size(); ; execute (Count_subarray(arr, n))->display(); ) else skip; operation Count_subarray(arr : OclAny, n : OclAny) pre: true post: true activity: var subarray_sum : OclAny := null; var remaining_sum : OclAny := null; var count : OclAny := null; Sequence{subarray_sum,remaining_sum,count} := Sequence{0,0,0}; ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i, n-1) do ( var subarray_sum : int := 0; ; var remaining_sum : int := 0; ; for k : Integer.subrange(i, j + 1-1) do ( subarray_sum := subarray_sum + arr[k+1];) ; for l : Integer.subrange(0, i-1) do ( remaining_sum := remaining_sum + arr[l+1];) ; for l : Integer.subrange(j + 1, n-1) do ( remaining_sum := remaining_sum + arr[l+1];) ; if ((subarray_sum->compareTo(remaining_sum)) > 0) then ( count := count + 1; ) else skip)) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,x,a,b=map(int,input().split()) p=abs(a-b) q=p+x if q>=n-1 : print(n-1) else : print(q) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,x,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : double := (a - b)->abs() ; var q : OclAny := p + x ; if (q->compareTo(n - 1)) >= 0 then ( execute (n - 1)->display() ) else ( execute (q)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- firstline=int(input()) total=0 memory=[] for x in range(firstline): A,G=list(map(int,input().split())) if total+A<=500 : total+=A memory.append("A") else : total-=G memory.append("G") print("".join(memory)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var firstline : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var total : int := 0 ; var memory : Sequence := Sequence{} ; for x : Integer.subrange(0, firstline-1) do ( var A : OclAny := null; var G : OclAny := null; Sequence{A,G} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if total + A <= 500 then ( total := total + A ; execute (("A") : memory) ) else ( total := total - G ; execute (("G") : memory) )) ; execute (StringLib.sumStringsWithSeparator((memory), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in " "*int(input()): n,x,a,b=map(int,input().split()) s=abs(a-b)+x print((s,n-1)[s+1>=n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : StringLib.nCopies(" ", ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var n : OclAny := null; var x : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,x,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : double := (a - b)->abs() + x ; execute (Sequence{s, n - 1}->select((s + 1->compareTo(n)) >= 0))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,x,a,b=map(int,input().split()) if a>b : a,b=b,a f=min(x,a-1) s=min(x-f,n-b) ans=b-a+f+s print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,x,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(b)) > 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a} ) else skip ; var f : OclAny := Set{x, a - 1}->min() ; var s : OclAny := Set{x - f, n - b}->min() ; var ans : double := b - a + f + s ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,x,a,b=map(int,input().split()) print(min(n-1,abs(a-b)+x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,x,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{n - 1, (a - b)->abs() + x}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,x,a,b=map(int,input().split()) print(min(n-1,abs(a-b)+x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,x,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{n - 1, (a - b)->abs() + x}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(input()) s=[0]*n for i in range(n): s[i]=int(input()) s=sorted(s) t=sum(s) if t % 10!=0 : print(t) sys.exit() for i in range(n): t=sum(s[: i])+sum(s[i+1 :]) if t % 10!=0 : print(t) sys.exit() print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( s[i+1] := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; s := s->sort() ; var t : OclAny := (s)->sum() ; if t mod 10 /= 0 then ( execute (t)->display() ; sys.exit() ) else skip ; for i : Integer.subrange(0, n-1) do ( t := (s.subrange(1,i))->sum() + (s.subrange(i + 1+1))->sum() ; if t mod 10 /= 0 then ( execute (t)->display() ; sys.exit() ) else skip) ; execute (0)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,ss): if all(s % 10==0 for s in ss): return 0 t=sum(ss) if t % 10!=0 : return t else : m=min(s for s in ss if s % 10!=0) return t-m def main(): n=int(input()) ss=[int(input())for _ in range(n)] print(solve(n,ss)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(n : OclAny, ss : OclAny) : OclAny pre: true post: true activity: if ((argument (test (logical_test (comparison (comparison (expr (expr (atom (name s))) % (expr (atom (number (integer 10)))))) == (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name ss))))))))->forAll( _x | _x = true ) then ( return 0 ) else skip ; var t : OclAny := (ss)->sum() ; if t mod 10 /= 0 then ( return t ) else ( var m : OclAny := ((argument (test (logical_test (comparison (expr (atom (name s)))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name ss))))) (comp_iter if (test (logical_test (comparison (comparison (expr (expr (atom (name s))) % (expr (atom (number (integer 10)))))) != (comparison (expr (atom (number (integer 0))))))))))))->min() ; return t - m ); operation main() pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; ss := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; execute (solve(n, ss))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n,*lst=map(int,sys.stdin.read().split()) res=sum(lst) if not res % 10 : tmp=[i for i in lst if i % 10] if tmp : res-=min(tmp) else : res=0 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var lst : OclAny := null; Sequence{n,lst} := (sys.stdin.readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var res : OclAny := (lst)->sum() ; if not(res mod 10) then ( var tmp : Sequence := lst->select(i | i mod 10)->collect(i | (i)) ; if tmp then ( res := res - (tmp)->min() ) else ( res := 0 ) ) else skip ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=[] for i in range(0,n): s.append(int(input())) sum=0 s.sort() for i in range(0,n): sum+=s[i] if sum % 10==0 : for i in range(0,n): if s[i]% 10==0 : continue else : sum-=s[i] break if sum % 10==0 : print(0) else : print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : s)) ; var sum : int := 0 ; s := s->sort() ; for i : Integer.subrange(0, n-1) do ( sum := sum + s[i+1]) ; if sum mod 10 = 0 then ( for i : Integer.subrange(0, n-1) do ( if s[i+1] mod 10 = 0 then ( continue ) else ( sum := sum - s[i+1] ; break )) ) else skip ; if sum mod 10 = 0 then ( execute (0)->display() ) else ( execute (sum)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): x=int(input()) if x//1000>0 : print(10*(x % 10-1)+10) elif x//100>0 : print(10*(x % 10-1)+6) elif x//10>0 : print(10*(x % 10-1)+3) else : print(10*(x % 10-1)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if x div 1000 > 0 then ( execute (10 * (x mod 10 - 1) + 10)->display() ) else (if x div 100 > 0 then ( execute (10 * (x mod 10 - 1) + 6)->display() ) else (if x div 10 > 0 then ( execute (10 * (x mod 10 - 1) + 3)->display() ) else ( execute (10 * (x mod 10 - 1) + 1)->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=[0]*N min_value=float('inf') for i in range(N): A[i]=int(input()) if(A[i]% 10!=0): min_value=min(min_value,A[i]) A.sort() sum_A=sum(A) if(sum_A % 10!=0): print(sum_A) else : if(min_value!=float('inf')): print(sum_A-min_value) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var min_value : double := ("" + (('inf')))->toReal() ; for i : Integer.subrange(0, N-1) do ( A[i+1] := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (A[i+1] mod 10 /= 0) then ( min_value := Set{min_value, A[i+1]}->min() ) else skip) ; A := A->sort() ; var sum_A : OclAny := (A)->sum() ; if (sum_A mod 10 /= 0) then ( execute (sum_A)->display() ) else ( if (min_value /= ("" + (('inf')))->toReal()) then ( execute (sum_A - min_value)->display() ) else ( execute (0)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- total=0 memory="" firstline=int(input()) for x in range(firstline): A,G=list(map(int,input().split())) if total+A<=500 : total+=A memory+="A" else : total-=G memory+="G" print(memory) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var total : int := 0 ; var memory : String := "" ; var firstline : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for x : Integer.subrange(0, firstline-1) do ( var A : OclAny := null; var G : OclAny := null; Sequence{A,G} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if total + A <= 500 then ( total := total + A ; memory := memory + "A" ) else ( total := total - G ; memory := memory + "G" )) ; execute (memory)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque from math import* import sys import random from bisect import* from functools import reduce for _ in range(int(input())): n,k=map(int,input().split()) arr=list(map(int,input().split())) res=sys.maxsize for color in range(1,101): i=0 day=0 while itoInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; for color : Integer.subrange(1, 101-1) do ( var i : int := 0 ; var day : int := 0 ; while (i->compareTo(n)) < 0 do ( if (i->compareTo(n)) < 0 & arr[i+1] /= color then ( i := i + k ; day := day + 1 ) else ( i := i + 1 )) ; res := Set{res, day}->min()) ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from collections import Counter for _ in range(int(input())): n,k=map(int,input().split()) w=list(map(int,input().split())) if k==1 : print(n-max(Counter(w).values())) else : d,m=set(w),10**5 for i in d : a,b=0,0 while atoInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if k = 1 then ( execute (n - (Counter(w).values())->max())->display() ) else ( var d : OclAny := null; var m : OclAny := null; Sequence{d,m} := Sequence{Set{}->union((w)),(10)->pow(5)} ; for i : d do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{0,0} ; while (a->compareTo(n)) < 0 do ( if w[a+1] /= i then ( a := a + k ; b := b + 1 ) else ( a := a + 1 )) ; var m : OclAny := Set{m, b}->min()) ; execute (m)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) c=list(map(int,input().split())) s=set(c) ans=10**9 for item in s : i=0 count=0 while itoInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Set := Set{}->union((c)) ; var ans : double := (10)->pow(9) ; for item : s do ( var i : int := 0 ; var count : int := 0 ; while (i->compareTo(n)) < 0 do ( if c[i+1] = item then ( i := i + 1 ) else ( i := i + k ; count := count + 1 )) ; ans := Set{ans, count}->min()) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input for _ in range(int(I())): n,k=map(int,I().split()) lst=list(map(int,I().split())) ans=n for c in set(lst): i,res=0,0 while itoInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (I().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lst : Sequence := ((I().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : OclAny := n ; for c : Set{}->union((lst)) do ( var i : OclAny := null; var res : OclAny := null; Sequence{i,res} := Sequence{0,0} ; while (i->compareTo(n)) < 0 do ( if lst[i+1] = c then ( i := i + 1 ) else ( i := i + k ; res := res + 1 )) ; ans := Set{res, ans}->min()) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter for _ in range(int(input())): n,k=[int(i)for i in input().split()] a=[int(i)for i in input().split()] w=100000000 for key in range(1,101): i=0 ans=0 while itoInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var w : int := 100000000 ; for key : Integer.subrange(1, 101-1) do ( var i : int := 0 ; var ans : int := 0 ; while (i->compareTo(n)) < 0 do ( while (i->compareTo(n)) < 0 & a[i+1] = key do ( i := i + 1) ; if i = n then ( break ) else skip ; if a[i+1] /= key then ( var c : int := 0 ; while (i->compareTo(n)) < 0 & (c->compareTo(k)) < 0 do ( c := c + 1 ; i := i + 1) ; ans := ans + 1 ) else skip) ; w := Set{w, ans}->min()) ; execute (w)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def findRepeatingNumber(arr,n): sq=sqrt(n) range__=int((n/sq)+1) count=[0 for i in range(range__)] for i in range(0,n+1,1): count[int((arr[i]-1)/sq)]+=1 selected_block=range__-1 for i in range(0,range__-1,1): if(count[i]>sq): selected_block=i break m={i : 0 for i in range(n)} for i in range(0,n+1,1): if(((selected_block*sq)1): return arr[i] return-1 if __name__=='__main__' : arr=[1,1,2,3,5,4] n=5 print("One of the numbers repeated in the array is:",findRepeatingNumber(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 4 }))))) ; n := 5 ; execute ("One of the numbers repeated in the array is:")->display() ) else skip; operation findRepeatingNumber(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sq : OclAny := sqrt(n) ; var range__ : int := ("" + (((n / sq) + 1)))->toInteger() ; var count : Sequence := Integer.subrange(0, range__-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n + 1-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( count[("" + (((arr[i+1] - 1) / sq)))->toInteger()+1] := count[("" + (((arr[i+1] - 1) / sq)))->toInteger()+1] + 1) ; var selected_block : double := range__ - 1 ; for i : Integer.subrange(0, range__ - 1-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if ((count[i+1]->compareTo(sq)) > 0) then ( selected_block := i ; break ) else skip) ; var m : Map := Integer.subrange(0, n-1)->select(i | true)->collect(i | Map{i |-> 0})->unionAll() ; for i : Integer.subrange(0, n + 1-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if ((((selected_block * sq)->compareTo(arr[i+1])) < 0) & ((arr[i+1]->compareTo(((selected_block + 1) * sq))) <= 0)) then ( m[arr[i+1]+1] := m[arr[i+1]+1] + 1 ; if (m[arr[i+1]+1] > 1) then ( return arr[i+1] ) else skip ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def maxPrimeFactors(n): maxPrime=-1 while n % 2==0 : maxPrime=2 n>>=1 for i in range(3,int(math.sqrt(n))+1,2): while n % i==0 : maxPrime=i n=n/i if n>2 : maxPrime=n return int(maxPrime) n=15 print(maxPrimeFactors(n)) n=25698751364526 print(maxPrimeFactors(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 15 ; execute (maxPrimeFactors(n))->display() ; n := 25698751364526 ; execute (maxPrimeFactors(n))->display(); operation maxPrimeFactors(n : OclAny) : OclAny pre: true post: true activity: var maxPrime : int := -1 ; while n mod 2 = 0 do ( maxPrime := 2 ; n := n div (2->pow(1))) ; for i : Integer.subrange(3, ("" + (((n)->sqrt())))->toInteger() + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( while n mod i = 0 do ( maxPrime := i ; n := n / i)) ; if n > 2 then ( maxPrime := n ) else skip ; return ("" + ((maxPrime)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) l=list(map(int,input().split())) count=0 for i in l : count+=i % 2 print(min(count,n-count)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : int := 0 ; for i : l do ( count := count + i mod 2) ; execute (Set{count, n - count}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: a=[0,0] for x in s.split(): a[int(x)% 2]+=1 print(min(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var a : Sequence := Sequence{0}->union(Sequence{ 0 }) ; for x : s.split() do ( a[("" + ((x)))->toInteger() mod 2+1] := a[("" + ((x)))->toInteger() mod 2+1] + 1) ; execute ((a)->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=input() print((int(n[0])-1)*10+(len(n)*len(n)+len(n))//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : String := (OclFile["System.in"]).readLine() ; execute ((("" + ((n->first())))->toInteger() - 1) * 10 + ((n)->size() * (n)->size() + (n)->size()) div 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) res='' anet=0 gnet=0 for _ in range(n): x,y=map(int,input().split()) if(x<=y and anet+x<=gnet+500)or(gnet+y>anet+500): anet+=x res+="A" else : gnet+=y res+="G" print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : String := '' ; var anet : int := 0 ; var gnet : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if ((x->compareTo(y)) <= 0 & (anet + x->compareTo(gnet + 500)) <= 0) or ((gnet + y->compareTo(anet + 500)) > 0) then ( anet := anet + x ; res := res + "A" ) else ( gnet := gnet + y ; res := res + "G" )) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): b=int(input()) a=[int(i)for i in input().split()] jup=[i for i in a if i % 2==0] tak=[i for i in a if i % 2!=0] print(min(len(jup),len(tak))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var jup : Sequence := a->select(i | i mod 2 = 0)->collect(i | (i)) ; var tak : Sequence := a->select(i | i mod 2 /= 0)->collect(i | (i)) ; execute (Set{(jup)->size(), (tak)->size()}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while(t>0): n=int(input()) lst=list(map(int,input().split())) e=0 o=0 for i in lst : if i % 2!=0 : o+=1 else : e+=1 if e==0 or o==0 : print(0) elif e>o : print(o) else : print(e) t=t-1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (t > 0) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var e : int := 0 ; var o : int := 0 ; for i : lst do ( if i mod 2 /= 0 then ( o := o + 1 ) else ( e := e + 1 )) ; if e = 0 or o = 0 then ( execute (0)->display() ) else (if (e->compareTo(o)) > 0 then ( execute (o)->display() ) else ( execute (e)->display() ) ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) a=list(map(int,input().split())) u=0 v=0 j=0 while jtoInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var u : int := 0 ; var v : int := 0 ; var j : int := 0 ; while (j->compareTo(n)) < 0 do ( if a[j+1] mod 2 = 1 then ( u := u + 1 ) else ( v := v + 1 ) ; j := j + 1) ; execute (Set{u, v}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() num_0=0 num_1=0 for i in range(len(s)): if s[i]=="0" : num_0+=1 else : num_1+=1 print(min(num_0,num_1)*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var num_0 : int := 0 ; var num var s : String := (OclFile["System.in"]).readLine() : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = "0" then ( num_0 := num_0 + 1 ) else ( num var s : String := (OclFile["System.in"]).readLine() := num var s : String := (OclFile["System.in"]).readLine() + 1 )) ; execute (Set{num_0, numnum_0}->min() * 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque from collections import Counter from itertools import product,permutations,combinations from operator import itemgetter from heapq import heappop,heappush from bisect import bisect_left,bisect_right,bisect from fractions import gcd from math import ceil,floor,sqrt,cos,sin,pi,factorial import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines sys.setrecursionlimit(10**8) INF=float('inf') MOD=10**9+7 def main(): s=input() if len(set(s))==1 : print(0) sys.exit() a=Counter(s) ans=min(a.values())*2 print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; sys.setrecursionlimit((10)->pow(8)) ; var INF : double := ("" + (('inf')))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; if (Set{}->union((s)))->size() = 1 then ( execute (0)->display() ; sys.exit() ) else skip ; var a : OclAny := Counter(s) ; var ans : double := (a.values())->min() * 2 ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(2*min(map(input().count,"01"))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (2 * (("01")->collect( _x | (input().count)->apply(_x) ))->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=list(input()) a=S.count('1') b=S.count('0') print(2*min(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var a : int := S->count('1') ; var b : int := S->count('0') ; execute (2 * Set{a, b}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(input()) before=[] cnt=0 for i,now in enumerate(s): if i==0 or len(before)==0 : before.append(now) continue if before[-1]!=now : before.pop() cnt+=2 else : before.append(now) print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var before : Sequence := Sequence{} ; var cnt : int := 0 ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var now : OclAny := _tuple->at(_indx); if i = 0 or (before)->size() = 0 then ( execute ((now) : before) ; continue ) else skip ; if before->last() /= now then ( before := before->front() ; cnt := cnt + 2 ) else ( execute ((now) : before) )) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pythagoreanTriplet(n): for i in range(1,int(n/3)+1): for j in range(i+1,int(n/2)+1): k=n-i-j if(i*i+j*j==k*k): print(i,",",j,",",k,sep="") return print("No Triplet") n=12 pythagoreanTriplet(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 12 ; pythagoreanTriplet(n); operation pythagoreanTriplet(n : OclAny) pre: true post: true activity: for i : Integer.subrange(1, ("" + ((n / 3)))->toInteger() + 1-1) do ( for j : Integer.subrange(i + 1, ("" + ((n / 2)))->toInteger() + 1-1) do ( var k : double := n - i - j ; if (i * i + j * j = k * k) then ( execute (i)->display() ; return ) else skip)) ; execute ("No Triplet")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def countDigits(a,b): if(a==0 or b==0): return 1 return math.floor(math.log10(abs(a))+math.log10(abs(b)))+1 a=33 b=-24 print(countDigits(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 33 ; b := -24 ; execute (countDigits(a, b))->display(); operation countDigits(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0 or b = 0) then ( return 1 ) else skip ; return (((a)->abs())->log10() + ((b)->abs())->log10())->floor() + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def toHex(self,num): if num==0 : return '0' mp='0123456789abcdef' ans='' for _ in range(8): n=num & 15 c=mp[n] ans=c+ans num=num>>4 return ans.lstrip('0') ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation toHex(num : OclAny) : OclAny pre: true post: true activity: if num = 0 then ( return '0' ) else skip ; var mp : String := '0123456789abcdef' ; var ans : String := '' ; for _anon : Integer.subrange(0, 8-1) do ( var n : int := MathLib.bitwiseAnd(num, 15) ; var c : OclAny := mp[n+1] ; ans := c + ans ; num := num /(2->pow(4))) ; return ans.lstrip('0'); } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) P=list(map(int,input().split())) L=[] for i in range(M): L.append(list(map(int,input().split()))) par=[] rank=[] for i in range(N): par.append(i) rank.append(0) def find(x,par): if par[x]==x : return x else : return find(par[x],par) def unite(x,y,par,rank): x=find(x,par) y=find(y,par) if x!=y : if rank[x]collect( _x | (OclType["int"])->apply(_x) ) ; var P : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var L : Sequence := Sequence{} ; for i : Integer.subrange(0, M-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : L)) ; var par : Sequence := Sequence{} ; var rank : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute ((i) : par) ; execute ((0) : rank)) ; skip ; skip ; for i : Integer.subrange(0, M-1) do ( unite(L[i+1]->first() - 1, L[i+1][1+1] - 1, par, rank)) ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( if find(P[i+1] - 1, par) = find(i, par) then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); operation find(x : OclAny, par : OclAny) : OclAny pre: true post: true activity: if par[x+1] = x then ( return x ) else ( return find(par[x+1], par) ); operation unite(x : OclAny, y : OclAny, par : OclAny, rank : OclAny) pre: true post: true activity: x := find(x, par) ; y := find(y, par) ; if x /= y then ( if (rank[x+1]->compareTo(rank[y+1])) < 0 then ( par[x+1] := y ) else ( par[y+1] := x ; if rank[x+1] = rank[y+1] then ( rank[x+1] := rank[x+1] + 1 ) else skip ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) c=0 q=0 for i in range(a): b=str(input()) d=list(dict.fromkeys(str(b))) if len(b)==1 : q=1 elif len(b)==2 : q=3 elif len(b)==3 : q=6 elif len(b)==4 : q=10 if d[0]!="1" : c=(int(d[0])-1)*10+q print(c) else : print(q) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := 0 ; var q : int := 0 ; for i : Integer.subrange(0, a-1) do ( var b : String := ("" + (((OclFile["System.in"]).readLine()))) ; var d : Sequence := ((trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) ))))))))) ))))->keys()->asSequence() ; if (b)->size() = 1 then ( q := 1 ) else (if (b)->size() = 2 then ( q := 3 ) else (if (b)->size() = 3 then ( q := 6 ) else (if (b)->size() = 4 then ( q := 10 ) else skip ) ) ) ; if d->first() /= "1" then ( c := (("" + ((d->first())))->toInteger() - 1) * 10 + q ; execute (c)->display() ) else ( execute (q)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def indexOfFirstOne(arr,low,high): while(low<=high): mid=(low+high)//2 if(arr[mid]==1 and(mid==0 or arr[mid-1]==0)): break elif(arr[mid]==1): high=mid-1 else : low=mid+1 return mid def posOfFirstOne(arr): l=0 h=1 while(arr[h]==0): l=h h=2*h return indexOfFirstOne(arr,l,h) arr=[0,0,1,1,1,1] print("Index=",posOfFirstOne(arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))))) ; execute ("Index=")->display(); operation indexOfFirstOne(arr : OclAny, low : OclAny, high : OclAny) : OclAny pre: true post: true activity: while ((low->compareTo(high)) <= 0) do ( var mid : int := (low + high) div 2 ; if (arr[mid+1] = 1 & (mid = 0 or arr[mid - 1+1] = 0)) then ( break ) else (if (arr[mid+1] = 1) then ( high := mid - 1 ) else ( low := mid + 1 ) ) ) ; return mid; operation posOfFirstOne(arr : OclAny) : OclAny pre: true post: true activity: var l : int := 0 ; var h : int := 1 ; while (arr[h+1] = 0) do ( l := h ; h := 2 * h) ; return indexOfFirstOne(arr, l, h); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import os import random import re import sys from math import gcd from math import sqrt n=int(input()) if n % 3==0 : print(n//3*2) elif n<3 : print(1) else : print(n//3*2+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 3 = 0 then ( execute (n div 3 * 2)->display() ) else (if n < 3 then ( execute (1)->display() ) else ( execute (n div 3 * 2 + 1)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=n//3 x*=2 if n % 3>0 : x+=1 print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := n div 3 ; x := x * 2 ; if n mod 3 > 0 then ( x := x + 1 ) else skip ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print((n*2+1)//3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((n * 2 + 1) div 3)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 3==0 : print(n//3*2) else : print(n//3*2+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 3 = 0 then ( execute (n div 3 * 2)->display() ) else ( execute (n div 3 * 2 + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) z=a//3*2 l=a % 3 if l==0 : z+=0 if l==1 : z+=1 if l==2 : z+=1 print(z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var z : int := a div 3 * 2 ; var l : int := a mod 3 ; if l = 0 then ( z := z + 0 ) else skip ; if l = 1 then ( z := z + 1 ) else skip ; if l = 2 then ( z := z + 1 ) else skip ; execute (z)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while(True): n=float(input()) if n<0 : break if int(n*16)-n*16 : print("NA"); continue else : s=bin(int(n*16))[2 :].zfill(12) print(s[:-4]+"."+s[-4 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while (true) do ( var n : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; if n < 0 then ( break ) else skip ; if ("" + ((n * 16)))->toInteger() - n * 16 then ( execute ("NA")->display(); continue ) else ( var s : OclAny := bin(("" + ((n * 16)))->toInteger()).subrange(2+1).zfill(12) ; execute (s.subrange(1,-4) + "." + s.subrange(-4+1))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,struct PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") while True : n=float(input()) if n<0 : break pre=int(n) post=n-int(n) res=bin(pre)[2 :].zfill(8)+'.' for k in range(4): post*=2 res+=str(int(post)) post-=int(post) if pre>255 or post>0 : print("NA") else : print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; while true do ( var n : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; if n < 0 then ( break ) else skip ; var pre : int := ("" + ((n)))->toInteger() ; var post : double := n - ("" + ((n)))->toInteger() ; var res : OclAny := bin(pre).subrange(2+1).zfill(8) + '.' ; for k : Integer.subrange(0, 4-1) do ( post := post * 2 ; res := res + ("" + ((("" + ((post)))->toInteger()))) ; post := post - ("" + ((post)))->toInteger()) ; if pre > 255 or post > 0 then ( execute ("NA")->display() ) else ( execute (res)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,P=map(int,input().split()) def combi(N,K): a=1 for i in range(K): a*=N-i for j in range(K): a/=j+1 return a ans=0 lis=list(map(int,input().split())) ls=[] for a in lis : ls.append(a % 2) one=ls.count(1) zero=ls.count(0) pattern_a=0 pattern_b=0 for j in range(zero+1): pattern_b+=combi(zero,j) time=0 while time<=one : if time % 2==P : pattern_a+=combi(one,time) time+=1 print(int(pattern_a*pattern_b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var P : OclAny := null; Sequence{N,P} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; var ans : int := 0 ; var lis : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ls : Sequence := Sequence{} ; for a : lis do ( execute ((a mod 2) : ls)) ; var one : int := ls->count(1) ; var zero : int := ls->count(0) ; var pattern_a : int := 0 ; var pattern_b : int := 0 ; for j : Integer.subrange(0, zero + 1-1) do ( pattern_b := pattern_b + combi(zero, j)) ; var time : int := 0 ; while (time->compareTo(one)) <= 0 do ( if time mod 2 = P then ( pattern_a := pattern_a + combi(one, time) ) else skip ; time := time + 1) ; execute (("" + ((pattern_a * pattern_b)))->toInteger())->display(); operation combi(N : OclAny, K : OclAny) : OclAny pre: true post: true activity: var a : int := 1 ; for i : Integer.subrange(0, K-1) do ( a := a * N - i) ; for j : Integer.subrange(0, K-1) do ( a := a / j + 1) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numbers=list(map(int,input().split())) start=0 arr=[] count=0 for i in range(0,numbers[0]): string="" next=start for j in range(0,numbers[0]): if count=numbers[0]: start=1 if start==0 else 0 else : string+="S" else : string+="S" arr.append(string) if countcollect( _x | (OclType["int"])->apply(_x) )) ; var start : int := 0 ; var arr : Sequence := Sequence{} ; var count : int := 0 ; for i : Integer.subrange(0, numbers->first()-1) do ( var string : String := "" ; var next : int := start ; for j : Integer.subrange(0, numbers->first()-1) do ( if (count->compareTo(numbers[1+1])) < 0 then ( if j = next then ( string := string + 'L' ; count := count + 1 ; next := next + 2 ; if (next->compareTo(numbers->first())) >= 0 then ( start := if start = 0 then 1 else 0 endif ) else skip ) else ( string := string + "S" ) ) else ( string := string + "S" )) ; execute ((string) : arr)) ; if (count->compareTo(numbers[1+1])) < 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; for i : arr do ( execute (i)->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def solve(f): if f>=256.0 : return 'NA' f*=16 int_f=int(f) if f!=int_f : return 'NA' bin_f=bin(int_f)[2 :] fraction_p=bin_f[-4 :] integer_p=bin_f[:-4] return integer_p.zfill(8)+'.'+fraction_p.zfill(4) def main(args): while True : f=float(input()) if f<0.0 : break result=solve(f) print(result) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(f : OclAny) : OclAny pre: true post: true activity: if f >= 256.0 then ( return 'NA' ) else skip ; f := f * 16 ; var int_f : int := ("" + ((f)))->toInteger() ; if f /= int_f then ( return 'NA' ) else skip ; var bin_f : OclAny := bin(int_f).subrange(2+1) ; var fraction_p : OclAny := bin_f.subrange(-4+1) ; var integer_p : OclAny := bin_f.subrange(1,-4) ; return integer_p.zfill(8) + '.' + fraction_p.zfill(4); operation main(args : OclAny) pre: true post: true activity: while true do ( f := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; if f < 0.0 then ( break ) else skip ; var result : OclAny := solve(f) ; execute (result)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def to_digit(f): u=int(f) d=f-u us="" if u==0 : us="0"*8 else : cnt=8 while u : if cnt==0 : return("DAME","DESU!!") cnt-=1 us+=str(u % 2) u//=2 us+="0"*cnt us=us[: :-1] ds="" cnt=4 acc=1 while d>0 : if cnt==0 : return("DAME","DESU!!") cnt-=1 acc/=2 if d>=acc : d-=acc ds+="1" else : ds+="0" ds+="0"*cnt return(us,ds) while True : f=float(input()) if f<0 : break us,ds=to_digit(f) if us=="DAME" : print("NA") else : print(us,ds,sep=".") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( f := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; if f < 0 then ( break ) else skip ; Sequence{us,ds} := to_digit(f) ; if us = "DAME" then ( execute ("NA")->display() ) else ( execute (us)->display() )); operation to_digit(f : OclAny) : OclAny pre: true post: true activity: var u : int := ("" + ((f)))->toInteger() ; var d : double := f - u ; var us : String := "" ; if u = 0 then ( us := StringLib.nCopies("0", 8) ) else ( var cnt : int := 8 ; while u do ( if cnt = 0 then ( return Sequence{"DAME", "DESU!!"} ) else skip ; cnt := cnt - 1 ; us := us + ("" + ((u mod 2))) ; u := u div 2) ; us := us + StringLib.nCopies("0", cnt) ; us := us(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ) ; var ds : String := "" ; cnt := 4 ; var acc : int := 1 ; while d > 0 do ( if cnt = 0 then ( return Sequence{"DAME", "DESU!!"} ) else skip ; cnt := cnt - 1 ; acc := acc / 2 ; if (d->compareTo(acc)) >= 0 then ( d := d - acc ; ds := ds + "1" ) else ( ds := ds + "0" )) ; ds := ds + StringLib.nCopies("0", cnt) ; return Sequence{us, ds}; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- loop=int(input()) for n in range(loop): item=input() result=item[0] sum=0 for j in range(0,len(item)): sum=sum+j+1 if result!=1 : print((int(result)-1)*10+sum) else : print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var loop : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for n : Integer.subrange(0, loop-1) do ( var item : String := (OclFile["System.in"]).readLine() ; var result : OclAny := item->first() ; var sum : int := 0 ; for j : Integer.subrange(0, (item)->size()-1) do ( sum := sum + j + 1) ; if result /= 1 then ( execute ((("" + ((result)))->toInteger() - 1) * 10 + sum)->display() ) else ( execute (sum)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : N=input() if N.find(".")<0 : N=N+".0" strA,strB=N.split(".") a=int(strA) if strA[0]=="-" : break b=int(strB)*(10**(4-len(strB))) s1="" s2="" for i in range(8): if a>0 : s1=str(a % 2)+s1 a=a//2 else : s1="0"+s1 for i in range(4): if b>0 : s2=s2+str((b*2)//10000) b=(b*2)% 10000 else : s2=s2+"0" if a==0 and b==0 : print(s1+"."+s2) else : print("NA") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var N : String := (OclFile["System.in"]).readLine() ; if N->indexOf(".") - 1 < 0 then ( N := N + ".0" ) else skip ; var strA : OclAny := null; var strB : OclAny := null; Sequence{strA,strB} := N.split(".") ; var a : int := ("" + ((strA)))->toInteger() ; if strA->first() = "-" then ( break ) else skip ; var b : double := ("" + ((strB)))->toInteger() * ((10)->pow((4 - (strB)->size()))) ; var s1 : String := "" ; var s2 : String := "" ; for i : Integer.subrange(0, 8-1) do ( if a > 0 then ( s1 := ("" + ((a mod 2))) + s1 ; a := a div 2 ) else ( s1 := "0" + s1 )) ; for i : Integer.subrange(0, 4-1) do ( if b > 0 then ( s2 := s2 + ("" + (((b * 2) div 10000))) ; b := (b * 2) mod 10000 ) else ( s2 := s2 + "0" )) ; if a = 0 & b = 0 then ( execute (s1 + "." + s2)->display() ) else ( execute ("NA")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def digSum(n): sum=0 ; rem=0 ; while(n): rem=n % 10 ; sum=sum+rem ; n=int(n/10); return sum ; def findX(n): for i in range(n+1): if(i+digSum(i)==n): return i ; return-1 ; n=43 ; print("x=",findX(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 43; ; execute ("x=")->display();; operation digSum(n : OclAny) pre: true post: true activity: var sum : int := 0; ; var rem : int := 0; ; while (n) do ( rem := n mod 10; ; sum := sum + rem; ; n := ("" + ((n / 10)))->toInteger();) ; return sum;; operation findX(n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n + 1-1) do ( if (i + digSum(i) = n) then ( return i; ) else skip) ; return -1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N=int(input()) P=[int(input())for _ in range(N)] editorial(N,P) def editorial(N,P): if N==1 : print(0) return a=[0]*(N+1) for i,p in enumerate(P): a[p]=i tmp=1 max_len=1 for i in range(1,N): if a[i]toInteger() ; var P : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; editorial(N, P); operation editorial(N : OclAny, P : OclAny) pre: true post: true activity: if N = 1 then ( execute (0)->display() ; return ) else skip ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; for _tuple : Integer.subrange(1, (P)->size())->collect( _indx | Sequence{_indx-1, (P)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p : OclAny := _tuple->at(_indx); a[p+1] := i) ; var tmp : int := 1 ; var max_len : int := 1 ; for i : Integer.subrange(1, N-1) do ( if (a[i+1]->compareTo(a[i + 1+1])) < 0 then ( tmp := tmp + 1 ; max_len := Set{max_len, tmp}->max() ) else ( tmp := 1 )) ; var ans : double := N - max_len ; execute (ans)->display(); operation WA(N : OclAny, P : OclAny) pre: true post: true activity: tmp := 0 ; ans := 0 ; for _tuple : Integer.subrange(1, (P)->size())->collect( _indx | Sequence{_indx-1, (P)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p : OclAny := _tuple->at(_indx); if i = 0 or P[i - 1+1] + 1 = p then ( tmp := tmp + 1 ) else ( ans := Set{ans, tmp}->max() ; tmp := 1 )) ; execute (N - ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d={} for x in map(int,open(0)): d[x]=d.get(x-1,0)+1 print(len(d)-max(d.values())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : OclAny := Set{} ; for x : (OclFile.newOclFile_Write(OclFile.newOclFile(0)))->collect( _x | (OclType["int"])->apply(_x) ) do ( d[x+1] := d.get(x - 1, 0) + 1) ; execute ((d)->size() - (d.values())->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**8) ini=lambda : int(sys.stdin.readline()) inm=lambda : map(int,sys.stdin.readline().split()) inl=lambda : list(inm()) ins=lambda : sys.stdin.readline().rstrip() N=ini() P=list(map(int,sys.stdin.readlines())) INF=1<<40 def solve(): if N==1 : return 0 inds=[None]*(N+1) for i,x in enumerate(P): inds[x]=i streak=[1]*(N+1) for k in range(2,N+1): if inds[k-1]l+r : ans=l+r return ans print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(8)) ; var ini : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var inm : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var inl : Function := lambda $$ : OclAny in ((inm->apply())) ; var ins : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var N : OclAny := ini->apply() ; var P : Sequence := (((OclFile["System.in"]).readlines())->collect( _x | (OclType["int"])->apply(_x) )) ; var INF : int := 1 * (2->pow(40)) ; skip ; execute (solve())->display(); operation solve() : OclAny pre: true post: true activity: if N = 1 then ( return 0 ) else skip ; var inds : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (N + 1)) ; for _tuple : Integer.subrange(1, (P)->size())->collect( _indx | Sequence{_indx-1, (P)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); inds[x+1] := i) ; var streak : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (N + 1)) ; for k : Integer.subrange(2, N + 1-1) do ( if (inds[k - 1+1]->compareTo(inds[k+1])) < 0 then ( streak[k+1] := streak[k - 1+1] + 1 ) else skip) ; var ans : int := INF ; for k : Integer.subrange(2, N + 1-1) do ( var r : int := if k = P->last() then 0 else 1 endif ; r := r + N - k ; var l : double := (k - 1) - streak[k - 1+1] ; if (ans->compareTo(l + r)) > 0 then ( ans := l + r ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys INF=float('inf') MOD=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return input() def main(): n=II() P=[II()for _ in range(n)] dp=[0]*(n+1) for p in P : dp[p]+=dp[p-1]+1 return n-max(dp) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var INF : double := ("" + (('inf')))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation SI() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation main() : OclAny pre: true post: true activity: var n : OclAny := II() ; var P : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (II())) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for p : P do ( dp[p+1] := dp[p+1] + dp[p - 1+1] + 1) ; return n - (dp)->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from operator import itemgetter read=sys.stdin.read N,*P=map(int,read().split()) p=sorted(enumerate(P),key=itemgetter(1)) length=[] cnt=1 for i in range(N-1): if p[i+1][0]collect( _x | (OclType["int"])->apply(_x) ) ; var p : Sequence := Integer.subrange(1, (P)->size())->collect( _indx | Sequence{_indx-1, (P)->at(_indx)} )->sortedBy($x | (itemgetter(1))->apply($x)) ; var length : Sequence := Sequence{} ; var cnt : int := 1 ; for i : Integer.subrange(0, N - 1-1) do ( if (p[i + 1+1]->first()->compareTo(p[i+1]->first())) < 0 then ( execute ((cnt) : length) ; cnt := 1 ) else ( cnt := cnt + 1 )) ; execute ((cnt) : length) ; execute (N - (length)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=[int(i)for i in input().split()] b=[] for i in range(len(a)): b.append([a[i],i+1]) while len(b)>1 : if b[0][0]-m>0 : b[0][0]-=m b.append([b[0][0],b[0][1]]) b.pop(0) else : b.pop(0) print(b[0][1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var b : Sequence := Sequence{} ; for i : Integer.subrange(0, (a)->size()-1) do ( execute ((Sequence{a[i+1]}->union(Sequence{ i + 1 })) : b)) ; while (b)->size() > 1 do ( if b->first()->first() - m > 0 then ( b->first()->first() := b->first()->first() - m ; execute ((Sequence{b->first()->first()}->union(Sequence{ b->first()[1+1] })) : b) ; b := b->excludingAt(0+1) ) else ( b := b->excludingAt(0+1) )) ; execute (b->first()[1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(7): a,b=map(int,input().split()) print(a-b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, 7-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (a - b)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n1,t1=map(int,input().split()) n2,t2=map(int,input().split()) n3,t3=map(int,input().split()) n4,t4=map(int,input().split()) n5,t5=map(int,input().split()) n6,t6=map(int,input().split()) n7,t7=map(int,input().split()) s1=abs(n1-t1) s2=abs(n2-t2) s3=abs(n3-t3) s4=abs(n4-t4) s5=abs(n5-t5) s6=abs(n6-t6) s7=abs(n7-t7) print(s1) print(s2) print(s3) print(s4) print(s5) print(s6) print(s7) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n1 : OclAny := null; var t1 : OclAny := null; Sequence{n1,t1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n2 : OclAny := null; var t2 : OclAny := null; Sequence{n2,t2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n3 : OclAny := null; var t3 : OclAny := null; Sequence{n3,t3} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n4 : OclAny := null; var t4 : OclAny := null; Sequence{n4,t4} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n5 : OclAny := null; var t5 : OclAny := null; Sequence{n5,t5} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n6 : OclAny := null; var t6 : OclAny := null; Sequence{n6,t6} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n7 : OclAny := null; var t7 : OclAny := null; Sequence{n7,t7} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s1 : double := (n1 - t1)->abs() ; var s2 : double := (n2 - t2)->abs() ; var s3 : double := (n3 - t3)->abs() ; var s4 : double := (n4 - t4)->abs() ; var s5 : double := (n5 - t5)->abs() ; var s6 : double := (n6 - t6)->abs() ; var s7 : double := (n7 - t7)->abs() ; execute (s1)->display() ; execute (s2)->display() ; execute (s3)->display() ; execute (s4)->display() ; execute (s5)->display() ; execute (s6)->display() ; execute (s7)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a1,b1=map(int,input().split()) a2,b2=map(int,input().split()) a3,b3=map(int,input().split()) a4,b4=map(int,input().split()) a5,b5=map(int,input().split()) a6,b6=map(int,input().split()) a7,b7=map(int,input().split()) def cal(a,b): x=a-b return x x1=cal(a1,b1) x2=cal(a2,b2) x3=cal(a3,b3) x4=cal(a4,b4) x5=cal(a5,b5) x6=cal(a6,b6) x7=cal(a7,b7) print(x1) print(x2) print(x3) print(x4) print(x5) print(x6) print(x7) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a1 : OclAny := null; var b1 : OclAny := null; Sequence{a1,b1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a2 : OclAny := null; var b2 : OclAny := null; Sequence{a2,b2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a3 : OclAny := null; var b3 : OclAny := null; Sequence{a3,b3} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a4 : OclAny := null; var b4 : OclAny := null; Sequence{a4,b4} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a5 : OclAny := null; var b5 : OclAny := null; Sequence{a5,b5} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a6 : OclAny := null; var b6 : OclAny := null; Sequence{a6,b6} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a7 : OclAny := null; var b7 : OclAny := null; Sequence{a7,b7} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; var x1 : OclAny := cal(a1, b1) ; var x2 : OclAny := cal(a2, b2) ; var x3 : OclAny := cal(a3, b3) ; var x4 : OclAny := cal(a4, b4) ; var x5 : OclAny := cal(a5, b5) ; var x6 : OclAny := cal(a6, b6) ; var x7 : OclAny := cal(a7, b7) ; execute (x1)->display() ; execute (x2)->display() ; execute (x3)->display() ; execute (x4)->display() ; execute (x5)->display() ; execute (x6)->display() ; execute (x7)->display(); operation cal(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var x : double := a - b ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) cost=[[float('inf')]*n for _ in range(n)] m=int(input()) for _ in range(m): a,b,c,d=map(int,input().split(',')) cost[a-1][b-1]=c cost[b-1][a-1]=d s,g,V,P=map(int,input().split(',')) for k in range(n): for i in range(n): for j in range(n): if cost[i][j]>cost[i][k]+cost[k][j]: cost[i][j]=cost[i][k]+cost[k][j] print(V-P-cost[s-1][g-1]-cost[g-1][s-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cost : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ ("" + (('inf')))->toReal() }, n))) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split(','))->collect( _x | (OclType["int"])->apply(_x) ) ; cost[a - 1+1][b - 1+1] := c ; cost[b - 1+1][a - 1+1] := d) ; var s : OclAny := null; var g : OclAny := null; var V : OclAny := null; var P : OclAny := null; Sequence{s,g,V,P} := (input().split(','))->collect( _x | (OclType["int"])->apply(_x) ) ; for k : Integer.subrange(0, n-1) do ( for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if (cost[i+1][j+1]->compareTo(cost[i+1][k+1] + cost[k+1][j+1])) > 0 then ( cost[i+1][j+1] := cost[i+1][k+1] + cost[k+1][j+1] ) else skip))) ; execute (V - P - cost[s - 1+1][g - 1+1] - cost[g - 1+1][s - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,h=map(int,input().split()) b,i=map(int,input().split()) c,j=map(int,input().split()) d,k=map(int,input().split()) e,l=map(int,input().split()) f,m=map(int,input().split()) g,n=map(int,input().split()) if acollect( _x | (OclType["int"])->apply(_x) ) ; var b : OclAny := null; var i : OclAny := null; Sequence{b,i} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : OclAny := null; var j : OclAny := null; Sequence{c,j} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : OclAny := null; var k : OclAny := null; Sequence{d,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var e : OclAny := null; var l : OclAny := null; Sequence{e,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var f : OclAny := null; var m : OclAny := null; Sequence{f,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var g : OclAny := null; var n : OclAny := null; Sequence{g,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(h)) < 0 or (b->compareTo(i)) < 0 or (c->compareTo(j)) < 0 or (d->compareTo(k)) < 0 or (e->compareTo(l)) < 0 or (f->compareTo(m)) < 0 or (g->compareTo(n)) < 0 then ( skip ) else ( execute (a - h)->display() ; execute (b - i)->display() ; execute (c - j)->display() ; execute (d - k)->display() ; execute (e - l)->display() ; execute (f - m)->display() ; execute (g - n)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(7): t,n=map(int,input().split()) I=[t,n] print(max(I)-min(I)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, 7-1) do ( var t : OclAny := null; var n : OclAny := null; Sequence{t,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var I : Sequence := Sequence{t}->union(Sequence{ n }) ; execute ((I)->max() - (I)->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import random def nthRoot(A,N): xPre=random.randint(1,101)% 10 eps=0.001 delX=2147483647 xK=0.0 while(delX>eps): xK=((N-1.0)*xPre+A/pow(xPre,N-1))/N delX=abs(xK-xPre) xPre=xK ; return xK N=4 A=81 nthRootValue=nthRoot(A,N) print("Nth root is ",nthRootValue) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; N := 4 ; A := 81 ; var nthRootValue : OclAny := nthRoot(A, N) ; execute ("Nth root is ")->display(); operation nthRoot(A : OclAny, N : OclAny) : OclAny pre: true post: true activity: var xPre : int := (1 + (OclRandom.defaultInstanceOclRandom()).nextInt(101 - 1)) mod 10 ; var eps : double := 0.001 ; var delX : int := 2147483647 ; var xK : double := 0.0 ; while ((delX->compareTo(eps)) > 0) do ( xK := ((N - 1.0) * xPre + A / (xPre)->pow(N - 1)) / N ; delX := (xK - xPre)->abs() ; xPre := xK;) ; return xK; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y,z,k=map(int,input().split()) A=list(map(int,input().split())) B=list(map(int,input().split())) C=list(map(int,input().split())) ls=[0]*(len(A)*len(B)) for i in range(len(A)): for j in range(len(B)): ls[(i*len(B))+j]=A[i]+B[j] ls.sort(reverse=True) ls=ls[: k] check_ls=[] for i in range(len(C)): for j in range(len(ls)): check_ls.append(C[i]+ls[j]) check_ls.sort(reverse=True) for i in range(k): print(check_ls[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; var k : OclAny := null; Sequence{x,y,z,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var B : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var C : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ls : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((A)->size() * (B)->size())) ; for i : Integer.subrange(0, (A)->size()-1) do ( for j : Integer.subrange(0, (B)->size()-1) do ( ls[(i * (B)->size()) + j+1] := A[i+1] + B[j+1])) ; ls := ls->sort() ; ls := ls.subrange(1,k) ; var check_ls : Sequence := Sequence{} ; for i : Integer.subrange(0, (C)->size()-1) do ( for j : Integer.subrange(0, (ls)->size()-1) do ( execute ((C[i+1] + ls[j+1]) : check_ls))) ; check_ls := check_ls->sort() ; for i : Integer.subrange(0, k-1) do ( execute (check_ls[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np def main(): X,Y,Z,K=list(map(int,input().split(' '))) A=np.array(list(map(int,input().split(' ')))) B=np.array(list(map(int,input().split(' ')))) C=np.array(list(map(int,input().split(' ')))) AB=np.array(np.meshgrid(A,B)).T.reshape(-1,2).sum(axis=1) AB[: :-1].sort() AB=AB[: min([K,X*Y])] ABC=np.array(np.meshgrid(AB,C)).T.reshape(-1,2).sum(axis=1) ABC[: :-1].sort() for ans in ABC[: K]: print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var X : OclAny := null; var Y : OclAny := null; var Z : OclAny := null; var K : OclAny := null; Sequence{X,Y,Z,K} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var A : Sequence := (((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ))) ; var B : Sequence := (((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ))) ; var C : Sequence := (((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ))) ; var AB : OclAny := np.array().T.reshape(-1, 2).sum((argument (test (logical_test (comparison (expr (atom (name axis)))))) = (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ; (expr (atom (name AB)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ])) (trailer . (name sort) (arguments ( )))) ; AB := AB.subrange(1,(Sequence{K}->union(Sequence{ X * Y }))->min()) ; var ABC : OclAny := np.array().T.reshape(-1, 2).sum((argument (test (logical_test (comparison (expr (atom (name axis)))))) = (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ; (expr (atom (name ABC)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ])) (trailer . (name sort) (arguments ( )))) ; for ans : ABC.subrange(1,K) do ( execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq X,Y,Z,K=map(int,input().split()) A_array=list(map(int,input().split())) B_array=list(map(int,input().split())) C_array=list(map(int,input().split())) A_array.sort() B_array.sort() C_array.sort() use_array=[] sum_array=[] candidate=[] heapq.heapify(candidate) max_sum=A_array[-1]+B_array[-1]+C_array[-1] heapq.heappush(candidate,(0,X-1,Y-1,Z-1)) use_array.append((X-1,Y-1,Z-1)) for i in range(K): s,x,y,z=heapq.heappop(candidate) sum_array.append(s) if x!=0 and(x-1,y,z)not in use_array : use_array.append((x-1,y,z)) diff=A_array[x]-A_array[x-1] heapq.heappush(candidate,(s+diff,x-1,y,z)) if y!=0 and(x,y-1,z)not in use_array : use_array.append((x,y-1,z)) diff=B_array[y]-B_array[y-1] heapq.heappush(candidate,(s+diff,x,y-1,z)) if z!=0 and(x,y,z-1)not in use_array : use_array.append((x,y,z-1)) diff=C_array[z]-C_array[z-1] heapq.heappush(candidate,(s+diff,x,y,z-1)) for ans in sum_array : print(max_sum-ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var X : OclAny := null; var Y : OclAny := null; var Z : OclAny := null; var K : OclAny := null; Sequence{X,Y,Z,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A_array : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var B_array : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var C_array : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; A_array := A_array->sort() ; B_array := B_array->sort() ; C_array := C_array->sort() ; var use_array : Sequence := Sequence{} ; var sum_array : Sequence := Sequence{} ; var candidate : Sequence := Sequence{} ; heapq.heapify(candidate) ; var max_sum : OclAny := A_array->last() + B_array->last() + C_array->last() ; heapq.heappush(candidate, Sequence{0, X - 1, Y - 1, Z - 1}) ; execute ((Sequence{X - 1, Y - 1, Z - 1}) : use_array) ; for i : Integer.subrange(0, K-1) do ( var s : OclAny := null; var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{s,x,y,z} := heapq.heappop(candidate) ; execute ((s) : sum_array) ; if x /= 0 & (use_array)->excludes(Sequence{x - 1, y, z}) then ( execute ((Sequence{x - 1, y, z}) : use_array) ; var diff : double := A_array[x+1] - A_array[x - 1+1] ; heapq.heappush(candidate, Sequence{s + diff, x - 1, y, z}) ) else skip ; if y /= 0 & (use_array)->excludes(Sequence{x, y - 1, z}) then ( execute ((Sequence{x, y - 1, z}) : use_array) ; diff := B_array[y+1] - B_array[y - 1+1] ; heapq.heappush(candidate, Sequence{s + diff, x, y - 1, z}) ) else skip ; if z /= 0 & (use_array)->excludes(Sequence{x, y, z - 1}) then ( execute ((Sequence{x, y, z - 1}) : use_array) ; diff := C_array[z+1] - C_array[z - 1+1] ; heapq.heappush(candidate, Sequence{s + diff, x, y, z - 1}) ) else skip) ; for ans : sum_array do ( execute (max_sum - ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) x=0 if k<=max(n**2//2,n**2-(n**2//2)): print('YES') for i in range(n): for j in range(n): if i % 2==j % 2 and xcollect( _x | (OclType["int"])->apply(_x) ) ; var x : int := 0 ; if (k->compareTo(Set{(n)->pow(2) div 2, (n)->pow(2) - ((n)->pow(2) div 2)}->max())) <= 0 then ( execute ('YES')->display() ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if i mod 2 = j mod 2 & (x->compareTo(k)) < 0 then ( execute ('L')->display() ; x := x + 1 ) else ( execute ('S')->display() )) ; execute (->display()) ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y,z,k=[int(_)for _ in input().split()] a=[int(_)for _ in input().split()] b=[int(_)for _ in input().split()] c=[int(_)for _ in input().split()] ab=[] for i in range(x): for j in range(y): ab.append(a[i]+b[j]) ab.sort(reverse=True) abc=[] for i in range(min(k,x*y)): for j in range(z): abc.append(ab[i]+c[j]) abc.sort(reverse=True) for i in range(k): print(abc[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; var k : OclAny := null; Sequence{x,y,z,k} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var a : Sequence := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var b : Sequence := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var c : Sequence := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var ab : Sequence := Sequence{} ; for i : Integer.subrange(0, x-1) do ( for j : Integer.subrange(0, y-1) do ( execute ((a[i+1] + b[j+1]) : ab))) ; ab := ab->sort() ; var abc : Sequence := Sequence{} ; for i : Integer.subrange(0, Set{k, x * y}->min()-1) do ( for j : Integer.subrange(0, z-1) do ( execute ((ab[i+1] + c[j+1]) : abc))) ; abc := abc->sort() ; for i : Integer.subrange(0, k-1) do ( execute (abc[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq def main(): na,nb,nc,K=map(int,input().split()) As=sorted(list(map(int,input().split())),reverse=True) Bs=sorted(list(map(int,input().split())),reverse=True) Cs=sorted(list(map(int,input().split())),reverse=True) scores=[(-(As[0]+Bs[0]+Cs[0]),0,0,0)] used=[(0,0,0)] def push(i,j,k): heapq.heappush(scores,(-(As[i]+Bs[j]+Cs[k]),i,j,k)) for _ in range(K): (score,i,j,k)=heapq.heappop(scores) print(-score) for di,dj,dk in[[1,0,0],[0,1,0],[0,0,1]]: if not(i+dicollect( _x | (OclType["int"])->apply(_x) ) ; var As : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var Bs : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var Cs : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var scores : Sequence := Sequence{ Sequence{-(As->first() + Bs->first() + Cs->first()), 0, 0, 0} } ; var used : Sequence := Sequence{ Sequence{0, 0, 0} } ; skip ; for _anon : Integer.subrange(0, K-1) do (suite); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def performQueries(A,q): n=len(A) pref_xor=[0 for i in range(n+1)] for i in range(1,n+1): pref_xor[i]=pref_xor[i-1]^ A[i-1] for i in q : L=i[0] R=i[1] if(L>R): L,R=R,L if(L!=R and pref_xor[R]==pref_xor[L-1]): print("Yes") else : print("No") Arr=[1,1,2,2,1] q=[[1,5],[1,4],[3,4]] performQueries(Arr,q); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var Arr : Sequence := Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 1 })))) ; q := Sequence{Sequence{1}->union(Sequence{ 5 })}->union(Sequence{Sequence{1}->union(Sequence{ 4 })}->union(Sequence{ Sequence{3}->union(Sequence{ 4 }) })) ; performQueries(Arr, q);; operation performQueries(A : OclAny, q : OclAny) pre: true post: true activity: var n : int := (A)->size() ; var pref_xor : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(1, n + 1-1) do ( pref_xor[i+1] := MathLib.bitwiseXor(pref_xor[i - 1+1], A[i - 1+1])) ; for i : q do ( var L : OclAny := i->first() ; var R : OclAny := i[1+1] ; if ((L->compareTo(R)) > 0) then ( Sequence{L,R} := Sequence{R,L} ) else skip ; if (L /= R & pref_xor[R+1] = pref_xor[L - 1+1]) then ( execute ("Yes")->display() ) else ( execute ("No")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,sys,io,math from array import array from math import* I=lambda :[*map(int,sys.stdin.readline().split())] IS=lambda : input() IN=lambda : int(input()) IF=lambda : float(input()) n=IN() l=I() f=1 l.sort() c=0 for i in l : if i>c : c+=1 print(c+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var I : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var IS : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var IN : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var IF : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toReal()) ; var n : OclAny := IN->apply() ; var l : OclAny := I->apply() ; var f : int := 1 ; l := l->sort() ; var c : int := 0 ; for i : l do ( if (i->compareTo(c)) > 0 then ( c := c + 1 ) else skip) ; execute (c + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=0x7fffffff import heapq def dijkstra(V,to,start,goal): dist=[INF]*V Q=[] dist[start]=0 heapq.heappush(Q,(0,start)) while len(Q): t,s=heapq.heappop(Q) if s==goal : break if dist[s]nt : dist[e]=nt heapq.heappush(Q,(nt,e)) return dist[goal] n=int(input())+1 to=[[]for i in range(n)] for i in range(int(input())): a,b,c,d=list(map(int,input().split(','))) to[a].append((b,c)) to[b].append((a,d)) s,g,V,P=list(map(int,input().split(','))) if s==g : print(V-P) else : print(V-P-dijkstra(n,to,s,g)-dijkstra(n,to,g,s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INF : int := 0x7fffffff ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() + 1 ; to := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := ((input().split(','))->collect( _x | (OclType["int"])->apply(_x) )) ; (expr (atom (name to)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name b)))))) , (test (logical_test (comparison (expr (atom (name c))))))) )))))))) )))) ; (expr (atom (name to)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name d))))))) )))))))) ))))) ; var s : OclAny := null; var g : OclAny := null; var P : OclAny := null; Sequence{s,g,V,P} := ((input().split(','))->collect( _x | (OclType["int"])->apply(_x) )) ; if s = g then ( execute (V - P)->display() ) else ( execute (V - P - dijkstra(n, to, s, g) - dijkstra(n, to, g, s))->display() ); operation dijkstra(V : OclAny, to : OclAny, start : OclAny, goal : OclAny) : OclAny pre: true post: true activity: var dist : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, V) ; var Q : Sequence := Sequence{} ; dist[start+1] := 0 ; heapq.heappush(Q, Sequence{0, start}) ; while (Q)->size() do ( var t : OclAny := null; var s : OclAny := null; Sequence{t,s} := heapq.heappop(Q) ; if s = goal then ( break ) else skip ; if (dist[s+1]->compareTo(t)) < 0 then ( continue ) else skip ; for i : to[s+1] do ( var e : OclAny := null; var cost : OclAny := null; Sequence{e,cost} := i ; var nt : OclAny := t + cost ; if (dist[e+1]->compareTo(nt)) > 0 then ( dist[e+1] := nt ; heapq.heappush(Q, Sequence{nt, e}) ) else skip)) ; return dist[goal+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) count=1 for i in sorted(a): if i>=count : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : int := 1 ; for i : a->sort() do ( if (i->compareTo(count)) >= 0 then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- IL=lambda : list(map(int,input().split())) IS=lambda : input().split() I=lambda : int(input()) S=lambda : input() n=I() a=IL() a=sorted(a) mex=1 for i in range(n): if a[i]>=mex : mex+=1 print(mex) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var IL : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var IS : Function := lambda $$ : OclAny in (input().split()) ; var I : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var S : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var n : OclAny := I->apply() ; var a : OclAny := IL->apply() ; a := a->sort() ; var mex : int := 1 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1]->compareTo(mex)) >= 0 then ( mex := mex + 1 ) else skip) ; execute (mex)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.stdin.readline() s=sorted(list(int(x)for x in sys.stdin.readline().split())) cur=1 for x in s : if x>=cur : cur+=1 print(cur) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; (expr (atom (name sys)) (trailer . (name stdin)) (trailer . (name readline) (arguments ( )))) ; var s : Sequence := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin)) (trailer . (name readline) (arguments ( ))) (trailer . (name split) (arguments ( )))))))))->sort() ; var cur : int := 1 ; for x : s do ( if (x->compareTo(cur)) >= 0 then ( cur := cur + 1 ) else skip) ; execute (cur)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) a.sort() c=1 for i in range(n): if a[i]>=c : a[i]=c c+=1 print(a[n-1]+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var c : int := 1 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1]->compareTo(c)) >= 0 then ( a[i+1] := c ; c := c + 1 ) else skip) ; execute (a[n - 1+1] + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- RO=sorted(map(int,input().split()[1 :]))[-1] PO=sorted(map(int,input().split()[1 :]))[-1] PI=sorted(map(int,input().split()[1 :]))[0] A,B=map(int,input().split()) print(pow(pow(RO,2)/(((A*PI)/(B*PO))+1),0.5)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var RO : OclAny := sorted((input().split()->tail())->collect( _x | (OclType["int"])->apply(_x) ))->last() ; var PO : OclAny := sorted((input().split()->tail())->collect( _x | (OclType["int"])->apply(_x) ))->last() ; var PI : OclAny := sorted((input().split()->tail())->collect( _x | (OclType["int"])->apply(_x) ))->first() ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (((RO)->pow(2) / (((A * PI) / (B * PO)) + 1))->pow(0.5))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil n,k=map(int,input().split()) if k>ceil(n*n/2): print('NO') else : print('YES') l=[list('S'*n)for x in range(n)]; c=0 while k>0 : for x in range(c % 2,n,2): if k<1 : break l[c][x]='L' ; k-=1 c+=1 for x in l : print(''.join(x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (k->compareTo(ceil(n * n / 2))) > 0 then ( execute ('NO')->display() ) else ( execute ('YES')->display() ; var l : Sequence := Integer.subrange(0, n-1)->select(x | true)->collect(x | ((StringLib.nCopies('S', n))->characters())); var c : int := 0 ; while k > 0 do ( for x : Integer.subrange(c mod 2, n-1)->select( $x | ($x - c mod 2) mod 2 = 0 ) do ( if k < 1 then ( break ) else skip ; l[c+1][x+1] := 'L'; k := k - 1) ; c := c + 1) ; for x : l do ( execute (StringLib.sumStringsWithSeparator((x), ''))->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- text=input() n=text.split(" ") n=n[1 :] n=[int(x)for x in n] maxradius=int(max(n)) text1=input() m=text1.split(" ") m=m[1 :] m=[int(x)for x in m] maxP1=int(max(m)) text2=input() k=text2.split(" ") k=k[1 :] k=[int(x)for x in k] minP2=int(min(k)) text3=input() g=text3.split(" ") A=int(g[0]) B=int(g[1]) result=float(pow((pow(maxradius,2)*maxP1*B)/(minP2*A+maxP1*B),0.5)) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var text : String := (OclFile["System.in"]).readLine() ; var n : OclAny := text.split(" ") ; n := n->tail() ; n := n->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var maxradius : int := ("" + (((n)->max())))->toInteger() ; var text1 : String := (OclFile["System.in"]).readLine() ; var m : OclAny := text1.split(" ") ; m := m->tail() ; m := m->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var maxP1 : int := ("" + (((m)->max())))->toInteger() ; var text2 : String := (OclFile["System.in"]).readLine() ; var k : OclAny := text2.split(" ") ; k := k->tail() ; k := k->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var minP2 : int := ("" + (((k)->min())))->toInteger() ; var text3 : String := (OclFile["System.in"]).readLine() ; var g : OclAny := text3.split(" ") ; var A : int := ("" + ((g->first())))->toInteger() ; var B : int := ("" + ((g[1+1])))->toInteger() ; var result : double := ("" + (((((maxradius)->pow(2) * maxP1 * B) / (minP2 * A + maxP1 * B))->pow(0.5))))->toReal() ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt max_ans=0 r1s=list(map(int,input().split()))[1 :] p1s=list(map(int,input().split()))[1 :] p2s=list(map(int,input().split()))[1 :] A,B=map(int,input().split()) p2=min(p2s) r1=max(r1s) for p1 in p1s : r2=sqrt((r1**2*p1*B)/((A*p2)+(B*p1))) if r2>max_ans : max_ans=r2 print(max_ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var max_ans : int := 0 ; var r1s : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->tail() ; var p1s : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->tail() ; var p2s : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->tail() ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p2 : OclAny := (p2s)->min() ; var r1 : OclAny := (r1s)->max() ; for p1 : p1s do ( var r2 : OclAny := sqrt(((r1)->pow(2) * p1 * B) / ((A * p2) + (B * p1))) ; if (r2->compareTo(max_ans)) > 0 then ( max_ans := r2 ) else skip) ; execute (max_ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt r1s=list(map(int,input().split()))[1 :] p1s=list(map(int,input().split()))[1 :] p2s=list(map(int,input().split()))[1 :] A,B=map(int,input().split()) p2=min(p2s) r1=max(r1s) p1=max(p1s) print(sqrt((r1**2*p1*B)/((A*p2)+(B*p1)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var r1s : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->tail() ; var p1s : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->tail() ; var p2s : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->tail() ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p2 : OclAny := (p2s)->min() ; var r1 : OclAny := (r1s)->max() ; var p1 : OclAny := (p1s)->max() ; execute (sqrt(((r1)->pow(2) * p1 * B) / ((A * p2) + (B * p1))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input().split(); numr1,r1=int(x[0]),list(map(int,x[1 :])) x=input().split(); nump1,p1=int(x[0]),list(map(int,x[1 :])) x=input().split(); nump2,p2=int(x[0]),list(map(int,x[1 :])) A,B=list(map(int,input().split())) print(max(r1)*(B*max(p1)/(B*max(p1)+min(p2)*A))**.5) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := input().split(); var numr1 : OclAny := null; var r1 : OclAny := null; Sequence{numr1,r1} := Sequence{("" + ((x->first())))->toInteger(),((x->tail())->collect( _x | (OclType["int"])->apply(_x) ))} ; x := input().split(); var nump1 : OclAny := null; var p1 : OclAny := null; Sequence{nump1,p1} := Sequence{("" + ((x->first())))->toInteger(),((x->tail())->collect( _x | (OclType["int"])->apply(_x) ))} ; x := input().split(); var nump2 : OclAny := null; var p2 : OclAny := null; Sequence{nump2,p2} := Sequence{("" + ((x->first())))->toInteger(),((x->tail())->collect( _x | (OclType["int"])->apply(_x) ))} ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((r1)->max() * ((B * (p1)->max() / (B * (p1)->max() + (p2)->min() * A)))->pow(.5))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : num=3 lterm=1 rterm=num*num+1 for i in range(num,-1,-1): for space in range(num,i-1,-1): print("",end="") for j in range(1,i+1): print(str(lterm)+"*",end="") lterm+=1 for j in range(1,i+1): print(rterm,end="") if jreverse() do ( for space : Integer.subrange(i - 1 + 1, num)->reverse() do ( execute ("")->display()) ; for j : Integer.subrange(1, i + 1-1) do ( execute (("" + ((lterm))) + "*")->display() ; lterm := lterm + 1) ; for j : Integer.subrange(1, i + 1-1) do ( execute (rterm)->display() ; if (j->compareTo(i)) < 0 then ( execute ("*")->display() ) else skip ; rterm := rterm + 1) ; rterm := rterm - (i - 1) * 2 - 1 ; execute (->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def warshallFloyd(V,dp): for k in range(V): for i in range(V): for j in range(V): dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]) def main(args): n=int(input()) m=int(input()) dp=[[float('inf')]*(n+1)for _ in range(n+1)] for i in range(n+1): dp[i][i]=0 for _ in range(m): a,b,c,d=[int(x)for x in input().split(',')] dp[a][b]=c dp[b][a]=d s,g,V,P=[int(x)for x in input().split(',')] warshallFloyd(n+1,dp) print(V-dp[s][g]-dp[g][s]-P) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation warshallFloyd(V : OclAny, dp : OclAny) pre: true post: true activity: for k : Integer.subrange(0, V-1) do ( for i : Integer.subrange(0, V-1) do ( for j : Integer.subrange(0, V-1) do ( dp[i+1][j+1] := Set{dp[i+1][j+1], dp[i+1][k+1] + dp[k+1][j+1]}->min()))); operation main(args : OclAny) pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; dp := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ ("" + (('inf')))->toReal() }, (n + 1)))) ; for i : Integer.subrange(0, n + 1-1) do ( dp[i+1][i+1] := 0) ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := input().split(',')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; dp[a+1][b+1] := c ; dp[b+1][a+1] := d) ; var s : OclAny := null; var g : OclAny := null; var P : OclAny := null; Sequence{s,g,V,P} := input().split(',')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; warshallFloyd(n + 1, dp) ; execute (V - dp[s+1][g+1] - dp[g+1][s+1] - P)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findPerm(n,differences): ans=[] ans.append(0) x=0 for i in range(n-1): diff=differences[i] x=x+diff ans.append(x) anss=ans ans=sorted(ans) flag=-1 for i in range(1,n): res=ans[i]-ans[i-1] if(res!=1): flag=0 if(flag==0): print("-1") return else : mpp=dict() j=1 value_at_index=[] for x in ans : mpp[x]=j j+=1 for x in anss : value_at_index.append(mpp[x]) for x in value_at_index : print(x,end=" ") print() differences=[] differences.append(2) differences.append(-3) differences.append(2) n=len(differences)+1 findPerm(n,differences) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; differences := Sequence{} ; execute ((2) : differences) ; execute ((-3) : differences) ; execute ((2) : differences) ; n := (differences)->size() + 1 ; findPerm(n, differences); operation findPerm(n : OclAny, differences : OclAny) pre: true post: true activity: var ans : Sequence := Sequence{} ; execute ((0) : ans) ; var x : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( var diff : OclAny := differences[i+1] ; x := x + diff ; execute ((x) : ans)) ; var anss : Sequence := ans ; ans := ans->sort() ; var flag : int := -1 ; for i : Integer.subrange(1, n-1) do ( var res : double := ans[i+1] - ans[i - 1+1] ; if (res /= 1) then ( flag := 0 ) else skip) ; if (flag = 0) then ( execute ("-1")->display() ; return ) else ( var mpp : Map := (arguments ( )) ; var j : int := 1 ; var value_at_index : Sequence := Sequence{} ; for x : ans do ( mpp[x+1] := j ; j := j + 1) ; for x : anss do ( execute ((mpp[x+1]) : value_at_index)) ; for x : value_at_index do ( execute (x)->display()) ; execute (->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ri(): return int(input()) def rli(): return list(map(int,input().split())) def ris(): return list(input()) def pli(a): return "".join(list(map(str,a))) N,M=rli() keiro=[[False for i in range(2)]for j in range(N+1)] for i in range(M): a,b=rli() if(b==1 or b==N): keiro[a][1 if b==1 else 0]=True elif(a==1 or a==N): keiro[b][1 if a==1 else 0]=True flag=False for i in range(2,N): if(keiro[i][1]and keiro[i][0]): flag=True if(flag): print("POSSIBLE") else : print("IMPOSSIBLE") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := rli() ; var keiro : Sequence := Integer.subrange(0, N + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, 2-1)->select(i | true)->collect(i | (false)))) ; for i : Integer.subrange(0, M-1) do ( var b : OclAny := null; Sequence{a,b} := rli() ; if (b = 1 or b = N) then ( keiro[a+1][if b = 1 then 1 else 0 endif+1] := true ) else (if (a = 1 or a = N) then ( keiro[b+1][if a = 1 then 1 else 0 endif+1] := true ) else skip)) ; var flag : boolean := false ; for i : Integer.subrange(2, N-1) do ( if (keiro[i+1][1+1] & keiro[i+1]->first()) then ( flag := true ) else skip) ; if (flag) then ( execute ("POSSIBLE")->display() ) else ( execute ("IMPOSSIBLE")->display() ); operation ri() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation rli() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ris() : OclAny pre: true post: true activity: return ((OclFile["System.in"]).readLine())->characters(); operation pli(a : OclAny) : OclAny pre: true post: true activity: return StringLib.sumStringsWithSeparator((((a)->collect( _x | (OclType["String"])->apply(_x) ))), ""); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class UnionFind : def __init__(self,n): self.par=[i for i in range(n+1)] self.rank=[0]*(n+1) def find(self,x): if self.par[x]==x : return x else : self.par[x]=self.find(self.par[x]) return self.par[x] def union(self,x,y): x=self.find(x) y=self.find(y) if self.rank[x]exists( _x | result = _x ); attribute par : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (i)); attribute rank : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); operation initialise(n : OclAny) : UnionFind pre: true post: true activity: self.par := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (i)) ; self.rank := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); return self; operation find(x : OclAny) : OclAny pre: true post: true activity: if self.par[x+1] = x then ( return x ) else ( self.par[x+1] := self->indexOf(self.par[x+1]) - 1 ; return self.par[x+1] ); operation union(x : OclAny,y : OclAny) pre: true post: true activity: x := self->indexOf(x) - 1 ; y := self->indexOf(y) - 1 ; if (self.rank[x+1]->compareTo(self.rank[y+1])) < 0 then ( self.par[x+1] := y ) else ( self.par[y+1] := x ; if self.rank[x+1] = self.rank[y+1] then ( self.rank[x+1] := self.rank[x+1] + 1 ) else skip ); operation same_check(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: return self->indexOf(x) - 1 = self->indexOf(y) - 1; } class FromPython { operation initialise() pre: true post: true activity: skip ; var m : OclAny := null; Sequence{n,m} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var uf : UnionFind := (UnionFind.newUnionFind()).initialise(n - 1) ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; if a = 1 or b = n then ( uf.union(a - 1, b - 1) ) else skip) ; if uf.same_check(0, n - 1) then ( execute ('POSSIBLE')->display() ) else ( execute ('IMPOSSIBLE')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def LI(): return list(map(int,input().split())) N,M=LI() A,B=[None]*M,[None]*M for i in range(M): A[i],B[i]=LI() A[i]-=1 B[i]-=1 def solve(link): for i in link[0]: if N-1 in link[i]: return "POSSIBLE" return "IMPOSSIBLE" def main(): link=[set()for _ in range(N)] for a,b in zip(A,B): link[a].add(b) link[b].add(a) ans=solve(link) print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := LI() ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := Sequence{MatrixLib.elementwiseMult(Sequence{ null }, M),MatrixLib.elementwiseMult(Sequence{ null }, M)} ; for i : Integer.subrange(0, M-1) do ( var A[i+1] : OclAny := null; var B[i+1] : OclAny := null; Sequence{A[i+1],B[i+1]} := LI() ; A[i+1] := A[i+1] - 1 ; B[i+1] := B[i+1] - 1) ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation solve(link : OclAny) : OclAny pre: true post: true activity: for i : link->first() do ( if (link[i+1])->includes(N - 1) then ( return "POSSIBLE" ) else skip) ; return "IMPOSSIBLE"; operation main() pre: true post: true activity: link := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; for _tuple : Integer.subrange(1, A->size())->collect( _indx | Sequence{A->at(_indx), B->at(_indx)} ) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); (expr (atom (name link)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name link)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var ans : OclAny := solve(link) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def SeaLand(x,y): if x % 2==0 and y>(x**2)//2 : print('NO') elif x % 2==1 and(x-1)//2*x+(x+1)//2collect( _x | (OclType["int"])->apply(_x) )) ; SeaLand(n, k); operation SeaLand(x : OclAny, y : OclAny) pre: true post: true activity: if x mod 2 = 0 & (y->compareTo(((x)->pow(2)) div 2)) > 0 then ( execute ('NO')->display() ) else (if x mod 2 = 1 & ((x - 1) div 2 * x + (x + 1) div 2->compareTo(y)) < 0 then ( execute ('NO')->display() ) else ( execute ('YES')->display() ; var count : int := 0 ; if x mod 2 = 0 then ( for i : Integer.subrange(0, x-1) do ( for j : Integer.subrange(0, x-1) do ( if (count->compareTo(y)) < 0 & i mod 2 = 0 then ( if j mod 2 = 1 then ( execute ('L')->display() ; count := count + 1 ) else ( execute ('S')->display() ) ) else (if (count->compareTo(y)) < 0 then ( if j mod 2 = 0 then ( execute ('L')->display() ; count := count + 1 ) else ( execute ('S')->display() ) ) else ( execute ('S')->display() ) ) ) ; execute (->display()) ) else ( for i : Integer.subrange(0, x-1) do ( for j : Integer.subrange(0, x-1) do ( if (count->compareTo(y)) < 0 & i mod 2 = 0 then ( if j mod 2 = 0 then ( execute ('L')->display() ; count := count + 1 ) else ( execute ('S')->display() ) ) else (if (count->compareTo(y)) < 0 then ( if j mod 2 = 1 then ( execute ('L')->display() ; count := count + 1 ) else ( execute ('S')->display() ) ) else ( execute ('S')->display() ) ) ) ; execute (->display()) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys N,M=map(int,input().split()) ab=[tuple(map(int,line.split()))for line in sys.stdin.readlines()] first=dict() for a,b in ab : if a==1 : first[b]=1 for a,b in ab : if b==N : if a in first : print("POSSIBLE") exit() print('IMPOSSIBLE') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ab : Sequence := (OclFile["System.in"]).readlines()->select(line | true)->collect(line | (((line.split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var first : Map := (arguments ( )) ; for _tuple : ab do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if a = 1 then ( first[b+1] := 1 ) else skip) ; for _tuple : ab do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if b = N then ( if (first)->includes(a) then ( execute ("POSSIBLE")->display() ; exit() ) else skip ) else skip) ; execute ('IMPOSSIBLE')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=[int(x)for x in input().split()] L=[None]*M for i in range(M): a,b=[int(x)for x in input().split()] L[i]=(a,b) set1=set() set2=set() for l in L : a,b=l[0],l[1] if a==1 : set1.add(b) if b==N : set2.add(a) if set1.isdisjoint(set2): print("IMPOSSIBLE") else : print("POSSIBLE") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var L : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, M) ; for i : Integer.subrange(0, M-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; L[i+1] := Sequence{a, b}) ; var set1 : Set := Set{}->union(()) ; var set2 : Set := Set{}->union(()) ; for l : L do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{l->first(),l[1+1]} ; if a = 1 then ( execute ((b) : set1) ) else skip ; if b = N then ( execute ((a) : set2) ) else skip) ; if set1->intersection(set2)->isEmpty() then ( execute ("IMPOSSIBLE")->display() ) else ( execute ("POSSIBLE")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def countPrimeFactors(n): count=0 ; while(n % 2==0): n=n/2 ; count+=1 ; i=3 ; while(i<=math.sqrt(n)): while(n % i==0): n=n/i ; count+=1 ; i=i+2 ; if(n>2): count+=1 ; return(count); def printKAlmostPrimes(k,n): i=1 ; num=2 while(i<=n): if(countPrimeFactors(num)==k): print(num,end=""); print("",end=""); i+=1 ; num+=1 ; return ; n=10 ; k=2 ; print("First n k-almost prime numbers:"); printKAlmostPrimes(k,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 10; ; k := 2; ; execute ("First n k-almost prime numbers:")->display(); ; printKAlmostPrimes(k, n);; operation countPrimeFactors(n : OclAny) pre: true post: true activity: var count : int := 0; ; while (n mod 2 = 0) do ( n := n / 2; ; count := count + 1;) ; var i : int := 3; ; while ((i->compareTo((n)->sqrt())) <= 0) do ( while (n mod i = 0) do ( n := n / i; ; count := count + 1;) ; i := i + 2;) ; if (n > 2) then ( count := count + 1; ) else skip ; return (count);; operation printKAlmostPrimes(k : OclAny, n : OclAny) : OclAny pre: true post: true activity: i := 1; ; var num : int := 2 ; while ((i->compareTo(n)) <= 0) do ( if (countPrimeFactors(num) = k) then ( execute (num)->display(); ; execute ("")->display(); ; i := i + 1; ) else skip ; num := num + 1;) ; return;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(N,K): combo=[0]*(N+1) combo[0]=1 for i in range(1,K+1): for j in range(0,N+1): if j>=i : combo[j]+=combo[j-i] return combo[N] if __name__=="__main__" : N,K=29,5 print(solve(N,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{N,K} := Sequence{29,5} ; execute (solve(N, K))->display() ) else skip; operation solve(N : OclAny, K : OclAny) : OclAny pre: true post: true activity: var combo : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; combo->first() := 1 ; for i : Integer.subrange(1, K + 1-1) do ( for j : Integer.subrange(0, N + 1-1) do ( if (j->compareTo(i)) >= 0 then ( combo[j+1] := combo[j+1] + combo[j - i+1] ) else skip)) ; return combo[N+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import sys sys.setrecursionlimit(10**8) def Z(): return int(input()) def ZZ(): return[int(_)for _ in input().split()] class edge : def __init__(self,to,id): self.to,self.id=to,id def main(): N=Z() col=[0]*(N-1) G=collections.defaultdict(list) for i in range(N-1): a,b=ZZ() G[a].append(edge(b,i)) G[b].append(edge(a,i)) numCol=0 for i in range(1,N+1): numCol=max(numCol,len(G[i])) def dfs(v): colSet=set() for ed in G[v]: if col[ed.id]!=0 : colSet.add(col[ed.id]) c=1 for ed in G[v]: if col[ed.id]!=0 : continue while c in colSet : c+=1 col[ed.id]=c c+=1 dfs(ed.to) dfs(1) print(numCol) for i in range(N-1): print(col[i]) return if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class edge { static operation newedge() : edge pre: true post: edge->exists( _x | result = _x ); attribute (testlist_star_expr (test (logical_test (comparison (expr (atom (name self)) (trailer . (name to)))))) , (test (logical_test (comparison (expr (atom (name self)) (trailer . (name id))))))) : OclAny := to,id; operation initialise(to : OclAny,id : OclAny) : edge pre: true post: true activity: var self.to : OclAny := null; var self.id : OclAny := null; Sequence{self.to,self.id} := Sequence{to,id}; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation Z() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation ZZ() : OclAny pre: true post: true activity: return input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())); operation main() pre: true post: true activity: var N : OclAny := Z() ; var col : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N - 1)) ; var G : OclAny := .defaultdict(OclType["Sequence"]) ; for i : Integer.subrange(0, N - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ZZ() ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name edge)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b))))))) , (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))) )))) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name edge)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))) ))))) ; var numCol : int := 0 ; for i : Integer.subrange(1, N + 1-1) do ( numCol := Set{numCol, (G[i+1])->size()}->max()) ; skip ; dfs(1) ; execute (numCol)->display() ; for i : Integer.subrange(0, N - 1-1) do ( execute (col[i+1])->display()) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque import sys input=sys.stdin.readline def bfs(v,N,G,E): visited=[0]*N queue=deque() K=-1 node2color=[-1 for _ in range(N)] queue.append(v) visited[v]=1 while queue : q=queue.popleft() color=0 for nex in G[q]: if visited[nex]: continue visited[nex]=1 color+=1 if color==node2color[q]: color+=1 node2color[nex]=color E[(min(q,nex),max(q,nex))]=color queue.append(nex) K=max(K,color) return K def main(): N=int(input()) G=[deque()for _ in range(N)] E=dict() for i in range(N-1): a,b=map(lambda x : int(x)-1,input().split()) G[a].append(b) G[b].append(a) E[(a,b)]=0 K=bfs(0,N,G,E) print(K) for value in E.values(): print(value) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; main(); operation bfs(v : OclAny, N : OclAny, G : OclAny, E : OclAny) : OclAny pre: true post: true activity: var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var queue : Sequence := () ; var K : int := -1 ; var node2color : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (-1)) ; execute ((v) : queue) ; visited[v+1] := 1 ; while queue do ( var q : OclAny := queue->first() ; queue := queue->tail() ; var color : int := 0 ; for nex : G[q+1] do ( if visited[nex+1] then ( continue ) else skip ; visited[nex+1] := 1 ; color := color + 1 ; if color = node2color[q+1] then ( color := color + 1 ) else skip ; node2color[nex+1] := color ; E[Sequence{Set{q, nex}->min(), Set{q, nex}->max()}+1] := color ; execute ((nex) : queue)) ; K := Set{K, color}->max()) ; return K; operation main() pre: true post: true activity: N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; G := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (())) ; E := (arguments ( )) ; for i : Integer.subrange(0, N - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))) ; E[Sequence{a, b}+1] := 0) ; K := bfs(0, N, G, E) ; execute (K)->display() ; for value : E.values() do ( execute (value)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=10000000 n=int(input()) m=int(input()) table=[[INF for i in range(n)]for j in range(n)] for l in range(m): a,b,c,d=[int(i)for i in input().split(",")] table[a-1][b-1]=c table[b-1][a-1]=d s,g,V,P=[int(i)for i in input().split(",")] visited=[False for i in range(n)] cost=[INF for i in range(n)] cost[s-1]=0 while True : v=-1 for i in range(n): if visited[i]==False and(v==-1 or cost[i]toInteger() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var table : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (Integer.subrange(0, n-1)->select(i | true)->collect(i | (INF)))) ; for l : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := input().split(",")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; table[a - 1+1][b - 1+1] := c ; table[b - 1+1][a - 1+1] := d) ; var s : OclAny := null; var g : OclAny := null; var V : OclAny := null; var P : OclAny := null; Sequence{s,g,V,P} := input().split(",")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var visited : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (false)) ; var cost : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (INF)) ; cost[s - 1+1] := 0 ; while true do ( var v : int := -1 ; for i : Integer.subrange(0, n-1) do ( if visited[i+1] = false & (v = -1 or (cost[i+1]->compareTo(cost[v+1])) < 0) then ( v := i ) else skip) ; if v = -1 then ( break ) else skip ; visited[v+1] := true ; for i : Integer.subrange(0, n-1) do ( cost[i+1] := Set{cost[i+1], cost[v+1] + table[v+1][i+1]}->min())) ; var ans : OclAny := cost[g - 1+1] ; visited := Integer.subrange(0, n-1)->select(i | true)->collect(i | (false)) ; cost := Integer.subrange(0, n-1)->select(i | true)->collect(i | (INF)) ; cost[g - 1+1] := 0 ; while true do ( v := -1 ; for i : Integer.subrange(0, n-1) do ( if visited[i+1] = false & (v = -1 or (cost[i+1]->compareTo(cost[v+1])) < 0) then ( v := i ) else skip) ; if v = -1 then ( break ) else skip ; visited[v+1] := true ; for i : Integer.subrange(0, n-1) do ( cost[i+1] := Set{cost[i+1], cost[v+1] + table[v+1][i+1]}->min())) ; ans := ans + cost[s - 1+1] ; execute (V - P - ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import collections import numpy as np class Edge : def __init__(self,dst,color): self.dst=dst self.color=color def __repr__(self): return str(self.dst)+' '+str(self.color) def main(): N=int(input()) adj_list=[[]for _ in range(N+1)] edge_order=[] for _ in range(N-1): a,b=list(map(int,input().split())) edge_order.append((a,len(adj_list[a]))) adj_list[a].append(Edge(b,None)) adj_list[b].append(Edge(a,None)) max_deg=0 for i in range(1,N+1): max_deg=max(max_deg,len(adj_list[i])) K=max_deg print(K) queue=collections.deque() queue.append((1,None)) while queue : cur_node,used_color=queue.popleft() if used_color is None : color=0 else : color=(used_color+1)% K for edge in adj_list[cur_node]: if edge.color is not None : pass else : edge.color=color for inv_edge in adj_list[edge.dst]: if inv_edge.dst==cur_node : inv_edge.color=color adj_list[edge.dst] queue.append((edge.dst,color)) color=(color+1)% K for i,j in edge_order : print(adj_list[i][j].color+1) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class Edge { static operation newEdge() : Edge pre: true post: Edge->exists( _x | result = _x ); attribute dst : OclAny := dst; attribute color : OclAny := color; operation initialise(dst : OclAny,color : OclAny) : Edge pre: true post: true activity: self.dst := dst ; self.color := color; return self; operation __repr__() : OclAny pre: true post: true activity: return ("" + ((self.dst))) + ' ' + ("" + ((self.color))); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var adj_list : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var edge_order : Sequence := Sequence{} ; for _anon : Integer.subrange(0, N - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((Sequence{a, (adj_list[a+1])->size()}) : edge_order) ; (expr (atom (name adj_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name Edge)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b))))))) , (argument (test (logical_test (comparison (expr (atom None))))))) ))))))))) )))) ; (expr (atom (name adj_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name Edge)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom None))))))) ))))))))) ))))) ; var max_deg : int := 0 ; for i : Integer.subrange(1, N + 1-1) do ( max_deg := Set{max_deg, (adj_list[i+1])->size()}->max()) ; var K : int := max_deg ; execute (K)->display() ; var queue : Sequence := () ; execute ((Sequence{1, null}) : queue) ; while queue do ( var cur_node : OclAny := null; var used_color : OclAny := null; Sequence{cur_node,used_color} := queue->first() ; queue := queue->tail() ; if used_color <>= null then ( color := 0 ) else ( color := (used_color + 1) mod K ) ; for edge : adj_list[cur_node+1] do ( if not(edge.color <>= null) then ( skip ) else ( edge.color := color ; for inv_edge : adj_list[edge.dst+1] do ( if inv_edge.dst = cur_node then ( inv_edge.color := color ) else skip) ; adj_list[edge.dst+1] ; execute ((Sequence{edge.dst, color}) : queue) ; color := (color + 1) mod K ))) ; for _tuple : edge_order do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); execute (adj_list[i+1][j+1].color + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) ans=[-1]*(N-1) rootLine=[0]*N numLine=[0]*N l=[] for i in range(N-1): a,b=map(int,input().split()) a-=1 b-=1 l.append([a,b,i]) l.sort() for a,b,i in l : numLine[a]+=1 if numLine[a]==rootLine[a]: numLine[a]+=1 ans[i]=numLine[a] rootLine[b]=numLine[a] print(max(ans)) for i in ans : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (N - 1)) ; var rootLine : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var numLine : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, N - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := a - 1 ; b := b - 1 ; execute ((Sequence{a}->union(Sequence{b}->union(Sequence{ i }))) : l)) ; l := l->sort() ; for _tuple : l do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); numLine[a+1] := numLine[a+1] + 1 ; if numLine[a+1] = rootLine[a+1] then ( numLine[a+1] := numLine[a+1] + 1 ) else skip ; ans[i+1] := numLine[a+1] ; rootLine[b+1] := numLine[a+1]) ; execute ((ans)->max())->display() ; for i : ans do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**8) def dfs(x,last=-1,ban_color=-1): color=1 for to in vertex[x]: if to==last : continue if color==ban_color : color+=1 color_dic[(x,to)]=color dfs(to,x,color) color+=1 n=int(input()) vertex={i :[]for i in range(n)} a=[0]*(n-1) b=[0]*(n-1) color_dic={} for i in range(n-1): a[i],b[i]=map(int,input().split()) a[i]-=1 b[i]-=1 vertex[a[i]].append(b[i]) vertex[b[i]].append(a[i]) max_v=0 for _,v in vertex.items(): if len(v)>max_v : max_v=len(v) print(max_v) dfs(0) for i in range(n-1): if(a[i],b[i])in color_dic : print(color_dic[(a[i],b[i])]) else : print(color_dic[(b[i],a[i])]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(8)) ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var vertex : Map := Integer.subrange(0, n-1)->select(i | true)->collect(i | Map{i |-> Sequence{}})->unionAll() ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n - 1)) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n - 1)) ; var color_dic : OclAny := Set{} ; for i : Integer.subrange(0, n - 1-1) do ( var a[i+1] : OclAny := null; var b[i+1] : OclAny := null; Sequence{a[i+1],b[i+1]} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a[i+1] := a[i+1] - 1 ; b[i+1] := b[i+1] - 1 ; (expr (atom (name vertex)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))) ; (expr (atom (name vertex)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))) ; var max_v : int := 0 ; for _tuple : vertex->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var _anon : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if ((v)->size()->compareTo(max_v)) > 0 then ( max_v := (v)->size() ) else skip) ; execute (max_v)->display() ; dfs(0) ; for i : Integer.subrange(0, n - 1-1) do ( if (color_dic)->includes(Sequence{a[i+1], b[i+1]}) then ( execute (color_dic[Sequence{a[i+1], b[i+1]}+1])->display() ) else ( execute (color_dic[Sequence{b[i+1], a[i+1]}+1])->display() )); operation dfs(x : OclAny, last : int, ban_color : int) pre: true post: true activity: if last->oclIsUndefined() then last := -1 else skip; if ban_color->oclIsUndefined() then ban_color := -1 else skip; var color : int := 1 ; for to : vertex[x+1] do ( if to = last then ( continue ) else skip ; if color = ban_color then ( color := color + 1 ) else skip ; color_dic[Sequence{x, to}+1] := color ; dfs(to, x, color) ; color := color + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def SeaLand(x,y): if x % 2==0 and y>(x**2)//2 : print('NO') elif x % 2==1 and(x-1)//2*x+(x+1)//2collect( _x | (OclType["int"])->apply(_x) )) ; SeaLand(n, k); operation SeaLand(x : OclAny, y : OclAny) pre: true post: true activity: if x mod 2 = 0 & (y->compareTo(((x)->pow(2)) div 2)) > 0 then ( execute ('NO')->display() ) else (if x mod 2 = 1 & ((x - 1) div 2 * x + (x + 1) div 2->compareTo(y)) < 0 then ( execute ('NO')->display() ) else ( execute ('YES')->display() ; var count : int := 0 ; for i : Integer.subrange(0, x-1) do ( for j : Integer.subrange(0, x-1) do ( if (count->compareTo(y)) < 0 & (i + j) mod 2 = 0 then ( execute ('L')->display() ; count := count + 1 ) else ( execute ('S')->display() )) ; execute (->display()) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : X=input() if X=='0' : break r='' minus=False if X[0]=='-' : minus=True X=X[1 :] kuri=0 idx=len(X)-1 while idx>=0 : a=int(X[idx]) if minus : r=str((10-a-kuri)% 10)+r kuri=0 if kuri+a==0 else 1 else : r=str((kuri+a)% 10)+r kuri=(kuri+a)//10 minus=not minus if idx==0 and kuri>0 : X='0'+X else : idx-=1 r=str(kuri)+r print(int(r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var X : String := (OclFile["System.in"]).readLine() ; if X = '0' then ( break ) else skip ; var r : String := '' ; var minus : boolean := false ; if X->first() = '-' then ( minus := true ; X := X->tail() ) else skip ; var kuri : int := 0 ; var idx : double := (X)->size() - 1 ; while idx >= 0 do ( var a : int := ("" + ((X[idx+1])))->toInteger() ; if minus then ( r := ("" + (((10 - a - kuri) mod 10))) + r ; kuri := if kuri + a = 0 then 0 else 1 endif ) else ( r := ("" + (((kuri + a) mod 10))) + r ; kuri := (kuri + a) div 10 ) ; minus := not(minus) ; if idx = 0 & kuri > 0 then ( X := '0' + X ) else ( idx := idx - 1 )) ; r := ("" + ((kuri))) + r ; execute (("" + ((r)))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break s=str(n)[: :-1] digi=[int(s[i])*((-1)**i)for i in range(len(s))]if n>=0 else[-int(s[i])*((-1)**i)for i in range(len(s)-1)] for i in range(2): digi.append(0) l=len(digi) negdec=0 for k in range(l): a=digi[k] if a<0 : negdec+=(10+a)*(10**k) digi[k+1]+=1 elif a>=10 : negdec+=(a-10)*(10**k) digi[k+1]-=1 else : negdec+=a*(10**k) print(negdec) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var s : OclAny := OclType["String"](n)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var digi : Sequence := if n >= 0 then Integer.subrange(0, (s)->size()-1)->select(i | true)->collect(i | (("" + ((s[i+1])))->toInteger() * (((-1))->pow(i)))) else Integer.subrange(0, (s)->size() - 1-1)->select(i | true)->collect(i | (-("" + ((s[i+1])))->toInteger() * (((-1))->pow(i)))) endif ; for i : Integer.subrange(0, 2-1) do ( execute ((0) : digi)) ; var l : int := (digi)->size() ; var negdec : int := 0 ; for k : Integer.subrange(0, l-1) do ( var a : OclAny := digi[k+1] ; if a < 0 then ( negdec := negdec + (10 + a) * ((10)->pow(k)) ; digi[k + 1+1] := digi[k + 1+1] + 1 ) else (if a >= 10 then ( negdec := negdec + (a - 10) * ((10)->pow(k)) ; digi[k + 1+1] := digi[k + 1+1] - 1 ) else ( negdec := negdec + a * ((10)->pow(k)) ) ) ) ; execute (negdec)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if n==0 : break a='' while n : b=n % 10 if b<0 : b+=10 a+=str(b) n=(n-b)//(-10) print(a[: :-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var a : String := '' ; while n do ( var b : int := n mod 10 ; if b < 0 then ( b := b + 10 ) else skip ; a := a + ("" + ((b))) ; n := (n - b) div (-10)) ; execute (a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : N=int(input()) if N==0 : break R=[] c=0 while N : if c : if N % 10>0 : R.append(10-(N % 10)) N+=10 else : R.append(0) else : R.append(N % 10) c ^=1 N//=10 R.reverse() print(*R,sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var R : Sequence := Sequence{} ; var c : int := 0 ; while N do ( if c then ( if N mod 10 > 0 then ( execute ((10 - (N mod 10)) : R) ; N := N + 10 ) else ( execute ((0) : R) ) ) else ( execute ((N mod 10) : R) ) ; c := c xor 1 ; N := N div 10) ; R := R->reverse() ; execute ((argument * (test (logical_test (comparison (expr (atom (name R))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break d=1 ans=0 b=1 while n!=0 : x=n %(10*b)*b ans=ans+x*d n-=x*b n//=10 b*=-1 d*=10 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var d : int := 1 ; var ans : int := 0 ; var b : int := 1 ; while n /= 0 do ( var x : int := n mod (10 * b) * b ; ans := ans + x * d ; n := n - x * b ; n := n div 10 ; b := b * -1 ; d := d * 10) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math ; def normal(m,n): N=((abs(m)*abs(n))/math.sqrt((abs(m)*abs(m))+(abs(n)*abs(n)))); return N ; m=-5 ; n=3 ; print(normal(m,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; ; skip ; m := -5; n := 3; ; execute (normal(m, n))->display();; operation normal(m : OclAny, n : OclAny) pre: true post: true activity: var N : double := (((m)->abs() * (n)->abs()) / (((m)->abs() * (m)->abs()) + ((n)->abs() * (n)->abs()))->sqrt()); ; return N;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,h=map(int,input().split()) ans=[] for i in range(1,n): ans.append(h*((i/n)**0.5)) print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var h : OclAny := null; Sequence{n,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(1, n-1) do ( execute ((h * (((i / n))->pow(0.5))) : ans)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heappop as pop from heapq import heappush as push INF=10**20 n=int(input()) m=int(input()) edges=[[]for _ in range(n)] for _ in range(m): a,b,c,d=map(int,input().split(",")) a,b=a-1,b-1 edges[a].append((b,c)) edges[b].append((a,d)) s,g,v,p=map(int,input().split(",")) s,g=s-1,g-1 def dij(s,g): que=[(0,s)] costs=[INF for _ in range(n)] costs[s]=0 while que : cost,num=pop(que) if num==g : return cost for edge in edges[num]: to,fee=edge if costs[to]>cost+fee : costs[to]=cost+fee push(que,(cost+fee,to)) print(v-p-dij(s,g)-dij(g,s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var INF : double := (10)->pow(20) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var edges : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split(","))->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{a - 1,b - 1} ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name b)))))) , (test (logical_test (comparison (expr (atom (name c))))))) )))))))) )))) ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name d))))))) )))))))) ))))) ; var s : OclAny := null; var g : OclAny := null; var v : OclAny := null; var p : OclAny := null; Sequence{s,g,v,p} := (input().split(","))->collect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := null; var g : OclAny := null; Sequence{s,g} := Sequence{s - 1,g - 1} ; skip ; execute (v - p - dij(s, g) - dij(g, s))->display(); operation dij(s : OclAny, g : OclAny) : OclAny pre: true post: true activity: var que : Sequence := Sequence{ Sequence{0, s} } ; var costs : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (INF)) ; costs[s+1] := 0 ; while que do ( var cost : OclAny := null; var num : OclAny := null; Sequence{cost,num} := pop(que) ; if num = g then ( return cost ) else skip ; for edge : edges[num+1] do ( var to : OclAny := null; var fee : OclAny := null; Sequence{to,fee} := edge ; if (costs[to+1]->compareTo(cost + fee)) > 0 then ( costs[to+1] := cost + fee ; push(que, Sequence{cost + fee, to}) ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def rl(): return list(map(int,input().split())) def ri(): return int(input()) n,h=rl() def check(x,s): global h ss=x/h*x/2 if ss>s : return True else : return False for i in range(n-1): s=h/2/n*(i+1) f=0 e=h while e-f>0.0000001 : mid=(f+e)/2 if check(mid,s): e=mid else : f=mid print(f) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute h : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; var n : OclAny := null; var h : OclAny := null; Sequence{n,h} := rl() ; skip ; for i : Integer.subrange(0, n - 1-1) do ( s := h / 2 / n * (i + 1) ; var f : int := 0 ; var e : OclAny := h ; while e - f > 0.0000001 do ( var mid : double := (f + e) / 2 ; if check(mid, s) then ( e := mid ) else ( f := mid )) ; execute (f)->display()); operation rl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ri() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation check(x : OclAny, s : OclAny) : OclAny pre: true post: true activity: skip ; var ss : double := x / h * x / 2 ; if (ss->compareTo(s)) > 0 then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,h=map(int,input().split()) for x in range(1,n): height=h*math.sqrt(x/n) print(height,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var h : OclAny := null; Sequence{n,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for x : Integer.subrange(1, n-1) do ( var height : double := h * (x / n)->sqrt() ; execute (height)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def longestString(str1,str2): count1=[0]*26 count2=[0]*26 for i in range(len(str1)): count1[ord(str1[i])-ord('a')]+=1 for i in range(len(str2)): count2[ord(str2[i])-ord('a')]+=1 result="" for i in range(26): for j in range(1,min(count1[i],count2[i])+1): result=result+chr(ord('a')+i) print(result) if __name__=="__main__" : str1="geeks" str2="cake" longestString(str1,str2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( str1 := "geeks" ; str2 := "cake" ; longestString(str1, str2) ) else skip; operation longestString(str1 : OclAny, str2 : OclAny) pre: true post: true activity: var count1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; var count2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for i : Integer.subrange(0, (str1)->size()-1) do ( count1[(str1[i+1])->char2byte() - ('a')->char2byte()+1] := count1[(str1[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; for i : Integer.subrange(0, (str2)->size()-1) do ( count2[(str2[i+1])->char2byte() - ('a')->char2byte()+1] := count2[(str2[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; var result : String := "" ; for i : Integer.subrange(0, 26-1) do ( for j : Integer.subrange(1, Set{count1[i+1], count2[i+1]}->min() + 1-1) do ( result := result + (('a')->char2byte() + i)->byte2char())) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import fileinput import math def main(): f=fileinput.input() line=next(f) c=line.split(" ") n=int(c[0]) h=int(c[1]) s=1.0*h/(2.0*n) d=0.0 for k in range(1,n): a=math.sqrt(k*s*2.0/h)*h print(a) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var f : OclAny := fileinput.input() ; var line : OclAny := (f).next() ; var c : OclAny := line.split(" ") ; var n : int := ("" + ((c->first())))->toInteger() ; var h : int := ("" + ((c[1+1])))->toInteger() ; var s : double := 1.0 * h / (2.0 * n) ; var d : double := 0.0 ; for k : Integer.subrange(1, n-1) do ( var a : double := (k * s * 2.0 / h)->sqrt() * h ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,h=map(int,input().split()) for i in range(1,n): print(h*(i/n)**0.5,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var h : OclAny := null; Sequence{n,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(1, n-1) do ( execute (h * ((i / n))->pow(0.5))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countBits(n): count=0 while(n): count+=1 n>>=1 return count i=65 print(countBits(i)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var i : int := 65 ; execute (countBits(i))->display(); operation countBits(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while (n) do ( count := count + 1 ; n := n div (2->pow(1))) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w=map(int,input().split()) a,b=map(int,input().split()) print(h*w-(a*b*((h//a)*(w//b)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (h * w - (a * b * ((h div a) * (w div b))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict from heapq import heappush,heappop import sys import math import bisect import random def LI(): return list(map(int,sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return list(map(list,sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l=[None for i in range(n)] for i in range(n): l[i]=I() return l def LIR(n): l=[None for i in range(n)] for i in range(n): l[i]=LI() return l def SR(n): l=[None for i in range(n)] for i in range(n): l[i]=S() return l def LSR(n): l=[None for i in range(n)] for i in range(n): l[i]=SR() return l mod=1000000007 h,w=LI() a,b=LI() y=h//a x=w//b ans=h*w-a*y*b*x print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : int := 1000000007 ; var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := LI() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := LI() ; var y : int := h div a ; var x : int := w div b ; var ans : double := h * w - a * y * b * x ; execute (ans)->display(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["Sequence"])->apply(_x) )); operation S() : OclAny pre: true post: true activity: return OclType["Sequence"]((OclFile["System.in"]).readLine())->front(); operation IR(n : OclAny) : OclAny pre: true post: true activity: var l : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; for i : Integer.subrange(0, n-1) do ( l[i+1] := I()) ; return l; operation LIR(n : OclAny) : OclAny pre: true post: true activity: l := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; for i : Integer.subrange(0, n-1) do ( l[i+1] := LI()) ; return l; operation SR(n : OclAny) : OclAny pre: true post: true activity: l := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; for i : Integer.subrange(0, n-1) do ( l[i+1] := S()) ; return l; operation LSR(n : OclAny) : OclAny pre: true post: true activity: l := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; for i : Integer.subrange(0, n-1) do ( l[i+1] := SR()) ; return l; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=list(map(int,input().split())) c,d=list(map(int,input().split())) sum1=a*b length2=a//c side2=b//d sum2=(c*length2)*(d*side2) print(sum1-sum2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sum1 : double := a * b ; var length2 : int := a div c ; var side2 : int := b div d ; var sum2 : double := (c * length2) * (d * side2) ; execute (sum1 - sum2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W=map(int,raw_input().split()) A,B=map(int,raw_input().split()) print(H % A*W)+(W % B*H)-(H % A)*(W % B) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (expr (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name H))) % (expr (atom (name A)))) * (expr (atom (name W))))))))) )))) + (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name W))) % (expr (atom (name B)))) * (expr (atom (name H)))))))) )))) - (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name H))) % (expr (atom (name A)))))))) ))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name W))) % (expr (atom (name B)))))))) ))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w=map(int,input().split()) a,b=map(int,input().split()) high=(h//a)*a wide=(w//b)*b print(h*w-high*wide) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var high : double := (h div a) * a ; var wide : double := (w div b) * b ; execute (h * w - high * wide)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r1,r2=map(int,input().split()) c1,c2=map(int,input().split()) d1,d2=map(int,input().split()) x=(d1+c1-r2)//2 y=r1-x z=c1-x w=d1-x if 1<=x<=9 and 1<=y<=9 and 1<=z<=9 and 1<=w<=9 and len(set([x,y,z,w]))==4 : print(x,y) print(z,w) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r1 : OclAny := null; var r2 : OclAny := null; Sequence{r1,r2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c1 : OclAny := null; var c2 : OclAny := null; Sequence{c1,c2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d1 : OclAny := null; var d2 : OclAny := null; Sequence{d1,d2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : int := (d1 + c1 - r2) div 2 ; var y : double := r1 - x ; var z : double := c1 - x ; var w : double := d1 - x ; if 1 <= x & (x <= 9) & 1 <= y & (y <= 9) & 1 <= z & (z <= 9) & 1 <= w & (w <= 9) & (Set{}->union((Sequence{x}->union(Sequence{y}->union(Sequence{z}->union(Sequence{ w }))))))->size() = 4 then ( execute (x)->display() ; execute (z)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left as bl n=int(input()) tlst=sorted([int(input())for _ in range(n)]) max_t=tlst[-1] divisors=[i for i in range(1,max_t+1)if max_t % i==0] ans=0 for t in tlst : ind=bl(divisors,t) ans+=divisors[ind]-t print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var tlst : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))->sort() ; var max_t : OclAny := tlst->last() ; var divisors : Sequence := Integer.subrange(1, max_t + 1-1)->select(i | max_t mod i = 0)->collect(i | (i)) ; var ans : int := 0 ; for t : tlst do ( var ind : OclAny := bl(divisors, t) ; ans := ans + divisors[ind+1] - t) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def msb(x): ret=0 while((x>>(ret+1))!=0): ret=ret+1 return ret def xorRange(l,r): max_bit=msb(r) mul=2 ans=0 for i in range(1,max_bit+1): if((l//mul)*mul==(r//mul)*mul): if((((l &(1<display(); operation msb(x : OclAny) : OclAny pre: true post: true activity: var ret : int := 0 ; while ((x /(2->pow((ret + 1)))) /= 0) do ( ret := ret + 1) ; return ret; operation xorRange(l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var max_bit : OclAny := msb(r) ; var mul : int := 2 ; var ans : int := 0 ; for i : Integer.subrange(1, max_bit + 1-1) do ( if ((l div mul) * mul = (r div mul) * mul) then ( if ((((MathLib.bitwiseAnd(l, (1 * (2->pow(i))))) /= 0) & (r - l + 1) mod 2 = 1)) then ( ans := ans + mul ) else skip ; mul := mul * 2 ; continue ) else skip ; var odd_c : int := 0 ; if (((MathLib.bitwiseAnd(l, (1 * (2->pow(i))))) /= 0) & l mod 2 = 1) then ( odd_c := (MathLib.bitwiseXor(odd_c, 1)) ) else skip ; if (((MathLib.bitwiseAnd(r, (1 * (2->pow(i))))) /= 0) & r mod 2 = 0) then ( odd_c := (MathLib.bitwiseXor(odd_c, 1)) ) else skip ; if (odd_c) then ( ans := ans + mul ) else skip ; mul := mul * 2) ; var zero_bit_cnt : int := (r - l + 1) div 2 ; if ((l mod 2 = 1) & (r mod 2 = 1)) then ( zero_bit_cnt := zero_bit_cnt + 1 ) else skip ; if (zero_bit_cnt mod 2 = 1) then ( ans := ans + 1 ) else skip ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) lis=[] cou=0 ans=0 for i in range(n): a=int(input()) cou=max(cou,a) lis.append(a) num=[] for i in range(1,cou+1): if cou % i==0 : num.append(i) for nu in lis : co=0 while num[co]toInteger() ; var lis : Sequence := Sequence{} ; var cou : int := 0 ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; cou := Set{cou, a}->max() ; execute ((a) : lis)) ; var num : Sequence := Sequence{} ; for i : Integer.subrange(1, cou + 1-1) do ( if cou mod i = 0 then ( execute ((i) : num) ) else skip) ; for nu : lis do ( var co : int := 0 ; while (num[co+1]->compareTo(nu)) < 0 do ( co := co + 1) ; ans := ans + (num[co+1] - nu)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def divisor_list(x): return tuple([i for i in range(1,x+1)if x % i==0]) N=int(input()) t=[int(input())for _ in range(N)] div=divisor_list(max(t)) di=0 for i in range(N): j=0 while div[j]toInteger() ; var t : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var div : OclAny := divisor_list((t)->max()) ; var di : int := 0 ; for i : Integer.subrange(0, N-1) do ( var j : int := 0 ; (compound_stmt while (test (logical_test (comparison (comparison (expr (atom (name div)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) < (comparison (expr (atom (name t)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name j)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name di)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name div)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))) - (expr (atom (name t)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))))))))))) ; execute (di)->display(); operation divisor_list(x : OclAny) : OclAny pre: true post: true activity: return (Integer.subrange(1, x + 1-1)->select(i | x mod i = 0)->collect(i | (i))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) max_t=0 timing=[] for i in range(n): timing.append(int(input())) if timing[i]>max_t : max_t=timing[i] divisor=[] for i in range(1,(max_t>>1)+1): if max_t % i==0 : divisor.append(i) divisor.append(max_t) adj=0 for t in timing : for d in divisor : if d>=t : adj+=d-t break print(adj) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var max_t : int := 0 ; var timing : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : timing) ; if (timing[i+1]->compareTo(max_t)) > 0 then ( max_t := timing[i+1] ) else skip) ; var divisor : Sequence := Sequence{} ; for i : Integer.subrange(1, (max_t /(2->pow(1))) + 1-1) do ( if max_t mod i = 0 then ( execute ((i) : divisor) ) else skip) ; execute ((max_t) : divisor) ; var adj : int := 0 ; for t : timing do ( for d : divisor do ( if (d->compareTo(t)) >= 0 then ( adj := adj + d - t ; break ) else skip)) ; execute (adj)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) lst=[int(input())for _ in range(N)] max_=max(lst) divisors=[] d=0 for i in range(1,int(max_**0.5)+1): if max_ % i==0 : divisors.append(i) divisors.append(max_//i) divisors.sort() for i in sorted(lst): for divisor in divisors : if i<=divisor : d+=divisor-i break print(d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var max_ : OclAny := (lst)->max() ; var divisors : Sequence := Sequence{} ; var d : int := 0 ; for i : Integer.subrange(1, ("" + (((max_)->pow(0.5))))->toInteger() + 1-1) do ( if max_ mod i = 0 then ( execute ((i) : divisors) ; execute ((max_ div i) : divisors) ) else skip) ; divisors := divisors->sort() ; for i : lst->sort() do ( for divisor : divisors do ( if (i->compareTo(divisor)) <= 0 then ( d := d + divisor - i ; break ) else skip)) ; execute (d)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def LongestSubarray(arr,n,k): arr2=[0]*n for i in range(n): arr2[i]=arr[i]% k max_length=0 i=0 while iunion(Sequence{9}->union(Sequence{7}->union(Sequence{18}->union(Sequence{29}->union(Sequence{ 11 }))))) ; n := (arr)->size() ; k := 11 ; execute (LongestSubarray(arr, n, k))->display() ) else skip; operation LongestSubarray(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var arr2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( arr2[i+1] := arr[i+1] mod k) ; var max_length : int := 0 ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( var current_length : int := 1 ; for j : Integer.subrange(i + 1, n-1) do ( if (arr2[j+1] = arr2[i+1]) then ( current_length := current_length + 1 ) else ( break )) ; max_length := Set{max_length, current_length}->max() ; i := j ; i := i + 1) ; return max_length; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()); print(m-1 if n-m+1<=m and n!=1 else m+1 if n!=1 else 1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); execute (if (n - m + 1->compareTo(m)) <= 0 & n /= 1 then m - 1 else if n /= 1 then m + 1 else 1 endif endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(i)for i in input().split()] print(m+1 if m<=n/2.0 else max(m-1,1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute (if (m->compareTo(n / 2.0)) <= 0 then m + 1 else Set{m - 1, 1}->max() endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) if n>1 : if m-1>=n-m : print(m-1) else : print(m+1) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n > 1 then ( if (m - 1->compareTo(n - m)) >= 0 then ( execute (m - 1)->display() ) else ( execute (m + 1)->display() ) ) else ( execute (1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) if(n==1): print(1) else : if(n//2>=m): print(m+1) else : print(m-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (n = 1) then ( execute (1)->display() ) else ( if ((n div 2->compareTo(m)) >= 0) then ( execute (m + 1)->display() ) else ( execute (m - 1)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r1,r2=list(map(int,input().split())) c1,c2=list(map(int,input().split())) d1,d2=list(map(int,input().split())) s_1=(r1+r2+d1+d2+c1+c2)/3 s_2=(r1-r2)+(d2-d1)+(c1-c2) if((s_1-s_2)% 4!=0): print(-1) else : z=int((s_1-s_2)/4) x=(c2-z) y=(r2-z) w=(r1-x) result=[w,x,y,z] is_valid=(w>0 and x>0 and y>0 and z>0)and(w<10 and x<10 and y<10 and z<10) for i in range(0,4): for j in range(i+1,4): if result[i]==result[j]: is_valid=False break if is_valid : print(w,x) print(y,z) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r1 : OclAny := null; var r2 : OclAny := null; Sequence{r1,r2} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c1 : OclAny := null; var c2 : OclAny := null; Sequence{c1,c2} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d1 : OclAny := null; var d2 : OclAny := null; Sequence{d1,d2} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s var r1 : OclAny := null; var r2 : OclAny := null; Sequence{r1,r2} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) : double := (r1 + r2 + d1 + d2 + c1 + c2) / 3 ; var s:= (r1 - r2) + (d2 - d1) + (c1 - c2) : double := (r1 - r2) + (d2 - d1) + (c1 - c2) ; if ((s var r1 : OclAny := null; var r2 : OclAny := null; Sequence{r1,r2} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) - s4) mod 4 /= 0) then ( execute (-1)->display() ) else ( var z : int := ("" + (((s var r1 : OclAny := null; var r2 : OclAny := null; Sequence{r1,r2} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) - s4) / 4)))->toInteger() ; var x : double := (c2 - z) ; var y : double := (r2 - z) ; var w : double := (r1 - x) ; var result : Sequence := Sequence{w}->union(Sequence{x}->union(Sequence{y}->union(Sequence{ z }))) ; var is_valid : boolean := (w > 0 & x > 0 & y > 0 & z > 0) & (w < 10 & x < 10 & y < 10 & z < 10) ; for i : Integer.subrange(0, 4-1) do ( for j : Integer.subrange(i + 1, 4-1) do ( if result[i+1] = result[j+1] then ( is_valid := false ; break ) else skip)) ; if is_valid then ( execute (w)->display() ; execute (y)->display() ) else ( execute (-1)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def q1(s,i): if(i==len(s)): print("Yes"); return ; if(s[i]=='a'): q1(s,i+1); else : q2(s,i+1); def q2(s,i): if(i==len(s)): print("No"); return ; if(s[i]=='a'): q1(s,i+1); else : q2(s,i+1); def q3(s,i): if(i==len(s)): print("Yes"); return ; if(s[i]=='a'): q4(s,i+1); else : q3(s,i+1); def q4(s,i): if(i==s.length()): print("No"); return ; if(s[i]=='a'): q4(s,i+1); else : q3(s,i+1); def q0(s,i): if(i==len(s)): print("No"); return ; if(s[i]=='a'): q1(s,i+1); else : q3(s,i+1); if __name__=='__main__' : s="abbaabb" ; q0(s,0); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( s := "abbaabb"; ; q0(s, 0); ) else skip; operation q1(s : OclAny, i : OclAny) : OclAny pre: true post: true activity: if (i = (s)->size()) then ( execute ("Yes")->display(); ; return; ) else skip ; if (s[i+1] = 'a') then ( q1(s, i + 1); ) else ( q2(s, i + 1); ); operation q2(s : OclAny, i : OclAny) : OclAny pre: true post: true activity: if (i = (s)->size()) then ( execute ("No")->display(); ; return; ) else skip ; if (s[i+1] = 'a') then ( q1(s, i + 1); ) else ( q2(s, i + 1); ); operation q3(s : OclAny, i : OclAny) : OclAny pre: true post: true activity: if (i = (s)->size()) then ( execute ("Yes")->display(); ; return; ) else skip ; if (s[i+1] = 'a') then ( q4(s, i + 1); ) else ( q3(s, i + 1); ); operation q4(s : OclAny, i : OclAny) : OclAny pre: true post: true activity: if (i = s.length()) then ( execute ("No")->display(); ; return; ) else skip ; if (s[i+1] = 'a') then ( q4(s, i + 1); ) else ( q3(s, i + 1); ); operation q0(s : OclAny, i : OclAny) : OclAny pre: true post: true activity: if (i = (s)->size()) then ( execute ("No")->display(); ; return; ) else skip ; if (s[i+1] = 'a') then ( q1(s, i + 1); ) else ( q3(s, i + 1); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- data=input().split(" ") n,m=int(data[0]),int(data[1]) right_num_count=n-m left_num_count=m-1 if n==1 : print(1) elif right_num_count>left_num_count : print(m+1) else : print(m-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var data : OclAny := input().split(" ") ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{("" + ((data->first())))->toInteger(),("" + ((data[1+1])))->toInteger()} ; var right_num_count : double := n - m ; var left_num_count : double := m - 1 ; if n = 1 then ( execute (1)->display() ) else (if (right_num_count->compareTo(left_num_count)) > 0 then ( execute (m + 1)->display() ) else ( execute (m - 1)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isHeterogram(s,n): hash=[0]*26 for i in range(n): if s[i]!=' ' : if hash[ord(s[i])-ord('a')]==0 : hash[ord(s[i])-ord('a')]=1 else : return False return True s="the big dwarf only jumps" n=len(s) print("YES" if isHeterogram(s,n)else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := "the big dwarf only jumps" ; n := (s)->size() ; execute (if isHeterogram(s, n) then "YES" else "NO" endif)->display(); operation isHeterogram(s : OclAny, n : OclAny) : OclAny pre: true post: true activity: var hash : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for i : Integer.subrange(0, n-1) do ( if s[i+1] /= ' ' then ( if hash[(s[i+1])->char2byte() - ('a')->char2byte()+1] = 0 then ( hash[(s[i+1])->char2byte() - ('a')->char2byte()+1] := 1 ) else ( return false ) ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools def compute(): arr=list(range(10)) temp=itertools.islice(itertools.permutations(arr),999999,None) return "".join(str(x)for x in next(temp)) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var arr : Sequence := (Integer.subrange(0, 10-1)) ; var temp : OclAny := itertools.islice(itertools.permutations(arr), 999999, null) ; return StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name next)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name temp)))))))) ))))))))), ""); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def FindPoint(x1,y1,x2,y2,x,y): if(x>x1 and xy1 and ydisplay() ) else ( execute ("No")->display() ) ) else skip; operation FindPoint(x1 : OclAny, y1 : OclAny, x2 : OclAny, y2 : OclAny, x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if ((x->compareTo(x1)) > 0 & (x->compareTo(x2)) < 0 & (y->compareTo(y1)) > 0 & (y->compareTo(y2)) < 0) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import maxsize as INT_MAX MX=2001 OFF=1000 class point : def __init__(self,x,y): self.x=x self.y=y def countPoints(n : int,points : list)->int : minx=[INT_MAX]*MX miny=[INT_MAX]*MX maxx=[0]*MX maxy=[0]*MX x,y=0,0 for i in range(n): points[i].x+=OFF points[i].y+=OFF x=points[i].x y=points[i].y minx[y]=min(minx[y],x) maxx[y]=max(maxx[y],x) miny[x]=min(miny[x],y) maxy[x]=max(maxy[x],y) count=0 for i in range(n): x=points[i].x y=points[i].y if(x>minx[y]and xminy[x]and yexists( _x | result = _x ); attribute x : OclAny := x; attribute y : OclAny := y; operation initialise(x : OclAny,y : OclAny) : point pre: true post: true activity: self.x := x ; self.y := y; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; var MX : int := 2001 ; var OFF : int := 1000 ; skip ; skip ; if __name__ = "__main__" then ( var points : Sequence := Sequence{(point.newpoint()).initialise(0, 0)}->union(Sequence{(point.newpoint()).initialise(0, 1)}->union(Sequence{(point.newpoint()).initialise(1, 0)}->union(Sequence{(point.newpoint()).initialise(0, -1)}->union(Sequence{ (point.newpoint()).initialise(-1, 0) })))) ; var n : int := (points)->size() ; execute (countPoints(n, points))->display() ) else skip; operation countPoints(n : int, points : Sequence(OclAny)) : int pre: true post: true activity: var minx : Sequence := MatrixLib.elementwiseMult(Sequence{ INT_MAX }, MX) ; var miny : Sequence := MatrixLib.elementwiseMult(Sequence{ INT_MAX }, MX) ; var maxx : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MX) ; var maxy : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MX) ; Sequence{x,y} := Sequence{0,0} ; for i : Integer.subrange(0, n-1) do ( points[i+1].x := points[i+1].x + OFF ; points[i+1].y := points[i+1].y + OFF ; x := points[i+1].x ; y := points[i+1].y ; minx[y+1] := Set{minx[y+1], x}->min() ; maxx[y+1] := Set{maxx[y+1], x}->max() ; miny[x+1] := Set{miny[x+1], y}->min() ; maxy[x+1] := Set{maxy[x+1], y}->max()) ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( x := points[i+1].x ; y := points[i+1].y ; if ((x->compareTo(minx[y+1])) > 0 & (x->compareTo(maxx[y+1])) < 0) then ( if ((y->compareTo(miny[x+1])) > 0 & (y->compareTo(maxy[x+1])) < 0) then ( count := count + 1 ) else skip ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- X_low,Y_up=map(int,input().split()) value=X_low cnt=0 while(value<=Y_up): cnt+=1 value*=2 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var X_low : OclAny := null; var Y_up : OclAny := null; Sequence{X_low,Y_up} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var value : OclAny := X_low ; var cnt : int := 0 ; while ((value->compareTo(Y_up)) <= 0) do ( cnt := cnt + 1 ; value := value * 2) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math x,y=map(int,input().split()) ans=1 a=y for i in range(10**9): if ay : break ans_t+=1 ans=max(ans,ans_t) a=math.floor(a**0.5) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 1 ; var a : OclAny := y ; for i : Integer.subrange(0, (10)->pow(9)-1) do ( if (a->compareTo(x)) < 0 or a = 1 then ( break ) else skip ; var x_t : OclAny := x ; var ans_t : int := 1 ; for j : Integer.subrange(0, (10)->pow(9)-1) do ( x_t := x_t * 2 ; if (x_t->compareTo(y)) > 0 then ( break ) else skip ; ans_t := ans_t + 1) ; ans := Set{ans, ans_t}->max() ; a := ((a)->pow(0.5))->floor()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=list(map(int,input().split())) ret=1 while True : x*=2 if x<=y : ret+=1 else : break print(ret) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ret : int := 1 ; while true do ( x := x * 2 ; if (x->compareTo(y)) <= 0 then ( ret := ret + 1 ) else ( break )) ; execute (ret)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import count,takewhile x,y=map(int,input().split()) print(sum(1 for _ in takewhile(lambda z : z<=y,(x*(2**i)for i in count())))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name takewhile)) (trailer (arguments ( (arglist (argument (test lambda (varargslist (vardef_parameters (vardef_parameter (name z)))) : (test (logical_test (comparison (comparison (expr (atom (name z)))) <= (comparison (expr (atom (name y))))))))) , (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) ** (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name count)) (trailer (arguments ( )))))))) )))))))) )))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(): x,y=map(int,sys.stdin.readline().split()) cnt=0 i=x while i<=y : cnt+=1 i+=i print(cnt) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cnt : int := 0 ; var i : OclAny := x ; while (i->compareTo(y)) <= 0 do ( cnt := cnt + 1 ; i := i + i) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) class BIT(): def __init__(self,size): self.table=[0 for _ in range(size+2)] self.size=size def b_sum(self,i): s=0 while i>0 : s+=self.table[i] i-=(i &-i) return s def b_add(self,i,x): while i<=self.size : self.table[i]+=x i+=(i &-i) return fr,ba=min(a),max(a)+1 while ba-fr>1 : mi=(fr+ba)//2 bit=BIT(n+1) res=0 inv=[0] min_tmp=0 for j in range(n): if a[j]>=mi : inv.append(inv[-1]+1) else : inv.append(inv[-1]-1) min_tmp=min(min_tmp,inv[-1]) for j in range(n+1): res+=bit.b_sum(inv[j]-min_tmp+1) bit.b_add(inv[j]-min_tmp+1,1) if res>=(n*(n+1)/4): fr=mi else : ba=mi print(fr) ------------------------------------------------------------ OCL File: --------- class BIT { static operation newBIT() : BIT pre: true post: BIT->exists( _x | result = _x ); attribute table : Sequence := Integer.subrange(0, size + 2-1)->select(_anon | true)->collect(_anon | (0)); attribute size : OclAny := size; operation initialise(size : OclAny) : pre: true post: true activity: self.table := Integer.subrange(0, size + 2-1)->select(_anon | true)->collect(_anon | (0)) ; self.size := size; return self; operation b_sum(i : OclAny) : OclAny pre: true post: true activity: var s : int := 0 ; while i > 0 do ( s := s + self.table[i+1] ; i := i - (MathLib.bitwiseAnd(i, -i))) ; return s; operation b_add(i : OclAny,x : OclAny) pre: true post: true activity: while (i->compareTo(self.size)) <= 0 do ( self.table[i+1] := self.table[i+1] + x ; i := i + (MathLib.bitwiseAnd(i, -i))) ; return; } class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; var fr : OclAny := null; var ba : OclAny := null; Sequence{fr,ba} := Sequence{(a)->min(),(a)->max() + 1} ; while ba - fr > 1 do ( var mi : int := (fr + ba) div 2 ; var bit : BIT := (BIT.newBIT()).initialise(n + 1) ; var res : int := 0 ; var inv : Sequence := Sequence{ 0 } ; var min_tmp : int := 0 ; for j : Integer.subrange(0, n-1) do ( if (a[j+1]->compareTo(mi)) >= 0 then ( execute ((inv->last() + 1) : inv) ) else ( execute ((inv->last() - 1) : inv) ; min_tmp := Set{min_tmp, inv->last()}->min() )) ; for j : Integer.subrange(0, n + 1-1) do ( res := res + bit.b_sum(inv[j+1] - min_tmp + 1) ; bit.b_add(inv[j+1] - min_tmp + 1, 1)) ; if (res->compareTo((n * (n + 1) / 4))) >= 0 then ( var fr : int := mi ) else ( var ba : int := mi )) ; execute (fr)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- arr=[] for i in range(0,3): arr=arr+list(map(int,input().split())) def sum_F(num1,num2,num3,num4,arr): if num1+num2==arr[0]: if num3+num4==arr[1]: if num1+num3==arr[2]: if num2+num4==arr[3]: if num1+num4==arr[4]: if num2+num3==arr[5]: return 1 ; else : return 0 ; else : return 0 ; else : return 0 ; else : return 0 ; else : return 0 ; else : return 0 ; def find(arr): for i in range(1,10): for j in range(1,10): if j in[i]: continue for z in range(1,10): if z in[i,j]: continue for x in range(1,10): if x in[z,i,j]: continue v=sum_F(i,j,z,x,arr) if v==1 : print(i,' ',j) print(z,' ',x) return ; return print(-1); find(arr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var arr : Sequence := Sequence{} ; for i : Integer.subrange(0, 3-1) do ( arr := arr->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; skip ; skip ; find(arr); operation sum_F(num1 : OclAny, num2 : OclAny, num3 : OclAny, num4 : OclAny, arr : OclAny) pre: true post: true activity: if num1 + num2 = arr->first() then ( if num3 + num4 = arr[1+1] then ( if num1 + num3 = arr[2+1] then ( if num2 + num4 = arr[3+1] then ( if num1 + num4 = arr[4+1] then ( if num2 + num3 = arr[5+1] then ( return 1; ) else ( return 0; ) ) else ( return 0; ) ) else ( return 0; ) ) else ( return 0; ) ) else ( return 0; ) ) else ( return 0; ); operation find(arr : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(1, 10-1) do ( for j : Integer.subrange(1, 10-1) do ( if (Sequence{ i })->includes(j) then ( continue ) else skip ; for z : Integer.subrange(1, 10-1) do ( if (Sequence{i}->union(Sequence{ j }))->includes(z) then ( continue ) else skip ; for x : Integer.subrange(1, 10-1) do ( if (Sequence{z}->union(Sequence{i}->union(Sequence{ j })))->includes(x) then ( continue ) else skip ; var v : OclAny := sum_F(i, j, z, x, arr) ; if v = 1 then ( execute (i)->display() ; execute (z)->display() ; return; ) else skip)))) ; return (-1)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sticks=[6,2,5,5,4,5,6,3,7,6]; def countSticks(string,n): cnt=0 ; for i in range(n): cnt+=(sticks[ord(string[i])-ord('0')]); return cnt ; if __name__=="__main__" : string="56" ; n=len(string); print(countSticks(string,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sticks : Sequence := Sequence{6}->union(Sequence{2}->union(Sequence{5}->union(Sequence{5}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{3}->union(Sequence{7}->union(Sequence{ 6 }))))))))); ; skip ; if __name__ = "__main__" then ( string := "56"; ; n := (string)->size(); ; execute (countSticks(string, n))->display(); ) else skip; operation countSticks(string : OclAny, n : OclAny) pre: true post: true activity: var cnt : int := 0; ; for i : Integer.subrange(0, n-1) do ( cnt := cnt + (sticks[(string[i+1])->char2byte() - ('0')->char2byte()+1]);) ; return cnt;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for t in range(0,T): n=int(input()) a=list(map(int,input().split())) ctr=0 maxi=max(a) for i in range(2,n): if a[i]a[i-2]: ctr+=1 if i!=n-1 : a[i]=max(a[i-1],a[i+1]) else : a[i]=a[i-1] print(ctr) for item in a : print(item,end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(0, T-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ctr : int := 0 ; var maxi : OclAny := (a)->max() ; for i : Integer.subrange(2, n-1) do ( if (a[i+1]->compareTo(a[i - 1+1])) < 0 & (a[i - 1+1]->compareTo(a[i - 2+1])) > 0 then ( ctr := ctr + 1 ; if i /= n - 1 then ( a[i+1] := Set{a[i - 1+1], a[i + 1+1]}->max() ) else ( a[i+1] := a[i - 1+1] ) ) else skip) ; execute (ctr)->display() ; for item : a do ( execute (item)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,a=int(input()),[int(i)for i in input().split()] c=0 for i in range(1,n-1): if a[i-1]a[i+1]: if i+2a[i+1]toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))} ; var c : int := 0 ; for i : Integer.subrange(1, n - 1-1) do ( if (a[i - 1+1]->compareTo(a[i+1])) < 0 & (a[i+1] > a[i + 1+1]) then ( if (i + 2->compareTo(n)) < 0 & (a[i+1]->compareTo(a[i + 1+1])) > 0 & (a[i + 1+1] < a[i + 2+1]) then ( a[i + 1+1] := Set{a[i+1], a[i + 2+1]}->max() ) else ( a[i + 1+1] := a[i+1] ) ; c := c + 1 ) else skip) ; (c)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) l=list(map(int,input().split())) check=[0]*n for j in range(1,n-1): if l[j]>l[j-1]and l[j]>l[j+1]: if check[j-1]: l[j-1]=l[j] else : l[j+1]=l[j] check[j+1]=1 print(check.count(1)) for i in l : print(i,end=' ') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var check : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for j : Integer.subrange(1, n - 1-1) do ( if (l[j+1]->compareTo(l[j - 1+1])) > 0 & (l[j+1]->compareTo(l[j + 1+1])) > 0 then ( if check[j - 1+1] then ( l[j - 1+1] := l[j+1] ) else ( l[j + 1+1] := l[j+1] ; check[j + 1+1] := 1 ) ) else skip) ; execute (check->count(1))->display() ; for i : l do ( execute (i)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) l=list(map(int,input().split())) l.append(0) c=0 for i in range(1,n-1): if l[i]>l[i+1]and l[i]>l[i-1]: l[i+1]=max(l[i],l[i+2]) c+=1 print(c) l.pop() for i in l : print(i,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((0) : l) ; var c : int := 0 ; for i : Integer.subrange(1, n - 1-1) do ( if (l[i+1]->compareTo(l[i + 1+1])) > 0 & (l[i+1]->compareTo(l[i - 1+1])) > 0 then ( l[i + 1+1] := Set{l[i+1], l[i + 2+1]}->max() ; c := c + 1 ) else skip) ; execute (c)->display() ; l := l->front() ; for i : l do ( execute (i)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for p in range(int(input())): n=int(input()); a,c=list(map(int,input().split()))+[0],0 for i in range(1,n-1): if a[i-1]a[i+1]: a[i+1]=max(a[i],a[i+2]); c+=1 print(c); print(*a[:-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for p : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var a : OclAny := null; var c : OclAny := null; Sequence{a,c} := Sequence{((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->union(Sequence{ 0 }),0} ; for i : Integer.subrange(1, n - 1-1) do ( if (a[i - 1+1]->compareTo(a[i+1])) < 0 & (a[i+1] > a[i + 1+1]) then ( a[i + 1+1] := Set{a[i+1], a[i + 2+1]}->max(); c := c + 1 ) else skip) ; execute (c)->display(); execute ((argument * (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def command(brr,a,b): arr[a]^=1 arr[b+1]^=1 def process(arr,n): for k in range(1,n+1,1): arr[k]^=arr[k-1] def result(arr,n): for k in range(1,n+1,1): print(arr[k],end=" ") if __name__=='__main__' : n=5 m=3 arr=[0 for i in range(n+2)] command(arr,1,5) command(arr,2,5) command(arr,3,5) process(arr,n) result(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( n := 5 ; var m : int := 3 ; arr := Integer.subrange(0, n + 2-1)->select(i | true)->collect(i | (0)) ; command(arr, 1, 5) ; command(arr, 2, 5) ; command(arr, 3, 5) ; process(arr, n) ; result(arr, n) ) else skip; operation command(brr : OclAny, a : OclAny, b : OclAny) pre: true post: true activity: arr[a+1] := arr[a+1] xor 1 ; arr[b + 1+1] := arr[b + 1+1] xor 1; operation process(arr : OclAny, n : OclAny) pre: true post: true activity: for k : Integer.subrange(1, n + 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( arr[k+1] := arr[k+1] xor arr[k - 1+1]); operation result(arr : OclAny, n : OclAny) pre: true post: true activity: for k : Integer.subrange(1, n + 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( execute (arr[k+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def mostFrequent(arr,n): arr.sort() max_count=1 ; res=arr[0]; curr_count=1 for i in range(1,n): if(arr[i]==arr[i-1]): curr_count+=1 else : if(curr_count>max_count): max_count=curr_count res=arr[i-1] curr_count=1 if(curr_count>max_count): max_count=curr_count res=arr[n-1] return res arr=[1,5,2,1,3,2,1] n=len(arr) print(mostFrequent(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{5}->union(Sequence{2}->union(Sequence{1}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 1 })))))) ; n := (arr)->size() ; execute (mostFrequent(arr, n))->display(); operation mostFrequent(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var max_count : int := 1; var res : OclAny := arr->first(); var curr_count : int := 1 ; for i : Integer.subrange(1, n-1) do ( if (arr[i+1] = arr[i - 1+1]) then ( curr_count := curr_count + 1 ) else ( if ((curr_count->compareTo(max_count)) > 0) then ( max_count := curr_count ; res := arr[i - 1+1] ) else skip ; curr_count := 1 )) ; if ((curr_count->compareTo(max_count)) > 0) then ( max_count := curr_count ; res := arr[n - 1+1] ) else skip ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=26 ; def maxLength(str,len): res=0 ; lastPos=[0]*MAX ; for i in range(MAX): lastPos[i]=-1 ; for i in range(len): C=ord(str[i])-ord('a'); if(lastPos[C]!=-1): res=max(len-(i-lastPos[C]-1)-1,res); lastPos[C]=i ; return res ; if __name__=='__main__' : str="geeksforgeeks" ; len=len(str); print(maxLength(str,len)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 26; ; skip ; if __name__ = '__main__' then ( OclType["String"] := "geeksforgeeks"; ; len := (OclType["String"])->size(); ; execute (maxLength(OclType["String"], len))->display(); ) else skip; operation maxLength(OclType["String"] : OclAny, len : OclAny) pre: true post: true activity: var res : int := 0; ; var lastPos : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX); ; for i : Integer.subrange(0, MAX-1) do ( lastPos[i+1] := -1;) ; for i : Integer.subrange(0, len-1) do ( var C : double := (("" + ([i+1])))->char2byte() - ('a')->char2byte(); ; if (lastPos[C+1] /= -1) then ( res := Set{len - (i - lastPos[C+1] - 1) - 1, res}->max(); ) else skip ; lastPos[C+1] := i;) ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=[] x=int(input()) c,d=map(int,input().split(' ')) for i in range(x): a,b=map(int,input().split(' ')) k.append([c*a+b,d*a+b]) k.sort() for i in range(len(k)-1): if k[i+1][1]toInteger() ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, x-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{c * a + b}->union(Sequence{ d * a + b })) : k)) ; k := k->sort() ; for i : Integer.subrange(0, (k)->size() - 1-1) do ( if (k[i + 1+1][1+1]->compareTo(k[i+1][1+1])) < 0 then ( execute ("YES")->display() ; quit() ) else skip) ; execute ("NO")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys INF=float('inf') MOD=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return input() def main(): n,p=LI() A=LI() even,odd=0,0 for a in A : if a % 2 : odd+=1 else : even+=1 if odd : return 2**(n-1) else : return 2**n if p==0 else 0 print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var INF : double := ("" + (('inf')))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation SI() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation main() : OclAny pre: true post: true activity: var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := LI() ; var A : OclAny := LI() ; var even : OclAny := null; var odd : OclAny := null; Sequence{even,odd} := Sequence{0,0} ; for a : A do ( if a mod 2 then ( odd := odd + 1 ) else ( even := even + 1 )) ; if odd then ( return (2)->pow((n - 1)) ) else ( return if p = 0 then (2)->pow(n) else 0 endif ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000,10**9)) write=lambda x : sys.stdout.write(x+"\n") n=int(input()) a=list(map(int,input().split())) from collections import Counter def sub(x): l=[1 if item>=x else-1 for item in a] count=[0]*(2*n+2) count[n]=1 i=n cumsum=1 ans=0 for item in l : i+=item if item==1 : cumsum+=count[i] else : cumsum-=count[i+1] ans+=cumsum count[i]+=1 cumsum+=1 return ans l=0 r=10**9+1 tmp=(n+1)*n//2 thre=tmp//2+tmp % 2 while l=thre : l=m else : r=m print(l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; sys.setrecursionlimit(Set{1000, (10)->pow(9)}->max()) ; var write : Function := lambda x : OclAny in ((OclFile["System.out"]).write(x + "\n")) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; skip ; l := 0 ; var r : double := (10)->pow(9) + 1 ; var tmp : int := (n + 1) * n div 2 ; var thre : int := tmp div 2 + tmp mod 2 ; while (l->compareTo(r - 1)) < 0 do ( var m : int := (l->union(r)) div 2 ; if (sub(m)->compareTo(thre)) >= 0 then ( l := m ) else ( r := m )) ; execute (l)->display(); operation sub(x : OclAny) : OclAny pre: true post: true activity: var l : Sequence := a->select(item | true)->collect(item | (if (item->compareTo(x)) >= 0 then 1 else -1 endif)) ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * n + 2)) ; count[n+1] := 1 ; var i : int := n ; var cumsum : int := 1 ; var ans : int := 0 ; for item : l do ( i := i + item ; if item = 1 then ( cumsum := cumsum + count[i+1] ) else ( cumsum := cumsum - count[i + 1+1] ) ; ans := ans + cumsum ; count[i+1] := count[i+1] + 1 ; cumsum := cumsum + 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000000 def ksmallest(arr,n,k): b=[0]*MAX ; for i in range(n): b[arr[i]]=1 ; for j in range(1,MAX): if(b[j]!=1): k-=1 ; if(k is not 1): return j ; k=1 ; arr=[1]; n=len(arr); print(ksmallest(arr,n,k)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1000000 ; skip ; k := 1; ; arr := Sequence{ 1 }; ; n := (arr)->size(); ; execute (ksmallest(arr, n, k))->display();; operation ksmallest(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX); ; for i : Integer.subrange(0, n-1) do ( b[arr[i+1]+1] := 1;) ; for j : Integer.subrange(1, MAX-1) do ( if (b[j+1] /= 1) then ( k := k - 1; ) else skip ; if (not(k <>= 1)) then ( return j; ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import queue N,M=map(int,input().split()) p=[int(i)-1 for i in input().split()] x=[0 for i in range(M)] y=[0 for i in range(M)] edge=[set()for i in range(N)] for i in range(M): x[i],y[i]=map(int,input().split()) x[i]-=1 ; y[i]-=1 edge[x[i]].add(y[i]) edge[y[i]].add(x[i]) k=0 L=[0 for i in range(N)] q=queue.Queue() reached=[0 for i in range(N)] for i in range(N): if reached[i]==1 : continue k+=1 q.put(i) reached[i]=1 L[i]=k while(not(q.empty())): r=q.get() for v in edge[r]: if not(reached[v]): q.put(v) reached[v]=1 L[v]=k ans=0 for i in range(N): if L[i]==L[p[i]]: ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger() - 1)) ; var x : Sequence := Integer.subrange(0, M-1)->select(i | true)->collect(i | (0)) ; var y : Sequence := Integer.subrange(0, M-1)->select(i | true)->collect(i | (0)) ; var edge : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Set{}->union(()))) ; for i : Integer.subrange(0, M-1) do ( var x[i+1] : OclAny := null; var y[i+1] : OclAny := null; Sequence{x[i+1],y[i+1]} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; x[i+1] := x[i+1] - 1; y[i+1] := y[i+1] - 1 ; (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))) ; (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))) ; var k : int := 0 ; var L : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; var q : OclAny := queue.Queue() ; var reached : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, N-1) do ( if reached[i+1] = 1 then ( continue ) else skip ; k := k + 1 ; q.put(i) ; reached[i+1] := 1 ; L[i+1] := k ; while (not((q.empty()))) do ( var r : OclAny := q.get() ; for v : edge[r+1] do ( if not((reached[v+1])) then ( q.put(v) ; reached[v+1] := 1 ; L[v+1] := k ) else skip))) ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( if L[i+1] = L[p[i+1]+1] then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import permutations import sys import threading input=sys.stdin.readline def print(*args,end='\n',sep=' ')->None : sys.stdout.write(sep.join(map(str,args))+end) def Solve(): r1,r2=list(map(int,input().split())) c1,c2=list(map(int,input().split())) d1,d2=list(map(int,input().split())) a1=(d1+c1-r2)//2 a2=r1-a1 a3=c1-a1 a4=d1-a1 if a1==a2 or a1==a3 or a1==a4 or a2==a3 or a2==a4 or a3==a4 or 1>a1 or a1>9 or 1>a2 or a2>9 or 1>a3 or a3>9 or 1>a4 or a4>9 : print(-1) else : print(a1,a2) print(a3,a4) if __name__=="__main__" : Solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; if __name__ = "__main__" then ( Solve() ) else skip; (funcdef def name print ( (typedargslist (args * (named_parameter (name args))) , (def_parameters (def_parameter (named_parameter (name end)) = (test (logical_test (comparison (expr (atom ' ')))))) , (def_parameter (named_parameter (name sep)) = (test (logical_test (comparison (expr (atom ' ')))))))) ) -> (test (logical_test (comparison (expr (atom None))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name sep)) (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name args)))))))) ))))))))) )))) + (expr (atom (name end))))))))) )))))))))))))) operation Solve() pre: true post: true activity: var r1 : OclAny := null; var r2 : OclAny := null; Sequence{r1,r2} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c1 : OclAny := null; var c2 : OclAny := null; Sequence{c1,c2} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d1 : OclAny := null; var d2 : OclAny := null; Sequence{d1,d2} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a1 : int := (d1 + c1 - r2) div 2 ; var a2 : double := r1 - a1 ; var a3 : double := c1 - a1 ; var a4 : double := d1 - a1 ; if a1 = a2 or a1 = a3 or a1 = a4 or a2 = a3 or a2 = a4 or a3 = a4 or 1 > a1 or a1 > 9 or 1 > a2 or a2 > 9 or 1 > a3 or a3 > 9 or 1 > a4 or a4 > 9 then ( execute (-1)->display() ) else ( execute (a1)->display() ; execute (a3)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isDivisible(n): while n//100 : d=n % 10 n//=10 n=abs(n+(d*13)) return(n % 43==0) if __name__=="__main__" : N=2795 if(isDivisible(N)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var N : int := 2795 ; if (isDivisible(N)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isDivisible(n : OclAny) : OclAny pre: true post: true activity: while n div 100 do ( var d : int := n mod 10 ; n := n div 10 ; n := (n + (d * 13))->abs()) ; return (n mod 43 = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isDivisible(n): while n//100 : d=n % 10 n//=10 n=abs(n-(d*14)) return(n % 47==0) if __name__=="__main__" : n=59173 if(isDivisible(n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 59173 ; if (isDivisible(n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isDivisible(n : OclAny) : OclAny pre: true post: true activity: while n div 100 do ( var d : int := n mod 10 ; n := n div 10 ; n := (n - (d * 14))->abs()) ; return (n mod 47 = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isDivisible(n): while n//100 : d=n % 10 n//=10 n=abs(n-(d*7)) return(n % 71==0) if __name__=="__main__" : N=5041 if(isDivisible(N)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var N : int := 5041 ; if (isDivisible(N)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isDivisible(n : OclAny) : OclAny pre: true post: true activity: while n div 100 do ( var d : int := n mod 10 ; n := n div 10 ; n := (n - (d * 7))->abs()) ; return (n mod 71 = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isDivisible(n): while n//100 : d=n % 10 n//=10 n=abs(n-(d*3)) return(n % 31==0) if __name__=="__main__" : n=1922 if(isDivisible(n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 1922 ; if (isDivisible(n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isDivisible(n : OclAny) : OclAny pre: true post: true activity: while n div 100 do ( var d : int := n mod 10 ; n := n div 10 ; n := (n - (d * 3))->abs()) ; return (n mod 31 = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Odd_Sum(n): total=(n+1)//2 odd=total*total return odd def Even_Sum(n): total=n//2 even=total*(total+1) return even def sumLtoR(L,R): odd_sum=Odd_Sum(R)-Odd_Sum(L-1) even_sum=Even_Sum(R)-Even_Sum(L-1) return even_sum-odd_sum L=1 ; R=5 print(sumLtoR(L,R)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; L := 1; R := 5 ; execute (sumLtoR(L, R))->display(); operation Odd_Sum(n : OclAny) : OclAny pre: true post: true activity: var total : int := (n + 1) div 2 ; var odd : int := total * total ; return odd; operation Even_Sum(n : OclAny) : OclAny pre: true post: true activity: total := n div 2 ; var even : int := total * (total + 1) ; return even; operation sumLtoR(L : OclAny, R : OclAny) : OclAny pre: true post: true activity: var odd_sum : double := Odd_Sum(R) - Odd_Sum(L - 1) ; var even_sum : double := Even_Sum(R) - Even_Sum(L - 1) ; return even_sum - odd_sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def test(ch): l=ch.split(" ") a=int(l[0]) b=int(l[1]) k=int(l[2]) if k % 2==0 : e=k//2 return(e*a-e*b) else : f=k//2+1 g=k//2 return(f*a-g*b) x=int(input()) for i in range(x): ch=input() print(test(ch)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, x-1) do ( ch := (OclFile["System.in"]).readLine() ; execute (test(ch))->display()); operation test(ch : OclAny) : OclAny pre: true post: true activity: var l : OclAny := ch.split(" ") ; var a : int := ("" + ((l->first())))->toInteger() ; var b : int := ("" + ((l[1+1])))->toInteger() ; var k : int := ("" + ((l[2+1])))->toInteger() ; if k mod 2 = 0 then ( var e : int := k div 2 ; return (e * a - e * b) ) else ( var f : int := k div 2 + 1 ; var g : int := k div 2 ) ; return (f * a - g * b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in '0'*int(input()): a,b,k=map(int,input().split()) print(k//2*(a-b)+k % 2*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : StringLib.nCopies('0', ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var a : OclAny := null; var b : OclAny := null; var k : OclAny := null; Sequence{a,b,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (k div 2 * (a - b) + k mod 2 * a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bitadd(a,w,bit): x=a while x<=(len(bit)-1): bit[x]+=w x+=x &(-1*x) def bitsum(a,bit): ret=0 x=a while x>0 : ret+=bit[x] x-=x &(-1*x) return ret def updiv(a,b): if a % b==0 : return a//b else : return a//b+1 def want(x): lis=[] for i in a : if i>=x : lis.append(1) else : lis.append(-1) slis=[0] for i in lis : slis.append(slis[-1]+i) dic={} nlis=[] for i in slis : if i not in dic : dic[i]=None nlis.append(i) nlis.sort() for i in range(len(nlis)): dic[nlis[i]]=i+1 ans=0 BIT=[0]*(len(nlis)+1) for i in slis : j=dic[i] ans+=bitsum(j,BIT) bitadd(j,1,BIT) return ans N=int(input()) a=list(map(int,input().split())) l=1 r=max(a)+1 while r-l!=1 : m=(l+r)//2 mnum=want(m) if mnum>=updiv((N**2+N)//2,2): l=m else : r=m print(l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : int := 1 ; var r : OclAny := (a)->max() + 1 ; while r - l /= 1 do ( var m : int := (l + r) div 2 ; var mnum : OclAny := want(m) ; if (mnum->compareTo(updiv(((N)->pow(2) + N) div 2, 2))) >= 0 then ( l := m ) else ( r := m )) ; execute (l)->display(); operation bitadd(a : OclAny, w : OclAny, bit : OclAny) pre: true post: true activity: var x : OclAny := a ; while (x->compareTo(((bit)->size() - 1))) <= 0 do ( bit[x+1] := bit[x+1] + w ; x := x + MathLib.bitwiseAnd(x, (-1 * x))); operation bitsum(a : OclAny, bit : OclAny) : OclAny pre: true post: true activity: var ret : int := 0 ; x := a ; while x > 0 do ( ret := ret + bit[x+1] ; x := x - MathLib.bitwiseAnd(x, (-1 * x))) ; return ret; operation updiv(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a mod b = 0 then ( return a div b ) else ( return a div b + 1 ); operation want(x : OclAny) : OclAny pre: true post: true activity: var lis : Sequence := Sequence{} ; for i : a do ( if (i->compareTo(x)) >= 0 then ( execute ((1) : lis) ) else ( execute ((-1) : lis) )) ; var slis : Sequence := Sequence{ 0 } ; for i : lis do ( execute ((slis->last() + i) : slis)) ; var dic : OclAny := Set{} ; var nlis : Sequence := Sequence{} ; for i : slis do ( if (dic)->excludes(i) then ( dic[i+1] := null ; execute ((i) : nlis) ) else skip) ; nlis := nlis->sort() ; for i : Integer.subrange(0, (nlis)->size()-1) do ( dic[nlis[i+1]+1] := i + 1) ; var ans : int := 0 ; var BIT : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((nlis)->size() + 1)) ; for i : slis do ( var j : OclAny := dic[i+1] ; ans := ans + bitsum(j, BIT) ; bitadd(j, 1, BIT)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input("")) for i in range(t): a,b,c=map(int,input().split()) ans=0 if(c % 2==0): ans=(a*(c//2))-(b*(c//2)) else : ans=(a*(c//2+1))-(b*(c//2)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine(""))))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; if (c mod 2 = 0) then ( ans := (a * (c div 2)) - (b * (c div 2)) ) else ( ans := (a * (c div 2 + 1)) - (b * (c div 2)) ) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): frwrd,bcwrd,nmbr=map(int,input().split()) if nmbr % 2==1 : p=(frwrd-bcwrd)*((nmbr-1)//2)+frwrd print(p) else : p=(frwrd-bcwrd)*(nmbr//2) print(p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var frwrd : OclAny := null; var bcwrd : OclAny := null; var nmbr : OclAny := null; Sequence{frwrd,bcwrd,nmbr} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if nmbr mod 2 = 1 then ( var p : double := (frwrd - bcwrd) * ((nmbr - 1) div 2) + frwrd ; execute (p)->display() ) else ( p := (frwrd - bcwrd) * (nmbr div 2) ; execute (p)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) for x in range(a): b,c,d=map(int,input().split()) otv=0-c*(d//2) if d % 2==0 : otv+=b*(d//2) else : otv+=b*(d//2+1) print(otv) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for x : Integer.subrange(0, a-1) do ( var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var otv : double := 0 - c * (d div 2) ; if d mod 2 = 0 then ( otv := otv + b * (d div 2) ) else ( otv := otv + b * (d div 2 + 1) ) ; execute (otv)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r1,r2=map(int,input().split()) c1,c2=map(int,input().split()) d1,d2=map(int,input().split()) a=(2*r1+2*d1+2*c1-d2-c2-r2)/6 if a<=0 or a!=int(a): print(-1) else : a=int(a) b=r1-a c=c1-a d=d1-a valid=True values=set([1,2,3,4,5,6,7,8,9]) if a not in values : valid=False else : values.remove(a) if b not in values : valid=False else : values.remove(b) if c not in values : valid=False else : values.remove(c) if d not in values : valid=False else : values.remove(d) if valid : print(a,b) print(c,d) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r1 : OclAny := null; var r2 : OclAny := null; Sequence{r1,r2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c1 : OclAny := null; var c2 : OclAny := null; Sequence{c1,c2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d1 : OclAny := null; var d2 : OclAny := null; Sequence{d1,d2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : double := (2 * r1 + 2 * d1 + 2 * c1 - d2 - c2 - r2) / 6 ; if a <= 0 or a /= ("" + ((a)))->toInteger() then ( execute (-1)->display() ) else ( a := ("" + ((a)))->toInteger() ; var b : double := r1 - a ; var c : double := c1 - a ; var d : double := d1 - a ; var valid : boolean := true ; var values : Set := Set{}->union((Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 9 })))))))))) ; if (values)->excludes(a) then ( valid := false ) else ( execute ((a) /: values) ) ; if (values)->excludes(b) then ( valid := false ) else ( execute ((b) /: values) ) ; if (values)->excludes(c) then ( valid := false ) else ( execute ((c) /: values) ) ; if (values)->excludes(d) then ( valid := false ) else ( execute ((d) /: values) ) ; if valid then ( execute (a)->display() ; execute (c)->display() ) else ( execute (-1)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isRatioPossible(lowCost,upCost,lowQuant,upQuant,r): for i in range(lowQuant,upQuant+1): ans=i*r if(lowCost<=ans and ans<=upCost): return True return False lowCost=14 ; upCost=30 lowQuant=5 ; upQuant=12 ; r=9 if(isRatioPossible(lowCost,upCost,lowQuant,upQuant,r)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; lowCost := 14; upCost := 30 ; lowQuant := 5; upQuant := 12; r := 9 ; if (isRatioPossible(lowCost, upCost, lowQuant, upQuant, r)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isRatioPossible(lowCost : OclAny, upCost : OclAny, lowQuant : OclAny, upQuant : OclAny, r : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(lowQuant, upQuant + 1-1) do ( var ans : double := i * r ; if ((lowCost->compareTo(ans)) <= 0 & (ans->compareTo(upCost)) <= 0) then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def Log2(x): if x==0 : return false ; return(math.log10(x)/math.log10(2)); def isPowerOfTwo(n): return(math.ceil(Log2(n))==math.floor(Log2(n))); if(isPowerOfTwo(31)): print("Yes"); else : print("No"); if(isPowerOfTwo(64)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if (isPowerOfTwo(31)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ; if (isPowerOfTwo(64)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ); operation Log2(x : OclAny) pre: true post: true activity: if x = 0 then ( return false; ) else skip ; return ((x)->log10() / (2)->log10());; operation isPowerOfTwo(n : OclAny) pre: true post: true activity: return ((Log2(n))->ceil() = (Log2(n))->floor());; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): LIMIT=50000000 primes=eulerlib.list_primes(eulerlib.sqrt(LIMIT)) sums={0} for i in range(2,5): newsums=set() for p in primes : q=p**i if q>LIMIT : break for x in sums : if x+q<=LIMIT : newsums.add(x+q) sums=newsums return str(len(sums)) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LIMIT : int := 50000000 ; var primes : OclAny := eulerlib.list_primes(eulerlib.sqrt(LIMIT)) ; var sums : Set := Set{ 0 } ; for i : Integer.subrange(2, 5-1) do ( var newsums : Set := Set{}->union(()) ; for p : primes do ( var q : double := (p)->pow(i) ; if (q->compareTo(LIMIT)) > 0 then ( break ) else skip ; for x : sums do ( if (x + q->compareTo(LIMIT)) <= 0 then ( execute ((x + q) : newsums) ) else skip)) ; sums := newsums) ; return ("" + (((sums)->size()))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def longLenSub(arr,n): um=defaultdict(lambda : 0) longLen=0 for i in range(n): len1=0 if(arr[i-1]in um and len1toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (a + b)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): print(sum([int(i)for i in input().split()])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute ((input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())))->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) l=list(map(int,input().split())) l2=[] for i in l : if i % m==0 : l2.append(i//m) else : l2.append(i//m+1) mx=max(l2) for i in range(n): if l2[i]==mx : ind=i print(ind+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l2 : Sequence := Sequence{} ; for i : l do ( if i mod m = 0 then ( execute ((i div m) : l2) ) else ( execute ((i div m + 1) : l2) )) ; var mx : OclAny := (l2)->max() ; for i : Integer.subrange(0, n-1) do ( if l2[i+1] = mx then ( var ind : OclAny := i ) else skip) ; execute (ind + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h=int(input()) for x in range(h): a,b=map(int,input().split()) print(a+b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for x : Integer.subrange(0, h-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (a + b)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: print(sum(map(int,s.split()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( execute (((s.split())->collect( _x | (OclType["int"])->apply(_x) ))->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys II=lambda : int(input()) LI=lambda : list(map(int,list(input().split(" ")))) MI=lambda : map(int,LI()) SI=lambda : input() s=II() for i in range(s): a,b=MI() print(a+b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var II : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var LI : Function := lambda $$ : OclAny in ((((input().split(" ")))->collect( _x | (OclType["int"])->apply(_x) ))) ; var MI : Function := lambda $$ : OclAny in ((LI->apply())->collect( _x | (OclType["int"])->apply(_x) )) ; var SI : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var s : OclAny := II->apply() ; for i : Integer.subrange(0, s-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := MI->apply() ; execute (a + b)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculateSum(n): sum=0 sum=1<display(); operation calculateSum(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; sum := 1 * (2->pow(n)); ; return (sum - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left,bisect_right while True : n,m=map(int,input().split()) if n==m==0 : break a=list(map(int,input().split())) w=list(map(int,input().split())) Set=set() def go(i,weight): if i==m : Set.add(weight) return go(i+1,weight) go(i+1,weight+w[i]) go(i+1,weight-w[i]) go(0,0) ans=False for i in a : if i not in Set : if ans==False : ans=set(abs(s-i)for s in Set) else : ans=set(s for s in ans if i+s in Set or i-s in Set) if ans==False : print(0) continue elif len(ans)==0 : print(-1) continue else : print(min(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = m & (m == 0) then ( break ) else skip ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var Set : Set := Set{}->union(()) ; skip ; go(0, 0) ; var ans : boolean := false ; for i : a do ( if (Set)->excludes(i) then ( if ans = false then ( ans := Set{}->union(((argument (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name s))) - (expr (atom (name i))))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name Set))))))))) ) else ( ans := Set{}->union(((argument (test (logical_test (comparison (expr (atom (name s)))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name ans))))) (comp_iter if (test (logical_test (logical_test (comparison (comparison (expr (expr (atom (name i))) + (expr (atom (name s))))) in (comparison (expr (atom (name Set)))))) or (logical_test (comparison (comparison (expr (expr (atom (name i))) - (expr (atom (name s))))) in (comparison (expr (atom (name Set))))))))))))) ) ) else skip) ; if ans = false then ( execute (0)->display() ; continue ) else (if (ans)->size() = 0 then ( execute (-1)->display() ; continue ) else ( execute ((ans)->min())->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculateSum(n): sum=0 for row in range(n): sum=sum+(1<display(); operation calculateSum(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for row : Integer.subrange(0, n-1) do ( sum := sum + (1 * (2->pow(row)))) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxDiff(arr,n): diff=arr[1]-arr[0] curr_sum=diff max_sum=curr_sum for i in range(1,n-1): diff=arr[i+1]-arr[i] if(curr_sum>0): curr_sum+=diff else : curr_sum=diff if(curr_sum>max_sum): max_sum=curr_sum return max_sum if __name__=='__main__' : arr=[80,2,6,3,100] n=len(arr) print("Maximum difference is",maxDiff(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{80}->union(Sequence{2}->union(Sequence{6}->union(Sequence{3}->union(Sequence{ 100 })))) ; n := (arr)->size() ; execute ("Maximum difference is")->display() ) else skip; operation maxDiff(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var diff : double := arr[1+1] - arr->first() ; var curr_sum : OclAny := diff ; var max_sum : OclAny := curr_sum ; for i : Integer.subrange(1, n - 1-1) do ( diff := arr[i + 1+1] - arr[i+1] ; if (curr_sum > 0) then ( curr_sum := curr_sum + diff ) else ( curr_sum := diff ) ; if ((curr_sum->compareTo(max_sum)) > 0) then ( max_sum := curr_sum ) else skip) ; return max_sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f3(n): a=b=c=0 for _ in range(n): a,b,c=(a+b+c+1)% 100000007,a,b return a def f5(n): a=b=c=d=e=0 for _ in range(n): a,b,c,d,e=(a+b+c+d+e+1)% 100000007,a,b,c,d return a while 1 : s=input() if s=="#" : break ans=1 num="_" cnt=1 for n in s+"_" : if n==num : cnt+=1 else : if num in "80" : ans=ans*f3(cnt)% 100000007 else : ans=ans*f5(cnt)% 100000007 num=n cnt=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while 1 do ( var s : String := (OclFile["System.in"]).readLine() ; if s = "#" then ( break ) else skip ; var ans : int := 1 ; var num : String := "_" ; var cnt : int := 1 ; for n : s + "_" do ( if n = num then ( cnt := cnt + 1 ) else ( if ("80")->characters()->includes(num) then ( ans := ans * f3(cnt) mod 100000007 ) else ( ans := ans * f5(cnt) mod 100000007 ) ; num := n ; cnt := 1 )) ; execute (ans)->display()); operation f3(n : OclAny) : OclAny pre: true post: true activity: a := a(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{(a + b + c + 1) mod 100000007,a,b}) ; return a; operation f5(n : OclAny) : OclAny pre: true post: true activity: a := a(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name e)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; Sequence{a,b,c,d,e} := Sequence{(a + b + c + d + e + 1) mod 100000007,a,b,c,d}) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairs(n): num=((n//2)+1) Max=n % num count=0 for i in range(1,n+1): for j in range(1,n+1): val=((n % i)% j)% n if(val==Max): count+=1 return count n=5 print(countPairs(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; execute (countPairs(n))->display(); operation countPairs(n : OclAny) : OclAny pre: true post: true activity: var num : int := ((n div 2) + 1) ; var Max : int := n mod num ; var count : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, n + 1-1) do ( var val : int := ((n mod i) mod j) mod n ; if (val = Max) then ( count := count + 1 ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input().strip() l=len(n) x=[0]*l for i in range(l-1): if i==0 : x[i]=0 else : x[i]=x[i-1] if n[i]==n[i+1]: x[i]+=1 ; for m in range(int(input())): y,z=map(int,input().split()) if y==1 : print(x[z-2]) else : print(x[z-2]-x[y-2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := input()->trim() ; var l : int := (n)->size() ; var x : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, l) ; for i : Integer.subrange(0, l - 1-1) do ( if i = 0 then ( x[i+1] := 0 ) else ( x[i+1] := x[i - 1+1] ) ; if n[i+1] = n[i + 1+1] then ( x[i+1] := x[i+1] + 1; ) else skip) ; for m : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var y : OclAny := null; var z : OclAny := null; Sequence{y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if y = 1 then ( execute (x[z - 2+1])->display() ) else ( execute (x[z - 2+1] - x[y - 2+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Fenwick : def __init__(self,size): self.arr=[0]*size def update(self,i,val): while i=0 : res+=self.arr[i]; i=(i &(i+1))-1 return res def paramin(F,l,r): while l<=r : mid=(l+r)//2 if F(mid): ans,r=mid,mid-1 else : l=mid+1 return ans from itertools import accumulate def medleq(i): x=vals[i] M=[(y<=x)*2-1 for y in L] MA=list(accumulate(M)) cnt=sum(y>0 for y in MA) F=Fenwick(2*n+3) for y in MA : c=y+n+1 cnt+=F.getsum(c-1) F.update(c,1) return cnt>=target n=int(input()) L=list(map(int,input().split())) tot=n+n*(n-1)//2 target=tot//2+1 vals=sorted(set(L)) print(vals[paramin(medleq,0,len(vals)-1)]) ------------------------------------------------------------ OCL File: --------- class Fenwick { static operation newFenwick() : Fenwick pre: true post: Fenwick->exists( _x | result = _x ); attribute arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, size); operation initialise(size : OclAny) : Fenwick pre: true post: true activity: self.arr := MatrixLib.elementwiseMult(Sequence{ 0 }, size); return self; operation update(i : OclAny,val : OclAny) pre: true post: true activity: while (i->compareTo((self.arr)->size())) < 0 do ( self.arr[i+1] := self.arr[i+1] + val; i := i or i + 1); operation getsum(i : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; while i >= 0 do ( res := res + self.arr[i+1]; i := (MathLib.bitwiseAnd(i, (i + 1))) - 1) ; return res; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var L : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var tot : int := n + n * (n - 1) div 2 ; var target : int := tot div 2 + 1 ; var vals : Sequence := Set{}->union((L))->sort() ; execute (vals[paramin(medleq, 0, (vals)->size() - 1)+1])->display(); operation paramin(F : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: while (l->compareTo(r)) <= 0 do ( var mid : int := (l + r) div 2 ; if F(mid) then ( var ans : OclAny := null; Sequence{ans,r} := Sequence{mid,mid - 1} ) else ( l := mid + 1 )) ; return ans; operation medleq(i : OclAny) : OclAny pre: true post: true activity: var x : OclAny := vals[i+1] ; var M : Sequence := L->select(y | true)->collect(y | (((y->compareTo(x)) <= 0) * 2 - 1)) ; var MA : Sequence := (accumulate(M)) ; var cnt : OclAny := ((argument (test (logical_test (comparison (comparison (expr (atom (name y)))) > (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name MA))))))))->sum() ; F := (Fenwick.newFenwick()).initialise(2 * n + 3) ; for y : MA do ( var c : OclAny := y + n + 1 ; cnt := cnt + F.getsum(c - 1) ; execute ((c, 1) <: F)) ; return (cnt->compareTo(target)) >= 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- soz=input() a=[0]*(len(soz)+1) for i in range(1,len(soz)): a[i]=a[i-1] if soz[i-1]==soz[i]: a[i]+=1 n=int(input()) arr=[] for i in range(n): m,l=input().split() arr.append(a[int(l)-1]-a[int(m)-1]) for i in arr : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var soz : String := (OclFile["System.in"]).readLine() ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((soz)->size() + 1)) ; for i : Integer.subrange(1, (soz)->size()-1) do ( a[i+1] := a[i - 1+1] ; if soz[i - 1+1] = soz[i+1] then ( a[i+1] := a[i+1] + 1 ) else skip) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var m : OclAny := null; var l : OclAny := null; Sequence{m,l} := input().split() ; execute ((a[("" + ((l)))->toInteger() - 1+1] - a[("" + ((m)))->toInteger() - 1+1]) : arr)) ; for i : arr do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() n=int(input()) b=[0]*len(s) c=0 for i in range(len(s)): b[i]=c if itoInteger() ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (s)->size()) ; var c : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( b[i+1] := c ; if (i->compareTo((s)->size() - 1)) < 0 & s[i+1] = s[i + 1+1] then ( c := c + 1 ) else skip) ; for _anon : Integer.subrange(0, n-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (b[r - 1+1] - b[l - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() n=int(input()) ps=[0]*(len(s)+1) for i in range(1,len(s)): if s[i]==s[i-1]: ps[i]=ps[i-1]+1 else : ps[i]=ps[i-1] while n!=0 : n-=1 a,b=map(int,input().split()) print(ps[b-1]-ps[a-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ps : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((s)->size() + 1)) ; for i : Integer.subrange(1, (s)->size()-1) do ( if s[i+1] = s[i - 1+1] then ( ps[i+1] := ps[i - 1+1] + 1 ) else ( ps[i+1] := ps[i - 1+1] )) ; while n /= 0 do ( n := n - 1 ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (ps[b - 1+1] - ps[a - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ilya_queries(s : str): counter=0 l=[0]*100005 for i in range(1,len(s)): if s[i]==s[i-1]: counter+=1 l[i]=counter m=int(input()) for _ in range(m): lo,r=map(int,input().split()) print(l[r-1]-l[lo-1]) s=input() ilya_queries(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : String := (OclFile["System.in"]).readLine() ; ilya_queries(s); operation ilya_queries(s : String) pre: true post: true activity: var counter : int := 0 ; var l : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100005) ; for i : Integer.subrange(1, (s)->size()-1) do ( if s[i+1] = s[i - 1+1] then ( counter := counter + 1 ) else skip ; l[i+1] := counter) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, m-1) do ( var lo : OclAny := null; var r : OclAny := null; Sequence{lo,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (l[r - 1+1] - l[lo - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): from sys import stdin f_i=stdin def rec(i): if i==0 : return 0 tray=cups[n-i] if tray=='A' : return rec(i-1) elif tray=='B' : return 2*3**(i-1)-1-rec(i-1) else : return rec(i-1)+2*3**(i-1) while True : n,m=map(int,f_i.readline().split()) if n==0 : break cups=[None]*n for tray in 'ABC' : itr=map(int,f_i.readline().split()) next(itr) for i in itr : cups[i-1]=tray num=rec(n) ans=min(num,3**n-1-num) if ans<=m : print(ans) else : print(-1) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: skip ; var f_i : OclAny := stdin ; skip ; while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (f_i.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var cups : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; for tray : 'ABC'->characters() do ( var itr : Sequence := (f_i.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; next(itr) ; for i : itr do ( cups[i - 1+1] := tray)) ; var num : OclAny := rec(n) ; var ans : OclAny := Set{num, (3)->pow(n) - 1 - num}->min() ; if (ans->compareTo(m)) <= 0 then ( execute (ans)->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,m=list(map(int,input().split())) if n==0 and m==0 : break medicines=set(map(int,input().split())) weights=list(map(int,input().split())) possibles={0} for i in weights : pre=possibles.copy() for j in possibles : plus=i+j minus=abs(i-j) pre.add(plus) pre.add(minus) possibles=pre possibles.discard(0) medicines-=possibles if len(medicines)==0 : print(0) continue add=[] for i in medicines : pre_add={0} for j in possibles : plus=i+j minus=abs(i-j) pre_add.add(plus) pre_add.add(minus) pre_add.add(i) pre_add.discard(0) add.append(pre_add) ans=add[0] for i in add : pre_ans=ans & i ans=pre_ans ans_list=[] for i in ans : ans_list.append(i) if len(ans_list)==0 : print(-1) elif len(ans_list)==1 : print(ans_list[0]) else : print(min(ans_list)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = 0 & m = 0 then ( break ) else skip ; var medicines : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var weights : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var possibles : Set := Set{ 0 } ; for i : weights do ( var pre : OclAny := possibles->copy() ; for j : possibles do ( var plus : OclAny := i + j ; var minus : double := (i - j)->abs() ; execute ((plus) : pre) ; execute ((minus) : pre)) ; possibles := pre) ; execute ((0) /: possibles) ; medicines := medicines - possibles ; if (medicines)->size() = 0 then ( execute (0)->display() ; continue ) else skip ; var add : Sequence := Sequence{} ; for i : medicines do ( var pre_add : Set := Set{ 0 } ; for j : possibles do ( plus := i + j ; minus := (i - j)->abs() ; execute ((plus) : pre_add) ; execute ((minus) : pre_add) ; execute ((i) : pre_add) ; execute ((0) /: pre_add)) ; execute ((pre_add) : add)) ; var ans : OclAny := add->first() ; for i : add do ( var pre_ans : int := MathLib.bitwiseAnd(ans, i) ; ans := pre_ans) ; var ans_list : Sequence := Sequence{} ; for i : ans do ( execute ((i) : ans_list)) ; if (ans_list)->size() = 0 then ( execute (-1)->display() ) else (if (ans_list)->size() = 1 then ( execute (ans_list->first())->display() ) else ( execute ((ans_list)->min())->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,radians from itertools import permutations,combinations,product,accumulate from operator import itemgetter,mul from copy import deepcopy from string import ascii_lowercase,ascii_uppercase,digits from fractions import gcd def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) sys.setrecursionlimit(10**9) INF=float('inf') mod=10**9+7 ans=[] while 1 : n,m=MAP() if n==0 and m==0 : break A=LIST() B=LIST() C=LIST() A=A[1 :] B=B[1 :] C=C[1 :] goal=defaultdict(int) for i in A : goal[n-i]=0 for i in B : goal[n-i]=1 for i in C : goal[n-i]=2 p=0 x=0 for i in range(n-1,-1,-1): d=abs(p-goal[i]) x+=d*(3**i) if d==1 : p=2-p tmp=min(x,3**n-1-x) if tmp<=m : ans.append(tmp) else : ans.append(-1) for i in ans : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var ans : Sequence := Sequence{} ; while 1 do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := MAP() ; if n = 0 & m = 0 then ( break ) else skip ; var A : OclAny := LIST() ; var B : OclAny := LIST() ; var C : OclAny := LIST() ; A := A->tail() ; B := B->tail() ; C := C->tail() ; var goal : OclAny := defaultdict(OclType["int"]) ; for i : A do ( goal[n - i+1] := 0) ; for i : B do ( goal[n - i+1] := 1) ; for i : C do ( goal[n - i+1] := 2) ; var p : int := 0 ; var x : int := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( var d : double := (p - goal[i+1])->abs() ; x := x + d * ((3)->pow(i)) ; if d = 1 then ( p := 2 - p ) else skip) ; var tmp : OclAny := Set{x, (3)->pow(n) - 1 - x}->min() ; if (tmp->compareTo(m)) <= 0 then ( execute ((tmp) : ans) ) else ( execute ((-1) : ans) )) ; for i : ans do ( execute (i)->display()); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline from collections import deque def main(): while True : N,M=map(int,readline().rstrip().split()) if N==M==0 : break _,*A=map(int,readline().rstrip().split()) _,*B=map(int,readline().rstrip().split()) _,*C=map(int,readline().rstrip().split()) A=[0]+A B=[0]+B C=[0]+C N+=1 que=deque([(A,B,C,0,-1)]) res=-1 while que : A,B,C,t,pre=que.popleft() if t>M : break if len(A)==N or len(C)==N : res=t break if A[-1]>B[-1]and pre!=2 : que.append((A[:-1],B+[A[-1]],C,t+1,1)) if B[-1]>A[-1]and pre!=1 : que.append((A+[B[-1]],B[:-1],C,t+1,2)) if B[-1]>C[-1]and pre!=4 : que.append((A,B[:-1],C+[B[-1]],t+1,3)) if C[-1]>B[-1]and pre!=3 : que.append((A,B+[C[-1]],C[:-1],t+1,4)) print(res) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: while true do ( var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (readline().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if N = M & (M == 0) then ( break ) else skip ; var _anon : OclAny := null; var A : OclAny := null; Sequence{_anon,A} := (readline().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var _anon : OclAny := null; var B : OclAny := null; Sequence{_anon,B} := (readline().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var _anon : OclAny := null; var C : OclAny := null; Sequence{_anon,C} := (readline().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := Sequence{ 0 }->union(A) ; var B : Sequence := Sequence{ 0 }->union(B) ; var C : Sequence := Sequence{ 0 }->union(C) ; N := N + 1 ; var que : Sequence := (Sequence{ Sequence{A, B, C, 0, -1} }) ; var res : int := -1 ; while que do ( var t : OclAny := null; var pre : OclAny := null; Sequence{A,B,C,t,pre} := que->first() ; que := que->tail() ; if (t->compareTo(M)) > 0 then ( break ) else skip ; if (A)->size() = N or (C)->size() = N then ( res := t ; break ) else skip ; if (A->last()->compareTo(B->last())) > 0 & pre /= 2 then ( execute ((Sequence{A->front(), B->union(Sequence{ A->last() }), C, t + 1, 1}) : que) ) else skip ; if (B->last()->compareTo(A->last())) > 0 & pre /= 1 then ( execute ((Sequence{A->union(Sequence{ B->last() }), B->front(), C, t + 1, 2}) : que) ) else skip ; if (B->last()->compareTo(C->last())) > 0 & pre /= 4 then ( execute ((Sequence{A, B->front(), C->union(Sequence{ B->last() }), t + 1, 3}) : que) ) else skip ; if (C->last()->compareTo(B->last())) > 0 & pre /= 3 then ( execute ((Sequence{A, B->union(Sequence{ C->last() }), C->front(), t + 1, 4}) : que) ) else skip) ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import sys if os.getenv("LOCAL"): sys.stdin=open("_in.txt","r") sys.setrecursionlimit(2147483647) INF=float("inf") IINF=10**18 MOD=10**9+7 def solve(N,M,A,B,C,ab): A=[0]+A B=[0]+B C=[0]+C for i in range(M+1): if len(A)==N+1 or len(C)==N+1 : return i if ab : if A[-1]toReal() ; var IINF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; skip ; while true do ( Sequence{N,M} := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if N = M & (M == 0) then ( break ) else skip ; var _anon : OclAny := null; var A : OclAny := null; Sequence{_anon,A} := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var _anon : OclAny := null; var B : OclAny := null; Sequence{_anon,B} := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var _anon : OclAny := null; var C : OclAny := null; Sequence{_anon,C} := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s1 : OclAny := solve(N, M, A, B, C, true) ; var s2 : OclAny := solve(N, M, A, B, C, false) ; var ans : OclAny := Set{s1, s2}->min() ; if (ans->compareTo(M)) <= 0 then ( execute (ans)->display() ) else ( execute (-1)->display() )); operation solve(N : OclAny, M : OclAny, A : OclAny, B : OclAny, C : OclAny, ab : OclAny) : OclAny pre: true post: true activity: A := Sequence{ 0 }->union(A) ; B := Sequence{ 0 }->union(B) ; C := Sequence{ 0 }->union(C) ; for i : Integer.subrange(0, M + 1-1) do ( if (A)->size() = N + 1 or (C)->size() = N + 1 then ( return i ) else skip ; if ab then ( if (A->last()->compareTo(B->last())) < 0 then ( execute ((B->last()) : A) ) else ( execute ((A->last()) : B) ) ) else ( if (C->last()->compareTo(B->last())) < 0 then ( execute ((B->last()) : C) ) else ( execute ((C->last()) : B) ) ) ; ab := not(ab)) ; return IINF; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : n,m=map(int,input().split()) l=[0 for i in range(n)] for i in range(3): s=list(map(int,input().split())) for j in s[1 :]: l[j-1]=i ans=100000000 for pos in[0,2]: count=0 for i in range(n): if abs(l[i]-pos)==2 : count+=2*3**(n-i-1) elif pos==1 and l[i]==0 : count+=(3**(n-i-1)-1)//2 pos=2 elif pos==1 and l[i]==2 : count+=(3**(n-i-1)-1)//2 pos=0 elif pos==0 and l[i]==1 : count+=3**(n-i-1) pos=2 elif pos==2 and l[i]==1 : count+=3**(n-i-1) pos=0 ans=min(count,ans) if(ans<=m): print(ans) else : print(-1) except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, 3-1) do ( var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : s->tail() do ( l[j - 1+1] := i)) ; var ans : int := 100000000 ; for pos : Sequence{0}->union(Sequence{ 2 }) do ( var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (l[i+1] - pos)->abs() = 2 then ( count := count + 2 * (3)->pow((n - i - 1)) ) else (if pos = 1 & l[i+1] = 0 then ( count := count + ((3)->pow((n - i - 1)) - 1) div 2 ; var pos : int := 2 ) else (if pos = 1 & l[i+1] = 2 then ( count := count + ((3)->pow((n - i - 1)) - 1) div 2 ; pos := 0 ) else (if pos = 0 & l[i+1] = 1 then ( count := count + (3)->pow((n - i - 1)) ; pos := 2 ) else (if pos = 2 & l[i+1] = 1 then ( count := count + (3)->pow((n - i - 1)) ; pos := 0 ) else skip ) ) ) ) ) ; ans := Set{count, ans}->min()) ; if ((ans->compareTo(m)) <= 0) then ( execute (ans)->display() ) else ( execute (-1)->display() )) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000,10**9)) write=lambda x : sys.stdout.write(x+"\n") def init(bit,values): for i,v in enumerate(values): update(bit,i,v) def query(bit,i): res_sum=0 while i>0 : res_sum+=bit[i] i-=i &(-i) return res_sum def update(bit,i,x): while i<=len(bit)-1 : bit[i]+=x i+=i &(-i) return n=int(input()) a=list(map(int,input().split())) from collections import Counter def sub(x): cumsum=[None]*n cumsum[0]=1 if a[0]>=x else-1 for i in range(1,n): cumsum[i]=cumsum[i-1]+(1 if a[i]>=x else-1) bit=[0]*(2*n+2) update(bit,n+1,1) ans=0 for v in cumsum : ans+=query(bit,v+n+1) update(bit,n+v+1,1) return ans l=0 r=10**9+1 tmp=(n+1)*n//2 thre=tmp//2+tmp % 2 while l=thre : l=m else : r=m print(l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; sys.setrecursionlimit(Set{1000, (10)->pow(9)}->max()) ; var write : Function := lambda x : OclAny in ((OclFile["System.out"]).write(x + "\n")) ; skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; skip ; var l : int := 0 ; var r : double := (10)->pow(9) + 1 ; var tmp : int := (n + 1) * n div 2 ; var thre : int := tmp div 2 + tmp mod 2 ; while (l->compareTo(r - 1)) < 0 do ( var m : int := (l + r) div 2 ; if (sub(m)->compareTo(thre)) >= 0 then ( l := m ) else ( r := m )) ; execute (l)->display(); operation init(bit : OclAny, values : OclAny) pre: true post: true activity: for _tuple : Integer.subrange(1, (values)->size())->collect( _indx | Sequence{_indx-1, (values)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); update(bit, i, v)); operation query(bit : OclAny, i : OclAny) : OclAny pre: true post: true activity: var res_sum : int := 0 ; while i > 0 do ( res_sum := res_sum + bit[i+1] ; i := i - MathLib.bitwiseAnd(i, (-i))) ; return res_sum; operation update(bit : OclAny, i : OclAny, x : OclAny) pre: true post: true activity: while (i->compareTo((bit)->size() - 1)) <= 0 do ( bit[i+1] := bit[i+1] + x ; i := i + MathLib.bitwiseAnd(i, (-i))) ; return; operation sub(x : OclAny) : OclAny pre: true post: true activity: var cumsum : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; cumsum->first() := if (a->first()->compareTo(x)) >= 0 then 1 else -1 endif ; for i : Integer.subrange(1, n-1) do ( cumsum[i+1] := cumsum[i - 1+1] + (if (a[i+1]->compareTo(x)) >= 0 then 1 else -1 endif)) ; bit := MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * n + 2)) ; update(bit, n + 1, 1) ; var ans : int := 0 ; for v : cumsum do ( ans := ans + query(bit, v + n + 1) ; update(bit, n + v + 1, 1)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100000 def prints(g1,a,g2,b): for i in range(a): print(g1[i],end="") print("and ",end="") for i in range(b): print(g2[i],end="") print("\n",end="") def checksum(g1,a,g2,b): x=0 for i in range(0,a,1): x+=g1[i] for i in range(b): x-=g2[i] return(x==0) def formgroups(arr,x,g1,a,g2,b,n): if(x==n): if(checksum(g1,a,g2,b)): prints(g1,a,g2,b) return g1[a]=arr[x] formgroups(arr,x+1,g1,a+1,g2,b,n) g2[b]=arr[x] formgroups(arr,x+1,g1,a,g2,b+1,n) if __name__=='__main__' : arr=[1,2,3,9,4,5] n=len(arr) g1=[0 for i in range(MAX)] g2=[0 for i in range(MAX)] formgroups(arr,0,g1,0,g2,0,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 100000 ; skip ; skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{9}->union(Sequence{4}->union(Sequence{ 5 }))))) ; n := (arr)->size() ; g1 := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)) ; g2 := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)) ; formgroups(arr, 0, g1, 0, g2, 0, n) ) else skip; operation prints(g1 : OclAny, a : OclAny, g2 : OclAny, b : OclAny) pre: true post: true activity: for i : Integer.subrange(0, a-1) do ( execute (g1[i+1])->display()) ; execute ("and ")->display() ; for i : Integer.subrange(0, b-1) do ( execute (g2[i+1])->display()) ; execute ("\n")->display(); operation checksum(g1 : OclAny, a : OclAny, g2 : OclAny, b : OclAny) : OclAny pre: true post: true activity: var x : int := 0 ; for i : Integer.subrange(0, a-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( x := x + g1[i+1]) ; for i : Integer.subrange(0, b-1) do ( x := x - g2[i+1]) ; return (x = 0); operation formgroups(arr : OclAny, x : OclAny, g1 : OclAny, a : OclAny, g2 : OclAny, b : OclAny, n : OclAny) pre: true post: true activity: if (x = n) then ( if (checksum(g1, a, g2, b)) then ( prints(g1, a, g2, b) ) else skip ; return ) else skip ; g1[a+1] := arr[x+1] ; formgroups(arr, x + 1, g1, a + 1, g2, b, n) ; g2[b+1] := arr[x+1] ; formgroups(arr, x + 1, g1, a, g2, b + 1, n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cutRibbon(): arr=[int(i)for i in input().split()] length=arr[0] arr=sorted(arr[1 : 4],reverse=False) if(length % arr[0]==0): print(int(length/arr[0])) return ans=0 if(arr[0]==arr[1]): k=0 for i in range(int(length/arr[2])+1): check=length-i*arr[2] if(check>=0 and check % arr[0]==0): k=int(check/arr[0]) ans=max(ans,k+i) else : k=0 for i in range(int(length/arr[2])+1): for j in range(int(length/arr[1])+1): check=length-i*arr[2]-j*arr[1] if(check>=0 and check % arr[0]==0): k=int(check/arr[0]) ans=max(ans,k+i+j) print(ans) return cutRibbon() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; cutRibbon(); operation cutRibbon() pre: true post: true activity: var arr : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var length : OclAny := arr->first() ; arr := arr.subrange(1+1, 4)->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name False)))))))) ; if (length mod arr->first() = 0) then ( execute (("" + ((length / arr->first())))->toInteger())->display() ; return ) else skip ; var ans : int := 0 ; if (arr->first() = arr[1+1]) then ( var k : int := 0 ; for i : Integer.subrange(0, ("" + ((length / arr[2+1])))->toInteger() + 1-1) do ( var check : double := length - i * arr[2+1] ; if (check >= 0 & check mod arr->first() = 0) then ( k := ("" + ((check / arr->first())))->toInteger() ; ans := Set{ans, k + i}->max() ) else skip) ) else ( k := 0 ; for i : Integer.subrange(0, ("" + ((length / arr[2+1])))->toInteger() + 1-1) do ( for j : Integer.subrange(0, ("" + ((length / arr[1+1])))->toInteger() + 1-1) do ( check := length - i * arr[2+1] - j * arr[1+1] ; if (check >= 0 & check mod arr->first() = 0) then ( k := ("" + ((check / arr->first())))->toInteger() ; ans := Set{ans, k + i + j}->max() ) else skip)) ) ; execute (ans)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b,c=map(int,input().split()) dynamic=[0]+[-100000]*(n+100000) for i in range(min(a,b,c),n+1): dynamic[i]=max(dynamic[i-a]+1,dynamic[i-b]+1,dynamic[i-c]+1) print(dynamic[n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{n,a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dynamic : Sequence := Sequence{ 0 }->union(MatrixLib.elementwiseMult(Sequence{ -100000 }, (n + 100000))) ; for i : Integer.subrange(Set{a, b, c}->min(), n + 1-1) do ( dynamic[i+1] := Set{dynamic[i - a+1] + 1, dynamic[i - b+1] + 1, dynamic[i - c+1] + 1}->max()) ; execute (dynamic[n+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,a,b,c=map(int,input().split()) dp=[0]+[-1e9]*5000 for i in range(1,x+1): dp[i]=max(dp[i-a],dp[i-b],dp[i-c])+1 print(dp[x]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{x,a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dp : Sequence := Sequence{ 0 }->union(MatrixLib.elementwiseMult(Sequence{ -("1e9")->toReal() }, 5000)) ; for i : Integer.subrange(1, x + 1-1) do ( dp[i+1] := Set{dp[i - a+1], dp[i - b+1], dp[i - c+1]}->max() + 1) ; execute (dp[x+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b,c=map(int,input().split()) x=min(a,b,c) z=max(a,b,c) y=a+b+c-x-z m=0 p=0 if n % x==0 : print(n//x) else : for i in range(1,n//y+1): if(n-y*i)% x==0 : if p>=(n-y*i)//x+i : break else : p=(n-y*i)//x+i elif(n-z*i)% x==0 : if p>=(n-z*i)//x+i : break else : p=(n-z*i)//x+i else : for j in range(0,i+1): if(n-y*j-z*(i-j))% x==0 : if p>=(n-y*j-z*(i-j))//x+i : m=1 break else : p=(n-y*j-z*(i-j))//x+i if m==1 : break if m==1 : break print(p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{n,a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := Set{a, b, c}->min() ; var z : OclAny := Set{a, b, c}->max() ; var y : double := a + b + c - x - z ; var m : int := 0 ; var p : int := 0 ; if n mod x = 0 then ( execute (n div x)->display() ) else ( for i : Integer.subrange(1, n div y + 1-1) do ( if (n - y * i) mod x = 0 then ( if (p->compareTo((n - y * i) div x + i)) >= 0 then ( break ) else ( p := (n - y * i) div x + i ) ) else (if (n - z * i) mod x = 0 then ( if (p->compareTo((n - z * i) div x + i)) >= 0 then ( break ) else ( p := (n - z * i) div x + i ) ) else ( for j : Integer.subrange(0, i + 1-1) do ( if (n - y * j - z * (i - j)) mod x = 0 then ( if (p->compareTo((n - y * j - z * (i - j)) div x + i)) >= 0 then ( m := 1 ; break ) else ( p := (n - y * j - z * (i - j)) div x + i ) ) else skip ; if m = 1 then ( break ) else skip) ; if m = 1 then ( break ) else skip ) ) ) ; execute (p)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n,a,b,c=map(int,sys.stdin.readline().split()) L=[0]*(n+1) a,b,c=sorted((a,b,c)) def process_cut(width): if width>n : return if L[width]==0 : L[width]=1 for i in range(n): next_idx=i+width if next_idx>n : break if(L[i]!=0): L[next_idx]=max(L[next_idx],L[i]+1) process_cut(a) process_cut(b) process_cut(c) print(L[n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{n,a,b,c} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var L : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{a, b, c}->sort() ; skip ; process_cut(a) ; process_cut(b) ; process_cut(c) ; execute (L[n+1])->display(); operation process_cut(width : OclAny) pre: true post: true activity: if (width->compareTo(n)) > 0 then ( return ) else skip ; if L[width+1] = 0 then ( L[width+1] := 1 ) else skip ; for i : Integer.subrange(0, n-1) do ( var next_idx : OclAny := i + width ; if (next_idx->compareTo(n)) > 0 then ( break ) else skip ; if (L[i+1] /= 0) then ( L[next_idx+1] := Set{L[next_idx+1], L[i+1] + 1}->max() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,m=map(int,input().split()) if n*m==0 : return False a=list(map(int,input().split())) w=list(map(int,input().split())) d={0 : 1} for i in w : new_d=dict(d) for j in d.keys(): new_d[j+i]=1 new_d[abs(j-i)]=1 new_d[i]=1 d=dict(new_d) nokori=[] for i in a : if i in d.keys(): pass else : nokori+=[i] nokorimono=len(nokori) if nokorimono==0 : print(0) return True ans_d={} for i in nokori : new_d={} for j in d.keys(): new_d[abs(i-j)]=1 new_d[i+j]=1 for j in new_d.keys(): if j in ans_d : ans_d[j]=ans_d[j]+1 else : ans_d[j]=1 ans=10**12 for i in ans_d.keys(): if ans_d[i]==nokorimono : ans=min(ans,i) if ans==10**12 : ans=-1 print(ans) return True while main(): pass ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while main() do ( skip); operation main() : OclAny pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n * m = 0 then ( return false ) else skip ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : Map := Map{ 0 |-> 1 } ; for i : w do ( var new_d : Map := ((atom (name d))) ; for j : d.keys() do ( new_d[j + i+1] := 1 ; new_d[(j - i)->abs()+1] := 1) ; new_d[i+1] := 1 ; d := ((atom (name new_d)))) ; var nokori : Sequence := Sequence{} ; for i : a do ( if (d.keys())->includes(i) then ( skip ) else ( nokori := nokori + Sequence{ i } )) ; var nokorimono : int := (nokori)->size() ; if nokorimono = 0 then ( execute (0)->display() ; return true ) else skip ; var ans_d : OclAny := Set{} ; for i : nokori do ( new_d := Set{} ; for j : d.keys() do ( new_d[(i - j)->abs()+1] := 1 ; new_d[i + j+1] := 1) ; for j : new_d.keys() do ( if (ans_d)->includes(j) then ( ans_d[j+1] := ans_d[j+1] + 1 ) else ( ans_d[j+1] := 1 ))) ; var ans : double := (10)->pow(12) ; for i : ans_d.keys() do ( if ans_d[i+1] = nokorimono then ( ans := Set{ans, i}->min() ) else skip) ; if ans = (10)->pow(12) then ( ans := -1 ) else skip ; execute (ans)->display() ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxSubseq(vec,n): suffix=0 i=n-1 while(i>=0): if(vec[i]==1): suffix+=1 vec[i]=suffix i-=1 res=0 zero=0 for i in range(0,n,1): if(vec[i]==0): zero+=1 if(vec[i]>0): res=max(res,zero+vec[i]) return max(res,zero) if __name__=='__main__' : input=[0,1,0,0,1,0] n=len(input) print(maxSubseq(input,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var input : Sequence := Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 0 }))))) ; n := (input)->size() ; execute (maxSubseq(input, n))->display() ) else skip; operation maxSubseq(vec : OclAny, n : OclAny) : OclAny pre: true post: true activity: var suffix : int := 0 ; var i : double := n - 1 ; while (i >= 0) do ( if (vec[i+1] = 1) then ( suffix := suffix + 1 ; vec[i+1] := suffix ) else skip ; i := i - 1) ; var res : int := 0 ; var zero : int := 0 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (vec[i+1] = 0) then ( zero := zero + 1 ) else skip ; if (vec[i+1] > 0) then ( res := Set{res, zero + vec[i+1]}->max() ) else skip) ; return Set{res, zero}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=4 C=4 def countPaths(maze): if(maze[0][0]==-1): return 0 for i in range(R): if(maze[i][0]==0): maze[i][0]=1 else : break for i in range(1,C,1): if(maze[0][i]==0): maze[0][i]=1 else : break for i in range(1,R,1): for j in range(1,C,1): if(maze[i][j]==-1): continue if(maze[i-1][j]>0): maze[i][j]=(maze[i][j]+maze[i-1][j]) if(maze[i][j-1]>0): maze[i][j]=(maze[i][j]+maze[i][j-1]) if(maze[R-1][C-1]>0): return maze[R-1][C-1] else : return 0 if __name__=='__main__' : maze=[[0,0,0,0],[0,-1,0,0],[-1,0,0,0],[0,0,0,0]] print(countPaths(maze)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : int := 4 ; var C : int := 4 ; skip ; if __name__ = '__main__' then ( maze := Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))}->union(Sequence{Sequence{0}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{ 0 })))}->union(Sequence{Sequence{-1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))}->union(Sequence{ Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))) }))) ; execute (countPaths(maze))->display() ) else skip; operation countPaths(maze : OclAny) : OclAny pre: true post: true activity: if (maze->first()->first() = -1) then ( return 0 ) else skip ; for i : Integer.subrange(0, R-1) do ( if (maze[i+1]->first() = 0) then ( maze[i+1]->first() := 1 ) else ( break )) ; for i : Integer.subrange(1, C-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if (maze->first()[i+1] = 0) then ( maze->first()[i+1] := 1 ) else ( break )) ; for i : Integer.subrange(1, R-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( for j : Integer.subrange(1, C-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if (maze[i+1][j+1] = -1) then ( continue ) else skip ; if (maze[i - 1+1][j+1] > 0) then ( maze[i+1][j+1] := (maze[i+1][j+1] + maze[i - 1+1][j+1]) ) else skip ; if (maze[i+1][j - 1+1] > 0) then ( maze[i+1][j+1] := (maze[i+1][j+1] + maze[i+1][j - 1+1]) ) else skip)) ; if (maze[R - 1+1][C - 1+1] > 0) then ( return maze[R - 1+1][C - 1+1] ) else ( return 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def isPrime(N): isPrime=True ; arr=[7,11,13,17,19,23,29,31] if(N<2): isPrime=False if(N % 2==0 or N % 3==0 or N % 5==0): isPrime=False for i in range(0,int(math.sqrt(N)),30): for c in arr : if(c>int(math.sqrt(N))): break else : if(N %(c+i)==0): isPrime=False break if(not isPrime): break if(isPrime): print("Prime Number") else : print("Not a Prime Number") if __name__=="__main__" : N=121 isPrime(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( N := 121 ; isPrime(N) ) else skip; operation isPrime(N : OclAny) pre: true post: true activity: var isPrime : boolean := true; ; var arr : Sequence := Sequence{7}->union(Sequence{11}->union(Sequence{13}->union(Sequence{17}->union(Sequence{19}->union(Sequence{23}->union(Sequence{29}->union(Sequence{ 31 }))))))) ; if (N < 2) then ( isPrime := false ) else skip ; if (N mod 2 = 0 or N mod 3 = 0 or N mod 5 = 0) then ( isPrime := false ) else skip ; for i : Integer.subrange(0, ("" + (((N)->sqrt())))->toInteger()-1)->select( $x | ($x - 0) mod 30 = 0 ) do ( for c : arr do ( if ((c->compareTo(("" + (((N)->sqrt())))->toInteger())) > 0) then ( break ) else ( if (N mod (c + i) = 0) then ( isPrime := false ; break ) else skip ) ; if (not(isPrime)) then ( break ) else skip)) ; if (isPrime) then ( execute ("Prime Number")->display() ) else ( execute ("Not a Prime Number")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline write=sys.stdout.write ans=[] while 1 : M=int(readline()) if M==0 : break P=[list(map(int,input().split()))for i in range(M)] memo={} def dfs(i,rest): if i==M : return rest==0 key=(i,rest) if key in memo : return memo[key] res=0 a,b=P[i] for j in range(0,b+1): if rest-j*a<0 : break res+=dfs(i+1,rest-j*a) memo[key]=res return res G=int(input()) for i in range(G): ans.append(str(dfs(0,int(input())))) write("\n".join(ans)) write("\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var write : OclAny := (OclFile["System.out"]).write ; var ans : Sequence := Sequence{} ; while 1 do ( var M : int := ("" + ((readline())))->toInteger() ; if M = 0 then ( break ) else skip ; var P : Sequence := Integer.subrange(0, M-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var memo : OclAny := Set{} ; skip ; var G : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, G-1) do ( execute ((("" + ((dfs(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()))))) : ans))) ; write(StringLib.sumStringsWithSeparator((ans), "\n")) ; write("\n"); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x1,y1,x2,y2=map(int,input().split()) a=x2-x1 b=y2-y1 print(x2-b,y2+a,x1-b,y1+a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : double := x2 - x1 ; var b : double := y2 - y1 ; execute (x2 - b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin sys.setrecursionlimit(10**5) def li(): return map(int,stdin.readline().split()) def li_(): return map(lambda x : int(x)-1,stdin.readline().split()) def lf(): return map(float,stdin.readline().split()) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) x1,y1,x2,y2=li() vx=x2-x1 vy=y2-y1 x3,y3=x2-vy,y2+vx x4,y4=x3-vx,y3-vy print(x3,y3,x4,y4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stdin : OclFile := OclFile["System.in"] ; sys.setrecursionlimit((10)->pow(5)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := li() ; var vx : double := x2 - x1 ; var vy : double := y2 - y1 ; var x3 : OclAny := null; var y3 : OclAny := null; Sequence{x3,y3} := Sequence{x2 - vy,y2 + vx} ; var x4 : OclAny := null; var y4 : OclAny := null; Sequence{x4,y4} := Sequence{x3 - vx,y3 - vy} ; execute (x3)->display(); operation li() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation li_() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ); operation lf() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ); operation ls() : OclAny pre: true post: true activity: return stdin.readLine().split(); operation ns() : OclAny pre: true post: true activity: return stdin.readLine().rstrip(); operation lc() : OclAny pre: true post: true activity: return (ns()); operation ni() : OclAny pre: true post: true activity: return ("" + ((stdin.readLine())))->toInteger(); operation nf() : OclAny pre: true post: true activity: return ("" + ((stdin.readLine())))->toReal(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np def run(p1,p4): v=p4-p1 A=np.array([[v[0],v[1]],[v[1],-v[0]]]) b=np.array([0,np.dot(v,v)]) x=np.dot(np.linalg.inv(A),b) return x+p1 l=list(map(int,input().split())) p1=np.array([l[0],l[1]]) p2=np.array([l[2],l[3]]) p3=run(p2,p1).astype(np.int64) p4=run(p3,p2).astype(np.int64) print("{}{}{}{}".format(p3[0],p3[1],p4[0],p4[1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; p1 := (Sequence{l->first()}->union(Sequence{ l[1+1] })) ; var p2 : Sequence := (Sequence{l[2+1]}->union(Sequence{ l[3+1] })) ; var p3 : OclAny := run(p2, p1).astype() ; p4 := run(p3, p2).astype() ; execute (StringLib.interpolateStrings("{}{}{}{}", Sequence{p3->first(), p3[1+1], p4->first(), p4[1+1]}))->display(); operation run(p1 : OclAny, p4 : OclAny) : OclAny pre: true post: true activity: var v : double := p4 - p1 ; var A : Sequence := (Sequence{Sequence{v->first()}->union(Sequence{ v[1+1] })}->union(Sequence{ Sequence{v[1+1]}->union(Sequence{ -v->first() }) })) ; var b : Sequence := (Sequence{0}->union(Sequence{ })) ; var x : (trailer . (name dot) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name np)) (trailer . (name linalg)) (trailer . (name inv) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name b)))))))) ))) := ; return x + p1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x1,y1,x2,y2=map(int,input().split()) dx,dy=abs(x2-x1),abs(y2-y1) if x1<=x2 and y1<=y2 : x3=-dy+x2 y3=dx+y2 x4=-dy+x1 y4=dx+y1 elif x2<=x1 and y1<=y2 : x3=-dy+x2 y3=-dx+y2 x4=-dy+x1 y4=-dx+y1 elif x1<=x2 and y2<=y1 : x3=dy+x2 y3=dx+y2 x4=dy+x1 y4=dx+y1 elif x2<=x1 and y2<=y1 : x3=dy+x2 y3=-dx+y2 x4=dy+x1 y4=-dx+y1 print(x3,y3,x4,y4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dx : OclAny := null; var dy : OclAny := null; Sequence{dx,dy} := Sequence{(x2 - x1)->abs(),(y2 - y1)->abs()} ; if (x1->compareTo(x2)) <= 0 & (y1->compareTo(y2)) <= 0 then ( var x3 : OclAny := -dy + x2 ; var y3 : OclAny := dx + y2 ; var x4 : OclAny := -dy + x1 ; var y4 : OclAny := dx + y1 ) else (if (x2->compareTo(x1)) <= 0 & (y1->compareTo(y2)) <= 0 then ( x3 := -dy + x2 ; y3 := -dx + y2 ; x4 := -dy + x1 ; y4 := -dx + y1 ) else (if (x1->compareTo(x2)) <= 0 & (y2->compareTo(y1)) <= 0 then ( x3 := dy + x2 ; y3 := dx + y2 ; x4 := dy + x1 ; y4 := dx + y1 ) else (if (x2->compareTo(x1)) <= 0 & (y2->compareTo(y1)) <= 0 then ( x3 := dy + x2 ; y3 := -dx + y2 ; x4 := dy + x1 ; y4 := -dx + y1 ) else skip ) ) ) ; execute (x3)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p=input().split(" ") x1=int(p[0]) y1=int(p[1]) x2=int(p[2]) y2=int(p[3]) DIF1=x2-x1 DIF2=y2-y1 x3=x2-DIF2 y3=y2+DIF1 x4=x1-DIF2 y4=y1+DIF1 print(str(x3)+" "+str(y3)+" "+str(x4)+" "+str(y4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : OclAny := input().split(" ") ; var x1 : int := ("" + ((p->first())))->toInteger() ; var y1 : int := ("" + ((p[1+1])))->toInteger() ; var x2 : int := ("" + ((p[2+1])))->toInteger() ; var y2 : int := ("" + ((p[3+1])))->toInteger() ; var DIF1 : double := x2 - x1 ; var DIF2 : double := y2 - y1 ; var x3 : double := x2 - DIF2 ; var y3 : int := y2 + DIF1 ; var x4 : double := x1 - DIF2 ; var y4 : int := y1 + DIF1 ; execute (("" + ((x3))) + " " + ("" + ((y3))) + " " + ("" + ((x4))) + " " + ("" + ((y4))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def max(x,y): if(x>y): return x return y def lps(seq,i,j): if(i==j): return 1 if(seq[i]==seq[j]and i+1==j): return 2 if(seq[i]==seq[j]): return lps(seq,i+1,j-1)+2 return max(lps(seq,i,j-1),lps(seq,i+1,j)) if __name__=='__main__' : seq="GEEKSFORGEEKS" n=len(seq) print("The length of the LPS is",lps(seq,0,n-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( seq := "GEEKSFORGEEKS" ; var n : int := (seq)->size() ; execute ("The length of the LPS is")->display() ) else skip; operation max(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if ((x->compareTo(y)) > 0) then ( return x ) else skip ; return y; operation lps(seq : OclAny, i : OclAny, j : OclAny) : OclAny pre: true post: true activity: if (i = j) then ( return 1 ) else skip ; if (seq[i+1] = seq[j+1] & i + 1 = j) then ( return 2 ) else skip ; if (seq[i+1] = seq[j+1]) then ( return lps(seq, i + 1, j - 1) + 2 ) else skip ; return Set{lps(seq, i, j - 1), lps(seq, i + 1, j)}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findLength(st,n): total=[0]*(n+1) for i in range(1,n+1): total[i]=(total[i-1]+int(st[i-1])-int('0')) ans=0 l=2 while(l<=n): for i in range(n-l+1): j=i+l-1 if(total[i+int(l/2)]-total[i]==total[i+l]-total[i+int(l/2)]): ans=max(ans,l) l=l+2 return ans st="123123" print("Length of the substring is",findLength(st,len(st))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; st := "123123" ; execute ("Length of the substring is")->display(); operation findLength(st : OclAny, n : OclAny) : OclAny pre: true post: true activity: var total : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(1, n + 1-1) do ( total[i+1] := (total[i - 1+1] + ("" + ((st[i - 1+1])))->toInteger() - ("" + (('0')))->toInteger())) ; var ans : int := 0 ; var l : int := 2 ; while ((l->compareTo(n)) <= 0) do ( for i : Integer.subrange(0, n - l + 1-1) do ( var j : double := i + l - 1 ; if (total[i + ("" + ((l / 2)))->toInteger()+1] - total[i+1] = total[i + l+1] - total[i + ("" + ((l / 2)))->toInteger()+1]) then ( ans := Set{ans, l}->max() ) else skip) ; l := l + 2) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def solve(N,M,A,W): S=set([0]) for w in W : T=set() for s in S : T.add(s); T.add(s+w); T.add(s-w) S=T C=defaultdict(int) L=None for a in A : if a not in S : if L is None : L=[abs(s-a)for s in S] else : L=[l for l in L if a+l in S or a-l in S] if L is None : print(0) elif L : print(min(L)) else : print(-1) while 1 : N,M=map(int,input().split()) if N==0 : break *A,=map(int,input().split()) *W,=map(int,input().split()) solve(N,M,A,W) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while 1 do ( Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if N = 0 then ( break ) else skip) ; (testlist_star_expr (star_expr * (expr (atom (name A)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name A)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (testlist_star_expr (star_expr * (expr (atom (name W)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name W)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation solve(N : OclAny, M : OclAny, A : OclAny, W : OclAny) pre: true post: true activity: var S : Set := Set{}->union((Sequence{ 0 })) ; for w : W do ( var T : Set := Set{}->union(()) ; for s : S do ( execute ((s) : T); execute ((s + w) : T); execute ((s - w) : T)) ; S := T) ; var C : OclAny := defaultdict(OclType["int"]) ; var L : OclAny := null ; for a : A do ( if (S)->excludes(a) then ( if L <>= null then ( L := S->select(s | true)->collect(s | ((s - a)->abs())) ) else ( L := L->select(l | (S)->includes(a + l) or (S)->includes(a - l))->collect(l | (l)) ) ) else skip) ; if L <>= null then ( execute (0)->display() ) else (if L then ( execute ((L)->min())->display() ) else ( execute (-1)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def prints(a,n,ind): i=ind while iunion(Sequence{'B'}->union(Sequence{'C'}->union(Sequence{'D'}->union(Sequence{'E'}->union(Sequence{ 'F' }))))) ; n := (a)->size(); ; prints(a, n, 3);; operation prints(a : OclAny, n : OclAny, ind : OclAny) pre: true post: true activity: var i : OclAny := ind ; while (i->compareTo(n + ind)) < 0 do ( execute (a[(i mod n)+1])->display() ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def prints(a,n,ind): b=[None]*2*n i=0 while iunion(Sequence{'B'}->union(Sequence{'C'}->union(Sequence{'D'}->union(Sequence{'E'}->union(Sequence{ 'F' }))))) ; n := (a)->size(); ; prints(a, n, 3);; operation prints(a : OclAny, n : OclAny, ind : OclAny) pre: true post: true activity: var b : Sequence := MatrixLib.elementwiseMult(MatrixLib.elementwiseMult(Sequence{ null }, 2), n) ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( b[i+1] := a[i+1]; var b[n + i+1] : OclAny := a[i+1] ; i := i + 1) ; i := ind ; while (i->compareTo(n + ind)) < 0 do ( execute (b[i+1])->display(); ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_input(): while True : try : yield ''.join(input()) except EOFError : break while True : m=int(input()) if m==0 : break a=[0 for i in range(7)] b=[0 for i in range(7)] for i in range(m): a[i],b[i]=[int(j)for j in input().split()] dp=[[0 for i in range(1001)]for j in range(8)] dp[0][0]=1 for i in range(7): for j in range(1001): for k in range(b[i]+1): if j+a[i]*k<=1000 : dp[i+1][j+a[i]*k]+=dp[i][j] g=int(input()) for i in range(g): n=int(input()) print(dp[m][n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if m = 0 then ( break ) else skip ; var a : Sequence := Integer.subrange(0, 7-1)->select(i | true)->collect(i | (0)) ; var b : Sequence := Integer.subrange(0, 7-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, m-1) do ( var a[i+1] : OclAny := null; var b[i+1] : OclAny := null; Sequence{a[i+1],b[i+1]} := input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger()))) ; var dp : Sequence := Integer.subrange(0, 8-1)->select(j | true)->collect(j | (Integer.subrange(0, 1001-1)->select(i | true)->collect(i | (0)))) ; dp->first()->first() := 1 ; for i : Integer.subrange(0, 7-1) do ( for j : Integer.subrange(0, 1001-1) do ( for k : Integer.subrange(0, b[i+1] + 1-1) do ( if j + a[i+1] * k <= 1000 then ( dp[i + 1+1][j + a[i+1] * k+1] := dp[i + 1+1][j + a[i+1] * k+1] + dp[i+1][j+1] ) else skip))) ; var g : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, g-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (dp[m+1][n+1])->display())); operation get_input(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; while true do ( try ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return StringLib.sumStringsWithSeparator(((OclFile["System.in"]).readLine()), '')) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def solve(): n,a,b=map(int,input().split()) e=0 o=0 for i in input().strip().split('*'): l=len(i) e+=l//2 o+=l % 2 print(min(o+e+min(e,a,b),b+a)) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; solve(); operation solve() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var e : int := 0 ; var o : int := 0 ; for i : input()->trim().split('*') do ( var l : int := (i)->size() ; e := e + l div 2 ; o := o + l mod 2) ; execute (Set{o + e + Set{e, a, b}->min(), b + a}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=map(int,input().split()) origa,origb=a,b railcar=input() occupied=[] for i in range(n): if railcar[i]=='*' : occupied.append(i) if len(occupied)==0 : if a==b : r=a+b print(min(n,r)) else : if n % 2==0 : u=min(max(a,b),n//2) else : u=min(max(a,b),n//2+1) v=min(min(a,b),n-u) print(min(n,v+u)) exit() spaces=[] if occupied[0]: spaces.append(occupied[0]) if n-occupied[-1]-1 : spaces.append(n-occupied[-1]-1) for i in range(1,len(occupied)): spaces.append(occupied[i]-occupied[i-1]-1) for i in spaces : if i % 2==0 : a-=i//2 b-=i//2 else : if a>b : a-=i//2+1 b-=i//2 else : a-=i//2 b-=i//2+1 res=origa-max(a,0) res+=origb-max(b,0) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var origa : OclAny := null; var origb : OclAny := null; Sequence{origa,origb} := Sequence{a,b} ; var railcar : String := (OclFile["System.in"]).readLine() ; var occupied : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if railcar[i+1] = '*' then ( execute ((i) : occupied) ) else skip) ; if (occupied)->size() = 0 then ( if a = b then ( var r : OclAny := a + b ; execute (Set{n, r}->min())->display() ) else ( if n mod 2 = 0 then ( var u : OclAny := Set{Set{a, b}->max(), n div 2}->min() ) else ( u := Set{Set{a, b}->max(), n div 2 + 1}->min() ) ; var v : OclAny := Set{Set{a, b}->min(), n - u}->min() ; execute (Set{n, v + u}->min())->display() ) ; exit() ) else skip ; var spaces : Sequence := Sequence{} ; if occupied->first() then ( execute ((occupied->first()) : spaces) ) else skip ; if n - occupied->last() - 1 then ( execute ((n - occupied->last() - 1) : spaces) ) else skip ; for i : Integer.subrange(1, (occupied)->size()-1) do ( execute ((occupied[i+1] - occupied[i - 1+1] - 1) : spaces)) ; for i : spaces do ( if i mod 2 = 0 then ( a := a - i div 2 ; b := b - i div 2 ) else ( if (a->compareTo(b)) > 0 then ( a := a - i div 2 + 1 ; b := b - i div 2 ) else ( a := a - i div 2 ; b := b - i div 2 + 1 ) )) ; var res : double := origa - Set{a, 0}->max() ; res := res + origb - Set{b, 0}->max() ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,a,b=(int(x)for x in input().split()) total=a+b string=input().split("*") for i in string : if a>b : a,b=b,a a-=min(a,len(i)//2) b-=min(b,len(i)-len(i)//2) print(total-a-b) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var total : OclAny := a + b ; var string : OclAny := input().split("*") ; for i : string do ( if (a->compareTo(b)) > 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a} ) else skip ; a := a - Set{a, (i)->size() div 2}->min() ; b := b - Set{b, (i)->size() - (i)->size() div 2}->min()) ; execute (total - a - b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def solve(): n,a,b=map(int,input().split()) s=input() p=-1 r=0 e=0 o=0 for i in range(n+1): if s[i]=='*' : if p+1b : a,b=b,a k=min(a,b) r=0 for i in range(min(e,k)+1): A,B=a-i,b-i l=e-i+o w=min(A,l) r=max(r,i*2+w+min(l-w,B)) print(r) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; solve(); operation solve() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var p : int := -1 ; var r : int := 0 ; var e : int := 0 ; var o : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( if s[i+1] = '*' then ( if (p + 1->compareTo(i)) < 0 then ( var l : double := i - p - 1 ; e := e + l div 2 ; o := o + l mod 2 ) else skip ; p := i ) else skip) ; if (p + 1->compareTo(n)) < 0 then ( l := n - p - 1 ; e := e + l div 2 ; o := o + l mod 2 ) else skip ; if (a->compareTo(b)) > 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a} ) else skip ; var k : OclAny := Set{a, b}->min() ; r := 0 ; for i : Integer.subrange(0, Set{e, k}->min() + 1-1) do ( var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := Sequence{a - i,b - i} ; l := e - i + o ; var w : OclAny := Set{A, l}->min() ; r := Set{r, i * 2 + w + Set{l - w, B}->min()}->max()) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def solve(): n,a,b=map(int,input().split()) e=0 o=0 for i in input().strip().split('*'): l=len(i) e+=l//2 o+=l % 2 if a>b : a,b=b,a k=min(a,b) r=0 for i in range(min(e,k)+1): A,B=a-i,b-i l=e-i+o w=min(A,l) r=max(r,i*2+w+min(l-w,B)) print(r) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; solve(); operation solve() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var e : int := 0 ; var o : int := 0 ; for i : input()->trim().split('*') do ( var l : int := (i)->size() ; e := e + l div 2 ; o := o + l mod 2) ; if (a->compareTo(b)) > 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a} ) else skip ; var k : OclAny := Set{a, b}->min() ; var r : int := 0 ; for i : Integer.subrange(0, Set{e, k}->min() + 1-1) do ( var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := Sequence{a - i,b - i} ; l := e - i + o ; var w : OclAny := Set{A, l}->min() ; r := Set{r, i * 2 + w + Set{l - w, B}->min()}->max()) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10000) n=int(input()) a=[] b=[[]for _ in[0]*n] def f(i,x): print('.'*x+a[i]) for j in b[i]: f(j,x+1) for i in range(n): c=int(input()) a+=[input()] if c!=0 : b[c-1]+=[i] f(0,0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(10000) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n)->select(_anon | true)->collect(_anon | (Sequence{})) ; skip ; for i : Integer.subrange(0, n-1) do ( var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := a + Sequence{ (OclFile["System.in"]).readLine() } ; if c /= 0 then ( b[c - 1+1] := b[c - 1+1] + Sequence{ i } ) else skip) ; f(0, 0); operation f(i : OclAny, x : OclAny) pre: true post: true activity: execute (StringLib.nCopies('.', x) + a[i+1])->display() ; for j : b[i+1] do ( f(j, x + 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(1010) N=int(input()) src=[] for i in range(N): k=int(input()) s=input() src.append((s,[])) if i==0 : continue src[k-1][1].append(i) def dfs(i,depth): s,ch=src[i] print('.'*depth+s) for c in ch : dfs(c,depth+1) dfs(0,0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(1010) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var src : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; execute ((Sequence{s, Sequence{}}) : src) ; if i = 0 then ( continue ) else skip ; (expr (atom (name src)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name k))) - (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; skip ; dfs(0, 0); operation dfs(i : OclAny, depth : OclAny) pre: true post: true activity: var ch : OclAny := null; Sequence{s,ch} := src[i+1] ; execute (StringLib.nCopies('.', depth) + s)->display() ; for c : ch do ( dfs(c, depth + 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] while True : n=I() a=[] e=collections.defaultdict(list) for i in range(n): k=I() l=S() e[k].append(i+1) a.append(l) f=[None]*n def ff(i,d): f[i-1]=1 r=['.'*d+a[i-1]] for j in e[i]: r+=ff(j,d+1) return r for i in range(n): if f[i]: continue rr+=ff(i+1,0) break return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var n : OclAny := I() ; var a : Sequence := Sequence{} ; var e : OclAny := .defaultdict(OclType["Sequence"]) ; for i : Integer.subrange(0, n-1) do ( var k : OclAny := I() ; var l : OclAny := S() ; (expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) )))) ; execute ((l) : a)) ; var f : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; skip ; for i : Integer.subrange(0, n-1) do ( if f[i+1] then ( continue ) else skip ; rr := rr + ff(i + 1, 0)) ; break) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m={"A" : float('inf'),"B" : float('inf'),"C" : float('inf'),"AB" : float('inf'),"AC" : float('inf'),"BC" : float('inf'),"ABC" : float('inf')} for i in range(n): inp=input() item=inp.split(' ') l="".join(sorted(item[1])) m[l]=min(m[l],int(item[0])) res=float('inf') res=min(res,m["A"]+m["B"]+m["C"]) res=min(res,m["AB"]+m["C"]) res=min(res,m["AC"]+m["B"]) res=min(res,m["A"]+m["BC"]) res=min(res,m["BC"]+m["AB"]) res=min(res,m["AC"]+m["BC"]) res=min(res,m["AC"]+m["AB"]) res=min(res,m["ABC"]) print(res if res!=float('inf')else-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : Map := Map{ "A" |-> ("" + (('inf')))->toReal() }->union(Map{ "B" |-> ("" + (('inf')))->toReal() }->union(Map{ "C" |-> ("" + (('inf')))->toReal() }->union(Map{ "AB" |-> ("" + (('inf')))->toReal() }->union(Map{ "AC" |-> ("" + (('inf')))->toReal() }->union(Map{ "BC" |-> ("" + (('inf')))->toReal() }->union(Map{ "ABC" |-> ("" + (('inf')))->toReal() })))))) ; for i : Integer.subrange(0, n-1) do ( var inp : String := (OclFile["System.in"]).readLine() ; var item : OclAny := inp.split(' ') ; var l : String := StringLib.sumStringsWithSeparator((item[1+1]->sort()), "") ; m->at(l) := Set{m->at(l), ("" + ((item->first())))->toInteger()}->min()) ; var res : double := ("" + (('inf')))->toReal() ; res := Set{res, m->at("A") + m->at("B") + m->at("C")}->min() ; res := Set{res, m->at("AB") + m->at("C")}->min() ; res := Set{res, m->at("AC") + m->at("B")}->min() ; res := Set{res, m->at("A") + m->at("BC")}->min() ; res := Set{res, m->at("BC") + m->at("AB")}->min() ; res := Set{res, m->at("AC") + m->at("BC")}->min() ; res := Set{res, m->at("AC") + m->at("AB")}->min() ; res := Set{res, m->at("ABC")}->min() ; execute (if res /= ("" + (('inf')))->toReal() then res else -1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- v1,v2=map(int,input().split()) t,d=map(int,input().split()) sum=0 for i in range(t): sum+=min(v1+d*i,v2+d*(t-i-1)) print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var v1 : OclAny := null; var v2 : OclAny := null; Sequence{v1,v2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : OclAny := null; var d : OclAny := null; Sequence{t,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sum : int := 0 ; for i : Integer.subrange(0, t-1) do ( sum := sum + Set{v1 + d * i, v2 + d * (t - i - 1)}->min()) ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def solve(m,cards,g,guesses): ans=[] cards.append([0,0]) cards.sort() W=max(guesses)+1 dp=[0]*W dp[0]=1 for i in range(1,m+1): card_num=cards[i][0] card_rem=cards[i][1] for j in range(W-1,0,-1): for k in range(1,card_rem+1): if card_num*k<=j : dp[j]+=dp[j-card_num*k] for gg in guesses : ans.append(dp[gg]) return ans def main(args): while True : m=int(input()) if m==0 : break cards=[] for _ in range(m): a,b=map(int,input().split()) cards.append([a,b]) g=int(input()) guesses=[int(input())for _ in range(g)] ans=solve(m,cards,g,guesses) print(*ans,sep='\n') if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(m : OclAny, cards : OclAny, g : OclAny, guesses : OclAny) : OclAny pre: true post: true activity: var ans : Sequence := Sequence{} ; execute ((Sequence{0}->union(Sequence{ 0 })) : cards) ; cards := cards->sort() ; var W : OclAny := (guesses)->max() + 1 ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, W) ; dp->first() := 1 ; for i : Integer.subrange(1, m + 1-1) do ( var card_num : OclAny := cards[i+1]->first() ; var card_rem : OclAny := cards[i+1][1+1] ; for j : Integer.subrange(0 + 1, W - 1)->reverse() do ( for k : Integer.subrange(1, card_rem + 1-1) do ( if (card_num * k->compareTo(j)) <= 0 then ( dp[j+1] := dp[j+1] + dp[j - card_num * k+1] ) else skip))) ; for gg : guesses do ( execute ((dp[gg+1]) : ans)) ; return ans; operation main(args : OclAny) pre: true post: true activity: while true do ( m := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if m = 0 then ( break ) else skip ; cards := Sequence{} ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a}->union(Sequence{ b })) : cards)) ; g := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; guesses := Integer.subrange(0, g-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; ans := solve(m, cards, g, guesses) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- v1,v2=input().split() t,d=input().split() v1=int(v1) v2=int(v2) t=int(t) d=int(d) a=1 v=v1 distance=0 for i in range(t): if v-v2>(t-i-1)*d : a*=-1 v=(t-i-1)*d+v2 distance+=v v+=a*d print(distance) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var v1 : OclAny := null; var v2 : OclAny := null; Sequence{v1,v2} := input().split() ; var t : OclAny := null; var d : OclAny := null; Sequence{t,d} := input().split() ; var v1 : int := ("" + ((v1)))->toInteger() ; var v2 : int := ("" + ((v2)))->toInteger() ; var t : int := ("" + ((t)))->toInteger() ; var d : int := ("" + ((d)))->toInteger() ; var a : int := 1 ; var v : int := v1 ; var distance : int := 0 ; for i : Integer.subrange(0, t-1) do ( if (v - v2->compareTo((t - i - 1) * d)) > 0 then ( a := a * -1 ; v := (t - i - 1) * d + v2 ) else skip ; distance := distance + v ; v := v + a * d) ; execute (distance)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- v1,v2=map(int,input().split()) n,d=map(int,input().split()) ans=0 for i in range(n-1): li=v1+i*d ri=v2+((n-1)-(i+1))*d ls=(v1+li)*(i+1)//2 rs=(v2+ri)*(n-1-i)//2 if abs(li-ri)<=d : ans=max(ans,ls+rs) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var v1 : OclAny := null; var v2 : OclAny := null; Sequence{v1,v2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( var li : OclAny := v1 + i * d ; var ri : OclAny := v2 + ((n - 1) - (i + 1)) * d ; var ls : int := (v1 + li) * (i + 1) div 2 ; var rs : int := (v2 + ri) * (n - 1 - i) div 2 ; if ((li - ri)->abs()->compareTo(d)) <= 0 then ( ans := Set{ans, ls + rs}->max() ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math v1,v2=map(int,input().split()) t,d=map(int,input().split()) a=[0]*(10000) a[0]=v1 a[t-1]=v2 l=0 r=t-1 while((r-l)>1): if a[l]collect( _x | (OclType["int"])->apply(_x) ) ; var t : OclAny := null; var d : OclAny := null; Sequence{t,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (10000)) ; a->first() := v1 ; a[t - 1+1] := v2 ; var l : int := 0 ; var r : double := t - 1 ; while ((r - l) > 1) do ( if (a[l+1]->compareTo(a[r+1])) < 0 then ( a[l + 1+1] := a[l+1] + d ; l := l + 1 ) else ( a[r - 1+1] := a[r+1] + d ; r := r - 1 )) ; execute ((a)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) Sherlock=list(input()) Moriarty=sorted(list(input())) copySherlock=[digit for digit in Sherlock] copyMoriarty=[digit for digit in Moriarty] minHits=0 maxHits=0 for i in range(n): for j in range(n): if Moriarty[j]==-1 : continue if Moriarty[j]>=Sherlock[i]: Moriarty[j]=-1 Sherlock[i]=-1 break for i in range(n): if Moriarty[i]!=-1 : minHits+=1 for i in range(n): for j in range(n): if copyMoriarty[j]==-1 : continue if copyMoriarty[j]>copySherlock[i]: maxHits+=1 copyMoriarty[j]=-1 break print(minHits) print(maxHits) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var Sherlock : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var Moriarty : Sequence := ((OclFile["System.in"]).readLine())->characters()->sort() ; var copySherlock : Sequence := Sherlock->select(digit | true)->collect(digit | (digit)) ; var copyMoriarty : Sequence := Moriarty->select(digit | true)->collect(digit | (digit)) ; var minHits : int := 0 ; var maxHits : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if Moriarty[j+1] = -1 then ( continue ) else skip ; if (Moriarty[j+1]->compareTo(Sherlock[i+1])) >= 0 then ( Moriarty[j+1] := -1 ; Sherlock[i+1] := -1 ; break ) else skip)) ; for i : Integer.subrange(0, n-1) do ( if Moriarty[i+1] /= -1 then ( minHits := minHits + 1 ) else skip) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if copyMoriarty[j+1] = -1 then ( continue ) else skip ; if (copyMoriarty[j+1]->compareTo(copySherlock[i+1])) > 0 then ( maxHits := maxHits + 1 ; copyMoriarty[j+1] := -1 ; break ) else skip)) ; execute (minHits)->display() ; execute (maxHits)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() m=input() ml=list(m) sl=list(s) ml=list(map(int,ml)) sl=list(map(int,sl)) f=0 mi=10 c=0 p=0 for i in range(n): for j in range(n): if ml[j]-sl[i]=sl[i]: mi=ml[j]-sl[i] p=j f=1 if f==1 : ml[p]=-1 c+=1 mi=10 f=0 print(n-c) f=0 mi=10 c=0 p=0 ml=list(m) sl=list(s) ml=list(map(int,ml)) sl=list(map(int,sl)) for i in range(n): for j in range(n): if ml[j]-sl[i]sl[i]: mi=ml[j]-sl[i] p=j f=1 if f==1 : ml[p]=-1 c+=1 mi=10 f=0 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var m : String := (OclFile["System.in"]).readLine() ; var ml : Sequence := (m)->characters() ; var sl : Sequence := (s)->characters() ; ml := ((ml)->collect( _x | (OclType["int"])->apply(_x) )) ; sl := ((sl)->collect( _x | (OclType["int"])->apply(_x) )) ; var f : int := 0 ; var mi : int := 10 ; var c : int := 0 ; var p : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if (ml[j+1] - sl[i+1]->compareTo(mi)) < 0 & (ml[j+1]->compareTo(sl[i+1])) >= 0 then ( mi := ml[j+1] - sl[i+1] ; p := j ; f := 1 ) else skip) ; if f = 1 then ( ml[p+1] := -1 ; c := c + 1 ) else skip ; mi := 10 ; f := 0) ; execute (n - c)->display() ; f := 0 ; mi := 10 ; c := 0 ; p := 0 ; ml := (m)->characters() ; sl := (s)->characters() ; ml := ((ml)->collect( _x | (OclType["int"])->apply(_x) )) ; sl := ((sl)->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if (ml[j+1] - sl[i+1]->compareTo(mi)) < 0 & (ml[j+1]->compareTo(sl[i+1])) > 0 then ( mi := ml[j+1] - sl[i+1] ; p := j ; f := 1 ) else skip) ; if f = 1 then ( ml[p+1] := -1 ; c := c + 1 ) else skip ; mi := 10 ; f := 0) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(n,s): first=s[0] min_m=0 max_s=0 for i in range(n-1): s[i]=s[i+1] s[-1]=first for i in range(n): if a[i]>s[i]: min_m+=1 elif s[i]>a[i]: max_s+=1 return s,min_m,max_s n=int(input()) a=list(map(int,list(input()))) b=list(map(int,list(input()))) for i in range(n-1): for j in range(n-i-1): if a[j+1]toInteger() ; var a : Sequence := ((((OclFile["System.in"]).readLine())->characters())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((((OclFile["System.in"]).readLine())->characters())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(0, n - i - 1-1) do ( if (a[j + 1+1]->compareTo(a[j+1])) < 0 then ( var a[j + 1+1] : OclAny := null; var a[j+1] : OclAny := null; Sequence{a[j + 1+1],a[j+1]} := Sequence{a[j+1],a[j + 1+1]} ) else skip ; if (b[j + 1+1]->compareTo(b[j+1])) < 0 then ( var b[j + 1+1] : OclAny := null; var b[j+1] : OclAny := null; Sequence{b[j + 1+1],b[j+1]} := Sequence{b[j+1],b[j + 1+1]} ) else skip)) ; var d1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var d2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; d1->first() := 1000 ; for i : Integer.subrange(1, n + 1-1) do ( Sequence{b,min_m,max_s} := f(n, b) ; d1[i+1] := Set{d1[i - 1+1], min_m}->min() ; d2[i+1] := Set{d2[i - 1+1], max_s}->max()) ; execute (d1[n+1])->display() ; execute (d2[n+1])->display(); operation f(n : OclAny, s : OclAny) : OclAny pre: true post: true activity: var first : OclAny := s->first() ; var min_m : int := 0 ; var max_s : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( s[i+1] := s[i + 1+1]) ; s->last() := first ; for i : Integer.subrange(0, n-1) do ( if (a[i+1]->compareTo(s[i+1])) > 0 then ( min_m := min_m + 1 ) else (if (s[i+1]->compareTo(a[i+1])) > 0 then ( max_s := max_s + 1 ) else skip)) ; return s, min_m, max_s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) S=list(map(int,input())) M=list(map(int,input())) M.sort() S.sort() beats=0 defens=n k=0 k2=0 for i in range(n): for j in range(k,n): if M[j]>S[i]: beats+=1 k=j+1 break else : k=n for j in range(k2,n): if M[j]>=S[i]: defens-=1 k2=j+1 break else : k2=n print(defens) print(beats) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : Sequence := (((OclFile["System.in"]).readLine())->collect( _x | (OclType["int"])->apply(_x) )) ; var M : Sequence := (((OclFile["System.in"]).readLine())->collect( _x | (OclType["int"])->apply(_x) )) ; M := M->sort() ; S := S->sort() ; var beats : int := 0 ; var defens : int := n ; var k : int := 0 ; var k2 : int := 0 ; for i : Integer.subrange(0, n-1) do ((compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name k))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name M)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) > (comparison (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name beats)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name k)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 1)))))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name k)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name n))))))))))))))) ; (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name k2))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name M)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) >= (comparison (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name defens)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name k2)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 1)))))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name k2)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name n)))))))))))))))) ; execute (defens)->display() ; execute (beats)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) Sherlock=list(input()) Moriarty=sorted(list(input())) copySherlock=[digit for digit in Sherlock] copyMoriarty=[digit for digit in Moriarty] minHits=0 maxHits=0 for i in range(n): for j in range(n): if Moriarty[j]==-1 : continue if Moriarty[j]>=Sherlock[i]: Moriarty[j]=-1 Sherlock[i]=-1 break for i in range(n): if Moriarty[i]!=-1 : minHits+=1 for i in range(n): for j in range(n): if copyMoriarty[j]==-1 : continue if copyMoriarty[j]>copySherlock[i]: maxHits+=1 copyMoriarty[j]=-1 break print(minHits) print(maxHits) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var Sherlock : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var Moriarty : Sequence := ((OclFile["System.in"]).readLine())->characters()->sort() ; var copySherlock : Sequence := Sherlock->select(digit | true)->collect(digit | (digit)) ; var copyMoriarty : Sequence := Moriarty->select(digit | true)->collect(digit | (digit)) ; var minHits : int := 0 ; var maxHits : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if Moriarty[j+1] = -1 then ( continue ) else skip ; if (Moriarty[j+1]->compareTo(Sherlock[i+1])) >= 0 then ( Moriarty[j+1] := -1 ; Sherlock[i+1] := -1 ; break ) else skip)) ; for i : Integer.subrange(0, n-1) do ( if Moriarty[i+1] /= -1 then ( minHits := minHits + 1 ) else skip) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if copyMoriarty[j+1] = -1 then ( continue ) else skip ; if (copyMoriarty[j+1]->compareTo(copySherlock[i+1])) > 0 then ( maxHits := maxHits + 1 ; copyMoriarty[j+1] := -1 ; break ) else skip)) ; execute (minHits)->display() ; execute (maxHits)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np a=np.vectorize(int)(input().split()) cnt2=np.vectorize(lambda x : int((np.max(a)-x)/2))(a) cnt1=np.max(a)-a-2*cnt2 print(sum(cnt2)+[0,2,1][sum(cnt1)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := np.vectorize(OclType["int"])(input().split()) ; var cnt2 : OclAny := np.vectorize(lambda x : OclAny in (("" + ((( - x) / 2)))->toInteger()))(a) ; var cnt1 : double := - a - 2 * cnt2 ; execute ((cnt2)->sum() + Sequence{0}->union(Sequence{2}->union(Sequence{ 1 }))[(cnt1)->sum()+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict from functools import lru_cache import sys sys.setrecursionlimit(2000) def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s=input() return(list(s[: len(s)-1])) def invr(): return(map(int,input().split())) def solve(j,i,v,dp): if len(v)==3 : return 0 if i>=len(j): return float('inf') h=hash(v) if(i,h)in dp : return dp[(i,h)] new_v=set(v).union(set(j[i][1])) new_v=tuple(sorted(new_v)) include=float('inf') if new_v!=v : include=solve(j,i+1,new_v,dp)+j[i][0] not_include=solve(j,i+1,v,dp) dp[(i,h)]=min(include,not_include) return dp[(i,h)] n=inp() j=[] dp=defaultdict(int) for _ in range(n): p,v=input().split() j.append((int(p),tuple(sorted(v)))) v=tuple("") val=solve(j,0,v,dp) if val==float('inf'): print(-1) else : print(val) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit(2000) ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := inp() ; j := Sequence{} ; dp := defaultdict(OclType["int"]) ; for _anon : Integer.subrange(0, n-1) do ( var p : OclAny := null; Sequence{p,v} := input().split() ; execute ((Sequence{("" + ((p)))->toInteger(), (v->sort())}) : j)) ; v := ("") ; var val : OclAny := solve(j, 0, v, dp) ; if val = ("" + (('inf')))->toReal() then ( execute (-1)->display() ) else ( execute (val)->display() ); operation inp() : OclAny pre: true post: true activity: return (("" + (((OclFile["System.in"]).readLine())))->toInteger()); operation inlt() : OclAny pre: true post: true activity: return (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))); operation insr() : OclAny pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; return ((s.subrange(1,(s)->size() - 1))); operation invr() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation solve(j : OclAny, i : OclAny, v : OclAny, dp : OclAny) : OclAny pre: true post: true activity: if (v)->size() = 3 then ( return 0 ) else skip ; if (i->compareTo((j)->size())) >= 0 then ( return ("" + (('inf')))->toReal() ) else skip ; var h : int := hash(v) ; if (dp)->includes(Sequence{i, h}) then ( return dp[Sequence{i, h}+1] ) else skip ; var new_v : OclAny := Set{}->union((v)).union(Set{}->union((j[i+1][1+1]))) ; new_v := (new_v->sort()) ; var include : double := ("" + (('inf')))->toReal() ; if new_v /= v then ( include := solve(j, i + 1, new_v, dp) + j[i+1]->first() ) else skip ; var not_include : OclAny := solve(j, i + 1, v, dp) ; dp[Sequence{i, h}+1] := Set{include, not_include}->min() ; return dp[Sequence{i, h}+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if n==0 : break dp=[1]+[0]*3000 for i in range(n): a,b=map(int,input().split()) for j in range(1001,-1,-1): for k in range(1,b+1): dp[j+a*k]+=dp[j] for _ in range(int(input())): print(dp[int(input())]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var dp : Sequence := Sequence{ 1 }->union(MatrixLib.elementwiseMult(Sequence{ 0 }, 3000)) ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for j : Integer.subrange(-1 + 1, 1001)->reverse() do ( for k : Integer.subrange(1, b + 1-1) do ( dp[j + a * k+1] := dp[j + a * k+1] + dp[j+1]))) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (dp[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1])->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) max=max(a,b,c) n=abs(max-b)+abs(max-c)+abs(max-a) if n % 2==0 : print(n//2) else : print((n+3)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var max : OclAny := Set{a, b, c}->max() ; var n : double := (max - b)->abs() + (max - c)->abs() + (max - a)->abs() ; if n mod 2 = 0 then ( execute (n div 2)->display() ) else ( execute ((n + 3) div 2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heappush,heappop func1=lambda A,B,C :[(A+1,B+1,C),(A,B+1,C+1),(A+1,B,C+1)] func2=lambda A,B,C :[(A+2,B,C),(A,B+2,C),(A,B,C+2)] def cost_func(A,B,C): return abs(A-B)+abs(A-C)+abs(B-C) def makeNode(alphabets,count): A,B,C=alphabets return cost_func(A,B,C),A,B,C,count+1 A,B,C=[int(n)for n in input().split()] first_cost=cost_func(A,B,C) nodes=[(first_cost,A,B,C,0)] check=set() check.add((A,B,C)) while len(nodes)!=0 : cost,A,B,C,count=heappop(nodes) if cost==0 : print(count) break for alphabets in func1(A,B,C)+func2(A,B,C): A,B,C=alphabets cost=cost_func(A,B,C) if alphabets not in check : check.add(alphabets) heappush(nodes,(cost,A,B,C,count+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var func1 : Function := lambda A : OclAny, B : OclAny, C : OclAny in (Sequence{Sequence{A + 1, B + 1, C}}->union(Sequence{Sequence{A, B + 1, C + 1}}->union(Sequence{ Sequence{A + 1, B, C + 1} }))) ; var func2 : Function := lambda A : OclAny, B : OclAny, C : OclAny in (Sequence{Sequence{A + 2, B, C}}->union(Sequence{Sequence{A, B + 2, C}}->union(Sequence{ Sequence{A, B, C + 2} }))) ; skip ; skip ; Sequence{A,B,C} := input().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; var first_cost : OclAny := cost_func(A, B, C) ; var nodes : Sequence := Sequence{ Sequence{first_cost, A, B, C, 0} } ; var check : Set := Set{}->union(()) ; execute ((Sequence{A, B, C}) : check) ; while (nodes)->size() /= 0 do ( var cost : OclAny := null; Sequence{cost,A,B,C,count} := heappop(nodes) ; if cost = 0 then ( execute (count)->display() ; break ) else skip ; for alphabets : func1->apply(A, B, C) + func2->apply(A, B, C) do ( Sequence{A,B,C} := alphabets ; var cost : OclAny := cost_func(A, B, C) ; if (check)->excludes(alphabets) then ( execute ((alphabets) : check) ; heappush(nodes, Sequence{cost, A, B, C, count + 1}) ) else skip)); operation cost_func(A : OclAny, B : OclAny, C : OclAny) : OclAny pre: true post: true activity: return (A - B)->abs() + (A - C)->abs() + (B - C)->abs(); operation makeNode(alphabets : OclAny, count : OclAny) : OclAny pre: true post: true activity: Sequence{A,B,C} := alphabets ; return cost_func(A, B, C), A, B, C, count + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**15 mod=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): a=LI() a.sort() r=0 while a[0]!=a[2]: r+=1 if a[0]pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(15) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var a : OclAny := LI() ; a := a->sort() ; var r : int := 0 ; while a->first() /= a[2+1] do ( r := r + 1 ; if (a->first()->compareTo(a[1+1])) < 0 then ( a->first() := a->first() + 2 ) else ( a->first() := a->first() + 1 ; a[1+1] := a[1+1] + 1 ) ; a := a->sort()) ; return r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=list(map(int,input().split())) numSort=sorted(num) count=numSort[2]-numSort[1] count+=(numSort[2]-(numSort[0]+count))/2 count=int(count)if count.is_integer()else int(count+1.5) print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var numSort : Sequence := num->sort() ; var count : double := numSort[2+1] - numSort[1+1] ; count := count + (numSort[2+1] - (numSort->first() + count)) / 2 ; count := if count.is_integer() then ("" + ((count)))->toInteger() else ("" + ((count + 1.5)))->toInteger() endif ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) for j in range(n): for k in range(j+1): if k==0 or k==j : print(1,end=' ') else : print(0,end=' ') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, n-1) do ( for k : Integer.subrange(0, j + 1-1) do ( if k = 0 or k = j then ( execute (1)->display() ) else ( execute (0)->display() )) ; execute (->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) for j in range(n): if j==0 : print("1") else : if j-1==0 : print("1 1") else : answer=list("l"*((j+1)*2-1)) answer[0],answer[len(answer)-1]="1","1" for c in range(1,len(answer)-1): if c % 2!=0 : answer[c]="" else : answer[c]="0" true_answer="".join(answer) print(true_answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, n-1) do ( if j = 0 then ( execute ("1")->display() ) else ( if j - 1 = 0 then ( execute ("1 1")->display() ) else ( var answer : Sequence := (StringLib.nCopies("l", ((j + 1) * 2 - 1)))->characters() ; var answer->first() : OclAny := null; var answer[(answer)->size() - 1+1] : OclAny := null; Sequence{answer->first(),answer[(answer)->size() - 1+1]} := Sequence{"1","1"} ; for c : Integer.subrange(1, (answer)->size() - 1-1) do ( if c mod 2 /= 0 then ( answer[c+1] := "" ) else ( answer[c+1] := "0" )) ; var true_answer : String := StringLib.sumStringsWithSeparator((answer), "") ; execute (true_answer)->display() ) ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- test=int(input()) for t in range(test): n=int(input()) a=list() for i in range(n): a.append([0]*(i+1)) a[i][0]=1 a[i][-1]=1 for i in range(n): print(*a[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var test : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(0, test-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := () ; for i : Integer.subrange(0, n-1) do ( execute ((MatrixLib.elementwiseMult(Sequence{ 0 }, (i + 1))) : a) ; a[i+1]->first() := 1 ; a[i+1]->last() := 1) ; for i : Integer.subrange(0, n-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): print(1) for i in range(int(input())-1): print(1,*[0]*i,1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (1)->display() ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger() - 1-1) do ( execute (1)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from decimal import Decimal t=int(input()) for i in range(t): n=int(input()) ans="" for j in range(1,n+1): for k in range(1,j+1): if k==1 or k==j : ans+="1 " else : ans+="0 " ans+="\n" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : String := "" ; for j : Integer.subrange(1, n + 1-1) do ( for k : Integer.subrange(1, j + 1-1) do ( if k = 1 or k = j then ( ans := ans + "1 " ) else ( ans := ans + "0 " )) ; ans := ans + "\n") ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bin(n): if(n>1): bin(n>>1) print(n & 1,end="") bin(131) print() bin(3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; bin(131) ; execute (->display() ; bin(3); operation bin(n : OclAny) pre: true post: true activity: if (n > 1) then ( bin(n /(2->pow(1))) ) else skip ; execute (MathLib.bitwiseAnd(n, 1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1001 while True : m=int(input()) if m==0 : break ab=[0] for i in range(m): ab.append(list(map(int,input().split()))) dp=[[0 for j in range(MAX)]for r in range(8)] dp[0][0]=1 for i in range(1,m+1): for j in range(MAX): if dp[i-1][j]==0 : continue ; s=j for k in range(ab[i][1],-1,-1): if stoInteger() ; if m = 0 then ( break ) else skip ; var ab : Sequence := Sequence{ 0 } ; for i : Integer.subrange(0, m-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : ab)) ; var dp : Sequence := Integer.subrange(0, 8-1)->select(r | true)->collect(r | (Integer.subrange(0, MAX-1)->select(j | true)->collect(j | (0)))) ; dp->first()->first() := 1 ; for i : Integer.subrange(1, m + 1-1) do ( for j : Integer.subrange(0, MAX-1) do ( if dp[i - 1+1][j+1] = 0 then ( continue; ) else skip ; var s : OclAny := j ; for k : Integer.subrange(-1 + 1, ab[i+1][1+1])->reverse() do ( if (s->compareTo(MAX)) < 0 then ( dp[i+1][s+1] := dp[i+1][s+1] + dp[i - 1+1][j+1] ) else skip ; s := s + ab[i+1]->first()))) ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (dp[m+1][("" + (((OclFile["System.in"]).readLine())))->toInteger()+1])->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) pow2=[1] for _ in range(3): pow2.append(2*pow2[-1]) inf=pow(10,9)+1 dp=[inf]*8 dp[0]=0 for _ in range(n): c,s=input().rstrip().split() c=int(c) x=0 for i in s : x ^=pow2[i-65] for i in range(7): j=i | x dp[j]=min(dp[j],dp[i]+c) ans=(dp[7]+1)%(inf+1)-1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var pow2 : Sequence := Sequence{ 1 } ; for _anon : Integer.subrange(0, 3-1) do ( execute ((2 * pow2->last()) : pow2)) ; var Math_PINFINITY : double := (10)->pow(9) + 1 ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ Math_PINFINITY }, 8) ; dp->first() := 0 ; for _anon : Integer.subrange(0, n-1) do ( var c : OclAny := null; var s : OclAny := null; Sequence{c,s} := input().rstrip().split() ; var c : int := ("" + ((c)))->toInteger() ; var x : int := 0 ; for i : s do ( x := x xor pow2[i - 65+1]) ; for i : Integer.subrange(0, 7-1) do ( var j : int := MathLib.bitwiseOr(i, x) ; dp[j+1] := Set{dp[j+1], dp[i+1] + c}->min())) ; var ans : double := (dp[7+1] + 1) mod (Math_PINFINITY + 1) - 1 ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): ans=sum(x for x in range(1000)if(x % 3==0 or x % 5==0)) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name x)))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1000))))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (expr (atom (name x))) % (expr (atom (number (integer 3)))))) == (comparison (expr (atom (number (integer 0))))))) or (logical_test (comparison (comparison (expr (expr (atom (name x))) % (expr (atom (number (integer 5)))))) == (comparison (expr (atom (number (integer 0)))))))))) ))))))))))->sum() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() S=input() A=S.count print('1 '*A('n')+'0 '*A('z')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var S : String := (OclFile["System.in"]).readLine() ; var A : OclAny := S.count ; execute (StringLib.nCopies('1 ', A('n')) + StringLib.nCopies('0 ', A('z')))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(s): cnt={} for c in s : if c in cnt : cnt[c]+=1 else : cnt[c]=1 z=0 if 'z' in cnt : z=cnt['z'] nol=[] for i in range(z): nol.append('0') o=0 if 'n' in cnt : o=cnt['n'] satu=[] for i in range(o): satu.append('1') ret='' if len(satu)>0 : ret+=' '.join(satu) if len(nol)>0 : if len(ret)>0 : ret+=' ' ret+=' '.join(nol) return ret input() print(solve(input())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; input() ; execute (solve((OclFile["System.in"]).readLine()))->display(); operation solve(s : OclAny) : OclAny pre: true post: true activity: var cnt : OclAny := Set{} ; for c : s do ( if (cnt)->includes(c) then ( cnt[c+1] := cnt[c+1] + 1 ) else ( cnt[c+1] := 1 )) ; var z : int := 0 ; if (cnt)->includes('z') then ( z := cnt->at('z') ) else skip ; var nol : Sequence := Sequence{} ; for i : Integer.subrange(0, z-1) do ( execute (('0') : nol)) ; var o : int := 0 ; if (cnt)->includes('n') then ( o := cnt->at('n') ) else skip ; var satu : Sequence := Sequence{} ; for i : Integer.subrange(0, o-1) do ( execute (('1') : satu)) ; var ret : String := '' ; if (satu)->size() > 0 then ( ret := ret + StringLib.sumStringsWithSeparator((satu), ' ') ) else skip ; if (nol)->size() > 0 then ( if (ret)->size() > 0 then ( ret := ret + ' ' ) else skip ; ret := ret + StringLib.sumStringsWithSeparator((nol), ' ') ) else skip ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) z=input() for i in range(z.count('n')): print(1,end=' ') for i in range(z.count('z')): print(0,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var z : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, z->count('n')-1) do ( execute (1)->display()) ; for i : Integer.subrange(0, z->count('z')-1) do ( execute (0)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- length=input() string=input() countingZeros=string.count('z') countingOnes=string.count('n') counter0=0 counter1=0 list=[] for i in range(countingOnes): if counter1!=countingOnes : list.append('1') counter1+=1 for i in range(countingZeros): if counter0!=countingZeros : list.append('0') counter0+=1 print(' '.join(list)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var length : String := (OclFile["System.in"]).readLine() ; var string : String := (OclFile["System.in"]).readLine() ; var countingZeros : int := string->count('z') ; var countingOnes : int := string->count('n') ; var counter0 : int := 0 ; var counter1 : int := 0 ; var OclType["Sequence"] : Sequence := Sequence{} ; for i : Integer.subrange(0, countingOnes-1) do ( if counter1 /= countingOnes then ( execute (('1') : OclType["Sequence"]) ) else skip ; counter1 := counter1 + 1) ; for i : Integer.subrange(0, countingZeros-1) do ( if counter0 /= countingZeros then ( execute (('0') : OclType["Sequence"]) ) else skip ; counter0 := counter0 + 1) ; execute (StringLib.sumStringsWithSeparator((OclType["Sequence"]), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=input() c=[] d=b.count('o') for x in range(b.count('n')): c.append('1') d-=b.count('n') for x in range(d): c.append('0') print(*c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : String := (OclFile["System.in"]).readLine() ; var c : Sequence := Sequence{} ; var d : int := b->count('o') ; for x : Integer.subrange(0, b->count('n')-1) do ( execute (('1') : c)) ; d := d - b->count('n') ; for x : Integer.subrange(0, d-1) do ( execute (('0') : c)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name c))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) print(b*2-a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (b * 2 - a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ABC_76_A(): R=int(input()) G=int(input()) print(2*G-R) if __name__=='__main__' : ABC_76_A() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( ABC_76_A() ) else skip; operation ABC_76_A() pre: true post: true activity: var R : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var G : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (2 * G - R)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(-int(input())+2*int(input())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (-("" + (((OclFile["System.in"]).readLine())))->toInteger() + 2 * ("" + (((OclFile["System.in"]).readLine())))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math N,P=map(int,input().split()) A=list(map(int,input().split())) B=[e % 2 for e in A] ans=pow(2,B.count(0)) def nCr(n,r): return(math.factorial(n)//(math.factorial(r)*math.factorial(n-r))) t=0 for k in range(B.count(1)+1): if k % 2==0 : t+=nCr(B.count(1),k) print(ans*t if P==0 else pow(2,N)-ans*t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var P : OclAny := null; Sequence{N,P} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var B : Sequence := A->select(e | true)->collect(e | (e mod 2)) ; var ans : double := (2)->pow(B->count(0)) ; skip ; var t : int := 0 ; for k : Integer.subrange(0, B->count(1) + 1-1) do ( if k mod 2 = 0 then ( t := t + nCr(B->count(1), k) ) else skip) ; execute (if P = 0 then ans * t else (2)->pow(N) - ans * t endif)->display(); operation nCr(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: return (MathLib.factorial(n) div (MathLib.factorial(r) * MathLib.factorial(n - r))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findTime(T,K): minutes=(((ord(T[0])-ord('0'))*10+ord(T[1])-ord('0'))*60+((ord(T[3])-ord('0'))*10+ord(T[4])-ord('0'))); minutes+=K hour=(int(minutes/60))% 24 min=minutes % 60 if(hour<10): print(0,hour,":",end=" ") else : print(hour,":",end=" ") if(min<10): print(0,min,end=" ") else : print(min,end=" ") if __name__=='__main__' : T="21:39" K=43 findTime(T,K) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( T := "21:39" ; K := 43 ; findTime(T, K) ) else skip; operation findTime(T : OclAny, K : OclAny) pre: true post: true activity: var minutes : double := ((((T->first())->char2byte() - ('0')->char2byte()) * 10 + (T[1+1])->char2byte() - ('0')->char2byte()) * 60 + (((T[3+1])->char2byte() - ('0')->char2byte()) * 10 + (T[4+1])->char2byte() - ('0')->char2byte())); ; minutes := minutes + K ; var hour : int := (("" + ((minutes / 60)))->toInteger()) mod 24 ; var min : int := minutes mod 60 ; if (hour < 10) then ( execute (0)->display() ) else ( execute (hour)->display() ) ; if (min < 10) then ( execute (0)->display() ) else ( execute (min)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=[int(input())for i in range(2)] print(b-a+b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Integer.subrange(0, 2-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; execute (b - a + b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import inf from collections import defaultdict from email.policy import default from tracemalloc import take_snapshot def dp(i,mask): if mask==7 : return 0 if i>=len(keys): return float('inf') take=dp(i+1,mask | keys[i])+bitMask[keys[i]] not_take=dp(i+1,mask) return min(take,not_take) def getBitMask(word): mask=0 for i in word : if i=='A' : mask=mask | 1 if i=='B' : mask=mask | 2 if i=='C' : mask=mask | 4 return mask if __name__=='__main__' : bitMask=defaultdict(lambda : float('inf')) for _ in range(int(input())): price,vitamin=input().split() v_mask=getBitMask(vitamin) bitMask[v_mask]=min(bitMask[v_mask],int(price)) keys=list(bitMask.keys()) ans=dp(0,0) ans=-1 if ans==float('inf')else ans print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var bitMask : OclAny := defaultdict(lambda $$ : OclAny in (("" + (('inf')))->toReal())) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var price : OclAny := null; var vitamin : OclAny := null; Sequence{price,vitamin} := input().split() ; var v_mask : OclAny := getBitMask(vitamin) ; bitMask[v_mask+1] := Set{bitMask[v_mask+1], ("" + ((price)))->toInteger()}->min()) ; var keys : Sequence := (bitMask.keys()) ; var ans : OclAny := dp(0, 0) ; ans := if ans = ("" + (('inf')))->toReal() then -1 else ans endif ; execute (ans)->display() ) else skip; operation dp(i : OclAny, mask : OclAny) : OclAny pre: true post: true activity: if mask = 7 then ( return 0 ) else skip ; if (i->compareTo((keys)->size())) >= 0 then ( return ("" + (('inf')))->toReal() ) else skip ; var take : OclAny := dp(i + 1, MathLib.bitwiseOr(mask, keys[i+1])) + bitMask[keys[i+1]+1] ; var not_take : OclAny := dp(i + 1, mask) ; return Set{take, not_take}->min(); operation getBitMask(word : OclAny) : OclAny pre: true post: true activity: mask := 0 ; for i : word do ( if i = 'A' then ( mask := MathLib.bitwiseOr(mask, 1) ) else skip ; if i = 'B' then ( mask := MathLib.bitwiseOr(mask, 2) ) else skip ; if i = 'C' then ( mask := MathLib.bitwiseOr(mask, 4) ) else skip) ; return mask; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=int(input()) G=int(input()) if 0<=R and G<=4500 : print(G*2-R) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var G : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if 0 <= R & G <= 4500 then ( execute (G * 2 - R)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Circular(n): Result=1 while n>0 : Result=Result*n n-=1 return Result if __name__=="__main__" : n=4 print(Circular(n-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 4 ; execute (Circular(n - 1))->display() ) else skip; operation Circular(n : OclAny) : OclAny pre: true post: true activity: var Result : int := 1 ; while n > 0 do ( Result := Result * n ; n := n - 1) ; return Result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def productDiagonals(arr,n): product=1 ; for i in range(n): product=product*arr[i][i]; product=product*arr[i][n-i-1]; if(n % 2==1): product=product//arr[n//2][n//2]; return product ; if __name__=='__main__' : arr1=[[1,2,3,4],[5,6,7,8],[9,7,4,2],[2,2,2,1]]; print(productDiagonals(arr1,4)); arr2=[[2,1,2,1,2],[1,2,1,2,1],[2,1,2,1,2],[1,2,1,2,1],[2,1,2,1,2]]; print(productDiagonals(arr2,5)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var arr1 : Sequence := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })))}->union(Sequence{Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 8 })))}->union(Sequence{Sequence{9}->union(Sequence{7}->union(Sequence{4}->union(Sequence{ 2 })))}->union(Sequence{ Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 1 }))) }))); ; execute (productDiagonals(arr1, 4))->display(); ; var arr2 : Sequence := Sequence{Sequence{2}->union(Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{ 2 }))))}->union(Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 1 }))))}->union(Sequence{Sequence{2}->union(Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{ 2 }))))}->union(Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 1 }))))}->union(Sequence{ Sequence{2}->union(Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{ 2 })))) })))); ; execute (productDiagonals(arr2, 5))->display(); ) else skip; operation productDiagonals(arr : OclAny, n : OclAny) pre: true post: true activity: var product : int := 1; ; for i : Integer.subrange(0, n-1) do ( product := product * arr[i+1][i+1]; ; product := product * arr[i+1][n - i - 1+1];) ; if (n mod 2 = 1) then ( product := product div arr[n div 2+1][n div 2+1]; ) else skip ; return product;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break dic={0 : 0,1 : 0,2 : 0,3 : 0,4 : 0,5 : 0,6 : 0,7 : 0,8 : 0,9 : 0} for _ in range(n): c=int(input()) dic[c]+=1 for v in dic.values(): print('*'*v if v!=0 else '-') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var dic : Map := Map{ 0 |-> 0 }->union(Map{ 1 |-> 0 }->union(Map{ 2 |-> 0 }->union(Map{ 3 |-> 0 }->union(Map{ 4 |-> 0 }->union(Map{ 5 |-> 0 }->union(Map{ 6 |-> 0 }->union(Map{ 7 |-> 0 }->union(Map{ 8 |-> 0 }->union(Map{ 9 |-> 0 }))))))))) ; for _anon : Integer.subrange(0, n-1) do ( var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; dic[c+1] := dic[c+1] + 1) ; for v : dic.values() do ( execute (if v /= 0 then StringLib.nCopies('*', v) else '-' endif)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pri(x): if x>0 : print('*'*x) else : print('-') while True : n=int(input()) if n==0 : break a=[] b=c=d=e=f=g=h=k=l=m=0 for i in range(n): a.append(int(input())) a.sort() for j in range(n): if a[j]==0 : b+=1 if a[j]==1 : c+=1 if a[j]==2 : d+=1 if a[j]==3 : e+=1 if a[j]==4 : f+=1 if a[j]==5 : g+=1 if a[j]==6 : h+=1 if a[j]==7 : k+=1 if a[j]==8 : l+=1 if a[j]==9 : m+=1 pri(b) pri(c) pri(d) pri(e) pri(f) pri(g) pri(h) pri(k) pri(l) pri(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var a : Sequence := Sequence{} ; b := b(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name e)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name f)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name g)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name h)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name k)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name m)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : a)) ; a := a->sort() ; for j : Integer.subrange(0, n-1) do ( if a[j+1] = 0 then ( b := b + 1 ) else skip ; if a[j+1] = 1 then ( c := c + 1 ) else skip ; if a[j+1] = 2 then ( d := d + 1 ) else skip ; if a[j+1] = 3 then ( e := e + 1 ) else skip ; if a[j+1] = 4 then ( f := f + 1 ) else skip ; if a[j+1] = 5 then ( g := g + 1 ) else skip ; if a[j+1] = 6 then ( h := h + 1 ) else skip ; if a[j+1] = 7 then ( k := k + 1 ) else skip ; if a[j+1] = 8 then ( l := l + 1 ) else skip ; if a[j+1] = 9 then ( m := m + 1 ) else skip) ; pri(b) ; pri(c) ; pri(d) ; pri(e) ; pri(f) ; pri(g) ; pri(h) ; pri(k) ; pri(l) ; pri(m)); operation pri(x : OclAny) pre: true post: true activity: if x > 0 then ( execute (StringLib.nCopies('*', x))->display() ) else ( execute ('-')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(20): n=int(input()) if n==0 : break a=[0]*10 for i in range(n): b=int(input()) a[b]+=1 for b in a : if b>0 : print("*"*b) else : print("-") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, 20-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; for i : Integer.subrange(0, n-1) do ( var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a[b+1] := a[b+1] + 1) ; for b : a do ( if b > 0 then ( execute (StringLib.nCopies("*", b))->display() ) else ( execute ("-")->display() ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : a=int(input()) if a==0 : break else : L=[] for i in range(a): b=int(input()) L.append(b) i+=1 for j in range(10): c=L.count(j) if c==0 : print("-") else : for k in range(c): print("*",end="") k+=1 print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if a = 0 then ( break ) else ( var L : Sequence := Sequence{} ; for i : Integer.subrange(0, a-1) do ( var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((b) : L) ; i := i + 1) ; for j : Integer.subrange(0, 10-1) do ( var c : int := L->count(j) ; if c = 0 then ( execute ("-")->display() ) else ( for k : Integer.subrange(0, c-1) do ( execute ("*")->display() ; k := k + 1) ; execute (->display() )) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d_init=[0]*10 while True : data=d_init[:] n=int(input()) if n==0 : break for _ in range(n): in_data=int(input()) data[in_data]+=1 for d in data : if d==0 : print("-") else : print("*"*d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d_init : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; while true do ( var data : Sequence := d_init ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; for _anon : Integer.subrange(0, n-1) do ( var in_data : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; data[in_data+1] := data[in_data+1] + 1) ; for d : data do ( if d = 0 then ( execute ("-")->display() ) else ( execute (StringLib.nCopies("*", d))->display() ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def maxProductSum(string,m): n=len(string) maxProd,maxSum=(-(sys.maxsize)-1,-(sys.maxsize)-1) for i in range(n-m): product,sum=1,0 for j in range(i,m+i): product=product*(ord(string[j])-ord('0')) sum=sum+(ord(string[j])-ord('0')) maxProd=max(maxProd,product) maxSum=max(maxSum,sum) print("Maximum Product=",maxProd) print("Maximum sum=",maxSum) if __name__=="__main__" : string="3675356291" m=5 maxProductSum(string,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( string := "3675356291" ; m := 5 ; maxProductSum(string, m) ) else skip; operation maxProductSum(string : OclAny, m : OclAny) pre: true post: true activity: var n : int := (string)->size() ; var maxProd : OclAny := null; var maxSum : OclAny := null; Sequence{maxProd,maxSum} := Sequence{-((trailer . (name maxsize))) - 1, -((trailer . (name maxsize))) - 1} ; for i : Integer.subrange(0, n - m-1) do ( var product : OclAny := null; var sum : OclAny := null; Sequence{product,sum} := Sequence{1,0} ; for j : Integer.subrange(i, m + i-1) do ( var product : double := product * ((string[j+1])->char2byte() - ('0')->char2byte()) ; var sum : OclAny := sum + ((string[j+1])->char2byte() - ('0')->char2byte())) ; var maxProd : OclAny := Set{maxProd, product}->max() ; var maxSum : OclAny := Set{maxSum, sum}->max()) ; execute ("Maximum Product=")->display() ; execute ("Maximum sum=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getSecondMostFreq(str): NO_OF_CHARS=256 count=[0]*NO_OF_CHARS for i in range(len(str)): count[ord(str[i])]+=1 first,second=0,0 for i in range(NO_OF_CHARS): if count[i]>count[first]: second=first first=i elif(count[i]>count[second]and count[i]!=count[first]): second=i return chr(second) if __name__=="__main__" : str="geeksforgeeks" res=getSecondMostFreq(str) if res!='\0' : print("Second most frequent char is",res) else : print("No second most frequent character") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( OclType["String"] := "geeksforgeeks" ; var res : OclAny := getSecondMostFreq(OclType["String"]) ; if res /= '\0' then ( execute ("Second most frequent char is")->display() ) else ( execute ("No second most frequent character")->display() ) ) else skip; operation getSecondMostFreq(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var NO_OF_CHARS : int := 256 ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, NO_OF_CHARS) ; for i : Integer.subrange(0, (OclType["String"])->size()-1) do ( count[(("" + ([i+1])))->char2byte()+1] := count[(("" + ([i+1])))->char2byte()+1] + 1) ; var first : OclAny := null; var second : OclAny := null; Sequence{first,second} := Sequence{0,0} ; for i : Integer.subrange(0, NO_OF_CHARS-1) do ( if (count[i+1]->compareTo(count[first+1])) > 0 then ( var second : OclAny := first ; var first : OclAny := i ) else (if ((count[i+1]->compareTo(count[second+1])) > 0 & count[i+1] /= count[first+1]) then ( second := i ) else skip)) ; return (second)->byte2char(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[0]*4001 for i in range(2001): a[i]=a[4000-i]=(i+3)*(i+2)*(i+1)//6-4*a[i-1001]*(i>999) while 1 : try : print(a[int(input())]) except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 4001) ; for i : Integer.subrange(0, 2001-1) do ( a[i+1] := (i + 3) * (i + 2) * (i + 1) div 6 - 4 * a[i - 1001+1] * (i > 999); var a[4000 - i+1] : double := (i + 3) * (i + 2) * (i + 1) div 6 - 4 * a[i - 1001+1] * (i > 999)) ; while 1 do ( try ( execute (a[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1])->display()) catch (_e : OclException) do ( break) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ma=lambda : map(int,input().split()) lma=lambda : list(map(int,input().split())) ni=lambda : int(input()) yn=lambda fl : print("Yes")if fl else print("No") import collections import math import itertools import heapq as hq class unionfind(): def __init__(self,n): self.par=list(range(n)) self.size=[1]*n self.rank=[0]*n def root(self,x): if self.par[x]==x : return x else : self.par[x]=self.root(self.par[x]) return self.par[x] def same(self,x,y): return self.root(x)==self.root(y) def unite(self,x,y): x=self.root(x) y=self.root(y) if x==y : return else : if self.rank[x]exists( _x | result = _x ); attribute par : Sequence := (Integer.subrange(0, n-1)); attribute size : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, n); attribute rank : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); operation initialise(n : OclAny) : pre: true post: true activity: self.par := (Integer.subrange(0, n-1)) ; self.size := MatrixLib.elementwiseMult(Sequence{ 1 }, n) ; self.rank := MatrixLib.elementwiseMult(Sequence{ 0 }, n); return self; operation root(x : OclAny) : OclAny pre: true post: true activity: if self.par[x+1] = x then ( return x ) else ( self.par[x+1] := self.root(self.par[x+1]) ; return self.par[x+1] ); operation same(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: return self.root(x) = self.root(y); operation unite(x : OclAny,y : OclAny) pre: true post: true activity: x := self.root(x) ; y := self.root(y) ; if x = y then ( return ) else ( if (self.rank[x+1]->compareTo(self.rank[y+1])) < 0 then ( Sequence{x,y} := Sequence{y,x} ) else skip ; if self.rank[x+1] = self.rank[y+1] then ( self.rank[x+1] := self.rank[x+1] + 1 ) else skip ; self.par[y+1] := x ; self.size[x+1] := self.size[x+1] + self.size[y+1] ); operation get_size(x : OclAny) : OclAny pre: true post: true activity: x := self.root(x) ; return self.size[x+1]; } class FromPython { operation initialise() pre: true post: true activity: var ma : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lma : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ni : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var yn : Function := lambda fl : OclAny in (if fl then ("Yes")->display() else ("No")->display() endif) ; skip ; skip ; skip ; skip ; skip ; var m : OclAny := null; Sequence{n,m} := ma->apply() ; var P : OclAny := lma->apply() ; var uf : unionfind := (unionfind.newunionfind()).initialise(n + 1) ; for i : Integer.subrange(0, m-1) do ( Sequence{x,y} := ma->apply() ; uf.unite(x, y)) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if uf.same(i + 1, P[i+1]) then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ips=set() for i in range(n): inp=input() ips.add(tuple(inp.split(' '))) res=float('inf') ips=list(ips) def find(t,a,b,c,total,start=0): if all([a,b,c]): global res res=min(res,total) else : for i in range(start,len(t)): na,nb,nc=a,b,c if not a : na=1 if 'A' in t[i][1]else 0 if not b : nb=1 if 'B' in t[i][1]else 0 if not c : nc=1 if 'C' in t[i][1]else 0 if total+int(t[i][0])toInteger() ; var ips : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( var inp : String := (OclFile["System.in"]).readLine() ; execute (((inp.split(' '))) : ips)) ; var res : double := ("" + (('inf')))->toReal() ; ips := (ips) ; skip ; find(ips, 0, 0, 0, 0) ; execute (if res /= ("" + (('inf')))->toReal() then res else -1 endif)->display(); operation find(t : OclAny, a : OclAny, b : OclAny, c : OclAny, total : OclAny, start : int) pre: true post: true activity: if start->oclIsUndefined() then start := 0 else skip; if (Sequence{a}->union(Sequence{b}->union(Sequence{ c })))->forAll( _x | _x = true ) then ( skip ; res := Set{res, total}->min() ) else ( for i : Integer.subrange(start, (t)->size()-1) do ( var na : OclAny := null; var nb : OclAny := null; var nc : OclAny := null; Sequence{na,nb,nc} := Sequence{a,b,c} ; if not(a) then ( var na : int := if (t[i+1][1+1])->includes('A') then 1 else 0 endif ) else skip ; if not(b) then ( var nb : int := if (t[i+1][1+1])->includes('B') then 1 else 0 endif ) else skip ; if not(c) then ( var nc : int := if (t[i+1][1+1])->includes('C') then 1 else 0 endif ) else skip ; if (total + ("" + ((t[i+1]->first())))->toInteger()->compareTo(res)) < 0 then ( find(t, na, nb, nc, total + ("" + ((t[i+1]->first())))->toInteger(), i + 1) ) else skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin from collections import defaultdict input=stdin.readline def main(args): lut=defaultdict(int) for a in range(1001): for b in range(1001): lut[a+b]+=1 for line in sys.stdin : n=int(line) ans=0 for i in range(n+1): ans+=lut[i]*lut[n-i] print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := stdin.readline ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation main(args : OclAny) pre: true post: true activity: var lut : OclAny := defaultdict(OclType["int"]) ; for a : Integer.subrange(0, 1001-1) do ( for b : Integer.subrange(0, 1001-1) do ( lut[a + b+1] := lut[a + b+1] + 1)) ; for line : OclFile["System.in"] do ( var n : int := ("" + ((line)))->toInteger() ; var ans : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( ans := ans + lut[i+1] * lut[n - i+1]) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- M=1000 DM=M*2+1 def count(n): global M res=n+1 if n>M : res-=(n-M)*2 return res def solve(n): cnt=0 for a in range(min(DM,n),-1,-1): b=n-a if b>DM : break cnt+=count(a)*count(b) return cnt while True : try : l=input() except EOFError : break nm=int(l) print(solve(nm)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute M : OclAny; operation initialise() pre: true post: true activity: var M : int := 1000 ; var DM : int := M * 2 + 1 ; skip ; skip ; while true do ( try ( var l : String := (OclFile["System.in"]).readLine()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))) ; var nm : int := ("" + ((l)))->toInteger() ; execute (solve(nm))->display()); operation count(n : OclAny) : OclAny pre: true post: true activity: skip ; var res : OclAny := n + 1 ; if (n->compareTo(M)) > 0 then ( res := res - (n - M) * 2 ) else skip ; return res; operation solve(n : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; for a : Integer.subrange(-1 + 1, Set{DM, n}->min())->reverse() do ( var b : double := n - a ; if (b->compareTo(DM)) > 0 then ( break ) else skip ; cnt := cnt + count(a) * count(b)) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys for line in sys.stdin.readlines(): n=int(line.rstrip()) count=0 for i in range(1001): if 0<=n-i<=1000 : count+=(n-i+1)*(i+1) elif 1001<=n-i<=2000 : count+=(2000-(n-i)+1)*(i+1) for i in range(1001,2001): if 0<=n-i<=1000 : count+=(n-i+1)*(2000-i+1) elif 1001<=n-i<=2000 : count+=(2000-(n-i)+1)*(2000-i+1) print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for line : (OclFile["System.in"]).readlines() do ( var n : int := ("" + ((StringLib.rightTrim(line))))->toInteger() ; var count : int := 0 ; for i : Integer.subrange(0, 1001-1) do ( if 0 <= n - i & (n - i <= 1000) then ( count := count + (n - i + 1) * (i + 1) ) else (if 1001 <= n - i & (n - i <= 2000) then ( count := count + (2000 - (n - i) + 1) * (i + 1) ) else skip)) ; for i : Integer.subrange(1001, 2001-1) do ( if 0 <= n - i & (n - i <= 1000) then ( count := count + (n - i + 1) * (2000 - i + 1) ) else (if 1001 <= n - i & (n - i <= 2000) then ( count := count + (2000 - (n - i) + 1) * (2000 - i + 1) ) else skip)) ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n_list=[] while True : try : n_list.append(int(input())) except : break for n in n_list : sum_list=list(range(1,1001))+list(range(1001,0,-1)) ans=0 for i in range(min(n+1,2001)): if 0<=(n-i)<=2000 : ans+=sum_list[i]*sum_list[n-i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n_list : Sequence := Sequence{} ; while true do ( try ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : n_list)) catch (_e : OclException) do ( break) ) ; for n : n_list do ( var sum_list : Sequence := (Integer.subrange(1, 1001-1))->union((Integer.subrange(0 + 1, 1001)->reverse())) ; var ans : int := 0 ; for i : Integer.subrange(0, Set{n + 1, 2001}->min()-1) do ( if 0 <= (n - i) & ((n - i) <= 2000) then ( ans := ans + sum_list[i+1] * sum_list[n - i+1] ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def mySort(arr,n): arr1=arr[: n//2] arr2=arr[n//2 :] arr1.sort() arr2.sort(reverse=True) return arr1+arr2 if __name__=='__main__' : arr=[5,4,6,2,1,3,8,9,7] n=len(arr) arr=mySort(arr,n) print("Modified Array : ") print(arr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{5}->union(Sequence{4}->union(Sequence{6}->union(Sequence{2}->union(Sequence{1}->union(Sequence{3}->union(Sequence{8}->union(Sequence{9}->union(Sequence{ 7 })))))))) ; n := (arr)->size() ; arr := mySort(arr, n) ; execute ("Modified Array : ")->display() ; execute (arr)->display() ) else skip; operation mySort(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var arr1 : OclAny := arr.subrange(1,n div 2) ; var arr2 : OclAny := arr.subrange(n div 2+1) ; arr1 := arr1->sort() ; arr2 := arr2->sort() ; return arr1 + arr2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minflip(arr1,arr2,arr3,p,q,n): flip=0 for i in range(0,n): if(arr1[i]^ arr2[i]!=arr3[i]): flip+=1 return flip if(flip<=p+q)else-1 arr1=[1,0,1,1,1,1,1] arr2=[0,1,1,1,1,0,0] arr3=[1,1,1,1,0,0,1] n=len(arr1) p=2 q=4 print(minflip(arr1,arr2,arr3,p,q,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr1 := Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })))))) ; arr2 := Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 0 })))))) ; arr3 := Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 1 })))))) ; n := (arr1)->size() ; p := 2 ; q := 4 ; execute (minflip(arr1, arr2, arr3, p, q, n))->display(); operation minflip(arr1 : OclAny, arr2 : OclAny, arr3 : OclAny, p : OclAny, q : OclAny, n : OclAny) : OclAny pre: true post: true activity: var flip : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (MathLib.bitwiseXor(arr1[i+1], arr2[i+1]) /= arr3[i+1]) then ( flip := flip + 1 ) else skip) ; return if ((flip->compareTo(p + q)) <= 0) then flip else -1 endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) N2=2**N S=list(map(int,input().split())) S.sort(reverse=True) slimes=[S[0]] INF=S[0]+1 S[0]=INF num=1 min_idx=1 for i in range(N): slimes.sort() n=num idx=min_idx is_continuous=True while n and idx<=N2-1 : if S[idx]toInteger() ; var N2 : double := (2)->pow(N) ; var S : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; S := S->sort() ; var slimes : Sequence := Sequence{ S->first() } ; var INF : OclAny := S->first() + 1 ; S->first() := INF ; var num : int := 1 ; var min_idx : int := 1 ; for i : Integer.subrange(0, N-1) do ( slimes := slimes->sort() ; var n : int := num ; var idx : int := min_idx ; var is_continuous : boolean := true ; while n & (idx->compareTo(N2 - 1)) <= 0 do ( if (S[idx+1]->compareTo(slimes[n - 1+1])) < 0 then ( execute ((S[idx+1]) : slimes) ; S[idx+1] := INF ; idx := idx + 1 ; n := n - 1 ; min_idx := min_idx + is_continuous ) else ( if (S[idx+1]->compareTo(INF)) < 0 then ( is_continuous := false ) else skip ; idx := idx + 1 ; min_idx := min_idx + is_continuous )) ; if n then ( execute ('No')->display() ; quit() ) else skip ; num := num * 2) ; execute ('Yes')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sum(n): i=1 s=0.0 for i in range(1,n+1): s=s+1/i ; return s ; n=5 print("Sum is",round(sum(n),6)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; execute ("Sum is")->display(); operation sum(n : OclAny) pre: true post: true activity: var i : int := 1 ; var s : double := 0.0 ; for i : Integer.subrange(1, n + 1-1) do ( s := s + 1 / i;) ; return s;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def side(a,b,c): return(c[1]-a[1])*(b[0]-a[0])-(b[1]-a[1])*(c[0]-a[0])>0 def isInner(x): return(side(p0,p1,x)==side(p1,p2,x)==side(p2,p0,x)) for _ in[0]*input(): P=map(int,raw_input().split()) p0=P[0 : 2] p1=P[2 : 4] p2=P[4 : 6] x1=P[6 : 8] x2=P[8 :] print['NG','OK'][isInner(x1)!=isInner(x2)] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, (OclFile["System.in"]).readLine()) do ( var P : Sequence := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p0 : OclAny := P.subrange(0+1, 2) ; var p1 : OclAny := P.subrange(2+1, 4) ; var p2 : OclAny := P.subrange(4+1, 6) ; var x1 : OclAny := P.subrange(6+1, 8) ; var x2 : OclAny := P.subrange(8+1) ; (expr (atom print) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'NG')))))) , (subscript (test (logical_test (comparison (expr (atom 'OK'))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (comparison (expr (atom (name isInner)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x1)))))))) ))))) != (comparison (expr (atom (name isInner)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x2)))))))) )))))))))) ])))); operation side(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: return (c[1+1] - a[1+1]) * (b->first() - a->first()) - (b[1+1] - a[1+1]) * (c->first() - a->first()) > 0; operation isInner(x : OclAny) : OclAny pre: true post: true activity: return (side(p0, p1, x) = side(p1, p2, x) & (side(p1, p2, x) == side(p2, p0, x))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Vector : def __init__(self,x,y): self.x=x self.y=y def __sub__(self,other): return Vector(self.x-other.x,self.y-other.y) @ staticmethod def cross_product(point1,point2): return point1.x*point2.y-point1.y*point2.x class Triangle : def __init__(self,x1,y1,x2,y2,x3,y3): self.point1=Vector(x1,y1) self.point2=Vector(x2,y2) self.point3=Vector(x3,y3) def is_contain(self,point): line1=point-self.point1 line2=self.point2-self.point1 direct1=Vector.cross_product(line1,line2) line1=point-self.point2 line2=self.point3-self.point2 direct2=Vector.cross_product(line1,line2) line1=point-self.point3 line2=self.point1-self.point3 direct3=Vector.cross_product(line1,line2) if 0exists( _x | result = _x ); attribute x : OclAny := x; attribute y : OclAny := y; operation initialise(x : OclAny,y : OclAny) : Vector pre: true post: true activity: self.x := x ; self.y := y; return self; operation __sub__(other : OclAny) : OclAny pre: true post: true activity: return Vector(self.x - other.x, self.y - other.y); } class Triangle { static operation newTriangle() : Triangle pre: true post: Triangle->exists( _x | result = _x ); attribute point1 : Vector := (Vector.newVector()).initialise(x1, y1); attribute point2 : Vector := (Vector.newVector()).initialise(x2, y2); attribute point3 : Vector := (Vector.newVector()).initialise(x3, y3); operation initialise(x1 : OclAny,y1 : OclAny,x2 : OclAny,y2 : OclAny,x3 : OclAny,y3 : OclAny) : Triangle pre: true post: true activity: self.point1 := (Vector.newVector()).initialise(x1, y1) ; self.point2 := (Vector.newVector()).initialise(x2, y2) ; self.point3 := (Vector.newVector()).initialise(x3, y3); return self; operation is_contain(point : OclAny) : OclAny pre: true post: true activity: var line1 : double := point - self.point1 ; var line2 : double := self.point2 - self.point1 ; var direct1 : Vector := (Vector.newVector()).initialise.cross_product(line1, line2) ; line1 := point - self.point2 ; line2 := self.point3 - self.point2 ; var direct2 : Vector := (Vector.newVector()).initialise.cross_product(line1, line2) ; line1 := point - self.point3 ; line2 := self.point1 - self.point3 ; var direct3 : Vector := (Vector.newVector()).initialise.cross_product(line1, line2) ; if 0 < direct1 & 0 < direct2 & 0 < direct3 then ( return 1 ) else (if direct1 < 0 & direct2 < 0 & direct3 < 0 then ( return 1 ) else ( return -1 ) ) ; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var data : Sequence := input().split(" ")->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; var triangle : Triangle := (Triangle.newTriangle()).initialise(data->first(), data[1+1], data[2+1], data[3+1], data[4+1], data[5+1]) ; var altair_point : Vector := (Vector.newVector()).initialise(data[6+1], data[7+1]) ; var vega_point : Vector := (Vector.newVector()).initialise(data[8+1], data[9+1]) ; var is_contain1 : OclAny := triangle.is_contain(altair_point) ; var is_contain2 : OclAny := triangle.is_contain(vega_point) ; var result : double := is_contain1 * is_contain2 ; if result = -1 then ( execute ("OK")->display() ) else ( execute ("NG")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- EPS=1e-10 def crossP(aa,bb,cc,dd): a=(bb-aa).real b=(cc-dd).real c=(bb-aa).imag d=(cc-dd).imag e=(cc-aa).real f=(cc-aa).imag det=a*d-b*c if abs(det)toReal() ; skip ; skip ; if __name__ = '__main__' then ( var n : int := ("" + ((input()->trim())))->toInteger() ; for i : Integer.subrange(0, n-1) do (suite) ) else skip ; Sequence{xp1}->union(Sequence{yp1}->union(Sequence{xp2}->union(Sequence{yp2}->union(Sequence{xp3}->union(Sequence{yp3}->union(Sequence{xk}->union(Sequence{yk}->union(Sequence{xs}->union(Sequence{ ys }))))))))) := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ); operation crossP(aa : OclAny, bb : OclAny, cc : OclAny, dd : OclAny) : OclAny pre: true post: true activity: var a : OclAny := (bb - aa).real ; var b : OclAny := (cc - dd).real ; var c : OclAny := (bb - aa).imag ; var d : OclAny := (cc - dd).imag ; var e : OclAny := (cc - aa).real ; var f : OclAny := (cc - aa).imag ; var det : double := a * d - b * c ; if ((det)->abs()->compareTo(EPS)) < 0 then ( return (-9999 + (-9999) * 1j) ) else skip ; var x : double := (d * e - b * f) / det ; var y : double := (-c * e + a * f) / det ; return (x + y * 1j); operation rangeP(st : OclAny) : OclAny pre: true post: true activity: return ((0.0 <= st.real & (st.real <= 1.0)) & (0.0 <= st.imag & (st.imag <= 1.0))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def startsWith(str,pre): strLen=len(str) preLen=len(pre) i=0 j=0 while(i=0 and j>=0): if(str[i]!=suff[j]): return False i-=1 j-=1 return True def checkString(str,a,b): if(len(str)!=len(a)+len(b)): return False if(startsWith(str,a)): if(endsWith(str,b)): return True if(startsWith(str,b)): if(endsWith(str,a)): return True return False str="GeeksforGeeks" a="Geeksfo" b="rGeeks" if(checkString(str,a,b)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; OclType["String"] := "GeeksforGeeks" ; a := "Geeksfo" ; b := "rGeeks" ; if (checkString(OclType["String"], a, b)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation startsWith(OclType["String"] : OclAny, pre : OclAny) : OclAny pre: true post: true activity: var strLen : int := (OclType["String"])->size() ; var preLen : int := (pre)->size() ; var i : int := 0 ; var j : int := 0 ; while ((i->compareTo(strLen)) < 0 & (j->compareTo(preLen)) < 0) do ( if (("" + ([i+1])) /= pre[j+1]) then ( return false ) else skip ; i := i + 1 ; j := j + 1) ; return true; operation endsWith(OclType["String"] : OclAny, suff : OclAny) : OclAny pre: true post: true activity: i := (OclType["String"])->size() - 1 ; j := (suff)->size() - 1 ; while (i >= 0 & j >= 0) do ( if (("" + ([i+1])) /= suff[j+1]) then ( return false ) else skip ; i := i - 1 ; j := j - 1) ; return true; operation checkString(OclType["String"] : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if ((OclType["String"])->size() /= (a)->size() + (b)->size()) then ( return false ) else skip ; if (startsWith(OclType["String"], a)) then ( if (endsWith(OclType["String"], b)) then ( return true ) else skip ) else skip ; if (startsWith(OclType["String"], b)) then ( if (endsWith(OclType["String"], a)) then ( return true ) else skip ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def is_atSameSide(a,b,line): sa=(line[1].real-line[0].real)*(a.imag-line[0].imag)+(line[1].imag-line[0].imag)*(line[0].real-a.real); sb=(line[1].real-line[0].real)*(b.imag-line[0].imag)+(line[1].imag-line[0].imag)*(line[0].real-b.real); return(sa>0 and sb>0)or(sa<0 and sb<0) for i in range(int(input())): buf=list(map(int,input().split())) p1=complex(buf[0],buf[1]) p2=complex(buf[2],buf[3]) p3=complex(buf[4],buf[5]) pk=complex(buf[6],buf[7]) ps=complex(buf[8],buf[9]) kin=is_atSameSide(p3,pk,[p1,p2])& is_atSameSide(p1,pk,[p2,p3])& is_atSameSide(p2,pk,[p3,p1]) sin=is_atSameSide(p3,ps,[p1,p2])& is_atSameSide(p1,ps,[p2,p3])& is_atSameSide(p2,ps,[p3,p1]) print("OK" if kin ^ sin else "NG") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var buf : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var p1 : OclAny := complex(buf->first(), buf[1+1]) ; var p2 : OclAny := complex(buf[2+1], buf[3+1]) ; var p3 : OclAny := complex(buf[4+1], buf[5+1]) ; var pk : OclAny := complex(buf[6+1], buf[7+1]) ; var ps : OclAny := complex(buf[8+1], buf[9+1]) ; var kin : int := MathLib.bitwiseAnd(MathLib.bitwiseAnd(is_atSameSide(p3, pk, Sequence{p1}->union(Sequence{ p2 })), is_atSameSide(p1, pk, Sequence{p2}->union(Sequence{ p3 }))), is_atSameSide(p2, pk, Sequence{p3}->union(Sequence{ p1 }))) ; var sin : int := MathLib.bitwiseAnd(MathLib.bitwiseAnd(is_atSameSide(p3, ps, Sequence{p1}->union(Sequence{ p2 })), is_atSameSide(p1, ps, Sequence{p2}->union(Sequence{ p3 }))), is_atSameSide(p2, ps, Sequence{p3}->union(Sequence{ p1 }))) ; execute (if MathLib.bitwiseXor(kin, sin) then "OK" else "NG" endif)->display()); operation is_atSameSide(a : OclAny, b : OclAny, line : OclAny) : OclAny pre: true post: true activity: var sa : double := (line[1+1].real - line->first().real) * (a.imag - line->first().imag) + (line[1+1].imag - line->first().imag) * (line->first().real - a.real); ; var sb : double := (line[1+1].real - line->first().real) * (b.imag - line->first().imag) + (line[1+1].imag - line->first().imag) * (line->first().real - b.real); ; return (sa > 0 & sb > 0) or (sa < 0 & sb < 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sign(p1,p2,p3): return(p1[0]-p3[0])*(p2[1]-p3[1])-(p2[0]-p3[0])*(p1[1]-p3[1]) def check(triangle,pt): v1=[triangle[0],triangle[1]] v2=[triangle[2],triangle[3]] v3=[triangle[4],triangle[5]] b1=sign(pt,v1,v2) if b1>0 : flag1=1 else : flag1=0 b2=sign(pt,v2,v3) if b2>0 : flag2=1 else : flag2=0 b3=sign(pt,v3,v1) if b3>0 : flag3=1 else : flag3=0 return((flag1==flag2)and(flag2==flag3)) n=int(input()) for _ in range(n): query=list(map(int,input().split())) triangle=query[0 : 6] hikoboshi=query[6 : 8] orihime=query[8 : 10] check1=check(triangle,hikoboshi) check2=check(triangle,orihime) if check1==check2 : print("NG") else : print("OK") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var query : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; triangle := query.subrange(0+1, 6) ; var hikoboshi : OclAny := query.subrange(6+1, 8) ; var orihime : OclAny := query.subrange(8+1, 10) ; var check1 : OclAny := check(triangle, hikoboshi) ; var check2 : OclAny := check(triangle, orihime) ; if check1 = check2 then ( execute ("NG")->display() ) else ( execute ("OK")->display() )); operation sign(p1 : OclAny, p2 : OclAny, p3 : OclAny) : OclAny pre: true post: true activity: return (p1->first() - p3->first()) * (p2[1+1] - p3[1+1]) - (p2->first() - p3->first()) * (p1[1+1] - p3[1+1]); operation check(triangle : OclAny, pt : OclAny) : OclAny pre: true post: true activity: var v1 : Sequence := Sequence{triangle->first()}->union(Sequence{ triangle[1+1] }) ; var v2 : Sequence := Sequence{triangle[2+1]}->union(Sequence{ triangle[3+1] }) ; var v3 : Sequence := Sequence{triangle[4+1]}->union(Sequence{ triangle[5+1] }) ; var b1 : OclAny := sign(pt, v1, v2) ; if b1 > 0 then ( var flag1 : int := 1 ) else ( flag1 := 0 ) ; var b2 : OclAny := sign(pt, v2, v3) ; if b2 > 0 then ( var flag2 : int := 1 ) else ( flag2 := 0 ) ; var b3 : OclAny := sign(pt, v3, v1) ; if b3 > 0 then ( var flag3 : int := 1 ) else ( flag3 := 0 ) ; return ((flag1 = flag2) & (flag2 = flag3)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bitonicGenerator(arr,n): evenArr=[] oddArr=[] for i in range(n): if((i % 2)==0): evenArr.append(arr[i]) else : oddArr.append(arr[i]) evenArr=sorted(evenArr) oddArr=sorted(oddArr) oddArr=oddArr[: :-1] i=0 for j in range(len(evenArr)): arr[i]=evenArr[j] i+=1 for j in range(len(oddArr)): arr[i]=oddArr[j] i+=1 arr=[1,5,8,9,6,7,3,4,2,0] n=len(arr) bitonicGenerator(arr,n) for i in arr : print(i,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{5}->union(Sequence{8}->union(Sequence{9}->union(Sequence{6}->union(Sequence{7}->union(Sequence{3}->union(Sequence{4}->union(Sequence{2}->union(Sequence{ 0 }))))))))) ; n := (arr)->size() ; bitonicGenerator(arr, n) ; for i : arr do ( execute (i)->display()); operation bitonicGenerator(arr : OclAny, n : OclAny) pre: true post: true activity: var evenArr : Sequence := Sequence{} ; var oddArr : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if ((i mod 2) = 0) then ( execute ((arr[i+1]) : evenArr) ) else ( execute ((arr[i+1]) : oddArr) )) ; evenArr := evenArr->sort() ; oddArr := oddArr->sort() ; oddArr := oddArr(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var i : int := 0 ; for j : Integer.subrange(0, (evenArr)->size()-1) do ( arr[i+1] := evenArr[j+1] ; i := i + 1) ; for j : Integer.subrange(0, (oddArr)->size()-1) do ( arr[i+1] := oddArr[j+1] ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairs(arr,n): count=0 right=0 left=0 visited=[False for i in range(n)] while(rightunion(Sequence{4}->union(Sequence{2}->union(Sequence{4}->union(Sequence{3}->union(Sequence{ 2 }))))) ; n := (arr)->size() ; execute (countPairs(arr, n))->display() ) else skip; operation countPairs(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var right : int := 0 ; var left : int := 0 ; var visited : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (false)) ; while ((right->compareTo(n)) < 0) do ( while ((right->compareTo(n)) < 0 & visited[arr[right+1]+1] = false) do ( count := count + (right - left) ; visited[arr[right+1]+1] := true ; right := right + 1) ; while ((left->compareTo(right)) < 0 & (right /= n & visited[arr[right+1]+1] = true)) do ( visited[arr[left+1]+1] := false ; left := left + 1)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def isSubtree(self,s,t): s_res=self.preorder(s,True) t_res=self.preorder(t,True) return t_res in s_res def preorder(self,root,isLeft): if root is None : if isLeft : return "lnull" else : return "rnull" return "#"+str(root.val)+" "+self.preorder(root.left,True)+" "+self.preorder(root.right,False) ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation isSubtree(s : OclAny,t : OclAny) : OclAny pre: true post: true activity: var s_res : OclAny := self.preorder(s, true) ; var t_res : OclAny := self.preorder(t, true) ; return (s_res)->includes(t_res); operation preorder(root : OclAny,isLeft : OclAny) : OclAny pre: true post: true activity: if root <>= null then ( if isLeft then ( return "lnull" ) else ( return "rnull" ) ) else skip ; return "#" + ("" + ((root.val))) + " " + self.preorder(root.left, true) + " " + self.preorder(root.right, false); } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil n,m=map(int,input().split()) x=list(map(int,input().split())) for i in range(n): x[i]=ceil(x[i]/m) max=x[0] c=1 for i in range(n): if(x[i]>=max): max=x[i] c=i+1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( x[i+1] := ceil(x[i+1] / m)) ; var max : OclAny := x->first() ; var c : int := 1 ; for i : Integer.subrange(0, n-1) do ( if ((x[i+1]->compareTo(max)) >= 0) then ( max := x[i+1] ; c := i + 1 ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- M=1001 ; MOD=998244353 ; dp=[[-1]*M]*M def solve(idx,diff,N,M,K): if(idx>N): if(diff==K): return 1 return 0 if(dp[idx][diff]!=-1): return dp[idx]; ans=solve(idx+1,diff,N,M,K); ans+=(M-1)*solve(idx+1,diff+1,N,M,K); dp[idx][diff]=ans % MOD ; return dp[idx][diff] if __name__=="__main__" : N=3 M=3 K=0 print(M*solve(2,0,N,M,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var M : int := 1001; ; var MOD : int := 998244353; ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ MatrixLib.elementwiseMult(Sequence{ -1 }, M) }, M) ; skip ; if __name__ = "__main__" then ( N := 3 ; M := 3 ; K := 0 ; execute (M * solve(2, 0, N, M, K))->display() ) else skip; operation solve(idx : OclAny, diff : OclAny, N : OclAny, M : OclAny, K : OclAny) : OclAny pre: true post: true activity: if ((idx->compareTo(N)) > 0) then ( if (diff = K) then ( return 1 ) else skip ; return 0 ) else skip ; if (dp[idx+1][diff+1] /= -1) then ( return dp[idx+1]; ) else skip ; var ans : OclAny := solve(idx + 1, diff, N, M, K); ; ans := ans + (M - 1) * solve(idx + 1, diff + 1, N, M, K); ; dp[idx+1][diff+1] := ans mod MOD; ; return dp[idx+1][diff+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib,math def compute(): NUM_SPHERES=21 sphereradii=[(i+30)*1000 for i in range(NUM_SPHERES)] minlength=[[None]*(2**NUM_SPHERES)for _ in range(NUM_SPHERES)] def find_minimum_length(currentsphereindex,setofspheres): if setofspheres &(1<display() ) else skip; operation compute() : OclAny pre: true post: true activity: var NUM_SPHERES : int := 21 ; var sphereradii : Sequence := Integer.subrange(0, NUM_SPHERES-1)->select(i | true)->collect(i | ((i + 30) * 1000)) ; var minlength : Sequence := Integer.subrange(0, NUM_SPHERES-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ null }, ((2)->pow(NUM_SPHERES))))) ; skip ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name find_minimum_length)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name NUM_SPHERES)))))))) ))) - (expr (atom (number (integer 1)))))))))) )))) + (expr (atom (name sphereradii)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name NUM_SPHERES)))))))) )))))))))->min() ; return ("" + ((("" + (((ans)->round())))->toInteger()))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): t=list(map(int,input().split())) t.sort() a,b=t[0]**2+t[1]**2,t[2]**2 if a==b : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var t : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; t := t->sort() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{(t->first())->pow(2) + (t[1+1])->pow(2),(t[2+1])->pow(2)} ; if a = b then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in[0]*int(input()): a,b,c=sorted(map(int,input().split())) print(['NO','YES'][a*a+b*b==c*c]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; execute (Sequence{'NO'}->union(Sequence{ 'YES' })->select(a * a + b * b = c * c))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys array=[] for i in sys.stdin : array.append(i) N=int(array[0]) for k in range(1,N+1): x=array[k].split() a,b,c=int(x[0]),int(x[1]),int(x[2]) if a**2+b**2==c**2 or b**2+c**2==a**2 or c**2+a**2==b**2 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var array : Sequence := Sequence{} ; for i : OclFile["System.in"] do ( execute ((i) : array)) ; var N : int := ("" + ((array->first())))->toInteger() ; for k : Integer.subrange(1, N + 1-1) do ( var x : OclAny := array[k+1].split() ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{("" + ((x->first())))->toInteger(),("" + ((x[1+1])))->toInteger(),("" + ((x[2+1])))->toInteger()} ; if (a)->pow(2) + (b)->pow(2) = (c)->pow(2) or (b)->pow(2) + (c)->pow(2) = (a)->pow(2) or (c)->pow(2) + (a)->pow(2) = (b)->pow(2) then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countIntegralSolutions(n): result=0 for i in range(n+1): for j in range(n+1): for k in range(n+1): if i+j+k==n : result+=1 return result n=3 print(countIntegralSolutions(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3 ; execute (countIntegralSolutions(n))->display(); operation countIntegralSolutions(n : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( for j : Integer.subrange(0, n + 1-1) do ( for k : Integer.subrange(0, n + 1-1) do ( if i + j + k = n then ( result := result + 1 ) else skip))) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() i=0 while int(x)>i : a,b,c=input().split() a=int(a) b=int(b) c=int(c) if a*a==b*b+c*c or b*b==c*c+a*a or c*c==b*b+a*a : print("YES") else : print("NO") i=i+1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := (OclFile["System.in"]).readLine() ; var i : int := 0 ; while (("" + ((x)))->toInteger()->compareTo(i)) > 0 do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := input().split() ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; var c : int := ("" + ((c)))->toInteger() ; if a * a = b * b + c * c or b * b = c * c + a * a or c * c = b * b + a * a then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input() for e in sys.stdin : a,b,c=sorted(map(int,e.split())) print(['NO','YES'][a*a+b*b==c*c]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; input() ; for e : OclFile["System.in"] do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (e.split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; execute (Sequence{'NO'}->union(Sequence{ 'YES' })->select(a * a + b * b = c * c))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getTotalXorOfSubarrayXors(arr,N): res=0 for i in range(0,N): freq=(i+1)*(N-i) if(freq % 2==1): res=res ^ arr[i] return res arr=[3,5,2,4,6] N=len(arr) print(getTotalXorOfSubarrayXors(arr,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{3}->union(Sequence{5}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 6 })))) ; N := (arr)->size() ; execute (getTotalXorOfSubarrayXors(arr, N))->display(); operation getTotalXorOfSubarrayXors(arr : OclAny, N : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; for i : Integer.subrange(0, N-1) do ( var freq : double := (i + 1) * (N - i) ; if (freq mod 2 = 1) then ( res := MathLib.bitwiseXor(res, arr[i+1]) ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getTotalXorOfSubarrayXors(arr,N): if(N % 2==0): return 0 res=0 for i in range(0,N,2): res ^=arr[i] return res if __name__=="__main__" : arr=[3,5,2,4,6] N=len(arr) print(getTotalXorOfSubarrayXors(arr,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{3}->union(Sequence{5}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 6 })))) ; N := (arr)->size() ; execute (getTotalXorOfSubarrayXors(arr, N))->display() ) else skip; operation getTotalXorOfSubarrayXors(arr : OclAny, N : OclAny) : OclAny pre: true post: true activity: if (N mod 2 = 0) then ( return 0 ) else skip ; var res : int := 0 ; for i : Integer.subrange(0, N-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( res := res xor arr[i+1]) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def I(): return(int(sys.stdin.readline())) def LI(): return([int(x)for x in sys.stdin.readline().split()]) def main(): N=I() S=sorted(LI(),reverse=True) flag=[True]*len(S) cur=[] cur.append(S[0]) flag[0]=False for i in range(N): j=0 jM=len(cur) for k in range(len(S)): if flag[k]and S[k]display() ) else skip; operation I() : OclAny pre: true post: true activity: return (("" + (((OclFile["System.in"]).readLine())))->toInteger()); operation LI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))); operation main() : OclAny pre: true post: true activity: var N : OclAny := I() ; var S : Sequence := LI()->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var flag : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (S)->size()) ; var cur : Sequence := Sequence{} ; execute ((S->first()) : cur) ; flag->first() := false ; for i : Integer.subrange(0, N-1) do ( var j : int := 0 ; var jM : int := (cur)->size() ; (compound_stmt for (exprlist (expr (atom (name k)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name S)))))))) ))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (expr (atom (name flag)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ]))))) and (logical_test (comparison (comparison (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])))) < (comparison (expr (atom (name cur)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cur)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name j)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name flag)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name False)))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name j)))) == (comparison (expr (atom (name jM))))))) : (suite (stmt (simple_stmt (small_stmt break)))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom "No")))))) ))))))))))))) ; cur := cur->sort()) ; return ("Yes"); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : l=int(input()) p=int(input()) q=int(input()) s=l/(p+q) x=p*s print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : double := l / (p + q) ; var x : double := p * s ; execute (x)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l,p,q=[int(input())for _ in[1,2,3]] print(l*p/(p+q)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := null; var p : OclAny := null; var q : OclAny := null; Sequence{l,p,q} := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; execute (l * p / (p + q))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) c=int(input()) cd=round(a*b/(b+c),7) c=a*b//(b+c) if c==cd : print(c) else : print(cd) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cd : double := MathLib.roundN(a * b / (b + c), 7) ; c := a * b div (b + c) ; if c = cd then ( execute (c)->display() ) else ( execute (cd)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A=int(input()) B=int(input()) C=int(input()) spd=0 ans=0 spd=A/(B+C); ans=spd*B ; print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var C : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var spd : int := 0 ; var ans : int := 0 ; spd := A / (B + C); ; ans := spd * B; ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import os import random import re import sys from math import gcd from math import sqrt l=int(input()) p=int(input()) q=int(input()) x=p*l/(p+q) print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : double := p * l / (p + q) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) l=sorted(map(int,input().split())) print(l[n]-l[n-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; execute (l[n+1] - l[n - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printCombination(n): for i in range(1,n): if(i % 3!=0): for j in range(1,n): if(j % 3!=0): for k in range(1,n): if(k % 3!=0 and(i+j+k)==n): print(i,j,k); return ; n=233 ; printCombination(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 233; ; printCombination(n);; operation printCombination(n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(1, n-1) do ( if (i mod 3 /= 0) then ( for j : Integer.subrange(1, n-1) do ( if (j mod 3 /= 0) then ( for k : Integer.subrange(1, n-1) do ( if (k mod 3 /= 0 & (i + j + k) = n) then ( execute (i)->display(); ; return; ) else skip) ) else skip) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for _ in range(n): i=int(input()) arr=list(map(int,input().split())) arr.sort() i=len(arr)-1 print(arr[i//2+1]-arr[i//2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var i : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := arr->sort() ; i := (arr)->size() - 1 ; execute (arr[i div 2 + 1+1] - arr[i div 2+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(lst,n): lst.sort() ans=lst[n]-lst[n-1] return ans t=int(input()) for i in range(t): n=int(input()) lst=[int(x)for x in input().split()] print(solve(lst,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; lst := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (solve(lst, n))->display()); operation solve(lst : OclAny, n : OclAny) : OclAny pre: true post: true activity: lst := lst->sort() ; var ans : double := lst[n+1] - lst[n - 1+1] ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(0,int(input())): n=int(input()) v=sorted(map(int,input().split())) print(v[n]-v[n-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var v : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; execute (v[n+1] - v[n - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq N=int(input()) S=list(map(int,input().split())) S=[-S[i]for i in range(len(S))] heapq.heapify(S) que=[] next=[] rest=[] x=heapq.heappop(S) heapq.heappush(que,x) while S : while que : x=heapq.heappop(que) while S : y=heapq.heappop(S) if y>x : heapq.heappush(next,x) heapq.heappush(next,y) break else : heapq.heappush(rest,y) else : print("No") exit() que=next next=[] while rest : x=heapq.heappop(rest) heapq.heappush(S,x) print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; S := Integer.subrange(0, (S)->size()-1)->select(i | true)->collect(i | (-S[i+1])) ; heapq.heapify(S) ; var que : Sequence := Sequence{} ; var next : Sequence := Sequence{} ; var rest : Sequence := Sequence{} ; var x : OclAny := heapq.heappop(S) ; heapq.heappush(que, x) ; while S do ( while que do ( x := heapq.heappop(que) ; (compound_stmt while (test (logical_test (comparison (expr (atom (name S)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name y)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name heapq)) (trailer . (name heappop) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name S)))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name y)))) > (comparison (expr (atom (name x))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name heapq)) (trailer . (name heappush) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name next))))))) , (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name heapq)) (trailer . (name heappush) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name next))))))) , (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name heapq)) (trailer . (name heappush) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name rest))))))) , (argument (test (logical_test (comparison (expr (atom (name y)))))))) ))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "No"))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name exit)) (trailer (arguments ( )))))))))))))))) ; que := next ; next := Sequence{} ; while rest do ( x := heapq.heappop(rest) ; heapq.heappush(S, x))) ; execute ("Yes")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) l1=list(map(int,input().split())) l1.sort() print(l1[(n)]-l1[(n)-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l1 := l1->sort() ; execute (l1[(n)+1] - l1[(n) - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) t=[int(x)for x in input().split()] ans=0 freq={} for i in range(n): if-t[i]in freq : ans+=freq[-t[i]] if t[i]in freq : freq[t[i]]+=1 else : freq[t[i]]=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : int := 0 ; var freq : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( if (freq)->includes(-t[i+1]) then ( ans := ans + freq->reverse()->at(-(-t[i+1])) ) else skip ; if (freq)->includes(t[i+1]) then ( freq[t[i+1]+1] := freq[t[i+1]+1] + 1 ) else ( freq[t[i+1]+1] := 1 )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() pari={} paruDZ=0 saraksts=list(map(int,input().split())) for i in saraksts : if i in pari : pari[i]+=1 else : pari[i]=1 for k in pari : if k==0 : paruDZ+=pari[k]*(pari[k]-1) elif k*-1 in pari : paruDZ+=pari[k]*pari[k*-1] print(paruDZ//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var pari : OclAny := Set{} ; var paruDZ : int := 0 ; var saraksts : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : saraksts do ( if (pari)->includes(i) then ( pari[i+1] := pari[i+1] + 1 ) else ( pari[i+1] := 1 )) ; for k : pari do ( if k = 0 then ( paruDZ := paruDZ + pari[k+1] * (pari[k+1] - 1) ) else (if (pari)->includes(k * -1) then ( paruDZ := paruDZ + pari[k+1] * pari[k * -1+1] ) else skip)) ; execute (paruDZ div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) t=list(map(int,input().split())) cnt=defaultdict(lambda : 0) for i in t : cnt[i]+=1 ans=0 for i in range(-10,0): ans+=cnt[i]*cnt[-i] ans+=cnt[0]*(cnt[0]-1)//2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; for i : t do ( cnt[i+1] := cnt[i+1] + 1) ; var ans : int := 0 ; for i : Integer.subrange(-10, 0-1) do ( ans := ans + cnt[i+1] * cnt->reverse()->at(-(-i))) ; ans := ans + cnt->first() * (cnt->first() - 1) div 2 ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from collections import Counter n=int(input()) w=Counter(map(int,input().split())) c=0 for i in w : if i==0 : c+=w[i]*(w[i]-1) else : if-i in w : c+=w[i]*w[-i] print(c//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : OclAny := Counter((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; for i : w do ( if i = 0 then ( c := c + w[i+1] * (w[i+1] - 1) ) else ( if (w)->includes(-i) then ( c := c + w[i+1] * w->reverse()->at(-(-i)) ) else skip )) ; execute (c div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) skaitli=list(map(int,input().split())) dic={} rez=0 for sk in skaitli : if sk in dic : dic[sk]+=1 else : dic[sk]=1 for key in dic : if key==0 : rez+=dic[key]*(dic[key]-1)/2 elif key<0 and key*-1 in dic : rez+=dic[key]*dic[key*-1] print(int(rez)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var skaitli : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dic : OclAny := Set{} ; var rez : int := 0 ; for sk : skaitli do ( if (dic)->includes(sk) then ( dic[sk+1] := dic[sk+1] + 1 ) else ( dic[sk+1] := 1 )) ; for key : dic do ( if key = 0 then ( rez := rez + dic[key+1] * (dic[key+1] - 1) / 2 ) else (if key < 0 & (dic)->includes(key * -1) then ( rez := rez + dic[key+1] * dic[key * -1+1] ) else skip)) ; execute (("" + ((rez)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- pya=int(input()) arre=[] while pya : pya-=1 arre.append(input().lower()) oString=input() lowString=oString.lower() letter1=input()[0].lower() letter2='a' if letter1.lower()!='a' else 'b' valid=[0 for i in range(len(oString))] setcito=set() for x in arre : if lowString.find(x)>=0 : wat=0 while True : index=lowString.find(x,wat) if index<0 : break for i in range(index,index+len(x)): setcito.add(i) wat=index+1 oString=list(oString) for i in setcito : letter=letter1 if lowString[i]!=letter1 else letter2 oString[i]=letter if oString[i].islower()else letter.upper() for x in oString : print(x,end="") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var pya : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arre : Sequence := Sequence{} ; while pya do ( pya := pya - 1 ; execute ((input()->toLowerCase()) : arre)) ; var oString : String := (OclFile["System.in"]).readLine() ; var lowString : String := oString->toLowerCase() ; var letter1 : OclAny := input()->first()->toLowerCase() ; var letter2 : String := if letter1->toLowerCase() /= 'a' then 'a' else 'b' endif ; var valid : Sequence := Integer.subrange(0, (oString)->size()-1)->select(i | true)->collect(i | (0)) ; var setcito : Set := Set{}->union(()) ; for x : arre do ( if lowString->indexOf(x) - 1 >= 0 then ( var wat : int := 0 ; while true do ( var index : int := lowString->indexOf(x, wat) - 1 ; if index < 0 then ( break ) else skip ; for i : Integer.subrange(index, index + (x)->size()-1) do ( execute ((i) : setcito)) ; wat := index + 1) ) else skip) ; oString := (oString)->characters() ; for i : setcito do ( var letter : OclAny := if lowString[i+1] /= letter1 then letter1 else letter2 endif ; oString[i+1] := if oString[i+1]->matches("[a-z ]*") then letter else letter->toUpperCase() endif) ; for x : oString->characters() do ( execute (x)->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- TEN=10 def digitSum(n): sum=0 while(n>0): sum+=n % TEN n//=TEN return sum def getNthTerm(n): sum=digitSum(n) if(sum % TEN==0): return(n*TEN) extra=TEN-(sum % TEN) return((n*TEN)+extra) def firstNTerms(n): for i in range(1,n+1): print(getNthTerm(i),end=" ") n=10 firstNTerms(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var TEN : int := 10 ; skip ; skip ; skip ; n := 10 ; firstNTerms(n); operation digitSum(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; while (n > 0) do ( sum := sum + n mod TEN ; n := n div TEN) ; return sum; operation getNthTerm(n : OclAny) : OclAny pre: true post: true activity: sum := digitSum(n) ; if (sum mod TEN = 0) then ( return (n * TEN) ) else skip ; var extra : double := TEN - (sum mod TEN) ; return ((n * TEN) + extra); operation firstNTerms(n : OclAny) pre: true post: true activity: for i : Integer.subrange(1, n + 1-1) do ( execute (getNthTerm(i))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[input().lower()for i in range(n)] b=input() c=input() b1=b.lower() d=[0]*len(b) e='' b2=len(b) for i in range(n): for j in range(b2-len(a[i])+1): for k in range(len(a[i])): if a[i][k]!=b1[j+k]: break else : for k in range(len(a[i])): d[j+k]=1 for i in range(len(b)): if d[i]: if b[i].lower()==c : if b[i]==b[i].lower(): if b[i]=='a' : e+='b' else : e+='a' else : if b[i]=='A' : e+='B' else : e+='A' else : if b[i]==b[i].lower(): e+=c else : e+=c.upper() else : e+=b[i] print(e) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (input()->toLowerCase())) ; var b : String := (OclFile["System.in"]).readLine() ; var c : String := (OclFile["System.in"]).readLine() ; var b1 : String := b->toLowerCase() ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (b)->size()) ; var e : String := '' ; var b2 : int := (b)->size() ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, b2 - (a[i+1])->size() + 1-1) do ((compound_stmt for (exprlist (expr (atom (name k)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])))) != (comparison (expr (atom (name b1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (name k))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt for (exprlist (expr (atom (name k)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (name k))))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))))))))) ; for i : Integer.subrange(0, (b)->size()-1) do ( if d[i+1] then ( if b[i+1]->toLowerCase() = c then ( if b[i+1] = b[i+1]->toLowerCase() then ( if b[i+1] = 'a' then ( e := e + 'b' ) else ( e := e + 'a' ) ) else ( if b[i+1] = 'A' then ( e := e + 'B' ) else ( e := e + 'A' ) ) ) else ( if b[i+1] = b[i+1]->toLowerCase() then ( e := e + c ) else ( e := e + c->toUpperCase() ) ) ) else ( e := e + b[i+1] )) ; execute (e)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys iFile=open(sys.argv[1],"r") size=int(iFile.readline().strip()) for i in range(size): line=iFile.readline().strip().split() N=int(line[0]) M=int(line[1]) K=int(line[2]) stones=0 if K<=4 : stones=K elif min(N,M)<=2 : stones=K elif min(N,M)==3 : enclosed=int((K-2)/3) enclosed=min(enclosed,max(N,M)-2) stones=K-enclosed else : if K<8 : enclosed=1 elif K<10 : enclosed=2 elif K<12 : enclosed=3 elif K<14 or max(N,M)==4 : enclosed=4 elif K<16 : enclosed=5 else : enclosed=6 stones=K-enclosed output=str(stones) print("Case #"+str(i+1)+": "+output) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var iFile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) ; var size : int := ("" + ((iFile.readLine()->trim())))->toInteger() ; for i : Integer.subrange(0, size-1) do ( var line : OclAny := iFile.readLine()->trim().split() ; var N : int := ("" + ((line->first())))->toInteger() ; var M : int := ("" + ((line[1+1])))->toInteger() ; var K : int := ("" + ((line[2+1])))->toInteger() ; var stones : int := 0 ; if K <= 4 then ( stones := K ) else (if Set{N, M}->min() <= 2 then ( stones := K ) else (if Set{N, M}->min() = 3 then ( var enclosed : int := ("" + (((K - 2) / 3)))->toInteger() ; enclosed := Set{enclosed, Set{N, M}->max() - 2}->min() ; stones := K - enclosed ) else ( if K < 8 then ( enclosed := 1 ) else (if K < 10 then ( enclosed := 2 ) else (if K < 12 then ( enclosed := 3 ) else (if K < 14 or Set{N, M}->max() = 4 then ( enclosed := 4 ) else (if K < 16 then ( enclosed := 5 ) else ( enclosed := 6 ) ) ) ) ) ; stones := K - enclosed ) ) ) ; var output : String := ("" + ((stones))) ; execute ("Case #" + ("" + ((i + 1))) + ": " + output)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin ni=lambda : int(ns()) na=lambda : list(map(int,stdin.readline().split())) ns=lambda : stdin.readline().rstrip() n=ni() a=na() a.sort(reverse=True) done=[False]*(1<toInteger()) ; var na : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ns : Function := lambda $$ : OclAny in (stdin.readLine().rstrip()) ; var n : OclAny := ni->apply() ; var a : OclAny := na->apply() ; a := a->sort() ; var done : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (1 * (2->pow(n)))) ; var b : Sequence := Sequence{ a->first() } ; done->first() := true ; for d : Integer.subrange(0, n-1) do ( var j : int := 0 ; for i : Integer.subrange(0, 1 * (2->pow(d))-1) do ( while (j->compareTo(1 * (2->pow(n)))) < 0 & (done[j+1] or (b[i+1]->compareTo(a[j+1])) <= 0) do ( j := j + 1) ; if j = 1 * (2->pow(n)) then ( execute ("No")->display() ; sys.exit(0) ) else skip ; execute ((a[j+1]) : b) ; done[j+1] := true) ; b := b->sort()) ; execute ("Yes")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- nR=int(input()) for run in range(nR): data=input().split() N=int(data[0]) M=int(data[1]) K=int(data[2]) mini=K for i in range(2,N+1): for j in range(2,M+1): loss=0 rm=0 for k in range(min(i,j)//2): for m in range(5): if 2*k==min(i,j)and m>2 : break if i*j-losstoInteger() ; for run : Integer.subrange(0, nR-1) do ( var data : OclAny := input().split() ; var N : int := ("" + ((data->first())))->toInteger() ; var M : int := ("" + ((data[1+1])))->toInteger() ; var K : int := ("" + ((data[2+1])))->toInteger() ; var mini : int := K ; for i : Integer.subrange(2, N + 1-1) do ( for j : Integer.subrange(2, M + 1-1) do ( var loss : int := 0 ; var rm : int := 0 ; for k : Integer.subrange(0, Set{i, j}->min() div 2-1) do ( for m : Integer.subrange(0, 5-1) do ( if 2 * k = Set{i, j}->min() & m > 2 then ( break ) else skip ; if (i * j - loss->compareTo(K)) < 0 then ( break ) else skip ; if (2 * (i + j) - 4 - rm->compareTo(mini)) < 0 then ( mini := 2 * (i + j) - 4 - rm ) else skip ; loss := loss + (k + 1) ; rm := rm + 1) ; if (i * j - loss->compareTo(K)) < 0 then ( break ) else skip))) ; execute ("Case #" + ("" + ((run + 1))) + ": " + ("" + ((mini))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import sqrt import math T=int(input()) test=1 while test<=T : print("Case #"+str(test)+": ",end="") test+=1 mnk=input().split() m=int(mnk[0]) n=int(mnk[1]) k=int(mnk[2]) if m>n : tmp=n n=m m=tmp if m<=2 : print(k) continue if m*n-k<=4 : print((m+n-4)*2-m*n+k+4) continue size=math.ceil(sqrt(k+4).real) w=0 if size>m : w=m else : w=size h=size-1 while w*h-4w : tmp=h h=w w=tmp if(w*h-4)-k>=2 and m>3 : ans-=1 if(w-1)*h-3>=k : ans=min((w+h-5)*2+1,ans) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var test : int := 1 ; while (test->compareTo(T)) <= 0 do ( execute ("Case #" + ("" + ((test))) + ": ")->display() ; test := test + 1 ; var mnk : OclAny := input().split() ; var m : int := ("" + ((mnk->first())))->toInteger() ; var n : int := ("" + ((mnk[1+1])))->toInteger() ; var k : int := ("" + ((mnk[2+1])))->toInteger() ; if (m->compareTo(n)) > 0 then ( var tmp : int := n ; n := m ; m := tmp ) else skip ; if m <= 2 then ( execute (k)->display() ; continue ) else skip ; if m * n - k <= 4 then ( execute ((m + n - 4) * 2 - m * n + k + 4)->display() ; continue ) else skip ; var size : double := (sqrt(k + 4).real)->ceil() ; var w : int := 0 ; if (size->compareTo(m)) > 0 then ( w := m ) else ( w := size ) ; var h : double := size - 1 ; while (w * h - 4->compareTo(k)) < 0 do ( h := h + 1) ; var ans : double := (w + h - 4) * 2 ; if (h->compareTo(w)) > 0 then ( tmp := h ; h := w ; w := tmp ) else skip ; if (w * h - 4) - k >= 2 & m > 3 then ( ans := ans - 1 ) else skip ; if ((w - 1) * h - 3->compareTo(k)) >= 0 then ( ans := Set{(w + h - 5) * 2 + 1, ans}->min() ) else skip ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools def valid(seq): for i in xrange(len(seq)-1): if abs(seq[i]-seq[i+1])>2 : return False return True def solve(case): n,m,k=case if min(n,m)<=2 : return k if k<=4 : return k count=k for i in xrange(1,n+1): for seq in itertools.product(range(1,m+1),repeat=i): if sum(seq)==k and valid(seq): count=min(count,seq[0]+seq[-1]+2*len(seq)-4) return count f=file('c.in','r') lines=f.readlines() t=int(lines[0]) f.close() g=file('c.out','w') for i in xrange(1,t+1): s=solve(map(int,lines[i].strip().split())) g.write("Case #{}:{}\n".format(i,s)) g.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var f : OclAny := file('c.in', 'r') ; var lines : String := f.readlines() ; var t : int := ("" + ((lines->first())))->toInteger() ; f.closeFile() ; var g : OclAny := file('c.out', 'w') ; for i : xrange(1, t + 1) do ( var s : OclAny := solve((lines[i+1]->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; g.write(StringLib.interpolateStrings("Case #{}:{}\n", Sequence{i, s}))) ; g.closeFile(); operation valid(seq : OclAny) : OclAny pre: true post: true activity: for i : xrange((seq)->size() - 1) do ( if (seq[i+1] - seq[i + 1+1])->abs() > 2 then ( return false ) else skip) ; return true; operation solve(case : OclAny) : OclAny pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := case ; if Set{n, m}->min() <= 2 then ( return k ) else skip ; if k <= 4 then ( return k ) else skip ; var count : OclAny := k ; for i : xrange(1, n + 1) do ( for seq : itertools.product(Integer.subrange(1, m + 1-1), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (name i)))))))) do ( if (seq)->sum() = k & valid(seq) then ( count := Set{count, seq->first() + seq->last() + 2 * (seq)->size() - 4}->min() ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import heapq def test(N,M,K,t,b,limit): stone=t+b cover=t+b layer=2 while layer<=M : if cover>=K and t-b<=2 : return stone else : stone+=2 b=min(N,b+2) cover+=b if b>t : t,b=b,t layer+=1 if stone>limit : break return-1 def main(): ifile=open('c.in','r') ofile=open('c.out','w') T=int(ifile.readline().strip()) for case in range(1,T+1): N,M,K=[int(x)for x in ifile.readline().split()] m=K for i in range(1,N+1): for j in range(1,i+1): t=test(N,M,K,i,j,m) if t>0 and t0 and tcompareTo(M)) <= 0 do ( if (cover->compareTo(K)) >= 0 & t - b <= 2 then ( return stone ) else ( stone := stone + 2 ; b := Set{N, b + 2}->min() ; cover := cover + b ; if (b->compareTo(t)) > 0 then ( Sequence{t,b} := Sequence{b,t} ) else skip ; layer := layer + 1 ) ; if (stone->compareTo(limit)) > 0 then ( break ) else skip) ; return -1; operation main() pre: true post: true activity: var ifile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('c.in')) ; var ofile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('c.out')) ; var T : int := ("" + ((ifile.readLine()->trim())))->toInteger() ; for case : Integer.subrange(1, T + 1-1) do ( Sequence{N,M,K} := ifile.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var m : OclAny := K ; for i : Integer.subrange(1, N + 1-1) do ( for j : Integer.subrange(1, i + 1-1) do ( t := test(N, M, K, i, j, m) ; if t > 0 & (t->compareTo(m)) < 0 then ( m := t ) else skip)) ; Sequence{N,M} := Sequence{M,N} ; for i : Integer.subrange(1, N + 1-1) do ( for j : Integer.subrange(1, i + 1-1) do ( t := test(N, M, K, i, j, m) ; if t > 0 & (t->compareTo(m)) < 0 then ( m := t ) else skip)) ; ofile.write(StringLib.format('Case #%d: %d ',Sequence{case, m}))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from fractions import gcd from itertools import accumulate def lcm(a,b): return a*b//gcd(a,b) def combination_count(n,r): return math.factorial(n)//(math.factorial(n-r)*math.factorial(r)) def permutations_count(n,r): return math.factorial(n)//math.factorial(n-r) big_prime=1000000007 N=int(sys.stdin.readline()) S=list(sys.stdin.readline().rstrip()) Wn=[0]*N En=[0]*N Wc=0 Ec=0 for i,s in enumerate(S): if s=="W" : Wc+=1 else : Ec+=1 Wn[i]=Wc En[i]=Ec ans=10**10 Wn=[0]+Wn En=[0]+En for i,(w,e)in enumerate(zip(Wn[1 : :],En[1 : :])): ans=min(Wn[i]+En[N]-En[i+1],ans) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var big_prime : int := 1000000007 ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : Sequence := (sys.stdin.readLine().rstrip()) ; var Wn : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var En : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var Wc : int := 0 ; var Ec : int := 0 ; for _tuple : Integer.subrange(1, (S)->size())->collect( _indx | Sequence{_indx-1, (S)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); if s = "W" then ( Wc := Wc + 1 ) else ( Ec := Ec + 1 ) ; Wn[i+1] := Wc ; En[i+1] := Ec) ; var ans : double := (10)->pow(10) ; Wn := Sequence{ 0 }->union(Wn) ; En := Sequence{ 0 }->union(En) ; for _tuple : Integer.subrange(1, (Integer.subrange(1, Wn(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop :))->size())->collect( _indx | Sequence{Wn(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop :))->at(_indx), En(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop :))->at(_indx)} ))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(1, Wn(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop :))->size())->collect( _indx | Sequence{Wn(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop :))->at(_indx), En(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop :))->at(_indx)} ))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{w, e} : OclAny := _tuple->at(_indx); ans := Set{Wn[i+1] + En[N+1] - En[i + 1+1], ans}->min()) ; execute (ans)->display(); operation lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a * b div gcd(a, b); operation combination_count(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: return MathLib.factorial(n) div (MathLib.factorial(n - r) * MathLib.factorial(r)); operation permutations_count(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: return MathLib.factorial(n) div MathLib.factorial(n - r); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def we(): input() s=input() cnt=s.count('E') ans=s.count('E') for i in s : if i=='W' : cnt+=1 else : cnt-=1 ans=min(ans,cnt) return(min(cnt,ans)) print(we()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (we())->display(); operation we() : OclAny pre: true post: true activity: input() ; var s : String := (OclFile["System.in"]).readLine() ; var cnt : int := s->count('E') ; var ans : int := s->count('E') ; for i : s->characters() do ( if i = 'W' then ( cnt := cnt + 1 ) else ( cnt := cnt - 1 ; ans := Set{ans, cnt}->min() )) ; return (Set{cnt, ans}->min()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) S=list(input()) reS=S[: :-1] wSum=[0 for i in range(N)] eSum=[0 for i in range(N)] for i in range(N): if i==0 : if S[i]=='W' : wSum[i]=1 if reS[i]=='E' : eSum[i]=1 else : if S[i]=='W' : wSum[i]=wSum[i-1]+1 else : wSum[i]=wSum[i-1] if reS[i]=='E' : eSum[i]=eSum[i-1]+1 else : eSum[i]=eSum[i-1] eSum=eSum[: :-1] cost=eSum[1] for i in range(1,N): if i==N-1 : if cost>wSum[N-2]: cost=wSum[N-2] else : if cost>wSum[i-1]+eSum[i+1]: cost=wSum[i-1]+eSum[i+1] print(cost) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var reS : OclAny := S(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var wSum : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; var eSum : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, N-1) do ( if i = 0 then ( if S[i+1] = 'W' then ( wSum[i+1] := 1 ) else skip ; if reS[i+1] = 'E' then ( eSum[i+1] := 1 ) else skip ) else ( if S[i+1] = 'W' then ( wSum[i+1] := wSum[i - 1+1] + 1 ) else ( wSum[i+1] := wSum[i - 1+1] ) ; if reS[i+1] = 'E' then ( eSum[i+1] := eSum[i - 1+1] + 1 ) else ( eSum[i+1] := eSum[i - 1+1] ) )) ; eSum := eSum(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var cost : OclAny := eSum[1+1] ; for i : Integer.subrange(1, N-1) do ( if i = N - 1 then ( if (cost->compareTo(wSum[N - 2+1])) > 0 then ( cost := wSum[N - 2+1] ) else skip ) else ( if (cost->compareTo(wSum[i - 1+1] + eSum[i + 1+1])) > 0 then ( cost := wSum[i - 1+1] + eSum[i + 1+1] ) else skip )) ; execute (cost)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(N : int,S : str): w=[0]*N e=[0]*N wt=0 et=0 a=[0]*N for i in range(N): s=S[i] w[i]=wt if s=="W" : wt+=1 if s=="E" : et+=1 e[i]=et for i in range(N): a[i]=w[i]+et-e[i] print(min(a)) return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() N=int(next(tokens)) S=next(tokens) solve(N,S) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(N : int, S : String) pre: true post: true activity: var w : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var e : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var wt : int := 0 ; var et : int := 0 ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for i : Integer.subrange(0, N-1) do ( var s : OclAny := S[i+1] ; w[i+1] := wt ; if s = "W" then ( wt := wt + 1 ) else skip ; if s = "E" then ( et := et + 1 ) else skip ; e[i+1] := et) ; for i : Integer.subrange(0, N-1) do ( a[i+1] := w[i+1] + et - e[i+1]) ; execute ((a)->min())->display() ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var N : int := ("" + (((tokens).next())))->toInteger() ; var S : OclAny := (tokens).next() ; solve(N, S); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def power(x,a): res=1 ; while(a): if(a & 1): res=res*x ; x=x*x ; a>>=1 ; return res ; def breakInteger(N): if(N==2): return 1 ; if(N==3): return 2 ; maxProduct=0 ; if(N % 3==0): maxProduct=power(3,int(N/3)); return maxProduct ; elif(N % 3==1): maxProduct=2*2*power(3,int(N/3)-1); return maxProduct ; elif(N % 3==2): maxProduct=2*power(3,int(N/3)); return maxProduct ; maxProduct=breakInteger(10); print(maxProduct); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; maxProduct := breakInteger(10); ; execute (maxProduct)->display();; operation power(x : OclAny, a : OclAny) pre: true post: true activity: var res : int := 1; ; while (a) do ( if (MathLib.bitwiseAnd(a, 1)) then ( res := res * x; ) else skip ; x := x * x; ; a := a div (2->pow(1));) ; return res;; operation breakInteger(N : OclAny) pre: true post: true activity: if (N = 2) then ( return 1; ) else skip ; if (N = 3) then ( return 2; ) else skip ; var maxProduct : int := 0; ; if (N mod 3 = 0) then ( maxProduct := power(3, ("" + ((N / 3)))->toInteger()); ; return maxProduct; ) else (if (N mod 3 = 1) then ( maxProduct := 2 * 2 * power(3, ("" + ((N / 3)))->toInteger() - 1); ; return maxProduct; ) else (if (N mod 3 = 2) then ( maxProduct := 2 * power(3, ("" + ((N / 3)))->toInteger()); ; return maxProduct; ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline def main(): N=int(input()) A=input()[:-1] E=[0] for a in A : if a=='E' : E.append(E[-1]+1) else : E.append(E[-1]) min_=float('inf') for i in range(N): min_=min(min_,(i-E[i])+(E[N]-E[i+1])) print(min_) if(__name__=='__main__'): main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; skip ; if (__name__ = '__main__') then ( main() ) else skip; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : OclAny := input()->front() ; var E : Sequence := Sequence{ 0 } ; for a : A do ( if a = 'E' then ( execute ((E->last() + 1) : E) ) else ( execute ((E->last()) : E) )) ; var min_ : double := ("" + (('inf')))->toReal() ; for i : Integer.subrange(0, N-1) do ( min_ := Set{min_, (i - E[i+1]) + (E[N+1] - E[i + 1+1])}->min()) ; execute (min_)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq n=int(input()) s=list(map(int,input().split())) maxn=(2**(n+1))-1 tree=[0]*maxn s=sorted(s) h=[] heapq.heappush(h,0) error=False i=len(s)-1 while i>=0 : count=1 while i>=0 and s[i-1]==s[i]: count+=1 i-=1 if len(h)toInteger() ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var maxn : double := ((2)->pow((n + 1))) - 1 ; var tree : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, maxn) ; s := s->sort() ; var h : Sequence := Sequence{} ; heapq.heappush(h, 0) ; var error : boolean := false ; var i : double := (s)->size() - 1 ; while i >= 0 do ( var count : int := 1 ; while i >= 0 & s[i - 1+1] = s[i+1] do ( count := count + 1 ; i := i - 1) ; if ((h)->size()->compareTo(count)) < 0 then ( error := true ; break ) else skip ; var dh : Sequence := Sequence{} ; for _anon : Integer.subrange(0, count-1) do ( execute ((heapq.heappop(h)) : dh)) ; for hi : dh do ( while (hi * 2 + 2->compareTo(maxn)) < 0 do ( heapq.heappush(h, hi * 2 + 1) ; var hi : double := hi * 2 + 2)) ; i := i - 1) ; if error then ( execute ('No')->display() ) else ( execute ('Yes')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) chips=list(map(int,input().split())) odd=0 even=0 for num in chips : if num % 2==0 : even+=1 else : odd+=1 print(min(even,odd)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var chips : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var odd : int := 0 ; var even : int := 0 ; for num : chips do ( if num mod 2 = 0 then ( even := even + 1 ) else ( odd := odd + 1 )) ; execute (Set{even, odd}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=[int(x)for x in input().split()] p=0 for e in x : if e % 2==0 : p+=1 i=n-p if i>p : print(p) else : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var p : int := 0 ; for e : x do ( if e mod 2 = 0 then ( p := p + 1 ) else skip) ; var i : double := n - p ; if (i->compareTo(p)) > 0 then ( execute (p)->display() ) else ( execute (i)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Ejercicio : def handle(self,chips_count : int,chips : list): even=sum(list(map(self.is_even,chips))) no_even=chips_count-even coins=even if even>no_even : coins=no_even return coins def is_even(self,n : str): return(int(n)% 2)==0 if __name__=='__main__' : chips_count=int(input()) chips=input().split(" ") use_case=Ejercicio() result=use_case.handle(chips_count,chips) print(result) ------------------------------------------------------------ OCL File: --------- class Ejercicio { static operation newEjercicio() : Ejercicio pre: true post: Ejercicio->exists( _x | result = _x ); operation handle(chips_count : int,chips : Sequence(OclAny)) : OclAny pre: true post: true activity: var even : OclAny := (((chips)->collect( _x | (self.is_even)->apply(_x) )))->sum() ; var no_even : double := chips_count - even ; var coins : OclAny := even ; if (even->compareTo(no_even)) > 0 then ( coins := no_even ) else skip ; return coins; operation is_even(n : String) : OclAny pre: true post: true activity: return (("" + ((n)))->toInteger() mod 2) = 0; } class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var chips_count : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var chips : OclAny := input().split(" ") ; var use_case : Ejercicio := (Ejercicio.newEjercicio()).initialise() ; var result : OclAny := use_case.handle(chips_count, chips) ; execute (result)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=sum(int(j)% 2 for j in input().split()) print(min(b,a-b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) % (expr (atom (number (integer 2)))))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( )))))))))->sum() ; execute (Set{b, a - b}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) q=0 w=0 for i in arr : if i % 2 : q+=1 else : w+=1 print(min(q,w)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : int := 0 ; var w : int := 0 ; for i : arr do ( if i mod 2 then ( q := q + 1 ) else ( w := w + 1 )) ; execute (Set{q, w}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,ceil N=10100000 temp=[True]*(N+1) temp[0]=temp[1]=False for i in range(2,ceil(sqrt(N+1))): if temp[i]: temp[i+i : : i]=[False]*(len(temp[i+i : : i])) quadruplet=[True,False,True,False,False,False,True,False,True] while True : try : n=int(input()) except : break for i in range(n,9,-1): if temp[i]and temp[i-8 : i+1]==quadruplet : print(i) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 10100000 ; var temp : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (N + 1)) ; temp->first() := false; var temp[1+1] : boolean := false ; for i : Integer.subrange(2, ceil(sqrt(N + 1))-1) do ( if temp[i+1] then ( temp(subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name i))))))) : (sliceop : (test (logical_test (comparison (expr (atom (name i)))))))) := MatrixLib.elementwiseMult(Sequence{ false }, ((temp(subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name i))))))) : (sliceop : (test (logical_test (comparison (expr (atom (name i)))))))))->size())) ) else skip) ; var quadruplet : Sequence := Sequence{true}->union(Sequence{false}->union(Sequence{true}->union(Sequence{false}->union(Sequence{false}->union(Sequence{false}->union(Sequence{true}->union(Sequence{false}->union(Sequence{ true })))))))) ; while true do ( try ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) catch (_e : OclException) do ( break) ; for i : Integer.subrange(9 + 1, n)->reverse() do ( if temp[i+1] & temp.subrange(i - 8+1, i + 1) = quadruplet then ( execute (i)->display() ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,bisect PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") def primes2(n): n,correction=n-n % 6+6,2-(n % 6>1) sieve=[True]*(n//3) for i in range(1,int(n**0.5)//3+1): if sieve[i]: k=3*i+1 | 1 sieve[k*k//3 : : 2*k]=[False]*((n//6-k*k//6-1)//k+1) sieve[k*(k-2*(i & 1)+4)//3 : : 2*k]=[False]*((n//6-k*(k-2*(i & 1)+4)//6-1)//k+1) return[2,3]+[3*i+1 | 1 for i in range(1,n//3-correction)if sieve[i]] primes=primes2(10**7) quad_max=[] for k in range(3,len(primes)): p=primes[k] if primes[k-3]==p-8 and primes[k-2]==p-6 and primes[k-1]==p-2 : quad_max.append(p) while True : n=int(input()) if n==0 : break idx=bisect.bisect_right(quad_max,n) print(quad_max[idx-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; skip ; var primes : OclAny := primes2((10)->pow(7)) ; var quad_max : Sequence := Sequence{} ; for k : Integer.subrange(3, (primes)->size()-1) do ( var p : OclAny := primes[k+1] ; if primes[k - 3+1] = p - 8 & primes[k - 2+1] = p - 6 & primes[k - 1+1] = p - 2 then ( execute ((p) : quad_max) ) else skip) ; while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var idx : OclAny := bisect.bisect_right(quad_max, n) ; execute (quad_max[idx - 1+1])->display()); operation primes2(n : OclAny) : OclAny pre: true post: true activity: var correction : OclAny := null; Sequence{n,correction} := Sequence{n - n mod 6 + 6,2 - (n mod 6 > 1)} ; var sieve : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (n div 3)) ; for i : Integer.subrange(1, ("" + (((n)->pow(0.5))))->toInteger() div 3 + 1-1) do ( if sieve[i+1] then ( var k : int := MathLib.bitwiseOr(3 * i + 1, 1) ; sieve(subscript (test (logical_test (comparison (expr (expr (expr (atom (name k))) * (expr (atom (name k)))) // (expr (atom (number (integer 3)))))))) : (sliceop : (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name k))))))))) := MatrixLib.elementwiseMult(Sequence{ false }, ((n div 6 - k * k div 6 - 1) div k + 1)) ; sieve(subscript (test (logical_test (comparison (expr (expr (expr (atom (name k))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name k))) - (expr (expr (atom (number (integer 2)))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) & (expr (atom (number (integer 1))))))))) ))))) + (expr (atom (number (integer 4))))))))) )))) // (expr (atom (number (integer 3)))))))) : (sliceop : (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name k))))))))) := MatrixLib.elementwiseMult(Sequence{ false }, ((n div 6 - k * (k - 2 * (MathLib.bitwiseAnd(i, 1)) + 4) div 6 - 1) div k + 1)) ) else skip) ; return Sequence{2}->union(Sequence{ 3 })->union(Integer.subrange(1, n div 3 - correction-1)->select(i | sieve[i+1])->collect(i | (MathLib.bitwiseOr(3 * i + 1, 1)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_right as br def quad_primes(n): is_prime=[True]*(n+1) is_prime[0]=is_prime[1]=False for i in range(2,int(n**(1/2))+1): if is_prime[i]: for j in range(i*i,n+1,i): is_prime[j]=False return[i+8 for i in range(n-7)if is_prime[i]and is_prime[i+2]and is_prime[i+6]and is_prime[i+8]] quad=quad_primes(10000000) while True : n=int(input()) if n==0 : break print(quad[br(quad,n)-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var quad : OclAny := quad_primes(10000000) ; while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; execute (quad[br(quad, n) - 1+1])->display()); operation quad_primes(n : OclAny) : OclAny pre: true post: true activity: var is_prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (n + 1)) ; is_prime->first() := false; var is_prime[1+1] : boolean := false ; for i : Integer.subrange(2, ("" + (((n)->pow((1 / 2)))))->toInteger() + 1-1) do ( if is_prime[i+1] then ( for j : Integer.subrange(i * i, n + 1-1)->select( $x | ($x - i * i) mod i = 0 ) do ( is_prime[j+1] := false) ) else skip) ; return Integer.subrange(0, n - 7-1)->select(i | is_prime[i+1] & is_prime[i + 2+1] & is_prime[i + 6+1] & is_prime[i + 8+1])->collect(i | (i + 8)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from bisect import bisect_right limit=10**7 sieve=[True]*limit sieve[0]=sieve[1]=False for i in range(4,limit,2): sieve[i]=False for i in range(3,int(len(sieve)**0.5)+1,2): if sieve[i]: for i in range(i**2,limit,i): sieve[i]=False primes=[i for i,x in enumerate(sieve)if x] s_primes=set(primes) quadruplet_primes=[13] for p in primes : if p % 10==1 and p+2 in s_primes and p+6 in s_primes and p+8 in s_primes : quadruplet_primes.append(p+8) def main(args): while True : n=int(input()) if n==0 : break print(quadruplet_primes[bisect_right(quadruplet_primes,n)-1]) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var limit : double := (10)->pow(7) ; var sieve : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, limit) ; sieve->first() := false; var sieve[1+1] : boolean := false ; for i : Integer.subrange(4, limit-1)->select( $x | ($x - 4) mod 2 = 0 ) do ( sieve[i+1] := false) ; for i : Integer.subrange(3, ("" + ((((sieve)->size())->pow(0.5))))->toInteger() + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if sieve[i+1] then ( for i : Integer.subrange((i)->pow(2), limit-1)->select( $x | ($x - (i)->pow(2)) mod i = 0 ) do ( sieve[i+1] := false) ) else skip) ; var primes : Sequence := Integer.subrange(1, (sieve)->size())->collect( _indx | Sequence{_indx-1, (sieve)->at(_indx)} )->select(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in x)->collect(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in (i)) ; var s_primes : Set := Set{}->union((primes)) ; var quadruplet_primes : Sequence := Sequence{ 13 } ; for p : primes do ( if p mod 10 = 1 & (s_primes)->includes(p + 2) & (s_primes)->includes(p + 6) & (s_primes)->includes(p + 8) then ( execute ((p + 8) : quadruplet_primes) ) else skip) ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation main(args : OclAny) pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; execute (quadruplet_primes[bisect_right(quadruplet_primes, n) - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from itertools import accumulate def input(): return sys.stdin.readline().strip() def list2d(a,b,c): return[[c]*b for i in range(a)] def list3d(a,b,c,d): return[[[d]*c for j in range(b)]for i in range(a)] def list4d(a,b,c,d,e): return[[[[e]*d for j in range(c)]for j in range(b)]for i in range(a)] def ceil(x,y=1): return int(-(-x//y)) def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(N=None): return list(MAP())if N is None else[INT()for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10**9) INF=float('inf') MOD=10**9+7 N=1000001 table=list(range(N+1)) for i in range(2,N+1): if table[i]==i : for j in range(i,N+1,i): table[j]*=1-1/i table[0]=1 ans=list(accumulate(table)) for i in range(INT()): a=INT() print(int(ans[a])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; N := 1000001 ; var table : Sequence := (Integer.subrange(0, N + 1-1)) ; for i : Integer.subrange(2, N + 1-1) do ( if table[i+1] = i then ( for j : Integer.subrange(i, N + 1-1)->select( $x | ($x - i) mod i = 0 ) do ( table[j+1] := table[j+1] * 1 - 1 / i) ) else skip) ; table->first() := 1 ; var ans : Sequence := (accumulate(table)) ; for i : Integer.subrange(0, INT()-1) do ( a := INT() ; execute (("" + ((ans[a+1])))->toInteger())->display()); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation list2d(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, a-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ c }, b))); operation list3d(a : OclAny, b : OclAny, c : OclAny, d : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, a-1)->select(i | true)->collect(i | (Integer.subrange(0, b-1)->select(j | true)->collect(j | (MatrixLib.elementwiseMult(Sequence{ d }, c))))); operation list4d(a : OclAny, b : OclAny, c : OclAny, d : OclAny, e : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, a-1)->select(i | true)->collect(i | (Integer.subrange(0, b-1)->select(j | true)->collect(j | (Integer.subrange(0, c-1)->select(j | true)->collect(j | (MatrixLib.elementwiseMult(Sequence{ e }, d))))))); operation ceil(x : OclAny, y : int) : OclAny pre: true post: true activity: if y->oclIsUndefined() then y := 1 else skip; return ("" + ((-(-x div y))))->toInteger(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST(N : OclAny) : OclAny pre: true post: true activity: if N->oclIsUndefined() then N := null else skip; return if N <>= null then (MAP()) else Integer.subrange(0, N-1)->select(i | true)->collect(i | (INT())) endif; operation Yes() pre: true post: true activity: execute ('Yes')->display(); operation No() pre: true post: true activity: execute ('No')->display(); operation YES() pre: true post: true activity: execute ('YES')->display(); operation NO() pre: true post: true activity: execute ('NO')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=3 C=3 import sys def minCost(cost,m,n): if(n<0 or m<0): return sys.maxsize elif(m==0 and n==0): return cost[m][n] else : return cost[m][n]+min(minCost(cost,m-1,n-1),minCost(cost,m-1,n),minCost(cost,m,n-1)) def min(x,y,z): if(xunion(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{Sequence{4}->union(Sequence{8}->union(Sequence{ 2 }))}->union(Sequence{ Sequence{1}->union(Sequence{5}->union(Sequence{ 3 })) })) ; execute (minCost(cost, 2, 2))->display(); operation minCost(cost : OclAny, m : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n < 0 or m < 0) then ( return (trailer . (name maxsize)) ) else (if (m = 0 & n = 0) then ( return cost[m+1][n+1] ) else ( return cost[m+1][n+1] + Set{minCost(cost, m - 1, n - 1), minCost(cost, m - 1, n), minCost(cost, m, n - 1)}->min() ) ) ; operation min(x : OclAny, y : OclAny, z : OclAny) : OclAny pre: true post: true activity: if ((x->compareTo(y)) < 0) then ( return if ((x->compareTo(z)) < 0) then x else z endif ) else ( return if ((y->compareTo(z)) < 0) then y else z endif ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- move=[[[10,10],[4,4]],[[8,2],[4,2]]] MAX_N=10000000+1 sos=[1]*(MAX_N+1) sos[0]=sos[1]=0 for i in range(2,int(MAX_N**0.5)+1): if sos[i]: for j in range(i+i,MAX_N+1,i): sos[j]=0 while 1 : try : n=int(input()) if not n : break n-=(n % 2==0) while n>=13 : if sos[n]and sos[n-2]and sos[n-6]and sos[n-8]: print(n) break else : n-=move[sos[n-8]][sos[n-6]][sos[n-2]] except : pass ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var move : Sequence := Sequence{Sequence{Sequence{10}->union(Sequence{ 10 })}->union(Sequence{ Sequence{4}->union(Sequence{ 4 }) })}->union(Sequence{ Sequence{Sequence{8}->union(Sequence{ 2 })}->union(Sequence{ Sequence{4}->union(Sequence{ 2 }) }) }) ; var MAX_N : int := 10000000 + 1 ; var sos : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (MAX_N + 1)) ; sos->first() := 0; var sos[1+1] : int := 0 ; for i : Integer.subrange(2, ("" + (((MAX_N)->pow(0.5))))->toInteger() + 1-1) do ( if sos[i+1] then ( for j : Integer.subrange(i + i, MAX_N + 1-1)->select( $x | ($x - i + i) mod i = 0 ) do ( sos[j+1] := 0) ) else skip) ; while 1 do ( try ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(n) then ( break ) else skip ; n := n - (n mod 2 = 0) ; while n >= 13 do ( if sos[n+1] & sos[n - 2+1] & sos[n - 6+1] & sos[n - 8+1] then ( execute (n)->display() ; break ) else ( n := n - move[sos[n - 8+1]+1][sos[n - 6+1]+1][sos[n - 2+1]+1] ))) catch (_e : OclException) do ( skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) r=[] s=0 l=0 for i in range(len(a)): if a[i]!=1 : s=s+a[i] t=i+1-l p=s-1*t if p % 2==0 : r.append(2) else : r.append(1) else : l=l+1 if len(r)==0 : r.append(2) else : q=r[-1] r.append(q) for i in range(len(r)): print(r[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var r : Sequence := Sequence{} ; var s : int := 0 ; var l : int := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( if a[i+1] /= 1 then ( s := s + a[i+1] ; var t : double := i + 1 - l ; var p : double := s - 1 * t ; if p mod 2 = 0 then ( execute ((2) : r) ) else ( execute ((1) : r) ) ) else ( l := l + 1 ; if (r)->size() = 0 then ( execute ((2) : r) ) else ( var q : String := r->last() ; execute ((q) : r) ) )) ; for i : Integer.subrange(0, (r)->size()-1) do ( execute (r[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) w=list(map(int,input().split())) c=2 for i in w : if i==1 : print(c) elif i % 2==0 : c=3-c print(c) else : print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 2 ; for i : w do ( if i = 1 then ( execute (c)->display() ) else (if i mod 2 = 0 then ( c := 3 - c ; execute (c)->display() ) else ( execute (c)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=False inp=input() while not inp : inp=input() a=[int(i)for i in inp.split()] winner=False for i in a : if i % 2==0 : winner=not winner if winner : print(1) else : print(2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : boolean := false ; var inp : String := (OclFile["System.in"]).readLine() ; while not(inp = "") do ( inp := (OclFile["System.in"]).readLine()) ; a := inp.split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var winner : boolean := false ; for i : a do ( if i mod 2 = 0 then ( winner := not(winner) ) else skip ; if winner then ( execute (1)->display() ) else ( execute (2)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def el7gsbeder(Tnumber,Vlists): numberofeven=0 numberofodds=0 for i in range(Tnumber): if(float(Vlists[i])%(2)==0): numberofeven=numberofeven+1 else : if(float(Vlists[i])!=1): numberofodds=numberofodds+1 if(numberofeven % 2==1): print("1") else : print("2") line=[input()for _ in range(2)] el7gsbeder(int(line[0]),line[1].split()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var line : Sequence := Integer.subrange(0, 2-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; el7gsbeder(("" + ((line->first())))->toInteger(), line[1+1].split()); operation el7gsbeder(Tnumber : OclAny, Vlists : OclAny) pre: true post: true activity: var numberofeven : int := 0 ; var numberofodds : int := 0 ; for i : Integer.subrange(0, Tnumber-1) do ( if (("" + ((Vlists[i+1])))->toReal() mod (2) = 0) then ( numberofeven := numberofeven + 1 ) else ( if (("" + ((Vlists[i+1])))->toReal() /= 1) then ( numberofodds := numberofodds + 1 ) else skip ) ; if (numberofeven mod 2 = 1) then ( execute ("1")->display() ) else ( execute ("2")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) flag=True x=[int(x)for x in input().split()] for i in range(n): c=x[i] if c % 2==0 : flag=not flag if flag : print(2) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var flag : boolean := true ; var x : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for i : Integer.subrange(0, n-1) do ( var c : OclAny := x[i+1] ; if c mod 2 = 0 then ( flag := not(flag) ) else skip ; if flag then ( execute (2)->display() ) else ( execute (1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def powerOfTwo(n): return(not(n & n-1)) def onlyFirstAndLastAreSet(n): if(n==1): return True return powerOfTwo(n-1) n=9 if(onlyFirstAndLastAreSet(n)): print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 9 ; if (onlyFirstAndLastAreSet(n)) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); operation powerOfTwo(n : OclAny) : OclAny pre: true post: true activity: return (not((MathLib.bitwiseAnd(n, n - 1)))); operation onlyFirstAndLastAreSet(n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return true ) else skip ; return powerOfTwo(n - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minimumCostOfBreaking(X,Y,m,n): res=0 X.sort(reverse=True) Y.sort(reverse=True) hzntl=1 ; vert=1 i=0 ; j=0 while(iY[j]): res+=X[i]*vert hzntl+=1 i+=1 else : res+=Y[j]*hzntl vert+=1 j+=1 total=0 while(iunion(Sequence{1}->union(Sequence{3}->union(Sequence{1}->union(Sequence{ 4 })))) ; Y := Sequence{4}->union(Sequence{1}->union(Sequence{ 2 })) ; execute (minimumCostOfBreaking(X, Y, m - 1, n - 1))->display(); operation minimumCostOfBreaking(X : OclAny, Y : OclAny, m : OclAny, n : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; X := X->sort() ; Y := Y->sort() ; var hzntl : int := 1; var vert : int := 1 ; var i : int := 0; var j : int := 0 ; while ((i->compareTo(m)) < 0 & (j->compareTo(n)) < 0) do ( if ((X[i+1]->compareTo(Y[j+1])) > 0) then ( res := res + X[i+1] * vert ; hzntl := hzntl + 1 ; i := i + 1 ) else ( res := res + Y[j+1] * hzntl ; vert := vert + 1 ; j := j + 1 )) ; var total : int := 0 ; while ((i->compareTo(m)) < 0) do ( total := total + X[i+1] ; i := i + 1) ; res := res + total * vert ; total := 0 ; while ((j->compareTo(n)) < 0) do ( total := total + Y[j+1] ; j := j + 1) ; res := res + total * hzntl ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r,D,x=map(int,input().split()) for i in range(10): x=r*x-D print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : OclAny := null; var D : OclAny := null; var x : OclAny := null; Sequence{r,D,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, 10-1) do ( var x : double := r * x - D ; execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math from collections import defaultdict,deque,Counter from bisect import bisect_left,bisect_right from itertools import combinations,permutations,product from heapq import heappush,heappop from functools import lru_cache input=sys.stdin.readline rs=lambda : input().strip() ri=lambda : int(input()) rl=lambda : list(map(int,input().split())) mod=1000000007 sys.setrecursionlimit(1000000) r,D,x=rl() for i in range(1,11): x=r*x-D print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var rs : Function := lambda $$ : OclAny in (input()->trim()) ; var ri : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var rl : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var mod : int := 1000000007 ; sys.setrecursionlimit(1000000) ; var r : OclAny := null; var D : OclAny := null; var x : OclAny := null; Sequence{r,D,x} := rl->apply() ; for i : Integer.subrange(1, 11-1) do ( var x : double := r * x - D ; execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=sorted(map(int,input().split())) print(min(sum(abs(x-i)for x,i in zip(p,range(s,n+1,2)))for s in(1,2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; execute (((argument (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (name i))))))))) ))))))) (comp_for for (exprlist (expr (atom (name x))) , (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p))))))) , (argument (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1))))))) , (test (logical_test (comparison (expr (atom (number (integer 2)))))))) ))))))))->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_prime_set(ub): from itertools import chain from math import sqrt if ub<4 : return({},{},{2},{2,3})[ub] ub,ub_sqrt=ub+1,int(sqrt(ub))+1 primes={2,3}| set(chain(range(5,ub,6),range(7,ub,6))) du=primes.difference_update for n in chain(range(5,ub_sqrt,6),range(7,ub_sqrt,6)): if n in primes : du(range(n*3,ub,n*2)) return primes def get_totient_count_range(ub,prime_set): ub,totient_count=ub+1,list(range(ub+1)) for prime in prime_set : totient_count[prime]-=1 for m in range(prime*2,ub,prime): totient_count[m]=totient_count[m]*(prime-1)//prime return totient_count import sys from itertools import accumulate ub=10**6 primes=get_prime_set(ub) a=get_totient_count_range(ub,primes) a[1]=2 a=list(accumulate(a)) input() print(*(a[int(n)]for n in sys.stdin),sep="\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; ub := (10)->pow(6) ; primes := get_prime_set(ub) ; var a : OclAny := get_totient_count_range(ub, primes) ; a[1+1] := 2 ; a := (accumulate(a)) ; input() ; execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))) ])))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin))))))) ))))))))->display(); operation get_prime_set(ub : OclAny) : OclAny pre: true post: true activity: skip ; skip ; if ub < 4 then ( return Sequence{Set{}, Set{}, Set{ 2 }, Set{2}->union(Set{ 3 })}[ub+1] ) else skip ; var ub_sqrt : OclAny := null; Sequence{ub,ub_sqrt} := Sequence{ub + 1,("" + ((sqrt(ub))))->toInteger() + 1} ; var primes : int := MathLib.bitwiseOr(Set{2}->union(Set{ 3 }), Set{}->union((chain(Integer.subrange(5, ub-1)->select( $x | ($x - 5) mod 6 = 0 ), Integer.subrange(7, ub-1)->select( $x | ($x - 7) mod 6 = 0 ))))) ; var du : OclAny := primes.difference_update ; for n : chain(Integer.subrange(5, ub_sqrt-1)->select( $x | ($x - 5) mod 6 = 0 ), Integer.subrange(7, ub_sqrt-1)->select( $x | ($x - 7) mod 6 = 0 )) do ( if (primes)->includes(n) then ( du(Integer.subrange(n * 3, ub-1)->select( $x | ($x - n * 3) mod n * 2 = 0 )) ) else skip) ; return primes; operation get_totient_count_range(ub : OclAny, prime_set : OclAny) : OclAny pre: true post: true activity: var totient_count : OclAny := null; Sequence{ub,totient_count} := Sequence{ub + 1,(Integer.subrange(0, ub + 1-1))} ; for prime : prime_set do ( totient_count[prime+1] := totient_count[prime+1] - 1 ; for m : Integer.subrange(prime * 2, ub-1)->select( $x | ($x - prime * 2) mod prime = 0 ) do ( totient_count[m+1] := totient_count[m+1] * (prime - 1) div prime)) ; return totient_count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import heapq import math import fractions import bisect import itertools from collections import Counter from collections import deque from operator import itemgetter def input(): return sys.stdin.readline().strip() def mp(): return map(int,input().split()) def lmp(): return list(map(int,input().split())) r,d,x=mp() for i in range(10): x=r*x-d print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var r : OclAny := null; var d : OclAny := null; var x : OclAny := null; Sequence{r,d,x} := mp() ; for i : Integer.subrange(0, 10-1) do ( var x : double := r * x - d ; execute (x)->display()); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation mp() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation lmp() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=input().split() a=int(a) b=int(b) c=int(c) i=0 while i<10 : i=i+1 c=a*c-b print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := input().split() ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; var c : int := ("" + ((c)))->toInteger() ; var i : int := 0 ; while i < 10 do ( i := i + 1 ; c := a * c - b ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r,D,x=map(int,input().split()) for i in range(2,12): print(int((r**(i-1))*(x+D/(1-r))-D/(1-r))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : OclAny := null; var D : OclAny := null; var x : OclAny := null; Sequence{r,D,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(2, 12-1) do ( execute (("" + ((((r)->pow((i - 1))) * (x + D / (1 - r)) - D / (1 - r))))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def gcd(a,b): if(a==0): return b return math.gcd(b % a,a) def countPairs(G,L): count=0 p=G*L for a in range(1,L+1): if(not(p % a)and math.gcd(a,p//a)==G): count+=1 return count if __name__=="__main__" : G=2 L=12 print("Total possible pair with GCD ",G,end="") print(" & LCM ",L,end="") print("=",countPairs(G,L)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( G := 2 ; L := 12 ; execute ("Total possible pair with GCD ")->display() ; execute (" & LCM ")->display() ; execute ("=")->display() ) else skip; operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0) then ( return b ) else skip ; return (b mod a)->gcd(a); operation countPairs(G : OclAny, L : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var p : double := G * L ; for a : Integer.subrange(1, L + 1-1) do ( if (not((p mod a)) & (a)->gcd(p div a) = G) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def multiply(a,b): mul=[[0 for x in range(3)]for y in range(3)]; for i in range(3): for j in range(3): mul[i][j]=0 ; for k in range(3): mul[i][j]+=a[i][k]*b[k][j]; for i in range(3): for j in range(3): a[i][j]=mul[i][j]; return a ; def power(F,n): M=[[1,1,1],[1,0,0],[0,1,0]]; if(n==1): return F[0][0]+F[0][1]; power(F,int(n/2)); F=multiply(F,F); if(n % 2!=0): F=multiply(F,M); return F[0][0]+F[0][1]; def findNthTerm(n): F=[[1,1,1],[1,0,0],[0,1,0]]; return power(F,n-2); n=5 ; print("F(5)is",findNthTerm(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 5; ; execute ("F(5)is")->display();; operation multiply(a : OclAny, b : OclAny) pre: true post: true activity: var mul : Sequence := Integer.subrange(0, 3-1)->select(y | true)->collect(y | (Integer.subrange(0, 3-1)->select(x | true)->collect(x | (0)))); ; for i : Integer.subrange(0, 3-1) do ( for j : Integer.subrange(0, 3-1) do ( mul[i+1][j+1] := 0; ; for k : Integer.subrange(0, 3-1) do ( mul[i+1][j+1] := mul[i+1][j+1] + a[i+1][k+1] * b[k+1][j+1];))) ; for i : Integer.subrange(0, 3-1) do ( for j : Integer.subrange(0, 3-1) do ( a[i+1][j+1] := mul[i+1][j+1];)) ; return a;; operation power(F : OclAny, n : OclAny) pre: true post: true activity: var M : Sequence := Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))}->union(Sequence{Sequence{1}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{ Sequence{0}->union(Sequence{1}->union(Sequence{ 0 })) })); ; if (n = 1) then ( return F->first()->first() + F->first()[1+1]; ) else skip ; power(F, ("" + ((n / 2)))->toInteger()); ; F := multiply(F, F); ; if (n mod 2 /= 0) then ( F := multiply(F, M); ) else skip ; return F->first()->first() + F->first()[1+1];; operation findNthTerm(n : OclAny) pre: true post: true activity: F := Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))}->union(Sequence{Sequence{1}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{ Sequence{0}->union(Sequence{1}->union(Sequence{ 0 })) })); ; return power(F, n - 2);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def MinimumValue(x,y): if(x>y): x,y=y,x a=1 b=x-1 c=y-b print(a,b,c) x=123 y=13 MinimumValue(x,y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := 123 ; y := 13 ; MinimumValue(x, y); operation MinimumValue(x : OclAny, y : OclAny) pre: true post: true activity: if ((x->compareTo(y)) > 0) then ( Sequence{x,y} := Sequence{y,x} ) else skip ; var a : int := 1 ; var b : double := x - 1 ; var c : double := y - b ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def checkPossibility(self,nums): broken_num=0 for i in range(len(nums)-1): if(nums[i]>nums[i+1]): broken_num+=1 if broken_num>=2 : return False if(i-1<0 or nums[i-1]<=nums[i+1]): nums[i]=nums[i+1] else : nums[i+1]=nums[i] return True ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation checkPossibility(nums : OclAny) : OclAny pre: true post: true activity: var broken_num : int := 0 ; for i : Integer.subrange(0, (nums)->size() - 1-1) do ( if ((nums[i+1]->compareTo(nums[i + 1+1])) > 0) then ( broken_num := broken_num + 1 ; if broken_num >= 2 then ( return false ) else skip ; if (i - 1 < 0 or (nums[i - 1+1]->compareTo(nums[i + 1+1])) <= 0) then ( nums[i+1] := nums[i + 1+1] ) else ( nums[i + 1+1] := nums[i+1] ) ) else skip) ; return true; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(mid,array,n,K): count=0 sum=0 for i in range(n): if(array[i]>mid): return False sum+=array[i] if(sum>mid): count+=1 sum=array[i] count+=1 if(count<=K): return True return False def solve(array,n,K): start=1 end=0 for i in range(n): end+=array[i] answer=0 while(start<=end): mid=(start+end)//2 if(check(mid,array,n,K)): answer=mid end=mid-1 else : start=mid+1 return answer if __name__=='__main__' : array=[1,2,3,4] n=len(array) K=3 print(solve(array,n,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( array := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))) ; n := (array)->size() ; K := 3 ; execute (solve(array, n, K))->display() ) else skip; operation check(mid : OclAny, array : OclAny, n : OclAny, K : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ((array[i+1]->compareTo(mid)) > 0) then ( return false ) else skip ; sum := sum + array[i+1] ; if ((sum->compareTo(mid)) > 0) then ( count := count + 1 ; sum := array[i+1] ) else skip) ; count := count + 1 ; if ((count->compareTo(K)) <= 0) then ( return true ) else skip ; return false; operation solve(array : OclAny, n : OclAny, K : OclAny) : OclAny pre: true post: true activity: var start : int := 1 ; var end : int := 0 ; for i : Integer.subrange(0, n-1) do ( end := end + array[i+1]) ; var answer : int := 0 ; while ((start->compareTo(end)) <= 0) do ( mid := (start + end) div 2 ; if (check(mid, array, n, K)) then ( answer := mid ; end := mid - 1 ) else ( start := mid + 1 )) ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter while True : m,n=(int(s)for s in input().split()) if not m : break objs=[int(input(),2)for i in range(n)] dp=[[0]*(1<1 : dp[mask][masked]=min(max(dp[mask | b][masked],dp[mask | b][masked | b])+1 for b in bits if not b & mask) print(dp[0][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; if not(m) then ( break ) else skip ; var objs : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine(), 2)))->toInteger())) ; var dp : Sequence := Integer.subrange(0, 1 * (2->pow(m))-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (1 * (2->pow(m)))))) ; var bits : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (1 * (2->pow(i)))) ; for mask : (Integer.subrange(0, 1 * (2->pow(m))-1))->reverse() do ( var s : OclAny := Counter((argument (test (logical_test (comparison (expr (expr (atom (name obj))) & (expr (atom (name mask))))))) (comp_for for (exprlist (expr (atom (name obj)))) in (logical_test (comparison (expr (atom (name objs)))))))) ; for _tuple : s->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var masked : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); if value > 1 then ( dp[mask+1][masked+1] := ((argument (test (logical_test (comparison (expr (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name mask))) | (expr (atom (name b))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name masked)))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name mask))) | (expr (atom (name b))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name masked))) | (expr (atom (name b))))))))) ])))))))) )))) + (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name bits))))) (comp_iter if (test (logical_test not (logical_test (comparison (expr (expr (atom (name b))) & (expr (atom (name mask))))))))))))->min() ) else skip)) ; execute (dp->first()->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import factorial as f n,p=map(int,input().split()) m=sum(map(lambda x : int(x)% 2,input().split())) o=n-m a=2**o b=0 if m : if p : for i in range(1,m+1,2): b+=f(m)//(f(m-i)*f(i)) else : for i in range(0,m+1,2): b+=f(m)//(f(m-i)*f(i)) print(a*b) else : if p==0 : print(a) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : OclAny := ((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() mod 2))->apply(_x) ))->sum() ; var o : double := n - m ; var a : double := (2)->pow(o) ; var b : int := 0 ; if m then ( if p then ( for i : Integer.subrange(1, m + 1-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( b := b + f(m) div (f(m - i) * f(i))) ) else ( for i : Integer.subrange(0, m + 1-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( b := b + f(m) div (f(m - i) * f(i))) ) ; execute (a * b)->display() ) else ( if p = 0 then ( execute (a)->display() ) else ( execute (0)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) cnt=n>>1 data=list(map(int,input().split())) data.sort() ans1=0 for i in range(cnt): ans1+=abs(data[i]-(2*i+1)) ans2=0 for i in range(cnt): ans2+=abs(data[i]-(2*i+2)) print(min(ans1,ans2)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cnt : int := n /(2->pow(1)) ; var data : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; data := data->sort() ; var ans1 : int := 0 ; for i : Integer.subrange(0, cnt-1) do ( ans1 := ans1 + (data[i+1] - (2 * i + 1))->abs()) ; var ans2 : int := 0 ; for i : Integer.subrange(0, cnt-1) do ( ans2 := ans2 + (data[i+1] - (2 * i + 2))->abs()) ; execute (Set{ans1, ans2}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter while True : m,n=(int(s)for s in input().split()) if not m : break objs=[int(input(),2)for i in range(n)] dp=[bytearray(1<1 : dp[mask][masked]=min(max(dp[mask+b][masked],dp[mask+b][masked+b])+1 for b in bits if not b & mask) print(dp[0][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; if not(m) then ( break ) else skip ; var objs : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine(), 2)))->toInteger())) ; var dp : Sequence := Integer.subrange(0, 1 * (2->pow(m))-1)->select(i | true)->collect(i | (bytearray(1 * (2->pow(m))))) ; var bits : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (1 * (2->pow(i)))) ; for mask : (Integer.subrange(0, (1 * (2->pow(m))) - 1-1))->reverse() do ( var s : OclAny := Counter((argument (test (logical_test (comparison (expr (expr (atom (name obj))) & (expr (atom (name mask))))))) (comp_for for (exprlist (expr (atom (name obj)))) in (logical_test (comparison (expr (atom (name objs)))))))) ; for _tuple : s->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var masked : OclAny := _tuple->at(_indx); _indx := _indx + 1; var count : OclAny := _tuple->at(_indx); if count > 1 then ( dp[mask+1][masked+1] := ((argument (test (logical_test (comparison (expr (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name mask))) + (expr (atom (name b))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name masked)))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name mask))) + (expr (atom (name b))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name masked))) + (expr (atom (name b))))))))) ])))))))) )))) + (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name bits))))) (comp_iter if (test (logical_test not (logical_test (comparison (expr (expr (atom (name b))) & (expr (atom (name mask))))))))))))->min() ) else skip)) ; execute (dp->first()->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() print("2018"+s[4 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; execute ("2018" + s.subrange(4+1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter while True : m,n=(int(s)for s in input().split()) if not m : break objects=[int(input(),2)for i in range(n)] dp=[bytearray(1<1 : dp[mask][masked]=min(max(dp[mask+b][masked],dp[mask+b][masked+b])+1 for b in bits if not b & mask) print(dp[0][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; if not(m) then ( break ) else skip ; var objects : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine(), 2)))->toInteger())) ; var dp : Sequence := Integer.subrange(0, 1 * (2->pow(m))-1)->select(i | true)->collect(i | (bytearray(1 * (2->pow(m))))) ; var bits : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (1 * (2->pow(i)))) ; for mask : (Integer.subrange(0, (1 * (2->pow(m))) - 1-1))->reverse() do ( for _tuple : Counter((argument (test (logical_test (comparison (expr (expr (atom (name obj))) & (expr (atom (name mask))))))) (comp_for for (exprlist (expr (atom (name obj)))) in (logical_test (comparison (expr (atom (name objects))))))))->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var masked : OclAny := _tuple->at(_indx); _indx := _indx + 1; var count : OclAny := _tuple->at(_indx); if count > 1 then ( dp[mask+1][masked+1] := ((argument (test (logical_test (comparison (expr (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name mask))) + (expr (atom (name b))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name masked)))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name mask))) + (expr (atom (name b))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name masked))) + (expr (atom (name b))))))))) ])))))))) )))) + (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name bits))))) (comp_iter if (test (logical_test not (logical_test (comparison (expr (expr (atom (name b))) & (expr (atom (name mask))))))))))))->min() ) else skip)) ; execute (dp->first()->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter while True : m,n=(int(s)for s in input().split()) if not m : break objects=[int(input(),2)for i in range(n)] dp=[bytearray(1<1 : dp[asked][masked]=min(max(dp[asked+b][masked],dp[asked+b][masked+b])for b in bits if not b & asked)+1 print(dp[0][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; if not(m) then ( break ) else skip ; var objects : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine(), 2)))->toInteger())) ; var dp : Sequence := Integer.subrange(0, 1 * (2->pow(m))-1)->select(i | true)->collect(i | (bytearray(1 * (2->pow(m))))) ; var bits : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (1 * (2->pow(i)))) ; for asked : (Integer.subrange(0, (1 * (2->pow(m))) - 1-1))->reverse() do ( for _tuple : Counter((argument (test (logical_test (comparison (expr (expr (atom (name obj))) & (expr (atom (name asked))))))) (comp_for for (exprlist (expr (atom (name obj)))) in (logical_test (comparison (expr (atom (name objects))))))))->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var masked : OclAny := _tuple->at(_indx); _indx := _indx + 1; var count : OclAny := _tuple->at(_indx); if count > 1 then ( dp[asked+1][masked+1] := ((argument (test (logical_test (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name asked))) + (expr (atom (name b))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name masked)))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name asked))) + (expr (atom (name b))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name masked))) + (expr (atom (name b))))))))) ])))))))) ))))))) (comp_for for (exprlist (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name bits))))) (comp_iter if (test (logical_test not (logical_test (comparison (expr (expr (atom (name b))) & (expr (atom (name asked))))))))))))->min() + 1 ) else skip)) ; execute (dp->first()->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter import sys def solve(): readline=sys.stdin.buffer.readline write=sys.stdout.buffer.write M,N=map(int,readline().split()) if M==N==0 : return False B=[int(readline(),2)for i in range(N)] memo={} def dfs(s,t): key=(s,t) if key in memo : return memo[key] c=0 for b in B : if(b & s)==t : c+=1 if c<=1 : memo[key]=0 return 0 res=M for i in range(M): b=(1<collect( _x | (OclType["int"])->apply(_x) ) ; if M = N & (N == 0) then ( return false ) else skip ; var B : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (("" + ((readline(), 2)))->toInteger())) ; var memo : OclAny := Set{} ; skip ; write((atom b "%d\n") mod dfs(0, 0)) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- test=int(input()) for i in range(test): a,b=input().split() a=int(a) b=int(b) c=(min(a,b)*2)**2 d=(max(a,b)**2) print(max(c,d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var test : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, test-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; var c : double := ((Set{a, b}->min() * 2))->pow(2) ; var d : double := ((Set{a, b}->max())->pow(2)) ; execute (Set{c, d}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): a,b=map(int,input().split()) if 2*min(a,b)>=max(a,b): print(min(a,b)*4*min(a,b)) else : print(max(a,b)*max(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (2 * Set{a, b}->min()->compareTo(Set{a, b}->max())) >= 0 then ( execute (Set{a, b}->min() * 4 * Set{a, b}->min())->display() ) else ( execute (Set{a, b}->max() * Set{a, b}->max())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) first=[] sec=[] for i in range(0,x): a,b=map(int,input().split()) first.append(a) sec.append(b) for i in range(0,x): if first[i]>=sec[i]: if sec[i]*2>=first[i]: print((sec[i]*2)**2) else : print(first[i]**2) if sec[i]>first[i]: if first[i]*2>sec[i]: print((first[i]*2)**2) else : print(sec[i]**2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var first : Sequence := Sequence{} ; var sec : Sequence := Sequence{} ; for i : Integer.subrange(0, x-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a) : first) ; execute ((b) : sec)) ; for i : Integer.subrange(0, x-1) do ( if (first[i+1]->compareTo(sec[i+1])) >= 0 then ( if (sec[i+1] * 2->compareTo(first[i+1])) >= 0 then ( execute (((sec[i+1] * 2))->pow(2))->display() ) else ( execute ((first[i+1])->pow(2))->display() ) ) else skip ; if (sec[i+1]->compareTo(first[i+1])) > 0 then ( if (first[i+1] * 2->compareTo(sec[i+1])) > 0 then ( execute (((first[i+1] * 2))->pow(2))->display() ) else ( execute ((sec[i+1])->pow(2))->display() ) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): a,b=input().split() a=int(a) b=int(b) if a<=b : a=a*2 else : b=b*2 if a>b : temp=a else : temp=b print(temp**2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; if (a->compareTo(b)) <= 0 then ( a := a * 2 ) else ( b := b * 2 ) ; if (a->compareTo(b)) > 0 then ( var temp : int := a ) else ( temp := b ) ; execute ((temp)->pow(2))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): a,b=map(int,input().split()) a,b=min(a,b),max(a,b) if 2*a>=b : print(4*a*a) else : print(b**2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{Set{a, b}->min(),Set{a, b}->max()} ; if (2 * a->compareTo(b)) >= 0 then ( execute (4 * a * a)->display() ) else ( execute ((b)->pow(2))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) w=sorted(map(int,input().split())) s1=list(range(1,n+1,2)) s2=list(range(2,n+1,2)) c1=0 for i in range(n//2): c1+=abs(w[i]-s1[i]) c2=0 for i in range(n//2): c2+=abs(w[i]-s2[i]) print(min(c1,c2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var s1 : Sequence := (Integer.subrange(1, n + 1-1)->select( $x | ($x - 1) mod 2 = 0 )) ; var s2 : Sequence := (Integer.subrange(2, n + 1-1)->select( $x | ($x - 2) mod 2 = 0 )) ; var c1 : int := 0 ; for i : Integer.subrange(0, n div 2-1) do ( c1 := c1 + (w[i+1] - s1[i+1])->abs()) ; var c2 : int := 0 ; for i : Integer.subrange(0, n div 2-1) do ( c2 := c2 + (w[i+1] - s2[i+1])->abs()) ; execute (Set{c1, c2}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) ans="YES" zero=[] temp=-1 for i in range(0,n): if b[i]==0 : zero.append(a[i]) continue x=a[i]-b[i] if temp==-1 : temp=x if x<0 or x!=temp : ans="NO" break if n==len(zero): temp=max(zero) for i in zero : if i<=temp : continue else : ans="NO" break print(ans) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : String := "YES" ; var zero : Sequence := Sequence{} ; var temp : int := -1 ; for i : Integer.subrange(0, n-1) do ( if b[i+1] = 0 then ( execute ((a[i+1]) : zero) ; continue ) else skip ; var x : double := a[i+1] - b[i+1] ; if temp = -1 then ( temp := x ) else skip ; if x < 0 or x /= temp then ( ans := "NO" ; break ) else skip) ; if n = (zero)->size() then ( temp := (zero)->max() ) else skip ; for i : zero do ( if (i->compareTo(temp)) <= 0 then ( continue ) else ( ans := "NO" ; break )) ; execute (ans)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) d=max(a)-max(b) i=0 while i=0): i+=1 continue else : print('No') break else : print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : double := (a)->max() - (b)->max() ; var i : int := 0 ; (compound_stmt while (test (logical_test (comparison (comparison (expr (atom (name i)))) < (comparison (expr (atom (name n))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))) == (comparison (expr (atom (name d)))))) or (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (number (integer 0))))))) and (logical_test (comparison (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))) < (comparison (expr (atom (name d))))))))) )))))))) ))))) and (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name d)))) >= (comparison (expr (atom (number (integer 0))))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt continue)))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'No'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'Yes'))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys IS=lambda : sys.stdin.readline().rstrip() II=lambda : int(IS()) MII=lambda : list(map(int,IS().split())) MIIZ=lambda : list(map(lambda x : x-1,MII())) INIT_VAL=0 MD2=lambda d1,d2 :[[INIT_VAL]*d2 for _ in range(d1)] MD3=lambda d1,d2,d3 :[MD2(d2,d3)for _ in range(d1)] DIVC=lambda x,y :-(-x//y) DIVF=lambda x,y : x//y def main(): print('2018'+IS()[4 :]) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var IS : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var II : Function := lambda $$ : OclAny in (("" + ((IS->apply())))->toInteger()) ; var MII : Function := lambda $$ : OclAny in (((IS->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var MIIZ : Function := lambda $$ : OclAny in (((MII->apply())->collect( _x | (lambda x : OclAny in (x - 1))->apply(_x) ))) ; var INIT_VAL : int := 0 ; var MD2 : Function := lambda d1 : OclAny, d2 : OclAny in (Integer.subrange(0, d1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ INIT_VAL }, d2)))) ; var MD3 : Function := lambda d1 : OclAny, d2 : OclAny, d3 : OclAny in (Integer.subrange(0, d1-1)->select(_anon | true)->collect(_anon | (MD2->apply(d2, d3)))) ; var DIVC : Function := lambda x : OclAny, y : OclAny in (-(-x div y)) ; var DIVF : Function := lambda x : OclAny, y : OclAny in (x div y) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: execute ('2018' + IS->apply().subrange(4+1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) t,=R() exec(t*"R();a=0,*R();b=[0,*R()];m=max(x-y for x,y in zip(a,b));print('YNEOS'[[max(0,x-m)for x in a]!=b::2]);") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := R->apply() ; (expr (expr (atom (name t))) * (expr (atom "R();a=0,*R();b=[0,*R()];m=max(x-y for x,y in zip(a,b));print('YNEOS'[[max(0,x-m)for x in a]!=b::2]);"))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=[int(x)for x in input().split()] b=[int(x)for x in input().split()] should_be=None for i in range(0,n): if(a[i]>=b[i]): if b[i]==0 : continue if should_be is None : should_be=a[i]-b[i] continue if a[i]-b[i]==should_be : continue print('NO') break else : for i in range(0,n): if b[i]==0 : if should_be is not None and a[i]-should_be>b[i]: print('NO') break else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var b : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var should_be : OclAny := null ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) >= (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt continue)))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name should_be)))) is (comparison (expr (atom None)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name should_be)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))))))) (stmt (simple_stmt (small_stmt continue)))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))) == (comparison (expr (atom (name should_be))))))) : (suite (stmt (simple_stmt (small_stmt continue))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))) (else_clause else : (suite (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name should_be)))) is not (comparison (expr (atom None))))) and (logical_test (comparison (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name should_be))))) > (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=[int(x)for x in input().split()] b=[int(x)for x in input().split()] maxi=max(a[i]-b[i]for i in range(n)) print('YNEOS'[1-(all(max(a[i]-maxi,0)==b[i]for i in range(n))and maxi>=0): : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var b : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var maxi : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->max() ; execute ('YNEOS'(subscript (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) - (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (expr (atom (name all)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name maxi)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))))) == (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))) )))))) and (logical_test (comparison (comparison (expr (atom (name maxi)))) >= (comparison (expr (atom (number (integer 0)))))))))) ))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): s=input() n=len(s) count_ab=0 count_ba=0 for i in range(n-1): if s[i]+s[i+1]=='ab' : count_ab+=1 elif s[i]+s[i+1]=='ba' : count_ba+=1 if count_ba==count_ab : print(s) elif count_ab>count_ba : a=list(s) if s[0]+s[1]=='ab' : a[0]="b" print("".join(a)) else : a[n-1]="a" print("".join(a)) else : a=list(s) if s[0]+s[1]=='ba' : a[0]="a" print("".join(a)) else : a[n-1]="b" print("".join(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var n : int := (s)->size() ; var count_ab : int := 0 ; var count_ba : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if s[i+1] + s[i + 1+1] = 'ab' then ( count_ab := count_ab + 1 ) else (if s[i+1] + s[i + 1+1] = 'ba' then ( count_ba := count_ba + 1 ) else skip)) ; if count_ba = count_ab then ( execute (s)->display() ) else (if (count_ab->compareTo(count_ba)) > 0 then ( var a : Sequence := (s)->characters() ; if s->first() + s[1+1] = 'ab' then ( a->first() := "b" ; execute (StringLib.sumStringsWithSeparator((a), ""))->display() ) else ( a[n - 1+1] := "a" ; execute (StringLib.sumStringsWithSeparator((a), ""))->display() ) ) else ( a := (s)->characters() ; if s->first() + s[1+1] = 'ba' then ( a->first() := "a" ; execute (StringLib.sumStringsWithSeparator((a), ""))->display() ) else ( a[n - 1+1] := "b" ; execute (StringLib.sumStringsWithSeparator((a), ""))->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a=input() print(a[:-1]+a[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : String := (OclFile["System.in"]).readLine() ; execute (a->front() + a->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): s=input().strip() flip=0 for i in range(1,len(s)): if s[i]!=s[i-1]: flip+=1 if flip % 2==1 : if s[0]=='a' : s='b'+s[1 :] else : s='a'+s[1 :] print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var s : OclAny := input()->trim() ; var flip : int := 0 ; for i : Integer.subrange(1, (s)->size()-1) do ( if s[i+1] /= s[i - 1+1] then ( flip := flip + 1 ) else skip) ; if flip mod 2 = 1 then ( if s->first() = 'a' then ( s := 'b' + s->tail() ) else ( s := 'a' + s->tail() ) ) else skip ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): s=list(input()) if(len(s)!=1): ab=0 ba=0 lastab=0 lastba=0 for i in range(1,len(s)): if s[i]=="b" and s[i-1]=="a" : ab+=1 elif s[i]=="a" and s[i-1]=="b" : ba+=1 if ab!=ba : if s[0]=="a" : s[0]="b" else : s[0]="a" print(''.join(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if ((s)->size() /= 1) then ( var ab : int := 0 ; var ba : int := 0 ; var lastab : int := 0 ; var lastba : int := 0 ; for i : Integer.subrange(1, (s)->size()-1) do ( if s[i+1] = "b" & s[i - 1+1] = "a" then ( ab := ab + 1 ) else (if s[i+1] = "a" & s[i - 1+1] = "b" then ( ba := ba + 1 ) else skip)) ; if ab /= ba then ( if s->first() = "a" then ( s->first() := "b" ) else ( s->first() := "a" ) ) else skip ) else skip ; execute (StringLib.sumStringsWithSeparator((s), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) num=list(map(int,input().split())) even,odd=0,0 for i in range(n//2): if(num[i]% 2==0): even+=1 else : odd+=1 num.sort() if(even==0 or odd==0): print(0) else : ans1,ans2=0,0 for i in range(n//2): x=num[i] ans1+=abs(x-2*(i+1)) ans2+=abs(x-2*(i+1)+1) print(min(ans1,ans2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var num : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var even : OclAny := null; var odd : OclAny := null; Sequence{even,odd} := Sequence{0,0} ; for i : Integer.subrange(0, n div 2-1) do ( if (num[i+1] mod 2 = 0) then ( even := even + 1 ) else ( odd := odd + 1 )) ; num := num->sort() ; if (even = 0 or odd = 0) then ( execute (0)->display() ) else ( var ans1 : OclAny := null; var ans2 : OclAny := null; Sequence{ans1,ans2} := Sequence{0,0} ; for i : Integer.subrange(0, n div 2-1) do ( var x : OclAny := num[i+1] ; ans1 := ans1 + (x - 2 * (i + 1))->abs() ; ans2 := ans2 + (x - 2 * (i + 1) + 1)->abs()) ; execute (Set{ans1, ans2}->min())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): s=input() if s[0]==s[-1]: print(s) else : if s[0]=='a' : print(s[0 : len(s)-1]+'a') else : print(s[0 : len(s)-1]+'b') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if s->first() = s->last() then ( execute (s)->display() ) else ( if s->first() = 'a' then ( execute (s.subrange(0+1, (s)->size() - 1) + 'a')->display() ) else ( execute (s.subrange(0+1, (s)->size() - 1) + 'b')->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def even_or_odd(N): l=len(N); if(N[l-1]=='0' or N[l-1]=='2' or N[l-1]=='4' or N[l-1]=='6'): return("Even") else : return("Odd") N="735" print(even_or_odd(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := "735" ; execute (even_or_odd(N))->display(); operation even_or_odd(N : OclAny) : OclAny pre: true post: true activity: var l : int := (N)->size(); ; if (N[l - 1+1] = '0' or N[l - 1+1] = '2' or N[l - 1+1] = '4' or N[l - 1+1] = '6') then ( return ("Even") ) else ( return ("Odd") ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[int(i)for i in input().split()] list=[] for i in range(a[0]): list.append([]) for i in range(a[1]): cmd=[int(i)for i in input().split()] if cmd[0]==0 : list[cmd[1]].append(cmd[2]) elif cmd[0]==1 : maped=map(str,list[cmd[1]]) output=" ".join(maped) print(output) elif cmd[0]==2 : list[cmd[1]]=[] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var OclType["Sequence"] : Sequence := Sequence{} ; for i : Integer.subrange(0, a->first()-1) do ( execute ((Sequence{}) : OclType["Sequence"])) ; for i : Integer.subrange(0, a[1+1]-1) do ( var cmd : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if cmd->first() = 0 then ( (expr (atom (name list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name cmd)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name cmd)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))) )))) ) else (if cmd->first() = 1 then ( var maped : Sequence := ([cmd[1+1]+1])->collect( _x | (OclType["String"])->apply(_x) ) ; var output : String := StringLib.sumStringsWithSeparator((maped), " ") ; execute (output)->display() ) else (if cmd->first() = 2 then ( [cmd[1+1]+1] := Sequence{} ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class UnionFind(object): def __init__(self,n=1): self.par=[i for i in range(n)] self.rank=[0 for _ in range(n)] self.size=[1 for _ in range(n)] def find(self,x): if self.par[x]==x : return x else : self.par[x]=self.find(self.par[x]) return self.par[x] def union(self,x,y): x=self.find(x) y=self.find(y) if x!=y : if self.rank[x]exists( _x | result = _x ); attribute par : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)); attribute rank : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)); attribute size : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (1)); operation initialise(n : int) : pre: true post: true activity: self.par := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)) ; self.rank := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)) ; self.size := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (1)); return self; operation find(x : OclAny) : OclAny pre: true post: true activity: if self.par[x+1] = x then ( return x ) else ( self.par[x+1] := self->indexOf(self.par[x+1]) - 1 ; return self.par[x+1] ); operation union(x : OclAny,y : OclAny) pre: true post: true activity: x := self->indexOf(x) - 1 ; y := self->indexOf(y) - 1 ; if x /= y then ( if (self.rank[x+1]->compareTo(self.rank[y+1])) < 0 then ( Sequence{x,y} := Sequence{y,x} ) else skip ; if self.rank[x+1] = self.rank[y+1] then ( self.rank[x+1] := self.rank[x+1] + 1 ) else skip ; self.par[y+1] := x ; self.size[x+1] := self.size[x+1] + self.size[y+1] ) else skip; operation is_same(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: return self->indexOf(x) - 1 = self->indexOf(y) - 1; operation get_size(x : OclAny) : OclAny pre: true post: true activity: x := self->indexOf(x) - 1 ; return self.size[x+1]; } class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var P : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var uf : UnionFind := (UnionFind.newUnionFind()).initialise(N) ; for i : Integer.subrange(0, M-1) do ( Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; x := x - 1; y := y - 1 ; uf.union(x, y)) ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( var now : double := P[i+1] - 1 ; var loc : OclAny := i ; if uf.is_same(now, loc) then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import itertools read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines N=readline().decode('utf8') S=N[: 3]+'8'+N[4 :] print(S) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; var N : OclAny := readline().decode('utf8') ; var S : OclAny := N.subrange(1,3) + '8' + N.subrange(4+1) ; execute (S)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin from collections import deque n,q=map(int,stdin.readline().split()) queries=stdin.readlines() A=[deque()for _ in range(n)] for query in queries : query=query.split() if query[0]=='0' : A[int(query[1])].append(query[2]) elif query[0]=='1' : print(' '.join(list(A[int(query[1])]))) else : A[int(query[1])].clear() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var queries : OclAny := stdin.readlines() ; var A : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (())) ; for query : queries do ( var query : OclAny := query.split() ; if query->first() = '0' then ( (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name query)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name query)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))) )))) ) else (if query->first() = '1' then ( execute (StringLib.sumStringsWithSeparator(((A[("" + ((query[1+1])))->toInteger()+1])), ' '))->display() ) else ( (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name query)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ))))))))) ])) (trailer . (name clear) (arguments ( )))) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Vector(): def __init__(self,num_vector): self.vector=[[]for i in range(0,num_vector)] def pushBack(self,t,x): self.vector[t].append(x) return self def dump(self,t): print(' '.join(map(str,self.vector[t]))) return self def clear(self,t): self.vector[t].clear() return self num_vector,num_queue=tuple(map(int,input().split(' '))) A=Vector(num_vector) for i in range(0,num_queue): queue=tuple(map(int,input().split(' '))) if queue[0]==0 : A.pushBack(queue[1],queue[2]) elif queue[0]==1 : A.dump(queue[1]) elif queue[0]==2 : A.clear(queue[1]) ------------------------------------------------------------ OCL File: --------- class Vector { static operation newVector() : Vector pre: true post: Vector->exists( _x | result = _x ); attribute vector : Sequence := Integer.subrange(0, num_vector-1)->select(i | true)->collect(i | (Sequence{})); operation initialise(num_vector : OclAny) : pre: true post: true activity: self.vector := Integer.subrange(0, num_vector-1)->select(i | true)->collect(i | (Sequence{})); return self; operation pushBack(t : OclAny,x : OclAny) : OclAny pre: true post: true activity: (expr (atom (name self)) (trailer . (name vector) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) ; return self; operation dump(t : OclAny) : OclAny pre: true post: true activity: execute (StringLib.sumStringsWithSeparator(((self.vector[t+1])->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ; return self; operation clear(t : OclAny) : OclAny pre: true post: true activity: (expr (atom (name self)) (trailer . (name vector) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name clear) (arguments ( )))) ; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; var num_queue : OclAny := null; Sequence{num_vector,num_queue} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var A : Vector := (Vector.newVector()).initialise(num_vector) ; for i : Integer.subrange(0, num_queue-1) do ( var queue : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; if queue->first() = 0 then ( A.pushBack(queue[1+1], queue[2+1]) ) else (if queue->first() = 1 then ( A.dump(queue[1+1]) ) else (if queue->first() = 2 then ( execute (A /<: A) ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from typing import List if __name__=="__main__" : num_vector,num_query=map(lambda x : int(x),input().split()) int_vector : List[List[int]]=[[]for _ in range(num_vector)] for _ in range(num_query): op,*value=map(lambda x : int(x),input().split()) if(0==op): int_vector[value[0]].append(value[1]) elif(1==op): print(" ".join([str(elem)for elem in int_vector[value[0]]])) elif(2==op): int_vector[value[0]]=[] else : pass ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var num_vector : OclAny := null; var num_query : OclAny := null; Sequence{num_vector,num_query} := (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ) ; var int_vector : OclAny := Integer.subrange(0, num_vector-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, num_query-1) do ( var op : OclAny := null; var value : OclAny := null; Sequence{op,value} := (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ) ; if (0 = op) then ( (expr (atom (name int_vector)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name value)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name value)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))) ) else (if (1 = op) then ( execute (StringLib.sumStringsWithSeparator((int_vector[value->first()+1]->select(elem | true)->collect(elem | (("" + ((elem)))))), " "))->display() ) else (if (2 = op) then ( int_vector[value->first()+1] := Sequence{} ) else ( skip ) ) ) ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def run(): n,q=[int(x)for x in input().split()] ls=[[]for _ in range(n)] for _ in range(q): command=input() if command.startswith('0'): i,j=[int(x)for x in command[2 :].split()] ls[i].append(j) elif command.startswith('1'): i=int(command[2 :]) print(" ".join([str(x)for x in ls[i]])) elif command.startswith('2'): i=int(command[2 :]) ls[i]=[] else : raise ValueError('invalid command') if __name__=='__main__' : run() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( run() ) else skip; operation run() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ls : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, q-1) do ( var command : String := (OclFile["System.in"]).readLine() ; if command->hasPrefix('0') then ( var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := command.subrange(2+1).split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; (expr (atom (name ls)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) ) else (if command->hasPrefix('1') then ( var i : int := ("" + ((command.subrange(2+1))))->toInteger() ; execute (StringLib.sumStringsWithSeparator((ls[i+1]->select(x | true)->collect(x | (("" + ((x)))))), " "))->display() ) else (if command->hasPrefix('2') then ( i := ("" + ((command.subrange(2+1))))->toInteger() ; ls[i+1] := Sequence{} ) else ( error IncorrectElementException.newIncorrectElementException('invalid command') ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() num=input().split() even=0 for i in num : if int(i)% 2==0 : even+=1 if even==1 : for i in num : if int(i)% 2==0 : print(num.index(i)+1) else : for i in num : if int(i)% 2==1 : print(num.index(i)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var num : OclAny := input().split() ; var even : int := 0 ; for i : num do ( if ("" + ((i)))->toInteger() mod 2 = 0 then ( even := even + 1 ) else skip) ; if even = 1 then ( for i : num do ( if ("" + ((i)))->toInteger() mod 2 = 0 then ( execute (num->indexOf(i) - 1 + 1)->display() ) else skip) ) else ( for i : num do ( if ("" + ((i)))->toInteger() mod 2 = 1 then ( execute (num->indexOf(i) - 1 + 1)->display() ) else skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=sorted(map(int,input().split())) print(min(sum(abs(x-i)for x,i in zip(p,range(s,n+1,2)))for s in(1,2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; execute (((argument (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (name i))))))))) ))))))) (comp_for for (exprlist (expr (atom (name x))) , (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p))))))) , (argument (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1))))))) , (test (logical_test (comparison (expr (atom (number (integer 2)))))))) ))))))))->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isDifferent(val,val2,val3): if val % 2==0 and(val2 % 2!=0 and val3 % 2!=0): return True elif val % 2!=0 and(val2 % 2==0 and val3 % 2==0): return True return False n=int(input()) list=list(map(int,input().split(' '))) if isDifferent(list[0],list[1],list[2]): print(1) elif isDifferent(list[-1],list[-2],list[-3]): print(len(list)) else : for i in range(1,len(list)-1): if isDifferent(list[i],list[i-1],list[i+1]): print(i+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var OclType["Sequence"] : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; if isDifferent(->first(), [1+1], [2+1]) then ( execute (1)->display() ) else (if isDifferent(->last(), ->front()->last(), ->reverse()->at(-(-3))) then ( execute ((OclType["Sequence"])->size())->display() ) else ( for i : Integer.subrange(1, (OclType["Sequence"])->size() - 1-1) do ( if isDifferent([i+1], [i - 1+1], [i + 1+1]) then ( execute (i + 1)->display() ) else skip) ) ) ; operation isDifferent(val : OclAny, val2 : OclAny, val3 : OclAny) : OclAny pre: true post: true activity: if val mod 2 = 0 & (val2 mod 2 /= 0 & val3 mod 2 /= 0) then ( return true ) else (if val mod 2 /= 0 & (val2 mod 2 = 0 & val3 mod 2 = 0) then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) k1=0 k2=0 a=[int(s)for s in input().split()] z=[0,0] for i in range(n): if a[i]% 2!=0 : k1=i+1 z[0]+=1 else : k2=i+1 z[1]+=1 if z[0]==1 : print(k1) else : print(k2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k1 : int := 0 ; var k2 : int := 0 ; var a : Sequence := input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; var z : Sequence := Sequence{0}->union(Sequence{ 0 }) ; for i : Integer.subrange(0, n-1) do ( if a[i+1] mod 2 /= 0 then ( k1 := i + 1 ; z->first() := z->first() + 1 ) else ( k2 := i + 1 ; z[1+1] := z[1+1] + 1 )) ; if z->first() = 1 then ( execute (k1)->display() ) else ( execute (k2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) list=[int(x)% 2 for x in input().split()] if sum(list)==1 : print(list.index(1)+1) else : print(list.index(0)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var OclType["Sequence"] : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() mod 2)) ; if (OclType["Sequence"])->sum() = 1 then ( execute (MatrixLib.elementwiseAdd(->indexOf(1) - 1, 1))->display() ) else ( execute (MatrixLib.elementwiseAdd(->indexOf(0) - 1, 1))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=list(map(int,input().split())) c=0 s=0 for i in range(a): if b[i]% 2==0 : s+=1 if b[i]% 2!=0 : c+=1 if s>c : for l in range(0,a): if b[l]% 2!=0 : print(l+1) else : for l in range(0,a): if b[l]% 2==0 : print(l+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; var s : int := 0 ; for i : Integer.subrange(0, a-1) do ( if b[i+1] mod 2 = 0 then ( s := s + 1 ) else skip ; if b[i+1] mod 2 /= 0 then ( c := c + 1 ) else skip) ; if (s->compareTo(c)) > 0 then ( for l : Integer.subrange(0, a-1) do ( if b[l+1] mod 2 /= 0 then ( execute (l + 1)->display() ) else skip) ) else ( for l : Integer.subrange(0, a-1) do ( if b[l+1] mod 2 = 0 then ( execute (l + 1)->display() ) else skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(X,Y,N,K): count=[0]*(N+1); sol=0 ; count[0]=0 ; for i in range(1,N+1): count[i]=(count[i-1]+abs(ord(X[i-1])-ord(Y[i-1]))); j=0 ; for i in range(1,N+1): while((count[i]-count[j])>K): j+=1 ; sol=max(sol,i-j); return sol ; if __name__=='__main__' : N=4 ; X="abcd" ; Y="bcde" ; K=3 ; print(solve(X,Y,N,K)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( N := 4; ; X := "abcd"; ; Y := "bcde"; ; K := 3; ; execute (solve(X, Y, N, K))->display(); ) else skip; operation solve(X : OclAny, Y : OclAny, N : OclAny, K : OclAny) pre: true post: true activity: var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)); ; var sol : int := 0; ; count->first() := 0; ; for i : Integer.subrange(1, N + 1-1) do ( count[i+1] := (count[i - 1+1] + ((X[i - 1+1])->char2byte() - (Y[i - 1+1])->char2byte())->abs());) ; var j : int := 0; ; for i : Integer.subrange(1, N + 1-1) do ( while (((count[i+1] - count[j+1])->compareTo(K)) > 0) do ( j := j + 1;) ; sol := Set{sol, i - j}->max();) ; return sol;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s_list=list(input().split('/')) if s_list[0]!='2018' : s_list[0]='2018' s='/'.join(s_list) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s_list : Sequence := (input().split('/')) ; if s_list->first() /= '2018' then ( s_list->first() := '2018' ) else skip ; var s : String := StringLib.sumStringsWithSeparator((s_list), '/') ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq n,m=map(int,input().split()) x=[] y=[] for i in range(n): day,salary=map(int,input().split()) heapq.heappush(x,(-day,-salary)) while x : d,s=heapq.heappop(x) r=m-len(y) if r>=-d : heapq.heappush(y,-s) else : heapq.heappush(y,-s) heapq.heappop(y) print(sum(y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := Sequence{} ; var y : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var day : OclAny := null; var salary : OclAny := null; Sequence{day,salary} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; heapq.heappush(x, Sequence{-day, -salary})) ; while x do ( var d : OclAny := null; var s : OclAny := null; Sequence{d,s} := heapq.heappop(x) ; var r : double := m - (y)->size() ; if (r->compareTo(-d)) >= 0 then ( heapq.heappush(y, -s) ) else ( heapq.heappush(y, -s) ; heapq.heappop(y) )) ; execute ((y)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* from copy import* from heapq import* from string import* from random import* from bisect import* from sys import stdin from sys import maxsize from operator import* from itertools import* from collections import Counter from collections import defaultdict def solve(l,m): n=len(l) L=[[]for i in range(10**5+1)] for i in l : d,r=i L[d].append(r) ans=0 hp=[] for i in range(1,m+1): for j in L[i]: heappush(hp,-j) if(hp): ans-=heappop(hp) return ans N,M=list(map(int,stdin.readline().rstrip().split())) l=[] for _ in range(N): a,b=list(map(int,stdin.readline().rstrip().split())) l.append([a,b]) ans=solve(l,M) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := ((stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := Sequence{} ; for _anon : Integer.subrange(0, N-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((Sequence{a}->union(Sequence{ b })) : l)) ; ans := solve(l, M) ; execute (ans)->display(); operation solve(l : OclAny, m : OclAny) : OclAny pre: true post: true activity: var n : int := (l)->size() ; var L : Sequence := Integer.subrange(0, (10)->pow(5) + 1-1)->select(i | true)->collect(i | (Sequence{})) ; for i : l do ( var d : OclAny := null; var r : OclAny := null; Sequence{d,r} := i ; (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name d)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name r)))))))) ))))) ; var ans : int := 0 ; var hp : Sequence := Sequence{} ; for i : Integer.subrange(1, m + 1-1) do ( for j : L[i+1] do ( heappush(hp, -j)) ; if (hp) then ( ans := ans - heappop(hp) ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline import heapq n,m=map(int,input().split()) jobs=[[]for i in range(m)] for i in range(n): a,b=map(int,input().split()) if a>m : pass else : jobs[m-a].append(b) if len(jobs)==0 : print(0) exit(0) q=[] heapq.heapify(q) ans=0 for i in reversed(range(m)): for b in jobs[i]: heapq.heappush(q,-b) if len(q)!=0 : ans+=heapq.heappop(q)*-1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var jobs : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(m)) > 0 then ( skip ) else ( (expr (atom (name jobs)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name m))) - (expr (atom (name a))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) )) ; if (jobs)->size() = 0 then ( execute (0)->display() ; exit(0) ) else skip ; var q : Sequence := Sequence{} ; heapq.heapify(q) ; var ans : int := 0 ; for i : (Integer.subrange(0, m-1))->reverse() do ( for b : jobs[i+1] do ( heapq.heappush(q, -b)) ; if (q)->size() /= 0 then ( ans := ans + heapq.heappop(q) * -1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,i): self.end=i+1 self.days={i} N,M=list(map(int,input().split())) BA=[] for i in range(N): a,b=list(map(int,input().split())) BA.append((b,a)) ans=0 schedule={} def concat(node1,node2,x): if len(node1.days)exists( _x | result = _x ); attribute end : OclAny := i + 1; attribute days : Set := Set{ i }; operation initialise(i : OclAny) : Node pre: true post: true activity: self.end := i + 1 ; self.days := Set{ i }; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var BA : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((Sequence{b, a}) : BA)) ; var ans : int := 0 ; var schedule : OclAny := Set{} ; skip ; BA := BA->sort() ; for _tuple : BA do (var _indx : int := 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); if (a->compareTo(M)) <= 0 then ( if (schedule)->includes(a) then ( var w : OclAny := schedule[a+1] ; x := w.end ; if (x->compareTo(M)) <= 0 then ( ans := ans + b ; if (schedule)->includes(x + 1) then ( concat(w, schedule[x + 1+1], x) ) else ( schedule[x+1] := w ; (expr (atom (name w)) (trailer . (name days)) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) ; w.end := w.end + 1 ) ) else skip ) else ( ans := ans + b ; if (schedule)->includes(a + 1) then ( w := schedule[a + 1+1] ; if (schedule)->includes(a - 1) then ( concat(schedule[a - 1+1], w, a) ) else ( schedule[a+1] := w ; (expr (atom (name w)) (trailer . (name days)) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))) ) ) else (if (schedule)->includes(a - 1) then ( w := schedule[a - 1+1] ; schedule[a+1] := w ; (expr (atom (name w)) (trailer . (name days)) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))) ; w.end := w.end + 1 ) else ( schedule[a+1] := (Node.newNode()).initialise(a) ) ) ) ) else skip) ; execute (ans)->display(); operation concat(node1 : OclAny, node2 : OclAny, x : OclAny) pre: true post: true activity: if ((node1.days)->size()->compareTo((node2.days)->size())) < 0 then ( Sequence{node1,node2} := Sequence{node2,node1} ) else ( node1.end := node2.end ) ; node1.days := node1.days or node2.days ; for i : node2.days do ( schedule[i+1] := node1) ; schedule[x+1] := node1 ; (expr (atom (name node1)) (trailer . (name days)) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=[int(i)for i in input().split()] a=s[1] c=[int(k)for k in input().split()] l=[] for j in range(1,s[0]+1): l.append(j) while(len(l)!=1): if c[0]<=a : c.pop(0) l.pop(0) else : c.append(c[0]-a) c.pop(0) l.append(l[0]) l.pop(0) print(l[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a : OclAny := s[1+1] ; var c : Sequence := input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger())) ; var l : Sequence := Sequence{} ; for j : Integer.subrange(1, s->first() + 1-1) do ( execute ((j) : l)) ; while ((l)->size() /= 1) do ( if (c->first()->compareTo(a)) <= 0 then ( c := c->excludingAt(0+1) ; l := l->excludingAt(0+1) ) else ( execute ((c->first() - a) : c) ; c := c->excludingAt(0+1) ; execute ((l->first()) : l) ; l := l->excludingAt(0+1) )) ; execute (l->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import heapq def solve(N : int,M : int,A : "List[int]",B : "List[int]"): tasks=list(map(tuple,zip(A,B))) tasks.sort() tasks.reverse() earnables=[] ans=0 for i in range(M+1): while len(tasks)>0 and tasks[-1][0]<=i : _,pay=tasks.pop() heapq.heappush(earnables,-pay) if len(earnables)>0 : ans+=-heapq.heappop(earnables) return ans def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() N=int(next(tokens)) M=int(next(tokens)) A=[int()]*(N) B=[int()]*(N) for i in range(N): A[i]=int(next(tokens)) B[i]=int(next(tokens)) ans=solve(N,M,A,B) if ans is not None : print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(N : int, M : int, A : "List[int]", B : "List[int]") : OclAny pre: true post: true activity: var tasks : Sequence := ((Integer.subrange(1, A->size())->collect( _indx | Sequence{A->at(_indx), B->at(_indx)} ))->collect( _x | (tuple)->apply(_x) )) ; tasks := tasks->sort() ; tasks := tasks->reverse() ; var earnables : Sequence := Sequence{} ; var ans : int := 0 ; for i : Integer.subrange(0, M + 1-1) do ( while (tasks)->size() > 0 & (tasks->last()->first()->compareTo(i)) <= 0 do ( var _anon : OclAny := null; var pay : OclAny := null; Sequence{_anon,pay} := tasks->last() ; tasks := tasks->front() ; heapq.heappush(earnables, -pay)) ; if (earnables)->size() > 0 then ( ans := ans + -heapq.heappop(earnables) ) else skip) ; return ans; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var N : int := ("" + (((tokens).next())))->toInteger() ; var M : int := ("" + (((tokens).next())))->toInteger() ; var A : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (()))->toInteger() }, (N)) ; var B : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (()))->toInteger() }, (N)) ; for i : Integer.subrange(0, N-1) do ( A[i+1] := ("" + (((tokens).next())))->toInteger() ; B[i+1] := ("" + (((tokens).next())))->toInteger()) ; ans := solve(N, M, A, B) ; if not(ans <>= null) then ( execute (ans)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) for _ in range(m): a=int(input()) while a : n,a=a,n % a print(['No','Yes'][n==1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for _anon : Integer.subrange(0, m-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while a do ( var n : OclAny := null; Sequence{n,a} := Sequence{a,n mod a})) ; execute (Sequence{'No'}->union(Sequence{ 'Yes' })->select(n = 1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPrime(n,i=2): if(n<=2): return True if(n==2)else False if(n % i==0): return False if(i*i>n): return true return isPrime(n,i+1) n=15 if(isPrime(n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 15 ; if (isPrime(n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isPrime(n : OclAny, i : int) : OclAny pre: true post: true activity: if i->oclIsUndefined() then i := 2 else skip; if (n <= 2) then ( return if (n = 2) then true else false endif ) else skip ; if (n mod i = 0) then ( return false ) else skip ; if ((i * i->compareTo(n)) > 0) then ( return true ) else skip ; return isPrime(n, i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPrime(n): i=2 while(i*i<=n): if(n % i==0): return False i+=1 return True def minimumSum(n): if(isPrime(n)): return 1 if(n % 2==0): return 2 if(isPrime(n-2)): return 2 return 3 n=27 print(minimumSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 27 ; execute (minimumSum(n))->display(); operation isPrime(n : OclAny) : OclAny pre: true post: true activity: var i : int := 2 ; while ((i * i->compareTo(n)) <= 0) do ( if (n mod i = 0) then ( return false ) else skip ; i := i + 1) ; return true; operation minimumSum(n : OclAny) : OclAny pre: true post: true activity: if (isPrime(n)) then ( return 1 ) else skip ; if (n mod 2 = 0) then ( return 2 ) else skip ; if (isPrime(n - 2)) then ( return 2 ) else skip ; return 3; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def isPrime(x): for i in range(2,int(sqrt(x))+1): if(x % i==0): return 0 ; return 1 ; def minimumCost(n): if(isPrime(n)): return 1 ; if(n % 2==1 and isPrime(n-2)): return 2 ; if(n % 2==0): return 2 ; return 3 ; if __name__=="__main__" : n=6 ; print(minimumCost(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( n := 6; ; execute (minimumCost(n))->display(); ) else skip; operation isPrime(x : OclAny) pre: true post: true activity: for i : Integer.subrange(2, ("" + ((sqrt(x))))->toInteger() + 1-1) do ( if (x mod i = 0) then ( return 0; ) else skip) ; return 1;; operation minimumCost(n : OclAny) pre: true post: true activity: if (isPrime(n)) then ( return 1; ) else skip ; if (n mod 2 = 1 & isPrime(n - 2)) then ( return 2; ) else skip ; if (n mod 2 = 0) then ( return 2; ) else skip ; return 3;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def snoob(x): next=0 if(x): rightOne=x &-(x) nextHigherOneBit=x+int(rightOne) rightOnesPattern=x ^ int(nextHigherOneBit) rightOnesPattern=(int(rightOnesPattern)/int(rightOne)) rightOnesPattern=int(rightOnesPattern)>>2 next=nextHigherOneBit | rightOnesPattern return next x=156 print("Next higher number with "+"same number of set bits is",snoob(x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := 156 ; execute ("Next higher number with " + "same number of set bits is")->display(); operation snoob(x : OclAny) : OclAny pre: true post: true activity: var next : int := 0 ; if (x) then ( var rightOne : int := MathLib.bitwiseAnd(x, -(x)) ; var nextHigherOneBit : OclAny := x + ("" + ((rightOne)))->toInteger() ; var rightOnesPattern : int := MathLib.bitwiseXor(x, ("" + ((nextHigherOneBit)))->toInteger()) ; rightOnesPattern := (("" + ((rightOnesPattern)))->toInteger() / ("" + ((rightOne)))->toInteger()) ; rightOnesPattern := ("" + ((rightOnesPattern)))->toInteger() /(2->pow(2)) ; next := MathLib.bitwiseOr(nextHigherOneBit, rightOnesPattern) ) else skip ; return next; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print("2018",input()[4 :],sep="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ("2018")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def properDivisorSum(n): sum=0 for i in range(n+1): for j in range(1,i+1): if j*j>i : break if(i % j==0): if(i//j==j): sum+=j else : sum+=j+i//j sum=sum-i return sum if __name__=='__main__' : n=4 print(properDivisorSum(n)) n=5 print(properDivisorSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 4 ; execute (properDivisorSum(n))->display() ; n := 5 ; execute (properDivisorSum(n))->display() ) else skip; operation properDivisorSum(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( for j : Integer.subrange(1, i + 1-1) do ( if (j * j->compareTo(i)) > 0 then ( break ) else skip ; if (i mod j = 0) then ( if (i div j = j) then ( sum := sum + j ) else ( sum := sum + j + i div j ) ) else skip) ; sum := sum - i) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def getMinLength(arr,n): count=0 ; result=sys.maxsize ; for i in range(n): if(arr[i]==1): count+=1 ; else : if(count!=0): result=min(result,count); count=0 ; return result ; arr=[1,1,0,0,1,1,1,0,1,1,1,1]; n=len(arr); print(getMinLength(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))))))))))); ; n := (arr)->size(); ; execute (getMinLength(arr, n))->display();; operation getMinLength(arr : OclAny, n : OclAny) pre: true post: true activity: var count : int := 0; ; var result : (trailer . (name maxsize)) := (trailer . (name maxsize)); ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] = 1) then ( count := count + 1; ) else ( if (count /= 0) then ( result := Set{result, count}->min(); ) else skip ; count := 0; )) ; return result;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INT_MAX=99999999999 def getLevenstein(inpt): revInput=inpt[: :-1] n=len(inpt) dp=[[-1 for _ in range(n+1)]for __ in range(n+1)] for i in range(n+1): dp[0][i]=i dp[i][0]=i for i in range(1,n+1): for j in range(1,n+1): if inpt[i-1]==revInput[j-1]: dp[i][j]=dp[i-1][j-1] else : dp[i][j]=1+min(dp[i-1][j],dp[i][j-1]) res=INT_MAX i,j=n,0 while i>=0 : res=min(res,dp[i][j]) if i0 : res=min(res,dp[i-1][j]) i-=1 j+=1 return res if __name__=="__main__" : inpt="myfirstgeekarticle" print(getLevenstein(inpt)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INT_MAX : int := 99999999999 ; skip ; if __name__ = "__main__" then ( inpt := "myfirstgeekarticle" ; execute (getLevenstein(inpt))->display() ) else skip; operation getLevenstein(inpt : OclAny) : OclAny pre: true post: true activity: var revInput : OclAny := inpt(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var n : int := (inpt)->size() ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(__ | true)->collect(__ | (Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (-1)))) ; for i : Integer.subrange(0, n + 1-1) do ( dp->first()[i+1] := i ; dp[i+1]->first() := i) ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, n + 1-1) do ( if inpt[i - 1+1] = revInput[j - 1+1] then ( dp[i+1][j+1] := dp[i - 1+1][j - 1+1] ) else ( dp[i+1][j+1] := 1 + Set{dp[i - 1+1][j+1], dp[i+1][j - 1+1]}->min() ))) ; var res : int := INT_MAX ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{n,0} ; while i >= 0 do ( res := Set{res, dp[i+1][j+1]}->min() ; if (i->compareTo(n)) < 0 then ( res := Set{res, dp[i + 1+1][j+1]}->min() ) else skip ; if i > 0 then ( res := Set{res, dp[i - 1+1][j+1]}->min() ) else skip ; i := i - 1 ; j := j + 1) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100003 ws=[0 for i in range(MAX)] par=[-1 for i in range(MAX*2)] def weight(x): root(x) return ws[x] def root(x): if par[x]<0 : return x p=root(par[x]) ws[x]=ws[x]+ws[par[x]] par[x]=p return par[x] def unite(y,x,z): z=z+weight(x) z=z-weight(y) x=root(x) y=root(y) if x==y : return 0 if par[y]select(i | true)->collect(i | (0)) ; var par : Sequence := Integer.subrange(0, MAX * 2-1)->select(i | true)->collect(i | (-1)) ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( skip ; var N : OclAny := null; var Q : OclAny := null; Sequence{N,Q} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; for q : Integer.subrange(0, Q-1) do ( var t : OclAny := null; var cmd : OclAny := null; Sequence{t,cmd} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; if t then ( Sequence{x,y} := cmd ; z := diff(x, y) ; if z = false then ( execute ("?")->display() ) else ( execute (z[1+1])->display() ) ) else ( Sequence{x,y,z} := cmd ; unite(x, y, z) )) ) else skip; operation weight(x : OclAny) : OclAny pre: true post: true activity: root(x) ; return ws[x+1]; operation root(x : OclAny) : OclAny pre: true post: true activity: if par[x+1] < 0 then ( return x ) else skip ; var p : OclAny := root(par[x+1]) ; ws[x+1] := ws[x+1] + ws[par[x+1]+1] ; par[x+1] := p ; return par[x+1]; operation unite(y : OclAny, x : OclAny, z : OclAny) : OclAny pre: true post: true activity: z := z + weight(x) ; z := z - weight(y) ; x := root(x) ; y := root(y) ; if x = y then ( return 0 ) else skip ; if (par[y+1]->compareTo(par[x+1])) < 0 then ( var tmp : OclAny := x ; x := y ; y := tmp ; z := -z ) else skip ; par[x+1] := par[x+1] + par[y+1] ; par[y+1] := x ; ws[y+1] := z ; return 1; operation diff(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if root(x) /= root(y) then ( return 0 ) else skip ; var ans : double := ws[x+1] - ws[y+1] ; return 1, ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): LIMIT=12000 minsumproduct=[None]*(LIMIT+1) def factorize(n,remain,maxfactor,sum,terms): if remain==1 : if sum>n : raise AssertionError() terms+=n-sum if terms<=LIMIT and(minsumproduct[terms]is None or ndisplay() ) else skip; operation compute() : OclAny pre: true post: true activity: var LIMIT : int := 12000 ; var minsumproduct : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (LIMIT + 1)) ; skip ; for i : Integer.subrange(2, LIMIT * 2 + 1-1) do ( factorize(i, i, i, 0, 0)) ; var ans : OclAny := (Set{}->union((minsumproduct.subrange(2+1))))->sum() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) MOD=10**9+7 fact,fact_inv,inv=[0]*(N+1),[0]*(N+1),[0]*(N+1) def main(): a=list(map(int,input().split())) fact[0]=1 for i in range(1,N+1): fact[i]=fact[i-1]*i % MOD fact_inv[N]=pow(fact[N],MOD-2,MOD) for i in range(N-1,0,-1): fact_inv[i]=fact_inv[i+1]*(i+1)% MOD for i in range(1,N+1): inv[i]=fact_inv[i]*fact[i-1]% MOD b,s=[0]*N,[0]*(N+1) for i in range(1,N+1): s[i]=(s[i-1]+inv[i])% MOD for i in range(N): b[i]=(s[i+1]+s[N-i]-1)% MOD ans=0 for i in range(N): ans=(ans+a[i]*b[i])% MOD ans=ans*fact[N]% MOD print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var MOD : double := (10)->pow(9) + 7 ; var fact : OclAny := null; var fact_inv : OclAny := null; var inv : OclAny := null; Sequence{fact,fact_inv,inv} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)),MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)),MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1))} ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; fact->first() := 1 ; for i : Integer.subrange(1, N + 1-1) do ( fact[i+1] := fact[i - 1+1] * i mod MOD) ; fact_inv[N+1] := (fact[N+1])->pow(MOD - 2) ; for i : Integer.subrange(0 + 1, N - 1)->reverse() do ( fact_inv[i+1] := fact_inv[i + 1+1] * (i + 1) mod MOD) ; for i : Integer.subrange(1, N + 1-1) do ( inv[i+1] := fact_inv[i+1] * fact[i - 1+1] mod MOD) ; var b : OclAny := null; var s : OclAny := null; Sequence{b,s} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, N),MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1))} ; for i : Integer.subrange(1, N + 1-1) do ( s[i+1] := (s[i - 1+1] + inv[i+1]) mod MOD) ; for i : Integer.subrange(0, N-1) do ( b[i+1] := (s[i + 1+1] + s[N - i+1] - 1) mod MOD) ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( ans := (ans + a[i+1] * b[i+1]) mod MOD) ; ans := ans * fact[N+1] mod MOD ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=10**9+7 i=s=r=0 f=1 input() a=input().split() for x in a : s+=pow(i+1,m-2,m); r+=int(x)*~-s+int(a[~ i])*s ; i+=1 ; f=f*i % m print(r*f % m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : double := (10)->pow(9) + 7 ; i := i(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name r)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; var f : int := 1 ; input() ; var a : OclAny := input().split() ; for x : a do ( s := s + (i + 1)->pow(m - 2); r := r + ("" + ((x)))->toInteger() * MathLib.bitwiseNot(-s) + ("" + ((a[MathLib.bitwiseNot(i)+1])))->toInteger() * s; i := i + 1; f := f * i mod m) ; execute (r * f mod m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def power(a,b): if b==0 : return 1 elif b==1 : return a % 1000000007 elif b % 2==0 : return(power(a,b//2)**2)% 1000000007 else : return(power(a,b//2)**2*a)% 1000000007 def divide(a,b): return(a*power(b,1000000005))% 1000000007 N=int(input()) fac_lim=N fac=[None]*(fac_lim+1) fac[0]=1 for i in range(fac_lim): fac[i+1]=fac[i]*(i+1) fac[i+1]=fac[i+1]% 1000000007 fs=[0]*(N+1) fs[1]=fac[N] for i in range(1,N): fs[i+1]=fs[i]+divide(fs[1],i+1) fs[i+1]%=1000000007 A=[int(i)for i in input().split()] ans=0 for i in range(N): ans+=(fs[i+1]+fs[N-i]-fs[1])*A[i] ans %=1000000007 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var fac_lim : int := N ; var fac : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (fac_lim + 1)) ; fac->first() := 1 ; for i : Integer.subrange(0, fac_lim-1) do ( fac[i + 1+1] := fac[i+1] * (i + 1) ; fac[i + 1+1] := fac[i + 1+1] mod 1000000007) ; var fs : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; fs[1+1] := fac[N+1] ; for i : Integer.subrange(1, N-1) do ( fs[i + 1+1] := fs[i+1] + divide(fs[1+1], i + 1) ; fs[i + 1+1] := fs[i + 1+1] mod 1000000007) ; var A : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( ans := ans + (fs[i + 1+1] + fs[N - i+1] - fs[1+1]) * A[i+1] ; ans := ans mod 1000000007) ; execute (ans)->display(); operation power(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if b = 0 then ( return 1 ) else (if b = 1 then ( return a mod 1000000007 ) else (if b mod 2 = 0 then ( return ((power(a, b div 2))->pow(2)) mod 1000000007 ) else ( return ((power(a, b div 2))->pow(2) * a) mod 1000000007 ) ) ) ; operation divide(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a * power(b, 1000000005)) mod 1000000007; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) ret=0 mod=int(1e9)+7 def inv(x): return pow(x,mod-2,mod) inv_memo=[inv(i)for i in range(1,n+1)] cum=[0]*(n+1) for i in range(n): cum[i+1]=(cum[i]+inv_memo[i])% mod for i in range(n): ret+=(cum[n-i]+cum[i+1]-1)*a[i] ret %=mod for i in range(2,n+1): ret*=i ret %=mod print(ret) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ret : int := 0 ; var mod : int := ("" + ((("1e9")->toReal())))->toInteger() + 7 ; skip ; var inv_memo : Sequence := Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | (inv(i))) ; var cum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(0, n-1) do ( cum[i + 1+1] := (cum[i+1] + inv_memo[i+1]) mod mod) ; for i : Integer.subrange(0, n-1) do ( ret := ret + (cum[n - i+1] + cum[i + 1+1] - 1) * a[i+1] ; ret := ret mod mod) ; for i : Integer.subrange(2, n + 1-1) do ( ret := ret * i ; ret := ret mod mod) ; execute (ret)->display(); operation inv(x : OclAny) : OclAny pre: true post: true activity: return (x)->pow(mod - 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline import numpy as np MOD=10**9+7 N=int(input()) M=10**6 A=np.array(input().split(),dtype=np.int64) Nsq=10**3 fact=np.arange(M,dtype=np.int64).reshape(Nsq,Nsq) fact[0,0]=1 for n in range(1,Nsq): fact[:,n]*=fact[:,n-1]; fact[:,n]%=MOD for n in range(1,Nsq): fact[n]*=fact[n-1,-1]; fact[n]%=MOD fact=fact.ravel() j=np.arange(N) inv=np.array([pow(i+1,MOD-2,MOD)for i in range(N)]) inv=np.cumsum(inv)% MOD temp=inv[j]+inv[N-1-j]-1 ans=(A*temp % MOD).sum() ans %=MOD ans*=fact[N] ans %=MOD print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var MOD : double := (10)->pow(9) + 7 ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var M : double := (10)->pow(6) ; var A : Sequence := (input().split(), (argument (test (logical_test (comparison (expr (atom (name dtype)))))) = (test (logical_test (comparison (expr (atom (name np)) (trailer . (name int64)))))))) ; var Nsq : double := (10)->pow(3) ; var fact : OclAny := np.arange(M, (argument (test (logical_test (comparison (expr (atom (name dtype)))))) = (test (logical_test (comparison (expr (atom (name np)) (trailer . (name int64)))))))).reshape(Nsq, Nsq) ; fact->first()->first() := 1 ; for n : Integer.subrange(1, Nsq-1) do ( fact->collect( _r | _r[n+1] ) := fact->collect( _r | _r[n+1] ) * fact->collect( _r | _r[n - 1+1] ); fact->collect( _r | _r[n+1] ) := fact->collect( _r | _r[n+1] ) mod MOD) ; for n : Integer.subrange(1, Nsq-1) do ( fact[n+1] := fact[n+1] * fact[n - 1+1]->last(); fact[n+1] := fact[n+1] mod MOD) ; fact := fact.ravel() ; var j : Sequence := MathLib.numericRange(0, (N), 1) ; var inv : Sequence := (Integer.subrange(0, N-1)->select(i | true)->collect(i | ((i + 1)->pow(MOD - 2)))) ; inv := mod MOD ; var temp : double := inv->restrict(j) + inv[N - 1 - j+1] - 1 ; var ans : OclAny := (MatrixLib.elementwiseMult(A, temp) mod MOD).sum() ; ans := ans mod MOD ; ans := ans * fact[N+1] ; ans := ans mod MOD ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Queue : def __init__(self): self.items=[] def isEmpty(self): return self.items==[] def add(self,item): self.items.append(item) def pop(self): return self.items.pop(0) def front(self): return self.items[0] def printQueue(self): for i in self.items : print(i,end="") print("") def reverseQueue(q): if(q.isEmpty()): return data=q.front(); q.pop(); reverseQueue(q) q.add(data) q=Queue() q.add(56) q.add(27) q.add(30) q.add(45) q.add(85) q.add(92) q.add(58) q.add(80) q.add(90) q.add(100) reverseQueue(q) q.printQueue() ------------------------------------------------------------ OCL File: --------- class Queue { static operation newQueue() : Queue pre: true post: Queue->exists( _x | result = _x ); attribute items : Sequence := Sequence{}; operation initialise() : Queue pre: true post: true activity: self.items := Sequence{}; return self; operation isEmpty() : OclAny pre: true post: true activity: return self.items = Sequence{}; operation add(item : OclAny) pre: true post: true activity: (expr (atom (name self)) (trailer . (name items)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name item)))))))) )))); operation pop() : OclAny pre: true post: true activity: return self.items->at(0`firstArg+1); operation front() : OclAny pre: true post: true activity: return self->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}); operation printQueue() pre: true post: true activity: for i : self.items do ( execute (i)->display()) ; execute ("")->display(); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; q := (Queue.newQueue()).initialise() ; execute ((56) : q) ; execute ((27) : q) ; execute ((30) : q) ; execute ((45) : q) ; execute ((85) : q) ; execute ((92) : q) ; execute ((58) : q) ; execute ((80) : q) ; execute ((90) : q) ; execute ((100) : q) ; reverseQueue(q) ; q.printQueue(); operation reverseQueue(q : OclAny) pre: true post: true activity: if (q.isEmpty()) then ( return ) else skip ; var data : OclAny := q.front(); ; q := q->front(); ; reverseQueue(q) ; execute ((data) : q); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from queue import Queue def firstnonrepeating(Str): global MAX_CHAR q=Queue() charCount=[0]*MAX_CHAR for i in range(len(Str)): q.put(Str[i]) charCount[ord(Str[i])-ord('a')]+=1 while(not q.empty()): if(charCount[ord(q.queue[0])-ord('a')]>1): q.get() else : print(q.queue[0],end=" ") break if(q.empty()): print(-1,end=" ") print() MAX_CHAR=26 Str="aabc" firstnonrepeating(Str) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute MAX_CHAR : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; MAX_CHAR := 26 ; Str := "aabc" ; firstnonrepeating(Str); operation firstnonrepeating(Str : OclAny) pre: true post: true activity: skip ; var q : OclAny := Queue() ; var charCount : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX_CHAR) ; for i : Integer.subrange(0, (Str)->size()-1) do ( q.put(Str[i+1]) ; charCount[(Str[i+1])->char2byte() - ('a')->char2byte()+1] := charCount[(Str[i+1])->char2byte() - ('a')->char2byte()+1] + 1 ; while (not(q.empty())) do ( if (charCount[(q.queue->first())->char2byte() - ('a')->char2byte()+1] > 1) then ( q.get() ) else ( execute (q.queue->first())->display() ; break )) ; if (q.empty()) then ( execute (-1)->display() ) else skip) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000000 prime=[True]*(MAX+1) def SieveOfEratosthenes(): prime[1]=False p=2 c=0 while(p*p<=MAX): c+=1 if(prime[p]==True): for i in range(p*2,MAX+1,p): prime[i]=False p+=1 def findDiff(arr,n): min=MAX+2 max=-1 for i in range(n): if(prime[arr[i]]==True): if(arr[i]>max): max=arr[i] if(arr[i]union(Sequence{2}->union(Sequence{3}->union(Sequence{ 5 }))) ; var res : OclAny := findDiff(arr, n) ; if (res = -1) then ( execute ("No prime numbers")->display() ) else ( execute ("Difference is ")->display() ) ) else skip; operation SieveOfEratosthenes() pre: true post: true activity: prime[1+1] := false ; var p : int := 2 ; var c : int := 0 ; while ((p * p->compareTo(MAX)) <= 0) do ( c := c + 1 ; if (prime[p+1] = true) then ( for i : Integer.subrange(p * 2, MAX + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip ; p := p + 1); operation findDiff(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var min : int := MAX + 2 ; var max : int := -1 ; for i : Integer.subrange(0, n-1) do ( if (prime[arr[i+1]+1] = true) then ( if ((arr[i+1]->compareTo(max)) > 0) then ( max := arr[i+1] ) else skip ; if ((arr[i+1]->compareTo(min)) < 0) then ( min := arr[i+1] ) else skip ) else skip) ; return if (max = -1) then -1 else (max - min) endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find(x,par_lst): if par_lst[x]==x : return x root=find(par_lst[x],par_lst) par_lst[x]=root return root while True : n=int(input()) if not n : break m=int(input()) edges=[] for _ in range(m): a,b,d=map(int,input().split(",")) edges.append((d//100-1,a,b)) edges.sort() par_lst=[i for i in range(n)] ans=0 for d,a,b in edges : par_a=find(a,par_lst) par_b=find(b,par_lst) if par_a!=par_b : par_lst[par_a]=par_b ans+=d print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(n) then ( break ) else skip ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var edges : Sequence := Sequence{} ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; var d : OclAny := null; Sequence{a,b,d} := (input().split(","))->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{d div 100 - 1, a, b}) : edges)) ; edges := edges->sort() ; par_lst := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)) ; var ans : int := 0 ; for _tuple : edges do (var _indx : int := 1; var d : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); var par_a : OclAny := find(a, par_lst) ; var par_b : OclAny := find(b, par_lst) ; if par_a /= par_b then ( par_lst[par_a+1] := par_b ; ans := ans + d ) else skip) ; execute (ans)->display()); operation find(x : OclAny, par_lst : OclAny) : OclAny pre: true post: true activity: if par_lst[x+1] = x then ( return x ) else skip ; var root : OclAny := find(par_lst[x+1], par_lst) ; par_lst[x+1] := root ; return root; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(1000000000) iim=lambda : map(int,input().rstrip().split()) def resolve(): N,Q=iim() S=[i for i in range(N)] W=[0]*N R=[0]*N def find(x): if S[x]==x : return x i=find(S[x]) W[x]+=W[S[x]] S[x]=i return i def relate(x,y,w): i=find(x) j=find(y) if R[i]collect( _x | (OclType["int"])->apply(_x) )) ; skip ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); operation resolve() pre: true post: true activity: var N : OclAny := null; var Q : OclAny := null; Sequence{N,Q} := iim->apply() ; var S : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (i)) ; var W : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var R : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; skip ; skip ; skip ; var ans : Sequence := Sequence{} ; (compound_stmt for (exprlist (expr (atom (name com))) ,)) ; (testlist_star_expr (star_expr * (expr (atom (name xyz)))) in) ; var Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name s)) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin)))))))} : int ; if com = 0 then ( relate((argument * (test (logical_test (comparison (expr (atom (name xyz)))))))) ) else ( execute ((diff((argument * (test (logical_test (comparison (expr (atom (name xyz))))))))) : ans) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import array import collections import heapq AdjacentVertex=collections.namedtuple("AdjacentVertex","vertex cost") DIV=100 INF=2**31-1 def compute_mst_prim(max_v,adj_list): key=collections.defaultdict(lambda : INF) key[0]=0 pq=[(key[v],v)for v in range(max_v)] heapq.heapify(pq) in_pq=array.array("B",(True for _ in range(max_v))) while pq : _,u=heapq.heappop(pq) in_pq[u]=False for v,v_cost in adj_list[u]: if in_pq[v]: w=v_cost if w0) def main(): while True : n=int(input()) if n==0 : break m=int(input()) adj_list=collections.defaultdict(set) for _ in range(m): a,b,w=map(int,input().split(",")) adj_list[a].add((b,w//DIV)) adj_list[b].add((a,w//DIV)) print(compute_number_of_lanterns(n,adj_list)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var AdjacentVertex : OclAny := .namedtuple("AdjacentVertex", "vertex cost") ; var DIV : int := 100 ; var INF : double := (2)->pow(31) - 1 ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation compute_mst_prim(max_v : OclAny, adj_list : OclAny) : OclAny pre: true post: true activity: var key : OclAny := .defaultdict(lambda $$ : OclAny in (INF)) ; key->first() := 0 ; var pq : Sequence := Integer.subrange(0, max_v-1)->select(v | true)->collect(v | (Sequence{key[v+1], v})) ; heapq.heapify(pq) ; var in_pq : OclAny := array.array("B", Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name True)))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name max_v)))))))) ))))))))}) ; while pq do ( var _anon : OclAny := null; var u : OclAny := null; Sequence{_anon,u} := heapq.heappop(pq) ; in_pq[u+1] := false ; for _tuple : adj_list[u+1] do (var _indx : int := 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v_cost : OclAny := _tuple->at(_indx); if in_pq[v+1] then ( var w : OclAny := v_cost ; if (w->compareTo(key[v+1])) < 0 then ( key[v+1] := w ; heapq.heappush(pq, Sequence{w, v}) ; in_pq[v+1] := true ) else skip ) else skip)) ; return key; operation compute_number_of_lanterns(max_v : OclAny, adj_list : OclAny) : OclAny pre: true post: true activity: key := compute_mst_prim(max_v, adj_list) ; return ((argument (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name key)) (trailer . (name values) (arguments ( )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name x)))) > (comparison (expr (atom (number (integer 0))))))))))))->sum(); operation main() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; adj_list := .defaultdict(OclType["Set"]) ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b,w} := (input().split(","))->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name adj_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name b)))))) , (test (logical_test (comparison (expr (expr (atom (name w))) // (expr (atom (name DIV)))))))) )))))))) )))) ; (expr (atom (name adj_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (expr (atom (name w))) // (expr (atom (name DIV)))))))) )))))))) ))))) ; execute (compute_number_of_lanterns(n, adj_list))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=10**7 while 1 : n=int(input()) if n==0 : break m=int(input()) M=[[INF]*n for i in range(n)] for i in range(m): a,b,c=map(int,input().split(',')) M[a][b]=c M[b][a]=c d=[INF]*n used=[0]*n d[0]=0 while 1 : minv=INF for i in range(n): if(not used[i])and(d[i]M[u][i]: d[i]=M[u][i] print(int(sum(d)/100)-(n-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INF : double := (10)->pow(7) ; while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var M : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ INF }, n))) ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split(','))->collect( _x | (OclType["int"])->apply(_x) ) ; M[a+1][b+1] := c ; M[b+1][a+1] := c) ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, n) ; var used : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; d->first() := 0 ; while 1 do ( var minv : OclAny := INF ; for i : Integer.subrange(0, n-1) do ( if (not(used[i+1])) & ((d[i+1]->compareTo(minv)) < 0) then ( minv := d[i+1] ; var u : OclAny := i ) else skip) ; if minv = INF then ( break ) else skip ; used[u+1] := 1 ; for i : Integer.subrange(0, n-1) do ( if (not(used[i+1])) & M[u+1][i+1] /= INF & (d[i+1]->compareTo(M[u+1][i+1])) > 0 then ( d[i+1] := M[u+1][i+1] ) else skip)) ; execute (("" + (((d)->sum() / 100)))->toInteger() - (n - 1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class UnionSet : def __init__(self,nmax): self.size=[1]*nmax self.id=[i for i in range(nmax+1)] def root(self,i): while i!=self.id[i]: self.id[i]=self.id[self.id[i]] i=self.id[i] return i def connected(self,p,q): return self.root(p)==self.root(q) def unite(self,p,q): i,j=self.root(p),self.root(q) if i==j : return if self.size[i]exists( _x | result = _x ); attribute size : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, nmax); attribute id : Sequence := Integer.subrange(0, nmax + 1-1)->select(i | true)->collect(i | (i)); operation initialise(nmax : OclAny) : UnionSet pre: true post: true activity: self.size := MatrixLib.elementwiseMult(Sequence{ 1 }, nmax) ; self.id := Integer.subrange(0, nmax + 1-1)->select(i | true)->collect(i | (i)); return self; operation root(i : OclAny) : OclAny pre: true post: true activity: while i /= self.id[i+1] do ( self.id[i+1] := self.id[self.id[i+1]+1] ; i := self.id[i+1]) ; return i; operation connected(p : OclAny,q : OclAny) : OclAny pre: true post: true activity: return self.root(p) = self.root(q); operation unite(p : OclAny,q : OclAny) pre: true post: true activity: var j : OclAny := null; Sequence{i,j} := Sequence{self.root(p),self.root(q)} ; if i = j then ( return ) else skip ; if (self.size[i+1]->compareTo(self.size[j+1])) < 0 then ( self.id[i+1] := j ; self.size[j+1] := self.size[j+1] + self.size[i+1] ) else ( self.id[j+1] := i ; self.size[i+1] := self.size[i+1] + self.size[j+1] ); } class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var u : UnionSet := (UnionSet.newUnionSet()).initialise(n) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var tbl : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; var d : OclAny := null; Sequence{a,b,d} := (input().split(','))->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{d div 100 - 1, a, b}) : tbl)) ; tbl := tbl->sort() ; var ans : int := 0; ; for x : tbl do ( var d : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{d,a,b} := x ; if not(u.connected(a, b)) then ( u.unite(a, b) ; ans := ans + d ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Wood : def __init__(self,num,noods,edges): self.num=num self.noods=noods self.edges=edges def cons(self,other): self.noods.extend(other.noods) self.edges.extend(other.edges) class Edge : def __init__(self,n1,n2,length): self.n1=n1 self.n2=n2 self.length=length def check(woods,edge): if woods[edge.n1].num!=woods[edge.n2].num : woods[edge.n1].cons(woods[edge.n2]) woods[edge.n1].edges.append(edge) for i in woods[edge.n1].noods : woods[i]=woods[edge.n1] while True : n=int(input()) if n==0 : break m=int(input()) e=[] woods=[] for i in range(m): n1,n2,length=map(int,input().split(",")) edge=Edge(n1,n2,length) e.append(edge) e=sorted(e,key=lambda x : x.length) for i in range(n): wood=Wood(i,[i],[]) woods.append(wood) for edge in e : check(woods,edge) s=0 for edge in woods[0].edges : s+=edge.length//100-1 print(s) ------------------------------------------------------------ OCL File: --------- class Wood { static operation newWood() : Wood pre: true post: Wood->exists( _x | result = _x ); attribute num : OclAny := num; attribute noods : OclAny := noods; attribute edges : OclAny := edges; operation initialise(num : OclAny,noods : OclAny,edges : OclAny) : Wood pre: true post: true activity: self.num := num ; self.noods := noods ; self.edges := edges; return self; operation cons(other : OclAny) pre: true post: true activity: (expr (atom (name self)) (trailer . (name noods)) (trailer . (name extend) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name other)) (trailer . (name noods)))))))) )))) ; (expr (atom (name self)) (trailer . (name edges)) (trailer . (name extend) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name other)) (trailer . (name edges)))))))) )))); } class Edge { static operation newEdge() : Edge pre: true post: Edge->exists( _x | result = _x ); attribute n1 : OclAny := n1; attribute n2 : OclAny := n2; attribute length : OclAny := length; operation initialise(n1 : OclAny,n2 : OclAny,length : OclAny) : Edge pre: true post: true activity: self.n1 := n1 ; self.n2 := n2 ; self.length := length; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var e : Sequence := Sequence{} ; woods := Sequence{} ; for i : Integer.subrange(0, m-1) do ( Sequence{n1,n2,length} := (input().split(","))->collect( _x | (OclType["int"])->apply(_x) ) ; edge := (Edge.newEdge()).initialise(n1, n2, length) ; execute ((edge) : e)) ; e := e->sortedBy($x | (lambda x : OclAny in (x.length))->apply($x)) ; for i : Integer.subrange(0, n-1) do ( var wood : Wood := (Wood.newWood()).initialise(i, Sequence{ i }, Sequence{}) ; execute ((wood) : woods)) ; for edge : e do ( check(woods, edge)) ; var s : int := 0 ; for edge : woods->first().edges do ( s := s + edge.length div 100 - 1) ; execute (s)->display()); operation check(woods : OclAny, edge : OclAny) pre: true post: true activity: if woods[edge.n1+1].num /= woods[edge.n2+1].num then ( (expr (atom (name woods)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name edge)) (trailer . (name n1)))))))) ])) (trailer . (name cons) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name woods)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name edge)) (trailer . (name n2)))))))) ])))))))) )))) ; (expr (atom (name woods)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name edge)) (trailer . (name n1)))))))) ])) (trailer . (name edges)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name edge)))))))) )))) ; for i : woods[edge.n1+1].noods do ( woods[i+1] := woods[edge.n1+1]) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- li=[] ind=0 for i in range(1,371): temp=[] p,q=i,i count=0 while p!=0 : p//=10 count+=1 if count==1 : li.append(i) if count==2 : temp=[] while q!=0 : x=q % 10 q//=10 temp.append(x) li=li+temp[: :-1] if count==3 : temp=[] while q!=0 : x=q % 10 q//=10 temp.append(x) li=li+temp[: :-1] li.pop() li.pop() n=int(input('')) print(li[n-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var li : Sequence := Sequence{} ; var ind : int := 0 ; for i : Integer.subrange(1, 371-1) do ( var temp : Sequence := Sequence{} ; var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := Sequence{i,i} ; var count : int := 0 ; while p /= 0 do ( p := p div 10 ; count := count + 1) ; if count = 1 then ( execute ((i) : li) ) else skip ; if count = 2 then ( temp := Sequence{} ; while q /= 0 do ( var x : int := q mod 10 ; q := q div 10 ; execute ((x) : temp)) ; li := li->union(temp(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ) else skip ; if count = 3 then ( temp := Sequence{} ; while q /= 0 do ( x := q mod 10 ; q := q div 10 ; execute ((x) : temp)) ; li := li->union(temp(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ) else skip) ; li := li->front() ; li := li->front() ; var n : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; execute (li[n - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s='' for i in range(1,n+1): s+=str(i) print(s[n-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := '' ; for i : Integer.subrange(1, n + 1-1) do ( s := s + ("" + ((i)))) ; execute (s[n - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print("".join([str(x)for x in range(1001)])[int(input())]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ("".join(Integer.subrange(0, 1001-1)->select(x | true)->collect(x | (("" + ((x))))))[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s='' i=1 while len(s)<=n : s+=str(i) i+=1 print(s[n-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := '' ; var i : int := 1 ; while ((s)->size()->compareTo(n)) <= 0 do ( s := s + ("" + ((i))) ; i := i + 1) ; execute (s[n - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict n=int(input()) graph=defaultdict(list) for _ in range(n-1): i,j=[int(x)for x in input().split()] graph[i].append(j) graph[j].append(i) left=0 right=0 color=defaultdict(int) visited=set() def dfs(node): level=[node] if node not in color : color[node]=1 while level : node=level.pop() for val in graph[node]: if val not in visited : color[val]=1-color[node] visited.add(val) level.append(val) for i in range(1,n+1): if i not in visited : visited.add(i) dfs(i) for val in range(1,n+1): if color[val]==0 : left+=1 else : right+=1 print(left*right-n+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var graph : OclAny := defaultdict(OclType["Sequence"]) ; for _anon : Integer.subrange(0, n - 1-1) do ( var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var left : int := 0 ; var right : int := 0 ; var color : OclAny := defaultdict(OclType["int"]) ; var visited : Set := Set{}->union(()) ; skip ; for i : Integer.subrange(1, n + 1-1) do ( if (visited)->excludes(i) then ( execute ((i) : visited) ; dfs(i) ) else skip) ; for val : Integer.subrange(1, n + 1-1) do ( if color[val+1] = 0 then ( left := left + 1 ) else ( right := right + 1 )) ; execute (left * right - n + 1)->display(); operation dfs(node : OclAny) pre: true post: true activity: var level : Sequence := Sequence{ node } ; if (color)->excludes(node) then ( color[node+1] := 1 ) else skip ; while level do ( node := level->last() ; level := level->front() ; for val : graph[node+1] do ( if (visited)->excludes(val) then ( color[val+1] := 1 - color[node+1] ; execute ((val) : visited) ; execute ((val) : level) ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) res="".join([str(i)for i in range(1,n+1)])[n-1] print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : OclAny := "".join(Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | (("" + ((i))))))[n - 1+1] ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class WeightedUnionFind(): def __init__(self,n): self.n=n self.parents=[-1]*n self.differ=[0]*n def find(self,x): if self.parents[x]<0 : return x else : r=self.find(self.parents[x]) self.differ[x]+=self.differ[self.parents[x]] self.parents[x]=r return self.parents[x] def unite(self,x,y,w): xp=self.find(x) yp=self.find(y) w=w+self.differ[x]-self.differ[y] if xp!=yp : if self.parents[xp]>self.parents[yp]: xp,yp=yp,xp w=-w self.parents[xp]+=self.parents[yp] self.parents[yp]=xp self.differ[yp]=w def diff(self,x,y): xp=self.find(x) yp=self.find(y) if xp==yp : return True,self.differ[y]-self.differ[x] else : return False,0 n,q=map(int,input().split()) WUF=WeightedUnionFind(n) for i in range(q): query=list(map(int,input().split())) if query[0]==0 : WUF.unite(query[1],query[2],query[3]) elif query[0]==1 : judge,diff=WUF.diff(query[1],query[2]) if judge : print(diff) else : print("?") ------------------------------------------------------------ OCL File: --------- class WeightedUnionFind { static operation newWeightedUnionFind() : WeightedUnionFind pre: true post: WeightedUnionFind->exists( _x | result = _x ); attribute n : OclAny := n; attribute parents : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n); attribute differ : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); operation initialise(n : OclAny) : pre: true post: true activity: self.n := n ; self.parents := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; self.differ := MatrixLib.elementwiseMult(Sequence{ 0 }, n); return self; operation find(x : OclAny) : OclAny pre: true post: true activity: if self.parents[x+1] < 0 then ( return x ) else ( var r : int := self->indexOf(self.parents[x+1]) - 1 ; self.differ[x+1] := self.differ[x+1] + self.differ[self.parents[x+1]+1] ; self.parents[x+1] := r ; return self.parents[x+1] ); operation unite(x : OclAny,y : OclAny,w : OclAny) pre: true post: true activity: var xp : int := self->indexOf(x) - 1 ; var yp : int := self->indexOf(y) - 1 ; w := w + self.differ[x+1] - self.differ[y+1] ; if xp /= yp then ( if (self.parents[xp+1]->compareTo(self.parents[yp+1])) > 0 then ( Sequence{xp,yp} := Sequence{yp,xp} ; w := -w ) else skip ; self.parents[xp+1] := self.parents[xp+1] + self.parents[yp+1] ; self.parents[yp+1] := xp ; self.differ[yp+1] := w ) else skip; operation diff(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: xp := self->indexOf(x) - 1 ; yp := self->indexOf(y) - 1 ; if xp = yp then ( return true, self.differ[y+1] - self.differ[x+1] ) else ( return false, 0 ); } class FromPython { operation initialise() pre: true post: true activity: skip ; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var WUF : WeightedUnionFind := (WeightedUnionFind.newWeightedUnionFind()).initialise(n) ; for i : Integer.subrange(0, q-1) do ( var query : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if query->first() = 0 then ( WUF.unite(query[1+1], query[2+1], query[3+1]) ) else (if query->first() = 1 then ( var judge : OclAny := null; var diff : OclAny := null; Sequence{judge,diff} := WUF.diff(query[1+1], query[2+1]) ; if judge then ( execute (diff)->display() ) else ( execute ("?")->display() ) ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def distinctSubstring(P,N): S=dict() for i in range(N): freq=[False]*26 s="" for j in range(i,N): pos=ord(P[j])-ord('a') if(freq[pos]==True): break freq[pos]=True s+=P[j] S[s]=1 return len(S) S="abba" N=len(S) print(distinctSubstring(S,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; S := "abba" ; N := (S)->size() ; execute (distinctSubstring(S, N))->display(); operation distinctSubstring(P : OclAny, N : OclAny) : OclAny pre: true post: true activity: var S : Map := (arguments ( )) ; for i : Integer.subrange(0, N-1) do ( var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, 26) ; var s : String := "" ; for j : Integer.subrange(i, N-1) do ( var pos : double := (P[j+1])->char2byte() - ('a')->char2byte() ; if (freq[pos+1] = true) then ( break ) else skip ; freq[pos+1] := true ; s := s + P[j+1] ; S->at(s) := 1)) ; return (S)->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=list(map(int,input().split())) i=a.index(1) ans=-(-(n-k)//(k-1))+1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var i : int := a->indexOf(1) - 1 ; var ans : int := -(-(n - k) div (k - 1)) + 1 ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil N,K=map(int,input().split()) A=list(map(int,input().split())) p=0 for k in range(N): if A[k]==1 : p=k+1 break print(ceil((N-1)/(K-1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var p : int := 0 ; for k : Integer.subrange(0, N-1) do ( if A[k+1] = 1 then ( p := k + 1 ; break ) else skip) ; execute (ceil((N - 1) / (K - 1)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,k=map(int,input().split()) a=list(map(int,input().split())) print(math.ceil((n-k)/(k-1))+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (((n - k) / (k - 1))->ceil() + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil def main(): n,k=map(int,input().split()) a=list(map(int,input().split())) target=float("inf") target_index=[] for i in range(n): if a[i]collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var target : double := ("" + (("inf")))->toReal() ; var target_index : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if (a[i+1]->compareTo(target)) < 0 then ( target := a[i+1] ; execute ((i) : target_index) ) else skip) ; var answer : double := ("" + (("inf")))->toReal() ; for t : target_index do ( answer := Set{answer, ceil(t / (k - 1)) + ceil((n - t - 1) / (k - 1))}->min()) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def main(): N,K=map(int,input().split()) A=list(map(int,input().split())) if N<=K : ans=1 else : ans=1+((N-K)+K-2)//(K-1) print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (N->compareTo(K)) <= 0 then ( var ans : int := 1 ) else ( ans := 1 + ((N - K) + K - 2) div (K - 1) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys INT_MAX=sys.maxsize ; INT_MIN=-(sys.maxsize-1) def minimumAdjacentDifference(a,n,k): minDiff=INT_MAX ; for i in range(1<union(Sequence{7}->union(Sequence{8}->union(Sequence{10}->union(Sequence{ 14 })))); ; execute (minimumAdjacentDifference(a, n, k))->display(); ) else skip; operation minimumAdjacentDifference(a : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var minDiff : OclAny := INT_MAX; ; for i : Integer.subrange(0, 1 * (2->pow(n))-1) do ( var cnt : OclAny := bin(i)->count('1'); ; if (cnt = n - k) then ( var temp : Sequence := Sequence{}; ; for j : Integer.subrange(0, n-1) do ( if ((MathLib.bitwiseAnd(i, (1 * (2->pow(j))))) /= 0) then ( execute ((a[j+1]) : temp); ) else skip) ; var maxDiff : OclAny := INT_MIN; ; for j : Integer.subrange(0, (temp)->size() - 1-1) do ( maxDiff := Set{maxDiff, temp[j + 1+1] - temp[j+1]}->max();) ; minDiff := Set{minDiff, maxDiff}->min(); ) else skip) ; return minDiff;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def difference(arr,n): largest=arr[0]; i=0 ; for i in range(n): if(largestunion(Sequence{5}->union(Sequence{9}->union(Sequence{3}->union(Sequence{ 2 })))); ; n := (arr)->size(); ; difference(arr, n); ) else skip; operation difference(arr : OclAny, n : OclAny) pre: true post: true activity: var largest : OclAny := arr->first(); ; var i : int := 0; ; for i : Integer.subrange(0, n-1) do ( if ((largest->compareTo(arr[i+1])) < 0) then ( largest := arr[i+1]; ) else skip) ; for i : Integer.subrange(0, n-1) do ( arr[i+1] := largest - arr[i+1];) ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countKdivPairs(A,n,K): freq=[0]*K for i in range(n): freq[A[i]% K]+=1 sum=freq[0]*(freq[0]-1)/2 ; i=1 while(i<=K//2 and i!=(K-i)): sum+=freq[i]*freq[K-i] i+=1 if(K % 2==0): sum+=(freq[K//2]*(freq[K//2]-1)/2); return int(sum) A=[2,2,1,7,5,3] n=len(A) K=4 print(countKdivPairs(A,n,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; A := Sequence{2}->union(Sequence{2}->union(Sequence{1}->union(Sequence{7}->union(Sequence{5}->union(Sequence{ 3 }))))) ; n := (A)->size() ; K := 4 ; execute (countKdivPairs(A, n, K))->display(); operation countKdivPairs(A : OclAny, n : OclAny, K : OclAny) : OclAny pre: true post: true activity: var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, K) ; for i : Integer.subrange(0, n-1) do ( freq[A[i+1] mod K+1] := freq[A[i+1] mod K+1] + 1) ; var sum : double := freq->first() * (freq->first() - 1) / 2; ; var i : int := 1 ; while ((i->compareTo(K div 2)) <= 0 & i /= (K - i)) do ( sum := sum + freq[i+1] * freq[K - i+1] ; i := i + 1) ; if (K mod 2 = 0) then ( sum := sum + (freq[K div 2+1] * (freq[K div 2+1] - 1) / 2); ) else skip ; return ("" + ((sum)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import partial n=int(input()) nodes=tuple(set()for _ in range(n)) u=set() v=set() sets=(u,v) discovered=set() for _ in range(n-1): i,j=[int(i)-1 for i in input().split()] nodes[i].add(j) nodes[j].add(i) def discover(index : int,set_index : int)->bool : if index in discovered : return True sets[set_index].add(index) discovered.add(index) for node in nodes[index]: functions.append(partial(discover,node,1-set_index)) return False functions=[partial(discover,0,0)] while functions : results=[func()for func in functions] if all(results): break print(len(u)*len(v)-n+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nodes : Sequence := ((argument (test (logical_test (comparison (expr (atom (name set)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))) ; var u : Set := Set{}->union(()) ; var v : Set := Set{}->union(()) ; var sets : OclAny := Sequence{u, v} ; var discovered : Set := Set{}->union(()) ; for _anon : Integer.subrange(0, n - 1-1) do ( var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger() - 1)) ; (expr (atom (name nodes)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) ; (expr (atom (name nodes)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; skip ; var functions : Sequence := Sequence{ partial(discover, 0, 0) } ; while functions do ( var results : Sequence := functions->select(func | true)->collect(func | (func())) ; if (results)->forAll( _x | _x = true ) then ( break ) else skip) ; execute ((u)->size() * (v)->size() - n + 1)->display(); operation discover(index : int, set_index : int) : boolean pre: true post: true activity: if (discovered)->includes(index) then ( return true ) else skip ; (expr (atom (name sets)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name set_index)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name index)))))))) )))) ; execute ((index) : discovered) ; for node : nodes[index+1] do ( execute ((partial(discover, node, 1 - set_index)) : functions)) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSet(x): if x==parent[x]: return x else : temp=parent[x] parent[x]=findSet(parent[x]) weight[x]+=weight[temp] return parent[x] def link(x,y,z): a=findSet(x) b=findSet(y) if a!=b : parent[b]=a weight[b]=weight[x]-weight[y]+z n,q=list(map(int,input().split())) data=(i for i in range(n)) parent=[i for i in range(n)] weight=[0 for i in range(n)] for i in range(q): Ltemp=list(map(int,input().split())) if len(Ltemp)==4 : x,y,z=Ltemp[1 :] link(x,y,z) else : x,y=Ltemp[1 :] if findSet(x)==findSet(y): print(weight[y]-weight[x]) else : print('?') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var data : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))} ; var parent : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)) ; var weight : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, q-1) do ( var Ltemp : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (Ltemp)->size() = 4 then ( Sequence{x,y,z} := Ltemp->tail() ; link(x, y, z) ) else ( Sequence{x,y} := Ltemp->tail() ; if findSet(x) = findSet(y) then ( execute (weight[y+1] - weight[x+1])->display() ) else ( execute ('?')->display() ) )); operation findSet(x : OclAny) : OclAny pre: true post: true activity: if x = parent[x+1] then ( return x ) else ( var temp : OclAny := parent[x+1] ; parent[x+1] := findSet(parent[x+1]) ; weight[x+1] := weight[x+1] + weight[temp+1] ; return parent[x+1] ); operation link(x : OclAny, y : OclAny, z : OclAny) pre: true post: true activity: var a : OclAny := findSet(x) ; var b : OclAny := findSet(y) ; if a /= b then ( parent[b+1] := a ; weight[b+1] := weight[x+1] - weight[y+1] + z ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(a): for x in['b','w']: if a[0 : : 4].count(x)==3 or a[2 : 7 : 2].count(x)==3 : return x for i in range(3): if a[i*3 : i*3+3].count(x)==3 or a[i : : 3].count(x)==3 : return x return 'NA' while 1 : a=list(input()) if len(a)==1 : break a+=list(input())+list(input()) print(f(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while 1 do ( a := ((OclFile["System.in"]).readLine())->characters() ; if (a)->size() = 1 then ( break ) else skip ; a := a + ((OclFile["System.in"]).readLine())->characters()->union(((OclFile["System.in"]).readLine())->characters()) ; execute (f(a))->display()); operation f(a : OclAny) : OclAny pre: true post: true activity: for x : Sequence{'b'}->union(Sequence{ 'w' }) do ( if a(subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 4)))))))))->count(x) = 3 or a(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (test (logical_test (comparison (expr (atom (number (integer 7))))))) (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->count(x) = 3 then ( return x ) else skip ; for i : Integer.subrange(0, 3-1) do ( if a.subrange(i * 3+1, i * 3 + 3)->count(x) = 3 or a(subscript (test (logical_test (comparison (expr (atom (name i)))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 3)))))))))->count(x) = 3 then ( return x ) else skip)) ; return 'NA'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : input_data1=input() if input_data1=="0" : break input_data2=input() input_data3=input() output="NA" if input_data1[0]!="+" and input_data1[0]==input_data1[1]==input_data1[2]: output=input_data1[0] elif input_data2[0]!="+" and input_data2[0]==input_data2[1]==input_data2[2]: output=input_data2[0] elif input_data3[0]!="+" and input_data3[0]==input_data3[1]==input_data3[2]: output=input_data3[0] elif input_data1[0]!="+" and input_data1[0]==input_data2[0]==input_data3[0]: output=input_data1[0] elif input_data1[1]!="+" and input_data1[1]==input_data2[1]==input_data3[1]: output=input_data1[1] elif input_data1[2]!="+" and input_data1[2]==input_data2[2]==input_data3[2]: output=input_data1[2] elif input_data1[0]!="+" and input_data1[0]==input_data2[1]==input_data3[2]: output=input_data1[0] elif input_data1[2]!="+" and input_data1[2]==input_data2[1]==input_data3[0]: output=input_data1[2] print(output) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var input_data1 : String := (OclFile["System.in"]).readLine() ; if input_data1 = "0" then ( break ) else skip ; var input_data2 : String := (OclFile["System.in"]).readLine() ; var input_data3 : String := (OclFile["System.in"]).readLine() ; var output : String := "NA" ; if input_data1->first() /= "+" & input_data1->first() = input_data1[1+1] & (input_data1[1+1] == input_data1[2+1]) then ( output := input_data1->first() ) else (if input_data2->first() /= "+" & input_data2->first() = input_data2[1+1] & (input_data2[1+1] == input_data2[2+1]) then ( output := input_data2->first() ) else (if input_data3->first() /= "+" & input_data3->first() = input_data3[1+1] & (input_data3[1+1] == input_data3[2+1]) then ( output := input_data3->first() ) else (if input_data1->first() /= "+" & input_data1->first() = input_data2->first() & (input_data2->first() == input_data3->first()) then ( output := input_data1->first() ) else (if input_data1[1+1] /= "+" & input_data1[1+1] = input_data2[1+1] & (input_data2[1+1] == input_data3[1+1]) then ( output := input_data1[1+1] ) else (if input_data1[2+1] /= "+" & input_data1[2+1] = input_data2[2+1] & (input_data2[2+1] == input_data3[2+1]) then ( output := input_data1[2+1] ) else (if input_data1->first() /= "+" & input_data1->first() = input_data2[1+1] & (input_data2[1+1] == input_data3[2+1]) then ( output := input_data1->first() ) else (if input_data1[2+1] /= "+" & input_data1[2+1] = input_data2[1+1] & (input_data2[1+1] == input_data3->first()) then ( output := input_data1[2+1] ) else skip ) ) ) ) ) ) ) ; execute (output)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def solve(board): colors=['b','w'] for c in colors : for y in range(3): if board[y].count(c)==3 : return c for x in range(3): if board[0][x]==c and board[1][x]==c and board[2][x]==c : return c if board[0][0]==c and board[1][1]==c and board[2][2]==c : return c if board[0][2]==c and board[1][1]==c and board[2][0]==c : return c return 'NA' def main(args): while True : temp=input().strip() if temp[0]=='0' : break board=[] board.append(list(temp)) board.append(list(input().strip())) board.append(list(input().strip())) result=solve(board) print(result) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(board : OclAny) : OclAny pre: true post: true activity: var colors : Sequence := Sequence{'b'}->union(Sequence{ 'w' }) ; for c : colors do ( for y : Integer.subrange(0, 3-1) do ( if board[y+1]->count(c) = 3 then ( return c ) else skip) ; for x : Integer.subrange(0, 3-1) do ( if board->first()[x+1] = c & board[1+1][x+1] = c & board[2+1][x+1] = c then ( return c ) else skip) ; if board->first()->first() = c & board[1+1][1+1] = c & board[2+1][2+1] = c then ( return c ) else skip ; if board->first()[2+1] = c & board[1+1][1+1] = c & board[2+1]->first() = c then ( return c ) else skip) ; return 'NA'; operation main(args : OclAny) pre: true post: true activity: while true do ( var temp : OclAny := input()->trim() ; if temp->first() = '0' then ( break ) else skip ; board := Sequence{} ; execute (((temp)) : board) ; execute (((input()->trim())) : board) ; execute (((input()->trim())) : board) ; var result : OclAny := solve(board) ; execute (result)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f1(c,l): for i in range(3): if c*3==l[i]: return 1 return 0 def f2(c,l): for i in range(0,7,3): s=set(h[i : i+3]) if c in s and len(s)==1 : return 1 return 0 def f3(c,l): if c*3==l[0]+l[4]+l[8]: return 1 if c*3==l[2]+l[4]+l[6]: return 1 return 0 while True : try : w=[input()for _ in range(3)] except : break if f1('b',w): print('b') continue if f1('w',w): print('w') continue h=[w[j][i]for i in range(3)for j in range(3)] if f2('b',h): print('b') continue if f2('w',h): print('w') continue if f3('b',h): print('b') continue if f3('w',h): print('w') continue print("NA") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; while true do ( try ( var w : Sequence := Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine()))) catch (_e : OclException) do ( break) ; if f1('b', w) then ( execute ('b')->display() ; continue ) else skip ; if f1('w', w) then ( execute ('w')->display() ; continue ) else skip ; var h : Sequence := Integer.subrange(0, 3-1)->select(i; j : Integer.subrange(0, 3-1) | true)->collect(i; j : Integer.subrange(0, 3-1) | (w[j+1][i+1])) ; if f2('b', h) then ( execute ('b')->display() ; continue ) else skip ; if f2('w', h) then ( execute ('w')->display() ; continue ) else skip ; if f3('b', h) then ( execute ('b')->display() ; continue ) else skip ; if f3('w', h) then ( execute ('w')->display() ; continue ) else skip ; execute ("NA")->display()); operation f1(c : OclAny, l : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, 3-1) do ( if c * 3 = l[i+1] then ( return 1 ) else skip) ; return 0; operation f2(c : OclAny, l : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, 7-1)->select( $x | ($x - 0) mod 3 = 0 ) do ( var s : Set := Set{}->union((h.subrange(i+1, i + 3))) ; if (s)->includes(c) & (s)->size() = 1 then ( return 1 ) else skip) ; return 0; operation f3(c : OclAny, l : OclAny) : OclAny pre: true post: true activity: if c * 3 = l->first() + l[4+1] + l[8+1] then ( return 1 ) else skip ; if c * 3 = l[2+1] + l[4+1] + l[6+1] then ( return 1 ) else skip ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy from test.support import _MemoryWatchdog BIG_NUM=2000000000 HUGE_NUM=99999999999999999 MOD=1000000007 EPS=0.000000001 sys.setrecursionlimit(100000) table=[[]for row in range(3)] def check(mark): global table for row in range(3): count=0 ; for col in range(3): if table[row][col]==mark : count+=1 if count==3 : return True for col in range(3): count=0 for row in range(3): if table[row][col]==mark : count+=1 if count==3 : return True if table[1][1]==mark and((table[0][0]==mark and table[2][2]==mark)or(table[0][2]==mark and table[2][0]==mark)): return True else : return False while True : input_str=input() if input_str[0]=="0" : break table[0]=input_str for row in range(1,3): table[row]=input() black=check("b") white=check("w") if black==True : print("b") elif white==True : print("w") else : print("NA") ------------------------------------------------------------ OCL File: --------- class FromPython { attribute table : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var HUGE_NUM : int := 99999999999999999 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; sys.setrecursionlimit(100000) ; var table : Sequence := Integer.subrange(0, 3-1)->select(row | true)->collect(row | (Sequence{})) ; skip ; while true do ( var input_str : String := (OclFile["System.in"]).readLine() ; if input_str->first() = "0" then ( break ) else skip ; table->first() := input_str ; for row : Integer.subrange(1, 3-1) do ( table[row+1] := (OclFile["System.in"]).readLine()) ; var black : OclAny := check("b") ; var white : OclAny := check("w") ; if black = true then ( execute ("b")->display() ) else (if white = true then ( execute ("w")->display() ) else ( execute ("NA")->display() ) ) ); operation check(mark : OclAny) : OclAny pre: true post: true activity: skip ; for row : Integer.subrange(0, 3-1) do ( var count : int := 0; ; for col : Integer.subrange(0, 3-1) do ( if table[row+1][col+1] = mark then ( count := count + 1 ) else skip) ; if count = 3 then ( return true ) else skip) ; for col : Integer.subrange(0, 3-1) do ( count := 0 ; for row : Integer.subrange(0, 3-1) do ( if table[row+1][col+1] = mark then ( count := count + 1 ) else skip) ; if count = 3 then ( return true ) else skip) ; if table[1+1][1+1] = mark & ((table->first()->first() = mark & table[2+1][2+1] = mark) or (table->first()[2+1] = mark & table[2+1]->first() = mark)) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxOnesIndex(arr,n): max_count=0 max_index=0 prev_zero=-1 prev_prev_zero=-1 for curr in range(n): if(arr[curr]==0): if(curr-prev_prev_zero>max_count): max_count=curr-prev_prev_zero max_index=prev_zero prev_prev_zero=prev_zero prev_zero=curr if(n-prev_prev_zero>max_count): max_index=prev_zero return max_index arr=[1,1,0,0,1,0,1,1,1,0,1,1,1] n=len(arr) print("Index of 0 to be replaced is ",maxOnesIndex(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })))))))))))) ; n := (arr)->size() ; execute ("Index of 0 to be replaced is ")->display(); operation maxOnesIndex(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var max_count : int := 0 ; var max_index : int := 0 ; var prev_zero : int := -1 ; var prev_prev_zero : int := -1 ; for curr : Integer.subrange(0, n-1) do ( if (arr[curr+1] = 0) then ( if ((curr - prev_prev_zero->compareTo(max_count)) > 0) then ( max_count := curr - prev_prev_zero ; max_index := prev_zero ) else skip ; prev_prev_zero := prev_zero ; prev_zero := curr ) else skip) ; if ((n - prev_prev_zero->compareTo(max_count)) > 0) then ( max_index := prev_zero ) else skip ; return max_index; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minimumX(n,k): ans=10**18 for i in range(k-1,0,-1): if n % i==0 : ans=min(ans,i+(n/i)*k) return ans n,k=4,6 print(minimumX(n,k)) n,k=5,5 print(minimumX(n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{n,k} := Sequence{4,6} ; execute (minimumX(n, k))->display() ; Sequence{n,k} := Sequence{5,5} ; execute (minimumX(n, k))->display(); operation minimumX(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var ans : double := (10)->pow(18) ; for i : Integer.subrange(0 + 1, k - 1)->reverse() do ( if n mod i = 0 then ( ans := Set{ans, i + (n / i) * k}->min() ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def resolve(): n=int(input()) low=[] high=[] for i in range(n): a,b=map(int,input().split()) low.append(a) high.append(b) low.sort() high.sort() if n % 2 : print(high[(n+1)//2-1]-low[(n+1)//2-1]+1) else : hh=(high[(n)//2-1]+high[(n)//2])/2 ll=(low[(n)//2-1]+low[(n)//2])/2 print(int((hh-ll)*2)+1) if __name__=="__main__" : resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( resolve() ) else skip; operation resolve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var low : Sequence := Sequence{} ; var high : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a) : low) ; execute ((b) : high)) ; low := low->sort() ; high := high->sort() ; if n mod 2 then ( execute (high[(n + 1) div 2 - 1+1] - low[(n + 1) div 2 - 1+1] + 1)->display() ) else ( var hh : double := (high[(n) div 2 - 1+1] + high[(n) div 2+1]) / 2 ; var ll : double := (low[(n) div 2 - 1+1] + low[(n) div 2+1]) / 2 ; execute (("" + (((hh - ll) * 2)))->toInteger() + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np LI=lambda : list(map(int,input().split())) N=int(input()) A,B=[None]*N,[None]*N for i in range(N): A[i],B[i]=LI() def main(): a,b=np.array(A,dtype=int),np.array(B,dtype=int) a.sort() b.sort() i=N//2 if N % 2==0 : a*=2 b*=2 l=(a[i-1]+a[i])//2 r=(b[i-1]+b[i])//2 ans=r-l+1 else : ans=b[i]-a[i]+1 print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var LI : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := Sequence{MatrixLib.elementwiseMult(Sequence{ null }, N),MatrixLib.elementwiseMult(Sequence{ null }, N)} ; for i : Integer.subrange(0, N-1) do ( var A[i+1] : OclAny := null; var B[i+1] : OclAny := null; Sequence{A[i+1],B[i+1]} := LI->apply()) ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{(A, (argument (test (logical_test (comparison (expr (atom (name dtype)))))) = (test (logical_test (comparison (expr (atom (name int)))))))),(B, (argument (test (logical_test (comparison (expr (atom (name dtype)))))) = (test (logical_test (comparison (expr (atom (name int))))))))} ; a := a->sort() ; b := b->sort() ; var i : int := N div 2 ; if N mod 2 = 0 then ( a := a * 2 ; b := b * 2 ; var l : int := (a[i - 1+1] + a[i+1]) div 2 ; var r : int := (b[i - 1+1] + b[i+1]) div 2 ; var ans : double := r - l + 1 ) else ( ans := b[i+1] - a[i+1] + 1 ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq as hp n=int(input()) if n % 2==0 : m=n//2+1 else : m=(n+1)//2 a,b=[],[] for i in range(0,n): c=list(map(int,input().split())) a.append(c[0]) b.append(c[1]) la=hp.nlargest(m,a) lb=hp.nlargest(m,b) if n % 2==0 : c=la[-1]+la[-2] d=lb[-1]+lb[-2] print(d-c+1) else : print(lb[-1]-la[-1]+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( var m : int := n div 2 + 1 ) else ( m := (n + 1) div 2 ) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{Sequence{},Sequence{}} ; for i : Integer.subrange(0, n-1) do ( var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((c->first()) : a) ; execute ((c[1+1]) : b)) ; var la : OclAny := hp.nlargest(m, a) ; var lb : OclAny := hp.nlargest(m, b) ; if n mod 2 = 0 then ( c := la->last() + la->front()->last() ; var d : OclAny := lb->last() + lb->front()->last() ; execute (d - c + 1)->display() ) else ( execute (lb->last() - la->last() + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def union(x,y,t): x,t_x=findSet(x) y,t_y=findSet(y) link(x,t_x,y,t_y,t) def link(x,d_x,y,d_y,t): if r[x]>r[y]: p[y]=x d[y]=d_x-d_y-t else : p[x]=y d[x]=d_y-d_x+t if r[x]==r[y]: r[y]=r[y]+1 def findSet(x): if x!=p[x]: p[x],t=findSet(p[x]) d[x]+=t return p[x],d[x] def diff(x,y): x,d_x=findSet(x) y,d_y=findSet(y) if x==y : return d_x-d_y else : return '?' if __name__=='__main__' : p,r,d=[],[],[] n_set,n_quare=map(int,input().split()) for i in range(n_set): p.append(i) r.append(0) d.append(0) for i in range(n_quare): l=input().split() if len(l)==4 : _,x,y,t=map(int,l) union(x,y,t) else : _,x,y=map(int,l) print(diff(x,y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var p : OclAny := null; var r : OclAny := null; var d : OclAny := null; Sequence{p,r,d} := Sequence{Sequence{},Sequence{},Sequence{}} ; var n_set : OclAny := null; var n_quare : OclAny := null; Sequence{n_set,n_quare} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, n_set-1) do ( execute ((i) : p) ; execute ((0) : r) ; execute ((0) : d)) ; for i : Integer.subrange(0, n_quare-1) do ( var l : OclAny := input().split() ; if (l)->size() = 4 then ( var _anon : OclAny := null; Sequence{_anon,x,y,t} := (l)->collect( _x | (OclType["int"])->apply(_x) ) ; union(x, y, t) ) else ( var _anon : OclAny := null; Sequence{_anon,x,y} := (l)->collect( _x | (OclType["int"])->apply(_x) ) ; execute (diff(x, y))->display() )) ) else skip; operation union(x : OclAny, y : OclAny, t : OclAny) pre: true post: true activity: var t_x : OclAny := null; Sequence{x,t_x} := findSet(x) ; var t_y : OclAny := null; Sequence{y,t_y} := findSet(y) ; link(x, t_x, y, t_y, t); operation link(x : OclAny, d_x : OclAny, y : OclAny, d_y : OclAny, t : OclAny) pre: true post: true activity: if (r[x+1]->compareTo(r[y+1])) > 0 then ( p[y+1] := x ; d[y+1] := d_x - d_y - t ) else ( p[x+1] := y ; d[x+1] := d_y - d_x + t ; if r[x+1] = r[y+1] then ( r[y+1] := r[y+1] + 1 ) else skip ); operation findSet(x : OclAny) : OclAny pre: true post: true activity: if x /= p[x+1] then ( var p[x+1] : OclAny := null; Sequence{p[x+1],t} := findSet(p[x+1]) ; d[x+1] := d[x+1] + t ) else skip ; return p[x+1], d[x+1]; operation diff(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: Sequence{x,d_x} := findSet(x) ; Sequence{y,d_y} := findSet(y) ; if x = y then ( return d_x - d_y ) else ( return '?' ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s1,s2=0,0 color=[0 for i in range(n)] edge=[[]for i in range(n)] a=[0 for i in range(n)] for i in range(n-1): u,v=map(int,input().split()) edge[u-1].append(v-1) edge[v-1].append(u-1) qu=[0] while len(qu)>0 : node=qu.pop(0) color[node]=1 for i in edge[node]: if color[i]!=1 : a[i]=1-a[node] qu.append(i) for i in range(n): if a[i]==0 : s1+=1 else : s2+=1 print(s1*s2-n+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s1 : OclAny := null; var s2 : OclAny := null; Sequence{s1,s2} := Sequence{0,0} ; var color : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var edge : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n - 1-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name u))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name u))) - (expr (atom (number (integer 1)))))))))) ))))) ; var qu : Sequence := Sequence{ 0 } ; while (qu)->size() > 0 do ( var node : OclAny := qu->at(0`firstArg+1) ; qu := qu->excludingAt(0+1) ; color[node+1] := 1 ; for i : edge[node+1] do ( if color[i+1] /= 1 then ( a[i+1] := 1 - a[node+1] ; execute ((i) : qu) ) else skip)) ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = 0 then ( s1 := s1 + 1 ) else ( s2 := s2 + 1 )) ; execute (s1 * s2 - n + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,*ABf=map(int,open(0).read().split()) AB=[ABf[i : i+2]for i in range(0,len(ABf),2)] A=sorted([x[0]for x in AB]) B=sorted([x[1]for x in AB]) if N % 2==1 : print(B[N//2]-A[N//2]+1) else : print(int(((B[N//2-1]+B[N//2])*(0.5)-(A[N//2-1]+A[N//2])*(0.5))*2+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var ABf : OclAny := null; Sequence{N,ABf} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var AB : Sequence := Integer.subrange(0, (ABf)->size()-1)->select( $x | ($x - 0) mod 2 = 0 )->select(i | true)->collect(i | (ABf.subrange(i+1, i + 2))) ; var A : Sequence := AB->select(x | true)->collect(x | (x->first()))->sort() ; var B : Sequence := AB->select(x | true)->collect(x | (x[1+1]))->sort() ; if N mod 2 = 1 then ( execute (B[N div 2+1] - A[N div 2+1] + 1)->display() ) else ( execute (("" + ((((B[N div 2 - 1+1] + B[N div 2+1]) * (0.5) - (A[N div 2 - 1+1] + A[N div 2+1]) * (0.5)) * 2 + 1)))->toInteger())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from heapq import heappush,heappop def input(): return sys.stdin.readline().strip() def main(): N=int(input()) lower=[] upper=[] for i in range(N): a,b=map(int,input().split()) heappush(lower,(a,i)) heappush(upper,(-b,i)) if N % 2!=0 : for _ in range(N//2): a,i=heappop(lower) a,_=heappop(lower) for _ in range(N//2): b,i=heappop(upper) b,_=heappop(upper) print(-b-a+1) else : for _ in range(N//2-1): a,i=heappop(lower) a0,i0=heappop(lower) a1,i1=heappop(lower) for _ in range(N//2-1): b,i=heappop(upper) b0,i0=heappop(upper) b1,i1=heappop(upper) print((-b1-b0)-(a1+a0)+1) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lower : Sequence := Sequence{} ; var upper : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; heappush(lower, Sequence{a, i}) ; heappush(upper, Sequence{-b, i})) ; if N mod 2 /= 0 then ( for _anon : Integer.subrange(0, N div 2-1) do ( var a : OclAny := null; var i : OclAny := null; Sequence{a,i} := heappop(lower)) ; var a : OclAny := null; var _anon : OclAny := null; Sequence{a,_anon} := heappop(lower) ; for _anon : Integer.subrange(0, N div 2-1) do ( var b : OclAny := null; var i : OclAny := null; Sequence{b,i} := heappop(upper)) ; var b : OclAny := null; var _anon : OclAny := null; Sequence{b,_anon} := heappop(upper) ; execute (-b - a + 1)->display() ) else ( for _anon : Integer.subrange(0, N div 2 - 1-1) do ( var a : OclAny := null; var i : OclAny := null; Sequence{a,i} := heappop(lower)) ; var a0 : OclAny := null; var i0 : OclAny := null; Sequence{a0,i0} := heappop(lower) ; var a1 : OclAny := null; var i1 : OclAny := null; Sequence{a1,i1} := heappop(lower) ; for _anon : Integer.subrange(0, N div 2 - 1-1) do ( var b : OclAny := null; var i : OclAny := null; Sequence{b,i} := heappop(upper)) ; var b0 : OclAny := null; var i0 : OclAny := null; Sequence{b0,i0} := heappop(upper) ; var b1 : OclAny := null; var i1 : OclAny := null; Sequence{b1,i1} := heappop(upper) ; execute ((-b1 - b0) - (a1 + a0) + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def moduloMultiplication(a,b,mod): res=0 ; a=a % mod ; while(b): if(b & 1): res=(res+a)% mod ; a=(2*a)% mod ; b>>=1 ; return res ; a=10123465234878998 ; b=65746311545646431 ; m=10005412336548794 ; print(moduloMultiplication(a,b,m)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 10123465234878998; ; b := 65746311545646431; ; var m : int := 10005412336548794; ; execute (moduloMultiplication(a, b, m))->display();; operation moduloMultiplication(a : OclAny, b : OclAny, mod : OclAny) pre: true post: true activity: var res : int := 0; ; a := a mod mod; ; while (b) do ( if (MathLib.bitwiseAnd(b, 1)) then ( res := (res + a) mod mod; ) else skip ; a := (2 * a) mod mod; ; b := b div (2->pow(1));) ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def searchnode(i,u,path): r=1 u[i]=1 for j in range(26): if path[i][j]and(not u[j]): r+=searchnode(j,u,path) return r while(True): n=int(input()) if not n : break strs=list(map(lambda x :[x[0],x[-1]],[input()for i in range(n)])) ss,ee=[0]*26,[0]*26 path=[[0]*26 for _ in range(27)] u=[0]*26 for s,e in strs : ss[ord(s)-ord('a')]+=1 ee[ord(e)-ord('a')]+=1 path[ord(s)-ord('a')][ord(e)-ord('a')]+=1 if[1 for s1,e1 in zip(ss,ee)if s1-e1]: print("NG") continue print("OK" if len([1 for s in ss if s])==searchnode(ord(s)-ord('a'),u,path)else "NG") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while (true) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(n) then ( break ) else skip ; var strs : Sequence := ((Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())))->collect( _x | (lambda x : OclAny in (Sequence{x->first()}->union(Sequence{ x->last() })))->apply(_x) )) ; var ss : OclAny := null; var ee : OclAny := null; Sequence{ss,ee} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, 26),MatrixLib.elementwiseMult(Sequence{ 0 }, 26)} ; path := Integer.subrange(0, 27-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 26))) ; u := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for _tuple : strs do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var e : OclAny := _tuple->at(_indx); ss[(s)->char2byte() - ('a')->char2byte()+1] := ss[(s)->char2byte() - ('a')->char2byte()+1] + 1 ; ee[(e)->char2byte() - ('a')->char2byte()+1] := ee[(e)->char2byte() - ('a')->char2byte()+1] + 1 ; path[(s)->char2byte() - ('a')->char2byte()+1][(e)->char2byte() - ('a')->char2byte()+1] := path[(s)->char2byte() - ('a')->char2byte()+1][(e)->char2byte() - ('a')->char2byte()+1] + 1) ; if Integer.subrange(1, ss->size())->collect( _indx | Sequence{ss->at(_indx), ee->at(_indx)} )->select(_tuple | let s1 : OclAny = _tuple->at(1) in let e1 : OclAny = _tuple->at(2) in s1 - e1)->collect(_tuple | let s1 : OclAny = _tuple->at(1) in let e1 : OclAny = _tuple->at(2) in (1)) then ( execute ("NG")->display() ; continue ) else skip ; execute (if (ss->select(s | s)->collect(s | (1)))->size() = searchnode((s)->char2byte() - ('a')->char2byte(), u, path) then "OK" else "NG" endif)->display()); operation searchnode(i : OclAny, u : OclAny, path : OclAny) : OclAny pre: true post: true activity: var r : int := 1 ; u[i+1] := 1 ; for j : Integer.subrange(0, 26-1) do ( if path[i+1][j+1] & (not(u[j+1])) then ( r := r + searchnode(j, u, path) ) else skip) ; return r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys f=sys.stdin from collections import defaultdict from collections import Counter while True : n=int(f.readline()) if n==0 : break words=[f.readline().strip()for _ in range(n)] words=[(ord(wi[0])-ord('a'),ord(wi[-1])-ord('a'))for wi in words] pre=Counter(w[0]for w in words) post=Counter(w[-1]for w in words) if pre!=post : print('NG') continue path=[[0 for j in range(26)]for i in range(26)] for s,e in words : path[s][e]=1 for k in range(26): for i in range(26): for j in range(26): if path[i][k]and path[k][j]: path[i][j]=1 s=words[0][0] flg=True for k in pre.keys(): if not path[s][k]: flg=False break print('OK' if flg else 'NG') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var f : OclFile := OclFile["System.in"] ; skip ; skip ; while true do ( var n : int := ("" + ((f.readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var words : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (f.readLine()->trim())) ; words := words->select(wi | true)->collect(wi | (Sequence{(wi->first())->char2byte() - ('a')->char2byte(), (wi->last())->char2byte() - ('a')->char2byte()})) ; var pre : OclAny := Counter((argument (test (logical_test (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))) (comp_for for (exprlist (expr (atom (name w)))) in (logical_test (comparison (expr (atom (name words)))))))) ; var post : OclAny := Counter((argument (test (logical_test (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))) (comp_for for (exprlist (expr (atom (name w)))) in (logical_test (comparison (expr (atom (name words)))))))) ; if pre /= post then ( execute ('NG')->display() ; continue ) else skip ; var path : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | (Integer.subrange(0, 26-1)->select(j | true)->collect(j | (0)))) ; for _tuple : words do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var e : OclAny := _tuple->at(_indx); path[s+1][e+1] := 1) ; for k : Integer.subrange(0, 26-1) do ( for i : Integer.subrange(0, 26-1) do ( for j : Integer.subrange(0, 26-1) do ( if path[i+1][k+1] & path[k+1][j+1] then ( path[i+1][j+1] := 1 ) else skip))) ; var s : OclAny := words->first()->first() ; var flg : boolean := true ; for k : pre.keys() do ( if not(path[s+1][k+1]) then ( flg := false ; break ) else skip) ; execute (if flg then 'OK' else 'NG' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque while True : n=int(input()) if n==0 : break ins={} outs={} node=set() base=ord("a") edges=[[0]*26 for _ in range(26)] for i in range(26): ins[i]=0 outs[i]=0 for _ in range(n): s=input() fr=ord(s[0])-base to=ord(s[-1])-base ins[to]+=1 outs[fr]+=1 edges[fr][to]=1 node.add(fr) node.add(to) for i in range(26): if ins[i]!=outs[i]: print("NG") break else : node=sorted(list(node)) visited=[False]*26 visited[node[0]]=True que=deque() que.append(node[0]) while que : p=que.popleft() for i in range(26): if edges[p][i]and not visited[i]: visited[i]=True que.append(i) for p in node : if not visited[p]: print("NG") break else : print("OK") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var ins : OclAny := Set{} ; var outs : OclAny := Set{} ; var node : Set := Set{}->union(()) ; var base : int := ("a")->char2byte() ; var edges : Sequence := Integer.subrange(0, 26-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 26))) ; for i : Integer.subrange(0, 26-1) do ( ins[i+1] := 0 ; outs[i+1] := 0) ; for _anon : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var fr : double := (s->first())->char2byte() - base ; var to : double := (s->last())->char2byte() - base ; ins[to+1] := ins[to+1] + 1 ; outs[fr+1] := outs[fr+1] + 1 ; edges[fr+1][to+1] := 1 ; execute ((fr) : node) ; execute ((to) : node)) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 26))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name ins)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) != (comparison (expr (atom (name outs)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NG"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name node)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name node)))))))) ))))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name visited)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name False))))))) ])) * (expr (atom (number (integer 26)))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name visited)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name node)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name True)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name que)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name deque)) (trailer (arguments ( ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name que)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name node)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))))))))))) (stmt (compound_stmt while (test (logical_test (comparison (expr (atom (name que)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name p)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name que)) (trailer . (name popleft) (arguments ( ))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 26))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name p)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))) and (logical_test not (logical_test (comparison (expr (atom (name visited)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name visited)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name True)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name que)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name p)))) in (testlist (test (logical_test (comparison (expr (atom (name node))))))) : (suite (stmt (compound_stmt if (test (logical_test not (logical_test (comparison (expr (atom (name visited)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name p)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NG"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "OK"))))))) )))))))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque ca=ord('a') while 1 : N=int(input()) if N==0 : break G=[[]for i in range(26)] S=[0]*26 ; T=[0]*26 for i in range(N): word=input() s=ord(word[0])-ca ; t=ord(word[-1])-ca S[s]+=1 ; T[t]+=1 G[s].append(t) ok=1 for i in range(26): if S[i]!=T[i]: ok=0 if ok : que=deque() U=[0]*26 for i in range(26): if S[i]: que.append(i) U[i]=1 break while que : v=que.popleft() for w in G[v]: if U[w]: continue U[w]=1 que.append(w) for i in range(26): if S[i]and not U[i]: ok=0 print("OK" if ok else "NG") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var ca : int := ('a')->char2byte() ; while 1 do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var G : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | (Sequence{})) ; var S : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26); var T : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for i : Integer.subrange(0, N-1) do ( var word : String := (OclFile["System.in"]).readLine() ; var s : double := (word->first())->char2byte() - ca; var t : double := (word->last())->char2byte() - ca ; S[s+1] := S[s+1] + 1; T[t+1] := T[t+1] + 1 ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) ))))) ; var ok : int := 1 ; for i : Integer.subrange(0, 26-1) do ( if S[i+1] /= T[i+1] then ( ok := 0 ) else skip) ; if ok then ( var que : Sequence := () ; var U : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for i : Integer.subrange(0, 26-1) do ( if S[i+1] then ( execute ((i) : que) ; U[i+1] := 1 ; break ) else skip) ; while que do ( var v : OclAny := que->first() ; que := que->tail() ; for w : G[v+1] do ( if U[w+1] then ( continue ) else skip ; U[w+1] := 1 ; execute ((w) : que))) ; for i : Integer.subrange(0, 26-1) do ( if S[i+1] & not(U[i+1]) then ( ok := 0 ) else skip) ) else skip ; execute (if ok then "OK" else "NG" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import* def searchnode(i,u,path): r=1 u[i]=1 for j in range(26): if path[(i,j)]and(not u[j]): r+=searchnode(j,u,path) return r def chrtoint(a): return ord(a)-ord('a') while 1 : n=int(input()) if n==0 : break inp=[input()for i in range(n)] front,back=[0]*26,[0]*26 path=defaultdict(int) u=[0]*26 for i in inp : front[chrtoint(i[0])]+=1 back[chrtoint(i[-1])]+=1 path[(chrtoint(i[0]),chrtoint(i[-1]))]+=1 if front!=back : print("NG") continue if sum(i!=0 for i in front)==searchnode(chrtoint(i[-1]),u,path): print("OK") else : print("NG") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var inp : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var front : OclAny := null; var back : OclAny := null; Sequence{front,back} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, 26),MatrixLib.elementwiseMult(Sequence{ 0 }, 26)} ; path := defaultdict(OclType["int"]) ; u := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for i : inp do ( front[chrtoint(i->first())+1] := front[chrtoint(i->first())+1] + 1 ; back[chrtoint(i->last())+1] := back[chrtoint(i->last())+1] + 1 ; path[Sequence{chrtoint(i->first()), chrtoint(i->last())}+1] := path[Sequence{chrtoint(i->first()), chrtoint(i->last())}+1] + 1) ; if front /= back then ( execute ("NG")->display() ; continue ) else skip ; if ((argument (test (logical_test (comparison (comparison (expr (atom (name i)))) != (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name front))))))))->sum() = searchnode(chrtoint(i->last()), u, path) then ( execute ("OK")->display() ) else ( execute ("NG")->display() )); operation searchnode(i : OclAny, u : OclAny, path : OclAny) : OclAny pre: true post: true activity: var r : int := 1 ; u[i+1] := 1 ; for j : Integer.subrange(0, 26-1) do ( if path[Sequence{i, j}+1] & (not(u[j+1])) then ( r := r + searchnode(j, u, path) ) else skip) ; return r; operation chrtoint(a : OclAny) : OclAny pre: true post: true activity: return (a)->char2byte() - ('a')->char2byte(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) ma=max(a) mai=a.index(ma) mi=min(a) mii=a.index(mi) ans=[] if abs(ma)>=abs(mi): for i in range(n): a[i]+=ma ans.append((mai+1,i+1)) for i in range(1,n): a[i]+=a[i-1] ans.append((i,i+1)) else : for i in range(n): a[i]+=mi ans.append((mii+1,i+1)) for i in range(n-2,-1,-1): a[i]+=a[i+1] ans.append((i+2,i+1)) print(len(ans)) for i in ans : print(*i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ma : OclAny := (a)->max() ; var mai : int := a->indexOf(ma) - 1 ; var mi : OclAny := (a)->min() ; var mii : int := a->indexOf(mi) - 1 ; var ans : Sequence := Sequence{} ; if ((ma)->abs()->compareTo((mi)->abs())) >= 0 then ( for i : Integer.subrange(0, n-1) do ( a[i+1] := a[i+1] + ma ; execute ((Sequence{mai + 1, i + 1}) : ans)) ; for i : Integer.subrange(1, n-1) do ( a[i+1] := a[i+1] + a[i - 1+1] ; execute ((Sequence{i, i + 1}) : ans)) ) else ( for i : Integer.subrange(0, n-1) do ( a[i+1] := a[i+1] + mi ; execute ((Sequence{mii + 1, i + 1}) : ans)) ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( a[i+1] := a[i+1] + a[i + 1+1] ; execute ((Sequence{i + 2, i + 1}) : ans)) ) ; execute ((ans)->size())->display() ; for i : ans do ( execute ((argument * (test (logical_test (comparison (expr (atom (name i))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools N,P=[int(i)for i in input().split()] biscuits=[int(i)for i in input().split()] even=0 odd=0 buffer_count=1 even_c=1 for i in biscuits : if i % 2==0 : even+=1 elif i % 2==1 : odd+=1 if P==0 : odd_c=1 elif P==1 : odd_c=0 if even>odd : for i in range(1,even+1): even_c+=2**(i-1) if i==odd : buffer_count=even_c elif odd>=even : for i in range(1,odd+1): buffer_count+=2**(i-1) if i==even : even_c=buffer_count if P==0 : if buffer_count>2 : odd_c=(buffer_count/2) elif P==1 : if buffer_count>1 : odd_c=(buffer_count/2) print(int(even_c*odd_c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var P : OclAny := null; Sequence{N,P} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var biscuits : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var even : int := 0 ; var odd : int := 0 ; var buffer_count : int := 1 ; var even_c : int := 1 ; for i : biscuits do ( if i mod 2 = 0 then ( even := even + 1 ) else (if i mod 2 = 1 then ( odd := odd + 1 ) else skip)) ; if P = 0 then ( var odd_c : int := 1 ) else (if P = 1 then ( odd_c := 0 ) else skip) ; if (even->compareTo(odd)) > 0 then ( for i : Integer.subrange(1, even + 1-1) do ( even_c := even_c + (2)->pow((i - 1)) ; if i = odd then ( buffer_count := even_c ) else skip) ) else (if (odd->compareTo(even)) >= 0 then ( for i : Integer.subrange(1, odd + 1-1) do ( buffer_count := buffer_count + (2)->pow((i - 1)) ; if i = even then ( even_c := buffer_count ) else skip) ) else skip) ; if P = 0 then ( if buffer_count > 2 then ( odd_c := (buffer_count / 2) ) else skip ) else (if P = 1 then ( if buffer_count > 1 then ( odd_c := (buffer_count / 2) ) else skip ) else skip) ; execute (("" + ((even_c * odd_c)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumDivisibles(A,B,M): sum=0 for i in range(A,B+1): if(i % M==0): sum+=i return sum if __name__=="__main__" : A=6 B=15 M=3 print(sumDivisibles(A,B,M)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( A := 6 ; B := 15 ; M := 3 ; execute (sumDivisibles(A, B, M))->display() ) else skip; operation sumDivisibles(A : OclAny, B : OclAny, M : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(A, B + 1-1) do ( if (i mod M = 0) then ( sum := sum + i ) else skip) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from collections import defaultdict sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod=10**9+7 def I(): return int(input()) def II(): return map(int,input().split()) def III(): return list(map(int,input().split())) def Line(N,num): if N<=0 : return[[]]*num elif num==1 : return[I()for _ in range(N)] else : read_all=[tuple(II())for _ in range(N)] return map(list,zip(*read_all)) def my_sign(x): return(x>0)-(x<0) N=I() a=III() max_val=0 max_sign=0 max_index=-1 for i,a0 in enumerate(a): if abs(a0)>max_val : max_val=abs(a0) max_sign=my_sign(a0) max_index=i if max_sign==0 : print(0) elif max_sign==1 : print(2*N-1) for i in range(N): print(max_index+1,i+1) for i in range(N-1): print(i+1,i+2) else : print(2*N-1) for i in range(N): print(max_index+1,i+1) for i in range(1,N)[: :-1]: print(i+1,i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; N := I() ; var a : OclAny := III() ; var max_val : int := 0 ; var max_sign : int := 0 ; var max_index : int := -1 ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a0 : OclAny := _tuple->at(_indx); if ((a0)->abs()->compareTo(max_val)) > 0 then ( max_val := (a0)->abs() ; max_sign := my_sign(a0) ; max_index := i ) else skip) ; if max_sign = 0 then ( execute (0)->display() ) else (if max_sign = 1 then ( execute (2 * N - 1)->display() ; for i : Integer.subrange(0, N-1) do ( execute (max_index + 1)->display()) ; for i : Integer.subrange(0, N - 1-1) do ( execute (i + 1)->display()) ) else ( execute (2 * N - 1)->display() ; for i : Integer.subrange(0, N-1) do ( execute (max_index + 1)->display()) ; for i : range(1, N)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( execute (i + 1)->display()) ) ) ; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation II() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation III() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation Line(N : OclAny, num : OclAny) : OclAny pre: true post: true activity: if N <= 0 then ( return MatrixLib.elementwiseMult(Sequence{ Sequence{} }, num) ) else (if num = 1 then ( return Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (I())) ) else ( var read_all : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | ((II()))) ; return (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name read_all)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name read_all)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name read_all)))))))`third->at(_indx)} ))->collect( _x | (OclType["Sequence"])->apply(_x) ) ) ) ; operation my_sign(x : OclAny) : OclAny pre: true post: true activity: return (x > 0) - (x < 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ls=[] for i in range(n): ls.append([]) for _ in range(n-1): u,v=map(int,input().split()) ls[u-1].append(v) ls[v-1].append(u) ls1=[[1]] ls2=[0]*n ls2[0]=1 ctr=1 rd,bl=1,0 c=1 while ctr!=n : cur=ls1[-1] ls1.append([]) for a in cur : if len(ls[a-1]): for b in ls[a-1]: if ls2[b-1]==0 : ls1[-1].append(b) ls2[b-1]=1 ctr+=1 if c==1 : bl+=1 else : rd+=1 c*=-1 ans=bl-len(ls[0]) rd-=1 for i in range(1,len(ls1)): if i % 2 : bl-=len(ls1[i]) for a in ls1[i]: ans+=rd-(len(ls[a-1])-1) else : rd-=len(ls1[i]) for a in ls1[i]: ans+=bl-(len(ls[a-1])-1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ls : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((Sequence{}) : ls)) ; for _anon : Integer.subrange(0, n - 1-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name ls)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name u))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) ; (expr (atom (name ls)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)))))))) ))))) ; var ls1 : Sequence := Sequence{ Sequence{ 1 } } ; var ls2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; ls2->first() := 1 ; var ctr : int := 1 ; var rd : OclAny := null; var bl : OclAny := null; Sequence{rd,bl} := Sequence{1,0} ; var c : int := 1 ; while ctr /= n do ( var cur : OclAny := ls1->last() ; execute ((Sequence{}) : ls1) ; for a : cur do ( if (ls[a - 1+1])->size() then ( for b : ls[a - 1+1] do ( if ls2[b - 1+1] = 0 then ( (expr (atom (name ls1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; ls2[b - 1+1] := 1 ; ctr := ctr + 1 ; if c = 1 then ( bl := bl + 1 ) else ( rd := rd + 1 ) ) else skip) ) else skip) ; c := c * -1) ; var ans : double := bl - (ls->first())->size() ; rd := rd - 1 ; for i : Integer.subrange(1, (ls1)->size()-1) do ( if i mod 2 then ( bl := bl - (ls1[i+1])->size() ; for a : ls1[i+1] do ( ans := ans + rd - ((ls[a - 1+1])->size() - 1)) ) else ( rd := rd - (ls1[i+1])->size() ; for a : ls1[i+1] do ( ans := ans + bl - ((ls[a - 1+1])->size() - 1)) )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) a=list(map(int,input().split())) i=max(range(N),key=lambda j : abs(a[j]))+1 ans='{}\n{}'.format(2*N,'\n'.join(['{}{}'.format(i,j)for j in range(1,N+1)if j!=i]+['{}{}'.format(i,i)]+(['{}{}'.format(i,1)]+['{}{}'.format(j,j+1)for j in range(1,N)]if a[i-1]>=0 else['{}{}'.format(i,N)]+['{}{}'.format(j+1,j)for j in reversed(range(1,N))]))) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var i : OclAny := Set{Integer.subrange(0, N-1), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name j)))) : (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) )))))))))}->max() + 1 ; var ans : String := StringLib.interpolateStrings('{} {}', Sequence{2 * N, StringLib.sumStringsWithSeparator((Integer.subrange(1, N + 1-1)->select(j | j /= i)->collect(j | (StringLib.interpolateStrings('{}{}', Sequence{i, j})))->union(Sequence{ StringLib.interpolateStrings('{}{}', Sequence{i, i}) })->union((if a[i - 1+1] >= 0 then Sequence{ StringLib.interpolateStrings('{}{}', Sequence{i, 1}) }->union(Integer.subrange(1, N-1)->select(j | true)->collect(j | (StringLib.interpolateStrings('{}{}', Sequence{j, j + 1})))) else Sequence{ StringLib.interpolateStrings('{}{}', Sequence{i, N}) }->union((Integer.subrange(1, N-1))->reverse()->select(j | true)->collect(j | (StringLib.interpolateStrings('{}{}', Sequence{j + 1, j})))) endif))), ' ')}) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import collections import bisect import itertools sys.setrecursionlimit(10**7) INF=10**16 MOD=10**9+7 ni=lambda : int(sys.stdin.readline().rstrip()) ns=lambda : map(int,sys.stdin.readline().rstrip().split()) na=lambda : list(map(int,sys.stdin.readline().rstrip().split())) na1=lambda : list(map(lambda x : int(x)-1,sys.stdin.readline().rstrip().split())) def main(): n=ni() a=na() min_num=min(a) min_num_idx=a.index(min_num) max_num=max(a) max_num_idx=a.index(max_num) ans=[] plus_flg=abs(max_num)>abs(min_num) if plus_flg : for i in range(n-1): while a[i]>a[i+1]: a[i+1]+=max_num ans.append((max_num_idx,i+1)) if max_numa[i]: a[i-1]+=min_num ans.append((min_num_idx,i-1)) if min_num>a[i-1]: min_num_idx=i-1 min_num=a[i-1] print(len(ans)) for a,b in ans : print(a+1,b+1) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; var INF : double := (10)->pow(16) ; var MOD : double := (10)->pow(9) + 7 ; var ni : Function := lambda $$ : OclAny in (("" + ((sys.stdin.readLine().rstrip())))->toInteger()) ; var ns : Function := lambda $$ : OclAny in ((sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var na : Function := lambda $$ : OclAny in (((sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var na1 : Function := lambda $$ : OclAny in (((sys.stdin.readLine().rstrip().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ))) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := ni->apply() ; var a : OclAny := na->apply() ; var min_num : OclAny := (a)->min() ; var min_num_idx : int := a->indexOf(min_num) - 1 ; var max_num : OclAny := (a)->max() ; var max_num_idx : int := a->indexOf(max_num) - 1 ; var ans : Sequence := Sequence{} ; var plus_flg : boolean := ((max_num)->abs()->compareTo((min_num)->abs())) > 0 ; if plus_flg then ( for i : Integer.subrange(0, n - 1-1) do ( while (a[i+1]->compareTo(a[i + 1+1])) > 0 do ( a[i + 1+1] := a[i + 1+1] + max_num ; execute ((Sequence{max_num_idx, i + 1}) : ans)) ; if (max_num->compareTo(a[i + 1+1])) < 0 then ( max_num_idx := i + 1 ; max_num := a[i + 1+1] ) else skip) ) else ( for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( while (a[i - 1+1]->compareTo(a[i+1])) > 0 do ( a[i - 1+1] := a[i - 1+1] + min_num ; execute ((Sequence{min_num_idx, i - 1}) : ans)) ; if (min_num->compareTo(a[i - 1+1])) > 0 then ( min_num_idx := i - 1 ; min_num := a[i - 1+1] ) else skip) ) ; execute ((ans)->size())->display() ; for _tuple : ans do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); execute (a + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=list(map(int,input().split())) if all(a==0 for a in A): print(0) exit() INF=float('inf') mn=INF mx=-INF mni=mxi=-1 for i,a in enumerate(A): if a>mx : mx=a mxi=i if a=0 : p=True elif mx<=0 : p=False else : if mx>-mn : for i,a in enumerate(A): if a<0 : ans.append((mxi+1,i+1)) p=True else : for i,a in enumerate(A): if a>0 : ans.append((mni+1,i+1)) p=False if p : for i in range(1,N): ans.append((i,i+1)) else : for i in range(N,1,-1): ans.append((i,i-1)) print(len(ans)) for a,b in ans : print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if ((argument (test (logical_test (comparison (comparison (expr (atom (name a)))) == (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name A))))))))->forAll( _x | _x = true ) then ( execute (0)->display() ; exit() ) else skip ; var INF : double := ("" + (('inf')))->toReal() ; var mn : OclAny := INF ; var mx : OclAny := -INF ; var mni : OclAny := -1; var mxi : int := -1 ; for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); if (a->compareTo(mx)) > 0 then ( mx := a ; mxi := i ) else skip ; if (a->compareTo(mn)) < 0 then ( mn := a ; mni := i ) else skip) ; var ans : Sequence := Sequence{} ; if mn >= 0 then ( var p : boolean := true ) else (if mx <= 0 then ( p := false ) else ( if (mx->compareTo(-mn)) > 0 then ( for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); if a < 0 then ( execute ((Sequence{mxi + 1, i + 1}) : ans) ) else skip) ; p := true ) else ( for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); if a > 0 then ( execute ((Sequence{mni + 1, i + 1}) : ans) ) else skip) ; p := false ) ) ) ; if p then ( for i : Integer.subrange(1, N-1) do ( execute ((Sequence{i, i + 1}) : ans)) ) else ( for i : Integer.subrange(1 + 1, N)->reverse() do ( execute ((Sequence{i, i - 1}) : ans)) ) ; execute ((ans)->size())->display() ; for _tuple : ans do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkPalindrome(string): length=len(string) length-=1 for i in range(length): if string[i]!=string[length]: return False length-=1 return True def printSolution(partitions): for i in range(len(partitions)): for j in range(len(partitions[i])): print(partitions[i][j],end="") print() def addStrings(v,s,temp,index): length=len(s) string="" current=temp[:] if index==0 : temp=[] for i in range(index,length): string+=s[i] if checkPalindrome(string): temp.append(string) if i+1size() ; length := length - 1 ; for i : Integer.subrange(0, length-1) do ( if string[i+1] /= string[length+1] then ( return false ) else skip ; length := length - 1) ; return true; operation printSolution(partitions : OclAny) pre: true post: true activity: for i : Integer.subrange(0, (partitions)->size()-1) do ( for j : Integer.subrange(0, (partitions[i+1])->size()-1) do ( execute (partitions[i+1][j+1])->display()) ; execute (->display()); operation addStrings(v : OclAny, s : OclAny, temp : OclAny, index : OclAny) pre: true post: true activity: length := (s)->size() ; string := "" ; var current : Sequence := temp ; if index = 0 then ( temp := Sequence{} ) else skip ; for i : Integer.subrange(index, length-1) do ( string := string + s[i+1] ; if checkPalindrome(string) then ( execute ((string) : temp) ; if (i + 1->compareTo(length)) < 0 then ( addStrings(v, s, temp, i + 1) ) else ( execute ((temp) : v) ) ; temp := current ) else skip); operation partition(s : OclAny, v : OclAny) pre: true post: true activity: temp := Sequence{} ; addStrings(v, s, temp, 0) ; printSolution(v); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() if n % 2!=0 : print('No') elif s[: int(n/2)]==s[int(n/2):]: print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; if n mod 2 /= 0 then ( execute ('No')->display() ) else (if s.subrange(1,("" + ((n / 2)))->toInteger()) = s.subrange(("" + ((n / 2)))->toInteger()+1) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import bisect from collections import defaultdict,deque,Counter from heapq import heappush,heappop def LI(): return[int(x)for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def S(): res=list(sys.stdin.readline()) if res[-1]=="\n" : return res[:-1] return res def A(): r=I() print(r*r) return def B(): N=I() s=S() if N % 2!=0 : print("No") elif ''.join(s[: N//2])==''.join(s[N//2 :]): print("Yes") else : print("No") return def C(): return def D(): return def E(): return def F(): return def resolve(): B() return if __name__=="__main__" : B() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( B() ) else skip; operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation S() : OclAny pre: true post: true activity: var res : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if res->last() = "\n" then ( return res->front() ) else skip ; return res; operation A() pre: true post: true activity: var r : OclAny := I() ; execute (r * r)->display() ; return; operation B() pre: true post: true activity: var N : OclAny := I() ; var s : OclAny := S() ; if N mod 2 /= 0 then ( execute ("No")->display() ) else (if StringLib.sumStringsWithSeparator((s.subrange(1,N div 2)), '') = StringLib.sumStringsWithSeparator((s.subrange(N div 2+1)), '') then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) ; return; operation C() pre: true post: true activity: return; operation D() pre: true post: true activity: return; operation E() pre: true post: true activity: return; operation F() pre: true post: true activity: return; operation resolve() pre: true post: true activity: B() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import gcd import math from math import factorial as f from math import ceil,floor,sqrt from sys import exit from copy import deepcopy import numpy as np import bisect import re import heapq from copy import deepcopy import itertools ii=lambda : int(input()) mi=lambda : map(int,input().split()) li=lambda : list(map(int,input().split())) def main(): n=ii() s=input() n2=n//2 if n % 2 : print('No') else : for i in range(n2): if not s[i]==s[i+n2]: print('No') exit() print('Yes') main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var ii : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var mi : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var li : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; skip ; main(); operation main() pre: true post: true activity: var n : OclAny := ii->apply() ; var s : String := (OclFile["System.in"]).readLine() ; var n2 : int := n div 2 ; if n mod 2 then ( execute ('No')->display() ) else ( for i : Integer.subrange(0, n2-1) do ( if not(s[i+1] = s[i + n2+1]) then ( execute ('No')->display() ; exit() ) else skip) ; execute ('Yes')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy import random import bisect import fractions import math import sys import collections mod=10**9+7 sys.setrecursionlimit(mod) d=collections.deque() def LI(): return list(map(int,sys.stdin.readline().split())) N=int(input()) S=str(input()) if N % 2!=0 : print("No") else : if S[: N//2]==S[N//2 :]: print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; sys.setrecursionlimit(mod) ; var d : Sequence := () ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : String := ("" + (((OclFile["System.in"]).readLine()))) ; if N mod 2 /= 0 then ( execute ("No")->display() ) else ( if S.subrange(1,N div 2) = S.subrange(N div 2+1) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def countNumbersWith4(n): if(n<4): return 0 d=int(mt.log10(n)) a=[1 for i in range(d+1)] a[0]=0 if len(a)>1 : a[1]=1 for i in range(2,d+1): a[i]=a[i-1]*9+mt.ceil(pow(10,i-1)) p=mt.ceil(pow(10,d)) msd=n//p if(msd==4): return(msd)*a[d]+(n % p)+1 if(msd>4): return((msd-1)*a[d]+p+countNumbersWith4(n % p)) return(msd)*a[d]+countNumbersWith4(n % p) n=328 print("Count of numbers from 1 to",n,"that have 4 as a digit is",countNumbersWith4(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 328 ; execute ("Count of numbers from 1 to")->display(); operation countNumbersWith4(n : OclAny) : OclAny pre: true post: true activity: if (n < 4) then ( return 0 ) else skip ; var d : int := ("" + ((mt.log10(n))))->toInteger() ; var a : Sequence := Integer.subrange(0, d + 1-1)->select(i | true)->collect(i | (1)) ; a->first() := 0 ; if (a)->size() > 1 then ( a[1+1] := 1 ) else skip ; for i : Integer.subrange(2, d + 1-1) do ( a[i+1] := a[i - 1+1] * 9 + mt.ceil((10)->pow(i - 1))) ; var p : int := mt.ceil((10)->pow(d)) ; var msd : int := n div p ; if (msd = 4) then ( return (msd) * a[d+1] + (n mod p) + 1 ) else skip ; if (msd > 4) then ( return ((msd - 1) * a[d+1] + p + countNumbersWith4(n mod p)) ) else skip ; return (msd) * a[d+1] + countNumbersWith4(n mod p); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import numpy as np class getStdin(object): @ classmethod def get_int(cls): return int(input()) @ classmethod def get_str(cls): return str(input()) class funcCls(object): @ classmethod def done(cls,n,s): l=len(s)//2 mm=s[0 : l] if s==mm+mm : print('Yes') else : print('No') return if __name__=='__main__' : n=getStdin.get_int() s=getStdin.get_str() funcCls.done(n,s) os.sys.exit(0) ------------------------------------------------------------ OCL File: --------- class getStdin extends object { static operation newgetStdin() : getStdin pre: true post: getStdin->exists( _x | result = _x ); } class funcCls extends object { static operation newfuncCls() : funcCls pre: true post: funcCls->exists( _x | result = _x ); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( n := (getStdin.newgetStdin()).initialise.get_int() ; s := (getStdin.newgetStdin()).initialise.get_str() ; funcCls.done(n, s) ; (expr (atom (name os)) (trailer . (name sys)) (trailer . (name exit) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=100000007 def dp(n,k): if tbl[n][k]: return tbl[n][k] if(k<<1)>n : k=n-k if k==0 : ans=1 elif k==1 : ans=n else : ans=dp(n-1,k)+dp(n-1,k-1) tbl[n][k]=ans % MOD return tbl[n][k] tbl=[[0 for j in range(1001)]for i in range(1001)] k=0 r,c,a1,a2,b1,b2=map(int,input().split()) dr=abs(a1-b1) if dr>r-dr : dr=r-dr if(dr<<1)==r : k+=1 dc=abs(a2-b2) if dc>c-dc : dc=c-dc if(dc<<1)==c : k+=1 print((dp(dr+dc,min(dr,dc))<select(i | true)->collect(i | (Integer.subrange(0, 1001-1)->select(j | true)->collect(j | (0)))) ; k := 0 ; var r : OclAny := null; var c : OclAny := null; var a1 : OclAny := null; var a2 : OclAny := null; var b1 : OclAny := null; var b2 : OclAny := null; Sequence{r,c,a1,a2,b1,b2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dr : double := (a1 - b1)->abs() ; if (dr->compareTo(r - dr)) > 0 then ( dr := r - dr ) else skip ; if (dr * (2->pow(1))) = r then ( k := k + 1 ) else skip ; var dc : double := (a2 - b2)->abs() ; if (dc->compareTo(c - dc)) > 0 then ( dc := c - dc ) else skip ; if (dc * (2->pow(1))) = c then ( k := k + 1 ) else skip ; execute ((dp(dr + dc, Set{dr, dc}->min()) * (2->pow(k))) mod MOD)->display(); operation dp(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if tbl[n+1][k+1] then ( return tbl[n+1][k+1] ) else skip ; if ((k * (2->pow(1)))->compareTo(n)) > 0 then ( k := n - k ) else skip ; if k = 0 then ( var ans : int := 1 ) else (if k = 1 then ( ans := n ) else ( ans := dp(n - 1, k) + dp(n - 1, k - 1) ) ) ; tbl[n+1][k+1] := ans mod MOD ; return tbl[n+1][k+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def bfs(edge_list,vis,T): q=deque() map={0 : 0,1 : 0} q.append((0,0)) vis[0]=1 while len(q)!=0 : val,lev=q.popleft() map[lev]+=1 for edge in edge_list[val]: if not vis[edge]: vis[edge]=1 q.append((edge,(lev+1)% 2)) return map[0]*map[1]-(T-1) T=int(input()) edge_list=[[]for _ in range(T)] vis=[0 for _ in range(T)] for _ in range(T-1): i,j=tuple(map(int,input().split())) edge_list[i-1].append(j-1) edge_list[j-1].append(i-1) print(bfs(edge_list,vis,T)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; T := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; edge_list := Integer.subrange(0, T-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; vis := Integer.subrange(0, T-1)->select(_anon | true)->collect(_anon | (0)) ; for _anon : Integer.subrange(0, T - 1-1) do ( var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (expr (atom (name edge_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name j))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name edge_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name j))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ))))) ; execute (bfs(edge_list, vis, T))->display(); operation bfs(edge_list : OclAny, vis : OclAny, T : OclAny) : OclAny pre: true post: true activity: var q : Sequence := () ; var map : Map := Map{ 0 |-> 0 }->union(Map{ 1 |-> 0 }) ; execute ((Sequence{0, 0}) : q) ; vis->first() := 1 ; while (q)->size() /= 0 do ( var val : OclAny := null; var lev : OclAny := null; Sequence{val,lev} := q->first() ; q := q->tail() ; ([lev+1]`third)->collect( _x | ([lev+1])->apply(_x) ) := ([lev+1]`third)->collect( _x | ([lev+1])->apply(_x) ) + 1 ; for edge : edge_list[val+1] do ( if not(vis[edge+1]) then ( vis[edge+1] := 1 ; execute ((Sequence{edge, (lev + 1) mod 2}) : q) ) else skip)) ; return MatrixLib.dotProduct((->first()`third)->collect( _x | (->first())->apply(_x) ),([1+1]`third)->collect( _x | ([1+1])->apply(_x) )) - (T - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import factorial if __name__=="__main__" : r,c,ar,ac,br,bc=map(int,input().strip("\n").split(" ")) maxans=100000007 dr=min(abs(br-ar),r-abs(br-ar)) if 2*dr==r : gainr=2 else : gainr=1 dc=min(abs(bc-ac),c-abs(bc-ac)) if 2*dc==c : gainc=2 else : gainc=1 ans1=factorial(dr+dc) ans2=factorial(dr) ans3=factorial(dc) ans4=ans1//ans2//ans3*gainr*gainc ans=ans4 print(ans % maxans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var r : OclAny := null; var c : OclAny := null; var ar : OclAny := null; var ac : OclAny := null; var br : OclAny := null; var bc : OclAny := null; Sequence{r,c,ar,ac,br,bc} := (input()->trim().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var maxans : int := 100000007 ; var dr : OclAny := Set{(br - ar)->abs(), r - (br - ar)->abs()}->min() ; if 2 * dr = r then ( var gainr : int := 2 ) else ( gainr := 1 ) ; var dc : OclAny := Set{(bc - ac)->abs(), c - (bc - ac)->abs()}->min() ; if 2 * dc = c then ( var gainc : int := 2 ) else ( gainc := 1 ) ; var ans1 : OclAny := factorial(dr + dc) ; var ans2 : OclAny := factorial(dr) ; var ans3 : OclAny := factorial(dc) ; var ans4 : int := ans1 div ans2 div ans3 * gainr * gainc ; var ans : int := ans4 ; execute (ans mod maxans)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=10**8+7 n=1001 def comb(x,y): if 2*y>x : return comb(x,x-y) return fac[x]*inv[y]*inv[x-y]% mod fac=[1]*(n+1) inv=[1]*(n+1) for i in range(2,n+1): fac[i]=fac[i-1]*i % mod inv[n]=pow(fac[n],mod-2,mod) for i in range(n-1,1,-1): inv[i]=inv[i+1]*(i+1)% mod r,c,a1,a2,b1,b2=map(int,input().split()) row=min(abs(b1-a1),r-abs(b1-a1)) col=min(abs(b2-a2),c-abs(b2-a2)) ans=1 if row*2==r : ans*=2 if col*2==c : ans*=2 ans*=comb(row+col,row) ans %=mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : double := (10)->pow(8) + 7 ; var n : int := 1001 ; skip ; var fac : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ; var inv : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ; for i : Integer.subrange(2, n + 1-1) do ( fac[i+1] := fac[i - 1+1] * i mod mod) ; inv[n+1] := (fac[n+1])->pow(mod - 2) ; for i : Integer.subrange(1 + 1, n - 1)->reverse() do ( inv[i+1] := inv[i + 1+1] * (i + 1) mod mod) ; var r : OclAny := null; var c : OclAny := null; var a1 : OclAny := null; var a2 : OclAny := null; var b1 : OclAny := null; var b2 : OclAny := null; Sequence{r,c,a1,a2,b1,b2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var row : OclAny := Set{(b1 - a1)->abs(), r - (b1 - a1)->abs()}->min() ; var col : OclAny := Set{(b2 - a2)->abs(), ? - (b2 - a2)->abs()}->min() ; var ans : int := 1 ; if row * 2 = r then ( ans := ans * 2 ) else skip ; if col * 2 = c then ( ans := ans * 2 ) else skip ; ans := ans * comb(row + col, row) ; ans := ans mod mod ; execute (ans)->display(); operation comb(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (2 * y->compareTo(x)) > 0 then ( return comb(x, x - y) ) else skip ; return fac[x+1] * inv[y+1] * inv[x - y+1] mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=100000007 r,c,a1,a2,b1,b2=map(int,input().split()) dx=abs(a1-b1) dy=abs(a2-b2) cnt=1 if dx*2==r : cnt*=2 if dy*2==c : cnt*=2 dx=min(dx,r-dx) dy=min(dy,c-dy) dp=[[0]*(dx+2)for _ in range(dy+2)] dp[0][1]=1 for y in range(1,dy+2): for x in range(1,dx+2): dp[y][x]=(dp[y-1][x]+dp[y][x-1])% MOD print(dp[dy+1][dx+1]*cnt % MOD) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : int := 100000007 ; var r : OclAny := null; var c : OclAny := null; var a1 : OclAny := null; var a2 : OclAny := null; var b1 : OclAny := null; var b2 : OclAny := null; Sequence{r,c,a1,a2,b1,b2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dx : double := (a1 - b1)->abs() ; var dy : double := (a2 - b2)->abs() ; var cnt : int := 1 ; if dx * 2 = r then ( cnt := cnt * 2 ) else skip ; if dy * 2 = c then ( cnt := cnt * 2 ) else skip ; dx := Set{dx, r - dx}->min() ; dy := Set{dy, c - dy}->min() ; var dp : Sequence := Integer.subrange(0, dy + 2-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (dx + 2)))) ; dp->first()[1+1] := 1 ; for y : Integer.subrange(1, dy + 2-1) do ( for x : Integer.subrange(1, dx + 2-1) do ( dp[y+1][x+1] := (dp[y - 1+1][x+1] + dp[y+1][x - 1+1]) mod MOD)) ; execute (dp[dy + 1+1][dx + 1+1] * cnt mod MOD)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import factorial sys.setrecursionlimit(10000) def comb(x,y): return factorial(x)//factorial(x-y)//factorial(y) w,h,ax,ay,bx,by=map(int,input().split()) dx=min(w-abs(ax-bx),abs(ax-bx)) dy=min(h-abs(ay-by),abs(ay-by)) ans=1 if dx*2==w : ans*=2 if dy*2==h : ans*=2 ans*=comb(dx+dy,dx) print(ans % 100000007) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit(10000) ; skip ; var w : OclAny := null; var h : OclAny := null; var ax : OclAny := null; var ay : OclAny := null; var bx : OclAny := null; var by : OclAny := null; Sequence{w,h,ax,ay,bx,by} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dx : OclAny := Set{w - (ax - bx)->abs(), (ax - bx)->abs()}->min() ; var dy : OclAny := Set{h - (ay - by)->abs(), (ay - by)->abs()}->min() ; var ans : int := 1 ; if dx * 2 = w then ( ans := ans * 2 ) else skip ; if dy * 2 = h then ( ans := ans * 2 ) else skip ; ans := ans * comb(dx + dy, dx) ; execute (ans mod 100000007)->display(); operation comb(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return factorial(x) div factorial(x - y) div factorial(y); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def findSubsequence(arr,n,k): M=defaultdict(lambda : 0) for i in range(0,n): M[arr[i]]+=1 numCount=[0]*(k+1) for p in M : if p<=k : i=1 while p*i<=k : numCount[p*i]+=M[p] i+=1 else : break lcm,length=0,0 for i in range(1,k+1): if numCount[i]>length : length=numCount[i] lcm=i if lcm==0 : print(-1) else : print("LCM={0},Length={1}".format(lcm,length)) print("Indexes=",end="") for i in range(0,n): if lcm % arr[i]==0 : print(i,end=" ") if __name__=="__main__" : k=14 arr=[2,3,4,5] n=len(arr) findSubsequence(arr,n,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( k := 14 ; arr := Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 }))) ; n := (arr)->size() ; findSubsequence(arr, n, k) ) else skip; operation findSubsequence(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var M : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; for i : Integer.subrange(0, n-1) do ( M[arr[i+1]+1] := M[arr[i+1]+1] + 1) ; var numCount : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (k + 1)) ; for p : M do ( if (p->compareTo(k)) <= 0 then ( var i : int := 1 ; while (p * i->compareTo(k)) <= 0 do ( numCount[p * i+1] := numCount[p * i+1] + M[p+1] ; i := i + 1) ) else ( break )) ; var lcm : OclAny := null; var length : OclAny := null; Sequence{lcm,length} := Sequence{0,0} ; for i : Integer.subrange(1, k + 1-1) do ( if (numCount[i+1]->compareTo(length)) > 0 then ( var length : OclAny := numCount[i+1] ; var lcm : int := i ) else skip) ; if lcm = 0 then ( execute (-1)->display() ) else ( execute (StringLib.interpolateStrings("LCM={0},Length={1}", Sequence{lcm, length}))->display() ; execute ("Indexes=")->display() ; for i : Integer.subrange(0, n-1) do ( if lcm mod arr[i+1] = 0 then ( execute (i)->display() ) else skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count_pairs(a,b,n,m): odd1=0 even1=0 odd2=0 even2=0 for i in range(n): if(a[i]% 2==1): odd1+=1 else : even1+=1 for i in range(m): if(b[i]% 2==1): odd2+=1 else : even2+=1 pairs=min(odd1,odd2)+min(even1,even2) return pairs if __name__=='__main__' : a=[9,14,6,2,11] b=[8,4,7,20] n=len(a) m=len(b) print(count_pairs(a,b,n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := Sequence{9}->union(Sequence{14}->union(Sequence{6}->union(Sequence{2}->union(Sequence{ 11 })))) ; b := Sequence{8}->union(Sequence{4}->union(Sequence{7}->union(Sequence{ 20 }))) ; n := (a)->size() ; m := (b)->size() ; execute (count_pairs(a, b, n, m))->display() ) else skip; operation count_pairs(a : OclAny, b : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var odd1 : int := 0 ; var even1 : int := 0 ; var odd2 : int := 0 ; var even2 : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] mod 2 = 1) then ( odd1 := odd1 + 1 ) else ( even1 := even1 + 1 )) ; for i : Integer.subrange(0, m-1) do ( if (b[i+1] mod 2 = 1) then ( odd2 := odd2 + 1 ) else ( even2 := even2 + 1 )) ; var pairs : OclAny := Set{odd1, odd2}->min() + Set{even1, even2}->min() ; return pairs; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count_pairs(a,b,n,m): odd1=0 even1=0 odd2=0 even2=0 for i in range(n): if(a[i]% 2): odd1+=1 else : even1+=1 for i in range(m): if(b[i]% 2): odd2+=1 else : even2+=1 pairs=(min(odd1,even2)+min(odd2,even1)) return pairs if __name__=='__main__' : a=[9,14,6,2,11] b=[8,4,7,20] n=len(a) m=len(b) print(count_pairs(a,b,n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := Sequence{9}->union(Sequence{14}->union(Sequence{6}->union(Sequence{2}->union(Sequence{ 11 })))) ; b := Sequence{8}->union(Sequence{4}->union(Sequence{7}->union(Sequence{ 20 }))) ; n := (a)->size() ; m := (b)->size() ; execute (count_pairs(a, b, n, m))->display() ) else skip; operation count_pairs(a : OclAny, b : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var odd1 : int := 0 ; var even1 : int := 0 ; var odd2 : int := 0 ; var even2 : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] mod 2) then ( odd1 := odd1 + 1 ) else ( even1 := even1 + 1 )) ; for i : Integer.subrange(0, m-1) do ( if (b[i+1] mod 2) then ( odd2 := odd2 + 1 ) else ( even2 := even2 + 1 )) ; var pairs : OclAny := (Set{odd1, even2}->min() + Set{odd2, even1}->min()) ; return pairs; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- wah=list(map(int,input().split(' '))) x,y,n=wah[0],wah[1],int(input()) all=[x,y,y-x,-x,-y,x-y] res=(n-1)% 6 print(all[res]% 1000000007) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var wah : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := null; var y : OclAny := null; var n : OclAny := null; Sequence{x,y,n} := Sequence{wah->first(),wah[1+1],("" + (((OclFile["System.in"]).readLine())))->toInteger()} ; var all : Sequence := Sequence{x}->union(Sequence{y}->union(Sequence{y - x}->union(Sequence{-x}->union(Sequence{-y}->union(Sequence{ x - y }))))) ; var res : int := (n - 1) mod 6 ; execute ([res+1]->forAll( _x | _x = true ) mod 1000000007)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxDiff(arr,arr_size): max_diff=arr[1]-arr[0] min_element=arr[0] for i in range(1,arr_size): if(arr[i]-min_element>max_diff): max_diff=arr[i]-min_element if(arr[i]union(Sequence{2}->union(Sequence{6}->union(Sequence{80}->union(Sequence{ 100 })))) ; var size : int := (arr)->size() ; execute ("Maximum difference is")->display(); operation maxDiff(arr : OclAny, arr_size : OclAny) : OclAny pre: true post: true activity: var max_diff : double := arr[1+1] - arr->first() ; var min_element : OclAny := arr->first() ; for i : Integer.subrange(1, arr_size-1) do ( if ((arr[i+1] - min_element->compareTo(max_diff)) > 0) then ( max_diff := arr[i+1] - min_element ) else skip ; if ((arr[i+1]->compareTo(min_element)) < 0) then ( min_element := arr[i+1] ) else skip) ; return max_diff; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binomialCoeff(n,k): C=[[0 for i in range(k+1)]for i in range(n+1)] for i in range(n+1): for j in range(min(i,k)+1): if(j==0 or j==i): C[i][j]=1 else : C[i][j]=C[i-1][j-1]+C[i-1][j] return C[n][k] def findMax(n): return binomialCoeff(n,n//2) n=5 print(findMax(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 5 ; execute (findMax(n))->display(); operation binomialCoeff(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var C : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, k + 1-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, n + 1-1) do ( for j : Integer.subrange(0, Set{i, k}->min() + 1-1) do ( if (j = 0 or j = i) then ( C[i+1][j+1] := 1 ) else ( C[i+1][j+1] := C[i - 1+1][j - 1+1] + C[i - 1+1][j+1] ))) ; return C[n+1][k+1]; operation findMax(n : OclAny) : OclAny pre: true post: true activity: return binomialCoeff(n, n div 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=26 def minimumAddition(str1,Len): freq=[0 for i in range(MAX)] for i in range(Len): freq[ord(str1[i])-ord('a')]+=1 maxFreq=max(freq) minAddition=0 for i in range(MAX): if(freq[i]>0): minAddition+=abs(maxFreq-freq[i]) return minAddition str1="geeksforgeeks" Len=len(str1) print(minimumAddition(str1,Len)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 26 ; skip ; str1 := "geeksforgeeks" ; Len := (str1)->size() ; execute (minimumAddition(str1, Len))->display(); operation minimumAddition(str1 : OclAny, Len : OclAny) : OclAny pre: true post: true activity: var freq : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, Len-1) do ( freq[(str1[i+1])->char2byte() - ('a')->char2byte()+1] := freq[(str1[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; var maxFreq : OclAny := (freq)->max() ; var minAddition : int := 0 ; for i : Integer.subrange(0, MAX-1) do ( if (freq[i+1] > 0) then ( minAddition := minAddition + (maxFreq - freq[i+1])->abs() ) else skip) ; return minAddition; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : for _ in range(int(input())): n=int(input()) bookshelf=list(map(int,input().split())) l,r=0,n-1 idxOneL,idxOneR=None,None while l<=r : if idxOneL!=None and idxOneR!=None : print(bookshelf[idxOneL : idxOneR].count(0)) break if idxOneL==None : if bookshelf[l]==1 : idxOneL=l else : l+=1 if idxOneR==None : if bookshelf[r]==1 : idxOneR=r else : r-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var bookshelf : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,n - 1} ; var idxOneL : OclAny := null; var idxOneR : OclAny := null; Sequence{idxOneL,idxOneR} := Sequence{null,null} ; while (l->compareTo(r)) <= 0 do ( if idxOneL /= null & idxOneR /= null then ( execute (bookshelf.subrange(idxOneL+1, idxOneR)->count(0))->display() ; break ) else skip ; if idxOneL = null then ( if bookshelf[l+1] = 1 then ( var idxOneL : OclAny := l ) else ( l := l + 1 ) ) else skip ; if idxOneR = null then ( if bookshelf[r+1] = 1 then ( var idxOneR : OclAny := r ) else ( r := r - 1 ) ) else skip)) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=input() b=input() ans=0 for i in range(0,n): ans=ans+min(10-abs(int(a[i])-int(b[i])),abs(int(a[i])-int(b[i]))) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( ans := ans + Set{10 - (("" + ((a[i+1])))->toInteger() - ("" + ((b[i+1])))->toInteger())->abs(), (("" + ((a[i+1])))->toInteger() - ("" + ((b[i+1])))->toInteger())->abs()}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s1=input() s2=input() s=0 for i in range(n): s+=min(abs(int(s1[i])-int(s2[i])),abs(10-abs(int(s1[i])-int(s2[i])))) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s1 : String := (OclFile["System.in"]).readLine() ; var s2 : String := (OclFile["System.in"]).readLine() ; var s : int := 0 ; for i : Integer.subrange(0, n-1) do ( s := s + Set{(("" + ((s1[i+1])))->toInteger() - ("" + ((s2[i+1])))->toInteger())->abs(), (10 - (("" + ((s1[i+1])))->toInteger() - ("" + ((s2[i+1])))->toInteger())->abs())->abs()}->min()) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,list(input()))) b=list(map(int,list(input()))) count=0 for x,y in zip(a,b): if x<=y : diff=min(y-x,10+x-y) else : diff=min(x-y,10+y-x) count+=diff print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((((OclFile["System.in"]).readLine())->characters())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((((OclFile["System.in"]).readLine())->characters())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : int := 0 ; for _tuple : Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), b->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if (x->compareTo(y)) <= 0 then ( var diff : OclAny := Set{y - x, 10 + x - y}->min() ) else ( diff := Set{x - y, 10 + y - x}->min() ) ; count := count + diff) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) str1=input() str2=input() i=0 total_dif=0 while itoInteger() ; var str1 : String := (OclFile["System.in"]).readLine() ; var str2 : String := (OclFile["System.in"]).readLine() ; var i : int := 0 ; var total_dif : int := 0 ; while (i->compareTo(n)) < 0 do ( var digit1 : int := ("" + ((str1[i+1])))->toInteger() ; var digit2 : int := ("" + ((str2[i+1])))->toInteger() ; total_dif := total_dif + Set{(digit1 - digit2)->abs(), Set{(10 - digit1 + digit2), (10 - digit2 + digit1)}->min()}->min() ; i := i + 1) ; execute (total_dif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input(); print(sum(min(abs(x-y),10-abs(x-y))for x,y in zip(map(int,input()),map(int,input())))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input(); execute (((argument (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (name y))))))))) )))))))) , (argument (test (logical_test (comparison (expr (expr (atom (number (integer 10)))) - (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (name y))))))))) )))))))))) ))))))) (comp_for for (exprlist (expr (atom (name x))) , (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))) )))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=32 pow2=[0 for i in range(MAX)] visited=[False for i in range(MAX)] ans=[] def power_2(): an=1 for i in range(MAX): pow2[i]=an an*=2 def countSetBits(x): setBits=0 while(x!=0): x=x &(x-1) setBits+=1 return setBits def add(num): point=0 value=0 for i in range(MAX): if(visited[i]): continue else : if(num & 1): value+=(1<select(i | true)->collect(i | (0)) ; var visited : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (false)) ; var ans : Sequence := Sequence{} ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( n := 3 ; k := 5 ; power()() ; solve(n, k) ) else skip; operation power var an : int := 1 ; for i : Integer.subrange(0, MAX-1) do ( pow2[i+1] := an ; an := an * 2)() pre: true post: true activity: var an : int := 1 ; for i : Integer.subrange(0, MAX-1) do ( pow2[i+1] := an ; an := an * 2); operation countSetBits(x : OclAny) : OclAny pre: true post: true activity: var setBits : int := 0 ; while (x /= 0) do ( x := MathLib.bitwiseAnd(x, (x - 1)) ; setBits := setBits + 1) ; return setBits; operation add(num : OclAny) pre: true post: true activity: var point : int := 0 ; var value : int := 0 ; for i : Integer.subrange(0, MAX-1) do ( if (visited[i+1]) then ( continue ) else ( if (MathLib.bitwiseAnd(num, 1)) then ( value := value + (1 * (2->pow(i))) ) else skip ; num := num div 2 )) ; execute ((value) : ans); operation solve(n : OclAny, k : OclAny) pre: true post: true activity: execute ((k) : ans) ; var countk : OclAny := countSetBits(k) ; if ((pow2[countk+1]->compareTo(n)) < 0) then ( execute (-1)->display() ; return ) else skip ; var count : int := 0 ; for i : Integer.subrange(0, pow2[countk+1] - 1-1) do ( add(i) ; count := count + 1 ; if (count = n) then ( break ) else skip) ; for i : Integer.subrange(0, n-1) do ( execute (ans[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys x,y=map(int,input().split()) n=int(input()) if(n % 6==1): print(x % 1000000007) if(n % 6==2): print(y % 1000000007) if(n % 6==3): print((y-x)% 1000000007) if(n % 6==4): print((-x)% 1000000007) if(n % 6==5): print((-y)% 1000000007) if(n % 6==0): print((x-y)% 1000000007) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n mod 6 = 1) then ( execute (x mod 1000000007)->display() ) else skip ; if (n mod 6 = 2) then ( execute (y mod 1000000007)->display() ) else skip ; if (n mod 6 = 3) then ( execute ((y - x) mod 1000000007)->display() ) else skip ; if (n mod 6 = 4) then ( execute ((-x) mod 1000000007)->display() ) else skip ; if (n mod 6 = 5) then ( execute ((-y) mod 1000000007)->display() ) else skip ; if (n mod 6 = 0) then ( execute ((x - y) mod 1000000007)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib,itertools def compute(): ans=max(((a,b)for a in range(-999,1000)for b in range(2,1000)),key=count_consecutive_primes) return str(ans[0]*ans[1]) def count_consecutive_primes(ab): a,b=ab for i in itertools.count(): n=i*i+i*a+b if not is_prime(n): return i isprimecache=eulerlib.list_primality(1000) def is_prime(n): if n<0 : return False elif ndisplay() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : OclAny := Set{Sequence{(testlist_comp (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name b))))))) )))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 999)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1000))))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1000))))))))) ))))))))))}, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name count_consecutive_primes)))))))}->max() ; return ("" + ((ans->first() * ans[1+1]))); operation count_consecutive_primes(ab : OclAny) : OclAny pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ab ; for i : itertools->count() do ( var n : double := i * i + i * a + b ; if not(is_prime(n)) then ( return i ) else skip); operation is_prime(n : OclAny) : OclAny pre: true post: true activity: if n < 0 then ( return false ) else (if (n->compareTo((isprimecache)->size())) < 0 then ( return isprimecache[n+1] ) else ( return eulerlib.is_prime(n) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for pratyush in range(int(input())): n,r=map(int,input().split()) a=min(r,n-1) ans=int((a*(a+1))//2) if a!=r : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for pratyush : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var r : OclAny := null; Sequence{n,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := Set{r, n - 1}->min() ; var ans : int := ("" + (((a * (a + 1)) div 2)))->toInteger() ; if a /= r then ( ans := ans + 1 ) else skip ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: n,r=map(int,s.split()); print((n*n-n+2,r*r+r)[n>r]//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var n : OclAny := null; var r : OclAny := null; Sequence{n,r} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ); execute (Sequence{n * n - n + 2, r * r + r}->select((n->compareTo(r)) > 0) div 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys I=lambda :[*map(int,sys.stdin.readline().split())] t,=I() for _ in range(t): n,r=I() k=min(r,n-1) print(k*(k+1)//2+(r>=n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var I : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := I->apply() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var r : OclAny := null; Sequence{n,r} := I->apply() ; var k : OclAny := Set{r, n - 1}->min() ; execute (k * (k + 1) div 2 + ((r->compareTo(n)) >= 0))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin nii=lambda : map(int,stdin.readline().split()) class UnionFind(): def __init__(self,n): self.n=n self.parents=[-1]*n def find(self,x): if self.parents[x]<0 : return x else : self.parents[x]=self.find(self.parents[x]) return self.parents[x] def union(self,x,y): x=self.find(x) y=self.find(y) if x==y : return if self.parents[x]>self.parents[y]: x,y=y,x self.parents[x]+=self.parents[y] self.parents[y]=x def same(self,x,y): return self.find(x)==self.find(y) n,m=nii() p=list(nii()) uf=UnionFind(n) for i in range(m): x,y=nii() x-=1 y-=1 uf.union(x,y) cnt=0 for i in range(n): if not uf.same(i,p[i]-1): cnt+=1 print(n-cnt) ------------------------------------------------------------ OCL File: --------- class UnionFind { static operation newUnionFind() : UnionFind pre: true post: UnionFind->exists( _x | result = _x ); attribute n : OclAny := n; attribute parents : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n); operation initialise(n : OclAny) : pre: true post: true activity: self.n := n ; self.parents := MatrixLib.elementwiseMult(Sequence{ -1 }, n); return self; operation find(x : OclAny) : OclAny pre: true post: true activity: if self.parents[x+1] < 0 then ( return x ) else ( self.parents[x+1] := self->indexOf(self.parents[x+1]) - 1 ; return self.parents[x+1] ); operation union(x : OclAny,y : OclAny) pre: true post: true activity: x := self->indexOf(x) - 1 ; y := self->indexOf(y) - 1 ; if x = y then ( return ) else skip ; if (self.parents[x+1]->compareTo(self.parents[y+1])) > 0 then ( Sequence{x,y} := Sequence{y,x} ) else skip ; self.parents[x+1] := self.parents[x+1] + self.parents[y+1] ; self.parents[y+1] := x; operation same(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: return self->indexOf(x) - 1 = self->indexOf(y) - 1; } class FromPython { operation initialise() pre: true post: true activity: skip ; var nii : Function := lambda $$ : OclAny in ((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; var m : OclAny := null; Sequence{n,m} := nii->apply() ; var p : Sequence := (nii->apply()) ; var uf : UnionFind := (UnionFind.newUnionFind()).initialise(n) ; for i : Integer.subrange(0, m-1) do ( Sequence{x,y} := nii->apply() ; x := x - 1 ; y := y - 1 ; uf.union(x, y)) ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( if not(uf.same(i, p[i+1] - 1)) then ( cnt := cnt + 1 ) else skip) ; execute (n - cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) print(input().strip("0 ").count("0")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (input()->trim()->count("0"))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: n,r=map(int,s.split()); print((n*n-n+2,r*r+r)[n>r]//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var n : OclAny := null; var r : OclAny := null; Sequence{n,r} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ); execute (Sequence{n * n - n + 2, r * r + r}->select((n->compareTo(r)) > 0) div 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: n,r=map(int,s.split()); print((n*n-n+2,r*r+r)[n>r]//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var n : OclAny := null; var r : OclAny := null; Sequence{n,r} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ); execute (Sequence{n * n - n + 2, r * r + r}->select((n->compareTo(r)) > 0) div 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt MAX=100001 isPrime=[0 for i in range(MAX)] def sieve(): for p in range(2,mt.ceil(mt.sqrt(MAX))): if(isPrime[p]==0): for i in range(2*p,MAX,p): isPrime[i]=1 def findSubset(a,n): cnt1=0 for i in range(n): if(a[i]==1): cnt1+=1 if(cnt1>0): for i in range(n): if((a[i]!=1)and(isPrime[a[i]+1]==0)): print(cnt1+1) for j in range(cnt1): print("1",end=" ") print(a[i]) return 0 if(cnt1>=2): print(cnt1) for i in range(cnt1): print("1",end=" ") print("\n") return 0 for i in range(n): for j in range(i+1,n): if(isPrime[a[i]+a[j]]==0): print(2) print(a[i]," ",a[j]) print(-1) sieve() A=[2,1,1] n=len(A) findSubset(A,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MAX : int := 100001 ; var isPrime : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)) ; skip ; skip ; sieve() ; var A : Sequence := Sequence{2}->union(Sequence{1}->union(Sequence{ 1 })) ; n := (A)->size() ; findSubset(A, n); operation sieve() pre: true post: true activity: for p : Integer.subrange(2, mt.ceil(mt.sqrt(MAX))-1) do ( if (isPrime[p+1] = 0) then ( for i : Integer.subrange(2 * p, MAX-1)->select( $x | ($x - 2 * p) mod p = 0 ) do ( isPrime[i+1] := 1) ) else skip); operation findSubset(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var cnt1 : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] = 1) then ( cnt1 := cnt1 + 1 ) else skip) ; if (cnt1 > 0) then ( for i : Integer.subrange(0, n-1) do ( if ((a[i+1] /= 1) & (isPrime[a[i+1] + 1+1] = 0)) then ( execute (cnt1 + 1)->display() ; for j : Integer.subrange(0, cnt1-1) do ( execute ("1")->display()) ; execute (a[i+1])->display() ; return 0 ) else skip) ) else skip ; if (cnt1 >= 2) then ( execute (cnt1)->display() ; for i : Integer.subrange(0, cnt1-1) do ( execute ("1")->display()) ; execute ("\n")->display() ; return 0 ) else skip ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if (isPrime[a[i+1] + a[j+1]+1] = 0) then ( execute (2)->display() ; execute (a[i+1])->display() ) else skip)) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,r,t=map(int,input().split()) speed=[int(input())for _ in range(n)] point=[0]*n bottle=[0]*r for i in range(n): point[i]=(point[i]+speed[i])% r bottle[point[i]]+=1 for _ in range(t-1): nums=[0]*r for i in range(n): bottle[point[i]]-=1 point[i]=(point[i]+speed[i])% r nums[point[i]]+=1 for i in range(r): if bottle[i]collect( _x | (OclType["int"])->apply(_x) ) ; var speed : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var point : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var bottle : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, r) ; for i : Integer.subrange(0, n-1) do ( point[i+1] := (point[i+1] + speed[i+1]) mod r ; bottle[point[i+1]+1] := bottle[point[i+1]+1] + 1) ; for _anon : Integer.subrange(0, t - 1-1) do ( var nums : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, r) ; for i : Integer.subrange(0, n-1) do ( bottle[point[i+1]+1] := bottle[point[i+1]+1] - 1 ; point[i+1] := (point[i+1] + speed[i+1]) mod r ; nums[point[i+1]+1] := nums[point[i+1]+1] + 1) ; for i : Integer.subrange(0, r-1) do ( if (bottle[i+1]->compareTo(nums[i+1])) < 0 then ( bottle[i+1] := nums[i+1] ) else skip ; bottle[i+1] := bottle[i+1] + nums[i+1])) ; execute ((bottle)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=map(int,input().split()) n=int(input()) a=[x,y,y-x,-x,-y,x-y] print(a[(n-1)% 6]% 1000000007) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{x}->union(Sequence{y}->union(Sequence{y - x}->union(Sequence{-x}->union(Sequence{-y}->union(Sequence{ x - y }))))) ; execute (a[(n - 1) mod 6+1] mod 1000000007)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy from test.support import _MemoryWatchdog BIG_NUM=2000000000 HUGE_NUM=99999999999999999 MOD=1000000007 EPS=0.000000001 sys.setrecursionlimit(100000) N,LEN,LIMIT=map(int,input().split()) speed=[None]*N loc=[None]*N num_fill=[0]*LEN num_empty=[0]*LEN ans=N for i in range(N): speed[i]=int(input()) loc[i]=speed[i] for current in range(2,LIMIT+1): for i in range(LEN): num_fill[i]+=num_empty[i] num_empty[i]=0 for i in range(N): loc[i]+=speed[i] loc[i]%=LEN num_empty[loc[i]]+=1 if num_fill[loc[i]]>0 : num_fill[loc[i]]-=1 else : ans+=1 print("%d" %(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var HUGE_NUM : int := 99999999999999999 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; sys.setrecursionlimit(100000) ; var N : OclAny := null; var LEN : OclAny := null; var LIMIT : OclAny := null; Sequence{N,LEN,LIMIT} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var speed : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, N) ; var loc : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, N) ; var num_fill : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, LEN) ; var num_empty : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, LEN) ; var ans : OclAny := N ; for i : Integer.subrange(0, N-1) do ( speed[i+1] := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; loc[i+1] := speed[i+1]) ; for current : Integer.subrange(2, LIMIT + 1-1) do ( for i : Integer.subrange(0, LEN-1) do ( num_fill[i+1] := num_fill[i+1] + num_empty[i+1] ; num_empty[i+1] := 0) ; for i : Integer.subrange(0, N-1) do ( loc[i+1] := loc[i+1] + speed[i+1] ; loc[i+1] := loc[i+1] mod LEN ; num_empty[loc[i+1]+1] := num_empty[loc[i+1]+1] + 1 ; if num_fill[loc[i+1]+1] > 0 then ( num_fill[loc[i+1]+1] := num_fill[loc[i+1]+1] - 1 ) else ( ans := ans + 1 ))) ; execute (StringLib.format("%d",(ans)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): print(input().replace('Hoshino','Hoshina')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( execute (input().replace('Hoshino', 'Hoshina'))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(data): result=data.replace('Hoshino','Hoshina') return result def main(args): num=int(input()) for _ in range(num): data=input() result=solve(data) print(result) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(data : OclAny) : OclAny pre: true post: true activity: var result : String := data.replace('Hoshino', 'Hoshina') ; return result; operation main(args : OclAny) pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, num-1) do ( data := (OclFile["System.in"]).readLine() ; result := solve(data) ; execute (result)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- [print(input().replace('Hoshino','Hoshina'))for _ in range(int(input()))] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") N=int(input()) for _ in range(N): print(input().replace("Hoshino","Hoshina")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, N-1) do ( execute (input().replace("Hoshino", "Hoshina"))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() try : while True : str=input() print(str.replace("Hoshino","Hoshina")) except EOFError : pass ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; try ( while true do ( var OclType["String"] : String := (OclFile["System.in"]).readLine() ; execute (("" + (.replace("Hoshino", "Hoshina"))))->display())) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt pass))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for j in range(t): input() a=input() first=a.index("1") last=a.rindex("1") a=a[first : last+1] print(a.count("0")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, t-1) do ( input() ; var a : String := (OclFile["System.in"]).readLine() ; var first : int := a->indexOf("1") - 1 ; var last : OclAny := a.rindex("1") ; a := a.subrange(first+1, last + 1) ; execute (a->count("0"))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countRotations(arr,low,high): if(highlow and arr[mid]arr[mid]): return countRotations(arr,low,mid-1); return countRotations(arr,mid+1,high) arr=[15,18,2,3,6,12] n=len(arr) print(countRotations(arr,0,n-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{15}->union(Sequence{18}->union(Sequence{2}->union(Sequence{3}->union(Sequence{6}->union(Sequence{ 12 }))))) ; var n : int := (arr)->size() ; execute (countRotations(arr, 0, n - 1))->display(); operation countRotations(arr : OclAny, low : OclAny, high : OclAny) : OclAny pre: true post: true activity: if ((high->compareTo(low)) < 0) then ( return 0 ) else skip ; if (high = low) then ( return low ) else skip ; var mid : OclAny := low + (high - low) / 2; ; mid := ("" + ((mid)))->toInteger() ; if ((mid->compareTo(high)) < 0 & (arr[mid + 1+1]->compareTo(arr[mid+1])) < 0) then ( return (mid + 1) ) else skip ; if ((mid->compareTo(low)) > 0 & (arr[mid+1]->compareTo(arr[mid - 1+1])) < 0) then ( return mid ) else skip ; if ((arr[high+1]->compareTo(arr[mid+1])) > 0) then ( return countRotations(arr, low, mid - 1); ) else skip ; return countRotations(arr, mid + 1, high); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,m=map(int,input().split()) i=0 while True : if i+1>m : ans=m break m-=i+1 i+=1 i %=n print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var i : int := 0 ; while true do ( if (i + 1->compareTo(m)) > 0 then ( var ans : OclAny := m ; break ) else skip ; m := m - i + 1 ; i := i + 1 ; i := i mod n) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() s=s.split() a=int(s[0]) b=int(s[1]) b %=(a+1)*a/2 for i in range(1,a+1): if bfirst())))->toInteger() ; var b : int := ("" + ((s[1+1])))->toInteger() ; b := b mod (a + 1) * a / 2 ; for i : Integer.subrange(1, a + 1-1) do ( if (b->compareTo(i)) < 0 then ( execute (("" + ((b)))->toInteger())->display() ; exit(0) ) else ( b := b - i )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printArray(N,arr): for i in range(0,N): print(arr[i],end=" ") print() def replacedArray(N,arr): pos_sum=0 neg_sum=0 for i in range(N-1,-1,-1): diff=abs(pos_sum)-abs(neg_sum) if(arr[i]>0): pos_sum=pos_sum+arr[i] else : neg_sum=neg_sum+arr[i] arr[i]=abs(diff) N=5 arr=[1,-1,2,3,-2] replacedArray(N,arr) printArray(N,arr) N=6 arr1=[-3,-4,-2,5,1,-2] replacedArray(N,arr1) printArray(N,arr1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; N := 5 ; arr := Sequence{1}->union(Sequence{-1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ -2 })))) ; replacedArray(N, arr) ; printArray(N, arr) ; N := 6 ; var arr1 : Sequence := Sequence{-3}->union(Sequence{-4}->union(Sequence{-2}->union(Sequence{5}->union(Sequence{1}->union(Sequence{ -2 }))))) ; replacedArray(N, arr1) ; printArray(N, arr1); operation printArray(N : OclAny, arr : OclAny) pre: true post: true activity: for i : Integer.subrange(0, N-1) do ( execute (arr[i+1])->display()) ; execute (->display(); operation replacedArray(N : OclAny, arr : OclAny) pre: true post: true activity: var pos_sum : int := 0 ; var neg_sum : int := 0 ; for i : Integer.subrange(-1 + 1, N - 1)->reverse() do ( var diff : double := (pos_sum)->abs() - (neg_sum)->abs() ; if (arr[i+1] > 0) then ( pos_sum := pos_sum + arr[i+1] ) else ( neg_sum := neg_sum + arr[i+1] ) ; arr[i+1] := (diff)->abs()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) x=1 while True : if mn : x=1 print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : int := 1 ; while true do ( if (m->compareTo(x)) < 0 then ( break ) else skip ; m := m - x ; x := x + 1 ; if (x->compareTo(n)) > 0 then ( x := 1 ) else skip) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) i=1 while m>=i : m-=i i=(i % n)+1 print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var i : int := 1 ; while (m->compareTo(i)) >= 0 do ( m := m - i ; i := (i mod n) + 1) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) lis=[] for i in range(1,n+1): lis.append(i) i=0 c=0 while True : while icollect( _x | (OclType["int"])->apply(_x) ) ; var lis : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( execute ((i) : lis)) ; var i : int := 0 ; var c : int := 0 ; while true do ( while (i->compareTo((lis)->size())) < 0 do ( if (m->compareTo(lis[i+1])) < 0 then ( c := c + 1 ; break ) else skip ; var m : double := m - lis[i+1] ; i := i + 1) ; i := 0 ; if c = 1 then ( break ) else skip) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def modularSum(arr,n,m): if(n>m): return True DP=[False for i in range(m)] for i in range(n): if(DP[0]): return True temp=[False for i in range(m)] for j in range(m): if(DP[j]==True): if(DP[(j+arr[i])% m]==False): temp[(j+arr[i])% m]=True for j in range(m): if(temp[j]): DP[j]=True DP[arr[i]% m]=True return DP[0] arr=[1,7] n=len(arr) m=5 print("YES")if(modularSum(arr,n,m))else print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{ 7 }) ; n := (arr)->size() ; m := 5 ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))) if (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name modularSum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr))))))) , (argument (test (logical_test (comparison (expr (atom (name n))))))) , (argument (test (logical_test (comparison (expr (atom (name m)))))))) )))))))) ))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))); operation modularSum(arr : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: if ((n->compareTo(m)) > 0) then ( return true ) else skip ; var DP : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (false)) ; for i : Integer.subrange(0, n-1) do ( if (DP->first()) then ( return true ) else skip ; var temp : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (false)) ; for j : Integer.subrange(0, m-1) do ( if (DP[j+1] = true) then ( if (DP[(j + arr[i+1]) mod m+1] = false) then ( temp[(j + arr[i+1]) mod m+1] := true ) else skip ) else skip) ; for j : Integer.subrange(0, m-1) do ( if (temp[j+1]) then ( DP[j+1] := true ) else skip) ; DP[arr[i+1] mod m+1] := true) ; return DP->first(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) q=int(input()) for i in range(q): b,e,k=list(map(int,input().split())) print(a[b : e].count(k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( var b : OclAny := null; var e : OclAny := null; var k : OclAny := null; Sequence{b,e,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (a.subrange(b+1, e)->count(k))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : num_int=int(input()) numbers=list(map(lambda x : int(x),input().split())) num_query=int(input()) for _ in range(num_query): begin,end,num=map(lambda x : int(x),input().split()) count=0 for elem in numbers[begin : end]: if(elem==num): count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var num_int : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var numbers : Sequence := ((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) )) ; var num_query : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, num_query-1) do ( var begin : OclAny := null; var end : OclAny := null; var num : OclAny := null; Sequence{begin,end,num} := (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ) ; var count : int := 0 ; for elem : numbers.subrange(begin+1, end) do ( if (elem = num) then ( count := count + 1 ) else skip) ; execute (count)->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=[*map(int,input().split())] q=int(input()) while q : q-=1 l,r,k=map(int,input().split()) print(arr[l : r].count(k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while q do ( q := q - 1 ; var l : OclAny := null; var r : OclAny := null; var k : OclAny := null; Sequence{l,r,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (arr.subrange(l+1, r)->count(k))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: print(s.strip('0 \n').count('0')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( execute (s->trim()->count('0'))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() nums=list(map(int,input().split(' '))) r=input() for _ in range(int(r)): f,l,v=list(map(int,input().split(' '))) print(nums[f : l].count(v)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var nums : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var r : String := (OclFile["System.in"]).readLine() ; for _anon : Integer.subrange(0, ("" + ((r)))->toInteger()-1) do ( var f : OclAny := null; var l : OclAny := null; var v : OclAny := null; Sequence{f,l,v} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; execute (nums.subrange(f+1, l)->count(v))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) A=list(map(int,input().split())) q=int(input()) def counta(b,e,k): B=A[b : e] print(B.count(k)) for i in range(q): queryi=list(map(int,input().split())) counta(queryi[0],queryi[1],queryi[2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; for i : Integer.subrange(0, q-1) do ( var queryi : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; counta(queryi->first(), queryi[1+1], queryi[2+1])); operation counta(b : OclAny, e : OclAny, k : OclAny) pre: true post: true activity: var B : OclAny := A.subrange(b+1, e) ; execute (B->count(k))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): a,b=map(int,input().split()) n=int(input()) arr=[a,b] for _ in range(14): arr.append(arr[-1]-arr[-2]) c=b-a a=b b=c print(arr[(n-1)% 6]%(10**9+7)) def main(): t=1 for _ in range(t): solution() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; main(); operation solution() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Sequence{a}->union(Sequence{ b }) ; for _anon : Integer.subrange(0, 14-1) do ( execute ((arr->last() - arr->front()->last()) : arr) ; var c : double := b - a ; var a : OclAny := b ; var b : OclAny := c) ; execute (arr[(n - 1) mod 6+1] mod ((10)->pow(9) + 7))->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,x=map(int,input().split()) A=list(map(int,input().split())) INF=(1<<42)-1 cum=[[INF]*N for _ in range(N)] for i in range(N): for j in range(i,N): cum[i][j]=min(cum[i][j-1],A[j]) ans=INF for k in range(N): score=0 for j in range(N): if j-k>=0 : score+=cum[j-k][j] else : score+=min(cum[0][j],cum[(j-k)% N][-1]) ans=min(ans,k*x+score) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var x : OclAny := null; Sequence{N,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var INF : double := (1 * (2->pow(42))) - 1 ; var cum : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ INF }, N))) ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(i, N-1) do ( cum[i+1][j+1] := Set{cum[i+1][j - 1+1], A[j+1]}->min())) ; var ans : OclAny := INF ; for k : Integer.subrange(0, N-1) do ( var score : int := 0 ; for j : Integer.subrange(0, N-1) do ( if j - k >= 0 then ( score := score + cum[j - k+1][j+1] ) else ( score := score + Set{cum->first()[j+1], cum[(j - k) mod N+1]->last()}->min() )) ; ans := Set{ans, k * x + score}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import queue from collections import deque,defaultdict import heapq as hpq from sys import stdin,setrecursionlimit ipt=stdin.readline setrecursionlimit(10**7) def main(): n,x=map(int,ipt().split()) a=[int(i)for i in ipt().split()] pm=a*1 mi=sum(a) for i in range(1,n): mii=x*i pp=pm*1 for j in range(n): pm[n-1-j]=min(pp[n-1-j],a[n-1-j-i]) mii+=pm[n-1-j] if mi>mii : mi=mii print(mi) return if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var ipt : OclAny := stdin.readline ; setrecursionlimit((10)->pow(7)) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (ipt().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ipt().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var pm : Sequence := MatrixLib.elementwiseMult(a, 1) ; var mi : OclAny := (a)->sum() ; for i : Integer.subrange(1, n-1) do ( var mii : double := x * i ; var pp : Sequence := MatrixLib.elementwiseMult(pm, 1) ; for j : Integer.subrange(0, n-1) do ( pm[n - 1 - j+1] := Set{pp[n - 1 - j+1], a[n - 1 - j - i+1]}->min() ; mii := mii + pm[n - 1 - j+1]) ; if (mi->compareTo(mii)) > 0 then ( mi := mii ) else skip) ; execute (mi)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,x,*A=map(int,open(0).read().split()) ans=float("inf") for i in range(N): ans=min(ans,sum(A)+x*i) A=[min(a,b)for a,b in zip(A,[A[-1]]+A[:-1])] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var x : OclAny := null; var A : OclAny := null; Sequence{N,x,A} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : double := ("" + (("inf")))->toReal() ; for i : Integer.subrange(0, N-1) do ( ans := Set{ans, (A)->sum() + x * i}->min() ; var A : Sequence := Integer.subrange(1, A->size())->collect( _indx | Sequence{A->at(_indx), Sequence{ A->last() }->union(A->front())->at(_indx)} )->select(_tuple | true)->collect(_tuple | let a : OclAny = _tuple->at(1) in let b : OclAny = _tuple->at(2) in (Set{a, b}->min()))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def segfunc(x,y): return min(x,y) ide_ele=10**18 class segtree(): def __init__(self,init_val,segfunc,ide_ele): n=len(init_val) self.segfunc=segfunc self.ide_ele=ide_ele self.num=1<<(n-1).bit_length() self.tree=[ide_ele]*2*self.num for i in range(n): self.tree[self.num+i]=init_val[i] for i in range(self.num-1,0,-1): self.tree[i]=self.segfunc(self.tree[2*i],self.tree[2*i+1]) def query(self,l,r): res=self.ide_ele l+=self.num r+=self.num+1 while l>=1 r>>=1 return res n,x=map(int,input().split()) a=list(map(int,input().split())) a+=a st=segtree(a,segfunc,ide_ele) ans=10**18 for k in range(n): cnt=k*x for i in range(n): cnt+=st.query(i,i+k) ans=min(ans,cnt) print(ans) ------------------------------------------------------------ OCL File: --------- class segtree { static operation newsegtree() : segtree pre: true post: segtree->exists( _x | result = _x ); attribute segfunc : OclAny := segfunc; attribute ide_ele : OclAny := ide_ele; attribute num : int := 1 * (2->pow((n - 1).bit_length())); attribute tree : Sequence := MatrixLib.elementwiseMult(MatrixLib.elementwiseMult(Sequence{ ide_ele }, 2), self.num); operation initialise(init_val : OclAny,segfunc : OclAny,ide_ele : OclAny) : pre: true post: true activity: var n : int := (init_val)->size() ; self.segfunc := segfunc ; self.ide_ele := ide_ele ; self.num := 1 * (2->pow((n - 1).bit_length())) ; self.tree := MatrixLib.elementwiseMult(MatrixLib.elementwiseMult(Sequence{ ide_ele }, 2), self.num) ; for i : Integer.subrange(0, n-1) do ( self.tree[self.num + i+1] := init_val[i+1]) ; for i : Integer.subrange(0 + 1, self.num - 1)->reverse() do ( self.tree[i+1] := self.segfunc(self.tree[2 * i+1], self.tree[2 * i + 1+1])); return self; operation query(l : OclAny,r : OclAny) : OclAny pre: true post: true activity: var res : OclAny := self.ide_ele ; l := l + self.num ; r := r + self.num + 1 ; while (l->compareTo(r)) < 0 do ( if MathLib.bitwiseAnd(l, 1) then ( res := self.segfunc(res, self.tree[l+1]) ; l := l + 1 ) else skip ; if MathLib.bitwiseAnd(r, 1) then ( res := self.segfunc(res, self.tree[r - 1+1]) ) else skip ; l := l div (2->pow(1)) ; r := r div (2->pow(1))) ; return res; } class FromPython { operation initialise() pre: true post: true activity: skip ; var ide_ele : double := (10)->pow(18) ; skip ; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a + a ; var st : segtree := (segtree.newsegtree()).initialise(a, segfunc, ide_ele) ; var ans : double := (10)->pow(18) ; for k : Integer.subrange(0, n-1) do ( var cnt : double := k * x ; for i : Integer.subrange(0, n-1) do ( cnt := cnt + st.query(i, i + k)) ; ans := Set{ans, cnt}->min()) ; execute (ans)->display(); operation segfunc(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return Set{x, y}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,x=map(int,input().split()) a=list(map(int,input().split())) b=[[None for _ in[0]*n]for _ in[0]*n] for i in range(n): m=a[i] for j in range(n): k=i-j if k<0 : k+=n m=min(m,a[k]) b[j][i]=m m=10**15 for i,j in enumerate(b): m=min(m,sum(j)+x*i) print(m) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, n)->select(_anon | true)->collect(_anon | (null)))) ; for i : Integer.subrange(0, n-1) do ( var m : OclAny := a[i+1] ; for j : Integer.subrange(0, n-1) do ( var k : double := i - j ; if k < 0 then ( k := k + n ) else skip ; m := Set{m, a[k+1]}->min() ; b[j+1][i+1] := m)) ; m := (10)->pow(15) ; for _tuple : Integer.subrange(1, (b)->size())->collect( _indx | Sequence{_indx-1, (b)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); m := Set{m, (j)->sum() + x * i}->min()) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : d,w=map(int,input().split()) if d+w==0 : break pond=[list(map(int,input().split()))for _ in range(d)] ans=0 for left in range(w-1): for right in range(w-1,left+1,-1): for top in range(d-1): for under in range(d-1,top+1,-1): outh=10 outh=min(outh,min(pond[top][left : right+1])) outh=min(outh,min(pond[under][left : right+1])) zpond=list(zip(*pond)) outh=min(outh,min(zpond[left][top : under])) outh=min(outh,min(zpond[right][top : under])) pondh=0 for i in range(top+1,under): pondh=max(pondh,max(pond[i][left+1 : right])) if pondhcollect( _x | (OclType["int"])->apply(_x) ) ; if d + w = 0 then ( break ) else skip ; var pond : Sequence := Integer.subrange(0, d-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ans : int := 0 ; for left : Integer.subrange(0, w - 1-1) do ( for right : Integer.subrange(left + 1 + 1, w - 1)->reverse() do ( for top : Integer.subrange(0, d - 1-1) do ( for under : Integer.subrange(top + 1 + 1, d - 1)->reverse() do ( var outh : int := 10 ; outh := Set{outh, (pond[top+1].subrange(left+1, right + 1))->min()}->min() ; outh := Set{outh, (pond[under+1].subrange(left+1, right + 1))->min()}->min() ; var zpond : Sequence := (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name pond)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name pond)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name pond)))))))`third->at(_indx)} )) ; outh := Set{outh, (zpond[left+1].subrange(top+1, under))->min()}->min() ; outh := Set{outh, (zpond[right+1].subrange(top+1, under))->min()}->min() ; var pondh : int := 0 ; for i : Integer.subrange(top + 1, under-1) do ( pondh := Set{pondh, (pond[i+1].subrange(left + 1+1, right))->max()}->max()) ; if (pondh->compareTo(outh)) < 0 then ( var cap : double := outh * (under - top - 1) * (right - left - 1) - ((argument (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name pond)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name left))) + (expr (atom (number (integer 1)))))))) : (test (logical_test (comparison (expr (atom (name right)))))))) ])))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name top))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name under)))))))) )))))))))->sum() ; ans := Set{cap, ans}->max() ) else skip)))) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools def rdp_connect()->bool : global h,w,e h,w=map(int,input().split()) if h==0 and w==0 : return False e=[list(map(int,input().split()))for _ in range(h)] return True def rdp_scan(x1 : int,y1 : int,x2 : int,y2 : int)->int : edges=[] edges.extend([e[j][x1]for j in range(y1,y2+1)]) edges.extend([e[j][x2]for j in range(y1,y2+1)]) edges.extend([e[y1][i]for i in range(x1+1,x2)]) edges.extend([e[y2][i]for i in range(x1+1,x2)]) inner=[e[j][i]for j,i in itertools.product(range(y1+1,y2),range(x1+1,x2))] edges_min=min(edges) if edges_min-max(inner)<=0 : return 0 return sum(map(lambda e : edges_min-e,inner)) if __name__=='__main__' : while rdp_connect(): best=0 for y1,x1 in itertools.product(range(h),range(w)): for y2,x2 in itertools.product(range(y1+2,h),range(x1+2,w)): best=max(best,rdp_scan(x1,y1,x2,y2)) print(best) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute h : OclAny; attribute w : OclAny; attribute e : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( while rdp_connect() do ( var best : int := 0 ; for _tuple : itertools.product(Integer.subrange(0, h-1), Integer.subrange(0, w-1)) do (var _indx : int := 1; var y1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x1 : OclAny := _tuple->at(_indx); for _tuple : itertools.product(Integer.subrange(y1 + 2, h-1), Integer.subrange(x1 + 2, w-1)) do (var _indx : int := 1; var y2 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x2 : OclAny := _tuple->at(_indx); best := Set{best, rdp_scan(x1, y1, x2, y2)}->max())) ; execute (best)->display()) ) else skip; operation rdp_connect() : boolean pre: true post: true activity: skip; skip; skip ; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if h = 0 & w = 0 then ( return false ) else skip ; e := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; return true; operation rdp_scan(x1 : int, y1 : int, x2 : int, y2 : int) : int pre: true post: true activity: var edges : Sequence := Sequence{} ; edges := edges->union(Integer.subrange(y1, y2 + 1-1)->select(j | true)->collect(j | (e[j+1][x1+1]))) ; edges := edges->union(Integer.subrange(y1, y2 + 1-1)->select(j | true)->collect(j | (e[j+1][x2+1]))) ; edges := edges->union(Integer.subrange(x1 + 1, x2-1)->select(i | true)->collect(i | (e[y1+1][i+1]))) ; edges := edges->union(Integer.subrange(x1 + 1, x2-1)->select(i | true)->collect(i | (e[y2+1][i+1]))) ; var inner : Sequence := itertools.product(Integer.subrange(y1 + 1, y2-1), Integer.subrange(x1 + 1, x2-1))->select(_tuple | true)->collect(_tuple | let j : OclAny = _tuple->at(1) in let i : OclAny = _tuple->at(2) in (e[j+1][i+1])) ; var edges_min : OclAny := (edges)->min() ; if edges_min - (inner)->max() <= 0 then ( return 0 ) else skip ; return ((inner)->collect( _x | (lambda e : OclAny in (edges_min - e))->apply(_x) ))->sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from itertools import permutations,combinations,product def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def LIST(): return list(map(int,input().split())) def MAP(): return map(int,input().split()) ans=[] while 1 : d,w=MAP() if d==0 and w==0 : break e=[LIST()for _ in range(d)] sum_max=0 for i in combinations(range(d),2): if abs(i[0]-i[1])==1 : continue for j in combinations(range(w),2): if abs(j[0]-j[1])==1 : continue min_=10 for k in range(i[0],i[1]+1): if k==i[0]or k==i[1]: for l in range(j[0],j[1]+1): min_=min(min_,e[k][l]) else : min_=min(min_,e[k][j[0]]) min_=min(min_,e[k][j[1]]) sum_=0 for k in range(i[0]+1,i[1]): for l in range(j[0]+1,j[1]): if e[k][l]>=min_ : sum_=0 break else : sum_+=(min_-e[k][l]) if e[k][l]>=min_ : break sum_max=max(sum_max,sum_) ans.append(sum_max) for x in ans : print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var ans : Sequence := Sequence{} ; while 1 do ( var d : OclAny := null; var w : OclAny := null; Sequence{d,w} := MAP() ; if d = 0 & w = 0 then ( break ) else skip ; var e : Sequence := Integer.subrange(0, d-1)->select(_anon | true)->collect(_anon | (LIST())) ; var sum_max : int := 0 ; for i : combinations(Integer.subrange(0, d-1), 2) do ( if (i->first() - i[1+1])->abs() = 1 then ( continue ) else skip ; for j : combinations(Integer.subrange(0, w-1), 2) do ( if (j->first() - j[1+1])->abs() = 1 then ( continue ) else skip ; var min_ : int := 10 ; for k : Integer.subrange(i->first(), i[1+1] + 1-1) do ( if k = i->first() or k = i[1+1] then ( for l : Integer.subrange(j->first(), j[1+1] + 1-1) do ( min_ := Set{min_, e[k+1][l+1]}->min()) ) else ( min_ := Set{min_, e[k+1][j->first()+1]}->min() ; min_ := Set{min_, e[k+1][j[1+1]+1]}->min() )) ; var sum_ : int := 0 ; for k : Integer.subrange(i->first() + 1, i[1+1]-1) do ( for l : Integer.subrange(j->first() + 1, j[1+1]-1) do ( if (e[k+1][l+1]->compareTo(min_)) >= 0 then ( sum_ := 0 ; break ) else ( sum_ := sum_ + (min_ - e[k+1][l+1]) )) ; if (e[k+1][l+1]->compareTo(min_)) >= 0 then ( break ) else skip) ; sum_max := Set{sum_max, sum_}->max())) ; execute ((sum_max) : ans)) ; for x : ans do ( execute (x)->display()); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) for i in range(num): lenz=int(input()) arr=input() arr=arr.split(" ") count=0 i=0 while itoInteger() ; for i : Integer.subrange(0, num-1) do ( var lenz : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : String := (OclFile["System.in"]).readLine() ; arr := arr.split(" ") ; var count : int := 0 ; var i : int := 0 ; while (i->compareTo((arr)->size() - 2)) < 0 do ( if arr[i+1] /= "1" then ( i := i + 1 ) else ( var count2 : int := 0 ; for j : Integer.subrange(i + 1, (arr)->size()-1) do ( if arr[j+1] = "0" then ( count2 := count2 + 1 ; i := j ) else ( count := count + count2 ; i := j ; break )) )) ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**9) input=sys.stdin.readline def calcVolume(L,R,T,B,min_wall): ret=0 for w in range(L,R+1): for h in range(B,T+1): ret+=(min_wall-garden[h][w]) return ret def pondsVolume(L,R,T,B): max_in_pond=0 for w in range(L,R+1): for h in range(B,T+1): max_in_pond=max(max_in_pond,garden[h][w]) min_wall=float('inf') for w in range(L-1,R+2): min_wall=min(min_wall,garden[B-1][w],garden[T+1][w]) for h in range(B-1,T+2): min_wall=min(min_wall,garden[h][L-1],garden[h][R+1]) if min_wall<=max_in_pond : return-1 else : return calcVolume(L,R,T,B,min_wall) while True : d,w=map(int,input().split()) if d==0 : break garden=[list(map(int,input().split()))for _ in range(d)] ans=0 wallMin=0 for L in range(1,w-1): for B in range(1,d-1): for R in range(L,w-1): for T in range(B,d-1): ans=max(ans,pondsVolume(L,R,T,B)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(9)) ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; while true do ( var d : OclAny := null; var w : OclAny := null; Sequence{d,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if d = 0 then ( break ) else skip ; var garden : Sequence := Integer.subrange(0, d-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ans : int := 0 ; var wallMin : int := 0 ; for L : Integer.subrange(1, w - 1-1) do ( for B : Integer.subrange(1, d - 1-1) do ( for R : Integer.subrange(L, w - 1-1) do ( for T : Integer.subrange(B, d - 1-1) do ( ans := Set{ans, pondsVolume(L, R, T, B)}->max())))) ; execute (ans)->display()); operation calcVolume(L : OclAny, R : OclAny, T : OclAny, B : OclAny, min_wall : OclAny) : OclAny pre: true post: true activity: var ret : int := 0 ; for w : Integer.subrange(L, R + 1-1) do ( for h : Integer.subrange(B, T + 1-1) do ( ret := ret + (min_wall - garden[h+1][w+1]))) ; return ret; operation pondsVolume(L : OclAny, R : OclAny, T : OclAny, B : OclAny) : OclAny pre: true post: true activity: var max_in_pond : int := 0 ; for w : Integer.subrange(L, R + 1-1) do ( for h : Integer.subrange(B, T + 1-1) do ( max_in_pond := Set{max_in_pond, garden[h+1][w+1]}->max())) ; min_wall := ("" + (('inf')))->toReal() ; for w : Integer.subrange(L - 1, R + 2-1) do ( min_wall := Set{min_wall, garden[B - 1+1][w+1], garden[T + 1+1][w+1]}->min()) ; for h : Integer.subrange(B - 1, T + 2-1) do ( min_wall := Set{min_wall, garden[h+1][L - 1+1], garden[h+1][R + 1+1]}->min()) ; if (min_wall->compareTo(max_in_pond)) <= 0 then ( return -1 ) else ( return calcVolume(L, R, T, B, min_wall) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter def solve(x,y,n): return[x,y,y-x,-x,-y,x-y][(n-1)% 6]% 1000000007 x,y=[int(i)for i in input().split()] n=int(input()) print(solve(x,y,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{x,y} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (solve(x, y, n))->display(); operation solve(x : OclAny, y : OclAny, n : OclAny) : OclAny pre: true post: true activity: return Sequence{x}->union(Sequence{y}->union(Sequence{y - x}->union(Sequence{-x}->union(Sequence{-y}->union(Sequence{ x - y })))))[(n - 1) mod 6+1] mod 1000000007; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(ry,rx,x,y,f): tmpmin=float("inf") for yi in range(ry): tmpmin=min(tmpmin,f[yi+y][x]) for xi in range(rx): tmpmin=min(tmpmin,f[y][xi+x]) for yi in range(ry): tmpmin=min(tmpmin,f[yi+y][x+rx-1]) for xi in range(rx): tmpmin=min(tmpmin,f[ry-1+y][x+xi]) res=0 for yi in range(y+1,y+ry-1): for xi in range(x+1,x+rx-1): res+=tmpmin-f[yi][xi] if f[yi][xi]>=tmpmin : return 0 return res def main(d,w): field=[list(map(int,input().split()))for i in range(d)] res=0 for ry in range(3,d+1): for rx in range(3,w+1): for y in range(d-ry+1): for x in range(w-rx+1): res=max(res,check(ry,rx,x,y,field)) print(res) while 1 : d,w=map(int,input().split()) if d==w==0 : break main(d,w) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while 1 do ( Sequence{d,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if d = w & (w == 0) then ( break ) else skip ; main(d, w)); operation check(ry : OclAny, rx : OclAny, x : OclAny, y : OclAny, f : OclAny) : OclAny pre: true post: true activity: var tmpmin : double := ("" + (("inf")))->toReal() ; for yi : Integer.subrange(0, ry-1) do ( tmpmin := Set{tmpmin, f[yi + y+1][x+1]}->min()) ; for xi : Integer.subrange(0, rx-1) do ( tmpmin := Set{tmpmin, f[y+1][xi + x+1]}->min()) ; for yi : Integer.subrange(0, ry-1) do ( tmpmin := Set{tmpmin, f[yi + y+1][x + rx - 1+1]}->min()) ; for xi : Integer.subrange(0, rx-1) do ( tmpmin := Set{tmpmin, f[ry - 1 + y+1][x + xi+1]}->min()) ; var res : int := 0 ; for yi : Integer.subrange(y + 1, y + ry - 1-1) do ( for xi : Integer.subrange(x + 1, x + rx - 1-1) do ( res := res + tmpmin - f[yi+1][xi+1] ; if (f[yi+1][xi+1]->compareTo(tmpmin)) >= 0 then ( return 0 ) else skip)) ; return res; operation main(d : OclAny, w : OclAny) pre: true post: true activity: var field : Sequence := Integer.subrange(0, d-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; res := 0 ; for ry : Integer.subrange(3, d + 1-1) do ( for rx : Integer.subrange(3, w + 1-1) do ( for y : Integer.subrange(0, d - ry + 1-1) do ( for x : Integer.subrange(0, w - rx + 1-1) do ( res := Set{res, check(ry, rx, x, y, field)}->max())))) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num,k=[int(x)for x in input().split()] arr=[int(x)for x in input().split()] different=set() temp=0 arr.sort() for x in arr : if(x % k!=0 or not x//k in different): different.add(x) temp=max(len(different),temp) print(temp) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : OclAny := null; var k : OclAny := null; Sequence{num,k} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var arr : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var different : Set := Set{}->union(()) ; var temp : int := 0 ; arr := arr->sort() ; for x : arr do ( if (x mod k /= 0 or not((different)->includes(x div k))) then ( execute ((x) : different) ) else skip ; temp := Set{(different)->size(), temp}->max()) ; execute (temp)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) nums=sorted(list(map(int,input().split()))) found=set(nums) removed=set() for num in nums : if num in removed : continue val=num*k if val in found : removed.add(val) if k==1 : print(len(nums)) else : print(len(nums)-len(removed)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var nums : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var found : Set := Set{}->union((nums)) ; var removed : Set := Set{}->union(()) ; for num : nums do ( if (removed)->includes(num) then ( continue ) else skip ; var val : double := num * k ; if (found)->includes(val) then ( execute ((val) : removed) ) else skip) ; if k = 1 then ( execute ((nums)->size())->display() ) else ( execute ((nums)->size() - (removed)->size())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num,k=[int(x)for x in input().split()] arr=[int(x)for x in input().split()] different=set() temp=0 arr.sort() for x in arr : if(x % k!=0 or not x//k in different): different.add(x) temp=max(len(different),temp) print(temp) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : OclAny := null; var k : OclAny := null; Sequence{num,k} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var arr : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var different : Set := Set{}->union(()) ; var temp : int := 0 ; arr := arr->sort() ; for x : arr do ( if (x mod k /= 0 or not((different)->includes(x div k))) then ( execute ((x) : different) ) else skip ; temp := Set{(different)->size(), temp}->max()) ; execute (temp)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num,k=[int(x)for x in input().split()] arr=[int(x)for x in input().split()] different=set() temp=0 arr.sort() for x in arr : if(x % k!=0 or not x//k in different): different.add(x) temp=max(len(different),temp) print(temp) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : OclAny := null; var k : OclAny := null; Sequence{num,k} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var arr : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var different : Set := Set{}->union(()) ; var temp : int := 0 ; arr := arr->sort() ; for x : arr do ( if (x mod k /= 0 or not((different)->includes(x div k))) then ( execute ((x) : different) ) else skip ; temp := Set{(different)->size(), temp}->max()) ; execute (temp)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num,k=[int(x)for x in input().split()] arr=[int(x)for x in input().split()] different=set() temp=0 arr.sort() for x in arr : if(x % k!=0 or not x//k in different): different.add(x) temp=max(len(different),temp) print(temp) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : OclAny := null; var k : OclAny := null; Sequence{num,k} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var arr : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var different : Set := Set{}->union(()) ; var temp : int := 0 ; arr := arr->sort() ; for x : arr do ( if (x mod k /= 0 or not((different)->includes(x div k))) then ( execute ((x) : different) ) else skip ; temp := Set{(different)->size(), temp}->max()) ; execute (temp)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def recycle(N,A,B): n=str(N) r=0 S=[] for k in range(1,len(n)): if n[k]>=n[0]: p=int(n[k :]+n[: k]) if(p>N)and(p<=B)and p not in S : S.append(p) r+=1 return r def work(s): A,B=tuple(map(int,s.split())) n=sum(recycle(k,A,B)for k in range(A,B)) return n if __name__=='__main__' : T=int(sys.stdin.readline().strip()) for i in range(T): s=work(sys.stdin.readline().rstrip()) print('Case #{}:{}'.format(i+1,s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( var T : int := ("" + ((sys.stdin.readLine()->trim())))->toInteger() ; for i : Integer.subrange(0, T-1) do ( s := work(sys.stdin.readLine().rstrip()) ; execute (StringLib.interpolateStrings('Case #{}:{}', Sequence{i + 1, s}))->display()) ) else skip; operation recycle(N : OclAny, A : OclAny, B : OclAny) : OclAny pre: true post: true activity: var n : String := ("" + ((N))) ; var r : int := 0 ; var S : Sequence := Sequence{} ; for k : Integer.subrange(1, (n)->size()-1) do ( if (n[k+1]->compareTo(n->first())) >= 0 then ( var p : int := ("" + ((n.subrange(k+1) + n.subrange(1,k))))->toInteger() ; if ((p->compareTo(N)) > 0) & ((p->compareTo(B)) <= 0) & (S)->excludes(p) then ( execute ((p) : S) ; r := r + 1 ) else skip ) else skip) ; return r; operation work(s : OclAny) : OclAny pre: true post: true activity: Sequence{A,B} := ((s.split())->collect( _x | (OclType["int"])->apply(_x) )) ; n := ((argument (test (logical_test (comparison (expr (atom (name recycle)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name k))))))) , (argument (test (logical_test (comparison (expr (atom (name A))))))) , (argument (test (logical_test (comparison (expr (atom (name B)))))))) ))))))) (comp_for for (exprlist (expr (atom (name k)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A))))))) , (argument (test (logical_test (comparison (expr (atom (name B)))))))) )))))))))->sum() ; return n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=open('C-small-attempt0.in','r') g=open('Csm.txt','w') T=int(f.next().strip()) def solve(A,B,N): sh=range(1,N) n1=range(N-1) j10=[10**j for j in sh] r10=[10**(N-j)for j in sh] res=0 for i in xrange(A,B): S=set() for j in n1 : r=i % j10[j] d=i/j10[j] N=r*r10[j]+d if N>i and N<=B : S.add(N) res+=len(S) return res for i in xrange(1,1+T): s=f.next().strip().split() A=int(s[0]) B=int(s[1]) N=len(s[0]) res=solve(A,B,N) g.write('Case #'+str(i)+': '+str(res)+'\n') g.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('C-small-attempt0.in')) ; var g : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('Csm.txt')) ; var T : int := ("" + ((f.next()->trim())))->toInteger() ; skip ; for i : xrange(1, 1 + T) do ( var s : OclAny := f.next()->trim().split() ; A := ("" + ((s->first())))->toInteger() ; B := ("" + ((s[1+1])))->toInteger() ; N := (s->first())->size() ; res := solve(A, B, N) ; g.write('Case #' + ("" + ((i))) + ': ' + ("" + ((res))) + ' ')) ; g.closeFile(); operation solve(A : OclAny, B : OclAny, N : OclAny) : OclAny pre: true post: true activity: var sh : Sequence := Integer.subrange(1, N-1) ; var n1 : Sequence := Integer.subrange(0, N - 1-1) ; var j10 : Sequence := sh->select(j | true)->collect(j | ((10)->pow(j))) ; var r10 : Sequence := sh->select(j | true)->collect(j | ((10)->pow((N - j)))) ; var res : int := 0 ; for i : xrange(A, B) do ( var S : Set := Set{}->union(()) ; for j : n1 do ( var r : int := i mod j10[j+1] ; var d : double := i / j10[j+1] ; N := r * r10[j+1] + d ; if (N->compareTo(i)) > 0 & (N->compareTo(B)) <= 0 then ( execute ((N) : S) ) else skip) ; res := res + (S)->size()) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- canons=[] def canonicalize(s): min_string=s for i in xrange(len(s)): s=s[1 :]+s[0] if stoInteger() ; for i : xrange(T) do ( var counts : OclAny := Set{} ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := raw_input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for j : xrange(A, B + 1) do ( s := canons[j+1] ; if not(counts.has_key(s)) then ( counts[s+1] := 0 ) else skip ; counts[s+1] := counts[s+1] + 1) ; var num : OclAny := ((argument (test (logical_test (comparison (expr (expr (expr (atom (name counts)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ]))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name counts)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ]))) - (expr (atom (number (integer 1))))))))) )))) / (expr (atom (number (integer 2)))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name counts))))))))->sum() ; (expr (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom 'Case #%d: ')) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) ))))))))) )))) + (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) )))))); operation canonicalize(s : OclAny) : OclAny pre: true post: true activity: var min_string : OclAny := s ; for i : xrange((s)->size()) do ( s := s->tail() + s->first() ; if (s->compareTo(min_string)) < 0 then ( min_string := s ) else skip) ; return min_string; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,m,obstacles,rangee): val=min(n,m) rangee=sorted(rangee) c=1 for i in range(obstacles-1,-1,-1): rangee[i]=2*rangee[i] val-=rangee[i] if(val<=0): return c else : c+=1 if(val>0): return-1 n=4 m=5 obstacles=3 rangee=[1.0,1.25,1.15] print(solve(n,m,obstacles,rangee)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; m := 5 ; obstacles := 3 ; rangee := Sequence{1.0}->union(Sequence{1.25}->union(Sequence{ 1.15 })) ; execute (solve(n, m, obstacles, rangee))->display(); operation solve(n : OclAny, m : OclAny, obstacles : OclAny, rangee : OclAny) : OclAny pre: true post: true activity: var val : OclAny := Set{n, m}->min() ; rangee := rangee->sort() ; var c : int := 1 ; for i : Integer.subrange(-1 + 1, obstacles - 1)->reverse() do ( rangee[i+1] := 2 * rangee[i+1] ; val := val - rangee[i+1] ; if (val <= 0) then ( return c ) else ( c := c + 1 )) ; if (val > 0) then ( return -1 ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INT_MIN=-2**31 INT_MAX=2**31 def findPostOrderUtil(pre,n,minval,maxval,preIndex): if(preIndex[0]==n): return if(pre[preIndex[0]]maxval): return val=pre[preIndex[0]] preIndex[0]+=1 findPostOrderUtil(pre,n,minval,val,preIndex) findPostOrderUtil(pre,n,val,maxval,preIndex) print(val,end=" ") def findPostOrder(pre,n): preIndex=[0] findPostOrderUtil(pre,n,INT_MIN,INT_MAX,preIndex) if __name__=='__main__' : pre=[40,30,35,80,100] n=len(pre) findPostOrder(pre,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INT_MIN : double := (-2)->pow(31) ; var INT_MAX : double := (2)->pow(31) ; skip ; skip ; if __name__ = '__main__' then ( pre := Sequence{40}->union(Sequence{30}->union(Sequence{35}->union(Sequence{80}->union(Sequence{ 100 })))) ; n := (pre)->size() ; findPostOrder(pre, n) ) else skip; operation findPostOrderUtil(pre : OclAny, n : OclAny, minval : OclAny, maxval : OclAny, preIndex : OclAny) pre: true post: true activity: if (preIndex->first() = n) then ( return ) else skip ; if ((pre[preIndex->first()+1]->compareTo(minval)) < 0 or (pre[preIndex->first()+1]->compareTo(maxval)) > 0) then ( return ) else skip ; var val : OclAny := pre[preIndex->first()+1] ; preIndex->first() := preIndex->first() + 1 ; findPostOrderUtil(pre, n, minval, val, preIndex) ; findPostOrderUtil(pre, n, val, maxval, preIndex) ; execute (val)->display(); operation findPostOrder(pre : OclAny, n : OclAny) pre: true post: true activity: preIndex := Sequence{ 0 } ; findPostOrderUtil(pre, n, INT_MIN, INT_MAX, preIndex); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sum(k,n): sum=(pow(k,n+1)-pow(k-1,n+1)); return sum ; n=3 ; K=3 ; print(sum(K,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3; ; var K : int := 3; ; execute ((K, n)->sum())->display();; operation sum(k : OclAny, n : OclAny) pre: true post: true activity: var sum : double := ((k)->pow(n + 1) - (k - 1)->pow(n + 1)); ; return sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(i,tight,sum_so_far,Sum,number,length): if i==length : if sum_so_far==Sum : return 1 else : return 0 ans=dp[i][tight][sum_so_far] if ans!=-1 : return ans ans=0 for currdigit in range(0,10): currdigitstr=str(currdigit) if not tight and currdigitstr>number[i]: break ntight=tight or currdigitstrselect(k | true)->collect(k | (Integer.subrange(0, 2-1)->select(j | true)->collect(j | (Integer.subrange(0, 162-1)->select(i | true)->collect(i | (-1)))))) ; execute (solve(0, 0, 0, Sum, number, (number)->size()))->display() ) else skip; operation solve(i : OclAny, tight : OclAny, sum_so_far : OclAny, Sum : OclAny, number : OclAny, length : OclAny) : OclAny pre: true post: true activity: if i = length then ( if sum_so_far = Sum then ( return 1 ) else ( return 0 ) ) else skip ; var ans : OclAny := dp[i+1][tight+1][sum_so_far+1] ; if ans /= -1 then ( return ans ) else skip ; ans := 0 ; for currdigit : Integer.subrange(0, 10-1) do ( var currdigitstr : String := ("" + ((currdigit))) ; if not(tight) & currdigitstr > number[i+1] then ( break ) else skip ; var ntight : boolean := tight or currdigitstr < number[i+1] ; var nsum_so_far : OclAny := sum_so_far + currdigit ; ans := ans + solve(i + 1, ntight, nsum_so_far, Sum, number, length)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- total=0 num_cases=int(input()) for i in range(num_cases): line=input() if sum([int(x)for x in line.split()])>=2 : total+=1 print(total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var total : int := 0 ; var num_cases : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, num_cases-1) do ( var line : String := (OclFile["System.in"]).readLine() ; if (line.split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))->sum() >= 2 then ( total := total + 1 ) else skip) ; execute (total)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) k=0 for i in range(n): s=input().split() if int(s[0])+int(s[1])+int(s[2])>=2 : k+=1 print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := 0 ; for i : Integer.subrange(0, n-1) do ( var s : OclAny := input().split() ; if ("" + ((s->first())))->toInteger() + ("" + ((s[1+1])))->toInteger() + ("" + ((s[2+1])))->toInteger() >= 2 then ( k := k + 1 ) else skip) ; execute (k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=0 for i in range(n): a,b,c=map(int,input().split()) if a+b+c>=2 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a + b + c >= 2 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) c=0 for i in range(n): l1=list(map(int,input().split())) if sum(l1)>1 : c=c+1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (l1)->sum() > 1 then ( c := c + 1 ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n=int(input()) c=0 for i in range(n): l1=list(map(int,input().split())) c1=Counter(l1) if c1[1]>1 : c=c+1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c1 : OclAny := Counter(l1) ; if c1[1+1] > 1 then ( c := c + 1 ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class newNode : def __init__(self,key): self.data=key self.left=None self.right=None def evenOddLevelDifference(root): if(not root): return 0 q=[] q.append(root) level=0 evenSum=0 oddSum=0 while(len(q)): size=len(q) level+=1 while(size>0): temp=q[0] q.pop(0) if(level % 2==0): evenSum+=temp.data else : oddSum+=temp.data if(temp.left): q.append(temp.left) if(temp.right): q.append(temp.right) size-=1 return(oddSum-evenSum) if __name__=='__main__' : root=newNode(5) root.left=newNode(2) root.right=newNode(6) root.left.left=newNode(1) root.left.right=newNode(4) root.left.right.left=newNode(3) root.right.right=newNode(8) root.right.right.right=newNode(9) root.right.right.left=newNode(7) result=evenOddLevelDifference(root) print("Diffence between sums is",result) ------------------------------------------------------------ OCL File: --------- class newNode { static operation newnewNode() : newNode pre: true post: newNode->exists( _x | result = _x ); attribute data : OclAny := key; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(key : OclAny) : newNode pre: true post: true activity: self.data := key ; self.left := null ; self.right := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( root := (newNode.newnewNode()).initialise(5) ; root.left := (newNode.newnewNode()).initialise(2) ; root.right := (newNode.newnewNode()).initialise(6) ; root.left.left := (newNode.newnewNode()).initialise(1) ; root.left.right := (newNode.newnewNode()).initialise(4) ; root.left.right.left := (newNode.newnewNode()).initialise(3) ; root.right.right := (newNode.newnewNode()).initialise(8) ; root.right.right.right := (newNode.newnewNode()).initialise(9) ; root.right.right.left := (newNode.newnewNode()).initialise(7) ; var result : OclAny := evenOddLevelDifference(root) ; execute ("Diffence between sums is")->display() ) else skip; operation evenOddLevelDifference(root : OclAny) : OclAny pre: true post: true activity: if (not(root)) then ( return 0 ) else skip ; var q : Sequence := Sequence{} ; execute ((root) : q) ; var level : int := 0 ; var evenSum : int := 0 ; var oddSum : int := 0 ; while ((q)->size()) do ( var size : int := (q)->size() ; level := level + 1 ; while (size > 0) do ( var temp : OclAny := q->first() ; q := q->excludingAt(0+1) ; if (level mod 2 = 0) then ( evenSum := evenSum + temp.data ) else ( oddSum := oddSum + temp.data ) ; if (temp.left) then ( execute ((temp.left) : q) ) else skip ; if (temp.right) then ( execute ((temp.right) : q) ) else skip ; size := size - 1)) ; return (oddSum - evenSum); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSubarrays(a,n,x): count=0 number=0 for i in range(n): if(a[i]>x): count+=1 else : number+=(count)*(count+1)/2 count=0 if(count): number+=(count)*(count+1)/2 return int(number) if __name__=='__main__' : a=[3,4,5,6,7,2,10,11] n=len(a) k=5 print(countSubarrays(a,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{2}->union(Sequence{10}->union(Sequence{ 11 }))))))) ; n := (a)->size() ; var k : int := 5 ; execute (countSubarrays(a, n, k))->display() ) else skip; operation countSubarrays(a : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var number : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ((a[i+1]->compareTo(x)) > 0) then ( count := count + 1 ) else ( number := number + (count) * (count + 1) / 2 ; count := 0 )) ; if (count) then ( number := number + (count) * (count + 1) / 2 ) else skip ; return ("" + ((number)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minCost(arr,n): count_even=0 count_odd=0 for i in range(n): if(arr[i]% 2==0): count_even+=1 else : count_odd+=1 return min(count_even,count_odd) arr=[2,4,3,1,5] n=len(arr) print(minCost(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{4}->union(Sequence{3}->union(Sequence{1}->union(Sequence{ 5 })))) ; n := (arr)->size() ; execute (minCost(arr, n))->display(); operation minCost(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count_even : int := 0 ; var count_odd : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] mod 2 = 0) then ( count_even := count_even + 1 ) else ( count_odd := count_odd + 1 )) ; return Set{count_even, count_odd}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countWays(n,arr,k): if(k<=0 or k>=n): return 0 s=set() for element in arr : s.add(element) if(len(s)<=k): return 0 ; return len(s)-k ; if __name__=="__main__" : arr=[100,200,400,50] k=3 ; n=len(arr); print(countWays(n,arr,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{100}->union(Sequence{200}->union(Sequence{400}->union(Sequence{ 50 }))) ; k := 3; ; n := (arr)->size(); ; execute (countWays(n, arr, k))->display() ) else skip; operation countWays(n : OclAny, arr : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (k <= 0 or (k->compareTo(n)) >= 0) then ( return 0 ) else skip ; var s : Set := Set{}->union(()) ; for element : arr do ( execute ((element) : s)) ; if (((s)->size()->compareTo(k)) <= 0) then ( return 0; ) else skip ; return (s)->size() - k;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() t=int(input()) e1=eval(s) e2=int(s[0]) i=1 while itoInteger() ; var e1 : OclAny := s ; var e2 : int := ("" + ((s->first())))->toInteger() ; var i : int := 1 ; while (i->compareTo((s)->size())) < 0 do ( var x : int := ("" + ((s[i + 1+1])))->toInteger() ; if s[i+1] = '+' then ( e2 := e2 + x ) else ( e2 := e2 * x ) ; i := i + 2) ; if e1 = t & e2 = t then ( execute ("U")->display() ) else (if e1 = t then ( execute ("M")->display() ) else (if e2 = t then ( execute ("L")->display() ) else ( execute ("I")->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printLastOccurrence(a,n): mp={i : 0 for i in range(7)} for i in range(n): mp[a[i]]=i for i in range(n): if(mp[a[i]]==i): print(a[i],end=" ") if __name__=='__main__' : a=[1,5,5,1,6,1] n=len(a) printLastOccurrence(a,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := Sequence{1}->union(Sequence{5}->union(Sequence{5}->union(Sequence{1}->union(Sequence{6}->union(Sequence{ 1 }))))) ; n := (a)->size() ; printLastOccurrence(a, n) ) else skip; operation printLastOccurrence(a : OclAny, n : OclAny) pre: true post: true activity: var mp : Map := Integer.subrange(0, 7-1)->select(i | true)->collect(i | Map{i |-> 0})->unionAll() ; for i : Integer.subrange(0, n-1) do ( mp[a[i+1]+1] := i) ; for i : Integer.subrange(0, n-1) do ( if (mp[a[i+1]+1] = i) then ( execute (a[i+1])->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break s=list(map(int,input().split())) if max(s)<2 : print('NA') else : t=s.count(0) print(n-t+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (s)->max() < 2 then ( execute ('NA')->display() ) else ( var t : int := s->count(0) ; execute (n - t + 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) count=1 if n==0 : break k=list(map(int,input().split())) k.sort(reverse=True) if k[0]<2 : print("NA") else : for i in k : if i!=0 : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := 1 ; if n = 0 then ( break ) else skip ; var k : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; k := k->sort() ; if k->first() < 2 then ( execute ("NA")->display() ) else ( for i : k do ( if i /= 0 then ( count := count + 1 ) else skip) ; execute (count)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,datetime PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") while True : n=int(input()) if n==0 : break t=[int(_)for _ in input().split()] if max(t)<2 : print("NA") else : print(1+len([i for i in t if i>0])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var t : Sequence := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; if (t)->max() < 2 then ( execute ("NA")->display() ) else ( execute (1 + (t->select(i | i > 0)->collect(i | (i)))->size())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : N=int(input()) if N==0 : break nums=[int(i)for i in input().split()] maxNum=0 cnt=0 for i in range(N): if nums[i]>0 : cnt=cnt+1 maxNum=max(nums[i],maxNum) if maxNum<2 : print("NA") else : print(cnt+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var nums : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var maxNum : int := 0 ; var cnt : int := 0 ; for i : Integer.subrange(0, N-1) do ( if nums[i+1] > 0 then ( cnt := cnt + 1 ) else skip ; maxNum := Set{nums[i+1], maxNum}->max()) ; if maxNum < 2 then ( execute ("NA")->display() ) else ( execute (cnt + 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : ko=int(input()) if ko==0 : break line=input().split() num=line.count("1")+line.count("0") if ko==num : print("NA") continue print(ko-line.count("0")+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var ko : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if ko = 0 then ( break ) else skip ; var line : OclAny := input().split() ; var num : int := line->count("1") + line->count("0") ; if ko = num then ( execute ("NA")->display() ; continue ) else skip ; execute (ko - line->count("0") + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPaths(m,n): if m==1 or n==1 : return 1 return(countPaths(m-1,n)+countPaths(m,n-1)) if __name__=="__main__" : n=5 m=5 print(countPaths(n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 5 ; m := 5 ; execute (countPaths(n, m))->display() ) else skip; operation countPaths(m : OclAny, n : OclAny) : OclAny pre: true post: true activity: if m = 1 or n = 1 then ( return 1 ) else skip ; return (countPaths(m - 1, n) + countPaths(m, n - 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfAP(a,d,n): sum=(n/2)*(2*a+(n-1)*d) return sum n=20 a=2.5 d=1.5 print(sumOfAP(a,d,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 20 ; a := 2.5 ; d := 1.5 ; execute (sumOfAP(a, d, n))->display(); operation sumOfAP(a : OclAny, d : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sum : double := (n / 2) * (2 * a + (n - 1) * d) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def countPairs(arr,n): count=0 for i in range(n): for j in range(i+1,n): if arr[i]*arr[j]>arr[i]+arr[j]: count+=1 return count arr=[5,0,3,1,2] n=len(arr) print(countPairs(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{5}->union(Sequence{0}->union(Sequence{3}->union(Sequence{1}->union(Sequence{ 2 })))) ; n := (arr)->size() ; execute (countPairs(arr, n))->display(); operation countPairs(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if (arr[i+1] * arr[j+1]->compareTo(arr[i+1] + arr[j+1])) > 0 then ( count := count + 1 ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect n=int(input()) l=list(map(int,input().split())) l.sort() res=0 for i in range(2,n): cnt=0 for j in range(i): p=l[i]-l[j] k=bisect.bisect_right(l,p) cnt+=i-k if k<=j : cnt-=1 res+=cnt print(res//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := l->sort() ; var res : int := 0 ; for i : Integer.subrange(2, n-1) do ( var cnt : int := 0 ; for j : Integer.subrange(0, i-1) do ( var p : double := l[i+1] - l[j+1] ; var k : OclAny := bisect.bisect_right(l, p) ; cnt := cnt + i - k ; if (k->compareTo(j)) <= 0 then ( cnt := cnt - 1 ) else skip) ; res := res + cnt) ; execute (res div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cnt=input() for k in range(int(cnt)): ip=input() if ip=="" : print("0000:0000:0000:0000:0000:0000:0000:0000") continue ip=ip.split(":") ret="" if ip[0]=="" : ip=["0000"]*(8-len(ip)+2)+ip[2 :] elif ip[-1]=="" : ip=ip[:-2]+["0000"]*(8-len(ip)+2) for i in range(len(ip)): if ip[i]=="" : ip=ip[: i]+["0000"]*(8-len(ip)+1)+ip[i+1 :] for i in range(len(ip)): if ip[i]!="" : ip[i]="0"*(4-len(ip[i]))+ip[i] print(":".join(ip)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cnt : String := (OclFile["System.in"]).readLine() ; for k : Integer.subrange(0, ("" + ((cnt)))->toInteger()-1) do ( var ip : String := (OclFile["System.in"]).readLine() ; if ip = "" then ( execute ("0000:0000:0000:0000:0000:0000:0000:0000")->display() ; continue ) else skip ; ip := ip.split(":") ; var ret : String := "" ; if ip->first() = "" then ( ip := MatrixLib.elementwiseMult(Sequence{ "0000" }, (8 - (ip)->size() + 2))->union(ip.subrange(2+1)) ) else (if ip->last() = "" then ( ip := ip->front()->front()->union(MatrixLib.elementwiseMult(Sequence{ "0000" }, (8 - (ip)->size() + 2))) ) else skip) ; for i : Integer.subrange(0, (ip)->size()-1) do ( if ip[i+1] = "" then ( ip := ip.subrange(1,i)->union(MatrixLib.elementwiseMult(Sequence{ "0000" }, (8 - (ip)->size() + 1))) + ip.subrange(i + 1+1) ) else skip) ; for i : Integer.subrange(0, (ip)->size()-1) do ( if ip[i+1] /= "" then ( ip[i+1] := StringLib.nCopies("0", (4 - (ip[i+1])->size())) + ip[i+1] ) else skip) ; execute (StringLib.sumStringsWithSeparator((ip), ":"))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def coordinateCompression(arr,n): s=dict() for i in range(n): s[arr[i]]=1 index=0 mp=dict() for itr in sorted(s): index+=1 mp[itr]=index for i in range(n): arr[i]=mp[arr[i]] def query(BIT,index,n): ans=0 while(index>0): ans=max(ans,BIT[index]) index-=index &(-index) return ans def update(BIT,index,n): x=query(BIT,index-1,n) value=x+1 while(index<=n): BIT[index]=max(BIT[index],value) index+=index &(-index) def findLISLength(arr,n): coordinateCompression(arr,n) BIT=[0]*(n+1) for i in range(n): update(BIT,arr[i],n) ans=query(BIT,n,n) return ans arr=[6,5,1,3,2,4,8,7] n=len(arr) ans=findLISLength(arr,n) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; arr := Sequence{6}->union(Sequence{5}->union(Sequence{1}->union(Sequence{3}->union(Sequence{2}->union(Sequence{4}->union(Sequence{8}->union(Sequence{ 7 }))))))) ; n := (arr)->size() ; ans := findLISLength(arr, n) ; execute (ans)->display(); operation coordinateCompression(arr : OclAny, n : OclAny) pre: true post: true activity: var s : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( s[arr[i+1]+1] := 1) ; var index : int := 0 ; var mp : Map := (arguments ( )) ; for itr : s->keys()->sort() do ( index := index + 1 ; mp[itr+1] := index) ; for i : Integer.subrange(0, n-1) do ( arr[i+1] := mp[arr[i+1]+1]); operation query(BIT : OclAny, index : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; while (index > 0) do ( ans := Set{ans, BIT[index+1]}->max() ; index := index - MathLib.bitwiseAnd(index, (-index))) ; return ans; operation update(BIT : OclAny, index : OclAny, n : OclAny) pre: true post: true activity: var x : OclAny := query(BIT, index - 1, n) ; var value : OclAny := x + 1 ; while ((index->compareTo(n)) <= 0) do ( BIT[index+1] := Set{BIT[index+1], value}->max() ; index := index + MathLib.bitwiseAnd(index, (-index))); operation findLISLength(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: coordinateCompression(arr, n) ; BIT := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(0, n-1) do ( update(BIT, arr[i+1], n)) ; ans := query(BIT, n, n) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] while True : a=[c for c in S()] l=len(a) s=I() t=int(a[0]) for i in range(len(a)//2): if a[i*2+1]=='+' : t+=int(a[i*2+2]) else : t*=int(a[i*2+2]) u=eval(''.join(a)) r='I' if s==u : if s==t : r='U' else : r='M' elif s==t : r='L' rr.append(r) break return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var a : Sequence := S()->select(c | true)->collect(c | (c)) ; var l : int := (a)->size() ; s := I() ; var t : int := ("" + ((a->first())))->toInteger() ; for i : Integer.subrange(0, (a)->size() div 2-1) do ( if a[i * 2 + 1+1] = '+' then ( t := t + ("" + ((a[i * 2 + 2+1])))->toInteger() ) else ( t := t * ("" + ((a[i * 2 + 2+1])))->toInteger() )) ; var u : OclAny := StringLib.sumStringsWithSeparator((a), '') ; var r : String := 'I' ; if s = u then ( if s = t then ( r := 'U' ) else ( r := 'M' ) ) else (if s = t then ( r := 'L' ) else skip) ; execute ((r) : rr) ; break) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) a=[[]for i in range(n)] for j in range(n): a[j]=list(map(int,input().split())) ans=False for j in range(5): for k in range(5): if k!=j : cnt1=0 cnt2=0 cntno=0 for z in range(n): if a[z][j]==1 : cnt1+=1 if a[z][k]==1 : cnt2+=1 if a[z][j]==0 and a[z][k]==0 : cntno+=1 if cnt1>=n//2 and cnt2>=n//2 and cntno==0 : ans=True if ans : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for j : Integer.subrange(0, n-1) do ( a[j+1] := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ans : boolean := false ; for j : Integer.subrange(0, 5-1) do ( for k : Integer.subrange(0, 5-1) do ( if k /= j then ( var cnt1 : int := 0 ; var cnt2 : int := 0 ; var cntno : int := 0 ; for z : Integer.subrange(0, n-1) do ( if a[z+1][j+1] = 1 then ( cnt1 := cnt1 + 1 ) else skip ; if a[z+1][k+1] = 1 then ( cnt2 := cnt2 + 1 ) else skip ; if a[z+1][j+1] = 0 & a[z+1][k+1] = 0 then ( cntno := cntno + 1 ) else skip) ; if (cnt1->compareTo(n div 2)) >= 0 & (cnt2->compareTo(n div 2)) >= 0 & cntno = 0 then ( ans := true ) else skip ) else skip)) ; if ans then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) a=[[]for i in range(n)] for j in range(n): a[j]=list(map(int,input().split())) ans=False for j in range(5): for k in range(5): if k!=j : cnt1=0 cnt2=0 cntno=0 for z in range(n): if a[z][j]==1 : cnt1+=1 if a[z][k]==1 : cnt2+=1 if a[z][j]==0 and a[z][k]==0 : cntno+=1 if cnt1>=n//2 and cnt2>=n//2 and cntno==0 : ans=True if ans : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for j : Integer.subrange(0, n-1) do ( a[j+1] := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ans : boolean := false ; for j : Integer.subrange(0, 5-1) do ( for k : Integer.subrange(0, 5-1) do ( if k /= j then ( var cnt1 : int := 0 ; var cnt2 : int := 0 ; var cntno : int := 0 ; for z : Integer.subrange(0, n-1) do ( if a[z+1][j+1] = 1 then ( cnt1 := cnt1 + 1 ) else skip ; if a[z+1][k+1] = 1 then ( cnt2 := cnt2 + 1 ) else skip ; if a[z+1][j+1] = 0 & a[z+1][k+1] = 0 then ( cntno := cntno + 1 ) else skip) ; if (cnt1->compareTo(n div 2)) >= 0 & (cnt2->compareTo(n div 2)) >= 0 & cntno = 0 then ( ans := true ) else skip ) else skip)) ; if ans then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): prefs=[] n=int(input()) for _ in range(n): prefs.append([int(i)for i in input().split()]) if n % 2 : print("NO") continue ans=False for i in range(5): if ans : break for j in range(i+1,5): if ans : break cnta,cntb=0,0 flag=False for pref in prefs : if not(pref[i]or pref[j]): flag=True break elif pref[i]and not pref[j]: cnta+=1 elif not pref[i]and pref[j]: cntb+=1 if flag : continue else : if cnta<=n/2 and cntb<=n/2 : ans=True print("YES" if ans else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var prefs : Sequence := Sequence{} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( execute ((input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))) : prefs)) ; if n mod 2 then ( execute ("NO")->display() ; continue ) else skip ; var ans : boolean := false ; for i : Integer.subrange(0, 5-1) do ( if ans then ( break ) else skip ; for j : Integer.subrange(i + 1, 5-1) do ( if ans then ( break ) else skip ; var cnta : OclAny := null; var cntb : OclAny := null; Sequence{cnta,cntb} := Sequence{0,0} ; var flag : boolean := false ; for pref : prefs do ( if not((pref[i+1] or pref[j+1])) then ( flag := true ; break ) else (if pref[i+1] & not(pref[j+1]) then ( cnta := cnta + 1 ) else (if not(pref[i+1]) & pref[j+1] then ( cntb := cntb + 1 ) else skip ) ) ) ; if flag then ( continue ) else ( if (cnta->compareTo(n / 2)) <= 0 & (cntb->compareTo(n / 2)) <= 0 then ( ans := true ) else skip ))) ; execute (if ans then "YES" else "NO" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) a=[[]for i in range(n)] for j in range(n): a[j]=list(map(int,input().split())) ans=False for j in range(5): for k in range(5): if k!=j : this_website_is_garbage=0 kill_yourselves_idiots=0 cntno=0 for z in range(n): if a[z][j]==1 : this_website_is_garbage+=1 if a[z][k]==1 : kill_yourselves_idiots+=1 if a[z][j]==0 and a[z][k]==0 : cntno+=1 if this_website_is_garbage>=n//2 and kill_yourselves_idiots>=n//2 and cntno==0 : ans=True if ans : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for j : Integer.subrange(0, n-1) do ( a[j+1] := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ans : boolean := false ; for j : Integer.subrange(0, 5-1) do ( for k : Integer.subrange(0, 5-1) do ( if k /= j then ( var this_website_is_garbage : int := 0 ; var kill_yourselves_idiots : int := 0 ; var cntno : int := 0 ; for z : Integer.subrange(0, n-1) do ( if a[z+1][j+1] = 1 then ( this_website_is_garbage := this_website_is_garbage + 1 ) else skip ; if a[z+1][k+1] = 1 then ( kill_yourselves_idiots := kill_yourselves_idiots + 1 ) else skip ; if a[z+1][j+1] = 0 & a[z+1][k+1] = 0 then ( cntno := cntno + 1 ) else skip) ; if (this_website_is_garbage->compareTo(n div 2)) >= 0 & (kill_yourselves_idiots->compareTo(n div 2)) >= 0 & cntno = 0 then ( ans := true ) else skip ) else skip)) ; if ans then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) a=[[]for i in range(n)] for j in range(n): a[j]=list(map(int,input().split())) ans=False for j in range(5): for k in range(5): if k!=j : cnt1=0 cnt2=0 cntno=0 for z in range(n): if a[z][j]==1 : cnt1+=1 if a[z][k]==1 : cnt2+=1 if a[z][j]==0 and a[z][k]==0 : cntno+=1 if cnt1>=n//2 and cnt2>=n//2 and cntno==0 : ans=True if ans : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for j : Integer.subrange(0, n-1) do ( a[j+1] := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ans : boolean := false ; for j : Integer.subrange(0, 5-1) do ( for k : Integer.subrange(0, 5-1) do ( if k /= j then ( var cnt1 : int := 0 ; var cnt2 : int := 0 ; var cntno : int := 0 ; for z : Integer.subrange(0, n-1) do ( if a[z+1][j+1] = 1 then ( cnt1 := cnt1 + 1 ) else skip ; if a[z+1][k+1] = 1 then ( cnt2 := cnt2 + 1 ) else skip ; if a[z+1][j+1] = 0 & a[z+1][k+1] = 0 then ( cntno := cntno + 1 ) else skip) ; if (cnt1->compareTo(n div 2)) >= 0 & (cnt2->compareTo(n div 2)) >= 0 & cntno = 0 then ( ans := true ) else skip ) else skip)) ; if ans then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): BASE=10 DIGITS=20 CONSECUTIVE=3 MAX_SUM=9 innerlen=BASE**CONSECUTIVE ways=[[1]+[0]*(innerlen-1)] for digits in range(1,DIGITS+CONSECUTIVE+1): newrow=[] for prefix in range(innerlen): sum=0 if digit_sum(prefix)<=MAX_SUM : for nextdigit in range(BASE): sum+=ways[digits-1][prefix %(BASE**(CONSECUTIVE-1))*BASE+nextdigit] newrow.append(sum) ways.append(newrow) ans=ways[-1][0]-ways[-2][0] return str(ans) def digit_sum(n): return sum(int(c)for c in str(n)) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var BASE : int := 10 ; var DIGITS : int := 20 ; var CONSECUTIVE : int := 3 ; var MAX_SUM : int := 9 ; var innerlen : double := (BASE)->pow(CONSECUTIVE) ; var ways : Sequence := Sequence{ Sequence{ 1 }->union(MatrixLib.elementwiseMult(Sequence{ 0 }, (innerlen - 1))) } ; for digits : Integer.subrange(1, DIGITS + CONSECUTIVE + 1-1) do ( var newrow : Sequence := Sequence{} ; for prefix : Integer.subrange(0, innerlen-1) do ( var sum : int := 0 ; if (digit_sum(prefix)->compareTo(MAX_SUM)) <= 0 then ( for nextdigit : Integer.subrange(0, BASE-1) do ( sum := sum + ways[digits - 1+1][prefix mod ((BASE)->pow((CONSECUTIVE - 1))) * BASE + nextdigit+1]) ) else skip ; execute ((sum) : newrow)) ; execute ((newrow) : ways)) ; var ans : double := ways->last()->first() - ways->front()->last()->first() ; return ("" + ((ans))); operation digit_sum(n : OclAny) : OclAny pre: true post: true activity: return ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- arr=[input(),input(),input(),input()] exit=False for i in range(3): if exit : break for j in range(3): countw=0 countb=0 if arr[i][j]=="#" : countb+=1 else : countw+=1 if arr[i+1][j]=="#" : countb+=1 else : countw+=1 if arr[i][j+1]=="#" : countb+=1 else : countw+=1 if arr[i+1][j+1]=="#" : countb+=1 else : countw+=1 if countw>=3 or countb>=3 : print("YES") exit=True break if not exit : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var arr : Sequence := Sequence{(OclFile["System.in"]).readLine()}->union(Sequence{(OclFile["System.in"]).readLine()}->union(Sequence{(OclFile["System.in"]).readLine()}->union(Sequence{ (OclFile["System.in"]).readLine() }))) ; var exit : boolean := false ; for i : Integer.subrange(0, 3-1) do ( if exit then ( break ) else skip ; for j : Integer.subrange(0, 3-1) do ( var countw : int := 0 ; var countb : int := 0 ; if arr[i+1][j+1] = "#" then ( countb := countb + 1 ) else ( countw := countw + 1 ) ; if arr[i + 1+1][j+1] = "#" then ( countb := countb + 1 ) else ( countw := countw + 1 ) ; if arr[i+1][j + 1+1] = "#" then ( countb := countb + 1 ) else ( countw := countw + 1 ) ; if arr[i + 1+1][j + 1+1] = "#" then ( countb := countb + 1 ) else ( countw := countw + 1 ) ; if countw >= 3 or countb >= 3 then ( execute ("YES")->display() ; exit := true ; break ) else skip)) ; if not(exit) then ( execute ("NO")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=[] for i in range(4): l=list(map(str,input())) t.append(l) def valide(c): for i in range(3): for j in range(3): nb=0 for x in range(i,i+2): for y in range(j,j+2): if t[x][y]==c : nb+=1 if nb>=3 : return True return False if valide('#')or valide('.'): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : Sequence := Sequence{} ; for i : Integer.subrange(0, 4-1) do ( var l : Sequence := (((OclFile["System.in"]).readLine())->collect( _x | (OclType["String"])->apply(_x) )) ; execute ((l) : t)) ; skip ; if valide('#') or valide('.') then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); operation valide(c : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, 3-1) do ( for j : Integer.subrange(0, 3-1) do ( var nb : int := 0 ; for x : Integer.subrange(i, i + 2-1) do ( for y : Integer.subrange(j, j + 2-1) do ( if t[x+1][y+1] = c then ( nb := nb + 1 ) else skip)) ; if nb >= 3 then ( return true ) else skip)) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import ipaddress n=int(input()) for i in range(n): short=str(input()) long=ipaddress.IPv6Address(short).exploded print(long) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var short : String := ("" + (((OclFile["System.in"]).readLine()))) ; var long : OclAny := ipaddress.IPv6Address(short).exploded ; execute (long)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=[] for i in range(4): l=list(map(str,input())) t.append(l) black=0 white=0 correct=0 for i in range(3): for j in range(3): if t[i][j]=='#' : black+=1 else : white+=1 if t[i][j+1]=='#' : black+=1 else : white+=1 if t[i+1][j]=='#' : black+=1 else : white+=1 if t[i+1][j+1]=='#' : black+=1 else : white+=1 if(black==0 or black==3 or white==0 or white==3 or white==4 or black==4): correct=1 break black=0 white=0 if correct==1 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : Sequence := Sequence{} ; for i : Integer.subrange(0, 4-1) do ( var l : Sequence := (((OclFile["System.in"]).readLine())->collect( _x | (OclType["String"])->apply(_x) )) ; execute ((l) : t)) ; var black : int := 0 ; var white : int := 0 ; var correct : int := 0 ; for i : Integer.subrange(0, 3-1) do ( for j : Integer.subrange(0, 3-1) do ( if t[i+1][j+1] = '#' then ( black := black + 1 ) else ( white := white + 1 ) ; if t[i+1][j + 1+1] = '#' then ( black := black + 1 ) else ( white := white + 1 ) ; if t[i + 1+1][j+1] = '#' then ( black := black + 1 ) else ( white := white + 1 ) ; if t[i + 1+1][j + 1+1] = '#' then ( black := black + 1 ) else ( white := white + 1 ) ; if (black = 0 or black = 3 or white = 0 or white = 3 or white = 4 or black = 4) then ( correct := 1 ; break ) else skip ; black := 0 ; white := 0)) ; if correct = 1 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count_dash(matrix,i,j): count=0 if matrix[i][j]=='#' : count+=1 if matrix[i][j+1]=='#' : count+=1 if matrix[i+1][j]=='#' : count+=1 if matrix[i+1][j+1]=='#' : count+=1 return count def count_dot(matrix,i,j): count=0 if matrix[i][j]=='.' : count+=1 if matrix[i][j+1]=='.' : count+=1 if matrix[i+1][j]=='.' : count+=1 if matrix[i+1][j+1]=='.' : count+=1 return count matrix=[] for _ in range(4): matrix.append(list(input())) possible=False for i in range(len(matrix)-1): if possible : break for j in range(len(matrix[0])-1): if count_dash(matrix,i,j)>=3 : possible=True break if count_dot(matrix,i,j)>=3 : possible=True break if possible : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; matrix := Sequence{} ; for _anon : Integer.subrange(0, 4-1) do ( execute ((((OclFile["System.in"]).readLine())->characters()) : matrix)) ; var possible : boolean := false ; for i : Integer.subrange(0, (matrix)->size() - 1-1) do ( if possible then ( break ) else skip ; for j : Integer.subrange(0, (matrix->first())->size() - 1-1) do ( if count_dash(matrix, i, j) >= 3 then ( possible := true ; break ) else skip ; if count_dot(matrix, i, j) >= 3 then ( possible := true ; break ) else skip)) ; if possible then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); operation count_dash(matrix : OclAny, i : OclAny, j : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; if matrix[i+1][j+1] = '#' then ( count := count + 1 ) else skip ; if matrix[i+1][j + 1+1] = '#' then ( count := count + 1 ) else skip ; if matrix[i + 1+1][j+1] = '#' then ( count := count + 1 ) else skip ; if matrix[i + 1+1][j + 1+1] = '#' then ( count := count + 1 ) else skip ; return count; operation count_dot(matrix : OclAny, i : OclAny, j : OclAny) : OclAny pre: true post: true activity: count := 0 ; if matrix[i+1][j+1] = '.' then ( count := count + 1 ) else skip ; if matrix[i+1][j + 1+1] = '.' then ( count := count + 1 ) else skip ; if matrix[i + 1+1][j+1] = '.' then ( count := count + 1 ) else skip ; if matrix[i + 1+1][j + 1+1] = '.' then ( count := count + 1 ) else skip ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() l=len(s) def parse1(s): cur=0 num=0 ; res=0 ; op='+' while cursize() ; skip ; skip ; v := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r1 : boolean := parse1(s) = v ; var r2 : boolean := parse2(s) = v ; execute ("ILMU"[r1 + 2 * r2+1])->display(); operation parse1(s : OclAny) : OclAny pre: true post: true activity: var cur : int := 0 ; var num : int := 0; var res : int := 0; var op : String := '+' ; while (cur->compareTo((s)->size())) < 0 do ( if ('+*')->characters()->includes(s[cur+1]) then ( if op <>= '+' then ( res := res + num ) else ( res := res * num ) ; num := 0; op := s[cur+1] ) else ( num := 10 * num + ("" + ((s[cur+1])))->toInteger() ) ; cur := cur + 1) ; if op <>= '+' then ( res := res + num ) else ( res := res * num ) ; return res; operation parse2(s : OclAny) : OclAny pre: true post: true activity: cur := 0 ; skip ; skip ; skip ; return expr(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- arr=[input(),input(),input(),input()] exit=False for i in range(3): if exit : break for j in range(3): countw=0 countb=0 if arr[i][j]=="#" : countb+=1 else : countw+=1 if arr[i+1][j]=="#" : countb+=1 else : countw+=1 if arr[i][j+1]=="#" : countb+=1 else : countw+=1 if arr[i+1][j+1]=="#" : countb+=1 else : countw+=1 if countw>=3 or countb>=3 : print("YES") exit=True break if not exit : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var arr : Sequence := Sequence{(OclFile["System.in"]).readLine()}->union(Sequence{(OclFile["System.in"]).readLine()}->union(Sequence{(OclFile["System.in"]).readLine()}->union(Sequence{ (OclFile["System.in"]).readLine() }))) ; var exit : boolean := false ; for i : Integer.subrange(0, 3-1) do ( if exit then ( break ) else skip ; for j : Integer.subrange(0, 3-1) do ( var countw : int := 0 ; var countb : int := 0 ; if arr[i+1][j+1] = "#" then ( countb := countb + 1 ) else ( countw := countw + 1 ) ; if arr[i + 1+1][j+1] = "#" then ( countb := countb + 1 ) else ( countw := countw + 1 ) ; if arr[i+1][j + 1+1] = "#" then ( countb := countb + 1 ) else ( countw := countw + 1 ) ; if arr[i + 1+1][j + 1+1] = "#" then ( countb := countb + 1 ) else ( countw := countw + 1 ) ; if countw >= 3 or countb >= 3 then ( execute ("YES")->display() ; exit := true ; break ) else skip)) ; if not(exit) then ( execute ("NO")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def isToeplitzMatrix(self,matrix): for r in range(len(matrix)-1): for c in range(len(matrix[0])-1): if matrix[r][c]!=matrix[r+1][c+1]: return False return True ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation isToeplitzMatrix(matrix : OclAny) : OclAny pre: true post: true activity: for r : Integer.subrange(0, (matrix)->size() - 1-1) do ( for c : Integer.subrange(0, (matrix->first())->size() - 1-1) do ( if matrix[r+1][c+1] /= matrix[r + 1+1][c + 1+1] then ( return false ) else skip)) ; return true; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib,fractions,itertools def compute(): LIMIT=10**9 ans=0 for s in itertools.count(1,2): if s*s>(LIMIT+1)//3 : break for t in range(s-2,0,-2): if fractions.gcd(s,t)==1 : a=s*t b=(s*s-t*t)//2 c=(s*s+t*t)//2 if a*2==c-1 : p=c*3-1 if p<=LIMIT : ans+=p if a*2==c+1 : p=c*3+1 if p<=LIMIT : ans+=p if b*2==c-1 : p=c*3-1 if p<=LIMIT : ans+=p if b*2==c+1 : p=c*3+1 if p<=LIMIT : ans+=p return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LIMIT : double := (10)->pow(9) ; var ans : int := 0 ; for s : itertools->count(1, 2) do ( if (s * s->compareTo((LIMIT + 1) div 3)) > 0 then ( break ) else skip ; for t : Integer.subrange(s - 2, 0-1)->select( $x | ($x - s - 2) mod -2 = 0 ) do ( if fractions.gcd(s, t) = 1 then ( var a : double := s * t ; var b : int := (s * s - t * t) div 2 ; var c : int := (s * s + t * t) div 2 ; if a * 2 = c - 1 then ( var p : double := c * 3 - 1 ; if (p->compareTo(LIMIT)) <= 0 then ( ans := ans + p ) else skip ) else skip ; if a * 2 = c + 1 then ( p := c * 3 + 1 ; if (p->compareTo(LIMIT)) <= 0 then ( ans := ans + p ) else skip ) else skip ; if b * 2 = c - 1 then ( p := c * 3 - 1 ; if (p->compareTo(LIMIT)) <= 0 then ( ans := ans + p ) else skip ) else skip ; if b * 2 = c + 1 then ( p := c * 3 + 1 ; if (p->compareTo(LIMIT)) <= 0 then ( ans := ans + p ) else skip ) else skip ) else skip)) ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,t,L,b=(int(s)for s in input().split()) if(n,t,L,b)==(0,0,0,0): break loses=[int(input())for i in range(L)] backs=[int(input())for i in range(b)] dp=[[0.]*n+[1.]for i in range(3)] stops=list(range(n+1))+list(reversed(range(n-5,n))) for i in reversed(range(t)): for j in range(n): dp[i % 3][j]=sum(dp[(i+2)% 3][d]if d in loses else dp[(i+1)% 3][0]if d in backs else dp[(i+1)% 3][d]for d in stops[j+1 : j+7])/6 print('{:.6f}'.format(dp[0][0])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var t : OclAny := null; var L : OclAny := null; var b : OclAny := null; Sequence{n,t,L,b} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; if Sequence{n, t, L, b} = Sequence{0, 0, 0, 0} then ( break ) else skip ; var loses : Sequence := Integer.subrange(0, L-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var backs : Sequence := Integer.subrange(0, b-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var dp : Sequence := Integer.subrange(0, 3-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0. }, n)->union(Sequence{ 1. }))) ; var stops : Sequence := (Integer.subrange(0, n + 1-1))->union(((Integer.subrange(n - 5, n-1))->reverse())) ; for i : (Integer.subrange(0, t-1))->reverse() do ( for j : Integer.subrange(0, n-1) do ( dp[i mod 3+1][j+1] := ((argument (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 2))))))))) ))) % (expr (atom (number (integer 3)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name d)))))))) ]))))) if (logical_test (comparison (comparison (expr (atom (name d)))) in (comparison (expr (atom (name loses)))))) else (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) ))) % (expr (atom (number (integer 3)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))) if (logical_test (comparison (comparison (expr (atom (name d)))) in (comparison (expr (atom (name backs)))))) else (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) ))) % (expr (atom (number (integer 3)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name d)))))))) ])))))))) (comp_for for (exprlist (expr (atom (name d)))) in (logical_test (comparison (expr (atom (name stops)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 1)))))))) : (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 7)))))))))) ]))))))))->sum() / 6)) ; execute (StringLib.interpolateStrings('{:.6f}', Sequence{dp->first()->first()}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(N,T,L,B): route=[-1]*(N+1) for _ in range(L): x=int(input()) route[x]=0 for _ in range(B): y=int(input()) route[y]=1 ans=0 before=[0]*(N+1) before[0]=1 beforebefore=[0]*(N+1) for _ in range(T): now=[0]*(N+1) future=[0]*(N+1) for i in range(N): for j in range(1,7): X=i+j if X>=N+1 : X=N-(X-N) if route[X]==-1 : now[X]+=before[i]/6 elif route[X]==0 : future[X]+=before[i]/6 else : now[0]+=before[i]/6 ans+=now[-1] before=[0]*(N+1) for i in range(N+1): before[i]=now[i]+beforebefore[i] beforebefore=future print("{:9f}".format(ans)) def main(): while True : N,T,L,B=map(int,input().split()) if N==0 : return solve(N,T,L,B) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(N : OclAny, T : OclAny, L : OclAny, B : OclAny) pre: true post: true activity: var route : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (N + 1)) ; for _anon : Integer.subrange(0, L-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; route[x+1] := 0) ; for _anon : Integer.subrange(0, B-1) do ( var y : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; route[y+1] := 1) ; var ans : int := 0 ; var before : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; before->first() := 1 ; var beforebefore : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; for _anon : Integer.subrange(0, T-1) do ( var now : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; var future : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(1, 7-1) do ( var X : OclAny := i + j ; if (X->compareTo(N + 1)) >= 0 then ( X := N - (X - N) ) else skip ; if route[X+1] = -1 then ( now[X+1] := now[X+1] + before[i+1] / 6 ) else (if route[X+1] = 0 then ( future[X+1] := future[X+1] + before[i+1] / 6 ) else ( now->first() := now->first() + before[i+1] / 6 ) ) )) ; ans := ans + now->last() ; before := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; for i : Integer.subrange(0, N + 1-1) do ( before[i+1] := now[i+1] + beforebefore[i+1]) ; beforebefore := future) ; execute (StringLib.interpolateStrings("{:9f}", Sequence{ans}))->display(); operation main() pre: true post: true activity: while true do ( Sequence{N,T,L,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if N = 0 then ( return ) else skip ; solve(N, T, L, B)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : N,T,L,B=map(int,input().split()) if not(N | T | L | B): break Lose=[False for i in range(N+1)] Back=[False for i in range(N+1)] for i in range(L): Lose[int(input())]=True for j in range(B): Back[int(input())]=True dp=[[0.0 for j in range(N+1)]for i in range(T+2)] dp[0][0]=1.0 for t in range(T): for n in range(N): for k in range(1,7): tmp=n+k if n+k>N : tmp=N-n-k-1 if Lose[tmp]: dp[t+2][tmp]+=dp[t][n]/6 elif Back[tmp]: dp[t+1][0]+=dp[t][n]/6 else : dp[t+1][tmp]+=dp[t][n]/6 ans=0.0 for i in range(T+2): ans+=dp[i][N] print("{0:.6f}".format(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var N : OclAny := null; var T : OclAny := null; var L : OclAny := null; var B : OclAny := null; Sequence{N,T,L,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if not((MathLib.bitwiseOr(MathLib.bitwiseOr(MathLib.bitwiseOr(N, T), L), B))) then ( break ) else skip ; var Lose : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (false)) ; var Back : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (false)) ; for i : Integer.subrange(0, L-1) do ( Lose[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1] := true) ; for j : Integer.subrange(0, B-1) do ( Back[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1] := true) ; var dp : Sequence := Integer.subrange(0, T + 2-1)->select(i | true)->collect(i | (Integer.subrange(0, N + 1-1)->select(j | true)->collect(j | (0.0)))) ; dp->first()->first() := 1.0 ; for t : Integer.subrange(0, T-1) do ( for n : Integer.subrange(0, N-1) do ( for k : Integer.subrange(1, 7-1) do ( var tmp : OclAny := n + k ; if (n + k->compareTo(N)) > 0 then ( tmp := N - n - k - 1 ) else skip ; if Lose[tmp+1] then ( dp[t + 2+1][tmp+1] := dp[t + 2+1][tmp+1] + dp[t+1][n+1] / 6 ) else (if Back[tmp+1] then ( dp[t + 1+1]->first() := dp[t + 1+1]->first() + dp[t+1][n+1] / 6 ) else ( dp[t + 1+1][tmp+1] := dp[t + 1+1][tmp+1] + dp[t+1][n+1] / 6 ) ) ))) ; var ans : double := 0.0 ; for i : Integer.subrange(0, T + 2-1) do ( ans := ans + dp[i+1][N+1]) ; execute (StringLib.interpolateStrings("{0:.6f}", Sequence{ans}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): from sys import stdin f_i=stdin while True : N,T,L,B=map(int,f_i.readline().split()) if N==0 : break skip={} sq_attr=[None]*N for i in range(L): sq=int(f_i.readline()) sq_attr[sq]='Lose' skip[sq]=0 for i in range(B): sq_attr[int(f_i.readline())]='Back' dp1=[0]*N dp2=[0]*N dp1[0]=1 ans=0 for i in range(T): for sq,pr in skip.items(): tmp=dp1[sq] dp1[sq]=pr skip[sq]=tmp for sq,pr in enumerate(dp1): if pr==0 : continue new_pr=pr/6 for next_sq in range(sq+1,sq+7): if next_sq>N : next_sq=2*N-next_sq elif next_sq==N : ans+=new_pr continue if sq_attr[next_sq]=='Back' : next_sq=0 dp2[next_sq]+=new_pr dp1=dp2 dp2=[0]*N print('{:.6f}'.format(ans)) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: skip ; var f_i : OclAny := stdin ; while true do ( var N : OclAny := null; var T : OclAny := null; var L : OclAny := null; var B : OclAny := null; Sequence{N,T,L,B} := (f_i.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if N = 0 then ( break ) else skip ; var skip : OclAny := Set{} ; var sq_attr : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, N) ; for i : Integer.subrange(0, L-1) do ( var sq : int := ("" + ((f_i.readLine())))->toInteger() ; sq_attr[sq+1] := 'Lose' ; skip[sq+1] := 0) ; for i : Integer.subrange(0, B-1) do ( sq_attr[("" + ((f_i.readLine())))->toInteger()+1] := 'Back') ; var dp1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var dp2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; dp1->first() := 1 ; var ans : int := 0 ; for i : Integer.subrange(0, T-1) do ( for _tuple : skip->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var sq : OclAny := _tuple->at(_indx); _indx := _indx + 1; var pr : OclAny := _tuple->at(_indx); var tmp : OclAny := dp1[sq+1] ; dp1[sq+1] := pr ; skip[sq+1] := tmp) ; for _tuple : Integer.subrange(1, (dp1)->size())->collect( _indx | Sequence{_indx-1, (dp1)->at(_indx)} ) do (var _indx : int := 1; var sq : OclAny := _tuple->at(_indx); _indx := _indx + 1; var pr : OclAny := _tuple->at(_indx); if pr = 0 then ( continue ) else skip ; var new_pr : double := pr / 6 ; for next_sq : Integer.subrange(sq + 1, sq + 7-1) do ( if (next_sq->compareTo(N)) > 0 then ( var next_sq : double := 2 * N - next_sq ) else (if next_sq = N then ( ans := ans + new_pr ; continue ) else skip) ; if sq_attr[next_sq+1] = 'Back' then ( next_sq := 0 ) else skip ; dp2[next_sq+1] := dp2[next_sq+1] + new_pr)) ; dp1 := dp2 ; dp2 := MatrixLib.elementwiseMult(Sequence{ 0 }, N)) ; execute (StringLib.interpolateStrings('{:.6f}', Sequence{ans}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cnt=input() for k in range(int(cnt)): ip=input() if ip=="" : print("0000:0000:0000:0000:0000:0000:0000:0000") continue ip=ip.split(":") ret="" if ip[0]=="" : ip=["0000"]*(8-len(ip)+2)+ip[2 :] elif ip[-1]=="" : ip=ip[:-2]+["0000"]*(8-len(ip)+2) for i in range(len(ip)): if ip[i]=="" : ip=ip[: i]+["0000"]*(8-len(ip)+1)+ip[i+1 :] for i in range(len(ip)): if ip[i]!="" : ip[i]="0"*(4-len(ip[i]))+ip[i] print(":".join(ip)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cnt : String := (OclFile["System.in"]).readLine() ; for k : Integer.subrange(0, ("" + ((cnt)))->toInteger()-1) do ( var ip : String := (OclFile["System.in"]).readLine() ; if ip = "" then ( execute ("0000:0000:0000:0000:0000:0000:0000:0000")->display() ; continue ) else skip ; ip := ip.split(":") ; var ret : String := "" ; if ip->first() = "" then ( ip := MatrixLib.elementwiseMult(Sequence{ "0000" }, (8 - (ip)->size() + 2))->union(ip.subrange(2+1)) ) else (if ip->last() = "" then ( ip := ip->front()->front()->union(MatrixLib.elementwiseMult(Sequence{ "0000" }, (8 - (ip)->size() + 2))) ) else skip) ; for i : Integer.subrange(0, (ip)->size()-1) do ( if ip[i+1] = "" then ( ip := ip.subrange(1,i)->union(MatrixLib.elementwiseMult(Sequence{ "0000" }, (8 - (ip)->size() + 1))) + ip.subrange(i + 1+1) ) else skip) ; for i : Integer.subrange(0, (ip)->size()-1) do ( if ip[i+1] /= "" then ( ip[i+1] := StringLib.nCopies("0", (4 - (ip[i+1])->size())) + ip[i+1] ) else skip) ; execute (StringLib.sumStringsWithSeparator((ip), ":"))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def inpl(): return list(map(int,input().split())) while True : N,T,L,B=inpl() if N==0 : break lose=[int(input())for _ in range(L)] back=[int(input())for _ in range(B)] mass=[0]*(N+1) for l in lose : mass[l]=1 for b in back : mass[b]=2 dp=[[0]*(N+1)for _ in range(T+3)] dp[0][0]=1.0 for i in range(T+1): for j in range(N): if dp[i][j]==0.0 : continue for k in range(1,7): curr=j+k if curr>N : curr=N-curr % N if mass[curr]==0 : dp[i+1][curr]+=dp[i][j]/6.0 elif mass[curr]==1 : dp[i+2][curr]+=dp[i][j]/6.0 else : dp[i+1][0]+=dp[i][j]/6.0 ans=0 for i in range(T+1): ans+=dp[i][N] print('{:.6f}'.format(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; while true do ( var N : OclAny := null; var T : OclAny := null; var L : OclAny := null; var B : OclAny := null; Sequence{N,T,L,B} := inpl() ; if N = 0 then ( break ) else skip ; var lose : Sequence := Integer.subrange(0, L-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var back : Sequence := Integer.subrange(0, B-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var mass : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; for l : lose do ( mass[l+1] := 1) ; for b : back do ( mass[b+1] := 2) ; var dp : Sequence := Integer.subrange(0, T + 3-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)))) ; dp->first()->first() := 1.0 ; for i : Integer.subrange(0, T + 1-1) do ( for j : Integer.subrange(0, N-1) do ( if dp[i+1][j+1] = 0.0 then ( continue ) else skip ; for k : Integer.subrange(1, 7-1) do ( var curr : OclAny := j + k ; if (curr->compareTo(N)) > 0 then ( curr := N - curr mod N ) else skip ; if mass[curr+1] = 0 then ( dp[i + 1+1][curr+1] := dp[i + 1+1][curr+1] + dp[i+1][j+1] / 6.0 ) else (if mass[curr+1] = 1 then ( dp[i + 2+1][curr+1] := dp[i + 2+1][curr+1] + dp[i+1][j+1] / 6.0 ) else ( dp[i + 1+1]->first() := dp[i + 1+1]->first() + dp[i+1][j+1] / 6.0 ) ) ))) ; var ans : int := 0 ; for i : Integer.subrange(0, T + 1-1) do ( ans := ans + dp[i+1][N+1]) ; execute (StringLib.interpolateStrings('{:.6f}', Sequence{ans}))->display()); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- stdin=input() s=stdin result="Yes" if "A" in s and "B" in s else "No" print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var stdin : String := (OclFile["System.in"]).readLine() ; var s : String := stdin ; var result : String := if (s)->characters()->includes("A") & (s)->characters()->includes("B") then "Yes" else "No" endif ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from fractions import gcd from itertools import groupby as gb from itertools import permutations as perm from itertools import combinations as comb from collections import Counter as C from collections import defaultdict as dd sys.setrecursionlimit(10**5) def y(f): if f : print('Yes') else : print('No') def Y(f): if f : print('YES') else : print('NO') def Z(f): if f : print('Yay!') else : print(':(') def ispow(n): if int(n**.5)**2==n : return True return False y(len(set(list(input())))==2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(5)) ; skip ; skip ; skip ; skip ; y((Set{}->union((((OclFile["System.in"]).readLine())->characters())))->size() = 2); operation y(f : OclAny) pre: true post: true activity: if f then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); operation Y(f : OclAny) pre: true post: true activity: if f then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); operation Z(f : OclAny) pre: true post: true activity: if f then ( execute ('Yay!')->display() ) else ( execute (':(')->display() ); operation ispow(n : OclAny) : OclAny pre: true post: true activity: if (("" + (((n)->pow(.5))))->toInteger())->pow(2) = n then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re class c(int): def __add__(self,n): return c(int(self)+int(n)) def __mul__(self,n): return c(int(self)*int(n)) s=input() d=int(input()) a=eval(re.sub(r'(\d+)',r'c(\1)',s)) b=int(s[0]) for i in range(1,len(s),2): if s[i]=='+' : b+=int(s[i+1]) else : b*=int(s[i+1]) if(a==b==d): e='U' elif(a==d): e='M' elif(b==d): e='L' else : e='I' print(e) ------------------------------------------------------------ OCL File: --------- class c extends OclType["int"] { static operation newc() : c pre: true post: c->exists( _x | result = _x ); operation __add__(n : OclAny) : OclAny pre: true post: true activity: return c(("" + ((self)))->toInteger() + ("" + ((n)))->toInteger()); operation __mul__(n : OclAny) : OclAny pre: true post: true activity: return c(("" + ((self)))->toInteger() * ("" + ((n)))->toInteger()); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var s : String := (OclFile["System.in"]).readLine() ; var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := (s).replaceAllMatches(StringLib.rawString('(\d+)'), StringLib.rawString('c(\1)')) ; var b : int := ("" + ((s->first())))->toInteger() ; for i : Integer.subrange(1, (s)->size()-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( if s[i+1] = '+' then ( b := b + ("" + ((s[i + 1+1])))->toInteger() ) else ( b := b * ("" + ((s[i + 1+1])))->toInteger() )) ; if (a = b & (b == d)) then ( var e : String := 'U' ) else (if (a = d) then ( e := 'M' ) else (if (b = d) then ( e := 'L' ) else ( e := 'I' ) ) ) ; execute (e)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from typing import* import collections import functools import itertools import math import sys INF=float('inf') YES="Yes" NO="No" def solve(S : str): return[YES,NO][S[0]==S[1]==S[2]] def main(): sys.setrecursionlimit(10**6) def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() S=next(tokens) print(f'{solve(S)}') if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var INF : double := ("" + (('inf')))->toReal() ; var YES : String := "Yes" ; var NO : String := "No" ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(S : String) : OclAny pre: true post: true activity: return Sequence{YES}->union(Sequence{ NO })->select(S->first() = S[1+1] & (S[1+1] == S[2+1])); operation main() pre: true post: true activity: sys.setrecursionlimit((10)->pow(6)) ; skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var S : OclAny := (tokens).next() ; execute (StringLib.formattedString('{solve(S)}'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(input()) number=s.count('A') if number==len(s)or number==0 : print('No') else : print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var number : int := s->count('A') ; if number = (s)->size() or number = 0 then ( execute ('No')->display() ) else ( execute ('Yes')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sep(): return map(int,input().strip().split(" ")) def lis(): return list(sep()) s=input() from collections import Counter c=Counter(s) if len(c.keys())>=2 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var s : String := (OclFile["System.in"]).readLine() ; skip ; var c : OclAny := Counter(s) ; if (c.keys())->size() >= 2 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation sep() : OclAny pre: true post: true activity: return (input()->trim().split(" "))->collect( _x | (OclType["int"])->apply(_x) ); operation lis() : OclAny pre: true post: true activity: return (sep()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : for _ in range(int(input())): n=int(input()) arr=tuple(map(int,input().split())) odd_count,even_count,odd_sum=0,0,0 for i in arr : if i & 1 : odd_sum+=i odd_count+=1 else : even_count+=1 if odd_sum % 2 : print("YES") elif odd_count>0 and even_count>0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var odd_count : OclAny := null; var even_count : OclAny := null; var odd_sum : OclAny := null; Sequence{odd_count,even_count,odd_sum} := Sequence{0,0,0} ; for i : arr do ( if MathLib.bitwiseAnd(i, 1) then ( odd_sum := odd_sum + i ; odd_count := odd_count + 1 ) else ( even_count := even_count + 1 )) ; if odd_sum mod 2 then ( execute ("YES")->display() ) else (if odd_count > 0 & even_count > 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) arr=[] even=0 odd=0 for i in range(t): a=int(input()) arr=list(map(int,input().split())) for i in range(len(arr)): if(arr[i]% 2==0): even+=1 else : odd+=1 if(odd==0 or(even==0 and odd % 2==0)): print("NO") else : print("YES") even=0 odd=0 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Sequence{} ; var even : int := 0 ; var odd : int := 0 ; for i : Integer.subrange(0, t-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; arr := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, (arr)->size()-1) do ( if (arr[i+1] mod 2 = 0) then ( even := even + 1 ) else ( odd := odd + 1 )) ; if (odd = 0 or (even = 0 & odd mod 2 = 0)) then ( execute ("NO")->display() ) else ( execute ("YES")->display() ) ; even := 0 ; odd := 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) s=list(map(int,input().split())) if sum(s)% 2!=0 : print('Yes') else : e,o=0,0 for i in range(n): if e==1 and o==1 : break if s[i]% 2==0 : e=1 else : o=1 if e==1 and o==1 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (s)->sum() mod 2 /= 0 then ( execute ('Yes')->display() ) else ( var e : OclAny := null; var o : OclAny := null; Sequence{e,o} := Sequence{0,0} ; for i : Integer.subrange(0, n-1) do ( if e = 1 & o = 1 then ( break ) else skip ; if s[i+1] mod 2 = 0 then ( var e : int := 1 ) else ( var o : int := 1 )) ; if e = 1 & o = 1 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def _ip_(ipv6): l=7-(len(ipv6)-len(ipv6.replace(":","",))) ipv6=ipv6.replace("::",":"*(l+2)) list=ipv6.split(":",) ip=["","","","","","","",""] for i in range(0,8): t=list[i] while len(t)!=4 : t="0"+t ip[i]=t t="" for i in range(0,8): t+=ip[i]+":" print(t[: len(t)-1 :]) l=int(input()) for i in range(0,l): _ip_(input()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; l := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, l-1) do ( _ip_((OclFile["System.in"]).readLine())); operation _ip_(ipv6 : OclAny) pre: true post: true activity: var l : double := 7 - ((ipv6)->size() - (ipv6.replace(":", (arglist (argument (test (logical_test (comparison (expr (atom "")))))) ,)))->size()) ; ipv6 := ipv6.replace("::", StringLib.nCopies(":", (l + 2))) ; var OclType["Sequence"] : OclAny := ipv6.split((arglist (argument (test (logical_test (comparison (expr (atom ":")))))) ,)) ; var ip : Sequence := Sequence{""}->union(Sequence{""}->union(Sequence{""}->union(Sequence{""}->union(Sequence{""}->union(Sequence{""}->union(Sequence{""}->union(Sequence{ "" }))))))) ; for i : Integer.subrange(0, 8-1) do ( var t : Sequence := [i+1] ; while (t)->size() /= 4 do ( t := "0"->union(t)) ; ip[i+1] := t) ; t := "" ; for i : Integer.subrange(0, 8-1) do ( t := t + ip[i+1] + ":") ; execute (t(subscript : (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) )))) - (expr (atom (number (integer 1)))))))) (sliceop :)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) odd=0 even=0 sum=0 for i in range(n): if a[i]% 2!=0 or a[i]==1 : odd+=1 else : even+=1 sum+=a[i] if sum % 2!=0 or sum==1 : print("YES") else : if(odd!=0 and even!=0): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var odd : int := 0 ; var even : int := 0 ; var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( if a[i+1] mod 2 /= 0 or a[i+1] = 1 then ( odd := odd + 1 ) else ( even := even + 1 ) ; sum := sum + a[i+1]) ; if sum mod 2 /= 0 or sum = 1 then ( execute ("YES")->display() ) else ( if (odd /= 0 & even /= 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for test in range(t): n=int(input()) numbers=list(map(int,input().split())) l=len(numbers) i=0 for x in numbers : if x % 2==0 : i+=1 if i==l : print('NO') else : i=0 for x in numbers : if x % 2==1 : i+=1 if i==l and l % 2==0 : print('NO') else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for test : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var numbers : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : int := (numbers)->size() ; var i : int := 0 ; for x : numbers do ( if x mod 2 = 0 then ( i := i + 1 ) else skip) ; if i = l then ( execute ('NO')->display() ) else ( i := 0 ; for x : numbers do ( if x mod 2 = 1 then ( i := i + 1 ) else skip) ; if i = l & l mod 2 = 0 then ( execute ('NO')->display() ) else ( execute ('YES')->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def minInsertions(H,n,K): inser=0 ; for i in range(1,n): diff=abs(H[i]-H[i-1]); if(diff<=K): continue ; else : inser+=math.ceil(diff/K)-1 ; return inser ; H=[2,4,8,16]; K=3 ; n=len(H); print(minInsertions(H,n,K)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; H := Sequence{2}->union(Sequence{4}->union(Sequence{8}->union(Sequence{ 16 }))); ; K := 3; ; n := (H)->size(); ; execute (minInsertions(H, n, K))->display();; operation minInsertions(H : OclAny, n : OclAny, K : OclAny) pre: true post: true activity: var inser : int := 0; ; for i : Integer.subrange(1, n-1) do ( var diff : double := (H[i+1] - H[i - 1+1])->abs(); ; if ((diff->compareTo(K)) <= 0) then ( continue; ) else ( inser := inser + (diff / K)->ceil() - 1; )) ; return inser;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countWords(str,l): count=1 ; if(l==1): return count if(str[0]==str[1]): count*=1 else : count*=2 for j in range(1,l-1): if(str[j]==str[j-1]and str[j]==str[j+1]): count*=1 elif(str[j]==str[j-1]or str[j]==str[j+1]or str[j-1]==str[j+1]): count*=2 else : count*=3 if(str[l-1]==str[l-2]): count*=1 else : count*=2 return count if __name__=="__main__" : str="abc" l=len(str) print(countWords(str,l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( OclType["String"] := "abc" ; l := (OclType["String"])->size() ; execute (countWords(OclType["String"], l))->display() ) else skip; operation countWords(OclType["String"] : OclAny, l : OclAny) : OclAny pre: true post: true activity: var count : int := 1; ; if (l = 1) then ( return count ) else skip ; if (("" + (->first())) = ("" + ([1+1]))) then ( count := count * 1 ) else ( count := count * 2 ) ; for j : Integer.subrange(1, l - 1-1) do ( if (("" + ([j+1])) = ("" + ([j - 1+1])) & ("" + ([j+1])) = ("" + ([j + 1+1]))) then ( count := count * 1 ) else (if (("" + ([j+1])) = ("" + ([j - 1+1])) or ("" + ([j+1])) = ("" + ([j + 1+1])) or ("" + ([j - 1+1])) = ("" + ([j + 1+1]))) then ( count := count * 2 ) else ( count := count * 3 ) ) ) ; if (("" + ([l - 1+1])) = ("" + ([l - 2+1]))) then ( count := count * 1 ) else ( count := count * 2 ) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def left2right(formula): ans=int(formula[0]) for i in range(1,len(formula),2): ans=eval(str(ans)+formula[i : i+2]) return ans formula=input() val=int(input()) if left2right(formula)==val : print('U' if eval(formula)==val else 'L') else : print('M' if eval(formula)==val else 'I') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; formula := (OclFile["System.in"]).readLine() ; var val : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if left2right(formula) = val then ( execute (if formula = val then 'U' else 'L' endif)->display() ) else ( execute (if formula = val then 'M' else 'I' endif)->display() ); operation left2right(formula : OclAny) : OclAny pre: true post: true activity: var ans : int := ("" + ((formula->first())))->toInteger() ; for i : Integer.subrange(1, (formula)->size()-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( ans := ("" + ((ans))) + formula.subrange(i+1, i + 2)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) l=sorted(list(map(int,input().split()))) s=sum(l) if s % 2==0 : print(s) else : for i in l : if i % 2!=0 : print(s-i) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var s : OclAny := (l)->sum() ; if s mod 2 = 0 then ( execute (s)->display() ) else ( for i : l do ( if i mod 2 /= 0 then ( execute (s - i)->display() ; break ) else skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) chis=list(map(int,input().split())) sm=sum(chis) minnech=0 if sm % 2==0 : print(sm) else : for i in range(n): if chis[i]% 2!=0 : if minnech==0 : minnech=chis[i] elif chis[i]toInteger() ; var chis : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sm : OclAny := (chis)->sum() ; var minnech : int := 0 ; if sm mod 2 = 0 then ( execute (sm)->display() ) else ( for i : Integer.subrange(0, n-1) do ( if chis[i+1] mod 2 /= 0 then ( if minnech = 0 then ( minnech := chis[i+1] ) else (if (chis[i+1]->compareTo(minnech)) < 0 then ( minnech := chis[i+1] ) else skip) ) else skip) ; execute (sm - minnech)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() numbers=list(map(int,input().split())) odd_numbers=list(filter((2).__rmod__,numbers)) total,odd_count_is_odd=sum(numbers),len(odd_numbers)% 2 print(total-min(odd_numbers)if odd_count_is_odd else total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var numbers : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var odd_numbers : Sequence := ((numbers)->select( _x | ((2).__rmod__)->apply(_x) = true )) ; var total : OclAny := null; var odd_count_is_odd : OclAny := null; Sequence{total,odd_count_is_odd} := Sequence{(numbers)->sum(),(odd_numbers)->size() mod 2} ; execute (if odd_count_is_odd then total - (odd_numbers)->min() else total endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input('')) l=list(map(int,input().split())) l1=list(filter(lambda x : x % 2==0,l)) l2=list(filter(lambda x : x % 2!=0,l)) if len(l2)>0 : if len(l2)% 2==0 : print(sum(l1)+sum(l2)) else : l2.remove(min(l2)) if len(l2)>0 : print(sum(l1)+sum(l2)) else : print(sum(l1)) else : print(sum(l1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l1 : Sequence := ((l)->select( _x | (lambda x : OclAny in (x mod 2 = 0))->apply(_x) = true )) ; var l2 : Sequence := ((l)->select( _x | (lambda x : OclAny in (x mod 2 /= 0))->apply(_x) = true )) ; if (l2)->size() > 0 then ( if (l2)->size() mod 2 = 0 then ( execute ((l1)->sum() + (l2)->sum())->display() ) else ( execute (((l2)->min()) /: l2) ; if (l2)->size() > 0 then ( execute ((l1)->sum() + (l2)->sum())->display() ) else ( execute ((l1)->sum())->display() ) ) ) else ( execute ((l1)->sum())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lst=list(map(int,input().split())) lst.sort() lst.reverse() od=0 for i in lst : if(i & 1): od+=1 sum=0 ok=0 for i in range(n): if(lst[i]% 2==0): sum+=lst[i] else : if(ok or od>1): sum+=lst[i] od-=1 ok=not ok print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; lst := lst->sort() ; lst := lst->reverse() ; var od : int := 0 ; for i : lst do ( if (MathLib.bitwiseAnd(i, 1)) then ( od := od + 1 ) else skip) ; var sum : int := 0 ; var ok : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (lst[i+1] mod 2 = 0) then ( sum := sum + lst[i+1] ) else ( if (ok or od > 1) then ( sum := sum + lst[i+1] ; od := od - 1 ; ok := not(ok) ) else skip )) ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): s=input()[:-1].split(':') c=0 for i in s : if i!='' : c+=1 d=[] x=0 for i in s : if i!='' : d.append(i.rjust(4,'0')) else : if x==0 : x=1 d.extend(['0000' for _ in range(8-c)]) print(':'.join(d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : OclAny := input()->front().split(':') ; var c : int := 0 ; for i : s do ( if i /= '' then ( c := c + 1 ) else skip) ; var d : Sequence := Sequence{} ; var x : int := 0 ; for i : s do ( if i /= '' then ( execute ((StringLib.padLeftWithInto(i, '0', 4)) : d) ) else ( if x = 0 then ( x := 1 ; d := d->union(Integer.subrange(0, 8 - c-1)->select(_anon | true)->collect(_anon | ('0000'))) ) else skip )) ; execute (StringLib.sumStringsWithSeparator((d), ':'))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getPerfectSquares(n): perfectSquares=[]; current=1 ; i=1 ; while(current<=n): perfectSquares.append(current); i+=1 ; current=int(pow(i,2)); return perfectSquares ; def maxPairSum(arr): n=len(arr); max=0 ; secondMax=0 ; if(arr[0]>arr[1]): max=arr[0]; secondMax=arr[1]; else : max=arr[1]; secondMax=arr[0]; for i in range(2,n): if(arr[i]>max): secondMax=max ; max=arr[i]; elif(arr[i]>secondMax): secondMax=arr[i]; return(max+secondMax); def countPairsWith(n,perfectSquares,nums): count=0 ; for i in range(len(perfectSquares)): temp=perfectSquares[i]-n ; if(temp>n and(temp in nums)): count+=1 ; return count ; def countPairs(arr): n=len(arr); max=maxPairSum(arr); perfectSquares=getPerfectSquares(max); nums=[]; for i in range(n): nums.append(arr[i]); count=0 ; for i in range(n): count+=countPairsWith(arr[i],perfectSquares,nums); return count ; arr=[2,3,6,9,10,20]; print(countPairs(arr)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; arr := Sequence{2}->union(Sequence{3}->union(Sequence{6}->union(Sequence{9}->union(Sequence{10}->union(Sequence{ 20 }))))); ; execute (countPairs(arr))->display();; operation getPerfectSquares(n : OclAny) pre: true post: true activity: var perfectSquares : Sequence := Sequence{}; ; var current : int := 1; ; var i : int := 1; ; while ((current->compareTo(n)) <= 0) do ( execute ((current) : perfectSquares); ; i := i + 1; ; current := ("" + (((i)->pow(2))))->toInteger();) ; return perfectSquares;; operation maxPairSum(arr : OclAny) pre: true post: true activity: n := (arr)->size(); ; var max : int := 0; ; var secondMax : int := 0; ; if ((arr->first()->compareTo(arr[1+1])) > 0) then ( max := arr->first(); ; secondMax := arr[1+1]; ) else ( max := arr[1+1]; ; secondMax := arr->first(); ) ; for i : Integer.subrange(2, n-1) do ( if ((arr[i+1]->compareTo(max)) > 0) then ( secondMax := max; ; max := arr[i+1]; ) else (if ((arr[i+1]->compareTo(secondMax)) > 0) then ( secondMax := arr[i+1]; ) else skip)) ; return (max + secondMax);; operation countPairsWith(n : OclAny, perfectSquares : OclAny, nums : OclAny) pre: true post: true activity: var count : int := 0; ; for i : Integer.subrange(0, (perfectSquares)->size()-1) do ( var temp : double := perfectSquares[i+1] - n; ; if ((temp->compareTo(n)) > 0 & ((nums)->includes(temp))) then ( count := count + 1; ) else skip) ; return count;; operation countPairs(arr : OclAny) pre: true post: true activity: n := (arr)->size(); ; max := maxPairSum(arr); ; perfectSquares := getPerfectSquares(max); ; nums := Sequence{}; ; for i : Integer.subrange(0, n-1) do ( execute ((arr[i+1]) : nums);) ; count := 0; ; for i : Integer.subrange(0, n-1) do ( count := count + countPairsWith(arr[i+1], perfectSquares, nums);) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findHypotenuse(side1,side2): h=(((side1*side1)+(side2*side2))**(1/2)); return h ; side1=3 ; side2=4 ; print(findHypotenuse(side1,side2)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; side1 := 3; ; side2 := 4; ; execute (findHypotenuse(side1, side2))->display();; operation findHypotenuse(side1 : OclAny, side2 : OclAny) pre: true post: true activity: var h : double := ((((side1 * side1) + (side2 * side2)))->pow((1 / 2))); ; return h;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printTwoOdd(arr,size): xor2=arr[0] set_bit_no=0 n=size-2 x,y=0,0 for i in range(1,size): xor2=xor2 ^ arr[i] set_bit_no=xor2 & ~(xor2-1) for i in range(size): if(arr[i]& set_bit_no): x=x ^ arr[i] else : y=y ^ arr[i] print("The two ODD elements are",x,"&",y) arr=[4,2,4,5,2,3,3,1] arr_size=len(arr) printTwoOdd(arr,arr_size) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{4}->union(Sequence{2}->union(Sequence{4}->union(Sequence{5}->union(Sequence{2}->union(Sequence{3}->union(Sequence{3}->union(Sequence{ 1 }))))))) ; var arr_size : int := (arr)->size() ; printTwoOdd(arr, arr_size); operation printTwoOdd(arr : OclAny, size : OclAny) pre: true post: true activity: var xor2 : OclAny := arr->first() ; var set_bit_no : int := 0 ; var n : double := size - 2 ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{0,0} ; for i : Integer.subrange(1, size-1) do ( xor2 := MathLib.bitwiseXor(xor2, arr[i+1])) ; set_bit_no := MathLib.bitwiseAnd(xor2, MathLib.bitwiseNot((xor2 - 1))) ; for i : Integer.subrange(0, size-1) do ( if (MathLib.bitwiseAnd(arr[i+1], set_bit_no)) then ( var x : int := MathLib.bitwiseXor(x, arr[i+1]) ) else ( var y : int := MathLib.bitwiseXor(y, arr[i+1]) )) ; execute ("The two ODD elements are")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,nums): maxIndex=nums.index(max(nums)) minIndex=nums.index(min(nums)) ans=float('INF') ans=min(ans,max(maxIndex,minIndex)+1) ans=min(ans,n-min(maxIndex,minIndex)) ans=min(ans,maxIndex+1+n-minIndex) ans=min(ans,minIndex+1+n-maxIndex) return ans t=int(input()) for T in range(t): n=int(input()) nums=list(map(int,input().split(' '))) print(solve(n,nums)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for T : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; nums := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; execute (solve(n, nums))->display()); operation solve(n : OclAny, nums : OclAny) : OclAny pre: true post: true activity: var maxIndex : int := nums->indexOf((nums)->max()) - 1 ; var minIndex : int := nums->indexOf((nums)->min()) - 1 ; var ans : double := ("" + (('INF')))->toReal() ; ans := Set{ans, Set{maxIndex, minIndex}->max() + 1}->min() ; ans := Set{ans, n - Set{maxIndex, minIndex}->min()}->min() ; ans := Set{ans, maxIndex + 1 + n - minIndex}->min() ; ans := Set{ans, minIndex + 1 + n - maxIndex}->min() ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(a): min_=101 max_=-1 fi=0 li=0 for i,e in enumerate(a): if min_>e : min_=e fi=i if max_li : fi,li=li,fi x=fi+1 y=li-fi z=len(a)-li if x<=z and y<=z : return x+y elif x<=y and z<=y : return x+z else : return y+z t=int(input()) for _ in range(t): n=input() a=[int(x)for x in input().split()] print(solve(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : String := (OclFile["System.in"]).readLine() ; a := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (solve(a))->display()); operation solve(a : OclAny) : OclAny pre: true post: true activity: var min_ : int := 101 ; var max_ : int := -1 ; var fi : int := 0 ; var li : int := 0 ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var e : OclAny := _tuple->at(_indx); if (min_->compareTo(e)) > 0 then ( min_ := e ; fi := i ) else skip ; if (max_->compareTo(e)) < 0 then ( max_ := e ; li := i ) else skip) ; if (fi->compareTo(li)) > 0 then ( Sequence{fi,li} := Sequence{li,fi} ) else skip ; var x : int := fi + 1 ; var y : double := li - fi ; var z : double := (a)->size() - li ; if (x->compareTo(z)) <= 0 & (y->compareTo(z)) <= 0 then ( return x + y ) else (if (x->compareTo(y)) <= 0 & (z->compareTo(y)) <= 0 then ( return x + z ) else ( return y + z ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def make_prime_table(n): is_prime=[True]*(n+1) is_prime[0]=False is_prime[1]=False for i in range(2,int(n**0.5)+1): if not is_prime[i]: continue for j in range(2*i,n+1,i): is_prime[j]=False return is_prime is_prime=make_prime_table(2*10**6) while True : n=int(input()) if n==0 : break l=n r=n while not is_prime[l]: l-=1 while not is_prime[r]: r+=1 print(r-l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; is_prime := make_prime_table(2 * (10)->pow(6)) ; while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var l : OclAny := n ; var r : OclAny := n ; while not(is_prime[l+1]) do ( l := l - 1) ; while not(is_prime[r+1]) do ( r := r + 1) ; execute (r - l)->display()); operation make_prime_table(n : OclAny) : OclAny pre: true post: true activity: var is_prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (n + 1)) ; is_prime->first() := false ; is_prime[1+1] := false ; for i : Integer.subrange(2, ("" + (((n)->pow(0.5))))->toInteger() + 1-1) do ( if not(is_prime[i+1]) then ( continue ) else skip ; for j : Integer.subrange(2 * i, n + 1-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ( is_prime[j+1] := false)) ; return is_prime; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n_square,k_th=map(int,input().split()) slogan=input() if k_th-1<(n_square-1)-(k_th-1): while k_th-1>0 : k_th-=1 print("LEFT") for i in range(n_square): print(f"PRINT{slogan[i]}") if i!=n_square-1 : print("RIGHT") else : n_right=n_square-k_th while n_right : n_right-=1 print("RIGHT") for i in range(n_square-1,-1,-1): print(f"PRINT{slogan[i]}") if i!=0 : print("LEFT") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n_square : OclAny := null; var k_th : OclAny := null; Sequence{n_square,k_th} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var slogan : String := (OclFile["System.in"]).readLine() ; if (k_th - 1->compareTo((n_square - 1) - (k_th - 1))) < 0 then ( while k_th - 1 > 0 do ( k_th := k_th - 1 ; execute ("LEFT")->display()) ; for i : Integer.subrange(0, n_square-1) do ( execute (StringLib.formattedString("PRINT{slogan[i]}"))->display() ; if i /= n_square - 1 then ( execute ("RIGHT")->display() ) else skip) ) else ( var n_right : double := n_square - k_th ; while n_right do ( n_right := n_right - 1 ; execute ("RIGHT")->display()) ; for i : Integer.subrange(-1 + 1, n_square - 1)->reverse() do ( execute (StringLib.formattedString("PRINT{slogan[i]}"))->display() ; if i /= 0 then ( execute ("LEFT")->display() ) else skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class MinStack(object): def __init__(self): self.stack=[] self.min_stack=[] def push(self,x): self.stack.append(x) if len(self.min_stack)==0 : self.min_stack.append(x) return if x<=self.min_stack[-1]: self.min_stack.append(x) else : self.min_stack.append(self.min_stack[-1]) def pop(self): if len(self.stack)>0 : self.min_stack.pop() self.stack.pop() def top(self): if len(self.stack)>0 : return self.stack[-1] return None def getMin(self): if len(self.min_stack)>0 : return self.min_stack[-1] return None ------------------------------------------------------------ OCL File: --------- class MinStack extends object { static operation newMinStack() : MinStack pre: true post: MinStack->exists( _x | result = _x ); attribute stack : Sequence := Sequence{}; attribute min_stack : Sequence := Sequence{}; operation initialise() : pre: true post: true activity: self.stack := Sequence{} ; self.min_stack := Sequence{}; return self; operation push(x : OclAny) pre: true post: true activity: (expr (atom (name self)) (trailer . (name stack)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) ; if (self.min_stack)->size() = 0 then ( (expr (atom (name self)) (trailer . (name min_stack)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) ; return ) else skip ; if (x->compareTo(self.min_stack->last())) <= 0 then ( (expr (atom (name self)) (trailer . (name min_stack)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) ) else ( (expr (atom (name self)) (trailer . (name min_stack)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name self)) (trailer . (name min_stack) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))))) )))) ); operation pop() pre: true post: true activity: if (self.stack)->size() > 0 then ( (expr (atom (name self)) (trailer . (name min_stack)) (trailer . (name pop) (arguments ( )))) ; (expr (atom (name self)) (trailer . (name stack)) (trailer . (name pop) (arguments ( )))) ) else skip; operation top() : OclAny pre: true post: true activity: if (self.stack)->size() > 0 then ( return self.stack->last() ) else skip ; return null; operation getMin() : OclAny pre: true post: true activity: if (self.min_stack)->size() > 0 then ( return self.min_stack->last() ) else skip ; return null; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(a): min_=101 max_=-1 fi=0 li=0 for i,e in enumerate(a): if min_>e : min_=e fi=i if max_li : fi,li=li,fi x=fi+1 y=li-fi z=len(a)-li if x<=z and y<=z : return x+y elif x<=y and z<=y : return x+z else : return y+z t=int(input()) for _ in range(t): n=input() a=[int(x)for x in input().split()] print(solve(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : String := (OclFile["System.in"]).readLine() ; a := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (solve(a))->display()); operation solve(a : OclAny) : OclAny pre: true post: true activity: var min_ : int := 101 ; var max_ : int := -1 ; var fi : int := 0 ; var li : int := 0 ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var e : OclAny := _tuple->at(_indx); if (min_->compareTo(e)) > 0 then ( min_ := e ; fi := i ) else skip ; if (max_->compareTo(e)) < 0 then ( max_ := e ; li := i ) else skip) ; if (fi->compareTo(li)) > 0 then ( Sequence{fi,li} := Sequence{li,fi} ) else skip ; var x : int := fi + 1 ; var y : double := li - fi ; var z : double := (a)->size() - li ; if (x->compareTo(z)) <= 0 & (y->compareTo(z)) <= 0 then ( return x + y ) else (if (x->compareTo(y)) <= 0 & (z->compareTo(y)) <= 0 then ( return x + z ) else ( return y + z ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): length=int(input()) list1=[int(num)for num in input().split()] a=list1.index(min(list1)) b=list1.index(max(list1)) p=min(a,b) q=max(a,b) print(min(q+1,length-p,p+1+length-q)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var length : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var list1 : Sequence := input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var a : int := list1->indexOf((list1)->min()) - 1 ; var b : int := list1->indexOf((list1)->max()) - 1 ; var p : OclAny := Set{a, b}->min() ; var q : OclAny := Set{a, b}->max() ; execute (Set{q + 1, length - p, p + 1 + length - q}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def isPrime(n): flag=1 i=2 while(i*i<=n): if(n % i==0): flag=0 break i+=1 return(True if flag==1 else False) def isPerfectSquare(x): sr=math.sqrt(x) return((sr-math.floor(sr))==0) def countInterestingPrimes(n): answer=0 for i in range(2,n): if(isPrime(i)!=None): j=1 while(j*j*j*j<=i): if(isPerfectSquare(i-j*j*j*j)): answer+=1 break j+=1 return answer if __name__=='__main__' : N=10 print(countInterestingPrimes(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var N : int := 10 ; execute (countInterestingPrimes(N))->display() ) else skip; operation isPrime(n : OclAny) : OclAny pre: true post: true activity: var flag : int := 1 ; var i : int := 2 ; while ((i * i->compareTo(n)) <= 0) do ( if (n mod i = 0) then ( flag := 0 ; break ) else skip ; i := i + 1) ; return (if flag = 1 then true else false endif); operation isPerfectSquare(x : OclAny) : OclAny pre: true post: true activity: var sr : double := (x)->sqrt() ; return ((sr - (sr)->floor()) = 0); operation countInterestingPrimes(n : OclAny) : OclAny pre: true post: true activity: var answer : int := 0 ; for i : Integer.subrange(2, n-1) do ( if (isPrime(i) /= null) then ( var j : int := 1 ; while ((j * j * j * j->compareTo(i)) <= 0) do ( if (isPerfectSquare(i - j * j * j * j)) then ( answer := answer + 1 ; break ) else skip ; j := j + 1) ) else skip) ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t = int(input()) for i in range(t): s = int(input()) arr = list(map(int, input().split())) m1 = arr.index(max(arr)) + 1 m2 = len(arr) - arr.index(max(arr)) n1 = arr.index(min(arr)) + 1 n2 = len(arr) - arr.index(min(arr)) res1 = min(m1, m2) + min(n1, n2) res2 = min(max(m1, n1), max(m2, n2)) print(res1 if res1 < res2 else res2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m1 : int := arr->indexOf((arr)->max()) - 1 + 1 ; var m2 : double := (arr)->size() - arr->indexOf((arr)->max()) - 1 ; var n1 : int := arr->indexOf((arr)->min()) - 1 + 1 ; var n2 : double := (arr)->size() - arr->indexOf((arr)->min()) - 1 ; var res1 : OclAny := Set{m1, m2}->min() + Set{n1, n2}->min() ; var res2 : OclAny := Set{Set{m1, n1}->max(), Set{m2, n2}->max()}->min() ; execute (if (res1->compareTo(res2)) < 0 then res1 else res2 endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,io,math from tokenize import Triple from math import* I=lambda :[*map(int,sys.stdin.readline().split())] IS=lambda : input() IN=lambda : int(input()) IF=lambda : float(input()) days=[28,30,31] week=['monday','tuesday','wednesday','thursday','friday','saturday','sunday'] a=IS() b=IS() for index,name in enumerate(week): if name==a : ind=index flag=False for mo in days : if week[(ind+mo)% 7]==b : flag=True if flag : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var I : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var IS : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var IN : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var IF : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toReal()) ; var days : Sequence := Sequence{28}->union(Sequence{30}->union(Sequence{ 31 })) ; var week : Sequence := Sequence{'monday'}->union(Sequence{'tuesday'}->union(Sequence{'wednesday'}->union(Sequence{'thursday'}->union(Sequence{'friday'}->union(Sequence{'saturday'}->union(Sequence{ 'sunday' })))))) ; var a : OclAny := IS->apply() ; var b : OclAny := IS->apply() ; for _tuple : Integer.subrange(1, (week)->size())->collect( _indx | Sequence{_indx-1, (week)->at(_indx)} ) do (var _indx : int := 1; var index : OclAny := _tuple->at(_indx); _indx := _indx + 1; var name : OclAny := _tuple->at(_indx); if name = a then ( var ind : OclAny := index ) else skip) ; var flag : boolean := false ; for mo : days do ( if week[(ind + mo) mod 7+1] = b then ( flag := true ) else skip) ; if flag then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w=["mo","tu","we","th","fr","sa","su"] exec('a,b=['+2*'w.index(input()[:2]),'+']') print('YNEOS'[all((a+x)% 7!=b for x in[0,2,3]): : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : Sequence := Sequence{"mo"}->union(Sequence{"tu"}->union(Sequence{"we"}->union(Sequence{"th"}->union(Sequence{"fr"}->union(Sequence{"sa"}->union(Sequence{ "su" })))))) ; (expr (expr (expr (atom 'a,b=[')) + (expr (expr (atom (number (integer 2)))) * (expr (atom 'w.index(input()[:2]),')))) + (expr (atom ']'))) ; execute ('YNEOS'(subscript (test (logical_test (comparison (expr (atom (name all)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name a))) + (expr (atom (name x)))))))) ))) % (expr (atom (number (integer 7)))))) != (comparison (expr (atom (name b))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) , (test (logical_test (comparison (expr (atom (number (integer 2))))))) , (test (logical_test (comparison (expr (atom (number (integer 3)))))))) ]))))))) ))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d=["monday","tuesday","wednesday","thursday","friday","saturday","sunday","monday","tuesday","wednesday","thursday","friday","saturday","sunday"] f=str(input()) s=str(input()) x=d.index(f) a=28 % 7 b=30 % 7 c=31 % 7 if d[x+a]==s or d[x+b]==s or d[x+c]==s : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : Sequence := Sequence{"monday"}->union(Sequence{"tuesday"}->union(Sequence{"wednesday"}->union(Sequence{"thursday"}->union(Sequence{"friday"}->union(Sequence{"saturday"}->union(Sequence{"sunday"}->union(Sequence{"monday"}->union(Sequence{"tuesday"}->union(Sequence{"wednesday"}->union(Sequence{"thursday"}->union(Sequence{"friday"}->union(Sequence{"saturday"}->union(Sequence{ "sunday" }))))))))))))) ; var f : String := ("" + (((OclFile["System.in"]).readLine()))) ; var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; var x : int := d->indexOf(f) - 1 ; var a : int := 28 mod 7 ; var b : int := 30 mod 7 ; var c : int := 31 mod 7 ; if d[x + a+1] = s or d[x + b+1] = s or d[x + c+1] = s then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=["monday","tuesday","wednesday","thursday","friday","saturday","sunday","monday","tuesday","wednesday"] a=input() b=input() cnt=0 t=10**9 r=10**9 for i in range(9): if s[i]==a : r=i for j in range(i,10): if s[j]==b : t=j break break if abs(r-t)==0 or abs(r-t)==2 or abs(r-t)==3 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := Sequence{"monday"}->union(Sequence{"tuesday"}->union(Sequence{"wednesday"}->union(Sequence{"thursday"}->union(Sequence{"friday"}->union(Sequence{"saturday"}->union(Sequence{"sunday"}->union(Sequence{"monday"}->union(Sequence{"tuesday"}->union(Sequence{ "wednesday" }))))))))) ; var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var cnt : int := 0 ; var t : double := (10)->pow(9) ; var r : double := (10)->pow(9) ; for i : Integer.subrange(0, 9-1) do ( if s[i+1] = a then ( r := i ; for j : Integer.subrange(i, 10-1) do ( if s[j+1] = b then ( t := j ; break ) else skip) ; break ) else skip) ; if (r - t)->abs() = 0 or (r - t)->abs() = 2 or (r - t)->abs() = 3 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline l=["monday","tuesday","wednesday","thursday","friday","saturday","sunday"] s=input()[:-1] w=input()[:-1] a=l.index(w)-l.index(s) if a<0 : a+=7 if a in[0,2,3]: print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var l : Sequence := Sequence{"monday"}->union(Sequence{"tuesday"}->union(Sequence{"wednesday"}->union(Sequence{"thursday"}->union(Sequence{"friday"}->union(Sequence{"saturday"}->union(Sequence{ "sunday" })))))) ; var s : OclAny := input()->front() ; var w : OclAny := input()->front() ; var a : double := l->indexOf(w) - 1 - l->indexOf(s) - 1 ; if a < 0 then ( a := a + 7 ) else skip ; if (Sequence{0}->union(Sequence{2}->union(Sequence{ 3 })))->includes(a) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- kolvomest=int(input()) k=0 spisok=[] for stroka in range(kolvomest): ryad=input() if 'OO' in ryad and k==0 : k=1 ryad=ryad.replace('OO','++',1) spisok.append(ryad) if k==1 : print('YES') for stroka in range(kolvomest): print(spisok[stroka]) else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var kolvomest : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := 0 ; var spisok : Sequence := Sequence{} ; for stroka : Integer.subrange(0, kolvomest-1) do ( var ryad : String := (OclFile["System.in"]).readLine() ; if (ryad)->characters()->includes('OO') & k = 0 then ( k := 1 ; ryad := ryad.replace('OO', '++', 1) ) else skip ; execute ((ryad) : spisok)) ; if k = 1 then ( execute ('YES')->display() ; for stroka : Integer.subrange(0, kolvomest-1) do ( execute (spisok[stroka+1])->display()) ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) rr=[] answ='NO' for i in range(n): r='' r=input() if answ=='NO' and 'OO' in r : answ='YES' r=r.replace("OO","++",1) rr.append(r) print(answ) if answ=='YES' : for i in range(n): print(rr[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var rr : Sequence := Sequence{} ; var answ : String := 'NO' ; for i : Integer.subrange(0, n-1) do ( var r : String := '' ; r := (OclFile["System.in"]).readLine() ; if answ = 'NO' & (r)->characters()->includes('OO') then ( answ := 'YES' ; r := r.replace("OO", "++", 1) ) else skip ; execute ((r) : rr)) ; execute (answ)->display() ; if answ = 'YES' then ( for i : Integer.subrange(0, n-1) do ( execute (rr[i+1])->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- one=["","one ","two ","three ","four ","five ","six ","seven ","eight ","nine ","ten ","eleven ","twelve ","thirteen ","fourteen ","fifteen ","sixteen ","seventeen ","eighteen ","nineteen "]; ten=["","","twenty ","thirty ","forty ","fifty ","sixty ","seventy ","eighty ","ninety "]; def numToWords(n,s): str="" ; if(n>19): str+=ten[n//10]+one[n % 10]; else : str+=one[n]; if(n): str+=s ; return str ; def convertToWords(n): out="" ; out+=numToWords((n//10000000),"crore "); out+=numToWords(((n//100000)% 100),"lakh "); out+=numToWords(((n//1000)% 100),"thousand "); out+=numToWords(((n//100)% 10),"hundred "); if(n>100 and n % 100): out+="and " ; out+=numToWords((n % 100),""); return out ; n=438237764 ; print(convertToWords(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var one : Sequence := Sequence{""}->union(Sequence{"one "}->union(Sequence{"two "}->union(Sequence{"three "}->union(Sequence{"four "}->union(Sequence{"five "}->union(Sequence{"six "}->union(Sequence{"seven "}->union(Sequence{"eight "}->union(Sequence{"nine "}->union(Sequence{"ten "}->union(Sequence{"eleven "}->union(Sequence{"twelve "}->union(Sequence{"thirteen "}->union(Sequence{"fourteen "}->union(Sequence{"fifteen "}->union(Sequence{"sixteen "}->union(Sequence{"seventeen "}->union(Sequence{"eighteen "}->union(Sequence{ "nineteen " }))))))))))))))))))); ; var ten : Sequence := Sequence{""}->union(Sequence{""}->union(Sequence{"twenty "}->union(Sequence{"thirty "}->union(Sequence{"forty "}->union(Sequence{"fifty "}->union(Sequence{"sixty "}->union(Sequence{"seventy "}->union(Sequence{"eighty "}->union(Sequence{ "ninety " }))))))))); ; skip ; skip ; n := 438237764; ; execute (convertToWords(n))->display();; operation numToWords(n : OclAny, s : OclAny) pre: true post: true activity: var OclType["String"] : String := ""; ; if (n > 19) then ( OclType["String"] := OclType["String"] + ten[n div 10+1] + one[n mod 10+1]; ) else ( OclType["String"] := OclType["String"] + one[n+1]; ) ; if (n) then ( OclType["String"] := OclType["String"] + s; ) else skip ; return OclType["String"];; operation convertToWords(n : OclAny) pre: true post: true activity: var out : String := ""; ; out := out + numToWords((n div 10000000), "crore "); ; out := out + numToWords(((n div 100000) mod 100), "lakh "); ; out := out + numToWords(((n div 1000) mod 100), "thousand "); ; out := out + numToWords(((n div 100) mod 10), "hundred "); ; if (n > 100 & n mod 100) then ( out := out + "and "; ) else skip ; out := out + numToWords((n mod 100), ""); ; return out;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input('')) l=[] k=[] m=[] for _ in range(n): l.append(input('')) for j in l : i=list(j) if i[0]=='O' and i[1]=='O' : m.append(l.index(j)) i[0]='+' i[1]='+' k.append(''.join(i)) elif i[3]=='O' and i[4]=='O' : m.append(l.index(j)) i[3]='+' i[4]='+' k.append(''.join(i)) if len(m)>0 : l[m[0]]=k[0] if len(m)>0 : print('YES') print('\n'.join(l)) else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; var l : Sequence := Sequence{} ; var k : Sequence := Sequence{} ; var m : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine('')) : l)) ; for j : l do ( var i : Sequence := (j) ; if i->first() = 'O' & i[1+1] = 'O' then ( execute ((l->indexOf(j) - 1) : m) ; i->first() := '+' ; i[1+1] := '+' ; execute ((StringLib.sumStringsWithSeparator((i), '')) : k) ) else (if i[3+1] = 'O' & i[4+1] = 'O' then ( execute ((l->indexOf(j) - 1) : m) ; i[3+1] := '+' ; i[4+1] := '+' ; execute ((StringLib.sumStringsWithSeparator((i), '')) : k) ) else skip)) ; if (m)->size() > 0 then ( l[m->first()+1] := k->first() ) else skip ; if (m)->size() > 0 then ( execute ('YES')->display() ; execute (StringLib.sumStringsWithSeparator((l), ' '))->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- seven_seg={0 : '0111111',1 : '0000110',2 : '1011011',3 : '1001111',4 : '1100110',5 : '1101101',6 : '1111101',7 : '0100111',8 : '1111111',9 : '1101111'} while True : seven_seg_state=['0']*7 n=int(input()) if n==-1 : break for _ in range(n): in_data=int(input()) for i in range(7): if seven_seg[in_data][i]==seven_seg_state[i]: print("0",end="") else : print("1",end="") seven_seg_state[i]=seven_seg[in_data][i] print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var seven_seg : Map := Map{ 0 |-> '0111111' }->union(Map{ 1 |-> '0000110' }->union(Map{ 2 |-> '1011011' }->union(Map{ 3 |-> '1001111' }->union(Map{ 4 |-> '1100110' }->union(Map{ 5 |-> '1101101' }->union(Map{ 6 |-> '1111101' }->union(Map{ 7 |-> '0100111' }->union(Map{ 8 |-> '1111111' }->union(Map{ 9 |-> '1101111' }))))))))) ; while true do ( var seven_seg_state : Sequence := MatrixLib.elementwiseMult(Sequence{ '0' }, 7) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = -1 then ( break ) else skip ; for _anon : Integer.subrange(0, n-1) do ( var in_data : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, 7-1) do ( if seven_seg[in_data+1][i+1] = seven_seg_state[i+1] then ( execute ("0")->display() ) else ( execute ("1")->display() ) ; seven_seg_state[i+1] := seven_seg[in_data+1][i+1]) ; execute (->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k='' for i in range(int(input())): k+=(input()+'\n') r=k.replace('OO','++',1) print(['YES\n'+r,'NO'][r is k]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : String := '' ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( k := k + ((OclFile["System.in"]).readLine() + ' ')) ; var r : String := k.replace('OO', '++', 1) ; execute (Sequence{'YES ' + r}->union(Sequence{ 'NO' })->select(r <>= k))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=0 c=0 l=[] for i in range(n): arr=[*input()] if arr[0]==arr[1]=='O' and m==0 : c+=1 elif arr[3]==arr[4]=='O' and m==0 : c+=1 l.append(arr) if c>=1 : print('YES') for arr in l : if arr[0]==arr[1]=='O' and m==0 : arr[0],arr[1]='+','+' print(''.join(arr)) m+=1 elif arr[3]==arr[4]=='O' and m==0 : arr[3],arr[4]='+','+' print(''.join(arr)) m+=1 else : print(''.join(arr)) else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := 0 ; var c : int := 0 ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var arr : Sequence := (OclFile["System.in"]).readLine() ; if arr->first() = arr[1+1] & (arr[1+1] == 'O') & m = 0 then ( c := c + 1 ) else (if arr[3+1] = arr[4+1] & (arr[4+1] == 'O') & m = 0 then ( c := c + 1 ) else skip) ; execute ((arr) : l)) ; if c >= 1 then ( execute ('YES')->display() ; for arr : l do ( if arr->first() = arr[1+1] & (arr[1+1] == 'O') & m = 0 then ( var arr->first() : OclAny := null; var arr[1+1] : OclAny := null; Sequence{arr->first(),arr[1+1]} := Sequence{'+','+'} ; execute (StringLib.sumStringsWithSeparator((arr), ''))->display() ; m := m + 1 ) else (if arr[3+1] = arr[4+1] & (arr[4+1] == 'O') & m = 0 then ( var arr[3+1] : OclAny := null; var arr[4+1] : OclAny := null; Sequence{arr[3+1],arr[4+1]} := Sequence{'+','+'} ; execute (StringLib.sumStringsWithSeparator((arr), ''))->display() ; m := m + 1 ) else ( execute (StringLib.sumStringsWithSeparator((arr), ''))->display() ) ) ) ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math class Node : def __init__(self,data): self.data=data self.next=None def prList(head): if(head==None): return temp=head print(temp.data,end="->") temp=temp.next while(temp!=head): print(temp.data,end="->") temp=temp.next print(head.data) def deleteK(head_ref,k): head=head_ref if(head==None): return curr=head prev=None while True : if(curr.next==head and curr==head): break prList(head) for i in range(k): prev=curr curr=curr.next if(curr==head): prev=head while(prev.next!=head): prev=prev.next head=curr.next prev.next=head head_ref=head elif(curr.next==head): prev.next=head else : prev.next=curr.next def insertNode(head_ref,x): head=head_ref temp=Node(x) if(head==None): temp.next=temp head_ref=temp return head_ref else : temp1=head while(temp1.next!=head): temp1=temp1.next temp1.next=temp temp.next=head return head if __name__=='__main__' : head=None head=insertNode(head,1) head=insertNode(head,2) head=insertNode(head,3) head=insertNode(head,4) head=insertNode(head,5) head=insertNode(head,6) head=insertNode(head,7) head=insertNode(head,8) head=insertNode(head,9) k=4 deleteK(head,k) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.next := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( head := null ; head := insertNode(head, 1) ; head := insertNode(head, 2) ; head := insertNode(head, 3) ; head := insertNode(head, 4) ; head := insertNode(head, 5) ; head := insertNode(head, 6) ; head := insertNode(head, 7) ; head := insertNode(head, 8) ; head := insertNode(head, 9) ; k := 4 ; deleteK(head, k) ) else skip; operation prList(head : OclAny) pre: true post: true activity: if (head = null) then ( return ) else skip ; var temp : OclAny := head ; execute (temp.data)->display() ; temp := temp.next ; while (temp /= head) do ( execute (temp.data)->display() ; temp := temp.next) ; execute (head.data)->display(); operation deleteK(head_ref : OclAny, k : OclAny) pre: true post: true activity: head := head_ref ; if (head = null) then ( return ) else skip ; var curr : OclAny := head ; var prev : OclAny := null ; while true do ( if (curr.next = head & curr = head) then ( break ) else skip ; prList(head) ; for i : Integer.subrange(0, k-1) do ( prev := curr ; curr := curr.next) ; if (curr = head) then ( prev := head ; while (prev.next /= head) do ( prev := prev.next) ; head := curr.next ; prev.next := head ; head_ref := head ) else (if (curr.next = head) then ( prev.next := head ) else ( prev.next := curr.next ) ) ); operation insertNode(head_ref : OclAny, x : OclAny) : OclAny pre: true post: true activity: head := head_ref ; temp := (Node.newNode()).initialise(x) ; if (head = null) then ( temp.next := temp ; head_ref := temp ; return head_ref ) else ( var temp1 : OclAny := head ; while (temp1.next /= head) do ( temp1 := temp1.next) ; temp1.next := temp ; temp.next := head ) ; return head; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def steps(cur,x,n): if x==0 : return float('inf') elif x>0 : return abs((n-cur)//x) else : return abs(int((cur-1)/x)) def countSteps(curx,cury,n,m,moves): count=0 k=len(moves) for i in range(0,k): x=moves[i][0] y=moves[i][1] stepct=min(steps(curx,x,n),steps(cury,y,m)) count+=stepct curx+=stepct*x cury+=stepct*y return count if __name__=="__main__" : n,m,x,y=4,5,1,1 moves=[[1,1],[1,1],[0,-2]] print(countSteps(x,y,n,m,moves)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( Sequence{n,m,x,y} := Sequence{4,5,1,1} ; moves := Sequence{Sequence{1}->union(Sequence{ 1 })}->union(Sequence{Sequence{1}->union(Sequence{ 1 })}->union(Sequence{ Sequence{0}->union(Sequence{ -2 }) })) ; execute (countSteps(x, y, n, m, moves))->display() ) else skip; operation steps(cur : OclAny, x : OclAny, n : OclAny) : OclAny pre: true post: true activity: if x = 0 then ( return ("" + (('inf')))->toReal() ) else (if x > 0 then ( return ((n - cur) div x)->abs() ) else ( return (("" + (((cur - 1) / x)))->toInteger())->abs() ) ) ; operation countSteps(curx : OclAny, cury : OclAny, n : OclAny, m : OclAny, moves : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var k : int := (moves)->size() ; for i : Integer.subrange(0, k-1) do ( x := moves[i+1]->first() ; var y : OclAny := moves[i+1][1+1] ; var stepct : OclAny := Set{steps(curx, x, n), steps(cury, y, m)}->min() ; count := count + stepct ; curx := curx + stepct * x ; cury := cury + stepct * y) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input().split() n[0]=int(n[0]) n[1]=int(n[1]) n[2]=int(n[2]) n.sort() print((n[1]-n[0])+(n[2]-n[1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := input().split() ; n->first() := ("" + ((n->first())))->toInteger() ; n[1+1] := ("" + ((n[1+1])))->toInteger() ; n[2+1] := ("" + ((n[2+1])))->toInteger() ; n := n->sort() ; execute ((n[1+1] - n->first()) + (n[2+1] - n[1+1]))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): x=input().split(" ") for i in range(len(x)): x[i]=int(x[i]) x.sort() sum=int((x[1]-x[0])+(x[2]-x[1])) print(sum) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var x : OclAny := input().split(" ") ; for i : Integer.subrange(0, (x)->size()-1) do ( x[i+1] := ("" + ((x[i+1])))->toInteger()) ; x := x->sort() ; var sum : int := ("" + (((x[1+1] - x->first()) + (x[2+1] - x[1+1]))))->toInteger() ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- coordinates=list(map(int,input().split(' '))) coordinates.sort() mid_point=coordinates[len(coordinates)//2] distance=0 for position in coordinates : distance+=abs(mid_point-position) print(distance) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var coordinates : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; coordinates := coordinates->sort() ; var mid_point : OclAny := coordinates[(coordinates)->size() div 2+1] ; var distance : int := 0 ; for position : coordinates do ( distance := distance + (mid_point - position)->abs()) ; execute (distance)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lst=list(map(int,input().split())) maish1=max(lst) maish2=min(lst) print(maish1-maish2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var maish1 : OclAny := (lst)->max() ; var maish2 : OclAny := (lst)->min() ; execute (maish1 - maish2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): a,b,c=[int(i)for i in input().split()] i=max(a,b,c) j=min(a,b,c) x=a+b+c-i-j print(i-x+x-j) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var i : OclAny := Set{a, b, c}->max() ; var j : OclAny := Set{a, b, c}->min() ; var x : double := a + b + c - i - j ; execute (i - x + x - j)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def flipSign(a): neg=0 ; tmp=1 if a<0 else-1 ; while(a!=0): neg+=tmp ; a+=tmp ; return neg ; def areDifferentSign(a,b): return((a<0 and b>0)or(a>0 and b<0)); def sub(a,b): return a+flipSign(b); def mul(a,b): if(adisplay(); ; execute ("Product is")->display(); ; Sequence{a,b} := Sequence{8,2}; ; if (b) then ( execute ("Division is")->display(); ) else ( execute ("Exception :-Divide by 0")->display(); ); operation flipSign(a : OclAny) pre: true post: true activity: var neg : int := 0; ; var tmp : int := if a < 0 then 1 else -1 endif; ; while (a /= 0) do ( neg := neg + tmp; ; a := a + tmp;) ; return neg;; operation areDifferentSign(a : OclAny, b : OclAny) pre: true post: true activity: return ((a < 0 & b > 0) or (a > 0 & b < 0));; operation sub(a : OclAny, b : OclAny) pre: true post: true activity: return a + flipSign(b);; operation mul(a : OclAny, b : OclAny) pre: true post: true activity: if ((a->compareTo(b)) < 0) then ( return mul(b, a); ) else skip ; var sum : int := 0; ; for i : Integer.subrange(0 + 1, (b)->abs())->reverse() do ( sum := sum + a;) ; if (b < 0) then ( sum := flipSign(sum); ) else skip ; return sum;; operation division(a : OclAny, b : OclAny) pre: true post: true activity: var quotient : int := 0; ; var divisor : OclAny := flipSign((b)->abs()); ; for dividend : Integer.subrange((a)->abs(), (divisor)->abs() + divisor-1)->select( $x | ($x - (a)->abs()) mod divisor = 0 ) do ( quotient := quotient + 1;) ; if (areDifferentSign(a, b)) then ( quotient := flipSign(quotient); ) else skip ; return quotient;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printArray(N,arr): for i in range(N): print(arr[i],end="") print("\n",end="") def replacedArray(N,arr): for i in range(N): pos_sum=0 neg_sum=0 for j in range(i+1,N,1): if(arr[j]>0): pos_sum+=arr[j] else : neg_sum+=arr[j] diff=abs(pos_sum)-abs(neg_sum) arr[i]=abs(diff) if __name__=='__main__' : N=5 arr=[1,-1,2,3,-2] replacedArray(N,arr) printArray(N,arr) N=6 arr1=[-3,-4,-2,5,1,-2] replacedArray(N,arr1) printArray(N,arr1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( N := 5 ; arr := Sequence{1}->union(Sequence{-1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ -2 })))) ; replacedArray(N, arr) ; printArray(N, arr) ; N := 6 ; var arr1 : Sequence := Sequence{-3}->union(Sequence{-4}->union(Sequence{-2}->union(Sequence{5}->union(Sequence{1}->union(Sequence{ -2 }))))) ; replacedArray(N, arr1) ; printArray(N, arr1) ) else skip; operation printArray(N : OclAny, arr : OclAny) pre: true post: true activity: for i : Integer.subrange(0, N-1) do ( execute (arr[i+1])->display()) ; execute ("\n")->display(); operation replacedArray(N : OclAny, arr : OclAny) pre: true post: true activity: for i : Integer.subrange(0, N-1) do ( var pos_sum : int := 0 ; var neg_sum : int := 0 ; for j : Integer.subrange(i + 1, N-1)->select( $x | ($x - i + 1) mod 1 = 0 ) do ( if (arr[j+1] > 0) then ( pos_sum := pos_sum + arr[j+1] ) else ( neg_sum := neg_sum + arr[j+1] )) ; var diff : double := (pos_sum)->abs() - (neg_sum)->abs() ; arr[i+1] := (diff)->abs()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def cntSubArr(arr,n): ans=0 ; for i in range(n): curr_gcd=0 ; for j in range(i,n): curr_gcd=gcd(curr_gcd,arr[j]); ans+=(curr_gcd==1); return ans ; if __name__=="__main__" : arr=[1,1,1]; n=len(arr); print(cntSubArr(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })); ; n := (arr)->size(); ; execute (cntSubArr(arr, n))->display(); ) else skip; operation cntSubArr(arr : OclAny, n : OclAny) pre: true post: true activity: var ans : int := 0; ; for i : Integer.subrange(0, n-1) do ( var curr_gcd : int := 0; ; for j : Integer.subrange(i, n-1) do ( curr_gcd := gcd(curr_gcd, arr[j+1]); ; ans := ans + (curr_gcd = 1);)) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isVowel(c): if(c=='a' or c=='e' or c=='i' or c=='o' or c=='u'): return True return False def isVowelPrime(Str,n): prime=[True for i in range(n)] prime[0]=False prime[1]=False for p in range(2,n): if p*p>n : break if(prime[p]==True): for i in range(2*p,n,p): prime[i]=False for i in range(n): if(isVowel(Str[i])and prime[i]==False): return False return True Str="geeksforgeeks" ; n=len(Str) if(isVowelPrime(Str,n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Str := "geeksforgeeks"; ; n := (Str)->size() ; if (isVowelPrime(Str, n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isVowel(c : OclAny) : OclAny pre: true post: true activity: if (c = 'a' or c = 'e' or c = 'i' or c = 'o' or c = 'u') then ( return true ) else skip ; return false; operation isVowelPrime(Str : OclAny, n : OclAny) : OclAny pre: true post: true activity: var prime : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (true)) ; prime->first() := false ; prime[1+1] := false ; for p : Integer.subrange(2, n-1) do ( if (p * p->compareTo(n)) > 0 then ( break ) else skip ; if (prime[p+1] = true) then ( for i : Integer.subrange(2 * p, n-1)->select( $x | ($x - 2 * p) mod p = 0 ) do ( prime[i+1] := false) ) else skip) ; for i : Integer.subrange(0, n-1) do ( if (isVowel(Str[i+1]) & prime[i+1] = false) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minStepToDeleteString(str): N=len(str) dp=[[0 for x in range(N+1)]for y in range(N+1)] for l in range(1,N+1): i=0 j=l-1 while jdisplay() ) else skip; operation minStepToDeleteString(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var N : int := (OclType["String"])->size() ; var dp : Sequence := Integer.subrange(0, N + 1-1)->select(y | true)->collect(y | (Integer.subrange(0, N + 1-1)->select(x | true)->collect(x | (0)))) ; for l : Integer.subrange(1, N + 1-1) do ( var i : int := 0 ; var j : double := l - 1 ; while (j->compareTo(N)) < 0 do ( if (l = 1) then ( dp[i+1][j+1] := 1 ) else ( dp[i+1][j+1] := 1 + dp[i + 1+1][j+1] ; if (("" + ([i+1])) = ("" + ([i + 1+1]))) then ( dp[i+1][j+1] := Set{1 + dp[i + 2+1][j+1], dp[i+1][j+1]}->min() ) else skip ; for K : Integer.subrange(i + 2, j + 1-1) do ( if (("" + ([i+1])) = ("" + ([K+1]))) then ( dp[i+1][j+1] := Set{dp[i + 1+1][K - 1+1] + dp[K + 1+1][j+1], dp[i+1][j+1]}->min() ) else skip) ) ; i := i + 1 ; j := j + 1)) ; return dp->first()[N - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- limit=1000000 position=[0]*(limit+1) def sieve(): position[0]=-1 position[1]=-1 pos=0 for i in range(2,limit+1): if(position[i]==0): pos+=1 position[i]=pos for j in range(i*2,limit+1,i): position[j]=-1 if __name__=="__main__" : sieve() n=11 print(position[n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var limit : int := 1000000 ; var position : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (limit + 1)) ; skip ; if __name__ = "__main__" then ( sieve() ; var n : int := 11 ; execute (position[n+1])->display() ) else skip; operation sieve() pre: true post: true activity: position->first() := -1 ; position[1+1] := -1 ; var pos : int := 0 ; for i : Integer.subrange(2, limit + 1-1) do ( if (position[i+1] = 0) then ( pos := pos + 1 ; position[i+1] := pos ; for j : Integer.subrange(i * 2, limit + 1-1)->select( $x | ($x - i * 2) mod i = 0 ) do ( position[j+1] := -1) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- DP_s=9 def getNumMonotone(ln): DP=[[0]*DP_s for i in range(ln)] for i in range(DP_s): DP[0][i]=i+1 for i in range(ln): DP[i][0]=1 for i in range(1,ln): for j in range(1,DP_s): DP[i][j]=DP[i-1][j]+DP[i][j-1] return DP[ln-1][DP_s-1] print(getNumMonotone(10)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var DP_s : int := 9 ; skip ; execute (getNumMonotone(10))->display(); operation getNumMonotone(ln : OclAny) : OclAny pre: true post: true activity: var DP : Sequence := Integer.subrange(0, ln-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, DP_s))) ; for i : Integer.subrange(0, DP_s-1) do ( DP->first()[i+1] := i + 1) ; for i : Integer.subrange(0, ln-1) do ( DP[i+1]->first() := 1) ; for i : Integer.subrange(1, ln-1) do ( for j : Integer.subrange(1, DP_s-1) do ( DP[i+1][j+1] := DP[i - 1+1][j+1] + DP[i+1][j - 1+1])) ; return DP[ln - 1+1][DP_s - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- DP_s=9 def getNumMonotone(ln): DP=[[0]*DP_s for i in range(ln)] for i in range(DP_s): DP[0][i]=i+1 for i in range(ln): DP[i][0]=1 for i in range(1,ln): for j in range(1,DP_s): DP[i][j]=DP[i-1][j]+DP[i][j-1] return DP[ln-1][DP_s-1] print(getNumMonotone(10)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var DP_s : int := 9 ; skip ; execute (getNumMonotone(10))->display(); operation getNumMonotone(ln : OclAny) : OclAny pre: true post: true activity: var DP : Sequence := Integer.subrange(0, ln-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, DP_s))) ; for i : Integer.subrange(0, DP_s-1) do ( DP->first()[i+1] := i + 1) ; for i : Integer.subrange(0, ln-1) do ( DP[i+1]->first() := 1) ; for i : Integer.subrange(1, ln-1) do ( for j : Integer.subrange(1, DP_s-1) do ( DP[i+1][j+1] := DP[i - 1+1][j+1] + DP[i+1][j - 1+1])) ; return DP[ln - 1+1][DP_s - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxCost(a,n,l,r): mx=0 for i in range(n): mx=max(mx,a[i]) count=[0]*(mx+1) for i in range(n): count[a[i]]+=1 res=[0]*(mx+1) res[0]=0 l=min(l,r) for num in range(1,mx+1): k=max(num-l-1,0) res[num]=max(res[num-1],num*count[num]+res[k]) return res[mx] if __name__=="__main__" : a=[2,1,2,3,2,2,1] l,r=1,1 n=len(a) print(maxCost(a,n,l,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{2}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 1 })))))) ; Sequence{l,r} := Sequence{1,1} ; n := (a)->size() ; execute (maxCost(a, n, l, r))->display() ) else skip; operation maxCost(a : OclAny, n : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var mx : int := 0 ; for i : Integer.subrange(0, n-1) do ( mx := Set{mx, a[i+1]}->max()) ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (mx + 1)) ; for i : Integer.subrange(0, n-1) do ( count[a[i+1]+1] := count[a[i+1]+1] + 1) ; var res : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (mx + 1)) ; res->first() := 0 ; l := Set{l, r}->min() ; for num : Integer.subrange(1, mx + 1-1) do ( var k : OclAny := Set{num - l - 1, 0}->max() ; res[num+1] := Set{res[num - 1+1], num * count[num+1] + res[k+1]}->max()) ; return res[mx+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def test(): nrow,ncol=map(int,input().split()) arr=[] val=100000000000 lr,lc=0,0 for row_id in range(nrow): temp=list(input()) arr.append([]) for col_id in range(ncol): if temp[col_id]=="R" : temp2=row_id+col_id arr[row_id].append(temp2) if temp20 : return False for i in range(nrow): for j in range(lc): if arr[i][j]>0 : return False return True num_test_cases=int(input()) for test_case in range(num_test_cases): val=test() if val : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var num_test_cases : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for test_case : Integer.subrange(0, num_test_cases-1) do ( val := test() ; if val then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); operation test() : OclAny pre: true post: true activity: var nrow : OclAny := null; var ncol : OclAny := null; Sequence{nrow,ncol} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := Sequence{} ; var val : int := 100000000000 ; var lr : OclAny := null; var lc : OclAny := null; Sequence{lr,lc} := Sequence{0,0} ; for row_id : Integer.subrange(0, nrow-1) do ( var temp : Sequence := ((OclFile["System.in"]).readLine())->characters() ; execute ((Sequence{}) : arr) ; for col_id : Integer.subrange(0, ncol-1) do ( if temp[col_id+1] = "R" then ( var temp2 : OclAny := row_id + col_id ; (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name row_id)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name temp2)))))))) )))) ; if (temp2->compareTo(val)) < 0 then ( val := temp2 ; var lr : OclAny := null; var lc : OclAny := null; Sequence{lr,lc} := Sequence{row_id,col_id} ) else skip ) else ( (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name row_id)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))) ))) ; for i : Integer.subrange(0, lr-1) do ( temp := arr[i+1] ; if (temp)->max() > 0 then ( return false ) else skip) ; for i : Integer.subrange(0, nrow-1) do ( for j : Integer.subrange(0, lc-1) do ( if arr[i+1][j+1] > 0 then ( return false ) else skip)) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for testCases in range(int(input())): n,m=map(int,input().split()) array=[[j for j in input()]for i in range(n)] rangeN=rangeM=6 for i in range(n): for j in range(m): if(array[i][j]=='R'): rangeN=min(i,rangeN) rangeM=min(j,rangeM) if(array[rangeN][rangeM]=='R'): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for testCases : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var array : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine()->select(j | true)->collect(j | (j)))) ; var rangeN : OclAny := 6; var rangeM : int := 6 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if (array[i+1][j+1] = 'R') then ( rangeN := Set{i, rangeN}->min() ; rangeM := Set{j, rangeM}->min() ) else skip)) ; if (array[rangeN+1][rangeM+1] = 'R') then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for testCases in range(int(input())): n,m=map(int,input().split()) array=[[j for j in input()]for i in range(n)] rangeN=n rangeM=m for i in range(n): for j in range(m): if(array[i][j]=='R'): rangeN=min(i,rangeN) rangeM=min(j,rangeM) if(array[rangeN][rangeM]=='R'): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for testCases : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var array : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine()->select(j | true)->collect(j | (j)))) ; var rangeN : OclAny := n ; var rangeM : OclAny := m ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if (array[i+1][j+1] = 'R') then ( rangeN := Set{i, rangeN}->min() ; rangeM := Set{j, rangeM}->min() ) else skip)) ; if (array[rangeN+1][rangeM+1] = 'R') then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math fin=open('input.txt','r') fout=open('output.txt','w') l=int(fin.readline()) for case in range(l): P,Q=map(int,fin.readline().strip().split()) frees=map(int,fin.readline().strip().split()) cache={} def rangeof(lid,rid): lrange=rrange=0 if lid==0 : lrange=1 else : lrange=frees[lid-1]+1 if rid==len(frees)-1 : rrange=P else : rrange=frees[rid+1]-1 return rrange-lrange+1 def getbetter(lid,rid): if lid>rid : return 0 if lid==rid : return rangeof(lid,rid)-1 key=(lid,rid) if key in cache : return cache[key] else : for i in range(lid,rid+1): cache[key]=rangeof(lid,rid)-1+min([getbetter(lid,i-1)+getbetter(i+1,rid)for i in range(lid,rid+1)]) return cache[key] fout.write("Case #%d: %d\n" %(case+1,getbetter(0,len(frees)-1))) fin.close() fout.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var fin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('input.txt')) ; var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('output.txt')) ; var l : int := ("" + ((fin.readLine())))->toInteger() ; for case : Integer.subrange(0, l-1) do ( var P : OclAny := null; var Q : OclAny := null; Sequence{P,Q} := (fin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var frees : Sequence := (fin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cache : OclAny := Set{} ; skip ; skip ; fout.write(StringLib.format("Case #%d: %d\n",Sequence{case + 1, getbetter(0, (frees)->size() - 1)}))) ; fin.closeFile() ; fout.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def factorial(n): i=n fact=1 while(n/i!=n): fact=fact*i i-=1 return fact num=5 ; print("Factorial of",num,"is",factorial(num)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var num : int := 5; ; execute ("Factorial of")->display(); operation factorial(n : OclAny) : OclAny pre: true post: true activity: var i : OclAny := n ; var fact : int := 1 ; while (n / i /= n) do ( fact := fact * i ; i := i - 1) ; return fact; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,m=input().split() n,m=int(n),int(m) ma=[[]*m]*n for i in range(n): ma[i]=list(input()) flag,flag1=False,True for i in range(n): for j in range(m): if ma[i][j]=="R" and not flag : flag=True x=j elif ma[i][j]=="R" : if jtoInteger() ; for p : Integer.subrange(0, t-1) do ( main()); operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split() ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{("" + ((n)))->toInteger(),("" + ((m)))->toInteger()} ; var ma : Sequence := MatrixLib.elementwiseMult(Sequence{ MatrixLib.elementwiseMult(Sequence{}, m) }, n) ; for i : Integer.subrange(0, n-1) do ( ma[i+1] := ((OclFile["System.in"]).readLine())->characters()) ; var flag : OclAny := null; var flag1 : OclAny := null; Sequence{flag,flag1} := Sequence{false,true} ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if ma[i+1][j+1] = "R" & not(flag) then ( var flag : boolean := true ; var x : OclAny := j ) else (if ma[i+1][j+1] = "R" then ( if (j->compareTo(x)) < 0 then ( var flag1 : boolean := false ; break ) else skip ) else skip))) ; if flag1 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): r,c=list(map(int,input().split())) pos=[input()for _ in range(r)] s=-1 for i,p in enumerate(pos): if "R" in p : s=i break res=all(pos[i].find("R")>=pos[s].find("R")for i in range(s+1,len(pos))if pos[i].find("R")!=-1) print("YNEOS"[not res : : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var pos : Sequence := Integer.subrange(0, r-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var s : int := -1 ; for _tuple : Integer.subrange(1, (pos)->size())->collect( _indx | Sequence{_indx-1, (pos)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p : OclAny := _tuple->at(_indx); if (p)->includes("R") then ( s := i ; break ) else skip) ; var res : boolean := ((argument (test (logical_test (comparison (comparison (expr (atom (name pos)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name find) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "R"))))))) ))))) >= (comparison (expr (atom (name pos)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])) (trailer . (name find) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "R"))))))) )))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name s))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name pos)))))))) ))))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name pos)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name find) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "R"))))))) ))))) != (comparison (expr (atom - (number (integer 1))))))))))))->forAll( _x | _x = true ) ; execute ("YNEOS"(subscript (test (logical_test not (logical_test (comparison (expr (atom (name res))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findArea(r): PI=3.142 return PI*(r*r); print("Area is %.6f" % findArea(5)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (StringLib.format("Area is %.6f",findArea(5)))->display();; operation findArea(r : OclAny) pre: true post: true activity: var PI : double := 3.142 ; return PI * (r * r);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (n,k)=map(int,input().split()) s=[0]*n for i in map(int,input().split()): s[i-1]=1 e=[[]for _ in range(n)] for _ in range(n-1): (x,y)=(int(s)-1 for s in input().split()) e[x].append(y) e[y].append(x) q=[0] fa=[-1]*n fa[0]=0 for i in range(n): x=q[i] for y in e[x]: if fa[y]==-1 : fa[y]=x q.append(y) dp=[0]*n k2=k*2 for x in reversed(q): for y in e[x]: if fa[y]==x : i=s[y] s[x]+=i dp[x]+=dp[y]+(k2-i if i>k else i) print(dp[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{n, k} : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( s[i - 1+1] := 1) ; var e : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, n - 1-1) do ( ; var Sequence{x, y} : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))) - (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; (expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))) ; (expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))) ; var q : Sequence := Sequence{ 0 } ; var fa : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; fa->first() := 0 ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := q[i+1] ; for y : e[x+1] do ( if fa[y+1] = -1 then ( fa[y+1] := x ; execute ((y) : q) ) else skip)) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var k2 : double := k * 2 ; for x : (q)->reverse() do ( for y : e[x+1] do ( if fa[y+1] = x then ( var i : OclAny := s[y+1] ; s[x+1] := s[x+1] + i ; dp[x+1] := dp[x+1] + dp[y+1] + (if (i->compareTo(k)) > 0 then k2 - i else i endif) ) else skip)) ; execute (dp->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def parser(): return[int(x)for x in input().split()] def DFS(): visited[0]=True stack=[] introduction_order=[] stack.append(0) while len(stack)>0 : v=stack.pop() for u in adjacents_list[v]: if not visited[u]: pi[u]=v visited[u]=True if university_in_city[u]: count_universities_subtree[u]+=1 stack.append(u) introduction_order.append(u) for v in introduction_order[: :-1]: count_universities_subtree[pi[v]]+=count_universities_subtree[v] n,k=parser() visited=[False for x in range(n)] pi=[0 for x in range(n)] count_universities_subtree=[0 for x in range(n)] university_in_city=[False for x in range(n)] cities_universities=parser() for i in cities_universities : university_in_city[i-1]=True adjacents_list=[[]for x in range(n)] for i in range(n-1): edge=parser() adjacents_list[edge[0]-1].append(edge[1]-1) adjacents_list[edge[1]-1].append(edge[0]-1) DFS() total=0 for i in range(1,n): total+=min(count_universities_subtree[i],2*k-count_universities_subtree[i]) print(total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := parser() ; var visited : Sequence := Integer.subrange(0, n-1)->select(x | true)->collect(x | (false)) ; var pi : Sequence := Integer.subrange(0, n-1)->select(x | true)->collect(x | (0)) ; var count_universities_subtree : Sequence := Integer.subrange(0, n-1)->select(x | true)->collect(x | (0)) ; var university_in_city : Sequence := Integer.subrange(0, n-1)->select(x | true)->collect(x | (false)) ; var cities_universities : OclAny := parser() ; for i : cities_universities do ( university_in_city[i - 1+1] := true) ; var adjacents_list : Sequence := Integer.subrange(0, n-1)->select(x | true)->collect(x | (Sequence{})) ; for i : Integer.subrange(0, n - 1-1) do ( var edge : OclAny := parser() ; (expr (atom (name adjacents_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name adjacents_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) - (expr (atom (number (integer 1)))))))))) ))))) ; DFS() ; var total : int := 0 ; for i : Integer.subrange(1, n-1) do ( total := total + Set{count_universities_subtree[i+1], 2 * k - count_universities_subtree[i+1]}->min()) ; execute (total)->display(); operation parser() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation DFS() pre: true post: true activity: visited->first() := true ; var stack : Sequence := Sequence{} ; var introduction_order : Sequence := Sequence{} ; execute ((0) : stack) ; while (stack)->size() > 0 do ( var v : OclAny := stack->last() ; stack := stack->front() ; for u : adjacents_list[v+1] do ( if not(visited[u+1]) then ( pi[u+1] := v ; visited[u+1] := true ; if university_in_city[u+1] then ( count_universities_subtree[u+1] := count_universities_subtree[u+1] + 1 ) else skip ; execute ((u) : stack) ; execute ((u) : introduction_order) ) else skip)) ; for v : introduction_order(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( count_universities_subtree[pi[v+1]+1] := count_universities_subtree[pi[v+1]+1] + count_universities_subtree[v+1]); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (n,k)=map(int,input().split()) s=[0]*n for i in map(int,input().split()): s[i-1]=1 e=[[]for _ in range(n)] for _ in range(n-1): (x,y)=(int(s)-1 for s in input().split()) e[x].append(y) e[y].append(x) q=[0] fa=[-1]*n fa[0]=0 for i in range(n): x=q[i] for y in e[x]: if fa[y]==-1 : fa[y]=x q.append(y) dp=[0]*n k2=k*2 for x in reversed(q): for y in e[x]: if fa[y]==x : i=s[y] s[x]+=i dp[x]+=dp[y]+(k2-i if i>k else i) print(dp[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{n, k} : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( s[i - 1+1] := 1) ; var e : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, n - 1-1) do ( ; var Sequence{x, y} : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))) - (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; (expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))) ; (expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))) ; var q : Sequence := Sequence{ 0 } ; var fa : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; fa->first() := 0 ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := q[i+1] ; for y : e[x+1] do ( if fa[y+1] = -1 then ( fa[y+1] := x ; execute ((y) : q) ) else skip)) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var k2 : double := k * 2 ; for x : (q)->reverse() do ( for y : e[x+1] do ( if fa[y+1] = x then ( var i : OclAny := s[y+1] ; s[x+1] := s[x+1] + i ; dp[x+1] := dp[x+1] + dp[y+1] + (if (i->compareTo(k)) > 0 then k2 - i else i endif) ) else skip)) ; execute (dp->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthTerm(N): return(abs(N*((N-1)*(N-3)*(N-5)))) if __name__=="__main__" : N=6 print(nthTerm(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := 6 ; execute (nthTerm(N))->display() ) else skip; operation nthTerm(N : OclAny) : OclAny pre: true post: true activity: return ((N * ((N - 1) * (N - 3) * (N - 5)))->abs()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getHeight(X): return(2*X) if __name__=='__main__' : X=35 print(getHeight(X)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( X := 35 ; execute (getHeight(X))->display() ) else skip; operation getHeight(X : OclAny) : OclAny pre: true post: true activity: return (2 * X); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- V=4 def countwalks(graph,u,v,k): if(k==0 and u==v): return 1 if(k==1 and graph[u][v]): return 1 if(k<=0): return 0 count=0 for i in range(0,V): if(graph[u][i]==1): count+=countwalks(graph,i,v,k-1) return count graph=[[0,1,1,1,],[0,0,0,1,],[0,0,0,1,],[0,0,0,0]] u=0 ; v=3 ; k=2 print(countwalks(graph,u,v,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var V : int := 4 ; skip ; graph := Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 1 })))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 1 })))}->union(Sequence{ Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))) }))) ; u := 0; v := 3; k := 2 ; execute (countwalks(graph, u, v, k))->display(); operation countwalks(graph : OclAny, u : OclAny, v : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (k = 0 & u = v) then ( return 1 ) else skip ; if (k = 1 & graph[u+1][v+1]) then ( return 1 ) else skip ; if (k <= 0) then ( return 0 ) else skip ; var count : int := 0 ; for i : Integer.subrange(0, V-1) do ( if (graph[u+1][i+1] = 1) then ( count := count + countwalks(graph, i, v, k - 1) ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- Infinity=1e10000 bests={} def best(qs=[0,1]): base=qs[-1]-qs[0]-2 if len(qs)==2 : return 0 elif len(qs)==3 : return base else : key=tuple(qs) if key not in bests : b=Infinity for split in range(1,len(qs)-1): b=min(b,best(qs[: split+1])+best(qs[split :])) bests[key]=b+base return bests[key] N=int(input()) for case in range(1,N+1): line=input().split() P=int(line[0]) Q=int(line[1]) pris=[int(w)for w in input().split()] cells=[0]+pris+[P+1] ans=best(cells) print("Case #"+str(case)+": "+str(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Math_PINFINITY : double := ("1e10000")->toReal() ; var bests : OclAny := Set{} ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for case : Integer.subrange(1, N + 1-1) do ( var line : OclAny := input().split() ; var P : int := ("" + ((line->first())))->toInteger() ; var Q : int := ("" + ((line[1+1])))->toInteger() ; var pris : Sequence := input().split()->select(w | true)->collect(w | (("" + ((w)))->toInteger())) ; var cells : Sequence := Sequence{ 0 }->union(pris)->union(Sequence{ P + 1 }) ; var ans : OclAny := best(cells) ; execute ("Case #" + ("" + ((case))) + ": " + ("" + ((ans))))->display()); operation best(qs : OclAny) : OclAny pre: true post: true activity: if qs->oclIsUndefined() then qs := Sequence{0}->union(Sequence{ 1 }) else skip; var base : double := qs->last() - qs->first() - 2 ; if (qs)->size() = 2 then ( return 0 ) else (if (qs)->size() = 3 then ( return base ) else ( var key : Sequence := (qs) ; if (bests)->excludes(key) then ( var b : double := Math_PINFINITY ; for split : Integer.subrange(1, (qs)->size() - 1-1) do ( b := Set{b, best(qs.subrange(1,split + 1)) + best(qs.subrange(split+1))}->min()) ; bests->restrict(key) := b + base ) else skip ; return bests->restrict(key) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import log10,floor def findDigits(n,b): if(n<0): return 0 M_PI=3.141592 M_E=2.7182 if(n<=1): return 1 x=((n*log10(n/M_E)+log10(2*M_PI*n)/2.0))/(log10(b)) return floor(x)+1 if __name__=='__main__' : print(findDigits(4,16)) print(findDigits(5,8)) print(findDigits(12,16)) print(findDigits(19,13)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( execute (findDigits(4, 16))->display() ; execute (findDigits(5, 8))->display() ; execute (findDigits(12, 16))->display() ; execute (findDigits(19, 13))->display() ) else skip; operation findDigits(n : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (n < 0) then ( return 0 ) else skip ; var M_PI : double := 3.141592 ; var M_E : double := 2.7182 ; if (n <= 1) then ( return 1 ) else skip ; var x : double := ((n * log10(n / M_E) + log10(2 * M_PI * n) / 2.0)) / (log10(b)) ; return floor(x) + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CntDivbyX(arr,n,x): number=0 count=0 for i in range(n): number=number*2+arr[i] if((number % x==0)): count+=1 return count if __name__=='__main__' : arr=[1,0,1,0,1,1,0] n=len(arr) x=2 print(CntDivbyX(arr,n,x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 0 })))))) ; n := (arr)->size() ; x := 2 ; execute (CntDivbyX(arr, n, x))->display() ) else skip; operation CntDivbyX(arr : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: var number : int := 0 ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( number := number * 2 + arr[i+1] ; if ((number mod x = 0)) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Bit(object): def __init__(self,N): self.N=N self.bit=[0]*(N+1) def add(self,a : int,w : int): x : int=a while x<=self.N : self.bit[x]+=w x+=x &-x def sum(self,a : int): ret : int=0 x : int=a while x>0 : ret+=self.bit[x] x-=x &-x return ret def range_sum(self,x,y): ret1=self.sum(y) ret2=self.sum(x-1) return ret1-ret2 N,q=input().split() N=int(N) q=int(q) bit=Bit(N) for _ in range(q): mode,x,y=input().rstrip().split() if mode=="0" : bit.add(int(x),int(y)) else : ret=bit.range_sum(int(x),int(y)) print(ret) ------------------------------------------------------------ OCL File: --------- class Bit extends object { static operation newBit() : Bit pre: true post: Bit->exists( _x | result = _x ); attribute N : OclAny := N; attribute bit : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)); operation initialise(N : OclAny) : pre: true post: true activity: self.N := N ; self.bit := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)); return self; operation add(a : int,w : int) pre: true post: true activity: var x : int := a ; while (x->compareTo(self.N)) <= 0 do ( self.bit[x+1] := self.bit[x+1] + w ; x := x + MathLib.bitwiseAnd(x, -x)); operation sum(a : int) : OclAny pre: true post: true activity: var ret : int := 0 ; var x : int := a ; while x > 0 do ( ret := ret + self.bit[x+1] ; x := x - MathLib.bitwiseAnd(x, -x)) ; return ret; operation range_sum(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: var ret1 : OclAny := self.sum(y) ; var ret2 : OclAny := self.sum(x - 1) ; return ret1 - ret2; } class FromPython { operation initialise() pre: true post: true activity: skip ; var q : OclAny := null; Sequence{N,q} := input().split() ; N := ("" + ((N)))->toInteger() ; var q : int := ("" + ((q)))->toInteger() ; var bit : Bit := (Bit.newBit()).initialise(N) ; for _anon : Integer.subrange(0, q-1) do ( var mode : OclAny := null; Sequence{mode,x,y} := input().rstrip().split() ; if mode = "0" then ( execute ((("" + ((x)))->toInteger(), ("" + ((y)))->toInteger()) : bit) ) else ( ret := bit.range_sum(("" + ((x)))->toInteger(), ("" + ((y)))->toInteger()) ; execute (ret)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline class SegmentTree : def __init__(self,num,ide_ele=0): tmp=1 while tmp0 : i=(i-1)//2 self.l[i]=self.func(self.l[i*2+1],self.l[i*2+2]) def query(self,a,b,k,l,r): if r<=a or b<=l : return self.ide_ele if a<=l and r<=b : return self.l[k] vl=self.query(a,b,k*2+1,l,(l+r)//2) vr=self.query(a,b,k*2+2,(l+r)//2,r) return self.func(vl,vr) def main(): N,Q=map(int,input().split()) segt=SegmentTree(N) for _ in range(Q): c,x,y=map(int,input().split()) if c==0 : segt.update(x-1,y) else : print(segt.query(x-1,y,0,0,segt.n)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class SegmentTree { static operation newSegmentTree() : SegmentTree pre: true post: SegmentTree->exists( _x | result = _x ); attribute n : int := tmp; attribute ide_ele : int := ide_ele; attribute l : Sequence := MatrixLib.elementwiseMult(Sequence{ ide_ele }, (2 * self.n - 1)); operation initialise(num : OclAny,ide_ele : int) : SegmentTree pre: true post: true activity: var tmp : int := 1 ; while (tmp->compareTo(num)) < 0 do ( tmp := tmp * 2) ; self.n := tmp ; self.ide_ele := ide_ele ; self.l := MatrixLib.elementwiseMult(Sequence{ ide_ele }, (2 * self.n - 1)); return self; operation func(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: return x + y; operation update(i : OclAny,val : OclAny) pre: true post: true activity: i := self.n - 1 + i ; self.l[i+1] := self.l[i+1] + val ; while i > 0 do ( i := (i - 1) div 2 ; self.l[i+1] := self.func(self.l[i * 2 + 1+1], self.l[i * 2 + 2+1])); operation query(a : OclAny,b : OclAny,k : OclAny,l : OclAny,r : OclAny) : OclAny pre: true post: true activity: if (r->compareTo(a)) <= 0 or (b->compareTo(l)) <= 0 then ( return self.ide_ele ) else skip ; if (a->compareTo(l)) <= 0 & (r->compareTo(b)) <= 0 then ( return self.l[k+1] ) else skip ; var vl : OclAny := self.query(a, b, k * 2 + 1, l, (l + r) div 2) ; var vr : OclAny := self.query(a, b, k * 2 + 2, (l + r) div 2, r) ; return self.func(vl, vr); } class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var Q : OclAny := null; Sequence{N,Q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var segt : SegmentTree := (SegmentTree.newSegmentTree()).initialise(N) ; for _anon : Integer.subrange(0, Q-1) do ( var c : OclAny := null; Sequence{c,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if c = 0 then ( execute ((x - 1, y) <: segt) ) else ( execute (segt.query(x - 1, y, 0, 0, segt.n))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def update(numlist,i): if i<0 : return if i==0 : numlist[i]=numlist[2*i+1]+numlist[2*i+2] return numlist[i]=numlist[2*i+1]+numlist[2*i+2] update(numlist,(i-1)//2) return def find(numlist,x,y,k,minimum,maximum): if x>=maximum or ycollect( _x | (OclType["int"])->apply(_x) ) ; var L2n : double := ()->ceil() ; var zero : double := (2)->pow((L2n)) - 1 ; var MAX : double := (2)->pow(31) - 1 ; numlist := MatrixLib.elementwiseMult(Sequence{ 0 }, ((2)->pow((L2n + 1)) - 1)) ; var resultlist : Sequence := Sequence{} ; for _anon : Integer.subrange(0, q-1) do ( var com : OclAny := null; Sequence{com,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if com then ( execute ((find(numlist, x - 1, y - 1, 0, 0, (2)->pow(L2n))) : resultlist) ) else ( numlist[zero + x - 1+1] := numlist[zero + x - 1+1] + y ; update(numlist, (zero + x - 2) div 2) )) ; for x : resultlist do ( execute (x)->display()); operation update(numlist : OclAny, i : OclAny) pre: true post: true activity: if i < 0 then ( return ) else skip ; if i = 0 then ( numlist[i+1] := numlist[2 * i + 1+1] + numlist[2 * i + 2+1] ; return ) else skip ; numlist[i+1] := numlist[2 * i + 1+1] + numlist[2 * i + 2+1] ; update(numlist, (i - 1) div 2) ; return; operation find(numlist : OclAny, x : OclAny, y : OclAny, k : OclAny, minimum : OclAny, maximum : OclAny) : OclAny pre: true post: true activity: if (x->compareTo(maximum)) >= 0 or (y->compareTo(minimum)) < 0 then ( return 0 ) else skip ; if (x->compareTo(minimum)) <= 0 & (maximum - 1->compareTo(y)) <= 0 then ( return numlist[k+1] ) else ( var L : OclAny := find(numlist, x, y, k * 2 + 1, minimum, (maximum + minimum) div 2) ; var R : OclAny := find(numlist, x, y, k * 2 + 2, (maximum + minimum) div 2, maximum) ; return L + R ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import division,print_function from sys import stdin def main(readline=stdin.readline): n,q=(int(s)for s in readline().split()) a=[0]*n b=[0]*(n//100+1) for _ in range(q): com,x,y=(int(s)for s in readline().split()) if com : x-=1 bx=x-x % 100+100 by=y-y % 100 if bxoclIsUndefined() then readline := stdin.readline else skip; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name readline)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n div 100 + 1)) ; for _anon : Integer.subrange(0, q-1) do ( var com : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{com,x,y} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name readline)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; if com then ( x := x - 1 ; var bx : double := x - x mod 100 + 100 ; var by : double := y - y mod 100 ; if (bx->compareTo(by)) < 0 then ( var s : OclAny := (a.subrange(x+1, bx))->sum() + (b.subrange(bx div 100+1, by div 100))->sum() + (a.subrange(by+1, y))->sum() ) else ( s := (a.subrange(x+1, y))->sum() ) ; execute (s)->display() ) else ( x := x - 1 ; a[x+1] := a[x+1] + y ; bx := x - x mod 100 ; b[x div 100+1] := (a.subrange(bx+1, bx + 100))->sum() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def segfunc(x,y): return x+y ide_ele=0 class SegTree : def __init__(self,init_val,segfunc,ide_ele): n=len(init_val) self.segfunc=segfunc self.ide_ele=ide_ele self.num=1<<(n-1).bit_length() self.tree=[ide_ele]*2*self.num for i in range(n): self.tree[self.num+i]=init_val[i] for i in range(self.num-1,0,-1): self.tree[i]=segfunc(self.tree[2*i],self.tree[2*i+1]) def update(self,k,x): k+=self.num self.tree[k]=x while k>1 : self.tree[k>>1]=segfunc(self.tree[k],self.tree[k ^ 1]) k>>=1 def query(self,l,r): res=self.ide_ele l+=self.num r+=self.num while l>=1 r>>=1 return res n,q=[int(x)for x in input().split()] seg=SegTree([0]*n,segfunc,ide_ele) for _ in range(q): com,x,y=[int(x)for x in input().split()] if com : print(seg.query(x-1,y)) else : x-=1 y+=seg.tree[seg.num+x] seg.update(x,y) ------------------------------------------------------------ OCL File: --------- class SegTree { static operation newSegTree() : SegTree pre: true post: SegTree->exists( _x | result = _x ); attribute segfunc : OclAny := segfunc; attribute ide_ele : int := ide_ele; attribute num : int := 1 * (2->pow((n - 1).bit_length())); attribute tree : Sequence := MatrixLib.elementwiseMult(MatrixLib.elementwiseMult(Sequence{ ide_ele }, 2), self.num); operation initialise(init_val : OclAny,segfunc : OclAny,ide_ele : OclAny) : SegTree pre: true post: true activity: var n : int := (init_val)->size() ; self.segfunc := segfunc ; self.ide_ele := ide_ele ; self.num := 1 * (2->pow((n - 1).bit_length())) ; self.tree := MatrixLib.elementwiseMult(MatrixLib.elementwiseMult(Sequence{ ide_ele }, 2), self.num) ; for i : Integer.subrange(0, n-1) do ( self.tree[self.num + i+1] := init_val[i+1]) ; for i : Integer.subrange(0 + 1, self.num - 1)->reverse() do ( self.tree[i+1] := segfunc(self.tree[2 * i+1], self.tree[2 * i + 1+1])); return self; operation update(k : OclAny,x : OclAny) pre: true post: true activity: k := k + self.num ; self.tree[k+1] := x ; while k > 1 do ( self.tree[k /(2->pow(1))+1] := segfunc(self.tree[k+1], self.tree[MathLib.bitwiseXor(k, 1)+1]) ; k := k div (2->pow(1))); operation query(l : OclAny,r : OclAny) : OclAny pre: true post: true activity: var res : OclAny := self.ide_ele ; l := l + self.num ; r := r + self.num ; while (l->compareTo(r)) < 0 do ( if MathLib.bitwiseAnd(l, 1) then ( res := segfunc(res, self.tree[l+1]) ; l := l + 1 ) else skip ; if MathLib.bitwiseAnd(r, 1) then ( res := segfunc(res, self.tree[r - 1+1]) ) else skip ; l := l div (2->pow(1)) ; r := r div (2->pow(1))) ; return res; } class FromPython { operation initialise() pre: true post: true activity: skip ; var ide_ele : int := 0 ; skip ; var q : OclAny := null; Sequence{n,q} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var seg : SegTree := (SegTree.newSegTree()).initialise(MatrixLib.elementwiseMult(Sequence{ 0 }, n), segfunc, ide_ele) ; for _anon : Integer.subrange(0, q-1) do ( var com : OclAny := null; Sequence{com,x,y} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if com then ( execute (seg.query(x - 1, y))->display() ) else ( x := x - 1 ; y := y + seg.tree[seg.num + x+1] ; execute ((x, y) <: seg) )); operation segfunc(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return x + y; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=10**9+7 n=int(input()) def nth_bit(d): return(n>>d)& 1 dp=[[0,0,0]for _ in range(61)] dp[-1][0]=1 for d in range(59,-1,-1): for s in range(3): for k in range(3): s2=min(2,2*s+nth_bit(d)-k) if s2>=0 : dp[d][s2]+=dp[d+1][s] ans=sum(dp[0])% mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : double := (10)->pow(9) + 7 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; var dp : Sequence := Integer.subrange(0, 61-1)->select(_anon | true)->collect(_anon | (Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))) ; dp->last()->first() := 1 ; for d : Integer.subrange(-1 + 1, 59)->reverse() do ( for s : Integer.subrange(0, 3-1) do ( for k : Integer.subrange(0, 3-1) do ( var s2 : OclAny := Set{2, 2 * s + nth_bit(d) - k}->min() ; if s2 >= 0 then ( dp[d+1][s2+1] := dp[d+1][s2+1] + dp[d + 1+1][s+1] ) else skip))) ; var ans : int := (dp->first())->sum() mod mod ; execute (ans)->display(); operation nth_bit(d : OclAny) : OclAny pre: true post: true activity: return MathLib.bitwiseAnd((n /(2->pow(d))), 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque,Counter from heapq import heappush,heappop,heapify import math from bisect import bisect_left,bisect_right import random from itertools import permutations,accumulate,combinations import sys import string INF=float('inf') def LI(): return list(map(int,sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return sys.stdin.readline().strip() def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] def SRL(n): return[list(S())for i in range(n)] def MSRL(n): return[[int(j)for j in list(S())]for i in range(n)] mod=10**9+7 n=bin(I())[2 :] dp0,dp1,dp2=1,0,0 for d in n : if d=='1' : dp0,dp1,dp2=dp0 % mod,(dp0+dp1)% mod,(dp1*2+dp2*3)% mod else : dp0,dp1,dp2=(dp0+dp1)% mod,dp1 % mod,(dp1+dp2*3)% mod print((dp0+dp1+dp2)% mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var INF : double := ("" + (('inf')))->toReal() ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; n := bin(I()).subrange(2+1) ; var dp0 : OclAny := null; var dp1 : OclAny := null; var dp2 : OclAny := null; Sequence{dp0,dp1,dp2} := Sequence{1,0,0} ; for d : n do ( if d = '1' then ( var dp0 : OclAny := null; var dp1 : OclAny := null; var dp2 : OclAny := null; Sequence{dp0,dp1,dp2} := Sequence{dp0 mod mod,(dp0 + dp1) mod mod,(dp1 * 2 + dp2 * 3) mod mod} ) else ( var dp0 : OclAny := null; var dp1 : OclAny := null; var dp2 : OclAny := null; Sequence{dp0,dp1,dp2} := Sequence{(dp0 + dp1) mod mod,dp1 mod mod,(dp1 + dp2 * 3) mod mod} )) ; execute ((dp0 + dp1 + dp2) mod mod)->display(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation S() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation SRL(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | ((S()))); operation MSRL(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | ((S())->select(j | true)->collect(j | (("" + ((j)))->toInteger())))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) binN=format(N,"b").zfill(60) mod=7+10**9 DP=[[0,0,0]for _ in range(60)] if binN[0]=="0" : DP[0]=[1,0,0] else : DP[0]=[1,1,0] for i in range(1,60): if binN[i]=="0" : DP[i][0]=(DP[i-1][0]+DP[i-1][1])% mod DP[i][1]=DP[i-1][1] DP[i][2]=(DP[i-1][2]*3+DP[i-1][1])% mod else : DP[i][0]=DP[i-1][0] DP[i][1]=(DP[i-1][0]+DP[i-1][1])% mod DP[i][2]=(DP[i-1][2]*3+DP[i-1][1]*2)% mod print(sum(DP[-1])% mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var binN : OclAny := format(N, "b").zfill(60) ; var mod : int := 7 + (10)->pow(9) ; var DP : Sequence := Integer.subrange(0, 60-1)->select(_anon | true)->collect(_anon | (Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))) ; if binN->first() = "0" then ( DP->first() := Sequence{1}->union(Sequence{0}->union(Sequence{ 0 })) ) else ( DP->first() := Sequence{1}->union(Sequence{1}->union(Sequence{ 0 })) ) ; for i : Integer.subrange(1, 60-1) do ( if binN[i+1] = "0" then ( DP[i+1]->first() := (DP[i - 1+1]->first() + DP[i - 1+1][1+1]) mod mod ; DP[i+1][1+1] := DP[i - 1+1][1+1] ; DP[i+1][2+1] := (DP[i - 1+1][2+1] * 3 + DP[i - 1+1][1+1]) mod mod ) else ( DP[i+1]->first() := DP[i - 1+1]->first() ; DP[i+1][1+1] := (DP[i - 1+1]->first() + DP[i - 1+1][1+1]) mod mod ; DP[i+1][2+1] := (DP[i - 1+1][2+1] * 3 + DP[i - 1+1][1+1] * 2) mod mod )) ; execute ((DP->last())->sum() mod mod)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_right,bisect_left n,*l=map(int,open(0).read().split()) l.sort() ans=0 for i in range(n): for j in range(i+1,n): a=l[i] b=l[j] right=bisect_left(l,a+b) left=bisect_right(l,max(a-b,b-a)) tmp=max(0,right-left) if left<=icollect( _x | (OclType["int"])->apply(_x) ) ; l := l->sort() ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( var a : OclAny := l[i+1] ; var b : OclAny := l[j+1] ; var right : OclAny := bisect_left(l, a + b) ; var left : OclAny := bisect_right(l, Set{a - b, b - a}->max()) ; var tmp : OclAny := Set{0, right - left}->max() ; if (left->compareTo(i)) <= 0 & (i < right) then ( tmp := tmp - 1 ) else skip ; if (left->compareTo(j)) <= 0 & (j < right) then ( tmp := tmp - 1 ) else skip ; ans := ans + tmp)) ; execute (ans div 3)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from gcjt import* for t in tests(): p,q=tuple(t.ri()) x=(0,)+tuple(t.ri())+(p+1,) f=array(q+2,q+2) for i in range(0,q+1): f[i][i+1]=0 for l in range(2,q+2): for i in range(q+2-l): f[i][i+l]=x[i+l]-x[i]-2+min(f[i][j]+f[j][i+l]for j in range(i+1,i+l)) t.answer(f[0][q+1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for t : tests() do ( var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := (t.ri()) ; var x : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) ,)}->union((t.ri())) + Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom (name p))) + (expr (atom (number (integer 1)))))))) ,)} ; var f : OclAny := array(q + 2, q + 2) ; for i : Integer.subrange(0, q + 1-1) do ( f[i+1][i + 1+1] := 0) ; for l : Integer.subrange(2, q + 2-1) do ( for i : Integer.subrange(0, q + 2 - l-1) do ( f[i+1][i + l+1] := x[i + l+1] - x[i+1] - 2 + ((argument (test (logical_test (comparison (expr (expr (atom (name f)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))) + (expr (atom (name f)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name l))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name l))))))))) )))))))))->min())) ; t.answer(f->first()[q + 1+1])); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Dp(x,hl,islim): if x==len(digit): return hl==0 if f[x][hl][islim]: return f[x][hl][islim] ans=0 mx=int(digit[x])if islim else 1 for i in range(mx+1): ans+=Dp(x+1,hl,islim and i==mx) if hl!=i : ans+=Dp(x+1,not hl,islim and i==mx) ans %=p f[x][hl][islim]=ans return ans p=10**9+7 digit=bin(int(input()))[2 :] f=[[[0,0],[0,0]]for i in range(len(digit))] print(Dp(0,0,1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var p : double := (10)->pow(9) + 7 ; var digit : OclAny := bin(("" + (((OclFile["System.in"]).readLine())))->toInteger()).subrange(2+1) ; var f : Sequence := Integer.subrange(0, (digit)->size()-1)->select(i | true)->collect(i | (Sequence{Sequence{0}->union(Sequence{ 0 })}->union(Sequence{ Sequence{0}->union(Sequence{ 0 }) }))) ; execute (Dp(0, 0, 1))->display(); operation Dp(x : OclAny, hl : OclAny, islim : OclAny) : OclAny pre: true post: true activity: if x = (digit)->size() then ( return hl = 0 ) else skip ; if f[x+1][hl+1][islim+1] then ( return f[x+1][hl+1][islim+1] ) else skip ; var ans : int := 0 ; var mx : int := if islim then ("" + ((digit[x+1])))->toInteger() else 1 endif ; for i : Integer.subrange(0, mx + 1-1) do ( ans := ans + Dp(x + 1, hl, islim & i = mx) ; if hl /= i then ( ans := ans + Dp(x + 1, not(hl), islim & i = mx) ) else skip) ; ans := ans mod p ; f[x+1][hl+1][islim+1] := ans ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.read readline=sys.stdin.readline n,=map(int,read().split()) d={} def f(n,m): if(n,m)in d : return d[(n,m)] if n<0 or m<0 : return 0 if n==0 : return max(1+n//2,1+m//2) if m==0 : return 1 nn=n>>1 if n & 1 else(n>>1)-1 mm=m>>1 if m & 1 else(m>>1)-1 v=f(nn,mm)+f(n>>1,m>>1)+f(n>>1,(m>>1)-1) d[(n,m)]=v return v ans=f(n,n) print(ans %(10**9+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := (OclFile["System.in"]).read ; var readline : OclAny := (OclFile["System.in"]).readline ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,)} := (read().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : OclAny := Set{} ; skip ; var ans : String := f(n, n) ; execute (StringLib.format(ans,((10)->pow(9) + 7)))->display(); operation f(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: if (d)->includes(Sequence{n, m}) then ( return d[Sequence{n, m}+1] ) else skip ; if n < 0 or m < 0 then ( return 0 ) else skip ; if n = 0 then ( return Set{1 + n div 2, 1 + m div 2}->max() ) else skip ; if m = 0 then ( return 1 ) else skip ; var nn : int := if MathLib.bitwiseAnd(n, 1) then n /(2->pow(1)) else (n /(2->pow(1))) - 1 endif ; var mm : int := if MathLib.bitwiseAnd(m, 1) then m /(2->pow(1)) else (m /(2->pow(1))) - 1 endif ; var v : String := f(nn, mm) + f(n /(2->pow(1)), m /(2->pow(1))) + f(n /(2->pow(1)), (m /(2->pow(1))) - 1) ; d[Sequence{n, m}+1] := v ; return v; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=list(map(lambda x : int(x)-1,input().split())) ts=[[]for _ in range(n)] p=0 t=0 while True : ts[p].append(t) if t==k : print(p+1) exit() if len(ts[p])==2 : if(k-ts[p][0])%(ts[p][1]-ts[p][0])==0 : print(p+1) exit() p=a[p] t+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) )) ; var ts : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var p : int := 0 ; var t : int := 0 ; while true do ((expr (atom (name ts)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name p)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) )))) ; if t = k then ( execute (p + 1)->display() ; exit() ) else skip ; if (ts[p+1])->size() = 2 then ( if (k - ts[p+1]->first()) mod (ts[p+1][1+1] - ts[p+1]->first()) = 0 then ( execute (p + 1)->display() ; exit() ) else skip ) else skip ; p := a[p+1] ; t := t + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import lru_cache @ lru_cache(maxsize=1<<10) def solve(p,q,a,n): def _solve(num,dem,d,m,s): if num==0 : return 1 if d==0 : return 0 if num*a//mcollect( _x | (OclType["int"])->apply(_x) ) ; if p = 0 then ( break ) else skip ; execute ((solve(p, q, a, n)) : ans)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import gcd def solve(p,q,a,n,l=1): ans=1 if p==1 and q<=a and q>=l else 0 denom=max(l,q//p) p_denom=denom*p while n*q>=p_denom and denom<=a : p_,q_=p_denom-q,q*denom if p_<=0 : denom+=1 p_denom+=p continue gcd_=gcd(p_,q_) p_//=gcd_ q_//=gcd_ if n==2 and p_==1 and q_*denom<=a and q_>=denom : ans+=1 else : ans+=solve(p_,q_,a//denom,n-1,denom) denom+=1 p_denom+=p return ans while True : p,q,a,n=map(int,input().split()) if p==q==a==n==0 : break gcd_=gcd(p,q) p//=gcd_ q//=gcd_ if n==1 : print(1 if p==1 and q<=a else 0) else : print(solve(p,q,a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( Sequence{p,q,a,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if p = q & (q == a) & (a == n) & (n == 0) then ( break ) else skip ; gcd_ := gcd(p, q) ; p := p div gcd_ ; q := q div gcd_ ; if n = 1 then ( execute (if p = 1 & (q->compareTo(a)) <= 0 then 1 else 0 endif)->display() ) else ( execute (solve(p, q, a, n))->display() )); operation solve(p : OclAny, q : OclAny, a : OclAny, n : OclAny, l : int) : OclAny pre: true post: true activity: if l->oclIsUndefined() then l := 1 else skip; var ans : int := if p = 1 & (q->compareTo(a)) <= 0 & (q->compareTo(l)) >= 0 then 1 else 0 endif ; var denom : OclAny := Set{l, q div p}->max() ; var p_denom : double := denom * p ; while (n * q->compareTo(p_denom)) >= 0 & (denom->compareTo(a)) <= 0 do ( var p_ : OclAny := null; var q_ : OclAny := null; Sequence{p_,q_} := Sequence{p_denom - q,q * denom} ; if p_ <= 0 then ( denom := denom + 1 ; p_denom := p_denom + p ; continue ) else skip ; var gcd_ : OclAny := gcd(p_, q_) ; p_ := p_ div gcd_ ; q_ := q_ div gcd_ ; if n = 2 & p_ = 1 & (q_ * denom->compareTo(a)) <= 0 & (q_->compareTo(denom)) >= 0 then ( ans := ans + 1 ) else ( ans := ans + solve(p_, q_, a div denom, n - 1, denom) ) ; denom := denom + 1 ; p_denom := p_denom + p) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import lru_cache @ lru_cache(maxsize=1<<10) def solve(p,q,a,n): def _solve(num,dem,d,m,s): if num==0 : return 1 if d==0 : return 0 if num*a//mselect(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if p = 0 then ( break ) else skip ; execute ((solve(p, q, a, n)) : ans)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import lru_cache @ lru_cache(maxsize=1<<10) def solve(p,q,a,n): def _solve(num,dem,d,m,s): if num==0 : return 1 if d==0 : return 0 if num*a//mselect(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if p = 0 then ( break ) else skip ; execute ((solve(p, q, a, n)) : ans)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binary_conversion(s,m): while(m): temp=m % 2 s+=str(temp) m=m//2 return s[: :-1] def find_character(n,m,i): s="" s=binary_conversion(s,m) s1="" for x in range(n): for j in range(len(s)): if s[j]=="1" : s1+="10" else : s1+="01" s=s1 s1="" e=ord(s[i]) r=ord('0') return e-r m,n,i=5,2,8 print(find_character(n,m,i)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{m,n,i} := Sequence{5,2,8} ; execute (find_character(n, m, i))->display(); operation binary_conversion(s : OclAny, m : OclAny) : OclAny pre: true post: true activity: while (m) do ( var temp : int := m mod 2 ; s := s + ("" + ((temp))) ; m := m div 2) ; return s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); operation find_character(n : OclAny, m : OclAny, i : OclAny) : OclAny pre: true post: true activity: s := "" ; s := binary_conversion(s, m) ; var s1 : String := "" ; for x : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, (s)->size()-1) do ( if s[j+1] = "1" then ( s1 := s1 + "10" ) else ( s1 := s1 + "01" )) ; s := s1 ; s1 := "") ; var e : int := (s[i+1])->char2byte() ; var r : int := ('0')->char2byte() ; return e - r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSubSets(arr,n): us=set() even_count=0 for i in range(n): if arr[i]% 2==0 : us.add(arr[i]) even_count=len(us) return pow(2,even_count)-1 arr=[4,2,1,9,2,6,5,3] n=len(arr) print("Numbers of subset=",countSubSets(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{4}->union(Sequence{2}->union(Sequence{1}->union(Sequence{9}->union(Sequence{2}->union(Sequence{6}->union(Sequence{5}->union(Sequence{ 3 }))))))) ; n := (arr)->size() ; execute ("Numbers of subset=")->display(); operation countSubSets(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var us : Set := Set{}->union(()) ; var even_count : int := 0 ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] mod 2 = 0 then ( execute ((arr[i+1]) : us) ) else skip) ; even_count := (us)->size() ; return (2)->pow(even_count) - 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000 f=[0]*MAX def fib(n): if(n==0): return 0 if(n==1 or n==2): f[n]=1 return f[n] if(f[n]): return f[n] k=(n+1)//2 if(n & 1)else n//2 if(n & 1): f[n]=(fib(k)*fib(k)+fib(k-1)*fib(k-1)) else : f[n]=(2*fib(k-1)+fib(k))*fib(k) return f[n] def gcd(a,b): if(a==0): return b return gcd(b % a,a) def findLCMFibonacci(a,b): return(fib(a)*fib(b))//fib(gcd(a,b)) if __name__=="__main__" : a=3 b=12 print(findLCMFibonacci(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1000 ; var f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX) ; skip ; skip ; skip ; if __name__ = "__main__" then ( a := 3 ; b := 12 ; execute (findLCMFibonacci(a, b))->display() ) else skip; operation fib(n : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return 0 ) else skip ; if (n = 1 or n = 2) then ( f[n+1] := 1 ; return f[n+1] ) else skip ; if (f[n+1]) then ( return f[n+1] ) else skip ; var k : int := if (MathLib.bitwiseAnd(n, 1)) then (n + 1) div 2 else n div 2 endif ; if (MathLib.bitwiseAnd(n, 1)) then ( f[n+1] := (fib(k) * fib(k) + fib(k - 1) * fib(k - 1)) ) else ( f[n+1] := (2 * fib(k - 1) + fib(k)) * fib(k) ) ; return f[n+1]; operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0) then ( return b ) else skip ; return gcd(b mod a, a); operation findLCMFibonacci(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (fib(a) * fib(b)) div fib(gcd(a, b)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) W=[] for i in range(N): W.append(list(input())) cnt=0 for i in range(1,N): if W[i][0]!=W[i-1][-1]: cnt=1 W.sort() for i in range(1,N): if W[i]==W[i-1]: cnt=1 if cnt==1 : print("No") else : print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var W : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute ((((OclFile["System.in"]).readLine())->characters()) : W)) ; var cnt : int := 0 ; for i : Integer.subrange(1, N-1) do ( if W[i+1]->first() /= W[i - 1+1]->last() then ( cnt := 1 ) else skip) ; W := W->sort() ; for i : Integer.subrange(1, N-1) do ( if W[i+1] = W[i - 1+1] then ( cnt := 1 ) else skip) ; if cnt = 1 then ( execute ("No")->display() ) else ( execute ("Yes")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNumbers(n,w): x=0 ; sum=0 ; if(w>=0 and w<=8): x=9-w ; elif(w>=-9 and w<=-1): x=10+w ; sum=pow(10,n-2); sum=(x*sum); return sum ; n=3 ; w=4 ; print(findNumbers(n,w)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3; ; w := 4; ; execute (findNumbers(n, w))->display();; operation findNumbers(n : OclAny, w : OclAny) pre: true post: true activity: var x : int := 0; ; var sum : int := 0; ; if (w >= 0 & w <= 8) then ( x := 9 - w; ) else (if (w >= -9 & w <= -1) then ( x := 10 + w; ) else skip) ; sum := (10)->pow(n - 2); ; sum := (x * sum); ; return sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findKthChar(s,k): len1=len(s) i=0 total_len=0 while(idisplay() ) else skip; operation findKthChar(s : OclAny, k : OclAny) : OclAny pre: true post: true activity: var len1 : int := (s)->size() ; var i : int := 0 ; var total_len : int := 0 ; while ((i->compareTo(len1)) < 0) do ( if (s[i+1]->matches("[a-zA-Z]*")) then ( total_len := total_len + 1 ; if (total_len = k) then ( return s[i+1] ) else skip ; i := i + 1 ) else ( var n : int := 0 ; while ((i->compareTo(len1)) < 0 & s[i+1]->matches("[a-zA-Z]*") = false) do ( n := n * 10 + ((s[i+1])->char2byte() - ('0')->char2byte()) ; i := i + 1) ; var next_total_len : int := total_len * n ; if ((k->compareTo(next_total_len)) <= 0) then ( var pos : int := k mod total_len ; if (pos = 0) then ( pos := total_len ) else skip ; return findKthChar(s, pos) ) else ( total_len := next_total_len ) )) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countNonEmptySubstr(str): n=len(str); return int(n*(n+1)/2); s="abcde" ; print(countNonEmptySubstr(s)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : String := "abcde"; ; execute (countNonEmptySubstr(s))->display();; operation countNonEmptySubstr(OclType["String"] : OclAny) pre: true post: true activity: var n : int := (OclType["String"])->size(); ; return ("" + ((n * (n + 1) / 2)))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): _,K=[int(x)for x in input().split()] A=[int(x)for x in input().split()] history=[1] history_dict={1 : 0} last_city=-1 for x in range(K): now=A[history[-1]-1] if now in history_dict : last_city=now break history.append(now) history_dict[now]=x+1 if last_city==-1 : print(history[-1]) else : index=history_dict[last_city] mod=(K-index)%(len(history)-index) print(history[index+mod]) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var _anon : OclAny := null; var K : OclAny := null; Sequence{_anon,K} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var history : Sequence := Sequence{ 1 } ; var history_dict : Map := Map{ 1 |-> 0 } ; var last_city : int := -1 ; for x : Integer.subrange(0, K-1) do ( var now : OclAny := A[history->last() - 1+1] ; if (history_dict)->includes(now) then ( last_city := now ; break ) else skip ; execute ((now) : history) ; history_dict[now+1] := x + 1) ; if last_city = -1 then ( execute (history->last())->display() ) else ( var index : OclAny := history_dict[last_city+1] ; var mod : int := (K - index) mod ((history)->size() - index) ; execute (history[index + mod+1])->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int,sys.stdin.readline().rstrip())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def LS2(): return list(sys.stdin.readline().rstrip()) N,K=MI() A=[0]+LI() visited=[0]*(N+1) times=[0]*(N+1) i=1 a=0 visited[1]=0 times[0]=1 while True : i=A[i] a+=1 if visited[i]!=0 : times[a]=i b,c=visited[i],a break else : visited[i]=a times[a]=i if K<=a : print(times[K]) else : print(times[a+(K-a)%(b-a)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := MI() ; var A : Sequence := Sequence{ 0 }->union(LI()) ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; var times : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; var i : int := 1 ; var a : int := 0 ; visited[1+1] := 0 ; times->first() := 1 ; while true do ( i := A[i+1] ; a := a + 1 ; if visited[i+1] /= 0 then ( times[a+1] := i ; var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := Sequence{visited[i+1],a} ; break ) else ( visited[i+1] := a ; times[a+1] := i )) ; if (K->compareTo(a)) <= 0 then ( execute (times[K+1])->display() ) else ( execute (times[a + (K - a) mod (b - a)+1])->display() ); operation I() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.readLine().rstrip())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LI2() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().rstrip())->collect( _x | (OclType["int"])->apply(_x) )); operation S() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation LS() : OclAny pre: true post: true activity: return (sys.stdin.readLine().rstrip().split()); operation LS2() : OclAny pre: true post: true activity: return (sys.stdin.readLine().rstrip()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict N,K=map(int,input().split()) L=list(map(int,input().split())) L.insert(0,-1) path=[1] ind=0 count=0 x=1 t=-1 flag=False Hash=defaultdict(lambda : 0) for i in range(N+1): ne=L[x] if Hash[ne]: flag=True t=Hash[ne] break path.append(ne) ind+=1 Hash[ne]=ind x=ne if flag==True : loop=path[t : :] if K<(len(path)): print(path[K]) else : K=K-len(path) K=K % len(loop) print(loop[K]) else : print(path[K-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var L : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; L := L.insertAt(0+1, -1) ; var path : Sequence := Sequence{ 1 } ; var ind : int := 0 ; var count : int := 0 ; var x : int := 1 ; var t : int := -1 ; var flag : boolean := false ; var Hash : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; for i : Integer.subrange(0, N + 1-1) do ( var ne : OclAny := L[x+1] ; if Hash[ne+1] then ( flag := true ; t := Hash[ne+1] ; break ) else skip ; execute ((ne) : path) ; ind := ind + 1 ; Hash[ne+1] := ind ; x := ne) ; if flag = true then ( var loop : OclAny := path(subscript (test (logical_test (comparison (expr (atom (name t)))))) : (sliceop :)) ; if (K->compareTo(((path)->size()))) < 0 then ( execute (path[K+1])->display() ) else ( var K : double := K - (path)->size() ; K := K mod (loop)->size() ; execute (loop[K+1])->display() ) ) else ( execute (path[K - 1+1])->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().strip().split()) L=list(map(int,input().strip().split())) L=[v-1 for v in L] seen=set() cur=0 untillBackToIntersec=0 while cur not in seen : seen.add(cur) untillBackToIntersec+=1 cur=L[cur] intersec=cur cur=0 beforeLoop=0 while cur!=intersec : cur=L[cur] beforeLoop+=1 if k<=beforeLoop : proceed=k else : loopSize=untillBackToIntersec-beforeLoop proceed=(k-beforeLoop)%(loopSize)+beforeLoop ans=0 for _ in range(proceed): ans=L[ans] print(ans+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var L : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; L := L->select(v | true)->collect(v | (v - 1)) ; var seen : Set := Set{}->union(()) ; var cur : int := 0 ; var untillBackToIntersec : int := 0 ; while (seen)->excludes(cur) do ( execute ((cur) : seen) ; untillBackToIntersec := untillBackToIntersec + 1 ; cur := L[cur+1]) ; var intersec : int := cur ; cur := 0 ; var beforeLoop : int := 0 ; while cur /= intersec do ( cur := L[cur+1] ; beforeLoop := beforeLoop + 1) ; if (k->compareTo(beforeLoop)) <= 0 then ( var proceed : OclAny := k ) else ( var loopSize : double := untillBackToIntersec - beforeLoop ; proceed := (k - beforeLoop) mod (loopSize) + beforeLoop ) ; var ans : int := 0 ; for _anon : Integer.subrange(0, proceed-1) do ( ans := L[ans+1]) ; execute (ans + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,n=map(int,input().split()) s=input() if n>(m//2): while n!=m : print("RIGHT") n+=1 while n!=1 : print("PRINT",s[n-1]) print("LEFT") n-=1 print("PRINT",s[n-1]) elif n<=(m//2): while n!=1 : print("LEFT") n-=1 while n!=m : print("PRINT",s[n-1]) print("RIGHT") n+=1 print("PRINT",s[n-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; if (n->compareTo((m div 2))) > 0 then ( while n /= m do ( execute ("RIGHT")->display() ; n := n + 1) ; while n /= 1 do ( execute ("PRINT")->display() ; execute ("LEFT")->display() ; n := n - 1) ; execute ("PRINT")->display() ) else (if (n->compareTo((m div 2))) <= 0 then ( while n /= 1 do ( execute ("LEFT")->display() ; n := n - 1) ; while n /= m do ( execute ("PRINT")->display() ; execute ("RIGHT")->display() ; n := n + 1) ; execute ("PRINT")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import math import sys def main(): n=int(input()) a=list(map(int,input().split())) d=collections.defaultdict(int) for x in a : c=0 while x>0 : c+=x % 2 x//=2 d[c]+=1 ans=0 for v in d.values(): ans+=v*(v-1)//2 print(ans) if __name__=="__main__" : t=1 while t>0 : main() t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( var t : int := 1 ; while t > 0 do ( main() ; t := t - 1) ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := .defaultdict(OclType["int"]) ; for x : a do ( var c : int := 0 ; while x > 0 do ( c := c + x mod 2 ; x := x div 2) ; d[c+1] := d[c+1] + 1) ; var ans : int := 0 ; for v : d.values() do ( ans := ans + v * (v - 1) div 2) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): input() return nPairsWithCommonFX(map(int,input().split())) def nPairsWithCommonFX(sequence): storage={} FXs=[] for value in sequence : y=f(value) if y not in storage : storage[y]=[value] FXs.append(y) else : storage[y].append(value) return(sum(len(storage[y])*len(storage[y])for y in FXs)-sum(len(storage[y])for y in FXs))//2 def f(n): y=1 while n!=1 : if n % 2 : y+=1 n//=2 return y if __name__=='__main__' : print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( execute (main())->display() ) else skip; operation main() : OclAny pre: true post: true activity: input() ; return nPairsWithCommonFX((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation nPairsWithCommonFX(sequence : OclAny) : OclAny pre: true post: true activity: var storage : OclAny := Set{} ; var FXs : Sequence := Sequence{} ; for value : sequence do ( var y : String := f(value) ; if (storage)->excludes(y) then ( storage->at(y) := Sequence{ value } ; execute ((y) : FXs) ) else ( (expr (atom (name storage)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name value)))))))) )))) )) ; return (((argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name storage)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])))))))) )))) * (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name storage)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])))))))) )))))))) (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name FXs))))))))->sum() - ((argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name storage)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])))))))) ))))))) (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name FXs))))))))->sum()) div 2; operation f(n : OclAny) : OclAny pre: true post: true activity: y := 1 ; while n /= 1 do ( if n mod 2 then ( y := y + 1 ) else skip ; n := n div 2) ; return y; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import cmath import heapq import itertools import math import operator import os import re import string import sys from collections import Counter,deque,defaultdict from copy import deepcopy from decimal import Decimal from fractions import gcd from functools import lru_cache,reduce from operator import itemgetter,mul,add,xor import numpy as np if os.getenv("LOCAL"): sys.stdin=open("_in.txt","r") sys.setrecursionlimit(10**9) INF=float("inf") IINF=10**18 MOD=10**9+7 N=int(sys.stdin.buffer.readline()) W=[sys.stdin.buffer.readline().decode().rstrip()for _ in range(N)] ok=len(set(W))==len(W) for s,t in zip(W,W[1 :]): ok &=s[-1]==t[0] if ok : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if os.getenv("LOCAL") then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("_in.txt")) ) else skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (("inf")))->toReal() ; var IINF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; var N : int := ("" + ((sys.stdin.buffer.readLine())))->toInteger() ; var W : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (sys.stdin.buffer.readLine().decode().rstrip())) ; var ok : boolean := (Set{}->union((W)))->size() = (W)->size() ; for _tuple : Integer.subrange(1, W->size())->collect( _indx | Sequence{W->at(_indx), W->tail()->at(_indx)} ) do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); ok := ok & s->last() = t->first()) ; if ok then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): input() return nPairsWithCommonFX(tuple(map(int,input().split()))) def nPairsWithCommonFX(sequence): storage={} FXs=[] for value in sequence : y=f(value) if y not in storage : storage[y]=[value] FXs.append(y) else : storage[y].append(value) return(sum(len(storage[y])*len(storage[y])for y in FXs)-sum(len(storage[y])for y in FXs))//2 memo={128,1,2,256,4,512,1024,2048,8,4096,32768,131072,262144,524288,8192,1048576,16,16384,4194304,32,8388608,16777216,33554432,67108864,134217728,268435456,536870912,64,65536,2097152} def f(n): global memo y=1 while n!=1 : if n % 2 : y+=1 elif n in memo : return y n//=2 return y if __name__=='__main__' : print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute memo : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; var memo : Set := Set{128}->union(Set{1}->union(Set{2}->union(Set{256}->union(Set{4}->union(Set{512}->union(Set{1024}->union(Set{2048}->union(Set{8}->union(Set{4096}->union(Set{32768}->union(Set{131072}->union(Set{262144}->union(Set{524288}->union(Set{8192}->union(Set{1048576}->union(Set{16}->union(Set{16384}->union(Set{4194304}->union(Set{32}->union(Set{8388608}->union(Set{16777216}->union(Set{33554432}->union(Set{67108864}->union(Set{134217728}->union(Set{268435456}->union(Set{536870912}->union(Set{64}->union(Set{65536}->union(Set{ 2097152 }))))))))))))))))))))))))))))) ; skip ; if __name__ = '__main__' then ( execute (main())->display() ) else skip; operation main() : OclAny pre: true post: true activity: input() ; return nPairsWithCommonFX(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))); operation nPairsWithCommonFX(sequence : OclAny) : OclAny pre: true post: true activity: var storage : OclAny := Set{} ; var FXs : Sequence := Sequence{} ; for value : sequence do ( var y : String := f(value) ; if (storage)->excludes(y) then ( storage->at(y) := Sequence{ value } ; execute ((y) : FXs) ) else ( (expr (atom (name storage)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name value)))))))) )))) )) ; return (((argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name storage)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])))))))) )))) * (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name storage)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])))))))) )))))))) (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name FXs))))))))->sum() - ((argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name storage)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])))))))) ))))))) (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name FXs))))))))->sum()) div 2; operation f(n : OclAny) : OclAny pre: true post: true activity: skip ; y := 1 ; while n /= 1 do ( if n mod 2 then ( y := y + 1 ) else (if (memo)->includes(n) then ( return y ) else skip) ; n := n div 2) ; return y; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculate(no): if no &(no-1)==0 : return 1 if no & 1==0 : return calculate(no//2) else : return 1+calculate(no//2) if __name__=="__main__" : n=int(input()) nos=input().split(" ") intarr=[] for no in nos : intarr.append(int(no)) count=dict() for i in intarr : e=calculate(i) if e in count : count[e]+=1 else : count[e]=1 answer=0 for val in count.values(): if val>1 : answer+=val*(val-1)//2 print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nos : OclAny := input().split(" ") ; var intarr : Sequence := Sequence{} ; for no : nos do ( execute ((("" + ((no)))->toInteger()) : intarr)) ; var count : Map := (arguments ( )) ; for i : intarr do ( var e : OclAny := calculate(i) ; if (count)->includes(e) then ( count[e+1] := count[e+1] + 1 ) else ( count[e+1] := 1 )) ; var answer : int := 0 ; for val : count.values() do ( if val > 1 then ( answer := answer + val * (val - 1) div 2 ) else skip) ; execute (answer)->display() ) else skip; operation calculate(no : OclAny) : OclAny pre: true post: true activity: if MathLib.bitwiseAnd(no, (no - 1)) = 0 then ( return 1 ) else skip ; if MathLib.bitwiseAnd(no, 1) = 0 then ( return calculate(no div 2) ) else ( return 1 + calculate(no div 2) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) v={} for i in a : c=0 while(i!=1): if i % 2==0 : i/=2 else : i=(i-1)/2 c+=1 if c in v : v[c]+=1 else : v[c]=1 t=0 for u in v : x=v[u] t+=(x*(x-1))/2 print(int(t)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var v : OclAny := Set{} ; for i : a do ( var c : int := 0 ; while (i /= 1) do ( if i mod 2 = 0 then ( i := i / 2 ) else ( var i : double := (i - 1) / 2 ; c := c + 1 )) ; if (v)->includes(c) then ( v[c+1] := v[c+1] + 1 ) else ( v[c+1] := 1 )) ; var t : int := 0 ; for u : v do ( var x : OclAny := v[u+1] ; t := t + (x * (x - 1)) / 2) ; execute (("" + ((t)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def min_noOf_operation(arr,n,k): res=0 for i in range(1,n): noOfSubtraction=0 if(arr[i]>arr[i-1]): noOfSubtraction=(arr[i]-arr[i-1])/k ; if((arr[i]-arr[i-1])% k!=0): noOfSubtraction+=1 arr[i]=arr[i]-k*noOfSubtraction res=res+noOfSubtraction return int(res) arr=[1,1,2,3] N=len(arr) k=5 print(min_noOf_operation(arr,N,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))) ; var N : int := (arr)->size() ; k := 5 ; execute (min_noOf_operation(arr, N, k))->display(); operation min_noOf_operation(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; for i : Integer.subrange(1, n-1) do ( var noOfSubtraction : int := 0 ; if ((arr[i+1]->compareTo(arr[i - 1+1])) > 0) then ( noOfSubtraction := (arr[i+1] - arr[i - 1+1]) / k; ; if ((arr[i+1] - arr[i - 1+1]) mod k /= 0) then ( noOfSubtraction := noOfSubtraction + 1 ) else skip ; arr[i+1] := arr[i+1] - k * noOfSubtraction ) else skip ; res := res + noOfSubtraction) ; return ("" + ((res)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CountSubSet(arr,n,X): N=2**n ; count=0 ; for i in range(N): for j in range(n): if(i &(1<union(Sequence{5}->union(Sequence{6}->union(Sequence{ 7 }))); ; X := 5; ; n := (arr)->size(); ; execute (CountSubSet(arr, n, X))->display(); ) else skip; operation CountSubSet(arr : OclAny, n : OclAny, X : OclAny) pre: true post: true activity: var N : double := (2)->pow(n); ; var count : int := 0; ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, n-1) do ( if (MathLib.bitwiseAnd(i, (1 * (2->pow(j))))) then ( if (arr[j+1] = X) then ( count := count + 1; ) else skip ) else skip)) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=5 def FindMaxProduct(arr,n): max=0 for i in range(n): for j in range(n): if((j-3)>=0): result=(arr[i][j]*arr[i][j-1]*arr[i][j-2]*arr[i][j-3]) if(max=0): result=(arr[i][j]*arr[i-1][j]*arr[i-2][j]*arr[i-3][j]) if(max=0 and(j-3)>=0): result=(arr[i][j]*arr[i-1][j-1]*arr[i-2][j-2]*arr[i-3][j-3]) if(max=0 and(j-1)<=0): result=(arr[i][j]*arr[i-1][j+1]*arr[i-2][j+2]*arr[i-3][j+3]) if(maxunion(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 }))))}->union(Sequence{Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{ 1 }))))}->union(Sequence{Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))))}->union(Sequence{Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{1}->union(Sequence{ 0 }))))}->union(Sequence{ Sequence{9}->union(Sequence{6}->union(Sequence{4}->union(Sequence{2}->union(Sequence{ 3 })))) })))) ; execute (FindMaxProduct(arr, n))->display() ) else skip; operation FindMaxProduct(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var max : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if ((j - 3) >= 0) then ( var result : double := (arr[i+1][j+1] * arr[i+1][j - 1+1] * arr[i+1][j - 2+1] * arr[i+1][j - 3+1]) ; if ((max->compareTo(result)) < 0) then ( max := result ) else skip ) else skip ; if ((i - 3) >= 0) then ( result := (arr[i+1][j+1] * arr[i - 1+1][j+1] * arr[i - 2+1][j+1] * arr[i - 3+1][j+1]) ; if ((max->compareTo(result)) < 0) then ( max := result ) else skip ) else skip ; if ((i - 3) >= 0 & (j - 3) >= 0) then ( result := (arr[i+1][j+1] * arr[i - 1+1][j - 1+1] * arr[i - 2+1][j - 2+1] * arr[i - 3+1][j - 3+1]) ; if ((max->compareTo(result)) < 0) then ( max := result ) else skip ) else skip ; if ((i - 3) >= 0 & (j - 1) <= 0) then ( result := (arr[i+1][j+1] * arr[i - 1+1][j + 1+1] * arr[i - 2+1][j + 2+1] * arr[i - 3+1][j + 3+1]) ; if ((max->compareTo(result)) < 0) then ( max := result ) else skip ) else skip)) ; return max; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=50002 ; primes=[] def sieve(): isPrime=[True]*(MAX) p=2 while p*p=z): count+=(x//z) z*=y return count def modMult(a,b,mod): res=0 a=a % mod while(b>0): if(b % 2==1): res=(res+a)% mod a=(a*2)% mod b//=2 return res % mod def countWays(n,m): ans=1 for i in range(1,len(primes)): powers=power(n,primes[i]) if(powers==0): break ans=modMult(ans,powers+1,m)% m if(((ans-1)% m)<0): return(ans-1+m)% m else : return(ans-1)% m if __name__=="__main__" : sieve() n=4 m=7 print(countWays(n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 50002; ; var primes : Sequence := Sequence{} ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( sieve() ; n := 4 ; m := 7 ; execute (countWays(n, m))->display() ) else skip; operation sieve() pre: true post: true activity: var isPrime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (MAX)) ; var p : int := 2 ; while (p * p->compareTo(MAX)) < 0 do ( if (isPrime[p+1] = true) then ( for i : Integer.subrange(p * 2, MAX-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( isPrime[i+1] := false) ) else skip ; p := p + 1) ; for p : Integer.subrange(2, MAX-1) do ( if (isPrime[p+1]) then ( execute ((p) : primes) ) else skip); operation power(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var z : OclAny := y ; while ((x->compareTo(z)) >= 0) do ( count := count + (x div z) ; z := z * y) ; return count; operation modMult(a : OclAny, b : OclAny, mod : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; a := a mod mod ; while (b > 0) do ( if (b mod 2 = 1) then ( res := (res + a) mod mod ) else skip ; a := (a * 2) mod mod ; b := b div 2) ; return res mod mod; operation countWays(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var ans : int := 1 ; for i : Integer.subrange(1, (primes)->size()-1) do ( var powers : OclAny := power(n, primes[i+1]) ; if (powers = 0) then ( break ) else skip ; ans := modMult(ans, powers + 1, m) mod m) ; if (((ans - 1) mod m) < 0) then ( return (ans - 1 + m) mod m ) else ( return (ans - 1) mod m ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def smallestIndexsum(arr,n): i=n-1 ; while(i>=0 and arr[i]% 2==1): i-=1 ; sum=0 ; for j in range(0,i+1): sum+=arr[j]; return sum ; if __name__=='__main__' : arr=[2,3,5,6,3,3]; n=len(arr); print(smallestIndexsum(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{6}->union(Sequence{3}->union(Sequence{ 3 }))))); ; n := (arr)->size(); ; execute (smallestIndexsum(arr, n))->display(); ) else skip; operation smallestIndexsum(arr : OclAny, n : OclAny) pre: true post: true activity: var i : double := n - 1; ; while (i >= 0 & arr[i+1] mod 2 = 1) do ( i := i - 1;) ; var sum : int := 0; ; for j : Integer.subrange(0, i + 1-1) do ( sum := sum + arr[j+1];) ; return sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) v=input() d=["LEFT","RIGHT"] f=k-1collect( _x | (OclType["int"])->apply(_x) ) ; var v : String := (OclFile["System.in"]).readLine() ; var d : Sequence := Sequence{"LEFT"}->union(Sequence{ "RIGHT" }) ; var f : boolean := (k - 1->compareTo(n - k)) < 0 ; var m : OclAny := Set{k - 1, n - k}->min() ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( execute ((d->select(not(f))) : a)) ; for i : v(subscript : (sliceop : (test (logical_test (comparison (expr (expr (atom - (number (integer 1)))) + (expr (expr (atom (number (integer 2)))) * (expr (atom (name f)))))))))) do ( execute (("PRINT " + i) : a) ; execute ((d[f+1]) : a)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys inp=sys.argv[1] outp="%s.out" % inp.split(".")[0] from itertools import product,combinations def unhappiness(tenants): res=0 for c in combinations(tenants,2): t1=c[0] t2=c[1] dx=abs(t1[0]-t2[0]) dy=abs(t1[1]-t2[1]) if dx==0 and dy==1 : res+=1 if dx==1 and dy==0 : res+=1 return res def solve(r,c,n): return min([unhappiness(t)for t in combinations(product(range(r),range(c)),n)]) with open(inp,'r')as f,open(outp,'w')as out : cases=int(f.readline()) for c in range(cases): r,cc,n=tuple([int(x)for x in f.readline()[:-1].split(" ")]) out.write("Case #%s: %s\n" %(c+1,solve(r,cc,n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var inp : (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) := (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) ; var outp : String := StringLib.format("%s.out",inp.split(".")->first()) ; skip ; skip ; skip ; try (var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(inp)); var out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(outp)); var cases : int := ("" + ((f.readLine())))->toInteger() ; for c : Integer.subrange(0, cases-1) do ( var cc : OclAny := null; Sequence{r,cc,n} := (f.readLine()->front().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) ; out.write(StringLib.format("Case #%s: %s\n",Sequence{c + 1, solve(r, cc, n)})))) catch (_e : OclException) do skip; operation unhappiness(tenants : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; for c : combinations(tenants, 2) do ( var t1 : OclAny := c->first() ; var t2 : OclAny := c[1+1] ; var dx : double := (t1->first() - t2->first())->abs() ; var dy : double := (t1[1+1] - t2[1+1])->abs() ; if dx = 0 & dy = 1 then ( res := res + 1 ) else skip ; if dx = 1 & dy = 0 then ( res := res + 1 ) else skip) ; return res; operation solve(r : OclAny, c : OclAny, n : OclAny) : OclAny pre: true post: true activity: return (combinations(product(Integer.subrange(0, r-1), Integer.subrange(0, c-1)), n)->select(t | true)->collect(t | (unhappiness(t))))->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() def main(): ed=[] for i in range(int(a)): neww=input() if i!=0 : if ed[i-1][-1]!=neww[0]or neww in ed : return 'No' ed.append(neww) return 'Yes' if __name__=='__main__' : print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; skip ; if __name__ = '__main__' then ( execute (main())->display() ) else skip; operation main() : OclAny pre: true post: true activity: var ed : Sequence := Sequence{} ; for i : Integer.subrange(0, ("" + ((a)))->toInteger()-1) do ( var neww : String := (OclFile["System.in"]).readLine() ; if i /= 0 then ( if ed[i - 1+1]->last() /= neww->first() or (ed)->includes(neww) then ( return 'No' ) else skip ) else skip ; execute ((neww) : ed)) ; return 'Yes'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys infile=None outfile=None def readline(): x=infile.readline() if len(x)>0 and x[-1]=='\n' : return x[:-1] else : return x def readint(): return int(readline()) def readfloat(): return float(readline()) def readints(): return[int(x)for x in readline().split()] def readfloats(): return[float(x)for x in readline().split()] def writeline(x): outfile.write(x+'\n') def writecase(casenum,answer): outfile.write('Case #{:d}:{}\n'.format(casenum,answer)) def run(main): global infile,outfile args=sys.argv infile=sys.stdin outfile=sys.stdout if len(args)==2 : if args[1]!='-' : infile=open(args[1],'r') if args[1].endswith('.in'): outfile=open(args[1][:-3]+'.out','w') elif len(args)==3 : if args[1]!='-' : infile=open(args[1],'r') if args[2]!='-' : outfile=open(args[2],'w') elif len(args)>3 : print("Expected 0,1,or 2 arguments,not{}".format(len(args)-1)) print(args) return t=readint() for casenum in range(1,t+1): main(casenum) if infile is not sys.stdin : infile.close() if outfile is not sys.stdout : outfile.close() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute infile : OclAny; attribute outfile : OclAny; operation initialise() pre: true post: true activity: skip ; var infile : OclAny := null ; var outfile : OclAny := null ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip; operation readline() : OclAny pre: true post: true activity: var x : String := infile.readLine() ; if (x)->size() > 0 & x->last() = ' ' then ( return x->front() ) else ( return x ); operation readint() : OclAny pre: true post: true activity: return ("" + ((readline())))->toInteger(); operation readfloat() : OclAny pre: true post: true activity: return ("" + ((readline())))->toReal(); operation readints() : OclAny pre: true post: true activity: return readline().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation readfloats() : OclAny pre: true post: true activity: return readline().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation writeline(x : OclAny) pre: true post: true activity: outfile.write(x + ' '); operation writecase(casenum : OclAny, answer : OclAny) pre: true post: true activity: outfile.write(StringLib.interpolateStrings('Case #{:d}:{} ', Sequence{casenum, answer})); operation run(main : OclAny) pre: true post: true activity: skip; skip ; var args : (trailer . (name argv)) := (trailer . (name argv)) ; infile := OclFile["System.in"] ; outfile := OclFile["System.out"] ; if (args)->size() = 2 then ( if args[1+1] /= '-' then ( infile := OclFile.newOclFile_Write(OclFile.newOclFile(args[1+1])) ; if args[1+1]->hasSuffix('.in') then ( outfile := OclFile.newOclFile_Write(OclFile.newOclFile(args[1+1].subrange(1,-3) + '.out')) ) else skip ) else skip ) else (if (args)->size() = 3 then ( if args[1+1] /= '-' then ( infile := OclFile.newOclFile_Write(OclFile.newOclFile(args[1+1])) ) else skip ; if args[2+1] /= '-' then ( outfile := OclFile.newOclFile_Write(OclFile.newOclFile(args[2+1])) ) else skip ) else (if (args)->size() > 3 then ( execute (StringLib.interpolateStrings("Expected 0,1,or 2 arguments,not{}", Sequence{(args)->size() - 1}))->display() ; execute (args)->display() ; return ) else skip ) ) ; var t : OclAny := readint() ; for casenum : Integer.subrange(1, t + 1-1) do ( main(casenum)) ; if not(infile <>= OclFile["System.in"]) then ( infile.closeFile() ) else skip ; if not(outfile <>= OclFile["System.out"]) then ( outfile.closeFile() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(R,C,N): z=N-(R*C+1)//2 if z<=0 : return 0 y=0 if R==1 or C==1 : if R*C % 2==0 : y+=1 z-=1 y+=2*z return y if R*C % 2==0 : dz=min(z,2) y+=2*dz z-=dz dz=min(z,R+C-4) y+=3*dz z-=dz y+=4*z return y if z==1 : return 3 z+=1 dz=min(z,4) y+=2*dz z-=dz dz=min(z,R+C-6) y+=3*dz z-=dz y+=4*z return y for x in range(1,int(input())+1): y=solve(*map(int,input().split())) print('Case #'+str(x)+':',y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for x : Integer.subrange(1, ("" + (((OclFile["System.in"]).readLine())))->toInteger() + 1-1) do ( y := solve((argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ; execute ('Case #' + ("" + ((x))) + ':')->display()); operation solve(R : OclAny, C : OclAny, N : OclAny) : OclAny pre: true post: true activity: var z : double := N - (R * C + 1) div 2 ; if z <= 0 then ( return 0 ) else skip ; var y : int := 0 ; if R = 1 or C = 1 then ( if R * C mod 2 = 0 then ( y := y + 1 ; z := z - 1 ) else skip ; y := y + 2 * z ; return y ) else skip ; if R * C mod 2 = 0 then ( var dz : OclAny := Set{z, 2}->min() ; y := y + 2 * dz ; z := z - dz ; dz := Set{z, R + C - 4}->min() ; y := y + 3 * dz ; z := z - dz ; y := y + 4 * z ; return y ) else skip ; if z = 1 then ( return 3 ) else skip ; z := z + 1 ; dz := Set{z, 4}->min() ; y := y + 2 * dz ; z := z - dz ; dz := Set{z, R + C - 6}->min() ; y := y + 3 * dz ; z := z - dz ; y := y + 4 * z ; return y; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import* inf=open('B-large.in') ouf=open('B-large.out','w') input=lambda : inf.readline().strip() print=partial(print,file=ouf) def solve(): r,c,n=map(int,input().split()) if r>c : r,c=c,r if n<=(r*c)//2+(r*c)% 2 : print(0) return free=r*c-n cur=(r-1)*c+(c-1)*r if r==1 : if c % 2==0 : ways=[[2]*(c//2-1)+[1]] else : ways=[[2]*(c//2),[2]*(c//2-1)+[1,1]] elif r*c % 2==0 : ways=[[4]*((r-2)*(c-2)//2)+[3]*(r-2+c-2)+[2,2]] else : ways=[[4]*((r-2)*(c-2)//2+1)+[3]*(r-3+c-3)+[2]*4,[4]*((r-2)*(c-2)//2)+[3]*(r-1+c-1),] print(cur-max(sum(way[: free])for way in ways)) tests=int(input()) for z in range(tests): print("Case #{}: ".format(z+1),end='') solve() ouf.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var Math_PINFINITY : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('B-large.in')) ; var ouf : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('B-large.out')) ; var input : Function := lambda $$ : OclAny in (Math_PINFINITY.readLine()->trim()) ; var print : OclAny := partial(print, (argument (test (logical_test (comparison (expr (atom (name file)))))) = (test (logical_test (comparison (expr (atom (name ouf)))))))) ; skip ; var tests : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for z : Integer.subrange(0, tests-1) do ( execute (StringLib.interpolateStrings("Case #{}: ", Sequence{z + 1}))->display() ; solve()) ; ouf.closeFile(); operation solve() pre: true post: true activity: var r : OclAny := null; var c : OclAny := null; var n : OclAny := null; Sequence{r,c,n} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (r->compareTo(c)) > 0 then ( var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := Sequence{c,r} ) else skip ; if (n->compareTo((r * c) div 2 + (r * c) mod 2)) <= 0 then ( execute (0)->display() ; return ) else skip ; var free : double := r * c - n ; var cur : double := (r - 1) * c + (c - 1) * r ; if r = 1 then ( if c mod 2 = 0 then ( var ways : Sequence := Sequence{ MatrixLib.elementwiseMult(Sequence{ 2 }, (c div 2 - 1))->union(Sequence{ 1 }) } ) else ( ways := Sequence{MatrixLib.elementwiseMult(Sequence{ 2 }, (c div 2))}->union(Sequence{ MatrixLib.elementwiseMult(Sequence{ 2 }, (c div 2 - 1))->union(Sequence{1}->union(Sequence{ 1 })) }) ) ) else (if r * c mod 2 = 0 then ( ways := Sequence{ MatrixLib.elementwiseMult(Sequence{ 4 }, ((r - 2) * (c - 2) div 2))->union(MatrixLib.elementwiseMult(Sequence{ 3 }, (r - 2 + c - 2)))->union(Sequence{2}->union(Sequence{ 2 })) } ) else ( ways := Sequence{MatrixLib.elementwiseMult(Sequence{ 4 }, ((r - 2) * (c - 2) div 2 + 1))->union(MatrixLib.elementwiseMult(Sequence{ 3 }, (r - 3 + c - 3)))->union(MatrixLib.elementwiseMult(Sequence{ 2 }, 4))}->union(Sequence{ MatrixLib.elementwiseMult(Sequence{ 4 }, ((r - 2) * (c - 2) div 2))->union(MatrixLib.elementwiseMult(Sequence{ 3 }, (r - 1 + c - 1))) }) ) ) ; execute (cur - ((argument (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name way)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name free)))))))) ])))))))) ))))))) (comp_for for (exprlist (expr (atom (name way)))) in (logical_test (comparison (expr (atom (name ways))))))))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def debug(*args): print(*args,file=sys.stderr) def permutations(n,k): if k==0 : yield[False]*n return for p in permutations(n-1,k-1): yield p+[True] if n>k : for p in permutations(n-1,k): yield p+[False] def cost(p,r,c): result=0 for i in range(r): for j in range(c-1): if p[i*c+j]and p[i*c+j+1]: result+=1 for i in range(r-1): for j in range(c): if p[i*c+j]and p[i*c+j+c]: result+=1 return result fin=sys.stdin T=int(fin.readline()) for case in range(1,T+1): R,C,N=map(int,fin.readline().split()) best=R*C*10 for p in permutations(R*C,N): best=min(best,cost(p,R,C)) result=best print("Case #%d: %s" %(case,result)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var fin : OclFile := OclFile["System.in"] ; var T : int := ("" + ((fin.readLine())))->toInteger() ; for case : Integer.subrange(1, T + 1-1) do ( var R : OclAny := null; var C : OclAny := null; var N : OclAny := null; Sequence{R,C,N} := (fin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var best : double := R * C * 10 ; for p : permutations(R * C, N) do ( best := Set{best, cost(p, R, C)}->min()) ; result := best ; execute (StringLib.format("Case #%d: %s",Sequence{case, result}))->display()); operation debug(args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) execute ((argument * (test (logical_test (comparison (expr (atom (name args))))))))->display(); operation permutations(n : OclAny, k : OclAny) pre: true post: true activity: if k = 0 then ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return MatrixLib.elementwiseMult(Sequence{ false }, n) ; return ) else skip ; for p : permutations(n - 1, k - 1) do ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return p->union(Sequence{ true })) ; if (n->compareTo(k)) > 0 then ( for p : permutations(n - 1, k) do ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return p->union(Sequence{ false })) ) else skip; operation cost(p : OclAny, r : OclAny, c : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; for i : Integer.subrange(0, r-1) do ( for j : Integer.subrange(0, c - 1-1) do ( if p[i * c + j+1] & p[i * c + j + 1+1] then ( result := result + 1 ) else skip)) ; for i : Integer.subrange(0, r - 1-1) do ( for j : Integer.subrange(0, c-1) do ( if p[i * c + j+1] & p[i * c + j + c+1] then ( result := result + 1 ) else skip)) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- y1,m1,d1=input().split(":") y2,m2,d2=input().split(":") from datetime import* date1=datetime(year=int(y1),month=int(m1),day=int(d1)) date2=datetime(year=int(y2),month=int(m2),day=int(d2)) res=date2-date1 print(abs(res.days)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var y1 : OclAny := null; var m1 : OclAny := null; var d1 : OclAny := null; Sequence{y1,m1,d1} := input().split(":") ; var y2 : OclAny := null; var m2 : OclAny := null; var d2 : OclAny := null; Sequence{y2,m2,d2} := input().split(":") ; skip ; var date1 : OclAny := ; var date2 : OclAny := ; var res : double := date2 - date1 ; execute ((res.days)->abs())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from datetime import date as d ; print(abs((d(*map(int,input().split(':')))-d(*map(int,input().split(':')))).days)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; execute (((d((argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ':'))))))) ))))))))) ))))))))) - d((argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ':'))))))) ))))))))) )))))))))).days)->abs())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- months=[0,31,28,31,30,31,30,31,31,30,31,30,31] def is_v(y): if y==1900 : return 0 if y % 4==0 : return 1 return 0 def days_from_begin(n): n=n.split(':') y=int(n[0]) m=int(n[1]) d=int(n[2]) days=0 for i in range(1900,y): days+=365+is_v(i) res=days for i in range(1,m): days+=months[i] if(is_v(y)and i==2): days+=1 return days+d n=input() f=days_from_begin(n) n=input() s=days_from_begin(n) print(abs(s-f)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var months : Sequence := Sequence{0}->union(Sequence{31}->union(Sequence{28}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{ 31 })))))))))))) ; skip ; skip ; n := (OclFile["System.in"]).readLine() ; var f : OclAny := days_from_begin(n) ; n := (OclFile["System.in"]).readLine() ; var s : OclAny := days_from_begin(n) ; execute ((s - f)->abs())->display(); operation is_v(y : OclAny) : OclAny pre: true post: true activity: if y = 1900 then ( return 0 ) else skip ; if y mod 4 = 0 then ( return 1 ) else skip ; return 0; operation days_from_begin(n : OclAny) : OclAny pre: true post: true activity: n := n.split(':') ; y := ("" + ((n->first())))->toInteger() ; var m : int := ("" + ((n[1+1])))->toInteger() ; var d : int := ("" + ((n[2+1])))->toInteger() ; var days : int := 0 ; for i : Integer.subrange(1900, y-1) do ( days := days + 365 + is_v(i)) ; var res : int := days ; for i : Integer.subrange(1, m-1) do ( days := days + months[i+1] ; if (is_v(y) & i = 2) then ( days := days + 1 ) else skip) ; return days + d; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import datetime t1=datetime.datetime.strptime(input(),"%Y:%m:%d") t2=datetime.datetime.strptime(input(),"%Y:%m:%d") print(abs((t2-t1).days)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t1 : OclAny := datetime.datetime.strptime((OclFile["System.in"]).readLine(), "%Y:%m:%d") ; var t2 : OclAny := datetime.datetime.strptime((OclFile["System.in"]).readLine(), "%Y:%m:%d") ; execute (((t2 - t1).days)->abs())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() totalQ=S.count("Q") CQ=0 CQAQ=0 for i in S : if i=="Q" : CQ+=1 elif i=="A" : CQAQ+=CQ*(totalQ-CQ) print(CQAQ) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var totalQ : int := S->count("Q") ; var CQ : int := 0 ; var CQAQ : int := 0 ; for i : S->characters() do ( if i = "Q" then ( CQ := CQ + 1 ) else (if i = "A" then ( CQAQ := CQAQ + CQ * (totalQ - CQ) ) else skip)) ; execute (CQAQ)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a,b,c,t='LEFT\n','RIGHT\n','PRINT ',input() if 2*k>n : k,a,b,t=n-k+1,b,a,t[: :-1] print(a*(k-1)+c+('\n'+b+c).join(t)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var t : OclAny := null; Sequence{a,b,c,t} := Sequence{'LEFT ','RIGHT ','PRINT ',(OclFile["System.in"]).readLine()} ; if (2 * k->compareTo(n)) > 0 then ( var k : OclAny := null; var a : OclAny := null; var b : OclAny := null; var t : OclAny := null; Sequence{k,a,b,t} := Sequence{n - k + 1,b,a,t(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))} ) else skip ; execute (a * (k - 1) + c + StringLib.sumStringsWithSeparator((t), (' ' + b + c)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict n=int(input()) s=defaultdict(lambda : 0) l=list([input()for i in range(n)]) f='Yes' i=-1 for v in l : s[v]+=1 if s[v]>=2 : f='No' if i!=-1 and l[i][-1]!=v[0]: f='No' i+=1 print(f) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; var l : Sequence := (Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine()))) ; var f : String := 'Yes' ; var i : int := -1 ; for v : l do ( s[v+1] := s[v+1] + 1 ; if s[v+1] >= 2 then ( f := 'No' ) else skip ; if i /= -1 & l[i+1]->last() /= v->first() then ( f := 'No' ) else skip ; i := i + 1) ; execute (f)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import combinations n=input() n_m=[] for x in n : if x=="Q" or x=="A" : n_m.append(x) a=list(combinations(n_m,3)) b=[] for x in a : if x[0]=="Q" and x[1]=="A" and x[2]=="Q" : b.append(x) print(len(b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : String := (OclFile["System.in"]).readLine() ; var n_m : Sequence := Sequence{} ; for x : n->characters() do ( if x = "Q" or x = "A" then ( execute ((x) : n_m) ) else skip) ; var a : Sequence := (combinations(n_m, 3)) ; var b : Sequence := Sequence{} ; for x : a do ( if x->first() = "Q" & x[1+1] = "A" & x[2+1] = "Q" then ( execute ((x) : b) ) else skip) ; execute ((b)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from typing import List,Tuple from collections import defaultdict,deque,namedtuple from heapq import heappush as push,heappop as pop import sys INF=(int)(1e9+7) sys.setrecursionlimit(INF) def su(s): n=len(s) cnt=0 for i in range(0,n-2): for j in range(i+1,n-1): for k in range(j+1,n): if s[i]=="Q" and s[j]=="A" and s[k]=="Q" : cnt+=1 return cnt if __name__=="__main__" : s=input() print(su(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var INF : OclAny := (OclType["int"])(("1e9")->toReal() + 7) ; sys.setrecursionlimit(INF) ; skip ; if __name__ = "__main__" then ( s := (OclFile["System.in"]).readLine() ; execute (su(s))->display() ) else skip; operation su(s : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; var cnt : int := 0 ; for i : Integer.subrange(0, n - 2-1) do ( for j : Integer.subrange(i + 1, n - 1-1) do ( for k : Integer.subrange(j + 1, n-1) do ( if s[i+1] = "Q" & s[j+1] = "A" & s[k+1] = "Q" then ( cnt := cnt + 1 ) else skip))) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from typing import List,Tuple from collections import defaultdict,deque,namedtuple from heapq import heappush as push,heappop as pop import sys INF=(int)(1e9+7) sys.setrecursionlimit(INF) def su(s): n=len(s) cnt=0 for i in range(0,n-2): for j in range(i+1,n-1): for k in range(j+1,n): if s[i]=="Q" and s[j]=="A" and s[k]=="Q" : cnt+=1 return cnt def test(s): n=len(s) left=[0]*n right=[0]*n if s[0]=='Q' : left[0]=1 for i in range(1,n,1): if s[i]=='Q' : left[i]=left[i-1]+1 continue left[i]=left[i-1] if s[n-1]=='Q' : right[n-1]=1 for i in range(n-2,-1,-1): if s[i]=='Q' : right[i]=right[i+1]+1 continue right[i]=right[i+1] res=0 for i in range(n): if s[i]=='A' : res+=left[i]*right[i] return res if __name__=="__main__" : s=input() print(test(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var INF : OclAny := (OclType["int"])(("1e9")->toReal() + 7) ; sys.setrecursionlimit(INF) ; skip ; skip ; if __name__ = "__main__" then ( s := (OclFile["System.in"]).readLine() ; execute (test(s))->display() ) else skip; operation su(s : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; var cnt : int := 0 ; for i : Integer.subrange(0, n - 2-1) do ( for j : Integer.subrange(i + 1, n - 1-1) do ( for k : Integer.subrange(j + 1, n-1) do ( if s[i+1] = "Q" & s[j+1] = "A" & s[k+1] = "Q" then ( cnt := cnt + 1 ) else skip))) ; return cnt; operation test(s : OclAny) : OclAny pre: true post: true activity: n := (s)->size() ; var left : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var right : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; if s->first() = 'Q' then ( left->first() := 1 ) else skip ; for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if s[i+1] = 'Q' then ( left[i+1] := left[i - 1+1] + 1 ; continue ) else skip ; left[i+1] := left[i - 1+1]) ; if s[n - 1+1] = 'Q' then ( right[n - 1+1] := 1 ) else skip ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( if s[i+1] = 'Q' then ( right[i+1] := right[i + 1+1] + 1 ; continue ) else skip ; right[i+1] := right[i + 1+1]) ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = 'A' then ( res := res + left[i+1] * right[i+1] ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,A,B=map(int,input().split()) ans=N//(A+B)*A rem=N %(A+B) ans+=min(rem,A) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{N,A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : double := N div (A + B) * A ; var rem : int := N mod (A + B) ; ans := ans + Set{rem, A}->min() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input().split() N,A,B=int(s[0]),int(s[1]),int(s[2]) def calc_rst(N,L): if int(N % L)>A : return A else : return int(N % L) def solve(N,A,B,L=A+B): return(int(N/L)*A)+calc_rst(N,L) print(solve(N,A,B)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := input().split() ; var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{N,A,B} := Sequence{("" + ((s->first())))->toInteger(),("" + ((s[1+1])))->toInteger(),("" + ((s[2+1])))->toInteger()} ; skip ; skip ; execute (solve(N, A, B))->display(); operation calc_rst(N : OclAny, L : OclAny) : OclAny pre: true post: true activity: if (("" + ((N mod L)))->toInteger()->compareTo(A)) > 0 then ( return A ) else ( return ("" + ((N mod L)))->toInteger() ); operation solve(N : OclAny, A : OclAny, B : OclAny, L : OclAny) : OclAny pre: true post: true activity: if L->oclIsUndefined() then L := A + B else skip; return (("" + ((N / L)))->toInteger() * A) + calc_rst(N, L); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a=list(map(int,input().split())) N=a[0] A=a[1] B=a[2] if N %(A+B)!=0 : repTimes=math.floor(N//(A+B)) bB=repTimes*A if N %(A+B)>A : extra=A else : extra=N %(A+B) bB+=extra else : repTimes=math.floor(N//(A+B)) bB=repTimes*A print(bB) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var N : OclAny := a->first() ; var A : OclAny := a[1+1] ; var B : OclAny := a[2+1] ; if N mod (A + B) /= 0 then ( var repTimes : double := (N div (A + B))->floor() ; var bB : double := repTimes * A ; if (N mod (A + B)->compareTo(A)) > 0 then ( var extra : OclAny := A ) else ( extra := N mod (A + B) ) ; bB := bB + extra ) else ( repTimes := (N div (A + B))->floor() ; bB := repTimes * A ) ; execute (bB)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def I(): return int(input()) def MI(): return map(int,input().split()) def LI(): return list(map(int,input().split())) def main(): mod=10**9+7 N,A,B=MI() ans=0 rep=N//(A+B) ans+=rep*A res=N-rep*(A+B) ans+=min(res,A) print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; main(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation main() pre: true post: true activity: var mod : double := (10)->pow(9) + 7 ; var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{N,A,B} := MI() ; var ans : int := 0 ; var rep : int := N div (A + B) ; ans := ans + rep * A ; var res : double := N - rep * (A + B) ; ans := ans + Set{res, A}->min() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import itertools import statistics n,a,b=list(map(int,input().split())) if n %(a+b)<=a : c=n %(a+b) else : c=a print(n//(a+b)*a+c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (n mod (a + b)->compareTo(a)) <= 0 then ( var c : int := n mod (a + b) ) else ( c := a ) ; execute (n div (a + b) * a + c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input_methods=['clipboard','file','key'] using_method=0 input_method=input_methods[using_method] tin=lambda : map(int,input().split()) lin=lambda : list(tin()) mod=1000000007 def main(): n,k=tin() al=lin() al.sort(reverse=True) ss=sum(al) arrive=[0]*k arrive[0]=1 useful_set=set() for v in al : ss-=v u_max=0 if v>=k : useful_set.add(v) continue for i,_ in enumerate(arrive): p=k-i-1 is_on=arrive[p] if is_on==1 and p+v>=k : useful_set.add(v) u_max=k elif is_on==1 : arrive[p+v]=1 u_max=max(u_max,p+v) if u_max+ss>=k : useful_set.add(v) ret=0 for v in al : if v not in useful_set : ret+=1 return ret isTest=False def pa(v): if isTest : print(v) def input_clipboard(): import clipboard input_text=clipboard.get() input_l=input_text.splitlines() for l in input_l : yield l if __name__=="__main__" : if sys.platform=='ios' : if input_method==input_methods[0]: ic=input_clipboard() input=lambda : ic.__next__() elif input_method==input_methods[1]: sys.stdin=open('inputFile.txt') else : pass isTest=True else : pass ret=main() if ret is not None : print(ret) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input_methods : Sequence := Sequence{'clipboard'}->union(Sequence{'file'}->union(Sequence{ 'key' })) ; var using_method : int := 0 ; var input_method : OclAny := input_methods[using_method+1] ; var tin : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lin : Function := lambda $$ : OclAny in ((tin->apply())) ; var mod : int := 1000000007 ; skip ; var isTest : boolean := false ; skip ; skip ; if __name__ = "__main__" then ( if OclProcess.getEnvironmentProperty("OS") = 'ios' then ( if input_method = input_methods->first() then ( var ic : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.input_clipboard(_i)) ; var input : Function := lambda $$ : OclAny in (ic.__next__()) ) else (if input_method = input_methods[1+1] then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('inputFile.txt')) ) else ( skip ) ) ; isTest := true ) else ( skip ) ; ret := main() ; if not(ret <>= null) then ( execute (ret)->display() ) else skip ) else skip; operation main() : OclAny pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := tin->apply() ; var al : OclAny := lin->apply() ; al := al->sort() ; var ss : OclAny := (al)->sum() ; var arrive : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, k) ; arrive->first() := 1 ; var useful_set : Set := Set{}->union(()) ; for v : al do ( ss := ss - v ; var u_max : int := 0 ; if (v->compareTo(k)) >= 0 then ( execute ((v) : useful_set) ; continue ) else skip ; for _tuple : Integer.subrange(1, (arrive)->size())->collect( _indx | Sequence{_indx-1, (arrive)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var _anon : OclAny := _tuple->at(_indx); var p : double := k - i - 1 ; var is_on : OclAny := arrive[p+1] ; if is_on = 1 & (p + v->compareTo(k)) >= 0 then ( execute ((v) : useful_set) ; u_max := k ) else (if is_on = 1 then ( arrive[p + v+1] := 1 ; u_max := Set{u_max, p + v}->max() ) else skip)) ; if (u_max + ss->compareTo(k)) >= 0 then ( execute ((v) : useful_set) ) else skip) ; var ret : int := 0 ; for v : al do ( if (useful_set)->excludes(v) then ( ret := ret + 1 ) else skip) ; return ret; operation pa(v : OclAny) pre: true post: true activity: if isTest then ( execute (v)->display() ) else skip; operation input_clipboard(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; skip ; var input_text : OclAny := clipboard.get() ; var input_l : OclAny := input_text.splitlines() ; for l : input_l do ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return l); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools def fff(x): dp=[0]*k dp[0]=1 for u in itertools.chain(a[: x],a[x+1 :]): h=dp[:] for i in range(u,k): h[i]=h[i]| dp[i-u] dp=h cnt=0 for i in range(max(0,k-a[x]),k): cnt+=dp[i] if cnt==0 : return True else : return False n,k=map(int,input().split()) a=list(map(int,input().split())) a.sort() low=0 high=n-1 while high-low>1 : mid=(high+low)//2 if fff(mid): low=mid else : high=mid if fff(high): print(high+1) elif fff(low): print(low+1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var low : int := 0 ; var high : double := n - 1 ; while high - low > 1 do ( var mid : int := (high + low) div 2 ; if fff(mid) then ( low := mid ) else ( high := mid )) ; if fff(high) then ( execute (high + 1)->display() ) else (if fff(low) then ( execute (low + 1)->display() ) else ( execute (0)->display() ) ) ; operation fff(x : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, k) ; dp->first() := 1 ; for u : itertools.chain(a.subrange(1,x), a.subrange(x + 1+1)) do ( var h : Sequence := dp ; for i : Integer.subrange(u, k-1) do ( h[i+1] := MathLib.bitwiseOr(h[i+1], dp[i - u+1])) ; dp := h) ; var cnt : int := 0 ; for i : Integer.subrange(Set{0, k - a[x+1]}->max(), k-1) do ( cnt := cnt + dp[i+1]) ; if cnt = 0 then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline N=int(input()) W=[None]*N for i in range(N): W[i]=input().rstrip() if not len(W)==len(list(set(W))): print('No') else : shiritoreteru=True for i in range(N-1): if not W[i][-1]==W[i+1][0]: shiritoreteru=False break if shiritoreteru : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var W : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, N) ; for i : Integer.subrange(0, N-1) do ( W[i+1] := input().rstrip()) ; if not((W)->size() = ((Set{}->union((W))))->size()) then ( execute ('No')->display() ) else ( var shiritoreteru : boolean := true ; for i : Integer.subrange(0, N - 1-1) do ( if not(W[i+1]->last() = W[i + 1+1]->first()) then ( shiritoreteru := false ; break ) else skip) ; if shiritoreteru then ( execute ('Yes')->display() ) else ( execute ('No')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) s=input() a=[] for letter in s : a.append(letter) if k>n/2 : for _ in range(n-k): print('RIGHT') a=a[: :-1] for i in range(n-1): print(f'PRINT{a[i]}') print('LEFT') print(f'PRINT{a[-1]}') else : for _ in range(k-1): print('LEFT') for i in range(n-1): print(f'PRINT{a[i]}') print('RIGHT') print(f'PRINT{a[-1]}') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var a : Sequence := Sequence{} ; for letter : s->characters() do ( execute ((letter) : a)) ; if (k->compareTo(n / 2)) > 0 then ( for _anon : Integer.subrange(0, n - k-1) do ( execute ('RIGHT')->display()) ; a := a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; for i : Integer.subrange(0, n - 1-1) do ( execute (StringLib.formattedString('PRINT{a[i]}'))->display() ; execute ('LEFT')->display()) ; execute (StringLib.formattedString('PRINT{a[-1]}'))->display() ) else ( for _anon : Integer.subrange(0, k - 1-1) do ( execute ('LEFT')->display()) ; for i : Integer.subrange(0, n - 1-1) do ( execute (StringLib.formattedString('PRINT{a[i]}'))->display() ; execute ('RIGHT')->display()) ; execute (StringLib.formattedString('PRINT{a[-1]}'))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def biser(lst,func): n=len(lst) nh=n//2 if n==1 : if func(lst[0]): return lst[0] else : return-1 if func(lst[nh]): return biser(lst[nh :],func) else : return biser(lst[: nh],func) def mkns(a,s,m): if a==0 : return s else : return(((s+1)<=K : return False for j in range(i+1,N): if a[j]>=K : break ss[i]=(((ss[i]+1)<=K : break ss[i+1]=(((ss[i]+1)<size() ; var nh : int := n div 2 ; if n = 1 then ( if func(lst->first()) then ( return lst->first() ) else ( return -1 ) ) else skip ; if func(lst[nh+1]) then ( return biser(lst.subrange(nh+1), func) ) else ( return biser(lst.subrange(1,nh), func) ); operation mkns(a : OclAny, s : OclAny, m : OclAny) : OclAny pre: true post: true activity: if a = 0 then ( return s ) else ( return MathLib.bitwiseAnd((MathLib.bitwiseOr(((s + 1) * (2->pow(a))), s)), m) ); operation main() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var ss : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; var pm : double := (1 * (2->pow(K))) - 1 ; var mask : Function := lambda c : OclAny in ((1 * (2->pow(K))) - (1 * (2->pow(c)))) ; var nn : int := 0 ; skip ; for i : Integer.subrange(0, N-1) do ( if (a[i+1]->compareTo(K)) >= 0 then ( break ) else skip ; ss[i + 1+1] := MathLib.bitwiseAnd((MathLib.bitwiseOr(((ss[i+1] + 1) * (2->pow(a[i+1]))), ss[i+1])), pm)) ; nn := biser((Integer.subrange(0, N-1)), isunnec) + 1 ; execute (nn)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from heapq import heappush,heappop import sys import math import bisect import random def LI(): return[int(x)for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return[list(x)for x in sys.stdin.readline().split()] def S(): return list(sys.stdin.readline())[:-1] def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] sys.setrecursionlimit(1000000) mod=1000000007 n,k=LI() a=LI() a.sort() a=a[: bisect.bisect_left(a,k)] n=len(a) a=a[: :-1] l=-1 r=n while r-l>1 : m=(l+r)//2 k_=k-a[m] dp=[0]*k dp[0]=1 ma=0 for i in range(n): if i==m : continue ai=a[i] for j in range(min(ma+1,k-ai))[: :-1]: j_=j+ai if dp[j]: if k_<=j_ : l=m break dp[j_]=1 if j_>ma : ma=j_ else : continue break else : r=m print(n-r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1000000) ; var mod : int := 1000000007 ; var k : OclAny := null; Sequence{n,k} := LI() ; var a : OclAny := LI() ; a := a->sort() ; a := a.subrange(1,bisect.bisect_left(a, k)) ; n := (a)->size() ; a := a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var l : int := -1 ; var r : OclAny := n ; while r - l > 1 do ( var m : int := (l + r) div 2 ; var k_ : double := k - a[m+1] ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, k) ; dp->first() := 1 ; var ma : int := 0 ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name i)))) == (comparison (expr (atom (name m))))))) : (suite (simple_stmt (small_stmt continue))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ai)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name ma))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name k))) - (expr (atom (name ai))))))))) ))))))))) ))) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name j_)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (name ai))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name k_)))) <= (comparison (expr (atom (name j_))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name m)))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j_)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name j_)))) > (comparison (expr (atom (name ma))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ma)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name j_))))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt continue))))))) (stmt (simple_stmt (small_stmt break)))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name r)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name m)))))))))))))))) ; execute (n - r)->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | ((x))); operation S() : OclAny pre: true post: true activity: return OclType["Sequence"]((OclFile["System.in"]).readLine())->front(); operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=list(map(int,input().split(" "))) A=sorted(list(map(int,input().split(" "))),reverse=True) result=0 S=sum(A) n=len(A) s=0 if S=K : result=n-i-1 else : s+=A[i] print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var A : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var result : int := 0 ; var S : OclAny := (A)->sum() ; var n : int := (A)->size() ; var s : int := 0 ; if (S->compareTo(K)) < 0 then ( result := n ) else (if S = K then ( result := 0 ) else ( for i : Integer.subrange(0, n-1) do ( if (s + A[i+1]->compareTo(K)) >= 0 then ( result := n - i - 1 ) else ( s := s + A[i+1] )) ) ) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,s=map(int,input().split()) m=s//n if s % n==0 : print(m) else : print(m+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : int := s div n ; if s mod n = 0 then ( execute (m)->display() ) else ( execute (m + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) if b % a==0 : print(b//a) else : print((b//a)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if b mod a = 0 then ( execute (b div a)->display() ) else ( execute ((b div a) + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,s=map(int,input().split()) ans=s//n+min(s % n,1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := s div n + Set{s mod n, 1}->min() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def coins(a,b): coin=0 while b>0 : if b>=a : coin+=(b//a) b %=a a-=1 return coin n,s=map(int,input().split(" ")) print(coins(n,s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; execute (coins(n, s))->display(); operation coins(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var coin : int := 0 ; while b > 0 do ( if (b->compareTo(a)) >= 0 then ( coin := coin + (b div a) ; b := b mod a ) else skip ; a := a - 1) ; return coin; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import floor n,s=list(map(int,input().split())) total=floor((s+n-1)/n) print(total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var total : OclAny := floor((s + n - 1) / n) ; execute (total)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def multiply(v,x): carry=0 size=len(v) for i in range(size): res=carry+v[i]*x v[i]=res % 10 carry=res//10 while(carry!=0): v.append(carry % 10) carry//=10 def findSumOfDigits(n): v=[] v.append(1) for i in range(1,n+1): multiply(v,i) sum=0 size=len(v) for i in range(size): sum+=v[i] return sum if __name__=="__main__" : n=1000 print(findSumOfDigits(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 1000 ; execute (findSumOfDigits(n))->display() ) else skip; operation multiply(v : OclAny, x : OclAny) pre: true post: true activity: var carry : int := 0 ; var size : int := (v)->size() ; for i : Integer.subrange(0, size-1) do ( var res : int := carry + v[i+1] * x ; v[i+1] := res mod 10 ; carry := res div 10) ; while (carry /= 0) do ( execute ((carry mod 10) : v) ; carry := carry div 10); operation findSumOfDigits(n : OclAny) : OclAny pre: true post: true activity: v := Sequence{} ; execute ((1) : v) ; for i : Integer.subrange(1, n + 1-1) do ( multiply(v, i)) ; var sum : int := 0 ; size := (v)->size() ; for i : Integer.subrange(0, size-1) do ( sum := sum + v[i+1]) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNum(div,rem,N): num=rem[N-1] i=N-2 while(i>=0): num=num*div[i]+rem[i] i-=1 return num if __name__=='__main__' : div=[8,3] rem=[2,2] N=len(div) print(findNum(div,rem,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( div := Sequence{8}->union(Sequence{ 3 }) ; rem := Sequence{2}->union(Sequence{ 2 }) ; N := (div)->size() ; execute (findNum(div, rem, N))->display() ) else skip; operation findNum(div : OclAny, rem : OclAny, N : OclAny) : OclAny pre: true post: true activity: var num : OclAny := rem[N - 1+1] ; var i : double := N - 2 ; while (i >= 0) do ( num := num * div[i+1] + rem[i+1] ; i := i - 1) ; return num; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): return nSpidersToSeeIn(tuple(input()for _ in range(int(input().split()[0])))) def nSpidersToSeeIn(field): return ' '.join(map(str,tuple(sum(spiders(field,x,y)for y in range(1,len(field)))for x in range(len(field[0]))))) def spiders(field,iRow,iCol): nSpiders=0 iRight,iLeft=iRow-iCol,iRow+iCol if iRight>=0 and field[iCol][iRight]=='R' : nSpiders+=1 if iLeftdisplay() ) else skip; operation main() : OclAny pre: true post: true activity: return nSpidersToSeeIn(((argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))))))) )))))))))); operation nSpidersToSeeIn(field : OclAny) : OclAny pre: true post: true activity: return StringLib.sumStringsWithSeparator(((((argument (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name spiders)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name field))))))) , (argument (test (logical_test (comparison (expr (atom (name x))))))) , (argument (test (logical_test (comparison (expr (atom (name y)))))))) ))))))) (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name field)))))))) ))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name field)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))))))) ))))))))))->collect( _x | (OclType["String"])->apply(_x) )), ' '); operation spiders(field : OclAny, iRow : OclAny, iCol : OclAny) : OclAny pre: true post: true activity: var nSpiders : int := 0 ; var iRight : OclAny := null; var iLeft : OclAny := null; Sequence{iRight,iLeft} := Sequence{iRow - iCol,iRow + iCol} ; if iRight >= 0 & field[iCol+1][iRight+1] = 'R' then ( nSpiders := nSpiders + 1 ) else skip ; if (iLeft->compareTo((field->first())->size())) < 0 & field[iCol+1][iLeft+1] = 'L' then ( nSpiders := nSpiders + 1 ) else skip ; if not(iCol mod 2) & field[iCol+1][iRow+1] = 'U' then ( nSpiders := nSpiders + 1 ) else skip ; return nSpiders; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printDistSum(arr,n): Sum=sum(arr) dp=[[False for i in range(Sum+1)]for i in range(n+1)] for i in range(n+1): dp[i][0]=True for i in range(1,n+1): dp[i][arr[i-1]]=True for j in range(1,Sum+1): if(dp[i-1][j]==True): dp[i][j]=True dp[i][j+arr[i-1]]=True for j in range(Sum+1): if(dp[n][j]==True): print(j,end=" ") arr=[2,3,4,5,6] n=len(arr) printDistSum(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 })))) ; n := (arr)->size() ; printDistSum(arr, n); operation printDistSum(arr : OclAny, n : OclAny) pre: true post: true activity: var Sum : OclAny := (arr)->sum() ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, Sum + 1-1)->select(i | true)->collect(i | (false)))) ; for i : Integer.subrange(0, n + 1-1) do ( dp[i+1]->first() := true) ; for i : Integer.subrange(1, n + 1-1) do ( dp[i+1][arr[i - 1+1]+1] := true ; for j : Integer.subrange(1, Sum + 1-1) do ( if (dp[i - 1+1][j+1] = true) then ( dp[i+1][j+1] := true ; dp[i+1][j + arr[i - 1+1]+1] := true ) else skip)) ; for j : Integer.subrange(0, Sum + 1-1) do ( if (dp[n+1][j+1] = true) then ( execute (j)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): return nSpidersToSeeIn(tuple(input()for _ in range(int(input().split()[0])))) def nSpidersToSeeIn(field): return ' '.join(map(str,tuple(sum((y<=x and field[y][x-y]=='R')+((x+y)display() ) else skip; operation main() : OclAny pre: true post: true activity: return nSpidersToSeeIn(((argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))))))) )))))))))); operation nSpidersToSeeIn(field : OclAny) : OclAny pre: true post: true activity: return StringLib.sumStringsWithSeparator(((((argument (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom (name y)))) <= (comparison (expr (atom (name x)))))) and (logical_test (comparison (comparison (expr (atom (name field)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (name y))))))))) ])))) == (comparison (expr (atom 'R')))))))) ))) + (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (name y)))))))) )))) < (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name field)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))))) and (logical_test (comparison (comparison (expr (atom (name field)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (name y))))))))) ])))) == (comparison (expr (atom 'L')))))))) )))) + (expr (atom ( (testlist_comp (test (logical_test (logical_test not (logical_test (comparison (expr (expr (atom (name y))) % (expr (atom (number (integer 2)))))))) and (logical_test (comparison (comparison (expr (atom (name field)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))) == (comparison (expr (atom 'U')))))))) ))))))) (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name field)))))))) ))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name field)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))))))) ))))))))))->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): return nSpidersToSeeIn(tuple(input()for _ in range(int(input().split()[0])))) def nSpidersToSeeIn(field): return ' '.join(map(str,(sum((y<=x and field[y][x-y]=='R')+((x+y)display() ) else skip; operation main() : OclAny pre: true post: true activity: return nSpidersToSeeIn(((argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))))))) )))))))))); operation nSpidersToSeeIn(field : OclAny) : OclAny pre: true post: true activity: return StringLib.sumStringsWithSeparator(((Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom (name y)))) <= (comparison (expr (atom (name x)))))) and (logical_test (comparison (comparison (expr (atom (name field)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (name y))))))))) ])))) == (comparison (expr (atom 'R')))))))) ))) + (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (name y)))))))) )))) < (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name field)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))))) and (logical_test (comparison (comparison (expr (atom (name field)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (name y))))))))) ])))) == (comparison (expr (atom 'L')))))))) )))) + (expr (atom ( (testlist_comp (test (logical_test (logical_test not (logical_test (comparison (expr (expr (atom (name y))) % (expr (atom (number (integer 2)))))))) and (logical_test (comparison (comparison (expr (atom (name field)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))) == (comparison (expr (atom 'U')))))))) ))))))) (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name field)))))))) ))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name field)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))))))) ))))))))})->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): return nSpidersToSeeIn(tuple(input()for _ in range(int(input().split()[0])))) def nSpidersToSeeIn(field): return ' '.join(map(str,tuple(sum(sum(((y<=x and field[y][x-y]=='R'),((x+y)display() ) else skip; operation main() : OclAny pre: true post: true activity: return nSpidersToSeeIn(((argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))))))) )))))))))); operation nSpidersToSeeIn(field : OclAny) : OclAny pre: true post: true activity: return StringLib.sumStringsWithSeparator(((((argument (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom (name y)))) <= (comparison (expr (atom (name x)))))) and (logical_test (comparison (comparison (expr (atom (name field)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (name y))))))))) ])))) == (comparison (expr (atom 'R')))))))) )))))) , (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (name y)))))))) )))) < (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name field)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))))) and (logical_test (comparison (comparison (expr (atom (name field)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (name y))))))))) ])))) == (comparison (expr (atom 'L')))))))) )))))) , (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test not (logical_test (comparison (expr (expr (atom (name y))) % (expr (atom (number (integer 2)))))))) and (logical_test (comparison (comparison (expr (atom (name field)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))) == (comparison (expr (atom 'U')))))))) ))))))) )))))))) ))))))) (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name field)))))))) ))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name field)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))))))) ))))))))))->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().strip().split()) out=[0 for _ in range(n)] comp=[i+2 for i in range(n)] for _ in range(m): l,r,x=map(int,input().strip().split()) t=l while t<=r : next_val=comp[t-1] if out[t-1]==0 and t!=x : out[t-1]=x comp[t-1]=r+1 if t>=x else x t=next_val print(*out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var out : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)) ; var comp : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i + 2)) ; for _anon : Integer.subrange(0, m-1) do ( var l : OclAny := null; var r : OclAny := null; var x : OclAny := null; Sequence{l,r,x} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : OclAny := l ; while (t->compareTo(r)) <= 0 do ( var next_val : OclAny := comp[t - 1+1] ; if out[t - 1+1] = 0 & t /= x then ( out[t - 1+1] := x ) else skip ; comp[t - 1+1] := if (t->compareTo(x)) >= 0 then r + 1 else x endif ; t := next_val)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name out))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().strip().split()) out=[0 for _ in range(n)] comp=[i+2 for i in range(n)] for _ in range(m): l,r,x=map(int,input().strip().split()) t=l while t<=r : next_val=comp[t-1] if out[t-1]==0 and t!=x : out[t-1]=x comp[t-1]=r+1 if t>=x else x t=next_val print(*out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var out : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)) ; var comp : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i + 2)) ; for _anon : Integer.subrange(0, m-1) do ( var l : OclAny := null; var r : OclAny := null; var x : OclAny := null; Sequence{l,r,x} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : OclAny := l ; while (t->compareTo(r)) <= 0 do ( var next_val : OclAny := comp[t - 1+1] ; if out[t - 1+1] = 0 & t /= x then ( out[t - 1+1] := x ) else skip ; comp[t - 1+1] := if (t->compareTo(x)) >= 0 then r + 1 else x endif ; t := next_val)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name out))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- knights,fights=[int(x)for x in input().split()] res=[0 for _ in range(knights)] arr=[i+1 for i in range(1,knights+1)] for _ in range(fights): k1,k2,w=[int(x)for x in input().split()] i=k1 while i<=k2 : next=arr[i-1] if iselect(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var res : Sequence := Integer.subrange(0, knights-1)->select(_anon | true)->collect(_anon | (0)) ; var arr : Sequence := Integer.subrange(1, knights + 1-1)->select(i | true)->collect(i | (i + 1)) ; for _anon : Integer.subrange(0, fights-1) do ( var k1 : OclAny := null; var k2 : OclAny := null; var w : OclAny := null; Sequence{k1,k2,w} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var i : OclAny := k1 ; while (i->compareTo(k2)) <= 0 do ( var next : OclAny := arr[i - 1+1] ; if (i->compareTo(w)) < 0 then ( arr[i - 1+1] := w ) else ( arr[i - 1+1] := k2 + 1 ) ; if res[i - 1+1] = 0 & i /= w then ( res[i - 1+1] := w ) else skip ; i := next)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) res=[i+1 for i in range(n)] ans=[0]*n for i in range(m): l,r,x=map(int,input().split()) li,xi=l-1,x-1 while licollect( _x | (OclType["int"])->apply(_x) ) ; var res : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i + 1)) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, m-1) do ( var l : OclAny := null; var r : OclAny := null; var x : OclAny := null; Sequence{l,r,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var li : OclAny := null; var xi : OclAny := null; Sequence{li,xi} := Sequence{l - 1,x - 1} ; while (li->compareTo(r)) < 0 do ( if ans[li+1] = 0 & li /= xi then ( ans[li+1] := x ) else skip ; var a : OclAny := res[li+1] ; if (li->compareTo(xi)) < 0 then ( res[li+1] := xi ) else ( res[li+1] := r ) ; var li : OclAny := a)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().strip().split()))[: n] ans=[0]*n mx=arr[-1] for i in range(n-2,-1,-1): ans[i]=max(0,mx-arr[i]+1) if arr[i]>mx : mx=arr[i] print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : OclAny := OclType["Sequence"]((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var mx : OclAny := arr->last() ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( ans[i+1] := Set{0, mx - arr[i+1] + 1}->max() ; if (arr[i+1]->compareTo(mx)) > 0 then ( mx := arr[i+1] ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def segregate0and1(arr,size): type0=0 type1=size-1 while(type0compareTo(type1)) < 0) do ( if (arr[type0+1] = 1) then ( suite ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) k=list(map(int,input().split())) m=0 d=[0 for i in range(n)] for i in range(n): d[n-i-1]=max(0,m+1-k[n-i-1]) m=max(m,k[n-i-1]) print(" ".join(str(x)for x in d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := 0 ; var d : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( d[n - i - 1+1] := Set{0, m + 1 - k[n - i - 1+1]}->max() ; m := Set{m, k[n - i - 1+1]}->max()) ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name d)))))))), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(lambda x : int(x),input().split())) arr.reverse() m=arr[0] arr[0]=0 for i in range(1,n): if arr[i]<=m : arr[i]=m-arr[i]+1 else : m=arr[i] arr[i]=0 arr.reverse() for i in range(n): print(arr[i],end=" ") print(" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) )) ; arr := arr->reverse() ; var m : OclAny := arr->first() ; arr->first() := 0 ; for i : Integer.subrange(1, n-1) do ( if (arr[i+1]->compareTo(m)) <= 0 then ( arr[i+1] := m - arr[i+1] + 1 ) else ( m := arr[i+1] ; arr[i+1] := 0 )) ; arr := arr->reverse() ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()) ; execute (" ")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Subtract(a,b): c=a+(~ b+1) return c if __name__=="__main__" : a,b=2,3 print(Subtract(a,b)) a,b=9,7 print(Subtract(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{a,b} := Sequence{2,3} ; execute (Subtract(a, b))->display() ; Sequence{a,b} := Sequence{9,7} ; execute (Subtract(a, b))->display() ) else skip; operation Subtract(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var c : OclAny := a + (MathLib.bitwiseNot(b) + 1) ; return c; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split(" "))) max=arr[n-1] arr[n-1]=0 i=n-2 while(i>=0): if(arr[i]<=max): arr[i]=max-arr[i]+1 else : max=arr[i] arr[i]=0 i-=1 for i in arr : print(i,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var max : OclAny := arr[n - 1+1] ; arr[n - 1+1] := 0 ; var i : double := n - 2 ; while (i >= 0) do ( if ((arr[i+1]->compareTo(max)) <= 0) then ( arr[i+1] := max - arr[i+1] + 1 ) else ( max := arr[i+1] ; arr[i+1] := 0 ) ; i := i - 1) ; for i : arr do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().strip().split()))[: n] ans=[0]*n mx=arr[-1] for i in range(n-2,-1,-1): ans[i]=max(0,mx-arr[i]+1) if arr[i]>mx : mx=arr[i] print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : OclAny := OclType["Sequence"]((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var mx : OclAny := arr->last() ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( ans[i+1] := Set{0, mx - arr[i+1] + 1}->max() ; if (arr[i+1]->compareTo(mx)) > 0 then ( mx := arr[i+1] ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pell(n): if(n<=2): return n return(2*pell(n-1)+pell(n-2)) n=4 ; print(pell(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4; ; execute (pell(n))->display(); operation pell(n : OclAny) : OclAny pre: true post: true activity: if (n <= 2) then ( return n ) else skip ; return (2 * pell(n - 1) + pell(n - 2)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) i,j=1,n*n while itoInteger() ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{1,n * n} ; while (i->compareTo(j)) < 0 do ( execute (i)->display() ; i := i + 1 ; j := j - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt from collections import defaultdict,deque import sys from bisect import bisect_right as b_r from bisect import bisect_left as b_l from os import path from heapq import* mod=1000000007 INT_MAX=sys.maxsize-1 INT_MIN=-sys.maxsize if(path.exists('input.txt')): sys.stdin=open('input.txt','r') sys.stdout=open('output.txt','w') def solve(): n=int(input()) for i in range(1,(n**2)//2+1,n//2): for j in range(n//2): print(i+j,end=" ") for j in range(n//2): print(n**2-i+1-j,end=" ") print() if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : int := 1000000007 ; var INT_MAX : double := (trailer . (name maxsize)) - 1 ; var INT_MIN : (trailer . (name maxsize)) := -(trailer . (name maxsize)) ; if (path.exists('input.txt')) then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('input.txt')) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile('output.txt')) ) else skip ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(1, ((n)->pow(2)) div 2 + 1-1)->select( $x | ($x - 1) mod n div 2 = 0 ) do ( for j : Integer.subrange(0, n div 2-1) do ( execute (i + j)->display()) ; for j : Integer.subrange(0, n div 2-1) do ( execute ((n)->pow(2) - i + 1 - j)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(0,n): for j in range(1,n+1): print((i+j-1)%(n)+1+(j-1)*(n),end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(1, n + 1-1) do ( execute ((i + j - 1) mod (n) + 1 + (j - 1) * (n))->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(0,(n**2)//2,n//2): res=[] for j in range(i,n//2+i): res.append(j+1) res.append(n**2-j) print(*res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, ((n)->pow(2)) div 2-1)->select( $x | ($x - 0) mod n div 2 = 0 ) do ( var res : Sequence := Sequence{} ; for j : Integer.subrange(i, n div 2 + i-1) do ( execute ((j + 1) : res) ; execute (((n)->pow(2) - j) : res)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countDivisbleby4(s): n=len(s) count=0 ; for i in range(0,n,1): if(s[i]=='4' or s[i]=='8' or s[i]=='0'): count+=1 for i in range(0,n-1,1): h=(ord(s[i])-ord('0'))*10+(ord(s[i+1])-ord('0')) if(h % 4==0): count=count+i+1 return count if __name__=='__main__' : s=['1','2','4'] print(countDivisbleby4(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( s := Sequence{'1'}->union(Sequence{'2'}->union(Sequence{ '4' })) ; execute (countDivisbleby4(s))->display() ) else skip; operation countDivisbleby4(s : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; var count : int := 0; ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (s[i+1] = '4' or s[i+1] = '8' or s[i+1] = '0') then ( count := count + 1 ) else skip) ; for i : Integer.subrange(0, n - 1-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( var h : double := ((s[i+1])->char2byte() - ('0')->char2byte()) * 10 + ((s[i + 1+1])->char2byte() - ('0')->char2byte()) ; if (h mod 4 = 0) then ( count := count + i + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a_n=[[0 for j in range(n)]for i in range(n)] t=1 for i in range(n): for j in range(n): a_n[i][j]=t t+=1 for i in range(n): o=0 for j in range(n): print(a_n[j][(i+o)% n],end=" ") o+=1 print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a_n : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, n-1)->select(j | true)->collect(j | (0)))) ; var t : int := 1 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( a_n[i+1][j+1] := t ; t := t + 1)) ; for i : Integer.subrange(0, n-1) do ( var o : int := 0 ; for j : Integer.subrange(0, n-1) do ( execute (a_n[j+1][(i + o) mod n+1])->display() ; o := o + 1) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binary_search(arr,low,high,ele): while lowele : high=mid else : low=mid+1 return-1 def printSmall(arr,asize,n): copy_arr=arr.copy() copy_arr.sort() for i in range(asize): if binary_search(copy_arr,low=0,high=n,ele=arr[i])>-1 : print(arr[i],end=" ") if __name__=="__main__" : arr=[1,5,8,9,6,7,3,4,2,0] asize=len(arr) n=5 printSmall(arr,asize,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{5}->union(Sequence{8}->union(Sequence{9}->union(Sequence{6}->union(Sequence{7}->union(Sequence{3}->union(Sequence{4}->union(Sequence{2}->union(Sequence{ 0 }))))))))) ; asize := (arr)->size() ; n := 5 ; printSmall(arr, asize, n) ) else skip; operation binary_search(arr : OclAny, low : OclAny, high : OclAny, ele : OclAny) : OclAny pre: true post: true activity: while (low->compareTo(high)) < 0 do ( var mid : int := (low + high) div 2 ; if arr[mid+1] = ele then ( return mid ) else (if (arr[mid+1]->compareTo(ele)) > 0 then ( high := mid ) else ( low := mid + 1 ) ) ) ; return -1; operation printSmall(arr : OclAny, asize : OclAny, n : OclAny) pre: true post: true activity: var copy_arr : OclAny := arr->copy() ; copy_arr := copy_arr->sort() ; for i : Integer.subrange(0, asize-1) do ( if binary_search(copy_arr, (argument (test (logical_test (comparison (expr (atom (name low)))))) = (test (logical_test (comparison (expr (atom (number (integer 0)))))))), (argument (test (logical_test (comparison (expr (atom (name high)))))) = (test (logical_test (comparison (expr (atom (name n))))))), (argument (test (logical_test (comparison (expr (atom (name ele)))))) = (test (logical_test (comparison (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) > -1 then ( execute (arr[i+1])->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countNumbers(n): k=0 count=0 while(n>0): if((n & 1)==0): count+=pow(2,k) k+=1 n>>=1 return count n=11 print(countNumbers(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 11 ; execute (countNumbers(n))->display(); operation countNumbers(n : OclAny) : OclAny pre: true post: true activity: var k : int := 0 ; var count : int := 0 ; while (n > 0) do ( if ((MathLib.bitwiseAnd(n, 1)) = 0) then ( count := count + (2)->pow(k) ) else skip ; k := k + 1 ; n := n div (2->pow(1))) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmd import IDENTCHARS n=int(input()) l=1 r=n while(ltoInteger() ; var l : int := 1 ; var r : int := n ; while ((l->compareTo(r)) < 0) do ( var mid : int := l + (r - l) div 2 ; var idxcnt : double := mid * (mid + 1) / 2 ; if ((idxcnt->compareTo(n)) < 0) then ( l := mid + 1 ) else ( r := mid )) ; l := l - 1 ; idxcnt := l * (l + 1) / 2 ; execute (("" + ((n - idxcnt)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=int(input().split()[-1]) best_buy=min(map(int,input().split())) best_sell=max(map(int,input().split())) num_buy=R//best_buy print(max(R,R+(best_sell-best_buy)*num_buy)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : int := ("" + ((input().split()->last())))->toInteger() ; var best_buy : OclAny := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->min() ; var best_sell : OclAny := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->max() ; var num_buy : int := R div best_buy ; execute (Set{R, R + (best_sell - best_buy) * num_buy}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=lambda : map(int,input().split()) e,e,r=i() s=min(i()) b=max(s,*i()) print(r % s+r//s*b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var e : OclAny := null; var e : OclAny := null; var r : OclAny := null; Sequence{e,e,r} := i->apply() ; var s : OclAny := (i->apply())->min() ; var b : OclAny := Set{s, (argument * (test (logical_test (comparison (expr (atom (name i)) (trailer (arguments ( ))))))))}->max() ; execute (r mod s + r div s * b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (ways_buy_shares,ways_sell_shares,fund)=map(int,input().split(' ')) buy_shares=input().split(' ') sell_shares=input().split(' ') for i in range(ways_buy_shares): buy_shares[i]=int(buy_shares[i]) for i in range(ways_sell_shares): sell_shares[i]=int(sell_shares[i]) shares_quantity_after_morning=fund//min(buy_shares) fund_after_morning=fund-shares_quantity_after_morning*min(buy_shares) at_the_end_of_the_day=shares_quantity_after_morning*max(sell_shares)+fund_after_morning if at_the_end_of_the_day>=fund : print(at_the_end_of_the_day) else : print(fund) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{ways_buy_shares, ways_sell_shares, fund} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var buy_shares : OclAny := input().split(' ') ; var sell_shares : OclAny := input().split(' ') ; for i : Integer.subrange(0, ways_buy_shares-1) do ( buy_shares[i+1] := ("" + ((buy_shares[i+1])))->toInteger()) ; for i : Integer.subrange(0, ways_sell_shares-1) do ( sell_shares[i+1] := ("" + ((sell_shares[i+1])))->toInteger()) ; var shares_quantity_after_morning : int := fund div (buy_shares)->min() ; var fund_after_morning : double := fund - shares_quantity_after_morning * (buy_shares)->min() ; var at_the_end_of_the_day : double := shares_quantity_after_morning * (sell_shares)->max() + fund_after_morning ; if (at_the_end_of_the_day->compareTo(fund)) >= 0 then ( execute (at_the_end_of_the_day)->display() ) else ( execute (fund)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=lambda : map(int,input().split()) _,_,r=i() s=min(i()) b=max(s,*i()) print(r % s+r//s*b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var _anon : OclAny := null; var _anon : OclAny := null; var r : OclAny := null; Sequence{_anon,_anon,r} := i->apply() ; var s : OclAny := (i->apply())->min() ; var b : OclAny := Set{s, (argument * (test (logical_test (comparison (expr (atom (name i)) (trailer (arguments ( ))))))))}->max() ; execute (r mod s + r div s * b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,m,r=map(int,input().split()) s=list(map(int,input().split())) b=list(map(int,input().split())) mi=min(s) c=r//mi ans=max(r,r % mi+max(b)*c) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : OclAny := null; var m : OclAny := null; var r : OclAny := null; Sequence{n,m,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mi : OclAny := (s)->min() ; var c : int := r div mi ; var ans : OclAny := Set{r, r mod mi + (b)->max() * c}->max() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import maxsize maximum,x,ans=-maxsize,None,maxsize graph=[[]for i in range(100)] weight=[0]*100 def dfs(node,parent): global x,ans,graph,weight,maximum a=bin(weight[node]+x).count('1') if maximumselect(i | true)->collect(i | (Sequence{})) ; var weight : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100) ; skip ; if __name__ = "__main__" then ( x := 15 ; weight[1+1] := 5 ; weight[2+1] := 10 ; weight[3+1] := 11 ; weight[4+1] := 8 ; weight[5+1] := 6 ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 3))))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 4))))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 5))))))))) )))) ; dfs(1, 1) ; execute (ans)->display() ) else skip; operation dfs(node : OclAny, parent : OclAny) pre: true post: true activity: skip; skip; skip; skip; skip ; var a : OclAny := bin(weight[node+1] + x)->count('1') ; if (maximum->compareTo(a)) < 0 then ( maximum := a ; ans := node ) else (if maximum = a then ( ans := Set{ans, node}->min() ) else skip) ; for to : graph[node+1] do ( if to = parent then ( continue ) else skip ; dfs(to, node)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) d=[int(input())for _ in range(n)] print(len(set(d))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; execute ((Set{}->union((d)))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=26 def updateFreq(strr,freq): lenn=len(strr) for i in range(lenn): freq[ord(strr[i])-ord('a')]+=1 def maxCount(strr,patt): strrFreq=[0 for i in range(MAX)] updateFreq(strr,strrFreq) pattFreq=[0 for i in range(MAX)] updateFreq(patt,pattFreq) ans=10**9 for i in range(MAX): if(pattFreq[i]==0): continue ans=min(ans,strrFreq[i]//pattFreq[i]) return ans strr="geeksforgeeks" patt="geeks" print(maxCount(strr,patt)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 26 ; skip ; skip ; strr := "geeksforgeeks" ; patt := "geeks" ; execute (maxCount(strr, patt))->display(); operation updateFreq(strr : OclAny, freq : OclAny) pre: true post: true activity: var lenn : int := (strr)->size() ; for i : Integer.subrange(0, lenn-1) do ( freq[(strr[i+1])->char2byte() - ('a')->char2byte()+1] := freq[(strr[i+1])->char2byte() - ('a')->char2byte()+1] + 1); operation maxCount(strr : OclAny, patt : OclAny) : OclAny pre: true post: true activity: var strrFreq : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)) ; updateFreq(strr, strrFreq) ; var pattFreq : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)) ; updateFreq(patt, pattFreq) ; var ans : double := (10)->pow(9) ; for i : Integer.subrange(0, MAX-1) do ( if (pattFreq[i+1] = 0) then ( continue ) else skip ; ans := Set{ans, strrFreq[i+1] div pattFreq[i+1]}->min()) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=eval(input().replace(" ","|")) b=eval(input().replace(" ","|")) print(a+b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := input().replace(" ", "|") ; var b : OclAny := input().replace(" ", "|") ; execute (a + b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) list_1=list(map(int,input().split())) list_2=list(map(int,input().split())) max_1=0 max_2=0 for i in range(n): max_1 |=list_1[i] max_2 |=list_2[i] print(max_1+max_2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var list var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var list:= ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var max var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() : int := 0 ; var max:= 0 : int := 0 ; for i : Integer.subrange(0, n-1) do ( max var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() := max var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() or list var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()[i+1] ; max or list_2[i+1] := max or list_2[i+1] or list_2[i+1]) ; execute (maxmax(max(max(maxmax(max(max(maxmax(max(max(maxmax(max(max(maxmax(max(max(maxmax(max(max(maxmax(max(max var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() + max_2) + max_2) + max_2 + max_2)->display() + max_2) + max_2) + max_2 + max_2)->display() + max_2) + max_2) + max_2 + max_2)->display() + max_2) + max_2) + max_2 + max_2)->display() + max_2) + max_2) + max_2 + max_2)->display() + max_2) + max_2) + max_2 + max_2)->display() + max_2) + max_2) + max_2 + max_2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) if n==1 : print(a[0]+b[0]) else : A=[] B=[] for i in range(n-1): x=a[i]| a[i+1] y=b[i]| b[i+1] A.append(x) B.append(y) for j in range(i+2,n): x |=a[j] y |=b[j] A.append(x) B.append(y) print(max(A)+max(B)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = 1 then ( execute (a->first() + b->first())->display() ) else ( var A : Sequence := Sequence{} ; var B : Sequence := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( var x : int := MathLib.bitwiseOr(a[i+1], a[i + 1+1]) ; var y : int := MathLib.bitwiseOr(b[i+1], b[i + 1+1]) ; execute ((x) : A) ; execute ((y) : B) ; for j : Integer.subrange(i + 2, n-1) do ( x := x or a[j+1] ; y := y or b[j+1] ; execute ((x) : A) ; execute ((y) : B))) ; execute ((A)->max() + (B)->max())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=1 while n>x : n-=x x+=1 print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := 1 ; while (n->compareTo(x)) > 0 do ( n := n - x ; x := x + 1) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=eval(input().replace(" ","|")) b=eval(input().replace(" ","|")) print(a+b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := input().replace(" ", "|") ; var b : OclAny := input().replace(" ", "|") ; execute (a + b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=eval(input().replace(" ","|")) b=eval(input().replace(" ","|")) print(a+b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := input().replace(" ", "|") ; var b : OclAny := input().replace(" ", "|") ; execute (a + b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,L,R,QL,QR=map(int,input().split()) W=list(map(int,input().split())) sum_el=[0] for i in range(1,n+1): sum_el.append(W[i-1]+sum_el[i-1]) answer=QR*(n-1)+sum_el[n]*R for i in range(1,n+1): energy=L*sum_el[i]+R*(sum_el[n]-sum_el[i]) if i>(n-i): energy=energy+(i-(n-i)-1)*QL elif(n-i)>i : energy=energy+((n-i)-i-1)*QR if energycollect( _x | (OclType["int"])->apply(_x) ) ; var W : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sum_el : Sequence := Sequence{ 0 } ; for i : Integer.subrange(1, n + 1-1) do ( execute ((W[i - 1+1] + sum_el[i - 1+1]) : sum_el)) ; var answer : double := QR * (n - 1) + sum_el[n+1] * R ; for i : Integer.subrange(1, n + 1-1) do ( var energy : double := L * sum_el[i+1] + R * (sum_el[n+1] - sum_el[i+1]) ; if (i->compareTo((n - i))) > 0 then ( energy := energy + (i - (n - i) - 1) * QL ) else (if ((n - i)->compareTo(i)) > 0 then ( energy := energy + ((n - i) - i - 1) * QR ) else skip) ; if (energy->compareTo(answer)) < 0 then ( answer := energy ) else skip) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(1): n,l,r,ql,qr=[int(x)for x in input().split()] arr=[int(x)for x in input().split()] temp1,temp2=[],[] curr=0 for i in arr : curr+=i temp1.append(curr) curr=0 for i in arr[: :-1]: curr+=i temp2.append(curr) temp2=temp2[: :-1] ans=min(l*sum(arr)+(n-1)*ql,r*sum(arr)+(n-1)*qr) for i in range(n-1): curr=temp1[i]*l+temp2[i+1]*r if i+1>n-(i+1): curr+=(2*(i+1)-n-1)*ql elif i+1select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var arr : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var temp1 : OclAny := null; var temp2 : OclAny := null; Sequence{temp1,temp2} := Sequence{Sequence{},Sequence{}} ; var curr : int := 0 ; for i : arr do ( curr := curr + i ; execute ((curr) : temp1)) ; curr := 0 ; for i : arr(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( curr := curr + i ; execute ((curr) : temp2)) ; var temp2 : OclAny := temp2(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var ans : OclAny := Set{l * (arr)->sum() + (n - 1) * ql, r * (arr)->sum() + (n - 1) * qr}->min() ; for i : Integer.subrange(0, n - 1-1) do ( curr := temp1[i+1] * l + temp2[i + 1+1] * r ; if (i + 1->compareTo(n - (i + 1))) > 0 then ( curr := curr + (2 * (i + 1) - n - 1) * ql ) else (if (i + 1->compareTo(n - (i + 1))) < 0 then ( curr := curr + (n - 2 * (i + 1) - 1) * qr ) else skip) ; ans := Set{ans, curr}->min()) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,l,r,ql,qr=map(int,input().split()) w=[0]+list(map(int,input().split())) for i in range(1,n+1): w[i]+=w[i-1] s=w[n] print(min(l*w[i]+r*(s-w[i])+ql*max(0,2*i-n-1)+qr*max(0,n-2*i-1)for i in range(n+1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; var r : OclAny := null; var ql : OclAny := null; var qr : OclAny := null; Sequence{n,l,r,ql,qr} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; for i : Integer.subrange(1, n + 1-1) do ( w[i+1] := w[i+1] + w[i - 1+1]) ; var s : OclAny := w[n+1] ; execute (((argument (test (logical_test (comparison (expr (expr (expr (expr (expr (atom (name l))) * (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) + (expr (expr (atom (name r))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name s))) - (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))) + (expr (expr (atom (name ql))) * (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (expr (expr (expr (atom (number (integer 2)))) * (expr (atom (name i)))) - (expr (atom (name n)))) - (expr (atom (number (integer 1)))))))))) )))))) + (expr (expr (atom (name qr))) * (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (expr (expr (atom (name n))) - (expr (expr (atom (number (integer 2)))) * (expr (atom (name i))))) - (expr (atom (number (integer 1)))))))))) ))))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) )))))))))->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect N=int(input()) Ln=list(map(int,input().split(' '))) def binary_area_search(target_list : list,target_item : int)->int : low=0 high=len(target_list)-1 while low<=high : mid=(low+high)//2 guess=target_list[mid] if guess>target_item : if mid==0 : return 0 if target_item>target_list[mid-1]: return mid high=mid-1 else : if mid==len(target_list)-1 : return None if target_list[mid+1]>target_item : return mid+1 low=mid+1 return None def main(): Ln.sort() count=0 for a in range(N): a_l=Ln[N-a-1] for b in range(a+1,N): b_idx=N-b-1 b_l=Ln[b_idx] c_threshold=a_l-b_l c_idx=bisect.bisect_right(Ln,c_threshold) if c_idx>=b_idx : continue count+=b_idx-c_idx print(count) def main2(): Ln.sort(reverse=True) count=0 for a in range(N): a_l=Ln[a] current_min=N-1 b=a+1 while b<=current_min : c_idx=current_min bc=Ln[b]+Ln[c_idx] if a_ltoInteger() ; var Ln : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; skip ; skip ; main(); operation binary_area_search(target_list : Sequence(OclAny), target_item : int) : int pre: true post: true activity: var low : int := 0 ; var high : double := (target_list)->size() - 1 ; while (low->compareTo(high)) <= 0 do ( var mid : int := (low + high) div 2 ; var guess : OclAny := target_list[mid+1] ; if (guess->compareTo(target_item)) > 0 then ( if mid = 0 then ( return 0 ) else skip ; if (target_item->compareTo(target_list[mid - 1+1])) > 0 then ( return mid ) else skip ; high := mid - 1 ) else ( if mid = (target_list)->size() - 1 then ( return null ) else skip ; if (target_list[mid + 1+1]->compareTo(target_item)) > 0 then ( return mid + 1 ) else skip ; low := mid + 1 )) ; return null; operation main() pre: true post: true activity: Ln := Ln->sort() ; var count : int := 0 ; for a : Integer.subrange(0, N-1) do ( var a_l : OclAny := Ln[N - a - 1+1] ; for b : Integer.subrange(a + 1, N-1) do ( var b_idx : double := N - b - 1 ; var b_l : OclAny := Ln[b_idx+1] ; var c_threshold : double := a_l - b_l ; var c_idx : OclAny := bisect.bisect_right(Ln, c_threshold) ; if (c_idx->compareTo(b_idx)) >= 0 then ( continue ) else skip ; count := count + b_idx - c_idx)) ; execute (count)->display(); operation main2() pre: true post: true activity: Ln := Ln->sort() ; count := 0 ; for a : Integer.subrange(0, N-1) do ( a_l := Ln[a+1] ; var current_min : double := N - 1 ; var b : OclAny := a + 1 ; while (b->compareTo(current_min)) <= 0 do ( c_idx := current_min ; var bc : OclAny := Ln[b+1] + Ln[c_idx+1] ; if (a_l->compareTo(bc)) < 0 then ( count := count + (current_min - b) ; b := b + 1 ; continue ) else skip ; current_min := current_min - 1)) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) d=[0]*N stack=[] for i in range(N): d[i]=int(input()) d=sorted(d,reverse=True) ans=0 for i in range(N): if len(stack)==0 : stack.append(d[i]) elif stack[-1]==d[i]: continue elif stack[-1]>d[i]: stack.append(d[i]) else : ans=max(ans,len(stack)) stack=[d[i]] ans=max(ans,len(stack)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var stack : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( d[i+1] := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; d := d->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( if (stack)->size() = 0 then ( execute ((d[i+1]) : stack) ) else (if stack->last() = d[i+1] then ( continue ) else (if (stack->last()->compareTo(d[i+1])) > 0 then ( execute ((d[i+1]) : stack) ) else ( ans := Set{ans, (stack)->size()}->max() ; stack := Sequence{ d[i+1] } ) ) ) ) ; ans := Set{ans, (stack)->size()}->max() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def wastedWater(V,M,N): amt_per_min=M-N time_to_fill=V/amt_per_min wasted_amt=N*time_to_fill return wasted_amt V=700 M=10 N=3 print(wastedWater(V,M,N)) V=1000 M=100 N=50 print(wastedWater(V,M,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; V := 700 ; M := 10 ; N := 3 ; execute (wastedWater(V, M, N))->display() ; V := 1000 ; M := 100 ; N := 50 ; execute (wastedWater(V, M, N))->display(); operation wastedWater(V : OclAny, M : OclAny, N : OclAny) : OclAny pre: true post: true activity: var amt_per_min : double := M - N ; var time_to_fill : double := V / amt_per_min ; var wasted_amt : double := N * time_to_fill ; return wasted_amt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxSubStr(str,n): count0=0 count1=0 cnt=0 for i in range(n): if str[i]=='0' : count0+=1 else : count1+=1 if count0==count1 : cnt+=1 if count0!=count1 : return-1 return cnt str="0100110101" n=len(str) print(maxSubStr(str,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclType["String"] := "0100110101" ; n := (OclType["String"])->size() ; execute (maxSubStr(OclType["String"], n))->display(); operation maxSubStr(OclType["String"] : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count0 : int := 0 ; var count1 : int := 0 ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ("" + ([i+1])) = '0' then ( count0 := count0 + 1 ) else ( count1 := count1 + 1 ) ; if count0 = count1 then ( cnt := cnt + 1 ) else skip) ; if count0 /= count1 then ( return -1 ) else skip ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=list(map(int,input().split())) print(min(a,b,c),max(a,b,c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (Set{a, b, c}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=list(map(int,input().split())) max=a[0] min=a[0] for i in range(1,len(a)): if maxa[i]: min=a[i] print(str(min)+" "+str(max)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var max : OclAny := a->first() ; var min : OclAny := a->first() ; for i : Integer.subrange(1, (a)->size()-1) do ( if (max->compareTo(a[i+1])) < 0 then ( max := a[i+1] ) else skip ; if (min->compareTo(a[i+1])) > 0 then ( min := a[i+1] ) else skip) ; execute (("" + ((min))) + " " + ("" + ((max))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def resolve(): A=[int(i)for i in input().split()] print(min(A),max(A)) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; resolve(); operation resolve() pre: true post: true activity: var A : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute ((A)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) i=int(math.ceil(((1+8*n)**0.5-1)/2)) print(n-i*(i-1)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := ("" + ((((((1 + 8 * n))->pow(0.5) - 1) / 2)->ceil())))->toInteger() ; execute (n - i * (i - 1) div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- res=sorted(map(int,input().split())) print(res[0],res[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var res : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; execute (res->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : a,b,c=map(int,input().split()) print(min(a,b,c),max(a,b,c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{a, b, c}->min())->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findS(s): _sum=0 n=1 while(_sumdisplay() ) else ( execute (n)->display() ); operation findS(s : OclAny) : OclAny pre: true post: true activity: var _sum : int := 0 ; var n : int := 1 ; while ((_sum->compareTo(s)) < 0) do ( _sum := _sum + n ; n := n + 1) ; n := n - 1 ; if _sum = s then ( return n ) else skip ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maximumAbsolute(arr,n): mn=10**9 mx=-10**9 for i in range(n): if(i>0 and arr[i]==-1 and arr[i-1]!=-1): mn=min(mn,arr[i-1]) mx=max(mx,arr[i-1]) if(imax_diff): max_diff=diff return max_diff if __name__=='__main__' : arr=[-1,-1,11,-1,3,-1] n=len(arr) print(maximumAbsolute(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{-1}->union(Sequence{-1}->union(Sequence{11}->union(Sequence{-1}->union(Sequence{3}->union(Sequence{ -1 }))))) ; n := (arr)->size() ; execute (maximumAbsolute(arr, n))->display() ) else skip; operation maximumAbsolute(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var mn : double := (10)->pow(9) ; var mx : double := (-10)->pow(9) ; for i : Integer.subrange(0, n-1) do ( if (i > 0 & arr[i+1] = -1 & arr[i - 1+1] /= -1) then ( mn := Set{mn, arr[i - 1+1]}->min() ; mx := Set{mx, arr[i - 1+1]}->max() ) else skip ; if ((i->compareTo(n - 1)) < 0 & arr[i+1] = -1 & arr[i + 1+1] /= -1) then ( mn := Set{mn, arr[i + 1+1]}->min() ; mx := Set{mx, arr[i + 1+1]}->max() ) else skip) ; var common_integer : int := (mn + mx) div 2 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] = -1) then ( arr[i+1] := common_integer ) else skip) ; var max_diff : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( var diff : double := (arr[i+1] - arr[i + 1+1])->abs() ; if ((diff->compareTo(max_diff)) > 0) then ( max_diff := diff ) else skip) ; return max_diff; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys unique_list=[] input_list=sys.stdin.readlines()[1 :] for i in input_list : if i not in unique_list : unique_list.append(i) print(len(unique_list)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var unique_list : Sequence := Sequence{} ; var input_list : OclAny := sys.stdin.readlines()->tail() ; for i : input_list do ( if (unique_list)->excludes(i) then ( execute ((i) : unique_list) ) else skip) ; execute ((unique_list)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=1000000007 def countStrings(N): dp=[[0]*3 for i in range(N+1)] dp[1][0]=1 ; dp[1][1]=1 ; dp[1][2]=0 ; for i in range(2,N+1): dp[i][0]=(dp[i-1][0]+dp[i-1][1]+dp[i-1][2])% MOD dp[i][1]=dp[i-1][0]% MOD dp[i][2]=dp[i-1][1]% MOD ans=(dp[N][0]+dp[N][1]+dp[N][2])% MOD return ans if __name__=='__main__' : N=3 print(countStrings(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : int := 1000000007 ; skip ; if __name__ = '__main__' then ( N := 3 ; execute (countStrings(N))->display() ) else skip; operation countStrings(N : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, 3))) ; dp[1+1]->first() := 1; ; dp[1+1][1+1] := 1; ; dp[1+1][2+1] := 0; ; for i : Integer.subrange(2, N + 1-1) do ( dp[i+1]->first() := (dp[i - 1+1]->first() + dp[i - 1+1][1+1] + dp[i - 1+1][2+1]) mod MOD ; dp[i+1][1+1] := dp[i - 1+1]->first() mod MOD ; dp[i+1][2+1] := dp[i - 1+1][1+1] mod MOD) ; var ans : int := (dp[N+1]->first() + dp[N+1][1+1] + dp[N+1][2+1]) mod MOD ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def longest_subseq(n,k,s): dp=[0]*n max_length=[0]*26 for i in range(n): curr=ord(s[i])-ord('a') lower=max(0,curr-k) upper=min(25,curr+k) for j in range(lower,upper+1): dp[i]=max(dp[i],max_length[j]+1) max_length[curr]=max(dp[i],max_length[curr]) return max(dp) def main(): s="geeksforgeeks" n=len(s) k=3 print(longest_subseq(n,k,s)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation longest_subseq(n : OclAny, k : OclAny, s : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var max_length : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for i : Integer.subrange(0, n-1) do ( var curr : double := (s[i+1])->char2byte() - ('a')->char2byte() ; var lower : OclAny := Set{0, curr - k}->max() ; var upper : OclAny := Set{25, curr + k}->min() ; for j : Integer.subrange(lower, upper + 1-1) do ( dp[i+1] := Set{dp[i+1], max_length[j+1] + 1}->max()) ; max_length[curr+1] := Set{dp[i+1], max_length[curr+1]}->max()) ; return (dp)->max(); operation main() pre: true post: true activity: s := "geeksforgeeks" ; n := (s)->size() ; k := 3 ; execute (longest_subseq(n, k, s))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def longestFibonacciSubarray(n,a): if(n<=2): return n Len=2 mx=-10**9 for i in range(2,n): if(a[i]==a[i-1]+a[i-2]): Len+=1 else : Len=2 mx=max(mx,Len) return mx n=5 a=[2,4,6,10,2] print(longestFibonacciSubarray(n,a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; a := Sequence{2}->union(Sequence{4}->union(Sequence{6}->union(Sequence{10}->union(Sequence{ 2 })))) ; execute (longestFibonacciSubarray(n, a))->display(); operation longestFibonacciSubarray(n : OclAny, a : OclAny) : OclAny pre: true post: true activity: if (n <= 2) then ( return n ) else skip ; var Len : int := 2 ; var mx : double := (-10)->pow(9) ; for i : Integer.subrange(2, n-1) do ( if (a[i+1] = a[i - 1+1] + a[i - 2+1]) then ( Len := Len + 1 ) else ( Len := 2 ) ; mx := Set{mx, Len}->max()) ; return mx; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minimumSubarrays(ar,n): se=[] cnt=1 ; for i in range(n): if se.count(ar[i])==0 : se.append(ar[i]) else : cnt+=1 se.clear() se.append(ar[i]) return cnt ar=[1,2,1,3,4,2,4,4,4] n=len(ar) print(minimumSubarrays(ar,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; ar := Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{3}->union(Sequence{4}->union(Sequence{2}->union(Sequence{4}->union(Sequence{4}->union(Sequence{ 4 })))))))) ; n := (ar)->size() ; execute (minimumSubarrays(ar, n))->display(); operation minimumSubarrays(ar : OclAny, n : OclAny) : OclAny pre: true post: true activity: var se : Sequence := Sequence{} ; var cnt : int := 1; ; for i : Integer.subrange(0, n-1) do ( if se->count(ar[i+1]) = 0 then ( execute ((ar[i+1]) : se) ) else ( cnt := cnt + 1 ; execute (se /<: se) ; execute ((ar[i+1]) : se) )) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(s): freq=[0]*10 while(s!=0): r=s % 10 s=s//10 freq[r]+=1 xor=0 for i in range(10): xor=xor ^ freq[i] if(xor==0): return True else : return False s=122233 if(check(s)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := 122233 ; if (check(s)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation check(s : OclAny) : OclAny pre: true post: true activity: var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; while (s /= 0) do ( var r : int := s mod 10 ; s := s div 10 ; freq[r+1] := freq[r+1] + 1) ; var xor : int := 0 ; for i : Integer.subrange(0, 10-1) do ( xor := MathLib.bitwiseXor(xor, freq[i+1])) ; if (xor = 0) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _,a=map(int,input().split()) days=list(map(int,input().split())) names=0 lists=0 for i in days : names+=i print(names//a-lists,end=' ') lists+=names//a-lists ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _anon : OclAny := null; var a : OclAny := null; Sequence{_anon,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var days : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var names : int := 0 ; var lists : int := 0 ; for i : days do ( names := names + i ; execute (names div a - lists)->display() ; lists := lists + names div a - lists); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_CHAR=26 ; def countFreq(str1,freq,len1): for i in range(len1): freq[ord(str1[i])-ord('a')]+=1 ; def canMakePalindrome(freq,len1): count_odd=0 ; for i in range(MAX_CHAR): if(freq[i]% 2!=0): count_odd+=1 ; if(len1 % 2==0): if(count_odd>0): return False ; else : return True ; if(count_odd!=1): return False ; return True ; def findOddAndRemoveItsFreq(freq): odd_str="" ; for i in range(MAX_CHAR): if(freq[i]% 2!=0): freq[i]-=1 ; odd_str+=chr(i+ord('a')); return odd_str ; return odd_str ; def findPalindromicString(str1): len1=len(str1); freq=[0]*MAX_CHAR ; countFreq(str1,freq,len1); if(canMakePalindrome(freq,len1)==False): return "No Palindromic String" ; odd_str=findOddAndRemoveItsFreq(freq); front_str="" ; rear_str="" ; for i in range(MAX_CHAR): temp="" ; if(freq[i]!=0): ch=chr(i+ord('a')); for j in range(1,int(freq[i]/2)+1): temp+=ch ; front_str+=temp ; rear_str=temp+rear_str ; return(front_str+odd_str+rear_str); str1="malayalam" ; print(findPalindromicString(str1)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_CHAR : int := 26; ; skip ; skip ; skip ; skip ; str1 := "malayalam"; ; execute (findPalindromicString(str1))->display();; operation countFreq(str1 : OclAny, freq : OclAny, len1 : OclAny) pre: true post: true activity: for i : Integer.subrange(0, len1-1) do ( freq[(str1[i+1])->char2byte() - ('a')->char2byte()+1] := freq[(str1[i+1])->char2byte() - ('a')->char2byte()+1] + 1;); operation canMakePalindrome(freq : OclAny, len1 : OclAny) pre: true post: true activity: var count_odd : int := 0; ; for i : Integer.subrange(0, MAX_CHAR-1) do ( if (freq[i+1] mod 2 /= 0) then ( count_odd := count_odd + 1; ) else skip) ; if (len1 mod 2 = 0) then ( if (count_odd > 0) then ( return false; ) else ( return true; ) ) else skip ; if (count_odd /= 1) then ( return false; ) else skip ; return true;; operation findOddAndRemoveItsFreq(freq : OclAny) pre: true post: true activity: var odd_str : String := ""; ; for i : Integer.subrange(0, MAX_CHAR-1) do ( if (freq[i+1] mod 2 /= 0) then ( freq[i+1] := freq[i+1] - 1; ; odd_str := odd_str + (i + ('a')->char2byte())->byte2char(); ; return odd_str; ) else skip) ; return odd_str;; operation findPalindromicString(str1 : OclAny) pre: true post: true activity: len1 := (str1)->size(); ; freq := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX_CHAR); ; countFreq(str1, freq, len1); ; if (canMakePalindrome(freq, len1) = false) then ( return "No Palindromic String"; ) else skip ; odd_str := findOddAndRemoveItsFreq(freq); ; var front_str : String := ""; ; var rear_str : String := ""; ; for i : Integer.subrange(0, MAX_CHAR-1) do ( var temp : String := ""; ; if (freq[i+1] /= 0) then ( var ch : String := (i + ('a')->char2byte())->byte2char(); ; for j : Integer.subrange(1, ("" + ((freq[i+1] / 2)))->toInteger() + 1-1) do ( temp := temp + ch;) ; front_str := front_str + temp; ; rear_str := temp + rear_str; ) else skip) ; return (front_str + odd_str + rear_str);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) n=int(input()) f=lambda x :(x+1)*x//2 print(n-f(int(((8*n-7)**.5-1)/2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var f : Function := lambda x : OclAny in ((x + 1) * x div 2) ; execute (n - f->apply(("" + (((((8 * n - 7))->pow(.5) - 1) / 2)))->toInteger()))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- days,page_limit=input().split() names=[int(x)for x in input().split()] left=0 for i in range(len(names)): left+=int(names[i]) print(int(left/int(page_limit)),end=" ") left=left % int(page_limit) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var days : OclAny := null; var page_limit : OclAny := null; Sequence{days,page_limit} := input().split() ; var names : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var left : int := 0 ; for i : Integer.subrange(0, (names)->size()-1) do ( left := left + ("" + ((names[i+1])))->toInteger() ; execute (("" + ((left / ("" + ((page_limit)))->toInteger())))->toInteger())->display() ; left := left mod ("" + ((page_limit)))->toInteger()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) s=list(map(int,input().split())) ans='' last=0 for i in range(0,n): ans+=str((last+s[i])//m)+' ' last=(last+s[i])% m print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : String := '' ; var last : int := 0 ; for i : Integer.subrange(0, n-1) do ( ans := ans + ("" + (((last + s[i+1]) div m))) + ' ' ; last := (last + s[i+1]) mod m) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) d=[int(input())for i in range(N)] d.sort() d_tmp=d[0] count=1 for i in range(N): if d_tmp!=d[i]: d_tmp=d[i] count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; d := d->sort() ; var d_tmp : OclAny := d->first() ; var count : int := 1 ; for i : Integer.subrange(0, N-1) do ( if d_tmp /= d[i+1] then ( d_tmp := d[i+1] ; count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys rd=sys.stdin.readline n,m=map(int,rd().split()) t=list(map(int,rd().split())) res=[] for i in range(n): if i==0 : res.append(str(t[i]//m)) t[i]%=m else : res.append(str((t[i]+(t[i-1]))//m)) t[i]=(t[i]+t[i-1])% m print(' '.join(res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var rd : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (rd().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : Sequence := ((rd().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if i = 0 then ( execute ((("" + ((t[i+1] div m)))) : res) ; t[i+1] := t[i+1] mod m ) else ( execute ((("" + (((t[i+1] + (t[i - 1+1])) div m)))) : res) ; t[i+1] := (t[i+1] + t[i - 1+1]) mod m )) ; execute (StringLib.sumStringsWithSeparator((res), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=list(map(int,input().split())); c=0 for i in a : print((c+i)//m,end=' '); c=(c+i)% m ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); var c : int := 0 ; for i : a do ( execute ((c + i) div m)->display(); c := (c + i) mod m); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAXN=1000005 ; even=[0]*MAXN ; odd=[0]*MAXN ; def precompute(arr,n): for i in range(n): if(arr[i]% 2==1): odd[i]=1 ; if(arr[i]% 2==0): even[i]=1 ; for i in range(1,n): even[i]=even[i]+even[i-1]; odd[i]=odd[i]+odd[i-1]; def isOdd(L,R): cnt=odd[R]; if(L>0): cnt-=odd[L-1]; if(cnt==R-L+1): return True ; return False ; def performQueries(a,n,q,m): precompute(a,n); for i in range(m): L=q[i][0]; R=q[i][1]; if(isOdd(L,R)): print("Odd"); else : print("Even"); if __name__=='__main__' : a=[2,1,5,7,6,8,9]; n=len(a); q=[[0,2],[1,2],[2,3],[3,6]]; m=len(q); performQueries(a,n,q,m); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAXN : int := 1000005; ; var even : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAXN); ; var odd : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAXN); ; skip ; skip ; skip ; if __name__ = '__main__' then ( a := Sequence{2}->union(Sequence{1}->union(Sequence{5}->union(Sequence{7}->union(Sequence{6}->union(Sequence{8}->union(Sequence{ 9 })))))); ; n := (a)->size(); ; q := Sequence{Sequence{0}->union(Sequence{ 2 })}->union(Sequence{Sequence{1}->union(Sequence{ 2 })}->union(Sequence{Sequence{2}->union(Sequence{ 3 })}->union(Sequence{ Sequence{3}->union(Sequence{ 6 }) }))); ; m := (q)->size(); ; performQueries(a, n, q, m); ) else skip; operation precompute(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if (arr[i+1] mod 2 = 1) then ( odd[i+1] := 1; ) else skip ; if (arr[i+1] mod 2 = 0) then ( even[i+1] := 1; ) else skip) ; for i : Integer.subrange(1, n-1) do ( even[i+1] := even[i+1] + even[i - 1+1]; ; odd[i+1] := odd[i+1] + odd[i - 1+1];); operation isOdd(L : OclAny, R : OclAny) pre: true post: true activity: var cnt : OclAny := odd[R+1]; ; if (L > 0) then ( cnt := cnt - odd[L - 1+1]; ) else skip ; if (cnt = R - L + 1) then ( return true; ) else skip ; return false;; operation performQueries(a : OclAny, n : OclAny, q : OclAny, m : OclAny) pre: true post: true activity: precompute(a, n); ; for i : Integer.subrange(0, m-1) do ( L := q[i+1]->first(); ; R := q[i+1][1+1]; ; if (isOdd(L, R)) then ( execute ("Odd")->display(); ) else ( execute ("Even")->display(); )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tests=int(input()) for _ in range(tests): windows=int(input()) test=True for k in range((windows//3+1)): if test : for j in range((windows//5+1)): if test : for i in range((windows//7+1)): if i*7+j*5+k*3==windows : print(k,j,i) test=False break if test : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var tests : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, tests-1) do ( var windows : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var test : boolean := true ; for k : Integer.subrange(0, (windows div 3 + 1)-1) do ( if test then ( for j : Integer.subrange(0, (windows div 5 + 1)-1) do ( if test then ( for i : Integer.subrange(0, (windows div 7 + 1)-1) do ( if i * 7 + j * 5 + k * 3 = windows then ( execute (k)->display() ; test := false ; break ) else skip) ) else skip) ) else skip) ; if test then ( execute (-1)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) answer=[0,0,0] if n==3 : print("1 0 0") continue elif n==5 : print("0 1 0") continue elif n==6 : print("2 0 0") continue elif n<7 : print(-1) continue else : answer[2]=n//7 n %=7 if n==1 : answer[2]-=1 answer[1]+=1 answer[0]+=1 elif n==2 : answer[2]-=1 answer[0]+=3 elif n==3 : answer[2]-=1 answer[1]+=2 elif n==4 : answer[2]-=1 answer[1]+=1 answer[0]+=2 elif n==5 : answer[2]-=1 answer[0]+=4 elif n==6 : answer[2]-=1 answer[1]+=2 answer[0]+=1 for x in answer : print(x,end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var answer : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) ; if n = 3 then ( execute ("1 0 0")->display() ; continue ) else (if n = 5 then ( execute ("0 1 0")->display() ; continue ) else (if n = 6 then ( execute ("2 0 0")->display() ; continue ) else (if n < 7 then ( execute (-1)->display() ; continue ) else ( answer[2+1] := n div 7 ; n := n mod 7 ; if n = 1 then ( answer[2+1] := answer[2+1] - 1 ; answer[1+1] := answer[1+1] + 1 ; answer->first() := answer->first() + 1 ) else (if n = 2 then ( answer[2+1] := answer[2+1] - 1 ; answer->first() := answer->first() + 3 ) else (if n = 3 then ( answer[2+1] := answer[2+1] - 1 ; answer[1+1] := answer[1+1] + 2 ) else (if n = 4 then ( answer[2+1] := answer[2+1] - 1 ; answer[1+1] := answer[1+1] + 1 ; answer->first() := answer->first() + 2 ) else (if n = 5 then ( answer[2+1] := answer[2+1] - 1 ; answer->first() := answer->first() + 4 ) else (if n = 6 then ( answer[2+1] := answer[2+1] - 1 ; answer[1+1] := answer[1+1] + 2 ; answer->first() := answer->first() + 1 ) else skip ) ) ) ) ) ) ) ) ) ; for x : answer do ( execute (x)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : n=int(input()) threes=0 fives=0 sevens=0 notPossible=False while n!=0 : if n % 3==0 : threes+=n//3 n=0 elif(n-7)% 3==0 and(n-7)>=0 : sevens+=1 n-=7 elif(n-5)% 3==0 and(n-5)>=0 : fives+=1 n-=5 else : notPossible=True break if notPossible : print(-1) else : print(threes,fives,sevens) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var threes : int := 0 ; var fives : int := 0 ; var sevens : int := 0 ; var notPossible : boolean := false ; while n /= 0 do ( if n mod 3 = 0 then ( threes := threes + n div 3 ; n := 0 ) else (if (n - 7) mod 3 = 0 & (n - 7) >= 0 then ( sevens := sevens + 1 ; n := n - 7 ) else (if (n - 5) mod 3 = 0 & (n - 5) >= 0 then ( fives := fives + 1 ; n := n - 5 ) else ( notPossible := true ; break ) ) ) ) ; if notPossible then ( execute (-1)->display() ) else ( execute (threes)->display() ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): w=int(input()) l=[0,0,0] l[0]=w//3 if w % 3==2 and w>=5 : l[0]-=1 l[1]=1 elif w % 3==1 and w>=7 : l[0]-=2 l[2]=1 elif w % 3!=0 : print(-1) continue print(*l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var w : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) ; l->first() := w div 3 ; if w mod 3 = 2 & w >= 5 then ( l->first() := l->first() - 1 ; l[1+1] := 1 ) else (if w mod 3 = 1 & w >= 7 then ( l->first() := l->first() - 2 ; l[2+1] := 1 ) else (if w mod 3 /= 0 then ( execute (-1)->display() ; continue ) else skip ) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name l))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getint(): return[int(i)for i in input().split()] def get(): return int(input()) def S(): for test in range(int(input())): solve() def solve(): n=get() if n in[1,2,4]: print(-1) return for i in range(334): for j in range(334): if(n-i*3-j*5)% 7==0 and(n-i*3-j*5)//7>=0 : print(i,j,(n-i*3-j*5)//7) return print(-1) S() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; S(); operation getint() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation get() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation S() pre: true post: true activity: for test : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve()); operation solve() pre: true post: true activity: var n : OclAny := get() ; if (Sequence{1}->union(Sequence{2}->union(Sequence{ 4 })))->includes(n) then ( execute (-1)->display() ; return ) else skip ; for i : Integer.subrange(0, 334-1) do ( for j : Integer.subrange(0, 334-1) do ( if (n - i * 3 - j * 5) mod 7 = 0 & (n - i * 3 - j * 5) div 7 >= 0 then ( execute (i)->display() ; return ) else skip)) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(1,10**8): if ntoInteger() ; for i : Integer.subrange(1, (10)->pow(8)-1) do ( if (n->compareTo(i + 1)) < 0 then ( execute (n)->display() ; exit() ) else skip ; n := n - i); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def solve(): n=int(input()) if n % 2 : if(n-1)//2 % 2==1 : return[(n-1)//2-2,(n-1)//2+2,1] else : return[(n-1)//2-1,(n-1)//2+1,1] else : return[n//2-1,n//2,1] for _ in range(int(input())): print(*solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name solve)) (trailer (arguments ( )))))))))->display()); operation solve() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 then ( if (n - 1) div 2 mod 2 = 1 then ( return Sequence{(n - 1) div 2 - 2}->union(Sequence{(n - 1) div 2 + 2}->union(Sequence{ 1 })) ) else ( return Sequence{(n - 1) div 2 - 1}->union(Sequence{(n - 1) div 2 + 1}->union(Sequence{ 1 })) ) ) else ( return Sequence{n div 2 - 1}->union(Sequence{n div 2}->union(Sequence{ 1 })) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) list_original=[int(input())for i in range(n)] check=101 count=0 list=sorted(list_original,reverse=True) for k in list : if ktoInteger() ; var list_original : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var check : int := 101 ; var count : int := 0 ; var OclType["Sequence"] : Sequence := list_original->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; for k : OclType["Sequence"] do ( if (k->compareTo(check)) < 0 then ( count := count + 1 ; check := k ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) if n % 2==0 : print(n-3,2,1) else : p=int((n-1)/2) if p % 2==0 : print(p+1,p-1,1) else : print(p+2,p-2,1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( execute (n - 3)->display() ) else ( var p : int := ("" + (((n - 1) / 2)))->toInteger() ; if p mod 2 = 0 then ( execute (p + 1)->display() ) else ( execute (p + 2)->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for _ in range(T): n=int(input()) c=1 b=(n-c)//2 a=n-b-c if a==b : a+=1 b-=1 if a % 2==0 and b % 2==0 : a+=1 b-=1 print(a,b,c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, T-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := 1 ; var b : int := (n - c) div 2 ; var a : double := n - b - c ; if a = b then ( a := a + 1 ; b := b - 1 ) else skip ; if a mod 2 = 0 & b mod 2 = 0 then ( a := a + 1 ; b := b - 1 ) else skip ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout import math T=int(stdin.readline()) for i in range(T): N=int(stdin.readline()) if N % 2==0 : A=N//2-1 B=N//2 C=1 else : C=1 A=3 B=N-1-A while(math.gcd(A,B)!=1): A+=2 B-=2 stdout.write(f"{A}{B}{C}\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var T : int := ("" + ((stdin.readLine())))->toInteger() ; for i : Integer.subrange(0, T-1) do ( var N : int := ("" + ((stdin.readLine())))->toInteger() ; if N mod 2 = 0 then ( var A : double := N div 2 - 1 ; var B : int := N div 2 ; var C : int := 1 ) else ( C := 1 ; A := 3 ; B := N - 1 - A ; while ((A)->gcd(B) /= 1) do ( A := A + 2 ; B := B - 2) ) ; stdout.write(StringLib.formattedString("{A}{B}{C}\n"))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for _ in range(int(input())): n=int(input()) if(n-3)% 2!=0 : print(n-3,2,1) else : i=(n-1)//2 while i>=1 : if math.gcd(i,n-i-1)==1 : print(i,n-i-1,1) break i-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n - 3) mod 2 /= 0 then ( execute (n - 3)->display() ) else ( var i : int := (n - 1) div 2 ; while i >= 1 do ( if (i)->gcd(n - i - 1) = 1 then ( execute (i)->display() ; break ) else skip ; i := i - 1) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=input() k=int(k) s=input() if len(s)<=k : print(str(s)) else : s=s[: k] print(str(s)+"...") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : String := (OclFile["System.in"]).readLine() ; k := ("" + ((k)))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; if (s)->size() <= k then ( execute (("" + ((s))))->display() ) else ( s := s.subrange(1,k) ; execute (("" + ((s))) + "...")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): K=int(input()) S=input() if len(S)<=K : return S return S[: K]+'...' if __name__=='__main__' : print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( execute (main())->display() ) else skip; operation main() : OclAny pre: true post: true activity: var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : String := (OclFile["System.in"]).readLine() ; if ((S)->size()->compareTo(K)) <= 0 then ( return S ) else skip ; return S.subrange(1,K) + '...'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) s=list(input()) if len(s)<=k : print(''.join(s)) else : print(''.join(s[: k])+'...') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if ((s)->size()->compareTo(k)) <= 0 then ( execute (StringLib.sumStringsWithSeparator((s), ''))->display() ) else ( execute (StringLib.sumStringsWithSeparator((s.subrange(1,k)), '') + '...')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- K=int(input()) S=input() print(S if len(S)<=K else S[: K]+"...") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : String := (OclFile["System.in"]).readLine() ; execute (if ((S)->size()->compareTo(K)) <= 0 then S else S.subrange(1,K) + "..." endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- K=input() S=input() if len(S)<=int(K): print(S) else : print("{}...".format(S[: int(K)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var K : String := (OclFile["System.in"]).readLine() ; var S : String := (OclFile["System.in"]).readLine() ; if ((S)->size()->compareTo(("" + ((K)))->toInteger())) <= 0 then ( execute (S)->display() ) else ( execute (StringLib.interpolateStrings("{}...", Sequence{S.subrange(1,("" + ((K)))->toInteger())}))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) def loveTriangle(idx,seen): if idx in seen : if len(seen)==3 : return idx return-1 return loveTriangle(arr[idx-1],seen | set([idx])) isTrue=False for i in range(1,n+1): if i==loveTriangle(arr[i-1],set([i])): isTrue=True break if isTrue : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; var isTrue : boolean := false ; for i : Integer.subrange(1, n + 1-1) do ( if i = loveTriangle(arr[i - 1+1], Set{}->union((Sequence{ i }))) then ( isTrue := true ; break ) else skip) ; if isTrue then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); operation loveTriangle(idx : OclAny, seen : OclAny) : OclAny pre: true post: true activity: if (seen)->includes(idx) then ( if (seen)->size() = 3 then ( return idx ) else skip ; return -1 ) else skip ; return loveTriangle(arr[idx - 1+1], MathLib.bitwiseOr(seen, Set{}->union((Sequence{ idx })))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() t=input() a=ord(t[0])-ord(s[0]) b=int(t[1])-int(s[1]) x=abs(a) y=abs(b) c=['R','U','L','D'] i=0 j=1 if a<0 : i=2 if b<0 : j=3 k=j if x>y : k=i x,y=y,x m=c[i]+c[j] n=c[k] print(y) for l in range(x): print(m) for l in range(y-x): print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var a : double := (t->first())->char2byte() - (s->first())->char2byte() ; var b : double := ("" + ((t[1+1])))->toInteger() - ("" + ((s[1+1])))->toInteger() ; var x : double := (a)->abs() ; var y : double := (b)->abs() ; var c : Sequence := Sequence{'R'}->union(Sequence{'U'}->union(Sequence{'L'}->union(Sequence{ 'D' }))) ; var i : int := 0 ; var j : int := 1 ; if a < 0 then ( i := 2 ) else skip ; if b < 0 then ( j := 3 ) else skip ; var k : int := j ; if (x->compareTo(y)) > 0 then ( k := i ; Sequence{x,y} := Sequence{y,x} ) else skip ; var m : OclAny := c[i+1] + c[j+1] ; var n : OclAny := c[k+1] ; execute (y)->display() ; for l : Integer.subrange(0, x-1) do ( execute (m)->display()) ; for l : Integer.subrange(0, y - x-1) do ( execute (n)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B,T=map(int,input().split()) ans=(T//A)*B print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var T : OclAny := null; Sequence{A,B,T} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : double := (T div A) * B ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math def solve(A : int,B : int,T : int): print(math.floor(T/A)*B) return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() A=int(next(tokens)) B=int(next(tokens)) T=int(next(tokens)) solve(A,B,T) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(A : int, B : int, T : int) pre: true post: true activity: execute ((T / A)->floor() * B)->display() ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var A : int := ("" + (((tokens).next())))->toInteger() ; var B : int := ("" + (((tokens).next())))->toInteger() ; var T : int := ("" + (((tokens).next())))->toInteger() ; solve(A, B, T); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def ip(): return int(input()) def inp(): return map(int,input().split()) def inpstr(): return map(str,input().split()) def linp(): return list(map(int,input().split())) def linpstr(): return list(map(str,input().split())) a,b,t=inp() print(t//a*b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var a : OclAny := null; var b : OclAny := null; var t : OclAny := null; Sequence{a,b,t} := inp() ; execute (t div a * b)->display(); operation ip() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inp() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation inpstr() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["String"])->apply(_x) ); operation linp() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation linpstr() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["String"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,t=map(int,input().split()) cookie=0 time=a while time<=t+0.5 : cookie+=b time+=a print(cookie) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var t : OclAny := null; Sequence{a,b,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cookie : int := 0 ; var time : OclAny := a ; while (time->compareTo(t + 0.5)) <= 0 do ( cookie := cookie + b ; time := time + a) ; execute (cookie)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque import heapq import math import bisect def main(): A,B,T=map(int,input().split()) print(T//A*B) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var T : OclAny := null; Sequence{A,B,T} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (T div A * B)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(m,n,o,p,hhmm): h=int(hhmm[0]+hhmm[1]) m=int(hhmm[3]+hhmm[4]) lft=h*60+m rt=lft+n i=30*10 ans=0 while i<1440 : if ilft : ans+=1 i+=o return ans m,n=map(int,input().split()) o,p=map(int,input().split()) hhmm=input() print(solve(m,n,o,p,hhmm)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; Sequence{o,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; hhmm := (OclFile["System.in"]).readLine() ; execute (solve(m, n, o, p, hhmm))->display(); operation solve(m : OclAny, n : OclAny, o : OclAny, p : OclAny, hhmm : OclAny) : OclAny pre: true post: true activity: var h : int := ("" + ((hhmm->first() + hhmm[1+1])))->toInteger() ; m := ("" + ((hhmm[3+1] + hhmm[4+1])))->toInteger() ; var lft : int := h * 60 + m ; var rt : int := lft + n ; var i : int := 30 * 10 ; var ans : int := 0 ; while i < 1440 do ( if (i->compareTo(rt)) < 0 & (i + p->compareTo(lft)) > 0 then ( ans := ans + 1 ) else skip ; i := i + o) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,ta=map(int,input().split()) b,tb=map(int,input().split()) hh,mm=map(int,input().split(':')) s=hh*60+mm t=hh*60+mm+ta i=0 ans=0 while 5*60+i*b<=23*60+59 : if s-tb<5*60+i*bcollect( _x | (OclType["int"])->apply(_x) ) ; var b : OclAny := null; var tb : OclAny := null; Sequence{b,tb} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var hh : OclAny := null; var mm : OclAny := null; Sequence{hh,mm} := (input().split(':'))->collect( _x | (OclType["int"])->apply(_x) ) ; var s : double := hh * 60 + mm ; var t : double := hh * 60 + mm + ta ; var i : int := 0 ; var ans : int := 0 ; while (5 * 60 + i * b->compareTo(23 * 60 + 59)) <= 0 do ( if (s - tb->compareTo(5 * 60 + i * b)) < 0 & (5 * 60 + i * b < t) then ( ans := ans + 1 ) else skip ; i := i + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,at=map(int,input().split()) b,bt=map(int,input().split()) t1,t2=map(int,input().split(':')) st=t2+(t1-5)*60 fin=st+at now=0 ans=0 while nowst : ans+=1 now+=b print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var at : OclAny := null; Sequence{a,at} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : OclAny := null; var bt : OclAny := null; Sequence{b,bt} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t1 : OclAny := null; var t2 : OclAny := null; Sequence{t1,t2} := (input().split(':'))->collect( _x | (OclType["int"])->apply(_x) ) ; var st : OclAny := t2 + (t1 - 5) * 60 ; var fin : OclAny := st + at ; var now : int := 0 ; var ans : int := 0 ; while (now->compareTo(fin)) < 0 & now < 1140 do ( if (now + bt->compareTo(st)) > 0 then ( ans := ans + 1 ) else skip ; now := now + b) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=input ; l=3 for _ in[0]*int(i()): x=int(i()) if x==l : print('NO'); exit() l ^=x print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : OclAny := input; var l : int := 3 ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + ((i())))->toInteger()) do ( var x : int := ("" + ((i())))->toInteger() ; if x = l then ( execute ('NO')->display(); exit() ) else skip ; l := l xor x) ; execute ('YES')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=input ; l=3 for _ in[0]*int(i()): x=int(i()) if x==l : print('NO'); exit() l ^=x print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : OclAny := input; var l : int := 3 ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + ((i())))->toInteger()) do ( var x : int := ("" + ((i())))->toInteger() ; if x = l then ( execute ('NO')->display(); exit() ) else skip ; l := l xor x) ; execute ('YES')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s1=input() s2=input() res=max(abs(ord(s1[0])-ord(s2[0])),abs(int(s1[1])-int(s2[1]))) print(res) hang1=ord(s1[0]) cot1=int(s1[1]) hang2=ord(s2[0]) cot2=int(s2[1]) while True : if hang1==hang2 and cot1==cot2 : break if hang1hang2 : print('L',end="") hang2+=1 if cot1cot2 : print('D',end="") cot2+=1 print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s1 : String := (OclFile["System.in"]).readLine() ; var s2 : String := (OclFile["System.in"]).readLine() ; var res : OclAny := Set{((s1->first())->char2byte() - (s2->first())->char2byte())->abs(), (("" + ((s1[1+1])))->toInteger() - ("" + ((s2[1+1])))->toInteger())->abs()}->max() ; execute (res)->display() ; var hang1 : int := (s1->first())->char2byte() ; var cot1 : int := ("" + ((s1[1+1])))->toInteger() ; var hang2 : int := (s2->first())->char2byte() ; var cot2 : int := ("" + ((s2[1+1])))->toInteger() ; while true do ( if hang1 = hang2 & cot1 = cot2 then ( break ) else skip ; if (hang1->compareTo(hang2)) < 0 then ( execute ('R')->display() ; hang1 := hang1 + 1 ) else ( if (hang1->compareTo(hang2)) > 0 then ( execute ('L')->display() ; hang2 := hang2 + 1 ) else skip ) ; if (cot1->compareTo(cot2)) < 0 then ( execute ('U')->display() ; cot1 := cot1 + 1 ) else ( if (cot1->compareTo(cot2)) > 0 then ( execute ('D')->display() ; cot2 := cot2 + 1 ) else skip ) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() planes=input().split() planes=[int(m)for m in planes] c,v=0,0 for ii in planes : c+=1 t=planes[ii-1] if planes[t-1]==c : print('YES') v=1 break if v!=1 : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var planes : OclAny := input().split() ; planes := planes->select(m | true)->collect(m | (("" + ((m)))->toInteger())) ; var c : OclAny := null; var v : OclAny := null; Sequence{c,v} := Sequence{0,0} ; for ii : planes do ( c := c + 1 ; var t : OclAny := planes[ii - 1+1] ; if planes[t - 1+1] = c then ( execute ('YES')->display() ; var v : int := 1 ; break ) else skip) ; if v /= 1 then ( execute ("NO")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) viewer=3 result=True for i in range(n): winner=int(input()) if winner==viewer : result=False if(winner==1 and viewer==3)or(winner==3 and viewer==1): viewer=2 elif(winner==2 and viewer==1)or(winner==1 and viewer==2): viewer=3 elif(winner==3 and viewer==2)or(winner==2 and viewer==3): viewer=1 if result : print("YES") else : print("NO") main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var viewer : int := 3 ; var result : boolean := true ; for i : Integer.subrange(0, n-1) do ( var winner : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if winner = viewer then ( result := false ) else skip ; if (winner = 1 & viewer = 3) or (winner = 3 & viewer = 1) then ( viewer := 2 ) else (if (winner = 2 & viewer = 1) or (winner = 1 & viewer = 2) then ( viewer := 3 ) else (if (winner = 3 & viewer = 2) or (winner = 2 & viewer = 3) then ( viewer := 1 ) else skip ) ) ) ; if result then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) player=[1,2] other=[3] switch=0 for i in range(n): s=int(input()) if s in player : other.append(s) player.remove(s) tmp=player player=other other=tmp else : switch=1 if switch==1 : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var player : Sequence := Sequence{1}->union(Sequence{ 2 }) ; var other : Sequence := Sequence{ 3 } ; var switch : int := 0 ; for i : Integer.subrange(0, n-1) do ( var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (player)->includes(s) then ( execute ((s) : other) ; execute ((s) /: player) ; var tmp : Sequence := player ; player := other ; other := tmp ) else ( switch := 1 )) ; if switch = 1 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[1,2] f="YES" for i in range(n): x=int(input()) if x in a : a=[x,6-sum(a)] else : f="NO" print(f) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{1}->union(Sequence{ 2 }) ; var f : String := "YES" ; for i : Integer.subrange(0, n-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (a)->includes(x) then ( a := Sequence{x}->union(Sequence{ 6 - (a)->sum() }) ) else ( f := "NO" )) ; execute (f)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- data=[l.strip()for l in open("infile","r").readlines()] out=open("outfile","w") ncases=int(data.pop(0)) for case in range(ncases): numelements=int(data.pop(0)) elements=[int(s)for s in data.pop(0).split(' ')] inwrongplace=0 for i in range(len(elements)): if elements[i]!=i+1 : inwrongplace+=1 out.write("Case #"+str(case+1)+": "+str("%.6f" % inwrongplace)+"\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var data : Sequence := open("infile", "r").readlines()->select(l | true)->collect(l | (l->trim())) ; var out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("outfile")) ; var ncases : int := ("" + ((data->at(0`firstArg+1))))->toInteger() ; for case : Integer.subrange(0, ncases-1) do ( var numelements : int := ("" + ((data->at(0`firstArg+1))))->toInteger() ; var elements : Sequence := data->at(0`firstArg+1).split(' ')->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; var inwrongplace : int := 0 ; for i : Integer.subrange(0, (elements)->size()-1) do ( if elements[i+1] /= i + 1 then ( inwrongplace := inwrongplace + 1 ) else skip) ; out.write("Case #" + ("" + ((case + 1))) + ": " + ("" + ((StringLib.format("%.6f",inwrongplace)))) + "\n")); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def times(steps,n): current_level=0 previous_level=0 count=0 for i in range(n): previous_level=current_level current_level=current_level+steps[i] if((previous_level<0 and current_level>=0)or(previous_level>0 and current_level<=0)): count+=1 return count steps=[1,-1,0,0,1,1,-3,2] n=len(steps) print(times(steps,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; steps := Sequence{1}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{-3}->union(Sequence{ 2 }))))))) ; n := (steps)->size() ; execute (times(steps, n))->display(); operation times(steps : OclAny, n : OclAny) : OclAny pre: true post: true activity: var current_level : int := 0 ; var previous_level : int := 0 ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( previous_level := current_level ; current_level := current_level + steps[i+1] ; if ((previous_level < 0 & current_level >= 0) or (previous_level > 0 & current_level <= 0)) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- D=360 x=[0 for i in range(D)] n=int(input()) for i in range(n): m,d,v,s=map(int,input().split()) m-=1 d-=1 start=30*m+d end=(start+v-1)% D h=[False for _ in range(D)] for j in range(v): y=(start+j)% D h[y]=True for j in range(D): if h[j]: x[j]=max(x[j],s) else : A=abs(start-j) if A>D//2 : A=D-A B=abs(end-j) if B>D//2 : B=D-B x[j]=max(x[j],s-min(A,B)) print(min(x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var D : int := 360 ; var x : Sequence := Integer.subrange(0, D-1)->select(i | true)->collect(i | (0)) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var m : OclAny := null; var d : OclAny := null; var v : OclAny := null; var s : OclAny := null; Sequence{m,d,v,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; m := m - 1 ; d := d - 1 ; var start : double := 30 * m + d ; var end : int := (start + v - 1) mod D ; var h : Sequence := Integer.subrange(0, D-1)->select(_anon | true)->collect(_anon | (false)) ; for j : Integer.subrange(0, v-1) do ( var y : int := (start + j) mod D ; h[y+1] := true) ; for j : Integer.subrange(0, D-1) do ( if h[j+1] then ( x[j+1] := Set{x[j+1], s}->max() ) else ( var A : double := (start - j)->abs() ; if (A->compareTo(D div 2)) > 0 then ( A := D - A ) else skip ; var B : double := (end - j)->abs() ; if (B->compareTo(D div 2)) > 0 then ( B := D - B ) else skip ; x[j+1] := Set{x[j+1], s - Set{A, B}->min()}->max() ))) ; execute ((x)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) eff=[0]*360 days=[list(map(int,input().split()))for i in range(n)] for m,d,v,s in days : a=(m-1)*30+d-1 b=a+v for i in range(a,b): eff[i % 360]=max(eff[i % 360],s) for i in range(b,a+360): eff[i % 360]=max(eff[i % 360],s-min(i-b+1,360+a-i)) print(min(eff)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var eff : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 360) ; var days : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for _tuple : days do (var _indx : int := 1; var m : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); var a : double := (m - 1) * 30 + d - 1 ; var b : OclAny := a + v ; for i : Integer.subrange(a, b-1) do ( eff[i mod 360+1] := Set{eff[i mod 360+1], s}->max()) ; for i : Integer.subrange(b, a + 360-1) do ( eff[i mod 360+1] := Set{eff[i mod 360+1], s - Set{i - b + 1, 360 + a - i}->min()}->max())) ; execute ((eff)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=input() N=int(N)+1 X=[0] C=[0]*360 for i in range(1,N): x=input() X.append(x.split()) i_start=(int(X[i][0])-1)*30+int(X[i][1])-1 i_end=i_start+int(X[i][2])-1 for j in range(i_start,i_end+1): C[j % 360]=max(C[j % 360],int(X[i][3])) for k in range(1,int(X[i][3])+1): C[(i_start-k+360)% 360]=max(C[(i_start-k+360)% 360],int(X[i][3])-k) C[(i_end+k)% 360]=max(C[(i_end+k)% 360],int(X[i][3])-k) print(min(C)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : String := (OclFile["System.in"]).readLine() ; N := ("" + ((N)))->toInteger() + 1 ; var X : Sequence := Sequence{ 0 } ; var C : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 360) ; for i : Integer.subrange(1, N-1) do ( var x : String := (OclFile["System.in"]).readLine() ; execute ((x.split()) : X) ; var i_start : double := (("" + ((X[i+1]->first())))->toInteger() - 1) * 30 + ("" + ((X[i+1][1+1])))->toInteger() - 1 ; var i_end : double := i_start + ("" + ((X[i+1][2+1])))->toInteger() - 1 ; for j : Integer.subrange(i_start, i_end + 1-1) do ( C[j mod 360+1] := Set{C[j mod 360+1], ("" + ((X[i+1][3+1])))->toInteger()}->max()) ; for k : Integer.subrange(1, ("" + ((X[i+1][3+1])))->toInteger() + 1-1) do ( C[(i_start - k + 360) mod 360+1] := Set{C[(i_start - k + 360) mod 360+1], ("" + ((X[i+1][3+1])))->toInteger() - k}->max() ; C[(i_end + k) mod 360+1] := Set{C[(i_end + k) mod 360+1], ("" + ((X[i+1][3+1])))->toInteger() - k}->max())) ; execute ((C)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(('Um_nik','Petr')[int(input())//1000<=sum(i==x for i,x in enumerate(map(int,input().split()),1))]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (Sequence{'Um_nik', 'Petr'}->select((("" + (((OclFile["System.in"]).readLine())))->toInteger() div 1000->compareTo(((argument (test (logical_test (comparison (comparison (expr (atom (name i)))) == (comparison (expr (atom (name x))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))))))->sum())) <= 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def shortest_path(s,t): cots=ord(s[0]) dongs=ord(s[1]) cott=ord(t[0]) dongt=ord(t[1]) print(max(abs(dongs-dongt),abs(cots-cott))) while True : if cots==cott and dongs==dongt : break if cotscott : cots-=1 print('L',end="") if dongs>dongt : dongs-=1 print('D',end="") else : if dongsfirst())->char2byte() ; var dongs : int := (s[1+1])->char2byte() ; var cott : int := (t->first())->char2byte() ; var dongt : int := (t[1+1])->char2byte() ; execute (Set{(dongs - dongt)->abs(), (cots - cott)->abs()}->max())->display() ; while true do ( if cots = cott & dongs = dongt then ( break ) else skip ; if (cots->compareTo(cott)) < 0 then ( cots := cots + 1 ; execute ('R')->display() ) else ( if (cots->compareTo(cott)) > 0 then ( cots := cots - 1 ; execute ('L')->display() ) else skip ) ; if (dongs->compareTo(dongt)) > 0 then ( dongs := dongs - 1 ; execute ('D')->display() ) else ( if (dongs->compareTo(dongt)) < 0 then ( dongs := dongs + 1 ; execute ('U')->display() ) else skip ) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(sys.stdin.readline().rstrip()) nums=list(map(int,sys.stdin.readline().split())) swaps=0 visited=set() for index in range(n): if index in visited : continue else : visited.add(index) length=0 value=nums[index] while(value!=index+1): visited.add(value-1) value=nums[value-1] length+=1 swaps+=length if((3*n-swaps)% 2): print("Um_nik") else : print("Petr") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + ((sys.stdin.readLine().rstrip())))->toInteger() ; var nums : Sequence := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var swaps : int := 0 ; var visited : Set := Set{}->union(()) ; for index : Integer.subrange(0, n-1) do ( if (visited)->includes(index) then ( continue ) else ( execute ((index) : visited) ; var length : int := 0 ; var value : OclAny := nums[index+1] ; while (value /= index + 1) do ( execute ((value - 1) : visited) ; value := nums[value - 1+1] ; length := length + 1) ; swaps := swaps + length )) ; if ((3 * n - swaps) mod 2) then ( execute ("Um_nik")->display() ) else ( execute ("Petr")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,flag=int(input()),0 nums=list(map(int,input().split())) nums=[nums[i]-1 for i in range(n)] for i in range(n): if nums[nums[nums[i]]]==i : flag=1 print("YES" if flag else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var flag : OclAny := null; Sequence{n,flag} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),0} ; var nums : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; nums := Integer.subrange(0, n-1)->select(i | true)->collect(i | (nums[i+1] - 1)) ; for i : Integer.subrange(0, n-1) do ( if nums[nums[nums[i+1]+1]+1] = i then ( var flag : int := 1 ) else skip) ; execute (if flag then "YES" else "NO" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[0]+[int(i)for i in input().split()] p=[0]*(n+1) for i in range(1,n+1): p[a[i]]=i cnt=0 for i in range(1,n+1): if(i!=a[i]): cnt+=1 k=a[i] a[i],a[p[i]]=a[p[i]],a[i] p[k],p[a[i]]=p[a[i]],p[k] if((3*n)% 2==cnt % 2): print("Petr") else : print("Um_nik") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{ 0 }->union(input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))) ; var p : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(1, n + 1-1) do ( p[a[i+1]+1] := i) ; var cnt : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( if (i /= a[i+1]) then ( cnt := cnt + 1 ; var k : OclAny := a[i+1] ; var a[i+1] : OclAny := null; var a[p[i+1]+1] : OclAny := null; Sequence{a[i+1],a[p[i+1]+1]} := Sequence{a[p[i+1]+1],a[i+1]} ; var p[k+1] : OclAny := null; var p[a[i+1]+1] : OclAny := null; Sequence{p[k+1],p[a[i+1]+1]} := Sequence{p[a[i+1]+1],p[k+1]} ) else skip) ; if ((3 * n) mod 2 = cnt mod 2) then ( execute ("Petr")->display() ) else ( execute ("Um_nik")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import* from collections import* import sys import io,os import math import random from heapq import* gcd=math.gcd sqrt=math.sqrt def ceil(a,b): a=-a k=a//b k=-k return k input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def strinp(testcases): k=5 if(testcases==-1 or testcases==1): k=1 f=str(input()) f=f[2 : len(f)-k] return f def minSwaps(arr): n=len(arr) vis={} for i in range(n): arr[i]-=1 vis[i]=False ans=0 for i in range(n): if vis[i]or arr[i]==i : continue cycle_size=0 j=i while not vis[j]: vis[j]=True j=arr[j] cycle_size+=1 if cycle_size>0 : ans+=(cycle_size-1) return ans def main(): t=1 for _ in range(t): n=int(input()) arr=list(map(int,input().split())) g=minSwaps(arr) if(3*n>=g and((3*n)-g)% 2==0): print('Petr') else : print('Um_nik') main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var gcd : OclAny := ; var sqrt : OclAny := ; skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; skip ; skip ; skip ; main(); operation ceil(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: a := -a ; var k : int := a div b ; k := -k ; return k; operation strinp(testcases : OclAny) : OclAny pre: true post: true activity: k := 5 ; if (testcases = -1 or testcases = 1) then ( k := 1 ) else skip ; var f : String := ("" + (((OclFile["System.in"]).readLine()))) ; f := f.subrange(2+1, (f)->size() - k) ; return f; operation minSwaps(arr : OclAny) : OclAny pre: true post: true activity: var n : int := (arr)->size() ; var vis : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( arr[i+1] := arr[i+1] - 1 ; vis[i+1] := false) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if vis[i+1] or arr[i+1] = i then ( continue ) else skip ; var cycle_size : int := 0 ; var j : OclAny := i ; while not(vis[j+1]) do ( vis[j+1] := true ; j := arr[j+1] ; cycle_size := cycle_size + 1) ; if cycle_size > 0 then ( ans := ans + (cycle_size - 1) ) else skip) ; return ans; operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; arr := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var g : OclAny := minSwaps(arr) ; if ((3 * n->compareTo(g)) >= 0 & ((3 * n) - g) mod 2 = 0) then ( execute ('Petr')->display() ) else ( execute ('Um_nik')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(('Um_nik','Petr')[int(input())//1000<=sum(i==x for i,x in enumerate(map(int,input().split()),1))]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (Sequence{'Um_nik', 'Petr'}->select((("" + (((OclFile["System.in"]).readLine())))->toInteger() div 1000->compareTo(((argument (test (logical_test (comparison (comparison (expr (atom (name i)))) == (comparison (expr (atom (name x))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))))))->sum())) <= 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def smallest(s): l=len(s) ans="" for i in range(l): if(s[i]>s[i+1]): for j in range(l): if(i!=j): ans+=s[j] return ans ans=s[0 : l-1] return ans if __name__=="__main__" : s="abcda" print(smallest(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "abcda" ; execute (smallest(s))->display() ) else skip; operation smallest(s : OclAny) : OclAny pre: true post: true activity: var l : int := (s)->size() ; var ans : String := "" ; for i : Integer.subrange(0, l-1) do ( if ((s[i+1]->compareTo(s[i + 1+1])) > 0) then ( for j : Integer.subrange(0, l-1) do ( if (i /= j) then ( ans := ans + s[j+1] ) else skip) ; return ans ) else skip) ; ans := s.subrange(0+1, l - 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=map(int,input().split()) gr1=[2] gr2=[4,6,9,11] if x in gr1 : x_gr=1 elif x in gr2 : x_gr=2 else : x_gr=3 if y in gr1 : y_gr=1 elif y in gr2 : y_gr=2 else : y_gr=3 if x_gr==y_gr : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var gr1 : Sequence := Sequence{ 2 } ; var gr2 : Sequence := Sequence{4}->union(Sequence{6}->union(Sequence{9}->union(Sequence{ 11 }))) ; if (gr1)->includes(x) then ( var x_gr : int := 1 ) else (if (gr2)->includes(x) then ( x_gr := 2 ) else ( x_gr := 3 ) ) ; if (gr1)->includes(y) then ( var y_gr : int := 1 ) else (if (gr2)->includes(y) then ( y_gr := 2 ) else ( y_gr := 3 ) ) ; if x_gr = y_gr then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) set1=[1,3,5,7,8,10,12] set2=[4,6,9,11] set3=[2] if a in set1 and b in set1 : print("Yes") exit() if a in set2 and b in set2 : print("Yes") exit() if a in set3 and b in set3 : print("Yes") exit() print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var set1 : Sequence := Sequence{1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{8}->union(Sequence{10}->union(Sequence{ 12 })))))) ; var set2 : Sequence := Sequence{4}->union(Sequence{6}->union(Sequence{9}->union(Sequence{ 11 }))) ; var set3 : Sequence := Sequence{ 2 } ; if (set1)->includes(a) & (set1)->includes(b) then ( execute ("Yes")->display() ; exit() ) else skip ; if (set2)->includes(a) & (set2)->includes(b) then ( execute ("Yes")->display() ; exit() ) else skip ; if (set3)->includes(a) & (set3)->includes(b) then ( execute ("Yes")->display() ; exit() ) else skip ; execute ("No")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys g=[None,1,3,1,2,1,2,1,1,2,1,2,1] x,y=map(int,sys.stdin.readline().split()) def main(): return 'Yes' if g[x]==g[y]else 'No' if __name__=='__main__' : ans=main() print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var g : Sequence := Sequence{null}->union(Sequence{1}->union(Sequence{3}->union(Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 1 })))))))))))) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; if __name__ = '__main__' then ( var ans : OclAny := main() ; execute (ans)->display() ) else skip; operation main() : OclAny pre: true post: true activity: return if g[x+1] = g[y+1] then 'Yes' else 'No' endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import reduce import math def main(): INF=float("inf") a,b=(int(_)for _ in input().split()) l1=[1,3,5,7,8,10,12] l2=[4,6,9,11] if(a in l1 and b in l1)or(a in l2 and b in l2)or(a==2 and b==2): print('Yes') else : print('No') if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var INF : double := ("" + (("inf")))->toReal() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name _)))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var l1 : Sequence := Sequence{1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{8}->union(Sequence{10}->union(Sequence{ 12 })))))) ; var l2 : Sequence := Sequence{4}->union(Sequence{6}->union(Sequence{9}->union(Sequence{ 11 }))) ; if ((l1)->includes(a) & (l1)->includes(b)) or ((l2)->includes(a) & (l2)->includes(b)) or (a = 2 & b = 2) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(): return map(int,input().split()) h,w=f(); print(sum([sum([(x+1)*(w-x)*v for x,v in enumerate(f())])*(y+1)*(h-y)for y in range(h)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := f(); execute ((Integer.subrange(0, h-1)->select(y | true)->collect(y | ((Integer.subrange(1, (f())->size())->collect( _indx | Sequence{_indx-1, (f())->at(_indx)} )->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in ((x + 1) * (w - x) * v)))->sum() * (y + 1) * (h - y))))->sum())->display(); operation f() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=input().split() a=['1','3','5','7','8','10','12'] b=['4','6','9','11'] print('Yes' if(x in a and y in a)or(x in b and y in b)else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := input().split() ; var a : Sequence := Sequence{'1'}->union(Sequence{'3'}->union(Sequence{'5'}->union(Sequence{'7'}->union(Sequence{'8'}->union(Sequence{'10'}->union(Sequence{ '12' })))))) ; var b : Sequence := Sequence{'4'}->union(Sequence{'6'}->union(Sequence{'9'}->union(Sequence{ '11' }))) ; execute (if ((a)->includes(x) & (a)->includes(y)) or ((b)->includes(x) & (b)->includes(y)) then 'Yes' else 'No' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def FindMinNumber(arr,n,k): i=0 j=0 min_num=10**9 found=False Sum=0 while(ik): while(Sum>k): Sum=Sum-arr[j] j+=1 if(Sum==k): min_num=min(min_num,((n-(i+1))+j)) found=True i+=1 if(found): return min_num return-1 arr=[1,3,2,5,6] n=len(arr) k=5 print(FindMinNumber(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{3}->union(Sequence{2}->union(Sequence{5}->union(Sequence{ 6 })))) ; n := (arr)->size() ; k := 5 ; execute (FindMinNumber(arr, n, k))->display(); operation FindMinNumber(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; var j : int := 0 ; var min_num : double := (10)->pow(9) ; var found : boolean := false ; var Sum : int := 0 ; while ((i->compareTo(n)) < 0) do ( Sum := Sum + arr[i+1] ; if (Sum = k) then ( min_num := Set{min_num, ((n - (i + 1)) + j)}->min() ; found := true ) else (if ((Sum->compareTo(k)) > 0) then ( while ((Sum->compareTo(k)) > 0) do ( Sum := Sum - arr[j+1] ; j := j + 1) ; if (Sum = k) then ( min_num := Set{min_num, ((n - (i + 1)) + j)}->min() ; found := true ) else skip ) else skip) ; i := i + 1) ; if (found) then ( return min_num ) else skip ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) l=list(map(int,(input().split()))) found=False for i in range(len(l)): start=l[i]-1 count=0 while count<2 : start=l[start]-1 count+=1 if start==i : found=True print("YES") break if not found : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := (((input().split()))->collect( _x | (OclType["int"])->apply(_x) )) ; var found : boolean := false ; for i : Integer.subrange(0, (l)->size()-1) do ( var start : double := l[i+1] - 1 ; var count : int := 0 ; while count < 2 do ( start := l[start+1] - 1 ; count := count + 1) ; if start = i then ( found := true ; execute ("YES")->display() ; break ) else skip) ; if not(found) then ( execute ("NO")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() b=0 for i in range(3): if n[i]=="1" : b+=1 print(b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var b : int := 0 ; for i : Integer.subrange(0, 3-1) do ( if n[i+1] = "1" then ( b := b + 1 ) else skip) ; execute (b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin inf=1<<60 mod=1000000007 ni=lambda : int(ns()) nin=lambda y :[ni()for _ in range(y)] na=lambda : list(map(int,stdin.readline().split())) nan=lambda y :[na()for _ in range(y)] nf=lambda : float(ns()) nfn=lambda y :[nf()for _ in range(y)] nfa=lambda : list(map(float,stdin.readline().split())) nfan=lambda y :[nfa()for _ in range(y)] ns=lambda : stdin.readline().rstrip() nsn=lambda y :[ns()for _ in range(y)] ncl=lambda y :[list(ns())for _ in range(y)] nas=lambda : stdin.readline().split() s=ns() ans=0 for i in range(len(s)): if s[i]=='1' : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stdin : OclFile := OclFile["System.in"] ; var Math_PINFINITY : int := 1 * (2->pow(60)) ; var mod : int := 1000000007 ; var ni : Function := lambda $$ : OclAny in (("" + ((ns())))->toInteger()) ; var nin : Function := lambda y : OclAny in (Integer.subrange(0, y-1)->select(_anon | true)->collect(_anon | (ni->apply()))) ; var na : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var Math_NaN : Function := lambda y : OclAny in (Integer.subrange(0, y-1)->select(_anon | true)->collect(_anon | (na->apply()))) ; var nf : Function := lambda $$ : OclAny in (("" + ((ns())))->toReal()) ; var nfn : Function := lambda y : OclAny in (Integer.subrange(0, y-1)->select(_anon | true)->collect(_anon | (nf->apply()))) ; var nfa : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ))) ; var nfan : Function := lambda y : OclAny in (Integer.subrange(0, y-1)->select(_anon | true)->collect(_anon | (nfa->apply()))) ; var ns : Function := lambda $$ : OclAny in (stdin.readLine().rstrip()) ; var nsn : Function := lambda y : OclAny in (Integer.subrange(0, y-1)->select(_anon | true)->collect(_anon | (ns->apply()))) ; var ncl : Function := lambda y : OclAny in (Integer.subrange(0, y-1)->select(_anon | true)->collect(_anon | ((ns->apply())))) ; var nas : Function := lambda $$ : OclAny in (stdin.readLine().split()) ; var s : OclAny := ns->apply() ; var ans : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = '1' then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- binDigit=[int(num)for num in list(input())] sumNum=sum(binDigit) print(sumNum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var binDigit : Sequence := ((OclFile["System.in"]).readLine())->characters()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var sumNum : OclAny := (binDigit)->sum() ; execute (sumNum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(input().count("1")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (input()->count("1"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): ans_list=list(str(input().split())) print(ans_list.count("1")) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var ans_list : Sequence := (("" + ((input().split()))))->characters() ; execute (ans_list->count("1"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthPalindrome(n,k): if(k & 1): temp=k//2 else : temp=k//2-1 palindrome=10**temp palindrome=palindrome+n-1 print(palindrome,end="") if(k & 1): palindrome=palindrome//10 while(palindrome): print(palindrome % 10,end="") palindrome=palindrome//10 if __name__=='__main__' : n=6 k=5 print(n,"th palindrome of",k," digit=",end=" ") nthPalindrome(n,k) print() n=10 k=6 print(n,"th palindrome of",k,"digit=",end=" ") nthPalindrome(n,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 6 ; k := 5 ; execute (n)->display() ; nthPalindrome(n, k) ; execute (->display() ; n := 10 ; k := 6 ; execute (n)->display() ; nthPalindrome(n, k) ) else skip; operation nthPalindrome(n : OclAny, k : OclAny) pre: true post: true activity: if (MathLib.bitwiseAnd(k, 1)) then ( var temp : int := k div 2 ) else ( temp := k div 2 - 1 ) ; var palindrome : double := (10)->pow(temp) ; palindrome := palindrome + n - 1 ; execute (palindrome)->display() ; if (MathLib.bitwiseAnd(k, 1)) then ( palindrome := palindrome div 10 ) else skip ; while (palindrome) do ( execute (palindrome mod 10)->display() ; palindrome := palindrome div 10); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import array from bisect import* from collections import* import fractions import heapq from itertools import* import math import random import re import string import sys N,X=map(int,input().split()) Xs=list(map(int,input().split())) Ys=Xs[: :-1] Y_sum=[0]*N Y_sum[0]=Ys[0] for i in range(1,N): Y_sum[i]=Y_sum[i-1]+Ys[i] ans=1e100 for rep_num in range(1,N+1): local_ans=X*rep_num local_ans+=5*Y_sum[rep_num-1] i=2*rep_num-1 n=1 while i<=N-1 : local_ans+=(2*n+3)*(Y_sum[i]-Y_sum[i-rep_num]) n+=1 i+=rep_num local_ans+=(2*n+3)*(Y_sum[N-1]-Y_sum[i-rep_num]) ans=min(ans,local_ans) print(ans+N*X) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var N : OclAny := null; var X : OclAny := null; Sequence{N,X} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var Xs : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var Ys : OclAny := Xs(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var Y_sum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; Y_sum->first() := Ys->first() ; for i : Integer.subrange(1, N-1) do ( Y_sum[i+1] := Y_sum[i - 1+1] + Ys[i+1]) ; var ans : double := ("1e100")->toReal() ; for rep_num : Integer.subrange(1, N + 1-1) do ( var local_ans : double := X * rep_num ; local_ans := local_ans + 5 * Y_sum[rep_num - 1+1] ; var i : double := 2 * rep_num - 1 ; var n : int := 1 ; while (i->compareTo(N - 1)) <= 0 do ( local_ans := local_ans + (2 * n + 3) * (Y_sum[i+1] - Y_sum[i - rep_num+1]) ; n := n + 1 ; i := i + rep_num) ; local_ans := local_ans + (2 * n + 3) * (Y_sum[N - 1+1] - Y_sum[i - rep_num+1]) ; ans := Set{ans, local_ans}->min()) ; execute (ans + N * X)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) L=[list(map(int,input().split()))for _ in range(n)] for i,X in enumerate(L): for j,Y in enumerate(X): if Y==1 or any(Y-L[t][j]in X for t in range(n)): continue print('NO') exit() print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var L : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for _tuple : Integer.subrange(1, (L)->size())->collect( _indx | Sequence{_indx-1, (L)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var X : OclAny := _tuple->at(_indx); for _tuple : Integer.subrange(1, (X)->size())->collect( _indx | Sequence{_indx-1, (X)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Y : OclAny := _tuple->at(_indx); if Y = 1 or ((argument (test (logical_test (comparison (comparison (expr (expr (atom (name Y))) - (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))) in (comparison (expr (atom (name X))))))) (comp_for for (exprlist (expr (atom (name t)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->exists( _x | _x = true ) then ( continue ) else skip ; execute ('NO')->display() ; exit())) ; execute ('YES')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque import sys,heapq,bisect,math,itertools,string,queue,datetime sys.setrecursionlimit(10**8) INF=float('inf') mod=10**9+7 def inpl(): return list(map(int,input().split())) def inpls(): return list(input().split()) N,X=inpl() xx=inpl() sum_xx=[0] tmp=0 for x in xx : tmp+=x sum_xx.append(tmp) ans=INF for k in range(1,N+1): tmp=X*(k+N) i=0 l=N-k r=N while True : if i<=1 : cost=5 else : cost=3+i*2 if l>=0 : tmp+=(sum_xx[r]-sum_xx[l])*cost else : tmp+=(sum_xx[r]-sum_xx[0])*cost break l-=k r-=k i+=1 ans=min(ans,tmp) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; var N : OclAny := null; var X : OclAny := null; Sequence{N,X} := inpl() ; var xx : OclAny := inpl() ; var sum_xx : Sequence := Sequence{ 0 } ; var tmp : int := 0 ; for x : xx do ( tmp := tmp + x ; execute ((tmp) : sum_xx)) ; var ans : OclAny := INF ; for k : Integer.subrange(1, N + 1-1) do ( tmp := X * (k + N) ; var i : int := 0 ; var l : double := N - k ; var r : OclAny := N ; while true do ( if i <= 1 then ( var cost : int := 5 ) else ( cost := 3 + i * 2 ) ; if l >= 0 then ( tmp := tmp + (sum_xx[r+1] - sum_xx[l+1]) * cost ) else ( tmp := tmp + (sum_xx[r+1] - sum_xx->first()) * cost ; break ) ; l := l - k ; r := r - k ; i := i + 1) ; ans := Set{ans, tmp}->min()) ; execute (ans)->display(); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inpls() : OclAny pre: true post: true activity: return (input().split()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate N,X,*A=map(int,open(0).read().split()) S=list(accumulate(A)) ans=float("inf") for k,s in enumerate(S,1): E=k*X+2*sum(S[j]for j in range(N-2*k-1,-1,-k)) ans=min(ans,E) print(ans+N*X+5*S[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var X : OclAny := null; var A : OclAny := null; Sequence{N,X,A} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : Sequence := (accumulate(A)) ; var ans : double := ("" + (("inf")))->toReal() ; for _tuple : Integer.subrange(1, (S, 1)->size())->collect( _indx | Sequence{_indx-1, (S, 1)->at(_indx)} ) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); var E : double := k * X + 2 * ((argument (test (logical_test (comparison (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name N))) - (expr (expr (atom (number (integer 2)))) * (expr (atom (name k))))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom - (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr - (expr (atom (name k))))))))) )))))))))->sum() ; ans := Set{ans, E}->min()) ; execute (ans + N * X + 5 * S->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- iN,iX=[int(x)for x in input().split()] aCum=[0] for x in input().split(): aCum+=[aCum[-1]+int(x)] def fCeil(iT,iR): return-1*iT//iR*-1 def fCalcCost(iN,iX,aCum,iK): iCost=(iN+iK)*iX+5*aCum[iN] for i in range(2,fCeil(iN,iK)): iCost+=2*aCum[iN-i*iK] return iCost if 1select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var aCum : Sequence := Sequence{ 0 } ; for x : input().split() do ( aCum := aCum + Sequence{ aCum->last() + ("" + ((x)))->toInteger() }) ; skip ; skip ; if 1 < iN then ( var iULim : OclAny := fCeil(iN, 2) + 1 ; var iLLim : int := 1 ; skip ; execute (fSearchLowCost(iLLim, fCalcCost(iN, iX, aCum, iLLim), iULim, fCalcCost(iN, iX, aCum, iULim), iN, iX, aCum))->display() ) else ( execute (2 * iX + 5 * aX->first())->display() ); operation fCeil(iT : OclAny, iR : OclAny) : OclAny pre: true post: true activity: return -1 * iT div iR * -1; operation fCalcCost(iN : OclAny, iX : OclAny, aCum : OclAny, iK : OclAny) : OclAny pre: true post: true activity: var iCost : double := (iN + iK) * iX + 5 * aCum[iN+1] ; for i : Integer.subrange(2, fCeil(iN, iK)-1) do ( iCost := iCost + 2 * aCum[iN - i * iK+1]) ; return iCost; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) success=False for i in range(n): loved=i for j in range(3): loved=arr[loved-1] if i==loved : success=True if success : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var success : boolean := false ; for i : Integer.subrange(0, n-1) do ( var loved : OclAny := i ; for j : Integer.subrange(0, 3-1) do ( loved := arr[loved - 1+1]) ; if i = loved then ( success := true ) else skip) ; if success then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,p=[int(i)for i in input().split()] X=[int(i)for i in input().split()] ans=[] S=[0] for x in X : S.append(S[-1]+x) for t in range(1,n+1): cur=n-t time=5 tmp=time*(S[-1]-S[cur])+(t+n)*p cur-=t while True : tmp+=time*(S[cur+t]-S[max(0,cur)]) if cur<=0 : break cur-=t time+=2 ans.append(tmp) print(min(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var X : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : Sequence := Sequence{} ; var S : Sequence := Sequence{ 0 } ; for x : X do ( execute ((S->last() + x) : S)) ; for t : Integer.subrange(1, n + 1-1) do ( var cur : double := n - t ; var time : int := 5 ; var tmp : double := time * (S->last() - S[cur+1]) + (t + n) * p ; cur := cur - t ; while true do ( tmp := tmp + time * (S[cur + t+1] - S[Set{0, cur}->max()+1]) ; if cur <= 0 then ( break ) else skip ; cur := cur - t ; time := time + 2) ; execute ((tmp) : ans)) ; execute ((ans)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=10000 hashTable=[0]*MAX def minOperations(arr,n): arr.sort() for i in range(n): hashTable[arr[i]]+=1 res=0 for i in range(n): if(hashTable[arr[i]]): for j in range(i,n): if(arr[j]% arr[i]==0): hashTable[arr[j]]=0 res+=1 return res if __name__=="__main__" : arr=[4,6,2,8,7,21,24,49,44] n=len(arr) print(minOperations(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 10000 ; var hashTable : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX) ; skip ; if __name__ = "__main__" then ( arr := Sequence{4}->union(Sequence{6}->union(Sequence{2}->union(Sequence{8}->union(Sequence{7}->union(Sequence{21}->union(Sequence{24}->union(Sequence{49}->union(Sequence{ 44 })))))))) ; n := (arr)->size() ; execute (minOperations(arr, n))->display() ) else skip; operation minOperations(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; for i : Integer.subrange(0, n-1) do ( hashTable[arr[i+1]+1] := hashTable[arr[i+1]+1] + 1) ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (hashTable[arr[i+1]+1]) then ( for j : Integer.subrange(i, n-1) do ( if (arr[j+1] mod arr[i+1] = 0) then ( hashTable[arr[j+1]+1] := 0 ) else skip) ; res := res + 1 ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p1,p2,p3,p4,a,b=map(int,input().split()) if min(p1,p2,p3,p4)>a and min(p1,p2,p3,p4)<=b : print(min(p1,p2,p3,p4)-a) elif min(p1,p2,p3,p4)>b and min(p1,p2,p3,p4)>a and a!=b : print(b-a+1) elif a==b and min(p1,p2,p3,p4)>a : print(min(p1,p2,p3,p4)-a) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p1 : OclAny := null; var p2 : OclAny := null; var p3 : OclAny := null; var p4 : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{p1,p2,p3,p4,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (Set{p1, p2, p3, p4}->min()->compareTo(a)) > 0 & (Set{p1, p2, p3, p4}->min()->compareTo(b)) <= 0 then ( execute (Set{p1, p2, p3, p4}->min() - a)->display() ) else (if (Set{p1, p2, p3, p4}->min()->compareTo(b)) > 0 & (Set{p1, p2, p3, p4}->min()->compareTo(a)) > 0 & a /= b then ( execute (b - a + 1)->display() ) else (if a = b & (Set{p1, p2, p3, p4}->min()->compareTo(a)) > 0 then ( execute (Set{p1, p2, p3, p4}->min() - a)->display() ) else ( execute (0)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def func(): *lst,a,b=map(int,input().strip().split()) count=0 for i in range(a,b+1): for item in lst : if i % item!=i : break else : count+=1 return count if __name__=='__main__' : ans=func() print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var ans : OclAny := func() ; execute (ans)->display() ) else skip; operation func() pre: true post: true activity: ; var lst : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{lst,a,b} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var count : int := 0 ; for i : Integer.subrange(a, b + 1-1) do ((compound_stmt for (exprlist (expr (atom (name item)))) in (testlist (test (logical_test (comparison (expr (atom (name lst))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name i))) % (expr (atom (name item))))) != (comparison (expr (atom (name i))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name count)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))))) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- *l,a,b=map(int,input().split()) print(max(0,min(b+1,*l)-a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{l,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{0, Set{b + 1, (argument * (test (logical_test (comparison (expr (atom (name l)))))))}->min() - a}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inp=lambda : list(map(int,input().split())) *p,a,b=inp() m=min(p) if mcollect( _x | (OclType["int"])->apply(_x) ))) ; var p : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{p,a,b} := inp->apply() ; var m : OclAny := (p)->min() ; if (m->compareTo(a)) < 0 then ( execute (0)->display() ) else ( if (b->compareTo(m)) < 0 then ( execute (b - a + 1)->display() ) else ( execute (m - a)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): s=[int(i)for i in input().split()] res="YES" if max(s[: 2])+max(s[2 :])==sum(sorted(s)[2 :])else "NO" print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var s : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var res : String := if (s.subrange(1,2))->max() + (s.subrange(2+1))->max() = (sorted(s).subrange(2+1))->sum() then "YES" else "NO" endif ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline p1,p2,p3,p4,a,b=map(int,input().split()) c=0 for i in range(a,b+1): if i % p1 % p2 % p3 % p4==i : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var p1 : OclAny := null; var p2 : OclAny := null; var p3 : OclAny := null; var p4 : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{p1,p2,p3,p4,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : int := 0 ; for i : Integer.subrange(a, b + 1-1) do ( if i mod p1 mod p2 mod p3 mod p4 = i then ( c := c + 1 ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import fractions def compute(): numer=1 denom=1 for d in range(10,100): for n in range(10,d): n0=n % 10 n1=n//10 d0=d % 10 d1=d//10 if(n1==d0 and n0*d==n*d1)or(n0==d1 and n1*d==n*d0): numer*=n denom*=d return str(denom//fractions.gcd(numer,denom)) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var numer : int := 1 ; var denom : int := 1 ; for d : Integer.subrange(10, 100-1) do ( for n : Integer.subrange(10, d-1) do ( var n0 : int := n mod 10 ; var n1 : int := n div 10 ; var d0 : int := d mod 10 ; var d1 : int := d div 10 ; if (n1 = d0 & n0 * d = n * d1) or (n0 = d1 & n1 * d = n * d0) then ( numer := numer * n ; denom := denom * d ) else skip)) ; return ("" + ((denom div fractions.gcd(numer, denom)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSetBits(n): count=0 while n : count+=n & 1 n>>=1 return count def countOfOddPascal(n): c=countSetBits(n) return pow(2,c) n=20 print(countOfOddPascal(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 20 ; execute (countOfOddPascal(n))->display(); operation countSetBits(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while n do ( count := count + MathLib.bitwiseAnd(n, 1) ; n := n div (2->pow(1))) ; return count; operation countOfOddPascal(n : OclAny) : OclAny pre: true post: true activity: var c : OclAny := countSetBits(n) ; return (2)->pow(c); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in[0]*int(input()): a,b,x,y=map(int,input().split()); print(max(b*x,b*(a-x-1),a*y,a*(b-y-1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var a : OclAny := null; var b : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{a,b,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); execute (Set{b * x, b * (a - x - 1), a * y, a * (b - y - 1)}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nextZero(i,occurrences): while i<26 : if occurrences[i]==0 : return i i+=1 return-1 def getModifiedString(str): n=len(str) if n>26 : return "-1" ch=str ch=list(ch) occurrences=[0]*26 for i in range(n): occurrences[ord(ch[i])-ord('a')]+=1 index=nextZero(0,occurrences) for i in range(n): if occurrences[ord(ch[i])-ord('a')]>1 : occurrences[ord(ch[i])-ord('a')]-=1 ch[i]=chr(ord('a')+index) occurrences[index]=1 index=nextZero(index+1,occurrences) ch=''.join(ch) print(ch) if __name__=="__main__" : str="geeksforgeeks" getModifiedString(str) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( OclType["String"] := "geeksforgeeks" ; getModifiedString(OclType["String"]) ) else skip; operation nextZero(i : OclAny, occurrences : OclAny) : OclAny pre: true post: true activity: while i < 26 do ( if occurrences[i+1] = 0 then ( return i ) else skip ; i := i + 1) ; return -1; operation getModifiedString(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var n : int := (OclType["String"])->size() ; if n > 26 then ( return "-1" ) else skip ; var ch : String := OclType["String"] ; ch := (ch)->characters() ; occurrences := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for i : Integer.subrange(0, n-1) do ( occurrences[(ch[i+1])->char2byte() - ('a')->char2byte()+1] := occurrences[(ch[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; var index : OclAny := nextZero(0, occurrences) ; for i : Integer.subrange(0, n-1) do ( if occurrences[(ch[i+1])->char2byte() - ('a')->char2byte()+1] > 1 then ( occurrences[(ch[i+1])->char2byte() - ('a')->char2byte()+1] := occurrences[(ch[i+1])->char2byte() - ('a')->char2byte()+1] - 1 ; ch[i+1] := (('a')->char2byte() + index)->byte2char() ; occurrences[index+1] := 1 ; index := nextZero(index + 1, occurrences) ) else skip) ; ch := StringLib.sumStringsWithSeparator((ch), '') ; execute (ch)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b,x,y=map(int,input().split()) a1=x*b a2=b*(a-x-1) a3=a*y a4=a*(b-y-1) print(max(a1,a2,a3,a4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{a,b,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a1 : double := x * b ; var a2 : double := b * (a - x - 1) ; var a3 : double := a * y ; var a4 : double := a * (b - y - 1) ; execute (Set{a1, a2, a3, a4}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in " "*int(input()): a,b,c,d=map(int,input().split()); print(max(a*d,b*c,(a*(b-d-1)),(b*(a-c-1)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : StringLib.nCopies(" ", ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); execute (Set{a * d, b * c, (a * (b - d - 1)), (b * (a - c - 1))}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): a,b,x,y=input().split(" ") a=int(a); b=int(b); x=int(x); y=int(y) x+=1 y+=1 aa=a*(y-1) bb=a*abs(b-y) cc=b*(x-1) dd=b*abs(a-x) ans=max(aa,bb) ans=max(ans,cc) ans=max(ans,dd) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{a,b,x,y} := input().split(" ") ; var a : int := ("" + ((a)))->toInteger(); var b : int := ("" + ((b)))->toInteger(); var x : int := ("" + ((x)))->toInteger(); var y : int := ("" + ((y)))->toInteger() ; x := x + 1 ; y := y + 1 ; var aa : double := a * (y - 1) ; var bb : double := a * (b - y)->abs() ; var cc : double := b * (x - 1) ; var dd : double := b * (a - x)->abs() ; var ans : OclAny := Set{aa, bb}->max() ; ans := Set{ans, cc}->max() ; ans := Set{ans, dd}->max() ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t=int(input()) ans=[] for _ in range(t): a,b,x,y=map(int,input().split()) ans0=max(max(x,a-x-1)*b,max(y,b-y-1)*a) ans.append(ans0) sys.stdout.write("\n".join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{a,b,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans0 : OclAny := Set{Set{x, a - x - 1}->max() * b, Set{y, b - y - 1}->max() * a}->max() ; execute ((ans0) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minSwaps(arr): n=len(arr) arrpos=[*enumerate(arr)] arrpos.sort(key=lambda it : it[1]) vis={k : False for k in range(n)} ans=0 for i in range(n): if vis[i]or arrpos[i][0]==i : continue cycle_size=0 j=i while not vis[j]: vis[j]=True j=arrpos[j][0] cycle_size+=1 if cycle_size>0 : ans+=(cycle_size-1) return ans arr=[1,5,4,3,2] print(minSwaps(arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{5}->union(Sequence{4}->union(Sequence{3}->union(Sequence{ 2 })))) ; execute (minSwaps(arr))->display(); operation minSwaps(arr : OclAny) : OclAny pre: true post: true activity: var n : int := (arr)->size() ; var arrpos : Sequence := Integer.subrange(1, (arr)->size())->collect( _indx | Sequence{_indx-1, (arr)->at(_indx)} ) ; arrpos := arrpos->sort() ; var vis : Map := Integer.subrange(0, n-1)->select(k | true)->collect(k | Map{k |-> false})->unionAll() ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if vis[i+1] or arrpos[i+1]->first() = i then ( continue ) else skip ; var cycle_size : int := 0 ; var j : OclAny := i ; while not(vis[j+1]) do ( vis[j+1] := true ; j := arrpos[j+1]->first() ; cycle_size := cycle_size + 1) ; if cycle_size > 0 then ( ans := ans + (cycle_size - 1) ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) sumL=[0]*(n+2) L=1 sumL[-2]=1 for i in range(n-1,0,-1): L=sumL[i+1] j=2 while i*j<=n : L+=(sumL[i*j]-sumL[min(n,(i+1)*j-1)+1]) L %=m j+=1 L %=m sumL[i]=(sumL[i+1]+L) sumL[i]%=m print(L) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sumL : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 2)) ; var L : int := 1 ; sumL->front()->last() := 1 ; for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( L := sumL[i + 1+1] ; var j : int := 2 ; while (i * j->compareTo(n)) <= 0 do ( L := L + (sumL[i * j+1] - sumL[Set{n, (i + 1) * j - 1}->min() + 1+1]) ; L := L mod m ; j := j + 1) ; L := L mod m ; sumL[i+1] := (sumL[i + 1+1] + L) ; sumL[i+1] := sumL[i+1] mod m) ; execute (L)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[list(map(int,input().split()))for i in range(n)] for i in range(n): for j in range(n): if a[i][j]!=1 : for t in range(n): if abs(a[i][j]-a[t][j])in a[i]: break else : print("NO") exit() print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if a[i+1][j+1] /= 1 then ( (compound_stmt for (exprlist (expr (atom (name t)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))) - (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))))) ))))) in (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name exit)) (trailer (arguments ( ))))))))))))))) ) else skip)) ; execute ("YES")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=1000005 prime=[True for i in range(N)] def sieve(): prime[1]=False prime[0]=False for i in range(2,N): if(prime[i]==True): for j in range(i*2,N,i): prime[j]=False def sumTruncatablePrimes(n): sum=0 for i in range(2,n): num=i flag=True while(num): if(prime[num]==False): flag=False break num//=10 num=i power=10 while(num//power): if(prime[num % power]==False): flag=False break power*=10 if(flag==True): sum+=i return sum n=25 sieve() print(sumTruncatablePrimes(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 1000005 ; var prime : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (true)) ; skip ; skip ; n := 25 ; sieve() ; execute (sumTruncatablePrimes(n))->display(); operation sieve() pre: true post: true activity: prime[1+1] := false ; prime->first() := false ; for i : Integer.subrange(2, N-1) do ( if (prime[i+1] = true) then ( for j : Integer.subrange(i * 2, N-1)->select( $x | ($x - i * 2) mod i = 0 ) do ( prime[j+1] := false) ) else skip); operation sumTruncatablePrimes(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(2, n-1) do ( var num : OclAny := i ; var flag : boolean := true ; while (num) do ( if (prime[num+1] = false) then ( flag := false ; break ) else skip ; num := num div 10) ; num := i ; var power : int := 10 ; while (num div power) do ( if (prime[num mod power+1] = false) then ( flag := false ; break ) else skip ; power := power * 10) ; if (flag = true) then ( sum := sum + i ) else skip) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findWeights(X): sum=0 power=0 while(sumcompareTo(X)) < 0) do ( sum := (3)->pow(power + 1) - 1 ; sum := sum div 2 ; power := power + 1) ; var ans : int := 1 ; for i : Integer.subrange(1, power + 1-1) do ( execute (ans)->display() ; ans := ans * 3); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def addToArrayForm(A,K): v,ans=[],[] rem,i=0,0 for i in range(len(A)-1,-1,-1): my=A[i]+(K % 10)+rem if my>9 : rem=1 v.append(my % 10) else : v.append(my) rem=0 K=K//10 while K>0 : my=(K % 10)+rem v.append(my % 10) if my//10>0 : rem=1 else : rem=0 K=K//10 if rem>0 : v.append(rem) for i in range(len(v)-1,-1,-1): ans.append(v[i]) return ans if __name__=="__main__" : A=[2,7,4] K=181 ans=addToArrayForm(A,K) for i in range(0,len(ans)): print(ans[i],end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( A := Sequence{2}->union(Sequence{7}->union(Sequence{ 4 })) ; K := 181 ; var ans : OclAny := addToArrayForm(A, K) ; for i : Integer.subrange(0, (ans)->size()-1) do ( execute (ans[i+1])->display()) ) else skip; operation addToArrayForm(A : OclAny, K : OclAny) : OclAny pre: true post: true activity: var v : OclAny := null; var ans : OclAny := null; Sequence{v,ans} := Sequence{Sequence{},Sequence{}} ; var rem : OclAny := null; var i : OclAny := null; Sequence{rem,i} := Sequence{0,0} ; for i : Integer.subrange(-1 + 1, (A)->size() - 1)->reverse() do ( var my : OclAny := A[i+1] + (K mod 10) + rem ; if my > 9 then ( var rem : int := 1 ; execute ((my mod 10) : v) ) else ( execute ((my) : v) ; rem := 0 ) ; K := K div 10) ; while K > 0 do ( my := (K mod 10) + rem ; execute ((my mod 10) : v) ; if my div 10 > 0 then ( rem := 1 ) else ( rem := 0 ) ; K := K div 10) ; if rem > 0 then ( execute ((rem) : v) ) else skip ; for i : Integer.subrange(-1 + 1, (v)->size() - 1)->reverse() do ( execute ((v[i+1]) : ans)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printPaths(inputchar,R,C): for i in range(C): dfs(inputchar,"",0,i,R,C); print() def dfs(inputchar,res,i,j,R,C): if(i==R): print(res,end=" "); return ; res=res+inputchar[i][j]; for k in range(C): dfs(inputchar,res,i+1,k,R,C); if(i+1==R): break ; if __name__=="__main__" : inputchar=[['a','b'],['d','e']]; R=len(inputchar); C=len(inputchar[0]); printPaths(inputchar,R,C); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( inputchar := Sequence{Sequence{'a'}->union(Sequence{ 'b' })}->union(Sequence{ Sequence{'d'}->union(Sequence{ 'e' }) }); ; R := (inputchar)->size(); ; C := (inputchar->first())->size(); ; printPaths(inputchar, R, C); ) else skip; operation printPaths(inputchar : OclAny, R : OclAny, C : OclAny) pre: true post: true activity: for i : Integer.subrange(0, C-1) do ( dfs(inputchar, "", 0, i, R, C); ; execute (->display()); operation dfs(inputchar : OclAny, res : OclAny, i : OclAny, j : OclAny, R : OclAny, C : OclAny) : OclAny pre: true post: true activity: if (i = R) then ( execute (res)->display(); ; return; ) else skip ; res := res + inputchar[i+1][j+1]; ; for k : Integer.subrange(0, C-1) do ( dfs(inputchar, res, i + 1, k, R, C); ; if (i + 1 = R) then ( break; ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def assign_room(direction,hotel): if direction=="L" : for x in range(10): if hotel[x]==0 : hotel[x]="1" return hotel elif direction=="R" : for x in range(9,-1,-1): if hotel[x]==0 : hotel[x]="1" return hotel else : hotel[int(direction)]=0 return hotel rooms=[0]*10 n=int(input("")) instructions=input("") for x in instructions : assign_room(x,rooms) for x in rooms : print(x,end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var rooms : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; var n : int := ("" + (((OclFile["System.in"]).readLine(""))))->toInteger() ; var instructions : String := (OclFile["System.in"]).readLine("") ; for x : instructions->characters() do ( assign_room(x, rooms)) ; for x : rooms do ( execute (x)->display()); operation assign_room(direction : OclAny, hotel : OclAny) : OclAny pre: true post: true activity: if direction = "L" then ( for x : Integer.subrange(0, 10-1) do ( if hotel[x+1] = 0 then ( hotel[x+1] := "1" ; return hotel ) else skip) ) else (if direction = "R" then ( for x : Integer.subrange(-1 + 1, 9)->reverse() do ( if hotel[x+1] = 0 then ( hotel[x+1] := "1" ; return hotel ) else skip) ) else ( hotel[("" + ((direction)))->toInteger()+1] := 0 ; return hotel ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def is_correct(hourMax,minuteMax,time): h,m=time.split(":") mirrored={"0":"0","1":"1","2":"5","3":"","4":"","5":"2","6":"","7":"","8":"8","9":""} mirrored_h=mirrored[h[1]]+mirrored[h[0]] mirrored_m=mirrored[m[1]]+mirrored[m[0]] if len(mirrored_h)==2 and int(mirrored_h)toInteger() ; for _anon : Integer.subrange(0, N-1) do ( Sequence{hourMax,minuteMax} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var hourNow : OclAny := null; var minuteNow : OclAny := null; Sequence{hourNow,minuteNow} := (input().split(":"))->collect( _x | (OclType["int"])->apply(_x) ) ; var result : String := "00:00" ; var flag : boolean := false ; for hour : Integer.subrange(hourNow, hourMax-1) do ( var start : OclAny := if hour = hourNow then minuteNow else 0 endif ; for minute : Integer.subrange(start, minuteMax-1) do ( time := StringLib.nCopies("0", (2 - (("" + ((hour))))->size())) + ("" + ((hour))) + ":" + StringLib.nCopies("0", (2 - (("" + ((minute))))->size())) + ("" + ((minute))) ; mirrored := is_correct(hourMax, minuteMax, time) ; if mirrored then ( result := time ; flag := true ; break ) else skip) ; if flag then ( break ) else skip) ; execute (result)->display()); operation is_correct(hourMax : OclAny, minuteMax : OclAny, time : OclAny) : OclAny pre: true post: true activity: var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := time.split(":") ; var mirrored : Map := Map{ "0" |-> "0" }->union(Map{ "1" |-> "1" }->union(Map{ "2" |-> "5" }->union(Map{ "3" |-> "" }->union(Map{ "4" |-> "" }->union(Map{ "5" |-> "2" }->union(Map{ "6" |-> "" }->union(Map{ "7" |-> "" }->union(Map{ "8" |-> "8" }->union(Map{ "9" |-> "" }))))))))) ; var mirrored_h : OclAny := mirrored[h[1+1]+1] + mirrored[h->first()+1] ; var mirrored_m : OclAny := mirrored[m[1+1]+1] + mirrored[m->first()+1] ; if (mirrored_h)->size() = 2 & (("" + ((mirrored_h)))->toInteger()->compareTo(minuteMax)) < 0 & (mirrored_m)->size() = 2 & (("" + ((mirrored_m)))->toInteger()->compareTo(hourMax)) < 0 then ( return mirrored_m + ":" + mirrored_h ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from os import sep n=int(input()) x=[i for i in input()] y=[0 for i in range(10)] for i in range(n): if x[i]=="L" : y[y.index(0)]=1 elif x[i]=="R" : y[~ y[: :-1].index(0)]=1 else : y[int(x[i])]=0 print(*y,sep="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := (OclFile["System.in"]).readLine()->select(i | true)->collect(i | (i)) ; var y : Sequence := Integer.subrange(0, 10-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( if x[i+1] = "L" then ( y[y->indexOf(0) - 1+1] := 1 ) else (if x[i+1] = "R" then ( y[MathLib.bitwiseNot(y(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->indexOf(0) - 1)+1] := 1 ) else ( y[("" + ((x[i+1])))->toInteger()+1] := 0 ) ) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name y))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) data=input() memo=[False]*10 for i in data : if i=='L' : for j in range(10): if not memo[j]: memo[j]=True break elif i=='R' : for j in range(9,-1,-1): if not memo[j]: memo[j]=True break else : memo[int(i)]=False print("".join(['1' if i else '0' for i in memo])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var data : String := (OclFile["System.in"]).readLine() ; var memo : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, 10) ; for i : data->characters() do ( if i = 'L' then ( for j : Integer.subrange(0, 10-1) do ( if not(memo[j+1]) then ( memo[j+1] := true ; break ) else skip) ) else (if i = 'R' then ( for j : Integer.subrange(-1 + 1, 9)->reverse() do ( if not(memo[j+1]) then ( memo[j+1] := true ; break ) else skip) ) else ( memo[("" + ((i)))->toInteger()+1] := false ) ) ) ; execute (StringLib.sumStringsWithSeparator((memo->select(i | true)->collect(i | (if i then '1' else '0' endif))), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) events=input() room_status=[0]*10 for e in events : if e=='L' : l=0 while(room_status[l]): l+=1 room_status[l]=1 continue if e=='R' : r=9 while(room_status[r]): r-=1 room_status[r]=1 continue room_status[int(e)]=0 print(*room_status,sep="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var events : String := (OclFile["System.in"]).readLine() ; var room_status : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; for e : events->characters() do ( if e = 'L' then ( var l : int := 0 ; while (room_status[l+1]) do ( l := l + 1) ; room_status[l+1] := 1 ; continue ) else skip ; if e = 'R' then ( var r : int := 9 ; while (room_status[r+1]) do ( r := r - 1) ; room_status[r+1] := 1 ; continue ) else skip ; room_status[("" + ((e)))->toInteger()+1] := 0) ; execute ((argument * (test (logical_test (comparison (expr (atom (name room_status))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() a=[0]*10 for c in input(): if c=='L' : i=0 while a[i]==1 : i+=1 a[i]=1 elif c=='R' : i=9 while a[i]==1 : i-=1 a[i]=1 else : a[int(c)]=0 print(*a,sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; for c : (OclFile["System.in"]).readLine() do ( if c = 'L' then ( var i : int := 0 ; while a[i+1] = 1 do ( i := i + 1) ; a[i+1] := 1 ) else (if c = 'R' then ( i := 9 ; while a[i+1] = 1 do ( i := i - 1) ; a[i+1] := 1 ) else ( a[("" + ((c)))->toInteger()+1] := 0 ) ) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) w=[] for _ in range(n): w+=list(map(int,input().split())) ans="YES" for i in range(n*n): if w[i]!=1 : c=0 for j in range(i-i % n,i-i % n+n): if j!=i : for k in range(i % n,n*n,n): if k!=i : if w[j]+w[k]==w[i]: c+=1 if c==0 : ans="NO" break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( w := w + ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ans : String := "YES" ; for i : Integer.subrange(0, n * n-1) do ( if w[i+1] /= 1 then ( var c : int := 0 ; for j : Integer.subrange(i - i mod n, i - i mod n + n-1) do ( if j /= i then ( for k : Integer.subrange(i mod n, n * n-1)->select( $x | ($x - i mod n) mod n = 0 ) do ( if k /= i then ( if w[j+1] + w[k+1] = w[i+1] then ( c := c + 1 ) else skip ) else skip) ) else skip) ; if c = 0 then ( ans := "NO" ; break ) else skip ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=input().split() b=b[0]+b[2 :] a=int(a) b=int(b) print(a*b//100) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; var b : OclAny := b->first() + b.subrange(2+1) ; var a : int := ("" + ((a)))->toInteger() ; b := ("" + ((b)))->toInteger() ; execute (a * b div 100)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): from sys import setrecursionlimit,stdin from os import environ from collections import defaultdict,deque,Counter from math import ceil,floor,gcd from itertools import accumulate,combinations,combinations_with_replacement setrecursionlimit(10**6) dbg=(lambda*something : print(*something))if 'TERM_PROGRAM' in environ else lambda*x : 0 input=lambda : stdin.readline().rstrip() LMIIS=lambda : list(map(int,input().split())) II=lambda : int(input()) P=10**9+7 INF=10**9+10 sa,sb=input().split() a=int(sa) b=int(float(sb)*100+0.1) print(a*b//100) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; setrecursionlimit((10)->pow(6)) ; var dbg : Function := if (environ)->includes('TERM_PROGRAM') then (lambda something : Sequence(OclAny) in (((argument * (test (logical_test (comparison (expr (atom (name something))))))))->display())) else lambda x : Sequence(OclAny) in (0) endif ; var input : Function := lambda $$ : OclAny in (stdin.readLine().rstrip()) ; var LMIIS : Function := lambda $$ : OclAny in (((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var II : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var P : double := (10)->pow(9) + 7 ; var INF : double := (10)->pow(9) + 10 ; var sa : OclAny := null; var sb : OclAny := null; Sequence{sa,sb} := input->apply().split() ; var a : int := ("" + ((sa)))->toInteger() ; var b : int := ("" + ((("" + ((sb)))->toReal() * 100 + 0.1)))->toInteger() ; execute (a * b div 100)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- C=input().split() A=int(C[0]) B=int(float(C[1])*100+0.1) E=A*B if E<100 : print(0) elif E<200 : print(1) elif E<300 : print(2) else : F=str(E) print(F[0 : len(F)-2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var C : OclAny := input().split() ; var A : int := ("" + ((C->first())))->toInteger() ; var B : int := ("" + ((("" + ((C[1+1])))->toReal() * 100 + 0.1)))->toInteger() ; var E : int := A * B ; if E < 100 then ( execute (0)->display() ) else (if E < 200 then ( execute (1)->display() ) else (if E < 300 then ( execute (2)->display() ) else ( var F : String := ("" + ((E))) ; execute (F.subrange(0+1, (F)->size() - 2))->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,decimal A,B=input().split() print(math.floor(int(A)*decimal.Decimal(B))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := input().split() ; execute ((("" + ((A)))->toInteger() * decimal.Decimal(B))->floor())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): A,B=input().replace('.','').split(' ') print(int(A)*int(B)//100) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := input().replace('.', '').split(' ') ; execute (("" + ((A)))->toInteger() * ("" + ((B)))->toInteger() div 100)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b=map(int,input().split()) a1,b1=map(int,input().split()) if max(a,b)==max(a1,b1): if min(a,b)+min(a1,b1)==max(a,b): print('YES') else : print('NO') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a1 : OclAny := null; var b1 : OclAny := null; Sequence{a1,b1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if Set{a, b}->max() = Set{a1, b1}->max() then ( if Set{a, b}->min() + Set{a1, b1}->min() = Set{a, b}->max() then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def calc(n): d='' for i in str(n): if i=='2' : d+='5' elif i=='5' : d+='2' else : d+=i return d.rjust(2,'0')[: :-1] for _ in range(int(input())): h,m=map(int,input().split()) s=input()[:-1] a=int(s[: 2]) b=int(s[3 :]) while 1 : x=calc(a) y=calc(b) if all(1 if i in['0','1','2','5','8']else 0 for i in x)and all(1 if i in['0','1','2','5','8']else 0 for i in y)and int(x)toInteger()-1) do ( var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := input()->front() ; var a : int := ("" + ((s.subrange(1,2))))->toInteger() ; var b : int := ("" + ((s.subrange(3+1))))->toInteger() ; while 1 do ( var x : OclAny := calc(a) ; var y : OclAny := calc(b) ; if ((argument (test (logical_test (comparison (expr (atom (number (integer 1)))))) if (logical_test (comparison (comparison (expr (atom (name i)))) in (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom '0'))))) , (test (logical_test (comparison (expr (atom '1'))))) , (test (logical_test (comparison (expr (atom '2'))))) , (test (logical_test (comparison (expr (atom '5'))))) , (test (logical_test (comparison (expr (atom '8')))))) ]))))) else (test (logical_test (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name x))))))))->forAll( _x | _x = true ) & ((argument (test (logical_test (comparison (expr (atom (number (integer 1)))))) if (logical_test (comparison (comparison (expr (atom (name i)))) in (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom '0'))))) , (test (logical_test (comparison (expr (atom '1'))))) , (test (logical_test (comparison (expr (atom '2'))))) , (test (logical_test (comparison (expr (atom '5'))))) , (test (logical_test (comparison (expr (atom '8')))))) ]))))) else (test (logical_test (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name y))))))))->forAll( _x | _x = true ) & (("" + ((x)))->toInteger()->compareTo(m)) < 0 & (("" + ((y)))->toInteger()->compareTo(h)) < 0 then ( break ) else skip ; b := b + 1 ; if b = m then ( a := a + 1 ; b := 0 ; a := a mod h ) else skip) ; execute (OclType["String"](a).rjust(2, '0') + ':' + OclType["String"](b).rjust(2, '0'))->display()); operation calc(n : OclAny) : OclAny pre: true post: true activity: var d : String := '' ; for i : ("" + ((n))) do ( if i = '2' then ( d := d + '5' ) else (if i = '5' then ( d := d + '2' ) else ( d := d + i ) ) ) ; return d.rjust(2, '0')(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : sorted(map(int,input().split())) t,=R() for _ in[0]*t : a,b=R(); c,d=R(); print('NYOE S'[b==d==a+c : : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort()) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := R->apply() ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, t) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := R->apply(); var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := R->apply(); execute ('NYOE S'(subscript (test (logical_test (comparison (comparison (comparison (expr (atom (name b)))) == (comparison (expr (atom (name d))))) == (comparison (expr (expr (atom (name a))) + (expr (atom (name c)))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): a,b=map(int,input().split()) a2,b2=map(int,input().split()) if a2==a and(b+b2)==a2 : print("Yes") elif a==b2 and(b+a2)==a : print("YES") elif b2==b and(a+a2)==b2 : print("Yes") elif b==a2 and(a+b2)==b : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a2 : OclAny := null; var b2 : OclAny := null; Sequence{a2,b2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a2 = a & (b + b2) = a2 then ( execute ("Yes")->display() ) else (if a = b2 & (b + a2) = a then ( execute ("YES")->display() ) else (if b2 = b & (a + a2) = b2 then ( execute ("Yes")->display() ) else (if b = a2 & (a + b2) = b then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): l1=list(map(int,input().split())) l2=list(map(int,input().split())) if((min(l1)+min(l2))==(max(l1)+max(l2))/2)and max(l1)==max(l2): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (((l1)->min() + (l2)->min()) = ((l1)->max() + (l2)->max()) / 2) & (l1)->max() = (l2)->max() then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys import itertools import fractions if __name__=='__main__' : wtf=sys.stdin.read() wtf=wtf.strip().split('\n') n=int(wtf[0]) mat=[[z for z in map(int,x.split())]for x in wtf[1 :]] ans=0 for i in range(n): if ans==-1 : break for j in range(n): if mat[i][j]!=1 : f=False for l in range(n): if l!=i : if mat[i][j]-mat[l][j]in mat[i]: f=True break if f is False : ans=-1 print('Yes' if ans==0 else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var wtf : String := (OclFile["System.in"]).readAll() ; wtf := wtf->trim().split(' ') ; var n : int := ("" + ((wtf->first())))->toInteger() ; var mat : Sequence := wtf->tail()->select(x | true)->collect(x | ((x.split())->collect( _x | (OclType["int"])->apply(_x) )->select(z | true)->collect(z | (z)))) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ans = -1 then ( break ) else skip ; for j : Integer.subrange(0, n-1) do ( if mat[i+1][j+1] /= 1 then ( var f : boolean := false ; for l : Integer.subrange(0, n-1) do ( if l /= i then ( if (mat[i+1])->includes(mat[i+1][j+1] - mat[l+1][j+1]) then ( f := true ; break ) else skip ) else skip) ; if f <>= false then ( ans := -1 ) else skip ) else skip)) ; execute (if ans = 0 then 'Yes' else 'No' endif)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : sorted([int(c)for c in input().split()]) n=int(input()) for i in range(n): a,b=R() c,d=R() print('yes' if b==d and a+c==b else 'no') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in (input().split()->select(c | true)->collect(c | (("" + ((c)))->toInteger()))->sort()) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := R->apply() ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := R->apply() ; execute (if b = d & a + c = b then 'yes' else 'no' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def precisionCompute(x,y,n): if y==0 : print("Infinite"); return ; if x==0 : print(0); return ; if n<=0 : print(x/y); return ; if(((x>0)and(y<0))or((x<0)and(y>0))): print("-",end=""); if x<0 : x=-x ; if y<0 : y=-y ; d=x/y ; for i in range(0,n+1): print(d); x=x-(y*d); if x==0 : break ; x=x*10 ; d=x/y ; if(i==0): print(".",end=""); x=22 ; y=7 ; n=15 ; precisionCompute(x,y,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := 22; ; y := 7; ; n := 15; ; precisionCompute(x, y, n);; operation precisionCompute(x : OclAny, y : OclAny, n : OclAny) : OclAny pre: true post: true activity: if y = 0 then ( execute ("Infinite")->display(); ; return; ) else skip ; if x = 0 then ( execute (0)->display(); ; return; ) else skip ; if n <= 0 then ( execute (x / y)->display(); ; return; ) else skip ; if (((x > 0) & (y < 0)) or ((x < 0) & (y > 0))) then ( execute ("-")->display(); ; if x < 0 then ( x := -x; ) else skip ; if y < 0 then ( y := -y; ) else skip ) else skip ; var d : double := x / y; ; for i : Integer.subrange(0, n + 1-1) do ( execute (d)->display(); ; x := x - (y * d); ; if x = 0 then ( break; ) else skip ; x := x * 10; ; d := x / y; ; if (i = 0) then ( execute (".")->display(); ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(b==0): return a else : return gcd(b,a % b) def lcmOfArray(arr,n): if(n<1): return 0 lcm=arr[0] for i in range(n): lcm=(lcm*arr[i])//gcd(lcm,arr[i]); return lcm def minPerfectCube(arr,n): lcm=lcmOfArray(arr,n) minPerfectCube=lcm cnt=0 while(lcm>1 and lcm % 2==0): cnt+=1 lcm//=2 if(cnt % 3==2): minPerfectCube*=2 elif(cnt % 3==1): minPerfectCube*=4 i=3 while(lcm>1): cnt=0 while(lcm % i==0): cnt+=1 lcm//=i if(cnt % 3==1): minPerfectCube*=i*i elif(cnt % 3==2): minPerfectCube*=i i+=2 return minPerfectCube if __name__=="__main__" : arr=[10,125,14,42,100] n=len(arr) print(minPerfectCube(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{10}->union(Sequence{125}->union(Sequence{14}->union(Sequence{42}->union(Sequence{ 100 })))) ; n := (arr)->size() ; execute (minPerfectCube(arr, n))->display() ) else skip; operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (b = 0) then ( return a ) else ( return gcd(b, a mod b) ); operation lcmOfArray(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n < 1) then ( return 0 ) else skip ; var lcm : OclAny := arr->first() ; for i : Integer.subrange(0, n-1) do ( lcm := (lcm * arr[i+1]) div gcd(lcm, arr[i+1]);) ; return lcm; operation minPerfectCube(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: lcm := lcmOfArray(arr, n) ; var minPerfectCube : OclAny := lcm ; var cnt : int := 0 ; while (lcm > 1 & lcm mod 2 = 0) do ( cnt := cnt + 1 ; lcm := lcm div 2) ; if (cnt mod 3 = 2) then ( minPerfectCube := minPerfectCube * 2 ) else (if (cnt mod 3 = 1) then ( minPerfectCube := minPerfectCube * 4 ) else skip) ; var i : int := 3 ; while (lcm > 1) do ( cnt := 0 ; while (lcm mod i = 0) do ( cnt := cnt + 1 ; lcm := lcm div i) ; if (cnt mod 3 = 1) then ( minPerfectCube := minPerfectCube * i * i ) else (if (cnt mod 3 = 2) then ( minPerfectCube := minPerfectCube * i ) else skip) ; i := i + 2) ; return minPerfectCube; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : s=[] q=[] elements=0 def __init__(self,key): self.data=key self.left=None self.right=None def printSpecificLevelOrder(self,root): self.s.append(root) prnt=self.s.pop(0) self.q.append(prnt.data) if prnt.right : self.s.append(root.right) if prnt.left : self.s.append(root.left) while(len(self.s)>0): first=self.s.pop(0) self.q.append(first.data) second=self.s.pop(0) self.q.append(second.data) if first.left and second.right and first.right and second.left : self.s.append(first.left) self.s.append(second.right) self.s.append(first.right) self.s.append(second.left) for elements in reversed(self.q): print(elements,end=" ") root=Node(1) root.left=Node(2) root.right=Node(3) print("Specific Level Order traversal of " "binary tree is") root.printSpecificLevelOrder(root) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); static attribute s : Sequence := Sequence{}; static attribute q : Sequence := Sequence{}; static attribute elements : int := 0; attribute data : OclAny := key; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(key : OclAny) : Node pre: true post: true activity: self.data := key ; self.left := null ; self.right := null; return self; operation printSpecificLevelOrder(root : OclAny) pre: true post: true activity: (expr (atom (name self)) (trailer . (name s)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name root)))))))) )))) ; var prnt : OclAny := self.s->at(0`firstArg+1) ; (expr (atom (name self)) (trailer . (name q)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name prnt)) (trailer . (name data)))))))) )))) ; if prnt.right then ( (expr (atom (name self)) (trailer . (name s)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name root)) (trailer . (name right)))))))) )))) ) else skip ; if prnt.left then ( (expr (atom (name self)) (trailer . (name s)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name root)) (trailer . (name left)))))))) )))) ) else skip ; while ((self.s)->size() > 0) do ( var first : OclAny := self.s->at(0`firstArg+1) ; (expr (atom (name self)) (trailer . (name q)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name first)) (trailer . (name data)))))))) )))) ; var second : OclAny := self.s->at(0`firstArg+1) ; (expr (atom (name self)) (trailer . (name q)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name second)) (trailer . (name data)))))))) )))) ; if first.left & second.right & first.right & second.left then ( (expr (atom (name self)) (trailer . (name s)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name first)) (trailer . (name left)))))))) )))) ; (expr (atom (name self)) (trailer . (name s)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name second)) (trailer . (name right)))))))) )))) ; (expr (atom (name self)) (trailer . (name s)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name first)) (trailer . (name right)))))))) )))) ; (expr (atom (name self)) (trailer . (name s)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name second)) (trailer . (name left)))))))) )))) ) else skip) ; for elements : (self.q)->reverse() do ( execute (elements)->display()); } class FromPython { operation initialise() pre: true post: true activity: skip ; root := (Node.newNode()).initialise(1) ; root.left := (Node.newNode()).initialise(2) ; root.right := (Node.newNode()).initialise(3) ; execute ((atom "Specific Level Order traversal of " "binary tree is"))->display() ; root.printSpecificLevelOrder(root); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def hollowSquare(rows): for i in range(1,rows+1): if(i==1 or i==rows): for j in range(1,rows+1): print("*",end="") else : for j in range(1,rows+1): if(j==1 or j==rows): print("*",end="") else : print(end="") print() def solidSquare(rows): for i in range(1,rows): for j in range(1,rows+1): print("*",end="") print() def printPattern(rows): print("Solid Square:") solidSquare(rows) print("\nHollow Square:") hollowSquare(rows) rows=5 printPattern(rows) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; rows := 5 ; printPattern(rows); operation hollowSquare(rows : OclAny) pre: true post: true activity: for i : Integer.subrange(1, rows + 1-1) do ( if (i = 1 or i = rows) then ( for j : Integer.subrange(1, rows + 1-1) do ( execute ("*")->display()) ) else ( for j : Integer.subrange(1, rows + 1-1) do ( if (j = 1 or j = rows) then ( execute ("*")->display() ) else ( execute ((argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom "")))))))->display() )) ) ; execute (->display()); operation solidSquare(rows : OclAny) pre: true post: true activity: for i : Integer.subrange(1, rows-1) do ( for j : Integer.subrange(1, rows + 1-1) do ( execute ("*")->display()) ; execute (->display()); operation printPattern(rows : OclAny) pre: true post: true activity: execute ("Solid Square:")->display() ; solidSquare(rows) ; execute ("\nHollow Square:")->display() ; hollowSquare(rows); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) t=list(map(int,input().split())) x=-1 y=0 for i in range(len(t)): if t[i]!=0 : y+=t[i] x=i if y==0 and x==-1 : print('NO') elif y!=0 : print('YES') print('1') print('1',n) else : print('YES') print('2') print('1',x) print(x+1,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : int := -1 ; var y : int := 0 ; for i : Integer.subrange(0, (t)->size()-1) do ( if t[i+1] /= 0 then ( y := y + t[i+1] ; x := i ) else skip) ; if y = 0 & x = -1 then ( execute ('NO')->display() ) else (if y /= 0 then ( execute ('YES')->display() ; execute ('1')->display() ; execute ('1')->display() ) else ( execute ('YES')->display() ; execute ('2')->display() ; execute ('1')->display() ; execute (x + 1)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a=int(input()),list(map(int,input().split())) x=next((i for i,ai in enumerate(a)if ai),None) if x is None : print('NO') elif sum(a): print('YES',1,'1{}'.format(n),sep='\n') else : print('YES',2,'1{}'.format(x+1),'{}{}'.format(x+2,n),sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),((input().split())->collect( _x | (OclType["int"])->apply(_x) ))} ; var x : OclAny := (Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name ai)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (atom (name ai)))))))))}, null).next() ; if x <>= null then ( execute ('NO')->display() ) else (if (a)->sum() then ( execute ('YES')->display() ) else ( execute ('YES')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def cross(a,b): return a.real*b.imag-a.imag*b.real def dot(a,b): return a.real*b.real+a.imag*b.imag def norm2(a,b): return(b.real-a.real)**2+(b.imag-a.imag)**2 def is_intersect(p0,p1,p2,p3): ta=cross(p1-p0,p2-p0) tb=cross(p1-p0,p3-p0) tc=cross(p3-p2,p0-p2) td=cross(p3-p2,p1-p2) if ta*tb<0 and tc*td<0 : return True else : return False def distance_option(p0,p1,p2): nn=norm2(p0,p1) if 0<=dot(p1-p0,p2-p0)<=nn : return abs(cross(p1-p0,p2-p0))/math.sqrt(nn) else : return math.sqrt(min(norm2(p0,p2),norm2(p1,p2))) def distance(p0,p1,p2,p3): if is_intersect(p0,p1,p2,p3): return 0 else : return min(distance_option(p0,p1,p2),distance_option(p0,p1,p3),distance_option(p2,p3,p0),distance_option(p2,p3,p1)) q=int(input()) for _ in[0]*q : x_y=map(int,input().split()) p0,p1,p2,p3=[x+y*1j for x,y in zip(*[x_y]*2)] print("{:.10f}".format(distance(p0,p1,p2,p3))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, q) do ( var x_y : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; Sequence{p0,p1,p2,p3} := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name x_y))))))) ])) * (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name x_y))))))) ])) * (expr (atom (number (integer 2)))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name x_y))))))) ])) * (expr (atom (number (integer 2)))))))))`third->at(_indx)} )->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (x + y * 1j)) ; execute (StringLib.interpolateStrings("{:.10f}", Sequence{distance(p0, p1, p2, p3)}))->display()); operation cross(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a.real * b.imag - a.imag * b.real; operation dot(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a.real * b.real + a.imag * b.imag; operation norm2(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return ((b.real - a.real))->pow(2) + ((b.imag - a.imag))->pow(2); operation is_intersect(p0 : OclAny, p1 : OclAny, p2 : OclAny, p3 : OclAny) : OclAny pre: true post: true activity: var ta : OclAny := cross(p1 - p0, p2 - p0) ; var tb : OclAny := cross(p1 - p0, p3 - p0) ; var tc : OclAny := cross(p3 - p2, p0 - p2) ; var td : OclAny := cross(p3 - p2, p1 - p2) ; if ta * tb < 0 & tc * td < 0 then ( return true ) else ( return false ); operation distance_option(p0 : OclAny, p1 : OclAny, p2 : OclAny) : OclAny pre: true post: true activity: var nn : OclAny := norm2(p0, p1) ; if 0 <= dot(p1 - p0, p2 - p0) & (dot(p1 - p0, p2 - p0) <= nn) then ( return (cross(p1 - p0, p2 - p0))->abs() / (nn)->sqrt() ) else ( return (Set{norm2(p0, p2), norm2(p1, p2)}->min())->sqrt() ); operation distance(p0 : OclAny, p1 : OclAny, p2 : OclAny, p3 : OclAny) : OclAny pre: true post: true activity: if is_intersect(p0, p1, p2, p3) then ( return 0 ) else ( return Set{distance_option(p0, p1, p2), distance_option(p0, p1, p3), distance_option(p2, p3, p0), distance_option(p2, p3, p1)}->min() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def is_correct(hmax,mmax,time): h,m=time.split(":") mirrored={"0":"0","1":"1","2":"5","3":"","4":"","5":"2","6":"","7":"","8":"8","9":""} mirrored_h=mirrored[h[1]]+mirrored[h[0]] mirrored_m=mirrored[m[1]]+mirrored[m[0]] if len(mirrored_h)==2 and int(mirrored_h) "0" }->union(Map{ "1" |-> "1" }->union(Map{ "2" |-> "5" }->union(Map{ "3" |-> "" }->union(Map{ "4" |-> "" }->union(Map{ "5" |-> "2" }->union(Map{ "6" |-> "" }->union(Map{ "7" |-> "" }->union(Map{ "8" |-> "8" }->union(Map{ "9" |-> "" }))))))))) ; var mirrored_h : OclAny := mirrored[h[1+1]+1] + mirrored[h->first()+1] ; var mirrored_m : OclAny := mirrored[m[1+1]+1] + mirrored[m->first()+1] ; if (mirrored_h)->size() = 2 & (("" + ((mirrored_h)))->toInteger()->compareTo(mmax)) < 0 & (mirrored_m)->size() = 2 & (("" + ((mirrored_m)))->toInteger()->compareTo(hmax)) < 0 then ( return mirrored_m + ":" + mirrored_h ) else skip ; return false; operation main() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( Sequence{hmax,mmax} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var hnow : OclAny := null; var mnow : OclAny := null; Sequence{hnow,mnow} := (input().split(":"))->collect( _x | (OclType["int"])->apply(_x) ) ; var result : String := "00:00" ; var end : boolean := false ; for hour : Integer.subrange(hnow, hmax-1) do ( var start : OclAny := if hour = hnow then mnow else 0 endif ; for minute : Integer.subrange(start, mmax-1) do ( time := OclType["String"](hour).rjust(2, "0") + ":" + OclType["String"](minute).rjust(2, "0") ; mirrored := is_correct(hmax, mmax, time) ; if mirrored then ( result := time ; end := true ; break ) else skip) ; if end then ( break ) else skip) ; execute (result)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a=int(input()),list(map(int,input().split())) x=next((i for i,ai in enumerate(a)if ai),None) if x is None : print('NO') elif sum(a): print('YES',1,'1{}'.format(n),sep='\n') else : print('YES',2,'1{}'.format(x+1),'{}{}'.format(x+2,n),sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),((input().split())->collect( _x | (OclType["int"])->apply(_x) ))} ; var x : OclAny := (Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name ai)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (atom (name ai)))))))))}, null).next() ; if x <>= null then ( execute ('NO')->display() ) else (if (a)->sum() then ( execute ('YES')->display() ) else ( execute ('YES')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) data=[list(map(int,input().split()))for _ in range(n)] ans=True for i in range(n): for j in range(n): if data[i][j]!=1 : chk=False for k in range(n): for l in range(n): if data[i][k]+data[l][j]==data[i][j]: chk=True break if not chk : ans=False break print("YES" if ans else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var data : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ans : boolean := true ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if data[i+1][j+1] /= 1 then ( var chk : boolean := false ; for k : Integer.subrange(0, n-1) do ( for l : Integer.subrange(0, n-1) do ( if data[i+1][k+1] + data[l+1][j+1] = data[i+1][j+1] then ( chk := true ; break ) else skip)) ; if not(chk) then ( ans := false ; break ) else skip ) else skip)) ; execute (if ans then "YES" else "NO" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) x=[int(x)for x in input().split()] zero_condition=False sum=0 mid=0 for i in range(0,len(x)): sum+=x[i] if(x[i]!=0): mid=i+1 if(mid==0): print("NO") elif(sum!=0): print("YES") print(1) print(1,len(x)) else : print("YES") print(2) print(1,mid-1) print(mid,len(x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var zero_condition : boolean := false ; var sum : int := 0 ; var mid : int := 0 ; for i : Integer.subrange(0, (x)->size()-1) do ( sum := sum + x[i+1] ; if (x[i+1] /= 0) then ( mid := i + 1 ) else skip) ; if (mid = 0) then ( execute ("NO")->display() ) else (if (sum /= 0) then ( execute ("YES")->display() ; execute (1)->display() ; execute (1)->display() ) else ( execute ("YES")->display() ; execute (2)->display() ; execute (1)->display() ; execute (mid)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(int(i)for i in input().split()) ans=[] l=r=0 sum=a[0] for i in range(1,n): if sum!=0 : if i<=n-1 and sum+a[i]!=0 : sum+=a[i] r+=1 else : ans.append([l+1,r+1]) sum=a[i] l=r=i else : sum+=a[i] r+=1 if sum!=0 : ans.append([l+1,r+1]) print('YES') print(len(ans)) for l,r in ans : print(l,r) else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ; var ans : Sequence := Sequence{} ; var l : OclAny := 0; var r : int := 0 ; var sum : OclAny := a->first() ; for i : Integer.subrange(1, n-1) do ( if sum /= 0 then ( if (i->compareTo(n - 1)) <= 0 & sum + a[i+1] /= 0 then ( sum := sum + a[i+1] ; r := r + 1 ) else ( execute ((Sequence{l + 1}->union(Sequence{ r + 1 })) : ans) ; sum := a[i+1] ; l := i; r := i ) ) else ( sum := sum + a[i+1] ; r := r + 1 )) ; if sum /= 0 then ( execute ((Sequence{l + 1}->union(Sequence{ r + 1 })) : ans) ; execute ('YES')->display() ; execute ((ans)->size())->display() ; for _tuple : ans do (var _indx : int := 1; var l : OclAny := _tuple->at(_indx); _indx := _indx + 1; var r : OclAny := _tuple->at(_indx); execute (l)->display()) ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) res=set(range(1,101)) for _ in range(n): r,*lines=(int(i)for i in input().split()) res &=set(lines) print(*res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : Set := Set{}->union((Integer.subrange(1, 101-1))) ; for _anon : Integer.subrange(0, n-1) do ( var r : OclAny := null; var lines : OclAny := null; Sequence{r,lines} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; res := res & Set{}->union((lines))) ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- stops=int(input()) tram_lines=[] for i in range(stops): stop=list(map(int,(input().split(' ')))) tram_lines.append(stop[1 :]) noticeable=[] for stop in tram_lines[0]: count=1 for i in range(1,stops): if stop in tram_lines[i]: count+=1 if count==stops : noticeable.append(stop) noticeable=set(noticeable) print(*noticeable) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var stops : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var tram_lines : Sequence := Sequence{} ; for i : Integer.subrange(0, stops-1) do ( var stop : Sequence := (((input().split(' ')))->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((stop->tail()) : tram_lines)) ; var noticeable : Sequence := Sequence{} ; for stop : tram_lines->first() do ( var count : int := 1 ; for i : Integer.subrange(1, stops-1) do ( if (tram_lines[i+1])->includes(stop) then ( count := count + 1 ) else skip) ; if count = stops then ( execute ((stop) : noticeable) ) else skip) ; noticeable := Set{}->union((noticeable)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name noticeable))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def li(): return list(map(int,input().split())) def gi(n): return[list(map(int,input().split()))for _ in range(n)] d={} n=int(input()) for _ in range(n): l=list(map(int,input().split())) for i in l[1 :]: d.setdefault(i,0) d[i]+=1 ans=[i for i in d if d[i]==n] print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var d : OclAny := Set{} ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : l->tail() do ( d.setdefault(i, 0) ; d[i+1] := d[i+1] + 1)) ; var ans : Sequence := d->select(i | d[i+1] = n)->collect(i | (i)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); operation li() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation gi(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) list1=[0 for i in range(100)] for _ in range(t): ll=list(map(int,input().split())) for i in range(1,len(ll)): list1[ll[i]-1]+=1 for i in range(100): if list1[i]==t : print(i+1,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var list1 : Sequence := Integer.subrange(0, 100-1)->select(i | true)->collect(i | (0)) ; for _anon : Integer.subrange(0, t-1) do ( var ll : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(1, (ll)->size()-1) do ( list1[ll[i+1] - 1+1] := list1[ll[i+1] - 1+1] + 1)) ; for i : Integer.subrange(0, 100-1) do ( if list1[i+1] = t then ( execute (i + 1)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import* from decimal import* import sys def _input(): return map(int,input().split()) def _list(): return list(map(int,input().split())) def _int(): return int(input()) a=[0]*10001 def solves(): n=int(input()) for i in range(n): r,*l=map(int,input().strip().split()) if(i==0): k=set(l) else : k=k.intersection(set(l)) print(*k) t=1 for i in range(2,10000): if a[i]==0 : for j in range(i*2,10000,i): a[j]=1 for _ in range(0,t): solves() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10001) ; skip ; var t : int := 1 ; for i : Integer.subrange(2, 10000-1) do ( if a[i+1] = 0 then ( for j : Integer.subrange(i * 2, 10000-1)->select( $x | ($x - i * 2) mod i = 0 ) do ( a[j+1] := 1) ) else skip) ; for _anon : Integer.subrange(0, t-1) do ( solves()); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation _list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation _int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation solves() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var r : OclAny := null; var l : OclAny := null; Sequence{r,l} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (i = 0) then ( var k : Set := Set{}->union((l)) ) else ( k := k->intersection(Set{}->union((l))) )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name k))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush MOD=10**9+7 def solution(): n=int(input()) print("abcd"*(n//4)+"abc"[: n % 4]) def main(): t=1 for _ in range(t): solution() import sys import threading sys.setrecursionlimit(1<<30) threading.stack_size(1<<27) thread=threading.Thread(target=main) thread.start(); thread.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1 * (2->pow(30))) ; threading.stack_size(1 * (2->pow(27))) ; var thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ; thread.start(); thread.join(); operation solution() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (StringLib.nCopies("abcd", (n div 4)) + "abc".subrange(1,n mod 4))->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- LUCKY="abcd" n=int(input()) s="" for i in range(n): s+=LUCKY[i % 4] print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var LUCKY : String := "abcd" ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := "" ; for i : Integer.subrange(0, n-1) do ( s := s + LUCKY[i mod 4+1]) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def is_correct(hourMax,minuteMax,time): h,m=time.split(":") mirrored={"0":"0","1":"1","2":"5","3":"","4":"","5":"2","6":"","7":"","8":"8","9":""} mirrored_h=mirrored[h[1]]+mirrored[h[0]] mirrored_m=mirrored[m[1]]+mirrored[m[0]] if len(mirrored_h)==2 and int(mirrored_h)toInteger() ; for _anon : Integer.subrange(0, N-1) do ( Sequence{hourMax,minuteMax} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var hourNow : OclAny := null; var minuteNow : OclAny := null; Sequence{hourNow,minuteNow} := (input().split(":"))->collect( _x | (OclType["int"])->apply(_x) ) ; var result : String := "00:00" ; var flag : boolean := false ; for hour : Integer.subrange(hourNow, hourMax-1) do ( var start : OclAny := if hour = hourNow then minuteNow else 0 endif ; for minute : Integer.subrange(start, minuteMax-1) do ( time := StringLib.nCopies("0", (2 - (("" + ((hour))))->size())) + ("" + ((hour))) + ":" + StringLib.nCopies("0", (2 - (("" + ((minute))))->size())) + ("" + ((minute))) ; mirrored := is_correct(hourMax, minuteMax, time) ; if mirrored then ( result := time ; flag := true ; break ) else skip) ; if flag then ( break ) else skip) ; execute (result)->display()); operation is_correct(hourMax : OclAny, minuteMax : OclAny, time : OclAny) : OclAny pre: true post: true activity: var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := time.split(":") ; var mirrored : Map := Map{ "0" |-> "0" }->union(Map{ "1" |-> "1" }->union(Map{ "2" |-> "5" }->union(Map{ "3" |-> "" }->union(Map{ "4" |-> "" }->union(Map{ "5" |-> "2" }->union(Map{ "6" |-> "" }->union(Map{ "7" |-> "" }->union(Map{ "8" |-> "8" }->union(Map{ "9" |-> "" }))))))))) ; var mirrored_h : OclAny := mirrored[h[1+1]+1] + mirrored[h->first()+1] ; var mirrored_m : OclAny := mirrored[m[1+1]+1] + mirrored[m->first()+1] ; if (mirrored_h)->size() = 2 & (("" + ((mirrored_h)))->toInteger()->compareTo(minuteMax)) < 0 & (mirrored_m)->size() = 2 & (("" + ((mirrored_m)))->toInteger()->compareTo(hourMax)) < 0 then ( return mirrored_m + ":" + mirrored_h ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=(int(x)for x in input().split()) MAX=(1<<32)-1 print("{:032b}".format(a & b)) print("{:032b}".format(a | b)) print("{:032b}".format(a ^ b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var MAX : double := (1 * (2->pow(32))) - 1 ; execute (StringLib.interpolateStrings("{:032b}", Sequence{MathLib.bitwiseAnd(a, b)}))->display() ; execute (StringLib.interpolateStrings("{:032b}", Sequence{MathLib.bitwiseOr(a, b)}))->display() ; execute (StringLib.interpolateStrings("{:032b}", Sequence{MathLib.bitwiseXor(a, b)}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=int(input()) a="abcd"*(s//4)+"abcd"[0 : s % 4] print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : String := StringLib.nCopies("abcd", (s div 4)) + "abcd".subrange(0+1, s mod 4) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s="abcd"*(n//4)+"abcd"[0 : n % 4] print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := StringLib.nCopies("abcd", (n div 4)) + "abcd".subrange(0+1, n mod 4) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s="abcd"*(n//4)+"abcd"[0 : n % 4] print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := StringLib.nCopies("abcd", (n div 4)) + "abcd".subrange(0+1, n mod 4) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import heapq import sys import math import itertools import bisect from io import BytesIO,IOBase import os def values(): return tuple(map(int,sys.stdin.readline().split())) def inlsts(): return[int(i)for i in sys.stdin.readline().split()] def inp(): return int(sys.stdin.readline()) def instr(): return sys.stdin.readline().strip() def words(): return[i for i in sys.stdin.readline().strip().split()] def chars(): return[i for i in sys.stdin.readline().strip()] def solve(): n=inp() t=[]; w=[] for i in range(n): a,b=values() t.append(a); w.append(b) sm=sum(t) cnt=sum(w) dp=[-float('inf')]*(sm+1) dp[0]=0 for i in range(n): for j in range(sm,t[i]-1,-1): dp[j]=max(dp[j],dp[j-t[i]]+w[i]) for i in range(1,len(dp)): rem=cnt-dp[i] if dp[i]>0 and rem<=i : print(i); break if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation values() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inlsts() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation instr() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation words() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim().split()->select(i | true)->collect(i | (i)); operation chars() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim()->select(i | true)->collect(i | (i)); operation solve() pre: true post: true activity: var n : OclAny := inp() ; var t : Sequence := Sequence{}; var w : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := values() ; execute ((a) : t); execute ((b) : w)) ; var sm : OclAny := (t)->sum() ; var cnt : OclAny := (w)->sum() ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ -("" + (('inf')))->toReal() }, (sm + 1)) ; dp->first() := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(t[i+1] - 1 + 1, sm)->reverse() do ( dp[j+1] := Set{dp[j+1], dp[j - t[i+1]+1] + w[i+1]}->max())) ; for i : Integer.subrange(1, (dp)->size()-1) do ( var rem : double := cnt - dp[i+1] ; if dp[i+1] > 0 & (rem->compareTo(i)) <= 0 then ( execute (i)->display(); break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* from sys import* from bisect import bisect_left as bl from bisect import bisect_right as br from collections import Counter as ctr from collections import deque as dq inp=lambda : int(input()) li=lambda : list(map(int,input().split())) lb=lambda : list(map(int,input().split()[0])) ls=lambda : list(input()) bi=lambda n : bin(n).replace("0b","") yn=lambda f : print('NYOE S'[f : : 2]) srp=lambda s,i,c : s[: i]+c+s[i+1 :] def solve(__=1): for _ in range(__): n=inp() wid1=[] wid2=[] for i in range(n): t,w=li() if t==1 : wid1+=[w] else : wid2+=[w] wid1.sort() wid2.sort() n=len(wid1) m=len(wid2) le=n+2*m i=j=0 ul=0 while itoInteger()) ; var li : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var lb : Function := lambda $$ : OclAny in (((input().split()->first())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ls : Function := lambda $$ : OclAny in (((OclFile["System.in"]).readLine())->characters()) ; var bi : Function := lambda n : OclAny in (bin(n).replace("0b", "")) ; var yn : Function := lambda f : OclAny in (('NYOE S'(subscript (test (logical_test (comparison (expr (atom (name f)))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display()) ; var srp : Function := lambda s : OclAny, i : OclAny, c : OclAny in (s.subrange(1,i) + c + s.subrange(i + 1+1)) ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation solve(__ : int) pre: true post: true activity: if __->oclIsUndefined() then __ := 1 else skip; for _anon : Integer.subrange(0, __-1) do ( var n : OclAny := inp->apply() ; var wid1 : Sequence := Sequence{} ; var wid2 : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var t : OclAny := null; var w : OclAny := null; Sequence{t,w} := li->apply() ; if t = 1 then ( wid1 := wid1 + Sequence{ w } ) else ( wid2 := wid2 + Sequence{ w } )) ; wid1 := wid1->sort() ; wid2 := wid2->sort() ; n := (wid1)->size() ; var m : int := (wid2)->size() ; var le : OclAny := n + 2 * m ; var i : OclAny := 0; var j : int := 0 ; var ul : int := 0 ; while (i->compareTo(n)) < 0 & (j->compareTo(m)) < 0 do ( if (wid2[j+1] + ul->compareTo(le - 2)) <= 0 then ( if (wid1[i+1] + (if (i->compareTo(n - 1)) < 0 then wid1[i + 1+1] else 0 endif)->compareTo(wid2[j+1])) < 0 then ( ul := ul + wid1[i+1] ; i := i + 1 ; le := le - 1 ) else ( ul := ul + wid2[j+1] ; j := j + 1 ; le := le - 2 ) ) else (if (wid1[i+1] + ul->compareTo(le - 1)) <= 0 then ( ul := ul + wid1[i+1] ; i := i + 1 ; le := le - 1 ) else ( break ) ) ) ; execute (le)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n1=int(input()) v=[] w=[] total_v=0 total_w=0 for i in range(n1): a,b=map(int,input().split()) v.append(a) w.append(b) total_v+=a total_w+=b dp=[[-10**9]*(total_v+1)for i in range(n1)] for i in range(n1): for j in range(total_v+1): if j==v[i]: dp[i][j]=max(dp[i-1][j],w[i]) else : dp[i][j]=max(dp[i-1][j],dp[i-1][j-v[i]]+w[i]) for i in range(1,total_v+1): if i>=total_w-dp[-1][i]: print(i) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var v : Sequence := Sequence{} ; var w : Sequence := Sequence{} ; var total_v : int := 0 ; var total_w : int := 0 ; for i : Integer.subrange(0, n1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a) : v) ; execute ((b) : w) ; total_v := total_v + a ; total_w := total_w + b) ; var dp : Sequence := Integer.subrange(0, n1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ (-10)->pow(9) }, (total_v + 1)))) ; for i : Integer.subrange(0, n1-1) do ( for j : Integer.subrange(0, total_v + 1-1) do ( if j = v[i+1] then ( dp[i+1][j+1] := Set{dp[i - 1+1][j+1], w[i+1]}->max() ) else ( dp[i+1][j+1] := Set{dp[i - 1+1][j+1], dp[i - 1+1][j - v[i+1]+1] + w[i+1]}->max() ))) ; for i : Integer.subrange(1, total_v + 1-1) do ( if (i->compareTo(total_w - dp->last()[i+1])) >= 0 then ( execute (i)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- kMaxN=1005 INF=0x3f3f3f3f dp=[0 for i in range(1,kMaxN)] t=[0 for i in range(1,kMaxN)] w=[0 for i in range(1,kMaxN)] sum=0 cnt=0 n=(int)(input()) for i in range(1,n+1): t[i],w[i]=map(int,input().split()) sum+=t[i] cnt+=w[i] for i in range(1,sum+1): dp[i]=-INF for i in range(1,n+1): for j in range(sum,t[i]-1,-1): dp[j]=max(dp[j],dp[j-t[i]]+w[i]); for i in range(1,sum+1): if dp[i]>0 and i>=cnt-dp[i]: print(i,end='\n') break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var kMaxN : int := 1005 ; var INF : int := 0x3f3f3f3f ; var dp : Sequence := Integer.subrange(1, kMaxN-1)->select(i | true)->collect(i | (0)) ; var t : Sequence := Integer.subrange(1, kMaxN-1)->select(i | true)->collect(i | (0)) ; var w : Sequence := Integer.subrange(1, kMaxN-1)->select(i | true)->collect(i | (0)) ; var sum : int := 0 ; var cnt : int := 0 ; var n : OclAny := (OclType["int"])((OclFile["System.in"]).readLine()) ; for i : Integer.subrange(1, n + 1-1) do ( var t[i+1] : OclAny := null; var w[i+1] : OclAny := null; Sequence{t[i+1],w[i+1]} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; sum := sum + t[i+1] ; cnt := cnt + w[i+1]) ; for i : Integer.subrange(1, sum + 1-1) do ( dp[i+1] := -INF) ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(t[i+1] - 1 + 1, sum)->reverse() do ( dp[j+1] := Set{dp[j+1], dp[j - t[i+1]+1] + w[i+1]}->max();)) ; for i : Integer.subrange(1, sum + 1-1) do ( if dp[i+1] > 0 & (i->compareTo(cnt - dp[i+1])) >= 0 then ( execute (i)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def main(): a,b,x=map(int,input().split()) if a<=x and x<=a+b : print("YES") else : print("NO") if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var x : OclAny := null; Sequence{a,b,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(x)) <= 0 & (x->compareTo(a + b)) <= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re import sys import math import itertools import bisect from copy import copy from collections import deque,Counter from decimal import Decimal import functools def v(): return input() def k(): return int(input()) def S(): return input().split() def I(): return map(int,input().split()) def X(): return list(input()) def L(): return list(input().split()) def l(): return list(map(int,input().split())) def lcm(a,b): return a*b//math.gcd(a,b) sys.setrecursionlimit(10**9) mod=10**9+7 cnt=0 ans=0 inf=float("inf") A,B,X=I() print("YES" if A<=X<=A+B else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var mod : double := (10)->pow(9) + 7 ; var cnt : int := 0 ; var ans : int := 0 ; var Math_PINFINITY : double := ("" + (("inf")))->toReal() ; var A : OclAny := null; var B : OclAny := null; var X : OclAny := null; Sequence{A,B,X} := I() ; execute (if (A->compareTo(X)) <= 0 & (X <= A + B) then "YES" else "NO" endif)->display(); operation v() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation k() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation S() : OclAny pre: true post: true activity: return input().split(); operation I() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation X() : OclAny pre: true post: true activity: return ((OclFile["System.in"]).readLine())->characters(); operation L() : OclAny pre: true post: true activity: return (input().split()); operation l() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a * b div (a)->gcd(b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,x=input().strip().split() a=int(a) b=int(b) x=int(x) c=x-a if 0<=c<=b : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var x : OclAny := null; Sequence{a,b,x} := input()->trim().split() ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; var x : int := ("" + ((x)))->toInteger() ; var c : double := x - a ; if 0 <= c & (c <= b) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): bm=0xffffffff a,b=map(int,input().split()) an=(a & b)& bm o=(a | b)& bm xo=(a ^ b)& bm print(format(an,"032b")) print(format(o,"032b")) print(format(xo,"032b")) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var bm : int := 0xffffffff ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var an : int := MathLib.bitwiseAnd((MathLib.bitwiseAnd(a, b)), bm) ; var o : int := MathLib.bitwiseAnd((MathLib.bitwiseOr(a, b)), bm) ; var xo : int := MathLib.bitwiseAnd((MathLib.bitwiseXor(a, b)), bm) ; execute ((an + ""))->display() ; execute ((o + ""))->display() ; execute ((xo + ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- __author__='Esfandiar' from math import ceil n=int(input()) m=num=odd=even=1 ans=list() while num!=n+1 : if num % 2 : ans.append((odd,odd)) odd+=1 else : m+=1 ans.append((even,even+1)) even+=1 num+=1 print(m) for i,j in ans : print(i,j) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var __author__ : String := 'Esfandiar' ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; m := m(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name num)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name odd)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name even)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))) ; var ans : Sequence := () ; while num /= n + 1 do ( if num mod 2 then ( execute ((Sequence{odd, odd}) : ans) ; odd := odd + 1 ) else ( m := m + 1 ; execute ((Sequence{even, even + 1}) : ans) ; even := even + 1 ) ; num := num + 1) ; execute (m)->display() ; for _tuple : ans do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B,X=[int(i)for i in input().split()] print("YES" if A<=X<=A+B else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var X : OclAny := null; Sequence{A,B,X} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute (if (A->compareTo(X)) <= 0 & (X <= A + B) then "YES" else "NO" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,itertools,heapq,collections,bisect input=lambda : sys.stdin.buffer.readline().rstrip().decode('utf-8') sys.setrecursionlimit(10**8) inf=float('inf') ans=count=0 a,b,x=map(int,input().split()) if a<=x<=a+b : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.buffer.readLine().rstrip().decode('utf-8')) ; sys.setrecursionlimit((10)->pow(8)) ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; var ans : OclAny := 0; var count : int := 0 ; var a : OclAny := null; var b : OclAny := null; var x : OclAny := null; Sequence{a,b,x} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(x)) <= 0 & (x <= a + b) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd as __gcd def findLargest(arr,n): gcd=0 for i in range(n): gcd=__gcd(arr[i],gcd) return gcd if __name__=='__main__' : arr=[3,6,9] n=len(arr) print(findLargest(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{3}->union(Sequence{6}->union(Sequence{ 9 })) ; n := (arr)->size() ; execute (findLargest(arr, n))->display() ) else skip; operation findLargest(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var gcd : int := 0 ; for i : Integer.subrange(0, n-1) do ( gcd := __gcd(arr[i+1], gcd)) ; return gcd; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findWinner(n): if((n-1)% 6==0): print("Second Player wins the game"); else : print("First Player wins the game"); if __name__=='__main__' : n=7 ; findWinner(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 7; ; findWinner(n); ) else skip; operation findWinner(n : OclAny) pre: true post: true activity: if ((n - 1) mod 6 = 0) then ( execute ("Second Player wins the game")->display(); ) else ( execute ("First Player wins the game")->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,h,a,b,k=map(int,input().split()) ans=[] for _ in range(k): ta,fa,tb,fb=map(int,input().split()) ans0=abs(ta-tb) if not ans0 : ans0+=abs(fa-fb) elif max(fa,fb)<=a : ans0+=2*a-(fa+fb) elif min(fa,fb)>=b : ans0+=(fa+fb)-2*b else : ans0+=abs(fa-fb) ans.append(ans0) sys.stdout.write("\n".join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : OclAny := null; var h : OclAny := null; var a : OclAny := null; var b : OclAny := null; var k : OclAny := null; Sequence{n,h,a,b,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, k-1) do ( var ta : OclAny := null; var fa : OclAny := null; var tb : OclAny := null; var fb : OclAny := null; Sequence{ta,fa,tb,fb} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans0 : double := (ta - tb)->abs() ; if not(ans0) then ( ans0 := ans0 + (fa - fb)->abs() ) else (if (Set{fa, fb}->max()->compareTo(a)) <= 0 then ( ans0 := ans0 + 2 * a - (fa + fb) ) else (if (Set{fa, fb}->min()->compareTo(b)) >= 0 then ( ans0 := ans0 + (fa + fb) - 2 * b ) else ( ans0 := ans0 + (fa - fb)->abs() ) ) ) ; execute ((ans0) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,h,a,b,k=map(int,input().split()) for i in range(k): ta,fa,tb,fb=map(int,input().split()) if ta==tb : ans=abs(fa-fb) else : ans=abs(tb-ta) if fab and fb>b : ans+=fa-b+fb-b else : ans+=abs(fa-fb) print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var h : OclAny := null; var a : OclAny := null; var b : OclAny := null; var k : OclAny := null; Sequence{n,h,a,b,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, k-1) do ( var ta : OclAny := null; var fa : OclAny := null; var tb : OclAny := null; var fb : OclAny := null; Sequence{ta,fa,tb,fb} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if ta = tb then ( var ans : double := (fa - fb)->abs() ) else ( ans := (tb - ta)->abs() ; if (fa->compareTo(a)) < 0 & (fb->compareTo(a)) < 0 then ( ans := ans + a - fa + a - fb ) else (if (fa->compareTo(b)) > 0 & (fb->compareTo(b)) > 0 then ( ans := ans + fa - b + fb - b ) else ( ans := ans + (fa - fb)->abs() ) ) ) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,h,a,b,k=map(int,input().split()) for _ in range(k): ta,fa,tb,fb=map(int,input().split()) c=abs(tb-ta) if c==0 : c+=abs(fa-fb) else : if fa>b : if fb>b : c+=fa-b+fb-b else : c+=fa-fb elif facollect( _x | (OclType["int"])->apply(_x) ) ; for _anon : Integer.subrange(0, k-1) do ( var ta : OclAny := null; var fa : OclAny := null; var tb : OclAny := null; var fb : OclAny := null; Sequence{ta,fa,tb,fb} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : double := (tb - ta)->abs() ; if c = 0 then ( c := c + (fa - fb)->abs() ) else ( if (fa->compareTo(b)) > 0 then ( if (fb->compareTo(b)) > 0 then ( c := c + fa - b + fb - b ) else ( c := c + fa - fb ) ) else (if (fa->compareTo(a)) < 0 then ( if (fb->compareTo(a)) < 0 then ( c := c + a - fa + a - fb ) else ( c := c + fb - fa ) ) else ( c := c + (fb - fa)->abs() ) ) ) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) n,h,a,b,k=R() for _ in[0]*k : t,f,s,g=R(); print(abs(f-g)+abs(t-s)+2*(max(0,min(f,g)-b)+max(0,a-max(f,g)))*(t!=s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var h : OclAny := null; var a : OclAny := null; var b : OclAny := null; var k : OclAny := null; Sequence{n,h,a,b,k} := R->apply() ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, k) do ( var t : OclAny := null; var f : OclAny := null; var s : OclAny := null; var g : OclAny := null; Sequence{t,f,s,g} := R->apply(); execute ((f - g)->abs() + (t - s)->abs() + 2 * (Set{0, Set{f, g}->min() - b}->max() + Set{0, a - Set{f, g}->max()}->max()) * (t /= s))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) a,b,c,d,e=list(map(int,input().split())) for i in range(e): f,g,h,i=list(map(int,input().split())) j=c if c>=g else(g if c<=g and g<=d else d) print(abs(j-g)+abs(j-i)+abs(f-h)if f!=h else abs(g-i)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; Sequence{a,b,c,d,e} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, e-1) do ( var f : OclAny := null; var g : OclAny := null; var h : OclAny := null; var i : OclAny := null; Sequence{f,g,h,i} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var j : OclAny := if (c->compareTo(g)) >= 0 then c else (if (c->compareTo(g)) <= 0 & (g->compareTo(d)) <= 0 then g else d endif) endif ; execute (if f /= h then (j - g)->abs() + (j - i)->abs() + (f - h)->abs() else (g - i)->abs() endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def run(): a,b=[int(i)for i in input().split()] fmt="{:032b}" mask=~(1<<32) print(fmt.format((a & b)& mask)) print(fmt.format((a | b)& mask)) print(fmt.format((a ^ b)& mask)) if __name__=='__main__' : run() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( run() ) else skip; operation run() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var fmt : String := "{:032b}" ; var mask : int := MathLib.bitwiseNot((1 * (2->pow(32)))) ; execute (StringLib.interpolateStrings(fmt, Sequence{MathLib.bitwiseAnd((MathLib.bitwiseAnd(a, b)), mask)}))->display() ; execute (StringLib.interpolateStrings(fmt, Sequence{MathLib.bitwiseAnd((MathLib.bitwiseOr(a, b)), mask)}))->display() ; execute (StringLib.interpolateStrings(fmt, Sequence{MathLib.bitwiseAnd((MathLib.bitwiseXor(a, b)), mask)}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict class Graph : def __init__(self): self.graph=defaultdict(list) def addEdge(self,u,v): self.graph[u].append(v) def BFS(self,s): visited=[False]*(len(self.graph)) queue=[] queue.append(s) visited[s]=True while queue : s=queue.pop(0) print(s,end=" ") for i in self.graph[s]: if visited[i]==False : queue.append(i) visited[i]=True g=Graph() g.addEdge(0,1) g.addEdge(0,2) g.addEdge(1,2) g.addEdge(2,0) g.addEdge(2,3) g.addEdge(3,3) print("Following is Breadth First Traversal" "(starting from vertex 2)") g.BFS(2) ------------------------------------------------------------ OCL File: --------- class Graph { static operation newGraph() : Graph pre: true post: Graph->exists( _x | result = _x ); attribute graph : OclAny := defaultdict(OclType["Sequence"]); operation initialise() : Graph pre: true post: true activity: self.graph := defaultdict(OclType["Sequence"]); return self; operation addEdge(u : OclAny,v : OclAny) pre: true post: true activity: (expr (atom (name self)) (trailer . (name graph) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))); operation BFS(s : OclAny) pre: true post: true activity: var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, ((self.graph)->size())) ; var queue : Sequence := Sequence{} ; execute ((s) : queue) ; visited[s+1] := true ; while queue do ( s := queue->at(0`firstArg+1) ; queue := queue->excludingAt(0+1) ; execute (s)->display() ; for i : self.graph[s+1] do ( if visited[i+1] = false then ( execute ((i) : queue) ; visited[i+1] := true ) else skip)); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var g : Graph := (Graph.newGraph()).initialise() ; g.addEdge(0, 1) ; g.addEdge(0, 2) ; g.addEdge(1, 2) ; g.addEdge(2, 0) ; g.addEdge(2, 3) ; g.addEdge(3, 3) ; execute ((atom "Following is Breadth First Traversal" "(starting from vertex 2)"))->display() ; g.BFS(2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def output(): print(m) for i in range(n): print(coord_X[i],coord_Y[i]) n=int(input()) m=0 while True : m+=1 if m*mtoInteger() ; var m : int := 0 ; while true do ( m := m + 1 ; if (m * m->compareTo(n)) < 0 then ( continue ) else skip ; if ((m * 2 - 2)->compareTo((n - 1))) < 0 then ( continue ) else skip ; var tab : Sequence := Integer.subrange(0, m-1)->select(j | true)->collect(j | (Integer.subrange(0, m-1)->select(i | true)->collect(i | (0)))) ; tab->first()->first() := 1 ; var fig : Sequence := Sequence{ 1 } ; var coord_X : Sequence := Sequence{ 1 } ; var coord_Y : Sequence := Sequence{ 1 } ; var L : int := 2 ; for r : Integer.subrange(0, m-1) do ( for c : Integer.subrange(0, m-1) do ( if tab[r+1][c+1] /= 0 then ( continue ) else skip ; var fit : boolean := true; ; var rp : OclAny := r + 1 ; var cp : OclAny := c + 1 ; for num_fig : Integer.subrange(0, (fig)->size()-1) do ( if (rp) = coord_X[num_fig+1] & (cp) = coord_Y[num_fig+1] then ( continue ) else (if (((coord_X[num_fig+1] - (rp))->abs() + (coord_Y[num_fig+1] - (cp))->abs())->compareTo(((L - fig[num_fig+1])->abs()))) < 0 then ( fit := false ; break ) else skip)) ; if fit then ( tab[r+1][c+1] := L ; execute ((L) : fig) ; execute ((rp) : coord_X) ; execute ((cp) : coord_Y) ; L := L + 1 ; if (fig)->size() = n then ( output() ; error SystemExit.newSystemExit ) else skip ) else skip)) ; if (fig)->size() = n then ( output() ; error SystemExit.newSystemExit ) else skip); operation output() pre: true post: true activity: execute (m)->display() ; for i : Integer.subrange(0, n-1) do ( execute (coord_X[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict class Graph : def __init__(self): self.graph=defaultdict(list) def addEdge(self,u,v): self.graph[u].append(v) def BFS(self,s): visited=[False]*(len(self.graph)) queue=[] queue.append(s) visited[s]=True while queue : s=queue.pop(0) print(s,end=" ") for i in self.graph[s]: if visited[i]==False : queue.append(i) visited[i]=True g=Graph() g.addEdge(0,1) g.addEdge(0,2) g.addEdge(1,2) g.addEdge(2,0) g.addEdge(2,3) g.addEdge(3,3) print("Following is Breadth First Traversal" "(starting from vertex 2)") g.BFS(2) ------------------------------------------------------------ OCL File: --------- class Graph { static operation newGraph() : Graph pre: true post: Graph->exists( _x | result = _x ); attribute graph : OclAny := defaultdict(OclType["Sequence"]); operation initialise() : Graph pre: true post: true activity: self.graph := defaultdict(OclType["Sequence"]); return self; operation addEdge(u : OclAny,v : OclAny) pre: true post: true activity: (expr (atom (name self)) (trailer . (name graph) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))); operation BFS(s : OclAny) pre: true post: true activity: var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, ((self.graph)->size())) ; var queue : Sequence := Sequence{} ; execute ((s) : queue) ; visited[s+1] := true ; while queue do ( s := queue->at(0`firstArg+1) ; queue := queue->excludingAt(0+1) ; execute (s)->display() ; for i : self.graph[s+1] do ( if visited[i+1] = false then ( execute ((i) : queue) ; visited[i+1] := true ) else skip)); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var g : Graph := (Graph.newGraph()).initialise() ; g.addEdge(0, 1) ; g.addEdge(0, 2) ; g.addEdge(1, 2) ; g.addEdge(2, 0) ; g.addEdge(2, 3) ; g.addEdge(3, 3) ; execute ((atom "Following is Breadth First Traversal" "(starting from vertex 2)"))->display() ; g.BFS(2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getElements(a,arr,n): elements=[1 for i in range(n+1)] elements[0]=a for i in range(n): elements[i+1]=arr[i]^ elements[i] for i in range(n+1): print(elements[i],end=" ") arr=[13,2,6,1] n=len(arr) a=5 getElements(a,arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{13}->union(Sequence{2}->union(Sequence{6}->union(Sequence{ 1 }))) ; n := (arr)->size() ; a := 5 ; getElements(a, arr, n); operation getElements(a : OclAny, arr : OclAny, n : OclAny) pre: true post: true activity: var elements : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (1)) ; elements->first() := a ; for i : Integer.subrange(0, n-1) do ( elements[i + 1+1] := MathLib.bitwiseXor(arr[i+1], elements[i+1])) ; for i : Integer.subrange(0, n + 1-1) do ( execute (elements[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- __author__='Tianren Liu' import sys import numpy as np def solve(R,P,S): if(R<0 or P<0 or S<0): return "IMPOSSIBLE" if R+P+S==1 : return 'R' if R>0 else 'P' if P>0 else 'S' Rn,Pn,Sn=(R+S-P)//2,(P-S+R)//2,(-R+S+P)//2 if(Rn>R or Pn>P or Sn>S): return "IMPOSSIBLE" res=solve(Rn,Pn,Sn) if res=="IMPOSSIBLE" : return "IMPOSSIBLE" else : nres='' m={'R' : 'RS','S' : 'SP','P' : 'PR'} for c in res : nres+=m[c] return nres def asort(S): if S=="IMPOSSIBLE" : return S l=len(S) if l>1 : Sl=asort(S[: l//2]) Sh=asort(S[l//2 :]) S=Sl+Sh if SltoInteger() ; for t : Integer.subrange(0, T-1) do ( var N : OclAny := null; Sequence{N,R,P,S} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{t + 1, asort(solve(R, P, S))}))->display()) ) else skip; operation solve(R : OclAny, P : OclAny, S : OclAny) : OclAny pre: true post: true activity: if (R < 0 or P < 0 or S < 0) then ( return "IMPOSSIBLE" ) else skip ; if R + P + S = 1 then ( return if R > 0 then 'R' else if P > 0 then 'P' else 'S' endif endif ) else skip ; var Rn : OclAny := null; var Pn : OclAny := null; var Sn : OclAny := null; Sequence{Rn,Pn,Sn} := Sequence{(R + S - P) div 2,(P - S + R) div 2,(-R + S + P) div 2} ; if ((Rn->compareTo(R)) > 0 or (Pn->compareTo(P)) > 0 or (Sn->compareTo(S)) > 0) then ( return "IMPOSSIBLE" ) else skip ; var res : OclAny := solve(Rn, Pn, Sn) ; if res = "IMPOSSIBLE" then ( return "IMPOSSIBLE" ) else ( var nres : String := '' ; var m : Map := Map{ 'R' |-> 'RS' }->union(Map{ 'S' |-> 'SP' }->union(Map{ 'P' |-> 'PR' })) ; for c : res do ( nres := nres + m[c+1]) ; return nres ); operation asort(S : OclAny) : OclAny pre: true post: true activity: if S = "IMPOSSIBLE" then ( return S ) else skip ; var l : int := (S)->size() ; if l > 1 then ( var Sl : OclAny := asort(S.subrange(1,l div 2)) ; var Sh : OclAny := asort(S.subrange(l div 2+1)) ; S := if (Sl->compareTo(Sh)) < 0 then Sl + Sh else Sh + Sl endif ) else skip ; return S; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- wins_over={"R" : "S","S" : "P","P" : "R"} def reorder(foo): if len(foo)==1 : return foo l=reorder(foo[: len(foo)//2]) r=reorder(foo[len(foo)//2 :]) return "".join(sorted([l,r])) def reverse(n,start): lineup=[start] for i in range(n): new_lineup=[] for c in lineup : new_lineup.extend([c,wins_over[c]]) lineup=new_lineup return reorder("".join(lineup)) def run(): n,r,p,s=tuple(int(x)for x in input().split()) ress=set() for c in wins_over : foo=reverse(n,c) if foo.count("R")==r and foo.count("P")==p and foo.count("S")==s : ress.add(foo) if len(ress)==0 : return "IMPOSSIBLE" else : return min(ress) tc=int(input()) for i in range(tc): res=run() print("Case #%d: %s" %(i+1,res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var wins_over : Map := Map{ "R" |-> "S" }->union(Map{ "S" |-> "P" }->union(Map{ "P" |-> "R" })) ; skip ; skip ; skip ; var tc : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, tc-1) do ( var res : OclAny := run() ; execute (StringLib.format("Case #%d: %s",Sequence{i + 1, res}))->display()); operation reorder(foo : OclAny) : OclAny pre: true post: true activity: if (foo)->size() = 1 then ( return foo ) else skip ; var l : OclAny := reorder(foo.subrange(1,(foo)->size() div 2)) ; var r : OclAny := reorder(foo.subrange((foo)->size() div 2+1)) ; return StringLib.sumStringsWithSeparator((Sequence{l}->union(Sequence{ r })->sort()), ""); operation reverse(n : OclAny, start : OclAny) : OclAny pre: true post: true activity: var lineup : Sequence := Sequence{ start } ; for i : Integer.subrange(0, n-1) do ( var new_lineup : Sequence := Sequence{} ; for c : lineup do ( new_lineup := new_lineup->union(Sequence{c}->union(Sequence{ wins_over[c+1] }))) ; lineup := new_lineup) ; return reorder(StringLib.sumStringsWithSeparator((lineup), "")); operation run() : OclAny pre: true post: true activity: var p : OclAny := null; var s : OclAny := null; Sequence{n,r,p,s} := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ; var ress : Set := Set{}->union(()) ; for c : wins_over->keys() do ( foo := reverse(n, c) ; if foo->count("R") = r & foo->count("P") = p & foo->count("S") = s then ( execute ((foo) : ress) ) else skip) ; if (ress)->size() = 0 then ( return "IMPOSSIBLE" ) else ( return (ress)->min() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[['P','R','S']] u='PRS' for n in range(1,13): v=[] for t in range(3): x,y=a[n-1][t],a[n-1][(t+1)% 3] v.append(min(x+y,y+x)) a.append(v) T=int(input()) for i in range(T): N,r,p,s=map(int,input().split()) res='IMPOSSIBLE' for u in a[N]: if u.count('R')==r and u.count('S')==s and u.count('P')==p : if res=='IMPOSSIBLE' : res=u else : res=min(res,u) print("Case #%d:" %(i+1),res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Sequence{ Sequence{'P'}->union(Sequence{'R'}->union(Sequence{ 'S' })) } ; var u : String := 'PRS' ; for n : Integer.subrange(1, 13-1) do ( var v : Sequence := Sequence{} ; for t : Integer.subrange(0, 3-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{a[n - 1+1][t+1],a[n - 1+1][(t + 1) mod 3+1]} ; execute ((Set{x + y, y + x}->min()) : v)) ; execute ((v) : a)) ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, T-1) do ( var N : OclAny := null; var r : OclAny := null; var p : OclAny := null; var s : OclAny := null; Sequence{N,r,p,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var res : String := 'IMPOSSIBLE' ; for u : a[N+1] do ( if u->count('R') = r & u->count('S') = s & u->count('P') = p then ( if res = 'IMPOSSIBLE' then ( res := u ) else ( res := Set{res, u}->min() ) ) else skip) ; execute (StringLib.format("Case #%d:",(i + 1)))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from pprint import pprint MAXN=14 ; tests=int(input()) src={} chars=('R','P','S') nxt={'R' : 'S','S' : 'P','P' : 'R'} for ch in chars : src[(ch,1)]=ch for i in range(2,MAXN+1): for ch in chars : s1=src[(ch,i-1)] s2=src[(nxt[ch],i-1)] s='' if s1toInteger() ; var src : OclAny := Set{} ; var chars : OclAny := Sequence{'R', 'P', 'S'} ; var nxt : Map := Map{ 'R' |-> 'S' }->union(Map{ 'S' |-> 'P' }->union(Map{ 'P' |-> 'R' })) ; for ch : chars do ( src[Sequence{ch, 1}+1] := ch) ; for i : Integer.subrange(2, MAXN + 1-1) do ( for ch : chars do ( var s1 : OclAny := src[Sequence{ch, i - 1}+1] ; var s2 : OclAny := src[Sequence{nxt[ch+1], i - 1}+1] ; var s : String := '' ; if (s1->compareTo(s2)) < 0 then ( s := s1 + s2 ) else ( s := s2 + s1 ) ; src[Sequence{ch, i}+1] := s)) ; var count : OclAny := Set{} ; for i : Integer.subrange(1, MAXN + 1-1) do ( for ch : chars do ( s := src[Sequence{ch, i}+1] ; count[Sequence{ch, i}+1] := ((argument (test (logical_test (comparison (expr (atom (name s)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name chars)))))))))) ; for test : Integer.subrange(0, tests-1) do ( var n : OclAny := null; var r : OclAny := null; var p : OclAny := null; (declareIfNecessary (test (logical_test (comparison (expr (atom (name s)))))) ,) Sequence{n,r,p,(testlist_star_expr (test (logical_test (comparison (expr (atom (name s)))))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; n := n + 1 ; var ans : String := 'Z' ; for ch : chars do ( if count[Sequence{ch, n}+1] = Sequence{r, p, s} then ( if src[Sequence{ch, n}+1] < ans then ( ans := src[Sequence{ch, n}+1] ) else skip ) else skip) ; if ans = 'Z' then ( ans := 'IMPOSSIBLE' ) else skip ; execute (StringLib.format("Case #%d: %s",Sequence{test + 1, ans}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input n,m=map(int,I().split()) b=[1]*n*2 b[0]=b[n-1]=b[n]=b[2*n-1]=0 for i in range(m): r,c=map(int,I().split()) b[r-1]=b[n+c-1]=0 if n % 2 and b[n//2]and b[n+n//2]: b[n//2]=0 print(sum(b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (I().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : Sequence := MatrixLib.elementwiseMult(MatrixLib.elementwiseMult(Sequence{ 1 }, n), 2) ; b->first() := b->first()(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n)))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (number (integer 2)))) * (expr (atom (name n)))) - (expr (atom (number (integer 1)))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for i : Integer.subrange(0, m-1) do ( var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := (I().split())->collect( _x | (OclType["int"])->apply(_x) ) ; b[r - 1+1] := 0; var b[n + c - 1+1] : int := 0) ; if n mod 2 & b[n div 2+1] & b[n + n div 2+1] then ( b[n div 2+1] := 0 ) else skip ; execute ((b)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input n,m=map(int,I().split()) b=[1]*n*2 b[0]=b[n-1]=b[n]=b[2*n-1]=0 for i in range(m): r,c=map(int,I().split()) b[r-1]=b[n+c-1]=0 if n % 2 and b[n//2]and b[n+n//2]: b[n//2]=0 print(sum(b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (I().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : Sequence := MatrixLib.elementwiseMult(MatrixLib.elementwiseMult(Sequence{ 1 }, n), 2) ; b->first() := b->first()(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n)))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (number (integer 2)))) * (expr (atom (name n)))) - (expr (atom (number (integer 1)))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for i : Integer.subrange(0, m-1) do ( var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := (I().split())->collect( _x | (OclType["int"])->apply(_x) ) ; b[r - 1+1] := 0; var b[n + c - 1+1] : int := 0) ; if n mod 2 & b[n div 2+1] & b[n + n div 2+1] then ( b[n div 2+1] := 0 ) else skip ; execute ((b)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def out(n): mask=2**32-1 print(format(n & mask,"032b")) a,b=map(int,input().split()) out(a & b) out(a | b) out(a ^ b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; out(MathLib.bitwiseAnd(a, b)) ; out(MathLib.bitwiseOr(a, b)) ; out(MathLib.bitwiseXor(a, b)); operation out(n : OclAny) pre: true post: true activity: var mask : double := (2)->pow(32) - 1 ; execute ((MathLib.bitwiseAnd(n, mask) + ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input n,m=map(int,I().split()) b=[1]*n*2 b[0]=b[n-1]=b[n]=b[2*n-1]=0 for i in range(m): r,c=map(int,I().split()) b[r-1]=b[n+c-1]=0 if n % 2 and b[n//2]and b[n+n//2]: b[n//2]=0 print(sum(b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (I().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : Sequence := MatrixLib.elementwiseMult(MatrixLib.elementwiseMult(Sequence{ 1 }, n), 2) ; b->first() := b->first()(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n)))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (number (integer 2)))) * (expr (atom (name n)))) - (expr (atom (number (integer 1)))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for i : Integer.subrange(0, m-1) do ( var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := (I().split())->collect( _x | (OclType["int"])->apply(_x) ) ; b[r - 1+1] := 0; var b[n + c - 1+1] : int := 0) ; if n mod 2 & b[n div 2+1] & b[n + n div 2+1] then ( b[n div 2+1] := 0 ) else skip ; execute ((b)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input n,m=map(int,I().split()) b=[1]*n*2 b[0]=b[n-1]=b[n]=b[2*n-1]=0 for i in range(m): r,c=map(int,I().split()) b[r-1]=b[n+c-1]=0 if n % 2 and b[n//2]and b[n+n//2]: b[n//2]=0 print(sum(b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (I().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : Sequence := MatrixLib.elementwiseMult(MatrixLib.elementwiseMult(Sequence{ 1 }, n), 2) ; b->first() := b->first()(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n)))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (number (integer 2)))) * (expr (atom (name n)))) - (expr (atom (number (integer 1)))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for i : Integer.subrange(0, m-1) do ( var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := (I().split())->collect( _x | (OclType["int"])->apply(_x) ) ; b[r - 1+1] := 0; var b[n + c - 1+1] : int := 0) ; if n mod 2 & b[n div 2+1] & b[n + n div 2+1] then ( b[n div 2+1] := 0 ) else skip ; execute ((b)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==1 : print(1) print(1,1) elif n==2 : print(2) print(1,1) print(1,2) else : x=(n+1)/2 if x==int(x): x=int(x) print(x) else : x=int(x)+1 print(x) for i in range(1,x+1): print(1,i) for j in range(2,x+1): if j-1>n-x : break print(j,i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (1)->display() ; execute (1)->display() ) else (if n = 2 then ( execute (2)->display() ; execute (1)->display() ; execute (1)->display() ) else ( var x : double := (n + 1) / 2 ; if x = ("" + ((x)))->toInteger() then ( x := ("" + ((x)))->toInteger() ; execute (x)->display() ) else ( x := ("" + ((x)))->toInteger() + 1 ; execute (x)->display() ) ; for i : Integer.subrange(1, x + 1-1) do ( execute (1)->display()) ; for j : Integer.subrange(2, x + 1-1) do ( if (j - 1->compareTo(n - x)) > 0 then ( break ) else skip ; execute (j)->display()) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def printRepeating(arr,size): S=0 ; P=1 ; n=size-2 for i in range(0,size): S=S+arr[i] P=P*arr[i] S=S-n*(n+1)//2 P=P//fact(n) D=math.sqrt(S*S-4*P) x=(D+S)//2 y=(S-D)//2 print("The two Repeating elements are ",(int)(x)," & ",(int)(y)) def fact(n): if(n==0): return 1 else : return(n*fact(n-1)) arr=[4,2,4,5,2,3,1] arr_size=len(arr) printRepeating(arr,arr_size) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; arr := Sequence{4}->union(Sequence{2}->union(Sequence{4}->union(Sequence{5}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 1 })))))) ; var arr_size : int := (arr)->size() ; printRepeating(arr, arr_size); operation printRepeating(arr : OclAny, size : OclAny) pre: true post: true activity: var S : int := 0; ; var P : int := 1; ; var n : double := size - 2 ; for i : Integer.subrange(0, size-1) do ( S := S + arr[i+1] ; P := P * arr[i+1]) ; S := S - n * (n + 1) div 2 ; P := P div fact(n) ; var D : double := (S * S - 4 * P)->sqrt() ; var x : int := (D + S) div 2 ; var y : int := (S - D) div 2 ; execute ("The two Repeating elements are ")->display(); operation fact(n : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return 1 ) else ( return (n * fact(n - 1)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- __author__='Pavel Mavrin' fin=open("A.in") fout=open("A.out","w") test_num=int(fin.readline()) def solve_test(): n,x=[int(x)for x in fin.readline().split()] s=[int(x)for x in fin.readline().split()] s.sort() res=0 j=n-1 for i in range(n): while j>i and s[i]+s[j]>x : j-=1 if j>i : res+=1 j-=1 else : break return str(res+(n-2*res)) for test_i in range(test_num): s="Case #"+str(test_i+1)+": "+solve_test() print(s) print(s,file=fout) fin.close() fout.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var __author__ : String := 'Pavel Mavrin' ; var fin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("A.in")) ; var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("A.out")) ; var test_num : int := ("" + ((fin.readLine())))->toInteger() ; skip ; for test_i : Integer.subrange(0, test_num-1) do ( s := "Case #" + ("" + ((test_i + 1))) + ": " + solve_test() ; execute (s)->display() ; execute (s)->display()) ; fin.closeFile() ; fout.closeFile(); operation solve_test() : OclAny pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := fin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var s : Sequence := fin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; s := s->sort() ; var res : int := 0 ; var j : double := n - 1 ; for i : Integer.subrange(0, n-1) do ( while (j->compareTo(i)) > 0 & (s[i+1] + s[j+1]->compareTo(x)) > 0 do ( j := j - 1) ; if (j->compareTo(i)) > 0 then ( res := res + 1 ; j := j - 1 ) else ( break )) ; return ("" + ((res + (n - 2 * res)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def rl(T): return list(map(T,input().split())) def solve(X,S): if len(S)==0 : return 0 if len(S)==1 : return 1 if S[0]+S[-1]<=X : return 1+solve(X,S[1 : len(S)-1]) if S[-1]<=X : return 1+solve(X,S[0 : len(S)-1]) raise Exception def main(): sys.setrecursionlimit(100000) T,=rl(int) for C in range(1,T+1): N,X=rl(int) S=rl(int) S.sort() ans=solve(X,S) print('Case #%d: %d' %(C,ans)) pass main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; main(); operation rl(T : OclAny) : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (T)->apply(_x) )); operation solve(X : OclAny, S : OclAny) : OclAny pre: true post: true activity: if (S)->size() = 0 then ( return 0 ) else skip ; if (S)->size() = 1 then ( return 1 ) else skip ; if (S->first() + S->last()->compareTo(X)) <= 0 then ( return 1 + solve(X, S.subrange(1+1, (S)->size() - 1)) ) else skip ; if (S->last()->compareTo(X)) <= 0 then ( return 1 + solve(X, S.subrange(0+1, (S)->size() - 1)) ) else skip ; error ProgramException.newProgramException; operation main() pre: true post: true activity: sys.setrecursionlimit(100000) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name T)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name T)))))) ,)} := rl(OclType["int"]) ; for C : Integer.subrange(1, T + 1-1) do ( var N : OclAny := null; Sequence{N,X} := rl(OclType["int"]) ; S := rl(OclType["int"]) ; S := S->sort() ; var ans : OclAny := solve(X, S) ; execute (StringLib.format('Case #%d: %d',Sequence{C, ans}))->display()) ; skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(dsize,fsizes): cnt=0 fsizes.sort(reverse=True) while True : s,k=None,None for i in range(len(fsizes)): if fsizes[i]!=-1 : s,k=fsizes[i],i break if not s : return cnt if k>100 : fsizes=fsizes[k :] k=0 fsizes[k]=-1 cnt+=1 d=None for i in range(len(fsizes)): if dsize-s>=fsizes[i]and fsizes[i]!=-1 : d=fsizes[i] j=i break if d and d!=-1 : fsizes[j]=-1 return cnt import sys infname=sys.argv[1] with open(infname)as inf : with open(infname.replace('.in','.out'),'w')as outf : T=int(inf.readline()) for t in range(1,T+1): n,dsize=map(int,inf.readline().split()) fsizes=map(int,inf.readline().split()) outf.write('Case #{}:{}\n'.format(t,solve(dsize,fsizes))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var infname : (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) := (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) ; try (var Math_PINFINITY : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(infname)); try (var outf : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(infname.replace('.in', '.out'))); var T : int := ("" + ((Math_PINFINITY.readLine())))->toInteger() ; for t : Integer.subrange(1, T + 1-1) do ( var n : OclAny := null; Sequence{n,dsize} := (Math_PINFINITY.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; fsizes := (Math_PINFINITY.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; outf.write(StringLib.interpolateStrings('Case #{}:{} ', Sequence{t, solve(dsize, fsizes)})))) catch (_e : OclException) do skip) catch (_e : OclException) do skip; operation solve(dsize : OclAny, fsizes : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; fsizes := fsizes->sort() ; while true do ( var s : OclAny := null; var k : OclAny := null; Sequence{s,k} := Sequence{null,null} ; for i : Integer.subrange(0, (fsizes)->size()-1) do ( if fsizes[i+1] /= -1 then ( var s : OclAny := null; var k : OclAny := null; Sequence{s,k} := Sequence{fsizes[i+1],i} ; break ) else skip) ; if not(s) then ( return cnt ) else skip ; if k > 100 then ( fsizes := fsizes.subrange(k+1) ; var k : int := 0 ) else skip ; fsizes[k+1] := -1 ; cnt := cnt + 1 ; var d : OclAny := null ; for i : Integer.subrange(0, (fsizes)->size()-1) do ( if (dsize - s->compareTo(fsizes[i+1])) >= 0 & fsizes[i+1] /= -1 then ( d := fsizes[i+1] ; var j : OclAny := i ; break ) else skip) ; if d & d /= -1 then ( fsizes[j+1] := -1 ) else skip) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys fin=open(sys.argv[1],"r") fout=open("p1.out","w") T=int(fin.readline()) for i in xrange(T): N,X=map(int,fin.readline().split()) S=sorted(map(int,fin.readline().split())) cur=0 for j in reversed(xrange(len(S))): if j<=cur : break elif S[cur]+S[j]<=X : cur+=1 fout.write("Case #"+str(i+1)+": "+str(N-cur)+"\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var fin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) ; var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("p1.out")) ; var T : int := ("" + ((fin.readLine())))->toInteger() ; for i : xrange(T) do ( var N : OclAny := null; var X : OclAny := null; Sequence{N,X} := (fin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : Sequence := (fin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var cur : int := 0 ; for j : (xrange((S)->size()))->reverse() do ( if (j->compareTo(cur)) <= 0 then ( break ) else (if (S[cur+1] + S[j+1]->compareTo(X)) <= 0 then ( cur := cur + 1 ) else skip)) ; fout.write("Case #" + ("" + ((i + 1))) + ": " + ("" + ((N - cur))) + "\n")); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for tc in range(int(input())): (N,X)=(int(x)for x in input().split()) S=[int(x)for x in input().split()] S=list(reversed(sorted(S))) res=0 while S : a=S[0] found=False for i,b in enumerate(S): if i>0 and a+b<=X : del S[i] del S[0] res+=1 found=True break if not found : del S[0] res+=1 print('Case #{}:{}'.format(tc+1,res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for tc : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( ; var Sequence{N, X} : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var S : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; S := ((S->sort())->reverse()) ; var res : int := 0 ; while S do ( var a : OclAny := S->first() ; var found : boolean := false ; for _tuple : Integer.subrange(1, (S)->size())->collect( _indx | Sequence{_indx-1, (S)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if i > 0 & (a + b->compareTo(X)) <= 0 then ( execute (S[i+1])->isDeleted() ; execute (S->first())->isDeleted() ; res := res + 1 ; found := true ; break ) else skip) ; if not(found) then ( execute (S->first())->isDeleted() ; res := res + 1 ) else skip) ; execute (StringLib.interpolateStrings('Case #{}:{}', Sequence{tc + 1, res}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math primes=[] for p in range(2,10001): for m in range(2,math.floor(math.sqrt(p))+1): if p % m==0 : break else : primes.append(p) targ=int(input()) while targ!=0 : ans=0 for p in range(len(primes)): if primes[p]>targ : break tempsum=0 for l in range(p,len(primes)): tempsum+=primes[l] if tempsum>targ : break elif tempsum==targ : ans+=1 break print(ans) targ=int(input()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var primes : Sequence := Sequence{} ; for p : Integer.subrange(2, 10001-1) do ((compound_stmt for (exprlist (expr (atom (name m)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name math)) (trailer . (name floor) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name math)) (trailer . (name sqrt) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p)))))))) ))))))))) )))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name p))) % (expr (atom (name m))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name primes)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p)))))))) )))))))))))))))) ; var targ : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while targ /= 0 do ( var ans : int := 0 ; for p : Integer.subrange(0, (primes)->size()-1) do ( if (primes[p+1]->compareTo(targ)) > 0 then ( break ) else skip ; var tempsum : int := 0 ; for l : Integer.subrange(p, (primes)->size()-1) do ( tempsum := tempsum + primes[l+1] ; if (tempsum->compareTo(targ)) > 0 then ( break ) else (if tempsum = targ then ( ans := ans + 1 ; break ) else skip))) ; execute (ans)->display() ; targ := ("" + (((OclFile["System.in"]).readLine())))->toInteger()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=map(int,input().split()) bin_x=format(x & y,'032b') bin_x1=format(x | y,'032b') bin_x2=format(x ^ y,'032b') print(bin_x) print(bin_x1) print(bin_x2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var bin_x : String := (MathLib.bitwiseAnd(x, y) + "") ; var bin_x1 : String := (MathLib.bitwiseOr(x, y) + "") ; var bin_x2 : String := (MathLib.bitwiseXor(x, y) + "") ; execute (bin_x)->display() ; execute (bin_x1)->display() ; execute (bin_x2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def prime(n): prime_flag=[0 for i in range(n+1)] prime_list=[] for i in range(2,n+1): if prime_flag[i]==0 : prime_list.append(i) temp=1 while temp*i<=n : prime_flag[temp*i]=1 temp+=1 return prime_list prime_list=prime(10000) answer=[] while True : n=int(input()) if not n : break left=0 right=0 count=2 ans=0 while True : if n==count : ans+=1 if left==right==len(prime_list)-1 : break elif count+prime_list[right+1]<=n and right!=len(prime_list)-1 : right+=1 count+=prime_list[right] else : if left==right : left+=1 right+=1 count=prime_list[left] else : count-=prime_list[left] left+=1 answer.append(ans) for i in answer : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; prime_list := prime(10000) ; var answer : Sequence := Sequence{} ; while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(n) then ( break ) else skip ; var left : int := 0 ; var right : int := 0 ; var count : int := 2 ; var ans : int := 0 ; while true do ( if n = count then ( ans := ans + 1 ) else skip ; if left = right & (right == (prime_list)->size() - 1) then ( break ) else (if (count + prime_list[right + 1+1]->compareTo(n)) <= 0 & right /= (prime_list)->size() - 1 then ( right := right + 1 ; count := count + prime_list[right+1] ) else ( if left = right then ( left := left + 1 ; right := right + 1 ; count := prime_list[left+1] ) else ( count := count - prime_list[left+1] ; left := left + 1 ) ) ) ) ; execute ((ans) : answer)) ; for i : answer do ( execute (i)->display()); operation prime(n : OclAny) : OclAny pre: true post: true activity: var prime_flag : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; var prime_list : Sequence := Sequence{} ; for i : Integer.subrange(2, n + 1-1) do ( if prime_flag[i+1] = 0 then ( execute ((i) : prime_list) ; var temp : int := 1 ; while (temp * i->compareTo(n)) <= 0 do ( prime_flag[temp * i+1] := 1 ; temp := temp + 1) ) else skip) ; return prime_list; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict class Primes(): def __init__(self,N): self.N=N self.prime={i for i in range(2,self.N+1)} for i in range(2,self.N+1): if i in self.prime : for j in range(i*2,self.N+1,i): if j in self.prime : self.prime.remove(j) def show_primes(self): return sorted(list(self.prime)) def main(): D=defaultdict(int) P=Primes(10000) prime=P.show_primes() prime.insert(0,0) L=len(prime) for i in range(1,L): prime[i]+=prime[i-1] for i in range(L): for j in range(i+1,L): D[prime[j]-prime[i]]+=1 V=1 while V!=0 : V=int(input()) if V==0 : continue print(D[V]) return if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class Primes { static operation newPrimes() : Primes pre: true post: Primes->exists( _x | result = _x ); attribute N : OclAny := N; attribute prime : Set := Integer.subrange(2, self.N + 1-1)->select(i | true)->collect(i | i)->asSet(); operation initialise(N : OclAny) : pre: true post: true activity: self.N := N ; self.prime := Integer.subrange(2, self.N + 1-1)->select(i | true)->collect(i | i)->asSet() ; for i : Integer.subrange(2, self.N + 1-1) do ( if (self.prime)->includes(i) then ( for j : Integer.subrange(i * 2, self.N + 1-1)->select( $x | ($x - i * 2) mod i = 0 ) do ( if (self.prime)->includes(j) then ( (expr (atom (name self)) (trailer . (name prime)) (trailer . (name remove) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) ) else skip) ) else skip); return self; operation show_primes() : OclAny pre: true post: true activity: return (self.prime)->sort(); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var D : OclAny := defaultdict(OclType["int"]) ; var P : Primes := (Primes.newPrimes()).initialise(10000) ; var prime : OclAny := P.show_primes() ; prime := prime.insertAt(0+1, 0) ; var L : int := (prime)->size() ; for i : Integer.subrange(1, L-1) do ( prime[i+1] := prime[i+1] + prime[i - 1+1]) ; for i : Integer.subrange(0, L-1) do ( for j : Integer.subrange(i + 1, L-1) do ( D[prime[j+1] - prime[i+1]+1] := D[prime[j+1] - prime[i+1]+1] + 1)) ; var V : int := 1 ; while V /= 0 do ( V := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if V = 0 then ( continue ) else skip ; execute (D[V+1])->display()) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10000000) MOD=10**9+7 INF=10**15 def sieve(n): if n==1 : return[] primes=[1 if i % 2==1 else 0 for i in range(n+1)] primes[1]=0 primes[2]=1 for i in range(3,n+1,2): if i*i>n : break if primes[i]: for j in range(i*i,n+1,i): primes[j]=0 return[p for p in range(2,n+1)if primes[p]==1] primes=sieve(10005) P=len(primes) def solve(N): ans=0 r=0 tot=0 for l in range(P): if primes[l]>N : break while r

pow(9) + 7 ; var INF : double := (10)->pow(15) ; skip ; primes := sieve(10005) ; var P : int := (primes)->size() ; skip ; while true do ( N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( exit() ) else skip ; solve(N)); operation sieve(n : OclAny) : OclAny pre: true post: true activity: if n = 1 then ( return Sequence{} ) else skip ; var primes : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (if i mod 2 = 1 then 1 else 0 endif)) ; primes[1+1] := 0 ; primes[2+1] := 1 ; for i : Integer.subrange(3, n + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if (i * i->compareTo(n)) > 0 then ( break ) else skip ; if primes[i+1] then ( for j : Integer.subrange(i * i, n + 1-1)->select( $x | ($x - i * i) mod i = 0 ) do ( primes[j+1] := 0) ) else skip) ; return Integer.subrange(2, n + 1-1)->select(p | primes[p+1] = 1)->collect(p | (p)); operation solve(N : OclAny) pre: true post: true activity: var ans : int := 0 ; var r : int := 0 ; var tot : int := 0 ; for l : Integer.subrange(0, P-1) do ( if (primes[l+1]->compareTo(N)) > 0 then ( break ) else skip ; while (r->compareTo(P)) < 0 & (tot + primes[r+1]->compareTo(N)) <= 0 do ( tot := tot + primes[r+1] ; r := r + 1) ; if tot = N then ( ans := ans + 1 ) else skip ; tot := tot - primes[l+1]) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print((n+2)//2) i=1 j=1 for x in range(n): print(i,j) if x % 2==0 : i=i+1 else : j=j+1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((n + 2) div 2)->display() ; var i : int := 1 ; var j : int := 1 ; for x : Integer.subrange(0, n-1) do ( execute (i)->display() ; if x mod 2 = 0 then ( i := i + 1 ) else ( j := j + 1 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def prime_list(n): is_prime=[True]*(n+1) is_prime[0]=False is_prime[1]=False for i in range(2,int(n**0.5)+1): if not is_prime[i]: continue for j in range(i*2,n+1,i): is_prime[j]=False return[i for i in range(n+1)if is_prime[i]] def subset_sum_problem(prime_list,length): subset_dict={} for i in range(length): now=0 for j in range(i,length): now+=prime_list[j] if not now in subset_dict : subset_dict[now]=1 else : subset_dict[now]=subset_dict[now]+1 return subset_dict if __name__=='__main__' : prime_list=prime_list(10000) length=len(prime_list) subset_dict=subset_sum_problem(prime_list,length) ans=[] while(True): n=int(input()) if n==0 : break if not n in subset_dict : ans.append(0) else : ans.append(subset_dict[n]) print(*ans,sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( prime_list := prime_list(10000) ; length := (prime_list)->size() ; subset_dict := subset_sum_problem(prime_list, length) ; var ans : Sequence := Sequence{} ; while (true) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; if not((subset_dict)->includes(n)) then ( execute ((0) : ans) ) else ( execute ((subset_dict[n+1]) : ans) )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ) else skip; operation prime_list(n : OclAny) : OclAny pre: true post: true activity: var is_prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (n + 1)) ; is_prime->first() := false ; is_prime[1+1] := false ; for i : Integer.subrange(2, ("" + (((n)->pow(0.5))))->toInteger() + 1-1) do ( if not(is_prime[i+1]) then ( continue ) else skip ; for j : Integer.subrange(i * 2, n + 1-1)->select( $x | ($x - i * 2) mod i = 0 ) do ( is_prime[j+1] := false)) ; return Integer.subrange(0, n + 1-1)->select(i | is_prime[i+1])->collect(i | (i)); operation subset_sum_problem(prime_list : OclAny, length : OclAny) : OclAny pre: true post: true activity: var subset_dict : OclAny := Set{} ; for i : Integer.subrange(0, length-1) do ( var now : int := 0 ; for j : Integer.subrange(i, length-1) do ( now := now + prime_list[j+1] ; if not((subset_dict)->includes(now)) then ( subset_dict[now+1] := 1 ) else ( subset_dict[now+1] := subset_dict[now+1] + 1 ))) ; return subset_dict; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import atan2,pi N,*XY=map(int,open(0).read().split()) XY=list(zip(*[iter(XY)]*2)) for i,(x,y)in enumerate(XY): D=sorted(atan2(X-x,Y-y)for j,(X,Y)in enumerate(XY)if j!=i) D.append(D[0]+2*pi) ans=0 for a,b in zip(D,D[1 :]): if b-a>=pi : ans=(b-a)-pi print(ans/(2*pi)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var XY : OclAny := null; Sequence{N,XY} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var XY : Sequence := (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name XY)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name XY)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name XY)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))`third->at(_indx)} )) ; for _tuple : Integer.subrange(1, (XY)->size())->collect( _indx | Sequence{_indx-1, (XY)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{x, y} : OclAny := _tuple->at(_indx); var D : Sequence := (argument (test (logical_test (comparison (expr (atom (name atan2)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name X))) - (expr (atom (name x)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name Y))) - (expr (atom (name y))))))))) ))))))) (comp_for for (exprlist (expr (atom (name j))) , (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name X)))))) , (test (logical_test (comparison (expr (atom (name Y))))))) )))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name XY)))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name j)))) != (comparison (expr (atom (name i))))))))))->sort() ; execute ((D->first() + 2 * pi) : D) ; var ans : int := 0 ; for _tuple : Integer.subrange(1, D->size())->collect( _indx | Sequence{D->at(_indx), D->tail()->at(_indx)} ) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if (b - a->compareTo(pi)) >= 0 then ( ans := (b - a) - pi ) else skip) ; execute (ans / (2 * pi))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import exit,stderr,setrecursionlimit from functools import reduce from itertools import* from collections import defaultdict from bisect import bisect from math import atan2,pi def read(): return int(input()) def reads(): return[int(x)for x in input().split()] setrecursionlimit(1000000) p=[] N=read() for _ in range(N): (x,y)=reads() p.append((x,y)) for i in range(N): (x,y)=p[i] (b1,e1)=(0,pi) (b2,e2)=(pi,2*pi) for j in range(N): if j==i : continue (z,w)=p[j] th=(atan2(w-y,z-x)+pi/2)%(2*pi) if th<=pi : b1=max(b1,th) e2=min(e2,th+pi) else : e1=min(e1,th-pi) b2=max(b2,th) result=(max(0,e1-b1)+max(0,e2-b2))/2/pi print("{:.20f}".format(result)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; setrecursionlimit(1000000) ; var p : Sequence := Sequence{} ; var N : OclAny := read() ; for _anon : Integer.subrange(0, N-1) do ( ; var Sequence{x, y} : OclAny := reads() ; execute ((Sequence{x, y}) : p)) ; for i : Integer.subrange(0, N-1) do ( ; Sequence{x, y} := p[i+1] ; var Sequence{b1, e1} : OclAny := Sequence{0, pi} ; var Sequence{b2, e2} : OclAny := Sequence{pi, 2 * pi} ; for j : Integer.subrange(0, N-1) do ( if j = i then ( continue ) else skip)) ; var Sequence{z, w} : OclAny := p[j+1]; operation read() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation reads() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,copy import numpy as np HUGE=2147483647 HUGEL=9223372036854775807 ABC="abcdefghijklmnopqrstuvwxyz" def main(): nt=200000 n=int(input()) xy=np.empty((2,n)) for i in range(n): x,y=map(int,input().split()) xy[:,i]=[x,y] x_rot=np.zeros((nt,n)) thetas=np.linspace(0,2.0*np.pi,nt,endpoint=False) cnt=[0 for i in range(n)] for i in range(n): x_rot[:,i]=xy[0,i]*np.cos(thetas)-xy[1,i]*np.sin(thetas) am=np.argmax(x_rot,axis=1) for t in range(nt): cnt[am[t]]+=1 for i in range(n): print("%.10f" %(cnt[i]/nt)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var HUGE : int := 2147483647 ; var HUGEL : int := 9223372036854775807 ; var ABC : String := "abcdefghijklmnopqrstuvwxyz" ; skip ; main(); operation main() pre: true post: true activity: var nt : int := 200000 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var xy : Sequence := MatrixLib.singleValueMatrix(Sequence{2, n}, 0.0) ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; xy->collect( _r | _r[i+1] ) := Sequence{x}->union(Sequence{ y })) ; var x_rot : Sequence := MatrixLib.singleValueMatrix(Sequence{nt, n}, 0.0) ; var thetas : Sequence := ; var cnt : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( x_rot->collect( _r | _r[i+1] ) := MatrixLib.elementwiseMult(MatrixLib.elementwiseApply(thetas, lambda x : double in (x->cos())), xy->first()[i+1]) - MatrixLib.elementwiseMult(MatrixLib.elementwiseApply(thetas, lambda x : double in (x->sin())), xy[1+1][i+1])) ; var am : (trailer . (name argmax) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x_rot))))))) , (argument (test (logical_test (comparison (expr (atom (name axis)))))) = (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ))) := ; for t : Integer.subrange(0, nt-1) do ( cnt[am[t+1]+1] := cnt[am[t+1]+1] + 1) ; for i : Integer.subrange(0, n-1) do ( execute (StringLib.format("%.10f",(cnt[i+1] / nt)))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from scipy.spatial import ConvexHull as CH import numpy as np norm=np.linalg.norm n,*t=map(int,open(0).read().split()) a=np.reshape(t,(n,2)) try : h=CH(a).vertices except : a=a-10**6 if np.all(a[:,0]==a[0,0]): a=np.fliplr(a) b=a[:,0] M=np.argmax(b) m=np.argmin(b) for i in range(n): print(0.5*(i in(m,M))) exit() l=len(h) for i in range(n): if i in h : j=np.where(h==i)[0] f,s,t=a[h[j-1]],a[i],a[h[(j+1)% l]] print(np.arccos(np.inner(t-s,s-f)/(norm(t-s)*norm(s-f)))[0,0]/(2*np.pi)) else : print(0.) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var norm : OclAny := np.linalg.norm ; var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : (trailer . (name reshape) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t))))))) , (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name n)))))) , (test (logical_test (comparison (expr (atom (number (integer 2)))))))) )))))))) ))) := MatrixLib.fillMatrixFrom(t, Sequence{n, 2}) ; try ( var h : OclAny := CH(a).vertices) catch (_e : OclException) do ( a := a - (10)->pow(6) ; if then ( a := ) else skip ; var b : Sequence := a->collect( _r | _r->first() ) ; var M : (trailer . (name argmax) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) ))) := ; var m : (trailer . (name argmin) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) ))) := ; for i : Integer.subrange(0, n-1) do ( execute (0.5 * ((Sequence{m, M})->includes(i)))->display()) ; exit()) ; var l : int := (h)->size() ; for i : Integer.subrange(0, n-1) do ( if (h)->includes(i) then ( var j : OclAny := np.where(h = i)->first() ; var f : OclAny := null; var s : OclAny := null; var t : OclAny := null; Sequence{f,s,t} := Sequence{a[h[j - 1+1]+1],a[i+1],a[h[(j + 1) mod l+1]+1]} ; execute (np.arccos( / (norm(t - s) * norm(s - f)))->first()->first() / (2 * MathLib.piValue()))->display() ) else ( execute (0.)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter import numpy as np p=2.5e5 n=int(input()) l=np.array([list(map(int,input().split()))for _ in range(n)],dtype=np.float32) ans=np.zeros(n) a=np.linspace(0,2*np.pi,p,endpoint=False) b=np.array([np.sin(a),np.cos(a)],dtype=np.float32) for i,v in Counter(np.argmax(np.dot(l,b),axis=0)).items(): ans[i]+=v/p print('\n'.join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var p : double := ("2.5e5")->toReal() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))), (argument (test (logical_test (comparison (expr (atom (name dtype)))))) = (test (logical_test (comparison (expr (atom (name np)) (trailer . (name float32)))))))) ; var ans : Sequence := MatrixLib.singleValueMatrix(n, 0.0) ; var a : Sequence := ; var b : Sequence := (Sequence{MatrixLib.elementwiseApply(a, lambda x : double in (x->sin()))}->union(Sequence{ MatrixLib.elementwiseApply(a, lambda x : double in (x->cos())) }), (argument (test (logical_test (comparison (expr (atom (name dtype)))))) = (test (logical_test (comparison (expr (atom (name np)) (trailer . (name float32)))))))) ; for _tuple : Counter()->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); ans[i+1] := ans[i+1] + v / p) ; execute (StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) print(f'{x:032b}') print(f'{~x & 0xffffffff:032b}') print(f'{x<<1 & 0xffffffff:032b}') print(f'{x>>1:032b}') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (StringLib.formattedString('{x:032b}'))->display() ; execute (StringLib.formattedString('{~x & 0xffffffff:032b}'))->display() ; execute (StringLib.formattedString('{x<<1 & 0xffffffff:032b}'))->display() ; execute (StringLib.formattedString('{x>>1:032b}'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- alp=['************','*qwertyuiop*','*asdfghjkl**','*zxcvbnm****','************'] _alp=''.join(alp) def check(now,nxt): a,b=_alp.find(now)//12,_alp.find(now)% 12 c,d=_alp.find(nxt)//12,_alp.find(nxt)% 12 q1=_log[-1] q2='L' if d<=5 else 'R' log.append(q2) if abs(a-c)+abs(b-d)<=1 : _log.append(q1) else : _log.append(q2) while 1 : s=input() if s=='#' : break log=['L' if _alp.find(s[0])% 12<=5 else 'R'] _log=[log[0]] for i in range(len(s)-1): check(s[i],s[i+1]) count=0 for x,y in zip(log,_log): if x!=y : count+=1 c=log[0] ans=0 for v in log : if c!=v : c=v ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var alp : Sequence := Sequence{'************'}->union(Sequence{'*qwertyuiop*'}->union(Sequence{'*asdfghjkl**'}->union(Sequence{'*zxcvbnm****'}->union(Sequence{ '************' })))) ; var _alp : String := StringLib.sumStringsWithSeparator((alp), '') ; skip ; while 1 do ( var s : String := (OclFile["System.in"]).readLine() ; if s = '#' then ( break ) else skip ; var log : Sequence := Sequence{ if _alp->indexOf(s->first()) - 1 mod 12 <= 5 then 'L' else 'R' endif } ; var _log : Sequence := Sequence{ log->first() } ; for i : Integer.subrange(0, (s)->size() - 1-1) do ( check(s[i+1], s[i + 1+1])) ; var count : int := 0 ; for _tuple : Integer.subrange(1, log->size())->collect( _indx | Sequence{log->at(_indx), _log->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if x /= y then ( count := count + 1 ) else skip) ; var c : OclAny := log->first() ; var ans : int := 0 ; for v : log do ( if c /= v then ( c := v ; ans := ans + 1 ) else skip) ; execute (ans)->display()); operation check(now : OclAny, nxt : OclAny) pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{_alp->indexOf(now) - 1 div 12,_alp->indexOf(now) - 1 mod 12} ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := Sequence{_alp->indexOf(nxt) - 1 div 12,_alp->indexOf(nxt) - 1 mod 12} ; var q1 : OclAny := _log->last() ; var q2 : String := if d <= 5 then 'L' else 'R' endif ; execute ((q2) : log) ; if (a - c)->abs() + (b - d)->abs() <= 1 then ( execute ((q1) : _log) ) else ( execute ((q2) : _log) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : x=list(input()) if(x[0]=="#"): break else : left="qwertasdfgzxcvb" right="yuiophjklnm" cnt=0 for i in range(len(x)-1): L=x[i]in left and x[i+1]in left R=x[i]in right and x[i+1]in right if(L or R): pass else : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var x : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if (x->first() = "#") then ( break ) else ( var left : String := "qwertasdfgzxcvb" ; var right : String := "yuiophjklnm" ; var cnt : int := 0 ; for i : Integer.subrange(0, (x)->size() - 1-1) do ( var L : boolean := (left)->characters()->includes(x[i+1]) & (left)->characters()->includes(x[i + 1+1]) ; var R : boolean := (right)->characters()->includes(x[i+1]) & (right)->characters()->includes(x[i + 1+1]) ; if (L or R) then ( skip ) else ( cnt := cnt + 1 )) ; execute (cnt)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- LEFT=0 RIGHT=1 key_dict={LEFT :["q","w","e","r","t","a","s","d","f","g","z","x","c","v","b",],RIGHT :["y","u","i","o","p","h","j","k","k","l","n","m",],} def get_input(): data_input=input() return data_input def count_chage_num(data_input): change_num=0 hand_place=None for c in data_input : if c in key_dict[LEFT]: if hand_place!=LEFT : change_num+=1 hand_place=LEFT else : if hand_place!=RIGHT : change_num+=1 hand_place=RIGHT if change_num!=0 : change_num-=1 return change_num if __name__=="__main__" : while True : data_input=get_input() if data_input[0]=="#" : break change_num=count_chage_num(data_input) print(change_num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var LEFT : int := 0 ; var RIGHT : int := 1 ; var key_dict : Map := Map{ LEFT |-> Sequence{"q"}->union(Sequence{"w"}->union(Sequence{"e"}->union(Sequence{"r"}->union(Sequence{"t"}->union(Sequence{"a"}->union(Sequence{"s"}->union(Sequence{"d"}->union(Sequence{"f"}->union(Sequence{"g"}->union(Sequence{"z"}->union(Sequence{"x"}->union(Sequence{"c"}->union(Sequence{"v"}->union(Sequence{ "b" })))))))))))))) }->union((dictorsetmaker (test (logical_test (comparison (expr (atom (name RIGHT)))))) : (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom "y"))))) , (test (logical_test (comparison (expr (atom "u"))))) , (test (logical_test (comparison (expr (atom "i"))))) , (test (logical_test (comparison (expr (atom "o"))))) , (test (logical_test (comparison (expr (atom "p"))))) , (test (logical_test (comparison (expr (atom "h"))))) , (test (logical_test (comparison (expr (atom "j"))))) , (test (logical_test (comparison (expr (atom "k"))))) , (test (logical_test (comparison (expr (atom "k"))))) , (test (logical_test (comparison (expr (atom "l"))))) , (test (logical_test (comparison (expr (atom "n"))))) , (test (logical_test (comparison (expr (atom "m"))))) ,) ]))))) ,)) ; skip ; skip ; if __name__ = "__main__" then ( while true do ( data_input := get_input() ; if data_input->first() = "#" then ( break ) else skip ; change_num := count_chage_num(data_input) ; execute (change_num)->display()) ) else skip; operation get_input() : OclAny pre: true post: true activity: var data_input : String := (OclFile["System.in"]).readLine() ; return data_input; operation count_chage_num(data_input : OclAny) : OclAny pre: true post: true activity: var change_num : int := 0 ; var hand_place : OclAny := null ; for c : data_input->characters() do ( if (key_dict[LEFT+1])->includes(c) then ( if hand_place /= LEFT then ( change_num := change_num + 1 ) else skip ; hand_place := LEFT ) else ( if hand_place /= RIGHT then ( change_num := change_num + 1 ) else skip ; hand_place := RIGHT )) ; if change_num /= 0 then ( change_num := change_num - 1 ) else skip ; return change_num; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**3 eps=1.0/10**10 mod=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] def f(c): return c in 'qwertasdfgzxcvb' while True : s=S() if s=='#' : break t=f(s[0]) r=0 for c in s[1 :]: ct=f(c) if t!=ct : r+=1 t=ct rr.append(r) return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(3) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; skip ; while true do ( s := S() ; if s = '#' then ( break ) else skip ; var t : String := f(s->first()) ; var r : int := 0 ; for c : s->tail() do ( var ct : String := f(c) ; if t /= ct then ( r := r + 1 ; t := ct ) else skip) ; execute ((r) : rr)) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil n=int(input()) m=ceil((n+1)/2) print(m) for i in range(1,m+1): print(1,i) for i in range(2,m+1): if i+m-1>n : break print(i,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : OclAny := ceil((n + 1) / 2) ; execute (m)->display() ; for i : Integer.subrange(1, m + 1-1) do ( execute (1)->display()) ; for i : Integer.subrange(2, m + 1-1) do ( if (i + m - 1->compareTo(n)) > 0 then ( break ) else skip ; execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- rh=set("yuiophjklnm") while 1 : t=input() if t=="#" : break c=0 for(i,j)in enumerate(t): if i==0 : if j in rh : r=True else : r=False else : if(j in rh and not r)or(not j in rh and r): c+=1 r=j in rh print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var rh : Set := Set{}->union(("yuiophjklnm")) ; while 1 do ( var t : String := (OclFile["System.in"]).readLine() ; if t = "#" then ( break ) else skip ; var c : int := 0 ; for Sequence{i, j} : Integer.subrange(1, (t)->size())->collect( _indx | Sequence{_indx-1, (t)->at(_indx)} ) do ( if i = 0 then ( if (rh)->includes(j) then ( var r : boolean := true ) else ( r := false ) ) else ( if ((rh)->includes(j) & not(r)) or (not((rh)->includes(j)) & r) then ( c := c + 1 ) else skip ; r := (rh)->includes(j) )) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- length,tour=input(),input() print('YES' if tour.count('SF')>tour.count('FS')else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var length : OclAny := null; var tour : OclAny := null; Sequence{length,tour} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine()} ; execute (if (tour->count('SF')->compareTo(tour->count('FS'))) > 0 then 'YES' else 'NO' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input('')) s=input('') c1=0 c=0 for i in range(n-1): if s[i]=='S' and s[i+1]=='F' : c+=1 if s[i]=='F' and s[i+1]=='S' : c1+=1 if c>c1 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; var s : String := (OclFile["System.in"]).readLine('') ; var c1 : int := 0 ; var c : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if s[i+1] = 'S' & s[i + 1+1] = 'F' then ( c := c + 1 ) else skip ; if s[i+1] = 'F' & s[i + 1+1] = 'S' then ( c1 := c1 + 1 ) else skip) ; if (c->compareTo(c1)) > 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input("")) s=input() a=0 b=0 for i in range(n-1): if(s[i]=='S' and s[i+1]=='F'): a+=1 elif(s[i]=='F' and s[i+1]=='S'): b+=1 if(a>b): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine(""))))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var a : int := 0 ; var b : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if (s[i+1] = 'S' & s[i + 1+1] = 'F') then ( a := a + 1 ) else (if (s[i+1] = 'F' & s[i + 1+1] = 'S') then ( b := b + 1 ) else skip)) ; if ((a->compareTo(b)) > 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) flight=input() s_f=0 f_s=0 for i in range(1,len(flight)): if flight[i]=='F' and flight[i-1]=='S' : s_f+=1 elif flight[i]=='S' and flight[i-1]=='F' : f_s+=1 if f_ss_f : print("NO") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var flight : String := (OclFile["System.in"]).readLine() ; var s_f : int := 0 ; var f_s : int := 0 ; for i : Integer.subrange(1, (flight)->size()-1) do ( if flight[i+1] = 'F' & flight[i - 1+1] = 'S' then ( s_f := s_f + 1 ) else (if flight[i+1] = 'S' & flight[i - 1+1] = 'F' then ( f_s := f_s + 1 ) else skip)) ; if (f_s->compareTo(s_f)) < 0 then ( execute ("YES")->display() ) else (if (f_s->compareTo(s_f)) > 0 then ( execute ("NO")->display() ) else ( execute ("NO")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import combinations from bisect import bisect_right def main(): N,*L=map(int,open(0).read().split()) L.sort() print(sum(bisect_right(L,L[i]+L[j]-1,lo=j+1)-(j+1)for i,j in combinations(range(N),2))) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var L : OclAny := null; Sequence{N,L} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; L := L->sort() ; execute (((argument (test (logical_test (comparison (expr (expr (atom (name bisect_right)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L))))))) , (argument (test (logical_test (comparison (expr (expr (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name lo)))))) = (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 1)))))))))) )))) - (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 1))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name combinations)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): l=list(map(int,input().split())) i=l.index(max(l))+1 l[i-1]=-1 j=l.index(max(l))+1 if(i==4 and j==3)or(i==3 and j==4)or(i==2 and j==1)or(i==1 and j==2): print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var i : int := l->indexOf((l)->max()) - 1 + 1 ; l[i - 1+1] := -1 ; var j : int := l->indexOf((l)->max()) - 1 + 1 ; if (i = 4 & j = 3) or (i = 3 & j = 4) or (i = 2 & j = 1) or (i = 1 & j = 2) then ( execute ("NO")->display() ) else ( execute ("YES")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() a=s.count('SF') b=s.count('FS') if a>b : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var a : int := s->count('SF') ; var b : int := s->count('FS') ; if (a->compareTo(b)) > 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- bigres=[] t=int(input()) for m in range(t): n=int(input()) a=list(map(int,input().strip().split())) res=a[0]*a[1] for q in range(len(a)-1): res=max(res,(a[q]*a[q+1])) bigres+=[res] for i in range(len(bigres)): print(bigres[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var bigres : Sequence := Sequence{} ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for m : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : double := a->first() * a[1+1] ; for q : Integer.subrange(0, (a)->size() - 1-1) do ( res := Set{res, (a[q+1] * a[q + 1+1])}->max()) ; bigres := bigres + Sequence{ res }) ; for i : Integer.subrange(0, (bigres)->size()-1) do ( execute (bigres[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) l=list(map(int,input().split())) ans=0 for i in range(n-1): ans=max(ans,l[i]*l[i+1]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( ans := Set{ans, l[i+1] * l[i + 1+1]}->max()) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): a=int(input()) b=list(map(int,input().split())) print(max(b[i-1]*b[i]for i in range(1,a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (((argument (test (logical_test (comparison (expr (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))) * (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))))))))->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) m=max([x*y for x,y in zip(a[:-1],a[1 :])]) print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : OclAny := (Integer.subrange(1, a->front()->size())->collect( _indx | Sequence{a->front()->at(_indx), a->tail()->at(_indx)} )->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (x * y)))->max() ; execute (m)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from typing import List,Tuple,Union from math import ceil from typing import List def munimum_number_of_piles(n : int,n_values : List[int])->int : n_values.sort() pile=-1 for idx,s in enumerate(n_values): k=int(ceil((idx+1)/(s+1))) pile=max(pile,k) return pile n=int(input()) a=list(map(int,input().split())) print(munimum_number_of_piles(n,a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (munimum_number_of_piles(n, a))->display(); operation munimum_number_of_piles(n : int, n_values : List[OclType["int"]+1]) : int pre: true post: true activity: n_values := n_values->sort() ; var pile : int := -1 ; for _tuple : Integer.subrange(1, (n_values)->size())->collect( _indx | Sequence{_indx-1, (n_values)->at(_indx)} ) do (var _indx : int := 1; var idx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); var k : int := ("" + ((ceil((idx + 1) / (s + 1)))))->toInteger() ; pile := Set{pile, k}->max()) ; return pile; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) l=list(map(int,input().split())) print(max(l[i-1]*l[i]for i in range(1,n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (((argument (test (logical_test (comparison (expr (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))) * (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def __gcd(x,y): if x>y : small=y else : small=x for i in range(1,small+1): if((x % i==0)and(y % i==0)): gcd=i return gcd def FindLCM(a,b): return(a*b)/__gcd(a,b); def rangeDivisor(m,n,a,b): lcm=FindLCM(a,b) a_divisor=int(n/a-(m-1)/a) b_divisor=int(n/b-(m-1)/b) common_divisor=int(n/lcm-(m-1)/lcm) ans=a_divisor+b_divisor-common_divisor return ans m=3 n=11 a=2 b=3 ; print(rangeDivisor(m,n,a,b)) m=11 n=1000000 a=6 b=35 print(rangeDivisor(m,n,a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; m := 3 ; n := 11 ; a := 2 ; b := 3; ; execute (rangeDivisor(m, n, a, b))->display() ; m := 11 ; n := 1000000 ; a := 6 ; b := 35 ; execute (rangeDivisor(m, n, a, b))->display(); operation __gcd(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (x->compareTo(y)) > 0 then ( var small : OclAny := y ) else ( small := x ) ; for i : Integer.subrange(1, small + 1-1) do ( if ((x mod i = 0) & (y mod i = 0)) then ( var gcd : OclAny := i ) else skip) ; return gcd; operation FindLCM(a : OclAny, b : OclAny) pre: true post: true activity: return (a * b) / __gcd(a, b);; operation rangeDivisor(m : OclAny, n : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var lcm : OclAny := FindLCM(a, b) ; var a_divisor : int := ("" + ((n / a - (m - 1) / a)))->toInteger() ; var b_divisor : int := ("" + ((n / b - (m - 1) / b)))->toInteger() ; var common_divisor : int := ("" + ((n / lcm - (m - 1) / lcm)))->toInteger() ; var ans : double := a_divisor + b_divisor - common_divisor ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() t=',.?!' for i in t : s=s.replace(i,i+' ') s=' '.join(s.strip().split()) for i in t : s=s.replace(' '+i,i) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var t : String := ',.?!' ; for i : t->characters() do ( s := s.replace(i, i + ' ')) ; s := StringLib.sumStringsWithSeparator((s->trim().split()), ' ') ; for i : t->characters() do ( s := s.replace(' ' + i, i)) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() res=[] punctuation=[',','.','!','?'] for i in range(len(s)): if i>=1 : if s[i]=='' : if res[-1]!='' : res.append(s[i]) else : continue else : if s[i]in punctuation : if res[-1]=='' : res.pop() res.append(s[i]) res.append('') else : res.append(s[i]) else : if s[i]=='' : continue if s[i]in punctuation : continue else : res.append(s[i]) print(''.join(res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var res : Sequence := Sequence{} ; var punctuation : Sequence := Sequence{','}->union(Sequence{'.'}->union(Sequence{'!'}->union(Sequence{ '?' }))) ; for i : Integer.subrange(0, (s)->size()-1) do ( if i >= 1 then ( if s[i+1] = '' then ( if res->last() /= '' then ( execute ((s[i+1]) : res) ) else ( continue ) ) else ( if (punctuation)->includes(s[i+1]) then ( if res->last() = '' then ( res := res->front() ) else skip ; execute ((s[i+1]) : res) ; execute (('') : res) ) else ( execute ((s[i+1]) : res) ) ) ) else ( if s[i+1] = '' then ( continue ) else skip ; if (punctuation)->includes(s[i+1]) then ( continue ) else ( execute ((s[i+1]) : res) ) )) ; execute (StringLib.sumStringsWithSeparator((res), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy BIG_NUM=2000000000 MOD=1000000007 EPS=0.000000001 SIZE=32 POW=[None]*SIZE POW[0]=1 for i in range(1,SIZE): POW[i]=POW[i-1]*2 x=int(input()) BIT=[0]*SIZE for i in range(0,SIZE): if POW[(SIZE-1)-i]<=x : BIT[i]=1 x-=POW[(SIZE-1)-i] for i in range(SIZE): print("%d" %(BIT[i]),end="") print() for i in range(SIZE): print("%d" %(1-BIT[i]),end="") print() for i in range(1,SIZE): print("%d" %(BIT[i]),end="") print("0") print("0",end="") for i in range(SIZE-1): print("%d" %(BIT[i]),end="") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; var SIZE : int := 32 ; var POW : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, SIZE) ; POW->first() := 1 ; for i : Integer.subrange(1, SIZE-1) do ( POW[i+1] := POW[i - 1+1] * 2) ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var BIT : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, SIZE) ; for i : Integer.subrange(0, SIZE-1) do ( if (POW[(SIZE - 1) - i+1]->compareTo(x)) <= 0 then ( BIT[i+1] := 1 ; x := x - POW[(SIZE - 1) - i+1] ) else skip) ; for i : Integer.subrange(0, SIZE-1) do ( execute (StringLib.format("%d",(BIT[i+1])))->display()) ; execute (->display() ; for i : Integer.subrange(0, SIZE-1) do ( execute (StringLib.format("%d",(1 - BIT[i+1])))->display()) ; execute (->display() ; for i : Integer.subrange(1, SIZE-1) do ( execute (StringLib.format("%d",(BIT[i+1])))->display()) ; execute ("0")->display() ; execute ("0")->display() ; for i : Integer.subrange(0, SIZE - 1-1) do ( execute (StringLib.format("%d",(BIT[i+1])))->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check_bit(number,bit_index): return number |(1<0 and str2[len(str2)-1]=='' : pass elif str1[i]in pun and len(str2)>0 and str2[len(str2)-1]=='' : str2[len(str2)-1]=str1[i] str2.append('') elif str1[i]in pun : str2.append(str1[i]) str2.append('') else : str2.append(str1[i]) i+=1 print(''.join(str2)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation check_bit(number : OclAny, bit_index : OclAny) : OclAny pre: true post: true activity: return MathLib.bitwiseOr(number, (1 * (2->pow(bit_index - 1)))) = number; operation update_bit(number : OclAny, i : OclAny, is_bit : OclAny) : OclAny pre: true post: true activity: if is_bit->oclIsUndefined() then is_bit := true else skip; var value : int := if is_bit then 1 else 0 endif ; var mask : int := MathLib.bitwiseNot((1 * (2->pow(i)))) ; return MathLib.bitwiseOr((MathLib.bitwiseAnd(number, mask)), (value * (2->pow(i)))); operation main() pre: true post: true activity: var str1 : String := (OclFile["System.in"]).readLine() ; var str2 : Sequence := Sequence{} ; i := 0 ; var pun : Sequence := Sequence{'?'}->union(Sequence{','}->union(Sequence{'.'}->union(Sequence{ '!' }))) ; while (i->compareTo((str1)->size())) < 0 do ( if str1[i+1] = '' & (str2)->size() > 0 & str2[(str2)->size() - 1+1] = '' then ( skip ) else (if (pun)->includes(str1[i+1]) & (str2)->size() > 0 & str2[(str2)->size() - 1+1] = '' then ( str2[(str2)->size() - 1+1] := str1[i+1] ; execute (('') : str2) ) else (if (pun)->includes(str1[i+1]) then ( execute ((str1[i+1]) : str2) ; execute (('') : str2) ) else ( execute ((str1[i+1]) : str2) ) ) ) ; i := i + 1) ; execute (StringLib.sumStringsWithSeparator((str2), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checker(text): res='' for i in text : if i.isalpha(): res+=i space=True elif i==' ' and space : res+=i space=False elif i=='.' or i==',' or i=='!' or i=='?' : if not space : res=res.rstrip() res+=i res+=' ' space=False return res if __name__=='__main__' : ans=checker(input()) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var ans : OclAny := checker((OclFile["System.in"]).readLine()) ; execute (ans)->display() ) else skip; operation checker(text : OclAny) : OclAny pre: true post: true activity: var res : String := '' ; for i : text do ( if i->matches("[a-zA-Z]*") then ( res := res + i ; var space : boolean := true ) else (if i = ' ' & space then ( res := res + i ; space := false ) else (if i = '.' or i = ',' or i = '!' or i = '?' then ( if not(space) then ( res := StringLib.rightTrim(res) ) else skip ; res := res + i ; res := res + ' ' ; space := false ) else skip ) ) ) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- li=input() word_start=False for i in li : if i=="," or i=="?" or i=="!" or i=="." : word_start=True print(i,end="") elif i=="" : word_start=True continue else : if word_start : print(""+i,end="") word_start=False else : print(i,end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var li : String := (OclFile["System.in"]).readLine() ; var word_start : boolean := false ; for i : li->characters() do ( if i = "," or i = "?" or i = "!" or i = "." then ( word_start := true ; execute (i)->display() ) else (if i = "" then ( word_start := true ; continue ) else ( if word_start then ( execute ("" + i)->display() ; word_start := false ) else ( execute (i)->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict import sys def smallestKFreq(arr,n,k): mp=defaultdict(lambda : 0) for i in range(n): mp[arr[i]]+=1 res=sys.maxsize res1=sys.maxsize for key,values in mp.items(): if values==k : res=min(res,key) return res if res!=res1 else-1 arr=[2,2,1,3,1] k=2 n=len(arr) print(smallestKFreq(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; arr := Sequence{2}->union(Sequence{2}->union(Sequence{1}->union(Sequence{3}->union(Sequence{ 1 })))) ; k := 2 ; n := (arr)->size() ; execute (smallestKFreq(arr, n, k))->display(); operation smallestKFreq(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var mp : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; for i : Integer.subrange(0, n-1) do ( mp[arr[i+1]+1] := mp[arr[i+1]+1] + 1) ; var res : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; var res1 : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; for _tuple : mp->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var values : OclAny := _tuple->at(_indx); if values = k then ( res := Set{res, key}->min() ) else skip) ; return if res /= res1 then res else -1 endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input_methods=['clipboard','file','key'] using_method=0 input_method=input_methods[using_method] IN=lambda : map(int,input().split()) mod=1000000007 def main_b(): s=input() pp=0 na=0 for i,c in enumerate(s[: :-1]): cc=na+int(c) na=0 if cc<=4 : pp+=cc else : na=1 if i==len(s)-1 : pp+=1 pp+=10-cc print(pp) def main(): s=input() pmin=1000 mmin=0 s='0'+s for c in s[: :-1]: v=int(c) npmin=min(pmin+10-(v+1),mmin+10-v) nmmin=min(pmin+v+1,mmin+v) pmin=npmin mmin=nmmin return min(pmin,mmin) isTest=False def pa(v): if isTest : print(v) def input_clipboard(): import clipboard input_text=clipboard.get() input_l=input_text.splitlines() for l in input_l : yield l if __name__=="__main__" : if sys.platform=='ios' : if input_method==input_methods[0]: ic=input_clipboard() input=lambda : ic.__next__() elif input_method==input_methods[1]: sys.stdin=open('inputFile.txt') else : pass isTest=True else : pass ret=main() if ret is not None : print(ret) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input_methods : Sequence := Sequence{'clipboard'}->union(Sequence{'file'}->union(Sequence{ 'key' })) ; var using_method : int := 0 ; var input_method : OclAny := input_methods[using_method+1] ; var IN : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mod : int := 1000000007 ; skip ; skip ; var isTest : boolean := false ; skip ; skip ; if __name__ = "__main__" then ( if OclProcess.getEnvironmentProperty("OS") = 'ios' then ( if input_method = input_methods->first() then ( var ic : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.input_clipboard(_i)) ; var input : Function := lambda $$ : OclAny in (ic.__next__()) ) else (if input_method = input_methods[1+1] then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('inputFile.txt')) ) else ( skip ) ) ; isTest := true ) else ( skip ) ; var ret : OclAny := main() ; if not(ret <>= null) then ( execute (ret)->display() ) else skip ) else skip; operation main_b() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var pp : int := 0 ; var na : int := 0 ; for _tuple : Integer.subrange(1, (s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->size())->collect( _indx | Sequence{_indx-1, (s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); var cc : int := na + ("" + ((c)))->toInteger() ; na := 0 ; if cc <= 4 then ( pp := pp + cc ) else ( na := 1 ; if i = (s)->size() - 1 then ( pp := pp + 1 ) else skip ; pp := pp + 10 - cc )) ; execute (pp)->display(); operation main() : OclAny pre: true post: true activity: s := (OclFile["System.in"]).readLine() ; var pmin : int := 1000 ; var mmin : int := 0 ; s := '0' + s ; for c : s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( var v : int := ("" + ((c)))->toInteger() ; var npmin : OclAny := Set{pmin + 10 - (v + 1), mmin + 10 - v}->min() ; var nmmin : OclAny := Set{pmin + v + 1, mmin + v}->min() ; pmin := npmin ; mmin := nmmin) ; return Set{pmin, mmin}->min(); operation pa(v : OclAny) pre: true post: true activity: if isTest then ( execute (v)->display() ) else skip; operation input_clipboard(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; skip ; var input_text : OclAny := clipboard.get() ; var input_l : OclAny := input_text.splitlines() ; for l : input_l do ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return l); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() x=len(n) inf=10**9 dp=[[inf]*2 for _ in range(x+1)] dp[0][0]=0 dp[0][1]=1 for i in range(x): s=int(n[i]) dp[i+1][0]=min(dp[i][0]+s,dp[i][1]+10-s) dp[i+1][1]=min(dp[i][0]+s+1,dp[i][1]+9-s) print(dp[x][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var x : int := (n)->size() ; var Math_PINFINITY : double := (10)->pow(9) ; var dp : Sequence := Integer.subrange(0, x + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ Math_PINFINITY }, 2))) ; dp->first()->first() := 0 ; dp->first()[1+1] := 1 ; for i : Integer.subrange(0, x-1) do ( var s : int := ("" + ((n[i+1])))->toInteger() ; dp[i + 1+1]->first() := Set{dp[i+1]->first() + s, dp[i+1][1+1] + 10 - s}->min() ; dp[i + 1+1][1+1] := Set{dp[i+1]->first() + s + 1, dp[i+1][1+1] + 9 - s}->min()) ; execute (dp[x+1]->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import Counter,defaultdict,deque from heapq import heapify,heappush,heappop from functools import lru_cache from math import floor,ceil,sqrt,gcd from string import ascii_lowercase from math import gcd from bisect import bisect_left,bisect,bisect_right def read(): return input().strip() def read_int(): return int(read()) def read_str_list(): return read().split() def read_numeric_list(): return list(map(int,read_str_list())) def solve(N,arr): pile_assigned=set() arr.sort() ans=0 while len(pile_assigned)=curr : pile_assigned.add(i) curr+=1 ans+=1 return ans N=read_int() arr=read_numeric_list() print(solve(N,arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; N := read_int() ; arr := read_numeric_list() ; execute (solve(N, arr))->display(); operation read() : OclAny pre: true post: true activity: return input()->trim(); operation read_int() : OclAny pre: true post: true activity: return ("" + ((read())))->toInteger(); operation read_str_list() : OclAny pre: true post: true activity: return read().split(); operation read_numeric_list() : OclAny pre: true post: true activity: return ((read_str_list())->collect( _x | (OclType["int"])->apply(_x) )); operation solve(N : OclAny, arr : OclAny) : OclAny pre: true post: true activity: var pile_assigned : Set := Set{}->union(()) ; arr := arr->sort() ; var ans : int := 0 ; while ((pile_assigned)->size()->compareTo(N)) < 0 do ( var curr : int := 0 ; for _tuple : Integer.subrange(1, (arr)->size())->collect( _indx | Sequence{_indx-1, (arr)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var num : OclAny := _tuple->at(_indx); if (pile_assigned)->excludes(i) & (num->compareTo(curr)) >= 0 then ( execute ((i) : pile_assigned) ; curr := curr + 1 ) else skip) ; ans := ans + 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=reversed("0"+input()) digit=next(N) total=0 carry=0 for nextdigit in N : digit=int(digit)+carry if digit<5 : total+=digit carry=0 elif digit==5 : if int(nextdigit)<5 : total+=digit carry=0 else : total+=10-digit carry=1 else : total+=10-digit carry=1 digit=nextdigit print(total+carry) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : Sequence := ("0" + (OclFile["System.in"]).readLine())->reverse() ; var digit : OclAny := (N).next() ; var total : int := 0 ; var carry : int := 0 ; for nextdigit : N do ( digit := ("" + ((digit)))->toInteger() + carry ; if digit < 5 then ( total := total + digit ; carry := 0 ) else (if digit = 5 then ( if ("" + ((nextdigit)))->toInteger() < 5 then ( total := total + digit ; carry := 0 ) else ( total := total + 10 - digit ; carry := 1 ) ) else ( total := total + 10 - digit ; carry := 1 ) ) ; digit := nextdigit) ; execute (total + carry)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,bisect,math,itertools,string,queue,copy from collections import Counter,defaultdict,deque from itertools import permutations,combinations from heapq import heappop,heappush sys.setrecursionlimit(10**8) mod=10**9+7 def inp(): return int(input()) def inpm(): return map(int,input().split()) def inpl(): return list(map(int,input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(input())for _ in range(n)) def inplL(n): return[list(input())for _ in range(n)] def inplT(n): return[tuple(input())for _ in range(n)] def inpll(n): return sorted([list(map(int,input().split()))for _ in range(n)]) def main(): n=list(input()) l=len(n) ans=0 for i in range(l): n[i]=int(n[i]) for i in range(l-1,-1,-1): if n[i]<=4 : ans+=n[i] elif n[i]==5 and(i==0 or n[i-1]<=4): ans+=n[i] else : ans+=10-n[i] n[i]=0 if i!=0 : n[i-1]+=1 if i==0 and n[i]==0 : ans+=1 print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inpm() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inpls() : OclAny pre: true post: true activity: return (input().split()); operation inplm(n : OclAny) : OclAny pre: true post: true activity: return ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))); operation inplL(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((OclFile["System.in"]).readLine())->characters())); operation inplT(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((OclFile["System.in"]).readLine()))); operation inpll(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))->sort(); operation main() pre: true post: true activity: n := ((OclFile["System.in"]).readLine())->characters() ; var l : int := (n)->size() ; var ans : int := 0 ; for i : Integer.subrange(0, l-1) do ( n[i+1] := ("" + ((n[i+1])))->toInteger()) ; for i : Integer.subrange(-1 + 1, l - 1)->reverse() do ( if n[i+1] <= 4 then ( ans := ans + n[i+1] ) else (if n[i+1] = 5 & (i = 0 or n[i - 1+1] <= 4) then ( ans := ans + n[i+1] ) else ( ans := ans + 10 - n[i+1] ; n[i+1] := 0 ; if i /= 0 then ( n[i - 1+1] := n[i - 1+1] + 1 ) else skip ) ) ; if i = 0 & n[i+1] = 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) n=list(map(int,list(readline().rstrip().decode())[: :-1])) a=0 b=10000 for x in n : memo=min(a+x,b+x) b=min(a+11-x,b+9-x) a=memo print(min(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; sys.setrecursionlimit((10)->pow(7)) ; var n : Sequence := ((OclType["Sequence"](readline().rstrip().decode())(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->collect( _x | (OclType["int"])->apply(_x) )) ; var a : int := 0 ; var b : int := 10000 ; for x : n do ( var memo : OclAny := Set{a + x, b + x}->min() ; b := Set{a + 11 - x, b + 9 - x}->min() ; a := memo) ; execute (Set{a, b}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): num=int(input()) b=format(num,"032b") bi=format(~ num & 0b11111111111111111111111111111111,"032b") bl=format(num<<1,"032b") br=format(num>>1,"032b") print(b) print(bi) if len(bl)>32 : print(bl[-32 :]) else : print(bl) print(br) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : String := (num + "") ; var bi : String := (MathLib.bitwiseAnd(MathLib.bitwiseNot(num), 0b11111111111111111111111111111111) + "") ; var bl : String := (num * (2->pow(1)) + "") ; var br : String := (num /(2->pow(1)) + "") ; execute (b)->display() ; execute (bi)->display() ; if (bl)->size() > 32 then ( execute (bl.subrange(-32+1))->display() ) else ( execute (bl)->display() ) ; execute (br)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def areVowelsInOrder(s): n=len(s) c=chr(64) for i in range(1,n): if(s[i]=='a' or s[i]=='e' or s[i]=='i' or s[i]=='o' or s[i]=='u'): if s[i]display() ) else ( execute ("No")->display() ) ) else skip; operation areVowelsInOrder(s : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; var c : String := (64)->byte2char() ; for i : Integer.subrange(1, n-1) do ( if (s[i+1] = 'a' or s[i+1] = 'e' or s[i+1] = 'i' or s[i+1] = 'o' or s[i+1] = 'u') then ( if s[i+1] < c then ( return false ) else ( c := s[i+1] ) ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=10**20 MAX_INT=10**6 a=[INF]*MAX_INT b=[INF]*MAX_INT a[0],b[0]=0,0 for i in range(1,200): t=i*(i+1)*(i+2)//6 mm=min(t*5,MAX_INT) for j in range(t,mm): if a[j]>a[j-t]+1 : a[j]=a[j-t]+1 if t % 2==0 : continue for j in range(t,MAX_INT): if b[j]>b[j-t]+1 : b[j]=b[j-t]+1 while True : N=int(input()) if N==0 : exit() print(a[N],b[N]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INF : double := (10)->pow(20) ; var MAX_INT : double := (10)->pow(6) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, MAX_INT) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, MAX_INT) ; var a->first() : OclAny := null; var b->first() : OclAny := null; Sequence{a->first(),b->first()} := Sequence{0,0} ; for i : Integer.subrange(1, 200-1) do ( var t : int := i * (i + 1) * (i + 2) div 6 ; var mm : OclAny := Set{t * 5, MAX_INT}->min() ; for j : Integer.subrange(t, mm-1) do ( if (a[j+1]->compareTo(a[j - t+1] + 1)) > 0 then ( a[j+1] := a[j - t+1] + 1 ) else skip) ; if t mod 2 = 0 then ( continue ) else skip ; for j : Integer.subrange(t, MAX_INT-1) do ( if (b[j+1]->compareTo(b[j - t+1] + 1)) > 0 then ( b[j+1] := b[j - t+1] + 1 ) else skip)) ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( exit() ) else skip ; execute (a[N+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): rec=[5]*1000000 rec[0]=0 tetra_num=[i*(i+1)*(i+2)//6 for i in range(1,181)] for i,a in enumerate(tetra_num): for j,b in enumerate(tetra_num[i :],start=i): if a+b>=1000000 : break for c in tetra_num[j :]: if a+b+c>=1000000 : break rec[a+b+c]=3 for i,a in enumerate(tetra_num,start=0): for b in tetra_num[i :]: if a+b>=1000000 : break rec[a+b]=2 for n in tetra_num : rec[n]=1 for i,n in enumerate(rec[1 :],start=1): if n==3 : for t in tetra_num : if i+t>=1000000 : break if rec[i+t]==5 : rec[i+t]=4 odd_rec=[1000000]*1000000 odd_rec[0]=0 odd_tetra_num=tetra_num[: : 4] for odd_t in odd_tetra_num : for i,tpl in enumerate(zip(odd_rec[odd_t :],odd_rec),start=odd_t): a,b=tpl b+=1 if bfirst() := 0 ; var tetra_num : Sequence := Integer.subrange(1, 181-1)->select(i | true)->collect(i | (i * (i + 1) * (i + 2) div 6)) ; for _tuple : Integer.subrange(1, (tetra_num)->size())->collect( _indx | Sequence{_indx-1, (tetra_num)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); for _tuple : Integer.subrange(1, (tetra_num.subrange(i+1), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (name i))))))))->size())->collect( _indx | Sequence{_indx-1, (tetra_num.subrange(i+1), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (name i))))))))->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if a + b >= 1000000 then ( break ) else skip ; for c : tetra_num.subrange(j+1) do ( if a + b + c >= 1000000 then ( break ) else skip ; rec[a + b + c+1] := 3))) ; for _tuple : Integer.subrange(1, (tetra_num, (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 0)))))))))->size())->collect( _indx | Sequence{_indx-1, (tetra_num, (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 0)))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); for b : tetra_num.subrange(i+1) do ( if a + b >= 1000000 then ( break ) else skip ; rec[a + b+1] := 2)) ; for n : tetra_num do ( rec[n+1] := 1) ; for _tuple : Integer.subrange(1, (rec->tail(), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->size())->collect( _indx | Sequence{_indx-1, (rec->tail(), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var n : OclAny := _tuple->at(_indx); if n = 3 then ( for t : tetra_num do ( if i + t >= 1000000 then ( break ) else skip ; if rec[i + t+1] = 5 then ( rec[i + t+1] := 4 ) else skip) ) else skip) ; var odd_rec : Sequence := MatrixLib.elementwiseMult(Sequence{ 1000000 }, 1000000) ; odd_rec->first() := 0 ; var odd_tetra_num : OclAny := tetra_num(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 4))))))))) ; for odd_t : odd_tetra_num do ( for _tuple : Integer.subrange(1, (Integer.subrange(1, odd_rec.subrange(odd_t+1)->size())->collect( _indx | Sequence{odd_rec.subrange(odd_t+1)->at(_indx), odd_rec->at(_indx)} ), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (name odd_t))))))))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(1, odd_rec.subrange(odd_t+1)->size())->collect( _indx | Sequence{odd_rec.subrange(odd_t+1)->at(_indx), odd_rec->at(_indx)} ), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (name odd_t))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var tpl : OclAny := _tuple->at(_indx); var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := tpl ; b := b + 1 ; if (b->compareTo(a)) < 0 then ( odd_rec[i+1] := b ) else skip)) ; skip ; var file_input : OclFile := OclFile["System.in"] ; var n : int := ("" + ((file_input.readLine())))->toInteger() ; while n do ( execute (rec[n+1])->display() ; n := ("" + ((file_input.readLine())))->toInteger()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import takewhile,count from time import perf_counter as timer M=10**6 nums=tuple(takewhile(lambda x : x=M : break dp0[x]=min((c,-i),dp0[x]) dp1=[(M,M)]*M dp1[0]=(0,0) for v,(c,i0)in enumerate(dp1): c+=1 for i,n in enumerate(odds[-i0 :],start=-i0): x=v+n if x>=M : break dp1[x]=min((c,-i),dp1[x]) x=int(input()) while x!=0 : print(dp0[x][0],dp1[x][0]) x=int(input()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var M : double := (10)->pow(6) ; var nums : Sequence := (takewhile(lambda x : OclAny in ((x->compareTo(M)) < 0), Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (expr (expr (atom (name m))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name m))) + (expr (atom (number (integer 1))))))))) )))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name m))) + (expr (atom (number (integer 2))))))))) )))) // (expr (atom (number (integer 6)))))))) (comp_for for (exprlist (expr (atom (name m)))) in (logical_test (comparison (expr (atom (name count)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ))))))))})) ; var odds : Sequence := ((argument (test (logical_test (comparison (expr (atom (name v)))))) (comp_for for (exprlist (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name nums))))) (comp_iter if (test (logical_test (comparison (expr (expr (atom (name v))) % (expr (atom (number (integer 2)))))))))))) ; var dp0 : Sequence := MatrixLib.elementwiseMult(Sequence{ Sequence{M, M} }, M) ; dp0->first() := Sequence{0, 0} ; for _tuple : Integer.subrange(1, (dp0)->size())->collect( _indx | Sequence{_indx-1, (dp0)->at(_indx)} ) do (var _indx : int := 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{c, i0} : OclAny := _tuple->at(_indx); c := c + 1 ; for _tuple : Integer.subrange(1, (nums.subrange(-i0+1), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr - (expr (atom (name i0)))))))))->size())->collect( _indx | Sequence{_indx-1, (nums.subrange(-i0+1), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr - (expr (atom (name i0)))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var n : OclAny := _tuple->at(_indx); var x : OclAny := v + n ; if (x->compareTo(M)) >= 0 then ( break ) else skip ; dp0[x+1] := Set{Sequence{c, -i}, dp0[x+1]}->min())) ; var dp1 : Sequence := MatrixLib.elementwiseMult(Sequence{ Sequence{M, M} }, M) ; dp1->first() := Sequence{0, 0} ; for _tuple : Integer.subrange(1, (dp1)->size())->collect( _indx | Sequence{_indx-1, (dp1)->at(_indx)} ) do (var _indx : int := 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{c, i0} : OclAny := _tuple->at(_indx); c := c + 1 ; for _tuple : Integer.subrange(1, (odds.subrange(-i0+1), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr - (expr (atom (name i0)))))))))->size())->collect( _indx | Sequence{_indx-1, (odds.subrange(-i0+1), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr - (expr (atom (name i0)))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var n : OclAny := _tuple->at(_indx); x := v + n ; if (x->compareTo(M)) >= 0 then ( break ) else skip ; dp1[x+1] := Set{Sequence{c, -i}, dp1[x+1]}->min())) ; x := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while x /= 0 do ( execute (dp0[x+1]->first())->display() ; x := ("" + (((OclFile["System.in"]).readLine())))->toInteger()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda : sys.stdin.readline().rstrip() YesNo=lambda b : print('Yes' if b else 'No') YESNO=lambda b : print('YES' if b else 'NO') def main(): Q=[] while True : N=int(input()) if N==0 : break Q.append(N) MAX_Q=max(Q) A=tuple((i+1)*(i+2)*(i+3)//6 for i in range(182)) A_odd=tuple(i for i in A if i % 2) A_even=tuple(i for i in A if i % 2==0) dp=[INF]*(MAX_Q+1) dp[0]=0 for x in A_odd : for k in range(x,MAX_Q+1): if dp[k]>dp[k-x]+1 : dp[k]=dp[k-x]+1 ans=[] for q in Q : ans.append(dp[q]) for x in A_even : for k in range(x,MAX_Q+1): dp[k]=min(dp[k],dp[k-x]+1) for i,q in enumerate(Q): print(dp[q],ans[i]) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var YesNo : Function := lambda b : OclAny in ((if b then 'Yes' else 'No' endif)->display()) ; var YESNO : Function := lambda b : OclAny in ((if b then 'YES' else 'NO' endif)->display()) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var Q : Sequence := Sequence{} ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; execute ((N) : Q)) ; var MAX_Q : OclAny := (Q)->max() ; var A : Sequence := ((argument (test (logical_test (comparison (expr (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) ))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 2))))))))) )))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 3))))))))) )))) // (expr (atom (number (integer 6)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 182))))))))) ))))))))) ; var A_odd : Sequence := ((argument (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name A))))) (comp_iter if (test (logical_test (comparison (expr (expr (atom (name i))) % (expr (atom (number (integer 2)))))))))))) ; var A_even : Sequence := ((argument (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name A))))) (comp_iter if (test (logical_test (comparison (comparison (expr (expr (atom (name i))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 0)))))))))))) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, (MAX_Q + 1)) ; dp->first() := 0 ; for x : A_odd do ( for k : Integer.subrange(x, MAX_Q + 1-1) do ( if (dp[k+1]->compareTo(dp[k - x+1] + 1)) > 0 then ( dp[k+1] := dp[k - x+1] + 1 ) else skip)) ; var ans : Sequence := Sequence{} ; for q : Q do ( execute ((dp[q+1]) : ans)) ; for x : A_even do ( for k : Integer.subrange(x, MAX_Q + 1-1) do ( dp[k+1] := Set{dp[k+1], dp[k - x+1] + 1}->min())) ; for _tuple : Integer.subrange(1, (Q)->size())->collect( _indx | Sequence{_indx-1, (Q)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var q : OclAny := _tuple->at(_indx); execute (dp[q+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque sq=[i for i in range(200)] for i in range(199): sq[i+1]+=sq[i] for i in range(199): sq[i+1]+=sq[i] ss=[] for s in sq : if s % 2 : ss.append(s) dp=defaultdict(lambda : False) check=defaultdict(lambda : False) for s in sq : dp[s]=True check[s]=True dps=defaultdict(lambda : False) checks=defaultdict(lambda : False) for s in ss : dps[s]=True checks[s]=True def main(n,ss,check,dp): q=deque() q.append((n,1)) check[n]=True if dp[n]: return 1 while q : a,i=q.pop() for s in ss : aa=a-s if aa<=0 : break if not check[aa]: check[aa]=True q.appendleft((aa,i+1)) else : if dp[aa]: return i+1 while 1 : n=int(input()) if n==0 : break check=defaultdict(lambda : False) for s in sq : check[s]=True checks=defaultdict(lambda : False) for s in ss : checks[s]=True print(main(n,sq,check,dp),main(n,ss,checks,dps)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var sq : Sequence := Integer.subrange(0, 200-1)->select(i | true)->collect(i | (i)) ; for i : Integer.subrange(0, 199-1) do ( sq[i + 1+1] := sq[i + 1+1] + sq[i+1]) ; for i : Integer.subrange(0, 199-1) do ( sq[i + 1+1] := sq[i + 1+1] + sq[i+1]) ; var ss : Sequence := Sequence{} ; for s : sq do ( if s mod 2 then ( execute ((s) : ss) ) else skip) ; var dp : OclAny := defaultdict(lambda $$ : OclAny in (false)) ; var check : OclAny := defaultdict(lambda $$ : OclAny in (false)) ; for s : sq do ( dp[s+1] := true ; check[s+1] := true) ; var dps : OclAny := defaultdict(lambda $$ : OclAny in (false)) ; var checks : OclAny := defaultdict(lambda $$ : OclAny in (false)) ; for s : ss do ( dps[s+1] := true ; checks[s+1] := true) ; skip ; while 1 do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; check := defaultdict(lambda $$ : OclAny in (false)) ; for s : sq do ( check[s+1] := true) ; checks := defaultdict(lambda $$ : OclAny in (false)) ; for s : ss do ( checks[s+1] := true) ; execute (main(n, sq, check, dp))->display()); operation main(n : OclAny, ss : OclAny, check : OclAny, dp : OclAny) : OclAny pre: true post: true activity: var q : Sequence := () ; execute ((Sequence{n, 1}) : q) ; check[n+1] := true ; if dp[n+1] then ( return 1 ) else skip ; while q do ( var a : OclAny := null; var i : OclAny := null; Sequence{a,i} := q->last() ; q := q->front() ; for s : ss do ( var aa : double := a - s ; if aa <= 0 then ( break ) else skip ; if not(check[aa+1]) then ( check[aa+1] := true ; q := q->prepend(Sequence{aa, i + 1}) ) else ( if dp[aa+1] then ( return i + 1 ) else skip ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countOfLetters(string): letter=0 ; for i in range(len(string)): if((string[i]>='A' and string[i]<='Z')or(string[i]>='a' and string[i]<='z')): letter+=1 ; return letter ; def countOfNumbers(string): number=0 ; for i in range(len(string)): if(string[i]>='0' and string[i]<='9'): number+=1 ; return number ; def check(string): if(countOfLetters(string)==countOfNumbers(string)): print("Yes"); else : print("No"); if __name__=="__main__" : string="GeeKs01324" ; check(string); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( string := "GeeKs01324"; ; check(string); ) else skip; operation countOfLetters(string : OclAny) pre: true post: true activity: var letter : int := 0; ; for i : Integer.subrange(0, (string)->size()-1) do ( if ((string[i+1] >= 'A' & string[i+1] <= 'Z') or (string[i+1] >= 'a' & string[i+1] <= 'z')) then ( letter := letter + 1; ) else skip) ; return letter;; operation countOfNumbers(string : OclAny) pre: true post: true activity: var number : int := 0; ; for i : Integer.subrange(0, (string)->size()-1) do ( if (string[i+1] >= '0' & string[i+1] <= '9') then ( number := number + 1; ) else skip) ; return number;; operation check(string : OclAny) pre: true post: true activity: if (countOfLetters(string) = countOfNumbers(string)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) s=list(map(int,input().split())) stacks=[[]for _ in range(n)] for i in range(101): for val in s : if val==i : for idx,stack in enumerate(stacks): if val>=len(stack): stacks[idx].append(val) break return sum([True for stack in stacks if len(stack)]) def main(): ret=solve() print(ret) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var stacks : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, 101-1) do ( for val : s do ( if val = i then ( for _tuple : Integer.subrange(1, (stacks)->size())->collect( _indx | Sequence{_indx-1, (stacks)->at(_indx)} ) do (var _indx : int := 1; var idx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var stack : OclAny := _tuple->at(_indx); if (val->compareTo((stack)->size())) >= 0 then ( (expr (atom (name stacks)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name idx)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name val)))))))) )))) ; break ) else skip) ) else skip)) ; return (stacks->select(stack | (stack)->size())->collect(stack | (true)))->sum(); operation main() pre: true post: true activity: var ret : OclAny := solve() ; execute (ret)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lis=[] cnt=0 while True : try : n=int(input()) if n : cnt+=1 lis.append(n) else : print(lis.pop(cnt-1)) cnt-=1 except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lis : Sequence := Sequence{} ; var cnt : int := 0 ; while true do ( try ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n then ( cnt := cnt + 1 ; execute ((n) : lis) ) else ( execute (lis->at((expr (expr (atom (name cnt))) - (expr (atom (number (integer 1)))))+1))->display() ; cnt := cnt - 1 )) catch (_e : OclException) do ( break) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys a=[int(i)for i in sys.stdin] b=[] for j in a : if j==0 : print(b.pop()) else : b.append(j) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : Sequence := OclFile["System.in"]->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var b : Sequence := Sequence{} ; for j : a do ( if j = 0 then ( execute (b->last())->display() ) else ( execute ((j) : b) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) y=format(x,"b").zfill(10) ly=len(y) ly=32-ly pady="0"*ly print(pady+y) rev=2**32-1-x z=format(rev,"b").zfill(10) lz=len(z) lz=32-lz padz="0"*lz print(padz+z) left=x*2 if left>=2**32 : left-=2**32 u=format(left,"b").zfill(10) lu=len(u) lu=32-lu padu="0"*lu print(padu+u) right=x//2 v=format(right,"b").zfill(10) lv=len(v) lv=32-lv padv="0"*lv print(padv+v) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var y : OclAny := format(x, "b").zfill(10) ; var ly : int := (y)->size() ; ly := 32 - ly ; var pady : String := StringLib.nCopies("0", ly) ; execute (pady + y)->display() ; var rev : double := (2)->pow(32) - 1 - x ; var z : OclAny := format(rev, "b").zfill(10) ; var lz : int := (z)->size() ; lz := 32 - lz ; var padz : String := StringLib.nCopies("0", lz) ; execute (padz + z)->display() ; var left : int := x * 2 ; if (left->compareTo((2)->pow(32))) >= 0 then ( left := left - (2)->pow(32) ) else skip ; var u : OclAny := format(left, "b").zfill(10) ; var lu : int := (u)->size() ; lu := 32 - lu ; var padu : String := StringLib.nCopies("0", lu) ; execute (padu + u)->display() ; var right : int := x div 2 ; var v : OclAny := format(right, "b").zfill(10) ; var lv : int := (v)->size() ; lv := 32 - lv ; var padv : String := StringLib.nCopies("0", lv) ; execute (padv + v)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys a=[] for e in map(int,sys.stdin): a.append(e)if e else print(a.pop()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : Sequence := Sequence{} ; for e : (OclFile["System.in"])->collect( _x | (OclType["int"])->apply(_x) ) do ((test (logical_test (comparison (expr (atom (name a)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name e)))))))) )))))) if (logical_test (comparison (expr (atom (name e))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)) (trailer . (name pop) (arguments ( ))))))))) ))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Stack(object): maxnum=100 array=[] for i in range(100): array.append(0) index=0 def push(self,data): self.array[self.index]=data self.index+=1 def pop(self): print(self.array[self.index-1]) self.index-=1 road=Stack() while True : try : num=int(raw_input()) if num!=0 : road.push(num) else : road.pop() except EOFError : break ------------------------------------------------------------ OCL File: --------- class Stack extends object { static operation newStack() : Stack pre: true post: Stack->exists( _x | result = _x ); static attribute maxnum : int := 100; static attribute array : Sequence := Sequence{}; static attribute index : int := 0; operation push(data : OclAny) pre: true post: true activity: self.array[self.index+1] := data ; self.index := self.index + 1; operation pop() pre: true post: true activity: execute (self.array[self.index - 1+1])->display() ; self.index := self.index - 1; } class FromPython { operation initialise() pre: true post: true activity: skip ; var road : Stack := (Stack.newStack()).initialise() ; while true do ( try ( var num : int := ("" + ((raw_input())))->toInteger() ; if num /= 0 then ( road.push(num) ) else ( road := road->front() )) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys d=sys.stdin.readline().rstrip() stack=list() while d : if d!='0' : stack.append(d) else : print(stack.pop()) d=sys.stdin.readline().rstrip() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var d : OclAny := sys.stdin.readLine().rstrip() ; var stack : Sequence := () ; while d do ( if d /= '0' then ( execute ((d) : stack) ) else ( execute (stack->last())->display() ) ; d := sys.stdin.readLine().rstrip()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,x=map(int,input().split()) if x==1 or x==2*N-1 : print("No") else : print("Yes") l=[i for i in range(1,2*N)] l.remove(x-1) l.remove(x) l.remove(x+1) for i in range(N-2): print(l[i]) print(x-1) print(x) print(x+1) for i in range(N-2): print(l[N-2+i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var x : OclAny := null; Sequence{N,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x = 1 or x = 2 * N - 1 then ( execute ("No")->display() ) else ( execute ("Yes")->display() ; var l : Sequence := Integer.subrange(1, 2 * N-1)->select(i | true)->collect(i | (i)) ; execute ((x - 1) /: l) ; execute ((x) /: l) ; execute ((x + 1) /: l) ; for i : Integer.subrange(0, N - 2-1) do ( execute (l[i+1])->display()) ; execute (x - 1)->display() ; execute (x)->display() ; execute (x + 1)->display() ; for i : Integer.subrange(0, N - 2-1) do ( execute (l[N - 2 + i+1])->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,X=[int(_)for _ in input().split()] from itertools import permutations def calc(x): def sub(y,debug=0): if debug : print("D",y) while len(y)>1 : y=[sorted(y[i : i+3])[1]for i in range(len(y)-2)] if debug : print("D",y) return y y=sub(x) if y[0]==2 : pass sub(x,1) print("=",x) return y[0] if X==1 or X==N*2-1 : print("No") else : print("Yes") if X==N*2-2 : xs=list(range(N-1,X+2))+list(range(1,N-1)) else : ys=list(range(1,X-1))+list(range(X+3,N*2)) xs=ys[: N-3]+[X+2,X-1,X,X+1]+ys[N-3 :] for x in xs : print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var X : OclAny := null; Sequence{N,X} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; skip ; skip ; if X = 1 or X = N * 2 - 1 then ( execute ("No")->display() ) else ( execute ("Yes")->display() ; if X = N * 2 - 2 then ( var xs : Sequence := (Integer.subrange(N - 1, X + 2-1))->union((Integer.subrange(1, N - 1-1))) ) else ( var ys : Sequence := (Integer.subrange(1, X - 1-1))->union((Integer.subrange(X + 3, N * 2-1))) ; xs := ys.subrange(1,N - 3)->union(Sequence{X + 2}->union(Sequence{X - 1}->union(Sequence{X}->union(Sequence{ X + 1 })))) + ys.subrange(N - 3+1) ) ; for x : xs do ( execute (x)->display()) ); operation calc(x : OclAny) : OclAny pre: true post: true activity: skip ; y := sub(x) ; if y->first() = 2 then ( skip ; sub(x, 1) ; execute ("=")->display() ) else skip ; return y->first(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines in_n=lambda : int(readline()) in_nn=lambda : map(int,readline().split()) in_s=lambda : readline().rstrip().decode('utf-8') in_nl=lambda : list(map(int,readline().split())) in_nl2=lambda H :[in_nl()for _ in range(H)] in_map=lambda :[s==ord('.')for s in readline()if s!=ord('\n')] in_map2=lambda H :[in_map()for _ in range(H)] in_all=lambda : map(int,read().split()) def main(): N,x=in_nn() max_n=2*N-1 if x==1 or x==max_n : print("No") exit() if xN : ans=[] pyr=set(range(1,max_n+1)) center=[x-2,x-1,x,x+1,x-3] pyr-=set(center) pyr=list(pyr) t_len=(max_n-5)//2 ans=pyr[: t_len]+center+pyr[t_len :] print("Yes") print('\n'.join(map(str,ans))) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; var in_n : Function := lambda $$ : OclAny in (("" + ((readline())))->toInteger()) ; var in_nn : Function := lambda $$ : OclAny in ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var in_s : Function := lambda $$ : OclAny in (readline().rstrip().decode('utf-8')) ; var in_nl : Function := lambda $$ : OclAny in (((readline().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var in_nl2 : Function := lambda H : OclAny in (Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (in_nl->apply()))) ; var in_map : Function := lambda $$ : OclAny in (readline()->select(s | s /= (' ')->char2byte())->collect(s | (s = ('.')->char2byte()))) ; var in_map2 : Function := lambda H : OclAny in (Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (in_map->apply()))) ; var in_all : Function := lambda $$ : OclAny in ((read().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var x : OclAny := null; Sequence{N,x} := in_nn->apply() ; var max_n : double := 2 * N - 1 ; if x = 1 or x = max_n then ( execute ("No")->display() ; exit() ) else skip ; if (x->compareTo(N)) < 0 then ( var ans : Sequence := Sequence{} ; var pyr : Set := Set{}->union((Integer.subrange(1, max_n + 1-1))) ; var center : Sequence := Sequence{x + 2}->union(Sequence{x + 1}->union(Sequence{x}->union(Sequence{x - 1}->union(Sequence{ x + 3 })))) ; pyr := pyr - Set{}->union((center)) ; pyr := (pyr) ; var t_len : int := (max_n - 5) div 2 ; ans := pyr.subrange(1,t_len)->union(center) + pyr.subrange(t_len+1) ) else (if x = N then ( ans := (Integer.subrange(1, max_n + 1-1)) ) else (if (x->compareTo(N)) > 0 then ( ans := Sequence{} ; pyr := Set{}->union((Integer.subrange(1, max_n + 1-1))) ; center := Sequence{x - 2}->union(Sequence{x - 1}->union(Sequence{x}->union(Sequence{x + 1}->union(Sequence{ x - 3 })))) ; pyr := pyr - Set{}->union((center)) ; pyr := (pyr) ; t_len := (max_n - 5) div 2 ; ans := pyr.subrange(1,t_len)->union(center) + pyr.subrange(t_len+1) ) else skip ) ) ; execute ("Yes")->display() ; execute (StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import fractions import heapq import collections import re import array import bisect from collections import Counter,defaultdict II=lambda : int(input()) MI=lambda : map(int,input().split()) def main(): N,x=MI() if x in[1,2*N-1]: print("No") return print("Yes") if N==2 : print("1\n2\n3") return s=set([i for i in range(1,2*N)]) a=[None]*(2*N-1) MED=N-1 if x==2*N-2 : l=(x-1,x,x+1,x-2) a[MED-1 : MED+3]=l for i in l : s.remove(i) else : l=x+1,x,x-1,x+2 a[MED-1 : MED+3]=l for i in l : s.remove(i) for i in range(2*N-1): if a[i]is None : a[i]=s.pop() for i in range(2*N-1): print(a[i]) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var II : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var MI : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var x : OclAny := null; Sequence{N,x} := MI->apply() ; if (Sequence{1}->union(Sequence{ 2 * N - 1 }))->includes(x) then ( execute ("No")->display() ; return ) else skip ; execute ("Yes")->display() ; if N = 2 then ( execute ("1\n2\n3")->display() ; return ) else skip ; var s : Set := Set{}->union((Integer.subrange(1, 2 * N-1)->select(i | true)->collect(i | (i)))) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (2 * N - 1)) ; var MED : double := N - 1 ; if x = 2 * N - 2 then ( var l : OclAny := Sequence{x - 1, x, x + 1, x - 2} ; a.subrange(MED - 1+1, MED + 3) := l ; for i : l do ( execute ((i) /: s)) ) else ( l := x + 1,x,x - 1,x + 2 ; a.subrange(MED - 1+1, MED + 3) := l ; for i : l do ( execute ((i) /: s)) ) ; for i : Integer.subrange(0, 2 * N - 1-1) do ( if a[i+1] <>= null then ( a[i+1] := s->last() ; s := s->front() ) else skip) ; for i : Integer.subrange(0, 2 * N - 1-1) do ( execute (a[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines N,X=map(int,read().split()) def case2(N,X): if X!=2 : return False return[1,2,3] def solve(N,X): if N==2 : return case2(N,X) if X==1 or X==N+N-1 : return False se=set(range(1,N+N)) A=[0]*(N+N-1) if X<=N : A[N-1]=X A[N]=1 A[N+1]=X+1 A[N-2]=X+2 se-=set([X,1,X+1,X+2]) else : A[N-1]=X A[N]=N+N-1 A[N+1]=X-1 A[N-2]=X-2 se-=set([X,N+N-1,X-1,X-2]) for i in range(N+N-1): if not A[i]: A[i]=se.pop() return A A=solve(N,X) if not A : print('No') else : print('Yes') print('\n'.join(map(str,A))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; var N : OclAny := null; var X : OclAny := null; Sequence{N,X} := (read().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; skip ; A := solve(N, X) ; if not(A) then ( execute ('No')->display() ) else ( execute ('Yes')->display() ; execute (StringLib.sumStringsWithSeparator(((A)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ); operation case2(N : OclAny, X : OclAny) : OclAny pre: true post: true activity: if X /= 2 then ( return false ) else skip ; return Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })); operation solve(N : OclAny, X : OclAny) : OclAny pre: true post: true activity: if N = 2 then ( return case2(N, X) ) else skip ; if X = 1 or X = N + N - 1 then ( return false ) else skip ; var se : Set := Set{}->union((Integer.subrange(1, N + N-1))) ; var A : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + N - 1)) ; if (X->compareTo(N)) <= 0 then ( A[N - 1+1] := X ; A[N+1] := 1 ; A[N + 1+1] := X + 1 ; A[N - 2+1] := X + 2 ; se := se - Set{}->union((Sequence{X}->union(Sequence{1}->union(Sequence{X + 1}->union(Sequence{ X + 2 }))))) ) else ( A[N - 1+1] := X ; A[N+1] := N + N - 1 ; A[N + 1+1] := X - 1 ; A[N - 2+1] := X - 2 ; se := se - Set{}->union((Sequence{X}->union(Sequence{N + N - 1}->union(Sequence{X - 1}->union(Sequence{ X - 2 }))))) ) ; for i : Integer.subrange(0, N + N - 1-1) do ( if not(A[i+1]) then ( A[i+1] := se->last() ; se := se->front() ) else skip) ; return A; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def cross(P0,P1,P2): x0,y0=P0 ; x1,y1=P1 ; x2,y2=P2 x1-=x0 ; x2-=x0 y1-=y0 ; y2-=y0 return x1*y2-x2*y1 def dot(P0,P1,P2): x0,y0=P0 ; x1,y1=P1 ; x2,y2=P2 x1-=x0 ; x2-=x0 y1-=y0 ; y2-=y0 return x1*x2+y1*y2 def dist2(P0,P1): x0,y0=P0 ; x1,y1=P1 return(x1-x0)**2+(y1-y0)**2 def collision_ll(S0,S1,T0,T1): return cross(S0,S1,T0)*cross(S0,S1,T1)<0 and cross(T0,T1,S0)*cross(T0,T1,S1)<0 def dist_lp(S,E,P): dd=dist2(S,E) if 0<=dot(S,E,P)<=dd : return abs(cross(S,E,P))/sqrt(dd) return sqrt(min(dist2(S,P),dist2(E,P))) def dist_ll(S0,S1,T0,T1): if collision_ll(S0,S1,T0,T1): return 0 return min(dist_lp(S0,S1,T0),dist_lp(S0,S1,T1),dist_lp(T0,T1,S0),dist_lp(T0,T1,S1)) n=int(input()) for i in range(n): x0,y0,x1,y1,X0,Y0,X1,Y1=map(int,input().split()) print("%.010f" % dist_ll((x0,y0),(x1,y1),(X0,Y0),(X1,Y1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var x0 : OclAny := null; var y0 : OclAny := null; var x1 : OclAny := null; var y1 : OclAny := null; var X0 : OclAny := null; var Y0 : OclAny := null; var X1 : OclAny := null; var Y1 : OclAny := null; Sequence{x0,y0,x1,y1,X0,Y0,X1,Y1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (StringLib.format("%.010f",dist_ll(Sequence{x0, y0}, Sequence{x1, y1}, Sequence{X0, Y0}, Sequence{X1, Y1})))->display()); operation cross(P0 : OclAny, P1 : OclAny, P2 : OclAny) : OclAny pre: true post: true activity: var x0 : OclAny := null; var y0 : OclAny := null; Sequence{x0,y0} := P0; var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := P1; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x2,y2} := P2 ; x1 := x1 - x0; x2 := x2 - x0 ; y1 := y1 - y0; y2 := y2 - y0 ; return x1 * y2 - x2 * y1; operation dot(P0 : OclAny, P1 : OclAny, P2 : OclAny) : OclAny pre: true post: true activity: var x0 : OclAny := null; var y0 : OclAny := null; Sequence{x0,y0} := P0; var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := P1; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x2,y2} := P2 ; x1 := x1 - x0; x2 := x2 - x0 ; y1 := y1 - y0; y2 := y2 - y0 ; return x1 * x2 + y1 * y2; operation dist2(P0 : OclAny, P1 : OclAny) : OclAny pre: true post: true activity: var x0 : OclAny := null; var y0 : OclAny := null; Sequence{x0,y0} := P0; var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := P1 ; return ((x1 - x0))->pow(2) + ((y1 - y0))->pow(2); operation collision_ll(S0 : OclAny, S1 : OclAny, T0 : OclAny, T1 : OclAny) : OclAny pre: true post: true activity: return cross(S0, S1, T0) * cross(S0, S1, T1) < 0 & cross(T0, T1, S0) * cross(T0, T1, S1) < 0; operation dist_lp(S : OclAny, E : OclAny, P : OclAny) : OclAny pre: true post: true activity: var dd : OclAny := dist2(S, E) ; if 0 <= dot(S, E, P) & (dot(S, E, P) <= dd) then ( return (cross(S, E, P))->abs() / sqrt(dd) ) else skip ; return sqrt(Set{dist2(S, P), dist2(E, P)}->min()); operation dist_ll(S0 : OclAny, S1 : OclAny, T0 : OclAny, T1 : OclAny) : OclAny pre: true post: true activity: if collision_ll(S0, S1, T0, T1) then ( return 0 ) else skip ; return Set{dist_lp(S0, S1, T0), dist_lp(S0, S1, T1), dist_lp(T0, T1, S0), dist_lp(T0, T1, S1)}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil n=int(input()) x=[int(i)for i in input().split()] d={} for i in x : d[i]=x.count(i) e=list(d.items()) e.sort() f=[] tot=0 for i,j in e : tot+=j f.append((i,j,tot)) ans=0 for i,j,k in f : m=int(ceil(k/(i+1))) ans=max(ans,m) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var d : OclAny := Set{} ; for i : x do ( d[i+1] := x->count(i)) ; var e : Sequence := (d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})) ; e := e->sort() ; var f : Sequence := Sequence{} ; var tot : int := 0 ; for _tuple : e do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); tot := tot + j ; execute ((Sequence{i, j, tot}) : f)) ; var ans : int := 0 ; for _tuple : f do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var k : OclAny := _tuple->at(_indx); var m : int := ("" + ((ceil(k / (i + 1)))))->toInteger() ; ans := Set{ans, m}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def out(n): mask=2**32-1 print(format(n & mask,"032b")) n=int(input()) out(n) out(~ n) out(n<<1) out(n>>1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; out(n) ; out(MathLib.bitwiseNot(n)) ; out(n * (2->pow(1))) ; out(n /(2->pow(1))); operation out(n : OclAny) pre: true post: true activity: var mask : double := (2)->pow(32) - 1 ; execute ((MathLib.bitwiseAnd(n, mask) + ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100001 perfectDiv=[0]*MAX def precomputeCounts(): i=1 while i*idisplay() ; n := 12 ; execute ("Total perfect divisors of ")->display() ) else skip; operation precomputeCounts() pre: true post: true activity: var i : int := 1 ; while (i * i->compareTo(MAX)) < 0 do ( for j : Integer.subrange(i * i, MAX-1)->select( $x | ($x - i * i) mod i * i = 0 ) do ( perfectDiv[j+1] := perfectDiv[j+1] + 1) ; i := i + 1); operation countPerfectDivisors(n : OclAny) : OclAny pre: true post: true activity: return perfectDiv[n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) A=list(map(int,input().split())) B=list(map(int,input().split())) print(sum(A)*sum(B)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var B : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((A)->sum() * (B)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(): return sum(map(int,input().split())) f(); print(f()*f()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; f(); execute (f() * f())->display(); operation f() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=[int(x)for x in input().split()] A=[int(x)for x in input().split()] B=[int(x)for x in input().split()] cntA=[0]*1001 cntB=[0]*1001 for a in A : cntA[a]=cntA[a]+1 for b in B : cntB[b]=cntB[b]+1 ans=0 for a in range(1001): for b in range(1001): ans=ans+(a*b*cntA[a]*cntB[b]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var B : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var cntA : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 1001) ; var cntB : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 1001) ; for a : A do ( cntA[a+1] := cntA[a+1] + 1) ; for b : B do ( cntB[b+1] := cntB[b+1] + 1) ; var ans : int := 0 ; for a : Integer.subrange(0, 1001-1) do ( for b : Integer.subrange(0, 1001-1) do ( ans := ans + (a * b * cntA[a+1] * cntB[b+1]))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _=input() A=sum([int(x)for x in input().split()]) B=sum([int(x)for x in input().split()]) print(A*B) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _anon : String := (OclFile["System.in"]).readLine() ; var A : OclAny := (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))->sum() ; var B : OclAny := (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))->sum() ; execute (A * B)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) an=0 ans=0 for i in range(n): an+=a[i] for j in range(m): ans+=an*b[j] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var an : int := 0 ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( an := an + a[i+1]) ; for j : Integer.subrange(0, m-1) do ( ans := ans + an * b[j+1]) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t,e=map(int,input().split()) xlst=list(map(int,input().split())) for i,x in enumerate(xlst): a=(t-e-1)//x if(a+1)*x<=t+e : print(i+1) break else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; var e : OclAny := null; Sequence{n,t,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var xlst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (compound_stmt for (exprlist (expr (atom (name i))) , (expr (atom (name x)))) in (testlist (test (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name xlst)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name a)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name t))) - (expr (atom (name e)))) - (expr (atom (number (integer 1))))))))) ))) // (expr (atom (name x))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name a))) + (expr (atom (number (integer 1))))))))) ))) * (expr (atom (name x))))) <= (comparison (expr (expr (atom (name t))) + (expr (atom (name e)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,T,E=map(int,input().split()) x=[int(x)for x in input().split()] Time=list(range(T-E,T+E+1,1)) time=[] for i in range(N): t=[] for j in range(len(Time)): if Time[j]% x[i]==0 : t.append(1) if 1 in t : time.append(1) else : time.append(0) if sum(time)==0 : print(-1) else : index=time.index(1) print(index+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var T : OclAny := null; var E : OclAny := null; Sequence{N,T,E} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var Time : Sequence := (Integer.subrange(T - E, T + E + 1-1)->select( $x | ($x - T - E) mod 1 = 0 )) ; var time : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var t : Sequence := Sequence{} ; for j : Integer.subrange(0, (Time)->size()-1) do ( if Time[j+1] mod x[i+1] = 0 then ( execute ((1) : t) ) else skip) ; if (t)->includes(1) then ( execute ((1) : time) ) else ( execute ((0) : time) )) ; if (time)->sum() = 0 then ( execute (-1)->display() ) else ( var index : int := time->indexOf(1) - 1 ; execute (index + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t,e=map(int,input().split()) watch=list(map(int,input().split())) ans=False for w in range(n): for i in range(e+1): if(t+i)% watch[w]==0 : ans=True break if(t-i)% watch[w]==0 : ans=True break if ans==True : break if ans==True : print(w+1) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; var e : OclAny := null; Sequence{n,t,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var watch : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : boolean := false ; for w : Integer.subrange(0, n-1) do ( for i : Integer.subrange(0, e + 1-1) do ( if (t + i) mod watch[w+1] = 0 then ( ans := true ; break ) else skip ; if (t - i) mod watch[w+1] = 0 then ( ans := true ; break ) else skip) ; if ans = true then ( break ) else skip) ; if ans = true then ( execute (w + 1)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,T,E=map(int,input().split()) x=[int(X)for X in input().split()] a=-1 for i in range(T-E,T+E+1): for j in range(N): if i % x[j]==0 : a=j+1 print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var T : OclAny := null; var E : OclAny := null; Sequence{N,T,E} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := input().split()->select(X | true)->collect(X | (("" + ((X)))->toInteger())) ; var a : int := -1 ; for i : Integer.subrange(T - E, T + E + 1-1) do ( for j : Integer.subrange(0, N-1) do ( if i mod x[j+1] = 0 then ( a := j + 1 ) else skip)) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math input_1=input().split() [h_1,a_1,c_1]=list(map(int,input_1)) input_2=input().split() [h_2,a_2]=list(map(int,input_2)) n_strike=math.ceil(h_2/a_1) if n_strike>1 : n_heal=max([math.ceil(((n_strike-1)*a_2-h_1)/(c_1-a_2)+0.01),0]) else : n_heal=0 print(n_strike+n_heal) for i in range(n_heal): print("HEAL") for i in range(n_strike): print("STRIKE") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input skip : OclAny := input().split() ; Sequence{hh skip, ah skip, cah skip}->union(Sequence{ahh skip, ah skip, cah skip}->union(Sequence{ cahh skip, ah skip, cah skip })) := ((inputOclType["int"], inputOclType["int"])->collect( _x | (OclType["int"])->apply(_x) )) ; var input:= input().split() : OclAny := input().split() ; Sequence{h:= ((input_2)->collect( _x | (OclType["int"])->apply(_x) ))}->union(Sequence{ a:= ((input_2)->collect( _x | (OclType["int"])->apply(_x) )) }) := ((input_2)->collect( _x | (OclType["int"])->apply(_x) )) ; var n_strike : double := (ha.ceil(ha skip / a skip) / a.ceil(ha skip / a skip))->ceil() ; if n_strike > 1 then ( var n_heal : OclAny := (Sequence{(((n_strike - 1) * ah.ceil(((n_strike - 1) * ah(((n_strike - 1) * ah.ceil(((n_strike - 1) * ah skip - h skip) / (c skip - a0.01) + 0.01) - h.ceil(((n_strike - 1) * ah skip - h skip) / (c skip - a0.01) + 0.01)) / (c.ceil(((n_strike - 1) * ah skip - h skip) / (c skip - a0.01) + 0.01) - a0.01) + 0.01)->ceil(), 0 - h(((n_strike - 1) * ah.ceil(((n_strike - 1) * ah skip - h skip) / (c skip - a0.01) + 0.01) - h.ceil(((n_strike - 1) * ah skip - h skip) / (c skip - a0.01) + 0.01)) / (c.ceil(((n_strike - 1) * ah skip - h skip) / (c skip - a0.01) + 0.01) - a0.01) + 0.01)->ceil(), 0) / (c(((n_strike - 1) * ah.ceil(((n_strike - 1) * ah skip - h skip) / (c skip - a0.01) + 0.01) - h.ceil(((n_strike - 1) * ah skip - h skip) / (c skip - a0.01) + 0.01)) / (c.ceil(((n_strike - 1) * ah skip - h skip) / (c skip - a0.01) + 0.01) - a0.01) + 0.01)->ceil(), 0 - a0.01) + 0.01) - h.ceil(((n_strike - 1) * ah(((n_strike - 1) * ah.ceil(((n_strike - 1) * ah skip - h skip) / (c skip - a0.01) + 0.01) - h.ceil(((n_strike - 1) * ah skip - h skip) / (c skip - a0.01) + 0.01)) / (c.ceil(((n_strike - 1) * ah skip - h skip) / (c skip - a0.01) + 0.01) - a0.01) + 0.01)->ceil(), 0 - h(((n_strike - 1) * ah.ceil(((n_strike - 1) * ah skip - h skip) / (c skip - a0.01) + 0.01) - h.ceil(((n_strike - 1) * ah skip - h skip) / (c skip - a0.01) + 0.01)) / (c.ceil(((n_strike - 1) * ah skip - h skip) / (c skip - a0.01) + 0.01) - a0.01) + 0.01)->ceil(), 0) / (c(((n_strike - 1) * ah.ceil(((n_strike - 1) * ah skip - h skip) / (c skip - a0.01) + 0.01) - h.ceil(((n_strike - 1) * ah skip - h skip) / (c skip - a0.01) + 0.01)) / (c.ceil(((n_strike - 1) * ah skip - h skip) / (c skip - a0.01) + 0.01) - a0.01) + 0.01)->ceil(), 0 - a0.01) + 0.01)) / (c.ceil(((n_strike - 1) * ah(((n_strike - 1) * ah.ceil(((n_strike - 1) * ah skip - h skip) / (c skip - a0.01) + 0.01) - h.ceil(((n_strike - 1) * ah skip - h skip) / (c skip - a0.01) + 0.01)) / (c.ceil(((n_strike - 1) * ah skip - h skip) / (c skip - a0.01) + 0.01) - a0.01) + 0.01)->ceil(), 0 - h(((n_strike - 1) * ah.ceil(((n_strike - 1) * ah skip - h skip) / (c skip - a0.01) + 0.01) - h.ceil(((n_strike - 1) * ah skip - h skip) / (c skip - a0.01) + 0.01)) / (c.ceil(((n_strike - 1) * ah skip - h skip) / (c skip - a0.01) + 0.01) - a0.01) + 0.01)->ceil(), 0) / (c(((n_strike - 1) * ah.ceil(((n_strike - 1) * ah skip - h skip) / (c skip - a0.01) + 0.01) - h.ceil(((n_strike - 1) * ah skip - h skip) / (c skip - a0.01) + 0.01)) / (c.ceil(((n_strike - 1) * ah skip - h skip) / (c skip - a0.01) + 0.01) - a0.01) + 0.01)->ceil(), 0 - a0.01) + 0.01) - a0.01) + 0.01)->ceil()}->union(Sequence{ 0 }))->max() ) else ( n_heal := 0 ) ; execute (n_strike + n_heal)->display() ; for i : Integer.subrange(0, n_heal-1) do ( execute ("HEAL")->display()) ; for i : Integer.subrange(0, n_strike-1) do ( execute ("STRIKE")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil n=int(input()) x=[int(i)for i in input().split()] ans=0 x.sort() for idx,val in enumerate(x): m=int(ceil((idx+1)/(val+1))) ans=max(ans,m) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : int := 0 ; x := x->sort() ; for _tuple : Integer.subrange(1, (x)->size())->collect( _indx | Sequence{_indx-1, (x)->at(_indx)} ) do (var _indx : int := 1; var idx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var val : OclAny := _tuple->at(_indx); var m : int := ("" + ((ceil((idx + 1) / (val + 1)))))->toInteger() ; ans := Set{ans, m}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t,e=map(int,input().split()) x=list(map(int,input().split())) xi=x[:] x.insert(0,0) xi.sort() for i in xi : if t-(t//i*i)<=e or abs(t-((t//i+1)*i))<=e : print(x.index(i)) break else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; var e : OclAny := null; Sequence{n,t,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var xi : Sequence := x ; x := x.insertAt(0+1, 0) ; xi := xi->sort() ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name xi))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (expr (atom (name t))) - (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name t))) // (expr (atom (name i)))) * (expr (atom (name i)))))))) ))))) <= (comparison (expr (atom (name e)))))) or (logical_test (comparison (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name t))) - (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name t))) // (expr (atom (name i)))) + (expr (atom (number (integer 1))))))))) ))) * (expr (atom (name i)))))))) ))))))))) ))))) <= (comparison (expr (atom (name e)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil def cal_IST(h,r): IST=round((h*r*1.0)/360,3); int_IST=int(IST); float_IST=ceil((IST-int_IST)*60); print(int_IST,":",float_IST); if __name__=="__main__" : h=20 ; r=150 ; cal_IST(h,r); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( h := 20; ; r := 150; ; cal_IST(h, r); ) else skip; operation cal_IST(h : OclAny, r : OclAny) pre: true post: true activity: var IST : double := MathLib.roundN((h * r * 1.0) / 360, 3); ; var int_IST : int := ("" + ((IST)))->toInteger(); ; var float_IST : OclAny := ceil((IST - int_IST) * 60); ; execute (int_IST)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def printRoots(n): theta=math.pi*2/n for k in range(0,n): real=math.cos(k*theta) img=math.sin(k*theta) print(real,end=" ") if(img>=0): print("+i ",end=" ") else : print("-i ",end=" ") print(abs(img)) if __name__=='__main__' : printRoots(1) printRoots(2) printRoots(3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( printRoots(1) ; printRoots(2) ; printRoots(3) ) else skip; operation printRoots(n : OclAny) pre: true post: true activity: var theta : double := * 2 / n ; for k : Integer.subrange(0, n-1) do ( var real : OclAny := ; var img : double := (k * theta)->sin() ; execute (real)->display() ; if (img >= 0) then ( execute ("+i ")->display() ) else ( execute ("-i ")->display() ) ; execute ((img)->abs())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findCart(arr1,arr2,n,n1): for i in range(0,n): for j in range(0,n1): print("{",arr1[i],",",arr2[j],"},",sep="",end="") arr1=[1,2,3] arr2=[4,5,6] n1=len(arr1) n2=len(arr2) findCart(arr1,arr2,n1,n2); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr1 := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; arr2 := Sequence{4}->union(Sequence{5}->union(Sequence{ 6 })) ; n1 := (arr1)->size() ; var n2 : int := (arr2)->size() ; findCart(arr1, arr2, n1, n2);; operation findCart(arr1 : OclAny, arr2 : OclAny, n : OclAny, n1 : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n1-1) do ( execute ("{")->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def no_of_ways(s): n=len(s) count_left=0 count_right=0 for i in range(0,n,1): if(s[i]==s[0]): count_left+=1 else : break i=n-1 while(i>=0): if(s[i]==s[n-1]): count_right+=1 else : break i-=1 if(s[0]==s[n-1]): return((count_left+1)*(count_right+1)) else : return(count_left+count_right+1) if __name__=='__main__' : s="geeksforgeeks" print(no_of_ways(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( s := "geeksforgeeks" ; execute (no_of_ways(s))->display() ) else skip; operation no_of_ways(s : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; var count_left : int := 0 ; var count_right : int := 0 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (s[i+1] = s->first()) then ( count_left := count_left + 1 ) else ( break )) ; var i : double := n - 1 ; while (i >= 0) do ( if (s[i+1] = s[n - 1+1]) then ( count_right := count_right + 1 ) else ( break ) ; i := i - 1) ; if (s->first() = s[n - 1+1]) then ( return ((count_left + 1) * (count_right + 1)) ) else ( return (count_left + count_right + 1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100000 ; prime=[True]*(MAX+1); def SieveOfEratosthenes(): prime[1]=False ; prime[0]=False ; p=2 ; while(p*p<=MAX): if(prime[p]): i=p*2 ; while(i<=MAX): prime[i]=False ; i+=p ; p+=1 ; def SumOfKthPrimes(arr,n,k): c=0 ; sum=0 ; for i in range(n): if(prime[arr[i]]): c+=1 ; if(c % k==0): sum+=arr[i]; c=0 ; print(sum); SieveOfEratosthenes(); arr=[2,3,5,7,11]; n=len(arr); k=2 ; SumOfKthPrimes(arr,n,k); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 100000; ; var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (MAX + 1)); ; skip ; skip ; SieveOfEratosthenes(); ; arr := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{ 11 })))); ; n := (arr)->size(); ; k := 2; ; SumOfKthPrimes(arr, n, k);; operation SieveOfEratosthenes() pre: true post: true activity: prime[1+1] := false; ; prime->first() := false; ; var p : int := 2; ; while ((p * p->compareTo(MAX)) <= 0) do ( if (prime[p+1]) then ( var i : int := p * 2; ; while ((i->compareTo(MAX)) <= 0) do ( prime[i+1] := false; ; i := i + p;) ) else skip ; p := p + 1;); operation SumOfKthPrimes(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var c : int := 0; ; var sum : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (prime[arr[i+1]+1]) then ( c := c + 1; ; if (c mod k = 0) then ( sum := sum + arr[i+1]; ; c := 0; ) else skip ) else skip) ; execute (sum)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000000 prime=[True]*(MAX+1) def SieveOfEratosthenes(): prime[1]=False ; prime[0]=False ; p=2 while p*p<=MAX : if(prime[p]==True): for i in range(p*2,MAX+1,p): prime[i]=False p+=1 def productOfKthPrimes(arr,n,k): c=0 product=1 for i in range(n): if(prime[arr[i]]): c+=1 if(c % k==0): product*=arr[i] c=0 print(product) if __name__=="__main__" : SieveOfEratosthenes() n=5 k=2 arr=[2,3,5,7,11] productOfKthPrimes(arr,n,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1000000 ; var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (MAX + 1)) ; skip ; skip ; if __name__ = "__main__" then ( SieveOfEratosthenes() ; n := 5 ; k := 2 ; arr := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{ 11 })))) ; productOfKthPrimes(arr, n, k) ) else skip; operation SieveOfEratosthenes() pre: true post: true activity: prime[1+1] := false; ; prime->first() := false; ; var p : int := 2 ; while (p * p->compareTo(MAX)) <= 0 do ( if (prime[p+1] = true) then ( for i : Integer.subrange(p * 2, MAX + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip ; p := p + 1); operation productOfKthPrimes(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var c : int := 0 ; var product : int := 1 ; for i : Integer.subrange(0, n-1) do ( if (prime[arr[i+1]+1]) then ( c := c + 1 ; if (c mod k = 0) then ( product := product * arr[i+1] ; c := 0 ) else skip ) else skip) ; execute (product)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def SieveOfEratosthenes(): prime[1]=False prime[0]=False p=2 while p*p<=MAX : if prime[p]==True : for i in range(p*2,MAX+1,p): prime[i]=False p+=1 def solve(arr,n,k): c=0 Sum=0 for i in range(0,n): if prime[arr[i]]: c+=1 if c % k==0 : Sum+=arr[i] c=0 print(Sum) if __name__=="__main__" : MAX=1000000 prime=[True]*(MAX+1) SieveOfEratosthenes() n,k=5,2 arr=[2,3,5,7,11] solve(arr,n,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var MAX : int := 1000000 ; var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (MAX + 1)) ; SieveOfEratosthenes() ; Sequence{n,k} := Sequence{5,2} ; arr := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{ 11 })))) ; solve(arr, n, k) ) else skip; operation SieveOfEratosthenes() pre: true post: true activity: prime[1+1] := false ; prime->first() := false ; var p : int := 2 ; while (p * p->compareTo(MAX)) <= 0 do ( if prime[p+1] = true then ( for i : Integer.subrange(p * 2, MAX + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip ; p := p + 1); operation solve(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var c : int := 0 ; var Sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( if prime[arr[i+1]+1] then ( c := c + 1 ; if c mod k = 0 then ( Sum := Sum + arr[i+1] ; c := 0 ) else skip ) else skip) ; execute (Sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findAllSequences(diff,out,start,end): if(abs(diff)>(end-start+1)//2): return ; if(start>end): if(diff==0): print(''.join(list(out)),end=""); return ; out[start]='0' ; out[end]='1' ; findAllSequences(diff+1,out,start+1,end-1); out[start]=out[end]='1' ; findAllSequences(diff,out,start+1,end-1); out[start]=out[end]='0' ; findAllSequences(diff,out,start+1,end-1); out[start]='1' ; out[end]='0' ; findAllSequences(diff-1,out,start+1,end-1); n=2 ; out=[""]*(2*n); findAllSequences(0,out,0,2*n-1); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := 2; ; out := MatrixLib.elementwiseMult(Sequence{ "" }, (2 * n)); ; findAllSequences(0, out, 0, 2 * n - 1);; operation findAllSequences(diff : OclAny, out : OclAny, start : OclAny, end : OclAny) : OclAny pre: true post: true activity: if (((diff)->abs()->compareTo((end - start + 1) div 2)) > 0) then ( return; ) else skip ; if ((start->compareTo(end)) > 0) then ( if (diff = 0) then ( execute (StringLib.sumStringsWithSeparator(((out)), ''))->display(); ) else skip ; return; ) else skip ; out[start+1] := '0'; ; out[end+1] := '1'; ; findAllSequences(diff + 1, out, start + 1, end - 1); ; out[start+1] := '1'; var out[end+1] : String := '1'; ; findAllSequences(diff, out, start + 1, end - 1); ; out[start+1] := '0'; out[end+1] := '0'; ; findAllSequences(diff, out, start + 1, end - 1); ; out[start+1] := '1'; ; out[end+1] := '0'; ; findAllSequences(diff - 1, out, start + 1, end - 1);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h1,a1,c1=map(int,input().split()) h2,a2=map(int,input().split()) lis=[] while h2>0 : if h1>a2 or a1>=h2 : h2-=a1 lis.append('STRIKE') else : h1+=c1 lis.append('HEAL') h1-=a2 print(len(lis)) print('\n'.join(lis)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h1 : OclAny := null; var a1 : OclAny := null; var c1 : OclAny := null; Sequence{h1,a1,c1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h2 : OclAny := null; var a2 : OclAny := null; Sequence{h2,a2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lis : Sequence := Sequence{} ; while h2 > 0 do ( if (h1->compareTo(a2)) > 0 or (a1->compareTo(h2)) >= 0 then ( h2 := h2 - a1 ; execute (('STRIKE') : lis) ) else ( h1 := h1 + c1 ; execute (('HEAL') : lis) ) ; h1 := h1 - a2) ; execute ((lis)->size())->display() ; execute (StringLib.sumStringsWithSeparator((lis), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def resolve(): s,t=input().split() a,b=map(int,input().split()) u=input() print(a-(s==u),b-(t==u)) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; resolve(); operation resolve() pre: true post: true activity: var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := input().split() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var u : String := (OclFile["System.in"]).readLine() ; execute (a - (s = u))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) for jj in range(x): n=int(input()) if n==1 : print(3) else : if n % 2==1 : print(1) else : p=0 k=n while n % 2==0 : p+=1 n//=2 t=2**p if t==k : print(t+1) else : print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for jj : Integer.subrange(0, x-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (3)->display() ) else ( if n mod 2 = 1 then ( execute (1)->display() ) else ( var p : int := 0 ; var k : int := n ; while n mod 2 = 0 do ( p := p + 1 ; n := n div 2) ; var t : double := (2)->pow(p) ; if t = k then ( execute (t + 1)->display() ) else ( execute (t)->display() ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,bisect,math,itertools,string,queue,copy import numpy as np import scipy from collections import Counter,defaultdict,deque from itertools import permutations,combinations from heapq import heappop,heappush from fractions import gcd sys.setrecursionlimit(10**8) mod=10**9+7 def inp(): return int(input()) def inpm(): return map(int,input().split()) def inpl(): return list(map(int,input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(input())for _ in range(n)) def inplL(n): return[list(input())for _ in range(n)] def inplT(n): return[tuple(input())for _ in range(n)] def inpll(n): return[list(map(int,input().split()))for _ in range(n)] def inplls(n): return sorted([list(map(int,input().split()))for _ in range(n)]) s,t=input().split() a,b=inpm() u=input() if u==s : a-=1 elif u==t : b-=1 print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := input().split() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := inpm() ; var u : String := (OclFile["System.in"]).readLine() ; if u = s then ( a := a - 1 ) else (if u = t then ( b := b - 1 ) else skip) ; execute (a)->display(); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inpm() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inpls() : OclAny pre: true post: true activity: return (input().split()); operation inplm(n : OclAny) : OclAny pre: true post: true activity: return ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))); operation inplL(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((OclFile["System.in"]).readLine())->characters())); operation inplT(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((OclFile["System.in"]).readLine()))); operation inpll(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))); operation inplls(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))->sort(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(S : str,T : str,A : int,B : int,U : str): if S==U : A-=1 if T==U : B-=1 print(A,B) return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() S=next(tokens) T=next(tokens) A=int(next(tokens)) B=int(next(tokens)) U=next(tokens) solve(S,T,A,B,U) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(S : String, T : String, A : int, B : int, U : String) pre: true post: true activity: if S = U then ( A := A - 1 ) else skip ; if T = U then ( B := B - 1 ) else skip ; execute (A)->display() ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var S : OclAny := (tokens).next() ; var T : OclAny := (tokens).next() ; var A : int := ("" + (((tokens).next())))->toInteger() ; var B : int := ("" + (((tokens).next())))->toInteger() ; var U : OclAny := (tokens).next() ; solve(S, T, A, B, U); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S,T=map(str,input().split()) A,B=map(int,input().split()) U=str(input()) if U==S : A-=1 else : B-=1 print(A,B) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : OclAny := null; var T : OclAny := null; Sequence{S,T} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var U : String := ("" + (((OclFile["System.in"]).readLine()))) ; if U = S then ( A := A - 1 ) else ( B := B - 1 ) ; execute (A)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin s,t=stdin.readline().rstrip().split() a,b=[int(x)for x in stdin.readline().rstrip().split()] u=stdin.readline().rstrip() if(s==u): a-=1 if(t==u): b-=1 print(str(a)+" "+str(b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := stdin.readLine().rstrip().split() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := stdin.readLine().rstrip().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var u : OclAny := stdin.readLine().rstrip() ; if (s = u) then ( a := a - 1 ) else skip ; if (t = u) then ( b := b - 1 ) else skip ; execute (("" + ((a))) + " " + ("" + ((b))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(h,high): h.sort() summ=0 for i in range(len(h)-1,-1,-2): summ+=h[i] return summ<=high n,h=map(int,input().split()) a=list(map(int,input().split())) l=-1 r=len(a)+1 while r-l>1 : m=(r+l)//2 if check(a[: m],h): l=m else : r=m print(l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; Sequence{n,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : int := -1 ; var r : int := (a)->size() + 1 ; while r - l > 1 do ( var m : int := (r + l) div 2 ; if check(a.subrange(1,m), h) then ( l := m ) else ( r := m )) ; execute (l)->display(); operation check(h : OclAny, high : OclAny) : OclAny pre: true post: true activity: h := h->sort() ; var summ : int := 0 ; for i : Integer.subrange((h)->size() - 1, -1-1)->select( $x | ($x - (h)->size() - 1) mod -2 = 0 ) do ( summ := summ + h[i+1]) ; return (summ->compareTo(high)) <= 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def so(d,x,dlen): st=0 en=dlen while st=st and en>=0 : i=(st+en)//2 zz=d[i] if x>zz : st=i+1 elif x==zz : return d[: i]+[x]+d[i :] else : en=i-1 i=(st+en)//2 if i<0 : d=[x]+d elif i>=dlen : d=d+[x] elif xh : dlen=dlen-1 break print(dlen) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var I : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var h : OclAny := null; Sequence{n,h} := I->apply() ; d := Sequence{} ; dlen := 0 ; for i : I->apply() do ( d := so(d, i, dlen) ; dlen := dlen + 1 ; var gg : int := 0 ; for j : Integer.subrange(dlen - 1, -1-1)->select( $x | ($x - dlen - 1) mod -2 = 0 ) do ( gg := gg + d[j+1]) ; if (gg->compareTo(h)) > 0 then ( dlen := dlen - 1 ; break ) else skip) ; execute (dlen)->display(); operation so(d : OclAny, x : OclAny, dlen : OclAny) : OclAny pre: true post: true activity: var st : int := 0 ; var en : OclAny := dlen ; while (st->compareTo(dlen)) < 0 & (en->compareTo(st)) >= 0 & en >= 0 do ( var i : int := (st + en) div 2 ; var zz : OclAny := d[i+1] ; if (x->compareTo(zz)) > 0 then ( st := i + 1 ) else (if x = zz then ( return d.subrange(1,i)->union(Sequence{ x }) + d.subrange(i+1) ) else ( en := i - 1 ) ) ) ; i := (st + en) div 2 ; if i < 0 then ( d := Sequence{ x }->union(d) ) else (if (i->compareTo(dlen)) >= 0 then ( d := d->union(Sequence{ x }) ) else (if (x->compareTo(d[i+1])) < 0 then ( d := d.subrange(1,i)->union(Sequence{ x }) + d.subrange(i+1) ) else ( d := d.subrange(1,i + 1)->union(Sequence{ x }) + d.subrange(i + 1+1) ) ) ) ; return d; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=lambda : map(int,input().split()) n,h=I() d=[] dlen=0 for i in I(): d=sorted(d+[i]) dlen=dlen+1 gg=0 for j in range(dlen-1,-1,-2): gg=gg+d[j] if gg>h : dlen=dlen-1 break print(dlen) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var h : OclAny := null; Sequence{n,h} := I->apply() ; var d : Sequence := Sequence{} ; var dlen : int := 0 ; for i : I->apply() do ( d := d->union(Sequence{ i })->sort() ; dlen := dlen + 1 ; var gg : int := 0 ; for j : Integer.subrange(dlen - 1, -1-1)->select( $x | ($x - dlen - 1) mod -2 = 0 ) do ( gg := gg + d[j+1]) ; if (gg->compareTo(h)) > 0 then ( dlen := dlen - 1 ; break ) else skip) ; execute (dlen)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- exec('n,k,*a='+'*map(int,input().split()),'*2) while sum(sorted(a[: n])[: :-2])>k : n-=1 print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: (expr (expr (atom 'n,k,*a=')) + (expr (expr (atom '*map(int,input().split()),')) * (expr (atom (number (integer 2)))))) ; while ((sorted(a.subrange(1,n))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 2))))))))))->sum()->compareTo(k)) > 0 do ( n := n - 1) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline h1,a1,c1=map(int,input().split()) h2,a2=map(int,input().split()) c=(h2+a1-1)//a1 x=c-1 d=0 while 1 : if h1/a2>x : break d+=1 h1+=c1-a2 print(c+d) for i in range(d): print('HEAL') for i in range(c): print('STRIKE') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var h1 : OclAny := null; var a1 : OclAny := null; var c1 : OclAny := null; Sequence{h1,a1,c1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h2 : OclAny := null; var a2 : OclAny := null; Sequence{h2,a2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : int := (h2 + a1 - 1) div a1 ; var x : double := c - 1 ; var d : int := 0 ; while 1 do ( if (h1 / a2->compareTo(x)) > 0 then ( break ) else skip ; d := d + 1 ; h1 := h1 + c1 - a2) ; execute (c + d)->display() ; for i : Integer.subrange(0, d-1) do ( execute ('HEAL')->display()) ; for i : Integer.subrange(0, c-1) do ( execute ('STRIKE')->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class newNode : def __init__(self,data): self.data=data self.next=None def printList(node): while(node!=None): print(node.data,"->",end=" ") node=node.next print("NULL") def cntNodes(node): if(node==None): return 0 return(1+cntNodes(node.next)) def updateList(head,m): cnt=cntNodes(head) if(cnt!=m and m0): prev=curr curr=curr.next skip-=1 prev.next=None tempHead=head head=curr while(curr.next!=None): curr=curr.next curr.next=tempHead printList(head) head=newNode(4) head.next=newNode(5) head.next.next=newNode(6) head.next.next.next=newNode(1) head.next.next.next.next=newNode(2) head.next.next.next.next.next=newNode(3) m=3 updateList(head,m) ------------------------------------------------------------ OCL File: --------- class newNode { static operation newnewNode() : newNode pre: true post: newNode->exists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := null; operation initialise(data : OclAny) : newNode pre: true post: true activity: self.data := data ; self.next := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; head := (newNode.newnewNode()).initialise(4) ; head.next := (newNode.newnewNode()).initialise(5) ; head.next.next := (newNode.newnewNode()).initialise(6) ; head.next.next.next := (newNode.newnewNode()).initialise(1) ; head.next.next.next.next := (newNode.newnewNode()).initialise(2) ; head.next.next.next.next.next := (newNode.newnewNode()).initialise(3) ; m := 3 ; updateList(head, m); operation printList(node : OclAny) pre: true post: true activity: while (node /= null) do ( execute (node.data)->display() ; node := node.next) ; execute ("NULL")->display(); operation cntNodes(node : OclAny) : OclAny pre: true post: true activity: if (node = null) then ( return 0 ) else skip ; return (1 + cntNodes(node.next)); operation updateList(head : OclAny, m : OclAny) pre: true post: true activity: var cnt : OclAny := cntNodes(head) ; if (cnt /= m & (m->compareTo(cnt)) < 0) then ( var skip : double := cnt - m ; var prev : OclAny := null ; var curr : OclAny := head ; while (skip > 0) do ( prev := curr ; curr := curr.next ; skip := skip - 1) ; prev.next := null ; var tempHead : OclAny := head ; head := curr ; while (curr.next /= null) do ( curr := curr.next) ; curr.next := tempHead ) else skip ; printList(head); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxSubStrings(s,k): maxSubStr=0 n=len(s) for c in range(27): ch=chr(ord('a')+c) curr=0 for i in range(n-k): if(s[i]!=ch): continue cnt=0 while(idisplay() ) else skip; operation maxSubStrings(s : OclAny, k : OclAny) : OclAny pre: true post: true activity: var maxSubStr : int := 0 ; var n : int := (s)->size() ; for c : Integer.subrange(0, 27-1) do ( var ch : String := (('a')->char2byte() + c)->byte2char() ; var curr : int := 0 ; for i : Integer.subrange(0, n - k-1) do ( if (s[i+1] /= ch) then ( continue ) else skip ; var cnt : int := 0 ; while ((i->compareTo(n)) < 0 & s[i+1] = ch & cnt /= k) do ( i := i + 1 ; cnt := cnt + 1) ; i := i - 1 ; if (cnt = k) then ( curr := curr + 1 ) else skip) ; maxSubStr := Set{maxSubStr, curr}->max()) ; return maxSubStr; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) if(n==1): print(3) else : x=n &-n while(x==n or(x & n)==0): x+=1 print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n = 1) then ( execute (3)->display() ) else ( var x : int := MathLib.bitwiseAnd(n, -n) ; while (x = n or (MathLib.bitwiseAnd(x, n)) = 0) do ( x := x + 1) ; execute (x)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=100 def ansQueries(prefeven,prefodd,l,r): if((r-l+1)% 2==0): print("0") else : if(l % 2==0): print(prefeven[r]^ prefeven[l-1]) else : print(prefodd[r]^ prefodd[l-1]) def wrapper(arr,n,l,r,q): prefodd=[0]*N prefeven=[0]*N for i in range(1,n+1): if((i)% 2==0): prefeven[i]=arr[i-1]^ prefeven[i-1] prefodd[i]=prefodd[i-1] else : prefeven[i]=prefeven[i-1] prefodd[i]=prefodd[i-1]^ arr[i-1] i=0 while(i!=q): ansQueries(prefeven,prefodd,l[i],r[i]) i+=1 if __name__=="__main__" : arr=[1,2,3,4,5] n=len(arr) l=[1,1,2] r=[2,3,4] q=len(l) wrapper(arr,n,l,r,q) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 100 ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ; n := (arr)->size() ; l := Sequence{1}->union(Sequence{1}->union(Sequence{ 2 })) ; r := Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })) ; q := (l)->size() ; wrapper(arr, n, l, r, q) ) else skip; operation ansQueries(prefeven : OclAny, prefodd : OclAny, l : OclAny, r : OclAny) pre: true post: true activity: if ((r - l + 1) mod 2 = 0) then ( execute ("0")->display() ) else ( if (l mod 2 = 0) then ( execute (MathLib.bitwiseXor(prefeven[r+1], prefeven[l - 1+1]))->display() ) else ( execute (MathLib.bitwiseXor(prefodd[r+1], prefodd[l - 1+1]))->display() ) ); operation wrapper(arr : OclAny, n : OclAny, l : OclAny, r : OclAny, q : OclAny) pre: true post: true activity: prefodd := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; prefeven := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for i : Integer.subrange(1, n + 1-1) do ( if ((i) mod 2 = 0) then ( prefeven[i+1] := MathLib.bitwiseXor(arr[i - 1+1], prefeven[i - 1+1]) ; prefodd[i+1] := prefodd[i - 1+1] ) else ( prefeven[i+1] := prefeven[i - 1+1] ; prefodd[i+1] := MathLib.bitwiseXor(prefodd[i - 1+1], arr[i - 1+1]) )) ; var i : int := 0 ; while (i /= q) do ( ansQueries(prefeven, prefodd, l[i+1], r[i+1]) ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[int(i)for i in input().split()] l.sort(reverse=True) for i in range(1,n): if l[i]>=l[i-1]: if l[i-1]==0 : l[i]=0 else : l[i]=l[i-1]-1 else : l[i]=l[i] print(sum(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; l := l->sort() ; for i : Integer.subrange(1, n-1) do ( if (l[i+1]->compareTo(l[i - 1+1])) >= 0 then ( if l[i - 1+1] = 0 then ( l[i+1] := 0 ) else ( l[i+1] := l[i - 1+1] - 1 ) ) else ( l[i+1] := l[i+1] )) ; execute ((l)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=sorted([int(i)for i in input().split()],reverse=True) for i in range(1,n): if a[i]>=a[i-1]: a[i]=max(0,a[i-1]-1) print(sum(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; for i : Integer.subrange(1, n-1) do ( if (a[i+1]->compareTo(a[i - 1+1])) >= 0 then ( a[i+1] := Set{0, a[i - 1+1] - 1}->max() ) else skip) ; execute ((a)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().strip().split())) a.sort(reverse=True) p=c=a[0] for i in range(1,n): if a[i]

1 : c+=p-1 p=p-1 else : break else : if p>1 : c+=p-1 p=p-1 else : break print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var p : OclAny := a->first(); var c : OclAny := a->first() ; for i : Integer.subrange(1, n-1) do ( if (a[i+1]->compareTo(p)) < 0 then ( c := c + a[i+1] ; p := a[i+1] ) else (if a[i+1] = p then ( if p > 1 then ( c := c + p - 1 ; p := p - 1 ) else ( break ) ) else ( if p > 1 then ( c := c + p - 1 ; p := p - 1 ) else ( break ) ) ) ) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) a=list(map(int,input().split())) pre=float('inf') ans=0 a.sort(reverse=True) for j in range(n): ans+=max(0,min(pre-1,a[j])) pre=max(0,min(pre-1,a[j])) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var pre : double := ("" + (('inf')))->toReal() ; var ans : int := 0 ; a := a->sort() ; for j : Integer.subrange(0, n-1) do ( ans := ans + Set{0, Set{pre - 1, a[j+1]}->min()}->max() ; pre := Set{0, Set{pre - 1, a[j+1]}->min()}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) w=sorted(map(int,input().split()),reverse=True) for i in range(1,n): if w[i]>=w[i-1]: w[i]=max(0,w[i-1]-1) print(sum(w)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; for i : Integer.subrange(1, n-1) do ( if (w[i+1]->compareTo(w[i - 1+1])) >= 0 then ( w[i+1] := Set{0, w[i - 1+1] - 1}->max() ) else skip) ; execute ((w)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for p in range(int(input())): n,k=list(map(int,input().split())) a=list(map(int,input().split())) if n % 2 : x,y=n//2,n//2+1 else : x,y=n//2-1,n//2+1 if n==2 : s=0 for i in range(0,n*k,2): s+=a[i] print(s) else : d,s=x*k,0 while d<(n*k): s+=a[d] d+=y print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for p : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n mod 2 then ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{n div 2,n div 2 + 1} ) else ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{n div 2 - 1,n div 2 + 1} ) ; if n = 2 then ( var s : int := 0 ; for i : Integer.subrange(0, n * k-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( s := s + a[i+1]) ; execute (s)->display() ) else ( var d : OclAny := null; Sequence{d,s} := Sequence{x * k,0} ; while (d->compareTo((n * k))) < 0 do ( s := s + a[d+1] ; d := d + y) ; execute (s)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from typing import List def run(h1,a1,c1,h2,a2): rt=[] while h2>0 : if h1>a2 or a1>=h2 : h2-=a1 rt.append('STRIKE') else : rt.append('HEAL') h1+=c1 h1-=a2 return[str(len(rt))]+rt if sys.argv[-1]=='t' : cases=[["10 22 28 21 27",["1","STRIKE"]],["10 6 100 17 5",["4","STRIKE","HEAL","STRIKE","STRIKE"]],["11 6 100 12 5",["2","STRIKE","STRIKE"]],] for case in cases : r=run(*[int(d)for d in case[0].split('')]) if r!=case[1]: print(case,r) else : h1,a1,c1=input('').split('') h2,a2=input('').split('') for d in run(int(h1),int(a1),int(c1),int(h2),int(a2)): print(d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) = 't' then ( var cases : Sequence := Sequence{Sequence{"10 22 28 21 27"}->union(Sequence{ Sequence{"1"}->union(Sequence{ "STRIKE" }) })}->union(Sequence{Sequence{"10 6 100 17 5"}->union(Sequence{ Sequence{"4"}->union(Sequence{"STRIKE"}->union(Sequence{"HEAL"}->union(Sequence{"STRIKE"}->union(Sequence{ "STRIKE" })))) })}->union(Sequence{ Sequence{"11 6 100 12 5"}->union(Sequence{ Sequence{"2"}->union(Sequence{"STRIKE"}->union(Sequence{ "STRIKE" })) }) })) ; for case : cases do ( var r : OclAny := run((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name d)))))))) ))))))) (comp_for for (exprlist (expr (atom (name d)))) in (logical_test (comparison (expr (atom (name case)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ''))))))) )))))))) ]))))))) ; if r /= case[1+1] then ( execute (case)->display() ) else skip) ) else ( Sequence{h1,a1,c1} := input('').split('') ; Sequence{h2,a2} := input('').split('') ; for d : run(("" + ((h1)))->toInteger(), ("" + ((a1)))->toInteger(), ("" + ((c1)))->toInteger(), ("" + ((h2)))->toInteger(), ("" + ((a2)))->toInteger()) do ( execute (d)->display()) ); operation run(h1 : OclAny, a1 : OclAny, c1 : OclAny, h2 : OclAny, a2 : OclAny) : OclAny pre: true post: true activity: var rt : Sequence := Sequence{} ; while h2 > 0 do ( if (h1->compareTo(a2)) > 0 or (a1->compareTo(h2)) >= 0 then ( h2 := h2 - a1 ; execute (('STRIKE') : rt) ) else ( execute (('HEAL') : rt) ; h1 := h1 + c1 ) ; h1 := h1 - a2) ; return Sequence{ ("" + (((rt)->size()))) }->union(rt); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=[int(x)for x in input().split()] a=[int(a)for a in input().split()] a.sort(reverse=True) sum=0 jc_love1=n//2 jc_love=jc_love1 while k>0 : k-=1 sum+=a[jc_love] jc_love=jc_love+jc_love1+1 print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a : Sequence := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; a := a->sort() ; var sum : int := 0 ; var jc_love1 : int := n div 2 ; var jc_love : int := jc_love1 ; while k > 0 do ( k := k - 1 ; sum := sum + a[jc_love+1] ; jc_love := jc_love + jc_love1 + 1) ; execute (sum)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): n,k=map(int,input().split()) l=list(map(int,input().split())) if n==1 : print(sum(l)) elif n==2 : print(sum(l[: : 2])) else : if n % 2==0 : s=0 for i in range(1,k+1): s=s+l[-(i*(n//2+1))] print(s) else : s=0 for i in range(1,k+1): s=s+l[-(i*(n//2+1))] print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = 1 then ( execute ((l)->sum())->display() ) else (if n = 2 then ( execute ((l(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->sum())->display() ) else ( if n mod 2 = 0 then ( var s : int := 0 ; for i : Integer.subrange(1, k + 1-1) do ( s := s + l->reverse()->at(-(-(i * (n div 2 + 1))))) ; execute (s)->display() ) else ( s := 0 ; for i : Integer.subrange(1, k + 1-1) do ( s := s + l->reverse()->at(-(-(i * (n div 2 + 1))))) ; execute (s)->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os.path import sys from math import* from math import floor,gcd,fabs,factorial,fmod,sqrt,inf,log if os.path.exists('input.txt'): sys.stdin=open('input.txt','r') sys.stdout=open('output.txt','w') def inp(): return sys.stdin.readline().strip() for _ in range(int(inp())): n,k=map(int,inp().split()) arr=list(map(int,inp().split())) ans=0 if n % 2==0 : x=n//2 else : x=n//2+1 a=n-x+1 b=0 for i in range(len(arr)-a,-1,-a): if b==k : break ans+=arr[i] b+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if os.path.exists('input.txt') then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('input.txt')) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile('output.txt')) ) else skip ; skip ; for _anon : Integer.subrange(0, ("" + ((inp())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (inp().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((inp().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; if n mod 2 = 0 then ( var x : int := n div 2 ) else ( x := n div 2 + 1 ) ; var a : double := n - x + 1 ; var b : int := 0 ; for i : Integer.subrange((arr)->size() - a, -1-1)->select( $x | ($x - (arr)->size() - a) mod -a = 0 ) do ( if b = k then ( break ) else skip ; ans := ans + arr[i+1] ; b := b + 1) ; execute (ans)->display()); operation inp() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x=int(input()) ans=(x & ~(x-1)) if x==1 : print(3) elif x==ans : print(ans+1) else : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := (MathLib.bitwiseAnd(x, MathLib.bitwiseNot((x - 1)))) ; if x = 1 then ( execute (3)->display() ) else (if x = ans then ( execute (ans + 1)->display() ) else ( execute (ans)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout T=int(stdin.readline()) for i in range(T): N,K=map(int,stdin.readline().strip().split()) A=list(map(int,stdin.readline().strip().split())) X=N-N//2 if N % 2==0 : X+=1 SUM=0 COUNT=0 DONE=0 for j in range(len(A)-1,-1,-1): COUNT+=1 if COUNT==X : SUM+=A[j] DONE+=1 COUNT=0 if DONE==K : break stdout.write(f"{SUM}\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var T : int := ("" + ((stdin.readLine())))->toInteger() ; for i : Integer.subrange(0, T-1) do ( var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var X : double := N - N div 2 ; if N mod 2 = 0 then ( X := X + 1 ) else skip ; var SUM : int := 0 ; var COUNT : int := 0 ; var DONE : int := 0 ; for j : Integer.subrange(-1 + 1, (A)->size() - 1)->reverse() do ( COUNT := COUNT + 1 ; if COUNT = X then ( SUM := SUM + A[j+1] ; DONE := DONE + 1 ; COUNT := 0 ) else skip ; if DONE = K then ( break ) else skip) ; stdout.write(StringLib.formattedString("{SUM}\n"))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,r=input().split(' ') stack=[[]for _ in range(int(n))] for _ in range(int(r)): row=list(map(int,input().split(' '))) c=row[0] i=row[1] if c==0 : stack[i].append(row[2]) if stack[i]: if c==1 : print(stack[i][-1]) if c==2 : stack[i].pop() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var r : OclAny := null; Sequence{n,r} := input().split(' ') ; var stack : Sequence := Integer.subrange(0, ("" + ((n)))->toInteger()-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, ("" + ((r)))->toInteger()-1) do ( var row : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var c : OclAny := row->first() ; var i : OclAny := row[1+1] ; if c = 0 then ( (expr (atom (name stack)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name row)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))) )))) ) else skip ; if stack[i+1] then ( if c = 1 then ( execute (stack[i+1]->last())->display() ) else skip ; if c = 2 then ( (expr (atom (name stack)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name pop) (arguments ( )))) ) else skip ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout from collections import defaultdict,deque n,q=map(int,stdin.readline().split()) queries=stdin.readlines() A=defaultdict(deque) ans=[] for query in queries : query=query.split() if query[0]=='0' : A[int(query[1])].append(query[2]) elif query[0]=='1' : index=int(query[1]) if A[index]: ans.append(A[index][-1]) else : index=int(query[1]) if A[index]: A[index].pop() print('\n'.join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var queries : OclAny := stdin.readlines() ; var A : OclAny := defaultdict(deque) ; var ans : Sequence := Sequence{} ; for query : queries do ( var query : OclAny := query.split() ; if query->first() = '0' then ( (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name query)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name query)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))) )))) ) else (if query->first() = '1' then ( var index : int := ("" + ((query[1+1])))->toInteger() ; if A[index+1] then ( execute ((A[index+1]->last()) : ans) ) else skip ) else ( index := ("" + ((query[1+1])))->toInteger() ; if A[index+1] then ( (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name index)))))))) ])) (trailer . (name pop) (arguments ( )))) ) else skip ) ) ) ; execute (StringLib.sumStringsWithSeparator((ans), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- readline=open(0).readline writelines=open(1,'w').writelines N,Q=map(int,readline().split()) ans=[] A=[[]for i in range(N)] def push(t,x): A[t].append(x) def top(t): A[t]and ans.append("%d\n" % A[t][-1]) def pop(t): A[t]and A[t].pop() C=[push,top,pop].__getitem__ for i in range(Q): t,*a=map(int,readline().split()) C(t)(*a) writelines(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var readline : OclAny := open(0).readline ; var writelines : OclAny := open(1, 'w').writelines ; var N : OclAny := null; var Q : OclAny := null; Sequence{N,Q} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := Sequence{} ; var A : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{})) ; skip ; skip ; skip ; var C : OclAny := Sequence{push}->union(Sequence{top}->union(Sequence{ pop })).__getitem__ ; for i : Integer.subrange(0, Q-1) do ( var a : OclAny := null; Sequence{t,a} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name C)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) ))) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; writelines(ans); operation push(t : OclAny, x : OclAny) pre: true post: true activity: (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))); operation top(t : OclAny) pre: true post: true activity: (logical_test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ]))))) and (logical_test (comparison (expr (atom (name ans)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom "%d\n")) % (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))))))))) ))))))); operation pop(t : OclAny) pre: true post: true activity: (logical_test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ]))))) and (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name pop) (arguments ( ))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque from typing import List if __name__=="__main__" : stack_num,query_num=map(lambda x : int(x),input().split()) stacks : List[deque]=[deque()for _ in range(stack_num)] for _ in range(query_num): op,*value=map(lambda x : int(x),input().split()) if(0==op): stacks[value[0]].append(value[1]) elif(1==op): stack=stacks[value[0]] if(0!=len(stack)): print(stack[len(stack)-1]) elif(2==op): stack=stacks[value[0]] if(0!=len(stack)): stack.pop() else : pass ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var stack_num : OclAny := null; var query_num : OclAny := null; Sequence{stack_num,query_num} := (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ) ; var stacks : OclAny := Integer.subrange(0, stack_num-1)->select(_anon | true)->collect(_anon | (())) ; for _anon : Integer.subrange(0, query_num-1) do ( var op : OclAny := null; var value : OclAny := null; Sequence{op,value} := (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ) ; if (0 = op) then ( (expr (atom (name stacks)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name value)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name value)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))) ) else (if (1 = op) then ( var stack : OclAny := stacks[value->first()+1] ; if (0 /= (stack)->size()) then ( execute (stack[(stack)->size() - 1+1])->display() ) else skip ) else (if (2 = op) then ( stack := stacks[value->first()+1] ; if (0 /= (stack)->size()) then ( stack := stack->front() ) else skip ) else ( skip ) ) ) ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class TwoDimStack(): def __init__(self,num_stack): self.stacks=[[]for i in range(0,num_stack,1)] def push(self,t,x): self.stacks[t].append(x) return self def top(self,t): if len(self.stacks[t])>0 : print(f'{self.stacks[t][len(self.stacks[t])-1]}') return self def pop(self,t): if len(self.stacks[t])>0 : self.stacks[t].pop() return self num_stack,num_queue=tuple(map(int,input().split(' '))) stacks=TwoDimStack(num_stack) for i in range(0,num_queue): queue=tuple(map(int,input().split(' '))) if queue[0]==0 : stacks.push(queue[1],queue[2]) elif queue[0]==1 : stacks.top(queue[1]) elif queue[0]==2 : stacks.pop(queue[1]) ------------------------------------------------------------ OCL File: --------- class TwoDimStack { static operation newTwoDimStack() : TwoDimStack pre: true post: TwoDimStack->exists( _x | result = _x ); attribute stacks : Sequence := Integer.subrange(0, num_stack-1)->select( $x | ($x - 0) mod 1 = 0 )->select(i | true)->collect(i | (Sequence{})); operation initialise(num_stack : OclAny) : pre: true post: true activity: self.stacks := Integer.subrange(0, num_stack-1)->select( $x | ($x - 0) mod 1 = 0 )->select(i | true)->collect(i | (Sequence{})); return self; operation push(t : OclAny,x : OclAny) : OclAny pre: true post: true activity: (expr (atom (name self)) (trailer . (name stacks) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) ; return self; operation top(t : OclAny) : OclAny pre: true post: true activity: if (self.stacks[t+1])->size() > 0 then ( execute (StringLib.formattedString('{self.stacks[t][len(self.stacks[t])-1]}'))->display() ) else skip ; return self; operation pop(t : OclAny) : OclAny pre: true post: true activity: if (self.stacks[t+1])->size() > 0 then ( (expr (atom (name self)) (trailer . (name stacks) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name pop) (arguments ( )))) ) else skip ; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; var num_queue : OclAny := null; Sequence{num_stack,num_queue} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var stacks : TwoDimStack := (TwoDimStack.newTwoDimStack()).initialise(num_stack) ; for i : Integer.subrange(0, num_queue-1) do ( var queue : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; if queue->first() = 0 then ( stacks.push(queue[1+1], queue[2+1]) ) else (if queue->first() = 1 then ( stacks.top(queue[1+1]) ) else (if queue->first() = 2 then ( stacks := stacks->excludingAt(queue[1+1]+1) ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from enum import Enum class Action(Enum): STRIKE="STRIKE" HEAL="HEAL" def get(l1,l2): h1=l1[0] a1=l1[1] c1=l1[2] h2=l2[0] a2=l2[1] ret=[] while h2>0 : if h2<=a1 : ret.append(Action.STRIKE) return ret if h1<=a2 : h1=h1+c1-a2 ret.append(Action.HEAL) continue ret.append(Action.STRIKE) h1=h1-a2 h2=h2-a1 if __name__=='__main__' : l1=input().split() l2=input().split() l1=[int(x)for x in l1] l2=[int(x)for x in l2] ret=get(l1,l2) print(len(ret)) for x in ret : print(x.value) ------------------------------------------------------------ OCL File: --------- class Action { static operation newAction() : Action pre: true post: Action->exists( _x | result = _x ); static attribute STRIKE : String := "STRIKE"; static attribute HEAL : String := "HEAL"; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( l1 := input().split() ; l2 := input().split() ; l1 := l1->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; l2 := l2->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; ret := get(l1, l2) ; execute ((ret)->size())->display() ; for x : ret do ( execute (x.value)->display()) ) else skip; operation get(l1 : OclAny, l2 : OclAny) : OclAny pre: true post: true activity: var h1 : OclAny := l1->first() ; var a1 : OclAny := l1[1+1] ; var c1 : OclAny := l1[2+1] ; var h2 : OclAny := l2->first() ; var a2 : OclAny := l2[1+1] ; var ret : Sequence := Sequence{} ; while h2 > 0 do ( if (h2->compareTo(a1)) <= 0 then ( execute (((Action.newAction()).initialise.STRIKE) : ret) ; return ret ) else skip ; if (h1->compareTo(a2)) <= 0 then ( h1 := h1 + c1 - a2 ; execute (((Action.newAction()).initialise.HEAL) : ret) ; continue ) else skip ; execute (((Action.newAction()).initialise.STRIKE) : ret) ; h1 := h1 - a2 ; h2 := h2 - a1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printArray(arr,n): for i in range(n): print(arr[i],end=" "); def removeMin(arr,n): minVal=arr[0]; for i in range(1,n): minVal=min(minVal,arr[i]); for i in range(n): arr[i]=arr[i]-minVal ; def removeFromMax(arr,n): maxVal=arr[0]; for i in range(1,n): maxVal=max(maxVal,arr[i]); for i in range(n): arr[i]=maxVal-arr[i]; def modifyArray(arr,n,k): if(k % 2==0): removeMin(arr,n); else : removeFromMax(arr,n); printArray(arr,n); if __name__=="__main__" : arr=[4,8,12,16]; n=len(arr) k=2 ; modifyArray(arr,n,k); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{4}->union(Sequence{8}->union(Sequence{12}->union(Sequence{ 16 }))); ; n := (arr)->size() ; k := 2; ; modifyArray(arr, n, k); ) else skip; operation printArray(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display();); operation removeMin(arr : OclAny, n : OclAny) pre: true post: true activity: var minVal : OclAny := arr->first(); ; for i : Integer.subrange(1, n-1) do ( minVal := Set{minVal, arr[i+1]}->min();) ; for i : Integer.subrange(0, n-1) do ( arr[i+1] := arr[i+1] - minVal;); operation removeFromMax(arr : OclAny, n : OclAny) pre: true post: true activity: var maxVal : OclAny := arr->first(); ; for i : Integer.subrange(1, n-1) do ( maxVal := Set{maxVal, arr[i+1]}->max();) ; for i : Integer.subrange(0, n-1) do ( arr[i+1] := maxVal - arr[i+1];); operation modifyArray(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: if (k mod 2 = 0) then ( removeMin(arr, n); ) else ( removeFromMax(arr, n); ) ; printArray(arr, n);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find_Centroid(v): ans=[0,0] n=len(v) signedArea=0 for i in range(len(v)): x0=v[i][0] y0=v[i][1] x1=v[(i+1)% n][0] y1=v[(i+1)% n][1] A=(x0*y1)-(x1*y0) signedArea+=A ans[0]+=(x0+x1)*A ans[1]+=(y0+y1)*A signedArea*=0.5 ans[0]=(ans[0])/(6*signedArea) ans[1]=(ans[1])/(6*signedArea) return ans vp=[[1,2],[3,-4],[6,-7]] ans=find_Centroid(vp) print(round(ans[0],12),ans[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var vp : Sequence := Sequence{Sequence{1}->union(Sequence{ 2 })}->union(Sequence{Sequence{3}->union(Sequence{ -4 })}->union(Sequence{ Sequence{6}->union(Sequence{ -7 }) })) ; ans := find_Centroid(vp) ; execute (MathLib.roundN(ans->first(), 12))->display(); operation find_Centroid(v : OclAny) : OclAny pre: true post: true activity: var ans : Sequence := Sequence{0}->union(Sequence{ 0 }) ; var n : int := (v)->size() ; var signedArea : int := 0 ; for i : Integer.subrange(0, (v)->size()-1) do ( var x0 : OclAny := v[i+1]->first() ; var y0 : OclAny := v[i+1][1+1] ; var x1 : OclAny := v[(i + 1) mod n+1]->first() ; var y1 : OclAny := v[(i + 1) mod n+1][1+1] ; var A : double := (x0 * y1) - (x1 * y0) ; signedArea := signedArea + A ; ans->first() := ans->first() + (x0 + x1) * A ; ans[1+1] := ans[1+1] + (y0 + y1) * A) ; signedArea := signedArea * 0.5 ; ans->first() := (ans->first()) / (6 * signedArea) ; ans[1+1] := (ans[1+1]) / (6 * signedArea) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) color='blue' block=0 i=0 while i!=n : command=str(input()) if command=='lock' : block=1 elif command=='unlock' : block=0 elif block==0 : color=command i+=1 print(color) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var color : String := 'blue' ; var block : int := 0 ; var i : int := 0 ; while i /= n do ( var command : String := ("" + (((OclFile["System.in"]).readLine()))) ; if command = 'lock' then ( block := 1 ) else (if command = 'unlock' then ( block := 0 ) else (if block = 0 then ( color := command ) else skip ) ) ; i := i + 1) ; execute (color)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) default_color='blue' unlock=True for i in range(n): msg=input() if msg=='lock' : unlock=False elif msg=='unlock' : unlock=True else : if unlock : default_color=msg print(default_color) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var default_color : String := 'blue' ; var unlock : boolean := true ; for i : Integer.subrange(0, n-1) do ( var msg : String := (OclFile["System.in"]).readLine() ; if msg = 'lock' then ( unlock := false ) else (if msg = 'unlock' then ( unlock := true ) else ( if unlock then ( default_color := msg ) else skip ) ) ) ; execute (default_color)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x=int(input()) ans=((x ^(x-1))+1)>>1 if x==1 : print(3) elif x==ans : print(ans+1) else : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := ((MathLib.bitwiseXor(x, (x - 1))) + 1) /(2->pow(1)) ; if x = 1 then ( execute (3)->display() ) else (if x = ans then ( execute (ans + 1)->display() ) else ( execute (ans)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- current_color='blue' colors=['red','orange','yellow','green','blue','indigo','violet'] is_lock=False number=int(input()) for _ in range(number): command=input() if command=='lock' : is_lock=True elif command=='unlock' : is_lock=False elif not is_lock and command in colors : current_color=command print(current_color) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var current_color : String := 'blue' ; var colors : Sequence := Sequence{'red'}->union(Sequence{'orange'}->union(Sequence{'yellow'}->union(Sequence{'green'}->union(Sequence{'blue'}->union(Sequence{'indigo'}->union(Sequence{ 'violet' })))))) ; var is_lock : boolean := false ; var number : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, number-1) do ( var command : String := (OclFile["System.in"]).readLine() ; if command = 'lock' then ( is_lock := true ) else (if command = 'unlock' then ( is_lock := false ) else (if not(is_lock) & (colors)->includes(command) then ( current_color := command ) else skip ) ) ) ; execute (current_color)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) color="blue" locked=False for i in range(x): text=input() if text=="lock" : locked=True elif text=="unlock" : locked=False elif not locked : color=text print(color) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var color : String := "blue" ; var locked : boolean := false ; for i : Integer.subrange(0, x-1) do ( var text : String := (OclFile["System.in"]).readLine() ; if text = "lock" then ( locked := true ) else (if text = "unlock" then ( locked := false ) else (if not(locked) then ( color := text ) else skip ) ) ) ; execute (color)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) color="blue" lock=False for i in range(n): msg=input() if msg=="lock" : lock=True elif msg=="unlock" : lock=False elif not lock : color=msg print(color) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var color : String := "blue" ; var lock : boolean := false ; for i : Integer.subrange(0, n-1) do ( var msg : String := (OclFile["System.in"]).readLine() ; if msg = "lock" then ( lock := true ) else (if msg = "unlock" then ( lock := false ) else (if not(lock) then ( color := msg ) else skip ) ) ) ; execute (color)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minOperations(ar,k): ar=sorted(ar) opsNeeded=0 for i in range(k): opsNeeded+=ar[k-1]-ar[i] ans=opsNeeded for i in range(k,len(ar)): opsNeeded=opsNeeded-(ar[i-1]-ar[i-k]) opsNeeded+=(k-1)*(ar[i]-ar[i-1]) ans=min(ans,opsNeeded) return ans arr=[3,1,9,100] n=len(arr) k=3 print(minOperations(arr,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var arr : Sequence := Sequence{3}->union(Sequence{1}->union(Sequence{9}->union(Sequence{ 100 }))) ; var n : int := (arr)->size() ; k := 3 ; execute (minOperations(arr, k))->display(); operation minOperations(ar : OclAny, k : OclAny) : OclAny pre: true post: true activity: ar := ar->sort() ; var opsNeeded : int := 0 ; for i : Integer.subrange(0, k-1) do ( opsNeeded := opsNeeded + ar[k - 1+1] - ar[i+1]) ; var ans : int := opsNeeded ; for i : Integer.subrange(k, (ar)->size()-1) do ( opsNeeded := opsNeeded - (ar[i - 1+1] - ar[i - k+1]) ; opsNeeded := opsNeeded + (k - 1) * (ar[i+1] - ar[i - 1+1]) ; ans := Set{ans, opsNeeded}->min()) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def charCheck(input_char): if((int(ord(input_char))>=65 and int(ord(input_char))<=90)or(int(ord(input_char))>=97 and int(ord(input_char))<=122)): print(" Alphabet ") elif(int(ord(input_char))>=48 and int(ord(input_char))<=57): print(" Digit ") else : print(" Special Character ") input_char='$' charCheck(input_char) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; input_char := '$' ; charCheck(input_char); operation charCheck(input_char : OclAny) pre: true post: true activity: if ((("" + (((input_char)->char2byte())))->toInteger() >= 65 & ("" + (((input_char)->char2byte())))->toInteger() <= 90) or (("" + (((input_char)->char2byte())))->toInteger() >= 97 & ("" + (((input_char)->char2byte())))->toInteger() <= 122)) then ( execute (" Alphabet ")->display() ) else (if (("" + (((input_char)->char2byte())))->toInteger() >= 48 & ("" + (((input_char)->char2byte())))->toInteger() <= 57) then ( execute (" Digit ")->display() ) else ( execute (" Special Character ")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(1000000000) ii=lambda : int(input()) mis=lambda : map(int,input().split()) lmis=lambda : list(mis()) def main(): N=ii() L=lmis() L.sort() import bisect ans=0 for ia in range(N): a=L[ia] for ib in range(ia+1,N): b=L[ib] ans+=max(0,bisect.bisect_left(L,a+b)-(ib+1)) print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(1000000000) ; var ii : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var mis : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lmis : Function := lambda $$ : OclAny in ((mis->apply())) ; skip ; main(); operation main() pre: true post: true activity: var N : OclAny := ii->apply() ; var L : OclAny := lmis->apply() ; L := L->sort() ; skip ; var ans : int := 0 ; for ia : Integer.subrange(0, N-1) do ( var a : OclAny := L[ia+1] ; for ib : Integer.subrange(ia + 1, N-1) do ( var b : OclAny := L[ib+1] ; ans := ans + Set{0, bisect.bisect_left(L, a + b) - (ib + 1)}->max())) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools as i,collections as c b=c.Counter(s[0]for s in open(0).readlines()[1 :]if s[0]in "MARCH") print(sum(p*q*r for p,q,r in i.combinations(b.values(),3))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var b : OclAny := c.Counter((argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name open)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))) (trailer . (name readlines) (arguments ( ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) in (comparison (expr (atom "MARCH")))))))))) ; execute (((argument (test (logical_test (comparison (expr (expr (expr (atom (name p))) * (expr (atom (name q)))) * (expr (atom (name r))))))) (comp_for for (exprlist (expr (atom (name p))) , (expr (atom (name q))) , (expr (atom (name r)))) in (logical_test (comparison (expr (atom (name i)) (trailer . (name combinations) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)) (trailer . (name values) (arguments ( )))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 3))))))))) )))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) mat=[[]for i in range(n)] b=[int(j)-1 for j in str(input()).split('')] for i in range(n): mat[i].append(b[i]) i=0 h='' i=0 while i1 : break a=mat[a][0] m=0 j=0 while jm : m=l[j] x=j+1 j=j+1 h=h+str(x)+'' i=i+1 print(h) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mat : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; var b : Sequence := OclType["String"]((OclFile["System.in"]).readLine()).split('')->select(j | true)->collect(j | (("" + ((j)))->toInteger() - 1)) ; for i : Integer.subrange(0, n-1) do ((expr (atom (name mat)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))) ; var i : int := 0 ; var h : String := '' ; i := 0 ; while (i->compareTo(n)) < 0 do ( var l : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (0)) ; var a : int := i ; while true do ( l[a+1] := l[a+1] + 1 ; if l[a+1] > 1 then ( break ) else skip ; a := mat[a+1]->first()) ; var m : int := 0 ; var j : int := 0 ; while (j->compareTo(n)) < 0 do ( if (l[j+1]->compareTo(m)) > 0 then ( m := l[j+1] ; var x : int := j + 1 ) else skip ; j := j + 1) ; h := h + ("" + ((x))) + '' ; i := i + 1) ; execute (h)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) w=list(map(int,input().split())) q=[] for i in range(n): d=[1]*n while d[i]: d[i]=0 i=w[i]-1 print(i+1,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, n) ; while d[i+1] do ( d[i+1] := 0 ; var i : double := w[i+1] - 1) ; execute (i + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections if __name__=='__main__' : n=int(input()) p=list(map(int,input().strip().split())) graph=collections.defaultdict(list) for i in range(n): graph[i+1].append(p[i]) res=[] for i in range(1,n+1): que=collections.deque([i]) seen=set() while que : curNode=que.popleft() if curNode in seen : res.append(str(curNode)) break seen.add(curNode) for nxtNode in graph[curNode]: que.append(nxtNode) print(" ".join(res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var graph : OclAny := .defaultdict(OclType["Sequence"]) ; for i : Integer.subrange(0, n-1) do ((expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))) ; var res : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( var que : Sequence := (Sequence{ i }) ; var seen : Set := Set{}->union(()) ; while que do ( var curNode : OclAny := que->first() ; que := que->tail() ; if (seen)->includes(curNode) then ( execute ((("" + ((curNode)))) : res) ; break ) else skip ; execute ((curNode) : seen) ; for nxtNode : graph[curNode+1] do ( execute ((nxtNode) : que)))) ; execute (StringLib.sumStringsWithSeparator((res), " "))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def me(a): c=[-1]*len(a) n=-101 for i in range(len(a)): if c[i]==-1 : r=i while c[r]==-1 : c[r]=n r=a[r] if c[r]==n : y=i while y!=r : c[y]=r y=a[y] elif c[r]<=-101 : y=i while y!=r : c[y]=r y=a[y] elif c[r]>=0 : y=i while y!=r : c[y]=c[r] y=a[y] n-=1 for i in range(len(c)): if c[i]<=-101 : c[i]=i return(' '.join(str(x+1)for x in c)) input() a=[int(x)-1 for x in input().split(' ')] print(me(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; input() ; a := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)) ; execute (me(a))->display(); operation me(a : OclAny) : OclAny pre: true post: true activity: var c : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (a)->size()) ; var n : int := -101 ; for i : Integer.subrange(0, (a)->size()-1) do ( if c[i+1] = -1 then ( var r : OclAny := i ; while c[r+1] = -1 do ( c[r+1] := n ; r := a[r+1]) ; if c[r+1] = n then ( var y : OclAny := i ; while y /= r do ( c[y+1] := r ; y := a[y+1]) ) else (if c[r+1] <= -101 then ( y := i ; while y /= r do ( c[y+1] := r ; y := a[y+1]) ) else (if c[r+1] >= 0 then ( y := i ; while y /= r do ( c[y+1] := c[r+1] ; y := a[y+1]) ) else skip ) ) ; n := n - 1 ) else skip) ; for i : Integer.subrange(0, (c)->size()-1) do ( if c[i+1] <= -101 then ( c[i+1] := i ) else skip) ; return (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (number (integer 1)))))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name c)))))))), ' ')); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) p=[0]+list(map(int,input().split())) ans=[] for i in range(1,n+1): visit=[0]*(n+1) j=i while not visit[j]: visit[j]=1 j=p[j] ans.append(j) sys.stdout.write(" ".join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( var visit : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var j : OclAny := i ; while not(visit[j+1]) do ( visit[j+1] := 1 ; j := p[j+1]) ; execute ((j) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " ") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) print(3 if n==1 else n &-n if n &(n-1)else(n &-n)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (if n = 1 then 3 else if MathLib.bitwiseAnd(n, (n - 1)) then MathLib.bitwiseAnd(n, -n) else (MathLib.bitwiseAnd(n, -n)) + 1 endif endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,m=map(int,input().split()) w=list(map(int,input().split())) d=[[]for i in range(n)] for i in range(m): a,b=map(int,input().split()) d[a-1].append(b) d[b-1].append(a) x=[] for i in range(n): if len(d[i])>1 : for i1 in range(len(d[i])): for i2 in range(i1+1,len(d[i])): if(i+1 in d[d[i][i1]-1])and(d[i][i2]in d[d[i][i1]-1])and(i+1 in d[d[i][i2]-1])and(d[i][i1]in d[d[i][i2]-1]): z=(i+1,d[i][i1],d[i][i2]) x.append(z) c1=1e9 for a,b,c in x : c1=min(c1,w[a-1]+w[b-1]+w[c-1]) print(c1 if c1!=1e9 else-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var x : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if (d[i+1])->size() > 1 then ( for i1 : Integer.subrange(0, (d[i+1])->size()-1) do ( for i2 : Integer.subrange(i1 + 1, (d[i+1])->size()-1) do ( if ((d[d[i+1][i1+1] - 1+1])->includes(i + 1)) & ((d[d[i+1][i1+1] - 1+1])->includes(d[i+1][i2+1])) & ((d[d[i+1][i2+1] - 1+1])->includes(i + 1)) & ((d[d[i+1][i2+1] - 1+1])->includes(d[i+1][i1+1])) then ( var z : OclAny := Sequence{i + 1, d[i+1][i1+1], d[i+1][i2+1]} ; execute ((z) : x) ) else skip)) ) else skip) ; var c1 : double := ("1e9")->toReal() ; for _tuple : x do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); c1 := Set{c1, w[a - 1+1] + w[b - 1+1] + w[c - 1+1]}->min()) ; execute (if c1 /= ("1e9")->toReal() then c1 else -1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=lambda : map(int,input().split()) n,m=I() N=list(I()) p=set() for i in range(m): x,y=I(); x-=1 ; y-=1 p.add((x,y)if x1e8 else r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := I->apply() ; var N : Sequence := (I->apply()) ; var p : Set := Set{}->union(()) ; for i : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := I->apply(); x := x - 1; y := y - 1 ; execute ((if (x->compareTo(y)) < 0 then Sequence{x, y} else Sequence{y, x} endif) : p)) ; var r : double := ("1e9")->toReal() ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, i-1) do ( for k : Integer.subrange(0, j-1) do ( if (p)->includes(Sequence{j, i}) & (p)->includes(Sequence{k, i}) & (p)->includes(Sequence{k, j}) then ( r := Set{r, N[i+1] + N[j+1] + N[k+1]}->min() ) else skip))) ; execute (if r > ("1e8")->toReal() then -1 else r endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys import queue import itertools from heapq import heappop,heappush import random def solve(): n,m=map(int,input().split()) a=list(map(int,input().split())) f=[[0 for i in range(n)]for j in range(n)] for i in range(m): c,b=map(int,input().split()) f[c-1][b-1]=1 f[b-1][c-1]=1 min_cost=1<<60 for i in range(n): for j in range(n): for k in range(n): if len(set([i,j,k]))==3 : if f[i][j]==1 and f[i][k]==1 and f[j][k]==1 : cost=a[i]+a[j]+a[k] if costtoInteger() ; for _anon : Integer.subrange(0, t-1) do ( solve()) ) else ( solve() ) ) else skip; operation solve() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var f : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, m-1) do ( var c : OclAny := null; var b : OclAny := null; Sequence{c,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; f[c - 1+1][b - 1+1] := 1 ; f[b - 1+1][c - 1+1] := 1) ; var min_cost : int := 1 * (2->pow(60)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( for k : Integer.subrange(0, n-1) do ( if (Set{}->union((Sequence{i}->union(Sequence{j}->union(Sequence{ k })))))->size() = 3 then ( if f[i+1][j+1] = 1 & f[i+1][k+1] = 1 & f[j+1][k+1] = 1 then ( var cost : OclAny := a[i+1] + a[j+1] + a[k+1] ; if (cost->compareTo(min_cost)) < 0 then ( min_cost := cost ) else skip ) else skip ) else skip))) ; if min_cost /= 1 * (2->pow(60)) then ( execute (min_cost)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,m=map(int,input().split()) G=[[0]*(n+1)for _ in range(n+1)] a=[0]+list(map(int,input().split())) for _ in range(m): u,v=map(int,input().split()) G[u][v]=1 G[v][u]=1 inf=pow(10,9)+1 ans=inf for i in range(1,n+1): for j in range(i+1,n+1): if not G[i][j]: continue s=a[i]+a[j] if s>ans : continue for k in range(j+1,n+1): if G[i][k]and G[j][k]: ans=min(ans,s+a[k]) ans=(ans+1)%(inf+1)-1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var G : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)))) ; var a : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; for _anon : Integer.subrange(0, m-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; G[u+1][v+1] := 1 ; G[v+1][u+1] := 1) ; var Math_PINFINITY : double := (10)->pow(9) + 1 ; var ans : double := Math_PINFINITY ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(i + 1, n + 1-1) do ( if not(G[i+1][j+1]) then ( continue ) else skip ; var s : OclAny := a[i+1] + a[j+1] ; if (s->compareTo(ans)) > 0 then ( continue ) else skip ; for k : Integer.subrange(j + 1, n + 1-1) do ( if G[i+1][k+1] & G[j+1][k+1] then ( ans := Set{ans, s + a[k+1]}->min() ) else skip))) ; ans := (ans + 1) mod (Math_PINFINITY + 1) - 1 ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) arr=[] for i in range(a): b=[int(g)for g in str(input()).split()] c=[max(b[: 2]),max(b[2 :])] m1=max(b) b.remove(m1) m2=max(b) if m1 in c and m2 in c : arr.append("YES") else : arr.append("NO") for j in arr : print(j) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Sequence{} ; for i : Integer.subrange(0, a-1) do ( var b : Sequence := OclType["String"]((OclFile["System.in"]).readLine()).split()->select(g | true)->collect(g | (("" + ((g)))->toInteger())) ; var c : Sequence := Sequence{(b.subrange(1,2))->max()}->union(Sequence{ (b.subrange(2+1))->max() }) ; var m1 : OclAny := (b)->max() ; execute ((m1) /: b) ; var m2 : OclAny := (b)->max() ; if (c)->includes(m1) & (c)->includes(m2) then ( execute (("YES") : arr) ) else ( execute (("NO") : arr) )) ; for j : arr do ( execute (j)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) l=list(map(int,input().split())) b=[[0 for i in range(n)]for j in range(n)] for i in range(m): x,y=map(int,input().split()) b[x-1][y-1]=1 b[y-1][x-1]=1 l1=[] for i in range(n): for j in range(n): if(i!=j): for k in range(n): if((b[i][j]==1 or b[j][i]==1)and(b[j][k]==1 or b[k][j]==1)and(b[k][i]==1 or b[i][k]==1)): l1.append(l[i]+l[j]+l[k]) l1.sort() if(len(l1)==0): print(-1) else : print(min(l1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; b[x - 1+1][y - 1+1] := 1 ; b[y - 1+1][x - 1+1] := 1) ; var l1 : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if (i /= j) then ( for k : Integer.subrange(0, n-1) do ( if ((b[i+1][j+1] = 1 or b[j+1][i+1] = 1) & (b[j+1][k+1] = 1 or b[k+1][j+1] = 1) & (b[k+1][i+1] = 1 or b[i+1][k+1] = 1)) then ( execute ((l[i+1] + l[j+1] + l[k+1]) : l1) ) else skip) ) else skip)) ; l1 := l1->sort() ; if ((l1)->size() = 0) then ( execute (-1)->display() ) else ( execute ((l1)->min())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) a=list(map(int,input().split())) c1,c2=0,0 for i in a : c1+=i//2 c2+=(i+1)//2 c1,c2=c2,c1 ans=min(c1,c2) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c1 : OclAny := null; var c2 : OclAny := null; Sequence{c1,c2} := Sequence{0,0} ; for i : a do ( c1 := c1 + i div 2 ; c2 := c2 + (i + 1) div 2 ; var c1 : OclAny := null; var c2 : OclAny := null; Sequence{c1,c2} := Sequence{c2,c1}) ; var ans : OclAny := Set{c1, c2}->min() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=int(input()),0,0 lst=map(int,input().split()) for thing in lst : a,b=b+(thing>>1),a+((thing+1)>>1) print(min(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),0,0} ; var lst : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for thing : lst do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b + (thing /(2->pow(1))),a + ((thing + 1) /(2->pow(1)))}) ; execute (Set{a, b}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t,x,y=int(input()),0,0 l=list(map(int,input().split())) for a in l : x,y=y+(a//2),x+((a+1)//2); print(min(x,y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{t,x,y} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),0,0} ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for a : l do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{y + (a div 2),x + ((a + 1) div 2)};) ; execute (Set{x, y}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=input().split() x,y=[0,0] for i in range(n): if(i & 1): x+=int(a[i])>>1 y+=(int(a[i])+1)>>1 else : x+=(int(a[i])+1)>>1 y+=int(a[i])>>1 print(min(x,y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := input().split() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{0}->union(Sequence{ 0 }) ; for i : Integer.subrange(0, n-1) do ( if (MathLib.bitwiseAnd(i, 1)) then ( x := x + ("" + ((a[i+1])))->toInteger() /(2->pow(1)) ; y := y + (("" + ((a[i+1])))->toInteger() + 1) /(2->pow(1)) ) else ( x := x + (("" + ((a[i+1])))->toInteger() + 1) /(2->pow(1)) ; y := y + ("" + ((a[i+1])))->toInteger() /(2->pow(1)) )) ; execute (Set{x, y}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=input().split() x,y=[0,0] for i in range(n): if(i & 1): x+=int(a[i])>>1 y+=(int(a[i])+1)>>1 else : x+=(int(a[i])+1)>>1 y+=int(a[i])>>1 print(min(x,y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := input().split() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{0}->union(Sequence{ 0 }) ; for i : Integer.subrange(0, n-1) do ( if (MathLib.bitwiseAnd(i, 1)) then ( x := x + ("" + ((a[i+1])))->toInteger() /(2->pow(1)) ; y := y + (("" + ((a[i+1])))->toInteger() + 1) /(2->pow(1)) ) else ( x := x + (("" + ((a[i+1])))->toInteger() + 1) /(2->pow(1)) ; y := y + ("" + ((a[i+1])))->toInteger() /(2->pow(1)) )) ; execute (Set{x, y}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B=map(int,input().split()) ans=A-2*B if ans<0 : ans=0 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : double := A - 2 * B ; if ans < 0 then ( ans := 0 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- u=input n,k=map(int,u().split()) M=[int(i)for i in u().split()] m=0 for j in range(n): for p in range(n): if(0==M[p]): print(p+1,end=' ') break for l in range(p+1-k): M[l]-=1 M[p]-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var u : OclAny := input ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (u().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var M : Sequence := u().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var m : int := 0 ; for j : Integer.subrange(0, n-1) do ( for p : Integer.subrange(0, n-1) do ( if (0 = M[p+1]) then ( execute (p + 1)->display() ; break ) else skip) ; for l : Integer.subrange(0, p + 1 - k-1) do ( M[l+1] := M[l+1] - 1) ; M[p+1] := M[p+1] - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,k=map(int,input().split()) a=list(map(int,input().split())) b=[0]*n for i in range(n): l=-1 for j in range(n): if a[j]==0 : l=j b[i]=j+1 a[j]-=1 break for j in range(n): if l>=j+k : a[j]-=1 print(*b) return if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( var l : int := -1 ; for j : Integer.subrange(0, n-1) do ( if a[j+1] = 0 then ( l := j ; b[i+1] := j + 1 ; a[j+1] := a[j+1] - 1 ; break ) else skip) ; for j : Integer.subrange(0, n-1) do ( if (l->compareTo(j + k)) >= 0 then ( a[j+1] := a[j+1] - 1 ) else skip)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name b))))))))->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() l=s.split() n=int(l[0]) k=int(l[1]) s=input() l=s.split() b=[-1] for i in range(1,n+1): b.append(int(l[i-1])) for i in range(1,n+1): j=1 while b[j]!=0 : j+=1 b[j]-=1 print(j,end=' ') for t in range(1,n+1): if j-k>=t : b[t]-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var l : OclAny := s.split() ; var n : int := ("" + ((l->first())))->toInteger() ; var k : int := ("" + ((l[1+1])))->toInteger() ; s := (OclFile["System.in"]).readLine() ; l := s.split() ; var b : Sequence := Sequence{ -1 } ; for i : Integer.subrange(1, n + 1-1) do ( execute ((("" + ((l[i - 1+1])))->toInteger()) : b)) ; for i : Integer.subrange(1, n + 1-1) do ( var j : int := 1 ; while b[j+1] /= 0 do ( j := j + 1) ; b[j+1] := b[j+1] - 1 ; execute (j)->display() ; for t : Integer.subrange(1, n + 1-1) do ( if (j - k->compareTo(t)) >= 0 then ( b[t+1] := b[t+1] - 1 ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,radians from itertools import accumulate,permutations,combinations,combinations_with_replacement,product,groupby from operator import itemgetter,mul from copy import deepcopy,copy from string import ascii_lowercase,ascii_uppercase,digits from bisect import bisect,bisect_left,insort,insort_left from fractions import gcd from heapq import heappush,heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) def ZIP(n): return zip(*(MAP()for _ in range(n))) sys.setrecursionlimit(10**9) INF=float('inf') mod=10**9+7 import numpy as np N=INT() S=[input()for _ in range(N)] march=["M","A","R","C","H"] march_lis=[0]*5 for s in S : if s[0].upper()in march : march_lis[march.index(s[0].upper())]+=1 ans=0 for x,y,z in combinations(march_lis,3): ans+=x*y*z print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; skip ; var N : OclAny := INT() ; var S : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var march : Sequence := Sequence{"M"}->union(Sequence{"A"}->union(Sequence{"R"}->union(Sequence{"C"}->union(Sequence{ "H" })))) ; var march_lis : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 5) ; for s : S do ( if (march)->includes(s->first()->toUpperCase()) then ( march_lis[march->indexOf(s->first()->toUpperCase()) - 1+1] := march_lis[march->indexOf(s->first()->toUpperCase()) - 1+1] + 1 ) else skip) ; var ans : int := 0 ; for _tuple : combinations(march_lis, 3) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); _indx := _indx + 1; var z : OclAny := _tuple->at(_indx); ans := ans + x * y * z) ; execute (ans)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ZIP(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))`third->at(_indx)} ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) b=list(map(int,input().split())) taken=[False for i in range(n+2)] a=[] for i in range(n): has=-1 for j in range(1,n+1): if not taken[j]and b[j-1]==0 : has=j break a.append(has) taken[has]=True for j in range(1,has-k+1): b[j-1]-=1 print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var taken : Sequence := Integer.subrange(0, n + 2-1)->select(i | true)->collect(i | (false)) ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var has : int := -1 ; for j : Integer.subrange(1, n + 1-1) do ( if not(taken[j+1]) & b[j - 1+1] = 0 then ( has := j ; break ) else skip) ; execute ((has) : a) ; taken[has+1] := true ; for j : Integer.subrange(1, has - k + 1-1) do ( b[j - 1+1] := b[j - 1+1] - 1)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def process(B,k): n=len(B) A=[] for i in range(n-k+1,n+1): A.append(i) for i in range(n-k,0,-1): c=B[i-1] if c==0 : A=[i]+A else : index=None my_count=0 for j in range(len(A)): if A[j]>=(i+k): my_count+=1 if my_count==c : index=j+1 break A=A[: index]+[i]+A[index :] return A n,k=[int(x)for x in input().split()] B=[int(x)for x in input().split()] answer=process(B,k) print(' '.join(map(str,answer))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{n,k} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; B := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var answer : OclAny := process(B, k) ; execute (StringLib.sumStringsWithSeparator(((answer)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); operation process(B : OclAny, k : OclAny) : OclAny pre: true post: true activity: var n : int := (B)->size() ; var A : Sequence := Sequence{} ; for i : Integer.subrange(n - k + 1, n + 1-1) do ( execute ((i) : A)) ; for i : Integer.subrange(0 + 1, n - k)->reverse() do ( var c : OclAny := B[i - 1+1] ; if c = 0 then ( A := Sequence{ i }->union(A) ) else ( var index : OclAny := null ; var my_count : int := 0 ; for j : Integer.subrange(0, (A)->size()-1) do ( if (A[j+1]->compareTo((i + k))) >= 0 then ( my_count := my_count + 1 ; if my_count = c then ( index := j + 1 ; break ) else skip ) else skip) ; A := A.subrange(1,index)->union(Sequence{ i }) + A.subrange(index+1) )) ; return A; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys def solve(): n=int(input()) rows=list(map(int,input().split())) r=[] cords={} for i in range(n): r.append(list(map(int,input().split()))) for j in range(rows[i]): cords[r[i][j]]=[i,j] it=1 ans=[] for i in range(n): for j in range(rows[i]): if r[i][j]!=it : tmp=[cords[it][0],cords[it][1]] r[i][j],r[cords[it][0]][cords[it][1]]=r[cords[it][0]][cords[it][1]],r[i][j] cords[r[cords[it][0]][cords[it][1]]]=tmp*1 ans.append([i,j,cords[it][0],cords[it][1]]) it+=1 print(len(ans)) for i in ans : for j in i : print(j+1,end=" ") print() if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var rows : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var r : Sequence := Sequence{} ; var cords : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : r) ; for j : Integer.subrange(0, rows[i+1]-1) do ( cords[r[i+1][j+1]+1] := Sequence{i}->union(Sequence{ j }))) ; var it : int := 1 ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, rows[i+1]-1) do ( if r[i+1][j+1] /= it then ( var tmp : Sequence := Sequence{cords[it+1]->first()}->union(Sequence{ cords[it+1][1+1] }) ; var r[i+1][j+1] : OclAny := null; var r[cords[it+1]->first()+1][cords[it+1][1+1]+1] : OclAny := null; Sequence{r[i+1][j+1],r[cords[it+1]->first()+1][cords[it+1][1+1]+1]} := Sequence{r[cords[it+1]->first()+1][cords[it+1][1+1]+1],r[i+1][j+1]} ; cords[r[cords[it+1]->first()+1][cords[it+1][1+1]+1]+1] := MatrixLib.elementwiseMult(tmp, 1) ; execute ((Sequence{i}->union(Sequence{j}->union(Sequence{cords[it+1]->first()}->union(Sequence{ cords[it+1][1+1] })))) : ans) ) else skip ; it := it + 1)) ; execute ((ans)->size())->display() ; for i : ans do ( for j : i do ( execute (j + 1)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=[[0,0]] l=[0] v=[] for i,c in enumerate(map(int,input().split())): p.extend([[i+1,j+1]for j in range(c)]) l.extend(list(map(int,input().split()))) for i in range(1,len(l)): if l[i]!=i : j=l.index(i) v.append(p[i]+p[j]) l[i],l[j]=l[j],l[i] print(len(v)) for x in v : print(' '.join(map(str,x))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := Sequence{ Sequence{0}->union(Sequence{ 0 }) } ; var l : Sequence := Sequence{ 0 } ; var v : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->size())->collect( _indx | Sequence{_indx-1, ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); p := p->union(Integer.subrange(0, c-1)->select(j | true)->collect(j | (Sequence{i + 1}->union(Sequence{ j + 1 })))) ; l := l->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for i : Integer.subrange(1, (l)->size()-1) do ( if l[i+1] /= i then ( var j : int := l->indexOf(i) - 1 ; execute ((p[i+1] + p[j+1]) : v) ; var l[i+1] : OclAny := null; var l[j+1] : OclAny := null; Sequence{l[i+1],l[j+1]} := Sequence{l[j+1],l[i+1]} ) else skip) ; execute ((v)->size())->display() ; for x : v do ( execute (StringLib.sumStringsWithSeparator(((x)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def prog(): n=int(input()) cs=list(map(int,input().split())) nums=[] locations={} locations2={} i=1 for c in cs : curr_nums=list(map(int,input().split())) for j in range(c): num=curr_nums[j] nums.append(num) if num in locations : locations[num].append([i,j+1]) else : locations[num]=[[i,j+1]] locations2[(i,j+1)]=num i+=1 nums.sort() swaps=[] i=1 idx=0 for c in cs : for j in range(c): if locations2[(i,j+1)]!=nums[idx]: other=locations[nums[idx]][-1] swaps.append([i,j+1,other[0],other[1]]) locations[nums[idx]].pop() del locations[locations2[(i,j+1)]][locations[locations2[(i,j+1)]].index([i,j+1])] locations[locations2[(i,j+1)]].append(other) locations2[tuple(other)]=locations2[(i,j+1)] locations2[(i,j+1)]=nums[idx] idx+=1 i+=1 print(len(swaps)) for swap in swaps : print(*swap) prog() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; prog(); operation prog() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cs : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var nums : Sequence := Sequence{} ; var locations : OclAny := Set{} ; var locations2 : OclAny := Set{} ; var i : int := 1 ; for c : cs do ( var curr_nums : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, c-1) do ( var num : OclAny := curr_nums[j+1] ; execute ((num) : nums) ; if (locations)->includes(num) then ( (expr (atom (name locations)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name num)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) , (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 1))))))))) ]))))))) )))) ) else ( locations[num+1] := Sequence{ Sequence{i}->union(Sequence{ j + 1 }) } ) ; locations2[Sequence{i, j + 1}+1] := num) ; i := i + 1) ; nums := nums->sort() ; var swaps : Sequence := Sequence{} ; i := 1 ; var idx : int := 0 ; for c : cs do ( for j : Integer.subrange(0, c-1) do ( if locations2[Sequence{i, j + 1}+1] /= nums[idx+1] then ( var other : OclAny := locations[nums[idx+1]+1]->last() ; execute ((Sequence{i}->union(Sequence{j + 1}->union(Sequence{other->first()}->union(Sequence{ other[1+1] })))) : swaps) ; (expr (atom (name locations)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name nums)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name idx)))))))) ])))))))) ])) (trailer . (name pop) (arguments ( )))) ; execute (locations[locations2[Sequence{i, j + 1}+1]+1][locations[locations2[Sequence{i, j + 1}+1]+1]->indexOf(Sequence{i}->union(Sequence{ j + 1 })) - 1+1])->isDeleted() ; (expr (atom (name locations)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name locations2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) , (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 1))))))))) )))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name other)))))))) )))) ; locations2->restrict((other)) := locations2[Sequence{i, j + 1}+1] ; locations2[Sequence{i, j + 1}+1] := nums[idx+1] ) else skip ; idx := idx + 1) ; i := i + 1) ; execute ((swaps)->size())->display() ; for swap : swaps do ( execute ((argument * (test (logical_test (comparison (expr (atom (name swap))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find(A,target): for i in range(len(A)): for j in range(len(A[i])): if A[i][j]==target : return[i+1,j+1] n=int(input()) C=list(map(int,input().split())) X=[] for i in range(n): Y=list(map(int,input().split())) X.append(Y) cnt=1 tot=0 ans=[] for i in range(len(X)): for j in range(len(X[i])): t=find(X,cnt) X[t[0]-1][t[1]-1],X[i][j]=X[i][j],X[t[0]-1][t[1]-1] if t[0]!=i+1 or t[1]!=j+1 : ans.append(str(i+1)+" "+str(j+1)+" "+str(t[0])+" "+str(t[1])) tot+=1 cnt+=1 print(tot) for i in ans : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var C : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var X : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var Y : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((Y) : X)) ; var cnt : int := 1 ; var tot : int := 0 ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, (X)->size()-1) do ( for j : Integer.subrange(0, (X[i+1])->size()-1) do ( var t : OclAny := find(X, cnt) ; var X[t->first() - 1+1][t[1+1] - 1+1] : OclAny := null; var X[i+1][j+1] : OclAny := null; Sequence{X[t->first() - 1+1][t[1+1] - 1+1],X[i+1][j+1]} := Sequence{X[i+1][j+1],X[t->first() - 1+1][t[1+1] - 1+1]} ; if t->first() /= i + 1 or t[1+1] /= j + 1 then ( execute ((("" + ((i + 1))) + " " + ("" + ((j + 1))) + " " + ("" + ((t->first()))) + " " + ("" + ((t[1+1])))) : ans) ; tot := tot + 1 ) else skip ; cnt := cnt + 1)) ; execute (tot)->display() ; for i : ans do ( execute (i)->display()); operation find(A : OclAny, target : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, (A)->size()-1) do ( for j : Integer.subrange(0, (A[i+1])->size()-1) do ( if A[i+1][j+1] = target then ( return Sequence{i + 1}->union(Sequence{ j + 1 }) ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=map(int,input().split()) result=[] for i,a in enumerate(A): result.append({'i' : i,'a' : a}) result.sort(key=lambda x : x['a']) print(' '.join([str(x['i']+1)for x in result])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var result : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); execute ((Map{ 'i' |-> i }->union(Map{ 'a' |-> a })) : result)) ; result := result->sort() ; execute (StringLib.sumStringsWithSeparator((result->select(x | true)->collect(x | (("" + ((x->at('i') + 1)))))), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=[int(x)for x in input().split()] print(max(a-2*b,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (Set{a - 2 * b, 0}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np n=int(input()) a=list(map(int,input().split())) print(*(np.argsort(a)+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name np)) (trailer . (name argsort) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))) + (expr (atom (number (integer 1))))))))) ))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from fractions import gcd from collections import deque import bisect sys.setrecursionlimit(1000000) def main(): N=int(input()) A=list(map(int,input().split())) combi=list(zip(range(1,N+1),A)) combi.sort(key=lambda x : x[1]) for key in combi : print(key[0],end='') print('') if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1000000) ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var combi : Sequence := (Integer.subrange(1, Integer.subrange(1, N + 1-1)->size())->collect( _indx | Sequence{Integer.subrange(1, N + 1-1)->at(_indx), A->at(_indx)} )) ; combi := combi->sort() ; for key : combi do ( execute (key->first())->display()) ; execute ('')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) march=['M','A','R','C','H'] s=[input()for _ in range(n)] m=[] a=[] r=[] c=[] h=[] for i in s : if i[0]=='M' : m.append(i) elif i[0]=='A' : a.append(i) elif i[0]=='R' : r.append(i) elif i[0]=='C' : c.append(i) elif i[0]=='H' : h.append(i) m=list(set(m)) a=list(set(a)) r=list(set(r)) c=list(set(c)) h=list(set(h)) l=[len(m),len(a),len(r),len(c),len(h)] ans=0 rr=[] if l.count(0)<=2 : ll=[i for i in l if i>=1] ans=1 if len(ll)==3 : for i in ll : ans*=i elif len(ll)==4 : for i in range(2): for j in range(i+1,3): for k in range(j+1,4): rr.append(ll[i]*ll[j]*ll[k]) ans=sum(rr) else : for i in range(3): for j in range(i+1,4): for k in range(j+1,5): rr.append(ll[i]*ll[j]*ll[k]) ans=sum(rr) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var march : Sequence := Sequence{'M'}->union(Sequence{'A'}->union(Sequence{'R'}->union(Sequence{'C'}->union(Sequence{ 'H' })))) ; var s : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var m : Sequence := Sequence{} ; var a : Sequence := Sequence{} ; var r : Sequence := Sequence{} ; var c : Sequence := Sequence{} ; var h : Sequence := Sequence{} ; for i : s do ( if i->first() = 'M' then ( execute ((i) : m) ) else (if i->first() = 'A' then ( execute ((i) : a) ) else (if i->first() = 'R' then ( execute ((i) : r) ) else (if i->first() = 'C' then ( execute ((i) : c) ) else (if i->first() = 'H' then ( execute ((i) : h) ) else skip ) ) ) ) ) ; m := (Set{}->union((m))) ; a := (Set{}->union((a))) ; r := (Set{}->union((r))) ; c := (Set{}->union((c))) ; h := (Set{}->union((h))) ; var l : Sequence := Sequence{(m)->size()}->union(Sequence{(a)->size()}->union(Sequence{(r)->size()}->union(Sequence{(c)->size()}->union(Sequence{ (h)->size() })))) ; var ans : int := 0 ; var rr : Sequence := Sequence{} ; if l->count(0) <= 2 then ( var ll : Sequence := l->select(i | i >= 1)->collect(i | (i)) ; ans := 1 ; if (ll)->size() = 3 then ( for i : ll do ( ans := ans * i) ) else (if (ll)->size() = 4 then ( for i : Integer.subrange(0, 2-1) do ( for j : Integer.subrange(i + 1, 3-1) do ( for k : Integer.subrange(j + 1, 4-1) do ( execute ((ll[i+1] * ll[j+1] * ll[k+1]) : rr)))) ; ans := (rr)->sum() ) else ( for i : Integer.subrange(0, 3-1) do ( for j : Integer.subrange(i + 1, 4-1) do ( for k : Integer.subrange(j + 1, 5-1) do ( execute ((ll[i+1] * ll[j+1] * ll[k+1]) : rr)))) ; ans := (rr)->sum() ) ) ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) N=I() A=LI() for i in range(N): A[i]=(A[i],i) A.sort() print(*[A[i][1]+1 for i in range(N)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var N : OclAny := I() ; var A : OclAny := LI() ; for i : Integer.subrange(0, N-1) do ( A[i+1] := Sequence{A[i+1], i}) ; A := A->sort() ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) + (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))) ])))))))->display(); operation I() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.readLine().rstrip())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from operator import itemgetter N=int(input()) A=[(i+1,int(x))for i,x in enumerate(input().split())] A_=sorted(A,key=itemgetter(1)) A__=[a[0]for a in A_] for i in A__[:-1]: print(i,end=' ') print(A__[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := Integer.subrange(1, (input().split())->size())->collect( _indx | Sequence{_indx-1, (input().split())->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in (Sequence{i + 1, ("" + ((x)))->toInteger()})) ; var A_ : Sequence := A->sortedBy($x | (itemgetter(1))->apply($x)) ; var A__ : Sequence := A_->select(a | true)->collect(a | (a->first())) ; for i : A__->front() do ( execute (i)->display()) ; execute (A__->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sameOccurrence(arr,n,x,y): result=0 for i in range(n): ctX=0 ctY=0 for j in range(i,n,1): if(arr[j]==x): ctX+=1 ; elif(arr[j]==y): ctY+=1 if(ctX==ctY): result+=1 return(result) if __name__=='__main__' : arr=[1,2,2,3,4,1] n=len(arr) x=2 y=3 print(sameOccurrence(arr,n,x,y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 1 }))))) ; n := (arr)->size() ; x := 2 ; y := 3 ; execute (sameOccurrence(arr, n, x, y))->display() ) else skip; operation sameOccurrence(arr : OclAny, n : OclAny, x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; for i : Integer.subrange(0, n-1) do ( var ctX : int := 0 ; var ctY : int := 0 ; for j : Integer.subrange(i, n-1)->select( $x | ($x - i) mod 1 = 0 ) do ( if (arr[j+1] = x) then ( ctX := ctX + 1; ) else (if (arr[j+1] = y) then ( ctY := ctY + 1 ) else skip) ; if (ctX = ctY) then ( result := result + 1 ) else skip)) ; return (result); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while(t): t-=1 s=input() n=len(s) ct=0 for i in s : if(i=="0"): ct+=1 if(ctn-ct): print(n-ct) else : if(n!=2): print(ct-1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (t) do ( t := t - 1 ; var s : String := (OclFile["System.in"]).readLine() ; var n : int := (s)->size() ; var ct : int := 0 ; for i : s->characters() do ( if (i = "0") then ( ct := ct + 1 ) else skip) ; if ((ct->compareTo(n - ct)) < 0) then ( execute (ct)->display() ) else (if ((ct->compareTo(n - ct)) > 0) then ( execute (n - ct)->display() ) else ( if (n /= 2) then ( execute (ct - 1)->display() ) else ( execute (0)->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- testCases=int(input()) for i in range(testCases): string=input() counter1=0 counter2=0 for i in range(len(string)): if(string[i]=='0'): counter1+=1 else : counter2+=1 if(counter1==counter2): print(counter1-1) else : print(min(counter1,counter2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var testCases : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, testCases-1) do ( var string : String := (OclFile["System.in"]).readLine() ; var counter1 : int := 0 ; var counter2 : int := 0 ; for i : Integer.subrange(0, (string)->size()-1) do ( if (string[i+1] = '0') then ( counter1 := counter1 + 1 ) else ( counter2 := counter2 + 1 )) ; if (counter1 = counter2) then ( execute (counter1 - 1)->display() ) else ( execute (Set{counter1, counter2}->min())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): s=input() n1=0 n0=0 for i in s : if i=="0" : n0+=1 else : n1+=1 if n1==n0 : print(n1-1) else : print(min(n1,n0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var n1 : int := 0 ; var n0 : int := 0 ; for i : s->characters() do ( if i = "0" then ( n0 := n0 + 1 ) else ( n1 := n1 + 1 )) ; if n1 = n0 then ( execute (n1 - 1)->display() ) else ( execute (Set{n1, n0}->min())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): s=input() print(min((len(s)-1)//2,s.count('0'),s.count('1'))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; execute (Set{((s)->size() - 1) div 2, s->count('0'), s->count('1')}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): s=input() print(min((len(s)-1)//2,s.count('0'),s.count('1'))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; execute (Set{((s)->size() - 1) div 2, s->count('0'), s->count('1')}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): A,B=map(int,input().split()) if B*2>=A : return 0 else : return A-2*B if __name__=='__main__' : print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( execute (main())->display() ) else skip; operation main() : OclAny pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (B * 2->compareTo(A)) >= 0 then ( return 0 ) else ( return A - 2 * B ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() c=0 f={} for x in input().split(): f[x]=d=f.get(x,0)+1 ; c+=d % 2*2-1 print(['Agasa','Conan'][c>0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var c : int := 0 ; var f : OclAny := Set{} ; for x : input().split() do ( f[x+1] := f.get(x, 0) + 1; var d : String := f.get(x, 0) + 1; c := c + d mod 2 * 2 - 1) ; execute (Sequence{'Agasa'}->union(Sequence{ 'Conan' })->select(c > 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) S=[0,0,0,0,0] for i in range(N): st=input() if st[0]=="M" : S[0]+=1 continue elif st[0]=="A" : S[1]+=1 continue elif st[0]=="R" : S[2]+=1 continue elif st[0]=="C" : S[3]+=1 continue elif st[0]=="H" : S[4]+=1 continue L=[(0,1,2),(0,1,3),(0,1,4),(0,2,3),(0,2,4),(0,3,4),(1,2,3),(1,2,4),(1,3,4),(2,3,4)] res=0 for i,j,k in L : res+=S[i]*S[j]*S[k] print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))) ; for i : Integer.subrange(0, N-1) do ( var st : String := (OclFile["System.in"]).readLine() ; if st->first() = "M" then ( S->first() := S->first() + 1 ; continue ) else (if st->first() = "A" then ( S[1+1] := S[1+1] + 1 ; continue ) else (if st->first() = "R" then ( S[2+1] := S[2+1] + 1 ; continue ) else (if st->first() = "C" then ( S[3+1] := S[3+1] + 1 ; continue ) else (if st->first() = "H" then ( S[4+1] := S[4+1] + 1 ; continue ) else skip ) ) ) ) ) ; var L : Sequence := Sequence{Sequence{0, 1, 2}}->union(Sequence{Sequence{0, 1, 3}}->union(Sequence{Sequence{0, 1, 4}}->union(Sequence{Sequence{0, 2, 3}}->union(Sequence{Sequence{0, 2, 4}}->union(Sequence{Sequence{0, 3, 4}}->union(Sequence{Sequence{1, 2, 3}}->union(Sequence{Sequence{1, 2, 4}}->union(Sequence{Sequence{1, 3, 4}}->union(Sequence{ Sequence{2, 3, 4} }))))))))) ; var res : int := 0 ; for _tuple : L do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var k : OclAny := _tuple->at(_indx); res := res + S[i+1] * S[j+1] * S[k+1]) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solution(): if len(p)>1 and p[-1]!=p[-2]: return 'Conan' elif len(p)==1 : return 'Conan' else : key={} for i in p : if i not in key : key[i]=1 else : key[i]+=1 for i in sorted(key)[: :-1]: if key[i]% 2==1 : return 'Conan' return 'Agasa' if __name__=='__main__' : _n=int(input()) p=[int(x)for x in input().rstrip().split()] p.sort() print(solution()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var _n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := input().rstrip().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; p := p->sort() ; execute (solution())->display() ) else skip; operation solution() : OclAny pre: true post: true activity: if (p)->size() > 1 & p->last() /= p->front()->last() then ( return 'Conan' ) else (if (p)->size() = 1 then ( return 'Conan' ) else ( var key : OclAny := Set{} ; for i : p do ( if (key)->excludes(i) then ( key[i+1] := 1 ) else ( key[i+1] := key[i+1] + 1 )) ; for i : sorted(key)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if key[i+1] mod 2 = 1 then ( return 'Conan' ) else skip) ; return 'Agasa' ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) list1=[int(num)for num in input().split()] list1.sort() c1=0 c2=0 i=len(list1)-1 flag=0 while(i>=0): c1=1 while(i-1>=0 and list1[i]==list1[i-1]): c1+=1 i-=1 i-=1 if(c1 % 2==1): flag=1 break if(flag==1): print("Conan") else : print("Agasa") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var list1 : Sequence := input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; list1 := list1->sort() ; var c1 : int := 0 ; var c2 : int := 0 ; var i : double := (list1)->size() - 1 ; var flag : int := 0 ; while (i >= 0) do ( c1 := 1 ; while (i - 1 >= 0 & list1[i+1] = list1[i - 1+1]) do ( c1 := c1 + 1 ; i := i - 1) ; i := i - 1 ; if (c1 mod 2 = 1) then ( flag := 1 ; break ) else skip) ; if (flag = 1) then ( execute ("Conan")->display() ) else ( execute ("Agasa")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) c=[0]*100001 q=0 a=list(map(int,input().split())) if n % 2==1 : print("Conan") else : for i in range(n): c[a[i]]+=1 for j in c : if j % 2==1 : q=1 break if q==1 : print("Conan") else : print("Agasa") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100001) ; var q : int := 0 ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n mod 2 = 1 then ( execute ("Conan")->display() ) else ( for i : Integer.subrange(0, n-1) do ( c[a[i+1]+1] := c[a[i+1]+1] + 1) ; for j : c do ( if j mod 2 = 1 then ( q := 1 ; break ) else skip) ; if q = 1 then ( execute ("Conan")->display() ) else ( execute ("Agasa")->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from collections import Counter n=int(input()) w=list(map(int,input().split())) c=Counter(w) for i in c : if c[i]% 2 : print('Conan') break else : print('Agasa') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : OclAny := Counter(w) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name c))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) % (expr (atom (number (integer 2)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'Conan'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'Agasa'))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[1,2,3,4,5]; for i in range(5): print(a[i],end=" "); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))); ; for i : Integer.subrange(0, 5-1) do ( execute (a[i+1])->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- target=93 arr=[1,31,3,1,93,3,31,1,93] length=len(arr) totalCount=0 for i in range(length-2): if target % arr[i]==0 : for j in range(i+1,length-1): if target %(arr[i]*arr[j])==0 : toFind=target//(arr[i]*arr[j]) for k in range(j+1,length): if arr[k]==toFind : totalCount+=1 print('Total number of triplets found: ',totalCount) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var target : int := 93 ; var arr : Sequence := Sequence{1}->union(Sequence{31}->union(Sequence{3}->union(Sequence{1}->union(Sequence{93}->union(Sequence{3}->union(Sequence{31}->union(Sequence{1}->union(Sequence{ 93 })))))))) ; var length : int := (arr)->size() ; var totalCount : int := 0 ; for i : Integer.subrange(0, length - 2-1) do ( if target mod arr[i+1] = 0 then ( for j : Integer.subrange(i + 1, length - 1-1) do ( if target mod (arr[i+1] * arr[j+1]) = 0 then ( var toFind : int := target div (arr[i+1] * arr[j+1]) ; for k : Integer.subrange(j + 1, length-1) do ( if arr[k+1] = toFind then ( totalCount := totalCount + 1 ) else skip) ) else skip) ) else skip) ; execute ('Total number of triplets found: ')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) if n==1 : print(*[1,1]) print(-l[0]) print(*[1,1]) print(0) print(*[1,1]) print(0) else : print(*[1,1]) print(-l[0]) print(*[1,n]) x=[0 for _ in range(n)] for i in range(1,n): x[i]=-l[i]*n print(*x) print(*[2,n]) for i in range(n): x[i]=(n-1)*l[i] print(*x[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = 1 then ( execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1))))))) , (test (logical_test (comparison (expr (atom (number (integer 1)))))))) ])))))))->display() ; execute (-l->first())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1))))))) , (test (logical_test (comparison (expr (atom (number (integer 1)))))))) ])))))))->display() ; execute (0)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1))))))) , (test (logical_test (comparison (expr (atom (number (integer 1)))))))) ])))))))->display() ; execute (0)->display() ) else ( execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1))))))) , (test (logical_test (comparison (expr (atom (number (integer 1)))))))) ])))))))->display() ; execute (-l->first())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1))))))) , (test (logical_test (comparison (expr (atom (name n))))))) ])))))))->display() ; var x : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)) ; for i : Integer.subrange(1, n-1) do ( x[i+1] := -l[i+1] * n) ; execute ((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display() ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 2))))))) , (test (logical_test (comparison (expr (atom (name n))))))) ])))))))->display() ; for i : Integer.subrange(0, n-1) do ( x[i+1] := (n - 1) * l[i+1]) ; execute ((argument * (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def inp(): return(int(input())) def inlst(): return(list(map(int,input().split()))) def insr(): s=input() return(list(s[: len(s)-1])) def invr(): return(map(int,input().split())) if __name__=="__main__" : _=inp() lst=inlst() n=len(lst) print('{}{}'.format(1,1)) print('{}'.format(-lst[0])) if n>1 : lst[0]=0 print('{}{}'.format(2,n)) for e in lst[1 : n]: print((n-1)*e,end='') print('') print('{}{}'.format(1,n)) for e in lst[0 : n]: print(-e*n,end='') print('') else : print('{}{}'.format(1,1)) print(0) print('{}{}'.format(1,1)) print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( var _anon : OclAny := inp() ; var lst : OclAny := inlst() ; var n : int := (lst)->size() ; execute (StringLib.interpolateStrings('{}{}', Sequence{1, 1}))->display() ; execute (StringLib.interpolateStrings('{}', Sequence{-lst->first()}))->display() ; if n > 1 then ( lst->first() := 0 ; execute (StringLib.interpolateStrings('{}{}', Sequence{2, n}))->display() ; for e : lst.subrange(1+1, n) do ( execute ((n - 1) * e)->display()) ; execute ('')->display() ; execute (StringLib.interpolateStrings('{}{}', Sequence{1, n}))->display() ; for e : lst.subrange(0+1, n) do ( execute (-e * n)->display()) ; execute ('')->display() ) else ( execute (StringLib.interpolateStrings('{}{}', Sequence{1, 1}))->display() ; execute (0)->display() ; execute (StringLib.interpolateStrings('{}{}', Sequence{1, 1}))->display() ; execute (0)->display() ) ) else skip; operation inp() : OclAny pre: true post: true activity: return (("" + (((OclFile["System.in"]).readLine())))->toInteger()); operation inlst() : OclAny pre: true post: true activity: return (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))); operation insr() : OclAny pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; return ((s.subrange(1,(s)->size() - 1))); operation invr() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) if n==1 : print('1 1',-a[0],'1 1','0','1 1','0',sep='\n') exit(0) print(1,n) for i in range(n): print(-a[i]*n,end=' ') a[i]-=a[i]*n print() print(1,n-1) for i in range(n-1): print(-a[i],end=' ') a[i]=0 print() print(n,n) print(-a[n-1]) a[n-1]=0 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = 1 then ( execute ('1 1')->display() ; exit(0) ) else skip ; execute (1)->display() ; for i : Integer.subrange(0, n-1) do ( execute (-a[i+1] * n)->display() ; a[i+1] := a[i+1] - a[i+1] * n) ; execute (->display() ; execute (1)->display() ; for i : Integer.subrange(0, n - 1-1) do ( execute (-a[i+1])->display() ; a[i+1] := 0) ; execute (->display() ; execute (n)->display() ; execute (-a[n - 1+1])->display() ; a[n - 1+1] := 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def dot(ux,uy,vx,vy): return ux*vx+uy*vy def cross(ux,uy,vx,vy): return ux*vy-uy*vx def dist_to_segment(x,y,ax,ay,bx,by): if dot(x-ax,y-ay,bx-ax,by-ay)<0 : return math.hypot(x-ax,y-ay) if dot(x-bx,y-by,ax-bx,ay-by)<0 : return math.hypot(x-bx,y-by) c=abs(cross(bx-ax,by-ay,x-ax,y-ay)) return c/math.hypot(bx-ax,by-ay) q=int(input()) for _ in range(q): x0,y0,x1,y1,x2,y2,x3,y3=map(int,input().split()) c1=cross(x1-x0,y1-y0,x2-x0,y2-y0) c2=cross(x1-x0,y1-y0,x3-x0,y3-y0) c3=cross(x3-x2,y3-y2,x0-x2,y0-y2) c4=cross(x3-x2,y3-y2,x1-x2,y1-y2) if c1*c2<0 and c3*c4<0 : d=0.0 else : d=dist_to_segment(x2,y2,x0,y0,x1,y1) d=min(d,dist_to_segment(x3,y3,x0,y0,x1,y1)) d=min(d,dist_to_segment(x0,y0,x2,y2,x3,y3)) d=min(d,dist_to_segment(x1,y1,x2,y2,x3,y3)) print('{:.10f}'.format(d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( var x0 : OclAny := null; var y0 : OclAny := null; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; var x3 : OclAny := null; var y3 : OclAny := null; Sequence{x0,y0,x1,y1,x2,y2,x3,y3} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c1 : OclAny := cross(x1 - x0, y1 - y0, x2 - x0, y2 - y0) ; var c2 : OclAny := cross(x1 - x0, y1 - y0, x3 - x0, y3 - y0) ; var c3 : OclAny := cross(x3 - x2, y3 - y2, x0 - x2, y0 - y2) ; var c4 : OclAny := cross(x3 - x2, y3 - y2, x1 - x2, y1 - y2) ; if c1 * c2 < 0 & c3 * c4 < 0 then ( var d : double := 0.0 ) else ( d := dist_to_segment(x2, y2, x0, y0, x1, y1) ; d := Set{d, dist_to_segment(x3, y3, x0, y0, x1, y1)}->min() ; d := Set{d, dist_to_segment(x0, y0, x2, y2, x3, y3)}->min() ; d := Set{d, dist_to_segment(x1, y1, x2, y2, x3, y3)}->min() ) ; execute (StringLib.interpolateStrings('{:.10f}', Sequence{d}))->display()); operation dot(ux : OclAny, uy : OclAny, vx : OclAny, vy : OclAny) : OclAny pre: true post: true activity: return ux * vx + uy * vy; operation cross(ux : OclAny, uy : OclAny, vx : OclAny, vy : OclAny) : OclAny pre: true post: true activity: return ux * vy - uy * vx; operation dist_to_segment(x : OclAny, y : OclAny, ax : OclAny, ay : OclAny, bx : OclAny, by : OclAny) : OclAny pre: true post: true activity: if dot(x - ax, y - ay, bx - ax, by - ay) < 0 then ( return ) else skip ; if dot(x - bx, y - by, ax - bx, ay - by) < 0 then ( return ) else skip ; var c : double := (cross(bx - ax, by - ay, x - ax, y - ay))->abs() ; return c / ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools import sys n=int(input()) s=[input()for i in range(n)] m=0 a=0 r=0 c=0 h=0 for si in s : if si[0]=='M' : m+=1 elif si[0]=='A' : a+=1 elif si[0]=='R' : r+=1 elif si[0]=='C' : c+=1 elif si[0]=='H' : h+=1 if m==0 and a==0 and r==0 and c==0 and h==0 : print(0) else : p=itertools.combinations(['M','A','R','C','H'],3) ans=0 for i in p : ans_=1 if 'M' in i : ans_*=m if 'A' in i : ans_*=a if 'R' in i : ans_*=r if 'C' in i : ans_*=c if 'H' in i : ans_*=h ans+=ans_ print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var m : int := 0 ; var a : int := 0 ; var r : int := 0 ; var c : int := 0 ; var h : int := 0 ; for si : s do ( if si->first() = 'M' then ( m := m + 1 ) else (if si->first() = 'A' then ( a := a + 1 ) else (if si->first() = 'R' then ( r := r + 1 ) else (if si->first() = 'C' then ( c := c + 1 ) else (if si->first() = 'H' then ( h := h + 1 ) else skip ) ) ) ) ) ; if m = 0 & a = 0 & r = 0 & c = 0 & h = 0 then ( execute (0)->display() ) else ( var p : OclAny := itertools.combinations(Sequence{'M'}->union(Sequence{'A'}->union(Sequence{'R'}->union(Sequence{'C'}->union(Sequence{ 'H' })))), 3) ; var ans : int := 0 ; for i : p do ( var ans_ : int := 1 ; if (i)->includes('M') then ( ans_ := ans_ * m ) else skip ; if (i)->includes('A') then ( ans_ := ans_ * a ) else skip ; if (i)->includes('R') then ( ans_ := ans_ * r ) else skip ; if (i)->includes('C') then ( ans_ := ans_ * c ) else skip ; if (i)->includes('H') then ( ans_ := ans_ * h ) else skip ; ans := ans + ans_) ; execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def resolve(): a,b=map(int,input().split()) ans=a-b*2 ans=0 if ans<=0 else ans print(ans) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; resolve(); operation resolve() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : double := a - b * 2 ; ans := if ans <= 0 then 0 else ans endif ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) if n==1 : print('1 1',-a[0],'1 1','0','1 1','0',sep='\n') exit(0) print(1,n) for i in range(n): print(-a[i]*n,end=' ') a[i]-=a[i]*n print() print(1,n-1) for i in range(n-1): print(-a[i],end=' ') a[i]=0 print() print(2,n) for i in range(1,n): print(-a[i],end=' ') a[i]=0 print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = 1 then ( execute ('1 1')->display() ; exit(0) ) else skip ; execute (1)->display() ; for i : Integer.subrange(0, n-1) do ( execute (-a[i+1] * n)->display() ; a[i+1] := a[i+1] - a[i+1] * n) ; execute (->display() ; execute (1)->display() ; for i : Integer.subrange(0, n - 1-1) do ( execute (-a[i+1])->display() ; a[i+1] := 0) ; execute (->display() ; execute (2)->display() ; for i : Integer.subrange(1, n-1) do ( execute (-a[i+1])->display() ; a[i+1] := 0) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd as __gcd def finalNum(arr,n): result=arr[0] for i in arr : result=__gcd(result,i) return result arr=[3,9,6,36] n=len(arr) print(finalNum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{3}->union(Sequence{9}->union(Sequence{6}->union(Sequence{ 36 }))) ; n := (arr)->size() ; execute (finalNum(arr, n))->display(); operation finalNum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var result : OclAny := arr->first() ; for i : arr do ( result := __gcd(result, i)) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=1000 def lastElement(a,n): steps=1 v=[[]for i in range(n)] if n==1 : return a[0] for i in range(0,n,2): v[steps].append(a[i]| a[i+1]) while len(v[steps])>1 : steps+=1 for i in range(0,len(v[steps-1]),2): if steps & 1 : v[steps].append(v[steps-1][i]| v[steps-1][i+1]) else : v[steps].append(v[steps-1][i]^ v[steps-1][i+1]) return v[steps][0] if __name__=="__main__" : a=[1,4,5,6] n=len(a) index,value,a[0]=0,2,2 print(lastElement(a,n)) index,value=3,5 value=5 a[index]=value print(lastElement(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 1000 ; skip ; if __name__ = "__main__" then ( a := Sequence{1}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))) ; n := (a)->size() ; var index : OclAny := null; var value : OclAny := null; var a->first() : OclAny := null; Sequence{index,value,a->first()} := Sequence{0,2,2} ; execute (lastElement(a, n))->display() ; var index : OclAny := null; var value : OclAny := null; Sequence{index,value} := Sequence{3,5} ; var value : int := 5 ; a[index+1] := value ; execute (lastElement(a, n))->display() ) else skip; operation lastElement(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var steps : int := 1 ; var v : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; if n = 1 then ( return a->first() ) else skip ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ((expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name steps)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) | (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))))))))) ))))) ; while (v[steps+1])->size() > 1 do ( steps := steps + 1 ; for i : Integer.subrange(0, (v[steps - 1+1])->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( if MathLib.bitwiseAnd(steps, 1) then ( (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name steps)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name steps))) - (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) | (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name steps))) - (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))))))))) )))) ) else ( (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name steps)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name steps))) - (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) ^ (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name steps))) - (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))))))))) )))) ))) ; return v[steps+1]->first(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def number_cake(n): return(n*n*n+5*n+6)//6 n=2 print(number_cake(n)) n=8 print(number_cake(n)) n=25 print(number_cake(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 2 ; execute (number_cake(n))->display() ; n := 8 ; execute (number_cake(n))->display() ; n := 25 ; execute (number_cake(n))->display(); operation number_cake(n : OclAny) : OclAny pre: true post: true activity: return (n * n * n + 5 * n + 6) div 6; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,x=map(int,input().split()) a=list(map(int,input().split())) count=0 for i in range(N-1): if a[i]+a[i+1]>=x : tmp=(a[i]+a[i+1]-x) a[i+1]-=tmp a[i+1]=max(0,a[i+1]) count+=tmp print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var x : OclAny := null; Sequence{N,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : int := 0 ; for i : Integer.subrange(0, N - 1-1) do ( if (a[i+1] + a[i + 1+1]->compareTo(x)) >= 0 then ( var tmp : double := (a[i+1] + a[i + 1+1] - x) ; a[i + 1+1] := a[i + 1+1] - tmp ; a[i + 1+1] := Set{0, a[i + 1+1]}->max() ; count := count + tmp ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,queue,math,copy,itertools from fractions import gcd sys.setrecursionlimit(10**7) INF=10**18 MOD=10**9+7 LI=lambda :[int(x)for x in sys.stdin.readline().split()] _LI=lambda :[int(x)-1 for x in sys.stdin.readline().split()] NI=lambda : int(sys.stdin.readline()) N,X=LI() A=LI() ans=0 for i in range(1,N): if A[i-1]+A[i]>X : sa=(A[i-1]+A[i])-X if A[i]>=sa : A[i]-=sa else : A[i]=0 ans+=sa print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; var INF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; var LI : Function := lambda $$ : OclAny in (sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) ; var _LI : Function := lambda $$ : OclAny in (sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1))) ; var NI : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var N : OclAny := null; var X : OclAny := null; Sequence{N,X} := LI->apply() ; var A : OclAny := LI->apply() ; var ans : int := 0 ; for i : Integer.subrange(1, N-1) do ( if (A[i - 1+1] + A[i+1]->compareTo(X)) > 0 then ( var sa : double := (A[i - 1+1] + A[i+1]) - X ; if (A[i+1]->compareTo(sa)) >= 0 then ( A[i+1] := A[i+1] - sa ) else ( A[i+1] := 0 ) ; ans := ans + sa ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n,x,*lst1=map(int,sys.stdin.read().split()) res1=res2=0 lst2=[0]+lst1 lst1.append(0) for i in range(n): tmpsum=lst2[i]+lst2[i+1] if tmpsum>x : res1+=tmpsum-x lst2[i+1]-=tmpsum-x for i in range(n,0,-1): tmpsum=lst1[i]+lst1[i-1] if tmpsum>x : res2+=tmpsum-x lst1[i-1]-=tmpsum-x print(min(res1,res2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var x : OclAny := null; var lst1 : OclAny := null; Sequence{n,x,lst1} := (sys.stdin.readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var res1 : OclAny := 0; var res2 : int := 0 ; var lst2 : Sequence := Sequence{ 0 }->union(lst1) ; execute ((0) : lst1) ; for i : Integer.subrange(0, n-1) do ( var tmpsum : OclAny := lst2[i+1] + lst2[i + 1+1] ; if (tmpsum->compareTo(x)) > 0 then ( res1 := res1 + tmpsum - x ; lst2[i + 1+1] := lst2[i + 1+1] - tmpsum - x ) else skip) ; for i : Integer.subrange(0 + 1, n)->reverse() do ( tmpsum := lst1[i+1] + lst1[i - 1+1] ; if (tmpsum->compareTo(x)) > 0 then ( res2 := res2 + tmpsum - x ; lst1[i - 1+1] := lst1[i - 1+1] - tmpsum - x ) else skip) ; execute (Set{res1, res2}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,x=map(int,input().split()) a=[int(x)for x in input().split()] answer=0 for i in range(1,n): if xcollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var answer : int := 0 ; for i : Integer.subrange(1, n-1) do ( if (x->compareTo(a[i - 1+1] + a[i+1])) < 0 then ( answer := answer + a[i - 1+1] + a[i+1] - x ; a[i+1] := a[i+1] - Set{a[i+1], a[i+1] + a[i - 1+1] - x}->min() ) else skip) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- NandX=list(map(int,input().split())) N=NandX[0] x=NandX[1] A=list(map(int,input().split())) ans=0 for i in range(1,N): s=A[i]+A[i-1] if xcollect( _x | (OclType["int"])->apply(_x) )) ; var N : OclAny := NandX->first() ; var x : OclAny := NandX[1+1] ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(1, N-1) do ( var s : OclAny := A[i+1] + A[i - 1+1] ; if (x->compareTo(s)) < 0 then ( var dif : double := s - x ; if (dif->compareTo(A[i+1])) <= 0 then ( A[i+1] := A[i+1] - dif ; ans := ans + dif ) else ( A[i - 1+1] := dif - A[i+1] ; A[i+1] := 0 ; ans := ans + dif ) ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) ans=0 s1=a[0] s2=b[0] i=0 j=0 while icollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; var s1 : OclAny := a->first() ; var s2 : OclAny := b->first() ; var i : int := 0 ; var j : int := 0 ; while (i->compareTo((a)->size())) < 0 or (j->compareTo((b)->size())) < 0 do ( if s1 = s2 then ( ans := ans + 1 ; i := i + 1 ; j := j + 1 ; if (i->compareTo((a)->size())) < 0 & (j->compareTo((b)->size())) < 0 then ( s1 := a[i+1] ; s2 := b[j+1] ) else skip ) else (if (s1->compareTo(s2)) < 0 then ( i := i + 1 ; s1 := s1 + a[i+1] ) else (if (s2->compareTo(s1)) < 0 then ( j := j + 1 ; s2 := s2 + b[j+1] ) else skip ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(10**9) def pin(type=int): return map(type,input().split()) def tupin(t=int): return tuple(pin(t)) def lispin(t=int): return list(pin(t)) from collections import Counter def resolve(): S=input() c=Counter(S) print((c["g"]-c["p"])//2) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; sys.setrecursionlimit((10)->pow(9)) ; skip ; skip ; skip ; skip ; skip ; resolve(); operation pin(type : OclAny) : OclAny pre: true post: true activity: if type->oclIsUndefined() then type := OclType["int"] else skip; return (input->apply().split())->collect( _x | (type)->apply(_x) ); operation tupin(t : OclAny) : OclAny pre: true post: true activity: if t->oclIsUndefined() then t := OclType["int"] else skip; return (pin(t)); operation lispin(t : OclAny) : OclAny pre: true post: true activity: if t->oclIsUndefined() then t := OclType["int"] else skip; return (pin(t)); operation resolve() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var c : OclAny := Counter(S) ; execute ((c->at("g") - c->at("p")) div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,p=map(int,input().split()) if(n>2*p): print(n-2*p) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if ((n->compareTo(2 * p)) > 0) then ( execute (n - 2 * p)->display() ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(input()) num_g,num_p=0,0 score=0 for x in s : if x=='g' : if num_g-num_p>0 : score+=1 num_p+=1 else : score=score num_g+=1 elif x=='p' : if num_g-num_p>0 : score=score num_p+=1 else : score-=1 num_g+=1 print(score) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var num_g : OclAny := null; var num_p : OclAny := null; Sequence{num_g,num_p} := Sequence{0,0} ; var score : int := 0 ; for x : s do ( if x = 'g' then ( if num_g - num_p > 0 then ( score := score + 1 ; num_p := num_p + 1 ) else ( score := score ; num_g := num_g + 1 ) ) else (if x = 'p' then ( if num_g - num_p > 0 then ( score := score ; num_p := num_p + 1 ) else ( score := score - 1 ; num_g := num_g + 1 ) ) else skip)) ; execute (score)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() count=0 for i in range(len(s)): if(i % 2==0 and s[i]=='g'): count=count if(i % 2==0 and s[i]=='p'): count=count-1 if(i % 2==1 and s[i]=='g'): count=count+1 if(i % 2==1 and s[i]=='p'): count=count print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var count : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if (i mod 2 = 0 & s[i+1] = 'g') then ( count := count ) else skip ; if (i mod 2 = 0 & s[i+1] = 'p') then ( count := count - 1 ) else skip ; if (i mod 2 = 1 & s[i+1] = 'g') then ( count := count + 1 ) else skip ; if (i mod 2 = 1 & s[i+1] = 'p') then ( count := count ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): import sys input=sys.stdin.readline s=input().rstrip('\n') t=len(s) mp=t//2 mg=t-mp import collections s=collections.Counter(s) print(mp-s["p"]) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var s : OclAny := input().rstrip(' ') ; var t : int := (s)->size() ; var mp : int := t div 2 ; var mg : double := t - mp ; skip ; s := .Counter(s) ; execute (mp - s->at("p"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() g_cnt=0 for te in s : if te=="g" : g_cnt+=1 p_cnt=len(s)-g_cnt best_p=len(s)//2 diff=best_p-p_cnt print(diff) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var g_cnt : int := 0 ; for te : s->characters() do ( if te = "g" then ( g_cnt := g_cnt + 1 ) else skip) ; var p_cnt : double := (s)->size() - g_cnt ; var best_p : int := (s)->size() div 2 ; var diff : double := best_p - p_cnt ; execute (diff)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pattern(N): k,space,rows=0,1,N for i in range(rows,0,-1): for j in range(1,i+1): print('*',end='') if i!=rows : for k in range(1,space+1): print('',end='') space+=2 for j in range(i,0,-1): if j!=rows : print('*',end='') print() print() N=6 pattern(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 6 ; pattern(N); operation pattern(N : OclAny) pre: true post: true activity: var k : OclAny := null; var space : OclAny := null; var rows : OclAny := null; Sequence{k,space,rows} := Sequence{0,1,N} ; for i : Integer.subrange(0 + 1, rows)->reverse() do ( for j : Integer.subrange(1, i + 1-1) do ( execute ('*')->display()) ; if i /= rows then ( for k : Integer.subrange(1, space + 1-1) do ( execute ('')->display()) ; space := space + 2 ) else skip ; for j : Integer.subrange(0 + 1, i)->reverse() do ( if j /= rows then ( execute ('*')->display() ) else skip) ; execute (->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maximum_middle_value(n,k,arr): ans=-1 low=(n+1-k)//2 high=(n+1-k)//2+k for i in range(low,high+1): ans=max(ans,arr[i-1]) return ans if __name__=="__main__" : n,k=5,2 arr=[9,5,3,7,10] print(maximum_middle_value(n,k,arr)) n,k=9,3 arr1=[2,4,3,9,5,8,7,6,10] print(maximum_middle_value(n,k,arr1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{n,k} := Sequence{5,2} ; arr := Sequence{9}->union(Sequence{5}->union(Sequence{3}->union(Sequence{7}->union(Sequence{ 10 })))) ; execute (maximum_middle_value(n, k, arr))->display() ; Sequence{n,k} := Sequence{9,3} ; var arr1 : Sequence := Sequence{2}->union(Sequence{4}->union(Sequence{3}->union(Sequence{9}->union(Sequence{5}->union(Sequence{8}->union(Sequence{7}->union(Sequence{6}->union(Sequence{ 10 })))))))) ; execute (maximum_middle_value(n, k, arr1))->display() ) else skip; operation maximum_middle_value(n : OclAny, k : OclAny, arr : OclAny) : OclAny pre: true post: true activity: var ans : int := -1 ; var low : int := (n + 1 - k) div 2 ; var high : int := (n + 1 - k) div 2 + k ; for i : Integer.subrange(low, high + 1-1) do ( ans := Set{ans, arr[i - 1+1]}->max()) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def pathSumHelper(self,root,target,so_far,cache): if root : complement=so_far+root.val-target if complement in cache : self.result+=cache[complement] cache[so_far+root.val]=cache.get(so_far+root.val,0)+1 self.pathSumHelper(root.left,target,so_far+root.val,cache) self.pathSumHelper(root.right,target,so_far+root.val,cache) cache[so_far+root.val]-=1 return def pathSum(self,root,sum): self.result=0 self.pathSumHelper(root,sum,0,{0 : 1}) return self.result ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation pathSumHelper(root : OclAny,target : OclAny,so_far : OclAny,cache : OclAny) pre: true post: true activity: if root then ( var complement : double := so_far + root.val - target ; if (cache)->includes(complement) then ( self.result := self.result + cache[complement+1] ) else skip ; cache[so_far + root.val+1] := cache.get(so_far + root.val, 0) + 1 ; self.pathSumHelper(root.left, target, so_far + root.val, cache) ; self.pathSumHelper(root.right, target, so_far + root.val, cache) ; cache[so_far + root.val+1] := cache[so_far + root.val+1] - 1 ) else skip ; return; operation pathSum(root : OclAny,sum : OclAny) : OclAny pre: true post: true activity: self.result := 0 ; self.pathSumHelper(root, sum, 0, Map{ 0 |-> 1 }) ; return self.result; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getmax(arr,n,x): s=0 for i in range(n): s=s+arr[i] print(min(s,x)) if __name__=='__main__' : arr=[1,2,3,4] x=5 arr_size=len(arr) getmax(arr,arr_size,x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))) ; x := 5 ; var arr_size : int := (arr)->size() ; getmax(arr, arr_size, x) ) else skip; operation getmax(arr : OclAny, n : OclAny, x : OclAny) pre: true post: true activity: var s : int := 0 ; for i : Integer.subrange(0, n-1) do ( s := s + arr[i+1]) ; execute (Set{s, x}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) cnt=0 x=0 ; y=0 i=0 ; j=0 f=-1 while iy : j+=1 f=1 else : i+=1 f=2 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : int := 0 ; var x : int := 0; var y : int := 0 ; var i : int := 0; var j : int := 0 ; var f : int := -1 ; while (i->compareTo(n)) < 0 & (j->compareTo(m)) < 0 do ( if f /= 1 then ( x := x + a[i+1] ) else skip ; if f /= 2 then ( y := y + b[j+1] ) else skip ; if x = y then ( cnt := cnt + 1 ; i := i + 1 ; j := j + 1 ; f := -1 ) else (if (x->compareTo(y)) > 0 then ( j := j + 1 ; f := 1 ) else ( i := i + 1 ; f := 2 ) ) ) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): print("Case "+str(i+1)+":") num=int(input()) for j in range(0,10): num*=num sn=str(num) if len(sn)<8 : d=8-len(sn) for k in range(d): sn="0"+sn num=int(sn[2 : 6]) print(num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( execute ("Case " + ("" + ((i + 1))) + ":")->display() ; var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, 10-1) do ( num := num * num ; var sn : String := ("" + ((num))) ; if (sn)->size() < 8 then ( var d : double := 8 - (sn)->size() ; for k : Integer.subrange(0, d-1) do ( sn := "0" + sn) ) else skip ; num := ("" + ((sn.subrange(2+1, 6))))->toInteger() ; execute (num)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- digit=100 def vrand(seed): del_down=int(seed*seed/digit) up_=int(del_down/(digit*digit)) up_*=(digit*digit) return del_down-up_ num=int(input()) sds=[] for i in range(num): sd=int(input()) sds.append(sd) for i in range(num): print("Case "+str(i+1)+":") seed=sds[i] for j in range(10): seed=vrand(seed) print(seed) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var digit : int := 100 ; skip ; var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sds : Sequence := Sequence{} ; for i : Integer.subrange(0, num-1) do ( var sd : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((sd) : sds)) ; for i : Integer.subrange(0, num-1) do ( execute ("Case " + ("" + ((i + 1))) + ":")->display() ; seed := sds[i+1] ; for j : Integer.subrange(0, 10-1) do ( seed := vrand(seed) ; execute (seed)->display())); operation vrand(seed : OclAny) : OclAny pre: true post: true activity: var del_down : int := ("" + ((seed * seed / digit)))->toInteger() ; var up_ : int := ("" + ((del_down / (digit * digit))))->toInteger() ; up_ := up_ * (digit * digit) ; return del_down - up_; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=list(map(int,input().split())) for e,i in enumerate(a): if i==0 : print(e+1) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var e : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); if i = 0 then ( execute (e + 1)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def solve(i,n): result=[] while len(result)<10 : i=i**2 i//=100 i %=10**n result.append(i) return result def main(args): n=4 d=int(input()) for i in range(1,d+1): init_value=int(input()) result=solve(init_value,n) print('Case{}:'.format(i)) print('\n'.join(map(str,result))) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(i : OclAny, n : OclAny) : OclAny pre: true post: true activity: var result : Sequence := Sequence{} ; while (result)->size() < 10 do ( i := (i)->pow(2) ; i := i div 100 ; i := i mod (10)->pow(n) ; execute ((i) : result)) ; return result; operation main(args : OclAny) pre: true post: true activity: n := 4 ; var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(1, d + 1-1) do ( var init_value : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; result := solve(init_value, n) ; execute (StringLib.interpolateStrings('Case{}:', Sequence{i}))->display() ; execute (StringLib.sumStringsWithSeparator(((result)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,copy PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") def middle_square(k): for step in range(10): k=(k**2//100)% 10000 print(k) N=int(input()) for case in range(1,N+1): print("Case %d:" % case) k=int(input()) middle_square(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for case : Integer.subrange(1, N + 1-1) do ( execute (StringLib.format("Case %d:",case))->display() ; k := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; middle_square(k)); operation middle_square(k : OclAny) pre: true post: true activity: for step : Integer.subrange(0, 10-1) do ( k := ((k)->pow(2) div 100) mod 10000 ; execute (k)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): d=int(input()) a=[] for _ in range(d): a.append(int(input())) ans=[] for x in range(d): ansans=[] hoge=a[x] for y in range(10): hoge=list("{0:08d}".format(hoge**2)) s="" for z in range(2,6): s+=hoge[z] hoge=int(s) ansans.append(hoge) ans.append(ansans) for x in range(1,d+1): print("Case",x,end="") print(":") for y in ans[x-1]: print(y) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; for _anon : Integer.subrange(0, d-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : a)) ; var ans : Sequence := Sequence{} ; for x : Integer.subrange(0, d-1) do ( var ansans : Sequence := Sequence{} ; var hoge : OclAny := a[x+1] ; for y : Integer.subrange(0, 10-1) do ( hoge := (StringLib.interpolateStrings("{0:08d}", Sequence{(hoge)->pow(2)}))->characters() ; var s : String := "" ; for z : Integer.subrange(2, 6-1) do ( s := s + hoge[z+1]) ; hoge := ("" + ((s)))->toInteger() ; execute ((hoge) : ansans)) ; execute ((ansans) : ans)) ; for x : Integer.subrange(1, d + 1-1) do ( execute ("Case")->display() ; execute (":")->display() ; for y : ans[x - 1+1] do ( execute (y)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=250000 SQRT=500 prime=[True]*MAX def sieve(): for i in range(2,MAX,2): prime[i]=False for i in range(3,SQRT,2): if prime[i]: for j in range(i*i,MAX,i): prime[j]=False sieve() while True : n=int(input()) if n==0 : break ans,m=0,n<<1 if n==1 : ans+=1 i=n+1 if(i & 1)==0 : i+=1 while i<=m : if prime[i]: ans+=1 i+=2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 250000 ; var SQRT : int := 500 ; var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, MAX) ; skip ; sieve() ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var ans : OclAny := null; var m : OclAny := null; Sequence{ans,m} := Sequence{0,n * (2->pow(1))} ; if n = 1 then ( ans := ans + 1 ) else skip ; var i : int := n + 1 ; if (MathLib.bitwiseAnd(i, 1)) = 0 then ( i := i + 1 ) else skip ; while (i->compareTo(m)) <= 0 do ( if prime[i+1] then ( ans := ans + 1 ) else skip ; i := i + 2) ; execute (ans)->display()); operation sieve() pre: true post: true activity: for i : Integer.subrange(2, MAX-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( prime[i+1] := false) ; for i : Integer.subrange(3, SQRT-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if prime[i+1] then ( for j : Integer.subrange(i * i, MAX-1)->select( $x | ($x - i * i) mod i = 0 ) do ( prime[j+1] := false) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import bisect inputs=[] while True : n=int(input()) if n==0 : break inputs.append(n) max_n=max(inputs) primes=[True for i in range(2*max_n+1)] primes[0]=False primes[1]=False for i in range(2,int(math.sqrt(2*max_n))+1): tmp=2*i while tmp<=2*max_n : primes[tmp]=False tmp+=i primes_lst=[] for i in range(2*max_n+1): if primes[i]: primes_lst.append(i) for n in inputs : if n==1 : print(1) else : print(bisect.bisect_left(primes_lst,2*n)-bisect.bisect_right(primes_lst,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var inputs : Sequence := Sequence{} ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; execute ((n) : inputs)) ; var max_n : OclAny := (inputs)->max() ; var primes : Sequence := Integer.subrange(0, 2 * max_n + 1-1)->select(i | true)->collect(i | (true)) ; primes->first() := false ; primes[1+1] := false ; for i : Integer.subrange(2, ("" + (((2 * max_n)->sqrt())))->toInteger() + 1-1) do ( var tmp : double := 2 * i ; while (tmp->compareTo(2 * max_n)) <= 0 do ( primes[tmp+1] := false ; tmp := tmp + i)) ; var primes_lst : Sequence := Sequence{} ; for i : Integer.subrange(0, 2 * max_n + 1-1) do ( if primes[i+1] then ( execute ((i) : primes_lst) ) else skip) ; for n : inputs do ( if n = 1 then ( execute (1)->display() ) else ( execute (bisect.bisect_left(primes_lst, 2 * n) - bisect.bisect_right(primes_lst, n))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from itertools import accumulate limit=2*123456+1 def solve(): is_prime=eratos(limit) cnt=[0]+list(accumulate(is_prime)) while 1 : n=int(sys.stdin.readline().rstrip()) if n==0 : return ans=cnt[2*n+1]-cnt[n+1] print(ans) def eratos(n): sieve=[True]*n sieve[0]=sieve[1]=False for p in range(2,n): if p*p>n : break if sieve[p]: for q in range(p*p,n,p): sieve[q]=False return sieve if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var limit : int := 2 * 123456 + 1 ; skip ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var is_prime : OclAny := eratos(limit) ; var cnt : Sequence := Sequence{ 0 }->union((accumulate(is_prime))) ; while 1 do ( var n : int := ("" + ((sys.stdin.readLine().rstrip())))->toInteger() ; if n = 0 then ( return ) else skip ; var ans : double := cnt[2 * n + 1+1] - cnt[n + 1+1] ; execute (ans)->display()); operation eratos(n : OclAny) : OclAny pre: true post: true activity: var sieve : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, n) ; sieve->first() := false; var sieve[1+1] : boolean := false ; for p : Integer.subrange(2, n-1) do ( if (p * p->compareTo(n)) > 0 then ( break ) else skip ; if sieve[p+1] then ( for q : Integer.subrange(p * p, n-1)->select( $x | ($x - p * p) mod p = 0 ) do ( sieve[q+1] := false) ) else skip) ; return sieve; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=(123456*2)+1 p=[1]*N def seive(): for i in range(2,int(N**0.5)+1): if p[i]==1 : for j in range(i*2,N+1,i): p[j]=0 seive() def main(): while True : n=int(input()) if n==0 : break print(sum(p[n+1 : n*2+1])) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := (123456 * 2) + 1 ; var p : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, N) ; skip ; seive() ; skip ; main(); operation seive() pre: true post: true activity: for i : Integer.subrange(2, ("" + (((N)->pow(0.5))))->toInteger() + 1-1) do ( if p[i+1] = 1 then ( for j : Integer.subrange(i * 2, N + 1-1)->select( $x | ($x - i * 2) mod i = 0 ) do ( p[j+1] := 0) ) else skip); operation main() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; execute ((p.subrange(n + 1+1, n * 2 + 1))->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def solve(n,m,blocks_1,blocks_2): blocks_1=deque(blocks_1) blocks_2=deque(blocks_2) sum_1=blocks_1.popleft() sum_2=0 ans=0 while len(blocks_1)>0 and len(blocks_2)>0 : if sum_10 : ans+=1 return ans if __name__=='__main__' : n,m=list(map(int,input().split())) blocks_1=list(map(int,input().split())) blocks_2=list(map(int,input().split())) print(solve(n,m,blocks_1,blocks_2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; blocks Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; blocks:= ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (solve(n, m, blocksm, blocks_2))->display() ) else skip; operation solve(n : OclAny, m : OclAny, blocksm : OclAny : OclAny, blocks_2 : OclAny) : OclAny pre: true post: true activity: blocks skip := (blocks skip) ; blocks:= (blocks_2) := (blocks_2) ; var sum blocks skip := (blocks skip) : OclAny := blocks blocks skip := (blocks skip)->first() ; blocksblocksblocksblocksblocksblocksblocks blocks skip := (blocks skip)->first()->first()->first()->first()->first()->first() := blocksblocksblocksblocksblocksblocksblocks blocks skip := (blocks skip)->first()->first()->first()->first()->first()->first()->tail() ; var sum:= 0 : int := 0 ; var ans : int := 0 ; while (blocks blocks skip := (blocks skip))->size() > 0 & (blocks0)->size() > 0 do ( if (sum blocks skip := (blocks skip)->compareTo(sum sum blocks skip := (blocks skip) := sum blocks skip := (blocks skip) + blocks blocks skip := (blocks skip)->first() ; blocksblocksblocksblocksblocksblocks blocks skip := (blocks skip)->first()->first()->first()->first()->first() := blocksblocksblocksblocksblocksblocks blocks skip := (blocks skip)->first()->first()->first()->first()->first()->tail())) < 0 then ( sum blocks skip := (blocks skip) := sum blocks skip := (blocks skip) + blocks blocks skip := (blocks skip)->first() ; blocksblocksblocksblocksblocksblocks blocks skip := (blocks skip)->first()->first()->first()->first()->first() := blocksblocksblocksblocksblocksblocks blocks skip := (blocks skip)->first()->first()->first()->first()->first()->tail() ) else ( sum + blocks_2->first() ; blocks->first() := blocks->first()->tail() := sum + blocks_2->first() ; blocks->first() := blocks->first()->tail() + blocks_2->first() ; blocks->first() := blocks->first()->tail() ) ; if sum if (sum blocks skip := (blocks skip)->compareTo(sum sum blocks skip := (blocks skip) := sum blocks skip := (blocks skip) + blocks blocks skip := (blocks skip)->first() ; blocksblocksblocksblocksblocksblocks blocks skip := (blocks skip)->first()->first()->first()->first()->first() := blocksblocksblocksblocksblocksblocks blocks skip := (blocks skip)->first()->first()->first()->first()->first()->tail())) < 0 then ( sum blocks skip := (blocks skip) := sum blocks skip := (blocks skip) + blocks blocks skip := (blocks skip)->first() ; blocksblocksblocksblocksblocksblocks blocks skip := (blocks skip)->first()->first()->first()->first()->first() := blocksblocksblocksblocksblocksblocks blocks skip := (blocks skip)->first()->first()->first()->first()->first()->tail() ) else ( sum + blocks_2->first() ; blocks->first() := blocks->first()->tail() := sum + blocks_2->first() ; blocks->first() := blocks->first()->tail() + blocks_2->first() ; blocks->first() := blocks->first()->tail() ) = sum ans := ans + 1 then ( ans := ans + 1 ) else skip) ; if (blocks blocks skip := (blocks skip))->size() + (blocks0)->size() > 0 then ( ans := ans + 1 ) else skip ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def prime(n): flag=[True]*(n+1) flag[0]=flag[1]=False for i in range(2,int(n**0.5)+1): if flag[i]: for j in range(i**2,n+1,i): flag[j]=False return flag flag=prime(123456*2) while True : n=int(input()) if n==0 : break print(flag[n+1 : 2*n+1].count(True)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; flag := prime(123456 * 2) ; while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; execute (flag.subrange(n + 1+1, 2 * n + 1)->count(true))->display()); operation prime(n : OclAny) : OclAny pre: true post: true activity: var flag : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (n + 1)) ; flag->first() := false; var flag[1+1] : boolean := false ; for i : Integer.subrange(2, ("" + (((n)->pow(0.5))))->toInteger() + 1-1) do ( if flag[i+1] then ( for j : Integer.subrange((i)->pow(2), n + 1-1)->select( $x | ($x - (i)->pow(2)) mod i = 0 ) do ( flag[j+1] := false) ) else skip) ; return flag; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxOR(arr,n): maxVal=0 ; for i in range(n-1): for j in range(i+1,n): maxVal=max(maxVal,arr[i]| arr[j]); return maxVal ; if __name__=='__main__' : arr=[4,8,12,16]; n=len(arr); print(maxOR(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{4}->union(Sequence{8}->union(Sequence{12}->union(Sequence{ 16 }))); ; n := (arr)->size(); ; execute (maxOR(arr, n))->display(); ) else skip; operation maxOR(arr : OclAny, n : OclAny) pre: true post: true activity: var maxVal : int := 0; ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(i + 1, n-1) do ( maxVal := Set{maxVal, MathLib.bitwiseOr(arr[i+1], arr[j+1])}->max();)) ; return maxVal;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def numJewelsInStones(self,J,S): if len(J)==0 or len(S)==0 : return 0 j_set=set(J) ans=0 for c in S : if c in j_set : ans+=1 return ans ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation numJewelsInStones(J : OclAny,S : OclAny) : OclAny pre: true post: true activity: if (J)->size() = 0 or (S)->size() = 0 then ( return 0 ) else skip ; var j_set : Set := Set{}->union((J)) ; var ans : int := 0 ; for c : S do ( if (j_set)->includes(c) then ( ans := ans + 1 ) else skip) ; return ans; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def examA(): X=LI() for i in range(len(X)): if X[i]==0 : ans=i+1 print(ans) return def examB(): ans=0 print(ans) return def examC(): ans=0 print(ans) return def examD(): ans=0 print(ans) return def examE(): ans=0 print(ans) return def examF(): ans=0 print(ans) return from decimal import Decimal as dec import sys,bisect,itertools,heapq,math,random from copy import deepcopy from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines def I(): return int(input()) def LI(): return list(map(int,sys.stdin.readline().split())) def DI(): return dec(input()) def LDI(): return list(map(dec,sys.stdin.readline().split())) def LSI(): return list(map(str,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod,mod2,inf,alphabet,_ep mod=10**9+7 mod2=998244353 inf=10**18 _ep=10**(-12) alphabet=[chr(ord('a')+i)for i in range(26)] sys.setrecursionlimit(10**7) if __name__=='__main__' : examA() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute mod : OclAny; attribute mod2 : OclAny; attribute inf : OclAny; attribute alphabet : OclAny; attribute _ep : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip; skip; skip; skip; skip ; mod := (10)->pow(9) + 7 ; mod2 := 998244353 ; Math_PINFINITY := (10)->pow(18) ; _ep := (10)->pow((-12)) ; alphabet := Integer.subrange(0, 26-1)->select(i | true)->collect(i | ((('a')->char2byte() + i)->byte2char())) ; sys.setrecursionlimit((10)->pow(7)) ; if __name__ = '__main__' then ( examA() ) else skip; operation examA() pre: true post: true activity: var X : OclAny := LI() ; for i : Integer.subrange(0, (X)->size()-1) do ( if X[i+1] = 0 then ( var ans : OclAny := i + 1 ) else skip) ; execute (ans)->display() ; return; operation examB() pre: true post: true activity: ans := 0 ; execute (ans)->display() ; return; operation examC() pre: true post: true activity: ans := 0 ; execute (ans)->display() ; return; operation examD() pre: true post: true activity: ans := 0 ; execute (ans)->display() ; return; operation examE() pre: true post: true activity: ans := 0 ; execute (ans)->display() ; return; operation examF() pre: true post: true activity: ans := 0 ; execute (ans)->display() ; return; operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation DI() : OclAny pre: true post: true activity: return dec((OclFile["System.in"]).readLine()); operation LDI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (dec)->apply(_x) )); operation LSI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["String"])->apply(_x) )); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation SI() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100 ; n=0 ; store=[0]*MAX ; graph=[[0 for i in range(MAX)]for j in range(MAX)]; d=[0]*MAX ; def is_clique(b): for i in range(1,b): for j in range(i+1,b): if(graph[store[i]][store[j]]==0): return False ; return True ; def maxCliques(i,l): max_=0 ; for j in range(i+1,n+1): store[l]=j ; if(is_clique(l+1)): max_=max(max_,l); max_=max(max_,maxCliques(j,l+1)); return max_ ; if __name__=='__main__' : edges=[[1,2],[2,3],[3,1],[4,3],[4,1],[4,2]]; size=len(edges); n=4 ; for i in range(size): graph[edges[i][0]][edges[i][1]]=1 ; graph[edges[i][1]][edges[i][0]]=1 ; d[edges[i][0]]+=1 ; d[edges[i][1]]+=1 ; print(maxCliques(0,1)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 100; ; var n : int := 0; ; var store : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX); ; var graph : Sequence := Integer.subrange(0, MAX-1)->select(j | true)->collect(j | (Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)))); ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX); ; skip ; skip ; if __name__ = '__main__' then ( var edges : Sequence := Sequence{Sequence{1}->union(Sequence{ 2 })}->union(Sequence{Sequence{2}->union(Sequence{ 3 })}->union(Sequence{Sequence{3}->union(Sequence{ 1 })}->union(Sequence{Sequence{4}->union(Sequence{ 3 })}->union(Sequence{Sequence{4}->union(Sequence{ 1 })}->union(Sequence{ Sequence{4}->union(Sequence{ 2 }) }))))); ; var size : int := (edges)->size(); ; n := 4; ; for i : Integer.subrange(0, size-1) do ( graph[edges[i+1]->first()+1][edges[i+1][1+1]+1] := 1; ; graph[edges[i+1][1+1]+1][edges[i+1]->first()+1] := 1; ; d[edges[i+1]->first()+1] := d[edges[i+1]->first()+1] + 1; ; d[edges[i+1][1+1]+1] := d[edges[i+1][1+1]+1] + 1;) ; execute (maxCliques(0, 1))->display(); ) else skip; operation is_clique(b : OclAny) pre: true post: true activity: for i : Integer.subrange(1, b-1) do ( for j : Integer.subrange(i + 1, b-1) do ( if (graph[store[i+1]+1][store[j+1]+1] = 0) then ( return false; ) else skip)) ; return true;; operation maxCliques(i : OclAny, l : OclAny) pre: true post: true activity: var max_ : int := 0; ; for j : Integer.subrange(i + 1, n + 1-1) do ( store[l+1] := j; ; if (is_clique(l + 1)) then ( max_ := Set{max_, l}->max(); ; max_ := Set{max_, maxCliques(j, l + 1)}->max(); ) else skip) ; return max_;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def setBitNumber(n): k=int(math.log(n,2)) return 2**k n=273 print(setBitNumber(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 273 ; execute (setBitNumber(n))->display(); operation setBitNumber(n : OclAny) : OclAny pre: true post: true activity: var k : int := ("" + (((n, 2)->log())))->toInteger() ; return (2)->pow(k); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) n,m,s,f=R() if st and kcollect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var m : OclAny := null; var s : OclAny := null; var f : OclAny := null; Sequence{n,m,s,f} := R->apply() ; if (s->compareTo(f)) < 0 then ( var d : int := 1 ; var c : String := 'R' ) else ( d := -1 ; c := 'L' ) ; var res : String := "" ; var i : int := 1 ; var j : OclAny := s ; var t : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{t,l,r} := R->apply() ; var k : int := 1 ; while j /= f do ( if (i->compareTo(t)) > 0 & (k->compareTo(m)) < 0 then ( var t : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{t,l,r} := R->apply() ; k := k + 1 ) else skip ; if i = t & ((l->compareTo(j)) <= 0 & (j <= r) or (l->compareTo(j + d)) <= 0 & (j + d <= r)) then ( res := res + 'X' ) else ( res := res + c ; j := j + d ) ; i := i + 1) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) n,m,s,f=R() if st and kcollect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var m : OclAny := null; var s : OclAny := null; var f : OclAny := null; Sequence{n,m,s,f} := R->apply() ; if (s->compareTo(f)) < 0 then ( var d : int := 1 ; var c : String := 'R' ) else ( d := -1 ; c := 'L' ) ; var res : String := "" ; var i : int := 1 ; var j : OclAny := s ; var t : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{t,l,r} := R->apply() ; var k : int := 1 ; while j /= f do ( if (i->compareTo(t)) > 0 & (k->compareTo(m)) < 0 then ( var t : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{t,l,r} := R->apply() ; k := k + 1 ) else skip ; if i = t & ((l->compareTo(j)) <= 0 & (j <= r) or (l->compareTo(j + d)) <= 0 & (j + d <= r)) then ( res := res + 'X' ) else ( res := res + c ; j := j + d ) ; i := i + 1) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def subsetPairNotDivisibleByK(arr,N,K): f=[0 for i in range(K)] for i in range(N): f[arr[i]% K]+=1 if(K % 2==0): f[K//2]=min(f[K//2],1) res=min(f[0],1) for i in range(1,(K//2)+1): res+=max(f[i],f[K-i]) return res arr=[3,7,2,9,1] N=len(arr) K=3 print(subsetPairNotDivisibleByK(arr,N,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{3}->union(Sequence{7}->union(Sequence{2}->union(Sequence{9}->union(Sequence{ 1 })))) ; N := (arr)->size() ; K := 3 ; execute (subsetPairNotDivisibleByK(arr, N, K))->display(); operation subsetPairNotDivisibleByK(arr : OclAny, N : OclAny, K : OclAny) : OclAny pre: true post: true activity: var f : Sequence := Integer.subrange(0, K-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, N-1) do ( f[arr[i+1] mod K+1] := f[arr[i+1] mod K+1] + 1) ; if (K mod 2 = 0) then ( f[K div 2+1] := Set{f[K div 2+1], 1}->min() ) else skip ; var res : OclAny := Set{f->first(), 1}->min() ; for i : Integer.subrange(1, (K div 2) + 1-1) do ( res := res + Set{f[i+1], f[K - i+1]}->max()) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(lines): w,m,k=list(map(int,lines[0].split())) max_length=0 available_digits=int(w/k) while available_digits>0 : current_cost_per_n=len(str(m)) same_cost_until=10**(current_cost_per_n) usable_numbers=same_cost_until-m use_digits=usable_numbers*current_cost_per_n m=same_cost_until if available_digits>=use_digits : max_length+=usable_numbers available_digits-=use_digits else : max_length+=int(available_digits/current_cost_per_n) available_digits=0 print(max_length) if __name__=="__main__" : main(sys.stdin.readlines()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main((OclFile["System.in"]).readlines()) ) else skip; operation main(lines : OclAny) pre: true post: true activity: var w : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{w,m,k} := ((lines->first().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var max_length : int := 0 ; var available_digits : int := ("" + ((w / k)))->toInteger() ; while available_digits > 0 do ( var current_cost_per_n : int := (("" + ((m))))->size() ; var same_cost_until : double := (10)->pow((current_cost_per_n)) ; var usable_numbers : double := same_cost_until - m ; var use_digits : double := usable_numbers * current_cost_per_n ; var m : OclAny := same_cost_until ; if (available_digits->compareTo(use_digits)) >= 0 then ( max_length := max_length + usable_numbers ; available_digits := available_digits - use_digits ) else ( max_length := max_length + ("" + ((available_digits / current_cost_per_n)))->toInteger() ; available_digits := 0 )) ; execute (max_length)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) c,i,j,x,y=1,0,0,0,0 while iy : y+=b[j] j+=1 elif xcollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : OclAny := null; var i : OclAny := null; var j : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{c,i,j,x,y} := Sequence{1,0,0,0,0} ; while (i->compareTo(n)) < 0 or (j->compareTo(m)) < 0 do ( if x = 0 then ( x := x + a[i+1] ; i := i + 1 ) else skip ; if (x->compareTo(y)) > 0 then ( y := y + b[j+1] ; j := j + 1 ) else (if (x->compareTo(y)) < 0 then ( x := x + a[i+1] ; i := i + 1 ) else ( c := c + 1 ; var x : OclAny := 0; var y : int := 0 ) ) ) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w,m,k=list(map(int,input().split())) z=a=10**len(str(m))-m if a*len(str(m))*k>=w : print(w//(len(str(m))*k)) else : w-=a*len(str(m))*k c=len(str(m))+1 while w>0 : a=9*10**(c-1) if a*c*k>=w : print(w//(c*k)+z) break w-=a*c*k z+=a c+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{w,m,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var z : OclAny := (10)->pow((("" + ((m))))->size()) - m; var a : double := (10)->pow((("" + ((m))))->size()) - m ; if (a * (("" + ((m))))->size() * k->compareTo(w)) >= 0 then ( execute (w div ((("" + ((m))))->size() * k))->display() ) else ( w := w - a * (("" + ((m))))->size() * k ; var c : int := (("" + ((m))))->size() + 1 ; while w > 0 do ( a := 9 * (10)->pow((c - 1)) ; if (a * c * k->compareTo(w)) >= 0 then ( execute (w div (c * k) + z)->display() ; break ) else skip ; w := w - a * c * k ; z := z + a ; c := c + 1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sum(k): ret=0 pw=10 len=1 while 1==1 : cur=min(pw-1,k) prev=pw//10 ret+=(cur-prev+1)*len if(pw-1>=k): break len+=1 pw*=10 return ret w,m,k=map(int,input().split()) lo=0 hi=int(1e18) while hi-lo>1 : md=(lo+hi)//2 c=sum(m+md-1)-sum(m-1) if c*k<=w : lo=md else : hi=md print(lo) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var w : OclAny := null; var m : OclAny := null; Sequence{w,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lo : int := 0 ; var hi : int := ("" + ((("1e18")->toReal())))->toInteger() ; while hi - lo > 1 do ( var md : int := (lo + hi) div 2 ; var c : double := (m + md - 1)->sum() - (m - 1)->sum() ; if (c * k->compareTo(w)) <= 0 then ( lo := md ) else ( hi := md )) ; execute (lo)->display(); operation sum(k : OclAny) : OclAny pre: true post: true activity: var ret : int := 0 ; var pw : int := 10 ; var len : int := 1 ; while 1 = 1 do ( var cur : OclAny := Set{pw - 1, k}->min() ; var prev : int := pw div 10 ; ret := ret + (cur - prev + 1) * len ; if ((pw - 1->compareTo(k)) >= 0) then ( break ) else skip ; len := len + 1 ; pw := pw * 10) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- int_in=input() integers=int_in.split() integers=list(map(int,integers)) w=integers[0] m=integers[1] k=integers[2] n=0 while(10**n)<=m : n+=1 max_len=0 c=0 while c+(10**(n)-m)*n*k<=w : c+=(10**(n)-m)*n*k max_len+=10**(n)-m m=10**n n+=1 max_len+=(w-c)//(n*k) print(max_len) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var int_in : String := (OclFile["System.in"]).readLine() ; var integers : OclAny := int_in.split() ; integers := ((integers)->collect( _x | (OclType["int"])->apply(_x) )) ; var w : OclAny := integers->first() ; var m : OclAny := integers[1+1] ; var k : OclAny := integers[2+1] ; var n : int := 0 ; while (((10)->pow(n))->compareTo(m)) <= 0 do ( n := n + 1) ; var max_len : int := 0 ; var c : int := 0 ; while (c + ((10)->pow((n)) - m) * n * k->compareTo(w)) <= 0 do ( c := c + ((10)->pow((n)) - m) * n * k ; max_len := max_len + (10)->pow((n)) - m ; m := (10)->pow(n) ; n := n + 1) ; max_len := max_len + (w - c) div (n * k) ; execute (max_len)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- W,M,K=map(int,input().split()) def f(N): ANS=0 for keta in range(1,20): lo=10**(keta-1) hi=min(N,10**keta-1) cnt=max(hi-lo+1,0) ANS+=keta*cnt return ANS ok=0 ng=1<<100 while ok+1collect( _x | (OclType["int"])->apply(_x) ) ; skip ; var ok : int := 0 ; var ng : int := 1 * (2->pow(100)) ; while (ok + 1->compareTo(ng)) < 0 do ( var x : int := (ok + ng) div 2 ; if ((f(M + x - 1) - f(M - 1)) * K->compareTo(W)) <= 0 then ( ok := x ) else ( ng := x )) ; execute (ok)->display(); operation f(N : OclAny) : OclAny pre: true post: true activity: var ANS : int := 0 ; for keta : Integer.subrange(1, 20-1) do ( var lo : double := (10)->pow((keta - 1)) ; var hi : OclAny := Set{N, (10)->pow(keta) - 1}->min() ; var cnt : OclAny := Set{hi - lo + 1, 0}->max() ; ANS := ANS + keta * cnt) ; return ANS; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() a=a.replace("","") print(a.find("0")+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; a := a.replace("", "") ; execute (a->indexOf("0") - 1 + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printRoots(a,b,c): print(1,",",c/(a*1.0)) a=2 b=3 c=-5 printRoots(a,b,c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 2 ; b := 3 ; c := -5 ; printRoots(a, b, c); operation printRoots(a : OclAny, b : OclAny, c : OclAny) pre: true post: true activity: execute (1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- memo=[[[-1 for i in range(2)]for j in range(2)]for k in range(32)] def dp(pos,fl,pr,bin): if(pos==len(bin)): return 1 ; if(memo[pos][fl][pr]!=-1): return memo[pos][fl][pr]; val=0 if(bin[pos]=='0'): val=val+dp(pos+1,fl,0,bin) elif(bin[pos]=='1'): val=val+dp(pos+1,1,0,bin) if(pr==0): if(fl==1): val+=dp(pos+1,fl,1,bin) elif(bin[pos]=='1'): val+=dp(pos+1,fl,1,bin) memo[pos][fl][pr]=val return val def findIntegers(num): bin="" while(num>0): if(num % 2): bin+="1" else : bin+="0" num//=2 bin=bin[: :-1]; return dp(0,0,0,bin) if __name__=="__main__" : N=12 print(findIntegers(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var memo : Sequence := Integer.subrange(0, 32-1)->select(k | true)->collect(k | (Integer.subrange(0, 2-1)->select(j | true)->collect(j | (Integer.subrange(0, 2-1)->select(i | true)->collect(i | (-1)))))) ; skip ; skip ; if __name__ = "__main__" then ( var N : int := 12 ; execute (findIntegers(N))->display() ) else skip; operation dp(pos : OclAny, fl : OclAny, pr : OclAny, bin : OclAny) : OclAny pre: true post: true activity: if (pos = (bin)->size()) then ( return 1; ) else skip ; if (memo[pos+1][fl+1][pr+1] /= -1) then ( return memo[pos+1][fl+1][pr+1]; ) else skip ; var val : int := 0 ; if (bin[pos+1] = '0') then ( val := val + dp(pos + 1, fl, 0, bin) ) else (if (bin[pos+1] = '1') then ( val := val + dp(pos + 1, 1, 0, bin) ) else skip) ; if (pr = 0) then ( if (fl = 1) then ( val := val + dp(pos + 1, fl, 1, bin) ) else (if (bin[pos+1] = '1') then ( val := val + dp(pos + 1, fl, 1, bin) ) else skip) ) else skip ; memo[pos+1][fl+1][pr+1] := val ; return val; operation findIntegers(num : OclAny) : OclAny pre: true post: true activity: bin := "" ; while (num > 0) do ( if (num mod 2) then ( bin := bin + "1" ) else ( bin := bin + "0" ) ; num := num div 2) ; bin := bin(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); ; return dp(0, 0, 0, bin); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=4 def MaximumDecimalValue(mat,n): dp=[[0 for i in range(n)]for i in range(n)] if(mat[0][0]==1): dp[0][0]=1 for i in range(1,n): if(mat[0][i]==1): dp[0][i]=dp[0][i-1]+2**i else : dp[0][i]=dp[0][i-1] for i in range(1,n): if(mat[i][0]==1): dp[i][0]=dp[i-1][0]+2**i else : dp[i][0]=dp[i-1][0] for i in range(1,n): for j in range(1,n): if(mat[i][j]==1): dp[i][j]=max(dp[i][j-1],dp[i-1][j])+(2**(i+j)) else : dp[i][j]=max(dp[i][j-1],dp[i-1][j]) return dp[n-1][n-1] if __name__=='__main__' : mat=[[1,1,0,1],[0,1,1,0],[1,0,0,1],[1,0,1,1]] print(MaximumDecimalValue(mat,4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 4 ; skip ; if __name__ = '__main__' then ( mat := Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 1 })))}->union(Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 0 })))}->union(Sequence{Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 1 })))}->union(Sequence{ Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 1 }))) }))) ; execute (MaximumDecimalValue(mat, 4))->display() ) else skip; operation MaximumDecimalValue(mat : OclAny, n : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)))) ; if (mat->first()->first() = 1) then ( dp->first()->first() := 1 ) else skip ; for i : Integer.subrange(1, n-1) do ( if (mat->first()[i+1] = 1) then ( dp->first()[i+1] := dp->first()[i - 1+1] + (2)->pow(i) ) else ( dp->first()[i+1] := dp->first()[i - 1+1] )) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name mat)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) == (comparison (expr (atom (number (integer 1))))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) + (expr (expr (atom (number (integer 2)))) ** (expr (atom (name i)))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))))))))))) ; for i : Integer.subrange(1, n-1) do ( for j : Integer.subrange(1, n-1) do ( if (mat[i+1][j+1] = 1) then ( dp[i+1][j+1] := Set{dp[i+1][j - 1+1], dp[i - 1+1][j+1]}->max() + ((2)->pow((i + j))) ) else ( dp[i+1][j+1] := Set{dp[i+1][j - 1+1], dp[i - 1+1][j+1]}->max() ))) ; return dp[n - 1+1][n - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def createHash(hash1,maxElement): prev,curr=0,1 hash1.add(prev) hash1.add(curr) while(currcompareTo(maxElement)) < 0) do ( var temp : OclAny := curr + prev ; execute ((temp) : hash1) ; var prev : OclAny := curr ; var curr : OclAny := temp); operation findFibonacciPair(n : OclAny) pre: true post: true activity: hash1 := Set{}->union(()) ; createHash(hash1, n) ; for i : Integer.subrange(0, n-1) do ( if ((hash1)->includes(i) & (hash1)->includes((n - i))) then ( execute (i)->display() ; return ) else skip) ; execute ("-1")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countgroup(a,n): xs=0 for i in range(n): xs=xs ^ a[i] if xs==0 : return(1<<(n-1))-1 return 0 a=[1,2,3] n=len(a) print(countgroup(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; n := (a)->size() ; execute (countgroup(a, n))->display(); operation countgroup(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var xs : int := 0 ; for i : Integer.subrange(0, n-1) do ( xs := MathLib.bitwiseXor(xs, a[i+1])) ; if xs = 0 then ( return (1 * (2->pow((n - 1)))) - 1 ) else skip ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N=int(input()) X1,X2=[int(i)for i in input().split()] X1+=0.00000001 X2-=0.00000001 retas=[] for n in range(N): retas.append([int(i)for i in input().split()]) B1={} B2={} for n in range(N): k=retas[n][0] b=retas[n][1] B1[k*X1+b]=n B2[k*X2+b]=n L1=list(B1.keys()) L2=list(B2.keys()) L1.sort() L2.sort() flag=True for n in range(N): if B1[L1[n]]!=B2[L2[n]]: flag=False break if not flag : print("YES") else : print("NO") main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var X1 : OclAny := null; var X2 : OclAny := null; Sequence{X1,X2} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; X1 := X1 + 0.00000001 ; X2 := X2 - 0.00000001 ; var retas : Sequence := Sequence{} ; for n : Integer.subrange(0, N-1) do ( execute ((input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))) : retas)) ; var B1 : OclAny := Set{} ; var B2 : OclAny := Set{} ; for n : Integer.subrange(0, N-1) do ( var k : OclAny := retas[n+1]->first() ; var b : OclAny := retas[n+1][1+1] ; B1[k * X1 + b+1] := n ; B2[k * X2 + b+1] := n) ; var L1 : Sequence := (B1.keys()) ; var L2 : Sequence := (B2.keys()) ; L1 := L1->sort() ; L2 := L2->sort() ; var flag : boolean := true ; for n : Integer.subrange(0, N-1) do ( if B1[L1[n+1]+1] /= B2[L2[n+1]+1] then ( flag := false ; break ) else skip) ; if not(flag) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def modInverse(a,m): a=a % m ; for x in range(1,m): if((a*x)% m==1): return x return 1 a=3 m=11 print(modInverse(a,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 3 ; m := 11 ; execute (modInverse(a, m))->display(); operation modInverse(a : OclAny, m : OclAny) : OclAny pre: true post: true activity: a := a mod m; ; for x : Integer.subrange(1, m-1) do ( if ((a * x) mod m = 1) then ( return x ) else skip) ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : a,en,b=input().split() if en=='?' : break else : a=int(a) b=int(b) if en=='+' : print(a+b) elif en=='-' : print(a-b) elif en=='*' : print(a*b) elif en=='/' : print(int(a/b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var a : OclAny := null; var en : OclAny := null; var b : OclAny := null; Sequence{a,en,b} := input().split() ; if en = '?' then ( break ) else ( var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; if en = '+' then ( execute (a + b)->display() ) else (if en = '-' then ( execute (a - b)->display() ) else (if en = '*' then ( execute (a * b)->display() ) else (if en = '/' then ( execute (("" + ((a / b)))->toInteger())->display() ) else skip ) ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def maxLength(s,n): ans=-(sys.maxsize+1); A,L,R=[],[],[]; freq=[0]*(n+5); for i in range(26): count=0 ; for j in range(n): if(ord(s[j])-ord('a')==i): count+=1 ; freq[j]=count ; for j in range(n): L.append((2*freq[j-1])-j); R.append((2*freq[j])-j); max_len=-(sys.maxsize+1); min_val=sys.maxsize ; for j in range(n): min_val=min(min_val,L[j]); A.append(min_val); l=0 ; r=j ; while(l<=r): mid=(l+r)>>1 ; if(A[mid]<=R[j]): max_len=max(max_len,j-mid+1); r=mid-1 ; else : l=mid+1 ; ans=max(ans,max_len); A.clear(); R.clear(); L.clear(); return ans ; if __name__=="__main__" : s="ababbbacbcbcca" ; n=len(s); print(maxLength(s,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( s := "ababbbacbcbcca"; ; n := (s)->size(); ; execute (maxLength(s, n))->display(); ) else skip; operation maxLength(s : OclAny, n : OclAny) pre: true post: true activity: var ans : (trailer . (name maxsize)) := -((trailer . (name maxsize)) + 1); ; var A : OclAny := null; var L : OclAny := null; var R : OclAny := null; Sequence{A,L,R} := Sequence{Sequence{},Sequence{},Sequence{}}; ; var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 5)); ; for i : Integer.subrange(0, 26-1) do ( var count : int := 0; ; for j : Integer.subrange(0, n-1) do ( if ((s[j+1])->char2byte() - ('a')->char2byte() = i) then ( count := count + 1; ) else skip ; freq[j+1] := count;) ; for j : Integer.subrange(0, n-1) do ( execute (((2 * freq[j - 1+1]) - j) : L); ; execute (((2 * freq[j+1]) - j) : R);) ; var max_len : (trailer . (name maxsize)) := -((trailer . (name maxsize)) + 1); ; var min_val : (trailer . (name maxsize)) := (trailer . (name maxsize)); ; for j : Integer.subrange(0, n-1) do ( min_val := Set{min_val, L[j+1]}->min(); ; execute ((min_val) : A); ; var l : int := 0; var r : OclAny := j; ; while ((l->compareTo(r)) <= 0) do ( var mid : int := (l + r) /(2->pow(1)); ; if ((A[mid+1]->compareTo(R[j+1])) <= 0) then ( max_len := Set{max_len, j - mid + 1}->max(); ; r := mid - 1; ) else ( l := mid + 1; ))) ; ans := Set{ans, max_len}->max(); ; execute (A /<: A); ; execute (R /<: R); ; execute (L /<: L);) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=100005 gr=[[]for i in range(N)] colour=[-1]*N edges=[] bip=True def add_edge(x,y): gr[x].append(y) gr[y].append(x) edges.append((x,y)) def dfs(x,col): colour[x]=col global bip for i in gr[x]: if colour[i]==-1 : dfs(i,col ^ 1) elif colour[i]==col : bip=False def Directed_Graph(n,m): dfs(1,1) if not bip : print(-1) return for i in range(0,m): if colour[edges[i][0]]==0 : edges[i][0],edges[i][1]=edges[i][1],edges[i][0] print(edges[i][0],edges[i][1]) if __name__=="__main__" : n,m=4,3 add_edge(1,2) add_edge(1,3) add_edge(1,4) Directed_Graph(n,m) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute bip : OclAny; operation initialise() pre: true post: true activity: var N : int := 100005 ; var gr : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{})) ; var colour : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, N) ; var edges : Sequence := Sequence{} ; var bip : boolean := true ; skip ; skip ; skip ; if __name__ = "__main__" then ( Sequence{n,m} := Sequence{4,3} ; add_edge(1, 2) ; add_edge(1, 3) ; add_edge(1, 4) ; Directed_Graph(n, m) ) else skip; operation add_edge(x : OclAny, y : OclAny) pre: true post: true activity: (expr (atom (name gr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))) ; (expr (atom (name gr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) ; execute ((Sequence{x, y}) : edges); operation dfs(x : OclAny, col : OclAny) pre: true post: true activity: colour[x+1] := col ; skip ; for i : gr[x+1] do ( if colour[i+1] = -1 then ( dfs(i, MathLib.bitwiseXor(col, 1)) ) else (if colour[i+1] = col then ( bip := false ) else skip)); operation Directed_Graph(n : OclAny, m : OclAny) pre: true post: true activity: dfs(1, 1) ; if not(bip) then ( execute (-1)->display() ; return ) else skip ; for i : Integer.subrange(0, m-1) do ( if colour[edges[i+1]->first()+1] = 0 then ( var edges[i+1]->first() : OclAny := null; var edges[i+1][1+1] : OclAny := null; Sequence{edges[i+1]->first(),edges[i+1][1+1]} := Sequence{edges[i+1][1+1],edges[i+1]->first()} ) else skip ; execute (edges[i+1]->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() l=list(map(int,input().split())) s=set(l) if any(i % 2==0 for i in s)and any(i % 2!=0 for i in s): l.sort() print(*l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Set := Set{}->union((l)) ; if ((argument (test (logical_test (comparison (comparison (expr (expr (atom (name i))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name s))))))))->exists( _x | _x = true ) & ((argument (test (logical_test (comparison (comparison (expr (expr (atom (name i))) % (expr (atom (number (integer 2)))))) != (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name s))))))))->exists( _x | _x = true ) then ( l := l->sort() ) else skip ; execute ((argument * (test (logical_test (comparison (expr (atom (name l))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) odd=even=0 for i in a : if i & 1 : odd+=1 else : even+=1 if even and odd : a.sort() print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var odd : OclAny := 0; var even : int := 0 ; for i : a do ( if MathLib.bitwiseAnd(i, 1) then ( odd := odd + 1 ) else ( even := even + 1 )) ; if even & odd then ( a := a->sort() ) else skip ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) a=list(map(int,input().split())) s=0 for i in a : s+=i % 2 if s and s ^ n : a.sort() ans=a sys.stdout.write(" ".join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : int := 0 ; for i : a do ( s := s + i mod 2) ; if s & MathLib.bitwiseXor(s, n) then ( a := a->sort() ) else skip ; var ans : Sequence := a ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " ") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d,e=map(int,input().split()) if a==0 : print(1) elif b==0 : print(2) elif c==0 : print(3) elif d==0 : print(4) elif e==0 : print(5) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; Sequence{a,b,c,d,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 0 then ( execute (1)->display() ) else (if b = 0 then ( execute (2)->display() ) else (if c = 0 then ( execute (3)->display() ) else (if d = 0 then ( execute (4)->display() ) else (if e = 0 then ( execute (5)->display() ) else skip ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout import sys def get_ints(): return map(int,sys.stdin.readline().strip().split()) def get_arr(): return list(map(int,sys.stdin.readline().strip().split())) def get_string(): return sys.stdin.readline().strip() n=int(input()) a=get_arr() cntodd=0 cnteven=0 for i in range(0,len(a)): if a[i]% 2==0 : cnteven+=1 else : cntodd+=1 if cntodd==0 or cnteven==0 : for i in range(0,len(a)): print(a[i],end=" ") else : a.sort() for i in range(0,len(a)): print(a[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := get_arr() ; var cntodd : int := 0 ; var cnteven : int := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( if a[i+1] mod 2 = 0 then ( cnteven := cnteven + 1 ) else ( cntodd := cntodd + 1 )) ; if cntodd = 0 or cnteven = 0 then ( for i : Integer.subrange(0, (a)->size()-1) do ( execute (a[i+1])->display()) ) else ( a := a->sort() ; for i : Integer.subrange(0, (a)->size()-1) do ( execute (a[i+1])->display()) ); operation get_ints() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ); operation get_arr() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation get_string() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) o,e=0,0 for i in arr : if i % 2==0 : o+=1 else : e+=1 if o!=0 and e!=0 : arr.sort() for i in arr : print(i,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var o : OclAny := null; var e : OclAny := null; Sequence{o,e} := Sequence{0,0} ; for i : arr do ( if i mod 2 = 0 then ( o := o + 1 ) else ( e := e + 1 )) ; if o /= 0 & e /= 0 then ( arr := arr->sort() ) else skip ; for i : arr do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k,n,w=map(int,input().strip().split()) sum=0 for i in range(1,w+1): sum+=k*i if sum<=n : print(0) else : print(sum-n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : OclAny := null; var n : OclAny := null; var w : OclAny := null; Sequence{k,n,w} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sum : int := 0 ; for i : Integer.subrange(1, w + 1-1) do ( sum := sum + k * i) ; if (sum->compareTo(n)) <= 0 then ( execute (0)->display() ) else ( execute (sum - n)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- arr=input().split(" ") k=int(arr[0]) n=int(arr[1]) w=int(arr[2]) cost=k*(w)*(w+1)/2 if cost>n : print(int(cost-n)) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var arr : OclAny := input().split(" ") ; var k : int := ("" + ((arr->first())))->toInteger() ; var n : int := ("" + ((arr[1+1])))->toInteger() ; var w : int := ("" + ((arr[2+1])))->toInteger() ; var cost : double := k * (w) * (w + 1) / 2 ; if (cost->compareTo(n)) > 0 then ( execute (("" + ((cost - n)))->toInteger())->display() ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() while '?' not in s.split()[1]: print(eval(''.join(s.replace('/','//')))) s=input() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; while (s.split()[1+1])->excludes('?') do ( execute (StringLib.sumStringsWithSeparator((s.replace('/', '//')), ''))->display() ; s := (OclFile["System.in"]).readLine()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k,n,w=input().split() if 1<=int(k)and int(w)<=1000 : total=0 for i in range(1,int(w)+1): total+=i*int(k) if total>int(n): print(total-int(n)) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : OclAny := null; var n : OclAny := null; var w : OclAny := null; Sequence{k,n,w} := input().split() ; if 1 <= ("" + ((k)))->toInteger() & ("" + ((w)))->toInteger() <= 1000 then ( var total : int := 0 ; for i : Integer.subrange(1, ("" + ((w)))->toInteger() + 1-1) do ( total := total + i * ("" + ((k)))->toInteger()) ; if (total->compareTo(("" + ((n)))->toInteger())) > 0 then ( execute (total - ("" + ((n)))->toInteger())->display() ) else ( execute (0)->display() ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k,n,w=map(int,input().split()) price_of_banana=0 for i in range(1,w+1): price_of_banana+=i*k if n>=price_of_banana : print(0) else : print(price_of_banana-n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : OclAny := null; var n : OclAny := null; var w : OclAny := null; Sequence{k,n,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var price_of_banana : int := 0 ; for i : Integer.subrange(1, w + 1-1) do ( price_of_banana := price_of_banana + i * k) ; if (n->compareTo(price_of_banana)) >= 0 then ( execute (0)->display() ) else ( execute (price_of_banana - n)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[int(x)for x in input().split()] w=(a[2]*(a[2]+1))//2 w=w*a[0]; if(a[1]>w): print(0) else : print(w-a[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var w : int := (a[2+1] * (a[2+1] + 1)) div 2 ; w := w * a->first(); ; if ((a[1+1]->compareTo(w)) > 0) then ( execute (0)->display() ) else ( execute (w - a[1+1])->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPrime(k): if(k<=1): return False for i in range(2,k): if(k % i==0): return false return True def check(num,k): flag=1 for i in range(2,k): if(num % i==0): flag=0 if(flag==1): if(num % k==0): return 1 else : return 0 else : return 0 def findCount(a,b,k): count=0 if(not isPrime(k)): return 0 else : for i in range(a,b+1): ans=check(i,k) if(ans==1): count+=1 else : continue return count if __name__=="__main__" : a=2020 b=6300 k=29 print(findCount(a,b,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( a := 2020 ; b := 6300 ; k := 29 ; execute (findCount(a, b, k))->display() ) else skip; operation isPrime(k : OclAny) : OclAny pre: true post: true activity: if (k <= 1) then ( return false ) else skip ; for i : Integer.subrange(2, k-1) do ( if (k mod i = 0) then ( return false ) else skip) ; return true; operation check(num : OclAny, k : OclAny) : OclAny pre: true post: true activity: var flag : int := 1 ; for i : Integer.subrange(2, k-1) do ( if (num mod i = 0) then ( flag := 0 ) else skip) ; if (flag = 1) then ( if (num mod k = 0) then ( return 1 ) else ( return 0 ) ) else ( return 0 ); operation findCount(a : OclAny, b : OclAny, k : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; if (not(isPrime(k))) then ( return 0 ) else ( for i : Integer.subrange(a, b + 1-1) do ( var ans : OclAny := check(i, k) ; if (ans = 1) then ( count := count + 1 ) else ( continue )) ) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B,C,D=map(int,input().split()) m=998244353 d=[[0]*(D+1)for _ in range(C+1)] d[A][B]=1 for i in range(A,C+1): for j in range(B,D+1): d[i][j]+=(d[i][j-1]*i+d[i-1][j]*j-d[i-1][j-1]*(i-1)*(j-1))% m print(d[C][D]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var D : OclAny := null; Sequence{A,B,C,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : int := 998244353 ; var d : Sequence := Integer.subrange(0, C + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (D + 1)))) ; d[A+1][B+1] := 1 ; for i : Integer.subrange(A, C + 1-1) do ( for j : Integer.subrange(B, D + 1-1) do ( d[i+1][j+1] := d[i+1][j+1] + (d[i+1][j - 1+1] * i + d[i - 1+1][j+1] * j - d[i - 1+1][j - 1+1] * (i - 1) * (j - 1)) mod m)) ; execute (d[C+1][D+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import collections import bisect a,b,c,d=map(int,input().split()) dp0=[[1 for i in range(d+1)]for j in range(c+1)] dp1=[[0 for i in range(d+1)]for j in range(c+1)] for i in range(c+1): for j in range(d+1): if jcollect( _x | (OclType["int"])->apply(_x) ) ; var dp0 : Sequence := Integer.subrange(0, c + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, d + 1-1)->select(i | true)->collect(i | (1)))) ; var dp1 : Sequence := Integer.subrange(0, c + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, d + 1-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, c + 1-1) do ( for j : Integer.subrange(0, d + 1-1) do ( if (j->compareTo(b)) < 0 or (i->compareTo(a)) < 0 then ( dp0[i+1][j+1] := 0 ; dp1[i+1][j+1] := 0 ) else skip)) ; for i : Integer.subrange(a, c + 1-1) do ( for j : Integer.subrange(b, d + 1-1) do ( if a = i & b = j then ( continue ) else skip ; dp0[i+1][j+1] := ((i * dp0[i+1][j - 1+1]) mod 998244353 + dp1[i+1][j - 1+1]) mod 998244353 ; dp1[i+1][j+1] := (j * (dp0[i - 1+1][j+1] + dp1[i - 1+1][j+1]) mod 998244353) mod 998244353)) ; execute ((dp0[c+1][d+1] + dp1[c+1][d+1]) mod 998244353)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): A=list(map(int,input().split())) for i in range(5): if A[i]!=i+1 : return i+1 print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (main())->display(); operation main() : OclAny pre: true post: true activity: var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, 5-1) do ( if A[i+1] /= i + 1 then ( return i + 1 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=998244353 A,B,C,D=map(int,input().split()) dp=[[0 for _ in range(D+1)]for _ in range(C+1)] dp[A][B]=1 for i in range(A,C+1): for j in range(B,D+1): if i>A : dp[i][j]+=j*dp[i-1][j] if j>B : dp[i][j]+=i*dp[i][j-1] if i>A and j>B : dp[i][j]-=(i-1)*(j-1)*dp[i-1][j-1] dp[i][j]%=MOD print(dp[C][D]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : int := 998244353 ; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var D : OclAny := null; Sequence{A,B,C,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dp : Sequence := Integer.subrange(0, C + 1-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, D + 1-1)->select(_anon | true)->collect(_anon | (0)))) ; dp[A+1][B+1] := 1 ; for i : Integer.subrange(A, C + 1-1) do ( for j : Integer.subrange(B, D + 1-1) do ( if (i->compareTo(A)) > 0 then ( dp[i+1][j+1] := dp[i+1][j+1] + j * dp[i - 1+1][j+1] ) else skip ; if (j->compareTo(B)) > 0 then ( dp[i+1][j+1] := dp[i+1][j+1] + i * dp[i+1][j - 1+1] ) else skip ; if (i->compareTo(A)) > 0 & (j->compareTo(B)) > 0 then ( dp[i+1][j+1] := dp[i+1][j+1] - (i - 1) * (j - 1) * dp[i - 1+1][j - 1+1] ) else skip ; dp[i+1][j+1] := dp[i+1][j+1] mod MOD)) ; execute (dp[C+1][D+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**8) input=sys.stdin.readline def main(): A,B,C,D=[int(x)for x in input().split()] MOD=998244353 dp=[[0]*(D-B+1)for j in range(C-A+1)] for j in range(C-A+1): if j==0 : dp[j][0]=1 else : dp[j][0]=pow(B,j,MOD) for i in range(1,D-B+1): if j==0 : dp[j][i]=dp[j][i-1]*(A+j)% MOD else : dp[j][i]=(dp[j][i-1]*(A+j)+(B+i)*dp[j-1][i]-dp[j-1][i-1]*((A+j-1)*(B+i-1)))% MOD print(dp[-1][-1]% MOD) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(8)) ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var D : OclAny := null; Sequence{A,B,C,D} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var MOD : int := 998244353 ; var dp : Sequence := Integer.subrange(0, C - A + 1-1)->select(j | true)->collect(j | (MatrixLib.elementwiseMult(Sequence{ 0 }, (D - B + 1)))) ; for j : Integer.subrange(0, C - A + 1-1) do ( if j = 0 then ( dp[j+1]->first() := 1 ) else ( dp[j+1]->first() := (B)->pow(j) ) ; for i : Integer.subrange(1, D - B + 1-1) do ( if j = 0 then ( dp[j+1][i+1] := dp[j+1][i - 1+1] * (A + j) mod MOD ) else ( dp[j+1][i+1] := (dp[j+1][i - 1+1] * (A + j) + (B + i) * dp[j - 1+1][i+1] - dp[j - 1+1][i - 1+1] * ((A + j - 1) * (B + i - 1))) mod MOD ))) ; execute (dp->last()->last() mod MOD)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys MOD=998244353 def main(A,B,C,D): I,J=C-A,D-B dp=[[0]*(I+1)for _ in range(I+J+1)] dp[0][0]=1 for k in range(1,I+J+1): for i in range(min(I,k)+1): j=k-i v=dp[k-1][i-1]*(j+B)% MOD if i>=1 else 0 h=dp[k-1][i]*(i+A)% MOD d=dp[k-2][i-1]*(i+A-1)*(j+B-1)if k>=2 and i>=1 else 0 dp[k][i]=(v+h-d)% MOD print(dp[I+J][I]) if __name__=='__main__' : input=sys.stdin.readline A,B,C,D=map(int,input().split()) main(A,B,C,D) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MOD : int := 998244353 ; skip ; if __name__ = '__main__' then ( var input : OclAny := (OclFile["System.in"]).readline ; Sequence{A,B,C,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; main(A, B, C, D) ) else skip; operation main(A : OclAny, B : OclAny, C : OclAny, D : OclAny) pre: true post: true activity: var I : OclAny := null; var J : OclAny := null; Sequence{I,J} := Sequence{C - A,D - B} ; var dp : Sequence := Integer.subrange(0, I + J + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (I + 1)))) ; dp->first()->first() := 1 ; for k : Integer.subrange(1, I + J + 1-1) do ( for i : Integer.subrange(0, Set{I, k}->min() + 1-1) do ( var j : double := k - i ; var v : int := if i >= 1 then dp[k - 1+1][i - 1+1] * (j + B) mod MOD else 0 endif ; var h : int := dp[k - 1+1][i+1] * (i + A) mod MOD ; var d : double := if k >= 2 & i >= 1 then dp[k - 2+1][i - 1+1] * (i + A - 1) * (j + B - 1) else 0 endif ; dp[k+1][i+1] := (v + h - d) mod MOD)) ; execute (dp[I + J+1][I+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for test in range(t): s1,s2,s3,s4=map(int,input().split()) ability=[s1,s2,s3,s4] max1=max(ability) ability.remove(max1) max2=max(ability) team1=[s1,s2] team2=[s3,s4] if max1 in team1 and max2 in team2 : print('YES') elif max1 in team2 and max2 in team1 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for test : Integer.subrange(0, t-1) do ( var s1 : OclAny := null; var s2 : OclAny := null; var s3 : OclAny := null; var s4 : OclAny := null; Sequence{s1,s2,s3,s4} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ability : Sequence := Sequence{s1}->union(Sequence{s2}->union(Sequence{s3}->union(Sequence{ s4 }))) ; var max1 : OclAny := (ability)->max() ; execute ((max1) /: ability) ; var max2 : OclAny := (ability)->max() ; var team1 : Sequence := Sequence{s1}->union(Sequence{ s2 }) ; var team2 : Sequence := Sequence{s3}->union(Sequence{ s4 }) ; if (team1)->includes(max1) & (team2)->includes(max2) then ( execute ('YES')->display() ) else (if (team2)->includes(max1) & (team1)->includes(max2) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,queue,math,copy,itertools,bisect,collections,heapq sys.setrecursionlimit(10**7) INF=10**3 MOD=10**9+7 LI=lambda :[int(x)for x in sys.stdin.readline().split()] NI=lambda : int(sys.stdin.readline()) N=NI() red=[LI()for _ in range(N)] blue=[LI()for _ in range(N)] red.sort(key=lambda x : x[1],reverse=True) blue.sort() ans=0 for bx,by in blue : for i in range(N): if bx>red[i][0]and by>red[i][1]: ans+=1 red[i][0]=INF break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var INF : double := (10)->pow(3) ; var MOD : double := (10)->pow(9) + 7 ; var LI : Function := lambda $$ : OclAny in (sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) ; var NI : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var N : OclAny := NI->apply() ; var red : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (LI->apply())) ; var blue : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (LI->apply())) ; red := red->sort() ; blue := blue->sort() ; var ans : int := 0 ; for _tuple : blue do (var _indx : int := 1; var bx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var by : OclAny := _tuple->at(_indx); for i : Integer.subrange(0, N-1) do ( if (bx->compareTo(red[i+1]->first())) > 0 & (by->compareTo(red[i+1][1+1])) > 0 then ( ans := ans + 1 ; red[i+1]->first() := INF ; break ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) red={} for _ in range(n): x,y=map(int,input().split()) if x in red : red[x].append(y) else : red[x]=[y] blue={} for _ in range(n): x,y=map(int,input().split()) if x in blue : blue[x].append(y) else : blue[x]=[y] blueOption=[2*n+1,[]] cnt=0 for i in range(2*n+1): border=2*n-i blueOption[0]=border if border in blue : blueOption[1]+=blue[border] blueOption[1].sort() if border in red : redTemp=red[border] redTemp.sort(reverse=True) for item in redTemp : for blueItem in blueOption[1]: if itemtoInteger() ; var red : OclAny := Set{} ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (red)->includes(x) then ( (expr (atom (name red)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))) ) else ( red[x+1] := Sequence{ y } )) ; var blue : OclAny := Set{} ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (blue)->includes(x) then ( (expr (atom (name blue)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))) ) else ( blue[x+1] := Sequence{ y } )) ; var blueOption : Sequence := Sequence{2 * n + 1}->union(Sequence{ Sequence{} }) ; var cnt : int := 0 ; for i : Integer.subrange(0, 2 * n + 1-1) do ( var border : double := 2 * n - i ; blueOption->first() := border ; if (blue)->includes(border) then ( blueOption[1+1] := blueOption[1+1] + blue[border+1] ; (expr (atom (name blueOption)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer . (name sort) (arguments ( )))) ) else skip ; if (red)->includes(border) then ( var redTemp : OclAny := red[border+1] ; redTemp := redTemp->sort() ; for item : redTemp do ( for blueItem : blueOption[1+1] do ( if (item->compareTo(blueItem)) < 0 then ( cnt := cnt + 1 ; (expr (atom (name blueOption)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer . (name remove) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name blueItem)))))))) )))) ; break ) else skip)) ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) R=[[int(i)for i in input().split()]for i in range(N)] B=[[int(i)for i in input().split()]for i in range(N)] List=[[]for i in range(N)] count=[0]*N unpaired=[True]*N for i,r in enumerate(R): for j,b in enumerate(B): if b[0]>r[0]and b[1]>r[1]: List[i].append(j) count[j]+=1 List.sort(key=lambda x : len(x)) ans=0 for l in List : k=float("inf") p=-1 for j in l : if unpaired[j]: if k>count[j]: k=count[j] p=j count[j]-=1 if p>=0 : ans+=1 unpaired[p]=False print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var R : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())))) ; var B : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())))) ; var List : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{})) ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var unpaired : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, N) ; for _tuple : Integer.subrange(1, (R)->size())->collect( _indx | Sequence{_indx-1, (R)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var r : OclAny := _tuple->at(_indx); for _tuple : Integer.subrange(1, (B)->size())->collect( _indx | Sequence{_indx-1, (B)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if (b->first()->compareTo(r->first())) > 0 & (b[1+1]->compareTo(r[1+1])) > 0 then ( (expr (atom (name List)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) ; count[j+1] := count[j+1] + 1 ) else skip)) ; List := List->sort() ; var ans : int := 0 ; for l : List do ( var k : double := ("" + (("inf")))->toReal() ; var p : int := -1 ; for j : l do ( if unpaired[j+1] then ( if (k->compareTo(count[j+1])) > 0 then ( k := count[j+1] ; p := j ) else skip ; count[j+1] := count[j+1] - 1 ) else skip) ; if p >= 0 then ( ans := ans + 1 ; unpaired[p+1] := false ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def read_values(): return map(int,input().split()) def read_list(): return list(read_values()) def func(N,mod): F=[1] for i in range(1,N+1): F.append(F[-1]*i % mod) return F def inv(a,mod): return pow(a,mod-2,mod) def C(F,a,b,mod): return F[a]*inv(F[b],mod)*inv(F[a-b],mod)% mod def main(): N=int(input()) R=[tuple(read_values())for _ in range(N)] B=[tuple(read_values())for _ in range(N)] B.sort() res=0 paired=[False]*N for bx,by in B : t=-1 for i,(rx,ry)in enumerate(R): if paired[i]: continue if rxcollect( _x | (OclType["int"])->apply(_x) ); operation read_list() : OclAny pre: true post: true activity: return (read_values()); operation func(N : OclAny, mod : OclAny) : OclAny pre: true post: true activity: var F : Sequence := Sequence{ 1 } ; for i : Integer.subrange(1, N + 1-1) do ( execute ((F->last() * i mod mod) : F)) ; return F; operation inv(a : OclAny, mod : OclAny) : OclAny pre: true post: true activity: return (a)->pow(mod - 2); operation C(F : OclAny, a : OclAny, b : OclAny, mod : OclAny) : OclAny pre: true post: true activity: return F[a+1] * inv(F[b+1], mod) * inv(F[a - b+1], mod) mod mod; operation main() pre: true post: true activity: N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var R : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | ((read_values()))) ; var B : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | ((read_values()))) ; B := B->sort() ; var res : int := 0 ; var paired : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, N) ; for _tuple : B do (var _indx : int := 1; var bx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var by : OclAny := _tuple->at(_indx); var t : int := -1 ; for _tuple : Integer.subrange(1, (R)->size())->collect( _indx | Sequence{_indx-1, (R)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{rx, ry} : OclAny := _tuple->at(_indx); if paired[i+1] then ( continue ) else skip ; if (rx->compareTo(bx)) < 0 & (ry->compareTo(by)) < 0 then ( if t = -1 or (R[t+1][1+1]->compareTo(ry)) < 0 then ( t := i ) else skip ) else skip) ; if t /= -1 then ( res := res + 1 ; paired[t+1] := true ) else skip) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect,collections,copy,heapq,itertools,math,string,sys input=lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF=float('inf') def I(): return int(input()) def F(): return float(input()) def SS(): 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 LSS(): return input().split() def resolve(): N=I() ab=[LI()for _ in range(N)] cd=[LI()for _ in range(N)] ab.sort() ab_used=collections.OrderedDict() for i in ab : ab_used[tuple(i)]=False cd.sort() ans=0 for c,d in cd : m=-1 m_ab=(-1,-1) for a,b in ab : if a>c : break if not ab_used[(a,b)]and d>b>m : m=b m_ab=(a,b) if m_ab!=(-1,-1): ab_used[m_ab]=True ans+=1 print(ans) if __name__=='__main__' : resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; sys.setrecursionlimit((10)->pow(7)) ; var INF : double := ("" + (('inf')))->toReal() ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( resolve() ) else skip; operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation SS() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation LI() : OclAny pre: true post: true activity: return input->apply().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return input->apply().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return input->apply().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LSS() : OclAny pre: true post: true activity: return input->apply().split(); operation resolve() pre: true post: true activity: var N : OclAny := I() ; var ab : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (LI())) ; var cd : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (LI())) ; ab := ab->sort() ; var ab_used : Map := () ; for i : ab do ( ab_used->restrict((i)) := false) ; cd := cd->sort() ; var ans : int := 0 ; for _tuple : cd do (var _indx : int := 1; var c : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); var m : int := -1 ; var m_ab : OclAny := Sequence{-1, -1} ; for _tuple : ab do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if (a->compareTo(c)) > 0 then ( break ) else skip ; if not(ab_used[Sequence{a, b}+1]) & (d->compareTo(b)) > 0 & (b > m) then ( m := b ; m_ab := Sequence{a, b} ) else skip) ; if m_ab /= Sequence{-1, -1} then ( ab_used[m_ab+1] := true ; ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a='abcdefghijklmnopqrstuvwxyz' n,k=map(int,input().split()); t=a[: 2]*n if k>n or(k==1 and n!=1): print(-1) elif n==1 : print('a') else : print(t[: n-k+2]+a[2 : k]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := 'abcdefghijklmnopqrstuvwxyz' ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var t : double := a.subrange(1,2) * n ; if (k->compareTo(n)) > 0 or (k = 1 & n /= 1) then ( execute (-1)->display() ) else (if n = 1 then ( execute ('a')->display() ) else ( execute (t.subrange(1,n - k + 2) + a.subrange(2+1, k))->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(i)for i in input().split()] if m>n or(m==1 and n>1): print(-1) else : k=(n-m+2)//2*'ab'+(n-m)% 2*'a' for i in range(m-2): k+=chr(i+ord('c')) if n==1 and m==1 : k='a' print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if (m->compareTo(n)) > 0 or (m = 1 & n > 1) then ( execute (-1)->display() ) else ( var k : double := (n - m + 2) div 2 * 'ab' + (n - m) mod 2 * 'a' ; for i : Integer.subrange(0, m - 2-1) do ( k := k + (i + ('c')->char2byte())->byte2char()) ; if n = 1 & m = 1 then ( k := 'a' ) else skip ; execute (k)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) root=int(n**(1/2))+1 isPrime=[True]*(n+3) for i in range(4,n+3,2): isPrime[i]=False ans=0 prePrime=-1 for i in range(3,n+3,2): if isPrime[i]: if prePrime+2==i : ans+=2 prePrime=i if i>root : continue for j in range(i*i,n+3,i): isPrime[j]=False print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var root : int := ("" + (((n)->pow((1 / 2)))))->toInteger() + 1 ; var isPrime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (n + 3)) ; for i : Integer.subrange(4, n + 3-1)->select( $x | ($x - 4) mod 2 = 0 ) do ( isPrime[i+1] := false) ; var ans : int := 0 ; var prePrime : int := -1 ; for i : Integer.subrange(3, n + 3-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if isPrime[i+1] then ( if prePrime + 2 = i then ( ans := ans + 2 ) else skip ; prePrime := i ; if (i->compareTo(root)) > 0 then ( continue ) else skip ; for j : Integer.subrange(i * i, n + 3-1)->select( $x | ($x - i * i) mod i = 0 ) do ( isPrime[j+1] := false) ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(i)for i in input().split()] if m>n or(m==1 and n>1): print(-1) else : k=(n-m+2)//2*'ab'+(n-m)% 2*'a' for i in range(m-2): k+=chr(i+ord('c')) if n==1 and m==1 : k='a' print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if (m->compareTo(n)) > 0 or (m = 1 & n > 1) then ( execute (-1)->display() ) else ( var k : double := (n - m + 2) div 2 * 'ab' + (n - m) mod 2 * 'a' ; for i : Integer.subrange(0, m - 2-1) do ( k := k + (i + ('c')->char2byte())->byte2char()) ; if n = 1 & m = 1 then ( k := 'a' ) else skip ; execute (k)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter from sys import stdin,stdout from heapq import nlargest,nsmallest def outnl(x): stdout.write(str(x)+'\n') def outsl(x): stdout.write(str(x)+'') def instr(): return stdin.readline().strip() def inint(): return int(stdin.readline()) def inspsint(): return map(int,stdin.readline().strip().split()) def inlist(): return list(map(int,stdin.readline().strip().split())) for _ in range(1): n,x=inspsint() if x>n or(x==1 and n>1): outnl(-1) continue if(n==1): outnl('a') continue l=n-x+2 for i in range(l): if i % 2==0 : outsl('a') else : outsl('b') c=99 for i in range(n-l): outsl(chr(c)) c+=1 print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; for _anon : Integer.subrange(0, 1-1) do ( var n : OclAny := null; Sequence{n,x} := inspsint() ; if (x->compareTo(n)) > 0 or (x = 1 & n > 1) then ( outnl(-1) ; continue ) else skip ; if (n = 1) then ( outnl('a') ; continue ) else skip ; var l : double := n - x + 2 ; for i : Integer.subrange(0, l-1) do ( if i mod 2 = 0 then ( outsl('a') ) else ( outsl('b') )) ; var c : int := 99 ; for i : Integer.subrange(0, n - l-1) do ( outsl((c)->byte2char()) ; c := c + 1) ; execute (->display()); operation outnl(x : OclAny) pre: true post: true activity: stdout.write(("" + ((x))) + ' '); operation outsl(x : OclAny) pre: true post: true activity: stdout.write(("" + ((x))) + ''); operation instr() : OclAny pre: true post: true activity: return stdin.readLine()->trim(); operation inint() : OclAny pre: true post: true activity: return ("" + ((stdin.readLine())))->toInteger(); operation inspsint() : OclAny pre: true post: true activity: return (stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ); operation inlist() : OclAny pre: true post: true activity: return ((stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : value=input().split(" ") a=int(value[0]) b=int(value[2]) op=value[1] if op=="+" : c=a+b print("{0}".format(c)) elif op=="-" : c=a-b print("{0}".format(c)) elif op=="*" : c=a*b print("{0}".format(c)) elif op=="/" : c=int(a/b) print("{0}".format(c)) elif op=="?" : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var value : OclAny := input().split(" ") ; var a : int := ("" + ((value->first())))->toInteger() ; var b : int := ("" + ((value[2+1])))->toInteger() ; var op : OclAny := value[1+1] ; if op = "+" then ( var c : int := a + b ; execute (StringLib.interpolateStrings("{0}", Sequence{c}))->display() ) else (if op = "-" then ( c := a - b ; execute (StringLib.interpolateStrings("{0}", Sequence{c}))->display() ) else (if op = "*" then ( c := a * b ; execute (StringLib.interpolateStrings("{0}", Sequence{c}))->display() ) else (if op = "/" then ( c := ("" + ((a / b)))->toInteger() ; execute (StringLib.interpolateStrings("{0}", Sequence{c}))->display() ) else (if op = "?" then ( break ) else skip ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- global maxn maxn=16 def precompute(): dp=[-1 for i in range(maxn)] dp[0]=0 v=[4,6,9] for i in range(1,maxn,1): for k in range(3): j=v[k] if(i>=j and dp[i-j]!=-1): dp[i]=max(dp[i],dp[i-j]+1) return dp def Maximum_Summands(dp,n): if(ndisplay() ) else skip; operation precompute() : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, maxn-1)->select(i | true)->collect(i | (-1)) ; dp->first() := 0 ; var v : Sequence := Sequence{4}->union(Sequence{6}->union(Sequence{ 9 })) ; for i : Integer.subrange(1, maxn-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( for k : Integer.subrange(0, 3-1) do ( var j : OclAny := v[k+1] ; if ((i->compareTo(j)) >= 0 & dp[i - j+1] /= -1) then ( dp[i+1] := Set{dp[i+1], dp[i - j+1] + 1}->max() ) else skip)) ; return dp; operation Maximum_Summands(dp : OclAny, n : OclAny) : OclAny pre: true post: true activity: if ((n->compareTo(maxn)) < 0) then ( return dp[n+1] ) else ( var t : int := ("" + (((n - maxn) / 4)))->toInteger() + 1 ; return t + dp[n - 4 * t+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSquares(n): return((n*(n+1)/2)*(2*n+1)/3) n=4 print("Count of squares is ",countSquares(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute ("Count of squares is ")->display(); operation countSquares(n : OclAny) : OclAny pre: true post: true activity: return ((n * (n + 1) / 2) * (2 * n + 1) / 3); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict n,m=map(int,input().split()) al=list(map(int,input().split())) modd=defaultdict(int) s=0 for a in al : s+=a s %=m modd[s]+=1 ans=0 for i in modd.values(): ans+=i*(i-1)//2 ans+=modd[0] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var al : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var modd : OclAny := defaultdict(OclType["int"]) ; var s : int := 0 ; for a : al do ( s := s + a ; s := s mod m ; modd[s+1] := modd[s+1] + 1) ; var ans : int := 0 ; for i : modd.values() do ( ans := ans + i * (i - 1) div 2) ; ans := ans + modd->first() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) A=list(map(int,input().split())) Left=[0]*(N+1) for i in range(1,N+1): Left[i]=(Left[i-1]+A[i-1])% M Left=Left[1 :] Left.sort() cnt=[] zero=Left.count(0) Left=Left[zero :] Num=len(Left) for i in range(Num): if i==0 : cnt.append(1) else : if Left[i-1]==Left[i]: cnt[-1]+=1 else : cnt.append(1) res=0 res+=zero+(zero*(zero-1))//2 for c in cnt : if c>1 : res+=(c*(c-1))//2 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var Left : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; for i : Integer.subrange(1, N + 1-1) do ( Left[i+1] := (Left[i - 1+1] + A[i - 1+1]) mod M) ; Left := Left->tail() ; Left := Left->sort() ; var cnt : Sequence := Sequence{} ; var zero : int := Left->count(0) ; Left := Left.subrange(zero+1) ; var Num : int := (Left)->size() ; for i : Integer.subrange(0, Num-1) do ( if i = 0 then ( execute ((1) : cnt) ) else ( if Left[i - 1+1] = Left[i+1] then ( cnt->last() := cnt->last() + 1 ) else ( execute ((1) : cnt) ) )) ; var res : int := 0 ; res := res + zero + (zero * (zero - 1)) div 2 ; for c : cnt do ( if c > 1 then ( res := res + (c * (c - 1)) div 2 ) else skip) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter,deque,OrderedDict,defaultdict import sys sys.setrecursionlimit(10**5+10) def input(): return sys.stdin.readline().strip() def resolve(): n,m=map(int,input().split()) A=list(map(int,input().split())) from itertools import accumulate B=[0]+A B=list(accumulate(B)) for i in range(n+1): B[i]%=m BB=Counter(B) ans=0 for v in BB.values(): ans+=v*(v-1)//2 print(ans) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(5) + 10) ; skip ; skip ; resolve(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation resolve() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; var B : Sequence := Sequence{ 0 }->union(A) ; B := (accumulate(B)) ; for i : Integer.subrange(0, n + 1-1) do ( B[i+1] := B[i+1] mod m) ; var BB : OclAny := Counter(B) ; var ans : int := 0 ; for v : BB.values() do ( ans := ans + v * (v - 1) div 2) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) input=sys.stdin.readline def main(): n,m=map(int,input().split()) a=list(map(int,input().split())) ans=0 a[0]=a[0]% m for i in range(1,n): a[i]+=a[i-1] a[i]%=m a.sort() target=0 cnt=1 for i in a : if i==target : ans+=cnt cnt+=1 else : target=i cnt=1 print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; a->first() := a->first() mod m ; for i : Integer.subrange(1, n-1) do ( a[i+1] := a[i+1] + a[i - 1+1] ; a[i+1] := a[i+1] mod m) ; a := a->sort() ; var target : int := 0 ; var cnt : int := 1 ; for i : a do ( if i = target then ( ans := ans + cnt ; cnt := cnt + 1 ) else ( target := i ; cnt := 1 )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin from collections import Counter import numpy as np N,M=[int(x)for x in stdin.readline().split()] A=np.array([int(a)for a in stdin.readline().split()],dtype=np.int64) cum_remainders=(np.hstack([0,A])% M).cumsum()% M remainder_counts=Counter(cum_remainders) combinations=0 for count in remainder_counts.values(): combinations+=count*(count-1)//2 print(combinations) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var A : Sequence := (stdin.readLine().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())), (argument (test (logical_test (comparison (expr (atom (name dtype)))))) = (test (logical_test (comparison (expr (atom (name np)) (trailer . (name int64)))))))) ; var cum_remainders : int := ( mod M).cumsum() mod M ; var remainder_counts : OclAny := Counter(cum_remainders) ; var combinations : int := 0 ; for count : remainder_counts.values() do ( combinations := combinations + count * (count - 1) div 2) ; execute (combinations)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys ; def FindSubarray(arr,n,k): count_one=[0]*n ; for i in range(n): count_one[i]=bin(arr[i]).count('1'); sum=count_one[0]; if(n==1): if(count_one[0]>=k): return 1 ; else : return-1 ; ans=sys.maxsize ; i=1 ; j=0 ; while(ik): ans=min(ans,(i-j)+1); sum-=count_one[j]; j+=1 ; elif(sum+count_one[i]==k): ans=min(ans,(i-j)+1); sum+=count_one[i]; i+=1 ; if(ans!=sys.maxsize): return ans ; else : return-1 ; if __name__=="__main__" : arr=[1,2,4,8]; n=len(arr); k=2 ; print(FindSubarray(arr,n,k)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; ; skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 8 }))); ; n := (arr)->size(); ; k := 2; ; execute (FindSubarray(arr, n, k))->display(); ) else skip; operation FindSubarray(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var count_one : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; for i : Integer.subrange(0, n-1) do ( count_one[i+1] := bin(arr[i+1])->count('1');) ; var sum : OclAny := count_one->first(); ; if (n = 1) then ( if ((count_one->first()->compareTo(k)) >= 0) then ( return 1; ) else ( return -1; ) ) else skip ; var ans : (trailer . (name maxsize)) := (trailer . (name maxsize)); ; var i : int := 1; ; var j : int := 0; ; while ((i->compareTo(n)) < 0) do ( if (k = count_one[j+1]) then ( ans := 1; ; break; ) else (if (k = count_one[i+1]) then ( ans := 1; ; break; ) else (if ((sum + count_one[i+1]->compareTo(k)) < 0) then ( sum := sum + count_one[i+1]; ; i := i + 1; ) else (if ((sum + count_one[i+1]->compareTo(k)) > 0) then ( ans := Set{ans, (i - j) + 1}->min(); ; sum := sum - count_one[j+1]; ; j := j + 1; ) else (if (sum + count_one[i+1] = k) then ( ans := Set{ans, (i - j) + 1}->min(); ; sum := sum + count_one[i+1]; ; i := i + 1; ) else skip ) ) ) ) ) ; if (ans /= (trailer . (name maxsize))) then ( return ans; ) else ( return -1; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math N=int(input()) P=[True for x in range(N+3)] P[0]=False P[1]=False for i in range(2,int(math.sqrt(N+3))+1): if P[i]: for j in range(i*2,N+3,i): P[j]=False count=0 for q in range(3,N+1): if P[q]and P[2+q]: count+=2 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var P : Sequence := Integer.subrange(0, N + 3-1)->select(x | true)->collect(x | (true)) ; P->first() := false ; P[1+1] := false ; for i : Integer.subrange(2, ("" + (((N + 3)->sqrt())))->toInteger() + 1-1) do ( if P[i+1] then ( for j : Integer.subrange(i * 2, N + 3-1)->select( $x | ($x - i * 2) mod i = 0 ) do ( P[j+1] := false) ) else skip) ; var count : int := 0 ; for q : Integer.subrange(3, N + 1-1) do ( if P[q+1] & P[2 + q+1] then ( count := count + 2 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Loss(SP,P): loss=0 loss=((2*P*P*SP)/(100*100-P*P)) print("Loss=",round(loss,3)) if __name__=="__main__" : SP,P=2400,30 Loss(SP,P) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{SP,P} := Sequence{2400,30} ; Loss(SP, P) ) else skip; operation Loss(SP : OclAny, P : OclAny) pre: true post: true activity: var loss : int := 0 ; loss := ((2 * P * P * SP) / (100 * 100 - P * P)) ; execute ("Loss=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ss=input("").split() a=int(ss[0]) b=ss[1] c=int(ss[2]) while b!="?" : if b=="+" : result=int(a+c) elif b=="-" : result=int(a-c) elif b=="*" : result=int(a*c) elif b=="/" : result=int(a/c) print("{0}".format(result)) ss=input("").split() a=int(ss[0]) b=ss[1] c=int(ss[2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ss : OclAny := input("").split() ; var a : int := ("" + ((ss->first())))->toInteger() ; var b : OclAny := ss[1+1] ; var c : int := ("" + ((ss[2+1])))->toInteger() ; while b /= "?" do ( if b = "+" then ( var result : int := ("" + ((a + c)))->toInteger() ) else (if b = "-" then ( result := ("" + ((a - c)))->toInteger() ) else (if b = "*" then ( result := ("" + ((a * c)))->toInteger() ) else (if b = "/" then ( result := ("" + ((a / c)))->toInteger() ) else skip ) ) ) ; execute (StringLib.interpolateStrings("{0}", Sequence{result}))->display() ; ss := input("").split() ; a := ("" + ((ss->first())))->toInteger() ; b := ss[1+1] ; c := ("" + ((ss[2+1])))->toInteger()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M,X=map(int,input().split()) A=sum(int(i)collect( _x | (OclType["int"])->apply(_x) ) ; var A : OclAny := ((argument (test (logical_test (comparison (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) < (comparison (expr (atom (name X))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( )))))))))->sum() ; execute (Set{A, M - A}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input_front=input().split(" ") input_back=input().split(" ") n,x=int(input_front[0]),int(input_front[2]) def problemB(n,x): masu_list=[0]*(n+1) adder=input_back for i in adder : masu_list[int(i)]=1 front=sum(masu_list[: x]) back=sum(masu_list[x+1 :]) if front<=back : return print(front) else : return print(back) problemB(n,x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var input_front : OclAny := input().split(" ") ; var input_back : OclAny := input().split(" ") ; var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := Sequence{("" + ((input_front->first())))->toInteger(),("" + ((input_front[2+1])))->toInteger()} ; skip ; problemB(n, x); operation problemB(n : OclAny, x : OclAny) : OclAny pre: true post: true activity: var masu_list : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var adder : OclAny := input_back ; for i : adder do ( masu_list[("" + ((i)))->toInteger()+1] := 1) ; var front : OclAny := (masu_list.subrange(1,x))->sum() ; var back : OclAny := (masu_list.subrange(x + 1+1))->sum() ; if (front->compareTo(back)) <= 0 then ( return (front)->display() ) else ( return (back)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines sys.setrecursionlimit(10**8) INF=float('inf') MOD=10**9+7 def main(): N,M,X=map(int,readline().split()) A=list(map(int,readline().split())) cost=[0]*(N+1) for i in range(M): cost[A[i]]+=1 ans=min(sum(cost[: X]),sum(cost[X+1 :])) print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; sys.setrecursionlimit((10)->pow(8)) ; var INF : double := ("" + (('inf')))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; var X : OclAny := null; Sequence{N,M,X} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cost : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; for i : Integer.subrange(0, M-1) do ( cost[A[i+1]+1] := cost[A[i+1]+1] + 1) ; var ans : OclAny := Set{(cost.subrange(1,X))->sum(), (cost.subrange(X + 1+1))->sum()}->min() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- costa=0 costb=0 n=0 N,M,X=map(int,input().split()) A=list(map(int,input().split())) for i in range(X,-1,-1): j=A.count(i) if j==1 : costa=costa+1 for n in range(X,N+1): k=A.count(n) if k==1 : costb=costb+1 if costa>costb : print(costb) else : print(costa) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var costa : int := 0 ; var costb : int := 0 ; var n : int := 0 ; var N : OclAny := null; var M : OclAny := null; var X : OclAny := null; Sequence{N,M,X} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(-1 + 1, X)->reverse() do ( var j : int := A->count(i) ; if j = 1 then ( costa := costa + 1 ) else skip) ; for n : Integer.subrange(X, N + 1-1) do ( var k : int := A->count(n) ; if k = 1 then ( costb := costb + 1 ) else skip) ; if (costa->compareTo(costb)) > 0 then ( execute (costb)->display() ) else ( execute (costa)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left N,M,X=[int(x)for x in input().split()] A=[int(x)for x in input().split()] b=bisect_left(A,X) if b==0 : print(0) exit() print(min(b,M-b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; var X : OclAny := null; Sequence{N,M,X} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var b : OclAny := bisect_left(A, X) ; if b = 0 then ( execute (0)->display() ; exit() ) else skip ; execute (Set{b, M - b}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) sushi=[int(x)for x in input().split()] res=0 before,after=0,0 cur=sushi[0] i=0 while itoInteger() ; var sushi : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var res : int := 0 ; var before : OclAny := null; var after : OclAny := null; Sequence{before,after} := Sequence{0,0} ; var cur : OclAny := sushi->first() ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( if sushi[i+1] = cur then ( before := before + 1 ; i := i + 1 ) else ( var j : int := i ; var jS : OclAny := sushi[j+1] ; cur := sushi[j+1] ; while (j->compareTo(n)) < 0 & sushi[j+1] = jS do ( after := after + 1 ; j := j + 1) ; i := j ; res := Set{res, Set{before, after}->min()}->max() ; var before : OclAny := after ; var after : int := 0 )) ; execute (res * 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re input() l=[*map(len,re.findall(r'1+|2+',input()[: : 2]))] print(max(map(min,zip(l,l[1 :])))*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; input() ; var l : Sequence := ((input()(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->allMatches(StringLib.rawString('1+|2+')))->collect( _x | (len)->apply(_x) ) ; execute (((Integer.subrange(1, l->size())->collect( _indx | Sequence{l->at(_indx), l->tail()->at(_indx)} ))->collect( _x | (min)->apply(_x) ))->max() * 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) li=list(map(int,input().split())) counts=list([0,0]) count=list([]) num=0 cnt1=0 cnt2=0 sum=0 for i in range(n): if li[i]==2 : if num==1 : count.append(cnt1) sum+=cnt1 cnt1=0 num=2 cnt2+=1 else : if num==2 : count.append(cnt2) sum+=cnt2 cnt2=0 num=1 cnt1+=1 count.append(n-sum) max=min(count[0],count[1]) for i in range(1,len(count)-1): x=min(count[i],count[i+1]) if x>max : max=x print(max*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var counts : Sequence := (Sequence{0}->union(Sequence{ 0 })) ; var count : Sequence := (Sequence{}) ; var num : int := 0 ; var cnt1 : int := 0 ; var cnt2 : int := 0 ; var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( if li[i+1] = 2 then ( if num = 1 then ( execute ((cnt1) : count) ; sum := sum + cnt1 ; cnt1 := 0 ) else skip ; num := 2 ; cnt2 := cnt2 + 1 ) else ( if num = 2 then ( execute ((cnt2) : count) ; sum := sum + cnt2 ; cnt2 := 0 ) else skip ; num := 1 ; cnt1 := cnt1 + 1 )) ; execute ((n - sum) : count) ; var max : OclAny := Set{count->first(), count[1+1]}->min() ; for i : Integer.subrange(1, (count)->size() - 1-1) do ( var x : OclAny := Set{count[i+1], count[i + 1+1]}->min() ; if (x->compareTo(max)) > 0 then ( max := x ) else skip) ; execute (max * 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) a=list(map(int,input().split()))+[0] m=n=p=0 for i in range(x): m+=1 if a[i]!=a[i+1]: p=max(p,min(m,n)) n=m m=0 print(2*p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->union(Sequence{ 0 }) ; m := m(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name n)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name p)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for i : Integer.subrange(0, x-1) do ( m := m + 1 ; if a[i+1] /= a[i + 1+1] then ( var p : OclAny := Set{p, Set{m, n}->min()}->max() ; var n : OclAny := m ; var m : int := 0 ) else skip) ; execute (2 * p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- L=[] input() r=1 for k in input().split(): L+=[r]*int(k) r+=1 input() for j in input().split(): print(L[int(j)-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var L : Sequence := Sequence{} ; input() ; var r : int := 1 ; for k : input().split() do ( L := L + MatrixLib.elementwiseMult(Sequence{ r }, ("" + ((k)))->toInteger()) ; r := r + 1) ; input() ; for j : input().split() do ( execute (L[("" + ((j)))->toInteger() - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin while True : (a,op,b)=stdin.readline().split(' ') a=int(a) b=int(b) if op=="?" : break ; elif op=="+" : print(a+b) elif op=="-" : print(a-b) elif op=="*" : print(a*b) elif op=="/" : print(a//b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( ; var Sequence{a, op, b} : OclAny := stdin.readLine().split(' ') ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; if op = "?" then ( break; ) else (if op = "+" then ( execute (a + b)->display() ) else (if op = "-" then ( execute (a - b)->display() ) else (if op = "*" then ( execute (a * b)->display() ) else (if op = "/" then ( execute (a div b)->display() ) else skip ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() suchi=list(map(int,input().split())) tamanho_sequencias=[] sequencia="" for i in range(0,len(suchi)-1): sequencia+=str(suchi[i]) if suchi[i+1]!=suchi[i]: tamanho_sequencias.append(len(sequencia)) sequencia="" if i+1==len(suchi)-1 : sequencia+=str(suchi[i+1]) tamanho_sequencias.append(len(sequencia)) maior_segmento_suchi=2 for i in range(0,len(tamanho_sequencias)-1): suchi_a=tamanho_sequencias[i] suchi_b=tamanho_sequencias[i+1] segmento_suchi=min(suchi_a,suchi_b)*2 if segmento_suchi>maior_segmento_suchi : maior_segmento_suchi=segmento_suchi print(maior_segmento_suchi) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var suchi : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var tamanho_sequencias : Sequence := Sequence{} ; var sequencia : String := "" ; for i : Integer.subrange(0, (suchi)->size() - 1-1) do ( sequencia := sequencia + ("" + ((suchi[i+1]))) ; if suchi[i + 1+1] /= suchi[i+1] then ( execute (((sequencia)->size()) : tamanho_sequencias) ; sequencia := "" ) else skip ; if i + 1 = (suchi)->size() - 1 then ( sequencia := sequencia + ("" + ((suchi[i + 1+1]))) ; execute (((sequencia)->size()) : tamanho_sequencias) ) else skip) ; var maior_segmento_suchi : int := 2 ; for i : Integer.subrange(0, (tamanho_sequencias)->size() - 1-1) do ( var suchi_a : OclAny := tamanho_sequencias[i+1] ; var suchi_b : OclAny := tamanho_sequencias[i + 1+1] ; var segmento_suchi : double := Set{suchi_a, suchi_b}->min() * 2 ; if (segmento_suchi->compareTo(maior_segmento_suchi)) > 0 then ( maior_segmento_suchi := segmento_suchi ) else skip) ; execute (maior_segmento_suchi)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): ans=sum(1 for i in range(1,10000000)if get_terminal(i)==89) return str(ans) TERMINALS=(1,89) def get_terminal(n): while n not in TERMINALS : n=square_digit_sum(n) return n def square_digit_sum(n): result=0 while n>0 : result+=SQUARE_DIGITS_SUM[n % 1000] n//=1000 return result SQUARE_DIGITS_SUM=[sum(int(c)**2 for c in str(i))for i in range(1000)] if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var TERMINALS : OclAny := Sequence{1, 89} ; skip ; skip ; var SQUARE_DIGITS_SUM : Sequence := Integer.subrange(0, 1000-1)->select(i | true)->collect(i | (((argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))) ** (expr (atom (number (integer 2)))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))->sum())) ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 10000000))))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name get_terminal)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) == (comparison (expr (atom (number (integer 89))))))))))))->sum() ; return ("" + ((ans))); operation get_terminal(n : OclAny) : OclAny pre: true post: true activity: while (TERMINALS)->excludes(n) do ( n := square_digit_sum(n)) ; return n; operation square_digit_sum(n : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; while n > 0 do ( result := result + SQUARE_DIGITS_SUM[n mod 1000+1] ; n := n div 1000) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function FC='#' PC='.' def bothends(f): def _func(self): print(FC,end='') f(self) print(FC) return _func class Frame : c=FC s=PC def __init__(self,w,h): self.w=w self.h=h @ bothends def _draw(self): print(self.s*(self.w-2),end='') def draw(self): for i in range(self.h-2): self._draw() def __enter__(self): print(self.c*self.w) return self def __exit__(self,exc_type,exc_value,traceback): print(self.c*self.w) return True while True : w,h=[int(s)for s in raw_input().split()] if w==h==0 : break with Frame(h,w)as fr : fr.draw() print() ------------------------------------------------------------ OCL File: --------- class Frame { static operation newFrame() : Frame pre: true post: Frame->exists( _x | result = _x ); static attribute c : String := FC; static attribute s : String := PC; attribute w : OclAny := w; attribute h : OclAny := h; operation initialise(w : OclAny,h : OclAny) : Frame pre: true post: true activity: self.w := w ; self.h := h; return self; operation draw() pre: true post: true activity: for i : Integer.subrange(0, self.h - 2-1) do ( self._draw()); operation __enter__() : OclAny pre: true post: true activity: execute (self.c * self.w)->display() ; return self; operation __exit__(exc_type : OclAny,exc_value : OclAny,traceback : OclAny) : OclAny pre: true post: true activity: execute (self.c * self.w)->display() ; return true; } class FromPython { operation initialise() pre: true post: true activity: skip ; var FC : String := '#' ; var PC : String := '.' ; skip ; skip ; while true do ( Sequence{w,h} := raw_input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; if w = h & (h == 0) then ( break ) else skip ; try (var fr : Frame := (Frame.newFrame()).initialise(h, w); fr.draw()) catch (_e : OclException) do skip ; execute (->display()); operation bothends(f : OclAny) : OclAny pre: true post: true activity: skip ; return _func; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys for line in sys.stdin : h,w=map(int,line.split()) if h==0 and w==0 : break for i in range(h): for j in range(w): if(i==0 or j==0 or i==h-1 or j==w-1): sys.stdout.write("#") else : sys.stdout.write(".") print print ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for line : OclFile["System.in"] do ( var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (line.split())->collect( _x | (OclType["int"])->apply(_x) ) ; if h = 0 & w = 0 then ( break ) else skip ; for i : Integer.subrange(0, h-1) do ( for j : Integer.subrange(0, w-1) do ( if (i = 0 or j = 0 or i = h - 1 or j = w - 1) then ( (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "#"))))))) )))) ) else ( (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "."))))))) )))) )) ; ) ; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : line=input().strip() if line=="0 0" : break else : line=line.split("") y=int(line[0]) x=int(line[1]) for i in range(y): for j in range(x): if i==0 or i==y-1 or j==0 or j==x-1 : print("#",end="") else : print(".",end="") print() print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var line : OclAny := input()->trim() ; if line = "0 0" then ( break ) else ( line := line.split("") ; var y : int := ("" + ((line->first())))->toInteger() ; var x : int := ("" + ((line[1+1])))->toInteger() ; for i : Integer.subrange(0, y-1) do ( for j : Integer.subrange(0, x-1) do ( if i = 0 or i = y - 1 or j = 0 or j = x - 1 then ( execute ("#")->display() ) else ( execute (".")->display() )) ; execute (->display()) ; execute (->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys for line in sys.stdin : h,w=map(int,line.rstrip().split()) if h==0 and w==0 : break edge='#'*w+'\n' rect=edge+('#'+'.'*(w-2)+'#\n')*(h-2)+edge print(rect) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for line : OclFile["System.in"] do ( var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (line.rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if h = 0 & w = 0 then ( break ) else skip ; var edge : String := StringLib.nCopies('#', w) + ' ' ; var rect : String := edge + ('#' + StringLib.nCopies('.', (w - 2)) + '# ') * (h - 2) + edge ; execute (rect)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : lst=list(map(int,input().split())) if lst[0]==0 and lst[1]==0 : break for k in range(lst[1]): print("#",end="") print("") for i in range(lst[0]-2): print("#",end="") for j in range(lst[1]-2): print(".",end="") print("#") for l in range(lst[1]): print("#",end="") print("\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if lst->first() = 0 & lst[1+1] = 0 then ( break ) else skip ; for k : Integer.subrange(0, lst[1+1]-1) do ( execute ("#")->display()) ; execute ("")->display() ; for i : Integer.subrange(0, lst->first() - 2-1) do ( execute ("#")->display() ; for j : Integer.subrange(0, lst[1+1] - 2-1) do ( execute (".")->display()) ; execute ("#")->display()) ; for l : Integer.subrange(0, lst[1+1]-1) do ( execute ("#")->display()) ; execute ("\n")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fact(n): fact=1 ; for i in range(1,n+1): fact*=i ; return fact ; def countStrings(string,n): distinct_char=set(); for i in range(n): distinct_char.add(string[i]); return fact(len(distinct_char)); if __name__=="__main__" : string="geeksforgeeks" ; n=len(string); print(countStrings(string,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( string := "geeksforgeeks"; ; n := (string)->size(); ; execute (countStrings(string, n))->display(); ) else skip; operation fact(n : OclAny) pre: true post: true activity: var fact : int := 1; ; for i : Integer.subrange(1, n + 1-1) do ( fact := fact * i;) ; return fact;; operation countStrings(string : OclAny, n : OclAny) pre: true post: true activity: var distinct_char : Set := Set{}->union(()); ; for i : Integer.subrange(0, n-1) do ( execute ((string[i+1]) : distinct_char);) ; return fact((distinct_char)->size());; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- M=4 N=5 def printCommonElements(mat): mp=dict() for j in range(N): mp[mat[0][j]]=1 for i in range(1,M): for j in range(N): if(mat[i][j]in mp.keys()and mp[mat[i][j]]==i): mp[mat[i][j]]=i+1 if i==M-1 : print(mat[i][j],end=" ") mat=[[1,2,1,4,8],[3,7,8,5,1],[8,7,7,3,1],[8,1,2,7,9]] printCommonElements(mat) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var M : int := 4 ; var N : int := 5 ; skip ; mat := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{4}->union(Sequence{ 8 }))))}->union(Sequence{Sequence{3}->union(Sequence{7}->union(Sequence{8}->union(Sequence{5}->union(Sequence{ 1 }))))}->union(Sequence{Sequence{8}->union(Sequence{7}->union(Sequence{7}->union(Sequence{3}->union(Sequence{ 1 }))))}->union(Sequence{ Sequence{8}->union(Sequence{1}->union(Sequence{2}->union(Sequence{7}->union(Sequence{ 9 })))) }))) ; printCommonElements(mat); operation printCommonElements(mat : OclAny) pre: true post: true activity: var mp : Map := (arguments ( )) ; for j : Integer.subrange(0, N-1) do ( mp[mat->first()[j+1]+1] := 1) ; for i : Integer.subrange(1, M-1) do ( for j : Integer.subrange(0, N-1) do ( if ((mp.keys())->includes(mat[i+1][j+1]) & mp[mat[i+1][j+1]+1] = i) then ( mp[mat[i+1][j+1]+1] := i + 1 ; if i = M - 1 then ( execute (mat[i+1][j+1])->display() ) else skip ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import time import math from collections import defaultdict from functools import lru_cache INF=10**18+3 EPS=1e-10 MAX_CACHE=10**9 def time_it(function,output=sys.stderr): def wrapped(*args,**kwargs): start=time.time() res=function(*args,**kwargs) elapsed_time=time.time()-start print('"%s" took %f ms' %(function.__name__,elapsed_time*1000),file=output) return res return wrapped @ time_it def main(): n=int(input()) x1,x2=map(int,input().split()) funcs=[] for _ in range(n): k,b=map(int,input().split()) funcs.append(lambda x,k=k,b=b : k*x+b) comp=lambda x : lambda i : funcs[i](x) sorted1=sorted(range(n),key=comp(x1+EPS)) sorted2=sorted(range(n),key=comp(x2-EPS)) print("Yes" if sorted1!=sorted2 else "No") def set_input(file): global input input=lambda : file.readline().strip() def set_output(file): global print local_print=print def print(*args,**kwargs): kwargs["file"]=kwargs.get("file",file) return local_print(*args,**kwargs) if __name__=='__main__' : set_input(open("input.txt","r")if "MINE" in sys.argv else sys.stdin) set_output(sys.stdout) main() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute input : OclAny; attribute name : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var INF : double := (10)->pow(18) + 3 ; var EPS : double := ("1e-10")->toReal() ; var MAX_CACHE : double := (10)->pow(9) ; skip ; (compound_stmt (decorator @ (dotted_name (name time_it))) (funcdef def (name main) ( ) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name n)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name x1)))))) , (test (logical_test (comparison (expr (atom (name x2))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name funcs)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom [ ]))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name _)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name k)))))) , (test (logical_test (comparison (expr (atom (name b))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name funcs)) (trailer . (name append) (arguments ( (arglist (argument (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)) , (vardef_parameter (name k) = (test (logical_test (comparison (expr (atom (name k))))))) , (vardef_parameter (name b) = (test (logical_test (comparison (expr (atom (name b))))))))) : (test (logical_test (comparison (expr (expr (expr (atom (name k))) * (expr (atom (name x)))) + (expr (atom (name b)))))))))) ))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name comp)))))))) (assign_part = (testlist_star_expr (testlist (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test lambda (varargslist (vardef_parameters (vardef_parameter (name i)))) : (test (logical_test (comparison (expr (atom (name funcs)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sorted1)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name comp)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x1))) + (expr (atom (name EPS))))))))) ))))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sorted2)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name comp)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x2))) - (expr (atom (name EPS))))))))) ))))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Yes")))) if (logical_test (comparison (comparison (expr (atom (name sorted1)))) != (comparison (expr (atom (name sorted2)))))) else (test (logical_test (comparison (expr (atom "No")))))))) ))))))))))))))) ; skip ; skip ; if __name__ = '__main__' then ( set_input(if ((trailer . (name argv)))->includes("MINE") then OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) else OclFile["System.in"] endif) ; set_output(OclFile["System.out"]) ; main() ) else skip; operation time_it(function : OclAny, output : OclAny) : OclAny pre: true post: true activity: if output->oclIsUndefined() then output := OclFile["System.err"] else skip; skip ; return wrapped; operation set_input(file : OclAny) pre: true post: true activity: skip ; input := lambda $$ : OclAny in (file.readLine()->trim()); operation set_output(file : OclAny) pre: true post: true activity: skip ; ; var local_print : OclAny := print ; skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) d=[0 for _ in range(n-1)] for i in range(n-1): d[i]=a[i+1]-a[i] cnt=1 l=r=cur=0 while l=0 : if cur==0 : cur=d[r] r+=1 if rtoInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : Sequence := Integer.subrange(0, n - 1-1)->select(_anon | true)->collect(_anon | (0)) ; for i : Integer.subrange(0, n - 1-1) do ( d[i+1] := a[i + 1+1] - a[i+1]) ; var cnt : int := 1 ; l := l(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name r)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cur)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; while (l->compareTo(n - 1)) < 0 do ( while (r->compareTo(n - 1)) < 0 & cur * d[r+1] >= 0 do ( if cur = 0 then ( var cur : OclAny := d[r+1] ) else skip ; r := r + 1) ; if (r->compareTo(n - 1)) < 0 & cur * d[r+1] < 0 then ( cnt := cnt + 1 ) else skip ; r := r + 1 ; var l : OclAny := r ; cur := 0) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculateSquareSum(n): fibo=[0]*(n+1); if(n<=0): return 0 ; fibo[0]=0 ; fibo[1]=1 ; sum=((fibo[0]*fibo[0])+(fibo[1]*fibo[1])); for i in range(2,n+1): fibo[i]=(fibo[i-1]+fibo[i-2]); sum+=(fibo[i]*fibo[i]); return sum ; n=6 ; print("Sum of squares of Fibonacci numbers is :",calculateSquareSum(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 6; ; execute ("Sum of squares of Fibonacci numbers is :")->display();; operation calculateSquareSum(n : OclAny) pre: true post: true activity: var fibo : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); ; if (n <= 0) then ( return 0; ) else skip ; fibo->first() := 0; ; fibo[1+1] := 1; ; var sum : double := ((fibo->first() * fibo->first()) + (fibo[1+1] * fibo[1+1])); ; for i : Integer.subrange(2, n + 1-1) do ( fibo[i+1] := (fibo[i - 1+1] + fibo[i - 2+1]); ; sum := sum + (fibo[i+1] * fibo[i+1]);) ; return sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=0 while True : c+=1 L=[] num=int(input()) if num==0 : break for i in range(num): name,w,l,d=input().split() w=int(w) d=int(d) L.append((i,name,w*3+d)) L.sort(key=lambda x :(-x[2],x[0])) if c>1 : print() for l in L : print("{},{}".format(l[1],l[2])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : int := 0 ; while true do ( c := c + 1 ; var L : Sequence := Sequence{} ; var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if num = 0 then ( break ) else skip ; for i : Integer.subrange(0, num-1) do ( var name : OclAny := null; var w : OclAny := null; var l : OclAny := null; var d : OclAny := null; Sequence{name,w,l,d} := input().split() ; var w : int := ("" + ((w)))->toInteger() ; var d : int := ("" + ((d)))->toInteger() ; execute ((Sequence{i, name, w * 3 + d}) : L)) ; L := L->sort() ; if c > 1 then ( execute (->display() ) else skip ; for l : L do ( execute (StringLib.interpolateStrings("{},{}", Sequence{l[1+1], l[2+1]}))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,k=map(int,input().split()) a=list(map(int,input().split())) for i in range(n): sub=min(a[i],k) a[i]=a[i]-sub a[-1]=a[-1]+sub k=k-sub print(*a,sep=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( var sub : OclAny := Set{a[i+1], k}->min() ; a[i+1] := a[i+1] - sub ; a->last() := a->last() + sub ; var k : double := k - sub) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) p=list() m=int(math.sqrt(n)+1) for i in range(2,m): if n % i==0 : c=0 while n % i==0 : c+=1 n//=i p.append(c) if n!=1 : p.append(1) maxi=1 for x in p : maxi*=(x+1) print(len(p),maxi-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := () ; var m : int := ("" + (((n)->sqrt() + 1)))->toInteger() ; for i : Integer.subrange(2, m-1) do ( if n mod i = 0 then ( var c : int := 0 ; while n mod i = 0 do ( c := c + 1 ; n := n div i) ; execute ((c) : p) ) else skip) ; if n /= 1 then ( execute ((1) : p) ) else skip ; var maxi : int := 1 ; for x : p do ( maxi := maxi * (x + 1)) ; execute ((p)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy def make_divisors(n): divisors=[] for i in range(1,int(n**0.5)+1): if n % i==0 : divisors.append(i) if i!=n//i : divisors.append(n//i) divisors.sort() return divisors def main(): N=int(input()) yakusu=make_divisors(N) max_times=len(yakusu)-1 min_times=0 result=[] for i in reversed(yakusu[:-1]): if i in result : continue result.extend(make_divisors(i)) min_times+=1 print(min_times,max_times) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation make_divisors(n : OclAny) : OclAny pre: true post: true activity: var divisors : Sequence := Sequence{} ; for i : Integer.subrange(1, ("" + (((n)->pow(0.5))))->toInteger() + 1-1) do ( if n mod i = 0 then ( execute ((i) : divisors) ; if i /= n div i then ( execute ((n div i) : divisors) ) else skip ) else skip) ; divisors := divisors->sort() ; return divisors; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var yakusu : OclAny := make_divisors(N) ; var max_times : double := (yakusu)->size() - 1 ; var min_times : int := 0 ; var result : Sequence := Sequence{} ; for i : (yakusu->front())->reverse() do ( if (result)->includes(i) then ( continue ) else skip ; result := result->union(make_divisors(i)) ; min_times := min_times + 1) ; execute (min_times)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(int(1e7)) from collections import deque def inpl(): return list(map(int,input().split())) def primes(N): sieve=[1]*(N+1) sieve[0],sieve[1]=0,0 P=[] for i in range(2,N+1): if sieve[i]: P.append(i) for j in range(2*i,N+1,i): sieve[j]=0 return P N=int(input()) P=primes(10**6+10) factors=[0]*len(P) for i in range(len(P)): p=P[i] while N % p==0 : factors[i]+=1 N=N//p factors+=[N!=1] a=sum([f>0 for f in factors]) b=1 for i in range(len(P)+1): b*=factors[i]+1 b-=1 print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(("" + ((("1e7")->toReal())))->toInteger()) ; skip ; skip ; skip ; N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; P := primes((10)->pow(6) + 10) ; var factors : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (P)->size()) ; for i : Integer.subrange(0, (P)->size()-1) do ( var p : OclAny := P[i+1] ; while N mod p = 0 do ( factors[i+1] := factors[i+1] + 1 ; N := N div p)) ; factors := factors + Sequence{ N /= 1 } ; var a : OclAny := (factors->select(f | true)->collect(f | (f > 0)))->sum() ; var b : int := 1 ; for i : Integer.subrange(0, (P)->size() + 1-1) do ( b := b * factors[i+1] + 1) ; b := b - 1 ; execute (a)->display(); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation primes(N : OclAny) : OclAny pre: true post: true activity: var sieve : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (N + 1)) ; var sieve->first() : OclAny := null; var sieve[1+1] : OclAny := null; Sequence{sieve->first(),sieve[1+1]} := Sequence{0,0} ; var P : Sequence := Sequence{} ; for i : Integer.subrange(2, N + 1-1) do ( if sieve[i+1] then ( execute ((i) : P) ; for j : Integer.subrange(2 * i, N + 1-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ( sieve[j+1] := 0) ) else skip) ; return P; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def line2int(linea): temp="" for i in linea : if i=="" : if temp!="" : val1=int(temp) temp="" else : temp=temp+i val2=int(temp) return(val1,val2) (n,m)=line2int(input()) if m==0 : minN=maxN=n else : minN=n-m*2 if minN<0 : minN=0 i=1 while m>0 : m=m-i i=i+1 maxN=n-i print(minN,maxN) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var Sequence{n, m} : OclAny := line2int((OclFile["System.in"]).readLine()) ; if m = 0 then ( var minN : OclAny := n; var maxN : OclAny := n ) else ( minN := n - m * 2 ; if minN < 0 then ( minN := 0 ) else skip ; var i : int := 1 ; while m > 0 do ( var m : double := m - i ; i := i + 1) ; maxN := n - i ) ; execute (minN)->display(); operation line2int(linea : OclAny) : OclAny pre: true post: true activity: var temp : String := "" ; for i : linea do ( if i = "" then ( if temp /= "" then ( var val1 : int := ("" + ((temp)))->toInteger() ; temp := "" ) else skip ) else ( temp := temp + i )) ; var val2 : int := ("" + ((temp)))->toInteger() ; return Sequence{val1, val2}; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) if n>m*2 : mi=n-m*2 else : mi=0 for i in range(n): comEdge=i*(i-1)/2 ma=0 if comEdge>=m : ma=abs(n-(i)) break print(mi,ma) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (n->compareTo(m * 2)) > 0 then ( var mi : double := n - m * 2 ) else ( mi := 0 ) ; for i : Integer.subrange(0, n-1) do ( var comEdge : double := i * (i - 1) / 2 ; var ma : int := 0 ; if (comEdge->compareTo(m)) >= 0 then ( ma := (n - (i))->abs() ; break ) else skip) ; execute (mi)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) l=0 r=n while lcollect( _x | (OclType["int"])->apply(_x) ) ; var l : int := 0 ; var r : OclAny := n ; while (l->compareTo(r)) < 0 do ( var med : int := (l + r) div 2 ; if (med * (med - 1) div 2->compareTo(m)) < 0 then ( l := med + 1 ) else ( r := med )) ; execute (Set{0, n - 2 * m}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) t=int(((8*m+1)**.5+1)/2) if m==0 : print(n,n) else : print(max(0,n-2*m),max(0,n-t-(max(0,t*(t-1))<2*m))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : int := ("" + (((((8 * m + 1))->pow(.5) + 1) / 2)))->toInteger() ; if m = 0 then ( execute (n)->display() ) else ( execute (Set{0, n - 2 * m}->max())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) pre=0 ans=1 t=0 for i in input().split(): a=int(i) if pre==0 : pre=a else : if pre>a : if-t<0 and t**2==1 : ans+=1 t=-2 else : t=-1 elif pretoInteger() ; var pre : int := 0 ; var ans : int := 1 ; var t : int := 0 ; for i : input().split() do ( var a : int := ("" + ((i)))->toInteger() ; if pre = 0 then ( pre := a ) else ( if (pre->compareTo(a)) > 0 then ( if -t < 0 & (t)->pow(2) = 1 then ( ans := ans + 1 ; t := -2 ) else ( t := -1 ) ) else (if (pre->compareTo(a)) < 0 then ( if t < 0 & (t)->pow(2) = 1 then ( ans := ans + 1 ; t := 2 ) else ( t := 1 ) ) else ( continue ) ) ; pre := a )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) ans1=max(0,n-2*m) l=-1 r=n while r-l>1 : M=(l+r)//2 if M*(M-1)//2>=m : r=M else : l=M print(ans1,n-r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans1 : OclAny := Set{0, n - 2 * m}->max() ; var l : int := -1 ; var r : OclAny := n ; while r - l > 1 do ( var M : int := (l + r) div 2 ; if (M * (M - 1) div 2->compareTo(m)) >= 0 then ( r := M ) else ( l := M )) ; execute (ans1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getMaxNum(a,b,c): if(b % c==0): return b x=((b//c)*c) if(x>=a and x<=b): return x else : return-1 a,b,c=2,10,3 print(getMaxNum(a,b,c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{a,b,c} := Sequence{2,10,3} ; execute (getMaxNum(a, b, c))->display(); operation getMaxNum(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: if (b mod c = 0) then ( return b ) else skip ; var x : double := ((b div c) * c) ; if ((x->compareTo(a)) >= 0 & (x->compareTo(b)) <= 0) then ( return x ) else ( return -1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) inches=round(n/3) feet=inches//12 inches=inches % 12 print(feet,inches) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var inches : double := (n / 3)->round() ; var feet : int := inches div 12 ; inches := inches mod 12 ; execute (feet)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=list(map(int,input().split(' '))) a=list(map(int,input().split(' '))) i=0 while itoInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var i : int := 0 ; while (i->compareTo(n)) < 0 & k do ( while (i->compareTo(n - 1)) < 0 & a[i+1] <= 0 do ( i := i + 1) ; a[i+1] := a[i+1] - 1 ; a->last() := a->last() + 1 ; k := k - 1) ; execute (StringLib.sumStringsWithSeparator(((a)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fi(n): ft=n//36 rem=n % 36 ic=round(rem/3) if ic==12 : ft+=1 ic=0 return ft,ic return n=int(input()) a,b=fi(n) print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := fi(n) ; execute (a)->display(); operation fi(n : OclAny) : OclAny pre: true post: true activity: var ft : int := n div 36 ; var rem : int := n mod 36 ; var ic : double := (rem / 3)->round() ; if ic = 12 then ( ft := ft + 1 ; ic := 0 ) else skip ; return ft, ic ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 3==0 : inc=n//3 elif n % 3==1 : inc=n//3 else : inc=n//3+1 feet=inc//12 inc=inc % 12 print(feet,inc) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 3 = 0 then ( var inc : int := n div 3 ) else (if n mod 3 = 1 then ( inc := n div 3 ) else ( inc := n div 3 + 1 ) ) ; var feet : int := inc div 12 ; inc := inc mod 12 ; execute (feet)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import permutations Test_case=1 for test in range(Test_case): n=int(input()) if n % 3==0 : inc=n//3 print(inc//12,inc % 12) elif n % 3==1 : inc=n//3 print(inc//12,inc % 12) else : inc=n//3+1 print(inc//12,inc % 12) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var Test_case : int := 1 ; for test : Integer.subrange(0, Test_case-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 3 = 0 then ( var inc : int := n div 3 ; execute (inc div 12)->display() ) else (if n mod 3 = 1 then ( inc := n div 3 ; execute (inc div 12)->display() ) else ( inc := n div 3 + 1 ; execute (inc div 12)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=(int(input())+1)//3 ; print(n//12,n % 12) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := (("" + (((OclFile["System.in"]).readLine())))->toInteger() + 1) div 3; execute (n div 12)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def HailstoneNumbers(N,c): print(N,end=" "); if(N==1 and c==0): return c ; elif(N==1 and c!=0): c=c+1 ; elif(N % 2==0): c=c+1 ; c=HailstoneNumbers(int(N/2),c); elif(N % 2!=0): c=c+1 ; c=HailstoneNumbers(3*N+1,c); return c ; N=7 ; x=HailstoneNumbers(N,0); print("\nNumber of Steps: ",x); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 7; ; var x : OclAny := HailstoneNumbers(N, 0); ; execute ("\nNumber of Steps: ")->display();; operation HailstoneNumbers(N : OclAny, c : OclAny) pre: true post: true activity: execute (N)->display(); ; if (N = 1 & c = 0) then ( return c; ) else (if (N = 1 & c /= 0) then ( c := c + 1; ) else (if (N mod 2 = 0) then ( c := c + 1; ; c := HailstoneNumbers(("" + ((N / 2)))->toInteger(), c); ) else (if (N mod 2 /= 0) then ( c := c + 1; ; c := HailstoneNumbers(3 * N + 1, c); ) else skip ) ) ) ; return c;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin from math import sqrt input=stdin.readline def closest_part(points,n): if n<=1 : return float('inf') m=n//2 x=points[m][0] d=min(closest_part(points[: m],m),closest_part(points[m :],n-m)) points.sort(key=lambda x : x[1]) b=[] for i in range(n): if(points[i][0]-x)**2>=d : continue for j in range(len(b)): dx=points[i][0]-b[-j-1][0] dy=points[i][1]-b[-j-1][1] if dy**2>=d : break d=min(d,(dx**2+dy**2)) b.append(points[i]) return d def main(args): n=int(input()) points=[tuple(map(int,input().split()))for _ in range(n)] points.sort() result=closest_part(points,n) print(result) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation closest_part(points : OclAny, n : OclAny) : OclAny pre: true post: true activity: if n <= 1 then ( return ("" + (('inf')))->toReal() ) else skip ; var m : int := n div 2 ; var x : OclAny := points[m+1]->first() ; var d : OclAny := Set{closest_part(points.subrange(1,m), m), closest_part(points.subrange(m+1), n - m)}->min() ; points := points->sort() ; var b : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if (((points[i+1]->first() - x))->pow(2)->compareTo(d)) >= 0 then ( continue ) else skip ; for j : Integer.subrange(0, (b)->size()-1) do ( var dx : double := points[i+1]->first() - b->reverse()->at(-(-j - 1))->first() ; var dy : double := points[i+1][1+1] - b->reverse()->at(-(-j - 1))[1+1] ; if ((dy)->pow(2)->compareTo(d)) >= 0 then ( break ) else skip ; d := Set{d, ((dx)->pow(2) + (dy)->pow(2))}->min()) ; execute ((points[i+1]) : b)) ; return d; operation main(args : OclAny) pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; points := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; points := points->sort() ; var result : OclAny := closest_part(points, n) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect,collections,copy,itertools,math,string import sys def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def main(): n=I() a=LI() tp=0 ans=1 for i in range(1,n): before=a[i-1] after=a[i] if tp==0 : if beforeafter : tp=-1 elif tp==1 : if before>after : ans+=1 tp=0 elif tp==-1 : if beforetoInteger(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )); operation S() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation LS() : OclAny pre: true post: true activity: return (sys.stdin.readLine().rstrip().split()); operation main() pre: true post: true activity: var n : OclAny := I() ; var a : OclAny := LI() ; var tp : int := 0 ; var ans : int := 1 ; for i : Integer.subrange(1, n-1) do ( var before : OclAny := a[i - 1+1] ; var after : OclAny := a[i+1] ; if tp = 0 then ( if (before->compareTo(after)) < 0 then ( tp := 1 ) else (if (before->compareTo(after)) > 0 then ( tp := -1 ) else skip) ) else (if tp = 1 then ( if (before->compareTo(after)) > 0 then ( ans := ans + 1 ; tp := 0 ) else skip ) else (if tp = -1 then ( if (before->compareTo(after)) < 0 then ( ans := ans + 1 ; tp := 0 ) else skip ) else skip ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from operator import itemgetter from itertools import combinations,takewhile from math import sqrt def solve(a : list,sorted_axis : int=-1): length=len(a) if length<=3 : return min((x1-x2)**2+(y1-y2)**2 for(x1,y1),(x2,y2)in combinations(a,2)) x_set_len=len(set(x for x,_ in a)) axis1=0 if x_set_len>length/2 else 1 if sorted_axis!=axis1 : a.sort(key=itemgetter(axis1)) mid_index=length//2 left,right=a[: mid_index],a[mid_index :] delta=min(solve(left,axis1),solve(right,axis1)) axis2=not axis1 median=a[mid_index][axis1] mid_a=sorted([p for _iter in((takewhile(lambda p : median-sqrt(delta)toInteger() ; var a : Sequence := (OclFile["System.in"]).readlines()->select(l | true)->collect(l | (((l.split())->collect( _x | (OclType["int"])->apply(_x) )))) ; execute (solve(a))->display() ) else skip; operation solve(a : Sequence(OclAny), sorted_axis : int) : OclAny pre: true post: true activity: if sorted_axis->oclIsUndefined() then sorted_axis := -1 else skip; var length : int := (a)->size() ; if length <= 3 then ( return ((argument (test (logical_test (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name x1))) - (expr (atom (name x2)))))))) ))) ** (expr (atom (number (integer 2))))) + (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name y1))) - (expr (atom (name y2)))))))) ))) ** (expr (atom (number (integer 2))))))))) (comp_for for (exprlist (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name x1)))))) , (test (logical_test (comparison (expr (atom (name y1))))))) ))) , (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name x2)))))) , (test (logical_test (comparison (expr (atom (name y2))))))) )))) in (logical_test (comparison (expr (atom (name combinations)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))))))))->min() ) else skip ; var x_set_len : int := (Set{}->union(((argument (test (logical_test (comparison (expr (atom (name x)))))) (comp_for for (exprlist (expr (atom (name x))) , (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name a))))))))))->size() ; var axis1 : int := if (x_set_len->compareTo(length / 2)) > 0 then 0 else 1 endif ; if sorted_axis /= axis1 then ( a := a->sort() ) else skip ; var mid_index : int := length div 2 ; var left : OclAny := null; var right : OclAny := null; Sequence{left,right} := Sequence{a.subrange(1,mid_index),a.subrange(mid_index+1)} ; var delta : OclAny := Set{solve(left, axis1), solve(right, axis1)}->min() ; var axis2 : boolean := not(axis1) ; var median : OclAny := a[mid_index+1][axis1+1] ; var mid_a : Sequence := Sequence{(takewhile(lambda p : OclAny in ((median - sqrt(delta)->compareTo(p[axis1+1])) < 0), left(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))), (takewhile(lambda p : OclAny in ((p[axis1+1]->compareTo(median + sqrt(delta))) < 0), right))}->select(_iter; p : _iter | true)->collect(_iter; p : _iter | (p))->sortedBy($x | (itemgetter(axis2))->apply($x)) ; for _tuple : Integer.subrange(1, (mid_a)->size())->collect( _indx | Sequence{_indx-1, (mid_a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{x1, y1} : OclAny := _tuple->at(_indx); var ub : OclAny := (if axis1 then x1 else y1 endif) + sqrt(delta) ; for _tuple : takewhile(lambda p : OclAny in ((p[axis2+1]->compareTo(ub)) < 0), mid_a.subrange(i + 1+1)) do (var _indx : int := 1; var x2 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y2 : OclAny := _tuple->at(_indx); delta := Set{delta, ((x1 - x2))->pow(2) + ((y1 - y2))->pow(2)}->min())) ; return delta; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[] for _ in range(n): a.append(list(map(int,input().split()))) b=sorted(a,key=lambda x :(x[0],x[1])) c=sorted(a,key=lambda x :(x[1],x[0])) ans=10**10 for i in range(n-1): temp=(b[i+1][0]-b[i][0])**2+(b[i+1][1]-b[i][1])**2 if ans>temp : ans=temp for i in range(n-1): temp=(c[i+1][0]-c[i][0])**2+(c[i+1][1]-c[i][1])**2 if ans>temp : ans=temp print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : a)) ; var b : Sequence := a->sortedBy($x | (lambda x : OclAny in (Sequence{x->first(), x[1+1]}))->apply($x)) ; var c : Sequence := a->sortedBy($x | (lambda x : OclAny in (Sequence{x[1+1], x->first()}))->apply($x)) ; var ans : double := (10)->pow(10) ; for i : Integer.subrange(0, n - 1-1) do ( var temp : double := ((b[i + 1+1]->first() - b[i+1]->first()))->pow(2) + ((b[i + 1+1][1+1] - b[i+1][1+1]))->pow(2) ; if (ans->compareTo(temp)) > 0 then ( ans := temp ) else skip) ; for i : Integer.subrange(0, n - 1-1) do ( temp := ((c[i + 1+1]->first() - c[i+1]->first()))->pow(2) + ((c[i + 1+1][1+1] - c[i+1][1+1]))->pow(2) ; if (ans->compareTo(temp)) > 0 then ( ans := temp ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) P,Q=[],[] for i in range(0,n): a,b=map(int,input().split()) P.append([a,b]) Q.append([b,a]) P.sort() Q.sort() dist=20000**2+20000**2 for p in range(0,n-1): temp=(P[p][0]-P[p+1][0])**2+(P[p][1]-P[p+1][1])**2 if temptoInteger() ; var P : OclAny := null; var Q : OclAny := null; Sequence{P,Q} := Sequence{Sequence{},Sequence{}} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a}->union(Sequence{ b })) : P) ; execute ((Sequence{b}->union(Sequence{ a })) : Q)) ; P := P->sort() ; Q := Q->sort() ; var dist : double := (20000)->pow(2) + (20000)->pow(2) ; for p : Integer.subrange(0, n - 1-1) do ( var temp : double := ((P[p+1]->first() - P[p + 1+1]->first()))->pow(2) + ((P[p+1][1+1] - P[p + 1+1][1+1]))->pow(2) ; if (temp->compareTo(dist)) < 0 then ( dist := temp ) else skip) ; for q : Integer.subrange(0, n - 1-1) do ( temp := ((Q[q+1]->first() - Q[q + 1+1]->first()))->pow(2) + ((Q[q+1][1+1] - Q[q + 1+1][1+1]))->pow(2) ; if (temp->compareTo(dist)) < 0 then ( dist := temp ) else skip) ; execute (dist)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from operator import itemgetter N=int(input()) a=[tuple(map(int,input().split()))for _ in[0]*N] ans=float("inf") a.sort() for(x1,y1),(x2,y2)in zip(a,a[1 :]): dist=(x1-x2)**2+(y1-y2)**2 if ans>dist : ans=dist a.sort(key=itemgetter(1)) for(x1,y1),(x2,y2)in zip(a,a[1 :]): dist=(x1-x2)**2+(y1-y2)**2 if ans>dist : ans=dist print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ans : double := ("" + (("inf")))->toReal() ; a := a->sort() ; for _tuple : Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), a->tail()->at(_indx)} ) do (var _indx : int := 1; var Sequence{x1, y1} : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{x2, y2} : OclAny := _tuple->at(_indx); var dist : double := ((x1 - x2))->pow(2) + ((y1 - y2))->pow(2) ; if (ans->compareTo(dist)) > 0 then ( ans := dist ) else skip) ; a := a->sort() ; for _tuple : Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), a->tail()->at(_indx)} ) do (var _indx : int := 1; var Sequence{x1, y1} : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{x2, y2} : OclAny := _tuple->at(_indx); dist := ((x1 - x2))->pow(2) + ((y1 - y2))->pow(2) ; if (ans->compareTo(dist)) > 0 then ( ans := dist ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) a=list(map(int,input().split())) s=0 for i in range(n): if k>0 : t=min(a[i],k) a[i]-=t k-=t s+=t a[-1]+=s print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : int := 0 ; for i : Integer.subrange(0, n-1) do ( if k > 0 then ( var t : OclAny := Set{a[i+1], k}->min() ; a[i+1] := a[i+1] - t ; k := k - t ; s := s + t ) else skip) ; a->last() := a->last() + s ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution : def binaryGap(self,n : int)->int : current=1 last1=-1 out=0 while n>0 : if n % 2==1 : if last1>=1 : out=max(out,current-last1) last1=current current+=1 n=n//2 return out ------------------------------------------------------------ OCL File: --------- class Solution { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation binaryGap(n : int) : int pre: true post: true activity: var current : int := 1 ; var last1 : int := -1 ; var out : int := 0 ; while n > 0 do ( if n mod 2 = 1 then ( if last1 >= 1 then ( out := Set{out, current - last1}->max() ) else skip ; last1 := current ) else skip ; current := current + 1 ; var n : int := n div 2) ; return out; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) h,m=map(int,input().split()) M,c=60*h+m,0 while '7' not in str(M//60)+str(M % 60): c+=1 ; M-=x if M<0 : M+=1440 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var M : OclAny := null; var c : OclAny := null; Sequence{M,c} := Sequence{60 * h + m,0} ; while (("" + ((M div 60))) + ("" + ((M mod 60))))->excludes('7') do ( c := c + 1; M := M - x ; if M < 0 then ( M := M + 1440 ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) h,m=map(int,input().split()) c=0 if "7" in str(h)or "7" in str(m): print("0") else : while("7" not in str(m))and("7" not in str(h)): m-=n c+=1 if m<0 : m=60+m h-=1 if h<0 : h=24+h print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : int := 0 ; if (("" + ((h))))->includes("7") or (("" + ((m))))->includes("7") then ( execute ("0")->display() ) else ( while ((("" + ((m))))->excludes("7")) & ((("" + ((h))))->excludes("7")) do ( m := m - n ; c := c + 1 ; if m < 0 then ( var m : int := 60 + m ; h := h - 1 ; if h < 0 then ( var h : int := 24 + h ) else skip ) else skip) ; execute (c)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) h,m=map(int,input().split()) M,c=60*h+m,0 while '7' not in str(M//60)+str(M % 60): c+=1 ; M-=x if M<0 : M+=1440 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var M : OclAny := null; var c : OclAny := null; Sequence{M,c} := Sequence{60 * h + m,0} ; while (("" + ((M div 60))) + ("" + ((M mod 60))))->excludes('7') do ( c := c + 1; M := M - x ; if M < 0 then ( M := M + 1440 ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) h,m=map(int,input().split()) M,c=60*h+m,0 while '7' not in str(M//60)+str(M % 60): c+=1 ; M-=x if M<0 : M+=1440 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var M : OclAny := null; var c : OclAny := null; Sequence{M,c} := Sequence{60 * h + m,0} ; while (("" + ((M div 60))) + ("" + ((M mod 60))))->excludes('7') do ( c := c + 1; M := M - x ; if M < 0 then ( M := M + 1440 ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,radians from itertools import groupby,accumulate,permutations,combinations,product from operator import itemgetter,mul from copy import deepcopy from string import ascii_lowercase,ascii_uppercase,digits from bisect import bisect,bisect_left from fractions import gcd from heapq import heappush,heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) def ZIP(n): return zip(*(MAP()for _ in range(n))) sys.setrecursionlimit(10**9) INF=float('inf') mod=10**9+7 N=INT() A=LIST() A=[k for k,g in groupby(A)] N=len(A) i=1 ans=0 while iA[i+1]or A[i-1]>A[i]pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var N : OclAny := INT() ; var A : OclAny := LIST() ; A := groupby(A)->select(_tuple | true)->collect(_tuple | let k : OclAny = _tuple->at(1) in let g : OclAny = _tuple->at(2) in (k)) ; N := (A)->size() ; var i : int := 1 ; var ans : int := 0 ; while (i->compareTo(N - 1)) < 0 do ( if (A[i - 1+1]->compareTo(A[i+1])) < 0 & (A[i+1] > A[i + 1+1]) or (A[i - 1+1]->compareTo(A[i+1])) > 0 & (A[i+1] < A[i + 1+1]) then ( ans := ans + 1 ; i := i + 1 ) else skip ; i := i + 1) ; execute (ans + 1)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ZIP(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))`third->at(_indx)} ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) (hh,mm)=map(str,input().split(' ')) if('7' in hh)or('7' in mm): print(0) else : press_the_button=0 while True : if int(mm)>=x : mm=str(int(mm)-x) else : mm=str(60+int(mm)-x) if int(hh)>0 : hh=str(int(hh)-1) else : hh=str(23) press_the_button+=1 if('7' in hh)or('7' in mm): break print(press_the_button) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var Sequence{hh, mm} : Sequence := (input().split(' '))->collect( _x | (OclType["String"])->apply(_x) ) ; if ((hh)->includes('7')) or ((mm)->includes('7')) then ( execute (0)->display() ) else ( var press_the_button : int := 0 ; while true do ( if (("" + ((mm)))->toInteger()->compareTo(x)) >= 0 then ( var mm : String := ("" + ((("" + ((mm)))->toInteger() - x))) ) else ( mm := ("" + ((60 + ("" + ((mm)))->toInteger() - x))) ; if ("" + ((hh)))->toInteger() > 0 then ( var hh : String := ("" + ((("" + ((hh)))->toInteger() - 1))) ) else ( hh := ("" + ((23))) ) ) ; press_the_button := press_the_button + 1 ; if ((hh)->characters()->includes('7')) or ((mm)->characters()->includes('7')) then ( break ) else skip) ; execute (press_the_button)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def canFormTeam(n,m): if(n>=1 and m>=2): return True if(m>=1 and n>=2): return True return False def maxTeams(n,m): count=0 while(canFormTeam(n,m)): if(n>m): n-=2 m-=1 else : m-=2 n-=1 count+=1 return count if __name__=='__main__' : n=4 m=5 print(maxTeams(n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( n := 4 ; m := 5 ; execute (maxTeams(n, m))->display() ) else skip; operation canFormTeam(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: if (n >= 1 & m >= 2) then ( return true ) else skip ; if (m >= 1 & n >= 2) then ( return true ) else skip ; return false; operation maxTeams(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while (canFormTeam(n, m)) do ( if ((n->compareTo(m)) > 0) then ( n := n - 2 ; m := m - 1 ) else ( m := m - 2 ; n := n - 1 ) ; count := count + 1) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binomialCoeff(n,k): res=1 ; if(k>n-k): k=n-k ; for i in range(k): res*=(n-i); res/=(i+1); return res ; def catalan(n): c=binomialCoeff(2*n,n); return int(c/(n+1)); n=3 ; print(catalan(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 3; ; execute (catalan(n))->display();; operation binomialCoeff(n : OclAny, k : OclAny) pre: true post: true activity: var res : int := 1; ; if ((k->compareTo(n - k)) > 0) then ( k := n - k; ) else skip ; for i : Integer.subrange(0, k-1) do ( res := res * (n - i); ; res := res / (i + 1);) ; return res;; operation catalan(n : OclAny) pre: true post: true activity: var c : OclAny := binomialCoeff(2 * n, n); ; return ("" + ((c / (n + 1))))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binomialCoefficient(n,k): if(k>n-k): k=n-k res=1 for i in range(k): res=res*(n-i) res=res/(i+1) return res def catalan(n): c=binomialCoefficient(2*n,n) return c/(n+1) for i in range(10): print(catalan(i),end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for i : Integer.subrange(0, 10-1) do ( execute (catalan(i))->display()); operation binomialCoefficient(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if ((k->compareTo(n - k)) > 0) then ( k := n - k ) else skip ; var res : int := 1 ; for i : Integer.subrange(0, k-1) do ( res := res * (n - i) ; res := res / (i + 1)) ; return res; operation catalan(n : OclAny) : OclAny pre: true post: true activity: var c : OclAny := binomialCoefficient(2 * n, n) ; return c / (n + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- NO_OF_CHARS=256 def toMutable(string): List=[] for i in string : List.append(i) return List def toString(List): return ''.join(List) def removeDups(string): bin_hash=[0]*NO_OF_CHARS ip_ind=0 res_ind=0 temp='' mutableString=toMutable(string) while ip_ind!=len(mutableString): temp=mutableString[ip_ind] if bin_hash[ord(temp)]==0 : bin_hash[ord(temp)]=1 mutableString[res_ind]=mutableString[ip_ind] res_ind+=1 ip_ind+=1 return toString(mutableString[0 : res_ind]) string="geeksforgeeks" print removeDups(string) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var NO_OF_CHARS : int := 256 ; skip ; skip ; skip ; string := "geeksforgeeks" ; ; removeDups(string); operation toMutable(string : OclAny) : OclAny pre: true post: true activity: var List : Sequence := Sequence{} ; for i : string do ( execute ((i) : List)) ; return List; operation toString(List : OclAny) : OclAny pre: true post: true activity: return StringLib.sumStringsWithSeparator((List), ''); operation removeDups(string : OclAny) : OclAny pre: true post: true activity: var bin_hash : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, NO_OF_CHARS) ; var ip_ind : int := 0 ; var res_ind : int := 0 ; var temp : String := '' ; var mutableString : OclAny := toMutable(string) ; while ip_ind /= (mutableString)->size() do ( temp := mutableString[ip_ind+1] ; if bin_hash[(temp)->char2byte()+1] = 0 then ( bin_hash[(temp)->char2byte()+1] := 1 ; mutableString[res_ind+1] := mutableString[ip_ind+1] ; res_ind := res_ind + 1 ) else skip ; ip_ind := ip_ind + 1) ; return toString(mutableString.subrange(0+1, res_ind)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) a=list(map(int,input().split())) i=0 while k and i<=n-2 : x=min(a[i],k) a[i]-=x a[-1]+=x i+=1 k-=x print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var i : int := 0 ; while k & (i->compareTo(n - 2)) <= 0 do ( var x : OclAny := Set{a[i+1], k}->min() ; a[i+1] := a[i+1] - x ; a->last() := a->last() + x ; i := i + 1 ; k := k - x) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) wordlist=[input()for i in range(n)] sortlist=[] for i in range(n): a=list(wordlist[i]) a.sort() sortlist.append(a) count=0 sortlist.sort() checkword="" check=0 for i in range(n): a=sortlist.pop() if checkword==a : check+=1 count+=check else : check=0 checkword=a print(int(count)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var wordlist : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var sortlist : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : Sequence := (wordlist[i+1]) ; a := a->sort() ; execute ((a) : sortlist)) ; var count : int := 0 ; sortlist := sortlist->sort() ; var checkword : String := "" ; var check : int := 0 ; for i : Integer.subrange(0, n-1) do ( a := sortlist->last() ; sortlist := sortlist->front() ; if checkword = a then ( check := check + 1 ; count := count + check ) else ( check := 0 ; checkword := a )) ; execute (("" + ((count)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict from collections import deque from collections import Counter import itertools import math def readInt(): return int(input()) def readInts(): return list(map(int,input().split())) def readChar(): return input() def readChars(): return input().split() def comb(n,r): return math.factorial(n)//math.factorial(r)//math.factorial(max(1,n-r)) def con(t): ans="" for i in t : ans+=i[0]+str(i[1]) return ans n=readInt() d=defaultdict(int) for i in[input()for i in range(n)]: t=defaultdict(int) for j in i : t[j]+=1 d[con(sorted(t.items()))]+=1 ans=0 for i in d : ans+=comb(d[i],2) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; n := readInt() ; var d : OclAny := defaultdict(OclType["int"]) ; for i : Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) do ( t := defaultdict(OclType["int"]) ; for j : i do ( t[j+1] := t[j+1] + 1) ; d[con(t->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sort())+1] := d[con(t->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sort())+1] + 1) ; ans := 0 ; for i : d do ( ans := ans + comb(d[i+1], 2)) ; execute (ans)->display(); operation readInt() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation readInts() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation readChar() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation readChars() : OclAny pre: true post: true activity: return input().split(); operation comb(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: return MathLib.factorial(n) div MathLib.factorial(r) div MathLib.factorial(Set{1, n - r}->max()); operation con(t : OclAny) : OclAny pre: true post: true activity: var ans : String := "" ; for i : t do ( ans := ans + i->first() + ("" + ((i[1+1])))) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import sys input=sys.stdin.readline N=int(input()) list=[''.join(sorted(list(input().strip("\n"))))for i in range(N)] list.sort() c=collections.Counter(list) c=c.most_common() ans=0 for i,v in c : ans+=v*(v-1)//2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var OclType["Sequence"] : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (StringLib.sumStringsWithSeparator(((input()->trim())->sort()), ''))) ; OclType["Sequence"] := OclType["Sequence"]->sort() ; var c : OclAny := .Counter(OclType["Sequence"]) ; c := c.most_common() ; var ans : int := 0 ; for _tuple : c do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); ans := ans + v * (v - 1) div 2) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np import collections n=int(input()) s=np.array([[str(i)for i in input().split()]for i in range(n)]) s=np.ravel(s) ans=0 sorted_list=[''.join(sorted(e))for e in s] c=collections.Counter(sorted_list) for i in c.values(): for j in range(0,i): ans+=j print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := (Integer.subrange(0, n-1)->select(i | true)->collect(i | (input().split()->select(i | true)->collect(i | (("" + ((i)))))))) ; s := MatrixLib.flattenMatrix(s) ; var ans : int := 0 ; var sorted_list : Sequence := s->select(e | true)->collect(e | (StringLib.sumStringsWithSeparator((e->sort()), ''))) ; var c : OclAny := .Counter(sorted_list) ; for i : c.values() do ( for j : Integer.subrange(0, i-1) do ( ans := ans + j)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfDigits(x): sum=0 while x!=0 : sum+=x % 10 x=x//10 return sum def countNumbers(l,r): count=0 for i in range(l,r+1): if i % 2==0 and sumOfDigits(i)% 3==0 : count+=1 return count l=1000 ; r=6000 print(countNumbers(l,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; l := 1000; r := 6000 ; execute (countNumbers(l, r))->display(); operation sumOfDigits(x : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; while x /= 0 do ( sum := sum + x mod 10 ; x := x div 10) ; return sum; operation countNumbers(l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(l, r + 1-1) do ( if i mod 2 = 0 & sumOfDigits(i) mod 3 = 0 then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) sub=0 count=1 A=[int(i)for i in input().split()] if N>1 : pre_num=A[1] pre_sub=A[1]-A[0] for num in A[2 :]: if not pre_num==num : if pre_sub*(num-pre_num)<0 : count+=1 pre_sub=0 else : pre_sub=num-pre_num pre_num=num print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sub : int := 0 ; var count : int := 1 ; var A : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if N > 1 then ( var pre_num : OclAny := A[1+1] ; var pre_sub : double := A[1+1] - A->first() ) else skip ; for num : A.subrange(2+1) do ( if not(pre_num = num) then ( if pre_sub * (num - pre_num) < 0 then ( count := count + 1 ; pre_sub := 0 ) else ( pre_sub := num - pre_num ) ; pre_num := num ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d={} c=0 for i in open(0): i=str(sorted(i)); t=d.get(i,0); c+=t ; d[i]=t+1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : OclAny := Set{} ; var c : int := 0 ; for i : OclFile.newOclFile_Write(OclFile.newOclFile(0)) do ( var i : String := ("" + ((i->sort()))); var t : OclAny := d.get(i, 0); c := c + t; d->at(i) := t + 1) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def getPosition(a,n,m): for i in range(n): a[i]=(a[i]//m+(a[i]% m!=0)) ans,maxx=-1,-1 for i in range(n-1,-1,-1): if(maxxunion(Sequence{5}->union(Sequence{ 4 })) ; n := (a)->size() ; m := 2 ; execute (getPosition(a, n, m))->display(); operation getPosition(a : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( a[i+1] := (a[i+1] div m + (a[i+1] mod m /= 0))) ; var ans : OclAny := null; var maxx : OclAny := null; Sequence{ans,maxx} := Sequence{-1,-1} ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if ((maxx->compareTo(a[i+1])) < 0) then ( var maxx : OclAny := a[i+1] ; var ans : OclAny := i ) else skip) ; return ans + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- days=[31,28,31,30,31,30,31,31,30,31,30,31]; def dayOfYear(date): year=(int)(date[0 : 4]); month=(int)(date[5 : 7]); day=(int)(date[8 :]); if(month>2 and year % 4==0 and(year % 100!=0 or year % 400==0)): day+=1 ; month-=1 ; while(month>0): day=day+days[month-1]; month-=1 ; return day ; if __name__=='__main__' : date="2019-01-09" ; print(dayOfYear(date)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var days : Sequence := Sequence{31}->union(Sequence{28}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{ 31 }))))))))))); ; skip ; if __name__ = '__main__' then ( date := "2019-01-09"; ; execute (dayOfYear(date))->display(); ) else skip; operation dayOfYear(date : OclAny) pre: true post: true activity: var year : OclAny := (OclType["int"])(date.subrange(0+1, 4)); ; var month : OclAny := (OclType["int"])(date.subrange(5+1, 7)); ; var day : OclAny := (OclType["int"])(date.subrange(8+1)); ; if (month > 2 & year mod 4 = 0 & (year mod 100 /= 0 or year mod 400 = 0)) then ( day := day + 1; ) else skip ; month := month - 1; ; while (month > 0) do ( day := day + days[month - 1+1]; ; month := month - 1;) ; return day;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) if n % 2==0 : a=[i+(2*(i % 2)-1)for i in range(1,n+1)] else : a=[i+(2*(i % 2)-1)for i in range(1,n-2)]+[n,n-2,n-1] print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( var a : Sequence := Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | (i + (2 * (i mod 2) - 1))) ) else ( a := Integer.subrange(1, n - 2-1)->select(i | true)->collect(i | (i + (2 * (i mod 2) - 1)))->union(Sequence{n}->union(Sequence{n - 2}->union(Sequence{ n - 1 }))) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : n=int(input()) if n % 2==0 : for i in range(1,n,2): print(i+1,i,end=' ') print() else : for i in range(1,n-2,2): print(i+1,i,end=' ') print(n,n-2,n-1,end=' ') print() t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( execute (i + 1)->display()) ; execute (->display() ) else ( for i : Integer.subrange(1, n - 2-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( execute (i + 1)->display()) ; execute (n)->display() ; execute (->display() ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) res=list(range(1,n+1)) res=[i+1 if i % 2==1 else i-1 for i in res] if len(res)% 2==1 : res[-2]+=2 res[-1]-=3 print(*res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : Sequence := (Integer.subrange(1, n + 1-1)) ; res := res->select(i | true)->collect(i | (if i mod 2 = 1 then i + 1 else i - 1 endif)) ; if (res)->size() mod 2 = 1 then ( res->front()->last() := res->front()->last() + 2 ; res->last() := res->last() - 3 ) else skip ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ellipse(l,b): if l<0 or b<0 : return-1 x=(3.14*l*b)/4 return x if __name__=="__main__" : l,b=5,3 print(ellipse(l,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{l,b} := Sequence{5,3} ; execute (ellipse(l, b))->display() ) else skip; operation ellipse(l : OclAny, b : OclAny) : OclAny pre: true post: true activity: if l < 0 or b < 0 then ( return -1 ) else skip ; var x : double := (3.14 * l * b) / 4 ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) if n % 2==0 : a=list(range(1,n+1)) for i in range(0,n,2): a[i],a[i+1]=a[i+1],a[i] else : a=[3,1,2] b=list(range(4,n+1)) for i in range(0,n-3,2): b[i],b[i+1]=b[i+1],b[i] a+=b return " ".join([str(i)for i in a]) t=int(input()) ans=[] while t : ans.append(str(solve())) t-=1 print("\n".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; while t do ( execute ((("" + ((solve())))) : ans) ; t := t - 1) ; execute (StringLib.sumStringsWithSeparator((ans), "\n"))->display(); operation solve() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( var a : Sequence := (Integer.subrange(1, n + 1-1)) ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( var a[i+1] : OclAny := null; var a[i + 1+1] : OclAny := null; Sequence{a[i+1],a[i + 1+1]} := Sequence{a[i + 1+1],a[i+1]}) ) else ( a := Sequence{3}->union(Sequence{1}->union(Sequence{ 2 })) ; var b : Sequence := (Integer.subrange(4, n + 1-1)) ; for i : Integer.subrange(0, n - 3-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( var b[i+1] : OclAny := null; var b[i + 1+1] : OclAny := null; Sequence{b[i+1],b[i + 1+1]} := Sequence{b[i + 1+1],b[i+1]}) ; a := a + b ) ; return StringLib.sumStringsWithSeparator((a->select(i | true)->collect(i | (("" + ((i)))))), " "); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) res,s=[],2 if n & 1==1 : res+=[3,1,2] s=5 res+=[i for pair in zip(range(s,n+1,2),range(s-1,n+1,2))for i in pair] print(*res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : OclAny := null; var s : OclAny := null; Sequence{res,s} := Sequence{Sequence{},2} ; if MathLib.bitwiseAnd(n, 1) = 1 then ( res := res + Sequence{3}->union(Sequence{1}->union(Sequence{ 2 })) ; var s : int := 5 ) else skip ; res := res + Integer.subrange(1, Integer.subrange(s, n + 1-1)->select( $x | ($x - s) mod 2 = 0 )->size())->collect( _indx | Sequence{Integer.subrange(s, n + 1-1)->select( $x | ($x - s) mod 2 = 0 )->at(_indx), Integer.subrange(s - 1, n + 1-1)->select( $x | ($x - s - 1) mod 2 = 0 )->at(_indx)} )->select(pair; i : pair | true)->collect(pair; i : pair | (i)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cnt=0 graph=[0]*100 for i in range(100): graph[i]=[] weight=["0"]*100 def isPalindrome(x): n=len(x) for i in range(0,n//2): if x[i]!=x[n-1-i]: return False return True def dfs(node,parent): global cnt x=weight[node] if(isPalindrome(x)): cnt+=1 for to in graph[node]: if to==parent : continue dfs(to,node) if __name__=="__main__" : weight[0]="" weight[1]="abc" weight[2]="aba" weight[3]="bcb" weight[4]="moh" weight[5]="aa" graph[1].append(2) graph[2].append(3) graph[2].append(4) graph[1].append(5) dfs(1,1) print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute cnt : OclAny; operation initialise() pre: true post: true activity: var cnt : int := 0 ; var graph : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100) ; for i : Integer.subrange(0, 100-1) do ( graph[i+1] := Sequence{}) ; var weight : Sequence := MatrixLib.elementwiseMult(Sequence{ "0" }, 100) ; skip ; skip ; if __name__ = "__main__" then ( weight->first() := "" ; weight[1+1] := "abc" ; weight[2+1] := "aba" ; weight[3+1] := "bcb" ; weight[4+1] := "moh" ; weight[5+1] := "aa" ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 3))))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 4))))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 5))))))))) )))) ; dfs(1, 1) ; execute (cnt)->display() ) else skip; operation isPalindrome(x : OclAny) : OclAny pre: true post: true activity: var n : int := (x)->size() ; for i : Integer.subrange(0, n div 2-1) do ( if x[i+1] /= x[n - 1 - i+1] then ( return false ) else skip) ; return true; operation dfs(node : OclAny, parent : OclAny) pre: true post: true activity: skip ; x := weight[node+1] ; if (isPalindrome(x)) then ( cnt := cnt + 1 ) else skip ; for to : graph[node+1] do ( if to = parent then ( continue ) else skip ; dfs(to, node)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=256 def countPairs(s): cnt=[0 for i in range(0,MAX)] for i in range(len(s)): cnt[ord(s[i])-97]+=1 ans=0 for i in range(0,MAX): ans+=cnt[i]*cnt[i] return ans if __name__=="__main__" : s="geeksforgeeks" print(countPairs(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 256 ; skip ; if __name__ = "__main__" then ( s := "geeksforgeeks" ; execute (countPairs(s))->display() ) else skip; operation countPairs(s : OclAny) : OclAny pre: true post: true activity: var cnt : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, (s)->size()-1) do ( cnt[(s[i+1])->char2byte() - 97+1] := cnt[(s[i+1])->char2byte() - 97+1] + 1) ; var ans : int := 0 ; for i : Integer.subrange(0, MAX-1) do ( ans := ans + cnt[i+1] * cnt[i+1]) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): F=set(map(int,input().split())) fl=min(F); fr=max(F) G={i for i in range(1,14)}-F-{7} gl=min(G); gr=max(G) memo={} def dfs(s,t,u): if(s,t,u)in memo : return memo[s,t,u] T=[G,F][u] res=0 if s-1 in T : if s-1<=[gl,fl][u]and[gr,fr][u]<=t : res=1 else : res |=dfs(s-1,t,u ^ 1)^ 1 if t+1 in T : if s<=[gl,fl][u]and[gr,fr][u]<=t+1 : res=1 else : res |=dfs(s,t+1,u ^ 1)^ 1 if s-1 not in T and t+1 not in T : res=dfs(s,t,u ^ 1)^ 1 memo[s,t,u]=res return res print(["no","yes"][dfs(7,7,1)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var F : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var fl : OclAny := (F)->min(); var fr : OclAny := (F)->max() ; var G : double := Integer.subrange(1, 14-1)->select(i | true)->collect(i | i)->asSet() - F - Set{ 7 } ; var gl : OclAny := (G)->min(); var gr : OclAny := (G)->max() ; var memo : OclAny := Set{} ; skip ; execute (Sequence{"no"}->union(Sequence{ "yes" })[dfs(7, 7, 1)+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def search(a_cards,b_cards,left,right,turn): if a_cards==[]: return True if b_cards==[]: return False ret=False if turn==0 : if left not in a_cards and right not in a_cards : return search(a_cards,b_cards,left,right,1) if left in a_cards : ret=ret or search([i for i in a_cards if i!=left],b_cards,left-1,right,1) if right in a_cards : ret=ret or search([i for i in a_cards if i!=right],b_cards,left,right+1,1) return ret ret=True if turn==1 : if left not in b_cards and right not in b_cards : return search(a_cards,b_cards,left,right,0) if left in b_cards : ret=ret and search(a_cards,[i for i in b_cards if i!=left],left-1,right,0) if right in b_cards : ret=ret and search(a_cards,[i for i in b_cards if i!=right],left,right+1,0) return ret n=int(input()) all_cards=[i+1 for i in range(13)if i!=6] for _ in range(n): a_cards=list(map(int,input().split())) b_cards=[i for i in all_cards if i not in a_cards] if search(a_cards,b_cards,6,8,0): print("yes") else : print("no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var all_cards : Sequence := Integer.subrange(0, 13-1)->select(i | i /= 6)->collect(i | (i + 1)) ; for _anon : Integer.subrange(0, n-1) do ( a_cards := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; b_cards := all_cards->select(i | (a_cards)->excludes(i))->collect(i | (i)) ; if search(a_cards, b_cards, 6, 8, 0) then ( execute ("yes")->display() ) else ( execute ("no")->display() )); operation search(a_cards : OclAny, b_cards : OclAny, left : OclAny, right : OclAny, turn : OclAny) : OclAny pre: true post: true activity: if a_cards = Sequence{} then ( return true ) else skip ; if b_cards = Sequence{} then ( return false ) else skip ; var ret : boolean := false ; if turn = 0 then ( if (a_cards)->excludes(left) & (a_cards)->excludes(right) then ( return search(a_cards, b_cards, left, right, 1) ) else skip ; if (a_cards)->includes(left) then ( ret := ret or search(a_cards->select(i | i /= left)->collect(i | (i)), b_cards, left - 1, right, 1) ) else skip ; if (a_cards)->includes(right) then ( ret := ret or search(a_cards->select(i | i /= right)->collect(i | (i)), b_cards, left, right + 1, 1) ) else skip ; return ret ) else skip ; ret := true ; if turn = 1 then ( if (b_cards)->excludes(left) & (b_cards)->excludes(right) then ( return search(a_cards, b_cards, left, right, 0) ) else skip ; if (b_cards)->includes(left) then ( ret := ret & search(a_cards, b_cards->select(i | i /= left)->collect(i | (i)), left - 1, right, 0) ) else skip ; if (b_cards)->includes(right) then ( ret := ret & search(a_cards, b_cards->select(i | i /= right)->collect(i | (i)), left, right + 1, 0) ) else skip ; return ret ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout import math n=int(stdin.readline().strip()) reserved=1 maxspeed=1 while True : if reserved+maxspeed*3>n : break maxspeed*=3 reserved+=maxspeed*2 ans=1 n-=1 i=3 while itrim())))->toInteger() ; var reserved : int := 1 ; var maxspeed : int := 1 ; while true do ( if (reserved + maxspeed * 3->compareTo(n)) > 0 then ( break ) else skip ; maxspeed := maxspeed * 3 ; reserved := reserved + maxspeed * 2) ; var ans : int := 1 ; n := n - 1 ; var i : int := 3 ; while (i->compareTo(maxspeed)) < 0 do ( ans := ans + 2 ; n := n - i * 2 ; i := i * 3) ; n := n - maxspeed ; i := maxspeed ; while i do ( ans := ans + n div i ; n := n - n div i * i ; i := i div 3) ; stdout.writelines(("" + ((ans + 1))) + ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) count=0 speed=1 margin=0 while t>0 : t-=speed count+=1 if margin+speed*3<=t : speed*=3 margin+=speed elif ttoInteger() ; var count : int := 0 ; var speed : int := 1 ; var margin : int := 0 ; while t > 0 do ( t := t - speed ; count := count + 1 ; if (margin + speed * 3->compareTo(t)) <= 0 then ( speed := speed * 3 ; margin := margin + speed ) else (if (t->compareTo(margin)) < 0 then ( margin := margin - speed ; speed := speed / 3 ) else skip)) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import sys def main(): T=read_int() print(solve(T)) def solve(T): if T<=3 : return T sec=1 T-=1 f=3 while T>=2*f : T-=2*f f*=3 sec+=2 if T>=f : T-=f sec+=1 else : f//=3 while T>0 : t=T//f T-=t*f sec+=t f//=3 return sec DEBUG='DEBUG' in os.environ def inp(): return sys.stdin.readline().rstrip() def read_int(): return int(inp()) def read_ints(): return[int(e)for e in inp().split()] def dprint(*value,sep=' ',end='\n'): if DEBUG : print(*value,sep=sep,end=end) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var DEBUG : boolean := (os.environ)->includes('DEBUG') ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var T : OclAny := read_int() ; execute (solve(T))->display(); operation solve(T : OclAny) : OclAny pre: true post: true activity: if T <= 3 then ( return T ) else skip ; var sec : int := 1 ; T := T - 1 ; var f : int := 3 ; while (T->compareTo(2 * f)) >= 0 do ( T := T - 2 * f ; f := f * 3 ; sec := sec + 2) ; if (T->compareTo(f)) >= 0 then ( T := T - f ; sec := sec + 1 ) else ( f := f div 3 ) ; while T > 0 do ( var t : int := T div f ; T := T - t * f ; sec := sec + t ; f := f div 3) ; return sec; operation inp() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation read_int() : OclAny pre: true post: true activity: return ("" + ((inp())))->toInteger(); operation read_ints() : OclAny pre: true post: true activity: return inp().split()->select(e | true)->collect(e | (("" + ((e)))->toInteger())); operation dprint(value : OclAny : Sequence(OclAny), sep : String, end : String) pre: true post: true activity: (args * (named_parameter (name value))) if sep->oclIsUndefined() then sep := ' ' else skip; if end->oclIsUndefined() then end := ' ' else skip; if DEBUG then ( execute ((argument * (test (logical_test (comparison (expr (atom (name value))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def predictFeature(a,b): if a==b : return a else : if 'S' in(a,b): pass else : return 'S' if 'T' in(a,b): pass else : return 'T' return 'E' def hyperSet(n,k,l): d={} for x in l : if x not in d : d[x]=1 else : d[x]+=1 ans=0 for i in range(n): for j in range(n): if i!=j : w='' for x in range(k): w+=predictFeature(l[i][x],l[j][x]) if w in d : c=0 if w==l[i]: c+=1 if w==l[j]: c+=1 ans+=d[w]-c return ans//6 n,k=map(int,input().split()) l=[] for _ in range(n): l.append(input()) print(hyperSet(n,k,l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; l := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : l)) ; execute (hyperSet(n, k, l))->display(); operation predictFeature(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a = b then ( return a ) else ( if (Sequence{a, b})->includes('S') then ( skip ) else ( return 'S' ) ; if (Sequence{a, b})->includes('T') then ( skip ) else ( return 'T' ) ; return 'E' ); operation hyperSet(n : OclAny, k : OclAny, l : OclAny) : OclAny pre: true post: true activity: var d : OclAny := Set{} ; for x : l do ( if (d)->excludes(x) then ( d[x+1] := 1 ) else ( d[x+1] := d[x+1] + 1 )) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if i /= j then ( var w : String := '' ; for x : Integer.subrange(0, k-1) do ( w := w + predictFeature(l[i+1][x+1], l[j+1][x+1])) ; if (d)->includes(w) then ( var c : int := 0 ; if w = l[i+1] then ( c := c + 1 ) else skip ; if w = l[j+1] then ( c := c + 1 ) else skip ; ans := ans + d->at(w) - c ) else skip ) else skip)) ; return ans div 6; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import io,os input=sys.stdin.readline N,K=map(int,input().split()) S=[] T=set() for i in range(N): s=str(input().rstrip()) S.append(s) T.add(s) ans=0 for i in range(N-1): s=S[i] for j in range(i+1,N): t=S[j] temp=[] for k in range(K): if s[k]==t[k]: temp.append(s[k]) if(s[k]=='S' and t[k]=='E')or(s[k]=='E' and t[k]=='S'): temp.append('T') if(s[k]=='S' and t[k]=='T')or(s[k]=='T' and t[k]=='S'): temp.append('E') if(s[k]=='T' and t[k]=='E')or(s[k]=='E' and t[k]=='T'): temp.append('S') temp=''.join(temp) if temp in T : ans+=1 print(ans//3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : Sequence := Sequence{} ; var T : Set := Set{}->union(()) ; for i : Integer.subrange(0, N-1) do ( var s : String := ("" + ((input().rstrip()))) ; execute ((s) : S) ; execute ((s) : T)) ; var ans : int := 0 ; for i : Integer.subrange(0, N - 1-1) do ( s := S[i+1] ; for j : Integer.subrange(i + 1, N-1) do ( var t : OclAny := S[j+1] ; var temp : Sequence := Sequence{} ; for k : Integer.subrange(0, K-1) do ( if s[k+1] = t[k+1] then ( execute ((s[k+1]) : temp) ) else skip ; if (s[k+1] = 'S' & t[k+1] = 'E') or (s[k+1] = 'E' & t[k+1] = 'S') then ( execute (('T') : temp) ) else skip ; if (s[k+1] = 'S' & t[k+1] = 'T') or (s[k+1] = 'T' & t[k+1] = 'S') then ( execute (('E') : temp) ) else skip ; if (s[k+1] = 'T' & t[k+1] = 'E') or (s[k+1] = 'E' & t[k+1] = 'T') then ( execute (('S') : temp) ) else skip) ; temp := StringLib.sumStringsWithSeparator((temp), '') ; if (T)->includes(temp) then ( ans := ans + 1 ) else skip)) ; execute (ans div 3)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter def inpl(): return tuple(map(int,input().split())) N=int(input()) A=list(map(int,input().split())) C=Counter(A) if C[-2]% 2==0 : ans=[i+1 for i,a in enumerate(A)if abs(a)==2] print(len(ans)) if len(ans): print(*ans,sep="\n") elif C[-1]>0 : ans=[i+1 for i,a in enumerate(A)if abs(a)==2]+[A.index(-1)+1] print(len(ans)) if len(ans): print(*sorted(ans),sep="\n") else : d=N-A[: :-1].index(-2) ans=[i+1 for i,a in enumerate(A)if abs(a)==2] del ans[ans.index(d)] print(len(ans)) if len(ans): print(*ans,sep="\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var C : OclAny := Counter(A) ; if C->front()->last() mod 2 = 0 then ( var ans : Sequence := Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} )->select(_tuple | let i : OclAny = _tuple->at(1) in let a : OclAny = _tuple->at(2) in (a)->abs() = 2)->collect(_tuple | let i : OclAny = _tuple->at(1) in let a : OclAny = _tuple->at(2) in (i + 1)) ; execute ((ans)->size())->display() ; if (ans)->size() then ( execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ) else skip ) else (if C->last() > 0 then ( ans := Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} )->select(_tuple | let i : OclAny = _tuple->at(1) in let a : OclAny = _tuple->at(2) in (a)->abs() = 2)->collect(_tuple | let i : OclAny = _tuple->at(1) in let a : OclAny = _tuple->at(2) in (i + 1))->union(Sequence{ A->indexOf(-1) - 1 + 1 }) ; execute ((ans)->size())->display() ; if (ans)->size() then ( execute ((argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) )))))))))->display() ) else skip ) else ( var d : double := N - A(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->indexOf(-2) - 1 ; ans := Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} )->select(_tuple | let i : OclAny = _tuple->at(1) in let a : OclAny = _tuple->at(2) in (a)->abs() = 2)->collect(_tuple | let i : OclAny = _tuple->at(1) in let a : OclAny = _tuple->at(2) in (i + 1)) ; execute (ans[ans->indexOf(d) - 1+1])->isDeleted() ; execute ((ans)->size())->display() ; if (ans)->size() then ( execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ) else skip ) ) ; operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lx,ly=[4,2],[2,4] dx=[-1,0,1,0] dy=[0,-1,0,1] while 1 : w,h=map(int,raw_input().split()) if w==0 and h==0 : break xs,ys=map(int,raw_input().split()) xg,yg=map(int,raw_input().split()) f=[[0 for i in range(102)]for j in range(102)] s=[] n=input() for i in range(n): c,d,x,y=map(int,raw_input().split()) for p in range(lx[d]): for q in range(ly[d]): f[y+q][x+p]=c ans=0 if f[ys][xs]>0 and f[ys][xs]==f[yg][xg]: c=f[ys][xs] s.append([xs,ys]) while len(s)>0 : x,y=s.pop() if x==xg and y==yg : ans=1 ; break ; for k in range(4): if f[y+dy[k]][x+dx[k]]==c : s.append([x+dx[k],y+dy[k]]) f[y+dy[k]][x+dx[k]]=0 print("OK" if ans==1 else "NG") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lx : OclAny := null; var ly : OclAny := null; Sequence{lx,ly} := Sequence{Sequence{4}->union(Sequence{ 2 }),Sequence{2}->union(Sequence{ 4 })} ; var dx : Sequence := Sequence{-1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 0 }))) ; var dy : Sequence := Sequence{0}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{ 1 }))) ; while 1 do ( var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if w = 0 & h = 0 then ( break ) else skip ; var xs : OclAny := null; var ys : OclAny := null; Sequence{xs,ys} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var xg : OclAny := null; var yg : OclAny := null; Sequence{xg,yg} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var f : Sequence := Integer.subrange(0, 102-1)->select(j | true)->collect(j | (Integer.subrange(0, 102-1)->select(i | true)->collect(i | (0)))) ; var s : Sequence := Sequence{} ; var n : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, n-1) do ( var c : OclAny := null; var d : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{c,d,x,y} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for p : Integer.subrange(0, lx[d+1]-1) do ( for q : Integer.subrange(0, ly[d+1]-1) do ( f[y + q+1][x + p+1] := c))) ; var ans : int := 0 ; if f[ys+1][xs+1] > 0 & f[ys+1][xs+1] = f[yg+1][xg+1] then ( var c : OclAny := f[ys+1][xs+1] ; execute ((Sequence{xs}->union(Sequence{ ys })) : s) ; while (s)->size() > 0 do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := s->last() ; s := s->front() ; if x = xg & y = yg then ( ans := 1; break; ) else skip ; for k : Integer.subrange(0, 4-1) do ( if f[y + dy[k+1]+1][x + dx[k+1]+1] = c then ( execute ((Sequence{x + dx[k+1]}->union(Sequence{ y + dy[k+1] })) : s) ; f[y + dy[k+1]+1][x + dx[k+1]+1] := 0 ) else skip)) ) else skip ; execute (if ans = 1 then "OK" else "NG" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import deque while True : W,H=map(int,input().split()) if W==0 : break (xs,ys),(xg,yg)=map(int,input().split()),map(int,input().split()) square=[[0]*(W+2)for _ in[0]*(H+2)] visited=[[0]*(W+2)for _ in[0]*(H+2)] visited[ys][xs]=1 N=int(input()) for c,d,from_x,from_y in(map(int,sys.stdin.readline().split())for _ in[0]*N): to_x,to_y=(from_x+4,from_y+2)if d==0 else(from_x+2,from_y+4) for y in range(from_y,to_y): square[y][from_x : to_x]=[c]*(to_x-from_x) color=square[ys][xs]or-1 dq=deque([(ys,xs)]) popleft,append=dq.popleft,dq.append while dq : y,x=popleft() if y==yg and x==xg : print("OK") break for ny,nx in((y+1,x),(y-1,x),(y,x+1),(y,x-1)): if not visited[ny][nx]and square[ny][nx]==color : visited[ny][nx]=1 append((ny,nx)) else : print("NG") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( var W : OclAny := null; var H : OclAny := null; Sequence{W,H} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if W = 0 then ( break ) else skip) ; var Sequence{xs, ys} : OclAny := null; var Sequence{xg, yg} : OclAny := null; Sequence{Sequence{xs, ys},Sequence{xg, yg}} := Sequence{(input().split())->collect( _x | (OclType["int"])->apply(_x) ),(input().split())->collect( _x | (OclType["int"])->apply(_x) )}; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt prime=[0]*100005 def SieveOfEratosthenes(n): for i in range(len(prime)): prime[i]=True prime[1]=False for p in range(2,int(sqrt(n))+1): if prime[p]==True : for i in range(p*2,n,p): prime[i]=False def sortedArray(arr,n): SieveOfEratosthenes(100005) v=[] for i in range(n): if prime[arr[i]]==0 : v.append(arr[i]) v.sort() j=0 for i in range(n): if prime[arr[i]]==True : print(arr[i],end=" ") else : print(v[j],end=" ") j+=1 if __name__=="__main__" : n=6 arr=[100,11,500,2,17,1] sortedArray(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100005) ; skip ; skip ; if __name__ = "__main__" then ( n := 6 ; arr := Sequence{100}->union(Sequence{11}->union(Sequence{500}->union(Sequence{2}->union(Sequence{17}->union(Sequence{ 1 }))))) ; sortedArray(arr, n) ) else skip; operation SieveOfEratosthenes(n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, (prime)->size()-1) do ( prime[i+1] := true) ; prime[1+1] := false ; for p : Integer.subrange(2, ("" + ((sqrt(n))))->toInteger() + 1-1) do ( if prime[p+1] = true then ( for i : Integer.subrange(p * 2, n-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip); operation sortedArray(arr : OclAny, n : OclAny) pre: true post: true activity: SieveOfEratosthenes(100005) ; var v : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if prime[arr[i+1]+1] = 0 then ( execute ((arr[i+1]) : v) ) else skip) ; v := v->sort() ; var j : int := 0 ; for i : Integer.subrange(0, n-1) do ( if prime[arr[i+1]+1] = true then ( execute (arr[i+1])->display() ) else ( execute (v[j+1])->display() ; j := j + 1 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(a==0 or b==0): False if(a==b): return a if(a>b): return gcd(a-b,b) return gcd(a,b-a) a=98 b=56 if(gcd(a,b)): print('GCD of',a,'and',b,'is',gcd(a,b)) else : print('not found') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 98 ; b := 56 ; if (gcd(a, b)) then ( execute ('GCD of')->display() ) else ( execute ('not found')->display() ); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0 or b = 0) then ( ) else skip ; if (a = b) then ( return a ) else skip ; if ((a->compareTo(b)) > 0) then ( return gcd(a - b, b) ) else skip ; return gcd(a, b - a); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(b==0): return a return gcd(b,a % b) a=98 b=56 if(gcd(a,b)): print('GCD of',a,'and',b,'is',gcd(a,b)) else : print('not found') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 98 ; b := 56 ; if (gcd(a, b)) then ( execute ('GCD of')->display() ) else ( execute ('not found')->display() ); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (b = 0) then ( return a ) else skip ; return gcd(b, a mod b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(a==0): return b if(b==0): return a if(a==b): return a if(a>b): return gcd(a-b,b) return gcd(a,b-a) a=98 b=56 if(gcd(a,b)): print('GCD of',a,'and',b,'is',gcd(a,b)) else : print('not found') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 98 ; b := 56 ; if (gcd(a, b)) then ( execute ('GCD of')->display() ) else ( execute ('not found')->display() ); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0) then ( return b ) else skip ; if (b = 0) then ( return a ) else skip ; if (a = b) then ( return a ) else skip ; if ((a->compareTo(b)) > 0) then ( return gcd(a - b, b) ) else skip ; return gcd(a, b - a); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if a==0 : return b return gcd(b % a,a) def lcm(a,b): return(a*b)/gcd(a,b) a=15 b=20 print('LCM of',a,'and',b,'is',lcm(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 15 ; b := 20 ; execute ('LCM of')->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a = 0 then ( return b ) else skip ; return gcd(b mod a, a); operation lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a * b) / gcd(a, b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(b==0): return a return gcd(b,a % b) a=98 b=56 if(gcd(a,b)): print('GCD of',a,'and',b,'is',gcd(a,b)) else : print('not found') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 98 ; b := 56 ; if (gcd(a, b)) then ( execute ('GCD of')->display() ) else ( execute ('not found')->display() ); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (b = 0) then ( return a ) else skip ; return gcd(b, a mod b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if a==0 : return b return gcd(b % a,a) def lcm(a,b): return(a*b)/gcd(a,b) a=15 b=20 print('LCM of',a,'and',b,'is',lcm(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 15 ; b := 20 ; execute ('LCM of')->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a = 0 then ( return b ) else skip ; return gcd(b mod a, a); operation lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a * b) / gcd(a, b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib,sys def compute(): x,y,m=1777,1855,10**8 sys.setrecursionlimit(y+30) ans=tetration_mod(x,y,m) return str(ans) def tetration_mod(x,y,m): if y==1 : return x % m else : return pow(x,tetration_mod(x,y-1,totient(m)),m) def totient(n): assert n>0 p=1 i=2 end=eulerlib.sqrt(n) while i<=end : if n % i==0 : p*=i-1 n//=i while n % i==0 : p*=i n//=i end=eulerlib.sqrt(n) i+=1 if n!=1 : p*=n-1 return p if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; var m : OclAny := null; Sequence{x,y,m} := Sequence{1777,1855,(10)->pow(8)} ; sys.setrecursionlimit(y + 30) ; var ans : OclAny := tetration_mod(x, y, m) ; return ("" + ((ans))); operation tetration_mod(x : OclAny, y : OclAny, m : OclAny) : OclAny pre: true post: true activity: if y = 1 then ( return x mod m ) else ( return (x)->pow(tetration_mod(x, y - 1, totient(m))) ); operation totient(n : OclAny) : OclAny pre: true post: true activity: assert n > 0 do "assertion failed" ; var p : int := 1 ; var i : int := 2 ; var end : double := eulerlib.sqrt(n) ; while (i->compareTo(end)) <= 0 do ( if n mod i = 0 then ( p := p * i - 1 ; n := n div i ; while n mod i = 0 do ( p := p * i ; n := n div i) ; end := eulerlib.sqrt(n) ) else skip ; i := i + 1) ; if n /= 1 then ( p := p * n - 1 ) else skip ; return p; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def min_sum(n,k,a): a.sort(reverse=False) if(a[0]<0): return-1 if(k==0): if(a[0]==a[n-1]): return(n*a[0]) else : return-1 else : f=0 for i in range(1,n,1): p=a[i]-a[0] if(p % k==0): continue else : f=1 break if(f): return-1 else : if(k==1): return n else : return(n*(a[0]% k)) if __name__=='__main__' : arr=[2,3,4,5] K=1 N=len(arr) print(min_sum(N,K,arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var arr : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 }))) ; var K : int := 1 ; var N : int := (arr)->size() ; execute (min_sum(N, K, arr))->display() ) else skip; operation min_sum(n : OclAny, k : OclAny, a : OclAny) : OclAny pre: true post: true activity: a := a->sort() ; if (a->first() < 0) then ( return -1 ) else skip ; if (k = 0) then ( if (a->first() = a[n - 1+1]) then ( return (n * a->first()) ) else ( return -1 ) ) else ( var f : int := 0 ; for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( var p : double := a[i+1] - a->first() ; if (p mod k = 0) then ( continue ) else ( f := 1 ; break )) ; if (f) then ( return -1 ) else ( if (k = 1) then ( return n ) else ( return (n * (a->first() mod k)) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def alternate(a,b,x): x=a ^ b ^ x print("After exchange") print("x is",x) a=-10 b=15 x=a print("x is",x) alternate(a,b,x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := -10 ; b := 15 ; x := a ; execute ("x is")->display() ; alternate(a, b, x); operation alternate(a : OclAny, b : OclAny, x : OclAny) pre: true post: true activity: x := MathLib.bitwiseXor(MathLib.bitwiseXor(a, b), x) ; execute ("After exchange")->display() ; execute ("x is")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def removeNthFromEnd(self,head,n): if head is None : return None slow=fast=head for i in range(n): fast=fast.next if fast is None : head=head.next return head while fast.next is not None : fast=fast.next slow=slow.next curr=slow.next slow.next=curr.next return head ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation removeNthFromEnd(head : OclAny,n : OclAny) : OclAny pre: true post: true activity: if head <>= null then ( return null ) else skip ; var slow : OclAny := head; var fast : OclAny := head ; for i : Integer.subrange(0, n-1) do ( fast := fast.next) ; if fast <>= null then ( head := head.next ; return head ) else skip ; while not(fast.next <>= null) do ( fast := fast.next ; slow := slow.next) ; var curr : OclAny := slow.next ; slow.next := curr.next ; return head; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): l=[int(i)for i in input().split(' ')] ls=[max(l[: 2]),max(l[2 :])] if sorted(ls)==sorted(l)[2 :]: print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var l : Sequence := input().split(' ')->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ls : Sequence := Sequence{(l.subrange(1,2))->max()}->union(Sequence{ (l.subrange(2+1))->max() }) ; if ls->sort() = sorted(l).subrange(2+1) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMaxLenEven(str): n=len(str) i=0 currlen=0 maxlen=0 st=-1 while(idisplay() ) else skip; operation findMaxLenEven(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var n : int := (OclType["String"])->size() ; var i : int := 0 ; var currlen : int := 0 ; var maxlen : int := 0 ; var st : int := -1 ; while ((i->compareTo(n)) < 0) do ( if (("" + ([i+1])) = ' ') then ( if (currlen mod 2 = 0) then ( if ((maxlen->compareTo(currlen)) < 0) then ( maxlen := currlen ; st := i - currlen ) else skip ) else skip ; currlen := 0 ) else ( currlen := currlen + 1 ) ; i := i + 1) ; if (currlen mod 2 = 0) then ( if ((maxlen->compareTo(currlen)) < 0) then ( maxlen := currlen ; st := i - currlen ) else skip ) else skip ; if (st = -1) then ( execute ("trie")->display() ; return "-1" ) else skip ; return ("" + (.subrange(st+1, st + maxlen))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pairsInSortedRotated(arr,n,x): for i in range(n): if arr[i]>arr[i+1]: break l=(i+1)% n r=i cnt=0 while(l!=r): if arr[l]+arr[r]==x : cnt+=1 if l==(r-1+n)% n : return cnt l=(l+1)% n r=(r-1+n)% n elif arr[l]+arr[r]union(Sequence{15}->union(Sequence{6}->union(Sequence{7}->union(Sequence{9}->union(Sequence{ 10 }))))) ; var s : int := 16 ; execute (pairsInSortedRotated(arr, 6, s))->display(); operation pairsInSortedRotated(arr : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if (arr[i+1]->compareTo(arr[i + 1+1])) > 0 then ( break ) else skip) ; var l : int := (i + 1) mod n ; var r : OclAny := i ; var cnt : int := 0 ; while (l /= r) do ( if arr[l+1] + arr[r+1] = x then ( cnt := cnt + 1 ; if l = (r - 1 + n) mod n then ( return cnt ) else skip ; l := (l + 1) mod n ; r := (r - 1 + n) mod n ) else (if (arr[l+1] + arr[r+1]->compareTo(x)) < 0 then ( l := (l + 1) mod n ) else ( r := (n + r - 1) mod n ) ) ) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools def compute(): LIMIT=10**6 for n in itertools.count(LIMIT): if least_divisible_repunit(n)>LIMIT : return str(n) def least_divisible_repunit(n): if n % 2==0 or n % 5==0 : return 0 k=1 s=1 p=1 while s % n!=0 : k+=1 p=p*10 % n s=(s+p)% n return k if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LIMIT : double := (10)->pow(6) ; for n : itertools->count(LIMIT) do ( if (least_divisible_repunit(n)->compareTo(LIMIT)) > 0 then ( return ("" + ((n))) ) else skip); operation least_divisible_repunit(n : OclAny) : OclAny pre: true post: true activity: if n mod 2 = 0 or n mod 5 = 0 then ( return 0 ) else skip ; var k : int := 1 ; var s : int := 1 ; var p : int := 1 ; while s mod n /= 0 do ( k := k + 1 ; p := p * 10 mod n ; s := (s + p) mod n) ; return k; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getPassingCars(A,n): countOne=0 ; result=0 while n>=1 : if A[n-1]==1 : countOne+=1 else : result+=countOne n-=1 return result A=[0,1,0,1,1] n=len(A) print(getPassingCars(A,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; A := Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 1 })))) ; n := (A)->size() ; execute (getPassingCars(A, n))->display(); operation getPassingCars(A : OclAny, n : OclAny) : OclAny pre: true post: true activity: var countOne : int := 0; var result : int := 0 ; while n >= 1 do ( if A[n - 1+1] = 1 then ( countOne := countOne + 1 ) else ( result := result + countOne ) ; n := n - 1) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib,itertools def compute(): ans=next(itertools.filterfalse(test_goldbach,itertools.count(9,2))) return str(ans) def test_goldbach(n): if n % 2==0 or eulerlib.is_prime(n): return True for i in itertools.count(1): k=n-2*i*i if k<=0 : return False elif eulerlib.is_prime(k): return True if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : OclAny := (itertools.filterfalse(test_goldbach, itertools->count(9, 2))).next() ; return ("" + ((ans))); operation test_goldbach(n : OclAny) : OclAny pre: true post: true activity: if n mod 2 = 0 or eulerlib.is_prime(n) then ( return true ) else skip ; for i : itertools->count(1) do ( var k : double := n - 2 * i * i ; if k <= 0 then ( return false ) else (if eulerlib.is_prime(k) then ( return true ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m,k=map(int,input().split()) l=[int(x)for x in input().split()] i=0 while(itoInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var i : int := 0 ; while ((i->compareTo(n - 1)) < 0) do ( var x : OclAny := Set{k - l[i + 1+1], 0}->min() ; m := m + (l[i+1] + x) ; if m < 0 then ( break ) else skip ; i := i + 1) ; if i = n - 1 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,m,k=map(int,input().split(" ")) hv=list(map(int,input().split(" "))) f=True for i in range(n-1): m+=hv[i]-max(0,hv[i+1]-k) if m<0 : f=False break if f : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var hv : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var f : boolean := true ; for i : Integer.subrange(0, n - 1-1) do ( m := m + hv[i+1] - Set{0, hv[i + 1+1] - k}->max() ; if m < 0 then ( f := false ; break ) else skip) ; if f then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n,m,k=map(int,input().split()) w=list(map(int,input().split())) if n==1 : print("YES") else : for i in range(n-1): c=max(0,w[i+1]-k) m+=w[i]-c if m<0 : print("NO") break else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = 1 then ( execute ("YES")->display() ) else ( (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))) - (expr (atom (name k))))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name m)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name c)))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name m)))) < (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) ))))))))))))))) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while(t): t-=1 n,m,k=map(int,input().split()) if k is None or k=='' : k=0 arr=list(map(int,input().split())) for i in range(1,n): m+=arr[i-1]-max(0,arr[i]-k) if m<0 : print('NO') break else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (t) do ( t := t - 1 ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if k <>= null or k = '' then ( var k : int := 0 ) else skip ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name m)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))) - (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name k))))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name m)))) < (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solver(object): @ classmethod def setup(cls,infile): cls.data={} def __init__(self,infile,tc): self.tc=tc self.I=I=map(int,infile.next().split()) def solve(self): import itertools as it S=self.I[1 :] seen={} for n in xrange(1,4): for s in it.combinations(S,n): ss=sum(s) if ss in seen : return 'Case #%s:\n%s\n%s\n' %(self.tc,' '.join('%d' % i for i in s),' '.join('%d' % i for i in seen[ss]),) seen[ss]=s return 'Case #%s: Impossible\n' %(self.tc,) if __name__=='__main__' : import sys T=int(sys.stdin.next()) Solver.setup(sys.stdin) for t in xrange(1,T+1): sys.stdout.write(Solver(sys.stdin,t).solve()) ------------------------------------------------------------ OCL File: --------- class Solver extends object { static operation newSolver() : Solver pre: true post: Solver->exists( _x | result = _x ); attribute tc : OclAny := tc; attribute I : OclAny := (infile.next().split())->collect( _x | (OclType["int"])->apply(_x) ); var I : Sequence := (infile.next().split())->collect( _x | (OclType["int"])->apply(_x) ); operation initialise(infile : OclAny,tc : OclAny) : pre: true post: true activity: self.tc := tc ; self.I := (infile.next().split())->collect( _x | (OclType["int"])->apply(_x) ); var I : Sequence := (infile.next().split())->collect( _x | (OclType["int"])->apply(_x) ); return self; operation solve() : OclAny pre: true post: true activity: skip ; var S : OclAny := self.I->tail() ; var seen : OclAny := Set{} ; for n : xrange(1, 4) do ( for s : it.combinations(S, n) do ( var ss : OclAny := (s)->sum() ; if (seen)->includes(ss) then ( return StringLib.format('Case #%s: %s %s ',Sequence{self.tc, StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (expr (atom '%d')) % (expr (atom (name i))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name s)))))))), ' '), (testlist_comp (test (logical_test (comparison (expr (atom ' ') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom '%d')) % (expr (atom (name i))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name seen)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ss)))))))) ])))))))) ))))))) ,)}) ) else skip ; seen[ss+1] := s)) ; return StringLib.format('Case #%s: Impossible ',Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name self)) (trailer . (name tc)))))) ,)}); } class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( skip ; var T : int := ("" + (((OclFile["System.in"]).next())))->toInteger() ; Solver.setup(OclFile["System.in"]) ; for t : xrange(1, T + 1) do ((expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name Solver)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin))))))) , (argument (test (logical_test (comparison (expr (atom (name t)))))))) ))) (trailer . (name solve) (arguments ( ))))))))) ))))) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict import math def createHash(hash1,maxElement): prev,curr=0,1 hash1.add(prev) hash1.add(curr) while(curr<=maxElement): temp=curr+prev if temp<=maxElement : hash1.add(temp) prev=curr curr=temp def gcdFibonacciFreq(arr,n): hash1=set() createHash(hash1,max(arr)) m=defaultdict(int) for i in range(n): m[arr[i]]+=1 gcd=0 for it in m.keys(): if(m[it]in hash1): gcd=math.gcd(gcd,it) return gcd if __name__=="__main__" : arr=[5,3,6,5,6,6,5,5] n=len(arr) print(gcdFibonacciFreq(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{5}->union(Sequence{3}->union(Sequence{6}->union(Sequence{5}->union(Sequence{6}->union(Sequence{6}->union(Sequence{5}->union(Sequence{ 5 }))))))) ; n := (arr)->size() ; execute (gcdFibonacciFreq(arr, n))->display() ) else skip; operation createHash(hash1 : OclAny, maxElement : OclAny) pre: true post: true activity: var prev : OclAny := null; var curr : OclAny := null; Sequence{prev,curr} := Sequence{0,1} ; execute ((prev) : hash1) ; execute ((curr) : hash1) ; while ((curr->compareTo(maxElement)) <= 0) do ( var temp : OclAny := curr + prev ; if (temp->compareTo(maxElement)) <= 0 then ( execute ((temp) : hash1) ) else skip ; var prev : OclAny := curr ; var curr : OclAny := temp); operation gcdFibonacciFreq(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: hash1 := Set{}->union(()) ; createHash(hash1, (arr)->max()) ; var m : OclAny := defaultdict(OclType["int"]) ; for i : Integer.subrange(0, n-1) do ( m[arr[i+1]+1] := m[arr[i+1]+1] + 1) ; var gcd : int := 0 ; for it : m.keys() do ( if ((hash1)->includes(m[it+1])) then ( gcd := (gcd)->gcd(it) ) else skip) ; return gcd; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math t=int(input()) for t in range(t): n,blocks,k=map(int,input().split()) towers=list(map(int,input().split())) yes=True for i in range(n-1): blocks+=towers[i]-max((towers[i+1]-k),0) if(blocks<0): yes=False if(yes): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(0, t-1) do ( var n : OclAny := null; var blocks : OclAny := null; var k : OclAny := null; Sequence{n,blocks,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var towers : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var yes : boolean := true ; for i : Integer.subrange(0, n - 1-1) do ( blocks := blocks + towers[i+1] - Set{(towers[i + 1+1] - k), 0}->max() ; if (blocks < 0) then ( yes := false ) else skip) ; if (yes) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMinRemoval(arr,n): value=0 maximum=0 if(n==1): return 0 for i in range(n): if(i!=0 and i!=n-1): value=value+abs(arr[i]-arr[i+1]) temp=(abs(arr[i]-arr[i+1])+abs(arr[i]-arr[i-1])-abs(arr[i-1]-arr[i+1])) elif(i==0): value=value+abs(arr[i]-arr[i+1]) temp=abs(arr[i]-arr[i+1]) else : temp=abs(arr[i]-arr[i-1]) maximum=max(maximum,temp) return(value-maximum) if __name__=="__main__" : arr=[1,5,3,2,10] n=len(arr) print(findMinRemoval(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{5}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 10 })))) ; n := (arr)->size() ; execute (findMinRemoval(arr, n))->display() ) else skip; operation findMinRemoval(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var value : int := 0 ; var maximum : int := 0 ; if (n = 1) then ( return 0 ) else skip ; for i : Integer.subrange(0, n-1) do ( if (i /= 0 & i /= n - 1) then ( value := value + (arr[i+1] - arr[i + 1+1])->abs() ; var temp : double := ((arr[i+1] - arr[i + 1+1])->abs() + (arr[i+1] - arr[i - 1+1])->abs() - (arr[i - 1+1] - arr[i + 1+1])->abs()) ) else (if (i = 0) then ( value := value + (arr[i+1] - arr[i + 1+1])->abs() ; temp := (arr[i+1] - arr[i + 1+1])->abs() ) else ( temp := (arr[i+1] - arr[i - 1+1])->abs() ) ) ; maximum := Set{maximum, temp}->max()) ; return (value - maximum); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find(n): arr=['']*(n+1); size=1 ; m=1 ; while(size<=n): i=0 ; while(icompareTo(n)) <= 0) do ( var i : int := 0; ; while ((i->compareTo(m)) < 0 & ((size + i)->compareTo(n)) <= 0) do ( arr[size + i+1] := "3" + arr[size - m + i+1]; ; i := i + 1;) ; i := 0; ; while ((i->compareTo(m)) < 0 & ((size + m + i)->compareTo(n)) <= 0) do ( arr[size + m + i+1] := "4" + arr[size - m + i+1]; ; i := i + 1;) ; m := m * (2->pow(1)); ; size := size + m;) ; execute (arr[n+1])->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxValue(a,b): b=sorted(b) bi=[i for i in b] ai=[i for i in a] n=len(a) m=len(b) j=m-1 for i in range(n): if(j<0): break if(bi[j]>ai[i]): ai[i]=bi[j] j-=1 x="".join(ai) return x a="1234" b="4321" print(maxValue(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := "1234" ; b := "4321" ; execute (maxValue(a, b))->display(); operation maxValue(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: b := b->sort() ; var bi : Sequence := b->select(i | true)->collect(i | (i)) ; var ai : Sequence := a->select(i | true)->collect(i | (i)) ; var n : int := (a)->size() ; var m : int := (b)->size() ; var j : double := m - 1 ; for i : Integer.subrange(0, n-1) do ( if (j < 0) then ( break ) else skip ; if ((bi[j+1]->compareTo(ai[i+1])) > 0) then ( ai[i+1] := bi[j+1] ; j := j - 1 ) else skip) ; var x : String := StringLib.sumStringsWithSeparator((ai), "") ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def _input(): return map(int,input().split()) n=int(input()) a=[]; b=[] res=0 for _ in range(n): i,j=_input() if i<0 : a.append((-i,j)) elif i>0 : b.append((i,j)) else : res+=j a.sort(); b.sort() la=len(a); lb=len(b) if la>lb+1 : la=lb+1 elif lb>la+1 : lb=la+1 for i in range(la): res+=a[i][1] for i in range(lb): res+=b[i][1] print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{}; var b : Sequence := Sequence{} ; var res : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := _input() ; if i < 0 then ( execute ((Sequence{-i, j}) : a) ) else (if i > 0 then ( execute ((Sequence{i, j}) : b) ) else ( res := res + j ) ) ) ; a := a->sort(); b := b->sort() ; var la : int := (a)->size(); var lb : int := (b)->size() ; if (la->compareTo(lb + 1)) > 0 then ( la := lb + 1 ) else (if (lb->compareTo(la + 1)) > 0 then ( lb := la + 1 ) else skip) ; for i : Integer.subrange(0, la-1) do ( res := res + a[i+1][1+1]) ; for i : Integer.subrange(0, lb-1) do ( res := res + b[i+1][1+1]) ; execute (res)->display(); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) left=[] right=[] for i in range(n): a,b=map(int,input().split()) if a<0 : left.append([a,b]) else : right.append([a,b]) right=sorted(right); left=sorted(left,reverse=True) su=0 a=left ; b=right if len(right)>len(left): a,b=b,a while b!=[]: su+=a[0][1]+b[0][1] a.pop(0); b.pop(0) if a!=[]: su+=a[0][1] print(su) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var left : Sequence := Sequence{} ; var right : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a < 0 then ( execute ((Sequence{a}->union(Sequence{ b })) : left) ) else ( execute ((Sequence{a}->union(Sequence{ b })) : right) )) ; right := right->sort(); left := left->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var su : int := 0 ; var a : Sequence := left; var b : Sequence := right ; if ((right)->size()->compareTo((left)->size())) > 0 then ( Sequence{a,b} := Sequence{b,a} ) else skip ; while b /= Sequence{} do ( su := su + a->first()[1+1] + b->first()[1+1] ; a := a->excludingAt(0+1); b := b->excludingAt(0+1)) ; if a /= Sequence{} then ( su := su + a->first()[1+1] ) else skip ; execute (su)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect n=int(input()) t=sorted(tuple(map(int,input().split()))for i in range(n)) b=bisect.bisect_left(t,(0,0)) l=min(b,n-b)+1 res=0 for i in range(l): if b+i=0 : res+=t[b-i-1][1] print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : Sequence := (argument (test (logical_test (comparison (expr (atom (name tuple)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))->sort() ; var b : OclAny := bisect.bisect_left(t, Sequence{0, 0}) ; var l : OclAny := Set{b, n - b}->min() + 1 ; var res : int := 0 ; for i : Integer.subrange(0, l-1) do ( if (b + i->compareTo(n)) < 0 then ( res := res + t[b + i+1][1+1] ) else skip ; if b - i - 1 >= 0 then ( res := res + t[b - i - 1+1][1+1] ) else skip) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=n*[0] a=n*[0] for i in range(n): x[i],a[i]=[int(i)for i in input().split()] for i in range(n): bish=x[0] k=0 for j in range(1,n-i): if x[j]>bish : bish=x[j] k=j x[n-1-i],x[k]=x[k],x[n-1-i] a[n-1-i],a[k]=a[k],a[n-1-i] manfi=0 mosbat=0 for i in range(n): if x[i]>0 : mosbat+=1 else : manfi+=1 if manfi==mosbat : print(sum(a)) elif mosbat>manfi : print(sum(a[: manfi*2+1])) else : print(sum(a[manfi-(mosbat+1):])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( var x[i+1] : OclAny := null; var a[i+1] : OclAny := null; Sequence{x[i+1],a[i+1]} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))) ; for i : Integer.subrange(0, n-1) do ( var bish : OclAny := x->first() ; var k : int := 0 ; for j : Integer.subrange(1, n - i-1) do ( if (x[j+1]->compareTo(bish)) > 0 then ( bish := x[j+1] ; k := j ) else skip) ; var x[n - 1 - i+1] : OclAny := null; var x[k+1] : OclAny := null; Sequence{x[n - 1 - i+1],x[k+1]} := Sequence{x[k+1],x[n - 1 - i+1]} ; var a[n - 1 - i+1] : OclAny := null; var a[k+1] : OclAny := null; Sequence{a[n - 1 - i+1],a[k+1]} := Sequence{a[k+1],a[n - 1 - i+1]}) ; var manfi : int := 0 ; var mosbat : int := 0 ; for i : Integer.subrange(0, n-1) do ( if x[i+1] > 0 then ( mosbat := mosbat + 1 ) else ( manfi := manfi + 1 )) ; if manfi = mosbat then ( execute ((a)->sum())->display() ) else (if (mosbat->compareTo(manfi)) > 0 then ( execute ((a.subrange(1,manfi * 2 + 1))->sum())->display() ) else ( execute ((a.subrange(manfi - (mosbat + 1)+1))->sum())->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) pos=[] neg=[] for _ in range(n): x,a=map(int,input().split()) if x>0 : pos.append((x,a)) else : neg.append((x,a)) pos.sort() neg.sort(reverse=True) pos=[x for _,x in pos] neg=[x for _,x in neg] if len(pos)==len(neg): print(sum(pos)+sum(neg)) else : ml=min(len(pos),len(neg)) total=sum(pos[: ml])+sum(neg[: ml]) if len(pos)>ml : total+=pos[ml] else : total+=neg[ml] print(total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var pos : Sequence := Sequence{} ; var neg : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var a : OclAny := null; Sequence{x,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x > 0 then ( execute ((Sequence{x, a}) : pos) ) else ( execute ((Sequence{x, a}) : neg) )) ; pos := pos->sort() ; neg := neg->sort() ; pos := pos->select(_tuple | true)->collect(_tuple | let _anon : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in (x)) ; neg := neg->select(_tuple | true)->collect(_tuple | let _anon : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in (x)) ; if (pos)->size() = (neg)->size() then ( execute ((pos)->sum() + (neg)->sum())->display() ) else ( var ml : OclAny := Set{(pos)->size(), (neg)->size()}->min() ; var total : OclAny := (pos.subrange(1,ml))->sum() + (neg.subrange(1,ml))->sum() ; if ((pos)->size()->compareTo(ml)) > 0 then ( total := total + pos[ml+1] ) else ( total := total + neg[ml+1] ) ; execute (total)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def geometricMean(arr,n): product=1 for i in range(0,n): product=product*arr[i] gm=(float)(math.pow(product,(1/n))) return(float)(gm) arr=[1,2,3,4,5,6,7,8] n=len(arr) print('{0:.6f}'.format(geometricMean(arr,n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 8 }))))))) ; n := (arr)->size() ; execute (StringLib.interpolateStrings('{0:.6f}', Sequence{geometricMean(arr, n)}))->display(); operation geometricMean(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var product : int := 1 ; for i : Integer.subrange(0, n-1) do ( product := product * arr[i+1]) ; var gm : OclAny := (OclType["double"])((product)->pow((1 / n))) ; return (OclType["double"])(gm); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def find_Area(a): R=a*(2.0-sqrt(2)); area=3.14*R*R/2.0 ; return area ; if __name__=="__main__" : a=4 ; print("Area of semicircle=",find_Area(a)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( a := 4; ; execute ("Area of semicircle=")->display(); ) else skip; operation find_Area(a : OclAny) pre: true post: true activity: var R : double := a * (2.0 - sqrt(2)); ; var area : double := 3.14 * R * R / 2.0; ; return area;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def readline_ints(): return[int(num)for num in fin.readline().strip().split()] import itertools def ordered_subsets_sums(S): lim=sum(S)//2 for i in range(1,len(S)): for subset in itertools.combinations(S,i): sub_sum=sum(subset) if sub_sum>lim : break yield subset,sub_sum def find_collision(S): sums={} for sub,sub_sum in ordered_subsets_sums(S): if sub_sum in sums : return sums[sub_sum],sub sums[sub_sum]=sub fname="C-large" with open(fname+".in","r")as fin,open(fname+".out","w")as fout : numcases=readline_ints()[0] print(numcases,"cases") for caseno in range(1,numcases+1): N,*S=readline_ints() S.sort() coll=find_collision(S) if coll is None : result="Impossible" else : s1,s2=coll result=" ".join(str(n)for n in sorted(s1))+"\n"+" ".join(str(n)for n in sorted(s2)) outstr="Case #%d:\n%s" %(caseno,result) fout.write(outstr+"\n") print(outstr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var fname : String := "C-large" ; try (var fin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(fname + ".in")); var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(fname + ".out")); var numcases : OclAny := readline_ints()->first() ; execute (numcases)->display() ; for caseno : Integer.subrange(1, numcases + 1-1) do ( var N : OclAny := null; var S : OclAny := null; Sequence{N,S} := readline_ints() ; S := S->sort() ; var coll : OclAny := find_collision(S) ; if coll <>= null then ( var result : String := "Impossible" ) else ( var s1 : OclAny := null; var s2 : OclAny := null; Sequence{s1,s2} := coll ; result := StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s1)))))))) ))))))))), " ") + "\n" + StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s2)))))))) ))))))))), " ") ) ; var outstr : String := StringLib.format("Case #%d:\n%s",Sequence{caseno, result}) ; fout.write(outstr + "\n") ; execute (outstr)->display())) catch (_e : OclException) do skip; operation readline_ints() : OclAny pre: true post: true activity: return fin.readLine()->trim().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())); operation ordered_subsets_sums(S : OclAny) pre: true post: true activity: var lim : int := (S)->sum() div 2 ; for i : Integer.subrange(1, (S)->size()-1) do ( for subset : itertools.combinations(S, i) do ( var sub_sum : OclAny := (subset)->sum() ; if (sub_sum->compareTo(lim)) > 0 then ( break ) else skip ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return subset, sub_sum)); operation find_collision(S : OclAny) : OclAny pre: true post: true activity: var sums : OclAny := Set{} ; for _tuple : ordered_subsets_sums(S) do (var _indx : int := 1; var sub : OclAny := _tuple->at(_indx); _indx := _indx + 1; var sub_sum : OclAny := _tuple->at(_indx); if (sums)->includes(sub_sum) then ( return sums[sub_sum+1], sub ) else skip ; sums[sub_sum+1] := sub); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=[0]*n a=list(map(int,input().split())) a=sorted(a) mod=10**9+7 ans=1 if(k % 2==0 or a[-1]>=0): mlt1=a[0]*a[1] mlt2=a[-2]*a[-1] l=0 r=-1 for i in range(k//2): if(mlt1>=mlt2): ans*=mlt1 % mod l+=2 if(l<=n-2): mlt1=a[l+1]*a[l] else : ans*=mlt2 % mod r-=2 if(r>=-n+1): mlt2=a[r-1]*a[r] ans %=mod if(k % 2==1): ans*=a[r] ans %=mod else : for i in range(k): ans*=a[n-1-i] ans %=mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var mod : double := (10)->pow(9) + 7 ; var ans : int := 1 ; if (k mod 2 = 0 or a->last() >= 0) then ( var mlt1 : double := a->first() * a[1+1] ; var mlt2 : double := a->front()->last() * a->last() ; var l : int := 0 ; var r : int := -1 ; for i : Integer.subrange(0, k div 2-1) do ( if ((mlt1->compareTo(mlt2)) >= 0) then ( ans := ans * mlt1 mod mod ; l := l + 2 ; if ((l->compareTo(n - 2)) <= 0) then ( mlt1 := a[l + 1+1] * a[l+1] ) else skip ) else ( ans := ans * mlt2 mod mod ; r := r - 2 ; if ((r->compareTo(-n + 1)) >= 0) then ( mlt2 := a[r - 1+1] * a[r+1] ) else skip ) ; ans := ans mod mod) ; if (k mod 2 = 1) then ( ans := ans * a[r+1] ; ans := ans mod mod ) else skip ) else ( for i : Integer.subrange(0, k-1) do ( ans := ans * a[n - 1 - i+1] ; ans := ans mod mod) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import operator from functools import reduce N,K=map(int,input().split()) A=list(map(int,input().split())) MOD=10**9+7 positives=[a for a in A if a>0] negatives=[a for a in A if a<0] positive_cnt=len(positives) negative_cnt=len(negatives) zero_cnt=A.count(0) if 2*min(K//2,negative_cnt//2)+positive_cnt>=K : ans=1 positives.sort(key=lambda x : abs(x),reverse=True) negatives.sort(key=lambda x : abs(x),reverse=True) if K % 2==1 : ans*=positives.pop(0) K-=1 X=[] for pair in zip(*[iter(positives)]*2): X.append(reduce(operator.mul,pair,1)) for pair in zip(*[iter(negatives)]*2): X.append(reduce(operator.mul,pair,1)) X.sort(reverse=True) ans*=reduce(lambda a,b : a*b % MOD,X[: K//2],1) print(ans % MOD) elif zero_cnt : print(0) else : A.sort(key=lambda x : abs(x)) print(reduce(lambda a,b : a*b % MOD,A[: K],1)% MOD) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var MOD : double := (10)->pow(9) + 7 ; var positives : Sequence := A->select(a | a > 0)->collect(a | (a)) ; var negatives : Sequence := A->select(a | a < 0)->collect(a | (a)) ; var positive_cnt : int := (positives)->size() ; var negative_cnt : int := (negatives)->size() ; var zero_cnt : int := A->count(0) ; if (2 * Set{K div 2, negative_cnt div 2}->min() + positive_cnt->compareTo(K)) >= 0 then ( var ans : int := 1 ; positives := positives->sort() ; negatives := negatives->sort() ; if K mod 2 = 1 then ( ans := ans * positives->at(0`firstArg+1) ; positives := positives->excludingAt(0+1) ; K := K - 1 ) else skip ; var X : Sequence := Sequence{} ; for pair : Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name positives)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name positives)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name positives)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))`third->at(_indx)} ) do ( execute ((reduce(operator.mul, pair, 1)) : X)) ; for pair : Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name negatives)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name negatives)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name negatives)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))`third->at(_indx)} ) do ( execute ((reduce(operator.mul, pair, 1)) : X)) ; X := X->sort() ; ans := ans * reduce(lambda a : OclAny, b : OclAny in (a * b mod MOD), X.subrange(1,K div 2), 1) ; execute (ans mod MOD)->display() ) else (if zero_cnt then ( execute (0)->display() ) else ( A := A->sort() ; execute (reduce(lambda a : OclAny, b : OclAny in (a * b mod MOD), A.subrange(1,K), 1) mod MOD)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=10**9+7 def func(A,n,k): A.sort() product=1 if(A[n-1]==0 and(k & 1)): return 0 if(A[n-1]<=0 and(k & 1)): for i in range(n-1,n-k-1,-1): product=(product*A[i])% mod return product % mod i=0 j=n-1 if(k & 1): product=(product*A[j])% mod j-=1 k-=1 k>>=1 for itr in range(k): left_product=(A[i]*A[i+1]) right_product=(A[j]*A[j-1]) if(left_product>right_product): product=(product*(left_product)% mod)% mod i+=2 else : product=((right_product % mod)*product)% mod j-=2 return product % mod n,k=list(map(int,input().split())) arr=list(map(int,input().split())) ans=func(arr,n,k) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : double := (10)->pow(9) + 7 ; skip ; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : OclAny := func(arr, n, k) ; execute (ans)->display(); operation func(A : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: A := A->sort() ; var product : int := 1 ; if (A[n - 1+1] = 0 & (MathLib.bitwiseAnd(k, 1))) then ( return 0 ) else skip ; if (A[n - 1+1] <= 0 & (MathLib.bitwiseAnd(k, 1))) then ( for i : Integer.subrange(n - k - 1 + 1, n - 1)->reverse() do ( product := (product * A[i+1]) mod mod) ; return product mod mod ) else skip ; var i : int := 0 ; var j : double := n - 1 ; if (MathLib.bitwiseAnd(k, 1)) then ( product := (product * A[j+1]) mod mod ; j := j - 1 ; k := k - 1 ) else skip ; k := k div (2->pow(1)) ; for itr : Integer.subrange(0, k-1) do ( var left_product : double := (A[i+1] * A[i + 1+1]) ; var right_product : double := (A[j+1] * A[j - 1+1]) ; if ((left_product->compareTo(right_product)) > 0) then ( product := (product * (left_product) mod mod) mod mod ; i := i + 2 ) else ( product := ((right_product mod mod) * product) mod mod ; j := j - 2 )) ; return product mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import heapq input=sys.stdin.readline sys.setrecursionlimit(10**7) def main(): N,K=map(int,input().split()) A=list(map(int,input().split())) MOD=10**9+7 pos=[] neg=[] for a in A : if a>=0 : pos.append(a) else : neg.append(a) flag=False if N==K : ans=1 for a in A : ans*=a ans %=MOD print(ans % MOD) exit() if len(pos)>0 : flag=True else : if K % 2==0 : flag=True ans=1 if not flag : h=[abs(x)for x in A] heapq.heapify(h) for i in range(K): ans*=heapq.heappop(h) ans %=MOD ans*=-1 else : hpos=[-x for x in pos] heapq.heapify(hpos) hneg=neg[:] heapq.heapify(hneg) if K % 2==1 : ans*=-heapq.heappop(hpos) ans %=MOD pairs=[] while len(hpos)>=2 : x=-heapq.heappop(hpos) x*=-heapq.heappop(hpos) heapq.heappush(pairs,-x) while len(hneg)>=2 : x=heapq.heappop(hneg) x*=heapq.heappop(hneg) heapq.heappush(pairs,-x) if len(pairs): for i in range(K//2): ans*=-heapq.heappop(pairs) ans %=MOD print(ans % MOD) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit((10)->pow(7)) ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var MOD : double := (10)->pow(9) + 7 ; var pos : Sequence := Sequence{} ; var neg : Sequence := Sequence{} ; for a : A do ( if a >= 0 then ( execute ((a) : pos) ) else ( execute ((a) : neg) )) ; var flag : boolean := false ; if N = K then ( var ans : int := 1 ; for a : A do ( ans := ans * a ; ans := ans mod MOD) ; execute (ans mod MOD)->display() ; exit() ) else skip ; if (pos)->size() > 0 then ( flag := true ) else ( if K mod 2 = 0 then ( flag := true ) else skip ) ; ans := 1 ; if not(flag) then ( var h : Sequence := A->select(x | true)->collect(x | ((x)->abs())) ; heapq.heapify(h) ; for i : Integer.subrange(0, K-1) do ( ans := ans * heapq.heappop(h) ; ans := ans mod MOD) ; ans := ans * -1 ) else ( var hpos : Sequence := pos->select(x | true)->collect(x | (-x)) ; heapq.heapify(hpos) ; var hneg : Sequence := neg ; heapq.heapify(hneg) ; if K mod 2 = 1 then ( ans := ans * -heapq.heappop(hpos) ; ans := ans mod MOD ) else skip ; var pairs : Sequence := Sequence{} ; while (hpos)->size() >= 2 do ( var x : OclAny := -heapq.heappop(hpos) ; x := x * -heapq.heappop(hpos) ; heapq.heappush(pairs, -x)) ; while (hneg)->size() >= 2 do ( x := heapq.heappop(hneg) ; x := x * heapq.heappop(hneg) ; heapq.heappush(pairs, -x)) ; if (pairs)->size() then ( for i : Integer.subrange(0, K div 2-1) do ( ans := ans * -heapq.heappop(pairs) ; ans := ans mod MOD) ) else skip ) ; execute (ans mod MOD)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=list(map(int,input().split())) a_pos=sorted([i for i in a if i>=0]) a_neg=sorted([i for i in a if i<0],reverse=True) mod=10**9+7 ans=1 if len(a_pos)==0 and k % 2 : for i in a_neg[: k]: ans=ans*i % mod print(ans) exit() while k>0 : if k==1 or len(a_neg)<=1 : if len(a_pos)==0 : ans*=a_neg.pop() elif len(a_pos)>0 : ans*=a_pos.pop() k-=1 elif len(a_pos)<=1 : ans*=a_neg.pop()*a_neg.pop() k-=2 elif a_pos[-1]*a_pos[-2]>a_neg[-1]*a_neg[-2]: ans*=a_pos.pop() k-=1 elif a_pos[0]*a_pos[1]<=a_neg[-1]*a_neg[-2]: ans*=a_neg.pop()*a_neg.pop() k-=2 ans %=mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a_pos : Sequence := a->select(i | i >= 0)->collect(i | (i))->sort() ; var a_neg : Sequence := a->select(i | i < 0)->collect(i | (i))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var mod : double := (10)->pow(9) + 7 ; var ans : int := 1 ; if (a_pos)->size() = 0 & k mod 2 then ( for i : a_neg.subrange(1,k) do ( ans := ans * i mod mod) ; execute (ans)->display() ; exit() ) else skip ; while k > 0 do ( if k = 1 or (a_neg)->size() <= 1 then ( if (a_pos)->size() = 0 then ( ans := ans * a_neg->last() ; a_neg := a_neg->front() ) else (if (a_pos)->size() > 0 then ( ans := ans * a_pos->last() ; a_pos := a_pos->front() ) else skip) ; k := k - 1 ) else (if (a_pos)->size() <= 1 then ( ans := ans * a_neg->last() * a_neg->last() ; k := k - 2 ) else (if (a_pos->last() * a_pos->front()->last()->compareTo(a_neg->last() * a_neg->front()->last())) > 0 then ( ans := ans * a_pos->last() ; a_pos := a_pos->front() ; k := k - 1 ) else (if (a_pos->first() * a_pos[1+1]->compareTo(a_neg->last() * a_neg->front()->last())) <= 0 then ( ans := ans * a_neg->last() * a_neg->last() ; k := k - 2 ) else skip ) ) ) ; ans := ans mod mod) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def display(n): for i in range(1,n+1): k=i for j in range(1,i+1): if k % 2==0 : print(j,end='') else : print('*',end='') k-=1 print() n=5 display(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; display(n); operation display(n : OclAny) pre: true post: true activity: for i : Integer.subrange(1, n + 1-1) do ( var k : OclAny := i ; for j : Integer.subrange(1, i + 1-1) do ( if k mod 2 = 0 then ( execute (j)->display() ) else ( execute ('*')->display() ) ; k := k - 1) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countXorPair(arr,n): count=0 for i in range(n): for j in range(i+1,n): if((arr[i]^ arr[j])% 2==1): count+=1 return count if __name__=="__main__" : arr=[1,2,3] n=len(arr) print(countXorPair(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; n := (arr)->size() ; execute (countXorPair(arr, n))->display() ) else skip; operation countXorPair(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if ((MathLib.bitwiseXor(arr[i+1], arr[j+1])) mod 2 = 1) then ( count := count + 1 ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def Square(n,i,j): mid=(i+j)/2 ; mul=mid*mid ; if((mul==n)or(abs(mul-n)<0.00001)): return mid ; elif(muln): res=Square(n,i-1,i); print("{0:.5f}".format(res)) found=True i+=1 ; if __name__=='__main__' : n=3 ; findSqrt(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( n := 3; ; findSqrt(n); ) else skip; operation Square(n : OclAny, i : OclAny, j : OclAny) pre: true post: true activity: var mid : double := (i + j) / 2; ; var mul : double := mid * mid; ; if ((mul = n) or ((mul - n)->abs() < 0.00001)) then ( return mid; ) else (if ((mul->compareTo(n)) < 0) then ( return Square(n, mid, j); ) else ( return Square(n, i, mid); ) ) ; operation findSqrt(n : OclAny) pre: true post: true activity: i := 1; ; var found : boolean := false; ; while (found = false) do ( if (i * i = n) then ( execute (i)->display(); ; found := true; ) else (if ((i * i->compareTo(n)) > 0) then ( var res : OclAny := Square(n, i - 1, i); ; execute (StringLib.interpolateStrings("{0:.5f}", Sequence{res}))->display() ; found := true ) else skip) ; i := i + 1;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import permutations as pm def main(): t=int(input()) fact9=9*8*7*6*5*4*3*2 for _ in range(t): l1=list(map(int,input().split())) l2=list(map(int,input().split())) ans1=0 ans2=0 for hand in pm(l2,9): score1=0 score2=0 for i,j in zip(l1,hand): if iscore2 : ans1+=1 print(ans1/fact9,ans2/fact9) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var fact9 : int := 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 ; for _anon : Integer.subrange(0, t-1) do ( var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans1 : int := 0 ; var ans2 : int := 0 ; for hand : pm(l2, 9) do ( var score1 : int := 0 ; var score2 : int := 0 ; for _tuple : Integer.subrange(1, l1->size())->collect( _indx | Sequence{l1->at(_indx), hand->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if (i->compareTo(j)) < 0 then ( score2 := score2 + (i + j) ) else ( score1 := score1 + (i + j) )) ; if (score1->compareTo(score2)) < 0 then ( ans2 := ans2 + 1 ) else (if (score1->compareTo(score2)) > 0 then ( ans1 := ans1 + 1 ) else skip)) ; execute (ans1 / fact9)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findQuadruples(a,b,c,d,x,n): count=0 for i in range(n): for j in range(n): for k in range(n): for l in range(n): if((a[i]^ b[j]^ c[k]^ d[l])==x): count+=1 return count x=3 a=[0,1] b=[2,0] c=[0,1] d=[0,1] n=len(a) print(findQuadruples(a,b,c,d,x,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := 3 ; a := Sequence{0}->union(Sequence{ 1 }) ; b := Sequence{2}->union(Sequence{ 0 }) ; c := Sequence{0}->union(Sequence{ 1 }) ; d := Sequence{0}->union(Sequence{ 1 }) ; n := (a)->size() ; execute (findQuadruples(a, b, c, d, x, n))->display(); operation findQuadruples(a : OclAny, b : OclAny, c : OclAny, d : OclAny, x : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( for k : Integer.subrange(0, n-1) do ( for l : Integer.subrange(0, n-1) do ( if ((MathLib.bitwiseXor(MathLib.bitwiseXor(MathLib.bitwiseXor(a[i+1], b[j+1]), c[k+1]), d[l+1])) = x) then ( count := count + 1 ) else skip)))) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from decimal import Decimal,ROUND_HALF_UP for _ in range(int(input())): a,b=tuple(sorted(map(int,input().split()),reverse=True)),tuple(sorted(map(int,input().split()))) c=0 q={():(0,0)} for i in range(9): nq={} for k in q : for j in b : if j not in k : x=q[k][0]+(a[i]+j)*(a[i]>j) y=q[k][1]+(a[i]+j)*(a[i]85 : c+=math.factorial(9-i-1) elif y<86 : nq[tuple(list(k)+[j])]=(x,y) q=nq c/=362880 print("{}{}".format(Decimal(c).quantize(Decimal('0.000001'),rounding=ROUND_HALF_UP),Decimal(1-c).quantize(Decimal('0.000001'),rounding=ROUND_HALF_UP))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{((input().split())->collect( _x | (OclType["int"])->apply(_x) )->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True))))))))),((input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort())} ; var c : int := 0 ; var q : Map := Map{ () |-> Sequence{0, 0} } ; for i : Integer.subrange(0, 9-1) do ( var nq : OclAny := Set{} ; for k : q->keys() do ( for j : b do ( if (k)->excludes(j) then ( var x : OclAny := q[k+1]->first() + (a[i+1] + j) * ((a[i+1]->compareTo(j)) > 0) ; var y : OclAny := q[k+1][1+1] + (a[i+1] + j) * ((a[i+1]->compareTo(j)) < 0) ; if x > 85 then ( c := c + MathLib.factorial(9 - i - 1) ) else (if y < 86 then ( nq->restrict(((k)->union(Sequence{ j }))) := Sequence{x, y} ) else skip) ) else skip)) ; q := nq) ; c := c / 362880 ; execute (StringLib.interpolateStrings("{}{}", Sequence{Decimal(c).quantize(Decimal('0.000001'), (argument (test (logical_test (comparison (expr (atom (name rounding)))))) = (test (logical_test (comparison (expr (atom (name ROUND_HALF_UP)))))))), Decimal(1 - c).quantize(Decimal('0.000001'), (argument (test (logical_test (comparison (expr (atom (name rounding)))))) = (test (logical_test (comparison (expr (atom (name ROUND_HALF_UP))))))))}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,itertools curr_dir=os.path.dirname(os.path.abspath(__file__)) srcfilename=os.path.join(curr_dir,'C-large.in') dstfilename=os.path.join(curr_dir,'output.txt') def solve(numbers_): numbers=sorted(numbers_) memory=dict((k,[k])for k in numbers) for r in xrange(2,len(numbers)): combinations=itertools.combinations(numbers,r) for combination in combinations : s=sum(combination) if s in memory : r1=memory[s] r2=combination return r1,r2 memory[s]=combination return 'Impossible' if __name__=='__main__' : with open(srcfilename,'rb')as inp : with open(dstfilename,'wb')as outp : lines=inp.readlines() count=int(lines.pop(0)) outlines=[] for i in xrange(count): line=lines[i] numbers=[int(number)for number in line.split(' ')] numbers.pop(0) result=solve(numbers) if result=='Impossible' : outlines.append('Case #%d: Impossible\n' %(i+1,)) else : r1,r2=result outlines.append('Case #%d:\n' %(i+1,)) outlines.append('%s\n' % ' '.join(['%d' % r1i for r1i in r1])) outlines.append('%s\n' % ' '.join(['%d' % r2i for r2i in r2])) outp.writelines(outlines) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var curr_dir : OclAny := os.path.dirname(os.path.abspath(__file__)) ; var srcfilename : OclAny := os.path.join(curr_dir, 'C-large.in') ; var dstfilename : OclAny := os.path.join(curr_dir, 'output.txt') ; skip ; if __name__ = '__main__' then ( try (var inp : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(srcfilename)); try (var outp : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(dstfilename)); var lines : OclAny := inp.readlines() ; var count : int := ("" + ((lines->at(0`firstArg+1))))->toInteger() ; var outlines : Sequence := Sequence{} ; for i : xrange(count) do ( var line : OclAny := lines[i+1] ; numbers := line.split(' ')->select(number | true)->collect(number | (("" + ((number)))->toInteger())) ; numbers := numbers->excludingAt(0+1) ; var result : OclAny := solve(numbers) ; if result = 'Impossible' then ( execute ((StringLib.format('Case #%d: Impossible ',Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))) ,)})) : outlines) ) else ( Sequence{r1,r2} := result ; execute ((StringLib.format('Case #%d: ',Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))) ,)})) : outlines) ; execute ((StringLib.format('%s ',StringLib.sumStringsWithSeparator((r1->select(r1i | true)->collect(r1i | (StringLib.format('%d',r1i)))), ' '))) : outlines) ; execute ((StringLib.format('%s ',StringLib.sumStringsWithSeparator((r2->select(r2i | true)->collect(r2i | (StringLib.format('%d',r2i)))), ' '))) : outlines) )) ; outp.writelines(outlines)) catch (_e : OclException) do skip) catch (_e : OclException) do skip ) else skip; operation solve(numbers_ : OclAny) : OclAny pre: true post: true activity: var numbers : Sequence := numbers_->sort() ; var memory : Map := ((argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name k)))))) , (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name k))))))) ])))))) )))))) (comp_for for (exprlist (expr (atom (name k)))) in (logical_test (comparison (expr (atom (name numbers)))))))) ; for r : xrange(2, (numbers)->size()) do ( var combinations : OclAny := itertools.combinations(numbers, r) ; for combination : combinations do ( var s : OclAny := (combination)->sum() ; if (memory)->includes(s) then ( var r1 : OclAny := memory[s+1] ; var r2 : OclAny := combination ; return r1, r2 ) else skip ; memory[s+1] := combination)) ; return 'Impossible'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printCombination(arr,n,r): data=[0]*r ; combinationUtil(arr,data,0,n-1,0,r); def combinationUtil(arr,data,start,end,index,r): if(index==r): for j in range(r): print(data[j],end=" "); print(); return ; i=start ; while(i<=end and end-i+1>=r-index): data[index]=arr[i]; combinationUtil(arr,data,i+1,end,index+1,r); i+=1 ; arr=[1,2,3,4,5]; r=3 ; n=len(arr); printCombination(arr,n,r); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))); ; r := 3; ; n := (arr)->size(); ; printCombination(arr, n, r);; operation printCombination(arr : OclAny, n : OclAny, r : OclAny) pre: true post: true activity: var data : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, r); ; combinationUtil(arr, data, 0, n - 1, 0, r);; operation combinationUtil(arr : OclAny, data : OclAny, start : OclAny, end : OclAny, index : OclAny, r : OclAny) : OclAny pre: true post: true activity: if (index = r) then ( for j : Integer.subrange(0, r-1) do ( execute (data[j+1])->display();) ; execute (->display(); ; return; ) else skip ; var i : OclAny := start; ; while ((i->compareTo(end)) <= 0 & (end - i + 1->compareTo(r - index)) >= 0) do ( data[index+1] := arr[i+1]; ; combinationUtil(arr, data, i + 1, end, index + 1, r); ; i := i + 1;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printCombination(arr,n,r): data=[0]*r combinationUtil(arr,n,r,0,data,0) def combinationUtil(arr,n,r,index,data,i): if(index==r): for j in range(r): print(data[j],end=" ") print() return if(i>=n): return data[index]=arr[i] combinationUtil(arr,n,r,index+1,data,i+1) combinationUtil(arr,n,r,index,data,i+1) if __name__=="__main__" : arr=[1,2,3,4,5] r=3 n=len(arr) printCombination(arr,n,r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ; r := 3 ; n := (arr)->size() ; printCombination(arr, n, r) ) else skip; operation printCombination(arr : OclAny, n : OclAny, r : OclAny) pre: true post: true activity: var data : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, r) ; combinationUtil(arr, n, r, 0, data, 0); operation combinationUtil(arr : OclAny, n : OclAny, r : OclAny, index : OclAny, data : OclAny, i : OclAny) pre: true post: true activity: if (index = r) then ( for j : Integer.subrange(0, r-1) do ( execute (data[j+1])->display()) ; execute (->display() ; return ) else skip ; if ((i->compareTo(n)) >= 0) then ( return ) else skip ; data[index+1] := arr[i+1] ; combinationUtil(arr, n, r, index + 1, data, i + 1) ; combinationUtil(arr, n, r, index, data, i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bitwiseAndOdd(n): result=1 ; for i in range(3,n+1,2): result=(result & i); return result ; if __name__=="__main__" : n=10 ; print(bitwiseAndOdd(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 10; ; execute (bitwiseAndOdd(n))->display(); ) else skip; operation bitwiseAndOdd(n : OclAny) pre: true post: true activity: var result : int := 1; ; for i : Integer.subrange(3, n + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( result := (MathLib.bitwiseAnd(result, i));) ; return result;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findTangent(A,x,y): dif=A-x*2 if y==(2*x-x*x): if dif<0 : print("y=",dif,"x",(x*dif)+(y)) elif dif>0 : print("y=",dif,"x+",-x*dif+y) else : print("Not Possible") if __name__=="__main__" : A,x,y=2,2,0 findTangent(A,x,y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{A,x,y} := Sequence{2,2,0} ; findTangent(A, x, y) ) else skip; operation findTangent(A : OclAny, x : OclAny, y : OclAny) pre: true post: true activity: var dif : double := A - x * 2 ; if y = (2 * x - x * x) then ( if dif < 0 then ( execute ("y=")->display() ) else (if dif > 0 then ( execute ("y=")->display() ) else ( execute ("Not Possible")->display() ) ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) while n : s=int(input()) a=set(map(int,input().split())) c=max(a)-min(a) print(c) n-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while n do ( var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var c : double := (a)->max() - (a)->min() ; execute (c)->display() ; n := n - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) mini=min(a) maxi=max(a) print(maxi-mini) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mini : OclAny := (a)->min() ; var maxi : OclAny := (a)->max() ; execute (maxi - mini)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): m=int(input()) l=list(map(int,input().split())) print(max(l)-min(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((l)->max() - (l)->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=[int(x)for x in input().split()] print(max(a)-min(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((a)->max() - (a)->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSmallest(s,q,m): N=len(s) H=[[0 for i in range(26)]for i in range(N+1)] for i in range(1,N+1): H[i][ord(s[i-1])-ord('a')]+=1 for j in range(26): H[i][j]+=H[i-1][j] for j in range(m): l=q[j][0] r=q[j][1] n=q[j][2] sum=0 for i in range(26): sum+=H[r][i]-H[l-1][i] if(sum>=n): print(chr(ord('a')+i)) break if __name__=='__main__' : s="afbccdeb" q=[[2,4,1],[1,6,4],[1,8,7]] x=len(q) findSmallest(s,q,x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( s := "afbccdeb" ; q := Sequence{Sequence{2}->union(Sequence{4}->union(Sequence{ 1 }))}->union(Sequence{Sequence{1}->union(Sequence{6}->union(Sequence{ 4 }))}->union(Sequence{ Sequence{1}->union(Sequence{8}->union(Sequence{ 7 })) })) ; var x : int := (q)->size() ; findSmallest(s, q, x) ) else skip; operation findSmallest(s : OclAny, q : OclAny, m : OclAny) pre: true post: true activity: var N : int := (s)->size() ; var H : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, 26-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(1, N + 1-1) do ( H[i+1][(s[i - 1+1])->char2byte() - ('a')->char2byte()+1] := H[i+1][(s[i - 1+1])->char2byte() - ('a')->char2byte()+1] + 1 ; for j : Integer.subrange(0, 26-1) do ( H[i+1][j+1] := H[i+1][j+1] + H[i - 1+1][j+1])) ; for j : Integer.subrange(0, m-1) do ( var l : OclAny := q[j+1]->first() ; var r : OclAny := q[j+1][1+1] ; var n : OclAny := q[j+1][2+1] ; var sum : int := 0 ; for i : Integer.subrange(0, 26-1) do ( sum := sum + H[r+1][i+1] - H[l - 1+1][i+1] ; if ((sum->compareTo(n)) >= 0) then ( execute ((('a')->char2byte() + i)->byte2char())->display() ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def equalizer(ls): big=max(ls) small=min(ls) steps=big-small return steps if __name__=='__main__' : test_cases=int(input()) answers=[] for i in range(test_cases): n=int(input()) ls=list(map(int,input().split())) steps=equalizer(ls) answers.append(steps) answer=[print(i)for i in answers] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var test_cases : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var answers : Sequence := Sequence{} ; for i : Integer.subrange(0, test_cases-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; ls := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; steps := equalizer(ls) ; execute ((steps) : answers)) ; var answer : Sequence := answers->select(i | true)->collect(i | ((i)->display())) ) else skip; operation equalizer(ls : OclAny) : OclAny pre: true post: true activity: var big : OclAny := (ls)->max() ; var small : OclAny := (ls)->min() ; var steps : double := big - small ; return steps; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countRotationsDivBy8(n): l=len(n) count=0 if(l==1): oneDigit=int(n[0]) if(oneDigit % 8==0): return 1 return 0 if(l==2): first=int(n[0])*10+int(n[1]) second=int(n[1])*10+int(n[0]) if(first % 8==0): count+=1 if(second % 8==0): count+=1 return count threeDigit=0 for i in range(0,(l-2)): threeDigit=(int(n[i])*100+int(n[i+1])*10+int(n[i+2])) if(threeDigit % 8==0): count+=1 threeDigit=(int(n[l-1])*100+int(n[0])*10+int(n[1])) if(threeDigit % 8==0): count+=1 threeDigit=(int(n[l-2])*100+int(n[l-1])*10+int(n[0])) if(threeDigit % 8==0): count+=1 return count if __name__=='__main__' : n="43262488612" print("Rotations:",countRotationsDivBy8(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := "43262488612" ; execute ("Rotations:")->display() ) else skip; operation countRotationsDivBy8(n : OclAny) : OclAny pre: true post: true activity: var l : int := (n)->size() ; var count : int := 0 ; if (l = 1) then ( var oneDigit : int := ("" + ((n->first())))->toInteger() ; if (oneDigit mod 8 = 0) then ( return 1 ) else skip ; return 0 ) else skip ; if (l = 2) then ( var first : int := ("" + ((n->first())))->toInteger() * 10 + ("" + ((n[1+1])))->toInteger() ; var second : int := ("" + ((n[1+1])))->toInteger() * 10 + ("" + ((n->first())))->toInteger() ; if (first mod 8 = 0) then ( count := count + 1 ) else skip ; if (second mod 8 = 0) then ( count := count + 1 ) else skip ; return count ) else skip ; var threeDigit : int := 0 ; for i : Integer.subrange(0, (l - 2)-1) do ( threeDigit := (("" + ((n[i+1])))->toInteger() * 100 + ("" + ((n[i + 1+1])))->toInteger() * 10 + ("" + ((n[i + 2+1])))->toInteger()) ; if (threeDigit mod 8 = 0) then ( count := count + 1 ) else skip) ; threeDigit := (("" + ((n[l - 1+1])))->toInteger() * 100 + ("" + ((n->first())))->toInteger() * 10 + ("" + ((n[1+1])))->toInteger()) ; if (threeDigit mod 8 = 0) then ( count := count + 1 ) else skip ; threeDigit := (("" + ((n[l - 2+1])))->toInteger() * 100 + ("" + ((n[l - 1+1])))->toInteger() * 10 + ("" + ((n->first())))->toInteger()) ; if (threeDigit mod 8 = 0) then ( count := count + 1 ) else skip ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lights=list(map(int,input().split())) ans=0 for i in range(1,n-1): if lights[i-1]==1 and lights[i]==0 and lights[i+1]==1 : lights[i+1]=0 ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lights : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(1, n - 1-1) do ( if lights[i - 1+1] = 1 & lights[i+1] = 0 & lights[i + 1+1] = 1 then ( lights[i + 1+1] := 0 ; ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r=int(input()) k=[0]*(r+1) for x in range(2,r+1): if k[x]==0 : for y in range(2*x,r+1,x): k[y]+=1 print(k.count(2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (r + 1)) ; for x : Integer.subrange(2, r + 1-1) do ( if k[x+1] = 0 then ( for y : Integer.subrange(2 * x, r + 1-1)->select( $x | ($x - 2 * x) mod x = 0 ) do ( k[y+1] := k[y+1] + 1) ) else skip) ; execute (k->count(2))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def primeCount(arr,n): max_val=max(arr) prime=[True]*(max_val+1) prime[0]=prime[1]=False p=2 while p*p<=max_val : if prime[p]==True : for i in range(p*2,max_val+1,p): prime[i]=False p+=1 count=0 for i in range(0,n): if prime[arr[i]]: count+=1 return count def getPrefixArray(arr,n,pre): pre[0]=arr[0] for i in range(1,n): pre[i]=pre[i-1]+arr[i] if __name__=="__main__" : arr=[1,4,8,4] n=len(arr) pre=[None]*n getPrefixArray(arr,n,pre) print(primeCount(pre,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{4}->union(Sequence{8}->union(Sequence{ 4 }))) ; n := (arr)->size() ; pre := MatrixLib.elementwiseMult(Sequence{ null }, n) ; getPrefixArray(arr, n, pre) ; execute (primeCount(pre, n))->display() ) else skip; operation primeCount(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var max_val : OclAny := (arr)->max() ; var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (max_val + 1)) ; prime->first() := false; var prime[1+1] : boolean := false ; var p : int := 2 ; while (p * p->compareTo(max_val)) <= 0 do ( if prime[p+1] = true then ( for i : Integer.subrange(p * 2, max_val + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip ; p := p + 1) ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( if prime[arr[i+1]+1] then ( count := count + 1 ) else skip) ; return count; operation getPrefixArray(arr : OclAny, n : OclAny, pre : OclAny) pre: true post: true activity: pre->first() := arr->first() ; for i : Integer.subrange(1, n-1) do ( pre[i+1] := pre[i - 1+1] + arr[i+1]); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from queue import Queue def interLeaveQueue(q): if(q.qsize()% 2!=0): print("Input even number of integers.") s=[] halfSize=int(q.qsize()/2) for i in range(halfSize): s.append(q.queue[0]) q.get() while len(s)!=0 : q.put(s[-1]) s.pop() for i in range(halfSize): q.put(q.queue[0]) q.get() for i in range(halfSize): s.append(q.queue[0]) q.get() while len(s)!=0 : q.put(s[-1]) s.pop() q.put(q.queue[0]) q.get() if __name__=='__main__' : q=Queue() q.put(11) q.put(12) q.put(13) q.put(14) q.put(15) q.put(16) q.put(17) q.put(18) q.put(19) q.put(20) interLeaveQueue(q) length=q.qsize() for i in range(length): print(q.queue[0],end=" ") q.get() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( q := Queue() ; q.put(11) ; q.put(12) ; q.put(13) ; q.put(14) ; q.put(15) ; q.put(16) ; q.put(17) ; q.put(18) ; q.put(19) ; q.put(20) ; interLeaveQueue(q) ; var length : OclAny := q.qsize() ; for i : Integer.subrange(0, length-1) do ( execute (q.queue->first())->display() ; q.get()) ) else skip; operation interLeaveQueue(q : OclAny) pre: true post: true activity: if (q.qsize() mod 2 /= 0) then ( execute ("Input even number of integers.")->display() ) else skip ; var s : Sequence := Sequence{} ; var halfSize : int := ("" + ((q.qsize() / 2)))->toInteger() ; for i : Integer.subrange(0, halfSize-1) do ( execute ((q.queue->first()) : s) ; q.get()) ; while (s)->size() /= 0 do ( q.put(s->last()) ; s := s->front()) ; for i : Integer.subrange(0, halfSize-1) do ( q.put(q.queue->first()) ; q.get()) ; for i : Integer.subrange(0, halfSize-1) do ( execute ((q.queue->first()) : s) ; q.get()) ; while (s)->size() /= 0 do ( q.put(s->last()) ; s := s->front() ; q.put(q.queue->first()) ; q.get()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n,s,k=map(int,input().split()) a=list(map(int,input().split())) for i in range(0,k+1): if s-i>=1 and not s-i in a : print(i); break if s+i<=n and not s+i in a : print(i); break else : assert False for _ in range(int(input())): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve()); operation solve() pre: true post: true activity: var n : OclAny := null; var s : OclAny := null; var k : OclAny := null; Sequence{n,s,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name k))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (expr (atom (name s))) - (expr (atom (name i))))) >= (comparison (expr (atom (number (integer 1))))))) and (logical_test not (logical_test (comparison (comparison (expr (expr (atom (name s))) - (expr (atom (name i))))) in (comparison (expr (atom (name a))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))) ;)) (stmt (simple_stmt (small_stmt break)))))) (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (expr (atom (name s))) + (expr (atom (name i))))) <= (comparison (expr (atom (name n)))))) and (logical_test not (logical_test (comparison (comparison (expr (expr (atom (name s))) + (expr (atom (name i))))) in (comparison (expr (atom (name a))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))) ;)) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt assert (test (logical_test (comparison (expr (atom (name False)))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,s,k=map(int,input().split()) a=set(map(int,input().split())) if s not in a : print(0) continue for i in range(1,1001): if 0toInteger()-1) do ( var n : OclAny := null; var s : OclAny := null; var k : OclAny := null; Sequence{n,s,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; if (a)->excludes(s) then ( execute (0)->display() ; continue ) else skip ; for i : Integer.subrange(1, 1001-1) do ( if 0 < s - i & (s - i <= n) then ( if (a)->excludes(s - i) then ( execute (i)->display() ; break ) else skip ) else skip ; if 0 < s + i & (s + i <= n) then ( if (a)->excludes(s + i) then ( execute (i)->display() ; break ) else skip ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,s,k=map(int,input().split()) a=list(map(int,input().split())) j=set() for i in range(k): j.add(a[i]) for i in range(n): if s-i>=1 and not(s-i in j): print(i) break if s+i<=n and not(s+i in j): print(i) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var s : OclAny := null; var k : OclAny := null; Sequence{n,s,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var j : Set := Set{}->union(()) ; for i : Integer.subrange(0, k-1) do ( execute ((a[i+1]) : j)) ; for i : Integer.subrange(0, n-1) do ( if s - i >= 1 & not(((j)->includes(s - i))) then ( execute (i)->display() ; break ) else skip ; if (s + i->compareTo(n)) <= 0 & not(((j)->includes(s + i))) then ( execute (i)->display() ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): y=input().split() n=int(y[0]) s=int(y[1]) k=int(y[2]) h=input().split() a=[] for i in range(k): a.append(int(h[i])) s1=s s2=s x=0 while True : if(s1 not in a and s1<=n)or(s2 not in a and s2>=1): print(x) break else : s1+=1 s2-=1 x+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var y : OclAny := input().split() ; var n : int := ("" + ((y->first())))->toInteger() ; var s : int := ("" + ((y[1+1])))->toInteger() ; var k : int := ("" + ((y[2+1])))->toInteger() ; var h : OclAny := input().split() ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, k-1) do ( execute ((("" + ((h[i+1])))->toInteger()) : a)) ; var s1 : int := s ; var s2 : int := s ; var x : int := 0 ; while true do ( if ((a)->excludes(s1) & (s1->compareTo(n)) <= 0) or ((a)->excludes(s2) & s2 >= 1) then ( execute (x)->display() ; break ) else ( s1 := s1 + 1 ; s2 := s2 - 1 ; x := x + 1 ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def miner(a,b,mines): s=0 j=0 while jtoInteger() ; for _anon : Integer.subrange(0, t-1) do ( Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; mines := (OclFile["System.in"]).readLine() ; execute (miner(a, b, mines))->display()); operation miner(a : OclAny, b : OclAny, mines : OclAny) : OclAny pre: true post: true activity: var s : int := 0 ; var j : int := 0 ; while (j->compareTo((mines)->size())) < 0 & mines[j+1] /= "1" do ( j := j + 1) ; if j = (mines)->size() then ( return 0 ) else skip ; for i : Integer.subrange(j + 1, (mines)->size()-1) do ( if mines[i+1] = "0" & mines[i - 1+1] = "1" then ( var r1 : double := i - 1 ) else (if mines[i+1] = "1" & mines[i - 1+1] = "0" then ( s := s + Set{b * (i - r1 - 1), a}->min() ) else skip)) ; s := s + a ; return s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,s,k=[int(x)for x in input().split()] fl={int(x)for x in input().split()} i=0 while 1 : if max(s-i,1)not in fl or min(n,s+i)not in fl : print(i); break i+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var s : OclAny := null; var k : OclAny := null; Sequence{n,s,k} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var fl : Set := input().split()->select(x | true)->collect(x | ("" + ((x)))->toInteger())->asSet() ; var i : int := 0 ; while 1 do ( if (fl)->excludes(Set{s - i, 1}->max()) or (fl)->excludes(Set{n, s + i}->min()) then ( execute (i)->display(); break ) else skip ; i := i + 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import gcd def findRatio(m,n): Am=m-5 An=n-5 numerator=Am//(gcd(Am,An)) denominator=An//(gcd(Am,An)) print(numerator,'/',denominator) if __name__=='__main__' : m=10 n=20 findRatio(m,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( m := 10 ; n := 20 ; findRatio(m, n) ) else skip; operation findRatio(m : OclAny, n : OclAny) pre: true post: true activity: var Am : double := m - 5 ; var An : double := n - 5 ; var numerator : int := Am div (gcd(Am, An)) ; var denominator : int := An div (gcd(Am, An)) ; execute (numerator)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def findDigits(n): if(n<0): return 0 ; if(n<=1): return 1 ; x=((n*math.log10(n/math.e)+math.log10(2*math.pi*n)/2.0)); return math.floor(x)+1 ; print(findDigits(1)); print(findDigits(50000000)); print(findDigits(1000000000)); print(findDigits(120)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; execute (findDigits(1))->display(); ; execute (findDigits(50000000))->display(); ; execute (findDigits(1000000000))->display(); ; execute (findDigits(120))->display();; operation findDigits(n : OclAny) pre: true post: true activity: if (n < 0) then ( return 0; ) else skip ; if (n <= 1) then ( return 1; ) else skip ; var x : double := ((n * (n / )->log10() + (2 * * n)->log10() / 2.0)); ; return (x)->floor() + 1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find_sum(n,k): total_sum=(n*(n+1))//2 power=k while power<=n : total_sum-=power power*=k return total_sum n=11 ; k=2 print(find_sum(n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 11; k := 2 ; execute (find_sum(n, k))->display(); operation find_sum(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var total_sum : int := (n * (n + 1)) div 2 ; var power : OclAny := k ; while (power->compareTo(n)) <= 0 do ( total_sum := total_sum - power ; power := power * k) ; return total_sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=int(input()) cou=0 p=[0 for i in range(3005)] for i in range(2,3005): if p[i]==0 : for j in range(2*i,3005,i): p[j]+=1 for i in range(1,c+1): if p[i]==2 : cou+=1 print(cou) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cou : int := 0 ; var p : Sequence := Integer.subrange(0, 3005-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(2, 3005-1) do ( if p[i+1] = 0 then ( for j : Integer.subrange(2 * i, 3005-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ( p[j+1] := p[j+1] + 1) ) else skip) ; for i : Integer.subrange(1, c + 1-1) do ( if p[i+1] = 2 then ( cou := cou + 1 ) else skip) ; execute (cou)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def FirstDigit(arr,n): S=0 for i in range(n): S=S+math.log10(arr[i]*1.0) fract_S=S-math.floor(S) ans=math.pow(10,fract_S) return ans arr=[5,8,3,7] n=len(arr) print((int)(FirstDigit(arr,n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{5}->union(Sequence{8}->union(Sequence{3}->union(Sequence{ 7 }))) ; n := (arr)->size() ; execute ((OclType["int"])(FirstDigit(arr, n)))->display(); operation FirstDigit(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var S : int := 0 ; for i : Integer.subrange(0, n-1) do ( S := S + (arr[i+1] * 1.0)->log10()) ; var fract_S : double := S - (S)->floor() ; var ans : double := (10)->pow(fract_S) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSum(arr,n,k): sum=0 for i in range(n): if arr[i]% k==0 : sum+=arr[i] return sum if __name__=="__main__" : arr=[15,16,10,9,6,7,17] n=len(arr) k=3 print(findSum(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{15}->union(Sequence{16}->union(Sequence{10}->union(Sequence{9}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 17 })))))) ; n := (arr)->size() ; k := 3 ; execute (findSum(arr, n, k))->display() ) else skip; operation findSum(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] mod k = 0 then ( sum := sum + arr[i+1] ) else skip) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys iFile=open(sys.argv[1],"r") T=int(iFile.readline().strip()) for t in range(T): line=iFile.readline().strip().split() K=int(line[0]) L=int(line[1]) S=int(line[2]) keyboard=iFile.readline().strip() target=iFile.readline().strip() effectiveLength=len(target) for strPos in range(1,len(target)): if target[strPos :]==target[:-strPos]: effectiveLength=strPos break max_bananas=1+int((S-len(target))/effectiveLength) single_prob=1.0 for letter in target : if letter in keyboard : single_prob*=keyboard.count(letter)/len(keyboard) else : single_prob=0.0 max_bananas=0 break total_prob=single_prob*(S-len(target)+1) answer=max_bananas-total_prob output=str(answer) print("Case #"+str(t+1)+": "+output) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var iFile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) ; var T : int := ("" + ((iFile.readLine()->trim())))->toInteger() ; for t : Integer.subrange(0, T-1) do ( var line : OclAny := iFile.readLine()->trim().split() ; var K : int := ("" + ((line->first())))->toInteger() ; var L : int := ("" + ((line[1+1])))->toInteger() ; var S : int := ("" + ((line[2+1])))->toInteger() ; var keyboard : OclAny := iFile.readLine()->trim() ; var target : OclAny := iFile.readLine()->trim() ; var effectiveLength : int := (target)->size() ; for strPos : Integer.subrange(1, (target)->size()-1) do ( if target.subrange(strPos+1) = target.subrange(1,-strPos) then ( effectiveLength := strPos ; break ) else skip) ; var max_bananas : int := 1 + ("" + (((S - (target)->size()) / effectiveLength)))->toInteger() ; var single_prob : double := 1.0 ; for letter : target do ( if (keyboard)->includes(letter) then ( single_prob := single_prob * keyboard->count(letter) / (keyboard)->size() ) else ( single_prob := 0.0 ; max_bananas := 0 ; break )) ; var total_prob : double := single_prob * (S - (target)->size() + 1) ; var answer : double := max_bananas - total_prob ; var output : String := ("" + ((answer))) ; execute ("Case #" + ("" + ((t + 1))) + ": " + output)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maximunBananas(key,target,length): if lengthcompareTo((target)->size())) < 0 then ( return 0 ) else skip ; var d : OclAny := Set{} ; for i : Integer.subrange(0, (key)->size()-1) do ( if (d)->includes(key[i+1]) then ( d[key[i+1]+1] := d[key[i+1]+1] + 1 ) else ( d[key[i+1]+1] := 1 )) ; for i : Integer.subrange(0, (target)->size()-1) do ( if (d)->excludes(target[i+1]) then ( return 0 ) else skip) ; var advanced : int := (target)->size() ; for i : Integer.subrange(0, (target)->size() - 1-1) do ( if target.subrange(1,i + 1) = target.subrange((target)->size() - i - 1+1) then ( advanced := (target)->size() - i - 1 ) else skip) ; return 1 + ("" + (((length - (target)->size()) / advanced)))->toInteger(); operation expectedBananas(key : OclAny, target : OclAny, length : OclAny) : OclAny pre: true post: true activity: d := Set{} ; for i : Integer.subrange(0, (key)->size()-1) do ( if (d)->includes(key[i+1]) then ( d[key[i+1]+1] := d[key[i+1]+1] + 1 ) else ( d[key[i+1]+1] := 1 )) ; var prob : int := 1 ; for i : Integer.subrange(0, (target)->size()-1) do ( if (d)->includes(target[i+1]) then ( prob := prob * d[target[i+1]+1] / (key)->size() ) else ( return 0 )) ; return prob * (length - (target)->size() + 1); operation calculate() : OclAny pre: true post: true activity: var k : OclAny := null; var l : OclAny := null; var s : OclAny := null; Sequence{k,l,s} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; key := (OclFile["System.in"]).readLine() ; target := (OclFile["System.in"]).readLine() ; return maximunBananas(key, target, s) - expectedBananas(key, target, s); operation main() pre: true post: true activity: var ncase : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, ncase-1) do ( execute (StringLib.interpolateStrings('Case #{}:{}', Sequence{i + 1, calculate()}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function,division from collections import Counter def overlap_shift(s): for i in range(len(s)): if s.startswith(s[i+1 :]): return i+1 def tc(tci): [klen,tlen,s]=map(int,raw_input().split()) keyboard=raw_input() target=raw_input() assert klen==len(keyboard) assert tlen==len(target) assert s>=tlen sol=0.0 counter=Counter(keyboard) if all(t in counter for t in target): sh=overlap_shift(target) occs=1+(s-tlen)//sh p=1.0 for t in target : p*=counter[t]/klen sol=occs-p*(s-tlen+1) print("Case #{}:{:.15f}".format(tci,sol)) tcn=int(raw_input()) for tci in range(1,tcn+1): tc(tci) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var tcn : int := ("" + ((raw_input())))->toInteger() ; for tci : Integer.subrange(1, tcn + 1-1) do ( tc(tci)); operation overlap_shift(s : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, (s)->size()-1) do ( if s->hasPrefix(s.subrange(i + 1+1)) then ( return i + 1 ) else skip); operation tc(tci : OclAny) pre: true post: true activity: ; Sequence{klen}->union(Sequence{tlen}->union(Sequence{ s })) := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var keyboard : OclAny := raw_input() ; var target : OclAny := raw_input() ; assert klen = (keyboard)->size() do "assertion failed" ; assert tlen = (target)->size() do "assertion failed" ; assert (s->compareTo(tlen)) >= 0 do "assertion failed" ; var sol : double := 0.0 ; var counter : OclAny := Counter(keyboard) ; if ((argument (test (logical_test (comparison (comparison (expr (atom (name t)))) in (comparison (expr (atom (name counter))))))) (comp_for for (exprlist (expr (atom (name t)))) in (logical_test (comparison (expr (atom (name target))))))))->forAll( _x | _x = true ) then ( var sh : OclAny := overlap_shift(target) ; var occs : int := 1 + (s - tlen) div sh ; var p : double := 1.0 ; for t : target do ( p := p * counter[t+1] / klen) ; sol := occs - p * (s - tlen + 1) ) else skip ; execute (StringLib.interpolateStrings("Case #{}:{:.15f}", Sequence{tci, sol}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while(t): a,b=[int(i)for i in input().split()] s=input() l=len(s) i=0 cluster=0 z=[] first=False while(itoInteger() ; while (t) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var s : String := (OclFile["System.in"]).readLine() ; var l : int := (s)->size() ; var i : int := 0 ; var cluster : int := 0 ; var z : Sequence := Sequence{} ; var first : boolean := false ; while ((i->compareTo(l)) < 0) do ( if (first = false) then ( if (s[i+1] = "1") then ( first := true ; cluster := cluster + 1 ; var j : int := i ; while (s[j+1] = "1") do ( j := j + 1 ; if (j = l) then ( break ) else skip) ; i := j ) else ( i := i + 1 ) ) else ( if (s[i+1] = "0") then ( var c : int := 0 ; j := i ; while (s[j+1] = "0") do ( j := j + 1 ; c := c + 1 ; if (j = l) then ( break ) else skip) ; i := j ; execute ((c) : z) ) else ( cluster := cluster + 1 ; j := i ; while (s[j+1] = "1") do ( j := j + 1 ; if (j = l) then ( break ) else skip) ; i := j ) )) ; if (cluster = 0) then ( execute (0)->display() ) else (if (cluster = 1) then ( execute (a)->display() ) else ( if (s->last() = "0") then ( z := z->front() ) else skip ; var mincost : double := cluster * a ; var y : int := 0 ; for i : z do ( mincost := Set{mincost, ((cluster - 1) * a) + (b * (y + i))}->min() ; if (mincost = ((cluster - 1) * a) + (b * (y + i))) then ( cluster := cluster - 1 ; y := y + i ) else skip) ; execute (mincost)->display() ) ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numbers=list(map(int,input().split())) data={'dept' : 0} def change_count(index): dif=data[f'{index}']['owes']-data[f'{index}']['have'] if dif<=0 : data['dept']-=data[f'{index}']['count'] data[f'{index}']['count']=0 else : data['dept']+=dif-data[f'{index}']['count'] data[f'{index}']['count']=dif for i in range(0,numbers[1]): x=list(map(int,input().split())) for z in range(0,2): if not f"{x[z]}" in data.keys(): data[f'{x[z]}']={"owes" : 0,"have" : 0,"count" : 0} data[f"{x[0]}"]['owes']+=x[2] data[f"{x[1]}"]['have']+=x[2] change_count(x[0]) change_count(x[1]) print(data['dept']) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var numbers : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var data : Map := Map{ 'dept' |-> 0 } ; skip ; for i : Integer.subrange(0, numbers[1+1]-1) do ( var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for z : Integer.subrange(0, 2-1) do ( if not((data.keys())->includes(StringLib.formattedString("{x[z]}"))) then ( data[StringLib.formattedString('{x[z]}')+1] := Map{ "owes" |-> 0 }->union(Map{ "have" |-> 0 }->union(Map{ "count" |-> 0 })) ) else skip) ; data[StringLib.formattedString("{x[0]}")+1]->at('owes') := data[StringLib.formattedString("{x[0]}")+1]->at('owes') + x[2+1] ; data[StringLib.formattedString("{x[1]}")+1]->at('have') := data[StringLib.formattedString("{x[1]}")+1]->at('have') + x[2+1] ; change_count(x->first()) ; change_count(x[1+1])) ; execute (data->at('dept'))->display(); operation change_count(index : OclAny) pre: true post: true activity: var dif : double := data[StringLib.formattedString('{index}')+1]->at('owes') - data[StringLib.formattedString('{index}')+1]->at('have') ; if dif <= 0 then ( data->at('dept') := data->at('dept') - data[StringLib.formattedString('{index}')+1]->at('count') ; data[StringLib.formattedString('{index}')+1]->at('count') := 0 ) else ( data->at('dept') := data->at('dept') + dif - data[StringLib.formattedString('{index}')+1]->at('count') ; data[StringLib.formattedString('{index}')+1]->at('count') := dif ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) balances=[0]*n for i in range(m): fro,to,am=map(int,input().split()) balances[fro-1]-=am balances[to-1]+=am ans=0 for i in range(n): if balances[i]<0 : ans+=-balances[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var balances : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, m-1) do ( var fro : OclAny := null; var to : OclAny := null; var am : OclAny := null; Sequence{fro,to,am} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; balances[fro - 1+1] := balances[fro - 1+1] - am ; balances[to - 1+1] := balances[to - 1+1] + am) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if balances[i+1] < 0 then ( ans := ans + -balances[i+1] ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(i)for i in input().split()]; dic=dict(); cou=0 for i in range(1,n+1): dic[i]=0 for i in range(m): a,b,c=list(map(int,input().split())) dic[a]-=c ; dic[b]+=c for i in dic.values(): if i>0 : cou+=i print(cou) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); var dic : Map := (arguments ( )); var cou : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( dic[i+1] := 0) ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; dic[a+1] := dic[a+1] - c; dic[b+1] := dic[b+1] + c) ; for i : dic.values() do ( if i > 0 then ( cou := cou + i ) else skip) ; execute (cou)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()); lst=[0]*(n+1); s=0 for i in range(m): a,b,c=map(int,input().split()); lst[a]+=c ; lst[b]-=c for i in lst : s+=abs(i) print(s//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var lst : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); var s : int := 0 ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); lst[a+1] := lst[a+1] + c; lst[b+1] := lst[b+1] - c) ; for i : lst do ( s := s + (i)->abs()) ; execute (s div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) debts=[0]*n for _ in range(m): minus,plus,value=map(int,input().split()) debts[minus-1]-=value debts[plus-1]+=value print(sum([debt for debt in debts if debt>0])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var debts : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for _anon : Integer.subrange(0, m-1) do ( var minus : OclAny := null; var plus : OclAny := null; var value : OclAny := null; Sequence{minus,plus,value} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; debts[minus - 1+1] := debts[minus - 1+1] - value ; debts[plus - 1+1] := debts[plus - 1+1] + value) ; execute ((debts->select(debt | debt > 0)->collect(debt | (debt)))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def SieveOfEratosthenes(n): l_prime=[] not_prime=[] prime=[True for i in range(n+1)] p=2 while p*p<=n : if prime[p]==True : for i in range(p*p,n+1,p): prime[i]=False p+=1 for p in range(2,n+1): if prime[p]: l_prime.append(p) else : not_prime.append(p) return l_prime,not_prime n=int(input()) l_prime,not_prime=SieveOfEratosthenes(n) count=0 set1=set(l_prime) for i in not_prime : l=[] j=2 while j*j<=i : if i % j==0 : l.append(j) l.append(i//j) j+=1 set2=set(l) c=set1.intersection(set2) if len(c)==2 : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; Sequence{l_prime,not_prime} := SieveOfEratosthenes(n) ; var count : int := 0 ; var set1 : Set := Set{}->union((l_prime)) ; for i : not_prime do ( var l : Sequence := Sequence{} ; var j : int := 2 ; while (j * j->compareTo(i)) <= 0 do ( if i mod j = 0 then ( execute ((j) : l) ; execute ((i div j) : l) ) else skip ; j := j + 1) ; var set2 : Set := Set{}->union((l)) ; var c : OclAny := set1->intersection(set2) ; if (c)->size() = 2 then ( count := count + 1 ) else skip) ; execute (count)->display(); operation SieveOfEratosthenes(n : OclAny) : OclAny pre: true post: true activity: var l_prime : Sequence := Sequence{} ; var not_prime : Sequence := Sequence{} ; var prime : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (true)) ; var p : int := 2 ; while (p * p->compareTo(n)) <= 0 do ( if prime[p+1] = true then ( for i : Integer.subrange(p * p, n + 1-1)->select( $x | ($x - p * p) mod p = 0 ) do ( prime[i+1] := false) ) else skip ; p := p + 1) ; for p : Integer.subrange(2, n + 1-1) do ( if prime[p+1] then ( execute ((p) : l_prime) ) else ( execute ((p) : not_prime) )) ; return l_prime, not_prime; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : (n,m)=[int(x)for x in input().split()] if n==0 and m==0 : exit() a=[] b=[] for i in range(n): a.append(int(input())) for i in range(m): b.append(int(input())) a_sum=sum(a) b_sum=sum(b) target=a_sum-b_sum found=False for ai in a : for bi in b : if(ai-bi)*2==target : print(ai,bi) found=True if found : break if found : break if found==False : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( ; var Sequence{n, m} : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if n = 0 & m = 0 then ( exit() ) else skip ; var a : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : a)) ; for i : Integer.subrange(0, m-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : b)) ; var a_sum : OclAny := (a)->sum() ; var b_sum : OclAny := (b)->sum() ; var target : double := a_sum - b_sum ; var found : boolean := false ; for ai : a do ( for bi : b do ( if (ai - bi) * 2 = target then ( execute (ai)->display() ; found := true ) else skip ; if found then ( break ) else skip) ; if found then ( break ) else skip) ; if found = false then ( execute (-1)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n,m=map(int,input().split()) if n==0 : break taro=[] hana=[] for i in range(n): taro.append(int(input())) for i in range(m): hana.append(int(input())) t_sum=sum(taro) h_sum=sum(hana) d=t_sum-h_sum mn=99999999 ans=[-1] for i in range(n): for j in range(m): if(t_sum-taro[i]+hana[j])==(h_sum-hana[j]+taro[i]): if mn>taro[i]+hana[j]: mn=taro[i]+hana[j] ans=(taro[i],hana[j]) print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var taro : Sequence := Sequence{} ; var hana : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : taro)) ; for i : Integer.subrange(0, m-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : hana)) ; var t_sum : OclAny := (taro)->sum() ; var h_sum : OclAny := (hana)->sum() ; var d : double := t_sum - h_sum ; var mn : int := 99999999 ; var ans : Sequence := Sequence{ -1 } ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if (t_sum - taro[i+1] + hana[j+1]) = (h_sum - hana[j+1] + taro[i+1]) then ( if (mn->compareTo(taro[i+1] + hana[j+1])) > 0 then ( mn := taro[i+1] + hana[j+1] ; ans := Sequence{taro[i+1], hana[j+1]} ) else skip ) else skip)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def search(t,st,h,sh): for ta in t : for ha in h : if st-ta+ha==sh-ha+ta : return ' '.join(map(str,[ta,ha])) return-1 while True : n,m=map(int,input().split()) if n==m==0 : break t=sorted([int(input())for _ in range(n)]) h=sorted([int(input())for _ in range(m)]) st,sh=sum(t),sum(h) r=search(t,st,h,sh) print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = m & (m == 0) then ( break ) else skip ; t := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))->sort() ; h := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))->sort() ; Sequence{st,sh} := Sequence{(t)->sum(),(h)->sum()} ; var r : OclAny := search(t, st, h, sh) ; execute (r)->display()); operation search(t : OclAny, st : OclAny, h : OclAny, sh : OclAny) : OclAny pre: true post: true activity: for ta : t do ( for ha : h do ( if st - ta + ha = sh - ha + ta then ( return StringLib.sumStringsWithSeparator(((Sequence{ta}->union(Sequence{ ha }))->collect( _x | (OclType["String"])->apply(_x) )), ' ') ) else skip)) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : data=input().split() n,m=int(data[0]),int(data[1]) if n==0 and m==0 : break tarou_cards=[] hanako_cards=[] cards_size=n+m total=0 t_total=0 h_total=0 for i in range(0,cards_size): point=int(input()) total+=point if n>=i+1 : tarou_cards.append(point) t_total+=point else : hanako_cards.append(point) h_total+=point tarou_cards.sort() hanako_cards.sort() if total % 2!=0 : print("-1") continue exchangeFlg=False target=t_total-total/2 for t_card in tarou_cards : for h_card in hanako_cards : diff=t_card-h_card if diff==target : print("{}{}".format(t_card,h_card)) exchangeFlg=True break if exchangeFlg : break if exchangeFlg!=True : print("-1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var data : OclAny := input().split() ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{("" + ((data->first())))->toInteger(),("" + ((data[1+1])))->toInteger()} ; if n = 0 & m = 0 then ( break ) else skip ; var tarou_cards : Sequence := Sequence{} ; var hanako_cards : Sequence := Sequence{} ; var cards_size : OclAny := n + m ; var total : int := 0 ; var t_total : int := 0 ; var h_total : int := 0 ; for i : Integer.subrange(0, cards_size-1) do ( var point : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; total := total + point ; if (n->compareTo(i + 1)) >= 0 then ( execute ((point) : tarou_cards) ; t_total := t_total + point ) else ( execute ((point) : hanako_cards) ; h_total := h_total + point )) ; tarou_cards := tarou_cards->sort() ; hanako_cards := hanako_cards->sort() ; if total mod 2 /= 0 then ( execute ("-1")->display() ; continue ) else skip ; var exchangeFlg : boolean := false ; var target : double := t_total - total / 2 ; for t_card : tarou_cards do ( for h_card : hanako_cards do ( var diff : double := t_card - h_card ; if diff = target then ( execute (StringLib.interpolateStrings("{}{}", Sequence{t_card, h_card}))->display() ; exchangeFlg := true ; break ) else skip) ; if exchangeFlg then ( break ) else skip) ; if exchangeFlg /= true then ( execute ("-1")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def findGreater(a,b): x=a*(math.log(b)); y=b*(math.log(a)); if(y>x): print("a^b is greater"); elif(y; operation findGreater(a : OclAny, b : OclAny) pre: true post: true activity: var x : double := a * ((b)->log()); ; var y : double := b * ((a)->log()); ; if ((y->compareTo(x)) > 0) then ( execute ("a^b is greater")->display(); ) else (if ((y->compareTo(x)) < 0) then ( execute ("b^a is greater")->display(); ) else ( execute ("Both are equal")->display(); ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a,b=map(int,input().split()) s=(input()) ind=[] for j in range(len(s)): if s[j]=="1" : ind.append(j+1) var=[] for j in range(len(ind)-1): if ind[j+1]-ind[j]!=1 : var.append(ind[j+1]-ind[j]-1) answer=[] ans=0 for j in range(len(var)): if var[j]*b<=a : ans+=var[j]*b else : answer.append(ans+a) ans=0 if j==len(var)-1 : answer.append(ans+a) if s.count("1")==0 : print(0) elif len(answer)==0 : print(a) else : print(sum(answer)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := ((OclFile["System.in"]).readLine()) ; var ind : Sequence := Sequence{} ; for j : Integer.subrange(0, (s)->size()-1) do ( if s[j+1] = "1" then ( execute ((j + 1) : ind) ) else skip) ; var var : Sequence := Sequence{} ; for j : Integer.subrange(0, (ind)->size() - 1-1) do ( if ind[j + 1+1] - ind[j+1] /= 1 then ( execute ((ind[j + 1+1] - ind[j+1] - 1) : var) ) else skip) ; var answer : Sequence := Sequence{} ; var ans : int := 0 ; for j : Integer.subrange(0, (var)->size()-1) do ( if (var[j+1] * b->compareTo(a)) <= 0 then ( ans := ans + var[j+1] * b ) else ( execute ((ans + a) : answer) ; ans := 0 ) ; if j = (var)->size() - 1 then ( execute ((ans + a) : answer) ) else skip) ; if s->count("1") = 0 then ( execute (0)->display() ) else (if (answer)->size() = 0 then ( execute (a)->display() ) else ( execute ((answer)->sum())->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans_list=[] while True : n,m=map(int,input().split()) if(n,m)==(0,0): break S=[int(input())for _ in range(n)] T=[int(input())for _ in range(m)] ss=sum(S) tt=sum(T) ans=(101,101) for s in S : for t in T : if ss-s+t==tt-t+s and s+tcollect( _x | (OclType["int"])->apply(_x) ) ; if Sequence{n, m} = Sequence{0, 0} then ( break ) else skip ; var S : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var T : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var ss : OclAny := (S)->sum() ; var tt : OclAny := (T)->sum() ; var ans : OclAny := Sequence{101, 101} ; for s : S do ( for t : T do ( if ss - s + t = tt - t + s & (s + t->compareTo((ans)->sum())) < 0 then ( ans := Sequence{s, t} ) else skip)) ; if ans = Sequence{101, 101} then ( ans := -1 ) else ( ans := StringLib.interpolateStrings("{}{}", Sequence{ans->first(), ans[1+1]}) ) ; execute ((ans) : ans_list)) ; for ans : ans_list do ( execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def fixedPoint(self,A): l,h=0,len(A)-1 while l<=h : mid=(l+h)//2 if A[mid]mid : h=mid-1 else : return mid return-1 ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation fixedPoint(A : OclAny) : OclAny pre: true post: true activity: var l : OclAny := null; var h : OclAny := null; Sequence{l,h} := Sequence{0,(A)->size() - 1} ; while (l->compareTo(h)) <= 0 do ( var mid : int := (l + h) div 2 ; if (A[mid+1]->compareTo(mid)) < 0 then ( var l : int := mid + 1 ) else (if (A[mid+1]->compareTo(mid)) > 0 then ( var h : double := mid - 1 ) else ( return mid ) ) ) ; return -1; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(): n=int(input()) edges=[] for i in range(n): edges.append(list(map(int,sys.stdin.readline().split()))) ans=0 for i in range(n-1): for j in range(i+1,n): ans+=min(edges[i][j],edges[j][i]) print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var edges : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) : edges)) ; var ans : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(i + 1, n-1) do ( ans := ans + Set{edges[i+1][j+1], edges[j+1][i+1]}->min())) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 dd=[(0,-1),(1,0),(0,1),(-1,0)] ddn=[(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)] def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] while True : n=I() a=[LI()for _ in range(n)] r=0 for i in range(n): for j in range(i+1,n): r+=min(a[i][j],a[j][i]) rr.append(r) break return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; var dd : Sequence := Sequence{Sequence{0, -1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{ Sequence{-1, 0} }))) ; var ddn : Sequence := Sequence{Sequence{0, -1}}->union(Sequence{Sequence{1, -1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{1, 1}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{-1, -1}}->union(Sequence{Sequence{-1, 0}}->union(Sequence{ Sequence{-1, 1} }))))))) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var n : OclAny := I() ; var a : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI())) ; var r : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( r := r + Set{a[i+1][j+1], a[j+1][i+1]}->min())) ; execute ((r) : rr) ; break) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) graph=[[0 for i in range(n)]for i in range(n)] for i in range(n): graph[i]=list(map(int,input().split())) ans=0 for i in range(n): for j in range(i+1,n): ans+=min(graph[i][j],graph[j][i]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var graph : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, n-1) do ( graph[i+1] := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( ans := ans + Set{graph[i+1][j+1], graph[j+1][i+1]}->min())) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- CHARS=26 def remAnagram(str1,str2): count1=[0]*CHARS count2=[0]*CHARS i=0 while idisplay() ) else skip; operation remAnagram(str1 : OclAny, str2 : OclAny) : OclAny pre: true post: true activity: var count1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, CHARS) ; var count2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, CHARS) ; var i : int := 0 ; while (i->compareTo((str1)->size())) < 0 do ( count1[(str1[i+1])->char2byte() - ('a')->char2byte()+1] := count1[(str1[i+1])->char2byte() - ('a')->char2byte()+1] + 1 ; i := i + 1) ; i := 0 ; while (i->compareTo((str2)->size())) < 0 do ( count2[(str2[i+1])->char2byte() - ('a')->char2byte()+1] := count2[(str2[i+1])->char2byte() - ('a')->char2byte()+1] + 1 ; i := i + 1) ; var result : int := 0 ; for i : Integer.subrange(0, 26-1) do ( result := result + (count1[i+1] - count2[i+1])->abs()) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections p=[0]*(3005) p[0]=0 p[1]=0 p[2]=1 def sieve_prime(p,n): for i in range(3,n,2): p[i]=1 for i in range(3,n,2): if p[i]==1 : for j in range(i*i,n,i): p[j]=0 return p def is_prime(n,primes): mp=collections.defaultdict(list) for i in range(2,n): if primes[i]==1 : for j in range(i,n,i): if j not in mp : mp[j]=1 else : mp[j]+=1 ans=0 for i in range(2,n): if mp[i]==2 : ans+=1 return ans primes=sieve_prime(p,3005) n=int(input()) print(is_prime(n+1,primes)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var p : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (3005)) ; p->first() := 0 ; p[1+1] := 0 ; p[2+1] := 1 ; skip ; skip ; primes := sieve_prime(p, 3005) ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (is_prime(n + 1, primes))->display(); operation sieve_prime(p : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(3, n-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( p[i+1] := 1) ; for i : Integer.subrange(3, n-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if p[i+1] = 1 then ( for j : Integer.subrange(i * i, n-1)->select( $x | ($x - i * i) mod i = 0 ) do ( p[j+1] := 0) ) else skip) ; return p; operation is_prime(n : OclAny, primes : OclAny) : OclAny pre: true post: true activity: var mp : OclAny := .defaultdict(OclType["Sequence"]) ; for i : Integer.subrange(2, n-1) do ( if primes[i+1] = 1 then ( for j : Integer.subrange(i, n-1)->select( $x | ($x - i) mod i = 0 ) do ( if (mp)->excludes(j) then ( mp[j+1] := 1 ) else ( mp[j+1] := mp[j+1] + 1 )) ) else skip) ; var ans : int := 0 ; for i : Integer.subrange(2, n-1) do ( if mp[i+1] = 2 then ( ans := ans + 1 ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sin def polyarea(n,r): if(r<0 and n<0): return-1 A=(((r*r*n)*sin((360/n)*3.14159/180))/2); return round(A,3) if __name__=="__main__" : r,n=9,6 print(polyarea(n,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( Sequence{r,n} := Sequence{9,6} ; execute (polyarea(n, r))->display() ) else skip; operation polyarea(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: if (r < 0 & n < 0) then ( return -1 ) else skip ; var A : double := (((r * r * n) * sin((360 / n) * 3.14159 / 180)) / 2); ; return MathLib.roundN(A, 3); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from xml.etree.ElementPath import prepare_parent for _ in range(int(input())): s=input() ans='YES' m={} m2={} for i in s : if i not in m : m[i]=1 else : m[i]+=1 if len(m)==1 : print('YES') continue for i in range(len(s)): if s[i]not in m2 : m2[s[i]]=[i] else : m2[s[i]].append(i) for i in m2 : for j in range(len(m2[i])-1): if abs(m2[i][j]-m2[i][j+1])toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var ans : String := 'YES' ; var m : OclAny := Set{} ; var m2 : OclAny := Set{} ; for i : s->characters() do ( if (m)->excludes(i) then ( m[i+1] := 1 ) else ( m[i+1] := m[i+1] + 1 )) ; if (m)->size() = 1 then ( execute ('YES')->display() ; continue ) else skip ; for i : Integer.subrange(0, (s)->size()-1) do ( if (m2)->excludes(s[i+1]) then ( m2[s[i+1]+1] := Sequence{ i } ) else ( (expr (atom (name m2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) )) ; for i : m2 do ( for j : Integer.subrange(0, (m2[i+1])->size() - 1-1) do ( if ((m2[i+1][j+1] - m2[i+1][j + 1+1])->abs()->compareTo((m)->size())) < 0 then ( ans := 'NO' ; break ) else skip)) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): for _ in range(int(input())): string=input() n=len(string) mp={} flag=True for i in string : mp[i]=mp.get(i,0)+1 count=len(mp) for i in range(0,n-count): if string[i]!=string[i+count]: flag=False if flag : print("YES") else : print("NO") main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var string : String := (OclFile["System.in"]).readLine() ; var n : int := (string)->size() ; var mp : OclAny := Set{} ; var flag : boolean := true ; for i : string->characters() do ( mp[i+1] := mp.get(i, 0) + 1) ; var count : int := (mp)->size() ; for i : Integer.subrange(0, n - count-1) do ( if string[i+1] /= string[i + count+1] then ( flag := false ) else skip) ; if flag then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def miner(a,b,mines): s=0 j=0 while jtoInteger() ; for _anon : Integer.subrange(0, t-1) do ( Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; mines := (OclFile["System.in"]).readLine() ; execute (miner(a, b, mines))->display()); operation miner(a : OclAny, b : OclAny, mines : OclAny) : OclAny pre: true post: true activity: var s : int := 0 ; var j : int := 0 ; while (j->compareTo((mines)->size())) < 0 & mines[j+1] /= "1" do ( j := j + 1) ; if j = (mines)->size() then ( return 0 ) else skip ; for i : Integer.subrange(j + 1, (mines)->size()-1) do ( if mines[i+1] = "0" & mines[i - 1+1] = "1" then ( var r1 : double := i - 1 ) else (if mines[i+1] = "1" & mines[i - 1+1] = "0" then ( if (b * (i - r1 - 1)->compareTo(a)) <= 0 then ( s := s + b * (i - r1 - 1) ) else ( s := s + a ) ) else skip)) ; s := s + a ; return s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): s=input() c=len(set(s)) print("Yes" if all(len(set(s[i : : c]))==1 for i in range(c))else "No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var c : int := (Set{}->union((s)))->size() ; execute (if ((argument (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))) : (sliceop : (test (logical_test (comparison (expr (atom (name c))))))))) ])))))))) ))))))))) ))))) == (comparison (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))))))))->forAll( _x | _x = true ) then "Yes" else "No" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for _ in range(T): s=input() marker=[] for i in range(26): marker.append([]) for i in range(len(s)): marker[ord(s[i])-97].append(i) count=0 for i in range(26): if len(marker[i])>0 : count+=1 if count==1 : print('YES') else : ans=True for item in marker : for i in range(len(item)-1): if item[i+1]-item[i]toInteger() ; for _anon : Integer.subrange(0, T-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var marker : Sequence := Sequence{} ; for i : Integer.subrange(0, 26-1) do ( execute ((Sequence{}) : marker)) ; for i : Integer.subrange(0, (s)->size()-1) do ((expr (atom (name marker)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name ord)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))) - (expr (atom (number (integer 97)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var count : int := 0 ; for i : Integer.subrange(0, 26-1) do ( if (marker[i+1])->size() > 0 then ( count := count + 1 ) else skip) ; if count = 1 then ( execute ('YES')->display() ) else ( var ans : boolean := true ; for item : marker do ( for i : Integer.subrange(0, (item)->size() - 1-1) do ( if (item[i + 1+1] - item[i+1]->compareTo(count)) < 0 then ( ans := false ; break ) else skip) ; if ans = false then ( break ) else skip) ; if not(ans) then ( execute ('NO')->display() ) else ( execute ('YES')->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict from bisect import bisect_left for _ in range(int(input())): s=input() st=set(s) n=len(st) i=0 j=0 while jtoInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var st : Set := Set{}->union((s)) ; var n : int := (st)->size() ; var i : int := 0 ; var j : int := 0 ; (compound_stmt while (test (logical_test (comparison (comparison (expr (atom (name j)))) < (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (expr (atom (name j))) - (expr (atom (name i)))) + (expr (atom (number (integer 1)))))) == (comparison (expr (atom (name n))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name st1)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))) : (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 1)))))))))) ])))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name st1)))))))) ))))) < (comparison (expr (atom (name n))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name j)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name j)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def surfaceArea(b,s): return 2*b*s+pow(b,2) if __name__=="__main__" : b=3 s=4 print(surfaceArea(b,s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( b := 3 ; s := 4 ; execute (surfaceArea(b, s))->display() ) else skip; operation surfaceArea(b : OclAny, s : OclAny) : OclAny pre: true post: true activity: return 2 * b * s + (b)->pow(2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count(s,Len): global MAX cur=0 dig=0 Sum=[0]*MAX dp=[[0,0,0]for i in range(MAX)] dp[0][0]=1 for i in range(1,Len+1): dig=int(s[i-1])-48 cur+=dig cur %=3 Sum[i]=cur dp[i][0]=dp[i-1][0] dp[i][1]=dp[i-1][1] dp[i][2]=dp[i-1][2] dp[i][Sum[i]]+=1 ans=0 dprev=0 value=0 dprev2=0 for i in range(1,Len+1): dig=int(s[i-1])-48 if dig==8 : ans+=1 if i-2>=0 : dprev=int(s[i-2])-48 value=dprev*10+dig if(value % 8==0)and(value % 3!=0): ans+=1 if i-3>=0 : dprev2=int(s[i-3])-48 dprev=int(s[i-2])-48 value=(dprev2*100+dprev*10+dig) if value % 8!=0 : continue ans+=(i-2) ans-=(dp[i-3][Sum[i]]) return ans MAX=1000 Str="6564525600" Len=len(Str) print(count(Str,Len)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute MAX : OclAny; operation initialise() pre: true post: true activity: skip ; MAX := 1000 ; var Str : String := "6564525600" ; Len := (Str)->size() ; execute (count(Str, Len))->display(); operation count(s : OclAny, Len : OclAny) : OclAny pre: true post: true activity: skip ; var cur : int := 0 ; var dig : int := 0 ; var Sum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX) ; var dp : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))) ; dp->first()->first() := 1 ; for i : Integer.subrange(1, Len + 1-1) do ( dig := ("" + ((s[i - 1+1])))->toInteger() - 48 ; cur := cur + dig ; cur := cur mod 3 ; Sum[i+1] := cur ; dp[i+1]->first() := dp[i - 1+1]->first() ; dp[i+1][1+1] := dp[i - 1+1][1+1] ; dp[i+1][2+1] := dp[i - 1+1][2+1] ; dp[i+1][Sum[i+1]+1] := dp[i+1][Sum[i+1]+1] + 1) ; var ans : int := 0 ; var dprev : int := 0 ; var value : int := 0 ; var dprev2 : int := 0 ; for i : Integer.subrange(1, Len + 1-1) do ( dig := ("" + ((s[i - 1+1])))->toInteger() - 48 ; if dig = 8 then ( ans := ans + 1 ) else skip ; if i - 2 >= 0 then ( dprev := ("" + ((s[i - 2+1])))->toInteger() - 48 ; value := dprev * 10 + dig ; if (value mod 8 = 0) & (value mod 3 /= 0) then ( ans := ans + 1 ) else skip ) else skip ; if i - 3 >= 0 then ( dprev2 := ("" + ((s[i - 3+1])))->toInteger() - 48 ; dprev := ("" + ((s[i - 2+1])))->toInteger() - 48 ; value := (dprev2 * 100 + dprev * 10 + dig) ; if value mod 8 /= 0 then ( continue ) else skip ; ans := ans + (i - 2) ; ans := ans - (dp[i - 3+1][Sum[i+1]+1]) ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sieve(maxm,prime): prime[0]=prime[1]=1 ; i=2 ; while(i*i<=maxm): if(prime[i]==0): for j in range(2*i,maxm+1,i): prime[j]=1 ; i+=1 ; def countPair(a,n): maxm=max(a); prime=[0]*(maxm+1); sieve(maxm,prime); countPrimes=0 ; for i in range(n): if(prime[a[i]]==0): countPrimes+=1 ; nonPrimes=n-countPrimes ; pairswith1Prime=nonPrimes*countPrimes ; pairsWith2Primes=(countPrimes*(countPrimes-1))//2 ; return pairswith1Prime+pairsWith2Primes ; arr=[2,3,5,4,7]; n=len(arr); print(countPair(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var arr : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{4}->union(Sequence{ 7 })))); ; n := (arr)->size(); ; execute (countPair(arr, n))->display();; operation sieve(maxm : OclAny, prime : OclAny) pre: true post: true activity: prime->first() := 1; var prime[1+1] : int := 1; ; var i : int := 2; ; while ((i * i->compareTo(maxm)) <= 0) do ( if (prime[i+1] = 0) then ( for j : Integer.subrange(2 * i, maxm + 1-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ( prime[j+1] := 1;) ) else skip ; i := i + 1;); operation countPair(a : OclAny, n : OclAny) pre: true post: true activity: maxm := (a)->max(); ; prime := MatrixLib.elementwiseMult(Sequence{ 0 }, (maxm + 1)); ; sieve(maxm, prime); ; var countPrimes : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (prime[a[i+1]+1] = 0) then ( countPrimes := countPrimes + 1; ) else skip) ; var nonPrimes : double := n - countPrimes; ; var pairswith1Prime : double := nonPrimes * countPrimes; ; var pairsWith2Primes : int := (countPrimes * (countPrimes - 1)) div 2; ; return pairswith1Prime + pairsWith2Primes;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input n=int(I()) s=I() print(sum(2>len(set(s[i-3 : i]))for i in range(n,len(s),n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; var n : int := ("" + ((I())))->toInteger() ; var s : OclAny := I() ; execute (((argument (test (logical_test (comparison (comparison (expr (atom (number (integer 2))))) > (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 3)))))))) : (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))))))) )))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) def isprime(x): if x<=2 : return x==2 for i in range(2,x): if x % i==0 : return 0 return 1 ans=0 for i in range(1,n+1): s=set() for j in range(1,i+1): if i % j==0 : s.add(j) s.add(i//j) res=0 for k in s : if isprime(k): res+=1 if res==2 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; var ans : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( var s : Set := Set{}->union(()) ; for j : Integer.subrange(1, i + 1-1) do ( if i mod j = 0 then ( execute ((j) : s) ; execute ((i div j) : s) ) else skip) ; var res : int := 0 ; for k : s do ( if isprime(k) then ( res := res + 1 ) else skip) ; if res = 2 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); operation isprime(x : OclAny) : OclAny pre: true post: true activity: if x <= 2 then ( return x = 2 ) else skip ; for i : Integer.subrange(2, x-1) do ( if x mod i = 0 then ( return 0 ) else skip) ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) f=input() list(f) out=0 for i in range(n,len(f),n): if(f[i-1]==f[i-2]and f[i-2]==f[i-3]): out=out+1 print(out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var f : String := (OclFile["System.in"]).readLine() ; OclType["Sequence"](f) ; var out : int := 0 ; for i : Integer.subrange(n, (f)->size()-1)->select( $x | ($x - n) mod n = 0 ) do ( if (f[i - 1+1] = f[i - 2+1] & f[i - 2+1] = f[i - 3+1]) then ( out := out + 1 ) else skip) ; execute (out)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() k=len(s) i=0 c=0 while(i=0): if(s[i-1]==s[i-2]): if(s[i-2]==s[i-3]): c+=1 i+=n print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var k : int := (s)->size() ; var i : int := 0 ; var c : int := 0 ; while ((i->compareTo(k)) < 0) do ( if (i - 3 >= 0) then ( if (s[i - 1+1] = s[i - 2+1]) then ( if (s[i - 2+1] = s[i - 3+1]) then ( c := c + 1 ) else skip ) else skip ) else skip ; i := i + n) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(0,t): n=int(input()) start_point=0 numb_moves=0 if n==1 : print(2) elif n % 3==0 : print(int(n/3)) continue elif n==2 or n==3 : print(1) else : x=n % 3 print(int((n-x)/3+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var start_point : int := 0 ; var numb_moves : int := 0 ; if n = 1 then ( execute (2)->display() ) else (if n mod 3 = 0 then ( execute (("" + ((n / 3)))->toInteger())->display() ; continue ) else (if n = 2 or n = 3 then ( execute (1)->display() ) else ( var x : int := n mod 3 ; execute (("" + (((n - x) / 3 + 1)))->toInteger())->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) g=input() r=0 for i in range(n,len(g),n): if g[i-1]==g[i-2]==g[i-3]: r+=1 print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var g : String := (OclFile["System.in"]).readLine() ; var r : int := 0 ; for i : Integer.subrange(n, (g)->size()-1)->select( $x | ($x - n) mod n = 0 ) do ( if g[i - 1+1] = g[i - 2+1] & (g[i - 2+1] == g[i - 3+1]) then ( r := r + 1 ) else skip) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input().strip()) ans=0 s=input().strip() for i in range(n,len(s),n): if s[i-1]==s[i-2]==s[i-3]: ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + ((input()->trim())))->toInteger() ; var ans : int := 0 ; var s : OclAny := input()->trim() ; for i : Integer.subrange(n, (s)->size()-1)->select( $x | ($x - n) mod n = 0 ) do ( if s[i - 1+1] = s[i - 2+1] & (s[i - 2+1] == s[i - 3+1]) then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sortString(str): str=''.join(sorted(str)) print(str) s="geeksforgeeks" sortString(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : String := "geeksforgeeks" ; sortString(s); operation sortString(OclType["String"] : OclAny) pre: true post: true activity: OclType["String"] := StringLib.sumStringsWithSeparator((OclType["String"]->sort()), '') ; execute (OclType["String"])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) l=[] for i in range(n): l.append(i+1) print(n) c=0 i=0 while itoInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((i + 1) : l)) ; execute (n)->display() ; var c : int := 0 ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( if i /= 0 then ( var l[c+1] : OclAny := null; var l[c + 1+1] : OclAny := null; Sequence{l[c+1],l[c + 1+1]} := Sequence{l[c + 1+1],l[c+1]} ; c := c + 1 ) else skip ; for each : l do ( execute (each)->display()) ; i := i + 1 ; execute (->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) p=[i+1 for i in range(n)] print(n) for i in range(n): print(*p) if itoInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i + 1)) ; execute (n)->display() ; for i : Integer.subrange(0, n-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name p))))))))->display() ; if (i->compareTo(n - 1)) < 0 then ( var p[i+1] : OclAny := null; var p[i + 1+1] : OclAny := null; Sequence{p[i+1],p[i + 1+1]} := Sequence{p[i + 1+1],p[i+1]} ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) p=[i+1 for i in range(n)] print(n) for i in range(n): print(*p) if itoInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i + 1)) ; execute (n)->display() ; for i : Integer.subrange(0, n-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name p))))))))->display() ; if (i->compareTo(n - 1)) < 0 then ( var p[i+1] : OclAny := null; var p[i + 1+1] : OclAny := null; Sequence{p[i+1],p[i + 1+1]} := Sequence{p[i + 1+1],p[i+1]} ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) p=[i+1 for i in range(n)] print(n) for i in range(n): print(*p) if itoInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i + 1)) ; execute (n)->display() ; for i : Integer.subrange(0, n-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name p))))))))->display() ; if (i->compareTo(n - 1)) < 0 then ( var p[i+1] : OclAny := null; var p[i + 1+1] : OclAny := null; Sequence{p[i+1],p[i + 1+1]} := Sequence{p[i + 1+1],p[i+1]} ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) print(n) a=[i for i in range(1,n+1)] i,j=n-2,n-1 for _ in range(n-1): print(*a) a[i],a[j]=a[j],a[i] i-=1 j-=1 print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n)->display() ; var a : Sequence := Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | (i)) ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{n - 2,n - 1} ; for _anon : Integer.subrange(0, n - 1-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display() ; var a[i+1] : OclAny := null; var a[j+1] : OclAny := null; Sequence{a[i+1],a[j+1]} := Sequence{a[j+1],a[i+1]} ; i := i - 1 ; j := j - 1) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : x1,x2,x3=1,3,6 y1,y2,y3=2,-4,-7 x=round((x1+x2+x3)/3,2) y=round((y1+y2+y3)/3,2) print("Centroid=","(",x,",",y,")") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var x1 : OclAny := null; var x2 : OclAny := null; var x3 : OclAny := null; Sequence{x1,x2,x3} := Sequence{1,3,6} ; var y1 : OclAny := null; var y2 : OclAny := null; var y3 : OclAny := null; Sequence{y1,y2,y3} := Sequence{2,-4,-7} ; var x : double := MathLib.roundN((x1 + x2 + x3) / 3, 2) ; var y : double := MathLib.roundN((y1 + y2 + y3) / 3, 2) ; execute ("Centroid=")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import product h,w,m=map(int,input().split()) row=[set()for _ in range(h)] col=[set()for _ in range(w)] for _ in range(m): x,y=map(lambda x : int(x)-1,input().split()) row[x].add(y) col[y].add(x) crow=0 ic=[] for i,x in enumerate(row): if crowcollect( _x | (OclType["int"])->apply(_x) ) ; var row : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; var col : Sequence := Integer.subrange(0, w-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; for _anon : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ) ; (expr (atom (name row)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))) ; (expr (atom (name col)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))) ; var crow : int := 0 ; var ic : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (row)->size())->collect( _indx | Sequence{_indx-1, (row)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); if (crow->compareTo((x)->size())) < 0 then ( crow := (x)->size() ; ic := Sequence{ i } ) else (if crow = (x)->size() then ( execute ((i) : ic) ) else skip)) ; var ccol : int := 0 ; var jc : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (col)->size())->collect( _indx | Sequence{_indx-1, (col)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); if (ccol->compareTo((x)->size())) < 0 then ( ccol := (x)->size() ; jc := Sequence{ j } ) else (if ccol = (x)->size() then ( execute ((j) : jc) ) else skip)) ; var ans : int := crow + ccol ; (compound_stmt for (exprlist (expr (atom (name i))) , (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name product)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ic))))))) , (argument (test (logical_test (comparison (expr (atom (name jc)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name j)))) not in (comparison (expr (atom (name row)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name ans))) - (expr (atom (number (integer 1)))))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def moves(): arr=[int(i)for i in input().split(" ")] n=arr[0] a=abs(n) if a % 3==0 : return(a//3) elif a==2 : return(1) elif a==0 : return(0) elif a==1 : return(2) elif a % 3==1 : return(2+((a-4)//3)) elif a % 3==2 : return(1+((a-2)//3)) test=int(input()) for i in range(0,test): print(moves()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var test : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, test-1) do ( execute (moves())->display()); operation moves() : OclAny pre: true post: true activity: var arr : Sequence := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var n : OclAny := arr->first() ; var a : double := (n)->abs() ; if a mod 3 = 0 then ( return (a div 3) ) else (if a = 2 then ( return (1) ) else (if a = 0 then ( return (0) ) else (if a = 1 then ( return (2) ) else (if a mod 3 = 1 then ( return (2 + ((a - 4) div 3)) ) else (if a mod 3 = 2 then ( return (1 + ((a - 2) div 3)) ) else skip ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import exit,stdin from collections import deque,Counter input=stdin.readline H,W,M=map(int,input().split()) col=Counter() row=Counter() D=Counter() for i in range(M): h,w=map(int,input().split()) row.update([h]) col.update([w]) D.update([str(h)+str(w)]) rtmp=row.most_common(1)[0][1] ctmp=col.most_common(1)[0][1] rmax=[] cmax=[] for r in row.most_common(): if r[1]collect( _x | (OclType["int"])->apply(_x) ) ; var col : OclAny := Counter() ; var row : OclAny := Counter() ; var D : OclAny := Counter() ; for i : Integer.subrange(0, M-1) do ( var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{ h }) <: row) ; execute ((Sequence{ w }) <: col) ; execute ((Sequence{ ("" + ((h))) + ("" + ((w))) }) <: D)) ; var rtmp : OclAny := row.most_common(1)->first()[1+1] ; var ctmp : OclAny := col.most_common(1)->first()[1+1] ; var rmax : Sequence := Sequence{} ; var cmax : Sequence := Sequence{} ; for r : row.most_common() do ( if (r[1+1]->compareTo(rtmp)) < 0 then ( break ) else skip ; execute ((r) : rmax)) ; for c : col.most_common() do ( if (c[1+1]->compareTo(ctmp)) < 0 then ( break ) else skip ; execute ((c) : cmax)) ; var ridx : String := ("" + ((rmax->first()->first()))) ; (compound_stmt for (exprlist (expr (atom (name d)))) in (testlist (test (logical_test (comparison (expr (atom (name cmax))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name D)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name ridx))) + (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))))))))) ])))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name rmax)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) + (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (name rmax)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) + (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) - (expr (atom (number (integer 1))))))))))))))))) ; var cidx : String := ("" + ((cmax->first()->first()))) ; (compound_stmt for (exprlist (expr (atom (name d)))) in (testlist (test (logical_test (comparison (expr (atom (name rmax))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name D)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))) + (expr (atom (name cidx))))))))) ])))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans2)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name cmax)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) + (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans2)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (name cmax)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) + (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) - (expr (atom (number (integer 1))))))))))))))))) ; execute (Set{ans, ans2}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict h,w,m=map(int,input().split()) targets=defaultdict(int) targets_count_yoko=defaultdict(int) targets_count_tate=defaultdict(int) for _ in range(m): y,x=map(int,input().split()) y-=1 x-=1 targets_count_yoko[x]+=1 targets_count_tate[y]+=1 targets[(y,x)]=-1 max_row=max(targets_count_yoko.values()) max_line=max(targets_count_tate.values()) y_idx=defaultdict(bool) x_idx=defaultdict(bool) max_count_x=0 max_count_y=0 for i in range(w): if targets_count_yoko[i]==max_row : x_idx[i]=True max_count_x+=1 for i in range(h): if targets_count_tate[i]==max_line : y_idx[i]=True max_count_y+=1 ans=max_line+max_row kumi=max_count_x*max_count_y for key_y,key_x in targets.keys(): if y_idx[key_y]and x_idx[key_x]: kumi-=1 if kumi==0 : break if kumi==0 : print(ans-1) else : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var h : OclAny := null; var w : OclAny := null; var m : OclAny := null; Sequence{h,w,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var targets : OclAny := defaultdict(OclType["int"]) ; var targets_count_yoko : OclAny := defaultdict(OclType["int"]) ; var targets_count_tate : OclAny := defaultdict(OclType["int"]) ; for _anon : Integer.subrange(0, m-1) do ( var y : OclAny := null; var x : OclAny := null; Sequence{y,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; y := y - 1 ; x := x - 1 ; targets_count_yoko[x+1] := targets_count_yoko[x+1] + 1 ; targets_count_tate[y+1] := targets_count_tate[y+1] + 1 ; targets[Sequence{y, x}+1] := -1) ; var max_row : OclAny := (targets_count_yoko.values())->max() ; var max_line : OclAny := (targets_count_tate.values())->max() ; var y_idx : OclAny := defaultdict(OclType["boolean"]) ; var x_idx : OclAny := defaultdict(OclType["boolean"]) ; var max_count_x : int := 0 ; var max_count_y : int := 0 ; for i : Integer.subrange(0, w-1) do ( if targets_count_yoko[i+1] = max_row then ( x_idx[i+1] := true ; max_count_x := max_count_x + 1 ) else skip) ; for i : Integer.subrange(0, h-1) do ( if targets_count_tate[i+1] = max_line then ( y_idx[i+1] := true ; max_count_y := max_count_y + 1 ) else skip) ; var ans : OclAny := max_line + max_row ; var kumi : int := max_count_x * max_count_y ; for _tuple : targets.keys() do (var _indx : int := 1; var key_y : OclAny := _tuple->at(_indx); _indx := _indx + 1; var key_x : OclAny := _tuple->at(_indx); if y_idx[key_y+1] & x_idx[key_x+1] then ( kumi := kumi - 1 ) else skip ; if kumi = 0 then ( break ) else skip) ; if kumi = 0 then ( execute (ans - 1)->display() ) else ( execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import defaultdict H,W,M=map(int,input().split()) X=[list(map(int,input().split()))for _ in range(M)] ctr_h=defaultdict(int) ctr_w=defaultdict(int) appeared=set() for h,w in X : ctr_h[h]+=1 ctr_w[w]+=1 appeared.add(h*W+w) val_h=sorted(ctr_h.items(),key=lambda x :-x[1]) val_w=sorted(ctr_w.items(),key=lambda x :-x[1]) max_h=val_h[0][1] max_w=val_w[0][1] val_h=[i for i,v in val_h if v==max_h] val_w=[i for i,v in val_w if v==max_w] if len(val_h)*len(val_w)>M : print(max_h+max_w) sys.exit(0) for h in val_h : for w in val_w : if h*W+w not in appeared : print(max_h+max_w) sys.exit(0) else : print(max_h+max_w-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var H : OclAny := null; var W : OclAny := null; var M : OclAny := null; Sequence{H,W,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var X : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ctr_h : OclAny := defaultdict(OclType["int"]) ; var ctr_w : OclAny := defaultdict(OclType["int"]) ; var appeared : Set := Set{}->union(()) ; for _tuple : X do (var _indx : int := 1; var h : OclAny := _tuple->at(_indx); _indx := _indx + 1; var w : OclAny := _tuple->at(_indx); ctr_h[h+1] := ctr_h[h+1] + 1 ; ctr_w[w+1] := ctr_w[w+1] + 1 ; execute ((h * W + w) : appeared)) ; var val_h : Sequence := ctr_h->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sortedBy($x | (lambda x : OclAny in (-x[1+1]))->apply($x)) ; var val_w : Sequence := ctr_w->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sortedBy($x | (lambda x : OclAny in (-x[1+1]))->apply($x)) ; var max_h : OclAny := val_h->first()[1+1] ; var max_w : OclAny := val_w->first()[1+1] ; val_h := val_h->select(_tuple | let i : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in v = max_h)->collect(_tuple | let i : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in (i)) ; val_w := val_w->select(_tuple | let i : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in v = max_w)->collect(_tuple | let i : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in (i)) ; if ((val_h)->size() * (val_w)->size()->compareTo(M)) > 0 then ( execute (max_h + max_w)->display() ; sys.exit(0) ) else skip ; (compound_stmt for (exprlist (expr (atom (name h)))) in (testlist (test (logical_test (comparison (expr (atom (name val_h))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name w)))) in (testlist (test (logical_test (comparison (expr (atom (name val_w))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (expr (atom (name h))) * (expr (atom (name W)))) + (expr (atom (name w))))) not in (comparison (expr (atom (name appeared))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name max_h))) + (expr (atom (name max_w))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name exit) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name max_h))) + (expr (atom (name max_w)))) - (expr (atom (number (integer 1)))))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans=0 h,w,m=map(int,input().split()) d=list() from collections import defaultdict r=defaultdict(int) c=defaultdict(int) r=[0]*(h+1) c=[0]*(w+1) for i in range(m): a,b=map(int,input().split()) d+=(a,b), r[a]+=1 c[b]+=1 R=max(r) C=max(c) x=0 nr=r.count(R) nc=c.count(C) for i in range(m): a,b=d[i] if r[a]==R and c[b]==C : x+=1 ans=R+C if x==nr*nc : ans-=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ans : int := 0 ; var h : OclAny := null; var w : OclAny := null; var m : OclAny := null; Sequence{h,w,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := () ; skip ; var r : OclAny := defaultdict(OclType["int"]) ; var c : OclAny := defaultdict(OclType["int"]) ; r := MatrixLib.elementwiseMult(Sequence{ 0 }, (h + 1)) ; c := MatrixLib.elementwiseMult(Sequence{ 0 }, (w + 1)) ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; d := d + (testlist (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name b))))))) )))))) ,) ; r[a+1] := r[a+1] + 1 ; c[b+1] := c[b+1] + 1) ; var R : OclAny := (r)->max() ; var C : OclAny := (c)->max() ; var x : int := 0 ; var nr : String := r->count(R) ; var nc : int := c->count(C) ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := d[i+1] ; if r[a+1] = R & c[b+1] = C then ( x := x + 1 ) else skip) ; ans := R + C ; if x = StringLib.nCopies(nr, nc) then ( ans := ans - 1 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printNumber(n): count=[0]*10 while(n): count[n % 10]+=1 n//=10 for i in range(1,10): for j in range(count[i]*i): print(i,end="") if __name__=="__main__" : n=3225 printNumber(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 3225 ; printNumber(n) ) else skip; operation printNumber(n : OclAny) pre: true post: true activity: var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; while (n) do ( count[n mod 10+1] := count[n mod 10+1] + 1 ; n := n div 10) ; for i : Integer.subrange(1, 10-1) do ( for j : Integer.subrange(0, count[i+1] * i-1) do ( execute (i)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxPrimefactorNum(N): arr=[0]*(N+1); i=2 ; while(i*i<=N): if(arr[i]>0): for j in range(2*i,N+1,i): arr[j]+=1 ; i+=1 ; arr[i]=1 ; return max(arr); N=40 ; print(maxPrimefactorNum(N)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 40; ; execute (maxPrimefactorNum(N))->display();; operation maxPrimefactorNum(N : OclAny) pre: true post: true activity: var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)); ; var i : int := 2; ; while ((i * i->compareTo(N)) <= 0) do ( if (arr[i+1] > 0) then ( for j : Integer.subrange(2 * i, N + 1-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ( arr[j+1] := arr[j+1] + 1;) ) else skip ; i := i + 1; ; arr[i+1] := 1;) ; return (arr)->max();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) cnt=1 for i in range(1,n): if a[i]<=a[i-1]: cnt+=1 print(cnt) print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : int := 1 ; for i : Integer.subrange(1, n-1) do ( if (a[i+1]->compareTo(a[i - 1+1])) <= 0 then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display() ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import* from bisect import* from math import* from collections import* from heapq import* from random import* import sys sys.setrecursionlimit(10**6) int1=lambda x : int(x)-1 p2D=lambda x : print(*x,sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int,sys.stdin.readline().split()) def MI1(): return map(int1,sys.stdin.readline().split()) def MF(): return map(float,sys.stdin.readline().split()) def LI(): return list(map(int,sys.stdin.readline().split())) def LI1(): return list(map(int1,sys.stdin.readline().split())) def LF(): return list(map(float,sys.stdin.readline().split())) def LLI(rows_number): return[LI()for _ in range(rows_number)] dij=[(1,0),(0,1),(-1,0),(0,-1)] def main(): n=II() aa=LI() mn=1 for a0,a1 in zip(aa,aa[1 :]): if a0>=a1 : mn+=1 print(mn) print(n) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(6)) ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; var p2D : Function := lambda x : OclAny in (((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var dij : Sequence := Sequence{Sequence{1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{-1, 0}}->union(Sequence{ Sequence{0, -1} }))) ; skip ; main(); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation MI1() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (int1)->apply(_x) ); operation MF() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LI1() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (int1)->apply(_x) )); operation LF() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) )); operation LLI(rows_number : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows_number-1)->select(_anon | true)->collect(_anon | (LI())); operation main() pre: true post: true activity: var n : OclAny := II() ; var aa : OclAny := LI() ; var mn : int := 1 ; for _tuple : Integer.subrange(1, aa->size())->collect( _indx | Sequence{aa->at(_indx), aa->tail()->at(_indx)} ) do (var _indx : int := 1; var a0 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a1 : OclAny := _tuple->at(_indx); if (a0->compareTo(a1)) >= 0 then ( mn := mn + 1 ) else skip) ; execute (mn)->display() ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def num(): return int(input()) def nums(): return list(map(int,input().split())) N=num() A=nums() ans_max=N ans_min=0 old_i=0 for i in A : if not i>old_i : ans_min+=1 old_i=i ans_min+=1 print(ans_min) print(ans_max) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := num() ; var A : OclAny := nums() ; var ans_max : OclAny := N ; var ans_min : int := 0 ; var old_i : int := 0 ; for i : A do ( if not((i->compareTo(old_i)) > 0) then ( ans_min := ans_min + 1 ) else skip ; old_i := i) ; ans_min := ans_min + 1 ; execute (ans_min)->display() ; execute (ans_max)->display(); operation num() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation nums() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def areElementsContiguous(arr,n): max1=max(arr) min1=min(arr) m=max1-min1+1 if(m>n): return False visited=[0]*m for i in range(0,n): visited[arr[i]-min1]=True for i in range(0,m): if(visited[i]==False): return False return True arr=[5,2,3,6,4,4,6,6] n=len(arr) if(areElementsContiguous(arr,n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{5}->union(Sequence{2}->union(Sequence{3}->union(Sequence{6}->union(Sequence{4}->union(Sequence{4}->union(Sequence{6}->union(Sequence{ 6 }))))))) ; n := (arr)->size() ; if (areElementsContiguous(arr, n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation areElementsContiguous(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var max1 : OclAny := (arr)->max() ; var min1 : OclAny := (arr)->min() ; var m : double := max1 - min1 + 1 ; if ((m->compareTo(n)) > 0) then ( return false ) else skip ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; for i : Integer.subrange(0, n-1) do ( visited[arr[i+1] - min1+1] := true) ; for i : Integer.subrange(0, m-1) do ( if (visited[i+1] = false) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=[] limit=10000000000 def gen(number,four,seven): if(number>limit): return if(number>0 and four==seven): l.append(number) gen(number*10+4,four+1,seven) gen(number*10+7,four,seven+1) def main(): gen(0,0,0) l.sort() n=int(input()) ans=0 for val in l : if(val>=n): ans=val break print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := Sequence{} ; var limit : int := 10000000000 ; skip ; skip ; main(); operation gen(number : OclAny, four : OclAny, seven : OclAny) pre: true post: true activity: if ((number->compareTo(limit)) > 0) then ( return ) else skip ; if (number > 0 & four = seven) then ( execute ((number) : l) ) else skip ; gen(number * 10 + 4, four + 1, seven) ; gen(number * 10 + 7, four, seven + 1); operation main() pre: true post: true activity: gen(0, 0, 0) ; l := l->sort() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; for val : l do ( if ((val->compareTo(n)) >= 0) then ( ans := val ; break ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=[int(x)for x in input().split()] min=1 max=N for i in range(1,N): if A[i]<=A[i-1]: min+=1 print(min) print(max) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var min : int := 1 ; var max : int := N ; for i : Integer.subrange(1, N-1) do ( if (A[i+1]->compareTo(A[i - 1+1])) <= 0 then ( min := min + 1 ) else skip) ; execute (min)->display() ; execute (max)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) ans=1 for i in range(n-1): if a[i]>=a[i+1]: ans+=1 print(ans) print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 1 ; for i : Integer.subrange(0, n - 1-1) do ( if (a[i+1]->compareTo(a[i + 1+1])) >= 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display() ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count_(count,e): hash=[False]*10 while(e>0): if(hash[e % 10]==False): count[e % 10]+=1 hash[e % 10]=True e//=10 def find_subsequence(arr,n): count=[0]*10 for i in range(n): count_(count,arr[i]) longest=0 for i in range(10): longest=max(count[i],longest) print(longest) if __name__=="__main__" : arr=[11,12,23,74,13] n=len(arr) find_subsequence(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{11}->union(Sequence{12}->union(Sequence{23}->union(Sequence{74}->union(Sequence{ 13 })))) ; n := (arr)->size() ; find_subsequence(arr, n) ) else skip; operation count_(count : OclAny, e : OclAny) pre: true post: true activity: var hash : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, 10) ; while (e > 0) do ( if (hash[e mod 10+1] = false) then ( count[e mod 10+1] := count[e mod 10+1] + 1 ) else skip ; hash[e mod 10+1] := true ; e := e div 10); operation find_subsequence(arr : OclAny, n : OclAny) pre: true post: true activity: count := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; for i : Integer.subrange(0, n-1) do ( count_(count, arr[i+1])) ; var longest : int := 0 ; for i : Integer.subrange(0, 10-1) do ( longest := Set{count[i+1], longest}->max()) ; execute (longest)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt MAXN=1000001 spf=[0 for i in range(MAXN)] def sieve(): for i in range(1,MAXN,1): spf[i]=i for i in range(4,MAXN,2): spf[i]=2 k=int(sqrt(MAXN)) for i in range(3,k,1): if(spf[i]==i): for j in range(i*i,MAXN,i): if(spf[j]==j): spf[j]=i def countSubArray(arr,n): ind=[-1 for i in range(MAXN)] count=0 last_ind=0 for i in range(0,n,1): while(arr[i]>1): div=spf[arr[i]] last_ind=max(last_ind,ind[div]) ind[div]=i+1 arr[i]=int(arr[i]/div) count+=i-last_ind+1 return count if __name__=='__main__' : sieve() arr=[2,3,9] n=len(arr) print(countSubArray(arr,n)) arr1=[2,3,5,15,7,2] n1=len(arr1) print(countSubArray(arr1,n1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MAXN : int := 1000001 ; var spf : Sequence := Integer.subrange(0, MAXN-1)->select(i | true)->collect(i | (0)) ; skip ; skip ; if __name__ = '__main__' then ( sieve() ; arr := Sequence{2}->union(Sequence{3}->union(Sequence{ 9 })) ; n := (arr)->size() ; execute (countSubArray(arr, n))->display() ; var arr1 : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{15}->union(Sequence{7}->union(Sequence{ 2 }))))) ; var n1 : int := (arr1)->size() ; execute (countSubArray(arr1, n1))->display() ) else skip; operation sieve() pre: true post: true activity: for i : Integer.subrange(1, MAXN-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( spf[i+1] := i) ; for i : Integer.subrange(4, MAXN-1)->select( $x | ($x - 4) mod 2 = 0 ) do ( spf[i+1] := 2) ; var k : int := ("" + ((sqrt(MAXN))))->toInteger() ; for i : Integer.subrange(3, k-1)->select( $x | ($x - 3) mod 1 = 0 ) do ( if (spf[i+1] = i) then ( for j : Integer.subrange(i * i, MAXN-1)->select( $x | ($x - i * i) mod i = 0 ) do ( if (spf[j+1] = j) then ( spf[j+1] := i ) else skip) ) else skip); operation countSubArray(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ind : Sequence := Integer.subrange(0, MAXN-1)->select(i | true)->collect(i | (-1)) ; var count : int := 0 ; var last_ind : int := 0 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( while (arr[i+1] > 1) do ( var div : OclAny := spf[arr[i+1]+1] ; last_ind := Set{last_ind, ind[div+1]}->max() ; ind[div+1] := i + 1 ; arr[i+1] := ("" + ((arr[i+1] / div)))->toInteger()) ; count := count + i - last_ind + 1) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=3 ; def multiply(mat,res): for i in range(N): for j in range(N): res[i][j]=0 ; for k in range(N): res[i][j]+=mat[i][k]*mat[k][j]; return res ; def InvolutoryMatrix(mat): res=[[0 for i in range(N)]for j in range(N)]; res=multiply(mat,res); for i in range(N): for j in range(N): if(i==j and res[i][j]!=1): return False ; if(i!=j and res[i][j]!=0): return False ; return True ; mat=[[1,0,0],[0,-1,0],[0,0,-1]]; if(InvolutoryMatrix(mat)): print("Involutory Matrix"); else : print("Not Involutory Matrix"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 3; ; skip ; skip ; mat := Sequence{Sequence{1}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{Sequence{0}->union(Sequence{-1}->union(Sequence{ 0 }))}->union(Sequence{ Sequence{0}->union(Sequence{0}->union(Sequence{ -1 })) })); ; if (InvolutoryMatrix(mat)) then ( execute ("Involutory Matrix")->display(); ) else ( execute ("Not Involutory Matrix")->display(); ); operation multiply(mat : OclAny, res : OclAny) pre: true post: true activity: for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( res[i+1][j+1] := 0; ; for k : Integer.subrange(0, N-1) do ( res[i+1][j+1] := res[i+1][j+1] + mat[i+1][k+1] * mat[k+1][j+1];))) ; return res;; operation InvolutoryMatrix(mat : OclAny) pre: true post: true activity: res := Integer.subrange(0, N-1)->select(j | true)->collect(j | (Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)))); ; res := multiply(mat, res); ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( if (i = j & res[i+1][j+1] /= 1) then ( return false; ) else skip ; if (i /= j & res[i+1][j+1] /= 0) then ( return false; ) else skip)) ; return true;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys rd=sys.stdin.readline n=int(rd()) a=list(map(int,rd().split())) res=0 for i in range(1,n-1): if a[i-1]==1 and a[i]==0 and a[i+1]==1 : res+=1 a[i+1]=0 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var rd : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + ((rd())))->toInteger() ; var a : Sequence := ((rd().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : int := 0 ; for i : Integer.subrange(1, n - 1-1) do ( if a[i - 1+1] = 1 & a[i+1] = 0 & a[i + 1+1] = 1 then ( res := res + 1 ; a[i + 1+1] := 0 ) else skip) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def first(n): a=n c=1 while(a!=0): a//=10 c=c*10 c=c//10 fi=n//c return fi def prime(n): if n in[2,3,5,7]: return True else : return False def check(n,k): l=n % 10 f=first(n) lp=prime(l) fp=prime(f) if(lp and fp): if(l+funion(Sequence{3}->union(Sequence{5}->union(Sequence{ 7 }))))->includes(n) then ( return true ) else ( return false ); operation check(n : OclAny, k : OclAny) pre: true post: true activity: var l : int := n mod 10 ; var f : OclAny := first(n) ; var lp : OclAny := prime(l) ; var fp : OclAny := prime(f) ; if (lp & fp) then ( if ((l + f->compareTo(k)) < 0) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def lengthSquare(X,Y): xDiff=X[0]-Y[0] yDiff=X[1]-Y[1] return xDiff*xDiff+yDiff*yDiff def printAngle(A,B,C): a2=lengthSquare(B,C) b2=lengthSquare(A,C) c2=lengthSquare(A,B) a=math.sqrt(a2); b=math.sqrt(b2); c=math.sqrt(c2); alpha=math.acos((b2+c2-a2)/(2*b*c)); betta=math.acos((a2+c2-b2)/(2*a*c)); gamma=math.acos((a2+b2-c2)/(2*a*b)); alpha=alpha*180/math.pi ; betta=betta*180/math.pi ; gamma=gamma*180/math.pi ; print("alpha : %f" %(alpha)) print("betta : %f" %(betta)) print("gamma : %f" %(gamma)) A=(0,0) B=(0,1) C=(1,0) printAngle(A,B,C); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; A := Sequence{0, 0} ; B := Sequence{0, 1} ; C := Sequence{1, 0} ; printAngle(A, B, C);; operation lengthSquare(X : OclAny, Y : OclAny) : OclAny pre: true post: true activity: var xDiff : double := X->first() - Y->first() ; var yDiff : double := X[1+1] - Y[1+1] ; return xDiff * xDiff + yDiff * yDiff; operation printAngle(A : OclAny, B : OclAny, C : OclAny) pre: true post: true activity: var a2 : OclAny := lengthSquare(B, C) ; var b2 : OclAny := lengthSquare(A, C) ; var c2 : OclAny := lengthSquare(A, B) ; var a : double := (a2)->sqrt(); ; var b : double := (b2)->sqrt(); ; var c : double := (c2)->sqrt(); ; var alpha : double := ((b2 + c2 - a2) / (2 * b * c))->acos(); ; var betta : double := ((a2 + c2 - b2) / (2 * a * c))->acos(); ; var gamma : double := ((a2 + b2 - c2) / (2 * a * b))->acos(); ; alpha := alpha * 180 / ; ; betta := betta * 180 / ; ; gamma := gamma * 180 / ; ; execute (StringLib.format("alpha : %f",(alpha)))->display() ; execute (StringLib.format("betta : %f",(betta)))->display() ; execute (StringLib.format("gamma : %f",(gamma)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) ans=[] while(t): n=int(input()) array_input=input().split() if len(array_input)==1 : ans.append(0) else : array=[int(x)for x in array_input] max_value=max(array) e=0 x=array[-1] while True : for i in array[: :-1]: if i>x : e+=1 x=i if i==max_value : break if i==max_value : ans.append(e) break if e==0 : ans.append(0) t-=1 print(*ans,sep="\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; while (t) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var array_input : OclAny := input().split() ; if (array_input)->size() = 1 then ( execute ((0) : ans) ) else ( var array : Sequence := array_input->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var max_value : OclAny := (array)->max() ; var e : int := 0 ; var x : OclAny := array->last() ; while true do ( for i : array(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if (i->compareTo(x)) > 0 then ( e := e + 1 ; x := i ) else skip ; if i = max_value then ( break ) else skip) ; if i = max_value then ( execute ((e) : ans) ; break ) else skip ; if e = 0 then ( execute ((0) : ans) ) else skip) ) ; t := t - 1) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while(t): n=int(input()) a=list(map(int,input().split())) maxE=0 ; maxV=a[len(a)-1] for c in range(len(a)-1,-1,-1): if(a[c]>maxV): maxE+=1 maxV=a[c] print(maxE) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (t) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var maxE : int := 0; var maxV : OclAny := a[(a)->size() - 1+1] ; for c : Integer.subrange(-1 + 1, (a)->size() - 1)->reverse() do ( if ((a[c+1]->compareTo(maxV)) > 0) then ( maxE := maxE + 1 ; maxV := a[c+1] ) else skip) ; execute (maxE)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def moves(): arr=[int(i)for i in input().split(" ")] n=arr[0] a=abs(n) if a % 3==0 : return(a//3) elif a==2 : return(1) elif a==0 : return(0) elif a==1 : return(2) elif a % 3==1 : return(2+((a-4)//3)) elif a % 3==2 : return(1+((a-2)//3)) test=int(input()) for i in range(0,test): print(moves()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var test : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, test-1) do ( execute (moves())->display()); operation moves() : OclAny pre: true post: true activity: var arr : Sequence := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var n : OclAny := arr->first() ; var a : double := (n)->abs() ; if a mod 3 = 0 then ( return (a div 3) ) else (if a = 2 then ( return (1) ) else (if a = 0 then ( return (0) ) else (if a = 1 then ( return (2) ) else (if a mod 3 = 1 then ( return (2 + ((a - 4) div 3)) ) else (if a mod 3 = 2 then ( return (1 + ((a - 2) div 3)) ) else skip ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for x in range(t): n=int(input()) a=list(map(int,input().split())) maxE=0 ; maxV=a[len(a)-1] for c in range(len(a)-1,-1,-1): if(a[c]>maxV): maxE+=1 maxV=a[c] print(maxE) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for x : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var maxE : int := 0; var maxV : OclAny := a[(a)->size() - 1+1] ; for c : Integer.subrange(-1 + 1, (a)->size() - 1)->reverse() do ( if ((a[c+1]->compareTo(maxV)) > 0) then ( maxE := maxE + 1 ; maxV := a[c+1] ) else skip) ; execute (maxE)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout T=int(stdin.readline()) for i in range(T): N=int(stdin.readline()) A=list(map(int,stdin.readline().strip().split())) MAX=max(A) NEW=[] for j in range(len(A)-1,-1,-1): if j==len(A)-1 : NEW.append(A[j]) elif A[j]>NEW[-1]: NEW.append(A[j]) if A[j]==MAX : break stdout.write(f"{len(NEW)-1}\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var T : int := ("" + ((stdin.readLine())))->toInteger() ; for i : Integer.subrange(0, T-1) do ( var N : int := ("" + ((stdin.readLine())))->toInteger() ; var A : Sequence := ((stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var MAX : OclAny := (A)->max() ; var NEW : Sequence := Sequence{} ; for j : Integer.subrange(-1 + 1, (A)->size() - 1)->reverse() do ( if j = (A)->size() - 1 then ( execute ((A[j+1]) : NEW) ) else (if (A[j+1]->compareTo(NEW->last())) > 0 then ( execute ((A[j+1]) : NEW) ) else skip) ; if A[j+1] = MAX then ( break ) else skip) ; stdout.write(StringLib.formattedString("{len(NEW)-1}\n"))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): s=int(input()) a=list(map(int,input().split())) lena=len(a) count=0 z=a[lena-1] for j in range(lena-2,-1,-1): if(ztoInteger() ; for i : Integer.subrange(0, t-1) do ( var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lena : int := (a)->size() ; var count : int := 0 ; var z : OclAny := a[lena - 1+1] ; for j : Integer.subrange(-1 + 1, lena - 2)->reverse() do ( if ((z->compareTo(a[j+1])) < 0) then ( z := a[j+1] ; count := count + 1 ) else skip) ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INT_MIN=-100000000 def maxEvenSum(arr,n): pos_sum=0 for i in range(n): if(arr[i]>0): pos_sum+=arr[i] if(pos_sum % 2==0): return pos_sum ans=INT_MIN ; for i in range(n): if(arr[i]% 2!=0): if(arr[i]>0): ans=max(ans,pos_sum-arr[i]) else : ans=max(ans,pos_sum+arr[i]) return ans a=[-2,2,-3,1] n=len(a) print(maxEvenSum(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INT_MIN : int := -100000000 ; skip ; var a : Sequence := Sequence{-2}->union(Sequence{2}->union(Sequence{-3}->union(Sequence{ 1 }))) ; n := (a)->size() ; execute (maxEvenSum(a, n))->display(); operation maxEvenSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var pos_sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] > 0) then ( pos_sum := pos_sum + arr[i+1] ) else skip) ; if (pos_sum mod 2 = 0) then ( return pos_sum ) else skip ; var ans : int := INT_MIN; ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] mod 2 /= 0) then ( if (arr[i+1] > 0) then ( ans := Set{ans, pos_sum - arr[i+1]}->max() ) else ( ans := Set{ans, pos_sum + arr[i+1]}->max() ) ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def xorOfArray(arr,n): xor_arr=0 for i in range(n): xor_arr=xor_arr ^ arr[i] return xor_arr if __name__=='__main__' : arr=[3,9,12,13,15] n=len(arr) print(xorOfArray(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{3}->union(Sequence{9}->union(Sequence{12}->union(Sequence{13}->union(Sequence{ 15 })))) ; n := (arr)->size() ; execute (xorOfArray(arr, n))->display() ) else skip; operation xorOfArray(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var xor_arr : int := 0 ; for i : Integer.subrange(0, n-1) do ( xor_arr := MathLib.bitwiseXor(xor_arr, arr[i+1])) ; return xor_arr; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- TEN=10 def updateFreq(n,freq): while(n): digit=n % TEN freq[digit]+=1 n//=TEN def areAnagrams(a,b): freqA=[0]*TEN freqB=[0]*TEN updateFreq(a,freqA) updateFreq(b,freqB) for i in range(TEN): if(freqA[i]!=freqB[i]): return False return True a=240 b=204 if(areAnagrams(a,b)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var TEN : int := 10 ; skip ; skip ; a := 240 ; b := 204 ; if (areAnagrams(a, b)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation updateFreq(n : OclAny, freq : OclAny) pre: true post: true activity: while (n) do ( var digit : int := n mod TEN ; freq[digit+1] := freq[digit+1] + 1 ; n := n div TEN); operation areAnagrams(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var freqA : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, TEN) ; var freqB : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, TEN) ; updateFreq(a, freqA) ; updateFreq(b, freqB) ; for i : Integer.subrange(0, TEN-1) do ( if (freqA[i+1] /= freqB[i+1]) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- flats_in_the_house=int(input()) state_of_lights=list(map(int,input().split(' '))) need_to_turn_off=0 i=0 while itoInteger() ; var state_of_lights : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var need_to_turn_off : int := 0 ; var i : int := 0 ; while (i->compareTo(flats_in_the_house - 2)) < 0 do ( if state_of_lights[i+1] = state_of_lights[i + 2+1] & (state_of_lights[i + 2+1] == 1) & state_of_lights[i + 1+1] = 0 then ( need_to_turn_off := need_to_turn_off + 1 ; i := i + 2 ) else skip ; i := i + 1) ; execute (need_to_turn_off)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def evenFib(n): if(n<1): return n if(n==1): return 2 return((4*evenFib(n-1))+evenFib(n-2)) n=7 print(evenFib(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 7 ; execute (evenFib(n))->display(); operation evenFib(n : OclAny) : OclAny pre: true post: true activity: if (n < 1) then ( return n ) else skip ; if (n = 1) then ( return 2 ) else skip ; return ((4 * evenFib(n - 1)) + evenFib(n - 2)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import log2,ceil def minOperations(N): x=log2(N) ans=ceil(x) return ans if __name__=='__main__' : N=10 print(minOperations(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( N := 10 ; execute (minOperations(N))->display() ) else skip; operation minOperations(N : OclAny) : OclAny pre: true post: true activity: var x : OclAny := log2(N) ; var ans : OclAny := ceil(x) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=a=1 for i in range(int(input())): T,A=map(int,input().split()); n=max(-(-t//T),-(-a//A)); t=n*T ; a=n*A print(t+a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := 1; var a : int := 1 ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var T : OclAny := null; var A : OclAny := null; Sequence{T,A} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var n : OclAny := Set{-(-t div T), -(-a div A)}->max(); t := n * T; a := n * A) ; execute (t + a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for liuo in[*map(int,open(0))][1 :]: print((liuo<2)--liuo//3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for liuo : (OclFile.newOclFile_Write(OclFile.newOclFile(0)))->collect( _x | (OclType["int"])->apply(_x) )->tail() do ( execute ((liuo < 2) - -liuo div 3)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nextpt(ratio1,ratio2,pt): if ratio1[0]*ratio2[1]-ratio1[1]*ratio2[0]>0 : pt[0]=pt[0]+((-1)*pt[0])% ratio2[0] pt[1]=pt[0]*ratio2[1]//ratio2[0] else : pt[1]=pt[1]+((-1)*pt[1])% ratio2[1] pt[0]=pt[1]*ratio2[0]//ratio2[1] return pt n=int(input()) ratios=[list(map(int,input().split()))for _ in range(n)] pt=ratios[0] for i in range(n-1): pt=nextpt(ratios[i],ratios[i+1],pt) print(sum(pt)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ratios : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; pt := ratios->first() ; for i : Integer.subrange(0, n - 1-1) do ( pt := nextpt(ratios[i+1], ratios[i + 1+1], pt)) ; execute ((pt)->sum())->display(); operation nextpt(ratio1 : OclAny, ratio2 : OclAny, pt : OclAny) : OclAny pre: true post: true activity: if ratio1->first() * ratio2[1+1] - ratio1[1+1] * ratio2->first() > 0 then ( pt->first() := pt->first() + ((-1) * pt->first()) mod ratio2->first() ; pt[1+1] := pt->first() * ratio2[1+1] div ratio2->first() ) else ( pt[1+1] := pt[1+1] + ((-1) * pt[1+1]) mod ratio2[1+1] ; pt->first() := pt[1+1] * ratio2->first() div ratio2[1+1] ) ; return pt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) TA=[list(map(int,input().split()))for i in range(N)] for i in range(1,N): Tprev,Aprev=TA[i-1] Ti,Ai=TA[i] if Ti>=Tprev and Ai>=Aprev : continue if(Tprev/Ti)>(Aprev/Ai): rate=-(-Tprev//Ti) else : rate=-(-Aprev//Ai) TA[i][0]=Ti*rate TA[i][1]=Ai*rate print(sum(TA[-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var TA : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for i : Integer.subrange(1, N-1) do ( var Tprev : OclAny := null; var Aprev : OclAny := null; Sequence{Tprev,Aprev} := TA[i - 1+1] ; var Ti : OclAny := null; var Ai : OclAny := null; Sequence{Ti,Ai} := TA[i+1] ; if (Ti->compareTo(Tprev)) >= 0 & (Ai->compareTo(Aprev)) >= 0 then ( continue ) else skip ; if ((Tprev / Ti)->compareTo((Aprev / Ai))) > 0 then ( var rate : int := -(-Tprev div Ti) ) else ( rate := -(-Aprev div Ai) ) ; TA[i+1]->first() := Ti * rate ; TA[i+1][1+1] := Ai * rate) ; execute ((TA->last())->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) suji=[] for i in range(n): suji=suji+list(map(int,input().split())) tlist=[] alist=[] for i in range(2*n): if i % 2==0 : tlist.append(suji[i]) else : alist.append(suji[i]) for i in range(n-1): aaa=alist[i]//alist[i+1] ttt=tlist[i]//tlist[i+1] if alist[i]% alist[i+1]!=0 : aaa+=1 if tlist[i]% tlist[i+1]!=0 : ttt+=1 k=max(aaa,ttt) tlist[i+1]=tlist[i+1]*k alist[i+1]=alist[i+1]*k print(int(tlist[n-1]+alist[n-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var suji : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( suji := suji->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var tlist : Sequence := Sequence{} ; var alist : Sequence := Sequence{} ; for i : Integer.subrange(0, 2 * n-1) do ( if i mod 2 = 0 then ( execute ((suji[i+1]) : tlist) ) else ( execute ((suji[i+1]) : alist) )) ; for i : Integer.subrange(0, n - 1-1) do ( var aaa : int := alist[i+1] div alist[i + 1+1] ; var ttt : int := tlist[i+1] div tlist[i + 1+1] ; if alist[i+1] mod alist[i + 1+1] /= 0 then ( aaa := aaa + 1 ) else skip ; if tlist[i+1] mod tlist[i + 1+1] /= 0 then ( ttt := ttt + 1 ) else skip ; var k : OclAny := Set{aaa, ttt}->max() ; tlist[i + 1+1] := tlist[i + 1+1] * k ; alist[i + 1+1] := alist[i + 1+1] * k) ; execute (("" + ((tlist[n - 1+1] + alist[n - 1+1])))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,Counter from itertools import product,groupby,count,permutations,combinations from math import pi,sqrt from collections import deque from bisect import bisect,bisect_left,bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF=float("inf") YES,Yes,yes,NO,No,no="YES","Yes","yes","NO","No","no" dy4,dx4=[0,1,0,-1],[1,0,-1,0] dy8,dx8=[0,-1,0,1,1,-1,-1,1],[1,0,-1,0,1,1,-1,-1] def inside(y,x,H,W): return 0<=y=a and A*i>=b : a,b=T*i,A*i break print(a+b) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(10000) ; var INF : double := ("" + (("inf")))->toReal() ; var YES : OclAny := null; var Yes : OclAny := null; var yes : OclAny := null; var NO : OclAny := null; var No : OclAny := null; var no : OclAny := null; Sequence{YES,Yes,yes,NO,No,no} := Sequence{"YES","Yes","yes","NO","No","no"} ; var dy4 : OclAny := null; var dx4 : OclAny := null; Sequence{dy4,dx4} := Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ -1 }))),Sequence{1}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{ 0 })))} ; var dy8 : OclAny := null; var dx8 : OclAny := null; Sequence{dy8,dx8} := Sequence{Sequence{0}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{-1}->union(Sequence{-1}->union(Sequence{ 1 }))))))),Sequence{1}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{-1}->union(Sequence{ -1 })))))))} ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation inside(y : OclAny, x : OclAny, H : OclAny, W : OclAny) : OclAny pre: true post: true activity: return 0 <= y & (y < H) & 0 <= x & (x < W); operation ceil(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a + b - 1) div b; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for _anon : Integer.subrange(0, N - 1-1) do ( var T : OclAny := null; var A : OclAny := null; Sequence{T,A} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : count(Set{a div T, b div A}->max() - 1) do ( if (T * i->compareTo(a)) >= 0 & (A * i->compareTo(b)) >= 0 then ( Sequence{a,b} := Sequence{T * i,A * i} ; break ) else skip)) ; execute (a + b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(k,d0,d1): s=((2*(d0+d1))% 10+(4*(d0+d1))% 10+(8*(d0+d1))% 10+(6*(d0+d1))% 10) a=(k-3)% 4 if(a==0): x=0 elif(a==1): x=(2*(d0+d1))% 10 elif(a==2): x=((2*(d0+d1))% 10+(4*(d0+d1))% 10) elif(a==3): x=((2*(d0+d1))% 10+(4*(d0+d1))% 10+(8*(d0+d1))% 10) sum=d0+d1+((k-3)//4)*s+x if(sum % 3==0): return "YES" else : return "NO" if __name__=='__main__' : k=13 d0=8 d1=1 print(check(k,d0,d1)) k=5 d0=3 d1=4 print(check(k,d0,d1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( k := 13 ; d0 := 8 ; d1 := 1 ; execute (check(k, d0, d1))->display() ; k := 5 ; d0 := 3 ; d1 := 4 ; execute (check(k, d0, d1))->display() ) else skip; operation check(k : OclAny, d0 : OclAny, d1 : OclAny) : OclAny pre: true post: true activity: var s : int := ((2 * (d0 + d1)) mod 10 + (4 * (d0 + d1)) mod 10 + (8 * (d0 + d1)) mod 10 + (6 * (d0 + d1)) mod 10) ; var a : int := (k - 3) mod 4 ; if (a = 0) then ( var x : int := 0 ) else (if (a = 1) then ( x := (2 * (d0 + d1)) mod 10 ) else (if (a = 2) then ( x := ((2 * (d0 + d1)) mod 10 + (4 * (d0 + d1)) mod 10) ) else (if (a = 3) then ( x := ((2 * (d0 + d1)) mod 10 + (4 * (d0 + d1)) mod 10 + (8 * (d0 + d1)) mod 10) ) else skip ) ) ) ; var sum : OclAny := d0 + d1 + ((k - 3) div 4) * s + x ; if (sum mod 3 = 0) then ( return "YES" ) else ( return "NO" ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b,c,d=map(int,input().split()) if(a==c and b==d): print(a,a+1) elif(a==c): print(a,a+1) elif(b==d): print(b-1,b) else : print(a,c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a = c & b = d) then ( execute (a)->display() ) else (if (a = c) then ( execute (a)->display() ) else (if (b = d) then ( execute (b - 1)->display() ) else ( execute (a)->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys import itertools import fractions if __name__=='__main__' : wtf=sys.stdin.read() wtf=wtf.strip().split('\n') for t in wtf[1 :]: l1,r1,l2,r2=map(int,t.split()) if l1!=l2 : print(l1,l2) elif l1!=r2 : print(l1,r2) elif r1!=l2 : print(r1,l2) elif r1!=r2 : print(r1,r2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var wtf : String := (OclFile["System.in"]).readAll() ; wtf := wtf->trim().split(' ') ; for t : wtf->tail() do ( var l1 : OclAny := null; var r1 : OclAny := null; var l2 : OclAny := null; var r2 : OclAny := null; Sequence{l1,r1,l2,r2} := (t.split())->collect( _x | (OclType["int"])->apply(_x) ) ; if l1 /= l2 then ( execute (l1)->display() ) else (if l1 /= r2 then ( execute (l1)->display() ) else (if r1 /= l2 then ( execute (r1)->display() ) else (if r1 /= r2 then ( execute (r1)->display() ) else skip ) ) ) ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) sp=[] p=[] n=0 b=list(map(int,input().split())) for r in range(1,len(b)-1): if b[r]==0 and b[r-1]==1 and b[r+1]==1 : n+=1 b[r+1]=0 print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sp : Sequence := Sequence{} ; var p : Sequence := Sequence{} ; var n : int := 0 ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for r : Integer.subrange(1, (b)->size() - 1-1) do ( if b[r+1] = 0 & b[r - 1+1] = 1 & b[r + 1+1] = 1 then ( n := n + 1 ; b[r + 1+1] := 0 ) else skip) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b,c,d=map(int,input().split()) if a==c : print(a,d) else : print(a,c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = c then ( execute (a)->display() ) else ( execute (a)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) for _ in range(x): l1,r1,l2,r2=map(int,input().split()) b=False for i in range(l1,r1+1): for j in range(l2,r2+1): if i!=j : print(i,j) b=True break if b : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, x-1) do ( var l1 : OclAny := null; var r1 : OclAny := null; var l2 : OclAny := null; var r2 : OclAny := null; Sequence{l1,r1,l2,r2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : boolean := false ; for i : Integer.subrange(l1, r1 + 1-1) do ( for j : Integer.subrange(l2, r2 + 1-1) do ( if i /= j then ( execute (i)->display() ; b := true ; break ) else skip) ; if b then ( break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): for i in range(int(input())): n=int(input()) if n % 3==0 : print(int(n/3)) elif n % 3==1 : if n==1 : print(2) else : print(int(n//3+n % 3)) else : print(int(n//3+1)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 3 = 0 then ( execute (("" + ((n / 3)))->toInteger())->display() ) else (if n mod 3 = 1 then ( if n = 1 then ( execute (2)->display() ) else ( execute (("" + ((n div 3 + n mod 3)))->toInteger())->display() ) ) else ( execute (("" + ((n div 3 + 1)))->toInteger())->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : l1,r1,l2,r2=map(int,input().split()) if l1==l2 : print(l1,r2) else : print(l1,l2) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( var l1 : OclAny := null; var r1 : OclAny := null; var l2 : OclAny := null; var r2 : OclAny := null; Sequence{l1,r1,l2,r2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if l1 = l2 then ( execute (l1)->display() ) else ( execute (l1)->display() ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque N=3 m={8 :{7,5},7 :{8,6,4},6 :{7,3},5 :{8,4,2},4 :{7,5,3,1},3 :{6,4,0},2 :{5,1},1 :{4,2,0},0 :{3,1}} goal=123456780 def g(i,j,a): t=a//(10**j)% 10 return a-t*(10**j)+t*(10**i) def solve(): MAP="".join(input().replace("","")for _ in range(N)) zero=8-MAP.find("0") start=int(MAP) if start==goal : return 0 dp=deque([(0,start,zero,1),(0,goal,0,0)]) TABLE={start :(1,0),goal :(0,0)} while dp : cnt,M,yx,flg=dp.popleft() cnt+=1 for nyx in m[yx]: key=g(yx,nyx,M) if key in TABLE : if TABLE[key][0]!=flg : return TABLE[key][1]+cnt continue TABLE[key]=(flg,cnt) dp.append((cnt,key,nyx,flg)) def MAIN(): print(solve()) MAIN() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 3 ; var m : Map := Map{ 8 |-> Set{7}->union(Set{ 5 }) }->union(Map{ 7 |-> Set{8}->union(Set{6}->union(Set{ 4 })) }->union(Map{ 6 |-> Set{7}->union(Set{ 3 }) }->union(Map{ 5 |-> Set{8}->union(Set{4}->union(Set{ 2 })) }->union(Map{ 4 |-> Set{7}->union(Set{5}->union(Set{3}->union(Set{ 1 }))) }->union(Map{ 3 |-> Set{6}->union(Set{4}->union(Set{ 0 })) }->union(Map{ 2 |-> Set{5}->union(Set{ 1 }) }->union(Map{ 1 |-> Set{4}->union(Set{2}->union(Set{ 0 })) }->union(Map{ 0 |-> Set{3}->union(Set{ 1 }) })))))))) ; var goal : int := 123456780 ; skip ; skip ; skip ; MAIN(); operation g(i : OclAny, j : OclAny, a : OclAny) : OclAny pre: true post: true activity: var t : int := a div ((10)->pow(j)) mod 10 ; return a - t * ((10)->pow(j)) + t * ((10)->pow(i)); operation solve() : OclAny pre: true post: true activity: var MAP : String := StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name replace) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "")))))) , (argument (test (logical_test (comparison (expr (atom ""))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) ))))))))), "") ; var zero : double := 8 - MAP->indexOf("0") - 1 ; var start : int := ("" + ((MAP)))->toInteger() ; if start = goal then ( return 0 ) else skip ; var dp : Sequence := (Sequence{Sequence{0, start, zero, 1}}->union(Sequence{ Sequence{0, goal, 0, 0} })) ; var TABLE : Map := Map{ start |-> Sequence{1, 0} }->union(Map{ goal |-> Sequence{0, 0} }) ; while dp do ( var cnt : OclAny := null; var M : OclAny := null; var yx : OclAny := null; var flg : OclAny := null; Sequence{cnt,M,yx,flg} := dp->first() ; dp := dp->tail() ; cnt := cnt + 1 ; for nyx : m[yx+1] do ( var key : OclAny := g(yx, nyx, M) ; if (TABLE)->includes(key) then ( if TABLE[key+1]->first() /= flg then ( return TABLE[key+1][1+1] + cnt ) else skip ; continue ) else skip ; TABLE[key+1] := Sequence{flg, cnt} ; execute ((Sequence{cnt, key, nyx, flg}) : dp))); operation MAIN() pre: true post: true activity: execute (solve())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heappush,heappop N=3 M=[] for i in range(N): M.append(list(map(int,input().split()))) A=(1,2,3,4,5,6,7,8,0) def h(M): c=0 it=iter(A).__next__ for i in range(N): for v in M[i]: if v!=it(): c+=1 return c def f(M): M0=[] for m in M : M0.extend(m) return tuple(M0) dd=((-1,0),(0,-1),(1,0),(0,1)) ci=cj=-1 for i in range(N): for j in range(N): if M[i][j]==0 : ci=i ; cj=j que=[(h(M),0,ci,cj,M)] U=set(f(M)) while que : hc,c,cr,cc,M=heappop(que) if hc==c : print(c) break for dr,dc in dd : nr=cr+dr ; nc=cc+dc if not 0<=nrcollect( _x | (OclType["int"])->apply(_x) ))) : M)) ; var A : OclAny := Sequence{1, 2, 3, 4, 5, 6, 7, 8, 0} ; skip ; skip ; var dd : OclAny := Sequence{Sequence{-1, 0}, Sequence{0, -1}, Sequence{1, 0}, Sequence{0, 1}} ; var ci : OclAny := -1; var cj : int := -1 ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( if M[i+1][j+1] = 0 then ( ci := i; cj := j ) else skip)) ; var que : Sequence := Sequence{ Sequence{h(M), 0, ci, cj, M} } ; var U : Set := Set{}->union((f(M))) ; while que do ( var hc : OclAny := null; var cr : OclAny := null; var cc : OclAny := null; Sequence{hc,c,cr,cc,M} := heappop(que) ; if hc = c then ( execute (c)->display() ; break ) else skip ; for _tuple : dd do (var _indx : int := 1; var dr : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dc : OclAny := _tuple->at(_indx); var nr : OclAny := cr + dr; var nc : OclAny := cc + dc ; if not(0 <= nr & (nr < N)) or not(0 <= nc & (nc < N)) then ( continue ) else skip ; var MM : Sequence := M->select(m | true)->collect(m | (m)) ; MM[cr+1][cc+1] := MM[nr+1][nc+1] ; MM[nr+1][nc+1] := 0 ; var s : String := f(MM) ; if (U)->includes(s) then ( continue ) else skip ; execute ((s) : U) ; heappush(que, Sequence{h(MM) + c + 1, c + 1, nr, nc, MM}))); operation h(M : OclAny) : OclAny pre: true post: true activity: var c : int := 0 ; var it : OclAny := iter(A).__next__ ; for i : Integer.subrange(0, N-1) do ( for v : M[i+1] do ( if v /= it() then ( c := c + 1 ) else skip)) ; return c; operation f(M : OclAny) : OclAny pre: true post: true activity: var M0 : Sequence := Sequence{} ; for m : M do ( M0 := M0->union(m)) ; return (M0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- adjacent=((1,3),(0,2,4),(1,5),(0,4,6),(1,3,5,7),(2,4,8),(3,7),(4,6,8),(5,7)) GOAL=[1,2,3,4,5,6,7,8,0] def solve(start): if start==GOAL : return 0 generated_state={tuple(start): 0,tuple(GOAL): 1} step={tuple(start): 0,tuple(GOAL): 0} s=0 state1=[(start,0),(GOAL,1)] while state1 : state2=state1[:] state1=[] s+=1 for s2,d in state2 : i=s2.index(0) for p in adjacent[i]: s1=s2[:] s1[i],s1[p]=s1[p],0 key=tuple(s1) if key in generated_state : if generated_state[key]!=d : return s+step[key] continue state1.append((s1,d)) generated_state[key]=d step[key]=s import sys start=list(map(int,sys.stdin.read().split())) print(solve(start)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var adjacent : OclAny := Sequence{Sequence{1, 3}, Sequence{0, 2, 4}, Sequence{1, 5}, Sequence{0, 4, 6}, Sequence{1, 3, 5, 7}, Sequence{2, 4, 8}, Sequence{3, 7}, Sequence{4, 6, 8}, Sequence{5, 7}} ; var GOAL : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 0 })))))))) ; skip ; skip ; start := ((sys.stdin.readAll().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (solve(start))->display(); operation solve(start : OclAny) : OclAny pre: true post: true activity: if start = GOAL then ( return 0 ) else skip ; var generated_state : Map := Map{ (start) |-> 0 }->union(Map{ (GOAL) |-> 1 }) ; var step : Map := Map{ (start) |-> 0 }->union(Map{ (GOAL) |-> 0 }) ; var s : int := 0 ; var state1 : Sequence := Sequence{Sequence{start, 0}}->union(Sequence{ Sequence{GOAL, 1} }) ; while state1 do ( var state2 : Sequence := state1 ; state1 := Sequence{} ; s := s + 1 ; for _tuple : state2 do (var _indx : int := 1; var s2 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); var i : int := s2->indexOf(0) - 1 ; for p : adjacent[i+1] do ( var s1 : Sequence := s2 ; var s1[i+1] : OclAny := null; var s1[p+1] : OclAny := null; Sequence{s1[i+1],s1[p+1]} := Sequence{s1[p+1],0} ; var key : Sequence := (s1) ; if (generated_state)->includes(key) then ( if generated_state->restrict(key) /= d then ( return s + step->restrict(key) ) else skip ; continue ) else skip ; execute ((Sequence{s1, d}) : state1) ; generated_state->restrict(key) := d ; step->restrict(key) := s))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque import sys M=[list(map(int,input().split()))for _ in range(3)] start=0 for i in range(3): for j in range(3): start+=M[i][j]*10**((2-i)*3+(2-j)) start="{:0>9}".format(start) def make_next_states(h,w,s): ret=[] x=[-1,0,1,0] y=[0,-1,0,1] for i in range(4): nh,nw=h+y[i],w+x[i] if(0<=nh<=2)and(0<=nw<=2): swap_ind=nh*3+nw char=s[swap_ind] next_s=s.replace(char,"x").replace("0",char).replace("x","0") ret.append(next_s) return ret finished=defaultdict(bool) finished[start]=True q=deque() q.append([start,0]) while 1 : s,n=q.popleft() finished[s]=True if s=="123456780" : break null=s.index("0") null_h=null//3 null_w=null % 3 next_states=make_next_states(null_h,null_w,s) for next_s in next_states : if not finished[next_s]: q.append([next_s,n+1]) print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var M : Sequence := Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var start : int := 0 ; for i : Integer.subrange(0, 3-1) do ( for j : Integer.subrange(0, 3-1) do ( start := start + M[i+1][j+1] * (10)->pow(((2 - i) * 3 + (2 - j))))) ; start := StringLib.interpolateStrings("{:0>9}", Sequence{start}) ; skip ; var finished : OclAny := defaultdict(OclType["boolean"]) ; finished[start+1] := true ; var q : Sequence := () ; execute ((Sequence{start}->union(Sequence{ 0 })) : q) ; while 1 do ( var n : OclAny := null; Sequence{s,n} := q->first() ; q := q->tail() ; finished[s+1] := true ; if s = "123456780" then ( break ) else skip ; var null : int := s->indexOf("0") - 1 ; var null_h : int := null div 3 ; var null_w : int := null mod 3 ; var next_states : OclAny := make_next_states(null_h, null_w, s) ; for next_s : next_states do ( if not(finished[next_s+1]) then ( execute ((Sequence{next_s}->union(Sequence{ n + 1 })) : q) ) else skip)) ; execute (n)->display(); operation make_next_states(h : OclAny, w : OclAny, s : OclAny) : OclAny pre: true post: true activity: var ret : Sequence := Sequence{} ; var x : Sequence := Sequence{-1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 0 }))) ; var y : Sequence := Sequence{0}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{ 1 }))) ; for i : Integer.subrange(0, 4-1) do ( var nh : OclAny := null; var nw : OclAny := null; Sequence{nh,nw} := Sequence{h + y[i+1],w + x[i+1]} ; if (0 <= nh & (nh <= 2)) & (0 <= nw & (nw <= 2)) then ( var swap_ind : double := nh * 3 + nw ; var char : OclAny := s[swap_ind+1] ; var next_s : OclAny := s.replace(char, "x").replace("0", char).replace("x", "0") ; execute ((next_s) : ret) ) else skip) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from itertools import chain from operator import mul exp10=[10**a for a in range(8,-1,-1)] movables=[{1,3},{0,2,4},{1,5},{0,4,6},{1,3,5,7},{2,4,8},{3,7},{4,6,8},{5,7}] destination=123456780 def swap(board,move_from,move_to): return board+(exp10[move_to]-exp10[move_from])*(board//exp10[move_from]% 10) board0=sum(map(mul,exp10,chain.from_iterable(map(int,input().split())for _ in range(3)))) p0=('0'+str(board0))[-9 :].index('0') appeared=({board0 : 0},{destination : 0}) queue=[] queue.extend((0,0,move_from,p0,board0)for move_from in movables[p0]) queue.extend((0,1,move_from,8,destination)for move_from in movables[8]) heapq.heapify(queue) while True : total_cost,direction,move_from,move_to,board=heapq.heappop(queue) if board in appeared[not direction]: print(total_cost+appeared[not direction][board]) break new_board=swap(board,move_from,move_to) if new_board in appeared[direction]: continue appeared[direction][new_board]=total_cost+1 for move_from2 in movables[move_from]: if move_from2!=move_to : heapq.heappush(queue,(total_cost+1,direction,move_from2,move_from,new_board)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var exp10 : Sequence := Integer.subrange(-1 + 1, 8)->reverse()->select(a | true)->collect(a | ((10)->pow(a))) ; var movables : Sequence := Sequence{Set{1}->union(Set{ 3 })}->union(Sequence{Set{0}->union(Set{2}->union(Set{ 4 }))}->union(Sequence{Set{1}->union(Set{ 5 })}->union(Sequence{Set{0}->union(Set{4}->union(Set{ 6 }))}->union(Sequence{Set{1}->union(Set{3}->union(Set{5}->union(Set{ 7 })))}->union(Sequence{Set{2}->union(Set{4}->union(Set{ 8 }))}->union(Sequence{Set{3}->union(Set{ 7 })}->union(Sequence{Set{4}->union(Set{6}->union(Set{ 8 }))}->union(Sequence{ Set{5}->union(Set{ 7 }) })))))))) ; var destination : int := 123456780 ; skip ; var board0 : OclAny := ((exp10)->collect( _x | (mul)->apply(_x) ))->sum() ; var p0 : OclAny := ('0' + ("" + ((board0)))).subrange(-9+1)->indexOf('0') - 1 ; var appeared : OclAny := Sequence{Map{ board0 |-> 0 }, Map{ destination |-> 0 }} ; var queue : Sequence := Sequence{} ; queue := queue->union((argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) , (test (logical_test (comparison (expr (atom (number (integer 0))))))) , (test (logical_test (comparison (expr (atom (name move_from)))))) , (test (logical_test (comparison (expr (atom (name p0)))))) , (test (logical_test (comparison (expr (atom (name board0))))))) )))))) (comp_for for (exprlist (expr (atom (name move_from)))) in (logical_test (comparison (expr (atom (name movables)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name p0)))))))) ])))))))) ; queue := queue->union((argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) , (test (logical_test (comparison (expr (atom (number (integer 1))))))) , (test (logical_test (comparison (expr (atom (name move_from)))))) , (test (logical_test (comparison (expr (atom (number (integer 8))))))) , (test (logical_test (comparison (expr (atom (name destination))))))) )))))) (comp_for for (exprlist (expr (atom (name move_from)))) in (logical_test (comparison (expr (atom (name movables)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 8))))))))) ])))))))) ; heapq.heapify(queue) ; while true do ( var total_cost : OclAny := null; var direction : OclAny := null; Sequence{total_cost,direction,move_from,move_to,board} := heapq.heappop(queue) ; if (appeared->select(not(direction)))->includes(board) then ( execute (total_cost + appeared->select(not(direction))[board+1])->display() ; break ) else skip ; var new_board : OclAny := swap(board, move_from, move_to) ; if (appeared[direction+1])->includes(new_board) then ( continue ) else skip ; appeared[direction+1][new_board+1] := total_cost + 1 ; for move_from2 : movables[move_from+1] do ( if move_from2 /= move_to then ( heapq.heappush(queue, Sequence{total_cost + 1, direction, move_from2, move_from, new_board}) ) else skip)); operation swap(board : OclAny, move_from : OclAny, move_to : OclAny) : OclAny pre: true post: true activity: return board + (exp10[move_to+1] - exp10[move_from+1]) * (board div exp10[move_from+1] mod 10); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib,itertools def compute(): LENGTH=20 BASE=10 MODULUS=10**9 MAX_SQR_DIGIT_SUM=(BASE-1)**2*LENGTH sqsum=[] count=[] for i in range(LENGTH+1): sqsum.append([0]*(MAX_SQR_DIGIT_SUM+1)) count.append([0]*(MAX_SQR_DIGIT_SUM+1)) if i==0 : count[0][0]=1 else : for j in range(BASE): for k in itertools.count(): index=k+j**2 if index>MAX_SQR_DIGIT_SUM : break sqsum[i][index]=(sqsum[i][index]+sqsum[i-1][k]+pow(BASE,i-1,MODULUS)*j*count[i-1][k])% MODULUS count[i][index]=(count[i][index]+count[i-1][k])% MODULUS ans=sum(sqsum[LENGTH][i**2]for i in range(1,eulerlib.sqrt(MAX_SQR_DIGIT_SUM))) return f"{ans%MODULUS:09}" if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LENGTH : int := 20 ; var BASE : int := 10 ; var MODULUS : double := (10)->pow(9) ; var MAX_SQR_DIGIT_SUM : double := ((BASE - 1))->pow(2) * LENGTH ; var sqsum : Sequence := Sequence{} ; var count : Sequence := Sequence{} ; for i : Integer.subrange(0, LENGTH + 1-1) do ( execute ((MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX_SQR_DIGIT_SUM + 1))) : sqsum) ; execute ((MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX_SQR_DIGIT_SUM + 1))) : count) ; if i = 0 then ( count->first()->first() := 1 ) else ( for j : Integer.subrange(0, BASE-1) do ( for k : itertools->count() do ( var index : OclAny := k + (j)->pow(2) ; if (index->compareTo(MAX_SQR_DIGIT_SUM)) > 0 then ( break ) else skip ; sqsum[i+1][index+1] := (sqsum[i+1][index+1] + sqsum[i - 1+1][k+1] + (BASE)->pow(i - 1) * j * count[i - 1+1][k+1]) mod MODULUS ; count[i+1][index+1] := (count[i+1][index+1] + count[i - 1+1][k+1]) mod MODULUS)) )) ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name sqsum)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name LENGTH)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) ** (expr (atom (number (integer 2)))))))))) ])))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name eulerlib)) (trailer . (name sqrt) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name MAX_SQR_DIGIT_SUM)))))))) ))))))))) )))))))))->sum() ; return StringLib.formattedString("{ans%MODULUS:09}"); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import bisect sys.setrecursionlimit(1000000000) from heapq import heappush,heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod=10**9+7 inf=float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) n=I() d=LI() d.sort() ans=d[n//2]-d[n//2-1] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit(1000000000) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; skip ; skip ; var n : OclAny := I() ; var d : OclAny := LI() ; d := d->sort() ; var ans : double := d[n div 2+1] - d[n div 2 - 1+1] ; execute (ans)->display(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) k=0 ans=0 for i in range(n): if arr[i]: if k==1 : ans+=1 k+=1 else : k=0 else : k+=1 if not arr[0]and arr[1]: ans-=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k : int := 0 ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] then ( if k = 1 then ( ans := ans + 1 ; k := k + 1 ) else ( k := 0 ) ) else ( k := k + 1 )) ; if not(arr->first()) & arr[1+1] then ( ans := ans - 1 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np i_N=int(input()) s_d=input().split() i_d=np.array(s_d).astype(type(i_N)) i_Counter=0 i_d=sorted(i_d) if(i_d[int(len(i_d)/2)-1]toInteger() ; var s_d : OclAny := input().split() ; var i_d : OclAny := np.array(s_d).astype((i_N)->oclType()) ; var i_Counter : int := 0 ; i_d := i_d->sort() ; if ((i_d[("" + (((i_d)->size() / 2)))->toInteger() - 1+1]->compareTo(i_d[("" + (((i_d)->size() / 2)))->toInteger()+1])) < 0) then ( i_Counter := i_d[("" + (((i_d)->size() / 2)))->toInteger()+1] - i_d[("" + (((i_d)->size() / 2)))->toInteger() - 1+1] ) else skip ; execute (i_Counter)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=list(input()) q=[] for i in range(n,0,-1): if n % i==0 : q+=[i] for j in q : w=n//j s=s[: w][: :-1]+s[w :] print(''.join(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var q : Sequence := Sequence{} ; for i : Integer.subrange(0 + 1, n)->reverse() do ( if n mod i = 0 then ( q := q + Sequence{ i } ) else skip) ; for j : q do ( var w : int := n div j ; s := s.subrange(1,w)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) + s.subrange(w+1)) ; execute (StringLib.sumStringsWithSeparator((s), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin if __name__=='__main__' : n=int(stdin.readline()) d=[int(x)for x in stdin.readline().rstrip().split()] d.sort() i=n//2 print(d[i]-d[i-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var n : int := ("" + ((stdin.readLine())))->toInteger() ; var d : Sequence := stdin.readLine().rstrip().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; d := d->sort() ; var i : int := n div 2 ; execute (d[i+1] - d[i - 1+1])->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) D=list(map(int,input().split())) D=sorted(D) left=D[N//2-1] right=D[N//2] print(right-left) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var D : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; D := D->sort() ; var left : OclAny := D[N div 2 - 1+1] ; var right : OclAny := D[N div 2+1] ; execute (right - left)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) d=list(map(int,input().split(' '))) d=sorted(d) print(d[int(n/2)]-d[int(n/2-1)]) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; d := d->sort() ; execute (d[("" + ((n / 2)))->toInteger()+1] - d[("" + ((n / 2 - 1)))->toInteger()+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def resolve(): import sys input=sys.stdin.readline n=int(input()) ans=set() for _ in range(n): q,x=[int(i)for i in input().split()] if q==0 : ans.add(x) print(len(ans)) elif q==1 : if x in ans : print(1) else : print(0) else : if x in ans : ans.remove(x) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; resolve(); operation resolve() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Set := Set{}->union(()) ; for _anon : Integer.subrange(0, n-1) do ( var q : OclAny := null; var x : OclAny := null; Sequence{q,x} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if q = 0 then ( execute ((x) : ans) ; execute ((ans)->size())->display() ) else (if q = 1 then ( if (ans)->includes(x) then ( execute (1)->display() ) else ( execute (0)->display() ) ) else ( if (ans)->includes(x) then ( execute ((x) /: ans) ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect S=[] def insert(S,count,x): y=bisect.bisect_left(S,x) if y>=count or S[y]!=x : S.insert(y,x) count+=1 print(count) return S,count def find(S,x): y=bisect.bisect_left(S,x) if ytoInteger() ; count := 0 ; for i : Integer.subrange(0, q-1) do ( var query : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if query->first() = 0 then ( Sequence{S,count} := insert(S, count, query[1+1]) ) else (if query->first() = 1 then ( execute (find(S, query[1+1])->first())->display() ) else ( if find(S, query[1+1])->first() = 1 then ( S := S->excludingAt(find(S, query[1+1])[1+1]+1) ; count := count - 1 ) else skip ) ) ); operation insert(S : OclAny, count : OclAny, x : OclAny) : OclAny pre: true post: true activity: var y : OclAny := bisect.bisect_left(S, x) ; if (y->compareTo(count)) >= 0 or S[y+1] /= x then ( S := S.insertAt(y+1, x) ; count := count + 1 ) else skip ; execute (count)->display() ; return S, count; operation find(S : OclAny, x : OclAny) : OclAny pre: true post: true activity: y := bisect.bisect_left(S, x) ; if (y->compareTo(count)) < 0 & S[y+1] = x then ( var judge : int := 1 ) else ( judge := 0 ) ; return judge, y; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- readline=open(0).readline writelines=open(1,'w').writelines s=set() def insert(x): s.add(x) ans.append("%d\n" % len(s)) def find(x): ans.append("%d\n" %(x in s)) C=[insert,find,s.discard].__getitem__ Q=int(readline()) ans=[] for _ in range(Q): t,x=map(int,readline().split()) C(t)(x) writelines(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var readline : OclAny := open(0).readline ; var writelines : OclAny := open(1, 'w').writelines ; var s : Set := Set{}->union(()) ; skip ; skip ; var C : OclAny := Sequence{insert}->union(Sequence{find}->union(Sequence{ s.discard })).__getitem__ ; var Q : int := ("" + ((readline())))->toInteger() ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, Q-1) do ( var t : OclAny := null; Sequence{t,x} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name C)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) ))) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))) ; writelines(ans); operation insert(x : OclAny) pre: true post: true activity: execute ((x) : s) ; execute ((StringLib.format("%d\n",(s)->size())) : ans); operation find(x : OclAny) pre: true post: true activity: execute ((StringLib.format("%d\n",((s)->includes(x)))) : ans); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline import collections def main(): tl={} for i in range(int(input())): l=list(map(int,input().split())) cmd=l[0] if cmd==0 : tl[l[1]]=1 print(len(tl)) elif cmd==1 : c=1 if l[1]in tl else 0 print(c) elif cmd==2 : d=l[1] try : tl.pop(d) except KeyError : None if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var tl : OclAny := Set{} ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cmd : OclAny := l->first() ; if cmd = 0 then ( tl[l[1+1]+1] := 1 ; execute ((tl)->size())->display() ) else (if cmd = 1 then ( var c : int := if (tl)->includes(l[1+1]) then 1 else 0 endif ; execute (c)->display() ) else (if cmd = 2 then ( var d : OclAny := l[1+1] ; try ( tl := tl->excludingAt(d+1)) (except_clause except (test (logical_test (comparison (expr (atom (name KeyError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom None)))))))))))) ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys s=set() input() for q in sys.stdin : q=q.split() if q[0]=='0' : s.add(q[1]) print(len(s)) elif q[0]=='1' : print(int(q[1]in s)) else : s.discard(q[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : Set := Set{}->union(()) ; input() ; for q : OclFile["System.in"] do ( var q : OclAny := q.split() ; if q->first() = '0' then ( execute ((q[1+1]) : s) ; execute ((s)->size())->display() ) else (if q->first() = '1' then ( execute (("" + (((s)->includes(q[1+1]))))->toInteger())->display() ) else ( execute ((q[1+1]) /: s) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=10000002 prime=[0]*(MAX) MAX_sqrt=int(MAX**(0.5)) prime_count=[0]*(MAX) def sieve(): prime[0],prime[1]=1,1 for i in range(2,MAX_sqrt): if prime[i]==0 : for j in range(i*2,MAX,i): if prime[j]==0 : prime[j]=i for i in range(2,MAX): if prime[i]==0 : prime[i]=i def numberOfDivisorsOfProduct(arr,n): for i in range(0,n): temp=arr[i] while temp!=1 : prime_count[prime[temp]]+=1 temp=temp//prime[temp] ans=1 for i in range(2,len(prime_count)): ans=ans*(prime_count[i]+1) return ans if __name__=="__main__" : sieve() arr=[2,4,6] n=len(arr) print(numberOfDivisorsOfProduct(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 10000002 ; var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX)) ; var MAX_sqrt : int := ("" + (((MAX)->pow((0.5)))))->toInteger() ; var prime_count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX)) ; skip ; skip ; if __name__ = "__main__" then ( sieve() ; arr := Sequence{2}->union(Sequence{4}->union(Sequence{ 6 })) ; n := (arr)->size() ; execute (numberOfDivisorsOfProduct(arr, n))->display() ) else skip; operation sieve() pre: true post: true activity: var prime->first() : OclAny := null; var prime[1+1] : OclAny := null; Sequence{prime->first(),prime[1+1]} := Sequence{1,1} ; for i : Integer.subrange(2, MAX_sqrt-1) do ( if prime[i+1] = 0 then ( for j : Integer.subrange(i * 2, MAX-1)->select( $x | ($x - i * 2) mod i = 0 ) do ( if prime[j+1] = 0 then ( prime[j+1] := i ) else skip) ) else skip) ; for i : Integer.subrange(2, MAX-1) do ( if prime[i+1] = 0 then ( prime[i+1] := i ) else skip); operation numberOfDivisorsOfProduct(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( var temp : OclAny := arr[i+1] ; while temp /= 1 do ( prime_count[prime[temp+1]+1] := prime_count[prime[temp+1]+1] + 1 ; temp := temp div prime[temp+1])) ; var ans : int := 1 ; for i : Integer.subrange(2, (prime_count)->size()-1) do ( ans := ans * (prime_count[i+1] + 1)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def val(c): if(c>='0' and c<='9'): return int(c) else : return c-'A'+10 def toDeci(strr,base): lenn=len(strr) power=1 num=0 for i in range(lenn-1,-1,-1): if(val(strr[i])>=base): return-1 num+=val(strr[i])*power power=power*base return num def checkCorrespond(strr,x): counter=0 n=len(strr) for i in range(n): for j in range(2,37): if(toDeci(strr[i],j)==x): counter+=1 break if(counter==n): print("YES") else : print("NO") x=16 strr=["10000","20","16"] checkCorrespond(strr,x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; x := 16 ; strr := Sequence{"10000"}->union(Sequence{"20"}->union(Sequence{ "16" })) ; checkCorrespond(strr, x); operation val(c : OclAny) : OclAny pre: true post: true activity: if (c >= '0' & c <= '9') then ( return ("" + ((c)))->toInteger() ) else ( return c - 'A' + 10 ); operation toDeci(strr : OclAny, base : OclAny) : OclAny pre: true post: true activity: var lenn : int := (strr)->size() ; var power : int := 1 ; var num : int := 0 ; for i : Integer.subrange(-1 + 1, lenn - 1)->reverse() do ( if ((val(strr[i+1])->compareTo(base)) >= 0) then ( return -1 ) else skip ; num := num + val(strr[i+1]) * power ; power := power * base) ; return num; operation checkCorrespond(strr : OclAny, x : OclAny) pre: true post: true activity: var counter : int := 0 ; var n : int := (strr)->size() ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(2, 37-1) do ( if (toDeci(strr[i+1], j) = x) then ( counter := counter + 1 ; break ) else skip)) ; if (counter = n) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) strk=input() for j in range(1,n+1): if j==n : strk=strk[: :-1] break if not n % j : prmzh=strk[: j] prmzh=prmzh[: :-1] strk=prmzh+strk[j :] print(strk) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var strk : String := (OclFile["System.in"]).readLine() ; for j : Integer.subrange(1, n + 1-1) do ( if j = n then ( strk := strk(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; break ) else skip ; if not(n mod j) then ( var prmzh : OclAny := strk.subrange(1,j) ; prmzh := prmzh(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; strk := prmzh + strk.subrange(j+1) ) else skip) ; execute (strk)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(num): digitSum=0 while(num!=0): digitSum=digitSum+num % 10 num=num//10 temp=(int)(digitSum) reverseDigitSum=0 while(temp!=0): rem=temp % 10 reverseDigitSum=reverseDigitSum*10+rem temp=temp/10 number=digitSum*reverseDigitSum return number num=1729 x=(check(num)) if(num==x): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; num := 1729 ; var x : OclAny := (check(num)) ; if (num = x) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation check(num : OclAny) : OclAny pre: true post: true activity: var digitSum : int := 0 ; while (num /= 0) do ( digitSum := digitSum + num mod 10 ; num := num div 10) ; var temp : OclAny := (OclType["int"])(digitSum) ; var reverseDigitSum : int := 0 ; while (temp /= 0) do ( var rem : int := temp mod 10 ; reverseDigitSum := reverseDigitSum * 10 + rem ; temp := temp / 10) ; var number : int := digitSum * reverseDigitSum ; return number; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def _sum(arr,n): return(sum(arr)) arr=[] arr=[12,3,4,15] n=len(arr) ans=_sum(arr,n) print('Sum of the array is ',ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{} ; arr := Sequence{12}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 15 }))) ; n := (arr)->size() ; var ans : OclAny := _sum(arr, n) ; execute ('Sum of the array is ')->display(); operation _sum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: return ((arr)->sum()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ways(n): first=2 ; second=3 ; res=0 ; for i in range(3,n+1): res=first+second ; first=second ; second=res ; return res ; n=7 ; print("Total ways are: ",ways(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 7; ; execute ("Total ways are: ")->display();; operation ways(n : OclAny) pre: true post: true activity: var first : int := 2; ; var second : int := 3; ; var res : int := 0; ; for i : Integer.subrange(3, n + 1-1) do ( res := first + second; ; first := second; ; second := res;) ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=[(int(x),i)for(i,x)in enumerate(input().split())] a.sort() used=[False for i in range(n)] sum=0 for(val,index)in a[-k :]: sum+=val used[index]=True print(sum) cur=0 ans=[] for i in range(n): if used[i]: ans.append(cur+1) cur=0 else : cur+=1 if cur>0 : ans[-1]+=cur print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(1, (input().split())->size())->collect( _indx | Sequence{_indx-1, (input().split())->at(_indx)} )->select(Sequence{i, x} | true)->collect(Sequence{i, x} | (Sequence{("" + ((x)))->toInteger(), i})) ; a := a->sort() ; var used : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (false)) ; var sum : int := 0 ; for Sequence{val, index} : a.subrange(-k+1) do ( sum := sum + val ; used[index+1] := true) ; execute (sum)->display() ; var cur : int := 0 ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if used[i+1] then ( execute ((cur + 1) : ans) ; cur := 0 ) else ( cur := cur + 1 )) ; if cur > 0 then ( ans->last() := ans->last() + cur ) else skip ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) n,k=R() a=sorted(zip(R(),range(n)))[-k :] print(sum(x[0]for x in a)) b=sorted(x[1]for x in a)+[n] b[0]=0 print(*(y-x for x,y in zip(b,b[1 :]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := R->apply() ; var a : OclAny := sorted(Integer.subrange(1, R->apply()->size())->collect( _indx | Sequence{R->apply()->at(_indx), Integer.subrange(0, n-1)->at(_indx)} )).subrange(-k+1) ; execute (((argument (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a))))))))->sum())->display() ; var b : Sequence := (argument (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a)))))))->sort()->union(Sequence{ n }) ; b->first() := 0 ; execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (name x))))))) (comp_for for (exprlist (expr (atom (name x))) , (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b))))))) , (argument (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))))))) )))))))) ))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- line1=str(input()) line1=line1.split("") n=int(line1[0]) k=int(line1[1]) string=str(input()) string=string.split("") sort=[] notsort=[] visited=[] for i in range(n): visited.append("0") sort.append(int(string[i])) notsort.append(int(string[i])) sort.sort() maximum=[] sum=0 maximumind=[] for i in range(1,k+1): maximum.append(sort[len(sort)-i]) sum+=sort[len(sort)-i] for i in range(len(maximum)): for j in range(n): if(maximum[i]==notsort[j]and visited[j]=="0"): visited[j]="1" maximumind.append(j) break maximumind.sort() size=[] f=0 for i in range(len(maximumind)): count=0 if(i==len(maximumind)-1): for j in range(f,n): count+=1 f+=1 size.append(count) else : for j in range(f,maximumind[i]+1): count+=1 f+=1 size.append(count) print(sum) ans="" for i in range(len(size)): ans+=str(size[i]) ans+="" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var line1 : String := ("" + (((OclFile["System.in"]).readLine()))) ; line1 := line1.split("") ; var n : int := ("" + ((line1->first())))->toInteger() ; var k : int := ("" + ((line1[1+1])))->toInteger() ; var string : String := ("" + (((OclFile["System.in"]).readLine()))) ; string := string.split("") ; var sort : Sequence := Sequence{} ; var notsort : Sequence := Sequence{} ; var visited : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (("0") : visited) ; execute ((("" + ((string[i+1])))->toInteger()) : sort) ; execute ((("" + ((string[i+1])))->toInteger()) : notsort)) ; sort := sort->sort() ; var maximum : Sequence := Sequence{} ; var sum : int := 0 ; var maximumind : Sequence := Sequence{} ; for i : Integer.subrange(1, k + 1-1) do ( execute ((sort[(sort)->size() - i+1]) : maximum) ; sum := sum + sort[(sort)->size() - i+1]) ; for i : Integer.subrange(0, (maximum)->size()-1) do ( for j : Integer.subrange(0, n-1) do ( if (maximum[i+1] = notsort[j+1] & visited[j+1] = "0") then ( visited[j+1] := "1" ; execute ((j) : maximumind) ; break ) else skip)) ; maximumind := maximumind->sort() ; var size : Sequence := Sequence{} ; var f : int := 0 ; for i : Integer.subrange(0, (maximumind)->size()-1) do ( var count : int := 0 ; if (i = (maximumind)->size() - 1) then ( for j : Integer.subrange(f, n-1) do ( count := count + 1 ; f := f + 1) ; execute ((count) : size) ) else ( for j : Integer.subrange(f, maximumind[i+1] + 1-1) do ( count := count + 1 ; f := f + 1) ; execute ((count) : size) )) ; execute (sum)->display() ; var ans : String := "" ; for i : Integer.subrange(0, (size)->size()-1) do ( ans := ans + ("" + ((size[i+1]))) ; ans := ans + "") ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,k=map(int,input().split()) w=list(map(int,input().split())) d=sorted(w,reverse=True)[: k] s=[-1] for i in range(len(d)): if i!=0 : if d[i]!=d[i-1]: s.append(w.index(d[i])) else : s.append(w.index(d[i],s[-1]+1)) else : s.append(w.index(d[i])) print(sum(d)) s.sort() s[-1]=n-1 for i in range(len(s)-1): print(s[i+1]-s[i],end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := sorted(w, (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))).subrange(1,k) ; var s : Sequence := Sequence{ -1 } ; for i : Integer.subrange(0, (d)->size()-1) do ( if i /= 0 then ( if d[i+1] /= d[i - 1+1] then ( execute ((w->indexOf(d[i+1]) - 1) : s) ) else ( execute ((w->indexOf(d[i+1], s->last() + 1) - 1) : s) ) ) else ( execute ((w->indexOf(d[i+1]) - 1) : s) )) ; execute ((d)->sum())->display() ; s := s->sort() ; s->last() := n - 1 ; for i : Integer.subrange(0, (s)->size() - 1-1) do ( execute (s[i + 1+1] - s[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=[] i=0 for x in input().split(): a.append((int(x),i)) i+=1 used=[False for i in range(n)] a.sort() sum=0 for(val,index)in a[-k :]: sum+=val used[index]=True print(sum) cur=0 ans=[] for i in range(n): if used[i]: ans.append(cur+1) cur=0 else : cur+=1 if cur>0 : ans[-1]+=cur print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{} ; var i : int := 0 ; for x : input().split() do ( execute ((Sequence{("" + ((x)))->toInteger(), i}) : a) ; i := i + 1) ; var used : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (false)) ; a := a->sort() ; var sum : int := 0 ; for Sequence{val, index} : a.subrange(-k+1) do ( sum := sum + val ; used[index+1] := true) ; execute (sum)->display() ; var cur : int := 0 ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if used[i+1] then ( execute ((cur + 1) : ans) ; cur := 0 ) else ( cur := cur + 1 )) ; if cur > 0 then ( ans->last() := ans->last() + cur ) else skip ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math pi=math.pi def volume(r,R,h): return 1/3*pi*h*(r*r+R*R+r*R) def curved_surface_area(r,R,l): return pi*l*(R+r) def total_surface_area(r,R,l,h): return pi*l*(R+r)+pi*(r*r+R*R) small_radius=3 big_radius=8 slant_height=13 height=12 print("Volume Of Frustum of Cone : ",end='') print(volume(small_radius,big_radius,height)) print("Curved Surface Area Of Frustum"+" of Cone : ",end='') print(curved_surface_area(small_radius,big_radius,slant_height)) print("Total Surface Area Of Frustum"+" of Cone : ",end='') print(total_surface_area(small_radius,big_radius,slant_height,height)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var pi : OclAny := ; skip ; skip ; skip ; var small_radius : int := 3 ; var big_radius : int := 8 ; var slant_height : int := 13 ; var height : int := 12 ; execute ("Volume Of Frustum of Cone : ")->display() ; execute (volume(small_radius, big_radius, height))->display() ; execute ("Curved Surface Area Of Frustum" + " of Cone : ")->display() ; execute (curved_surface_area(small_radius, big_radius, slant_height))->display() ; execute ("Total Surface Area Of Frustum" + " of Cone : ")->display() ; execute (total_surface_area(small_radius, big_radius, slant_height, height))->display(); operation volume(r : OclAny, R : OclAny, h : OclAny) : OclAny pre: true post: true activity: return 1 / 3 * pi * h * (r * r + R * R + r * R); operation curved_surface_area(r : OclAny, R : OclAny, l : OclAny) : OclAny pre: true post: true activity: return pi * l * (R + r); operation total_surface_area(r : OclAny, R : OclAny, l : OclAny, h : OclAny) : OclAny pre: true post: true activity: return pi * l * (R + r) + pi * (r * r + R * R); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def digitSum(n): sum=0 ; while(n>0): sum+=(n % 10); n//=10 ; return sum ; def isPalindrome(n): divisor=1 ; while(n//divisor>=10): divisor*=10 ; while(n!=0): leading=n//divisor ; trailing=n % 10 ; if(leading!=trailing): return False ; n=(n % divisor)//10 ; divisor=divisor//100 ; return True ; def isDigitSumPalindrome(n): sum=digitSum(n); if(isPalindrome(sum)): return True ; return False ; if __name__=="__main__" : n=56 ; if(isDigitSumPalindrome(n)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( n := 56; ; if (isDigitSumPalindrome(n)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ) else skip; operation digitSum(n : OclAny) pre: true post: true activity: var sum : int := 0; ; while (n > 0) do ( sum := sum + (n mod 10); ; n := n div 10;) ; return sum;; operation isPalindrome(n : OclAny) pre: true post: true activity: var divisor : int := 1; ; while (n div divisor >= 10) do ( divisor := divisor * 10;) ; while (n /= 0) do ( var leading : int := n div divisor; ; var trailing : int := n mod 10; ; if (leading /= trailing) then ( return false; ) else skip ; n := (n mod divisor) div 10; ; divisor := divisor div 100;) ; return true;; operation isDigitSumPalindrome(n : OclAny) pre: true post: true activity: sum := digitSum(n); ; if (isPalindrome(sum)) then ( return true; ) else skip ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def findAnswer(str1,str2,n): l,r=0,0 ans=2 for i in range(n): if(str1[i]!=str2[i]): l=i break for i in range(n-1,-1,-1): if(str1[i]!=str2[i]): r=i break if(rsize() ; execute (findAnswer(str1, str2, n))->display(); operation findAnswer(str1 : OclAny, str2 : OclAny, n : OclAny) : OclAny pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,0} ; var ans : int := 2 ; for i : Integer.subrange(0, n-1) do ( if (str1[i+1] /= str2[i+1]) then ( var l : OclAny := i ; break ) else skip) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (str1[i+1] /= str2[i+1]) then ( var r : OclAny := i ; break ) else skip) ; if ((r->compareTo(l)) < 0) then ( return 26 * (n + 1) ) else (if (l = r) then ( return ans ) else ( for i : Integer.subrange(l + 1, r + 1-1) do ( if (str1[i+1] /= str2[i - 1+1]) then ( ans := ans - 1 ; break ) else skip) ; for i : Integer.subrange(l + 1, r + 1-1) do ( if (str1[i - 1+1] /= str2[i+1]) then ( ans := ans - 1 ; break ) else skip) ; return ans ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=int(input()),input() for i in range(1,n+1): if n % i==0 : t=t[i-1 : :-1]+t[i :] print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),(OclFile["System.in"]).readLine()} ; for i : Integer.subrange(1, n + 1-1) do ( if n mod i = 0 then ( var t : OclAny := t(subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))) : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) + t.subrange(i+1) ) else skip) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) li=[0,1,2,3,4,5,6,7,8,9] res=[n] p=n//10 i=1 while p>0 : rem=p % 10 p//=10 j=li.index(rem) if j==0 : i+=1 continue else : j=li[j-1] res.append(p*10**(i+1)+j*10**i+int('9'*i)) i+=1 maxsum=0 maxi=0 def getsum(n): res=0 while n>0 : res+=n % 10 n//=10 return res for i in res : if getsum(i)>maxsum : maxsum=getsum(i) maxi=i print(maxi) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li : Sequence := Sequence{0}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 9 }))))))))) ; var res : Sequence := Sequence{ n } ; var p : int := n div 10 ; var i : int := 1 ; while p > 0 do ( var rem : int := p mod 10 ; p := p div 10 ; var j : int := li->indexOf(rem) - 1 ; if j = 0 then ( i := i + 1 ; continue ) else ( j := li[j - 1+1] ; execute ((p * (10)->pow((i + 1)) + j * (10)->pow(i) + ("" + ((StringLib.nCopies('9', i))))->toInteger()) : res) ; i := i + 1 )) ; var maxsum : int := 0 ; var maxi : int := 0 ; skip ; for i : res do ( if (getsum(i)->compareTo(maxsum)) > 0 then ( maxsum := getsum(i) ; maxi := i ) else skip) ; execute (maxi)->display(); operation getsum(n : OclAny) : OclAny pre: true post: true activity: res := 0 ; while n > 0 do ( res := res + n mod 10 ; n := n div 10) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) z=1 while(z<=t): n=int(input()) if(n<6): print("15") elif(n>6 and n % 2!=0): n=n+1 print(n//2*5) elif(n>=6 and n % 2==0): print(n//2*5) z=z+1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var z : int := 1 ; while ((z->compareTo(t)) <= 0) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n < 6) then ( execute ("15")->display() ) else (if (n > 6 & n mod 2 /= 0) then ( n := n + 1 ; execute (n div 2 * 5)->display() ) else (if (n >= 6 & n mod 2 = 0) then ( execute (n div 2 * 5)->display() ) else skip ) ) ; z := z + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) n+=n % 2 n=max(6,n) print(5*(n//2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; n := n + n mod 2 ; n := Set{6, n}->max() ; execute (5 * (n div 2))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) i=1 while True : if i>t : break i=i+1 n=int(input()) k=n//6 if n<=6 : print(15) continue if n % 6==0 : print(15*k) elif n % 6==1 or n % 6==2 : print(15*(k-1)+20) elif n % 6==3 or n % 6==4 : print(15*(k-1)+25) else : print(15*(k+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 1 ; while true do ( if (i->compareTo(t)) > 0 then ( break ) else skip ; i := i + 1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := n div 6 ; if n <= 6 then ( execute (15)->display() ; continue ) else skip ; if n mod 6 = 0 then ( execute (15 * k)->display() ) else (if n mod 6 = 1 or n mod 6 = 2 then ( execute (15 * (k - 1) + 20)->display() ) else (if n mod 6 = 3 or n mod 6 = 4 then ( execute (15 * (k - 1) + 25)->display() ) else ( execute (15 * (k + 1))->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n): time=2.5 if n<=6 : return round(6*time) if n<=8 : return round(8*time) if n<=10 : return round(10*time) if n % 2==0 : return round(n*2+round(n/2)) else : n+=1 return round(n*2+round(n/2)) t=int(input()) for _ in range(t): n=int(input()) print(solve(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (solve(n))->display()); operation solve(n : OclAny) : OclAny pre: true post: true activity: var time : double := 2.5 ; if n <= 6 then ( return (6 * time)->round() ) else skip ; if n <= 8 then ( return (8 * time)->round() ) else skip ; if n <= 10 then ( return (10 * time)->round() ) else skip ; if n mod 2 = 0 then ( return (n * 2 + (n / 2)->round())->round() ) else ( n := n + 1 ; return (n * 2 + (n / 2)->round())->round() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- test=int(input()) count=0 while(counttoInteger() ; var count : int := 0 ; while ((count->compareTo(test)) < 0) do ( var ans : int := 0 ; var friends : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var smalls : int := friends div 6 ; ans := smalls * 15 ; if (friends <= 6) then ( execute (15)->display() ; count := count + 1 ; continue ) else skip ; if (friends mod 6 = 1 or friends mod 6 = 2) then ( ans := ans + 5 ) else (if (friends mod 6 = 3 or friends mod 6 = 4) then ( ans := ans + 10 ) else (if (friends mod 6 = 5) then ( ans := ans + 15 ) else skip ) ) ; execute (ans)->display() ; count := count + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getPercentile(rank,students): result=(students-rank)/students*100 ; return result ; if __name__=="__main__" : your_rank=805 ; total_students=97481 ; print(getPercentile(your_rank,total_students)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var your_rank : int := 805; ; var total_students : int := 97481; ; execute (getPercentile(your_rank, total_students))->display(); ) else skip; operation getPercentile(rank : OclAny, students : OclAny) pre: true post: true activity: var result : double := (students - rank) / students * 100; ; return result;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPrime(n): if(n<=1): return False if(n<=3): return True if(n % 2==0 or n % 3==0): return False i=5 while(i*i<=n): if(n % i==0 or n %(i+2)==0): return False i=i+6 return True n=17 if(isPrime(n)and(n % 16==1)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 17 ; if (isPrime(n) & (n mod 16 = 1)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); operation isPrime(n : OclAny) : OclAny pre: true post: true activity: if (n <= 1) then ( return false ) else skip ; if (n <= 3) then ( return true ) else skip ; if (n mod 2 = 0 or n mod 3 = 0) then ( return false ) else skip ; var i : int := 5 ; while ((i * i->compareTo(n)) <= 0) do ( if (n mod i = 0 or n mod (i + 2) = 0) then ( return false ) else skip ; i := i + 6) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPrime(n): if(n<=1): return False if(n<=3): return True if(n % 2==0 or n % 3==0): return False i=5 while(i*i<=n): if(n % i==0 or n %(i+2)==0): return False i=i+6 return True n=13 if(isPrime(n)and(n % 4==1)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 13 ; if (isPrime(n) & (n mod 4 = 1)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); operation isPrime(n : OclAny) : OclAny pre: true post: true activity: if (n <= 1) then ( return false ) else skip ; if (n <= 3) then ( return true ) else skip ; if (n mod 2 = 0 or n mod 3 = 0) then ( return false ) else skip ; var i : int := 5 ; while ((i * i->compareTo(n)) <= 0) do ( if (n mod i = 0 or n mod (i + 2) = 0) then ( return false ) else skip ; i := i + 6) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPrime(n): if(n<=1): return False if(n<=3): return True if(n % 2==0 or n % 3==0): return False i=5 while(i*i<=n): if(n % i==0 or n %(i+2)==0): return False i=i+6 return True def isPowerOfTwo(n): return(n and(not(n &(n-1)))) n=43 if(isPrime(n)and isPowerOfTwo(n*3-1)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 43 ; if (isPrime(n) & isPowerOfTwo(n * 3 - 1)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); operation isPrime(n : OclAny) : OclAny pre: true post: true activity: if (n <= 1) then ( return false ) else skip ; if (n <= 3) then ( return true ) else skip ; if (n mod 2 = 0 or n mod 3 = 0) then ( return false ) else skip ; var i : int := 5 ; while ((i * i->compareTo(n)) <= 0) do ( if (n mod i = 0 or n mod (i + 2) = 0) then ( return false ) else skip ; i := i + 6) ; return true; operation isPowerOfTwo(n : OclAny) : OclAny pre: true post: true activity: return (n & (not((MathLib.bitwiseAnd(n, (n - 1)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() for i in range(1,n+1): if n % i==0 : s=s[: i][: :-1]+s[i :] print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(1, n + 1-1) do ( if n mod i = 0 then ( s := s.subrange(1,i)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) + s.subrange(i+1) ) else skip) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a,b,c=map(int,input().split()) maxx=max(a,b,c) if a==b==c==maxx : print("1 1 1") else : if c==b==maxx : print(maxx-a+1,1,1) else : if a==c==maxx : print(1,maxx-b+1,1) else : if a==b==maxx : print(1,1,maxx-c+1) else : if a==maxx : print(0,maxx-b+1,maxx-c+1) if b==maxx : print(maxx-a+1,0,maxx-c+1) if c==maxx : print(maxx-a+1,maxx-b+1,0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var maxx : OclAny := Set{a, b, c}->max() ; if a = b & (b == c) & (c == maxx) then ( execute ("1 1 1")->display() ) else ( if c = b & (b == maxx) then ( execute (maxx - a + 1)->display() ) else ( if a = c & (c == maxx) then ( execute (1)->display() ) else ( if a = b & (b == maxx) then ( execute (1)->display() ) else ( if a = maxx then ( execute (0)->display() ) else skip ; if b = maxx then ( execute (maxx - a + 1)->display() ) else skip ; if c = maxx then ( execute (maxx - a + 1)->display() ) else skip ) ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() l=len(x) if x.count('9')==l : print(x) exit() for i in range(1,l): if x[i]!='9' : sr='' for j in range(l-i): sr+='9' xxx=int(str(x[: i]))-1 temp=str(xxx)+sr t1=0 t2=0 for i in range(l): t1+=int(x[i]) t2+=int(temp[i]) if t1>=t2 : print(x) else : print(int(temp)) exit() print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := (OclFile["System.in"]).readLine() ; var l : int := (x)->size() ; if x->count('9') = l then ( execute (x)->display() ; exit() ) else skip ; for i : Integer.subrange(1, l-1) do ( if x[i+1] /= '9' then ( var sr : String := '' ; for j : Integer.subrange(0, l - i-1) do ( sr := sr + '9') ; var xxx : double := ("" + ((("" + ((x.subrange(1,i)))))))->toInteger() - 1 ; var temp : String := ("" + ((xxx))) + sr ; var t1 : int := 0 ; var t2 : int := 0 ; for i : Integer.subrange(0, l-1) do ( t1 := t1 + ("" + ((x[i+1])))->toInteger() ; t2 := t2 + ("" + ((temp[i+1])))->toInteger()) ; if (t1->compareTo(t2)) >= 0 then ( execute (x)->display() ) else ( execute (("" + ((temp)))->toInteger())->display() ) ; exit() ) else skip) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): votes=list(map(int,input().split())) max_votes=max(votes) max_count=len([x for x in votes if x==max_votes]) if max_count>1 : print(*[max_votes+1-x for x in votes]) else : print(*[max_votes+1-x if x!=max_votes else 0 for x in votes]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var votes : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var max_votes : OclAny := (votes)->max() ; var max_count : int := (votes->select(x | x = max_votes)->collect(x | (x)))->size() ; if max_count > 1 then ( execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name max_votes))) + (expr (atom (number (integer 1))))) - (expr (atom (name x))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name votes))))))) ])))))))->display() ) else ( execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name max_votes))) + (expr (atom (number (integer 1))))) - (expr (atom (name x)))))) if (logical_test (comparison (comparison (expr (atom (name x)))) != (comparison (expr (atom (name max_votes)))))) else (test (logical_test (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name votes))))))) ])))))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while(t>0): a,b,c=map(int,input().split()) k=max(a,b,c) li=[a,b,c] x=y=z=0 if(a==b and b==c): print(x+1,y+1,z+1) elif(li.count(k)>1): for i in li : print(k+1-i,end=" ") else : for i in li : if(i!=k): print(k+1-i,end=" ") else : print(0) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (t > 0) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : OclAny := Set{a, b, c}->max() ; var li : Sequence := Sequence{a}->union(Sequence{b}->union(Sequence{ c })) ; x := x(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name y)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name z)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; if (a = b & b = c) then ( execute (x + 1)->display() ) else (if (li->count(k) > 1) then ( for i : li do ( execute (k + 1 - i)->display()) ) else ( for i : li do ( if (i /= k) then ( execute (k + 1 - i)->display() ) else ( execute (0)->display() )) ) ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): mass=list(map(int,input().split())) d=mass.count(max(mass)) if d==1 : for i in range(3): if mass[i]==max(mass): print(0,end=" ") else : print(abs(mass[i]-max(mass))+1,end=" ") elif d==2 : for i in range(3): if mass[i]==max(mass): print(1,end=" ") else : print(abs(mass[i]-max(mass))+1,end=" ") else : print(1,1,1,end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var mass : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : int := mass->count((mass)->max()) ; if d = 1 then ( for i : Integer.subrange(0, 3-1) do ( if mass[i+1] = (mass)->max() then ( execute (0)->display() ) else ( execute ((mass[i+1] - (mass)->max())->abs() + 1)->display() )) ) else (if d = 2 then ( for i : Integer.subrange(0, 3-1) do ( if mass[i+1] = (mass)->max() then ( execute (1)->display() ) else ( execute ((mass[i+1] - (mass)->max())->abs() + 1)->display() )) ) else ( execute (1)->display() ) ) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): cand=input().split() a=int(cand[0]) b=int(cand[1]) c=int(cand[2]) if a-max(b,c)<0 : print(abs(a-max(b,c))+1,end=" ") elif a-max(b,c)==0 : print(1,end=" ") else : print(0,end=" ") if b-max(a,c)<0 : print(abs(b-max(a,c))+1,end=" ") elif b-max(a,c)==0 : print(1,end=" ") else : print(0,end=" ") if c-max(b,a)<0 : print(abs(c-max(b,a))+1) elif c-max(b,a)==0 : print(1) else : print(0) t=int(input()) while t>0 : solve() t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( solve() ; t := t - 1); operation solve() pre: true post: true activity: var cand : OclAny := input().split() ; var a : int := ("" + ((cand->first())))->toInteger() ; var b : int := ("" + ((cand[1+1])))->toInteger() ; var c : int := ("" + ((cand[2+1])))->toInteger() ; if a - Set{b, c}->max() < 0 then ( execute ((a - Set{b, c}->max())->abs() + 1)->display() ) else (if a - Set{b, c}->max() = 0 then ( execute (1)->display() ) else ( execute (0)->display() ) ) ; if b - Set{a, c}->max() < 0 then ( execute ((b - Set{a, c}->max())->abs() + 1)->display() ) else (if b - Set{a, c}->max() = 0 then ( execute (1)->display() ) else ( execute (0)->display() ) ) ; if c - Set{b, a}->max() < 0 then ( execute ((c - Set{b, a}->max())->abs() + 1)->display() ) else (if c - Set{b, a}->max() = 0 then ( execute (1)->display() ) else ( execute (0)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countOfSubstringWithKOnes(s,K): N=len(s) res=0 countOfOne=0 freq=[0 for i in range(N+1)] freq[0]=1 for i in range(0,N,1): countOfOne+=ord(s[i])-ord('0') if(countOfOne>=K): res+=freq[countOfOne-K] freq[countOfOne]+=1 return res if __name__=='__main__' : s="10010" K=1 print(countOfSubstringWithKOnes(s,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( s := "10010" ; K := 1 ; execute (countOfSubstringWithKOnes(s, K))->display() ) else skip; operation countOfSubstringWithKOnes(s : OclAny, K : OclAny) : OclAny pre: true post: true activity: var N : int := (s)->size() ; var res : int := 0 ; var countOfOne : int := 0 ; var freq : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (0)) ; freq->first() := 1 ; for i : Integer.subrange(0, N-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( countOfOne := countOfOne + (s[i+1])->char2byte() - ('0')->char2byte() ; if ((countOfOne->compareTo(K)) >= 0) then ( res := res + freq[countOfOne - K+1] ) else skip ; freq[countOfOne+1] := freq[countOfOne+1] + 1) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def kth(arr1,arr2,m,n,k): sorted1=[0]*(m+n) i=0 j=0 d=0 while(iunion(Sequence{3}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 9 })))) ; arr2 := Sequence{1}->union(Sequence{4}->union(Sequence{8}->union(Sequence{ 10 }))) ; k := 5; ; execute (kth(arr1, arr2, 5, 4, k))->display(); operation kth(arr1 : OclAny, arr2 : OclAny, m : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var sorted1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (m + n)) ; var i : int := 0 ; var j : int := 0 ; var d : int := 0 ; while ((i->compareTo(m)) < 0 & (j->compareTo(n)) < 0) do ( if ((arr1[i+1]->compareTo(arr2[j+1])) < 0) then ( sorted1[d+1] := arr1[i+1] ; i := i + 1 ) else ( sorted1[d+1] := arr2[j+1] ; j := j + 1 ) ; d := d + 1) ; while ((i->compareTo(m)) < 0) do ( sorted1[d+1] := arr1[i+1] ; d := d + 1 ; i := i + 1) ; while ((j->compareTo(n)) < 0) do ( sorted1[d+1] := arr2[j+1] ; d := d + 1 ; j := j + 1) ; return sorted1[k - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=256 freq=[[0 for i in range(MAX)]for j in range(MAX)] def preCalculate(string,n): freq[ord(string[0])][0]=1 for i in range(1,n): ch=string[i] for j in range(MAX): charToUpdate=chr(j) if charToUpdate==ch : freq[j][i]=freq[j][i-1]+1 else : freq[j][i]=freq[j][i-1] def getFrequency(ch,l,r): if l==0 : return freq[ord(ch)][r] else : return(freq[ord(ch)][r]-freq[ord(ch)][l-1]) def firstNonRepeating(string,n,l,r): t=[""]*2 for i in range(l,r): ch=string[i] if getFrequency(ch,l,r)==1 : t[0]=ch return t[0] return "-1" if __name__=="__main__" : string="GeeksForGeeks" n=len(string) queries=[(0,3),(2,3),(5,12)] q=len(queries) preCalculate(string,n) for i in range(q): print(firstNonRepeating(string,n,queries[i][0],queries[i][1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 256 ; var freq : Sequence := Integer.subrange(0, MAX-1)->select(j | true)->collect(j | (Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)))) ; skip ; skip ; skip ; if __name__ = "__main__" then ( string := "GeeksForGeeks" ; n := (string)->size() ; var queries : Sequence := Sequence{Sequence{0, 3}}->union(Sequence{Sequence{2, 3}}->union(Sequence{ Sequence{5, 12} })) ; var q : int := (queries)->size() ; preCalculate(string, n) ; for i : Integer.subrange(0, q-1) do ( execute (firstNonRepeating(string, n, queries[i+1]->first(), queries[i+1][1+1]))->display()) ) else skip; operation preCalculate(string : OclAny, n : OclAny) pre: true post: true activity: freq[(string->first())->char2byte()+1]->first() := 1 ; for i : Integer.subrange(1, n-1) do ( var ch : OclAny := string[i+1] ; for j : Integer.subrange(0, MAX-1) do ( var charToUpdate : String := (j)->byte2char() ; if charToUpdate = ch then ( freq[j+1][i+1] := freq[j+1][i - 1+1] + 1 ) else ( freq[j+1][i+1] := freq[j+1][i - 1+1] ))); operation getFrequency(ch : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: if l = 0 then ( return freq[(ch)->char2byte()+1][r+1] ) else ( return (freq[(ch)->char2byte()+1][r+1] - freq[(ch)->char2byte()+1][l - 1+1]) ); operation firstNonRepeating(string : OclAny, n : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var t : Sequence := MatrixLib.elementwiseMult(Sequence{ "" }, 2) ; for i : Integer.subrange(l, r-1) do ( ch := string[i+1] ; if getFrequency(ch, l, r) = 1 then ( t->first() := ch ; return t->first() ) else skip) ; return "-1"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=256 freq=[[0 for i in range(256)]for j in range(1000)] def preCalculate(string,n): freq[ord(string[0])][0]=1 for i in range(1,n): ch=string[i] for j in range(MAX): charToUpdate=chr(j) if charToUpdate==ch : freq[j][i]=freq[j][i-1]+1 else : freq[j][i]=freq[j][i-1] def getFrequency(ch,l,r): if l==0 : return freq[ord(ch)][r] else : return(freq[ord(ch)][r]-freq[ord(ch)][l-1]) def lastNonRepeating(string,n,l,r): for i in range(r,l-1,-1): ch=string[i] if getFrequency(ch,l,r)==1 : return ch return "-1" if __name__=="__main__" : string="GeeksForGeeks" n=len(string) queries=[(2,9),(2,3),(0,12)] q=len(queries) preCalculate(string,n) for i in range(q): print(lastNonRepeating(string,n,queries[i][0],queries[i][1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 256 ; var freq : Sequence := Integer.subrange(0, 1000-1)->select(j | true)->collect(j | (Integer.subrange(0, 256-1)->select(i | true)->collect(i | (0)))) ; skip ; skip ; skip ; if __name__ = "__main__" then ( string := "GeeksForGeeks" ; n := (string)->size() ; var queries : Sequence := Sequence{Sequence{2, 9}}->union(Sequence{Sequence{2, 3}}->union(Sequence{ Sequence{0, 12} })) ; var q : int := (queries)->size() ; preCalculate(string, n) ; for i : Integer.subrange(0, q-1) do ( execute (lastNonRepeating(string, n, queries[i+1]->first(), queries[i+1][1+1]))->display()) ) else skip; operation preCalculate(string : OclAny, n : OclAny) pre: true post: true activity: freq[(string->first())->char2byte()+1]->first() := 1 ; for i : Integer.subrange(1, n-1) do ( var ch : OclAny := string[i+1] ; for j : Integer.subrange(0, MAX-1) do ( var charToUpdate : String := (j)->byte2char() ; if charToUpdate = ch then ( freq[j+1][i+1] := freq[j+1][i - 1+1] + 1 ) else ( freq[j+1][i+1] := freq[j+1][i - 1+1] ))); operation getFrequency(ch : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: if l = 0 then ( return freq[(ch)->char2byte()+1][r+1] ) else ( return (freq[(ch)->char2byte()+1][r+1] - freq[(ch)->char2byte()+1][l - 1+1]) ); operation lastNonRepeating(string : OclAny, n : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(l - 1 + 1, r)->reverse() do ( ch := string[i+1] ; if getFrequency(ch, l, r) = 1 then ( return ch ) else skip) ; return "-1"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() for d in range(1,n+1): if n % d==0 : s=s[: d][: :-1]+s[d :] print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; for d : Integer.subrange(1, n + 1-1) do ( if n mod d = 0 then ( s := s.subrange(1,d)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) + s.subrange(d+1) ) else skip) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def divide(a,b): for i in range(2,min(a,b)+1): while(a % i==0 and b % i==0): a=a//i b=b//i print("A=",a,",B=",b) if __name__=="__main__" : A,B=10,15 divide(A,B) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := Sequence{10,15} ; divide(A, B) ) else skip; operation divide(a : OclAny, b : OclAny) pre: true post: true activity: for i : Integer.subrange(2, Set{a, b}->min() + 1-1) do ( while (a mod i = 0 & b mod i = 0) do ( a := a div i ; b := b div i)) ; execute ("A=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import random permutation=[] def printPermutation(): for i in permutation : print(i,end=" ") def give_random_number(l,r): x=random.randint(l,r) return x def generate_random_permutation(l,r): if(l>r): return n=give_random_number(l,r) permutation.append(n) generate_random_permutation(l,n-1) generate_random_permutation(n+1,r) l=5 r=15 generate_random_permutation(l,r) printPermutation() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var permutation : Sequence := Sequence{} ; skip ; skip ; skip ; l := 5 ; r := 15 ; generate_random_permutation(l, r) ; printPermutation(); operation printPermutation() pre: true post: true activity: for i : permutation do ( execute (i)->display()); operation give_random_number(l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var x : int := (l + (OclRandom.defaultInstanceOclRandom()).nextInt(r - l)) ; return x; operation generate_random_permutation(l : OclAny, r : OclAny) pre: true post: true activity: if ((l->compareTo(r)) > 0) then ( return ) else skip ; var n : OclAny := give_random_number(l, r) ; execute ((n) : permutation) ; generate_random_permutation(l, n - 1) ; generate_random_permutation(n + 1, r); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=input() p=[t]+[int(t)-int(t[-k :])-1 for k in range(1,len(t))] print(max(p,key=lambda variant : sum(map(int,str(variant))))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : String := (OclFile["System.in"]).readLine() ; var p : Sequence := Sequence{ t }->union(Integer.subrange(1, (t)->size()-1)->select(k | true)->collect(k | (("" + ((t)))->toInteger() - ("" + ((t.subrange(-k+1))))->toInteger() - 1))) ; execute (Set{p, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name variant)))) : (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name variant)))))))) ))))))))) ))))))))) )))))))))}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=map(int,input().split()) if d==1 : print(n*(n-1)//2) else : print((n-1)+(n-d-1)*n-((n-d-1)*(n+d-2)//2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if d = 1 then ( execute (n * (n - 1) div 2)->display() ) else ( execute ((n - 1) + (n - d - 1) * n - ((n - d - 1) * (n + d - 2) div 2))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=map(int,input().split()) if d==1 : print(n*(n-1)//2) else : print((n-1)+(n-d-1)*n-((n-d-1)*(n+d-2)//2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if d = 1 then ( execute (n * (n - 1) div 2)->display() ) else ( execute ((n - 1) + (n - d - 1) * n - ((n - d - 1) * (n + d - 2) div 2))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) if n==m : print(0) else : counter=0 flag=True while m>n : if(m/2)% n==0 : m/=2 counter+=1 elif(m/3)% n==0 : m/=3 counter+=1 else : flag=False break print(counter if flag else-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = m then ( execute (0)->display() ) else ( var counter : int := 0 ; var flag : boolean := true ; while (m->compareTo(n)) > 0 do ( if (m / 2) mod n = 0 then ( m := m / 2 ; counter := counter + 1 ) else (if (m / 3) mod n = 0 then ( m := m / 3 ; counter := counter + 1 ) else ( flag := false ; break ) ) ) ; execute (if flag then counter else -1 endif)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s,target=[int(i)for i in input().split(" ")] ctr=0 ans=[] def dfs(prod,ctr): if len(ans): return if prod==target : ans.append(ctr) return if prod>target : return prod*=2 dfs(prod,ctr+1) prod/=2 prod*=3 dfs(prod,ctr+1) prod/=3 dfs(s,ctr) print(ans[0]if len(ans)else-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := null; var target : OclAny := null; Sequence{s,target} := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ctr : int := 0 ; var ans : Sequence := Sequence{} ; skip ; dfs(s, ctr) ; execute (if (ans)->size() then ans->first() else -1 endif)->display(); operation dfs(prod : OclAny, ctr : OclAny) pre: true post: true activity: if (ans)->size() then ( return ) else skip ; if prod = target then ( execute ((ctr) : ans) ; return ) else skip ; if (prod->compareTo(target)) > 0 then ( return ) else skip ; prod := prod * 2 ; dfs(prod, ctr + 1) ; prod := prod / 2 ; prod := prod * 3 ; dfs(prod, ctr + 1) ; prod := prod / 3; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(n,m): nn=n mm=m if n==m : return 0 n2=0 n3=0 m2=0 m3=0 while n % 2==0 : n=n//2 n2+=1 while n % 3==0 : n=n//3 n3+=1 while m % 3==0 : m=m//3 m3+=1 while m % 2==0 : m=m//2 m2+=1 if not m3>=n3 or not m2>=n2 : return-1 if n!=m : return-1 return m3-n3+m2-n2 n,m=map(int,input().split(" ")) print(f(n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{n,m} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; execute (f(n, m))->display(); operation f(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var nn : OclAny := n ; var mm : OclAny := m ; if n = m then ( return 0 ) else skip ; var n2 : int := 0 ; var n3 : int := 0 ; var m2 : int := 0 ; var m3 : int := 0 ; while n mod 2 = 0 do ( n := n div 2 ; n2 := n2 + 1) ; while n mod 3 = 0 do ( n := n div 3 ; n3 := n3 + 1) ; while m mod 3 = 0 do ( m := m div 3 ; m3 := m3 + 1) ; while m mod 2 = 0 do ( m := m div 2 ; m2 := m2 + 1) ; if not((m3->compareTo(n3)) >= 0) or not((m2->compareTo(n2)) >= 0) then ( return -1 ) else skip ; if n /= m then ( return -1 ) else skip ; return m3 - n3 + m2 - n2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s,f=list(input().split(" ")) s,f=int(s),int(f) def check(num): step=0 while num % 2==0 : num=num/2 step+=1 while num % 3==0 : num=num/3 step+=1 if num==1 : print(step) else : print(-1) check(f/s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := null; var f : OclAny := null; Sequence{s,f} := (input().split(" ")) ; var s : OclAny := null; var f : OclAny := null; Sequence{s,f} := Sequence{("" + ((s)))->toInteger(),("" + ((f)))->toInteger()} ; skip ; check(f / s); operation check(num : OclAny) pre: true post: true activity: var step : int := 0 ; while num mod 2 = 0 do ( num := num / 2 ; step := step + 1) ; while num mod 3 = 0 do ( num := num / 3 ; step := step + 1) ; if num = 1 then ( execute (step)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) x,r=0,m/n for i in[2,3]: while r % i==0 : r/=i ; x+=1 print(x if r==1 else-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := null; var r : OclAny := null; Sequence{x,r} := Sequence{0,m / n} ; for i : Sequence{2}->union(Sequence{ 3 }) do ( while r mod i = 0 do ( r := r / i; x := x + 1)) ; execute (if r = 1 then x else -1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) T=[[]for i in range(n)] D=[-1]*n D[0]=0 Q=[0] for i in range(n-1): u,v,w=map(int,input().split()) T[u-1].append([v-1,w]) T[v-1].append([u-1,w]) while Q : q=Q.pop() for adj,w in T[q]: if D[adj]<0 : D[adj]=(D[q]+w)% 2 Q.append(adj) for d in D : print(d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var T : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; var D : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; D->first() := 0 ; var Q : Sequence := Sequence{ 0 } ; for i : Integer.subrange(0, n - 1-1) do ( var u : OclAny := null; var v : OclAny := null; var w : OclAny := null; Sequence{u,v,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name T)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name u))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (atom (name w))))))) ]))))))) )))) ; (expr (atom (name T)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name u))) - (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (atom (name w))))))) ]))))))) ))))) ; while Q do ( var q : OclAny := Q->last() ; Q := Q->front() ; for _tuple : T[q+1] do (var _indx : int := 1; var adj : OclAny := _tuple->at(_indx); _indx := _indx + 1; var w : OclAny := _tuple->at(_indx); if D[adj+1] < 0 then ( D[adj+1] := (D[q+1] + w) mod 2 ; execute ((adj) : Q) ) else skip)) ; for d : D do ( execute (d)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from random import randint def fin_st(l_i,st,l,rules): dict_a={"R" : l[0],"P" : l[1],"S" : l[2]} fin_str='' for i in st : if dict_a[rules[i]]>0 : fin_str+=rules[i] dict_a[rules[i]]-=1 else : t=randint(0,len(l_i)-1) fin_str+=l_i[t] del l_i[t] return fin_str for i in range(int(input())): n=int(input()) a,b,c=map(int,input().split()) st=input() rules={"S" : "R","P" : "S","R" : "P"} dict_a={"R" : a,"P" : b,"S" : c} dict_b={"R" : 0,"P" : 0,"S" : 0} for i in st : dict_b[i]+=1 wins=0 for i in dict_b : if dict_a[rules[i]]>=dict_b[i]: wins+=dict_b[i] dict_a[rules[i]]-=dict_b[i] else : wins+=dict_a[rules[i]] dict_a[rules[i]]=0 if round(n/2+1e-9)<=wins : print('YES') print(fin_st(["R"]*dict_a['R']+["P"]*dict_a['P']+["S"]*dict_a["S"],st,[a,b,c],rules)) else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; st := (OclFile["System.in"]).readLine() ; rules := Map{ "S" |-> "R" }->union(Map{ "P" |-> "S" }->union(Map{ "R" |-> "P" })) ; dict_a := Map{ "R" |-> a }->union(Map{ "P" |-> b }->union(Map{ "S" |-> c })) ; var dict_b : Map := Map{ "R" |-> 0 }->union(Map{ "P" |-> 0 }->union(Map{ "S" |-> 0 })) ; for i : st do ( dict_b[i+1] := dict_b[i+1] + 1) ; var wins : int := 0 ; for i : dict_b->keys() do ( if (dict_a[rules[i+1]+1]->compareTo(dict_b[i+1])) >= 0 then ( wins := wins + dict_b[i+1] ; dict_a[rules[i+1]+1] := dict_a[rules[i+1]+1] - dict_b[i+1] ) else ( wins := wins + dict_a[rules[i+1]+1] ; dict_a[rules[i+1]+1] := 0 )) ; if ((n / 2 + ("1e-9")->toReal())->round()->compareTo(wins)) <= 0 then ( execute ('YES')->display() ; execute (fin_st(MatrixLib.elementwiseMult(Sequence{ "R" }, dict_a->at('R'))->union(MatrixLib.elementwiseMult(Sequence{ "P" }, dict_a->at('P')))->union(MatrixLib.elementwiseMult(Sequence{ "S" }, dict_a->at("S"))), st, Sequence{a}->union(Sequence{b}->union(Sequence{ c })), rules))->display() ) else ( execute ('NO')->display() )); operation fin_st(l_i : OclAny, st : OclAny, l : OclAny, rules : OclAny) : OclAny pre: true post: true activity: var dict_a : Map := Map{ "R" |-> l->first() }->union(Map{ "P" |-> l[1+1] }->union(Map{ "S" |-> l[2+1] })) ; var fin_str : String := '' ; for i : st do ( if dict_a[rules[i+1]+1] > 0 then ( fin_str := fin_str + rules[i+1] ; dict_a[rules[i+1]+1] := dict_a[rules[i+1]+1] - 1 ) else ( var t : OclAny := randint(0, (l_i)->size() - 1) ; fin_str := fin_str + l_i[t+1] ; execute (l_i[t+1])->isDeleted() )) ; return fin_str; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys input=sys.stdin.readline for _ in range(int(input())): n=list(map(int,input().split()))[0] r,p,s=list(map(int,input().split())) S=list(map(str,input().split()))[0] cnt=0 ans='' for i in S : if i=='R' and p : ans+='P' p-=1 cnt+=1 elif i=='P' and s : ans+='S' s-=1 cnt+=1 elif i=='S' and r : ans+='R' r-=1 cnt+=1 else : ans+='0' ans=list(ans) a=[r,p,s] j=0 temp="RPS" for i in range(len(ans)): if ans[i]=='0' : if a[j]==0 : while j<3 and a[j]==0 : j+=1 ans[i]=temp[j] a[j]-=1 if cnt>=math.ceil(n/2): print("YES") print(*ans,sep="") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->first() ; var r : OclAny := null; var p : OclAny := null; var s : OclAny := null; Sequence{r,p,s} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var S : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["String"])->apply(_x) ))->first() ; var cnt : int := 0 ; var ans : String := '' ; for i : S do ( if i = 'R' & p then ( ans := ans + 'P' ; p := p - 1 ; cnt := cnt + 1 ) else (if i = 'P' & s then ( ans := ans + 'S' ; s := s - 1 ; cnt := cnt + 1 ) else (if i = 'S' & r then ( ans := ans + 'R' ; r := r - 1 ; cnt := cnt + 1 ) else ( ans := ans + '0' ) ) ) ) ; ans := (ans)->characters() ; var a : Sequence := Sequence{r}->union(Sequence{p}->union(Sequence{ s })) ; var j : int := 0 ; var temp : String := "RPS" ; for i : Integer.subrange(0, (ans)->size()-1) do ( if ans[i+1] = '0' then ( if a[j+1] = 0 then ( while j < 3 & a[j+1] = 0 do ( j := j + 1) ) else skip ; ans[i+1] := temp[j+1] ; a[j+1] := a[j+1] - 1 ) else skip) ; if (cnt->compareTo((n / 2)->ceil())) >= 0 then ( execute ("YES")->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n=int(input()) a,b,c=map(int,input().split()) a1,b1,c1=a,b,c s=input()[:-1] e,f,g=0,0,0 d='' for i in s : if i=='R' : e+=1 if b>0 : b-=1 d+='P' else : d+='?' elif i=='P' : f+=1 if c>0 : c-=1 d+='S' else : d+='?' else : g+=1 if a>0 : a-=1 d+='R' else : d+='?' x=min(b1,e)+min(c1,f)+min(a1,g) if x>=(n+1)//2 : print('YES') q='' for i in d : if i=='?' : if a>0 : a-=1 q+='R' elif b>0 : b-=1 q+='P' else : c-=1 q+='S' else : q+=i print(q) else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a1 : OclAny := null; var b1 : OclAny := null; var c1 : OclAny := null; Sequence{a1,b1,c1} := Sequence{a,b,c} ; var s : OclAny := input()->front() ; var e : OclAny := null; var f : OclAny := null; var g : OclAny := null; Sequence{e,f,g} := Sequence{0,0,0} ; var d : String := '' ; for i : s do ( if i = 'R' then ( e := e + 1 ; if b > 0 then ( b := b - 1 ; d := d + 'P' ) else ( d := d + '?' ) ) else (if i = 'P' then ( f := f + 1 ; if c > 0 then ( c := c - 1 ; d := d + 'S' ) else ( d := d + '?' ) ) else ( g := g + 1 ; if a > 0 then ( a := a - 1 ; d := d + 'R' ) else ( d := d + '?' ) ) ) ) ; var x : OclAny := Set{b1, e}->min() + Set{c1, f}->min() + Set{a1, g}->min() ; if (x->compareTo((n + 1) div 2)) >= 0 then ( execute ('YES')->display() ; var q : String := '' ; for i : d->characters() do ( if i = '?' then ( if a > 0 then ( a := a - 1 ; q := q + 'R' ) else (if b > 0 then ( b := b - 1 ; q := q + 'P' ) else ( c := c - 1 ; q := q + 'S' ) ) ) else ( q := q + i )) ; execute (q)->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- start,end,k=input(),input(),int(input()) n,mod=len(end),10**9+7 dp=[1,0] psum=1 for i in range(k): dp[0]=psum-dp[0] dp[1]=psum-dp[1] psum=(dp[0]+((n-1)*dp[1])% mod)% mod ans=0 for i in range(n): if start[i :]+start[: i]==end : if i==0 : ans+=dp[0] else : ans+=dp[1] print(ans % mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var start : OclAny := null; var end : OclAny := null; var k : OclAny := null; Sequence{start,end,k} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine(),("" + (((OclFile["System.in"]).readLine())))->toInteger()} ; var n : OclAny := null; var mod : OclAny := null; Sequence{n,mod} := Sequence{(end)->size(),(10)->pow(9) + 7} ; var dp : Sequence := Sequence{1}->union(Sequence{ 0 }) ; var psum : int := 1 ; for i : Integer.subrange(0, k-1) do ( dp->first() := psum - dp->first() ; dp[1+1] := psum - dp[1+1] ; psum := (dp->first() + ((n - 1) * dp[1+1]) mod mod) mod mod) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if start.subrange(i+1) + start.subrange(1,i) = end then ( if i = 0 then ( ans := ans + dp->first() ) else ( ans := ans + dp[1+1] ) ) else skip) ; execute (ans mod mod)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def digits(k): sum=0 for i in range(len(k)): sum+=int(k[i]) return sum for i in range(1): k=input() s=int(k) n=len(k) if n==1 : print(k) elif k[1 : :]==('9'*(n-1)): print(k) elif(k[1 :-1]==('9'*(n-2)))&(k[-1]=='8'): print(k) elif(k[1]=='8')&(k[2 : :]==('9'*(n-2))): print(k) else : m=k[1 : :] r=int(m) u=s-r-1 u=str(u) if(k[1]=='9'): t=1 m=k[0] while(k[t+1]=='9'): m+='9' t+=1 m=m+'8'+('9'*(n-1-t)) if(k[t+2 : :]=='9'*(n-t-2))&(k[t+1]=='8'): m=k a=digits(m) b=digits(u) if(a>=b): print(m) else : print(u) else : print(u) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, 1-1) do ( k := (OclFile["System.in"]).readLine() ; var s : int := ("" + ((k)))->toInteger() ; var n : int := (k)->size() ; if n = 1 then ( execute (k)->display() ) else (if k(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop :)) = (StringLib.nCopies('9', (n - 1))) then ( execute (k)->display() ) else (if MathLib.bitwiseAnd((k.subrange(1+1, -1) = (StringLib.nCopies('9', (n - 2)))), (k->last() = '8')) then ( execute (k)->display() ) else (if MathLib.bitwiseAnd((k[1+1] = '8'), (k(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop :)) = (StringLib.nCopies('9', (n - 2))))) then ( execute (k)->display() ) else ( var m : OclAny := k(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop :)) ; var r : int := ("" + ((m)))->toInteger() ; var u : double := s - r - 1 ; u := ("" + ((u))) ; if (k[1+1] = '9') then ( var t : int := 1 ; m := k->first() ; while (k[t + 1+1] = '9') do ( m := m + '9' ; t := t + 1) ; m := m + '8' + (StringLib.nCopies('9', (n - 1 - t))) ; if MathLib.bitwiseAnd((k(subscript (test (logical_test (comparison (expr (expr (atom (name t))) + (expr (atom (number (integer 2)))))))) : (sliceop :)) = StringLib.nCopies('9', (n - t - 2))), (k[t + 1+1] = '8')) then ( m := k ) else skip ; var a : OclAny := digits(m) ; var b : OclAny := digits(u) ; if ((a->compareTo(b)) >= 0) then ( execute (m)->display() ) else ( execute (u)->display() ) ) else ( execute (u)->display() ) ) ) ) ) ); operation digits(k : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, (k)->size()-1) do ( sum := sum + ("" + ((k[i+1])))->toInteger()) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t=int(input()) ans=[] for _ in range(t): n=int(input()) a,b,c=map(int,input().split()) s=list(input().rstrip()) ans0=["?"]*n cnt=0 for i in range(n): if s[i]==82 and b : b-=1 ans0[i]="P" cnt+=1 elif s[i]==80 and c : c-=1 ans0[i]="S" cnt+=1 elif s[i]==83 and a : a-=1 ans0[i]="R" cnt+=1 if cnttoInteger() ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := (input().rstrip()) ; var ans0 : Sequence := MatrixLib.elementwiseMult(Sequence{ "?" }, n) ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = 82 & b then ( b := b - 1 ; ans0[i+1] := "P" ; cnt := cnt + 1 ) else (if s[i+1] = 80 & c then ( c := c - 1 ; ans0[i+1] := "S" ; cnt := cnt + 1 ) else (if s[i+1] = 83 & a then ( a := a - 1 ; ans0[i+1] := "R" ; cnt := cnt + 1 ) else skip ) ) ) ; if (cnt->compareTo(n div 2 + n mod 2)) < 0 then ( ans0 := "NO" ; execute ((ans0) : ans) ) else ( execute (("YES") : ans) ; for i : Integer.subrange(0, n-1) do ( if not(ans0[i+1] = "?") then ( continue ) else skip ; if a then ( a := a - 1 ; ans0[i+1] := "R" ) else (if b then ( b := b - 1 ; ans0[i+1] := "P" ) else ( c := c - 1 ; ans0[i+1] := "S" ) ) ) ; execute ((StringLib.sumStringsWithSeparator((ans0), "")) : ans) )) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for i in range(int(input())): n=int(input()) r,p,S=map(int,input().split()) s=input() ans=[] cnt=0 for j in range(n): if s[j]=="R" : if p>0 : ans.append("P") p-=1 cnt+=1 else : ans.append("") elif s[j]=="P" : if S>0 : ans.append("S") S-=1 cnt+=1 else : ans.append("") elif s[j]=="S" : if r>0 : ans.append("R") r-=1 cnt+=1 else : ans.append("") for j in range(len(ans)): if ans[j]=="" : if r>0 : ans[j]="R" r-=1 elif p>0 : ans[j]="P" p-=1 elif S>0 : ans[j]="S" S-=1 if cnt>=(n+1)//2 : print("YES") for j in range(n): print(ans[j],end="") print() else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r : OclAny := null; var p : OclAny := null; var S : OclAny := null; Sequence{r,p,S} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var ans : Sequence := Sequence{} ; var cnt : int := 0 ; for j : Integer.subrange(0, n-1) do ( if s[j+1] = "R" then ( if p > 0 then ( execute (("P") : ans) ; p := p - 1 ; cnt := cnt + 1 ) else ( execute (("") : ans) ) ) else (if s[j+1] = "P" then ( if S > 0 then ( execute (("S") : ans) ; S := S - 1 ; cnt := cnt + 1 ) else ( execute (("") : ans) ) ) else (if s[j+1] = "S" then ( if r > 0 then ( execute (("R") : ans) ; r := r - 1 ; cnt := cnt + 1 ) else ( execute (("") : ans) ) ) else skip ) ) ) ; for j : Integer.subrange(0, (ans)->size()-1) do ( if ans[j+1] = "" then ( if r > 0 then ( ans[j+1] := "R" ; r := r - 1 ) else (if p > 0 then ( ans[j+1] := "P" ; p := p - 1 ) else (if S > 0 then ( ans[j+1] := "S" ; S := S - 1 ) else skip ) ) ) else skip) ; if (cnt->compareTo((n + 1) div 2)) >= 0 then ( execute ("YES")->display() ; for j : Integer.subrange(0, n-1) do ( execute (ans[j+1])->display()) ; execute (->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter a,b=list(map(int,input().split())) m=list(map(int,input().split())) c=[] for i in range(b): c.append(abs(m[i]-a)) c=Counter(c) if b>0 : i=0 while i<=b : if i not in c : print(a-i) break elif c[i]<2 and i!=0 : if a-i in m : print(i+a) else : print(-i+a) break i+=1 else : print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : Sequence := Sequence{} ; for i : Integer.subrange(0, b-1) do ( execute (((m[i+1] - a)->abs()) : c)) ; c := Counter(c) ; if b > 0 then ( var i : int := 0 ; while (i->compareTo(b)) <= 0 do ( if (c)->excludes(i) then ( execute (a - i)->display() ; break ) else (if c[i+1] < 2 & i /= 0 then ( if (m)->includes(a - i) then ( execute (i + a)->display() ) else ( execute (-i + a)->display() ) ; break ) else skip) ; i := i + 1) ) else ( execute (a)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=lambda : stdin.readline().rstrip() X,N=map(int,input().split()) P=list(map(int,input().split())) def solve(A,B): if A not in P : print(A) return if B not in P : print(B) return solve(A-1,B+1) solve(X,X) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (stdin.readLine().rstrip()) ; var X : OclAny := null; var N : OclAny := null; Sequence{X,N} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var P : Sequence := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; solve(X, X); operation solve(A : OclAny, B : OclAny) pre: true post: true activity: if (P)->excludes(A) then ( execute (A)->display() ; return ) else skip ; if (P)->excludes(B) then ( execute (B)->display() ; return ) else skip ; solve(A - 1, B + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,n=[int(i)for i in input().split()] p=[int(i)for i in input().split()] for i in range(100): if not x-i in p : print(x-i) exit(0) if not x+i in p : print(x+i) exit(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var n : OclAny := null; Sequence{x,n} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var p : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; for i : Integer.subrange(0, 100-1) do ( if not((p)->includes(x - i)) then ( execute (x - i)->display() ; exit(0) ) else skip ; if not((p)->includes(x + i)) then ( execute (x + i)->display() ; exit(0) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def paint(): while len(stack)>0 : node=stack.pop() for n in adj_list[node]: if color_list[n[0]]!="-1" : continue stack.append(n[0]) if n[1]% 2==0 : color_list[n[0]]=color_list[node] else : if color_list[node]=="0" : color_list[n[0]]="1" else : color_list[n[0]]="0" N=int(input()) adj_list=[[]for i in range(N)] for i in range(N-1): elm=[int(x)for x in input().split()] adj_list[elm[0]-1].append([elm[1]-1,elm[2]]) adj_list[elm[1]-1].append([elm[0]-1,elm[2]]) color_list=["-1"]*N color_list[0]="0" import sys sys.setrecursionlimit(10000) stack=[0] paint() for c in color_list : print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var adj_list : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, N - 1-1) do ( var elm : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; (expr (atom (name adj_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name elm)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name elm)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) - (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (atom (name elm)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ]))))))) ]))))))) )))) ; (expr (atom (name adj_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name elm)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name elm)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) - (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (atom (name elm)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ]))))))) ]))))))) ))))) ; var color_list : Sequence := MatrixLib.elementwiseMult(Sequence{ "-1" }, N) ; color_list->first() := "0" ; skip ; sys.setrecursionlimit(10000) ; var stack : Sequence := Sequence{ 0 } ; paint() ; for c : color_list do ( execute (c)->display()); operation paint() pre: true post: true activity: while (stack)->size() > 0 do ( var node : OclAny := stack->last() ; stack := stack->front() ; for n : adj_list[node+1] do ( if color_list[n->first()+1] /= "-1" then ( continue ) else skip ; execute ((n->first()) : stack) ; if n[1+1] mod 2 = 0 then ( color_list[n->first()+1] := color_list[node+1] ) else ( if color_list[node+1] = "0" then ( color_list[n->first()+1] := "1" ) else ( color_list[n->first()+1] := "0" ) ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- targ,length=map(int,input().split('')) banned=[False]*100 bans=input() if bans!='' : for ban in bans.split(''): banned[int(ban)-1]=True for dist in range(100): if targ-dist>0 : if not banned[targ-dist-1]: print(targ-dist) exit() else : print(targ-dist) exit() if targ+dist<=100 : if not banned[targ+dist-1]: print(targ+dist) exit() else : print(targ+dist) exit() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var targ : OclAny := null; var length : OclAny := null; Sequence{targ,length} := (input().split(''))->collect( _x | (OclType["int"])->apply(_x) ) ; var banned : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, 100) ; var bans : String := (OclFile["System.in"]).readLine() ; if bans /= '' then ( for ban : bans.split('') do ( banned[("" + ((ban)))->toInteger() - 1+1] := true) ) else skip ; for dist : Integer.subrange(0, 100-1) do ( if targ - dist > 0 then ( if not(banned[targ - dist - 1+1]) then ( execute (targ - dist)->display() ; exit() ) else skip ) else ( execute (targ - dist)->display() ; exit() ) ; if targ + dist <= 100 then ( if not(banned[targ + dist - 1+1]) then ( execute (targ + dist)->display() ; exit() ) else skip ) else ( execute (targ + dist)->display() ; exit() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import floor,ceil,sqrt,factorial,log from collections import Counter,deque from functools import reduce import numpy as np def S(): return input() def I(): return int(input()) def MS(): return map(str,input().split()) def MI(): return map(int,input().split()) def FLI(): return[int(i)for i in input().split()] def LS(): return list(MS()) def LI(): return list(MI()) def LLS(): return[list(map(str,l.split()))for l in input()] def LLI(): return[list(map(int,l.split()))for l in input()] def LLSN(n : int): return[LS()for _ in range(n)] def LLIN(n : int): return[LI()for _ in range(n)] X,N=MI() if N==0 : print(X) exit() P=LI() _min=10**9 ans=[] for p in range(X+1): for i in[-1,1]: a=X+(i*p) if a not in P : print(a) exit() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var X : OclAny := null; var N : OclAny := null; Sequence{X,N} := MI() ; if N = 0 then ( execute (X)->display() ; exit() ) else skip ; var P : OclAny := LI() ; var _min : double := (10)->pow(9) ; var ans : Sequence := Sequence{} ; for p : Integer.subrange(0, X + 1-1) do ( for i : Sequence{-1}->union(Sequence{ 1 }) do ( var a : OclAny := X + (i * p) ; if (P)->excludes(a) then ( execute (a)->display() ; exit() ) else skip)); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MS() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["String"])->apply(_x) ); operation MI() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation FLI() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation LS() : OclAny pre: true post: true activity: return (MS()); operation LI() : OclAny pre: true post: true activity: return (MI()); operation LLS() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine()->select(l | true)->collect(l | (((l.split())->collect( _x | (OclType["String"])->apply(_x) )))); operation LLI() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine()->select(l | true)->collect(l | (((l.split())->collect( _x | (OclType["int"])->apply(_x) )))); operation LLSN(n : int) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LS())); operation LLIN(n : int) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=input().split() color='#Black&White' for i in range(int(n)): x=input().split() for j in range(int(m)): if x[j]!='B' and x[j]!='G' and x[j]!='W' : color='#Color' print(color) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split() ; var color : String := '#Black&White' ; for i : Integer.subrange(0, ("" + ((n)))->toInteger()-1) do ( var x : OclAny := input().split() ; for j : Integer.subrange(0, ("" + ((m)))->toInteger()-1) do ( if x[j+1] /= 'B' & x[j+1] /= 'G' & x[j+1] /= 'W' then ( color := '#Color' ) else skip)) ; execute (color)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=[] x,y=(map(int,input().split())) for i in range(x): l+=input().split() if('C' in l)or('M' in l)or('Y' in l): print("#Color") else : print('#Black&White') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := Sequence{} ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, x-1) do ( l := l + input().split()) ; if ((l)->includes('C')) or ((l)->includes('M')) or ((l)->includes('Y')) then ( execute ("#Color")->display() ) else ( execute ('#Black&White')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) d="" for i in range(a): c=[str(q)for q in input().split()] if "C" in c or "M" in c or "Y" in c : d="#Color" break else : d="#Black&White" print(d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : String := "" ; for i : Integer.subrange(0, a-1) do ( var c : Sequence := input().split()->select(q | true)->collect(q | (("" + ((q))))) ; if (c)->includes("C") or (c)->includes("M") or (c)->includes("Y") then ( d := "#Color" ; break ) else ( d := "#Black&White" )) ; execute (d)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n,m,k=input().split(" ") a=[int(x)for x in input().split(" ")] b=[int(x)for x in input().split(" ")] a.sort() b.sort() ans="NO" i=len(a)-1 j=len(b)-1 while(i>=0 and j>=0): if a[i]>b[j]: ans="YES" print(ans) return i-=1 j-=1 if len(a)>len(b): ans="YES" print(ans) def main(): solve() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation solve() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := input().split(" ") ; var a : Sequence := input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var b : Sequence := input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; a := a->sort() ; b := b->sort() ; var ans : String := "NO" ; var i : double := (a)->size() - 1 ; var j : double := (b)->size() - 1 ; while (i >= 0 & j >= 0) do ( if (a[i+1]->compareTo(b[j+1])) > 0 then ( ans := "YES" ; execute (ans)->display() ; return ) else skip ; i := i - 1 ; j := j - 1) ; if ((a)->size()->compareTo((b)->size())) > 0 then ( ans := "YES" ) else skip ; execute (ans)->display(); operation main() pre: true post: true activity: solve(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) count=0 for i in range(n): m=list((input().split())) for i in m : if i=='C' or i=='M' or i=='Y' : count+=1 if count>0 : print("#Color") else : print("#Black&White") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( var m : Sequence := ((input().split())) ; for i : m do ( if i = 'C' or i = 'M' or i = 'Y' then ( count := count + 1 ) else skip)) ; if count > 0 then ( execute ("#Color")->display() ) else ( execute ("#Black&White")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- row,col=map(int,input().split()) st=set() for i in range(row): for n in input().split(): st.add(n) print('#Color' if len(st.intersection(set('CMY'.strip())))else '#Black&White') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var row : OclAny := null; var col : OclAny := null; Sequence{row,col} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var st : Set := Set{}->union(()) ; for i : Integer.subrange(0, row-1) do ( for n : input().split() do ( execute ((n) : st))) ; execute (if (st->intersection(Set{}->union(('CMY'->trim()))))->size() then '#Color' else '#Black&White' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def exponent(A,B): if(A==0): return 0 ; if(B==0): return 1 ; if(B % 2==0): y=exponent(A,B/2); y=(y*y); else : y=A ; y=(y*exponent(A,B-1)); return y ; def sum(k,n): sum=exponent(k,n+1)-exponent(k-1,n+1); return sum ; n=3 ; K=3 ; print(sum(K,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 3; ; var K : int := 3; ; execute ((K, n)->sum())->display();; operation exponent(A : OclAny, B : OclAny) pre: true post: true activity: if (A = 0) then ( return 0; ) else skip ; if (B = 0) then ( return 1; ) else skip ; if (B mod 2 = 0) then ( var y : OclAny := exponent(A, B / 2); ; y := (y * y); ) else ( y := A; ; y := (y * exponent(A, B - 1)); ) ; return y;; operation sum(k : OclAny, n : OclAny) pre: true post: true activity: var sum : double := exponent(k, n + 1) - exponent(k - 1, n + 1); ; return sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() print(s[: : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; execute (s(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- number=int(input()) list_of_lucky_numbers=[] last_lucky=0 next_digit=4 cycle=1 next_lucky_4=0 next_lucky_7=0 list_of_4_and_7=[] last_array_4_and_7=[0,0] least=0 while 1 : next_lucky_4=int(str(last_lucky)+"4") next_lucky_7=int(str(last_lucky)+"7") list_of_lucky_numbers.append(next_lucky_4) list_of_4_and_7.append([last_array_4_and_7[0]+1,last_array_4_and_7[1]]) if last_array_4_and_7[0]+1==last_array_4_and_7[1]and next_lucky_4>=number : least=next_lucky_4 break list_of_lucky_numbers.append(next_lucky_7) list_of_4_and_7.append([last_array_4_and_7[0],last_array_4_and_7[1]+1]) if last_array_4_and_7[0]==last_array_4_and_7[1]+1 and next_lucky_7>=number : least=next_lucky_7 break last_lucky=list_of_lucky_numbers[int(cycle/2)] last_array_4_and_7=list_of_4_and_7[int(cycle/2)] cycle+=1 print(least) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var number : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var list_of_lucky_numbers : Sequence := Sequence{} ; var last_lucky : int := 0 ; var next_digit : int := 4 ; var cycle : int := 1 ; var next_lucky_4 : int := 0 ; var next_lucky_7 : int := 0 ; var list_of_4_and_7 : Sequence := Sequence{} ; var last_array_4_and_7 : Sequence := Sequence{0}->union(Sequence{ 0 }) ; var least : int := 0 ; while 1 do ( next_lucky_4 := ("" + ((("" + ((last_lucky))) + "4")))->toInteger() ; next_lucky_7 := ("" + ((("" + ((last_lucky))) + "7")))->toInteger() ; execute ((next_lucky_4) : list_of_lucky_numbers) ; execute ((Sequence{last_array_4_and_7->first() + 1}->union(Sequence{ last_array_4_and_7[1+1] })) : list_of_4_and_7) ; if last_array_4_and_7->first() + 1 = last_array_4_and_7[1+1] & (next_lucky_4->compareTo(number)) >= 0 then ( least := next_lucky_4 ; break ) else skip ; execute ((next_lucky_7) : list_of_lucky_numbers) ; execute ((Sequence{last_array_4_and_7->first()}->union(Sequence{ last_array_4_and_7[1+1] + 1 })) : list_of_4_and_7) ; if last_array_4_and_7->first() = last_array_4_and_7[1+1] + 1 & (next_lucky_7->compareTo(number)) >= 0 then ( least := next_lucky_7 ; break ) else skip ; last_lucky := list_of_lucky_numbers[("" + ((cycle / 2)))->toInteger()+1] ; last_array_4_and_7 := list_of_4_and_7[("" + ((cycle / 2)))->toInteger()+1] ; cycle := cycle + 1) ; execute (least)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import bisect def solve(s): n=len(s) A=[] for i in range(0,n,2): A.append(s[i]) return ''.join(A) def main(): print(solve(input())) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation solve(s : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; var A : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( execute ((s[i+1]) : A)) ; return StringLib.sumStringsWithSeparator((A), ''); operation main() pre: true post: true activity: execute (solve((OclFile["System.in"]).readLine()))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() L=["a"]*((len(s)+1)//2) for i in range(0,(len(s)+1)//2): L[i]=s[2*i] print("".join(L)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var L : Sequence := MatrixLib.elementwiseMult(Sequence{ "a" }, (((s)->size() + 1) div 2)) ; for i : Integer.subrange(0, ((s)->size() + 1) div 2-1) do ( L[i+1] := s[2 * i+1]) ; execute (StringLib.sumStringsWithSeparator((L), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(input()[: : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (input()(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(input()) array=[] for i in range(len(s)): if i % 2==0 : array.append(s[i]) print("".join(array),end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var array : Sequence := Sequence{} ; for i : Integer.subrange(0, (s)->size()-1) do ( if i mod 2 = 0 then ( execute ((s[i+1]) : array) ) else skip) ; execute (StringLib.sumStringsWithSeparator((array), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- pref=[0]*100001 def checkPalindrome(num): strr=str(num) l=0 r=len(strr)-1 while(lunion(Sequence{ 13 })}->union(Sequence{ Sequence{12}->union(Sequence{ 21 }) }) ; printSumPalindromic(arr, Q); operation checkPalindrome(num : OclAny) : OclAny pre: true post: true activity: var strr : String := ("" + ((num))) ; var l : int := 0 ; var r : double := (strr)->size() - 1 ; while ((l->compareTo(r)) < 0) do ( if (strr[l+1] /= strr[r+1]) then ( return 0 ) else skip ; l := l + 1 ; r := r - 1) ; return num; operation preCompute() pre: true post: true activity: for i : Integer.subrange(1, 100001-1) do ( pref[i+1] := pref[i - 1+1] + checkPalindrome(i)); operation printSum(L : OclAny, R : OclAny) pre: true post: true activity: execute (pref[R+1] - pref[L - 1+1])->display(); operation printSumPalindromic(arr : OclAny, Q : OclAny) pre: true post: true activity: preCompute() ; for i : Integer.subrange(0, Q-1) do ( printSum(arr[i+1]->first(), arr[i+1][1+1])); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def main(): H=int(input()) ans=0 while H>0 : ans+=1 H//=2 print(pow(2,ans)-1) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var H : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; while H > 0 do ( ans := ans + 1 ; H := H div 2) ; execute ((2)->pow(ans) - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : n,m,k=list(map(int,input().split(' '))) a,b=list(map(int,input().split(' '))),list(map(int,input().split(' '))) a.sort(reverse=True) b.sort(reverse=True) if n>m or a[0]>b[0]: print('YES') exit() j=0 for i in range(len(a)): if a[i]>b[i]: print('YES') exit() print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )),((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ))} ; a := a->sort() ; b := b->sort() ; if (n->compareTo(m)) > 0 or (a->first()->compareTo(b->first())) > 0 then ( execute ('YES')->display() ; exit() ) else skip ; var j : int := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( if (a[i+1]->compareTo(b[i+1])) > 0 then ( execute ('YES')->display() ; exit() ) else skip) ; execute ("NO")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math h=int(input()) l=math.floor(math.log(h,2)) print(2**l*2-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var h : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : double := ((h, 2)->log())->floor() ; execute ((2)->pow(l) * 2 - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import os import math import string ii=lambda : int(sys.stdin.buffer.readline().rstrip()) il=lambda : list(map(int,sys.stdin.buffer.readline().split())) fl=lambda : list(map(float,sys.stdin.buffer.readline().split())) iln=lambda n :[int(sys.stdin.buffer.readline().rstrip())for _ in range(n)] iss=lambda : sys.stdin.buffer.readline().decode().rstrip() sl=lambda : list(map(str,sys.stdin.buffer.readline().decode().split())) isn=lambda n :[sys.stdin.buffer.readline().decode().rstrip()for _ in range(n)] lcm=lambda x,y : x*y/math.gcd(x,y) MOD=10**9+7 MAX=float('inf') def f(N): atk=0 if N==1 : atk+=1 else : atk+=f(N//2)*2+1 return atk def main(): if os.getenv("LOCAL"): sys.stdin=open("input.txt","r") N=ii() print(f(N)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var ii : Function := lambda $$ : OclAny in (("" + ((sys.stdin.buffer.readLine().rstrip())))->toInteger()) ; var il : Function := lambda $$ : OclAny in (((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var fl : Function := lambda $$ : OclAny in (((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ))) ; var iln : Function := lambda n : OclAny in (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + ((sys.stdin.buffer.readLine().rstrip())))->toInteger()))) ; var iss : Function := lambda $$ : OclAny in (sys.stdin.buffer.readLine().decode().rstrip()) ; var sl : Function := lambda $$ : OclAny in (((sys.stdin.buffer.readLine().decode().split())->collect( _x | (OclType["String"])->apply(_x) ))) ; var isn : Function := lambda n : OclAny in (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (sys.stdin.buffer.readLine().decode().rstrip()))) ; var lcm : Function := lambda x : OclAny, y : OclAny in (x * y / (x)->gcd(y)) ; var MOD : double := (10)->pow(9) + 7 ; var MAX : double := ("" + (('inf')))->toReal() ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation f(N : OclAny) : OclAny pre: true post: true activity: var atk : int := 0 ; if N = 1 then ( atk := atk + 1 ) else ( atk := atk + f(N div 2) * 2 + 1 ) ; return atk; operation main() pre: true post: true activity: if os.getenv("LOCAL") then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ) else skip ; N := ii->apply() ; execute (f(N))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H=int(input()) def divCount(n,cnt=0): if n<=1 : return cnt return divCount(int(n/2),cnt+1) attackCount=0 for i in range(0,divCount(H)+1): attackCount+=pow(2,i) print(attackCount) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; var attackCount : int := 0 ; for i : Integer.subrange(0, divCount(H) + 1-1) do ( attackCount := attackCount + (2)->pow(i)) ; execute (attackCount)->display(); operation divCount(n : OclAny, cnt : int) : OclAny pre: true post: true activity: if cnt->oclIsUndefined() then cnt := 0 else skip; if n <= 1 then ( return cnt ) else skip ; return divCount(("" + ((n / 2)))->toInteger(), cnt + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections N=int(input()) UVW=[[int(_)for _ in input().split()]for _ in range(N-1)] cd=collections.defaultdict G=cd(lambda : cd(int)) for u,v,w in UVW : G[u][v]=G[v][u]=w ans=[-1]*(N+1) ans[1]=0 stack=[1] while stack : f=stack.pop() for t in G[f].keys(): if ans[t]==-1 : stack+=[t] if G[f][t]% 2 : ans[t]=1-ans[f] else : ans[t]=ans[f] print(*ans[1 :],sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var UVW : Sequence := Integer.subrange(0, N - 1-1)->select(_anon | true)->collect(_anon | (input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())))) ; var cd : OclAny := .defaultdict ; var G : OclAny := cd(lambda $$ : OclAny in (cd(OclType["int"]))) ; for _tuple : UVW do (var _indx : int := 1; var u : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var w : OclAny := _tuple->at(_indx); G[u+1][v+1] := w; var G[v+1][u+1] : OclAny := w) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (N + 1)) ; ans[1+1] := 0 ; var stack : Sequence := Sequence{ 1 } ; while stack do ( var f : OclAny := stack->last() ; stack := stack->front() ; for t : G[f+1].keys() do ( if ans[t+1] = -1 then ( stack := stack + Sequence{ t } ; if G[f+1][t+1] mod 2 then ( ans[t+1] := 1 - ans[f+1] ) else ( ans[t+1] := ans[f+1] ) ) else skip)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(2**(len(bin(int(input())))-2)-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((2)->pow(((bin(("" + (((OclFile["System.in"]).readLine())))->toInteger()))->size() - 2)) - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000,10**9)) write=lambda x : sys.stdout.write(x+"\n") n,k=list(map(int,input().split())) M=10**9+7 def fs(n): s=set() for i in range(1,int(n**0.5)+2): if n % i==0 : s.add(i) s.add(n//i) l=sorted(list(s)) return l ds=fs(n) m=len(ds) nums=[None]*m for i in range(m): val=pow(k,(ds[i]+1)//2,M) for j in range(i): if ds[i]% ds[j]==0 : val-=nums[j] val %=M nums[i]=val % M ans=0 inv2=pow(2,M-2,M) for i in range(m): if ds[i]% 2==0 : ans+=ds[i]*nums[i]*inv2 else : ans+=ds[i]*nums[i] ans %=M print(ans % M) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; sys.setrecursionlimit(Set{1000, (10)->pow(9)}->max()) ; var write : Function := lambda x : OclAny in ((OclFile["System.out"]).write(x + "\n")) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var M : double := (10)->pow(9) + 7 ; skip ; var ds : OclAny := fs(n) ; var m : int := (ds)->size() ; var nums : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, m) ; for i : Integer.subrange(0, m-1) do ( var val : double := (k)->pow((ds[i+1] + 1) div 2) ; for j : Integer.subrange(0, i-1) do ( if ds[i+1] mod ds[j+1] = 0 then ( val := val - nums[j+1] ; val := val mod M ) else skip) ; nums[i+1] := val mod M) ; var ans : int := 0 ; var inv2 : double := (2)->pow(M - 2) ; for i : Integer.subrange(0, m-1) do ( if ds[i+1] mod 2 = 0 then ( ans := ans + ds[i+1] * nums[i+1] * inv2 ) else ( ans := ans + ds[i+1] * nums[i+1] ) ; ans := ans mod M) ; execute (ans mod M)->display(); operation fs(n : OclAny) : OclAny pre: true post: true activity: var s : Set := Set{}->union(()) ; for i : Integer.subrange(1, ("" + (((n)->pow(0.5))))->toInteger() + 2-1) do ( if n mod i = 0 then ( execute ((i) : s) ; execute ((n div i) : s) ) else skip) ; var l : Sequence := (s)->sort() ; return l; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def divisors(M): d=[] i=1 while M>=i**2 : if M % i==0 : d.append(i) if i**2!=M : d.append(M//i) i=i+1 d.sort() return d mod=10**9+7 N,K=map(int,input().split()) div=divisors(N) res=[0 for i in range(len(div))] ans=0 if N % 2==0 : for i in range(len(div)): d=div[i] g=gcd(2*d,N) res[i]+=pow(K,g//2,mod) res[i]%=mod ans+=d*res[i] ans %=mod for j in range(i+1,len(div)): if div[j]% d==0 : res[j]-=res[i] res[j]%=mod print(ans % mod) else : for i in range(len(div)): d=div[i] g=gcd(2*d,N) res[i]+=pow(K,(g+1)//2,mod) res[i]%=mod ans+=d*res[i] ans %=mod for j in range(i+1,len(div)): if div[j]% d==0 : res[j]-=res[i] res[j]%=mod print(ans % mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var mod : double := (10)->pow(9) + 7 ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var div : OclAny := divisors(N) ; var res : Sequence := Integer.subrange(0, (div)->size()-1)->select(i | true)->collect(i | (0)) ; var ans : int := 0 ; if N mod 2 = 0 then ( for i : Integer.subrange(0, (div)->size()-1) do ( d := div[i+1] ; var g : OclAny := gcd(MatrixLib.elementwiseMult(d, 2), N) ; res[i+1] := res[i+1] + (K)->pow(g div 2) ; res[i+1] := res[i+1] mod mod ; ans := ans + MatrixLib.elementwiseMult(d, res[i+1]) ; ans := ans mod mod ; for j : Integer.subrange(i + 1, (div)->size()-1) do ( if div[j+1] mod d = 0 then ( res[j+1] := res[j+1] - res[i+1] ; res[j+1] := res[j+1] mod mod ) else skip)) ; execute (ans mod mod)->display() ) else ( for i : Integer.subrange(0, (div)->size()-1) do ( d := div[i+1] ; g := gcd(MatrixLib.elementwiseMult(d, 2), N) ; res[i+1] := res[i+1] + (K)->pow((g + 1) div 2) ; res[i+1] := res[i+1] mod mod ; ans := ans + MatrixLib.elementwiseMult(d, res[i+1]) ; ans := ans mod mod ; for j : Integer.subrange(i + 1, (div)->size()-1) do ( if div[j+1] mod d = 0 then ( res[j+1] := res[j+1] - res[i+1] ; res[j+1] := res[j+1] mod mod ) else skip)) ; execute (ans mod mod)->display() ); operation divisors(M : OclAny) : OclAny pre: true post: true activity: var d : Sequence := Sequence{} ; var i : int := 1 ; while (M->compareTo((i)->pow(2))) >= 0 do ( if M mod i = 0 then ( execute ((i) : d) ; if (i)->pow(2) /= M then ( execute ((M div i) : d) ) else skip ) else skip ; i := i + 1) ; d := d->sort() ; return d; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.read readline=sys.stdin.readline n,k=map(int,readline().split()) MOD=10**9+7 def divisor_list(N): if N==1 : return[1] res=[] for i in range(1,N): if i*i>=N : break if N % i==0 : res.append(i) res.append(N//i) if i*i==N : res.append(i) return sorted(res) if n & 1 : p=[i for i in divisor_list(n)] r={pi : pow(k,(pi+1)//2,MOD)for pi in p} for pi in p : for pj in p : if pj>=pi : break if pi % pj==0 : r[pi]-=r[pj] ans=0 for pi,v in r.items(): ans+=v*(pi) ans %=MOD print(ans) else : p=[1]+[i for i in divisor_list(n)if i % 2==0 and i!=2] r={pi : pow(k,(pi+1)//2,MOD)for pi in p} for pi in p : for pj in p : if pj>=pi : break if pi % pj==0 : r[pi]-=r[pj] ans=0 for pi,v in r.items(): if pi==1 : ans+=v else : ans+=v*(pi//2) ans %=MOD print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := (OclFile["System.in"]).read ; var readline : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var MOD : double := (10)->pow(9) + 7 ; skip ; if MathLib.bitwiseAnd(n, 1) then ( var p : Sequence := divisor_list(n)->select(i | true)->collect(i | (i)) ; var r : Map := p->select(pi | true)->collect(pi | Map{pi |-> (k)->pow((pi + 1) div 2)})->unionAll() ; for pi : p do ( for pj : p do ( if (pj->compareTo(pi)) >= 0 then ( break ) else skip ; if pi mod pj = 0 then ( r[pi+1] := r[pi+1] - r[pj+1] ) else skip)) ; var ans : int := 0 ; for _tuple : r->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var pi : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); ans := ans + v * (pi)) ; ans := ans mod MOD ; execute (ans)->display() ) else ( p := Sequence{ 1 }->union(divisor_list(n)->select(i | i mod 2 = 0 & i /= 2)->collect(i | (i))) ; r := p->select(pi | true)->collect(pi | Map{pi |-> (k)->pow((pi + 1) div 2)})->unionAll() ; for pi : p do ( for pj : p do ( if (pj->compareTo(pi)) >= 0 then ( break ) else skip ; if pi mod pj = 0 then ( r[pi+1] := r[pi+1] - r[pj+1] ) else skip)) ; ans := 0 ; for _tuple : r->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var pi : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if pi = 1 then ( ans := ans + v ) else ( ans := ans + v * (pi div 2) )) ; ans := ans mod MOD ; execute (ans)->display() ); operation divisor_list(N : OclAny) : OclAny pre: true post: true activity: if N = 1 then ( return Sequence{ 1 } ) else skip ; var res : Sequence := Sequence{} ; for i : Integer.subrange(1, N-1) do ( if (i * i->compareTo(N)) >= 0 then ( break ) else skip ; if N mod i = 0 then ( execute ((i) : res) ; execute ((N div i) : res) ) else skip) ; if i * i = N then ( execute ((i) : res) ) else skip ; return res->sort(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def MI(): return map(int,sys.stdin.readline().rstrip().split()) N,K=MI() mod=10**9+7 def divisor(n): res=[] for i in range(1,int(n**.5)+1): if n % i==0 : res.append(i) if i!=n//i : res.append(n//i) return res A=divisor(N) d={} for a in A : d[a]=divisor(a) prime=[] for i in range(2,int(N**.5)+1): if N % i==0 : prime.append(i) while N % i==0 : N//=i if N!=1 : prime.append(N) mu={} for a in A : b=a r=1 for p in prime : if b % p==0 : r*=-1 if b//p % p==0 : r=0 break mu[a]=r ans=0 for a in A : for b in d[a]: if a % 2==0 : ans+=mu[a//b]*pow(K,(b+1)//2,mod)*(a//2) ans %=mod else : ans+=mu[a//b]*pow(K,(b+1)//2,mod)*a ans %=mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := MI() ; var mod : double := (10)->pow(9) + 7 ; skip ; var A : OclAny := divisor(N) ; var d : OclAny := Set{} ; for a : A do ( d[a+1] := divisor(a)) ; var prime : Sequence := Sequence{} ; for i : Integer.subrange(2, ("" + (((N)->pow(.5))))->toInteger() + 1-1) do ( if N mod i = 0 then ( execute ((i) : prime) ; while N mod i = 0 do ( N := N div i) ) else skip) ; if N /= 1 then ( execute ((N) : prime) ) else skip ; var mu : OclAny := Set{} ; for a : A do ( var b : OclAny := a ; var r : int := 1 ; for p : prime do ( if b mod p = 0 then ( r := r * -1 ; if b div p mod p = 0 then ( r := 0 ; break ) else skip ) else skip) ; mu[a+1] := r) ; var ans : int := 0 ; for a : A do ( for b : d[a+1] do ( if a mod 2 = 0 then ( ans := ans + mu[a div b+1] * (K)->pow((b + 1) div 2) * (a div 2) ; ans := ans mod mod ) else ( ans := ans + mu[a div b+1] * (K)->pow((b + 1) div 2) * a ; ans := ans mod mod ))) ; execute (ans)->display(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ); operation divisor(n : OclAny) : OclAny pre: true post: true activity: var res : Sequence := Sequence{} ; for i : Integer.subrange(1, ("" + (((n)->pow(.5))))->toInteger() + 1-1) do ( if n mod i = 0 then ( execute ((i) : res) ; if i /= n div i then ( execute ((n div i) : res) ) else skip ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline import numpy as np MOD=10**9+7 N,K=map(int,input().split()) U=int(10**4.5+10) div=np.arange(1,U,dtype=np.int64) div=div[N % div==0] div=sorted(np.union1d(div,N//div)) A={d : pow(K,int((d+1)//2),MOD)for d in div} B={} for d in div : B[d]=A[d]-sum(B[dd]for dd in div if ddpow(9) + 7 ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var U : int := ("" + (((10)->pow(4.5) + 10)))->toInteger() ; var div : Sequence := MathLib.numericRange(1, U, (argument (test (logical_test (comparison (expr (atom (name dtype)))))) = (test (logical_test (comparison (expr (atom (name np)) (trailer . (name int64)))))))) ; div := div->select(N mod div = 0) ; div := ->sort() ; var A : Map := div->select(d | true)->collect(d | Map{d |-> (K)->pow(("" + (((d + 1) div 2)))->toInteger())})->unionAll() ; var B : OclAny := Set{} ; for d : div do ( B[d+1] := A[d+1] - ((argument (test (logical_test (comparison (expr (atom (name B)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name dd)))))))) ])))))) (comp_for for (exprlist (expr (atom (name dd)))) in (logical_test (comparison (expr (atom (name div))))) (comp_iter if (test (logical_test (logical_test (comparison (comparison (expr (atom (name dd)))) < (comparison (expr (atom (name d)))))) and (logical_test (comparison (comparison (expr (expr (atom (name d))) % (expr (atom (name dd))))) == (comparison (expr (atom (number (integer 0)))))))))))))->sum()) ; var answer : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name B)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name d)))))))) ]))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name d))) // (expr (atom (number (integer 2))))))) if (logical_test (comparison (comparison (expr (expr (atom (name d))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 0))))))) else (test (logical_test (comparison (expr (atom (name d)))))))) ))))))) (comp_for for (exprlist (expr (atom (name d)))) in (logical_test (comparison (expr (atom (name div))))))))->sum() ; answer := answer mod MOD ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=3 ; def interchangeDiagonals(array): for i in range(N): if(i!=N/2): temp=array[i][i]; array[i][i]=array[i][N-i-1]; array[i][N-i-1]=temp ; for i in range(N): for j in range(N): print(array[i][j],end=" "); print(); if __name__=='__main__' : array=[4,5,6],[1,2,3],[7,8,9]; interchangeDiagonals(array); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 3; ; skip ; if __name__ = '__main__' then ( array := Sequence{4}->union(Sequence{5}->union(Sequence{ 6 })),Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })),Sequence{7}->union(Sequence{8}->union(Sequence{ 9 })); ; interchangeDiagonals(array); ) else skip; operation interchangeDiagonals(array : OclAny) pre: true post: true activity: for i : Integer.subrange(0, N-1) do ( if (i /= N / 2) then ( var temp : OclAny := array[i+1][i+1]; ; array[i+1][i+1] := array[i+1][N - i - 1+1]; ; array[i+1][N - i - 1+1] := temp; ) else skip) ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( execute (array[i+1][j+1])->display();) ; execute (->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def day_725(): input() a=[int(v)for v in input().split(" ")] b=[int(v)for v in input().split(" ")] if len(a)>len(b): print("YES") else : a.sort() b.sort() i,j=len(a)-1,len(b)-1 while i>=0 : if a[i]>b[j]: print("YES") break i-=1 j-=1 if i==-1 : print("NO") if __name__=='__main__' : day_725() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( day_725() ) else skip; operation day_725() pre: true post: true activity: input() ; var a : Sequence := input().split(" ")->select(v | true)->collect(v | (("" + ((v)))->toInteger())) ; var b : Sequence := input().split(" ")->select(v | true)->collect(v | (("" + ((v)))->toInteger())) ; if ((a)->size()->compareTo((b)->size())) > 0 then ( execute ("YES")->display() ) else ( a := a->sort() ; b := b->sort() ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{(a)->size() - 1,(b)->size() - 1} ; while i >= 0 do ( if (a[i+1]->compareTo(b[j+1])) > 0 then ( execute ("YES")->display() ; break ) else skip ; i := i - 1 ; j := j - 1) ; if i = -1 then ( execute ("NO")->display() ) else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) l=[] for i in range(t): l.append([int(i)for i in input().split()]) def m(s,a,b,c): capa=int(s//c) free=int(capa//a) return(capa+b*free) for i in l : print(m(i[0],i[1],i[2],i[3])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( execute ((input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))) : l)) ; skip ; for i : l do ( execute (m(i->first(), i[1+1], i[2+1], i[3+1]))->display()); operation m(s : OclAny, a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: var capa : int := ("" + ((s div c)))->toInteger() ; var free : int := ("" + ((capa div a)))->toInteger() ; return (capa + b * free); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import os import random import re import sys for _ in range(int(input())): s,a,b,c=list(map(int,input().split())) d=(s//c) x=d//a final=x*b print(d+final) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{s,a,b,c} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : int := (s div c) ; var x : int := d div a ; var final : double := x * b ; execute (d + final)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**5) class Node : def __init__(self): self.val=None self.color=None self.a=[] n=int(input()) nodes=[] for i in range(n): nodes.append(Node()) for i in range(n-1): u,v,w=map(int,input().split()) node1=nodes[u-1] node2=nodes[v-1] node1.val=u node2.val=v node1.a.append([node2,w]) node2.a.append([node1,w]) root=nodes[0] root.color=True nodeSet=set() def traverse(node,distance): if node in nodeSet : return else : nodeSet.add(node) for pair in node.a : adjNode=pair[0] dis=pair[1] if(distance+dis)% 2==0 : adjNode.color=root.color else : adjNode.color=not root.color traverse(adjNode,distance+dis) traverse(root,0) for i in range(n): node=nodes[i] if node.color : print(1) else : print(0) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute val : OclAny := null; attribute color : OclAny := null; attribute a : Sequence := Sequence{}; operation initialise() : Node pre: true post: true activity: self.val := null ; self.color := null ; self.a := Sequence{}; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(5)) ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nodes : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((Node.newNode()).initialise()) : nodes)) ; for i : Integer.subrange(0, n - 1-1) do ( var u : OclAny := null; var v : OclAny := null; var w : OclAny := null; Sequence{u,v,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var node1 : OclAny := nodes[u - 1+1] ; var node2 : OclAny := nodes[v - 1+1] ; node1.val := u ; node2.val := v ; (expr (atom (name node1)) (trailer . (name a)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name node2)))))) , (test (logical_test (comparison (expr (atom (name w))))))) ]))))))) )))) ; (expr (atom (name node2)) (trailer . (name a)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name node1)))))) , (test (logical_test (comparison (expr (atom (name w))))))) ]))))))) ))))) ; var root : OclAny := nodes->first() ; root.color := true ; var nodeSet : Set := Set{}->union(()) ; skip ; traverse(root, 0) ; for i : Integer.subrange(0, n-1) do ( node := nodes[i+1] ; if node.color then ( execute (1)->display() ) else ( execute (0)->display() )); operation traverse(node : OclAny, distance : OclAny) pre: true post: true activity: if (nodeSet)->includes(node) then ( return ) else ( execute ((node) : nodeSet) ) ; for pair : node.a do ( var adjNode : OclAny := pair->first() ; var dis : OclAny := pair[1+1] ; if (distance + dis) mod 2 = 0 then ( adjNode.color := root.color ) else ( adjNode.color := not(root.color) ) ; traverse(adjNode, distance + dis)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): s,a,b,c=map(int,input().split()); print(s//c//a*b+s//c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{s,a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); execute (s div c div a * b + s div c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): s,a,b,c=[int(i)for(i)in input().split()] awcb=s//c ab=(awcb//a)*b print(awcb+ab) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var s : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{s,a,b,c} := input().split()->select((i) | true)->collect((i) | (("" + ((i)))->toInteger())) ; var awcb : int := s div c ; var ab : double := (awcb div a) * b ; execute (awcb + ab)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b,c,d=map(int,input().split()) s=a//d d=(s//b)*c print(s+d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : int := a div d ; var d : double := (s div b) * c ; execute (s + d)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100000 ; prime=[True]*100002 ; def SieveOfEratosthenes(): p=2 ; while(p*p<=MAX): if(prime[p]==True): i=p*2 ; while(i<=MAX): prime[i]=False ; i+=p ; p+=1 ; def superpower(n): SieveOfEratosthenes(); superPower=0 ; factor=0 ; i=2 ; while(n>1 and i<=MAX): if(prime[i]): factor=0 ; while(n % i==0 and n>1): factor+=1 ; n=int(n/i); if(superPowerdisplay();; operation SieveOfEratosthenes() pre: true post: true activity: var p : int := 2; ; while ((p * p->compareTo(MAX)) <= 0) do ( if (prime[p+1] = true) then ( var i : int := p * 2; ; while ((i->compareTo(MAX)) <= 0) do ( prime[i+1] := false; ; i := i + p;) ) else skip ; p := p + 1;); operation superpower(n : OclAny) pre: true post: true activity: SieveOfEratosthenes(); ; var superPower : int := 0; ; var factor : int := 0; ; i := 2; ; while (n > 1 & (i->compareTo(MAX)) <= 0) do ( if (prime[i+1]) then ( factor := 0; ; while (n mod i = 0 & n > 1) do ( factor := factor + 1; ; n := ("" + ((n / i)))->toInteger();) ; if ((superPower->compareTo(factor)) < 0) then ( superPower := factor; ) else skip ) else skip ; i := i + 1;) ; return superPower;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printSubArrays(arr,start,end): if end==len(arr): return elif start>end : return printSubArrays(arr,0,end+1) else : print(arr[start : end+1]) return printSubArrays(arr,start+1,end) arr=[1,2,3] printSubArrays(arr,0,0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; printSubArrays(arr, 0, 0); operation printSubArrays(arr : OclAny, start : OclAny, end : OclAny) pre: true post: true activity: if end = (arr)->size() then ( return ) else (if (start->compareTo(end)) > 0 then ( return printSubArrays(arr, 0, end + 1) ) else ( execute (arr.subrange(start+1, end + 1))->display() ; return printSubArrays(arr, start + 1, end) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isDivisible999(num): n=len(num); if(n==0 or num[0]=='0'): return true if((n % 3)==1): num="00"+num if((n % 3)==2): num="0"+num gSum=0 for i in range(0,n,3): group=0 group+=(ord(num[i])-48)*100 group+=(ord(num[i+1])-48)*10 group+=(ord(num[i+2])-48) gSum+=group if(gSum>1000): num=str(gSum) n=len(num) gSum=isDivisible999(num) return(gSum==999) if __name__=="__main__" : num="1998" n=len(num) if(isDivisible999(num)): print("Divisible") else : print("Not divisible") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( num := "1998" ; n := (num)->size() ; if (isDivisible999(num)) then ( execute ("Divisible")->display() ) else ( execute ("Not divisible")->display() ) ) else skip; operation isDivisible999(num : OclAny) : OclAny pre: true post: true activity: var n : int := (num)->size(); ; if (n = 0 or num->first() = '0') then ( return true ) else skip ; if ((n mod 3) = 1) then ( num := "00" + num ) else skip ; if ((n mod 3) = 2) then ( num := "0" + num ) else skip ; var gSum : int := 0 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 3 = 0 ) do ( var group : int := 0 ; group := group + ((num[i+1])->char2byte() - 48) * 100 ; group := group + ((num[i + 1+1])->char2byte() - 48) * 10 ; group := group + ((num[i + 2+1])->char2byte() - 48) ; gSum := gSum + group) ; if (gSum > 1000) then ( num := ("" + ((gSum))) ; n := (num)->size() ; gSum := isDivisible999(num) ) else skip ; return (gSum = 999); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=lambda : map(int,input().split()) n,k=I() print(max(0,2*n*k-n-2*sum([*I()]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := I->apply() ; execute (Set{0, 2 * n * k - n - 2 * (I->apply())->sum()}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=list(map(int,input().split())) a=list(map(int,input().split())) cnt=0 s=0 for i in a : s+=i while s/n+0.5collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : int := 0 ; var s : int := 0 ; for i : a do ( s := s + i) ; while (s / n + 0.5->compareTo(k)) < 0 do ( s := s + k ; cnt := cnt + 1 ; n := n + 1) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fish(): [n,m,k]=[int(i)for i in input().split(' ')] a=[int(i)for i in input().split(' ')] b=[int(i)for i in input().split(' ')] if len(a)>len(b): print('YES') return a.sort(reverse=True) b.sort(reverse=True) for i in range(len(a)): if a[i]>b[i]: print('YES') return print('NO') if __name__=='__main__' : fish() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( fish() ) else skip; operation fish() pre: true post: true activity: ; Sequence{n}->union(Sequence{m}->union(Sequence{ k })) := input().split(' ')->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a : Sequence := input().split(' ')->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var b : Sequence := input().split(' ')->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if ((a)->size()->compareTo((b)->size())) > 0 then ( execute ('YES')->display() ; return ) else skip ; a := a->sort() ; b := b->sort() ; for i : Integer.subrange(0, (a)->size()-1) do ( if (a[i+1]->compareTo(b[i+1])) > 0 then ( execute ('YES')->display() ; return ) else skip) ; execute ('NO')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split(' ')) m=list(map(int,input().split(' '))) print(max(int((n*k-sum(m))*2-n),0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var m : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; execute (Set{("" + (((n * k - (m)->sum()) * 2 - n)))->toInteger(), 0}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(2000000) input=sys.stdin.readline import heapq N=int(input()) G=[[]for j in range(N)] color=[0]*N for _ in range(N-1): e,f,g=list(map(int,input().split())) heapq.heappush(G[e-1],[f-1,g % 2]) heapq.heappush(G[f-1],[e-1,g % 2]) def dfs(v,p,c): color[v]=c for k in range(len(G[v])): i,j=heapq.heappop(G[v]) if i==p : continue elif j==0 : dfs(i,v,c) elif j==1 : dfs(i,v,1-c) dfs(0,-1,0) for k in color : print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(2000000) ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var G : Sequence := Integer.subrange(0, N-1)->select(j | true)->collect(j | (Sequence{})) ; var color : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for _anon : Integer.subrange(0, N - 1-1) do ( var e : OclAny := null; var f : OclAny := null; var g : OclAny := null; Sequence{e,f,g} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; heapq.heappush(G[e - 1+1], Sequence{f - 1}->union(Sequence{ g mod 2 })) ; heapq.heappush(G[f - 1+1], Sequence{e - 1}->union(Sequence{ g mod 2 }))) ; skip ; dfs(0, -1, 0) ; for k : color do ( execute (k)->display()); operation dfs(v : OclAny, p : OclAny, c : OclAny) pre: true post: true activity: color[v+1] := c ; for k : Integer.subrange(0, (G[v+1])->size()-1) do ( var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := heapq.heappop(G[v+1]) ; if i = p then ( continue ) else (if j = 0 then ( dfs(i, v, c) ) else (if j = 1 then ( dfs(i, v, 1 - c) ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) lst=list(map(int,input().split())) m=0 t=sum(lst) a=t/n while a<(2*k-1)/2 : t+=k n+=1 a=t/n m+=1 lst.append(k) print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := 0 ; var t : OclAny := (lst)->sum() ; var a : double := t / n ; while (a->compareTo((2 * k - 1) / 2)) < 0 do ( t := t + k ; n := n + 1 ; a := t / n ; m := m + 1 ; execute ((k) : lst)) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- in1=input() in2=input() in1=in1.split() in11=int(in1[0]) in12=int(in1[1]) in2=in2.split() s=0 for i in in2 : s+=int(i) n=0 r=((n*in12)+s)/(in11+n) while rfirst())))->toInteger() ; var in12 : int := ("" + ((in1[1+1])))->toInteger() ; in2 := in2.split() ; var s : int := 0 ; for i : in2->characters() do ( s := s + ("" + ((i)))->toInteger()) ; var n : int := 0 ; var r : double := ((n * in12) + s) / (in11 + n) ; while (r->compareTo(in12 - .5)) < 0 do ( n := n + 1 ; r := ((n * in12) + s) / (in11 + n)) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import division def sumOfSeries(a,num): res=0 prev=1 for i in range(1,n+1): prev*=(a/i) res=res+prev return res n=5 a=2 print(round(sumOfSeries(a,n),4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := 5 ; a := 2 ; execute (MathLib.roundN(sumOfSeries(a, n), 4))->display(); operation sumOfSeries(a : OclAny, num : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; var prev : int := 1 ; for i : Integer.subrange(1, n + 1-1) do ( prev := prev * (a / i) ; res := res + prev) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printTheArray(arr,n): for i in range(0,n): print(arr[i],end=" ") print() def generateAllBinaryStrings(n,arr,i): if i==n : printTheArray(arr,n) return arr[i]=0 generateAllBinaryStrings(n,arr,i+1) arr[i]=1 generateAllBinaryStrings(n,arr,i+1) if __name__=="__main__" : n=4 arr=[None]*n generateAllBinaryStrings(n,arr,0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 4 ; arr := MatrixLib.elementwiseMult(Sequence{ null }, n) ; generateAllBinaryStrings(n, arr, 0) ) else skip; operation printTheArray(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()) ; execute (->display(); operation generateAllBinaryStrings(n : OclAny, arr : OclAny, i : OclAny) pre: true post: true activity: if i = n then ( printTheArray(arr, n) ; return ) else skip ; arr[i+1] := 0 ; generateAllBinaryStrings(n, arr, i + 1) ; arr[i+1] := 1 ; generateAllBinaryStrings(n, arr, i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numberSequence(n): num=pow(4,n)-pow(2,n)-1 return num if __name__=="__main__" : n=4 print(numberSequence(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 4 ; execute (numberSequence(n))->display() ) else skip; operation numberSequence(n : OclAny) : OclAny pre: true post: true activity: var num : double := (4)->pow(n) - (2)->pow(n) - 1 ; return num; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def digitProduct(n): prod=1 while(n): prod=prod*(n % 10) n=int(n/10) return prod def printMultiplicativePrimes(n): prime=[True for i in range(n+1)] prime[0]=prime[1]=False for p in range(2,int(sqrt(n))+1,1): if(prime[p]): for i in range(p*2,n+1,p): prime[i]=False for i in range(2,n+1,1): if(prime[i]and prime[digitProduct(i)]): print(i,end=" ") if __name__=='__main__' : n=10 printMultiplicativePrimes(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( n := 10 ; printMultiplicativePrimes(n) ) else skip; operation digitProduct(n : OclAny) : OclAny pre: true post: true activity: var prod : int := 1 ; while (n) do ( prod := prod * (n mod 10) ; n := ("" + ((n / 10)))->toInteger()) ; return prod; operation printMultiplicativePrimes(n : OclAny) pre: true post: true activity: var prime : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (true)) ; prime->first() := false; var prime[1+1] : boolean := false ; for p : Integer.subrange(2, ("" + ((sqrt(n))))->toInteger() + 1-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (prime[p+1]) then ( for i : Integer.subrange(p * 2, n + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip) ; for i : Integer.subrange(2, n + 1-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (prime[i+1] & prime[digitProduct(i)+1]) then ( execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minMoves(arr,n): expectedItem=n for i in range(n-1,-1,-1): if(arr[i]==expectedItem): expectedItem-=1 return expectedItem arr=[4,3,2,1] n=len(arr) print(minMoves(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{4}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 1 }))) ; n := (arr)->size() ; execute (minMoves(arr, n))->display(); operation minMoves(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var expectedItem : OclAny := n ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (arr[i+1] = expectedItem) then ( expectedItem := expectedItem - 1 ) else skip) ; return expectedItem; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def largestGCDSubsequence(arr,n): ans=0 maxele=max(arr) for i in range(2,maxele+1): count=0 for j in range(n): if(arr[j]% i==0): count+=1 ans=max(ans,count) return ans if __name__=='__main__' : arr=[3,6,2,5,4] size=len(arr) print(largestGCDSubsequence(arr,size)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{3}->union(Sequence{6}->union(Sequence{2}->union(Sequence{5}->union(Sequence{ 4 })))) ; var size : int := (arr)->size() ; execute (largestGCDSubsequence(arr, size))->display() ) else skip; operation largestGCDSubsequence(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; var maxele : OclAny := (arr)->max() ; for i : Integer.subrange(2, maxele + 1-1) do ( var count : int := 0 ; for j : Integer.subrange(0, n-1) do ( if (arr[j+1] mod i = 0) then ( count := count + 1 ) else skip) ; ans := Set{ans, count}->max()) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculateSum(n): a1=1 ; a2=2 ; r=2 ; d=1 ; return((n)*(2*a1+(n-1)*d)/2+a2*(pow(r,n)-1)/(r-1)); n=5 ; print("Sum=",int(calculateSum(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5; ; execute ("Sum=")->display(); operation calculateSum(n : OclAny) pre: true post: true activity: var a1 : int := 1; ; var a2 : int := 2; ; var r : int := 2; ; var d : int := 1; ; return ((n) * (2 * a1 + (n - 1) * d) / 2 + a2 * ((r)->pow(n) - 1) / (r - 1));; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from operator import itemgetter from typing import* from collections import deque,Counter,defaultdict from bisect import* import heapq,math from functools import cmp_to_key,reduce from itertools import groupby,islice,zip_longest def main(): n,m,k=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) if n>m : print("YES") else : a.sort(reverse=True) b.sort(reverse=True) for i,it in enumerate(a): if it>b[i]: print("YES") return print("NO") main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; main(); operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (n->compareTo(m)) > 0 then ( execute ("YES")->display() ) else ( a := a->sort() ; b := b->sort() ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var it : OclAny := _tuple->at(_indx); if (it->compareTo(b[i+1])) > 0 then ( execute ("YES")->display() ; return ) else skip) ; execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printPairs(arr,n): v=[] for i in range(n): for j in range(i+1,n): if(abs(arr[i])==abs(arr[j])): v.append(abs(arr[i])) if(len(v)==0): return ; v.sort() for i in range(len(v)): print(-v[i],"",v[i],end=" ") if __name__=="__main__" : arr=[4,8,9,-4,1,-1,-8,-9] n=len(arr) printPairs(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{4}->union(Sequence{8}->union(Sequence{9}->union(Sequence{-4}->union(Sequence{1}->union(Sequence{-1}->union(Sequence{-8}->union(Sequence{ -9 }))))))) ; n := (arr)->size() ; printPairs(arr, n) ) else skip; operation printPairs(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var v : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if ((arr[i+1])->abs() = (arr[j+1])->abs()) then ( execute (((arr[i+1])->abs()) : v) ) else skip)) ; if ((v)->size() = 0) then ( return; ) else skip ; v := v->sort() ; for i : Integer.subrange(0, (v)->size()-1) do ( execute (-v[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count(str1,str2): c=0 ; j=0 ; for i in range(len(str1)): if str1[i]in str2 : c+=1 ; j+=1 ; print("No.of matching characters are: ",c); if __name__=="__main__" : str1="aabcddekll12@" ; str2="bb2211@55k" ; count(str1,str2); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( str1 := "aabcddekll12@"; ; str2 := "bb2211@55k"; ; count(str1, str2); ) else skip; operation count(str1 : OclAny, str2 : OclAny) pre: true post: true activity: var c : int := 0; var j : int := 0; ; for i : Integer.subrange(0, (str1)->size()-1) do ( if (str2)->includes(str1[i+1]) then ( c := c + 1; ) else skip ; j := j + 1;) ; execute ("No.of matching characters are: ")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n=int(input()) s=input()[:-1] c1,c2,d,e=0,0,0,0 for i in range(n-1): if s[i]=='-' : if d==0 : e+=2 else : e+=1 d=1 elif s[i]=='>' : c1=1 d=0 else : c2=1 d=0 if s[-1]=='-' : e+=2 if s[-2]=='-' : e-=1 if s[0]=='-' : e-=1 elif s[-1]=='>' : c1=1 else : c2=1 if c1==0 or c2==0 : print(n) else : print(e) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := input()->front() ; var c1 : OclAny := null; var c2 : OclAny := null; var d : OclAny := null; var e : OclAny := null; Sequence{c1,c2,d,e} := Sequence{0,0,0,0} ; for i : Integer.subrange(0, n - 1-1) do ( if s[i+1] = '-' then ( if d = 0 then ( e := e + 2 ) else ( e := e + 1 ) ; var d : int := 1 ) else (if s[i+1] = '>' then ( var c1 : int := 1 ; d := 0 ) else ( var c2 : int := 1 ; d := 0 ) ) ) ; if s->last() = '-' then ( e := e + 2 ; if s->front()->last() = '-' then ( e := e - 1 ) else skip ; if s->first() = '-' then ( e := e - 1 ) else skip ) else (if s->last() = '>' then ( c1 := 1 ) else ( c2 := 1 ) ) ; if c1 = 0 or c2 = 0 then ( execute (n)->display() ) else ( execute (e)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): n,s,r=int(input()),input(),0 if 0 in(s.count('>'),s.count('<')): print(n) continue for i in range(n): if '-' in(s[i],s[(i+1)% n]): r+=1 print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var s : OclAny := null; var r : OclAny := null; Sequence{n,s,r} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),(OclFile["System.in"]).readLine(),0} ; if (Sequence{s->count('>'), s->count('<')})->includes(0) then ( execute (n)->display() ; continue ) else skip ; for i : Integer.subrange(0, n-1) do ( if (Sequence{s[i+1], s[(i + 1) mod n+1]})->includes('-') then ( r := r + 1 ) else skip) ; execute (r)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) s=input().rstrip() c=d=e=0 for i in range(n): if s[i]=='<' : c+=1 elif s[i]=='>' : d+=1 else : e+=1 if c==0 or d==0 : print(n) else : if e==0 : print(0) else : e=0 s+=s[0] for i in range(n): if s[i]=='-' : if s[i+1]=='-' : e+=1 else : e+=2 print(e) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := input().rstrip() ; c := c(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name e)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = '<' then ( c := c + 1 ) else (if s[i+1] = '>' then ( d := d + 1 ) else ( e := e + 1 ) ) ) ; if c = 0 or d = 0 then ( execute (n)->display() ) else ( if e = 0 then ( execute (0)->display() ) else ( var e : int := 0 ; s := s + s->first() ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = '-' then ( if s[i + 1+1] = '-' then ( e := e + 1 ) else ( e := e + 2 ) ) else skip) ; execute (e)->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math alfabet={'a' : 1,'b' : 2,'c' : 3,'d' : 4,'e' : 5,'f' : 6,'g' : 7,'h' : 8,'i' : 9,'j' : 10,'k' : 11,'l' : 12,'m' : 13,'n' : 14,'o' : 15,'p' : 16,'q' : 17,'r' : 18,'s' : 19,'t' : 20,'u' : 21,'v' : 22,'w' : 23,'x' : 24,'y' : 25,'z' : 26} alfabet_2={'1' : "a",'2' : "b",'3' : "c",'4' : "d",'5' : "e",'6' : "f",'7' : "g",'8' : "h",'9' : "i",'10' : "j",'11' : "k",'12' : "l",'13' : "m",'14' : "n",'15' : "o",'16' : "p",'17' : "q",'18' : "r",'19' : "s",'20' : "t",'21' : "u",'22' : "v",'23' : "w",'24' : "x",'25' : "y",'26' : "z"} contor=1 my_dict={} for j in range(1,27): for i in range(1,27): if i!=j : element=alfabet_2[str(j)]+alfabet_2[str(i)] my_dict[element]=contor contor+=1 z=int(input()) for i in range(z): n=int(input()) stringul=input() my_set=set() blocaj=0 if ">" in stringul and "<" in stringul : blocaj=1 if stringul[n-1]=='-' : my_set.add(0) my_set.add(n-1) for i in range(0,n-1): if stringul[i]=='-' : my_set.add(i) my_set.add(i+1) if blocaj==0 : print(n) else : print(len(my_set)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var alfabet : Map := Map{ 'a' |-> 1 }->union(Map{ 'b' |-> 2 }->union(Map{ 'c' |-> 3 }->union(Map{ 'd' |-> 4 }->union(Map{ 'e' |-> 5 }->union(Map{ 'f' |-> 6 }->union(Map{ 'g' |-> 7 }->union(Map{ 'h' |-> 8 }->union(Map{ 'i' |-> 9 }->union(Map{ 'j' |-> 10 }->union(Map{ 'k' |-> 11 }->union(Map{ 'l' |-> 12 }->union(Map{ 'm' |-> 13 }->union(Map{ 'n' |-> 14 }->union(Map{ 'o' |-> 15 }->union(Map{ 'p' |-> 16 }->union(Map{ 'q' |-> 17 }->union(Map{ 'r' |-> 18 }->union(Map{ 's' |-> 19 }->union(Map{ 't' |-> 20 }->union(Map{ 'u' |-> 21 }->union(Map{ 'v' |-> 22 }->union(Map{ 'w' |-> 23 }->union(Map{ 'x' |-> 24 }->union(Map{ 'y' |-> 25 }->union(Map{ 'z' |-> 26 }))))))))))))))))))))))))) ; var alfabet:= Map{ '1' |-> "a" }->union(Map{ '2' |-> "b" }->union(Map{ '3' |-> "c" }->union(Map{ '4' |-> "d" }->union(Map{ '5' |-> "e" }->union(Map{ '6' |-> "f" }->union(Map{ '7' |-> "g" }->union(Map{ '8' |-> "h" }->union(Map{ '9' |-> "i" }->union(Map{ '10' |-> "j" }->union(Map{ '11' |-> "k" }->union(Map{ '12' |-> "l" }->union(Map{ '13' |-> "m" }->union(Map{ '14' |-> "n" }->union(Map{ '15' |-> "o" }->union(Map{ '16' |-> "p" }->union(Map{ '17' |-> "q" }->union(Map{ '18' |-> "r" }->union(Map{ '19' |-> "s" }->union(Map{ '20' |-> "t" }->union(Map{ '21' |-> "u" }->union(Map{ '22' |-> "v" }->union(Map{ '23' |-> "w" }->union(Map{ '24' |-> "x" }->union(Map{ '25' |-> "y" }->union(Map{ '26' |-> "z" }))))))))))))))))))))))))) : Map := Map{ '1' |-> "a" }->union(Map{ '2' |-> "b" }->union(Map{ '3' |-> "c" }->union(Map{ '4' |-> "d" }->union(Map{ '5' |-> "e" }->union(Map{ '6' |-> "f" }->union(Map{ '7' |-> "g" }->union(Map{ '8' |-> "h" }->union(Map{ '9' |-> "i" }->union(Map{ '10' |-> "j" }->union(Map{ '11' |-> "k" }->union(Map{ '12' |-> "l" }->union(Map{ '13' |-> "m" }->union(Map{ '14' |-> "n" }->union(Map{ '15' |-> "o" }->union(Map{ '16' |-> "p" }->union(Map{ '17' |-> "q" }->union(Map{ '18' |-> "r" }->union(Map{ '19' |-> "s" }->union(Map{ '20' |-> "t" }->union(Map{ '21' |-> "u" }->union(Map{ '22' |-> "v" }->union(Map{ '23' |-> "w" }->union(Map{ '24' |-> "x" }->union(Map{ '25' |-> "y" }->union(Map{ '26' |-> "z" }))))))))))))))))))))))))) ; var contor : int := 1 ; var my_dict : OclAny := Set{} ; for j : Integer.subrange(1, 27-1) do ( for i : Integer.subrange(1, 27-1) do ( if i /= j then ( var element : OclAny := alfabetalfabet_2[("" + ((i)))+1][("" + ((j)))+1] + alfabet_2[("" + ((i)))+1] ; my_dict[element+1] := contor ; contor := contor + 1 ) else skip)) ; var z : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, z-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var stringul : String := (OclFile["System.in"]).readLine() ; var my_set : Set := Set{}->union(()) ; var blocaj : int := 0 ; if (stringul)->characters()->includes(">") & (stringul)->characters()->includes("<") then ( blocaj := 1 ) else skip ; if stringul[n - 1+1] = '-' then ( execute ((0) : my_set) ; execute ((n - 1) : my_set) ) else skip ; for i : Integer.subrange(0, n - 1-1) do ( if stringul[i+1] = '-' then ( execute ((i) : my_set) ; execute ((i + 1) : my_set) ) else skip) ; if blocaj = 0 then ( execute (n)->display() ) else ( execute ((my_set)->size())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as m i=input() inp=[] for a in range(0,int(i)): input() inp+=[input()] for s in inp : n=len(s) M='<' not in s A='>' not in s c=0 in_pointer=-1 out_pointer=0 for k in range(n): i=s[in_pointer] o=s[out_pointer] if i=='-' or o=='-' : c+=1 elif o=='>' : c+=M elif i=='<' : c+=A in_pointer+=1 out_pointer+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var i : String := (OclFile["System.in"]).readLine() ; var inp : Sequence := Sequence{} ; for a : Integer.subrange(0, ("" + ((i)))->toInteger()-1) do ( input() ; inp := inp + Sequence{ (OclFile["System.in"]).readLine() }) ; for s : inp do ( var n : int := (s)->size() ; var M : boolean := (s)->excludes('<') ; var A : boolean := (s)->excludes('>') ; var c : int := 0 ; var in_pointer : int := -1 ; var out_pointer : int := 0 ; for k : Integer.subrange(0, n-1) do ( i := s[in_pointer+1] ; var o : OclAny := s[out_pointer+1] ; if i = '-' or o = '-' then ( c := c + 1 ) else (if o = '>' then ( c := c + M ) else (if i = '<' then ( c := c + A ) else skip ) ) ; in_pointer := in_pointer + 1 ; out_pointer := out_pointer + 1) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for p in range(int(input())): n=int(input()) a=list(map(int,input().split())) x=a.count(0) y=a.count(1) if x>=n//2 : print(x) print(*([0]*x)) else : d=y-(y % 2) print(d) print(*([1]*d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for p : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : int := a->count(0) ; var y : int := a->count(1) ; if (x->compareTo(n div 2)) >= 0 then ( execute (x)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr (atom (name x)))))))) ))))))))->display() ) else ( var d : double := y - (y mod 2) ; execute (d)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1)))))))) ])) * (expr (atom (name d)))))))) ))))))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a=int(input()) b=list(map(int,input().split())) c=b.count(0) if c>=a//2 : print(c) print(*[0 for i in range(c)]) else : print((a-c)-((a-c)% 2)) print(*[1 for i in range((a-c)-((a-c)% 2))]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := b->count(0) ; if (c->compareTo(a div 2)) >= 0 then ( execute (c)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))))))) ])))))))->display() ) else ( execute ((a - c) - ((a - c) mod 2))->display() ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (name c)))))))) ))) - (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (name c)))))))) ))) % (expr (atom (number (integer 2))))))))) ))))))))) )))))))) ])))))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a=int(input()) b=list(map(int,input().split())) c=b.count(0) if c>=a//2 : print(c) print(*[0 for i in range(c)]) else : print((a-c)-((a-c)% 2)) print(*[1 for i in range((a-c)-((a-c)% 2))]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := b->count(0) ; if (c->compareTo(a div 2)) >= 0 then ( execute (c)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))))))) ])))))))->display() ) else ( execute ((a - c) - ((a - c) mod 2))->display() ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (name c)))))))) ))) - (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (name c)))))))) ))) % (expr (atom (number (integer 2))))))))) ))))))))) )))))))) ])))))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- iter=int(input()) for _ in range(iter): n=int(input()) a=list(map(int,input().split(' '))) count=0 for i in range(n): if(a[i]==0): count+=1 if(count>=n//2): print(count) print('0 '*(count)) else : if(count & 1): print(n-count-1) print('1 '*(n-count-1)) else : print(n-count) print('1 '*(n-count)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var iter : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, iter-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] = 0) then ( count := count + 1 ) else skip) ; if ((count->compareTo(n div 2)) >= 0) then ( execute (count)->display() ; execute (StringLib.nCopies('0 ', (count)))->display() ) else ( if (MathLib.bitwiseAnd(count, 1)) then ( execute (n - count - 1)->display() ; execute (StringLib.nCopies('1 ', (n - count - 1)))->display() ) else ( execute (n - count)->display() ; execute (StringLib.nCopies('1 ', (n - count)))->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for p in range(t): n,x,m=map(int,input().split()) L=x R=x for i in range(m): l,r=(map(int,input().split())) if l<=R and r>=L : L=min(L,l) R=max(R,r) print(R-L+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for p : Integer.subrange(0, t-1) do ( var n : OclAny := null; var x : OclAny := null; var m : OclAny := null; Sequence{n,x,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var L : OclAny := x ; var R : OclAny := x ; for i : Integer.subrange(0, m-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (l->compareTo(R)) <= 0 & (r->compareTo(L)) >= 0 then ( L := Set{L, l}->min() ; R := Set{R, r}->max() ) else skip) ; execute (R - L + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def doublefactorial(n): if(n==0 or n==1): return 1 ; return n*doublefactorial(n-2); print("Double factorial is",doublefactorial(5)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute ("Double factorial is")->display();; operation doublefactorial(n : OclAny) pre: true post: true activity: if (n = 0 or n = 1) then ( return 1; ) else skip ; return n * doublefactorial(n - 2);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq tbl=[] N=int(input()) for i in range(N): a,b=map(int,input().split()) tbl.append((a,b)) tbl.sort() Q=[] ans=s=sz=0 for t in tbl : s+=t[0] heapq.heappush(Q,(t[1],t[0])) sz+=1 while sz and sz*Q[0][0]ans : ans=sz print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var tbl : Sequence := Sequence{} ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, N-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a, b}) : tbl)) ; tbl := tbl->sort() ; var Q : Sequence := Sequence{} ; ans := ans(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sz)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for t : tbl do ( s := s + t->first() ; heapq.heappush(Q, Sequence{t[1+1], t->first()}) ; sz := sz + 1 ; while sz & (sz * Q->first()->first()->compareTo(s)) < 0 do ( s := s - Q->first()[1+1] ; heapq.heappop(Q) ; sz := sz - 1) ; if (sz->compareTo(ans)) > 0 then ( var ans : OclAny := sz ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.buffer.readline def process(A): n=len(A) d=[0,0] for i in range(n): ai=A[i] d[ai]+=1 if d[0]>=n//2 : answer=[] for i in range(n//2): answer.append(0) sys.stdout.write(f'{len(answer)}\n') answer=' '.join(map(str,answer)) sys.stdout.write(f'{answer}\n') else : m=d[1] m=m-(m % 2) answer=[] for i in range(m): answer.append(1) sys.stdout.write(f'{m}\n') answer=' '.join(map(str,answer)) sys.stdout.write(f'{answer}\n') t=int(input()) for i in range(t): n=int(input()) A=[int(x)for x in input().split()] process(A) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := sys.stdin.buffer.readline ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; A := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; process(A)); operation process(A : OclAny) pre: true post: true activity: var n : int := (A)->size() ; var d : Sequence := Sequence{0}->union(Sequence{ 0 }) ; for i : Integer.subrange(0, n-1) do ( var ai : OclAny := A[i+1] ; d[ai+1] := d[ai+1] + 1) ; if (d->first()->compareTo(n div 2)) >= 0 then ( var answer : Sequence := Sequence{} ; for i : Integer.subrange(0, n div 2-1) do ( execute ((0) : answer)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom f '{len(answer)} '))))))) )))) ; answer := StringLib.sumStringsWithSeparator(((answer)->collect( _x | (OclType["String"])->apply(_x) )), ' ') ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom f '{answer} '))))))) )))) ) else ( var m : OclAny := d[1+1] ; m := m - (m mod 2) ; answer := Sequence{} ; for i : Integer.subrange(0, m-1) do ( execute ((1) : answer)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom f '{m} '))))))) )))) ; answer := StringLib.sumStringsWithSeparator(((answer)->collect( _x | (OclType["String"])->apply(_x) )), ' ') ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom f '{answer} '))))))) )))) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def MinimumX(a,b,c,k): x=10**9 if(k<=c): return 0 h=k-c l=0 while(l<=h): m=(l+h)//2 if((a*m*m)+(b*m)>(k-c)): x=min(x,m) h=m-1 elif((a*m*m)+(b*m)<(k-c)): l=m+1 else : return m return x a,b,c,k=3,2,4,15 print(MinimumX(a,b,c,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{a,b,c,k} := Sequence{3,2,4,15} ; execute (MinimumX(a, b, c, k))->display(); operation MinimumX(a : OclAny, b : OclAny, c : OclAny, k : OclAny) : OclAny pre: true post: true activity: var x : double := (10)->pow(9) ; if ((k->compareTo(c)) <= 0) then ( return 0 ) else skip ; var h : double := k - c ; var l : int := 0 ; while ((l->compareTo(h)) <= 0) do ( var m : int := (l + h) div 2 ; if (((a * m * m) + (b * m)->compareTo((k - c))) > 0) then ( x := Set{x, m}->min() ; h := m - 1 ) else (if (((a * m * m) + (b * m)->compareTo((k - c))) < 0) then ( l := m + 1 ) else ( return m ) ) ) ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minLettersNeeded(n): if n % 26==0 : return(n//26) else : return((n//26)+1) n=52 print(minLettersNeeded(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 52 ; execute (minLettersNeeded(n))->display(); operation minLettersNeeded(n : OclAny) : OclAny pre: true post: true activity: if n mod 26 = 0 then ( return (n div 26) ) else ( return ((n div 26) + 1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) k1=k s=input() A=[0 for i in range(26)] for i in range(n): A[ord(s[i])-ord('a')]+=1 sch=0 otv='' while A[sch]!=0 and len(otv)!=k1 : if schtoInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k1 : OclAny := k ; var s : String := (OclFile["System.in"]).readLine() ; var A : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( A[(s[i+1])->char2byte() - ('a')->char2byte()+1] := A[(s[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; var sch : int := 0 ; var otv : String := '' ; while A[sch+1] /= 0 & (otv)->size() /= k1 do ( if (sch->compareTo(n div k1)) < 0 then ( otv := otv + (sch + ('a')->char2byte())->byte2char() * (Set{0, k - A[sch+1]}->max()) ) else ( break ) ; var k : OclAny := Set{k, A[sch+1]}->min() ; sch := sch + 1) ; otv := otv + (sch + ('a')->char2byte())->byte2char() * (k1 - (otv)->size()) ; execute (otv(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) while T : n,k=list(map(int,input().split())) string=input() freq=[0]*26 for ch in string : freq[ord(ch)-ord('a')]+=1 bps=n//k ans="" for i in range(k): first_zero=freq.index(0) till=min(bps,first_zero) ans+=chr(97+till) for j in range(till): freq[j]-=1 print(ans) T-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while T do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var string : String := (OclFile["System.in"]).readLine() ; var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for ch : string->characters() do ( freq[(ch)->char2byte() - ('a')->char2byte()+1] := freq[(ch)->char2byte() - ('a')->char2byte()+1] + 1) ; var bps : int := n div k ; var ans : String := "" ; for i : Integer.subrange(0, k-1) do ( var first_zero : int := freq->indexOf(0) - 1 ; var till : OclAny := Set{bps, first_zero}->min() ; ans := ans + (97 + till)->byte2char() ; for j : Integer.subrange(0, till-1) do ( freq[j+1] := freq[j+1] - 1)) ; execute (ans)->display() ; T := T - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,k,s): dct={} for i in range(n): if s[i]not in dct : dct[s[i]]=1 else : dct[s[i]]+=1 if 'a' not in dct : return('a'*k) res='' lim=n//k j=1 while len(res)=j and utoInteger() ; var abc : Sequence := ('abcdefghijklmnopqrstuvwxyz')->characters() ; while (t) do ( t := t - 1 ; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; s := (OclFile["System.in"]).readLine() ; execute (solve(n, k, s))->display()); operation solve(n : OclAny, k : OclAny, s : OclAny) : OclAny pre: true post: true activity: var dct : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( if (dct)->excludes(s[i+1]) then ( dct[s[i+1]+1] := 1 ) else ( dct[s[i+1]+1] := dct[s[i+1]+1] + 1 )) ; if (dct)->excludes('a') then ( return (StringLib.nCopies('a', k)) ) else skip ; var res : String := '' ; var lim : int := n div k ; var j : int := 1 ; while ((res)->size()->compareTo(k)) < 0 do ( var u : int := 0 ; while (dct)->includes(abc[u+1]) & (dct[abc[u+1]+1]->compareTo(j)) >= 0 & (u->compareTo(lim)) < 0 do ( u := u + 1) ; res := res + abc[u+1] ; j := j + 1) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n,k=map(int,input().split()) s=input() dp=[0]*26 for i in range(n): dp[ord(s[i])-97]+=1 ans=str() for i in range(k): cnt=0 while cnt0 : dp[cnt]-=1 ; cnt+=1 ans+=chr(97+cnt) print(ans) for _ in range(int(input())): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve()); operation solve() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for i : Integer.subrange(0, n-1) do ( dp[(s[i+1])->char2byte() - 97+1] := dp[(s[i+1])->char2byte() - 97+1] + 1) ; var ans : String := ("" + (())) ; for i : Integer.subrange(0, k-1) do ( var cnt : int := 0 ; while (cnt->compareTo(n / k)) < 0 & dp[cnt+1] > 0 do ( dp[cnt+1] := dp[cnt+1] - 1; cnt := cnt + 1) ; ans := ans + (97 + cnt)->byte2char()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=list(map(int,input().split())) vasya=max((b*3)/10,b-(b/250)*d) Misha=max((a*3)/10,a-(a/250)*c) if vasya==Misha : print("Tie") elif vasya>Misha : print("Vasya") else : print("Misha") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var vasya : OclAny := Set{(b * 3) / 10, b - (b / 250) * d}->max() ; var Misha : OclAny := Set{(a * 3) / 10, a - (a / 250) * c}->max() ; if vasya = Misha then ( execute ("Tie")->display() ) else (if (vasya->compareTo(Misha)) > 0 then ( execute ("Vasya")->display() ) else ( execute ("Misha")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=map(int,input().split()) m=max((3*a)//10,a-((a//250)*c)) v=max((3*b)//10,b-((b//250)*d)) if m>v : print('Misha') elif mcollect( _x | (OclType["int"])->apply(_x) ) ; var m : OclAny := Set{(3 * a) div 10, a - ((a div 250) * c)}->max() ; var v : OclAny := Set{(3 * b) div 10, b - ((b div 250) * d)}->max() ; if (m->compareTo(v)) > 0 then ( execute ('Misha')->display() ) else (if (m->compareTo(v)) < 0 then ( execute ('Vasya')->display() ) else ( execute ('Tie')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPalindrome(str): l=0 h=len(str)-1 while(h>l): if(str[l]!=str[h]): return 0 l=l+1 h=h-1 return 1 def minRemovals(str): if(str[0]==''): return 0 if(isPalindrome(str)): return 1 return 2 print(minRemovals("010010")) print(minRemovals("0100101")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; execute (minRemovals("010010"))->display() ; execute (minRemovals("0100101"))->display(); operation isPalindrome(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var l : int := 0 ; var h : double := (OclType["String"])->size() - 1 ; while ((h->compareTo(l)) > 0) do ( if (("" + ([l+1])) /= ("" + ([h+1]))) then ( return 0 ) else skip ; l := l + 1 ; h := h - 1) ; return 1; operation minRemovals(OclType["String"] : OclAny) : OclAny pre: true post: true activity: if (("" + (->first())) = '') then ( return 0 ) else skip ; if (isPalindrome(OclType["String"])) then ( return 1 ) else skip ; return 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=map(int,input().split(" ")) misha=max((3*a/10),(a-(a*c/250))) vasya=max((3*b/10),(b-(b*d/250))) if misha>vasya : print("Misha") elif mishacollect( _x | (OclType["int"])->apply(_x) ) ; var misha : OclAny := Set{(3 * a / 10), (a - (a * c / 250))}->max() ; var vasya : OclAny := Set{(3 * b / 10), (b - (b * d / 250))}->max() ; if (misha->compareTo(vasya)) > 0 then ( execute ("Misha")->display() ) else (if (misha->compareTo(vasya)) < 0 then ( execute ("Vasya")->display() ) else ( execute ("Tie")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxDivide(a,b): while a % b==0 : a=a/b return a def isUgly(no): no=maxDivide(no,2) no=maxDivide(no,3) no=maxDivide(no,5) return 1 if no==1 else 0 def getNthUglyNo(n): i=1 count=1 while n>count : i+=1 if isUgly(i): count+=1 return i no=getNthUglyNo(150) print("150th ugly no.is ",no) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; no := getNthUglyNo(150) ; execute ("150th ugly no.is ")->display(); operation maxDivide(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: while a mod b = 0 do ( a := a / b) ; return a; operation isUgly(no : OclAny) : OclAny pre: true post: true activity: no := maxDivide(no, 2) ; no := maxDivide(no, 3) ; no := maxDivide(no, 5) ; return if no = 1 then 1 else 0 endif; operation getNthUglyNo(n : OclAny) : OclAny pre: true post: true activity: var i : int := 1 ; var count : int := 1 ; while (n->compareTo(count)) > 0 do ( i := i + 1 ; if isUgly(i) then ( count := count + 1 ) else skip) ; return i; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p1,p2,t1,t2=map(int,input().split()) sc1=max(0.3*p1,p1-(0.004*p1*t1)) sc2=max(0.3*p2,p2-(0.004*p2*t2)) if sc1>sc2 : print("Misha") elif sc2>sc1 : print("Vasya") else : print("Tie") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p1 : OclAny := null; var p2 : OclAny := null; var t1 : OclAny := null; var t2 : OclAny := null; Sequence{p1,p2,t1,t2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sc1 : OclAny := Set{0.3 * p1, p1 - (0.004 * p1 * t1)}->max() ; var sc2 : OclAny := Set{0.3 * p2, p2 - (0.004 * p2 * t2)}->max() ; if (sc1->compareTo(sc2)) > 0 then ( execute ("Misha")->display() ) else (if (sc2->compareTo(sc1)) > 0 then ( execute ("Vasya")->display() ) else ( execute ("Tie")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): a,b,c,d=map(int,input().split()) misha=max(3*a/10,a-(a*c)/250) vasya=max(3*b/10,b-(b*d)/250) if misha>vasya : print("Misha") if mishacollect( _x | (OclType["int"])->apply(_x) ) ; var misha : OclAny := Set{3 * a / 10, a - (a * c) / 250}->max() ; var vasya : OclAny := Set{3 * b / 10, b - (b * d) / 250}->max() ; if (misha->compareTo(vasya)) > 0 then ( execute ("Misha")->display() ) else skip ; if (misha->compareTo(vasya)) < 0 then ( execute ("Vasya")->display() ) else skip ; if misha = vasya then ( execute ("Tie")->display() ) else skip; operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from itertools import product MOD=1000000007 def solve(N : int,K : int): if K % 2==1 : print(0) return dp=[[[0 for k in range(K+1)]for j in range(N+2)]for i in range(N+1)] dp[0][0][0]=1 for i,j,k in product(range(1,N+1),range(N+1),range(K+1)): prev_k=k-2*j if prev_k<0 : continue dp[i][j][k]+=dp[i-1][j][prev_k] dp[i][j][k]+=2*j*dp[i-1][j][prev_k] dp[i][j][k]+=(j+1)*(j+1)*dp[i-1][j+1][prev_k] if j>0 : dp[i][j][k]+=dp[i-1][j-1][prev_k] dp[i][j][k]%=MOD print(dp[N][0][K]) return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() n=int(next(tokens)) k=int(next(tokens)) solve(n,k) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var MOD : int := 1000000007 ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(N : int, K : int) pre: true post: true activity: if K mod 2 = 1 then ( execute (0)->display() ; return ) else skip ; var dp : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, N + 2-1)->select(j | true)->collect(j | (Integer.subrange(0, K + 1-1)->select(k | true)->collect(k | (0)))))) ; dp->first()->first()->first() := 1 ; for _tuple : product(Integer.subrange(1, N + 1-1), Integer.subrange(0, N + 1-1), Integer.subrange(0, K + 1-1)) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var k : OclAny := _tuple->at(_indx); var prev_k : double := k - 2 * j ; if prev_k < 0 then ( continue ) else skip ; dp[i+1][j+1][k+1] := dp[i+1][j+1][k+1] + dp[i - 1+1][j+1][prev_k+1] ; dp[i+1][j+1][k+1] := dp[i+1][j+1][k+1] + 2 * j * dp[i - 1+1][j+1][prev_k+1] ; dp[i+1][j+1][k+1] := dp[i+1][j+1][k+1] + (j + 1) * (j + 1) * dp[i - 1+1][j + 1+1][prev_k+1] ; if j > 0 then ( dp[i+1][j+1][k+1] := dp[i+1][j+1][k+1] + dp[i - 1+1][j - 1+1][prev_k+1] ) else skip ; dp[i+1][j+1][k+1] := dp[i+1][j+1][k+1] mod MOD) ; execute (dp[N+1]->first()[K+1])->display() ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var n : int := ("" + (((tokens).next())))->toInteger() ; var k : int := ("" + (((tokens).next())))->toInteger() ; solve(n, k); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) scr=10000 dp=[[[0]*(n+1)for i in range(scr)]for j in range(n+1)] dp[0][0][0]=1 mod=10**9+7 for i in range(0,n): for nsc in range(-scr//2,scr//2): for x in range(n): nownum=i+1 dp[i+1][nsc][x]+=dp[i][nsc][x] dp[i+1][nsc][x]%=mod if x>0 : dp[i+1][(nsc+2*nownum)% scr][x-1]+=dp[i][nsc][x]*x*x dp[i+1][(nsc+2*nownum)% scr][x-1]%=mod if x>0 : dp[i+1][nsc][x]+=dp[i][nsc][x]*x dp[i+1][nsc][x]%=mod if x>0 : dp[i+1][nsc][x]+=dp[i][nsc][x]*x dp[i+1][nsc][x]%=mod if xcollect( _x | (OclType["int"])->apply(_x) ) ; var scr : int := 10000 ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, scr-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)))))) ; dp->first()->first()->first() := 1 ; var mod : double := (10)->pow(9) + 7 ; for i : Integer.subrange(0, n-1) do ( for nsc : Integer.subrange(-scr div 2, scr div 2-1) do ( for x : Integer.subrange(0, n-1) do ( var nownum : OclAny := i + 1 ; dp[i + 1+1][nsc+1][x+1] := dp[i + 1+1][nsc+1][x+1] + dp[i+1][nsc+1][x+1] ; dp[i + 1+1][nsc+1][x+1] := dp[i + 1+1][nsc+1][x+1] mod mod ; if x > 0 then ( dp[i + 1+1][(nsc + 2 * nownum) mod scr+1][x - 1+1] := dp[i + 1+1][(nsc + 2 * nownum) mod scr+1][x - 1+1] + dp[i+1][nsc+1][x+1] * x * x ; dp[i + 1+1][(nsc + 2 * nownum) mod scr+1][x - 1+1] := dp[i + 1+1][(nsc + 2 * nownum) mod scr+1][x - 1+1] mod mod ) else skip ; if x > 0 then ( dp[i + 1+1][nsc+1][x+1] := dp[i + 1+1][nsc+1][x+1] + dp[i+1][nsc+1][x+1] * x ; dp[i + 1+1][nsc+1][x+1] := dp[i + 1+1][nsc+1][x+1] mod mod ) else skip ; if x > 0 then ( dp[i + 1+1][nsc+1][x+1] := dp[i + 1+1][nsc+1][x+1] + dp[i+1][nsc+1][x+1] * x ; dp[i + 1+1][nsc+1][x+1] := dp[i + 1+1][nsc+1][x+1] mod mod ) else skip ; if (x->compareTo(n)) < 0 then ( dp[i + 1+1][(nsc - 2 * nownum) mod scr+1][x + 1+1] := dp[i + 1+1][(nsc - 2 * nownum) mod scr+1][x + 1+1] + dp[i+1][nsc+1][x+1] ; dp[i + 1+1][(nsc - 2 * nownum) mod scr+1][x + 1+1] := dp[i + 1+1][(nsc - 2 * nownum) mod scr+1][x + 1+1] mod mod ) else skip))) ; execute (dp[n+1][k+1]->first() mod mod)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- 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,K=map(int,read().split()) L=N*(N-1)//2+1 dp=np.zeros((N,L),dtype=np.int64) dp[0,0]=1 for _ in range(1,N+1): prev=dp dp=np.zeros_like(prev) for n in range(N): x=prev[n] dp[n,n :]+=x[: L-n]*(n+n+1) if n>0 : dp[n-1,n-1 :]+=x[: L-n+1]*n if n+1pow(9) + 7 ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (read().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var L : int := N * (N - 1) div 2 + 1 ; var dp : Sequence := MatrixLib.singleValueMatrix(Sequence{N, L}, 0.0) ; dp->first()->first() := 1 ; for _anon : Integer.subrange(1, N + 1-1) do ( var prev : Sequence := dp ; dp := MatrixLib.singleValueMatrix(MatrixLib.shape(prev), 0.0) ; for n : Integer.subrange(0, N-1) do ( var x : OclAny := prev[n+1] ; dp[n+1].subrange(n+1) := dp[n+1].subrange(n+1) + x.subrange(1,L - n) * (n + n + 1) ; if n > 0 then ( dp[n - 1+1].subrange(n - 1+1) := dp[n - 1+1].subrange(n - 1+1) + x.subrange(1,L - n + 1) * n ) else skip ; if (n + 1->compareTo(N)) < 0 then ( dp[n + 1+1].subrange(n + 1+1) := dp[n + 1+1].subrange(n + 1+1) + x.subrange(1,L - n - 1) * (n + 1) ) else skip) ; dp := dp mod MOD) ; x := dp->first() ; if MathLib.bitwiseAnd(K, 1) then ( var answer : int := 0 ) else (if (K div 2->compareTo(L)) < 0 then ( answer := x[K div 2+1] ) else ( answer := 0 ) ) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) dp={} dp[(0,0,0)]=1 def perm(i,j,k): if(i,j,k)in dp : return dp[(i,j,k)] if i==0 : if k==0 and j==0 : return 1 else : return 0 elif k<0 or j<0 or icollect( _x | (OclType["int"])->apply(_x) ) ; var dp : OclAny := Set{} ; dp[Sequence{0, 0, 0}+1] := 1 ; skip ; execute (perm(n, 0, k))->display(); operation perm(i : OclAny, j : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (dp)->includes(Sequence{i, j, k}) then ( return dp[Sequence{i, j, k}+1] ) else skip ; if i = 0 then ( if k = 0 & j = 0 then ( return 1 ) else ( return 0 ) ) else (if k < 0 or j < 0 or (i->compareTo(j)) < 0 then ( return 0 ) else ( dp[Sequence{i, j, k}+1] := ((j + j + 1) * perm(i - 1, j, k - 2 * j) + (j + 1) * (j + 1) * perm(i - 1, j + 1, k - 2 * j) + 1 * perm(i - 1, j - 1, k - 2 * j)) mod ((10)->pow(9) + 7) ; return dp[Sequence{i, j, k}+1] ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=10**9+7 n,oddness=[int(item)for item in input().split()] if oddness % 2==1 : print(0) exit() oddness//=2 max_oddness=n*n+n max_pending=n+1 dp=[[[0]*(max_oddness)for _ in range(max_pending)]for _ in range(n)] oddness_itr=[item for item in range(n*n)] for i in range(n): if i==0 : dp[0][0][0]=1 dp[0][1][1]=1 continue for j in range(i+1): for k in oddness_itr : dp[i][j][k+j]+=dp[i-1][j][k] dp[i][j][k+j]+=dp[i-1][j][k]*j*2 dp[i][j][k+j]%=MOD if j>0 : dp[i][j-1][k+j-1]+=dp[i-1][j][k]*j*j dp[i][j-1][k+j-1]%=MOD dp[i][j+1][k+j+1]+=dp[i-1][j][k] dp[i][j+1][k+j+1]%=MOD print(dp[n-1][0][oddness]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : double := (10)->pow(9) + 7 ; var n : OclAny := null; var oddness : OclAny := null; Sequence{n,oddness} := input().split()->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; if oddness mod 2 = 1 then ( execute (0)->display() ; exit() ) else skip ; oddness := oddness div 2 ; var max_oddness : double := n * n + n ; var max_pending : OclAny := n + 1 ; var dp : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, max_pending-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (max_oddness)))))) ; var oddness_itr : Sequence := Integer.subrange(0, n * n-1)->select(item | true)->collect(item | (item)) ; for i : Integer.subrange(0, n-1) do ( if i = 0 then ( dp->first()->first()->first() := 1 ; dp->first()[1+1][1+1] := 1 ; continue ) else skip ; for j : Integer.subrange(0, i + 1-1) do ( for k : oddness_itr do ( dp[i+1][j+1][k + j+1] := dp[i+1][j+1][k + j+1] + dp[i - 1+1][j+1][k+1] ; dp[i+1][j+1][k + j+1] := dp[i+1][j+1][k + j+1] + dp[i - 1+1][j+1][k+1] * j * 2 ; dp[i+1][j+1][k + j+1] := dp[i+1][j+1][k + j+1] mod MOD ; if j > 0 then ( dp[i+1][j - 1+1][k + j - 1+1] := dp[i+1][j - 1+1][k + j - 1+1] + dp[i - 1+1][j+1][k+1] * j * j ; dp[i+1][j - 1+1][k + j - 1+1] := dp[i+1][j - 1+1][k + j - 1+1] mod MOD ) else skip ; dp[i+1][j + 1+1][k + j + 1+1] := dp[i+1][j + 1+1][k + j + 1+1] + dp[i - 1+1][j+1][k+1] ; dp[i+1][j + 1+1][k + j + 1+1] := dp[i+1][j + 1+1][k + j + 1+1] mod MOD))) ; execute (dp[n - 1+1]->first()[oddness+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys a,b=map(int,sys.stdin.readline().split()) if a<=8 and b<=8 : print('Yay!') else : print(":(") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a <= 8 & b <= 8 then ( execute ('Yay!')->display() ) else ( execute (":(")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfSubstrings(num): n=len(num) sumofdigit=[] sumofdigit.append(int(num[0])) res=sumofdigit[0] for i in range(1,n): numi=int(num[i]) sumofdigit.append((i+1)*numi+10*sumofdigit[i-1]) res+=sumofdigit[i] return res num="1234" print(sumOfSubstrings(num)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; num := "1234" ; execute (sumOfSubstrings(num))->display(); operation sumOfSubstrings(num : OclAny) : OclAny pre: true post: true activity: var n : int := (num)->size() ; var sumofdigit : Sequence := Sequence{} ; execute ((("" + ((num->first())))->toInteger()) : sumofdigit) ; var res : OclAny := sumofdigit->first() ; for i : Integer.subrange(1, n-1) do ( var numi : int := ("" + ((num[i+1])))->toInteger() ; execute (((i + 1) * numi + 10 * sumofdigit[i - 1+1]) : sumofdigit) ; res := res + sumofdigit[i+1]) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input(); print(':('*(len(s)>3 or '9' in s)or 'Yay!') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine(); execute (StringLib.nCopies(':(', ((s)->size() > 3 or (s)->characters()->includes('9'))) or 'Yay!')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): A,B=map(int,input().split()) if A<9 and B<9 : print("Yay!") else : print(":(") if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if A < 9 & B < 9 then ( execute ("Yay!")->display() ) else ( execute (":(")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def _input(): return map(int,input().split()) n=int(input()) s=input() lst=list(_input()) fi=la=-1 for i in range(n): k=int(s[i]) if lst[k-1]>k : if fi==-1 : fi=i else : la=i elif lst[k-1]==k : if fi!=-1 : la=i else : if fi!=-1 : la=i-1 ; break if fi==la and fi==-1 : print(s) else : print(s[: fi],end='') if la==-1 : la=n-1 for i in range(fi,la+1): print(lst[int(s[i])-1],end='') print(s[la+1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var lst : Sequence := (_input()) ; var fi : OclAny := -1; var la : int := -1 ; for i : Integer.subrange(0, n-1) do ( var k : int := ("" + ((s[i+1])))->toInteger() ; if (lst[k - 1+1]->compareTo(k)) > 0 then ( if fi = -1 then ( fi := i ) else ( la := i ) ) else (if lst[k - 1+1] = k then ( if fi /= -1 then ( la := i ) else skip ) else ( if fi /= -1 then ( la := i - 1; break ) else skip ) ) ) ; if fi = la & fi = -1 then ( execute (s)->display() ) else ( execute (s.subrange(1,fi))->display() ; if la = -1 then ( la := n - 1 ) else skip ; for i : Integer.subrange(fi, la + 1-1) do ( execute (lst[("" + ((s[i+1])))->toInteger() - 1+1])->display()) ; execute (s.subrange(la + 1+1))->display() ); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys a,b=map(int,sys.stdin.readline().split()) if acollect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(b)) < 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a} ) else skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := Sequence{16 - b * 2,a - b} ; var ans : String := if (c->compareTo(r div 2)) <= 0 then 'Yay!' else ':(' endif ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=list(map(int,input().split())) if a<=8 and b<=8 : print('Yay!') exit() print(':(') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if a <= 8 & b <= 8 then ( execute ('Yay!')->display() ; exit() ) else skip ; execute (':(')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) if a<=b : print(a) else : print(a-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(b)) <= 0 then ( execute (a)->display() ) else ( execute (a - 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import cmath import heapq import itertools import math import operator import os import random import re import string import sys from collections import Counter,deque,defaultdict from copy import deepcopy from decimal import Decimal from fractions import gcd from functools import lru_cache,reduce from operator import itemgetter,mul,add,xor import numpy as np if os.getenv("LOCAL"): sys.stdin=open("_in.txt","r") sys.setrecursionlimit(10**9) INF=float("inf") IINF=10**18 MOD=10**9+7 from datetime import datetime,timedelta a,b=list(map(int,sys.stdin.buffer.readline().split())) dt=datetime(2018,1,1) until=datetime(2018,a,b) cnt=0 while dt<=until : if dt.month==dt.day : cnt+=1 dt+=timedelta(days=1) print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if os.getenv("LOCAL") then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("_in.txt")) ) else skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (("inf")))->toReal() ; var IINF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dt : OclAny := ; var until : OclAny := ; var cnt : int := 0 ; while (dt->compareTo(until)) <= 0 do ( if dt.getMonth() = dt.getDate() then ( cnt := cnt + 1 ) else skip ; dt := dt + timedelta((argument (test (logical_test (comparison (expr (atom (name days)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os f=lambda : list(map(int,input().split())) if 'local' in os.environ : sys.stdin=open('./input.txt','r') def solve(): a,b=f() if a<=b : print(a) else : print(a-1) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var f : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; if (os.environ)->includes('local') then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('./input.txt')) ) else skip ; skip ; solve(); operation solve() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := f->apply() ; if (a->compareTo(b)) <= 0 then ( execute (a)->display() ) else ( execute (a - 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()); print(a-1+(a<=b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); execute (a - 1 + ((a->compareTo(b)) <= 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[int(x)for x in input().split(' ')] m,d=a if dselect(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var m : OclAny := null; var d : OclAny := null; Sequence{m,d} := a ; if (d->compareTo(m)) < 0 then ( execute (m - 1)->display() ) else ( execute (m)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findCountOfPairs(a,b,n): ans=0 ans+=n*int(a/n)*int(b/n) ans+=int(a/n)*(b % n) ans+=(a % n)*int(b/n) ans+=int(((a % n)+(b % n))/n); return ans if __name__=='__main__' : a=5 b=13 n=3 print(findCountOfPairs(a,b,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := 5 ; b := 13 ; n := 3 ; execute (findCountOfPairs(a, b, n))->display() ) else skip; operation findCountOfPairs(a : OclAny, b : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; ans := ans + n * ("" + ((a / n)))->toInteger() * ("" + ((b / n)))->toInteger() ; ans := ans + ("" + ((a / n)))->toInteger() * (b mod n) ; ans := ans + (a mod n) * ("" + ((b / n)))->toInteger() ; ans := ans + ("" + ((((a mod n) + (b mod n)) / n)))->toInteger(); ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,p=map(int,input().split()) abc=[list(map(int,input().split()))for _ in range(m)] abc=[[a,b,p-c]for a,b,c in abc] def BF(edges,num_v,source): inf=float("inf") dist=[inf for i in range(num_v)] dist[source-1]=0 neg=[False for _ in range(num_v)] for i in range(num_v-1): for edge in edges : if edge[0]!=inf and dist[edge[1]-1]>dist[edge[0]-1]+edge[2]: dist[edge[1]-1]=dist[edge[0]-1]+edge[2] for i in range(num_v): for edge in edges : if edge[0]!=inf and dist[edge[1]-1]>dist[edge[0]-1]+edge[2]: dist[edge[1]-1]=dist[edge[0]-1]+edge[2] neg[edge[1]-1]=True if neg[edge[0]-1]==True : neg[edge[1]-1]=True return dist,neg dis,neg=BF(abc,n,1) print(-1 if neg[-1]else max(0,-dis[-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var p : OclAny := null; Sequence{n,m,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var abc : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; abc := abc->select(_tuple | true)->collect(_tuple | let a : OclAny = _tuple->at(1) in let b : OclAny = _tuple->at(2) in (Sequence{a}->union(Sequence{b}->union(Sequence{ p - c })))) ; skip ; var dis : OclAny := null; Sequence{dis,neg} := BF(abc, n, 1) ; execute (if neg->last() then -1 else Set{0, -dis->last()}->max() endif)->display(); operation BF(edges : OclAny, num_v : OclAny, source : OclAny) : OclAny pre: true post: true activity: var Math_PINFINITY : double := ("" + (("inf")))->toReal() ; var dist : Sequence := Integer.subrange(0, num_v-1)->select(i | true)->collect(i | (Math_PINFINITY)) ; dist[source - 1+1] := 0 ; var neg : Sequence := Integer.subrange(0, num_v-1)->select(_anon | true)->collect(_anon | (false)) ; for i : Integer.subrange(0, num_v - 1-1) do ( for edge : edges do ( if edge->first() /= Math_PINFINITY & (dist[edge[1+1] - 1+1]->compareTo(dist[edge->first() - 1+1] + edge[2+1])) > 0 then ( dist[edge[1+1] - 1+1] := dist[edge->first() - 1+1] + edge[2+1] ) else skip)) ; for i : Integer.subrange(0, num_v-1) do ( for edge : edges do ( if edge->first() /= Math_PINFINITY & (dist[edge[1+1] - 1+1]->compareTo(dist[edge->first() - 1+1] + edge[2+1])) > 0 then ( dist[edge[1+1] - 1+1] := dist[edge->first() - 1+1] + edge[2+1] ; neg[edge[1+1] - 1+1] := true ) else skip ; if neg[edge->first() - 1+1] = true then ( neg[edge[1+1] - 1+1] := true ) else skip)) ; return dist, neg; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inf=float('inf') def bellmanford(n : int,edges : list,start : int,goal : int)->(list,bool): dist=[inf]*n dist[start]=0 exist_negative_cycle=False for _ in range(n-1): for v,nv,w in edges : if dist[nv]>dist[v]+w : dist[nv]=dist[v]+w is_updated=[False]*n for _ in range(n): for v,nv,w in edges : if dist[nv]>dist[v]+w : dist[nv]=dist[v]+w is_updated[nv]=True if is_updated[v]is True : is_updated[nv]=True exist_negative_cycle=is_updated[goal] return dist,exist_negative_cycle N,M,P=map(int,input().split()) edges=[] for _ in range(M): A,B,C=map(int,input().split()) A-=1 ; B-=1 C=C-P edges.append((A,B,-C)) dist,exist_negative_cycle=bellmanford(N,edges,0,N-1) if exist_negative_cycle is True : ans=-1 else : ans=max(-dist[N-1],0) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; skip ; var N : OclAny := null; var M : OclAny := null; var P : OclAny := null; Sequence{N,M,P} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var edges : Sequence := Sequence{} ; for _anon : Integer.subrange(0, M-1) do ( var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{A,B,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; A := A - 1; B := B - 1 ; var C : double := C - P ; execute ((Sequence{A, B, -C}) : edges)) ; Sequence{dist,exist_negative_cycle} := bellmanford(N, edges, 0, N - 1) ; if exist_negative_cycle <>= true then ( var ans : int := -1 ) else ( ans := Set{-dist[N - 1+1], 0}->max() ) ; execute (ans)->display(); operation bellmanford(n : int, edges : Sequence(OclAny), start : int, goal : int) : OclAny pre: true post: true activity: var dist : Sequence := MatrixLib.elementwiseMult(Sequence{ Math_PINFINITY }, n) ; dist[start+1] := 0 ; var exist_negative_cycle : boolean := false ; for _anon : Integer.subrange(0, n - 1-1) do ( for _tuple : edges do (var _indx : int := 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var nv : OclAny := _tuple->at(_indx); _indx := _indx + 1; var w : OclAny := _tuple->at(_indx); if (dist[nv+1]->compareTo(dist[v+1] + w)) > 0 then ( dist[nv+1] := dist[v+1] + w ) else skip)) ; var is_updated : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ; for _anon : Integer.subrange(0, n-1) do ( for _tuple : edges do (var _indx : int := 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var nv : OclAny := _tuple->at(_indx); _indx := _indx + 1; var w : OclAny := _tuple->at(_indx); if (dist[nv+1]->compareTo(dist[v+1] + w)) > 0 then ( dist[nv+1] := dist[v+1] + w ; is_updated[nv+1] := true ) else skip ; if is_updated[v+1] <>= true then ( is_updated[nv+1] := true ) else skip)) ; exist_negative_cycle := is_updated[goal+1] ; return dist, exist_negative_cycle; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import collections import copy import functools import heapq import math import sys from collections import deque from collections import defaultdict input=sys.stdin.readline MOD=10**9+7 N,M,P=map(int,(input().split())) line=[] for i in range(M): a,b,c=map(int,(input().split())) line.append([a-1,b-1,-c+P]) min_distance=[float("inf")]*N min_distance[0]=0 def Bellman_Ford(S,V,E,distance): update=False flag=0 for _ in range(V): for s,g,d in distance : if min_distance[s]!=float("inf")and min_distance[s]+dpow(9) + 7 ; var N : OclAny := null; var M : OclAny := null; var P : OclAny := null; Sequence{N,M,P} := ((input().split()))->collect( _x | (OclType["int"])->apply(_x) ) ; var line : Sequence := Sequence{} ; for i : Integer.subrange(0, M-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := ((input().split()))->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a - 1}->union(Sequence{b - 1}->union(Sequence{ -c + P }))) : line)) ; var min_distance : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (("inf")))->toReal() }, N) ; min_distance->first() := 0 ; skip ; skip ; Sequence{min_distance,flag} := Bellman_Ford(1, N, M, line) ; if flag = 1 then ( var ans : OclAny := min_distance[N - 1+1] ; execute (Set{-ans, 0}->max())->display() ) else ( min_distance := Bellman_Ford2(1, N, M, line) ; ans := min_distance[N - 1+1] ; if ans = -("" + (("inf")))->toReal() then ( execute (-1)->display() ) else ( execute (Set{-ans, 0}->max())->display() ) ); operation Bellman_Ford(S : OclAny, V : OclAny, E : OclAny, distance : OclAny) : OclAny pre: true post: true activity: var update : boolean := false ; var flag : int := 0 ; for _anon : Integer.subrange(0, V-1) do ( for _tuple : distance do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var g : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); if min_distance[s+1] /= ("" + (("inf")))->toReal() & (min_distance[s+1] + d->compareTo(min_distance[g+1])) < 0 then ( min_distance[g+1] := min_distance[s+1] + d ; update := true ) else skip) ; if not(update) then ( flag := 1 ; break ) else skip) ; return min_distance, flag; operation Bellman_Ford2(S : OclAny, V : OclAny, E : OclAny, distance : OclAny) : OclAny pre: true post: true activity: for _anon : Integer.subrange(0, V-1) do ( for _tuple : distance do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var g : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); if min_distance[s+1] /= ("" + (("inf")))->toReal() & (min_distance[s+1] + d->compareTo(min_distance[g+1])) < 0 then ( min_distance[g+1] := -("" + (("inf")))->toReal() ) else skip)) ; return min_distance; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _=int(input()) a=list(map(int,list(input()))) f=[0]+list(map(int,input().split())) started=False for i in range(len(a)): if a[i]toInteger() ; var a : Sequence := ((((OclFile["System.in"]).readLine())->characters())->collect( _x | (OclType["int"])->apply(_x) )) ; var f : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var started : boolean := false ; for i : Integer.subrange(0, (a)->size()-1) do ( if (a[i+1]->compareTo(f[a[i+1]+1])) < 0 then ( started := true ; a[i+1] := f[a[i+1]+1] ) else (if a[i+1] = f[a[i+1]+1] then ( continue ) else (if started then ( break ) else skip ) ) ) ; execute (StringLib.sumStringsWithSeparator(((a)->collect( _x | (OclType["String"])->apply(_x) )), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(1000000000) ii=lambda : int(input()) miis=lambda : map(int,input().split()) lmiis=lambda : list(miis()) def reachable_nodeset(start,inc): reachable=set() reachable.add(start) nodes=[start] while nodes : n=nodes.pop() for i in inc[n]: if i not in reachable : nodes.append(i) reachable.add(i) return reachable def bellmanford(num,start,goal,edges): cost=[float('inf')]*num cost[start]=0 for _ in range(num): updated=False for a,b,c in edges : if cost[b]>cost[a]+c : cost[b]=cost[a]+c updated=True if not updated : break else : return-1 return max(0,-cost[goal]) def solve(): N,M,P=miis() to=[[]for _ in range(N)] ot=[[]for _ in range(N)] edges=[] for _ in range(M): a,b,c=miis() a-=1 b-=1 c=-(c-P) to[a].append(b) ot[b].append(a) edges.append((a,b,c)) reachableFromZero=reachable_nodeset(0,to) reachableToN=reachable_nodeset(N-1,ot) ok=reachableFromZero.intersection(reachableToN) edges=tuple((a,b,c)for a,b,c in edges if a in ok and b in ok) print(bellmanford(N,0,N-1,edges)) if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(1000000000) ; var ii : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var miis : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lmiis : Function := lambda $$ : OclAny in ((miis->apply())) ; skip ; skip ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation reachable_nodeset(start : OclAny, inc : OclAny) : OclAny pre: true post: true activity: var reachable : Set := Set{}->union(()) ; execute ((start) : reachable) ; var nodes : Sequence := Sequence{ start } ; while nodes do ( var n : OclAny := nodes->last() ; nodes := nodes->front() ; for i : inc[n+1] do ( if (reachable)->excludes(i) then ( execute ((i) : nodes) ; execute ((i) : reachable) ) else skip)) ; return reachable; operation bellmanford(num : OclAny, start : OclAny, goal : OclAny, edges : OclAny) : OclAny pre: true post: true activity: var cost : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (('inf')))->toReal() }, num) ; cost[start+1] := 0 ; (compound_stmt for (exprlist (expr (atom (name _)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name updated)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name False)))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name a))) , (expr (atom (name b))) , (expr (atom (name c)))) in (testlist (test (logical_test (comparison (expr (atom (name edges))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name cost)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])))) > (comparison (expr (expr (atom (name cost)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ]))) + (expr (atom (name c)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cost)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name cost)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ]))) + (expr (atom (name c))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name updated)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name True)))))))))))))))))) (stmt (compound_stmt if (test (logical_test not (logical_test (comparison (expr (atom (name updated))))))) : (suite (simple_stmt (small_stmt break)))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))))))) ; return Set{0, -cost[goal+1]}->max(); operation solve() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; var P : OclAny := null; Sequence{N,M,P} := miis->apply() ; var to : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var ot : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; edges := Sequence{} ; for _anon : Integer.subrange(0, M-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := miis->apply() ; a := a - 1 ; b := b - 1 ; var c : double := -(c - P) ; (expr (atom (name to)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name ot)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))) ; execute ((Sequence{a, b, c}) : edges)) ; var reachableFromZero : OclAny := reachable_nodeset(0, to) ; var reachableToN : OclAny := reachable_nodeset(N - 1, ot) ; var ok : OclAny := reachableFromZero->intersection(reachableToN) ; edges := ((argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name b)))))) , (test (logical_test (comparison (expr (atom (name c))))))) )))))) (comp_for for (exprlist (expr (atom (name a))) , (expr (atom (name b))) , (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name edges))))) (comp_iter if (test (logical_test (logical_test (comparison (comparison (expr (atom (name a)))) in (comparison (expr (atom (name ok)))))) and (logical_test (comparison (comparison (expr (atom (name b)))) in (comparison (expr (atom (name ok)))))))))))) ; execute (bellmanford(N, 0, N - 1, edges))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys inf=10000000000 def BellmanFord(edges,points,start): dist=[inf for i in range(points)] dist[start-1]=0 for i in range(points): for edge in edges : if dist[edge[0]-1]!=inf and dist[edge[1]-1]>dist[edge[0]-1]+edge[2]: dist[edge[1]-1]=dist[edge[0]-1]+edge[2] dist1=dist[N-1] for i in range(points): for edge in edges : if dist[edge[0]-1]!=inf and dist[edge[1]-1]>dist[edge[0]-1]+edge[2]: dist[edge[1]-1]=dist[edge[0]-1]+edge[2] dist2=dist[N-1] if dist1!=dist2 : return "Loop" return(dist) N,M,P=[int(i)for i in input().split()] Edges=[] for i in range(M): a,b,c=[int(i)for i in input().split()] Edges.append((a,b,P-c)) dist=BellmanFord(Edges,N,1) if dist=="Loop" : print(-1) else : print(max(-dist[N-1],0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var Math_PINFINITY : int := 10000000000 ; skip ; var N : OclAny := null; var M : OclAny := null; var P : OclAny := null; Sequence{N,M,P} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var Edges : Sequence := Sequence{} ; for i : Integer.subrange(0, M-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute ((Sequence{a, b, P - c}) : Edges)) ; dist := BellmanFord(Edges, N, 1) ; if dist = "Loop" then ( execute (-1)->display() ) else ( execute (Set{-dist[N - 1+1], 0}->max())->display() ); operation BellmanFord(edges : OclAny, points : OclAny, start : OclAny) : OclAny pre: true post: true activity: var dist : Sequence := Integer.subrange(0, points-1)->select(i | true)->collect(i | (Math_PINFINITY)) ; dist[start - 1+1] := 0 ; for i : Integer.subrange(0, points-1) do ( for edge : edges do ( if dist[edge->first() - 1+1] /= Math_PINFINITY & (dist[edge[1+1] - 1+1]->compareTo(dist[edge->first() - 1+1] + edge[2+1])) > 0 then ( dist[edge[1+1] - 1+1] := dist[edge->first() - 1+1] + edge[2+1] ) else skip) ; var dist1 : OclAny := dist[N - 1+1]) ; for i : Integer.subrange(0, points-1) do ( for edge : edges do ( if dist[edge->first() - 1+1] /= Math_PINFINITY & (dist[edge[1+1] - 1+1]->compareTo(dist[edge->first() - 1+1] + edge[2+1])) > 0 then ( dist[edge[1+1] - 1+1] := dist[edge->first() - 1+1] + edge[2+1] ) else skip) ; var dist2 : OclAny := dist[N - 1+1]) ; if dist1 /= dist2 then ( return "Loop" ) else skip ; return (dist); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def main(): def primes(n): is_prime=[True]*(n+1) is_prime[0]=is_prime[1]=False for i in range(2,int(n**(1/2))+1): if is_prime[i]: for j in range(i*i,n+1,i): is_prime[j]=False return[i for i in range(n+1)if is_prime[i]] prime_list=primes(100000) solvers=[[]for _ in range(100001)] for p in prime_list : for i in range(p,100001,p): solvers[i].append(p) n=int(input()) a_list=list(map(int,input().split())) parent=[i for i in range(100001)] def find(x): if x==parent[x]: return x parent[x]=find(parent[x]) return parent[x] for i,v in enumerate(a_list): p_rep=find(min(solvers[v])) for s in solvers[v]: parent[find(s)]=p_rep parent[find(v)]=p_rep dic=defaultdict(set) for i,v in enumerate(a_list): dic[find(v)].add(i) a_list.sort() for i,v in enumerate(a_list): if i not in dic[find(v)]: print(0) break else : print(1) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: skip ; var prime_list : OclAny := primes(100000) ; var solvers : Sequence := Integer.subrange(0, 100001-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for p : prime_list do ( for i : Integer.subrange(p, 100001-1)->select( $x | ($x - p) mod p = 0 ) do ((expr (atom (name solvers)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p)))))))) )))))) ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var parent : Sequence := Integer.subrange(0, 100001-1)->select(i | true)->collect(i | (i)) ; skip ; for _tuple : Integer.subrange(1, (a_list)->size())->collect( _indx | Sequence{_indx-1, (a_list)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); var p_rep : OclAny := find((solvers[v+1])->min()) ; for s : solvers[v+1] do ( parent[find(s)+1] := p_rep) ; parent[find(v)+1] := p_rep) ; var dic : OclAny := defaultdict(OclType["Set"]) ; for _tuple : Integer.subrange(1, (a_list)->size())->collect( _indx | Sequence{_indx-1, (a_list)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); (expr (atom (name dic)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name find)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) ))))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; a_list := a_list->sort() ; (compound_stmt for (exprlist (expr (atom (name i))) , (expr (atom (name v)))) in (testlist (test (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a_list)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name i)))) not in (comparison (expr (atom (name dic)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name find)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) ))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ways(s,n): dp=[[0 for i in range(n)]for i in range(n)] for i in range(n): dp[0][i]=1 for i in range(1,n): temp="" for j in range(i,n): temp+=s[j] test="" for k in range(i-1,-1,-1): test+=s[k] if(testsize() ; execute (ways(s, n))->display(); operation ways(s : OclAny, n : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, n-1) do ( dp->first()[i+1] := 1) ; for i : Integer.subrange(1, n-1) do ( var temp : String := "" ; for j : Integer.subrange(i, n-1) do ( temp := temp + s[j+1] ; var test : String := "" ; for k : Integer.subrange(-1 + 1, i - 1)->reverse() do ( test := test + s[k+1] ; if (test < temp) then ( dp[i+1][j+1] := dp[i+1][j+1] + dp[k+1][i - 1+1] ) else skip))) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( ans := ans + dp[i+1][n - 1+1]) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) print(2**n-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((2)->pow(n) - 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for _ in range(n): x=int(input()) if(x==1): print(1) else : print(2**x-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (x = 1) then ( execute (1)->display() ) else ( execute ((2)->pow(x) - 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): LIMIT=1000000 maxnumer=0 maxdenom=1 for d in range(1,LIMIT+1): n=d*3//7 if d % 7==0 : n-=1 if n*maxdenom>d*maxnumer : maxnumer=n maxdenom=d return str(maxnumer) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LIMIT : int := 1000000 ; var maxnumer : int := 0 ; var maxdenom : int := 1 ; for d : Integer.subrange(1, LIMIT + 1-1) do ( var n : int := d * 3 div 7 ; if d mod 7 = 0 then ( n := n - 1 ) else skip ; if (n * maxdenom->compareTo(d * maxnumer)) > 0 then ( maxnumer := n ; maxdenom := d ) else skip) ; return ("" + ((maxnumer))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) for i in range(num): n=int(input()) print((2**n)-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, num-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (((2)->pow(n)) - 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): print(2**int(input())-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute ((2)->pow(("" + (((OclFile["System.in"]).readLine())))->toInteger()) - 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) print((1<toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((1 * (2->pow(n))) - 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isOdd(arr,n): flag=0 ; flag1=0 ; sum=0 ; for i in range(n): sum+=arr[i]; if(arr[i]% 2==0 and flag==0): flag=1 ; l=arr[i]; if(arr[i]% 2!=0 and flag1==0): r=arr[i]; flag1=1 ; if(sum % 2!=0): return True ; else : if(flag1==1 and flag==1): return True ; else : return False ; if __name__=="__main__" : arr=[5,4,4,5,1,3]; n=len(arr); res=isOdd(arr,n); if(res): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{5}->union(Sequence{4}->union(Sequence{4}->union(Sequence{5}->union(Sequence{1}->union(Sequence{ 3 }))))); ; n := (arr)->size(); ; var res : OclAny := isOdd(arr, n); ; if (res) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ) else skip; operation isOdd(arr : OclAny, n : OclAny) pre: true post: true activity: var flag : int := 0; var flag1 : int := 0; var sum : int := 0; ; for i : Integer.subrange(0, n-1) do ( sum := sum + arr[i+1]; ; if (arr[i+1] mod 2 = 0 & flag = 0) then ( flag := 1; ; var l : OclAny := arr[i+1]; ) else skip ; if (arr[i+1] mod 2 /= 0 & flag1 = 0) then ( var r : OclAny := arr[i+1]; ; flag1 := 1; ) else skip) ; if (sum mod 2 /= 0) then ( return true; ) else ( if (flag1 = 1 & flag = 1) then ( return true; ) else ( return false; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=int(1e9)+7 if __name__=="__main__" : a=input() b=input() k=int(input()) if(len(a)!=len(b)): print(0) exit() a=a+a x=0 y=0 for i in range(len(a)//2): flag=1 for j in range(len(b)): if(a[j+i]!=b[j]): flag=0 break if(flag==1): x+=1 else : y+=1 flag=0 for i in range(len(b)): if(a[i]!=b[i]): flag=1 u=1 v=0 if(flag==1): v=1 u=0 for i in range(k): uu=(u*(x-1))% MOD+(v*(x))% MOD vv=(u*(y))% MOD+(v*(y-1))% MOD u=uu % MOD v=vv % MOD print(u) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : int := ("" + ((("1e9")->toReal())))->toInteger() + 7 ; if __name__ = "__main__" then ( var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if ((a)->size() /= (b)->size()) then ( execute (0)->display() ; exit() ) else skip ; a := a + a ; var x : int := 0 ; var y : int := 0 ; for i : Integer.subrange(0, (a)->size() div 2-1) do ( var flag : int := 1 ; for j : Integer.subrange(0, (b)->size()-1) do ( if (a[j + i+1] /= b[j+1]) then ( flag := 0 ; break ) else skip) ; if (flag = 1) then ( x := x + 1 ) else ( y := y + 1 )) ; flag := 0 ; for i : Integer.subrange(0, (b)->size()-1) do ( if (a[i+1] /= b[i+1]) then ( flag := 1 ) else skip) ; var u : int := 1 ; var v : int := 0 ; if (flag = 1) then ( v := 1 ; u := 0 ) else skip ; for i : Integer.subrange(0, k-1) do ( var uu : int := (u * (x - 1)) mod MOD + (v * (x)) mod MOD ; var vv : int := (u * (y)) mod MOD + (v * (y - 1)) mod MOD ; u := uu mod MOD ; v := vv mod MOD) ; execute (u)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) s=input()[:-1] w=list(map(int,input().split())) c=-1 for i in range(n): a=int(s[i]) if w[a-1]>a : c=i break if c==-1 : print(s) else : d='' e=-1 for i in range(c,n): a=int(s[i]) if w[a-1]>=a : d+=str(w[a-1]) else : e=i break if e==-1 : print(s[: c]+d) else : print(s[: c]+d+s[e :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := input()->front() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := -1 ; for i : Integer.subrange(0, n-1) do ( var a : int := ("" + ((s[i+1])))->toInteger() ; if (w[a - 1+1]->compareTo(a)) > 0 then ( c := i ; break ) else skip) ; if c = -1 then ( execute (s)->display() ) else ( var d : String := '' ; var e : int := -1 ; for i : Integer.subrange(c, n-1) do ( a := ("" + ((s[i+1])))->toInteger() ; if (w[a - 1+1]->compareTo(a)) >= 0 then ( d := d + ("" + ((w[a - 1+1]))) ) else ( e := i ; break )) ; if e = -1 then ( execute (s.subrange(1,c) + d)->display() ) else ( execute (s.subrange(1,c) + d + s.subrange(e+1))->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for nt in range(int(input())): n,k=map(int,input().split()) s=input() if 2*k==n : print("NO") continue ans="NO" if s[0 : k]==s[n-k :][: :-1]: ans="YES" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for nt : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; if 2 * k = n then ( execute ("NO")->display() ; continue ) else skip ; var ans : String := "NO" ; if s.subrange(0+1, k) = s.subrange(n - k+1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( ans := "YES" ) else skip ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout T=int(stdin.readline()) for i in range(T): N,K=map(int,stdin.readline().strip().split()) S=list(stdin.readline().strip()) LEN=0 for j in range((N)//2): if S[j]==S[N-j-1]: LEN+=1 else : break if N % 2!=0 : LEN+=1 if K>=LEN and K!=0 : stdout.write("NO\n") else : stdout.write("YES\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var T : int := ("" + ((stdin.readLine())))->toInteger() ; for i : Integer.subrange(0, T-1) do ( var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : Sequence := (stdin.readLine()->trim()) ; var LEN : int := 0 ; for j : Integer.subrange(0, (N) div 2-1) do ( if S[j+1] = S[N - j - 1+1] then ( LEN := LEN + 1 ) else ( break )) ; if N mod 2 /= 0 then ( LEN := LEN + 1 ) else skip ; if (K->compareTo(LEN)) >= 0 & K /= 0 then ( stdout.write("NO\n") ) else ( stdout.write("YES\n") )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): t=int(input()) for i in range(t): n,k=map(int,input().split()) s=str(input()) if n<2*k+1 : print('NO') else : for i in range(k): if s[i]!=s[n-i-1]: print('NO') break else : print('YES') if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; if (n->compareTo(2 * k + 1)) < 0 then ( execute ('NO')->display() ) else ( (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name k)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) != (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name n))) - (expr (atom (name i)))) - (expr (atom (number (integer 1)))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) ))))))))))))))) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for pratyush in range(int(input())): n,k=list(map(int,input().split())) s=input() if k==0 : print("YES") elif n==2*k : print("NO") else : a=s[: k] f=s[: :-1] b=f[: k] if a==b : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for pratyush : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : String := (OclFile["System.in"]).readLine() ; if k = 0 then ( execute ("YES")->display() ) else (if n = 2 * k then ( execute ("NO")->display() ) else ( var a : OclAny := s.subrange(1,k) ; var f : OclAny := s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var b : String := f.subrange(1,k) ; if a = b then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=[0]*100 ; def coef(n): c[0]=1 ; for i in range(n): c[1+i]=1 ; for j in range(i,0,-1): c[j]=c[j-1]-c[j]; c[0]=-c[0]; def isPrime(n): coef(n); c[0]=c[0]+1 ; c[n]=c[n]-1 ; i=n ; while(i>-1 and c[i]% n==0): i=i-1 ; return True if i<0 else False ; n=37 ; if(isPrime(n)): print("Prime"); else : print("Not Prime"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100); ; skip ; skip ; n := 37; ; if (isPrime(n)) then ( execute ("Prime")->display(); ) else ( execute ("Not Prime")->display(); ); operation coef(n : OclAny) pre: true post: true activity: c->first() := 1; ; for i : Integer.subrange(0, n-1) do ( c[1 + i+1] := 1; ; for j : Integer.subrange(0 + 1, i)->reverse() do ( c[j+1] := c[j - 1+1] - c[j+1];) ; c->first() := -c->first();); operation isPrime(n : OclAny) pre: true post: true activity: coef(n); ; c->first() := c->first() + 1; ; c[n+1] := c[n+1] - 1; ; var i : OclAny := n; ; while (i > -1 & c[i+1] mod n = 0) do ( i := i - 1;) ; return if i < 0 then true else false endif;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) s=input() if k==0 : print('YES') else : cnt=0 for i in range(n//2): if s[i]==s[n-1-i]: cnt=cnt+1 else : break if(n>=(2*k)+1 and cnt>=k): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; if k = 0 then ( execute ('YES')->display() ) else ( var cnt : int := 0 ; for i : Integer.subrange(0, n div 2-1) do ( if s[i+1] = s[n - 1 - i+1] then ( cnt := cnt + 1 ) else ( break )) ; if ((n->compareTo((2 * k) + 1)) >= 0 & (cnt->compareTo(k)) >= 0) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def maxCommonFactors(a,b): gcd=math.gcd(a,b) ans=1 ; i=2 while(i*i<=gcd): if(gcd % i==0): ans+=1 while(gcd % i==0): gcd=gcd//i i+=1 if(gcd!=1): ans+=1 return ans a=12 b=18 print(maxCommonFactors(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 12 ; b := 18 ; execute (maxCommonFactors(a, b))->display(); operation maxCommonFactors(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var gcd : long := (a)->gcd(b) ; var ans : int := 1; ; var i : int := 2 ; while ((i * i->compareTo(gcd)) <= 0) do ( if (gcd mod i = 0) then ( ans := ans + 1 ; while (gcd mod i = 0) do ( gcd := gcd div i) ) else skip ; i := i + 1) ; if (gcd /= 1) then ( ans := ans + 1 ) else skip ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def allCharactersSame(s): n=len(s) for i in range(1,n): if s[i]!=s[0]: return False return True if __name__=="__main__" : s="aaa" if allCharactersSame(s): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "aaa" ; if allCharactersSame(s) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation allCharactersSame(s : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; for i : Integer.subrange(1, n-1) do ( if s[i+1] /= s->first() then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) r=[] for i in range(t): a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) m=max(b) n=max(c) if m>n : r.append("YES") else : r.append("NO") for i in range(len(r)): print(r[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : OclAny := (b)->max() ; var n : OclAny := (c)->max() ; if (m->compareTo(n)) > 0 then ( execute (("YES") : r) ) else ( execute (("NO") : r) )) ; for i : Integer.subrange(0, (r)->size()-1) do ( execute (r[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input exec(int(I())*"n=I().split();I();print('YNEOS'[n[0]in I()::2]);") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name I)) (trailer (arguments ( ))))))))) )))) * (expr (atom "n=I().split();I();print('YNEOS'[n[0]in I()::2]);"))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : n,n1,n1=[int(i)for i in input().split()] x1=[int(i)for i in input().split()] x2=[int(i)for i in input().split()] if max(x1)>max(x2): print('YES') else : print('NO') t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( var n : OclAny := null; var n1 : OclAny := null; var n1 : OclAny := null; Sequence{n,n1,n1} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var x1 : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var x2 : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if ((x1)->max()->compareTo((x2)->max())) > 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input(); t=[*map(int,input())]; f=0,*input().split(); c=0 ; a=0 for b in t : n=int(f[b]) if n>b or n==b and c : c=1 ; t[a]=n elif c : break a+=1 print(*t,sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input(); var t : Sequence := ((OclFile["System.in"]).readLine())->collect( _x | (OclType["int"])->apply(_x) ); var f : OclAny := 0,input().split(); var c : int := 0; var a : int := 0 ; for b : t do ( var n : int := ("" + ((f[b+1])))->toInteger() ; if (n->compareTo(b)) > 0 or n = b & c then ( c := 1; t[a+1] := n ) else (if c then ( break ) else skip) ; a := a + 1) ; execute ((argument * (test (logical_test (comparison (expr (atom (name t))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import* from decimal import* from opcode import HAVE_ARGUMENT import sys from tkinter import N input_=sys.stdin.readline def _input(): return map(int,input().split()) def _list(): return list(map(int,input().split())) def solves(): n,k1,k2=_input() a1=_list() a2=_list() if(max(a1)>max(a2)): print("YES") else : print("NO") t=1 t=int(input()) for _ in range(0,t): solves() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var input_ : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; var t : int := 1 ; t := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( solves()); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation _list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation solves() pre: true post: true activity: var n : OclAny := null; var k1 : OclAny := null; var k2 : OclAny := null; Sequence{n,k1,k2} := _input() ; var a1 : OclAny := _list() ; var a2 : OclAny := _list() ; if (((a1)->max()->compareTo((a2)->max())) > 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys lines=[] for line in sys.stdin : lines.append(line.split()) for i in range(int(lines[0][0])): n=int(lines[3*i+1][0]) k1=int(lines[3*i+1][1]) k2=int(lines[3*i+1][2]) for j in range(k1): if int(lines[3*i+2][j])==n : print('YES') for j in range(k2): if int(lines[3*i+3][j])==n : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var lines : Sequence := Sequence{} ; for line : OclFile["System.in"] do ( execute ((line.split()) : lines)) ; for i : Integer.subrange(0, ("" + ((lines->first()->first())))->toInteger()-1) do ( var n : int := ("" + ((lines[3 * i + 1+1]->first())))->toInteger() ; var k1 : int := ("" + ((lines[3 * i + 1+1][1+1])))->toInteger() ; var k2 : int := ("" + ((lines[3 * i + 1+1][2+1])))->toInteger() ; for j : Integer.subrange(0, k1-1) do ( if ("" + ((lines[3 * i + 2+1][j+1])))->toInteger() = n then ( execute ('YES')->display() ) else skip) ; for j : Integer.subrange(0, k2-1) do ( if ("" + ((lines[3 * i + 3+1][j+1])))->toInteger() = n then ( execute ('NO')->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printUnsorted(arr,n): e=n-1 for s in range(0,n-1): if arr[s]>arr[s+1]: break if s==n-1 : print("The complete array is sorted") exit() e=n-1 while e>0 : if arr[e]max : max=arr[i] if arr[i]min : s=i break i=n-1 while i>=e+1 : if arr[i]union(Sequence{12}->union(Sequence{20}->union(Sequence{30}->union(Sequence{25}->union(Sequence{40}->union(Sequence{32}->union(Sequence{31}->union(Sequence{35}->union(Sequence{50}->union(Sequence{ 60 })))))))))) ; var arr_size : int := (arr)->size() ; printUnsorted(arr, arr_size); operation printUnsorted(arr : OclAny, n : OclAny) pre: true post: true activity: var e : double := n - 1 ; for s : Integer.subrange(0, n - 1-1) do ( if (arr[s+1]->compareTo(arr[s + 1+1])) > 0 then ( break ) else skip) ; if s = n - 1 then ( execute ("The complete array is sorted")->display() ; exit() ) else skip ; e := n - 1 ; while e > 0 do ( if (arr[e+1]->compareTo(arr[e - 1+1])) < 0 then ( break ) else skip ; e := e - 1) ; var max : OclAny := arr[s+1] ; var min : OclAny := arr[s+1] ; for i : Integer.subrange(s + 1, e + 1-1) do ( if (arr[i+1]->compareTo(max)) > 0 then ( max := arr[i+1] ) else skip ; if (arr[i+1]->compareTo(min)) < 0 then ( min := arr[i+1] ) else skip) ; for i : Integer.subrange(0, s-1) do ( if (arr[i+1]->compareTo(min)) > 0 then ( var s : OclAny := i ; break ) else skip) ; var i : double := n - 1 ; while (i->compareTo(e + 1)) >= 0 do ( if (arr[i+1]->compareTo(max)) < 0 then ( e := i ; break ) else skip ; i := i - 1) ; execute ("The unsorted subarray which makes the given array")->display() ; execute (StringLib.format("sorted lies between the indexes %d and %d",Sequence{s, e}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin as sin def aint(): return int(input()) def amap(): return map(int,sin.readline().split()) def alist(): return list(map(int,sin.readline().split())) def astr(): return input() def rec(n,k,s): if len(s)==n : if int(s)>=k : return int(s) else : return float("inf") else : if s.count("4")==n//2 : return rec(n,k,s+"7") elif s.count("7")==n//2 : return rec(n,k,s+"4") else : return min(rec(n,k,s+"4"),rec(n,k,s+"7")) s=input() n=len(s) if n % 2!=0 : n+=1 ans=min(rec(n,int(s),""),rec(n+2,int(s),"")) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; s := (OclFile["System.in"]).readLine() ; n := (s)->size() ; if n mod 2 /= 0 then ( n := n + 1 ) else skip ; var ans : OclAny := Set{rec(n, ("" + ((s)))->toInteger(), ""), rec(n + 2, ("" + ((s)))->toInteger(), "")}->min() ; execute (ans)->display(); operation aint() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation amap() : OclAny pre: true post: true activity: return (sin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation alist() : OclAny pre: true post: true activity: return ((sin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation astr() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation rec(n : OclAny, k : OclAny, s : OclAny) : OclAny pre: true post: true activity: if (s)->size() = n then ( if (("" + ((s)))->toInteger()->compareTo(k)) >= 0 then ( return ("" + ((s)))->toInteger() ) else ( return ("" + (("inf")))->toReal() ) ) else ( if s->count("4") = n div 2 then ( return rec(n, k, s + "7") ) else (if s->count("7") = n div 2 then ( return rec(n, k, s + "4") ) else ( return Set{rec(n, k, s + "4"), rec(n, k, s + "7")}->min() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _=input() l=[int(x)for x in input().split()] best=0 curr=0 last=0 for v in l : if v>=last : curr+=1 if curr>best : best=curr else : curr=1 last=v print(best) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _anon : String := (OclFile["System.in"]).readLine() ; var l : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var best : int := 0 ; var curr : int := 0 ; var last : int := 0 ; for v : l do ( if (v->compareTo(last)) >= 0 then ( curr := curr + 1 ; if (curr->compareTo(best)) > 0 then ( best := curr ) else skip ) else ( curr := 1 ) ; last := v) ; execute (best)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) L=list(map(int,input().split())) answer=0 count=1 for i in range(len(L)-1): if L[i]<=L[i+1]: count+=1 else : if count>answer : answer=count count=1 print(max(answer,count)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var L : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var answer : int := 0 ; var count : int := 1 ; for i : Integer.subrange(0, (L)->size() - 1-1) do ( if (L[i+1]->compareTo(L[i + 1+1])) <= 0 then ( count := count + 1 ) else ( if (count->compareTo(answer)) > 0 then ( answer := count ) else skip ; count := 1 )) ; execute (Set{answer, count}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) cnt=1 ans=float('-inf') for i in range(n-1): if l[i]<=l[i+1]: cnt+=1 else : cnt=1 ans=max(ans,cnt) if len(l)==1 : print(1) else : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : int := 1 ; var ans : double := ("" + (('-inf')))->toReal() ; for i : Integer.subrange(0, n - 1-1) do ( if (l[i+1]->compareTo(l[i + 1+1])) <= 0 then ( cnt := cnt + 1 ) else ( cnt := 1 ) ; ans := Set{ans, cnt}->max()) ; if (l)->size() = 1 then ( execute (1)->display() ) else ( execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) inp=input().split() l=[int(i)for i in inp] count=1 max_count=1 for i in range(n-1): if l[i]>l[i+1]: max_count=max(max_count,count) count=1 continue else : count+=1 max_count=max(max_count,count) print(max_count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var inp : OclAny := input().split() ; var l : Sequence := inp->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var count : int := 1 ; var max_count : int := 1 ; for i : Integer.subrange(0, n - 1-1) do ( if (l[i+1]->compareTo(l[i + 1+1])) > 0 then ( max_count := Set{max_count, count}->max() ; count := 1 ; continue ) else ( count := count + 1 )) ; max_count := Set{max_count, count}->max() ; execute (max_count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) numbers=list(map(int,input().split())) c1,c2=1,1 for i in range(1,n): if numbers[i]>=numbers[i-1]: c1+=1 else : if c1>c2 : c2=c1 c1=1 if c1>1 and c2toInteger() ; var numbers : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c1 : OclAny := null; var c2 : OclAny := null; Sequence{c1,c2} := Sequence{1,1} ; for i : Integer.subrange(1, n-1) do ( if (numbers[i+1]->compareTo(numbers[i - 1+1])) >= 0 then ( c1 := c1 + 1 ) else ( if (c1->compareTo(c2)) > 0 then ( var c2 : OclAny := c1 ) else skip ; var c1 : int := 1 )) ; if c1 > 1 & (c2->compareTo(c1)) < 0 then ( c2 := c1 ) else skip ; execute (c2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d,l=map(int,input().split()) print(d//l+d % l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : OclAny := null; var l : OclAny := null; Sequence{d,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (d div l + d mod l)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- D,L=map(int,input().split()) if L<=D : if D % L==0 : print(D//L) else : print(D//L+D % L) else : print(D) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var D : OclAny := null; var L : OclAny := null; Sequence{D,L} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (L->compareTo(D)) <= 0 then ( if D mod L = 0 then ( execute (D div L)->display() ) else ( execute (D div L + D mod L)->display() ) ) else ( execute (D)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input(); t=[*map(int,input())]; f=0,*input().split(); c=0 ; a=0 for b in t : n=int(f[b]) if n>b or n==b and c : c=1 ; t[a]=n elif c : break a+=1 print(*t,sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input(); var t : Sequence := ((OclFile["System.in"]).readLine())->collect( _x | (OclType["int"])->apply(_x) ); var f : OclAny := 0,input().split(); var c : int := 0; var a : int := 0 ; for b : t do ( var n : int := ("" + ((f[b+1])))->toInteger() ; if (n->compareTo(b)) > 0 or n = b & c then ( c := 1; t[a+1] := n ) else (if c then ( break ) else skip) ; a := a + 1) ; execute ((argument * (test (logical_test (comparison (expr (atom (name t))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- D,L=map(int,input().split()) i=0 while D>=L : D=D-L i+=1 i+=D print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var D : OclAny := null; var L : OclAny := null; Sequence{D,L} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var i : int := 0 ; while (D->compareTo(L)) >= 0 do ( var D : double := D - L ; i := i + 1) ; i := i + D ; execute (i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(sum(divmod(*map(int,input().split())))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((Sequence{((argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))))) div (argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))`third), ((argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))))) mod (argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))`third)})->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def count_greater(arr,n): min=sys.maxsize ; counter=0 ; for i in range(n-1,-1,-1): if(arr[i]>min): counter+=1 ; if(arr[i]<=min): min=arr[i]; return counter ; if __name__=="__main__" : arr=[3,2,1,2,3,4,5]; n=len(arr); print(count_greater(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{3}->union(Sequence{2}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))))); ; n := (arr)->size(); ; execute (count_greater(arr, n))->display(); ) else skip; operation count_greater(arr : OclAny, n : OclAny) pre: true post: true activity: var min : (trailer . (name maxsize)) := (trailer . (name maxsize)); ; var counter : int := 0; ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if ((arr[i+1]->compareTo(min)) > 0) then ( counter := counter + 1; ) else skip ; if ((arr[i+1]->compareTo(min)) <= 0) then ( min := arr[i+1]; ) else skip) ; return counter;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- D,L=[int(x)for x in input().split()] print((D//L)+(D % L)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var D : OclAny := null; var L : OclAny := null; Sequence{D,L} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((D div L) + (D mod L))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import re def solve(l): s=max(l) for a in range(1,s): s=min(s,reduce(lambda x,y : x-(-y)/a-1,l,a)) return(s) inp=open("B-large.in","r") out=open("B-large","w") lines=inp.readlines() for i in range(1,len(lines)/2+1): l=[int(x)for x in re.split(" ",lines[2*i])] out.write("Case #"+str(i)+": "+str(solve(l))+"\n") out.close() inp.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var inp : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("B-large.in")) ; var out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("B-large")) ; var lines : OclAny := inp.readlines() ; for i : Integer.subrange(1, (lines)->size() / 2 + 1-1) do ( l := (lines[2 * i+1])->split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; out.write("Case #" + ("" + ((i))) + ": " + ("" + ((solve(l)))) + "\n")) ; out.closeFile() ; inp.closeFile(); operation solve(l : OclAny) : OclAny pre: true post: true activity: var s : OclAny := (l)->max() ; for a : Integer.subrange(1, s-1) do ( s := Set{s, reduce(lambda x : OclAny, y : OclAny in (x - (-y) / a - 1), l, a)}->min()) ; return (s); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- DESCRIPTION=""" """ import os import sys import argparse def perr(msg): sys.stderr.write("%s" % msg) sys.stderr.flush() def pinfo(msg): sys.stdout.write("%s" % msg) sys.stdout.flush() def runcmd(cmd): perr("%s\n" % cmd) os.system(cmd) def getargs(): parser=argparse.ArgumentParser(description=DESCRIPTION,formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('infile',type=str,help='input file') parser.add_argument('outfile',type=str,nargs='?',default=None,help='output file') return parser.parse_args() def steps_to_get_Pmax_eq_p(P,Pmax): nstep=0 for p in P : nstep+=((p-1)/Pmax) return nstep def solve(D,P): min_costs=max(P) for Pmax in range(1,max(P)+1): N=steps_to_get_Pmax_eq_p(P,Pmax) costs=N+Pmax if costsmax() ; for Pmax : Integer.subrange(1, (P)->max() + 1-1) do ( var N : OclAny := steps_to_get_Pmax_eq_p(P, Pmax) ; var costs : OclAny := N + Pmax ; if (costs->compareTo(min_costs)) < 0 then ( min_costs := costs ) else skip) ; return min_costs; operation main(args : OclAny) pre: true post: true activity: if null = args.outfile then ( var outfile : OclFile := OclFile["System.out"] ) else ( outfile := OclFile.newOclFile_Write(OclFile.newOclFile(args.outfile)) ) ; try (var infile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(args.infile)); var T : int := ("" + ((infile.readLine())))->toInteger() ; for i : Integer.subrange(1, T + 1-1) do ( D := ("" + ((infile.readLine())))->toInteger() ; P := infile.readLine().split()->select(p | true)->collect(p | (("" + ((p)))->toInteger())) ; outfile.write(StringLib.format("Case #%d: %d\n",Sequence{i, solve(D, P)})))) catch (_e : OclException) do skip ; if null /= args.outfile then ( outfile.closeFile() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys def findsol(P,D): P.sort() T=P[len(P)-1] for jj in range(1,T): N=0 for kk in P : N+=math.ceil(kk/jj)-1 T2=N+jj if(T2toInteger() ; for ii : Integer.subrange(1, T + 1-1) do ( D := ("" + ((fidi.readLine())))->toInteger() ; P := fidi.readLine() ; P := convertnums(P) ; a := findsol(P, D) ; fido.write('Case #' + ("" + ((ii))) + ': ' + ("" + ((a))) + ' ') ; execute ('Case #')->display()) ; fidi.closeFile() ; fido.closeFile(); operation findsol(P : OclAny, D : OclAny) : OclAny pre: true post: true activity: P := P->sort() ; var T : OclAny := P[(P)->size() - 1+1] ; for jj : Integer.subrange(1, T-1) do ( var N : int := 0 ; for kk : P do ( N := N + (kk / jj)->ceil() - 1) ; var T2 : int := N + jj ; if ((T2->compareTo(T)) < 0) then ( T := T2 ) else skip) ; return T; operation convertnums(s : OclAny) : OclAny pre: true post: true activity: var a : Sequence := Sequence{} ; var ii : int := 0 ; for jj : Integer.subrange(0, (s)->size()-1) do ( if s[jj+1] = ' ' then ( if ((ii->compareTo(jj)) < 0) then ( execute ((("" + ((s.subrange(ii+1, jj))))->toInteger()) : a) ; ii := jj + 1 ) else skip ) else skip) ; execute ((("" + ((s.subrange(ii+1, jj))))->toInteger()) : a) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for case in range(1,T+1): input() p=[int(i)for i in input().split()] ans=min(e+sum(-(-i//e)-1 for i in p)for e in range(1,max(p)+1)) print("Case #{}:{}".format(case,ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for case : Integer.subrange(1, T + 1-1) do ( input() ; var p : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name e))) + (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr - (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr - (expr (atom (name i)))) // (expr (atom (name e)))))))) )))) - (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name p)))))))) )))))))) (comp_for for (exprlist (expr (atom (name e)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p)))))))) )))) + (expr (atom (number (integer 1)))))))))) )))))))))->min() ; execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{case, ans}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math if __name__=='__main__' : n=int(sys.stdin.readline()) for i in range(n): sys.stdout.write("Case #{}: ".format(i+1)) n=int(sys.stdin.readline()) l=map(int,sys.stdin.readline().split(' ')) m=max(l) ans=m for i in range(1,m+1): d=0 for p in l : if p>i : d=d+int(math.ceil(p/float(i)))-1 ans=min(ans,d+i) sys.stdout.write("{}\n".format(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ((expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Case #{}: ") (trailer . (name format) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ))))))))) )))) ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := (sys.stdin.readLine().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var m : OclAny := (l)->max() ; var ans : OclAny := m ; for i : Integer.subrange(1, m + 1-1) do ( var d : int := 0 ; for p : l do ( if (p->compareTo(i)) > 0 then ( d := d + ("" + (((p / ("" + ((i)))->toReal())->ceil())))->toInteger() - 1 ) else skip) ; ans := Set{ans, d + i}->min()) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "{}\n") (trailer . (name format) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline sys.setrecursionlimit(10**7) n=int(input()) xy=[[[]for _ in range(10**5+1)]for __ in range(2)] for _ in range(n): x,y=map(int,input().split()) xy[0][x].append(y) xy[1][y].append(x) ans=0 used=[[False for _ in range(10**5+1)]for __ in range(2)] def dfs(i,flag): for v in xy[flag][i]: if not used[1-flag][v]: used[1-flag][v]=True dfs(v,1-flag) count[1-flag]+=1 for i in range(10**5+1): if xy[0][i]and not used[0][i]: used[0][i]=True count=[1,0] dfs(i,0) ans+=count[0]*count[1] ans-=n print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit((10)->pow(7)) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var xy : Sequence := Integer.subrange(0, 2-1)->select(__ | true)->collect(__ | (Integer.subrange(0, (10)->pow(5) + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})))) ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name xy)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))) ; (expr (atom (name xy)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))) ; var ans : int := 0 ; var used : Sequence := Integer.subrange(0, 2-1)->select(__ | true)->collect(__ | (Integer.subrange(0, (10)->pow(5) + 1-1)->select(_anon | true)->collect(_anon | (false)))) ; skip ; for i : Integer.subrange(0, (10)->pow(5) + 1-1) do ( if xy->first()[i+1] & not(used->first()[i+1]) then ( used->first()[i+1] := true ; var count : Sequence := Sequence{1}->union(Sequence{ 0 }) ; dfs(i, 0) ; ans := ans + count->first() * count[1+1] ) else skip) ; ans := ans - n ; execute (ans)->display(); operation dfs(i : OclAny, flag : OclAny) pre: true post: true activity: for v : xy[flag+1][i+1] do ( if not(used[1 - flag+1][v+1]) then ( used[1 - flag+1][v+1] := true ; dfs(v, 1 - flag) ; count[1 - flag+1] := count[1 - flag+1] + 1 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter class UnionFind : def __init__(self,size): self.data=[-1]*size def find(self,x): if self.data[x]<0 : return x else : self.data[x]=self.find(self.data[x]) return self.data[x] def union(self,x,y): x,y=self.find(x),self.find(y) if x!=y : if self.data[y]exists( _x | result = _x ); attribute data : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, size); operation initialise(size : OclAny) : UnionFind pre: true post: true activity: self.data := MatrixLib.elementwiseMult(Sequence{ -1 }, size); return self; operation find(x : OclAny) : OclAny pre: true post: true activity: if self.data[x+1] < 0 then ( return x ) else ( self.data[x+1] := self->indexOf(self.data[x+1]) - 1 ; return self.data[x+1] ); operation union(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: Sequence{x,y} := Sequence{self->indexOf(x) - 1,self->indexOf(y) - 1} ; if x /= y then ( if (self.data[y+1]->compareTo(self.data[x+1])) < 0 then ( Sequence{x,y} := Sequence{y,x} ) else skip ; self.data[x+1] := self.data[x+1] + self.data[y+1] ; self.data[y+1] := x ) else skip ; return (x /= y); operation same(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: return (self->indexOf(x) - 1 = self->indexOf(y) - 1); operation size(x : OclAny) : OclAny pre: true post: true activity: return -self.data[self->indexOf(x) - 1+1]; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var MAX : double := (10)->pow(5) + 10 ; var uf : UnionFind := (UnionFind.newUnionFind()).initialise(2 * MAX) ; var N : OclAny := null; var XY : OclAny := null; Sequence{N,XY} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for _tuple : Integer.subrange(1, (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name XY)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name XY)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name iter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name XY)))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))`third->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); uf.union(x, y + MAX)) ; var X : OclAny := Counter((argument (test (logical_test (comparison (expr (atom (name uf)) (trailer . (name find) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name MAX)))))))) ))))))))) ; var Y : OclAny := Counter((argument (test (logical_test (comparison (expr (atom (name uf)) (trailer . (name find) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name MAX))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name MAX))) * (expr (atom (number (integer 2)))))))))) ))))))))) ; var res : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name X)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) * (expr (atom (name Y)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name MAX))) * (expr (atom (number (integer 2)))))))))) )))))))))->sum() ; execute (res - N)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def make_divisors(n): lower_divisors,upper_divisors=[],[] i=1 while i*i<=n : if n % i==0 : lower_divisors.append(i) if i!=n//i : upper_divisors.append(n//i) i+=1 return lower_divisors+upper_divisors[: :-1] N=int(input()) s=list(map(int,input().split())) D=[[]] for i in range(1,N): DD=[] T=[0] for j in range(i,N,i): T.append(T[-1]+s[j]) DD.append(T) T=[0] start=(N-1)% i if start==0 : start+=i for j in range(start,N,i): T.append(T[-1]+s[j]) DD.append(T) D.append(DD) ans=s[-1] cnt=0 for n in range(2,N-1): end=N-1-n for m in make_divisors(end): if n<=m : break if n % m==0 and end>=n : continue k=end//m a=D[m][0][k] l=len(D[m][1]) b=D[m][1][-1]-D[m][1][l-k-2] ans=max(ans,a+b) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var D : Sequence := Sequence{ Sequence{} } ; for i : Integer.subrange(1, N-1) do ( var DD : Sequence := Sequence{} ; var T : Sequence := Sequence{ 0 } ; for j : Integer.subrange(i, N-1)->select( $x | ($x - i) mod i = 0 ) do ( execute ((T->last() + s[j+1]) : T)) ; execute ((T) : DD) ; T := Sequence{ 0 } ; var start : int := (N - 1) mod i ; if start = 0 then ( start := start + i ) else skip ; for j : Integer.subrange(start, N-1)->select( $x | ($x - start) mod i = 0 ) do ( execute ((T->last() + s[j+1]) : T)) ; execute ((T) : DD) ; execute ((DD) : D)) ; var ans : OclAny := s->last() ; var cnt : int := 0 ; for n : Integer.subrange(2, N - 1-1) do ( var end : double := N - 1 - n ; for m : make_divisors(end) do ( if (n->compareTo(m)) <= 0 then ( break ) else skip ; if n mod m = 0 & (end->compareTo(n)) >= 0 then ( continue ) else skip ; var k : int := end div m ; var a : OclAny := D[m+1]->first()[k+1] ; var l : int := (D[m+1][1+1])->size() ; var b : double := D[m+1][1+1]->last() - D[m+1][1+1][l - k - 2+1] ; ans := Set{ans, a + b}->max())) ; execute (ans)->display(); operation make_divisors(n : OclAny) : OclAny pre: true post: true activity: var lower_divisors : OclAny := null; var upper_divisors : OclAny := null; Sequence{lower_divisors,upper_divisors} := Sequence{Sequence{},Sequence{}} ; var i : int := 1 ; while (i * i->compareTo(n)) <= 0 do ( if n mod i = 0 then ( execute ((i) : lower_divisors) ; if i /= n div i then ( execute ((n div i) : upper_divisors) ) else skip ) else skip ; i := i + 1) ; return lower_divisors + upper_divisors(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline import copy N=int(input()) P=[list(map(int,input().split()))+[i]for i in range(N)] Q=copy.deepcopy(P) Group=[i for i in range(N)] def find(x): while Group[x]!=x : x=Group[x] return x def Union(x,y): if find(x)!=find(y): Group[find(y)]=Group[find(x)]=min(find(y),find(x)) P.sort(key=lambda x : x[0]) for i in range(1,N): if P[i][0]==P[i-1][0]: Union(P[i][2],P[i-1][2]) P.sort(key=lambda x : x[1]) for i in range(1,N): if P[i][1]==P[i-1][1]: Union(P[i][2],P[i-1][2]) B=[[]for i in range(N)] for i in range(N): B[find(i)].append(i) ANS=0 for BEL in B : X=[] Y=[] for b in BEL : X.append(Q[b][0]) Y.append(Q[b][1]) ANS+=len(set(X))*len(set(Y))-len(BEL) print(ANS) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var P : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->union(Sequence{ i }))) ; var Q : OclAny := copy.deepcopy(P) ; var Group : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (i)) ; skip ; skip ; P := P->sort() ; for i : Integer.subrange(1, N-1) do ( if P[i+1]->first() = P[i - 1+1]->first() then ( Union(P[i+1][2+1], P[i - 1+1][2+1]) ) else skip) ; P := P->sort() ; for i : Integer.subrange(1, N-1) do ( if P[i+1][1+1] = P[i - 1+1][1+1] then ( Union(P[i+1][2+1], P[i - 1+1][2+1]) ) else skip) ; var B : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, N-1) do ((expr (atom (name B)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name find)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var ANS : int := 0 ; for BEL : B do ( var X : Sequence := Sequence{} ; var Y : Sequence := Sequence{} ; for b : BEL do ( execute ((Q[b+1]->first()) : X) ; execute ((Q[b+1][1+1]) : Y)) ; ANS := ANS + (Set{}->union((X)))->size() * (Set{}->union((Y)))->size() - (BEL)->size()) ; execute (ANS)->display(); operation find(x : OclAny) : OclAny pre: true post: true activity: while Group[x+1] /= x do ( x := Group[x+1]) ; return x; operation Union(x : OclAny, y : OclAny) pre: true post: true activity: if find(x) /= find(y) then ( Group[find(y)+1] := Set{find(y), find(x)}->min(); var Group[find(x)+1] : OclAny := Set{find(y), find(x)}->min() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=map(int,input().split()) a_list=list(map(int,input().split())) a_list.sort() count=0 for i in range(n): x=x-a_list[i] count+=1 if x<=0 : break if x==0 : print(count) else : print(count-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a_list := a_list->sort() ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x : double := x - a_list[i+1] ; count := count + 1 ; if x <= 0 then ( break ) else skip) ; if x = 0 then ( execute (count)->display() ) else ( execute (count - 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**7) def dfs(G,F,crr,pre,ret,st): F[crr]=False if crr<10**5 : ret[0]+=1 else : ret[1]+=1 for nxt in G[crr]: if nxt==pre : continue p,q=crr,nxt if q

0 : tmp=[0]*3 dfs(G,F,i,-1,tmp,st) ans+=tmp[0]*tmp[1]-tmp[2] print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation dfs(G : OclAny, F : OclAny, crr : OclAny, pre : OclAny, ret : OclAny, st : OclAny) pre: true post: true activity: F[crr+1] := false ; if (crr->compareTo((10)->pow(5))) < 0 then ( ret->first() := ret->first() + 1 ) else ( ret[1+1] := ret[1+1] + 1 ) ; for nxt : G[crr+1] do ( if nxt = pre then ( continue ) else skip ; var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := Sequence{crr,nxt} ; if (q->compareTo(p)) < 0 then ( var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := Sequence{q,p} ) else skip ; if not((st)->includes(Sequence{p, q})) then ( execute ((Sequence{p, q}) : st) ; ret[2+1] := ret[2+1] + 1 ) else skip ; if F[nxt+1] then ( dfs(G, F, nxt, crr, ret, st) ) else skip); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; G := Integer.subrange(0, 2 * (10)->pow(5)-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{x - 1,y - 1 + (10)->pow(5)} ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))) ; F := MatrixLib.elementwiseMult(Sequence{ true }, (2 * (10)->pow(5))) ; var ans : int := 0 ; st := Set{}->union(()) ; for i : Integer.subrange(0, 2 * (10)->pow(5)-1) do ( if F[i+1] & (G[i+1])->size() > 0 then ( var tmp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 3) ; dfs(G, F, i, -1, tmp, st) ; ans := ans + tmp->first() * tmp[1+1] - tmp[2+1] ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque N=int(input()) nmax=2*10**5 nhalf=10**5 G=[[]for i in range(nmax)] for i in range(N): x,y=map(int,input().split()) G[x-1].append(nhalf+y-1) G[nhalf+y-1].append(x-1) used=[False]*nmax ans=0 for i in range(nhalf): if G[i]!=[]and not used[i]: cnt_1=0 cnt_2=0 q=deque([i]) used[i]=True while len(q)>0 : a=q.popleft() if atoInteger() ; var nmax : double := 2 * (10)->pow(5) ; var nhalf : double := (10)->pow(5) ; var G : Sequence := Integer.subrange(0, nmax-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, N-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name nhalf))) + (expr (atom (name y)))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name nhalf))) + (expr (atom (name y)))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ))))) ; var used : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, nmax) ; var ans : int := 0 ; for i : Integer.subrange(0, nhalf-1) do ( if G[i+1] /= Sequence{} & not(used[i+1]) then ( var cnt skip : int := 0 ; var cnt:= 0 : int := 0 ; var q : Sequence := (Sequence{ i }) ; used[i+1] := true ; while (q)->size() > 0 do ( var a : OclAny := q->first() ; q := q->tail() ; if (a->compareTo(nhalf)) < 0 then ( cnt + 1 := cnt + 1 + 1 ) else ( cnt var a : OclAny := q->first() ; q := q->tail() := cnt var a : OclAny := q->first() ; q := q->tail() + 1 ) ; var Vs : OclAny := G[a+1] ; for u : Vs do ( if not(used[u+1]) then ( execute ((u) : q) ; used[u+1] := true ) else skip)) ; ans := ans + cnt var cnt skip : int := 0 * cnt_2 ) else skip) ; execute (ans - N)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(st): n=len(st) if(((int)(st[n-1])% 2)!=0): return False digitSum=0 for i in range(0,n): digitSum=digitSum+(int)(st[i]) return(digitSum % 3==0) st="1332" if(check(st)): print("Yes") else : print("No ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; st := "1332" ; if (check(st)) then ( execute ("Yes")->display() ) else ( execute ("No ")->display() ); operation check(st : OclAny) : OclAny pre: true post: true activity: var n : int := (st)->size() ; if (((OclType["int"])(st[n - 1+1]) mod 2) /= 0) then ( return false ) else skip ; var digitSum : int := 0 ; for i : Integer.subrange(0, n-1) do ( digitSum := digitSum + (OclType["int"])(st[i+1])) ; return (digitSum mod 3 = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(st): n=len(st) digitSum=0 for i in range(0,n): digitSum=digitSum+(int)(st[i]) return(digitSum % 9==0) st="99333" if(check(st)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; st := "99333" ; if (check(st)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation check(st : OclAny) : OclAny pre: true post: true activity: var n : int := (st)->size() ; var digitSum : int := 0 ; for i : Integer.subrange(0, n-1) do ( digitSum := digitSum + (OclType["int"])(st[i+1])) ; return (digitSum mod 9 = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def letterCasePermutation(self,S): B=sum(letter.isalpha()for letter in S) ans=[] for bits in xrange(1<>b)& 1 : word.append(letter.lower()) else : word.append(letter.upper()) b+=1 else : word.append(letter) ans.append("".join(word)) return ans ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation letterCasePermutation(S : OclAny) : OclAny pre: true post: true activity: var B : OclAny := ((argument (test (logical_test (comparison (expr (atom (name letter)) (trailer . (name isalpha) (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name letter)))) in (logical_test (comparison (expr (atom (name S))))))))->sum() ; var ans : Sequence := Sequence{} ; for bits : xrange(1 * (2->pow(B))) do ( var b : int := 0 ; var word : Sequence := Sequence{} ; for letter : S do ( if letter->matches("[a-zA-Z]*") then ( if MathLib.bitwiseAnd((bits /(2->pow(b))), 1) then ( execute ((letter->toLowerCase()) : word) ) else ( execute ((letter->toUpperCase()) : word) ) ; b := b + 1 ) else ( execute ((letter) : word) )) ; execute ((StringLib.sumStringsWithSeparator((word), "")) : ans)) ; return ans; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def countDigits(n): return int(n*math.log10(2)+1); n=5 ; print(countDigits(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 5; ; execute (countDigits(n))->display();; operation countDigits(n : OclAny) pre: true post: true activity: return ("" + ((n * (2)->log10() + 1)))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,floor def isPerfectSquare(N): sr=sqrt(N) return(sr-floor(sr))==0 def BetrothedNumbers(n,m): Sum1=1 Sum2=1 for i in range(2,int(sqrt(n))+1,1): if(n % i==0): if(isPerfectSquare(n)): Sum1+=i else : Sum1+=i+n/i for i in range(2,int(sqrt(m))+1,1): if(m % i==0): if(isPerfectSquare(m)): Sum2+=i else : Sum2+=i+(m/i) if((n+1==Sum2)and(m+1==Sum1)): print("YES") else : print("NO") if __name__=='__main__' : N=9504 M=20734 BetrothedNumbers(N,M) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( N := 9504 ; var M : int := 20734 ; BetrothedNumbers(N, M) ) else skip; operation isPerfectSquare(N : OclAny) : OclAny pre: true post: true activity: var sr : OclAny := sqrt(N) ; return (sr - floor(sr)) = 0; operation BetrothedNumbers(n : OclAny, m : OclAny) pre: true post: true activity: var Sum1 : int := 1 ; var Sum2 : int := 1 ; for i : Integer.subrange(2, ("" + ((sqrt(n))))->toInteger() + 1-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (n mod i = 0) then ( if (isPerfectSquare(n)) then ( Sum1 := Sum1 + i ) else ( Sum1 := Sum1 + i + n / i ) ) else skip) ; for i : Integer.subrange(2, ("" + ((sqrt(m))))->toInteger() + 1-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (m mod i = 0) then ( if (isPerfectSquare(m)) then ( Sum2 := Sum2 + i ) else ( Sum2 := Sum2 + i + (m / i) ) ) else skip) ; if ((n + 1 = Sum2) & (m + 1 = Sum1)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import array def compute(): LIMIT=40000000 totient=list_totients(LIMIT-1) totientchainlen=array.array("L",[0,1]) ans=0 for i in range(len(totientchainlen),len(totient)): chainlen=totientchainlen[totient[i]]+1 totientchainlen.append(chainlen) if chainlen==25 and totient[i]==i-1 : ans+=i return str(ans) def list_totients(n): assert n<(1<<32) result=array.array("L",range(n+1)) for i in range(2,n+1): if result[i]==i : for j in range(i,n+1,i): result[j]=result[j]//i*(i-1) return result if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LIMIT : int := 40000000 ; var totient : OclAny := list_totients(LIMIT - 1) ; var totientchainlen : OclAny := array.array("L", Sequence{0}->union(Sequence{ 1 })) ; var ans : int := 0 ; for i : Integer.subrange((totientchainlen)->size(), (totient)->size()-1) do ( var chainlen : OclAny := totientchainlen[totient[i+1]+1] + 1 ; execute ((chainlen) : totientchainlen) ; if chainlen = 25 & totient[i+1] = i - 1 then ( ans := ans + i ) else skip) ; return ("" + ((ans))); operation list_totients(n : OclAny) : OclAny pre: true post: true activity: assert (n->compareTo((1 * (2->pow(32))))) < 0 do "assertion failed" ; var result : OclAny := array.array("L", Integer.subrange(0, n + 1-1)) ; for i : Integer.subrange(2, n + 1-1) do ( if result[i+1] = i then ( for j : Integer.subrange(i, n + 1-1)->select( $x | ($x - i) mod i = 0 ) do ( result[j+1] := result[j+1] div i * (i - 1)) ) else skip) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : t-=1 n=int(input()) a=list(map(int,input().split(' '))) ans=0 b=set() for i in range(0,n): if(a[i]in b)==False : ans+=1 b.add(a[i]) elif(a[i]+1 in b)==False : ans+=1 b.add(a[i]+1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( t := t - 1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; var b : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( if ((b)->includes(a[i+1])) = false then ( ans := ans + 1 ; execute ((a[i+1]) : b) ) else (if ((b)->includes(a[i+1] + 1)) = false then ( ans := ans + 1 ; execute ((a[i+1] + 1) : b) ) else skip)) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from heapq import heappush,heappop import sys import math import bisect import random def LI(): return[int(x)for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return[list(x)for x in sys.stdin.readline().split()] def S(): res=list(sys.stdin.readline()) if res[-1]=="\n" : return res[:-1] return res def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] sys.setrecursionlimit(1000000) mod=1000000007 def solve(): n=I() s=LI() ans=0 for c in range(1,n+1): K=(n-1)//c dp=0 S=set([0,n-1]) for k in range(1,K+1): a=i=n-1-k*c if i in S : break b=a-c if b>=a or b<=0 : break S.add(i) j=k*c if j in S : break S.add(j) cost=s[i]+s[j] dp+=cost if ansselect(x | true)->collect(x | (("" + ((x)))->toInteger())); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | ((x))); operation S() : OclAny pre: true post: true activity: var res : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if res->last() = "\n" then ( return res->front() ) else skip ; return res; operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation solve() pre: true post: true activity: n := I() ; var s : OclAny := LI() ; var ans : int := 0 ; for c : Integer.subrange(1, n + 1-1) do ( var K : int := (n - 1) div c ; var dp : int := 0 ; var S : Set := Set{}->union((Sequence{0}->union(Sequence{ n - 1 }))) ; for k : Integer.subrange(1, K + 1-1) do ( var a : OclAny := n - 1 - k * c; var i : double := n - 1 - k * c ; if (S)->includes(i) then ( break ) else skip ; var b : double := a - c ; if (b->compareTo(a)) >= 0 or b <= 0 then ( break ) else skip ; execute ((i) : S) ; var j : double := k * c ; if (S)->includes(j) then ( break ) else skip ; execute ((j) : S) ; var cost : OclAny := s[i+1] + s[j+1] ; dp := dp + cost ; if (ans->compareTo(dp)) < 0 then ( ans := dp ) else skip)) ; execute (ans)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import socket if socket.gethostname()in['N551J','F551C']: sys.stdin=open('a1.in') def read_int_list(): return list(map(int,input().split())) def read_int(): return int(input()) def read_str_list(): return input().split() def read_str(): return input() def solve(): n,x=read_int_list() a=read_int_list() a.sort() if sum(a)==x : return n res=0 for i in range(n): if sum(a[: i])<=x : res=i return res def main(): res=solve() print(res) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if (Sequence{'N551J'}->union(Sequence{ 'F551C' }))->includes(socket.gethostname()) then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('a1.in')) ) else skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation read_int_list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation read_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation read_str_list() : OclAny pre: true post: true activity: return input().split(); operation read_str() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation solve() : OclAny pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := read_int_list() ; var a : OclAny := read_int_list() ; a := a->sort() ; if (a)->sum() = x then ( return n ) else skip ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ((a.subrange(1,i))->sum()->compareTo(x)) <= 0 then ( res := i ) else skip) ; return res; operation main() pre: true post: true activity: res := solve() ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) s=set() num=map(int,input().split()) for j in num : if j in s : s.add(j+1) else : s.add(j) print(len(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Set := Set{}->union(()) ; var num : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for j : num do ( if (s)->includes(j) then ( execute ((j + 1) : s) ) else ( execute ((j) : s) )) ; execute ((s)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: t=set(); for x in map(int,s.split()): t |={x+(x in t)} print(len(t)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var t : Set := Set{}->union(()); ; for x : (s.split())->collect( _x | (OclType["int"])->apply(_x) ) do ( t := t or Set{ x + ((t)->includes(x)) }) ; execute ((t)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : t=t-1 n=int(input()) a=[int(x)for x in input().split()] stack=[] stack1=[0,0] for i in range(0,len(a)): check=0 ii=len(a)-i-1 if not stack1 : stack1.append(a[ii]+1) else : x=a[ii]+1 if x!=stack1[-1]and x!=stack1[-2]: stack1.append(x) elif a[ii]!=stack1[-1]and a[ii]!=stack1[-2]: stack1.append(a[ii]) print(len(stack1)-2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( t := t - 1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var stack : Sequence := Sequence{} ; var stack1 : Sequence := Sequence{0}->union(Sequence{ 0 }) ; for i : Integer.subrange(0, (a)->size()-1) do ( var check : int := 0 ; var ii : double := (a)->size() - i - 1 ; if not(stack1) then ( execute ((a[ii+1] + 1) : stack1) ) else ( var x : OclAny := a[ii+1] + 1 ; if x /= stack1->last() & x /= stack1->front()->last() then ( execute ((x) : stack1) ) else (if a[ii+1] /= stack1->last() & a[ii+1] /= stack1->front()->last() then ( execute ((a[ii+1]) : stack1) ) else skip) )) ; execute ((stack1)->size() - 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) notes=list(map(int,input().split())) note_lst=set() diversity=0 for i in notes : if i in note_lst : if i+1 not in note_lst : note_lst.add(i+1) diversity+=1 else : note_lst.add(i) diversity+=1 print(diversity) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var notes : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var note_lst : Set := Set{}->union(()) ; var diversity : int := 0 ; for i : notes do ( if (note_lst)->includes(i) then ( if (note_lst)->excludes(i + 1) then ( execute ((i + 1) : note_lst) ; diversity := diversity + 1 ) else skip ) else ( execute ((i) : note_lst) ; diversity := diversity + 1 )) ; execute (diversity)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- case=1 while True : n=int(input()) if not n : break jpeg=[[0]*n for _ in range(n)] n1=n-1 px,cur=[0,0],1 while px[0]3}'.format(pixel)for pixel in row)) case+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var case : int := 1 ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(n) then ( break ) else skip ; var jpeg : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, n))) ; var n1 : double := n - 1 ; var px : OclAny := null; var cur : OclAny := null; Sequence{px,cur} := Sequence{Sequence{0}->union(Sequence{ 0 }),1} ; while (px->first()->compareTo(n)) < 0 do ( var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := px ; jpeg[i+1][j+1] := cur ; var odd : int := (i + j) mod 2 ; if px->select(not(odd)) = n1 then ( px[odd+1] := px[odd+1] + 1 ) else (if not(px[odd+1]) then ( px->select(not(odd)) := px->select(not(odd)) + 1 ) else ( px->select(not(odd)) := px->select(not(odd)) + 1 ; px[odd+1] := px[odd+1] - 1 ) ) ; cur := cur + 1) ; execute (StringLib.interpolateStrings('Case{}:', Sequence{case}))->display() ; for row : jpeg do ( execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom '{:>3}') (trailer . (name format) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name pixel)))))))) ))))))) (comp_for for (exprlist (expr (atom (name pixel)))) in (logical_test (comparison (expr (atom (name row)))))))), ''))->display()) ; case := case + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def p(t): for l in t : for n in l : print("{0:>3}".format(n),end="") print("") c=0 for n in sys.stdin : n=int(n) if n==0 : break t=[[0 for _ in range(n)]for _ in range(n)] c+=1 print("Case{}:".format(c)) x=0 y=0 up=True for i in range(1,n*n+1): t[y][x]=i if up : if y==0 : if xtoInteger() ; if n = 0 then ( break ) else skip ; t := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)))) ; c := c + 1 ; execute (StringLib.interpolateStrings("Case{}:", Sequence{c}))->display() ; var x : int := 0 ; var y : int := 0 ; var up : boolean := true ; for i : Integer.subrange(1, n * n + 1-1) do ( t[y+1][x+1] := i ; if up then ( if y = 0 then ( if (x->compareTo(n - 1)) < 0 then ( x := x + 1 ; up := false ) else ( y := y + 1 ; up := false ) ) else ( if (x->compareTo(n - 1)) < 0 then ( x := x + 1 ; y := y - 1 ) else ( y := y + 1 ; up := false ) ) ) else ( if x = 0 then ( if (y->compareTo(n - 1)) < 0 then ( y := y + 1 ; up := true ) else ( x := x + 1 ; up := true ) ) else ( if (y->compareTo(n - 1)) < 0 then ( x := x - 1 ; y := y + 1 ) else ( x := x + 1 ; up := true ) ) )) ; p(t)); operation p(t : OclAny) pre: true post: true activity: for l : t do ( for n : l do ( execute (StringLib.interpolateStrings("{0:>3}", Sequence{n}))->display()) ; execute ("")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : TC=1 while True : N=int(input()) if N==0 : break arr=[[0 for _ in range(N)]for _ in range(N)] i=0 j=0 val=1 prevMove="UR" while True : arr[i][j]=val val+=1 if i==N-1 and j==N-1 : break elif i==0 : if prevMove=="UR" : if j!=N-1 : j+=1 prevMove="R" else : i+=1 prevMove="D" else : i+=1 j-=1 prevMove="DL" elif i==N-1 : if prevMove=="DL" : j+=1 prevMove="R" else : i-=1 j+=1 prevMove="UR" elif j==0 : if prevMove=="DL" : i+=1 prevMove="D" else : i-=1 j+=1 prevMove="UR" elif j==N-1 : if prevMove=="UR" : i+=1 prevMove="D" else : i+=1 j-=1 prevMove="DL" else : if prevMove=="DL" : i+=1 j-=1 else : i-=1 j+=1 print("Case{}:".format(TC)) TC+=1 for i in range(N): for j in range(N): print("{:3d}".format(arr[i][j]),end='') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var TC : int := 1 ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var arr : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (0)))) ; var i : int := 0 ; var j : int := 0 ; var val : int := 1 ; var prevMove : String := "UR" ; while true do ( arr[i+1][j+1] := val ; val := val + 1 ; if i = N - 1 & j = N - 1 then ( break ) else (if i = 0 then ( if prevMove = "UR" then ( if j /= N - 1 then ( j := j + 1 ; prevMove := "R" ) else ( i := i + 1 ; prevMove := "D" ) ) else ( i := i + 1 ; j := j - 1 ; prevMove := "DL" ) ) else (if i = N - 1 then ( if prevMove = "DL" then ( j := j + 1 ; prevMove := "R" ) else ( i := i - 1 ; j := j + 1 ; prevMove := "UR" ) ) else (if j = 0 then ( if prevMove = "DL" then ( i := i + 1 ; prevMove := "D" ) else ( i := i - 1 ; j := j + 1 ; prevMove := "UR" ) ) else (if j = N - 1 then ( if prevMove = "UR" then ( i := i + 1 ; prevMove := "D" ) else ( i := i + 1 ; j := j - 1 ; prevMove := "DL" ) ) else ( if prevMove = "DL" then ( i := i + 1 ; j := j - 1 ) else ( i := i - 1 ; j := j + 1 ) ) ) ) ) ) ) ; execute (StringLib.interpolateStrings("Case{}:", Sequence{TC}))->display() ; TC := TC + 1 ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( execute (StringLib.interpolateStrings("{:3d}", Sequence{arr[i+1][j+1]}))->display()) ; execute (->display())) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=1 while 1 : N=int(input()) if N==0 : break print("Case %d:" % t); t+=1 M=[[0]*N for i in range(N)] c=1 for i in range(2*N-1): for j in range(max(i-N+1,0),min(N,i+1)): if i % 2==0 : M[i-j][j]="%3d" % c else : M[j][i-j]="%3d" % c c+=1 for l in M : print(*l,sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := 1 ; while 1 do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; execute (StringLib.format("Case %d:",t))->display(); t := t + 1 ; var M : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, N))) ; var c : int := 1 ; for i : Integer.subrange(0, 2 * N - 1-1) do ( for j : Integer.subrange(Set{i - N + 1, 0}->max(), Set{N, i + 1}->min()-1) do ( if i mod 2 = 0 then ( M[i - j+1][j+1] := StringLib.format("%3d",c) ) else ( M[j+1][i - j+1] := StringLib.format("%3d",c) ) ; c := c + 1)) ; for l : M do ( execute ((argument * (test (logical_test (comparison (expr (atom (name l))))))))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline cno=0 while True : n=int(input()) if n==0 : break cno+=1 a=[[0 for j in range(12)]for i in range(12)] m=k=f=1 ; while True : if f : for r in range(k-1,-1,-1): a[r][k-1-r]=m m+=1 else : for c in range(k-1,-1,-1): a[k-1-c][c]=m m+=1 f=1-f k+=1 if k>n : break k=n-1 while True : if f : for c in range(n-k,n): a[2*n-1-k-c][c]=m m+=1 else : for r in range(n-k,n): a[r][2*n-1-k-r]=m m+=1 f=1-f k-=1 if k<1 : break print("Case ",cno,":",sep='') for r in range(n): for c in range(n): print(format(a[r][c],"3d"),end='') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; var cno : int := 0 ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; cno := cno + 1 ; var a : Sequence := Integer.subrange(0, 12-1)->select(i | true)->collect(i | (Integer.subrange(0, 12-1)->select(j | true)->collect(j | (0)))) ; m := m(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name k)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name f)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))); ; while true do ( if f then ( for r : Integer.subrange(-1 + 1, k - 1)->reverse() do ( a[r+1][k - 1 - r+1] := m ; m := m + 1) ) else ( for c : Integer.subrange(-1 + 1, k - 1)->reverse() do ( a[k - 1 - c+1][c+1] := m ; m := m + 1) ) ; var f : double := 1 - f ; k := k + 1 ; if (k->compareTo(n)) > 0 then ( break ) else skip) ; var k : double := n - 1 ; while true do ( if f then ( for c : Integer.subrange(n - k, n-1) do ( a[2 * n - 1 - k - c+1][c+1] := m ; m := m + 1) ) else ( for r : Integer.subrange(n - k, n-1) do ( a[r+1][2 * n - 1 - k - r+1] := m ; m := m + 1) ) ; f := 1 - f ; k := k - 1 ; if k < 1 then ( break ) else skip) ; execute ("Case ")->display() ; for r : Integer.subrange(0, n-1) do ( for c : Integer.subrange(0, n-1) do ( execute ((a[r+1][c+1] + ""))->display()) ; execute (->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) a.sort() if a[n-1]>=a[n-2]+a[n-3]: print("NO") else : print("YES") for i in range(n-1,-1,-2): print(a[i],end=" ") for i in range(n % 2,n,2): print(a[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; if (a[n - 1+1]->compareTo(a[n - 2+1] + a[n - 3+1])) >= 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; for i : Integer.subrange(n - 1, -1-1)->select( $x | ($x - n - 1) mod -2 = 0 ) do ( execute (a[i+1])->display()) ; for i : Integer.subrange(n mod 2, n-1)->select( $x | ($x - n mod 2) mod 2 = 0 ) do ( execute (a[i+1])->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- amount_test_cases=int(input()) def is_in_range(left,right,target : list): if left<=target[0]<=right or left<=target[1]<=right : return True return False def print_total_positions(array_lenght,initial_range,operations): for range in operations : left=int(range[0]) right=int(range[1]) if is_in_range(left,right,initial_range): initial_range[0]=min(left,initial_range[0]) initial_range[1]=max(right,initial_range[1]) print((initial_range[1]-initial_range[0])+1) for _ in range(amount_test_cases): operations=[] array_lenght,index,amount_operations=input().split(" ") for _ in range(int(amount_operations)): operations.append(input().split(" ")) print_total_positions(array_lenght,[int(index),int(index)],operations) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var amount_test_cases : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; skip ; for _anon : Integer.subrange(0, amount_test_cases-1) do ( operations := Sequence{} ; var index : OclAny := null; var amount_operations : OclAny := null; Sequence{array_lenght,index,amount_operations} := input().split(" ") ; for _anon : Integer.subrange(0, ("" + ((amount_operations)))->toInteger()-1) do ( execute ((input().split(" ")) : operations)) ; print_total_positions(array_lenght, Sequence{("" + ((index)))->toInteger()}->union(Sequence{ ("" + ((index)))->toInteger() }), operations)); operation is_in_range(left : OclAny, right : OclAny, target : Sequence(OclAny)) : OclAny pre: true post: true activity: if (left->compareTo(target->first())) <= 0 & (target->first() <= right) or (left->compareTo(target[1+1])) <= 0 & (target[1+1] <= right) then ( return true ) else skip ; return false; operation print_total_positions(array_lenght : OclAny, initial_range : OclAny, operations : OclAny) pre: true post: true activity: for range : operations do ( left := ("" + (((arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))->toInteger() ; right := ("" + (((arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))->toInteger() ; if is_in_range(left, right, initial_range) then ( initial_range->first() := Set{left, initial_range->first()}->min() ; initial_range[1+1] := Set{right, initial_range[1+1]}->max() ) else skip) ; execute ((initial_range[1+1] - initial_range->first()) + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re,os from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,radians from itertools import permutations,combinations,product,accumulate from operator import itemgetter,mul from copy import deepcopy from string import ascii_lowercase,ascii_uppercase,digits from fractions import gcd def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def S_MAP(): return map(str,input().split()) def LIST(): return list(map(int,input().split())) def S_LIST(): return list(map(str,input().split())) sys.setrecursionlimit(10**9) INF=float('inf') mod=10**9+7 N,x=MAP() A=LIST() A.sort() cnt=0 for a in A : x-=a if x>=0 : cnt+=1 else : break if x>0 : print(cnt-1) else : print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var N : OclAny := null; var x : OclAny := null; Sequence{N,x} := MAP() ; var A : OclAny := LIST() ; A := A->sort() ; var cnt : int := 0 ; for a : A do ( x := x - a ; if x >= 0 then ( cnt := cnt + 1 ) else ( break )) ; if x > 0 then ( execute (cnt - 1)->display() ) else ( execute (cnt)->display() ); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation S_MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["String"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation S_LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["String"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate N,*S=map(int,open(0).read().split()) ans=0 for dx in range(1,N-1): k,r=divmod(N-1,dx) if r==0 : k=(k+1)//2 ans=max(ans,max(accumulate(a+b for a,b in zip(S[: dx*k : dx],S[N-1 :(N-1)-dx*k :-dx])))) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var S : OclAny := null; Sequence{N,S} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; for dx : Integer.subrange(1, N - 1-1) do ( var k : OclAny := null; var r : OclAny := null; Sequence{k,r} := Sequence{(N - 1 div dx), (N - 1 mod dx)} ; if r = 0 then ( var k : int := (k + 1) div 2 ) else skip ; ans := Set{ans, (accumulate((argument (test (logical_test (comparison (expr (expr (atom (name a))) + (expr (atom (name b))))))) (comp_for for (exprlist (expr (atom (name a))) , (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (expr (atom (name dx))) * (expr (atom (name k))))))) (sliceop : (test (logical_test (comparison (expr (atom (name dx))))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name N))) - (expr (atom (number (integer 1)))))))) : (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name N))) - (expr (atom (number (integer 1))))))))) ))) - (expr (expr (atom (name dx))) * (expr (atom (name k)))))))) (sliceop : (test (logical_test (comparison (expr - (expr (atom (name dx)))))))))) ])))))))) ))))))))))->max()}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) l.sort() x=l[-1] l.pop(-1) g=-2 for i in range(len(l)+1): if(l[i-1]+l[(i)% len(l)])>x : if i>g : g=i if g>-1 : print('YES') l.insert(g,x) for i in l : print(i,end=' ') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := l->sort() ; var x : OclAny := l->last() ; l := l->excludingAt(-1+1) ; var g : int := -2 ; for i : Integer.subrange(0, (l)->size() + 1-1) do ( if ((l[i - 1+1] + l[(i) mod (l)->size()+1])->compareTo(x)) > 0 then ( if (i->compareTo(g)) > 0 then ( g := i ) else skip ) else skip) ; if g > -1 then ( execute ('YES')->display() ; l := l.insertAt(g+1, x) ; for i : l do ( execute (i)->display()) ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) a.sort() if a[n-1]>=a[n-2]+a[n-3]: print("NO") else : print("YES") for i in range(n-1,-1,-2): print(a[i],end=" ") for i in range(n % 2,n,2): print(a[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; if (a[n - 1+1]->compareTo(a[n - 2+1] + a[n - 3+1])) >= 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; for i : Integer.subrange(n - 1, -1-1)->select( $x | ($x - n - 1) mod -2 = 0 ) do ( execute (a[i+1])->display()) ; for i : Integer.subrange(n mod 2, n-1)->select( $x | ($x - n mod 2) mod 2 = 0 ) do ( execute (a[i+1])->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) a.sort() if(a[-3]+a[-2]>a[-1]): print("YES") print(*a[:-2],*a[-2 :][: :-1]) else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; if ((a->reverse()->at(-(-3)) + a->front()->last()->compareTo(a->last())) > 0) then ( execute ("YES")->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom - (number (integer 2))))))))) ]))))))))->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) a=list(map(int,input().split())) a.sort(reverse=True) a[0],a[1]=a[1],a[0] ans="YES" if a[1]toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var a->first() : OclAny := null; var a[1+1] : OclAny := null; Sequence{a->first(),a[1+1]} := Sequence{a[1+1],a->first()} ; var ans : String := if (a[1+1]->compareTo(a->first() + a[2+1])) < 0 then "YES" else "NO" endif ; execute (ans)->display() ; if ans = "YES" then ( (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " ") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))))))) ))))))))) )))) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def XorSum(arr,n): result=0 for i in range(0,n): k=0 for j in range(1,arr[i]+1): k=k ^ arr[i] result=result+k return result arr=[1,2,6,3,4,5] n=len(arr) print(XorSum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{6}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 }))))) ; n := (arr)->size() ; execute (XorSum(arr, n))->display(); operation XorSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; for i : Integer.subrange(0, n-1) do ( var k : int := 0 ; for j : Integer.subrange(1, arr[i+1] + 1-1) do ( k := MathLib.bitwiseXor(k, arr[i+1])) ; result := result + k) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findGreatest(arr,n): result=-1 for i in range(n): for j in range(n-1): for k in range(j+1,n): if(arr[j]*arr[k]==arr[i]): result=max(result,arr[i]) return result if __name__=="__main__" : arr=[30,10,9,3,35] n=len(arr) print(findGreatest(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{30}->union(Sequence{10}->union(Sequence{9}->union(Sequence{3}->union(Sequence{ 35 })))) ; n := (arr)->size() ; execute (findGreatest(arr, n))->display() ) else skip; operation findGreatest(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var result : int := -1 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n - 1-1) do ( for k : Integer.subrange(j + 1, n-1) do ( if (arr[j+1] * arr[k+1] = arr[i+1]) then ( result := Set{result, arr[i+1]}->max() ) else skip))) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() for i in range(n-1): if(s[i]!=s[i+1]): print("YES") print(s[i],s[i+1],sep="") exit(0) print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, n - 1-1) do ( if (s[i+1] /= s[i + 1+1]) then ( execute ("YES")->display() ; execute (s[i+1])->display() ; exit(0) ) else skip) ; execute ("NO")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(n,s): for i in range(n-1): if s[i]!=s[i+1]: print('YES') print(s[i]+s[i+1]) return print('NO') return n=int(input()) s=input() f(n,s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; s := (OclFile["System.in"]).readLine() ; f(n, s); operation f(n : OclAny, s : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n - 1-1) do ( if s[i+1] /= s[i + 1+1] then ( execute ('YES')->display() ; execute (s[i+1] + s[i + 1+1])->display() ; return ) else skip) ; execute ('NO')->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() ans=None ch=s[0] for i in range(1,n): if s[i]!=ch : ans=ch+s[i] break if ans==None : print("NO") else : print("YES") print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var ans : OclAny := null ; var ch : OclAny := s->first() ; for i : Integer.subrange(1, n-1) do ( if s[i+1] /= ch then ( ans := ch + s[i+1] ; break ) else skip) ; if ans = null then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- na=lambda : list(map(int,input().split())) n,x=na() a=sorted(na()) ans=0 if a[0]>x : print(0) exit() for i in a : if i>x : x=0 break x-=i ans+=1 if x!=0 : ans-=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var na : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := na->apply() ; var a : Sequence := na->apply()->sort() ; var ans : int := 0 ; if (a->first()->compareTo(x)) > 0 then ( execute (0)->display() ; exit() ) else skip ; for i : a do ( if (i->compareTo(x)) > 0 then ( var x : int := 0 ; break ) else skip ; x := x - i ; ans := ans + 1) ; if x /= 0 then ( ans := ans - 1 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() found=False for c1,c2 in zip(s[:-1],s[1 :]): if c1!=c2 : print("YES") print(c1+c2) found=True break if not found : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var found : boolean := false ; for _tuple : Integer.subrange(1, s->front()->size())->collect( _indx | Sequence{s->front()->at(_indx), s->tail()->at(_indx)} ) do (var _indx : int := 1; var c1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c2 : OclAny := _tuple->at(_indx); if c1 /= c2 then ( execute ("YES")->display() ; execute (c1 + c2)->display() ; found := true ; break ) else skip) ; if not(found) then ( execute ("NO")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines import numpy as np N=int(readline()) S=np.array(read().split(),np.int64) def F(d): L=S[:-d : d].cumsum() R=S[: :-1][:-d : d].cumsum() if(N-1)% d==0 : n=(N-1)//d x=np.arange(1,n+1) bl=(x+x<=n+1) L=L[bl]; R=R[bl] return(L+R).max() def G(n): D=(N-1-n)//n L=np.zeros(D+1,np.int64) R=np.zeros(D+1,np.int64) for i in range(1,n+1): L+=S[: i*(D+1): i] R+=S[: :-1][: i*(D+1): i] ok=np.ones(D+1,np.bool) overlap=(np.arange(D+1)*(n+n)>=N-1) overlap[1 :]&=((N-1)% np.arange(1,D+1)==0) x=L+R x[overlap]=0 return x.max() L=int((N-1)**.5+10) L=min(N-1,L) x=max(F(n)for n in range(1,L+1)) y=max(G(n)for n in range(1,L+1)) answer=max(x,y) print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; skip ; var N : int := ("" + ((readline())))->toInteger() ; var S : Sequence := (read().split(), ) ; skip ; skip ; L := ("" + ((((N - 1))->pow(.5) + 10)))->toInteger() ; L := Set{N - 1, L}->min() ; x := ((argument (test (logical_test (comparison (expr (atom (name F)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name L))) + (expr (atom (number (integer 1)))))))))) )))))))))->max() ; var y : OclAny := ((argument (test (logical_test (comparison (expr (atom (name G)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name L))) + (expr (atom (number (integer 1)))))))))) )))))))))->max() ; var answer : OclAny := Set{x, y}->max() ; execute (answer)->display(); operation F(d : OclAny) : OclAny pre: true post: true activity: var L : OclAny := S(subscript : (test (logical_test (comparison (expr - (expr (atom (name d))))))) (sliceop : (test (logical_test (comparison (expr (atom (name d)))))))).cumsum() ; var R : OclAny := S(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))(subscript : (test (logical_test (comparison (expr - (expr (atom (name d))))))) (sliceop : (test (logical_test (comparison (expr (atom (name d)))))))).cumsum() ; if (N - 1) mod d = 0 then ( var n : int := (N - 1) div d ; var x : Sequence := MathLib.numericRange(1, n + 1, 1) ; var bl : boolean := ((x->union(x)->compareTo(n + 1)) <= 0) ; L := L[bl+1]; R := R[bl+1] ) else skip ; return (L + R)->max(); operation G(n : OclAny) : OclAny pre: true post: true activity: var D : int := (N - 1 - n) div n ; L := MatrixLib.singleValueMatrix(D + 1, 0.0) ; R := MatrixLib.singleValueMatrix(D + 1, 0.0) ; for i : Integer.subrange(1, n + 1-1) do ( L := L + S(subscript : (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name D))) + (expr (atom (number (integer 1))))))))) ))))))) (sliceop : (test (logical_test (comparison (expr (atom (name i)))))))) ; R := R + S(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))(subscript : (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name D))) + (expr (atom (number (integer 1))))))))) ))))))) (sliceop : (test (logical_test (comparison (expr (atom (name i))))))))) ; var ok : Sequence := MatrixLib.singleValueMatrix(D + 1, 1.0) ; var overlap : boolean := ((MatrixLib.elementwiseMult(MathLib.numericRange(0, (D + 1), 1), (n + n))->compareTo(N - 1)) >= 0) ; overlap->tail() := overlap->tail() & ((N - 1) mod MathLib.numericRange(1, D + 1, 1) = 0) ; x := L + R ; x[overlap+1] := 0 ; return x->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() cur_len=1 cur_str=s[0] for i in range(1,n): if s[i]!=s[i-1]: cur_len+=1 cur_str+=s[i] else : cur_len=1 cur_str=s[i] if cur_len==2 : print('YES') print(cur_str) break else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var cur_len : int := 1 ; var cur_str : OclAny := s->first() ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) != (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cur_len)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cur_str)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cur_len)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cur_str)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name cur_len)))) == (comparison (expr (atom (number (integer 2)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name cur_str)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=256 def compare(arr1,arr2): for i in range(MAX): if arr1[i]!=arr2[i]: return False return True def search(pat,txt): M=len(pat) N=len(txt) countP=[0]*MAX countTW=[0]*MAX for i in range(M): (countP[ord(pat[i])])+=1 (countTW[ord(txt[i])])+=1 for i in range(M,N): if compare(countP,countTW): print("Found at Index",(i-M)) (countTW[ord(txt[i])])+=1 (countTW[ord(txt[i-M])])-=1 if compare(countP,countTW): print("Found at Index",N-M) txt="BACDGABCDA" pat="ABCD" search(pat,txt) ------------------------------------------------------------ OCL File: --------- class FromPython { suite`nestedAttributeDefinitions operation initialise() pre: true post: true activity: var MAX : int := 256 ; skip ; skip ; (countP[(pat[i+1])->char2byte()+1]) := (countP[(pat[i+1])->char2byte()+1]) + 1 ; (countTW[(txt[i+1])->char2byte()+1]) := (countTW[(txt[i+1])->char2byte()+1]) + 1; operation compare(arr1 : OclAny, arr2 : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, MAX-1) do ( if arr1[i+1] /= arr2[i+1] then ( return false ) else skip) ; return true; operation search(pat : OclAny, txt : OclAny) pre: true post: true activity: var M : int := (pat)->size() ; var N : int := (txt)->size() ; var countP : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX) ; var countTW : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX) ; for i : Integer.subrange(0, M-1) do (suite); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline N,M=map(int,readline().split()) MOD=10**9+7 N-=1 M-=1 X=list(map(int,readline().split())) CX=[x2-x1 for x1,x2 in zip(X,X[1 :])] CX=[CX[i]*(N-i)*(i+1)for i in range(N)] Y=list(map(int,readline().split())) CY=[y2-y1 for y1,y2 in zip(Y,Y[1 :])] CY=[CY[j]*(M-j)*(j+1)for j in range(M)] print(sum(CX)% MOD*sum(CY)% MOD) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var MOD : double := (10)->pow(9) + 7 ; N := N - 1 ; M := M - 1 ; var X : Sequence := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var CX : Sequence := Integer.subrange(1, X->size())->collect( _indx | Sequence{X->at(_indx), X->tail()->at(_indx)} )->select(_tuple | true)->collect(_tuple | let x1 : OclAny = _tuple->at(1) in let x2 : OclAny = _tuple->at(2) in (x2 - x1)) ; CX := Integer.subrange(0, N-1)->select(i | true)->collect(i | (CX[i+1] * (N - i) * (i + 1))) ; var Y : Sequence := ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var CY : Sequence := Integer.subrange(1, Y->size())->collect( _indx | Sequence{Y->at(_indx), Y->tail()->at(_indx)} )->select(_tuple | true)->collect(_tuple | let y1 : OclAny = _tuple->at(1) in let y2 : OclAny = _tuple->at(2) in (y2 - y1)) ; CY := Integer.subrange(0, M-1)->select(j | true)->collect(j | (CY[j+1] * (M - j) * (j + 1))) ; execute ((CX)->sum() mod MOD * (CY)->sum() mod MOD)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_sum_line(count,val_list): len_list=len(val_list) sum_line=0 for i in range(len_list): sum_line+=val_list[i]*(i-(len_list-1-i)) return sum_line n,m=list(map(int,input().split())) x_list=list(map(int,input().split())) y_list=list(map(int,input().split())) sum_x_line=get_sum_line(n,x_list) sum_y_line=get_sum_line(m,y_list) ans=int(sum_x_line*sum_y_line %(10**9+7)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var y_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sum_x_line : OclAny := get_sum_line(n, x_list) ; var sum_y_line : OclAny := get_sum_line(m, y_list) ; var ans : int := ("" + ((sum_x_line * sum_y_line mod ((10)->pow(9) + 7))))->toInteger() ; execute (ans)->display(); operation get_sum_line(count : OclAny, val_list : OclAny) : OclAny pre: true post: true activity: var len_list : int := (val_list)->size() ; var sum_line : int := 0 ; for i : Integer.subrange(0, len_list-1) do ( sum_line := sum_line + val_list[i+1] * (i - (len_list - 1 - i))) ; return sum_line; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**8) def sort(a): a.sort() def rev(a): a.reverse() def sd(): return int(input()) def _sd(): return map(int,input().split()) def sa(): return list(map(int,input().split())) def ss(): return input() def sf(): return float(input()) def main(): n,m=_sd() X=sa() Y=sa() sum_x=int(0) sum_y=int(0) mod=int((1e+9)+7) for i in range(1,n+1): sum_x+=(i+i-n-1)*X[i-1] sum_x %=mod for i in range(1,m+1): sum_y+=(i+i-m-1)*Y[i-1] sum_y %=mod print((sum_x*sum_y)% mod) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(8)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; main(); operation sort(a : OclAny) pre: true post: true activity: a := a->sort(); operation rev(a : OclAny) pre: true post: true activity: a := a->reverse(); operation sd() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation _sd() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation sa() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ss() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation sf() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := _sd() ; var X : OclAny := sa() ; var Y : OclAny := sa() ; var sum_x : int := ("" + ((0)))->toInteger() ; var sum_y : int := ("" + ((0)))->toInteger() ; var mod : int := ("" + (((("1e+9")->toReal()) + 7)))->toInteger() ; for i : Integer.subrange(1, n + 1-1) do ( sum_x := sum_x + (i + i - n - 1) * X[i - 1+1] ; sum_x := sum_x mod mod) ; for i : Integer.subrange(1, m + 1-1) do ( sum_y := sum_y + (i + i - m - 1) * Y[i - 1+1] ; sum_y := sum_y mod mod) ; execute ((sum_x * sum_y) mod mod)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=10**9+7 def sum_subarrays(A): N=len(A) S=[0] for a in A : S.append(S[-1]+a) S[-1]%=mod return sum((2*i-N-1)*s % mod for i,s in enumerate(S))% mod N,M=map(int,input().split()) X=[0]+list(map(int,input().split())) Y=[0]+list(map(int,input().split())) diff_X=[X[i+1]-X[i]for i in range(N)] diff_Y=[Y[i+1]-Y[i]for i in range(M)] print(sum_subarrays(diff_X)*sum_subarrays(diff_Y)% mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : double := (10)->pow(9) + 7 ; skip ; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var X : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var Y : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var diff_X : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (X[i + 1+1] - X[i+1])) ; var diff_Y : Sequence := Integer.subrange(0, M-1)->select(i | true)->collect(i | (Y[i + 1+1] - Y[i+1])) ; execute (sum_subarrays(diff_X) * sum_subarrays(diff_Y) mod mod)->display(); operation sum_subarrays(A : OclAny) : OclAny pre: true post: true activity: var N : int := (A)->size() ; var S : Sequence := Sequence{ 0 } ; for a : A do ( execute ((S->last() + a) : S) ; S->last() := S->last() mod mod) ; return ((argument (test (logical_test (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (expr (atom (number (integer 2)))) * (expr (atom (name i)))) - (expr (atom (name N)))) - (expr (atom (number (integer 1))))))))) ))) * (expr (atom (name s)))) % (expr (atom (name mod))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name S)))))))) )))))))))->sum() mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) x=map(int,input().split()) y=map(int,input().split()) x=list(x) y=list(y) x.sort() y.sort() M=10**9+7 a=sum([(2*k-n+1)*x[k]for k in range(n)]) b=sum([(2*k-m+1)*y[k]for k in range(m)]) a %=M b %=M res=a*b % M print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var y : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; x := (x) ; y := (y) ; x := x->sort() ; y := y->sort() ; var M : double := (10)->pow(9) + 7 ; var a : OclAny := (Integer.subrange(0, n-1)->select(k | true)->collect(k | ((2 * k - n + 1) * x[k+1])))->sum() ; var b : OclAny := (Integer.subrange(0, m-1)->select(k | true)->collect(k | ((2 * k - m + 1) * y[k+1])))->sum() ; a := a mod M ; b := b mod M ; var res : int := a * b mod M ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- fib=[0,1,1] for i in range(3,51): fib.append(fib[-1]+fib[-2]) for i in range(1,51): fib[i]+=fib[i-1] n,m=map(int,input().split()) ans=[0]*n left=m last=0 for i in range(n): if ans[i]!=0 : continue for j in range(i+1,n+1): size=n-j if size==1 : perms=1 else : perms=fib[size-1]+1 if perms>=left : ans[i]=j break else : left-=perms nlast=ans[i] t=i+1 while(tunion(Sequence{1}->union(Sequence{ 1 })) ; for i : Integer.subrange(3, 51-1) do ( execute ((fib->last() + fib->front()->last()) : fib)) ; for i : Integer.subrange(1, 51-1) do ( fib[i+1] := fib[i+1] + fib[i - 1+1]) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var left : OclAny := m ; var last : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ans[i+1] /= 0 then ( continue ) else skip ; for j : Integer.subrange(i + 1, n + 1-1) do ( var size : double := n - j ; if size = 1 then ( var perms : int := 1 ) else ( perms := fib[size - 1+1] + 1 ) ; if (perms->compareTo(left)) >= 0 then ( ans[i+1] := j ; break ) else ( left := left - perms )) ; var nlast : OclAny := ans[i+1] ; var t : OclAny := i + 1 ; while ((t->compareTo(n)) < 0 & ans[t - 1+1] /= last + 1) do ( ans[t+1] := ans[t - 1+1] - 1 ; t := t + 1) ; last := nlast) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys N,x=map(int,input().split()) A=[int(i)for i in input().split()] A.sort() y=x ans=0 if A[0]>y : print(0) sys.exit() for i in range(N): if ycollect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; A := A->sort() ; var y : OclAny := x ; var ans : int := 0 ; if (A->first()->compareTo(y)) > 0 then ( execute (0)->display() ; sys.exit() ) else skip ; for i : Integer.subrange(0, N-1) do ( if (y->compareTo(A[i+1])) < 0 then ( execute (ans)->display() ; sys.exit() ) else skip ; ans := ans + 1 ; y := y - A[i+1]) ; if y /= 0 then ( ans := ans - 1 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rint(): return int(input()) def rints(): return list(map(int,input().split())) n,k=rints() pos=[0]*(n+1) pos[0]=1 pos[1]=1 for i in range(2,n+1): pos[i]=pos[i-1]+pos[i-2] perm=list(range(1,n+1)) i=0 while ifirst() := 1 ; pos[1+1] := 1 ; for i : Integer.subrange(2, n + 1-1) do ( pos[i+1] := pos[i - 1+1] + pos[i - 2+1]) ; var perm : Sequence := (Integer.subrange(1, n + 1-1)) ; var i : int := 0 ; while (i->compareTo(n - 1)) < 0 do ( if (pos[n - i - 1+1]->compareTo(k)) < 0 then ( perm[i+1] := perm[i+1] + 1 ; perm[i + 1+1] := perm[i + 1+1] - 1 ; k := k - pos[n - i - 1+1] ; i := i + 2 ) else ( i := i + 1 )) ; execute (StringLib.sumStringsWithSeparator(((perm)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); operation rint() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation rints() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=[0 for i in range(n+1)] a[0],a[1]=1,1 for i in range(2,n+1): a[i]=a[i-1]+a[i-2] p=[i+1 for i in range(n)] i=0 while ia[n-1-i]: p[i],p[i+1]=p[i+1],p[i] k-=a[n-1-i] i+=2 else : i+=1 p=[str(i)for i in p] print(' '.join(p)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; var a->first() : OclAny := null; var a[1+1] : OclAny := null; Sequence{a->first(),a[1+1]} := Sequence{1,1} ; for i : Integer.subrange(2, n + 1-1) do ( a[i+1] := a[i - 1+1] + a[i - 2+1]) ; var p : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i + 1)) ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( if (k->compareTo(a[n - 1 - i+1])) > 0 then ( var p[i+1] : OclAny := null; var p[i + 1+1] : OclAny := null; Sequence{p[i+1],p[i + 1+1]} := Sequence{p[i + 1+1],p[i+1]} ; k := k - a[n - 1 - i+1] ; i := i + 2 ) else ( i := i + 1 )) ; p := p->select(i | true)->collect(i | (("" + ((i))))) ; execute (StringLib.sumStringsWithSeparator((p), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import itertools input=sys.stdin.readline sys.setrecursionlimit(100000) mod=10**9+7 def read_values(): return map(int,input().split()) def read_index(): return map(lambda x : int(x)-1,input().split()) def read_list(): return list(read_values()) def read_lists(N): return[read_list()for n in range(N)] class V : def __init__(self,f,v=None): self.f=f self.v=v def __str__(self): return str(self.v) def ud(self,n): if self.v is None : self.v=n else : self.v=self.f(self.v,n) def main(): N=int(input()) S=read_list() res=V(max,0) for c in range(1,N): r=0 t1=0 t2=N-1 while True : t1+=c t2-=c if t2exists( _x | result = _x ); attribute f : OclAny := f; attribute v : OclAny := v; operation initialise(f : OclAny,v : OclAny) : V pre: true post: true activity: self.f := f ; self.v := v; return self; operation __str__() : OclAny pre: true post: true activity: return ("" + ((self.v))); operation ud(n : OclAny) pre: true post: true activity: if self.v <>= null then ( self.v := n ) else ( self.v := self.f(self.v, n) ); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit(100000) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation read_values() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation read_index() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ); operation read_list() : OclAny pre: true post: true activity: return (read_values()); operation read_lists(N : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, N-1)->select(n | true)->collect(n | (read_list())); operation main() pre: true post: true activity: N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : OclAny := read_list() ; var res : V := (V.newV()).initialise(max, 0) ; for c : Integer.subrange(1, N-1) do ( var r : int := 0 ; var t1 : int := 0 ; var t2 : double := N - 1 ; while true do ( t1 := t1 + c ; t2 := t2 - c ; if (t2->compareTo(c)) < 0 then ( break ) else skip ; if (N - 1) mod c = 0 & (2 * t2->compareTo(N - 1)) <= 0 then ( break ) else skip ; r := r + S[t1+1] + S[t2+1] ; res.ud(r))) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from typing import List def find_kth_permutation(n : int,k : int)->List[int]: fib=[0]*(n+1) fib[0]=fib[1]=1 for i in range(2,n+1): fib[i]=fib[i-1]+fib[i-2] idx=0 res=[0]*n while idxcollect( _x | (OclType["int"])->apply(_x) ) ; var r : OclAny := find_kth_permutation(n, k) ; execute ((argument * (test (logical_test (comparison (expr (atom (name r))))))))->display(); operation find_kth_permutation(n : int, k : int) : OclAny pre: true post: true activity: var fib : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; fib->first() := 1; var fib[1+1] : int := 1 ; for i : Integer.subrange(2, n + 1-1) do ( fib[i+1] := fib[i - 1+1] + fib[i - 2+1]) ; var idx : int := 0 ; var res : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; while (idx->compareTo(n)) < 0 do ( if (k->compareTo(fib[n - idx - 1+1])) <= 0 then ( res[idx+1] := idx + 1 ; idx := idx + 1 ) else ( k := k - fib[n - idx - 1+1] ; res[idx+1] := idx + 2 ; res[idx + 1+1] := idx + 1 ; idx := idx + 2 )) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- size=['S','M','L','XL','XXL'] n=list(map(int,input().split())) k=int(input()) for i in range(k): w=size.index(input()) fit=[size[w]] x=1 while x<5 : if w+x<5 : fit.append(size[w+x]) if w-x>=0 : fit.append(size[w-x]) x=x+1 for e in fit : if n[size.index(e)]: n[size.index(e)]-=1 print(e) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var size : Sequence := Sequence{'S'}->union(Sequence{'M'}->union(Sequence{'L'}->union(Sequence{'XL'}->union(Sequence{ 'XXL' })))) ; var n : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, k-1) do ( var w : int := size->indexOf((OclFile["System.in"]).readLine()) - 1 ; var fit : Sequence := Sequence{ size[w+1] } ; var x : int := 1 ; while x < 5 do ( if w + x < 5 then ( execute ((size[w + x+1]) : fit) ) else skip ; if w - x >= 0 then ( execute ((size[w - x+1]) : fit) ) else skip ; x := x + 1) ; for e : fit do ( if n[size->indexOf(e) - 1+1] then ( n[size->indexOf(e) - 1+1] := n[size->indexOf(e) - 1+1] - 1 ; execute (e)->display() ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline w=list(map(int,input().split())) D={'S' : 0,'M' : 1,'L' : 2,'XL' : 3,'XXL' : 4} L={0 : 'S',1 : 'M',2 : 'L',3 : 'XL',4 : 'XXL'} for _ in range(int(input())): s=input()[:-1] if w[D[s]]>0 : w[D[s]]-=1 print(s) else : i=1 while True : if D[s]+i<=4 : if w[D[s]+i]>0 : w[D[s]+i]-=1 print(L[D[s]+i]) break if D[s]-i>=0 : if w[D[s]-i]>0 : w[D[s]-i]-=1 print(L[D[s]-i]) break i+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var D : Map := Map{ 'S' |-> 0 }->union(Map{ 'M' |-> 1 }->union(Map{ 'L' |-> 2 }->union(Map{ 'XL' |-> 3 }->union(Map{ 'XXL' |-> 4 })))) ; var L : Map := Map{ 0 |-> 'S' }->union(Map{ 1 |-> 'M' }->union(Map{ 2 |-> 'L' }->union(Map{ 3 |-> 'XL' }->union(Map{ 4 |-> 'XXL' })))) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : OclAny := input()->front() ; if w[D[s+1]+1] > 0 then ( w[D[s+1]+1] := w[D[s+1]+1] - 1 ; execute (s)->display() ) else ( var i : int := 1 ; while true do ( if D[s+1] + i <= 4 then ( if w[D[s+1] + i+1] > 0 then ( w[D[s+1] + i+1] := w[D[s+1] + i+1] - 1 ; execute (L[D[s+1] + i+1])->display() ; break ) else skip ) else skip ; if D[s+1] - i >= 0 then ( if w[D[s+1] - i+1] > 0 then ( w[D[s+1] - i+1] := w[D[s+1] - i+1] - 1 ; execute (L[D[s+1] - i+1])->display() ; break ) else skip ) else skip ; i := i + 1) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): sizes=[['S',0],['M',0],['L',0],['XL',0],['XXL',0]] arr=[int(i)for i in input().split()] index=0 for k in sizes : k[1]=arr[index] index+=1 arr_s=[0,1,2,3,4] arr_m=[1,2,0,3,4] arr_l=[2,3,1,4,0] arr_xl=[3,4,2,1,0] arr_xxl=[4,3,2,1,0] n=int(input()) for i in range(n): x=input() if x=='S' : for j in arr_s : if sizes[j][1]>0 : sizes[j][1]-=1 print(sizes[j][0]) break if x=='M' : for j in arr_m : if sizes[j][1]>0 : sizes[j][1]-=1 print(sizes[j][0]) break if x=='L' : for j in arr_l : if sizes[j][1]>0 : sizes[j][1]-=1 print(sizes[j][0]) break if x=='XL' : for j in arr_xl : if sizes[j][1]>0 : sizes[j][1]-=1 print(sizes[j][0]) break if x=='XXL' : for j in arr_xxl : if sizes[j][1]>0 : sizes[j][1]-=1 print(sizes[j][0]) break if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var sizes : Sequence := Sequence{Sequence{'S'}->union(Sequence{ 0 })}->union(Sequence{Sequence{'M'}->union(Sequence{ 0 })}->union(Sequence{Sequence{'L'}->union(Sequence{ 0 })}->union(Sequence{Sequence{'XL'}->union(Sequence{ 0 })}->union(Sequence{ Sequence{'XXL'}->union(Sequence{ 0 }) })))) ; var arr : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var index : int := 0 ; for k : sizes do ( k[1+1] := arr[index+1] ; index := index + 1) ; var arr_s : Sequence := Sequence{0}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })))) ; var arr_m : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{0}->union(Sequence{3}->union(Sequence{ 4 })))) ; var arr_l : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{1}->union(Sequence{4}->union(Sequence{ 0 })))) ; var arr_xl : Sequence := Sequence{3}->union(Sequence{4}->union(Sequence{2}->union(Sequence{1}->union(Sequence{ 0 })))) ; var arr_xxl : Sequence := Sequence{4}->union(Sequence{3}->union(Sequence{2}->union(Sequence{1}->union(Sequence{ 0 })))) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var x : String := (OclFile["System.in"]).readLine() ; if x = 'S' then ( for j : arr_s do ( if sizes[j+1][1+1] > 0 then ( sizes[j+1][1+1] := sizes[j+1][1+1] - 1 ; execute (sizes[j+1]->first())->display() ; break ) else skip) ) else skip ; if x = 'M' then ( for j : arr_m do ( if sizes[j+1][1+1] > 0 then ( sizes[j+1][1+1] := sizes[j+1][1+1] - 1 ; execute (sizes[j+1]->first())->display() ; break ) else skip) ) else skip ; if x = 'L' then ( for j : arr_l do ( if sizes[j+1][1+1] > 0 then ( sizes[j+1][1+1] := sizes[j+1][1+1] - 1 ; execute (sizes[j+1]->first())->display() ; break ) else skip) ) else skip ; if x = 'XL' then ( for j : arr_xl do ( if sizes[j+1][1+1] > 0 then ( sizes[j+1][1+1] := sizes[j+1][1+1] - 1 ; execute (sizes[j+1]->first())->display() ; break ) else skip) ) else skip ; if x = 'XXL' then ( for j : arr_xxl do ( if sizes[j+1][1+1] > 0 then ( sizes[j+1][1+1] := sizes[j+1][1+1] - 1 ; execute (sizes[j+1]->first())->display() ; break ) else skip) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=list(map(int,input().split())) a={'S' : 0,'M' : 1,'L' : 2,'XL' : 3,'XXL' : 4} b=['S','M','L','XL','XXL'] for i in range(int(input())): c=a[input()] for i in range(5): if c+i<5 and n[c+i]>0 : print(b[c+i]) n[c+i]-=1 break elif c-i>=0 and n[c-i]>0 : print(b[c-i]) n[c-i]-=1 break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Map := Map{ 'S' |-> 0 }->union(Map{ 'M' |-> 1 }->union(Map{ 'L' |-> 2 }->union(Map{ 'XL' |-> 3 }->union(Map{ 'XXL' |-> 4 })))) ; var b : Sequence := Sequence{'S'}->union(Sequence{'M'}->union(Sequence{'L'}->union(Sequence{'XL'}->union(Sequence{ 'XXL' })))) ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var c : OclAny := a[(OclFile["System.in"]).readLine()+1] ; for i : Integer.subrange(0, 5-1) do ( if c + i < 5 & n[c + i+1] > 0 then ( execute (b[c + i+1])->display() ; n[c + i+1] := n[c + i+1] - 1 ; break ) else (if c - i >= 0 & n[c - i+1] > 0 then ( execute (b[c - i+1])->display() ; n[c - i+1] := n[c - i+1] - 1 ; break ) else skip))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,x=map(int,input().split()) a=sorted(list(map(int,input().split()))) b=sorted(list(map(int,input().split())),reverse=True) if _!=t-1 : input() flag=True for i in range(n): if a[i]+b[i]>x : flag=False break print('YES' if flag else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; if _anon /= t - 1 then ( input() ) else skip ; var flag : boolean := true ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] + b[i+1]->compareTo(x)) > 0 then ( flag := false ; break ) else skip) ; execute (if flag then 'YES' else 'NO' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n,x=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) b.sort(reverse=True) for i in range(n): if a[i]+b[i]>x : print('NO') return print('YES') t=int(input()) for _ in range(t): solve() if _!=t-1 : c=input() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( solve() ; if _anon /= t - 1 then ( var c : String := (OclFile["System.in"]).readLine() ) else skip); operation solve() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; b := b->sort() ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] + b[i+1]->compareTo(x)) > 0 then ( execute ('NO')->display() ; return ) else skip) ; execute ('YES')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) left=0 right=0 for _ in range(n): a,b=map(int,input().split()) if a>0 : right+=1 elif a<0 : left+=1 if left==0 or right==0 or left==1 or right==1 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var left : int := 0 ; var right : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a > 0 then ( right := right + 1 ) else (if a < 0 then ( left := left + 1 ) else skip)) ; if left = 0 or right = 0 or left = 1 or right = 1 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=lambda : list(map(int,input().split())) s=f()[0] for i in range(s): n,x=f() a=sorted(f()) b=sorted(f())[: :-1] l=[z+y for z,y in zip(a,b)] print("YNEOS"[max(l)>x : : 2]) if i!=s-1 : input() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var s : OclAny := f->apply()->first() ; for i : Integer.subrange(0, s-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := f->apply() ; var a : Sequence := f->apply()->sort() ; var b : OclAny := sorted(f->apply())(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var l : Sequence := Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), b->at(_indx)} )->select(_tuple | true)->collect(_tuple | let z : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (z + y)) ; execute ("YNEOS"(subscript (test (logical_test (comparison (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)))))))) ))))) > (comparison (expr (atom (name x))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display() ; if i /= s - 1 then ( input() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : t-=1 n,x=(int(_)for _ in input().strip().split(' ')) a=list(map(int,input().split(' '))) b=list(map(int,input().split(' '))) if t!=0 : s=input() a.sort() b.sort(reverse=True) k=1 for i in range(0,n): if a[i]+b[i]>x : k=0 break if(k): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( t := t - 1 ; var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name _)))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name strip) (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ' '))))))) ))))))))} ; var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; if t /= 0 then ( var s : String := (OclFile["System.in"]).readLine() ) else skip ; a := a->sort() ; b := b->sort() ; var k : int := 1 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] + b[i+1]->compareTo(x)) > 0 then ( k := 0 ; break ) else skip) ; if (k) then ( execute ("Yes")->display() ) else ( execute ("No")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for j in range(t): n,s=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split()))[: :-1] if j!=t-1 : z=input() ans='Yes' for i in range(n): if a[i]+b[i]>s : ans='No' break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, t-1) do ( var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; if j /= t - 1 then ( var z : String := (OclFile["System.in"]).readLine() ) else skip ; var ans : String := 'Yes' ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] + b[i+1]->compareTo(s)) > 0 then ( ans := 'No' ; break ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil,sqrt def perfectSquares(l,r): number=ceil(sqrt(l)); n2=number*number ; number=(number*2)+1 ; while((n2>=l and n2<=r)): print(n2,end=" "); n2=n2+number ; number+=2 ; if __name__=="__main__" : l=2 ; r=24 ; perfectSquares(l,r); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( l := 2; r := 24; ; perfectSquares(l, r); ) else skip; operation perfectSquares(l : OclAny, r : OclAny) pre: true post: true activity: var number : OclAny := ceil(sqrt(l)); ; var n2 : int := number * number; ; number := (number * 2) + 1; ; while (((n2->compareTo(l)) >= 0 & (n2->compareTo(r)) <= 0)) do ( execute (n2)->display(); ; n2 := n2 + number; ; number := number + 2;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n): ans=(n*n//4) return ans if __name__=='__main__' : n=10 print(solve(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 10 ; execute (solve(n))->display() ) else skip; operation solve(n : OclAny) : OclAny pre: true post: true activity: var ans : int := (n * n div 4) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) w=[] for i in range(n): w.append("("*(n-i)+")"*(n-i)+"()"*i) return "\n".join(w) t=int(input()) ans=[] while t : ans.append(str(solve())) t-=1 print("\n".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; while t do ( execute ((("" + ((solve())))) : ans) ; t := t - 1) ; execute (StringLib.sumStringsWithSeparator((ans), "\n"))->display(); operation solve() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((StringLib.nCopies("(", (n - i)) + StringLib.nCopies(")", (n - i)) + StringLib.nCopies("()", i)) : w)) ; return StringLib.sumStringsWithSeparator((w), "\n"); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) for j in range(n): print("()"*j+"("*(n-j)+")"*(n-j)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, n-1) do ( execute (StringLib.nCopies("()", j) + StringLib.nCopies("(", (n - j)) + StringLib.nCopies(")", (n - j)))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- iteraciones=int(input()) for _ in range(iteraciones): n=int(input()) str="("*n+")"*(n-1) for i in range(n): print(str[0 : i+1]+")"+str[i+1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var iteraciones : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, iteraciones-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var OclType["String"] : String := StringLib.nCopies("(", n) + StringLib.nCopies(")", (n - 1)) ; for i : Integer.subrange(0, n-1) do ( execute (("" + (.subrange(0+1, i + 1))) + ")" + ("" + (.subrange(i + 1+1))))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for _ in range(T): N=int(input()) for i in range(N): print('('*i+'()'*(N-i)+')'*i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, T-1) do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, N-1) do ( execute (StringLib.nCopies('(', i) + StringLib.nCopies('()', (N - i)) + StringLib.nCopies(')', i))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for _ in range(T): N=int(input()) for i in range(N): print('('*i+'()'*(N-i)+')'*i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, T-1) do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, N-1) do ( execute (StringLib.nCopies('(', i) + StringLib.nCopies('()', (N - i)) + StringLib.nCopies(')', i))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) r=0 ; l=0 for i in range(n): x,y=map(int,input().split()) if x>0 : r+=1 else : l+=1 if min(r,l)<=1 : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r : int := 0; var l : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x > 0 then ( r := r + 1 ) else ( l := l + 1 )) ; if Set{r, l}->min() <= 1 then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Valid(a,b,c,d): if(a+b+c+d==360): return True ; return False ; a=80 ; b=70 ; c=100 ; d=110 ; if(Valid(a,b,c,d)): print("Valid quadilateral"); else : print("Invalid quadilateral"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 80; b := 70; c := 100; d := 110; ; if (Valid(a, b, c, d)) then ( execute ("Valid quadilateral")->display(); ) else ( execute ("Invalid quadilateral")->display(); ); operation Valid(a : OclAny, b : OclAny, c : OclAny, d : OclAny) pre: true post: true activity: if (a + b + c + d = 360) then ( return true; ) else skip ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,R,r=map(int,input().split()) if n==1 : if r<=R : print("YES") else : print("NO") else : lhs=2*r*r/(1-math.cos(2*math.pi/n)) rhs=(R-r)*(R-r) if float('%.9f' % lhs)<=rhs : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var R : OclAny := null; var r : OclAny := null; Sequence{n,R,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 1 then ( if (r->compareTo(R)) <= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else ( var lhs : double := 2 * r * r / (1 - ) ; var rhs : double := (R - r) * (R - r) ; if (("" + ((StringLib.format('%.9f',lhs))))->toReal()->compareTo(rhs)) <= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math number_of_plates,radius_of_table,radius_of_plate=map(int,input().split()) radius_of_plate=float(radius_of_plate) radius_of_table=float(radius_of_table) if number_of_plates==1 and radius_of_plate<=radius_of_table : print("YES") elif radius_of_tableradius_of_plate-1.0e-9 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var number_of_plates : OclAny := null; var radius_of_table : OclAny := null; var radius_of_plate : OclAny := null; Sequence{number_of_plates,radius_of_table,radius_of_plate} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var radius_of_plate : double := ("" + ((radius_of_plate)))->toReal() ; var radius_of_table : double := ("" + ((radius_of_table)))->toReal() ; if number_of_plates = 1 & (radius_of_plate->compareTo(radius_of_table)) <= 0 then ( execute ("YES")->display() ) else (if (radius_of_table->compareTo(radius_of_plate)) < 0 then ( execute ("NO")->display() ) else ( if ((radius_of_table - radius_of_plate) * ( / number_of_plates)->sin()->compareTo(radius_of_plate - ("1.0e-9")->toReal())) > 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from bisect import bisect_left as lb,bisect_right as rb from collections import* from math import gcd,pi,sin input_=lambda : sys.stdin.readline().strip("\n") ii=lambda : int(input_()) il=lambda : list(map(int,input_().split())) ilf=lambda : list(map(float,input_().split())) lii=lambda : list(map(int,list(ip()))) ip=lambda : input_() f=lambda : sys.stdout.flush() mod=10**9+7 n,R,r=il() if(n==1 and R>=r)or(R>=r+r/sin(pi/n)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var input_ : Function := lambda $$ : OclAny in (sys.stdin.readLine()->trim()) ; var ii : Function := lambda $$ : OclAny in (("" + ((input_->apply())))->toInteger()) ; var il : Function := lambda $$ : OclAny in (((input_->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ilf : Function := lambda $$ : OclAny in (((input_->apply().split())->collect( _x | (OclType["double"])->apply(_x) ))) ; var lii : Function := lambda $$ : OclAny in ((((ip()))->collect( _x | (OclType["int"])->apply(_x) ))) ; var ip : Function := lambda $$ : OclAny in (input_->apply()) ; var f : Function := lambda $$ : OclAny in ((OclFile["System.out"]).flush()) ; var mod : double := (10)->pow(9) + 7 ; var n : OclAny := null; var R : OclAny := null; var r : OclAny := null; Sequence{n,R,r} := il->apply() ; if (n = 1 & (R->compareTo(r)) >= 0) or ((R->compareTo(r + r / sin(pi / n))) >= 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def CheckArray(arr,n): prod=1 freq=[] for i in range(n): freq.append(arr[i]) prod*=arr[i] root=math.sqrt(prod) if(root*root==prod): if root in freq : return True return False if __name__=="__main__" : arr=[1,2,12,3,2] n=len(arr) if(CheckArray(arr,n)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{12}->union(Sequence{3}->union(Sequence{ 2 })))) ; n := (arr)->size() ; if (CheckArray(arr, n)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; operation CheckArray(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var prod : int := 1 ; var freq : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((arr[i+1]) : freq) ; prod := prod * arr[i+1]) ; var root : double := (prod)->sqrt() ; if (root * root = prod) then ( if (freq)->includes(root) then ( return true ) else skip ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,R,r=map(int,input().split()) if(r>R): print("NO") elif(r>R/2): if(n==1): print("YES") else : print("NO") else : s=math.asin(r/(R-r))*2 if(s*n<2*math.pi or abs(s*n-2*math.pi)<0.000000001): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var R : OclAny := null; var r : OclAny := null; Sequence{n,R,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if ((r->compareTo(R)) > 0) then ( execute ("NO")->display() ) else (if ((r->compareTo(R / 2)) > 0) then ( if (n = 1) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else ( var s : double := (r / (R - r))->asin() * 2 ; if ((s * n->compareTo(2 * )) < 0 or (s * n - 2 * )->abs() < 0.000000001) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,R,r=map(int,input().split()) if RR/2 : print('YES' if n==1 else 'NO') else : from math import asin,pi a=2*asin(r/(R-r)) print('YES' if 2*pi/a-n>=-1e-8 else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var R : OclAny := null; var r : OclAny := null; Sequence{n,R,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (R->compareTo(r)) < 0 then ( execute ('NO')->display() ) else (if (r->compareTo(R / 2)) > 0 then ( execute (if n = 1 then 'YES' else 'NO' endif)->display() ) else ( skip ; var a : double := 2 * asin(r / (R - r)) ; execute (if 2 * pi / a - n >= -("1e-8")->toReal() then 'YES' else 'NO' endif)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=2*10**7 def main(): N,M=(int(i)for i in input().split()) A=[] B=[] C=[] for _ in range(M): a,b=(int(i)for i in input().split()) A.append(a) B.append(b) C.append({int(i)for i in input().split()}) dp=[[INF]*(1<pow(7) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var A : Sequence := Sequence{} ; var B : Sequence := Sequence{} ; var C : Sequence := Sequence{} ; for _anon : Integer.subrange(0, M-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; execute ((a) : A) ; execute ((b) : B) ; execute ((input().split()->select(i | true)->collect(i | ("" + ((i)))->toInteger())->asSet()) : C)) ; var dp : Sequence := Integer.subrange(0, M + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ INF }, (1 * (2->pow(N)))))) ; dp->first()->first() := 0 ; for i : Integer.subrange(0, M-1) do ( for j : Integer.subrange(0, 1 * (2->pow(N))-1) do ( dp[i + 1+1][j+1] := Set{dp[i + 1+1][j+1], dp[i+1][j+1]}->min() ; if dp[i+1][j+1] /= INF then ( var next_bit : OclAny := j ; for bit : C[i+1] do ( next_bit := next_bit or (1 * (2->pow((bit - 1))))) ; dp[i + 1+1][next_bit+1] := Set{dp[i + 1+1][next_bit+1], dp[i+1][j+1] + A[i+1]}->min() ) else skip)) ; var ans : OclAny := dp->last()->last() ; if ans = INF then ( execute (-1)->display() ) else ( execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import reduce INF=10**7 N,M=map(int,input().split()) L=1<pow(7) ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var L : int := 1 * (2->pow(N)) ; var keys : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, M) ; for m : Integer.subrange(0, M-1) do ( var cost : OclAny := null; var _anon : OclAny := null; Sequence{cost,_anon} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var match : OclAny := reduce(lambda a : OclAny, b : OclAny in (MathLib.bitwiseOr(a, b)), Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name shamt))))))) (comp_for for (exprlist (expr (atom (name shamt)))) in (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test lambda (varargslist (vardef_parameters (vardef_parameter (name n)))) : (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))) - (expr (atom (number (integer 1)))))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))}) ; keys[m+1] := cost,match) ; var table : Sequence := Integer.subrange(0, M + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ INF }, L))) ; table->first()->first() := 0 ; for m : Integer.subrange(0, M-1) do ( var cost : OclAny := null; Sequence{cost,match} := keys[m+1] ; for l : Integer.subrange(0, L-1) do ( var now : OclAny := table[m+1][l+1] ; if l & not(now) then ( continue ) else skip ; table[m + 1+1][l+1] := Set{now, table[m + 1+1][l+1]}->min() ; table[m + 1+1][MathLib.bitwiseOr(l, match)+1] := Set{now + cost, table[m + 1+1][MathLib.bitwiseOr(l, match)+1]}->min())) ; execute (if table[M+1][L - 1+1] /= INF then table[M+1][L - 1+1] else -1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from subprocess import* with open('e.cpp','w')as f : f.write(r""" #include using namespace std; const int maxs=4096; int dp[maxs]; int main(){ memset(dp,0x3f,16384); dp[0]=0; int n,m; cin>>n>>m; while(m--){ int a,b,s=0; cin>>a>>b; while(b--){ int c; cin>>c; s ^=1<\r\nusing namespace std;\r\n\r\nconst int maxs=4096;\r\nint dp[maxs];\r\n\r\nint main(){\r\n\tmemset(dp,0x3f,16384);\r\n\tdp[0]=0;\r\n\tint n,m;\r\n\tcin>>n>>m;\r\n\twhile(m--){\r\n\t\tint a,b,s=0;\r\n\t\tcin>>a>>b;\r\n\t\twhile(b--){\r\n\t\t\tint c;\r\n\t\t\tcin>>c;\r\n\t\t\ts ^=1<0 : a+=1 else : b+=1 if min(a,b)<=1 : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := 0; var b : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x > 0 then ( a := a + 1 ) else ( b := b + 1 )) ; if Set{a, b}->min() <= 1 then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=10**9 def as_bit(ls): ret=0 for l in ls : ret |=1<<(l-1) return ret def main(): N,M=map(int,input().split()) C,A=[],[] for _ in range(M): a,b=map(int,input().split()) A.append(a) c=list(map(int,input().split())) C.append(as_bit(c)) dp=[[INF]*(2**N)for _ in range(M+1)] for i in range(M+1): dp[i][0]=0 for i in range(M): for bit in range(2**N): dp[i+1][bit | C[i]]=min(dp[i+1][bit | C[i]],dp[i][bit]+A[i]) dp[i+1][bit]=min(dp[i+1][bit],dp[i][bit]) ans=dp[-1][-1] print(ans if ans!=INF else-1) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INF : double := (10)->pow(9) ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation as_bit(ls : OclAny) : OclAny pre: true post: true activity: var ret : int := 0 ; for l : ls do ( ret := ret or 1 * (2->pow((l - 1)))) ; return ret; operation main() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var C : OclAny := null; var A : OclAny := null; Sequence{C,A} := Sequence{Sequence{},Sequence{}} ; for _anon : Integer.subrange(0, M-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a) : A) ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((as_bit(c)) : C)) ; var dp : Sequence := Integer.subrange(0, M + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ INF }, ((2)->pow(N))))) ; for i : Integer.subrange(0, M + 1-1) do ( dp[i+1]->first() := 0) ; for i : Integer.subrange(0, M-1) do ( for bit : Integer.subrange(0, (2)->pow(N)-1) do ( dp[i + 1+1][MathLib.bitwiseOr(bit, C[i+1])+1] := Set{dp[i + 1+1][MathLib.bitwiseOr(bit, C[i+1])+1], dp[i+1][bit+1] + A[i+1]}->min() ; dp[i + 1+1][bit+1] := Set{dp[i + 1+1][bit+1], dp[i+1][bit+1]}->min())) ; var ans : OclAny := dp->last()->last() ; execute (if ans /= INF then ans else -1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) dp=[0]+[10**8+10]*(2**n-1) for i in range(m): a,b=map(int,input().split()) s=sum([2**(x-1)for x in list(map(int,input().split()))]) for j in range(2**n): if dp[j | s]>dp[j]+a : dp[j | s]=dp[j]+a if dp[-1]<=10**8 : print(dp[-1]) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dp : Sequence := Sequence{ 0 }->union(MatrixLib.elementwiseMult(Sequence{ (10)->pow(8) + 10 }, ((2)->pow(n) - 1))) ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->select(x | true)->collect(x | ((2)->pow((x - 1)))))->sum() ; for j : Integer.subrange(0, (2)->pow(n)-1) do ( if (dp[MathLib.bitwiseOr(j, s)+1]->compareTo(dp[j+1] + a)) > 0 then ( dp[MathLib.bitwiseOr(j, s)+1] := dp[j+1] + a ) else skip)) ; if (dp->last()->compareTo((10)->pow(8))) <= 0 then ( execute (dp->last())->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt MAX=100001 prime=[0 for i in range(MAX+1)] countdiv=[0 for i in range(MAX+1)] def SieveOfEratosthenes(): for i in range(2,mt.ceil(mt.sqrt(MAX+1))): if(prime[i]==0): for j in range(i*2,MAX+1,i): prime[j]=i for i in range(1,MAX): if(prime[i]==0): prime[i]=i def largestGCDSubsequence(arr,n): ans=0 for i in range(n): element=arr[i] while(element>1): div=prime[element] countdiv[div]+=1 ans=max(ans,countdiv[div]) while(element % div==0): element=element//div return ans SieveOfEratosthenes() arr=[10,15,7,25,9,35] size=len(arr) print(largestGCDSubsequence(arr,size)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MAX : int := 100001 ; var prime : Sequence := Integer.subrange(0, MAX + 1-1)->select(i | true)->collect(i | (0)) ; var countdiv : Sequence := Integer.subrange(0, MAX + 1-1)->select(i | true)->collect(i | (0)) ; skip ; skip ; SieveOfEratosthenes() ; arr := Sequence{10}->union(Sequence{15}->union(Sequence{7}->union(Sequence{25}->union(Sequence{9}->union(Sequence{ 35 }))))) ; var size : int := (arr)->size() ; execute (largestGCDSubsequence(arr, size))->display(); operation SieveOfEratosthenes() pre: true post: true activity: for i : Integer.subrange(2, mt.ceil(mt.sqrt(MAX + 1))-1) do ( if (prime[i+1] = 0) then ( for j : Integer.subrange(i * 2, MAX + 1-1)->select( $x | ($x - i * 2) mod i = 0 ) do ( prime[j+1] := i) ) else skip) ; for i : Integer.subrange(1, MAX-1) do ( if (prime[i+1] = 0) then ( prime[i+1] := i ) else skip); operation largestGCDSubsequence(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var element : OclAny := arr[i+1] ; while (element > 1) do ( var div : OclAny := prime[element+1] ; countdiv[div+1] := countdiv[div+1] + 1 ; ans := Set{ans, countdiv[div+1]}->max() ; while (element mod div = 0) do ( element := element div div))) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Count(s,pos): c=s[pos-1] counter=0 for i in range(pos-1): if s[i]==c : counter=counter+1 return counter if __name__=="__main__" : s="abacsddaa" n=len(s) query=[9,3,2] Q=len(query) for i in range(Q): pos=query[i] print(Count(s,pos)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "abacsddaa" ; var n : int := (s)->size() ; var query : Sequence := Sequence{9}->union(Sequence{3}->union(Sequence{ 2 })) ; var Q : int := (query)->size() ; for i : Integer.subrange(0, Q-1) do ( pos := query[i+1] ; execute (Count(s, pos))->display()) ) else skip; operation Count(s : OclAny, pos : OclAny) : OclAny pre: true post: true activity: var c : OclAny := s[pos - 1+1] ; var counter : int := 0 ; for i : Integer.subrange(0, pos - 1-1) do ( if s[i+1] = c then ( counter := counter + 1 ) else skip) ; return counter; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): a,b,c,d=map(int,input().split()) if b>=a : print(b) continue if c<=d : print(-1) continue a-=b dif=c-d print(b+(a+dif-1)//dif*c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (b->compareTo(a)) >= 0 then ( execute (b)->display() ; continue ) else skip ; if (c->compareTo(d)) <= 0 then ( execute (-1)->display() ; continue ) else skip ; a := a - b ; var dif : double := c - d ; execute (b + (a + dif - 1) div dif * c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=int(1e9)+7 if __name__=="__main__" : a,b,k=input(),input(),int(input()) x,y=(1,0)if a==b else(0,1) n=len(b) b+=b same=sum(a==b[i : i+n]for i in range(n)) diff=n-same for _ in range(k): x,y=((x*(same-1))% MOD+(y*same)% MOD)% MOD,((x*(diff))% MOD+(y*(diff-1))% MOD)% MOD print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : int := ("" + ((("1e9")->toReal())))->toInteger() + 7 ; if __name__ = "__main__" then ( var a : OclAny := null; var b : OclAny := null; var k : OclAny := null; Sequence{a,b,k} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine(),("" + (((OclFile["System.in"]).readLine())))->toInteger()} ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := if a = b then Sequence{1, 0} else Sequence{0, 1} endif ; var n : int := (b)->size() ; b := b + b ; var same : OclAny := ((argument (test (logical_test (comparison (comparison (expr (atom (name a)))) == (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))) : (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name n))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->sum() ; var diff : double := n - same ; for _anon : Integer.subrange(0, k-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{((x * (same - 1)) mod MOD + (y * same) mod MOD) mod MOD,((x * (diff)) mod MOD + (y * (diff - 1)) mod MOD) mod MOD}) ; execute (x)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNumbers(N): i=1 while(i<=N): print((i*i*i),end=" ") i+=1 if __name__=='__main__' : N=4 findNumbers(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( N := 4 ; findNumbers(N) ) else skip; operation findNumbers(N : OclAny) pre: true post: true activity: var i : int := 1 ; while ((i->compareTo(N)) <= 0) do ( execute ((i * i * i))->display() ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: a,b,c,d=map(int,s.split()); print(b+(a>b)*(c>d and 0-(b-a)//(c-d)*c or-b-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ); execute (b + ((a->compareTo(b)) > 0) * ((c->compareTo(d)) > 0 & 0 - (b - a) div (c - d) * c or -b - 1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b,c,d=map(int,input().split()) sm=b a-=b if c-d<=0 and a>0 : sm=-1 elif a>0 : k=a//(c-d) if a %(c-d)!=0 : k+=1 sm+=k*c print(sm) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sm : OclAny := b ; a := a - b ; if c - d <= 0 & a > 0 then ( sm := -1 ) else (if a > 0 then ( var k : int := a div (c - d) ; if a mod (c - d) /= 0 then ( k := k + 1 ) else skip ; sm := sm + k * c ) else skip) ; execute (sm)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil t=int(input()) for i in range(t): a,b,c,d=map(int,input().split()) if b>=a : print(b) elif c<=d : print(-1) else : print(b+ceil((a-b)/(c-d))*c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (b->compareTo(a)) >= 0 then ( execute (b)->display() ) else (if (c->compareTo(d)) <= 0 then ( execute (-1)->display() ) else ( execute (b + ceil((a - b) / (c - d)) * c)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- countr=countl=0 for i in range(int(input())): x,y=map(int,input().split()) if(x<0): countl+=1 else : countr+=1 if min(countr,countl)<2 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var countr : OclAny := 0; var countl : int := 0 ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (x < 0) then ( countl := countl + 1 ) else ( countr := countr + 1 )) ; if Set{countr, countl}->min() < 2 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) i=1 while True : if i>t : break a,b,c,d=map(int,input().split()) if b>=a : print(b) else : if c<=d : print(-1) else : n=(a-b)/(c-d) if n % 1==0 : print(b+(int(n)*c)) else : print(b+(int(n)+1)*c) i=i+1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 1 ; while true do ( if (i->compareTo(t)) > 0 then ( break ) else skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (b->compareTo(a)) >= 0 then ( execute (b)->display() ) else ( if (c->compareTo(d)) <= 0 then ( execute (-1)->display() ) else ( var n : double := (a - b) / (c - d) ; if n mod 1 = 0 then ( execute (b + (("" + ((n)))->toInteger() * c))->display() ) else ( execute (b + (("" + ((n)))->toInteger() + 1) * c)->display() ) ) ) ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printDuplicates(arr): dict={} for ele in arr : try : dict[ele]+=1 except : dict[ele]=1 for item in dict : if(dict[item]>1): print(item,end=" ") print("\n") if __name__=="__main__" : list=[12,11,40,12,5,6,5,12,11] printDuplicates(list) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var OclType["Sequence"] : Sequence := Sequence{12}->union(Sequence{11}->union(Sequence{40}->union(Sequence{12}->union(Sequence{5}->union(Sequence{6}->union(Sequence{5}->union(Sequence{12}->union(Sequence{ 11 })))))))) ; printDuplicates(OclType["Sequence"]) ) else skip; operation printDuplicates(arr : OclAny) pre: true post: true activity: var OclType["Map"] : OclAny := Set{} ; for ele : arr do ( try ( (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ele)))))))) ]) := (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ele)))))))) ]) + 1) catch (_e : OclException) do ( (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ele)))))))) ]) := 1) ) ; for item : OclType["Map"] do ( if ((arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name item)))))))) ]) > 1) then ( execute (item)->display() ) else skip) ; execute ("\n")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(i)for i in input().split()] c=0 for i in a : if i % 2!=0 : c+=1 print("YES" if c % 2==0 else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var c : int := 0 ; for i : a do ( if i mod 2 /= 0 then ( c := c + 1 ) else skip) ; execute (if c mod 2 = 0 then "YES" else "NO" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main10(): buf=int(input("")); strbuf=input(""); strbufs=strbuf.split(); buf2=[]; for i in range(buf): buf2.append(int(strbufs[i])); if len(buf2)==1 : return("YES"); else : ki=0 ; for i in range(buf): if buf2[i]% 2==1 : ki+=1 ; if ki % 2==0 : print("YES"); else : print("NO"); if __name__=='__main__' : main10() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main10() ) else skip; operation main10() pre: true post: true activity: var buf : int := ("" + (((OclFile["System.in"]).readLine(""))))->toInteger(); ; var strbuf : String := (OclFile["System.in"]).readLine(""); ; var strbufs : OclAny := strbuf.split(); ; var buf2 : Sequence := Sequence{}; ; for i : Integer.subrange(0, buf-1) do ( execute ((("" + ((strbufs[i+1])))->toInteger()) : buf2);) ; if (buf2)->size() = 1 then ( return ("YES"); ) else ( var ki : int := 0; ; for i : Integer.subrange(0, buf-1) do ( if buf2[i+1] mod 2 = 1 then ( ki := ki + 1; ) else skip) ; if ki mod 2 = 0 then ( execute ("YES")->display(); ) else ( execute ("NO")->display(); ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) A=list(map(int,input().split())) if sum(A)% 2==0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (A)->sum() mod 2 = 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) aa=[int(a)for a in input().rstrip().split()] n_even=len(list(filter(lambda a : a % 2==0,aa))) n_odd=len(list(filter(lambda a : a % 2==1,aa))) x=n_odd//2 n_odd-=x*2 n_even+=x if n_even>1 : n_even=1 if n_even==0 or n_odd==0 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var aa : Sequence := input().rstrip().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; var n_even : int := (((aa)->select( _x | (lambda a : OclAny in (a mod 2 = 0))->apply(_x) = true )))->size() ; var n_odd : int := (((aa)->select( _x | (lambda a : OclAny in (a mod 2 = 1))->apply(_x) = true )))->size() ; var x : int := n_odd div 2 ; n_odd := n_odd - x * 2 ; n_even := n_even + x ; if n_even > 1 then ( n_even := 1 ) else skip ; if n_even = 0 or n_odd = 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input().split() i=0 count=0 while itoInteger() ; var s : OclAny := input().split() ; var i : int := 0 ; var count : int := 0 ; while (i->compareTo(n)) < 0 do ( if ("" + ((s[i+1])))->toInteger() mod 2 /= 0 then ( count := count + 1 ) else skip ; i := i + 1) ; if count mod 2 = 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import combinations_with_replacement as cwr n,m=map(int,input().split()) c_lst=list(map(int,input().split())) for t in cwr((0,1,2,3,4,5,6,7,8,9),n): out="" cost=0 for n in t : cost+=c_lst[n] out+=str(n) if cost<=m : print(out) break else : print("NA") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c_lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (compound_stmt for (exprlist (expr (atom (name t)))) in (testlist (test (logical_test (comparison (expr (atom (name cwr)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) , (test (logical_test (comparison (expr (atom (number (integer 1))))))) , (test (logical_test (comparison (expr (atom (number (integer 2))))))) , (test (logical_test (comparison (expr (atom (number (integer 3))))))) , (test (logical_test (comparison (expr (atom (number (integer 4))))))) , (test (logical_test (comparison (expr (atom (number (integer 5))))))) , (test (logical_test (comparison (expr (atom (number (integer 6))))))) , (test (logical_test (comparison (expr (atom (number (integer 7))))))) , (test (logical_test (comparison (expr (atom (number (integer 8))))))) , (test (logical_test (comparison (expr (atom (number (integer 9)))))))) ))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name out)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom ""))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cost)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name n)))) in (testlist (test (logical_test (comparison (expr (atom (name t))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cost)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name c_lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n)))))))) ]))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name out)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name cost)))) <= (comparison (expr (atom (name m))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name out)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NA"))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def findMissingUtil(arr,low,high,diff): if(high<=low): return sys.maxsize ; mid=int(low+(high-low)/2); if(arr[mid+1]-arr[mid]!=diff): return(arr[mid]+diff); if(mid>0 and arr[mid]-arr[mid-1]!=diff): return(arr[mid-1]+diff); if(arr[mid]==arr[0]+mid*diff): return findMissingUtil(arr,mid+1,high,diff); return findMissingUtil(arr,low,mid-1,diff); def findMissing(arr,n): diff=int((arr[n-1]-arr[0])/n); return findMissingUtil(arr,0,n-1,diff); arr=[2,4,8,10,12,14]; n=len(arr); print("The missing element is",findMissing(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; arr := Sequence{2}->union(Sequence{4}->union(Sequence{8}->union(Sequence{10}->union(Sequence{12}->union(Sequence{ 14 }))))); ; n := (arr)->size(); ; execute ("The missing element is")->display();; operation findMissingUtil(arr : OclAny, low : OclAny, high : OclAny, diff : OclAny) pre: true post: true activity: if ((high->compareTo(low)) <= 0) then ( return (trailer . (name maxsize)); ) else skip ; var mid : int := ("" + ((low + (high - low) / 2)))->toInteger(); ; if (arr[mid + 1+1] - arr[mid+1] /= diff) then ( return (arr[mid+1] + diff); ) else skip ; if (mid > 0 & arr[mid+1] - arr[mid - 1+1] /= diff) then ( return (arr[mid - 1+1] + diff); ) else skip ; if (arr[mid+1] = arr->first() + mid * diff) then ( return findMissingUtil(arr, mid + 1, high, diff); ) else skip ; return findMissingUtil(arr, low, mid - 1, diff);; operation findMissing(arr : OclAny, n : OclAny) pre: true post: true activity: diff := ("" + (((arr[n - 1+1] - arr->first()) / n)))->toInteger(); ; return findMissingUtil(arr, 0, n - 1, diff);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findPair(arr,n): if(n<2): print("-1") return i=0 first=-1 second=-1 for i in range(n): if(arr[i]>first): second=first first=arr[i] elif(arr[i]>second): second=arr[i] print("n=",first,"and r=",second) arr=[0,2,3,4,1,6,8,9] n=len(arr) findPair(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{0}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{1}->union(Sequence{6}->union(Sequence{8}->union(Sequence{ 9 }))))))) ; n := (arr)->size() ; findPair(arr, n); operation findPair(arr : OclAny, n : OclAny) pre: true post: true activity: if (n < 2) then ( execute ("-1")->display() ; return ) else skip ; var i : int := 0 ; var first : int := -1 ; var second : int := -1 ; for i : Integer.subrange(0, n-1) do ( if ((arr[i+1]->compareTo(first)) > 0) then ( second := first ; first := arr[i+1] ) else (if ((arr[i+1]->compareTo(second)) > 0) then ( second := arr[i+1] ) else skip)) ; execute ("n=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline LED_pattern=[0b0111111,0b0000110,0b1011011,0b1001111,0b1100110,0b1101101,0b1111101,0b0100111,0b1111111,0b1101111,0b0000000] def solve(cp,np): a=LED_pattern[cp] b=LED_pattern[np] return bin(a ^ b)[2 :].zfill(7) def main(args): while True : n=int(input()) if n==-1 : break cp=10 for _ in range(n): d=int(input()) ans=solve(cp,d) cp=d print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; var LED_pattern : Sequence := Sequence{0b0111111}->union(Sequence{0b0000110}->union(Sequence{0b1011011}->union(Sequence{0b1001111}->union(Sequence{0b1100110}->union(Sequence{0b1101101}->union(Sequence{0b1111101}->union(Sequence{0b0100111}->union(Sequence{0b1111111}->union(Sequence{0b1101111}->union(Sequence{ 0b0000000 })))))))))) ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(cp : OclAny, np : OclAny) : OclAny pre: true post: true activity: var a : OclAny := LED_pattern[cp+1] ; var b : OclAny := LED_pattern[np+1] ; return bin(MathLib.bitwiseXor(a, b)).subrange(2+1).zfill(7); operation main(args : OclAny) pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = -1 then ( break ) else skip ; cp := 10 ; for _anon : Integer.subrange(0, n-1) do ( var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : OclAny := solve(cp, d) ; cp := d ; execute (ans)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,sys,io,math from array import array from math import* I=lambda :[*map(int,sys.stdin.readline().split())] IS=lambda : input() IN=lambda : int(input()) IF=lambda : float(input()) n=IN() l=I() inf=pow(10,9)+1 t,c=0,inf for i in range(1,101): d=0 for j in l : d+=min(abs((i-1)-j),abs(i-j),abs((i+1)-j)) if c>d : t,c=i,d print(t,c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var I : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var IS : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var IN : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var IF : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toReal()) ; var n : OclAny := IN->apply() ; var l : OclAny := I->apply() ; var Math_PINFINITY : double := (10)->pow(9) + 1 ; var t : OclAny := null; var c : OclAny := null; Sequence{t,c} := Sequence{0,Math_PINFINITY} ; for i : Integer.subrange(1, 101-1) do ( var d : int := 0 ; for j : l do ( d := d + Set{((i - 1) - j)->abs(), (i - j)->abs(), ((i + 1) - j)->abs()}->min()) ; if (c->compareTo(d)) > 0 then ( var t : OclAny := null; var c : OclAny := null; Sequence{t,c} := Sequence{i,d} ) else skip) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil n=int(input()) a=[int(i)for i in input().split()] global_cost=100000000000000 T=None for t in range(1,101): local_cost=0 for i in range(n): if abs(a[i]-t)>=2 : local_cost+=abs(a[i]-t)-1 if global_cost>local_cost : global_cost=local_cost T=t print(T,global_cost) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var global_cost : int := 100000000000000 ; var T : OclAny := null ; for t : Integer.subrange(1, 101-1) do ( var local_cost : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] - t)->abs() >= 2 then ( local_cost := local_cost + (a[i+1] - t)->abs() - 1 ) else skip) ; if (global_cost->compareTo(local_cost)) > 0 then ( global_cost := local_cost ; T := t ) else skip) ; execute (T)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import os import random import re import sys ans=1e9 total=1 n=int(input()) arr=list(map(int,input().split())) for i in range(100): count=0 for j in range(n): count+=min(min(abs(arr[j]-i-1),abs(arr[j]-i+1)),abs(arr[j]-i)) if counttoReal() ; var total : int := 1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, 100-1) do ( var count : int := 0 ; for j : Integer.subrange(0, n-1) do ( count := count + Set{Set{(arr[j+1] - i - 1)->abs(), (arr[j+1] - i + 1)->abs()}->min(), (arr[j+1] - i)->abs()}->min()) ; if (count->compareTo(ans)) < 0 then ( ans := count ; total := i; ) else skip) ; if total = 0 & ans = 0 then ( execute (1)->display() ) else ( execute (total)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def ii(): return int(input()) def si(): return input() def mi(): return map(int,input().strip().split(" ")) def msi(): return map(str,input().strip().split(" ")) def li(): return list(mi()) def read(): sys.stdin=open("input.txt",'r') sys.stout=open("output.txt",'w') def main(): n=ii() lst=li() cost=1e9+7 ans=0 for i in range(min(lst),max(lst)+1): s=0 for j in lst : if j==i : continue s+=abs(j-i)-1 if stoInteger(); operation si() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation mi() : OclAny pre: true post: true activity: return (input()->trim().split(" "))->collect( _x | (OclType["int"])->apply(_x) ); operation msi() : OclAny pre: true post: true activity: return (input()->trim().split(" "))->collect( _x | (OclType["String"])->apply(_x) ); operation li() : OclAny pre: true post: true activity: return (mi()); operation read() pre: true post: true activity: OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ; (trailer . (name stout)) := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")); operation main() pre: true post: true activity: var n : OclAny := ii() ; var lst : OclAny := li() ; var cost : double := ("1e9")->toReal() + 7 ; var ans : int := 0 ; for i : Integer.subrange((lst)->min(), (lst)->max() + 1-1) do ( var s : int := 0 ; for j : lst do ( if j = i then ( continue ) else skip ; s := s + (j - i)->abs() - 1) ; if (s->compareTo(cost)) < 0 then ( cost := Set{cost, s}->min() ; ans := i ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) a=list(map(int,input().split())) inf=pow(10,9)+1 t,c=0,inf for i in range(1,101): c0=0 for j in a : c0+=min(abs((i-1)-j),abs(i-j),abs((i+1)-j)) if c>c0 : t,c=i,c0 print(t,c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var Math_PINFINITY : double := (10)->pow(9) + 1 ; var t : OclAny := null; var c : OclAny := null; Sequence{t,c} := Sequence{0,Math_PINFINITY} ; for i : Integer.subrange(1, 101-1) do ( var c0 : int := 0 ; for j : a do ( c0 := c0 + Set{((i - 1) - j)->abs(), (i - j)->abs(), ((i + 1) - j)->abs()}->min()) ; if (c->compareTo(c0)) > 0 then ( var t : OclAny := null; var c : OclAny := null; Sequence{t,c} := Sequence{i,c0} ) else skip) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c={"1" : "","2" : "k","3" : "s","4" : "t","5" : "n","6" : "h","7" : "m","8" : "y","9" : "r","0" : "w"} m={"T" : "a","L" : "i","U" : "u","R" : "e","D" : "o"} s=input() ans="" for i in range(0,len(s),2): com=s[i : i+2] if com=="0U" : ans+="nn" else : ans+=c[com[0]]+m[com[1]] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : Map := Map{ "1" |-> "" }->union(Map{ "2" |-> "k" }->union(Map{ "3" |-> "s" }->union(Map{ "4" |-> "t" }->union(Map{ "5" |-> "n" }->union(Map{ "6" |-> "h" }->union(Map{ "7" |-> "m" }->union(Map{ "8" |-> "y" }->union(Map{ "9" |-> "r" }->union(Map{ "0" |-> "w" }))))))))) ; var m : Map := Map{ "T" |-> "a" }->union(Map{ "L" |-> "i" }->union(Map{ "U" |-> "u" }->union(Map{ "R" |-> "e" }->union(Map{ "D" |-> "o" })))) ; var s : String := (OclFile["System.in"]).readLine() ; var ans : String := "" ; for i : Integer.subrange(0, (s)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( var com : OclAny := s.subrange(i+1, i + 2) ; if com = "0U" then ( ans := ans + "nn" ) else ( ans := ans + c[com->first()+1] + m[com[1+1]+1] )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c="w kstnhmyr" v="aiueo" d=["T","L","U","R","D"] f=[] a=input() for i in range(0,len(a),2): b=int(a[i]) e=d.index(a[i+1]) if b==0 and e==2 : f+='nn' elif b==1 : f+=v[e] else : f+=c[b]+v[e] print("".join(f)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : String := "w kstnhmyr" ; var v : String := "aiueo" ; var d : Sequence := Sequence{"T"}->union(Sequence{"L"}->union(Sequence{"U"}->union(Sequence{"R"}->union(Sequence{ "D" })))) ; var f : Sequence := Sequence{} ; var a : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, (a)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( var b : int := ("" + ((a[i+1])))->toInteger() ; var e : int := d->indexOf(a[i + 1+1]) - 1 ; if b = 0 & e = 2 then ( f := f + 'nn' ) else (if b = 1 then ( f := f + v[e+1] ) else ( f := f + c[b+1] + v[e+1] ) ) ) ; execute (StringLib.sumStringsWithSeparator((f), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c,v,d,f,a="w kstnhmyr","aiueo",["T","L","U","R","D"],"",input() for i in range(0,len(a),2): b=int(a[i]) e=d.index(a[i+1]) if b==0 and e==2 : f+='nn' elif b==1 : f+=v[e] else : f+=c[b]+v[e] print(f) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : OclAny := null; var v : OclAny := null; var d : OclAny := null; var f : OclAny := null; var a : OclAny := null; Sequence{c,v,d,f,a} := Sequence{"w kstnhmyr","aiueo",Sequence{"T"}->union(Sequence{"L"}->union(Sequence{"U"}->union(Sequence{"R"}->union(Sequence{ "D" })))),"",(OclFile["System.in"]).readLine()} ; for i : Integer.subrange(0, (a)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( var b : int := ("" + ((a[i+1])))->toInteger() ; var e : int := d->indexOf(a[i + 1+1]) - 1 ; if b = 0 & e = 2 then ( f := f + 'nn' ) else (if b = 1 then ( f := f + v[e+1] ) else ( f := f + c[b+1] + v[e+1] ) ) ) ; execute (f)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) l=list(map(int,input().split())) c=[0]*101 for i in l : c[i]+=1 n1,n2=0,0 i=0 while i=2 : i+=1 n1=i while i=1 : i+=1 n2=i print(n1+n2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 101) ; for i : l do ( c[i+1] := c[i+1] + 1) ; var n1 : OclAny := null; var n2 : OclAny := null; Sequence{n1,n2} := Sequence{0,0} ; var i : int := 0 ; while (i->compareTo((l)->size())) < 0 & c[i+1] >= 2 do ( i := i + 1) ; var n1 : int := i ; while (i->compareTo((l)->size())) < 0 & c[i+1] >= 1 do ( i := i + 1) ; var n2 : int := i ; execute (n1 + n2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- flicks={"T" : "a","L" : "i","U" : "u","R" : "e","D" : "o"} buttons={"1" : "","2" : "k","3" : "s","4" : "t","5" : "n","6" : "h","7" : "m","8" : "y","9" : "r","0" : "w"} def get_word(button,flick): if button=="0" and flick=="U" : return "nn" return buttons[button]+flicks[flick] cmds=input() result="" for i in range(0,len(cmds),2): result+=get_word(cmds[i],cmds[i+1]) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var flicks : Map := Map{ "T" |-> "a" }->union(Map{ "L" |-> "i" }->union(Map{ "U" |-> "u" }->union(Map{ "R" |-> "e" }->union(Map{ "D" |-> "o" })))) ; var buttons : Map := Map{ "1" |-> "" }->union(Map{ "2" |-> "k" }->union(Map{ "3" |-> "s" }->union(Map{ "4" |-> "t" }->union(Map{ "5" |-> "n" }->union(Map{ "6" |-> "h" }->union(Map{ "7" |-> "m" }->union(Map{ "8" |-> "y" }->union(Map{ "9" |-> "r" }->union(Map{ "0" |-> "w" }))))))))) ; skip ; var cmds : String := (OclFile["System.in"]).readLine() ; var result : String := "" ; for i : Integer.subrange(0, (cmds)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( result := result + get_word(cmds[i+1], cmds[i + 1+1])) ; execute (result)->display(); operation get_word(button : OclAny, flick : OclAny) : OclAny pre: true post: true activity: if button = "0" & flick = "U" then ( return "nn" ) else skip ; return buttons[button+1] + flicks[flick+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools def luck(n): string=str(n) k=0 t=int(len(string)/2) if(len(string)% 2!=0): k=1 elif(int(string[0])>7): k=2 if(k!=0)or(len(string)==10): if(len(string)==10): k=0 t=int((len(string)+k)/2) v=['4']*t+['7']*t print("".join(v)) return if int(string[0])<4 : v=['4']*t+['7']*t print("".join(v)) return if int(string[0])>4 and int(string[0])<7 : v=['7']+['4']*(t-1)+['7']*(t-1)+['4'] print("".join(v)) return p=list(itertools.permutations(['4']*t+['7']*t)) for i in range(len(p)): p[i]=int("".join(p[i])) p.sort() for p in p : if p>=n : print(p) return v=['4']*(t+1)+['7']*(t+1) print("".join(v)) return n=int(input()) luck(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; luck(n); operation luck(n : OclAny) pre: true post: true activity: var string : String := ("" + ((n))) ; var k : int := 0 ; var t : int := ("" + (((string)->size() / 2)))->toInteger() ; if ((string)->size() mod 2 /= 0) then ( k := 1 ) else (if (("" + ((string->first())))->toInteger() > 7) then ( k := 2 ) else skip) ; if (k /= 0) or ((string)->size() = 10) then ( if ((string)->size() = 10) then ( k := 0 ) else skip ; t := ("" + ((((string)->size() + k) / 2)))->toInteger() ; var v : Sequence := MatrixLib.elementwiseMult(Sequence{ '4' }, t)->union(MatrixLib.elementwiseMult(Sequence{ '7' }, t)) ; execute (StringLib.sumStringsWithSeparator((v), ""))->display() ; return ) else skip ; if ("" + ((string->first())))->toInteger() < 4 then ( v := MatrixLib.elementwiseMult(Sequence{ '4' }, t)->union(MatrixLib.elementwiseMult(Sequence{ '7' }, t)) ; execute (StringLib.sumStringsWithSeparator((v), ""))->display() ; return ) else skip ; if ("" + ((string->first())))->toInteger() > 4 & ("" + ((string->first())))->toInteger() < 7 then ( v := Sequence{ '7' }->union(MatrixLib.elementwiseMult(Sequence{ '4' }, (t - 1)))->union(MatrixLib.elementwiseMult(Sequence{ '7' }, (t - 1)))->union(Sequence{ '4' }) ; execute (StringLib.sumStringsWithSeparator((v), ""))->display() ; return ) else skip ; var p : Sequence := (itertools.permutations(MatrixLib.elementwiseMult(Sequence{ '4' }, t)->union(MatrixLib.elementwiseMult(Sequence{ '7' }, t)))) ; for i : Integer.subrange(0, (p)->size()-1) do ( p[i+1] := ("" + ((StringLib.sumStringsWithSeparator((p[i+1]), ""))))->toInteger()) ; p := p->sort() ; for p : p do ( if (p->compareTo(n)) >= 0 then ( execute (p)->display() ; return ) else skip) ; v := MatrixLib.elementwiseMult(Sequence{ '4' }, (t + 1))->union(MatrixLib.elementwiseMult(Sequence{ '7' }, (t + 1))) ; execute (StringLib.sumStringsWithSeparator((v), ""))->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- moji=input() flag=0 answer=[] for i in range(0,len(moji)): if flag==1 : flag=0 continue if moji[i]=="2" : answer.append("k") elif moji[i]=="3" : answer.append("s") elif moji[i]=="4" : answer.append("t") elif moji[i]=="5" : answer.append("n") elif moji[i]=="6" : answer.append("h") elif moji[i]=="7" : answer.append("m") elif moji[i]=="8" : answer.append("y") elif moji[i]=="9" : answer.append("r") elif moji[i]=="0" : i+=1 flag=1 if moji[i]=="T" : answer.append("wa") elif moji[i]=="D" : answer.append("wo") elif moji[i]=="U" : answer.append("nn") elif moji[i]=="T" : answer.append("a") elif moji[i]=="L" : answer.append("i") elif moji[i]=="U" : answer.append("u") elif moji[i]=="R" : answer.append("e") elif moji[i]=="D" : answer.append("o") for i in answer : print(i,end="") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var moji : String := (OclFile["System.in"]).readLine() ; var flag : int := 0 ; var answer : Sequence := Sequence{} ; for i : Integer.subrange(0, (moji)->size()-1) do ( if flag = 1 then ( flag := 0 ; continue ) else skip ; if moji[i+1] = "2" then ( execute (("k") : answer) ) else (if moji[i+1] = "3" then ( execute (("s") : answer) ) else (if moji[i+1] = "4" then ( execute (("t") : answer) ) else (if moji[i+1] = "5" then ( execute (("n") : answer) ) else (if moji[i+1] = "6" then ( execute (("h") : answer) ) else (if moji[i+1] = "7" then ( execute (("m") : answer) ) else (if moji[i+1] = "8" then ( execute (("y") : answer) ) else (if moji[i+1] = "9" then ( execute (("r") : answer) ) else (if moji[i+1] = "0" then ( i := i + 1 ; flag := 1 ; if moji[i+1] = "T" then ( execute (("wa") : answer) ) else (if moji[i+1] = "D" then ( execute (("wo") : answer) ) else (if moji[i+1] = "U" then ( execute (("nn") : answer) ) else skip ) ) ) else (if moji[i+1] = "T" then ( execute (("a") : answer) ) else (if moji[i+1] = "L" then ( execute (("i") : answer) ) else (if moji[i+1] = "U" then ( execute (("u") : answer) ) else (if moji[i+1] = "R" then ( execute (("e") : answer) ) else (if moji[i+1] = "D" then ( execute (("o") : answer) ) else skip ) ) ) ) ) ) ) ) ) ) ) ) ) ) ; for i : answer do ( execute (i)->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Square(row,column,moves): a=0 ; b=0 ; c=0 ; d=0 ; total=0 ; a=row-moves ; b=row+moves ; c=column-moves ; d=column+moves ; if(a<1): a=1 ; if(c<1): c=1 ; if(b>8): b=8 ; if(d>8): d=8 ; total=(b-a+1)*(d-c+1)-1 ; return total ; if __name__=="__main__" : R=4 ; C=5 ; M=2 ; print(Square(R,C,M)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var R : int := 4; var C : int := 5; var M : int := 2; ; execute (Square(R, C, M))->display(); ) else skip; operation Square(row : OclAny, column : OclAny, moves : OclAny) pre: true post: true activity: var a : int := 0; var b : int := 0; var c : int := 0; ; var d : int := 0; var total : int := 0; ; a := row - moves; ; b := row + moves; ; c := column - moves; ; d := column + moves; ; if (a < 1) then ( a := 1; ) else skip ; if (c < 1) then ( c := 1; ) else skip ; if (b > 8) then ( b := 8; ) else skip ; if (d > 8) then ( d := 8; ) else skip ; total := (b - a + 1) * (d - c + 1) - 1; ; return total;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b,c=map(int,input().split()) tot=a+2*b+3*c if tot % 2==0 : print(0) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var tot : OclAny := a + 2 * b + 3 * c ; if tot mod 2 = 0 then ( execute (0)->display() ) else ( execute (1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : a,b,c=map(int,input().split()) n=1*a+2*b+3*c if n % 2==0 : print("0") else : print("1") t=t-1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : double := 1 * a + 2 * b + 3 * c ; if n mod 2 = 0 then ( execute ("0")->display() ) else ( execute ("1")->display() ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): a=list(map(int,input().split())) x=a[0] y=a[1] z=a[2] ans=1 if(((((x % 2==0)and(y % 2==0))and(z % 2==0))or(((x % 2==0)and(y % 2==1))and(z % 2==0)))or((((x % 2==1)and(y % 2==1))and(z % 2==1))or(((x % 2==1)and(y % 2==0))and(z % 2==1)))): ans=0 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := a->first() ; var y : OclAny := a[1+1] ; var z : OclAny := a[2+1] ; var ans : int := 1 ; if (((((x mod 2 = 0) & (y mod 2 = 0)) & (z mod 2 = 0)) or (((x mod 2 = 0) & (y mod 2 = 1)) & (z mod 2 = 0))) or ((((x mod 2 = 1) & (y mod 2 = 1)) & (z mod 2 = 1)) or (((x mod 2 = 1) & (y mod 2 = 0)) & (z mod 2 = 1)))) then ( ans := 0 ) else skip ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b,c=map(int,input().split()) print((a+c)% 2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a + c) mod 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=list(map(int,input().split())) a=1*n[0]+2*n[1]+3*n[2] if a % 2==0 : print(0) elif a % 2==1 : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : double := 1 * n->first() + 2 * n[1+1] + 3 * n[2+1] ; if a mod 2 = 0 then ( execute (0)->display() ) else (if a mod 2 = 1 then ( execute (1)->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math ; def powmod(x,y,p): res=1 ; x=x % p ; while(y>0): if(y & 1): res=(res*x)% p ; y=y>>1 ; x=(x*x)% p ; return res ; def discreteLogarithm(a,b,m): n=int(math.sqrt(m)+1); value=[0]*m ; for i in range(n,0,-1): value[powmod(a,i*n,m)]=i ; for j in range(n): cur=(powmod(a,j,m)*b)% m ; if(value[cur]): ans=value[cur]*n-j ; if(ansdisplay(); ; a := 3; ; b := 7; ; m := 11; ; execute (discreteLogarithm(a, b, m))->display();; operation powmod(x : OclAny, y : OclAny, p : OclAny) pre: true post: true activity: var res : int := 1; ; x := x mod p; ; while (y > 0) do ( if (MathLib.bitwiseAnd(y, 1)) then ( res := (res * x) mod p; ) else skip ; y := y /(2->pow(1)); ; x := (x * x) mod p;) ; return res;; operation discreteLogarithm(a : OclAny, b : OclAny, m : OclAny) pre: true post: true activity: var n : int := ("" + (((m)->sqrt() + 1)))->toInteger(); ; var value : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m); ; for i : Integer.subrange(0 + 1, n)->reverse() do ( value[powmod(a, i * n, m)+1] := i;) ; for j : Integer.subrange(0, n-1) do ( var cur : int := (powmod(a, j, m) * b) mod m; ; if (value[cur+1]) then ( var ans : double := value[cur+1] * n - j; ; if ((ans->compareTo(m)) < 0) then ( return ans; ) else skip ) else skip) ; return -1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Circumference(l,w): return(2*(l+w)) l=8 w=4 c=Circumference(l,w) print("Circumference of a"+" rectangle is % d" %(c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; l := 8 ; w := 4 ; var c : OclAny := Circumference(l, w) ; execute ("Circumference of a" + StringLib.format(" rectangle is % d",(c)))->display(); operation Circumference(l : OclAny, w : OclAny) : OclAny pre: true post: true activity: return (2 * (l + w)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for j in range(0,n): m=int(input()) a=input().split() l=[] p=[] for o in range(0,m): if int(a[o])not in l : l.append(int(a[o])) else : p.append(int(a[o])) b=False for i in range(0,len(l)): if i not in l : b=True break if b : s=(i) else : s=(len(l)) if p==[]: print(s) else : b=False for i in range(0,len(p)): if i not in p : b=True break if b : print(s+i) else : print(s+len(p)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, n-1) do ( var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := input().split() ; var l : Sequence := Sequence{} ; var p : Sequence := Sequence{} ; for o : Integer.subrange(0, m-1) do ( if (l)->excludes(("" + ((a[o+1])))->toInteger()) then ( execute ((("" + ((a[o+1])))->toInteger()) : l) ) else ( execute ((("" + ((a[o+1])))->toInteger()) : p) )) ; var b : boolean := false ; for i : Integer.subrange(0, (l)->size()-1) do ( if (l)->excludes(i) then ( b := true ; break ) else skip) ; if b then ( var s : OclAny := (i) ) else ( s := ((l)->size()) ) ; if p = Sequence{} then ( execute (s)->display() ) else ( b := false ; for i : Integer.subrange(0, (p)->size()-1) do ( if (p)->excludes(i) then ( b := true ; break ) else skip) ; if b then ( execute (s + i)->display() ) else ( execute (s + (p)->size())->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=0 c1=0 for _ in range(int(input(''))): x,y=map(int,input().split()) if x>0 : c+=1 else : c1+=1 if c==0 or c1==0 : print('Yes') else : if c==1 or c1==1 : print('YES') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : int := 0 ; var c1 : int := 0 ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine(''))))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x > 0 then ( c := c + 1 ) else ( c1 := c1 + 1 )) ; if c = 0 or c1 = 0 then ( execute ('Yes')->display() ) else ( if c = 1 or c1 = 1 then ( execute ('YES')->display() ) else ( execute ('No')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def edgeDisjoint(n): result=0 result=math.floor(n/2) return result if __name__=="__main__" : n=4 print(int(edgeDisjoint(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 4 ; execute (("" + ((edgeDisjoint(n))))->toInteger())->display() ) else skip; operation edgeDisjoint(n : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; result := (n / 2)->floor() ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,a,k): leader=0 size=n p=list(range(1,n+1)) res=[] for i in range(0,k): j=(leader+a[i])% size res.append(p[j]) p.pop(j) size-=1 leader=j % size print(*res) def main(): n,k=map(int,input().split()) a=[int(x)for x in input().split()] solve(n,a,k) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation solve(n : OclAny, a : OclAny, k : OclAny) pre: true post: true activity: var leader : int := 0 ; var size : OclAny := n ; var p : Sequence := (Integer.subrange(1, n + 1-1)) ; var res : Sequence := Sequence{} ; for i : Integer.subrange(0, k-1) do ( var j : int := (leader + a[i+1]) mod size ; execute ((p[j+1]) : res) ; p := p->excludingAt(j+1) ; size := size - 1 ; leader := j mod size) ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display(); operation main() pre: true post: true activity: Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; solve(n, a, k); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) A=list(map(int,input().split())) X=list(range(n)) cur=0 ans=[] for i in range(k): m=len(X) j=(cur+A[i])% m ans.append(X.pop(j)) cur=j ans=[i+1 for i in ans] print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var X : Sequence := (Integer.subrange(0, n-1)) ; var cur : int := 0 ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, k-1) do ( var m : int := (X)->size() ; var j : int := (cur + A[i+1]) mod m ; execute ((X->at(j`firstArg+1)) : ans) ; cur := j) ; ans := ans->select(i | true)->collect(i | (i + 1)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) s=[int(i)for i in input().split()] a=[i for i in range(1,n+1)] r=0 j=0 d=[] for i in range(k): if j==len(a): j=0 for _ in range(s[i]% len(a)): if j>=len(a)-1 : j=0 else : j+=1 d.append(a.pop(j)) print(*d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a : Sequence := Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | (i)) ; var r : int := 0 ; var j : int := 0 ; var d : Sequence := Sequence{} ; for i : Integer.subrange(0, k-1) do ( if j = (a)->size() then ( j := 0 ) else skip ; for _anon : Integer.subrange(0, s[i+1] mod (a)->size()-1) do ( if (j->compareTo((a)->size() - 1)) >= 0 then ( j := 0 ) else ( j := j + 1 )) ; execute ((a->at(j`firstArg+1)) : d)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name d))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) kids=[i+1 for i in range(n)] a=[int(x)for x in input().split()] lead=0 for i in range(k): x=(a[i]+lead)% len(kids) lead=x if lead==len(kids)-1 : lead=0 print(kids.pop(x),end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var kids : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i + 1)) ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var lead : int := 0 ; for i : Integer.subrange(0, k-1) do ( var x : int := (a[i+1] + lead) mod (kids)->size() ; lead := x ; if lead = (kids)->size() - 1 then ( lead := 0 ) else skip ; execute (kids->at(x`firstArg+1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sum=[0 for i in range(1000005)] def toInt(x): return int(x) def prepareSum(s): sum[0]=0 for i in range(0,len(s)): sum[i+1]=sum[i]+toInt(s[i]) def query(l,r): if((sum[r+1]-sum[l])% 3==0): print("Divisible by 3") else : print("Not divisible by 3") if __name__=='__main__' : n="12468236544" prepareSum(n) query(0,1) query(1,2) query(3,6) query(0,10) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sum : Sequence := Integer.subrange(0, 1000005-1)->select(i | true)->collect(i | (0)) ; skip ; skip ; skip ; if __name__ = '__main__' then ( var n : String := "12468236544" ; prepareSum(n) ; query(0, 1) ; query(1, 2) ; query(3, 6) ; query(0, 10) ) else skip; operation toInt(x : OclAny) : OclAny pre: true post: true activity: return ("" + ((x)))->toInteger(); operation prepareSum(s : OclAny) pre: true post: true activity: ->first()->sum() := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( [i + 1+1]->sum() := [i+1]->sum() + toInt(s[i+1])); operation query(l : OclAny, r : OclAny) pre: true post: true activity: if (([r + 1+1]->sum() - [l+1]->sum()) mod 3 = 0) then ( execute ("Divisible by 3")->display() ) else ( execute ("Not divisible by 3")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): LIMIT=100000 rads=[0]+[1]*LIMIT for i in range(2,len(rads)): if rads[i]==1 : for j in range(i,len(rads),i): rads[j]*=i data=sorted((rad,i)for(i,rad)in enumerate(rads)) return str(data[10000][1]) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LIMIT : int := 100000 ; var rads : Sequence := Sequence{ 0 }->union(MatrixLib.elementwiseMult(Sequence{ 1 }, LIMIT)) ; for i : Integer.subrange(2, (rads)->size()-1) do ( if rads[i+1] = 1 then ( for j : Integer.subrange(i, (rads)->size()-1)->select( $x | ($x - i) mod i = 0 ) do ( rads[j+1] := rads[j+1] * i) ) else skip) ; var data : Sequence := (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name rad)))))) , (test (logical_test (comparison (expr (atom (name i))))))) )))))) (comp_for for (exprlist (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) , (test (logical_test (comparison (expr (atom (name rad))))))) )))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name rads)))))))) ))))))))->sort() ; return ("" + ((data[10000+1][1+1]))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) x=[int(i)for i in input().strip().split()] for xi in x : val=xi % 14 if xi>14 and val<=6 and val>0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := input()->trim().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; for xi : x do ( var val : int := xi mod 14 ; if xi > 14 & val <= 6 & val > 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() a=input() for j in list(map(int,input().split())): print("YNEOS"[1-(j % 14 in range(1,7)and j>14): : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var a : String := (OclFile["System.in"]).readLine() ; for j : ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) do ( execute ("YNEOS"(subscript (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) - (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (expr (atom (name j))) % (expr (atom (number (integer 14)))))) in (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 7))))))))) ))))))) and (logical_test (comparison (comparison (expr (atom (name j)))) > (comparison (expr (atom (number (integer 14)))))))))) ))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt from collections import defaultdict,deque from bisect import bisect_left as b_l from bisect import bisect_right as b_r import sys mod=10**9+7 t=int(input()) a=[int(i)for i in input().split()] for i in a : if(i>14 and(i % 14>0 and i % 14<7)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; for i : a do ( if (i > 14 & (i mod 14 > 0 & i mod 14 < 7)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,x,m=map(int,input().split()) lb=x ub=x for i in range(m): a,b=map(int,input().split()) if(a<=lb and b>=lb or lb<=a<=ub): lb=min(lb,a) ub=max(ub,b) else : print(ub-lb+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; var m : OclAny := null; Sequence{n,x,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lb : OclAny := x ; var ub : OclAny := x ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name m)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name b))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (logical_test (comparison (comparison (expr (atom (name a)))) <= (comparison (expr (atom (name lb)))))) and (logical_test (comparison (comparison (expr (atom (name b)))) >= (comparison (expr (atom (name lb))))))) or (logical_test (comparison (comparison (comparison (expr (atom (name lb)))) <= (comparison (expr (atom (name a))))) <= (comparison (expr (atom (name ub))))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name lb)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name lb))))))) , (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ub)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ub))))))) , (argument (test (logical_test (comparison (expr (atom (name b)))))))) ))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name ub))) - (expr (atom (name lb)))) + (expr (atom (number (integer 1)))))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : T,D,L=map(int,input().split()) if T==0 : break a=[] for i in range(T): x=int(input()) if x>=L : a.append(i) T,ans=T-1,0 for i in range(1,len(a)): x=D if T-a[i-1]T else D print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var T : OclAny := null; var D : OclAny := null; var L : OclAny := null; Sequence{T,D,L} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if T = 0 then ( break ) else skip ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, T-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (x->compareTo(L)) >= 0 then ( execute ((i) : a) ) else skip) ; var T : OclAny := null; var ans : OclAny := null; Sequence{T,ans} := Sequence{T - 1,0} ; for i : Integer.subrange(1, (a)->size()-1) do ( x := D ; if (T - a[i - 1+1]->compareTo(D)) < 0 then ( x := T - a[i - 1+1] ) else skip ; if (a[i+1] - a[i - 1+1]->compareTo(x)) < 0 then ( ans := ans + a[i+1] - a[i - 1+1] ) else ( ans := ans + x )) ; if a then ( ans := ans + if (a->last() + D->compareTo(T)) > 0 then T - a->last() else D endif ) else skip ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(0,t): n=int(input()) a=input().split() c=[] for j in a : c.append(int(j)) ans=0 a=c bl=False bl2=False bl3=False for k in range(0,len(a)): if a[k]!=k : bl3=True if bl3 : for j in range(0,max(c)+2): if a.count(j)==0 : bl2=True if bl : ans=ans+j break else : ans=ans+2*j break elif a.count(j)==1 and bl==False : ans=ans+j bl=True print(ans) else : print(max(c)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := input().split() ; var c : Sequence := Sequence{} ; for j : a do ( execute ((("" + ((j)))->toInteger()) : c)) ; var ans : int := 0 ; a := c ; var bl : boolean := false ; var bl2 : boolean := false ; var bl3 : boolean := false ; for k : Integer.subrange(0, (a)->size()-1) do ( if a[k+1] /= k then ( bl3 := true ) else skip) ; if bl3 then ( for j : Integer.subrange(0, (c)->max() + 2-1) do ( if a->count(j) = 0 then ( bl2 := true ; if bl then ( ans := ans + j ; break ) else ( ans := ans + 2 * j ; break ) ) else (if a->count(j) = 1 & bl = false then ( ans := ans + j ; bl := true ) else skip)) ; execute (ans)->display() ) else ( execute ((c)->max() + 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) y=list(map(int,input().split())) for i in range(x): if 1<=y[i]% 14<=6 and y[i]>14 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var y : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, x-1) do ( if 1 <= y[i+1] mod 14 & (y[i+1] mod 14 <= 6) & y[i+1] > 14 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(n): return 'YES' if n>14 and 1<=n % 14<=6 else 'NO' n=int(input()) [print(f(int(c)))for c in input().split()] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; ; operation f(n : OclAny) : OclAny pre: true post: true activity: return if n > 14 & 1 <= n mod 14 & (n mod 14 <= 6) then 'YES' else 'NO' endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): import sys input=sys.stdin.readline sys.setrecursionlimit(10**6) n,m=map(int,input().split()) if m>n*2 : print(n+(m-n*2)//4) else : print(m//2) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit((10)->pow(6)) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (m->compareTo(n * 2)) > 0 then ( execute (n + (m - n * 2) div 4)->display() ) else ( execute (m div 2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import floor s_num,c_num=tuple(int(i)for i in input().split(" ")) ans=0 temp=s_num*2 if c_num<=temp : ans+=floor(c_num/2) else : ans+=s_num ans+=floor((c_num-temp)/4) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s_num : OclAny := null; var c_num : OclAny := null; Sequence{s_num,c_num} := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " "))))))) ))))))))) ; var ans : int := 0 ; var temp : double := s_num * 2 ; if (c_num->compareTo(temp)) <= 0 then ( ans := ans + floor(c_num / 2) ) else ( ans := ans + s_num ; ans := ans + floor((c_num - temp) / 4) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def examC(): N,M=LI() if N-M//2>=0 : ans=M//2 else : ans=N+(M-N*2)//4 print(ans) return def examD(): return def examE(): return def examF(): ans=0 print(ans) return import sys,copy,bisect,itertools,heapq,math from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) def LSI(): return list(map(str,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod,mod2,inf,alphabet mod=10**9+7 mod2=998244353 inf=10**18 alphabet=[chr(ord('a')+i)for i in range(26)] if __name__=='__main__' : examC() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute mod : OclAny; attribute mod2 : OclAny; attribute inf : OclAny; attribute alphabet : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip; skip; skip; skip ; mod := (10)->pow(9) + 7 ; mod2 := 998244353 ; Math_PINFINITY := (10)->pow(18) ; alphabet := Integer.subrange(0, 26-1)->select(i | true)->collect(i | ((('a')->char2byte() + i)->byte2char())) ; if __name__ = '__main__' then ( examC() ) else skip; operation examC() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := LI() ; if N - M div 2 >= 0 then ( var ans : int := M div 2 ) else ( ans := N + (M - N * 2) div 4 ) ; execute (ans)->display() ; return; operation examD() pre: true post: true activity: return; operation examE() pre: true post: true activity: return; operation examF() pre: true post: true activity: ans := 0 ; execute (ans)->display() ; return; operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LSI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["String"])->apply(_x) )); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation SI() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=[int(x)for x in input().split()] def check(x): if M<2*x : return False s=max(0,x-N) if M<2*s+2*x : return False return True ok=0 ng=2**60 while ng-ok>1 : m=(ok+ng)//2 if check(m): ok=m else : ng=m print(ok) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; skip ; var ok : int := 0 ; var ng : double := (2)->pow(60) ; while ng - ok > 1 do ( var m : int := (ok + ng) div 2 ; if check(m) then ( ok := m ) else ( ng := m )) ; execute (ok)->display(); operation check(x : OclAny) : OclAny pre: true post: true activity: if (M->compareTo(2 * x)) < 0 then ( return false ) else skip ; var s : OclAny := Set{0, x - N}->max() ; if (M->compareTo(2 * s + 2 * x)) < 0 then ( return false ) else skip ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(N,M): ans=min(M//2,N) x=(M-2*N)//4 for i in range(x-5,x+6): if i>=0 and M>=2*i : M2=M-2*i N2=N+i ans=max(ans,min(M2//2,N2)) return ans N,M=map(int,input().split()) ret=solve(N,M) print(ret) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ret : OclAny := solve(N, M) ; execute (ret)->display(); operation solve(N : OclAny, M : OclAny) : OclAny pre: true post: true activity: var ans : OclAny := Set{M div 2, N}->min() ; var x : int := (M - 2 * N) div 4 ; for i : Integer.subrange(x - 5, x + 6-1) do ( if i >= 0 & (M->compareTo(2 * i)) >= 0 then ( var M2 : double := M - 2 * i ; var N2 : OclAny := N + i ; ans := Set{ans, Set{M2 div 2, N2}->min()}->max() ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def printFirstNegativeInteger(arr,n,k): Di=deque() for i in range(k): if(arr[i]<0): Di.append(i); for i in range(k,n): if(not Di): print(0,end=' ') else : print(arr[Di[0]],end=' '); while Di and Di[0]<=(i-k): Di.popleft() if(arr[i]<0): Di.append(i); if not Di : print(0) else : print(arr[Di[0]],end=" ") if __name__=="__main__" : arr=[12,-1,-7,8,-15,30,16,28] n=len(arr) k=3 printFirstNegativeInteger(arr,n,k); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{12}->union(Sequence{-1}->union(Sequence{-7}->union(Sequence{8}->union(Sequence{-15}->union(Sequence{30}->union(Sequence{16}->union(Sequence{ 28 }))))))) ; n := (arr)->size() ; k := 3 ; printFirstNegativeInteger(arr, n, k); ) else skip; operation printFirstNegativeInteger(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var Di : Sequence := () ; for i : Integer.subrange(0, k-1) do ( if (arr[i+1] < 0) then ( execute ((i) : Di); ) else skip) ; for i : Integer.subrange(k, n-1) do ( if (not(Di)) then ( execute (0)->display() ) else ( execute (arr[Di->first()+1])->display(); ) ; while Di & (Di->first()->compareTo((i - k))) <= 0 do ( Di := Di->tail()) ; if (arr[i+1] < 0) then ( execute ((i) : Di); ) else skip) ; if not(Di) then ( execute (0)->display() ) else ( execute (arr[Di->first()+1])->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==2 : a,b=map(int,input().split()) small=min(a,b) large=max(a,b) for i in range(1,min(small,large//2)): if a % i==0 and b % i==0 : print(i) else : a,b,c=map(int,input().split()) small=min(a,b,c) large=max(a,b,c) for i in range(1,min(small,large//2)): if a % i==0 and b % i==0 and c % i==0 : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 2 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var small : OclAny := Set{a, b}->min() ; var large : OclAny := Set{a, b}->max() ; for i : Integer.subrange(1, Set{small, large div 2}->min()-1) do ( if a mod i = 0 & b mod i = 0 then ( execute (i)->display() ) else skip) ) else ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; small := Set{a, b, c}->min() ; large := Set{a, b, c}->max() ; for i : Integer.subrange(1, Set{small, large div 2}->min()-1) do ( if a mod i = 0 & b mod i = 0 & c mod i = 0 then ( execute (i)->display() ) else skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : T,D,L=map(int,input().split()) if T==0 : exit() XXX=[int(input())for i in range(T)] limit_time=0 ans=0 swet_time=0 for i,x in enumerate(XXX): if limit_time>0 : swet_time+=1 limit_time-=1 if x>=L : limit_time=D if limit_time==0 : ans+=swet_time swet_time=0 elif i==len(XXX)-1 : ans+=swet_time print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var T : OclAny := null; var D : OclAny := null; var L : OclAny := null; Sequence{T,D,L} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if T = 0 then ( exit() ) else skip ; var XXX : Sequence := Integer.subrange(0, T-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var limit_time : int := 0 ; var ans : int := 0 ; var swet_time : int := 0 ; for _tuple : Integer.subrange(1, (XXX)->size())->collect( _indx | Sequence{_indx-1, (XXX)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); if limit_time > 0 then ( swet_time := swet_time + 1 ; limit_time := limit_time - 1 ) else skip ; if (x->compareTo(L)) >= 0 then ( limit_time := D ) else skip ; if limit_time = 0 then ( ans := ans + swet_time ; swet_time := 0 ) else (if i = (XXX)->size() - 1 then ( ans := ans + swet_time ) else skip)) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(n1,n2): if n1toInteger() ; var number_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if N = 2 then ( var GCD : OclAny := gcd(number_list->first(), number_list[1+1]) ) else ( GCD := gcd(gcd(number_list->first(), number_list[1+1]), number_list[2+1]) ) ) else skip ; ; operation gcd(n1 : OclAny, n2 : OclAny) : OclAny pre: true post: true activity: if (n1->compareTo(n2)) < 0 then ( Sequence{n1,n2} := Sequence{n2,n1} ) else skip ; if n1 = n2 or n2 = 0 then ( return n1 ) else skip ; Sequence{n1,n2} := Sequence{n2,(n1 mod n2)} ; return gcd(n1, n2); operation make_divisor_list(number : OclAny) : OclAny pre: true post: true activity: var divisor_list : Sequence := Sequence{} ; if number = 1 then ( return Sequence{ 1 } ) else skip ; for i : Integer.subrange(1, number div 2 + 1-1) do ( if number mod i = 0 then ( execute ((i) : divisor_list) ) else skip) ; execute ((number) : divisor_list) ; return divisor_list; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: a=[0]*101 for x in s.split(): a[int(x)]+=1 i=a.index(0); a[i]=1 ; print(i+a.index(1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 101) ; for x : s.split() do ( a[("" + ((x)))->toInteger()+1] := a[("" + ((x)))->toInteger()+1] + 1) ; var i : int := a->indexOf(0) - 1; a[i+1] := 1; execute (i + a->indexOf(1) - 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math n=int(sys.stdin.readline().rstrip()) nums=list(map(int,sys.stdin.readline().rstrip().split())) g=nums[0] for num in nums[1 :]: g=math.gcd(g,num) ans=set() for i in range(1,int(math.sqrt(g))+1): if g % i==0 : ans.add(i) ans.add(g//i) for n in sorted(ans): print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + ((sys.stdin.readLine().rstrip())))->toInteger() ; var nums : Sequence := ((sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var g : OclAny := nums->first() ; for num : nums->tail() do ( g := (g)->gcd(num)) ; var ans : Set := Set{}->union(()) ; for i : Integer.subrange(1, ("" + (((g)->sqrt())))->toInteger() + 1-1) do ( if g mod i = 0 then ( execute ((i) : ans) ; execute ((g div i) : ans) ) else skip) ; for n : ans->sort() do ( execute (n)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() n=list(map(int,input().split())) [print(x)for x in range(1,min(n)+1)if sum(m % x for m in n)==0] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var n : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) Ans=[] if n==2 : l=input().split() a=int(l[0]) b=int(l[1]) if a>=b : for i in range(1,b+1): if b % i==0 : if a % i==0 : Ans.append(i) else : pass else : pass else : for i in range(1,a+1): if a % i==0 : if b % i==0 : Ans.append(i) else : pass else : pass else : l=input().split() p=[] p.append(int(l[0])) p.append(int(l[1])) p.append(int(l[2])) c=max(p) p.remove(c) a=p[0] b=p[1] if a>=b : for i in range(1,b+1): if b % i==0 : if a % i==0 : if c % i==0 : Ans.append(i) else : pass else : pass else : pass else : for i in range(1,a+1): if a % i==0 : if b % i==0 : if c % i==0 : Ans.append(i) else : pass else : pass else : pass for A in Ans : print(A) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var Ans : Sequence := Sequence{} ; if n = 2 then ( var l : OclAny := input().split() ; var a : int := ("" + ((l->first())))->toInteger() ; var b : int := ("" + ((l[1+1])))->toInteger() ; if (a->compareTo(b)) >= 0 then ( for i : Integer.subrange(1, b + 1-1) do ( if b mod i = 0 then ( if a mod i = 0 then ( execute ((i) : Ans) ) else ( skip ) ) else ( skip )) ) else ( for i : Integer.subrange(1, a + 1-1) do ( if a mod i = 0 then ( if b mod i = 0 then ( execute ((i) : Ans) ) else ( skip ) ) else ( skip )) ) ) else ( l := input().split() ; var p : Sequence := Sequence{} ; execute ((("" + ((l->first())))->toInteger()) : p) ; execute ((("" + ((l[1+1])))->toInteger()) : p) ; execute ((("" + ((l[2+1])))->toInteger()) : p) ; var c : OclAny := (p)->max() ; execute ((c) /: p) ; a := p->first() ; b := p[1+1] ; if (a->compareTo(b)) >= 0 then ( for i : Integer.subrange(1, b + 1-1) do ( if b mod i = 0 then ( if a mod i = 0 then ( if c mod i = 0 then ( execute ((i) : Ans) ) else ( skip ) ) else ( skip ) ) else ( skip )) ) else ( for i : Integer.subrange(1, a + 1-1) do ( if a mod i = 0 then ( if b mod i = 0 then ( if c mod i = 0 then ( execute ((i) : Ans) ) else ( skip ) ) else ( skip ) ) else ( skip )) ) ) ; for A : Ans do ( execute (A)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(9): name,a,p=map(str,input().split()) print(name,int(a)+int(p),int(a)*200+int(p)*300) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, 9-1) do ( var name : OclAny := null; var a : OclAny := null; var p : OclAny := null; Sequence{name,a,p} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; execute (name)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=0 a=[0,0,0] while k<27 : a[0],a[1],a[2]=input().split() x=int(a[1])+int(a[2]) y=200*int(a[1])+300*int(a[2]) print(a[0],x,y) k=k+3 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := 0 ; var a : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) ; while k < 27 do ( var a->first() : OclAny := null; var a[1+1] : OclAny := null; var a[2+1] : OclAny := null; Sequence{a->first(),a[1+1],a[2+1]} := input().split() ; var x : int := ("" + ((a[1+1])))->toInteger() + ("" + ((a[2+1])))->toInteger() ; var y : int := 200 * ("" + ((a[1+1])))->toInteger() + 300 * ("" + ((a[2+1])))->toInteger() ; execute (a->first())->display() ; k := k + 3); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- classmate=[] morning=[] afternoon=[] for i in range(9): a,b,c=input().split() classmate.append(a) morning.append(int(b)) afternoon.append(int(c)) for i in range(9): print(classmate[i],morning[i]+afternoon[i],morning[i]*200+afternoon[i]*300) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var classmate : Sequence := Sequence{} ; var morning : Sequence := Sequence{} ; var afternoon : Sequence := Sequence{} ; for i : Integer.subrange(0, 9-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := input().split() ; execute ((a) : classmate) ; execute ((("" + ((b)))->toInteger()) : morning) ; execute ((("" + ((c)))->toInteger()) : afternoon)) ; for i : Integer.subrange(0, 9-1) do ( execute (classmate[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- list=[] for i in range(9): n,a,b=input().split() a=int(a) b=int(b) list.append((n,int(a),int(b))) print(n,end=' ') print(a+b,end=' ') print(a*200+b*300) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var OclType["Sequence"] : Sequence := Sequence{} ; for i : Integer.subrange(0, 9-1) do ( var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := input().split() ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; execute ((Sequence{n, ("" + ((a)))->toInteger(), ("" + ((b)))->toInteger()}) : OclType["Sequence"]) ; execute (n)->display() ; execute (a + b)->display() ; execute (a * 200 + b * 300)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=0 for i in range(9): a,b,c=map(str,input().split()) b=int(b) c=int(c) print(a,b+c,b*200+c*300) i+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : int := 0 ; for i : Integer.subrange(0, 9-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; var b : int := ("" + ((b)))->toInteger() ; var c : int := ("" + ((c)))->toInteger() ; execute (a)->display() ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : t,d,l=map(int,input().split()) if t==d==l==0 : break x=[0]*(t+1) for i in range(t): s=int(input()) if s0 : s+=1 print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var t : OclAny := null; var d : OclAny := null; var l : OclAny := null; Sequence{t,d,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if t = d & (d == l) & (l == 0) then ( break ) else skip ; var x : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (t + 1)) ; for i : Integer.subrange(0, t-1) do ( var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (s->compareTo(l)) < 0 then ( continue ) else skip ; x[i+1] := x[i+1] + 1 ; x[Set{i + d, t}->min()+1] := x[Set{i + d, t}->min()+1] - 1) ; var y : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, t) ; y->first() := x->first() ; for i : Integer.subrange(0, t - 1-1) do ( y[i + 1+1] := y[i+1] + x[i + 1+1]) ; s := 0 ; for i : y->front() do ( if i > 0 then ( s := s + 1 ) else skip) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- xp1,yp1,xp2,yp2=map(int,input().split()) q=int(input()) if xp1==xp2 : for i in range(q): x0,y0=map(int,input().split()) print('{:.10f}'.format(2*xp1-x0),'{:.10f}'.format(y0)) else : a=float((yp2-yp1)/(xp2-xp1)) for i in range(q): x0,y0=map(int,input().split()) x=a*((y0-yp1)-a*(x0-xp1))/(1+a**2)+x0 y=(a*(a*y0+x0-xp1)+yp1)/(1+a**2) print('{:.10f}'.format(2*x-x0),'{:.10f}'.format(2*y-y0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var xp1 : OclAny := null; var yp1 : OclAny := null; var xp2 : OclAny := null; var yp2 : OclAny := null; Sequence{xp1,yp1,xp2,yp2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if xp1 = xp2 then ( for i : Integer.subrange(0, q-1) do ( var x0 : OclAny := null; var y0 : OclAny := null; Sequence{x0,y0} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (StringLib.interpolateStrings('{:.10f}', Sequence{2 * xp1 - x0}))->display()) ) else ( var a : double := ("" + (((yp2 - yp1) / (xp2 - xp1))))->toReal() ; for i : Integer.subrange(0, q-1) do ( var x0 : OclAny := null; var y0 : OclAny := null; Sequence{x0,y0} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : double := a * ((y0 - yp1) - a * (x0 - xp1)) / (1 + (a)->pow(2)) + x0 ; var y : double := (a * (a * y0 + x0 - xp1) + yp1) / (1 + (a)->pow(2)) ; execute (StringLib.interpolateStrings('{:.10f}', Sequence{2 * x - x0}))->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Vector : def __init__(self,x,y): self.x=x self.y=y def is_orthogonal(self,v): if self.x*v.x+self.y*v.y==0 : return True else : return False def is_parallel(self,v): if self.x*v.y-self.y*v.x==0 : return True else : return False def dot_product(self,v): return self.x*v.x+self.y*v.y def quadrance(self): return self.x**2+self.y**2 def mul(self,k): return Vector(self.x*k,self.y*k) def __add__(self,v): return Vector(self.x+v.x,self.y+v.y) def __sub__(self,v): return Vector(self.x-v.x,self.y-v.y) def __str__(self): return "{0:.8f}{1:.8f}".format(self.x,self.y) def projection_on(self,v): return v.mul(self.dot_product(v)/v.quadrance()) def rejection_from(self,v): return self-self.projection_on(v) import sys file_input=sys.stdin x_p1,y_p1,x_p2,y_p2=map(int,file_input.readline().split()) p1_p2=Vector(x_p2-x_p1,y_p2-y_p1) q=int(file_input.readline()) for line in file_input : x_p,y_p=map(int,line.split()) p1_p=Vector(x_p-x_p1,y_p-y_p1) r_v=p1_p.rejection_from(p1_p2) o_p=Vector(x_p,y_p) print(o_p-r_v.mul(2)) ------------------------------------------------------------ OCL File: --------- class Vector { static operation newVector() : Vector pre: true post: Vector->exists( _x | result = _x ); attribute x : OclAny := x; attribute y : OclAny := y; operation initialise(x : OclAny,y : OclAny) : Vector pre: true post: true activity: self.x := x ; self.y := y; return self; operation is_orthogonal(v : OclAny) : OclAny pre: true post: true activity: if self.x * v.x + self.y * v.y = 0 then ( return true ) else ( return false ); operation is_parallel(v : OclAny) : OclAny pre: true post: true activity: if self.x * v.y - self.y * v.x = 0 then ( return true ) else ( return false ); operation dot_product(v : OclAny) : OclAny pre: true post: true activity: return self.x * v.x + self.y * v.y; operation quadrance() : OclAny pre: true post: true activity: return (self.x)->pow(2) + (self.y)->pow(2); operation mul(k : OclAny) : OclAny pre: true post: true activity: return Vector(self.x * k, self.y * k); operation __add__(v : OclAny) : OclAny pre: true post: true activity: return Vector(self.x + v.x, self.y + v.y); operation __sub__(v : OclAny) : OclAny pre: true post: true activity: return Vector(self.x - v.x, self.y - v.y); operation __str__() : OclAny pre: true post: true activity: return StringLib.interpolateStrings("{0:.8f}{1:.8f}", Sequence{self.x, self.y}); operation projection_on(v : OclAny) : OclAny pre: true post: true activity: return v.mul(self.dot_product(v) / v.quadrance()); operation rejection_from(v : OclAny) : OclAny pre: true post: true activity: return self - self.projection_on(v); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var file_input : OclFile := OclFile["System.in"] ; var x_p1 : OclAny := null; var y_p1 : OclAny := null; var x_p2 : OclAny := null; var y_p2 : OclAny := null; Sequence{x_p1,y_p1,x_p2,y_p2} := (file_input.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p1_p2 : Vector := (Vector.newVector()).initialise(x_p2 - x_p1, y_p2 - y_p1) ; var q : int := ("" + ((file_input.readLine())))->toInteger() ; for line : file_input do ( var x_p : OclAny := null; var y_p : OclAny := null; Sequence{x_p,y_p} := (line.split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p1_p : Vector := (Vector.newVector()).initialise(x_p - x_p1, y_p - y_p1) ; var r_v : OclAny := p1_p.rejection_from(p1_p2) ; var o_p : Vector := (Vector.newVector()).initialise(x_p, y_p) ; execute (o_p - r_v.mul(2))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) d={i : 0 for i in range(101)} arr=list(map(int,input().split())) if arr.count(0)==0 : print(0) else : for v in arr : d[v]+=1 r1=0 r2=0 for i in range(100,-1,-1): if d[i]==0 : r1=i if d[i]<=1 : r2=i print(r1+r2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Map := Integer.subrange(0, 101-1)->select(i | true)->collect(i | Map{i |-> 0})->unionAll() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if arr->count(0) = 0 then ( execute (0)->display() ) else ( for v : arr do ( d[v+1] := d[v+1] + 1) ; var r1 : int := 0 ; var r2 : int := 0 ; for i : Integer.subrange(-1 + 1, 100)->reverse() do ( if d[i+1] = 0 then ( r1 := i ) else skip ; if d[i+1] <= 1 then ( r2 := i ) else skip) ; execute (r1 + r2)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dot(a,b): return a.real*b.real+a.imag*b.imag x1,y1,x2,y2=map(int,input().split()) p1=x1+y1*1j p2=x2+y2*1j l=p2-p1 l_norm=dot(l,l) q=int(input()) for x3,y3 in(map(int,input().split())for _ in[0]*q): p3=x3+y3*1j a=p3-p1 k=dot(a,l)/l_norm projection_vector=k*l reflect_vector=projection_vector-a print(x3+2*reflect_vector.real,y3+2*reflect_vector.imag) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p1 : OclAny := x1 + y1 * 1j ; var p2 : OclAny := x2 + y2 * 1j ; var l : double := p2 - p1 ; var l_norm : OclAny := dot(l, l) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _tuple : Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr (atom (name q))))))))} do (var _indx : int := 1; var x3 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y3 : OclAny := _tuple->at(_indx); var p3 : OclAny := x3 + y3 * 1j ; a := p3 - p1 ; var k : double := dot(a, l) / l_norm ; var projection_vector : double := k * l ; var reflect_vector : double := projection_vector - a ; execute (x3 + 2 * reflect_vector.real)->display()); operation dot(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a.real * b.real + a.imag * b.imag; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def inner_product(v1,v2): return v1.real*v2.real+v1.imag*v2.imag def project(a,b): return a*inner_product(a,b)/(abs(a)**2) def reflect(p0,p1,p2): a=p1-p0 b=p2-p0 v=project(a,b) u=v-b p3=p2+2*u return p3 def main(): x_p0,y_p0,x_p1,y_p1=map(float,input().split()) p0=complex(x_p0,y_p0) p1=complex(x_p1,y_p1) q=int(input()) for _ in range(q): p2=complex(*map(float,input().split())) t=reflect(p0,p1,p2) print("{:.10f}{:.10f}".format(t.real,t.imag)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation inner_product(v1 : OclAny, v2 : OclAny) : OclAny pre: true post: true activity: return v1.real * v2.real + v1.imag * v2.imag; operation project(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a * inner_product(a, b) / (((a)->abs())->pow(2)); operation reflect(p0 : OclAny, p1 : OclAny, p2 : OclAny) : OclAny pre: true post: true activity: a := p1 - p0 ; b := p2 - p0 ; var v : OclAny := project(a, b) ; var u : double := v - b ; var p3 : OclAny := p2 + 2 * u ; return p3; operation main() pre: true post: true activity: var x_p0 : OclAny := null; var y_p0 : OclAny := null; var x_p1 : OclAny := null; var y_p1 : OclAny := null; Sequence{x_p0,y_p0,x_p1,y_p1} := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; p0 := complex(x_p0, y_p0) ; p1 := complex(x_p1, y_p1) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( p2 := complex((argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name float))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ; var t : OclAny := reflect(p0, p1, p2) ; execute (StringLib.interpolateStrings("{:.10f}{:.10f}", Sequence{t.real, t.imag}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import math class Vector2(collections.namedtuple("Vector2",["x","y"])): def __add__(self,other): return Vector2(self.x+other.x,self.y+other.y) def __sub__(self,other): return Vector2(self.x-other.x,self.y-other.y) def __mul__(self,scalar): return Vector2(self.x*scalar,self.y*scalar) def __neg__(self): return Vector2(-self.x,-self.y) def __pos__(self): return Vector2(+self.x,+self.y) def __abs__(self): return math.sqrt(float(self.x*self.x+self.y*self.y)) def dot(self,other): return self.x*other.x+self.y*other.y def cross(self,other): return self.x*other.y-self.y*other.x if __name__=='__main__' : a,b,c,d=map(int,input().split()) p1=Vector2(a,b) p2=Vector2(c,d) base=p2-p1 q=int(input()) ans=[] for _ in range(q): e,f=map(int,input().split()) p=Vector2(e,f) hypo=Vector2(e-a,f-b) proj=p1+base*(hypo.dot(base)/float(base.x**2+base.y**2)) x=p+(proj-p)*2 ans.append(x) for x in ans : print(x.x,x.y) ------------------------------------------------------------ OCL File: --------- class Vector2 extends .namedtuple("Vector2", Sequence{"x"}->union(Sequence{ "y" })) { static operation newVector2() : Vector2 pre: true post: Vector2->exists( _x | result = _x ); operation __add__(other : OclAny) : OclAny pre: true post: true activity: return Vector2(self.x + other.x, self.y + other.y); operation __sub__(other : OclAny) : OclAny pre: true post: true activity: return Vector2(self.x - other.x, self.y - other.y); operation __mul__(scalar : OclAny) : OclAny pre: true post: true activity: return Vector2(self.x * scalar, self.y * scalar); operation __neg__() : OclAny pre: true post: true activity: return Vector2(-self.x, -self.y); operation __pos__() : OclAny pre: true post: true activity: return Vector2(self.x, self.y); operation __abs__() : OclAny pre: true post: true activity: return (("" + ((self.x * self.x + self.y * self.y)))->toReal())->sqrt(); operation dot(other : OclAny) : OclAny pre: true post: true activity: return self.x * other.x + self.y * other.y; operation cross(other : OclAny) : OclAny pre: true post: true activity: return self.x * other.y - self.y * other.x; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p1 : Vector2 := (Vector2.newVector2()).initialise(a, b) ; var p2 : Vector2 := (Vector2.newVector2()).initialise(c, d) ; var base : double := p2 - p1 ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, q-1) do ( var e : OclAny := null; var f : OclAny := null; Sequence{e,f} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : Vector2 := (Vector2.newVector2()).initialise(e, f) ; var hypo : Vector2 := (Vector2.newVector2()).initialise(e - a, f - b) ; var proj : OclAny := p1 + base * (hypo.dot(base) / ("" + (((base.x)->pow(2) + (base.y)->pow(2))))->toReal()) ; var x : OclAny := p + (proj - p) * 2 ; execute ((x) : ans)) ; for x : ans do ( execute (x.x)->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dot(a,b): return a[0]*b[0]+a[1]*b[1] def projection(a,b): return[x*dot(a,b)/dot(a,a)for x in a] x1,y1,x2,y2=[int(i)for i in input().split()] a=[x2-x1,y2-y1] q=int(input()) for i in range(q): x,y=[int(i)for i in input().split()] b=[x-x1,y-y1] c=projection(a,b) print(c[0]+x1,c[1]+y1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; a := Sequence{x2 - x1}->union(Sequence{ y2 - y1 }) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; b := Sequence{x - x1}->union(Sequence{ y - y1 }) ; var c : OclAny := projection(a, b) ; execute (c->first() + x1)->display()); operation dot(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a->first() * b->first() + a[1+1] * b[1+1]; operation projection(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a->select(x | true)->collect(x | (x * dot(a, b) / dot(a, a))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Vec2 : def __init__(self,y,x): self.y=y self.x=x def __add__(self,other): assert isinstance(other,Vec2) return Vec2(self.y+other.y,self.x+other.x) def __sub__(self,other): assert isinstance(other,Vec2) return Vec2(self.y-other.y,self.x-other.x) def __mul__(self,other): if isinstance(other,Vec2): return self.y*other.y+self.x*other.x else : return Vec2(self.y*other,self.x*other) def __str__(self): return str((self.y,self.x)) def size(self): return(self.x**2+self.y**2)**0.5 def projection(self,vec): p=self*vec/self.size()**2 return self*p def main(): x_p1,y_p1,x_p2,y_p2=map(int,input().split()) p1=Vec2(y_p1,x_p1) p2=Vec2(y_p2,x_p2) p1p2=p2-p1 q=int(input()) for _ in range(q): x_q,y_q=map(int,input().split()) p1q=Vec2(y_q,x_q)-p1 p1x=p1p2.projection(p1q) x=p1+p1x print(x.x,x.y) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class Vec2 { static operation newVec2() : Vec2 pre: true post: Vec2->exists( _x | result = _x ); attribute y : OclAny := y; attribute x : OclAny := x; operation initialise(y : OclAny,x : OclAny) : Vec2 pre: true post: true activity: self.y := y ; self.x := x; return self; operation __add__(other : OclAny) : OclAny pre: true post: true activity: assert (Vec2).isInstance(other) do "assertion failed" ; return Vec2(self.y + other.y, self.x + other.x); operation __sub__(other : OclAny) : OclAny pre: true post: true activity: assert (Vec2).isInstance(other) do "assertion failed" ; return Vec2(self.y - other.y, self.x - other.x); operation __mul__(other : OclAny) : OclAny pre: true post: true activity: if (Vec2).isInstance(other) then ( return self.y * other.y + self.x * other.x ) else ( return Vec2(self.y * other, self.x * other) ); operation __str__() : OclAny pre: true post: true activity: return ("" + ((Sequence{self.y, self.x}))); operation size() : OclAny pre: true post: true activity: return (((self.x)->pow(2) + (self.y)->pow(2)))->pow(0.5); operation projection(vec : OclAny) : OclAny pre: true post: true activity: var p : double := self * vec / (self.size())->pow(2) ; return self * p; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var x_p1 : OclAny := null; var y_p1 : OclAny := null; var x_p2 : OclAny := null; var y_p2 : OclAny := null; Sequence{x_p1,y_p1,x_p2,y_p2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p1 : Vec2 := (Vec2.newVec2()).initialise(y_p1, x_p1) ; var p2 : Vec2 := (Vec2.newVec2()).initialise(y_p2, x_p2) ; var p1p2 : double := p2 - p1 ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( var x_q : OclAny := null; var y_q : OclAny := null; Sequence{x_q,y_q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p1q : double := (Vec2.newVec2()).initialise(y_q, x_q) - p1 ; var p1x : OclAny := p1p2.projection(p1q) ; x := p1 + p1x ; execute (x.x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from itertools import starmap readline=sys.stdin.readline class Segment(object): __slots__=('fi','se') def __init__(self,fi,se): self.fi=fi self.se=se def cross(a,b): return a.real*b.imag-a.imag*b.real def dot(a,b): return a.real*b.real+a.imag*b.imag def norm(base): return abs(base)**2 def project(s,p2): base=s.fi-s.se r=dot(p2-s.fi,base)/norm(base) return s.fi+base*r s=Segment(*list(starmap(complex,zip(*[map(int,readline().split())]*2)))) n=int(readline()) for _ in[0]*n : p2=complex(*[int(i)for i in readline().split()]) ap=project(s,p2) print(ap.real,ap.imag) ------------------------------------------------------------ OCL File: --------- class Segment extends object { static operation newSegment() : Segment pre: true post: Segment->exists( _x | result = _x ); static attribute __slots__ : OclAny := Sequence{'fi', 'se'}; attribute fi : OclAny := fi; attribute se : OclAny := se; operation initialise(fi : OclAny,se : OclAny) : pre: true post: true activity: self.fi := fi ; self.se := se; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var readline : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; skip ; s := (Segment.newSegment()).initialise((argument * (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name starmap)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name complex))))))) , (argument (test (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name readline)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))))) ])) * (expr (atom (number (integer 2)))))))))) ))))))))) ))))))))) ))))))))) ; var n : int := ("" + ((readline())))->toInteger() ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, n) do ( p2 := complex((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name readline)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( )))))))) ]))))))) ; var ap : OclAny := project(s, p2) ; execute (ap.real)->display()); operation cross(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a.real * b.imag - a.imag * b.real; operation dot(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a.real * b.real + a.imag * b.imag; operation norm(base : OclAny) : OclAny pre: true post: true activity: return ((base)->abs())->pow(2); operation project(s : OclAny, p2 : OclAny) : OclAny pre: true post: true activity: base := s.fi - s.se ; var r : double := dot(p2 - s.fi, base) / norm(base) ; return s.fi + base * r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sx,sy,ex,ey=(int(n)for n in input().split(" ")) trial=int(input()) for _ in range(trial): x,y=(int(n)for n in input().split(" ")) if sx==ex : print(sx,y) elif sy==ey : print(x,sy) else : grad=(ey-sy)/(ex-sx) y_seg=sy-(grad*sx) per_grad=-1/grad per_y_seg=y-(per_grad*x) ans_x=(y_seg-per_y_seg)/(-1*(grad-per_grad)) ans_y=per_grad*ans_x+per_y_seg print(ans_x,ans_y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sx : OclAny := null; var sy : OclAny := null; var ex : OclAny := null; var ey : OclAny := null; Sequence{sx,sy,ex,ey} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " "))))))) ))))))))} ; var trial : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, trial-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " "))))))) ))))))))} ; if sx = ex then ( execute (sx)->display() ) else (if sy = ey then ( execute (x)->display() ) else ( var grad : double := (ey - sy) / (ex - sx) ; var y_seg : double := sy - (grad * sx) ; var per_grad : double := -1 / grad ; var per_y_seg : double := y - (per_grad * x) ; var ans_x : double := (y_seg - per_y_seg) / (-1 * (grad - per_grad)) ; var ans_y : double := per_grad * ans_x + per_y_seg ; execute (ans_x)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : T,D,L=map(int,input().split()) if T==0 and D==0 and L==0 : break x=[int(input())for i in range(T)] beforeflag=0 flag=0 total=0 for i in range(T): if x[i]>=L : flag=1 if beforeflag!=D+1 and beforeflag!=0 : total+=1 elif x[i]0 and flag<=D : flag+=1 total+=1 else : flag=0 beforeflag=flag print(total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var T : OclAny := null; var D : OclAny := null; var L : OclAny := null; Sequence{T,D,L} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if T = 0 & D = 0 & L = 0 then ( break ) else skip ; var x : Sequence := Integer.subrange(0, T-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var beforeflag : int := 0 ; var flag : int := 0 ; var total : int := 0 ; for i : Integer.subrange(0, T-1) do ( if (x[i+1]->compareTo(L)) >= 0 then ( flag := 1 ; if beforeflag /= D + 1 & beforeflag /= 0 then ( total := total + 1 ) else skip ) else (if (x[i+1]->compareTo(L)) < 0 & flag > 0 & (flag->compareTo(D)) <= 0 then ( flag := flag + 1 ; total := total + 1 ) else ( flag := 0 ) ) ; beforeflag := flag) ; execute (total)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def inner_product(vect1,vect2): return sum([(v1_el*v2_el)for v1_el,v2_el in zip(vect1,vect2)]) def vector_abs(vect): return sqrt(sum([element**2 for element in vect])) def direction_unit_vector(p_from,p_to): d_vector=[(xt-xf)for xt,xf in zip(p_to,p_from)] d_u_vector=[element/vector_abs(d_vector)for element in d_vector] return d_u_vector def projection(origin,line_from,line_to): direction_unit=direction_unit_vector(line_from,line_to) origin_d_vector=[(org-lf)for org,lf in zip(origin,line_from)] inject_dist=inner_product(direction_unit,origin_d_vector) on_line_vect=[inject_dist*element for element in direction_unit] return[olv_el+lf_el for olv_el,lf_el in zip(on_line_vect,line_from)] if __name__=='__main__' : xy_list=list(map(int,input().split())) p1_list=xy_list[: 2] p2_list=xy_list[2 :] Q=int(input()) for i in range(Q): p_list=list(map(int,input().split())) x_list=projection(p_list,p1_list,p2_list) print(' '.join(map(str,x_list))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var xy_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var p1_list : OclAny := xy_list.subrange(1,2) ; var p2_list : OclAny := xy_list.subrange(2+1) ; var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, Q-1) do ( var p_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x_list : OclAny := projection(p_list, p1_list, p2_list) ; execute (StringLib.sumStringsWithSeparator(((x_list)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()) ) else skip; operation inner_product(vect1 : OclAny, vect2 : OclAny) : OclAny pre: true post: true activity: return (Integer.subrange(1, vect1->size())->collect( _indx | Sequence{vect1->at(_indx), vect2->at(_indx)} )->select(_tuple | true)->collect(_tuple | let v1_el : OclAny = _tuple->at(1) in let v2_el : OclAny = _tuple->at(2) in ((v1_el * v2_el))))->sum(); operation vector_abs(vect : OclAny) : OclAny pre: true post: true activity: return sqrt((vect->select(element | true)->collect(element | ((element)->pow(2))))->sum()); operation direction_unit_vector(p_from : OclAny, p_to : OclAny) : OclAny pre: true post: true activity: var d_vector : Sequence := Integer.subrange(1, p_to->size())->collect( _indx | Sequence{p_to->at(_indx), p_from->at(_indx)} )->select(_tuple | true)->collect(_tuple | let xt : OclAny = _tuple->at(1) in let xf : OclAny = _tuple->at(2) in ((xt - xf))) ; var d_u_vector : Sequence := d_vector->select(element | true)->collect(element | (element / vector_abs(d_vector))) ; return d_u_vector; operation projection(origin : OclAny, line_from : OclAny, line_to : OclAny) : OclAny pre: true post: true activity: var direction_unit : OclAny := direction_unit_vector(line_from, line_to) ; var origin_d_vector : Sequence := Integer.subrange(1, origin->size())->collect( _indx | Sequence{origin->at(_indx), line_from->at(_indx)} )->select(_tuple | true)->collect(_tuple | let org : OclAny = _tuple->at(1) in let lf : OclAny = _tuple->at(2) in ((org - lf))) ; var inject_dist : OclAny := inner_product(direction_unit, origin_d_vector) ; var on_line_vect : Sequence := direction_unit->select(element | true)->collect(element | (inject_dist * element)) ; return Integer.subrange(1, on_line_vect->size())->collect( _indx | Sequence{on_line_vect->at(_indx), line_from->at(_indx)} )->select(_tuple | true)->collect(_tuple | let olv_el : OclAny = _tuple->at(1) in let lf_el : OclAny = _tuple->at(2) in (olv_el + lf_el)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printInitials(string : str): length=len(string) string.strip() t="" for i in range(length): ch=string[i] if ch!=' ' : t+=ch else : print(t[0].upper()+".",end="") t="" temp="" for j in range(len(t)): if j==0 : temp+=t[0].upper() else : temp+=t[j].lower() print(temp) if __name__=="__main__" : string="ishita bhuiya" printInitials(string) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var string : String := "ishita bhuiya" ; printInitials(string) ) else skip; operation printInitials(string : String) pre: true post: true activity: var length : int := (string)->size() ; string->trim() ; var t : String := "" ; for i : Integer.subrange(0, length-1) do ( var ch : OclAny := string[i+1] ; if ch /= ' ' then ( t := t + ch ) else ( execute (t->first()->toUpperCase() + ".")->display() ; t := "" )) ; var temp : String := "" ; for j : Integer.subrange(0, (t)->size()-1) do ( if j = 0 then ( temp := temp + t->first()->toUpperCase() ) else ( temp := temp + t[j+1]->toLowerCase() )) ; execute (temp)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def max_sum(arr,n,k): dp=[0]*n ; dp[0]=max(0,arr[0]); i=1 ; while(iunion(Sequence{2}->union(Sequence{-2}->union(Sequence{4}->union(Sequence{3}->union(Sequence{ 1 }))))); ; n := (arr)->size() ; k := 4; ; execute (max_sum(arr, n, k))->display(); ) else skip; operation max_sum(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; dp->first() := Set{0, arr->first()}->max(); ; var i : int := 1; ; while ((i->compareTo(k)) < 0) do ( dp[i+1] := Set{dp[i - 1+1], arr[i+1]}->max(); ; i := i + 1;) ; i := k; ; while ((i->compareTo(n)) < 0) do ( dp[i+1] := Set{dp[i - 1+1], arr[i+1] + dp[i - k+1]}->max(); ; i := i + 1;) ; return dp[n - 1+1];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def p(st): l=len(st) tc=1 ac=0 p=s[0] for i in range(1,l): if st[i]==p : tc+=1 else : ac+=tc//2 tc=1 p=st[i] else : ac+=tc//2 return ac s=input() k=int(input()) n=len(s) if n==1 : print(k//2) exit() if n==2 : if s[0]==s[1]: print(k) else : print(0) exit() ac=p(s) if k>1 : ac4=p(s+s+s+s) if ac*4==ac4 : print(ac*k) elif ac4-ac*4==3 : print(ac*k+(k-1)) elif ac4-ac*4==2 : print(ac*k+(k//2)) else : print(ac) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : String := (OclFile["System.in"]).readLine() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := (s)->size() ; if n = 1 then ( execute (k div 2)->display() ; exit() ) else skip ; if n = 2 then ( if s->first() = s[1+1] then ( execute (k)->display() ) else ( execute (0)->display() ) ; exit() ) else skip ; ac := p(s) ; if k > 1 then ( var ac4 : OclAny := p(s + s + s + s) ; if ac * 4 = ac4 then ( execute (ac * k)->display() ) else (if ac4 - ac * 4 = 3 then ( execute (ac * k + (k - 1))->display() ) else (if ac4 - ac * 4 = 2 then ( execute (ac * k + (k div 2))->display() ) else skip ) ) ) else ( execute (ac)->display() ); operation p(st : OclAny) : OclAny pre: true post: true activity: var l : int := (st)->size() ; var tc : int := 1 ; var ac : int := 0 ; var p : OclAny := s->first() ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name l)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name st)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (name p))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name tc)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ac)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name tc))) // (expr (atom (number (integer 2))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name tc)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name p)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name st)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ac)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name tc))) // (expr (atom (number (integer 2)))))))))))))))) ; return ac; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s="" k=int(input()) x=1 while True : try : if s[k-1]!="" : print(s[k-1]) break except : s+=str(x) x+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := "" ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := 1 ; while true do ( try ( if s[k - 1+1] /= "" then ( execute (s[k - 1+1])->display() ; break ) else skip) catch (_e : OclException) do ( s := s + ("" + ((x))) ; x := x + 1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- out=[] for i in range(10000): out.append(str(i)) str1="".join(out) print(str1[int(input())]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var out : Sequence := Sequence{} ; for i : Integer.subrange(0, 10000-1) do ( execute ((("" + ((i)))) : out)) ; var str1 : String := StringLib.sumStringsWithSeparator((out), "") ; execute (str1[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- out=[] for i in range(0,10001): out.append(str(i)) str1="".join(out) print(str1[int(input())]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var out : Sequence := Sequence{} ; for i : Integer.subrange(0, 10001-1) do ( execute ((("" + ((i)))) : out)) ; var str1 : String := StringLib.sumStringsWithSeparator((out), "") ; execute (str1[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s="" p=int(input()) for i in range(1,3000): s+=str(i) print(s[p-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := "" ; var p : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(1, 3000-1) do ( s := s + ("" + ((i)))) ; execute (s[p - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin,stdout from math import* import math,random,operator from itertools import product,permutations,combinations from collections import deque,defaultdict,Counter input=sys.stdin.readline s='' l=[i for i in range(1,100000)] for i in l : s+=str(i) def hi(): n=int(input()) print(s[n-1]) if __name__=="__main__" : hi() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var s : String := '' ; var l : Sequence := Integer.subrange(1, 100000-1)->select(i | true)->collect(i | (i)) ; for i : l do ( s := s + ("" + ((i)))) ; skip ; if __name__ = "__main__" then ( hi() ) else skip; operation hi() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (s[n - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countX(a,b): if(b>a): return 0 elif(a==b): return-1 else : x=a-b ans=0 i=1 while i*i<=x : if(x % i==0): d1=i d2=b-1 if(i*i!=x): d2=x//i if(d1>b): ans+=1 if(d2>b): ans+=1 i+=1 return ans if __name__=="__main__" : a=21 b=5 print(countX(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := 21 ; b := 5 ; execute (countX(a, b))->display() ) else skip; operation countX(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if ((b->compareTo(a)) > 0) then ( return 0 ) else (if (a = b) then ( return -1 ) else ( var x : double := a - b ; var ans : int := 0 ; var i : int := 1 ; while (i * i->compareTo(x)) <= 0 do ( if (x mod i = 0) then ( var d1 : int := i ; var d2 : double := b - 1 ; if (i * i /= x) then ( d2 := x div i ) else skip ; if ((d1->compareTo(b)) > 0) then ( ans := ans + 1 ) else skip ; if ((d2->compareTo(b)) > 0) then ( ans := ans + 1 ) else skip ) else skip ; i := i + 1) ; return ans ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools import operator def f(): t,d,l=map(int,input().split()) if t==d==l==0 : return True hist=[0]*(10**5*2+1) for i in range(t): x=int(input()) if x>=l : hist[i+1]+=1 hist[i+d+1]-=1 print(sum(map(bool,itertools.accumulate(hist[: t],operator.add)))) while not f(): pass ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; while not(f()) do ( skip); operation f() : OclAny pre: true post: true activity: var t : OclAny := null; var d : OclAny := null; var l : OclAny := null; Sequence{t,d,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if t = d & (d == l) & (l == 0) then ( return true ) else skip ; var hist : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((10)->pow(5) * 2 + 1)) ; for i : Integer.subrange(0, t-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (x->compareTo(l)) >= 0 then ( hist[i + 1+1] := hist[i + 1+1] + 1 ; hist[i + d + 1+1] := hist[i + d + 1+1] - 1 ) else skip) ; execute (((itertools.accumulate(hist.subrange(1,t), operator.add))->collect( _x | (OclType["boolean"])->apply(_x) ))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sol(): n,m=map(int,input().split()) t,w={},{} p,q=set(),set() for i in range(m): l,r,d=[int(i)for i in input().split()] if l in w : w[l].add((r,d)) else : w[l]={(r,d)} p.add(l) q.add(r) s=p-q chk=set() if len(s)==0 : print(["No","Yes"][m==0]) exit() for i in s : chk.add((i,0)) while len(chk): x=chk.pop() if x[0]in w : for j in w[x[0]]: if(i,j[0])in t and t[(i,j[0])]!=t[(i,x[0])]+j[1]: print("No") exit() elif(i,j[0])not in t : t[(i,j[0])]=x[1]+j[1] chk.add((j[0],x[1]+j[1])) print("Yes") if __name__=="__main__" : sol() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( sol() ) else skip; operation sol() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : OclAny := null; var w : OclAny := null; Sequence{t,w} := Sequence{Set{},Set{}} ; var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := Sequence{Set{}->union(()),Set{}->union(())} ; for i : Integer.subrange(0, m-1) do ( var l : OclAny := null; var r : OclAny := null; var d : OclAny := null; Sequence{l,r,d} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if (w)->includes(l) then ( (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name l)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name r)))))) , (test (logical_test (comparison (expr (atom (name d))))))) )))))))) )))) ) else ( w[l+1] := Set{ Sequence{r, d} } ) ; execute ((l) : p) ; execute ((r) : q)) ; var s : double := p - q ; var chk : Set := Set{}->union(()) ; if (s)->size() = 0 then ( execute (Sequence{"No"}->union(Sequence{ "Yes" })->select(m = 0))->display() ; exit() ) else skip ; for i : s do ( execute ((Sequence{i, 0}) : chk) ; while (chk)->size() do ( var x : OclAny := chk->last() ; chk := chk->front() ; if (w)->includes(x->first()) then ( for j : w[x->first()+1] do ( if (t)->includes(Sequence{i, j->first()}) & t[Sequence{i, j->first()}+1] /= t[Sequence{i, x->first()}+1] + j[1+1] then ( execute ("No")->display() ; exit() ) else (if (t)->excludes(Sequence{i, j->first()}) then ( t[Sequence{i, j->first()}+1] := x[1+1] + j[1+1] ; execute ((Sequence{j->first(), x[1+1] + j[1+1]}) : chk) ) else skip)) ) else skip)) ; execute ("Yes")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class WeightedUF : def __init__(self,n): self.par=[i for i in range(n)] self.rank=[0]*n self.weight=[0]*n def find(self,x): if self.par[x]==x : return x else : y=self.find(self.par[x]) self.weight[x]+=self.weight[self.par[x]] self.par[x]=y return y def unite(self,x,y,w): rx=self.find(x) ry=self.find(y) if self.rank[rx]exists( _x | result = _x ); attribute par : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)); attribute rank : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); attribute weight : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); operation initialise(n : OclAny) : WeightedUF pre: true post: true activity: self.par := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i)) ; self.rank := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; self.weight := MatrixLib.elementwiseMult(Sequence{ 0 }, n); return self; operation find(x : OclAny) : OclAny pre: true post: true activity: if self.par[x+1] = x then ( return x ) else ( var y : int := self->indexOf(self.par[x+1]) - 1 ; self.weight[x+1] := self.weight[x+1] + self.weight[self.par[x+1]+1] ; self.par[x+1] := y ; return y ); operation unite(x : OclAny,y : OclAny,w : OclAny) pre: true post: true activity: var rx : int := self->indexOf(x) - 1 ; var ry : int := self->indexOf(y) - 1 ; if (self.rank[rx+1]->compareTo(self.rank[ry+1])) < 0 then ( self.par[rx+1] := ry ; self.weight[rx+1] := w - self.weight[x+1] + self.weight[y+1] ) else ( self.par[ry+1] := rx ; self.weight[ry+1] := -w - self.weight[y+1] + self.weight[x+1] ; if self.rank[rx+1] = self.rank[ry+1] then ( self.rank[rx+1] := self.rank[rx+1] + 1 ) else skip ); operation same(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: return self->indexOf(x) - 1 = self->indexOf(y) - 1; operation diff(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: return self.weight[x+1] - self.weight[y+1]; } class FromPython { operation initialise() pre: true post: true activity: skip ; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var wuf : WeightedUF := (WeightedUF.newWeightedUF()).initialise(n) ; for i : Integer.subrange(0, m-1) do ( var l : OclAny := null; var r : OclAny := null; var d : OclAny := null; Sequence{l,r,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; l := l - 1 ; r := r - 1 ; if wuf.same(l, r) then ( if wuf.diff(l, r) /= d then ( execute ("No")->display() ; exit() ) else skip ) else ( wuf.unite(l, r, d) )) ; execute ("Yes")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import collections input=sys.stdin.readline def main(): N,M=[int(x)for x in input().split()] LRD=[[int(x)for x in input().split()]for _ in range(M)] A=[[]for j in range(N+1)] if M==0 : print("Yes") return slist=set() for l,r,d in LRD : A[l].append([r,d]) A[r].append([l,-d]) slist.add(l) slist.add(r) dmemo=[None]*(N+1) f=False for i in list(slist): if dmemo[i]is not None : continue s=collections.deque() s.append(i) dmemo[i]=0 while s : c=s.pop() for r,d in A[c]: if dmemo[r]is not None : if dmemo[r]-dmemo[c]!=d : f=True break else : dmemo[r]=dmemo[c]+d s.append(r) if f : break if f : break if f : print("No") else : print("Yes") if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var LRD : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))) ; var A : Sequence := Integer.subrange(0, N + 1-1)->select(j | true)->collect(j | (Sequence{})) ; if M = 0 then ( execute ("Yes")->display() ; return ) else skip ; var slist : Set := Set{}->union(()) ; for _tuple : LRD do (var _indx : int := 1; var l : OclAny := _tuple->at(_indx); _indx := _indx + 1; var r : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name l)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name r)))))) , (test (logical_test (comparison (expr (atom (name d))))))) ]))))))) )))) ; (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name l)))))) , (test (logical_test (comparison (expr - (expr (atom (name d)))))))) ]))))))) )))) ; execute ((l) : slist) ; execute ((r) : slist)) ; var dmemo : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (N + 1)) ; var f : boolean := false ; for i : (slist) do ( if not(dmemo[i+1] <>= null) then ( continue ) else skip ; var s : Sequence := () ; execute ((i) : s) ; dmemo[i+1] := 0 ; while s do ( var c : OclAny := s->last() ; s := s->front() ; for _tuple : A[c+1] do (var _indx : int := 1; var r : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); if not(dmemo[r+1] <>= null) then ( if dmemo[r+1] - dmemo[c+1] /= d then ( f := true ; break ) else skip ) else ( dmemo[r+1] := dmemo[c+1] + d ; execute ((r) : s) )) ; if f then ( break ) else skip) ; if f then ( break ) else skip) ; if f then ( execute ("No")->display() ) else ( execute ("Yes")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dfs(graph,start,visited): if visited[start]!=-99999 : return True stack=[start] visited[start]=0 while stack : label=stack.pop() for nextnode,distance in graph[label]: if visited[nextnode]==-99999 : stack.append(nextnode) visited[nextnode]=visited[label]+distance elif visited[nextnode]!=visited[label]+distance : return False return True N,M=(int(i)for i in input().split()) graph=[[]for i in range(N+1)] for i in range(M): L,R,D=(int(i)for i in input().split()) graph[L].append((R,D)) graph[R].append((L,-1*D)) visited=[-99999 for i in range(N+1)] flag=True for i in range(1,N+1): ans=dfs(graph,i,visited) if not ans : flag=False break if flag : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; graph := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, M-1) do ( var L : OclAny := null; var R : OclAny := null; var D : OclAny := null; Sequence{L,R,D} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name L)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name R)))))) , (test (logical_test (comparison (expr (atom (name D))))))) )))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name R)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name L)))))) , (test (logical_test (comparison (expr (expr (atom - (number (integer 1)))) * (expr (atom (name D)))))))) )))))))) ))))) ; visited := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (-99999)) ; var flag : boolean := true ; for i : Integer.subrange(1, N + 1-1) do ( var ans : OclAny := dfs(graph, i, visited) ; if not(ans) then ( flag := false ; break ) else skip) ; if flag then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); operation dfs(graph : OclAny, start : OclAny, visited : OclAny) : OclAny pre: true post: true activity: if visited[start+1] /= -99999 then ( return true ) else skip ; var stack : Sequence := Sequence{ start } ; visited[start+1] := 0 ; while stack do ( var label : OclAny := stack->last() ; stack := stack->front() ; for _tuple : graph[label+1] do (var _indx : int := 1; var nextnode : OclAny := _tuple->at(_indx); _indx := _indx + 1; var distance : OclAny := _tuple->at(_indx); if visited[nextnode+1] = -99999 then ( execute ((nextnode) : stack) ; visited[nextnode+1] := visited[label+1] + distance ) else (if visited[nextnode+1] /= visited[label+1] + distance then ( return false ) else skip))) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=list(input()) K=int(input()) if K % 2==0 : A=S.copy() S=S+S ans=0 x=0 for i in range(len(S)-1): if S[i]==S[i+1]: S[i+1]=":" ans+=1 if S[0]==S[-1]and K>3 : x=(1)*(K//2-1) print((K//2)*ans+x) else : ans=0 A=S.copy() S=S+S x=0 for i in range(len(S)-1): if S[i]==S[i+1]: S[i+1]=":" ans+=1 if S[i]!=":" and K!=1 : A=list(S[-1])+A for i in range(len(A)-1): if A[i]==A[i+1]: A[i+1]=":" x+=1 print((K//2)*ans+x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if K mod 2 = 0 then ( var A : OclAny := S->copy() ; S := S->union(S) ; var ans : int := 0 ; var x : int := 0 ; for i : Integer.subrange(0, (S)->size() - 1-1) do ( if S[i+1] = S[i + 1+1] then ( S[i + 1+1] := ":" ; ans := ans + 1 ) else skip) ; if S->first() = S->last() & K > 3 then ( x := (1) * (K div 2 - 1) ) else skip ; execute ((K div 2) * ans + x)->display() ) else ( ans := 0 ; A := S->copy() ; S := S->union(S) ; x := 0 ; for i : Integer.subrange(0, (S)->size() - 1-1) do ( if S[i+1] = S[i + 1+1] then ( S[i + 1+1] := ":" ; ans := ans + 1 ) else skip) ; if S[i+1] /= ":" & K /= 1 then ( A := (S->last())->union(A) ) else skip ; for i : Integer.subrange(0, (A)->size() - 1-1) do ( if A[i+1] = A[i + 1+1] then ( A[i + 1+1] := ":" ; x := x + 1 ) else skip) ; execute ((K div 2) * ans + x)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- queue=[] N,M=map(int,input().split()) NE=9223372036854775807 mp=[NE]*(N+1) lst=[[]for _ in range(N+1)] for _ in range(M): L,R,D=map(int,input().split()) lst[L].append((L,R,D)) lst[R].append((L,R,D)) def check(L,R,D): if mp[L]==NE : mp[L]=mp[R]-D elif mp[R]==NE : mp[R]=mp[L]+D else : if mp[L]+D!=mp[R]: print("No") exit() def check_list(ls,checking): while len(ls): L,R,D=ls.pop() check(L,R,D) nx=R if L==checking else L if len(lst[nx]): queue.append(nx) for i in range(1,N+1): if mp[i]==NE : mp[i]=0 check_list(lst[i],i) while(len(queue)>0): num=queue.pop() check_list(lst[num],num) print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var queue : Sequence := Sequence{} ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var NE : int := 9223372036854775807 ; var mp : Sequence := MatrixLib.elementwiseMult(Sequence{ NE }, (N + 1)) ; var lst : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, M-1) do ( var L : OclAny := null; var R : OclAny := null; var D : OclAny := null; Sequence{L,R,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name L)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name L)))))) , (test (logical_test (comparison (expr (atom (name R)))))) , (test (logical_test (comparison (expr (atom (name D))))))) )))))))) )))) ; (expr (atom (name lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name R)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name L)))))) , (test (logical_test (comparison (expr (atom (name R)))))) , (test (logical_test (comparison (expr (atom (name D))))))) )))))))) ))))) ; skip ; skip ; for i : Integer.subrange(1, N + 1-1) do ( if mp[i+1] = NE then ( mp[i+1] := 0 ) else skip ; check_list(lst[i+1], i) ; while ((queue)->size() > 0) do ( var num : OclAny := queue->last() ; queue := queue->front() ; check_list(lst[num+1], num))) ; execute ("Yes")->display(); operation check(L : OclAny, R : OclAny, D : OclAny) pre: true post: true activity: if mp[L+1] = NE then ( mp[L+1] := mp[R+1] - D ) else (if mp[R+1] = NE then ( mp[R+1] := mp[L+1] + D ) else ( if mp[L+1] + D /= mp[R+1] then ( execute ("No")->display() ; exit() ) else skip ) ) ; operation check_list(ls : OclAny, checking : OclAny) pre: true post: true activity: while (ls)->size() do ( Sequence{L,R,D} := ls->last() ; ls := ls->front() ; check(L, R, D) ; var nx : OclAny := if L = checking then R else L endif ; if (lst[nx+1])->size() then ( execute ((nx) : queue) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input().split() len_a=int(a[0]) len_b=int(a[1]) a=input().split() k=int(a[0]) m=int(a[1]) array_a=input().split() array_b=input().split() a=0 while afirst())))->toInteger() ; var len_b : int := ("" + ((a[1+1])))->toInteger() ; a := input().split() ; var k : int := ("" + ((a->first())))->toInteger() ; var m : int := ("" + ((a[1+1])))->toInteger() ; var array_a : OclAny := input().split() ; var array_b : OclAny := input().split() ; a := 0 ; while (a->compareTo(len_a)) < 0 do ( array_a[a+1] := ("" + ((array_a[a+1])))->toInteger() ; a := a + 1) ; a := 0 ; while (a->compareTo(len_b)) < 0 do ( array_b[a+1] := ("" + ((array_b[a+1])))->toInteger() ; a := a + 1) ; if (array_a[k - 1+1]->compareTo(array_b[len_b - m+1])) < 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n1,n2=list(map(int,input().split())) k,m=list(map(int,input().split())) a=list(map(int,input().split())) b=list(map(int,input().split())) if a[k-1]collect( _x | (OclType["int"])->apply(_x) )) ; var k : OclAny := null; var m : OclAny := null; Sequence{k,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (a[k - 1+1]->compareTo(b[n2 - m+1])) < 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- z=lambda : tuple(map(int,input().split())); s,s1=z(); a,b=z(); print("YES" if z()[a-1]collect( _x | (OclType["int"])->apply(_x) ))); var s : OclAny := null; var s1 : OclAny := null; Sequence{s,s1} := z->apply(); var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := z->apply(); execute (if (z->apply()[a - 1+1]->compareTo(z->apply()->reverse()->at(-(-b)))) < 0 then "YES" else "NO" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=input().split() k,m=input().split() k=int(k) m=int(m) first=input().split() second=input().split() if int(first[k-1])toInteger() ; var m : int := ("" + ((m)))->toInteger() ; var first : OclAny := input().split() ; var second : OclAny := input().split() ; if (("" + ((first[k - 1+1])))->toInteger()->compareTo(("" + ((second->reverse()->at(-(-m)))))->toInteger())) < 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minimumSwaps(arr): count=0 ; i=0 ; while(iunion(Sequence{3}->union(Sequence{4}->union(Sequence{1}->union(Sequence{ 5 })))); ; execute (minimumSwaps(arr))->display(); ) else skip; operation minimumSwaps(arr : OclAny) pre: true post: true activity: var count : int := 0; ; var i : int := 0; ; while ((i->compareTo((arr)->size())) < 0) do ( if (arr[i+1] /= i + 1) then ( while (arr[i+1] /= i + 1) do ( var temp : int := 0; ; temp := arr[arr[i+1] - 1+1]; ; arr[arr[i+1] - 1+1] := arr[i+1]; ; arr[i+1] := temp; ; count := count + 1;) ) else skip ; i := i + 1;) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- na,nb=map(int,input().split()) k,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) if b[nb-m]>a[k-1]: print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var na : OclAny := null; var nb : OclAny := null; Sequence{na,nb} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : OclAny := null; var m : OclAny := null; Sequence{k,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (b[nb - m+1]->compareTo(a[k - 1+1])) > 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=[int(x)for x in input().split()] if a==0 and b==0 : if c==0 : print(-1) else : print(0) elif a==0 : print(1) print("{0:.5f}".format(-c/b)) else : root1=(-b+(b**2-4*a*c)**0.5)/(2*a) root2=(-b-(b**2-4*a*c)**0.5)/(2*a) if root1==root2 : print(1) print("{0:.5f}".format(root1)) elif type(root1)==complex and type(root2)==complex : print(0) elif type(root1)==complex : print(1) print("{0:.5f}".format(root2)) elif type(root2)==complex : print(1) print("{0:.5f}".format(root1)) elif root1>root2 : print(2) print("{0:.5f}".format(root2)) print("{0:.5f}".format(root1)) else : print(2) print("{0:.5f}".format(root1)) print("{0:.5f}".format(root2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if a = 0 & b = 0 then ( if c = 0 then ( execute (-1)->display() ) else ( execute (0)->display() ) ) else (if a = 0 then ( execute (1)->display() ; execute (StringLib.interpolateStrings("{0:.5f}", Sequence{-c / b}))->display() ) else ( var root1 : double := (-b + (((b)->pow(2) - 4 * a * c))->pow(0.5)) / (2 * a) ; var root2 : double := (-b - (((b)->pow(2) - 4 * a * c))->pow(0.5)) / (2 * a) ; if root1 = root2 then ( execute (1)->display() ; execute (StringLib.interpolateStrings("{0:.5f}", Sequence{root1}))->display() ) else (if (root1)->oclType() = complex & (root2)->oclType() = complex then ( execute (0)->display() ) else (if (root1)->oclType() = complex then ( execute (1)->display() ; execute (StringLib.interpolateStrings("{0:.5f}", Sequence{root2}))->display() ) else (if (root2)->oclType() = complex then ( execute (1)->display() ; execute (StringLib.interpolateStrings("{0:.5f}", Sequence{root1}))->display() ) else (if (root1->compareTo(root2)) > 0 then ( execute (2)->display() ; execute (StringLib.interpolateStrings("{0:.5f}", Sequence{root2}))->display() ; execute (StringLib.interpolateStrings("{0:.5f}", Sequence{root1}))->display() ) else ( execute (2)->display() ; execute (StringLib.interpolateStrings("{0:.5f}", Sequence{root1}))->display() ; execute (StringLib.interpolateStrings("{0:.5f}", Sequence{root2}))->display() ) ) ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=list(map(int,input().split())) a=x[0] b=x[1] c=x[2] import math if a==0 : if b==0 : if c==0 : print(-1) else : print(0) else : print(1) if c!=0 : r=-c/b else : r=abs(c/b) print("{:.10f}".format(r)) else : d=(b*b)-(4*a*c) if d<0 : print(0) elif d==0 : print(1) r=(-b)/(2*a) print("{:.10f}".format(r)) else : r1=math.sqrt(d) r11=(-b+r1)/(2*a) r12=(-b-r1)/(2*a) r=[] r.append(min(r11,r12)) r.append(max(r11,r12)) print(2) for i in r : print("{:.10f}".format(i)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := x->first() ; var b : OclAny := x[1+1] ; var c : OclAny := x[2+1] ; skip ; if a = 0 then ( if b = 0 then ( if c = 0 then ( execute (-1)->display() ) else ( execute (0)->display() ) ) else ( execute (1)->display() ; if c /= 0 then ( var r : double := -c / b ) else ( r := (c / b)->abs() ) ; execute (StringLib.interpolateStrings("{:.10f}", Sequence{r}))->display() ) ) else ( var d : double := (b * b) - (4 * a * c) ; if d < 0 then ( execute (0)->display() ) else (if d = 0 then ( execute (1)->display() ; r := (-b) / (2 * a) ; execute (StringLib.interpolateStrings("{:.10f}", Sequence{r}))->display() ) else ( var r1 : double := (d)->sqrt() ; var r11 : double := (-b + r1) / (2 * a) ; var r12 : double := (-b - r1) / (2 * a) ; r := Sequence{} ; execute ((Set{r11, r12}->min()) : r) ; execute ((Set{r11, r12}->max()) : r) ; execute (2)->display() ; for i : r do ( execute (StringLib.interpolateStrings("{:.10f}", Sequence{i}))->display()) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) if a==0 : if b==0 : if c==0 : print(-1) else : print(0) else : print(1) print(-c/b) else : D=b**2-4*a*c if D==0 : print(1) print(-b/(2*a)) elif D<0 : print(0) else : print(2) ans=sorted([(-b-D**0.5)/(2*a),(-b+D**0.5)/(2*a)]) print(*ans,sep="\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 0 then ( if b = 0 then ( if c = 0 then ( execute (-1)->display() ) else ( execute (0)->display() ) ) else ( execute (1)->display() ; execute (-c / b)->display() ) ) else ( var D : double := (b)->pow(2) - 4 * a * c ; if D = 0 then ( execute (1)->display() ; execute (-b / (2 * a))->display() ) else (if D < 0 then ( execute (0)->display() ) else ( execute (2)->display() ; var ans : Sequence := Sequence{(-b - (D)->pow(0.5)) / (2 * a)}->union(Sequence{ (-b + (D)->pow(0.5)) / (2 * a) })->sort() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=[int(a)for a in input().split()] if a==0 : if b==0 : if c==0 : print(-1) else : print(0) else : print(1) print(-c/b) else : D=b**2-4*a*c if D==0 : print(1) print(-b/(2*a)) elif D<0 : print(0) else : print(2) ans=sorted([(-b-D**0.5)/(2*a),(-b+D**0.5)/(2*a)]) print(*ans,sep="\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; if a = 0 then ( if b = 0 then ( if c = 0 then ( execute (-1)->display() ) else ( execute (0)->display() ) ) else ( execute (1)->display() ; execute (-c / b)->display() ) ) else ( var D : double := (b)->pow(2) - 4 * a * c ; if D = 0 then ( execute (1)->display() ; execute (-b / (2 * a))->display() ) else (if D < 0 then ( execute (0)->display() ) else ( execute (2)->display() ; var ans : Sequence := Sequence{(-b - (D)->pow(0.5)) / (2 * a)}->union(Sequence{ (-b + (D)->pow(0.5)) / (2 * a) })->sort() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def f(s): i=0 n=0 while icompareTo((s)->size() - 1)) < 0 do ( if s[i+1] = s[i + 1+1] then ( n := n + 1 ; i := i + 2 ) else ( i := i + 1 )) ; return n; operation main() pre: true post: true activity: var S : OclAny := input()->trim() ; var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a1 : String := f(S) ; var a2 : String := f(S * 2) ; var a3 : String := f(S * 3) ; if K = 1 then ( execute (a1)->display() ; return ) else skip ; if K = 2 then ( execute (a2)->display() ; return ) else skip ; var r1 : double := a2 - a1 ; var r2 : double := a3 - a2 ; var ans : String := a1 + r1 * (K div 2) + r2 * ((K - 1) div 2) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import time import sys import os from math import gcd,floor,sqrt,log start_time=time.time() def iin(): return int(input()) def sin(): return input().strip() def listin(): return list(map(int,input().strip().split())) def liststr(): return list(map(str,input().strip().split())) def ceill(x): return int(x)if(x==int(x))else int(x)+1 def ceilldiv(x,d): x//d if(x % d==0)else x//d+1 def LCM(a,b): return(a*b)//gcd(a,b) def solve(): a,b,c=listin() if a==0 : if b==0 : if c==0 : print(-1) return print(0) return print(1) print("{0:.10f}".format((-1*c)/b)) return d=b**2-(4*a*c) if d<0 : print(0) return x=set() x.add(((-1*b)-sqrt(d))/(2*a)) x.add(((-1*b)+sqrt(d))/(2*a)) x=list(x) x.sort() print(len(x)) for i in x : print("{0:.10f}".format(i)) t=1 for hula in range(t): solve() sys.stderr.write(str(time.time()-start_time)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var start_time : OclAny := time.time() ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var t : int := 1 ; for hula : Integer.subrange(0, t-1) do ( solve()) ; (expr (atom (name sys)) (trailer . (name stderr)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name time)) (trailer . (name time) (arguments ( )))) - (expr (atom (name start_time))))))))) ))))))))) )))); operation iin() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation sin() : OclAny pre: true post: true activity: return input()->trim(); operation listin() : OclAny pre: true post: true activity: return ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation liststr() : OclAny pre: true post: true activity: return ((input()->trim().split())->collect( _x | (OclType["String"])->apply(_x) )); operation ceill(x : OclAny) : OclAny pre: true post: true activity: return if (x = ("" + ((x)))->toInteger()) then ("" + ((x)))->toInteger() else ("" + ((x)))->toInteger() + 1 endif; operation ceilldiv(x : OclAny, d : OclAny) pre: true post: true activity: (test (logical_test (comparison (expr (expr (atom (name x))) // (expr (atom (name d)))))) if (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (expr (atom (name x))) % (expr (atom (name d))))) == (comparison (expr (atom (number (integer 0))))))))) ))))) else (test (logical_test (comparison (expr (expr (expr (atom (name x))) // (expr (atom (name d)))) + (expr (atom (number (integer 1))))))))); operation LCM(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a * b) div gcd(a, b); operation solve() pre: true post: true activity: var c : OclAny := null; Sequence{a,b,c} := listin() ; if a = 0 then ( if b = 0 then ( if c = 0 then ( execute (-1)->display() ; return ) else skip ; execute (0)->display() ; return ) else skip ; execute (1)->display() ; execute (StringLib.interpolateStrings("{0:.10f}", Sequence{(-1 * c) / b}))->display() ; return ) else skip ; d := (b)->pow(2) - (4 * a * c) ; if d < 0 then ( execute (0)->display() ; return ) else skip ; x := Set{}->union(()) ; execute ((((-1 * b) - sqrt(d)) / (2 * a)) : x) ; execute ((((-1 * b) + sqrt(d)) / (2 * a)) : x) ; x := (x) ; x := x->sort() ; execute ((x)->size())->display() ; for i : x do ( execute (StringLib.interpolateStrings("{0:.10f}", Sequence{i}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def average(a,n): sum=0 for i in range(n): sum+=a[i] return sum/n ; arr=[10,2,3,4,5,6,7,8,9] n=len(arr) print(average(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var arr : Sequence := Sequence{10}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 9 })))))))) ; n := (arr)->size() ; execute (average(arr, n))->display(); operation average(a : OclAny, n : OclAny) pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + a[i+1]) ; return sum / n;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binarySearch(arr,low,high,x): while(low<=high): mid=int((low+high)/2) if(arr[mid]==x): return mid elif(arr[mid]>x): high=mid-1 else : low=mid+1 def isKSortedArray(arr,n,k): aux=[0 for i in range(n)] for i in range(0,n,1): aux[i]=arr[i] aux.sort(reverse=False) for i in range(0,n,1): j=binarySearch(aux,0,n-1,arr[i]) if(abs(i-j)>k): return "No" return "Yes" if __name__=='__main__' : arr=[3,2,1,5,6,4] n=len(arr) k=2 print("Is it a k sorted array?:",isKSortedArray(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{3}->union(Sequence{2}->union(Sequence{1}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 4 }))))) ; n := (arr)->size() ; k := 2 ; execute ("Is it a k sorted array?:")->display() ) else skip; operation binarySearch(arr : OclAny, low : OclAny, high : OclAny, x : OclAny) : OclAny pre: true post: true activity: while ((low->compareTo(high)) <= 0) do ( var mid : int := ("" + (((low + high) / 2)))->toInteger() ; if (arr[mid+1] = x) then ( return mid ) else (if ((arr[mid+1]->compareTo(x)) > 0) then ( high := mid - 1 ) else ( low := mid + 1 ) ) ); operation isKSortedArray(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var aux : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( aux[i+1] := arr[i+1]) ; aux := aux->sort() ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( var j : OclAny := binarySearch(aux, 0, n - 1, arr[i+1]) ; if (((i - j)->abs()->compareTo(k)) > 0) then ( return "No" ) else skip) ; return "Yes"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nCr(n,k): C=[[0 for i in range(k+1)]for j in range(n+1)] for i in range(n+1): for j in range(min(i,k)+1): if(j==0 or j==i): C[i][j]=1 else : C[i][j]=C[i-1][j-1]+C[i-1][j] return C[n][k] def resultOfAllSubsets(arr,N): result=0.0 sum=0 for i in range(N): sum+=arr[i] for n in range(1,N+1): result+=(sum*(nCr(N-1,n-1)))/n return result arr=[2,3,5,7] N=len(arr) print(resultOfAllSubsets(arr,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 7 }))) ; N := (arr)->size() ; execute (resultOfAllSubsets(arr, N))->display(); operation nCr(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var C : Sequence := Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, k + 1-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, n + 1-1) do ( for j : Integer.subrange(0, Set{i, k}->min() + 1-1) do ( if (j = 0 or j = i) then ( C[i+1][j+1] := 1 ) else ( C[i+1][j+1] := C[i - 1+1][j - 1+1] + C[i - 1+1][j+1] ))) ; return C[n+1][k+1]; operation resultOfAllSubsets(arr : OclAny, N : OclAny) : OclAny pre: true post: true activity: var result : double := 0.0 ; var sum : int := 0 ; for i : Integer.subrange(0, N-1) do ( sum := sum + arr[i+1]) ; for n : Integer.subrange(1, N + 1-1) do ( result := result + (sum * (nCr(N - 1, n - 1))) / n) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib,heapq def compute(): TARGET=500500 MODULUS=500500507 isprime=eulerlib.list_primality(7376507) queue=[] nextprime=2 heapq.heappush(queue,nextprime) ans=1 for _ in range(TARGET): item=heapq.heappop(queue) ans*=item ans %=MODULUS heapq.heappush(queue,item**2) if item==nextprime : nextprime+=1 while not isprime[nextprime]: nextprime+=1 heapq.heappush(queue,nextprime) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var TARGET : int := 500500 ; var MODULUS : int := 500500507 ; var isprime : OclAny := eulerlib.list_primality(7376507) ; var queue : Sequence := Sequence{} ; var nextprime : int := 2 ; heapq.heappush(queue, nextprime) ; var ans : int := 1 ; for _anon : Integer.subrange(0, TARGET-1) do ( var item : OclAny := heapq.heappop(queue) ; ans := ans * item ; ans := ans mod MODULUS ; heapq.heappush(queue, (item)->pow(2)) ; if item = nextprime then ( nextprime := nextprime + 1 ; while not(isprime[nextprime+1]) do ( nextprime := nextprime + 1) ; heapq.heappush(queue, nextprime) ) else skip) ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def productPrimeFactors(n): product=1 if(n % 2==0): product*=2 while(n % 2==0): n=n/2 for i in range(3,int(math.sqrt(n)),2): if(n % i==0): product=product*i while(n % i==0): n=n/i if(n>2): product=product*n return product n=44 print(int(productPrimeFactors(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 44 ; execute (("" + ((productPrimeFactors(n))))->toInteger())->display(); operation productPrimeFactors(n : OclAny) : OclAny pre: true post: true activity: var product : int := 1 ; if (n mod 2 = 0) then ( product := product * 2 ; while (n mod 2 = 0) do ( n := n / 2) ) else skip ; for i : Integer.subrange(3, ("" + (((n)->sqrt())))->toInteger()-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if (n mod i = 0) then ( product := product * i ; while (n mod i = 0) do ( n := n / i) ) else skip) ; if (n > 2) then ( product := product * n ) else skip ; return product; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() count=0 for i in range(len(s)-1): if s[i]==s[i+1]: count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var count : int := 0 ; for i : Integer.subrange(0, (s)->size() - 1-1) do ( if s[i+1] = s[i + 1+1] then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=str(input()) count=0 for i in range(0,len(s)-1): if s[i]==s[i+1]: count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; var count : int := 0 ; for i : Integer.subrange(0, (s)->size() - 1-1) do ( if s[i+1] = s[i + 1+1] then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=input() out=0 for i in range(n-1): if arr[i]==arr[i+1]: out+=1 print(out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : String := (OclFile["System.in"]).readLine() ; var out : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if arr[i+1] = arr[i + 1+1] then ( out := out + 1 ) else skip) ; execute (out)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=input() out=0 for i in range(n-1): if arr[i]==arr[i+1]: out+=1 print(out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : String := (OclFile["System.in"]).readLine() ; var out : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if arr[i+1] = arr[i + 1+1] then ( out := out + 1 ) else skip) ; execute (out)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) rocks=str(input()) c=0 for i in range(len(rocks)-1): if rocks[i]==rocks[i+1]: c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var rocks : String := ("" + (((OclFile["System.in"]).readLine()))) ; var c : int := 0 ; for i : Integer.subrange(0, (rocks)->size() - 1-1) do ( if rocks[i+1] = rocks[i + 1+1] then ( c := c + 1 ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): MOD=int(1e9+7) a=input() b=input() n=int(input()) ca,cb=0,0 for i in range(len(a)): s=a[i :]+a[: i] if s==b : ca+=1 else : cb+=1 if ca==0 : print(0) return da=[0]*(n+1) db=da[:] da[0]=1 if a==b else 0 db[0]=1-da[0] for i in range(1,n+1): da[i]=da[i-1]*(ca-1)+db[i-1]*ca db[i]=da[i-1]*cb+db[i-1]*(cb-1) da[i]%=MOD db[i]%=MOD print(da[n]) return if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var MOD : int := ("" + ((("1e9")->toReal() + 7)))->toInteger() ; var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ca : OclAny := null; var cb : OclAny := null; Sequence{ca,cb} := Sequence{0,0} ; for i : Integer.subrange(0, (a)->size()-1) do ( var s : OclAny := a.subrange(i+1) + a.subrange(1,i) ; if s = b then ( ca := ca + 1 ) else ( cb := cb + 1 )) ; if ca = 0 then ( execute (0)->display() ; return ) else skip ; var da : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var db : Sequence := da ; da->first() := if a = b then 1 else 0 endif ; db->first() := 1 - da->first() ; for i : Integer.subrange(1, n + 1-1) do ( da[i+1] := da[i - 1+1] * (ca - 1) + db[i - 1+1] * ca ; db[i+1] := da[i - 1+1] * cb + db[i - 1+1] * (cb - 1) ; da[i+1] := da[i+1] mod MOD ; db[i+1] := db[i+1] mod MOD) ; execute (da[n+1])->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import numpy as np from itertools import groupby int1=lambda x : int(x)-1 read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines sys.setrecursionlimit(500000) S=list(readline().decode().rstrip()) K=int(readline()) g=[len(list(g))for _,g in groupby(S)] if len(g)==1 : print(len(S)*K//2) else : acc=sum(l//2 for l in g)*K if S[0]==S[-1]and g[0]% 2==1 and g[-1]% 2==1 : acc+=K-1 print(acc) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; sys.setrecursionlimit(500000) ; var S : Sequence := (readline().decode().rstrip()) ; var K : int := ("" + ((readline())))->toInteger() ; var g : Sequence := groupby(S)->select(_tuple | true)->collect(_tuple | let _anon : OclAny = _tuple->at(1) in let g : OclAny = _tuple->at(2) in (((g))->size())) ; if (g)->size() = 1 then ( execute ((S)->size() * K div 2)->display() ) else ( var acc : double := ((argument (test (logical_test (comparison (expr (expr (atom (name l))) // (expr (atom (number (integer 2)))))))) (comp_for for (exprlist (expr (atom (name l)))) in (logical_test (comparison (expr (atom (name g))))))))->sum() * K ; if S->first() = S->last() & g->first() mod 2 = 1 & g->last() mod 2 = 1 then ( acc := acc + K - 1 ) else skip ; execute (acc)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) m=0 for i in range(n): if l[i]<0 : m+=1 l[i]=-l[i] for i in range(m): l[i]=-l[i] r=l.copy() r.sort() if r==l : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := 0 ; for i : Integer.subrange(0, n-1) do ( if l[i+1] < 0 then ( m := m + 1 ; l[i+1] := -l[i+1] ) else skip) ; for i : Integer.subrange(0, m-1) do ( l[i+1] := -l[i+1]) ; var r : OclAny := l->copy() ; r := r->sort() ; if r = l then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- xx=int(input()) def cal(n,arr): x=0 for i in range(n): if arr[i]<0 : x+=1 arr[i]=-arr[i] for i in range(x): arr[i]=-arr[i] if sorted(arr)==arr : return True return False for jj in range(xx): n=int(input()) arr=[int(i)for i in input().split(' ')] if cal(n,arr): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var xx : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; for jj : Integer.subrange(0, xx-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; arr := input().split(' ')->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if cal(n, arr) then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); operation cal(n : OclAny, arr : OclAny) : OclAny pre: true post: true activity: var x : int := 0 ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] < 0 then ( x := x + 1 ; arr[i+1] := -arr[i+1] ) else skip) ; for i : Integer.subrange(0, x-1) do ( arr[i+1] := -arr[i+1]) ; if arr->sort() = arr then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findUniquePair(arr,n): XOR=arr[0] for i in range(1,n): XOR=XOR ^ arr[i] set_bit_no=XOR & ~(XOR-1) x=0 y=0 for i in range(0,n): if(arr[i]& set_bit_no): x=x ^ arr[i] else : y=y ^ arr[i] print("The unique pair is(",x,",",y,")",sep="") a=[6,1,3,5,1,3,7,6] n=len(a) findUniquePair(a,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : Sequence := Sequence{6}->union(Sequence{1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{1}->union(Sequence{3}->union(Sequence{7}->union(Sequence{ 6 }))))))) ; n := (a)->size() ; findUniquePair(a, n); operation findUniquePair(arr : OclAny, n : OclAny) pre: true post: true activity: var XOR : OclAny := arr->first() ; for i : Integer.subrange(1, n-1) do ( XOR := MathLib.bitwiseXor(XOR, arr[i+1])) ; var set_bit_no : int := MathLib.bitwiseAnd(XOR, MathLib.bitwiseNot((XOR - 1))) ; var x : int := 0 ; var y : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (MathLib.bitwiseAnd(arr[i+1], set_bit_no)) then ( x := MathLib.bitwiseXor(x, arr[i+1]) ) else ( y := MathLib.bitwiseXor(y, arr[i+1]) )) ; execute ("The unique pair is(")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter def solve(): n=int(input()) arr=list(map(int,input().split())) minus=len(list(filter(lambda x : x<0,arr))) flag=False for i in range(minus-1): if abs(arr[i])>=abs(arr[i+1]): continue else : flag=True break for i in range(minus,n-1): if abs(arr[i])<=abs(arr[i+1]): continue else : flag=True break print("YES" if not flag else "NO") def main(): t=int(input()) for _ in range(t): solve() if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var minus : int := (((arr)->select( _x | (lambda x : OclAny in (x < 0))->apply(_x) = true )))->size() ; var flag : boolean := false ; for i : Integer.subrange(0, minus - 1-1) do ( if ((arr[i+1])->abs()->compareTo((arr[i + 1+1])->abs())) >= 0 then ( continue ) else ( flag := true ; break )) ; for i : Integer.subrange(minus, n - 1-1) do ( if ((arr[i+1])->abs()->compareTo((arr[i + 1+1])->abs())) <= 0 then ( continue ) else ( flag := true ; break )) ; execute (if not(flag) then "YES" else "NO" endif)->display(); operation main() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( solve()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for case_num in range(t): n=int(input()) a=list(map(int,input().split())) neg=len([x for x in a if x<0]) for i in range(n): if itoInteger() ; for case_num : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var neg : int := (a->select(x | x < 0)->collect(x | (x)))->size() ; for i : Integer.subrange(0, n-1) do ( if (i->compareTo(neg)) < 0 then ( a[i+1] := -(a[i+1])->abs() ) else ( a[i+1] := (a[i+1])->abs() )) ; execute (if a = a->sort() then 'YES' else 'NO' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for f in range(int(input())): n,a=int(input()),[*map(int,input().split())] h=sum(1 for v in a if v<0) b=[abs(a[i])*(-1 if itoInteger()-1) do ( var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),(input().split())->collect( _x | (OclType["int"])->apply(_x) )} ; var h : OclAny := ((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name a))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name v)))) < (comparison (expr (atom (number (integer 0))))))))))))->sum() ; var b : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((a[i+1])->abs() * (if (i->compareTo(h)) < 0 then -1 else 1 endif))) ; execute (if b->sort() = b then 'YES' else 'NO' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) l=sorted(map(int,input().split())) j=0 for i in l : while l[j]collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var j : int := 0 ; for i : l do ( while (l[j+1]->compareTo(i)) < 0 do ( if (i->compareTo(k + l[j+1])) <= 0 then ( n := n - 1 ) else skip ; j := j + 1)) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=list(map(int,input().strip().split())) dic={} for i in a : if i in dic.keys(): dic[i]+=1 else : dic[i]=1 s=list(set(a)) s.sort() c=0 for i in range(len(s)-1): if s[i+1]-s[i]>k : c+=dic[s[i]] c+=dic[s[-1]] print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dic : OclAny := Set{} ; for i : a do ( if (dic.keys())->includes(i) then ( dic[i+1] := dic[i+1] + 1 ) else ( dic[i+1] := 1 )) ; var s : Sequence := (Set{}->union((a))) ; s := s->sort() ; var c : int := 0 ; for i : Integer.subrange(0, (s)->size() - 1-1) do ( if (s[i + 1+1] - s[i+1]->compareTo(k)) > 0 then ( c := c + dic[s[i+1]+1] ) else skip) ; c := c + dic[s->last()+1] ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=list(map(int,input().split())) a.sort() j=0 for i in a : while a[j]collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var j : int := 0 ; for i : a do ( while (a[j+1]->compareTo(i)) < 0 do ( if (i - a[j+1]->compareTo(k)) <= 0 then ( n := n - 1 ) else skip ; j := j + 1)) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n,k=[int(i)for i in input().split()] a=sorted([int(i)for i in input().split()]) cnt=Counter(a) ans=0 l=list(zip(a,[cnt[i]for i in a])) for i in range(1,n): if l[i][0]>l[i-1][0]and l[i-1][0]+k>=l[i][0]: ans+=l[i-1][1] print(n-ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))->sort() ; var cnt : OclAny := Counter(a) ; var ans : int := 0 ; var l : Sequence := (Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), a->select(i | true)->collect(i | (cnt[i+1]))->at(_indx)} )) ; for i : Integer.subrange(1, n-1) do ( if (l[i+1]->first()->compareTo(l[i - 1+1]->first())) > 0 & (l[i - 1+1]->first() + k->compareTo(l[i+1]->first())) >= 0 then ( ans := ans + l[i - 1+1][1+1] ) else skip) ; execute (n - ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,k=map(int,input().split()) w=sorted(map(int,input().split())) j=0 for i in w : while w[j]collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var j : int := 0 ; for i : w do ( while (w[j+1]->compareTo(i)) < 0 do ( if (i->compareTo(k + w[j+1])) <= 0 then ( n := n - 1 ) else skip ; j := j + 1)) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[input()for i in range(2)] text=a[0] iter=int(a[1]) text_list=list(text) ren=[] start=text_list[0] a=0 for i in range(1,len(text_list)): if text_list[i]==start : a+=1 if i==len(text_list)-1 : ren.append(a) else : start=text_list[i] ren.append(a) a=0 for i in range(len(ren)): ren[i]+=1 if ren==[]: ren=[1] ans=0 if len(ren)==1 : ans=ren[0]*iter//2 elif text_list[0]==text_list[-1]: if ren[0]% 2==1 and ren[-1]% 2==1 : for r in ren : ans+=(r//2) ans*=iter ans+=iter-1 else : for r in ren : ans+=(r//2) ans*=iter else : for r in ren : ans+=(r//2) ans*=iter print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Integer.subrange(0, 2-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var text : OclAny := a->first() ; var iter : int := ("" + ((a[1+1])))->toInteger() ; var text_list : Sequence := (text) ; var ren : Sequence := Sequence{} ; var start : OclAny := text_list->first() ; a := 0 ; for i : Integer.subrange(1, (text_list)->size()-1) do ( if text_list[i+1] = start then ( a := a + 1 ; if i = (text_list)->size() - 1 then ( execute ((a) : ren) ) else skip ) else ( start := text_list[i+1] ; execute ((a) : ren) ; a := 0 )) ; for i : Integer.subrange(0, (ren)->size()-1) do ( ren[i+1] := ren[i+1] + 1) ; if ren = Sequence{} then ( ren := Sequence{ 1 } ) else skip ; var ans : int := 0 ; if (ren)->size() = 1 then ( ans := ren->first() * iter div 2 ) else (if text_list->first() = text_list->last() then ( if ren->first() mod 2 = 1 & ren->last() mod 2 = 1 then ( for r : ren do ( ans := ans + (r div 2)) ; ans := ans * iter ; ans := ans + iter - 1 ) else ( for r : ren do ( ans := ans + (r div 2)) ; ans := ans * iter ) ) else ( for r : ren do ( ans := ans + (r div 2)) ; ans := ans * iter ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def power(x,y): if(y==0): return 1 elif(int(y % 2)==0): return(power(x,int(y/2))*power(x,int(y/2))) else : return(x*power(x,int(y/2))*power(x,int(y/2))) x=2 ; y=3 print(power(x,y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := 2; y := 3 ; execute (power(x, y))->display(); operation power(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (y = 0) then ( return 1 ) else (if (("" + ((y mod 2)))->toInteger() = 0) then ( return (power(x, ("" + ((y / 2)))->toInteger()) * power(x, ("" + ((y / 2)))->toInteger())) ) else ( return (x * power(x, ("" + ((y / 2)))->toInteger()) * power(x, ("" + ((y / 2)))->toInteger())) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=[] for i in range(n): k=input() s.append(k) flag=0 d1=[] d2=[] rem=set() for i in range(n): for j in range(n): if(i==j): d1.append(s[i][j]) if(i==n-j-1): d2.append(s[i][j]) if(i!=j and i!=n-j-1): rem.add(s[i][j]) if(len(rem)!=1): print('NO') elif(d1!=d2): print('NO') elif(len(set(d1))!=1): print('NO') elif(set(d1)==rem): print('NO') else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var k : String := (OclFile["System.in"]).readLine() ; execute ((k) : s)) ; var flag : int := 0 ; var d1 : Sequence := Sequence{} ; var d2 : Sequence := Sequence{} ; var rem : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if (i = j) then ( execute ((s[i+1][j+1]) : d1) ) else skip ; if (i = n - j - 1) then ( execute ((s[i+1][j+1]) : d2) ) else skip ; if (i /= j & i /= n - j - 1) then ( execute ((s[i+1][j+1]) : rem) ) else skip)) ; if ((rem)->size() /= 1) then ( execute ('NO')->display() ) else (if (d1 /= d2) then ( execute ('NO')->display() ) else (if ((Set{}->union((d1)))->size() /= 1) then ( execute ('NO')->display() ) else (if (Set{}->union((d1)) = rem) then ( execute ('NO')->display() ) else ( execute ('YES')->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def charVal(s,i): if(s[i]=='0'): return 0 elif(s[i]=='1'): return 1 else : return 2 def countMinimalReplacements(s,i,prev,dp,n): if(i==n): return 0 if(dp[i][prev]!=-1): return dp[i][prev] val=charVal(s,i) ans=sys.maxsize if(val==prev): val=0 for cur in range(3): if(cur==prev): continue val=1+countMinimalReplacements(s,i+1,cur,dp,n) ans=min(ans,val) else : ans=countMinimalReplacements(s,i+1,val,dp,n) dp[i][val]=ans return dp[i][val] if __name__=='__main__' : s="201220211" n=len(s) dp=[[-1 for i in range(3)]for i in range(n)] val=charVal(s,0) print(countMinimalReplacements(s,1,val,dp,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( s := "201220211" ; n := (s)->size() ; dp := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, 3-1)->select(i | true)->collect(i | (-1)))) ; val := charVal(s, 0) ; execute (countMinimalReplacements(s, 1, val, dp, n))->display() ) else skip; operation charVal(s : OclAny, i : OclAny) : OclAny pre: true post: true activity: if (s[i+1] = '0') then ( return 0 ) else (if (s[i+1] = '1') then ( return 1 ) else ( return 2 ) ) ; operation countMinimalReplacements(s : OclAny, i : OclAny, prev : OclAny, dp : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (i = n) then ( return 0 ) else skip ; if (dp[i+1][prev+1] /= -1) then ( return dp[i+1][prev+1] ) else skip ; var val : OclAny := charVal(s, i) ; var ans : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; if (val = prev) then ( val := 0 ; for cur : Integer.subrange(0, 3-1) do ( if (cur = prev) then ( continue ) else skip ; val := 1 + countMinimalReplacements(s, i + 1, cur, dp, n) ; ans := Set{ans, val}->min()) ) else ( ans := countMinimalReplacements(s, i + 1, val, dp, n) ) ; dp[i+1][val+1] := ans ; return dp[i+1][val+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def xorRange(pre,l,r): cntOnes=pre[r] if(l-1>=0): cntOnes-=pre[l-1] if(cntOnes % 2==0): return 0 else : return 1 def performQueries(queries,q,a,n): pre=[0 for i in range(n)] pre[0]=a[0] for i in range(1,n): pre[i]=pre[i-1]+a[i] for i in range(q): print(xorRange(pre,queries[i][0],queries[i][1])) a=[1,0,1,1,0,1,1] n=len(a) queries=[[0,3],[0,2]] q=len(queries) performQueries(queries,q,a,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 1 })))))) ; n := (a)->size() ; queries := Sequence{Sequence{0}->union(Sequence{ 3 })}->union(Sequence{ Sequence{0}->union(Sequence{ 2 }) }) ; q := (queries)->size() ; performQueries(queries, q, a, n); operation xorRange(pre : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var cntOnes : OclAny := pre[r+1] ; if (l - 1 >= 0) then ( cntOnes := cntOnes - pre[l - 1+1] ) else skip ; if (cntOnes mod 2 = 0) then ( return 0 ) else ( return 1 ); operation performQueries(queries : OclAny, q : OclAny, a : OclAny, n : OclAny) pre: true post: true activity: pre := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; pre->first() := a->first() ; for i : Integer.subrange(1, n-1) do ( pre[i+1] := pre[i - 1+1] + a[i+1]) ; for i : Integer.subrange(0, q-1) do ( execute (xorRange(pre, queries[i+1]->first(), queries[i+1][1+1]))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math CONVERT=10000 def f(nums,power,k): for i in range(power): nums[nums.index(min(nums))]+=1 ans=1 for n in nums : ans*=n/CONVERT return ans def logs(x): if x==0 : return-100000 return math.log(x) def logadd(a,b): if atoInteger() ; for case : Integer.subrange(1, T + 1-1) do ( var n : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; power := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; power := power * CONVERT ; power := (power)->round() ; var starts : Sequence := ((input().split())->collect( _x | (OclType["double"])->apply(_x) )) ; for i : Integer.subrange(0, (starts)->size()-1) do ( starts[i+1] := (starts[i+1] * CONVERT)->round()) ; ans := f(starts, power, k) ; execute (StringLib.format("Case #%s: %s",Sequence{case, ans}))->display()); operation f(nums : OclAny, power : OclAny, k : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, power-1) do ( nums[nums->indexOf((nums)->min()) - 1+1] := nums[nums->indexOf((nums)->min()) - 1+1] + 1) ; var ans : int := 1 ; for n : nums do ( ans := ans * n / CONVERT) ; return ans; operation logs(x : OclAny) : OclAny pre: true post: true activity: if x = 0 then ( return -100000 ) else skip ; return (x)->log(); operation logadd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a->compareTo(b)) < 0 then ( Sequence{a,b} := Sequence{b,a} ) else skip ; return a + logs(1 + (b - a)->exp()); operation p(nums : OclAny, K : OclAny) : OclAny pre: true post: true activity: var store : Sequence := Sequence{} ; for i : Integer.subrange(0, K + 1-1) do ( execute ((MatrixLib.elementwiseMult(Sequence{ 0 }, (nums)->size())) : store)) ; for k : Integer.subrange(0, K + 1-1) do ( for i : Integer.subrange(0, (nums)->size()-1) do ( if k = 0 then ( store[k+1][i+1] := 0 ) else (if i = 0 then ( store[k+1][i+1] := -100000 ) else ( store[k+1][i+1] := logadd(store[k - 1+1][i - 1+1] + logs(nums[i+1]), store[k+1][i - 1+1] + logs(1 - nums[i+1])) ) ) )) ; return store[K+1][(nums)->size() - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from functools import reduce lines=[l.strip()for l in sys.stdin.readlines()] T=int(lines[0]) i=1 for t in range(T): N,K=map(int,lines[i].split(' ')) i+=1 U=float(lines[i]) i+=1 P=list(map(float,lines[i].split(' '))) i+=1 P.sort() j=0 while j0.000000000001 : while jselect(l | true)->collect(l | (l->trim())) ; var T : int := ("" + ((lines->first())))->toInteger() ; var i : int := 1 ; for t : Integer.subrange(0, T-1) do ( var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (lines[i+1].split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; i := i + 1 ; var U : double := ("" + ((lines[i+1])))->toReal() ; i := i + 1 ; var P : Sequence := ((lines[i+1].split(' '))->collect( _x | (OclType["double"])->apply(_x) )) ; i := i + 1 ; P := P->sort() ; var j : int := 0 ; while (j->compareTo(N)) < 0 & U > 0.000000000001 do ( while (j->compareTo(N - 1)) < 0 & P[j+1] = P[j + 1+1] do ( j := j + 1) ; var target : OclAny := if (j->compareTo(N - 1)) < 0 then P[j + 1+1] else 1 endif ; var required : double := (target - P[j+1]) * (j + 1) ; if (required->compareTo(U)) <= 0 then ( U := U - required ; P.subrange(0+1, j + 1) := MatrixLib.elementwiseMult(Sequence{ target }, (j + 1)) ) else ( target := P[j+1] + U / (j + 1) ; U := 0 ; P.subrange(0+1, j + 1) := MatrixLib.elementwiseMult(Sequence{ target }, (j + 1)) )) ; execute (StringLib.format("Case #%d: %f",Sequence{t + 1, reduce(lambda x : OclAny, y : OclAny in (x * y), P, 1.0)}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- with open('C-small-1-attempt0.in')as infile : with open('C-small-1-attempt0.out','w')as outfile : cases=int(next(infile)) for case in range(1,cases+1): n,k=map(int,next(infile).split()) u=round(float(next(infile))*10000) p=list(map(lambda x : round(float(x)*10000),next(infile).split())) p.sort() p.append(10000) i=0 while u>0 and itoInteger() ; for case : Integer.subrange(1, cases + 1-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (next(infile).split())->collect( _x | (OclType["int"])->apply(_x) ) ; var u : double := (("" + (((infile).next())))->toReal() * 10000)->round() ; var p : Sequence := ((next(infile).split())->collect( _x | (lambda x : OclAny in ((("" + ((x)))->toReal() * 10000)->round()))->apply(_x) )) ; p := p->sort() ; execute ((10000) : p) ; var i : int := 0 ; while u > 0 & (i->compareTo((p)->size())) < 0 do ( while (i->compareTo((p)->size())) < 0 & p[i+1] = p[i + 1+1] do ( i := i + 1) ; var x : OclAny := Set{(p[i + 1+1] - p[i+1]) * (i + 1), u}->min() ; for j : Integer.subrange(0, i + 1-1) do ( p[j+1] := p[j+1] + x / (i + 1)) ; u := u - x) ; var product : int := 1 ; for x : p do ( product := product * x / 10000) ; execute (case)->display() ; execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{case, product}))->display())) catch (_e : OclException) do skip) catch (_e : OclException) do skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def problem(success,units,cores): cores.sort() cores.append(1.0) spent=0.0 min_prob=0.0 for i,core in enumerate(cores): if core==1.0 : min_prob=1.0 break plan=(cores[i+1]-cores[i])*(i+1) if plan>units-spent : min_prob=core+(units-spent)/(i+1) break spent+=plan prob=1.0 for n in cores : prob*=max(min_prob,n) return prob def nextline(input_file): data="" while not data : data=input_file.readline() return data[:-1] def intsplit(s): return[int(x)for x in s.split("")] def floatsplit(s): return[float(x)for x in s.split("")] def main(): result="" with sys.stdin if len(sys.argv)==1 else open(sys.argv[1],'r')as infile : number=int(nextline(infile)) for run in range(number): case=nextline(infile) total,success=intsplit(case) units=float(nextline(infile)) cores=floatsplit(nextline(infile)) result+='Case #{}:{}\n'.format(1+run,problem(success,units,cores)) if len(sys.argv)==1 : print(result,end='') else : with open(sys.argv[1].replace('in','sol'),'w')as result_file : result_file.write(result) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation problem(success : OclAny, units : OclAny, cores : OclAny) : OclAny pre: true post: true activity: cores := cores->sort() ; execute ((1.0) : cores) ; var spent : double := 0.0 ; var min_prob : double := 0.0 ; for _tuple : Integer.subrange(1, (cores)->size())->collect( _indx | Sequence{_indx-1, (cores)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var core : OclAny := _tuple->at(_indx); if core = 1.0 then ( min_prob := 1.0 ; break ) else skip ; var plan : double := (cores[i + 1+1] - cores[i+1]) * (i + 1) ; if (plan->compareTo(units - spent)) > 0 then ( min_prob := core + (units - spent) / (i + 1) ; break ) else skip ; spent := spent + plan) ; var prob : double := 1.0 ; for n : cores do ( prob := prob * Set{min_prob, n}->max()) ; return prob; operation nextline(input_file : OclAny) : OclAny pre: true post: true activity: var data : String := "" ; while not(data = "") do ( data := input_file.readLine()) ; return data->front(); operation intsplit(s : OclAny) : OclAny pre: true post: true activity: return s.split("")->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation floatsplit(s : OclAny) : OclAny pre: true post: true activity: return s.split("")->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation main() pre: true post: true activity: var result : String := "" ; try (var infile : OclFile := if ((trailer . (name argv)))->size() = 1 then OclFile["System.in"] else OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) endif; var number : int := ("" + ((nextline(infile))))->toInteger() ; for run : Integer.subrange(0, number-1) do ( var case : OclAny := nextline(infile) ; var total : OclAny := null; Sequence{total,success} := intsplit(case) ; units := ("" + ((nextline(infile))))->toReal() ; cores := floatsplit(nextline(infile)) ; result := result + StringLib.interpolateStrings('Case #{}:{} ', Sequence{1 + run, problem(success, units, cores)}))) catch (_e : OclException) do skip ; if ((trailer . (name argv)))->size() = 1 then ( execute (result)->display() ) else ( try (var result_file : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))).replace('in', 'sol'))); result_file.write(result)) catch (_e : OclException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import functools import operator def work(): n,k=map(int,input().split()) u=float(input()) ps=list(map(float,input().split())) def f(v): return functools.reduce(operator.mul,(max(p,v)for p in ps)) def search(a,b,it): if it==100 : return a c=0.5*(a+b) return search(c,b,it+1)if sum(max(0,c-p)for p in ps)<=u else search(a,c,it+1) return f(search(0,1,0)) for t in range(int(input())): print('Case #{}:{:.7f}'.format(t+1,work())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (StringLib.interpolateStrings('Case #{}:{:.7f}', Sequence{t + 1, work()}))->display()); operation work() : OclAny pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var u : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; var ps : Sequence := ((input().split())->collect( _x | (OclType["double"])->apply(_x) )) ; skip ; skip ; return f(search(0, 1, 0)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printArray(A,n,K): minEle=10**9 maxEle=-10**9 for i in range(n): minEle=min(minEle,A[i]) maxEle=max(maxEle,A[i]) if(K!=0): if(K % 2==1): for i in range(n): A[i]=maxEle-A[i] else : for i in range(n): A[i]=A[i]-minEle for i in A : print(i,end=" ") if __name__=='__main__' : arr=[4,8,12,16] K=4 N=len(arr) printArray(arr,N,K) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var arr : Sequence := Sequence{4}->union(Sequence{8}->union(Sequence{12}->union(Sequence{ 16 }))) ; K := 4 ; var N : int := (arr)->size() ; printArray(arr, N, K) ) else skip; operation printArray(A : OclAny, n : OclAny, K : OclAny) pre: true post: true activity: var minEle : double := (10)->pow(9) ; var maxEle : double := (-10)->pow(9) ; for i : Integer.subrange(0, n-1) do ( minEle := Set{minEle, A[i+1]}->min() ; maxEle := Set{maxEle, A[i+1]}->max()) ; if (K /= 0) then ( if (K mod 2 = 1) then ( for i : Integer.subrange(0, n-1) do ( A[i+1] := maxEle - A[i+1]) ) else ( for i : Integer.subrange(0, n-1) do ( A[i+1] := A[i+1] - minEle) ) ) else skip ; for i : A do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p=[] for i in range(2,1121): for j in range(2,int(i**0.5)+1): if not i % j : break else : p+=[i] dp=[[0]*1121 for _ in range(15)] dp[0][0]=1 for x,y in enumerate(p): for i in range(min(x+1,14),0,-1): for j in range(y,1121): dp[i][j]+=dp[i-1][j-y] while 1 : n,k=map(int,input().split()) if n==0 : break print(dp[k][n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : Sequence := Sequence{} ; for i : Integer.subrange(2, 1121-1) do ((compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) ** (expr (atom (number 0.5))))))))) )))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test not (logical_test (comparison (expr (expr (atom (name i))) % (expr (atom (name j)))))))) : (suite (simple_stmt (small_stmt break)))))) (else_clause else : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name p)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name i))))))) ]))))))))))))) ; var dp : Sequence := Integer.subrange(0, 15-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 1121))) ; dp->first()->first() := 1 ; for _tuple : Integer.subrange(1, (p)->size())->collect( _indx | Sequence{_indx-1, (p)->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); for i : Integer.subrange(0 + 1, Set{x + 1, 14}->min())->reverse() do ( for j : Integer.subrange(y, 1121-1) do ( dp[i+1][j+1] := dp[i+1][j+1] + dp[i - 1+1][j - y+1]))) ; while 1 do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; execute (dp[k+1][n+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,s=open(0); print(min(sum(abs(x-c**i)for i,x in enumerate(sorted(map(int,s.split()))))for c in range(2+9**6//int(n)**2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := OclFile.newOclFile_Write(OclFile.newOclFile(0)); execute (((argument (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (expr (atom (name c))) ** (expr (atom (name i)))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name s)) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) + (expr (expr (expr (atom (number (integer 9)))) ** (expr (atom (number (integer 6))))) // (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))) ** (expr (atom (number (integer 2)))))))))))) )))))))))->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[0] i=0 while True : k=a[i] if k>=n and str(k).count('4')==str(k).count('7'): print(k) break a+=[10*k+4,10*k+7] i+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{ 0 } ; var i : int := 0 ; while true do ( var k : OclAny := a[i+1] ; if (k->compareTo(n)) >= 0 & OclType["String"](k)->count('4') = OclType["String"](k)->count('7') then ( execute (k)->display() ; break ) else skip ; a := a + Sequence{10 * k + 4}->union(Sequence{ 10 * k + 7 }) ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- primes=[] flag=[0 for i in range(1121)] for i in range(2,1121): if flag[i]==0 : primes.append(i) count=2 while i*count<1121 : flag[i*count]=1 count+=1 dp=[[0 for i in range(15)]for j in range(1121)] dp[0][0]=1 for p in primes : for k in range(13,-1,-1): for n in range(1121): if n+p<1121 : dp[n+p][k+1]+=dp[n][k] else : break while True : N,K=map(int,input().split()) if(N | K==0): break print(dp[N][K]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var primes : Sequence := Sequence{} ; var flag : Sequence := Integer.subrange(0, 1121-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(2, 1121-1) do ( if flag[i+1] = 0 then ( execute ((i) : primes) ) else skip ; var count : int := 2 ; while i * count < 1121 do ( flag[i * count+1] := 1 ; count := count + 1)) ; var dp : Sequence := Integer.subrange(0, 1121-1)->select(j | true)->collect(j | (Integer.subrange(0, 15-1)->select(i | true)->collect(i | (0)))) ; dp->first()->first() := 1 ; for p : primes do ( for k : Integer.subrange(-1 + 1, 13)->reverse() do ( for n : Integer.subrange(0, 1121-1) do ( if n + p < 1121 then ( dp[n + p+1][k + 1+1] := dp[n + p+1][k + 1+1] + dp[n+1][k+1] ) else ( break )))) ; while true do ( var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (MathLib.bitwiseOr(N, K) = 0) then ( break ) else skip ; execute (dp[N+1][K+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import string import collections import fractions import random from operator import itemgetter import itertools from collections import deque import copy import heapq import bisect MOD=10**9+7 INF=float('inf') input=lambda : sys.stdin.readline().strip() sys.setrecursionlimit(10**8) def judge_prime_num(n): if n % 2==0 and n!=2 : return False else : for num in range(3,int(math.sqrt(n)+2)): if n % num==0 : return False return True prime_list=[] for i in range(2,1121): if judge_prime_num(i): prime_list.append(i) dp=[[[0]*1122 for _ in range(16)]for _ in range(190)] dp[0][0][0]=1 for i in range(len(prime_list)): for j in range(15): for k in range(1121): if k+prime_list[i]<=1120 : dp[i+1][j+1][k+prime_list[i]]+=dp[i][j][k] dp[i+1][j][k]+=dp[i][j][k] n,k=map(int,input().split()) while not n==k==0 : print(dp[len(prime_list)][k][n]) n,k=map(int,input().split()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var MOD : double := (10)->pow(9) + 7 ; var INF : double := ("" + (('inf')))->toReal() ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine()->trim()) ; sys.setrecursionlimit((10)->pow(8)) ; skip ; var prime_list : Sequence := Sequence{} ; for i : Integer.subrange(2, 1121-1) do ( if judge_prime_num(i) then ( execute ((i) : prime_list) ) else skip) ; var dp : Sequence := Integer.subrange(0, 190-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, 16-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 1122))))) ; dp->first()->first()->first() := 1 ; for i : Integer.subrange(0, (prime_list)->size()-1) do ( for j : Integer.subrange(0, 15-1) do ( for k : Integer.subrange(0, 1121-1) do ( if k + prime_list[i+1] <= 1120 then ( dp[i + 1+1][j + 1+1][k + prime_list[i+1]+1] := dp[i + 1+1][j + 1+1][k + prime_list[i+1]+1] + dp[i+1][j+1][k+1] ) else skip ; dp[i + 1+1][j+1][k+1] := dp[i + 1+1][j+1][k+1] + dp[i+1][j+1][k+1]))) ; var k : OclAny := null; Sequence{n,k} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; while not(n = k & (k == 0)) do ( execute (dp[(prime_list)->size()+1][k+1][n+1])->display() ; var k : OclAny := null; Sequence{n,k} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )); operation judge_prime_num(n : OclAny) : OclAny pre: true post: true activity: if n mod 2 = 0 & n /= 2 then ( return false ) else ( for num : Integer.subrange(3, ("" + (((n)->sqrt() + 2)))->toInteger()-1) do ( if n mod num = 0 then ( return false ) else skip) ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=64 ; def maxOR(L,R): if(L==R): return L ; ans=0 ; for i in range(MAX-1,-1,-1): p=1<>i)& 1 ; rbit=(R>>i)& 1 ; if((rbit==1)and(lbit==0)): ans+=(p<<1)-1 ; break ; if(rbit==1): ans+=p ; return ans ; if __name__=="__main__" : L=4 ; R=5 ; print(maxOR(L,R)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 64; ; skip ; if __name__ = "__main__" then ( L := 4; R := 5; ; execute (maxOR(L, R))->display(); ) else skip; operation maxOR(L : OclAny, R : OclAny) pre: true post: true activity: if (L = R) then ( return L; ) else skip ; var ans : int := 0; ; for i : Integer.subrange(-1 + 1, MAX - 1)->reverse() do ( var p : int := 1 * (2->pow(i)); ; var lbit : int := MathLib.bitwiseAnd((L /(2->pow(i))), 1); ; var rbit : int := MathLib.bitwiseAnd((R /(2->pow(i))), 1); ; if ((rbit = 1) & (lbit = 0)) then ( ans := ans + (p * (2->pow(1))) - 1; ; break; ) else skip ; if (rbit = 1) then ( ans := ans + p; ) else skip) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import product variables=set(list("abcdefghijk")) def formula(S,X,i): if S[i]=="T" : return 1,i+1 elif S[i]=="F" : return 0,i+1 elif S[i]in variables : return X[S[i]],i+1 elif S[i]=="-" : i+=1 that,i=formula(S,X,i) return(not that),i else : i+=1 this,i=formula(S,X,i) op=S[i] i+=1 that,i=formula(S,X,i) i+=1 if op=="*" : return this & that,i elif op=="+" : return this | that,i elif op=="@" : return(not this)| that,i else : raise S=input() T,F=1,0 while S!="#" : S=S.replace("->","@") while "--" in S : S=S.replace("--","") L,R=S.split("=") for v in range(2**11): X={} for a,x in zip(list("abcdefghijk"),format(v,"b").zfill(11)): X[a]=int(x) l,_=formula(L,X,0) r,_=formula(R,X,0) if int(l)!=int(r): print("NO") break else : print("YES") S=input() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var variables : Set := Set{}->union((("abcdefghijk")->characters())) ; skip ; S := (OclFile["System.in"]).readLine() ; var T : OclAny := null; var F : OclAny := null; Sequence{T,F} := Sequence{1,0} ; while S /= "#" do ( S := S.replace("->", "@") ; while (S)->includes("--") do ( S := S.replace("--", "")) ; var L : OclAny := null; var R : OclAny := null; Sequence{L,R} := S.split("=") ; (compound_stmt for (exprlist (expr (atom (name v)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) ** (expr (atom (number (integer 11)))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name X)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom { }))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name a))) , (expr (atom (name x)))) in (testlist (test (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "abcdefghijk"))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name format)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v))))))) , (argument (test (logical_test (comparison (expr (atom "b"))))))) ))) (trailer . (name zfill) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 11))))))))) ))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name X)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name l)))))) , (test (logical_test (comparison (expr (atom (name _))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name formula)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L))))))) , (argument (test (logical_test (comparison (expr (atom (name X))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name r)))))) , (test (logical_test (comparison (expr (atom (name _))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name formula)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name R))))))) , (argument (test (logical_test (comparison (expr (atom (name X))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)))))))) ))))) != (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name r)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) ))))))))))))))) ; S := (OclFile["System.in"]).readLine()); operation formula(S : OclAny, X : OclAny, i : OclAny) : OclAny pre: true post: true activity: if S[i+1] = "T" then ( return 1, i + 1 ) else (if S[i+1] = "F" then ( return 0, i + 1 ) else (if (variables)->includes(S[i+1]) then ( return X[S[i+1]+1], i + 1 ) else (if S[i+1] = "-" then ( i := i + 1 ; var that : OclAny := null; Sequence{that,i} := formula(S, X, i) ; return (not(that)), i ) else ( i := i + 1 ; var this : OclAny := null; Sequence{this,i} := formula(S, X, i) ; var op : OclAny := S[i+1] ; i := i + 1 ; var that : OclAny := null; Sequence{that,i} := formula(S, X, i) ; i := i + 1 ; if op = "*" then ( return MathLib.bitwiseAnd(this, that), i ) else (if op = "+" then ( return MathLib.bitwiseOr(this, that), i ) else (if op = "@" then ( return MathLib.bitwiseOr((not(this)), that), i ) else ( (small_stmt raise) ) ) ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : s=input() if s=="#" : break index=-1 bits=[] for i in range(2<<11): bit=[] for j in range(11): bit.append(i>>j & 1==1) bits.append(bit) def formula(string): global index index+=1 if string[index]=="T" : return True elif string[index]=="F" : return False elif string[index]=="-" : return not formula(string) elif string[index]=="(" : left=formula(string) index+=1 ope=string[index] if ope=="-" : index+=1 right=formula(string) index+=1 if ope=="+" : return left or right elif ope=="*" : return left and right else : return False if left and not right else True else : return bit[ord(string[index])-ord("a")] f=True for bit in bits : l,r=s.split("=") index=-1 l_b=formula(l) index=-1 r_b=formula(r) if l_b!=r_b : f=False if f : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { attribute index : OclAny; operation initialise() pre: true post: true activity: while true do ( var s : String := (OclFile["System.in"]).readLine() ; if s = "#" then ( break ) else skip ; var index : int := -1 ; var bits : Sequence := Sequence{} ; for i : Integer.subrange(0, 2 * (2->pow(11))-1) do ( var bit : Sequence := Sequence{} ; for j : Integer.subrange(0, 11-1) do ( execute ((MathLib.bitwiseAnd(i /(2->pow(j)), 1) = 1) : bit)) ; execute ((bit) : bits)) ; skip ; var f : boolean := true ; for bit : bits do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := s.split("=") ; index := -1 ; var l_b : OclAny := formula(l) ; index := -1 ; var r_b : OclAny := formula(r) ; if l_b /= r_b then ( f := false ) else skip) ; if f then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSplit(arr,n): preSum=0 ind1=-1 ind2=-1 S=arr[0] for i in range(1,n): S+=arr[i] if(S % 3!=0): return 0 S1=S/3 S2=2*S1 for i in range(0,n): preSum+=arr[i] if(preSum % S1==0 and ind1==-1): ind1=i elif(preSum % S2==0): ind2=i break if(ind1!=-1 and ind2!=-1): print("({},{})".format(ind1,ind2)) return 1 return 0 arr=[1,3,4,0,4] n=len(arr) if(findSplit(arr,n)==0): print("-1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{3}->union(Sequence{4}->union(Sequence{0}->union(Sequence{ 4 })))) ; n := (arr)->size() ; if (findSplit(arr, n) = 0) then ( execute ("-1")->display() ) else skip; operation findSplit(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var preSum : int := 0 ; var ind1 : int := -1 ; var ind2 : int := -1 ; var S : OclAny := arr->first() ; for i : Integer.subrange(1, n-1) do ( S := S + arr[i+1]) ; if (S mod 3 /= 0) then ( return 0 ) else skip ; var S1 : double := S / 3 ; var S2 : double := 2 * S1 ; for i : Integer.subrange(0, n-1) do ( preSum := preSum + arr[i+1] ; if (preSum mod S1 = 0 & ind1 = -1) then ( ind1 := i ) else (if (preSum mod S2 = 0) then ( ind2 := i ; break ) else skip)) ; if (ind1 /= -1 & ind2 /= -1) then ( execute (StringLib.interpolateStrings("({},{})", Sequence{ind1, ind2}))->display() ; return 1 ) else skip ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def NoofTriplets(N,K): cnt=[0]*K ; for i in range(1,N+1): cnt[i % K]+=1 ; if(K & 1): rslt=cnt[0]*cnt[0]*cnt[0]; return rslt else : rslt=(cnt[0]*cnt[0]*cnt[0]+cnt[K//2]*cnt[K//2]*cnt[K//2]); return rslt if __name__=="__main__" : N=3 ; K=2 ; print(NoofTriplets(N,K)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := 3; K := 2; ; execute (NoofTriplets(N, K))->display(); ) else skip; operation NoofTriplets(N : OclAny, K : OclAny) : OclAny pre: true post: true activity: var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, K); ; for i : Integer.subrange(1, N + 1-1) do ( cnt[i mod K+1] := cnt[i mod K+1] + 1;) ; if (MathLib.bitwiseAnd(K, 1)) then ( var rslt : double := cnt->first() * cnt->first() * cnt->first(); ; return rslt ) else ( rslt := (cnt->first() * cnt->first() * cnt->first() + cnt[K div 2+1] * cnt[K div 2+1] * cnt[K div 2+1]); ; return rslt ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printTwoSetBitNums(n): x=1 while(n>0): y=0 while(y 0) do ( var y : int := 0 ; while ((y->compareTo(x)) < 0) do ( execute ((1 * (2->pow(x))) + (1 * (2->pow(y))))->display() ; n := n - 1 ; if (n = 0) then ( return ) else skip ; y := y + 1) ; x := x + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def KnapSack(val,wt,n,W): dp=[0]*(W+1); for i in range(n): for j in range(W,wt[i],-1): dp[j]=max(dp[j],val[i]+dp[j-wt[i]]); return dp[W]; val=[7,8,4]; wt=[3,8,6]; W=10 ; n=3 ; print(KnapSack(val,wt,n,W)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; val := Sequence{7}->union(Sequence{8}->union(Sequence{ 4 })); ; wt := Sequence{3}->union(Sequence{8}->union(Sequence{ 6 })); ; W := 10; n := 3; ; execute (KnapSack(val, wt, n, W))->display();; operation KnapSack(val : OclAny, wt : OclAny, n : OclAny, W : OclAny) pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (W + 1)); ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(wt[i+1] + 1, W)->reverse() do ( dp[j+1] := Set{dp[j+1], val[i+1] + dp[j - wt[i+1]+1]}->max();)) ; return dp[W+1];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def twoEggDrop(k): return mt.ceil((-1.0+mt.sqrt(1+8*k))/2) k=100 print(twoEggDrop(k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; k := 100 ; execute (twoEggDrop(k))->display(); operation twoEggDrop(k : OclAny) : OclAny pre: true post: true activity: return mt.ceil((-1.0 + mt.sqrt(1 + 8 * k)) / 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,x,m=map(int,input().split(' ')) L,R=x,x for _ in range(m): l,r=map(int,input().split(' ')) if not(RtoInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; var m : OclAny := null; Sequence{n,x,m} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var L : OclAny := null; var R : OclAny := null; Sequence{L,R} := Sequence{x,x} ; for _anon : Integer.subrange(0, m-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; if not(((R->compareTo(l)) < 0 or (r->compareTo(L)) < 0)) then ( var L : OclAny := null; var R : OclAny := null; Sequence{L,R} := Sequence{Set{L, l}->min(),Set{R, r}->max()} ) else skip) ; execute (R - L + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) b=n-1 s=set() for i in range(n): x=input() if x[i]!=x[b]or len(set(x))!=2 : print("NO") exit() for j in range(n): s.add(x[j]) if len(s)>2 : print("NO") exit() if j!=i and j!=b : if x[i]==x[j]: print("NO") exit() b-=1 print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : double := n - 1 ; var s : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( var x : String := (OclFile["System.in"]).readLine() ; if x[i+1] /= x[b+1] or (Set{}->union((x)))->size() /= 2 then ( execute ("NO")->display() ; exit() ) else skip ; for j : Integer.subrange(0, n-1) do ( execute ((x[j+1]) : s) ; if (s)->size() > 2 then ( execute ("NO")->display() ; exit() ) else skip ; if j /= i & j /= b then ( if x[i+1] = x[j+1] then ( execute ("NO")->display() ; exit() ) else skip ) else skip) ; b := b - 1) ; execute ("YES")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(x)for x in input().split()] a.sort() inf=10**18 if n<=2 : print(a[0]-1) else : ans=sum(a)-n for x in range(1,10**9): curPow=1 curCost=0 for i in range(n): curCost+=abs(a[i]-curPow) curPow*=x if curPow>inf : break if curPow>inf : break if curPow/x>ans+a[n-1]: break ans=min(ans,curCost) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; a := a->sort() ; var Math_PINFINITY : double := (10)->pow(18) ; if n <= 2 then ( execute (a->first() - 1)->display() ) else ( var ans : double := (a)->sum() - n ; for x : Integer.subrange(1, (10)->pow(9)-1) do ( var curPow : int := 1 ; var curCost : int := 0 ; for i : Integer.subrange(0, n-1) do ( curCost := curCost + (a[i+1] - curPow)->abs() ; curPow := curPow * x ; if (curPow->compareTo(Math_PINFINITY)) > 0 then ( break ) else skip) ; if (curPow->compareTo(Math_PINFINITY)) > 0 then ( break ) else skip ; if (curPow / x->compareTo(ans + a[n - 1+1])) > 0 then ( break ) else skip ; ans := Set{ans, curCost}->min()) ; execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def nextPerfectSquare(N): nextN=math.floor(math.sqrt(N))+1 return nextN*nextN if __name__=='__main__' : N=35 print(nextPerfectSquare(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( N := 35 ; execute (nextPerfectSquare(N))->display() ) else skip; operation nextPerfectSquare(N : OclAny) : OclAny pre: true post: true activity: var nextN : double := ((N)->sqrt())->floor() + 1 ; return nextN * nextN; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) print(a//b,a % b,"%.9f" %(a/b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (a div b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=input().split() a,b=int(a),int(b) d=a//b r=a % b f=a/b print(d,r,"{0:.5f}".format(f)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{("" + ((a)))->toInteger(),("" + ((b)))->toInteger()} ; var d : int := a div b ; var r : int := a mod b ; var f : double := a / b ; execute (d)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : a,b=map(int,input().split()) d,r,f=a/b,a % b,float(a/b) print("%d %d %0.5f" %(d,r,f)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : OclAny := null; var r : OclAny := null; var f : OclAny := null; Sequence{d,r,f} := Sequence{a / b,a mod b,("" + ((a / b)))->toReal()} ; execute (StringLib.format("%d %d %0.5f",Sequence{d, r, f}))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=input().split() a,b=int(l[0]),int(l[1]) print(f"{a//b}{a%b}{a/b:.5f}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := input().split() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{("" + ((l->first())))->toInteger(),("" + ((l[1+1])))->toInteger()} ; execute (StringLib.formattedString("{a//b}{a%b}{a/b:.5f}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=list(map(int,input().split())) print("%d %d %.10f" %(a//b,a % b,a/b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (StringLib.format("%d %d %.10f",Sequence{a div b, a mod b, a / b}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def getArea(base,hypotenuse): height=math.sqrt(hypotenuse*hypotenuse-base*base); return 0.5*base*height def printRightAngleTriangle(hypotenuse,area): hsquare=hypotenuse*hypotenuse sideForMaxArea=math.sqrt(hsquare/2.0) maxArea=getArea(sideForMaxArea,hypotenuse) if(area>maxArea): print("Not possiblen") return low=0.0 high=sideForMaxArea while(abs(high-low)>1e-6): base=(low+high)/2.0 if(getArea(base,hypotenuse)>=area): high=base else : low=base height=math.ceil(math.sqrt(hsquare-base*base)) base=math.floor(base) print(base,height) if __name__=='__main__' : hypotenuse=5 area=6 printRightAngleTriangle(hypotenuse,area) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( hypotenuse := 5 ; area := 6 ; printRightAngleTriangle(hypotenuse, area) ) else skip; operation getArea(base : OclAny, hypotenuse : OclAny) : OclAny pre: true post: true activity: var height : double := (hypotenuse * hypotenuse - base * base)->sqrt(); ; return 0.5 * base * height; operation printRightAngleTriangle(hypotenuse : OclAny, area : OclAny) pre: true post: true activity: var hsquare : double := hypotenuse * hypotenuse ; var sideForMaxArea : double := (hsquare / 2.0)->sqrt() ; var maxArea : OclAny := getArea(sideForMaxArea, hypotenuse) ; if ((area->compareTo(maxArea)) > 0) then ( execute ("Not possiblen")->display() ; return ) else skip ; var low : double := 0.0 ; var high : OclAny := sideForMaxArea ; while ((high - low)->abs() > ("1e-6")->toReal()) do ( base := (low + high) / 2.0 ; if ((getArea(base, hypotenuse)->compareTo(area)) >= 0) then ( high := base ) else ( low := base )) ; height := ((hsquare - base * base)->sqrt())->ceil() ; base := (base)->floor() ; execute (base)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=3 MAX=60 dp=[[[0 for i in range(30)]for i in range(30)]for i in range(MAX+1)] v=[[[0 for i in range(30)]for i in range(30)]for i in range(MAX+1)] def findCount(mat,i,j,m): if(i==0 and j==0): if(m==mat[0][0]): return 1 else : return 0 if(m<0): return 0 if(i<0 or j<0): return 0 if(v[i][j][m]>0): return dp[i][j][m] v[i][j][m]=True dp[i][j][m]=(findCount(mat,i-1,j,m-mat[i][j])+findCount(mat,i,j-1,m-mat[i][j])) return dp[i][j][m] mat=[[1,1,1],[1,1,1],[1,1,1]] m=5 print(findCount(mat,n-1,n-1,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := 3 ; var MAX : int := 60 ; var dp : Sequence := Integer.subrange(0, MAX + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, 30-1)->select(i | true)->collect(i | (Integer.subrange(0, 30-1)->select(i | true)->collect(i | (0)))))) ; var v : Sequence := Integer.subrange(0, MAX + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, 30-1)->select(i | true)->collect(i | (Integer.subrange(0, 30-1)->select(i | true)->collect(i | (0)))))) ; skip ; mat := Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))}->union(Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))}->union(Sequence{ Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })) })) ; m := 5 ; execute (findCount(mat, n - 1, n - 1, m))->display(); operation findCount(mat : OclAny, i : OclAny, j : OclAny, m : OclAny) : OclAny pre: true post: true activity: if (i = 0 & j = 0) then ( if (m = mat->first()->first()) then ( return 1 ) else ( return 0 ) ) else skip ; if (m < 0) then ( return 0 ) else skip ; if (i < 0 or j < 0) then ( return 0 ) else skip ; if (v[i+1][j+1][m+1] > 0) then ( return dp[i+1][j+1][m+1] ) else skip ; v[i+1][j+1][m+1] := true ; dp[i+1][j+1][m+1] := (findCount(mat, i - 1, j, m - mat[i+1][j+1]) + findCount(mat, i, j - 1, m - mat[i+1][j+1])) ; return dp[i+1][j+1][m+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline a=input()[:-1] b=input()[:-1] x=len(a) c,d=0,0 for i in range(x): if a[i]=='7' and b[i]=='4' : c+=1 if a[i]=='4' and b[i]=='7' : d+=1 print(min(c,d)+c-min(c,d)+d-min(c,d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var a : OclAny := input()->front() ; var b : OclAny := input()->front() ; var x : int := (a)->size() ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := Sequence{0,0} ; for i : Integer.subrange(0, x-1) do ( if a[i+1] = '7' & b[i+1] = '4' then ( c := c + 1 ) else skip ; if a[i+1] = '4' & b[i+1] = '7' then ( d := d + 1 ) else skip) ; execute (Set{c, d}->min() + c - Set{c, d}->min() + d - Set{c, d}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=[str(input())for i in range(n)] t=arr[0][0] u=arr[0][1] a=0 b=0 for j in range(n): for k in range(n): if arr[j][k]==t and arr[j][n-k-1]==t : a+=1 break for j in range(n): b+=arr[j].count(u) if a==n and b==n*n-n*2+1 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine()))))) ; var t : OclAny := arr->first()->first() ; var u : OclAny := arr->first()[1+1] ; var a : int := 0 ; var b : int := 0 ; for j : Integer.subrange(0, n-1) do ( for k : Integer.subrange(0, n-1) do ( if arr[j+1][k+1] = t & arr[j+1][n - k - 1+1] = t then ( a := a + 1 ; break ) else skip)) ; for j : Integer.subrange(0, n-1) do ( b := b + arr[j+1]->count(u)) ; if a = n & b = n * n - n * 2 + 1 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input(); b=input() c4,c7=0,0 for i in range(len(a)): if a[i]!=b[i]: if a[i]=='4' : c4+=1 else : c7+=1 print(max(c4,c7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine(); var b : String := (OclFile["System.in"]).readLine() ; var c4 : OclAny := null; var c7 : OclAny := null; Sequence{c4,c7} := Sequence{0,0} ; for i : Integer.subrange(0, (a)->size()-1) do ( if a[i+1] /= b[i+1] then ( if a[i+1] = '4' then ( c4 := c4 + 1 ) else ( c7 := c7 + 1 ) ) else skip) ; execute (Set{c4, c7}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(x)for x in input().split()] a.sort() inf=10**18 if n<=2 : print(a[0]-1) else : ans=sum(a)-n for x in range(1,10**9): curPow=1 curCost=0 for i in range(n): curCost+=abs(a[i]-curPow) curPow*=x if curPow>inf : break if curPow>inf : break if curPow/x>ans+a[n-1]: break ans=min(ans,curCost) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; a := a->sort() ; var Math_PINFINITY : double := (10)->pow(18) ; if n <= 2 then ( execute (a->first() - 1)->display() ) else ( var ans : double := (a)->sum() - n ; for x : Integer.subrange(1, (10)->pow(9)-1) do ( var curPow : int := 1 ; var curCost : int := 0 ; for i : Integer.subrange(0, n-1) do ( curCost := curCost + (a[i+1] - curPow)->abs() ; curPow := curPow * x ; if (curPow->compareTo(Math_PINFINITY)) > 0 then ( break ) else skip) ; if (curPow->compareTo(Math_PINFINITY)) > 0 then ( break ) else skip ; if (curPow / x->compareTo(ans + a[n - 1+1])) > 0 then ( break ) else skip ; ans := Set{ans, curCost}->min()) ; execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def solve(): a=list(input()) b=list(input()) n=len(a) seven_a=a.count('7') seven_b=b.count('7') if seven_a==seven_b : count=0 for i in range(n): if a[i]!=b[i]: count+=1 return count//2 count_s=0 count_f=0 for i in range(n): if a[i]=='7' and b[i]=='4' : count_s+=1 elif a[i]=='4' and b[i]=='7' : count_f+=1 return max(count_f,count_s) if __name__=='__main__' : print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( execute (solve())->display() ) else skip; operation solve() : OclAny pre: true post: true activity: var a : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var b : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var n : int := (a)->size() ; var seven_a : int := a->count('7') ; var seven_b : int := b->count('7') ; if seven_a = seven_b then ( var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( if a[i+1] /= b[i+1] then ( count := count + 1 ) else skip) ; return count div 2 ) else skip ; var count_s : int := 0 ; var count_f : int := 0 ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = '7' & b[i+1] = '4' then ( count_s := count_s + 1 ) else (if a[i+1] = '4' & b[i+1] = '7' then ( count_f := count_f + 1 ) else skip)) ; return Set{count_f, count_s}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=input(),input() l=[a[i]+b[i]for i in range(len(a))] print(max(l.count('47'),l.count('74'))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine()} ; var l : Sequence := Integer.subrange(0, (a)->size()-1)->select(i | true)->collect(i | (a[i+1] + b[i+1])) ; execute (Set{l->count('47'), l->count('74')}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input().rstrip() b=input().rstrip() n=len(a) p4=[] p7=[] for i in range(n): if a[i]!=b[i]: if a[i]=='7' : p7.append(i) else : p4.append(i) print(max(len(p4),len(p7))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := input().rstrip() ; var b : OclAny := input().rstrip() ; var n : int := (a)->size() ; var p4 : Sequence := Sequence{} ; var p7 : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if a[i+1] /= b[i+1] then ( if a[i+1] = '7' then ( execute ((i) : p7) ) else ( execute ((i) : p4) ) ) else skip) ; execute (Set{(p4)->size(), (p7)->size()}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline write=sys.stdout.write def solve(): A,B,P=map(int,readline().split()) if A==B==P==0 : return False N=(B-A+1) data=[0]*(N+1) def get(k): s=0 while k : s+=data[k] k-=k &-k return s % P *V,=range(A,B+1) V.sort(key=str) for v in V : k=v+1-A x=get(k)+1 while k<=N : data[k]+=x k+=k &-k write("%d\n" %(get(N)% P)) return True while solve(): ... ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var write : OclAny := (OclFile["System.out"]).write ; skip ; (testlist_star_expr (star_expr * (expr (atom (name V)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name V)))) ,)} := Integer.subrange(A, B + 1-1); operation solve() : OclAny pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var P : OclAny := null; Sequence{A,B,P} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if A = B & (B == P) & (P == 0) then ( return false ) else skip ; var N : double := (B - A + 1) ; var data : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNormal(A,x,y): dif=A-x*2 if(y==(2*x-x*x)): if(dif<0): print(0-dif,"y=","x",(0-x)+(y*dif)) elif(dif>0): print(dif,"y=","-x+",x+dif*y) else : print("x=",x) else : print("Not possible") if __name__=='__main__' : A=2 x=2 y=0 findNormal(A,x,y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( A := 2 ; x := 2 ; y := 0 ; findNormal(A, x, y) ) else skip; operation findNormal(A : OclAny, x : OclAny, y : OclAny) pre: true post: true activity: var dif : double := A - x * 2 ; if (y = (2 * x - x * x)) then ( if (dif < 0) then ( execute (0 - dif)->display() ) else (if (dif > 0) then ( execute (dif)->display() ) else ( execute ("x=")->display() ) ) ) else ( execute ("Not possible")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pattern(): k=0 spaces=1 n=7 for i in range(n,0,-1): for j in range(1,i+1): print(i,end="") if(i!=n): for k in range(1,spaces+1): print(end="") spaces=spaces+2 for j in range(i,0,-1): if(j!=n): print(i,end="") print() spaces=spaces-4 for i in range(2,n+1): for j in range(1,i+1): print(i,end="") if(i!=n): for k in range(1,spaces+1): print(end="") spaces=spaces-2 for j in range(i,0,-1): if(j!=n): print(i,end="") print() pattern() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; pattern(); operation pattern() pre: true post: true activity: var k : int := 0 ; var spaces : int := 1 ; var n : int := 7 ; for i : Integer.subrange(0 + 1, n)->reverse() do ( for j : Integer.subrange(1, i + 1-1) do ( execute (i)->display()) ; if (i /= n) then ( for k : Integer.subrange(1, spaces + 1-1) do ( execute ((argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom "")))))))->display()) ; spaces := spaces + 2 ) else skip ; for j : Integer.subrange(0 + 1, i)->reverse() do ( if (j /= n) then ( execute (i)->display() ) else skip) ; execute (->display()) ; spaces := spaces - 4 ; for i : Integer.subrange(2, n + 1-1) do ( for j : Integer.subrange(1, i + 1-1) do ( execute (i)->display()) ; if (i /= n) then ( for k : Integer.subrange(1, spaces + 1-1) do ( execute ((argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom "")))))))->display()) ; spaces := spaces - 2 ) else skip ; for j : Integer.subrange(0 + 1, i)->reverse() do ( if (j /= n) then ( execute (i)->display() ) else skip) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y,a,b,c=(int(x)for x in input().split()) list_p=list(map(int,input().split())) list_q=list(map(int,input().split())) list_r=list(map(int,input().split())) list_p.sort() list_q.sort() list_p.reverse() list_q.reverse() for i in range(x): list_r.append(list_p[i]) for i in range(y): list_r.append(list_q[i]) list_r.sort() list_r.reverse() sum=0 for i in range(x+y): sum+=list_r[i] print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{x,y,a,b,c} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var list_p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var list_q : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var list_r : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; list_p := list_p->sort() ; list_q := list_q->sort() ; list_p := list_p->reverse() ; list_q := list_q->reverse() ; for i : Integer.subrange(0, x-1) do ( execute ((list_p[i+1]) : list_r)) ; for i : Integer.subrange(0, y-1) do ( execute ((list_q[i+1]) : list_r)) ; list_r := list_r->sort() ; list_r := list_r->reverse() ; var sum : int := 0 ; for i : Integer.subrange(0, x + y-1) do ( sum := sum + list_r[i+1]) ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np X,Y,A,B,C=map(int,input().split()) p=np.array(tuple(map(int,input().split()))) q=np.array(tuple(map(int,input().split()))) r=np.array(tuple(map(int,input().split()))) p=np.partition(p,A-X) q=np.partition(q,B-Y) pqr=np.concatenate((p[-X :],q[-Y :],r)) pqr=np.partition(pqr,len(pqr)-(X+Y)) ans=sum(pqr[-(X+Y):]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var X : OclAny := null; var Y : OclAny := null; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{X,Y,A,B,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : Sequence := (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var q : Sequence := (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var r : Sequence := (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; p := ; q := ; var pqr : (trailer . (name concatenate) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr - (expr (atom (name X))))))) :)) ])))))) , (test (logical_test (comparison (expr (atom (name q)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr - (expr (atom (name Y))))))) :)) ])))))) , (test (logical_test (comparison (expr (atom (name r))))))) )))))))) ))) := ; pqr := ; var ans : OclAny := (pqr.subrange(-(X + Y)+1))->sum() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) my_set_diag=set() my_set_non_diag=set() for i in range(0,n): a=input() for j in range(0,n): if((i==j)|((i+j)==n-1)): my_set_diag.add(a[j]) else : my_set_non_diag.add(a[j]) flag=0 if((len(my_set_diag)==1)&(len(my_set_non_diag)==1)): if(my_set_diag!=my_set_non_diag): flag=1 if(flag==1): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var my_set_diag : Set := Set{}->union(()) ; var my_set_non_diag : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( var a : String := (OclFile["System.in"]).readLine() ; for j : Integer.subrange(0, n-1) do ( if (MathLib.bitwiseOr((i = j), ((i + j) = n - 1))) then ( execute ((a[j+1]) : my_set_diag) ) else ( execute ((a[j+1]) : my_set_non_diag) ))) ; var flag : int := 0 ; if (MathLib.bitwiseAnd(((my_set_diag)->size() = 1), ((my_set_non_diag)->size() = 1))) then ( if (my_set_diag /= my_set_non_diag) then ( flag := 1 ) else skip ) else skip ; if (flag = 1) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from pprint import pprint import sys sys.setrecursionlimit(10**6) X,Y,A,B,C=map(int,input().split()) apples_A=sorted(list(map(int,input().split()))) apples_B=sorted(list(map(int,input().split()))) apples_C=sorted(list(map(int,input().split()))) apples_rest=sorted(apples_A[-X :]+apples_B[-Y :]+apples_C) ans=sum(apples_rest[-(X+Y):]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(6)) ; var X : OclAny := null; var Y : OclAny := null; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{X,Y,A,B,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var apples_A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var apples_B : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var apples_C : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var apples_rest : Sequence := apples_A.subrange(-X+1) + apples_B.subrange(-Y+1)->union(apples_C)->sort() ; var ans : OclAny := (apples_rest.subrange(-(X + Y)+1))->sum() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def merge(A,B): C=[] i=0 j=0 while iB[j]: C.append(A[i]) i+=1 else : C.append(B[j]) j+=1 if len(A)-i>len(B)-j : C.extend(A[i :]) else : C.extend(B[j :]) return C X,Y,A,B,C=map(int,input().split()) P=list(map(int,input().split())) Q=list(map(int,input().split())) R=list(map(int,input().split())) P.sort(reverse=True) Q.sort(reverse=True) R.sort(reverse=True) S=merge(P[: X],Q[: Y]) S=merge(S,R) score=0 for i in range(X+Y): score+=S[i] print(score) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var X : OclAny := null; var Y : OclAny := null; Sequence{X,Y,A,B,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var P : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var Q : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var R : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; P := P->sort() ; Q := Q->sort() ; R := R->sort() ; var S : OclAny := merge(P.subrange(1,X), Q.subrange(1,Y)) ; S := merge(S, R) ; var score : int := 0 ; for i : Integer.subrange(0, X + Y-1) do ( score := score + S[i+1]) ; execute (score)->display(); operation merge(A : OclAny, B : OclAny) : OclAny pre: true post: true activity: var C : Sequence := Sequence{} ; var i : int := 0 ; var j : int := 0 ; while (i->compareTo((A)->size())) < 0 & (j->compareTo((B)->size())) < 0 do ( if (A[i+1]->compareTo(B[j+1])) > 0 then ( execute ((A[i+1]) : C) ; i := i + 1 ) else ( execute ((B[j+1]) : C) ; j := j + 1 )) ; if ((A)->size() - i->compareTo((B)->size() - j)) > 0 then ( C := C->union(A.subrange(i+1)) ) else ( C := C->union(B.subrange(j+1)) ) ; return C; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=map(int,input().split()) a=list(sorted(a)) if n>=60 : print(sum(a)-n) else : min_dif=-1 for c in range(1,10**6): dif=0 for i in range(len(a)): dif+=abs(c**i-a[i]) if diftoInteger() ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := (a->sort()) ; if n >= 60 then ( execute ((a)->sum() - n)->display() ) else ( var min_dif : int := -1 ; for c : Integer.subrange(1, (10)->pow(6)-1) do ( var dif : int := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( dif := dif + ((c)->pow(i) - a[i+1])->abs()) ; if (dif->compareTo(min_dif)) < 0 or min_dif = -1 then ( min_dif := dif ) else ( break )) ; execute (min_dif)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque X,Y,A,B,C=map(int,input().split()) P=[int(n)for n in input().split()] Q=[int(n)for n in input().split()] R=[int(n)for n in input().split()] P.sort() Q.sort() R.sort(reverse=True) PQ=deque(sorted(P[-X :]+Q[-Y :])) R=deque(R) while True : if not R or R[0]<=PQ[0]: break if R[0]>PQ[0]: PQ.append(R.popleft()) PQ.popleft() print(sum(PQ)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var X : OclAny := null; var Y : OclAny := null; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{X,Y,A,B,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var P : Sequence := input().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; var Q : Sequence := input().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; var R : Sequence := input().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; P := P->sort() ; Q := Q->sort() ; R := R->sort() ; var PQ : Sequence := (P.subrange(-X+1) + Q.subrange(-Y+1)->sort()) ; R := (R) ; while true do ( if not(R) or (R->first()->compareTo(PQ->first())) <= 0 then ( break ) else skip ; if (R->first()->compareTo(PQ->first())) > 0 then ( execute ((R->first()) : PQ) ; PQ := PQ->tail() ) else skip) ; execute ((PQ)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def answer(n): m=2 ; ans=1 ; r=1 ; while rdisplay();; operation answer(n : OclAny) pre: true post: true activity: var m : int := 2; ; var ans : int := 1; ; var r : int := 1; ; while (r->compareTo(n)) < 0 do ( r := (OclType["int"])(((2)->pow(m) - 1) * ((2)->pow(m - 1))); ; if (r->compareTo(n)) < 0 then ( ans := r; ) else skip ; m := m + 1;) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def next_permutation(L): n=len(L) i=n-2 while i>=0 and L[i]>=L[i+1]: i-=1 if i==-1 : return False j=i+1 while jL[i]: j+=1 j-=1 L[i],L[j]=L[j],L[i] left=i+1 right=n-1 while leftsize() ; var i : double := n - 2 ; while i >= 0 & (L[i+1]->compareTo(L[i + 1+1])) >= 0 do ( i := i - 1) ; if i = -1 then ( return false ) else skip ; var j : OclAny := i + 1 ; while (j->compareTo(n)) < 0 & (L[j+1]->compareTo(L[i+1])) > 0 do ( j := j + 1) ; j := j - 1 ; var L[i+1] : OclAny := null; var L[j+1] : OclAny := null; Sequence{L[i+1],L[j+1]} := Sequence{L[j+1],L[i+1]} ; var left : OclAny := i + 1 ; var right : double := n - 1 ; while (left->compareTo(right)) < 0 do ( var L[left+1] : OclAny := null; var L[right+1] : OclAny := null; Sequence{L[left+1],L[right+1]} := Sequence{L[right+1],L[left+1]} ; left := left + 1 ; right := right - 1) ; return true; operation nPermute(string : OclAny, n : OclAny) pre: true post: true activity: string := (string)->characters() ; var new_string : Sequence := Sequence{} ; string := string->sort() ; j := 2 ; while next_permutation(string) do ( new_string := string ; if j = n then ( break ) else skip ; j := j + 1) ; execute (StringLib.sumStringsWithSeparator((new_string), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,copy HUGE=2147483647 HUGEL=9223372036854775807 ABC="abcdefghijklmnopqrstuvwxyz" def main(): h,w=map(int,input().split()) su=0 for i in range(h): line=input() su+=line.count("#") print("Possible" if su==h+w-1 else "Impossible") main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var HUGE : int := 2147483647 ; var HUGEL : int := 9223372036854775807 ; var ABC : String := "abcdefghijklmnopqrstuvwxyz" ; skip ; main(); operation main() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var su : int := 0 ; for i : Integer.subrange(0, h-1) do ( var line : String := (OclFile["System.in"]).readLine() ; su := su + line->count("#")) ; execute (if su = h + w - 1 then "Possible" else "Impossible" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin ri=lambda : int(rs()) rl=lambda : list(map(int,stdin.readline().split())) rs=lambda : stdin.readline().rstrip() H,W=rl() A=[list(rs())for _ in range(H)] for i in range(H): for j in range(W): if A[i][j]=='#' : A[i][j]=1 else : A[i][j]=0 A[i].append(0) A.append([0]*(W+1)) bool=True for i in range(H): for j in range(W): if i==0 and j==0 : if A[i+1][j]+A[i][j+1]!=1 : bool=False continue if i==H-1 and j==W-1 : if A[i-1][j]+A[i][j-1]!=1 : bool=False continue if A[i][j]==1 : if A[i+1][j]+A[i][j+1]!=1 : bool=False if A[i-1][j]+A[i][j-1]!=1 : bool=False print('Possible' if bool else 'Impossible') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stdin : OclFile := OclFile["System.in"] ; var ri : Function := lambda $$ : OclAny in (("" + ((rs())))->toInteger()) ; var rl : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var rs : Function := lambda $$ : OclAny in (stdin.readLine().rstrip()) ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := rl->apply() ; var A : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | ((rs->apply()))) ; for i : Integer.subrange(0, H-1) do ( for j : Integer.subrange(0, W-1) do ( if A[i+1][j+1] = '#' then ( A[i+1][j+1] := 1 ) else ( A[i+1][j+1] := 0 )) ; (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))))) ; execute ((MatrixLib.elementwiseMult(Sequence{ 0 }, (W + 1))) : A) ; var OclType["boolean"] : boolean := true ; for i : Integer.subrange(0, H-1) do ( for j : Integer.subrange(0, W-1) do ( if i = 0 & j = 0 then ( if A[i + 1+1][j+1] + A[i+1][j + 1+1] /= 1 then ( OclType["boolean"] := false ) else skip ; continue ) else skip ; if i = H - 1 & j = W - 1 then ( if A[i - 1+1][j+1] + A[i+1][j - 1+1] /= 1 then ( OclType["boolean"] := false ) else skip ; continue ) else skip ; if A[i+1][j+1] = 1 then ( if A[i + 1+1][j+1] + A[i+1][j + 1+1] /= 1 then ( OclType["boolean"] := false ) else skip ; if A[i - 1+1][j+1] + A[i+1][j - 1+1] /= 1 then ( OclType["boolean"] := false ) else skip ) else skip)) ; execute (if OclType["boolean"] then 'Possible' else 'Impossible' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin h,w=map(int,stdin.readline().rstrip().split()) a=[stdin.readline().rstrip()for i in range(h)] count=0 for i in a : for j in i : if j=='#' : count+=1 if h+w-1==count : print('Possible') else : print('Impossible') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, h-1)->select(i | true)->collect(i | (stdin.readLine().rstrip())) ; var count : int := 0 ; for i : a do ( for j : i do ( if j = '#' then ( count := count + 1 ) else skip)) ; if h + w - 1 = count then ( execute ('Possible')->display() ) else ( execute ('Impossible')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): h,w=map(int,input().split()) a=[["." for j in range(w+2)]for i in range(h+2)] for i in range(h): s=list(input().rstrip()) for j in range(w): a[i+1][j+1]=s[j] y,x=1,1 f=True while y!=h or x!=w : a[y][x]="." if a[y-1][x]=="#" or a[y][x-1]=="#" or(a[y+1][x]=="#" and a[y][x+1]=="#"): f=False break else : if a[y+1][x]=="#" : y+=1 else : x+=1 if a[y-1][x]=="#" or a[y][x-1]=="#" : f=False if f : print("Possible") else : print("Impossible") if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, h + 2-1)->select(i | true)->collect(i | (Integer.subrange(0, w + 2-1)->select(j | true)->collect(j | (".")))) ; for i : Integer.subrange(0, h-1) do ( var s : Sequence := (input().rstrip()) ; for j : Integer.subrange(0, w-1) do ( a[i + 1+1][j + 1+1] := s[j+1])) ; var y : OclAny := null; var x : OclAny := null; Sequence{y,x} := Sequence{1,1} ; var f : boolean := true ; while y /= h or x /= w do ( a[y+1][x+1] := "." ; if a[y - 1+1][x+1] = "#" or a[y+1][x - 1+1] = "#" or (a[y + 1+1][x+1] = "#" & a[y+1][x + 1+1] = "#") then ( f := false ; break ) else ( if a[y + 1+1][x+1] = "#" then ( y := y + 1 ) else ( x := x + 1 ) )) ; if a[y - 1+1][x+1] = "#" or a[y+1][x - 1+1] = "#" then ( f := false ) else skip ; if f then ( execute ("Possible")->display() ) else ( execute ("Impossible")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[] check=1 s=input() if len(set(s))!=2 : check=0 else : if s.count(s[0])!=2 : check=0 else : if s[0]!=s[-1]: check=0 a=list(set(s)) a.sort() for i in range(1,n): s1=input() if len(set(s1))!=2 : check=0 else : if i*2+1==n : if s1.count(s[0])!=1 : check=0 else : if sorted(list(set(s1)))!=a : check=0 else : if s1.count(s[0])!=2 : check=0 else : if sorted(list(set(s1)))!=a : check=0 if check==1 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; var check : int := 1 ; var s : String := (OclFile["System.in"]).readLine() ; if (Set{}->union((s)))->size() /= 2 then ( check := 0 ) else ( if s->count(s->first()) /= 2 then ( check := 0 ) else ( if s->first() /= s->last() then ( check := 0 ) else skip ) ) ; a := (Set{}->union((s))) ; a := a->sort() ; for i : Integer.subrange(1, n-1) do ( var s1 : String := (OclFile["System.in"]).readLine() ; if (Set{}->union((s1)))->size() /= 2 then ( check := 0 ) else ( if i * 2 + 1 = n then ( if s1->count(s->first()) /= 1 then ( check := 0 ) else ( if (Set{}->union((s1)))->sort() /= a then ( check := 0 ) else skip ) ) else ( if s1->count(s->first()) /= 2 then ( check := 0 ) else ( if (Set{}->union((s1)))->sort() /= a then ( check := 0 ) else skip ) ) )) ; if check = 1 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def resolve(): import collections H,W=[int(item)for item in input().split()] grid=[[item for item in input()]for _ in range(H)] cnt=0 for line in grid : for i in line : if i=='#' : cnt+=1 if cnt>H+W-1 : print('Impossible') else : print('Possible') if __name__=="__main__" : resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( resolve() ) else skip; operation resolve() pre: true post: true activity: skip ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := input().split()->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; var grid : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine()->select(item | true)->collect(item | (item)))) ; var cnt : int := 0 ; for line : grid do ( for i : line do ( if i = '#' then ( cnt := cnt + 1 ) else skip)) ; if (cnt->compareTo(H + W - 1)) > 0 then ( execute ('Impossible')->display() ) else ( execute ('Possible')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): LENGTH=50 return str(sum(count_ways(LENGTH,i)for i in range(2,5))) def count_ways(length,m): ways=[1]+[0]*length for n in range(1,len(ways)): ways[n]+=ways[n-1] if n>=m : ways[n]+=ways[n-m] return ways[-1]-1 if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LENGTH : int := 50 ; return ("" + ((((argument (test (logical_test (comparison (expr (atom (name count_ways)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name LENGTH))))))) , (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 5))))))))) )))))))))->sum()))); operation count_ways(length : OclAny, m : OclAny) : OclAny pre: true post: true activity: var ways : Sequence := Sequence{ 1 }->union(MatrixLib.elementwiseMult(Sequence{ 0 }, length)) ; for n : Integer.subrange(1, (ways)->size()-1) do ( ways[n+1] := ways[n+1] + ways[n - 1+1] ; if (n->compareTo(m)) >= 0 then ( ways[n+1] := ways[n+1] + ways[n - m+1] ) else skip) ; return ways->last() - 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(arr,n): k=-10**9 r=10**9 for i in range(n): k=max(k,arr[i]) r=min(r,arr[i]) k+=1 for i in range(n): arr[i]=k-arr[i] for i in range(n): if(abs(arr[i])-10): arr[abs(arr[i])-1]=-arr[abs(arr[i])-1] flag=0 for i in range(k-r): if(arr[i]>0): flag=1 break return flag==0 arr=[5,2,3,6,4,4,6,6] n=len(arr) if(check(arr,n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{5}->union(Sequence{2}->union(Sequence{3}->union(Sequence{6}->union(Sequence{4}->union(Sequence{4}->union(Sequence{6}->union(Sequence{ 6 }))))))) ; n := (arr)->size() ; if (check(arr, n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation check(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var k : double := (-10)->pow(9) ; var r : double := (10)->pow(9) ; for i : Integer.subrange(0, n-1) do ( k := Set{k, arr[i+1]}->max() ; r := Set{r, arr[i+1]}->min()) ; k := k + 1 ; for i : Integer.subrange(0, n-1) do ( arr[i+1] := k - arr[i+1]) ; for i : Integer.subrange(0, n-1) do ( if (((arr[i+1])->abs() - 1->compareTo(n)) < 0 & arr[(arr[i+1])->abs() - 1+1] > 0) then ( arr[(arr[i+1])->abs() - 1+1] := -arr[(arr[i+1])->abs() - 1+1] ) else skip) ; var flag : int := 0 ; for i : Integer.subrange(0, k - r-1) do ( if (arr[i+1] > 0) then ( flag := 1 ; break ) else skip) ; return flag = 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) a=list(map(int,input().split())) a.sort() k=math.floor(pow(a[-1],1/(len(a)-1))) a1=0 for i in range(0,n): a1+=abs(k**i-a[i]) k+=1 a2=a1 if n<40 : a2=0 for i in range(0,n): a2+=abs(k**i-a[i]) print(min(a1,a2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var k : double := ((a->last())->pow(1 / ((a)->size() - 1)))->floor() ; var a1 : int := 0 ; for i : Integer.subrange(0, n-1) do ( a1 := a1 + ((k)->pow(i) - a[i+1])->abs()) ; k := k + 1 ; var a2 : int := a1 ; if n < 40 then ( a2 := 0 ; for i : Integer.subrange(0, n-1) do ( a2 := a2 + ((k)->pow(i) - a[i+1])->abs()) ) else skip ; execute (Set{a1, a2}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def power(x,y): if(y==0): return 1 elif(y % 2==0): return(power(x,y//2)*power(x,y//2)) else : return(x*power(x,y//2)*power(x,y//2)) def sieveOfEratosthenes(n,isPrime): isPrime[0]=isPrime[1]=False for i in range(2,n+1): isPrime[i]=True p=2 while(p*p<=n): if(isPrime[p]==True): i=p*2 while(i<=n): isPrime[i]=False i=i+p p=p+1 def leftTruPrime(n): temp=n cnt=0 while(temp!=0): cnt=cnt+1 temp1=temp % 10 ; if(temp1==0): return False temp=temp//10 isPrime=[None]*(n+1) sieveOfEratosthenes(n,isPrime) for i in range(cnt,0,-1): mod=power(10,i) if(isPrime[n % mod]!=True): return False return True n=113 if(leftTruPrime(n)): print(n,"is left truncatable prime") else : print(n,"is not left truncatable prime") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 113 ; if (leftTruPrime(n)) then ( execute (n)->display() ) else ( execute (n)->display() ); operation power(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (y = 0) then ( return 1 ) else (if (y mod 2 = 0) then ( return (power(x, y div 2) * power(x, y div 2)) ) else ( return (x * power(x, y div 2) * power(x, y div 2)) ) ) ; operation sieveOfEratosthenes(n : OclAny, isPrime : OclAny) pre: true post: true activity: isPrime->first() := false; var isPrime[1+1] : boolean := false ; for i : Integer.subrange(2, n + 1-1) do ( isPrime[i+1] := true) ; var p : int := 2 ; while ((p * p->compareTo(n)) <= 0) do ( if (isPrime[p+1] = true) then ( var i : int := p * 2 ; while ((i->compareTo(n)) <= 0) do ( isPrime[i+1] := false ; i := i + p) ) else skip ; p := p + 1); operation leftTruPrime(n : OclAny) : OclAny pre: true post: true activity: var temp : OclAny := n ; var cnt : int := 0 ; while (temp /= 0) do ( cnt := cnt + 1 ; var temp1 : int := temp mod 10; ; if (temp1 = 0) then ( return false ) else skip ; temp := temp div 10) ; isPrime := MatrixLib.elementwiseMult(Sequence{ null }, (n + 1)) ; sieveOfEratosthenes(n, isPrime) ; for i : Integer.subrange(0 + 1, cnt)->reverse() do ( var mod : OclAny := power(10, i) ; if (isPrime[n mod mod+1] /= true) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minReplacement(s,length): ans=0 for i in range(0,length): if i % 2==0 and s[i]=='1' : ans+=1 if i % 2==1 and s[i]=='0' : ans+=1 return min(ans,length-ans) if __name__=="__main__" : s="1100" length=len(s) print(minReplacement(s,length)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "1100" ; length := (s)->size() ; execute (minReplacement(s, length))->display() ) else skip; operation minReplacement(s : OclAny, length : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, length-1) do ( if i mod 2 = 0 & s[i+1] = '1' then ( ans := ans + 1 ) else skip ; if i mod 2 = 1 & s[i+1] = '0' then ( ans := ans + 1 ) else skip) ; return Set{ans, length - ans}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def right_left(a,n): total=dict.fromkeys(a,0); left=dict.fromkeys(a,0); for i in range(n): if a[i]not in total : total[a[i]]=1 total[a[i]]+=1 ; for i in range(n): print(total[a[i]]-1-(2*left[a[i]]),end=" "); left[a[i]]+=1 ; if __name__=="__main__" : a=[1,2,3,2,1]; n=len(a); right_left(a,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 1 })))); ; n := (a)->size(); ; right_left(a, n); ) else skip; operation right_left(a : OclAny, n : OclAny) pre: true post: true activity: var total : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))); ; var left : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))); ; for i : Integer.subrange(0, n-1) do ( if (total)->excludes(a[i+1]) then ( total[a[i+1]+1] := 1 ) else skip ; total[a[i+1]+1] := total[a[i+1]+1] + 1;) ; for i : Integer.subrange(0, n-1) do ( execute (total[a[i+1]+1] - 1 - (2 * left[a[i+1]+1]))->display(); ; left[a[i+1]+1] := left[a[i+1]+1] + 1;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin N=int(input()) A=[int(x)for x in stdin.readline().split(' ')] cnt=0 for i in range(N-1): for j in range(0,N-1-i): if(A[j]>A[j+1]): A[j],A[j+1]=(A[j+1],A[j]) cnt+=1 print(' '.join(map(str,A))) print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := stdin.readLine().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var cnt : int := 0 ; for i : Integer.subrange(0, N - 1-1) do ( for j : Integer.subrange(0, N - 1 - i-1) do ( if ((A[j+1]->compareTo(A[j + 1+1])) > 0) then ( var A[j+1] : OclAny := null; var A[j + 1+1] : OclAny := null; Sequence{A[j+1],A[j + 1+1]} := Sequence{A[j + 1+1], A[j+1]} ; cnt := cnt + 1 ) else skip)) ; execute (StringLib.sumStringsWithSeparator(((A)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N=int(input()) A=list(map(int,input().split())) bubbleSort(A,N) def bubbleSort(A,N): flag=1 i=0 while flag : flag=0 for j in range(N-1,0,-1): if A[j]toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; bubbleSort(A, N); operation bubbleSort(A : OclAny, N : OclAny) pre: true post: true activity: var flag : int := 1 ; var i : int := 0 ; while flag do ( flag := 0 ; for j : Integer.subrange(0 + 1, N - 1)->reverse() do ( if (A[j+1]->compareTo(A[j - 1+1])) < 0 then ( var A[j+1] : OclAny := null; var A[j - 1+1] : OclAny := null; Sequence{A[j+1],A[j - 1+1]} := Sequence{A[j - 1+1],A[j+1]} ; flag := 1 ; i := i + 1 ) else skip)) ; execute (StringLib.sumStringsWithSeparator(((A)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ; execute (i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : n=int(input()) num=[int(i)for i in input().split()] flag=1 count=0 while flag!=0 : flag=0 rev=list(range(1,n)) rev.reverse() for j in rev : if num[j]toInteger() ; var num : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var flag : int := 1 ; var count : int := 0 ; while flag /= 0 do ( flag := 0 ; var rev : Sequence := (Integer.subrange(1, n-1)) ; rev := rev->reverse() ; for j : rev do ( if (num[j+1]->compareTo(num[j - 1+1])) < 0 then ( var tmp : OclAny := num[j+1] ; num[j+1] := num[j - 1+1] ; num[j - 1+1] := tmp ; flag := 1 ; count := count + 1 ) else skip)) ; for i : Integer.subrange(0, n-1) do ( if i /= n - 1 then ( execute (StringLib.format("%d",(num[i+1])))->display() ) else ( execute (StringLib.format("%d",(num[i+1])))->display() )) ; execute (count)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re import sys for s in sys.stdin : print(re.sub(r"@(\d)(.)",lambda m : m.group(2)*int(m.group(1)),s.rstrip())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for s : OclFile["System.in"] do ( execute ((StringLib.rightTrim(s)).replaceAllMatches(StringLib.rawString("@(\d)(.)"), lambda m : OclAny in (m.group(2) * ("" + ((m.group(1))))->toInteger())))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() nums=input() nums=nums.split() nums=list(map(int,nums)) cnt=0 for i in range(int(n)-1): for j in range(int(n)-1): if nums[j]>nums[j+1]: tmp=nums[j+1] nums[j+1]=nums[j] nums[j]=tmp cnt+=1 print(' '.join(map(str,nums))) print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var nums : String := (OclFile["System.in"]).readLine() ; nums := nums.split() ; nums := ((nums)->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : int := 0 ; for i : Integer.subrange(0, ("" + ((n)))->toInteger() - 1-1) do ( for j : Integer.subrange(0, ("" + ((n)))->toInteger() - 1-1) do ( if (nums[j+1]->compareTo(nums[j + 1+1])) > 0 then ( var tmp : OclAny := nums[j + 1+1] ; nums[j + 1+1] := nums[j+1] ; nums[j+1] := tmp ; cnt := cnt + 1 ) else skip)) ; execute (StringLib.sumStringsWithSeparator(((nums)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=list(map(int,input().split())) def bubble_sort(A,N): cnt=0 flag=True while(flag): flag=False for i in range(N-1,0,-1): if(A[i-1]>A[i]): tmp=A[i-1] A[i-1]=A[i] A[i]=tmp cnt+=1 flag=True print(" ".join(list(map(str,A)))) print(cnt) bubble_sort(A,N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; bubble_sort(A, N); operation bubble_sort(A : OclAny, N : OclAny) pre: true post: true activity: var cnt : int := 0 ; var flag : boolean := true ; while (flag) do ( flag := false ; for i : Integer.subrange(0 + 1, N - 1)->reverse() do ( if ((A[i - 1+1]->compareTo(A[i+1])) > 0) then ( var tmp : OclAny := A[i - 1+1] ; A[i - 1+1] := A[i+1] ; A[i+1] := tmp ; cnt := cnt + 1 ; flag := true ) else skip)) ; execute (StringLib.sumStringsWithSeparator((((A)->collect( _x | (OclType["String"])->apply(_x) ))), " "))->display() ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPattern(n,pat): pattern_int=0 power_two=1 all_ones=0 i=len(pat)-1 while(i>=0): current_bit=ord(pat[i])-ord('0') pattern_int+=(power_two*current_bit) all_ones=all_ones+power_two power_two=power_two*2 i-=1 count=0 while(n!=0 and n>=pattern_int): if((n & all_ones)==pattern_int): count+=1 n=n>>1 return count if __name__=='__main__' : n=500 pat="10" print(countPattern(n,pat)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 500 ; pat := "10" ; execute (countPattern(n, pat))->display() ) else skip; operation countPattern(n : OclAny, pat : OclAny) : OclAny pre: true post: true activity: var pattern_int : int := 0 ; var power_two : int := 1 ; var all_ones : int := 0 ; var i : double := (pat)->size() - 1 ; while (i >= 0) do ( var current_bit : double := (pat[i+1])->char2byte() - ('0')->char2byte() ; pattern_int := pattern_int + (power_two * current_bit) ; all_ones := all_ones + power_two ; power_two := power_two * 2 ; i := i - 1) ; var count : int := 0 ; while (n /= 0 & (n->compareTo(pattern_int)) >= 0) do ( if ((MathLib.bitwiseAnd(n, all_ones)) = pattern_int) then ( count := count + 1 ) else skip ; n := n /(2->pow(1))) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,m=[int(i)for i in input().split("")] a=[int(u)for u in input().split("")] hash_a=[0 for i in range(n+2)] counters=[0 for i in range(2*m)] collector=[] for i in range(len(a)): hash_a[a[i]]+=1 counters[hash_a[a[i]]]+=1 if counters[hash_a[a[i]]]==n : collector.append("1") else : collector.append("0") print("".join(collector)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split("")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a : Sequence := input().split("")->select(u | true)->collect(u | (("" + ((u)))->toInteger())) ; var hash_a : Sequence := Integer.subrange(0, n + 2-1)->select(i | true)->collect(i | (0)) ; var counters : Sequence := Integer.subrange(0, 2 * m-1)->select(i | true)->collect(i | (0)) ; var collector : Sequence := Sequence{} ; for i : Integer.subrange(0, (a)->size()-1) do ( hash_a[a[i+1]+1] := hash_a[a[i+1]+1] + 1 ; counters[hash_a[a[i+1]+1]+1] := counters[hash_a[a[i+1]+1]+1] + 1 ; if counters[hash_a[a[i+1]+1]+1] = n then ( execute (("1") : collector) ) else ( execute (("0") : collector) )) ; execute (StringLib.sumStringsWithSeparator((collector), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() def uniq(iii): tmp=0 for jj in range(1,len(s)): bb={} for ii in iii : bb.setdefault(s[ii-jj],[]).append(ii) tmp=max(tmp,sum(1 for vvv in bb.values()if len(vvv)==1)) return tmp aa={} for ii,ss in enumerate(s): aa.setdefault(ss,[]).append(ii) ans=0 for iii in aa.values(): ans+=uniq(iii) print(ans/len(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; skip ; var aa : OclAny := Set{} ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var ii : OclAny := _tuple->at(_indx); _indx := _indx + 1; var ss : OclAny := _tuple->at(_indx); (expr (atom (name aa)) (trailer . (name setdefault) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ss))))))) , (argument (test (logical_test (comparison (expr (atom [ ]))))))) ))) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ii)))))))) ))))) ; var ans : int := 0 ; for iii : aa.values() do ( ans := ans + uniq(iii)) ; execute (ans / (s)->size())->display(); operation uniq(iii : OclAny) : OclAny pre: true post: true activity: var tmp : int := 0 ; for jj : Integer.subrange(1, (s)->size()-1) do ( var bb : OclAny := Set{} ; for ii : iii do ((expr (atom (name bb)) (trailer . (name setdefault) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name ii))) - (expr (atom (name jj))))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom [ ]))))))) ))) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ii)))))))) ))))) ; tmp := Set{tmp, ((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name vvv)))) in (logical_test (comparison (expr (atom (name bb)) (trailer . (name values) (arguments ( )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name vvv)))))))) ))))) == (comparison (expr (atom (number (integer 1))))))))))))->sum()}->max()) ; return tmp; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) problems=list(map(int,input().split())) freq=[0]*(n+1) answer='' contador=0 for i in range(m): if freq[problems[i]]==0 : contador+=1 freq[problems[i]]+=1 if contador==n : answer+='1' for j in range(1,n+1): if freq[j]-1==0 : contador-=1 freq[j]-=1 else : answer+='0' else : freq[problems[i]]+=1 answer+='0' print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var problems : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var answer : String := '' ; var contador : int := 0 ; for i : Integer.subrange(0, m-1) do ( if freq[problems[i+1]+1] = 0 then ( contador := contador + 1 ; freq[problems[i+1]+1] := freq[problems[i+1]+1] + 1 ; if contador = n then ( answer := answer + '1' ; for j : Integer.subrange(1, n + 1-1) do ( if freq[j+1] - 1 = 0 then ( contador := contador - 1 ) else skip ; freq[j+1] := freq[j+1] - 1) ) else ( answer := answer + '0' ) ) else ( freq[problems[i+1]+1] := freq[problems[i+1]+1] + 1 ; answer := answer + '0' )) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lista=[0] final=[] contador=0 controles=list(map(int,input().split())) sequencia=list(map(int,input().split())) lista=lista*controles[0] for a in range(controles[1]): lista[sequencia[a]-1]+=1 if lista[sequencia[a]-1]==1 : contador+=1 if contador==len(lista): contador=0 final.append("1") for b in range(len(lista)): lista[b]-=1 if lista[b]>=1 : contador+=1 else : final.append("0") print(''.join(final)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lista : Sequence := Sequence{ 0 } ; var final : Sequence := Sequence{} ; var contador : int := 0 ; var controles : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sequencia : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; lista := MatrixLib.elementwiseMult(lista, controles->first()) ; for a : Integer.subrange(0, controles[1+1]-1) do ( lista[sequencia[a+1] - 1+1] := lista[sequencia[a+1] - 1+1] + 1 ; if lista[sequencia[a+1] - 1+1] = 1 then ( contador := contador + 1 ) else skip ; if contador = (lista)->size() then ( contador := 0 ; execute (("1") : final) ; for b : Integer.subrange(0, (lista)->size()-1) do ( lista[b+1] := lista[b+1] - 1 ; if lista[b+1] >= 1 then ( contador := contador + 1 ) else skip) ) else ( execute (("0") : final) )) ; execute (StringLib.sumStringsWithSeparator((final), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(num)for num in input().split()] table=[0]*n size=0 problems=[int(num)for num in input().split()] saida='' for problem in problems : table[problem-1]+=1 if table[problem-1]==1 : size+=1 if size==n : saida+='1' for i in range(n): table[i]-=1 if table[i]==0 : size-=1 else : saida+='0' else : saida+='0' print(saida) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var table : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var size : int := 0 ; var problems : Sequence := input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var saida : String := '' ; for problem : problems do ( table[problem - 1+1] := table[problem - 1+1] + 1 ; if table[problem - 1+1] = 1 then ( size := size + 1 ; if size = n then ( saida := saida + '1' ; for i : Integer.subrange(0, n-1) do ( table[i+1] := table[i+1] - 1 ; if table[i+1] = 0 then ( size := size - 1 ) else skip) ) else ( saida := saida + '0' ) ) else ( saida := saida + '0' )) ; execute (saida)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,m=map(int,input().split()) a=list(map(int,input().split())) cnt=[0]*(n+1) c=0 ans=[] for i in a : if not cnt[i]: c+=1 cnt[i]+=1 ans.append("0" if c ^ n else "1") if c==n : for j in range(1,n+1): cnt[j]-=1 if not cnt[j]: c-=1 sys.stdout.write("".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var c : int := 0 ; var ans : Sequence := Sequence{} ; for i : a do ( if not(cnt[i+1]) then ( c := c + 1 ) else skip ; cnt[i+1] := cnt[i+1] + 1 ; execute ((if MathLib.bitwiseXor(c, n) then "0" else "1" endif) : ans) ; if c = n then ( for j : Integer.subrange(1, n + 1-1) do ( cnt[j+1] := cnt[j+1] - 1 ; if not(cnt[j+1]) then ( c := c - 1 ) else skip) ) else skip) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNumber(n): num=n-1 ; num=2*(4**num); num=num//3 ; return num ; if __name__=="__main__" : n=5 ; print(findNumber(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 5; ; execute (findNumber(n))->display(); ) else skip; operation findNumber(n : OclAny) pre: true post: true activity: var num : double := n - 1; ; num := 2 * ((4)->pow(num)); ; num := num div 3; ; return num;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : line=list(map(str,input())) string="" for i in range(len(line)): if(line[i]!='@' and line[i-1]!='@' and line[i-2]!='@'): string+=line[i] elif line[i]=='@' : string+=line[i+2]*int(line[i+1]) else : pass print(string) except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var line : Sequence := (((OclFile["System.in"]).readLine())->collect( _x | (OclType["String"])->apply(_x) )) ; var string : String := "" ; for i : Integer.subrange(0, (line)->size()-1) do ( if (line[i+1] /= '@' & line[i - 1+1] /= '@' & line[i - 2+1] /= '@') then ( string := string + line[i+1] ) else (if line[i+1] = '@' then ( string := string + line[i + 2+1] * ("" + ((line[i + 1+1])))->toInteger() ) else ( skip ) ) ) ; execute (string)->display()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def multiply(x,y): if(y==0): return 0 if(y>0): return(x+multiply(x,y-1)) if(y<0): return-multiply(x,-y) print(multiply(5,-11)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (multiply(5, -11))->display(); operation multiply(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (y = 0) then ( return 0 ) else skip ; if (y > 0) then ( return (x + multiply(x, y - 1)) ) else skip ; if (y < 0) then ( return -multiply(x, -y) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sz=1000 fib=set() def fibonacci(): prev,curr,length=0,1,2 fib.add(prev) fib.add(curr) while(length<=sz): temp=curr+prev fib.add(temp) prev=curr curr=temp length+=1 def printArray(arr,length): for i in range(length): print(arr[i],end=" ") def removeFibonacci(arr,length): fibonacci() for i in fib : if i in arr : arr.remove(i) length-=1 printArray(arr,length) if __name__=="__main__" : arr=[4,6,5,3,8,7,10,11,14,15] length=len(arr) removeFibonacci(arr,length) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sz : int := 1000 ; var fib : Set := Set{}->union(()) ; skip ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{4}->union(Sequence{6}->union(Sequence{5}->union(Sequence{3}->union(Sequence{8}->union(Sequence{7}->union(Sequence{10}->union(Sequence{11}->union(Sequence{14}->union(Sequence{ 15 }))))))))) ; length := (arr)->size() ; removeFibonacci(arr, length) ) else skip; operation fibonacci() pre: true post: true activity: var prev : OclAny := null; var curr : OclAny := null; var length : OclAny := null; Sequence{prev,curr,length} := Sequence{0,1,2} ; execute ((prev) : fib) ; execute ((curr) : fib) ; while ((length->compareTo(sz)) <= 0) do ( var temp : OclAny := curr + prev ; execute ((temp) : fib) ; var prev : OclAny := curr ; var curr : OclAny := temp ; length := length + 1); operation printArray(arr : OclAny, length : OclAny) pre: true post: true activity: for i : Integer.subrange(0, length-1) do ( execute (arr[i+1])->display()); operation removeFibonacci(arr : OclAny, length : OclAny) pre: true post: true activity: fibonacci() ; for i : fib do ( if (arr)->includes(i) then ( execute ((i) /: arr) ; length := length - 1 ) else skip) ; printArray(arr, length); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def minAbsDiff(n): left=1<<(int)(math.floor(math.log2(n))) right=left*2 return min((n-left),(right-n)) if __name__=="__main__" : n=15 print(minAbsDiff(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 15 ; execute (minAbsDiff(n))->display() ) else skip; operation minAbsDiff(n : OclAny) : OclAny pre: true post: true activity: var left : int := 1 * (2->pow((OclType["int"])(()->floor()))) ; var right : int := left * 2 ; return Set{(n - left), (right - n)}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bitonicGenerator(arr,n): i=1 j=n-1 if(j % 2!=0): j=j-1 while(iunion(Sequence{5}->union(Sequence{8}->union(Sequence{9}->union(Sequence{6}->union(Sequence{7}->union(Sequence{3}->union(Sequence{4}->union(Sequence{2}->union(Sequence{ 0 }))))))))) ; n := (arr)->size() ; arr := bitonicGenerator(arr, n) ; execute (arr)->display(); operation bitonicGenerator(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var i : int := 1 ; var j : double := n - 1 ; if (j mod 2 /= 0) then ( j := j - 1 ) else skip ; while ((i->compareTo(j)) < 0) do ( var arr[j+1] : OclAny := null; var arr[i+1] : OclAny := null; Sequence{arr[j+1],arr[i+1]} := Sequence{arr[i+1],arr[j+1]} ; i := i + 2 ; j := j - 2) ; var arr_f : Sequence := Sequence{} ; var arr_s : Sequence := Sequence{} ; for i : Integer.subrange(0, ("" + (((n + 1) / 2)))->toInteger()-1) do ( execute ((arr[i+1]) : arr_f)) ; i := ("" + (((n + 1) / 2)))->toInteger() ; while ((i->compareTo(n)) < 0) do ( execute ((arr[i+1]) : arr_s) ; i := i + 1) ; arr_f := arr_f->sort() ; arr_s := arr_s->sort() ; for i : arr_s do ( execute ((i) : arr_f)) ; return arr_f; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=5 def printSumSimple(mat,k): if(k>n): return for i in range(n-k+1): for j in range(n-k+1): sum=0 for p in range(i,k+i): for q in range(j,k+j): sum+=mat[p][q] print(sum,end=" ") print() if __name__=="__main__" : mat=[[1,1,1,1,1],[2,2,2,2,2],[3,3,3,3,3],[4,4,4,4,4],[5,5,5,5,5]] k=3 printSumSimple(mat,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := 5 ; skip ; if __name__ = "__main__" then ( mat := Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))))}->union(Sequence{Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 2 }))))}->union(Sequence{Sequence{3}->union(Sequence{3}->union(Sequence{3}->union(Sequence{3}->union(Sequence{ 3 }))))}->union(Sequence{Sequence{4}->union(Sequence{4}->union(Sequence{4}->union(Sequence{4}->union(Sequence{ 4 }))))}->union(Sequence{ Sequence{5}->union(Sequence{5}->union(Sequence{5}->union(Sequence{5}->union(Sequence{ 5 })))) })))) ; k := 3 ; printSumSimple(mat, k) ) else skip; operation printSumSimple(mat : OclAny, k : OclAny) pre: true post: true activity: if ((k->compareTo(n)) > 0) then ( return ) else skip ; for i : Integer.subrange(0, n - k + 1-1) do ( for j : Integer.subrange(0, n - k + 1-1) do ( var sum : int := 0 ; for p : Integer.subrange(i, k + i-1) do ( for q : Integer.subrange(j, k + j-1) do ( sum := sum + mat[p+1][q+1])) ; execute (sum)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- str=input() l=len(str) a=[0]*(2*l) pos=[[]for i in range(26)] for i,c in enumerate(str): t=ord(c)-ord('a') a[i]=t a[i+l]=t pos[t].append(i) ans=0 for c in range(26): cur=0 for k in range(1,l): cnt=[0]*26 for i in pos[c]: cnt[a[i+k]]+=1 cur=max(cur,len([1 for x in cnt if x==1])) ans+=cur print(ans/l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var OclType["String"] : String := (OclFile["System.in"]).readLine() ; var l : int := (OclType["String"])->size() ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * l)) ; var pos : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | (Sequence{})) ; for _tuple : Integer.subrange(1, (OclType["String"])->size())->collect( _indx | Sequence{_indx-1, (OclType["String"])->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); var t : double := (c)->char2byte() - ('a')->char2byte() ; a[i+1] := t ; a[i + l+1] := t ; (expr (atom (name pos)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var ans : int := 0 ; for c : Integer.subrange(0, 26-1) do ( var cur : int := 0 ; for k : Integer.subrange(1, l-1) do ( var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for i : pos[c+1] do ( cnt[a[i + k+1]+1] := cnt[a[i + k+1]+1] + 1) ; cur := Set{cur, (cnt->select(x | x = 1)->collect(x | (1)))->size()}->max()) ; ans := ans + cur) ; execute (ans / l)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) print(m+n-1) if n==1 and m==1 : print(1,1) else : for i in range(1,n+1): print(i,1) for i in range(2,m+1): print(1,i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (m + n - 1)->display() ; if n = 1 & m = 1 then ( execute (1)->display() ) else ( for i : Integer.subrange(1, n + 1-1) do ( execute (i)->display()) ; for i : Integer.subrange(2, m + 1-1) do ( execute (1)->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) print(a+b-1) for i in range(1,a+b): print(max(1,i-b+1),min(i,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (a + b - 1)->display() ; for i : Integer.subrange(1, a + b-1) do ( execute (Set{1, i - b + 1}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) n,m=map(int,input().split()) print(n+m-1) for i in range(n): print(i+1,1) for i in range(m-1): print(1,i+2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (n + m - 1)->display() ; for i : Integer.subrange(0, n-1) do ( execute (i + 1)->display()) ; for i : Integer.subrange(0, m - 1-1) do ( execute (1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) print(a+b-1) for i in range(1,a+1): print(i,1) for i in range(2,b+1): print(1,i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (a + b - 1)->display() ; for i : Integer.subrange(1, a + 1-1) do ( execute (i)->display()) ; for i : Integer.subrange(2, b + 1-1) do ( execute (1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import(division,absolute_import,print_function,unicode_literals) from sys import stdin li=[] for line in stdin : compress=False num=1 for c in line : if c=='@' : compress=True elif compress : compress=False num=int(c) else : li.append(c*num) num=1 print(''.join(li),end='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var li : Sequence := Sequence{} ; for line : stdin do ( var compress : boolean := false ; var num : int := 1 ; for c : line do ( if c = '@' then ( compress := true ) else (if compress then ( compress := false ; num := ("" + ((c)))->toInteger() ) else ( execute ((c * num) : li) ; num := 1 ) ) )) ; execute (StringLib.sumStringsWithSeparator((li), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) z=a-1+b print(z) for i in range(b): print(1,i+1) for i in range(1,a): print(i+1,1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var z : double := a - 1 + b ; execute (z)->display() ; for i : Integer.subrange(0, b-1) do ( execute (1)->display()) ; for i : Integer.subrange(1, a-1) do ( execute (i + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- v=[1,0,0,0,1,0,1,0,2,1,1,2,0,1,0,0] n=int(input()) a=1 if n==0 else 0 while n>0 : a+=v[n % 16] n//=16 print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var v : Sequence := Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{2}->union(Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 0 }))))))))))))))) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := if n = 0 then 1 else 0 endif ; while n > 0 do ( a := a + v[n mod 16+1] ; n := n div 16) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) h=hex(a) s=str(h)[2 :] oneHole=['0','4','6','9','a','d'] twoHoles=['8','b'] count=0 for i in range(len(s)): if s[i]in oneHole : count+=1 elif s[i]in twoHoles : count+=2 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var h : String := MathLib.decimal2hex(a) ; var s : OclAny := OclType["String"](h).subrange(2+1) ; var oneHole : Sequence := Sequence{'0'}->union(Sequence{'4'}->union(Sequence{'6'}->union(Sequence{'9'}->union(Sequence{'a'}->union(Sequence{ 'd' }))))) ; var twoHoles : Sequence := Sequence{'8'}->union(Sequence{ 'b' }) ; var count : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if (oneHole)->includes(s[i+1]) then ( count := count + 1 ) else (if (twoHoles)->includes(s[i+1]) then ( count := count + 2 ) else skip)) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def to_hex(n): return hex(n)[2 :].upper() def closed_loops(x): d={'0' : 1,'1' : 0,'2' : 0,'3' : 0,'4' : 1,'5' : 0,'6' : 1,'7' : 0,'8' : 2,'9' : 1,'A' : 1,'B' : 2,'C' : 0,'D' : 1,'E' : 0,'F' : 0} total=0 a=to_hex(x) for c in a : total+=d[c] return total def main(): n=int(input()) print(closed_loops(n)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation to_hex(n : OclAny) : OclAny pre: true post: true activity: return hex(n).subrange(2+1)->toUpperCase(); operation closed_loops(x : OclAny) : OclAny pre: true post: true activity: var d : Map := Map{ '0' |-> 1 }->union(Map{ '1' |-> 0 }->union(Map{ '2' |-> 0 }->union(Map{ '3' |-> 0 }->union(Map{ '4' |-> 1 }->union(Map{ '5' |-> 0 }->union(Map{ '6' |-> 1 }->union(Map{ '7' |-> 0 }->union(Map{ '8' |-> 2 }->union(Map{ '9' |-> 1 }->union(Map{ 'A' |-> 1 }->union(Map{ 'B' |-> 2 }->union(Map{ 'C' |-> 0 }->union(Map{ 'D' |-> 1 }->union(Map{ 'E' |-> 0 }->union(Map{ 'F' |-> 0 }))))))))))))))) ; var total : int := 0 ; var a : OclAny := to_hex(x) ; for c : a do ( total := total + d[c+1]) ; return total; operation main() pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (closed_loops(n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=hex(int(input()))[2 :] sum=0 for i in n : sum+=[1,0,0,0,1,0,1,0,2,1,1,2,0,1,0,0][int(i,16)] print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := hex(("" + (((OclFile["System.in"]).readLine())))->toInteger()).subrange(2+1) ; var sum : int := 0 ; for i : n do ( sum := sum + Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{2}->union(Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 0 })))))))))))))))[("" + ((i, 16)))->toInteger()+1]) ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a={'0' : 1,'1' : 0,'2' : 0,'3' : 0,'4' : 1,'5' : 0,'6' : 1,'7' : 0,'8' : 2,'9' : 1,'a' : 1,'b' : 2,'c' : 0,'d' : 1,'e' : 0,'f' : 0} s=0 for i in hex(int(input())).replace('0x',''): s+=a[i] print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Map := Map{ '0' |-> 1 }->union(Map{ '1' |-> 0 }->union(Map{ '2' |-> 0 }->union(Map{ '3' |-> 0 }->union(Map{ '4' |-> 1 }->union(Map{ '5' |-> 0 }->union(Map{ '6' |-> 1 }->union(Map{ '7' |-> 0 }->union(Map{ '8' |-> 2 }->union(Map{ '9' |-> 1 }->union(Map{ 'a' |-> 1 }->union(Map{ 'b' |-> 2 }->union(Map{ 'c' |-> 0 }->union(Map{ 'd' |-> 1 }->union(Map{ 'e' |-> 0 }->union(Map{ 'f' |-> 0 }))))))))))))))) ; var s : int := 0 ; for i : hex(("" + (((OclFile["System.in"]).readLine())))->toInteger()).replace('0x', '') do ( s := s + a[i+1]) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() l=len(s) instances=[[]for x in range(26)] s_i=[ord(c)-97 for c in s] for i in range(l): instances[s_i[i]].append(i) sum_probability=0 for c in range(0,26): if not instances[c]: continue if len(instances[c])==0 : sum_probability+=1 continue max_probability=0 for guess in range(1,l): num_seen=[0]*26 probability=0 for index in instances[c]: num_seen[s_i[(index+guess)% l]]+=1 for x in num_seen : if x==1 : probability+=1 max_probability=max(max_probability,probability) sum_probability+=max_probability print(sum_probability/l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var l : int := (s)->size() ; var instances : Sequence := Integer.subrange(0, 26-1)->select(x | true)->collect(x | (Sequence{})) ; var s_i : Sequence := s->characters()->select(c | true)->collect(c | ((c)->char2byte() - 97)) ; for i : Integer.subrange(0, l-1) do ((expr (atom (name instances)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s_i)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var sum_probability : int := 0 ; for c : Integer.subrange(0, 26-1) do ( if not(instances[c+1]) then ( continue ) else skip ; if (instances[c+1])->size() = 0 then ( sum_probability := sum_probability + 1 ; continue ) else skip ; var max_probability : int := 0 ; for guess : Integer.subrange(1, l-1) do ( var num_seen : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; var probability : int := 0 ; for index : instances[c+1] do ( num_seen[s_i[(index + guess) mod l+1]+1] := num_seen[s_i[(index + guess) mod l+1]+1] + 1) ; for x : num_seen do ( if x = 1 then ( probability := probability + 1 ) else skip) ; max_probability := Set{max_probability, probability}->max()) ; sum_probability := sum_probability + max_probability) ; execute (sum_probability / l)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numOfWhiteHats(arr,n): freq=[0 for i in range(n+1+1)] for i in range(n): if(arr[i]>=n): return-1 freq[arr[i]]+=1 diffFreq=0 for i in range(n-1,-1,-1): if(freq[i]): diffFreq+=1 if(diffFreq==1 and freq[n-1]==n): return n if(diffFreq==1 and freq[0]==n): return 0 if(diffFreq!=2): return-1 for k in range(n-1,0,-1): if(freq[k]): break if(freq[k-1]==k and freq[k]+k==n): return freq[k-1] else : return-1 arr=[2,2,2,3,3] n=len(arr) print(numOfWhiteHats(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 3 })))) ; n := (arr)->size() ; execute (numOfWhiteHats(arr, n))->display(); operation numOfWhiteHats(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var freq : Sequence := Integer.subrange(0, n + 1 + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( if ((arr[i+1]->compareTo(n)) >= 0) then ( return -1 ) else skip ; freq[arr[i+1]+1] := freq[arr[i+1]+1] + 1) ; var diffFreq : int := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (freq[i+1]) then ( diffFreq := diffFreq + 1 ) else skip) ; if (diffFreq = 1 & freq[n - 1+1] = n) then ( return n ) else skip ; if (diffFreq = 1 & freq->first() = n) then ( return 0 ) else skip ; if (diffFreq /= 2) then ( return -1 ) else skip ; for k : Integer.subrange(0 + 1, n - 1)->reverse() do ( if (freq[k+1]) then ( break ) else skip) ; if (freq[k - 1+1] = k & freq[k+1] + k = n) then ( return freq[k - 1+1] ) else ( return -1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def canBeBalanced(s,n): count=0 count_1=0 for i in range(n): if(s[i]=='('): count+=1 else : count-=1 count_1=min(count_1,count) if(count_1>=-1 and count==0): return True return False s="())()(" n=len(s) if(canBeBalanced(s,n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := "())()(" ; n := (s)->size() ; if (canBeBalanced(s, n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation canBeBalanced(s : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var count var count : int := 0 : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (s[i+1] = '(') then ( count := count + 1 ) else ( count := count - 1 ) ; count if (s[i+1] = '(') then ( count := count + 1 ) else ( count := count - 1 ) := Set{count(count(count if (s[i+1] = '(') then ( count := count + 1 ) else ( count := count - 1 ), count), count), count}->min()) ; if (count var count : int := 0 >= -1 & count = 0) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline cur=[0 for i in range(20)] counts={0 : cur.copy()} for i in range(1,200001): b=bin(i) for j in range(len(b)-2): if b[-j-1]=='1' : cur[j]+=1 counts[i]=cur.copy() for t in range(int(input())): l,r=map(int,input().split()) ar=counts[r] al=counts[l-1] cc=[ar[i]-al[i]for i in range(len(ar))] print(r-l+1-max(cc)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var cur : Sequence := Integer.subrange(0, 20-1)->select(i | true)->collect(i | (0)) ; var counts : Map := Map{ 0 |-> cur->copy() } ; for i : Integer.subrange(1, 200001-1) do ( var b : OclAny := bin(i) ; for j : Integer.subrange(0, (b)->size() - 2-1) do ( if b->reverse()->at(-(-j - 1)) = '1' then ( cur[j+1] := cur[j+1] + 1 ) else skip) ; counts[i+1] := cur->copy()) ; for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ar : OclAny := counts[r+1] ; var al : OclAny := counts[l - 1+1] ; var cc : Sequence := Integer.subrange(0, (ar)->size()-1)->select(i | true)->collect(i | (ar[i+1] - al[i+1])) ; execute (r - l + 1 - (cc)->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readlines=sys.stdin.readlines write=sys.stdout.write def solve(): for line in readlines(): s=line.strip() ans=[] L=len(s) i=0 while itrim() ; var ans : Sequence := Sequence{} ; var L : int := (s)->size() ; var i : int := 0 ; while (i->compareTo(L)) < 0 do ( if s[i+1] = "@" then ( var k : int := ("" + ((s[i + 1+1])))->toInteger() ; i := i + 2 ) else ( k := 1 ) ; var c : OclAny := s[i+1] ; execute ((c * k) : ans) ; i := i + 1) ; write(StringLib.sumStringsWithSeparator((ans), "")) ; write("\n")); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lis=[] k=25 mp={} for i in range(2*(10**5)+3): s=bin(i)[2 :][: :-1] s+='0'*(k-len(s)) for i in range(len(s)): if(i not in mp): mp[i]=0 if s[i]=="0" : mp[i]+=1 lis.append(mp.copy()) for p in range(int(input())): l,r=map(int,input().split()) ans=2**31 for i in range(k): ans=min(ans,lis[r][i]-lis[l-1][i]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lis : Sequence := Sequence{} ; var k : int := 25 ; var mp : OclAny := Set{} ; for i : Integer.subrange(0, 2 * ((10)->pow(5)) + 3-1) do ( var s : OclAny := bin(i).subrange(2+1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; s := s + StringLib.nCopies('0', (k - (s)->size())) ; for i : Integer.subrange(0, (s)->size()-1) do ( if ((mp)->excludes(i)) then ( mp[i+1] := 0 ) else skip ; if s[i+1] = "0" then ( mp[i+1] := mp[i+1] + 1 ) else skip) ; execute ((mp->copy()) : lis)) ; for p : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : double := (2)->pow(31) ; for i : Integer.subrange(0, k-1) do ( ans := Set{ans, lis[r+1][i+1] - lis[l - 1+1][i+1]}->min()) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math L=[[0 for i in range(20)]for i in range(2*(10**5)+1)] for j in range(0,2*(10**5)+1): for k in range(0,20): L[j][k]=L[j-1][k] if((j &(1<>k==1): L[j][k]+=1 t=int(input()) for i in range(0,t): l,r=map(int,input().split()) u=0 for k in range(0,20): u=max(u,L[r][k]-L[l-1][k]) print((r-l+1)-u) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var L : Sequence := Integer.subrange(0, 2 * ((10)->pow(5)) + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, 20-1)->select(i | true)->collect(i | (0)))) ; for j : Integer.subrange(0, 2 * ((10)->pow(5)) + 1-1) do ( for k : Integer.subrange(0, 20-1) do ( L[j+1][k+1] := L[j - 1+1][k+1] ; if ((MathLib.bitwiseAnd(j, (1 * (2->pow(k))))) /(2->pow(k)) = 1) then ( L[j+1][k+1] := L[j+1][k+1] + 1 ) else skip)) ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var u : int := 0 ; for k : Integer.subrange(0, 20-1) do ( u := Set{u, L[r+1][k+1] - L[l - 1+1][k+1]}->max()) ; execute ((r - l + 1) - u)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def main(ps): l,r=map(int,input().split()) arr=[ps[r][i]-ps[l-1][i]for i in range(20)] return min(arr) ps=[[0]*20 for _ in range(2*(10**5)+1)] n=len(ps) for i in range(1,2*(10**5)+1): ps[i]=list(ps[i-1]) num=i for j in range(20): ps[i][j]+=0 if num & 1 else 1 num>>=1 for _ in range(int(input())): print(main(ps)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; ps := Integer.subrange(0, 2 * ((10)->pow(5)) + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 20))) ; var n : int := (ps)->size() ; for i : Integer.subrange(1, 2 * ((10)->pow(5)) + 1-1) do ( ps[i+1] := (ps[i - 1+1]) ; var num : OclAny := i ; for j : Integer.subrange(0, 20-1) do ( ps[i+1][j+1] := ps[i+1][j+1] + if MathLib.bitwiseAnd(num, 1) then 0 else 1 endif ; num := num div (2->pow(1)))) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (main(ps))->display()); operation main(ps : OclAny) : OclAny pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := Integer.subrange(0, 20-1)->select(i | true)->collect(i | (ps[r+1][i+1] - ps[l - 1+1][i+1])) ; return (arr)->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline maxx=100000<<1 d=[[0]*18] for i in range(1,maxx+1): d.append([d[-1][j]+(i &(1<pow(1)) ; var d : Sequence := Sequence{ MatrixLib.elementwiseMult(Sequence{ 0 }, 18) } ; for i : Integer.subrange(1, maxx + 1-1) do ( execute ((Integer.subrange(0, 18-1)->select(j | true)->collect(j | (d->last()[j+1] + (MathLib.bitwiseAnd(i, (1 * (2->pow(j)))) /= 0)))) : d)) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (("" + ((r - l + 1 - ((argument (test (logical_test (comparison (expr (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name l))) - (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 18))))))))) )))))))))->max()))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minInt(str1): for i in range(len(str1)): if(str1[i]>=5): str1[i]=(9-str1[i]) if(str1[0]==0): str1[0]=9 temp="" for i in str1 : temp+=str(i) return temp str1="589" str1=[int(i)for i in str1] print(minInt(str1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; str1 := "589" ; str1 := str1->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute (minInt(str1))->display(); operation minInt(str1 : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, (str1)->size()-1) do ( if (str1[i+1] >= 5) then ( str1[i+1] := (9 - str1[i+1]) ) else skip) ; if (str1->first() = 0) then ( str1->first() := 9 ) else skip ; var temp : String := "" ; for i : str1 do ( temp := temp + ("" + ((i)))) ; return temp; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys if(__name__=='__main__'): tc_count=int(sys.stdin.readline().strip()) for i in range(tc_count): sys.stdin.readline() v1=[int(x)for x in sys.stdin.readline().strip().split()] v2=[int(x)for x in sys.stdin.readline().strip().split()] v1.sort() v2.sort() v2.reverse() msp=0 assert(len(v1)==len(v2)) for j in range(len(v1)): msp+=v1[j]*v2[j] sys.stdout.write('Case #%d: %d\n' %(i+1,msp)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if (__name__ = '__main__') then ( var tc_count : int := ("" + ((sys.stdin.readLine()->trim())))->toInteger() ; for i : Integer.subrange(0, tc_count-1) do ((expr (atom (name sys)) (trailer . (name stdin)) (trailer . (name readline) (arguments ( )))) ; var v1 : Sequence := sys.stdin.readLine()->trim().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var v2 : Sequence := sys.stdin.readLine()->trim().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; v1 := v1->sort() ; v2 := v2->sort() ; v2 := v2->reverse() ; var msp : int := 0 ; assert ((v1)->size() = (v2)->size()) do "assertion failed" ; for j : Integer.subrange(0, (v1)->size()-1) do ( msp := msp + v1[j+1] * v2[j+1]) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom 'Case #%d: %d ')) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (atom (name msp))))))) ))))))))) ))))) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys argv=sys.argv[1 :] testFile=open(argv[0]+'.in','rb') outFile=open(argv[0]+'.out','wb') nCases=int(testFile.readline()) for i in xrange(1,nCases+1): n=int(testFile.readline()) v1=sorted(int(val)for val in testFile.readline().split()) v2=sorted(int(val)for val in testFile.readline().split()) v2=v2[: :-1] outFile.write('Case #%i: %i\n' %(i,sum(a*b for a,b in zip(v1,v2)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var argv : (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])) := (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])) ; var testFile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(argv->first() + '.in')) ; var outFile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(argv->first() + '.out')) ; var nCases : int := ("" + ((testFile.readLine())))->toInteger() ; for i : xrange(1, nCases + 1) do ( var n : int := ("" + ((testFile.readLine())))->toInteger() ; var v1 : Sequence := (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name val)))))))) ))))))) (comp_for for (exprlist (expr (atom (name val)))) in (logical_test (comparison (expr (atom (name testFile)) (trailer . (name readline) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))->sort() ; var v2 : Sequence := (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name val)))))))) ))))))) (comp_for for (exprlist (expr (atom (name val)))) in (logical_test (comparison (expr (atom (name testFile)) (trailer . (name readline) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))->sort() ; v2 := v2(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; outFile.write(StringLib.format('Case #%i: %i ',Sequence{i, ((argument (test (logical_test (comparison (expr (expr (atom (name a))) * (expr (atom (name b))))))) (comp_for for (exprlist (expr (atom (name a))) , (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v1))))))) , (argument (test (logical_test (comparison (expr (atom (name v2)))))))) )))))))))->sum()}))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from operator import itemgetter def solve(data): result=[] for name,win,lose,draw in data : score=win*3+draw*1 result.append([name,score]) result.sort(key=itemgetter(1),reverse=True) return result def main(args): first_data_set=True while True : n=int(input()) if n==0 : break data=[] for _ in range(n): name,win,lose,draw=input().split() data.append([name,int(win),int(lose),int(draw)]) result=solve(data) if first_data_set : first_data_set=False else : print() for r in result : print(','.join(map(str,r))) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(data : OclAny) : OclAny pre: true post: true activity: var result : Sequence := Sequence{} ; for _tuple : data do (var _indx : int := 1; var name : OclAny := _tuple->at(_indx); _indx := _indx + 1; var win : OclAny := _tuple->at(_indx); _indx := _indx + 1; var lose : OclAny := _tuple->at(_indx); _indx := _indx + 1; var draw : OclAny := _tuple->at(_indx); var score : double := win * 3 + draw * 1 ; execute ((Sequence{name}->union(Sequence{ score })) : result)) ; result := result->sort() ; return result; operation main(args : OclAny) pre: true post: true activity: var first_data_set : boolean := true ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; data := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var name : OclAny := null; var win : OclAny := null; var lose : OclAny := null; var draw : OclAny := null; Sequence{name,win,lose,draw} := input().split() ; execute ((Sequence{name}->union(Sequence{("" + ((win)))->toInteger()}->union(Sequence{("" + ((lose)))->toInteger()}->union(Sequence{ ("" + ((draw)))->toInteger() })))) : data)) ; result := solve(data) ; if first_data_set then ( first_data_set := false ) else ( execute (->display() ) ; for r : result do ( execute (StringLib.sumStringsWithSeparator(((r)->collect( _x | (OclType["String"])->apply(_x) )), ','))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() def uniq(iii): tmp=0 for jj in range(1,len(s)): bb={} for ii in iii : bb.setdefault(s[ii-jj],[]).append(ii) tmp=max(tmp,sum(1 for vvv in bb.values()if len(vvv)==1)) return tmp aa={} for ii,ss in enumerate(s): aa.setdefault(ss,[]).append(ii) ans=0 for iii in aa.values(): ans+=uniq(iii) print(ans/len(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; skip ; var aa : OclAny := Set{} ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var ii : OclAny := _tuple->at(_indx); _indx := _indx + 1; var ss : OclAny := _tuple->at(_indx); (expr (atom (name aa)) (trailer . (name setdefault) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ss))))))) , (argument (test (logical_test (comparison (expr (atom [ ]))))))) ))) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ii)))))))) ))))) ; var ans : int := 0 ; for iii : aa.values() do ( ans := ans + uniq(iii)) ; execute (ans / (s)->size())->display(); operation uniq(iii : OclAny) : OclAny pre: true post: true activity: var tmp : int := 0 ; for jj : Integer.subrange(1, (s)->size()-1) do ( var bb : OclAny := Set{} ; for ii : iii do ((expr (atom (name bb)) (trailer . (name setdefault) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name ii))) - (expr (atom (name jj))))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom [ ]))))))) ))) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ii)))))))) ))))) ; tmp := Set{tmp, ((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name vvv)))) in (logical_test (comparison (expr (atom (name bb)) (trailer . (name values) (arguments ( )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name vvv)))))))) ))))) == (comparison (expr (atom (number (integer 1))))))))))))->sum()}->max()) ; return tmp; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys _TYPE={'d' : int,'l' : long,'f' : float,'s' : str} _buffer=[] def next_token(): if not _buffer : line=sys.stdin.readline() _buffer.extend(line.split()) return _buffer.pop(0) def scanf(format): if len(format)% 2!=0 : raise ValueError for i in xrange(0,len(format),2): if format[i]!='%' : raise ValueError if format[i+1]not in 'dfs' : raise ValueError result=[] for i in xrange(1,len(format),2): token=next_token() value=_TYPE[format[i]](token) result.append(value) return tuple(result) def printf(format,*args): message=format % args sys.stdout.write(message) return len(message) def solve(): n,=scanf('%d') v1=list(scanf('%d'*n)) v2=list(scanf('%d'*n)) v1.sort() v2.sort() msp=sum(x*y for x,y in zip(v1,v2[: :-1])) return msp num_cases,=scanf('%d') for case_num in xrange(num_cases): result=solve() printf('Case #%d: %s\n',case_num+1,result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var _TYPE : Map := Map{ 'd' |-> OclType["int"] }->union(Map{ 'l' |-> long }->union(Map{ 'f' |-> OclType["double"] }->union(Map{ 's' |-> OclType["String"] }))) ; var _buffer : Sequence := Sequence{} ; skip ; skip ; skip ; skip ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name num_cases)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name num_cases)))))) ,)} := scanf('%d') ; for case_num : xrange(num_cases) do ( result := solve() ; printf('Case #%d: %s ', case_num + 1, result)); operation next_token() : OclAny pre: true post: true activity: if not(_buffer) then ( var line : String := (OclFile["System.in"]).readLine() ; _buffer := _buffer->union(line.split()) ) else skip ; return _buffer->at(0`firstArg+1); operation scanf(format : OclAny) : OclAny pre: true post: true activity: if (format)->size() mod 2 /= 0 then ( error IncorrectElementException.newIncorrectElementException ) else skip ; for i : xrange(0, (format)->size(), 2) do ( if ([i+1] + "") /= '%' then ( error IncorrectElementException.newIncorrectElementException ) else skip ; if ('dfs')->characters()->excludes(([i + 1+1] + "")) then ( error IncorrectElementException.newIncorrectElementException ) else skip) ; var result : Sequence := Sequence{} ; for i : xrange(1, (format)->size(), 2) do ( var token : OclAny := next_token() ; var value : OclAny := _TYPE[([i+1] + "")+1](token) ; execute ((value) : result)) ; return (result); operation printf(format : OclAny, args : OclAny : Sequence(OclAny)) : OclAny pre: true post: true activity: (args * (named_parameter (name args))) var message : int := format mod args ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name message)))))))) )))) ; return (message)->size(); operation solve() : OclAny pre: true post: true activity: (testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,)} := scanf('%d') ; var v1 : Sequence := (scanf(StringLib.nCopies('%d', n))) ; var v2 : Sequence := (scanf(StringLib.nCopies('%d', n))) ; v1 := v1->sort() ; v2 := v2->sort() ; var msp : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name x))) * (expr (atom (name y))))))) (comp_for for (exprlist (expr (atom (name x))) , (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v1))))))) , (argument (test (logical_test (comparison (expr (atom (name v2)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ])))))))) )))))))))->sum() ; return msp; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys for e in sys.stdin : a='' ; b=n=0 for c in e[:-1]: if '@'==c : b=1 elif b & 1 : n=int(c); b=2 elif b & 2 : a+=c*n ; b=0 else : a+=c print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for e : OclFile["System.in"] do ( var a : String := ''; var b : OclAny := 0; var n : int := 0 ; for c : e->front() do ( if '@' = c then ( b := 1 ) else (if MathLib.bitwiseAnd(b, 1) then ( n := ("" + ((c)))->toInteger(); b := 2 ) else (if MathLib.bitwiseAnd(b, 2) then ( a := a + c * n; b := 0 ) else ( a := a + c ) ) ) ) ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math def dist(p1,p2): x1,y1=p1 x2,y2=p2 return pyth(x2-x1,y2-y1) def pyth(s1,s2): return math.sqrt(math.pow(s1,2)+math.pow(s2,2)) def cArea(r): return math.pi*math.pow(r,2) def rectArea(l,w): return l*w def triArea(s1,s2,s3): s=(s1+s2+s3)/2 return s*(s-s1)*(s-s2)*(s-s3) def main(v1,v2): v1.sort() v2.sort(lambda a,b : cmp(b,a)) sum=0 for i in range(len(v1)): sum+=(v1[i]*v2[i]) return sum def getline(fpin,types): args=fpin.readline().strip().split() for i in range(len(types)): args[i]=types[i](args[i]) return args if __name__=="__main__" : fpin=open(sys.argv[1]) if len(sys.argv)>2 : fpout=open(sys.argv[2],'w') else : fpout=sys.stdout cases=int(fpin.readline().strip()) for case in range(1,cases+1): s=int(fpin.readline().strip()) v1=[int(x)for x in fpin.readline().strip().split()] v2=[int(x)for x in fpin.readline().strip().split()] fpout.write("Case #%d: %s\n" %(case,main(v1,v2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( fpin := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) ; if ((trailer . (name argv)))->size() > 2 then ( var fpout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))) ) else ( fpout := OclFile["System.out"] ) ; var cases : int := ("" + ((fpin.readLine()->trim())))->toInteger() ; for case : Integer.subrange(1, cases + 1-1) do ( s := ("" + ((fpin.readLine()->trim())))->toInteger() ; v1 := fpin.readLine()->trim().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; v2 := fpin.readLine()->trim().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; fpout.write(StringLib.format("Case #%d: %s\n",Sequence{case, main(v1, v2)}))) ) else skip; operation dist(p1 : OclAny, p2 : OclAny) : OclAny pre: true post: true activity: var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := p1 ; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x2,y2} := p2 ; return pyth(x2 - x1, y2 - y1); operation pyth(s1 : OclAny, s2 : OclAny) : OclAny pre: true post: true activity: return ((s1)->pow(2) + (s2)->pow(2))->sqrt(); operation cArea(r : OclAny) : OclAny pre: true post: true activity: return * (r)->pow(2); operation rectArea(l : OclAny, w : OclAny) : OclAny pre: true post: true activity: return l * w; operation triArea(s1 : OclAny, s2 : OclAny, s3 : OclAny) : OclAny pre: true post: true activity: var s : double := (s1 + s2 + s3) / 2 ; return s * (s - s1) * (s - s2) * (s - s3); operation main(v1 : OclAny, v2 : OclAny) : OclAny pre: true post: true activity: v1 := v1->sort() ; v2 := v2->sort() ; var sum : int := 0 ; for i : Integer.subrange(0, (v1)->size()-1) do ( sum := sum + (v1[i+1] * v2[i+1])) ; return sum; operation getline(fpin : OclAny, types : OclAny) : OclAny pre: true post: true activity: var args : OclAny := fpin.readLine()->trim().split() ; for i : Integer.subrange(0, (types)->size()-1) do ( args[i+1] := types[i+1](args[i+1])) ; return args; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- filename="A-large.in" f=open(filename,'r') of=open("A-large.out",'w') N=int(f.readline()) for x in xrange(N): n=int(f.readline()) a=f.readline().split(' ') b=f.readline().split(' ') a=[int(y)for y in a] b=[int(y)for y in b] a.sort() b.sort(reverse=True) s=0 for y in xrange(len(a)): s+=a[y]*b[y] print>>of,"Case #%d: %d" %(x+1,s) f.close() of.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var filename : String := "A-large.in" ; var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(filename)) ; var of : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("A-large.out")) ; var N : int := ("" + ((f.readLine())))->toInteger() ; for x : xrange(N) do ( var n : int := ("" + ((f.readLine())))->toInteger() ; var a : OclAny := f.readLine().split(' ') ; var b : OclAny := f.readLine().split(' ') ; a := a->select(y | true)->collect(y | (("" + ((y)))->toInteger())) ; b := b->select(y | true)->collect(y | (("" + ((y)))->toInteger())) ; a := a->sort() ; b := b->sort() ; var s : int := 0 ; for y : xrange((a)->size()) do ( s := s + a[y+1] * b[y+1]) ; print /(2->pow(of)) ; (expr (expr (atom "Case #%d: %d")) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (atom (name s))))))) ))))) ; f.closeFile() ; of.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100001 ; prefix=[0]*MAX ; def sieve_modified(): for i in range(1,MAX,2): for j in range(i,MAX,i): prefix[j]+=i ; for i in range(1,MAX): prefix[i]+=prefix[i-1]; def sumOddFactors(L,R): return(prefix[R]-prefix[L-1]); sieve_modified(); l=6 ; r=10 ; print(sumOddFactors(l,r)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 100001; ; var prefix : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX); ; skip ; skip ; sieve_modified(); ; var l : int := 6; ; var r : int := 10; ; execute (sumOddFactors(l, r))->display();; operation sieve_modified() pre: true post: true activity: for i : Integer.subrange(1, MAX-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( for j : Integer.subrange(i, MAX-1)->select( $x | ($x - i) mod i = 0 ) do ( prefix[j+1] := prefix[j+1] + i;)) ; for i : Integer.subrange(1, MAX-1) do ( prefix[i+1] := prefix[i+1] + prefix[i - 1+1];); operation sumOddFactors(L : OclAny, R : OclAny) pre: true post: true activity: return (prefix[R+1] - prefix[L - 1+1]);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) print("YES")if n % 4==0 else print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))) if (logical_test (comparison (comparison (expr (expr (atom (name n))) % (expr (atom (number (integer 4)))))) == (comparison (expr (atom (number (integer 0))))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) ))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): m=int(input()) if m % 4==0 and m>=4 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if m mod 4 = 0 & m >= 4 then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): m=int(input()) if m % 4==0 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if m mod 4 = 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n): return 'YES' if n % 4==0 else 'NO' t=int(input()) for _ in range(t): n=int(input()) print(solve(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (solve(n))->display()); operation solve(n : OclAny) : OclAny pre: true post: true activity: return if n mod 4 = 0 then 'YES' else 'NO' endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for test in range(t): n=int(input()) if n % 4==0 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for test : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 4 = 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,l=map(int,input().split()) print((h*h+l*l)/(2*h)-h) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var l : OclAny := null; Sequence{h,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((h * h + l * l) / (2 * h) - h)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countIntervals(arr,V,N): count=0 for i in range(N): li=arr[i][0] ri=arr[i][1] if(V>=li and V<=ri): count+=1 return count ; if __name__=="__main__" : arr=[[1,10],[5,10],[15,25],[7,12],[20,25]] V=7 N=len(arr) print((countIntervals(arr,V,N))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{Sequence{1}->union(Sequence{ 10 })}->union(Sequence{Sequence{5}->union(Sequence{ 10 })}->union(Sequence{Sequence{15}->union(Sequence{ 25 })}->union(Sequence{Sequence{7}->union(Sequence{ 12 })}->union(Sequence{ Sequence{20}->union(Sequence{ 25 }) })))) ; V := 7 ; N := (arr)->size() ; execute ((countIntervals(arr, V, N)))->display() ) else skip; operation countIntervals(arr : OclAny, V : OclAny, N : OclAny) pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, N-1) do ( var li : OclAny := arr[i+1]->first() ; var ri : OclAny := arr[i+1][1+1] ; if ((V->compareTo(li)) >= 0 & (V->compareTo(ri)) <= 0) then ( count := count + 1 ) else skip) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isMajority(a): mp={} for i in a : if i in mp : mp[i]+=1 else : mp[i]=1 for x in mp : if mp[x]>=len(a)//2 : return True return False a=[2,3,9,2,2] print("Yes" if isMajority(a)else "No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{2}->union(Sequence{3}->union(Sequence{9}->union(Sequence{2}->union(Sequence{ 2 })))) ; execute (if isMajority(a) then "Yes" else "No" endif)->display(); operation isMajority(a : OclAny) : OclAny pre: true post: true activity: var mp : OclAny := Set{} ; for i : a do ( if (mp)->includes(i) then ( mp[i+1] := mp[i+1] + 1 ) else ( mp[i+1] := 1 )) ; for x : mp do ( if (mp[x+1]->compareTo((a)->size() div 2)) >= 0 then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- li=list(map(int,input().split())) n=li[0] m=li[1] if(ncollect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := li->first() ; var m : OclAny := li[1+1] ; if ((n->compareTo(m)) < 0) then ( Sequence{n,m} := Sequence{m,n} ) else skip ; var num : double := ((n)->pow(2)) - ((m)->pow(2)) ; var dem : double := 2 * m ; execute (num / dem)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- li=list(map(int,input().split())) n=li[0] m=li[1] if(ncollect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := li->first() ; var m : OclAny := li[1+1] ; if ((n->compareTo(m)) < 0) then ( Sequence{n,m} := Sequence{m,n} ) else skip ; var num : double := ((n)->pow(2)) - ((m)->pow(2)) ; var dem : double := 2 * m ; execute (num / dem)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline H,L=map(int,input().split()) print((L**2-H**2)/(2*H)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var H : OclAny := null; var L : OclAny := null; Sequence{H,L} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (((L)->pow(2) - (H)->pow(2)) / (2 * H))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,l=map(float,input().split()) print(-(h**2-l**2)/(2*h)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var l : OclAny := null; Sequence{h,l} := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; execute (-((h)->pow(2) - (l)->pow(2)) / (2 * h))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def findDigits(n): if(n<0): return 0 ; if(n<=1): return 1 ; digits=0 ; for i in range(2,n+1): digits+=math.log10(i); return math.floor(digits)+1 ; print(findDigits(1)); print(findDigits(5)); print(findDigits(10)); print(findDigits(120)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; execute (findDigits(1))->display(); ; execute (findDigits(5))->display(); ; execute (findDigits(10))->display(); ; execute (findDigits(120))->display();; operation findDigits(n : OclAny) pre: true post: true activity: if (n < 0) then ( return 0; ) else skip ; if (n <= 1) then ( return 1; ) else skip ; var digits : int := 0; ; for i : Integer.subrange(2, n + 1-1) do ( digits := digits + (i)->log10();) ; return (digits)->floor() + 1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline()[:-1] sys.setrecursionlimit(10**8) from collections import deque n=int(input()) G=[0]*n memo=[0]*n dis=[0]*n dis[0]=1 que=deque() que.append((0,1)) for i in range(n): inp=tuple(map(int,input().split())) G[inp[0]-1]=inp[2 :] while que : vertex,d=que.popleft() for v in G[vertex]: if not dis[v-1]: dis[v-1]=d+1 que.append((v-1,d+1)) for i in range(n): print(i+1,dis[i]-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine()->front()) ; sys.setrecursionlimit((10)->pow(8)) ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var G : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var memo : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var dis : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; dis->first() := 1 ; var que : Sequence := () ; execute ((Sequence{0, 1}) : que) ; for i : Integer.subrange(0, n-1) do ( var inp : Sequence := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; G[inp->first() - 1+1] := inp.subrange(2+1)) ; while que do ( var vertex : OclAny := null; var d : OclAny := null; Sequence{vertex,d} := que->first() ; que := que->tail() ; for v : G[vertex+1] do ( if not(dis[v - 1+1]) then ( dis[v - 1+1] := d + 1 ; execute ((Sequence{v - 1, d + 1}) : que) ) else skip)) ; for i : Integer.subrange(0, n-1) do ( execute (i + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import copy import sys import fractions import decimal import heapq import collections import itertools import bisect sys.setrecursionlimit(100001) def getInputIntList(): outputDataList=[] inputData=input().split() outputDataList=[int(n)for n in inputData] return outputDataList def getSomeInputInt(n): outputDataList=[] for i in range(n): inputData=int(input()) outputDataList.append(inputData) return outputDataList def getSomeInputListInt(n): inputDataList=[] outputDataList=[] for i in range(n): inputData=input().split() inputDataList=[int(n)for n in inputData] outputDataList.append(inputDataList) return outputDataList n=int(input()) adj=[list(map(int,input().split()))[2 :]for _ in range(n)] d=[-1]*n for a in adj : for i in range(len(a)): a[i]-=1 s=0 q=collections.deque([]) d[s]=0 q.append(s) while len(q): u=q.popleft() v=adj[u] for vi in v : if d[vi]==-1 : d[vi]=d[u]+1 q.append(vi) elif d[vi]>d[u]+1 : d[vi]=d[u]+1 q.append(vi) for i,di in enumerate(d): print(i+1,di) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(100001) ; skip ; skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var adj : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(2+1))) ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; for a : adj do ( for i : Integer.subrange(0, (a)->size()-1) do ( a[i+1] := a[i+1] - 1)) ; var s : int := 0 ; var q : Sequence := (Sequence{}) ; d[s+1] := 0 ; execute ((s) : q) ; while (q)->size() do ( var u : OclAny := q->first() ; q := q->tail() ; var v : OclAny := adj[u+1] ; for vi : v do ( if d[vi+1] = -1 then ( d[vi+1] := d[u+1] + 1 ; execute ((vi) : q) ) else (if (d[vi+1]->compareTo(d[u+1] + 1)) > 0 then ( d[vi+1] := d[u+1] + 1 ; execute ((vi) : q) ) else skip))) ; for _tuple : Integer.subrange(1, (d)->size())->collect( _indx | Sequence{_indx-1, (d)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var di : OclAny := _tuple->at(_indx); execute (i + 1)->display()); operation getInputIntList() : OclAny pre: true post: true activity: var outputDataList : Sequence := Sequence{} ; var inputData : OclAny := input().split() ; outputDataList := inputData->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; return outputDataList; operation getSomeInputInt(n : OclAny) : OclAny pre: true post: true activity: outputDataList := Sequence{} ; for i : Integer.subrange(0, n-1) do ( inputData := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((inputData) : outputDataList)) ; return outputDataList; operation getSomeInputListInt(n : OclAny) : OclAny pre: true post: true activity: var inputDataList : Sequence := Sequence{} ; outputDataList := Sequence{} ; for i : Integer.subrange(0, n-1) do ( inputData := input().split() ; inputDataList := inputData->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; execute ((inputDataList) : outputDataList)) ; return outputDataList; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque from typing import List import sys def bfs(adj_list : List[List[int]])->List[int]: n=len(adj_list) result : List[int]=[sys.maxsize for _ in range(n)] result[0]=0 queue : deque=deque() queue.append(0) while len(queue)>0 : cur=queue.popleft() for vertex in adj_list[cur]: if result[cur]+1toInteger() ; var adj_list : OclAny := Integer.subrange(0, num_vertices-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, num_vertices-1) do ( var vertex : OclAny := null; var num_adjs : OclAny := null; var adjs : OclAny := null; Sequence{vertex,num_adjs,adjs} := (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) ) ; for i : Integer.subrange(0, num_adjs-1) do ((expr (atom (name adj_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name vertex))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name adjs)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (number (integer 1)))))))))) )))))) ; result := bfs(adj_list) ; for i : Integer.subrange(0, num_vertices-1) do ( if (trailer . (name maxsize)) = result[i+1] then ( result[i+1] := -1 ) else skip ; execute (StringLib.formattedString("{i+1}{result[i]}"))->display()) ) else skip; operation bfs(adj_list : List[List[OclType["int"]+1]+1]) : OclAny pre: true post: true activity: var n : int := (adj_list)->size() ; var result : OclAny := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((trailer . (name maxsize)))) ; result->first() := 0 ; var queue : Sequence := () ; execute ((0) : queue) ; while (queue)->size() > 0 do ( var cur : OclAny := queue->first() ; queue := queue->tail() ; for vertex : adj_list[cur+1] do ( if (result[cur+1] + 1->compareTo(result[vertex+1])) < 0 then ( result[vertex+1] := result[cur+1] + 1 ; execute ((vertex) : queue) ) else skip)) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) class Node : def __init__(self,idd,neighbors): self.idd=idd self.neighbors=neighbors self.dist=-1 def __repr__(self): return "{0}{1}".format(self.idd,self.dist) def breadthFirstSearch(Nodes): stack=[Nodes[0]] Nodes[0].dist=0 while len(stack)>0 : current=stack.pop(0) for v in current.neighbors : v_node=Nodes[v-1] if(v_node.dist==-1): v_node.dist=current.dist+1 stack.append(v_node) else : v_node.dist=v_node.dist if v_node.distexists( _x | result = _x ); attribute idd : OclAny := idd; attribute neighbors : OclAny := neighbors; attribute dist : int := -1; operation initialise(idd : OclAny,neighbors : OclAny) : Node pre: true post: true activity: self.idd := idd ; self.neighbors := neighbors ; self.dist := -1; return self; operation __repr__() : OclAny pre: true post: true activity: return StringLib.interpolateStrings("{0}{1}", Sequence{self.idd, self.dist}); } class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; skip ; Nodes := MatrixLib.elementwiseMult(Sequence{ null }, n) ; for i : Integer.subrange(0, n-1) do ( var row : Sequence := input().split()->select(tt | true)->collect(tt | (("" + ((tt)))->toInteger())) ; Nodes[row->first() - 1+1] := (Node.newNode()).initialise(row->first(), Integer.subrange(0, row[1+1]-1)->select(j | true)->collect(j | (row[j + 2+1])))) ; Nodes := breadthFirstSearch(Nodes) ; for node : Nodes do ( execute (node)->display()); operation breadthFirstSearch(Nodes : OclAny) : OclAny pre: true post: true activity: var stack : Sequence := Sequence{ Nodes->first() } ; Nodes->first().dist := 0 ; while (stack)->size() > 0 do ( var current : OclAny := stack->at(0`firstArg+1) ; stack := stack->excludingAt(0+1) ; for v : current.neighbors do ( var v_node : OclAny := Nodes[v - 1+1] ; if (v_node.dist = -1) then ( v_node.dist := current.dist + 1 ; execute ((v_node) : stack) ) else ( v_node.dist := if (v_node.dist->compareTo(current.dist + 1)) < 0 then v_node.dist else current.dist + 1 endif ))) ; return Nodes; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from heapq import heappush,heappop from itertools import permutations import sys import math import bisect def LI(): return[int(x)for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return[list(x)for x in sys.stdin.readline().split()] def S(): res=list(sys.stdin.readline()) if res[-1]=="\n" : return res[:-1] return res def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] sys.setrecursionlimit(1000000) mod=1000000007 def solve(): n=I() v=[] for i in range(n): e=LI() u=e[2 :] for i in range(len(u)): u[i]-=1 v.append(u) d=[-1]*n d[0]=0 q=deque([0]) while q : x=q.popleft() nd=d[x]+1 for y in v[x]: if d[y]<0 : d[y]=nd q.append(y) for i in range(n): print(i+1,d[i]) return if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1000000) ; var mod : int := 1000000007 ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | ((x))); operation S() : OclAny pre: true post: true activity: var res : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if res->last() = "\n" then ( return res->front() ) else skip ; return res; operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation solve() pre: true post: true activity: n := I() ; var v : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var e : OclAny := LI() ; var u : OclAny := e.subrange(2+1) ; for i : Integer.subrange(0, (u)->size()-1) do ( u[i+1] := u[i+1] - 1) ; execute ((u) : v)) ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; d->first() := 0 ; var q : Sequence := (Sequence{ 0 }) ; while q do ( var x : OclAny := q->first() ; q := q->tail() ; var nd : OclAny := d[x+1] + 1 ; for y : v[x+1] do ( if d[y+1] < 0 then ( d[y+1] := nd ; execute ((y) : q) ) else skip)) ; for i : Integer.subrange(0, n-1) do ( execute (i + 1)->display()) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,m=map(int,input().split()) DP=[0]*(n+5) CUM=[1]*(n+5) CUM[1]=0 DP[1]=1 S=1 for i in range(2,n+1): CUM[i]=(CUM[i-1]+CUM[i])% m DP[i]=(S+CUM[i])% m S+=DP[i] S %=m for j in range(i+i,n+1,i): CUM[j]=(CUM[j]+DP[i]-DP[i-1])% m print(DP[n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var DP : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 5)) ; var CUM : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 5)) ; CUM[1+1] := 0 ; DP[1+1] := 1 ; var S : int := 1 ; for i : Integer.subrange(2, n + 1-1) do ( CUM[i+1] := (CUM[i - 1+1] + CUM[i+1]) mod m ; DP[i+1] := (S + CUM[i+1]) mod m ; S := S + DP[i+1] ; S := S mod m ; for j : Integer.subrange(i + i, n + 1-1)->select( $x | ($x - i + i) mod i = 0 ) do ( CUM[j+1] := (CUM[j+1] + DP[i+1] - DP[i - 1+1]) mod m)) ; execute (DP[n+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,k=map(int,input().split()) a=list(map(int,input().split())) has=False prop=n==1 for i in range(n): if a[i]==k : has=True if a[i]>=k and i>0 : if a[i-1]>=k : prop=True if i>1 and a[i-2]>=k : prop=True print("yes" if has and prop else "no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var has : boolean := false ; var prop : boolean := n = 1 ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = k then ( has := true ) else skip ; if (a[i+1]->compareTo(k)) >= 0 & i > 0 then ( if (a[i - 1+1]->compareTo(k)) >= 0 then ( prop := true ) else skip ; if i > 1 & (a[i - 2+1]->compareTo(k)) >= 0 then ( prop := true ) else skip ) else skip) ; execute (if has & prop then "yes" else "no" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def msbPos(n): msb_p=-1 while(n>0): n=n>>1 msb_p+=1 return msb_p def andOperator(x,y): res=0 while(x>0 and y>0): msb_p1=msbPos(x) msb_p2=msbPos(y) if(msb_p1!=msb_p2): break msb_val=(1<display(); operation msbPos(n : OclAny) : OclAny pre: true post: true activity: var msb_p : int := -1 ; while (n > 0) do ( n := n /(2->pow(1)) ; msb_p := msb_p + 1) ; return msb_p; operation andOperator(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; while (x > 0 & y > 0) do ( var msb_p1 : OclAny := msbPos(x) ; var msb_p2 : OclAny := msbPos(y) ; if (msb_p1 /= msb_p2) then ( break ) else skip ; var msb_val : int := (1 * (2->pow(msb_p1))) ; res := res + msb_val ; x := x - msb_val ; y := y - msb_val) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def largestCube(r): if(r<0): return-1 a=(2*r)/sqrt(3) return a if __name__=='__main__' : r=5 print("{0:.6}".format(largestCube(r))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( r := 5 ; execute (StringLib.interpolateStrings("{0:.6}", Sequence{largestCube(r)}))->display() ) else skip; operation largestCube(r : OclAny) : OclAny pre: true post: true activity: if (r < 0) then ( return -1 ) else skip ; var a : double := (2 * r) / sqrt(3) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numberOfPaths(m,n): for i in range(n,(m+n-1)): path*=i ; path//=(i-n+1); return path ; print(numberOfPaths(3,3)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (numberOfPaths(3, 3))->display();; operation numberOfPaths(m : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(n, (m + n - 1)-1) do ( path := path * i; ; path := path div (i - n + 1);) ; return path;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,m=map(int,input().split()) s=input() mem=set() base=ord("a")-1 mod1=1000000007 mod2=2147483647 h1=[0] h2=[0] for c in s : h1.append((h1[-1]*27+ord(c)-base)% mod1) h2.append((h2[-1]*27+ord(c)-base)% mod2) pow_mem1={0 : 1} pow_mem2={0 : 1} def my_pow1(x): if x in pow_mem1 : return pow_mem1[x] pow_mem1[x]=my_pow1(x-1)*27 % mod1 return pow_mem1[x] def my_pow2(x): if x in pow_mem2 : return pow_mem2[x] pow_mem2[x]=my_pow2(x-1)*27 % mod2 return pow_mem2[x] left=right=1 for _ in range(m): com=input() if com=="L++" : left+=1 if com=="L--" : left-=1 if com=="R++" : right+=1 if com=="R--" : right-=1 x=(h1[right]-h1[left-1]*my_pow1(right-left+1))% mod1 y=(h2[right]-h2[left-1]*my_pow2(right-left+1))% mod2 mem.add((x,y)) print(len(mem)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var mem : Set := Set{}->union(()) ; var base : double := ("a")->char2byte() - 1 ; var mod1 : int := 1000000007 ; var mod2 : int := 2147483647 ; var h1 : Sequence := Sequence{ 0 } ; var h2 : Sequence := Sequence{ 0 } ; for c : s->characters() do ( execute (((h1->last() * 27 + (c)->char2byte() - base) mod mod1) : h1) ; execute (((h2->last() * 27 + (c)->char2byte() - base) mod mod2) : h2)) ; var pow_mem1 : Map := Map{ 0 |-> 1 } ; var pow_mem2 : Map := Map{ 0 |-> 1 } ; skip ; skip ; var left : OclAny := 1; var right : int := 1 ; for _anon : Integer.subrange(0, m-1) do ( var com : String := (OclFile["System.in"]).readLine() ; if com = "L++" then ( left := left + 1 ) else skip ; if com = "L--" then ( left := left - 1 ) else skip ; if com = "R++" then ( right := right + 1 ) else skip ; if com = "R--" then ( right := right - 1 ) else skip ; x := (h1[right+1] - h1[left - 1+1] * my_pow1(right - left + 1)) mod mod1 ; var y : int := (h2[right+1] - h2[left - 1+1] * my_pow2(right - left + 1)) mod mod2 ; execute ((Sequence{x, y}) : mem)) ; execute ((mem)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import random n,m=map(int,input().split()) s=input() base1=1007 mod1=10**9+7 base2=2009 mod2=10**9+9 modTank1=[3000012541,3000012553,3000012563,3000012649,3000012683,3000012709] mod1=modTank1[random.randint(0,5)] modTank2=[3000014753,3000014783,3000014833,3000014839,3000014891,3000015433] mod2=modTank2[random.randint(0,5)] hash1=[0]*(n+1) power1=[1]*(n+1) hash2=[0]*(n+1) power2=[1]*(n+1) for i,e in enumerate(s): hash1[i+1]=(hash1[i]*base1+ord(e))% mod1 power1[i+1]=(power1[i]*base1)% mod1 hash2[i+1]=(hash2[i]*base2+ord(e))% mod2 power2[i+1]=(power2[i]*base2)% mod2 res=0 tank1=set() L=0 R=1 for _ in range(m): q=input() if q=='L++' : L+=1 elif q=='L--' : L-=1 elif q=='R++' : R+=1 else : R-=1 hashData1=((hash1[R]-hash1[L]*power1[R-L]% mod1)% mod1)*(10**10)+(hash2[R]-hash2[L]*power2[R-L]% mod2)% mod2 if hashData1 in tank1 : res+=1 tank1.add(hashData1) print(len(tank1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var base1 : int := 1007 ; var mod1 : double := (10)->pow(9) + 7 ; var base2 : int := 2009 ; var mod2 : double := (10)->pow(9) + 9 ; var modTank1 : Sequence := Sequence{3000012541}->union(Sequence{3000012553}->union(Sequence{3000012563}->union(Sequence{3000012649}->union(Sequence{3000012683}->union(Sequence{ 3000012709 }))))) ; mod1 := modTank1[(0 + (OclRandom.defaultInstanceOclRandom()).nextInt(5 - 0))+1] ; var modTank2 : Sequence := Sequence{3000014753}->union(Sequence{3000014783}->union(Sequence{3000014833}->union(Sequence{3000014839}->union(Sequence{3000014891}->union(Sequence{ 3000015433 }))))) ; mod2 := modTank2[(0 + (OclRandom.defaultInstanceOclRandom()).nextInt(5 - 0))+1] ; var hash1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var power1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ; var hash2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var power2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var e : OclAny := _tuple->at(_indx); hash1[i + 1+1] := (hash1[i+1] * base1 + (e)->char2byte()) mod mod1 ; power1[i + 1+1] := (power1[i+1] * base1) mod mod1 ; hash2[i + 1+1] := (hash2[i+1] * base2 + (e)->char2byte()) mod mod2 ; power2[i + 1+1] := (power2[i+1] * base2) mod mod2) ; var res : int := 0 ; var tank1 : Set := Set{}->union(()) ; var L : int := 0 ; var R : int := 1 ; for _anon : Integer.subrange(0, m-1) do ( var q : String := (OclFile["System.in"]).readLine() ; if q = 'L++' then ( L := L + 1 ) else (if q = 'L--' then ( L := L - 1 ) else (if q = 'R++' then ( R := R + 1 ) else ( R := R - 1 ) ) ) ; var hashData1 : double := ((hash1[R+1] - hash1[L+1] * power1[R - L+1] mod mod1) mod mod1) * ((10)->pow(10)) + (hash2[R+1] - hash2[L+1] * power2[R - L+1] mod mod2) mod mod2 ; if (tank1)->includes(hashData1) then ( res := res + 1 ) else skip ; execute ((hashData1) : tank1)) ; execute ((tank1)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=float('inf') MOD=10**9+7 def inpl(): return list(map(int,input().split())) class RollingHash : def __init__(self,s,base,mod): self.s=s self.length=length=len(s) self.base=base self.mod=mod self.h=h=[0]*(length+1) for i in range(length): h[i+1]=(h[i]*base+ord(s[i]))% mod self.p=p=[1]*(length+1) for i in range(length): p[i+1]=pow(base,i+1,mod) def get(self,l,r): mod=self.mod return((self.h[r]-self.h[l]*self.p[r-l])+mod)% mod def solve(): N,M=inpl() S=input() h1=RollingHash(S,13,MOD) h2=RollingHash(S,17,MOD) left,right=0,1 vs=set() ans=0 for i in range(M): q=input() if q=='R++' : right+=1 elif q=='R--' : right-=1 elif q=='L++' : left+=1 else : left-=1 v=(h1.get(left,right),h2.get(left,right)) if v not in vs : ans+=1 vs.add(v) return ans print(solve()) ------------------------------------------------------------ OCL File: --------- class RollingHash { static operation newRollingHash() : RollingHash pre: true post: RollingHash->exists( _x | result = _x ); attribute s : OclAny := s; attribute length : OclAny := (s)->size(); var length : int := (s)->size(); attribute base : OclAny := base; attribute mod : OclAny := mod; attribute h : OclAny := MatrixLib.elementwiseMult(Sequence{ 0 }, (length + 1)); var h : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (length + 1)); attribute p : OclAny := MatrixLib.elementwiseMult(Sequence{ 1 }, (length + 1)); var p : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (length + 1)); operation initialise(s : OclAny,base : OclAny,mod : OclAny) : RollingHash pre: true post: true activity: self.s := s ; self.length := (s)->size(); var length : int := (s)->size() ; self.base := base ; self.mod := mod ; self.h := MatrixLib.elementwiseMult(Sequence{ 0 }, (length + 1)); var h : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (length + 1)) ; for i : Integer.subrange(0, length-1) do ( h[i + 1+1] := (h[i+1] * base + (s[i+1])->char2byte()) mod mod) ; self.p := MatrixLib.elementwiseMult(Sequence{ 1 }, (length + 1)); var p : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (length + 1)) ; for i : Integer.subrange(0, length-1) do ( p[i + 1+1] := (base)->pow(i + 1)); return self; operation get(l : OclAny,r : OclAny) : OclAny pre: true post: true activity: mod := self.mod ; return ((self.h[r+1] - self.h[l+1] * self.p[r - l+1]) + mod) mod mod; } class FromPython { operation initialise() pre: true post: true activity: var INF : double := ("" + (('inf')))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; execute (solve())->display(); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation solve() : OclAny pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := inpl() ; var S : String := (OclFile["System.in"]).readLine() ; var h1 : RollingHash := (RollingHash.newRollingHash()).initialise(S, 13, MOD) ; var h2 : RollingHash := (RollingHash.newRollingHash()).initialise(S, 17, MOD) ; var left : OclAny := null; var right : OclAny := null; Sequence{left,right} := Sequence{0,1} ; var vs : Set := Set{}->union(()) ; var ans : int := 0 ; for i : Integer.subrange(0, M-1) do ( var q : String := (OclFile["System.in"]).readLine() ; if q = 'R++' then ( right := right + 1 ) else (if q = 'R--' then ( right := right - 1 ) else (if q = 'L++' then ( left := left + 1 ) else ( left := left - 1 ) ) ) ; var v : OclAny := Sequence{h1.get(left, right), h2.get(left, right)} ; if (vs)->excludes(v) then ( ans := ans + 1 ; execute ((v) : vs) ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,data): self.data=data self.left=None self.right=None def newNode(data): temp=Node(0) temp.data=data temp.left=temp.right=None return temp def maxOfRightElement(root): res=-999999 if(root==None): return-1 if(root.right!=None): res=root.right.data return max(maxOfRightElement(root.right),res,maxOfRightElement(root.left)) root=newNode(7) root.left=newNode(6) root.right=newNode(5) root.left.left=newNode(4) root.left.right=newNode(3) root.right.left=newNode(2) root.right.right=newNode(1) print(maxOfRightElement(root)) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.left := null ; self.right := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; root := newNode(7) ; root.left := newNode(6) ; root.right := newNode(5) ; root.left.left := newNode(4) ; root.left.right := newNode(3) ; root.right.left := newNode(2) ; root.right.right := newNode(1) ; execute (maxOfRightElement(root))->display(); operation newNode(data : OclAny) : OclAny pre: true post: true activity: var temp : Node := (Node.newNode()).initialise(0) ; temp.data := data ; temp.left := null; var temp.right : OclAny := null ; return temp; operation maxOfRightElement(root : OclAny) : OclAny pre: true post: true activity: var res : int := -999999 ; if (root = null) then ( return -1 ) else skip ; if (root.right /= null) then ( res := root.right.data ) else skip ; return Set{maxOfRightElement(root.right), res, maxOfRightElement(root.left)}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def removeElements(arr,n): brr=[0]*n ; l=1 ; brr[0]=arr[0]; for i in range(1,n): if(brr[l-1]<=arr[i]): brr[l]=arr[i]; l+=1 ; for i in range(l): print(brr[i],end=" "); if __name__=="__main__" : arr=[10,12,9,10,2,13,14]; n=len(arr); removeElements(arr,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{10}->union(Sequence{12}->union(Sequence{9}->union(Sequence{10}->union(Sequence{2}->union(Sequence{13}->union(Sequence{ 14 })))))); ; n := (arr)->size(); ; removeElements(arr, n); ) else skip; operation removeElements(arr : OclAny, n : OclAny) pre: true post: true activity: var brr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); var l : int := 1; ; brr->first() := arr->first(); ; for i : Integer.subrange(1, n-1) do ( if ((brr[l - 1+1]->compareTo(arr[i+1])) <= 0) then ( brr[l+1] := arr[i+1]; ; l := l + 1; ) else skip) ; for i : Integer.subrange(0, l-1) do ( execute (brr[i+1])->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minSteps(arr,N): s=[]; s.append((0,-1)); maxStepsToeliminate=-1 ; for i in range(1,N): stepsToeliminate=1 ; while(len(s)!=0): if(arr[s[-1][0]]>=arr[i]): stepsToeliminate=max(stepsToeliminate,s[-1][1]+1); s.pop(); else : break ; if(len(s)==0): stepsToeliminate=-1 ; maxStepsToeliminate=max(maxStepsToeliminate,stepsToeliminate); s.append((i,stepsToeliminate)); print(0 if(maxStepsToeliminate<0)else maxStepsToeliminate); if __name__=="__main__" : arr=[3,2,1,7,5]; size=len(arr); minSteps(arr,size); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{3}->union(Sequence{2}->union(Sequence{1}->union(Sequence{7}->union(Sequence{ 5 })))); ; var size : int := (arr)->size(); ; minSteps(arr, size); ) else skip; operation minSteps(arr : OclAny, N : OclAny) pre: true post: true activity: var s : Sequence := Sequence{}; ; execute ((Sequence{0, -1}) : s); ; var maxStepsToeliminate : int := -1; ; for i : Integer.subrange(1, N-1) do ( var stepsToeliminate : int := 1; ; while ((s)->size() /= 0) do ( if ((arr[s->last()->first()+1]->compareTo(arr[i+1])) >= 0) then ( stepsToeliminate := Set{stepsToeliminate, s->last()[1+1] + 1}->max(); ; s := s->front(); ) else ( break; )) ; if ((s)->size() = 0) then ( stepsToeliminate := -1; ) else skip ; maxStepsToeliminate := Set{maxStepsToeliminate, stepsToeliminate}->max(); ; execute ((Sequence{i, stepsToeliminate}) : s);) ; execute (if (maxStepsToeliminate < 0) then 0 else maxStepsToeliminate endif)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=int(input().split(" ")[1]) lookup_table={} for _ in range(m): word_one,word_two=input().split(" ") min_word=min(word_one,word_two,key=len) lookup_table[word_one]=min_word lookup_table[word_two]=min_word final_sentence=input().split(" ") print(" ".join([lookup_table[word]for word in final_sentence])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : int := ("" + ((input().split(" ")[1+1])))->toInteger() ; var lookup_table : OclAny := Set{} ; for _anon : Integer.subrange(0, m-1) do ( var word_one : OclAny := null; var word_two : OclAny := null; Sequence{word_one,word_two} := input().split(" ") ; var min_word : OclAny := Set{word_one, word_two, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name len)))))))}->min() ; lookup_table[word_one+1] := min_word ; lookup_table[word_two+1] := min_word) ; var final_sentence : OclAny := input().split(" ") ; execute (StringLib.sumStringsWithSeparator((final_sentence->select(word | true)->collect(word | (lookup_table[word+1]))), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,w=map(int,input().split()) vw_l=[[int(x)for x in input().split()]for y in range(n)] dp=[[0]*(w+1)for y in range(n+1)] for i in range(n): _v,_w=vw_l[i] for j in range(w+1): if j<_w : dp[i+1][j]=dp[i][j] else : dp[i+1][j]=max(dp[i+1][j-_w]+_v,dp[i][j]) print(dp[n][w]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var w : OclAny := null; Sequence{n,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var vw_l : Sequence := Integer.subrange(0, n-1)->select(y | true)->collect(y | (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))) ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(y | true)->collect(y | (MatrixLib.elementwiseMult(Sequence{ 0 }, (w + 1)))) ; for i : Integer.subrange(0, n-1) do ( var _v : OclAny := null; var _w : OclAny := null; Sequence{_v,_w} := vw_l[i+1] ; for j : Integer.subrange(0, w + 1-1) do ( if (j->compareTo(_w)) < 0 then ( dp[i + 1+1][j+1] := dp[i+1][j+1] ) else ( dp[i + 1+1][j+1] := Set{dp[i + 1+1][j - _w+1] + _v, dp[i+1][j+1]}->max() ))) ; execute (dp[n+1][w+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inp1=input() n,m=int(inp1.split(' ')[0]),int(inp1.split(' ')[1]) l=[] d={} for i in range(m): inp2=input() s1,s2=(inp2.split(' ')[0]),(inp2.split(' ')[1]) l1,l2=len(inp2.split(' ')[0]),len(inp2.split(' ')[1]) if l1<=l2 : d[s2]=s1 else : d[s1]=s2 inp3=input() lis1=inp3.split(' ') lis2=[] for i in lis1 : if i in d.keys(): lis2.append(d[i]) else : lis2.append(i) output="" for i in lis2 : output=output+i+' ' print(output) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inp1 : String := (OclFile["System.in"]).readLine() ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{("" + ((inp1.split(' ')->first())))->toInteger(),("" + ((inp1.split(' ')[1+1])))->toInteger()} ; var l : Sequence := Sequence{} ; var d : OclAny := Set{} ; for i : Integer.subrange(0, m-1) do ( var inp2 : String := (OclFile["System.in"]).readLine() ; var s1 : OclAny := null; var s2 : OclAny := null; Sequence{s1,s2} := Sequence{(inp2.split(' ')->first()),(inp2.split(' ')[1+1])} ; var l1 : OclAny := null; var l2 : OclAny := null; Sequence{l1,l2} := Sequence{(inp2.split(' ')->first())->size(),(inp2.split(' ')[1+1])->size()} ; if (l1->compareTo(l2)) <= 0 then ( d[s2+1] := s1 ) else ( d[s1+1] := s2 )) ; var inp3 : String := (OclFile["System.in"]).readLine() ; var lis1 : OclAny := inp3.split(' ') ; var lis2 : Sequence := Sequence{} ; for i : lis1 do ( if (d.keys())->includes(i) then ( execute ((d[i+1]) : lis2) ) else ( execute ((i) : lis2) )) ; var output : String := "" ; for i : lis2 do ( output := output + i + ' ') ; execute (output)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def length(str): count=0 ; flag=False ; length=len(str)-1 ; while(length!=0): if(str[length]==' '): return count ; else : count+=1 ; length-=1 ; return count ; str="Geeks for Geeks" ; print("The length of last word is",length(str)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclType["String"] := "Geeks for Geeks"; ; execute ("The length of last word is")->display();; operation length(OclType["String"] : OclAny) pre: true post: true activity: var count : int := 0; ; var flag : boolean := false; ; var length : double := (OclType["String"])->size() - 1; ; while (length /= 0) do ( if (("" + ([length+1])) = ' ') then ( return count; ) else ( count := count + 1; ) ; length := length - 1;) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- first_line=input().split() dic={} for i in range(int(first_line[1])): second_line=input().split() dic[second_line[0]]=second_line[1] last_line=input().split() for i in last_line : if len(i)==len(dic[i]): print(i,end=' ') elif len(i)toInteger()-1) do ( var second_line : OclAny := input().split() ; dic[second_line->first()+1] := second_line[1+1]) ; var last_line : OclAny := input().split() ; for i : last_line do ( if (i)->size() = (dic[i+1])->size() then ( execute (i)->display() ) else (if ((i)->size()->compareTo((dic[i+1])->size())) < 0 then ( execute (i)->display() ) else ( execute (dic[i+1])->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,l=tuple(map(int,input().split())) ans='' wordlist={} for i in range(l): x,y=tuple(input().split()) wordlist[x]=y prof=input() for i in prof.split(): if len(wordlist[i])collect( _x | (OclType["int"])->apply(_x) )) ; var ans : String := '' ; var wordlist : OclAny := Set{} ; for i : Integer.subrange(0, l-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split()) ; wordlist[x+1] := y) ; var prof : String := (OclFile["System.in"]).readLine() ; for i : prof.split() do ( if ((wordlist[i+1])->size()->compareTo((i)->size())) < 0 then ( ans := ans + wordlist[i+1] + " " ) else ( ans := ans + i + " " )) ; execute (ans->front())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p=dict() n,m=map(int,input().split()) for _ in range(m): a,b=input().split() p[a]=[a,b][len(b)collect( _x | (OclType["int"])->apply(_x) ) ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; p[a+1] := Sequence{a}->union(Sequence{ b })->select(((b)->size()->compareTo((a)->size())) < 0)) ; execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name w)))))))) ])))))) (comp_for for (exprlist (expr (atom (name w)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( )))))))) ))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(H,S): return H*H>=4*S def findPairs(H,n,S,m): count=0 for i in range(n): for j in range(m): if check(H[i],S[j]): count+=1 return count if __name__=="__main__" : H=[1,6,4] n=len(H) S=[23,3,42,14] m=len(S) print(findPairs(H,n,S,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( H := Sequence{1}->union(Sequence{6}->union(Sequence{ 4 })) ; n := (H)->size() ; S := Sequence{23}->union(Sequence{3}->union(Sequence{42}->union(Sequence{ 14 }))) ; m := (S)->size() ; execute (findPairs(H, n, S, m))->display() ) else skip; operation check(H : OclAny, S : OclAny) : OclAny pre: true post: true activity: return (H * H->compareTo(4 * S)) >= 0; operation findPairs(H : OclAny, n : OclAny, S : OclAny, m : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if check(H[i+1], S[j+1]) then ( count := count + 1 ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100000 def Print3Smallest(arr,n): firstmin=MAX secmin=MAX thirdmin=MAX for i in range(0,n): if arr[i]size()-1) do ( if i mod 4 = 0 then ( execute ((s[i+1]) : s1) ) else (if i mod 4 = 1 then ( execute ((s[i+1]) : s2) ) else (if i mod 4 = 2 then ( execute ((s[i+1]) : s3) ) else ( execute ((s[i+1]) : s4) ) ) ) ) ; if (s1)->includes('R') then ( var ls_R : Sequence := s1 ) else (if (s2)->includes('R') then ( ls_R := s2 ) else (if (s3)->includes('R') then ( ls_R := s3 ) else ( ls_R := s4 ) ) ) ; if (s1)->includes('B') then ( var ls_B : Sequence := s1 ) else (if (s2)->includes('B') then ( ls_B := s2 ) else (if (s3)->includes('B') then ( ls_B := s3 ) else ( ls_B := s4 ) ) ) ; if (s1)->includes('Y') then ( var ls_Y : Sequence := s1 ) else (if (s2)->includes('Y') then ( ls_Y := s2 ) else (if (s3)->includes('Y') then ( ls_Y := s3 ) else ( ls_Y := s4 ) ) ) ; if (s1)->includes('G') then ( var ls_G : Sequence := s1 ) else (if (s2)->includes('G') then ( ls_G := s2 ) else (if (s3)->includes('G') then ( ls_G := s3 ) else ( ls_G := s4 ) ) ) ; execute (ls_R->count('!'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict s=(input()) d=defaultdict(int) for i,el in enumerate(s): if s!="!" : d[el]=i % 4 e=defaultdict(int) for i,el in enumerate(s): if el=="!" : e[i % 4]+=1 print(e[d["R"]],e[d["B"]],e[d["Y"]],e[d["G"]]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : String := ((OclFile["System.in"]).readLine()) ; var d : OclAny := defaultdict(OclType["int"]) ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var el : OclAny := _tuple->at(_indx); if s /= "!" then ( d[el+1] := i mod 4 ) else skip) ; var e : OclAny := defaultdict(OclType["int"]) ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var el : OclAny := _tuple->at(_indx); if el = "!" then ( e[i mod 4+1] := e[i mod 4+1] + 1 ) else skip) ; execute (e[d->at("R")+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def _input(): return map(int,input().split()) s=input() res=[0]*4 i=0 ss='' while icompareTo((s)->size())) < 0 & (ss)->size() < 4 do ( if s[i+1] /= '!' then ( ss := ss + s[i+1] ) else ( var j : int := i + 4 ; while (j->compareTo((s)->size())) < 0 & s[j+1] = '!' do ( j := j + 4) ; ss := ss + s[j+1] ) ; i := i + 1) ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = '!' then ( var k : OclAny := ss[i mod 4+1] ; if k = 'R' then ( res->first() := res->first() + 1 ) else skip ; if k = 'B' then ( res[1+1] := res[1+1] + 1 ) else skip ; if k = 'Y' then ( res[2+1] := res[2+1] + 1 ) else skip ; if k = 'G' then ( res[3+1] := res[3+1] + 1 ) else skip ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display(); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import string import fractions import random from operator import itemgetter import itertools from collections import deque import copy import heapq import bisect MOD=10**9+7 INF=float('inf') input=lambda : sys.stdin.readline().strip() sys.setrecursionlimit(10**8) N,W=map(int,input().split()) v=[0]*N w=[0]*N for i in range(N): v[i],w[i]=map(int,input().split()) dp=[[0]*(W+10)for _ in range(N+10)] for i in range(1,W+1): if i>=w[0]: dp[1][i]=max(v[0],dp[1][i-w[0]]+v[0]) for i in range(2,N+1): for j in range(1,W+1): if j-w[i-1]>=0 : dp[i][j]=max(dp[i-1][j],dp[i][j-w[i-1]]+v[i-1]) else : dp[i][j]=dp[i-1][j] print(dp[N][W]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var MOD : double := (10)->pow(9) + 7 ; var INF : double := ("" + (('inf')))->toReal() ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine()->trim()) ; sys.setrecursionlimit((10)->pow(8)) ; var N : OclAny := null; var W : OclAny := null; Sequence{N,W} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var v : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var w : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for i : Integer.subrange(0, N-1) do ( var v[i+1] : OclAny := null; var w[i+1] : OclAny := null; Sequence{v[i+1],w[i+1]} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dp : Sequence := Integer.subrange(0, N + 10-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (W + 10)))) ; for i : Integer.subrange(1, W + 1-1) do ( if (i->compareTo(w->first())) >= 0 then ( dp[1+1][i+1] := Set{v->first(), dp[1+1][i - w->first()+1] + v->first()}->max() ) else skip) ; for i : Integer.subrange(2, N + 1-1) do ( for j : Integer.subrange(1, W + 1-1) do ( if j - w[i - 1+1] >= 0 then ( dp[i+1][j+1] := Set{dp[i - 1+1][j+1], dp[i+1][j - w[i - 1+1]+1] + v[i - 1+1]}->max() ) else ( dp[i+1][j+1] := dp[i - 1+1][j+1] ))) ; execute (dp[N+1][W+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() countR=0 countB=0 countY=0 countG=0 for i in range(0,4): j=i count=0 letter=None while jcompareTo((s)->size())) < 0 do ( if s[j+1] = '!' then ( count := count + 1 ) else ( letter := s[j+1] ) ; j := j + 4) ; if letter = 'R' then ( countR := countR + count ) else (if letter = 'B' then ( countB := countB + count ) else (if letter = 'Y' then ( countY := countY + count ) else (if letter = 'G' then ( countG := countG + count ) else skip ) ) ) ) ; execute (countR)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dayofweek(d,m,y): t=[0,3,2,5,0,3,5,1,4,6,2,4] y-=m<3 return((y+int(y/4)-int(y/100)+int(y/400)+t[m-1]+d)% 7) day=dayofweek(30,8,2010) print(day) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var day : OclAny := dayofweek(30, 8, 2010) ; execute (day)->display(); operation dayofweek(d : OclAny, m : OclAny, y : OclAny) : OclAny pre: true post: true activity: var t : Sequence := Sequence{0}->union(Sequence{3}->union(Sequence{2}->union(Sequence{5}->union(Sequence{0}->union(Sequence{3}->union(Sequence{5}->union(Sequence{1}->union(Sequence{4}->union(Sequence{6}->union(Sequence{2}->union(Sequence{ 4 }))))))))))) ; y := y - m < 3 ; return ((y + ("" + ((y / 4)))->toInteger() - ("" + ((y / 100)))->toInteger() + ("" + ((y / 400)))->toInteger() + t[m - 1+1] + d) mod 7); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import pi,cos,sin r,_x,_y,n=map(int,input().split()) _m=list(map(int,input().split())) x,y=_x/r,_y/r m=sum(_m) t=[0.0]*(n+1) _t=0 a=[] for i in range(n): _t+=_m[i]/m*2*pi t[i+1]=_t a.append(int((1+((sin(t[i])*y-cos(t[i])*x)+(x*cos(t[i+1])-y*sin(t[i+1])))/(t[i+1]-t[i]))*100)) print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var r : OclAny := null; var _x : OclAny := null; var _y : OclAny := null; var n : OclAny := null; Sequence{r,_x,_y,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var _m : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{_x / r,_y / r} ; var m : OclAny := (_m)->sum() ; var t : Sequence := MatrixLib.elementwiseMult(Sequence{ 0.0 }, (n + 1)) ; var _t : int := 0 ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( _t := _t + _m[i+1] / m * 2 * pi ; t[i + 1+1] := _t ; execute ((("" + (((1 + ((sin(t[i+1]) * y - cos(t[i+1]) * x) + (x * cos(t[i + 1+1]) - y * sin(t[i + 1+1]))) / (t[i + 1+1] - t[i+1])) * 100)))->toInteger()) : a)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def powerNumbers(n): v=set(); v.add(1); for i in range(2,n+1): if(i*i<=n): j=i*i ; v.add(j); while(j*i<=n): v.add(j*i); j=j*i ; return len(v); print(powerNumbers(50)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (powerNumbers(50))->display();; operation powerNumbers(n : OclAny) pre: true post: true activity: var v : Set := Set{}->union(()); ; execute ((1) : v); ; for i : Integer.subrange(2, n + 1-1) do ( if ((i * i->compareTo(n)) <= 0) then ( var j : double := i * i; ; execute ((j) : v); ; while ((j * i->compareTo(n)) <= 0) do ( execute ((j * i) : v); ; j := j * i;) ) else skip) ; return (v)->size();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def productDivisible(n,k): product=1 position=1 while n>0 : if position % 2==0 : product*=n % 10 n=n/10 position+=1 if product % k==0 : return True return False n=321922 k=3 if productDivisible(n,k)==True : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 321922 ; k := 3 ; if productDivisible(n, k) = true then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); operation productDivisible(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var product : int := 1 ; var position : int := 1 ; while n > 0 do ( if position mod 2 = 0 then ( product := product * n mod 10 ) else skip ; n := n / 10 ; position := position + 1) ; if product mod k = 0 then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isDivisibleBy10(bin,n): if(bin[n-1]=='1'): return False sum=0 for i in range(n-2,-1,-1): if(bin[i]=='1'): posFromRight=n-i-1 if(posFromRight % 4==1): sum=sum+2 elif(posFromRight % 4==2): sum=sum+4 elif(posFromRight % 4==3): sum=sum+8 elif(posFromRight % 4==0): sum=sum+6 if(sum % 10==0): return True return False def isDivisibleBy20(bin,n): if(bin[n-1]=='1'): return false return isDivisibleBy10(bin,n-1) bin=['1','0','1','0','0','0'] n=len(bin) if(isDivisibleBy20(bin,n-1)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; bin := Sequence{'1'}->union(Sequence{'0'}->union(Sequence{'1'}->union(Sequence{'0'}->union(Sequence{'0'}->union(Sequence{ '0' }))))) ; n := (bin)->size() ; if (isDivisibleBy20(bin, n - 1)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isDivisibleBy10(bin : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (bin[n - 1+1] = '1') then ( return false ) else skip ; var sum : int := 0 ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( if (bin[i+1] = '1') then ( var posFromRight : double := n - i - 1 ; if (posFromRight mod 4 = 1) then ( sum := sum + 2 ) else (if (posFromRight mod 4 = 2) then ( sum := sum + 4 ) else (if (posFromRight mod 4 = 3) then ( sum := sum + 8 ) else (if (posFromRight mod 4 = 0) then ( sum := sum + 6 ) else skip ) ) ) ) else skip) ; if (sum mod 10 = 0) then ( return true ) else skip ; return false; operation isDivisibleBy20(bin : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (bin[n - 1+1] = '1') then ( return false ) else skip ; return isDivisibleBy10(bin, n - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def halfsquare(n,x,y): half=n//2 if((half==x or half==x-1)and(half==y or half==y-1)): print("NO") else : print("YES") if __name__=="__main__" : n=100 x,y=51,100 halfsquare(n,x,y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 100 ; Sequence{x,y} := Sequence{51,100} ; halfsquare(n, x, y) ) else skip; operation halfsquare(n : OclAny, x : OclAny, y : OclAny) pre: true post: true activity: var half : int := n div 2 ; if ((half = x or half = x - 1) & (half = y or half = y - 1)) then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=str(input()) if s=='Sunny' : print('Cloudy') elif s=='Cloudy' : print('Rainy') else : print('Sunny') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; if s = 'Sunny' then ( execute ('Cloudy')->display() ) else (if s = 'Cloudy' then ( execute ('Rainy')->display() ) else ( execute ('Sunny')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() sun="Sunny" cloud="Cloudy" rain="Rainy" if S==sun : print(cloud) elif S==cloud : print(rain) else : print(sun) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var sun : String := "Sunny" ; var cloud : String := "Cloudy" ; var rain : String := "Rainy" ; if S = sun then ( execute (cloud)->display() ) else (if S = cloud then ( execute (rain)->display() ) else ( execute (sun)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=["Sunny","Cloudy","Rainy"] s=input() print(l[(l.index(s)+1)% 3]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := Sequence{"Sunny"}->union(Sequence{"Cloudy"}->union(Sequence{ "Rainy" })) ; var s : String := (OclFile["System.in"]).readLine() ; execute (l[(l->indexOf(s) - 1 + 1) mod 3+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(N,W,data): dp=[0]*(W+1) for v,w in data : for i in range(w,W+1): dp[i]=max(dp[i-w]+v,dp[i]) return dp[-1] if __name__=='__main__' : N,W=map(int,input().split()) data=[tuple(map(int,input().split()))for _ in range(N)] print(solve(N,W,data)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( Sequence{N,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; data := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; execute (solve(N, W, data))->display() ) else skip; operation solve(N : OclAny, W : OclAny, data : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (W + 1)) ; for _tuple : data do (var _indx : int := 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var w : OclAny := _tuple->at(_indx); for i : Integer.subrange(w, W + 1-1) do ( dp[i+1] := Set{dp[i - w+1] + v, dp[i+1]}->max())) ; return dp->last(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def main(): S=input().strip() if S=="Sunny" : print("Cloudy") elif S=="Cloudy" : print("Rainy") else : print("Sunny") if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var S : OclAny := input()->trim() ; if S = "Sunny" then ( execute ("Cloudy")->display() ) else (if S = "Cloudy" then ( execute ("Rainy")->display() ) else ( execute ("Sunny")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): s=input() tenki=['Sunny','Cloudy','Rainy'] index=tenki.index(s) print(tenki[(index+1)% 3]) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var tenki : Sequence := Sequence{'Sunny'}->union(Sequence{'Cloudy'}->union(Sequence{ 'Rainy' })) ; var index : int := tenki->indexOf(s) - 1 ; execute (tenki[(index + 1) mod 3+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): while(a!=0): c=a ; a=b % a ; b=c ; return b ; def forbenius(X,Y): if(gcd(X,Y)!=1): print("NA"); return ; A=(X*Y)-(X+Y); N=(X-1)*(Y-1)//2 ; print("Largest Amount=",A); print("Total Count=",N); X=2 ; Y=5 ; forbenius(X,Y); X=5 ; Y=10 ; print(""); forbenius(X,Y); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; X := 2; ; Y := 5; ; forbenius(X, Y); ; X := 5; ; Y := 10; ; execute ("")->display(); ; forbenius(X, Y);; operation gcd(a : OclAny, b : OclAny) pre: true post: true activity: while (a /= 0) do ( var c : OclAny := a; ; a := b mod a; ; b := c;) ; return b;; operation forbenius(X : OclAny, Y : OclAny) : OclAny pre: true post: true activity: if (gcd(X, Y) /= 1) then ( execute ("NA")->display(); ; return; ) else skip ; var A : double := (X * Y) - (X + Y); ; var N : int := (X - 1) * (Y - 1) div 2; ; execute ("Largest Amount=")->display(); ; execute ("Total Count=")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def partSort(arr,N,a,b): l=min(a,b) r=max(a,b) temp=[0 for i in range(r-l+1)] j=0 for i in range(l,r+1,1): temp[j]=arr[i] j+=1 temp.sort(reverse=False) j=0 for i in range(l,r+1,1): arr[i]=temp[j] j+=1 for i in range(0,N,1): print(arr[i],end=" ") if __name__=='__main__' : arr=[7,8,4,5,2] a=1 b=4 N=len(arr) partSort(arr,N,a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{7}->union(Sequence{8}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 2 })))) ; a := 1 ; b := 4 ; N := (arr)->size() ; partSort(arr, N, a, b) ) else skip; operation partSort(arr : OclAny, N : OclAny, a : OclAny, b : OclAny) pre: true post: true activity: var l : OclAny := Set{a, b}->min() ; var r : OclAny := Set{a, b}->max() ; var temp : Sequence := Integer.subrange(0, r - l + 1-1)->select(i | true)->collect(i | (0)) ; var j : int := 0 ; for i : Integer.subrange(l, r + 1-1)->select( $x | ($x - l) mod 1 = 0 ) do ( temp[j+1] := arr[i+1] ; j := j + 1) ; temp := temp->sort() ; j := 0 ; for i : Integer.subrange(l, r + 1-1)->select( $x | ($x - l) mod 1 = 0 ) do ( arr[i+1] := temp[j+1] ; j := j + 1) ; for i : Integer.subrange(0, N-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : arr=[1,5,8,9,6,7,3,4,2,0] n=len(arr) arr.sort(reverse=True) print("Array after sorting : ") for i in range(n): print(arr[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var arr : Sequence := Sequence{1}->union(Sequence{5}->union(Sequence{8}->union(Sequence{9}->union(Sequence{6}->union(Sequence{7}->union(Sequence{3}->union(Sequence{4}->union(Sequence{2}->union(Sequence{ 0 }))))))))) ; var n : int := (arr)->size() ; arr := arr->sort() ; execute ("Array after sorting : ")->display() ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bestApproximate(x,y,n): sum_x=0 sum_y=0 sum_xy=0 sum_x2=0 for i in range(0,n): sum_x+=x[i] sum_y+=y[i] sum_xy+=x[i]*y[i] sum_x2+=pow(x[i],2) m=(float)((n*sum_xy-sum_x*sum_y)/(n*sum_x2-pow(sum_x,2))); c=(float)(sum_y-m*sum_x)/n ; print("m=",m); print("c=",c); x=[1,2,3,4,5] y=[14,27,40,55,68] n=len(x) bestApproximate(x,y,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ; y := Sequence{14}->union(Sequence{27}->union(Sequence{40}->union(Sequence{55}->union(Sequence{ 68 })))) ; n := (x)->size() ; bestApproximate(x, y, n); operation bestApproximate(x : OclAny, y : OclAny, n : OclAny) pre: true post: true activity: var sum_x : int := 0 ; var sum_y : int := 0 ; var sum_xy : int := 0 ; var sum_x2 : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum_x := sum_x + x[i+1] ; sum_y := sum_y + y[i+1] ; sum_xy := sum_xy + x[i+1] * y[i+1] ; sum_x2 := sum_x2 + (x[i+1])->pow(2)) ; var m : OclAny := (OclType["double"])((n * sum_xy - sum_x * sum_y) / (n * sum_x2 - (sum_x)->pow(2))); ; var c : double := (OclType["double"])(sum_y - m * sum_x) / n; ; execute ("m=")->display(); ; execute ("c=")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,data): self.data=data self.next=next head=None def push(head_ref,new_data): global head new_node=Node(0) new_node.data=new_data new_node.next=(head_ref) (head_ref)=new_node head=head_ref def productOfLastN_NodesUtil(head,n): if(n<=0): return 0 st=[] prod=1 while(head!=None): st.append(head.data) head=head.next while(n>0): n=n-1 prod*=st[-1] st.pop() return prod head=None push(head,12) push(head,4) push(head,8) push(head,6) push(head,10) n=2 print(productOfLastN_NodesUtil(head,n)) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := next; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.next := next; return self; } class FromPython { attribute head : OclAny; operation initialise() pre: true post: true activity: skip ; var head : OclAny := null ; skip ; var (head_ref) : OclAny := new_node; operation push(head_ref : OclAny, new_data : OclAny) pre: true post: true activity: skip ; var new_node : Node := (Node.newNode()).initialise(0) ; new_node.data := new_data ; new_node.next := (head_ref); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def modExp(a,b): result=1 while(b>0): if(int(b)& 1): result=result*a a=a*a b/=2 return result def check(num): if(num & 1 or num<3): return-1 elif(num % 4==0): return modExp(num/4,4) elif(num % 6==0): return modExp(num/3,2)*modExp(num/6,2) elif(num % 10==0): return modExp(num/5,2)*(num/10)*(num/2) else : return-1 if __name__=='__main__' : num=10 print(int(check(num))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( num := 10 ; execute (("" + ((check(num))))->toInteger())->display() ) else skip; operation modExp(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var result : int := 1 ; while (b > 0) do ( if (MathLib.bitwiseAnd(("" + ((b)))->toInteger(), 1)) then ( result := result * a ) else skip ; a := a * a ; b := b / 2) ; return result; operation check(num : OclAny) : OclAny pre: true post: true activity: if (MathLib.bitwiseAnd(num, 1) or num < 3) then ( return -1 ) else (if (num mod 4 = 0) then ( return modExp(num / 4, 4) ) else (if (num mod 6 = 0) then ( return modExp(num / 3, 2) * modExp(num / 6, 2) ) else (if (num mod 10 = 0) then ( return modExp(num / 5, 2) * (num / 10) * (num / 2) ) else ( return -1 ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,next=None,prev=None,data=None): self.next=next self.prev=prev self.data=data ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute next : OclAny := next; attribute prev : OclAny := prev; attribute data : OclAny := data; operation initialise(next : OclAny,prev : OclAny,data : OclAny) : Node pre: true post: true activity: self.next := next ; self.prev := prev ; self.data := data; return self; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMaxDiff(arr,n): if(n<2): print("Invalid ") return 0 res=-2147483648 for i in range(n): for j in range(n): if(res<(arr[i]-arr[j]-i+j)): res=(arr[i]-arr[j]-i+j) return res arr=[9,15,4,12,13] n=len(arr) print(findMaxDiff(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{9}->union(Sequence{15}->union(Sequence{4}->union(Sequence{12}->union(Sequence{ 13 })))) ; n := (arr)->size() ; execute (findMaxDiff(arr, n))->display(); operation findMaxDiff(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n < 2) then ( execute ("Invalid ")->display() ; return 0 ) else skip ; var res : int := -2147483648 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if ((res->compareTo((arr[i+1] - arr[j+1] - i + j))) < 0) then ( res := (arr[i+1] - arr[j+1] - i + j) ) else skip)) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,W=[int(x)for x in input().split()] items=[] for i in range(N): items.append(tuple(int(x)for x in input().split())) DP=[[0]*(W+1)for _ in range(N+1)] for i in range(N): for j in range(W+1): v,w=items[i] if w<=j : DP[i+1][j]=max(DP[i][j],v+DP[i+1][j-w]) else : DP[i+1][j]=DP[i][j] print(DP[-1][-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var W : OclAny := null; Sequence{N,W} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var items : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute ((((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( )))))))))) : items)) ; var DP : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (W + 1)))) ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, W + 1-1) do ( var v : OclAny := null; var w : OclAny := null; Sequence{v,w} := items[i+1] ; if (w->compareTo(j)) <= 0 then ( DP[i + 1+1][j+1] := Set{DP[i+1][j+1], v + DP[i + 1+1][j - w+1]}->max() ) else ( DP[i + 1+1][j+1] := DP[i+1][j+1] ))) ; execute (DP->last()->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : a,b,i,j=0,0,0,0 print("Enter lower bound of the interval:",end="") a=int(input()) print(a) print("Enter upper bound of the interval:",end="") b=int(input()) print(b) print("Prime numbers between",a,"and",b,"are:",end="") if(a==1): print(a,end=" ") a+=1 if(b>=2): print(a,end=" ") a+=1 if(a==2): print(a,end=" ") if(a % 2==0): a+=1 for i in range(a,b+1,2): flag=1 j=2 while(j*j<=i): if(i % j==0): flag=0 break j+=1 if(flag==1): print(i,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var a : OclAny := null; var b : OclAny := null; var i : OclAny := null; var j : OclAny := null; Sequence{a,b,i,j} := Sequence{0,0,0,0} ; execute ("Enter lower bound of the interval:")->display() ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (a)->display() ; execute ("Enter upper bound of the interval:")->display() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (b)->display() ; execute ("Prime numbers between")->display() ; if (a = 1) then ( execute (a)->display() ; a := a + 1 ; if (b >= 2) then ( execute (a)->display() ; a := a + 1 ) else skip ) else skip ; if (a = 2) then ( execute (a)->display() ) else skip ; if (a mod 2 = 0) then ( a := a + 1 ) else skip ; for i : Integer.subrange(a, b + 1-1)->select( $x | ($x - a) mod 2 = 0 ) do ( var flag : int := 1 ; var j : int := 2 ; while ((j * j->compareTo(i)) <= 0) do ( if (i mod j = 0) then ( flag := 0 ; break ) else skip ; j := j + 1) ; if (flag = 1) then ( execute (i)->display() ) else skip) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : a,b,i,j,flag=0,0,0,0,0 print("Enter lower bound of the interval:",end="") a=int(input()) print(a) print("Enter upper bound of the interval:",end="") b=int(input()) print(b) print("Prime numbers between",a,"and",b,"are:",end="") for i in range(a,b+1): if(i==1): continue flag=1 for j in range(2,i//2+1): if(i % j==0): flag=0 break if(flag==1): print(i,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var a : OclAny := null; var b : OclAny := null; var i : OclAny := null; var j : OclAny := null; var flag : OclAny := null; Sequence{a,b,i,j,flag} := Sequence{0,0,0,0,0} ; execute ("Enter lower bound of the interval:")->display() ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (a)->display() ; execute ("Enter upper bound of the interval:")->display() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (b)->display() ; execute ("Prime numbers between")->display() ; for i : Integer.subrange(a, b + 1-1) do ( if (i = 1) then ( continue ) else skip ; var flag : int := 1 ; for j : Integer.subrange(2, i div 2 + 1-1) do ( if (i mod j = 0) then ( flag := 0 ; break ) else skip) ; if (flag = 1) then ( execute (i)->display() ) else skip) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100 def smallestInRow(mat,n,m): print("{",end="") for i in range(n): minm=mat[i][0] for j in range(1,m,1): if(mat[i][j]union(Sequence{1}->union(Sequence{ 7 }))}->union(Sequence{Sequence{3}->union(Sequence{7}->union(Sequence{ 2 }))}->union(Sequence{ Sequence{5}->union(Sequence{4}->union(Sequence{ 9 })) })); ; execute ("Minimum element of each row is")->display() ; smallestInRow(mat, n, m) ; execute ("Minimum element of each column is")->display() ; smallestInCol(mat, n, m) ) else skip; operation smallestInRow(mat : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: execute ("{")->display() ; for i : Integer.subrange(0, n-1) do ( var minm : OclAny := mat[i+1]->first() ; for j : Integer.subrange(1, m-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if ((mat[i+1][j+1]->compareTo(minm)) < 0) then ( minm := mat[i+1][j+1] ) else skip) ; execute (minm)->display()) ; execute ("}")->display(); operation smallestInCol(mat : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: execute ("{")->display() ; for i : Integer.subrange(0, m-1) do ( minm := mat->first()[i+1] ; for j : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if ((mat[j+1][i+1]->compareTo(minm)) < 0) then ( minm := mat[j+1][i+1] ) else skip) ; execute (minm)->display()) ; execute ("}")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minAbsDiff(n): mod=n % 4 ; if(mod==0 or mod==3): return 0 ; return 1 ; if __name__=="__main__" : n=5 ; print(minAbsDiff(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 5; ; execute (minAbsDiff(n))->display() ) else skip; operation minAbsDiff(n : OclAny) pre: true post: true activity: var mod : int := n mod 4; ; if (mod = 0 or mod = 3) then ( return 0; ) else skip ; return 1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) num=list(map(int,input().split())) num.sort(reverse=True) for i in range(n): x=num[i] if(x<0 or x**0.5 % 1!=0): print(x) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var num : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; num := num->sort() ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := num[i+1] ; if (x < 0 or (x)->pow(0.5) mod 1 /= 0) then ( execute (x)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dfs(v,k,s): if k==K : return 1 if s==S else 0 res=0 for i in range(v+1,N+1): res+=dfs(i,k+1,s+i) return res while True : N,K,S=map(int,input().split()) if not N : break print(dfs(0,0,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var N : OclAny := null; var K : OclAny := null; var S : OclAny := null; Sequence{N,K,S} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if not(N) then ( break ) else skip ; execute (dfs(0, 0, 0))->display()); operation dfs(v : OclAny, k : OclAny, s : OclAny) : OclAny pre: true post: true activity: if k = K then ( return if s = S then 1 else 0 endif ) else skip ; var res : int := 0 ; for i : Integer.subrange(v + 1, N + 1-1) do ( res := res + dfs(i, k + 1, s + i)) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] while True : n,k,s=LI() if n==0 and k==0 and s==0 : break d=collections.defaultdict(int) d[(0,0)]=1 for i in range(1,n+1): for kk,vv in list(d.items()): if kk[0]==k or kk[1]+i>s : continue d[(kk[0]+1,kk[1]+i)]+=vv rr.append(d[(k,s)]) return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k,s} := LI() ; if n = 0 & k = 0 & s = 0 then ( break ) else skip ; var d : OclAny := .defaultdict(OclType["int"]) ; d[Sequence{0, 0}+1] := 1 ; for i : Integer.subrange(1, n + 1-1) do ( for _tuple : (d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})) do (var _indx : int := 1; var kk : OclAny := _tuple->at(_indx); _indx := _indx + 1; var vv : OclAny := _tuple->at(_indx); if kk->first() = k or (kk[1+1] + i->compareTo(s)) > 0 then ( continue ) else skip ; d[Sequence{kk->first() + 1, kk[1+1] + i}+1] := d[Sequence{kk->first() + 1, kk[1+1] + i}+1] + vv)) ; execute ((d[Sequence{k, s}+1]) : rr)) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import combinations while 1 : n,k,s=map(int,input().split()) if n==k==s==0 : break a=0 for i in combinations(range(1,n+1),k): if len(set(i))collect( _x | (OclType["int"])->apply(_x) ) ; if n = k & (k == s) & (s == 0) then ( break ) else skip ; var a : int := 0 ; for i : combinations(Integer.subrange(1, n + 1-1), k) do ( if ((Set{}->union((i)))->size()->compareTo(k)) < 0 then ( continue ) else skip ; a := a + (i)->sum() = s) ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools while True : N,K,S=map(int,input().split()) if N==0 : break cnt=0 for comb in itertools.combinations(range(1,N+1),K): if sum(comb)==S : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var N : OclAny := null; var K : OclAny := null; var S : OclAny := null; Sequence{N,K,S} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if N = 0 then ( break ) else skip ; var cnt : int := 0 ; for comb : itertools.combinations(Integer.subrange(1, N + 1-1), K) do ( if (comb)->sum() = S then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rec(n,u,k,s): if k==1 : if ucollect( _x | (OclType["int"])->apply(_x) ) ; if n = k & (k == s) & (s == 0) then ( break ) else skip ; execute (rec(n, 0, k, s))->display()); operation rec(n : OclAny, u : OclAny, k : OclAny, s : OclAny) : OclAny pre: true post: true activity: if k = 1 then ( if (u->compareTo(s)) < 0 & (s <= n) then ( return 1 ) else ( return 0 ) ) else skip ; var ret : int := 0 ; for i : Integer.subrange(u + 1, n - k + 2-1) do ( ret := ret + rec(n, i, k - 1, s - i)) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def main(): N,W=map(int,input().split()) vw=[None]*N for i in range(N): vw[i]=tuple(map(int,input().split())) dp=[0]*(W+1) for v,w in vw : for i in range(w,W+1): dp[i]=max(dp[i],dp[i-w]+v) ans=max(dp) print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var W : OclAny := null; Sequence{N,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var vw : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, N) ; for i : Integer.subrange(0, N-1) do ( vw[i+1] := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (W + 1)) ; for _tuple : vw do (var _indx : int := 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var w : OclAny := _tuple->at(_indx); for i : Integer.subrange(w, W + 1-1) do ( dp[i+1] := Set{dp[i+1], dp[i - w+1] + v}->max())) ; var ans : OclAny := (dp)->max() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countP(n,k): if(n==0 or k==0 or k>n): return 0 if(k==1 or k==n): return 1 return(k*countP(n-1,k)+countP(n-1,k-1)) if __name__=="__main__" : print(countP(3,2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (countP(3, 2))->display() ) else skip; operation countP(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (n = 0 or k = 0 or (k->compareTo(n)) > 0) then ( return 0 ) else skip ; if (k = 1 or k = n) then ( return 1 ) else skip ; return (k * countP(n - 1, k) + countP(n - 1, k - 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(): mat=[] for i in range(3): mat.append(list(input())) for i in range(3): j=0 while(jcharacters()) : mat)) ; for i : Integer.subrange(0, 3-1) do ( var j : int := 0 ; while ((j->compareTo((mat)->size())) < 0) do ( if (mat[i+1][j+1] = (mat[2 - i+1][2 - j+1])) then ( j := j + 1 ; continue ) else ( execute ("No")->display() ; return ))) ; execute ("YES")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- matrix=[] for x in range(3): a=input() matrix.append(a) result=0 for x in range(3): for y in range(3): if matrix[x][y]==matrix[2-x][2-y]: result+=1 if result==9 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var matrix : Sequence := Sequence{} ; for x : Integer.subrange(0, 3-1) do ( var a : String := (OclFile["System.in"]).readLine() ; execute ((a) : matrix)) ; var result : int := 0 ; for x : Integer.subrange(0, 3-1) do ( for y : Integer.subrange(0, 3-1) do ( if matrix[x+1][y+1] = matrix[2 - x+1][2 - y+1] then ( result := result + 1 ) else skip)) ; if result = 9 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- kl="" ; for i in range(3): kl+=input(); print(['NO','YES'][kl==kl[: :-1]]); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var kl : String := ""; ; for i : Integer.subrange(0, 3-1) do ( kl := kl + (OclFile["System.in"]).readLine();) ; execute (Sequence{'NO'}->union(Sequence{ 'YES' })->select(kl = kl(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))))->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() s1=input() s2=input() if s[0]==s2[2]and s[1]==s2[1]and s[2]==s2[0]and s1[0]==s1[2]: print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var s1 : String := (OclFile["System.in"]).readLine() ; var s2 : String := (OclFile["System.in"]).readLine() ; if s->first() = s2[2+1] & s[1+1] = s2[1+1] & s[2+1] = s2->first() & s1->first() = s1[2+1] then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=set(map(int,input().split())) b=set(x*x for x in range(1001)) print(max(a-b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var b : Set := Set{}->union(((argument (test (logical_test (comparison (expr (expr (atom (name x))) * (expr (atom (name x))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1001))))))))) )))))))))) ; execute ((a - b)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l="" ; for i in range(3): l+=input(); print(['NO','YES'][l==l[: :-1]]); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : String := ""; ; for i : Integer.subrange(0, 3-1) do ( l := l + (OclFile["System.in"]).readLine();) ; execute (Sequence{'NO'}->union(Sequence{ 'YES' })->select(l = l(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))))->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculate(N): length=len(N) l=int((length)/2) count=0 for i in range(l+1): s=N[0 : 0+i] l1=len(s) t=N[i : l1+i] try : if s[0]=='0' or t[0]=='0' : continue except : continue if s==t : count+=1 return count N=str("2202200") print(calculate(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := ("" + (("2202200"))) ; execute (calculate(N))->display(); operation calculate(N : OclAny) : OclAny pre: true post: true activity: var length : int := (N)->size() ; var l : int := ("" + (((length) / 2)))->toInteger() ; var count : int := 0 ; for i : Integer.subrange(0, l + 1-1) do ( var s : OclAny := N.subrange(0+1, 0 + i) ; var l1 : int := (s)->size() ; var t : OclAny := N.subrange(i+1, l1 + i) ; try ( if s->first() = '0' or t->first() = '0' then ( continue ) else skip) catch (_e : OclException) do ( continue) ; if s = t then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,Q=list(map(int,input().split())) C=list(map(int,input().split())) M=max(C)+1 t1=[0]*(M) for v in C : t1[v]=1 t2=[0]*(M) v=0 for i in range(M): if t1[i]: v=i t2[i]=v for i in range(Q): t=int(input()) n_v=M-1 m=0 while n_v!=0 : amr=n_v % t m=max(m,amr) tmp=n_v-m-1 if tmp<=0 : break n_v=t2[tmp] print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var Q : OclAny := null; Sequence{N,Q} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var C : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var M : OclAny := (C)->max() + 1 ; var t1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (M)) ; for v : C do ( t1[v+1] := 1) ; var t2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (M)) ; var v : int := 0 ; for i : Integer.subrange(0, M-1) do ( if t1[i+1] then ( v := i ) else skip ; t2[i+1] := v) ; for i : Integer.subrange(0, Q-1) do ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n_v : double := M - 1 ; var m : int := 0 ; while n_v /= 0 do ( var amr : int := n_v mod t ; m := Set{m, amr}->max() ; var tmp : double := n_v - m - 1 ; if tmp <= 0 then ( break ) else skip ; n_v := t2[tmp+1]) ; execute (m)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,Q=map(int,input().split()) tbl=[0]*300005 nmax,tbl[0]=0,1 c=list(map(int,input().split())) for k in c : tbl[k]=1 if k>nmax : nmax=k tbl[k & 1]=1 tbl[k & 3]=1 tbl[k & 7]=1 for i in range(Q): q=int(input()) if q>nmax : print(nmax) else : f=0 for k in range(q-1,-1,-1): for i in range(k,nmax+1,q): if tbl[i]: print(k) f=1 break if f : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var Q : OclAny := null; Sequence{N,Q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var tbl : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 300005) ; var nmax : OclAny := null; var tbl->first() : OclAny := null; Sequence{nmax,tbl->first()} := Sequence{0,1} ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for k : c do ( tbl[k+1] := 1 ; if (k->compareTo(nmax)) > 0 then ( var nmax : OclAny := k ) else skip ; tbl[MathLib.bitwiseAnd(k, 1)+1] := 1 ; tbl[MathLib.bitwiseAnd(k, 3)+1] := 1 ; tbl[MathLib.bitwiseAnd(k, 7)+1] := 1) ; for i : Integer.subrange(0, Q-1) do ( var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (q->compareTo(nmax)) > 0 then ( execute (nmax)->display() ) else ( var f : int := 0 ; for k : Integer.subrange(-1 + 1, q - 1)->reverse() do ( for i : Integer.subrange(k, nmax + 1-1)->select( $x | ($x - k) mod q = 0 ) do ( if tbl[i+1] then ( execute (k)->display() ; f := 1 ; break ) else skip) ; if f then ( break ) else skip) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import(division,absolute_import,print_function,unicode_literals) from sys import stdin from math import cos,sin,atan2,pi PI2=pi/2 L=[None,(1.0,0.0)] for _ in range(2,1001): x,y=L[-1] rad=atan2(y,x)+PI2 L.append((x+cos(rad),y+sin(rad))) for line in stdin : n=int(line) if n==-1 : break print('{:0.2f}\n{:0.2f}'.format(*L[n])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var PI2 : double := pi / 2 ; var L : Sequence := Sequence{null}->union(Sequence{ Sequence{1.0, 0.0} }) ; for _anon : Integer.subrange(2, 1001-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := L->last() ; var rad : OclAny := atan2(y, x) + PI2 ; execute ((Sequence{x + cos(rad), y + sin(rad)}) : L)) ; for line : stdin do ( var n : int := ("" + ((line)))->toInteger() ; if n = -1 then ( break ) else skip ; execute (StringLib.interpolateStrings('{:0.2f} {:0.2f}', Sequence{(argument * (test (logical_test (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n)))))))) ])))))))}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect n,q=map(int,input().split()) c=list(map(int,input().split())) c=sorted(c) for i in range(q): query=int(input()) num=query ans=0 while True : if c[-1]+query=0 : ans=max(ans,c[end-1]% query) num+=query print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; c := c->sort() ; for i : Integer.subrange(0, q-1) do ( var query : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var num : int := query ; var ans : int := 0 ; while true do ( if (c->last() + query->compareTo(num)) < 0 then ( break ) else skip ; var end : OclAny := bisect.bisect_left(c, num) ; if end - 1 >= 0 then ( ans := Set{ans, c[end - 1+1] mod query}->max() ) else skip ; num := num + query) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,Q=list(map(int,input().split())) C=list(map(int,input().split())) M=max(C)+1 T=[0]*(M) for v in C : T[v]=1 L=[0]*(M) m=0 for i in range(M): L[i]=m if T[i]: m=i for i in range(Q): q=int(input()) maxv=0 cur=m while 0collect( _x | (OclType["int"])->apply(_x) )) ; var C : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var M : OclAny := (C)->max() + 1 ; var T : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (M)) ; for v : C do ( T[v+1] := 1) ; var L : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (M)) ; var m : int := 0 ; for i : Integer.subrange(0, M-1) do ( L[i+1] := m ; if T[i+1] then ( m := i ) else skip) ; for i : Integer.subrange(0, Q-1) do ( var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var maxv : int := 0 ; var cur : int := m ; while 0 < cur do ( var p : int := cur mod q ; maxv := Set{maxv, p}->max() ; if cur - p < 0 then ( break ) else skip ; cur := L[cur - p+1]) ; execute (maxv)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printIndices(n,a): for i in range(n): print(a[i][1],end="") print("\n",end="") def printPermutations(n,a,k): arr=[[0,0]for i in range(n)] for i in range(n): arr[i][0]=a[i] arr[i][1]=i arr.sort(reverse=False) count=1 for i in range(1,n): if(arr[i][0]==arr[i-1][0]): count+=1 if(countunion(Sequence{3}->union(Sequence{3}->union(Sequence{ 1 }))) ; n := (a)->size() ; k := 3 ; printPermutations(n, a, k) ) else skip; operation printIndices(n : OclAny, a : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (a[i+1][1+1])->display()) ; execute ("\n")->display(); operation printPermutations(n : OclAny, a : OclAny, k : OclAny) pre: true post: true activity: var arr : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{0}->union(Sequence{ 0 }))) ; for i : Integer.subrange(0, n-1) do ( arr[i+1]->first() := a[i+1] ; arr[i+1][1+1] := i) ; arr := arr->sort() ; var count : int := 1 ; for i : Integer.subrange(1, n-1) do ( if (arr[i+1]->first() = arr[i - 1+1]->first()) then ( count := count + 1 ) else skip) ; if ((count->compareTo(k)) < 0) then ( execute ("-1")->display() ; return ) else skip ; for i : Integer.subrange(0, k - 1-1) do ( printIndices(n, arr) ; for j : Integer.subrange(1, n-1) do ( if (arr[j+1]->first() = arr[j - 1+1]->first()) then ( var temp : OclAny := arr[j+1] ; arr[j+1] := arr[j - 1+1] ; arr[j - 1+1] := temp ; break ) else skip)) ; printIndices(n, arr); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countNumbers(n): c=0 limit=int(n**(0.5)) prime=[i for i in range(limit+1)] i=2 while i*i<=limit : if prime[i]==i : for j in range(i*i,limit+1,i): if prime[j]==j : prime[j]=i i+=1 for i in range(2,limit+1): p=prime[i] q=prime[i//prime[i]] if p*q==i and q!=1 and p!=q : c+=1 elif prime[i]==i : if i**8<=n : c+=1 return c if __name__=="__main__" : n=1000 print(countNumbers(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 1000 ; execute (countNumbers(n))->display() ) else skip; operation countNumbers(n : OclAny) : OclAny pre: true post: true activity: var c : int := 0 ; var limit : int := ("" + (((n)->pow((0.5)))))->toInteger() ; var prime : Sequence := Integer.subrange(0, limit + 1-1)->select(i | true)->collect(i | (i)) ; var i : int := 2 ; while (i * i->compareTo(limit)) <= 0 do ( if prime[i+1] = i then ( for j : Integer.subrange(i * i, limit + 1-1)->select( $x | ($x - i * i) mod i = 0 ) do ( if prime[j+1] = j then ( prime[j+1] := i ) else skip) ) else skip ; i := i + 1) ; for i : Integer.subrange(2, limit + 1-1) do ( var p : OclAny := prime[i+1] ; var q : OclAny := prime[i div prime[i+1]+1] ; if p * q = i & q /= 1 & p /= q then ( c := c + 1 ) else (if prime[i+1] = i then ( if ((i)->pow(8)->compareTo(n)) <= 0 then ( c := c + 1 ) else skip ) else skip)) ; return c; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: n,m,k=map(int,s.split()); print((min(m,n//k)*k-m)//(k-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ); execute ((Set{m, n div k}->min() * k - m) div (k - 1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil t=int(input()) for _ in range(t): s=input() n,m,k=map(int,s.split()) c=n/k if m<2 or c>=m : print(m) elif n==m or c==1 : print(0) else : j=m-c ans=int(c-ceil(j/(k-1))) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : double := n / k ; if m < 2 or (c->compareTo(m)) >= 0 then ( execute (m)->display() ) else (if n = m or c = 1 then ( execute (0)->display() ) else ( var j : double := m - c ; var ans : int := ("" + ((c - ceil(j / (k - 1)))))->toInteger() ; execute (ans)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) l=list(map(int,input().split())) mx=-10000000 for i in l : x=math.sqrt(abs(i)) y=math.floor(x)**2 if y!=i : mx=max(mx,i) print(mx) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mx : int := -10000000 ; for i : l do ( var x : double := ((i)->abs())->sqrt() ; var y : double := ((x)->floor())->pow(2) ; if y /= i then ( mx := Set{mx, i}->max() ) else skip) ; execute (mx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m,k=map(int,input().split()) print(min(m,(n-m)//(k-1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{m, (n - m) div (k - 1)}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,m,k=list(map(int,input().split())) c=n//k if c>=m : print(m) else : m-=c d=0 while m>0 : d+=1 m-=(k-1) print(c-d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := n div k ; if (c->compareTo(m)) >= 0 then ( execute (m)->display() ) else ( m := m - c ; var d : int := 0 ; while m > 0 do ( d := d + 1 ; m := m - (k - 1)) ; execute (c - d)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for i in range(int(input())): n,m,k=map(int,input().split()) j=min(m,n//k) lj=m-j lj=math.ceil(lj/(k-1)) print(j-lj) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var j : OclAny := Set{m, n div k}->min() ; var lj : double := m - j ; lj := (lj / (k - 1))->ceil() ; execute (j - lj)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for e in iter(input,'-1'): z=1 for _ in[0]*~-int(e): d=z*1j ; z+=d/abs(d) print(z.real) print(z.imag) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for e : OclIterator.newOclIterator_Sequence(input, '-1') do ( var z : int := 1 ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, MathLib.bitwiseNot(-("" + ((e)))->toInteger())) do ( var d : double := z * 1j; z := z + d / (d)->abs()) ; execute (z.real)->display() ; execute (z.imag)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=int(input()) ans=[0]*n a=list(map(int,input().split())) for i in range(m): cnt=0 b=list(map(int,input().split())) for j in range(n): if b[j]==a[i]: ans[j]+=1 else : cnt+=1 ans[a[i]-1]+=cnt for i in range(n): print(ans[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, m-1) do ( var cnt : int := 0 ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, n-1) do ( if b[j+1] = a[i+1] then ( ans[j+1] := ans[j+1] + 1 ) else ( cnt := cnt + 1 )) ; ans[a[i+1] - 1+1] := ans[a[i+1] - 1+1] + cnt) ; for i : Integer.subrange(0, n-1) do ( execute (ans[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p,t=[int(input())for i in range(2)] tg=[int(s)for s in input().split(" ")] pts=[0 for i in range(p)] for i in range(t): ex=[int(s)for s in input().split(" ")] c_wr=0 for j in range(p): if ex[j]==tg[i]: pts[j]+=1 else : c_wr+=1 pts[tg[i]-1]+=c_wr for pt in pts : print(pt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : OclAny := null; var t : OclAny := null; Sequence{p,t} := Integer.subrange(0, 2-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var tg : Sequence := input().split(" ")->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; var pts : Sequence := Integer.subrange(0, p-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, t-1) do ( var ex : Sequence := input().split(" ")->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; var c_wr : int := 0 ; for j : Integer.subrange(0, p-1) do ( if ex[j+1] = tg[i+1] then ( pts[j+1] := pts[j+1] + 1 ) else ( c_wr := c_wr + 1 )) ; pts[tg[i+1] - 1+1] := pts[tg[i+1] - 1+1] + c_wr) ; for pt : pts do ( execute (pt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- peopleCounts=int(input()) gameCounts=int(input()) targets=list(map(int,input().split())) result=[0]*peopleCounts for i in range(gameCounts): judges=list(map(int,input().split())) ans=targets[i] for judgeIndex in range(len(judges)): if ans==judges[judgeIndex]: result[judgeIndex]+=1 else : result[ans-1]+=1 for v in result : print(v) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var peopleCounts : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var gameCounts : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var targets : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var result : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, peopleCounts) ; for i : Integer.subrange(0, gameCounts-1) do ( var judges : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : OclAny := targets[i+1] ; for judgeIndex : Integer.subrange(0, (judges)->size()-1) do ( if ans = judges[judgeIndex+1] then ( result[judgeIndex+1] := result[judgeIndex+1] + 1 ) else ( result[ans - 1+1] := result[ans - 1+1] + 1 ))) ; for v : result do ( execute (v)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) M=int(input()) target_list=[int(i)for i in input().split(" ")] vote_list=[[int(i)for i in input().split(" ")]for j in range(M)] score_list=[0 for i in range(N)] for i in range(M): target=target_list[i] vote=vote_list[i] for j in range(N): if vote[j]==target : score_list[j]+=1 else : score_list[target-1]+=1 for i in score_list : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var M : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var target_list : Sequence := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var vote_list : Sequence := Integer.subrange(0, M-1)->select(j | true)->collect(j | (input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())))) ; var score_list : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, M-1) do ( var target : OclAny := target_list[i+1] ; var vote : OclAny := vote_list[i+1] ; for j : Integer.subrange(0, N-1) do ( if vote[j+1] = target then ( score_list[j+1] := score_list[j+1] + 1 ) else ( score_list[target - 1+1] := score_list[target - 1+1] + 1 ))) ; for i : score_list do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) m=int(input()) A=list(map(int,input().split())) B=[list(map(int,input().split()))for i in range(m)] p=[0 for i in range(n+1)] for i in range(m): for j in range(n): if B[i][j]==A[i]: p[j+1]+=1 else : p[A[i]]+=1 for i in range(1,n+1): print(p[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var B : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var p : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, m-1) do ( for j : Integer.subrange(0, n-1) do ( if B[i+1][j+1] = A[i+1] then ( p[j + 1+1] := p[j + 1+1] + 1 ) else ( p[A[i+1]+1] := p[A[i+1]+1] + 1 ))) ; for i : Integer.subrange(1, n + 1-1) do ( execute (p[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def smallestPoss(s,n): ans="" ; arr=[0]*10 ; for i in range(n): arr[ord(s[i])-48]+=1 ; for i in range(10): for j in range(arr[i]): ans=ans+str(i); return ans ; if __name__=='__main__' : N=15 ; K="325343273113434" ; print(smallestPoss(K,N)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var N : int := 15; ; var K : String := "325343273113434"; ; execute (smallestPoss(K, N))->display(); ) else skip; operation smallestPoss(s : OclAny, n : OclAny) pre: true post: true activity: var ans : String := ""; ; var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10); ; for i : Integer.subrange(0, n-1) do ( arr[(s[i+1])->char2byte() - 48+1] := arr[(s[i+1])->char2byte() - 48+1] + 1;) ; for i : Integer.subrange(0, 10-1) do ( for j : Integer.subrange(0, arr[i+1]-1) do ( ans := ans + ("" + ((i)));)) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- list1=[] for x in range(0,10): for y in range(0,10): for i in range(1,10): for j in range(0,(2**i)+1): bn=bin(j) bn=bn[2 :] c=bn.zfill(i) temp=c.replace("0",str(x)) res=temp.replace("1",str(y)) list1.append(int(res)) list1=sorted(list(set(list1))) inp1=int(input()) ans=-1 for x in range(len(list1)): if int(list1[x])<=inp1 : ans+=1 else : break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var list1 : Sequence := Sequence{} ; for x : Integer.subrange(0, 10-1) do ( for y : Integer.subrange(0, 10-1) do ( for i : Integer.subrange(1, 10-1) do ( for j : Integer.subrange(0, ((2)->pow(i)) + 1-1) do ( var bn : OclAny := bin(j) ; bn := bn.subrange(2+1) ; var c : OclAny := bn.zfill(i) ; var temp : String := c.replace("0", ("" + ((x)))) ; var res : String := temp.replace("1", ("" + ((y)))) ; execute ((("" + ((res)))->toInteger()) : list1))))) ; list1 := (Set{}->union((list1)))->sort() ; var inp1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := -1 ; for x : Integer.subrange(0, (list1)->size()-1) do ( if (("" + ((list1[x+1])))->toInteger()->compareTo(inp1)) <= 0 then ( ans := ans + 1 ) else ( break )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math ans=-1e18 n=int(input()) a=input().split() for i in a : u=int(i) if(u>=0): if(math.floor(math.sqrt(u))*math.floor(math.sqrt(u))!=u): ans=max(u,ans) else : ans=max(ans,u) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var ans : double := -("1e18")->toReal() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := input().split() ; for i : a do ( var u : int := ("" + ((i)))->toInteger() ; if (u >= 0) then ( if (((u)->sqrt())->floor() * ((u)->sqrt())->floor() /= u) then ( ans := Set{u, ans}->max() ) else skip ) else ( ans := Set{ans, u}->max() )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inp=int(input()) l1=[] c=-1 for x in range(0,10): for y in range(0,10): for l in range(0,10): for j in range(0,2**l): b=bin(j) b=b[2 :] b=b.zfill(l) f=b.replace('0',str(x)) last=f.replace('1',str(y)) l1.append(int(last)) u=(set(l1)) for m in u : if int(m)<=inp : c+=1 if inp==1000000000 : print(c+1) else : print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inp : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l1 : Sequence := Sequence{} ; var c : int := -1 ; for x : Integer.subrange(0, 10-1) do ( for y : Integer.subrange(0, 10-1) do ( for l : Integer.subrange(0, 10-1) do ( for j : Integer.subrange(0, (2)->pow(l)-1) do ( var b : OclAny := bin(j) ; b := b.subrange(2+1) ; b := b.zfill(l) ; var f : String := b.replace('0', ("" + ((x)))) ; var last : String := f.replace('1', ("" + ((y)))) ; execute ((("" + ((last)))->toInteger()) : l1))))) ; var u : Set := (Set{}->union((l1))) ; for m : u do ( if (("" + ((m)))->toInteger()->compareTo(inp)) <= 0 then ( c := c + 1 ) else skip) ; if inp = 1000000000 then ( execute (c + 1)->display() ) else ( execute (c)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- array=[] for x in range(0,10): for y in range(0,10): for i in range(0,10): for j in range(0,2**i): b=bin(j)[2 :] b=b.zfill(i) b=b.replace("0",str(x)) b=b.replace("1",str(y)) array.append(int(b)) cout=0 array=set(array) a=int(input()) for k in array : if int(k)<=a : cout+=1 if a==10**9 : print(cout) else : print(cout-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var array : Sequence := Sequence{} ; for x : Integer.subrange(0, 10-1) do ( for y : Integer.subrange(0, 10-1) do ( for i : Integer.subrange(0, 10-1) do ( for j : Integer.subrange(0, (2)->pow(i)-1) do ( var b : OclAny := bin(j).subrange(2+1) ; b := b.zfill(i) ; b := b.replace("0", ("" + ((x)))) ; b := b.replace("1", ("" + ((y)))) ; execute ((("" + ((b)))->toInteger()) : array))))) ; var cout : int := 0 ; array := Set{}->union((array)) ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for k : array do ( if (("" + ((k)))->toInteger()->compareTo(a)) <= 0 then ( cout := cout + 1 ) else skip) ; if a = (10)->pow(9) then ( execute (cout)->display() ) else ( execute (cout - 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math MAX=1005 r,d=[0.0]*MAX,[0.0]*MAX r[1]=1.0 for i in range(2,MAX): d[i]=d[i-1]+math.atan(1/r[i-1]) r[i]=math.sqrt(r[i-1]**2+1) while True : i=int(input()) if i<0 : break print(r[i]*math.cos(d[i]),r[i]*math.sin(d[i]),sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MAX : int := 1005 ; var r : OclAny := null; var d : OclAny := null; Sequence{r,d} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0.0 }, MAX),MatrixLib.elementwiseMult(Sequence{ 0.0 }, MAX)} ; r[1+1] := 1.0 ; for i : Integer.subrange(2, MAX-1) do ( d[i+1] := d[i - 1+1] + (1 / r[i - 1+1])->atan() ; r[i+1] := ((r[i - 1+1])->pow(2) + 1)->sqrt()) ; while true do ( var i : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if i < 0 then ( break ) else skip ; execute (r[i+1] * )->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lis=[] for i in range(0,10): for j in range(0,10): for k in range(0,10): for l in range(0,2**k): b=bin(l)[2 :] b=b.zfill(k) b=b.replace("0",str(i)) b=b.replace("1",str(j)) lis.append(int(b)) count=0 lis=set(lis) a=int(input()) for m in lis : if int(m)<=a : count+=1 if a==10**9 : print(count) else : print(count-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lis : Sequence := Sequence{} ; for i : Integer.subrange(0, 10-1) do ( for j : Integer.subrange(0, 10-1) do ( for k : Integer.subrange(0, 10-1) do ( for l : Integer.subrange(0, (2)->pow(k)-1) do ( var b : OclAny := bin(l).subrange(2+1) ; b := b.zfill(k) ; b := b.replace("0", ("" + ((i)))) ; b := b.replace("1", ("" + ((j)))) ; execute ((("" + ((b)))->toInteger()) : lis))))) ; var count : int := 0 ; lis := Set{}->union((lis)) ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for m : lis do ( if (("" + ((m)))->toInteger()->compareTo(a)) <= 0 then ( count := count + 1 ) else skip) ; if a = (10)->pow(9) then ( execute (count)->display() ) else ( execute (count - 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def return_palindrome(s : str,c : str,i : int): new_s=s[: i]+c+s[i :] if new_s==new_s[: :-1]: return new_s else : return "NA" s=input() found=False for i in range(len(s)+1): if found : break for c in "abcdefghijklmnopqrstuvwxyz" : if found : break palindrome=return_palindrome(s,c,i) if palindrome!="NA" : print(palindrome) found=True if not found : print("NA") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : String := (OclFile["System.in"]).readLine() ; var found : boolean := false ; for i : Integer.subrange(0, (s)->size() + 1-1) do ( if found then ( break ) else skip ; for c : "abcdefghijklmnopqrstuvwxyz"->characters() do ( if found then ( break ) else skip ; var palindrome : OclAny := return_palindrome(s, c, i) ; if palindrome /= "NA" then ( execute (palindrome)->display() ; found := true ) else skip)) ; if not(found) then ( execute ("NA")->display() ) else skip; operation return_palindrome(s : String, c : String, i : int) : OclAny pre: true post: true activity: var new_s : OclAny := s.subrange(1,i) + c + s.subrange(i+1) ; if new_s = new_s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( return new_s ) else ( return "NA" ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from string import ascii_lowercase def main(): s=input() n=len(s) for i in range(n+1): for c in ascii_lowercase : t=s t=t[: i]+c+t[i :] if t==t[: :-1]: print(t) return print("NA") main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var n : int := (s)->size() ; for i : Integer.subrange(0, n + 1-1) do ( for c : ascii_lowercase do ( var t : String := s ; t := t.subrange(1,i) + c + t.subrange(i+1) ; if t = t(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( execute (t)->display() ; return ) else skip)) ; execute ("NA")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline s=input()[:-1] x=len(s) ans='' for i in range(x//2): if s[i]!=s[x-i-1]: d=s[: i]+s[x-i-1]+s[i :] e=s[: x-i]+s[i]+s[x-i :] for j in range((x+1)//2): if d[j]!=d[x-j]: ans="NA" break else : ans=d if ans=='NA' : for j in range((x+1)//2): if e[j]!=e[x-j]: ans="NA" break else : ans=e break else : s=s[: x//2]+s[x//2]+s[x//2 :] ans=s print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var s : OclAny := input()->front() ; var x : int := (s)->size() ; var ans : String := '' ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) // (expr (atom (number (integer 2)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) != (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name x))) - (expr (atom (name i)))) - (expr (atom (number (integer 1)))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name x))) - (expr (atom (name i)))) - (expr (atom (number (integer 1)))))))))) ])))) + (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))) :)) ]))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name e)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (name i))))))))) ]))) + (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) + (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (name i))))))) :)) ]))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (number (integer 1))))))))) ))) // (expr (atom (number (integer 2)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) != (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (name j))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom "NA"))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name ans)))) == (comparison (expr (atom 'NA')))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (number (integer 1))))))))) ))) // (expr (atom (number (integer 2)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) != (comparison (expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (name j))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom "NA"))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name e))))))))))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (expr (atom (name x))) // (expr (atom (number (integer 2)))))))))) ]))) + (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) // (expr (atom (number (integer 2)))))))))) ])))) + (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) // (expr (atom (number (integer 2)))))))) :)) ]))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s))))))))))))))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(s): def d(s): return s==s[: :-1] s="."+s+"." for letter in list(set(s.replace(".",""))): for i in range(len(s)): if d((s[: i]+letter+s[i :]).replace(".","")): return(s[: i]+letter+s[i :]).replace(".","") return "NA" s=input() print(f(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := (OclFile["System.in"]).readLine() ; execute (f(s))->display(); operation f(s : OclAny) : OclAny pre: true post: true activity: skip ; s := "." + s + "." ; for letter : (Set{}->union((s.replace(".", "")))) do ( for i : Integer.subrange(0, (s)->size()-1) do ( if d((s.subrange(1,i) + letter + s.subrange(i+1)).replace(".", "")) then ( return (s.subrange(1,i) + letter + s.subrange(i+1)).replace(".", "") ) else skip)) ; return "NA"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() n=len(s) for j in range(26): for i in range(n+1): s2=s[: i]+chr(j+97)+s[i :] if s2==s2[: :-1]: print(s2); exit() print("NA") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var n : int := (s)->size() ; for j : Integer.subrange(0, 26-1) do ( for i : Integer.subrange(0, n + 1-1) do ( var s2 : OclAny := s.subrange(1,i) + (j + 97)->byte2char() + s.subrange(i+1) ; if s2 = s2(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( execute (s2)->display(); exit() ) else skip)) ; execute ("NA")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): primes=eulerlib.list_primes(1000000) for n in range(5,len(primes),2): rem=n*primes[n-1]*2 if rem>10000000000 : return str(n) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var primes : OclAny := eulerlib.list_primes(1000000) ; for n : Integer.subrange(5, (primes)->size()-1)->select( $x | ($x - 5) mod 2 = 0 ) do ( var rem : double := n * primes[n - 1+1] * 2 ; if rem > 10000000000 then ( return ("" + ((n))) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- necklace=input() strings=necklace.count('-') pearls=necklace.count('o') if pearls==0 : print("yes") elif strings==0 : print("yes") elif(strings % pearls)==0 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var necklace : String := (OclFile["System.in"]).readLine() ; var strings : int := necklace->count('-') ; var pearls : int := necklace->count('o') ; if pearls = 0 then ( execute ("yes")->display() ) else (if strings = 0 then ( execute ("yes")->display() ) else (if (strings mod pearls) = 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- first=False while 1 : n=int(input()) if n==0 : break if first : print() else : first=True data=[] for _ in range(n): country,win,lose,draw=map(str,input().split()) point=int(win)*3+int(draw) data.append([country,point]) data.sort(key=lambda item :-item[1]) for country,point in data : print(country+","+str(point)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var first : boolean := false ; while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; if first then ( execute (->display() ) else ( first := true ) ; var data : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var country : OclAny := null; var win : OclAny := null; var lose : OclAny := null; var draw : OclAny := null; Sequence{country,win,lose,draw} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; var point : int := ("" + ((win)))->toInteger() * 3 + ("" + ((draw)))->toInteger() ; execute ((Sequence{country}->union(Sequence{ point })) : data)) ; data := data->sort() ; for _tuple : data do (var _indx : int := 1; var country : OclAny := _tuple->at(_indx); _indx := _indx + 1; var point : OclAny := _tuple->at(_indx); execute (country + "," + ("" + ((point))))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=[int(x)for x in input().split()] squares=set() for i in range(0,1000+1): squares.add(i*i) ans=-float('inf') for i in range(n): if arr[i]not in squares : ans=max(ans,arr[i]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var squares : Set := Set{}->union(()) ; for i : Integer.subrange(0, 1000 + 1-1) do ( execute ((i * i) : squares)) ; var ans : double := -("" + (('inf')))->toReal() ; for i : Integer.subrange(0, n-1) do ( if (squares)->excludes(arr[i+1]) then ( ans := Set{ans, arr[i+1]}->max() ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import atan,atan2,degrees,pi,cos,sin Memo=[] def init_memo(n): global Memo Memo.append((0,0)) Memo.append((1,0)) for i in range(n): x=Memo[-1][0] y=Memo[-1][1] rad=atan2(-y,-x) rad-=pi/2 x+=cos(rad) y+=sin(rad) Memo.append((x,y)) def solve(n): global Memo return Memo[n] def main(args): init_memo(1000) while True : n=int(input()) if n==-1 : break result=solve(n) print('{:.2f}'.format(result[0])) print('{:.2f}'.format(result[1])) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute Memo : OclAny; attribute Memo : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; var Memo : Sequence := Sequence{} ; skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation init_memo(n : OclAny) pre: true post: true activity: skip ; execute ((Sequence{0, 0}) : Memo) ; execute ((Sequence{1, 0}) : Memo) ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := Memo->last()->first() ; var y : OclAny := Memo->last()[1+1] ; var rad : OclAny := atan2(-y, -x) ; rad := rad - pi / 2 ; x := x + cos(rad) ; y := y + sin(rad) ; execute ((Sequence{x, y}) : Memo)); operation solve(n : OclAny) : OclAny pre: true post: true activity: skip ; return Memo[n+1]; operation main(args : OclAny) pre: true post: true activity: init_memo(1000) ; while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = -1 then ( break ) else skip ; var result : OclAny := solve(n) ; execute (StringLib.interpolateStrings('{:.2f}', Sequence{result->first()}))->display() ; execute (StringLib.interpolateStrings('{:.2f}', Sequence{result[1+1]}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() print("YES" if s.count('-')% max(s.count('o'),1)==0 else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; execute (if s->count('-') mod Set{s->count('o'), 1}->max() = 0 then "YES" else "NO" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() print('NO' if len(s)%(s.count('o')or 1)else 'YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; execute (if (s)->size() mod (s->count('o') or 1) then 'NO' else 'YES' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- v=input() print('NO' if len(v)%(v.count('o')or 1)else 'YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var v : String := (OclFile["System.in"]).readLine() ; execute (if (v)->size() mod (v->count('o') or 1) then 'NO' else 'YES' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- pearl=input() print('NO' if len(pearl)%(pearl.count('o')or 1)else 'YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var pearl : String := (OclFile["System.in"]).readLine() ; execute (if (pearl)->size() mod (pearl->count('o') or 1) then 'NO' else 'YES' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline N=int(input()) A=list(map(int,input().split())) B=list(map(int,input().split())) def main(): graph=[[]for _ in range(51)] for start in range(51): for cost in range(1,51): if start % cost==0 : graph[0].append((cost,start)) for end in range(1,51): for cost in range(end+1,51): start=end+cost while start<=50 : graph[end].append((cost,start)) start+=cost use=0 for l in reversed(range(1,52)): for a,b in zip(A,B): ok=False q=[b] checked=[False]*51 checked[b]=True while q : qq=[] for p in q : if p==a : ok=True break for cost,np in graph[p]: if not checked[np]and(costtoInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var B : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; if __name__ = "__main__" then ( execute (main())->display() ) else skip; operation main() : OclAny pre: true post: true activity: var graph : Sequence := Integer.subrange(0, 51-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for start : Integer.subrange(0, 51-1) do ( for cost : Integer.subrange(1, 51-1) do ( if start mod cost = 0 then ( (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name cost)))))) , (test (logical_test (comparison (expr (atom (name start))))))) )))))))) )))) ) else skip)) ; for end : Integer.subrange(1, 51-1) do ( for cost : Integer.subrange(end + 1, 51-1) do ( var start : OclAny := end + cost ; while start <= 50 do ((expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name end)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name cost)))))) , (test (logical_test (comparison (expr (atom (name start))))))) )))))))) )))) ; start := start + cost))) ; var use : int := 0 ; for l : (Integer.subrange(1, 52-1))->reverse() do ( for _tuple : Integer.subrange(1, A->size())->collect( _indx | Sequence{A->at(_indx), B->at(_indx)} ) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); var ok : boolean := false ; var q : Sequence := Sequence{ b } ; var checked : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, 51) ; checked[b+1] := true ; while q do ( var qq : Sequence := Sequence{} ; for p : q do ( if p = a then ( ok := true ; break ) else skip ; for _tuple : graph[p+1] do (var _indx : int := 1; var cost : OclAny := _tuple->at(_indx); _indx := _indx + 1; var np : OclAny := _tuple->at(_indx); if not(checked[np+1]) & ((cost->compareTo(l)) < 0 or MathLib.bitwiseAnd(use, (1 * (2->pow(cost))))) then ( checked[np+1] := true ; execute ((np) : qq) ) else skip)) ; if ok then ( break ) else skip ; q := qq) ; if not(ok) then ( if l = 51 then ( return -1 ) else skip ; use := use or (1 * (2->pow(l))) ; break ) else skip)) ; return use; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from scipy.sparse.csgraph import floyd_warshall n,*a=map(int,open(0).read().split()) a,b=a[: n],a[n :] for x,y in zip(a,b): if x==y : continue if y>x : print(-1) exit() if x-y<=y : print(-1) exit() M=max(a) d=[] for k in range(M-1,-1,-1): s=set(a) e=[[0]*(M+1)for _ in range(M+1)] for i in range(M+1): e[i][i]=1 for i in d+list(range(k,0,-1)): t=s.copy() for x in s : e[x][x % i]=1 t |={x % i} s=t c=floyd_warshall(e) for x,y in zip(a,b): if c[x,y]==float('inf'): d+=k+1, break print(sum(2**k for k in d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{a.subrange(1,n),a.subrange(n+1)} ; for _tuple : Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), b->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if x = y then ( continue ) else skip ; if (y->compareTo(x)) > 0 then ( execute (-1)->display() ; exit() ) else skip ; if (x - y->compareTo(y)) <= 0 then ( execute (-1)->display() ; exit() ) else skip) ; var M : OclAny := (a)->max() ; var d : Sequence := Sequence{} ; for k : Integer.subrange(-1 + 1, M - 1)->reverse() do ( var s : Set := Set{}->union((a)) ; var e : Sequence := Integer.subrange(0, M + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (M + 1)))) ; for i : Integer.subrange(0, M + 1-1) do ( e[i+1][i+1] := 1) ; for i : d->union((Integer.subrange(0 + 1, k)->reverse())) do ( var t : OclAny := s->copy() ; for x : s do ( e[x+1][x mod i+1] := 1 ; t := t or Set{ x mod i }) ; s := t) ; var c : OclAny := floyd_warshall(e) ; for _tuple : Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), b->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if c[x+1][y+1] = ("" + (('inf')))->toReal() then ( d := d + (testlist (test (logical_test (comparison (expr (expr (atom (name k))) + (expr (atom (number (integer 1)))))))) ,) ; break ) else skip)) ; execute (((argument (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) ** (expr (atom (name k))))))) (comp_for for (exprlist (expr (atom (name k)))) in (logical_test (comparison (expr (atom (name d))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def warshall_floyd(d): r=range(M+1) for k in r : for i in r : for j in r : t=d[i][k]+d[k][j] if tx : print(-1) exit() if x-y<=y : print(-1) exit() M=max(a) d=[] for k in range(M-1,-1,-1): s=set(a) e=[[10**18]*(M+1)for _ in range(M+1)] for i in range(M+1): e[i][i]=1 for i in d+list(range(k,0,-1)): t=s.copy() for x in s : e[x][x % i]=1 t |={x % i} s=t c=warshall_floyd(e) for x,y in zip(a,b): if c[x][y]>=10**18 : d+=k+1, break print(sum(2**k for k in d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{a.subrange(1,n),a.subrange(n+1)} ; for _tuple : Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), b->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if x = y then ( continue ) else skip ; if (y->compareTo(x)) > 0 then ( execute (-1)->display() ; exit() ) else skip ; if (x - y->compareTo(y)) <= 0 then ( execute (-1)->display() ; exit() ) else skip) ; var M : OclAny := (a)->max() ; d := Sequence{} ; for k : Integer.subrange(-1 + 1, M - 1)->reverse() do ( var s : Set := Set{}->union((a)) ; var e : Sequence := Integer.subrange(0, M + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ (10)->pow(18) }, (M + 1)))) ; for i : Integer.subrange(0, M + 1-1) do ( e[i+1][i+1] := 1) ; for i : d->union((Integer.subrange(0 + 1, k)->reverse())) do ( t := s->copy() ; for x : s do ( e[x+1][x mod i+1] := 1 ; t := t or Set{ x mod i }) ; s := t) ; var c : OclAny := warshall_floyd(e) ; for _tuple : Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), b->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if (c[x+1][y+1]->compareTo((10)->pow(18))) >= 0 then ( d := d + (testlist (test (logical_test (comparison (expr (expr (atom (name k))) + (expr (atom (number (integer 1)))))))) ,) ; break ) else skip)) ; execute (((argument (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) ** (expr (atom (name k))))))) (comp_for for (exprlist (expr (atom (name k)))) in (logical_test (comparison (expr (atom (name d))))))))->sum())->display(); operation warshall_floyd(d : OclAny) : OclAny pre: true post: true activity: var r : Sequence := Integer.subrange(0, M + 1-1) ; for k : r do ( for i : r do ( for j : r do ( var t : OclAny := d[i+1][k+1] + d[k+1][j+1] ; if (t->compareTo(d[i+1][j+1])) < 0 then ( d[i+1][j+1] := t ) else skip))) ; return d; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from scipy.sparse.csgraph import dijkstra def make_graph(m,subset): matrix=[[0]*(m+1)for _ in range(m+1)] for k in subset : for s in range(k,m+1): matrix[s][s % k]=1 return dijkstra(matrix) def solve(n,aaa,bbb): for a,b in zip(aaa,bbb): if a50 for a,b in zip(aaa,bbb)): return-1 for k in range(m,0,-1): subset.remove(k) sp=make_graph(m,subset) if any(sp[a,b]>50 for a,b in zip(aaa,bbb)): subset.add(k) return sum(1<toInteger() ; aaa := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; bbb := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (solve(n, aaa, bbb))->display(); operation make_graph(m : OclAny, subset : OclAny) : OclAny pre: true post: true activity: var matrix : Sequence := Integer.subrange(0, m + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (m + 1)))) ; for k : subset do ( for s : Integer.subrange(k, m + 1-1) do ( matrix[s+1][s mod k+1] := 1)) ; return dijkstra(matrix); operation solve(n : OclAny, aaa : OclAny, bbb : OclAny) : OclAny pre: true post: true activity: for _tuple : Integer.subrange(1, aaa->size())->collect( _indx | Sequence{aaa->at(_indx), bbb->at(_indx)} ) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if (a->compareTo(b)) < 0 then ( return -1 ) else skip) ; m := (aaa)->max() ; subset := Set{}->union((Integer.subrange(1, m + 1-1))) ; var sp : OclAny := make_graph(m, subset) ; if ((argument (test (logical_test (comparison (comparison (expr (atom (name sp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a))))))) , (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])))) > (comparison (expr (atom (number (integer 50)))))))) (comp_for for (exprlist (expr (atom (name a))) , (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name aaa))))))) , (argument (test (logical_test (comparison (expr (atom (name bbb)))))))) )))))))))->exists( _x | _x = true ) then ( return -1 ) else skip ; for k : Integer.subrange(0 + 1, m)->reverse() do ( execute ((k) /: subset) ; sp := make_graph(m, subset) ; if ((argument (test (logical_test (comparison (comparison (expr (atom (name sp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a))))))) , (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])))) > (comparison (expr (atom (number (integer 50)))))))) (comp_for for (exprlist (expr (atom (name a))) , (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name aaa))))))) , (argument (test (logical_test (comparison (expr (atom (name bbb)))))))) )))))))))->exists( _x | _x = true ) then ( execute ((k) : subset) ) else skip) ; return ((argument (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name k))))))) (comp_for for (exprlist (expr (atom (name k)))) in (logical_test (comparison (expr (atom (name subset))))))))->sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def inpl(): return[int(i)for i in input().split()] from collections import defaultdict import sys def edge(S): e=defaultdict(lambda : set()) for i in range(N+1): for j in S : e[i].add(i % j) e[i]=e[i]|{i} return e def path(edge): p=defaultdict(lambda : set()) for st in range(N+1): Q,p[st],new=[edge[st]]*3 while Q : for j in Q : new=new | edge[j] Q=new-p[st] p[st]=p[st]| new return p K=int(input()) A=inpl() B=inpl() for i in range(K): if A[i]toInteger() ; var A : OclAny := inpl() ; var B : OclAny := inpl() ; for i : Integer.subrange(0, K-1) do ( if (A[i+1]->compareTo(B[i+1])) < 0 then ( execute (-1)->display() ; sys.exit() ) else skip) ; if A = B then ( execute (0)->display() ; sys.exit() ) else skip ; var N : OclAny := (A)->max() ; var T : Sequence := Sequence{} ; for l : Integer.subrange(-1 + 1, N)->reverse() do ( S := T->union((Integer.subrange(1, 1 + l-1))) ; var Pa : OclAny := path(edge(S)) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name K)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name B)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) not in (comparison (expr (atom (name Pa)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt continue)))))) ; execute ((l + 1) : T)) ; if not(T) then ( execute (2)->display() ; sys.exit() ) else skip ; if (T)->includes(N + 1) then ( execute (-1)->display() ; sys.exit() ) else skip ; execute ((T->select(i | true)->collect(i | ((2)->pow(i))))->sum())->display(); operation inpl() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation edge(S : OclAny) : OclAny pre: true post: true activity: var e : OclAny := defaultdict(lambda $$ : OclAny in (Set{}->union(()))) ; for i : Integer.subrange(0, N + 1-1) do ( for j : S do ((expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) % (expr (atom (name j))))))))) ))))) ; e[i+1] := MathLib.bitwiseOr(e[i+1], Set{ i })) ; return e; operation path(edge : OclAny) : OclAny pre: true post: true activity: var p : OclAny := defaultdict(lambda $$ : OclAny in (Set{}->union(()))) ; for st : Integer.subrange(0, N + 1-1) do ( var Q : OclAny := null; var p[st+1] : OclAny := null; var new : OclAny := null; Sequence{Q,p[st+1],new} := MatrixLib.elementwiseMult(Sequence{ edge[st+1] }, 3) ; while Q do ( for j : Q do ( var new : int := MathLib.bitwiseOr(new, edge[j+1])) ; var Q : double := new - p[st+1] ; p[st+1] := MathLib.bitwiseOr(p[st+1], new))) ; return p; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,data): self.data=data self.left=None self.right=None class Trie : def __init__(self): self.root=Node(0) def insert(self,pre_xor): self.temp=self.root for i in range(31,-1,-1): val=pre_xor &(1<exists( _x | result = _x ); attribute data : OclAny := data; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.left := null ; self.right := null; return self; } class Trie { static operation newTrie() : Trie pre: true post: Trie->exists( _x | result = _x ); attribute root : Node := (Node.newNode()).initialise(0); operation initialise() : Trie pre: true post: true activity: self.root := (Node.newNode()).initialise(0); return self; operation insert(pre_xor : OclAny) pre: true post: true activity: self.temp := self.root ; for i : Integer.subrange(-1 + 1, 31)->reverse() do ( var val : int := MathLib.bitwiseAnd(pre_xor, (1 * (2->pow(i)))) ; if val then ( if not(self.temp.right) then ( self.temp.right := (Node.newNode()).initialise(0) ) else skip ; self.temp := self.temp.right ) else skip ; if not(val) then ( if not(self.temp.left) then ( self.temp.left := (Node.newNode()).initialise(0) ) else skip ; self.temp := self.temp.left ) else skip) ; self.temp.data := pre_xor; operation query(xor : OclAny) : OclAny pre: true post: true activity: self.temp := self.root ; for i : Integer.subrange(-1 + 1, 31)->reverse() do ( val := MathLib.bitwiseAnd(xor, (1 * (2->pow(i)))) ; if val then ( if self.temp.left then ( self.temp := self.temp.left ) else (if self.temp.right then ( self.temp := self.temp.right ) else skip) ) else ( if self.temp.right then ( self.temp := self.temp.right ) else (if self.temp.left then ( self.temp := self.temp.left ) else skip) )) ; return MathLib.bitwiseXor(xor, self.temp.data); operation maxSubArrayXOR(n : OclAny,Arr : OclAny) : OclAny pre: true post: true activity: self := self.insertAt(0+1, 0) ; var result : double := -("" + (('inf')))->toReal() ; pre_xor := 0 ; for i : Integer.subrange(0, n-1) do ( pre_xor := MathLib.bitwiseXor(pre_xor, Arr[i+1]) ; self := self.insertAt(pre_xor+1, pre_xor) ; result := Set{result, self.query(pre_xor)}->max()) ; return result; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( Arr := Sequence{8}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 12 }))) ; n := (Arr)->size() ; var trie : Trie := (Trie.newTrie()).initialise() ; execute (trie.maxSubArrayXOR(n, Arr))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bitsAreInAltPatrnInGivenTRange(n,l,r): num=n>>(l-1); prev=num & 1 ; num=num>>1 ; for i in range(1,(r-l)): curr=num & 1 ; if(curr==prev): return False ; prev=curr ; num=num>>1 ; return True ; if __name__=="__main__" : n=18 ; l=1 ; r=3 ; if(bitsAreInAltPatrnInGivenTRange(n,l,r)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 18; ; l := 1; ; r := 3; ; if (bitsAreInAltPatrnInGivenTRange(n, l, r)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ) else skip; operation bitsAreInAltPatrnInGivenTRange(n : OclAny, l : OclAny, r : OclAny) pre: true post: true activity: var num : int := n /(2->pow((l - 1))); ; var prev : int := MathLib.bitwiseAnd(num, 1); ; num := num /(2->pow(1)); ; for i : Integer.subrange(1, (r - l)-1) do ( var curr : int := MathLib.bitwiseAnd(num, 1); ; if (curr = prev) then ( return false; ) else skip ; prev := curr; ; num := num /(2->pow(1));) ; return true;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import os import math for s in sys.stdin : n=int(s) if n==-1 : break v=[1,0] for i in range(n-1): w=[-v[1],v[0]] l=math.sqrt(w[0]**2+w[1]**2) normalized=[w[0]/l,w[1]/l] vx=v[0]+normalized[0] vy=v[1]+normalized[1] v=[vx,vy] print(v[0]) print(v[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; for s : OclFile["System.in"] do ( var n : int := ("" + ((s)))->toInteger() ; if n = -1 then ( break ) else skip ; var v : Sequence := Sequence{1}->union(Sequence{ 0 }) ; for i : Integer.subrange(0, n - 1-1) do ( var w : Sequence := Sequence{-v[1+1]}->union(Sequence{ v->first() }) ; var l : double := ((w->first())->pow(2) + (w[1+1])->pow(2))->sqrt() ; var normalized : Sequence := Sequence{w->first() / l}->union(Sequence{ w[1+1] / l }) ; var vx : OclAny := v->first() + normalized->first() ; var vy : OclAny := v[1+1] + normalized[1+1] ; v := Sequence{vx}->union(Sequence{ vy })) ; execute (v->first())->display() ; execute (v[1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSolutions(a): count=bin(a).count('1') return 2**count if __name__=="__main__" : a=3 print(countSolutions(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := 3 ; execute (countSolutions(a))->display() ) else skip; operation countSolutions(a : OclAny) : OclAny pre: true post: true activity: var count : OclAny := bin(a)->count('1') ; return (2)->pow(count); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) x=a.index(1)+1 y=a.index(n)+1 print(max(abs(n-x),abs(n-y),abs(1-x),abs(1-y))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : int := a->indexOf(1) - 1 + 1 ; var y : int := a->indexOf(n) - 1 + 1 ; execute (Set{(n - x)->abs(), (n - y)->abs(), (1 - x)->abs(), (1 - y)->abs()}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() s=input().split() M=s.index(n) n=int(n) m=s.index('1') print(max(m,M,n-m-1,n-1-M)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var s : OclAny := input().split() ; var M : int := s->indexOf(n) - 1 ; n := ("" + ((n)))->toInteger() ; var m : int := s->indexOf('1') - 1 ; execute (Set{m, M, n - m - 1, n - 1 - M}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s=input() return(list(s[: len(s)-1])) def invr(): return(map(int,input().split())) def printList(strings): for string in strings : print(string) n=inp() a=invr() list_a=list(a) idx_max=list_a.index(n) idx_min=list_a.index(1) max_idx=max(idx_max,idx_min,abs(n-1-idx_max),abs(n-1-idx_min)) print(max_idx) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := inp() ; var a : OclAny := invr() ; var list_a : Sequence := (a) ; var idx_max : int := list_a->indexOf(n) - 1 ; var idx_min : int := list_a->indexOf(1) - 1 ; var max_idx : OclAny := Set{idx_max, idx_min, (n - 1 - idx_max)->abs(), (n - 1 - idx_min)->abs()}->max() ; execute (max_idx)->display(); operation inp() : OclAny pre: true post: true activity: return (("" + (((OclFile["System.in"]).readLine())))->toInteger()); operation inlt() : OclAny pre: true post: true activity: return (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))); operation insr() : OclAny pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; return ((s.subrange(1,(s)->size() - 1))); operation invr() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation printList(strings : OclAny) pre: true post: true activity: for string : strings do ( execute (string)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) numbers=input().split(' ') for i in range(n): numbers[i]=int(numbers[i]) max_number_index=numbers.index(max(numbers)) min_number_index=numbers.index(min(numbers)) initial_distance=abs(min_number_index-max_number_index) if max_number_index==0 or min_number_index==0 or max_number_index==n-1 or min_number_index==n-1 : print(n-1) else : print(max(initial_distance,n-1-max_number_index,n-1-min_number_index,max_number_index,min_number_index)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var numbers : OclAny := input().split(' ') ; for i : Integer.subrange(0, n-1) do ( numbers[i+1] := ("" + ((numbers[i+1])))->toInteger()) ; var max_number_index : int := numbers->indexOf((numbers)->max()) - 1 ; var min_number_index : int := numbers->indexOf((numbers)->min()) - 1 ; var initial_distance : double := (min_number_index - max_number_index)->abs() ; if max_number_index = 0 or min_number_index = 0 or max_number_index = n - 1 or min_number_index = n - 1 then ( execute (n - 1)->display() ) else ( execute (Set{initial_distance, n - 1 - max_number_index, n - 1 - min_number_index, max_number_index, min_number_index}->max())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=*map(int,input().split()), x,y=sorted([a.index(1),a.index(n)]) print(max(y,n-1-x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := (testlist_star_expr (star_expr * (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))) ,) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{a->indexOf(1) - 1}->union(Sequence{ a->indexOf(n) - 1 })->sort() ; execute (Set{y, n - 1 - x}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumSubarrayMins(A,n): left,right=[None]*n,[None]*n s1,s2=[],[] for i in range(0,n): cnt=1 while len(s1)>0 and s1[-1][0]>A[i]: cnt+=s1[-1][1] s1.pop() s1.append([A[i],cnt]) left[i]=cnt for i in range(n-1,-1,-1): cnt=1 while len(s2)>0 and s2[-1][0]>A[i]: cnt+=s2[-1][1] s2.pop() s2.append([A[i],cnt]) right[i]=cnt result=0 for i in range(0,n): result+=A[i]*left[i]*right[i] return result if __name__=="__main__" : A=[3,1,2,4] n=len(A) print(sumSubarrayMins(A,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( A := Sequence{3}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 4 }))) ; n := (A)->size() ; execute (sumSubarrayMins(A, n))->display() ) else skip; operation sumSubarrayMins(A : OclAny, n : OclAny) : OclAny pre: true post: true activity: var left : OclAny := null; var right : OclAny := null; Sequence{left,right} := Sequence{MatrixLib.elementwiseMult(Sequence{ null }, n),MatrixLib.elementwiseMult(Sequence{ null }, n)} ; var s1 : OclAny := null; var s2 : OclAny := null; Sequence{s1,s2} := Sequence{Sequence{},Sequence{}} ; for i : Integer.subrange(0, n-1) do ( var cnt : int := 1 ; while (s1)->size() > 0 & (s1->last()->first()->compareTo(A[i+1])) > 0 do ( cnt := cnt + s1->last()[1+1] ; s1 := s1->front()) ; execute ((Sequence{A[i+1]}->union(Sequence{ cnt })) : s1) ; left[i+1] := cnt) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( cnt := 1 ; while (s2)->size() > 0 & (s2->last()->first()->compareTo(A[i+1])) > 0 do ( cnt := cnt + s2->last()[1+1] ; s2 := s2->front()) ; execute ((Sequence{A[i+1]}->union(Sequence{ cnt })) : s2) ; right[i+1] := cnt) ; var result : int := 0 ; for i : Integer.subrange(0, n-1) do ( result := result + A[i+1] * left[i+1] * right[i+1]) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isValid(n,d): digit=n % 10 ; sum=digit ; if(digit==d): return False ; n=int(n/10); while(n>0): digit=n % 10 ; if(digit==d or digit<=sum): return False ; else : sum+=digit ; n=int(n/10); return True ; def printGoodNumber(L,R,d): for i in range(L,R+1): if(isValid(i,d)): print(i,end=" "); L=410 ; R=520 ; d=3 ; printGoodNumber(L,R,d); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; L := 410; ; R := 520; ; d := 3; ; printGoodNumber(L, R, d);; operation isValid(n : OclAny, d : OclAny) pre: true post: true activity: var digit : int := n mod 10; ; var sum : int := digit; ; if (digit = d) then ( return false; ) else skip ; n := ("" + ((n / 10)))->toInteger(); ; while (n > 0) do ( digit := n mod 10; ; if (digit = d or (digit->compareTo(sum)) <= 0) then ( return false; ) else ( sum := sum + digit; ; n := ("" + ((n / 10)))->toInteger(); )) ; return true;; operation printGoodNumber(L : OclAny, R : OclAny, d : OclAny) pre: true post: true activity: for i : Integer.subrange(L, R + 1-1) do ( if (isValid(i, d)) then ( execute (i)->display(); ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) ans=0 for i in range(1,N+1,2): cnt=0 for j in range(1,i+1): if i % j==0 : cnt+=1 if cnt==8 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; for i : Integer.subrange(1, N + 1-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( var cnt : int := 0 ; for j : Integer.subrange(1, i + 1-1) do ( if i mod j = 0 then ( cnt := cnt + 1 ) else skip) ; if cnt = 8 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inp=input() n=int(inp) if n<105 : print(0) elif 105<=n<135 : print(1) elif 135<=n<165 : print(2) elif 165<=n<189 : print(3) elif 189<=n<195 : print(4) elif 195<=n : print(5) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inp : String := (OclFile["System.in"]).readLine() ; var n : int := ("" + ((inp)))->toInteger() ; if n < 105 then ( execute (0)->display() ) else (if 105 <= n & (n < 135) then ( execute (1)->display() ) else (if 135 <= n & (n < 165) then ( execute (2)->display() ) else (if 165 <= n & (n < 189) then ( execute (3)->display() ) else (if 189 <= n & (n < 195) then ( execute (4)->display() ) else (if 195 <= n then ( execute (5)->display() ) else skip ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def solve(): n,k=map(int,input().split()) a=list(map(int,input().split())) if k not in set(a): print("NO") return if n==1 : if a[0]==k : print("YES") else : print("NO") return for i in range(n): if i+1=k : print("YES") return if i+2=k : print("YES") return print("NO") return for nt in range(int(input())): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; for nt : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve()); operation solve() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (Set{}->union((a)))->excludes(k) then ( execute ("NO")->display() ; return ) else skip ; if n = 1 then ( if a->first() = k then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ; return ) else skip ; for i : Integer.subrange(0, n-1) do ( if (i + 1->compareTo(n)) < 0 then ( if (Set{a[i+1], a[i + 1+1]}->min()->compareTo(k)) >= 0 then ( execute ("YES")->display() ; return ) else skip ) else skip ; if (i + 2->compareTo(n)) < 0 then ( if (sorted(Sequence{a[i+1]}->union(Sequence{a[i + 1+1]}->union(Sequence{ a[i + 2+1] })))[1+1]->compareTo(k)) >= 0 then ( execute ("YES")->display() ; return ) else skip ) else skip) ; execute ("NO")->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy import math def get_int(): return int(input()) def get_string(): return input() def get_int_list(): return[int(x)for x in input().split()] def get_string_list(): return input().split() def get_int_multi(): return map(int,input().split()) def get_string_char_list(): return list(str(input())) def main(): n=get_int() ans=0 for i in range(1,n+1,2): count=0 for ii in range(1,n+1): if i % ii==0 : count+=1 if count==8 : ans+=1 print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation get_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation get_string() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation get_int_list() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation get_string_list() : OclAny pre: true post: true activity: return input().split(); operation get_int_multi() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation get_string_char_list() : OclAny pre: true post: true activity: return (("" + (((OclFile["System.in"]).readLine()))))->characters(); operation main() pre: true post: true activity: var n : OclAny := get_int() ; var ans : int := 0 ; for i : Integer.subrange(1, n + 1-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( var count : int := 0 ; for ii : Integer.subrange(1, n + 1-1) do ( if i mod ii = 0 then ( count := count + 1 ) else skip) ; if count = 8 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,m=map(int,input().split()) if n==1 : print(m*(m+1)//2) elif m==1 : print(n*(n+1)//2) else : p=m*(m-1)//2 q=n*(n+1)//2 q*=m print(p+q) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 1 then ( execute (m * (m + 1) div 2)->display() ) else (if m = 1 then ( execute (n * (n + 1) div 2)->display() ) else ( var p : int := m * (m - 1) div 2 ; var q : int := n * (n + 1) div 2 ; q := q * m ; execute (p + q)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(len([i for i in range(int(input()))if i+1 in[105,135,165,189,195]])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1)->select(i | (Sequence{105}->union(Sequence{135}->union(Sequence{165}->union(Sequence{189}->union(Sequence{ 195 })))))->includes(i + 1))->collect(i | (i)))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import collections import fractions import itertools import functools import operator def yakusu_rekkyo(n): lower_divisors,upper_divisors=[],[] i=1 while i*i<=n : if n % i==0 : lower_divisors.append(i) if i!=n//i : upper_divisors.append(n//i) i+=1 return lower_divisors+upper_divisors[: :-1] def solve(): n=int(input()) cnt=0 for i in range(1,n+1): hoge=0 for j in yakusu_rekkyo(i): if j % 2==1 : hoge+=1 if hoge==8 : cnt+=1 print(cnt) return 0 if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation yakusu_rekkyo(n : OclAny) : OclAny pre: true post: true activity: var lower_divisors : OclAny := null; var upper_divisors : OclAny := null; Sequence{lower_divisors,upper_divisors} := Sequence{Sequence{},Sequence{}} ; var i : int := 1 ; while (i * i->compareTo(n)) <= 0 do ( if n mod i = 0 then ( execute ((i) : lower_divisors) ; if i /= n div i then ( execute ((n div i) : upper_divisors) ) else skip ) else skip ; i := i + 1) ; return lower_divisors + upper_divisors(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); operation solve() : OclAny pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cnt : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( var hoge : int := 0 ; for j : yakusu_rekkyo(i) do ( if j mod 2 = 1 then ( hoge := hoge + 1 ) else skip) ; if hoge = 8 then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display() ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def nthprimedigitsnumber(n): len=1 ; prev_count=0 ; while(1): curr_count=(prev_count+math.pow(4,len)); if(prev_count=n): break ; len+=1 ; prev_count=curr_count ; for i in range(1,len+1): for j in range(1,5): if(prev_count+pow(4,len-i); operation nthprimedigitsnumber(n : OclAny) pre: true post: true activity: var len : int := 1; ; var prev_count : int := 0; ; while (1) do ( var curr_count : int := (prev_count + (4)->pow(len)); ; if ((prev_count->compareTo(n)) < 0 & (curr_count->compareTo(n)) >= 0) then ( break; ) else skip ; len := len + 1; ; prev_count := curr_count;) ; for i : Integer.subrange(1, len + 1-1) do ( for j : Integer.subrange(1, 5-1) do ( if ((prev_count + (4)->pow(len - i)->compareTo(n)) < 0) then ( prev_count := prev_count + (4)->pow(len - i); ) else ( if (j = 1) then ( execute ("2")->display(); ) else (if (j = 2) then ( execute ("3")->display(); ) else (if (j = 3) then ( execute ("5")->display(); ) else (if (j = 4) then ( execute ("7")->display(); ) else skip ) ) ) ; break; ))) ; execute (->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_lines=int(input()) for iii in range(num_lines): s=input() low_idx=0 high_idx=0 lowest_amount=-1 counts=[0,0,0] counts[int(s[0])-1]+=1 is_valid=True while(counts[0]==0 or counts[1]==0 or counts[2]==0): high_idx+=1 if(high_idx>=len(s)): is_valid=False break counts[int(s[high_idx])-1]+=1 if(not is_valid): print(0) else : assert(high_idx>=2) lowest_amount=high_idx while(low_idx!=len(s)-1): if(is_valid): counts[int(s[low_idx])-1]-=1 if(counts[int(s[low_idx])-1]==0): is_valid=False low_idx+=1 if(is_valid): lowest_amount=min(lowest_amount,high_idx-low_idx) else : if(high_idx==len(s)-1): break high_idx+=1 counts[int(s[high_idx])-1]+=1 if(counts[int(s[high_idx])-1]==1): is_valid=True print(lowest_amount+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_lines : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for iii : Integer.subrange(0, num_lines-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var low_idx : int := 0 ; var high_idx : int := 0 ; var lowest_amount : int := -1 ; var counts : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) ; counts[("" + ((s->first())))->toInteger() - 1+1] := counts[("" + ((s->first())))->toInteger() - 1+1] + 1 ; var is_valid : boolean := true ; while (counts->first() = 0 or counts[1+1] = 0 or counts[2+1] = 0) do ( high_idx := high_idx + 1 ; if ((high_idx->compareTo((s)->size())) >= 0) then ( is_valid := false ; break ) else skip ; counts[("" + ((s[high_idx+1])))->toInteger() - 1+1] := counts[("" + ((s[high_idx+1])))->toInteger() - 1+1] + 1) ; if (not(is_valid)) then ( execute (0)->display() ) else ( assert (high_idx >= 2) do "assertion failed" ; lowest_amount := high_idx ; while (low_idx /= (s)->size() - 1) do ( if (is_valid) then ( counts[("" + ((s[low_idx+1])))->toInteger() - 1+1] := counts[("" + ((s[low_idx+1])))->toInteger() - 1+1] - 1 ; if (counts[("" + ((s[low_idx+1])))->toInteger() - 1+1] = 0) then ( is_valid := false ) else skip ; low_idx := low_idx + 1 ; if (is_valid) then ( lowest_amount := Set{lowest_amount, high_idx - low_idx}->min() ) else skip ) else ( if (high_idx = (s)->size() - 1) then ( break ) else skip ; high_idx := high_idx + 1 ; counts[("" + ((s[high_idx+1])))->toInteger() - 1+1] := counts[("" + ((s[high_idx+1])))->toInteger() - 1+1] + 1 ; if (counts[("" + ((s[high_idx+1])))->toInteger() - 1+1] = 1) then ( is_valid := true ) else skip )) ; execute (lowest_amount + 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ternary_string(s): if len(s)<3 : return 0 shortest=len(s)+1 start=0 end=0 totals=[0]*3 done=False while not done : contains_all=totals[0]>0 and totals[1]>0 and totals[2]>0 if contains_all : shortest=min(shortest,end-start) if shortest<=len(s)and shortest==3 : return 3 if contains_all : removed_index=int(s[start])-1 totals[removed_index]-=1 start+=1 elif endlen(s): return 0 return shortest if __name__=='__main__' : t=int(input()) for i in range(0,t): print(ternary_string(input())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( execute (ternary_string((OclFile["System.in"]).readLine()))->display()) ) else skip; operation ternary_string(s : OclAny) : OclAny pre: true post: true activity: if (s)->size() < 3 then ( return 0 ) else skip ; var shortest : int := (s)->size() + 1 ; var start : int := 0 ; var end : int := 0 ; var totals : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 3) ; var done : boolean := false ; while not(done) do ( var contains_all : boolean := totals->first() > 0 & totals[1+1] > 0 & totals[2+1] > 0 ; if contains_all then ( shortest := Set{shortest, end - start}->min() ) else skip ; if (shortest->compareTo((s)->size())) <= 0 & shortest = 3 then ( return 3 ) else skip ; if contains_all then ( var removed_index : double := ("" + ((s[start+1])))->toInteger() - 1 ; totals[removed_index+1] := totals[removed_index+1] - 1 ; start := start + 1 ) else (if (end->compareTo((s)->size())) < 0 then ( var added_index : double := ("" + ((s[end+1])))->toInteger() - 1 ; totals[added_index+1] := totals[added_index+1] + 1 ; end := end + 1 ) else ( done := true ) ) ) ; if (shortest->compareTo((s)->size())) > 0 then ( return 0 ) else skip ; return shortest; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys numCases=int(input()) while numCases>0 : text=input() counts=[0]*3 count=sys.maxsize leftIndex=0 for i in range(len(text)): position=ord(text[i])-49 counts[position]+=1 while counts[ord(text[leftIndex])-49]>1 : counts[ord(text[leftIndex])-49]-=1 leftIndex+=1 if counts[0]!=0 and counts[1]!=0 and counts[2]!=0 : count=min(count,i-leftIndex+1) if count==sys.maxsize : count=0 print(count) numCases-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var numCases : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while numCases > 0 do ( var text : String := (OclFile["System.in"]).readLine() ; var counts : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 3) ; var count : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; var leftIndex : int := 0 ; for i : Integer.subrange(0, (text)->size()-1) do ( var position : double := (text[i+1])->char2byte() - 49 ; counts[position+1] := counts[position+1] + 1 ; while counts[(text[leftIndex+1])->char2byte() - 49+1] > 1 do ( counts[(text[leftIndex+1])->char2byte() - 49+1] := counts[(text[leftIndex+1])->char2byte() - 49+1] - 1 ; leftIndex := leftIndex + 1) ; if counts->first() /= 0 & counts[1+1] /= 0 & counts[2+1] /= 0 then ( count := Set{count, i - leftIndex + 1}->min() ) else skip) ; if count = (trailer . (name maxsize)) then ( count := 0 ) else skip ; execute (count)->display() ; numCases := numCases - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def check_has_all_chars(freq): for k in freq.keys(): if freq[k]==0 : return False return True t_num_test_cases=int(input()) for t in range(t_num_test_cases): given_input=input() shortest=math.inf freq={'1' : 0,'2' : 0,'3' : 0} lft=0 for rt in range(len(given_input)): freq[given_input[rt]]+=1 while(lfttoInteger() ; for t : Integer.subrange(0, t_num_test_cases-1) do ( var given_input : String := (OclFile["System.in"]).readLine() ; var shortest : OclAny := ; freq := Map{ '1' |-> 0 }->union(Map{ '2' |-> 0 }->union(Map{ '3' |-> 0 })) ; var lft : int := 0 ; for rt : Integer.subrange(0, (given_input)->size()-1) do ( freq[given_input[rt+1]+1] := freq[given_input[rt+1]+1] + 1 ; while ((lft->compareTo((given_input)->size())) < 0 & check_has_all_chars(freq)) do ( shortest := Set{shortest, rt - lft + 1}->min() ; freq[given_input[lft+1]+1] := freq[given_input[lft+1]+1] - 1 ; lft := lft + 1)) ; if shortest = then ( execute (0)->display() ) else ( execute (shortest)->display() )); operation check_has_all_chars(freq : OclAny) : OclAny pre: true post: true activity: for k : freq.keys() do ( if freq[k+1] = 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import zip_longest as zl n,m=map(int,input().split()) if m-n*2<=0 : wind=list(range(1,m+1)) prh=[] else : man=range(1,m+1) wind=list(man[: n*2]) prh=list(man[n*2 :]) for a,b in zl(prh,wind,fillvalue=''): print(str(a)+' '+str(b),end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if m - n * 2 <= 0 then ( var wind : Sequence := (Integer.subrange(1, m + 1-1)) ; var prh : Sequence := Sequence{} ) else ( var man : Sequence := Integer.subrange(1, m + 1-1) ; wind := (man.subrange(1,n * 2)) ; prh := (man.subrange(n * 2+1)) ) ; for _tuple : zl(prh, wind, (argument (test (logical_test (comparison (expr (atom (name fillvalue)))))) = (test (logical_test (comparison (expr (atom ''))))))) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); execute (("" + ((a))) + ' ' + ("" + ((b))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from bisect import bisect_right as bi_r inf=float('inf') n,*A=map(int,sys.stdin.read().split()) def main(): res=[inf]*n for a in A[: :-1]: i=bi_r(res,a) res[i]=a for i in range(n): if res[i]==inf : return i return n if __name__=='__main__' : ans=main() print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; var n : OclAny := null; var A : OclAny := null; Sequence{n,A} := (sys.stdin.readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; if __name__ = '__main__' then ( var ans : OclAny := main() ; execute (ans)->display() ) else skip; operation main() : OclAny pre: true post: true activity: var res : Sequence := MatrixLib.elementwiseMult(Sequence{ Math_PINFINITY }, n) ; for a : A(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( var i : OclAny := bi_r(res, a) ; res[i+1] := a) ; for i : Integer.subrange(0, n-1) do ( if res[i+1] = Math_PINFINITY then ( return i ) else skip) ; return n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=input().split() n,m=int(n),int(m) arr=[[0]*n,[0]*n,[0]*n,[0]*n] passenger=1 for i in range(n): arr[0][i]=passenger+(2*n) arr[1][i]=passenger arr[2][i]=passenger+(2*n)+1 arr[3][i]=passenger+1 passenger+=2 for i in range(n): for j in range(4): if(arr[j][i]<=m): print(arr[j][i],end=' ') print('\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split() ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{("" + ((n)))->toInteger(),("" + ((m)))->toInteger()} ; var arr : Sequence := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, n)}->union(Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, n)}->union(Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, n)}->union(Sequence{ MatrixLib.elementwiseMult(Sequence{ 0 }, n) }))) ; var passenger : int := 1 ; for i : Integer.subrange(0, n-1) do ( arr->first()[i+1] := passenger + (2 * n) ; arr[1+1][i+1] := passenger ; arr[2+1][i+1] := passenger + (2 * n) + 1 ; arr[3+1][i+1] := passenger + 1 ; passenger := passenger + 2) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, 4-1) do ( if ((arr[j+1][i+1]->compareTo(m)) <= 0) then ( execute (arr[j+1][i+1])->display() ) else skip)) ; execute (' ')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- pairs,passa=map(int,input().split(" ")) data=[] i=0 while i<=2*(pairs-1): if 2*pairs+1+i<=passa : data.append(2*pairs+1+i) if 1+i<=passa : data.append(1+i) if 2*pairs+2+i<=passa : data.append(2*pairs+2+i) if 2+i<=passa : data.append(2+i) i+=2 print(" ".join(map(str,data))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var pairs : OclAny := null; var passa : OclAny := null; Sequence{pairs,passa} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var data : Sequence := Sequence{} ; var i : int := 0 ; while (i->compareTo(2 * (pairs - 1))) <= 0 do ( if (2 * pairs + 1 + i->compareTo(passa)) <= 0 then ( execute ((2 * pairs + 1 + i) : data) ) else skip ; if (1 + i->compareTo(passa)) <= 0 then ( execute ((1 + i) : data) ) else skip ; if (2 * pairs + 2 + i->compareTo(passa)) <= 0 then ( execute ((2 * pairs + 2 + i) : data) ) else skip ; if (2 + i->compareTo(passa)) <= 0 then ( execute ((2 + i) : data) ) else skip ; i := i + 2) ; execute (StringLib.sumStringsWithSeparator(((data)->collect( _x | (OclType["String"])->apply(_x) )), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _n=int(input()) for i in range(1,_n+1): _x,_y=input().split() _x=int(_x) _y=int(_y) _ans=(1+_y)*_y/2 _ans+=(_y+_x*_y)*_x/2 _ans-=_y print(int(_ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(1, _n + 1-1) do ( var _x : OclAny := null; var _y : OclAny := null; Sequence{_x,_y} := input().split() ; var _x : int := ("" + ((_x)))->toInteger() ; var _y : int := ("" + ((_y)))->toInteger() ; var _ans : double := (1 + _y) * _y / 2 ; _ans := _ans + (_y + _x * _y) * _x / 2 ; _ans := _ans - _y ; execute (("" + ((_ans)))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() n,m=map(int,input().split()) A=[] for i in range(1,2*n,2): A+=[2*n+i,i,2*n+i+1,i+1] print(*(a for a in A if a<=m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := Sequence{} ; for i : Integer.subrange(1, 2 * n-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( A := A + Sequence{2 * n + i}->union(Sequence{i}->union(Sequence{2 * n + i + 1}->union(Sequence{ i + 1 })))) ; execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name a)))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name A))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name a)))) <= (comparison (expr (atom (name m)))))))))) ))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split(' ')) rows=[list(range(1,2*n,2)),list(range(2,2*n+1,2)),list(range(2*n+1,4*n+1,2)),list(range(2*n+2,4*n+1,2))] final_list=[] for(LNW,LW,RNW,RW)in zip(rows[2],rows[0],rows[3],rows[1]): final_list.extend([LNW,LW,RNW,RW]) for element in range(len(final_list)-1,-1,-1): if final_list[element]>m : final_list.pop(element) print(*final_list,sep=(' ')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var rows : Sequence := Sequence{(Integer.subrange(1, 2 * n-1)->select( $x | ($x - 1) mod 2 = 0 ))}->union(Sequence{(Integer.subrange(2, 2 * n + 1-1)->select( $x | ($x - 2) mod 2 = 0 ))}->union(Sequence{(Integer.subrange(2 * n + 1, 4 * n + 1-1)->select( $x | ($x - 2 * n + 1) mod 2 = 0 ))}->union(Sequence{ (Integer.subrange(2 * n + 2, 4 * n + 1-1)->select( $x | ($x - 2 * n + 2) mod 2 = 0 )) }))) ; var final_list : Sequence := Sequence{} ; for Sequence{LNW, LW, RNW, RW} : Integer.subrange(1, rows[2+1]->size())->collect( _indx | Sequence{rows[2+1]->at(_indx), rows->first()->at(_indx)} ) do ( final_list := final_list->union(Sequence{LNW}->union(Sequence{LW}->union(Sequence{RNW}->union(Sequence{ RW }))))) ; for element : Integer.subrange(-1 + 1, (final_list)->size() - 1)->reverse() do ( if (final_list[element+1]->compareTo(m)) > 0 then ( final_list := final_list->excludingAt(element+1) ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name final_list))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxAND(L,R): maximum=L & R for i in range(L,R,1): for j in range(i+1,R+1,1): maximum=max(maximum,(i & j)) return maximum if __name__=='__main__' : L=1 R=632 print(maxAND(L,R)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( L := 1 ; R := 632 ; execute (maxAND(L, R))->display() ) else skip; operation maxAND(L : OclAny, R : OclAny) : OclAny pre: true post: true activity: var maximum : int := MathLib.bitwiseAnd(L, R) ; for i : Integer.subrange(L, R-1)->select( $x | ($x - L) mod 1 = 0 ) do ( for j : Integer.subrange(i + 1, R + 1-1)->select( $x | ($x - i + 1) mod 1 = 0 ) do ( maximum := Set{maximum, (MathLib.bitwiseAnd(i, j))}->max())) ; return maximum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Minimum_Operations(a,n): np=[0 for i in range(n+1)] for i in range(n-1,-1,-1): np[i]=np[i+1] if(a[i]<=0): np[i]+=1 pos=0 ans=n for i in range(n-1): if(a[i]>=0): pos+=1 ans=min(ans,pos+np[i+1]) return ans a=[-1,0,1,2] n=len(a) print(Minimum_Operations(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{-1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 2 }))) ; n := (a)->size() ; execute (Minimum_Operations(a, n))->display(); operation Minimum_Operations(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var np : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( := ; if (a[i+1] <= 0) then ( := + 1 ) else skip) ; var pos : int := 0 ; var ans : OclAny := n ; for i : Integer.subrange(0, n - 1-1) do ( if (a[i+1] >= 0) then ( pos := pos + 1 ) else skip ; ans := Set{ans, pos + }->min()) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import itertools import sys import copy A,B,K=map(int,input().split()) if B-Acollect( _x | (OclType["int"])->apply(_x) ) ; if (B - A->compareTo(K * 2)) < 0 then ( for i : Integer.subrange(A, B + 1-1) do ( execute (("" + ((i))))->display()) ) else ( for i : Integer.subrange(A, A + K-1) do ( execute (("" + ((i))))->display()) ; for i : Integer.subrange(B - K + 1, B + 1-1) do ( execute (("" + ((i))))->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re from math import ceil,floor,sqrt,pi,factorial,gcd from copy import deepcopy from collections import Counter,deque from heapq import heapify,heappop,heappush from itertools import accumulate,product,combinations,combinations_with_replacement from bisect import bisect,bisect_left,bisect_right from functools import reduce from decimal import Decimal,getcontext def i_input(): return int(input()) def i_map(): return map(int,input().split()) def i_list(): return list(i_map()) def i_row(N): return[i_input()for _ in range(N)] def i_row_list(N): return[i_list()for _ in range(N)] def s_input(): return input() def s_map(): return input().split() def s_list(): return list(s_map()) def s_row(N): return[s_input for _ in range(N)] def s_row_str(N): return[s_list()for _ in range(N)] def s_row_list(N): return[list(s_input())for _ in range(N)] def lcm(a,b): return a*b//gcd(a,b) sys.setrecursionlimit(10**6) INF=float('inf') MOD=10**9+7 num_list=[] str_list=[] def main(): a,b,k=i_map() ans_list=[] for i in range(a,a+k): if i>b : continue ans_list.append(i) for i in range(b-k+1,b+1): if ipow(6)) ; var INF : double := ("" + (('inf')))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; var num_list : Sequence := Sequence{} ; var str_list : Sequence := Sequence{} ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation i_input() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation i_map() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation i_list() : OclAny pre: true post: true activity: return (i_map()); operation i_row(N : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (i_input())); operation i_row_list(N : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (i_list())); operation s_input() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation s_map() : OclAny pre: true post: true activity: return input().split(); operation s_list() : OclAny pre: true post: true activity: return (s_map()); operation s_row(N : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (s_input)); operation s_row_str(N : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (s_list())); operation s_row_list(N : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | ((s_input()))); operation lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a * b div gcd(a, b); operation main() pre: true post: true activity: var k : OclAny := null; Sequence{a,b,k} := i_map() ; var ans_list : Sequence := Sequence{} ; for i : Integer.subrange(a, a + k-1) do ( if (i->compareTo(b)) > 0 then ( continue ) else skip ; execute ((i) : ans_list)) ; for i : Integer.subrange(b - k + 1, b + 1-1) do ( if (i->compareTo(a)) < 0 then ( continue ) else skip ; execute ((i) : ans_list)) ; ans_list := (Set{}->union((ans_list))) ; for num : ans_list do ( execute (num)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : A,B,K=map(int,input().split()) answer=[] for i in range(K): n=A+i if n<=B : answer.append(n) m=B-i if A<=m : answer.append(m) answer=sorted(list(set(answer))) for i in range(len(answer)): print(answer[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var A : OclAny := null; var B : OclAny := null; var K : OclAny := null; Sequence{A,B,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var answer : Sequence := Sequence{} ; for i : Integer.subrange(0, K-1) do ( var n : OclAny := A + i ; if (n->compareTo(B)) <= 0 then ( execute ((n) : answer) ) else skip ; var m : double := B - i ; if (A->compareTo(m)) <= 0 then ( execute ((m) : answer) ) else skip) ; answer := (Set{}->union((answer)))->sort() ; for i : Integer.subrange(0, (answer)->size()-1) do ( execute (answer[i+1])->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left from collections import deque import sys input=sys.stdin.readline N=int(input()) A=[int(input())for _ in range(N)] q=deque([A[0]]) for i in range(1,N): insert_index=bisect_left(q,A[i]) if insert_index==0 : q.appendleft(A[i]) else : q[insert_index-1]=A[i] print(len(q)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var q : Sequence := (Sequence{ A->first() }) ; for i : Integer.subrange(1, N-1) do ( var insert_index : OclAny := bisect_left(q, A[i+1]) ; if insert_index = 0 then ( q := q->prepend(A[i+1]) ) else ( q[insert_index - 1+1] := A[i+1] )) ; execute ((q)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(A : int,B : int,K : int): if(B-A+1)<=2*K : for i in range(A,B+1): print(i) else : for i in range(A,A+K): print(i) for i in range(B-K+1,B+1): print(i) def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() A=int(next(tokens)) B=int(next(tokens)) K=int(next(tokens)) solve(A,B,K) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(A : int, B : int, K : int) pre: true post: true activity: if ((B - A + 1)->compareTo(2 * K)) <= 0 then ( for i : Integer.subrange(A, B + 1-1) do ( execute (i)->display()) ) else ( for i : Integer.subrange(A, A + K-1) do ( execute (i)->display()) ; for i : Integer.subrange(B - K + 1, B + 1-1) do ( execute (i)->display()) ); operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var A : int := ("" + (((tokens).next())))->toInteger() ; var B : int := ("" + (((tokens).next())))->toInteger() ; var K : int := ("" + (((tokens).next())))->toInteger() ; solve(A, B, K); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def resolve(): a,b,k=map(int,input().split()) realk=min(b-a+1,k) ans=list(range(a,a+realk)) ans+=list(range(b-realk+1,b+1)) answer=sorted(list(set(ans))) for i in answer : print(i) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; resolve(); operation resolve() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var k : OclAny := null; Sequence{a,b,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var realk : OclAny := Set{b - a + 1, k}->min() ; var ans : Sequence := (Integer.subrange(a, a + realk-1)) ; ans := ans + (Integer.subrange(b - realk + 1, b + 1-1)) ; var answer : Sequence := (Set{}->union((ans)))->sort() ; for i : answer do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lst,row,col=[],[],[] ans=0 for _ in range(n): z=list(map(int,input().split())) lst.append(z) row.append(sum(z)) for i in range(n): z=[] for j in range(n): z.append(lst[j][i]) col.append(sum(z)) for i in range(n): for j in range(n): if col[i]>row[j]: ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : OclAny := null; var row : OclAny := null; var col : OclAny := null; Sequence{lst,row,col} := Sequence{Sequence{},Sequence{},Sequence{}} ; var ans : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var z : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((z) : lst) ; execute (((z)->sum()) : row)) ; for i : Integer.subrange(0, n-1) do ( z := Sequence{} ; for j : Integer.subrange(0, n-1) do ( execute ((lst[j+1][i+1]) : z)) ; execute (((z)->sum()) : col)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if (col[i+1]->compareTo(row[j+1])) > 0 then ( ans := ans + 1 ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in[*open(0)][1 :]: num,x=map(int,i.split()); print(x*(x-1+num*num+num)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var num : OclAny := null; var x : OclAny := null; Sequence{num,x} := (i.split())->collect( _x | (OclType["int"])->apply(_x) ); execute (x * (x - 1 + num * num + num) div 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,A=int(input()),[] for i in range(n): A.append([int(x)for x in input().split()]) print(sum(1 for i in range(n)for j in range(n)if sum(A[i])toInteger(),Sequence{}} ; for i : Integer.subrange(0, n-1) do ( execute ((input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) : A)) ; execute (((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))) < (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom (name A)))))))) ))))))))) ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) ))))))))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline def ii(): return int(input()) def li(): return list(map(int,input().split())) from math import sqrt def perfect_sq(n): x=int(sqrt(n)) while x*xn : x-=1 return(x*x==n) n=ii() l=[] for i in range(n): a=li() l.append(a) rsum=[0 for i in range(n)] csum=[0 for i in range(n)] for i in range(n): for j in range(n): rsum[i]+=l[i][j] csum[j]+=l[i][j] ans=0 for i in range(n): for j in range(n): if csum[j]>rsum[i]: ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; skip ; skip ; skip ; skip ; n := ii() ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := li() ; execute ((a) : l)) ; var rsum : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var csum : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( rsum[i+1] := rsum[i+1] + l[i+1][j+1] ; csum[j+1] := csum[j+1] + l[i+1][j+1])) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if (csum[j+1]->compareTo(rsum[i+1])) > 0 then ( ans := ans + 1 ) else skip)) ; execute (ans)->display(); operation ii() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation li() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation perfect_sq(n : OclAny) : OclAny pre: true post: true activity: var x : int := ("" + ((sqrt(n))))->toInteger() ; while (x * x->compareTo(n)) < 0 do ( x := x + 1) ; while (x * x->compareTo(n)) > 0 do ( x := x - 1) ; return (x * x = n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[] for _ in range(n): l=list(map(int,input().split())) a.append(l) sr=[] sc=[] c=0 for i in range(n): sr.append(sum(a[i])) for i in range(n): s=0 for j in range(n): s+=a[j][i] sc.append(s) for x in sc : for y in sr : if x>y : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((l) : a)) ; var sr : Sequence := Sequence{} ; var sc : Sequence := Sequence{} ; var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( execute (((a[i+1])->sum()) : sr)) ; for i : Integer.subrange(0, n-1) do ( var s : int := 0 ; for j : Integer.subrange(0, n-1) do ( s := s + a[j+1][i+1]) ; execute ((s) : sc)) ; for x : sc do ( for y : sr do ( if (x->compareTo(y)) > 0 then ( c := c + 1 ) else skip)) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[[int(j)for j in input().split()]for i in range(n)] r=[sum(a[k][j]for j in range(n))for k in range(n)] c=[sum(a[i][k]for i in range(n))for k in range(n)] res=sum(1 for j in range(n)for i in range(n)if c[j]>r[i]) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger())))) ; var r : Sequence := Integer.subrange(0, n-1)->select(k | true)->collect(k | (((argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->sum())) ; var c : Sequence := Integer.subrange(0, n-1)->select(k | true)->collect(k | (((argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->sum())) ; var res : OclAny := ((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) > (comparison (expr (atom (name r)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))))))))->sum() ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def toNegativeBase(n,negBase): if(n==0): return "0" converted="01" while(n!=0): remainder=n %(negBase) n=int(n/negBase) if(remainder<0): remainder+=((-1)*negBase) n+=1 converted=str(remainder)+converted return converted if __name__=='__main__' : n=13 negBase=-2 print(toNegativeBase(n,negBase)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 13 ; negBase := -2 ; execute (toNegativeBase(n, negBase))->display() ) else skip; operation toNegativeBase(n : OclAny, negBase : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return "0" ) else skip ; var converted : String := "01" ; while (n /= 0) do ( var remainder : int := n mod (negBase) ; n := ("" + ((n / negBase)))->toInteger() ; if (remainder < 0) then ( remainder := remainder + ((-1) * negBase) ; n := n + 1 ) else skip ; converted := ("" + ((remainder))) + converted) ; return converted; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=sorted([int(j)for j in input().split()]) cost=0 for j in range(len(a)-1): cost+=abs(a[j]-a[j+1]) print(cost) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger()))->sort() ; var cost : int := 0 ; for j : Integer.subrange(0, (a)->size() - 1-1) do ( cost := cost + (a[j+1] - a[j + 1+1])->abs()) ; execute (cost)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binary_search(key): bad,good=-1,len(ans) while good-bad>1 : mid=(bad+good)//2 if ans[mid][-1]toInteger() ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, N-1) do ( var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var idx : OclAny := binary_search(A) ; if idx = (ans)->size() then ( execute ((Sequence{ A }) : ans) ) else ( (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name idx)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)))))))) )))) )) ; execute ((ans)->size())->display(); operation binary_search(key : OclAny) : OclAny pre: true post: true activity: var bad : OclAny := null; var good : OclAny := null; Sequence{bad,good} := Sequence{-1,(ans)->size()} ; while good - bad > 1 do ( var mid : int := (bad + good) div 2 ; if (ans[mid+1]->last()->compareTo(key)) < 0 then ( var good : int := mid ) else ( var bad : int := mid )) ; return good; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): tasks=list(map(int,input().split(" "))) tasks.sort() print(abs(tasks[0]-tasks[1])+abs(tasks[1]-tasks[2])) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var tasks : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; tasks := tasks->sort() ; execute ((tasks->first() - tasks[1+1])->abs() + (tasks[1+1] - tasks[2+1])->abs())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) ab=abs(a-b) bc=abs(b-c) ca=abs(c-a) print(min([ab+bc,bc+ca,ca+ab])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ab : double := (a - b)->abs() ; var bc : double := (b - c)->abs() ; var ca : double := (c - a)->abs() ; execute ((Sequence{ab + bc}->union(Sequence{bc + ca}->union(Sequence{ ca + ab })))->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import combinations def resolve(): seq=list(map(int,input().split())) ans=0 cos=[] comb=combinations(seq,2) for el in comb : cos.append(abs(el[0]-el[1])) print(sum(cos)-max(cos)) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; resolve(); operation resolve() pre: true post: true activity: var seq : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; var cos : Sequence := Sequence{} ; var comb : OclAny := combinations(seq, 2) ; for el : comb do ( execute (((el->first() - el[1+1])->abs()) : cos)) ; execute ((cos)->sum() - (cos)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools a=input().split() dict={} for i in range(len(a)): dict[i]=int(a[i]) ans=1000 b=list(itertools.permutations([0,1,2])) for i in range(len(b)): x=abs(dict[b[i][2]]-dict[b[i][1]])+abs(dict[b[i][1]]-dict[b[i][0]]) if xsize()-1) do ( (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]) := ("" + ((a[i+1])))->toInteger()) ; var ans : int := 1000 ; var b : Sequence := (itertools.permutations(Sequence{0}->union(Sequence{1}->union(Sequence{ 2 })))) ; for i : Integer.subrange(0, (b)->size()-1) do ( var x : double := ((arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))) ]) - (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ]))->abs() + ((arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ]) - (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ]))->abs() ; if (x->compareTo(ans)) < 0 then ( ans := x ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t=int(input()) ans=[] for _ in range(t): n,m=map(int,input().split()) ans0=m*(m+1)//2+m*n*(n+1)//2-m ans.append(ans0) sys.stdout.write("\n".join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans0 : double := m * (m + 1) div 2 + m * n * (n + 1) div 2 - m ; execute ((ans0) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def RSF(n): while(n>=10): x=n ; l=0 ; while(n>0): n=n//10 ; l+=1 ; a=[0]*l ; i=l-1 ; while(x>0): a[i]=x % 10 ; x=x//10 ; i-=1 ; for j in range(0,l-1): n=n*10+abs(a[j]-a[j+1]); return n ; if __name__=='__main__' : n=614 ; ans=RSF(n); print(ans); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 614; ; var ans : OclAny := RSF(n); ; execute (ans)->display(); ) else skip; operation RSF(n : OclAny) pre: true post: true activity: while (n >= 10) do ( var x : OclAny := n; ; var l : int := 0; ; while (n > 0) do ( n := n div 10; ; l := l + 1;) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, l); ; var i : double := l - 1; ; while (x > 0) do ( a[i+1] := x mod 10; ; x := x div 10; ; i := i - 1;) ; for j : Integer.subrange(0, l - 1-1) do ( n := n * 10 + (a[j+1] - a[j + 1+1])->abs();)) ; return n;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys class Node : def __init__(self,data): self.data=data self.next=None def push(head,data): if not head : return Node(data) newNode=Node(data) newNode.next=head head=newNode return head def circular(head): start=head while(head.next is not None): head=head.next head.next=start return start def displayList(node): start=node while(node.next is not start): print("{}".format(node.data),end="") node=node.next print("{}".format(node.data),end="") if __name__=='__main__' : head=None head=push(head,15) head=push(head,14) head=push(head,13) head=push(head,22) head=push(head,17) circular(head) print("Display List:") displayList(head) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.next := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( head := null ; head := push(head, 15) ; head := push(head, 14) ; head := push(head, 13) ; head := push(head, 22) ; head := push(head, 17) ; circular(head) ; execute ("Display List:")->display() ; displayList(head) ) else skip; operation push(head : OclAny, data : OclAny) : OclAny pre: true post: true activity: if not(head) then ( return (Node.newNode()).initialise(data) ) else skip ; var newNode : Node := (Node.newNode()).initialise(data) ; newNode.next := head ; head := newNode ; return head; operation circular(head : OclAny) : OclAny pre: true post: true activity: var start : OclAny := head ; while (not(head.next <>= null)) do ( head := head.next) ; head.next := start ; return start; operation displayList(node : OclAny) pre: true post: true activity: start := node ; while (not(node.next <>= start)) do ( execute (StringLib.interpolateStrings("{}", Sequence{node.data}))->display() ; node := node.next) ; execute (StringLib.interpolateStrings("{}", Sequence{node.data}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def licenseKeyFormatting(self,S,K): S=S.upper().replace('-','') ls=len(S) if ls % K==0 : pos=K else : pos=ls % K res=S[: pos] while posexists( _x | result = _x ); operation licenseKeyFormatting(S : OclAny,K : OclAny) : OclAny pre: true post: true activity: S := S->toUpperCase().replace('-', '') ; var ls : int := (S)->size() ; if ls mod K = 0 then ( var pos : OclAny := K ) else ( pos := ls mod K ) ; var res : OclAny := S.subrange(1,pos) ; while (pos->compareTo(ls)) < 0 do ( res := res + '-' + S.subrange(pos+1, pos + K) ; pos := pos + K) ; return res; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math EPS=1E-15 ; def findMinValue(arr,n): sum=0 ; for i in range(n): sum+=math.log10(arr[i])+EPS ; xl=(sum/n+EPS); res=math.pow(10.0,xl)+EPS ; return math.ceil(res+EPS); arr=[4,2,1,10,6]; n=len(arr); print(findMinValue(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var EPS : double := ("1E-15")->toReal(); ; skip ; arr := Sequence{4}->union(Sequence{2}->union(Sequence{1}->union(Sequence{10}->union(Sequence{ 6 })))); ; n := (arr)->size(); ; execute (findMinValue(arr, n))->display();; operation findMinValue(arr : OclAny, n : OclAny) pre: true post: true activity: var sum : int := 0; ; for i : Integer.subrange(0, n-1) do ( sum := sum + (arr[i+1])->log10() + EPS;) ; var xl : double := (sum / n + EPS); ; var res : double := (10.0)->pow(xl) + EPS; ; return (res + EPS)->ceil();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def digitalRoot(num): if(num=="0"): return 0 ans=0 for i in range(0,len(num)): ans=(ans+int(num[i]))% 9 if(ans==0): return 9 else : return ans % 9 num="65785412" print(digitalRoot(num)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; num := "65785412" ; execute (digitalRoot(num))->display(); operation digitalRoot(num : OclAny) : OclAny pre: true post: true activity: if (num = "0") then ( return 0 ) else skip ; var ans : int := 0 ; for i : Integer.subrange(0, (num)->size()-1) do ( ans := (ans + ("" + ((num[i+1])))->toInteger()) mod 9) ; if (ans = 0) then ( return 9 ) else ( return ans mod 9 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import sys def input(): return sys.stdin.readline().rstrip() def iIn(): return int(input()) def iInM(): return map(int,input().split()) def iInM1(): return map(int1,input().split()) def iInLH(): return list(map(int,input().split())) def iInLH1(): return list(map(int1,input().split())) def iInLV(n): return[iIn()for _ in range(n)] def iInLV1(n): return[iIn()-1 for _ in range(n)] def iInLD(n): return[iInLH()for _ in range(n)] def iInLD1(n): return[iInLH1()for _ in range(n)] def sInLH(): return list(input().split()) def sInLV(n): return[input().rstrip('\n')for _ in range(n)] def sInLD(n): return[sInLH()for _ in range(n)] def OutH(lst,deli=' '): print(deli.join(map(str,lst))) def OutV(lst): print('\n'.join(map(str,lst))) sys.setrecursionlimit(10**6) int1=lambda x : int(x)-1 INF=int(1e9) MOD=1000000007 dx=(-1,0,1,0) dy=(0,-1,0,1) N=iIn() A=iInLV(N) lst=[A[0]] for i in range(1,N): idx=bisect.bisect_left(lst,A[i]) if idx==0 : lst.insert(0,A[i]) else : lst[idx-1]=A[i] print(len(lst)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(6)) ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; var INF : int := ("" + ((("1e9")->toReal())))->toInteger() ; var MOD : int := 1000000007 ; var dx : OclAny := Sequence{-1, 0, 1, 0} ; var dy : OclAny := Sequence{0, -1, 0, 1} ; var N : OclAny := iIn() ; var A : OclAny := iInLV(N) ; lst := Sequence{ A->first() } ; for i : Integer.subrange(1, N-1) do ( var idx : OclAny := bisect.bisect_left(lst, A[i+1]) ; if idx = 0 then ( lst := lst.insertAt(0+1, A[i+1]) ) else ( lst[idx - 1+1] := A[i+1] )) ; execute ((lst)->size())->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation iIn() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation iInM() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation iInM1() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (int1)->apply(_x) ); operation iInLH() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation iInLH1() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (int1)->apply(_x) )); operation iInLV(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (iIn())); operation iInLV1(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (iIn() - 1)); operation iInLD(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (iInLH())); operation iInLD1(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (iInLH1())); operation sInLH() : OclAny pre: true post: true activity: return (input().split()); operation sInLV(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (input().rstrip(' '))); operation sInLD(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (sInLH())); operation OutH(lst : OclAny, deli : String) pre: true post: true activity: if deli->oclIsUndefined() then deli := ' ' else skip; execute (StringLib.sumStringsWithSeparator(((lst)->collect( _x | (OclType["String"])->apply(_x) )), deli))->display(); operation OutV(lst : OclAny) pre: true post: true activity: execute (StringLib.sumStringsWithSeparator(((lst)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n1,n2=map(int,(input().split())) sequence=[] found=False def change(num,seq,n2): if num==n2 : global found,sequence found=True sequence=seq.copy() return if num>n2 : return change(num*2,seq+[num*2],n2) change((num*10)+1,seq+[(num*10)+1],n2) change(n1,[n1],n2) if found : print("YES") print(len(sequence)) for n in sequence : print(n,end=" ") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { attribute found : OclAny; attribute sequence : OclAny; operation initialise() pre: true post: true activity: var n1 : OclAny := null; var n2 : OclAny := null; Sequence{n1,n2} := ((input().split()))->collect( _x | (OclType["int"])->apply(_x) ) ; var sequence : Sequence := Sequence{} ; var found : boolean := false ; skip ; change(n1, Sequence{ n1 }, n2) ; if found then ( execute ("YES")->display() ; execute ((sequence)->size())->display() ; for n : sequence do ( execute (n)->display()) ) else ( execute ("NO")->display() ); operation change(num : OclAny, seq : OclAny, n2 : OclAny) pre: true post: true activity: if num = n2 then ( skip; skip ; found := true ; sequence := seq->copy() ; return ) else skip ; if (num->compareTo(n2)) > 0 then ( return ) else skip ; change(num * 2, seq->union(Sequence{ num * 2 }), n2) ; change((num * 10) + 1, seq->union(Sequence{ (num * 10) + 1 }), n2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def transform(start_num,count,arr): global b,found if found : return if start_num>b : return if start_num==b : found=True print('YES') print(count+1) print(*arr) return n_arr_1=arr.copy() n_arr_1.append(2*start_num) transform(2*start_num,count+1,n_arr_1) n_arr_2=arr.copy() n_arr_2.append(10*start_num+1) transform(10*start_num+1,count+1,n_arr_2) return if __name__=='__main__' : a,b=map(int,input().split()) found=False arr=[a] transform(a,0,arr) if not found : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { attribute b : OclAny; attribute found : OclAny; operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var a : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; found := false ; arr := Sequence{ a } ; transform(a, 0, arr) ; if not(found) then ( execute ('NO')->display() ) else skip ) else skip; operation transform(start_num : OclAny, count : OclAny, arr : OclAny) pre: true post: true activity: skip; skip ; if found then ( return ) else skip ; if (start_num->compareTo(b)) > 0 then ( return ) else skip ; if start_num = b then ( found := true ; execute ('YES')->display() ; execute (count + 1)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name arr))))))))->display() ; return ) else skip ; var n_arr skip; skip : OclAny := arr->copy() ; execute ((2 * start_num) : n_arrn_arrn_arrn_arrn_arrn_arrn_arr skip; skip.append(2 * start_num).append(2 * start_num).append(2 * start_num).append(2 * start_num).append(2 * start_num).append(2 * start_num)) ; transform(2 * start_num, count + 1, n_arrcount + 1) ; var n_arr:= arr->copy() : OclAny := arr->copy() ; execute ((10 * start_num + 1) : n_arr.append(10 * start_num + 1)) ; transform(10 * start_num + 1, count + 1, n_arr_2) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=list(map(int,input().split())) y='' l=[b] while b!=a : if a>b : y='NO' break if b % 2==0 : b=int(b/2) if b==a : l.append(b) break else : l.append(b) elif str(b)[-1]=='1' : b=str(b)[:-1] b=int(b) l.append(b) else : y='NO' break if y=='NO' : print(y) else : print("YES") print(len(l)) print(*l[: :-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var y : String := '' ; var l : Sequence := Sequence{ b } ; while b /= a do ( if (a->compareTo(b)) > 0 then ( y := 'NO' ; break ) else skip ; if b mod 2 = 0 then ( var b : int := ("" + ((b / 2)))->toInteger() ; if b = a then ( execute ((b) : l) ; break ) else ( execute ((b) : l) ) ) else (if OclType["String"](b)->last() = '1' then ( b := OclType["String"](b)->front() ; b := ("" + ((b)))->toInteger() ; execute ((b) : l) ) else ( y := 'NO' ; break ) ) ) ; if y = 'NO' then ( execute (y)->display() ) else ( execute ("YES")->display() ; execute ((l)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ]))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) def create(a,b): if a>b : return[[],0] if a==b : return[[],1] c=create(a*2,b) d=create(10*a+1,b) if c[1]: return[[a]+c[0],1] if d[1]: return[[a]+d[0],1] return[[],0] arr=create(a,b) if arr==[[],0]: print('NO') else : print('YES') m=arr[0] print(len(m)+1) for i in m : print(i,end=' ') print(b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; var arr : OclAny := create(a, b) ; if arr = Sequence{Sequence{}}->union(Sequence{ 0 }) then ( execute ('NO')->display() ) else ( execute ('YES')->display() ; var m : OclAny := arr->first() ; execute ((m)->size() + 1)->display() ; for i : m do ( execute (i)->display()) ; execute (b)->display() ); operation create(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a->compareTo(b)) > 0 then ( return Sequence{Sequence{}}->union(Sequence{ 0 }) ) else skip ; if a = b then ( return Sequence{Sequence{}}->union(Sequence{ 1 }) ) else skip ; var c : OclAny := create(a * 2, b) ; var d : OclAny := create(10 * a + 1, b) ; if c[1+1] then ( return Sequence{Sequence{ a }->union(c->first())}->union(Sequence{ 1 }) ) else skip ; if d[1+1] then ( return Sequence{Sequence{ a }->union(d->first())}->union(Sequence{ 1 }) ) else skip ; return Sequence{Sequence{}}->union(Sequence{ 0 }); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy ab=input() ab=list(map(int,ab.split())) a,b=ab[0],ab[1] vector=[a] answer=[] def a_to_b(a,b,vector,answer): if a>b : return False elif a==b : answer=copy.deepcopy(vector) print('YES') print(len(answer)) for i in answer : print(i,end=' ') return True vector.append(2*a) p1=a_to_b(2*a,b,vector,answer) vector.remove(vector[-1]) vector.append(10*a+1) p2=a_to_b(10*a+1,b,vector,answer) vector.remove(vector[-1]) return p1 or p2 p=a_to_b(a,b,vector,answer) if p==False : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var ab : String := (OclFile["System.in"]).readLine() ; ab := ((ab.split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{ab->first(),ab[1+1]} ; var vector : Sequence := Sequence{ a } ; var answer : Sequence := Sequence{} ; skip ; var p : OclAny := a_to_b(a, b, vector, answer) ; if p = false then ( execute ('NO')->display() ) else skip; operation a_to_b(a : OclAny, b : OclAny, vector : OclAny, answer : OclAny) : OclAny pre: true post: true activity: if (a->compareTo(b)) > 0 then ( return false ) else (if a = b then ( answer := copy.deepcopy(vector) ; execute ('YES')->display() ; execute ((answer)->size())->display() ; for i : answer do ( execute (i)->display()) ; return true ) else skip) ; execute ((2 * a) : vector) ; var p1 : OclAny := a_to_b(2 * a, b, vector, answer) ; execute ((vector->last()) /: vector) ; execute ((10 * a + 1) : vector) ; var p2 : OclAny := a_to_b(10 * a + 1, b, vector, answer) ; execute ((vector->last()) /: vector) ; return p1 or p2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n,m=map(int,input().split()) print((m*(m-1+n*(n+1)))//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((m * (m - 1 + n * (n + 1))) div 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def k_sum(a,n,k): r,sum=0,0 ; ans=0 ; for l in range(n): while(sumunion(Sequence{1}->union(Sequence{2}->union(Sequence{ 7 }))); k := 10; ; n := (a)->size(); ; execute (k_sum(a, n, k))->display();; operation k_sum(a : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var r : OclAny := null; var sum : OclAny := null; Sequence{r,sum} := Sequence{0,0}; ; var ans : int := 0; ; for l : Integer.subrange(0, n-1) do ( while ((sum->compareTo(k)) < 0) do ( if (r = n) then ( break; ) else ( sum := sum + a[r+1]; ; r := r + 1; )) ; if ((sum->compareTo(k)) < 0) then ( break; ) else skip ; ans := ans + n - r + 1; ; sum := sum - a[l+1];) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getChar(strr): summ=0 for i in range(len(strr)): summ+=(ord(strr[i])-ord('a')+1) if(summ % 26==0): return ord('z') else : summ=summ % 26 return chr(ord('a')+summ-1) strr="gfg" print(getChar(strr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; strr := "gfg" ; execute (getChar(strr))->display(); operation getChar(strr : OclAny) : OclAny pre: true post: true activity: var summ : int := 0 ; for i : Integer.subrange(0, (strr)->size()-1) do ( summ := summ + ((strr[i+1])->char2byte() - ('a')->char2byte() + 1)) ; if (summ mod 26 = 0) then ( return ('z')->char2byte() ) else ( summ := summ mod 26 ; return (('a')->char2byte() + summ - 1)->byte2char() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumNth(A,B,m,n): res=0 ; if(n==1): for i in range(m): res=res+A[i]; elif(n==2): for i in range(m): res=res+B[i]*m ; else : f=[0]*n ; f[0]=0 ; f[1]=1 ; for i in range(2,n): f[i]=f[i-1]+f[i-2]; for i in range(m): res=(res+(m*(B[i]*f[n-1]))+(m*(A[i]*f[n-2]))); return res ; A=[1,2,3]; B=[4,5,6]; n=3 ; m=len(A); print(sumNth(A,B,m,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; A := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })); ; B := Sequence{4}->union(Sequence{5}->union(Sequence{ 6 })); ; n := 3; ; m := (A)->size(); ; execute (sumNth(A, B, m, n))->display();; operation sumNth(A : OclAny, B : OclAny, m : OclAny, n : OclAny) pre: true post: true activity: var res : int := 0; ; if (n = 1) then ( for i : Integer.subrange(0, m-1) do ( res := res + A[i+1];) ) else (if (n = 2) then ( for i : Integer.subrange(0, m-1) do ( res := res + B[i+1] * m;) ) else ( var f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; f->first() := 0; ; f[1+1] := 1; ; for i : Integer.subrange(2, n-1) do ( f[i+1] := f[i - 1+1] + f[i - 2+1];) ; for i : Integer.subrange(0, m-1) do ( res := (res + (m * (B[i+1] * f[n - 1+1])) + (m * (A[i+1] * f[n - 2+1])));) ) ) ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def odd_even(n): odd_indexes=[] even_indexes=[] for i in range(len(n)): if i % 2==0 : odd_indexes.append(n[i]) else : even_indexes.append(n[i]) for i in sorted(odd_indexes): print(i,end=" ") for i in sorted(even_indexes): print(i,end=" ") n=[3,2,7,6,8] odd_even(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := Sequence{3}->union(Sequence{2}->union(Sequence{7}->union(Sequence{6}->union(Sequence{ 8 })))) ; odd_even(n); operation odd_even(n : OclAny) pre: true post: true activity: var odd_indexes : Sequence := Sequence{} ; var even_indexes : Sequence := Sequence{} ; for i : Integer.subrange(0, (n)->size()-1) do ( if i mod 2 = 0 then ( execute ((n[i+1]) : odd_indexes) ) else ( execute ((n[i+1]) : even_indexes) )) ; for i : odd_indexes->sort() do ( execute (i)->display()) ; for i : even_indexes->sort() do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lis(A : "Array[int]")->int : from bisect import bisect_right dp=[A[0]] for i in A[1 :]: if i>=dp[-1]: dp.append(i) else : dp[bisect_right(dp,i)]=i return len(dp) def main(): N,*A=map(int,open(0)) ans=lis(A[: :-1]) print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation lis(A : "Array[int]") : int pre: true post: true activity: skip ; var dp : Sequence := Sequence{ A->first() } ; for i : A->tail() do ( if (i->compareTo(dp->last())) >= 0 then ( execute ((i) : dp) ) else ( dp[bisect_right(dp, i)+1] := i )) ; return (dp)->size(); operation main() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; Sequence{N,A} := (OclFile.newOclFile_Write(OclFile.newOclFile(0)))->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : OclAny := lis(A(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printFirstNegativeInteger(arr,n,k): for i in range(0,(n-k+1)): flag=False for j in range(0,k): if(arr[i+j]<0): print(arr[i+j],end=" ") flag=True break if(not(flag)): print("0",end=" ") arr=[12,-1,-7,8,-15,30,16,28] n=len(arr) k=3 printFirstNegativeInteger(arr,n,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{12}->union(Sequence{-1}->union(Sequence{-7}->union(Sequence{8}->union(Sequence{-15}->union(Sequence{30}->union(Sequence{16}->union(Sequence{ 28 }))))))) ; n := (arr)->size() ; k := 3 ; printFirstNegativeInteger(arr, n, k); operation printFirstNegativeInteger(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: for i : Integer.subrange(0, (n - k + 1)-1) do ( var flag : boolean := false ; for j : Integer.subrange(0, k-1) do ( if (arr[i + j+1] < 0) then ( execute (arr[i + j+1])->display() ; flag := true ; break ) else skip) ; if (not((flag))) then ( execute ("0")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fillPrefixSum(arr,n,prefixSum): prefixSum[0]=arr[0] for i in range(1,n): prefixSum[i]=prefixSum[i-1]+arr[i] arr=[10,4,16,20] n=len(arr) prefixSum=[0 for i in range(n+1)] fillPrefixSum(arr,n,prefixSum) for i in range(n): print(prefixSum[i],"",end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{10}->union(Sequence{4}->union(Sequence{16}->union(Sequence{ 20 }))) ; n := (arr)->size() ; prefixSum := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; fillPrefixSum(arr, n, prefixSum) ; for i : Integer.subrange(0, n-1) do ( execute (prefixSum[i+1])->display()); operation fillPrefixSum(arr : OclAny, n : OclAny, prefixSum : OclAny) pre: true post: true activity: prefixSum->first() := arr->first() ; for i : Integer.subrange(1, n-1) do ( prefixSum[i+1] := prefixSum[i - 1+1] + arr[i+1]); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,atan2,cos,sin while(1): try : x1,y1,x2,y2,xq,yq=[float(i)for i in input().split(",")] r=sqrt((xq-x1)**2+(yq-y1)**2) th1=atan2(y2-y1,x2-x1) th2=atan2(yq-y1,xq-x1) th3=-(th2-th1)+th1 print("{:.6f}{:.6f}".format(x1+r*cos(th3),y1+r*sin(th3))) except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while (1) do ( try ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; var xq : OclAny := null; var yq : OclAny := null; Sequence{x1,y1,x2,y2,xq,yq} := input().split(",")->select(i | true)->collect(i | (("" + ((i)))->toReal())) ; var r : OclAny := sqrt(((xq - x1))->pow(2) + ((yq - y1))->pow(2)) ; var th1 : OclAny := atan2(y2 - y1, x2 - x1) ; var th2 : OclAny := atan2(yq - y1, xq - x1) ; var th3 : double := -(th2 - th1) + th1 ; execute (StringLib.interpolateStrings("{:.6f}{:.6f}", Sequence{x1 + r * cos(th3), y1 + r * sin(th3)}))->display()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dot(a,b): return a.real*b.real+a.imag*b.imag def norm(a): return a.real**2+a.imag**2 def project(line,p): base=line[1]-line[0] r=dot(p-line[0],base)/norm(base) return line[0]+base*r def symmetric_Point(line,p): return p+2*(project(line,p)-p) while True : try : p=list(map(float,input().split(','))) except : break line=[] line.append(complex(p[0],p[1])) line.append(complex(p[2],p[3])) pp=complex(p[4],p[5]) qq=symmetric_Point(line,pp) print(qq.real,qq.imag) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; while true do ( try ( p := ((input().split(','))->collect( _x | (OclType["double"])->apply(_x) ))) catch (_e : OclException) do ( break) ; line := Sequence{} ; execute ((complex(p->first(), p[1+1])) : line) ; execute ((complex(p[2+1], p[3+1])) : line) ; var pp : OclAny := complex(p[4+1], p[5+1]) ; var qq : OclAny := symmetric_Point(line, pp) ; execute (qq.real)->display()); operation dot(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a.real * b.real + a.imag * b.imag; operation norm(a : OclAny) : OclAny pre: true post: true activity: return (a.real)->pow(2) + (a.imag)->pow(2); operation project(line : OclAny, p : OclAny) : OclAny pre: true post: true activity: var base : double := line[1+1] - line->first() ; var r : double := dot(p - line->first(), base) / norm(base) ; return line->first() + base * r; operation symmetric_Point(line : OclAny, p : OclAny) : OclAny pre: true post: true activity: return p + 2 * (project(line, p) - p); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import os import math class Vector2(): def __init__(self,x,y): self._x=float(x) self._y=float(y) def normalize(self): norm=self.norm() return Vector2(self._x/norm,self._y/norm) def norm(self): return math.sqrt(self._x**2+self._y**2) def dot(self,other): return self._x*other._x+self._y*other._y def __add__(self,other): return Vector2(self._x+other._x,self._y+other._y) def __sub__(self,other): return Vector2(self._x-other._x,self._y-other._y) def __str__(self): round_x=round(self._x,6) round_y=round(self._y,6) return "{}{}".format(round_x,round_y) def __mul__(self,scale): return Vector2(self._x*scale,self._y*scale) for s in sys.stdin : x1,y1,x2,y2,xq,yq=map(float,s.split(',')) OP1=Vector2(x1,y1) OP2=Vector2(x2,y2) OQ=Vector2(xq,yq) P2P1=OP2-OP1 N=P2P1.normalize() P1Q=OQ-OP1 dot=P1Q.dot(N) P1O=N*dot QO=P1O-P1Q OR=OP1+P1O+QO print(OR) ------------------------------------------------------------ OCL File: --------- class Vector2 { static operation newVector2() : Vector2 pre: true post: Vector2->exists( _x | result = _x ); attribute _x : double := ("" + ((x)))->toReal(); attribute _y : double := ("" + ((y)))->toReal(); operation initialise(x : OclAny,y : OclAny) : pre: true post: true activity: self._x := ("" + ((x)))->toReal() ; self._y := ("" + ((y)))->toReal(); return self; operation normalize() : OclAny pre: true post: true activity: var norm : OclAny := self.norm() ; return Vector2(self._x / norm, self._y / norm); operation norm() : OclAny pre: true post: true activity: return ((self._x)->pow(2) + (self._y)->pow(2))->sqrt(); operation dot(other : OclAny) : OclAny pre: true post: true activity: return self._x * other._x + self._y * other._y; operation __add__(other : OclAny) : OclAny pre: true post: true activity: return Vector2(self._x + other._x, self._y + other._y); operation __sub__(other : OclAny) : OclAny pre: true post: true activity: return Vector2(self._x - other._x, self._y - other._y); operation __str__() : OclAny pre: true post: true activity: var round_x : double := MathLib.roundN(self._x, 6) ; var round_y : double := MathLib.roundN(self._y, 6) ; return StringLib.interpolateStrings("{}{}", Sequence{round_x, round_y}); operation __mul__(scale : OclAny) : OclAny pre: true post: true activity: return Vector2(self._x * scale, self._y * scale); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; for s : OclFile["System.in"] do ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; var xq : OclAny := null; var yq : OclAny := null; Sequence{x1,y1,x2,y2,xq,yq} := (s.split(','))->collect( _x | (OclType["double"])->apply(_x) ) ; var OP1 : Vector2 := (Vector2.newVector2()).initialise(x1, y1) ; var OP2 : Vector2 := (Vector2.newVector2()).initialise(x2, y2) ; var OQ : Vector2 := (Vector2.newVector2()).initialise(xq, yq) ; var P2P1 : double := OP2 - OP1 ; var N : OclAny := P2P1.normalize() ; var P1Q : double := OQ - OP1 ; var dot : OclAny := P1Q.dot(N) ; var P1O : double := N * dot ; var QO : double := P1O - P1Q ; var OR : OclAny := OP1 + P1O + QO ; execute (OR)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") def symmetric_point(x1,y1,x2,y2,xq,yq): rx=x2-x1 ry=y2-y1 det=-rx**2-ry**2 det_s=rx*(yq-y1)-ry*(xq-x1) s=det_s/det xr=xq-2*s*ry yr=yq+2*s*rx return xr,yr for line in sys.stdin : x1,y1,x2,y2,xq,yq=[float(_)for _ in line.split(',')] xr,yr=symmetric_point(x1,y1,x2,y2,xq,yq) print("%.6f %.6f" %(xr,yr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; skip ; for line : OclFile["System.in"] do ( Sequence{x1,y1,x2,y2,xq,yq} := line.split(',')->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toReal())) ; Sequence{xr,yr} := symmetric_point(x1, y1, x2, y2, xq, yq) ; execute (StringLib.format("%.6f %.6f",Sequence{xr, yr}))->display()); operation symmetric_point(x1 : OclAny, y1 : OclAny, x2 : OclAny, y2 : OclAny, xq : OclAny, yq : OclAny) : OclAny pre: true post: true activity: var rx : double := x2 - x1 ; var ry : double := y2 - y1 ; var det : double := -(rx)->pow(2) - (ry)->pow(2) ; var det_s : double := rx * (yq - y1) - ry * (xq - x1) ; var s : double := det_s / det ; var xr : double := xq - 2 * s * ry ; var yr : OclAny := yq + 2 * s * rx ; return xr, yr; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect as upper_bound from bisect import bisect_left as lower_bound from math import floor N=1000005 MAX=10**18 powers=[] squares=dict() s=dict() def powersPrecomputation(): for i in range(2,N): squares[i*i]=1 if(i not in squares.keys()): continue temp=i while(i*i<=(MAX//temp)): temp*=(i*i) s[temp]=1 for x in s : powers.append(x) def calculateAnswer(L,R): powersPrecomputation() perfectSquares=floor((R)**(.5))-floor((L-1)**(.5)) high=upper_bound(powers,R) low=lower_bound(powers,L) perfectPowers=perfectSquares+(high-low) ans=(R-L+1)-perfectPowers return ans L=13 R=20 print(calculateAnswer(L,R)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var N : int := 1000005 ; var MAX : double := (10)->pow(18) ; var powers : Sequence := Sequence{} ; var squares : Map := (arguments ( )) ; var s : Map := (arguments ( )) ; skip ; skip ; L := 13 ; R := 20 ; execute (calculateAnswer(L, R))->display(); operation powersPrecomputation() pre: true post: true activity: for i : Integer.subrange(2, N-1) do ( squares[i * i+1] := 1 ; if ((squares.keys())->excludes(i)) then ( continue ) else skip ; var temp : OclAny := i ; while ((i * i->compareTo((MAX div temp))) <= 0) do ( temp := temp * (i * i) ; s[temp+1] := 1)) ; for x : s->keys() do ( execute ((x) : powers)); operation calculateAnswer(L : OclAny, R : OclAny) : OclAny pre: true post: true activity: powersPrecomputation() ; var perfectSquares : double := floor(((R))->pow((.5))) - floor(((L - 1))->pow((.5))) ; var high : OclAny := upper_bound(powers, R) ; var low : OclAny := lower_bound(powers, L) ; var perfectPowers : OclAny := perfectSquares + (high - low) ; var ans : double := (R - L + 1) - perfectPowers ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import* for e in sys.stdin : a,b,c,d,e,f=map(float,e.split(',')) z,w,q=complex(a,b),complex(c,d),complex(e,f) z+=(z-w)*(q-z).conjugate()/(z-w).conjugate() print(z.real,z.imag) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for e : OclFile["System.in"] do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; var f : OclAny := null; Sequence{a,b,c,d,e,f} := (e.split(','))->collect( _x | (OclType["double"])->apply(_x) ) ; var z : OclAny := null; var w : OclAny := null; var q : OclAny := null; Sequence{z,w,q} := Sequence{complex(a, b),complex(c, d),complex(e, f)} ; z := z + (z - w) * (q - z).conjugate() / (z - w).conjugate() ; execute (z.real)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n,k=map(int,input().split()) bit=[int(j)for j in input().split()] low=n*(n-1)-2*k*n maxvalue=low for ni in range(2,n+1): a=max(int(low//ni)+1,1) if atoInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var bit : Sequence := input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; var low : double := n * (n - 1) - 2 * k * n ; var maxvalue : OclAny := low ; for ni : Integer.subrange(2, n + 1-1) do ( var a : OclAny := Set{("" + ((low div ni)))->toInteger() + 1, 1}->max() ; if (a->compareTo(ni)) < 0 then ( for nj : Integer.subrange(a, ni-1) do ( maxvalue := Set{maxvalue, ni * nj - k * (MathLib.bitwiseOr(bit[nj - 1+1], bit[ni - 1+1]))}->max()) ) else skip) ; execute (maxvalue)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : n,k=map(int,input().split()) a=list(map(int,input().split())) l=max(0,n-2*k-1) ans=-1e12 for i in range(l,n): for j in range(i+1,n): ans=max(ans,(i+1)*(j+1)-k*(a[i]| a[j])) print(ans) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : OclAny := Set{0, n - 2 * k - 1}->max() ; var ans : double := -("1e12")->toReal() ; for i : Integer.subrange(l, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( ans := Set{ans, (i + 1) * (j + 1) - k * (MathLib.bitwiseOr(a[i+1], a[j+1]))}->max())) ; execute (ans)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printKMissing(arr,n,k): arr.sort() i=0 while(iunion(Sequence{3}->union(Sequence{ 4 })) ; n := (arr)->size() ; k := 3 ; printKMissing(arr, n, k);; operation printKMissing(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: arr := arr->sort() ; var i : int := 0 ; while ((i->compareTo(n)) < 0 & arr[i+1] <= 0) do ( i := i + 1) ; var count : int := 0 ; var curr : int := 1 ; while ((count->compareTo(k)) < 0 & (i->compareTo(n)) < 0) do ( if (arr[i+1] /= curr) then ( execute (("" + ((curr))) + " ")->display() ; count := count + 1 ) else ( i := i + 1 ) ; curr := curr + 1) ; while ((count->compareTo(k)) < 0) do ( execute (("" + ((curr))) + " ")->display() ; curr := curr + 1 ; count := count + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) l=list(map(int,input().split())) maxi=-99999999999999 l1=max(0,n-2*k-1) for i in range(l1,n): for j in range(i+1,n): res=(i+1)*(j+1)-k*(l[i]| l[j]) maxi=max(res,maxi) print(maxi) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var maxi : int := -99999999999999 ; var l1 : OclAny := Set{0, n - 2 * k - 1}->max() ; for i : Integer.subrange(l1, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( var res : double := (i + 1) * (j + 1) - k * (MathLib.bitwiseOr(l[i+1], l[j+1])) ; maxi := Set{res, maxi}->max())) ; execute (maxi)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline MX=int(2e5+5) MOD=int(1e9+7) def main(): test=int(input()) for _ in range(test): n,k=map(int,input().split()) ara=[int(x)for x in input().split()] idx=max(0,n-2*k) ans=-n*n for i in range(idx,n): for j in range(i+1,n): temp=(i+1)*(j+1)-k*(ara[i]| ara[j]) ans=max(ans,temp) print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; var MX : int := ("" + ((("2e5")->toReal() + 5)))->toInteger() ; var MOD : int := ("" + ((("1e9")->toReal() + 7)))->toInteger() ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var test : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, test-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ara : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var idx : OclAny := Set{0, n - 2 * k}->max() ; var ans : double := -n * n ; for i : Integer.subrange(idx, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( var temp : double := (i + 1) * (j + 1) - k * (MathLib.bitwiseOr(ara[i+1], ara[j+1])) ; ans := Set{ans, temp}->max())) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys inpu=sys.stdin.readline prin=sys.stdout.write for _ in range(int(inpu())): n,k=map(int,inpu().split()) lis=list(map(int,inpu().split(' '))) ans=n*(n-1)-k*(lis[n-1]| lis[n-2]) for i in range(n,1,-1): a=lis[i-1] if i*(i-1)toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (inpu().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lis : Sequence := ((inpu().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : double := n * (n - 1) - k * (MathLib.bitwiseOr(lis[n - 1+1], lis[n - 2+1])) ; for i : Integer.subrange(1 + 1, n)->reverse() do ( var a : OclAny := lis[i - 1+1] ; if (i * (i - 1)->compareTo(ans)) < 0 then ( break ) else skip ; for j : Integer.subrange(0 + 1, i - 1)->reverse() do ( ans := Set{ans, i * j - k * (MathLib.bitwiseOr(a, lis[j - 1+1]))}->max())) ; prin(("" + ((ans))) + ' ')); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_CHAR=26 def commonCharacters(strings,n): prim=[True]*MAX_CHAR for i in range(n): sec=[False]*MAX_CHAR for j in range(len(strings[i])): if(prim[ord(strings[i][j])-ord('a')]): sec[ord(strings[i][j])-ord('a')]=True for i in range(MAX_CHAR): prim[i]=sec[i] for i in range(26): if(prim[i]): print("%c " %(i+ord('a')),end="") strings=["geeksforgeeks","gemkstones","acknowledges","aguelikes"] n=len(strings) commonCharacters(strings,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_CHAR : int := 26 ; skip ; strings := Sequence{"geeksforgeeks"}->union(Sequence{"gemkstones"}->union(Sequence{"acknowledges"}->union(Sequence{ "aguelikes" }))) ; n := (strings)->size() ; commonCharacters(strings, n); operation commonCharacters(strings : OclAny, n : OclAny) pre: true post: true activity: var prim : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, MAX_CHAR) ; for i : Integer.subrange(0, n-1) do ( var sec : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, MAX_CHAR) ; for j : Integer.subrange(0, (strings[i+1])->size()-1) do ( if (prim[(strings[i+1][j+1])->char2byte() - ('a')->char2byte()+1]) then ( sec[(strings[i+1][j+1])->char2byte() - ('a')->char2byte()+1] := true ) else skip) ; for i : Integer.subrange(0, MAX_CHAR-1) do ( prim[i+1] := sec[i+1])) ; for i : Integer.subrange(0, 26-1) do ( if (prim[i+1]) then ( execute (StringLib.format("%c ",(i + ('a')->char2byte())))->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def findDisappearedNumbers(self,nums): res=[] if nums : n=len(nums) for i in range(n): val=abs(nums[i])-1 if nums[val]>0 : nums[val]=-nums[val] for i in range(n): if nums[i]>0 : res.append(i+1) return res ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation findDisappearedNumbers(nums : OclAny) : OclAny pre: true post: true activity: var res : Sequence := Sequence{} ; if nums then ( var n : int := (nums)->size() ; for i : Integer.subrange(0, n-1) do ( var val : double := (nums[i+1])->abs() - 1 ; if nums[val+1] > 0 then ( nums[val+1] := -nums[val+1] ) else skip) ; for i : Integer.subrange(0, n-1) do ( if nums[i+1] > 0 then ( execute ((i + 1) : res) ) else skip) ) else skip ; return res; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def findMaxValue(): res=2 ; fact=2 ; while(True): if(fact<0 or fact>sys.maxsize): break ; res+=1 ; fact=fact*res ; return res-1 ; if __name__=='__main__' : print("Maximum value of integer:",findMaxValue()); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( execute ("Maximum value of integer:")->display(); ) else skip; operation findMaxValue() pre: true post: true activity: var res : int := 2; ; var fact : int := 2; ; while (true) do ( if (fact < 0 or (fact->compareTo((trailer . (name maxsize)))) > 0) then ( break; ) else skip ; res := res + 1; ; fact := fact * res;) ; return res - 1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def swap(dice,i,j,k,l): x=dice[l] dice[l]=dice[k] dice[k]=dice[j] dice[j]=dice[i] dice[i]=x return dice def Sroll(dice): dice=swap(dice,0,1,5,4) return dice def Eroll(dice): dice=swap(dice,0,2,5,3) return dice def Wroll(dice): dice=swap(dice,0,3,5,2) return dice def Nroll(dice): dice=swap(dice,0,4,5,1) return dice dice1=list(map(int,input().split())) dice2=list(map(int,input().split())) top=dice1[0] fro=dice1[1] for j in range(0,8): if(fro==dice2[1]): break if(j==3): dice2=Eroll(dice2) dice2=Sroll(dice2) while(top!=dice2[0]): dice2=Eroll(dice2) if(dice1[2]==dice2[2]): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var dice1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dice2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var top : OclAny := dice1->first() ; var fro : OclAny := dice1[1+1] ; for j : Integer.subrange(0, 8-1) do ( if (fro = dice2[1+1]) then ( break ) else skip ; if (j = 3) then ( dice2 := Eroll(dice2) ) else skip ; dice2 := Sroll(dice2)) ; while (top /= dice2->first()) do ( dice2 := Eroll(dice2)) ; if (dice1[2+1] = dice2[2+1]) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation swap(dice : OclAny, i : OclAny, j : OclAny, k : OclAny, l : OclAny) : OclAny pre: true post: true activity: var x : OclAny := dice[l+1] ; dice[l+1] := dice[k+1] ; dice[k+1] := dice[j+1] ; dice[j+1] := dice[i+1] ; dice[i+1] := x ; return dice; operation Sroll(dice : OclAny) : OclAny pre: true post: true activity: dice := swap(dice, 0, 1, 5, 4) ; return dice; operation Eroll(dice : OclAny) : OclAny pre: true post: true activity: dice := swap(dice, 0, 2, 5, 3) ; return dice; operation Wroll(dice : OclAny) : OclAny pre: true post: true activity: dice := swap(dice, 0, 3, 5, 2) ; return dice; operation Nroll(dice : OclAny) : OclAny pre: true post: true activity: dice := swap(dice, 0, 4, 5, 1) ; return dice; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np import sys dp=np.zeros((1000,1000)) def sum(a,i,j): ans=0 for m in range(i,j+1): ans=(ans+a[m])% 100 return ans def solve(a,i,j): if(i==j): return 0 if(dp[i][j]!=-1): return dp[i][j] dp[i][j]=sys.maxsize for k in range(i,j): dp[i][j]=min(dp[i][j],(solve(a,i,k)+solve(a,k+1,j)+(sum(a,i,k)*sum(a,k+1,j)))) return dp[i][j] def intialize(n): for i in range(n+1): for j in range(n+1): dp[i][j]=-1 if __name__=="__main__" : a=[40,60,20] n=len(a) intialize(n) print(int(solve(a,0,n-1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var dp : Sequence := MatrixLib.singleValueMatrix(Sequence{1000, 1000}, 0.0) ; skip ; skip ; skip ; if __name__ = "__main__" then ( a := Sequence{40}->union(Sequence{60}->union(Sequence{ 20 })) ; n := (a)->size() ; intialize(n) ; execute (("" + ((solve(a, 0, n - 1))))->toInteger())->display() ) else skip; operation sum(a : OclAny, i : OclAny, j : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for m : Integer.subrange(i, j + 1-1) do ( ans := (ans + a[m+1]) mod 100) ; return ans; operation solve(a : OclAny, i : OclAny, j : OclAny) : OclAny pre: true post: true activity: if (i = j) then ( return 0 ) else skip ; if (dp[i+1][j+1] /= -1) then ( return dp[i+1][j+1] ) else skip ; dp[i+1][j+1] := (trailer . (name maxsize)) ; for k : Integer.subrange(i, j-1) do ( dp[i+1][j+1] := Set{dp[i+1][j+1], (solve(a, i, k) + solve(a, k + 1, j) + ((a, i, k)->sum() * (a, k + 1, j)->sum()))}->min()) ; return dp[i+1][j+1]; operation intialize(n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n + 1-1) do ( for j : Integer.subrange(0, n + 1-1) do ( dp[i+1][j+1] := -1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys side=((2-1,3-1,5-1,4-1),(6-1,3-1,1-1,4-1),(1-1,2-1,6-1,5-1),(1-1,5-1,6-1,2-1),(1-1,3-1,6-1,4-1),(5-1,3-1,2-1,4-1)) def check_rotate(face1,face2,f2_index): f1_bot=face1[5] if face2[5-f2_index]!=f1_bot : return False f2_side_index=side[f2_index]*2 f2_side=[face2[f2_side_index[i]]for i in range(len(f2_side_index))] f1_side=[face1[i]for i in(2-1,3-1,5-1,4-1)] for i in range(4): if f1_side==f2_side[i : i+4]: return True return False def check_ident(face1,face2): f1_top=face1[0] for index in range(len(face2)): if face2[index]==f1_top : if check_rotate(face1,face2,index): return True return False face1=sys.stdin.readline().split() face2=sys.stdin.readline().split() if check_ident(face1,face2): print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var side : OclAny := Sequence{Sequence{2 - 1, 3 - 1, 5 - 1, 4 - 1}, Sequence{6 - 1, 3 - 1, 1 - 1, 4 - 1}, Sequence{1 - 1, 2 - 1, 6 - 1, 5 - 1}, Sequence{1 - 1, 5 - 1, 6 - 1, 2 - 1}, Sequence{1 - 1, 3 - 1, 6 - 1, 4 - 1}, Sequence{5 - 1, 3 - 1, 2 - 1, 4 - 1}} ; skip ; skip ; face1 := sys.stdin.readLine().split() ; face2 := sys.stdin.readLine().split() ; if check_ident(face1, face2) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); operation check_rotate(face1 : OclAny, face2 : OclAny, f2_index : OclAny) : OclAny pre: true post: true activity: var f1_bot : OclAny := face1[5+1] ; if face2[5 - f2_index+1] /= f1_bot then ( return false ) else skip ; var f2_side_index : double := side[f2_index+1] * 2 ; var f2_side : Sequence := Integer.subrange(0, (f2_side_index)->size()-1)->select(i | true)->collect(i | (face2[f2_side_index[i+1]+1])) ; var f1_side : Sequence := Sequence{2 - 1, 3 - 1, 5 - 1, 4 - 1}->select(i | true)->collect(i | (face1[i+1])) ; for i : Integer.subrange(0, 4-1) do ( if f1_side = f2_side.subrange(i+1, i + 4) then ( return true ) else skip) ; return false; operation check_ident(face1 : OclAny, face2 : OclAny) : OclAny pre: true post: true activity: var f1_top : OclAny := face1->first() ; for index : Integer.subrange(0, (face2)->size()-1) do ( if face2[index+1] = f1_top then ( if check_rotate(face1, face2, index) then ( return true ) else skip ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d,e=[list(map(int,input().split()))for _ in range(2)]; e[3],e[4]=e[4],e[3] t=0 for i in range(6): m={0 : '012345',1 : '152304',2 : '215043',3 : '310542',4 : '402351',5 : '513240'}[i] f=[d[int(j)]for j in m]; f[3],f[4]=f[4],f[3] if f[0]==e[0]: f=f[1 : 5]*2 for j in range(4): if f[j : j+4]==e[1 : 5]: t=1 print(('No','Yes')[t==1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : OclAny := null; var e : OclAny := null; Sequence{d,e} := Integer.subrange(0, 2-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))); var e[3+1] : OclAny := null; var e[4+1] : OclAny := null; Sequence{e[3+1],e[4+1]} := Sequence{e[4+1],e[3+1]} ; var t : int := 0 ; for i : Integer.subrange(0, 6-1) do ( var m : OclAny := Map{ 0 |-> '012345' }->union(Map{ 1 |-> '152304' }->union(Map{ 2 |-> '215043' }->union(Map{ 3 |-> '310542' }->union(Map{ 4 |-> '402351' }->union(Map{ 5 |-> '513240' })))))[i+1] ; var f : Sequence := m->select(j | true)->collect(j | (d[("" + ((j)))->toInteger()+1])); var f[3+1] : OclAny := null; var f[4+1] : OclAny := null; Sequence{f[3+1],f[4+1]} := Sequence{f[4+1],f[3+1]} ; if f->first() = e->first() then ( f := f.subrange(1+1, 5) * 2 ; for j : Integer.subrange(0, 4-1) do ( if f.subrange(j+1, j + 4) = e.subrange(1+1, 5) then ( t := 1 ) else skip) ) else skip) ; execute (Sequence{'No', 'Yes'}->select(t = 1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printNumbers(a,n): mpp=dict() for i in range(n): num=a[i] for j in range(1,num+1): if j*j>num : break if(num % j==0): if(j!=1): mpp[j]=mpp.get(j,0)+1 if((num//j)!=j): mpp[num//j]=mpp.get(num//j,0)+1 maxi=0 for it in mpp : maxi=max(mpp[it],maxi) for it in mpp : if(mpp[it]==maxi): print(it,end=" ") a=[12,15,27,20,40] n=len(a) printNumbers(a,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{12}->union(Sequence{15}->union(Sequence{27}->union(Sequence{20}->union(Sequence{ 40 })))) ; n := (a)->size() ; printNumbers(a, n); operation printNumbers(a : OclAny, n : OclAny) pre: true post: true activity: var mpp : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( var num : OclAny := a[i+1] ; for j : Integer.subrange(1, num + 1-1) do ( if (j * j->compareTo(num)) > 0 then ( break ) else skip ; if (num mod j = 0) then ( if (j /= 1) then ( mpp[j+1] := mpp.get(j, 0) + 1 ) else skip ; if ((num div j) /= j) then ( mpp[num div j+1] := mpp.get(num div j, 0) + 1 ) else skip ) else skip)) ; var maxi : int := 0 ; for it : mpp->keys() do ( maxi := Set{mpp[it+1], maxi}->max()) ; for it : mpp->keys() do ( if (mpp[it+1] = maxi) then ( execute (it)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ptn=["23542","14631","12651","15621","13641","32453"] def rNO(d): global ptn for i,e in enumerate(ptn): if d in e : return i return 0 dice1=list(input().split("")) dice2=list(input().split("")) e=dice1[2] d2=["",""] for i,v in enumerate(dice2): if dice1[0]==v : d2[0]=str(i+1) if dice1[1]==v : d2[1]=str(i+1) d2Idx=rNO("".join(d2)) if dice1[2]==dice2[d2Idx]: print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { attribute ptn : OclAny; operation initialise() pre: true post: true activity: var ptn : Sequence := Sequence{"23542"}->union(Sequence{"14631"}->union(Sequence{"12651"}->union(Sequence{"15621"}->union(Sequence{"13641"}->union(Sequence{ "32453" }))))) ; skip ; var dice1 : Sequence := (input().split("")) ; var dice2 : Sequence := (input().split("")) ; var e : OclAny := dice1[2+1] ; var d2 : Sequence := Sequence{""}->union(Sequence{ "" }) ; for _tuple : Integer.subrange(1, (dice2)->size())->collect( _indx | Sequence{_indx-1, (dice2)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if dice1->first() = v then ( d2->first() := ("" + ((i + 1))) ) else skip ; if dice1[1+1] = v then ( d2[1+1] := ("" + ((i + 1))) ) else skip) ; var d2Idx : OclAny := rNO(StringLib.sumStringsWithSeparator((d2), "")) ; if dice1[2+1] = dice2[d2Idx+1] then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation rNO(d : OclAny) : OclAny pre: true post: true activity: skip ; for _tuple : Integer.subrange(1, (ptn)->size())->collect( _indx | Sequence{_indx-1, (ptn)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var e : OclAny := _tuple->at(_indx); if (e)->includes(d) then ( return i ) else skip) ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Dice : def __init__(self,a,b,c,d,e,f): self.face1=a self.face2=b self.face3=c self.face4=d self.face5=e self.face6=f def above_face(self): return self.face1 def roll(self,order): if order=='N' : tmp=self.face1 self.face1=self.face2 self.face2=self.face6 self.face6=self.face5 self.face5=tmp elif order=='S' : tmp=self.face1 self.face1=self.face5 self.face5=self.face6 self.face6=self.face2 self.face2=tmp elif order=='W' : tmp=self.face1 self.face1=self.face3 self.face3=self.face6 self.face6=self.face4 self.face4=tmp else : tmp=self.face1 self.face1=self.face4 self.face4=self.face6 self.face6=self.face3 self.face3=tmp a,b,c,d,e,f=map(int,input().split()) dice1=Dice(a,b,c,d,e,f) a,b,c,d,e,f=map(int,input().split()) dice2=Dice(a,b,c,d,e,f) import random flag=False for i in 'NNNNWNNNWNNNENNNENNNWNNN' : dice1.roll(i) if dice1.face1==dice2.face1 and dice1.face2==dice2.face2 and dice1.face3==dice2.face3 and dice1.face4==dice2.face4 and dice1.face5==dice2.face5 and dice1.face6==dice2.face6 : flag=True break if flag==True : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class Dice { static operation newDice() : Dice pre: true post: Dice->exists( _x | result = _x ); attribute face1 : OclAny := a; attribute face2 : OclAny := b; attribute face3 : OclAny := c; attribute face4 : OclAny := d; attribute face5 : OclAny := e; attribute face6 : OclAny := f; operation initialise(a : OclAny,b : OclAny,c : OclAny,d : OclAny,e : OclAny,f : OclAny) : Dice pre: true post: true activity: self.face1 := a ; self.face2 := b ; self.face3 := c ; self.face4 := d ; self.face5 := e ; self.face6 := f; return self; operation above_face() : OclAny pre: true post: true activity: return self.face1; operation roll(order : OclAny) pre: true post: true activity: if order = 'N' then ( var tmp : OclAny := self.face1 ; self.face1 := self.face2 ; self.face2 := self.face6 ; self.face6 := self.face5 ; self.face5 := tmp ) else (if order = 'S' then ( tmp := self.face1 ; self.face1 := self.face5 ; self.face5 := self.face6 ; self.face6 := self.face2 ; self.face2 := tmp ) else (if order = 'W' then ( tmp := self.face1 ; self.face1 := self.face3 ; self.face3 := self.face6 ; self.face6 := self.face4 ; self.face4 := tmp ) else ( tmp := self.face1 ; self.face1 := self.face4 ; self.face4 := self.face6 ; self.face6 := self.face3 ; self.face3 := tmp ) ) ) ; } class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{a,b,c,d,e,f} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dice1 : Dice := (Dice.newDice()).initialise(a, b, c, d, e, f) ; Sequence{a,b,c,d,e,f} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dice2 : Dice := (Dice.newDice()).initialise(a, b, c, d, e, f) ; skip ; var flag : boolean := false ; for i : 'NNNNWNNNWNNNENNNENNNWNNN'->characters() do ( dice1.roll(i) ; if dice1.face1 = dice2.face1 & dice1.face2 = dice2.face2 & dice1.face3 = dice2.face3 & dice1.face4 = dice2.face4 & dice1.face5 = dice2.face5 & dice1.face6 = dice2.face6 then ( flag := true ; break ) else skip) ; if flag = true then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: t=set() for x in map(int,s.split()): t |={(x,-x)[x in t]} print(len(t)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var t : Set := Set{}->union(()) ; for x : (s.split())->collect( _x | (OclType["int"])->apply(_x) ) do ( t := t or Set{ Sequence{x, -x}->select((t)->includes(x)) }) ; execute ((t)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t=int(input()) ans=[] for _ in range(t): n=int(input()) a=list(map(int,input().split())) cnt=[0]*105 for i in a : cnt[abs(i)]+=1 ans0=min(cnt[0],1) for i in cnt[1 :]: ans0+=min(i,2) ans.append(ans0) sys.stdout.write("\n".join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 105) ; for i : a do ( cnt[(i)->abs()+1] := cnt[(i)->abs()+1] + 1) ; var ans0 : OclAny := Set{cnt->first(), 1}->min() ; for i : cnt->tail() do ( ans0 := ans0 + Set{i, 2}->min()) ; execute ((ans0) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: t=set() for x in map(int,s.split()): t |={(x,-x)[x in t]} print(len(t)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var t : Set := Set{}->union(()) ; for x : (s.split())->collect( _x | (OclType["int"])->apply(_x) ) do ( t := t or Set{ Sequence{x, -x}->select((t)->includes(x)) }) ; execute ((t)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) a=[int(i)for i in input().split()] w={} for i in a : if i in w : w[i]+=1 else : w[i]=1 ans=0 for i in w : if i==0 : ans+=1 else : if w[i]>=2 : if-i not in w : ans+=2 else : ans+=1 else : ans+=1 return ans t=int(input()) ans=[] while t : ans.append(str(solve())) t-=1 print("\n".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; ans := Sequence{} ; while t do ( execute ((("" + ((solve())))) : ans) ; t := t - 1) ; execute (StringLib.sumStringsWithSeparator((ans), "\n"))->display(); operation solve() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var w : OclAny := Set{} ; for i : a do ( if (w)->includes(i) then ( w[i+1] := w[i+1] + 1 ) else ( w[i+1] := 1 )) ; var ans : int := 0 ; for i : w do ( if i = 0 then ( ans := ans + 1 ) else ( if w[i+1] >= 2 then ( if (w)->excludes(-i) then ( ans := ans + 2 ) else ( ans := ans + 1 ) ) else ( ans := ans + 1 ) )) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): s={} n,ans=int(input()),0 a=list(map(int,input().split(' '))) ans=0 if n==len(a): b=[] for i in range(n): if a[i]not in b : b.append(a[i]) ans+=1 else : if a[i]*(-1)not in b : b.append(a[i]*(-1)) ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : OclAny := Set{} ; var n : OclAny := null; var ans : OclAny := null; Sequence{n,ans} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),0} ; var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; if n = (a)->size() then ( var b : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if (b)->excludes(a[i+1]) then ( execute ((a[i+1]) : b) ; ans := ans + 1 ) else ( if (b)->excludes(a[i+1] * (-1)) then ( execute ((a[i+1] * (-1)) : b) ; ans := ans + 1 ) else skip )) ) else skip ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def primesieve(prime): prime[1]=False ; for p in range(2,int(sqrt(650))+1): if(prime[p]==True): for i in range(p*2,651,p): prime[i]=False ; def sum_sqsum(n): sum=0 ; sqsum=0 ; while(n): x=n % 10 ; sum+=x ; sqsum+=x*x ; n//=10 ; return(sum,sqsum); def countnumber(L,R): prime=[True]*651 ; primesieve(prime); cnt=0 ; for i in range(L,R+1): digit=sum_sqsum(i); if(prime[digit[0]]and prime[digit[1]]): cnt+=1 ; return cnt ; if __name__=="__main__" : L=10 ; R=20 ; print(countnumber(L,R)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( L := 10; ; R := 20; ; execute (countnumber(L, R))->display(); ) else skip; operation primesieve(prime : OclAny) pre: true post: true activity: prime[1+1] := false; ; for p : Integer.subrange(2, ("" + ((sqrt(650))))->toInteger() + 1-1) do ( if (prime[p+1] = true) then ( for i : Integer.subrange(p * 2, 651-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false;) ) else skip); operation sum_sqsum(n : OclAny) pre: true post: true activity: var sum : int := 0; ; var sqsum : int := 0; ; while (n) do ( var x : int := n mod 10; ; sum := sum + x; ; sqsum := sqsum + x * x; ; n := n div 10;) ; return Sequence{sum, sqsum};; operation countnumber(L : OclAny, R : OclAny) pre: true post: true activity: prime := MatrixLib.elementwiseMult(Sequence{ true }, 651); ; primesieve(prime); ; var cnt : int := 0; ; for i : Integer.subrange(L, R + 1-1) do ( var digit : OclAny := sum_sqsum(i); ; if (prime[digit->first()+1] & prime[digit[1+1]+1]) then ( cnt := cnt + 1; ) else skip) ; return cnt;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printArray(arr,size): for i in range(size): print(arr[i],end=""); print(""); return ; def printSequencesRecur(arr,n,k,index): if(k==0): printArray(arr,index); if(k>0): for i in range(1,n+1): arr[index]=i ; printSequencesRecur(arr,n,k-1,index+1); def printSequences(n,k): arr=[0]*n ; printSequencesRecur(arr,n,k,0); return ; n=3 ; k=2 ; printSequences(n,k); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 3; ; k := 2; ; printSequences(n, k);; operation printArray(arr : OclAny, size : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, size-1) do ( execute (arr[i+1])->display();) ; execute ("")->display(); ; return;; operation printSequencesRecur(arr : OclAny, n : OclAny, k : OclAny, index : OclAny) pre: true post: true activity: if (k = 0) then ( printArray(arr, index); ) else skip ; if (k > 0) then ( for i : Integer.subrange(1, n + 1-1) do ( arr[index+1] := i; ; printSequencesRecur(arr, n, k - 1, index + 1);) ) else skip; operation printSequences(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: arr := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; printSequencesRecur(arr, n, k, 0); ; return;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printRepeating(arr,size): s=set() for i in range(size): if arr[i]not in s : s.add(arr[i]) for i in s : print(i,end=" ") if __name__=='__main__' : arr=[1,3,2,2,1] size=len(arr) printRepeating(arr,size) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{3}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 1 })))) ; size := (arr)->size() ; printRepeating(arr, size) ) else skip; operation printRepeating(arr : OclAny, size : OclAny) pre: true post: true activity: var s : Set := Set{}->union(()) ; for i : Integer.subrange(0, size-1) do ( if (s)->excludes(arr[i+1]) then ( execute ((arr[i+1]) : s) ) else skip) ; for i : s do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() ts=s.replace("a","") ls=len(ts)//2 ans=s[: len(s)-ls] if len(ts)% 2 or ans.replace("a","")!=ts[ls :]: print(":(") else : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var ts : String := s.replace("a", "") ; var ls : int := (ts)->size() div 2 ; var ans : OclAny := s.subrange(1,(s)->size() - ls) ; if (ts)->size() mod 2 or ans.replace("a", "") /= ts.subrange(ls+1) then ( execute (":(")->display() ) else ( execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools def compute(): INDEX=124 stream=(i for i in itertools.count(1,2)if not has_tribonacci_multiple(i)) ans=next(itertools.islice(stream,INDEX-1,None)) return str(ans) def has_tribonacci_multiple(i): seen=set() a,b,c=1,1,1 while True : key=(a,b,c) if key in seen : return False seen.add(key) if a % i==0 : return True a,b,c=b,c,(a+b+c)% i if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var INDEX : int := 124 ; var stream : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name itertools)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))))) (comp_iter if (test (logical_test not (logical_test (comparison (expr (atom (name has_tribonacci_multiple)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))))} ; var ans : OclAny := (itertools.islice(stream, INDEX - 1, null)).next() ; return ("" + ((ans))); operation has_tribonacci_multiple(i : OclAny) : OclAny pre: true post: true activity: var seen : Set := Set{}->union(()) ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{1,1,1} ; while true do ( var key : OclAny := Sequence{a, b, c} ; if (seen)->includes(key) then ( return false ) else skip ; execute ((key) : seen) ; if a mod i = 0 then ( return true ) else skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{b,c,(a + b + c) mod i}); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solution(a,b,n): i=0 while i*a<=n : if(n-(i*a))% b==0 : print("x=",i,",y=",int((n-(i*a))/b)) return 0 i=i+1 print("No solution") a=2 b=3 n=7 solution(a,b,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 2 ; b := 3 ; n := 7 ; solution(a, b, n); operation solution(a : OclAny, b : OclAny, n : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; while (i * a->compareTo(n)) <= 0 do ( if (n - (i * a)) mod b = 0 then ( execute ("x=")->display() ; return 0 ) else skip ; i := i + 1) ; execute ("No solution")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline x,y=map(int,input().split()) if max(x,y)<=8 : if pow(x,y)pow(y,x): ans=">" else : ans="=" else : if xy : ans="<" if y ^ 1 else ">" else : ans="=" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if Set{x, y}->max() <= 8 then ( if ((x)->pow(y)->compareTo((y)->pow(x))) < 0 then ( var ans : String := "<" ) else (if ((x)->pow(y)->compareTo((y)->pow(x))) > 0 then ( ans := ">" ) else ( ans := "=" ) ) ) else ( if (x->compareTo(y)) < 0 then ( ans := if MathLib.bitwiseXor(x, 1) then ">" else "<" endif ) else (if (x->compareTo(y)) > 0 then ( ans := if MathLib.bitwiseXor(y, 1) then "<" else ">" endif ) else ( ans := "=" ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math x,y=list(map(int,input().split())) if x*math.log(y)>y*math.log(x): print("<") elif x*math.log(y)==y*math.log(x): print("=") else : print(">") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (x * (y)->log()->compareTo(y * (x)->log())) > 0 then ( execute ("<")->display() ) else (if x * (y)->log() = y * (x)->log() then ( execute ("=")->display() ) else ( execute (">")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math x,y=map(int,input().split()) a=y*math.log(x,10) b=x*math.log(y,10) if a>b : print('>') elif a')->display() ) else (if (a->compareTo(b)) < 0 then ( execute ('<')->display() ) else ( execute ('=')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math x,y=map(int,input().split()) a=y*math.log(x) b=x*math.log(y) if abs(a-b)<1e-8 : print('=') elif a') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : double := y * (x)->log() ; var b : double := x * (y)->log() ; if (a - b)->abs() < ("1e-8")->toReal() then ( execute ('=')->display() ) else (if (a->compareTo(b)) < 0 then ( execute ('<')->display() ) else ( execute ('>')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math x,y=map(int,input().split()) a=y*math.log(x) b=x*math.log(y) if abs(a-b)<1e-8 : print('=') elif a') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : double := y * (x)->log() ; var b : double := x * (y)->log() ; if (a - b)->abs() < ("1e-8")->toReal() then ( execute ('=')->display() ) else (if (a->compareTo(b)) < 0 then ( execute ('<')->display() ) else ( execute ('>')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==0 : print(0) else : s=input() ans=1 for i in range(1,len(s)): if s[i-1]=='x' and s[i]=='x' : break ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( execute (0)->display() ) else ( var s : String := (OclFile["System.in"]).readLine() ; var ans : int := 1 ; for i : Integer.subrange(1, (s)->size()-1) do ( if s[i - 1+1] = 'x' & s[i+1] = 'x' then ( break ) else skip ; ans := ans + 1) ; execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N=int(input()) S=input() try : ans=S.index('xx')+1 print(ans) except : print(N) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : String := (OclFile["System.in"]).readLine() ; try ( var ans : int := S->indexOf('xx') - 1 + 1 ; execute (ans)->display()) catch (_e : OclException) do ( execute (N)->display()) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import os import math for i,s in enumerate(sys.stdin): n=int(s) if n==0 : break elif i!=0 : print() A=[] for i in range(n): lst=input().split() name=lst[0] w=int(lst[1]) l=int(lst[2]) d=int(lst[3]) score=3*w+d A.append((score,-i,name)) A.sort(reverse=True) for a in A : score=a[0] name=a[2] print('{},{}'.format(name,score)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; for _tuple : Integer.subrange(1, (OclFile["System.in"])->size())->collect( _indx | Sequence{_indx-1, (OclFile["System.in"])->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); var n : int := ("" + ((s)))->toInteger() ; if n = 0 then ( break ) else (if i /= 0 then ( execute (->display() ) else skip) ; var A : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var lst : OclAny := input().split() ; var name : OclAny := lst->first() ; var w : int := ("" + ((lst[1+1])))->toInteger() ; var l : int := ("" + ((lst[2+1])))->toInteger() ; var d : int := ("" + ((lst[3+1])))->toInteger() ; var score : int := 3 * w + d ; execute ((Sequence{score, -i, name}) : A)) ; A := A->sort() ; for a : A do ( score := a->first() ; name := a[2+1] ; execute (StringLib.interpolateStrings('{},{}', Sequence{name, score}))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x1,x2=map(int,input().split()) lista=[] for i in range(n): ki,bi=map(int,input().split()) result=(ki*x1+bi,ki*x2+bi) lista.append(result) new_lista=sorted(lista) def func(value): if value : if value>0 : return 1 else : return-1 return value for i in range(1,len(new_lista)): if((func(new_lista[i][0]-new_lista[i-1][0]))*func(new_lista[i][1]-new_lista[i-1][1]))<0 : print('YES') exit() print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x1 : OclAny := null; var x2 : OclAny := null; Sequence{x1,x2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lista : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var ki : OclAny := null; var bi : OclAny := null; Sequence{ki,bi} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var result : OclAny := Sequence{ki * x1 + bi, ki * x2 + bi} ; execute ((result) : lista)) ; var new_lista : Sequence := lista->sort() ; skip ; for i : Integer.subrange(1, (new_lista)->size()-1) do ( if ((func(new_lista[i+1]->first() - new_lista[i - 1+1]->first())) * func(new_lista[i+1][1+1] - new_lista[i - 1+1][1+1])) < 0 then ( execute ('YES')->display() ; exit() ) else skip) ; execute ('NO')->display(); operation func(value : OclAny) : OclAny pre: true post: true activity: if value then ( if value > 0 then ( return 1 ) else ( return -1 ) ) else skip ; return value; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys i=sys.stdin.readline n,m=map(int,i().split()) sa=i().count("-") sa=min([n-sa,sa]) ss=[] for _ in range(m): a,b=map(int,i().split()) b-=a ss.append((b % 2 and b<=sa<<1)and "1\n" or "0\n") print("".join(ss)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var i : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (i().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sa : OclAny := i()->count("-") ; sa := (Sequence{n - sa}->union(Sequence{ sa }))->min() ; var ss : Sequence := Sequence{} ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (i().split())->collect( _x | (OclType["int"])->apply(_x) ) ; b := b - a ; execute (((b mod 2 & (b->compareTo(sa * (2->pow(1)))) <= 0) & "1\n" or "0\n") : ss)) ; execute (StringLib.sumStringsWithSeparator((ss), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() no_a=s.replace('a','') if(len(no_a)==0): print(s) elif no_a[: len(no_a)//2]==no_a[len(no_a)//2 :]and s[-1*len(no_a)//2 :]==no_a[len(no_a)//2 :]: print(s[:-1*len(no_a)//2]) else : print(":(") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var no_a : String := s.replace('a', '') ; if ((no_a)->size() = 0) then ( execute (s)->display() ) else (if no_a.subrange(1,(no_a)->size() div 2) = no_a.subrange((no_a)->size() div 2+1) & s.subrange(-1 * (no_a)->size() div 2+1) = no_a.subrange((no_a)->size() div 2+1) then ( execute (s.subrange(1,-1 * (no_a)->size() div 2))->display() ) else ( execute (":(")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys rhombus=rectangle=0 for line in sys.stdin : a,b,c=map(int,line.split(",")) if c**2==a**2+b**2 : rectangle+=1 elif a==b : rhombus+=1 print(rectangle) print(rhombus) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var rhombus : OclAny := 0; var rectangle : int := 0 ; for line : OclFile["System.in"] do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (line.split(","))->collect( _x | (OclType["int"])->apply(_x) ) ; if (c)->pow(2) = (a)->pow(2) + (b)->pow(2) then ( rectangle := rectangle + 1 ) else (if a = b then ( rhombus := rhombus + 1 ) else skip)) ; execute (rectangle)->display() ; execute (rhombus)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin n=int(stdin.readline().rstrip()) s=stdin.readline().rstrip() faint=False for i in range(1,n): if s[i-1]=="x" and s[i]=="x" : print(i) exit() print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + ((stdin.readLine().rstrip())))->toInteger() ; var s : OclAny := stdin.readLine().rstrip() ; var faint : boolean := false ; for i : Integer.subrange(1, n-1) do ( if s[i - 1+1] = "x" & s[i+1] = "x" then ( execute (i)->display() ; exit() ) else skip) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() print(input().find('xx')+1 or n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; execute (input()->indexOf('xx') - 1 + 1 or n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=input() S=input() N=int(N) S_list=list(S) flg=0 for i in range(N): if flg==0 : if S_list[i]==('x'): flg=1 elif S_list[i]==('o'): flg=0 elif S_list[i]==('x'): flg=2 break if i==N-1 : if flg<2 : i=N print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : String := (OclFile["System.in"]).readLine() ; var S : String := (OclFile["System.in"]).readLine() ; N := ("" + ((N)))->toInteger() ; var S_list : Sequence := (S)->characters() ; var flg : int := 0 ; for i : Integer.subrange(0, N-1) do ( if flg = 0 then ( if S_list[i+1] = ('x') then ( flg := 1 ) else skip ) else (if S_list[i+1] = ('o') then ( flg := 0 ) else (if S_list[i+1] = ('x') then ( flg := 2 ; break ) else skip ) ) ) ; if i = N - 1 then ( if flg < 2 then ( var i : String := N ) else skip ) else skip ; execute (i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W=map(int,input().split()) G=[list(map(lambda x : x=='#',input().strip()))for _ in range(H)] Takahashi=[[False]*W for _ in range(H)] Aoki=[[False]*W for _ in range(H)] for h in range(H): for w in range(W): if w==0 : Takahashi[h][w]=True elif not h & 1 : Aoki[h][w]=True if w==W-1 : Aoki[h][w]=True elif h & 1 : Takahashi[h][w]=True if G[h][w]: Takahashi[h][w]=True Aoki[h][w]=True print('\n'.join([''.join(['#' if s else '.' for s in Takahashi[i]])for i in range(H)])) print('') print('\n'.join([''.join(['#' if s else '.' for s in Aoki[i]])for i in range(H)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var G : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (((input()->trim())->collect( _x | (lambda x : OclAny in (x = '#'))->apply(_x) )))) ; var Takahashi : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ false }, W))) ; var Aoki : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ false }, W))) ; for h : Integer.subrange(0, H-1) do ( for w : Integer.subrange(0, W-1) do ( if w = 0 then ( Takahashi[h+1][w+1] := true ) else (if not(MathLib.bitwiseAnd(h, 1)) then ( Aoki[h+1][w+1] := true ) else skip) ; if w = W - 1 then ( Aoki[h+1][w+1] := true ) else (if MathLib.bitwiseAnd(h, 1) then ( Takahashi[h+1][w+1] := true ) else skip) ; if G[h+1][w+1] then ( Takahashi[h+1][w+1] := true ; Aoki[h+1][w+1] := true ) else skip)) ; execute (StringLib.sumStringsWithSeparator((Integer.subrange(0, H-1)->select(i | true)->collect(i | (StringLib.sumStringsWithSeparator((Takahashi[i+1]->select(s | true)->collect(s | (if s then '#' else '.' endif))), '')))), ' '))->display() ; execute ('')->display() ; execute (StringLib.sumStringsWithSeparator((Integer.subrange(0, H-1)->select(i | true)->collect(i | (StringLib.sumStringsWithSeparator((Aoki[i+1]->select(s | true)->collect(s | (if s then '#' else '.' endif))), '')))), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): import sys input=sys.stdin.readline H,W=map(int,input().split()) grid_p=[] for _ in range(H): grid_p.append(input().rstrip('\n')) grid_r=[['.']*W for _ in range(H)] grid_b=[['.']*W for _ in range(H)] for w in range(W): grid_r[0][w]='#' grid_b[-1][w]='#' for h in range(1,H-1): for w in range(W): if w % 2 : grid_r[h][w]='#' else : grid_b[h][w]='#' for h in range(H): for w in range(W): if grid_p[h][w]=='#' : grid_r[h][w]='#' grid_b[h][w]='#' [print(''.join(line))for line in grid_r] print('') [print(''.join(line))for line in grid_b] if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; ; operation main() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var grid_p : Sequence := Sequence{} ; for _anon : Integer.subrange(0, H-1) do ( execute ((input().rstrip(' ')) : grid_p)) ; var grid_r : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ '.' }, W))) ; var grid_b : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ '.' }, W))) ; for w : Integer.subrange(0, W-1) do ( grid_r->first()[w+1] := '#' ; grid_b->last()[w+1] := '#') ; for h : Integer.subrange(1, H - 1-1) do ( for w : Integer.subrange(0, W-1) do ( if w mod 2 then ( grid_r[h+1][w+1] := '#' ) else ( grid_b[h+1][w+1] := '#' ))) ; for h : Integer.subrange(0, H-1) do ( for w : Integer.subrange(0, W-1) do ( if grid_p[h+1][w+1] = '#' then ( grid_r[h+1][w+1] := '#' ; grid_b[h+1][w+1] := '#' ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,Counter from itertools import product,groupby,count,permutations,combinations from math import pi,sqrt from collections import deque from bisect import bisect,bisect_left,bisect_right INF=10**10 def check(ans1,ans2,field): h,w=len(ans1),len(ans1[0]) ans=[[0]*w for _ in range(h)] for y in range(h): for x in range(w): c="#" if ans1[y][x]==ans2[y][x]=="#" else "." if field[y][x]!=c : print(y,x) def main(): H,W=map(int,input().split()) field=[] for _ in range(H): field.append(input()) ans1,ans2=[["."]*W for _ in range(H)],[["."]*W for _ in range(H)] for i in range(H): ans1[i][0]="#" ans2[i][-1]="#" if i % 2==0 : ans1[i]=["#"]*(W-1)+["."] else : ans2[i]=["."]+["#"]*(W-1) for y in range(H): for x in range(W): if field[y][x]=="#" : if y % 2==0 : ans2[y][x]="#" else : ans1[y][x]="#" for line in ans1 : print("".join(line)) print() for line in ans2 : print("".join(line)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var INF : double := (10)->pow(10) ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation check(ans1 : OclAny, ans2 : OclAny, field : OclAny) pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := Sequence{(ans1)->size(),(ans1->first())->size()} ; var ans : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, w))) ; for y : Integer.subrange(0, h-1) do ( for x : Integer.subrange(0, w-1) do ( var c : String := if ans1[y+1][x+1] = ans2[y+1][x+1] & (ans2[y+1][x+1] == "#") then "#" else "." endif ; if field[y+1][x+1] /= c then ( execute (y)->display() ) else skip)); operation main() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; field := Sequence{} ; for _anon : Integer.subrange(0, H-1) do ( execute (((OclFile["System.in"]).readLine()) : field)) ; Sequence{ans1,ans2} := Sequence{Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ "." }, W))),Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ "." }, W)))} ; for i : Integer.subrange(0, H-1) do ( ans1[i+1]->first() := "#" ; ans2[i+1]->last() := "#" ; if i mod 2 = 0 then ( ans1[i+1] := MatrixLib.elementwiseMult(Sequence{ "#" }, (W - 1))->union(Sequence{ "." }) ) else ( ans2[i+1] := Sequence{ "." }->union(MatrixLib.elementwiseMult(Sequence{ "#" }, (W - 1))) )) ; for y : Integer.subrange(0, H-1) do ( for x : Integer.subrange(0, W-1) do ( if field[y+1][x+1] = "#" then ( if y mod 2 = 0 then ( ans2[y+1][x+1] := "#" ) else ( ans1[y+1][x+1] := "#" ) ) else skip)) ; for line : ans1 do ( execute (StringLib.sumStringsWithSeparator((line), ""))->display()) ; execute (->display() ; for line : ans2 do ( execute (StringLib.sumStringsWithSeparator((line), ""))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import numpy as np H,W=map(int,sys.stdin.buffer.readline().split()) purple=np.frombuffer(sys.stdin.buffer.read(),dtype='S1').reshape(H,-1)[:,: W].astype(str) red=np.full((H,W),'.',dtype='U1') blue=np.full((H,W),'.',dtype='U1') red[:,: : 2]='#' red[-1]='.' red[0]='#' blue[:,1 : : 2]='#' blue[-1]='#' blue[0]='.' is_purple=purple=='#' red[is_purple]='#' blue[is_purple]='#' print('\n'.join(''.join(row)for row in red)) print() print('\n'.join(''.join(row)for row in blue)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var purple : OclAny := np.frombuffer(sys.stdin.buffer.readAll(), (argument (test (logical_test (comparison (expr (atom (name dtype)))))) = (test (logical_test (comparison (expr (atom 'S1'))))))).reshape(H, -1)->collect( _r | _r.subrange(1,W) ).astype(OclType["String"]) ; var red : Sequence := MatrixLib.singleValueMatrix(Sequence{H, W}, '.') ; var blue : Sequence := MatrixLib.singleValueMatrix(Sequence{H, W}, '.') ; red->collect( _r | _r(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ) := '#' ; red->last() := '.' ; red->first() := '#' ; blue->collect( _r | _r(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ) := '#' ; blue->last() := '#' ; blue->first() := '.' ; var is_purple : boolean := purple = '#' ; red[is_purple+1] := '#' ; blue[is_purple+1] := '#' ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom '') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name row)))))))) ))))))) (comp_for for (exprlist (expr (atom (name row)))) in (logical_test (comparison (expr (atom (name red)))))))), ' '))->display() ; execute (->display() ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom '') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name row)))))))) ))))))) (comp_for for (exprlist (expr (atom (name row)))) in (logical_test (comparison (expr (atom (name blue)))))))), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def main(): h,w=LI() a=[[c=='#' for c in S()]for _ in range(h)] r=['#'*w] for c in a[1 :-1]: t='' for i in range(w): ci=c[i] if ci or i % 2==0 : t+='#' else : t+='.' r.append(t) r.append('.'*w) r.append('') r.append('.'*w) for c in a[1 :-1]: t='' for i in range(w): ci=c[i] if ci or i % 2==1 : t+='#' else : t+='.' r.append(t) r.append('#'*w) return '\n'.join(r) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation main() : OclAny pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := LI() ; var a : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (S()->select(c | true)->collect(c | (c = '#')))) ; var r : Sequence := Sequence{ StringLib.nCopies('#', w) } ; for c : a.subrange(1+1, -1) do ( var t : String := '' ; for i : Integer.subrange(0, w-1) do ( var ci : OclAny := c[i+1] ; if ci or i mod 2 = 0 then ( t := t + '#' ) else ( t := t + '.' )) ; execute ((t) : r)) ; execute ((StringLib.nCopies('.', w)) : r) ; execute (('') : r) ; execute ((StringLib.nCopies('.', w)) : r) ; for c : a.subrange(1+1, -1) do ( t := '' ; for i : Integer.subrange(0, w-1) do ( ci := c[i+1] ; if ci or i mod 2 = 1 then ( t := t + '#' ) else ( t := t + '.' )) ; execute ((t) : r)) ; execute ((StringLib.nCopies('#', w)) : r) ; return StringLib.sumStringsWithSeparator((r), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def unitDigitXRaisedY(x,y): res=1 for i in range(y): res=(res*x)% 10 return res print(unitDigitXRaisedY(4,2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (unitDigitXRaisedY(4, 2))->display(); operation unitDigitXRaisedY(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; for i : Integer.subrange(0, y-1) do ( res := (res * x) mod 10) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() str1="" str2="" flag=0 n=len(s) for i in range(n): str1+=s[i] if(s[i]!="a"): str2+=s[i] if(str1+str2)==s : flag=1 break if(flag==0): print(":(") else : print(str1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var str1 : String := "" ; var str2 : String := "" ; var flag : int := 0 ; var n : int := (s)->size() ; for i : Integer.subrange(0, n-1) do ( str1 := str1 + s[i+1] ; if (s[i+1] /= "a") then ( str2 := str2 + s[i+1] ) else skip ; if (str1 + str2) = s then ( flag := 1 ; break ) else skip) ; if (flag = 0) then ( execute (":(")->display() ) else ( execute (str1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) count=0 for x in range(1,(n//2)+1): if(n-x)% x==0 : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := 0 ; for x : Integer.subrange(1, (n div 2) + 1-1) do ( if (n - x) mod x = 0 then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): Rec=0 Dia=0 while True : try : a,b,c=map(int,input().split(",")) if a==b : Dia+=1 elif a!=b and c>a and c>b : Rec+=1 except EOFError : break print(Rec) print(Dia) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var Rec : int := 0 ; var Dia : int := 0 ; while true do ( try ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split(","))->collect( _x | (OclType["int"])->apply(_x) ) ; if a = b then ( Dia := Dia + 1 ) else (if a /= b & (c->compareTo(a)) > 0 & (c->compareTo(b)) > 0 then ( Rec := Rec + 1 ) else skip)) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))) ; execute (Rec)->display() ; execute (Dia)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) k=0 for i in range(1,a): if a % i==0 : k+=1 print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := 0 ; for i : Integer.subrange(1, a-1) do ( if a mod i = 0 then ( k := k + 1 ) else skip) ; execute (k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) c=0 for i in range(1,n//2+1): if((n-i)//i)*i==n-i : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := 0 ; for i : Integer.subrange(1, n div 2 + 1-1) do ( if ((n - i) div i) * i = n - i then ( c := c + 1 ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(len([x for x in range(1,n)if not n % x])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((Integer.subrange(1, n-1)->select(x | not(n mod x))->collect(x | (x)))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) count=0 for i in range(1,x): if x % i==0 : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := 0 ; for i : Integer.subrange(1, x-1) do ( if x mod i = 0 then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=[int(x)for x in input().split()] if k>=2*n : print(0) elif k>n : print((2*n-k+1)//2) elif k==n : print((n-1)//2) else : print((k-1)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if (k->compareTo(2 * n)) >= 0 then ( execute (0)->display() ) else (if (k->compareTo(n)) > 0 then ( execute ((2 * n - k + 1) div 2)->display() ) else (if k = n then ( execute ((n - 1) div 2)->display() ) else ( execute ((k - 1) div 2)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) if n>=k : if k % 2==0 : k-=1 print(k//2) exit(0) ans=2*n-k if ans<=0 : print(0) else : print((ans+1)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (n->compareTo(k)) >= 0 then ( if k mod 2 = 0 then ( k := k - 1 ) else skip ; execute (k div 2)->display() ; exit(0) ) else skip ; var ans : double := 2 * n - k ; if ans <= 0 then ( execute (0)->display() ) else ( execute ((ans + 1) div 2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) if n>=k : if k % 2==0 : k-=1 print(k//2) exit(0) ans=2*n-k if ans<=0 : print(0) else : print((ans+1)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (n->compareTo(k)) >= 0 then ( if k mod 2 = 0 then ( k := k - 1 ) else skip ; execute (k div 2)->display() ; exit(0) ) else skip ; var ans : double := 2 * n - k ; if ans <= 0 then ( execute (0)->display() ) else ( execute ((ans + 1) div 2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) if n>=k : if k % 2==0 : k-=1 print(k//2) exit(0) ans=2*n-k if ans<=0 : print(0) else : print((ans+1)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (n->compareTo(k)) >= 0 then ( if k mod 2 = 0 then ( k := k - 1 ) else skip ; execute (k div 2)->display() ; exit(0) ) else skip ; var ans : double := 2 * n - k ; if ans <= 0 then ( execute (0)->display() ) else ( execute ((ans + 1) div 2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import inf def main(): t=int(input()) while t : n,k=list(map(int,input().split(' '))) a=list(map(int,input().split(' '))) flag=False exsit=False dist=inf small_num=0 for i in range(n): if a[i]==k : exsit=True if a[i]>=k : if dist<=1 : flag=True dist=0 if a[i]toInteger() ; while t do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var flag : boolean := false ; var exsit : boolean := false ; var dist : double := Math_PINFINITY ; var small_num : int := 0 ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = k then ( exsit := true ) else skip ; if (a[i+1]->compareTo(k)) >= 0 then ( if dist <= 1 then ( flag := true ) else skip ; dist := 0 ) else skip ; if (a[i+1]->compareTo(k)) < 0 then ( dist := dist + 1 ; small_num := small_num + 1 ) else skip) ; if exsit then ( if flag or small_num = 0 then ( execute ('yes')->display() ) else ( execute ('no')->display() ) ) else ( execute ('no')->display() ) ; t := t - 1) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) print(max(0,min(n,k-1)-(k>>1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{0, Set{n, k - 1}->min() - (k /(2->pow(1)))}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def checkCollision(a,b,c,x,y,radius): dist=((abs(a*x+b*y+c))/math.sqrt(a*a+b*b)) if(radius==dist): print("Touch") elif(radius>dist): print("Intersect") else : print("Outside") radius=5 x=0 y=0 a=3 b=4 c=25 checkCollision(a,b,c,x,y,radius) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; radius := 5 ; x := 0 ; y := 0 ; a := 3 ; b := 4 ; c := 25 ; checkCollision(a, b, c, x, y, radius); operation checkCollision(a : OclAny, b : OclAny, c : OclAny, x : OclAny, y : OclAny, radius : OclAny) pre: true post: true activity: var dist : double := (((a * x + b * y + c)->abs()) / (a * a + b * b)->sqrt()) ; if (radius = dist) then ( execute ("Touch")->display() ) else (if ((radius->compareTo(dist)) > 0) then ( execute ("Intersect")->display() ) else ( execute ("Outside")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import(division,absolute_import,print_function,unicode_literals) from sys import stdin rectangle=diamond=0 for line in stdin : try : a,b,c=(int(s)for s in line.split(',')) except ValueError : break diamond+=a==b rectangle+=a**2+b**2==c**2 print(rectangle,diamond,sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var rectangle : OclAny := 0; var diamond : int := 0 ; for line : stdin do ( try ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name line)) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ','))))))) ))))))))}) (except_clause except (test (logical_test (comparison (expr (atom (name ValueError)))))) : (suite (stmt (simple_stmt (small_stmt break))))) ; diamond := diamond + a = b ; rectangle := rectangle + (a)->pow(2) + (b)->pow(2) = (c)->pow(2)) ; execute (rectangle)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) def f(m): global n global k total=m*k-(m*(m-1))//2 total-=(m-1) return total>=n if((k*(k+1))//2-(k-1)(l+1)): m=(r+l)//2 if(f(m)==0): l=m else : r=m print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute n : OclAny; attribute k : OclAny; operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; if (((k * (k + 1)) div 2 - (k - 1)->compareTo(n)) < 0) then ( execute (-1)->display() ) else (if n = 1 then ( execute (0)->display() ) else ( var r : OclAny := k ; var l : int := 0 ; while ((r->compareTo((l + 1))) > 0) do ( m := (r + l) div 2 ; if (f(m) = 0) then ( l := m ) else ( r := m )) ; execute (r)->display() ) ) ; operation f(m : OclAny) : OclAny pre: true post: true activity: skip ; skip ; var total : double := m * k - (m * (m - 1)) div 2 ; total := total - (m - 1) ; return (total->compareTo(n)) >= 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) cnt=0 def sum1(n): return(n*(n+1))//2 s=sum1(k-1) n=n-1 if s=n : ans=mid low=mid+1 else : high=mid-1 print(k-1-ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cnt : int := 0 ; skip ; var s : OclAny := sum1(k - 1) ; n := n - 1 ; if (s->compareTo(n)) < 0 then ( execute (-1)->display() ) else ( var low : int := 0 ; var high : double := k - 1 ; while (low->compareTo(high)) <= 0 do ( var mid : int := low + (high - low) div 2 ; if (s - sum1(mid)->compareTo(n)) >= 0 then ( var ans : int := mid ; low := mid + 1 ) else ( high := mid - 1 )) ; execute (k - 1 - ans)->display() ); operation sum1(n : OclAny) : OclAny pre: true post: true activity: return (n * (n + 1)) div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import heapq import sys import math import itertools import bisect from io import BytesIO,IOBase import os def valid(i,j,n,m): if i=0 and j>=0 and j=n : return k-h+1 else : return k-h+2 if __name__=="__main__" : print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( execute (solve())->display() ) else skip; operation valid(i : OclAny, j : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: if (i->compareTo(n)) < 0 & i >= 0 & j >= 0 & (j->compareTo(m)) < 0 then ( return true ) else skip ; return false; operation sumn(i : OclAny, n : OclAny) : OclAny pre: true post: true activity: return (n - i + 1) * (i + n) div 2; operation sqfun(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: return (-b + (b * b - 4 * a * c)->sqrt()) / (2 * a); operation value() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation values() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inlsts() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inps() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation instr() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation stlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (i)); operation solve() : OclAny pre: true post: true activity: var k : OclAny := null; Sequence{n,k} := values() ; if n = 1 then ( return 0 ) else skip ; k := k - 1; n := n - 1 ; if (((1 + k) * k) div 2->compareTo(n)) < 0 then ( return -1 ) else skip ; var h : int := ("" + ((sqfun(1, -1, 2 * n - k * k - k))))->toInteger() ; if (sumn(h, k)->compareTo(n)) >= 0 then ( return k - h + 1 ) else ( return k - h + 2 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sum(l): return int((l*(l+1))/2) def sume(s,e): if s<=1 : return sum(e) else : return sum(e)-sum(s-1) def minsplitters(k,n): st=int(1) en=int(k) while(stn : st=md+1 else : en=md return k-st+2 n,k=map(int,input().split()) if n==1 : print(0) elif(n<=k): print(1) else : n-=1 k-=1 if sum(k)collect( _x | (OclType["int"])->apply(_x) ) ; if n = 1 then ( execute (0)->display() ) else (if ((n->compareTo(k)) <= 0) then ( execute (1)->display() ) else ( n := n - 1 ; k := k - 1 ; if ((k)->sum()->compareTo(n)) < 0 then ( execute (-1)->display() ) else ( execute (minsplitters(k, n))->display() ) ) ) ; operation sum(l : OclAny) : OclAny pre: true post: true activity: return ("" + (((l * (l + 1)) / 2)))->toInteger(); operation sume(s : OclAny, e : OclAny) : OclAny pre: true post: true activity: if s <= 1 then ( return (e)->sum() ) else ( return (e)->sum() - (s - 1)->sum() ); operation minsplitters(k : OclAny, n : OclAny) : OclAny pre: true post: true activity: var st : int := ("" + ((1)))->toInteger() ; var en : int := ("" + ((k)))->toInteger() ; while ((st->compareTo(en)) < 0) do ( var md : int := ("" + (((st + en) / 2)))->toInteger() ; s := sume(md, k) ; if s = n then ( return k - md + 1 ) else skip ; if (s->compareTo(n)) > 0 then ( st := md + 1 ) else ( en := md )) ; return k - st + 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=list(map(int,input().split())) n=l[0] k=l[1] def solve(n,k): mx=((k*(k+1))//2)-(k-1) if mx=n : return k-1-md else : e=md else : s=md print(solve(n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := l->first() ; var k : OclAny := l[1+1] ; skip ; execute (solve(n, k))->display(); operation solve(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var mx : double := ((k * (k + 1)) div 2) - (k - 1) ; if (mx->compareTo(n)) < 0 then ( return -1 ) else (if mx = n then ( return k - 1 ) else skip) ; if n = 1 then ( return 0 ) else skip ; var s : int := 1 ; var e : double := k - 1 ; var o : int := 1 ; while true do ( var md : int := (s + e) div 2 ; var op1 : int := ((md + 1) * (md + 2)) div 2 ; if (mx - op1->compareTo(n)) < 0 then ( var op2 : int := ((md) * (md + 1)) div 2 ; if (mx - op2->compareTo(n)) >= 0 then ( return k - 1 - md ) else ( e := md ) ) else ( s := md )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def DivisibleBy41(first,second,c,n): digit=[0]*n digit[0]=first digit[1]=second for i in range(2,n): digit[i]=(digit[i-1]*c+digit[i-2])% 10 ans=digit[0] for i in range(1,n): ans=(ans*10+digit[i])% 41 if(ans % 41==0): return True else : return False first=1 second=2 c=1 n=3 if(DivisibleBy41(first,second,c,n)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; first := 1 ; second := 2 ; c := 1 ; n := 3 ; if (DivisibleBy41(first, second, c, n)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); operation DivisibleBy41(first : OclAny, second : OclAny, c : OclAny, n : OclAny) : OclAny pre: true post: true activity: var digit : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; digit->first() := first ; digit[1+1] := second ; for i : Integer.subrange(2, n-1) do ( digit[i+1] := (digit[i - 1+1] * c + digit[i - 2+1]) mod 10) ; var ans : OclAny := digit->first() ; for i : Integer.subrange(1, n-1) do ( ans := (ans * 10 + digit[i+1]) mod 41) ; if (ans mod 41 = 0) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : l=[0,2,5,5,4,5,6,3,7,6] n,m=list(map(int,input().split())) a=list(map(int,input().split())) res='' INF=10**4 dp=[[0,0]for i in range(n+1)] for i in range(n): for j in range(m): if dp[i][1]+l[a[j]]!=i+l[a[j]]or i+l[a[j]]>n : pass else : dp[i+l[a[j]]][0]=max(dp[i][0]+1,dp[i+l[a[j]]][0]) dp[i+l[a[j]]][1]=dp[i][1]+l[a[j]] for i in range(1,n): dp[i][0]=-INF if dp[i][0]==0 else dp[i][0] a.sort(reverse=True) i=n while i>0 : for j in range(m): if i>=l[a[j]]and dp[i-l[a[j]]][0]+1==dp[i][0]: res+=str(a[j]) i-=l[a[j]] break else : pass print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var l : Sequence := Sequence{0}->union(Sequence{2}->union(Sequence{5}->union(Sequence{5}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{3}->union(Sequence{7}->union(Sequence{ 6 }))))))))) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : String := '' ; var INF : double := (10)->pow(4) ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Sequence{0}->union(Sequence{ 0 }))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if dp[i+1][1+1] + l[a[j+1]+1] /= i + l[a[j+1]+1] or (i + l[a[j+1]+1]->compareTo(n)) > 0 then ( skip ) else ( dp[i + l[a[j+1]+1]+1]->first() := Set{dp[i+1]->first() + 1, dp[i + l[a[j+1]+1]+1]->first()}->max() ; dp[i + l[a[j+1]+1]+1][1+1] := dp[i+1][1+1] + l[a[j+1]+1] ))) ; for i : Integer.subrange(1, n-1) do ( dp[i+1]->first() := if dp[i+1]->first() = 0 then -INF else dp[i+1]->first() endif) ; a := a->sort() ; var i : OclAny := n ; while i > 0 do ( for j : Integer.subrange(0, m-1) do ( if (i->compareTo(l[a[j+1]+1])) >= 0 & dp[i - l[a[j+1]+1]+1]->first() + 1 = dp[i+1]->first() then ( res := res + ("" + ((a[j+1]))) ; i := i - l[a[j+1]+1] ; break ) else ( skip ))) ; execute (res)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- string=input() s="" sp=string for i in range(len(string)-1,-1,-1): if string[i]=='a' : s=string[: i+1] sp=string[i+1 :] break smod="".join(list(filter(lambda c : c!='a',s))) diff=len(sp)-len(smod) if((diff<0)or(diff & 1)): print(":(") else : smod+=sp[: diff//2] s+=sp[: diff//2] sp=sp[diff//2 :] print([":(",s][smod==sp]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var string : String := (OclFile["System.in"]).readLine() ; var s : String := "" ; var sp : String := string ; for i : Integer.subrange(-1 + 1, (string)->size() - 1)->reverse() do ( if string[i+1] = 'a' then ( s := string.subrange(1,i + 1) ; sp := string.subrange(i + 1+1) ; break ) else skip) ; var smod : String := StringLib.sumStringsWithSeparator((((s)->select( _x | (lambda c : OclAny in (c /= 'a'))->apply(_x) = true ))), "") ; var diff : double := (sp)->size() - (smod)->size() ; if ((diff < 0) or (MathLib.bitwiseAnd(diff, 1))) then ( execute (":(")->display() ) else ( smod := smod + sp.subrange(1,diff div 2) ; s := s + sp.subrange(1,diff div 2) ; sp := sp.subrange(diff div 2+1) ; execute (Sequence{":("}->union(Sequence{ s })->select(smod = sp))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def max_for_str(a,b): if len(a)>len(b): return a elif len(a)c2 : return a elif c1=0 and not dp[i-match[int(A)]]is None : if dp[i]is None : dp[i]=A+dp[i-match[int(A)]] else : dp[i]=max_for_str(dp[i],A+dp[i-match[int(A)]]) print(dp[N]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var match : Sequence := Sequence{0}->union(Sequence{2}->union(Sequence{5}->union(Sequence{5}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{3}->union(Sequence{7}->union(Sequence{ 6 }))))))))) ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var As : Sequence := (input().split()) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (N + 1)) ; dp->first() := "" ; for i : Integer.subrange(0, N + 1-1) do ( for A : As do ( if i - match[("" + ((A)))->toInteger()+1] >= 0 & not(dp[i - match[("" + ((A)))->toInteger()+1]+1] <>= null) then ( if dp[i+1] <>= null then ( dp[i+1] := A + dp[i - match[("" + ((A)))->toInteger()+1]+1] ) else ( dp[i+1] := max_for_str(dp[i+1], A + dp[i - match[("" + ((A)))->toInteger()+1]+1]) ) ) else skip)) ; execute (dp[N+1])->display(); operation max_for_str(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if ((a)->size()->compareTo((b)->size())) > 0 then ( return a ) else (if ((a)->size()->compareTo((b)->size())) < 0 then ( return b ) else ( for _tuple : Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), b->at(_indx)} ) do (var _indx : int := 1; var c1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c2 : OclAny := _tuple->at(_indx); if (c1->compareTo(c2)) > 0 then ( return a ) else (if (c1->compareTo(c2)) < 0 then ( return b ) else skip)) ; return a ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def is_big(x=[0]*10,y=[0]*10): if sum(x)>sum(y): return True if sum(x)y[i]: return True if y[i]>x[i]: return False return True n,m=map(int,input().split()) a=sorted(list(map(int,input().split()))) d=[0]*8 b=[] L1=[1,7,4,2,3,5,6,9,8] L2=[2,3,4,5,5,5,6,6,7] for i in range(9): if L1[i]in a : d[L2[i]]=L1[i] if L2[i]not in b : b.append(L2[i]) p=[] for i in range(n+1): p.append([-1,0,0,0,0,0,0,0,0,0]) p[0][0]=0 for i in range(1,n+1): for t in b : if i-t<0 or p[i-t][0]==-1 : continue q=p[i-t][:] q[d[t]]+=1 if is_big(q,p[i]): p[i]=q a="" for i in range(10)[: :-1]: a+=str(i)*p[n][i] print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 8) ; var b : Sequence := Sequence{} ; var L1 : Sequence := Sequence{1}->union(Sequence{7}->union(Sequence{4}->union(Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{6}->union(Sequence{9}->union(Sequence{ 8 })))))))) ; var L2 : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{5}->union(Sequence{5}->union(Sequence{6}->union(Sequence{6}->union(Sequence{ 7 })))))))) ; for i : Integer.subrange(0, 9-1) do ( if (a)->includes(L1[i+1]) then ( d[L2[i+1]+1] := L1[i+1] ; if (b)->excludes(L2[i+1]) then ( execute ((L2[i+1]) : b) ) else skip ) else skip) ; var p : Sequence := Sequence{} ; for i : Integer.subrange(0, n + 1-1) do ( execute ((Sequence{-1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))))))))) : p)) ; p->first()->first() := 0 ; for i : Integer.subrange(1, n + 1-1) do ( for t : b do ( if i - t < 0 or p[i - t+1]->first() = -1 then ( continue ) else skip ; var q : OclAny := p[i - t+1] ; q[d[t+1]+1] := q[d[t+1]+1] + 1 ; if is_big(q, p[i+1]) then ( p[i+1] := q ) else skip)) ; a := "" ; for i : range(10)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( a := a + ("" + ((i))) * p[n+1][i+1]) ; execute (a)->display(); operation is_big(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if x->oclIsUndefined() then x := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) else skip; if y->oclIsUndefined() then y := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) else skip; if ((x)->sum()->compareTo((y)->sum())) > 0 then ( return true ) else skip ; if ((x)->sum()->compareTo((y)->sum())) < 0 then ( return false ) else skip ; for i : range(0, 10)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if (x[i+1]->compareTo(y[i+1])) > 0 then ( return true ) else skip ; if (y[i+1]->compareTo(x[i+1])) > 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import sys input=sys.stdin.readline ri=lambda : int(input()) rs=lambda : input().rstrip() ril=lambda : list(map(int,input().split())) rsl=lambda : input().rstrip().split() ris=lambda n :[ri()for _ in range(n)] rss=lambda n :[rs()for _ in range(n)] rils=lambda n :[ril()for _ in range(n)] rsls=lambda n :[rsl()for _ in range(n)] d0={1 : 2,2 : 5,3 : 5,4 : 4,5 : 5,6 : 6,7 : 3,8 : 7,9 : 6,} n,m=ril() ls=ril() d=collections.defaultdict(int) for x in ls : d[d0[x]]=max(x,d[d0[x]]) dp=[(0,0)]*(n+1) for i in range(2,n+1): for count,num in d.items(): if count>i : continue k,l=dp[i-count] if count!=i and l==0 : continue dp[i]=(max(dp[i][0],10*k+num),max(dp[i][1],l+1)) if k!=0 : dp[i]=(max(dp[i][0],num*10**l+k),max(dp[i][1],l+1)) print(dp[n][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var ri : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var rs : Function := lambda $$ : OclAny in (input().rstrip()) ; var ril : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var rsl : Function := lambda $$ : OclAny in (input().rstrip().split()) ; var ris : Function := lambda n : OclAny in (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (ri->apply()))) ; var rss : Function := lambda n : OclAny in (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (rs->apply()))) ; var rils : Function := lambda n : OclAny in (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (ril->apply()))) ; var rsls : Function := lambda n : OclAny in (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (rsl->apply()))) ; var d0 : Map := Map{ 1 |-> 2 }->union(Map{ 2 |-> 5 }->union(Map{ 3 |-> 5 }->union(Map{ 4 |-> 4 }->union(Map{ 5 |-> 5 }->union(Map{ 6 |-> 6 }->union(Map{ 7 |-> 3 }->union(Map{ 8 |-> 7 }->union((dictorsetmaker (test (logical_test (comparison (expr (atom (number (integer 9))))))) : (test (logical_test (comparison (expr (atom (number (integer 6))))))) ,))))))))) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ril->apply() ; var ls : OclAny := ril->apply() ; var d : OclAny := .defaultdict(OclType["int"]) ; for x : ls do ( d[d0[x+1]+1] := Set{x, d[d0[x+1]+1]}->max()) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ Sequence{0, 0} }, (n + 1)) ; for i : Integer.subrange(2, n + 1-1) do ( for _tuple : d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var count : OclAny := _tuple->at(_indx); _indx := _indx + 1; var num : OclAny := _tuple->at(_indx); if (count->compareTo(i)) > 0 then ( continue ) else skip ; var k : OclAny := null; var l : OclAny := null; Sequence{k,l} := dp[i - count+1] ; if count /= i & l = 0 then ( continue ) else skip ; dp[i+1] := Sequence{Set{dp[i+1]->first(), 10 * k + num}->max(), Set{dp[i+1][1+1], l + 1}->max()} ; if k /= 0 then ( dp[i+1] := Sequence{Set{dp[i+1]->first(), num * (10)->pow(l) + k}->max(), Set{dp[i+1][1+1], l + 1}->max()} ) else skip)) ; execute (dp[n+1]->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def is_rectangle(a,b,c): return a**2+b**2==c**2 def is_rhombus(a,b,c): return a==b if __name__=='__main__' : rectangle_count=0 rhombus_count=0 for line in sys.stdin : a,b,c=[int(x)for x in line.strip().split(',')] if is_rectangle(a,b,c): rectangle_count+=1 if is_rhombus(a,b,c): rhombus_count+=1 print('{0}\n{1}'.format(rectangle_count,rhombus_count)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( var rectangle_count : int := 0 ; var rhombus_count : int := 0 ; for line : OclFile["System.in"] do ( Sequence{a,b,c} := line->trim().split(',')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if is_rectangle(a, b, c) then ( rectangle_count := rectangle_count + 1 ) else skip ; if is_rhombus(a, b, c) then ( rhombus_count := rhombus_count + 1 ) else skip) ; execute (StringLib.interpolateStrings('{0} {1}', Sequence{rectangle_count, rhombus_count}))->display() ) else skip; operation is_rectangle(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: return (a)->pow(2) + (b)->pow(2) = (c)->pow(2); operation is_rhombus(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: return a = b; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) INF=10**6 match_dict={1 : 2,2 : 5,3 : 5,4 : 4,5 : 5,6 : 6,7 : 3,8 : 7,9 : 6} a_list=list(map(int,input().split())) a_sorted=sorted(a_list,reverse=True) dp=[0,-INF] for i in range(2,n+1): tmp_dp=[] for a in a_sorted : if i-match_dict[a]<0 : tmp_dp.append(-INF) else : tmp_dp.append(dp[i-match_dict[a]]+1) dp.append(max(tmp_dp)) sum_str='' tmp_i=n while tmp_i>0 : for a in a_sorted : if tmp_i>=match_dict[a]and dp[tmp_i-match_dict[a]]==dp[tmp_i]-1 : sum_str=sum_str+str(a) tmp_i=tmp_i-match_dict[a] break print(int(sum_str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var INF : double := (10)->pow(6) ; var match_dict : Map := Map{ 1 |-> 2 }->union(Map{ 2 |-> 5 }->union(Map{ 3 |-> 5 }->union(Map{ 4 |-> 4 }->union(Map{ 5 |-> 5 }->union(Map{ 6 |-> 6 }->union(Map{ 7 |-> 3 }->union(Map{ 8 |-> 7 }->union(Map{ 9 |-> 6 })))))))) ; var a_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a_sorted : Sequence := a_list->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var dp : Sequence := Sequence{0}->union(Sequence{ -INF }) ; for i : Integer.subrange(2, n + 1-1) do ( var tmp_dp : Sequence := Sequence{} ; for a : a_sorted do ( if i - match_dict[a+1] < 0 then ( execute ((-INF) : tmp_dp) ) else ( execute ((dp[i - match_dict[a+1]+1] + 1) : tmp_dp) )) ; execute (((tmp_dp)->max()) : dp)) ; var sum_str : String := '' ; var tmp_i : OclAny := n ; while tmp_i > 0 do ( for a : a_sorted do ( if (tmp_i->compareTo(match_dict[a+1])) >= 0 & dp[tmp_i - match_dict[a+1]+1] = dp[tmp_i+1] - 1 then ( sum_str := sum_str + ("" + ((a))) ; tmp_i := tmp_i - match_dict[a+1] ; break ) else skip)) ; execute (("" + ((sum_str)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=1 while True : n=int(input()) if not n : break x0,y0=map(float,input().split()) prx,pry=x0,y0 area=0 for _ in range(n-1): x,y=map(float,input().split()) area+=(prx*y-x*pry) prx,pry=x,y area+=(prx*y0-x0*pry) area/=2 print(num,abs(area)) num+=1 input() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := 1 ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(n) then ( break ) else skip ; var x0 : OclAny := null; var y0 : OclAny := null; Sequence{x0,y0} := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; var prx : OclAny := null; var pry : OclAny := null; Sequence{prx,pry} := Sequence{x0,y0} ; var area : int := 0 ; for _anon : Integer.subrange(0, n - 1-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; area := area + (prx * y - x * pry) ; var prx : OclAny := null; var pry : OclAny := null; Sequence{prx,pry} := Sequence{x,y}) ; area := area + (prx * y0 - x0 * pry) ; area := area / 2 ; execute (num)->display() ; num := num + 1 ; input()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def area(p,q,r): a=[x-y for x,y in zip(r,p)] b=[x-y for x,y in zip(q,p)] return(a[0]*b[1]-a[1]*b[0])/2 S=[] while True : string=input() if string=='' : continue elif int(string)==0 : break else : n=int(string) v=[] for _ in range(n): v.append([int(x)for x in input().split()]) s=0 for i in range(1,n-1): s+=area(v[0],v[i],v[i+1]) S.append(round(s,1)) for i,x in enumerate(S): print(i+1,x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var S : Sequence := Sequence{} ; while true do ( var string : String := (OclFile["System.in"]).readLine() ; if string = '' then ( continue ) else (if ("" + ((string)))->toInteger() = 0 then ( break ) else ( var n : int := ("" + ((string)))->toInteger() ; var v : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) : v)) ; var s : int := 0 ; for i : Integer.subrange(1, n - 1-1) do ( s := s + area(v->first(), v[i+1], v[i + 1+1])) ; execute ((MathLib.roundN(s, 1)) : S) ) ) ) ; for _tuple : Integer.subrange(1, (S)->size())->collect( _indx | Sequence{_indx-1, (S)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); execute (i + 1)->display()); operation area(p : OclAny, q : OclAny, r : OclAny) : OclAny pre: true post: true activity: var a : Sequence := Integer.subrange(1, r->size())->collect( _indx | Sequence{r->at(_indx), p->at(_indx)} )->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (x - y)) ; var b : Sequence := Integer.subrange(1, q->size())->collect( _indx | Sequence{q->at(_indx), p->at(_indx)} )->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (x - y)) ; return (a->first() * b[1+1] - a[1+1] * b->first()) / 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def area(px,py,x,y): if py>y : py,y=y,py return py*(x-px)+(x-px)*abs(y-py)/2 count=1 while True : res=0 n=int(input()) if n==0 : break px,py=map(int,input().split()) sx,sy=px,py for _ in range(n-1): x,y=map(int,input().split()) res+=area(px,py,x,y) px,py=x,y res+=area(px,py,sx,sy) print(count,res) count+=1 input() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var count : int := 1 ; while true do ( var res : int := 0 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; Sequence{px,py} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sx : OclAny := null; var sy : OclAny := null; Sequence{sx,sy} := Sequence{px,py} ; for _anon : Integer.subrange(0, n - 1-1) do ( Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; res := res + area(px, py, x, y) ; Sequence{px,py} := Sequence{x,y}) ; res := res + area(px, py, sx, sy) ; execute (count)->display() ; count := count + 1 ; input()); operation area(px : OclAny, py : OclAny, x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (py->compareTo(y)) > 0 then ( Sequence{py,y} := Sequence{y,py} ) else skip ; return py * (x - px) + (x - px) * (y - py)->abs() / 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys if sys.version_info[0]>=3 : raw_input=input cross=lambda a1,b1,a2,b2 : a1*b2-a2*b1 try : T=0 while True : T+=1 n=int(raw_input()) if n==0 : break a=[[float(e)for e in raw_input().split()]for i in range(n)] s=0 t=0 for i in range(n-1): x=cross(a[i][0],a[i][1],a[i+1][0],a[i+1][1]) if x>0 : s+=abs(x)/2 else : t+=abs(x)/2 x=cross(a[n-1][0],a[n-1][1],a[0][0],a[0][1]) if x>0 : s+=abs(x)/2 else : t+=abs(x)/2 print('%d %.1f' %(T,abs(s-t))) raw_input() except EOFError : pass ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if (trailer . (name version_info) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) >= 3 then ( var raw_input : OclAny := input ) else skip ; var cross : Function := lambda a1 : OclAny, b1 : OclAny, a2 : OclAny, b2 : OclAny in (a1 * b2 - a2 * b1) ; try ( var T : int := 0 ; while true do ( T := T + 1 ; var n : int := ("" + ((raw_input())))->toInteger() ; if n = 0 then ( break ) else skip ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (raw_input().split()->select(e | true)->collect(e | (("" + ((e)))->toReal())))) ; var s : int := 0 ; var t : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( var x : OclAny := cross->apply(a[i+1]->first(), a[i+1][1+1], a[i + 1+1]->first(), a[i + 1+1][1+1]) ; if x > 0 then ( s := s + (x)->abs() / 2 ) else ( t := t + (x)->abs() / 2 )) ; x := cross->apply(a[n - 1+1]->first(), a[n - 1+1][1+1], a->first()->first(), a->first()[1+1]) ; if x > 0 then ( s := s + (x)->abs() / 2 ) else ( t := t + (x)->abs() / 2 ) ; execute (StringLib.format('%d %.1f',Sequence{T, (s - t)->abs()}))->display() ; raw_input())) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt pass))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from decimal import Decimal,ROUND_HALF_UP def calc_area(pp): n,s=len(pp),0 for i in range(n): s+=(pp[i].real-pp[(i+1)% n].real)*(pp[i].imag+pp[(i+1)% n].imag) return abs(s)/2 cno=0 while True : n=int(input()) if n==0 : break pp=[complex(*map(int,input().split()))for i in range(n)] input() cno+=1 print(cno,Decimal(str(calc_area(pp))).quantize(Decimal('0.1'),rounding=ROUND_HALF_UP)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var cno : int := 0 ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; pp := Integer.subrange(0, n-1)->select(i | true)->collect(i | (complex((argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))))) ; input() ; cno := cno + 1 ; execute (cno)->display()); operation calc_area(pp : OclAny) : OclAny pre: true post: true activity: var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := Sequence{(pp)->size(),0} ; for i : Integer.subrange(0, n-1) do ( s := s + (pp[i+1].real - pp[(i + 1) mod n+1].real) * (pp[i+1].imag + pp[(i + 1) mod n+1].imag)) ; return (s)->abs() / 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=input() removed=t.replace('a','') ds=removed[int(len(removed)/2):] s=t[: len(t)-len(ds)] if len(removed)% 2==1 or s.replace('a','')!=ds : print(':(') else : print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : String := (OclFile["System.in"]).readLine() ; var removed : String := t.replace('a', '') ; var ds : OclAny := removed.subrange(("" + (((removed)->size() / 2)))->toInteger()+1) ; var s : OclAny := t.subrange(1,(t)->size() - (ds)->size()) ; if (removed)->size() mod 2 = 1 or s.replace('a', '') /= ds then ( execute (':(')->display() ) else ( execute (s)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,X=map(int,input().split(" ")) l_list=input().split() count=1 d=0 for i in range(N): da=d+int(l_list[i]) d=da if da<=X : count+=1 else : print(count) break if count==int(N)+1 : print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var X : OclAny := null; Sequence{N,X} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var l_list : OclAny := input().split() ; var count : int := 1 ; var d : int := 0 ; for i : Integer.subrange(0, N-1) do ( var da : int := d + ("" + ((l_list[i+1])))->toInteger() ; d := da ; if (da->compareTo(X)) <= 0 then ( count := count + 1 ) else ( execute (count)->display() ; break ) ; if count = ("" + ((N)))->toInteger() + 1 then ( execute (count)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys ; import string ; sys.setrecursionlimit(20000) import copy import itertools from functools import lru_cache PPP=1000000007 n,x=map(int,input().split()) l=[int(x)for x in input().split()] import re def doit(): p=0 res=1 for lx in l : p+=lx if x

collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; skip ; skip ; try ( execute (doit())->display()) catch (e : ProgramException) do ( execute ("e")->display()) ; operation doit() : OclAny pre: true post: true activity: var p : int := 0 ; var res : int := 1 ; for lx : l do ( p := p + lx ; if (x->compareTo(p)) < 0 then ( break ) else skip ; res := res + 1) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=list(map(int,input().split())) lList=list(map(int,input().split())) coordinate=0 count=1 for l in lList : coordinate+=l if coordinate<=x : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lList : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var coordinate : int := 0 ; var count : int := 1 ; for l : lList do ( coordinate := coordinate + l ; if (coordinate->compareTo(x)) <= 0 then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,x=map(int,input().split()) l=list(map(int,input().split())) ans=1 max=0 for i in range(len(l)): max+=l[i] if max<=x : ans+=1 print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 1 ; var max : int := 0 ; for i : Integer.subrange(0, (l)->size()-1) do ( max := max + l[i+1] ; if (max->compareTo(x)) <= 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_input(): while True : try : yield ''.join(input()) except EOFError : break N=list(get_input()) ans1=0 ans2=0 for l in range(len(N)): a,b,c=[int(i)for i in N[l].split(",")] if a*a+b*b==c*c : ans1+=1 if a==b : ans2+=1 print(ans1) print(ans2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : Sequence := (OclIterator.newOclIterator_Function(lambda _i : int in self.get_input(_i))) ; var ans1 : int := 0 ; var ans2 : int := 0 ; for l : Integer.subrange(0, (N)->size()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := N[l+1].split(",")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if a * a + b * b = c * c then ( ans1 := ans1 + 1 ) else skip ; if a = b then ( ans2 := ans2 + 1 ) else skip) ; execute (ans1)->display() ; execute (ans2)->display(); operation get_input(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; while true do ( try ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return StringLib.sumStringsWithSeparator(((OclFile["System.in"]).readLine()), '')) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=map(int,input().split()) L=[int(i)for i in input().split()] cnt=0 Sum=[0 for i in range(len(L)+1)] for i in range(len(L)): Sum[i+1]=Sum[i]+L[i] for i in range(len(Sum)): if Sum[i]>x : break else : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var L : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var cnt : int := 0 ; var Sum : Sequence := Integer.subrange(0, (L)->size() + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, (L)->size()-1) do ( Sum[i + 1+1] := Sum[i+1] + L[i+1]) ; for i : Integer.subrange(0, (Sum)->size()-1) do ( if (Sum[i+1]->compareTo(x)) > 0 then ( break ) else ( cnt := cnt + 1 )) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=list(map(int,input().split())) c=b[0] for j in b : if j>c : c=j m=0 for k in b : m+=(c-k) print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : OclAny := b->first() ; for j : b do ( if (j->compareTo(c)) > 0 then ( c := j ) else skip) ; var m : int := 0 ; for k : b do ( m := m + (c - k)) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) max_burles=max(a) total=0 for i in a : total+=abs(max_burles-i) print(total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var max_burles : OclAny := (a)->max() ; var total : int := 0 ; for i : a do ( total := total + (max_burles - i)->abs()) ; execute (total)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) max_burles=max(a) total=0 for i in a : total+=abs(max_burles-i) print(total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var max_burles : OclAny := (a)->max() ; var total : int := 0 ; for i : a do ( total := total + (max_burles - i)->abs()) ; execute (total)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) maxb=max(a) print(sum(map(lambda e : abs(maxb-e),a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var maxb : OclAny := (a)->max() ; execute (((a)->collect( _x | (lambda e : OclAny in ((maxb - e)->abs()))->apply(_x) ))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) K=max(map(a.count,a)) i=0 while True : if a.count(a[i])=0 and a[j]!=A[i]: j-=1 if jtoInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var K : OclAny := ((a)->collect( _x | (a.count)->apply(_x) ))->max() ; var i : int := 0 ; while true do ( if (a->count(a[i+1])->compareTo(K)) < 0 then ( var C : int := a->count(a[i+1]) ; n := n - C ; var Val : OclAny := a[i+1] ; for k : Integer.subrange(0, C-1) do ( execute ((Val) /: a)) ) else ( i := i + 1 ) ; if i = n then ( break ) else skip) ; var MinI : int := 1000001 ; var ID : int := -1 ; var A : Sequence := (Set{}->union((a))) ; for i : Integer.subrange(0, (A)->size()-1) do ( var j : double := n - 1 ; while j >= 0 & a[j+1] /= A[i+1] do ( j := j - 1) ; if (j->compareTo(MinI)) < 0 then ( MinI := j ; ID := A[i+1] ) else skip) ; execute (ID)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) maxb=max(a) print(sum(map(lambda e : abs(maxb-e),a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var maxb : OclAny := (a)->max() ; execute (((a)->collect( _x | (lambda e : OclAny in ((maxb - e)->abs()))->apply(_x) ))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for j in range(int(input())): a,b=map(int,input().split()) k=0 k=(23-a)*60+(60-b) print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for j : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : int := 0 ; k := (23 - a) * 60 + (60 - b) ; execute (k)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): h,m=map(int,input().split()) out=1440-h*60-m print(out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var out : double := 1440 - h * 60 - m ; execute (out)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): h,m=map(int,input().split()) t,d=0,0 d=24*60 t=h*60+m print(d-t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : OclAny := null; Sequence{t,d} := Sequence{0,0} ; var d : int := 24 * 60 ; t := h * 60 + m ; execute (d - t)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): h,m=map(int,input().split()) print(1440-h*60-m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (1440 - h * 60 - m)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def maxValue(a,n): first=defaultdict(lambda : 0) last=defaultdict(lambda : 0) pr=[None]*n pr[0]=a[0] for i in range(1,n): pr[i]=pr[i-1]+a[i] if first[a[i]]==0 : first[a[i]]=i last[a[i]]=i ans=0 for i in range(0,n): start=first[a[i]] end=last[a[i]] ans=max(ans,pr[end]-pr[start-1]) return ans if __name__=="__main__" : arr=[1,3,5,2,4,18,2,3] n=len(arr) print(maxValue(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var arr : Sequence := Sequence{1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{2}->union(Sequence{4}->union(Sequence{18}->union(Sequence{2}->union(Sequence{ 3 }))))))) ; n := (arr)->size() ; execute (maxValue(arr, n))->display() ) else skip; operation maxValue(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var first : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; var last : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; var pr : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; pr->first() := a->first() ; for i : Integer.subrange(1, n-1) do ( pr[i+1] := pr[i - 1+1] + a[i+1] ; if first[a[i+1]+1] = 0 then ( first[a[i+1]+1] := i ) else skip ; last[a[i+1]+1] := i) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var start : OclAny := first[a[i+1]+1] ; var end : OclAny := last[a[i+1]+1] ; ans := Set{ans, pr[end+1] - pr[start - 1+1]}->max()) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) k=0 for i in range(a): b,c=map(int,input().split()) k=(23-b)*60+(60-c) print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := 0 ; for i : Integer.subrange(0, a-1) do ( var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; k := (23 - b) * 60 + (60 - c) ; execute (k)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bar(a,b,c): x=(a+b+c)/3 return x while True : n=int(input()) if n==0 : break for i in range(n): m,e,j=map(int,input().split()) y=(m+e)/2 x=bar(m,e,j) if(m==100 or e==100 or j==100)or y>=90 or x>=80 : print("A") elif x>=70 : print("B") elif x>=50 : if m>=80 or e>=80 : print("B") else : print("C") else : print("C") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; for i : Integer.subrange(0, n-1) do ( var m : OclAny := null; var e : OclAny := null; var j : OclAny := null; Sequence{m,e,j} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var y : double := (m + e) / 2 ; x := bar(m, e, j) ; if (m = 100 or e = 100 or j = 100) or y >= 90 or x >= 80 then ( execute ("A")->display() ) else (if x >= 70 then ( execute ("B")->display() ) else (if x >= 50 then ( if m >= 80 or e >= 80 then ( execute ("B")->display() ) else ( execute ("C")->display() ) ) else ( execute ("C")->display() ) ) ) )); operation bar(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: var x : double := (a + b + c) / 3 ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,fractions PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") def grade(m,e,j): if m+e>=180 or m+e+j>=240 or max(e,j,m)==100 : return 'A' elif m+e+j>=210 : return 'B' elif m+e+j>=150 and max(m,e)>=80 : return 'B' return 'C' while True : n=int(input()) if n==0 : break for _ in range(n): m,e,j=[int(__)for __ in input().split()] print(grade(m,e,j)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; for _anon : Integer.subrange(0, n-1) do ( Sequence{m,e,j} := input().split()->select(__ | true)->collect(__ | (("" + ((__)))->toInteger())) ; execute (grade(m, e, j))->display())); operation grade(m : OclAny, e : OclAny, j : OclAny) : OclAny pre: true post: true activity: if m + e >= 180 or m + e + j >= 240 or Set{e, j, m}->max() = 100 then ( return 'A' ) else (if m + e + j >= 210 then ( return 'B' ) else (if m + e + j >= 150 & Set{m, e}->max() >= 80 then ( return 'B' ) else skip ) ) ; return 'C'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def a1(li): if 100 in li : return 1 else : return 0 def a2(li): if(li[0]+li[1])/2>=90 : return 1 else : return 0 def a3(li): if sum(li)/3>=80 : return 1 else : return 0 def isA(li): if a1(li)or a2(li)or a3(li): return 1 else : 0 def b1(li): if sum(li)/3>=70 : return 1 else : return 0 def b2(li): if sum(li)/3>=50 and(li[0]>=80 or li[1]>=80): return 1 else : return 0 def isB(li): if b1(li)or b2(li): return 1 else : 0 def isX(li): if isA(li): return 'A' elif isB(li): return 'B' else : return 'C' while True : N=int(input()) if N==0 : break for _ in range(N): l=list(map(int,input().split())) print(isX(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; for _anon : Integer.subrange(0, N-1) do ( var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (isX(l))->display())); operation a1(li : OclAny) : OclAny pre: true post: true activity: if (li)->includes(100) then ( return 1 ) else ( return 0 ); operation a2(li : OclAny) : OclAny pre: true post: true activity: if (li->first() + li[1+1]) / 2 >= 90 then ( return 1 ) else ( return 0 ); operation a3(li : OclAny) : OclAny pre: true post: true activity: if (li)->sum() / 3 >= 80 then ( return 1 ) else ( return 0 ); operation isA(li : OclAny) : OclAny pre: true post: true activity: if a1(li) or a2(li) or a3(li) then ( return 1 ) else ( ); operation b1(li : OclAny) : OclAny pre: true post: true activity: if (li)->sum() / 3 >= 70 then ( return 1 ) else ( return 0 ); operation b2(li : OclAny) : OclAny pre: true post: true activity: if (li)->sum() / 3 >= 50 & (li->first() >= 80 or li[1+1] >= 80) then ( return 1 ) else ( return 0 ); operation isB(li : OclAny) : OclAny pre: true post: true activity: if b1(li) or b2(li) then ( return 1 ) else ( ); operation isX(li : OclAny) : OclAny pre: true post: true activity: if isA(li) then ( return 'A' ) else (if isB(li) then ( return 'B' ) else ( return 'C' ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from collections import Counter n=int(input()) s=input()[:-1].split() w=Counter(s) s=s[: :-1] c,a=-1,0 for i in w : if w[i]==max(w.values()): if s.index(i)>c : a=i c=s.index(i) print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := input()->front().split() ; var w : OclAny := Counter(s) ; s := s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var c : OclAny := null; var a : OclAny := null; Sequence{c,a} := Sequence{-1,0} ; for i : w do ( if w[i+1] = (w.values())->max() then ( if (s->indexOf(i) - 1->compareTo(c)) > 0 then ( var a : OclAny := i ; var c : int := s->indexOf(i) - 1 ) else skip ) else skip) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : num=int(input()) if num==0 : break else : for _ in range(num): a,b,c=map(int,input().split()) if a==100 or b==100 or c==100 or(a+b)/2>=90 or(a+b+c)/3>=80 : print("A") elif(a+b+c)/3>=70 or(a+b+c)/3>=50 and a>=80 or(a+b+c)/3>=50 and b>=80 : print("B") else : print("C") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if num = 0 then ( break ) else ( for _anon : Integer.subrange(0, num-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 100 or b = 100 or c = 100 or (a + b) / 2 >= 90 or (a + b + c) / 3 >= 80 then ( execute ("A")->display() ) else (if (a + b + c) / 3 >= 70 or (a + b + c) / 3 >= 50 & a >= 80 or (a + b + c) / 3 >= 50 & b >= 80 then ( execute ("B")->display() ) else ( execute ("C")->display() ) ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while(True): n=int(input()) if not n : break for _ in range(n): m,e,j=map(int,input().split()) if 100 in[m,e,j]: print("A"); continue elif(m+e)/2>=90 : print("A"); continue elif(m+e+j)/3>=80 : print("A"); continue elif(m+e+j)/3>=70 : print("B"); continue elif(m+e+j)/3>=50 and(m>=80 or e>=80): print("B"); continue else : print("C"); continue ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while (true) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(n) then ( break ) else skip ; for _anon : Integer.subrange(0, n-1) do ( var m : OclAny := null; var e : OclAny := null; var j : OclAny := null; Sequence{m,e,j} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (Sequence{m}->union(Sequence{e}->union(Sequence{ j })))->includes(100) then ( execute ("A")->display(); continue ) else (if (m + e) / 2 >= 90 then ( execute ("A")->display(); continue ) else (if (m + e + j) / 3 >= 80 then ( execute ("A")->display(); continue ) else (if (m + e + j) / 3 >= 70 then ( execute ("B")->display(); continue ) else (if (m + e + j) / 3 >= 50 & (m >= 80 or e >= 80) then ( execute ("B")->display(); continue ) else ( execute ("C")->display(); continue ) ) ) ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n_computers,k_participants=map(int,input().split()) kps=list(map(int,input().split())) print(min(sorted(kps,reverse=True)[: k_participants])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n_computers : OclAny := null; var k_participants : OclAny := null; Sequence{n_computers,k_participants} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var kps : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((sorted(kps, (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))).subrange(1,k_participants))->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) print(sorted(map(int,input().split()))[n-k]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (sorted((input().split())->collect( _x | (OclType["int"])->apply(_x) ))[n - k+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) print(sorted(map(int,input().split()))[n-k]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (sorted((input().split())->collect( _x | (OclType["int"])->apply(_x) ))[n - k+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=list(map(int,input().split())) arr=sorted(list(map(int,input().split()))) print(arr[n-k]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; execute (arr[n - k+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getPairs(a,n): visited1=set() un=[0]*n un[n-1]=0 count=0 for i in range(n-1,-1,-1): if(a[i]in visited1): un[i-1]=count else : count+=1 un[i-1]=count visited1.add(a[i]) visited2=set() answer=0 for i in range(n-1): if(a[i]in visited2): continue answer+=un[i] visited2.add(a[i]) return answer a=[1,2,2,4,2,5,3,5] n=len(a) print(getPairs(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{4}->union(Sequence{2}->union(Sequence{5}->union(Sequence{3}->union(Sequence{ 5 }))))))) ; n := (a)->size() ; execute (getPairs(a, n))->display(); operation getPairs(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var visited1 : Set := Set{}->union(()) ; var un : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; un[n - 1+1] := 0 ; var count : int := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if ((visited1)->includes(a[i+1])) then ( un[i - 1+1] := count ) else ( count := count + 1 ; un[i - 1+1] := count ) ; execute ((a[i+1]) : visited1)) ; var visited2 : Set := Set{}->union(()) ; var answer : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if ((visited2)->includes(a[i+1])) then ( continue ) else skip ; answer := answer + un[i+1] ; execute ((a[i+1]) : visited2)) ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) d=list(map(int,input().split())) d.sort() print(d[-b]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; d := d->sort() ; execute (d->reverse()->at(-(-b)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def balance_is_realizable(imbalance,x,balance): if imbalance>=0 : return(x-balance)>=0 else : return(x-balance)<=0 def main(): t=int(input()) for i in range(t): n,x=tuple(int(o)for o in input().split()) string=input() balances_to_occurrences=defaultdict(int) imbalance=0 s=0 for char in string : if char=='0' : imbalance+=1 else : imbalance-=1 balances_to_occurrences[imbalance]+=1 if imbalance==0 : if(x in balances_to_occurrences or x==0): print(-1) else : print(0) else : for balance,occurrences in balances_to_occurrences.items(): if(x-balance)% imbalance==0 and balance_is_realizable(imbalance,x,balance): s+=occurrences if x==0 : s+=1 print(s) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation balance_is_realizable(imbalance : OclAny, x : OclAny, balance : OclAny) : OclAny pre: true post: true activity: if imbalance >= 0 then ( return (x - balance) >= 0 ) else ( return (x - balance) <= 0 ); operation main() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; Sequence{n,x} := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name o)))))))) ))))))) (comp_for for (exprlist (expr (atom (name o)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ; var string : String := (OclFile["System.in"]).readLine() ; var balances_to_occurrences : OclAny := defaultdict(OclType["int"]) ; imbalance := 0 ; var s : int := 0 ; for char : string->characters() do ( if char = '0' then ( imbalance := imbalance + 1 ) else ( imbalance := imbalance - 1 ) ; balances_to_occurrences[imbalance+1] := balances_to_occurrences[imbalance+1] + 1) ; if imbalance = 0 then ( if ((balances_to_occurrences)->includes(x) or x = 0) then ( execute (-1)->display() ) else ( execute (0)->display() ) ) else ( for _tuple : balances_to_occurrences->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var balance : OclAny := _tuple->at(_indx); _indx := _indx + 1; var occurrences : OclAny := _tuple->at(_indx); if (x - balance) mod imbalance = 0 & balance_is_realizable(imbalance, x, balance) then ( s := s + occurrences ) else skip) ; if x = 0 then ( s := s + 1 ) else skip ; execute (s)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* zzz=int(input()) for zz in range(zzz): n,x=map(int,input().split()) s=[int(i)for i in input()] a=[] bal=0 for i in range(n): if s[i]>0 : bal-=1 else : bal+=1 a.append(bal) if x>0 and a[-1]<0 and max(a)0 and min(a)>x : print(0) elif a[-1]!=0 : ans=0 for i in range(n): if(x-a[i])% a[-1]==0 and(x-a[i])//a[-1]>=0 : ans+=1 if x==0 : ans+=1 print(ans) else : if x in a : print(-1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var zzz : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for zz : Integer.subrange(0, zzz-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := (OclFile["System.in"]).readLine()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a : Sequence := Sequence{} ; var bal : int := 0 ; for i : Integer.subrange(0, n-1) do ( if s[i+1] > 0 then ( bal := bal - 1 ) else ( bal := bal + 1 ) ; execute ((bal) : a)) ; if x > 0 & a->last() < 0 & ((a)->max()->compareTo(x)) < 0 then ( execute (0)->display() ) else (if x < 0 & a->last() > 0 & ((a)->min()->compareTo(x)) > 0 then ( execute (0)->display() ) else (if a->last() /= 0 then ( var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (x - a[i+1]) mod a->last() = 0 & (x - a[i+1]) div a->last() >= 0 then ( ans := ans + 1 ) else skip) ; if x = 0 then ( ans := ans + 1 ) else skip ; execute (ans)->display() ) else ( if (a)->includes(x) then ( execute (-1)->display() ) else ( execute (0)->display() ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections input() counter=collections.Counter() most=0 for a in input().split(): a=int(a) counter[a]+=1 if counter[a]>most : most=counter[a] photo=a print(photo) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; input() ; var counter : OclAny := .Counter() ; var most : int := 0 ; for a : input().split() do ( var a : int := ("" + ((a)))->toInteger() ; counter[a+1] := counter[a+1] + 1 ; if (counter[a+1]->compareTo(most)) > 0 then ( most := counter[a+1] ; var photo : int := a ) else skip) ; execute (photo)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x,y=[int(x)for x in input().split()] s=input() b,z,ans,flag=s.count('0')-s.count('1'),0,0,False if y==0 : ans=1 for elem in s : z+=(elem=='0')-(elem=='1') if b==0 and z==y : flag=True print(-1) break if z==y or((y-z)*b>0 and abs((y-z))% abs(b)==0): ans+=1 if not flag : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var s : String := (OclFile["System.in"]).readLine() ; var b : OclAny := null; var z : OclAny := null; var ans : OclAny := null; var flag : OclAny := null; Sequence{b,z,ans,flag} := Sequence{s->count('0') - s->count('1'),0,0,false} ; if y = 0 then ( var ans : int := 1 ) else skip ; for elem : s->characters() do ( z := z + (elem = '0') - (elem = '1') ; if b = 0 & z = y then ( var flag : boolean := true ; execute (-1)->display() ; break ) else skip ; if z = y or ((y - z) * b > 0 & ((y - z))->abs() mod (b)->abs() = 0) then ( ans := ans + 1 ) else skip) ; if not(flag) then ( execute (ans)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,x=map(int,input().split()) string=input() num=[0] for i in string : if i=='1' : num.append(num[-1]-1) else : num.append(num[-1]+1) ans=0 isInfi=False for i in num[:-1]: if num[n]==0 : if i==x : isInfi=True elif abs(x-i)% abs(num[n])==0 : if(x-i)/(num[n])>=0 : ans+=1 if isInfi : print(-1) else : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var string : String := (OclFile["System.in"]).readLine() ; var num : Sequence := Sequence{ 0 } ; for i : string->characters() do ( if i = '1' then ( execute ((num->last() - 1) : num) ) else ( execute ((num->last() + 1) : num) )) ; var ans : int := 0 ; var isInfi : boolean := false ; for i : num->front() do ( if num[n+1] = 0 then ( if i = x then ( isInfi := true ) else skip ) else (if (x - i)->abs() mod (num[n+1])->abs() = 0 then ( if (x - i) / (num[n+1]) >= 0 then ( ans := ans + 1 ) else skip ) else skip)) ; if isInfi then ( execute (-1)->display() ) else ( execute (ans)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def str_balance(s): return s.count("0")-s.count("1") def val(c): if c=="1" : return-1 return 1 def arr_balance(s): l=[0] for c in s : l.append(l[-1]+val(c)) return l[1 :] INFINITE=-1 def calc_prefix_number(s,n,x): l=arr_balance(s) steps=l[-1] if steps==0 : if x in l : return INFINITE return 0 cnt=0 if x==0 : cnt+=1 for cell in l : if(x-cell)% steps==0 and(x-cell)*steps>=0 : cnt+=1 return cnt testcases=int(input()) for _ in range(testcases): n,x=[int(p)for p in input().split()] s=input() print(calc_prefix_number(s,n,x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var INFINITE : int := -1 ; skip ; var testcases : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, testcases-1) do ( Sequence{n,x} := input().split()->select(p | true)->collect(p | (("" + ((p)))->toInteger())) ; s := (OclFile["System.in"]).readLine() ; execute (calc_prefix_number(s, n, x))->display()); operation str_balance(s : OclAny) : OclAny pre: true post: true activity: return s->count("0") - s->count("1"); operation val(c : OclAny) : OclAny pre: true post: true activity: if c = "1" then ( return -1 ) else skip ; return 1; operation arr_balance(s : OclAny) : OclAny pre: true post: true activity: var l : Sequence := Sequence{ 0 } ; for c : s do ( execute ((l->last() + val(c)) : l)) ; return l->tail(); operation calc_prefix_number(s : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: l := arr_balance(s) ; var steps : OclAny := l->last() ; if steps = 0 then ( if (l)->includes(x) then ( return INFINITE ) else skip ; return 0 ) else skip ; var cnt : int := 0 ; if x = 0 then ( cnt := cnt + 1 ) else skip ; for cell : l do ( if (x - cell) mod steps = 0 & (x - cell) * steps >= 0 then ( cnt := cnt + 1 ) else skip) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def search(arr,l,h,key): if l>h : return-1 mid=(l+h)//2 if arr[mid]==key : return mid if arr[l]<=arr[mid]: if key>=arr[l]and key<=arr[mid]: return search(arr,l,mid-1,key) return search(arr,mid+1,h,key) if key>=arr[mid]and key<=arr[h]: return search(a,mid+1,h,key) return search(arr,l,mid-1,key) arr=[4,5,6,7,8,9,1,2,3] key=6 i=search(arr,0,len(arr)-1,key) if i!=-1 : print("Index: %d" % i) else : print("Key not found") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })))))))) ; key := 6 ; var i : OclAny := search(arr, 0, (arr)->size() - 1, key) ; if i /= -1 then ( execute (StringLib.format("Index: %d",i))->display() ) else ( execute ("Key not found")->display() ); operation search(arr : OclAny, l : OclAny, h : OclAny, key : OclAny) : OclAny pre: true post: true activity: if (l->compareTo(h)) > 0 then ( return -1 ) else skip ; var mid : int := (l + h) div 2 ; if arr[mid+1] = key then ( return mid ) else skip ; if (arr[l+1]->compareTo(arr[mid+1])) <= 0 then ( if (key->compareTo(arr[l+1])) >= 0 & (key->compareTo(arr[mid+1])) <= 0 then ( return search(arr, l, mid - 1, key) ) else skip ; return search(arr, mid + 1, h, key) ) else skip ; if (key->compareTo(arr[mid+1])) >= 0 & (key->compareTo(arr[h+1])) <= 0 then ( return search(a, mid + 1, h, key) ) else skip ; return search(arr, l, mid - 1, key); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fillWithFreq(arr,n): temp=[0 for i in range(n)] for i in range(n): temp[arr[i]]+=1 for i in range(n): arr[i]=temp[i] arr=[5,2,3,4,5,5,4,5,6,7] n=len(arr) fillWithFreq(arr,n) for i in range(n): print(arr[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{5}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{5}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 7 }))))))))) ; n := (arr)->size() ; fillWithFreq(arr, n) ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); operation fillWithFreq(arr : OclAny, n : OclAny) pre: true post: true activity: var temp : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( temp[arr[i+1]+1] := temp[arr[i+1]+1] + 1) ; for i : Integer.subrange(0, n-1) do ( arr[i+1] := temp[i+1]); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def convert_To_Len_th_base(n,arr,Len,L): for i in range(L): print(arr[n % Len],end="") n//=Len print() def printf(arr,Len,L): for i in range(pow(Len,L)): convert_To_Len_th_base(i,arr,Len,L) arr=[1,2,3] Len=len(arr) L=2 printf(arr,Len,L) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; Len := (arr)->size() ; L := 2 ; printf(arr, Len, L); operation convert_To_Len_th_base(n : OclAny, arr : OclAny, Len : OclAny, L : OclAny) pre: true post: true activity: for i : Integer.subrange(0, L-1) do ( execute (arr[n mod Len+1])->display() ; n := n div Len) ; execute (->display(); operation printf(arr : OclAny, Len : OclAny, L : OclAny) pre: true post: true activity: for i : Integer.subrange(0, (Len)->pow(L)-1) do ( convert_To_Len_th_base(i, arr, Len, L)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) d=dict() maxi=0 maxv=0 for _ in range(m): a,b=map(int,input().split()) if a-1 in d : d[a-1]+=1 else : d[a-1]=1 if b-1 in d : d[b-1]+=1 else : d[b-1]=1 if d[a-1]>maxv : maxv=d[a-1] maxi=a-1 if d[b-1]>maxv : maxv=d[b-1] maxi=b-1 if m+1==n : if maxv==m : print('star topology') elif maxv==2 : print('bus topology') else : print('unknown topology') elif m==n : if maxv==2 : print('ring topology') else : print('unknown topology') else : print('unknown topology') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Map := (arguments ( )) ; var maxi : int := 0 ; var maxv : int := 0 ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (d)->includes(a - 1) then ( d[a - 1+1] := d[a - 1+1] + 1 ) else ( d[a - 1+1] := 1 ) ; if (d)->includes(b - 1) then ( d[b - 1+1] := d[b - 1+1] + 1 ) else ( d[b - 1+1] := 1 ) ; if (d[a - 1+1]->compareTo(maxv)) > 0 then ( maxv := d[a - 1+1] ; maxi := a - 1 ) else skip ; if (d[b - 1+1]->compareTo(maxv)) > 0 then ( maxv := d[b - 1+1] ; maxi := b - 1 ) else skip) ; if m + 1 = n then ( if maxv = m then ( execute ('star topology')->display() ) else (if maxv = 2 then ( execute ('bus topology')->display() ) else ( execute ('unknown topology')->display() ) ) ) else (if m = n then ( if maxv = 2 then ( execute ('ring topology')->display() ) else ( execute ('unknown topology')->display() ) ) else ( execute ('unknown topology')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isTwoAlter(s): for i in range(len(s)-2): if(s[i]!=s[i+2]): return False if(s[0]==s[1]): return False return True if __name__=="__main__" : str="ABAB" if(isTwoAlter(str)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var OclType["String"] : String := "ABAB" ; if (isTwoAlter(OclType["String"])) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isTwoAlter(s : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, (s)->size() - 2-1) do ( if (s[i+1] /= s[i + 2+1]) then ( return false ) else skip) ; if (s->first() = s[1+1]) then ( return false ) else skip ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import string def getRes(connections,n,m): bus=0 for i in range(1,n+1): if connections[i]==1 : bus+=1 elif connections[i]==n-1 and m==n-1 : print("star topology") return elif connections[i]!=2 : print("unknown topology") return if bus==2 : print("bus topology") else : print("ring topology") return if __name__=="__main__" : [n,m]=[int(i)for i in sys.stdin.readline().split()] connections=[0 for x in range(n+1)] for i in range(m): [x,y]=[int(i)for i in sys.stdin.readline().split()] connections[x]+=1 connections[y]+=1 getRes(connections,n,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( ; Sequence{n}->union(Sequence{ m }) := sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; connections := Integer.subrange(0, n + 1-1)->select(x | true)->collect(x | (0)) ; for i : Integer.subrange(0, m-1) do (suite) ) else skip ; Sequence{x}->union(Sequence{ y }) := sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation getRes(connections : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: var bus : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( if connections[i+1] = 1 then ( bus := bus + 1 ) else (if connections[i+1] = n - 1 & m = n - 1 then ( execute ("star topology")->display() ; return ) else (if connections[i+1] /= 2 then ( execute ("unknown topology")->display() ; return ) else skip ) ) ) ; if bus = 2 then ( execute ("bus topology")->display() ) else ( execute ("ring topology")->display() ) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import string def getRes(connections,n,m): bus=0 for i in range(1,n+1): if connections[i]==1 : bus+=1 elif connections[i]==n-1 and m==n-1 : print("star topology") return elif connections[i]!=2 : print("unknown topology") return if bus==2 : print("bus topology") else : print("ring topology") return if __name__=="__main__" : [n,m]=[int(i)for i in sys.stdin.readline().split()] connections=[0 for x in range(n+1)] for i in range(m): [x,y]=[int(i)for i in sys.stdin.readline().split()] connections[x]+=1 connections[y]+=1 getRes(connections,n,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( ; Sequence{n}->union(Sequence{ m }) := sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; connections := Integer.subrange(0, n + 1-1)->select(x | true)->collect(x | (0)) ; for i : Integer.subrange(0, m-1) do (suite) ) else skip ; Sequence{x}->union(Sequence{ y }) := sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation getRes(connections : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: var bus : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( if connections[i+1] = 1 then ( bus := bus + 1 ) else (if connections[i+1] = n - 1 & m = n - 1 then ( execute ("star topology")->display() ; return ) else (if connections[i+1] /= 2 then ( execute ("unknown topology")->display() ; return ) else skip ) ) ) ; if bus = 2 then ( execute ("bus topology")->display() ) else ( execute ("ring topology")->display() ) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n=int(input()) a=input().split() for i in range(n): a[i]=int(a[i]) counts=Counter(a) candidates=[] likes=0 for key,value in counts.items(): if value is max(counts.values()): candidates.append(key) likes=value candidates_dictionary={} if len(candidates)==1 : print(candidates[0]) else : for candidate in candidates : for i in range(likes-1): a.remove(candidate) for candidate in candidates : candidates_dictionary[candidate]=a.index(candidate) for candidate,last_liked in candidates_dictionary.items(): if last_liked==min(candidates_dictionary.values()): print(candidate) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := input().split() ; for i : Integer.subrange(0, n-1) do ( a[i+1] := ("" + ((a[i+1])))->toInteger()) ; var counts : OclAny := Counter(a) ; var candidates : Sequence := Sequence{} ; var likes : int := 0 ; for _tuple : counts->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); if value <>= (counts.values())->max() then ( execute ((key) : candidates) ; likes := value ) else skip) ; var candidates_dictionary : OclAny := Set{} ; if (candidates)->size() = 1 then ( execute (candidates->first())->display() ) else ( for candidate : candidates do ( for i : Integer.subrange(0, likes - 1-1) do ( execute ((candidate) /: a))) ; for candidate : candidates do ( candidates_dictionary[candidate+1] := a->indexOf(candidate) - 1) ; for _tuple : candidates_dictionary->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var candidate : OclAny := _tuple->at(_indx); _indx := _indx + 1; var last_liked : OclAny := _tuple->at(_indx); if last_liked = (candidates_dictionary.values())->min() then ( execute (candidate)->display() ) else skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,m=map(int,input().split()) g=[[]for _ in range(n)] for _ in range(m): x,y=map(int,input().split()) g[x-1].append(y-1) g[y-1].append(x-1) def ring(n,m,g): if all(len(l)==2 for l in g): return True else : return False def star(n,m,g): return any(len(l)==m for l in g) def bus(n,m,g): for node in range(3): if len(g[node])==2 : break else : return False exit=0 visited=[0]*n visited[node]=1 nodes=[node] while nodes : cur=nodes.pop() count=0 for new_node in g[cur]: if not visited[new_node]: visited[new_node]=1 nodes.append(new_node) count+=1 if count==0 : exit+=1 return exit==2 if m==n-1 and bus(n,m,g): print("bus topology") elif m==n and ring(n,m,g): print("ring topology") elif m==n-1 and star(n,m,g): print("star topology") else : print("unknown topology") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var g : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ))))) ; skip ; skip ; skip ; if m = n - 1 & bus(n, m, g) then ( execute ("bus topology")->display() ) else (if m = n & ring(n, m, g) then ( execute ("ring topology")->display() ) else (if m = n - 1 & star(n, m, g) then ( execute ("star topology")->display() ) else ( execute ("unknown topology")->display() ) ) ) ; operation ring(n : OclAny, m : OclAny, g : OclAny) : OclAny pre: true post: true activity: if ((argument (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)))))))) ))))) == (comparison (expr (atom (number (integer 2)))))))) (comp_for for (exprlist (expr (atom (name l)))) in (logical_test (comparison (expr (atom (name g))))))))->forAll( _x | _x = true ) then ( return true ) else ( return false ); operation star(n : OclAny, m : OclAny, g : OclAny) : OclAny pre: true post: true activity: return ((argument (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)))))))) ))))) == (comparison (expr (atom (name m))))))) (comp_for for (exprlist (expr (atom (name l)))) in (logical_test (comparison (expr (atom (name g))))))))->exists( _x | _x = true ); operation bus(n : OclAny, m : OclAny, g : OclAny) : OclAny pre: true post: true activity: (compound_stmt for (exprlist (expr (atom (name node)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 3))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name node)))))))) ])))))))) ))))) == (comparison (expr (atom (number (integer 2)))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name False))))))))))))) ; var exit : int := 0 ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; visited[node+1] := 1 ; var nodes : Sequence := Sequence{ node } ; while nodes do ( var cur : OclAny := nodes->last() ; nodes := nodes->front() ; var count : int := 0 ; for new_node : g[cur+1] do ( if not(visited[new_node+1]) then ( visited[new_node+1] := 1 ; execute ((new_node) : nodes) ; count := count + 1 ) else skip) ; if count = 0 then ( exit := exit + 1 ) else skip) ; return exit = 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def max_gcd(n,p): count=0 ; gcd=1 ; while(p % 2==0): p>>=1 ; count=count+1 ; if(count>0): gcd=gcd*pow(2,count//n); for i in range(3,(int)(math.sqrt(p)),2): count=0 ; while(p % i==0): count=count+1 ; p=p//i ; if(count>0): gcd=gcd*pow(i,count//n); if(p>2): gcd=gcd*pow(p,1//n); return gcd ; n=3 ; p=80 ; print(max_gcd(n,p)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 3; ; p := 80; ; execute (max_gcd(n, p))->display();; operation max_gcd(n : OclAny, p : OclAny) pre: true post: true activity: var count : int := 0; ; var gcd : int := 1; ; while (p mod 2 = 0) do ( p := p div (2->pow(1)); ; count := count + 1;) ; if (count > 0) then ( gcd := gcd * (2)->pow(count div n); ) else skip ; for i : Integer.subrange(3, (OclType["int"])((p)->sqrt())-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( count := 0; ; while (p mod i = 0) do ( count := count + 1; ; p := p div i;) ; if (count > 0) then ( gcd := gcd * (i)->pow(count div n); ) else skip) ; if (p > 2) then ( gcd := gcd * (p)->pow(1 div n); ) else skip ; return gcd;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil,floor def maxArea(perimeter): length=int(ceil(perimeter/4)) breadth=int(floor(perimeter/4)) return length*breadth if __name__=='__main__' : n=38 print("Maximum Area=",maxArea(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var n : int := 38 ; execute ("Maximum Area=")->display() ) else skip; operation maxArea(perimeter : OclAny) : OclAny pre: true post: true activity: var length : int := ("" + ((ceil(perimeter / 4))))->toInteger() ; var breadth : int := ("" + ((floor(perimeter / 4))))->toInteger() ; return length * breadth; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solution(n,arr): ans=0 num_of_ones=0 num_of_twos=0 for i in range(n): if arr[i]==1 : num_of_ones+=1 else : num_of_twos+=1 min_val=min(num_of_ones,num_of_twos) diff=num_of_ones-min_val if diff>=3 : ans=diff//3 return min_val+ans n=int(input()) arr=[int(x)for x in input().strip().split(" ")] print(solution(n,arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; arr := input()->trim().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (solution(n, arr))->display(); operation solution(n : OclAny, arr : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; var num_of_ones : int := 0 ; var num_of_twos : int := 0 ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] = 1 then ( num_of_ones := num_of_ones + 1 ) else ( num_of_twos := num_of_twos + 1 )) ; var min_val : OclAny := Set{num_of_ones, num_of_twos}->min() ; var diff : double := num_of_ones - min_val ; if diff >= 3 then ( ans := diff div 3 ) else skip ; return min_val + ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=list(map(int,input().split())) if 2 not in b : print(sum(b)//3) elif 1 not in b : print("0") else : if b.count(1)>=b.count(2): print(b.count(2)+(b.count(1)-b.count(2))//3) else : print(b.count(1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (b)->excludes(2) then ( execute ((b)->sum() div 3)->display() ) else (if (b)->excludes(1) then ( execute ("0")->display() ) else ( if (b->count(1)->compareTo(b->count(2))) >= 0 then ( execute (b->count(2) + (b->count(1) - b->count(2)) div 3)->display() ) else ( execute (b->count(1))->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) n1=0 n2=0 ans=0 for i in l : if i==1 : n1+=1 elif i==2 : n2+=1 mi=min(n1,n2) if n1>mi : mi+=(n1-mi)//3 print(mi) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n1 : int := 0 ; var n2 : int := 0 ; var ans : int := 0 ; for i : l do ( if i = 1 then ( n1 := n1 + 1 ) else (if i = 2 then ( n2 := n2 + 1 ) else skip)) ; var mi : OclAny := Set{n1, n2}->min() ; if (n1->compareTo(mi)) > 0 then ( mi := mi + (n1 - mi) div 3 ) else skip ; execute (mi)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() a=[0,0] for x in input().split(): a[int(x)-1]+=1 c=min(a) print(c+(a[0]-c)//3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var a : Sequence := Sequence{0}->union(Sequence{ 0 }) ; for x : input().split() do ( a[("" + ((x)))->toInteger() - 1+1] := a[("" + ((x)))->toInteger() - 1+1] + 1) ; var c : OclAny := (a)->min() ; execute (c + (a->first() - c) div 3)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import* from decimal import* def _input(): return map(int,input().split()) def _list(): return list(map(int,input().split())) def solves(): n=int(input()) lst=sorted(_list()) a=0 b=0 for i in range(n): if(lst[i]==1): a+=1 else : b+=1 if(a<=b): print(a) else : print(b+(a-b)//3) t=1 for _ in range(0,t): solves() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solves()); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation _list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation solves() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := _list()->sort() ; var a : int := 0 ; var b : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (lst[i+1] = 1) then ( a := a + 1 ) else ( b := b + 1 )) ; if ((a->compareTo(b)) <= 0) then ( execute (a)->display() ) else ( execute (b + (a - b) div 3)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findRemainder(n): l=n % 10 while(n>=10): n//=10 f=n remainder=f % l print(remainder) n=5223 findRemainder(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5223 ; findRemainder(n); operation findRemainder(n : OclAny) pre: true post: true activity: var l : int := n mod 10 ; while (n >= 10) do ( n := n div 10) ; var f : OclAny := n ; var remainder : int := f mod l ; execute (remainder)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def max2(x,y): return x if x>y else y def min2(x,y): return x if xcollect( _x | (OclType["int"])->apply(_x) ) ; var H : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var dp : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, N - K + 1-1)->select(_anon | true)->collect(_anon | ((10)->pow(9) * N)))) ; dp->first()->first() := 0 ; for _tuple : Integer.subrange(1, (H->tail(), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->size())->collect( _indx | Sequence{_indx-1, (H->tail(), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var h : OclAny := _tuple->at(_indx); for k : Integer.subrange(1, min2(i + 1, N - K + 1)-1) do ( dp[i+1][k+1] := ((argument (test (logical_test (comparison (expr (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name k))) - (expr (atom (number (integer 1)))))))))) ]))) + (expr (atom (name max2)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name h))) - (expr (atom (name H)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))))) )))))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))->min())) ; execute (((argument (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))) (comp_for for (exprlist (expr (atom (name d)))) in (logical_test (comparison (expr (atom (name dp))))))))->min())->display(); operation max2(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return if (x->compareTo(y)) > 0 then x else y endif; operation min2(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return if (x->compareTo(y)) < 0 then x else y endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() n=int(input()) A=[0]*1000001 idx=1 for i in list(map(int,input().split())): A[i]+=1 if A[i]>A[idx]: idx=i print(idx) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 1000001) ; var idx : int := 1 ; for i : ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) do ( A[i+1] := A[i+1] + 1 ; if (A[i+1]->compareTo(A[idx+1])) > 0 then ( idx := i ) else skip) ; execute (idx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from heapq import heappush,heappop import sys import math import bisect import random def LI(): return[int(x)for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return[list(x)for x in sys.stdin.readline().split()] def S(): res=list(sys.stdin.readline()) if res[-1]=="\n" : return res[:-1] return res def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] sys.setrecursionlimit(1000000) mod=1000000007 def solve(): n,k=LI() h=LI() h.insert(0,0) dp=[[float("inf")]*(n+1)for i in range(n+1)] dp[0][0]=0 for i in range(n): ni=i+1 hi=h[ni] for s in range(n): ns=s+1 for j in range(ni): hj=h[j] nd=dp[j][s]+max(0,hi-hj) if ndselect(x | true)->collect(x | (("" + ((x)))->toInteger())); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | ((x))); operation S() : OclAny pre: true post: true activity: var res : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if res->last() = "\n" then ( return res->front() ) else skip ; return res; operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation solve() pre: true post: true activity: var k : OclAny := null; Sequence{n,k} := LI() ; var h : OclAny := LI() ; h := h.insertAt(0+1, 0) ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ ("" + (("inf")))->toReal() }, (n + 1)))) ; dp->first()->first() := 0 ; for i : Integer.subrange(0, n-1) do ( var ni : OclAny := i + 1 ; var hi : OclAny := h[ni+1] ; for s : Integer.subrange(0, n-1) do ( var ns : OclAny := s + 1 ; for j : Integer.subrange(0, ni-1) do ( var hj : OclAny := h[j+1] ; var nd : OclAny := dp[j+1][s+1] + Set{0, hi - hj}->max() ; if (nd->compareTo(dp[ni+1][ns+1])) < 0 then ( dp[ni+1][ns+1] := nd ) else skip))) ; var ans : OclAny := (Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (dp[i+1][n - k+1])))->min() ; execute (ans)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin ni=lambda : int(ns()) na=lambda : list(map(int,stdin.readline().split())) ns=lambda : stdin.readline().rstrip() n,k=na() h=na() ys=h[:]+[0] ys.sort() ys2=[] for v in ys : if len(ys2)>0 and ys2[-1]==v : continue ys2.append(v) ys=ys2 m=len(ys) dp=[[999999999999999999]*m for _ in range(k+1)] dp[0][0]=0 for v in h : ndp=[[999999999999999999]*m for _ in range(k+1)] for i in range(k+1): plus=99999999999999999 for j in range(m): plus=min(plus+(ys[j]-ys[j-1]if j>0 else 0),dp[i][j]) if ys[j]==v : ndp[i][j]=min(ndp[i][j],plus) elif i+1<=k : ndp[i+1][j]=min(ndp[i+1][j],plus) plus=99999999999999999 for j in range(m-1,-1,-1): plus=min(plus,dp[i][j]) if ys[j]==v : ndp[i][j]=min(ndp[i][j],plus) elif i+1<=k : ndp[i+1][j]=min(ndp[i+1][j],plus) dp=ndp ans=min(min(row)for row in dp) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stdin : OclFile := OclFile["System.in"] ; var ni : Function := lambda $$ : OclAny in (("" + ((ns())))->toInteger()) ; var na : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ns : Function := lambda $$ : OclAny in (stdin.readLine().rstrip()) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := na->apply() ; var h : OclAny := na->apply() ; var ys : Sequence := h->union(Sequence{ 0 }) ; ys := ys->sort() ; var ys2 : Sequence := Sequence{} ; for v : ys do ( if (ys2)->size() > 0 & ys2->last() = v then ( continue ) else skip ; execute ((v) : ys2)) ; ys := ys2 ; var m : int := (ys)->size() ; var dp : Sequence := Integer.subrange(0, k + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 999999999999999999 }, m))) ; dp->first()->first() := 0 ; for v : h do ( var ndp : Sequence := Integer.subrange(0, k + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 999999999999999999 }, m))) ; for i : Integer.subrange(0, k + 1-1) do ( var plus : int := 99999999999999999 ; for j : Integer.subrange(0, m-1) do ( plus := Set{plus + (if j > 0 then ys[j+1] - ys[j - 1+1] else 0 endif), dp[i+1][j+1]}->min() ; if ys[j+1] = v then ( ndp[i+1][j+1] := Set{ndp[i+1][j+1], plus}->min() ) else (if (i + 1->compareTo(k)) <= 0 then ( ndp[i + 1+1][j+1] := Set{ndp[i + 1+1][j+1], plus}->min() ) else skip)) ; plus := 99999999999999999 ; for j : Integer.subrange(-1 + 1, m - 1)->reverse() do ( plus := Set{plus, dp[i+1][j+1]}->min() ; if ys[j+1] = v then ( ndp[i+1][j+1] := Set{ndp[i+1][j+1], plus}->min() ) else (if (i + 1->compareTo(k)) <= 0 then ( ndp[i + 1+1][j+1] := Set{ndp[i + 1+1][j+1], plus}->min() ) else skip))) ; dp := ndp) ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name row)))))))) ))))))) (comp_for for (exprlist (expr (atom (name row)))) in (logical_test (comparison (expr (atom (name dp))))))))->min() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from collections import defaultdict sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod=10**9+7 def I(): return int(input()) def II(): return map(int,input().split()) def III(): return list(map(int,input().split())) def Line(N,num): if N<=0 : return[[]]*num elif num==1 : return[I()for _ in range(N)] else : read_all=[tuple(II())for _ in range(N)] return map(list,zip(*read_all)) N,K=II() H=III() if N==K : print(0) exit() dp=[[float('inf')]*(N-K+1)for _ in range(N)] for x in range(N): for y in range(N-K+1): if x+1pow(7)) ; skip ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; var K : OclAny := null; Sequence{N,K} := II() ; var H : OclAny := III() ; if N = K then ( execute (0)->display() ; exit() ) else skip ; var dp : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ ("" + (('inf')))->toReal() }, (N - K + 1)))) ; for x : Integer.subrange(0, N-1) do ( for y : Integer.subrange(0, N - K + 1-1) do ( if (x + 1->compareTo(y)) < 0 then ( continue ) else (if y = 0 then ( dp[x+1][y+1] := ("" + (('inf')))->toReal() ) else (if y = 1 then ( dp[x+1][y+1] := H[x+1] ) else ( var val : double := ("" + (('inf')))->toReal() ; for i : Integer.subrange(0, x-1) do ( var now : OclAny := dp[i+1][y - 1+1] + Set{0, H[x+1] - H[i+1]}->max() ; if (now->compareTo(val)) < 0 then ( val := now ) else skip) ; dp[x+1][y+1] := val ) ) ) )) ; var ans : double := ("" + (('inf')))->toReal() ; for i : Integer.subrange(0, N-1) do ( if (dp[i+1][N - K+1]->compareTo(ans)) < 0 then ( ans := dp[i+1][N - K+1] ) else skip) ; execute (ans)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation II() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation III() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation Line(N : OclAny, num : OclAny) : OclAny pre: true post: true activity: if N <= 0 then ( return MatrixLib.elementwiseMult(Sequence{ Sequence{} }, num) ) else (if num = 1 then ( return Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (I())) ) else ( var read_all : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | ((II()))) ; return (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name read_all)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name read_all)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name read_all)))))))`third->at(_indx)} ))->collect( _x | (OclType["Sequence"])->apply(_x) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): INF=float('inf') def max2(x,y): return x if x>=y else y N,K=map(int,input().split()) Hs=[0]+list(map(int,input().split())) if N==K : return 0 dp=[INF]*(N+1) dp[0]=0 for j in range(1,N-K+1): dp2=[INF]*(N+1) for i,H in enumerate(Hs[j :],j): for k in range(j-1,i): dp2[i]=min(dp2[i],dp[k]+max2(0,H-Hs[k])) dp=dp2 return min(dp) ans=solve() print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var ans : OclAny := solve() ; execute (ans)->display(); operation solve() : OclAny pre: true post: true activity: var INF : double := ("" + (('inf')))->toReal() ; skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var Hs : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; if N = K then ( return 0 ) else skip ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, (N + 1)) ; dp->first() := 0 ; for j : Integer.subrange(1, N - K + 1-1) do ( var dp2 : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, (N + 1)) ; for _tuple : Integer.subrange(1, (Hs.subrange(j+1), j)->size())->collect( _indx | Sequence{_indx-1, (Hs.subrange(j+1), j)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var H : OclAny := _tuple->at(_indx); for k : Integer.subrange(j - 1, i-1) do ( dp2[i+1] := Set{dp2[i+1], dp[k+1] + max2(0, H - Hs[k+1])}->min())) ; dp := dp2) ; return (dp)->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect ans=0 N=int(input()) A=[int(i)for i in input().split()] B=[int(i)for i in input().split()] C=[int(i)for i in input().split()] A.sort() B.sort() C.sort() for b in B : a=bisect.bisect_left(A,b) c=N-bisect.bisect_right(C,b) ans+=a*c print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var ans : int := 0 ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var B : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var C : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; A := A->sort() ; B := B->sort() ; C := C->sort() ; for b : B do ( var a : OclAny := bisect.bisect_left(A, b) ; var c : double := N - bisect.bisect_right(C, b) ; ans := ans + a * c) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N=int(input()) parts=[[int(a),0]for a in input().split()] parts+=[[int(b),1]for b in input().split()] parts+=[[int(c),2]for c in input().split()] parts=sorted(parts,key=lambda x : x[0],reverse=True) countC=0 countBC=0 ans=0 for i in range(len(parts)): if parts[i][1]==0 : ans+=countBC elif parts[i][1]==1 : countBC+=countC else : countC+=1 return ans if __name__=='__main__' : print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( execute (main())->display() ) else skip; operation main() : OclAny pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var parts : Sequence := input().split()->select(a | true)->collect(a | (Sequence{("" + ((a)))->toInteger()}->union(Sequence{ 0 }))) ; parts := parts + input().split()->select(b | true)->collect(b | (Sequence{("" + ((b)))->toInteger()}->union(Sequence{ 1 }))) ; parts := parts + input().split()->select(c | true)->collect(c | (Sequence{("" + ((c)))->toInteger()}->union(Sequence{ 2 }))) ; parts := parts->sortedBy($x | (lambda x : OclAny in (x->first()))->apply($x)) ; var countC : int := 0 ; var countBC : int := 0 ; var ans : int := 0 ; for i : Integer.subrange(0, (parts)->size()-1) do ( if parts[i+1][1+1] = 0 then ( ans := ans + countBC ) else (if parts[i+1][1+1] = 1 then ( countBC := countBC + countC ) else ( countC := countC + 1 ) ) ) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_right N=int(input()) A=list(map(int,input().split())) B=list(map(int,input().split())) C=list(map(int,input().split())) B=sorted(B) C=sorted(C) b_list={N : 0} for i in range(N-1,-1,-1): j=bisect_right(C,B[i]) b_list[i]=N-j+b_list[i+1] m=0 for i in range(N): j=bisect_right(B,A[i]) m+=b_list[j] print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var B : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var C : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; B := B->sort() ; C := C->sort() ; var b_list : Map := Map{ N |-> 0 } ; for i : Integer.subrange(-1 + 1, N - 1)->reverse() do ( var j : OclAny := bisect_right(C, B[i+1]) ; b_list[i+1] := N - j + b_list[i + 1+1]) ; var m : int := 0 ; for i : Integer.subrange(0, N-1) do ( j := bisect_right(B, A[i+1]) ; m := m + b_list[j+1]) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import*; N,A,B,C=[sorted(map(int,input().split()))for _ in[0]*4]; print(sum(bisect_left(A,x)*(N[0]-bisect_right(C,x))for x in B)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{N,A,B,C} := MatrixLib.elementwiseMult(Sequence{ 0 }, 4)->select(_anon | true)->collect(_anon | ((input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort())); execute (((argument (test (logical_test (comparison (expr (expr (atom (name bisect_left)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A))))))) , (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name N)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) - (expr (atom (name bisect_right)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name C))))))) , (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name B))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect cnt=0 n=int(input()) a=sorted(list(map(int,input().split()))) b=sorted(list(map(int,input().split()))) c=sorted(list(map(int,input().split()))) ab=[0]*n bc=[0]*n for i in range(n): bc[i]=bisect.bisect_left(b,c[i]-0.5) ab[i]=bisect.bisect_left(a,b[i]-0.5) for i in range(1,n): ab[i]+=ab[i-1] for i in range(n): if bc[i]!=0 : cnt+=ab[bc[i]-1] print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var cnt : int := 0 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var ab : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var bc : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( bc[i+1] := bisect.bisect_left(b, c[i+1] - 0.5) ; ab[i+1] := bisect.bisect_left(a, b[i+1] - 0.5)) ; for i : Integer.subrange(1, n-1) do ( ab[i+1] := ab[i+1] + ab[i - 1+1]) ; for i : Integer.subrange(0, n-1) do ( if bc[i+1] /= 0 then ( cnt := cnt + ab[bc[i+1] - 1+1] ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- name=['Sheldon','Leonard','Penny','Rajesh','Howard'] n=int(input()) p=0 if n<=5 : print(name[n % 5-1]) else : while 5*(2**p)<=n : n-=(5*(2**p)) p+=1 res=n//(2**p) print(name[res]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var name : Sequence := Sequence{'Sheldon'}->union(Sequence{'Leonard'}->union(Sequence{'Penny'}->union(Sequence{'Rajesh'}->union(Sequence{ 'Howard' })))) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : int := 0 ; if n <= 5 then ( execute (name[n mod 5 - 1+1])->display() ) else ( while (5 * ((2)->pow(p))->compareTo(n)) <= 0 do ( n := n - (5 * ((2)->pow(p))) ; p := p + 1) ; var res : int := n div ((2)->pow(p)) ; execute (name[res+1])->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) sa=input().count("-") sa=min([n-sa,sa]) ss="" for _ in range(m): a,b=map(int,input().split()) diff=(b-a) ss+=(diff % 2 and diff<=sa<<1)and "1\n" or "0\n" print(ss) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sa : OclAny := input()->count("-") ; sa := (Sequence{n - sa}->union(Sequence{ sa }))->min() ; var ss : String := "" ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var diff : double := (b - a) ; ss := ss + (diff mod 2 & (diff->compareTo(sa * (2->pow(1)))) <= 0) & "1\n" or "0\n") ; execute (ss)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkIfStartsWithCapital(string): if(string[0]>='A' and string[0]<='Z'): return 1 ; else : return 0 ; def check(string): if(checkIfStartsWithCapital(string)): print("Accepted"); else : print("Not Accepted"); if __name__=="__main__" : string="GeeksforGeeks" ; check(string); string="geeksforgeeks" ; check(string); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( string := "GeeksforGeeks"; ; check(string); ; string := "geeksforgeeks"; ; check(string); ) else skip; operation checkIfStartsWithCapital(string : OclAny) pre: true post: true activity: if (string->first() >= 'A' & string->first() <= 'Z') then ( return 1; ) else ( return 0; ); operation check(string : OclAny) pre: true post: true activity: if (checkIfStartsWithCapital(string)) then ( execute ("Accepted")->display(); ) else ( execute ("Not Accepted")->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculate_angle(n,i,j,k): x,y=0,0 if(idisplay(); operation calculate_angle(n : OclAny, i : OclAny, j : OclAny, k : OclAny) : OclAny pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{0,0} ; if ((i->compareTo(j)) < 0) then ( var x : double := j - i ) else ( x := j + n - i ) ; if ((j->compareTo(k)) < 0) then ( var y : double := k - j ) else ( y := k + n - j ) ; var ang1 : int := (180 * x) div n ; var ang2 : int := (180 * y) div n ; var ans : double := 180 - ang1 - ang2 ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(arr,n): k=len(arr) mp=[False for i in range(n+2)] for i in range(k): mp[arr[i]]=True leftSegment=arr[0]-1 for i in range(1,k): leftSegment=max(leftSegment,arr[i]-arr[i-1]-1) rightSegment=n-arr[k-1] maxSegment=max(leftSegment,rightSegment); tim=0 if(maxSegment & 1): tim=(maxSegment//2)+1 else : tim=maxSegment//2 return tim N=5 arr=[1,4] print(solve(arr,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 5 ; arr := Sequence{1}->union(Sequence{ 4 }) ; execute (solve(arr, N))->display(); operation solve(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var k : int := (arr)->size() ; var mp : Sequence := Integer.subrange(0, n + 2-1)->select(i | true)->collect(i | (false)) ; for i : Integer.subrange(0, k-1) do ( mp[arr[i+1]+1] := true) ; var leftSegment : double := arr->first() - 1 ; for i : Integer.subrange(1, k-1) do ( leftSegment := Set{leftSegment, arr[i+1] - arr[i - 1+1] - 1}->max()) ; var rightSegment : double := n - arr[k - 1+1] ; var maxSegment : OclAny := Set{leftSegment, rightSegment}->max(); ; var tim : int := 0 ; if (MathLib.bitwiseAnd(maxSegment, 1)) then ( tim := (maxSegment div 2) + 1 ) else ( tim := maxSegment div 2 ) ; return tim; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findCombinationsUtil(arr,index,n,red_num): s=set() sum=0 if(red_num<0): return if(red_num==0): for i in range(index): s.add(arr[i]) for itr in s : sum=sum+(itr) if(sum==n): for i in s : print(i,end="") print("\n",end="") return if(index==0): prev=1 else : prev=arr[index-1] for k in range(prev,n+1,1): arr[index]=k findCombinationsUtil(arr,index+1,n,red_num-k) def findCombinations(n): a=[0 for i in range(n+1)] findCombinationsUtil(a,0,n,n) if __name__=='__main__' : n=7 findCombinations(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( n := 7 ; findCombinations(n) ) else skip; operation findCombinationsUtil(arr : OclAny, index : OclAny, n : OclAny, red_num : OclAny) pre: true post: true activity: var s : Set := Set{}->union(()) ; var sum : int := 0 ; if (red_num < 0) then ( return ) else skip ; if (red_num = 0) then ( for i : Integer.subrange(0, index-1) do ( execute ((arr[i+1]) : s)) ; for itr : s do ( sum := sum + (itr)) ; if (sum = n) then ( for i : s do ( execute (i)->display()) ; execute ("\n")->display() ; return ) else skip ) else skip ; if (index = 0) then ( var prev : int := 1 ) else ( prev := arr[index - 1+1] ) ; for k : Integer.subrange(prev, n + 1-1)->select( $x | ($x - prev) mod 1 = 0 ) do ( arr[index+1] := k ; findCombinationsUtil(arr, index + 1, n, red_num - k)); operation findCombinations(n : OclAny) pre: true post: true activity: var a : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; findCombinationsUtil(a, 0, n, n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def diff(List): List.sort() if List[0]<0 : print("NO") else : print("YES") L={0} Set=set(List) Q=Set while not Q==set(): for x in Set : for y in Set : l={abs(x-y)} L.update(l) L.remove(0) Q=L.difference(Set) Set.update(L) print(len(Set)) for x in Set : print(x,end=' ') print() N=int(input()) for x in range(N): n=input() S=[int(x)for x in input().split()] diff(S) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for x : Integer.subrange(0, N-1) do ( var n : String := (OclFile["System.in"]).readLine() ; var S : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; diff(S)); operation diff(List : OclAny) pre: true post: true activity: List := List->sort() ; if List->first() < 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; var L : Set := Set{ 0 } ; var Set : Set := Set{}->union((List)) ; var Q : OclAny := Set ; while not(Q = Set{}->union(())) do ( for x : Set do ( for y : Set do ( var l : Set := Set{ (x - y)->abs() } ; execute ((l) <: L))) ; execute ((0) /: L) ; Q := L - (Set) ; execute ((L) <: Set)) ; execute ((Set)->size())->display() ; for x : Set do ( execute (x)->display()) ; execute (->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: print(*(['nO']if min(map(int,s.split()))<0 else['yES\n101\n',*range(101)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom 'nO')))))) ])))) if (logical_test (comparison (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name s)) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))) < (comparison (expr (atom (number (integer 0))))))) else (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom 'yES 101 '))))) , (star_expr * (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 101))))))))) )))))) ]))))))) ))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) l=[int(j)for j in input().split()] l1=[] if min(l)<0 : print("NO") else : print("YES") print(max(l)+1) for j in range(max(l)+1): l1.append(j) print(*l1,sep=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; var l1 : Sequence := Sequence{} ; if (l)->min() < 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; execute ((l)->max() + 1)->display() ; for j : Integer.subrange(0, (l)->max() + 1-1) do ( execute ((j) : l1)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name l1))))))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import* from math import* from decimal import* from collections import* import numbers from operator import index import sys def _input(): return map(int,input().split()) def _list(): return list(map(int,input().split())) def _int(): return int(input()) def solves(): n=int(input()) lst=_list() for i in range(n): if lst[i]<0 : print("NO") return print("YES") ans=[i for i in range(max(lst)+1)] print(len(ans)) print(*ans) t=1 t=int(input()) for _ in range(0,t): solves() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var t : int := 1 ; t := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( solves()); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation _list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation _int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation solves() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : OclAny := _list() ; for i : Integer.subrange(0, n-1) do ( if lst[i+1] < 0 then ( execute ("NO")->display() ; return ) else skip) ; execute ("YES")->display() ; var ans : Sequence := Integer.subrange(0, (lst)->max() + 1-1)->select(i | true)->collect(i | (i)) ; execute ((ans)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) if min(a)<0 : print("NO") continue print("YES") mx=max(a)+1 print(mx) print(" ".join(map(str,range(0,mx)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (a)->min() < 0 then ( execute ("NO")->display() ; continue ) else skip ; execute ("YES")->display() ; var mx : OclAny := (a)->max() + 1 ; execute (mx)->display() ; execute (StringLib.sumStringsWithSeparator(((Integer.subrange(0, mx-1))->collect( _x | (OclType["String"])->apply(_x) )), " "))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def KthMinValAfterMconcatenate(A,N,M,K): V=[] for i in range(0,M): for j in range(0,N): V.append(A[j]) V.sort() return V[K-1] if __name__=="__main__" : A=[3,1,2] M,K=3,4 N=len(A) print(KthMinValAfterMconcatenate(A,N,M,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( A := Sequence{3}->union(Sequence{1}->union(Sequence{ 2 })) ; Sequence{M,K} := Sequence{3,4} ; N := (A)->size() ; execute (KthMinValAfterMconcatenate(A, N, M, K))->display() ) else skip; operation KthMinValAfterMconcatenate(A : OclAny, N : OclAny, M : OclAny, K : OclAny) : OclAny pre: true post: true activity: var V : Sequence := Sequence{} ; for i : Integer.subrange(0, M-1) do ( for j : Integer.subrange(0, N-1) do ( execute ((A[j+1]) : V))) ; V := V->sort() ; return V[K - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import log2 n,m=[int(i)for i in input().split()] queue=[[n,0]] maxn=10e4 red=lambda x : x*2 blue=lambda x : x-1 memoized_values=set() while queue : current_n,buttons_pressed=queue.pop(0) if current_n==m : print(buttons_pressed) break if blue(current_n)not in memoized_values and blue(current_n)>0 : memoized_values.add(blue(current_n)) queue.append([blue(current_n),buttons_pressed+1]) if red(current_n)not in memoized_values and red(current_n)<=maxn : memoized_values.add(red(current_n)) queue.append([red(current_n),buttons_pressed+1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var queue : Sequence := Sequence{ Sequence{n}->union(Sequence{ 0 }) } ; var maxn : double := ("10e4")->toReal() ; var red : Function := lambda x : OclAny in (x * 2) ; var blue : Function := lambda x : OclAny in (x - 1) ; var memoized_values : Set := Set{}->union(()) ; while queue do ( var current_n : OclAny := null; var buttons_pressed : OclAny := null; Sequence{current_n,buttons_pressed} := queue->at(0`firstArg+1) ; queue := queue->excludingAt(0+1) ; if current_n = m then ( execute (buttons_pressed)->display() ; break ) else skip ; if (memoized_values)->excludes(blue->apply(current_n)) & blue->apply(current_n) > 0 then ( execute ((blue->apply(current_n)) : memoized_values) ; execute ((Sequence{blue->apply(current_n)}->union(Sequence{ buttons_pressed + 1 })) : queue) ) else skip ; if (memoized_values)->excludes(red->apply(current_n)) & (red->apply(current_n)->compareTo(maxn)) <= 0 then ( execute ((red->apply(current_n)) : memoized_values) ; execute ((Sequence{red->apply(current_n)}->union(Sequence{ buttons_pressed + 1 })) : queue) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getAvg(prev_avg,x,n): return((prev_avg*n+x)/(n+1)); def streamAvg(arr,n): avg=0 ; for i in range(n): avg=getAvg(avg,arr[i],i); print("Average of ",i+1," numbers is ",avg); arr=[10,20,30,40,50,60]; n=len(arr); streamAvg(arr,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{10}->union(Sequence{20}->union(Sequence{30}->union(Sequence{40}->union(Sequence{50}->union(Sequence{ 60 }))))); ; n := (arr)->size(); ; streamAvg(arr, n);; operation getAvg(prev_avg : OclAny, x : OclAny, n : OclAny) pre: true post: true activity: return ((prev_avg * n + x) / (n + 1));; operation streamAvg(arr : OclAny, n : OclAny) pre: true post: true activity: var avg : int := 0; ; for i : Integer.subrange(0, n-1) do ( avg := getAvg(avg, arr[i+1], i); ; execute ("Average of ")->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect cnt=0 while 1 : outs=[] outn=[] n=int(input()) if n==0 : break elif cnt>0 : print() names=[] scores=[] for i in range(n): line=list(input().split()) name=line[0] names.append(name) w=line[1] l=line[2] d=line[3] score=3*int(w)+int(d) tm=bisect.bisect_left(outs,score) outs.insert(tm,score) outn.insert(tm,name) for i,j in zip(reversed(outn),reversed(outs)): print(f'{i},{j}') cnt+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var cnt : int := 0 ; while 1 do ( var outs : Sequence := Sequence{} ; var outn : Sequence := Sequence{} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else (if cnt > 0 then ( execute (->display() ) else skip) ; var names : Sequence := Sequence{} ; var scores : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var line : Sequence := (input().split()) ; var name : OclAny := line->first() ; execute ((name) : names) ; var w : OclAny := line[1+1] ; var l : OclAny := line[2+1] ; var d : OclAny := line[3+1] ; var score : int := 3 * ("" + ((w)))->toInteger() + ("" + ((d)))->toInteger() ; var tm : OclAny := bisect.bisect_left(outs, score) ; outs := outs.insertAt(tm+1, score) ; outn := outn.insertAt(tm+1, name)) ; for _tuple : Integer.subrange(1, (outn)->reverse()->size())->collect( _indx | Sequence{(outn)->reverse()->at(_indx), (outs)->reverse()->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); execute (StringLib.formattedString('{i},{j}'))->display()) ; cnt := cnt + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=5 i=1 q=["Sheldon","Leonard","Penny","Rajesh","Howard"] while(m*itoInteger() ; var m : int := 5 ; var i : int := 1 ; var q : Sequence := Sequence{"Sheldon"}->union(Sequence{"Leonard"}->union(Sequence{"Penny"}->union(Sequence{"Rajesh"}->union(Sequence{ "Howard" })))) ; while ((m * i->compareTo(n)) < 0) do ( n := n - m * i ; i := i * 2) ; execute (q[(n - 1) div (i)+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque n,m=map(int,input().split()) def bfs(n,m): visited=set() q=deque() q.append(n) visited.add(n) if n>m : return n-m cnt=0 while q : for _ in range(len(q)): n=q.popleft() visited.add(n) if n==m : return cnt else : if n-1 not in visited and n>0 : q.append(n-1) if n*2 not in visited and n*2<3*m : q.append(n*2) cnt+=1 print(bfs(n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; execute (bfs(n, m))->display(); operation bfs(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var visited : Set := Set{}->union(()) ; var q : Sequence := () ; execute ((n) : q) ; execute ((n) : visited) ; if (n->compareTo(m)) > 0 then ( return n - m ) else skip ; var cnt : int := 0 ; while q do ( for _anon : Integer.subrange(0, (q)->size()-1) do ( n := q->first() ; q := q->tail() ; execute ((n) : visited) ; if n = m then ( return cnt ) else ( if (visited)->excludes(n - 1) & n > 0 then ( execute ((n - 1) : q) ) else skip ; if (visited)->excludes(n * 2) & (n * 2->compareTo(3 * m)) < 0 then ( execute ((n * 2) : q) ) else skip )) ; cnt := cnt + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) if n>m : print(n-m) else : cnt=0 while m>n : if m % 2 : m+=1 else : m=m//2 cnt+=1 print(cnt+n-m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (n->compareTo(m)) > 0 then ( execute (n - m)->display() ) else ( var cnt : int := 0 ; while (m->compareTo(n)) > 0 do ( if m mod 2 then ( m := m + 1 ) else ( var m : int := m div 2 ) ; cnt := cnt + 1) ; execute (cnt + n - m)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import timeit from collections import deque numbers=list(map(int,input().split())) count=0 info={} arr=deque([numbers[0],'count']) while True : value=arr.popleft() if value=="count" : count+=1 arr.append('count') continue elif value==numbers[1]: break if value>0 and numbers[1]/value>1 : arr.append(value*2) if value>0 and not value in info : arr.append(value-1) info[value]=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var numbers : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : int := 0 ; var info : OclAny := Set{} ; var arr : Sequence := (Sequence{numbers->first()}->union(Sequence{ 'count' })) ; while true do ( var value : OclAny := arr->first() ; arr := arr->tail() ; if value = "count" then ( count := count + 1 ; execute (('count') : arr) ; continue ) else (if value = numbers[1+1] then ( break ) else skip) ; if value > 0 & numbers[1+1] / value > 1 then ( execute ((value * 2) : arr) ) else skip ; if value > 0 & not((info)->includes(value)) then ( execute ((value - 1) : arr) ; info[value+1] := 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(x)for x in input().split()] count=0 while n!=m : if m>n : if m % 2==0 : m=m//2 count+=1 else : m+=1 count+=1 else : m+=1 count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var count : int := 0 ; while n /= m do ( if (m->compareTo(n)) > 0 then ( if m mod 2 = 0 then ( var m : int := m div 2 ; count := count + 1 ) else ( m := m + 1 ; count := count + 1 ) ) else ( m := m + 1 ; count := count + 1 )) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* def numberOfSolutions(n): c=0 while(n): c+=n % 2 n//=2 return int(pow(2,c)) if __name__=="__main__" : n=3 print(numberOfSolutions(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 3 ; execute (numberOfSolutions(n))->display() ) else skip; operation numberOfSolutions(n : OclAny) : OclAny pre: true post: true activity: var c : int := 0 ; while (n) do ( c := c + n mod 2 ; n := n div 2) ; return ("" + (((2)->pow(c))))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=[int(i)for i in input().split()] a=[int(i)for i in input().split()] somatorioA=sum(a) if x==(somatorioA+n-1): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var somatorioA : OclAny := (a)->sum() ; if x = (somatorioA + n - 1) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=map(int,input().split()) a=list(map(int,input().split())) if sum(a)+n-1==x : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (a)->sum() + n - 1 = x then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=map(int,input().split()) a=list(map(int,input().split())) if sum(a)+n-1==x : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (a)->sum() + n - 1 = x then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): ans=0 isprime=eulerlib.list_primality(999999) primes=eulerlib.list_primes(999999) consecutive=0 for i in range(len(primes)): sum=primes[i] consec=1 for j in range(i+1,len(primes)): sum+=primes[j] consec+=1 if sum>=len(isprime): break if isprime[sum]and consec>consecutive : ans=sum consecutive=consec return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : int := 0 ; var isprime : OclAny := eulerlib.list_primality(999999) ; var primes : OclAny := eulerlib.list_primes(999999) ; var consecutive : int := 0 ; for i : Integer.subrange(0, (primes)->size()-1) do ( var sum : OclAny := primes[i+1] ; var consec : int := 1 ; for j : Integer.subrange(i + 1, (primes)->size()-1) do ( sum := sum + primes[j+1] ; consec := consec + 1 ; if (sum->compareTo((isprime)->size())) >= 0 then ( break ) else skip ; if isprime[sum+1] & (consec->compareTo(consecutive)) > 0 then ( ans := sum ; consecutive := consec ) else skip)) ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=map(int,input().split()) a=map(int,input().split()) total_of_ones=sum(a) if total_of_ones+n-1==x : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var total_of_ones : OclAny := (a)->sum() ; if total_of_ones + n - 1 = x then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- firstLine=list(map(int,input().split())) secondLine=list(map(int,input().split())) sum=0 for i in range(firstLine[0]): sum+=secondLine[i] sum=sum+firstLine[0]-1 if(sum==firstLine[1]): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var firstLine : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var secondLine : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sum : int := 0 ; for i : Integer.subrange(0, firstLine->first()-1) do ( sum := sum + secondLine[i+1]) ; sum := sum + firstLine->first() - 1 ; if (sum = firstLine[1+1]) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=5 i=1 q=["Sheldon","Leonard","Penny","Rajesh","Howard"] while(m*itoInteger() ; var m : int := 5 ; var i : int := 1 ; var q : Sequence := Sequence{"Sheldon"}->union(Sequence{"Leonard"}->union(Sequence{"Penny"}->union(Sequence{"Rajesh"}->union(Sequence{ "Howard" })))) ; while ((m * i->compareTo(n)) < 0) do ( n := n - m * i ; i := i * 2) ; execute (q[(n - 1) div (i)+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import fractions def compute(): ans=1 for i in range(1,21): ans*=i//fractions.gcd(i,ans) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : int := 1 ; for i : Integer.subrange(1, 21-1) do ( ans := ans * i div fractions.gcd(i, ans)) ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Profit(costPrice,sellingPrice): profit=(sellingPrice-costPrice) return profit def Loss(costPrice,sellingPrice): Loss=(costPrice-sellingPrice) return Loss if __name__=="__main__" : costPrice,sellingPrice=1500,2000 if sellingPrice==costPrice : print("No profit nor Loss") elif sellingPrice>costPrice : print(Profit(costPrice,sellingPrice),"Profit") else : print(Loss(costPrice,sellingPrice),"Loss") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( Sequence{costPrice,sellingPrice} := Sequence{1500,2000} ; if sellingPrice = costPrice then ( execute ("No profit nor Loss")->display() ) else (if (sellingPrice->compareTo(costPrice)) > 0 then ( execute (Profit(costPrice, sellingPrice))->display() ) else ( execute (Loss(costPrice, sellingPrice))->display() ) ) ) else skip; operation Profit(costPrice : OclAny, sellingPrice : OclAny) : OclAny pre: true post: true activity: var profit : double := (sellingPrice - costPrice) ; return profit; operation Loss(costPrice : OclAny, sellingPrice : OclAny) : OclAny pre: true post: true activity: var Loss : double := (costPrice - sellingPrice) ; return Loss; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=input().split() n=int(n) a=int(a) b=int(b) if(b>0): if(b % n==0): print(a) else : if(a+b % n>n): print(a+b % n-n) else : print(a+b % n) else : if(b % n==0): print(a) else : if(a+b % n>n): print(a+b % n-n) else : print(a+b % n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; if (b > 0) then ( if (b mod n = 0) then ( execute (a)->display() ) else ( if ((a + b mod n->compareTo(n)) > 0) then ( execute (a + b mod n - n)->display() ) else ( execute (a + b mod n)->display() ) ) ) else ( if (b mod n = 0) then ( execute (a)->display() ) else ( if ((a + b mod n->compareTo(n)) > 0) then ( execute (a + b mod n - n)->display() ) else ( execute (a + b mod n)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inp=[int(i)for i in input().split()] n=inp[0] a=inp[1] b=inp[2] result=(a+b)% n if result==0 : result=n print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inp : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var n : OclAny := inp->first() ; var a : OclAny := inp[1+1] ; var b : OclAny := inp[2+1] ; var result : int := (a + b) mod n ; if result = 0 then ( result := n ) else skip ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=input().split() n=int(n) a=int(a) b=int(b) result=(a+b)% n if result==0 : result=n print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; var result : int := (a + b) mod n ; if result = 0 then ( result := n ) else skip ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=[int(i)for i in input().split()] l=0 if(k[2]+k[1])% k[0]==0 : l=k[0] print((k[2]+k[1])% k[0]+l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var l : int := 0 ; if (k[2+1] + k[1+1]) mod k->first() = 0 then ( l := k->first() ) else skip ; execute ((k[2+1] + k[1+1]) mod k->first() + l)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=[int(x)for x in input().split()] if(b<0): for i in range(0,-b): if(a==1): a=n else : a=a-1 elif(b>0): for i in range(0,b): if(a==n): a=1 else : a=a+1 print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if (b < 0) then ( for i : Integer.subrange(0, -b-1) do ( if (a = 1) then ( var a : OclAny := n ) else ( a := a - 1 )) ) else (if (b > 0) then ( for i : Integer.subrange(0, b-1) do ( if (a = n) then ( a := 1 ) else ( a := a + 1 )) ) else skip) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import division from __future__ import print_function import sys def solve(R,k,N,groups): groups=list(groups) total=sum(groups) if totalk)or(j==i): break current+=nextg d[i]=current,j money=0 start=0 history=[] moneyhistory=[] for i in xrange(R): history.append(start) moneyhistory.append(money) dmoney,dstart=d[start] money+=dmoney start=dstart if start in history : break else : return money index=history.index(start) initmoney=moneyhistory[index] cyclemoney=money-initmoney cyclesize=len(history)-index numcycles=int((R-index)/cyclesize) money=initmoney+cyclemoney*numcycles for i in xrange(R-numcycles*cyclesize-index): dmoney,dstart=d[start] money+=dmoney start=dstart return money def main(filename): with open(filename,"r")as f : for case,line in enumerate(f): if not case : T=int(line.strip()) continue if case>T : break R,k,N=(int(c)for c in line.split()) line=next(f) groups=(int(c)for c in line.split()) print("Case #{0}:{1}".format(case,solve(R,k,N,groups))) if __name__=="__main__" : main(sys.argv[1]) sys.exit(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) ; sys.exit(0) ) else skip; operation solve(R : OclAny, k : OclAny, N : OclAny, groups : OclAny) : OclAny pre: true post: true activity: groups := (groups) ; var total : OclAny := (groups)->sum() ; if (total->compareTo(k)) < 0 then ( return total * R ) else skip ; var d : OclAny := Set{} ; for _tuple : Integer.subrange(1, (groups)->size())->collect( _indx | Sequence{_indx-1, (groups)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var g : OclAny := _tuple->at(_indx); var current : OclAny := g ; var j : OclAny := i ; while true do ( j := (j + 1) mod N ; var nextg : OclAny := groups[j+1] ; if ((current + nextg->compareTo(k)) > 0) or (j = i) then ( break ) else skip ; current := current + nextg) ; d[i+1] := current,j) ; var money : int := 0 ; var start : int := 0 ; var history : Sequence := Sequence{} ; var moneyhistory : Sequence := Sequence{} ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name xrange)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name R)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name history)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name start)))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name moneyhistory)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name money)))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name dmoney)))))) , (test (logical_test (comparison (expr (atom (name dstart))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name start)))))))) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name money)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name dmoney))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name start)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dstart)))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name start)))) in (comparison (expr (atom (name history))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name money))))))))))))) ; var index : int := history->indexOf(start) - 1 ; var initmoney : OclAny := moneyhistory[index+1] ; var cyclemoney : double := money - initmoney ; var cyclesize : double := (history)->size() - index ; var numcycles : int := ("" + (((R - index) / cyclesize)))->toInteger() ; money := initmoney + cyclemoney * numcycles ; for i : xrange(R - numcycles * cyclesize - index) do ( var dmoney : OclAny := null; var dstart : OclAny := null; Sequence{dmoney,dstart} := d[start+1] ; money := money + dmoney ; start := dstart) ; return money; operation main(filename : OclAny) pre: true post: true activity: try (var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(filename)); for _tuple : Integer.subrange(1, (f)->size())->collect( _indx | Sequence{_indx-1, (f)->at(_indx)} ) do (var _indx : int := 1; var case : OclAny := _tuple->at(_indx); _indx := _indx + 1; var line : OclAny := _tuple->at(_indx); if not(case) then ( var T : int := ("" + ((line->trim())))->toInteger() ; continue ) else skip ; if (case->compareTo(T)) > 0 then ( break ) else skip ; Sequence{R,k,N} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name line)) (trailer . (name split) (arguments ( ))))))))} ; var line : OclAny := (f).next() ; groups := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name line)) (trailer . (name split) (arguments ( ))))))))} ; execute (StringLib.interpolateStrings("Case #{0}:{1}", Sequence{case, solve(R, k, N, groups)}))->display())) catch (_e : OclException) do skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=int(input()) i=1 while(s!=1 and s!=2 and s!=4): if s % 2==0 : s=s/2 else : s=3*s+1 i+=1 print(i+3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 1 ; while (s /= 1 & s /= 2 & s /= 4) do ( if s mod 2 = 0 then ( s := s / 2 ) else ( s := 3 * s + 1 ) ; i := i + 1) ; execute (i + 3)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) def f(n): if n % 2==0 : return int(n/2) else : return 3*n+1 def main(s): a=[0]*10000000 a[s]=1 i=1 while True : s=f(s) i+=1 if a[s]==1 : print(i) break a[s]=1 return main(int(input())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; skip ; skip ; main(("" + (((OclFile["System.in"]).readLine())))->toInteger()); operation f(n : OclAny) : OclAny pre: true post: true activity: if n mod 2 = 0 then ( return ("" + ((n / 2)))->toInteger() ) else ( return 3 * n + 1 ); operation main(s : OclAny) pre: true post: true activity: var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10000000) ; a[s+1] := 1 ; var i : int := 1 ; while true do ( s := f(s) ; i := i + 1 ; if a[s+1] = 1 then ( execute (i)->display() ; break ) else skip ; a[s+1] := 1) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def func(n): if n % 2==0 : return n/2 else : return 3*n+1 def main(): from builtins import int,map,list,print,len import sys sys.setrecursionlimit(10**6) input=(lambda :(sys.stdin.readline()).rstrip()) input_list=(lambda : input().split()) input_number=(lambda : int(input())) input_number_list=(lambda : list(map(int,input_list()))) s=input_number() ls=[s] for i in range(1000000): a=func(ls[-1]) ls.append(a) if a in ls[:-1]: print(len(ls)) break if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation func(n : OclAny) : OclAny pre: true post: true activity: if n mod 2 = 0 then ( return n / 2 ) else ( return 3 * n + 1 ); operation main() pre: true post: true activity: skip ; print ; ; skip ; sys.setrecursionlimit((10)->pow(6)) ; var input : Function := (lambda $$ : OclAny in (StringLib.rightTrim(((OclFile["System.in"]).readLine())))) ; var input_list : Function := (lambda $$ : OclAny in (input->apply().split())) ; var input_number : Function := (lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var input_number_list : Function := (lambda $$ : OclAny in (((input_list->apply())->collect( _x | (OclType["int"])->apply(_x) )))) ; var s : OclAny := input_number->apply() ; var ls : Sequence := Sequence{ s } ; for i : Integer.subrange(0, 1000000-1) do ( var a : OclAny := func(ls->last()) ; execute ((a) : ls) ; if (ls->front())->includes(a) then ( execute ((ls)->size())->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) if math.log((n/5+1),2)% 1==0 : print('Howard') else : x=1 while 5*(2**x-1)toInteger() ; if ((n / 5 + 1), 2)->log() mod 1 = 0 then ( execute ('Howard')->display() ) else ( var x : int := 1 ; while (5 * ((2)->pow(x) - 1)->compareTo(n)) < 0 do ( x := x + 1) ; x := x - 1 ; var p : double := 5 * ((2)->pow(x) - 1) ; var d : double := n - p ; if (d->compareTo((2)->pow(x))) <= 0 then ( execute ('Sheldon')->display() ) else (if ((2)->pow(x)->compareTo(d)) < 0 & (d <= ((2)->pow(x)) * 2) then ( execute ('Leonard')->display() ) else (if (((2)->pow(x)) * 2->compareTo(d)) < 0 & (d <= ((2)->pow(x)) * 3) then ( execute ('Penny')->display() ) else (if (((2)->pow(x)) * 3->compareTo(d)) < 0 & (d <= ((2)->pow(x)) * 4) then ( execute ('Rajesh')->display() ) else ( execute ('Howard')->display() ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) tmp=0 if(n==1 or n==2): print(4) else : while n!=4 : if(n % 2==0): n/=2 else : n=3*n+1 tmp+=1 print(tmp+4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var tmp : int := 0 ; if (n = 1 or n = 2) then ( execute (4)->display() ) else ( while n /= 4 do ( if (n mod 2 = 0) then ( n := n / 2 ) else ( n := 3 * n + 1 ) ; tmp := tmp + 1) ; execute (tmp + 4)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys s=int(input()) a=[] a.append(s) i=1 def f(n): if n % 2==0 : return n//2 else : return 3*n+1 while True : val=f(a[i-1]) if val in a : print(i+1) sys.exit() a.append(val) i+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; execute ((s) : a) ; var i : int := 1 ; skip ; while true do ( var val : String := f(a[i - 1+1]) ; if (a)->includes(val) then ( execute (i + 1)->display() ; sys.exit() ) else skip ; execute ((val) : a) ; i := i + 1); operation f(n : OclAny) : OclAny pre: true post: true activity: if n mod 2 = 0 then ( return n div 2 ) else ( return 3 * n + 1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,m=map(int,input().split()) if n==0 and m==0 : break a=[int(x)for x in input().split()] ans=0 for i in a : if icollect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 & m = 0 then ( break ) else skip ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : int := 0 ; for i : a do ( if (i->compareTo(m div n)) < 0 then ( ans := ans + i ) else ( ans := ans + m div n )) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : N,M=map(int,input().split()) if(N | M)==0 : break A=[int(x)for x in input().split()] ans=0 M//=N for a in A : if acollect( _x | (OclType["int"])->apply(_x) ) ; if (MathLib.bitwiseOr(N, M)) = 0 then ( break ) else skip ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : int := 0 ; M := M div N ; for a : A do ( if (a->compareTo(M)) < 0 then ( ans := ans + a ) else ( ans := ans + M )) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : a,b=map(int,input().split()) if a==b==0 : break h=b//a for c in list(map(int,input().split())): if ccollect( _x | (OclType["int"])->apply(_x) ) ; if a = b & (b == 0) then ( break ) else skip ; var h : int := b div a ; for c : ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) do ( if (c->compareTo(h)) < 0 then ( b := b - h - c ) else skip) ; execute (b)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n,m=map(int,input().split()) if n==0 : break a=list(map(int,input().split())) c=0 for i in range(n): c+=min(m//n,a[i]) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( c := c + Set{m div n, a[i+1]}->min()) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lis(arr,n): i,j,maxm=0,0,0 lst=[1 for s in range(n)] for i in range(1,n): for j in range(0,i): if(arr[i]>arr[j]and lst[i]union(Sequence{22}->union(Sequence{9}->union(Sequence{33}->union(Sequence{21}->union(Sequence{50}->union(Sequence{41}->union(Sequence{ 60 }))))))) ; n := (arr)->size() ; execute ("Length of lst is")->display(); operation lis(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var i : OclAny := null; var j : OclAny := null; var maxm : OclAny := null; Sequence{i,j,maxm} := Sequence{0,0,0} ; var lst : Sequence := Integer.subrange(0, n-1)->select(s | true)->collect(s | (1)) ; for i : Integer.subrange(1, n-1) do ( for j : Integer.subrange(0, i-1) do ( if ((arr[i+1]->compareTo(arr[j+1])) > 0 & (lst[i+1]->compareTo(lst[j+1] + 1)) < 0) then ( lst[i+1] := lst[j+1] + 1 ) else skip)) ; for i : Integer.subrange(0, n-1) do ( if (maxm->compareTo(lst[i+1])) < 0 then ( var maxm : OclAny := lst[i+1] ) else skip) ; return maxm; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,m=map(int,input().split()) if(n,m)==(0,0): break t=m//n a=list(map(int,input().split())) cnt=0 for i in a : if t<=i : cnt+=t else : cnt+=i print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if Sequence{n, m} = Sequence{0, 0} then ( break ) else skip ; var t : int := m div n ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : int := 0 ; for i : a do ( if (t->compareTo(i)) <= 0 then ( cnt := cnt + t ) else ( cnt := cnt + i )) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : N=int(input()) if N==0 : break mem=[] for i in range(N): l,p,a,b,c,d,e,f,s,m=map(lambda x : int(x)if x[0].isdigit()else x,input().split()) time=a+b+c+(d+e)*m income=f*m*s-p mem.append((-income/time,l)) for e,name in sorted(mem): print(name) print('#') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var mem : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var l : OclAny := null; var p : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; var f : OclAny := null; var s : OclAny := null; var m : OclAny := null; Sequence{l,p,a,b,c,d,e,f,s,m} := (input().split())->collect( _x | (lambda x : OclAny in (if x->first()->matches("[0-9]*") then ("" + ((x)))->toInteger() else x endif))->apply(_x) ) ; var time : OclAny := a + b + c + (d + e) * m ; var income : double := f * m * s - p ; execute ((Sequence{-income / time, l}) : mem)) ; for _tuple : mem->sort() do (var _indx : int := 1; var e : OclAny := _tuple->at(_indx); _indx := _indx + 1; var name : OclAny := _tuple->at(_indx); execute (name)->display()) ; execute ('#')->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from heapq import heappush,heappop import sys import math import bisect import random def LI(): return[int(x)for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return[list(x)for x in sys.stdin.readline().split()] def S(): return list(sys.stdin.readline())[:-1] def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] sys.setrecursionlimit(1000000) mod=1000000007 def solve(n): lis=[] for i in range(n): l=input().split() p,a,b,c,d,e,f,s,m=[int(i)for i in l[1 :]] l=l[0] lis.append(((f*s*m-p)/(a+b+c+(d+e)*m),l)) lis.sort(key=lambda x :(-x[0],x[1])) for i,j in lis : print(j) print("#") return if __name__=="__main__" : while 1 : n=I() if n==0 : break solve(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1000000) ; var mod : int := 1000000007 ; skip ; if __name__ = "__main__" then ( while 1 do ( n := I() ; if n = 0 then ( break ) else skip ; solve(n)) ) else skip; operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | ((x))); operation S() : OclAny pre: true post: true activity: return OclType["Sequence"]((OclFile["System.in"]).readLine())->front(); operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation solve(n : OclAny) pre: true post: true activity: var lis : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var l : OclAny := input().split() ; var p : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; var f : OclAny := null; var s : OclAny := null; var m : OclAny := null; Sequence{p,a,b,c,d,e,f,s,m} := l->tail()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; l := l->first() ; execute ((Sequence{(f * s * m - p) / (a + b + c + (d + e) * m), l}) : lis)) ; lis := lis->sort() ; for _tuple : lis do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); execute (j)->display()) ; execute ("#")->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] def f(k): p,a,b,c,d,e,f,s,m=map(int,k[1 :]) t=a+b+c+(d+e)*m u=f*s*m-p return(-u/t,k[0]) while True : n=I() if n==0 : break a=[LS()for _ in range(n)] b=[f(c)for c in a] b.sort() for u,l in b : rr.append(l) rr.append('#') return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; skip ; while true do ( var n : OclAny := I() ; if n = 0 then ( break ) else skip ; var a : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LS())) ; var b : Sequence := a->select(c | true)->collect(c | (f(c))) ; b := b->sort() ; for _tuple : b do (var _indx : int := 1; var u : OclAny := _tuple->at(_indx); _indx := _indx + 1; var l : OclAny := _tuple->at(_indx); execute ((l) : rr)) ; execute (('#') : rr)) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=1 while 5*(2**x-1)toInteger() ; var x : int := 1 ; while (5 * ((2)->pow(x) - 1)->compareTo(n)) < 0 do ( x := x + 1) ; x := x - 1 ; var p : double := 5 * ((2)->pow(x) - 1) ; var d : double := n - p ; if (d->compareTo((2)->pow(x))) <= 0 then ( execute ('Sheldon')->display() ) else (if ((2)->pow(x)->compareTo(d)) < 0 & (d <= ((2)->pow(x)) * 2) then ( execute ('Leonard')->display() ) else (if (((2)->pow(x)) * 2->compareTo(d)) < 0 & (d <= ((2)->pow(x)) * 3) then ( execute ('Penny')->display() ) else (if (((2)->pow(x)) * 3->compareTo(d)) < 0 & (d <= ((2)->pow(x)) * 4) then ( execute ('Rajesh')->display() ) else ( execute ('Howard')->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : exit() else : aa=[] for i in range(n): l,p,a,b,c,d,e,f,s,m=input().split() p=int(p) a=int(a) b=int(b) c=int(c) d=int(d) e=int(e) f=int(f) s=int(s) m=int(m) time=a+b+c+(d+e)*m pro=s*m*f-p aa.append([pro/time,l]) aa.sort(key=lambda x :(-x[0],x[1])) for i in range(n): print(aa[i][1]) print("#") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( exit() ) else ( var aa : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var l : OclAny := null; var p : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; var f : OclAny := null; var s : OclAny := null; var m : OclAny := null; Sequence{l,p,a,b,c,d,e,f,s,m} := input().split() ; var p : int := ("" + ((p)))->toInteger() ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; var c : int := ("" + ((c)))->toInteger() ; var d : int := ("" + ((d)))->toInteger() ; var e : int := ("" + ((e)))->toInteger() ; var f : int := ("" + ((f)))->toInteger() ; var s : int := ("" + ((s)))->toInteger() ; var m : int := ("" + ((m)))->toInteger() ; var time : int := a + b + c + (d + e) * m ; var pro : double := s * m * f - p ; execute ((Sequence{pro / time}->union(Sequence{ l })) : aa)) ; aa := aa->sort() ; for i : Integer.subrange(0, n-1) do ( execute (aa[i+1][1+1])->display()) ; execute ("#")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) int1=lambda x : int(x)-1 p2D=lambda x : print(*x,sep="\n") def MI(): return map(int,sys.stdin.readline().split()) def LI(): return list(map(int,sys.stdin.readline().split())) def LLI(rows_number): return[LI()for _ in range(rows_number)] def main(): while 1 : n=int(input()) if n==0 : break ans=[] for _ in range(n): l,*num=input().split() p,a,b,c,d,e,f,s,m=map(int,num) ans.append([(f*s*m-p)/(a+b+c+(d+e)*m),l]) ans.sort(key=lambda x :(-x[0],x[1])) for _,l in ans : print(l) print("#") main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; var p2D : Function := lambda x : OclAny in (((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ; skip ; skip ; skip ; skip ; main(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LLI(rows_number : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows_number-1)->select(_anon | true)->collect(_anon | (LI())); operation main() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var l : OclAny := null; var num : OclAny := null; Sequence{l,num} := input().split() ; var p : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; var f : OclAny := null; var s : OclAny := null; var m : OclAny := null; Sequence{p,a,b,c,d,e,f,s,m} := (num)->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{(f * s * m - p) / (a + b + c + (d + e) * m)}->union(Sequence{ l })) : ans)) ; ans := ans->sort() ; for _tuple : ans do (var _indx : int := 1; var _anon : OclAny := _tuple->at(_indx); _indx := _indx + 1; var l : OclAny := _tuple->at(_indx); execute (l)->display()) ; execute ("#")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- testCount=int(raw_input()) for testIndex in range(testCount): ans="Case #"+str(testIndex+1)+": " n,m=[int(x)for x in raw_input().split(" ")] p=[float(x)for x in raw_input().split(" ")] minType=m+1.0 p1=reduce(lambda x,y : x*y,p,1.0) type=(m-n)*p1+(m-n+1+m)*(1-p1) minType=min(type,minType) p1=1.0 for i in range(1,n): p1*=p[i-1] type=(n-i+m-i)*p1+(n-i+m-i+1+m)*(1-p1) minType=min(type,minType) print(ans+str(minType+1.0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var testCount : int := ("" + ((raw_input())))->toInteger() ; for testIndex : Integer.subrange(0, testCount-1) do ( var ans : String := "Case #" + ("" + ((testIndex + 1))) + ": " ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := raw_input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var p : Sequence := raw_input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toReal())) ; var minType : OclAny := m + 1.0 ; var p1 : OclAny := reduce(lambda x : OclAny, y : OclAny in (x * y), p, 1.0) ; var type : double := (m - n) * p1 + (m - n + 1 + m) * (1 - p1) ; minType := Set{type, minType}->min() ; p1 := 1.0 ; for i : Integer.subrange(1, n-1) do ( p1 := p1 * p[i - 1+1] ; type := (n - i + m - i) * p1 + (n - i + m - i + 1 + m) * (1 - p1) ; minType := Set{type, minType}->min()) ; execute (ans + ("" + ((minType + 1.0))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- with open('A-large.in','r')as fin : with open('output.txt','w')as fout : numcases=int(fin.readline()) for i in range(1,numcases+1): line=[int(j)for j in fin.readline().split()] charstyped=line[0] numchars=line[1] line=[float(j)for j in fin.readline().split()] bestcost=numchars+2 correctprob=1 for idx in range(charstyped): correctprob=correctprob*line[idx] currcost=(numchars+1)*(1-correctprob)+(charstyped-idx-1)+(numchars-idx-1)+1 if currcosttoInteger() ; for i : Integer.subrange(1, numcases + 1-1) do ( var line : Sequence := fin.readLine().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; var charstyped : OclAny := line->first() ; var numchars : OclAny := line[1+1] ; line := fin.readLine().split()->select(j | true)->collect(j | (("" + ((j)))->toReal())) ; var bestcost : OclAny := numchars + 2 ; var correctprob : int := 1 ; for idx : Integer.subrange(0, charstyped-1) do ( correctprob := correctprob * line[idx+1] ; var currcost : double := (numchars + 1) * (1 - correctprob) + (charstyped - idx - 1) + (numchars - idx - 1) + 1 ; if (currcost->compareTo(bestcost)) < 0 then ( bestcost := currcost ) else skip) ; fout.write("Case #") ; fout.write(("" + ((i)))) ; fout.write(": ") ; fout.write(("" + ((bestcost)))) ; fout.write(' ') ; execute (i)->display())) catch (_e : OclException) do skip) catch (_e : OclException) do skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys t_n=int(sys.stdin.readline()) for t_t in range(1,t_n+1): a,b=list(map(int,sys.stdin.readline().split())) p=list(map(float,sys.stdin.readline().split())) ans=1.0*b+1 r=1.0 for x in range(0,a+1): ans=min(ans,(a+b-2*x)+(1.0-r)*(b+1)) if xtoInteger() ; for t_t : Integer.subrange(1, t_n + 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var p : Sequence := ((sys.stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) )) ; var ans : double := 1.0 * b + 1 ; var r : double := 1.0 ; for x : Integer.subrange(0, a + 1-1) do ( ans := Set{ans, (a + b - 2 * x) + (1.0 - r) * (b + 1)}->min() ; if (x->compareTo(a)) < 0 then ( r := r * p[x+1] ) else skip) ; execute (StringLib.format("Case #%d: %.10f",Sequence{t_t, ans + 1.0}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=(i for i in input().split()) z=int(a+b) import math if z**(1/2)==math.floor(z**(1/2)): print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var z : int := ("" + ((a + b)))->toInteger() ; skip ; if (z)->pow((1 / 2)) = ((z)->pow((1 / 2)))->floor() then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def work(K,N,P): return min(work_backspace(K,N,P),work_giveup(K,N,P)) def work_backspace(K,N,P): Pc=1 res=N*N for k in range(K+1): r=(K-k) r+=(N+1-k) r+=(1-Pc)*(N+1) if ktoInteger() ; for i : Integer.subrange(1, T + 1-1) do ( Sequence{K,N} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; P := (raw_input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; execute (StringLib.interpolateStrings('Case #{}:{:f}', Sequence{i, work(K, N, P)}))->display()); operation work(K : OclAny, N : OclAny, P : OclAny) : OclAny pre: true post: true activity: return Set{work_backspace(K, N, P), work_giveup(K, N, P)}->min(); operation work_backspace(K : OclAny, N : OclAny, P : OclAny) : OclAny pre: true post: true activity: var Pc : int := 1 ; var res : double := N * N ; for k : Integer.subrange(0, K + 1-1) do ( var r : double := (K - k) ; r := r + (N + 1 - k) ; r := r + (1 - Pc) * (N + 1) ; if (k->compareTo(K)) < 0 then ( Pc := Pc * P[k+1] ) else skip ; res := Set{res, r}->min()) ; return res; operation work_giveup(K : OclAny, N : OclAny, P : OclAny) : OclAny pre: true post: true activity: return 1 + N + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- pr=[] prime=[1 for i in range(10000000+1)] def sieve(n): for p in range(2,n): if p*p>n : break if(prime[p]==True): for i in range(2*p,n+1,p): prime[i]=False for p in range(2,n+1): if(prime[p]): pr.append(p) def SemiPrimeSum(N): ans=0 for i in range(len(pr)): for j in range(i,len(pr)): if(pr[i]*pr[j]>N): break ans+=pr[i]*pr[j] return ans N=6 sieve(N) print(SemiPrimeSum(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var pr : Sequence := Sequence{} ; var prime : Sequence := Integer.subrange(0, 10000000 + 1-1)->select(i | true)->collect(i | (1)) ; skip ; skip ; N := 6 ; sieve(N) ; execute (SemiPrimeSum(N))->display(); operation sieve(n : OclAny) pre: true post: true activity: for p : Integer.subrange(2, n-1) do ( if (p * p->compareTo(n)) > 0 then ( break ) else skip ; if (prime[p+1] = true) then ( for i : Integer.subrange(2 * p, n + 1-1)->select( $x | ($x - 2 * p) mod p = 0 ) do ( prime[i+1] := false) ) else skip) ; for p : Integer.subrange(2, n + 1-1) do ( if (prime[p+1]) then ( execute ((p) : pr) ) else skip); operation SemiPrimeSum(N : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, (pr)->size()-1) do ( for j : Integer.subrange(i, (pr)->size()-1) do ( if ((pr[i+1] * pr[j+1]->compareTo(N)) > 0) then ( break ) else skip ; ans := ans + pr[i+1] * pr[j+1])) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n,k=map(int,input().split()) ans=0 for i in range(2,n+1): if(n % i==0): ans=i break ; print(n+ans+(k-1)*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; for i : Integer.subrange(2, n + 1-1) do ( if (n mod i = 0) then ( ans := i ; break; ) else skip) ; execute (n + ans + (k - 1) * 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ls=[] set=int(input()) for i in range(set): n,k=map(int,input().split()) for i in range(k): d=2 if n % 2==0 : n+=2*(k-i) break else : while n % d!=0 : d+=1 if n %(d+1)==0 : d+=1 n+=d ls.append(n) for x in range(set): print(ls[x]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ls : Sequence := Sequence{} ; var OclType["Set"] : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, OclType["Set"]-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, k-1) do ( var d : int := 2 ; if n mod 2 = 0 then ( n := n + 2 * (k - i) ; break ) else ( while n mod d /= 0 do ( d := d + 1) ; if n mod (d + 1) = 0 then ( d := d + 1 ) else skip ; n := n + d )) ; execute ((n) : ls)) ; for x : Integer.subrange(0, OclType["Set"]-1) do ( execute (ls[x+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for _ in range(T): temp=input().split(); n,k=[int(x)for x in temp] if n % 2==0 : print(n+2*k) else : i=2 while i<=n : if n % i==0 : break i+=1 print(n+i+2*(k-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, T-1) do ( var temp : OclAny := input().split(); var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := temp->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if n mod 2 = 0 then ( execute (n + 2 * k)->display() ) else ( var i : int := 2 ; while (i->compareTo(n)) <= 0 do ( if n mod i = 0 then ( break ) else skip ; i := i + 1) ; execute (n + i + 2 * (k - 1))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSumofEle(arr1,m,arr2,n,k): arraySum=0 for i in range(n): arraySum+=arr2[i] mean=arraySum/n sumOfElements=0 difference=0 for i in range(m): difference=arr1[i]-mean if((difference<0)and(k>(-1)*difference)): sumOfElements+=arr1[i] if((difference>=0)and(k>difference)): sumOfElements+=arr1[i] return sumOfElements arr1=[1,2,3,4,7,9] arr2=[0,1,2,1,1,4] k=2 m=len(arr1) n=len(arr2) print(findSumofEle(arr1,m,arr2,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr1 := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{7}->union(Sequence{ 9 }))))) ; arr2 := Sequence{0}->union(Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 4 }))))) ; k := 2 ; m := (arr1)->size() ; n := (arr2)->size() ; execute (findSumofEle(arr1, m, arr2, n, k))->display(); operation findSumofEle(arr1 : OclAny, m : OclAny, arr2 : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var arraySum : int := 0 ; for i : Integer.subrange(0, n-1) do ( arraySum := arraySum + arr2[i+1]) ; var mean : double := arraySum / n ; var sumOfElements : int := 0 ; var difference : int := 0 ; for i : Integer.subrange(0, m-1) do ( difference := arr1[i+1] - mean ; if ((difference < 0) & ((k->compareTo((-1) * difference)) > 0)) then ( sumOfElements := sumOfElements + arr1[i+1] ) else skip ; if ((difference >= 0) & ((k->compareTo(difference)) > 0)) then ( sumOfElements := sumOfElements + arr1[i+1] ) else skip) ; return sumOfElements; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,k=list(map(int,input().split())) if n % 2==0 : print(n+k*2) else : prime=-1 for i in range(3,n,2): if i**2>n : break if n % i==0 : prime=i break if prime==-1 : prime=n print(n+prime+(k-1)*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n mod 2 = 0 then ( execute (n + k * 2)->display() ) else ( var prime : int := -1 ; for i : Integer.subrange(3, n-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if ((i)->pow(2)->compareTo(n)) > 0 then ( break ) else skip ; if n mod i = 0 then ( prime := i ; break ) else skip) ; if prime = -1 then ( prime := n ) else skip ; execute (n + prime + (k - 1) * 2)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def smallest_div(n): for i in range(2,n+1): if n % i==0 : return i def calculate(n,k): if n % 2==0 : n+=2*k else : n+=2*(k-1)+smallest_div(n) print(n) t=int(input()) l1=[] l2=[] for i in range(t): n,k=map(int,input().split()) l1.append(n) l2.append(k) for i in range(t): calculate(l1[i],l2[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l1 : Sequence := Sequence{} ; var l2 : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((n) : l1) ; execute ((k) : l2)) ; for i : Integer.subrange(0, t-1) do ( calculate(l1[i+1], l2[i+1])); operation smallest_div(n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(2, n + 1-1) do ( if n mod i = 0 then ( return i ) else skip); operation calculate(n : OclAny, k : OclAny) pre: true post: true activity: if n mod 2 = 0 then ( n := n + 2 * k ) else ( n := n + 2 * (k - 1) + smallest_div(n) ) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(b,m): if m>2**(b-2): print("IMPOSSIBLE") return print("POSSIBLE") if m==2**(b-2): print("0"+"1"*(b-1)) else : l=[(m>>i)& 1 for i in range(b-2)] print("0"+"".join(map(str,reversed(l)))+"0") for i in range(1,b): print("0"*(i+1)+"1"*(b-i-1)) t=int(input()) for i in range(t): print("Case #"+str(i+1)+":",end=" ") b,m=map(int,input().split()) solve(b,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( execute ("Case #" + ("" + ((i + 1))) + ":")->display() ; Sequence{b,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; solve(b, m)); operation solve(b : OclAny, m : OclAny) pre: true post: true activity: if (m->compareTo((2)->pow((b - 2)))) > 0 then ( execute ("IMPOSSIBLE")->display() ; return ) else skip ; execute ("POSSIBLE")->display() ; if m = (2)->pow((b - 2)) then ( execute ("0" + StringLib.nCopies("1", (b - 1)))->display() ) else ( var l : Sequence := Integer.subrange(0, b - 2-1)->select(i | true)->collect(i | (MathLib.bitwiseAnd((m /(2->pow(i))), 1))) ; execute ("0" + StringLib.sumStringsWithSeparator((((l)->reverse())->collect( _x | (OclType["String"])->apply(_x) )), "") + "0")->display() ) ; for i : Integer.subrange(1, b-1) do ( execute (StringLib.nCopies("0", (i + 1)) + StringLib.nCopies("1", (b - i - 1)))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for case in range(1,T+1): t=input().split() B=int(t[0]) M=int(t[1]) if M>2**(B-2): print('Case #{0}: IMPOSSIBLE'.format(case)) continue else : print('Case #{0}: POSSIBLE'.format(case)) ans=[] for i in range(B): ans.append([]) for j in range(B): ans[i].append('0') for j in range(i+1,B-1): ans[i][j]='1' for i in range(B-2,0,-1): now=2**(i-1) if M>=now : M-=now ans[i][B-1]='1' assert(M<=1) if M>=1 : ans[0][B-1]='1' for line in ans : print(''.join(line)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for case : Integer.subrange(1, T + 1-1) do ( var t : OclAny := input().split() ; var B : int := ("" + ((t->first())))->toInteger() ; var M : int := ("" + ((t[1+1])))->toInteger() ; if (M->compareTo((2)->pow((B - 2)))) > 0 then ( execute (StringLib.interpolateStrings('Case #{0}: IMPOSSIBLE', Sequence{case}))->display() ; continue ) else ( execute (StringLib.interpolateStrings('Case #{0}: POSSIBLE', Sequence{case}))->display() ) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, B-1) do ( execute ((Sequence{}) : ans) ; for j : Integer.subrange(0, B-1) do ((expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '0'))))))) ))))) ; for j : Integer.subrange(i + 1, B - 1-1) do ( ans[i+1][j+1] := '1')) ; for i : Integer.subrange(0 + 1, B - 2)->reverse() do ( var now : double := (2)->pow((i - 1)) ; if (M->compareTo(now)) >= 0 then ( M := M - now ; ans[i+1][B - 1+1] := '1' ) else skip) ; assert (M <= 1) do "assertion failed" ; if M >= 1 then ( ans->first()[B - 1+1] := '1' ) else skip ; for line : ans do ( execute (StringLib.sumStringsWithSeparator((line), ''))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict import math def LI(): return list(map(int,input().split())) def II(): return int(input()) def LS(): return input().split() def S(): return input() def LIR(n): return[LI()for i in range(n)] mod=1000000007 a,b=LS() c=int(a+b) for i in range(1,1000): if i*i==c : print("Yes") quit() print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : int := 1000000007 ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := LS() ; var c : int := ("" + ((a + b)))->toInteger() ; for i : Integer.subrange(1, 1000-1) do ( if i * i = c then ( execute ("Yes")->display() ; quit() ) else skip) ; execute ("No")->display(); operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return input().split(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for test in range(1,T+1): B,M=[int(x)for x in input().split()] print("Case #%d: " % test,end="") if M>(2**(B-2)): print("IMPOSSIBLE") continue A=[[0]*B for _ in range(B)] for i in range(0,B): for j in range(i+1,B): A[i][j]=1 if M<2**(B-2): A[0][B-1]=0 for i in range(B-2): if(1<toInteger() ; for test : Integer.subrange(1, T + 1-1) do ( var B : OclAny := null; var M : OclAny := null; Sequence{B,M} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (StringLib.format("Case #%d: ",test))->display() ; if (M->compareTo(((2)->pow((B - 2))))) > 0 then ( execute ("IMPOSSIBLE")->display() ; continue ) else skip ; var A : Sequence := Integer.subrange(0, B-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, B))) ; for i : Integer.subrange(0, B-1) do ( for j : Integer.subrange(i + 1, B-1) do ( A[i+1][j+1] := 1)) ; if (M->compareTo((2)->pow((B - 2)))) < 0 then ( A->first()[B - 1+1] := 0 ; for i : Integer.subrange(0, B - 2-1) do ( if MathLib.bitwiseAnd((1 * (2->pow(i))), M) then ( A->first()[B - i - 2+1] := 1 ) else ( A->first()[B - i - 2+1] := 0 )) ) else skip ; execute ("POSSIBLE")->display() ; for i : Integer.subrange(0, B-1) do ( execute (StringLib.sumStringsWithSeparator((A[i+1]->select(x | true)->collect(x | (("" + ((x)))))), ""))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve_test(inp): B,M=map(int,inp.readline().split()) if M>2**(B-2): return 'IMPOSSIBLE' if M==2**(B-2): first='0'+'1'*(B-1) else : first='0'+bin(M)[2 :].zfill(B-2)+'0' print(bin(M),bin(M)[2 :].zfill(B-2)) lines=['0'*i+'1'*(B-i)for i in range(2,B+1)] return 'POSSIBLE\n'+'\n'.join([first]+lines) def solve_dumb(inp): return '1' inp=open(sys.argv[1]) inp_dumb=open(sys.argv[1]) out=open(sys.argv[1].rsplit('.',1)[0]+'.out','w') out_dumb=open(sys.argv[1].rsplit('.',1)[0]+'.dumb.out','w') n_tests=int(inp.readline()) for i in range(n_tests): ans=solve_test(inp) print("Case #%d: " %(i+1)+ans,file=out) ans_dumb=solve_dumb(inp_dumb) print("Case #%d: " %(i+1)+ans_dumb,file=out_dumb) if ans!=ans_dumb : print('Wrong',i+1,file=sys.stderr) out.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; inp := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) ; var inp_dumb : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) ; var out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(sys.argv[1+1].rsplit('.', 1)->first() + '.out')) ; var out_dumb : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(sys.argv[1+1].rsplit('.', 1)->first() + '.dumb.out')) ; var n_tests : int := ("" + ((inp.readLine())))->toInteger() ; for i : Integer.subrange(0, n_tests-1) do ( var ans : OclAny := solve_test(inp) ; execute (StringLib.format("Case #%d: ",(i + 1)) + ans)->display() ; var ans_dumb : OclAny := solve_dumb(inp_dumb) ; execute (StringLib.format("Case #%d: ",(i + 1)) + ans_dumb)->display() ; if ans /= ans_dumb then ( execute ('Wrong')->display() ) else skip) ; out.closeFile(); operation solve_test(inp : OclAny) : OclAny pre: true post: true activity: var B : OclAny := null; var M : OclAny := null; Sequence{B,M} := (inp.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (M->compareTo((2)->pow((B - 2)))) > 0 then ( return 'IMPOSSIBLE' ) else skip ; if M = (2)->pow((B - 2)) then ( var first : String := '0' + StringLib.nCopies('1', (B - 1)) ) else ( first := '0' + bin(M).subrange(2+1).zfill(B - 2) + '0' ) ; execute (bin(M))->display() ; var lines : Sequence := Integer.subrange(2, B + 1-1)->select(i | true)->collect(i | (StringLib.nCopies('0', i) + StringLib.nCopies('1', (B - i)))) ; return 'POSSIBLE ' + StringLib.sumStringsWithSeparator((Sequence{ first }->union(lines)), ' '); operation solve_dumb(inp : OclAny) : OclAny pre: true post: true activity: return '1'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def isPrime(N): if(N<2): return False if(N<4): return True if((N & 1)==0): return False if(N % 3==0): return False curr=5 s=sqrt(N) while(curr<=s): if(N % curr==0): return False curr+=2 if(N % curr==0): return False curr+=4 return True def check(s,p,prefix_sum,n): satisfies=True for i in range(n): if(i+s-1>=n): break if(i-1>=0): x=prefix_sum[i-1] else : x=0 if(prefix_sum[i+s-1]-x1): mid=(low+high)//2 if(check(mid,p,prefix_sum,y-x+1)): high=mid else : low=mid if(check(low,p,prefix_sum,y-x+1)): return low return high x=12 y=42 p=3 print(minimumWindowSize(x,y,p)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; x := 12 ; y := 42 ; p := 3 ; execute (minimumWindowSize(x, y, p))->display(); operation isPrime(N : OclAny) : OclAny pre: true post: true activity: if (N < 2) then ( return false ) else skip ; if (N < 4) then ( return true ) else skip ; if ((MathLib.bitwiseAnd(N, 1)) = 0) then ( return false ) else skip ; if (N mod 3 = 0) then ( return false ) else skip ; var curr : int := 5 ; var s : OclAny := sqrt(N) ; while ((curr->compareTo(s)) <= 0) do ( if (N mod curr = 0) then ( return false ) else skip ; curr := curr + 2 ; if (N mod curr = 0) then ( return false ) else skip ; curr := curr + 4) ; return true; operation check(s : OclAny, p : OclAny, prefix_sum : OclAny, n : OclAny) : OclAny pre: true post: true activity: var satisfies : boolean := true ; for i : Integer.subrange(0, n-1) do ( if ((i + s - 1->compareTo(n)) >= 0) then ( break ) else skip ; if (i - 1 >= 0) then ( var x : OclAny := prefix_sum[i - 1+1] ) else ( x := 0 ) ; if ((prefix_sum[i + s - 1+1] - x->compareTo(p)) < 0) then ( satisfies := false ) else skip) ; return satisfies; operation minimumWindowSize(x : OclAny, y : OclAny, p : OclAny) : OclAny pre: true post: true activity: prefix_sum := MatrixLib.elementwiseMult(Sequence{ 0 }, (y - x + 1)) ; for i : Integer.subrange(x, y + 1-1) do ( if (isPrime(i)) then ( prefix_sum[i - x+1] := 1 ) else skip) ; for i : Integer.subrange(1, y - x + 1-1) do ( prefix_sum[i+1] := prefix_sum[i+1] + prefix_sum[i - 1+1]) ; var low : int := 1 ; var high : double := y - x + 1 ; while (high - low > 1) do ( var mid : int := (low + high) div 2 ; if (check(mid, p, prefix_sum, y - x + 1)) then ( high := mid ) else ( low := mid )) ; if (check(low, p, prefix_sum, y - x + 1)) then ( return low ) else skip ; return high; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def checkPerfectSquare(n): d=sqrt(n) if d*d==n : return True return False def largestPerfectSquareNumber(a,n): maxi=-1 for i in range(n): if(checkPerfectSquare(a[i])): maxi=max(a[i],maxi) return maxi if __name__=="__main__" : a=[16,20,25,2,3,10] n=len(a) print(largestPerfectSquareNumber(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( a := Sequence{16}->union(Sequence{20}->union(Sequence{25}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 10 }))))) ; n := (a)->size() ; execute (largestPerfectSquareNumber(a, n))->display() ) else skip; operation checkPerfectSquare(n : OclAny) : OclAny pre: true post: true activity: var d : OclAny := sqrt(n) ; if d * d = n then ( return true ) else skip ; return false; operation largestPerfectSquareNumber(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var maxi : int := -1 ; for i : Integer.subrange(0, n-1) do ( if (checkPerfectSquare(a[i+1])) then ( maxi := Set{a[i+1], maxi}->max() ) else skip) ; return maxi; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def compress(self,chars): anchor=write=0 for read,c in enumerate(chars): if read+1==len(chars)or chars[read+1]!=c : chars[write]=chars[anchor] write+=1 if read>anchor : for digit in str(read-anchor+1): chars[write]=digit write+=1 anchor=read+1 return write ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation compress(chars : OclAny) : OclAny pre: true post: true activity: var anchor : OclAny := 0; var write : int := 0 ; for _tuple : Integer.subrange(1, (chars)->size())->collect( _indx | Sequence{_indx-1, (chars)->at(_indx)} ) do (var _indx : int := 1; var read : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if read + 1 = (chars)->size() or chars[read + 1+1] /= c then ( chars[write+1] := chars[anchor+1] ; write := write + 1 ; if (read->compareTo(anchor)) > 0 then ( for digit : ("" + ((read - anchor + 1))) do ( chars[write+1] := digit ; write := write + 1) ) else skip ; anchor := read + 1 ) else skip) ; return write; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkPalindrome(num): string=str(num) l=0 r=len(string)-1 ; while(lsize() - 1; ; while ((l->compareTo(r)) < 0) do ( if (string[l+1] /= string[r+1]) then ( execute ("No")->display() ; return; ) else skip ; l := l + 1; ; r := r - 1;) ; execute ("Yes")->display() ; return;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CountWays(n,flag): if n==0 : return 1 sum=0 if flag==False and n>1 : sum=sum+CountWays(n-1,False)+CountWays(n-2,True) else : sum=sum+CountWays(n-1,False) return sum if __name__=='__main__' : n=5 print(CountWays(n,False)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 5 ; execute (CountWays(n, false))->display() ) else skip; operation CountWays(n : OclAny, flag : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( return 1 ) else skip ; var sum : int := 0 ; if flag = false & n > 1 then ( sum := sum + CountWays(n - 1, false) + CountWays(n - 2, true) ) else ( sum := sum + CountWays(n - 1, false) ) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isVowel(c): return(c=='a' or c=='e' or c=='i' or c=='o' or c=='u'); def countSubstringsUtil(s): count=0 ; mp=dict.fromkeys(s,0); n=len(s); start=0 ; for i in range(n): mp[s[i]]+=1 ; while(mp['a']>0 and mp['e']>0 and mp['i']>0 and mp['o']>0 and mp['u']>0): count+=n-i ; mp[s[start]]-=1 ; start+=1 ; return count ; def countSubstrings(s): count=0 ; temp="" ; for i in range(len(s)): if(isVowel(s[i])): temp+=s[i]; else : if(len(temp)>0): count+=countSubstringsUtil(temp); temp="" ; if(len(temp)>0): count+=countSubstringsUtil(temp); return count ; if __name__=="__main__" : s="aeouisddaaeeiouua" ; print(countSubstrings(s)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( s := "aeouisddaaeeiouua"; ; execute (countSubstrings(s))->display(); ) else skip; operation isVowel(c : OclAny) pre: true post: true activity: return (c = 'a' or c = 'e' or c = 'i' or c = 'o' or c = 'u');; operation countSubstringsUtil(s : OclAny) pre: true post: true activity: var count : int := 0; ; var mp : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))); ; var n : int := (s)->size(); ; var start : int := 0; ; for i : Integer.subrange(0, n-1) do ( mp[s[i+1]+1] := mp[s[i+1]+1] + 1; ; while (mp->at('a') > 0 & mp->at('e') > 0 & mp->at('i') > 0 & mp->at('o') > 0 & mp->at('u') > 0) do ( count := count + n - i; ; mp[s[start+1]+1] := mp[s[start+1]+1] - 1; ; start := start + 1;)) ; return count;; operation countSubstrings(s : OclAny) pre: true post: true activity: count := 0; ; var temp : String := ""; ; for i : Integer.subrange(0, (s)->size()-1) do ( if (isVowel(s[i+1])) then ( temp := temp + s[i+1]; ) else ( if ((temp)->size() > 0) then ( count := count + countSubstringsUtil(temp); ) else skip ; temp := ""; )) ; if ((temp)->size() > 0) then ( count := count + countSubstringsUtil(temp); ) else skip ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=[-1]+[ord(c)-ord('0')for c in input()]+[-1] for _ in range(k): L,R=map(int,input().split()) b=[-1]+a[L : R+1]+[-1] ans,dp,p=[0]*10,1,1 c=b[p] while c!=-1 : if c==12 : p-=1 dp=-1 if b[p]==12 or b[p]==14 : b.pop(p+1) elif c==14 : dp=1 if b[p+1]==12 or b[p+1]==14 : b.pop(p) else : p+=1 else : if c==0 : b.pop(p) else : b[p]-=1 p+=dp if c==0 and dp==1 : p-=1 ans[c]+=1 c=b[p] print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{ -1 }->union((OclFile["System.in"]).readLine()->select(c | true)->collect(c | ((c)->char2byte() - ('0')->char2byte())))->union(Sequence{ -1 }) ; for _anon : Integer.subrange(0, k-1) do ( var L : OclAny := null; var R : OclAny := null; Sequence{L,R} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : Sequence := Sequence{ -1 }->union(a.subrange(L+1, R + 1))->union(Sequence{ -1 }) ; var ans : OclAny := null; var dp : OclAny := null; var p : OclAny := null; Sequence{ans,dp,p} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, 10),1,1} ; var c : OclAny := b[p+1] ; while c /= -1 do ( if c = 12 then ( p := p - 1 ; var dp : int := -1 ; if b[p+1] = 12 or b[p+1] = 14 then ( b := b->excludingAt(p + 1+1) ) else skip ) else (if c = 14 then ( dp := 1 ; if b[p + 1+1] = 12 or b[p + 1+1] = 14 then ( b := b->excludingAt(p+1) ) else ( p := p + 1 ) ) else ( if c = 0 then ( b := b->excludingAt(p+1) ) else ( b[p+1] := b[p+1] - 1 ) ; p := p + dp ; if c = 0 & dp = 1 then ( p := p - 1 ) else skip ; ans[c+1] := ans[c+1] + 1 ) ) ; c := b[p+1]) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,q=map(int,input().split()) S=list('x'+input()+'x') for _ in range(q): l,r=map(int,input().split()) s=S[l-1 : r+2] s[0]=s[-1]='x' c=[0]*10 dp,p=1,1 while s[p]!='x' : if s[p]=='>' : dp=1 if s[p+1]in "><" : s.pop(p) else : p+=1 elif s[p]=='<' : dp=-1 p-=1 if s[p]in "><" : s.pop(p+1) else : d=ord(s[p])-ord('0') c[d]+=1 if d==0 : s.pop(p) else : s[p]=chr(d-1+ord('0')) p+=dp if d==0 and dp==1 : p-=1 print(' '.join(map(str,c))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : Sequence := ('x' + (OclFile["System.in"]).readLine() + 'x')->characters() ; for _anon : Integer.subrange(0, q-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := S.subrange(l - 1+1, r + 2) ; s->first() := 'x'; var s->last() : String := 'x' ; var c : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; var dp : OclAny := null; var p : OclAny := null; Sequence{dp,p} := Sequence{1,1} ; while s[p+1] /= 'x' do ( if s[p+1] = '>' then ( var dp : int := 1 ; if ("><")->characters()->includes(s[p + 1+1]) then ( s := s->excludingAt(p+1) ) else ( p := p + 1 ) ) else (if s[p+1] = '<' then ( dp := -1 ; p := p - 1 ; if ("><")->characters()->includes(s[p+1]) then ( s := s->excludingAt(p + 1+1) ) else skip ) else ( var d : double := (s[p+1])->char2byte() - ('0')->char2byte() ; c[d+1] := c[d+1] + 1 ; if d = 0 then ( s := s->excludingAt(p+1) ) else ( s[p+1] := (d - 1 + ('0')->char2byte())->byte2char() ) ; p := p + dp ; if d = 0 & dp = 1 then ( p := p - 1 ) else skip ) ) ) ; execute (StringLib.sumStringsWithSeparator(((c)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,radians from itertools import accumulate,permutations,combinations,product,groupby from operator import itemgetter,mul from copy import deepcopy from string import ascii_lowercase,ascii_uppercase,digits from bisect import bisect,bisect_left from fractions import gcd from heapq import heappush,heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) def ZIP(n): return zip(*(MAP()for _ in range(n))) sys.setrecursionlimit(10**9) INF=float('inf') mod=10**9+7 a,b=MAP() print("Yes" if sqrt(10**(len(str(b)))*a+b)==int(sqrt(10**(len(str(b)))*a+b))else "No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := MAP() ; execute (if sqrt((10)->pow(((("" + ((b))))->size())) * a + b) = ("" + ((sqrt((10)->pow(((("" + ((b))))->size())) * a + b))))->toInteger() then "Yes" else "No" endif)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ZIP(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))`third->at(_indx)} ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,q=map(int,input().split()) S=[-1]+list(map(lambda x : ord(x)-ord('0'),input()))+[-1] D=[12,14] for _ in range(q): l,r=map(int,input().split()) s=S[l-1 : r+2] s[0]=s[-1]=-1 c=[0]*10 dp,p=1,1 i=s[p] while i!=-1 : if i==14 : dp=1 if s[p+1]in D : s.pop(p) else : p+=1 elif i==12 : dp=-1 p-=1 if s[p]in D : s.pop(p+1) else : c[i]+=1 if i==0 : s.pop(p) else : s[p]-=1 p+=dp if i==0 and dp==1 : p-=1 i=s[p] print(' '.join(map(str,c))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : Sequence := Sequence{ -1 }->union((((OclFile["System.in"]).readLine())->collect( _x | (lambda x : OclAny in ((x)->char2byte() - ('0')->char2byte()))->apply(_x) )))->union(Sequence{ -1 }) ; var D : Sequence := Sequence{12}->union(Sequence{ 14 }) ; for _anon : Integer.subrange(0, q-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := S.subrange(l - 1+1, r + 2) ; s->first() := -1; var s->last() : int := -1 ; var c : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; var dp : OclAny := null; var p : OclAny := null; Sequence{dp,p} := Sequence{1,1} ; var i : OclAny := s[p+1] ; while i /= -1 do ( if i = 14 then ( var dp : int := 1 ; if (D)->includes(s[p + 1+1]) then ( s := s->excludingAt(p+1) ) else ( p := p + 1 ) ) else (if i = 12 then ( dp := -1 ; p := p - 1 ; if (D)->includes(s[p+1]) then ( s := s->excludingAt(p + 1+1) ) else skip ) else ( c[i+1] := c[i+1] + 1 ; if i = 0 then ( s := s->excludingAt(p+1) ) else ( s[p+1] := s[p+1] - 1 ) ; p := p + dp ; if i = 0 & dp = 1 then ( p := p - 1 ) else skip ) ) ; i := s[p+1]) ; execute (StringLib.sumStringsWithSeparator(((c)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve_task6(): n,q=map(int,input().split(" ")) program=input() result=[] for k in range(q): l,r=map(int,input().split(" ")) temp_program=list(program[l-1 : r]) cp=0 dp=1 temp_result=[0 for i in range(10)] flag=False while 0<=cp" : dp=1 else : dp=-1 flag=True cp+=dp result.append(temp_result) return result result=solve_task6() for line in result : print(" ".join([str(el)for el in line])+" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; result := solve_task6() ; for line : result do ( execute (StringLib.sumStringsWithSeparator((line->select(el | true)->collect(el | (("" + ((el)))))), " ") + " ")->display()); operation solve_task6() : OclAny pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var program : String := (OclFile["System.in"]).readLine() ; var result : Sequence := Sequence{} ; for k : Integer.subrange(0, q-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var temp_program : Sequence := (program.subrange(l - 1+1, r)) ; var cp : int := 0 ; var dp : int := 1 ; var temp_result : Sequence := Integer.subrange(0, 10-1)->select(i | true)->collect(i | (0)) ; var flag : boolean := false ; while 0 <= cp & (cp < (temp_program)->size()) do ( var current_symbol : OclAny := temp_program[cp+1] ; if current_symbol->matches("[0-9]*") then ( flag := false ; if current_symbol = "0" then ( temp_result->first() := temp_result->first() + 1 ; temp_program := temp_program->excludingAt(cp+1) ; if dp = 1 then ( cp := cp - 1 ) else skip ) else ( temp_result[("" + ((temp_program[cp+1])))->toInteger()+1] := temp_result[("" + ((temp_program[cp+1])))->toInteger()+1] + 1 ; temp_program[cp+1] := ("" + ((("" + ((current_symbol)))->toInteger() - 1))) ) ) else ( if flag then ( temp_program := temp_program->excludingAt(cp - dp+1) ; if dp = 1 then ( cp := cp - dp ) else skip ) else skip ; if current_symbol = ">" then ( dp := 1 ) else ( dp := -1 ) ; flag := true ) ; cp := cp + dp) ; execute ((temp_result) : result)) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def setAllBitsAfterMSB(n): n |=n>>1 n |=n>>2 n |=n>>4 n |=n>>8 n |=n>>16 return n def toggle(n): n=n ^ setAllBitsAfterMSB(n) return n n=10 n=toggle(n) print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 10 ; n := toggle(n) ; execute (n)->display(); operation setAllBitsAfterMSB(n : OclAny) : OclAny pre: true post: true activity: n := n or n /(2->pow(1)) ; n := n or n /(2->pow(2)) ; n := n or n /(2->pow(4)) ; n := n or n /(2->pow(8)) ; n := n or n /(2->pow(16)) ; return n; operation toggle(n : OclAny) : OclAny pre: true post: true activity: n := MathLib.bitwiseXor(n, setAllBitsAfterMSB(n)) ; return n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Data : def __init__(self,x,y): self.x=x self.y=y def inv_interpolate(d : list,n : int,y : float)->float : x=0 for i in range(n): xi=d[i].x for j in range(n): if j!=i : xi=(xi*(y-d[j].y)/(d[i].y-d[j].y)) x+=xi return x if __name__=="__main__" : d=[Data(1.27,2.3),Data(2.25,2.95),Data(2.5,3.5),Data(3.6,5.1)] n=4 y=4.5 print("Value of x at y=4.5 :",round(inv_interpolate(d,n,y),5)) ------------------------------------------------------------ OCL File: --------- class Data { static operation newData() : Data pre: true post: Data->exists( _x | result = _x ); attribute x : OclAny := x; attribute y : OclAny := y; operation initialise(x : OclAny,y : OclAny) : Data pre: true post: true activity: self.x := x ; self.y := y; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var d : Sequence := Sequence{(Data.newData()).initialise(1.27, 2.3)}->union(Sequence{(Data.newData()).initialise(2.25, 2.95)}->union(Sequence{(Data.newData()).initialise(2.5, 3.5)}->union(Sequence{ (Data.newData()).initialise(3.6, 5.1) }))) ; var n : int := 4 ; y := 4.5 ; execute ("Value of x at y=4.5 :")->display() ) else skip; operation inv_interpolate(d : Sequence(OclAny), n : int, y : double) : double pre: true post: true activity: x := 0 ; for i : Integer.subrange(0, n-1) do ( var xi : OclAny := d[i+1].x ; for j : Integer.subrange(0, n-1) do ( if j /= i then ( xi := (xi * (y - d[j+1].y) / (d[i+1].y - d[j+1].y)) ) else skip) ; x := x + xi) ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findElement(arr,n): prefixMul=[] prefixMul.append(arr[0]) for i in range(1,n): prefixMul.append(prefixMul[i-1]*arr[i]) suffixMul=[None for i in range(0,n)] suffixMul[n-1]=arr[n-1] for i in range(n-2,-1,-1): suffixMul[i]=suffixMul[i+1]*arr[i] for i in range(1,n-1): if prefixMul[i]==suffixMul[i]: return arr[i] return-1 arr=[2,3,4,1,4,6] n=len(arr) print(findElement(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{1}->union(Sequence{4}->union(Sequence{ 6 }))))) ; n := (arr)->size() ; execute (findElement(arr, n))->display(); operation findElement(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var prefixMul : Sequence := Sequence{} ; execute ((arr->first()) : prefixMul) ; for i : Integer.subrange(1, n-1) do ( execute ((prefixMul[i - 1+1] * arr[i+1]) : prefixMul)) ; var suffixMul : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; suffixMul[n - 1+1] := arr[n - 1+1] ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( suffixMul[i+1] := suffixMul[i + 1+1] * arr[i+1]) ; for i : Integer.subrange(1, n - 1-1) do ( if prefixMul[i+1] = suffixMul[i+1] then ( return arr[i+1] ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numberOfDays(a,b,n): Days=b*(n+a)//(a+b) return Days a=10 b=20 n=5 print(numberOfDays(a,b,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 10 ; b := 20 ; n := 5 ; execute (numberOfDays(a, b, n))->display(); operation numberOfDays(a : OclAny, b : OclAny, n : OclAny) : OclAny pre: true post: true activity: var Days : int := b * (n + a) div (a + b) ; return Days; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): m=int(input()) p=input() i=1 while(ip[i]or(i>1 and p[i]==p[i-1]))): i+=1 print(p[: i]+p[i-1 : :-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : String := (OclFile["System.in"]).readLine() ; var i : int := 1 ; while ((i->compareTo(m)) < 0 & ((p[i - 1+1]->compareTo(p[i+1])) > 0 or (i > 1 & p[i+1] = p[i - 1+1]))) do ( i := i + 1) ; execute (p.subrange(1,i) + p(subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))) : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np class GFG : def MaxSumDifference(a,n): np.sort(a); j=0 finalSequence=[0 for x in range(n)] for i in range(0,int(n/2)): finalSequence[j]=a[i] finalSequence[j+1]=a[n-i-1] j=j+2 if(n % 2!=0): finalSequence[n-1]=a[n/2] MaximumSum=0 for i in range(0,n-1): MaximumSum=(MaximumSum+abs(finalSequence[i]-finalSequence[i+1])) MaximumSum=(MaximumSum+abs(finalSequence[n-1]-finalSequence[0])); print(MaximumSum) a=[1,2,4,8] n=len(a) GFG.MaxSumDifference(a,n); ------------------------------------------------------------ OCL File: --------- class GFG { static operation newGFG() : GFG pre: true post: GFG->exists( _x | result = _x ); operation MaxSumDifference(a : OclAny , n : OclAny) pre: true post: true activity: np := np->sort(); ; var j : int := 0 ; var finalSequence : Sequence := Integer.subrange(0, n-1)->select(x | true)->collect(x | (0)) ; for i : Integer.subrange(0, ("" + ((n / 2)))->toInteger()-1) do ( finalSequence[j+1] := a[i+1] ; finalSequence[j + 1+1] := a[n - i - 1+1] ; j := j + 2) ; if (n mod 2 /= 0) then ( finalSequence[n - 1+1] := a[n / 2+1] ) else skip ; var MaximumSum : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( MaximumSum := (MaximumSum + (finalSequence[i+1] - finalSequence[i + 1+1])->abs())) ; MaximumSum := (MaximumSum + (finalSequence[n - 1+1] - finalSequence->first())->abs()); ; execute (MaximumSum)->display(); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 8 }))) ; n := (a)->size() ; GFG.MaxSumDifference(a, n);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- testcases=int(input()) for i in range(testcases): n=int(input()) input_2=input() word=[*input_2] mirror_list=list([word[0]]) for i in range(1,n): if word[i]toInteger() ; for i : Integer.subrange(0, testcases-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var input:= (OclFile["System.in"]).readLine() : String := (OclFile["System.in"]).readLine() ; var word : Sequence := input_2 ; var mirror_list : Sequence := (Sequence{ word->first() }) ; for i : Integer.subrange(1, n-1) do ( if (word[i+1]->compareTo(mirror_list->last())) < 0 then ( execute ((word[i+1]) : mirror_list) ) else ( if (mirror_list)->size() = 1 then ( break ) else ( if word[i+1] = mirror_list->last() & (word[i+1]->compareTo(mirror_list->front()->last())) <= 0 then ( execute ((word[i+1]) : mirror_list) ) else ( break ) ) )) ; var result : Sequence := mirror_list->union(mirror_list(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ; var result_mirror : String := StringLib.sumStringsWithSeparator((result), '') ; execute (result_mirror)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- testcases=int(input()) for i in range(testcases): n=int(input()) input_2=input() word=[*input_2] mirror_list=list([word[0]]) for i in range(1,n): if word[i]toInteger() ; for i : Integer.subrange(0, testcases-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var input:= (OclFile["System.in"]).readLine() : String := (OclFile["System.in"]).readLine() ; var word : Sequence := input_2 ; var mirror_list : Sequence := (Sequence{ word->first() }) ; for i : Integer.subrange(1, n-1) do ( if (word[i+1]->compareTo(mirror_list->last())) < 0 then ( execute ((word[i+1]) : mirror_list) ) else ( if (mirror_list)->size() = 1 then ( break ) else ( if word[i+1] = mirror_list->last() then ( execute ((word[i+1]) : mirror_list) ) else ( break ) ) )) ; var result : Sequence := mirror_list->union(mirror_list(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ; var result_mirror : String := StringLib.sumStringsWithSeparator((result), '') ; execute (result_mirror)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=int(input().replace("","")) if c**0.5 % 1!=0 : print("No") else : print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : int := ("" + ((input().replace("", ""))))->toInteger() ; if (c)->pow(0.5) mod 1 /= 0 then ( execute ("No")->display() ) else ( execute ("Yes")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for _ in range(T): n=int(input()) s=input() marker=-1 marker2=False for i in range(1,n): if ord(s[i])>ord(s[i-1]): marker=i break elif ord(s[i])toInteger() ; for _anon : Integer.subrange(0, T-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var marker : int := -1 ; var marker2 : boolean := false ; for i : Integer.subrange(1, n-1) do ( if ((s[i+1])->char2byte()->compareTo((s[i - 1+1])->char2byte())) > 0 then ( marker := i ; break ) else (if ((s[i+1])->char2byte()->compareTo((s[i - 1+1])->char2byte())) < 0 then ( marker2 := true ) else (if (s[i+1])->char2byte() = (s[i - 1+1])->char2byte() & not(marker2) then ( marker := i ; break ) else skip ) ) ) ; if marker = -1 then ( var ans : String := s + s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; execute (ans)->display() ) else ( ans := s.subrange(1,marker) ; ans := ans + ans(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; execute (ans)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: a=*map(ord,s[:-1]),123 ; i=1 while(i>1)+a[i-1]>a[i]: i+=1 s=s[: i]; print(s+s[: :-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var a : OclAny := (s->front())->collect( _x | (ord)->apply(_x) ),123; var i : int := 1 ; while ((i > 1) + a[i - 1+1]->compareTo(a[i+1])) > 0 do ( i := i + 1) ; var s : OclAny := s.subrange(1,i); execute (s + s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100005 fibonacci=set() def createHash(): global fibonacci prev,curr=0,1 fibonacci.add(prev) fibonacci.add(curr) while(curr<=MAX): temp=curr+prev if temp<=MAX : fibonacci.add(temp) prev=curr curr=temp def checkArray(arr,n): sum=0 for i in range(n): if(arr[i]in fibonacci): sum+=arr[i] if(sum in fibonacci): return True return False if __name__=="__main__" : arr=[1,2,4,8,2] n=len(arr) createHash() if(checkArray(arr,n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { attribute fibonacci : OclAny; operation initialise() pre: true post: true activity: var MAX : int := 100005 ; var fibonacci : Set := Set{}->union(()) ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{8}->union(Sequence{ 2 })))) ; n := (arr)->size() ; createHash() ; if (checkArray(arr, n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation createHash() pre: true post: true activity: skip ; var prev : OclAny := null; var curr : OclAny := null; Sequence{prev,curr} := Sequence{0,1} ; execute ((prev) : fibonacci) ; execute ((curr) : fibonacci) ; while ((curr->compareTo(MAX)) <= 0) do ( var temp : OclAny := curr + prev ; if (temp->compareTo(MAX)) <= 0 then ( execute ((temp) : fibonacci) ) else skip ; var prev : OclAny := curr ; var curr : OclAny := temp); operation checkArray(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ((fibonacci)->includes(arr[i+1])) then ( sum := sum + arr[i+1] ) else skip) ; if ((fibonacci)->includes(sum)) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(a==0): return b return gcd(b % a,a) def solve(health,n): currentgcd=gcd(health[0],health[1]) for i in range(2,n): currentgcd=gcd(currentgcd,health[i]) return currentgcd health=[4,6,8,12] n=len(health) print(solve(health,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; health := Sequence{4}->union(Sequence{6}->union(Sequence{8}->union(Sequence{ 12 }))) ; n := (health)->size() ; execute (solve(health, n))->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0) then ( return b ) else skip ; return gcd(b mod a, a); operation solve(health : OclAny, n : OclAny) : OclAny pre: true post: true activity: var currentgcd : OclAny := gcd(health->first(), health[1+1]) ; for i : Integer.subrange(2, n-1) do ( currentgcd := gcd(currentgcd, health[i+1])) ; return currentgcd; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def squarearea(r): if(r<0): return-1 a=4*(pow(r,2)/5) return a if __name__=="__main__" : r=5 print(int(squarearea(r))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( r := 5 ; execute (("" + ((squarearea(r))))->toInteger())->display() ) else skip; operation squarearea(r : OclAny) : OclAny pre: true post: true activity: if (r < 0) then ( return -1 ) else skip ; var a : double := 4 * ((r)->pow(2) / 5) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Graph : def __init__(self,V): self.V=V self.adj=[[]for i in range(V)] def addEdge(self,v,w): self.adj[v].append(w) def DFSUtil(self,s,visited): stack=[] stack.append(s) while(len(stack)!=0): s=stack.pop() if(not visited[s]): print(s,end=" ") visited[s]=True i=0 while iexists( _x | result = _x ); attribute V : OclAny := V; attribute adj : Sequence := Integer.subrange(0, V-1)->select(i | true)->collect(i | (Sequence{})); operation initialise(V : OclAny) : Graph pre: true post: true activity: self.V := V ; self.adj := Integer.subrange(0, V-1)->select(i | true)->collect(i | (Sequence{})); return self; operation addEdge(v : OclAny,w : OclAny) pre: true post: true activity: (expr (atom (name self)) (trailer . (name adj) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name w)))))))) )))); operation DFSUtil(s : OclAny,visited : OclAny) pre: true post: true activity: var stack : Sequence := Sequence{} ; execute ((s) : stack) ; while ((stack)->size() /= 0) do ( s := stack->last() ; stack := stack->front() ; if (not(visited[s+1])) then ( execute (s)->display() ; visited[s+1] := true ) else skip ; var i : int := 0 ; while (i->compareTo((self.adj[s+1])->size())) < 0 do ( if (not(visited[self.adj[s+1][i+1]+1])) then ( execute ((self.adj[s+1][i+1]) : stack) ) else skip ; i := i + 1)); operation DFS() pre: true post: true activity: visited := MatrixLib.elementwiseMult(Sequence{ false }, self.V) ; for i : Integer.subrange(0, self.V-1) do ( if (not(visited[i+1])) then ( self.DFSUtil(i, visited) ) else skip); } class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var g : Graph := (Graph.newGraph()).initialise(5) ; g.addEdge(1, 0) ; g.addEdge(2, 1) ; g.addEdge(3, 4) ; g.addEdge(4, 0) ; execute ("Following is Depth First Traversal")->display() ; g.DFS() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Graph : def __init__(self,V): self.V=V self.adj=[[]for i in range(V)] def addEdge(self,v,w): self.adj[v].append(w) def DFS(self,s): visited=[False for i in range(self.V)] stack=[] stack.append(s) while(len(stack)): s=stack[-1] stack.pop() if(not visited[s]): print(s,end=' ') visited[s]=True for node in self.adj[s]: if(not visited[node]): stack.append(node) g=Graph(5); g.addEdge(1,0); g.addEdge(0,2); g.addEdge(2,1); g.addEdge(0,3); g.addEdge(1,4); print("Following is Depth First Traversal") g.DFS(0) ------------------------------------------------------------ OCL File: --------- class Graph { static operation newGraph() : Graph pre: true post: Graph->exists( _x | result = _x ); attribute V : OclAny := V; attribute adj : Sequence := Integer.subrange(0, V-1)->select(i | true)->collect(i | (Sequence{})); operation initialise(V : OclAny) : Graph pre: true post: true activity: self.V := V ; self.adj := Integer.subrange(0, V-1)->select(i | true)->collect(i | (Sequence{})); return self; operation addEdge(v : OclAny,w : OclAny) pre: true post: true activity: (expr (atom (name self)) (trailer . (name adj) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name w)))))))) )))); operation DFS(s : OclAny) pre: true post: true activity: var visited : Sequence := Integer.subrange(0, self.V-1)->select(i | true)->collect(i | (false)) ; var stack : Sequence := Sequence{} ; execute ((s) : stack) ; while ((stack)->size()) do ( s := stack->last() ; stack := stack->front() ; if (not(visited[s+1])) then ( execute (s)->display() ; visited[s+1] := true ) else skip ; for node : self.adj[s+1] do ( if (not(visited[node+1])) then ( execute ((node) : stack) ) else skip)); } class FromPython { operation initialise() pre: true post: true activity: skip ; var g : Graph := (Graph.newGraph()).initialise(5); ; g.addEdge(1, 0); ; g.addEdge(0, 2); ; g.addEdge(2, 1); ; g.addEdge(0, 3); ; g.addEdge(1, 4); ; execute ("Following is Depth First Traversal")->display() ; g.DFS(0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): s=input() if len(s)==2 and s[0]==s[1]: print(1,2) return for i in range(len(s)-2): if s[i]==s[i+1]or s[i+1]==s[i+2]or s[i]==s[i+2]: print(i+1,i+3) return print(-1,-1) return if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; if (s)->size() = 2 & s->first() = s[1+1] then ( execute (1)->display() ; return ) else skip ; for i : Integer.subrange(0, (s)->size() - 2-1) do ( if s[i+1] = s[i + 1+1] or s[i + 1+1] = s[i + 2+1] or s[i+1] = s[i + 2+1] then ( execute (i + 1)->display() ; return ) else skip) ; execute (-1)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reverse(n): rev=0 ; while(n>0): d=n % 10 ; rev=rev*10+d ; n=n//10 ; return rev ; def isPalin(n): return(n==reverse(n)); def countDigits(n): c=0 ; while(n>0): n=n//10 ; c+=1 ; return c ; def countPalinDigits(arr,n): s=0 ; for i in range(n): if(arr[i]<10 or isPalin(arr[i])): s+=countDigits(arr[i]); return s ; arr=[121,56,434]; n=len(arr); print(countPalinDigits(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; arr := Sequence{121}->union(Sequence{56}->union(Sequence{ 434 })); ; n := (arr)->size(); ; execute (countPalinDigits(arr, n))->display();; operation reverse(n : OclAny) pre: true post: true activity: var rev : int := 0; ; while (n > 0) do ( var d : int := n mod 10; ; rev := rev * 10 + d; ; n := n div 10;) ; return rev;; operation isPalin(n : OclAny) pre: true post: true activity: return (n = reverse(n));; operation countDigits(n : OclAny) pre: true post: true activity: var c : int := 0; ; while (n > 0) do ( n := n div 10; ; c := c + 1;) ; return c;; operation countPalinDigits(arr : OclAny, n : OclAny) pre: true post: true activity: var s : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] < 10 or isPalin(arr[i+1])) then ( s := s + countDigits(arr[i+1]); ) else skip) ; return s;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import gcd import math from math import factorial as f from math import ceil,floor,sqrt from sys import exit from copy import deepcopy import numpy as np import bisect import re import heapq ii=lambda : int(input()) mi=lambda : map(int,input().split()) li=lambda : list(map(int,input().split())) def main(): s=input() n=len(s) for i in range(n-2): if s[i]==s[i+1]: ans=str(i+1)+' '+str(i+2) print(ans) exit() if s[i]==s[i+2]: ans=str(i+1)+' '+str(i+3) print(ans) exit() if s[n-2]==s[n-1]: ans=str(n-1)+' '+str(n) print(ans) exit() print('-1-1') main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var ii : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var mi : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var li : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; skip ; main(); operation main() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var n : int := (s)->size() ; for i : Integer.subrange(0, n - 2-1) do ( if s[i+1] = s[i + 1+1] then ( var ans : String := ("" + ((i + 1))) + ' ' + ("" + ((i + 2))) ; execute (ans)->display() ; exit() ) else skip ; if s[i+1] = s[i + 2+1] then ( ans := ("" + ((i + 1))) + ' ' + ("" + ((i + 3))) ; execute (ans)->display() ; exit() ) else skip) ; if s[n - 2+1] = s[n - 1+1] then ( ans := ("" + ((n - 1))) + ' ' + ("" + ((n))) ; execute (ans)->display() ; exit() ) else skip ; execute ('-1-1')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=[x for x in input().split()] print('Yes' if(int(a+b)**0.5)% 1==0 else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(x | true)->collect(x | (x)) ; execute (if ((("" + ((a + b)))->toInteger())->pow(0.5)) mod 1 = 0 then 'Yes' else 'No' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import reduce import math def main(): INF=float("inf") s=list(_ for _ in input()) left=-1 right=-1 for i in range(len(s)-1): if(s[i+1]==s[i]): left=i+1 right=i+2 break for i in range(len(s)-2): if(s[i+2]==s[i]): left=i+1 right=i+3 break print(left,right) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var INF : double := ("" + (("inf")))->toReal() ; var s : Sequence := ((argument (test (logical_test (comparison (expr (atom (name _)))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ; var left : int := -1 ; var right : int := -1 ; for i : Integer.subrange(0, (s)->size() - 1-1) do ( if (s[i + 1+1] = s[i+1]) then ( left := i + 1 ; right := i + 2 ; break ) else skip) ; for i : Integer.subrange(0, (s)->size() - 2-1) do ( if (s[i + 2+1] = s[i+1]) then ( left := i + 1 ; right := i + 3 ; break ) else skip) ; execute (left)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline s=[-1,-2]+list(map(ord,readline().strip())) N=len(s) ans=(-1,-1) for i in range(2,N): if s[i]==s[i-1]: ans=(i-2,i-1) break if s[i]==s[i-2]: ans=(i-3,i-1) break print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var s : Sequence := Sequence{-1}->union(Sequence{ -2 })->union(((readline()->trim())->collect( _x | (ord)->apply(_x) ))) ; var N : int := (s)->size() ; var ans : OclAny := Sequence{-1, -1} ; for i : Integer.subrange(2, N-1) do ( if s[i+1] = s[i - 1+1] then ( ans := Sequence{i - 2, i - 1} ; break ) else skip ; if s[i+1] = s[i - 2+1] then ( ans := Sequence{i - 3, i - 1} ; break ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() t=s[1 :]+" " r=s[2 :]+" " for n,(i,j,k)in enumerate(zip(s,t,r)): if i==j : print(n+1,n+2) exit() elif i==k : print(n+1,n+3) exit() print(-1,-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var t : OclAny := s->tail() + " " ; var r : OclAny := s.subrange(2+1) + " " ; for _tuple : Integer.subrange(1, (Integer.subrange(1, s->size())->collect( _indx | Sequence{s->at(_indx), t->at(_indx)} ))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(1, s->size())->collect( _indx | Sequence{s->at(_indx), t->at(_indx)} ))->at(_indx)} ) do (var _indx : int := 1; var n : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{i, j, k} : OclAny := _tuple->at(_indx); if i = j then ( execute (n + 1)->display() ; exit() ) else (if i = k then ( execute (n + 1)->display() ; exit() ) else skip)) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sequence(n): f=[0,1,1] print(f[1],end=" "), print(f[2],end=" "), for i in range(3,n+1): f.append(f[f[i-1]]+f[i-f[i-1]]) print(f[i],end=" "), n=13 sequence(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 13 ; sequence(n); operation sequence(n : OclAny) pre: true post: true activity: var f : Sequence := Sequence{0}->union(Sequence{1}->union(Sequence{ 1 })) ; (testlist_star_expr (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name f)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom " "))))))) ))))))) ,) ; (testlist_star_expr (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name f)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom " "))))))) ))))))) ,) ; for i : Integer.subrange(3, n + 1-1) do ( execute ((f[f[i - 1+1]+1] + f[i - f[i - 1+1]+1]) : f) ; (testlist_star_expr (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name f)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom " "))))))) ))))))) ,)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,p,q,r=[int(i)for i in input().split()] l=[int(i)for i in input().split()] prefixMax=list() pM=l[0]*p for i in l : if(i*p>pM): pM=i*p prefixMax.append(pM) suffixMax=list() sM=l[n-1]*r for j in range(n-1,-1,-1): if(l[j]*r>sM): sM=l[j]*r suffixMax.append(sM) suffixMax=suffixMax[: :-1] mM=l[0]*q maxValue=-2**64+1 for i in range(n): sum=prefixMax[i]+l[i]*q+suffixMax[i] if(sum>maxValue): maxValue=sum print(maxValue) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var p : OclAny := null; var q : OclAny := null; var r : OclAny := null; Sequence{n,p,q,r} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var l : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var prefixMax : Sequence := () ; var pM : double := l->first() * p ; for i : l do ( if ((i * p->compareTo(pM)) > 0) then ( pM := i * p ) else skip ; execute ((pM) : prefixMax)) ; var suffixMax : Sequence := () ; var sM : double := l[n - 1+1] * r ; for j : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if ((l[j+1] * r->compareTo(sM)) > 0) then ( sM := l[j+1] * r ) else skip ; execute ((sM) : suffixMax)) ; suffixMax := suffixMax(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var mM : double := l->first() * q ; var maxValue : double := (-2)->pow(64) + 1 ; for i : Integer.subrange(0, n-1) do ( var sum : OclAny := prefixMax[i+1] + l[i+1] * q + suffixMax[i+1] ; if ((sum->compareTo(maxValue)) > 0) then ( maxValue := sum ) else skip) ; execute (maxValue)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().rstrip("\n") n,p,q,r=[int(x)for x in input().split()] a=[int(x)for x in input().split()] first=second=ans=int(-5e18) for i in a : if firstapply().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a : Sequence := input->apply().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; first := first(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name second)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number 5e18)))))))) )))))))))) ; for i : a do ( if (first->compareTo(p * i)) < 0 then ( var first : double := p * i ) else skip ; if (second->compareTo(first + q * i)) < 0 then ( var second : OclAny := first + q * i ) else skip ; if (ans->compareTo(second + r * i)) < 0 then ( var ans : OclAny := second + r * i ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,p,q,r=list(map(int,input().split())) ar=list(map(int,input().split())) preMax=[0]*n sufMax=[0]*n preMax[0]=p*ar[0] sufMax[n-1]=r*ar[n-1] for i in range(1,n): if preMax[i-1]>(ar[i]*p): preMax[i]=preMax[i-1] else : preMax[i]=ar[i]*p if ar[n-i-1]*r>sufMax[n-i]: sufMax[n-i-1]=ar[n-i-1]*r else : sufMax[n-i-1]=sufMax[n-i] ans=ar[0]*q+preMax[0]+sufMax[0] for i in range(1,n): if ar[i]*q+preMax[i]+sufMax[i]>ans : ans=ar[i]*q+preMax[i]+sufMax[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var p : OclAny := null; var q : OclAny := null; var r : OclAny := null; Sequence{n,p,q,r} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ar : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var preMax : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var sufMax : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; preMax->first() := p * ar->first() ; sufMax[n - 1+1] := r * ar[n - 1+1] ; for i : Integer.subrange(1, n-1) do ( if (preMax[i - 1+1]->compareTo((ar[i+1] * p))) > 0 then ( preMax[i+1] := preMax[i - 1+1] ) else ( preMax[i+1] := ar[i+1] * p ) ; if (ar[n - i - 1+1] * r->compareTo(sufMax[n - i+1])) > 0 then ( sufMax[n - i - 1+1] := ar[n - i - 1+1] * r ) else ( sufMax[n - i - 1+1] := sufMax[n - i+1] )) ; var ans : double := ar->first() * q + preMax->first() + sufMax->first() ; for i : Integer.subrange(1, n-1) do ( if (ar[i+1] * q + preMax[i+1] + sufMax[i+1]->compareTo(ans)) > 0 then ( ans := ar[i+1] * q + preMax[i+1] + sufMax[i+1] ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def P_Max(arr,p): n=len(arr) arr=[x*p for x in arr] PMax=n*[0] PMax[0]=arr[0] for i in range(1,n): if arr[i]>PMax[i-1]: PMax[i]=arr[i] else : PMax[i]=PMax[i-1] return PMax def S_Max(arr,r): n=len(arr) arr=[x*r for x in arr] SMax=n*[0] SMax[n-1]=arr[n-1] i=n-2 while(i>=0): if arr[i]>SMax[i+1]: SMax[i]=arr[i] else : SMax[i]=SMax[i+1] i-=1 return SMax def potion(arr,n,p,q,r): max_val=float('-inf') PMax=P_Max(arr,p) SMax=S_Max(arr,r) for i in range(n): max_val=max(max_val,(PMax[i]+q*arr[i]+SMax[i])) return max_val [n,p,q,r]=list(map(int,input().strip().split())) arr=list(map(int,input().strip().split())) val=potion(arr,n,p,q,r) print(val) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; Sequence{n}->union(Sequence{p}->union(Sequence{q}->union(Sequence{ r }))) := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var val : OclAny := potion(arr, n, p, q, r) ; execute (val)->display(); operation P_Max(arr : OclAny, p : OclAny) : OclAny pre: true post: true activity: var n : int := (arr)->size() ; arr := arr->select(x | true)->collect(x | (x * p)) ; var PMax : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; PMax->first() := arr->first() ; for i : Integer.subrange(1, n-1) do ( if (arr[i+1]->compareTo(PMax[i - 1+1])) > 0 then ( PMax[i+1] := arr[i+1] ) else ( PMax[i+1] := PMax[i - 1+1] )) ; return PMax; operation S_Max(arr : OclAny, r : OclAny) : OclAny pre: true post: true activity: n := (arr)->size() ; arr := arr->select(x | true)->collect(x | (x * r)) ; var SMax : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; SMax[n - 1+1] := arr[n - 1+1] ; var i : double := n - 2 ; while (i >= 0) do ( if (arr[i+1]->compareTo(SMax[i + 1+1])) > 0 then ( SMax[i+1] := arr[i+1] ) else ( SMax[i+1] := SMax[i + 1+1] ) ; i := i - 1) ; return SMax; operation potion(arr : OclAny, n : OclAny, p : OclAny, q : OclAny, r : OclAny) : OclAny pre: true post: true activity: var max_val : double := ("" + (('-inf')))->toReal() ; PMax := P_Max(arr, p) ; SMax := S_Max(arr, r) ; for i : Integer.subrange(0, n-1) do ( max_val := Set{max_val, (PMax[i+1] + q * arr[i+1] + SMax[i+1])}->max()) ; return max_val; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,p,q,r=map(int,input().split()) a=list(map(int,input().split())) dp0=[-1e15 for i in range(n)] dp1=[-1e15 for i in range(n)] dp2=[-1e15 for i in range(n)] dp0[0]=a[0]*p dp1[0]=a[0]*p+a[0]*q dp2[0]=a[0]*p+a[0]*q+a[0]*r for i in range(1,n): dp0[i]=max(dp0[i-1],a[i]*p) for i in range(1,n): dp1[i]=max(dp1[i-1],dp0[i]+a[i]*q) for i in range(1,n): dp2[i]=max(dp2[i-1],dp1[i]+a[i]*r) print(dp2[n-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var p : OclAny := null; var q : OclAny := null; var r : OclAny := null; Sequence{n,p,q,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dp0 : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (-("1e15")->toReal())) ; var dp1 : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (-("1e15")->toReal())) ; var dp2 : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (-("1e15")->toReal())) ; dp0->first() := a->first() * p ; dp1->first() := a->first() * p + a->first() * q ; dp2->first() := a->first() * p + a->first() * q + a->first() * r ; for i : Integer.subrange(1, n-1) do ( dp0[i+1] := Set{dp0[i - 1+1], a[i+1] * p}->max()) ; for i : Integer.subrange(1, n-1) do ( dp1[i+1] := Set{dp1[i - 1+1], dp0[i+1] + a[i+1] * q}->max()) ; for i : Integer.subrange(1, n-1) do ( dp2[i+1] := Set{dp2[i - 1+1], dp1[i+1] + a[i+1] * r}->max()) ; execute (dp2[n - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lenoflongestnonpalindrome(s): max1,length=1,0 for i in range(0,len(s)-1): if s[i]==s[i+1]: length=0 elif s[i+1]==s[i-1]and i>0 : length=1 else : length+=1 max1=max(max1,length+1) if max1==1 : return 0 else : return max1 if __name__=="__main__" : s="synapse" print(lenoflongestnonpalindrome(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "synapse" ; execute (lenoflongestnonpalindrome(s))->display() ) else skip; operation lenoflongestnonpalindrome(s : OclAny) : OclAny pre: true post: true activity: var max1 : OclAny := null; var length : OclAny := null; Sequence{max1,length} := Sequence{1,0} ; for i : Integer.subrange(0, (s)->size() - 1-1) do ( if s[i+1] = s[i + 1+1] then ( var length : int := 0 ) else (if s[i + 1+1] = s[i - 1+1] & i > 0 then ( length := 1 ) else ( length := length + 1 ) ) ; var max1 : OclAny := Set{max1, length + 1}->max()) ; if max1 = 1 then ( return 0 ) else ( return max1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) sa=input().count("-") sa=min([n-sa,sa]) ss=[] for _ in range(m): a,b=map(int,input().split()) diff=(b-a) ss.append((diff % 2 and diff<=sa<<1)and "1\n" or "0\n") print("".join(ss)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sa : OclAny := input()->count("-") ; sa := (Sequence{n - sa}->union(Sequence{ sa }))->min() ; var ss : Sequence := Sequence{} ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var diff : double := (b - a) ; execute (((diff mod 2 & (diff->compareTo(sa * (2->pow(1)))) <= 0) & "1\n" or "0\n") : ss)) ; execute (StringLib.sumStringsWithSeparator((ss), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fix(A): s=set() for i in range(len(A)): s.add(A[i]) for i in range(len(A)): if i in s : A[i]=i else : A[i]=-1 return A if __name__=="__main__" : A=[-1,-1,6,1,9,3,2,-1,4,-1] print(fix(A)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( A := Sequence{-1}->union(Sequence{-1}->union(Sequence{6}->union(Sequence{1}->union(Sequence{9}->union(Sequence{3}->union(Sequence{2}->union(Sequence{-1}->union(Sequence{4}->union(Sequence{ -1 }))))))))) ; execute (fix(A))->display() ) else skip; operation fix(A : OclAny) : OclAny pre: true post: true activity: var s : Set := Set{}->union(()) ; for i : Integer.subrange(0, (A)->size()-1) do ( execute ((A[i+1]) : s)) ; for i : Integer.subrange(0, (A)->size()-1) do ( if (s)->includes(i) then ( A[i+1] := i ) else ( A[i+1] := -1 )) ; return A; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): ans=sum(1 for i in range(1,10)for j in range(1,22)if len(str(i**j))==j) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 10))))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 22))))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) ** (expr (atom (name j))))))))) ))))))))) ))))) == (comparison (expr (atom (name j)))))))))))))->sum() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math if __name__=='__main__' : n=12 print(math.sqrt(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var n : int := 12 ; execute ((n)->sqrt())->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def findSum(n): return math.sqrt(3)*(n*(n+1)/2) if __name__=='__main__' : n=10 print(findSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( n := 10 ; execute (findSum(n))->display() ) else skip; operation findSum(n : OclAny) : OclAny pre: true post: true activity: return (3)->sqrt() * (n * (n + 1) / 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def findNth(n): nthElement=19+(n-1)*9 outliersCount=int(math.log10(nthElement))-1 nthElement+=9*outliersCount return nthElement if __name__=="__main__" : print(findNth(5)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (findNth(5))->display() ) else skip; operation findNth(n : OclAny) : OclAny pre: true post: true activity: var nthElement : int := 19 + (n - 1) * 9 ; var outliersCount : double := ("" + (((nthElement)->log10())))->toInteger() - 1 ; nthElement := nthElement + 9 * outliersCount ; return nthElement; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def per(a,b): return(a+b) def area(s): return(s/2) a=7 b=8 s=10 print(per(a,b)) print(area(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 7 ; b := 8 ; s := 10 ; execute (per(a, b))->display() ; execute (area(s))->display(); operation per(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a + b); operation area(s : OclAny) : OclAny pre: true post: true activity: return (s / 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isBinary(n): while n!=0 : temp=n % 10 if temp!=0 and temp!=1 : return False n=n//10 return True def formBinaryStr(n,a): flag=True s="" for i in range(0,n): if isBinary(a[i])==True : s+=str(a[i]) else : flag=False break if flag==True : print(s) else : cout<<"-1\n" if __name__=="__main__" : a=[10,1,0,11,10] N=len(a) formBinaryStr(N,a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( a := Sequence{10}->union(Sequence{1}->union(Sequence{0}->union(Sequence{11}->union(Sequence{ 10 })))) ; var N : int := (a)->size() ; formBinaryStr(N, a) ) else skip; operation isBinary(n : OclAny) : OclAny pre: true post: true activity: while n /= 0 do ( var temp : int := n mod 10 ; if temp /= 0 & temp /= 1 then ( return false ) else skip ; n := n div 10) ; return true; operation formBinaryStr(n : OclAny, a : OclAny) pre: true post: true activity: var flag : boolean := true ; var s : String := "" ; for i : Integer.subrange(0, n-1) do ( if isBinary(a[i+1]) = true then ( s := s + ("" + ((a[i+1]))) ) else ( flag := false ; break )) ; if flag = true then ( execute (s)->display() ) else ( (expr (expr (atom (name cout))) << (expr (atom "-1\n"))) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculateAND(arr,n): max_val=max(arr) prime=[True for i in range(max_val+1)] prime[0]=False prime[1]=False for p in range(2,max_val+1): if p*p>=max_val : break if(prime[p]): for i in range(2*p,max_val+1,p): prime[i]=False S1=0 S2=0 for i in range(n): if(prime[arr[i]]): S1+=arr[i] elif(arr[i]!=1): S2+=arr[i] return(S1 & S2) arr=[3,4,6,7] n=len(arr) print(calculateAND(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{3}->union(Sequence{4}->union(Sequence{6}->union(Sequence{ 7 }))) ; n := (arr)->size() ; execute (calculateAND(arr, n))->display(); operation calculateAND(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var max_val : OclAny := (arr)->max() ; var prime : Sequence := Integer.subrange(0, max_val + 1-1)->select(i | true)->collect(i | (true)) ; prime->first() := false ; prime[1+1] := false ; for p : Integer.subrange(2, max_val + 1-1) do ( if (p * p->compareTo(max_val)) >= 0 then ( break ) else skip ; if (prime[p+1]) then ( for i : Integer.subrange(2 * p, max_val + 1-1)->select( $x | ($x - 2 * p) mod p = 0 ) do ( prime[i+1] := false) ) else skip) ; var S1 : int := 0 ; var S2 : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (prime[arr[i+1]+1]) then ( S1 := S1 + arr[i+1] ) else (if (arr[i+1] /= 1) then ( S2 := S2 + arr[i+1] ) else skip)) ; return (MathLib.bitwiseAnd(S1, S2)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break books=[] read_t=0 write_t=0 for i in range(n): r,w=map(int,input().split()) read_t+=r write_t+=w books.append((r,w)) books=sorted(books) if books[-1][0]<=read_t//2 : print(read_t+write_t) continue sukima=books[-1][0]-(read_t-books[-1][0]) dp=[[0 for i in range(sukima+1)]for i in range(n)] for i in range(1,n): for j in range(1,sukima+1): dp[i][j]=max(dp[i-1][j],dp[i-1][j-books[i-1][1]]+books[i-1][1]if j-books[i-1][1]>=0 else 0) print(read_t+write_t+sukima-dp[-1][-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var books : Sequence := Sequence{} ; var read_t : int := 0 ; var write_t : int := 0 ; for i : Integer.subrange(0, n-1) do ( var r : OclAny := null; var w : OclAny := null; Sequence{r,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; read_t := read_t + r ; write_t := write_t + w ; execute ((Sequence{r, w}) : books)) ; books := books->sort() ; if (books->last()->first()->compareTo(read_t div 2)) <= 0 then ( execute (read_t + write_t)->display() ; continue ) else skip ; var sukima : double := books->last()->first() - (read_t - books->last()->first()) ; var dp : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, sukima + 1-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(1, n-1) do ( for j : Integer.subrange(1, sukima + 1-1) do ( dp[i+1][j+1] := Set{dp[i - 1+1][j+1], if j - books[i - 1+1][1+1] >= 0 then dp[i - 1+1][j - books[i - 1+1][1+1]+1] + books[i - 1+1][1+1] else 0 endif}->max())) ; execute (read_t + write_t + sukima - dp->last()->last())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10000000) input=lambda : sys.stdin.readline().rstrip() while True : n=int(input()) if n==0 : break books=[] read_t=0 write_t=0 for i in range(n): r,w=map(int,input().split()) read_t+=r write_t+=w books.append((r,w)) books=sorted(books) if books[-1][0]<=read_t//2 : print(read_t+write_t) continue sukima=books[-1][0]-(read_t-books[-1][0]) dp=[[0 for i in range(sukima+1)]for i in range(n)] for i in range(1,n): for j in range(1,sukima+1): dp[i][j]=max(dp[i-1][j],dp[i-1][j-books[i-1][1]]+books[i-1][1]if j-books[i-1][1]>=0 else 0) print(read_t+write_t+sukima-dp[-1][-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(10000000) ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var books : Sequence := Sequence{} ; var read_t : int := 0 ; var write_t : int := 0 ; for i : Integer.subrange(0, n-1) do ( var r : OclAny := null; var w : OclAny := null; Sequence{r,w} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; read_t := read_t + r ; write_t := write_t + w ; execute ((Sequence{r, w}) : books)) ; books := books->sort() ; if (books->last()->first()->compareTo(read_t div 2)) <= 0 then ( execute (read_t + write_t)->display() ; continue ) else skip ; var sukima : double := books->last()->first() - (read_t - books->last()->first()) ; var dp : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, sukima + 1-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(1, n-1) do ( for j : Integer.subrange(1, sukima + 1-1) do ( dp[i+1][j+1] := Set{dp[i - 1+1][j+1], if j - books[i - 1+1][1+1] >= 0 then dp[i - 1+1][j - books[i - 1+1][1+1]+1] + books[i - 1+1][1+1] else 0 endif}->max())) ; execute (read_t + write_t + sukima - dp->last()->last())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import division,print_function try : input=raw_input except NameError : pass from datetime import datetime import math MAXW=1001 def solve(n,read,write): sumR=sum(read) sumW=sum(write) next=[] base=-1 for i in range(n): if read[i]sum() ; var sumW : OclAny := (write)->sum() ; var next : Sequence := Sequence{} ; var base : int := -1 ; for i : Integer.subrange(0, n-1) do ( if (read[i+1]->compareTo(sumR div 2)) < 0 then ( execute ((Sequence{read[i+1], write[i+1]}) : next) ) else ( base := read[i+1] )) ; if ((next)->size() = n) then ( execute (sumR + sumW)->display() ; return ) else skip ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, MAXW) ; dp->first() := true ; for i : Integer.subrange(0, n - 1-1) do ( var tmp : Sequence := dp ; for j : Integer.subrange(0, base + 1-1) do ( if dp[j+1] then ( var na : OclAny := j + next[i+1]->first() ; var nb : OclAny := j + next[i+1]->first() + next[i+1][1+1] ; if (na->compareTo(base)) <= 0 then ( tmp[na+1] := true ) else skip ; if (nb->compareTo(base)) <= 0 then ( tmp[nb+1] := true ) else skip ) else skip) ; dp := tmp) ; var res : int := 0 ; for i : Integer.subrange(0, base + 1-1) do ( if dp[i+1] then ( res := base - i ) else skip) ; execute (sumR + sumW + res)->display(); operation main() pre: true post: true activity: while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( return ) else skip ; read := Sequence{} ; write := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var r : OclAny := null; var w : OclAny := null; Sequence{r,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((r) : read) ; execute ((w) : write)) ; solve(n, read, write)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): A=list(map(int,input().split())) ans=abs(A[0]+A[1]-A[2]-A[3]) for i in range(4): for j in range(4): if i==j : continue now=0 for t in range(4): if t==i or t==j : now+=A[t] else : now-=A[t] if abs(now)collect( _x | (OclType["int"])->apply(_x) )) ; var ans : double := (A->first() + A[1+1] - A[2+1] - A[3+1])->abs() ; for i : Integer.subrange(0, 4-1) do ( for j : Integer.subrange(0, 4-1) do ( if i = j then ( continue ) else skip ; var now : int := 0 ; for t : Integer.subrange(0, 4-1) do ( if t = i or t = j then ( now := now + A[t+1] ) else ( now := now - A[t+1] )) ; if ((now)->abs()->compareTo(ans)) < 0 then ( ans := (now)->abs() ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) t,=R() exec(t*'n,k=R();a=[*R()];i=0\nwhile k and icollect( _x | (OclType["int"])->apply(_x) )) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := R->apply() ; (expr (expr (atom (name t))) * (expr (atom 'n,k=R();a=[*R()];i=0 while k and itoInteger() ; if N = 0 then ( return false ) else skip ; var P : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((readline().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; P := P->sort() ; var RS : OclAny := ((argument (test (logical_test (comparison (expr (atom (name r)))))) (comp_for for (exprlist (expr (atom (name r))) , (expr (atom (name w)))) in (logical_test (comparison (expr (atom (name P))))))))->sum() ; var WS : OclAny := ((argument (test (logical_test (comparison (expr (atom (name w)))))) (comp_for for (exprlist (expr (atom (name r))) , (expr (atom (name w)))) in (logical_test (comparison (expr (atom (name P))))))))->sum() ; if ((argument (test (logical_test (comparison (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name r))))) <= (comparison (expr (atom (name RS))))))) (comp_for for (exprlist (expr (atom (name r))) , (expr (atom (name w)))) in (logical_test (comparison (expr (atom (name P))))))))->forAll( _x | _x = true ) then ( write(StringLib.format("%d\n",(RS + WS))) ; return true ) else skip ; var rl : OclAny := null; var sl : OclAny := null; Sequence{rl,sl} := P->last() ; var W : double := 2 * rl - RS ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (W + 1)) ; dp->first() := 1 ; for _tuple : P->front() do (var _indx : int := 1; var r : OclAny := _tuple->at(_indx); _indx := _indx + 1; var w : OclAny := _tuple->at(_indx); for j : Integer.subrange(w - 1 + 1, W)->reverse() do ( dp[j+1] := dp[j+1] or dp[j - w+1])) ; var ma : OclAny := ((argument (test (logical_test (comparison (expr (atom (name j)))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name W))) + (expr (atom (number (integer 1)))))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))))))->max() ; write(StringLib.format("%d\n",(RS + WS + (W - ma)))) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findIndex(str): l=len(str) open=[0]*(l+1) close=[0]*(l+1) index=-1 open[0]=0 close[l]=0 if(str[0]=='('): open[1]=1 if(str[l-1]==')'): close[l-1]=1 for i in range(1,l): if(str[i]=='('): open[i+1]=open[i]+1 else : open[i+1]=open[i] for i in range(l-2,-1,-1): if(str[i]==')'): close[i]=close[i+1]+1 else : close[i]=close[i+1] if(open[l]==0): return len if(close[0]==0): return 0 for i in range(l+1): if(open[i]==close[i]): index=i return index str="(()))(()()())))" print(findIndex(str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclType["String"] := "(()))(()()())))" ; execute (findIndex(OclType["String"]))->display(); operation findIndex(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var l : int := (OclType["String"])->size() ; var open : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (l + 1)) ; var close : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (l + 1)) ; var index : int := -1 ; OclFile.newOclFile_Write(OclFile.newOclFile(->first())) := 0 ; close[l+1] := 0 ; if (("" + (->first())) = '(') then ( OclFile.newOclFile_Write(OclFile.newOclFile([1+1])) := 1 ) else skip ; if (("" + ([l - 1+1])) = ')') then ( close[l - 1+1] := 1 ) else skip ; for i : Integer.subrange(1, l-1) do ( if (("" + ([i+1])) = '(') then ( OclFile.newOclFile_Write(OclFile.newOclFile([i + 1+1])) := OclFile.newOclFile_Write(OclFile.newOclFile([i+1])) + 1 ) else ( OclFile.newOclFile_Write(OclFile.newOclFile([i + 1+1])) := OclFile.newOclFile_Write(OclFile.newOclFile([i+1])) )) ; for i : Integer.subrange(-1 + 1, l - 2)->reverse() do ( if (("" + ([i+1])) = ')') then ( close[i+1] := close[i + 1+1] + 1 ) else ( close[i+1] := close[i + 1+1] )) ; if (OclFile.newOclFile_Write(OclFile.newOclFile([l+1])) = 0) then ( return len ) else skip ; if (close->first() = 0) then ( return 0 ) else skip ; for i : Integer.subrange(0, l + 1-1) do ( if (OclFile.newOclFile_Write(OclFile.newOclFile([i+1])) = close[i+1]) then ( index := i ) else skip) ; return index; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfDigit(K): sod=0 while(K): sod=sod+K % 10 K=K//10 return sod def totalNumbersWithSpecificDifference(N,diff): low=1 high=N while(low<=high): mid=(low+high)//2 if(mid-sumOfDigit(mid)display(); operation sumOfDigit(K : OclAny) : OclAny pre: true post: true activity: var sod : int := 0 ; while (K) do ( sod := sod + K mod 10 ; K := K div 10) ; return sod; operation totalNumbersWithSpecificDifference(N : OclAny, diff : OclAny) : OclAny pre: true post: true activity: var low : int := 1 ; var high : OclAny := N ; while ((low->compareTo(high)) <= 0) do ( var mid : int := (low + high) div 2 ; if ((mid - sumOfDigit(mid)->compareTo(diff)) < 0) then ( low := mid + 1 ) else ( high := mid - 1 )) ; return (N - high); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numOfsubarrays(arr,n): count=0 for i in range(n): product=arr[i] sum=arr[i] for j in range(i+1,n): if(product==sum): count+=1 product*=arr[j] sum+=arr[j] if(product==sum): count+=1 return count arr=[1,3,2] n=len(arr) print(numOfsubarrays(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{3}->union(Sequence{ 2 })) ; n := (arr)->size() ; execute (numOfsubarrays(arr, n))->display(); operation numOfsubarrays(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( var product : OclAny := arr[i+1] ; var sum : OclAny := arr[i+1] ; for j : Integer.subrange(i + 1, n-1) do ( if (product = sum) then ( count := count + 1 ) else skip ; product := product * arr[j+1] ; sum := sum + arr[j+1]) ; if (product = sum) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) ans=0 i=0 while i+1<=len(a): if a[i]!=i+1 : if i+1 in a : del a[i : a.index(i+1)] else : del a[i :] else : i+=1 if len(a)==0 : print(-1) else : print(n-len(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; var i : int := 0 ; while (i + 1->compareTo((a)->size())) <= 0 do ( if a[i+1] /= i + 1 then ( if (a)->includes(i + 1) then ( execute (a.subrange(i+1, a->indexOf(i + 1) - 1))->isDeleted() ) else ( execute (a.subrange(i+1))->isDeleted() ) ) else ( i := i + 1 )) ; if (a)->size() = 0 then ( execute (-1)->display() ) else ( execute (n - (a)->size())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) a=map(int,input().split()) a=list(a) count=1 ans=0 ; for i in range(N): if a[i]==count : count+=1 else : ans+=1 print("-1" if ans==N else ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := (a) ; var count : int := 1 ; var ans : int := 0; ; for i : Integer.subrange(0, N-1) do ( if a[i+1] = count then ( count := count + 1 ) else ( ans := ans + 1 )) ; execute (if ans = N then "-1" else ans endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=[0]*200005 n=int(input()) a=[0]+list(map(int,input().split())) l[0]=1 for i in range(1,n+1): if l[a[i]-1]==1 : l[a[i]]=1 res=n for i in range(1,n+1): res-=l[i] if res==n : res=-1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 200005) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; l->first() := 1 ; for i : Integer.subrange(1, n + 1-1) do ( if l[a[i+1] - 1+1] = 1 then ( l[a[i+1]+1] := 1 ) else skip) ; var res : int := n ; for i : Integer.subrange(1, n + 1-1) do ( res := res - l[i+1]) ; if res = n then ( res := -1 ) else skip ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(_)for _ in input().split()] c=1 i=0 while i!=n : if a[i]==c : c+=1 i+=1 if c==1 : print(-1) else : print(n-c+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var c : int := 1 ; var i : int := 0 ; while i /= n do ( if a[i+1] = c then ( c := c + 1 ) else skip ; i := i + 1) ; if c = 1 then ( execute (-1)->display() ) else ( execute (n - c + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,*A=map(int,open(0).read().split()) cnt=0 ans=0 for i in range(N): if cnt+1==A[i]: cnt+=1 else : ans+=1 if ans==N : print(-1) else : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; Sequence{N,A} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cnt : int := 0 ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( if cnt + 1 = A[i+1] then ( cnt := cnt + 1 ) else ( ans := ans + 1 )) ; if ans = N then ( execute (-1)->display() ) else ( execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from heapq import heappush,heappop from itertools import permutations,accumulate import sys import math import bisect def LI(): return[int(x)for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return[list(x)for x in sys.stdin.readline().split()] def S(): res=list(sys.stdin.readline()) if res[-1]=="\n" : return res[:-1] return res def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] sys.setrecursionlimit(1000000) mod=1000000007 def solve(): s=list(map(int,input().split())) T=sum(s) ans=100000 for i in range(4): for j in range(i+1,4): ans=min(abs(2*(s[i]+s[j])-T),ans) print(ans) return if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1000000) ; var mod : int := 1000000007 ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | ((x))); operation S() : OclAny pre: true post: true activity: var res : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if res->last() = "\n" then ( return res->front() ) else skip ; return res; operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation solve() pre: true post: true activity: var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var T : OclAny := (s)->sum() ; var ans : int := 100000 ; for i : Integer.subrange(0, 4-1) do ( for j : Integer.subrange(i + 1, 4-1) do ( ans := Set{(2 * (s[i+1] + s[j+1]) - T)->abs(), ans}->min())) ; execute (ans)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**5+10) def input(): return sys.stdin.readline().strip() def resolve(): n=int(input()) import math def make_prime_list_2(num): if num<2 : return[] prime_list=[i for i in range(num+1)] prime_list[1]=0 num_sqrt=math.sqrt(num) for prime in prime_list : if prime==0 : continue if prime>num_sqrt : break for non_prime in range(2*prime,num,prime): prime_list[non_prime]=0 return[prime for prime in prime_list if prime!=0] def prime_factorization_2(num): if num<=1 : return False else : num_sqrt=math.floor(math.sqrt(num)) prime_list=make_prime_list_2(num_sqrt) dict_counter={} for prime in prime_list : while num % prime==0 : if prime in dict_counter : dict_counter[prime]+=1 else : dict_counter[prime]=1 num//=prime if num!=1 : if num in dict_counter : dict_counter[num]+=1 else : dict_counter[num]=1 return dict_counter d=prime_factorization_2(n) val=1 for v in d.values(): val*=(v+1) print(len(d),val-1) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(5) + 10) ; skip ; skip ; resolve(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation resolve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; skip ; skip ; var d : OclAny := prime_factorization_2(n) ; var val : int := 1 ; for v : d.values() do ( val := val * (v + 1)) ; execute ((d)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def convertBST(self,root): total=0 node=root stack=[] while stack or node is not None : while node is not None : stack.append(node) node=node.right node=stack.pop() total+=node.val node.val=total node=node.left return root ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation convertBST(root : OclAny) : OclAny pre: true post: true activity: var total : int := 0 ; var node : OclAny := root ; var stack : Sequence := Sequence{} ; while stack or not(node <>= null) do ( while not(node <>= null) do ( execute ((node) : stack) ; node := node.right) ; node := stack->last() ; stack := stack->front() ; total := total + node.val ; node.val := total ; node := node.left) ; return root; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() n=len(s)-1 sum=0 co1=1 for i in range(n,-1,-1): if s[i]=='1' : sum+=co1 co1*=2 co1=1 l=0 while sum>co1 : co1*=4 l+=1 print(l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var n : double := (s)->size() - 1 ; var sum : int := 0 ; var co1 : int := 1 ; for i : Integer.subrange(-1 + 1, n)->reverse() do ( if s[i+1] = '1' then ( sum := sum + co1 ) else skip ; co1 := co1 * 2) ; co1 := 1 ; var l : int := 0 ; while (sum->compareTo(co1)) > 0 do ( co1 := co1 * 4 ; l := l + 1) ; execute (l)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(a==0): return b return gcd(b % a,a) def phi(n): result=1 for i in range(2,n): if(gcd(i,n)==1): result+=1 return result for n in range(1,11): print("phi(",n,")=",phi(n),sep="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for n : Integer.subrange(1, 11-1) do ( execute ("phi(")->display()); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0) then ( return b ) else skip ; return gcd(b mod a, a); operation phi(n : OclAny) : OclAny pre: true post: true activity: var result : int := 1 ; for i : Integer.subrange(2, n-1) do ( if (gcd(i, n) = 1) then ( result := result + 1 ) else skip) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): k,s=input(),input() res=0 for i in range(1,len(s)): res+=abs(k.index(s[i])-k.index(s[i-1])) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var k : OclAny := null; var s : OclAny := null; Sequence{k,s} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine()} ; var res : int := 0 ; for i : Integer.subrange(1, (s)->size()-1) do ( res := res + (k->indexOf(s[i+1]) - 1 - k->indexOf(s[i - 1+1]) - 1)->abs()) ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- nt=int(input()) for i in range(nt): mat=[] nc=int(input()) c1=str(input()) c2=str(input()) mat.append([i for i in c1]) mat.append([i for i in c2]) for i in range(nc): if mat[0][i+1]=='1' and mat[1][i+1]=='1' : print('NO') break elif i+1==nc-1 : print('YES') break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var nt : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, nt-1) do ( var mat : Sequence := Sequence{} ; var nc : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c1 : String := ("" + (((OclFile["System.in"]).readLine()))) ; var c2 : String := ("" + (((OclFile["System.in"]).readLine()))) ; execute ((c1->characters()->select(i | true)->collect(i | (i))) : mat) ; execute ((c2->characters()->select(i | true)->collect(i | (i))) : mat) ; for i : Integer.subrange(0, nc-1) do ( if mat->first()[i + 1+1] = '1' & mat[1+1][i + 1+1] = '1' then ( execute ('NO')->display() ; break ) else (if i + 1 = nc - 1 then ( execute ('YES')->display() ; break ) else skip))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) a=input() b=input() ans='YES' for j in range(n): if a[j]=='1' and b[j]=='1' : ans='NO' print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var ans : String := 'YES' ; for j : Integer.subrange(0, n-1) do ( if a[j+1] = '1' & b[j+1] = '1' then ( ans := 'NO' ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[*open(0)][1 :] for _ in range(len(a)//3): print((int(a[3*_+1],2)& int(a[3*_+2],2)==0)*'YES' or 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() ; for _anon : Integer.subrange(0, (a)->size() div 3-1) do ( execute ((MathLib.bitwiseAnd(("" + ((a[3 * _anon + 1+1], 2)))->toInteger(), ("" + ((a[3 * _anon + 2+1], 2)))->toInteger()) = 0) * 'YES' or 'NO')->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : n=int(input()) S1=input() S2=input() i=0 s1=list(S1) s2=list(S2) check=0 for i in range(0,n): if s1[i]==s2[i]and s2[i]=='1' : check=1 if s2[n-1]=='1' : check=1 if check==1 : print("NO") if check==0 : print("YES") t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S1 : String := (OclFile["System.in"]).readLine() ; var S2 : String := (OclFile["System.in"]).readLine() ; var i : int := 0 ; var s1 : Sequence := (S1)->characters() ; var s2 : Sequence := (S2)->characters() ; var check : int := 0 ; for i : Integer.subrange(0, n-1) do ( if s1[i+1] = s2[i+1] & s2[i+1] = '1' then ( check := 1 ) else skip) ; if s2[n - 1+1] = '1' then ( check := 1 ) else skip ; if check = 1 then ( execute ("NO")->display() ) else skip ; if check = 0 then ( execute ("YES")->display() ) else skip ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def oneDigit(num): return((num>=0)and(num<10)); def isPalUtil(num,dupNum): if(oneDigit(num)): return(num==(dupNum)% 10); if(isPalUtil(int(num/10),dupNum)==False): return-1 ; dupNum=int(dupNum/10); return(num % 10==(dupNum)% 10); def isPal(num): if(num<0): num=(-num); dupNum=(num); return isPalUtil(num,dupNum); n=12321 ; if(isPal(n)==0): print("Yes"); else : print("No"); n=12 ; if(isPal(n)==0): print("Yes"); else : print("No"); n=88 ; if(isPal(n)==1): print("Yes"); else : print("No"); n=8999 ; if(isPal(n)==0): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var n : int := 12321; ; if (isPal(n) = 0) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ; n := 12; ; if (isPal(n) = 0) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ; n := 88; ; if (isPal(n) = 1) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ; n := 8999; ; if (isPal(n) = 0) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ); operation oneDigit(num : OclAny) pre: true post: true activity: return ((num >= 0) & (num < 10));; operation isPalUtil(num : OclAny, dupNum : OclAny) pre: true post: true activity: if (oneDigit(num)) then ( return (num = (dupNum) mod 10); ) else skip ; if (isPalUtil(("" + ((num / 10)))->toInteger(), dupNum) = false) then ( return -1; ) else skip ; dupNum := ("" + ((dupNum / 10)))->toInteger(); ; return (num mod 10 = (dupNum) mod 10);; operation isPal(num : OclAny) pre: true post: true activity: if (num < 0) then ( num := (-num); ) else skip ; dupNum := (num); ; return isPalUtil(num, dupNum);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,radians from itertools import accumulate,permutations,combinations,product from operator import itemgetter,mul from copy import deepcopy from string import ascii_lowercase,ascii_uppercase,digits from bisect import bisect,bisect_left from fractions import gcd from heapq import heappush,heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) def ZIP(n): return zip(*(MAP()for _ in range(n))) sys.setrecursionlimit(10**9) INF=float('inf') mod=10**9+7 A=LIST() A.sort() a=A[0]+A[3] b=A[2]+A[1] print(abs(a-b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var A : OclAny := LIST() ; A := A->sort() ; var a : OclAny := A->first() + A[3+1] ; var b : OclAny := A[2+1] + A[1+1] ; execute ((a - b)->abs())->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ZIP(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))`third->at(_indx)} ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math c1x,c1y,c1r=map(int,input().split()) c2x,c2y,c2r=map(int,input().split()) d=math.sqrt((c1x-c2x)**2+(c1y-c2y)**2) if d>c1r+c2r : print(4) elif d==c1r+c2r : print(3) elif d+c1r==c2r or d+c2r==c1r : print(1) elif d+c1rcollect( _x | (OclType["int"])->apply(_x) ) ; var c2x : OclAny := null; var c2y : OclAny := null; var c2r : OclAny := null; Sequence{c2x,c2y,c2r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : double := (((c1x - c2x))->pow(2) + ((c1y - c2y))->pow(2))->sqrt() ; if (d->compareTo(c1r + c2r)) > 0 then ( execute (4)->display() ) else (if d = c1r + c2r then ( execute (3)->display() ) else (if d + c1r = c2r or d + c2r = c1r then ( execute (1)->display() ) else (if (d + c1r->compareTo(c2r)) < 0 or (d + c2r->compareTo(c1r)) < 0 then ( execute (0)->display() ) else ( execute (2)->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math class Circle : def __init__(self,x,y,r): self.x=x self.y=y self.r=r def Exchange(c1,c2): return list((c2,c1)) data=list(map(int,input("").split())) c1=Circle(data[0],data[1],data[2]) data=list(map(int,input("").split())) c2=Circle(data[0],data[1],data[2]) if c1.rc1.r+c2.r : print(4) elif d==c1.r+c2.r : print(3) elif c1.r-c2.rexists( _x | result = _x ); attribute x : OclAny := x; attribute y : OclAny := y; attribute r : OclAny := r; operation initialise(x : OclAny,y : OclAny,r : OclAny) : Circle pre: true post: true activity: self.x := x ; self.y := y ; self.r := r; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var data : Sequence := ((input("").split())->collect( _x | (OclType["int"])->apply(_x) )) ; c1 := (Circle.newCircle()).initialise(data->first(), data[1+1], data[2+1]) ; data := ((input("").split())->collect( _x | (OclType["int"])->apply(_x) )) ; c2 := (Circle.newCircle()).initialise(data->first(), data[1+1], data[2+1]) ; if (c1.r->compareTo(c2.r)) < 0 then ( ; Sequence{c1}->union(Sequence{ c2 }) := Exchange(c1, c2) ; var d : double := (((c1.x - c2.x))->pow(2) + ((c1.y - c2.y))->pow(2))->sqrt() ; if (d->compareTo(c1.r + c2.r)) > 0 then ( execute (4)->display() ) else (if d = c1.r + c2.r then ( execute (3)->display() ) else (if (c1.r - c2.r->compareTo(d)) < 0 & (d->compareTo(c1.r + c2.r)) < 0 then ( execute (2)->display() ) else (if d = c1.r - c2.r then ( execute (1)->display() ) else (if (d->compareTo(c1.r - c2.r)) < 0 then ( execute (0)->display() ) else skip ) ) ) ) ) else skip; operation Exchange(c1 : OclAny, c2 : OclAny) : OclAny pre: true post: true activity: return (Sequence{c2, c1}); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import namedtuple class CircleIntersections(object): def __init__(self,): _input=sys.stdin.readlines() x1,y1,r1=map(int,_input[0].split()) x2,y2,r2=map(int,_input[1].split()) Circle=namedtuple('Circle',('centre','radius')) self.c1=Circle(centre=x1+y1*1j,radius=r1) self.c2=Circle(centre=x2+y2*1j,radius=r2) def calc_intersection(self): c_distance=abs(self.c2.centre-self.c1.centre) r1,r2=self.c1.radius,self.c2.radius if c_distance>r1+r2 : return 4 elif c_distance==r1+r2 : return 3 elif abs(r1-r2)exists( _x | result = _x ); attribute c1 : OclAny := Circle((argument (test (logical_test (comparison (expr (atom (name centre)))))) = (test (logical_test (comparison (expr (expr (atom (name x1))) + (expr (expr (atom (name y1))) * (expr (atom (number 1j))))))))), (argument (test (logical_test (comparison (expr (atom (name radius)))))) = (test (logical_test (comparison (expr (atom (name r1)))))))); attribute c2 : OclAny := Circle((argument (test (logical_test (comparison (expr (atom (name centre)))))) = (test (logical_test (comparison (expr (expr (atom (name x2))) + (expr (expr (atom (name y2))) * (expr (atom (number 1j))))))))), (argument (test (logical_test (comparison (expr (atom (name radius)))))) = (test (logical_test (comparison (expr (atom (name r2)))))))); operation initialise() : pre: true post: true activity: var _input : OclAny := (OclFile["System.in"]).readlines() ; var x1 : OclAny := null; var y1 : OclAny := null; var r1 : OclAny := null; Sequence{x1,y1,r1} := (_input->first().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x2 : OclAny := null; var y2 : OclAny := null; var r2 : OclAny := null; Sequence{x2,y2,r2} := (_input[1+1].split())->collect( _x | (OclType["int"])->apply(_x) ) ; var Circle : OclAny := namedtuple('Circle', Sequence{'centre', 'radius'}) ; self.c1 := Circle((argument (test (logical_test (comparison (expr (atom (name centre)))))) = (test (logical_test (comparison (expr (expr (atom (name x1))) + (expr (expr (atom (name y1))) * (expr (atom (number 1j))))))))), (argument (test (logical_test (comparison (expr (atom (name radius)))))) = (test (logical_test (comparison (expr (atom (name r1)))))))) ; self.c2 := Circle((argument (test (logical_test (comparison (expr (atom (name centre)))))) = (test (logical_test (comparison (expr (expr (atom (name x2))) + (expr (expr (atom (name y2))) * (expr (atom (number 1j))))))))), (argument (test (logical_test (comparison (expr (atom (name radius)))))) = (test (logical_test (comparison (expr (atom (name r2)))))))); return self; operation calc_intersection() : OclAny pre: true post: true activity: var c_distance : double := (self.c2.centre - self.c1.centre)->abs() ; var r1 : OclAny := null; var r2 : OclAny := null; Sequence{r1,r2} := Sequence{self.c1.radius,self.c2.radius} ; if (c_distance->compareTo(r1 + r2)) > 0 then ( return 4 ) else (if c_distance = r1 + r2 then ( return 3 ) else (if ((r1 - r2)->abs()->compareTo(c_distance)) < 0 & (c_distance < r1 + r2) then ( return 2 ) else (if c_distance = (r1 - r2)->abs() then ( return 1 ) else ( return 0 ) ) ) ) ; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( var case : CircleIntersections := (CircleIntersections.newCircleIntersections()).initialise() ; execute (case.calc_intersection())->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math c1x,c1y,c1r=[int(i)for i in input().split()] c2x,c2y,c2r=[int(i)for i in input().split()] d=math.sqrt(pow(c1x-c2x,2)+pow(c1y-c2y,2)) bcr=0 scr=0 if c1r>c2r : bcr=c1r scr=c2r else : bcr=c2r scr=c1r if d>bcr+scr : print(4) elif d==bcr+scr : print(3) elif d+scr>bcr : print(2) elif d+scr==bcr : print(1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var c1x : OclAny := null; var c1y : OclAny := null; var c1r : OclAny := null; Sequence{c1x,c1y,c1r} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var c2x : OclAny := null; var c2y : OclAny := null; var c2r : OclAny := null; Sequence{c2x,c2y,c2r} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var d : double := ((c1x - c2x)->pow(2) + (c1y - c2y)->pow(2))->sqrt() ; var bcr : int := 0 ; var scr : int := 0 ; if (c1r->compareTo(c2r)) > 0 then ( bcr := c1r ; scr := c2r ) else ( bcr := c2r ; scr := c1r ) ; if (d->compareTo(bcr + scr)) > 0 then ( execute (4)->display() ) else (if d = bcr + scr then ( execute (3)->display() ) else (if (d + scr->compareTo(bcr)) > 0 then ( execute (2)->display() ) else (if d + scr = bcr then ( execute (1)->display() ) else ( execute (0)->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt c1=list(map(int,input().split())) c2=list(map(int,input().split())) d=sqrt((c1[0]-c2[0])**2+(c1[1]-c2[1])**2) lsum=c1[2]+c2[2] lsub=abs(c1[2]-c2[2]) if d>lsum : print('4') if d==lsum : print('3') if lsubcollect( _x | (OclType["int"])->apply(_x) )) ; var c2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := sqrt(((c1->first() - c2->first()))->pow(2) + ((c1[1+1] - c2[1+1]))->pow(2)) ; var lsum : OclAny := c1[2+1] + c2[2+1] ; var lsub : double := (c1[2+1] - c2[2+1])->abs() ; if (d->compareTo(lsum)) > 0 then ( execute ('4')->display() ) else skip ; if d = lsum then ( execute ('3')->display() ) else skip ; if (lsub->compareTo(d)) < 0 & (d < lsum) then ( execute ('2')->display() ) else skip ; if d = lsub then ( execute ('1')->display() ) else skip ; if (d->compareTo(lsub)) < 0 then ( execute ('0')->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) print(n//3-2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n div 3 - 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countDivisibles(A,B,M): if(A % M==0): return((B/M)-(A/M))+1 return((B/M)-(A/M)) A=30 B=70 M=10 print(countDivisibles(A,B,M)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; A := 30 ; B := 70 ; M := 10 ; execute (countDivisibles(A, B, M))->display(); operation countDivisibles(A : OclAny, B : OclAny, M : OclAny) : OclAny pre: true post: true activity: if (A mod M = 0) then ( return ((B / M) - (A / M)) + 1 ) else skip ; return ((B / M) - (A / M)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSum(arr,N): mp=dict() for i in range(N): mp[arr[i]]=mp.get(arr[i],0)+1 maxFreq=0 for itr in mp : if(mp[itr]>maxFreq): maxFreq=mp[itr] Sum=0 for itr in mp : if(mp[itr]==maxFreq): Sum+=itr*mp[itr] return Sum arr=[1,1,2,2,2,2,3,3,3,3] N=len(arr) print(findSum(arr,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{3}->union(Sequence{3}->union(Sequence{3}->union(Sequence{ 3 }))))))))) ; N := (arr)->size() ; execute (findSum(arr, N))->display(); operation findSum(arr : OclAny, N : OclAny) : OclAny pre: true post: true activity: var mp : Map := (arguments ( )) ; for i : Integer.subrange(0, N-1) do ( mp[arr[i+1]+1] := mp.get(arr[i+1], 0) + 1) ; var maxFreq : int := 0 ; for itr : mp->keys() do ( if ((mp[itr+1]->compareTo(maxFreq)) > 0) then ( maxFreq := mp[itr+1] ) else skip) ; var Sum : int := 0 ; for itr : mp->keys() do ( if (mp[itr+1] = maxFreq) then ( Sum := Sum + itr * mp[itr+1] ) else skip) ; return Sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections def findsum(arr,N): mp=collections.defaultdict(int) for i in range(N): mp[arr[i]]+=1 sum=0 for i in mp : if(mp[i]% 2!=0): sum+=(i*mp[i]) return sum arr=[10,20,20,10,40,40,10] N=len(arr) print(findsum(arr,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{10}->union(Sequence{20}->union(Sequence{20}->union(Sequence{10}->union(Sequence{40}->union(Sequence{40}->union(Sequence{ 10 })))))) ; N := (arr)->size() ; execute (findsum(arr, N))->display(); operation findsum(arr : OclAny, N : OclAny) : OclAny pre: true post: true activity: var mp : OclAny := .defaultdict(OclType["int"]) ; for i : Integer.subrange(0, N-1) do ( mp[arr[i+1]+1] := mp[arr[i+1]+1] + 1) ; var sum : int := 0 ; for i : mp do ( if (mp[i+1] mod 2 /= 0) then ( sum := sum + (i * mp[i+1]) ) else skip) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys str=input() k=int(input()) ans=0 if(k>=len(str)): print((k+len(str))//2*2) exit() for i in range(len(str)): for j in range(0,i+1): len1=len(str[j : i+1]) len2=len(str[i+1 :]) minn=min(len1,len2) if(str[j : j+minn]==str[i+1 : i+1+minn]): if(minn==len1): ans=max(ans,len1*2) elif(k+len2>=len1): ans=max(ans,len1*2) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var OclType["String"] : String := (OclFile["System.in"]).readLine() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; if ((k->compareTo((OclType["String"])->size())) >= 0) then ( execute ((k + (OclType["String"])->size()) div 2 * 2)->display() ; exit() ) else skip ; for i : Integer.subrange(0, (OclType["String"])->size()-1) do ( for j : Integer.subrange(0, i + 1-1) do ( var len1 : int := (("" + (.subrange(j+1, i + 1))))->size() ; var len2 : int := (("" + (.subrange(i + 1+1))))->size() ; var minn : OclAny := Set{len1, len2}->min() ; if (("" + (.subrange(j+1, j + minn))) = ("" + (.subrange(i + 1+1, i + 1 + minn)))) then ( if (minn = len1) then ( ans := Set{ans, len1 * 2}->max() ) else (if ((k + len2->compareTo(len1)) >= 0) then ( ans := Set{ans, len1 * 2}->max() ) else skip) ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calc(r,k,size): n=len(size) history={} money=[] pos=0 for round in xrange(r): if pos in history : repeat=money[history[pos]:] l=len(repeat) remain=r-round final=(remain/l)*sum(repeat)+sum(repeat[: remain % l])+sum(money) return final history[pos]=len(money) m=0 start=pos while True : if m+size[pos]>k : break m+=size[pos] pos=(pos+1)% n if pos==start : break money.append(m) return sum(money) def work(name): f=open(name+".in") out=open(name+".out",'w') case_max=int(f.readline()) for caseno in xrange(1,case_max+1): out.write("Case #%d: " % caseno) r,k,n=map(int,f.readline().split()) size=map(int,f.readline().split()) out.write("%d\n" % calc(r,k,size)) f.close() out.close() if __name__=="__main__" : work("C-large") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( work("C-large") ) else skip; operation calc(r : OclAny, k : OclAny, size : OclAny) : OclAny pre: true post: true activity: var n : int := (size)->size() ; var history : OclAny := Set{} ; var money : Sequence := Sequence{} ; var pos : int := 0 ; for round : xrange(r) do ( if (history)->includes(pos) then ( var repeat : OclAny := money.subrange(history[pos+1]+1) ; var l : int := (repeat)->size() ; var remain : double := r - round ; var final : double := (remain / l) * (repeat)->sum() + (repeat.subrange(1,remain mod l))->sum() + (money)->sum() ; return final ) else skip ; history[pos+1] := (money)->size() ; var m : int := 0 ; var start : int := pos ; while true do ( if (m + size[pos+1]->compareTo(k)) > 0 then ( break ) else skip ; m := m + size[pos+1] ; pos := (pos + 1) mod n ; if pos = start then ( break ) else skip) ; execute ((m) : money)) ; return (money)->sum(); operation work(name : OclAny) pre: true post: true activity: var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(name + ".in")) ; var out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(name + ".out")) ; var case_max : int := ("" + ((f.readLine())))->toInteger() ; for caseno : xrange(1, case_max + 1) do ( out.write(StringLib.format("Case #%d: ",caseno)) ; Sequence{r,k,n} := (f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; size := (f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; out.write(StringLib.format("%d\n",calc(r, k, size)))) ; f.closeFile() ; out.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t,k=input(),int(input()) n=len(t) s=min(k,(n+k)//2) for i in range(n-k): for j in range(i+s+1,min(n,(n+i+k)//2+1)): d=j-i if n-j>d : if t[i : j]==t[j : j+d]: s=d elif t[i : n-d]==t[j : n]: s=d print(2*s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := null; var k : OclAny := null; Sequence{t,k} := Sequence{(OclFile["System.in"]).readLine(),("" + (((OclFile["System.in"]).readLine())))->toInteger()} ; var n : int := (t)->size() ; var s : OclAny := Set{k, (n + k) div 2}->min() ; for i : Integer.subrange(0, n - k-1) do ( for j : Integer.subrange(i + s + 1, Set{n, (n + i + k) div 2 + 1}->min()-1) do ( var d : double := j - i ; if (n - j->compareTo(d)) > 0 then ( if t.subrange(i+1, j) = t.subrange(j+1, j + d) then ( s := d ) else skip ) else (if t.subrange(i+1, n - d) = t.subrange(j+1, n) then ( s := d ) else skip))) ; execute (2 * s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s,r=input(),int(input()) def compare(a,b): return a[: len(b)]==b def f(s,n,N): if not s or n<2*N : return N for i in range(n//2,0,-1): if compare(s[: i],s[i : 2*i]): return f(s[1 :],n-1,max(i,N)) return f(s[1 :],n-1,N) if len(s)toInteger()} ; skip ; skip ; if ((s)->size()->compareTo(r)) < 0 then ( execute (((s)->size() + r) div 2 * 2)->display() ) else ( execute (2 * f(s, (s)->size() + r, 0))->display() ); operation compare(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a.subrange(1,(b)->size()) = b; operation f(s : OclAny, n : OclAny, N : OclAny) : OclAny pre: true post: true activity: if not(s) or (n->compareTo(2 * N)) < 0 then ( return N ) else skip ; for i : Integer.subrange(0 + 1, n div 2)->reverse() do ( if compare(s.subrange(1,i), s.subrange(i+1, 2 * i)) then ( return f(s->tail(), n - 1, Set{i, N}->max()) ) else skip) ; return f(s->tail(), n - 1, N); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def tandem(n,a,i): for k in range(i,i+n): if a[k]!=a[k+n]and a[k+n]!='??' : return 0 return 1 s=list(input().strip()) k=int(input()) s+=['??' for i in range(k)] res=0 for i in range(len(s)): for n in range(1,(len(s)-i)//2+1): if tandem(n,s,i): res=max(res,n*2) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : Sequence := (input()->trim()) ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; s := s + Integer.subrange(0, k-1)->select(i | true)->collect(i | ('??')) ; var res : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( for n : Integer.subrange(1, ((s)->size() - i) div 2 + 1-1) do ( if tandem(n, s, i) then ( res := Set{res, n * 2}->max() ) else skip)) ; execute (res)->display(); operation tandem(n : OclAny, a : OclAny, i : OclAny) : OclAny pre: true post: true activity: for k : Integer.subrange(i, i + n-1) do ( if a[k+1] /= a[k + n+1] & a[k + n+1] /= '??' then ( return 0 ) else skip) ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): s=input() k=int(input()) s+='?'*k N=len(s) result=0 for l in range(1,N): count=0 for i in range(N-l): if s[i]==s[i+l]or s[i+l]=='?' : count+=1 if count==l : result=l break else : count=0 print(result*2) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; s := s + StringLib.nCopies('?', k) ; var N : int := (s)->size() ; var result : int := 0 ; for l : Integer.subrange(1, N-1) do ( var count : int := 0 ; for i : Integer.subrange(0, N - l-1) do ( if s[i+1] = s[i + l+1] or s[i + l+1] = '?' then ( count := count + 1 ; if count = l then ( result := l ; break ) else skip ) else ( count := 0 ))) ; execute (result * 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ch(s1,s2): s1=ord(s1) s2=ord(s2) if abs(s1-s2)==0 or abs(s1-s2)==2 : return True return False def solve(s,n): i=0 while i<(n/2): if not ch(s[i],s[n-i-1]): print("NO",end="\n") return i=i+1 print("YES",end="\n") for pratyush in range(int(input())): x=int(input()) s=input() solve(s,x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for pratyush : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; s := (OclFile["System.in"]).readLine() ; solve(s, x)); operation ch(s1 : OclAny, s2 : OclAny) : OclAny pre: true post: true activity: s1 := (s1)->char2byte() ; s2 := (s2)->char2byte() ; if (s1 - s2)->abs() = 0 or (s1 - s2)->abs() = 2 then ( return true ) else skip ; return false; operation solve(s : OclAny, n : OclAny) pre: true post: true activity: var i : int := 0 ; while (i->compareTo((n / 2))) < 0 do ( if not(ch(s[i+1], s[n - i - 1+1])) then ( execute ("NO")->display() ; return ) else skip ; i := i + 1) ; execute ("YES")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) s=input() i=0 j=n-1 while itoInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var i : int := 0 ; var j : double := n - 1 ; while (i->compareTo(j)) < 0 do ( if s[i+1] = "a" then ( var l : Sequence := Sequence{"b"}->union(Sequence{ "b" }) ) else (if s[i+1] = "z" then ( l := Sequence{"y"}->union(Sequence{ "y" }) ) else ( l := Sequence{((s[i+1])->char2byte() - 1)->byte2char()}->union(Sequence{ ((s[i+1])->char2byte() + 1)->byte2char() }) ) ) ; if s[j+1] = "a" then ( var r : Sequence := Sequence{"b"}->union(Sequence{ "b" }) ) else (if s[j+1] = "z" then ( r := Sequence{"y"}->union(Sequence{ "y" }) ) else ( r := Sequence{((s[j+1])->char2byte() - 1)->byte2char()}->union(Sequence{ ((s[j+1])->char2byte() + 1)->byte2char() }) ) ) ; if l->first() = r->first() or l[1+1] = r->first() or l->first() = r[1+1] or l[1+1] = r[1+1] then ( i := i + 1 ; j := j - 1 ) else ( break )) ; if (i->compareTo(j)) < 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): print((int(input())-6)//3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger() - 6) div 3)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from tokenize import Triple I=lambda :[*map(int,sys.stdin.readline().split())] IS=lambda : input() IN=lambda : int(input()) IF=lambda : float(input()) for i in range(IN()): n=IN() s=IS() res=True for i in range(n): k=abs(ord(s[i])-ord(s[n-i-1])) if k>2 or k & 1 : res=False break print("YES" if res else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var I : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var IS : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var IN : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var IF : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toReal()) ; for i : Integer.subrange(0, IN->apply()-1) do ( var n : OclAny := IN->apply() ; var s : OclAny := IS->apply() ; var res : boolean := true ; for i : Integer.subrange(0, n-1) do ( var k : double := ((s[i+1])->char2byte() - (s[n - i - 1+1])->char2byte())->abs() ; if k > 2 or MathLib.bitwiseAnd(k, 1) then ( res := false ; break ) else skip) ; execute (if res then "YES" else "NO" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) for _ in range(k): n=int(input()) s=input() ans=True for i in range(n//2): temp=abs(ord(s[i])-ord(s[n-1-i])) if not(temp==2 or temp==0): ans=False print("YES" if ans else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, k-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var ans : boolean := true ; for i : Integer.subrange(0, n div 2-1) do ( var temp : double := ((s[i+1])->char2byte() - (s[n - 1 - i+1])->char2byte())->abs() ; if not((temp = 2 or temp = 0)) then ( ans := false ) else skip) ; execute (if ans then "YES" else "NO" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,s): i=0 j=n-1 while i<=j : if s[i]=='a' and s[i]==s[j]: i+=1 j-=1 if s[i]=='z' and s[i]==j : i+=1 j-=1 if chr(ord(s[i])+1)==chr(ord(s[j])+1): i+=1 j-=1 elif chr(ord(s[i])-1)==chr(ord(s[j])-1): i+=1 j-=1 elif chr(ord(s[i])+1)==chr(ord(s[j])-1): i+=1 j-=1 elif chr(ord(s[i])-1)==chr(ord(s[j])+1): i+=1 j-=1 else : return "NO" return "YES" t=int(input()) for i in range(t): n=int(input()) s=input() print(solve(n,s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; s := (OclFile["System.in"]).readLine() ; execute (solve(n, s))->display()); operation solve(n : OclAny, s : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; var j : double := n - 1 ; while (i->compareTo(j)) <= 0 do ( if s[i+1] = 'a' & s[i+1] = s[j+1] then ( i := i + 1 ; j := j - 1 ) else skip ; if s[i+1] = 'z' & s[i+1] = j then ( i := i + 1 ; j := j - 1 ) else skip ; if ((s[i+1])->char2byte() + 1)->byte2char() = ((s[j+1])->char2byte() + 1)->byte2char() then ( i := i + 1 ; j := j - 1 ) else (if ((s[i+1])->char2byte() - 1)->byte2char() = ((s[j+1])->char2byte() - 1)->byte2char() then ( i := i + 1 ; j := j - 1 ) else (if ((s[i+1])->char2byte() + 1)->byte2char() = ((s[j+1])->char2byte() - 1)->byte2char() then ( i := i + 1 ; j := j - 1 ) else (if ((s[i+1])->char2byte() - 1)->byte2char() = ((s[j+1])->char2byte() + 1)->byte2char() then ( i := i + 1 ; j := j - 1 ) else ( return "NO" ) ) ) ) ) ; return "YES"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=map(int,input().split()) tuyoi=max(a,b,c,d)+min(a,c,b,d) print(abs(a+b+c+d-2*tuyoi)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var tuyoi : OclAny := Set{a, b, c, d}->max() + Set{a, c, b, d}->min() ; execute ((a + b + c + d - 2 * tuyoi)->abs())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import chain from bisect import bisect_left max_n=50022 primes={2,3}|{m for n in(5,7)for m in range(n,max_n,6)} du=primes.difference_update for n in chain(range(5,max_n,6),range(7,max_n,6)): if n in primes : du(range(n*3,max_n,n*2)) primes=tuple(primes) try : while True : n=int(input()) i=bisect_left(primes,n) print(primes[i-1],primes[i+(n==primes[i])]) except EOFError : exit() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var max_n : int := 50022 ; var primes : int := MathLib.bitwiseOr(Set{2}->union(Set{ 3 }), Sequence{5, 7}->select(n; m : Integer.subrange(n, max_n-1)->select( $x | ($x - n) mod 6 = 0 ) | true)->collect(n; m : Integer.subrange(n, max_n-1)->select( $x | ($x - n) mod 6 = 0 ) | m)->asSet()) ; var du : OclAny := primes.difference_update ; for n : chain(Integer.subrange(5, max_n-1)->select( $x | ($x - 5) mod 6 = 0 ), Integer.subrange(7, max_n-1)->select( $x | ($x - 7) mod 6 = 0 )) do ( if (primes)->includes(n) then ( du(Integer.subrange(n * 3, max_n-1)->select( $x | ($x - n * 3) mod n * 2 = 0 )) ) else skip) ; primes := (primes) ; try ( while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : OclAny := bisect_left(primes, n) ; execute (primes[i - 1+1])->display())) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name exit)) (trailer (arguments ( )))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def create_prime(n): prime=[1]*(n+1) prime[: 2]=[0,0] for i in range(len(prime)): if prime[i]: for j in range(2*i,len(prime),i): prime[j]=0 return prime def under(prime,n): for i in range(n-1,-1,-1): if prime[i]: return i def over(prime,n): for i in range(n+1,len(prime)): if prime[i]: return i import sys n=[int(line)for line in sys.stdin] prime=create_prime(max(n)+100) for ni in n : print(under(prime,ni),over(prime,ni)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; n := OclFile["System.in"]->select(line | true)->collect(line | (("" + ((line)))->toInteger())) ; prime := create_prime((n)->max() + 100) ; for ni : n do ( execute (under(prime, ni))->display()); operation create_prime(n : OclAny) : OclAny pre: true post: true activity: var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ; prime.subrange(1,2) := Sequence{0}->union(Sequence{ 0 }) ; for i : Integer.subrange(0, (prime)->size()-1) do ( if prime[i+1] then ( for j : Integer.subrange(2 * i, (prime)->size()-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ( prime[j+1] := 0) ) else skip) ; return prime; operation under(prime : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if prime[i+1] then ( return i ) else skip); operation over(prime : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(n + 1, (prime)->size()-1) do ( if prime[i+1] then ( return i ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=1000000 p=[1]*(n+1) p[0],p[1]=0,0 for i in range(2,int(n**0.5)+1): if p[i]: for j in range(i*i,n+1,i): p[j]=0 p=[i for i in range(n+1)if p[i]==1] while 1 : try : n=int(input()) except : break for i in range(len(p)): if p[i]==n : print(p[i-1],p[i+1]) break elif p[i]>n : print(p[i-1],p[i]) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := 1000000 ; var p : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ; var p->first() : OclAny := null; var p[1+1] : OclAny := null; Sequence{p->first(),p[1+1]} := Sequence{0,0} ; for i : Integer.subrange(2, ("" + (((n)->pow(0.5))))->toInteger() + 1-1) do ( if p[i+1] then ( for j : Integer.subrange(i * i, n + 1-1)->select( $x | ($x - i * i) mod i = 0 ) do ( p[j+1] := 0) ) else skip) ; p := Integer.subrange(0, n + 1-1)->select(i | p[i+1] = 1)->collect(i | (i)) ; while 1 do ( try ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) catch (_e : OclException) do ( break) ; for i : Integer.subrange(0, (p)->size()-1) do ( if p[i+1] = n then ( execute (p[i - 1+1])->display() ; break ) else (if (p[i+1]->compareTo(n)) > 0 then ( execute (p[i - 1+1])->display() ; break ) else skip))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math p=[2] s=3 max=50000 while p[len(p)-1]<=max : m=int(math.sqrt(s)) r=True for i in p : if i>m : break if s % i==0 : r=False break if r : p.append(s) s+=2 while True : try : n=int(raw_input()) except EOFError as e : break i=0 while p[i]size() - 1+1]->compareTo(max)) <= 0 do ( var m : int := ("" + (((s)->sqrt())))->toInteger() ; var r : boolean := true ; for i : p do ( if (i->compareTo(m)) > 0 then ( break ) else skip ; if s mod i = 0 then ( r := false ; break ) else skip) ; if r then ( execute ((s) : p) ) else skip ; s := s + 2) ; while true do ( try ( var n : int := ("" + ((raw_input())))->toInteger()) catch (e : EOFError) do ( break) ; var i : int := 0 ; while (p[i+1]->compareTo(n)) < 0 do ( i := i + 1) ; execute (StringLib.format("%d %d",Sequence{p[i - 1+1], if p[i+1] = n then p[i + 1+1] else p[i+1] endif}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect prime=[2,3,5,7,11,13] shieve1=[1]*257 for i in prime : itr=i-1 while(itr<256): shieve1[itr]=0 itr+=i for i in range(16,256): if shieve1[i]: prime.append(i+1) shieve2=[1]*(50101) for i in prime : itr=i-1 while(itr<50100): shieve2[itr]=0 itr+=i for i in range(257,50101): if shieve2[i]: prime.append(i+1) while True : try : n=int(input()) m=bisect.bisect(prime,n) if n==prime[m-1]: print(prime[m-2],prime[m]) else : print(prime[m-1],prime[m]) except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var prime : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{11}->union(Sequence{ 13 }))))) ; var shieve1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, 257) ; for i : prime do ( var itr : double := i - 1 ; while (itr < 256) do ( shieve1[itr+1] := 0 ; itr := itr + i)) ; for i : Integer.subrange(16, 256-1) do ( if shieve1[i+1] then ( execute ((i + 1) : prime) ) else skip) ; var shieve2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (50101)) ; for i : prime do ( itr := i - 1 ; while (itr < 50100) do ( shieve2[itr+1] := 0 ; itr := itr + i)) ; for i : Integer.subrange(257, 50101-1) do ( if shieve2[i+1] then ( execute ((i + 1) : prime) ) else skip) ; while true do ( try ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : OclAny := bisect.bisect(prime, n) ; if n = prime[m - 1+1] then ( execute (prime[m - 2+1])->display() ) else ( execute (prime[m - 1+1])->display() )) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 2==0 : print(n*n//2) for x in range(n//2): for x in range(n//2): print("C.",end="") print("") for x in range(n//2): print(".C",end="") print("") else : print((((n//2)+1)*((n//2)+1))+((n//2)*(n//2))) for x in range(n//2): for x in range(n//2): print("C.",end="") print("C") for x in range(n//2): print(".C",end="") print(".") for x in range(n//2): print("C.",end="") print("C") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( execute (n * n div 2)->display() ; for x : Integer.subrange(0, n div 2-1) do ( for x : Integer.subrange(0, n div 2-1) do ( execute ("C.")->display()) ; execute ("")->display() ; for x : Integer.subrange(0, n div 2-1) do ( execute (".C")->display()) ; execute ("")->display()) ) else ( execute ((((n div 2) + 1) * ((n div 2) + 1)) + ((n div 2) * (n div 2)))->display() ; for x : Integer.subrange(0, n div 2-1) do ( for x : Integer.subrange(0, n div 2-1) do ( execute ("C.")->display()) ; execute ("C")->display() ; for x : Integer.subrange(0, n div 2-1) do ( execute (".C")->display()) ; execute (".")->display()) ; for x : Integer.subrange(0, n div 2-1) do ( execute ("C.")->display()) ; execute ("C")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n): is_coder=True r=[] c=0 l_odd='C.'*(n//2)+('C' if n % 2==1 else '') l_even='.C'*(n//2)+('.' if n % 2==1 else '') c_even=n//2 c_odd=c_even+(1 if n % 2==1 else 0) for _ in range(n): if is_coder : l=l_odd c+=c_odd else : l=l_even c+=c_even is_coder=not is_coder r.append(l) return c,r def print_res(c,r): print(c) for l in r : print(l) n=int(input()) print_res(*solve(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; print_res((argument * (test (logical_test (comparison (expr (atom (name solve)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))); operation solve(n : OclAny) : OclAny pre: true post: true activity: var is_coder : boolean := true ; var r : Sequence := Sequence{} ; var c : int := 0 ; var l_odd : String := StringLib.nCopies('C.', (n div 2)) + (if n mod 2 = 1 then 'C' else '' endif) ; var l_even : String := StringLib.nCopies('.C', (n div 2)) + (if n mod 2 = 1 then '.' else '' endif) ; var c_even : int := n div 2 ; var c_odd : int := c_even + (if n mod 2 = 1 then 1 else 0 endif) ; for _anon : Integer.subrange(0, n-1) do ( if is_coder then ( var l : String := l_odd ; c := c + c_odd ) else ( l := l_even ; c := c + c_even ) ; is_coder := not(is_coder) ; execute ((l) : r)) ; return c, r; operation print_res(c : OclAny, r : OclAny) pre: true post: true activity: execute (c)->display() ; for l : r do ( execute (l)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) ans=(n-6)//3 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := (n - 6) div 3 ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) counter=0 board=[] for i in range(n): if i % 2==0 : s="" for j in range(n): if j % 2==0 : counter+=1 s+="C" else : s+="." board.append(s) else : s="" for j in range(n): if j % 2==0 : s+="." else : counter+=1 s+="C" board.append(s) print(counter) for row in board : print(row) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var counter : int := 0 ; var board : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if i mod 2 = 0 then ( var s : String := "" ; for j : Integer.subrange(0, n-1) do ( if j mod 2 = 0 then ( counter := counter + 1 ; s := s + "C" ) else ( s := s + "." )) ; execute ((s) : board) ) else ( s := "" ; for j : Integer.subrange(0, n-1) do ( if j mod 2 = 0 then ( s := s + "." ) else ( counter := counter + 1 ; s := s + "C" )) ; execute ((s) : board) )) ; execute (counter)->display() ; for row : board do ( execute (row)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) res=(n**2+1)//2 print(res) for i in range(n): print(("C."*((n+2)//2))[i & 1 : n+(i & 1)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : int := ((n)->pow(2) + 1) div 2 ; execute (res)->display() ; for i : Integer.subrange(0, n-1) do ( execute ((StringLib.nCopies("C.", ((n + 2) div 2))).subrange(MathLib.bitwiseAnd(i, 1)+1, n + (MathLib.bitwiseAnd(i, 1))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- li=list(map(int,input().split())) ans=10**9 for bit_state in range(1<<4): if bin(bit_state).count("1")==2 : tmp1=0 tmp2=0 for i in range(4): if bit_state &(1<collect( _x | (OclType["int"])->apply(_x) )) ; var ans : double := (10)->pow(9) ; for bit_state : Integer.subrange(0, 1 * (2->pow(4))-1) do ( if bin(bit_state)->count("1") = 2 then ( var tmp1 : int := 0 ; var tmp2 : int := 0 ; for i : Integer.subrange(0, 4-1) do ( if MathLib.bitwiseAnd(bit_state, (1 * (2->pow(i)))) then ( tmp1 := tmp1 + li[i+1] ) else ( tmp2 := tmp2 + li[i+1] )) ; ans := Set{ans, (tmp1 - tmp2)->abs()}->min() ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) print((a*a+1)//2) for i in range(a): for j in range(a): if i % 2==j % 2 : print("C",end="") else : print(".",end="") print("") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((a * a + 1) div 2)->display() ; for i : Integer.subrange(0, a-1) do ( for j : Integer.subrange(0, a-1) do ( if i mod 2 = j mod 2 then ( execute ("C")->display() ) else ( execute (".")->display() )) ; execute ("")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt N=100000 prime=[True for i in range(N+1)] def SieveOfEratosthenes(): k=int(sqrt(N))+1 for p in range(2,k,1): if(prime[p]==True): for i in range(p*2,N+1,p): prime[i]=False def longestPrimeSubarray(arr,n): left=[0 for i in range(n)] right=[0 for i in range(n)] primecount=0 res=0 for i in range(n): left[i]=primecount if(prime[arr[i]]): primecount+=1 else : primecount=0 primecount=0 i=n-1 while(i>=0): right[i]=primecount if(prime[arr[i]]): primecount+=1 else : primecount=0 i-=1 for i in range(n): res=max(res,left[i]+right[i]) return res if __name__=='__main__' : arr=[2,8,5,7,9,5,7] SieveOfEratosthenes() n=len(arr) print("largest length of PrimeSubarray",longestPrimeSubarray(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 100000 ; var prime : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (true)) ; skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{2}->union(Sequence{8}->union(Sequence{5}->union(Sequence{7}->union(Sequence{9}->union(Sequence{5}->union(Sequence{ 7 })))))) ; SieveOfEratosthenes() ; n := (arr)->size() ; execute ("largest length of PrimeSubarray")->display() ) else skip; operation SieveOfEratosthenes() pre: true post: true activity: var k : int := ("" + ((sqrt(N))))->toInteger() + 1 ; for p : Integer.subrange(2, k-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (prime[p+1] = true) then ( for i : Integer.subrange(p * 2, N + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip); operation longestPrimeSubarray(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var left : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var right : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var primecount : int := 0 ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( left[i+1] := primecount ; if (prime[arr[i+1]+1]) then ( primecount := primecount + 1 ) else ( primecount := 0 )) ; primecount := 0 ; var i : double := n - 1 ; while (i >= 0) do ( right[i+1] := primecount ; if (prime[arr[i+1]+1]) then ( primecount := primecount + 1 ) else ( primecount := 0 ) ; i := i - 1) ; for i : Integer.subrange(0, n-1) do ( res := Set{res, left[i+1] + right[i+1]}->max()) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) move=0 for i in range(1,n): move+=max(arr[i-1]-arr[i],0) print(move) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var move : int := 0 ; for i : Integer.subrange(1, n-1) do ( move := move + Set{arr[i - 1+1] - arr[i+1], 0}->max()) ; execute (move)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) f=0 count=0 c=0 mm=[] for i in range(n-1): if a[i]>a[i+1]: f=1 c=1 count+=1 x=i+1 else : if c==1 : mm.append(a[x-count : x+1]) c=0 count=0 if c==1 : mm.append(a[x-count : x+1]) cc=0 if f==0 : print("0") else : for j in range(len(mm)): cc+=max(mm[j])-min(mm[j]) print(cc) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var f : int := 0 ; var count : int := 0 ; var c : int := 0 ; var mm : Sequence := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( if (a[i+1]->compareTo(a[i + 1+1])) > 0 then ( f := 1 ; c := 1 ; count := count + 1 ; var x : OclAny := i + 1 ) else ( if c = 1 then ( execute ((a.subrange(x - count+1, x + 1)) : mm) ; c := 0 ; count := 0 ) else skip )) ; if c = 1 then ( execute ((a.subrange(x - count+1, x + 1)) : mm) ) else skip ; var cc : int := 0 ; if f = 0 then ( execute ("0")->display() ) else ( for j : Integer.subrange(0, (mm)->size()-1) do ( cc := cc + (mm[j+1])->max() - (mm[j+1])->min()) ; execute (cc)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) sequence=[int(i)for i in input().split()] maxx=0 s=0 for i in range(n-1): s=sequence[i]-sequence[i+1] if sequence[i+1]toInteger() ; var sequence : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var maxx : int := 0 ; var s : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( s := sequence[i+1] - sequence[i + 1+1] ; if (sequence[i + 1+1]->compareTo(sequence[i+1])) < 0 then ( maxx := maxx + s ) else skip) ; execute (maxx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): c=0 for i in range(n-1): if arr[i]>arr[i+1]: c+=arr[i]-arr[i+1] return c from sys import stdin input=stdin.readline n=int(input()) arr=[int(x)for x in input().split()] print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (solve())->display(); operation solve() : OclAny pre: true post: true activity: var c : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if (arr[i+1]->compareTo(arr[i + 1+1])) > 0 then ( c := c + arr[i+1] - arr[i + 1+1] ) else skip) ; return c; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) sequence=[int(i)for i in input().split()] maxx=0 s=0 for i in range(n-1): s=sequence[i]-sequence[i+1] if sequence[i+1]toInteger() ; var sequence : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var maxx : int := 0 ; var s : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( s := sequence[i+1] - sequence[i + 1+1] ; if (sequence[i + 1+1]->compareTo(sequence[i+1])) < 0 then ( maxx := maxx + s ) else skip) ; execute (maxx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fib(f,N): f[1]=1 f[2]=1 for i in range(3,N+1): f[i]=f[i-1]+f[i-2] def fiboTriangle(n): N=n*(n+1)//2 f=[0]*(N+1) fib(f,N) fiboNum=1 for i in range(1,n+1): for j in range(1,i+1): fiboNum=fiboNum+1 print(f[fiboNum],"",end="") print() n=5 fiboTriangle(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 5 ; fiboTriangle(n); operation fib(f : OclAny, N : OclAny) pre: true post: true activity: f[1+1] := 1 ; f[2+1] := 1 ; for i : Integer.subrange(3, N + 1-1) do ( f[i+1] := f[i - 1+1] + f[i - 2+1]); operation fiboTriangle(n : OclAny) pre: true post: true activity: N := n * (n + 1) div 2 ; f := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; fib(f, N) ; var fiboNum : int := 1 ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, i + 1-1) do ( fiboNum := fiboNum + 1 ; execute (f[fiboNum+1])->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) print(n//3-2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n div 3 - 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque n,m=map(int,input().split()) M=m g={i :[]for i in range(1,n+1)} while m : n1,n2=map(int,input().split()) g[n1].append(n2) g[n2].append(n1) m=m-1 v=[False for _ in range(n+1)] cities=0 for start in range(1,n+1): if v[start]==False : v[start]=True queue=deque([start]) while queue : curr=queue.popleft() for i in g[curr]: if v[i]==False : v[i]=True queue.append(i) cities=cities+1 if M==n and cities==1 : print("FHTAGN!") else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var M : OclAny := m ; var g : Map := Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | Map{i |-> Sequence{}})->unionAll() ; while m do ( var n1 : OclAny := null; var n2 : OclAny := null; Sequence{n1,n2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n1)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n2)))))))) )))) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n2)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n1)))))))) )))) ; var m : double := m - 1) ; var v : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (false)) ; var cities : int := 0 ; for start : Integer.subrange(1, n + 1-1) do ( if v[start+1] = false then ( v[start+1] := true ; var queue : Sequence := (Sequence{ start }) ; while queue do ( var curr : OclAny := queue->first() ; queue := queue->tail() ; for i : g[curr+1] do ( if v[i+1] = false then ( v[i+1] := true ; execute ((i) : queue) ) else skip)) ; cities := cities + 1 ) else skip) ; if M = n & cities = 1 then ( execute ("FHTAGN!")->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,data): self.data=data self.prev=None self.next=None def push(head_ref,new_data): new_node=Node(new_data) new_node.next=head_ref if head_ref!=None : head_ref.prev=new_node head_ref=new_node return head_ref def makeOddNode(head_ref,A,n): ptr=head_ref i=0 while ptr!=None : next=ptr.next if ptr.data % 2==0 : ptr.data=A[i] i+=1 ptr=next def printList(head): while head!=None : print(head.data,end=" ") head=head.next if __name__=="__main__" : head=None Arr=[3,5,23,17,1] head=push(head,4) head=push(head,7) head=push(head,8) head=push(head,9) head=push(head,6) n=len(Arr) print("Original List:",end=" ") printList(head) print() makeOddNode(head,Arr,n) print("New odd List:",end=" ") printList(head) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute prev : OclAny := null; attribute next : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.prev := null ; self.next := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( head := null ; var Arr : Sequence := Sequence{3}->union(Sequence{5}->union(Sequence{23}->union(Sequence{17}->union(Sequence{ 1 })))) ; head := push(head, 4) ; head := push(head, 7) ; head := push(head, 8) ; head := push(head, 9) ; head := push(head, 6) ; n := (Arr)->size() ; execute ("Original List:")->display() ; printList(head) ; execute (->display() ; makeOddNode(head, Arr, n) ; execute ("New odd List:")->display() ; printList(head) ) else skip; operation push(head_ref : OclAny, new_data : OclAny) : OclAny pre: true post: true activity: var new_node : Node := (Node.newNode()).initialise(new_data) ; new_node.next := head_ref ; if head_ref /= null then ( head_ref.prev := new_node ) else skip ; head_ref := new_node ; return head_ref; operation makeOddNode(head_ref : OclAny, A : OclAny, n : OclAny) pre: true post: true activity: var ptr : OclAny := head_ref ; var i : int := 0 ; while ptr /= null do ( var next : OclAny := ptr.next ; if ptr.data mod 2 = 0 then ( ptr.data := A[i+1] ; i := i + 1 ) else skip ; ptr := next); operation printList(head : OclAny) pre: true post: true activity: while head /= null do ( execute (head.data)->display() ; head := head.next); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys import queue import itertools from heapq import heappop,heappush import random def solve(): def bfs(start): used[start]=0 q,it=[start],0 cycle=0 while it!=len(q): k=q[it] for u in g[k]: if used[u]==-1 : q.append(u) used[u]=k else : if u!=used[k]: cycle+=1 it+=1 return cycle n,m=map(int,input().split()) g=[[]for i in range(n)] for i in range(m): v,u=map(int,input().split()) g[v-1].append(u-1) g[u-1].append(v-1) used=[-1 for i in range(n)] c=bfs(0)//2 if c==1 and-1 not in used : print("FHTAGN!") else : print("NO") if __name__=='__main__' : multi_test=0 if multi_test : t=int(sys.stdin.readline()) for _ in range(t): solve() else : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var multi_test : int := 0 ; if multi_test then ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( solve()) ) else ( solve() ) ) else skip; operation solve() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var g : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, m-1) do ( var v : OclAny := null; var u : OclAny := null; Sequence{v,u} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name u))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name u))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name v))) - (expr (atom (number (integer 1)))))))))) ))))) ; var used : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (-1)) ; var c : int := bfs(0) div 2 ; if c = 1 & (used)->excludes(-1) then ( execute ("FHTAGN!")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict nodos=defaultdict(list) n,m=map(int,input().split(' ')) for i in range(m): a,b=map(int,input().split(' ')) nodos[a-1].append(b-1) nodos[b-1].append(a-1) visitadas=[False]*n def DFS(nodo): visitadas[nodo]=True for i in nodos[nodo]: if not visitadas[i]: DFS(i) conjuntos=0 for i in range(n): if not visitadas[i]: DFS(i) conjuntos+=1 if conjuntos==1 and n==m : print('FHTAGN!') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var nodos : OclAny := defaultdict(OclType["Sequence"]) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name nodos)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name nodos)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ))))) ; var visitadas : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ; skip ; var conjuntos : int := 0 ; for i : Integer.subrange(0, n-1) do ( if not(visitadas[i+1]) then ( DFS(i) ; conjuntos := conjuntos + 1 ) else skip) ; if conjuntos = 1 & n = m then ( execute ('FHTAGN!')->display() ) else ( execute ('NO')->display() ); operation DFS(nodo : OclAny) pre: true post: true activity: visitadas[nodo+1] := true ; for i : nodos[nodo+1] do ( if not(visitadas[i+1]) then ( DFS(i) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def get_root(s): v=[] while not s==root[s]: v.append(s) s=root[s] for i in v : root[i]=s return s def unite(s,t): rs,rt=get_root(s),get_root(t) if not rs ^ rt : return if rank[s]==rank[t]: rank[rs]+=1 if rank[s]>=rank[t]: root[rt]=rs size[rs]+=size[rt] else : root[rs]=rt size[rt]+=size[rs] return def same(s,t): return True if get_root(s)==get_root(t)else False def get_size(s): return size[get_root(s)] n,m=map(int,input().split()) G=[[]for _ in range(n+1)] root=[i for i in range(n+1)] rank=[1 for _ in range(n+1)] size=[1 for _ in range(n+1)] c=0 for _ in range(m): x,y=map(int,input().split()) if same(x,y): c+=1 unite(x,y) ans="FHTAGN!" if not c ^ 1 and not n ^ m else "NO" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; skip ; skip ; skip ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var G : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var root : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (i)) ; var rank : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (1)) ; var size : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (1)) ; var c : int := 0 ; for _anon : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if same(x, y) then ( c := c + 1 ) else skip ; unite(x, y)) ; var ans : String := if not(MathLib.bitwiseXor(c, 1)) & not(MathLib.bitwiseXor(n, m)) then "FHTAGN!" else "NO" endif ; execute (ans)->display(); operation get_root(s : OclAny) : OclAny pre: true post: true activity: var v : Sequence := Sequence{} ; while not(s = root[s+1]) do ( execute ((s) : v) ; s := root[s+1]) ; for i : v do ( root[i+1] := s) ; return s; operation unite(s : OclAny, t : OclAny) pre: true post: true activity: var rs : OclAny := null; var rt : OclAny := null; Sequence{rs,rt} := Sequence{get_root(s),get_root(t)} ; if not(MathLib.bitwiseXor(rs, rt)) then ( return ) else skip ; if rank[s+1] = rank[t+1] then ( rank[rs+1] := rank[rs+1] + 1 ) else skip ; if (rank[s+1]->compareTo(rank[t+1])) >= 0 then ( root[rt+1] := rs ; size[rs+1] := size[rs+1] + size[rt+1] ) else ( root[rs+1] := rt ; size[rt+1] := size[rt+1] + size[rs+1] ) ; return; operation same(s : OclAny, t : OclAny) : OclAny pre: true post: true activity: return if get_root(s) = get_root(t) then true else false endif; operation get_size(s : OclAny) : OclAny pre: true post: true activity: return size[get_root(s)+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dfs(v): visited[v]=1 for u in graph[v]: if visited[u]==0 : dfs(u) n,m=map(int,input().split()) graph=[[]for _ in range(n)] for _ in range(m): x,y=map(int,input().split()) graph[x-1].append(y-1) graph[y-1].append(x-1) visited=[0]*n dfs(0) print('FHTAGN!' if visited.count(1)==n and n>=3 and n==m else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var graph : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ))))) ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; dfs(0) ; execute (if visited->count(1) = n & n >= 3 & n = m then 'FHTAGN!' else 'NO' endif)->display(); operation dfs(v : OclAny) pre: true post: true activity: visited[v+1] := 1 ; for u : graph[v+1] do ( if visited[u+1] = 0 then ( dfs(u) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INT_MAX=32767 def eggDrop(n,k): eggFloor=[[0 for x in range(k+1)]for x in range(n+1)] for i in range(1,n+1): eggFloor[i][1]=1 eggFloor[i][0]=0 for j in range(1,k+1): eggFloor[1][j]=j for i in range(2,n+1): for j in range(2,k+1): eggFloor[i][j]=INT_MAX for x in range(1,j+1): res=1+max(eggFloor[i-1][x-1],eggFloor[i][j-x]) if resdisplay(); operation eggDrop(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var eggFloor : Sequence := Integer.subrange(0, n + 1-1)->select(x | true)->collect(x | (Integer.subrange(0, k + 1-1)->select(x | true)->collect(x | (0)))) ; for i : Integer.subrange(1, n + 1-1) do ( eggFloor[i+1][1+1] := 1 ; eggFloor[i+1]->first() := 0) ; for j : Integer.subrange(1, k + 1-1) do ( eggFloor[1+1][j+1] := j) ; for i : Integer.subrange(2, n + 1-1) do ( for j : Integer.subrange(2, k + 1-1) do ( eggFloor[i+1][j+1] := INT_MAX ; for x : Integer.subrange(1, j + 1-1) do ( var res : int := 1 + Set{eggFloor[i - 1+1][x - 1+1], eggFloor[i+1][j - x+1]}->max() ; if (res->compareTo(eggFloor[i+1][j+1])) < 0 then ( eggFloor[i+1][j+1] := res ) else skip))) ; return eggFloor[n+1][k+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) mass=list(map(int,input().split())) ans=[] b=False for i in range(1,n-1): if mass[i-1]mass[i+1]: b=True ans.append(i) ans.append(i+1) ans.append(i+2) break if b : print("YES") print(*ans) else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mass : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : Sequence := Sequence{} ; var b : boolean := false ; for i : Integer.subrange(1, n - 1-1) do ( if (mass[i - 1+1]->compareTo(mass[i+1])) < 0 & (mass[i+1]->compareTo(mass[i + 1+1])) > 0 then ( b := true ; execute ((i) : ans) ; execute ((i + 1) : ans) ; execute ((i + 2) : ans) ; break ) else skip) ; if b then ( execute ("YES")->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for n in range(int(input())): T=int(input()) P=list(map(int,input().split())) for t in range(T-2): if P[t]P[t+2]: print("YES") print(f"{t+1}{t+2}{t+3}") break else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for n : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var P : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (compound_stmt for (exprlist (expr (atom (name t)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name T))) - (expr (atom (number (integer 2)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name P)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])))) < (comparison (expr (atom (name P)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name t))) + (expr (atom (number (integer 1)))))))))) ])))))) and (logical_test (comparison (comparison (expr (atom (name P)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name t))) + (expr (atom (number (integer 1)))))))))) ])))) > (comparison (expr (atom (name P)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name t))) + (expr (atom (number (integer 2)))))))))) ])))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom f "{t+1}{t+2}{t+3}"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: a=*map(int,s.split()),; i=''.join('01'[xz]for x,y,z in zip(a,a[1 :],a[2 :])).find('1'); print(*(['YES',i+1,i+2,i+3],['NO'])[i<0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var a : OclAny := (testlist_star_expr (star_expr * (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name s)) (trailer . (name split) (arguments ( ))))))))) ))))) ,); var i : OclAny := ''.join((argument (test (logical_test (comparison (expr (atom '01') (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (comparison (comparison (expr (atom (name x)))) < (comparison (expr (atom (name y))))) > (comparison (expr (atom (name z))))))))) ])))))) (comp_for for (exprlist (expr (atom (name x))) , (expr (atom (name y))) , (expr (atom (name z)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) :)) ])))))))) )))))))))->indexOf('1') - 1; execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom 'YES'))))) , (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 2)))))))) , (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 3))))))))) ]))))) , (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom 'NO')))))) ])))))) )) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (comparison (expr (atom (name i)))) < (comparison (expr (atom (number (integer 0)))))))))) ]))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) c=0 for i in range(1,n-1): if(a[i]>a[i-1]and a[i]>a[i+1]): c=1 print("YES") print(i,i+1,i+2) break if(c==0): print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; for i : Integer.subrange(1, n - 1-1) do ( if ((a[i+1]->compareTo(a[i - 1+1])) > 0 & (a[i+1]->compareTo(a[i + 1+1])) > 0) then ( c := 1 ; execute ("YES")->display() ; execute (i)->display() ; break ) else skip) ; if (c = 0) then ( execute ("NO")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) print((n//3)-2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((n div 3) - 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s_max=[0] for i in range(1,11): s=0 for j in range(i): s+=(10-j-1)*(i-j) s_max.append(s) def check(u,r,s,m): if r==0 : return s==0 n=0 for i in range(10): n*=2 if u[i]: n+=1 if(n,r,s)in m : return m[(n,r,s)] if s<0 or s>s_max[r]: return 0 ans=0 for i in range(10): if not u[i]: u[i]=True ans+=check(u,r-1,s-i*r,m) u[i]=False m[(n,r,s)]=ans return m[(n,r,s)] memo={} while True : try : n,s=map(int,input().split()) used=[False for i in range(10)] ans=check(used,n,s,memo) print(ans) except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s_max : Sequence := Sequence{ 0 } ; for i : Integer.subrange(1, 11-1) do ( var s : int := 0 ; for j : Integer.subrange(0, i-1) do ( s := s + (10 - j - 1) * (i - j)) ; execute ((s) : s_max)) ; skip ; var memo : OclAny := Set{} ; while true do ( try ( Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var used : Sequence := Integer.subrange(0, 10-1)->select(i | true)->collect(i | (false)) ; ans := check(used, n, s, memo) ; execute (ans)->display()) catch (_e : OclException) do ( break) ); operation check(u : OclAny, r : OclAny, s : OclAny, m : OclAny) : OclAny pre: true post: true activity: if r = 0 then ( return s = 0 ) else skip ; var n : int := 0 ; for i : Integer.subrange(0, 10-1) do ( n := n * 2 ; if u[i+1] then ( n := n + 1 ) else skip) ; if (m)->includes(Sequence{n, r, s}) then ( return m[Sequence{n, r, s}+1] ) else skip ; if s < 0 or (s->compareTo(s_max[r+1])) > 0 then ( return 0 ) else skip ; var ans : int := 0 ; for i : Integer.subrange(0, 10-1) do ( if not(u[i+1]) then ( u[i+1] := true ; ans := ans + check(u, r - 1, s - i * r, m) ; u[i+1] := false ) else skip) ; m[Sequence{n, r, s}+1] := ans ; return m[Sequence{n, r, s}+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t1=tuple(map(int,input().split(":"))) t2=tuple(map(int,input().split(":"))) def mts(t): return t[0]*60+t[1] t1=mts(t1) t2=mts(t2) def stm(m): return map(str,[m//60,m % 60]) t=stm((t1+t2)//2) print(":".join([('00'+s)[-2 :]for s in t])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t1 : Sequence := ((input().split(":"))->collect( _x | (OclType["int"])->apply(_x) )) ; var t2 : Sequence := ((input().split(":"))->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; t1 := mts(t1) ; t2 := mts(t2) ; skip ; t := stm((t1->union(t2)) div 2) ; execute (StringLib.sumStringsWithSeparator((t->select(s | true)->collect(s | (('00' + s).subrange(-2+1)))), ":"))->display(); operation mts(t : OclAny) : OclAny pre: true post: true activity: return t->first() * 60 + t[1+1]; operation stm(m : OclAny) : OclAny pre: true post: true activity: return (Sequence{m div 60}->union(Sequence{ m mod 60 }))->collect( _x | (OclType["String"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h1,m1=[int(i)for i in input().split(":")] h2,m2=[int(i)for i in input().split(":")] total_min=(h2-h1)*60+m2-m1 half=total_min//2 h=h1+half//60 m=m1+half % 60 if m>=60 : h+=1 m=m % 60 h=str(h)if h>9 else "0"+str(h) m=str(m)if m>9 else "0"+str(m) print(h+":"+m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h1 : OclAny := null; var m1 : OclAny := null; Sequence{h1,m1} := input().split(":")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var h2 : OclAny := null; var m2 : OclAny := null; Sequence{h2,m2} := input().split(":")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var total_min : double := (h2 - h1) * 60 + m2 - m1 ; var half : int := total_min div 2 ; var h : OclAny := h1 + half div 60 ; var m : OclAny := m1 + half mod 60 ; if m >= 60 then ( h := h + 1 ; m := m mod 60 ) else skip ; h := if h > 9 then ("" + ((h))) else "0" + ("" + ((h))) endif ; m := if m > 9 then ("" + ((m))) else "0" + ("" + ((m))) endif ; execute (h + ":" + m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- start,end=input(),input() start=int(start[: 2])*60+int(start[3 :]) end=int(end[: 2])*60+int(end[3 :]) mid=(start+end)//2 m=mid//60 s=mid % 60 print(f"{'0'+str(m)if m<10 else m}:{'0'+str(s)if s<10 else s}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var start : OclAny := null; var end : OclAny := null; Sequence{start,end} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine()} ; var start : int := ("" + ((start.subrange(1,2))))->toInteger() * 60 + ("" + ((start.subrange(3+1))))->toInteger() ; var end : int := ("" + ((end.subrange(1,2))))->toInteger() * 60 + ("" + ((end.subrange(3+1))))->toInteger() ; var mid : int := (start + end) div 2 ; var m : int := mid div 60 ; var s : int := mid mod 60 ; execute (StringLib.formattedString("{'0'+str(m)if m<10 else m}:{'0'+str(s)if s<10 else s}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,m=map(int,input().split(':')) h2,m2=map(int,input().split(':')) start=h*60+m finish=h2*60+m2 middle=(start+finish)//2 h3='0'+str(middle//60)if middle//60<10 else str(middle//60) m3='0'+str(middle % 60)if middle % 60<10 else str(middle % 60) print(f'{h3}:{m3}') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var m : OclAny := null; Sequence{h,m} := (input().split(':'))->collect( _x | (OclType["int"])->apply(_x) ) ; var h2 : OclAny := null; var m2 : OclAny := null; Sequence{h2,m2} := (input().split(':'))->collect( _x | (OclType["int"])->apply(_x) ) ; var start : double := h * 60 + m ; var finish : double := h2 * 60 + m2 ; var middle : int := (start + finish) div 2 ; var h3 : String := if middle div 60 < 10 then '0' + ("" + ((middle div 60))) else ("" + ((middle div 60))) endif ; var m3 : String := if middle mod 60 < 10 then '0' + ("" + ((middle mod 60))) else ("" + ((middle mod 60))) endif ; execute (StringLib.formattedString('{h3}:{m3}'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,n=input().split(':') m1,n1=input().split(':') m=int(m) m1=int(m1) n=int(n) n1=int(n1) x3=(((m*60+n)+(m1*60+n1))/2)/60 y3=(((m*60+n)+(m1*60+n1))/2)% 60 if x3>=10 : if y3>=10 : print("%d:%d" %(x3,y3)) else : print("%d:0%d" %(x3,y3)) else : if y3>=10 : print("0%d:%d" %(x3,y3)) else : print("0%d:0%d" %(x3,y3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := input().split(':') ; var m1 : OclAny := null; var n1 : OclAny := null; Sequence{m1,n1} := input().split(':') ; var m : int := ("" + ((m)))->toInteger() ; var m1 : int := ("" + ((m1)))->toInteger() ; var n : int := ("" + ((n)))->toInteger() ; var n1 : int := ("" + ((n1)))->toInteger() ; var x3 : double := (((m * 60 + n) + (m1 * 60 + n1)) / 2) / 60 ; var y3 : int := (((m * 60 + n) + (m1 * 60 + n1)) / 2) mod 60 ; if x3 >= 10 then ( if y3 >= 10 then ( execute (StringLib.format("%d:%d",Sequence{x3, y3}))->display() ) else ( execute (StringLib.format("%d:0%d",Sequence{x3, y3}))->display() ) ) else ( if y3 >= 10 then ( execute (StringLib.format("0%d:%d",Sequence{x3, y3}))->display() ) else ( execute (StringLib.format("0%d:0%d",Sequence{x3, y3}))->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) s=input() i=len(s)-1 s1="" while i!=-1 : if s[i]=="0" : s1+=chr(96+int(s[i-2]+s[i-1])) i-=3 else : s1+=chr(96+int(s[i])) i-=1 print(s1[: :-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var i : double := (s)->size() - 1 ; var s1 : String := "" ; while i /= -1 do ( if s[i+1] = "0" then ( s1 := s1 + (96 + ("" + ((s[i - 2+1] + s[i - 1+1])))->toInteger())->byte2char() ; i := i - 3 ) else ( s1 := s1 + (96 + ("" + ((s[i+1])))->toInteger())->byte2char() ; i := i - 1 )) ; execute (s1(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): n=int(input()) arr=input() arr=arr.replace("100","j") arr=arr.replace("200","t") arr=arr.replace("110","k") arr=arr.replace("120","l") arr=arr.replace("130","m") arr=arr.replace("140","n") arr=arr.replace("150","o") arr=arr.replace("160","p") arr=arr.replace("170","q") arr=arr.replace("180","r") arr=arr.replace("190","s") arr=arr.replace("210","u") arr=arr.replace("220","v") arr=arr.replace("230","w") arr=arr.replace("240","x") arr=arr.replace("250","y") arr=arr.replace("260","z") arr=arr.replace("1","a") arr=arr.replace("2","b") arr=arr.replace("3","c") arr=arr.replace("4","d") arr=arr.replace("5","e") arr=arr.replace("6","f") arr=arr.replace("7","g") arr=arr.replace("8","h") arr=arr.replace("9","i") print(arr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : String := (OclFile["System.in"]).readLine() ; arr := arr.replace("100", "j") ; arr := arr.replace("200", "t") ; arr := arr.replace("110", "k") ; arr := arr.replace("120", "l") ; arr := arr.replace("130", "m") ; arr := arr.replace("140", "n") ; arr := arr.replace("150", "o") ; arr := arr.replace("160", "p") ; arr := arr.replace("170", "q") ; arr := arr.replace("180", "r") ; arr := arr.replace("190", "s") ; arr := arr.replace("210", "u") ; arr := arr.replace("220", "v") ; arr := arr.replace("230", "w") ; arr := arr.replace("240", "x") ; arr := arr.replace("250", "y") ; arr := arr.replace("260", "z") ; arr := arr.replace("1", "a") ; arr := arr.replace("2", "b") ; arr := arr.replace("3", "c") ; arr := arr.replace("4", "d") ; arr := arr.replace("5", "e") ; arr := arr.replace("6", "f") ; arr := arr.replace("7", "g") ; arr := arr.replace("8", "h") ; arr := arr.replace("9", "i") ; execute (arr)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) li=input() li=li.replace("100","j") li=li.replace("200","t") li=li.replace("110","k") li=li.replace("120","l") li=li.replace("130","m") li=li.replace("140","n") li=li.replace("150","o") li=li.replace("160","p") li=li.replace("170","q") li=li.replace("180","r") li=li.replace("190","s") li=li.replace("210","u") li=li.replace("220","v") li=li.replace("230","w") li=li.replace("240","x") li=li.replace("250","y") li=li.replace("260","z") li=li.replace("1","a") li=li.replace("2","b") li=li.replace("3","c") li=li.replace("4","d") li=li.replace("5","e") li=li.replace("6","f") li=li.replace("7","g") li=li.replace("8","h") li=li.replace("9","i") print(li) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li : String := (OclFile["System.in"]).readLine() ; li := li.replace("100", "j") ; li := li.replace("200", "t") ; li := li.replace("110", "k") ; li := li.replace("120", "l") ; li := li.replace("130", "m") ; li := li.replace("140", "n") ; li := li.replace("150", "o") ; li := li.replace("160", "p") ; li := li.replace("170", "q") ; li := li.replace("180", "r") ; li := li.replace("190", "s") ; li := li.replace("210", "u") ; li := li.replace("220", "v") ; li := li.replace("230", "w") ; li := li.replace("240", "x") ; li := li.replace("250", "y") ; li := li.replace("260", "z") ; li := li.replace("1", "a") ; li := li.replace("2", "b") ; li := li.replace("3", "c") ; li := li.replace("4", "d") ; li := li.replace("5", "e") ; li := li.replace("6", "f") ; li := li.replace("7", "g") ; li := li.replace("8", "h") ; li := li.replace("9", "i") ; execute (li)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=eval(input()) for i in range(t): n=eval(input()) s=input() ans="" i=0 while i=3 : ans=ans+str(chr(ord('a')-1+int(s[i]))) i+=1 else : if i+2>=n or s[i+2]!='0' or(i+3compareTo(n)) < 0 do ( if ("" + ((s[i+1])))->toInteger() >= 3 then ( ans := ans + ("" + (((('a')->char2byte() - 1 + ("" + ((s[i+1])))->toInteger())->byte2char()))) ; i := i + 1 ) else ( if (i + 2->compareTo(n)) >= 0 or s[i + 2+1] /= '0' or ((i + 3->compareTo(n)) < 0 & s[i + 3+1] = '0') then ( ans := ans + ("" + (((('a')->char2byte() - 1 + ("" + ((s[i+1])))->toInteger())->byte2char()))) ; i := i + 1 ) else ( var temp : int := ("" + ((s[i+1])))->toInteger() * 10 + ("" + ((s[i + 1+1])))->toInteger() ; ans := ans + (temp + ('a')->char2byte() - 1)->byte2char() ; i := i + 3 ) )) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) t,=R() def decode(value): return chr(int(value)+96) for i in range(t): n,=R() code,=R() code_str=str(code) decode_str="" point=len(code_str)-1 while(point>=0): if(code_str[point]=="0" and len(code_str)>2): decode_str=decode(code_str[point-2 : point])+decode_str point-=3 else : decode_str=decode(code_str[point])+decode_str point-=1 print(decode_str) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := R->apply() ; skip ; for i : Integer.subrange(0, t-1) do ((testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name n)))))) ,)} := R->apply() ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name code)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name code)))))) ,)} := R->apply() ; var code_str : String := ("" + ((code))) ; var decode_str : String := "" ; var point : double := (code_str)->size() - 1 ; while (point >= 0) do ( if (code_str[point+1] = "0" & (code_str)->size() > 2) then ( decode_str := decode(code_str.subrange(point - 2+1, point)) + decode_str ; point := point - 3 ) else ( decode_str := decode(code_str[point+1]) + decode_str ; point := point - 1 )) ; execute (decode_str)->display()); operation decode(value : OclAny) : OclAny pre: true post: true activity: return (("" + ((value)))->toInteger() + 96)->byte2char(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import(division,absolute_import,print_function,unicode_literals) from sys import stdin def solve(li,n,s,total,cnt): for i in li : value=i*n+total if value>s : break if n-1 : subli=li[:] subli.remove(i) r=range(n-1,0,-1) minimum=value+sum(i*j for i,j in zip(r,subli)) maximum=value+sum(i*j for i,j in zip(r,subli[: :-1])) if minimum<=s<=maximum : solve(subli,n-1,s,value,cnt) elif value==s : cnt[0]+=1 break cnt=[0] for line in stdin : n,s=(int(s)for s in line.split()) cnt[0]=0 solve(list(range(10)),n,s,0,cnt) print(cnt[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; cnt := Sequence{ 0 } ; for line : stdin do ( Sequence{n,s} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name line)) (trailer . (name split) (arguments ( ))))))))} ; cnt->first() := 0 ; solve((Integer.subrange(0, 10-1)), n, s, 0, cnt) ; execute (cnt->first())->display()); operation solve(li : OclAny, n : OclAny, s : OclAny, total : OclAny, cnt : OclAny) pre: true post: true activity: for i : li do ( var value : double := i * n + total ; if (value->compareTo(s)) > 0 then ( break ) else skip ; if n - 1 then ( var subli : Sequence := li ; execute ((i) /: subli) ; var r : Sequence := Integer.subrange(0 + 1, n - 1)->reverse() ; var minimum : OclAny := value + ((argument (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom (name j))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name r))))))) , (argument (test (logical_test (comparison (expr (atom (name subli)))))))) )))))))))->sum() ; var maximum : OclAny := value + ((argument (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom (name j))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name r))))))) , (argument (test (logical_test (comparison (expr (atom (name subli)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ])))))))) )))))))))->sum() ; if (minimum->compareTo(s)) <= 0 & (s <= maximum) then ( solve(subli, n - 1, s, value, cnt) ) else skip ) else (if value = s then ( cnt->first() := cnt->first() + 1 ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,k=map(int,input().split()) a=list(map(int,input().split())) s=sum(a) ans=0 for i in range(k): d=0 for j in range(i,n,k): d+=a[j] ans=max(ans,abs(s-d)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : OclAny := (a)->sum() ; var ans : int := 0 ; for i : Integer.subrange(0, k-1) do ( var d : int := 0 ; for j : Integer.subrange(i, n-1)->select( $x | ($x - i) mod k = 0 ) do ( d := d + a[j+1]) ; ans := Set{ans, (s - d)->abs()}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=2**63-1 def solve(a,b,n): x=INF for l in range(1,n+1): d,m=divmod(b,l) if not m : for k in range(1,n+1): x=min(x,abs(k*d-a)) return x def main(): a,b,n=map(int,input().split()) print(solve(a,b,n)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INF : double := (2)->pow(63) - 1 ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(a : OclAny, b : OclAny, n : OclAny) : OclAny pre: true post: true activity: var x : OclAny := INF ; for l : Integer.subrange(1, n + 1-1) do ( var d : OclAny := null; var m : OclAny := null; Sequence{d,m} := Sequence{(b div l), (b mod l)} ; if not(m) then ( for k : Integer.subrange(1, n + 1-1) do ( x := Set{x, (k * d - a)->abs()}->min()) ) else skip) ; return x; operation main() pre: true post: true activity: Sequence{a,b,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (solve(a, b, n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,n=map(int,input().split()) score=abs(a-b) for x in range(1,n+1): for y in range(1,n+1): if b*x % y==0 : new_a=b*x//y score=min(score,abs(a-new_a)) print(score) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var n : OclAny := null; Sequence{a,b,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var score : double := (a - b)->abs() ; for x : Integer.subrange(1, n + 1-1) do ( for y : Integer.subrange(1, n + 1-1) do ( if b * x mod y = 0 then ( var new_a : int := b * x div y ; score := Set{score, (a - new_a)->abs()}->min() ) else skip)) ; execute (score)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=998244353 def comb(n,r): if ncollect( _x | (OclType["int"])->apply(_x) ) ; var fa : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (k + 1)) ; var fi : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (k + 1)) ; for i : Integer.subrange(1, k + 1-1) do ( fa[i+1] := fa[i - 1+1] * i mod mod ; fi[i+1] := (fa[i+1])->pow(mod - 2)) ; var ans : int := 0 ; for i : Integer.subrange(0, k - n + 1-1) do ( ans := ans + comb(k - 1, n + i - 1) ; ans := ans mod mod) ; execute (ans)->display(); operation comb(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: if (n->compareTo(r)) < 0 then ( return 0 ) else skip ; if n < 0 or r < 0 then ( return 0 ) else skip ; return fa[n+1] * fi[r+1] mod mod * fi[n - r+1] mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()); p=998244353 ; r=range ; f=[1] for i in r(k): f+=[-~ i*f[i]% p] print(sum(f[-2]*pow(f[i]*f[-2-i],-1,p)for i in r(n-1,k))% p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var p : int := 998244353; var r : OclAny := range; var f : Sequence := Sequence{ 1 } ; for i : r(k) do ( f := f + Sequence{ -MathLib.bitwiseNot(i) * f[i+1] mod p }) ; execute (((argument (test (logical_test (comparison (expr (expr (atom (name f)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 2))))))))) ]))) * (expr (atom (name pow)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name f)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) * (expr (atom (name f)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom - (number (integer 2)))) - (expr (atom (name i))))))))) ])))))))) , (argument (test (logical_test (comparison (expr (atom - (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name p)))))))) )))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name r)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name k)))))))) )))))))))->sum() mod p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def combs_mod(n,k,mod): inv=[1]*(k+1) for i in range(1,k+1): inv[i]=pow(i,mod-2,mod) ans=[1]*(k+1) for i in range(1,k+1): ans[i]=ans[i-1]*(n+1-i)*inv[i]% mod return ans def solve(): mod=998244353 N,K=map(int,input().split()) ans=0 if K=2 : ans-=com2[N-2] elif difdisplay(); operation combs_mod(n : OclAny, k : OclAny, mod : OclAny) : OclAny pre: true post: true activity: var inv : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (k + 1)) ; for i : Integer.subrange(1, k + 1-1) do ( inv[i+1] := (i)->pow(mod - 2)) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (k + 1)) ; for i : Integer.subrange(1, k + 1-1) do ( ans[i+1] := ans[i - 1+1] * (n + 1 - i) * inv[i+1] mod mod) ; return ans; operation solve() : OclAny pre: true post: true activity: mod := 998244353 ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; ans := 0 ; if (K->compareTo(N)) < 0 then ( return ans ) else skip ; var com : OclAny := combs_mod(K, K, mod) ; for r : Integer.subrange(0, K + 1-1) do ( var b : double := K - r ; var dif : double := r - b ; if dif < 0 or (r->compareTo(N)) < 0 then ( continue ) else (if dif = 0 then ( var com2 : OclAny := combs_mod(K - 1, K - 1, mod) ; ans := ans + com2[r+1] ; if N >= 2 then ( ans := ans - com2[N - 2+1] ) else skip ) else (if (dif->compareTo(N)) < 0 then ( ans := ans + com[r+1] - com[N - 1 - dif+1] ) else ( ans := ans + com[r+1] ) ) ) ; ans := ans mod mod) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,k): MOD=998244353 if n>k : return 0 if n==1 : return pow(2,k-1,MOD) pf,kf=1,1 for m in range(2,k+1): pf=kf kf*=m kf %=MOD inv=pow(kf,MOD-2,MOD) invs=[1]*(k+1) invs[k]=inv for m in range(k,1,-1): inv*=m inv %=MOD invs[m-1]=inv ans=0 if k & 1==0 : r=k>>1 s=k-n+1 ans=pf*(invs[r]*invs[r-1]-invs[s]*invs[k-s-1])% MOD for r in range(k//2+1,k+1): if r*2>=n+k : ans+=kf*invs[r]*invs[k-r] else : s=r*2-n+1 ans+=kf*(invs[r]*invs[k-r]-invs[s]*invs[k-s]) ans %=MOD return ans print(solve(*map(int,input().split()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (solve((argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))))->display(); operation solve(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var MOD : int := 998244353 ; if (n->compareTo(k)) > 0 then ( return 0 ) else skip ; if n = 1 then ( return (2)->pow(k - 1) ) else skip ; var pf : OclAny := null; var kf : OclAny := null; Sequence{pf,kf} := Sequence{1,1} ; for m : Integer.subrange(2, k + 1-1) do ( var pf : OclAny := kf ; kf := kf * m ; kf := kf mod MOD) ; var inv : double := (kf)->pow(MOD - 2) ; var invs : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (k + 1)) ; invs[k+1] := inv ; for m : Integer.subrange(1 + 1, k)->reverse() do ( inv := inv * m ; inv := inv mod MOD ; invs[m - 1+1] := inv) ; var ans : int := 0 ; if MathLib.bitwiseAnd(k, 1) = 0 then ( var r : int := k /(2->pow(1)) ; var s : double := k - n + 1 ; ans := pf * (invs[r+1] * invs[r - 1+1] - invs[s+1] * invs[k - s - 1+1]) mod MOD ) else skip ; for r : Integer.subrange(k div 2 + 1, k + 1-1) do ( if (r * 2->compareTo(n + k)) >= 0 then ( ans := ans + kf * invs[r+1] * invs[k - r+1] ) else ( s := r * 2 - n + 1 ; ans := ans + kf * (invs[r+1] * invs[k - r+1] - invs[s+1] * invs[k - s+1]) ) ; ans := ans mod MOD) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) p=998244353 r=range f=[1] for i in r(k): f+=[-~ i*f[i]% p] a=0 for i in r(n-1,k): a+=f[k-1]*pow(f[i]*f[k-1-i],-1,p) print(a % p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : int := 998244353 ; var r : OclAny := range ; var f : Sequence := Sequence{ 1 } ; for i : r(k) do ( f := f + Sequence{ -MathLib.bitwiseNot(i) * f[i+1] mod p }) ; var a : int := 0 ; for i : r(n - 1, k) do ( a := a + f[k - 1+1] * (f[i+1] * f[k - 1 - i+1])->pow(-1)) ; execute (a mod p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): f=open('input.txt','r') n=int(f.readline()) arr=list(map(int,f.readline().split())); arr.sort() l=0 ; r=0 while larr[r]*2 : r+=1 l+=1 return r print(solve(),file=open('output.txt','w')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (solve())->display(); operation solve() : OclAny pre: true post: true activity: var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('input.txt')) ; var n : int := ("" + ((f.readLine())))->toInteger() ; var arr : Sequence := ((f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); arr := arr->sort() ; var l : int := 0; var r : int := 0 ; while (l->compareTo(n)) < 0 do ( if (arr[l+1]->compareTo(arr[r+1] * 2)) > 0 then ( r := r + 1 ) else skip ; l := l + 1) ; return r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin from sys import stdout import os.path if(os.path.exists('input.txt')): stdin=open("input.txt","r") stdout=open("output.txt","w") stderr=open("error.txt","w") def get_data(n,messurements): min_value=n+1 j=0 for i in range(n): while j=messurements[j]: j+=1 if messurements[i]*2>=messurements[j-1]: final_deletes=i+n-j min_value=min(min_value,final_deletes) return min_value def main(): n=int(stdin.readline()) messurements=[int(x)for x in stdin.readline().split()] messurements.sort() print(get_data(n,messurements),file=stdout) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if (os.path.exists('input.txt')) then ( var stdin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ; var stdout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ; var stderr : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("error.txt")) ) else skip ; skip ; skip ; main(); operation get_data(n : OclAny, messurements : OclAny) : OclAny pre: true post: true activity: var min_value : OclAny := n + 1 ; var j : int := 0 ; for i : Integer.subrange(0, n-1) do ( while (j->compareTo(n)) < 0 & (messurements[i+1] * 2->compareTo(messurements[j+1])) >= 0 do ( j := j + 1) ; if (messurements[i+1] * 2->compareTo(messurements[j - 1+1])) >= 0 then ( var final_deletes : double := i + n - j ; min_value := Set{min_value, final_deletes}->min() ) else skip) ; return min_value; operation main() pre: true post: true activity: n := ("" + ((stdin.readLine())))->toInteger() ; messurements := stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; messurements := messurements->sort() ; execute (get_data(n, messurements))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) sa=input().count("-") sa=min([n-sa,sa]) ss=[] for _ in range(m): a,b=map(int,input().split()) a=(b-a) ss.append((a % 2 and a<=sa<<1)and "1\n" or "0\n") print("".join(ss)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sa : OclAny := input()->count("-") ; sa := (Sequence{n - sa}->union(Sequence{ sa }))->min() ; var ss : Sequence := Sequence{} ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : double := (b - a) ; execute (((a mod 2 & (a->compareTo(sa * (2->pow(1)))) <= 0) & "1\n" or "0\n") : ss)) ; execute (StringLib.sumStringsWithSeparator((ss), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def memoize(f): memo={} def main(*args): if args in memo : return memo[args] result=memo[args]=f(*args) return result return main def get_num(remains): i=0 while remains : if remains & 1 : yield i i+=1 remains>>=1 @ memoize def calc(n,s,remains): if n==1 : if remains &(1<=0) for line in sys.stdin : n,s=map(int,line.split()) print(calc(n,s,(1<<10)-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; (compound_stmt (decorator @ (dotted_name (name memoize))) (funcdef def (name calc) ( (typedargslist (def_parameters (def_parameter (named_parameter (name n))) , (def_parameter (named_parameter (name s))) , (def_parameter (named_parameter (name remains))))) ) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name n)))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (expr (atom (name remains))) & (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name s)))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name s)))) <= (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name calc)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name s))) - (expr (expr (atom (name n))) * (expr (atom (name m))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name remains))) ^ (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name m)))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name m)))) in (logical_test (comparison (expr (atom (name get_num)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name remains)))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (expr (atom (name s))) - (expr (expr (atom (name n))) * (expr (atom (name m)))))) >= (comparison (expr (atom (number (integer 0)))))))))))) )))))))))))))) ; for line : OclFile["System.in"] do ( var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (line.split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (calc(n, s, (1 * (2->pow(10))) - 1))->display()); operation memoize(f : OclAny) : OclAny pre: true post: true activity: var memo : OclAny := Set{} ; skip ; return main; operation get_num(remains : OclAny) pre: true post: true activity: var i : int := 0 ; while remains do ( if MathLib.bitwiseAnd(remains, 1) then ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return i ) else skip ; i := i + 1 ; remains := remains div (2->pow(1))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- file=open("input.txt","r") n=int(file.readline()) ar=[int(x)for x in file.readline().split()] ans=n-1 ar.sort() file.close() for i in range(1,n): lb=ar[i]/2 lo,hi=0,i if ar[0]>=lb : ans=min(ans,n-i-1) elif ar[i-1]=lb and ar[mid-1]=lb : hi=mid-1 else : lo=mid+1 oput=open("output.txt","w") oput.write(str(ans)) oput.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var file : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ; var n : int := ("" + ((file.readLine())))->toInteger() ; var ar : Sequence := file.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : double := n - 1 ; ar := ar->sort() ; file.closeFile() ; for i : Integer.subrange(1, n-1) do ( var lb : double := ar[i+1] / 2 ; var lo : OclAny := null; var hi : OclAny := null; Sequence{lo,hi} := Sequence{0,i} ; if (ar->first()->compareTo(lb)) >= 0 then ( ans := Set{ans, n - i - 1}->min() ) else (if (ar[i - 1+1]->compareTo(lb)) < 0 then ( ans := Set{ans, n - 1}->min() ) else ( while (lo->compareTo(hi)) <= 0 do ( var mid : int := (lo + hi) div 2 ; if (ar[mid+1]->compareTo(lb)) >= 0 & (ar[mid - 1+1]->compareTo(lb)) < 0 then ( ans := Set{ans, n - i - 1 + mid}->min() ; break ) else (if (ar[mid+1]->compareTo(lb)) >= 0 then ( var hi : double := mid - 1 ) else ( var lo : int := mid + 1 ) ) ) ) ) ) ; var oput : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ; oput.write(("" + ((ans)))) ; oput.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() n,k=map(int,input().split()) arr=[*map(int,input().split())] print(max([abs(sum(arr)-sum(arr[u : : k]))for u in range(k)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Integer.subrange(0, k-1)->select(u | true)->collect(u | (((arr)->sum() - (arr(subscript (test (logical_test (comparison (expr (atom (name u)))))) : (sliceop : (test (logical_test (comparison (expr (atom (name k)))))))))->sum())->abs())))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- with open('input.txt','r')as f1 : n=int(f1.readline()) c=[*map(int,f1.readline().split())] c.sort() res=0 from bisect import bisect for i,x in enumerate(c): res=max(res,bisect(c,x*2)-i) with open('output.txt','w')as f2 : f2.write(str(n-res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: try (var f1 : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('input.txt')); var n : int := ("" + ((f1.readLine())))->toInteger() ; var c : Sequence := (f1.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) catch (_e : OclException) do skip ; c := c->sort() ; var res : int := 0 ; skip ; for _tuple : Integer.subrange(1, (c)->size())->collect( _indx | Sequence{_indx-1, (c)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); res := Set{res, bisect(c, x * 2) - i}->max()) ; try (var f2 : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('output.txt')); f2.write(("" + ((n - res))))) catch (_e : OclException) do skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): file=open('input.txt','r') n=int(file.readline()) arr=list(map(int,file.readline().split())) arr.sort() res=0 left=0 for i in range(len(arr)): while arr[i]>2*arr[left]: left+=1 res=max(res,i-left+1) file.close() file=open("output.txt",'w') file.write(str(len(arr)-res)) def main(): t=1 for _ in range(t): solution() import sys import threading sys.setrecursionlimit(1<<30) threading.stack_size(1<<27) thread=threading.Thread(target=main) thread.start(); thread.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1 * (2->pow(30))) ; threading.stack_size(1 * (2->pow(27))) ; var thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ; thread.start(); thread.join(); operation solution() pre: true post: true activity: var file : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('input.txt')) ; var n : int := ("" + ((file.readLine())))->toInteger() ; var arr : Sequence := ((file.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := arr->sort() ; var res : int := 0 ; var left : int := 0 ; for i : Integer.subrange(0, (arr)->size()-1) do ( while (arr[i+1]->compareTo(2 * arr[left+1])) > 0 do ( left := left + 1) ; res := Set{res, i - left + 1}->max()) ; file.closeFile() ; file := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ; file.write(("" + (((arr)->size() - res)))); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def deleteElements(arr,n,k): st=[] st.append(arr[0]) top=0 count=0 for i in range(1,n): while(len(st)!=0 and countunion(Sequence{10}->union(Sequence{25}->union(Sequence{30}->union(Sequence{ 40 })))) ; deleteElements(arr, (arr)->size(), k); operation deleteElements(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var st : Sequence := Sequence{} ; execute ((arr->first()) : st) ; var top : int := 0 ; var count : int := 0 ; for i : Integer.subrange(1, n-1) do ( while ((st)->size() /= 0 & (count->compareTo(k)) < 0 & (st[top+1]->compareTo(arr[i+1])) < 0) do ( st := st->front() ; count := count + 1 ; top := top - 1) ; execute ((arr[i+1]) : st) ; top := top + 1) ; for i : Integer.subrange(0, (st)->size()-1) do ( execute (st[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def power(a,n): if n==0 : return 1 p=power(a,n//2)% mod p=(p*p)% mod if n & 1==1 : p=(p*a)% mod return p def computeSum(arr,n): arr.sort() Sum=0 for i in range(0,n): maxs=(power(2,i)-1+mod)% mod maxs=(maxs*arr[i])% mod mins=(power(2,n-1-i)-1+mod)% mod mins=(mins*arr[i])% mod V=(maxs-mins+mod)% mod Sum=(Sum+V)% mod return Sum if __name__=="__main__" : mod=1000000007 arr=[4,3,1] n=len(arr) print(computeSum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var mod : int := 1000000007 ; arr := Sequence{4}->union(Sequence{3}->union(Sequence{ 1 })) ; n := (arr)->size() ; execute (computeSum(arr, n))->display() ) else skip; operation power(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( return 1 ) else skip ; var p : int := power(a, n div 2) mod mod ; p := (p * p) mod mod ; if MathLib.bitwiseAnd(n, 1) = 1 then ( p := (p * a) mod mod ) else skip ; return p; operation computeSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var Sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( var maxs : int := (power(2, i) - 1 + mod) mod mod ; maxs := (maxs * arr[i+1]) mod mod ; var mins : int := (power(2, n - 1 - i) - 1 + mod) mod mod ; mins := (mins * arr[i+1]) mod mod ; var V : int := (maxs - mins + mod) mod mod ; Sum := (Sum + V) mod mod) ; return Sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX5=100 def maximumZeros(arr,n,k): global MAX5 subset=[[-1]*(MAX5+5)for _ in range(k+1)] subset[0][0]=0 for p in arr : pw2,pw5=0,0 while not p % 2 : pw2+=1 p//=2 while not p % 5 : pw5+=1 p//=5 for i in range(k-1,-1,-1): for j in range(MAX5): if subset[i][j]!=-1 : subset[i+1][j+pw5]=(max(subset[i+1][j+pw5],(subset[i][j]+pw2))) ans=0 for i in range(MAX5): ans=max(ans,min(i,subset[k][i])) return ans arr=[50,4,20] k=2 n=len(arr) print(maximumZeros(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute MAX5 : OclAny; operation initialise() pre: true post: true activity: var MAX5 : int := 100 ; skip ; arr := Sequence{50}->union(Sequence{4}->union(Sequence{ 20 })) ; k := 2 ; n := (arr)->size() ; execute (maximumZeros(arr, n, k))->display(); operation maximumZeros(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: skip ; var subset : Sequence := Integer.subrange(0, k + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ -1 }, (MAX5 + 5)))) ; subset->first()->first() := 0 ; for p : arr do ( var pw2 : OclAny := null; var pw5 : OclAny := null; Sequence{pw2,pw5} := Sequence{0,0} ; while not(p mod 2) do ( pw2 := pw2 + 1 ; p := p div 2) ; while not(p mod 5) do ( pw5 := pw5 + 1 ; p := p div 5) ; for i : Integer.subrange(-1 + 1, k - 1)->reverse() do ( for j : Integer.subrange(0, MAX5-1) do ( if subset[i+1][j+1] /= -1 then ( subset[i + 1+1][j + pw5+1] := (Set{subset[i + 1+1][j + pw5+1], (subset[i+1][j+1] + pw2)}->max()) ) else skip))) ; var ans : int := 0 ; for i : Integer.subrange(0, MAX5-1) do ( ans := Set{ans, Set{i, subset[k+1][i+1]}->min()}->max()) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B=map(int,input().split()) ans=0 for i in range(A,B+1): num=str(i) if num[0 : 2]==num[: :-1][0 : 2]: ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; for i : Integer.subrange(A, B + 1-1) do ( var num : String := ("" + ((i))) ; if num.subrange(0+1, 2) = num(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))).subrange(0+1, 2) then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getORDER(n): order=list() while(n>0): order.append(n % 10) n//=10 return order A,B=map(int,input().split()) res=0 for i in range(A,B+1): order=list(getORDER(i)) if(order[0]==order[4]and order[1]==order[3]): res+=1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var res : int := 0 ; for i : Integer.subrange(A, B + 1-1) do ( order := (getORDER(i)) ; if (order->first() = order[4+1] & order[1+1] = order[3+1]) then ( res := res + 1 ) else skip) ; execute (res)->display(); operation getORDER(n : OclAny) : OclAny pre: true post: true activity: var order : Sequence := () ; while (n > 0) do ( execute ((n mod 10) : order) ; n := n div 10) ; return order; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(k): k=str(k) for i in range(len(k)//2): if k[i]!=k[len(k)-i-1]: return False return True def main(): A,B=[int(i)for i in input().split()] ans=0 for k in range(A,B+1): if f(k): ans+=1 print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation f(k : OclAny) : OclAny pre: true post: true activity: k := ("" + ((k))) ; for i : Integer.subrange(0, (k)->size() div 2-1) do ( if k[i+1] /= k[(k)->size() - i - 1+1] then ( return false ) else skip) ; return true; operation main() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : int := 0 ; for k : Integer.subrange(A, B + 1-1) do ( if f(k) then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import combinations import sys dp=[[[0]*331 for _ in[0]*2048]for _ in[0]*11] for i in range(11): dp[1][2**i][i]=1 for i in range(2,11): for used in(sum(comb)for comb in combinations([2**n for n in range(10)],i-1)): for j in filter(lambda x : used & 2**x==0,range(10)): for total,count in filter(lambda p : p[1]>0,enumerate(dp[i-1][used])): dp[i][used | 2**j][total+j*i]+=count for n,s in(map(int,l.rstrip().split())for l in sys.stdin): print(sum(a[s]for a in dp[n]if a[s])if s<331 else 0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 11)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 2048)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 331))))) ; for i : Integer.subrange(0, 11-1) do ( dp[1+1][(2)->pow(i)+1][i+1] := 1) ; for i : Integer.subrange(2, 11-1) do ( for used : Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name comb)))))))) ))))))) (comp_for for (exprlist (expr (atom (name comb)))) in (logical_test (comparison (expr (atom (name combinations)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) ** (expr (atom (name n))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 10))))))))) )))))))) ])))))) , (argument (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ))))))))} do ( for j : (Integer.subrange(0, 10-1))->select( _x | (lambda x : OclAny in (MathLib.bitwiseAnd(used, (2)->pow(x)) = 0))->apply(_x) = true ) do ( for _tuple : (Integer.subrange(1, (dp[i - 1+1][used+1])->size())->collect( _indx | Sequence{_indx-1, (dp[i - 1+1][used+1])->at(_indx)} ))->select( _x | (lambda p : OclAny in (p[1+1] > 0))->apply(_x) = true ) do (var _indx : int := 1; var total : OclAny := _tuple->at(_indx); _indx := _indx + 1; var count : OclAny := _tuple->at(_indx); dp[i+1][MathLib.bitwiseOr(used, (2)->pow(j))+1][total + j * i+1] := dp[i+1][MathLib.bitwiseOr(used, (2)->pow(j))+1][total + j * i+1] + count)))) ; for _tuple : Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name l)) (trailer . (name rstrip) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name l)))) in (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin)))))))} do (var _indx : int := 1; var n : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); execute (if s < 331 then ((argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n)))))))) ]))))) (comp_iter if (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ]))))))))))->sum() else 0 endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=input().split() A=int(a) B=int(b) def judge(n): J=0 s=str(n) if s==s[: :-1]: J=1 else : pass return J num=0 for i in range(A,B+1): j=0 j=judge(i) if j==1 : num+=1 else : pass print(num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; var A : int := ("" + ((a)))->toInteger() ; var B : int := ("" + ((b)))->toInteger() ; skip ; var num : int := 0 ; for i : Integer.subrange(A, B + 1-1) do ( var j : int := 0 ; j := judge(i) ; if j = 1 then ( num := num + 1 ) else ( skip )) ; execute (num)->display(); operation judge(n : OclAny) : OclAny pre: true post: true activity: var J : int := 0 ; var s : String := ("" + ((n))) ; if s = s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( J := 1 ) else ( skip ) ; return J; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) c=list(range(a,b+1)) count=0 for i in c : j=str(i) if j[0]==j[4]and j[1]==j[3]: count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : Sequence := (Integer.subrange(a, b + 1-1)) ; var count : int := 0 ; for i : c do ( var j : String := ("" + ((i))) ; if j->first() = j[4+1] & j[1+1] = j[3+1] then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) li=[] li=list(map(int,input().split())) final=0 for i in range(0,len(li)): ex=[] for j in li : ex.append(j) for j in range(i,n,k): ex[j]=0 for j in range(i,-1,-k): ex[j]=0 ans=0 e1=ex.count(1) e2=(ex.count(-1)) ans=abs(e1-e2) final=max(ans,final) print(final) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var li : Sequence := Sequence{} ; li := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var final : int := 0 ; for i : Integer.subrange(0, (li)->size()-1) do ( var ex : Sequence := Sequence{} ; for j : li do ( execute ((j) : ex)) ; for j : Integer.subrange(i, n-1)->select( $x | ($x - i) mod k = 0 ) do ( ex[j+1] := 0) ; for j : Integer.subrange(i, -1-1)->select( $x | ($x - i) mod -k = 0 ) do ( ex[j+1] := 0) ; var ans : int := 0 ; var e1 : int := ex->count(1) ; var e2 : int := (ex->count(-1)) ; ans := (e1 - e2)->abs() ; final := Set{ans, final}->max()) ; execute (final)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math pwr=[0]*10 def isMunchhausen(n): sm=0 temp=n while(temp): sm=sm+pwr[(temp % 10)] temp=temp//10 return(sm==n) def printMunchhausenNumbers(n): for i in range(0,10): pwr[i]=math.pow((float)(i),(float)(i)) for i in range(1,n+1): if(isMunchhausen(i)): print(i) n=10000 printMunchhausenNumbers(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var pwr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; skip ; skip ; n := 10000 ; printMunchhausenNumbers(n); operation isMunchhausen(n : OclAny) : OclAny pre: true post: true activity: var sm : int := 0 ; var temp : OclAny := n ; while (temp) do ( sm := sm + pwr[(temp mod 10)+1] ; temp := temp div 10) ; return (sm = n); operation printMunchhausenNumbers(n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, 10-1) do ( pwr[i+1] := ((OclType["double"])(i))->pow((OclType["double"])(i))) ; for i : Integer.subrange(1, n + 1-1) do ( if (isMunchhausen(i)) then ( execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for r in[*open(0)][2 : : 2]: b=sorted(map(int,r.split())) print(min(y-x for x,y in zip(b,b[1 :]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for r : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var b : Sequence := (r.split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; execute (((argument (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (name x))))))) (comp_for for (exprlist (expr (atom (name x))) , (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b))))))) , (argument (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))))))) )))))))))->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) a=sorted([int(i)for i in input().split()],reverse=True) b=[] for j in range(len(a)-1): b.append(abs(a[j]-a[j+1])) print(min(b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var b : Sequence := Sequence{} ; for j : Integer.subrange(0, (a)->size() - 1-1) do ( execute (((a[j+1] - a[j + 1+1])->abs()) : b)) ; execute ((b)->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): size=int(input()) m=2e9 strength=list(map(int,input().split())) strength.sort() for i in range(size): for j in range(i+1,size): if abs(strength[i]-strength[j])toInteger()-1) do ( var size : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : double := ("2e9")->toReal() ; var strength : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; strength := strength->sort() ; for i : Integer.subrange(0, size-1) do ( for j : Integer.subrange(i + 1, size-1) do ( if ((strength[i+1] - strength[j+1])->abs()->compareTo(m)) < 0 then ( m := (strength[i+1] - strength[j+1])->abs() ) else skip)) ; execute (m)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) l=list(map(int,input().split())) l.sort() d=[] for i in range(1,n): d.append(l[i]-l[i-1]) print(min(d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := l->sort() ; var d : Sequence := Sequence{} ; for i : Integer.subrange(1, n-1) do ( execute ((l[i+1] - l[i - 1+1]) : d)) ; execute ((d)->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for tc in range(T): n=int(input()) l1=list(map(int,input().split())) l1.sort() ans=10**20 for i in range(n): for j in range(i+1,n): ans=min(ans,l1[j]-l1[i]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for tc : Integer.subrange(0, T-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l1 := l1->sort() ; var ans : double := (10)->pow(20) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( ans := Set{ans, l1[j+1] - l1[i+1]}->min())) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Fibonacci(n): if n<0 : print("Incorrect input") elif n==0 : return 0 elif n==1 : return 1 else : return Fibonacci(n-1)+Fibonacci(n-2) print(Fibonacci(9)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (Fibonacci(9))->display(); operation Fibonacci(n : OclAny) pre: true post: true activity: if n < 0 then ( execute ("Incorrect input")->display() ) else (if n = 0 then ( return 0 ) else (if n = 1 then ( return 1 ) else ( return Fibonacci(n - 1) + Fibonacci(n - 2) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- max=0 for i in range(1,10): max+=i*(i+1) dp=[[[-1]*1025 for i in range(max+1)]for j in range(11)] def solve(n,s,used): if n==0 and s==0 : return 1 ; if n<=0 or s<0 : return 0 if dp[n][s][used]!=-1 : return dp[n][s][used] sum=0 for i in range(0,10): if(used>>i)% 2==0 : used+=1<=0 and s<=max : used=0 ans=solve(n,s,used) print(ans) except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var max : int := 0 ; for i : Integer.subrange(1, 10-1) do ( max := max + i * (i + 1)) ; var dp : Sequence := Integer.subrange(0, 11-1)->select(j | true)->collect(j | (Integer.subrange(0, max + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ -1 }, 1025))))) ; skip ; while (1) do ( try ( Sequence{n,s} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var ans : int := 0 ; if s >= 0 & (s->compareTo(max)) <= 0 then ( used := 0 ; ans := solve(n, s, used) ) else skip ; execute (ans)->display()) catch (_e : OclException) do ( break) ); operation solve(n : OclAny, s : OclAny, used : OclAny) : OclAny pre: true post: true activity: if n = 0 & s = 0 then ( return 1; ) else skip ; if n <= 0 or s < 0 then ( return 0 ) else skip ; if dp[n+1][s+1][used+1] /= -1 then ( return dp[n+1][s+1][used+1] ) else skip ; var sum : int := 0 ; for i : Integer.subrange(0, 10-1) do ( if (used /(2->pow(i))) mod 2 = 0 then ( used := used + 1 * (2->pow(i)) ; sum := sum + solve(n - 1, s - i * n, used) ; used := used - 1 * (2->pow(i)) ) else skip) ; dp[n+1][s+1][used+1] := sum ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) z=len(bin(n))-3 print((2**z)-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var z : double := (bin(n))->size() - 3 ; execute (((2)->pow(z)) - 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) k=1 while 2*k<=n : k*=2 print(k-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := 1 ; while (2 * k->compareTo(n)) <= 0 do ( k := k * 2) ; execute (k - 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) n |=n>>1 n |=n>>2 n |=n>>4 n |=n>>8 n |=n>>16 n |=n>>32 n |=n>>64 print(n>>1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; n := n or n /(2->pow(1)) ; n := n or n /(2->pow(2)) ; n := n or n /(2->pow(4)) ; n := n or n /(2->pow(8)) ; n := n or n /(2->pow(16)) ; n := n or n /(2->pow(32)) ; n := n or n /(2->pow(64)) ; execute (n /(2->pow(1)))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) li=[] li=list(map(int,input().split())) final=0 for i in range(0,len(li)): ex=[] for j in li : ex.append(j) for j in range(i,n,k): ex[j]=0 for j in range(i,-1,-k): ex[j]=0 ass=0 e1=ex.count(1) e2=(ex.count(-1)) ass=abs(e1-e2) final=max(ass,final) print(final) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var li : Sequence := Sequence{} ; li := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var final : int := 0 ; for i : Integer.subrange(0, (li)->size()-1) do ( var ex : Sequence := Sequence{} ; for j : li do ( execute ((j) : ex)) ; for j : Integer.subrange(i, n-1)->select( $x | ($x - i) mod k = 0 ) do ( ex[j+1] := 0) ; for j : Integer.subrange(i, -1-1)->select( $x | ($x - i) mod -k = 0 ) do ( ex[j+1] := 0) ; var ass : int := 0 ; var e1 : int := ex->count(1) ; var e2 : int := (ex->count(-1)) ; ass := (e1 - e2)->abs() ; final := Set{ass, final}->max()) ; execute (final)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) print((1<toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((1 * (2->pow((Integer.subrange(0, 32-1)->select(i | (MathLib.bitwiseAnd(n, (1 * (2->pow(i))))))->collect(i | (i)))->max()))) - 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a=int(input()) k=1 while(k<=a): j=k k<<=1 print(j-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := 1 ; while ((k->compareTo(a)) <= 0) do ( var j : int := k ; k := k * (2->pow(1))) ; execute (j - 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def getWinner(arr,n): __gcd=arr[0]; maxEle=arr[0]; for i in range(1,n): __gcd=gcd(__gcd,arr[i]); maxEle=max(maxEle,arr[i]); totalMoves=(maxEle/__gcd)-n ; if(totalMoves % 2==1): return 'A' ; return 'B' ; if __name__=="__main__" : arr=[5,6,7]; n=len(arr) print(getWinner(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{5}->union(Sequence{6}->union(Sequence{ 7 })); ; n := (arr)->size() ; execute (getWinner(arr, n))->display() ) else skip; operation getWinner(arr : OclAny, n : OclAny) pre: true post: true activity: var __gcd : OclAny := arr->first(); ; var maxEle : OclAny := arr->first(); ; for i : Integer.subrange(1, n-1) do ( __gcd := gcd(__gcd, arr[i+1]); ; maxEle := Set{maxEle, arr[i+1]}->max();) ; var totalMoves : double := (maxEle / __gcd) - n; ; if (totalMoves mod 2 = 1) then ( return 'A'; ) else skip ; return 'B';; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): numbers=set(eulerlib.binomial(n,k)for n in range(51)for k in range(n+1)) maximum=max(numbers) primes=eulerlib.list_primes(eulerlib.sqrt(maximum)) primessquared=[p*p for p in primes] def is_squarefree(n): for p2 in primessquared : if p2>n : break if n % p2==0 : return False return True ans=sum(n for n in numbers if is_squarefree(n)) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var numbers : Set := Set{}->union(((argument (test (logical_test (comparison (expr (atom (name eulerlib)) (trailer . (name binomial) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n))))))) , (argument (test (logical_test (comparison (expr (atom (name k)))))))) ))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 51))))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name k)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) )))))))))))) ; var maximum : OclAny := (numbers)->max() ; var primes : OclAny := eulerlib.list_primes(eulerlib.sqrt(maximum)) ; var primessquared : Sequence := primes->select(p | true)->collect(p | (p * p)) ; skip ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name n)))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name numbers))))) (comp_iter if (test (logical_test (comparison (expr (atom (name is_squarefree)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))))->sum() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumDigits(no): return 0 if no==0 else int(no % 10)+sumDigits(int(no/10)) print(sumDigits(687)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (sumDigits(687))->display(); operation sumDigits(no : OclAny) : OclAny pre: true post: true activity: return if no = 0 then 0 else ("" + ((no mod 10)))->toInteger() + sumDigits(("" + ((no / 10)))->toInteger()) endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def anagramMappings(self,A,B): val_index={} ans=[] for i,n in enumerate(B): val_index[n]=i for n in A : ans.append(val_index[n]) return ans ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation anagramMappings(A : OclAny,B : OclAny) : OclAny pre: true post: true activity: var val_index : OclAny := Set{} ; var ans : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (B)->size())->collect( _indx | Sequence{_indx-1, (B)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var n : OclAny := _tuple->at(_indx); val_index[n+1] := i) ; for n : A do ( execute ((val_index[n+1]) : ans)) ; return ans; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=1000000007 def fact(n): res=1 for i in range(2,n+1): res=res*i return res def nCr(n,r): return int(fact(n)/(fact(r)*fact(n-r))) def powmod(a,n): if(n==0): return 1 pt=powmod(a,int(n/2)) pt=(pt*pt)% mod if(n % 2): return(pt*a)% mod else : return pt def CountSubset(arr,n): ans=powmod(2,n-1) arr.sort(reverse=False) for i in range(n): j=i+1 while(junion(Sequence{3}->union(Sequence{ 2 })) ; n := (arr)->size() ; execute (CountSubset(arr, n))->display() ) else skip; operation fact(n : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; for i : Integer.subrange(2, n + 1-1) do ( res := res * i) ; return res; operation nCr(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: return ("" + ((fact(n) / (fact(r) * fact(n - r)))))->toInteger(); operation powmod(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return 1 ) else skip ; var pt : OclAny := powmod(a, ("" + ((n / 2)))->toInteger()) ; pt := (pt * pt) mod mod ; if (n mod 2) then ( return (pt * a) mod mod ) else ( return pt ); operation CountSubset(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : OclAny := powmod(2, n - 1) ; arr := arr->sort() ; for i : Integer.subrange(0, n-1) do ( var j : OclAny := i + 1 ; while ((j->compareTo(n)) < 0 & arr[j+1] = arr[i+1]) do ( r := n - 1 - j ; var l : OclAny := i ; ans := (ans + nCr(l + r, l)) mod mod ; j := j + 1)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(s): n=len(s); for i in range(2,n): if(s[i]=='1' and s[i-1]=='1' and s[i-2]=='1'): return 1 ; def countStr(i,s): if(i<0): if(check(s)): return 1 ; return 0 ; s[i]='0' ; ans=countStr(i-1,s); s[i]='1' ; ans+=countStr(i-1,s); s[i]='0' ; return ans ; if __name__=="__main__" : N=4 ; s=list('0'*N); print(countStr(N-1,s)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var N : int := 4; ; s := (StringLib.nCopies('0', N))->characters(); ; execute (countStr(N - 1, s))->display(); ) else skip; operation check(s : OclAny) pre: true post: true activity: var n : int := (s)->size(); ; for i : Integer.subrange(2, n-1) do ( if (s[i+1] = '1' & s[i - 1+1] = '1' & s[i - 2+1] = '1') then ( return 1; ) else skip); operation countStr(i : OclAny, s : OclAny) pre: true post: true activity: if (i < 0) then ( if (check(s)) then ( return 1; ) else skip ; return 0; ) else skip ; s[i+1] := '0'; ; var ans : OclAny := countStr(i - 1, s); ; s[i+1] := '1'; ; ans := ans + countStr(i - 1, s); ; s[i+1] := '0'; ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculate(n,power): return sum([int(i)for i in str(pow(n,power))]) n=5 power=4 print(calculate(n,power)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; power := 4 ; execute (calculate(n, power))->display(); operation calculate(n : OclAny, power : OclAny) : OclAny pre: true post: true activity: return (("" + (((n)->pow(power))))->select(i | true)->collect(i | (("" + ((i)))->toInteger())))->sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def altitude(a,b): return math.sqrt(pow(a,2)-(pow(b,2)/4)) def area(b,h): return(1*b*h)/2 if __name__=="__main__" : a=2 b=3 h=altitude(a,b) print("Altitude="+str(round(h,3)),end=",") print("Area="+str(round(area(b,h),3))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( a := 2 ; b := 3 ; h := altitude(a, b) ; execute ("Altitude=" + ("" + ((MathLib.roundN(h, 3)))))->display() ; execute ("Area=" + ("" + ((MathLib.roundN(area(b, h), 3)))))->display() ) else skip; operation altitude(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return ((a)->pow(2) - ((b)->pow(2) / 4))->sqrt(); operation area(b : OclAny, h : OclAny) : OclAny pre: true post: true activity: return (1 * b * h) / 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPossible(w,h,x,y): if(x*2==w and y*2==h): return True return False if __name__=='__main__' : w=1 h=2 x=1 y=2 if(isPossible(w,h,x,y)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( w := 1 ; h := 2 ; x := 1 ; y := 2 ; if (isPossible(w, h, x, y)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isPossible(w : OclAny, h : OclAny, x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (x * 2 = w & y * 2 = h) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkIfAllVowels(string): hash=[0]*5 ; for i in range(len(string)): if(string[i]=='A' or string[i]=='a'): hash[0]=1 ; elif(string[i]=='E' or string[i]=='e'): hash[1]=1 ; elif(string[i]=='I' or string[i]=='i'): hash[2]=1 ; elif(string[i]=='O' or string[i]=='o'): hash[3]=1 ; elif(string[i]=='U' or string[i]=='u'): hash[4]=1 ; for i in range(5): if(hash[i]==0): return 1 ; return 0 ; def checkIfAllVowelsArePresent(string): if(checkIfAllVowels(string)): print("Not Accepted"); else : print("Accepted"); if __name__=="__main__" : string="aeioubc" ; checkIfAllVowelsArePresent(string); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( string := "aeioubc"; ; checkIfAllVowelsArePresent(string); ) else skip; operation checkIfAllVowels(string : OclAny) pre: true post: true activity: var hash : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 5); ; for i : Integer.subrange(0, (string)->size()-1) do ( if (string[i+1] = 'A' or string[i+1] = 'a') then ( hash->first() := 1; ) else (if (string[i+1] = 'E' or string[i+1] = 'e') then ( hash[1+1] := 1; ) else (if (string[i+1] = 'I' or string[i+1] = 'i') then ( hash[2+1] := 1; ) else (if (string[i+1] = 'O' or string[i+1] = 'o') then ( hash[3+1] := 1; ) else (if (string[i+1] = 'U' or string[i+1] = 'u') then ( hash[4+1] := 1; ) else skip ) ) ) ) ) ; for i : Integer.subrange(0, 5-1) do ( if (hash[i+1] = 0) then ( return 1; ) else skip) ; return 0;; operation checkIfAllVowelsArePresent(string : OclAny) pre: true post: true activity: if (checkIfAllVowels(string)) then ( execute ("Not Accepted")->display(); ) else ( execute ("Accepted")->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from re import L import sys,bisect from collections import deque,OrderedDict,defaultdict import heapq from collections import Counter def inp(): return sys.stdin.readline().rstrip() def mpp(): return map(int,inp().split()) def lis(): return list(mpp()) def yn(n): if n : return "YES" else : return "NO" def fn(arr,n,k): ans=0 for i in range(k): di=Counter(arr) for j in range(i,n,k): di[arr[j]]-=1 ans=max(ans,abs(di[1]-di[-1])) return ans def main(): n,k=mpp() arr=lis() print(fn(arr,n,k)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation inp() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation mpp() : OclAny pre: true post: true activity: return (inp().split())->collect( _x | (OclType["int"])->apply(_x) ); operation lis() : OclAny pre: true post: true activity: return (mpp()); operation yn(n : OclAny) : OclAny pre: true post: true activity: if n then ( return "YES" ) else ( return "NO" ); operation fn(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, k-1) do ( var di : OclAny := Counter(arr) ; for j : Integer.subrange(i, n-1)->select( $x | ($x - i) mod k = 0 ) do ( di[arr[j+1]+1] := di[arr[j+1]+1] - 1) ; ans := Set{ans, (di[1+1] - di->last())->abs()}->max()) ; return ans; operation main() pre: true post: true activity: Sequence{n,k} := mpp() ; arr := lis() ; execute (fn(arr, n, k))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def NthSmallest(K): Q=[] for i in range(1,10): Q.append(i) for i in range(1,K+1): x=Q[0] Q.remove(Q[0]) if(x % 10!=0): Q.append(x*10+x % 10-1) Q.append(x*10+x % 10) if(x % 10!=9): Q.append(x*10+x % 10+1) return x if __name__=='__main__' : N=16 print(NthSmallest(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var N : int := 16 ; execute (NthSmallest(N))->display() ) else skip; operation NthSmallest(K : OclAny) : OclAny pre: true post: true activity: var Q : Sequence := Sequence{} ; for i : Integer.subrange(1, 10-1) do ( execute ((i) : Q)) ; for i : Integer.subrange(1, K + 1-1) do ( var x : OclAny := Q->first() ; execute ((Q->first()) /: Q) ; if (x mod 10 /= 0) then ( execute ((x * 10 + x mod 10 - 1) : Q) ) else skip ; execute ((x * 10 + x mod 10) : Q) ; if (x mod 10 /= 9) then ( execute ((x * 10 + x mod 10 + 1) : Q) ) else skip) ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def resolve(): import sys input=sys.stdin.readline a,b,c,x,y=map(int,input().split()) z=min(x,y) ans=min(a*x+b*y,a*(x-z)+b*(y-z)+c*z*2,max(x,y)*2*c) print(ans) if __name__=='__main__' : resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( resolve() ) else skip; operation resolve() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{a,b,c,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var z : OclAny := Set{x, y}->min() ; var ans : OclAny := Set{a * x + b * y, a * (x - z) + b * (y - z) + c * z * 2, Set{x, y}->max() * 2 * c}->min() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return input() def main(): a,b,c,x,y=LI() return min(max(x,y)*c*2,a*x+b*y,max(0,x-y)*a+y*c*2,max(0,y-x)*b+x*c*2) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var mod : double := (10)->pow(9) + 7 ; var dd : Sequence := Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{ Sequence{0, -1} }))) ; var ddn : Sequence := Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{-1, 1}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{1, 1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{1, -1}}->union(Sequence{Sequence{0, -1}}->union(Sequence{ Sequence{-1, -1} }))))))) ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation main() : OclAny pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{a,b,c,x,y} := LI() ; return Set{Set{x, y}->max() * c * 2, a * x + b * y, Set{0, x - y}->max() * a + y * c * 2, Set{0, y - x}->max() * b + x * c * 2}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B,C,X,Y=map(int,input().split()) cost=set() for n_AB in range(0,max(X,Y)*2+1,2): n_A=max(0,X-n_AB//2) n_B=max(0,Y-n_AB//2) cost.add(n_A*A+n_B*B+n_AB*C) print(min(cost)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var X : OclAny := null; var Y : OclAny := null; Sequence{A,B,C,X,Y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cost : Set := Set{}->union(()) ; for n_AB : Integer.subrange(0, Set{X, Y}->max() * 2 + 1-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( var n_A : OclAny := Set{0, X - n_AB div 2}->max() ; var n_B : OclAny := Set{0, Y - n_AB div 2}->max() ; execute ((n_A * A + n_B * B + n_AB * C) : cost)) ; execute ((cost)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000001 MAX_sqrt=MAX**(0.5) primeUpto=[0]*(MAX) def SieveOfEratosthenes(): isPrime=[1]*(MAX) isPrime[0],isPrime[1]=0,0 for i in range(2,int(MAX_sqrt)): if isPrime[i]==1 : for j in range(i*2,MAX,i): isPrime[j]=0 for i in range(1,MAX): primeUpto[i]=primeUpto[i-1] if isPrime[i]==1 : primeUpto[i]+=1 def countOfNumbers(N,K): SieveOfEratosthenes() low,high,ans=1,N,0 while low<=high : mid=(low+high)>>1 if mid-primeUpto[mid]>=K : ans=mid high=mid-1 else : low=mid+1 return(N-ans+1)if ans else 0 if __name__=="__main__" : N,K=10,3 print(countOfNumbers(N,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1000001 ; var MAX_sqrt : double := (MAX)->pow((0.5)) ; var primeUpto : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX)) ; skip ; skip ; if __name__ = "__main__" then ( Sequence{N,K} := Sequence{10,3} ; execute (countOfNumbers(N, K))->display() ) else skip; operation SieveOfEratosthenes() pre: true post: true activity: var isPrime : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (MAX)) ; var isPrime->first() : OclAny := null; var isPrime[1+1] : OclAny := null; Sequence{isPrime->first(),isPrime[1+1]} := Sequence{0,0} ; for i : Integer.subrange(2, ("" + ((MAX_sqrt)))->toInteger()-1) do ( if isPrime[i+1] = 1 then ( for j : Integer.subrange(i * 2, MAX-1)->select( $x | ($x - i * 2) mod i = 0 ) do ( isPrime[j+1] := 0) ) else skip) ; for i : Integer.subrange(1, MAX-1) do ( primeUpto[i+1] := primeUpto[i - 1+1] ; if isPrime[i+1] = 1 then ( primeUpto[i+1] := primeUpto[i+1] + 1 ) else skip); operation countOfNumbers(N : OclAny, K : OclAny) : OclAny pre: true post: true activity: SieveOfEratosthenes() ; var low : OclAny := null; var high : OclAny := null; var ans : OclAny := null; Sequence{low,high,ans} := Sequence{1,N,0} ; while (low->compareTo(high)) <= 0 do ( var mid : int := (low + high) /(2->pow(1)) ; if (mid - primeUpto[mid+1]->compareTo(K)) >= 0 then ( var ans : int := mid ; var high : double := mid - 1 ) else ( var low : int := mid + 1 )) ; return if ans then (N - ans + 1) else 0 endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): a_price,b_price,ab_price,a_num,b_num=map(int,input().split()) chukan_price=(a_price+b_price)/2 min_num=min(a_num,b_num) ans=0 if chukan_price>ab_price : ans+=min_num*2*ab_price a_num-=min_num b_num-=min_num if a_price>2*ab_price : ans+=a_num*2*ab_price else : ans+=a_num*a_price if b_price>2*ab_price : ans+=b_num*2*ab_price else : ans+=b_num*b_price else : ans+=a_num*a_price ans+=b_num*b_price print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var a_price : OclAny := null; var b_price : OclAny := null; var ab_price : OclAny := null; var a_num : OclAny := null; var b_num : OclAny := null; Sequence{a_price,b_price,ab_price,a_num,b_num} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var chukan_price : double := (a_price + b_price) / 2 ; var min_num : OclAny := Set{a_num, b_num}->min() ; var ans : int := 0 ; if (chukan_price->compareTo(ab_price)) > 0 then ( ans := ans + min_num * 2 * ab_price ; a_num := a_num - min_num ; b_num := b_num - min_num ; if (a_price->compareTo(2 * ab_price)) > 0 then ( ans := ans + a_num * 2 * ab_price ) else ( ans := ans + a_num * a_price ) ; if (b_price->compareTo(2 * ab_price)) > 0 then ( ans := ans + b_num * 2 * ab_price ) else ( ans := ans + b_num * b_price ) ) else ( ans := ans + a_num * a_price ; ans := ans + b_num * b_price ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def smaller(x,y): if xcollect( _x | (OclType["int"])->apply(_x) ) ; var sum : int := 0 ; if (A + B->compareTo(2 * AB)) <= 0 then ( sum := sum + A * X + B * Y ) else ( var pizzaset : double := 2 * smaller(X, Y) ; sum := sum + pizzaset * AB ; X := X - pizzaset div 2 ; Y := Y - pizzaset div 2 ; if X = 0 then ( if (B->compareTo(2 * AB)) <= 0 then ( sum := sum + B * Y ) else ( sum := sum + 2 * Y * AB ) ) else ( if (A->compareTo(2 * AB)) <= 0 then ( sum := sum + A * X ) else ( sum := sum + 2 * X * AB ) ) ) ; execute (sum)->display(); operation smaller(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (x->compareTo(y)) < 0 then ( return x ) else skip ; return y; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSetBits(n): count=0 while n : n &=(n-1) count+=1 return count def countUnsetBitsInGivenRange(n,l,r): num=((1<display(); operation countSetBits(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while n do ( n := n & (n - 1) ; count := count + 1) ; return count; operation countUnsetBitsInGivenRange(n : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var num : int := MathLib.bitwiseXor(((1 * (2->pow(r))) - 1), ((1 * (2->pow((l - 1)))) - 1)) ; return (r - l + 1) - countSetBits(MathLib.bitwiseAnd(n, num)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSetBits(n): count=0 while(n): n &=(n-1) count=count+1 return count def countSetBitsInGivenRange(n,l,r): num=((1<display(); operation countSetBits(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while (n) do ( n := n & (n - 1) ; count := count + 1) ; return count; operation countSetBitsInGivenRange(n : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var num : int := MathLib.bitwiseXor(((1 * (2->pow(r))) - 1), ((1 * (2->pow((l - 1)))) - 1)) ; return countSetBits(MathLib.bitwiseAnd(n, num)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ReplaceElements(arr,n): mp=dict() for i in range(n): mp[arr[i]]=mp.get(arr[i],0)+1 for i in range(n): arr[i]=n-mp[arr[i]] arr=[1,2,5,2,2,5,4] n=len(arr) ReplaceElements(arr,n) for i in range(n): print(arr[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{5}->union(Sequence{2}->union(Sequence{2}->union(Sequence{5}->union(Sequence{ 4 })))))) ; n := (arr)->size() ; ReplaceElements(arr, n) ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); operation ReplaceElements(arr : OclAny, n : OclAny) pre: true post: true activity: var mp : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( mp[arr[i+1]+1] := mp.get(arr[i+1], 0) + 1) ; for i : Integer.subrange(0, n-1) do ( arr[i+1] := n - mp[arr[i+1]+1]); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def remove(arr,n): m=dict.fromkeys(arr,0); for i in range(n): m[arr[i]]+=1 ; for i in range(n): if((m[arr[i]]& 1)): continue ; print(arr[i],end=","); if __name__=="__main__" : arr=[3,3,3,2,2,4,7,7]; n=len(arr); remove(arr,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{3}->union(Sequence{3}->union(Sequence{3}->union(Sequence{2}->union(Sequence{2}->union(Sequence{4}->union(Sequence{7}->union(Sequence{ 7 }))))))); ; n := (arr)->size(); ; remove(arr, n); ) else skip; operation remove(arr : OclAny, n : OclAny) pre: true post: true activity: var m : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))); ; for i : Integer.subrange(0, n-1) do ( m[arr[i+1]+1] := m[arr[i+1]+1] + 1;) ; for i : Integer.subrange(0, n-1) do ( if ((MathLib.bitwiseAnd(m[arr[i+1]+1], 1))) then ( continue; ) else skip ; execute (arr[i+1])->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input_num=input() input_num=int(input_num) for i in range(1,10,1): flag=False for j in range(1,10,1): if input_num==i*j : print("Yes") flag=True break if flag : break if not flag : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var input_num : String := (OclFile["System.in"]).readLine() ; input_num := ("" + ((input_num)))->toInteger() ; for i : Integer.subrange(1, 10-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( var flag : boolean := false ; for j : Integer.subrange(1, 10-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if input_num = i * j then ( execute ("Yes")->display() ; flag := true ; break ) else skip) ; if flag then ( break ) else skip) ; if not(flag) then ( execute ("No")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ReplaceElementsByFrequency(arr,n): mp={i : 0 for i in range(len(arr))} for i in range(n): mp[arr[i]]+=1 for i in range(n): arr[i]=mp[arr[i]] if __name__=='__main__' : arr=[1,2,5,2,2,5] n=len(arr) ReplaceElementsByFrequency(arr,n); for i in range(n): print(arr[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{5}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 5 }))))) ; n := (arr)->size() ; ReplaceElementsByFrequency(arr, n); ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()) ) else skip; operation ReplaceElementsByFrequency(arr : OclAny, n : OclAny) pre: true post: true activity: var mp : Map := Integer.subrange(0, (arr)->size()-1)->select(i | true)->collect(i | Map{i |-> 0})->unionAll() ; for i : Integer.subrange(0, n-1) do ( mp[arr[i+1]+1] := mp[arr[i+1]+1] + 1) ; for i : Integer.subrange(0, n-1) do ( arr[i+1] := mp[arr[i+1]+1]); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=26 def countPairs(string,k): n=len(string); freq=[0]*MAX ; for i in range(n): freq[ord(string[i])-ord('a')]+=1 ; cnt=0 ; if(k==0): for i in range(MAX): if(freq[i]>1): cnt+=((freq[i]*(freq[i]-1))//2); else : for i in range(MAX): if(freq[i]>0 and i+k0): cnt+=(freq[i]*freq[i+k]); return cnt ; if __name__=="__main__" : string="abcdab" ; k=0 ; print(countPairs(string,k)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 26 ; skip ; if __name__ = "__main__" then ( string := "abcdab"; ; k := 0; ; execute (countPairs(string, k))->display(); ) else skip; operation countPairs(string : OclAny, k : OclAny) pre: true post: true activity: var n : int := (string)->size(); ; var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX); ; for i : Integer.subrange(0, n-1) do ( freq[(string[i+1])->char2byte() - ('a')->char2byte()+1] := freq[(string[i+1])->char2byte() - ('a')->char2byte()+1] + 1;) ; var cnt : int := 0; ; if (k = 0) then ( for i : Integer.subrange(0, MAX-1) do ( if (freq[i+1] > 1) then ( cnt := cnt + ((freq[i+1] * (freq[i+1] - 1)) div 2); ) else skip) ) else ( for i : Integer.subrange(0, MAX-1) do ( if (freq[i+1] > 0 & (i + k->compareTo(MAX)) < 0 & freq[i + k+1] > 0) then ( cnt := cnt + (freq[i+1] * freq[i + k+1]); ) else skip) ) ; return cnt;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSquares(row,column): topLeft=min(row,column)-1 bottomRight=8-max(row,column) topRight=min(row,9-column)-1 bottomLeft=8-max(row,9-column) return(topLeft+topRight+bottomRight+bottomLeft) row=4 column=4 print(countSquares(row,column)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; row := 4 ; column := 4 ; execute (countSquares(row, column))->display(); operation countSquares(row : OclAny, column : OclAny) : OclAny pre: true post: true activity: var topLeft : double := Set{row, column}->min() - 1 ; var bottomRight : double := 8 - Set{row, column}->max() ; var topRight : double := Set{row, 9 - column}->min() - 1 ; var bottomLeft : double := 8 - Set{row, 9 - column}->max() ; return (topLeft + topRight + bottomRight + bottomLeft); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for C in range(1,T+1): D,I,M,N=input().split(' ') D,I,M,N=int(D),int(I),int(M),int(N) x=input().split(' ') r=[0]*256 for q in x : nr=list(map(lambda i : i+D,r)) q=int(q) if M==0 : for i in range(256): nr[i]=min(nr[i],r[i]+abs(q-i)) else : for i in range(256): for j in range(256): nr[j]=min(nr[j],r[i]+abs(q-j)+(max(0,abs(i-j)-1)//M)*I) r=nr print('Case #%d: %s' %(C,min(r))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for C : Integer.subrange(1, T + 1-1) do ( var D : OclAny := null; var I : OclAny := null; var M : OclAny := null; var N : OclAny := null; Sequence{D,I,M,N} := input().split(' ') ; var D : OclAny := null; var I : OclAny := null; var M : OclAny := null; var N : OclAny := null; Sequence{D,I,M,N} := Sequence{("" + ((D)))->toInteger(),("" + ((I)))->toInteger(),("" + ((M)))->toInteger(),("" + ((N)))->toInteger()} ; var x : OclAny := input().split(' ') ; var r : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 256) ; for q : x do ( var nr : Sequence := ((r)->collect( _x | (lambda i : OclAny in (i + D))->apply(_x) )) ; var q : int := ("" + ((q)))->toInteger() ; if M = 0 then ( for i : Integer.subrange(0, 256-1) do ( nr[i+1] := Set{nr[i+1], r[i+1] + (q - i)->abs()}->min()) ) else ( for i : Integer.subrange(0, 256-1) do ( for j : Integer.subrange(0, 256-1) do ( nr[j+1] := Set{nr[j+1], r[i+1] + (q - j)->abs() + (Set{0, (i - j)->abs() - 1}->max() div M) * I}->min())) ) ; r := nr) ; execute (StringLib.format('Case #%d: %s',Sequence{C, (r)->min()}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,bisect sys.setrecursionlimit(15000) n=int(sys.stdin.readline()) a=list(map(int,sys.stdin.readline().split())) a.append(0) st=[] ar=0 for i in range(n+1): if not st : st.append([i,a[i]]) elif st[-1][1]a[i]: while st and st[-1][1]>=a[i]: j,h=st.pop() ar=max(ar,(i-j)*(h)) st.append([j,a[i]]) print(ar) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(15000) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((0) : a) ; var st : Sequence := Sequence{} ; var ar : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( if not(st) then ( execute ((Sequence{i}->union(Sequence{ a[i+1] })) : st) ) else (if (st->last()[1+1]->compareTo(a[i+1])) < 0 then ( execute ((Sequence{i}->union(Sequence{ a[i+1] })) : st) ) else (if st->last()[1+1] = a[i+1] then ( execute ((Sequence{i}->union(Sequence{ a[i+1] })) : st) ) else (if (st->last()[1+1]->compareTo(a[i+1])) > 0 then ( while st & (st->last()[1+1]->compareTo(a[i+1])) >= 0 do ( var j : OclAny := null; var h : OclAny := null; Sequence{j,h} := st->last() ; st := st->front() ; ar := Set{ar, (i - j) * (h)}->max()) ; execute ((Sequence{j}->union(Sequence{ a[i+1] })) : st) ) else skip ) ) ) ) ; execute (ar)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : N=int(input()) hist=list(map(lambda x : int(x),input().split())) stack=[(0,-1)] ans=0 for i in range(N): height=hist[i] pos=i while stack and height<=stack[-1][0]: h,j=stack.pop() ans=max(ans,(i-j)*h) pos=j stack.append((height,pos)) while stack : h,j=stack.pop() ans=max(ans,(N-j)*h) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var hist : Sequence := ((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) )) ; var stack : Sequence := Sequence{ Sequence{0, -1} } ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( var height : OclAny := hist[i+1] ; var pos : OclAny := i ; while stack & (height->compareTo(stack->last()->first())) <= 0 do ( var h : OclAny := null; var j : OclAny := null; Sequence{h,j} := stack->last() ; stack := stack->front() ; ans := Set{ans, (i - j) * h}->max() ; pos := j) ; execute ((Sequence{height, pos}) : stack)) ; while stack do ( var h : OclAny := null; var j : OclAny := null; Sequence{h,j} := stack->last() ; stack := stack->front() ; ans := Set{ans, (N - j) * h}->max()) ; execute (ans)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque iim=lambda : map(int,input().rstrip().split()) def calc(dp): ans=0 dq=deque([[0,0]]) for i,hi in enumerate(dp): j=i while dq[-1][1]>hi : j,h1=dq.pop() ans=max(ans,(i-j)*h1) if dq[-1][1]collect( _x | (OclType["int"])->apply(_x) )) ; skip ; skip ; if __name__ = "__main__" then ( resolve() ) else skip; operation calc(dp : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; var dq : Sequence := (Sequence{ Sequence{0}->union(Sequence{ 0 }) }) ; for _tuple : Integer.subrange(1, (dp)->size())->collect( _indx | Sequence{_indx-1, (dp)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var hi : OclAny := _tuple->at(_indx); var j : OclAny := i ; while (dq->last()[1+1]->compareTo(hi)) > 0 do ( var h1 : OclAny := null; Sequence{j,h1} := dq->last() ; dq := dq->front() ; ans := Set{ans, (i - j) * h1}->max()) ; if (dq->last()[1+1]->compareTo(hi)) < 0 then ( execute ((Sequence{j}->union(Sequence{ hi })) : dq) ) else skip) ; var i : int := (dp)->size() ; for _tuple : dq do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var hi : OclAny := _tuple->at(_indx); ans := Set{ans, (i - j) * hi}->max()) ; return ans; operation resolve() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var H : Sequence := (iim->apply()) ; execute (calc(H))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda : sys.stdin.readline().rstrip() def resolve(): n=int(input()) IH=[(i,h)for i,h in enumerate(map(int,input().split()))] IH.append((n,0)) ans=0 Q=[[-1,0]] for i,h in IH : while(Q[-1][1]>h): i0,h0=Q.pop() ans=max(ans,h0*(i-Q[-1][0]-1)) if(Q[-1][1]toReal() ; var MOD : double := (10)->pow(9) + 7 ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; skip ; resolve(); operation resolve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var IH : Sequence := Integer.subrange(1, ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))->size())->collect( _indx | Sequence{_indx-1, ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let h : OclAny = _tuple->at(2) in (Sequence{i, h})) ; execute ((Sequence{n, 0}) : IH) ; var ans : int := 0 ; var Q : Sequence := Sequence{ Sequence{-1}->union(Sequence{ 0 }) } ; for _tuple : IH do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var h : OclAny := _tuple->at(_indx); while ((Q->last()[1+1]->compareTo(h)) > 0) do ( var i0 : OclAny := null; var h0 : OclAny := null; Sequence{i0,h0} := Q->last() ; Q := Q->front() ; ans := Set{ans, h0 * (i - Q->last()->first() - 1)}->max()) ; if ((Q->last()[1+1]->compareTo(h)) < 0) then ( execute ((Sequence{i}->union(Sequence{ h })) : Q) ) else (if (Q->last()[1+1] = h) then ( Q->last()->first() := i ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,collections file=sys.stdin n=int(file.readline()) C=list(map(int,file.readline().split())) def square(P): G=[] L=collections.deque() for i,v in enumerate(P): if not L : L.append((i,v)) continue if v>L[-1][1]: L.append((i,v)) elif vtoInteger() ; var C : Sequence := ((file.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; execute (square(C))->display(); operation square(P : OclAny) : OclAny pre: true post: true activity: var G : Sequence := Sequence{} ; var L : Sequence := () ; for _tuple : Integer.subrange(1, (P)->size())->collect( _indx | Sequence{_indx-1, (P)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if not(L) then ( execute ((Sequence{i, v}) : L) ; continue ) else skip ; if (v->compareTo(L->last()[1+1])) > 0 then ( execute ((Sequence{i, v}) : L) ) else (if (v->compareTo(L->last()[1+1])) < 0 then ( var k : double := i - 1 ; while L & (v->compareTo(L->last()[1+1])) < 0 do ( var a : OclAny := L->last() ; L := L->front() ; execute (((k - a->first() + 1) * a[1+1]) : G)) ; execute ((Sequence{a->first(), v}) : L) ) else skip)) ; while L do ( a := L->last() ; L := L->front() ; execute ((((P)->size() - a->first()) * a[1+1]) : G)) ; return (G)->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def preCalculate(binary,n,left): count1,count0=0,0 for i in range(n): left[i][0]=count1 left[i][1]=count0 if(binary[i]): count1+=1 else : count0+=1 binary=[1,1,1,0,0,1,0,1,1] n=len(binary) left=[[0 for i in range(2)]for i in range(n)] preCalculate(binary,n,left) queries=[0,1,2,4] q=len(queries) for i in range(q): print(left[queries[i]][0],"ones",left[queries[i]][1],"zeros") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; binary := Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 1 })))))))) ; n := (binary)->size() ; left := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, 2-1)->select(i | true)->collect(i | (0)))) ; preCalculate(binary, n, left) ; var queries : Sequence := Sequence{0}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 4 }))) ; var q : int := (queries)->size() ; for i : Integer.subrange(0, q-1) do ( execute (left[queries[i+1]+1]->first())->display()); operation preCalculate(binary : OclAny, n : OclAny, left : OclAny) pre: true post: true activity: var count1 : OclAny := null; var count0 : OclAny := null; Sequence{count1,count0} := Sequence{0,0} ; for i : Integer.subrange(0, n-1) do ( left[i+1]->first() := count1 ; left[i+1][1+1] := count0 ; if (binary[i+1]) then ( count1 := count1 + 1 ) else ( count0 := count0 + 1 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class KthLargest(object): def __init__(self,k,nums): self.nums=nums self.k=k heapq.heapify(self.nums) while len(self.nums)>k : heapq.heappop(self.nums) def add(self,val): if len(self.nums)self.nums[0]: heapq.heapreplace(self.nums,val) return self.nums[0] ------------------------------------------------------------ OCL File: --------- class KthLargest extends object { static operation newKthLargest() : KthLargest pre: true post: KthLargest->exists( _x | result = _x ); attribute nums : OclAny := nums; attribute k : OclAny := k; operation initialise(k : OclAny,nums : OclAny) : pre: true post: true activity: self.nums := nums ; self.k := k ; heapq.heapify(self.nums) ; while ((self.nums)->size()->compareTo(k)) > 0 do ( heapq.heappop(self.nums)); return self; operation add(val : OclAny) : OclAny pre: true post: true activity: if ((self.nums)->size()->compareTo(self.k)) < 0 then ( heapq.heappush(self.nums, val) ) else (if (val->compareTo(self.nums->first())) > 0 then ( heapq.heapreplace(self.nums, val) ) else skip) ; return self.nums->first(); } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A=int(input()) kk=[i*j for i in range(1,10)for j in range(1,10)] ans="No" if A in kk : ans="Yes" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var kk : Sequence := Integer.subrange(1, 10-1)->select(i; j : Integer.subrange(1, 10-1) | true)->collect(i; j : Integer.subrange(1, 10-1) | (i * j)) ; var ans : String := "No" ; if (kk)->includes(A) then ( ans := "Yes" ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) if n % 2==1 : print('-',end='') print(math.ceil(n/2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 1 then ( execute ('-')->display() ) else skip ; execute ((n / 2)->ceil())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) if(t % 2==0): print(t//2) else : print(-(t+1)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (t mod 2 = 0) then ( execute (t div 2)->display() ) else ( execute (-(t + 1) div 2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countOperations(n): i=2 while((i*i)n): i=n return(1+(n-i)//2) n=5 print(countOperations(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; execute (countOperations(n))->display(); operation countOperations(n : OclAny) : OclAny pre: true post: true activity: var i : int := 2 ; while (((i * i)->compareTo(n)) < 0 & (n mod i)) do ( i := i + 1) ; if (((i * i)->compareTo(n)) > 0) then ( i := n ) else skip ; return (1 + (n - i) div 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(n): if n % 2 : return-(n+1)//2 return n//2 print(f(int(input()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (f(("" + (((OclFile["System.in"]).readLine())))->toInteger()))->display(); operation f(n : OclAny) : OclAny pre: true post: true activity: if n mod 2 then ( return -(n + 1) div 2 ) else skip ; return n div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def add(num1,num2): return num1-num2 num=eval(input()) print(num//2 if num % 2==0 else-(num+1)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var num : OclAny := (OclFile["System.in"]).readLine() ; execute (if num mod 2 = 0 then num div 2 else -(num + 1) div 2 endif)->display(); operation add(num1 : OclAny, num2 : OclAny) : OclAny pre: true post: true activity: return num1 - num2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()); print(n//2-n % 2*n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); execute (n div 2 - n mod 2 * n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def farthest_min(a,n): suffix_min=[0 for i in range(n)] suffix_min[n-1]=a[n-1] for i in range(n-2,-1,-1): suffix_min[i]=min(suffix_min[i+1],a[i]) for i in range(n): low=i+1 high=n-1 ans=-1 while(low<=high): mid=(low+high)//2 if(suffix_min[mid]union(Sequence{1}->union(Sequence{5}->union(Sequence{2}->union(Sequence{ 4 })))) ; n := (a)->size() ; farthest_min(a, n); operation farthest_min(a : OclAny, n : OclAny) pre: true post: true activity: var suffix_min : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; suffix_min[n - 1+1] := a[n - 1+1] ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( suffix_min[i+1] := Set{suffix_min[i + 1+1], a[i+1]}->min()) ; for i : Integer.subrange(0, n-1) do ( var low : OclAny := i + 1 ; var high : double := n - 1 ; var ans : int := -1 ; while ((low->compareTo(high)) <= 0) do ( var mid : int := (low + high) div 2 ; if ((suffix_min[mid+1]->compareTo(a[i+1])) < 0) then ( ans := mid ; low := mid + 1 ) else ( high := mid - 1 )) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect while True : n=int(input()) if n==0 : break tc=sorted([int(input())for _ in range(n)]) hc=sorted([v for v in range(1,2*n+1)if v not in tc]) ba=[] flag=True while tc and hc : if len(ba)==0 : try : if flag : tmp=tc.pop(0) flag=False else : tmp=hc.pop(0) flag=True except IndexError : pass ba=[tmp] continue last_card=ba[-1] if flag : x=bisect.bisect_left(tc,last_card) flag=False try : tmp=tc.pop(x) except IndexError : ba=[] continue else : x=bisect.bisect_left(hc,last_card) flag=True try : tmp=hc.pop(x) except IndexError : ba=[] continue ba.append(tmp) print(len(hc)) print(len(tc)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var tc : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))->sort() ; var hc : Sequence := Integer.subrange(1, 2 * n + 1-1)->select(v | (tc)->excludes(v))->collect(v | (v))->sort() ; var ba : Sequence := Sequence{} ; var flag : boolean := true ; while tc & hc do ( if (ba)->size() = 0 then ( try ( if flag then ( var tmp : OclAny := tc->at(0`firstArg+1) ; tc := tc->excludingAt(0+1) ; flag := false ) else ( tmp := hc->at(0`firstArg+1) ; hc := hc->excludingAt(0+1) ; flag := true )) (except_clause except (test (logical_test (comparison (expr (atom (name IndexError)))))) : (suite (stmt (simple_stmt (small_stmt pass))))) ; ba := Sequence{ tmp } ; continue ) else skip ; var last_card : OclAny := ba->last() ; if flag then ( var x : OclAny := bisect.bisect_left(tc, last_card) ; flag := false ; try ( tmp := tc->at(x`firstArg+1) ; tc := tc->excludingAt(x+1)) (except_clause except (test (logical_test (comparison (expr (atom (name IndexError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ba)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom [ ]))))))))))) (stmt (simple_stmt (small_stmt continue))))) ) else ( x := bisect.bisect_left(hc, last_card) ; flag := true ; try ( tmp := hc->at(x`firstArg+1) ; hc := hc->excludingAt(x+1)) (except_clause except (test (logical_test (comparison (expr (atom (name IndexError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ba)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom [ ]))))))))))) (stmt (simple_stmt (small_stmt continue))))) ) ; execute ((tmp) : ba)) ; execute ((hc)->size())->display() ; execute ((tc)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def hand(card,board): for i,c in enumerate(card): if boardtoInteger() ; if n = 0 then ( break ) else skip ; var taro : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : taro)) ; taro := taro->sort() ; var hanako : Sequence := Sequence{} ; for i : Integer.subrange(1, 2 * n + 1-1) do ( if (taro)->excludes(i) then ( execute ((i) : hanako) ) else skip) ; hanako := hanako->sort() ; board := 0 ; var order : int := 0 ; while 1 do ( if order = 0 then ( card := hand(taro, board) ; if taro = Sequence{} or hanako = Sequence{} then ( break ) else skip ; if board = card then ( board := 0 ; order := 1 ; continue ) else skip ; board := card ; card := hand(hanako, board) ; if taro = Sequence{} or hanako = Sequence{} then ( break ) else skip ; if board = card then ( board := 0 ; continue ) else skip ; board := card ) else ( card := hand(hanako, board) ; if taro = Sequence{} or hanako = Sequence{} then ( break ) else skip ; if board = card then ( board := 0 ; order := 0 ; continue ) else skip ; board := card ; card := hand(taro, board) ; if taro = Sequence{} or hanako = Sequence{} then ( break ) else skip ; if board = card then ( board := 0 ; continue ) else skip ; board := card )) ; execute ((hanako)->size())->display() ; execute ((taro)->size())->display()); operation hand(card : OclAny, board : OclAny) pre: true post: true activity: (compound_stmt for (exprlist (expr (atom (name i))) , (expr (atom (name c)))) in (testlist (test (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name card)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name board)))) < (comparison (expr (atom (name c))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name board)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name card)) (trailer . (name pop) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name board)))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name board))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bisect(a,x,lo=0,hi=None): if hi is None : hi=len(a) while lotoInteger() ; if n = 0 then ( break ) else skip ; var dealt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * n)) ; var thand : Sequence := Sequence{} ; var hhand : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( dealt[("" + (((OclFile["System.in"]).readLine())))->toInteger() - 1+1] := 1) ; for i : Integer.subrange(0, 2 * n-1) do ( if dealt[i+1] then ( execute ((i) : thand) ) else ( execute ((i) : hhand) )) ; thand := thand->sort() ; hhand := hhand->sort() ; var tarosturn : int := 1 ; var ba : int := -1 ; while true do ( if (thand)->size() = 0 then ( execute ((hhand)->size())->display() ; execute (0)->display() ; break ) else (if (hhand)->size() = 0 then ( execute (0)->display() ; execute ((thand)->size())->display() ; break ) else skip) ; if tarosturn then ( var taro : OclAny := bisect(thand, ba) ; if taro /= (thand)->size() then ( ba := thand->at(taro`firstArg+1) ; thand := thand->excludingAt(taro+1) ) else ( ba := -1 ) ; tarosturn := 0 ) else ( var hanako : OclAny := bisect(hhand, ba) ; if hanako /= (hhand)->size() then ( ba := hhand->at(hanako`firstArg+1) ; hhand := hhand->excludingAt(hanako+1) ) else ( ba := -1 ) ; tarosturn := 1 ))); operation bisect(a : OclAny, x : OclAny, lo : int, hi : OclAny) : OclAny pre: true post: true activity: if lo->oclIsUndefined() then lo := 0 else skip; if hi->oclIsUndefined() then hi := null else skip; if hi <>= null then ( hi := (a)->size() ) else skip ; while (lo->compareTo(hi)) < 0 do ( var mid : int := (lo + hi) div 2 ; if (x->compareTo(a[mid+1])) < 0 then ( hi := mid ) else ( lo := mid + 1 )) ; return lo; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class C : def __init__(self): self.value=[] def append(self,n): self.value.append(n) def popleft(self): if not self.value : return-1 else : ret=self.value[0] del self.value[0] return ret def popover(self,n): ret=-1 for i,v in enumerate(self.value): if v>n : ret=v del self.value[i] break return ret def empty(self): return self.value==[] @ property def length(self): return len(self.value) def main(): while True : n=int(input()) if n==0 : break taro_bool=[False]*(2*n+1) taro=C() hanako=C() for i in range(n): v=int(input()) taro_bool[v]=True for i in range(1,2*n+1): if taro_bool[i]: taro.append(i) else : hanako.append(i) ba=taro.popleft() teban=1 playing=[taro,hanako] while not taro.empty()and not hanako.empty(): if ba==0 : ba=playing[teban].popleft() else : x=playing[teban].popover(ba) ba=x if x>0 else 0 teban ^=1 print(hanako.length) print(taro.length) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class C { static operation newC() : C pre: true post: C->exists( _x | result = _x ); attribute value : Sequence := Sequence{}; operation initialise() : C pre: true post: true activity: self.value := Sequence{}; return self; operation append(n : OclAny) pre: true post: true activity: (expr (atom (name self)) (trailer . (name value)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))); operation popleft() : OclAny pre: true post: true activity: if not(self.value) then ( return -1 ) else ( var ret : OclAny := self.value->first() ; execute (self.value->first())->isDeleted() ; return ret ); operation popover(n : OclAny) : OclAny pre: true post: true activity: ret := -1 ; for _tuple : Integer.subrange(1, (self.value)->size())->collect( _indx | Sequence{_indx-1, (self.value)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if (v->compareTo(n)) > 0 then ( ret := v ; execute (self.value[i+1])->isDeleted() ; break ) else skip) ; return ret; operation empty() : OclAny pre: true post: true activity: return self.value = Sequence{}; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var taro_bool : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (2 * n + 1)) ; var taro : C := (C.newC()).initialise() ; var hanako : C := (C.newC()).initialise() ; for i : Integer.subrange(0, n-1) do ( var v : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; taro_bool[v+1] := true) ; for i : Integer.subrange(1, 2 * n + 1-1) do ( if taro_bool[i+1] then ( execute ((i) : taro) ) else ( execute ((i) : hanako) )) ; var ba : OclAny := taro->first() ; taro := taro->tail() ; var teban : int := 1 ; var playing : Sequence := Sequence{taro}->union(Sequence{ hanako }) ; while not(taro.empty()) & not(hanako.empty()) do ( if ba = 0 then ( ba := playing[teban+1]->first() ) else ( var x : OclAny := playing[teban+1].popover(ba) ; ba := if x > 0 then x else 0 endif ) ; teban := teban xor 1) ; execute (hanako.length)->display() ; execute (taro.length)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.readline() def main(): n=int(input()) for i in range(1,10): if n % i==0 : sho=n//i if 1<=sho and sho<=9 : print("Yes") return 0 print("No") if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation main() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(1, 10-1) do ( if n mod i = 0 then ( var sho : int := n div i ; if 1 <= sho & sho <= 9 then ( execute ("Yes")->display() ; return 0 ) else skip ) else skip) ; execute ("No")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect for e in iter(input,'0'): n=int(e) c=[sorted(int(input())for _ in[0]*n)] c+=[sorted(set(range(1,2*n+1))-set(c[0]))] t=f=0 while 1 : x=bisect.bisect(c[t],f) if not c[t]: break f=c[t].pop(x)if xtoInteger() ; var c : Sequence := Sequence{ (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr (atom (name n))))))))->sort() } ; c := c + Sequence{ Set{}->union((Integer.subrange(1, 2 * n + 1-1))) - Set{}->union((c->first()))->sort() } ; var t : OclAny := 0; var f : int := 0 ; while 1 do ( var x : OclAny := bisect.bisect(c[t+1], f) ; if not(c[t+1]) then ( break ) else skip ; f := if (x->compareTo((c[t+1])->size())) < 0 then c[t+1]->at(x`firstArg+1) else 0 endif ; t := t xor 1) ; for i : Sequence{1}->union(Sequence{ 0 }) do ( execute ((c[i+1])->size())->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,q=map(int,input().split()) s=input() ac=[0]*(n-1) for i in range(n-1): if s[i]=='A' and s[i+1]=='C' : ac[i]=1 acc=[0]*n for i in range(n-1): acc[i+1]=acc[i]+ac[i] lr=[tuple(map(int,input().split()))for _ in range(q)] for i in range(q): l=lr[i][0]-1 r=lr[i][1]-1 print(acc[r]-acc[l]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var ac : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n - 1)) ; for i : Integer.subrange(0, n - 1-1) do ( if s[i+1] = 'A' & s[i + 1+1] = 'C' then ( ac[i+1] := 1 ) else skip) ; var acc : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n - 1-1) do ( acc[i + 1+1] := acc[i+1] + ac[i+1]) ; var lr : Sequence := Integer.subrange(0, q-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for i : Integer.subrange(0, q-1) do ( var l : double := lr[i+1]->first() - 1 ; var r : double := lr[i+1][1+1] - 1 ; execute (acc[r+1] - acc[l+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(i)for i in input().split()] from heapq import* pq1=a[: n] heapify(pq1) s=sum(pq1) score1=[s] for i in range(n): c=heappushpop(pq1,a[n+i]) s+=a[n+i]-c score1.append(s) pq2=[-i for i in a[2*n :]] heapify(pq2) s=sum(pq2) score2=[s] for i in range(1,n+1): c=heappushpop(pq2,-a[2*n-i]) s+=-a[2*n-i]-c score2.append(s) ans=-10**17 for i,j in zip(score1,reversed(score2)): ans=max(ans,i+j) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; skip ; var pq1 : OclAny := a.subrange(1,n) ; heapify(pq1) ; var s : OclAny := (pq1)->sum() ; var score1 : Sequence := Sequence{ s } ; for i : Integer.subrange(0, n-1) do ( var c : OclAny := heappushpop(pq1, a[n + i+1]) ; s := s + a[n + i+1] - c ; execute ((s) : score1)) ; var pq2 : Sequence := a.subrange(2 * n+1)->select(i | true)->collect(i | (-i)) ; heapify(pq2) ; s := (pq2)->sum() ; var score2 : Sequence := Sequence{ s } ; for i : Integer.subrange(1, n + 1-1) do ( c := heappushpop(pq2, -a[2 * n - i+1]) ; s := s + -a[2 * n - i+1] - c ; execute ((s) : score2)) ; var ans : double := (-10)->pow(17) ; for _tuple : Integer.subrange(1, score1->size())->collect( _indx | Sequence{score1->at(_indx), (score2)->reverse()->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); ans := Set{ans, i + j}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): from heapq import heapify,heappush,heappop N=int(input()) A=list(map(int,input().split())) before=A[: N] after=[-n for n in A[N*2 :]] bes=sum(before) afs=sum(after) heapify(before) heapify(after) result=[0]*(N+1) result[0]=bes result[-1]=afs for i in range(N,N*2): a=A[i] heappush(before,a) k=heappop(before) bes+=a-k result[i-N+1]+=bes for i in range(N*2-1,N-1,-1): a=-A[i] heappush(after,a) k=heappop(after) afs+=a-k result[i-N]+=afs return max(result) print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (solve())->display(); operation solve() : OclAny pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var before : OclAny := A.subrange(1,N) ; var after : Sequence := A.subrange(N * 2+1)->select(n | true)->collect(n | (-n)) ; var bes : OclAny := (before)->sum() ; var afs : OclAny := (after)->sum() ; heapify(before) ; heapify(after) ; var result : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; result->first() := bes ; result->last() := afs ; for i : Integer.subrange(N, N * 2-1) do ( var a : OclAny := A[i+1] ; heappush(before, a) ; var k : OclAny := heappop(before) ; bes := bes + a - k ; result[i - N + 1+1] := result[i - N + 1+1] + bes) ; for i : Integer.subrange(N - 1 + 1, N * 2 - 1)->reverse() do ( a := -A[i+1] ; heappush(after, a) ; k := heappop(after) ; afs := afs + a - k ; result[i - N+1] := result[i - N+1] + afs) ; return (result)->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import heapq def input(): return sys.stdin.readline().rstrip() def main(): n=int(input()) a=list(map(int,input().split())) a_minus=list(map(lambda x :-x,a)) a_bef,a_aft=a[: n],a_minus[-n :] a_bef_sum,a_aft_sum={n : sum(a_bef)},{2*n :-sum(a_aft)} heapq.heapify(a_bef) heapq.heapify(a_aft) for i in range(n): bef_key=n+i heapq.heappush(a_bef,a[bef_key]) a_bef_sum[bef_key+1]=a_bef_sum[bef_key]-heapq.heappop(a_bef)+a[bef_key] aft_key=n*2-i-1 heapq.heappush(a_aft,a_minus[aft_key]) a_aft_sum[aft_key]=a_aft_sum[aft_key+1]+heapq.heappop(a_aft)+a[aft_key] ans=-pow(10,15) for i in range(n+1): diff=a_bef_sum[n+i]-a_aft_sum[n+i] if diff>ans : ans=diff print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a_minus : Sequence := ((a)->collect( _x | (lambda x : OclAny in (-x))->apply(_x) )) ; var a_bef : OclAny := null; var a_aft : OclAny := null; Sequence{a_bef,a_aft} := Sequence{a.subrange(1,n),a_minus.subrange(-n+1)} ; var a_bef_sum : OclAny := null; var a_aft_sum : OclAny := null; Sequence{a_bef_sum,a_aft_sum} := Sequence{Map{ n |-> (a_bef)->sum() },Map{ 2 * n |-> -(a_aft)->sum() }} ; heapq.heapify(a_bef) ; heapq.heapify(a_aft) ; for i : Integer.subrange(0, n-1) do ( var bef_key : int := n + i ; heapq.heappush(a_bef, a[bef_key+1]) ; a_bef_sum[bef_key + 1+1] := a_bef_sum[bef_key+1] - heapq.heappop(a_bef) + a[bef_key+1] ; var aft_key : double := n * 2 - i - 1 ; heapq.heappush(a_aft, a_minus[aft_key+1]) ; a_aft_sum[aft_key+1] := a_aft_sum[aft_key + 1+1] + heapq.heappop(a_aft) + a[aft_key+1]) ; var ans : double := -(10)->pow(15) ; for i : Integer.subrange(0, n + 1-1) do ( var diff : double := a_bef_sum[n + i+1] - a_aft_sum[n + i+1] ; if (diff->compareTo(ans)) > 0 then ( ans := diff ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools import math import heapq N=int(input()) nums=list(map(int,input().split(" "))) half1=nums[: N] middle=nums[N : 2*N] half2=nums[2*N :] half2=list(map(lambda x :-x,half2)) heapq.heapify(half1) heapq.heapify(half2) count=0 lsum=sum(half1) rsum=sum(half2) ruiseki_left=[lsum] ruiseki_right=[rsum] for i in range(N): head=half1[0] if middle[i]>head : ruiseki_left.append(ruiseki_left[-1]-head+middle[i]) heapq.heappop(half1) heapq.heappush(half1,middle[i]) else : ruiseki_left.append(ruiseki_left[-1]) middle.reverse() for i in range(N): head=half2[0] if middle[i]>head : ruiseki_right.append(ruiseki_right[-1]-head+(-middle[i])) heapq.heappop(half2) heapq.heappush(half2,-middle[i]) else : ruiseki_right.append(ruiseki_right[-1]) ans=-(10**20) for i in range(N+1): ans=max(ans,ruiseki_left[i]+ruiseki_right[N-i]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nums : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var half1 : OclAny := nums.subrange(1,N) ; var middle : OclAny := nums.subrange(N+1, 2 * N) ; var half2 : OclAny := nums.subrange(2 * N+1) ; half2 := ((half2)->collect( _x | (lambda x : OclAny in (-x))->apply(_x) )) ; heapq.heapify(half1) ; heapq.heapify(half2) ; var count : int := 0 ; var lsum : OclAny := (half1)->sum() ; var rsum : OclAny := (half2)->sum() ; var ruiseki_left : Sequence := Sequence{ lsum } ; var ruiseki_right : Sequence := Sequence{ rsum } ; for i : Integer.subrange(0, N-1) do ( var head : OclAny := half1->first() ; if (middle[i+1]->compareTo(head)) > 0 then ( execute ((ruiseki_left->last() - head + middle[i+1]) : ruiseki_left) ; heapq.heappop(half1) ; heapq.heappush(half1, middle[i+1]) ) else ( execute ((ruiseki_left->last()) : ruiseki_left) )) ; middle := middle->reverse() ; for i : Integer.subrange(0, N-1) do ( head := half2->first() ; if (middle[i+1]->compareTo(head)) > 0 then ( execute ((ruiseki_right->last() - head + (-middle[i+1])) : ruiseki_right) ; heapq.heappop(half2) ; heapq.heappush(half2, -middle[i+1]) ) else ( execute ((ruiseki_right->last()) : ruiseki_right) )) ; var ans : double := -((10)->pow(20)) ; for i : Integer.subrange(0, N + 1-1) do ( ans := Set{ans, ruiseki_left[i+1] + ruiseki_right[N - i+1]}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import* from collections import defaultdict from copy import deepcopy from math import log from itertools import accumulate N=int(input()) A=list(map(int,input().split())) X=[sum(A[: N])] Xheap=A[: N] heapify(Xheap) for i in range(N,2*N): x=heappushpop(Xheap,A[i]) S=X[-1]+A[i]-x X.append(S) A.reverse() Y=[sum(A[: N])] Yheap=[-i for i in A[: N]] heapify(Yheap) for i in range(N,2*N): y=-heappushpop(Yheap,-A[i]) S=Y[-1]+A[i]-y Y.append(S) Y.reverse() ans=-10**19 for i in range(N+1): ans=max(ans,X[i]-Y[i]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var X : Sequence := Sequence{ (A.subrange(1,N))->sum() } ; var Xheap : OclAny := A.subrange(1,N) ; heapify(Xheap) ; for i : Integer.subrange(N, 2 * N-1) do ( var x : OclAny := heappushpop(Xheap, A[i+1]) ; var S : double := X->last() + A[i+1] - x ; execute ((S) : X)) ; A := A->reverse() ; var Y : Sequence := Sequence{ (A.subrange(1,N))->sum() } ; var Yheap : Sequence := A.subrange(1,N)->select(i | true)->collect(i | (-i)) ; heapify(Yheap) ; for i : Integer.subrange(N, 2 * N-1) do ( var y : OclAny := -heappushpop(Yheap, -A[i+1]) ; S := Y->last() + A[i+1] - y ; execute ((S) : Y)) ; Y := Y->reverse() ; var ans : double := (-10)->pow(19) ; for i : Integer.subrange(0, N + 1-1) do ( ans := Set{ans, X[i+1] - Y[i+1]}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) S=list(map(int,input().split())) q=int(input()) T=list(map(int,input().split())) ans=0 def binary_search(lis,item): l=0 r=len(lis)-1 while l<=r : mid=(l+r)//2 guess=lis[mid] if guess==item : return 1 if guess>item : r=mid-1 else : l=mid+1 return 0 for i in T : ans+=binary_search(S,i) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var T : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; skip ; for i : T do ( ans := ans + binary_search(S, i)) ; execute (ans)->display(); operation binary_search(lis : OclAny, item : OclAny) : OclAny pre: true post: true activity: var l : int := 0 ; var r : double := (lis)->size() - 1 ; while (l->compareTo(r)) <= 0 do ( var mid : int := (l + r) div 2 ; var guess : OclAny := lis[mid+1] ; if guess = item then ( return 1 ) else skip ; if (guess->compareTo(item)) > 0 then ( r := mid - 1 ) else ( l := mid + 1 )) ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import itertools import time import math sys.setrecursionlimit(10**7) from collections import defaultdict read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines n=int(input()) S=list(sorted(map(int,input().split()))) q=int(input()) T=list(map(int,input().split())) ans=0 for t in T : left=-1 right=n while(right-left>1): mid=left+(right-left)//2 if S[mid]>=t : right=mid else : left=mid if S[right]==t : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort()) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var T : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for t : T do ( var left : int := -1 ; var right : int := n ; while (right - left > 1) do ( var mid : int := left + (right - left) div 2 ; if (S[mid+1]->compareTo(t)) >= 0 then ( right := mid ) else ( left := mid )) ; if S[right+1] = t then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() a=set(input().split()) input() b=set(input().split()) print(len(a & b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var a : Set := Set{}->union((input().split())) ; input() ; var b : Set := Set{}->union((input().split())) ; execute ((MathLib.bitwiseAnd(a, b))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- iipt=lambda : int(input()) miipt=lambda : list(map(int,input().split(" "))) import bisect N=iipt() c=miipt() M=iipt() qu=miipt() ans=0 for q in qu : a=0 b=N-1 while b-a>1 : x=(a+b)//2 if c[a]==q or c[b]==q : ans+=1 break if c[x]toInteger()) ; var miipt : Function := lambda $$ : OclAny in (((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ))) ; skip ; var N : OclAny := iipt->apply() ; var c : OclAny := miipt->apply() ; var M : OclAny := iipt->apply() ; var qu : OclAny := miipt->apply() ; var ans : int := 0 ; for q : qu do ( var a : int := 0 ; var b : double := N - 1 ; (compound_stmt while (test (logical_test (comparison (comparison (expr (expr (atom (name b))) - (expr (atom (name a))))) > (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name a))) + (expr (atom (name b)))))))) ))) // (expr (atom (number (integer 2)))))))))))))) (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])))) == (comparison (expr (atom (name q)))))) or (logical_test (comparison (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])))) == (comparison (expr (atom (name q)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))) < (comparison (expr (atom (name q))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name a)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x))))))))))))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])))) == (comparison (expr (atom (name q)))))) or (logical_test (comparison (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])))) == (comparison (expr (atom (name q)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))))))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) nums=[1,2,3,4,5,6,7,8,9] num2=[1,2,3,4,5,6,7,8,9] for i in nums : for j in nums : if i*j==N : print("Yes") exit() print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nums : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 9 })))))))) ; var num2 : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 9 })))))))) ; for i : nums do ( for j : nums do ( if i * j = N then ( execute ("Yes")->display() ; exit() ) else skip)) ; execute ("No")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def log(*args): print(*args,file=sys.stderr) def main(): n,q=map(int,input().split()) s=input().rstrip() before='' start_cumsum=[] end_cumsum=[] now_val=0 for(i,c)in enumerate(s): end_cumsum.append(now_val) if c=='A' : before='A' elif c=='C' and before=='A' : now_val+=1 before='' else : before='' start_cumsum.append(now_val) end_cumsum.append(now_val) for _ in range(q): l,r=map(int,input().split()) print(start_cumsum[r-1]-start_cumsum[l-1]) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation log(args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) execute ((argument * (test (logical_test (comparison (expr (atom (name args))))))))->display(); operation main() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := input().rstrip() ; var before : String := '' ; var start_cumsum : Sequence := Sequence{} ; var end_cumsum : Sequence := Sequence{} ; var now_val : int := 0 ; for Sequence{i, c} : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do ( execute ((now_val) : end_cumsum) ; if c = 'A' then ( before := 'A' ) else (if c = 'C' & before = 'A' then ( now_val := now_val + 1 ; before := '' ) else ( before := '' ) ) ; execute ((now_val) : start_cumsum)) ; execute ((now_val) : end_cumsum) ; for _anon : Integer.subrange(0, q-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (start_cumsum[r - 1+1] - start_cumsum[l - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N=int(input()) S={int(i)for i in input().split()} q=int(input()) T=(int(i)for i in input().split()) ans=0 for t in T : if t in S : ans+=1 print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : Set := input().split()->select(i | true)->collect(i | ("" + ((i)))->toInteger())->asSet() ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var T : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var ans : int := 0 ; for t : T do ( if (S)->includes(t) then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : t-=1 n,x,y,d=(int(_)for _ in input().strip().split(' ')) if abs(y-x)% d!=0 and(y-1)% d!=0 and(n-y)% d!=0 : print(-1) else : if abs(y-x)% d==0 : print(abs(y-x)//d) else : a=((x-1)//d+(y-1)//d if(x-1)% d==0 else(x-1)//d+1+(y-1)//d)if(y-1)% d==0 else 0x3f3f3f3f b=((n-x)//d+(n-y)//d if(n-x)% d==0 else(n-x)//d+1+(n-y)//d)if(n-y)% d==0 else 0x3f3f3f3f print(min(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( t := t - 1 ; var n : OclAny := null; var x : OclAny := null; var y : OclAny := null; var d : OclAny := null; Sequence{n,x,y,d} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name _)))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name strip) (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ' '))))))) ))))))))} ; if (y - x)->abs() mod d /= 0 & (y - 1) mod d /= 0 & (n - y) mod d /= 0 then ( execute (-1)->display() ) else ( if (y - x)->abs() mod d = 0 then ( execute ((y - x)->abs() div d)->display() ) else ( var a : int := if (y - 1) mod d = 0 then (if (x - 1) mod d = 0 then (x - 1) div d + (y - 1) div d else (x - 1) div d + 1 + (y - 1) div d endif) else 0x3f3f3f3f endif ; var b : int := if (n - y) mod d = 0 then (if (n - x) mod d = 0 then (n - x) div d + (n - y) div d else (n - x) div d + 1 + (n - y) div d endif) else 0x3f3f3f3f endif ; execute (Set{a, b}->min())->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def udiv(a,b): if a % b==0 : return a//b return a//b+1 for some_random_name in range(int(input())): n,x,y,d=map(int,input().split()) if(y-x)% d==0 : print(abs((y-x))//d) continue ans=9999999999999999999999999 if(n-y)% d==0 : ans=(udiv(n-x,d)+(n-y)//d) if((y-1)% d==0): ans=min(udiv(x-1,d)+(y-1)//d,ans) if ans==9999999999999999999999999 : ans=-1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for some_random_name : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; var y : OclAny := null; var d : OclAny := null; Sequence{n,x,y,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (y - x) mod d = 0 then ( execute (((y - x))->abs() div d)->display() ; continue ) else skip ; var ans : double := 9999999999999999999999999 ; if (n - y) mod d = 0 then ( ans := (udiv(n - x, d) + (n - y) div d) ) else skip ; if ((y - 1) mod d = 0) then ( ans := Set{udiv(x - 1, d) + (y - 1) div d, ans}->min() ) else skip ; if ans = 9999999999999999999999999 then ( ans := -1 ) else skip ; execute (ans)->display()); operation udiv(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a mod b = 0 then ( return a div b ) else skip ; return a div b + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil t=int(input()) for i in range(t): n,x,y,d=map(int,input().split()) res=9999999999 if abs(y-x)% d==0 : print(abs(y-x)//d) else : p=0 pp=0 if(y-1)% d==0 : p=(y-1)//d+ceil((x-1)/d) else : p=-1 if(n-y)% d==0 : pp=(n-y)//d+ceil((n-x)/d) else : pp=-1 if p==-1 : print(pp) elif pp==-1 : print(p) elif ptoInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var x : OclAny := null; var y : OclAny := null; var d : OclAny := null; Sequence{n,x,y,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var res : int := 9999999999 ; if (y - x)->abs() mod d = 0 then ( execute ((y - x)->abs() div d)->display() ) else ( var p : int := 0 ; var pp : int := 0 ; if (y - 1) mod d = 0 then ( p := (y - 1) div d + ceil((x - 1) / d) ) else ( p := -1 ) ; if (n - y) mod d = 0 then ( pp := (n - y) div d + ceil((n - x) / d) ) else ( pp := -1 ) ; if p = -1 then ( execute (pp)->display() ) else (if pp = -1 then ( execute (p)->display() ) else (if (p->compareTo(pp)) < 0 then ( execute (p)->display() ) else ( execute (pp)->display() ) ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n,x,y,d=map(int,input().split()) if(y-x)% d==0 : print(abs(y-x)//d) else : a=(y-1)% d b=(n-y)% d if a==b==0 : c1=(x-1)//d+((x-1)% d>0)+(y-1)//d c2=(n-x)//d+((n-x)% d>0)+(n-y)//d print(min(c1,c2)) elif a==0 : print((x-1)//d+((x-1)% d>0)+(y-1)//d) elif b==0 : print((n-x)//d+((n-x)% d>0)+(n-y)//d) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; var y : OclAny := null; var d : OclAny := null; Sequence{n,x,y,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (y - x) mod d = 0 then ( execute ((y - x)->abs() div d)->display() ) else ( var a : int := (y - 1) mod d ; var b : int := (n - y) mod d ; if a = b & (b == 0) then ( var c1 : int := (x - 1) div d + ((x - 1) mod d > 0) + (y - 1) div d ; var c2 : int := (n - x) div d + ((n - x) mod d > 0) + (n - y) div d ; execute (Set{c1, c2}->min())->display() ) else (if a = 0 then ( execute ((x - 1) div d + ((x - 1) mod d > 0) + (y - 1) div d)->display() ) else (if b = 0 then ( execute ((n - x) div d + ((n - x) mod d > 0) + (n - y) div d)->display() ) else ( execute (-1)->display() ) ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) print((a+b)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a + b) div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=input().split() a=int(a) b=int(b) print((a+b)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; execute ((a + b) div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(sum(map(int,input().split()))//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum() div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a,b=map(int,input().split()) print(math.floor((a+b)/2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (((a + b) / 2)->floor())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) x=int((a+b)/2) print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : int := ("" + (((a + b) / 2)))->toInteger() ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys INF=float('inf') MOD=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return input() def main(): n,q=LI() s='X'+SI() Q=[LI()for _ in range(q)] ac=[0] for i in range(1,n+1): if(s[i],s[i-1])==('C','A'): ac.append(ac[-1]+1) else : ac.append(ac[-1]) for l,r in Q : print(ac[r]-ac[l]) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var INF : double := ("" + (('inf')))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; main(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation SI() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation main() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := LI() ; var s : String := 'X' + SI() ; var Q : Sequence := Integer.subrange(0, q-1)->select(_anon | true)->collect(_anon | (LI())) ; var ac : Sequence := Sequence{ 0 } ; for i : Integer.subrange(1, n + 1-1) do ( if Sequence{s[i+1], s[i - 1+1]} = Sequence{'C', 'A'} then ( execute ((ac->last() + 1) : ac) ) else ( execute ((ac->last()) : ac) )) ; for _tuple : Q do (var _indx : int := 1; var l : OclAny := _tuple->at(_indx); _indx := _indx + 1; var r : OclAny := _tuple->at(_indx); execute (ac[r+1] - ac[l+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r=range(1,10); print(' YNeos'[int(input())in[i*j for i in r for j in r]: : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : Sequence := Integer.subrange(1, 10-1); execute (' YNeos'(subscript (test (logical_test (comparison (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))) in (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom (name j))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name r))))) (comp_iter (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name r))))))))) ])))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def summation(n): return n<<(n-1); n=2 ; print(summation(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 2; ; execute (summation(n))->display();; operation summation(n : OclAny) pre: true post: true activity: return n * (2->pow((n - 1)));; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def I(): return int(input()) def MI(): return map(int,input().split()) def LMI(): return list(map(int,input().split())) MOD=10**9+7 S=input() S=''.join(list(reversed(S))) while len(S)>0 : if S[: 7]=='remaerd' : S=S[7 :] elif S[: 6]=='resare' : S=S[6 :] elif S[: 5]in['esare','maerd']: S=S[5 :] else : print('NO') exit(0) print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var MOD : double := (10)->pow(9) + 7 ; var S : String := (OclFile["System.in"]).readLine() ; S := StringLib.sumStringsWithSeparator((((S)->reverse())), '') ; while (S)->size() > 0 do ( if S.subrange(1,7) = 'remaerd' then ( S := S.subrange(7+1) ) else (if S.subrange(1,6) = 'resare' then ( S := S.subrange(6+1) ) else (if (Sequence{'esare'}->union(Sequence{ 'maerd' }))->includes(S.subrange(1,5)) then ( S := S.subrange(5+1) ) else ( execute ('NO')->display() ; exit(0) ) ) ) ) ; execute ('YES')->display(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LMI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print('YNEOS'[len(input().replace('eraser','').replace('erase','').replace('dreamer','').replace('dream',''))>0 : : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ('YNEOS'(subscript (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name replace) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'eraser')))))) , (argument (test (logical_test (comparison (expr (atom ''))))))) ))) (trailer . (name replace) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'erase')))))) , (argument (test (logical_test (comparison (expr (atom ''))))))) ))) (trailer . (name replace) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'dreamer')))))) , (argument (test (logical_test (comparison (expr (atom ''))))))) ))) (trailer . (name replace) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'dream')))))) , (argument (test (logical_test (comparison (expr (atom ''))))))) ))))))))) ))))) > (comparison (expr (atom (number (integer 0)))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- text="".join(reversed(input())) words=["".join(reversed(x))for x in["dreamer","eraser","dream","erase"]] while text!="" : has_striped=False for word in words : if text.find(word)!=0 : continue text=text[len(word):] has_striped=True if not has_striped : break print("YES" if text=="" else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var text : String := StringLib.sumStringsWithSeparator((((OclFile["System.in"]).readLine())->reverse()), "") ; var words : Sequence := Sequence{"dreamer"}->union(Sequence{"eraser"}->union(Sequence{"dream"}->union(Sequence{ "erase" })))->select(x | true)->collect(x | (StringLib.sumStringsWithSeparator(((x)->reverse()), ""))) ; while text /= "" do ( var has_striped : boolean := false ; for word : words do ( if text->indexOf(word) - 1 /= 0 then ( continue ) else skip ; text := text.subrange((word)->size()+1) ; has_striped := true) ; if not(has_striped) then ( break ) else skip) ; execute (if text = "" then "YES" else "NO" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() ret=False while(len(S)>0): if S[-5 :]=='dream' : if len(S)==5 : ret=True break else : S=S[:-5] elif S[-7 :]=='dreamer' : if len(S)==7 : ret=True break else : S=S[:-7] elif S[-5 :]=='erase' : if len(S)==5 : ret=True break else : S=S[:-5] elif S[-6 :]=='eraser' : if len(S)==6 : ret=True break else : S=S[:-6] else : break if ret : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var ret : boolean := false ; while ((S)->size() > 0) do ( if S.subrange(-5+1) = 'dream' then ( if (S)->size() = 5 then ( ret := true ; break ) else ( S := S.subrange(1,-5) ) ) else (if S.subrange(-7+1) = 'dreamer' then ( if (S)->size() = 7 then ( ret := true ; break ) else ( S := S.subrange(1,-7) ) ) else (if S.subrange(-5+1) = 'erase' then ( if (S)->size() = 5 then ( ret := true ; break ) else ( S := S.subrange(1,-5) ) ) else (if S.subrange(-6+1) = 'eraser' then ( if (S)->size() = 6 then ( ret := true ; break ) else ( S := S.subrange(1,-6) ) ) else ( break ) ) ) ) ) ; if ret then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s_1=input() s=s_1[: :-1] while len(s)>=0 : if s[0 : 5]=="maerd" : s=s[5 : len(s)] continue elif s[0 : 7]=="remaerd" : s=s[7 : len(s)] continue elif s[0 : 5]=="esare" : s=s[5 : len(s)] continue elif s[0 : 6]=="resare" : s=s[6 : len(s)] continue elif s=="" : print("YES") break else : print("NO") break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s_1 : String := (OclFile["System.in"]).readLine() ; var s : OclAny := s var s_1 : String := (OclFile["System.in"]).readLine()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; while (s)->size() >= 0 do ( if s.subrange(0+1, 5) = "maerd" then ( s := s.subrange(5+1, (s)->size()) ; continue ) else (if s.subrange(0+1, 7) = "remaerd" then ( s := s.subrange(7+1, (s)->size()) ; continue ) else (if s.subrange(0+1, 5) = "esare" then ( s := s.subrange(5+1, (s)->size()) ; continue ) else (if s.subrange(0+1, 6) = "resare" then ( s := s.subrange(6+1, (s)->size()) ; continue ) else (if s = "" then ( execute ("YES")->display() ; break ) else ( execute ("NO")->display() ; break ) ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): N=100 s=sum(i for i in range(1,N+1)) s2=sum(i**2 for i in range(1,N+1)) return str(s**2-s2) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var N : int := 100 ; var s : OclAny := ((argument (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name N))) + (expr (atom (number (integer 1)))))))))) )))))))))->sum() ; var s2 : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name i))) ** (expr (atom (number (integer 2)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name N))) + (expr (atom (number (integer 1)))))))))) )))))))))->sum() ; return ("" + (((s)->pow(2) - s2))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s={int(input())for s in range(2)} a={1,2,3} print(list(a-s)[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Set := Integer.subrange(0, 2-1)->select(s | true)->collect(s | ("" + (((OclFile["System.in"]).readLine())))->toInteger())->asSet() ; var a : Set := Set{1}->union(Set{2}->union(Set{ 3 })) ; execute (OclType["Sequence"](a - s)->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math INF=10**18 PI=math.pi large_P=1000000007 def my_pow(N,a,M): if(a==0): return 1 else : if(a % 2==0): tempo=my_pow(N,a/2,M) return(tempo*tempo)% M else : tempo=my_pow(N,a-1,M) return(tempo*N)% M def my_combination(N,a,M): res=1 for i in range(0,a): res*=N-i res %=M for i in range(0,a): res*=my_pow(i+1,M-2,M) res %=M return res def my_combination_table(N,M,v): if(len(v)pow(18) ; var PI : OclAny := ; var large_P : int := 1000000007 ; skip ; skip ; skip ; var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(1, 4-1) do ( if (i /= A & i /= B) then ( execute (i)->display() ; break ) else skip); operation my_pow(N : OclAny, a : OclAny, M : OclAny) : OclAny pre: true post: true activity: if (a = 0) then ( return 1 ) else ( if (a mod 2 = 0) then ( var tempo : OclAny := my_pow(N, a / 2, M) ; return (tempo * tempo) mod M ) else ( tempo := my_pow(N, a - 1, M) ; return (tempo * N) mod M ) ); operation my_combination(N : OclAny, a : OclAny, M : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; for i : Integer.subrange(0, a-1) do ( res := res * N - i ; res := res mod M) ; for i : Integer.subrange(0, a-1) do ( res := res * my_pow(i + 1, M - 2, M) ; res := res mod M) ; return res; operation my_combination_table(N : OclAny, M : OclAny, v : OclAny) pre: true post: true activity: if (((v)->size()->compareTo(N + 1)) < 0) then ( var l : double := N + 1 - (v)->size() ; tempo := MatrixLib.elementwiseMult(Sequence{ 1 }, l) ; v := v->union(tempo) ) else skip ; for i : Integer.subrange(1, N + 1-1) do ( v[i+1] := v[i - 1+1] * (N - (i - 1)) ; v[i+1] := v[i+1] mod M ; v[i+1] := v[i+1] * my_pow(i, M - 2, M) ; v[i+1] := v[i+1] mod M) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) sa=input().count("-") sa=min([n-sa,sa]) ss=[] for _ in range(m): a,b=map(int,input().split()) b-=a ss.append((b % 2 and b<=sa<<1)and "1\n" or "0\n") print("".join(ss)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sa : OclAny := input()->count("-") ; sa := (Sequence{n - sa}->union(Sequence{ sa }))->min() ; var ss : Sequence := Sequence{} ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; b := b - a ; execute (((b mod 2 & (b->compareTo(sa * (2->pow(1)))) <= 0) & "1\n" or "0\n") : ss)) ; execute (StringLib.sumStringsWithSeparator((ss), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate n,q=map(int,input().split()) s=input() problems=[list(map(int,input().split()))for _ in range(q)] def count(total,i): return total+1 if s[i-1 : i+1]=='AC' else total cumsum=list(accumulate([0]+list(range(1,n)),count)) for l,r in problems : print(cumsum[r-1]-cumsum[l-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var problems : Sequence := Integer.subrange(0, q-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; skip ; var cumsum : Sequence := (accumulate(Sequence{ 0 }->union((Integer.subrange(1, n-1))), count)) ; for _tuple : problems do (var _indx : int := 1; var l : OclAny := _tuple->at(_indx); _indx := _indx + 1; var r : OclAny := _tuple->at(_indx); execute (cumsum[r - 1+1] - cumsum[l - 1+1])->display()); operation count(total : OclAny, i : OclAny) : OclAny pre: true post: true activity: return if s.subrange(i - 1+1, i + 1) = 'AC' then total + 1 else total endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A=input() B=input() if A=="1" or B=="1" : if A=="2" or B=="2" : print("3") elif A=="3" or B=="3" : print("2") elif A=="2" or B=="2" : if A=="3" or B=="3" : print("1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : String := (OclFile["System.in"]).readLine() ; var B : String := (OclFile["System.in"]).readLine() ; if A = "1" or B = "1" then ( if A = "2" or B = "2" then ( execute ("3")->display() ) else (if A = "3" or B = "3" then ( execute ("2")->display() ) else skip) ) else (if A = "2" or B = "2" then ( if A = "3" or B = "3" then ( execute ("1")->display() ) else skip ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pairwiseDifference(arr,n): for i in range(n-1): diff=abs(arr[i]-arr[i+1]) print(diff,end=" ") if __name__=="__main__" : arr=[4,10,15,5,6] n=len(arr) pairwiseDifference(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{4}->union(Sequence{10}->union(Sequence{15}->union(Sequence{5}->union(Sequence{ 6 })))) ; n := (arr)->size() ; pairwiseDifference(arr, n) ) else skip; operation pairwiseDifference(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n - 1-1) do ( var diff : double := (arr[i+1] - arr[i + 1+1])->abs() ; execute (diff)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin INF=float("inf") IINF=10**18 MOD=10**9+7 a=int(stdin.readline().rstrip()) b=int(stdin.readline().rstrip()) if a!=1 and b!=1 : print(1) if a!=2 and b!=2 : print(2) if a!=3 and b!=3 : print(3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var INF : double := ("" + (("inf")))->toReal() ; var IINF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; var a : int := ("" + ((stdin.readLine().rstrip())))->toInteger() ; var b : int := ("" + ((stdin.readLine().rstrip())))->toInteger() ; if a /= 1 & b /= 1 then ( execute (1)->display() ) else skip ; if a /= 2 & b /= 2 then ( execute (2)->display() ) else skip ; if a /= 3 & b /= 3 then ( execute (3)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=[1,2,3] for i in range(2): l.remove(int(input())) print(l[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; for i : Integer.subrange(0, 2-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) /: l)) ; execute (l->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() nums=input().split() reversed_nums=reversed(nums) print(' '.join(reversed_nums)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var nums : OclAny := input().split() ; var reversed_nums : Sequence := (nums)->reverse() ; execute (StringLib.sumStringsWithSeparator((reversed_nums), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=map(int,input().split()) a=list(a) for i in range(len(a),0,-1): if a[i-1]==a[0]: print(a[0],end='\n') else : print(a[i-1],end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := (a) ; for i : Integer.subrange(0 + 1, (a)->size())->reverse() do ( if a[i - 1+1] = a->first() then ( execute (a->first())->display() ) else ( execute (a[i - 1+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() print(" ".join(input().split()[: :-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; execute (StringLib.sumStringsWithSeparator((input().split()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function raw_input() print(' '.join(reversed(raw_input().split()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; raw_input() ; execute (StringLib.sumStringsWithSeparator(((raw_input().split())->reverse()), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) a.reverse() print(' '.join(map(str,a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->reverse() ; execute (StringLib.sumStringsWithSeparator(((a)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- Max=100 def countCommon(mat,n): res=0 for i in range(n): if mat[i][i]==mat[i][n-i-1]: res=res+1 return res mat=[[1,2,3],[4,5,6],[7,8,9]] print(countCommon(mat,3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Max : int := 100 ; skip ; mat := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))}->union(Sequence{ Sequence{7}->union(Sequence{8}->union(Sequence{ 9 })) })) ; execute (countCommon(mat, 3))->display(); operation countCommon(mat : OclAny, n : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( if mat[i+1][i+1] = mat[i+1][n - i - 1+1] then ( res := res + 1 ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin sN,sQ=stdin.readline().split() N,Q=int(sN),int(sQ) S=stdin.readline().rstrip() data=[stdin.readline().split()for itr in range(Q)] grid=[None]*N count=0 for num in range(N): if num==0 : grid[num]=count continue if S[num]=='C' and S[num-1]=='A' : count+=1 grid[num]=count continue grid[num]=count for itr in range(Q): l=int(data[itr][0])-1 r=int(data[itr][1])-1 print(grid[r]-grid[l]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var sN : OclAny := null; var sQ : OclAny := null; Sequence{sN,sQ} := stdin.readLine().split() ; var N : OclAny := null; var Q : OclAny := null; Sequence{N,Q} := Sequence{("" + ((sN)))->toInteger(),("" + ((sQ)))->toInteger()} ; var S : OclAny := stdin.readLine().rstrip() ; var data : Sequence := Integer.subrange(0, Q-1)->select(itr | true)->collect(itr | (stdin.readLine().split())) ; var grid : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, N) ; var count : int := 0 ; for num : Integer.subrange(0, N-1) do ( if num = 0 then ( grid[num+1] := count ; continue ) else skip ; if S[num+1] = 'C' & S[num - 1+1] = 'A' then ( count := count + 1 ; grid[num+1] := count ; continue ) else skip ; grid[num+1] := count) ; for itr : Integer.subrange(0, Q-1) do ( var l : double := ("" + ((data[itr+1]->first())))->toInteger() - 1 ; var r : double := ("" + ((data[itr+1][1+1])))->toInteger() - 1 ; execute (grid[r+1] - grid[l+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=int(input()) if n>27 : print(m) else : print(m %(2**n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n > 27 then ( execute (m)->display() ) else ( execute (m mod ((2)->pow(n)))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=int(input()) a=2**n b=m % a print(b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : double := (2)->pow(n) ; var b : int := m mod a ; execute (b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,s=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) ans="NO" if(a[s-1]or b[s-1])and a[0]: if a[s-1]: ans="YES" else : for i in range(s,n): if a[i]and b[i]: ans="YES" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : String := "NO" ; if (a[s - 1+1] or b[s - 1+1]) & a->first() then ( if a[s - 1+1] then ( ans := "YES" ) else ( for i : Integer.subrange(s, n-1) do ( if a[i+1] & b[i+1] then ( ans := "YES" ) else skip) ) ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) if a>30 : print(input()) else : print(int(input())%(2**a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if a > 30 then ( execute ((OclFile["System.in"]).readLine())->display() ) else ( execute (("" + (((OclFile["System.in"]).readLine())))->toInteger() mod ((2)->pow(a)))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=int(input()),int(input()) print(m %(1<toInteger(),("" + (((OclFile["System.in"]).readLine())))->toInteger()} ; execute (m mod (1 * (2->pow(n))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math x=int(input()) y=int(input()) try : l=math.pow(2,x) except OverflowError : l=math.inf print(int(y % l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var y : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; try ( var l : double := (2)->pow(x)) (except_clause except (test (logical_test (comparison (expr (atom (name OverflowError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name math)) (trailer . (name inf)))))))))))))) ; execute (("" + ((y mod l)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,data=0): self.data=data self.left=None self.right=None def constructTreeUtil(post,n): root=Node(post[n-1]) s=[] s.append(root) i=n-2 while(i>=0): x=Node(post[i]) temp=None while(len(s)>0 and post[i]exists( _x | result = _x ); attribute data : int := data; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(data : int) : Node pre: true post: true activity: self.data := data ; self.left := null ; self.right := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; post := Sequence{1}->union(Sequence{7}->union(Sequence{5}->union(Sequence{50}->union(Sequence{40}->union(Sequence{ 10 }))))) ; size := (post)->size() ; root := constructTree(post, size) ; execute ("Inorder traversal of the constructed tree:")->display() ; printInorder(root); operation constructTreeUtil(post : OclAny, n : OclAny) : OclAny pre: true post: true activity: var root : Node := (Node.newNode()).initialise(post[n - 1+1]) ; var s : Sequence := Sequence{} ; execute ((root) : s) ; var i : double := n - 2 ; while (i >= 0) do ( var x : Node := (Node.newNode()).initialise(post[i+1]) ; var temp : OclAny := null ; while ((s)->size() > 0 & (post[i+1]->compareTo(s->last().data)) < 0) do ( temp := s->last() ; s := s->front()) ; if (temp /= null) then ( temp.left := x ) else ( s->last().right := x ) ; execute ((x) : s) ; i := i - 1) ; return root; operation constructTree(post : OclAny, size : OclAny) : OclAny pre: true post: true activity: return constructTreeUtil(post, size); operation printInorder(node : OclAny) pre: true post: true activity: if (node = null) then ( return ) else skip ; printInorder(node.left) ; execute (node.data)->display() ; printInorder(node.right); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=[input()for _ in range(8)] print(90) a=-1 for j in range(8): for i in range(7,a,a): print(m[i][j],end='') print() print(180) for i in range(7,a,a): for j in range(7,a,a): print(m[i][j],end='') print() print(270) for j in range(7,a,a): for i in range(8): print(m[i][j],end='') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : Sequence := Integer.subrange(0, 8-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; execute (90)->display() ; var a : int := -1 ; for j : Integer.subrange(0, 8-1) do ( for i : Integer.subrange(7, a-1)->select( $x | ($x - 7) mod a = 0 ) do ( execute (m[i+1][j+1])->display()) ; execute (->display()) ; execute (180)->display() ; for i : Integer.subrange(7, a-1)->select( $x | ($x - 7) mod a = 0 ) do ( for j : Integer.subrange(7, a-1)->select( $x | ($x - 7) mod a = 0 ) do ( execute (m[i+1][j+1])->display()) ; execute (->display()) ; execute (270)->display() ; for j : Integer.subrange(7, a-1)->select( $x | ($x - 7) mod a = 0 ) do ( for i : Integer.subrange(0, 8-1) do ( execute (m[i+1][j+1])->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def rotate_ccw(data): A=[['']*8 for _ in range(8)] for i in range(8): for j in range(8): A[i][j]=data[j][7-i] for l in A : print(''.join(l)) return A def rotate_cw(data): A=[['']*8 for _ in range(8)] for i in range(8): for j in range(8): A[i][j]=data[7-j][i] for l in A : print(''.join(l)) return A def main(args): data=[] for _ in range(8): data.append(list(input().strip())) print('90') data=rotate_cw(data) print('180') data=rotate_cw(data) print('270') data=rotate_cw(data) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation rotate_ccw(data : OclAny) : OclAny pre: true post: true activity: var A : Sequence := Integer.subrange(0, 8-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ '' }, 8))) ; for i : Integer.subrange(0, 8-1) do ( for j : Integer.subrange(0, 8-1) do ( A[i+1][j+1] := data[j+1][7 - i+1])) ; for l : A do ( execute (StringLib.sumStringsWithSeparator((l), ''))->display()) ; return A; operation rotate_cw(data : OclAny) : OclAny pre: true post: true activity: A := Integer.subrange(0, 8-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ '' }, 8))) ; for i : Integer.subrange(0, 8-1) do ( for j : Integer.subrange(0, 8-1) do ( A[i+1][j+1] := data[7 - j+1][i+1])) ; for l : A do ( execute (StringLib.sumStringsWithSeparator((l), ''))->display()) ; return A; operation main(args : OclAny) pre: true post: true activity: data := Sequence{} ; for _anon : Integer.subrange(0, 8-1) do ( execute (((input()->trim())) : data)) ; execute ('90')->display() ; data := rotate_cw(data) ; execute ('180')->display() ; data := rotate_cw(data) ; execute ('270')->display() ; data := rotate_cw(data); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Draw(pattern,rowRange,colRange): s="" for row in rowRange : for col in colRange : s+=pattern[row][col] s+="\n" print(s,end="") def Draw2(pattern,colRange,rowRange): s="" for col in colRange : for row in rowRange : s+=pattern[row][col] s+="\n" print(s,end="") pattern=[input()for lp in range(8)] print("90") Draw2(pattern,range(0,8),range(7,-1,-1)) print("180") Draw(pattern,range(7,-1,-1),range(7,-1,-1)) print("270") Draw2(pattern,range(7,-1,-1),range(0,8)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; pattern := Integer.subrange(0, 8-1)->select(lp | true)->collect(lp | ((OclFile["System.in"]).readLine())) ; execute ("90")->display() ; Draw2(pattern, Integer.subrange(0, 8-1), Integer.subrange(-1 + 1, 7)->reverse()) ; execute ("180")->display() ; Draw(pattern, Integer.subrange(-1 + 1, 7)->reverse(), Integer.subrange(-1 + 1, 7)->reverse()) ; execute ("270")->display() ; Draw2(pattern, Integer.subrange(-1 + 1, 7)->reverse(), Integer.subrange(0, 8-1)); operation Draw(pattern : OclAny, rowRange : OclAny, colRange : OclAny) pre: true post: true activity: var s : String := "" ; for row : rowRange do ( for col : colRange do ( s := s + pattern[row+1][col+1]) ; s := s + "\n") ; execute (s)->display(); operation Draw2(pattern : OclAny, colRange : OclAny, rowRange : OclAny) pre: true post: true activity: s := "" ; for col : colRange do ( for row : rowRange do ( s := s + pattern[row+1][col+1]) ; s := s + "\n") ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for i in range(T): l,r=map(int,input().split()) print(l,l*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, T-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (l)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rotate(k,p): q=[] print('90' if k==1 else('180' if k==2 else '270')) for i in range(8): t='' for j in range(8)[: :-1]: print(p[j][i],end='') t+=p[j][i] q.append(t) print() return q p=[input()for _ in range(8)] for i in range(1,4): p=rotate(i,p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; p := Integer.subrange(0, 8-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; for i : Integer.subrange(1, 4-1) do ( p := rotate(i, p)); operation rotate(k : OclAny, p : OclAny) : OclAny pre: true post: true activity: var q : Sequence := Sequence{} ; execute (if k = 1 then '90' else (if k = 2 then '180' else '270' endif) endif)->display() ; for i : Integer.subrange(0, 8-1) do ( var t : String := '' ; for j : range(8)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( execute (p[j+1][i+1])->display() ; t := t + p[j+1][i+1]) ; execute ((t) : q) ; execute (->display()) ; return q; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def spin(p): ret=[[None]*8 for _ in range(8)] for i in range(8): for j in range(8): ret[i][j]=p[7-j][i] return ret def print_p(p): for line in p : print("".join(line)) p=[input()for _ in range(8)] print(90) p=spin(p) print_p(p) print(180) p=spin(p) print_p(p) print(270) p=spin(p) print_p(p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; p := Integer.subrange(0, 8-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; execute (90)->display() ; p := spin(p) ; print_p(p) ; execute (180)->display() ; p := spin(p) ; print_p(p) ; execute (270)->display() ; p := spin(p) ; print_p(p); operation spin(p : OclAny) : OclAny pre: true post: true activity: var ret : Sequence := Integer.subrange(0, 8-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ null }, 8))) ; for i : Integer.subrange(0, 8-1) do ( for j : Integer.subrange(0, 8-1) do ( ret[i+1][j+1] := p[7 - j+1][i+1])) ; return ret; operation print_p(p : OclAny) pre: true post: true activity: for line : p do ( execute (StringLib.sumStringsWithSeparator((line), ""))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minSwap(arr,n,k): count=0 for i in range(0,n): if(arr[i]<=k): count=count+1 bad=0 for i in range(0,count): if(arr[i]>k): bad=bad+1 ans=bad j=count for i in range(0,n): if(j==n): break if(arr[i]>k): bad=bad-1 if(arr[j]>k): bad=bad+1 ans=min(ans,bad) j=j+1 return ans arr=[2,1,5,6,3] n=len(arr) k=3 print(minSwap(arr,n,k)) arr1=[2,7,9,5,8,7,4] n=len(arr1) k=5 print(minSwap(arr1,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{1}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 3 })))) ; n := (arr)->size() ; k := 3 ; execute (minSwap(arr, n, k))->display() ; var arr1 : Sequence := Sequence{2}->union(Sequence{7}->union(Sequence{9}->union(Sequence{5}->union(Sequence{8}->union(Sequence{7}->union(Sequence{ 4 })))))) ; n := (arr1)->size() ; k := 5 ; execute (minSwap(arr1, n, k))->display(); operation minSwap(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ((arr[i+1]->compareTo(k)) <= 0) then ( count := count + 1 ) else skip) ; var bad : int := 0 ; for i : Integer.subrange(0, count-1) do ( if ((arr[i+1]->compareTo(k)) > 0) then ( bad := bad + 1 ) else skip) ; var ans : int := bad ; var j : int := count ; for i : Integer.subrange(0, n-1) do ( if (j = n) then ( break ) else skip ; if ((arr[i+1]->compareTo(k)) > 0) then ( bad := bad - 1 ) else skip ; if ((arr[j+1]->compareTo(k)) > 0) then ( bad := bad + 1 ) else skip ; ans := Set{ans, bad}->min() ; j := j + 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=[int(x)for x in input().split()] b=[int(x)for x in input().split()] def func(m,n): for j in range(m,n): if a[j]==1 and b[j]==1 : return "YES" return "NO" if a[0]==1 : if a[m-1]==1 : print("YES") else : if b[m-1]==1 : print(func(m,n)) else : print("NO") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var b : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; skip ; if a->first() = 1 then ( if a[m - 1+1] = 1 then ( execute ("YES")->display() ) else ( if b[m - 1+1] = 1 then ( execute (func(m, n))->display() ) else ( execute ("NO")->display() ) ) ) else ( execute ("NO")->display() ); operation func(m : OclAny, n : OclAny) : OclAny pre: true post: true activity: for j : Integer.subrange(m, n-1) do ( if a[j+1] = 1 & b[j+1] = 1 then ( return "YES" ) else skip) ; return "NO"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() ans=p=0 for s in S : k=ord(s)-ord('A') if k<=p : ans+=1 p=k print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var ans : OclAny := 0; var p : int := 0 ; for s : S->characters() do ( var k : double := (s)->char2byte() - ('A')->char2byte() ; if (k->compareTo(p)) <= 0 then ( ans := ans + 1 ) else skip ; p := k) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() print((s[0]=='A')+sum(s[i]>=s[i+1]for i in range(len(s)-1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; execute ((s->first() = 'A') + ((argument (test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) >= (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))) - (expr (atom (number (integer 1)))))))))) )))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin s="A"+stdin.readline().rstrip() AZ="ABCDEFGHIJKLMNOPQRSTUVWXYZ" ans=0 for i in range(1,len(s)): if AZ.find(s[i])<=AZ.find(s[i-1]): ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : String := "A" + stdin.readLine().rstrip() ; var AZ : String := "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; var ans : int := 0 ; for i : Integer.subrange(1, (s)->size()-1) do ( if (AZ->indexOf(s[i+1]) - 1->compareTo(AZ->indexOf(s[i - 1+1]) - 1)) <= 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ" Now=0 ans=0 for s in S : Next=alpha.find(s) if(Nowcharacters() do ( var Next : int := alpha->indexOf(s) - 1 ; if ((Now->compareTo(Next)) < 0) then ( skip ) else ( ans := ans + 1 ) ; Now := Next) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() cnt,x=0,65 for c in S : cnt=cnt+(x>=ord(c)) x=ord(c) print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var cnt : OclAny := null; var x : OclAny := null; Sequence{cnt,x} := Sequence{0,65} ; for c : S->characters() do ( var cnt : OclAny := cnt + ((x->compareTo((c)->char2byte())) >= 0) ; var x : int := (c)->char2byte()) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def xorOfSum(a,n): answer=0 for i in range(n): for j in range(i+1,n): answer ^=(a[i]+a[j]) return answer if __name__=='__main__' : n=3 A=[1,2,3] print(xorOfSum(A,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 3 ; var A : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; execute (xorOfSum(A, n))->display() ) else skip; operation xorOfSum(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var answer : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( answer := answer xor (a[i+1] + a[j+1]))) ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b=map(int,input().split()) print(a,a*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def steps(string,n): flag=False x=0 for i in range(len(string)): if(x==0): flag=True if(x==n-1): flag=False for j in range(x): print("*",end="") print(string[i]) if(flag==True): x+=1 else : x-=1 n=4 string="GeeksForGeeks" print("String: ",string) print("Max Length of Steps: ",n) steps(string,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 4 ; string := "GeeksForGeeks" ; execute ("String: ")->display() ; execute ("Max Length of Steps: ")->display() ; steps(string, n); operation steps(string : OclAny, n : OclAny) pre: true post: true activity: var flag : boolean := false ; var x : int := 0 ; for i : Integer.subrange(0, (string)->size()-1) do ( if (x = 0) then ( flag := true ) else skip ; if (x = n - 1) then ( flag := false ) else skip ; for j : Integer.subrange(0, x-1) do ( execute ("*")->display()) ; execute (string[i+1])->display() ; if (flag = true) then ( x := x + 1 ) else ( x := x - 1 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPrime(n): if n<=1 : return False for i in range(2,n): if n % i==0 : return False return True def printPrime(n): for i in range(2,n+1): if isPrime(i): print(i,end=" ") if __name__=="__main__" : n=7 printPrime(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 7 ; printPrime(n) ) else skip; operation isPrime(n : OclAny) : OclAny pre: true post: true activity: if n <= 1 then ( return false ) else skip ; for i : Integer.subrange(2, n-1) do ( if n mod i = 0 then ( return false ) else skip) ; return true; operation printPrime(n : OclAny) pre: true post: true activity: for i : Integer.subrange(2, n + 1-1) do ( if isPrime(i) then ( execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPrime(n): if(n<=1): return False if(n<=3): return True if(n % 2==0 or n % 3==0): return False i=5 while(i*i<=n): if(n % i==0 or n %(i+2)==0): return False i=i+6 return True def printPrime(n): for i in range(2,n+1): if isPrime(i): print(i,end=" ") n=7 printPrime(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 7 ; printPrime(n); operation isPrime(n : OclAny) : OclAny pre: true post: true activity: if (n <= 1) then ( return false ) else skip ; if (n <= 3) then ( return true ) else skip ; if (n mod 2 = 0 or n mod 3 = 0) then ( return false ) else skip ; var i : int := 5 ; while ((i * i->compareTo(n)) <= 0) do ( if (n mod i = 0 or n mod (i + 2) = 0) then ( return false ) else skip ; i := i + 6) ; return true; operation printPrime(n : OclAny) pre: true post: true activity: for i : Integer.subrange(2, n + 1-1) do ( if isPrime(i) then ( execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000000 Sieve=[0]*(MAX+1) def constructSieve(): for i in range(2,MAX+1): if(Sieve[i]==0): for j in range(2*i,MAX+1,i): temp=j ; while(temp>1 and temp % i==0): Sieve[j]+=1 ; temp=temp//i ; def checkElements(A,n,k): for i in range(n): if(Sieve[A[i]]==k): print("YES"); else : print("NO"); if __name__=="__main__" : constructSieve(); k=3 ; A=[12,36,42,72]; n=len(A); checkElements(A,n,k); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1000000 ; var Sieve : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX + 1)) ; skip ; skip ; if __name__ = "__main__" then ( constructSieve(); ; k := 3; ; A := Sequence{12}->union(Sequence{36}->union(Sequence{42}->union(Sequence{ 72 }))); ; n := (A)->size(); ; checkElements(A, n, k); ) else skip; operation constructSieve() pre: true post: true activity: for i : Integer.subrange(2, MAX + 1-1) do ( if (Sieve[i+1] = 0) then ( for j : Integer.subrange(2 * i, MAX + 1-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ( var temp : OclAny := j; ; while (temp > 1 & temp mod i = 0) do ( Sieve[j+1] := Sieve[j+1] + 1; ; temp := temp div i;)) ) else skip); operation checkElements(A : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if (Sieve[A[i+1]+1] = k) then ( execute ("YES")->display(); ) else ( execute ("NO")->display(); )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- st,als=map(int,input().split()) up=input().replace('','') down=input().replace('','') cnt=up[als-1 :].find('1') if up[0]=='1' and cnt!=-1 : cnt+=(als-1) if cnt+1==als : print('YES') else : if down[als-1]=='1' : for j in range(cnt,st): if up[j]=='1' and down[j]=='1' : print('YES') break else : print('NO') else : print('NO') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var st : OclAny := null; var als : OclAny := null; Sequence{st,als} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var up : OclAny := input().replace('', '') ; var down : OclAny := input().replace('', '') ; var cnt : OclAny := up.subrange(als - 1+1)->indexOf('1') - 1 ; if up->first() = '1' & cnt /= -1 then ( cnt := cnt + (als - 1) ; if cnt + 1 = als then ( execute ('YES')->display() ) else ( if down[als - 1+1] = '1' then ( (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name cnt))))))) , (argument (test (logical_test (comparison (expr (atom (name st)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name up)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) == (comparison (expr (atom '1'))))) and (logical_test (comparison (comparison (expr (atom (name down)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) == (comparison (expr (atom '1'))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) ))))))))))))))) ) else ( execute ('NO')->display() ) ) ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re def isValidTime(time): regexPattern="(1[012]|[1-9]):"+"[0-5][0-9](\\s)"+"?(?i)(am|pm)" ; compiledPattern=re.compile(regexPattern); if(time==None): return False ; if re.search(compiledPattern,time): return True else : return False if __name__=="__main__" : str1="12:15 AM" ; print(isValidTime(str1)); str2="9:45PM" ; print(isValidTime(str2)); str3="1:15" ; print(isValidTime(str3)); str4="17:30" ; print(isValidTime(str4)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var str1 : String := "12:15 AM"; ; execute (isValidTime(str1))->display(); ; var str2 : String := "9:45PM"; ; execute (isValidTime(str2))->display(); ; var str3 : String := "1:15"; ; execute (isValidTime(str3))->display(); ; var str4 : String := "17:30"; ; execute (isValidTime(str4))->display(); ) else skip; operation isValidTime(time : OclAny) : OclAny pre: true post: true activity: var regexPattern : String := "(1[012]|[1-9]):" + "[0-5][0-9](\\s)" + "?(?i)(am|pm)"; ; var compiledPattern : OclRegex := OclRegex.compile(regexPattern); ; if (time = null) then ( return false; ) else skip ; if (time)->firstMatch(compiledPattern) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bin(n): if n>1 : bin(n//2) print(n % 2,end="") if __name__=="__main__" : bin(7) print() bin(4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( bin(7) ; execute (->display() ; bin(4) ) else skip; operation bin(n : OclAny) pre: true post: true activity: if n > 1 then ( bin(n div 2) ) else skip ; execute (n mod 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculate(s,e,m): t=e-s c=0 if t>m[4]: c+=m[4]*m[1] t=t-m[4] else : c+=m[1]*t t=0 if t>m[5]: c+=m[5]*m[2] t=t-m[5] else : c+=m[2]*t t=0 c+=m[3]*t return c work=[] m=[int(i)for i in input().split(" ")] for i in range(0,m[0]): l=[int(i)for i in input().split(" ")] work.append(l) n=len(work) power=0 for i in range(len(work)): if i==n-1 : power+=(work[i][1]-work[i][0])*m[1] else : power+=calculate(work[i][1],work[i+1][0],m)+(work[i][1]-work[i][0])*m[1] print(power) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var work : Sequence := Sequence{} ; m := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; for i : Integer.subrange(0, m->first()-1) do ( var l : Sequence := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute ((l) : work)) ; var n : int := (work)->size() ; var power : int := 0 ; for i : Integer.subrange(0, (work)->size()-1) do ( if i = n - 1 then ( power := power + (work[i+1][1+1] - work[i+1]->first()) * m[1+1] ) else ( power := power + calculate(work[i+1][1+1], work[i + 1+1]->first(), m) + (work[i+1][1+1] - work[i+1]->first()) * m[1+1] )) ; execute (power)->display(); operation calculate(s : OclAny, e : OclAny, m : OclAny) : OclAny pre: true post: true activity: var t : double := e - s ; var c : int := 0 ; if (t->compareTo(m[4+1])) > 0 then ( c := c + m[4+1] * m[1+1] ; t := t - m[4+1] ) else ( c := c + m[1+1] * t ; t := 0 ) ; if (t->compareTo(m[5+1])) > 0 then ( c := c + m[5+1] * m[2+1] ; t := t - m[5+1] ) else ( c := c + m[2+1] * t ; t := 0 ) ; c := c + m[3+1] * t ; return c; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d,e,f=map(int,input().split()) ran=[] for i in range(a): ran.append(list(map(int,input().split()))) fee=0 for i in range(0,a-1): fee+=b*(ran[i][1]-ran[i][0]) time=ran[i+1][0]-ran[i][1] if time<=e : fee+=b*time elif time>e and time<=(e+f): fee+=b*e+c*(time-e) else : fee+=b*e+c*f+d*(time-e-f) fee+=b*(ran[-1][1]-ran[-1][0]) print(fee) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; var f : OclAny := null; Sequence{a,b,c,d,e,f} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ran : Sequence := Sequence{} ; for i : Integer.subrange(0, a-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : ran)) ; var fee : int := 0 ; for i : Integer.subrange(0, a - 1-1) do ( fee := fee + b * (ran[i+1][1+1] - ran[i+1]->first()) ; var time : double := ran[i + 1+1]->first() - ran[i+1][1+1] ; if (time->compareTo(e)) <= 0 then ( fee := fee + b * time ) else (if (time->compareTo(e)) > 0 & (time->compareTo((e + f))) <= 0 then ( fee := fee + b * e + c * (time - e) ) else ( fee := fee + b * e + c * f + d * (time - e - f) ) ) ) ; fee := fee + b * (ran->last()[1+1] - ran->last()->first()) ; execute (fee)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def func(): n,p1,p2,p3,t1,t2=map(int,input().strip().split()) left,right=[0]*n,[0]*n power=0 for i in range(n): left[i],right[i]=map(int,input().strip().split()) power+=(right[i]-left[i])*p1 for i in range(n-1): interval=left[i+1]-right[i] if interval<=t1 : power+=p1*interval elif t1trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var left : OclAny := null; var right : OclAny := null; Sequence{left,right} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, n),MatrixLib.elementwiseMult(Sequence{ 0 }, n)} ; var power : int := 0 ; for i : Integer.subrange(0, n-1) do ( var left[i+1] : OclAny := null; var right[i+1] : OclAny := null; Sequence{left[i+1],right[i+1]} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; power := power + (right[i+1] - left[i+1]) * p1) ; for i : Integer.subrange(0, n - 1-1) do ( var interval : double := left[i + 1+1] - right[i+1] ; if (interval->compareTo(t1)) <= 0 then ( power := power + p1 * interval ) else (if (t1->compareTo(interval)) < 0 & (interval <= t1 + t2) then ( power := power + p1 * t1 + p2 * (interval - t1) ) else ( power := power + p1 * t1 + p2 * t2 + p3 * (interval - t1 - t2) ) ) ) ; execute (power)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) while k>0 : k-=1 v,y=map(int,input().split()) print(v,v*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while k > 0 do ( k := k - 1 ; var v : OclAny := null; var y : OclAny := null; Sequence{v,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (v)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=lambda : map(int,input().split()) n,a,b,c,u,v=I() exec('x=['+n*'[*I()],'+']') r=0 for i in range(n): r+=a*(x[i][1]-x[i][0]) if i : t=x[i][0]-x[i-1][1] s=min(t,u); r+=s*a ; t-=s s=min(t,v); r+=s*b ; t-=s r+=t*c print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var u : OclAny := null; var v : OclAny := null; Sequence{n,a,b,c,u,v} := I->apply() ; (expr (expr (expr (atom 'x=[')) + (expr (expr (atom (name n))) * (expr (atom '[*I()],')))) + (expr (atom ']'))) ; var r : int := 0 ; for i : Integer.subrange(0, n-1) do ( r := r + a * (x[i+1][1+1] - x[i+1]->first()) ; if i then ( var t : double := x[i+1]->first() - x[i - 1+1][1+1] ; var s : OclAny := Set{t, u}->min(); r := r + s * a; t := t - s ; s := Set{t, v}->min(); r := r + s * b; t := t - s ; r := r + t * c ) else skip) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,p1,p2,p3,t1,t2=list(map(int,input().split())) l,r=list(map(int,input().split())) s=(r-l)*p1 for i in range(n-1): x=r l,r=list(map(int,input().split())) s=s+(r-l)*p1 t=l-x if t>t1+t2 : s=s+(t1*p1)+(t2*p2)+((t-t1-t2)*p3) elif t>t1 : s=s+(t1*p1)+((t-t1)*p2) else : s=s+(t*p1) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var p1 : OclAny := null; var p2 : OclAny := null; var p3 : OclAny := null; var t1 : OclAny := null; var t2 : OclAny := null; Sequence{n,p1,p2,p3,t1,t2} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : double := (r - l) * p1 ; for i : Integer.subrange(0, n - 1-1) do ( var x : OclAny := r ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; s := s + (r - l) * p1 ; var t : double := l - x ; if (t->compareTo(t1 + t2)) > 0 then ( s := s + (t1 * p1) + (t2 * p2) + ((t - t1 - t2) * p3) ) else (if (t->compareTo(t1)) > 0 then ( s := s + (t1 * p1) + ((t - t1) * p2) ) else ( s := s + (t * p1) ) ) ) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def findSecondMinimumValue(self,root): if not root : return-1 ans=float('inf') min_val=root.val stack=[root] while stack : curr=stack.pop() if not curr : continue if min_valexists( _x | result = _x ); operation findSecondMinimumValue(root : OclAny) : OclAny pre: true post: true activity: if not(root) then ( return -1 ) else skip ; var ans : double := ("" + (('inf')))->toReal() ; var min_val : OclAny := root.val ; var stack : Sequence := Sequence{ root } ; while stack do ( var curr : OclAny := stack->last() ; stack := stack->front() ; if not(curr) then ( continue ) else skip ; if (min_val->compareTo(curr.val)) < 0 & (curr.val < ans) then ( ans := curr.val ) else (if curr.val = min_val then ( execute ((curr.left) : stack) ; execute ((curr.right) : stack) ) else skip)) ; return if (ans->compareTo(("" + (('inf')))->toReal())) < 0 then ans else -1 endif; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import string def distance(src,dest): idx=string.ascii_uppercase.find(src)+1 idx_d=string.ascii_uppercase.find(dest)+1 aux=abs(idx-idx_d) return min(aux,26-aux) def calc_distance(s): tar='ACTG' aux=0 for i in range(4): aux+=distance(s[i],tar[i]) return aux n=int(input()) s=input() ans=99999999999999999 for i in range(len(s)-3): res=sum(map(lambda x : distance(x[0],x[1]),zip(s[i : i+4],'ACTG'))) ans=min(ans,res) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; s := (OclFile["System.in"]).readLine() ; var ans : int := 99999999999999999 ; for i : Integer.subrange(0, (s)->size() - 3-1) do ( var res : OclAny := ((Integer.subrange(1, s.subrange(i+1, i + 4)->size())->collect( _indx | Sequence{s.subrange(i+1, i + 4)->at(_indx), 'ACTG'->at(_indx)} ))->collect( _x | (lambda x : OclAny in (distance(x->first(), x[1+1])))->apply(_x) ))->sum() ; ans := Set{ans, res}->min()) ; execute (ans)->display(); operation distance(src : OclAny, dest : OclAny) : OclAny pre: true post: true activity: var idx : OclAny := string.ascii_uppercase->indexOf(src) - 1 + 1 ; var idx_d : OclAny := string.ascii_uppercase->indexOf(dest) - 1 + 1 ; var aux : double := (idx - idx_d)->abs() ; return Set{aux, 26 - aux}->min(); operation calc_distance(s : OclAny) : OclAny pre: true post: true activity: var tar : String := 'ACTG' ; aux := 0 ; for i : Integer.subrange(0, 4-1) do ( aux := aux + distance(s[i+1], tar[i+1])) ; return aux; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sdist2(l): su=[0,2,19,6] alp="ABCDEFGHIJKLMNOPQRSTUVWXYZ" diff=[] for i in range(4): x=alp.index(l[i]) y=su[i] if y>x : y,x=x,y aa=x-y bb=(26+y)-x if(0<=aa<=26)and(0<=bb<=26): diff.append(min(aa,bb)) return sum(diff) n=int(input()) st=input() data=[] for i in range(n-3): xs=st[i : i+4] data.append(sdist2(xs)) print(min(data)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var st : String := (OclFile["System.in"]).readLine() ; var data : Sequence := Sequence{} ; for i : Integer.subrange(0, n - 3-1) do ( var xs : OclAny := st.subrange(i+1, i + 4) ; execute ((sdist2(xs)) : data)) ; execute ((data)->min())->display(); operation sdist2(l : OclAny) : OclAny pre: true post: true activity: var su : Sequence := Sequence{0}->union(Sequence{2}->union(Sequence{19}->union(Sequence{ 6 }))) ; var alp : String := "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; var diff : Sequence := Sequence{} ; for i : Integer.subrange(0, 4-1) do ( var x : int := alp->indexOf(l[i+1]) - 1 ; var y : OclAny := su[i+1] ; if (y->compareTo(x)) > 0 then ( Sequence{y,x} := Sequence{x,y} ) else skip ; var aa : double := x - y ; var bb : double := (26 + y) - x ; if (0 <= aa & (aa <= 26)) & (0 <= bb & (bb <= 26)) then ( execute ((Set{aa, bb}->min()) : diff) ) else skip) ; return (diff)->sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def area2(x1,y1,x2,y2,x3,y3): vx1=x2-x1 vx2=x3-x1 vy1=y2-y1 vy2=y3-y1 return abs(vx1*vy2-vx2*vy1) def find_v(N,M,A): for x1 in xrange(N+1): for y1 in xrange(M+1): for x2 in xrange(N+1): for y2 in xrange(M+1): if(area2(0,0,x1,y1,x2,y2)==A): return(0,x1,x2,0,y1,y2) return None filename="B-small-attempt0.in" f=open(filename,'r') of=open("B-large.out",'w') C=int(f.readline()) for x in xrange(C): l=f.readline().split(' ') N=int(l[0]) M=int(l[1]) A=int(l[2]) points=find_v(N,M,A) if(points!=None): print>>of,"Case #%d: %d %d %d %d %d %d" %(x+1,points[0],points[3],points[1],points[4],points[2],points[5]) else : print>>of,"Case #%d: IMPOSSIBLE" %(x+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var filename : String := "B-small-attempt0.in" ; var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(filename)) ; var of : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("B-large.out")) ; var C : int := ("" + ((f.readLine())))->toInteger() ; for x : xrange(C) do ( var l : OclAny := f.readLine().split(' ') ; N := ("" + ((l->first())))->toInteger() ; M := ("" + ((l[1+1])))->toInteger() ; A := ("" + ((l[2+1])))->toInteger() ; var points : OclAny := find_v(N, M, A) ; if (points /= null) then ( print /(2->pow(of)) ; (expr (expr (atom "Case #%d: %d %d %d %d %d %d")) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (atom (name points)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))) , (test (logical_test (comparison (expr (atom (name points)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 3))))))))) ])))))) , (test (logical_test (comparison (expr (atom (name points)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))) , (test (logical_test (comparison (expr (atom (name points)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 4))))))))) ])))))) , (test (logical_test (comparison (expr (atom (name points)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))) , (test (logical_test (comparison (expr (atom (name points)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 5))))))))) ]))))))) )))) ) else ( print /(2->pow(of)) ; (expr (expr (atom "Case #%d: IMPOSSIBLE")) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (number (integer 1))))))))) )))) )); operation area2(x1 : OclAny, y1 : OclAny, x2 : OclAny, y2 : OclAny, x3 : OclAny, y3 : OclAny) : OclAny pre: true post: true activity: var vx1 : double := x2 - x1 ; var vx2 : double := x3 - x1 ; var vy1 : double := y2 - y1 ; var vy2 : double := y3 - y1 ; return (vx1 * vy2 - vx2 * vy1)->abs(); operation find_v(N : OclAny, M : OclAny, A : OclAny) : OclAny pre: true post: true activity: for x1 : xrange(N + 1) do ( for y1 : xrange(M + 1) do ( for x2 : xrange(N + 1) do ( for y2 : xrange(M + 1) do ( if (area2(0, 0, x1, y1, x2, y2) = A) then ( return Sequence{0, x1, x2, 0, y1, y2} ) else skip)))) ; return null; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=lambda : map(int,input().split()) n,s=I() a=*I(), b=*I(), print('NYOE S'[a[0]and(a[s-1]or(b[s-1]and any(x==1==y for x,y in zip(a[s :],b[s :])))): : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := I->apply() ; var a : OclAny := (testlist_star_expr (star_expr * (expr (atom (name I)) (trailer (arguments ( ))))) ,) ; var b : OclAny := (testlist_star_expr (star_expr * (expr (atom (name I)) (trailer (arguments ( ))))) ,) ; execute ('NYOE S'(subscript (test (logical_test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))) and (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name s))) - (expr (atom (number (integer 1)))))))))) ]))))) or (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name s))) - (expr (atom (number (integer 1)))))))))) ]))))) and (logical_test (comparison (expr (atom (name any)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (comparison (comparison (expr (atom (name x)))) == (comparison (expr (atom (number (integer 1)))))) == (comparison (expr (atom (name y))))))) (comp_for for (exprlist (expr (atom (name x))) , (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))) :)) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))) :)) ])))))))) ))))))))) ))))))))) )))))))) ))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() s=input() print(min(sum(min(x,26-x)for x in map(lambda x,y : abs(ord(x)-ord(y)),t,'ACTG'))for t in zip(s,s[1 :],s[2 :],s[3 :]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var s : String := (OclFile["System.in"]).readLine() ; execute (((argument (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x))))))) , (argument (test (logical_test (comparison (expr (expr (atom (number (integer 26)))) - (expr (atom (name x))))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)) , (vardef_parameter (name y)))) : (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name ord)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) - (expr (atom (name ord)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))))))))) ))))))))) , (argument (test (logical_test (comparison (expr (atom (name t))))))) , (argument (test (logical_test (comparison (expr (atom 'ACTG'))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name t)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s))))))) , (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) :)) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 3))))))) :)) ])))))))) )))))))))->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() input() l=[a for a in map(ord,input())] print(min(sum(min((a-b)% 26,(b-a)% 26)for a,b in zip((65,67,84,71),l[i :]))for i in range(len(l)-3))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; input() ; var l : Sequence := ((OclFile["System.in"]).readLine())->collect( _x | (ord)->apply(_x) )->select(a | true)->collect(a | (a)) ; execute (((argument (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (name b)))))))) ))) % (expr (atom (number (integer 26))))))))) , (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (name a)))))))) ))) % (expr (atom (number (integer 26)))))))))) ))))))) (comp_for for (exprlist (expr (atom (name a))) , (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 65))))))) , (test (logical_test (comparison (expr (atom (number (integer 67))))))) , (test (logical_test (comparison (expr (atom (number (integer 84))))))) , (test (logical_test (comparison (expr (atom (number (integer 71)))))))) ))))))) , (argument (test (logical_test (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))) :)) ])))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)))))))) )))) - (expr (atom (number (integer 3)))))))))) )))))))))->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) s=list(input().rstrip()) for i in range(n): s[i]-=65 x=[ord(i)-65 for i in list("ACTG")] inf=pow(10,9)+1 ans=inf for i in range(n-3): cnt=0 for j in range(4): cnt+=min((s[i+j]-x[j])% 26,(x[j]-s[i+j])% 26) ans=min(ans,cnt) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := (input().rstrip()) ; for i : Integer.subrange(0, n-1) do ( s[i+1] := s[i+1] - 65) ; var x : Sequence := ("ACTG")->characters()->select(i | true)->collect(i | ((i)->char2byte() - 65)) ; var Math_PINFINITY : double := (10)->pow(9) + 1 ; var ans : double := Math_PINFINITY ; for i : Integer.subrange(0, n - 3-1) do ( var cnt : int := 0 ; for j : Integer.subrange(0, 4-1) do ( cnt := cnt + Set{(s[i + j+1] - x[j+1]) mod 26, (x[j+1] - s[i + j+1]) mod 26}->min()) ; ans := Set{ans, cnt}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tests=int(input()) for _ in range(tests): l,r=[int(x)for x in input().split()] print(l,2*l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var tests : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, tests-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (l)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def record_sum(record,l,r,n,adder): for i in range(l,r+1): record[i]+=adder n=5 m=5 arr=[0]*n query=[[1,1,2],[1,4,5],[2,1,2],[2,1,3],[2,3,4]] record=[0]*m for i in range(m-1,-1,-1): if(query[i][0]==2): record_sum(record,query[i][1]-1,query[i][2]-1,m,record[i]+1) else : record_sum(record,i,i,m,1) for i in range(m): if(query[i][0]==1): record_sum(arr,query[i][1]-1,query[i][2]-1,n,record[i]) for i in range(n): print(arr[i],end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; var m : int := 5 ; var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var query : Sequence := Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{ 2 }))}->union(Sequence{Sequence{1}->union(Sequence{4}->union(Sequence{ 5 }))}->union(Sequence{Sequence{2}->union(Sequence{1}->union(Sequence{ 2 }))}->union(Sequence{Sequence{2}->union(Sequence{1}->union(Sequence{ 3 }))}->union(Sequence{ Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })) })))) ; record := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; for i : Integer.subrange(-1 + 1, m - 1)->reverse() do ( if (query[i+1]->first() = 2) then ( record_sum(record, query[i+1][1+1] - 1, query[i+1][2+1] - 1, m, record[i+1] + 1) ) else ( record_sum(record, i, i, m, 1) )) ; for i : Integer.subrange(0, m-1) do ( if (query[i+1]->first() = 1) then ( record_sum(arr, query[i+1][1+1] - 1, query[i+1][2+1] - 1, n, record[i+1]) ) else skip) ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); operation record_sum(record : OclAny, l : OclAny, r : OclAny, n : OclAny, adder : OclAny) pre: true post: true activity: for i : Integer.subrange(l, r + 1-1) do ( record[i+1] := record[i+1] + adder); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def num(): return int(input()) def nums(): return list(map(int,input().split())) def get_near_index(sorted_l,val,last): left=0 right=len(sorted_l)-1 while left<=right : mid=(right+left)//2 if sorted_l[mid]==val : return mid if last else mid elif sorted_l[mid]>val : right=mid-1 else : left=mid+1 return right if last else left N,Q=nums() A=nums() A.sort() L,R=[],[] for i in range(Q): li,ri=nums() L.append(li) R.append(ri) for l,r in zip(L,R): l_idx=get_near_index(A,l,0) r_idx=get_near_index(A,r,1) print(r_idx-l_idx+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var N : OclAny := null; var Q : OclAny := null; Sequence{N,Q} := nums() ; var A : OclAny := nums() ; A := A->sort() ; var L : OclAny := null; var R : OclAny := null; Sequence{L,R} := Sequence{Sequence{},Sequence{}} ; for i : Integer.subrange(0, Q-1) do ( var li : OclAny := null; var ri : OclAny := null; Sequence{li,ri} := nums() ; execute ((li) : L) ; execute ((ri) : R)) ; for _tuple : Integer.subrange(1, L->size())->collect( _indx | Sequence{L->at(_indx), R->at(_indx)} ) do (var _indx : int := 1; var l : OclAny := _tuple->at(_indx); _indx := _indx + 1; var r : OclAny := _tuple->at(_indx); var l_idx : OclAny := get_near_index(A, l, 0) ; var r_idx : OclAny := get_near_index(A, r, 1) ; execute (r_idx - l_idx + 1)->display()); operation num() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation nums() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation get_near_index(sorted_l : OclAny, val : OclAny, last : OclAny) : OclAny pre: true post: true activity: var left : int := 0 ; var right : double := (sorted_l)->size() - 1 ; while (left->compareTo(right)) <= 0 do ( var mid : int := (right + left) div 2 ; if sorted_l[mid+1] = val then ( return if last then mid else mid endif ) else (if (sorted_l[mid+1]->compareTo(val)) > 0 then ( right := mid - 1 ) else ( left := mid + 1 ) ) ) ; return if last then right else left endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printbinomial(max): for m in range(max+1): print('% 2d' % m,end='') binom=1 for x in range(m+1): if m!=0 and x!=0 : binom=binom*(m-x+1)/x print('% 4d' % binom,end='') print("\n",end='') max=10 printbinomial(max) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; max := 10 ; printbinomial(max); operation printbinomial(max : OclAny) pre: true post: true activity: for m : Integer.subrange(0, max + 1-1) do ( execute (StringLib.format('% 2d',m))->display() ; var binom : int := 1 ; for x : Integer.subrange(0, m + 1-1) do ( if m /= 0 & x /= 0 then ( binom := binom * (m - x + 1) / x ) else skip ; execute (StringLib.format('% 4d',binom))->display()) ; execute ("\n")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMinCost(arr,n,choc_cost): choc_buy=arr[0] curr_choc=0 for i in range(0,n-1): choc=arr[i]-arr[i+1] curr_choc+=choc if(curr_choc<0): choc_buy+=abs(curr_choc) curr_choc=0 return choc_buy*choc_cost arr=[10,6,11,4,7,1] n=len(arr) p=5 print(findMinCost(arr,n,p)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{10}->union(Sequence{6}->union(Sequence{11}->union(Sequence{4}->union(Sequence{7}->union(Sequence{ 1 }))))) ; n := (arr)->size() ; var p : int := 5 ; execute (findMinCost(arr, n, p))->display(); operation findMinCost(arr : OclAny, n : OclAny, choc_cost : OclAny) : OclAny pre: true post: true activity: var choc_buy : OclAny := arr->first() ; var curr_choc : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( var choc : double := arr[i+1] - arr[i + 1+1] ; curr_choc := curr_choc + choc ; if (curr_choc < 0) then ( choc_buy := choc_buy + (curr_choc)->abs() ; curr_choc := 0 ) else skip) ; return choc_buy * choc_cost; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=list(map(int,input().split())) A.sort() if sum(A)% 2==0 : print(sum(A)//2) else : for i in range(N): if A[i]% 2==1 : break print((sum(A)-A[i])//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; A := A->sort() ; if (A)->sum() mod 2 = 0 then ( execute ((A)->sum() div 2)->display() ) else ( for i : Integer.subrange(0, N-1) do ( if A[i+1] mod 2 = 1 then ( break ) else skip) ; execute (((A)->sum() - A[i+1]) div 2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() x=[int(i)for i in input().split()] if sum(x)% 2==1 : y=[i for i in x if i % 2==1] print(int((sum(x)-min(y))/2)) else : print(int(sum(x)/2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var x : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if (x)->sum() mod 2 = 1 then ( var y : Sequence := x->select(i | i mod 2 = 1)->collect(i | (i)) ; execute (("" + ((((x)->sum() - (y)->min()) / 2)))->toInteger())->display() ) else ( execute (("" + (((x)->sum() / 2)))->toInteger())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) li=list(map(int,input().split())) li.sort(reverse=True) ki=0 kifl=False ans=0 for a in li : if a % 2==0 : ans+=a else : if(kifl==True): ans+=ki+a kifl=False else : ki=a kifl=True print(ans//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; li := li->sort() ; var ki : int := 0 ; var kifl : boolean := false ; var ans : int := 0 ; for a : li do ( if a mod 2 = 0 then ( ans := ans + a ) else ( if (kifl = true) then ( ans := ans + ki + a ; kifl := false ) else ( ki := a ; kifl := true ) )) ; execute (ans div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) a=11 for i in range(1,10**5+1): if N % i==0 : a=min(a,max(len(str(N//i)),len(str(i)))) print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := 11 ; for i : Integer.subrange(1, (10)->pow(5) + 1-1) do ( if N mod i = 0 then ( a := Set{a, Set{(("" + ((N div i))))->size(), (("" + ((i))))->size()}->max()}->min() ) else skip) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input(); a=list(map(int,input().split())); b=sum(a); print((b-(min([x for x in a if x % 2])if b % 2 else 0))//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input(); var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); var b : OclAny := (a)->sum(); execute ((b - (if b mod 2 then (a->select(x | x mod 2)->collect(x | (x)))->min() else 0 endif)) div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=[int(x)for x in input().split()] A.sort() ans=sum(A) for a in A : if ans % 2==0 or a % 2==0 : continue ans-=a ans=ans//2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; A := A->sort() ; var ans : OclAny := (A)->sum() ; for a : A do ( if ans mod 2 = 0 or a mod 2 = 0 then ( continue ) else skip ; ans := ans - a) ; ans := ans div 2 ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count_island(ban): def remove(x,y): if 0<=y<12 and 0<=x<12 and ban[y][x]==1 : ban[y][x]=0 for dx,dy in[(-1,0),(1,0),(0,-1),(0,1)]: remove(x+dx,y+dy) count=0 for y in range(12): for x in range(12): if ban[y][x]==1 : count+=1 remove(x,y) print(count) ban=[] while True : try : s=input() except EOFError : break if s : ban.append(list(map(int,s))) else : count_island(ban) ban=[] if ban : count_island(ban) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; ban := Sequence{} ; while true do ( try ( var s : String := (OclFile["System.in"]).readLine()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))) ; if s then ( execute ((((s)->collect( _x | (OclType["int"])->apply(_x) ))) : ban) ) else ( count_island(ban) ; ban := Sequence{} )) ; if ban then ( count_island(ban) ) else skip; operation count_island(ban : OclAny) pre: true post: true activity: skip ; var count : int := 0 ; for y : Integer.subrange(0, 12-1) do ( for x : Integer.subrange(0, 12-1) do ( if ban[y+1][x+1] = 1 then ( count := count + 1 ; remove(x, y) ) else skip)) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countDigits(n): count=0 while(n>0): count+=1 n=n//10 return count def checkPrime(n): if(n<=1): return-1 if(n<=3): return 0 if(n % 2==0 or n % 3==0): return-1 i=5 while i*i<=n : if(n % i==0 or n %(i+2)==0): return-1 i+=6 return 0 def printPrimePoints(n): count=countDigits(n) if(count==1 or count==2): print("-1") return found=False for i in range(1,(count-1)): left=n//(pow(10,count-i)) right=n %(pow(10,count-i-1)) if(checkPrime(left)==0 and checkPrime(right)==0): print(i,end=" ") found=True if(found==False): print("-1") if __name__=="__main__" : n=2317 printPrimePoints(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( n := 2317 ; printPrimePoints(n) ) else skip; operation countDigits(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while (n > 0) do ( count := count + 1 ; n := n div 10) ; return count; operation checkPrime(n : OclAny) : OclAny pre: true post: true activity: if (n <= 1) then ( return -1 ) else skip ; if (n <= 3) then ( return 0 ) else skip ; if (n mod 2 = 0 or n mod 3 = 0) then ( return -1 ) else skip ; var i : int := 5 ; while (i * i->compareTo(n)) <= 0 do ( if (n mod i = 0 or n mod (i + 2) = 0) then ( return -1 ) else skip ; i := i + 6) ; return 0; operation printPrimePoints(n : OclAny) pre: true post: true activity: count := countDigits(n) ; if (count = 1 or count = 2) then ( execute ("-1")->display() ; return ) else skip ; var found : boolean := false ; for i : Integer.subrange(1, (count - 1)-1) do ( var left : int := n div ((10)->pow(count - i)) ; var right : int := n mod ((10)->pow(count - i - 1)) ; if (checkPrime(left) = 0 & checkPrime(right) = 0) then ( execute (i)->display() ; found := true ) else skip) ; if (found = false) then ( execute ("-1")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def print_first_N_primes(N): i,j,flag=0,0,0 ; print("Prime numbers between 1 and ",N," are:"); for i in range(1,N+1,1): if(i==1 or i==0): continue ; flag=1 ; for j in range(2,((i//2)+1),1): if(i % j==0): flag=0 ; break ; if(flag==1): print(i,end=" "); N=100 ; print_first_N_primes(N); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 100; ; print_first_N_primes(N);; operation print_first_N_primes(N : OclAny) pre: true post: true activity: var i : OclAny := null; var j : OclAny := null; var flag : OclAny := null; Sequence{i,j,flag} := Sequence{0,0,0}; ; execute ("Prime numbers between 1 and ")->display(); ; for i : Integer.subrange(1, N + 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if (i = 1 or i = 0) then ( continue; ) else skip ; var flag : int := 1; ; for j : Integer.subrange(2, ((i div 2) + 1)-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (i mod j = 0) then ( flag := 0; ; break; ) else skip) ; if (flag = 1) then ( execute (i)->display(); ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def divSum(n): result=0 for i in range(2,(int)(math.sqrt(n))+1): if(n % i==0): if(i==(n/i)): result=result+i else : result=result+(i+n//i) return(result+n+1) n=30 print(divSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 30 ; execute (divSum(n))->display(); operation divSum(n : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; for i : Integer.subrange(2, (OclType["int"])((n)->sqrt()) + 1-1) do ( if (n mod i = 0) then ( if (i = (n / i)) then ( result := result + i ) else ( result := result + (i + n div i) ) ) else skip) ; return (result + n + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,q=map(int,input().split()) a=list(map(int,input().split())) b=["0"]*n l_q=0 for i in range(n): a_i=a[-i-1] if l_ql_q : l_q+=1 b[-i-1]="1" elif a_i<=l_q : b[-i-1]="1" print("".join(b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ "0" }, n) ; var l_q : int := 0 ; for i : Integer.subrange(0, n-1) do ( var a_i : OclAny := a->reverse()->at(-(-i - 1)) ; if (l_q->compareTo(q)) < 0 & (a_i->compareTo(l_q)) > 0 then ( l_q := l_q + 1 ; b->reverse()->at(-(-i - 1)) := "1" ) else (if (a_i->compareTo(l_q)) <= 0 then ( b->reverse()->at(-(-i - 1)) := "1" ) else skip)) ; execute (StringLib.sumStringsWithSeparator((b), ""))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,q=map(int,input().split()) a=[*map(int,input().split())] s,nq=0,0 b=[0]*n for i in range(n-1,-1,-1): if a[i]<=nq : b[i]=1 elif nqtoInteger()-1) do ( var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := null; var nq : OclAny := null; Sequence{s,nq} := Sequence{0,0} ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (a[i+1]->compareTo(nq)) <= 0 then ( b[i+1] := 1 ) else (if (nq->compareTo(q)) < 0 then ( nq := nq + 1 ; b[i+1] := 1 ) else skip)) ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name b)))))))), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,q=map(int,input().split()) a=[*map(int,input().split())] b=['0']*n cnt=0 for i in range(n): if cntcnt : cnt+=1 b[-i-1]='1' elif a[-i-1]<=cnt : b[-i-1]='1' print(''.join(b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ '0' }, n) ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (cnt->compareTo(q)) < 0 & (a->reverse()->at(-(-i - 1))->compareTo(cnt)) > 0 then ( cnt := cnt + 1 ; b->reverse()->at(-(-i - 1)) := '1' ) else (if (a->reverse()->at(-(-i - 1))->compareTo(cnt)) <= 0 then ( b->reverse()->at(-(-i - 1)) := '1' ) else skip)) ; execute (StringLib.sumStringsWithSeparator((b), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math def get_ints(): return map(int,sys.stdin.readline().strip().split()) def get_ls(): return list(map(int,sys.stdin.readline().strip().split())) def main(): for _ in range(int(input())): n,q=get_ints() ans=[0]*n ls=get_ls() m=0 for i in range(n-1,-1,-1): if ls[i]<=m : ans[i]=1 elif mtrim().split())->collect( _x | (OclType["int"])->apply(_x) ); operation get_ls() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation main() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := get_ints() ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var ls : OclAny := get_ls() ; var m : int := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (ls[i+1]->compareTo(m)) <= 0 then ( ans[i+1] := 1 ) else (if (m->compareTo(q)) < 0 then ( ans[i+1] := 1 ; m := m + 1 ) else skip)) ; for c : ans do ( execute (c)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* def isPower(a): if a==1 : return True for i in range(2,int(sqrt(a))+1): val=log(a)/log(i) if(round((val-int(val)),8)<0.00000001): return True return False if __name__=="__main__" : n=16 if isPower(n): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var n : int := 16 ; if isPower(n) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isPower(a : OclAny) : OclAny pre: true post: true activity: if a = 1 then ( return true ) else skip ; for i : Integer.subrange(2, ("" + ((sqrt(a))))->toInteger() + 1-1) do ( var val : double := log(a) / log(i) ; if (MathLib.roundN((val - ("" + ((val)))->toInteger()), 8) < 0.00000001) then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def F(A,B): def keta(n): ans=1 while True : n=n//10 if n==0 : break ans+=1 return ans return max(keta(A),keta(B)) def solve(): N=int(input()) ans=float("inf") for i in range(1,math.ceil(math.sqrt(N))+1): A=i if N % A!=0 : continue B=int(N/A) ans=min(ans,F(A,B)) print(ans) if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation F(A : OclAny, B : OclAny) : OclAny pre: true post: true activity: skip ; return Set{keta(A), keta(B)}->max(); operation solve() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; ans := ("" + (("inf")))->toReal() ; for i : Integer.subrange(1, ((N)->sqrt())->ceil() + 1-1) do ( A := i ; if N mod A /= 0 then ( continue ) else skip ; B := ("" + ((N / A)))->toInteger() ; ans := Set{ans, F(A, B)}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : while True : try : A=[] for i in range(8): tmp=list(map(int,input())) if tmp.count(1)>0 : A.append(tmp) if len(A)==1 : print("C") elif len(A)==4 : print("B") else : if len(A)==2 : if A[0].index(1)A[1].index(1): print("G") else : print("A") elif len(A)==3 : if A[0].index(1)collect( _x | (OclType["int"])->apply(_x) )) ; if tmp->count(1) > 0 then ( execute ((tmp) : A) ) else skip) ; if (A)->size() = 1 then ( execute ("C")->display() ) else (if (A)->size() = 4 then ( execute ("B")->display() ) else ( if (A)->size() = 2 then ( if (A->first()->indexOf(1) - 1->compareTo(A[1+1]->indexOf(1) - 1)) < 0 then ( execute ("E")->display() ) else (if (A->first()->indexOf(1) - 1->compareTo(A[1+1]->indexOf(1) - 1)) > 0 then ( execute ("G")->display() ) else ( execute ("A")->display() ) ) ) else (if (A)->size() = 3 then ( if (A->first()->indexOf(1) - 1->compareTo(A[2+1]->indexOf(1) - 1)) < 0 then ( execute ("F")->display() ) else ( execute ("D")->display() ) ) else skip) ) ) ; input()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- u=int(input()) while u>0 : u-=1 q,w=map(int,input().split()) print(q,q*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var u : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while u > 0 do ( u := u - 1 ; var q : OclAny := null; var w : OclAny := null; Sequence{q,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (q)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys counter=0 block=[] for line in sys.stdin : if line=="\n" : counter=-1 block=[] else : counter+=1 for i in line : if i=="1" : block.append([counter,line.index(i)]) if counter==7 : if block[0][0]==block[1][0]: if block[1][0]==block[2][0]: print("C") elif block[0][1]==block[2][1]: print("A") elif block[0][1]union(Sequence{ line->indexOf(i) - 1 })) : block) ) else skip) ) ; if counter = 7 then ( if block->first()->first() = block[1+1]->first() then ( if block[1+1]->first() = block[2+1]->first() then ( execute ("C")->display() ) else (if block->first()[1+1] = block[2+1][1+1] then ( execute ("A")->display() ) else (if (block->first()[1+1]->compareTo(block[2+1][1+1])) < 0 then ( execute ("E")->display() ) else ( execute ("G")->display() ) ) ) ) else ( if block->first()[1+1] = block[3+1][1+1] then ( execute ("B")->display() ) else (if (block->first()[1+1]->compareTo(block[3+1][1+1])) < 0 then ( execute ("F")->display() ) else ( execute ("D")->display() ) ) ) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline write=sys.stdout.write B=[771,16843009,15,66306,1539,131841,774] C="ABCDEFG" def solve(): N=8 su=0 for i in range(N): s=readline().strip() for j in range(N): if s[j]=='1' : su |=1<<(i*N+j) for i in range(N*N): for k in range(7): b=B[k]<union(Sequence{16843009}->union(Sequence{15}->union(Sequence{66306}->union(Sequence{1539}->union(Sequence{131841}->union(Sequence{ 774 })))))) ; var C : String := "ABCDEFG" ; skip ; try ( while solve() do ( readline())) catch (_e : OclException) do () ; operation solve() : OclAny pre: true post: true activity: var N : int := 8 ; var su : int := 0 ; for i : Integer.subrange(0, N-1) do ( var s : OclAny := readline()->trim() ; for j : Integer.subrange(0, N-1) do ( if s[j+1] = '1' then ( su := su or 1 * (2->pow((i * N + j))) ) else skip)) ; for i : Integer.subrange(0, N * N-1) do ( for k : Integer.subrange(0, 7-1) do ( var b : int := B[k+1] * (2->pow(i)) ; if (MathLib.bitwiseAnd(su, b)) = b then ( write(StringLib.format("%s\n",C[k+1])) ) else skip)) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : figmap=[[0]*12 for _ in range(12)] for i in range(8): instr=input() for j in range(8): figmap[i][j+1]=int(instr[j]) outi=outj=0 flag=True for i in range(12): for j in range(12): if figmap[i][j]==1 and flag : outi=i ; outj=j flag=False if figmap[outi+1][outj]*figmap[outi][outj+1]*figmap[outi+1][outj+1]==1 : print("A") if figmap[outi+1][outj]*figmap[outi+2][outj]*figmap[outi+3][outj]==1 : print("B") if figmap[outi][outj+1]*figmap[outi][outj+2]*figmap[outi][outj+3]==1 : print("C") if figmap[outi+1][outj]*figmap[outi+1][outj-1]*figmap[outi+2][outj-1]==1 : print("D") if figmap[outi][outj+1]*figmap[outi+1][outj+1]*figmap[outi+1][outj+2]==1 : print("E") if figmap[outi+1][outj]*figmap[outi+1][outj+1]*figmap[outi+2][outj+1]==1 : print("F") if figmap[outi+1][outj]*figmap[outi][outj+1]*figmap[outi+1][outj-1]==1 : print("G") input() except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var figmap : Sequence := Integer.subrange(0, 12-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 12))) ; for i : Integer.subrange(0, 8-1) do ( var instr : String := (OclFile["System.in"]).readLine() ; for j : Integer.subrange(0, 8-1) do ( figmap[i+1][j + 1+1] := ("" + ((instr[j+1])))->toInteger())) ; var outi : OclAny := 0; var outj : int := 0 ; var flag : boolean := true ; for i : Integer.subrange(0, 12-1) do ( for j : Integer.subrange(0, 12-1) do ( if figmap[i+1][j+1] = 1 & flag then ( outi := i; outj := j ; flag := false ) else skip)) ; if figmap[outi + 1+1][outj+1] * figmap[outi+1][outj + 1+1] * figmap[outi + 1+1][outj + 1+1] = 1 then ( execute ("A")->display() ) else skip ; if figmap[outi + 1+1][outj+1] * figmap[outi + 2+1][outj+1] * figmap[outi + 3+1][outj+1] = 1 then ( execute ("B")->display() ) else skip ; if figmap[outi+1][outj + 1+1] * figmap[outi+1][outj + 2+1] * figmap[outi+1][outj + 3+1] = 1 then ( execute ("C")->display() ) else skip ; if figmap[outi + 1+1][outj+1] * figmap[outi + 1+1][outj - 1+1] * figmap[outi + 2+1][outj - 1+1] = 1 then ( execute ("D")->display() ) else skip ; if figmap[outi+1][outj + 1+1] * figmap[outi + 1+1][outj + 1+1] * figmap[outi + 1+1][outj + 2+1] = 1 then ( execute ("E")->display() ) else skip ; if figmap[outi + 1+1][outj+1] * figmap[outi + 1+1][outj + 1+1] * figmap[outi + 2+1][outj + 1+1] = 1 then ( execute ("F")->display() ) else skip ; if figmap[outi + 1+1][outj+1] * figmap[outi+1][outj + 1+1] * figmap[outi + 1+1][outj - 1+1] = 1 then ( execute ("G")->display() ) else skip ; input()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (simple_stmt (small_stmt break))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): line=input() while True : surface=list(map(int,line)) for _ in range(7): surface.extend(map(int,input())) for i,v in enumerate(surface): if not v==1 : continue if i+9<64 and surface[i+1]==1 and surface[i+8]==1 and surface[i+9]==1 : print('A') break if i+24<64 and surface[i+24]==1 : print('B') break if surface[i+3]==1 : print('C') break if i+15<64 and surface[i+15]==1 : print('D') break if i+10<64 and surface[i+10]==1 : print('E') break if i+17<64 and surface[i+17]==1 : print('F') break if surface[i+1]==1 and surface[i+7]==1 and surface[i+8]==1 : print('G') break try : input() line=input() except EOFError : break if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( solve() ) else skip; operation solve() pre: true post: true activity: var line : String := (OclFile["System.in"]).readLine() ; while true do ( var surface : Sequence := ((line)->collect( _x | (OclType["int"])->apply(_x) )) ; for _anon : Integer.subrange(0, 7-1) do ( surface := surface->union(((OclFile["System.in"]).readLine())->collect( _x | (OclType["int"])->apply(_x) ))) ; for _tuple : Integer.subrange(1, (surface)->size())->collect( _indx | Sequence{_indx-1, (surface)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if not(v = 1) then ( continue ) else skip ; if i + 9 < 64 & surface[i + 1+1] = 1 & surface[i + 8+1] = 1 & surface[i + 9+1] = 1 then ( execute ('A')->display() ; break ) else skip ; if i + 24 < 64 & surface[i + 24+1] = 1 then ( execute ('B')->display() ; break ) else skip ; if surface[i + 3+1] = 1 then ( execute ('C')->display() ; break ) else skip ; if i + 15 < 64 & surface[i + 15+1] = 1 then ( execute ('D')->display() ; break ) else skip ; if i + 10 < 64 & surface[i + 10+1] = 1 then ( execute ('E')->display() ; break ) else skip ; if i + 17 < 64 & surface[i + 17+1] = 1 then ( execute ('F')->display() ; break ) else skip ; if surface[i + 1+1] = 1 & surface[i + 7+1] = 1 & surface[i + 8+1] = 1 then ( execute ('G')->display() ; break ) else skip) ; try ( input() ; line := (OclFile["System.in"]).readLine()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkYear(year): if(year % 4)==0 : if(year % 100)==0 : if(year % 400)==0 : return True else : return False else : return True else : return False year=2000 if(checkYear(year)): print("Leap Year") else : print("Not a Leap Year") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; year := 2000 ; if (checkYear(year)) then ( execute ("Leap Year")->display() ) else ( execute ("Not a Leap Year")->display() ); operation checkYear(year : OclAny) : OclAny pre: true post: true activity: if (year mod 4) = 0 then ( if (year mod 100) = 0 then ( if (year mod 400) = 0 then ( return true ) else ( return false ) ) else ( return true ) ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkYear(year): return(((year % 4==0)and(year % 100!=0))or(year % 400==0)); year=2000 if(checkYear(year)): print("Leap Year") else : print("Not a Leap Year") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; year := 2000 ; if (checkYear(year)) then ( execute ("Leap Year")->display() ) else ( execute ("Not a Leap Year")->display() ); operation checkYear(year : OclAny) pre: true post: true activity: return (((year mod 4 = 0) & (year mod 100 /= 0)) or (year mod 400 = 0));; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findevenPair(A,N): count=0 for i in range(0,N): if(A[i]% 2!=0): count+=1 oddCount=count*(count-1)/2 return(int)((N*(N-1)/2)-oddCount) a=[5,1,3,2] n=len(a) print(findevenPair(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : Sequence := Sequence{5}->union(Sequence{1}->union(Sequence{3}->union(Sequence{ 2 }))) ; var n : int := (a)->size() ; execute (findevenPair(a, n))->display(); operation findevenPair(A : OclAny, N : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, N-1) do ( if (A[i+1] mod 2 /= 0) then ( count := count + 1 ) else skip) ; var oddCount : double := count * (count - 1) / 2 ; return (OclType["int"])((N * (N - 1) / 2) - oddCount); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isMinHeap(level,n): for i in range(int(n/2)-1,-1,-1): if level[i]>level[2*i+1]: return False if 2*i+2level[2*i+2]: return False return True if __name__=='__main__' : level=[10,15,14,25,30] n=len(level) if isMinHeap(level,n): print("True") else : print("False") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( level := Sequence{10}->union(Sequence{15}->union(Sequence{14}->union(Sequence{25}->union(Sequence{ 30 })))) ; n := (level)->size() ; if isMinHeap(level, n) then ( execute ("True")->display() ) else ( execute ("False")->display() ) ) else skip; operation isMinHeap(level : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(-1 + 1, ("" + ((n / 2)))->toInteger() - 1)->reverse() do ( if (level[i+1]->compareTo(level[2 * i + 1+1])) > 0 then ( return false ) else skip ; if (2 * i + 2->compareTo(n)) < 0 then ( if (level[i+1]->compareTo(level[2 * i + 2+1])) > 0 then ( return false ) else skip ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numDecodings(s : str)->int : return numDecodingsHelper(s,len(s)); def numDecodingsHelper(s : str,n : int)->int : if n==0 or n==1 : return 1 count=0 if s[n-1]>"0" : count=numDecodingsHelper(s,n-1) if(s[n-2]=='1' or(s[n-2]=='2' and s[n-1]<'7')): count+=numDecodingsHelper(s,n-2) return count digits="1234" print("Count is ",numDecodings(digits)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var digits : String := "1234" ; execute ("Count is ")->display(); operation numDecodings(s : String) : int pre: true post: true activity: return numDecodingsHelper(s, (s)->size());; operation numDecodingsHelper(s : String, n : int) : int pre: true post: true activity: if n = 0 or n = 1 then ( return 1 ) else skip ; var count : int := 0 ; if s[n - 1+1] > "0" then ( count := numDecodingsHelper(s, n - 1) ) else skip ; if (s[n - 2+1] = '1' or (s[n - 2+1] = '2' & s[n - 1+1] < '7')) then ( count := count + numDecodingsHelper(s, n - 2) ) else skip ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) def divisor(n): f=[] d=[1] c=0 r=int(n**0.5) for i in range(2,r+2): while n % i==0 : c+=1 n=n//i if c!=0 : f.append([i,c]) c=0 if n!=1 : f.append([n,1]) for i in range(len(f)): t=[] for j in range(1,f[i][1]+1): t.append(f[i][0]**j) for j in range(len(d)): for k in range(len(t)): d.append(d[j]*t[k]) return sorted(d) x=divisor(n) a=x[len(x)//2] c=0 while a>=10 : a=a/10 c+=1 print(c+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; var x : OclAny := divisor(n) ; var a : OclAny := x[(x)->size() div 2+1] ; c := 0 ; while a >= 10 do ( a := a / 10 ; c := c + 1) ; execute (c + 1)->display(); operation divisor(n : OclAny) : OclAny pre: true post: true activity: var f : Sequence := Sequence{} ; var d : Sequence := Sequence{ 1 } ; var c : int := 0 ; var r : int := ("" + (((n)->pow(0.5))))->toInteger() ; for i : Integer.subrange(2, r + 2-1) do ( while n mod i = 0 do ( c := c + 1 ; n := n div i) ; if c /= 0 then ( execute ((Sequence{i}->union(Sequence{ c })) : f) ; c := 0 ) else skip) ; if n /= 1 then ( execute ((Sequence{n}->union(Sequence{ 1 })) : f) ) else skip ; for i : Integer.subrange(0, (f)->size()-1) do ( var t : Sequence := Sequence{} ; for j : Integer.subrange(1, f[i+1][1+1] + 1-1) do ( execute (((f[i+1]->first())->pow(j)) : t)) ; for j : Integer.subrange(0, (d)->size()-1) do ( for k : Integer.subrange(0, (t)->size()-1) do ( execute ((d[j+1] * t[k+1]) : d)))) ; return d->sort(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): LIMIT=5000 MODULUS=10**16 count=[0]*(LIMIT**2//2) count[0]=1 s=0 for p in eulerlib.list_primes(LIMIT): for i in reversed(range(s+1)): count[i+p]=(count[i+p]+count[i])% MODULUS s+=p isprime=eulerlib.list_primality(s+1) ans=sum(count[i]for i in range(s+1)if isprime[i])% MODULUS return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LIMIT : int := 5000 ; var MODULUS : double := (10)->pow(16) ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((LIMIT)->pow(2) div 2)) ; count->first() := 1 ; var s : int := 0 ; for p : eulerlib.list_primes(LIMIT) do ( for i : (Integer.subrange(0, s + 1-1))->reverse() do ( count[i + p+1] := (count[i + p+1] + count[i+1]) mod MODULUS) ; s := s + p) ; var isprime : OclAny := eulerlib.list_primality(s + 1) ; var ans : int := ((argument (test (logical_test (comparison (expr (atom (name count)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name s))) + (expr (atom (number (integer 1)))))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (atom (name isprime)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))))->sum() mod MODULUS ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() months=["January","February","March","April","May","June","July","August","September","October","November","December"] n=int(input()) idx=months.index(s) idx+=n ; idx %=12 print(months[idx]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var months : Sequence := Sequence{"January"}->union(Sequence{"February"}->union(Sequence{"March"}->union(Sequence{"April"}->union(Sequence{"May"}->union(Sequence{"June"}->union(Sequence{"July"}->union(Sequence{"August"}->union(Sequence{"September"}->union(Sequence{"October"}->union(Sequence{"November"}->union(Sequence{ "December" }))))))))))) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var idx : int := months->indexOf(s) - 1 ; idx := idx + n; ; idx := idx mod 12 ; execute (months[idx+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=['January','February','March','April','May','June','July','August','September','October','November','December'] l=l+l s=input() n=int(input()) x=l.index(s)+(n % 12) print(l[x]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := Sequence{'January'}->union(Sequence{'February'}->union(Sequence{'March'}->union(Sequence{'April'}->union(Sequence{'May'}->union(Sequence{'June'}->union(Sequence{'July'}->union(Sequence{'August'}->union(Sequence{'September'}->union(Sequence{'October'}->union(Sequence{'November'}->union(Sequence{ 'December' }))))))))))) ; l := l->union(l) ; var s : String := (OclFile["System.in"]).readLine() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := l->indexOf(s) - 1 + (n mod 12) ; execute (l[x+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- month=["January","February","March","April","May","June","July","August","September","October","November","December"] n=input() for i in range(12): if n==month[i]: sum=i k=int(input()) sum=(sum+k)% 12 print(month[sum]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var month : Sequence := Sequence{"January"}->union(Sequence{"February"}->union(Sequence{"March"}->union(Sequence{"April"}->union(Sequence{"May"}->union(Sequence{"June"}->union(Sequence{"July"}->union(Sequence{"August"}->union(Sequence{"September"}->union(Sequence{"October"}->union(Sequence{"November"}->union(Sequence{ "December" }))))))))))) ; var n : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, 12-1) do ( if n = month[i+1] then ( var sum : OclAny := i ) else skip) ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; sum := (sum + k) mod 12 ; execute (month[sum+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import calendar a=input() b=[calendar.month_name[i]for i in range(13)][1 :] print(b[(int(input())+b.index(a))% 12]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : String := (OclFile["System.in"]).readLine() ; var b : OclAny := Integer.subrange(0, 13-1)->select(i | true)->collect(i | (calendar.month_name[i+1]))->tail() ; execute (b[(("" + (((OclFile["System.in"]).readLine())))->toInteger() + b->indexOf(a) - 1) mod 12+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def codecraft(): monthes=['January','February','March','April','May','June','July','August','September','October','November','December'] now=input() index=0 for i in range(12): if monthes[i]==now : index=i break k=int(input()) print(monthes[(i+k)% 12]) codecraft() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; codecraft(); operation codecraft() pre: true post: true activity: var monthes : Sequence := Sequence{'January'}->union(Sequence{'February'}->union(Sequence{'March'}->union(Sequence{'April'}->union(Sequence{'May'}->union(Sequence{'June'}->union(Sequence{'July'}->union(Sequence{'August'}->union(Sequence{'September'}->union(Sequence{'October'}->union(Sequence{'November'}->union(Sequence{ 'December' }))))))))))) ; var now : String := (OclFile["System.in"]).readLine() ; var index : int := 0 ; for i : Integer.subrange(0, 12-1) do ( if monthes[i+1] = now then ( index := i ; break ) else skip) ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (monthes[(i + k) mod 12+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin s=stdin.readline().rstrip() ans=len(s) for c in range(ord('a'),ord('z')+1): cnt,cntMax=0,0 for i in range(0,len(s)): if s[i]==chr(c): cntMax=max(cnt,cntMax) cnt=0 continue cnt+=1 cntMax=max(cnt,cntMax) ans=min(ans,cntMax) print(ans,'\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : OclAny := stdin.readLine().rstrip() ; var ans : int := (s)->size() ; for c : Integer.subrange(('a')->char2byte(), ('z')->char2byte() + 1-1) do ( var cnt : OclAny := null; var cntMax : OclAny := null; Sequence{cnt,cntMax} := Sequence{0,0} ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = (c)->byte2char() then ( var cntMax : OclAny := Set{cnt, cntMax}->max() ; var cnt : int := 0 ; continue ) else skip ; cnt := cnt + 1) ; cntMax := Set{cnt, cntMax}->max() ; ans := Set{ans, cntMax}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input().strip() n=len(s) D={chr(i):[]for i in range(97,123)} for i in range(97,123): for j in range(n): if s[j]==chr(i): D[chr(i)].append(j) cntmin=1000 for i in range(97,123): if len(D[chr(i)])==1 : d=D[chr(i)][0] cntmin=min(cntmin,max(d,n-1-d)) elif len(D[chr(i)])>1 : A=[] for j in range(len(D[chr(i)])): if j==0 : A.append(D[chr(i)][0]) if jtrim() ; var n : int := (s)->size() ; var D : Map := Integer.subrange(97, 123-1)->select(i | true)->collect(i | Map{(i)->byte2char() |-> Sequence{}})->unionAll() ; for i : Integer.subrange(97, 123-1) do ( for j : Integer.subrange(0, n-1) do ( if s[j+1] = (i)->byte2char() then ( (expr (atom (name D)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name chr)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) ) else skip)) ; var cntmin : int := 1000 ; for i : Integer.subrange(97, 123-1) do ( if (D[(i)->byte2char()+1])->size() = 1 then ( var d : OclAny := D[(i)->byte2char()+1]->first() ; cntmin := Set{cntmin, Set{d, n - 1 - d}->max()}->min() ) else (if (D[(i)->byte2char()+1])->size() > 1 then ( var A : Sequence := Sequence{} ; for j : Integer.subrange(0, (D[(i)->byte2char()+1])->size()-1) do ( if j = 0 then ( execute ((D[(i)->byte2char()+1]->first()) : A) ) else skip ; if (j->compareTo((D[(i)->byte2char()+1])->size() - 1)) < 0 then ( execute ((D[(i)->byte2char()+1][j + 1+1] - D[(i)->byte2char()+1][j+1] - 1) : A) ) else skip) ; execute ((n - 1 - D[(i)->byte2char()+1]->last()) : A) ; cntmin := Set{cntmin, (A)->max()}->min() ) else skip)) ; execute (cntmin)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() print(min(max(map(len,s.split(t)))for t in s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; execute (((argument (test (logical_test (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len))))))) , (argument (test (logical_test (comparison (expr (atom (name s)) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) ))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name t)))) in (logical_test (comparison (expr (atom (name s))))))))->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=pow(10,5) def countProcedure(lst,char,cnt=0): flags=[x==char for x in lst] if all(flags): return cnt else : _lst=[char if lst[i]==char or lst[i+1]==char else lst[i]for i in range(len(lst)-1)] return countProcedure(_lst,char,cnt+1) def solve(s): s=list(s) res=INF for char in(chr(ord("a")+i)for i in range(26)): res=min(res,countProcedure(s,char)) return res def main(): s=input() print(solve(s)) return if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INF : double := (10)->pow(5) ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation countProcedure(lst : OclAny, char : OclAny, cnt : int) : OclAny pre: true post: true activity: if cnt->oclIsUndefined() then cnt := 0 else skip; var flags : Sequence := lst->select(x | true)->collect(x | (x = char)) ; if (flags)->forAll( _x | _x = true ) then ( return cnt ) else ( var _lst : Sequence := Integer.subrange(0, (lst)->size() - 1-1)->select(i | true)->collect(i | (if lst[i+1] = char or lst[i + 1+1] = char then char else lst[i+1] endif)) ; return countProcedure(_lst, char, cnt + 1) ); operation solve(s : OclAny) : OclAny pre: true post: true activity: s := (s) ; var res : OclAny := INF ; for char : Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name chr)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name ord)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "a"))))))) )))) + (expr (atom (name i))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 26))))))))) ))))))))} do ( res := Set{res, countProcedure(s, char)}->min()) ; return res; operation main() pre: true post: true activity: s := (OclFile["System.in"]).readLine() ; execute (solve(s))->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() n=len(s) alset=set() mojiretsu=s chuumoku="" cnt=0 ans=float("INF") for i in range(n): if s[i]not in alset : chuumoku=s[i] alset.add(chuumoku) while len(set(mojiretsu))!=1 : cpmojiretsu=mojiretsu mojiretsu="" for j in range(len(cpmojiretsu)-1): if cpmojiretsu[j]==chuumoku or cpmojiretsu[j+1]==chuumoku : mojiretsu+=chuumoku else : mojiretsu+=s[j] cnt+=1 if ans>cnt : ans=cnt cnt=0 mojiretsu=s print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var n : int := (s)->size() ; var alset : Set := Set{}->union(()) ; var mojiretsu : String := s ; var chuumoku : String := "" ; var cnt : int := 0 ; var ans : double := ("" + (("INF")))->toReal() ; for i : Integer.subrange(0, n-1) do ( if (alset)->excludes(s[i+1]) then ( chuumoku := s[i+1] ; execute ((chuumoku) : alset) ; while (Set{}->union((mojiretsu)))->size() /= 1 do ( var cpmojiretsu : String := mojiretsu ; mojiretsu := "" ; for j : Integer.subrange(0, (cpmojiretsu)->size() - 1-1) do ( if cpmojiretsu[j+1] = chuumoku or cpmojiretsu[j + 1+1] = chuumoku then ( mojiretsu := mojiretsu + chuumoku ) else ( mojiretsu := mojiretsu + s[j+1] )) ; cnt := cnt + 1) ; if (ans->compareTo(cnt)) > 0 then ( ans := cnt ) else skip ; cnt := 0 ; mojiretsu := s ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countOddNumber(row_num): count=0 while row_num!=0 : count+=row_num & 1 row_num>>=1 return(1<pow(1))) ; return (1 * (2->pow(count))); operation gouldSequence(n : OclAny) pre: true post: true activity: for row_num : Integer.subrange(0, n-1) do ( execute (countOddNumber(row_num))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.read readline=sys.stdin.readline readlines=sys.stdin.readlines sys.setrecursionlimit(10**7) import math n=int(readline()) m=int(math.sqrt(n)) l=[] for a in range(1,m+1): if n % a==0 : b=n//a c=max(len(str(a)),len(str(b))) l.append(c) print(min(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := (OclFile["System.in"]).read ; var readline : OclAny := (OclFile["System.in"]).readline ; var readlines : OclAny := (OclFile["System.in"]).readlines ; sys.setrecursionlimit((10)->pow(7)) ; skip ; var n : int := ("" + ((readline())))->toInteger() ; var m : int := ("" + (((n)->sqrt())))->toInteger() ; var l : Sequence := Sequence{} ; for a : Integer.subrange(1, m + 1-1) do ( if n mod a = 0 then ( var b : int := n div a ; var c : OclAny := Set{(("" + ((a))))->size(), (("" + ((b))))->size()}->max() ; execute ((c) : l) ) else skip) ; execute ((l)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as M def R(A): return(A[0]**2+A[1]**2)**.5 def I(i): return[map(int,raw_input().split())for _ in[0]*i] def C(a,b): return a>b or abs(a-b)<1e-6 def f(e1): tx,ty,sx,sy=e1 x=[] for e2 in WP : wx,wy,r=e2 wt=[tx-wx,ty-wy]; rwt=R(wt) sw=[wx-sx,wy-sy]; rsw=R(sw) st=[tx-sx,ty-sy]; rst=R(st) F=[rwtfirst())->pow(2) + (A[1+1])->pow(2)))->pow(.5); operation I(i : OclAny) : OclAny pre: true post: true activity: return MatrixLib.elementwiseMult(Sequence{ 0 }, i)->select(_anon | true)->collect(_anon | ((raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ))); operation C(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a->compareTo(b)) > 0 or (a - b)->abs() < ("1e-6")->toReal(); operation f(e1 : OclAny) : OclAny pre: true post: true activity: var tx : OclAny := null; var ty : OclAny := null; var sx : OclAny := null; var sy : OclAny := null; Sequence{tx,ty,sx,sy} := e1 ; var x : Sequence := Sequence{} ; for e2 : WP do ( var wx : OclAny := null; var wy : OclAny := null; var r : OclAny := null; Sequence{wx,wy,r} := e2 ; var wt : Sequence := Sequence{tx - wx}->union(Sequence{ ty - wy }); var rwt : String := R(wt) ; var sw : Sequence := Sequence{wx - sx}->union(Sequence{ wy - sy }); var rsw : String := R(sw) ; var st : Sequence := Sequence{tx - sx}->union(Sequence{ ty - sy }); var rst : String := R(st) ; var F : Sequence := Sequence{rwt < r}->union(Sequence{ rsw < r }) ; if rst = 0 then ( var c : int := 1 ) else (if F = Sequence{1}->union(Sequence{ 1 }) then ( c := 1 ) else (if F = Sequence{1}->union(Sequence{ 0 }) or F = Sequence{0}->union(Sequence{ 1 }) then ( c := 0 ) else (if F = Sequence{0}->union(Sequence{ 0 }) then ( a := M.pi / 2 - M.acos(r / rsw) ; b := M.acos(MathLib.roundN((sw->first() * st->first() + sw[1+1] * st[1+1]) / rsw / rst, 4)) ; if C(a, b) & C((rst)->pow(2), (rsw)->pow(2) - (r)->pow(2)) then ( c := 0 ) else ( c := 1 ) ) else skip ) ) ) ; execute ((c) : x)) ; return (x)->forAll( _x | _x = true ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as M def R(A): return(A[0]**2+A[1]**2)**.5 def I(i): return[map(int,raw_input().split())for _ in[0]*i] def C(a,b): return a>b or abs(a-b)<1e-6 def f(e1): tx,ty,sx,sy=e1 x=[] for e2 in WP : wx,wy,r=e2 wt=[tx-wx,ty-wy]; rwt=R(wt) sw=[wx-sx,wy-sy]; rsw=R(sw) st=[tx-sx,ty-sy]; rst=R(st) F=[rwtfirst())->pow(2) + (A[1+1])->pow(2)))->pow(.5); operation I(i : OclAny) : OclAny pre: true post: true activity: return MatrixLib.elementwiseMult(Sequence{ 0 }, i)->select(_anon | true)->collect(_anon | ((raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ))); operation C(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a->compareTo(b)) > 0 or (a - b)->abs() < ("1e-6")->toReal(); operation f(e1 : OclAny) : OclAny pre: true post: true activity: var tx : OclAny := null; var ty : OclAny := null; var sx : OclAny := null; var sy : OclAny := null; Sequence{tx,ty,sx,sy} := e1 ; var x : Sequence := Sequence{} ; for e2 : WP do ( var wx : OclAny := null; var wy : OclAny := null; var r : OclAny := null; Sequence{wx,wy,r} := e2 ; var wt : Sequence := Sequence{tx - wx}->union(Sequence{ ty - wy }); var rwt : String := R(wt) ; var sw : Sequence := Sequence{wx - sx}->union(Sequence{ wy - sy }); var rsw : String := R(sw) ; var st : Sequence := Sequence{tx - sx}->union(Sequence{ ty - sy }); var rst : String := R(st) ; var F : Sequence := Sequence{rwt < r}->union(Sequence{ rsw < r }) ; if rst = 0 then ( var c : int := 1 ) else (if F = Sequence{1}->union(Sequence{ 1 }) then ( c := 1 ) else (if F = Sequence{1}->union(Sequence{ 0 }) or F = Sequence{0}->union(Sequence{ 1 }) then ( c := 0 ) else (if F = Sequence{0}->union(Sequence{ 0 }) then ( a := M.pi / 2 - M.acos(r / rsw) ; b := M.acos(MathLib.roundN((sw->first() * st->first() + sw[1+1] * st[1+1]) / rsw / rst, 4)) ; if C(a, b) & C((rst)->pow(2), (rsw)->pow(2) - (r)->pow(2)) then ( c := 0 ) else ( c := 1 ) ) else skip ) ) ) ; if c = 0 then ( return 0 ) else skip ; execute ((c) : x)) ; return (x)->forAll( _x | _x = true ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as M def R(A): return(A[0]**2+A[1]**2)**.5 def I(i): return[map(int,raw_input().split())for _ in[0]*i] def C(a,b): return a>b or abs(a-b)<1e-6 def f(e1): tx,ty,sx,sy=e1 x=[] st=[tx-sx,ty-sy]; rst=R(st) for e2 in WP : wx,wy,r=e2 wt=[tx-wx,ty-wy]; rwt=R(wt) sw=[wx-sx,wy-sy]; rsw=R(sw) F=[rwtfirst())->pow(2) + (A[1+1])->pow(2)))->pow(.5); operation I(i : OclAny) : OclAny pre: true post: true activity: return MatrixLib.elementwiseMult(Sequence{ 0 }, i)->select(_anon | true)->collect(_anon | ((raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ))); operation C(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a->compareTo(b)) > 0 or (a - b)->abs() < ("1e-6")->toReal(); operation f(e1 : OclAny) : OclAny pre: true post: true activity: var tx : OclAny := null; var ty : OclAny := null; var sx : OclAny := null; var sy : OclAny := null; Sequence{tx,ty,sx,sy} := e1 ; var x : Sequence := Sequence{} ; var st : Sequence := Sequence{tx - sx}->union(Sequence{ ty - sy }); var rst : String := R(st) ; for e2 : WP do ( var wx : OclAny := null; var wy : OclAny := null; var r : OclAny := null; Sequence{wx,wy,r} := e2 ; var wt : Sequence := Sequence{tx - wx}->union(Sequence{ ty - wy }); var rwt : String := R(wt) ; var sw : Sequence := Sequence{wx - sx}->union(Sequence{ wy - sy }); var rsw : String := R(sw) ; var F : Sequence := Sequence{rwt < r}->union(Sequence{ rsw < r }) ; var c : int := 1 ; if F = Sequence{1}->union(Sequence{ 0 }) or F = Sequence{0}->union(Sequence{ 1 }) then ( return 0 ) else (if F = Sequence{0}->union(Sequence{ 0 }) then ( a := M.pi / 2 - M.acos(r / rsw) ; b := M.acos(MathLib.roundN((sw->first() * st->first() + sw[1+1] * st[1+1]) / rsw / rst, 4)) ; if C(a, b) & C((rst)->pow(2), (rsw)->pow(2) - (r)->pow(2)) then ( return 0 ) else skip ) else skip) ; execute ((c) : x)) ; return (x)->forAll( _x | _x = true ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as M def R(A): return(A[0]**2+A[1]**2)**.5 def I(i): return[map(int,raw_input().split())for _ in[0]*i] def C(a,b): return a>b or abs(a-b)<1e-6 def f(e1): tx,ty,sx,sy=e1 x=[] st=[tx-sx,ty-sy]; rst=R(st) for e2 in WP : wx,wy,r=e2 wt=[tx-wx,ty-wy]; rwt=R(wt) sw=[wx-sx,wy-sy]; rsw=R(sw) F=[rwtfirst())->pow(2) + (A[1+1])->pow(2)))->pow(.5); operation I(i : OclAny) : OclAny pre: true post: true activity: return MatrixLib.elementwiseMult(Sequence{ 0 }, i)->select(_anon | true)->collect(_anon | ((raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ))); operation C(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a->compareTo(b)) > 0 or (a - b)->abs() < ("1e-6")->toReal(); operation f(e1 : OclAny) : OclAny pre: true post: true activity: var tx : OclAny := null; var ty : OclAny := null; var sx : OclAny := null; var sy : OclAny := null; Sequence{tx,ty,sx,sy} := e1 ; var x : Sequence := Sequence{} ; var st : Sequence := Sequence{tx - sx}->union(Sequence{ ty - sy }); var rst : String := R(st) ; for e2 : WP do ( var wx : OclAny := null; var wy : OclAny := null; var r : OclAny := null; Sequence{wx,wy,r} := e2 ; var wt : Sequence := Sequence{tx - wx}->union(Sequence{ ty - wy }); var rwt : String := R(wt) ; var sw : Sequence := Sequence{wx - sx}->union(Sequence{ wy - sy }); var rsw : String := R(sw) ; var F : Sequence := Sequence{rwt < r}->union(Sequence{ rsw < r }) ; if F = Sequence{1}->union(Sequence{ 0 }) or F = Sequence{0}->union(Sequence{ 1 }) then ( return 0 ) else (if F = Sequence{0}->union(Sequence{ 0 }) then ( a := M.pi / 2 - M.acos(r / rsw) ; b := M.acos(MathLib.roundN((sw->first() * st->first() + sw[1+1] * st[1+1]) / rsw / rst, 4)) ; if C(a, b) & C((rst)->pow(2), (rsw)->pow(2) - (r)->pow(2)) then ( return 0 ) else skip ) else skip)) ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def intersection(cx,cy,r,P1,P2): x1,y1=P1 ; x2,y2=P2 xd=x2-x1 ; yd=y2-y1 X=x1-cx ; Y=y1-cy a=xd**2+yd**2 b=xd*X+yd*Y c=X**2+Y**2-r**2 f0=c ; f1=a+2*b+c if(f0>=0 and f1<=0)or(f0<=0 and f1>=0): return True return-a<=b<=0 and b**2-a*c>=0 and(f0>=0 or f1>=0) def solve(): N=int(input()) if N==0 : return False C=[] for i in range(N): x,y,r=map(int,input().split()) C.append((x,y,r)) M=int(input()) for i in range(M): tx,ty,sx,sy=map(int,input().split()) for j in range(N): cx,cy,r=C[j] if intersection(cx,cy,r,(tx,ty),(sx,sy)): print("Safe") break else : print("Danger") return True while solve(): ... ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; while solve() do (); operation intersection(cx : OclAny, cy : OclAny, r : OclAny, P1 : OclAny, P2 : OclAny) : OclAny pre: true post: true activity: var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := P1; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x2,y2} := P2 ; var xd : double := x2 - x1; var yd : double := y2 - y1 ; var X : double := x1 - cx; var Y : double := y1 - cy ; var a : double := (xd)->pow(2) + (yd)->pow(2) ; var b : double := xd * X + yd * Y ; var c : double := (X)->pow(2) + (Y)->pow(2) - (r)->pow(2) ; var f0 : OclAny := c; var f1 : OclAny := a + 2 * b + c ; if (f0 >= 0 & f1 <= 0) or (f0 <= 0 & f1 >= 0) then ( return true ) else skip ; return (-a->compareTo(b)) <= 0 & (b <= 0) & (b)->pow(2) - a * c >= 0 & (f0 >= 0 or f1 >= 0); operation solve() : OclAny pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( return false ) else skip ; var C : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{x, y, r}) : C)) ; var M : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, M-1) do ( var tx : OclAny := null; var ty : OclAny := null; var sx : OclAny := null; var sy : OclAny := null; Sequence{tx,ty,sx,sy} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name cx)))))) , (test (logical_test (comparison (expr (atom (name cy)))))) , (test (logical_test (comparison (expr (atom (name r))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name C)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name intersection)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name cx))))))) , (argument (test (logical_test (comparison (expr (atom (name cy))))))) , (argument (test (logical_test (comparison (expr (atom (name r))))))) , (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name tx)))))) , (test (logical_test (comparison (expr (atom (name ty))))))) ))))))) , (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name sx)))))) , (test (logical_test (comparison (expr (atom (name sy))))))) )))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Safe"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Danger"))))))) )))))))))))))))) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def findCount(d): return 9*(pow(10,d-1)-pow(9,d-1)); def findCountUpto(d): totalCount=0 for i in range(1,d+1): totalCount=totalCount+findCount(i) return totalCount d=1 print(findCountUpto(d)) d=2 print(findCountUpto(d)) d=4 print(findCountUpto(d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; d := 1 ; execute (findCountUpto(d))->display() ; d := 2 ; execute (findCountUpto(d))->display() ; d := 4 ; execute (findCountUpto(d))->display(); operation findCount(d : OclAny) pre: true post: true activity: return 9 * ((10)->pow(d - 1) - (9)->pow(d - 1));; operation findCountUpto(d : OclAny) : OclAny pre: true post: true activity: var totalCount : int := 0 ; for i : Integer.subrange(1, d + 1-1) do ( totalCount := totalCount + findCount(i)) ; return totalCount; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def digitSum(n): digSum=0 while(n>0): digSum+=n % 10 n//=10 return digSum def countInteger(n,s): if(ns): return(n-i+1) return 0 n=1000 s=100 print(countInteger(n,s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 1000 ; s := 100 ; execute (countInteger(n, s))->display(); operation digitSum(n : OclAny) : OclAny pre: true post: true activity: var digSum : int := 0 ; while (n > 0) do ( digSum := digSum + n mod 10 ; n := n div 10) ; return digSum; operation countInteger(n : OclAny, s : OclAny) : OclAny pre: true post: true activity: if ((n->compareTo(s)) < 0) then ( return 0 ) else skip ; for i : Integer.subrange(s, Set{n, s + 163}->min() + 1-1) do ( if (((i - digitSum(i))->compareTo(s)) > 0) then ( return (n - i + 1) ) else skip) ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop def solution(): _,m,k=map(int,input().split()) if k==0 : print(-1) return ; graph=defaultdict(list) for _ in range(m): a,b,w=map(int,input().split()) graph[a].append((b,w)) graph[b].append((a,w)) store=set(map(int,input().split())) ans=float("inf") for node in store : for nbr,w in graph[node]: if nbr not in store : ans=min(ans,w) if ans==float("inf"): print(-1) return ; print(ans) import sys import threading sys.setrecursionlimit(1<<30) threading.stack_size(1<<27) thread=threading.Thread(target=solution) thread.start(); thread.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1 * (2->pow(30))) ; threading.stack_size(1 * (2->pow(27))) ; var thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name solution)))))))) ; thread.start(); thread.join(); operation solution() : OclAny pre: true post: true activity: var _anon : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{_anon,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if k = 0 then ( execute (-1)->display() ; return; ) else skip ; var graph : OclAny := defaultdict(OclType["Sequence"]) ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; var w : OclAny := null; Sequence{a,b,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name b)))))) , (test (logical_test (comparison (expr (atom (name w))))))) )))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name w))))))) )))))))) ))))) ; var store : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ans : double := ("" + (("inf")))->toReal() ; for node : store do ( for _tuple : graph[node+1] do (var _indx : int := 1; var nbr : OclAny := _tuple->at(_indx); _indx := _indx + 1; var w : OclAny := _tuple->at(_indx); if (store)->excludes(nbr) then ( ans := Set{ans, w}->min() ) else skip)) ; if ans = ("" + (("inf")))->toReal() then ( execute (-1)->display() ; return; ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main_function(): n,m,k=[int(i)for i in input().split(" ")] u_v_l=[] for i in range(m): u_v_l.append([int(e)for e in input().split(" ")]) a_k=[] if k>0 : a_k=[int(u)for u in input().split(" ")] hash_a_k=[0 for i in range(n+1)] for i in a_k : hash_a_k[i]=1 graph={int(i):[]for i in range(n+1)} hash_roads={} for i in u_v_l : u,v,l=i if tuple(sorted([u,v]))in hash_roads : if hash_roads[tuple(sorted([u,v]))]>l : hash_roads[tuple(sorted([u,v]))]=l else : hash_roads[tuple(sorted([u,v]))]=l for i in hash_roads : u,v=i l=hash_roads[i] graph[u].append([v,l]) graph[v].append([u,l]) min_val=10**10 stack=[] for i in range(1,n+1): if hash_a_k[i]==1 : for j in range(len(graph[i])): v,l=graph[i][j] if hash_a_k[v]==0 : if lselect(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var u_v_l : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( execute ((input().split(" ")->select(e | true)->collect(e | (("" + ((e)))->toInteger()))) : u_v_l)) ; var a_k : Sequence := Sequence{} ; if k > 0 then ( a_k := input().split(" ")->select(u | true)->collect(u | (("" + ((u)))->toInteger())) ) else skip ; var hash_a_k : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; for i : a_k do ( hash_a_k[i+1] := 1) ; var graph : Map := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | Map{("" + ((i)))->toInteger() |-> Sequence{}})->unionAll() ; var hash_roads : OclAny := Set{} ; for i : u_v_l do ( var u : OclAny := null; var v : OclAny := null; var l : OclAny := null; Sequence{u,v,l} := i ; if (hash_roads)->includes((Sequence{u}->union(Sequence{ v })->sort())) then ( if (hash_roads->restrict((Sequence{u}->union(Sequence{ v })->sort()))->compareTo(l)) > 0 then ( hash_roads->restrict((Sequence{u}->union(Sequence{ v })->sort())) := l ) else skip ) else ( hash_roads->restrict((Sequence{u}->union(Sequence{ v })->sort())) := l )) ; for i : hash_roads do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := i ; var l : OclAny := hash_roads[i+1] ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name v)))))) , (test (logical_test (comparison (expr (atom (name l))))))) ]))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name u)))))) , (test (logical_test (comparison (expr (atom (name l))))))) ]))))))) ))))) ; var min_val : double := (10)->pow(10) ; var stack : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( if hash_a_k[i+1] = 1 then ( for j : Integer.subrange(0, (graph[i+1])->size()-1) do ( var v : OclAny := null; Sequence{v,l} := graph[i+1][j+1] ; if hash_a_k[v+1] = 0 then ( if (l->compareTo(min_val)) < 0 then ( min_val := l ) else skip ) else skip) ) else skip) ; if min_val = (10)->pow(10) then ( execute (-1)->display() ) else ( execute (min_val)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nth_group(n): return n*(2*pow(n,2)+1) N=5 print(nth_group(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 5 ; execute (nth_group(N))->display(); operation nth_group(n : OclAny) : OclAny pre: true post: true activity: return n * (2 * (n)->pow(2) + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMin(V): deno=[1,2,5,10,20,50,100,500,1000] n=len(deno) ans=[] i=n-1 while(i>=0): while(V>=deno[i]): V-=deno[i] ans.append(deno[i]) i-=1 for i in range(len(ans)): print(ans[i],end="") if __name__=='__main__' : n=93 print("Following is minimal number","of change for",n,": ",end="") findMin(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 93 ; execute ("Following is minimal number")->display() ; findMin(n) ) else skip; operation findMin(V : OclAny) pre: true post: true activity: var deno : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{5}->union(Sequence{10}->union(Sequence{20}->union(Sequence{50}->union(Sequence{100}->union(Sequence{500}->union(Sequence{ 1000 })))))))) ; var n : int := (deno)->size() ; var ans : Sequence := Sequence{} ; var i : double := n - 1 ; while (i >= 0) do ( while ((V->compareTo(deno[i+1])) >= 0) do ( V := V - deno[i+1] ; execute ((deno[i+1]) : ans)) ; i := i - 1) ; for i : Integer.subrange(0, (ans)->size()-1) do ( execute (ans[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(): inp=input() inp=inp.split() n=int(inp[0]) m=int(inp[1]) k=int(inp[2]) if k==0 : print(-1) return 0 edges=[] storages=set() ans=sys.maxsize for _ in range(m): inp=input() inp=inp.split() u=int(inp[0]) v=int(inp[1]) w=int(inp[2]) edge=[u,v,w] edges.append(edge) inp=input() inp=inp.split() for inpu in inp : storage=int(inpu) storages.add(storage) for edge in edges : if(edge[0]in storages or edge[1]in storages): if not((edge[0]in storages and edge[1]in storages)): ans=min(ans,edge[2]) if(ans==sys.maxsize): print(-1) return 0 print(ans) return 0 if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() : OclAny pre: true post: true activity: var inp : String := (OclFile["System.in"]).readLine() ; inp := inp.split() ; var n : int := ("" + ((inp->first())))->toInteger() ; var m : int := ("" + ((inp[1+1])))->toInteger() ; var k : int := ("" + ((inp[2+1])))->toInteger() ; if k = 0 then ( execute (-1)->display() ; return 0 ) else skip ; var edges : Sequence := Sequence{} ; var storages : Set := Set{}->union(()) ; var ans : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; for _anon : Integer.subrange(0, m-1) do ( inp := (OclFile["System.in"]).readLine() ; inp := inp.split() ; var u : int := ("" + ((inp->first())))->toInteger() ; var v : int := ("" + ((inp[1+1])))->toInteger() ; var w : int := ("" + ((inp[2+1])))->toInteger() ; var edge : Sequence := Sequence{u}->union(Sequence{v}->union(Sequence{ w })) ; execute ((edge) : edges)) ; inp := (OclFile["System.in"]).readLine() ; inp := inp.split() ; for inpu : inp->characters() do ( var storage : int := ("" + ((inpu)))->toInteger() ; execute ((storage) : storages)) ; for edge : edges do ( if ((storages)->includes(edge->first()) or (storages)->includes(edge[1+1])) then ( if not((((storages)->includes(edge->first()) & (storages)->includes(edge[1+1])))) then ( ans := Set{ans, edge[2+1]}->min() ) else skip ) else skip) ; if (ans = (trailer . (name maxsize))) then ( execute (-1)->display() ; return 0 ) else skip ; execute (ans)->display() ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin def li(): return[int(x)for x in stdin.readline().split()] def li_(): return[int(x)-1 for x in stdin.readline().split()] def lf(): return[float(x)for x in stdin.readline().split()] def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(ns()) def nf(): return float(ns()) n=ni() i=1 ans=10*10 while i*i<=n : if n % i==0 : f=max(len(str(i)),len(str(n//i))) ans=min(ans,f) i+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stdin : OclFile := OclFile["System.in"] ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := ni() ; var i : int := 1 ; var ans : int := 10 * 10 ; while (i * i->compareTo(n)) <= 0 do ( if n mod i = 0 then ( var f : OclAny := Set{(("" + ((i))))->size(), (("" + ((n div i))))->size()}->max() ; ans := Set{ans, f}->min() ) else skip ; i := i + 1) ; execute (ans)->display(); operation li() : OclAny pre: true post: true activity: return stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation li_() : OclAny pre: true post: true activity: return stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation lf() : OclAny pre: true post: true activity: return stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation ls() : OclAny pre: true post: true activity: return stdin.readLine().split(); operation ns() : OclAny pre: true post: true activity: return stdin.readLine().rstrip(); operation lc() : OclAny pre: true post: true activity: return (ns()); operation ni() : OclAny pre: true post: true activity: return ("" + ((ns())))->toInteger(); operation nf() : OclAny pre: true post: true activity: return ("" + ((ns())))->toReal(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(): inp=input() inp=inp.split() n=int(inp[0]) m=int(inp[1]) k=int(inp[2]) if k==0 : print(-1) return 0 edges=[] storages=set() ans=sys.maxsize for _ in range(m): inp=input() inp=inp.split() u=int(inp[0]) v=int(inp[1]) w=int(inp[2]) edge=[u,v,w] edges.append(edge) inp=input() inp=inp.split() for inpu in inp : storage=int(inpu) storages.add(storage) for edge in edges : if(edge[0]in storages or edge[1]in storages): if not((edge[0]in storages and edge[1]in storages)): ans=min(ans,edge[2]) if(ans==sys.maxsize): print(-1) return 0 print(ans) return 0 if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() : OclAny pre: true post: true activity: var inp : String := (OclFile["System.in"]).readLine() ; inp := inp.split() ; var n : int := ("" + ((inp->first())))->toInteger() ; var m : int := ("" + ((inp[1+1])))->toInteger() ; var k : int := ("" + ((inp[2+1])))->toInteger() ; if k = 0 then ( execute (-1)->display() ; return 0 ) else skip ; var edges : Sequence := Sequence{} ; var storages : Set := Set{}->union(()) ; var ans : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; for _anon : Integer.subrange(0, m-1) do ( inp := (OclFile["System.in"]).readLine() ; inp := inp.split() ; var u : int := ("" + ((inp->first())))->toInteger() ; var v : int := ("" + ((inp[1+1])))->toInteger() ; var w : int := ("" + ((inp[2+1])))->toInteger() ; var edge : Sequence := Sequence{u}->union(Sequence{v}->union(Sequence{ w })) ; execute ((edge) : edges)) ; inp := (OclFile["System.in"]).readLine() ; inp := inp.split() ; for inpu : inp->characters() do ( var storage : int := ("" + ((inpu)))->toInteger() ; execute ((storage) : storages)) ; for edge : edges do ( if ((storages)->includes(edge->first()) or (storages)->includes(edge[1+1])) then ( if not((((storages)->includes(edge->first()) & (storages)->includes(edge[1+1])))) then ( ans := Set{ans, edge[2+1]}->min() ) else skip ) else skip) ; if (ans = (trailer . (name maxsize))) then ( execute (-1)->display() ; return 0 ) else skip ; execute (ans)->display() ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,m,k=map(int,input().split()) d=[0]*n g=[map(int,input().split())for _ in range(m)] for i in map(int,input().split()): d[i-1]=1 x=1e10 for a,b,c in g : if(d[a-1]==1 and d[b-1]==0)or(d[a-1]==0 and d[b-1]==1): x=min(c,x) print(x if x!=1e10 else-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var g : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; for i : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( d[i - 1+1] := 1) ; var x : double := ("1e10")->toReal() ; for _tuple : g do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if (d[a - 1+1] = 1 & d[b - 1+1] = 0) or (d[a - 1+1] = 0 & d[b - 1+1] = 1) then ( x := Set{c, x}->min() ) else skip) ; execute (if x /= ("1e10")->toReal() then x else -1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=map(int,input().split()) reciprocal_A=[1/x for x in A] ans=1/sum(reciprocal_A) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var reciprocal_A : Sequence := A->select(x | true)->collect(x | (1 / x)) ; var ans : double := 1 / (reciprocal_A)->sum() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from functools import reduce def input(): return sys.stdin.readline().rstrip() def main(): n=int(input()) a_tuple=tuple(map(int,input().split())) a_mul=reduce(lambda a,b : a*b,a_tuple) print(a_mul/sum([a_mul/a for a in a_tuple])) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a_tuple : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a_mul : OclAny := reduce(lambda a : OclAny, b : OclAny in (a * b), a_tuple) ; execute (a_mul / (a_tuple->select(a | true)->collect(a | (a_mul / a)))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import operator def prod(array): result=1 for i in range(len(array)): result*=array[i] return result n=int(input()) a=list(map(int,input().split())) for i in range(n): a[i]=1/a[i] print(1/sum(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( a[i+1] := 1 / a[i+1]) ; execute (1 / (a)->sum())->display(); operation prod(array : OclAny) : OclAny pre: true post: true activity: var result : int := 1 ; for i : Integer.subrange(0, (array)->size()-1) do ( result := result * array[i+1]) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from decimal import Decimal,ROUND_HALF_UP,ROUND_HALF_EVEN N=int(input()) a=list(map(int,input().split())) res=0 for i in range(N): res+=1/a[i] print(Decimal(1/res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : int := 0 ; for i : Integer.subrange(0, N-1) do ( res := res + 1 / a[i+1]) ; execute (Decimal(1 / res))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import Fraction n=int(input()) a=list(map(lambda x : Fraction(1,int(x)),input().split())) print(float(Fraction(1,sum(a)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (lambda x : OclAny in (Fraction(1, ("" + ((x)))->toInteger())))->apply(_x) )) ; execute (("" + ((Fraction(1, (a)->sum()))))->toReal())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import defaultdict sys.setrecursionlimit(10**6) int1=lambda x : int(x)-1 p2D=lambda x : print(*x,sep="\n") def MI(): return map(int,sys.stdin.readline().split()) def LI(): return list(map(int,sys.stdin.readline().split())) def LLI(rows_number): return[LI()for _ in range(rows_number)] def main(): def check(s): for i in range(n): if s>>i & 1 : for j,y in to[i]: if s>>j & 1!=y : return False return True to=defaultdict(list) n=int(input()) for i in range(n): a=int(input()) for _ in range(a): x,y=MI() to[i].append([x-1,y]) ans=0 for s in range(1<pow(6)) ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; var p2D : Function := lambda x : OclAny in (((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ; skip ; skip ; skip ; skip ; main(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LLI(rows_number : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows_number-1)->select(_anon | true)->collect(_anon | (LI())); operation main() pre: true post: true activity: skip ; var to : OclAny := defaultdict(OclType["Sequence"]) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, a-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := MI() ; (expr (atom (name to)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (atom (name y))))))) ]))))))) )))))) ; var ans : int := 0 ; for s : Integer.subrange(0, 1 * (2->pow(n))-1) do ( if check(s) then ( ans := Set{ans, bin(s)->count("1")}->max() ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools def compute(): cond=lambda i : all(sorted(str(i))==sorted(str(j*i))for j in range(2,7)) ans=next(i for i in itertools.count(1)if cond(i)) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var cond : Function := lambda i : OclAny in (((argument (test (logical_test (comparison (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))) ))))) == (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name j))) * (expr (atom (name i))))))))) ))))))))) )))))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 7))))))))) )))))))))->forAll( _x | _x = true )) ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name itertools)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (atom (name cond)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))))).next() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def parser(): while 1 : data=list(input().split(' ')) for number in data : if len(number)>0 : yield(number) input_parser=parser() def gw(): global input_parser return next(input_parser) def gi(): data=gw() return int(data) import numpy import scipy def best(bm): res=[-1]*N for i in range(N): if(bm &(1<pow(N))-1) do ( ans := Set{ans, best(bitmap)}->max()) ; execute (ans)->display(); operation parser(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; while 1 do ( var data : Sequence := (input().split(' ')) ; for number : data do ( if (number)->size() > 0 then ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return (number) ) else skip)); operation gw() : OclAny pre: true post: true activity: skip ; return (input_parser).next(); operation gi() : OclAny pre: true post: true activity: data := gw() ; return ("" + ((data)))->toInteger(); operation best(bm : OclAny) : OclAny pre: true post: true activity: var res : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, N) ; for i : Integer.subrange(0, N-1) do ( if (MathLib.bitwiseAnd(bm, (1 * (2->pow(i)))) = 0) then ( if (res[i+1] = 1) then ( return -1 ) else skip ; res[i+1] := 0 ; continue ) else skip ; if (res[i+1] = 0) then ( return -1 ) else skip ; res[i+1] := 1 ; for _tuple : ts[i+1] do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if res[x+1] = -1 then ( res[x+1] := y ) else (if res[x+1] /= y then ( return -1 ) else skip))) ; var cnt : int := 0 ; for v : res do ( if v then ( cnt := cnt + 1 ) else skip) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict from itertools import combinations N=int(input()) testimonies=[] for _ in range(N): A=int(input()) ts=defaultdict(set) for _ in range(A): x,y=map(int,input().split()) x-=1 ts['honest' if y else 'not'].add(x) testimonies.append(ts) for n in range(N,0,-1): for honests in combinations(range(N),r=n): hs=set() ns=set() for i in honests : hs |=testimonies[i]['honest'] ns |=testimonies[i]['not'] if not hs & ns and not hs-set(honests)and not set(honests)& ns : print(n) break else : continue break else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var testimonies : Sequence := Sequence{} ; for _anon : Integer.subrange(0, N-1) do ( var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ts : OclAny := defaultdict(OclType["Set"]) ; for _anon : Integer.subrange(0, A-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; x := x - 1 ; (expr (atom (name ts)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'honest')))) if (logical_test (comparison (expr (atom (name y))))) else (test (logical_test (comparison (expr (atom 'not')))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))) ; execute ((ts) : testimonies)) ; (compound_stmt for (exprlist (expr (atom (name n)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name honests)))) in (testlist (test (logical_test (comparison (expr (atom (name combinations)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name r)))))) = (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name hs)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name set)) (trailer (arguments ( ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ns)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name set)) (trailer (arguments ( ))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name honests))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name hs)))))))) (assign_part |= (testlist (test (logical_test (comparison (expr (atom (name testimonies)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'honest'))))))) ]))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ns)))))))) (assign_part |= (testlist (test (logical_test (comparison (expr (atom (name testimonies)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'not'))))))) ])))))))))))))) (stmt (compound_stmt if (test (logical_test (logical_test (logical_test not (logical_test (comparison (expr (expr (atom (name hs))) & (expr (atom (name ns))))))) and (logical_test not (logical_test (comparison (expr (expr (atom (name hs))) - (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name honests)))))))) ))))))))) and (logical_test not (logical_test (comparison (expr (expr (atom (name set)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name honests)))))))) )))) & (expr (atom (name ns))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt continue))))))) (stmt (simple_stmt (small_stmt break)))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(x)for x in input().split()] b=[int(x)for x in input().split()] if a[0]!=0 : index_b=b.index(a[0]) else : index_b=b.index(a[1]) for index_a in range(0,len(a)): if a[index_a]==0 : continue if b[index_b % len(a)]==0 : index_b+=1 if a[index_a]!=b[index_b % len(a)]: print('NO') exit() index_b+=1 print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var b : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if a->first() /= 0 then ( var index_b : int := b->indexOf(a->first()) - 1 ) else ( index_b := b->indexOf(a[1+1]) - 1 ) ; for index_a : Integer.subrange(0, (a)->size()-1) do ( if a[index_a+1] = 0 then ( continue ) else skip ; if b[index_b mod (a)->size()+1] = 0 then ( index_b := index_b + 1 ) else skip ; if a[index_a+1] /= b[index_b mod (a)->size()+1] then ( execute ('NO')->display() ; exit() ) else skip ; index_b := index_b + 1) ; execute ('YES')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def two(x): p=bin(x) ans=p[2 :] if len(ans)toInteger() ; var aa : Sequence := Sequence{} ; var aaa : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((a) : aaa) ; var qw : Sequence := Sequence{} ; for j : Integer.subrange(0, a-1) do ( var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{x}->union(Sequence{ y })) : qw)) ; execute ((qw) : aa)) ; var anst : int := 0 ; for i : Integer.subrange(0, (2)->pow(n)-1) do ( p := two(i) ; var flag : boolean := true ; var syojiki : Sequence := Sequence{} ; for u : Integer.subrange(0, n-1) do ( if p[u+1] = "1" then ( execute ((1) : syojiki) ) else ( execute ((0) : syojiki) )) ; ans := p->count("1") ; for j : Integer.subrange(0, n-1) do ( if flag = false then ( break ) else skip ; if p[j+1] = "0" then ( continue ) else skip ; for k : Integer.subrange(0, aaa[j+1]-1) do ( if aa[j+1][k+1][1+1] = 0 then ( if syojiki[aa[j+1][k+1]->first() - 1+1] = 1 then ( flag := false ; break ) else skip ; syojiki[aa[j+1][k+1]->first() - 1+1] := 0 ) else ( if syojiki[aa[j+1][k+1]->first() - 1+1] = 0 then ( flag := false ; break ) else skip ; syojiki[aa[j+1][k+1]->first() - 1+1] := 1 ))) ; if flag then ( anst := Set{anst, ans}->max() ) else skip) ; execute (anst)->display(); operation two(x : OclAny) : OclAny pre: true post: true activity: var p : OclAny := bin(x) ; var ans : OclAny := p.subrange(2+1) ; if ((ans)->size()->compareTo(n)) < 0 then ( ans := StringLib.nCopies("0", (n - (ans)->size())) + ans ) else skip ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools from collections import defaultdict def ok_bit(bit): for i in range(N): if bit[i]==0 : continue for x,y in evidence_dict[i]: if y!=bit[x-1]: return False return True def solver(): for bit in reversed(bit_list): if ok_bit(bit): return bit return[0] N=int(input()) evidence_dict=defaultdict(list) A=[] for i in range(N): A1=int(input()) for j in range(A1): evidence_dict[i].append(list(map(int,input().split()))) L=[0,1] bit_list=list(itertools.product(L,repeat=N)) if __name__=="__main__" : ans_bit=solver() res=0 for b in ans_bit : if b==1 : res+=1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var evidence_dict : OclAny := defaultdict(OclType["Sequence"]) ; var A : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var A1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, A1-1) do ((expr (atom (name evidence_dict)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))))))) )))))) ; var L : Sequence := Sequence{0}->union(Sequence{ 1 }) ; var bit_list : Sequence := (itertools.product(L, (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (name N))))))))) ; if __name__ = "__main__" then ( var ans_bit : OclAny := solver() ; var res : int := 0 ; for b : ans_bit do ( if b = 1 then ( res := res + 1 ) else skip) ; execute (res)->display() ) else skip; operation ok_bit(bit : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, N-1) do ( if bit[i+1] = 0 then ( continue ) else skip ; for _tuple : evidence_dict[i+1] do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if y /= bit[x - 1+1] then ( return false ) else skip)) ; return true; operation solver() : OclAny pre: true post: true activity: for bit : (bit_list)->reverse() do ( if ok_bit(bit) then ( return bit ) else skip) ; return Sequence{ 0 }; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=1000000007 MAX=10000 prefix=[0]*(MAX+1) def buildPrefix(): prime=[True]*(MAX+1) p=2 while p*p<=MAX : if(prime[p]==True): for i in range(p*2,MAX+1,p): prime[i]=False p+=1 prefix[0]=prefix[1]=1 for p in range(2,MAX+1): prefix[p]=prefix[p-1] if(prime[p]): prefix[p]=(prefix[p]*p)% mod def power(x,y,p): res=1 x=x % p while(y>0): if(y & 1): res=(res*x)% p y=y>>1 x=(x*x)% p return res def inverse(n): return power(n,mod-2,mod) def productPrimeRange(L,R): return(prefix[R]*inverse(prefix[L-1]))% mod if __name__=="__main__" : buildPrefix() L=10 R=20 print(productPrimeRange(L,R)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : int := 1000000007 ; var MAX : int := 10000 ; var prefix : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX + 1)) ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( buildPrefix() ; L := 10 ; R := 20 ; execute (productPrimeRange(L, R))->display() ) else skip; operation buildPrefix() pre: true post: true activity: var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (MAX + 1)) ; var p : int := 2 ; while (p * p->compareTo(MAX)) <= 0 do ( if (prime[p+1] = true) then ( for i : Integer.subrange(p * 2, MAX + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip ; p := p + 1) ; prefix->first() := 1; var prefix[1+1] : int := 1 ; for p : Integer.subrange(2, MAX + 1-1) do ( prefix[p+1] := prefix[p - 1+1] ; if (prime[p+1]) then ( prefix[p+1] := (prefix[p+1] * p) mod mod ) else skip); operation power(x : OclAny, y : OclAny, p : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; x := x mod p ; while (y > 0) do ( if (MathLib.bitwiseAnd(y, 1)) then ( res := (res * x) mod p ) else skip ; y := y /(2->pow(1)) ; x := (x * x) mod p) ; return res; operation inverse(n : OclAny) : OclAny pre: true post: true activity: return power(n, mod - 2, mod); operation productPrimeRange(L : OclAny, R : OclAny) : OclAny pre: true post: true activity: return (prefix[R+1] * inverse(prefix[L - 1+1])) mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printPermutation(n): if(n % 2!=0): print(-1); else : for i in range(1,(n//2)+1): print((2*i),(2*i-1),end=" "); n=4 ; printPermutation(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4; ; printPermutation(n);; operation printPermutation(n : OclAny) pre: true post: true activity: if (n mod 2 /= 0) then ( execute (-1)->display(); ) else ( for i : Integer.subrange(1, (n div 2) + 1-1) do ( execute ((2 * i))->display();) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def mostCommonWord(self,paragraph,banned): banned=set(banned) count=collections.Counter(word for word in re.split('[!?\',;.]',paragraph.lower())if word) return max((item for item in count.items()if item[0]not in banned),key=operator.itemgetter(1))[0] ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation mostCommonWord(paragraph : OclAny,banned : OclAny) : OclAny pre: true post: true activity: banned := Set{}->union((banned)) ; var count : OclAny := .Counter((argument (test (logical_test (comparison (expr (atom (name word)))))) (comp_for for (exprlist (expr (atom (name word)))) in (logical_test (comparison (expr (atom (name re)) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '[!?\',;.]')))))) , (argument (test (logical_test (comparison (expr (atom (name paragraph)) (trailer . (name lower) (arguments ( ))))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (atom (name word)))))))))) ; return max(Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name item)))))) (comp_for for (exprlist (expr (atom (name item)))) in (logical_test (comparison (expr (atom (name count)) (trailer . (name items) (arguments ( )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name item)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) not in (comparison (expr (atom (name banned))))))))))}, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name operator)) (trailer . (name itemgetter) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))))))->first(); } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline from collections import namedtuple from itertools import permutations def solve(items): total_weight=0 for i in items : total_weight+=i.w best_ans=[] best_gp=float('inf') for perm in permutations(items): ans=[] squashed=False cw=0 gp=0 n=len(items) for p in perm : if p.s=0 : ans.append(items[i].name) items.pop(i) break return ans item=namedtuple('item',['name','w','s']) def main(args): while True : n=int(input()) if n==0 : break items=[] for _ in range(n): name,w,s=input().split() items.append(item(name,int(w),int(s))) result=solve2(items) print('\n'.join(result)) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; skip ; skip ; var item : OclAny := namedtuple('item', Sequence{'name'}->union(Sequence{'w'}->union(Sequence{ 's' }))) ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(items : OclAny) : OclAny pre: true post: true activity: var total_weight : int := 0 ; for i : items do ( total_weight := total_weight + i.w) ; var best_ans : Sequence := Sequence{} ; var best_gp : double := ("" + (('inf')))->toReal() ; for perm : permutations(items) do ( var ans : Sequence := Sequence{} ; var squashed : boolean := false ; var cw : int := 0 ; var gp : int := 0 ; var n : int := (items)->size() ; for p : perm do ( if (p.s->compareTo(cw)) < 0 then ( squashed := true ; break ) else skip ; cw := cw + p.w ; execute ((p.name) : ans) ; gp := gp + n * p.w ; n := n - 1) ; if not(squashed) then ( gp := gp / total_weight ; if (gp->compareTo(best_gp)) < 0 then ( best_gp := gp ; best_ans := ans ) else skip ) else skip) ; best_ans := best_ans->reverse() ; return best_ans; operation solve2(items : OclAny) : OclAny pre: true post: true activity: items := items->sort() ; ans := Sequence{} ; while items do ( total_weight := 0 ; for i : items do ( total_weight := total_weight + i.w) ; var cap : Sequence := items->select(x | true)->collect(x | (x.s - total_weight + x.w)) ; for i : Integer.subrange(0, (items)->size()-1) do ( if cap[i+1] >= 0 then ( execute ((items[i+1].name) : ans) ; items := items->excludingAt(i+1) ; break ) else skip)) ; return ans; operation main(args : OclAny) pre: true post: true activity: while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; items := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var name : OclAny := null; var w : OclAny := null; var s : OclAny := null; Sequence{name,w,s} := input().split() ; execute ((item(name, ("" + ((w)))->toInteger(), ("" + ((s)))->toInteger())) : items)) ; var result : OclAny := solve2(items) ; execute (StringLib.sumStringsWithSeparator((result), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline from collections import namedtuple def solve(items): from itertools import permutations total_weight=0 for i in items : total_weight+=i.w best_ans=[] best_gp=float('inf') for perm in permutations(items): ans=[] squashed=False cw=0 gp=0 n=len(items) for p in perm : if p.s=0 : ans.append(items[i].name) i=items.pop(i) total_weight-=i.w break return ans item=namedtuple('item',['name','w','s']) def main(args): while True : n=int(input()) if n==0 : break items=[] for _ in range(n): name,w,s=input().split() items.append(item(name,int(w),int(s))) result=solve2(items) print('\n'.join(result)) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; skip ; var item : OclAny := namedtuple('item', Sequence{'name'}->union(Sequence{'w'}->union(Sequence{ 's' }))) ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(items : OclAny) : OclAny pre: true post: true activity: skip ; var total_weight : int := 0 ; for i : items do ( total_weight := total_weight + i.w) ; var best_ans : Sequence := Sequence{} ; var best_gp : double := ("" + (('inf')))->toReal() ; for perm : permutations(items) do ( var ans : Sequence := Sequence{} ; var squashed : boolean := false ; var cw : int := 0 ; var gp : int := 0 ; var n : int := (items)->size() ; for p : perm do ( if (p.s->compareTo(cw)) < 0 then ( squashed := true ; break ) else skip ; cw := cw + p.w ; execute ((p.name) : ans) ; gp := gp + n * p.w ; n := n - 1) ; if not(squashed) then ( gp := gp / total_weight ; if (gp->compareTo(best_gp)) < 0 then ( best_gp := gp ; best_ans := ans ) else skip ) else skip) ; best_ans := best_ans->reverse() ; return best_ans; operation solve2(items : OclAny) : OclAny pre: true post: true activity: items := items->sort() ; total_weight := 0 ; for i : items do ( total_weight := total_weight + i.w) ; ans := Sequence{} ; while items do ( var cap : Sequence := items->select(x | true)->collect(x | (x.s - total_weight + x.w)) ; for i : Integer.subrange(0, (items)->size()-1) do ( if cap[i+1] >= 0 then ( execute ((items[i+1].name) : ans) ; var i : OclAny := items->at(i`firstArg+1) ; items := items->excludingAt(i+1) ; total_weight := total_weight - i.w ; break ) else skip)) ; return ans; operation main(args : OclAny) pre: true post: true activity: while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; items := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var name : OclAny := null; var w : OclAny := null; var s : OclAny := null; Sequence{name,w,s} := input().split() ; execute ((item(name, ("" + ((w)))->toInteger(), ("" + ((s)))->toInteger())) : items)) ; var result : OclAny := solve2(items) ; execute (StringLib.sumStringsWithSeparator((result), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count(arr,n,x): if(x==1): ans=pow(2,n)-1 return ans ; count=0 for i in range(n): if(arr[i]% x==0): count+=1 ans=pow(2,count)-1 return ans if __name__=="__main__" : arr=[2,4,3,5] n=len(arr) x=1 print(count(arr,n,x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{2}->union(Sequence{4}->union(Sequence{3}->union(Sequence{ 5 }))) ; n := (arr)->size() ; x := 1 ; execute (count(arr, n, x))->display() ) else skip; operation count(arr : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: if (x = 1) then ( var ans : double := (2)->pow(n) - 1 ; return ans; ) else skip ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] mod x = 0) then ( count := count + 1 ) else skip) ; ans := (2)->pow(count) - 1 ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import namedtuple Data=namedtuple("Data","name weight limit") def search(food_list,select_list,total_weight): if len(food_list)==0 : return select_list limit=select_list[len(select_list)-1].limit for lp,food in enumerate(food_list): if total_weight<=limit : select_list.append(food) food_list.remove(food) total_weight-=food.weight search(food_list,select_list,total_weight) if len(food_list)==0 : return select_list else : select_list.pop() food_list.insert(lp,food) total_weight+=food.weight return None while True : input_count=int(input()) if input_count==0 : break input_data=[input().split(" ")for _ in range(input_count)] input_data=[Data(item[0],int(item[1]),int(item[2]))for item in input_data] input_data.sort(key=lambda x :(x.weight,x.limit),reverse=True) total_weight=sum([item.weight for item in input_data]) result=search(input_data,[Data("sentinel",0,999999)],total_weight) del result[0] output=[item.name for item in result] print("\n".join(output)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var Data : OclAny := namedtuple("Data", "name weight limit") ; skip ; while true do ( var input_count : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if input_count = 0 then ( break ) else skip ; var input_data : Sequence := Integer.subrange(0, input_count-1)->select(_anon | true)->collect(_anon | (input().split(" "))) ; input_data := input_data->select(item | true)->collect(item | (Data(item->first(), ("" + ((item[1+1])))->toInteger(), ("" + ((item[2+1])))->toInteger()))) ; input_data := input_data->sort() ; total_weight := (input_data->select(item | true)->collect(item | (item.weight)))->sum() ; var result : OclAny := search(input_data, Sequence{ Data("sentinel", 0, 999999) }, total_weight) ; execute (result->first())->isDeleted() ; var output : Sequence := result->select(item | true)->collect(item | (item.name)) ; execute (StringLib.sumStringsWithSeparator((output), "\n"))->display()); operation search(food_list : OclAny, select_list : OclAny, total_weight : OclAny) : OclAny pre: true post: true activity: if (food_list)->size() = 0 then ( return select_list ) else skip ; var limit : OclAny := select_list[(select_list)->size() - 1+1].limit ; for _tuple : Integer.subrange(1, (food_list)->size())->collect( _indx | Sequence{_indx-1, (food_list)->at(_indx)} ) do (var _indx : int := 1; var lp : OclAny := _tuple->at(_indx); _indx := _indx + 1; var food : OclAny := _tuple->at(_indx); if (total_weight->compareTo(limit)) <= 0 then ( execute ((food) : select_list) ; execute ((food) /: food_list) ; total_weight := total_weight - food.weight ; search(food_list, select_list, total_weight) ; if (food_list)->size() = 0 then ( return select_list ) else ( select_list := select_list->front() ; food_list := food_list.insertAt(lp+1, food) ; total_weight := total_weight + food.weight ) ) else skip) ; return null; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=10**20 while True : n=int(input()) if n==0 : break names=[] weights=[] safes=[] for _ in range(n): f,w,s=input().split() names.append(f) weights.append(int(w)) safes.append(int(s)) all_weight=sum(weights) dic=[None]*(2**n) def score(rest,total_weight,count): if dic[rest]!=None : return dic[rest] if rest==0 : return(0,[]) ret=(INF,[]) mask=1 for i in range(n): if rest & mask : if safes[i]>=all_weight-total_weight-weights[i]: temp=score(rest & ~ mask,total_weight+weights[i],count+1) ret=min(ret,(temp[0]+weights[i]*(count+1),[names[i]]+temp[1])) mask<<=1 dic[rest]=ret return ret print(*score(2**n-1,0,0)[1],sep="\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INF : double := (10)->pow(20) ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var names : Sequence := Sequence{} ; var weights : Sequence := Sequence{} ; var safes : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var f : OclAny := null; var w : OclAny := null; var s : OclAny := null; Sequence{f,w,s} := input().split() ; execute ((f) : names) ; execute ((("" + ((w)))->toInteger()) : weights) ; execute ((("" + ((s)))->toInteger()) : safes)) ; var all_weight : OclAny := (weights)->sum() ; var dic : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, ((2)->pow(n))) ; skip ; execute ((argument * (test (logical_test (comparison (expr (atom (name score)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (number (integer 2)))) ** (expr (atom (name n)))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re S=input() regex=r'A[a-z][a-z]*C[a-z]*[a-z]' ans=re.match(regex,S) if(ans!=None): if(ans.span()==(0,len(S))): print('AC') else : print('WA') else : print('WA') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var S : String := (OclFile["System.in"]).readLine() ; var regex : String := StringLib.rawString('A[a-z][a-z]*C[a-z]*[a-z]') ; var ans : String := (S)->firstMatch("^" + regex + ".*") ; if (ans /= null) then ( if (ans.span() = Sequence{0, (S)->size()}) then ( execute ('AC')->display() ) else ( execute ('WA')->display() ) ) else ( execute ('WA')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) i=0 t=0 if a[0]!=0 else 1 for j in range(n): if a[t]==b[j]: i=j break bl=True for j in range(n): if b[i % n]!=a[j]: if a[j]==0 : continue elif b[i % n]==0 and b[(i+1)% n]==a[j]: i+=2 continue bl=False break i+=1 print("YES" if bl else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var i : int := 0 ; var t : int := if a->first() /= 0 then 0 else 1 endif ; for j : Integer.subrange(0, n-1) do ( if a[t+1] = b[j+1] then ( i := j ; break ) else skip) ; var bl : boolean := true ; for j : Integer.subrange(0, n-1) do ( if b[i mod n+1] /= a[j+1] then ( if a[j+1] = 0 then ( continue ) else (if b[i mod n+1] = 0 & b[(i + 1) mod n+1] = a[j+1] then ( i := i + 2 ; continue ) else skip) ; bl := false ; break ) else skip ; i := i + 1) ; execute (if bl then "YES" else "NO" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() AC="AC" if not s[0]=="A" : AC="WA" s=s[1 :] if not s[1 :-1].count("C")==1 : AC="WA" s=s.replace("C","c") if not s.islower(): AC="WA" print(AC) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var AC : String := "AC" ; if not(s->first() = "A") then ( AC := "WA" ) else skip ; s := s->tail() ; if not(s.subrange(1+1, -1)->count("C") = 1) then ( AC := "WA" ) else skip ; s := s.replace("C", "c") ; if not(s->matches("[a-z ]*")) then ( AC := "WA" ) else skip ; execute (AC)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() print("AC" if all([S.startswith("A"),len([c for c in S[2 :-1]if c=="C"])==1,all([c in "abcdefghijklmnopqrstuvwxyz" for c in S[1 :]if c!="C"]),])else "WA") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; execute (if (Sequence{S->hasPrefix("A")}->union(Sequence{(S.subrange(2+1, -1)->select(c | c = "C")->collect(c | (c)))->size() = 1}->union(Sequence{ (S->tail()->select(c | c /= "C")->collect(c | (("abcdefghijklmnopqrstuvwxyz")->characters()->includes(c))))->forAll( _x | _x = true ) })))->forAll( _x | _x = true ) then "AC" else "WA" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() flg=0 if s[0]!="A" : print("WA") elif s[2 :-1].count("C")!=1 : print("WA") else : index=s.find("C") all_ind=[i for i in range(1,len(s))] all_ind.remove(index) for i in all_ind : if s[i].isupper(): flg=1 print("WA") break if flg==0 : print("AC") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var flg : int := 0 ; if s->first() /= "A" then ( execute ("WA")->display() ) else (if s.subrange(2+1, -1)->count("C") /= 1 then ( execute ("WA")->display() ) else ( var index : int := s->indexOf("C") - 1 ; var all_ind : Sequence := Integer.subrange(1, (s)->size()-1)->select(i | true)->collect(i | (i)) ; execute ((index) /: all_ind) ; for i : all_ind do ( if s[i+1]->matches("[A-Z ]*") then ( flg := 1 ; execute ("WA")->display() ; break ) else skip) ; if flg = 0 then ( execute ("AC")->display() ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() x=len(s) d='abcdefghijklmnopqrstuvwxyz' sum=0 count=0 ans='WA' if s[0]=='A' : for i in range(2,x-1): if s[i]=='C' : sum+=1 if sum==1 : for i in range(1,x): for j in range(26): if s[i]==d[j]: count+=1 if count==x-2 : ans='AC' print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var x : int := (s)->size() ; var d : String := 'abcdefghijklmnopqrstuvwxyz' ; var sum : int := 0 ; var count : int := 0 ; var ans : String := 'WA' ; if s->first() = 'A' then ( for i : Integer.subrange(2, x - 1-1) do ( if s[i+1] = 'C' then ( sum := sum + 1 ) else skip) ; if sum = 1 then ( for i : Integer.subrange(1, x-1) do ( for j : Integer.subrange(0, 26-1) do ( if s[i+1] = d[j+1] then ( count := count + 1 ) else skip)) ; if count = x - 2 then ( ans := 'AC' ) else skip ) else skip ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def modularInverse(n,prime): dp=[0]*(n+1) dp[0]=dp[1]=1 for i in range(2,n+1): dp[i]=dp[prime % i]*(prime-prime//i)% prime for i in range(1,n+1): print(dp[i],end=" ") n=10 prime=17 modularInverse(n,prime) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 10 ; prime := 17 ; modularInverse(n, prime); operation modularInverse(n : OclAny, prime : OclAny) pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; dp->first() := 1; var dp[1+1] : int := 1 ; for i : Integer.subrange(2, n + 1-1) do ( dp[i+1] := dp[prime mod i+1] * (prime - prime div i) mod prime) ; for i : Integer.subrange(1, n + 1-1) do ( execute (dp[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=0x7ffffff N,K=map(int,input().split()) k,f=[INF]*(N+1),[0]*(N+1) a=[0]+[int(input())for i in range(N)] ans=0 for i in range(N,0,-1): re=a[i] if re : if f[i]==0 : v=0 ; ans+=1 else : v=k[i] if vv : k[re]=v f[re]=1 ; else : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INF : int := 0x7ffffff ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : OclAny := null; var f : OclAny := null; Sequence{k,f} := Sequence{MatrixLib.elementwiseMult(Sequence{ INF }, (N + 1)),MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1))} ; var a : Sequence := Sequence{ 0 }->union(Integer.subrange(0, N-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))) ; var ans : int := 0 ; for i : Integer.subrange(0 + 1, N)->reverse() do ( var re : OclAny := a[i+1] ; if re then ( if f[i+1] = 0 then ( var v : int := 0; ans := ans + 1 ) else ( v := k[i+1] ; if (v->compareTo(K)) < 0 then ( ans := ans + 1 ) else skip ) ; v := v + 1 ; if (v->compareTo(K)) < 0 & (k[re+1]->compareTo(v)) > 0 then ( k[re+1] := v ) else skip ; f[re+1] := 1; ) else ( ans := ans + 1 )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findEle(arr,n): sum=0 for i in range(n): sum+=arr[i] for i in range(n): if arr[i]==sum-arr[i]: return arr[i] return-1 if __name__=="__main__" : arr=[1,2,3,6] n=len(arr) print(findEle(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 6 }))) ; n := (arr)->size() ; execute (findEle(arr, n))->display() ) else skip; operation findEle(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + arr[i+1]) ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] = sum - arr[i+1] then ( return arr[i+1] ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline N,K=map(int,readline().split()) a=[int(readline())-1 for _ in[0]*N] result=a.count(-1) nodes=set() node_add=nodes.add hoge=set() hoge_add=hoge.add for i in range(N): if a[i]in hoge : node_add(a[i]) hoge_add(a[i]) visited=set() add=visited.add startnode={v : K-1 for v in{i for i in range(N)if a[i]>-1}-set(a)} while startnode : nextnode=dict() for v,l in startnode.items(): result+=(v not in visited) add(v) v=a[v] while a[v]>-1 and v not in nodes and l>0 : if v not in visited : result+=1 add(v) l-=1 v=a[v] if a[v]>-1 and v in nodes and l>0 : nextnode[v]=max(nextnode.get(v,0),l-1) startnode=nextnode print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N)->select(_anon | true)->collect(_anon | (("" + ((readline())))->toInteger() - 1)) ; var result : int := a->count(-1) ; var nodes : Set := Set{}->union(()) ; var node_add : OclAny := nodes.add ; var hoge : Set := Set{}->union(()) ; var hoge_add : OclAny := hoge.add ; for i : Integer.subrange(0, N-1) do ( if (hoge)->includes(a[i+1]) then ( node_add(a[i+1]) ) else skip ; hoge_add(a[i+1])) ; var visited : Set := Set{}->union(()) ; var add : OclAny := visited.add ; var startnode : Map := Integer.subrange(0, N-1)->select(i | a[i+1] > -1)->collect(i | i)->asSet() - Set{}->union((a))->select(v | true)->collect(v | Map{v |-> K - 1})->unionAll() ; while startnode do ( var nextnode : Map := (arguments ( )) ; for _tuple : startnode->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var l : OclAny := _tuple->at(_indx); result := result + ((visited)->excludes(v)) ; add(v) ; var v : OclAny := a[v+1] ; while a[v+1] > -1 & (nodes)->excludes(v) & l > 0 do ( if (visited)->excludes(v) then ( result := result + 1 ; add(v) ) else skip ; l := l - 1 ; v := a[v+1]) ; if a[v+1] > -1 & (nodes)->includes(v) & l > 0 then ( nextnode[v+1] := Set{nextnode.get(v, 0), l - 1}->max() ) else skip) ; startnode := nextnode) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def main(): H,N=map(int,input().split()) AB=[[int(i)for i in input().split()]for _ in range(N)] dp=[float("inf")]*(H+1) dp[H]=0 for i in range(H,-1,-1): for j in range(N): tmp=max(0,i-AB[j][0]) dp[tmp]=min(dp[tmp],dp[i]+AB[j][1]) print(dp[0]) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var H : OclAny := null; var N : OclAny := null; Sequence{H,N} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var AB : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())))) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (("inf")))->toReal() }, (H + 1)) ; dp[H+1] := 0 ; for i : Integer.subrange(-1 + 1, H)->reverse() do ( for j : Integer.subrange(0, N-1) do ( var tmp : OclAny := Set{0, i - AB[j+1]->first()}->max() ; dp[tmp+1] := Set{dp[tmp+1], dp[i+1] + AB[j+1][1+1]}->min())) ; execute (dp->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,N=[int(zz)for zz in input().split()] mahou=[[int(zz)for zz in input().split()]for _ in range(N)] dmg=[i[0]for i in mahou] mp=[i[1]for i in mahou] dp=[[0]*(H+1)for _ in range(N)] for j in range(1,H+1): if j<=dmg[0]: dp[0][j]=mp[0] else : dp[0][j]=dp[0][j-dmg[0]]+mp[0] for i in range(1,N): for j in range(1,H+1): if j<=dmg[i]: dp[i][j]=min(mp[i],dp[i-1][j]) else : dp[i][j]=min(dp[i][j-dmg[i]]+mp[i],dp[i-1][j]) print(dp[-1][-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var N : OclAny := null; Sequence{H,N} := input().split()->select(zz | true)->collect(zz | (("" + ((zz)))->toInteger())) ; var mahou : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (input().split()->select(zz | true)->collect(zz | (("" + ((zz)))->toInteger())))) ; var dmg : Sequence := mahou->select(i | true)->collect(i | (i->first())) ; var mp : Sequence := mahou->select(i | true)->collect(i | (i[1+1])) ; var dp : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (H + 1)))) ; for j : Integer.subrange(1, H + 1-1) do ( if (j->compareTo(dmg->first())) <= 0 then ( dp->first()[j+1] := mp->first() ) else ( dp->first()[j+1] := dp->first()[j - dmg->first()+1] + mp->first() )) ; for i : Integer.subrange(1, N-1) do ( for j : Integer.subrange(1, H + 1-1) do ( if (j->compareTo(dmg[i+1])) <= 0 then ( dp[i+1][j+1] := Set{mp[i+1], dp[i - 1+1][j+1]}->min() ) else ( dp[i+1][j+1] := Set{dp[i+1][j - dmg[i+1]+1] + mp[i+1], dp[i - 1+1][j+1]}->min() ))) ; execute (dp->last()->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin mod=1000000007 inf=1<<60 ni=lambda : int(ns()) na=lambda : list(map(int,stdin.readline().split())) ns=lambda : stdin.readline().rstrip() nas=lambda : stdin.readline().split() h,n=na() ab=[na()for i in range(n)] max_a=max([ab[i][0]for i in range(n)]) dp=[inf]*(h+max_a) dp[0]=0 for i in range(n): for j in range(h): a,b=ab[i] m=min(j+a,h) dp[m]=min(dp[m],dp[j]+b) print(dp[h]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stdin : OclFile := OclFile["System.in"] ; var mod : int := 1000000007 ; var Math_PINFINITY : int := 1 * (2->pow(60)) ; var ni : Function := lambda $$ : OclAny in (("" + ((ns())))->toInteger()) ; var na : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ns : Function := lambda $$ : OclAny in (stdin.readLine().rstrip()) ; var nas : Function := lambda $$ : OclAny in (stdin.readLine().split()) ; var h : OclAny := null; var n : OclAny := null; Sequence{h,n} := na->apply() ; var ab : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (na->apply())) ; var max_a : OclAny := (Integer.subrange(0, n-1)->select(i | true)->collect(i | (ab[i+1]->first())))->max() ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ Math_PINFINITY }, (h + max_a)) ; dp->first() := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, h-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ab[i+1] ; var m : OclAny := Set{j + a, h}->min() ; dp[m+1] := Set{dp[m+1], dp[j+1] + b}->min())) ; execute (dp[h+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=list(map(int,input().split())) B=list(map(int,input().split())) A.remove(0) B.remove(0) ind_b=B.index(A[0]) R=B[ind_b :]+B[0 : ind_b] if A==R : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var B : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((0) /: A) ; execute ((0) /: B) ; var ind_b : int := B->indexOf(A->first()) - 1 ; var R : OclAny := B.subrange(ind_b+1) + B.subrange(0+1, ind_b) ; if A = R then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from bisect import bisect_left from bisect import bisect_right import collections import copy import heapq from collections import defaultdict from heapq import heappop,heappush import itertools input=sys.stdin.readline def inputInt(): return int(input()) def inputMap(): return map(int,input().split()) def inputList(): return list(map(int,input().split())) def main(): H,N=inputMap() AB=[] for i in range(N): A,B=inputMap() AB.append((A,B)) DP=[float('inf')for i in range(H+1)] DP[-1]=0 for i in range(H,-1,-1): for j,val in enumerate(AB): A,B=val tukatta_MP=DP[i] tugi=i-A if tugi<0 : tugi=0 tmp=tukatta_MP+B if tmptoInteger(); operation inputMap() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation inputList() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation main() pre: true post: true activity: var H : OclAny := null; var N : OclAny := null; Sequence{H,N} := inputMap() ; var AB : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := inputMap() ; execute ((Sequence{A, B}) : AB)) ; var DP : Sequence := Integer.subrange(0, H + 1-1)->select(i | true)->collect(i | (("" + (('inf')))->toReal())) ; DP->last() := 0 ; for i : Integer.subrange(-1 + 1, H)->reverse() do ( for _tuple : Integer.subrange(1, (AB)->size())->collect( _indx | Sequence{_indx-1, (AB)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var val : OclAny := _tuple->at(_indx); var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := val ; var tukatta_MP : OclAny := DP[i+1] ; var tugi : double := i - A ; if tugi < 0 then ( tugi := 0 ) else skip ; var tmp : OclAny := tukatta_MP + B ; if (tmp->compareTo(DP[tugi+1])) < 0 then ( DP[tugi+1] := tmp ) else skip)) ; execute (DP->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,n=map(int,input().split()) A,B=[],[] for _ in range(n): a,b=map(int,input().split()) A.append(a) B.append(b) dp=[1000000000]*(H+max(A)+1) dp[0]=0 for n in range(H+1): for a,b in zip(A,B): dp[n+a]=min(dp[n+a],dp[n]+b) print(min(dp[H :])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var n : OclAny := null; Sequence{H,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := Sequence{Sequence{},Sequence{}} ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a) : A) ; execute ((b) : B)) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 1000000000 }, (H + (A)->max() + 1)) ; dp->first() := 0 ; for n : Integer.subrange(0, H + 1-1) do ( for _tuple : Integer.subrange(1, A->size())->collect( _indx | Sequence{A->at(_indx), B->at(_indx)} ) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); dp[n + a+1] := Set{dp[n + a+1], dp[n+1] + b}->min())) ; execute ((dp.subrange(H+1))->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumofseries(n): return int(n*(n+1)*(n+2)*(n+3)/4) print(sumofseries(3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (sumofseries(3))->display(); operation sumofseries(n : OclAny) : OclAny pre: true post: true activity: return ("" + ((n * (n + 1) * (n + 2) * (n + 3) / 4)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def preProcess(n): preProcessedCubes=list() for i in range(1,mt.ceil(n**(1./3.))): iThCube=i**3 cubeString=str(iThCube) preProcessedCubes.append(cubeString) return preProcessedCubes def findLargestCubeUtil(num,preProcessedCubes): preProcessedCubes=preProcessedCubes[: :-1] totalCubes=len(preProcessedCubes) for i in range(totalCubes): currCube=preProcessedCubes[i] digitsInCube=len(currCube) index=0 digitsInNumber=len(num) for j in range(digitsInNumber): if(num[j]==currCube[index]): index+=1 if(digitsInCube==index): return currCube return "Not Possible" def findLargestCube(n): preProcessedCubes=preProcess(n) num=str(n) ans=findLargestCubeUtil(num,preProcessedCubes) print("Largest Cube that can be formed from",n,"is",ans) n=4125 findLargestCube(n) n=876 findLargestCube(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; n := 4125 ; findLargestCube(n) ; n := 876 ; findLargestCube(n); operation preProcess(n : OclAny) : OclAny pre: true post: true activity: var preProcessedCubes : Sequence := () ; for i : Integer.subrange(1, mt.ceil((n)->pow((1. / 3.)))-1) do ( var iThCube : double := (i)->pow(3) ; var cubeString : String := ("" + ((iThCube))) ; execute ((cubeString) : preProcessedCubes)) ; return preProcessedCubes; operation findLargestCubeUtil(num : OclAny, preProcessedCubes : OclAny) : OclAny pre: true post: true activity: preProcessedCubes := preProcessedCubes(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var totalCubes : int := (preProcessedCubes)->size() ; for i : Integer.subrange(0, totalCubes-1) do ( var currCube : OclAny := preProcessedCubes[i+1] ; var digitsInCube : int := (currCube)->size() ; var index : int := 0 ; var digitsInNumber : int := (num)->size() ; for j : Integer.subrange(0, digitsInNumber-1) do ( if (num[j+1] = currCube[index+1]) then ( index := index + 1 ) else skip ; if (digitsInCube = index) then ( return currCube ) else skip)) ; return "Not Possible"; operation findLargestCube(n : OclAny) pre: true post: true activity: preProcessedCubes := preProcess(n) ; num := ("" + ((n))) ; var ans : OclAny := findLargestCubeUtil(num, preProcessedCubes) ; execute ("Largest Cube that can be formed from")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def small(x,y): m=str(x) for i in range(0,10): res=int(str(m)+str(i)) if res % y==0 : return str(i) if res % y!=0 and i==9 : return False a,b,n=map(int,input().split()) if small(a,b)==False : print(-1) else : print(str(a)+small(a,b)+(n-1)*'0') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; var n : OclAny := null; Sequence{a,b,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if small(a, b) = false then ( execute (-1)->display() ) else ( execute (("" + ((a))) + small(a, b) + (n - 1) * '0')->display() ); operation small(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var m : String := ("" + ((x))) ; for i : Integer.subrange(0, 10-1) do ( var res : int := ("" + ((("" + ((m))) + ("" + ((i))))))->toInteger() ; if res mod y = 0 then ( return ("" + ((i))) ) else skip ; if res mod y /= 0 & i = 9 then ( return false ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findExtraCharacter(strA,strB): m1={} for i in strB : if i in m1 : m1[i]+=1 else : m1[i]=1 for i in strA : m1[i]-=1 for h1 in m1 : if m1[h1]==1 : return h1 if __name__=="__main__" : strA='abcd' strB='cbdad' print(findExtraCharacter(strA,strB)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( strA := 'abcd' ; strB := 'cbdad' ; execute (findExtraCharacter(strA, strB))->display() ) else skip; operation findExtraCharacter(strA : OclAny, strB : OclAny) : OclAny pre: true post: true activity: var m1 : OclAny := Set{} ; for i : strB do ( if (m1)->includes(i) then ( m1[i+1] := m1[i+1] + 1 ) else ( m1[i+1] := 1 )) ; for i : strA do ( m1[i+1] := m1[i+1] - 1) ; for h1 : m1 do ( if m1[h1+1] = 1 then ( return h1 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- li=[int(x)for x in input().split()] a=li[0] b=li[1] n=li[2] if a % b==0 : s2=str(a) s3="0"*n s2+=s3 print(s2) else : s=str(a) ans=-True j=0 while(jselect(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a : OclAny := li->first() ; var b : OclAny := li[1+1] ; var n : OclAny := li[2+1] ; if a mod b = 0 then ( var s2 : String := ("" + ((a))) ; var s3 : String := StringLib.nCopies("0", n) ; s2 := s2 + s3 ; execute (s2)->display() ) else ( var s : String := ("" + ((a))) ; var ans : boolean := -true ; var j : int := 0 ; while ((j->compareTo(n)) < 0) do ( for i : Integer.subrange(0, 10-1) do ( s := s + ("" + ((i))) ; if ("" + ((s)))->toInteger() mod b = 0 then ( ans := true ; var s4 : String := StringLib.nCopies("0", (n - (j + 1))) ; s := s + ("" + ((s4))) ; j := n ; break ) else ( var l : int := (s)->size() ; s := s.subrange(1,l - 1) ; ans := false )) ; j := j + 1) ; if ans = true then ( execute (("" + ((s)))->toInteger())->display() ) else ( execute (-1)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,n=map(int,input().split()) num=a flag=0 ans=str(a) for i in range(n): if num % b==0 : ans+="0" else : ost=(num*10)% b if ost==0 : ans+=str(0) elif(b-ost)>9 : print(-1) flag=1 break else : ans+=str(b-ost) num=0 if flag==0 : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var n : OclAny := null; Sequence{a,b,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var num : OclAny := a ; var flag : int := 0 ; var ans : String := ("" + ((a))) ; for i : Integer.subrange(0, n-1) do ( if num mod b = 0 then ( ans := ans + "0" ) else ( var ost : int := (num * 10) mod b ; if ost = 0 then ( ans := ans + ("" + ((0))) ) else (if (b - ost) > 9 then ( execute (-1)->display() ; flag := 1 ; break ) else ( ans := ans + ("" + ((b - ost))) ) ) ) ; num := 0) ; if flag = 0 then ( execute (ans)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,n=map(int,input().split()) a=a*10+9 rem=a % b if rem<=9 : a-=rem else : print(-1) quit() n-=1 print(str(a)+"0"*n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var n : OclAny := null; Sequence{a,b,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : double := a * 10 + 9 ; var rem : int := a mod b ; if rem <= 9 then ( a := a - rem ) else ( execute (-1)->display() ; quit() ) ; n := n - 1 ; execute (("" + ((a))) + StringLib.nCopies("0", n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(a,b,n): f=False c=0 for i in range(10): if int(str(a)+str(i))% b==0 : f=True c=i break if not f : return-1 return str(a)+str(c)+'0'*(n-1) a,b,n=[int(i)for i in input().split()] print(solve(a,b,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{a,b,n} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute (solve(a, b, n))->display(); operation solve(a : OclAny, b : OclAny, n : OclAny) : OclAny pre: true post: true activity: var f : boolean := false ; var c : int := 0 ; for i : Integer.subrange(0, 10-1) do ( if ("" + ((("" + ((a))) + ("" + ((i))))))->toInteger() mod b = 0 then ( f := true ; c := i ; break ) else skip) ; if not(f) then ( return -1 ) else skip ; return ("" + ((a))) + ("" + ((c))) + StringLib.nCopies('0', (n - 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def solve_cos(star,telescope): inner=sum([i*j for i,j in zip(star,telescope)]) dis_star=(sum(map(lambda a : a*a,star)))**(1/2) dis_telescope=(sum(map(lambda a : a*a,telescope)))**(1/2) return inner/(dis_star*dis_telescope) while True : n=int(input()) if n==0 : break stars=[list(map(float,input().split()))for i in range(n)] m=int(input()) telescopes=[list(map(float,input().split()))for i in range(m)] count=0 for star in stars : for telescope in telescopes : cos1=solve_cos(star,telescope[:-1]) cos2=math.cos(telescope[-1]) if cos2<=cos1 : count+=1 break print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var stars : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["double"])->apply(_x) )))) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var telescopes : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["double"])->apply(_x) )))) ; var count : int := 0 ; for star : stars do ( for telescope : telescopes do ( var cos1 : OclAny := solve_cos(star, telescope->front()) ; var cos2 : OclAny := ; if (cos2->compareTo(cos1)) <= 0 then ( count := count + 1 ; break ) else skip)) ; execute (count)->display()); operation solve_cos(star : OclAny, telescope : OclAny) : OclAny pre: true post: true activity: var inner : OclAny := (Integer.subrange(1, star->size())->collect( _indx | Sequence{star->at(_indx), telescope->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let j : OclAny = _tuple->at(2) in (i * j)))->sum() ; var dis_star : double := ((((star)->collect( _x | (lambda a : OclAny in (a * a))->apply(_x) ))->sum()))->pow((1 / 2)) ; var dis_telescope : double := ((((telescope)->collect( _x | (lambda a : OclAny in (a * a))->apply(_x) ))->sum()))->pow((1 / 2)) ; return inner / (dis_star * dis_telescope); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() f=lambda :(''+input()).replace(' 0','') a,b=f(),f() print('YES' if a in b+b else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var f : Function := lambda $$ : OclAny in (('' + (OclFile["System.in"]).readLine()).replace(' 0', '')) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{f->apply(),f->apply()} ; execute (if (b + b)->includes(a) then 'YES' else 'NO' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math while True : n=int(input()) if not n : break stars=[list(map(float,input().split()))for i in range(n)] is_watch_star=[False for i in range(n)] scope=[list(map(float,input().split()))for j in range(int(input()))] for i in scope : a=(i[0]**2+i[1]**2+i[2]**2)**0.5 for j in range(len(stars)): star=stars[j] b=(star[0]**2+star[1]**2+star[2]**2)**0.5 if math.cos(i[3])*a*btoInteger() ; if not(n) then ( break ) else skip ; var stars : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["double"])->apply(_x) )))) ; var is_watch_star : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (false)) ; var scope : Sequence := Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1)->select(j | true)->collect(j | (((input().split())->collect( _x | (OclType["double"])->apply(_x) )))) ; for i : scope do ( var a : double := (((i->first())->pow(2) + (i[1+1])->pow(2) + (i[2+1])->pow(2)))->pow(0.5) ; for j : Integer.subrange(0, (stars)->size()-1) do ( var star : OclAny := stars[j+1] ; var b : double := (((star->first())->pow(2) + (star[1+1])->pow(2) + (star[2+1])->pow(2)))->pow(0.5) ; if ( * a * b->compareTo(i->first() * star->first() + i[1+1] * star[1+1] + i[2+1] * star[2+1])) < 0 then ( is_watch_star[j+1] := true ) else skip)) ; execute ((((is_watch_star)->select( _x | (lambda x : OclAny in (x))->apply(_x) = true )))->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,ceil def decToOctal(n): octalNum=[0]*100 ; i=0 ; while(n!=0): octalNum[i]=n % 8 ; n=n//8 ; i+=1 ; for j in range(i-1,-1,-1): print(octalNum[j],end=""); print(); def nDigitPerfectSquares(n): decimal=pow(ceil(sqrt(pow(8,n)))-1,2); decToOctal(decimal); if __name__=="__main__" : n=2 ; nDigitPerfectSquares(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( n := 2; ; nDigitPerfectSquares(n); ) else skip; operation decToOctal(n : OclAny) pre: true post: true activity: var octalNum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100); ; var i : int := 0; ; while (n /= 0) do ( octalNum[i+1] := n mod 8; ; n := n div 8; ; i := i + 1;) ; for j : Integer.subrange(-1 + 1, i - 1)->reverse() do ( execute (octalNum[j+1])->display();) ; execute (->display();; operation nDigitPerfectSquares(n : OclAny) pre: true post: true activity: var decimal : double := (ceil(sqrt((8)->pow(n))) - 1)->pow(2); ; decToOctal(decimal);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : ax,ay=5,0 bx,by=1,1 cx,cy=2,5 print(ax+cx-bx,",",ay+cy-by) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var ax : OclAny := null; var ay : OclAny := null; Sequence{ax,ay} := Sequence{5,0} ; var bx : OclAny := null; var by : OclAny := null; Sequence{bx,by} := Sequence{1,1} ; var cx : OclAny := null; var cy : OclAny := null; Sequence{cx,cy} := Sequence{2,5} ; execute (ax + cx - bx)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y,z,t,r,s=map(int,input().split()) d=abs(x-y) print('YNEOS'[d*t<(abs(x-z)+d)*r+3*s : : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; var t : OclAny := null; var r : OclAny := null; var s : OclAny := null; Sequence{x,y,z,t,r,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : double := (x - y)->abs() ; execute ('YNEOS'(subscript (test (logical_test (comparison (comparison (expr (expr (atom (name d))) * (expr (atom (name t))))) < (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (name z))))))))) )))) + (expr (atom (name d)))))))) ))) * (expr (atom (name r)))) + (expr (expr (atom (number (integer 3)))) * (expr (atom (name s))))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : balls=int(input()) ans=0 if balls==0 : break for cs in range(54): for ts in range(96): if pow(cs,3)<=balls : ans=max(ans,pow(cs,3)) if ts*(ts+1)*(ts+2)//6<=balls : ans=max(ans,ts*(ts+1)*(ts+2)//6) if pow(cs,3)+ts*(ts+1)*(ts+2)//6<=balls : ans=max(ans,pow(cs,3)+ts*(ts+1)*(ts+2)//6) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var balls : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; if balls = 0 then ( break ) else skip ; for cs : Integer.subrange(0, 54-1) do ( for ts : Integer.subrange(0, 96-1) do ( if ((cs)->pow(3)->compareTo(balls)) <= 0 then ( ans := Set{ans, (cs)->pow(3)}->max() ) else skip ; if (ts * (ts + 1) * (ts + 2) div 6->compareTo(balls)) <= 0 then ( ans := Set{ans, ts * (ts + 1) * (ts + 2) div 6}->max() ) else skip ; if ((cs)->pow(3) + ts * (ts + 1) * (ts + 2) div 6->compareTo(balls)) <= 0 then ( ans := Set{ans, (cs)->pow(3) + ts * (ts + 1) * (ts + 2) div 6}->max() ) else skip)) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y,z,t1,t2,t3=map(int,input().split()) lift_time=t3*3+abs(z-x)*t2+abs(y-x)*t2 les_time=abs(y-x)*t1 if lift_time>les_time : print('NO') else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; var t1 : OclAny := null; var t2 : OclAny := null; var t3 : OclAny := null; Sequence{x,y,z,t1,t2,t3} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lift_time : double := t3 * 3 + (z - x)->abs() * t2 + (y - x)->abs() * t2 ; var les_time : double := (y - x)->abs() * t1 ; if (lift_time->compareTo(les_time)) > 0 then ( execute ('NO')->display() ) else ( execute ('YES')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while(True): x,y,z,t1,t2,t3=map(int,input().split(" ")) ele=(abs(x-z)*t2)+2*t3+(abs(x-y)*t2)+t3 strn=abs(x-y)*t1 if(ele>strn): print("No") break ; else : print("Yes") break ; ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while (true) do ( var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; var t1 : OclAny := null; var t2 : OclAny := null; var t3 : OclAny := null; Sequence{x,y,z,t1,t2,t3} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var ele : double := ((x - z)->abs() * t2) + 2 * t3 + ((x - y)->abs() * t2) + t3 ; var strn : double := (x - y)->abs() * t1 ; if ((ele->compareTo(strn)) > 0) then ( execute ("No")->display() ; break; ) else ( execute ("Yes")->display() ; break; )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (x,y,z,t1,t2,t3)=map(int,input().split(' ')) total_time_if_use_elevator=(abs(z-x)+abs(y-x))*t2+t3*3 total_time_if_use_stairs=abs(y-x)*t1 if total_time_if_use_elevator<=total_time_if_use_stairs : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{x, y, z, t1, t2, t3} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var total_time_if_use_elevator : double := ((z - x)->abs() + (y - x)->abs()) * t2 + t3 * 3 ; var total_time_if_use_stairs : double := (y - x)->abs() * t1 ; if (total_time_if_use_elevator->compareTo(total_time_if_use_stairs)) <= 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y,z,t,r,s=map(int,input().split()) d=abs(x-y) print('YNEOS'[d*t<(abs(x-z)+d)*r+3*s : : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; var t : OclAny := null; var r : OclAny := null; var s : OclAny := null; Sequence{x,y,z,t,r,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : double := (x - y)->abs() ; execute ('YNEOS'(subscript (test (logical_test (comparison (comparison (expr (expr (atom (name d))) * (expr (atom (name t))))) < (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (name z))))))))) )))) + (expr (atom (name d)))))))) ))) * (expr (atom (name r)))) + (expr (expr (atom (number (integer 3)))) * (expr (atom (name s))))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break p=list(map(int,input().split()))+[-1] ans,s=[],p[0] for i in range(1,n+1): if p[i]!=p[i-1]+1 : if s==p[i-1]: ans.append(str(s)) else : ans.append(str(s)+'-'+str(p[i-1])) s=p[i] print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->union(Sequence{ -1 }) ; var ans : OclAny := null; var s : OclAny := null; Sequence{ans,s} := Sequence{Sequence{},p->first()} ; for i : Integer.subrange(1, n + 1-1) do ( if p[i+1] /= p[i - 1+1] + 1 then ( if s = p[i - 1+1] then ( execute ((("" + ((s)))) : ans) ) else ( execute ((("" + ((s))) + '-' + ("" + ((p[i - 1+1])))) : ans) ) ; var s : OclAny := p[i+1] ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break line=list(map(int,input().split())) i=0 while itoInteger() ; if n = 0 then ( break ) else skip ; var line : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( var j : int := i ; while (j + 1->compareTo(n)) < 0 & line[j + 1+1] - line[j+1] = 1 do ( j := j + 1) ; var s : String := if n - 1 = j then "\n" else " " endif ; if i = j then ( execute (StringLib.format("%d%s",Sequence{line[i+1], s}))->display() ; i := i + 1 ) else ( execute (StringLib.format("%d-%d%s",Sequence{line[i+1], line[j+1], s}))->display() ; i := j + 1 ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,m,a): for x2 in xrange(0,n+1): for y1 in xrange(0,m+1): b=a+x2*y1 for x1 in xrange(1,n+1): if b % x1==0 and b//x1<=m : return "%d %d %d %d %d %d" %(0,0,x1,y1,x2,b//x1) return "IMPOSSIBLE" for c in range(input()): n,m,a=map(int,raw_input().split()) print("Case #%d: %s" %(c+1,solve(n,m,a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for c : Integer.subrange(0, (OclFile["System.in"]).readLine()-1) do ( Sequence{n,m,a} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (StringLib.format("Case #%d: %s",Sequence{c + 1, solve(n, m, a)}))->display()); operation solve(n : OclAny, m : OclAny, a : OclAny) : OclAny pre: true post: true activity: for x2 : xrange(0, n + 1) do ( for y1 : xrange(0, m + 1) do ( var b : OclAny := a + x2 * y1 ; for x1 : xrange(1, n + 1) do ( if b mod x1 = 0 & (b div x1->compareTo(m)) <= 0 then ( return StringLib.format("%d %d %d %d %d %d",Sequence{0, 0, x1, y1, x2, b div x1}) ) else skip))) ; return "IMPOSSIBLE"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s1=list(input().strip().split()) s2=list(input().strip().split()) s1.remove('0') s2.remove('0') s1=''.join(s1) s2=''.join(s2) s1=s1+s1 if s2 in s1 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s1 : Sequence := (input()->trim().split()) ; var s2 : Sequence := (input()->trim().split()) ; execute (('0') /: s1) ; execute (('0') /: s2) ; s1 := StringLib.sumStringsWithSeparator((s1), '') ; s2 := StringLib.sumStringsWithSeparator((s2), '') ; s1 := s1->union(s1) ; if (s1)->includes(s2) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break pages=list(map(int,input().split())) ans="" while pages : for i in range(len(pages)-1): if pages[i+1]-pages[i]!=1 : s=pages[: i+1] if i==0 : ans+=" "+str(s[0]) else : ans+=" "+str(s[0])+"-"+str(s[-1]) pages=pages[i+1 :] break else : if len(pages)==1 : ans+=" "+str(pages[0]) else : ans+=" "+str(pages[0])+"-"+str(pages[-1]) break print(ans.strip()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var pages : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : String := "" ; while pages do ((compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name pages)))))))) )))) - (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name pages)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))) - (expr (atom (name pages)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))) != (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name pages)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name i)))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom " ")) + (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (expr (expr (atom " ")) + (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))) + (expr (atom "-"))) + (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))))) ))))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name pages)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name pages)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))) :)) ])))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name pages)))))))) ))))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom " ")) + (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name pages)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (expr (expr (atom " ")) + (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name pages)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))) + (expr (atom "-"))) + (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name pages)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))))) ))))))))))))))))) (stmt (simple_stmt (small_stmt break))))))) ; execute (ans->trim())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find_array(a,n): x=0 ; for i in range(n): a[i]+=x ; print(a[i],end=' '); x=max(x,a[i]); if __name__=="__main__" : a=[40,12,62]; n=len(a); find_array(a,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{40}->union(Sequence{12}->union(Sequence{ 62 })); ; n := (a)->size(); ; find_array(a, n); ) else skip; operation find_array(a : OclAny, n : OclAny) pre: true post: true activity: var x : int := 0; ; for i : Integer.subrange(0, n-1) do ( a[i+1] := a[i+1] + x; ; execute (a[i+1])->display(); ; x := Set{x, a[i+1]}->max();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cube=[] tetrahedral=[] def solve(n): min=0 diff_min=pow(10,6) for i in cube : for j in tetrahedral : sum_value=i+j now_diff=n-sum_value if now_diff=0 : diff_min=now_diff min=sum_value return min if __name__=='__main__' : for i in range(0,55): cube.append(i**3) for i in range(0,97): tetrahedral.append(i*(i+1)*(i+2)//6) ans=[] while(True): n=int(input()) if n==0 : break ans.append(solve(n)) print(*ans,sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cube : Sequence := Sequence{} ; var tetrahedral : Sequence := Sequence{} ; skip ; if __name__ = '__main__' then ( for i : Integer.subrange(0, 55-1) do ( execute (((i)->pow(3)) : cube)) ; for i : Integer.subrange(0, 97-1) do ( execute ((i * (i + 1) * (i + 2) div 6) : tetrahedral)) ; var ans : Sequence := Sequence{} ; while (true) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; execute ((solve(n)) : ans)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ) else skip; operation solve(n : OclAny) : OclAny pre: true post: true activity: var min : int := 0 ; var diff_min : double := (10)->pow(6) ; for i : cube do ( for j : tetrahedral do ( var sum_value : OclAny := i + j ; var now_diff : double := n - sum_value ; if (now_diff->compareTo(diff_min)) < 0 & now_diff >= 0 then ( diff_min := now_diff ; min := sum_value ) else skip)) ; return min; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1001 prefix=[[0 for i in range(MAX)]for j in range(MAX)] ar=[0 for i in range(MAX)] def cal_prefix(n,arr): for i in range(n): ar[i+1]=arr[i] for i in range(1,1001,1): for j in range(n+1): prefix[i][j]=0 for j in range(1,n+1): if ar[j]<=i : k=1 else : k=0 prefix[i][j]=prefix[i][j-1]+k def ksub(l,r,n,k): lo=1 hi=1000 while(lo+1=k): hi=mid else : lo=mid+1 if(prefix[lo][r]-prefix[lo][l-1]>=k): hi=lo return hi if __name__=='__main__' : arr=[1,4,2,3,5,7,6] n=len(arr) k=4 cal_prefix(n,arr) queries=[[1,n,1],[2,n-2,2],[3,n-1,3]] q=len(queries) for i in range(q): print(ksub(queries[i][0],queries[i][1],n,queries[i][2])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1001 ; var prefix : Sequence := Integer.subrange(0, MAX-1)->select(j | true)->collect(j | (Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)))) ; var ar : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)) ; skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{4}->union(Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{ 6 })))))) ; n := (arr)->size() ; k := 4 ; cal_prefix(n, arr) ; var queries : Sequence := Sequence{Sequence{1}->union(Sequence{n}->union(Sequence{ 1 }))}->union(Sequence{Sequence{2}->union(Sequence{n - 2}->union(Sequence{ 2 }))}->union(Sequence{ Sequence{3}->union(Sequence{n - 1}->union(Sequence{ 3 })) })) ; var q : int := (queries)->size() ; for i : Integer.subrange(0, q-1) do ( execute (ksub(queries[i+1]->first(), queries[i+1][1+1], n, queries[i+1][2+1]))->display()) ) else skip; operation cal_prefix(n : OclAny, arr : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( ar[i + 1+1] := arr[i+1]) ; for i : Integer.subrange(1, 1001-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( for j : Integer.subrange(0, n + 1-1) do ( prefix[i+1][j+1] := 0) ; for j : Integer.subrange(1, n + 1-1) do ( if (ar[j+1]->compareTo(i)) <= 0 then ( var k : int := 1 ) else ( k := 0 ) ; prefix[i+1][j+1] := prefix[i+1][j - 1+1] + k)); operation ksub(l : OclAny, r : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var lo : int := 1 ; var hi : int := 1000 ; while ((lo + 1->compareTo(hi)) < 0) do ( var mid : int := ("" + (((lo + hi) / 2)))->toInteger() ; if ((prefix[mid+1][r+1] - prefix[mid+1][l - 1+1]->compareTo(k)) >= 0) then ( hi := mid ) else ( lo := mid + 1 )) ; if ((prefix[lo+1][r+1] - prefix[lo+1][l - 1+1]->compareTo(k)) >= 0) then ( hi := lo ) else skip ; return hi; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find(n): b=n a=b*(n-1) if a*b>n and a//bcompareTo(n)) > 0 & (a div b->compareTo(n)) < 0 then ( execute (StringLib.interpolateStrings("a={},b={}", Sequence{a, b}))->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left def fibMonaccianSearch(arr,x,n): fibMMm2=0 fibMMm1=1 fibM=fibMMm2+fibMMm1 while(fibM1): i=min(offset+fibMMm2,n-1) if(arr[i]x): fibM=fibMMm2 fibMMm1=fibMMm1-fibMMm2 fibMMm2=fibM-fibMMm1 else : return i if(fibMMm1 and arr[offset+1]==x): return offset+1 ; return-1 arr=[10,22,35,40,45,50,80,82,85,90,100] n=len(arr) x=85 print("Found at index:",fibMonaccianSearch(arr,x,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{10}->union(Sequence{22}->union(Sequence{35}->union(Sequence{40}->union(Sequence{45}->union(Sequence{50}->union(Sequence{80}->union(Sequence{82}->union(Sequence{85}->union(Sequence{90}->union(Sequence{ 100 })))))))))) ; n := (arr)->size() ; x := 85 ; execute ("Found at index:")->display(); operation fibMonaccianSearch(arr : OclAny, x : OclAny, n : OclAny) : OclAny pre: true post: true activity: var fibMMm2 : int := 0 ; var fibMMm1 : int := 1 ; var fibM : int := fibMMm2 + fibMMm1 ; while ((fibM->compareTo(n)) < 0) do ( fibMMm2 := fibMMm1 ; fibMMm1 := fibM ; fibM := fibMMm2 + fibMMm1) ; var offset : int := -1; ; while (fibM > 1) do ( var i : OclAny := Set{offset + fibMMm2, n - 1}->min() ; if ((arr[i+1]->compareTo(x)) < 0) then ( fibM := fibMMm1 ; fibMMm1 := fibMMm2 ; fibMMm2 := fibM - fibMMm1 ; offset := i ) else (if ((arr[i+1]->compareTo(x)) > 0) then ( fibM := fibMMm2 ; fibMMm1 := fibMMm1 - fibMMm2 ; fibMMm2 := fibM - fibMMm1 ) else ( return i ) ) ) ; if (fibMMm1 & arr[offset + 1+1] = x) then ( return offset + 1; ) else skip ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def rank(q): a=q/m*100 if a<50 : return 'noob' elif a<80 : return 'random' elif a<90 : return 'average' elif a<99 : return 'hardcore' else : return 'pro' n=int(input()) d=dict() for _ in range(n): a,b=input()[:-1].split() b=int(b) if d.get(a,0)==0 : d[a]=b else : d[a]=max(d[a],b) m=len(d) s=dict() for i in d : if s.get(d[i],0)==0 : s[d[i]]=[i] else : s[d[i]].append(i) d=sorted([(i,s[i],len(s[i]))for i in s]) e=[] c=0 for x,w,i in d : c+=i r=rank(c) for j in w : e.append((j,r)) print(len(e)) for i in e : print(' '.join(i)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Map := (arguments ( )) ; for _anon : Integer.subrange(0, n-1) do ( var b : OclAny := null; Sequence{a,b} := input()->front().split() ; var b : int := ("" + ((b)))->toInteger() ; if d.get(a, 0) = 0 then ( d[a+1] := b ) else ( d[a+1] := Set{d[a+1], b}->max() )) ; var m : int := (d)->size() ; var s : Map := (arguments ( )) ; for i : d->keys() do ( if s.get(d[i+1], 0) = 0 then ( s[d[i+1]+1] := Sequence{ i } ) else ( (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) )) ; d := s->keys()->select(i | true)->collect(i | (Sequence{i, s[i+1], (s[i+1])->size()}))->sort() ; var e : Sequence := Sequence{} ; var c : int := 0 ; for x, w, i : d->keys() do ( c := c + i ; var r : OclAny := rank(c) ; for j : w do ( execute ((Sequence{j, r}) : e))) ; execute ((e)->size())->display() ; for i : e do ( execute (StringLib.sumStringsWithSeparator((i), ' '))->display()); operation rank(q : OclAny) : OclAny pre: true post: true activity: var a : double := q / m * 100 ; if a < 50 then ( return 'noob' ) else (if a < 80 then ( return 'random' ) else (if a < 90 then ( return 'average' ) else (if a < 99 then ( return 'hardcore' ) else ( return 'pro' ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict R=lambda : map(int,input().split()) n=int(input()) mp=defaultdict(int) for i in range(n): name,sc=input().split() sc=int(sc) mp[name]=max(sc,mp[name]) players=sorted([(k,v)for k,v in mp.items()],key=lambda x : x[1]) print(len(players)) j=0 for i,playerAndScore in enumerate(players): player,score=playerAndScore while jcollect( _x | (OclType["int"])->apply(_x) )) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mp : OclAny := defaultdict(OclType["int"]) ; for i : Integer.subrange(0, n-1) do ( var name : OclAny := null; var sc : OclAny := null; Sequence{name,sc} := input().split() ; var sc : int := ("" + ((sc)))->toInteger() ; mp[name+1] := Set{sc, mp[name+1]}->max()) ; var players : Sequence := mp->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->select(_tuple | true)->collect(_tuple | let k : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in (Sequence{k, v}))->sortedBy($x | (lambda x : OclAny in (x[1+1]))->apply($x)) ; execute ((players)->size())->display() ; var j : int := 0 ; for _tuple : Integer.subrange(1, (players)->size())->collect( _indx | Sequence{_indx-1, (players)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var playerAndScore : OclAny := _tuple->at(_indx); var player : OclAny := null; var score : OclAny := null; Sequence{player,score} := playerAndScore ; while (j->compareTo((players)->size())) < 0 & (players[j+1][1+1]->compareTo(score)) <= 0 do ( j := j + 1) ; if j / (players)->size() < 0.5 then ( execute (StringLib.sumStringsWithSeparator((Sequence{player}->union(Sequence{ 'noob' })), ' '))->display() ) else (if 0.5 <= j / (players)->size() & (j / (players)->size() < 0.8) then ( execute (StringLib.sumStringsWithSeparator((Sequence{player}->union(Sequence{ 'random' })), ' '))->display() ) else (if 0.8 <= j / (players)->size() & (j / (players)->size() < 0.9) then ( execute (StringLib.sumStringsWithSeparator((Sequence{player}->union(Sequence{ 'average' })), ' '))->display() ) else (if 0.9 <= j / (players)->size() & (j / (players)->size() < 0.99) then ( execute (StringLib.sumStringsWithSeparator((Sequence{player}->union(Sequence{ 'hardcore' })), ' '))->display() ) else ( execute (StringLib.sumStringsWithSeparator((Sequence{player}->union(Sequence{ 'pro' })), ' '))->display() ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a={} for i in range(n): s=input().split() if s[0]in a : a[s[0]]=max(int(s[1]),a[s[0]]) else : a[s[0]]=int(s[1]) n=len(a) print(n) for s in a : k=0 for y in a : if a[y]>a[s]: k+=1 if k*2>n : print(s,"noob") elif k*5>n : print(s,"random") elif k*10>n : print(s,"average") elif k*100>n : print(s,"hardcore") else : print(s,"pro") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var s : OclAny := input().split() ; if (a)->includes(s->first()) then ( a[s->first()+1] := Set{("" + ((s[1+1])))->toInteger(), a[s->first()+1]}->max() ) else ( a[s->first()+1] := ("" + ((s[1+1])))->toInteger() )) ; n := (a)->size() ; execute (n)->display() ; for s : a do ( var k : int := 0 ; for y : a do ( if (a[y+1]->compareTo(a[s+1])) > 0 then ( k := k + 1 ) else skip) ; if (k * 2->compareTo(n)) > 0 then ( execute (s)->display() ) else (if (k * 5->compareTo(n)) > 0 then ( execute (s)->display() ) else (if (k * 10->compareTo(n)) > 0 then ( execute (s)->display() ) else (if (k * 100->compareTo(n)) > 0 then ( execute (s)->display() ) else ( execute (s)->display() ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,OrderedDict n=int(input()) u=defaultdict(int) for _ in range(n): name,score=input().split() u[name]=max(u[name],int(score)) scoreToPlayers=defaultdict(list) for pl in u : scoreToPlayers[u[pl]].append(pl) v=OrderedDict(sorted(scoreToPlayers.items())) res=[] before=0 for(i,s)in enumerate(v): perc=(len(v[s])+before)/len(u) r="noob" if 0.5<=perc<0.8 : r="random" elif 0.8<=perc<0.9 : r="average" elif 0.9<=perc<0.99 : r="hardcore" elif 0.99<=perc : r="pro" for name in v[s]: res.append((name,r)) before+=len(v[s]) print(len(res)) for(name,category)in res : print(name,category) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var u : OclAny := defaultdict(OclType["int"]) ; for _anon : Integer.subrange(0, n-1) do ( var name : OclAny := null; var score : OclAny := null; Sequence{name,score} := input().split() ; u[name+1] := Set{u[name+1], ("" + ((score)))->toInteger()}->max()) ; var scoreToPlayers : OclAny := defaultdict(OclType["Sequence"]) ; for pl : u do ((expr (atom (name scoreToPlayers)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name pl)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name pl)))))))) ))))) ; var v : OclAny := (scoreToPlayers->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sort()) ; var res : Sequence := Sequence{} ; var before : int := 0 ; for Sequence{i, s} : Integer.subrange(1, (v)->size())->collect( _indx | Sequence{_indx-1, (v)->at(_indx)} ) do ( var perc : double := ((v[s+1])->size() + before) / (u)->size() ; var r : String := "noob" ; if 0.5 <= perc & (perc < 0.8) then ( r := "random" ) else (if 0.8 <= perc & (perc < 0.9) then ( r := "average" ) else (if 0.9 <= perc & (perc < 0.99) then ( r := "hardcore" ) else (if 0.99 <= perc then ( r := "pro" ) else skip ) ) ) ; for name : v[s+1] do ( execute ((Sequence{name, r}) : res)) ; before := before + (v[s+1])->size()) ; execute ((res)->size())->display() ; for Sequence{name, category} : res do ( execute (name)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxPerimeter(arr): maxi=0 n=len(arr) for i in range(n-2): for j in range(i+1,n-1): for k in range(j+1,n): a=arr[i] b=arr[j] c=arr[k] if(asize() ; for i : Integer.subrange(0, n - 2-1) do ( for j : Integer.subrange(i + 1, n - 1-1) do ( for k : Integer.subrange(j + 1, n-1) do ( var a : OclAny := arr[i+1] ; var b : OclAny := arr[j+1] ; var c : OclAny := arr[k+1] ; if ((a->compareTo(b + c)) < 0 & (b->compareTo(a + c)) < 0 & (c->compareTo(a + b)) < 0) then ( maxi := Set{maxi, a + b + c}->max() ) else skip))) ; if (maxi = 0) then ( return "Triangle formation is not possible" ) else ( return "Maximum Perimeter is: " + ("" + ((maxi))) ); operation main() pre: true post: true activity: var arr1 : Sequence := Sequence{6}->union(Sequence{1}->union(Sequence{6}->union(Sequence{5}->union(Sequence{8}->union(Sequence{ 4 }))))) ; a := maxPerimeter(arr1) ; execute (a)->display() ; var arr2 : Sequence := Sequence{2}->union(Sequence{20}->union(Sequence{7}->union(Sequence{55}->union(Sequence{1}->union(Sequence{33}->union(Sequence{12}->union(Sequence{ 4 }))))))) ; a := maxPerimeter(arr2) ; execute (a)->display() ; var arr3 : Sequence := Sequence{33}->union(Sequence{6}->union(Sequence{20}->union(Sequence{1}->union(Sequence{8}->union(Sequence{12}->union(Sequence{5}->union(Sequence{55}->union(Sequence{4}->union(Sequence{ 9 }))))))))) ; a := maxPerimeter(arr3) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def smallestNumber(n): if(n>=0 and n<=9): return n digits=list() for i in range(9,1,-1): while(n % i==0): digits.append(i) n=n//i if(n!=1): return-1 k=0 while(len(digits)!=0): k=k*10+digits[-1] digits.pop() return k n=100 print(smallestNumber(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 100 ; execute (smallestNumber(n))->display(); operation smallestNumber(n : OclAny) : OclAny pre: true post: true activity: if (n >= 0 & n <= 9) then ( return n ) else skip ; var digits : Sequence := () ; for i : Integer.subrange(1 + 1, 9)->reverse() do ( while (n mod i = 0) do ( execute ((i) : digits) ; n := n div i)) ; if (n /= 1) then ( return -1 ) else skip ; var k : int := 0 ; while ((digits)->size() /= 0) do ( k := k * 10 + digits->last() ; digits := digits->front()) ; return k; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=[int(x)for x in input().split()] c0=0 c1=0 for i in range(n): if arr[i]% 2==1 : c1=c1+1 else : c0=c0+1 if c0==0 or c1==0 : print(0) else : if c1 % 2==0 : print(n-2) else : print(n-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var c0 : int := 0 ; var c1 : int := 0 ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] mod 2 = 1 then ( c1 := c1 + 1 ) else ( c0 := c0 + 1 )) ; if c0 = 0 or c1 = 0 then ( execute (0)->display() ) else ( if c1 mod 2 = 0 then ( execute (n - 2)->display() ) else ( execute (n - 1)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import(division,absolute_import,print_function,unicode_literals) from sys import stdin def solve(L): n=0 sets=set() for y in range(12): for x in range(12): if not L[y][x]: continue elif y and L[y-1][x]: L[y][x]=L[y-1][x] elif x and L[y][x-1]: L[y][x]=L[y][x-1] else : n+=1 sets.add(n) L[y][x]=n for x in range(10,-1,-1): if L[y][x]and L[y][x+1]and L[y][x]!=L[y][x+1]: sets.discard(L[y][x]) L[y][x]=L[y][x+1] return len(sets) s='\n' sep='\n' while s : L=[] for i in range(12): L.append([int(s)for s in stdin.readline().rstrip()]) print(solve(L)) s=stdin.readline() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var s : String := ' ' ; var sep : String := ' ' ; while s do ( L := Sequence{} ; for i : Integer.subrange(0, 12-1) do ( execute ((stdin.readLine().rstrip()->select(s | true)->collect(s | (("" + ((s)))->toInteger()))) : L)) ; execute (solve(L))->display() ; s := stdin.readLine()); operation solve(L : OclAny) : OclAny pre: true post: true activity: var n : int := 0 ; var sets : Set := Set{}->union(()) ; for y : Integer.subrange(0, 12-1) do ( for x : Integer.subrange(0, 12-1) do ( if not(L[y+1][x+1]) then ( continue ) else (if y & L[y - 1+1][x+1] then ( L[y+1][x+1] := L[y - 1+1][x+1] ) else (if x & L[y+1][x - 1+1] then ( L[y+1][x+1] := L[y+1][x - 1+1] ) else ( n := n + 1 ; execute ((n) : sets) ; L[y+1][x+1] := n ) ) ) ) ; for x : Integer.subrange(-1 + 1, 10)->reverse() do ( if L[y+1][x+1] & L[y+1][x + 1+1] & L[y+1][x+1] /= L[y+1][x + 1+1] then ( execute ((L[y+1][x+1]) /: sets) ; L[y+1][x+1] := L[y+1][x + 1+1] ) else skip)) ; return (sets)->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) p,q=0,0 for i in a : if i % 2==0 : p+=1 else : q+=1 if p==0 or q==0 : print(0) exit() res=p if q % 2==0 : res+=2*max(q//2-1,0) else : res+=(q//2)*2 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := Sequence{0,0} ; for i : a do ( if i mod 2 = 0 then ( p := p + 1 ) else ( q := q + 1 )) ; if p = 0 or q = 0 then ( execute (0)->display() ; exit() ) else skip ; var res : OclAny := p ; if q mod 2 = 0 then ( res := res + 2 * Set{q div 2 - 1, 0}->max() ) else ( res := res + (q div 2) * 2 ) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=list(map(int,input().split())) even=0 odd=0 for a in A : if a % 2==0 : even+=1 else : odd+=1 if even==0 or odd==0 : print(0) elif odd % 2==1 : print(N-1) else : print(N-2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var even : int := 0 ; var odd : int := 0 ; for a : A do ( if a mod 2 = 0 then ( even := even + 1 ) else ( odd := odd + 1 )) ; if even = 0 or odd = 0 then ( execute (0)->display() ) else (if odd mod 2 = 1 then ( execute (N - 1)->display() ) else ( execute (N - 2)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) *a,=map(int,input().split()) o=e=0 for i in a : if i % 2 : o+=1 else : e+=1 if not o or not e : print(0) elif o % 2 : print(n-1) else : print(n-2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (testlist_star_expr (star_expr * (expr (atom (name a)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name a)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var o : OclAny := 0; var e : int := 0 ; for i : a do ( if i mod 2 then ( o := o + 1 ) else ( e := e + 1 )) ; if not(o) or not(e) then ( execute (0)->display() ) else (if o mod 2 then ( execute (n - 1)->display() ) else ( execute (n - 2)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNum(N,K): rem=N % K if(rem==0): return N else : return N-rem if __name__=='__main__' : N=45 K=6 print("Largest number smaller than or equal to"+str(N)+"that is divisible by"+str(K)+"is",findNum(N,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( N := 45 ; K := 6 ; execute ("Largest number smaller than or equal to" + ("" + ((N))) + "that is divisible by" + ("" + ((K))) + "is")->display() ) else skip; operation findNum(N : OclAny, K : OclAny) : OclAny pre: true post: true activity: var rem : int := N mod K ; if (rem = 0) then ( return N ) else ( return N - rem ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def powerfulIntegers(x,y,bound): s=set() powersOfY=[] powersOfY.append(1) i=y while i=bound): break for j in powersOfY : num=xPowI+j if(num<=bound): s.add(num) else : break i+=1 for itr in s : print(itr,end=" ") if __name__=="__main__" : x=2 y=3 bound=10 powerfulIntegers(x,y,bound) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( x := 2 ; y := 3 ; bound := 10 ; powerfulIntegers(x, y, bound) ) else skip; operation powerfulIntegers(x : OclAny, y : OclAny, bound : OclAny) pre: true post: true activity: var s : Set := Set{}->union(()) ; var powersOfY : Sequence := Sequence{} ; execute ((1) : powersOfY) ; var i : OclAny := y ; while (i->compareTo(bound)) < 0 do ( execute ((i) : powersOfY) ; i := i * y) ; i := 0 ; while (true) do ( var xPowI : double := (x)->pow(i) ; if ((xPowI->compareTo(bound)) >= 0) then ( break ) else skip ; for j : powersOfY do ( var num : OclAny := xPowI + j ; if ((num->compareTo(bound)) <= 0) then ( execute ((num) : s) ) else ( break )) ; i := i + 1) ; for itr : s do ( execute (itr)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(a==0 or b==0): return 0 if(a==b): return a if(a>b): return gcd(a-b,b) return gcd(a,b-a) def getRounding(n,k): rounding=pow(10,k); result=gcd(rounding,n) return((rounding*n)/result) n=375 k=4 print(int(getRounding(n,k))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 375 ; k := 4 ; execute (("" + ((getRounding(n, k))))->toInteger())->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0 or b = 0) then ( return 0 ) else skip ; if (a = b) then ( return a ) else skip ; if ((a->compareTo(b)) > 0) then ( return gcd(a - b, b) ) else skip ; return gcd(a, b - a); operation getRounding(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var rounding : double := (10)->pow(k); ; var result : OclAny := gcd(rounding, n) ; return ((rounding * n) / result); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def test_case(): r=float(input()) area=float(r**2*math.pi) circum=float(2*r*math.pi) print("{0:.8f}{1:.8f}".format(area,circum)) if __name__=="__main__" : test_case() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( test_case() ) else skip; operation test_case() pre: true post: true activity: var r : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; var area : double := ("" + (((r)->pow(2) * )))->toReal() ; var circum : double := ("" + ((2 * r * )))->toReal() ; execute (StringLib.interpolateStrings("{0:.8f}{1:.8f}", Sequence{area, circum}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- 1 2 3 from math import pi r=float(input()) print('{:.6f}{:.6f}'.format(pi*r**2,2*pi*r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: ; ; ; skip ; var r : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; execute (StringLib.interpolateStrings('{:.6f}{:.6f}', Sequence{pi * (r)->pow(2), 2 * pi * r}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calc_circle(r): pi=3.14159265359 area=round(r*r*pi,6) circ=round(2*r*pi,6) return(area,circ) if __name__=="__main__" : r=float(input()) area,circ=calc_circle(r) print(f"{area:.6f}{circ:.6f}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( r := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; Sequence{area,circ} := calc_circle(r) ; execute (StringLib.formattedString("{area:.6f}{circ:.6f}"))->display() ) else skip; operation calc_circle(r : OclAny) : OclAny pre: true post: true activity: var pi : double := 3.14159265359 ; var area : double := MathLib.roundN(r * r * pi, 6) ; var circ : double := MathLib.roundN(2 * r * pi, 6) ; return Sequence{area, circ}; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r,s,p=map(int,input().split()) ps=[None]*p for k in range(p): i,j=map(int,input().split()) if j<=s : j-=1 ps[k]=r+1-i+abs(s-j) ans=0 for t,p in enumerate(sorted(ps)[: :-1]): ans=max(ans,t+p) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : OclAny := null; var s : OclAny := null; var p : OclAny := null; Sequence{r,s,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ps : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, p) ; for k : Integer.subrange(0, p-1) do ( var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (j->compareTo(s)) <= 0 then ( j := j - 1 ) else skip ; ps[k+1] := r + 1 - i + (s - j)->abs()) ; var ans : int := 0 ; for _tuple : Integer.subrange(1, (sorted(ps)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->size())->collect( _indx | Sequence{_indx-1, (sorted(ps)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->at(_indx)} ) do (var _indx : int := 1; var t : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p : OclAny := _tuple->at(_indx); ans := Set{ans, t + p}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- answer=[] while True : n=int(input()) if n==0 : break ans=0 for i in range(55): for j in range(96): temp=i*i*i+(j*(j+1)*(j+2)//6) if temp<=n : if anstoInteger() ; if n = 0 then ( break ) else skip ; var ans : int := 0 ; for i : Integer.subrange(0, 55-1) do ( for j : Integer.subrange(0, 96-1) do ( var temp : double := i * i * i + (j * (j + 1) * (j + 2) div 6) ; if (temp->compareTo(n)) <= 0 then ( if (ans->compareTo(temp)) < 0 then ( ans := temp ) else skip ) else ( break ))) ; execute ((ans) : answer)) ; for i : answer do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r=float(input()) pi=3.1415926535897932384626 print(pi*r*r,2*pi*r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; var pi : double := 3.1415926535897932384626 ; execute (pi * r * r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r=float(input()) import math pi=math.pi s=(r**2)*pi l=2*r*pi print(s,l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; skip ; var pi : OclAny := ; var s : double := ((r)->pow(2)) * pi ; var l : double := 2 * r * pi ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : s=input() if s=='END OF INPUT' : break while True : if ' ' in s : s=s.replace(' ',' 0 ') else : break s=s.split() for i in s : print(len(i)if i!='0' else 0,end='') print('') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var s : String := (OclFile["System.in"]).readLine() ; if s = 'END OF INPUT' then ( break ) else skip ; while true do ( if (s)->characters()->includes(' ') then ( s := s.replace(' ', ' 0 ') ) else ( break )) ; s := s.split() ; for i : s->characters() do ( execute (if i /= '0' then (i)->size() else 0 endif)->display()) ; execute ('')->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- flag=True while flag : n=input() if n=="END OF INPUT" : flag=False else : count=0 for c in n : if c=="" : print(count,end="") count=0 else : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var flag : boolean := true ; while flag do ( var n : String := (OclFile["System.in"]).readLine() ; if n = "END OF INPUT" then ( flag := false ) else ( var count : int := 0 ; for c : n->characters() do ( if c = "" then ( execute (count)->display() ; count := 0 ) else ( count := count + 1 )) ; execute (count)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re while True : d=input() if d=='END OF INPUT' : break lst=re.split('[]',d) p=[] for i in range(len(lst)): p.append(len(lst[i])) for i in range(len(lst)): if lst[i]=='' : p[i]=0 P=[str(j)for j in p] P=''.join(P) print(P) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var d : String := (OclFile["System.in"]).readLine() ; if d = 'END OF INPUT' then ( break ) else skip ; var lst : Sequence(String) := (d)->split('[]') ; var p : Sequence := Sequence{} ; for i : Integer.subrange(0, (lst)->size()-1) do ( execute (((lst[i+1])->size()) : p)) ; for i : Integer.subrange(0, (lst)->size()-1) do ( if lst[i+1] = '' then ( p[i+1] := 0 ) else skip) ; var P : Sequence := p->select(j | true)->collect(j | (("" + ((j))))) ; P := StringLib.sumStringsWithSeparator((P), '') ; execute (P)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : put=input() if(put=="END OF INPUT"): break print(''.join(map(str,map(len,put.split(' '))))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var put : String := (OclFile["System.in"]).readLine() ; if (put = "END OF INPUT") then ( break ) else skip ; execute (StringLib.sumStringsWithSeparator((((put.split(' '))->collect( _x | (len)->apply(_x) ))->collect( _x | (OclType["String"])->apply(_x) )), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : s=input() if s=="END OF INPUT" : break t="" while True : if s[0]==" " : while s[0]==" " : t+="0" s=s[1 :] else : try : i=s.index(" ") t+=str(i) s=s[i+1 :] except : t+=str(len(s)) break print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var s : String := (OclFile["System.in"]).readLine() ; if s = "END OF INPUT" then ( break ) else skip ; var t : String := "" ; while true do ( if s->first() = " " then ( while s->first() = " " do ( t := t + "0" ; s := s->tail()) ) else ( try ( var i : int := s->indexOf(" ") - 1 ; t := t + ("" + ((i))) ; s := s.subrange(i + 1+1)) catch (_e : OclException) do ( t := t + ("" + (((s)->size()))) ; break) )) ; execute (t)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cty,loc=map(int,input().split()) crim=list(map(int,input().split())) coont=0 if crim[loc-1]==1 : coont+=1 for i in range(1000): if i==0 : continue if loc-1-i>=0 and loc+i-1=0 : if crim[loc-1-i]==1 : coont+=1 elif loc+i-1collect( _x | (OclType["int"])->apply(_x) ) ; var crim : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var coont : int := 0 ; if crim[loc - 1+1] = 1 then ( coont := coont + 1 ) else skip ; for i : Integer.subrange(0, 1000-1) do ( if i = 0 then ( continue ) else skip ; if loc - 1 - i >= 0 & (loc + i - 1->compareTo(cty)) < 0 then ( if crim[loc - 1 - i+1] = 1 & crim[loc + i - 1+1] = 1 then ( coont := coont + 2 ) else skip ) else (if loc - 1 - i >= 0 then ( if crim[loc - 1 - i+1] = 1 then ( coont := coont + 1 ) else skip ) else (if (loc + i - 1->compareTo(cty)) < 0 & crim[loc + i - 1+1] = 1 then ( coont := coont + 1 ) else skip ) ) ) ; execute (coont)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a=map(int,input().split()) n-=1 a-=1 c=0 t=list(map(int,input().split())) for i in range(1000000): x=0 if i==0 : x+=t[a] if x==1 : c+=1 elif(a-i)>=0 and(i+a)<=n : x+=t[abs(i-a)] x+=t[i+a] if x==2 : c+=2 elif(a-i)<0 and(i+a)<=n : x+=t[i+a] if x==1 : c+=1 elif(a-i)>=0 and(i+a)>n : x+=t[abs(i-a)] if x==1 : c+=1 elif(a-i)<0 and(i+a)>n : break print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; n := n - 1 ; a := a - 1 ; var c : int := 0 ; var t : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, 1000000-1) do ( var x : int := 0 ; if i = 0 then ( x := x + t[a+1] ; if x = 1 then ( c := c + 1 ) else skip ) else (if (a - i) >= 0 & ((i + a)->compareTo(n)) <= 0 then ( x := x + t[(i - a)->abs()+1] ; x := x + t[i + a+1] ; if x = 2 then ( c := c + 2 ) else skip ) else (if (a - i) < 0 & ((i + a)->compareTo(n)) <= 0 then ( x := x + t[i + a+1] ; if x = 1 then ( c := c + 1 ) else skip ) else (if (a - i) >= 0 & ((i + a)->compareTo(n)) > 0 then ( x := x + t[(i - a)->abs()+1] ; if x = 1 then ( c := c + 1 ) else skip ) else (if (a - i) < 0 & ((i + a)->compareTo(n)) > 0 then ( break ) else skip ) ) ) ) ) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a=map(int,input().split()) cities=list(map(int,input().split())) if len(cities)==1 : print(cities[0]) exit() sum_crimnals=0 for city in cities : if city==1 : sum_crimnals+=1 l=a-2 r=a while l>=0 and rcollect( _x | (OclType["int"])->apply(_x) ) ; var cities : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (cities)->size() = 1 then ( execute (cities->first())->display() ; exit() ) else skip ; var sum_crimnals : int := 0 ; for city : cities do ( if city = 1 then ( sum_crimnals := sum_crimnals + 1 ) else skip) ; var l : double := a - 2 ; var r : OclAny := a ; while l >= 0 & (r->compareTo(n)) < 0 do ( if cities[l+1] /= cities[r+1] then ( sum_crimnals := sum_crimnals - 1 ) else skip ; l := l - 1 ; r := r + 1) ; execute (sum_crimnals)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans=[] while True : N=int(input()) if not N : break now_cube=int(N**(1/3+0.000001)) now_pyramid=0 tmp_ans=now_cube**3 for i in range(now_cube,-1,-1): while True : if(now_pyramid+1)*(now_pyramid+2)*(now_pyramid+3)//6+i**3>N : tmp_ans=max(tmp_ans,now_pyramid*(now_pyramid+1)*(now_pyramid+2)//6+i**3) break now_pyramid+=1 ans.append(tmp_ans) [print(i)for i in ans] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ans : Sequence := Sequence{} ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(N) then ( break ) else skip ; var now_cube : int := ("" + (((N)->pow((1 / 3 + 0.000001)))))->toInteger() ; var now_pyramid : int := 0 ; var tmp_ans : double := (now_cube)->pow(3) ; for i : Integer.subrange(-1 + 1, now_cube)->reverse() do ( while true do ( if ((now_pyramid + 1) * (now_pyramid + 2) * (now_pyramid + 3) div 6 + (i)->pow(3)->compareTo(N)) > 0 then ( tmp_ans := Set{tmp_ans, now_pyramid * (now_pyramid + 1) * (now_pyramid + 2) div 6 + (i)->pow(3)}->max() ; break ) else skip ; now_pyramid := now_pyramid + 1)) ; execute ((tmp_ans) : ans)) ; ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import array from fractions import Fraction import functools import itertools import math import os import sys def main(): R,S,P=read_ints() A=[] for _ in range(P): i,j=read_ints() i-=1 j-=1 A.append((i,j)) print(solve(R,S,P,A)) def solve(R,S,P,A): q=[0]*(R+S+1) for i,j in A : x=S-j if j0 : q[i]=1 of=c-1 if of>0 : return R+S+1+of while q and q[-1]==0 : del q[-1] return len(q) DEBUG='DEBUG' in os.environ def inp(): return sys.stdin.readline().rstrip() def read_int(): return int(inp()) def read_ints(): return[int(e)for e in inp().split()] def dprint(*value,sep=' ',end='\n'): if DEBUG : print(*value,sep=sep,end=end) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var DEBUG : boolean := (os.environ)->includes('DEBUG') ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var R : OclAny := null; var S : OclAny := null; var P : OclAny := null; Sequence{R,S,P} := read_ints() ; var A : Sequence := Sequence{} ; for _anon : Integer.subrange(0, P-1) do ( var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := read_ints() ; i := i - 1 ; j := j - 1 ; execute ((Sequence{i, j}) : A)) ; execute (solve(R, S, P, A))->display(); operation solve(R : OclAny, S : OclAny, P : OclAny, A : OclAny) : OclAny pre: true post: true activity: var q : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (R + S + 1)) ; for _tuple : A do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); var x : double := if (j->compareTo(S)) < 0 then S - j else j - S + 1 endif ; q[R - 1 - i + x+1] := q[R - 1 - i + x+1] + 1) ; var of : int := 0 ; for i : Integer.subrange(0, R + S + 1-1) do ( var c : OclAny := q[i+1] + of ; if c > 0 then ( q[i+1] := 1 ; of := c - 1 ) else skip) ; if of > 0 then ( return R + S + 1 + of ) else skip ; while q & q->last() = 0 do ( execute (q->last())->isDeleted()) ; return (q)->size(); operation inp() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation read_int() : OclAny pre: true post: true activity: return ("" + ((inp())))->toInteger(); operation read_ints() : OclAny pre: true post: true activity: return inp().split()->select(e | true)->collect(e | (("" + ((e)))->toInteger())); operation dprint(value : OclAny : Sequence(OclAny), sep : String, end : String) pre: true post: true activity: (args * (named_parameter (name value))) if sep->oclIsUndefined() then sep := ' ' else skip; if end->oclIsUndefined() then end := ' ' else skip; if DEBUG then ( execute ((argument * (test (logical_test (comparison (expr (atom (name value))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=map(int,input().split()) a=list(map(int,input().split())) sum=sum(a) d=d-1 for i in range(n): if d-i>=0 and d+icollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sum : OclAny := (a)->sum() ; var d : double := d - 1 ; for i : Integer.subrange(0, n-1) do ( if d - i >= 0 & (d + i->compareTo(n)) < 0 then ( if a[d - i+1] + a[d + i+1] = 1 then ( sum := sum - 1 ) else skip ) else skip) ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a=map(int,input().split()) a-=1 b=[1]*n+[*map(int,input().split())]+[1]*n print(sum(b[n+a-abs(a-x)]*b[n+a+abs(a-x)]for x in range(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := a - 1 ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, n)->union((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->union(MatrixLib.elementwiseMult(Sequence{ 1 }, n)) ; execute (((argument (test (logical_test (comparison (expr (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name n))) + (expr (atom (name a)))) - (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (name x))))))))) )))))))))) ]))) * (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name n))) + (expr (atom (name a)))) + (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (name x))))))))) )))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=99999 size=10 def getSetBitsFromOneToN(N): two,ans=2,0 n=N while(n>0): ans+=(N//two)*(two>>1) if((N &(two-1))>(two>>1)-1): ans+=(N &(two-1))-(two>>1)+1 two<<=1 n>>=1 return ans def findMinimum(x): low=0 high=100000 ans=high while(low<=high): mid=(low+high)>>1 if(getSetBitsFromOneToN(mid)>=x): ans=min(ans,mid) high=mid-1 else : low=mid+1 return ans x=20 print(findMinimum(x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INF : int := 99999 ; var size : int := 10 ; skip ; skip ; x := 20 ; execute (findMinimum(x))->display(); operation getSetBitsFromOneToN(N : OclAny) : OclAny pre: true post: true activity: var two : OclAny := null; var ans : OclAny := null; Sequence{two,ans} := Sequence{2,0} ; var n : OclAny := N ; while (n > 0) do ( ans := ans + (N div two) * (two /(2->pow(1))) ; if (((MathLib.bitwiseAnd(N, (two - 1)))->compareTo((two /(2->pow(1))) - 1)) > 0) then ( ans := ans + (MathLib.bitwiseAnd(N, (two - 1))) - (two /(2->pow(1))) + 1 ) else skip ; two := two * (2->pow(1)) ; n := n div (2->pow(1))) ; return ans; operation findMinimum(x : OclAny) : OclAny pre: true post: true activity: var low : int := 0 ; var high : int := 100000 ; var ans : int := high ; while ((low->compareTo(high)) <= 0) do ( var mid : int := (low + high) /(2->pow(1)) ; if ((getSetBitsFromOneToN(mid)->compareTo(x)) >= 0) then ( ans := Set{ans, mid}->min() ; high := mid - 1 ) else ( low := mid + 1 )) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sin def calculateSide(n,r): theta=360/n theta_in_radians=theta*3.14/180 return 2*r*sin(theta_in_radians/2) if __name__=='__main__' : n=3 r=5 print('{0:.5}'.format(calculateSide(n,r))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( n := 3 ; r := 5 ; execute (StringLib.interpolateStrings('{0:.5}', Sequence{calculateSide(n, r)}))->display() ) else skip; operation calculateSide(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: var theta : double := 360 / n ; var theta_in_radians : double := theta * 3.14 / 180 ; return 2 * r * sin(theta_in_radians / 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A=[11,15,7,19] N=len(A) Set=set() for i in range(0,N): res=2147483647 for j in range(i,N): res &=A[j] Set.add(res) print(Set) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : Sequence := Sequence{11}->union(Sequence{15}->union(Sequence{7}->union(Sequence{ 19 }))) ; var N : int := (A)->size() ; var Set : Set := Set{}->union(()) ; for i : Integer.subrange(0, N-1) do ( var res : int := 2147483647 ; for j : Integer.subrange(i, N-1) do ( res := res & A[j+1] ; execute ((res) : Set))) ; execute (Set)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- chessboard_list1=[] chessboard_list2=[] for i in range(8): row=input() chessboard_list1.append(row) for j in range(8): l='' for row in chessboard_list1 : l+=row[j] chessboard_list2.append(l) if chessboard_list1.count('BBBBBBBB')==8 : print(8) else : sum=chessboard_list1.count('BBBBBBBB')+chessboard_list2.count('BBBBBBBB') print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var chessboard_list1 : Sequence := Sequence{} ; var chessboard_list2 : Sequence := Sequence{} ; for i : Integer.subrange(0, 8-1) do ( var row : String := (OclFile["System.in"]).readLine() ; execute ((row) : chessboard_list1)) ; for j : Integer.subrange(0, 8-1) do ( var l : String := '' ; for row : chessboard_list1 do ( l := l + row[j+1]) ; execute ((l) : chessboard_list2)) ; if chessboard_list1->count('BBBBBBBB') = 8 then ( execute (8)->display() ) else ( var sum : int := chessboard_list1->count('BBBBBBBB') + chessboard_list2->count('BBBBBBBB') ; execute (sum)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- e=0 s1='' s2='' s3='' s4='' s5='' s6='' s7='' s8='' for i in range(8): s=str(input()) if(s==('B'*8)): e=e+1 s1=s1+s[0] s2=s2+s[1] s3=s3+s[2] s4=s4+s[3] s5=s5+s[4] s6=s6+s[5] s7=s7+s[6] s8=s8+s[7] if(s1==('B'*8)): e=e+1 if(s2==('B'*8)): e=e+1 if(s3==('B'*8)): e=e+1 if(s4==('B'*8)): e=e+1 if(s5==('B'*8)): e=e+1 if(s6==('B'*8)): e=e+1 if(s7==('B'*8)): e=e+1 if(s8==('B'*8)): e=e+1 if(e==16): print(8) else : print(e) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var e : int := 0 ; var s1 : String := '' ; var s2 : String := '' ; var s3 : String := '' ; var s4 : String := '' ; var s5 : String := '' ; var s6 : String := '' ; var s7 : String := '' ; var s8 : String := '' ; for i : Integer.subrange(0, 8-1) do ( var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; if (s = (StringLib.nCopies('B', 8))) then ( e := e + 1 ) else skip ; s1 := s1 + s->first() ; s2 := s2 + s[1+1] ; s3 := s3 + s[2+1] ; s4 := s4 + s[3+1] ; s5 := s5 + s[4+1] ; s6 := s6 + s[5+1] ; s7 := s7 + s[6+1] ; s8 := s8 + s[7+1]) ; if (s1 = (StringLib.nCopies('B', 8))) then ( e := e + 1 ) else skip ; if (s2 = (StringLib.nCopies('B', 8))) then ( e := e + 1 ) else skip ; if (s3 = (StringLib.nCopies('B', 8))) then ( e := e + 1 ) else skip ; if (s4 = (StringLib.nCopies('B', 8))) then ( e := e + 1 ) else skip ; if (s5 = (StringLib.nCopies('B', 8))) then ( e := e + 1 ) else skip ; if (s6 = (StringLib.nCopies('B', 8))) then ( e := e + 1 ) else skip ; if (s7 = (StringLib.nCopies('B', 8))) then ( e := e + 1 ) else skip ; if (s8 = (StringLib.nCopies('B', 8))) then ( e := e + 1 ) else skip ; if (e = 16) then ( execute (8)->display() ) else ( execute (e)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans,met=0,False for i in range(8): s=input() if s=='BBBBBBBB' : ans+=1 elif not met : ans+=s.count('B') met=True print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ans : OclAny := null; var met : OclAny := null; Sequence{ans,met} := Sequence{0,false} ; for i : Integer.subrange(0, 8-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if s = 'BBBBBBBB' then ( ans := ans + 1 ) else (if not(met) then ( ans := ans + s->count('B') ; var met : boolean := true ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- board=[] out=0 for i in range(8): row=input() board.append(row) complete=True for i in range(8): if board[i]!="BBBBBBBB" : complete=False break if complete : out=8 print(out) else : for i in range(8): same=True for j in range(8): if board[i][j]!="B" : same=False break if same : out+=1 for i in range(8): same=True for j in range(8): if board[j][i]!="B" : same=False break if same : out+=1 print(out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var board : Sequence := Sequence{} ; var out : int := 0 ; for i : Integer.subrange(0, 8-1) do ( var row : String := (OclFile["System.in"]).readLine() ; execute ((row) : board)) ; var complete : boolean := true ; for i : Integer.subrange(0, 8-1) do ( if board[i+1] /= "BBBBBBBB" then ( complete := false ; break ) else skip) ; if complete then ( out := 8 ; execute (out)->display() ) else ( for i : Integer.subrange(0, 8-1) do ( var same : boolean := true ; for j : Integer.subrange(0, 8-1) do ( if board[i+1][j+1] /= "B" then ( same := false ; break ) else skip) ; if same then ( out := out + 1 ) else skip) ; for i : Integer.subrange(0, 8-1) do ( same := true ; for j : Integer.subrange(0, 8-1) do ( if board[j+1][i+1] /= "B" then ( same := false ; break ) else skip) ; if same then ( out := out + 1 ) else skip) ; execute (out)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=0 r,c=0,-1 dl=[] for i in range(n): tl=list(map(int,input().split())) if c<0 and tl.count(0): r=i c=tl.index(0) dl+=[tl] s=sum(dl[(r+1)% n]) a=s-sum(dl[r]) dl[r][c]=a if n>1 and a<1 : print(-1) exit() for i in range(n): if s!=sum(dl[i]): print(-1) exit() dl=list(map(list,zip(*dl))) for i in range(n): if s!=sum(dl[i]): print(-1) exit() s1=s2=0 for i in range(n): s1+=dl[i][i] s2+=dl[i][n-i-1] if not(s1==s2==s): print(-1) exit() if n==1 : a=1 print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := 0 ; var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := Sequence{0,-1} ; var dl : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var tl : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if c < 0 & tl->count(0) then ( var r : OclAny := i ; var c : int := tl->indexOf(0) - 1 ) else skip ; dl := dl + Sequence{ tl }) ; var s : OclAny := (dl[(r + 1) mod n+1])->sum() ; a := s - (dl[r+1])->sum() ; dl[r+1][c+1] := a ; if n > 1 & a < 1 then ( execute (-1)->display() ; exit() ) else skip ; for i : Integer.subrange(0, n-1) do ( if s /= (dl[i+1])->sum() then ( execute (-1)->display() ; exit() ) else skip) ; dl := ((Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name dl)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name dl)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name dl)))))))`third->at(_indx)} ))->collect( _x | (OclType["Sequence"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( if s /= (dl[i+1])->sum() then ( execute (-1)->display() ; exit() ) else skip) ; var s1 : OclAny := 0; var s2 : int := 0 ; for i : Integer.subrange(0, n-1) do ( s1 := s1 + dl[i+1][i+1] ; s2 := s2 + dl[i+1][n - i - 1+1]) ; if not((s1 = s2 & (s2 == s))) then ( execute (-1)->display() ; exit() ) else skip ; if n = 1 then ( a := 1 ) else skip ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : while True : num=int(input()) if num==0 : break ans=999999999 for c in range(54): cubic=c*c*c if cubic>num : break for t in range(96): tetra=(t*(t+1)*(t+2))//6 if cubic+tetra>num : break if abs(cubic+tetra-num)toInteger() ; if num = 0 then ( break ) else skip ; var ans : int := 999999999 ; for c : Integer.subrange(0, 54-1) do ( var cubic : double := c * c * c ; if (cubic->compareTo(num)) > 0 then ( break ) else skip ; for t : Integer.subrange(0, 96-1) do ( var tetra : int := (t * (t + 1) * (t + 2)) div 6 ; if (cubic + tetra->compareTo(num)) > 0 then ( break ) else skip ; if ((cubic + tetra - num)->abs()->compareTo((num - ans)->abs())) < 0 then ( ans := cubic + tetra ) else skip)) ; execute (ans)->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[] for i in range(0,8): a.append(input()) t1=0 t2=0 for i in range(0,8): if a[i].count('B')==8 : t1+=1 else : t2=a[i].count('B') print(t1+t2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Sequence{} ; for i : Integer.subrange(0, 8-1) do ( execute (((OclFile["System.in"]).readLine()) : a)) ; var t1 : int := 0 ; var t2 : int := 0 ; for i : Integer.subrange(0, 8-1) do ( if a[i+1]->count('B') = 8 then ( t1 := t1 + 1 ) else ( t2 := a[i+1]->count('B') )) ; execute (t1 + t2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w=map(int,input().split()) lst=[] alldot=[True]*w for i in range(h): s=input() if s.count('#')>=1 : lst.append(s) for t in range(w): alldot[t]=alldot[t]and s[t]=='.' else : h-=1 res=['']*h for i in range(h): for j in range(w): if alldot[j]: pass else : res[i]+=lst[i][j] for i in res : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lst : Sequence := Sequence{} ; var alldot : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, w) ; for i : Integer.subrange(0, h-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if s->count('#') >= 1 then ( execute ((s) : lst) ; for t : Integer.subrange(0, w-1) do ( alldot[t+1] := alldot[t+1] & s[t+1] = '.') ) else ( h := h - 1 )) ; var res : Sequence := MatrixLib.elementwiseMult(Sequence{ '' }, h) ; for i : Integer.subrange(0, h-1) do ( for j : Integer.subrange(0, w-1) do ( if alldot[j+1] then ( skip ) else ( res[i+1] := res[i+1] + lst[i+1][j+1] ))) ; for i : res do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dp={}; def solve(s,c): if(len(s)==1): return 0 ; if(len(s)==2): if(s[0]==s[1]and s[0]==c): return 1 ; else : return 0 ; if(s+" "+c)in dp : return dp[s+" "+c]; ans=0 ; if(s[0]==s[len(s)-1]and s[0]==c): for c1 in range(97,123): if(chr(c1)!=c): ans=max(ans,1+solve(s[1 : len(s)-1],chr(c1))); else : for i in range(len(s)): if(s[i]==c): for j in range(len(s)-1,i,-1): if(s[j]==c): if(j==i): break ; ans=solve(s[i : j-i+2],c); break ; break ; dp[s+" "+c]=ans ; return dp[s+" "+c]; if __name__=="__main__" : s="abscrcdba" ; ma=0 ; for c1 in range(97,123): ma=max(ma,solve(s,chr(c1))*2); print(ma); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dp : OclAny := Set{}; ; skip ; if __name__ = "__main__" then ( s := "abscrcdba"; ; var ma : int := 0; ; for c1 : Integer.subrange(97, 123-1) do ( ma := Set{ma, solve(s, (c1)->byte2char()) * 2}->max();) ; execute (ma)->display(); ) else skip; operation solve(s : OclAny, c : OclAny) pre: true post: true activity: if ((s)->size() = 1) then ( return 0; ) else skip ; if ((s)->size() = 2) then ( if (s->first() = s[1+1] & s->first() = c) then ( return 1; ) else ( return 0; ) ) else skip ; if (dp)->includes((s + " " + c)) then ( return dp[s + " " + c+1]; ) else skip ; var ans : int := 0; ; if (s->first() = s[(s)->size() - 1+1] & s->first() = c) then ( for c1 : Integer.subrange(97, 123-1) do ( if ((c1)->byte2char() /= c) then ( ans := Set{ans, 1 + solve(s.subrange(1+1, (s)->size() - 1), (c1)->byte2char())}->max(); ) else skip) ) else ( for i : Integer.subrange(0, (s)->size()-1) do ( if (s[i+1] = c) then ( for j : Integer.subrange(i + 1, (s)->size() - 1)->reverse() do ( if (s[j+1] = c) then ( if (j = i) then ( break; ) else skip ; ans := solve(s.subrange(i+1, j - i + 2), c); ; break; ) else skip) ; break; ) else skip) ) ; dp[s + " " + c+1] := ans; ; return dp[s + " " + c+1];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,l,r=map(int,input().split()) l1=[] l2=[] k=1 d=r-l for i in range(n): while(l>0): l1.append(k) l2.append(k) k=k*2 l=l-1 if(r-l)>0 : while(d>0): l2.append(k) k=k*2 d=d-1 if len(l2)collect( _x | (OclType["int"])->apply(_x) ) ; var l1 : Sequence := Sequence{} ; var l2 : Sequence := Sequence{} ; var k : int := 1 ; var d : double := r - l ; for i : Integer.subrange(0, n-1) do ( while (l > 0) do ( execute ((k) : l1) ; execute ((k) : l2) ; k := k * 2 ; var l : double := l - 1) ; if (r - l) > 0 then ( while (d > 0) do ( execute ((k) : l2) ; k := k * 2 ; d := d - 1) ) else skip ; if ((l2)->size()->compareTo(n)) < 0 then ( execute ((k div 2) : l2) ) else skip ; if ((l1)->size()->compareTo(n)) < 0 then ( execute ((1) : l1) ) else skip) ; execute ((l1)->sum())->display() ; execute ((l2)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,l,r=map(int,input().split()) s_min=0 count=1 k=1 while count<=l : s_min+=k k*=2 count+=1 s_min+=(n-l) print(s_min,end=' ') s_max=0 count=1 k=1 while count<=r : s_max+=k k*=2 count+=1 s_max+=(n-r)*(k//2) print(s_max) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{n,l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s_min : int := 0 ; var count : int := 1 ; var k : int := 1 ; while (count->compareTo(l)) <= 0 do ( s_min := s_min + k ; k := k * 2 ; count := count + 1) ; s_min := s_min + (n - l) ; execute (s_min)->display() ; var s_max : int := 0 ; count := 1 ; k := 1 ; while (count->compareTo(r)) <= 0 do ( s_max := s_max + k ; k := k * 2 ; count := count + 1) ; s_max := s_max + (n - r) * (k div 2) ; execute (s_max)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,l,r=map(int,input().split()) print(2**l-1+n-l,(n-r+2)*2**(r-1)-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{n,l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((2)->pow(l) - 1 + n - l)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys from collections import deque,OrderedDict,defaultdict import heapq from collections import Counter def inp(): return sys.stdin.readline().rstrip() def mpp(): return map(int,inp().split()) def lis(): return list(mpp()) def yn(n): if n : return "YES" else : return "NO" def mn(n,l,r): cst=0 for i in range(n-l+1): cst+=1 k=2 for i in range(n-l+1,n): cst+=k k*=2 return cst def mx(n,l,r): cst=0 for i in range(n-r): cst+=2**(r-1) k=1 for i in range(n-r,n): cst+=k k*=2 return cst def fn(n,l,r): return(mn(n,l,r),mx(n,l,r)) def main(): n,l,r=mpp() print(*fn(n,l,r)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation inp() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation mpp() : OclAny pre: true post: true activity: return (inp().split())->collect( _x | (OclType["int"])->apply(_x) ); operation lis() : OclAny pre: true post: true activity: return (mpp()); operation yn(n : OclAny) : OclAny pre: true post: true activity: if n then ( return "YES" ) else ( return "NO" ); operation mn(n : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var cst : int := 0 ; for i : Integer.subrange(0, n - l + 1-1) do ( cst := cst + 1) ; var k : int := 2 ; for i : Integer.subrange(n - l + 1, n-1) do ( cst := cst + k ; k := k * 2) ; return cst; operation mx(n : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: cst := 0 ; for i : Integer.subrange(0, n - r-1) do ( cst := cst + (2)->pow((r - 1))) ; k := 1 ; for i : Integer.subrange(n - r, n-1) do ( cst := cst + k ; k := k * 2) ; return cst; operation fn(n : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: return Sequence{mn(n, l, r), mx(n, l, r)}; operation main() pre: true post: true activity: Sequence{n,l,r} := mpp() ; execute ((argument * (test (logical_test (comparison (expr (atom (name fn)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n))))))) , (argument (test (logical_test (comparison (expr (atom (name l))))))) , (argument (test (logical_test (comparison (expr (atom (name r)))))))) )))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l1=[int(a)for a in input().split()] n=l1[0] l=l1[1] r=l1[2] min=(n-l+1)+2*((2**(l-1))-1) max=((2**r)-1)+((n-r)*(2**(r-1))) print(min,max) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l1 : Sequence := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; var n : OclAny := l1->first() ; var l : OclAny := l1[1+1] ; var r : OclAny := l1[2+1] ; var min : double := (n - l + 1) + 2 * (((2)->pow((l - 1))) - 1) ; var max : double := (((2)->pow(r)) - 1) + ((n - r) * ((2)->pow((r - 1)))) ; execute (min)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- L=int(input()) N=len(bin(L)[2 :]) M=0 Lines=[] for i in range(N-1): M+=2 Lines.append((i+1,i+2,0)) Lines.append((i+1,i+2,2**i)) tmp=2**(N-1) for i,j in enumerate(bin(L)[3 :],1): if j=='1' : M+=1 Lines.append((N-i,N,tmp)) tmp+=2**(N-i-1) print(N,M) for Line in Lines : print("{}{}{}".format(Line[0],Line[1],Line[2])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var L : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var N : int := (bin(L).subrange(2+1))->size() ; var M : int := 0 ; var Lines : Sequence := Sequence{} ; for i : Integer.subrange(0, N - 1-1) do ( M := M + 2 ; execute ((Sequence{i + 1, i + 2, 0}) : Lines) ; execute ((Sequence{i + 1, i + 2, (2)->pow(i)}) : Lines)) ; var tmp : double := (2)->pow((N - 1)) ; for _tuple : Integer.subrange(1, (bin(L).subrange(3+1), 1)->size())->collect( _indx | Sequence{_indx-1, (bin(L).subrange(3+1), 1)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if j = '1' then ( M := M + 1 ; execute ((Sequence{N - i, N, tmp}) : Lines) ; tmp := tmp + (2)->pow((N - i - 1)) ) else skip) ; execute (N)->display() ; for Line : Lines do ( execute (StringLib.interpolateStrings("{}{}{}", Sequence{Line->first(), Line[1+1], Line[2+1]}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): L=int(input()) r=0 while 2**(r+1)<=L : r+=1 assert r<20 N=r+1 edges=list() for i in range(1,N): edges.append((i,i+1,0)) edges.append((i,i+1,2**(i-1))) for t in range(N-1,0,-1): if L-2**(t-1)>=2**r : edges.append((t,N,L-2**(t-1))) L-=2**(t-1) print('{}{}'.format(N,len(edges))) for e in edges : print(' '.join(map(str,e))) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var L : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r : int := 0 ; while ((2)->pow((r + 1))->compareTo(L)) <= 0 do ( r := r + 1) ; assert r < 20 do "assertion failed" ; var N : int := r + 1 ; var edges : Sequence := () ; for i : Integer.subrange(1, N-1) do ( execute ((Sequence{i, i + 1, 0}) : edges) ; execute ((Sequence{i, i + 1, (2)->pow((i - 1))}) : edges)) ; for t : Integer.subrange(0 + 1, N - 1)->reverse() do ( if (L - (2)->pow((t - 1))->compareTo((2)->pow(r))) >= 0 then ( execute ((Sequence{t, N, L - (2)->pow((t - 1))}) : edges) ; L := L - (2)->pow((t - 1)) ) else skip) ; execute (StringLib.interpolateStrings('{}{}', Sequence{N, (edges)->size()}))->display() ; for e : edges do ( execute (StringLib.sumStringsWithSeparator(((e)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def substitute(text,a,b): pos=0 newText=text L1=len(a) L2=len(b) while True : idx=newText.find(a,pos) if idx<0 : return newText newText=newText[: idx]+b+newText[idx+L1 :] pos=idx+L2 return newText def transform(orig,goal,count): global subs global minCount if len(orig)>len(goal): return if orig==goal : minCount=min(minCount,count) return for key in subs : newStr=substitute(orig,key,subs[key]) if newStr!=orig : transform(newStr,goal,count+1) if __name__=='__main__' : while True : N=int(input()) if N==0 : break subs={} for _ in range(N): a,b=input().strip().split() subs[a]=b orig=input().strip() goal=input().strip() minCount=999999999 transform(orig,goal,0) if minCount==999999999 : print(-1) else : print(minCount) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute subs : OclAny; attribute minCount : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; subs := Set{} ; for _anon : Integer.subrange(0, N-1) do ( Sequence{a,b} := input()->trim().split() ; subs[a+1] := b) ; orig := input()->trim() ; goal := input()->trim() ; minCount := 999999999 ; transform(orig, goal, 0) ; if minCount = 999999999 then ( execute (-1)->display() ) else ( execute (minCount)->display() )) ) else skip; operation substitute(text : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var pos : int := 0 ; var newText : OclAny := text ; var L1 : int := (a)->size() ; var L2 : int := (b)->size() ; while true do ( var idx : int := newText->indexOf(a, pos) - 1 ; if idx < 0 then ( return newText ) else skip ; newText := newText.subrange(1,idx) + b + newText.subrange(idx + L1+1) ; pos := idx + L2) ; return newText; operation transform(orig : OclAny, goal : OclAny, count : OclAny) pre: true post: true activity: skip ; skip ; if ((orig)->size()->compareTo((goal)->size())) > 0 then ( return ) else skip ; if orig = goal then ( minCount := Set{minCount, count}->min() ; return ) else skip ; for key : subs do ( var newStr : OclAny := substitute(orig, key, subs[key+1]) ; if newStr /= orig then ( transform(newStr, goal, count + 1) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import copy import heapq import math import sys from collections import* from itertools import accumulate,combinations,permutations,product def input(): return sys.stdin.readline()[:-1] def ruiseki(lst): return[0]+list(accumulate(lst)) mod=pow(10,9)+7 al=[chr(ord('a')+i)for i in range(26)] direction=[[1,0],[0,1],[-1,0],[0,-1]] l=int(input()) r=20 while 2**r>l : r-=1 anslst=[] for i in range(2*r): lst=[i//2+1,i//2+2,0] if i % 2==1 : lst[2]=2**((i)//2) anslst.append(lst) for i in range(r): if l-2**(r-i-1)>=2**r : anslst.append([r-i,r+1,l-2**(r-i-1)]) l-=2**(r-i-1) print(*[r+1,len(anslst)]) for i in range(len(anslst)): print(*anslst[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; var al : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | ((('a')->char2byte() + i)->byte2char())) ; var direction : Sequence := Sequence{Sequence{1}->union(Sequence{ 0 })}->union(Sequence{Sequence{0}->union(Sequence{ 1 })}->union(Sequence{Sequence{-1}->union(Sequence{ 0 })}->union(Sequence{ Sequence{0}->union(Sequence{ -1 }) }))) ; var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r : int := 20 ; while ((2)->pow(r)->compareTo(l)) > 0 do ( r := r - 1) ; var anslst : Sequence := Sequence{} ; for i : Integer.subrange(0, 2 * r-1) do ( lst := Sequence{i div 2 + 1}->union(Sequence{i div 2 + 2}->union(Sequence{ 0 })) ; if i mod 2 = 1 then ( lst[2+1] := (2)->pow(((i) div 2)) ) else skip ; execute ((lst) : anslst)) ; for i : Integer.subrange(0, r-1) do ( if (l - (2)->pow((r - i - 1))->compareTo((2)->pow(r))) >= 0 then ( execute ((Sequence{r - i}->union(Sequence{r + 1}->union(Sequence{ l - (2)->pow((r - i - 1)) }))) : anslst) ; l := l - (2)->pow((r - i - 1)) ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name r))) + (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name anslst)))))))) )))))))) ])))))))->display() ; for i : Integer.subrange(0, (anslst)->size()-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name anslst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))->display()); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation ruiseki(lst : OclAny) : OclAny pre: true post: true activity: return Sequence{ 0 }->union((accumulate(lst))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda : sys.stdin.readline().rstrip() def iterate(L,n,m,edges,mode): if(mode & 1 or L==1): edges+=[(1,n,L)] return L+1,n,m+1,edges else : edges=[(u,v,2*w)for u,v,w in edges] edges+=[(n,n+1,0),(n,n+1,1)] return 2*L,n+1,m+2,edges def resolve(): L=int(input()) res=[L % 2] while(L!=1): if(L & 1): L-=1 else : L//=2 res.append(L % 2) res.reverse() L=1 n=2 m=1 edges=[(1,2,0)] for mode in res[1 :]: L,n,m,edges=iterate(L,n,m,edges,mode) print(n,m) for e in edges : print(*e) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(2147483647) ; var INF : double := ("" + (("inf")))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; skip ; skip ; resolve(); operation iterate(L : OclAny, n : OclAny, m : OclAny, edges : OclAny, mode : OclAny) : OclAny pre: true post: true activity: if (MathLib.bitwiseAnd(mode, 1) or L = 1) then ( edges := edges + Sequence{ Sequence{1, n, L} } ; return L + 1, n, m + 1, edges ) else ( edges := edges->select(_tuple | true)->collect(_tuple | let u : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in (Sequence{u, v, 2 * w})) ; edges := edges + Sequence{Sequence{n, n + 1, 0}}->union(Sequence{ Sequence{n, n + 1, 1} }) ; return 2 * L, n + 1, m + 2, edges ); operation resolve() pre: true post: true activity: L := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : Sequence := Sequence{ L mod 2 } ; while (L /= 1) do ( if (MathLib.bitwiseAnd(L, 1)) then ( L := L - 1 ) else ( L := L div 2 ) ; execute ((L mod 2) : res)) ; res := res->reverse() ; L := 1 ; n := 2 ; m := 1 ; edges := Sequence{ Sequence{1, 2, 0} } ; for mode : res->tail() do ( Sequence{L,n,m,edges} := iterate(L, n, m, edges, mode)) ; execute (n)->display() ; for e : edges do ( execute ((argument * (test (logical_test (comparison (expr (atom (name e))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w=map(int,input().split()) f=[] for i in range(h): f.append(list(input())) a=[] for i in range(len(f)): if f[i]==["."]*len(f[i]): a.append(i) for i in a : del f[i] for s in range(len(a)): a[s]-=1 f2=[] for i in range(w): s=[] for k in f : s.append(k[i]) f2.append(s) b=[] for i in range(len(f2)): if f2[i]==["."]*len(f2[i]): b.append(i) for i in b : del f2[i] for s in range(len(b)): b[s]-=1 ff=[] for i in range(len(f2[0])): s=[] for k in f2 : s.append(k[i]) ff.append(s) for i in ff : for s in range(len(i)-1): print(i[s],end="") print(i[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var f : Sequence := Sequence{} ; for i : Integer.subrange(0, h-1) do ( execute ((((OclFile["System.in"]).readLine())->characters()) : f)) ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, (f)->size()-1) do ( if f[i+1] = MatrixLib.elementwiseMult(Sequence{ "." }, (f[i+1])->size()) then ( execute ((i) : a) ) else skip) ; for i : a do ( execute (f[i+1])->isDeleted() ; for s : Integer.subrange(0, (a)->size()-1) do ( a[s+1] := a[s+1] - 1)) ; var f2 : Sequence := Sequence{} ; for i : Integer.subrange(0, w-1) do ( var s : Sequence := Sequence{} ; for k : f do ( execute ((k[i+1]) : s)) ; execute ((s) : f2)) ; var b : Sequence := Sequence{} ; for i : Integer.subrange(0, (f2)->size()-1) do ( if f2[i+1] = MatrixLib.elementwiseMult(Sequence{ "." }, (f2[i+1])->size()) then ( execute ((i) : b) ) else skip) ; for i : b do ( execute (f2[i+1])->isDeleted() ; for s : Integer.subrange(0, (b)->size()-1) do ( b->restrict(s) := b->restrict(s) - 1)) ; var ff : Sequence := Sequence{} ; for i : Integer.subrange(0, (f2->first())->size()-1) do ( s := Sequence{} ; for k : f2 do ( execute ((k[i+1]) : s)) ; execute ((s) : ff)) ; for i : ff do ( for s : Integer.subrange(0, (i)->size() - 1-1) do ( execute (i->restrict(s))->display()) ; execute (i->last())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math l=int(input()) n=math.floor(math.log2(l))+1 e=[] for v in range(n-1): e.append([v+1,v+2,0]) e.append([v+1,v+2,2**v]) if(l>>v)& 1 : e.append([v+1,n,l-2**v]) l-=2**v print(n,len(e)) for x in e : print(" ".join(map(str,x))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : double := ()->floor() + 1 ; var e : Sequence := Sequence{} ; for v : Integer.subrange(0, n - 1-1) do ( execute ((Sequence{v + 1}->union(Sequence{v + 2}->union(Sequence{ 0 }))) : e) ; execute ((Sequence{v + 1}->union(Sequence{v + 2}->union(Sequence{ (2)->pow(v) }))) : e) ; if MathLib.bitwiseAnd((l /(2->pow(v))), 1) then ( execute ((Sequence{v + 1}->union(Sequence{n}->union(Sequence{ l - (2)->pow(v) }))) : e) ; l := l - (2)->pow(v) ) else skip) ; execute (n)->display() ; for x : e do ( execute (StringLib.sumStringsWithSeparator(((x)->collect( _x | (OclType["String"])->apply(_x) )), " "))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Sum(N): SumOfPrimeDivisors=[0]*(N+1) for i in range(2,N+1): if(SumOfPrimeDivisors[i]==0): for j in range(i,N+1,i): SumOfPrimeDivisors[j]+=i return SumOfPrimeDivisors[N] N=60 print("Sum of prime","divisors of 60 is",Sum(N)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 60 ; execute ("Sum of prime")->display();; operation Sum(N : OclAny) : OclAny pre: true post: true activity: var SumOfPrimeDivisors : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; for i : Integer.subrange(2, N + 1-1) do ( if (SumOfPrimeDivisors[i+1] = 0) then ( for j : Integer.subrange(i, N + 1-1)->select( $x | ($x - i) mod i = 0 ) do ( SumOfPrimeDivisors[j+1] := SumOfPrimeDivisors[j+1] + i) ) else skip) ; return SumOfPrimeDivisors[N+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for qwe in range(t): input() s=input() if len(s)==1 : print("YES") continue if len(s)==2 : if s=="11" or s=="00" : print("NO") else : print("YES") continue print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for qwe : Integer.subrange(0, t-1) do ( input() ; var s : String := (OclFile["System.in"]).readLine() ; if (s)->size() = 1 then ( execute ("YES")->display() ; continue ) else skip ; if (s)->size() = 2 then ( if s = "11" or s = "00" then ( execute ("NO")->display() ) else ( execute ("YES")->display() ) ; continue ) else skip ; execute ("NO")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) s=input() if n>2 : return 'NO' if n==1 : return 'YES' if s[0]!=s[1]: return 'YES' return 'NO' T=int(input()) for t in range(T): print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(0, T-1) do ( execute (solve())->display()); operation solve() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; if n > 2 then ( return 'NO' ) else skip ; if n = 1 then ( return 'YES' ) else skip ; if s->first() /= s[1+1] then ( return 'YES' ) else skip ; return 'NO'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) s=input() if n==1 : print("YES") elif n==2 : if s[0]!=s[1]: print("YES") else : print("NO") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; if n = 1 then ( execute ("YES")->display() ) else (if n = 2 then ( if s->first() /= s[1+1] then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else ( execute ("NO")->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: print('YNEOS'[len(s)>len({*s}): : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( execute ('YNEOS'(subscript (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))) > (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom { (dictorsetmaker (testlist_comp (star_expr * (expr (atom (name s)))))) }))))))) )))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) s=input() if n==1 or(n==2 and s[0]!=s[1]): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; if n = 1 or (n = 2 & s->first() /= s[1+1]) then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def testcase_ends(): n=int(input()) if n==0 : return 1 sub=[input().split()for i in range(n)] gamma=input() delta=input() q=deque() q.append((gamma,0)) res=10000 while q : s,i=q.popleft() for alpha,beta in sub : if alpha not in s : continue t=s.replace(alpha,beta) if t==delta : res=min(res,i+1) continue elif len(t)>=len(delta): continue q.append((t,i+1)) if res==10000 : res=-1 print(res) return 0 def main(): while not testcase_ends(): pass if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation testcase_ends() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( return 1 ) else skip ; var sub : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (input().split())) ; var gamma : String := (OclFile["System.in"]).readLine() ; var delta : String := (OclFile["System.in"]).readLine() ; var q : Sequence := () ; execute ((Sequence{gamma, 0}) : q) ; var res : int := 10000 ; while q do ( var s : OclAny := null; var i : OclAny := null; Sequence{s,i} := q->first() ; q := q->tail() ; for _tuple : sub do (var _indx : int := 1; var alpha : OclAny := _tuple->at(_indx); _indx := _indx + 1; var beta : OclAny := _tuple->at(_indx); if (s)->excludes(alpha) then ( continue ) else skip ; var t : String := s.replace(alpha, beta) ; if t = delta then ( res := Set{res, i + 1}->min() ; continue ) else (if ((t)->size()->compareTo((delta)->size())) >= 0 then ( continue ) else skip) ; execute ((Sequence{t, i + 1}) : q))) ; if res = 10000 then ( res := -1 ) else skip ; execute (res)->display() ; return 0; operation main() pre: true post: true activity: while not(testcase_ends()) do ( skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def divisibleBy36(num): l=len(num) if(l==0): return("No") if(l==1 and num[0]!='0'): return("No") two_digit_num=(((int)(num[l-2]))*10+(int)(num[l-1])) if(two_digit_num % 4!=0): return "No" sm=0 for i in range(0,l): sm=sm+(int)(num[i]) if(sm % 9!=0): return("No") return("Yes") num="92567812197966231384" print(divisibleBy36(num)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; num := "92567812197966231384" ; execute (divisibleBy36(num))->display(); operation divisibleBy36(num : OclAny) : OclAny pre: true post: true activity: var l : int := (num)->size() ; if (l = 0) then ( return ("No") ) else skip ; if (l = 1 & num->first() /= '0') then ( return ("No") ) else skip ; var two_digit_num : double := (((OclType["int"])(num[l - 2+1])) * 10 + (OclType["int"])(num[l - 1+1])) ; if (two_digit_num mod 4 /= 0) then ( return "No" ) else skip ; var sm : int := 0 ; for i : Integer.subrange(0, l-1) do ( sm := sm + (OclType["int"])(num[i+1])) ; if (sm mod 9 /= 0) then ( return ("No") ) else skip ; return ("Yes"); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline n,currently=map(int,input().split()); position=[]; dic=dict() for i in range(n): dx,dy,popu=map(int,input().split()) if(dx**2+dy**2)**.5 in dic : dic[(dx**2+dy**2)**.5]+=popu else : dic[(dx**2+dy**2)**.5]=popu if currently>=10**6 : print(-1) else : arr=list(dic.keys()); arr.sort(); cum=[dic[arr[0]]+currently]; lenth=len(arr); ans=-1 for i in range(1,lenth): cum.append(cum[-1]+dic[arr[i]]) l=0 ; r=lenth-1 while l<=r : mid=(r+l)//2 if cum[mid]>=10**6 : ans=mid r=mid-1 else : l=mid+1 if ans<0 : print(-1) else : print(arr[ans]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; var n : OclAny := null; var currently : OclAny := null; Sequence{n,currently} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var position : Sequence := Sequence{}; var dic : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( var dx : OclAny := null; var dy : OclAny := null; var popu : OclAny := null; Sequence{dx,dy,popu} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (dic)->includes((((dx)->pow(2) + (dy)->pow(2)))->pow(.5)) then ( dic[(((dx)->pow(2) + (dy)->pow(2)))->pow(.5)+1] := dic[(((dx)->pow(2) + (dy)->pow(2)))->pow(.5)+1] + popu ) else ( dic[(((dx)->pow(2) + (dy)->pow(2)))->pow(.5)+1] := popu )) ; if (currently->compareTo((10)->pow(6))) >= 0 then ( execute (-1)->display() ) else ( var arr : Sequence := (dic.keys()); arr := arr->sort(); var cum : Sequence := Sequence{ dic[arr->first()+1] + currently }; var lenth : int := (arr)->size(); var ans : int := -1 ; for i : Integer.subrange(1, lenth-1) do ( execute ((cum->last() + dic[arr[i+1]+1]) : cum)) ; var l : int := 0; var r : double := lenth - 1 ; while (l->compareTo(r)) <= 0 do ( var mid : int := (r + l) div 2 ; if (cum[mid+1]->compareTo((10)->pow(6))) >= 0 then ( ans := mid ; r := mid - 1 ) else ( l := mid + 1 )) ; if ans < 0 then ( execute (-1)->display() ) else ( execute (arr[ans+1])->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def solve(): numLocation,totalPeople=map(int,input().split()) location=dict() for i in range(numLocation): x,y,people=map(int,input().split()) r=x*x+y*y if r in location : location[r]+=people else : location[r]=people radius=[] for r in location : radius.append(r) radius.sort() for r in radius : totalPeople+=location[r] if totalPeople>=1000000 : print(math.sqrt(r)) return print("-1") solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; solve(); operation solve() pre: true post: true activity: var numLocation : OclAny := null; var totalPeople : OclAny := null; Sequence{numLocation,totalPeople} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var location : Map := (arguments ( )) ; for i : Integer.subrange(0, numLocation-1) do ( var x : OclAny := null; var y : OclAny := null; var people : OclAny := null; Sequence{x,y,people} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var r : double := x * x + y * y ; if (location)->includes(r) then ( location[r+1] := location[r+1] + people ) else ( location[r+1] := people )) ; var radius : Sequence := Sequence{} ; for r : location->keys() do ( execute ((r) : radius)) ; radius := radius->sort() ; for r : radius do ( totalPeople := totalPeople + location[r+1] ; if totalPeople >= 1000000 then ( execute ((r)->sqrt())->display() ; return ) else skip) ; execute ("-1")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np H,W=list(map(int,input().split())) mat=np.zeros((H,W)) original_mat=[] removed_line=[] removed_column=[] for i in range(H): row=input() line=[] for j,c in enumerate(row): if c=="#" : mat[i,j]=1 if np.sum(mat[i,:])==0 : removed_line.append(i) else : original_mat.append(row) for i in range(W): if np.sum(mat[:,i])==0 : removed_column.append(i) for row in original_mat : for i,c in enumerate(row): if i not in removed_column : print(c,end="") print("\n",end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mat : Sequence := MatrixLib.singleValueMatrix(Sequence{H, W}, 0.0) ; var original_mat : Sequence := Sequence{} ; var removed_line : Sequence := Sequence{} ; var removed_column : Sequence := Sequence{} ; for i : Integer.subrange(0, H-1) do ( var row : String := (OclFile["System.in"]).readLine() ; var line : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (row)->size())->collect( _indx | Sequence{_indx-1, (row)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if c = "#" then ( mat[i+1][j+1] := 1 ) else skip) ; if MatrixLib.sumMatrix(mat[i+1]) = 0 then ( execute ((i) : removed_line) ) else ( execute ((row) : original_mat) )) ; for i : Integer.subrange(0, W-1) do ( if MatrixLib.sumMatrix(mat->collect( _r | _r[i+1] )) = 0 then ( execute ((i) : removed_column) ) else skip) ; for row : original_mat do ( for _tuple : Integer.subrange(1, (row)->size())->collect( _indx | Sequence{_indx-1, (row)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if (removed_column)->excludes(i) then ( execute (c)->display() ) else skip) ; execute ("\n")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,s=map(int,input().split()) d=[] for i in range(n): x,y,k=map(int,input().split()) d.append((((x**2+y**2)**0.5),k)) d.sort() for i in range(n): s+=d[i][1] if s>=1e6 : print(d[i][0]) break else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; var k : OclAny := null; Sequence{x,y,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{((((x)->pow(2) + (y)->pow(2)))->pow(0.5)), k}) : d)) ; d := d->sort() ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name s)))) >= (comparison (expr (atom (number 1e6))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,s=map(int,input().split()) location=dict() city=set() for _ in range(n): x,y,k=map(int,input().split()) r=x**2+y**2 if r in location : location[r]+=k else : location[r]=k city.add(r) city=sorted(city) i=0 while True : s+=location[city[i]] if s>=1000000 : break i+=1 if i==len(city): break print("{:.7f}".format(city[i]**0.5)if icollect( _x | (OclType["int"])->apply(_x) ) ; var location : Map := (arguments ( )) ; var city : Set := Set{}->union(()) ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; var k : OclAny := null; Sequence{x,y,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var r : double := (x)->pow(2) + (y)->pow(2) ; if (location)->includes(r) then ( location[r+1] := location[r+1] + k ) else ( location[r+1] := k ) ; execute ((r) : city)) ; city := city->sort() ; var i : int := 0 ; while true do ( s := s + location[city[i+1]+1] ; if s >= 1000000 then ( break ) else skip ; i := i + 1 ; if i = (city)->size() then ( break ) else skip) ; execute (if (i->compareTo((city)->size())) < 0 then StringLib.interpolateStrings("{:.7f}", Sequence{(city[i+1])->pow(0.5)}) else -1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def MaximumProduct(a,n): cntneg=0 cntzero=0 used=[0]*n pos=-1 for i in range(n): if(a[i]==0): used[i]=1 cntzero+=1 if(a[i]<0): cntneg+=1 if(pos==-1 or abs(a[pos])>abs(a[i])): pos=i if(cntneg % 2==1): used[pos]=1 if(cntzero==n or(cntzero==n-1 and cntneg==1)): for i in range(n-1): print(1," ",i+1," ",i+2) return lst=-1 for i in range(n): if(used[i]): if(lst!=-1): print(1," ",lst+1," ",i+1) lst=i if(lst!=-1): print(2," ",lst+1) lst=-1 for i in range(n): if(not used[i]): if(lst!=-1): print(1," ",lst+1," ",i+1) lst=i if __name__=="__main__" : a=[5,-2,0,1,-3] n=len(a) MaximumProduct(a,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{5}->union(Sequence{-2}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ -3 })))) ; n := (a)->size() ; MaximumProduct(a, n) ) else skip; operation MaximumProduct(a : OclAny, n : OclAny) pre: true post: true activity: var cntneg : int := 0 ; var cntzero : int := 0 ; var used : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var pos : int := -1 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] = 0) then ( used[i+1] := 1 ; cntzero := cntzero + 1 ) else skip ; if (a[i+1] < 0) then ( cntneg := cntneg + 1 ; if (pos = -1 or ((a[pos+1])->abs()->compareTo((a[i+1])->abs())) > 0) then ( pos := i ) else skip ) else skip) ; if (cntneg mod 2 = 1) then ( used[pos+1] := 1 ) else skip ; if (cntzero = n or (cntzero = n - 1 & cntneg = 1)) then ( for i : Integer.subrange(0, n - 1-1) do ( execute (1)->display()) ; return ) else skip ; var lst : int := -1 ; for i : Integer.subrange(0, n-1) do ( if (used[i+1]) then ( if (lst /= -1) then ( execute (1)->display() ) else skip ; lst := i ) else skip) ; if (lst /= -1) then ( execute (2)->display() ) else skip ; lst := -1 ; for i : Integer.subrange(0, n-1) do ( if (not(used[i+1])) then ( if (lst /= -1) then ( execute (1)->display() ) else skip ; lst := i ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def equalize(arr,n,k): min_ele=min(arr); flag=True ; for i in range(n): if(not((arr[i]+k)>=(min_ele+k)and(min_ele+k)>=(arr[i]-k))): flag=False ; break ; if(flag): return min_ele+k ; else : return-1 ; if __name__=='__main__' : K=2 ; arr=[1,2,3,4,5]; N=len(arr) print(equalize(arr,N,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var K : int := 2; ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))); ; var N : int := (arr)->size() ; execute (equalize(arr, N, K))->display() ) else skip; operation equalize(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var min_ele : OclAny := (arr)->min(); ; var flag : boolean := true; ; for i : Integer.subrange(0, n-1) do ( if (not((((arr[i+1] + k)->compareTo((min_ele + k))) >= 0 & ((min_ele + k)->compareTo((arr[i+1] - k))) >= 0))) then ( flag := false; ; break; ) else skip) ; if (flag) then ( return min_ele + k; ) else ( return -1; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) a=list(map(int,input().split())) res=a[0] for i in range(1,n): res &=a[i] print(res) for _ in range(int(input())): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve()); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : OclAny := a->first() ; for i : Integer.subrange(1, n-1) do ( res := res & a[i+1]) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) numbers=list(map(int,input().split())) x=numbers[0] for number in numbers[1 :]: x=x & number print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var numbers : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := numbers->first() ; for number : numbers->tail() do ( x := MathLib.bitwiseAnd(x, number)) ; execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import queue while 1 : n=int(input()) if n==0 : break dic={} for i in range(n): k,s=input().split() dic[k]=s s=input() ans=input() q=queue.Queue() q.put((s,0)) find=False while not q.empty(): s=q.get() if s[0]==ans : print(s[1]) q=queue.Queue() find=True if not find : for k in dic.keys(): t=s[0].replace(k,dic[k]) if len(t)<=len(ans)and s[0]!=t : q.put((t,s[1]+1)) if not find : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var dic : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var k : OclAny := null; var s : OclAny := null; Sequence{k,s} := input().split() ; dic[k+1] := s) ; var s : String := (OclFile["System.in"]).readLine() ; var ans : String := (OclFile["System.in"]).readLine() ; var q : OclAny := queue.Queue() ; q.put(Sequence{s, 0}) ; var find : boolean := false ; while not(q.empty()) do ( s := q.get() ; if s->first() = ans then ( execute (s[1+1])->display() ; q := queue.Queue() ; find := true ) else skip ; if not(find) then ( for k : dic.keys() do ( var t : OclAny := s->first().replace(k, dic[k+1]) ; if ((t)->size()->compareTo((ans)->size())) <= 0 & s->first() /= t then ( q.put(Sequence{t, s[1+1] + 1}) ) else skip) ) else skip) ; if not(find) then ( execute (-1)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(0,int(input())): input() v=list(map(int,input().split())) t=v[0] for i in v[1 :]: t &=i print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( input() ; var v : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : OclAny := v->first() ; for i : v->tail() do ( t := t & i) ; execute (t)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- TC=int(input()) while TC>0 : TC-=1 n=int(input()) print(eval(input().replace(' ','&'))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var TC : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while TC > 0 do ( TC := TC - 1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (input().replace(' ', '&'))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): n=int(input()) arr=tuple(map(int,input().split())) ans=arr[0] for x in arr : ans=ans & x print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : OclAny := arr->first() ; for x : arr do ( ans := MathLib.bitwiseAnd(ans, x)) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findFourElements(arr,n,X): mp={} for i in range(n-1): for j in range(i+1,n): mp[arr[i]+arr[j]]=[i,j] for i in range(n-1): for j in range(i+1,n): summ=arr[i]+arr[j] if(X-summ)in mp : p=mp[X-summ] if(p[0]!=i and p[0]!=j and p[1]!=i and p[1]!=j): print(arr[i],",",arr[j],",",arr[p[0]],",",arr[p[1]],sep="") return arr=[10,20,30,40,1,2] n=len(arr) X=91 findFourElements(arr,n,X) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{10}->union(Sequence{20}->union(Sequence{30}->union(Sequence{40}->union(Sequence{1}->union(Sequence{ 2 }))))) ; n := (arr)->size() ; X := 91 ; findFourElements(arr, n, X); operation findFourElements(arr : OclAny, n : OclAny, X : OclAny) pre: true post: true activity: var mp : OclAny := Set{} ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(i + 1, n-1) do ( mp[arr[i+1] + arr[j+1]+1] := Sequence{i}->union(Sequence{ j }))) ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(i + 1, n-1) do ( var summ : OclAny := arr[i+1] + arr[j+1] ; if (mp)->includes((X - summ)) then ( var p : OclAny := mp[X - summ+1] ; if (p->first() /= i & p->first() /= j & p[1+1] /= i & p[1+1] /= j) then ( execute (arr[i+1])->display() ; return ) else skip ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w=map(int,input().split()) block=[input()for _ in range(h)] ok=[[False]*w for _ in range(h)] for y in range(h): for x in range(w): if block[y][x]=='.' : nowy=0 nowx=0 flag=True while nowycollect( _x | (OclType["int"])->apply(_x) ) ; var block : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var ok : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ false }, w))) ; for y : Integer.subrange(0, h-1) do ( for x : Integer.subrange(0, w-1) do ( if block[y+1][x+1] = '.' then ( var nowy : int := 0 ; var nowx : int := 0 ; var flag : boolean := true ; while (nowy->compareTo(h)) < 0 do ( if block[nowy+1][x+1] = '.' then ( nowy := nowy + 1 ) else ( flag := false ; break )) ; if flag then ( for y_ : Integer.subrange(0, h-1) do ( ok[y_+1][x+1] := true) ) else skip ; flag := true ; while (nowx->compareTo(w)) < 0 do ( if block[y+1][nowx+1] = '.' then ( nowx := nowx + 1 ) else ( flag := false ; break )) ; if flag then ( for x_ : Integer.subrange(0, w-1) do ( ok[y+1][x_+1] := true) ) else skip ) else skip)) ; var ans : Sequence := Sequence{} ; for y : Integer.subrange(0, h-1) do ( var a : String := "" ; for x : Integer.subrange(0, w-1) do ( if ok[y+1][x+1] /= true then ( a := a + block[y+1][x+1] ) else skip) ; if (a)->size() /= 0 then ( execute ((a) : ans) ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def ntests(L,P,C): ratio=P*1.0/L if ratio<=C : return 0 if L==1 and P==3 : return 1 testpoint=int(L*(ratio**0.5)) count=max(1+ntests(L,testpoint,C),1+ntests(testpoint,P,C)) if(testpoint*testpoint==L*P or testpoint+1==P): return count count2=max(1+ntests(L,testpoint+1,C),1+ntests(testpoint+1,P,C)) return min(count,count2) infile=sys.stdin T=int(infile.readline().strip()) for i in xrange(T): L,P,C=map(int,infile.readline().strip().split()) result=ntests(L,P,C) print("Case #%d: %s" %(i+1,str(result))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var infile : OclFile := OclFile["System.in"] ; var T : int := ("" + ((infile.readLine()->trim())))->toInteger() ; for i : xrange(T) do ( Sequence{L,P,C} := (infile.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var result : OclAny := ntests(L, P, C) ; execute (StringLib.format("Case #%d: %s",Sequence{i + 1, ("" + ((result)))}))->display()); operation ntests(L : OclAny, P : OclAny, C : OclAny) : OclAny pre: true post: true activity: var ratio : double := P * 1.0 / L ; if (ratio->compareTo(C)) <= 0 then ( return 0 ) else skip ; if L = 1 & P = 3 then ( return 1 ) else skip ; var testpoint : int := ("" + ((L * ((ratio)->pow(0.5)))))->toInteger() ; var count : OclAny := Set{1 + ntests(L, testpoint, C), 1 + ntests(testpoint, P, C)}->max() ; if (testpoint * testpoint = L * P or testpoint + 1 = P) then ( return count ) else skip ; var count2 : OclAny := Set{1 + ntests(L, testpoint + 1, C), 1 + ntests(testpoint + 1, P, C)}->max() ; return Set{count, count2}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math T=int(input()) for testCase in range(0,T): line=input().split() L=int(line[0]) P=int(line[1]) C=int(line[2]) a=math.log(P/L,C) a=math.ceil(a) b=math.ceil(math.log(a,2)) print('Case #{0}:{1}'.format(testCase+1,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for testCase : Integer.subrange(0, T-1) do ( var line : OclAny := input().split() ; var L : int := ("" + ((line->first())))->toInteger() ; var P : int := ("" + ((line[1+1])))->toInteger() ; var C : int := ("" + ((line[2+1])))->toInteger() ; var a : double := (P / L, C)->log() ; a := (a)->ceil() ; var b : double := ((a, 2)->log())->ceil() ; execute (StringLib.interpolateStrings('Case #{0}:{1}', Sequence{testCase + 1, b}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import log,ceil def solve_problem(L,P,C): intervals=int(ceil(log((P+L-1)/L,C))) tests=0 while intervals>1 : tests+=1 intervals=(intervals+1)/2 return tests def run_process(args): return solve_problem(*args) def process_file(fin,fout): def get_problem(): return map(int,fin.readline().split(' ')) numLines=int(fin.readline()) problem_list=[get_problem()for i in range(numLines)] if False : from multiprocessing import Pool p=Pool(8) solution_list=p.map(run_process,problem_list) else : solution_list=map(run_process,problem_list) for i,s in enumerate(solution_list): fout.write("Case #%s: %s\n" %(i+1,s)) if __name__=='__main__' : from sys import argv process_file(open(argv[1]),open(argv[1].replace("in","out"),"w")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( skip ; process_file(OclFile.newOclFile_Write(OclFile.newOclFile(argv[1+1])), OclFile.newOclFile_Write(OclFile.newOclFile(argv[1+1].replace("in", "out")))) ) else skip; operation solve_problem(L : OclAny, P : OclAny, C : OclAny) : OclAny pre: true post: true activity: var intervals : int := ("" + ((ceil(log((P + L - 1) / L, C)))))->toInteger() ; var tests : int := 0 ; while intervals > 1 do ( tests := tests + 1 ; intervals := (intervals + 1) / 2) ; return tests; operation run_process(args : OclAny) : OclAny pre: true post: true activity: return solve_problem((argument * (test (logical_test (comparison (expr (atom (name args)))))))); operation process_file(fin : OclAny, fout : OclAny) pre: true post: true activity: skip ; var numLines : int := ("" + ((fin.readLine())))->toInteger() ; var problem_list : Sequence := Integer.subrange(0, numLines-1)->select(i | true)->collect(i | (get_problem())) ; if false then ( skip ; var p : OclAny := Pool(8) ; var solution_list : OclAny := p.map(run_process, problem_list) ) else ( solution_list := (problem_list)->collect( _x | (run_process)->apply(_x) ) ) ; for _tuple : Integer.subrange(1, (solution_list)->size())->collect( _indx | Sequence{_indx-1, (solution_list)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); fout.write(StringLib.format("Case #%s: %s\n",Sequence{i + 1, s}))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math inf='B-large.in' f_in=open(inf) f_out=open('out.txt','w') def find_parts(l,p,c): parts=1 t=l*c while t

>f_out,'Case #'+str(case)+": "+str(ans) T=int(f_in.next()) for case in xrange(1,T+1): slove(case) f_out.close() f_in.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var Math_PINFINITY : String := 'B-large.in' ; var f_in : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(Math_PINFINITY)) ; var f_out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('out.txt')) ; skip ; skip ; var T : int := ("" + ((f_in.next())))->toInteger() ; for case : xrange(1, T + 1) do ( slove(case)) ; f_out.closeFile() ; f_in.closeFile(); operation find_parts(l : OclAny, p : OclAny, c : OclAny) : OclAny pre: true post: true activity: var parts : int := 1 ; var t : double := l * c ; while (t->compareTo(p)) < 0 do ( parts := parts + 1 ; t := t * c) ; return parts; operation slove(case : OclAny) pre: true post: true activity: var ln : OclAny := f_in.next().split(' ') ; Sequence{l,p,c} := Sequence{("" + ((ln->first())))->toInteger(),("" + ((ln[1+1])))->toInteger(),("" + ((ln[2+1])))->toInteger()} ; var ans : int := ("" + ((((find_parts(l, p, c), 2)->log())->ceil())))->toInteger() ; print /(2->pow(f_out)) ; (expr (expr (expr (expr (atom 'Case #')) + (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name case)))))))) ))))) + (expr (atom ": "))) + (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,itertools from pprint import pprint from collections import namedtuple import math from decimal import Decimal from fractions import Fraction output_line="Case #{X:d}:{Y:d}" Rope=namedtuple("Rope","a b") if __name__=="__main__" : infile,outfile=sys.argv[1 :] with open(infile,"r")as inhandle,open(outfile,"w")as outhandle : T=int(inhandle.readline()) for t in range(T): L,P,C=map(int,inhandle.readline().split()) stage1=math.log(Fraction(P,L),C) stage2=math.log(stage1,2) num_tests=max(0,math.ceil(stage2)) print(stage1,stage2,num_tests) print(output_line.format(X=t+1,Y=num_tests),file=outhandle) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var output_line : String := "Case #{X:d}:{Y:d}" ; var Rope : OclAny := namedtuple("Rope", "a b") ; if __name__ = "__main__" then ( var infile : OclAny := null; var outfile : OclAny := null; Sequence{infile,outfile} := (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])) ; try (var inhandle : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(infile)); var outhandle : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(outfile)); var T : int := ("" + ((inhandle.readLine())))->toInteger() ; for t : Integer.subrange(0, T-1) do ( var L : OclAny := null; var P : OclAny := null; var C : OclAny := null; Sequence{L,P,C} := (inhandle.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var stage1 : double := (Fraction(P, L), C)->log() ; var stage2 : double := (stage1, 2)->log() ; var num_tests : OclAny := Set{0, (stage2)->ceil()}->max() ; execute (stage1)->display() ; execute (StringLib.interpolateStrings(output_line, Sequence{(argument (test (logical_test (comparison (expr (atom (name X)))))) = (test (logical_test (comparison (expr (expr (atom (name t))) + (expr (atom (number (integer 1))))))))), (argument (test (logical_test (comparison (expr (atom (name Y)))))) = (test (logical_test (comparison (expr (atom (name num_tests)))))))}))->display())) catch (_e : OclException) do skip ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ls=list(map(int,input().split())) cnt=dict() ans=True for el in ls : if el not in cnt : cnt[el]=1 else : cnt[el]+=1 if cnt[el]>(n+1)//2 : ans=False if ans : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ls : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : Map := (arguments ( )) ; var ans : boolean := true ; for el : ls do ( if (cnt)->excludes(el) then ( cnt[el+1] := 1 ) else ( cnt[el+1] := cnt[el+1] + 1 ) ; if (cnt[el+1]->compareTo((n + 1) div 2)) > 0 then ( ans := false ) else skip) ; if ans then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): ans=max(i*j for i in range(100,1000)for j in range(100,1000)if str(i*j)==str(i*j)[: :-1]) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom (name j))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 100)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1000))))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 100)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1000))))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom (name j))))))))) ))))) == (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom (name j))))))))) ))) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ])))))))))))))->max() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def longestAlternating(arr,n): count=[None]*n count[n-1]=1 i=n-2 while i>=0 : if(arr[i]*arr[i+1]<0): count[i]=count[i+1]+1 else : count[i]=1 ; i=i-1 i=0 while iunion(Sequence{-1}->union(Sequence{-1}->union(Sequence{2}->union(Sequence{-2}->union(Sequence{ -3 }))))) ; n := (a)->size() ; longestAlternating(a, n);; operation longestAlternating(arr : OclAny, n : OclAny) pre: true post: true activity: var count : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; count[n - 1+1] := 1 ; var i : double := n - 2 ; while i >= 0 do ( if (arr[i+1] * arr[i + 1+1] < 0) then ( count[i+1] := count[i + 1+1] + 1 ) else ( count[i+1] := 1; ) ; i := i - 1) ; i := 0 ; while (i->compareTo(n)) < 0 do ( execute (count[i+1])->display() ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=1000001 visited=[0]*N ; goesTo=[0]*N ; def dfs(i): if(visited[i]==1): return 0 ; visited[i]=1 ; x=dfs(goesTo[i]); return(x+1); def noOfTranspositions(P,n): for i in range(1,n+1): visited[i]=0 ; for i in range(n): goesTo[P[i]]=i+1 ; transpositions=0 ; for i in range(1,n+1): if(visited[i]==0): ans=dfs(i); transpositions+=ans-1 ; return transpositions ; if __name__=="__main__" : permutation=[5,1,4,3,2]; n=len(permutation); print(noOfTranspositions(permutation,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 1000001 ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N); ; var goesTo : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N); ; skip ; skip ; if __name__ = "__main__" then ( var permutation : Sequence := Sequence{5}->union(Sequence{1}->union(Sequence{4}->union(Sequence{3}->union(Sequence{ 2 })))); ; n := (permutation)->size(); ; execute (noOfTranspositions(permutation, n))->display(); ) else skip; operation dfs(i : OclAny) pre: true post: true activity: if (visited[i+1] = 1) then ( return 0; ) else skip ; visited[i+1] := 1; ; var x : OclAny := dfs(goesTo[i+1]); ; return (x + 1);; operation noOfTranspositions(P : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(1, n + 1-1) do ( visited[i+1] := 0;) ; for i : Integer.subrange(0, n-1) do ( goesTo[P[i+1]+1] := i + 1;) ; var transpositions : int := 0; ; for i : Integer.subrange(1, n + 1-1) do ( if (visited[i+1] = 0) then ( var ans : OclAny := dfs(i); ; transpositions := transpositions + ans - 1; ) else skip) ; return transpositions;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d=int(input()) if d==22 : print('Christmas Eve Eve Eve') if d==23 : print('Christmas Eve Eve') if d==24 : print('Christmas Eve') if d==25 : print('Christmas') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if d = 22 then ( execute ('Christmas Eve Eve Eve')->display() ) else skip ; if d = 23 then ( execute ('Christmas Eve Eve')->display() ) else skip ; if d = 24 then ( execute ('Christmas Eve')->display() ) else skip ; if d = 25 then ( execute ('Christmas')->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print('Christmas'+' Eve'*(25-int(input()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ('Christmas' + StringLib.nCopies(' Eve', (25 - ("" + (((OclFile["System.in"]).readLine())))->toInteger())))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def resolve(): h,w=map(int,input().split()) grid=[] for _ in range(h): grid.append(list(input())) for i in range(h): removable=True for j in range(w): if grid[i][j]=='#' : removable=False break if removable : for j in range(w): grid[i][j]=False for i in range(w): for j in range(h): removable=True if grid[j][i]=='#' : removable=False break if removable : for j in range(h): grid[j][i]=False for r in grid : ans="" for el in r : if el : ans+=el if ans : print(ans) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; resolve(); operation resolve() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var grid : Sequence := Sequence{} ; for _anon : Integer.subrange(0, h-1) do ( execute ((((OclFile["System.in"]).readLine())->characters()) : grid)) ; for i : Integer.subrange(0, h-1) do ( var removable : boolean := true ; for j : Integer.subrange(0, w-1) do ( if grid[i+1][j+1] = '#' then ( removable := false ; break ) else skip) ; if removable then ( for j : Integer.subrange(0, w-1) do ( grid[i+1][j+1] := false) ) else skip) ; for i : Integer.subrange(0, w-1) do ( for j : Integer.subrange(0, h-1) do ( removable := true ; if grid[j+1][i+1] = '#' then ( removable := false ; break ) else skip) ; if removable then ( for j : Integer.subrange(0, h-1) do ( grid[j+1][i+1] := false) ) else skip) ; for r : grid do ( var ans : String := "" ; for el : r do ( if el then ( ans := ans + el ) else skip) ; if ans then ( execute (ans)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() a=int(a) if a==25 : print("Christmas") if a==24 : print("Christmas Eve") if a==23 : print("Christmas Eve Eve") if a==22 : print("Christmas Eve Eve Eve") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; a := ("" + ((a)))->toInteger() ; if a = 25 then ( execute ("Christmas")->display() ) else skip ; if a = 24 then ( execute ("Christmas Eve")->display() ) else skip ; if a = 23 then ( execute ("Christmas Eve Eve")->display() ) else skip ; if a = 22 then ( execute ("Christmas Eve Eve Eve")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=['Christmas'] c=['Eve']*(25-a) b.extend(c) print(' '.join(b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := Sequence{ 'Christmas' } ; var c : Sequence := MatrixLib.elementwiseMult(Sequence{ 'Eve' }, (25 - a)) ; b := b->union(c) ; execute (StringLib.sumStringsWithSeparator((b), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d=int(input()) D=25-d s="Christmas" t=" Eve" for i in range(D): s=s+t print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var D : double := 25 - d ; var s : String := "Christmas" ; var t : String := " Eve" ; for i : Integer.subrange(0, D-1) do ( s := s + t) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) w=input().split() for i in range(len(w)): w[i]=int(w[i]) w.sort() ans=1000000000 for i in range(len(w)): for j in range(i+1,len(w)): add=False sums=0 for k in range(len(w)): if(k==i or k==j): continue if(not add): sums-=w[k] add=True else : sums+=w[k] add=False ans=min(ans,sums) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : OclAny := input().split() ; for i : Integer.subrange(0, (w)->size()-1) do ( w[i+1] := ("" + ((w[i+1])))->toInteger()) ; w := w->sort() ; var ans : int := 1000000000 ; for i : Integer.subrange(0, (w)->size()-1) do ( for j : Integer.subrange(i + 1, (w)->size()-1) do ( var add : boolean := false ; var sums : int := 0 ; for k : Integer.subrange(0, (w)->size()-1) do ( if (k = i or k = j) then ( continue ) else skip ; if (not(add)) then ( sums := sums - w[k+1] ; add := true ) else ( sums := sums + w[k+1] ; add := false )) ; ans := Set{ans, sums}->min())) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=input().split() possible=True for i in set(m): if m.count(i)>=n/2+1 : possible=False break print('YES' if possible else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : OclAny := input().split() ; var possible : boolean := true ; for i : Set{}->union((m)) do ( if (m->count(i)->compareTo(n / 2 + 1)) >= 0 then ( possible := false ; break ) else skip) ; execute (if possible then 'YES' else 'NO' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import inf n=int(input()) n*=2 nums=[int(x)for x in input().split()] ans=inf for i in range(n-1): for j in range(i+1,n): v=nums[: i]+nums[i+1 : j]+nums[j+1 :] v.sort() length=len(v) s=0 for k in range(0,length,2): s+=v[k+1]-v[k] ans=min(ans,s) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; n := n * 2 ; var nums : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : double := Math_PINFINITY ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(i + 1, n-1) do ( var v : OclAny := nums.subrange(1,i) + nums.subrange(i + 1+1, j) + nums.subrange(j + 1+1) ; v := v->sort() ; var length : int := (v)->size() ; var s : int := 0 ; for k : Integer.subrange(0, length-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( s := s + v[k + 1+1] - v[k+1]) ; ans := Set{ans, s}->min())) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def raz(a): ans=0 for i in range(0,len(a),2): ans+=a[i+1]-a[i] return ans def creat(a,x): y=x+1 ans=[] while ytoInteger() ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; ans := Sequence{} ; for i : Integer.subrange(0, n * 2 - 1-1) do ( execute ((creat(a, i)) : ans)) ; execute ((ans)->min())->display(); operation raz(a : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, (a)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( ans := ans + a[i + 1+1] - a[i+1]) ; return ans; operation creat(a : OclAny, x : OclAny) : OclAny pre: true post: true activity: var y : OclAny := x + 1 ; ans := Sequence{} ; while (y->compareTo((a)->size())) < 0 do ( execute ((raz(a.subrange(1,x) + a.subrange(x + 1+1, y) + a.subrange(y + 1+1))) : ans) ; y := y + 2) ; return (ans)->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(x)for x in input().split()] a.sort() def calc(arr): s=0 for i in range(0,len(arr),2): s+=arr[i+1]-arr[i] return s ans=99999999 for i in range(2*n): for j in range(i,2*n): if i==j : continue b=a[: i]+a[i+1 : j]+a[j+1 :] ans=min(ans,calc(b)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; a := a->sort() ; skip ; var ans : int := 99999999 ; for i : Integer.subrange(0, 2 * n-1) do ( for j : Integer.subrange(i, 2 * n-1) do ( if i = j then ( continue ) else skip ; var b : OclAny := a.subrange(1,i) + a.subrange(i + 1+1, j) + a.subrange(j + 1+1) ; ans := Set{ans, calc(b)}->min())) ; execute (ans)->display(); operation calc(arr : OclAny) : OclAny pre: true post: true activity: var s : int := 0 ; for i : Integer.subrange(0, (arr)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( s := s + arr[i + 1+1] - arr[i+1]) ; return s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input())*2 a=[int(i)for i in input().split()] a.sort() ans=1000000000000 for i in range(n): for j in range(i+1,n): w=a[: i]+a[i+1 : j]+a[j+1 :] s=sum(w[i+1]-w[i]for i in range(0,n-2,2)) ans=min(s,ans) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() * 2 ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; a := a->sort() ; var ans : int := 1000000000000 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( var w : OclAny := a.subrange(1,i) + a.subrange(i + 1+1, j) + a.subrange(j + 1+1) ; var s : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))) - (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))))))))->sum() ; ans := Set{s, ans}->min())) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def knowPair(a,b,n,s,m): i=0 rem=0 count_b=0 flag=0 while(i<=a): rem=s-(n*i) count_b=rem//m if(rem % m==0 and count_b<=b): flag=1 i+=1 if(flag==1): print("YES") else : print("NO") if __name__=='__main__' : A=1 B=2 n=3 S=4 m=2 knowPair(A,B,n,S,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var A : int := 1 ; var B : int := 2 ; n := 3 ; var S : int := 4 ; m := 2 ; knowPair(A, B, n, S, m) ) else skip; operation knowPair(a : OclAny, b : OclAny, n : OclAny, s : OclAny, m : OclAny) pre: true post: true activity: var i : int := 0 ; var rem : int := 0 ; var count_b : int := 0 ; var flag : int := 0 ; while ((i->compareTo(a)) <= 0) do ( rem := s - (n * i) ; count_b := rem div m ; if (rem mod m = 0 & (count_b->compareTo(b)) <= 0) then ( flag := 1 ) else skip ; i := i + 1) ; if (flag = 1) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=[int(i)for i in input().split()] zeros=[int(i)for i in input().split()] ans=0 if not sum(zeros)% 2 : ans+=1 visited=[False for i in range(n)] ciclos=0 for i in range(n): if not visited[i]: ciclos+=1 j=i while not visited[j]: visited[j]=True j=p[j]-1 if ciclos==1 : ans+=0 else : ans+=ciclos print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var zeros : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : int := 0 ; if not((zeros)->sum() mod 2) then ( ans := ans + 1 ) else skip ; var visited : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (false)) ; var ciclos : int := 0 ; for i : Integer.subrange(0, n-1) do ( if not(visited[i+1]) then ( ciclos := ciclos + 1 ) else skip ; var j : OclAny := i ; while not(visited[j+1]) do ( visited[j+1] := true ; j := p[j+1] - 1)) ; if ciclos = 1 then ( ans := ans + 0 ) else ( ans := ans + ciclos ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(x)for x in input().split()] cnt5=0 cnt0=0 for i in range(n): if a[i]==5 : cnt5+=1 if a[i]==0 : cnt0+=1 if cnt0>0 and cnt5<9 : print('0') elif cnt0==0 : print('-1') else : for i in range(cnt5//9): print('555555555',end="") for i in range(cnt0): print('0',end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var cnt5 : int := 0 ; var cnt0 : int := 0 ; for i : Integer.subrange(0, n-1) do ( if a[i+1] = 5 then ( cnt5 := cnt5 + 1 ) else skip ; if a[i+1] = 0 then ( cnt0 := cnt0 + 1 ) else skip) ; if cnt0 > 0 & cnt5 < 9 then ( execute ('0')->display() ) else (if cnt0 = 0 then ( execute ('-1')->display() ) else ( for i : Integer.subrange(0, cnt5 div 9-1) do ( execute ('555555555')->display()) ; for i : Integer.subrange(0, cnt0-1) do ( execute ('0')->display()) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=[int(i)for i in input().split()] b=[int(i)for i in input().split()] ans=0 visited=[False for i in range(n)] for i in range(n): if visited[i]: continue ans+=1 while not visited[i]: visited[i]=True i=p[i]-1 if ans==1 : ans=0 ans+=(sum(b)+1)% 2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var b : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : int := 0 ; var visited : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (false)) ; for i : Integer.subrange(0, n-1) do ( if visited[i+1] then ( continue ) else skip ; ans := ans + 1 ; while not(visited[i+1]) do ( visited[i+1] := true ; var i : double := p[i+1] - 1)) ; if ans = 1 then ( ans := 0 ) else skip ; ans := ans + ((b)->sum() + 1) mod 2 ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- read=lambda : map(int,input().split()) n=int(input()) p=list(read()) b=list(read()) ans=(b.count(1)+1)% 2 was=[0]*n cnt=0 for i in range(n): if not was[i]: cnt+=1 v=i while not was[v]: was[v]=1 v=p[v]-1 if cnt>1 : ans+=cnt print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var read : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := (read->apply()) ; var b : Sequence := (read->apply()) ; var ans : int := (b->count(1) + 1) mod 2 ; var was : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( if not(was[i+1]) then ( cnt := cnt + 1 ; var v : OclAny := i ; while not(was[v+1]) do ( was[v+1] := 1 ; v := p[v+1] - 1) ) else skip) ; if cnt > 1 then ( ans := ans + cnt ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(input()) p=[int(i)for i in input().split()] b=[int(i)for i in input().split()] ans=0 num_cycles=0 checked=set() for i in range(n): if i in checked : continue checked.add(i) nxt=p[i]-1 while nxt!=i : checked.add(nxt) nxt=p[nxt]-1 num_cycles+=1 ans+=num_cycles if num_cycles!=1 else 0 ans+=(sum(b)% 2)==0 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var b : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : int := 0 ; var num_cycles : int := 0 ; var checked : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( if (checked)->includes(i) then ( continue ) else skip ; execute ((i) : checked) ; var nxt : double := p[i+1] - 1 ; while nxt /= i do ( execute ((nxt) : checked) ; nxt := p[nxt+1] - 1) ; num_cycles := num_cycles + 1) ; ans := ans + if num_cycles /= 1 then num_cycles else 0 endif ; ans := ans + ((b)->sum() mod 2) = 0 ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from statistics import mode n=int(input()) arr=[int(x)for x in input().split()] mode=mode(arr) m=arr.count(mode) if n>=2*m-1 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var mode : OclAny := mode(arr) ; var m : int := arr->count(mode) ; if (n->compareTo(2 * m - 1)) >= 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline class Unionfind : def __init__(self,n): self.par=[-1]*n self.rank=[1]*n def root(self,x): p=x while not self.par[p]<0 : p=self.par[p] while x!=p : tmp=x x=self.par[x] self.par[tmp]=p return p def unite(self,x,y): rx,ry=self.root(x),self.root(y) if rx==ry : return False if self.rank[rx]exists( _x | result = _x ); attribute par : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n); attribute rank : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, n); operation initialise(n : OclAny) : Unionfind pre: true post: true activity: self.par := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; self.rank := MatrixLib.elementwiseMult(Sequence{ 1 }, n); return self; operation root(x : OclAny) : OclAny pre: true post: true activity: var p : OclAny := x ; while not(self.par[p+1] < 0) do ( p := self.par[p+1]) ; while x /= p do ( var tmp : OclAny := x ; x := self.par[x+1] ; self.par[tmp+1] := p) ; return p; operation unite(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: var rx : OclAny := null; var ry : OclAny := null; Sequence{rx,ry} := Sequence{self.root(x),self.root(y)} ; if rx = ry then ( return false ) else skip ; if (self.rank[rx+1]->compareTo(self.rank[ry+1])) < 0 then ( var rx : OclAny := null; var ry : OclAny := null; Sequence{rx,ry} := Sequence{ry,rx} ) else skip ; self.par[rx+1] := self.par[rx+1] + self.par[ry+1] ; self.par[ry+1] := rx ; if self.rank[rx+1] = self.rank[ry+1] then ( self.rank[rx+1] := self.rank[rx+1] + 1 ) else skip; operation is_same(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: return self.root(x) = self.root(y); operation count(x : OclAny) : OclAny pre: true post: true activity: return -self.par[self.root(x)+1]; } class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; p := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var uf : Unionfind := (Unionfind.newUnionfind()).initialise(n) ; for i : Integer.subrange(0, n-1) do ( uf.unite(i, p[i+1] - 1)) ; var rs : Set := Set{}->union(((argument (test (logical_test (comparison (expr (atom (name uf)) (trailer . (name root) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))) ; if (rs)->size() = 1 then ( var ans : int := 0 ) else ( ans := (rs)->size() ) ; if b->count(1) mod 2 = 0 then ( ans := ans + 1 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- infilecode="CLI" import sys mapping={"A" : "A","B" : "B","C" : "C","D" : "D","E" : "E","X" : "example","S" : "-small","L" : "-large","P" : "-practice","0" : "-attempt0","1" : "-attempt1","2" : "-attempt2","z" : "-1","Z" : "-2","I" : ".in","T" : ".txt"} infile="".join(mapping[c]for c in infilecode) outfile=infile.replace(".in","")+".out.txt" sys.stdin=open(infile,'r') output=open(outfile,'w') T=int(input()) for case in range(1,T+1): N,K=map(int,input().split()) print(N,K) sizes=[N,N+1] num=[1,0] while K>sum(num): a,b=sizes K-=sum(num) sizes=[(a-1)//2,b//2] if a % 2==0 : num=[num[0],num[0]+num[1]*2] else : num=[num[0]*2+num[1],num[1]] print(sizes,num,K) if K<=num[1]: size=sizes[1] else : size=sizes[0] R=size//2 L=(size-1)//2 answer=str(R)+" "+str(L) print("Case #%d:" % case,answer) print("Case #%d:" % case,answer,file=output) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var infilecode : String := "CLI" ; skip ; var mapping : Map := Map{ "A" |-> "A" }->union(Map{ "B" |-> "B" }->union(Map{ "C" |-> "C" }->union(Map{ "D" |-> "D" }->union(Map{ "E" |-> "E" }->union(Map{ "X" |-> "example" }->union(Map{ "S" |-> "-small" }->union(Map{ "L" |-> "-large" }->union(Map{ "P" |-> "-practice" }->union(Map{ "0" |-> "-attempt0" }->union(Map{ "1" |-> "-attempt1" }->union(Map{ "2" |-> "-attempt2" }->union(Map{ "z" |-> "-1" }->union(Map{ "Z" |-> "-2" }->union(Map{ "I" |-> ".in" }->union(Map{ "T" |-> ".txt" }))))))))))))))) ; var infile : String := StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name mapping)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name c)))))))) ])))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name infilecode)))))))), "") ; var outfile : String := infile.replace(".in", "") + ".out.txt" ; OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile(infile)) ; var output : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(outfile)) ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for case : Integer.subrange(1, T + 1-1) do ( var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (N)->display() ; var sizes : Sequence := Sequence{N}->union(Sequence{ N + 1 }) ; var num : Sequence := Sequence{1}->union(Sequence{ 0 }) ; while (K->compareTo((num)->sum())) > 0 do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := sizes ; K := K - (num)->sum() ; sizes := Sequence{(a - 1) div 2}->union(Sequence{ b div 2 }) ; if a mod 2 = 0 then ( num := Sequence{num->first()}->union(Sequence{ num->first() + num[1+1] * 2 }) ) else ( num := Sequence{num->first() * 2 + num[1+1]}->union(Sequence{ num[1+1] }) ) ; execute (sizes)->display()) ; if (K->compareTo(num[1+1])) <= 0 then ( var size : OclAny := sizes[1+1] ) else ( size := sizes->first() ) ; var R : int := size div 2 ; var L : int := (size - 1) div 2 ; var answer : String := ("" + ((R))) + " " + ("" + ((L))) ; execute (StringLib.format("Case #%d:",case))->display() ; execute (StringLib.format("Case #%d:",case))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def split(n): return n//2,(n-1)//2 def merge(a,n1,n2,b,m1,m2): if n1==m1 : return a+a+b,n1,b,m2 elif n2==m2 : return a,n1,a+b+b,m2 else : raise Exception("Can't reduce{}".format((n1,n2,m1,m2))) def solve(a,n,b,m,k): if k<=a : return split(n) elif k<=a+b : return split(m) else : def t(*args): return tuple(args) return solve(*(merge(*(t(a)+split(n)+t(b)+split(m)))+t(k-a-b))) def main(): t=int(input()) for ti in range(t): n,k=map(int,input().split(" ")) print("Case #{}:{}".format(ti+1,' '.join(map(str,sorted(solve(1,n,0,n-1,k),reverse=True))))) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation split(n : OclAny) : OclAny pre: true post: true activity: return n div 2, (n - 1) div 2; operation merge(a : OclAny, n1 : OclAny, n2 : OclAny, b : OclAny, m1 : OclAny, m2 : OclAny) : OclAny pre: true post: true activity: if n1 = m1 then ( return a + a + b, n1, b, m2 ) else (if n2 = m2 then ( return a, n1, a + b + b, m2 ) else ( error ProgramException.newProgramException(StringLib.interpolateStrings("Can't reduce{}", Sequence{Sequence{n1, n2, m1, m2}})) ) ) ; operation solve(a : OclAny, n : OclAny, b : OclAny, m : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (k->compareTo(a)) <= 0 then ( return split(n) ) else (if (k->compareTo(a + b)) <= 0 then ( return split(m) ) else ( skip ; return solve((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name merge)) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (expr (atom (name t)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))) + (expr (atom (name split)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))) + (expr (atom (name t)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) ))))) + (expr (atom (name split)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name m)))))))) ))))))))) )))))))) )))) + (expr (atom (name t)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name k))) - (expr (atom (name a)))) - (expr (atom (name b))))))))) ))))))))) )))))))) ) ) ; operation main() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for ti : Integer.subrange(0, t-1) do ( Sequence{n,k} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{ti + 1, StringLib.sumStringsWithSeparator(((solve(1, n, 0, n - 1, k)->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))))->collect( _x | (OclType["String"])->apply(_x) )), ' ')}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import numpy as np import heapq def solve(n,k): intervals={n : 1} lens=[-n] ls=0 rs=0 while k>0 : val=-heapq.heappop(lens) num=intervals[val] del intervals[val] k=k-num ls=int((val-1)/2) rs=val-ls-1 if not ls in intervals : intervals[ls]=0 heapq.heappush(lens,-ls) if not rs in intervals : intervals[rs]=0 heapq.heappush(lens,-rs) intervals[rs]=intervals[rs]+num intervals[ls]=intervals[ls]+num return(max(ls,rs),min(ls,rs)) t=int(raw_input()) for i in range(1,t+1): n,m=[s for s in raw_input().split(" ")] data=[int(a)for a in list(str(n))] result=solve(int(n),int(m)) print("Case #{}:{}{}".format(i,result[0],result[1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var t : int := ("" + ((raw_input())))->toInteger() ; for i : Integer.subrange(1, t + 1-1) do ( var m : OclAny := null; Sequence{n,m} := raw_input().split(" ")->select(s | true)->collect(s | (s)) ; var data : Sequence := (("" + ((n))))->characters()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; var result : OclAny := solve(("" + ((n)))->toInteger(), ("" + ((m)))->toInteger()) ; execute (StringLib.interpolateStrings("Case #{}:{}{}", Sequence{i, result->first(), result[1+1]}))->display()); operation solve(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var intervals : Map := Map{ n |-> 1 } ; var lens : Sequence := Sequence{ -n } ; var ls : int := 0 ; var rs : int := 0 ; while k > 0 do ( var val : OclAny := -heapq.heappop(lens) ; var num : OclAny := intervals[val+1] ; execute (intervals[val+1])->isDeleted() ; k := k - num ; ls := ("" + (((val - 1) / 2)))->toInteger() ; rs := val - ls - 1 ; if not((intervals)->includes(ls)) then ( intervals[ls+1] := 0 ; heapq.heappush(lens, -ls) ) else skip ; if not((intervals)->includes(rs)) then ( intervals[rs+1] := 0 ; heapq.heappush(lens, -rs) ) else skip ; intervals[rs+1] := intervals[rs+1] + num ; intervals[ls+1] := intervals[ls+1] + num) ; return Sequence{Set{ls, rs}->max(), Set{ls, rs}->min()}; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function import sys from sys import stdin def eprint(*args,**kwargs): print(*args,file=sys.stderr,**kwargs) def ln(f=int): return list(map(f,stdin.readline().strip().split())) T,=ln() INF=float('inf') for test in range(T): N,K=ln() xs=[(N,1)] h={} h[N]=1 while True : n,q=max(h.items()) a=n//2 b=n-a-1 del h[n] if not a in h : h[a]=0 if not b in h : h[b]=0 if a==b : h[a]+=2*q else : h[a]+=q h[b]+=q if K<=q : res_mx=max(a,b) res_mn=min(a,b) break K-=q print("Case #"+str(test+1)+": "+str(res_mx)+" "+str(res_mn)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name T)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name T)))))) ,)} := ln() ; var INF : double := ("" + (('inf')))->toReal() ; for test : Integer.subrange(0, T-1) do ( var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := ln() ; var xs : Sequence := Sequence{ Sequence{N, 1} } ; var h : OclAny := Set{} ; h[N+1] := 1 ; while true do ( var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (h->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}))->max() ; var a : int := n div 2 ; var b : double := n - a - 1 ; execute (h[n+1])->isDeleted() ; if not((h)->includes(a)) then ( h[a+1] := 0 ) else skip ; if not((h)->includes(b)) then ( h[b+1] := 0 ) else skip ; if a = b then ( h[a+1] := h[a+1] + 2 * q ) else ( h[a+1] := h[a+1] + q ; h[b+1] := h[b+1] + q ) ; if (K->compareTo(q)) <= 0 then ( var res_mx : OclAny := Set{a, b}->max() ; var res_mn : OclAny := Set{a, b}->min() ; break ) else skip ; K := K - q) ; execute ("Case #" + ("" + ((test + 1))) + ": " + ("" + ((res_mx))) + " " + ("" + ((res_mn))))->display()); operation eprint(args : OclAny : Sequence(OclAny), kwargs : OclAny : Map(String, OclAny)) pre: true post: true activity: (args * (named_parameter (name args)))(kwargs ** (named_parameter (name kwargs))) execute ((argument * (test (logical_test (comparison (expr (atom (name args))))))))->display(); operation ln(f : OclAny) : OclAny pre: true post: true activity: if f->oclIsUndefined() then f := OclType["int"] else skip; return ((stdin.readLine()->trim().split())->collect( _x | (f)->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import groupby def solve(): n,k=[int(w)for w in input().split()] a=[(n,1)] while True : b=[] for d,cnt in a : if cnt0])) def prepare_input(): local=False task='C' attempt=-1 import sys if local : sys.stdin=open("../input.txt","r") else : filename="../{}-small-2-attempt{}".format(task,attempt)if attempt>=0 else "../{}-large".format(task) sys.stdin=open(filename+".in","r") sys.stdout=open(filename+".out","w") print("filename:",filename[3 :],file=sys.stderr) prepare_input() tests=int(input()) for test in range(1,tests+1): res=solve() print("Case #{}:{}".format(test,res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; prepare_input() ; var tests : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for test : Integer.subrange(1, tests + 1-1) do ( var res : OclAny := solve() ; execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{test, res}))->display()); operation solve() : OclAny pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(w | true)->collect(w | (("" + ((w)))->toInteger())) ; var a : Sequence := Sequence{ Sequence{n, 1} } ; while true do ( var b : Sequence := Sequence{} ; for _tuple : a do (var _indx : int := 1; var d : OclAny := _tuple->at(_indx); _indx := _indx + 1; var cnt : OclAny := _tuple->at(_indx); if (cnt->compareTo(k)) < 0 then ( k := k - cnt ; execute ((Sequence{(d - 1) div 2, cnt}) : b) ; execute ((Sequence{d div 2, cnt}) : b) ) else ( return StringLib.interpolateStrings("{}{}", Sequence{d div 2, (d - 1) div 2}) )) ; a := groupby(b->sort(), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name t)))) : (test (logical_test (comparison (expr (atom (name t)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))))->select(_tuple | true)->collect(_tuple | let f : OclAny = _tuple->at(1) in let g : OclAny = _tuple->at(2) in (Sequence{f, ((argument (test (logical_test (comparison (expr (atom (name s)))))) (comp_for for (exprlist (expr (atom (name _))) , (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name g))))))))->sum()})) ; a := ((a->select(x | x->first() > 0)->collect(x | (x)))->reverse())); operation prepare_input() pre: true post: true activity: var local : boolean := false ; var task : String := 'C' ; var attempt : int := -1 ; skip ; if local then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("../input.txt")) ) else ( var filename : String := if attempt >= 0 then StringLib.interpolateStrings("../{}-small-2-attempt{}", Sequence{task, attempt}) else StringLib.interpolateStrings("../{}-large", Sequence{task}) endif ; OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile(filename + ".in")) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile(filename + ".out")) ; execute ("filename:")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reverseWord(Str): i=1 j=len(Str)-2 while(isize() - 2 ; while ((i->compareTo(j)) < 0) do ( var temp : OclAny := Str[i+1] ; Str[i+1] := Str[j+1] ; Str[j+1] := temp ; i := i + 1 ; j := j - 1) ; return StringLib.sumStringsWithSeparator((Str), ""); operation reverseWords(Str : OclAny) pre: true post: true activity: Str := Str.split() ; for i : Str do ( j := i->select(h | true)->collect(h | (h)) ; execute (reverseWord(j))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a1,a2,a3,a4,a5,a6=input().split() a=int(a2)+int(a1)+int(a3) s=a**2-(int(a1)**2+int(a3)**2+int(a5)**2) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a1 : OclAny := null; var a2 : OclAny := null; var a3 : OclAny := null; var a4 : OclAny := null; var a5 : OclAny := null; var a6 : OclAny := null; Sequence{a1,a2,a3,a4,a5,a6} := input().split() ; var a : int := ("" + ((a2)))->toInteger() + ("" + ((a1)))->toInteger() + ("" + ((a3)))->toInteger() ; var s : double := (a)->pow(2) - ((("" + ((a1)))->toInteger())->pow(2) + (("" + ((a3)))->toInteger())->pow(2) + (("" + ((a5)))->toInteger())->pow(2)) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) digits=[int(x)for x in input().split()] ddict={5 : 0,0 : 0} for x in digits : ddict[x]+=1 if ddict[0]==0 : return-1 if ddict[5]//9>0 : ans='' for i in range((ddict[5]//9)*9): ans+='5' for i in range(ddict[0]): ans+='0' return ans else : return 0 ans='' for i in range(ddict[5]): ans+='5' for i in range(ddict[0]): ans+='0' return ans print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (solve())->display(); operation solve() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var digits : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ddict : Map := Map{ 5 |-> 0 }->union(Map{ 0 |-> 0 }) ; for x : digits do ( ddict[x+1] := ddict[x+1] + 1) ; if ddict->first() = 0 then ( return -1 ) else skip ; if ddict[5+1] div 9 > 0 then ( var ans : String := '' ; for i : Integer.subrange(0, (ddict[5+1] div 9) * 9-1) do ( ans := ans + '5') ; for i : Integer.subrange(0, ddict->first()-1) do ( ans := ans + '0') ; return ans ) else ( return 0 ) ; ans := '' ; for i : Integer.subrange(0, ddict[5+1]-1) do ( ans := ans + '5') ; for i : Integer.subrange(0, ddict->first()-1) do ( ans := ans + '0') ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def xorLessK(arr,n,k): count=0 for i in range(n): tempXor=0 for j in range(i,n): tempXor ^=arr[j] if(tempXorunion(Sequence{9}->union(Sequence{10}->union(Sequence{11}->union(Sequence{ 12 })))) ; n := (arr)->size() ; execute (xorLessK(arr, n, k))->display() ) else skip; operation xorLessK(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( var tempXor : int := 0 ; for j : Integer.subrange(i, n-1) do ( tempXor := tempXor xor arr[j+1] ; if ((tempXor->compareTo(k)) < 0) then ( count := count + 1 ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[int(i)for i in input().split()] ans='YES' for i in l : if l.count(i)>(n+1)/2 : ans='NO' break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : String := 'YES' ; for i : l do ( if (l->count(i)->compareTo((n + 1) / 2)) > 0 then ( ans := 'NO' ; break ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printOrder(arr,n,k): len1=k len2=n-k arr1=[0]*k arr2=[0]*(n-k) for i in range(k): arr1[i]=arr[i] for i in range(k,n): arr2[i-k]=arr[i] arr1.sort() arr2.sort() for i in range(n): if(iunion(Sequence{4}->union(Sequence{6}->union(Sequence{2}->union(Sequence{1}->union(Sequence{3}->union(Sequence{8}->union(Sequence{9}->union(Sequence{ -1 })))))))) ; k := 4 ; n := (arr)->size() ; printOrder(arr, n, k) ) else skip; operation printOrder(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var len1 : OclAny := k ; var len2 : double := n - k ; var arr1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, k) ; var arr2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n - k)) ; for i : Integer.subrange(0, k-1) do ( arr1[i+1] := arr[i+1]) ; for i : Integer.subrange(k, n-1) do ( arr2[i - k+1] := arr[i+1]) ; arr1 := arr1->sort() ; arr2 := arr2->sort() ; for i : Integer.subrange(0, n-1) do ( if ((i->compareTo(k)) < 0) then ( arr[i+1] := arr1[i+1] ) else ( arr[i+1] := arr2[len2 - 1+1] ; len2 := len2 - 1 )) ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline def mul(a,b): return((a % mod)*(b % mod))% mod def sub(a,b): return(a-b+mod)% mod def answer(): ans=1 for i in range(1,31): upper=min(d+1,(1<toInteger()-1) do ( var d : OclAny := null; var mod : OclAny := null; Sequence{d,mod} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (answer())->display()); operation mul(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return ((a mod mod) * (b mod mod)) mod mod; operation sub(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a - b + mod) mod mod; operation answer() : OclAny pre: true post: true activity: var ans : int := 1 ; for i : Integer.subrange(1, 31-1) do ( var upper : OclAny := Set{d + 1, (1 * (2->pow(i)))}->min() ; var lower : int := (1 * (2->pow((i - 1)))) ; ans := mul(ans, upper - lower + 1) ; if ((d->compareTo((1 * (2->pow(i))))) < 0) then ( break ) else skip) ; ans := sub(ans, 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for q in range(int(input())): n,m=map(int,input().split()); st,ans=1,1 while st<=n : ans*=min(st*2-st+1,n-st+2); st*=2 print((ans-1)% m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for q : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var st : OclAny := null; var ans : OclAny := null; Sequence{st,ans} := Sequence{1,1} ; while (st->compareTo(n)) <= 0 do ( ans := ans * Set{st * 2 - st + 1, n - st + 2}->min(); st := st * 2) ; execute ((ans - 1) mod m)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while(t>=1): t-=1 values=input().split() d,m=int(values[0]),int(values[1]) result=1 for i in range(0,32): if d<(1<toInteger() ; while (t >= 1) do ( t := t - 1 ; var values : OclAny := input().split() ; var d : OclAny := null; var m : OclAny := null; Sequence{d,m} := Sequence{("" + ((values->first())))->toInteger(),("" + ((values[1+1])))->toInteger()} ; var result : int := 1 ; for i : Integer.subrange(0, 32-1) do ( if (d->compareTo((1 * (2->pow(i))))) < 0 then ( break ) else skip ; result := result * (Set{(1 * (2->pow((i + 1)))) - 1, d}->min() - (1 * (2->pow(i))) + 2)) ; result := result - 1 ; var result_mod_m : int := result mod m ; if result_mod_m < 0 then ( result_mod_m := result_mod_m + m ) else skip ; execute (result_mod_m)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for _ in range(T): D,M=map(int,input().split(' ')) x=D pow2=[1] while x : pow2.append(pow2[-1]*2 % M) x//=2 ans=1 for x in pow2[:-2]: ans=(ans*(x+1))% M ans=(ans*(D-pow2[-2]+2+M)% M-1+M)% M print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, T-1) do ( var D : OclAny := null; var M : OclAny := null; Sequence{D,M} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := D ; var pow2 : Sequence := Sequence{ 1 } ; while x do ( execute ((pow2->last() * 2 mod M) : pow2) ; x := x div 2) ; var ans : int := 1 ; for x : pow2->front()->front() do ( ans := (ans * (x + 1)) mod M) ; ans := (ans * (D - pow2->front()->last() + 2 + M) mod M - 1 + M) mod M ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- DEBUG=0 if DEBUG==1 : data=open('1.in','r') def readline(): if DEBUG==1 : return data.readline().strip('\n') else : try : return input().strip('\n') except EOFError : return '' def readi(): return[int(t)for t in readline().split()] def H(n): p=0 while n>0 : n//=2 p+=1 return p-1 tc,=readi() for _ in range(tc): d,m=readi() ans=1 for i in range(H(d)+1): t=min(2**(i+1)-1,d)-2**i+2 ans*=t ans %=m ans-=1 if ans<0 : ans+=m print(ans) if DEBUG==1 : data.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var DEBUG : int := 0 ; if DEBUG = 1 then ( var data : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('1.in')) ) else skip ; skip ; skip ; skip ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name tc)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name tc)))))) ,)} := readi() ; for _anon : Integer.subrange(0, tc-1) do ( var d : OclAny := null; var m : OclAny := null; Sequence{d,m} := readi() ; var ans : int := 1 ; for i : Integer.subrange(0, H(d) + 1-1) do ( var t : double := Set{(2)->pow((i + 1)) - 1, d}->min() - (2)->pow(i) + 2 ; ans := ans * t ; ans := ans mod m) ; ans := ans - 1 ; if ans < 0 then ( ans := ans + m ) else skip ; execute (ans)->display()) ; if DEBUG = 1 then ( data.closeFile() ) else skip; operation readline() : OclAny pre: true post: true activity: if DEBUG = 1 then ( return data.readLine()->trim() ) else ( try ( return input()->trim()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom ''))))))))))) ); operation readi() : OclAny pre: true post: true activity: return readline().split()->select(t | true)->collect(t | (("" + ((t)))->toInteger())); operation H(n : OclAny) : OclAny pre: true post: true activity: var p : int := 0 ; while n > 0 do ( n := n div 2 ; p := p + 1) ; return p - 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minSum(a,n): a=sorted(a) num1,num2=0,0 for i in range(n): if i % 2==0 : num1=num1*10+a[i] else : num2=num2*10+a[i] return num2+num1 arr=[5,3,0,7,4] n=len(arr) print("The required sum is",minSum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var arr : Sequence := Sequence{5}->union(Sequence{3}->union(Sequence{0}->union(Sequence{7}->union(Sequence{ 4 })))) ; n := (arr)->size() ; execute ("The required sum is")->display(); operation minSum(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: a := a->sort() ; var num1 : OclAny := null; var num2 : OclAny := null; Sequence{num1,num2} := Sequence{0,0} ; for i : Integer.subrange(0, n-1) do ( if i mod 2 = 0 then ( var num1 : double := num1 * 10 + a[i+1] ) else ( var num2 : double := num2 * 10 + a[i+1] )) ; return num2 + num1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**9) def mi(): return map(int,input().split()) def ii(): return int(input()) def isp(): return input().split() def deb(text): print("-------\n{}\n-------".format(text)) INF=10**20 def main(): W,H,x,y=mi() ans='{:.10f}'.format(W*H/2) ans2=1 if x==W/2 and y==H/2 else 0 print(ans,ans2) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(9)) ; skip ; skip ; skip ; skip ; var INF : double := (10)->pow(20) ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation mi() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation ii() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation isp() : OclAny pre: true post: true activity: return input().split(); operation deb(text : OclAny) pre: true post: true activity: execute (StringLib.interpolateStrings("-------\n{}\n-------", Sequence{text}))->display(); operation main() pre: true post: true activity: var W : OclAny := null; var H : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{W,H,x,y} := mi() ; var ans : String := StringLib.interpolateStrings('{:.10f}', Sequence{W * H / 2}) ; var ans2 : int := if x = W / 2 & y = H / 2 then 1 else 0 endif ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import os import itertools import _collections import string from functools import lru_cache class cin(): def int(): return int(sys.stdin.readline().rstrip()) def string(): return sys.stdin.readline().rstrip() def mapInt(): return[int(x)for x in cin.string().split()] def stringList(n): return[input()for i in range(n)] def intListList(n): return[cin.mapInt()for i in range(n)] def intColsList(n): return[int(input())for i in range(n)] class Math(): def gcd(a,b): if b==0 : return a return Math.gcd(b,a % b) def roundUp(a,b): return-(-a//b) def toUpperMultiple(a,x): return Math.roundUp(a,x)*x def toLowerMultiple(a,x): return(a//x)*x def nearPow2(n): if n<=0 : return 0 if n &(n-1)==0 : return n ret=1 while(n>0): ret<<=1 n>>=1 return ret MOD=int(1e09)+7 def main(): W,H,X,Y=cin.mapInt() print(float(W)*float(H)*0.5,"01"[X*2==W and Y*2==H]) return if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class cin { static operation newcin() : cin pre: true post: cin->exists( _x | result = _x ); static operation OclType["int"]() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.readLine().rstrip())))->toInteger(); static operation string() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); static operation mapInt() : OclAny pre: true post: true activity: return cin.string().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation stringList((def_parameters (def_parameter (named_parameter (name n))))) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())); operation intListList((def_parameters (def_parameter (named_parameter (name n))))) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (cin.mapInt())); operation intColsList((def_parameters (def_parameter (named_parameter (name n))))) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())); } class Math { static operation newMath() : Math pre: true post: Math->exists( _x | result = _x ); operation gcd(a : OclAny , b : OclAny) : OclAny pre: true post: true activity: if b = 0 then ( return a ) else skip ; return Math.gcd(b, a mod b); operation roundUp(a : OclAny , b : OclAny) : OclAny pre: true post: true activity: return -(-a div b); operation toUpperMultiple(a : OclAny , x : OclAny) : OclAny pre: true post: true activity: return Math.roundUp(a, x) * x; operation toLowerMultiple(a : OclAny , x : OclAny) : OclAny pre: true post: true activity: return (a div x) * x; operation nearPow2((def_parameters (def_parameter (named_parameter (name n))))) : OclAny pre: true post: true activity: if n <= 0 then ( return 0 ) else skip ; if MathLib.bitwiseAnd(n, (n - 1)) = 0 then ( return n ) else skip ; var ret : int := 1 ; while (n > 0) do ( ret := ret * (2->pow(1)) ; n := n div (2->pow(1))) ; return ret; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var MOD : int := ("" + ((("1e09")->toReal())))->toInteger() + 7 ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var W : OclAny := null; var H : OclAny := null; var X : OclAny := null; var Y : OclAny := null; Sequence{W,H,X,Y} := (cin.newcin()).initialise.mapInt() ; execute (("" + ((W)))->toReal() * ("" + ((H)))->toReal() * 0.5)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=int(input()) l=map(int,input().split()) cevap=[] liste=list(l) if liste.count(5)>=9 : x=liste.count(5) m=int(x/9) for i in range(9*m): cevap.append("5") for t in range(liste.count(0)): cevap.append("0") if cevap[-1]=="0" : print("".join(cevap)) else : print("-1") if liste.count(5)<9 : if liste.count(0)==0 : print("-1") else : print("0") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cevap : Sequence := Sequence{} ; var liste : Sequence := (l) ; if liste->count(5) >= 9 then ( var x : int := liste->count(5) ; m := ("" + ((x / 9)))->toInteger() ; for i : Integer.subrange(0, 9 * m-1) do ( execute (("5") : cevap)) ; for t : Integer.subrange(0, liste->count(0)-1) do ( execute (("0") : cevap)) ; if cevap->last() = "0" then ( execute (StringLib.sumStringsWithSeparator((cevap), ""))->display() ) else ( execute ("-1")->display() ) ) else skip ; if liste->count(5) < 9 then ( if liste->count(0) = 0 then ( execute ("-1")->display() ) else ( execute ("0")->display() ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- Num_seg=[[0,1,1,1,1,1,1],[0,0,0,0,1,1,0],[1,0,1,1,0,1,1],[1,0,0,1,1,1,1],[1,1,0,0,1,1,0],[1,1,0,1,1,0,1],[1,1,1,1,1,0,1],[0,1,0,0,1,1,1],[1,1,1,1,1,1,1],[1,1,0,1,1,1,1]] while True : n=int(input()) if n==-1 : break num_b=int(input()) seg="" for h in range(7): seg=seg+str(Num_seg[num_b][h]) print(seg) for i in range(n-1): num_a=int(input()) seg="" for j in range(7): if Num_seg[num_b][j]==Num_seg[num_a][j]: seg=seg+"0" else : seg=seg+"1" num_b=num_a print(seg) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Num_seg : Sequence := Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))))))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 0 }))))))}->union(Sequence{Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 1 }))))))}->union(Sequence{Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))))))}->union(Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 0 }))))))}->union(Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 1 }))))))}->union(Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 1 }))))))}->union(Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))))))}->union(Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))))))}->union(Sequence{ Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })))))) }))))))))) ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = -1 then ( break ) else skip ; var num_b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var seg : String := "" ; for h : Integer.subrange(0, 7-1) do ( seg := seg + ("" + ((Num_seg[num_b+1][h+1])))) ; execute (seg)->display() ; for i : Integer.subrange(0, n - 1-1) do ( var num_a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; seg := "" ; for j : Integer.subrange(0, 7-1) do ( if Num_seg[num_b+1][j+1] = Num_seg[num_a+1][j+1] then ( seg := seg + "0" ) else ( seg := seg + "1" )) ; num_b := num_a ; execute (seg)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- W,H,x,y=map(int,input().split()) print((W*H)/2,int((W/2==x and H/2==y))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var W : OclAny := null; var H : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{W,H,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((W * H) / 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- W,H,x,y=map(int,input().split()) buf_x=W-x buf_y=H-y if buf_x>=x : ver_area=H*x else : ver_area=H*buf_x if buf_y>=y : hori_area=W*y else : hori_area=W*buf_y if x*2==W and y*2==H : print(float(W*H/2),1) else : print(float(W*H/2),0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var W : OclAny := null; var H : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{W,H,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var buf_x : double := W - x ; var buf_y : double := H - y ; if (buf_x->compareTo(x)) >= 0 then ( var ver_area : double := H * x ) else ( ver_area := H * buf_x ) ; if (buf_y->compareTo(y)) >= 0 then ( var hori_area : double := W * y ) else ( hori_area := W * buf_y ) ; if x * 2 = W & y * 2 = H then ( execute (("" + ((W * H / 2)))->toReal())->display() ) else ( execute (("" + ((W * H / 2)))->toReal())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math ni=lambda : int(ns()) na=lambda : list(map(int,input().split())) ns=lambda : input() W,H,x,y=na() r=W*H/2 l=1 if x==W/2 and y==H/2 else 0 print(r,l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var ni : Function := lambda $$ : OclAny in (("" + ((ns())))->toInteger()) ; var na : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ns : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var W : OclAny := null; var H : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{W,H,x,y} := na->apply() ; var r : double := W * H / 2 ; var l : int := if x = W / 2 & y = H / 2 then 1 else 0 endif ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(st): n=len(st) if(n==0 and n==1): return False if(n==2): return((int)(st[n-2])*10+((int)(st[n-1])% 16==0)) if(n==3): return(((int)(st[n-3])*100+(int)(st[n-2])*10+(int)(st[n-1]))% 16==0) last=(int)(st[n-1]) second_last=(int)(st[n-2]) third_last=(int)(st[n-3]) fourth_last=(int)(st[n-4]) return((fourth_last*1000+third_last*100+second_last*10+last)% 16==0) st="769528" if(check(st)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; st := "769528" ; if (check(st)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation check(st : OclAny) : OclAny pre: true post: true activity: var n : int := (st)->size() ; if (n = 0 & n = 1) then ( return false ) else skip ; if (n = 2) then ( return ((OclType["int"])(st[n - 2+1]) * 10 + ((OclType["int"])(st[n - 1+1]) mod 16 = 0)) ) else skip ; if (n = 3) then ( return (((OclType["int"])(st[n - 3+1]) * 100 + (OclType["int"])(st[n - 2+1]) * 10 + (OclType["int"])(st[n - 1+1])) mod 16 = 0) ) else skip ; var last : OclAny := (OclType["int"])(st[n - 1+1]) ; var second_last : OclAny := (OclType["int"])(st[n - 2+1]) ; var third_last : OclAny := (OclType["int"])(st[n - 3+1]) ; var fourth_last : OclAny := (OclType["int"])(st[n - 4+1]) ; return ((fourth_last * 1000 + third_last * 100 + second_last * 10 + last) mod 16 = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math iter=1 for _ in range(iter): n,k=list(map(int,input().split(' '))) w=list(map(int,input().split(' '))) r=0 for i in range(n): r+=math.ceil(w[i]/k) print(math.ceil(r/2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var iter : int := 1 ; for _anon : Integer.subrange(0, iter-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var w : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var r : int := 0 ; for i : Integer.subrange(0, n-1) do ( r := r + (w[i+1] / k)->ceil()) ; execute ((r / 2)->ceil())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,k=map(int,input().split()) ar=list(map(int,input().split())) s=0 for x in range(n): s+=math.ceil(ar[x]/k) print(math.ceil(s/2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ar : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : int := 0 ; for x : Integer.subrange(0, n-1) do ( s := s + (ar[x+1] / k)->ceil()) ; execute ((s / 2)->ceil())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,k=map(int,input().split()) w=list(map(int,input().split())) c,s=0,0 for i in w : c+=i//(2*k) if i %(2*k)>k : c+=1 elif i %(2*k)>0 : s+=1 print(c+(s+1)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : OclAny := null; var s : OclAny := null; Sequence{c,s} := Sequence{0,0} ; for i : w do ( c := c + i div (2 * k) ; if (i mod (2 * k)->compareTo(k)) > 0 then ( c := c + 1 ) else (if i mod (2 * k) > 0 then ( s := s + 1 ) else skip)) ; execute (c + (s + 1) div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,k=map(int,input().split()) w=list(map(int,input().split())) c,s=0,0 for i in w : c+=i//(2*k) if i %(2*k)>k : c+=1 elif i %(2*k)>0 : s+=1 print(c+(s+1)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : OclAny := null; var s : OclAny := null; Sequence{c,s} := Sequence{0,0} ; for i : w do ( c := c + i div (2 * k) ; if (i mod (2 * k)->compareTo(k)) > 0 then ( c := c + 1 ) else (if i mod (2 * k) > 0 then ( s := s + 1 ) else skip)) ; execute (c + (s + 1) div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def _input(): return map(int,input().split()) n,k=_input() lst=list(_input()) res=0 i=0 while i2*k : res+=((lst[i]//(2*k))) res-=1 if lst[i]%(2*k)!=0 : lst[i]-=(2*k)*(lst[i]//(2*k)); i-=1 ; res+=1 i+=1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := _input() ; var lst : Sequence := (_input()) ; var res : int := 0 ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( if (lst[i+1]->compareTo(k)) <= 0 then ( if (i->compareTo(n - 1)) < 0 then ( if (lst[i + 1+1]->compareTo(k)) <= 0 then ( i := i + 1 ) else ( lst[i + 1+1] := lst[i + 1+1] - k ) ) else skip ) else skip ; if (lst[i+1]->compareTo(2 * k)) > 0 then ( res := res + ((lst[i+1] div (2 * k))) ; res := res - 1 ; if lst[i+1] mod (2 * k) /= 0 then ( lst[i+1] := lst[i+1] - (2 * k) * (lst[i+1] div (2 * k)); i := i - 1; ) else skip ) else skip ; res := res + 1 ; i := i + 1) ; execute (res)->display(); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def circumferenceparallelogram(a,b): return((2*a)+(2*b)) a=10 b=8 print("Circumference of a given Parallelogram is :",round(circumferenceparallelogram(a,b),4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 10 ; b := 8 ; execute ("Circumference of a given Parallelogram is :")->display(); operation circumferenceparallelogram(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return ((2 * a) + (2 * b)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque dq=deque() append,popleft=dq.append,dq.popleft try : while True : a=[[0]*14]+[[0]+list(map(int,input()))+[0]for _ in[0]*12]+[[0]*14] result=0 for y in range(1,13): for x in filter(lambda x : a[y][x],range(1,13)): result+=1 a[y][x]=0 dq.clear() append((x,y)) while dq : cx,cy=popleft() for dx,dy in((0,-1),(1,0),(0,1),(-1,0)): if a[cy+dy][cx+dx]: a[cy+dy][cx+dx]=0 append((cx+dx,cy+dy)) print(result) input() except EOFError : pass ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var dq : Sequence := () ; var append : OclAny := null; var popleft : OclAny := null; Sequence{append,popleft} := Sequence{dq.append,dq.popleft} ; try ( while true do ( var a : Sequence := Sequence{ MatrixLib.elementwiseMult(Sequence{ 0 }, 14) }->union(MatrixLib.elementwiseMult(Sequence{ 0 }, 12)->select(_anon | true)->collect(_anon | (Sequence{ 0 }->union((((OclFile["System.in"]).readLine())->collect( _x | (OclType["int"])->apply(_x) )))->union(Sequence{ 0 }))))->union(Sequence{ MatrixLib.elementwiseMult(Sequence{ 0 }, 14) }) ; var result : int := 0 ; for y : Integer.subrange(1, 13-1) do ( for x : (Integer.subrange(1, 13-1))->select( _x | (lambda x : OclAny in (a[y+1][x+1]))->apply(_x) = true ) do ( result := result + 1 ; a[y+1][x+1] := 0 ; execute (dq /<: dq) ; append(Sequence{x, y}) ; while dq do ( var cx : OclAny := null; var cy : OclAny := null; Sequence{cx,cy} := popleft() ; for _tuple : Sequence{Sequence{0, -1}, Sequence{1, 0}, Sequence{0, 1}, Sequence{-1, 0}} do (var _indx : int := 1; var dx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dy : OclAny := _tuple->at(_indx); if a[cy + dy+1][cx + dx+1] then ( a[cy + dy+1][cx + dx+1] := 0 ; append(Sequence{cx + dx, cy + dy}) ) else skip)))) ; execute (result)->display() ; input())) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt pass))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) arr=list(map(int,input().split(" "))) fives=0 zeros=0 for x in arr : if x>0 : fives+=1 else : zeros+=1 if fives==0 and zeros>0 : print(0) return if zeros==0 : print(-1) return if fives<9 : print(0) return fives=fives-fives % 9 print(int(''.join(['5',]*fives)+''.join(['0',]*zeros))) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var fives : int := 0 ; var zeros : int := 0 ; for x : arr do ( if x > 0 then ( fives := fives + 1 ) else ( zeros := zeros + 1 )) ; if fives = 0 & zeros > 0 then ( execute (0)->display() ; return ) else skip ; if zeros = 0 then ( execute (-1)->display() ; return ) else skip ; if fives < 9 then ( execute (0)->display() ; return ) else skip ; fives := fives - fives mod 9 ; execute (("" + ((StringLib.sumStringsWithSeparator((MatrixLib.elementwiseMult(Sequence{ '5' }, fives)), '') + StringLib.sumStringsWithSeparator((MatrixLib.elementwiseMult(Sequence{ '0' }, zeros)), ''))))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maximumNumberDistinctPrimeRange(m,n): factorCount=[0]*(n+1) prime=[False]*(n+1) for i in range(n+1): factorCount[i]=0 prime[i]=True for i in range(2,n+1): if(prime[i]==True): factorCount[i]=1 for j in range(i*2,n+1,i): factorCount[j]+=1 prime[j]=False max=factorCount[m] num=m for i in range(m,n+1): if(factorCount[i]>max): max=factorCount[i] num=i return num if __name__=="__main__" : m=4 n=6 print(maximumNumberDistinctPrimeRange(m,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( m := 4 ; n := 6 ; execute (maximumNumberDistinctPrimeRange(m, n))->display() ) else skip; operation maximumNumberDistinctPrimeRange(m : OclAny, n : OclAny) : OclAny pre: true post: true activity: var factorCount : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (n + 1)) ; for i : Integer.subrange(0, n + 1-1) do ( factorCount[i+1] := 0 ; prime[i+1] := true) ; for i : Integer.subrange(2, n + 1-1) do ( if (prime[i+1] = true) then ( factorCount[i+1] := 1 ; for j : Integer.subrange(i * 2, n + 1-1)->select( $x | ($x - i * 2) mod i = 0 ) do ( factorCount[j+1] := factorCount[j+1] + 1 ; prime[j+1] := false) ) else skip) ; var max : OclAny := factorCount[m+1] ; var num : OclAny := m ; for i : Integer.subrange(m, n + 1-1) do ( if ((factorCount[i+1]->compareTo(max)) > 0) then ( max := factorCount[i+1] ; num := i ) else skip) ; return num; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def read(): return list(map(int,input().split())) def calc(bs,ls,first): if sum(ls[0 : : 2])!=bs.count(first)or sum(ls[1 : : 2])!=bs.count(1-first): return float("inf") res=0 i,j=0,0 for k in range(0,len(ls),2): if k>0 : i+=ls[k-1] for _ in range(ls[k]): j=bs.index(first,j) res+=abs(j-i) i+=1 j+=1 return res while 1 : try : n,m=read() bs=read() ls=read() except : break print(min(calc(bs,ls,i)for i in range(2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while 1 do ( try ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := read() ; bs := read() ; ls := read()) catch (_e : OclException) do ( break) ; execute (((argument (test (logical_test (comparison (expr (atom (name calc)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name bs))))))) , (argument (test (logical_test (comparison (expr (atom (name ls))))))) , (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))))))))->min())->display()); operation read() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation calc(bs : OclAny, ls : OclAny, first : OclAny) : OclAny pre: true post: true activity: if (ls(subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->sum() /= bs->count(first) or (ls(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->sum() /= bs->count(1 - first) then ( return ("" + (("inf")))->toReal() ) else skip ; var res : int := 0 ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,0} ; for k : Integer.subrange(0, (ls)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( if k > 0 then ( i := i + ls[k - 1+1] ) else skip ; for _anon : Integer.subrange(0, ls[k+1]-1) do ( var j : int := bs->indexOf(first, j) - 1 ; res := res + (j - i)->abs() ; i := i + 1 ; j := j + 1)) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (n,m)=map(int,input().split()) b=tuple(map(int,input().split())) p=list(map(int,input().split())) cs=0 ss={} fs=[] bs=[b] while bs : (fs,bs)=(bs,fs) while fs : b=fs.pop() if b not in ss : ss[b]=cs b=list(b) for i in range(n-1): (b[i],b[i+1])=(b[i+1],b[i]) bs.append(tuple(b)) (b[i+1],b[i])=(b[i],b[i+1]) cs=cs+1 for(k,v)in ss.items(): res=[] co=1 for i in range(1,len(k)): if k[i-1]==k[i]: co=co+1 else : res.append(co) co=1 res.append(co) if res==p and vcollect( _x | (OclType["int"])->apply(_x) ) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cs : int := 0 ; var ss : OclAny := Set{} ; var fs : Sequence := Sequence{} ; var bs : Sequence := Sequence{ b } ; while bs do ( ; var Sequence{fs, bs} : OclAny := Sequence{bs, fs} ; while fs do ( b := fs->last() ; fs := fs->front() ; if (ss)->excludes(b) then ( ss->restrict(b) := cs ; b := (b) ; for i : Integer.subrange(0, n - 1-1) do (suite) ) else skip)) ; Sequence{b[i+1], b[i + 1+1]} := Sequence{b[i + 1+1], b[i+1]}; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) *B,=map(int,input().split()) *P,=map(int,input().split()) def solve(v): C=B[:] D=[] for i in range(M): D+=[(i & 1)^ v]*P[i] res=0 for i in range(N): if C[i]!=D[i]: for j in range(i,N): if D[i]==C[j]: C[i],C[j]=C[j],C[i] res+=j-i break else : return 10**9 return res print(min(solve(0),solve(1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (testlist_star_expr (star_expr * (expr (atom (name B)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name B)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (testlist_star_expr (star_expr * (expr (atom (name P)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name P)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; execute (Set{solve(0), solve(1)}->min())->display(); operation solve(v : OclAny) : OclAny pre: true post: true activity: var C : Sequence := B ; var D : Sequence := Sequence{} ; for i : Integer.subrange(0, M-1) do ( D := D + MatrixLib.elementwiseMult(Sequence{ MathLib.bitwiseXor((MathLib.bitwiseAnd(i, 1)), v) }, P[i+1])) ; var res : int := 0 ; for i : Integer.subrange(0, N-1) do ( if C[i+1] /= D[i+1] then ( (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name D)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (name C)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name C)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))) , (test (logical_test (comparison (expr (atom (name C)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))) (assign_part = (testlist_star_expr (test (logical_test (comparison (expr (atom (name C)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))) , (test (logical_test (comparison (expr (atom (name C)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name res)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name j))) - (expr (atom (name i)))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (expr (atom (number (integer 10)))) ** (expr (atom (number (integer 9))))))))))))))) ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy N,M=[int(i)for i in input().split()] b=[int(i)for i in input().split()] p=[int(i)for i in input().split()] def solve(num): ret=0 c=copy.deepcopy(b) c_=[] for i in range(M): c_+=[(int(i % 2==num))]*p[i] for i in range(N): if c[i]!=c_[i]: for j in range(i,N): if c_[i]==c[j]: ret+=j-i c[i],c[j]=c[j],c[i] break else : return 1000 return ret print(min(solve(0),solve(1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var b : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var p : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; skip ; execute (Set{solve(0), solve(1)}->min())->display(); operation solve(num : OclAny) : OclAny pre: true post: true activity: var ret : int := 0 ; var c : OclAny := copy.deepcopy(b) ; var c_ : Sequence := Sequence{} ; for i : Integer.subrange(0, M-1) do ( c_ := c_ + MatrixLib.elementwiseMult(Sequence{ (("" + ((i mod 2 = num)))->toInteger()) }, p[i+1])) ; for i : Integer.subrange(0, N-1) do ( if c[i+1] /= c_[i+1] then ( (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (name N)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name c_)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ret)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name j))) - (expr (atom (name i)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))) , (test (logical_test (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))) (assign_part = (testlist_star_expr (test (logical_test (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))) , (test (logical_test (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 1000)))))))))))))) ) else skip) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def depth(id): depth=0 target_id=id while nodes[target_id][0]!=-1 : depth+=1 target_id=nodes[target_id][0] return depth nodes=dict() n=int(input()) for _ in range(n): id,k,*c_list=list(map(int,input().split())) if id not in nodes : nodes[id]=(-1,list()) node=nodes[id] node=(node[0],c_list) nodes[id]=node for child_id in c_list : if child_id not in nodes : nodes[child_id]=(-1,list()) child_node=nodes[child_id] child_node=(id,child_node[1]) nodes[child_id]=child_node for id,node in sorted(nodes.items()): node_type="root" if node[0]==-1 else "internal node" if node[1]else "leaf" print(f"node{id}: parent={node[0]},depth={depth(id)},{node_type},{node[1]}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var nodes : Map := (arguments ( )) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var k : OclAny := null; var c_list : OclAny := null; Sequence{id,k,c_list} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (nodes)->excludes(id) then ( nodes[id+1] := Sequence{-1, ()} ) else skip ; var node : OclAny := nodes[id+1] ; node := Sequence{node->first(), c_list} ; nodes[id+1] := node ; for child_id : c_list do ( if (nodes)->excludes(child_id) then ( nodes[child_id+1] := Sequence{-1, ()} ) else skip ; var child_node : OclAny := nodes[child_id+1] ; child_node := Sequence{id, child_node[1+1]} ; nodes[child_id+1] := child_node)) ; for _tuple : nodes->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sort() do (var _indx : int := 1; var id : OclAny := _tuple->at(_indx); _indx := _indx + 1; var node : OclAny := _tuple->at(_indx); var node_type : String := if node->first() = -1 then "root" else if node[1+1] then "internal node" else "leaf" endif endif ; execute (StringLib.formattedString("node{id}: parent={node[0]},depth={depth(id)},{node_type},{node[1]}"))->display()); operation depth(id : OclAny) : OclAny pre: true post: true activity: var depth : int := 0 ; var target_id : OclAny := id ; while nodes[target_id+1]->first() /= -1 do ( depth := depth + 1 ; target_id := nodes[target_id+1]->first()) ; return depth; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline def depthcheck(idx,depth): global depthlist,childlist depthlist[idx]['depth']=depth+1 if childlist[idx]!=[]: for child in childlist[idx]: depthcheck(child,depth+1) else : depthlist[idx]['type']='leaf' n=int(input()) childlist=[[]]*n parentlist=[-1]*n depthlist=[{'depth' : 0,'type' : 'internal node'}for _ in range(n)] for i in range(n): idx,c,*childs=map(int,input().split()) childlist[idx]=list(childs) for childidx in childs : parentlist[childidx]=idx for idx in range(n): if parentlist[idx]==-1 : depthlist[idx]['type']='root' for child in childlist[idx]: depthcheck(child,0) break for i in range(n): print('node %s: parent=%d,depth=%d,%s,%s' %(i,parentlist[i],depthlist[i]['depth'],depthlist[i]['type'],childlist[i])) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute depthlist : OclAny; attribute childlist : OclAny; operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; childlist := MatrixLib.elementwiseMult(Sequence{ Sequence{} }, n) ; var parentlist : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; depthlist := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Map{ 'depth' |-> 0 }->union(Map{ 'type' |-> 'internal node' }))) ; for i : Integer.subrange(0, n-1) do ( var c : OclAny := null; var childs : OclAny := null; Sequence{idx,c,childs} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; childlist[idx+1] := (childs) ; for childidx : childs do ( parentlist[childidx+1] := idx)) ; for idx : Integer.subrange(0, n-1) do ( if parentlist[idx+1] = -1 then ( depthlist[idx+1]->at('type') := 'root' ; for child : childlist[idx+1] do ( depthcheck(child, 0)) ; break ) else skip) ; for i : Integer.subrange(0, n-1) do ( execute (StringLib.format('node %s: parent=%d,depth=%d,%s,%s',Sequence{i, parentlist[i+1], depthlist[i+1]->at('depth'), depthlist[i+1]->at('type'), childlist[i+1]}))->display()); operation depthcheck(idx : OclAny, depth : OclAny) pre: true post: true activity: skip; skip ; depthlist[idx+1]->at('depth') := depth + 1 ; if childlist[idx+1] /= Sequence{} then ( for child : childlist[idx+1] do ( depthcheck(child, depth + 1)) ) else ( depthlist[idx+1]->at('type') := 'leaf' ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(input()) ary=[[int(_)for _ in line.strip().split()]for line in sys.stdin] ary.sort(key=lambda x : x[0]) def output(i,p,d,t,ch): print('node{}: parent={},depth={},{},{}'.format(i,p,d,t,ch)) bry=[{'id' : i,'parent' :-1,'depth' : 0,'type' : 'root','children' :[]}for i in range(n)] for node in ary : no=node[0] if node[1]: for cno in node[2 :]: bry[no]['children'].append(cno) bry[cno]['parent']=no if ary[cno][1]: bry[cno]['type']='internal node' else : bry[cno]['type']='leaf' else : if n>1 : bry[no]['type']='leaf' tmp=[(node['id'],node['parent'])for node in bry] root=[min(tmp,key=lambda x : x[1])[0]] flag=True while flag : flag=False tmp=[] for i in root : for cno in bry[i]['children']: bry[cno]['depth']=bry[i]['depth']+1 tmp.append(cno) flag=True root=tmp for node in bry : output(node['id'],node['parent'],node['depth'],node['type'],node['children']) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ary : Sequence := OclFile["System.in"]->select(line | true)->collect(line | (line->trim().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())))) ; ary := ary->sort() ; skip ; var bry : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Map{ 'id' |-> i }->union(Map{ 'parent' |-> -1 }->union(Map{ 'depth' |-> 0 }->union(Map{ 'type' |-> 'root' }->union(Map{ 'children' |-> Sequence{} })))))) ; for node : ary do ( var no : OclAny := node->first() ; if node[1+1] then ( for cno : node.subrange(2+1) do ((expr (atom (name bry)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name no)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'children'))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name cno)))))))) )))) ; bry[cno+1]->at('parent') := no ; if ary[cno+1][1+1] then ( bry[cno+1]->at('type') := 'internal node' ) else ( bry[cno+1]->at('type') := 'leaf' )) ) else ( if n > 1 then ( bry[no+1]->at('type') := 'leaf' ) else skip )) ; var tmp : Sequence := bry->select(node | true)->collect(node | (Sequence{node->at('id'), node->at('parent')})) ; var root : Sequence := Sequence{ min(tmp, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))))->first() } ; var flag : boolean := true ; while flag do ( flag := false ; tmp := Sequence{} ; for i : root do ( for cno : bry[i+1]->at('children') do ( bry[cno+1]->at('depth') := bry[i+1]->at('depth') + 1 ; execute ((cno) : tmp) ; flag := true)) ; root := tmp) ; for node : bry do ( output(node->at('id'), node->at('parent'), node->at('depth'), node->at('type'), node->at('children'))); operation output(i : OclAny, p : OclAny, d : OclAny, t : OclAny, ch : OclAny) pre: true post: true activity: execute (StringLib.interpolateStrings('node{}: parent={},depth={},{},{}', Sequence{i, p, d, t, ch}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class node(): def __init__(self,id,parent,child,depth,type_t): self.id=id self.parent=parent self.child=child self.depth=depth self.type_t=type_t def add(t,d,i,parent,depth): type_t='internal node' if d[i][1]==0 : type_t='leaf' if depth==0 : type_t='root' child=[] if not d[i][1]==0 : child=d[i][2 :] new_node=node(i,parent,d[i][2 :],depth,type_t) t.append(new_node) for c in child : add(t,d,c,i,depth+1) N=int(input()) tree=[] data=[[]for i in range(N)] for i in range(N): data[i]=[int(i)for i in input().split()] data.sort(key=lambda x : x[0]) root=[True for i in range(N)] for d in data : for c in d[2 :]: root[c]=False for i in range(N): if root[i]: add(tree,data,i,-1,0) tree.sort(key=lambda x : x.id) for t in tree : print(f'node{t.id}: parent={t.parent},depth={t.depth},{t.type_t},{t.child}') ------------------------------------------------------------ OCL File: --------- class node { static operation newnode() : node pre: true post: node->exists( _x | result = _x ); attribute id : OclAny := id; attribute parent : OclAny := parent; attribute child : OclAny := child; attribute depth : OclAny := depth; attribute type_t : OclAny := type_t; operation initialise(id : OclAny,parent : OclAny,child : OclAny,depth : OclAny,type_t : OclAny) : pre: true post: true activity: self.id := id ; self.parent := parent ; self.child := child ; self.depth := depth ; self.type_t := type_t; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var tree : Sequence := Sequence{} ; var data : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, N-1) do ( data[i+1] := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))) ; data := data->sort() ; var root : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (true)) ; for d : data do ( for c : d.subrange(2+1) do ( root[c+1] := false)) ; for i : Integer.subrange(0, N-1) do ( if root[i+1] then ( add(tree, data, i, -1, 0) ) else skip) ; tree := tree->sort() ; for t : tree do ( execute (StringLib.formattedString('node{t.id}: parent={t.parent},depth={t.depth},{t.type_t},{t.child}'))->display()); operation add(t : OclAny, d : OclAny, i : OclAny, parent : OclAny, depth : OclAny) pre: true post: true activity: type_t := 'internal node' ; if d[i+1][1+1] = 0 then ( type_t := 'leaf' ) else skip ; if depth = 0 then ( type_t := 'root' ) else skip ; child := Sequence{} ; if not(d[i+1][1+1] = 0) then ( child := d[i+1].subrange(2+1) ) else skip ; var new_node : node := (node.newnode()).initialise(i, parent, d[i+1].subrange(2+1), depth, type_t) ; execute ((new_node) : t) ; for c : child do ( add(t, d, c, i, depth + 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==1 : print(1) exit() a=[list(map(int,input().split()))for i in range(n)] s,r=[sum(ai)for ai in a],[0 in ai for ai in a].index(True) x,y=s[r],s[(r+1)% n] if x>=y or not all(i==r or si==y for i,si in enumerate(s)): print(-1) else : a[r][a[r].index(0)]=y-x fc=all(sum(a[i][j]for i in range(n))==y for j in range(n)) fld=sum(a[i][i]for i in range(n))==y frd=sum(a[i][n-i-1]for i in range(n))==y print(y-x if fc and fld and frd else-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (1)->display() ; exit() ) else skip ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var s : OclAny := null; var r : OclAny := null; Sequence{s,r} := Sequence{a->select(ai | true)->collect(ai | ((ai)->sum())),a->select(ai | true)->collect(ai | ((ai)->includes(0)))->indexOf(true) - 1} ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{s[r+1],s[(r + 1) mod n+1]} ; if (x->compareTo(y)) >= 0 or not(((argument (test (logical_test (logical_test (comparison (comparison (expr (atom (name i)))) == (comparison (expr (atom (name r)))))) or (logical_test (comparison (comparison (expr (atom (name si)))) == (comparison (expr (atom (name y)))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name si)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))))))))->forAll( _x | _x = true )) then ( execute (-1)->display() ) else ( a[r+1][a[r+1]->indexOf(0) - 1+1] := y - x ; var fc : boolean := ((argument (test (logical_test (comparison (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))) ))))) == (comparison (expr (atom (name y))))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->forAll( _x | _x = true ) ; var fld : boolean := ((argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->sum() = y ; var frd : boolean := ((argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name n))) - (expr (atom (name i)))) - (expr (atom (number (integer 1)))))))))) ])))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->sum() = y ; execute (if fc & fld & frd then y - x else -1 endif)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) a=list(map(int,input().split())) m=0 for x in set(a): s=a.count(x) m=max(m,s) if m>math.ceil(n/2): print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := 0 ; for x : Set{}->union((a)) do ( var s : int := a->count(x) ; m := Set{m, s}->max()) ; if (m->compareTo((n / 2)->ceil())) > 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def q(a,h): d[a]=h for b in t[a]: q(b,h+1) t,p,d={},{},{} input() for e in sys.stdin : e=e.split() t[e[0]]=e[2 :] for i in e[2 :]: p[i]=e[0] r=(set(t)-set(p)).pop() p[r]='-1' q(r,0) print('\n'.join(f"node{i}: parent={p[i]},depth={d[i]},{'root'if'-1'==p[i]else'internal node'if t[i]else'leaf'},[{','.join(t[i])}]" for i in map(str,sorted(map(int,t))))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var t : OclAny := null; var p : OclAny := null; var d : OclAny := null; Sequence{t,p,d} := Sequence{Set{},Set{},Set{}} ; input() ; for e : OclFile["System.in"] do ( var e : OclAny := e.split() ; t[e->first()+1] := e.subrange(2+1) ; for i : e.subrange(2+1) do ( p[i+1] := e->first())) ; var r : OclAny := (Set{}->union((t)) - Set{}->union((p)))->last() ; (Set{}->union((t)) - Set{}->union((p))) := (Set{}->union((t)) - Set{}->union((p)))->front() ; p[r+1] := '-1' ; q(r, 0) ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom f "node{i}: parent={p[i]},depth={d[i]},{'root'if'-1'==p[i]else'internal node'if t[i]else'leaf'},[{','.join(t[i])}]"))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name t)))))))) ))))))))) ))))))))) ))))))))), ' '))->display(); operation q(a : OclAny, h : OclAny) pre: true post: true activity: d[a+1] := h ; for b : t[a+1] do ( q(b, h + 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=input() a=[int(i)for i in l.split(" ")] if 0 not in a : print(-1) else : k=a.count(5) zeros=a.count(0) output=0 for i in range(1,k+1): if 5*i % 9==0 : output=int('5'*i+'0'*zeros) print(output) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : String := (OclFile["System.in"]).readLine() ; var a : Sequence := l.split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if (a)->excludes(0) then ( execute (-1)->display() ) else ( var k : int := a->count(5) ; var zeros : int := a->count(0) ; var output : int := 0 ; for i : Integer.subrange(1, k + 1-1) do ( if 5 * i mod 9 = 0 then ( output := ("" + ((StringLib.nCopies('5', i) + StringLib.nCopies('0', zeros))))->toInteger() ) else skip) ; execute (output)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bfs(v): distance=[-1]*n distance[v]=0 next=connection[v] next2=set() visited=[-1]*n visited[v]=1 visitct=1 ct=0 while len(next)!=0 and visitct!=n : ct+=1 for i in range(len(next)): if visited[next[i]]==-1 : distance[next[i]]=ct visited[next[i]]=1 visitct+=1 for j in range(len(connection[next[i]])): if visited[connection[next[i]][j]]==-1 : next2.add(connection[next[i]][j]) next=list(next2) next2=set() return distance n=int(input()) l=[list(map(int,input().split()))for i in range(n-1)] connection=[[]for i in range(n)] for i in range(n-1): connection[l[i][0]-1].append(l[i][1]-1) connection[l[i][1]-1].append(l[i][0]-1) if max(bfs(bfs(0).index(max(bfs(0)))))% 3==1 : print('Second') else : print('First') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Integer.subrange(0, n - 1-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var connection : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, n - 1-1) do ((expr (atom (name connection)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name connection)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) - (expr (atom (number (integer 1)))))))))) ))))) ; if (bfs(bfs(0)->indexOf((bfs(0))->max()) - 1))->max() mod 3 = 1 then ( execute ('Second')->display() ) else ( execute ('First')->display() ); operation bfs(v : OclAny) : OclAny pre: true post: true activity: var distance : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; distance[v+1] := 0 ; var next : OclAny := connection[v+1] ; var next2 : Set := Set{}->union(()) ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; visited[v+1] := 1 ; var visitct : int := 1 ; var ct : int := 0 ; while (next)->size() /= 0 & visitct /= n do ( ct := ct + 1 ; for i : Integer.subrange(0, (next)->size()-1) do ( if visited[[i+1].next()+1] = -1 then ( distance[[i+1].next()+1] := ct ; visited[[i+1].next()+1] := 1 ; visitct := visitct + 1 ; for j : Integer.subrange(0, (connection[[i+1].next()+1])->size()-1) do ( if visited[connection[[i+1].next()+1][j+1]+1] = -1 then ( execute ((connection[[i+1].next()+1][j+1]) : next2) ) else skip) ) else skip) ; next := (next2) ; next2 := Set{}->union(())) ; return distance; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heappush,heappop def dijkstra(graph : list,node : int,start : int)->list : inf=float('inf') dist=[inf]*node dist[start]=0 heap=[(0,start)] while heap : cost,thisNode=heappop(heap) for NextCost,NextNode in graph[thisNode]: dist_cand=dist[thisNode]+NextCost if dist_candtoInteger() ; var g : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, N - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := a - 1 ; b := b - 1 ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1))))))) , (test (logical_test (comparison (expr (atom (name b))))))) )))))))) )))) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1))))))) , (test (logical_test (comparison (expr (atom (name a))))))) )))))))) ))))) ; var d : OclAny := dijkstra(g, N, 0) ; var r : int := 0 ; var n : int := 0 ; for i : Integer.subrange(0, N-1) do ( if (r->compareTo(d[i+1])) < 0 then ( r := d[i+1] ; n := i ) else skip) ; r := (dijkstra(g, N, n))->max() ; if r mod 3 = 0 or r mod 3 = 2 then ( execute ('First')->display() ) else ( execute ('Second')->display() ); operation dijkstra(graph : Sequence(OclAny), node : int, start : int) : Sequence pre: true post: true activity: var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; var dist : Sequence := MatrixLib.elementwiseMult(Sequence{ Math_PINFINITY }, node) ; dist[start+1] := 0 ; var heap : Sequence := Sequence{ Sequence{0, start} } ; while heap do ( var cost : OclAny := null; var thisNode : OclAny := null; Sequence{cost,thisNode} := heappop(heap) ; for _tuple : graph[thisNode+1] do (var _indx : int := 1; var NextCost : OclAny := _tuple->at(_indx); _indx := _indx + 1; var NextNode : OclAny := _tuple->at(_indx); var dist_cand : OclAny := dist[thisNode+1] + NextCost ; if (dist_cand->compareTo(dist[NextNode+1])) < 0 then ( dist[NextNode+1] := dist_cand ; heappush(heap, Sequence{dist[NextNode+1], NextNode}) ) else skip)) ; return dist; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import deque,defaultdict INF=float('inf') MOD=10**9+7 dy,dx=(0,-1,0,1),(1,0,-1,0) def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def II(): return int(sys.stdin.readline()) def SI(): return input() def main(): n=II() G=defaultdict(list) for _ in range(n-1): a,b=LI_() G[a].append(b) G[b].append(a) def DFS(start): stack=deque([start]) dist=[INF]*n dist[start]=0 max_dist=0 farthest_v=start while stack : curr=stack.pop() for next in G[curr]: if dist[next]!=INF : continue dist[next]=dist[curr]+1 stack.append(next) if dist[next]>max_dist : max_dist=dist[next] farthest_v=next return farthest_v,max_dist v,d=DFS(0) u,d=DFS(v) if d==1 : d=0 print('First' if d % 3!=1 else 'Second') if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var INF : double := ("" + (('inf')))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; var dy : OclAny := null; var dx : OclAny := null; Sequence{dy,dx} := Sequence{Sequence{0, -1, 0, 1},Sequence{1, 0, -1, 0}} ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation SI() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation main() pre: true post: true activity: var n : OclAny := II() ; var G : OclAny := defaultdict(OclType["Sequence"]) ; for _anon : Integer.subrange(0, n - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := LI_() ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; skip ; var v : OclAny := null; var d : OclAny := null; Sequence{v,d} := DFS(0) ; var u : OclAny := null; var d : OclAny := null; Sequence{u,d} := DFS(v) ; if d = 1 then ( var d : int := 0 ) else skip ; execute (if d mod 3 /= 1 then 'First' else 'Second' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**7) input=sys.stdin.readline n=int(input()) graph=[[]for _ in range(n)] for i in range(n-1): a,b=map(int,input().split()) a-=1 b-=1 graph[a].append(b) graph[b].append(a) def dfs(v,dist,memo): memo[v]=dist for nv in graph[v]: if memo[nv]>=0 : continue dfs(nv,dist+1,memo) memo=[-1]*n dfs(0,0,memo) node=0 dist=0 for i in range(n): if memo[i]>dist : dist=memo[i] node=i memo=[-1]*n dfs(node,0,memo) dist=max(memo) count=dist+1 dp=[0]*(count+10) dp[0]=0 dp[1]=1 dp[2]=0 dp[3]=1 dp[4]=1 if count>=5 : for i in range(5,count+1): if dp[i-2]==1 and dp[i-1]==1 : dp[i]=0 else : dp[i]=1 if dp[count]: print("First") else : print("Second") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var graph : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, n - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := a - 1 ; b := b - 1 ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; skip ; memo := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; dfs(0, 0, memo) ; var node : int := 0 ; dist := 0 ; for i : Integer.subrange(0, n-1) do ( if (memo[i+1]->compareTo(dist)) > 0 then ( dist := memo[i+1] ; node := i ) else skip) ; memo := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; dfs(node, 0, memo) ; dist := (memo)->max() ; var count : OclAny := dist + 1 ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (count + 10)) ; dp->first() := 0 ; dp[1+1] := 1 ; dp[2+1] := 0 ; dp[3+1] := 1 ; dp[4+1] := 1 ; if count >= 5 then ( for i : Integer.subrange(5, count + 1-1) do ( if dp[i - 2+1] = 1 & dp[i - 1+1] = 1 then ( dp[i+1] := 0 ) else ( dp[i+1] := 1 )) ) else skip ; if dp[count+1] then ( execute ("First")->display() ) else ( execute ("Second")->display() ); operation dfs(v : OclAny, dist : OclAny, memo : OclAny) pre: true post: true activity: memo[v+1] := dist ; for nv : graph[v+1] do ( if memo[nv+1] >= 0 then ( continue ) else skip ; dfs(nv, dist + 1, memo)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import* def s(s): f,q=[1]*-~ n,deque([(s,0)]) while q : t,c=q.popleft() for v in e[t]: q+=[(v,c+1)]*f[v] f[v]=0 return t,c n,*t=map(int,open(0).read().split()) e=[[]for _ in[0]*-~ n] for a,b in zip(t[: : 2],t[1 : : 2]): e[a]+=b, e[b]+=a, print('SFeicrosntd'[s(s(1)[0])[1]% 3!=1 : : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var e : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, -MathLib.bitwiseNot(n))->select(_anon | true)->collect(_anon | (Sequence{})) ; for _tuple : Integer.subrange(1, t(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{t(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->at(_indx), t(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->at(_indx)} ) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); e[a+1] := e[a+1] + (testlist (test (logical_test (comparison (expr (atom (name b)))))) ,) ; e[b+1] := e[b+1] + (testlist (test (logical_test (comparison (expr (atom (name a)))))) ,)) ; execute ('SFeicrosntd'(subscript (test (logical_test (comparison (comparison (expr (expr (atom (name s)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) % (expr (atom (number (integer 3)))))) != (comparison (expr (atom (number (integer 1)))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); operation s(s : OclAny) : OclAny pre: true post: true activity: var f : OclAny := null; var q : OclAny := null; Sequence{f,q} := Sequence{MatrixLib.elementwiseMult(Sequence{ 1 }, -MathLib.bitwiseNot(n)),(Sequence{ Sequence{s, 0} })} ; while q do ( var t : OclAny := null; var c : OclAny := null; Sequence{t,c} := q->first() ; q := q->tail() ; for v : e[t+1] do ( q := q + MatrixLib.elementwiseMult(Sequence{ Sequence{v, c + 1} }, f[v+1]) ; f[v+1] := 0)) ; return t, c; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect primes=[0,0]+[1]*999999 for i in range(2,1001): if primes[i]: for j in range(i*i,1000001,i): primes[j]=0 prime_value=[i for i in range(len(primes))if primes[i]] while True : n=int(input()) if n==0 : break x=bisect.bisect_right(prime_value,n//2) print(sum(1 for p in prime_value[: x]if primes[n-p])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var primes : Sequence := Sequence{0}->union(Sequence{ 0 })->union(MatrixLib.elementwiseMult(Sequence{ 1 }, 999999)) ; for i : Integer.subrange(2, 1001-1) do ( if primes[i+1] then ( for j : Integer.subrange(i * i, 1000001-1)->select( $x | ($x - i * i) mod i = 0 ) do ( primes[j+1] := 0) ) else skip) ; var prime_value : Sequence := Integer.subrange(0, (primes)->size()-1)->select(i | primes[i+1])->collect(i | (i)) ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var x : OclAny := bisect.bisect_right(prime_value, n div 2) ; execute (((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name p)))) in (logical_test (comparison (expr (atom (name prime_value)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name x)))))))) ]))))) (comp_iter if (test (logical_test (comparison (expr (atom (name primes)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (name p))))))))) ]))))))))))->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,bisect PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") def primes2(n): n,correction=n-n % 6+6,2-(n % 6>1) sieve=[True]*(n//3) for i in range(1,int(n**0.5)//3+1): if sieve[i]: k=3*i+1 | 1 sieve[k*k//3 : : 2*k]=[False]*((n//6-k*k//6-1)//k+1) sieve[k*(k-2*(i & 1)+4)//3 : : 2*k]=[False]*((n//6-k*(k-2*(i & 1)+4)//6-1)//k+1) return[2,3]+[3*i+1 | 1 for i in range(1,n//3-correction)if sieve[i]] primes=primes2(10**6) pset=set(primes) while True : n=int(input()) if n==0 : break S=0 for p in primes : if p>n//2 : break if n-p in pset : S+=1 print(S) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; skip ; var primes : OclAny := primes2((10)->pow(6)) ; var pset : Set := Set{}->union((primes)) ; while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var S : int := 0 ; for p : primes do ( if (p->compareTo(n div 2)) > 0 then ( break ) else skip ; if (pset)->includes(n - p) then ( S := S + 1 ) else skip) ; execute (S)->display()); operation primes2(n : OclAny) : OclAny pre: true post: true activity: var correction : OclAny := null; Sequence{n,correction} := Sequence{n - n mod 6 + 6,2 - (n mod 6 > 1)} ; var sieve : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (n div 3)) ; for i : Integer.subrange(1, ("" + (((n)->pow(0.5))))->toInteger() div 3 + 1-1) do ( if sieve[i+1] then ( var k : int := MathLib.bitwiseOr(3 * i + 1, 1) ; sieve(subscript (test (logical_test (comparison (expr (expr (expr (atom (name k))) * (expr (atom (name k)))) // (expr (atom (number (integer 3)))))))) : (sliceop : (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name k))))))))) := MatrixLib.elementwiseMult(Sequence{ false }, ((n div 6 - k * k div 6 - 1) div k + 1)) ; sieve(subscript (test (logical_test (comparison (expr (expr (expr (atom (name k))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name k))) - (expr (expr (atom (number (integer 2)))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) & (expr (atom (number (integer 1))))))))) ))))) + (expr (atom (number (integer 4))))))))) )))) // (expr (atom (number (integer 3)))))))) : (sliceop : (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name k))))))))) := MatrixLib.elementwiseMult(Sequence{ false }, ((n div 6 - k * (k - 2 * (MathLib.bitwiseAnd(i, 1)) + 4) div 6 - 1) div k + 1)) ) else skip) ; return Sequence{2}->union(Sequence{ 3 })->union(Integer.subrange(1, n div 3 - correction-1)->select(i | sieve[i+1])->collect(i | (MathLib.bitwiseOr(3 * i + 1, 1)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline write=sys.stdout.write M=1000000 sq=int(M**.5) pl=[] p=[1]*(M+1) p[0]=p[1]=0 for x in range(2,sq+1): if p[x]: for y in range(x*x,M+1,x): p[y]=0 pl.append(x) for x in range(sq+1,M+1): if p[x]: pl.append(x) def solve(): N=int(readline()) if N==0 : return False ans=0 N2=N//2 for x in pl : if N2pow(.5))))->toInteger() ; var pl : Sequence := Sequence{} ; var p : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (M + 1)) ; p->first() := 0; var p[1+1] : int := 0 ; for x : Integer.subrange(2, sq + 1-1) do ( if p[x+1] then ( for y : Integer.subrange(x * x, M + 1-1)->select( $x | ($x - x * x) mod x = 0 ) do ( p[y+1] := 0) ; execute ((x) : pl) ) else skip) ; for x : Integer.subrange(sq + 1, M + 1-1) do ( if p[x+1] then ( execute ((x) : pl) ) else skip) ; skip ; while solve() do (); operation solve() : OclAny pre: true post: true activity: var N : int := ("" + ((readline())))->toInteger() ; if N = 0 then ( return false ) else skip ; var ans : int := 0 ; var N2 : int := N div 2 ; for x : pl do ( if (N2->compareTo(x)) < 0 then ( break ) else skip ; if p[N - x+1] then ( ans := ans + 1 ) else skip) ; write(StringLib.format("%d\n",ans)) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def maxSumPair(arr1,n1,arr2,n2): max1=-sys.maxsize-1 max2=-sys.maxsize-1 for i in range(0,n1): if(arr1[i]>max1): max1=arr1[i] for i in range(0,n2): if(arr2[i]>max2): max2=arr2[i] return max1+max2 arr1=[10,2,3] arr2=[3,4,7] n1=len(arr1) n2=len(arr2) print(maxSumPair(arr1,n1,arr2,n2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr1 := Sequence{10}->union(Sequence{2}->union(Sequence{ 3 })) ; arr2 := Sequence{3}->union(Sequence{4}->union(Sequence{ 7 })) ; n1 := (arr1)->size() ; n2 := (arr2)->size() ; execute (maxSumPair(arr1, n1, arr2, n2))->display(); operation maxSumPair(arr1 : OclAny, n1 : OclAny, arr2 : OclAny, n2 : OclAny) : OclAny pre: true post: true activity: var max1 : double := -(trailer . (name maxsize)) - 1 ; var max2 : double := -(trailer . (name maxsize)) - 1 ; for i : Integer.subrange(0, n1-1) do ( if ((arr1[i+1]->compareTo(max1)) > 0) then ( max1 := arr1[i+1] ) else skip) ; for i : Integer.subrange(0, n2-1) do ( if ((arr2[i+1]->compareTo(max2)) > 0) then ( max2 := arr2[i+1] ) else skip) ; return max1 + max2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin from bisect import bisect_left input=stdin.readline def create_prime_list(limit): x=limit**0.5 primes=[] nums=[x for x in range(2,limit+1)] while nums[0]<=x : primes.append(nums[0]) current_prime=nums[0] nums=[x for x in nums if x % current_prime!=0] primes.extend(nums) return primes def main(args): primes=create_prime_list(1000000) while True : n=int(input()) if n==0 : break ans=0 for i in range(n): a=primes[i] if a>n/2 : break i=bisect_left(primes,n-a) if i!=len(primes)and primes[i]==n-a : ans+=1 print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation create_prime_list(limit : OclAny) : OclAny pre: true post: true activity: var x : double := (limit)->pow(0.5) ; var primes : Sequence := Sequence{} ; var nums : Sequence := Integer.subrange(2, limit + 1-1)->select(x | true)->collect(x | (x)) ; while (nums->first()->compareTo(x)) <= 0 do ( execute ((nums->first()) : primes) ; var current_prime : OclAny := nums->first() ; nums := nums->select(x | x mod current_prime /= 0)->collect(x | (x))) ; primes := primes->union(nums) ; return primes; operation main(args : OclAny) pre: true post: true activity: primes := create_prime_list(1000000) ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := primes[i+1] ; if (a->compareTo(n / 2)) > 0 then ( break ) else skip ; var i : OclAny := bisect_left(primes, n - a) ; if i /= (primes)->size() & primes[i+1] = n - a then ( ans := ans + 1 ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import array def is_prime_number(num): limit=int(num**0.5) for lp in range(3,limit+1,2): if num % lp==0 : return False return True LENGTH=1000000 prime_number_list=array.array("i",[True]*(LENGTH+1)) prime_number_list[0]=False prime_number_list[1]=False for lp in range(4,LENGTH+1,2): prime_number_list[lp]=False limit=int((LENGTH+1)**0.5) for lp in range(3,limit+1,2): if is_prime_number(lp): for lp2 in range(lp*2,LENGTH+1,lp): prime_number_list[lp2]=False while True : input_num=int(input()) if input_num==0 : break count=0 for lp in range(2,input_num//2+1): if prime_number_list[lp]and prime_number_list[input_num-lp]: count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var LENGTH : int := 1000000 ; var prime_number_list : OclAny := array.array("i", MatrixLib.elementwiseMult(Sequence{ true }, (LENGTH + 1))) ; prime_number_list->first() := false ; prime_number_list[1+1] := false ; for lp : Integer.subrange(4, LENGTH + 1-1)->select( $x | ($x - 4) mod 2 = 0 ) do ( prime_number_list[lp+1] := false) ; limit := ("" + ((((LENGTH + 1))->pow(0.5))))->toInteger() ; for lp : Integer.subrange(3, limit + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if is_prime_number(lp) then ( for lp2 : Integer.subrange(lp * 2, LENGTH + 1-1)->select( $x | ($x - lp * 2) mod lp = 0 ) do ( prime_number_list[lp2+1] := false) ) else skip) ; while true do ( var input_num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if input_num = 0 then ( break ) else skip ; var count : int := 0 ; for lp : Integer.subrange(2, input_num div 2 + 1-1) do ( if prime_number_list[lp+1] & prime_number_list[input_num - lp+1] then ( count := count + 1 ) else skip) ; execute (count)->display()); operation is_prime_number(num : OclAny) : OclAny pre: true post: true activity: var limit : int := ("" + (((num)->pow(0.5))))->toInteger() ; for lp : Integer.subrange(3, limit + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if num mod lp = 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=input() x=sorted(a) y=sorted(b) cnt=0 if x!=y : print("NO") else : n=min(len(a),len(b)) for i in range(n): if a[i]!=b[i]: cnt+=1 if cnt>2 : print("NO") break else : if cnt==2 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var x : Sequence := a->sort() ; var y : Sequence := b->sort() ; var cnt : int := 0 ; if x /= y then ( execute ("NO")->display() ) else ( var n : OclAny := Set{(a)->size(), (b)->size()}->min() ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) != (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cnt)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name cnt)))) > (comparison (expr (atom (number (integer 2)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name cnt)))) == (comparison (expr (atom (number (integer 2)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) ))))))))))))))))))) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()); a=1 for i in range(3,2*n+1): a=a*i %(10**9+7) print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var a : int := 1 ; for i : Integer.subrange(3, 2 * n + 1-1) do ( a := a * i mod ((10)->pow(9) + 7)) ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) s=1 k=(10**9)+7 for i in range(3,(2*n)+1): s=(s*i)% k print((s)% k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : int := 1 ; var k : double := ((10)->pow(9)) + 7 ; for i : Integer.subrange(3, (2 * n) + 1-1) do ( s := (s * i) mod k) ; execute ((s) mod k)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline import math def solve(): n=int(input()) mo=10**9+7 ans=1 if n==1 : return 1 ans=1 for i in range(3,2*n+1): ans*=i % mo ans %=mo return ans % mo for _ in range(int(input())): print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (solve())->display()); operation solve() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mo : double := (10)->pow(9) + 7 ; var ans : int := 1 ; if n = 1 then ( return 1 ) else skip ; ans := 1 ; for i : Integer.subrange(3, 2 * n + 1-1) do ( ans := ans * i mod mo ; ans := ans mod mo) ; return ans mod mo; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) res=1 for j in range(3,2*n+1): res*=j res %=1000000007 print(res) t=int(input()) while t>0 : t-=1 solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( t := t - 1 ; solve()); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : int := 1 ; for j : Integer.subrange(3, 2 * n + 1-1) do ( res := res * j ; res := res mod 1000000007) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from collections import Counter,deque from sys import stdout import time from math import factorial,log,gcd import sys from decimal import Decimal from heapq import* def S(): return sys.stdin.readline().split() def I(): return[int(i)for i in sys.stdin.readline().split()] def II(): return int(sys.stdin.readline()) def IS(): return sys.stdin.readline().replace('\n','') def main(): n=II() p=1 for i in range(2,2*n): p=(p*(i+1))% mod print(p) if __name__=='__main__' : mod=10**9+7 for _ in range(II()): main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var mod : double := (10)->pow(9) + 7 ; for _anon : Integer.subrange(0, II()-1) do ( main()) ) else skip; operation S() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation IS() : OclAny pre: true post: true activity: return sys.stdin.readLine().replace(' ', ''); operation main() pre: true post: true activity: var n : OclAny := II() ; var p : int := 1 ; for i : Integer.subrange(2, 2 * n-1) do ( p := (p * (i + 1)) mod mod) ; execute (p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=[int(i)for i in input().split()] b=bin(k)[2 :] ans=0 for i in range(len(b)): ans+=int(b[i])*pow(n,len(b)-i-1,1000000007) print(ans % 1000000007) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var b : OclAny := bin(k).subrange(2+1) ; var ans : int := 0 ; for i : Integer.subrange(0, (b)->size()-1) do ( ans := ans + ("" + ((b[i+1])))->toInteger() * (n)->pow((b)->size() - i - 1)) ; execute (ans mod 1000000007)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) MOD_MAX=(10**9)+7 for t in range(T): n,k=map(int,input().split()) s=0 pv=0 while k>0 : rem=k % 2 if rem==1 : s=(s+((n**pv)% MOD_MAX))% MOD_MAX k=int(k/2) pv+=1 print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var MOD_MAX : double := ((10)->pow(9)) + 7 ; for t : Integer.subrange(0, T-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : int := 0 ; var pv : int := 0 ; while k > 0 do ( var rem : int := k mod 2 ; if rem = 1 then ( s := (s + (((n)->pow(pv)) mod MOD_MAX)) mod MOD_MAX ) else skip ; var k : int := ("" + ((k / 2)))->toInteger() ; pv := pv + 1) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def operations(op,n,k): i,count=0,0 nVal=0 minimum=10**9 for i in range(n): nVal+=op[i] minimum=min(minimum,nVal) if((k+nVal)<=0): return(i+1) if(nVal>=0): return-1 times=(k-abs(minimum))//abs(nVal) k=(k-(times*abs(nVal))) count=(times*n) while(k>0): for i in range(n): k=k+op[i] count+=1 if(k<=0): break return count op=[-60,65,-1,14,-25] n=len(op) k=100000 print(operations(op,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; op := Sequence{-60}->union(Sequence{65}->union(Sequence{-1}->union(Sequence{14}->union(Sequence{ -25 })))) ; n := (op)->size() ; k := 100000 ; execute (operations(op, n, k))->display(); operation operations(op : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var i : OclAny := null; var count : OclAny := null; Sequence{i,count} := Sequence{0,0} ; var nVal : int := 0 ; var minimum : double := (10)->pow(9) ; for i : Integer.subrange(0, n-1) do ( nVal := nVal + op[i+1] ; minimum := Set{minimum, nVal}->min() ; if ((k + nVal) <= 0) then ( return (i + 1) ) else skip) ; if (nVal >= 0) then ( return -1 ) else skip ; var times : int := (k - (minimum)->abs()) div (nVal)->abs() ; k := (k - (times * (nVal)->abs())) ; var count : double := (times * n) ; while (k > 0) do ( for i : Integer.subrange(0, n-1) do ( k := k + op[i+1] ; count := count + 1 ; if (k <= 0) then ( break ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for t1 in range(t): l=list(map(int,input().split())) ans=0 for i in range(31,-1,-1): if(l[1]&(1<toInteger() ; for t1 : Integer.subrange(0, t-1) do ( var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(-1 + 1, 31)->reverse() do ( if (MathLib.bitwiseAnd(l[1+1], (1 * (2->pow(i)))) /= 0) then ( ans := ans + ((l->first())->pow(i)) ) else skip) ; ans := ans mod ((10)->pow(9) + 7) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in[0]*int(input()): n,k=map(int,input().split()) s=[] ns=0 while k>=1 : s.append(k % 2) k//=2 ans=0 p=0 for i in s : ans+=i*(n**p) p+=1 print(ans %(1000000000+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := Sequence{} ; var ns : int := 0 ; while k >= 1 do ( execute ((k mod 2) : s) ; k := k div 2) ; var ans : int := 0 ; var p : int := 0 ; for i : s do ( ans := ans + i * ((n)->pow(p)) ; p := p + 1) ; execute (ans mod (1000000000 + 7))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def solve(n,k): bink=bin(k)[2 :][: :-1] sm=0 for i in range(len(bink)): if bink[i]=='1' : sm=(sm+n**(i))%(10**9+7) return int(sm) for t in range(int(input())): n,k=map(int,input().split()) print(solve(n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (solve(n, k))->display()); operation solve(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var bink : OclAny := bin(k).subrange(2+1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var sm : int := 0 ; for i : Integer.subrange(0, (bink)->size()-1) do ( if bink[i+1] = '1' then ( sm := (sm + (n)->pow((i))) mod ((10)->pow(9) + 7) ) else skip) ; return ("" + ((sm)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s1=input() s2=input() if len(s1)!=len(s2): print("NO") exit() res=[] for i in range(len(s1)): if s1[i]!=s2[i]: res.append(i) if len(res)>2 : print("NO") exit() if len(res)==0 : print("YES") exit() if len(res)!=2 or s1[res[0]]!=s2[res[1]]or s1[res[1]]!=s2[res[0]]: print("NO") exit() print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s1 : String := (OclFile["System.in"]).readLine() ; var s2 : String := (OclFile["System.in"]).readLine() ; if (s1)->size() /= (s2)->size() then ( execute ("NO")->display() ; exit() ) else skip ; var res : Sequence := Sequence{} ; for i : Integer.subrange(0, (s1)->size()-1) do ( if s1[i+1] /= s2[i+1] then ( execute ((i) : res) ) else skip ; if (res)->size() > 2 then ( execute ("NO")->display() ; exit() ) else skip) ; if (res)->size() = 0 then ( execute ("YES")->display() ; exit() ) else skip ; if (res)->size() /= 2 or s1[res->first()+1] /= s2[res[1+1]+1] or s1[res[1+1]+1] /= s2[res->first()+1] then ( execute ("NO")->display() ; exit() ) else skip ; execute ("YES")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys for i in range(int(input())): r,g,b=map(int,input().split()) m=max(r,b,g) su=r+g+b su-=m ans=0 if(su>m): m+=(su-m)/2 ans=int(m) print(ans) continue ans=su print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var r : OclAny := null; var g : OclAny := null; var b : OclAny := null; Sequence{r,g,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : OclAny := Set{r, b, g}->max() ; var su : OclAny := r + g + b ; su := su - m ; var ans : int := 0 ; if ((su->compareTo(m)) > 0) then ( m := m + (su - m) / 2 ; ans := ("" + ((m)))->toInteger() ; execute (ans)->display() ; continue ) else skip ; ans := su ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a=list(map(int,input().split())) a.sort() if a[2]<=a[0]+a[1]: print(sum(a)//2) else : print(a[1]+a[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; if (a[2+1]->compareTo(a->first() + a[1+1])) <= 0 then ( execute ((a)->sum() div 2)->display() ) else ( execute (a[1+1] + a->first())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): x,y,z=map(int,input().split()) print("%d" %(min(x+y,x+z,y+z,(x+y+z)/2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (StringLib.format("%d",(Set{x + y, x + z, y + z, (x + y + z) / 2}->min())))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for z in range(int(input())): li=list(map(int,input().split())) li.sort() if li[0]+li[1]<=li[2]: print(li[0]+li[1]) else : print(sum(li)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for z : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var li : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; li := li->sort() ; if (li->first() + li[1+1]->compareTo(li[2+1])) <= 0 then ( execute (li->first() + li[1+1])->display() ) else ( execute ((li)->sum() div 2)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for j in range(int(input())): a=list(map(int,input().split())) a.sort() a=a[: :-1] if a[0]<=a[1]+a[2]: print((a[0]+a[1]+a[2])//2) else : print(a[1]+a[2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for j : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; a := a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; if (a->first()->compareTo(a[1+1] + a[2+1])) <= 0 then ( execute ((a->first() + a[1+1] + a[2+1]) div 2)->display() ) else ( execute (a[1+1] + a[2+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dic={0 : "A",1 : "B",2 : "C",3 : "D",4 : "E"} while True : sa=list(map(int,input().split())) if sa==[0,0]: break lst=[sum(sa)] for _ in range(4): lst.append(sum(map(int,input().split()))) print(dic[lst.index(max(lst))],max(lst)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dic : Map := Map{ 0 |-> "A" }->union(Map{ 1 |-> "B" }->union(Map{ 2 |-> "C" }->union(Map{ 3 |-> "D" }->union(Map{ 4 |-> "E" })))) ; while true do ( var sa : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if sa = Sequence{0}->union(Sequence{ 0 }) then ( break ) else skip ; var lst : Sequence := Sequence{ (sa)->sum() } ; for _anon : Integer.subrange(0, 4-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum()) : lst)) ; execute (dic[lst->indexOf((lst)->max()) - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- pref=[0]*100010 ; def isPerfectCube(x): cr=round(x**(1/3)); rslt=x if(cr*cr*cr==x)else 0 ; return rslt ; def compute(): for i in range(1,100001): pref[i]=pref[i-1]+isPerfectCube(i); def printSum(L,R): sum=pref[R]-pref[L-1]; print(sum,end=" "); if __name__=="__main__" : compute(); Q=4 ; arr=[[1,10],[1,100],[2,25],[4,50]]; for i in range(Q): printSum(arr[i][0],arr[i][1]); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var pref : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100010); ; skip ; skip ; skip ; if __name__ = "__main__" then ( compute(); ; var Q : int := 4; ; var arr : Sequence := Sequence{Sequence{1}->union(Sequence{ 10 })}->union(Sequence{Sequence{1}->union(Sequence{ 100 })}->union(Sequence{Sequence{2}->union(Sequence{ 25 })}->union(Sequence{ Sequence{4}->union(Sequence{ 50 }) }))); ; for i : Integer.subrange(0, Q-1) do ( printSum(arr[i+1]->first(), arr[i+1][1+1]);) ) else skip; operation isPerfectCube(x : OclAny) pre: true post: true activity: var cr : double := ((x)->pow((1 / 3)))->round(); ; var rslt : OclAny := if (cr * cr * cr = x) then x else 0 endif; ; return rslt;; operation compute() pre: true post: true activity: for i : Integer.subrange(1, 100001-1) do ( pref[i+1] := pref[i - 1+1] + isPerfectCube(i);); operation printSum(L : OclAny, R : OclAny) pre: true post: true activity: var sum : double := pref[R+1] - pref[L - 1+1]; ; execute (sum)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : T=[] am,pm=[int(x)for x in input().split()] if am==0 and pm==0 : break T.append(am+pm) for i in range(4): am,pm=[int(x)for x in input().split()] T.append(am+pm) num=sorted(list(enumerate(T)),key=lambda x :-x[1])[0][0] print("ABCDEF"[num],T[num]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var T : Sequence := Sequence{} ; var am : OclAny := null; var pm : OclAny := null; Sequence{am,pm} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if am = 0 & pm = 0 then ( break ) else skip ; execute ((am + pm) : T) ; for i : Integer.subrange(0, 4-1) do ( var am : OclAny := null; var pm : OclAny := null; Sequence{am,pm} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((am + pm) : T)) ; var num : OclAny := sorted((Integer.subrange(1, (T)->size())->collect( _indx | Sequence{_indx-1, (T)->at(_indx)} )), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr - (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))))))->first()->first() ; execute ("ABCDEF"[num+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys while True : slist={'A' : 0,'B' : 0,'C' : 0,'D' : 0,'E' : 0} for c in 'ABCDE' : s1,s2=map(int,input().split()) if s1==0 and s2==0 : sys.exit() slist[c]=s1+s2 print(*sorted(slist.items(),key=lambda x : x[1])[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var slist : Map := Map{ 'A' |-> 0 }->union(Map{ 'B' |-> 0 }->union(Map{ 'C' |-> 0 }->union(Map{ 'D' |-> 0 }->union(Map{ 'E' |-> 0 })))) ; for c : 'ABCDE'->characters() do ( var s1 : OclAny := null; var s2 : OclAny := null; Sequence{s1,s2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if s1 = 0 & s2 = 0 then ( sys.exit() ) else skip ; slist[c+1] := s1 + s2) ; execute ((argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name slist)) (trailer . (name items) (arguments ( )))))))) , (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))))) ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : a,b=map(int,input().split(" ")) if a==0 and b==0 : break c,d=map(int,input().split(" ")) e,f=map(int,input().split(" ")) g,h=map(int,input().split(" ")) i,j=map(int,input().split(" ")) listsum=[a+b,c+d,e+f,g+h,i+j] listsum.sort() if listsum[-1]==a+b : print("A",listsum[-1]) elif listsum[-1]==c+d : print("B",listsum[-1]) elif listsum[-1]==e+f : print("C",listsum[-1]) elif listsum[-1]==g+h : print("D",listsum[-1]) elif listsum[-1]==i+j : print("E",listsum[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 0 & b = 0 then ( break ) else skip ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var e : OclAny := null; var f : OclAny := null; Sequence{e,f} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var g : OclAny := null; var h : OclAny := null; Sequence{g,h} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var listsum : Sequence := Sequence{a + b}->union(Sequence{c + d}->union(Sequence{e + f}->union(Sequence{g + h}->union(Sequence{ i + j })))) ; listsum := listsum->sort() ; if listsum->last() = a + b then ( execute ("A")->display() ) else (if listsum->last() = c + d then ( execute ("B")->display() ) else (if listsum->last() = e + f then ( execute ("C")->display() ) else (if listsum->last() = g + h then ( execute ("D")->display() ) else (if listsum->last() = i + j then ( execute ("E")->display() ) else skip ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): from sys import stdin f_i=stdin while True : s1A,s2A=map(int,f_i.readline().split()) if s1A==0 and s2A==0 : break sales=[(s1A+s2A,'A')] for shop in 'BCDE' : cnt=sum(map(int,f_i.readline().split())) sales.append((cnt,shop)) cnt,shop=max(sales) print(f"{shop}{cnt}") solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: skip ; var f_i : OclAny := stdin ; while true do ( var s1A : OclAny := null; var s2A : OclAny := null; Sequence{s1A,s2A} := (f_i.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if s1A = 0 & s2A = 0 then ( break ) else skip ; var sales : Sequence := Sequence{ Sequence{s1A + s2A, 'A'} } ; for shop : 'BCDE'->characters() do ( var cnt : OclAny := ((f_i.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum() ; execute ((Sequence{cnt, shop}) : sales)) ; var shop : OclAny := null; Sequence{cnt,shop} := (sales)->max() ; execute (StringLib.formattedString("{shop}{cnt}"))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt from collections import defaultdict,deque from bisect import bisect_left as b_l from bisect import bisect_right as b_r import sys a=input() b=input() cnt=[] if(len(a)!=len(b)): print("NO") else : for i in range(len(a)): if(a[i]!=b[i]): cnt.append(i) if(len(cnt)!=2): print("NO") else : if(a[cnt[0]]==b[cnt[-1]]and a[cnt[-1]]==b[cnt[0]]): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var cnt : Sequence := Sequence{} ; if ((a)->size() /= (b)->size()) then ( execute ("NO")->display() ) else ( for i : Integer.subrange(0, (a)->size()-1) do ( if (a[i+1] /= b[i+1]) then ( execute ((i) : cnt) ) else skip) ; if ((cnt)->size() /= 2) then ( execute ("NO")->display() ) else ( if (a[cnt->first()+1] = b[cnt->last()+1] & a[cnt->last()+1] = b[cnt->first()+1]) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def isprime(n): i=2 for i in range(2,int((math.sqrt(n)+1))): if n % i==0 : return False return True def LegendreConjecture(n): print("Primes in the range ",n*n," and ",(n+1)*(n+1)," are:") for i in range(n*n,(((n+1)*(n+1))+1)): if(isprime(i)): print(i) n=50 LegendreConjecture(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 50 ; LegendreConjecture(n); operation isprime(n : OclAny) : OclAny pre: true post: true activity: var i : int := 2 ; for i : Integer.subrange(2, ("" + ((((n)->sqrt() + 1))))->toInteger()-1) do ( if n mod i = 0 then ( return false ) else skip) ; return true; operation LegendreConjecture(n : OclAny) pre: true post: true activity: execute ("Primes in the range ")->display() ; for i : Integer.subrange(n * n, (((n + 1) * (n + 1)) + 1)-1) do ( if (isprime(i)) then ( execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countRotations(n): l=len(n) if(l==1): oneDigit=(int)(n[0]) if(oneDigit % 4==0): return 1 return 0 count=0 for i in range(0,l-1): twoDigit=(int)(n[i])*10+(int)(n[i+1]) if(twoDigit % 4==0): count=count+1 twoDigit=(int)(n[l-1])*10+(int)(n[0]) if(twoDigit % 4==0): count=count+1 return count n="4834" print("Rotations: ",countRotations(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := "4834" ; execute ("Rotations: ")->display(); operation countRotations(n : OclAny) : OclAny pre: true post: true activity: var l : int := (n)->size() ; if (l = 1) then ( var oneDigit : OclAny := (OclType["int"])(n->first()) ; if (oneDigit mod 4 = 0) then ( return 1 ) else skip ; return 0 ) else skip ; var count : int := 0 ; for i : Integer.subrange(0, l - 1-1) do ( var twoDigit : double := (OclType["int"])(n[i+1]) * 10 + (OclType["int"])(n[i + 1+1]) ; if (twoDigit mod 4 = 0) then ( count := count + 1 ) else skip) ; twoDigit := (OclType["int"])(n[l - 1+1]) * 10 + (OclType["int"])(n->first()) ; if (twoDigit mod 4 = 0) then ( count := count + 1 ) else skip ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def decomp(n,k): i=2 mylist=[] while i*i<=n and len(mylist)collect( _x | (OclType["int"])->apply(_x) ) ; var result : OclAny := decomp(n, k) ; if (result)->size() = k then ( execute ((argument * (test (logical_test (comparison (expr (atom (name result))))))))->display() ) else ( execute (-1)->display() ); operation decomp(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var i : int := 2 ; var mylist : Sequence := Sequence{} ; while (i * i->compareTo(n)) <= 0 & ((mylist)->size()->compareTo(k - 1)) < 0 do ( if n mod i = 0 then ( execute ((i) : mylist) ; n := n div i ) else ( i := i + 1 )) ; execute ((n) : mylist) ; return mylist; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,h=map(int,input().split()) i=2 a=[] while i*i<=n : while n % i==0 : a.append(i) n=n//i i=i+1 if n>1 : a.append(n) if len(a)h : h1=a[0]*a[1] a.remove(a[0]) a[0]=h1 print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var h : OclAny := null; Sequence{n,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var i : int := 2 ; var a : Sequence := Sequence{} ; while (i * i->compareTo(n)) <= 0 do ( while n mod i = 0 do ( execute ((i) : a) ; var n : int := n div i) ; i := i + 1) ; if n > 1 then ( execute ((n) : a) ) else skip ; if ((a)->size()->compareTo(h)) < 0 then ( execute (-1)->display() ) else ( while ((a)->size()->compareTo(h)) > 0 do ( var h1 : double := a->first() * a[1+1] ; execute ((a->first()) /: a) ; a->first() := h1) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) factors=[] d=2 while d*d<=n : if n % d==0 : factors.append(d) n//=d else : d+=1 factors.append(n) if len(factors)k : l=factors.pop() d=factors.pop() g=l*d factors.append(g) print(" ".join(map(str,factors))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var factors : Sequence := Sequence{} ; var d : int := 2 ; while (d * d->compareTo(n)) <= 0 do ( if n mod d = 0 then ( execute ((d) : factors) ; n := n div d ) else ( d := d + 1 )) ; execute ((n) : factors) ; if ((factors)->size()->compareTo(k)) < 0 then ( execute ("-1")->display() ) else ( while ((factors)->size()->compareTo(k)) > 0 do ( var l : OclAny := factors->last() ; factors := factors->front() ; d := factors->last() ; factors := factors->front() ; var g : double := l * d ; execute ((g) : factors)) ; execute (StringLib.sumStringsWithSeparator(((factors)->collect( _x | (OclType["String"])->apply(_x) )), " "))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys f=sys.stdin n,r,l=map(int,f.readline().split()) appearance=[0]*n point=[0]*n top=0 pre_t=0 for line in f : d,t,x=map(int,line.split()) d-=1 appearance[top]+=t-pre_t pre_t=t point[d]+=x if 0collect( _x | (OclType["int"])->apply(_x) ) ; var appearance : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var point : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var top : int := 0 ; var pre_t : int := 0 ; for line : f do ( var d : OclAny := null; var t : OclAny := null; var x : OclAny := null; Sequence{d,t,x} := (line.split())->collect( _x | (OclType["int"])->apply(_x) ) ; d := d - 1 ; appearance[top+1] := appearance[top+1] + t - pre_t ; pre_t := t ; point[d+1] := point[d+1] + x ; if 0 < x & top /= d then ( if (point[top+1]->compareTo(point[d+1])) < 0 then ( top := d ) else (if point[top+1] = point[d+1] & (d->compareTo(top)) < 0 then ( top := d ) else skip) ) else (if x < 0 & top = d then ( top := point->indexOf((point)->max()) - 1 ) else skip)) ; appearance[top+1] := appearance[top+1] + l - pre_t ; execute (1 + appearance->indexOf((appearance)->max()) - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) def prime(n): if n==1 : return False for i in range(2,int(n**0.5)+1): if n % i==0 : return False return True if k==1 : print(n) else : a=[] for i in range(1,n//2+1): if prime(i): a.append(i) ans=[] flag=0 for i in range(len(a)): elem=a[i] while n % elem==0 : ans.append(elem) n//=elem if len(ans)==k : x=ans[-1] ans[-1]=x*n flag=1 break if flag : break if flag==0 : print(-1) else : print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; if k = 1 then ( execute (n)->display() ) else ( var a : Sequence := Sequence{} ; for i : Integer.subrange(1, n div 2 + 1-1) do ( if prime(i) then ( execute ((i) : a) ) else skip) ; var ans : Sequence := Sequence{} ; var flag : int := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( var elem : OclAny := a[i+1] ; while n mod elem = 0 do ( execute ((elem) : ans) ; n := n div elem ; if (ans)->size() = k then ( var x : OclAny := ans->last() ; ans->last() := x * n ; flag := 1 ; break ) else skip) ; if flag then ( break ) else skip) ; if flag = 0 then ( execute (-1)->display() ) else ( execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ) ); operation prime(n : OclAny) : OclAny pre: true post: true activity: if n = 1 then ( return false ) else skip ; for i : Integer.subrange(2, ("" + (((n)->pow(0.5))))->toInteger() + 1-1) do ( if n mod i = 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def k_factorization(n,k,mlpts): if k==1 : return mlpts+[n] for d in range(2,round(n**0.5)+1): if n % d==0 : mlpts.append(d) return k_factorization(n//d,k-1,mlpts) return[-1] n,k=map(int,input().split()) print(*k_factorization(n,k,[])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name k_factorization)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n))))))) , (argument (test (logical_test (comparison (expr (atom (name k))))))) , (argument (test (logical_test (comparison (expr (atom [ ]))))))) )))))))))->display(); operation k_factorization(n : OclAny, k : OclAny, mlpts : OclAny) : OclAny pre: true post: true activity: if k = 1 then ( return mlpts->union(Sequence{ n }) ) else skip ; for d : Integer.subrange(2, ((n)->pow(0.5))->round() + 1-1) do ( if n mod d = 0 then ( execute ((d) : mlpts) ; return k_factorization(n div d, k - 1, mlpts) ) else skip) ; return Sequence{ -1 }; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAXN=30 def countMaxLength(N): pre=[0 for i in range(MAXN)] p=1 pre[0]=0 for i in range(1,MAXN,1): p*=2 pre[i]=pre[i-1]+i*p for i in range(1,MAXN,1): if(pre[i]>=N): ind=i break x=N-pre[ind-1] y=2*ind-1 if(x>=y): res=min(x,y) else : res=max(x,2*(ind-2)+1) return res if __name__=='__main__' : N=25 print(countMaxLength(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAXN : int := 30 ; skip ; if __name__ = '__main__' then ( N := 25 ; execute (countMaxLength(N))->display() ) else skip; operation countMaxLength(N : OclAny) : OclAny pre: true post: true activity: var pre : Sequence := Integer.subrange(0, MAXN-1)->select(i | true)->collect(i | (0)) ; var p : int := 1 ; pre->first() := 0 ; for i : Integer.subrange(1, MAXN-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( p := p * 2 ; pre[i+1] := pre[i - 1+1] + i * p) ; for i : Integer.subrange(1, MAXN-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if ((pre[i+1]->compareTo(N)) >= 0) then ( var ind : OclAny := i ; break ) else skip) ; var x : double := N - pre[ind - 1+1] ; var y : double := 2 * ind - 1 ; if ((x->compareTo(y)) >= 0) then ( var res : OclAny := Set{x, y}->min() ) else ( res := Set{x, 2 * (ind - 2) + 1}->max() ) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) e=[] for i in range(n): listi=list(input()) f=sorted(listi) print(*f,sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var e : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var listi : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var f : Sequence := listi->sort() ; execute ((argument * (test (logical_test (comparison (expr (atom (name f))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[] for i in range(n): b=input() a=sorted(b) for i in range(len(b)): print(a[i],end="") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var b : String := (OclFile["System.in"]).readLine() ; var a : Sequence := b->sort() ; for i : Integer.subrange(0, (b)->size()-1) do ( execute (a[i+1])->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=input() k=0 a1,b1=sorted(a),sorted(b) if a1==b1 : for i in range(len(a)): if a[i]!=b[i]: k+=1 if k==2 : print("YES") else : print("NO") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var k : int := 0 ; var a1 : OclAny := null; var b1 : OclAny := null; Sequence{a1,b1} := Sequence{a->sort(),b->sort()} ; if a1 = b1 then ( for i : Integer.subrange(0, (a)->size()-1) do ( if a[i+1] /= b[i+1] then ( k := k + 1 ) else skip) ; if k = 2 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): st=input() b,b1=[],[] n1=0 for i in range(len(st)): if st[i]not in b : b.append(st[i]) for i in b : if st.count(i)>1 : n1=i*2 else : n1=i b1.append(n1) print(''.join(b1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var st : String := (OclFile["System.in"]).readLine() ; var b : OclAny := null; var b1 : OclAny := null; Sequence{b,b1} := Sequence{Sequence{},Sequence{}} ; var n1 : int := 0 ; for i : Integer.subrange(0, (st)->size()-1) do ( if (b)->excludes(st[i+1]) then ( execute ((st[i+1]) : b) ) else skip) ; for i : b do ( if st->count(i) > 1 then ( n1 := i * 2 ) else ( n1 := i ) ; execute ((n1) : b1)) ; execute (StringLib.sumStringsWithSeparator((b1), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): s=input() b=sorted(s) for i in b : print(i,end="") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var b : Sequence := s->sort() ; for i : b do ( execute (i)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): s=input() b=sorted(s) for i in b : print(i,end="") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var b : Sequence := s->sort() ; for i : b do ( execute (i)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reverse(x): rev=0 ; while(x>0): rev=(rev*10)+x % 10 ; x=int(x/10); return rev ; def printEmirp(n): prime=[1]*(n+1); p=2 ; while(p*p<=n): if(prime[p]==1): for i in range(p*2,n+1,p): prime[i]=0 ; p+=1 ; for p in range(2,n+1): if(prime[p]==1): rev=reverse(p); if(p!=rev and rev<=n and prime[rev]==1): print(p,rev,end=" "); prime[rev]=0 ; n=100 ; printEmirp(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 100; ; printEmirp(n);; operation reverse(x : OclAny) pre: true post: true activity: var rev : int := 0; ; while (x > 0) do ( rev := (rev * 10) + x mod 10; ; x := ("" + ((x / 10)))->toInteger();) ; return rev;; operation printEmirp(n : OclAny) pre: true post: true activity: var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)); ; var p : int := 2; ; while ((p * p->compareTo(n)) <= 0) do ( if (prime[p+1] = 1) then ( for i : Integer.subrange(p * 2, n + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := 0;) ) else skip ; p := p + 1;) ; for p : Integer.subrange(2, n + 1-1) do ( if (prime[p+1] = 1) then ( rev := reverse(p); ; if (p /= rev & (rev->compareTo(n)) <= 0 & prime[rev+1] = 1) then ( execute (p)->display(); ; prime[rev+1] := 0; ) else skip ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin from heapq import heappop,heappush input=stdin.readline pq=[] entry_finder={} REMOVED=float('inf') def add_team(score,team): if team in entry_finder : remove_team(team) entry=[-score,team] entry_finder[team]=entry heappush(pq,entry) def remove_team(team): entry=entry_finder.pop(team) entry[-1]=REMOVED def pop_team(): while pq : score,team=heappop(pq) if team is not REMOVED : del entry_finder[team] return score,team raise KeyError('pop from an empty priority queue') def main(args): N,R,L=map(int,input().split(' ')) on_tv=[0]*(N+1) scores=[0]*(N+1) add_team(0,1) last_time=0 need_pop=True top_score=0 for i in range(R): d,t,x=[int(x)for x in input().split(' ')] if need_pop : need_pop=False top_score,team=pop_team() if d!=team : add_team(scores[team],team) on_tv[team]+=(t-last_time) scores[d]+=x add_team(scores[d],d) if x>0 and scores[d]>top_score : need_pop=True last_time=t t=L score,team=pop_team() on_tv[team]+=(t-last_time) print(on_tv.index(max(on_tv))) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := stdin.readline ; var pq : Sequence := Sequence{} ; var entry_finder : OclAny := Set{} ; var REMOVED : double := ("" + (('inf')))->toReal() ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation add_team(score : OclAny, team : OclAny) pre: true post: true activity: if (entry_finder)->includes(team) then ( remove_team(team) ) else skip ; var entry : Sequence := Sequence{-score}->union(Sequence{ team }) ; entry_finder[team+1] := entry ; heappush(pq, entry); operation remove_team(team : OclAny) pre: true post: true activity: entry := entry_finder->at(team`firstArg+1) ; entry_finder := entry_finder->excludingAt(team+1) ; entry->last() := REMOVED; operation pop_team() : OclAny pre: true post: true activity: while pq do ( Sequence{score,team} := heappop(pq) ; if not(team <>= REMOVED) then ( execute (entry_finder[team+1])->isDeleted() ; return score, team ) else skip) ; error KeyError.newKeyError('pop from an empty priority queue'); operation main(args : OclAny) pre: true post: true activity: var N : OclAny := null; var R : OclAny := null; var L : OclAny := null; Sequence{N,R,L} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var on_tv : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; var scores : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; add_team(0, 1) ; var last_time : int := 0 ; var need_pop : boolean := true ; var top_score : int := 0 ; for i : Integer.subrange(0, R-1) do ( var d : OclAny := null; var t : OclAny := null; var x : OclAny := null; Sequence{d,t,x} := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if need_pop then ( need_pop := false ; Sequence{top_score,team} := pop_team() ; if d /= team then ( add_team(scores[team+1], team) ) else skip ) else skip ; on_tv[team+1] := on_tv[team+1] + (t - last_time) ; scores[d+1] := scores[d+1] + x ; add_team(scores[d+1], d) ; if x > 0 & (scores[d+1]->compareTo(top_score)) > 0 then ( need_pop := true ) else skip ; last_time := t) ; var t : OclAny := L ; Sequence{score,team} := pop_team() ; on_tv[team+1] := on_tv[team+1] + (t - last_time) ; execute (on_tv->indexOf((on_tv)->max()) - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math sys.setrecursionlimit(500000) INF=float('inf') def main(): s=input() if s[-1]!='s' : return s+'s' else : return s+'es' if __name__=='__main__' : print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit(500000) ; var INF : double := ("" + (('inf')))->toReal() ; skip ; if __name__ = '__main__' then ( execute (main())->display() ) else skip; operation main() : OclAny pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; if s->last() /= 's' then ( return s + 's' ) else ( return s + 'es' ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import base64 import subprocess import zlib exe_bin="c%1E9eQ+Da6<>Wgb`nQc5{D>BLqu?j1NdUaA8{Zql5II>;siIAgZW4nSvp(S$dZvx!46CtCXhiBLOo0eLZLGrm@;KL(}wA^!+$jxLdy)(&`u#!K9ZJ?N>IQp6w&}z-`?#?cdI+ThT$)7CVuyR_ukvLZ};}R@1B1Y?CrMOY=|`n`W_-&W3|TnDL&Ou6alOaErg#JqP1uN@J^i^PtVzmw5r&Trq^cIc%FU-8L3T2E0A@2q{c`Q@)q@oul}{vzqMWiJx%-dR~Yr|RBw>#4N`eV-BgcJHa;i)AEG!zIguG}7;kHBXl)kKNnx|&GKMlQRItgTjr@yKX0fzwJjrC^M3PiQBON-1eXPAgI>w6imwOh}>dP+ZdPncum-Uul*S(Rfd!U-9`Ov2Y42sj#f1dm_Q$Zory`!f82zlW8R-g-3frIMj%P{jFG4ZHmYVxY*UNw8_ad22rWGCm}0czTg4Cqw&52+-+Y=dLj|Qx5!EiT#w4h;1C(f_&6SuQt4zO9G8^|e4tS^?`y@ZV=O1qQcC&CZuafyZ^CgiA3HT4Vf>L~Mp3U)X*2u%VXhO|*vS^W8;ozkI5Ix&^Z7PwLLeh2Mtb_2aeoUA`EW2uCU7JIcgXzt5FSX}A}6AFx0KF|O5|pQO)Si5WIv9?_T%BO97kX(E_WxI|%cLi9THnqhXkp?VX*tNoYjddwV)M@n)g9c(qw*L7jtxfsP*R6Ph%5a1ex>h0Q(#yH(GTC1{78%Ax+W!wysd`;i@0BC^*zkapi*+}mvM?Hf)2RHS7FvMfey|$)7Di+pwANBt-dBDt{^A$x_HqtNePxlThVPsQhZelMv;nRDK!ZNoewuD!+*EBqaGmDsLw|aW_Av^5<)TCn3n+r1JkEJQ;evPvzeRet43NYoOm(fU&iS+1I1uQRjwwGS+NYUA=EQ*9hX`u}-&mtUY)Ej63_9_-w_xm0EzrXS?duK#N&t-N~*xH_DOz#iOA*2vl<&D9u7ohiJog*D-Rv`(>3in1PG1B%T(ho==(eZGSYf(zCsdX8zb^;=*owDR(h^edK3$dXAUc!2cYCrg>=U#95D&jG+ZXCRR&h}EV2MK|?GJ%eVZ{;9{gByz9GC&|SjA(+;MQ|u_Dy9KEUoL8YfEd%-on{op=RA3YMA%VkX2RULH}mWksqjLHqL>*_~e{J%+88W=B^TLC&d@$6b~4@h#IUW2CeKJYQG)Uj~dVRKP`i+0pd?J4EsEAx#vGC6mlXA;bg^iAZH`$hlt(>Gg`ce_}=_*fyFPs7&J=eCj-|8_Vi?53Je4wHXB~6QHS2}7SR4c_OqVsN4*>0RG+OUKXc^n{}cj#=evs6_cAlkn?2u~{irMZexOkM3e25N-1=(fZ88Bj>@@$u+n-4b%g)8m6lr=4uGNYdxEtBV-L^H=l~t3rN;kpD87&7kFVpQG=JE*DQTZo6DHKi+0hhbm<+-|M@hw${&{eCiytJuqJ<}&=BR}}A-`~ide+^D?_3H#%i-31N2u#4`K4K5JJck|Ku0H#37r8uu1YA{t#mEDDVvc$V>75D4^7T7vrp5DRg`D>+clJDIndRVvV1K&6SK4Pf9DEGLXXqKCOcP7(c~n{IkNA3EJt`d`%O0Xy_j#^G|+n}9j5dErAH{ekJ3je{T-zzDSc6&)cqQboT(?GiL2-Q>@yg=78}X{*dNJY)i|f*eFDkBIBfhx!92@a!)M$z?L1#^I7n(K2Yl{1V5qG0grufog{eTf)hU#5r_;NH^V}{oj_a7s^qPXuE@e54Xy#t@wZ+xQI^JqZab-5r6ESvVHXvz%K%veV1hKFPoFtDSxh4TGV6sEb!|cnxCwGi{<2l7V;0N^5y$g*sl4{$A8qq&T|%cyTiQRBjnKLm!C(6I`6B{q4h>Q?9lKse;nrh-b>@qN8>3`{9z0E8Haft%NYy#kE#7>YM;G+DxKzaENh+ScD6am+HxU3wZncd+v_yF(|ihHxm*(HjJ-QZ%fD5$?H0t<*{2Oj?S5aXF9QuP+)g)~V2Yvq0*5;Hn$i2|cPBtUoWc8B41!3#AP^x6?akH;fCsh_@SR!l{;h}VzU7Oci@!D$9QY4*Gm!xSOnBT7}Rr=f-H$yoUbVTc)be)g~u2{Ba>Po48ieC!5%7fhsi+4nc1^aeHOpEa>3hqpc<&54SAw4mwgol7CDUHV1m7D;RV@OCO6-j`=G$`Q_%8ev4!cazzM;qiQQn^?-9YaENA_4X^s-(0#2O!FFGGSma+)GLEFcG9zV{wIa36n!Eg^?s&z@q{`)nE##q`F54QjG3bv1qEqf%QlPOXCq~Ou>peexbDaXg1h2^cfzNBXFS_gr$T8*hWWTzcbs+zj`Bi0`dxC?9cbkqjg`PPrkQ*1ZQ)m&(430)>E9lH}$mwr0qgl?twDOB>`fy&2!5NRxM}NlYv)}(2{WCZJZX=5x;q=+>_l)xC1AhFEA>;GQ&NqzmX$fBcaZcar?+L8*f6wW&d;y~|Zo%{M{3EB&@(PSD=j8e4hnzo2S1fN=`uhZp=i|-K-#?L7Kg#skxwLPsxxc*r2dMOHkyiTq586K+*aA+E`E{I*iO-M5)|KvmUjLtR`o;4SCG0ul^;xsiglI8-RNq7O{oMNXbNZDwt$#kz$MiRHxLMxY?2j}=s(+j=VDcUkQ2G9`Q0Ke8oxMb(zvLDyzkZfl=pVgYqi#-t*Z)66!oec" open("./kyomu",'wb').write(zlib.decompress(base64.b85decode(exe_bin))) subprocess.run(["chmod+x./kyomu"],shell=True) subprocess.run(["./kyomu"],shell=True) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var exe_bin : String := "c%1E9eQ+Da6<>Wgb`nQc5{D>BLqu?j1NdUaA8{Zql5II>;siIAgZW4nSvp(S$dZvx!46CtCXhiBLOo0eLZLGrm@;KL(}wA^!+$jxLdy)(&`u#!K9ZJ?N>IQp6w&}z-`?#?cdI+ThT$)7CVuyR_ukvLZ};}R@1B1Y?CrMOY=|`n`W_-&W3|TnDL&Ou6alOaErg#JqP1uN@J^i^PtVzmw5r&Trq^cIc%FU-8L3T2E0A@2q{c`Q@)q@oul}{vzqMWiJx%-dR~Yr|RBw>#4N`eV-BgcJHa;i)AEG!zIguG}7;kHBXl)kKNnx|&GKMlQRItgTjr@yKX0fzwJjrC^M3PiQBON-1eXPAgI>w6imwOh}>dP+ZdPncum-Uul*S(Rfd!U-9`Ov2Y42sj#f1dm_Q$Zory`!f82zlW8R-g-3frIMj%P{jFG4ZHmYVxY*UNw8_ad22rWGCm}0czTg4Cqw&52+-+Y=dLj|Qx5!EiT#w4h;1C(f_&6SuQt4zO9G8^|e4tS^?`y@ZV=O1qQcC&CZuafyZ^CgiA3HT4Vf>L~Mp3U)X*2u%VXhO|*vS^W8;ozkI5Ix&^Z7PwLLeh2Mtb_2aeoUA`EW2uCU7JIcgXzt5FSX}A}6AFx0KF|O5|pQO)Si5WIv9?_T%BO97kX(E_WxI|%cLi9THnqhXkp?VX*tNoYjddwV)M@n)g9c(qw*L7jtxfsP*R6Ph%5a1ex>h0Q(#yH(GTC1{78%Ax+W!wysd`;i@0BC^*zkapi*+}mvM?Hf)2RHS7FvMfey|$)7Di+pwANBt-dBDt{^A$x_HqtNePxlThVPsQhZelMv;nRDK!ZNoewuD!+*EBqaGmDsLw|aW_Av^5<)TCn3n+r1JkEJQ;evPvzeRet43NYoOm(fU&iS+1I1uQRjwwGS+NYUA=EQ*9hX`u}-&mtUY)Ej63_9_-w_xm0EzrXS?duK#N&t-N~*xH_DOz#iOA*2vl<&D9u7ohiJog*D-Rv`(>3in1PG1B%T(ho==(eZGSYf(zCsdX8zb^;=*owDR(h^edK3$dXAUc!2cYCrg>=U#95D&jG+ZXCRR&h}EV2MK|?GJ%eVZ{;9{gByz9GC&|SjA(+;MQ|u_Dy9KEUoL8YfEd%-on{op=RA3YMA%VkX2RULH}mWksqjLHqL>*_~e{J%+88W=B^TLC&d@$6b~4@h#IUW2CeKJYQG)Uj~dVRKP`i+0pd?J4EsEAx#vGC6mlXA;bg^iAZH`$hlt(>Gg`ce_}= skip skip var exe_bin : String := "c%1E9eQ+Da6<>Wgb`nQc5{D>BLqu?j1NdUaA8{Zql5II>;siIAgZW4nSvp(S$dZvx!46CtCXhiBLOo0eLZLGrm@;KL(}wA^!+$jxLdy)(&`u#!K9ZJ?N>IQp6w&}z-`?#?cdI+ThT$)7CVuyR_ukvLZ};}R@1B1Y?CrMOY=|`n`W_-&W3|TnDL&Ou6alOaErg#JqP1uN@J^i^PtVzmw5r&Trq^cIc%FU-8L3T2E0A@2q{c`Q@)q@oul}{vzqMWiJx%-dR~Yr|RBw>#4N`eV-BgcJHa;i)AEG!zIguG}7;kHBXl)kKNnx|&GKMlQRItgTjr@yKX0fzwJjrC^M3PiQBON-1eXPAgI>w6imwOh}>dP+ZdPncum-Uul*S(Rfd!U-9`Ov2Y42sj#f1dm_Q$Zory`!f82zlW8R-g-3frIMj%P{jFG4ZHmYVxY*UNw8_ad22rWGCm}0czTg4Cqw&52+-+Y=dLj|Qx5!EiT#w4h;1C(f_&6SuQt4zO9G8^|e4tS^?`y@ZV=O1qQcC&CZuafyZ^CgiA3HT4Vf>L~Mp3U)X*2u%VXhO|*vS^W8;ozkI5Ix&^Z7PwLLeh2Mtb_2aeoUA`EW2uCU7JIcgXzt5FSX}A}6AFx0KF|O5|pQO)Si5WIv9?_T%BO97kX(E_WxI|%cLi9THnqhXkp?VX*tNoYjddwV)M@n)g9c(qw*L7jtxfsP*R6Ph%5a1ex>h0Q(#yH(GTC1{78%Ax+W!wysd`;i@0BC^*zkapi*+}mvM?Hf)2RHS7FvMfey|$)7Di+pwANBt-dBDt{^A$x_HqtNePxlThVPsQhZelMv;nRDK!ZNoewuD!+*EBqaGmDsLw|aW_Av^5<)TCn3n+r1JkEJQ;evPvzeRet43NYoOm(fU&iS+1I1uQRjwwGS+NYUA=EQ*9hX`u}-&mtUY)Ej63_9_-w_xm0EzrXS?duK#N&t-N~*xH_DOz#iOA*2vl<&D9u7ohiJog*D-Rv`(>3in1PG1B%T(ho==(eZGSYf(zCsdX8zb^;=*owDR(h^edK3$dXAUc!2cYCrg>=U#95D&jG+ZXCRR&h}EV2MK|?GJ%eVZ{;9{gByz9GC&|SjA(+;MQ|u_Dy9KEUoL8YfEd%-on{op=RA3YMA%VkX2RULH}mWksqjLHqL>*_~e{J%+88W=B^TLC&d@$6b~4@h#IUW2CeKJYQG)Uj~dVRKP`i+0pd?J4EsEAx#vGC6mlXA;bg^iAZH`$hlt(>Gg`ce_}=_*fyFPs7&J=eCj-|8_Vi?53Je4wHXB~6QHS2}7SR4c_OqVsN4*>0RG+OUKXc^n{}cj#=evs6_cAlkn?2u~{irMZexOkM3e25N-1=(fZ88Bj>@@$u+n-4b%g)8m6lr=4uGNYdxEtBV-L^H=l~t3rN;kpD87&7kFVpQG=JE*DQTZo6DHKi+0hhbm<+-|M@hw${&{eCiytJuqJ<}&=BR}}A-`~ide+^D?_3H#%i-31N2u#4`K4K5JJck|Ku0H#37r8uu1YA{t#mEDDVvc$V>75D4^7T7vrp5DRg`D>+clJDIndRVvV1K&6SK4Pf9DEGLXXqKCOcP7(c~n{IkNA3EJt`d`%O0Xy_j#^G|+n}9j5dErAH{ekJ3je{T-zzDSc6&)cqQboT(?GiL2-Q>@yg=78}X{*dNJY)i|f*eFDkBIBfhx!92@a!)M$z?L1#^I7n(K2Yl{1V5qG0grufog{eTf)hU#5r_;NH^V}{oj_a7s^qPXuE@e54Xy#t@wZ+xQI^JqZab-5r6ESvVHXvz%K%veV1hKFPoFtDSxh4TGV6sEb!|cnxCwGi{<2l7V;0N^5y$g*sl4{$A8qq&T|%cyTiQRBjnKLm!C(6I`6B{q4h>Q?9lKse;nrh-b>@qN8>3`{9z0E8Haft%NYy#kE#7>YM;G+DxKzaENh+ScD6am+HxU3wZncd+v_yF(|ihHxm*(HjJ-QZ%fD5$?H0t<*{2Oj?S5aXF9QuP+)g)~V2Yvq0*5;Hn$i2|cPBtUoWc8B41!3#AP^x6?akH;fCsh_@SR!l{;h}VzU7Oci@!D$9QY4*Gm!xSOnBT7}Rr=f-H$yoUbVTc)be)g~u2{Ba>Po48ieC!5%7fhsi+4nc1^aeHOpEa>3hqpc<&54SAw4mwgol7CDUHV1m7D;RV@OCO6-j`=G$`Q_%8ev4!cazzM;qiQQn^?-9YaENA_4X^s-(0#2O!FFGGSma+)GLEFcG9zV{wIa36n!Eg^?s&z@q{`)nE##q`F54QjG3bv1qEqf%QlPOXCq~Ou>peexbDaXg1h2^cfzNBXFS_gr$T8*hWWTzcbs+zj`Bi0`dxC?9cbkqjg`PPrkQ*1ZQ)m&(430)>E9lH}$mwr0qgl?twDOB>`fy&2!5NRxM}NlYv)}(2{WCZJZX=5x;q=+>_l)xC1AhFEA>;GQ&NqzmX$fBcaZcar?+L8*f6wW&d;y~|Zo%{M{3EB&@(PSD=j8e4hnzo2S1fN=`uhZp=i|-K-#?L7Kg#skxwLPsxxc*r2dMOHkyiTq586K+*aA+E`E{I*iO-M5)|KvmUjLtR`o;4SCG0ul^;xsiglI8-RNq7O{oMNXbNZDwt$#kz$MiRHxLMxY?2j}=s(+j=VDcUkQ2G9`Q0Ke8oxMb(zvLDyzkZfl=pVgYqi#-t*Z)66!oec"(expr (atom (name open)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "./kyomu")))))) , (argument (test (logical_test (comparison (expr (atom 'wb'))))))) ))) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name zlib)) (trailer . (name decompress) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name base64)) (trailer . (name b85decode) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name exe_bin)))))))) ))))))))) ))))))))) )))) subprocess(OclProcess.newOclProcess((arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom "chmod+x./kyomu")))))) ])))))) , (argument (test (logical_test (comparison (expr (atom (name shell)))))) = (test (logical_test (comparison (expr (atom (name True)))))))), "")).start() subprocess(OclProcess.newOclProcess((arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom "./kyomu")))))) ])))))) , (argument (test (logical_test (comparison (expr (atom (name shell)))))) = (test (logical_test (comparison (expr (atom (name True)))))))), "")).start()fyFPs7&J=eCj-|8_Vi?53Je4wHXB~6QHS2}7SR4c_OqVsN4*>0RG+OUKXc^n{}cj#=evs6_cAlkn?2u~{irMZexOkM3e25N-1=(fZ88Bj>@@$u+n-4b%g)8m6lr=4uGNYdxEtBV-L^H=l~t3rN;kpD87&7kFVpQG=JE*DQTZo6DHKi+0hhbm<+-|M@hw${&{eCiytJuqJ<}&=BR}}A-`~ide+^D?_3H#%i-31N2u#4`K4K5JJck|Ku0H#37r8uu1YA{t#mEDDVvc$V>75D4^7T7vrp5DRg`D>+clJDIndRVvV1K&6SK4Pf9DEGLXXqKCOcP7(c~n{IkNA3EJt`d`%O0Xy_j#^G|+n}9j5dErAH{ekJ3je{T-zzDSc6&)cqQboT(?GiL2-Q>@yg=78}X{*dNJY)i|f*eFDkBIBfhx!92@a!)M$z?L1#^I7n(K2Yl{1V5qG0grufog{eTf)hU#5r_;NH^V}{oj_a7s^qPXuE@e54Xy#t@wZ+xQI^JqZab-5r6ESvVHXvz%K%veV1hKFPoFtDSxh4TGV6sEb!|cnxCwGi{<2l7V;0N^5y$g*sl4{$A8qq&T|%cyTiQRBjnKLm!C(6I`6B{q4h>Q?9lKse;nrh-b>@qN8>3`{9z0E8Haft%NYy#kE#7>YM;G+DxKzaENh+ScD6am+HxU3wZncd+v_yF(|ihHxm*(HjJ-QZ%fD5$?H0t<*{2Oj?S5aXF9QuP+)g)~V2Yvq0*5;Hn$i2|cPBtUoWc8B41!3#AP^x6?akH;fCsh_@SR!l{;h}VzU7Oci@!D$9QY4*Gm!xSOnBT7}Rr=f-H$yoUbVTc)be)g~u2{Ba>Po48ieC!5%7fhsi+4nc1^aeHOpEa>3hqpc<&54SAw4mwgol7CDUHV1m7D;RV@OCO6-j`=G$`Q_%8ev4!cazzM;qiQQn^?-9YaENA_4X^s-(0#2O!FFGGSma+)GLEFcG9zV{wIa36n!Eg^?s&z@q{`)nE##q`F54QjG3bv1qEqf%QlPOXCq~Ou>peexbDaXg1h2^cfzNBXFS_gr$T8*hWWTzcbs+zj`Bi0`dxC?9cbkqjg`PPrkQ*1ZQ)m&(430)>E9lH}$mwr0qgl?twDOB>`fy&2!5NRxM}NlYv)}(2{WCZJZX=5x;q=+>_l)xC1AhFEA>;GQ&NqzmX$fBcaZcar?+L8*f6wW&d;y~|Zo%{M{3EB&@(PSD=j8e4hnzo2S1fN=`uhZp=i|-K-#?L7Kg#skxwLPsxxc*r2dMOHkyiTq586K+*aA+E`E{I*iO-M5)|KvmUjLtR`o;4SCG0ul^;xsiglI8-RNq7O{oMNXbNZDwt$#kz$MiRHxLMxY?2j}=s(+j=VDcUkQ2G9`Q0Ke8oxMb(zvLDyzkZfl=pVgYqi#-t*Z)66!oec" ; (expr (atom (name open)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "./kyomu")))))) , (argument (test (logical_test (comparison (expr (atom 'wb'))))))) ))) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name zlib)) (trailer . (name decompress) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name base64)) (trailer . (name b85decode) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name exe_bin)))))))) ))))))))) ))))))))) )))) ; subprocess(OclProcess.newOclProcess((arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom "chmod+x./kyomu")))))) ])))))) , (argument (test (logical_test (comparison (expr (atom (name shell)))))) = (test (logical_test (comparison (expr (atom (name True)))))))), "")).start() ; subprocess(OclProcess.newOclProcess((arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom "./kyomu")))))) ])))))) , (argument (test (logical_test (comparison (expr (atom (name shell)))))) = (test (logical_test (comparison (expr (atom (name True)))))))), "")).start(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input().strip() if s[-1]=="s" : print(s+"es") else : print(s+"s") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := input()->trim() ; if s->last() = "s" then ( execute (s + "es")->display() ) else ( execute (s + "s")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() print(S+("es" if S.endswith("s")else "s")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; execute (S + (if S->hasSuffix("s") then "es" else "s" endif))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**9) def mi(): return map(int,input().split()) def ii(): return int(input()) def isp(): return input().split() def deb(text): print("-------\n{}\n-------".format(text)) INF=10**20 def main(): S=input() if S[-1]!="s" : print(S+"s") else : print(S+"es") if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(9)) ; skip ; skip ; skip ; skip ; var INF : double := (10)->pow(20) ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation mi() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation ii() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation isp() : OclAny pre: true post: true activity: return input().split(); operation deb(text : OclAny) pre: true post: true activity: execute (StringLib.interpolateStrings("-------\n{}\n-------", Sequence{text}))->display(); operation main() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; if S->last() /= "s" then ( execute (S + "s")->display() ) else ( execute (S + "es")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxIndexDiff(arr,n): LMin=[None]*n RMax=[None]*n LMin[0]=arr[0] for i in range(1,n): LMin[i]=min(arr[i],LMin[i-1]) RMax[n-1]=arr[n-1] for j in range(n-2,-1,-1): RMax[j]=max(arr[j],RMax[j+1]) i=0 j=0 maxDiff=-1 while(junion(Sequence{1}->union(Sequence{2}->union(Sequence{-1}->union(Sequence{-1}->union(Sequence{ 1 }))))) ; x := 1 ; n := (arr)->size() ; execute (longestsubarray(arr, n, x))->display() ) else skip; operation maxIndexDiff(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var LMin : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; var RMax : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; LMin->first() := arr->first() ; for i : Integer.subrange(1, n-1) do ( LMin[i+1] := Set{arr[i+1], LMin[i - 1+1]}->min()) ; RMax[n - 1+1] := arr[n - 1+1] ; for j : Integer.subrange(-1 + 1, n - 2)->reverse() do ( RMax[j+1] := Set{arr[j+1], RMax[j + 1+1]}->max()) ; var i : int := 0 ; var j : int := 0 ; var maxDiff : int := -1 ; while ((j->compareTo(n)) < 0 & (i->compareTo(n)) < 0) do ( if ((LMin[i+1]->compareTo(RMax[j+1])) < 0) then ( maxDiff := Set{maxDiff, j - i}->max() ; j := j + 1 ) else ( i := i + 1 )) ; return maxDiff + 1; operation modifyarr(arr : OclAny, n : OclAny, x : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( arr[i+1] := arr[i+1] - x); operation calcprefix(arr : OclAny, n : OclAny) pre: true post: true activity: var s : int := 0 ; for i : Integer.subrange(0, n-1) do ( s := s + arr[i+1] ; arr[i+1] := s); operation longestsubarray(arr : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: modifyarr(arr, n, x) ; calcprefix(arr, n) ; return maxIndexDiff(arr, n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): s1=input() s2=input() if len(s1)!=len(s2): print('NO') return cnt1,cnt2={},{} for i in range(len(s1)): if s1[i]not in cnt1 : cnt1[s1[i]]=0 if s2[i]not in cnt2 : cnt2[s2[i]]=0 cnt1[s1[i]]+=1 cnt2[s2[i]]+=1 for key,val in cnt1.items(): val2=cnt2.get(key,0) if val!=val2 : print('NO') return d=0 for i in range(len(s1)): if s1[i]!=s2[i]: d+=1 if d>2 : print('NO') return print('YES') if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var s1 : String := (OclFile["System.in"]).readLine() ; var s2 : String := (OclFile["System.in"]).readLine() ; if (s1)->size() /= (s2)->size() then ( execute ('NO')->display() ; return ) else skip ; var cnt1 : OclAny := null; var cnt2 : OclAny := null; Sequence{cnt1,cnt2} := Sequence{Set{},Set{}} ; for i : Integer.subrange(0, (s1)->size()-1) do ( if (cnt1)->excludes(s1[i+1]) then ( cnt1[s1[i+1]+1] := 0 ) else skip ; if (cnt2)->excludes(s2[i+1]) then ( cnt2[s2[i+1]+1] := 0 ) else skip ; cnt1[s1[i+1]+1] := cnt1[s1[i+1]+1] + 1 ; cnt2[s2[i+1]+1] := cnt2[s2[i+1]+1] + 1) ; for _tuple : cnt1->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var val : OclAny := _tuple->at(_indx); var val2 : OclAny := cnt2.get(key, 0) ; if val /= val2 then ( execute ('NO')->display() ; return ) else skip) ; var d : int := 0 ; for i : Integer.subrange(0, (s1)->size()-1) do ( if s1[i+1] /= s2[i+1] then ( d := d + 1 ) else skip) ; if d > 2 then ( execute ('NO')->display() ; return ) else skip ; execute ('YES')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def swap(s): k=s[0] l=list(s[:]) for i in range(1,len(s)): l[i-1]=s[i] l[-1]=k return ''.join(l) n=int(input()) a=[input()for i in range(n)] ans=2500 for i in range(len(a[0])): cnt=i for j in range(1,n): s=a[j][:] while s!=a[0]: s=swap(s) cnt+=1 if cnt>2500 : print(-1) exit() a[0]=swap(a[0]) ans=min(ans,cnt) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var ans : int := 2500 ; for i : Integer.subrange(0, (a->first())->size()-1) do ( var cnt : OclAny := i ; for j : Integer.subrange(1, n-1) do ( s := a[j+1] ; while s /= a->first() do ( s := swap(s) ; cnt := cnt + 1 ; if cnt > 2500 then ( execute (-1)->display() ; exit() ) else skip)) ; a->first() := swap(a->first()) ; ans := Set{ans, cnt}->min()) ; execute (ans)->display(); operation swap(s : OclAny) : OclAny pre: true post: true activity: var k : OclAny := s->first() ; var l : Sequence := (s) ; for i : Integer.subrange(1, (s)->size()-1) do ( l[i - 1+1] := s[i+1]) ; l->last() := k ; return StringLib.sumStringsWithSeparator((l), ''); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[] for i in range(n): s=str(input()) l.append(s) ans=[] for k in range(n): res=0 for i in l : t=2*i if l[k]not in t : print(-1) exit(0) else : res+=t.index(l[k]) ans.append(res) print(min(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; execute ((s) : l)) ; var ans : Sequence := Sequence{} ; for k : Integer.subrange(0, n-1) do ( var res : int := 0 ; for i : l do ( var t : double := 2 * i ; if (t)->excludes(l[k+1]) then ( execute (-1)->display() ; exit(0) ) else ( res := res + t->indexOf(l[k+1]) - 1 )) ; execute ((res) : ans)) ; execute ((ans)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from asyncio import shield n=int(input()) s_list=[] for i in range(n): s_list.append(input()) result=1e9 for i in range(len(s_list[0])): goal=s_list[0]if(i==0)else s_list[0][i :]+s_list[0][0 : i] shift=i invalid=False for j in range(1,n): success=False for k in range(len(s_list[0])): curr_shift=s_list[j]if(k==0)else s_list[j][k :]+s_list[j][0 : k] if(curr_shift==goal): success=True shift+=k break if(not(success)): invalid=True break if(not(invalid)): result=min(result,shift) if(result==1e9): print(-1) else : print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s_list : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : s_list)) ; var result : double := ("1e9")->toReal() ; for i : Integer.subrange(0, (s_list->first())->size()-1) do ( var goal : OclAny := if (i = 0) then s_list->first() else s_list->first().subrange(i+1) + s_list->first().subrange(0+1, i) endif ; var shift : OclAny := i ; var invalid : boolean := false ; for j : Integer.subrange(1, n-1) do ( var success : boolean := false ; for k : Integer.subrange(0, (s_list->first())->size()-1) do ( var curr_shift : OclAny := if (k = 0) then s_list[j+1] else s_list[j+1].subrange(k+1) + s_list[j+1].subrange(0+1, k) endif ; if (curr_shift = goal) then ( success := true ; shift := shift + k ; break ) else skip) ; if (not((success))) then ( invalid := true ; break ) else skip) ; if (not((invalid))) then ( result := Set{result, shift}->min() ) else skip) ; if (result = ("1e9")->toReal()) then ( execute (-1)->display() ) else ( execute (result)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from heapq import* N,R,L=map(int,input().split()) score=[0]*N pq=[] for i in range(N): heappush(pq,(-score[i],i)) prev_t=0 now=0 time=[0]*N for _ in range(R): di,ti,xi=map(int,input().split()) time[now]+=ti-prev_t prev_t=ti heappush(pq,(-score[now],now)) heappush(pq,(-score[di-1]-xi,di-1)) score[di-1]+=xi while True : s,idx=heappop(pq) s*=-1 if score[idx]==s : break now=idx time[now]+=L-prev_t max_t=0 ans=-1 for i in range(N): if time[i]>max_t : max_t=time[i] ans=i+1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var N : OclAny := null; var R : OclAny := null; var L : OclAny := null; Sequence{N,R,L} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var score : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var pq : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( heappush(pq, Sequence{-score[i+1], i})) ; var prev_t : int := 0 ; var now : int := 0 ; var time : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for _anon : Integer.subrange(0, R-1) do ( var di : OclAny := null; var ti : OclAny := null; var xi : OclAny := null; Sequence{di,ti,xi} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; time[now+1] := time[now+1] + ti - prev_t ; prev_t := ti ; heappush(pq, Sequence{-score[now+1], now}) ; heappush(pq, Sequence{-score[di - 1+1] - xi, di - 1}) ; score[di - 1+1] := score[di - 1+1] + xi ; while true do ( var s : OclAny := null; var idx : OclAny := null; Sequence{s,idx} := heappop(pq) ; s := s * -1 ; if score[idx+1] = s then ( break ) else skip) ; now := idx) ; time[now+1] := time[now+1] + L - prev_t ; var max_t : int := 0 ; var ans : int := -1 ; for i : Integer.subrange(0, N-1) do ( if (time[i+1]->compareTo(max_t)) > 0 then ( max_t := time[i+1] ; ans := i + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().rstrip("\n") n=int(input()) s=['' for _ in range(n)] t=['' for _ in range(n)] for i in range(n): s[i]=input() t[i]=s[i]+s[i] m=len(s[0]) ans=2*n*m for i in range(m): sums=i for j in range(1,n): if t[j].find(t[0][i : i+m])!=-1 : sums+=t[j].find(t[0][i : i+m]) else : print(-1) exit() ans=min(ans,sums) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip("\n")) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ('')) ; var t : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ('')) ; for i : Integer.subrange(0, n-1) do ( s[i+1] := (OclFile["System.in"]).readLine() ; t[i+1] := s[i+1] + s[i+1]) ; var m : int := (s->first())->size() ; var ans : int := 2 * n * m ; for i : Integer.subrange(0, m-1) do ( var sums : OclAny := i ; for j : Integer.subrange(1, n-1) do ( if t[j+1]->indexOf(t->first().subrange(i+1, i + m)) - 1 /= -1 then ( sums := sums + t[j+1]->indexOf(t->first().subrange(i+1, i + m)) - 1 ) else ( execute (-1)->display() ; exit() )) ; ans := Set{ans, sums}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def swap(s): k=s[0] l=list(s[:]) for i in range(1,len(s)): l[i-1]=s[i] l[-1]=k return ''.join(l) n=int(input()) a=[input()for i in range(n)] ans=1e5 for i in range(len(a[0])): cnt=i for j in range(1,n): s=a[j][:] while s!=a[0]: s=swap(s) cnt+=1 if cnt>1e5 : print(-1) exit() a[0]=swap(a[0]) ans=min(ans,cnt) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var ans : double := ("1e5")->toReal() ; for i : Integer.subrange(0, (a->first())->size()-1) do ( var cnt : OclAny := i ; for j : Integer.subrange(1, n-1) do ( s := a[j+1] ; while s /= a->first() do ( s := swap(s) ; cnt := cnt + 1 ; if cnt > ("1e5")->toReal() then ( execute (-1)->display() ; exit() ) else skip)) ; a->first() := swap(a->first()) ; ans := Set{ans, cnt}->min()) ; execute (ans)->display(); operation swap(s : OclAny) : OclAny pre: true post: true activity: var k : OclAny := s->first() ; var l : Sequence := (s) ; for i : Integer.subrange(1, (s)->size()-1) do ( l[i - 1+1] := s[i+1]) ; l->last() := k ; return StringLib.sumStringsWithSeparator((l), ''); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def area_of_circle(m,n): square_of_radius=(m*n)/4 area=(3.141*square_of_radius) return area if __name__=='__main__' : n=10 m=30 print(area_of_circle(m,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 10 ; m := 30 ; execute (area_of_circle(m, n))->display() ) else skip; operation area_of_circle(m : OclAny, n : OclAny) : OclAny pre: true post: true activity: var square_of_radius : double := (m * n) / 4 ; var area : double := (3.141 * square_of_radius) ; return area; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) print(a-b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (a - b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,collections as cl,bisect as bs sys.setrecursionlimit(100000) Max=sys.maxsize def l(): return list(map(int,input().split())) def m(): return map(int,input().split()) def onem(): return int(input()) def s(x): a=[] aa=x[0] su=1 for i in range(len(x)-1): if aa==x[i+1]: a.append([aa,su]) aa=x[i+1] su=1 else : su+=1 a.append([aa,su]) return a def jo(x): return " ".join(map(str,x)) def max2(x): return max(map(max,x)) n,m=m() print(n-m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(100000) ; var Max : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; skip ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := m() ; execute (n - m)->display(); operation l() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation m() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation onem() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation s(x : OclAny) : OclAny pre: true post: true activity: var a : Sequence := Sequence{} ; var aa : OclAny := x->first() ; var su : int := 1 ; for i : Integer.subrange(0, (x)->size() - 1-1) do ( if aa = x[i + 1+1] then ( execute ((Sequence{aa}->union(Sequence{ su })) : a) ; aa := x[i + 1+1] ; su := 1 ) else ( su := su + 1 )) ; execute ((Sequence{aa}->union(Sequence{ su })) : a) ; return a; operation jo(x : OclAny) : OclAny pre: true post: true activity: return StringLib.sumStringsWithSeparator(((x)->collect( _x | (OclType["String"])->apply(_x) )), " "); operation max2(x : OclAny) : OclAny pre: true post: true activity: return ((x)->collect( _x | (max)->apply(_x) ))->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(eval(input().replace(" ","-"))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (input().replace(" ", "-"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import sys def main(): a,b=map(int,input().split()) print(a-b) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (a - b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countDecreasing(A,n): cnt=0 len=1 for i in range(n-1): if(A[i+1]1): cnt+=(((len-1)*len)//2) return cnt if __name__=="__main__" : A=[100,3,1,13] n=len(A) print(countDecreasing(A,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( A := Sequence{100}->union(Sequence{3}->union(Sequence{1}->union(Sequence{ 13 }))) ; n := (A)->size() ; execute (countDecreasing(A, n))->display() ) else skip; operation countDecreasing(A : OclAny, n : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; var len : int := 1 ; for i : Integer.subrange(0, n - 1-1) do ( if ((A[i + 1+1]->compareTo(A[i+1])) < 0) then ( len := len + 1 ) else ( cnt := cnt + (((len - 1) * len) div 2); ; len := 1 )) ; if (len > 1) then ( cnt := cnt + (((len - 1) * len) div 2) ) else skip ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from decimal import* a,b=input().rstrip().split(' ') getcontext().prec=100001 print(Decimal(a)-Decimal(b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().rstrip().split(' ') ; getcontext().prec := 100001 ; execute (Decimal(a) - Decimal(b))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def powerNumbers(n): v=[] for i in range(2,int(math.pow(n,1.0/3.0))+1): j=i*i while(j*i<=n): j=j*i s=int(math.sqrt(j)) if(s*s!=j): v.append(j) v.sort() v=list(dict.fromkeys(v)) return len(v)+int(math.sqrt(n)) if __name__=='__main__' : print(powerNumbers(50)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( execute (powerNumbers(50))->display() ) else skip; operation powerNumbers(n : OclAny) : OclAny pre: true post: true activity: var v : Sequence := Sequence{} ; for i : Integer.subrange(2, ("" + (((n)->pow(1.0 / 3.0))))->toInteger() + 1-1) do ( var j : double := i * i ; while ((j * i->compareTo(n)) <= 0) do ( j := j * i ; var s : int := ("" + (((j)->sqrt())))->toInteger() ; if (s * s /= j) then ( execute ((j) : v) ) else skip)) ; v := v->sort() ; v := ((trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) ))))->keys()->asSequence() ; return (v)->size() + ("" + (((n)->sqrt())))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from heapq import heappush,heappop,heapreplace def solve(): file_input=sys.stdin N,R,L=map(int,file_input.readline().split()) pq=[[0,i,0]for i in range(1,N+1)] m=dict(zip(range(1,N+1),pq)) pre_t=0 for line in file_input : d,t,x=map(int,line.split()) team=pq[0] team[2]+=t-pre_t pre_t=t if team[1]==d : team[0]-=x if x<0 : heapreplace(pq,team) else : scored_team=m[d][:] scored_team[0]-=x heappush(pq,scored_team) m[d][2]=-1 m[d]=scored_team while pq[0][2]==-1 : heappop(pq) pq[0][2]+=L-pre_t ans_team=max(pq,key=lambda x :(x[2],-x[1])) print(ans_team[1]) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; solve(); operation solve() pre: true post: true activity: var file_input : OclFile := OclFile["System.in"] ; var N : OclAny := null; var R : OclAny := null; var L : OclAny := null; Sequence{N,R,L} := (file_input.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var pq : Sequence := Integer.subrange(1, N + 1-1)->select(i | true)->collect(i | (Sequence{0}->union(Sequence{i}->union(Sequence{ 0 })))) ; var m : Map := ((expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name N))) + (expr (atom (number (integer 1)))))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name pq)))))))) ))))) ; var pre_t : int := 0 ; for line : file_input do ( var d : OclAny := null; var t : OclAny := null; var x : OclAny := null; Sequence{d,t,x} := (line.split())->collect( _x | (OclType["int"])->apply(_x) ) ; var team : OclAny := pq->first() ; team[2+1] := team[2+1] + t - pre_t ; pre_t := t ; if team[1+1] = d then ( team->first() := team->first() - x ; if x < 0 then ( heapreplace(pq, team) ) else skip ) else ( var scored_team : OclAny := m[d+1] ; scored_team->first() := scored_team->first() - x ; heappush(pq, scored_team) ; m[d+1][2+1] := -1 ; m[d+1] := scored_team ) ; while pq->first()[2+1] = -1 do ( heappop(pq))) ; pq->first()[2+1] := pq->first()[2+1] + L - pre_t ; var ans_team : OclAny := Set{pq, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))) , (test (logical_test (comparison (expr - (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ))))))))}->max() ; execute (ans_team[1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=3 def dotProduct(vect_A,vect_B): product=0 for i in range(0,n): product=product+vect_A[i]*vect_B[i] return product def crossProduct(vect_A,vect_B,cross_P): cross_P.append(vect_A[1]*vect_B[2]-vect_A[2]*vect_B[1]) cross_P.append(vect_A[2]*vect_B[0]-vect_A[0]*vect_B[2]) cross_P.append(vect_A[0]*vect_B[1]-vect_A[1]*vect_B[0]) if __name__=='__main__' : vect_A=[3,-5,4] vect_B=[2,6,5] cross_P=[] print("Dot product:",end=" ") print(dotProduct(vect_A,vect_B)) print("Cross product:",end=" ") crossProduct(vect_A,vect_B,cross_P) for i in range(0,n): print(cross_P[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := 3 ; skip ; skip ; if __name__ = '__main__' then ( vect_A := Sequence{3}->union(Sequence{-5}->union(Sequence{ 4 })) ; vect_B := Sequence{2}->union(Sequence{6}->union(Sequence{ 5 })) ; cross_P := Sequence{} ; execute ("Dot product:")->display() ; execute (dotProduct(vect_A, vect_B))->display() ; execute ("Cross product:")->display() ; crossProduct(vect_A, vect_B, cross_P) ; for i : Integer.subrange(0, n-1) do ( execute (cross_P[i+1])->display()) ) else skip; operation dotProduct(vect_A : OclAny, vect_B : OclAny) : OclAny pre: true post: true activity: var product : int := 0 ; for i : Integer.subrange(0, n-1) do ( product := product + vect_A[i+1] * vect_B[i+1]) ; return product; operation crossProduct(vect_A : OclAny, vect_B : OclAny, cross_P : OclAny) pre: true post: true activity: execute ((vect_A[1+1] * vect_B[2+1] - vect_A[2+1] * vect_B[1+1]) : cross_P) ; execute ((vect_A[2+1] * vect_B->first() - vect_A->first() * vect_B[2+1]) : cross_P) ; execute ((vect_A->first() * vect_B[1+1] - vect_A[1+1] * vect_B->first()) : cross_P); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def answer(X,K): MIN=pow(10,K-1) if(MIN % X==0): return(MIN) else : return((MIN+X)-((MIN+X)% X)) X=83 ; K=5 ; print(answer(X,K)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; X := 83; ; K := 5; ; execute (answer(X, K))->display();; operation answer(X : OclAny, K : OclAny) : OclAny pre: true post: true activity: var MIN : double := (10)->pow(K - 1) ; if (MIN mod X = 0) then ( return (MIN) ) else ( return ((MIN + X) - ((MIN + X) mod X)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- exec(int(input())*"print(input().strip('0').count('0'));") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) )))) * (expr (atom "print(input().strip('0').count('0'));"))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): print(input().strip('0').count('0')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (input()->trim()->count('0'))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(s): all=s.count('0') first=0 for i in range(len(s)): if s[i]=='0' : first+=1 else : break end=0 for i in range(len(s)-1,-1,-1): if s[i]=='0' : end+=1 else : break if all==len(s): return 0 return all-first-end t=int(input()) for i in range(t): s=input() print(solve(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( s := (OclFile["System.in"]).readLine() ; execute (solve(s))->display()); operation solve(s : OclAny) : OclAny pre: true post: true activity: var all : int := s->count('0') ; var first : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = '0' then ( first := first + 1 ) else ( break )) ; var end : int := 0 ; for i : Integer.subrange(-1 + 1, (s)->size() - 1)->reverse() do ( if s[i+1] = '0' then ( end := end + 1 ) else ( break )) ; if all = (s)->size() then ( return 0 ) else skip ; return all - first - end; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ZeroErase(s): strip=s.strip('0') n=len(strip) count=0 for i in range(0,n): if strip[i]=='0' : count+=1 return count t=int(input()) for i in range(0,t): inp=input() print(ZeroErase(inp)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var inp : String := (OclFile["System.in"]).readLine() ; execute (ZeroErase(inp))->display()); operation ZeroErase(s : OclAny) : OclAny pre: true post: true activity: var strip : String := s->trim() ; var n : int := (strip)->size() ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( if strip[i+1] = '0' then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): print(input().strip("0").count("0")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (input()->trim()->count("0"))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxDistance(n,fuel): dist_covered=0 while(n>0): dist_covered=dist_covered+(fuel/n) n=n-1 return dist_covered if __name__=='__main__' : n=3 fuel=100 print("Maximum distance possible with",n,"bikes is",maxDistance(n,fuel)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 3 ; fuel := 100 ; execute ("Maximum distance possible with")->display() ) else skip; operation maxDistance(n : OclAny, fuel : OclAny) : OclAny pre: true post: true activity: var dist_covered : int := 0 ; while (n > 0) do ( dist_covered := dist_covered + (fuel / n) ; n := n - 1) ; return dist_covered; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,asin,degrees,cos,radians f,e,d,c,b,a=[int(x)for x in input().split()] x=sqrt(a*a+b*b+a*b) A1=a*b angleX=degrees(asin(b*sqrt(3)/(2*x))) y=sqrt(e*e+f*f+e*f) A2=e*f angleY=degrees(asin(e*sqrt(3)/(2*y))) angleXY=120-angleX-angleY s=(x+y+c+d)/2 v=cos(radians((angleXY+120)/2)) A3=sqrt((s-x)*(s-y)*(s-c)*(s-d)-x*y*c*d*v*v) print(round(A1+A2+A3*4/sqrt(3))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var f : OclAny := null; var e : OclAny := null; var d : OclAny := null; var c : OclAny := null; var b : OclAny := null; var a : OclAny := null; Sequence{f,e,d,c,b,a} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var x : OclAny := sqrt(a * a + b * b + a * b) ; var A1 : double := a * b ; var angleX : OclAny := degrees(asin(b * sqrt(3) / (2 * x))) ; var y : OclAny := sqrt(e * e + f * f + e * f) ; var A2 : double := e * f ; var angleY : OclAny := degrees(asin(e * sqrt(3) / (2 * y))) ; var angleXY : double := 120 - angleX - angleY ; var s : double := (x + y + c + d) / 2 ; var v : OclAny := cos(radians((angleXY + 120) / 2)) ; var A3 : OclAny := sqrt((s - x) * (s - y) * (s - c) * (s - d) - x * y * c * d * v * v) ; execute ((A1 + A2 + A3 * 4 / sqrt(3))->round())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): x,y,z=map(int,input().split()) print(z-(z-y)% x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (z - (z - y) mod x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from heapq import heappush,heappop def solve(): file_input=sys.stdin N,R,L=map(int,file_input.readline().split()) hq=[] m={} for i in range(1,N+1): team=[0,i,0] heappush(hq,team) m[i]=team time=0 for line in file_input : d,t,x=map(int,line.split()) hq[0][2]+=t-time time=t scored_team=m[d][:] scored_team[0]-=x heappush(hq,scored_team) m[d][2]=-1 m[d]=scored_team while hq[0][2]==-1 : heappop(hq) hq[0][2]+=L-time ans_team=max(hq,key=lambda x :(x[2],-x[1])) print(ans_team[1]) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; solve(); operation solve() pre: true post: true activity: var file_input : OclFile := OclFile["System.in"] ; var N : OclAny := null; var R : OclAny := null; var L : OclAny := null; Sequence{N,R,L} := (file_input.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var hq : Sequence := Sequence{} ; var m : OclAny := Set{} ; for i : Integer.subrange(1, N + 1-1) do ( var team : Sequence := Sequence{0}->union(Sequence{i}->union(Sequence{ 0 })) ; heappush(hq, team) ; m[i+1] := team) ; var time : int := 0 ; for line : file_input do ( var d : OclAny := null; var t : OclAny := null; var x : OclAny := null; Sequence{d,t,x} := (line.split())->collect( _x | (OclType["int"])->apply(_x) ) ; hq->first()[2+1] := hq->first()[2+1] + t - time ; time := t ; var scored_team : OclAny := m[d+1] ; scored_team->first() := scored_team->first() - x ; heappush(hq, scored_team) ; m[d+1][2+1] := -1 ; m[d+1] := scored_team ; while hq->first()[2+1] = -1 do ( heappop(hq))) ; hq->first()[2+1] := hq->first()[2+1] + L - time ; var ans_team : OclAny := Set{hq, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))) , (test (logical_test (comparison (expr - (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ))))))))}->max() ; execute (ans_team[1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) odd=0 one=0 zero=0 for i in range(n): s=input() if(len(s)% 2==1): odd+=1 one+=(s.count('1')) zero+=(s.count('0')) if(zero % 2==1 and(odd==0)): print(n-1) else : print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var odd : int := 0 ; var one : int := 0 ; var zero : int := 0 ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if ((s)->size() mod 2 = 1) then ( odd := odd + 1 ) else skip ; one := one + (s->count('1')) ; zero := zero + (s->count('0'))) ; if (zero mod 2 = 1 & (odd = 0)) then ( execute (n - 1)->display() ) else ( execute (n)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input for _ in[0]*int(I()): n=int(I()); f=c=0 for _ in[0]*n : s=I(); f |=len(s); c ^=s.count('1') print(n-(~ f & c & 1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + ((I())))->toInteger()) do ( var n : int := ("" + ((I())))->toInteger(); var f : OclAny := 0; var c : int := 0 ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, n) do ( var s : OclAny := I(); f := f or (s)->size(); c := c xor s->count('1')) ; execute (n - (MathLib.bitwiseAnd(MathLib.bitwiseAnd(MathLib.bitwiseNot(f), c), 1)))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for y in[0]*int(input()): n=int(input()); f=c=0 for z in[0]*n : s=input(); f |=len(s); c ^=s.count('1') print(n-(~ f & c & 1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for y : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var f : OclAny := 0; var c : int := 0 ; for z : MatrixLib.elementwiseMult(Sequence{ 0 }, n) do ( var s : String := (OclFile["System.in"]).readLine(); f := f or (s)->size(); c := c xor s->count('1')) ; execute (n - (MathLib.bitwiseAnd(MathLib.bitwiseAnd(MathLib.bitwiseNot(f), c), 1)))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- results=[] for t in range(int(input())): n=int(input()) strings=[] good=0 bad=0 odd=0 for i in range(n): strings.append(input()) if len(strings[i])% 2==1 : good+=1 odd+=1 else : if len(strings[i])% 2==0 and strings[i].count('0')% 2==0 and strings[i].count('1')% 2==0 : good+=1 else : bad+=1 if bad % 2==1 : if odd>0 : good+=bad else : good+=bad-1 else : good+=bad results.append(str(good)) print('\n'.join(results)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var results : Sequence := Sequence{} ; for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var strings : Sequence := Sequence{} ; var good : int := 0 ; var bad : int := 0 ; var odd : int := 0 ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : strings) ; if (strings[i+1])->size() mod 2 = 1 then ( good := good + 1 ; odd := odd + 1 ) else ( if (strings[i+1])->size() mod 2 = 0 & strings[i+1]->count('0') mod 2 = 0 & strings[i+1]->count('1') mod 2 = 0 then ( good := good + 1 ) else ( bad := bad + 1 ) )) ; if bad mod 2 = 1 then ( if odd > 0 then ( good := good + bad ) else ( good := good + bad - 1 ) ) else ( good := good + bad ) ; execute ((("" + ((good)))) : results)) ; execute (StringLib.sumStringsWithSeparator((results), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque n=int(input()) que=deque() for i in range(n): command=input() if command=="deleteFirst" : que.popleft() elif command=="deleteLast" : que.pop() else : x,y=command.split() if x=="insert" : que.appendleft(y) else : if y in que : que.remove(y) print(*que) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var que : Sequence := () ; for i : Integer.subrange(0, n-1) do ( var command : String := (OclFile["System.in"]).readLine() ; if command = "deleteFirst" then ( que := que->tail() ) else (if command = "deleteLast" then ( que := que->front() ) else ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := command.split() ; if x = "insert" then ( que := que->prepend(y) ) else ( if (que)->includes(y) then ( execute ((y) /: que) ) else skip ) ) ) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name que))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import deque n=int(sys.stdin.readline()) inputs=[] for i in range(n): inputs.append(sys.stdin.readline().split()) linked_list=deque([]) for line in inputs : cmd=line[0] if len(line)==2 : value=line[1] if cmd=="insert" : linked_list.appendleft(value) elif cmd=="delete" : if value in linked_list : linked_list.remove(value) elif cmd=="deleteFirst" : linked_list.popleft() elif cmd=="deleteLast" : linked_list.pop() print(*linked_list) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var inputs : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((sys.stdin.readLine().split()) : inputs)) ; var linked_list : Sequence := (Sequence{}) ; for line : inputs do ( var cmd : OclAny := line->first() ; if (line)->size() = 2 then ( var value : OclAny := line[1+1] ) else skip ; if cmd = "insert" then ( linked_list := linked_list->prepend(value) ) else (if cmd = "delete" then ( if (linked_list)->includes(value) then ( execute ((value) /: linked_list) ) else skip ) else (if cmd = "deleteFirst" then ( linked_list := linked_list->tail() ) else (if cmd = "deleteLast" then ( linked_list := linked_list->front() ) else skip ) ) ) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name linked_list))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque from enum import Enum import sys import math BIG_NUM=2000000000 MOD=1000000007 EPS=0.000000001 LIST=deque() num_command=int(input()) for loop in range(num_command): input_command=input() if input_command=='deleteFirst' : LIST.popleft() elif input_command=='deleteLast' : LIST.pop(); else : com,num=input_command.split() if com=='insert' : LIST.appendleft(num) elif com=='delete' : try : LIST.remove(num) except : pass print(' '.join(LIST)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; var LIST : Sequence := () ; var num_command : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for loop : Integer.subrange(0, num_command-1) do ( var input_command : String := (OclFile["System.in"]).readLine() ; if input_command = 'deleteFirst' then ( LIST := LIST->tail() ) else (if input_command = 'deleteLast' then ( LIST := LIST->front(); ) else ( var com : OclAny := null; var num : OclAny := null; Sequence{com,num} := input_command.split() ; if com = 'insert' then ( LIST := LIST->prepend(num) ) else (if com = 'delete' then ( try ( execute ((num) /: LIST)) catch (_e : OclException) do ( skip) ) else skip) ) ) ) ; execute (StringLib.sumStringsWithSeparator((LIST), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque import sys n=int(input()) deq=deque() sub_deq={} for cmd in sys.stdin.readlines(): if cmd=='deleteFirst\n' : while deq : data=deq.pop() if data[1]: data[1]=0 break elif cmd=='deleteLast\n' : while deq : data=deq.popleft() if data[1]: data[1]=0 break else : cmd,val=cmd.split() if cmd=='insert' : data=[val,1] deq.append(data) if val not in sub_deq : sub_deq[val]=[data] else : sub_deq[val].append(data) elif cmd=='delete' : if val in sub_deq : deq_v=sub_deq[val] while deq_v : data=deq_v.pop() if data[1]: data[1]=0 break sys.stdout.write(" ".join(data[0]for data in reversed(deq)if data[1])) sys.stdout.write('\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var deq : Sequence := () ; var sub_deq : OclAny := Set{} ; for cmd : (OclFile["System.in"]).readlines() do ( if cmd = 'deleteFirst ' then ( while deq do ( var data : OclAny := deq->last() ; deq := deq->front() ; if data[1+1] then ( data[1+1] := 0 ; break ) else skip) ) else (if cmd = 'deleteLast ' then ( while deq do ( data := deq->first() ; deq := deq->tail() ; if data[1+1] then ( data[1+1] := 0 ; break ) else skip) ) else ( var cmd : OclAny := null; var val : OclAny := null; Sequence{cmd,val} := cmd.split() ; if cmd = 'insert' then ( data := Sequence{val}->union(Sequence{ 1 }) ; execute ((data) : deq) ; if (sub_deq)->excludes(val) then ( sub_deq[val+1] := Sequence{ data } ) else ( (expr (atom (name sub_deq)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name val)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name data)))))))) )))) ) ) else (if cmd = 'delete' then ( if (sub_deq)->includes(val) then ( var deq_v : OclAny := sub_deq[val+1] ; while deq_v do ( data := deq_v->last() ; deq_v := deq_v->front() ; if data[1+1] then ( data[1+1] := 0 ; break ) else skip) ) else skip ) else skip) ) ) ) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " ") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name data)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))) (comp_for for (exprlist (expr (atom (name data)))) in (logical_test (comparison (expr (atom (name reversed)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name deq)))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (atom (name data)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))))) ))))))))) )))) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ' '))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque query=int(input()) l=deque() for _ in range(query): command=input().strip() if command=="deleteFirst" : try : l.popleft() except : pass elif command=="deleteLast" : try : l.pop() except : pass else : command,value=command.split(" ") if command=="insert" : l.appendleft(int(value)) elif command=="delete" : try : l.remove(int(value)) except : pass print(*l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var query : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := () ; for _anon : Integer.subrange(0, query-1) do ( var command : OclAny := input()->trim() ; if command = "deleteFirst" then ( try ( l := l->tail()) catch (_e : OclException) do ( skip) ) else (if command = "deleteLast" then ( try ( l := l->front()) catch (_e : OclException) do ( skip) ) else ( var value : OclAny := null; Sequence{command,value} := command.split(" ") ; if command = "insert" then ( l := l->prepend(("" + ((value)))->toInteger()) ) else (if command = "delete" then ( try ( execute ((("" + ((value)))->toInteger()) /: l)) catch (_e : OclException) do ( skip) ) else skip) ) ) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name l))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=list(map(int,input().split())) A.append(0) A.sort() winner="" for i in range(N+1): if A[N-i]>i : if(A[N-i]-i)% 2==0 : winner="First" else : winner="Second" elif A[N-i]==i : if(A[N-i+1]-A[N-i])% 2==1 : winner="First" break else : count=0 for j in range(N-i,-1,-1): if A[j]==i : count+=1 else : break if count % 2==1 : winner="First" else : winner="Second" break else : break print(winner) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((0) : A) ; A := A->sort() ; var winner : String := "" ; for i : Integer.subrange(0, N + 1-1) do ( if (A[N - i+1]->compareTo(i)) > 0 then ( if (A[N - i+1] - i) mod 2 = 0 then ( winner := "First" ) else ( winner := "Second" ) ) else (if A[N - i+1] = i then ( if (A[N - i + 1+1] - A[N - i+1]) mod 2 = 1 then ( winner := "First" ; break ) else ( var count : int := 0 ; for j : Integer.subrange(-1 + 1, N - i)->reverse() do ( if A[j+1] = i then ( count := count + 1 ) else ( break )) ; if count mod 2 = 1 then ( winner := "First" ) else ( winner := "Second" ) ; break ) ) else ( break ) ) ) ; execute (winner)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def centered_cube(n): return(2*n+1)*(n*n+n+1) if __name__=='__main__' : n=3 print(n,"th Centered cube "+"number : ",centered_cube(n)) n=10 print(n,"th Centered cube "+"number : ",centered_cube(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 3 ; execute (n)->display() ; n := 10 ; execute (n)->display() ) else skip; operation centered_cube(n : OclAny) : OclAny pre: true post: true activity: return (2 * n + 1) * (n * n + n + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=[] for i in range(1,a+1): x,y,n=map(int,input().split()) j=(n-y)//x k=j*x+y b.append(k) for z in b : print(z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := Sequence{} ; for i : Integer.subrange(1, a + 1-1) do ( var x : OclAny := null; var y : OclAny := null; var n : OclAny := null; Sequence{x,y,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var j : int := (n - y) div x ; var k : double := j * x + y ; execute ((k) : b)) ; for z : b do ( execute (z)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n,*aaa=map(int,sys.stdin.read().split()) aaa.sort(reverse=True) aaa.append(-1) i=0 while aaa[i+1]>i+1 : i+=1 j=i while aaa[j]>=i+1 : j+=1 if(aaa[i]-i)% 2==0 or(j-i)% 2==0 : ans=0 else : ans=1 print(['First','Second'][ans]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var aaa : OclAny := null; Sequence{n,aaa} := (sys.stdin.readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; aaa := aaa->sort() ; execute ((-1) : aaa) ; var i : int := 0 ; while (aaa[i + 1+1]->compareTo(i + 1)) > 0 do ( i := i + 1) ; var j : int := i ; while (aaa[j+1]->compareTo(i + 1)) >= 0 do ( j := j + 1) ; if (aaa[i+1] - i) mod 2 = 0 or (j - i) mod 2 = 0 then ( var ans : int := 0 ) else ( ans := 1 ) ; execute (Sequence{'First'}->union(Sequence{ 'Second' })[ans+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time sys.setrecursionlimit(10**7) inf=10**10 mod=10**9+7 def f(): n=int(input()) a=list(map(int,input().split())) a.sort() a.reverse() i=j=0 while i+1j+1 : i+=1 j+=1 if(a[i]-j-1)% 2==1 : return 'First' k=0 while i+1j : i+=1 k+=1 if k % 2==1 : return 'First' return 'Second' print(f()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(10) ; var mod : double := (10)->pow(9) + 7 ; skip ; execute (f())->display(); operation f() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; a := a->reverse() ; var i : OclAny := 0; var j : int := 0 ; while (i + 1->compareTo(n)) < 0 & (a[i + 1+1]->compareTo(j + 1)) > 0 do ( i := i + 1 ; j := j + 1) ; if (a[i+1] - j - 1) mod 2 = 1 then ( return 'First' ) else skip ; var k : int := 0 ; while (i + 1->compareTo(n)) < 0 & (a[i + 1+1]->compareTo(j)) > 0 do ( i := i + 1 ; k := k + 1) ; if k mod 2 = 1 then ( return 'First' ) else skip ; return 'Second'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=sorted(map(int,input().split()))[: :-1] j=i=0 for x in range(n): i+=a[i]>i ; j+=a[j]>=i print('SFeicrosntd'[(a[i-1]^ i)& 1 |(j ^ i)& 1 : : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := sorted((input().split())->collect( _x | (OclType["int"])->apply(_x) ))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var j : OclAny := 0; var i : int := 0 ; for x : Integer.subrange(0, n-1) do ( i := i + (a[i+1]->compareTo(i)) > 0; j := j + (a[j+1]->compareTo(i)) >= 0) ; execute ('SFeicrosntd'(subscript (test (logical_test (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))) ^ (expr (atom (name i)))))))) ))) & (expr (atom (number (integer 1))))) | (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name j))) ^ (expr (atom (name i)))))))) ))) & (expr (atom (number (integer 1))))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(i)for i in input().split()] a.sort(reverse=True) a.append(0) ans=False for i in range(n): if i+1>=a[i+1]: ans=(((a[i]-i)% 2)==0) for j in range(i+1,n+1): if a[j]<=i : ans=ans or(((i-j)% 2)==0) break break if ans : print("First") else : print("Second") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; a := a->sort() ; execute ((0) : a) ; var ans : boolean := false ; for i : Integer.subrange(0, n-1) do ( if (i + 1->compareTo(a[i + 1+1])) >= 0 then ( ans := (((a[i+1] - i) mod 2) = 0) ; for j : Integer.subrange(i + 1, n + 1-1) do ( if (a[j+1]->compareTo(i)) <= 0 then ( ans := ans or (((i - j) mod 2) = 0) ; break ) else skip) ; break ) else skip) ; if ans then ( execute ("First")->display() ) else ( execute ("Second")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def distribution(arr,n): arr.sort(reverse=False) count=1 for i in range(1,n,1): if(arr[i]>arr[i-1]): count+=1 return min(count,n/2) if __name__=='__main__' : arr=[1,1,2,1,3,4] n=len(arr) print(int(distribution(arr,n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{3}->union(Sequence{ 4 }))))) ; n := (arr)->size() ; execute (("" + ((distribution(arr, n))))->toInteger())->display() ) else skip; operation distribution(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var count : int := 1 ; for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if ((arr[i+1]->compareTo(arr[i - 1+1])) > 0) then ( count := count + 1 ) else skip) ; return Set{count, n / 2}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _MIN=-2147483648 _MAX=2147483648 class getnode : def __init__(self,data): self.data=data self.left=None self.right=None def getlevel(root,data): q=[] level=1 q.append(root) q.append(None) while(len(q)): temp=q[0] q.pop(0) if(temp==None): if len(q)==0 : return 0 if(q[0]!=None): q.append(None) level+=1 else : if(temp.data==data): return level if(temp.left): q.append(temp.left) if(temp.right): q.append(temp.right) return 0 if __name__=='__main__' : root=getnode(20) root.left=getnode(10) root.right=getnode(30) root.left.left=getnode(5) root.left.right=getnode(15) root.left.right.left=getnode(12) root.right.left=getnode(25) root.right.right=getnode(40) level=getlevel(root,30) if level!=0 : print("level of node 30 is",level) else : print("node 30 not found") level=getlevel(root,12) if level!=0 : print("level of node 12 is",level) else : print("node 12 not found") level=getlevel(root,25) if level!=0 : print("level of node 25 is",level) else : print("node 25 not found") level=getlevel(root,27) if level!=0 : print("level of node 27 is",level) else : print("node 27 not found") ------------------------------------------------------------ OCL File: --------- class getnode { static operation newgetnode() : getnode pre: true post: getnode->exists( _x | result = _x ); attribute data : OclAny := data; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(data : OclAny) : getnode pre: true post: true activity: self.data := data ; self.left := null ; self.right := null; return self; } class FromPython { operation initialise() pre: true post: true activity: var _MIN : int := -2147483648 ; var _MAX : int := 2147483648 ; skip ; skip ; if __name__ = '__main__' then ( root := (getnode.newgetnode()).initialise(20) ; root.left := (getnode.newgetnode()).initialise(10) ; root.right := (getnode.newgetnode()).initialise(30) ; root.left.left := (getnode.newgetnode()).initialise(5) ; root.left.right := (getnode.newgetnode()).initialise(15) ; root.left.right.left := (getnode.newgetnode()).initialise(12) ; root.right.left := (getnode.newgetnode()).initialise(25) ; root.right.right := (getnode.newgetnode()).initialise(40) ; level := getlevel(root, 30) ; if level /= 0 then ( execute ("level of node 30 is")->display() ) else ( execute ("node 30 not found")->display() ) ; level := getlevel(root, 12) ; if level /= 0 then ( execute ("level of node 12 is")->display() ) else ( execute ("node 12 not found")->display() ) ; level := getlevel(root, 25) ; if level /= 0 then ( execute ("level of node 25 is")->display() ) else ( execute ("node 25 not found")->display() ) ; level := getlevel(root, 27) ; if level /= 0 then ( execute ("level of node 27 is")->display() ) else ( execute ("node 27 not found")->display() ) ) else skip; operation getlevel(root : OclAny, data : OclAny) : OclAny pre: true post: true activity: var q : Sequence := Sequence{} ; var level : int := 1 ; execute ((root) : q) ; execute ((null) : q) ; while ((q)->size()) do ( var temp : OclAny := q->first() ; q := q->excludingAt(0+1) ; if (temp = null) then ( if (q)->size() = 0 then ( return 0 ) else skip ; if (q->first() /= null) then ( execute ((null) : q) ) else skip ; level := level + 1 ) else ( if (temp.data = data) then ( return level ) else skip ; if (temp.left) then ( execute ((temp.left) : q) ) else skip ; if (temp.right) then ( execute ((temp.right) : q) ) else skip )) ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lis=[] lis2=[] for i in range(n): lis.append(input()) a=dict() for t in lis : a[t]=1 s=sum(a.values()) if s==2 : for m in a.keys(): lis2.append(lis.count(m)) if lis2[0]==lis2[1]: print('YES') for m in a.keys(): print(m) else : print('NO') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lis : Sequence := Sequence{} ; var lis2 : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : lis)) ; var a : Map := (arguments ( )) ; for t : lis do ( a[t+1] := 1) ; var s : OclAny := (a.values())->sum() ; if s = 2 then ( for m : a.keys() do ( execute ((lis->count(m)) : lis2)) ; if lis2->first() = lis2[1+1] then ( execute ('YES')->display() ; for m : a.keys() do ( execute (m)->display()) ) else ( execute ('NO')->display() ) ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) list1=[] for i in range(n): list1.append(int(input())) res=list(set(list1)) if(len(res)==2 and list1.count(res[0])==list1.count(res[1])): print("YES") print(res[0],res[1]) else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var list1 : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : list1)) ; var res : Sequence := (Set{}->union((list1))) ; if ((res)->size() = 2 & list1->count(res->first()) = list1->count(res[1+1])) then ( execute ("YES")->display() ; execute (res->first())->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() n=int(input()) q=[] for i in range(n): q+=[int(input())] if len(set(q))==2 and q.count(q[0])==n//2 : print("YES\n",*{*q}) else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var q : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( q := q + Sequence{ ("" + (((OclFile["System.in"]).readLine())))->toInteger() }) ; if (Set{}->union((q)))->size() = 2 & q->count(q->first()) = n div 2 then ( execute ("YES\n")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(input()) if n==1 : print(1) sys.exit(0) magic_square=[] for _ in range(n): magic_square.append(list(map(int,input().split()))) row_sums,col_sums=[],[] da,db=0,0 ret=0 def cal(): global da,db for row in magic_square : row_sums.append(sum(row)) for i in range(n): acc=0 for j in range(n): acc+=magic_square[j][i] col_sums.append(acc) da+=magic_square[i][i] db+=magic_square[-i-1][i] cal() if len(set(row_sums))>2 or len(set(col_sums))>2 : print(-1) else : x,y=0,0 difx,dify=row_sums[1]-row_sums[0],col_sums[1]-col_sums[0] for i in range(1,n): if row_sums[i]1 or len(set(col_sums))>1 : print(-1) else : print(difx) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute da : OclAny; attribute db : OclAny; operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (1)->display() ; sys.exit(0) ) else skip ; var magic_square : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : magic_square)) ; var row_sums : OclAny := null; var col_sums : OclAny := null; Sequence{row_sums,col_sums} := Sequence{Sequence{},Sequence{}} ; var da : OclAny := null; var db : OclAny := null; Sequence{da,db} := Sequence{0,0} ; var ret : int := 0 ; skip ; cal() ; if (Set{}->union((row_sums)))->size() > 2 or (Set{}->union((col_sums)))->size() > 2 then ( execute (-1)->display() ) else ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{0,0} ; var difx : OclAny := null; var dify : OclAny := null; Sequence{difx,dify} := Sequence{row_sums[1+1] - row_sums->first(),col_sums[1+1] - col_sums->first()} ; for i : Integer.subrange(1, n-1) do ( if (row_sums[i+1]->compareTo(row_sums[i - 1+1])) < 0 then ( var x : OclAny := null; var difx : OclAny := null; Sequence{x,difx} := Sequence{i,row_sums[i - 1+1] - row_sums[i+1]} ) else skip ; if (col_sums[i+1]->compareTo(col_sums[i - 1+1])) < 0 then ( var y : OclAny := null; var dify : OclAny := null; Sequence{y,dify} := Sequence{i,col_sums[i - 1+1] - col_sums[i+1]} ) else skip) ; if difx /= dify then ( execute (-1)->display() ) else ( magic_square[x+1][y+1] := difx ; var row_sums : OclAny := null; var col_sums : OclAny := null; Sequence{row_sums,col_sums} := Sequence{Sequence{},Sequence{}} ; Sequence{da,db} := Sequence{0,0} ; cal() ; execute ((da) : row_sums) ; execute ((db) : col_sums) ; if (Set{}->union((row_sums)))->size() > 1 or (Set{}->union((col_sums)))->size() > 1 then ( execute (-1)->display() ) else ( execute (difx)->display() ) ) ); operation cal() pre: true post: true activity: skip; skip ; for row : magic_square do ( execute (((row)->sum()) : row_sums)) ; for i : Integer.subrange(0, n-1) do ( var acc : int := 0 ; for j : Integer.subrange(0, n-1) do ( acc := acc + magic_square[j+1][i+1]) ; execute ((acc) : col_sums) ; da := da + magic_square[i+1][i+1] ; db := db + magic_square->reverse()->at(-(-i - 1))[i+1]); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def paint(map_inp,x,y): if map_inp[y][x]: map_inp[y][x]=False if map_inp[y][x-1]: map_inp=paint(map_inp,x-1,y) if map_inp[y][x+1]: map_inp=paint(map_inp,x+1,y) if map_inp[y-1][x]: map_inp=paint(map_inp,x,y-1) if map_inp[y+1][x]: map_inp=paint(map_inp,x,y+1) return map_inp while True : try : m=[[False for i in range(14)]for j in range(14)] for i in range(12): inp=input() for j in range(12): if inp[j]=="1" : m[i+1][j+1]=True cnt=0 for i in range(12): for j in range(12): if m[i+1][j+1]: m=paint(m,j+1,i+1) cnt+=1 print(cnt) inp=input() except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( try ( var m : Sequence := Integer.subrange(0, 14-1)->select(j | true)->collect(j | (Integer.subrange(0, 14-1)->select(i | true)->collect(i | (false)))) ; for i : Integer.subrange(0, 12-1) do ( var inp : String := (OclFile["System.in"]).readLine() ; for j : Integer.subrange(0, 12-1) do ( if inp[j+1] = "1" then ( m[i + 1+1][j + 1+1] := true ) else skip)) ; var cnt : int := 0 ; for i : Integer.subrange(0, 12-1) do ( for j : Integer.subrange(0, 12-1) do ( if m[i + 1+1][j + 1+1] then ( m := paint(m, j + 1, i + 1) ; cnt := cnt + 1 ) else skip)) ; execute (cnt)->display() ; inp := (OclFile["System.in"]).readLine()) catch (_e : OclException) do ( break) ); operation paint(map_inp : OclAny, x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if map_inp[y+1][x+1] then ( map_inp[y+1][x+1] := false ; if map_inp[y+1][x - 1+1] then ( map_inp := paint(map_inp, x - 1, y) ) else skip ; if map_inp[y+1][x + 1+1] then ( map_inp := paint(map_inp, x + 1, y) ) else skip ; if map_inp[y - 1+1][x+1] then ( map_inp := paint(map_inp, x, y - 1) ) else skip ; if map_inp[y + 1+1][x+1] then ( map_inp := paint(map_inp, x, y + 1) ) else skip ) else skip ; return map_inp; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s={} for i in range(n): x=int(input()) if(x not in s): s.update({x : 1}) else : s[x]+=1 k=[*s.keys()] if(len(k)==2 and s[k[0]]-s[k[1]]==0): print("YES"); print(*k) else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if ((s)->excludes(x)) then ( execute ((Map{ x |-> 1 }) <: s) ) else ( s[x+1] := s[x+1] + 1 )) ; var k : Sequence := s.keys() ; if ((k)->size() = 2 & s[k->first()+1] - s[k[1+1]+1] = 0) then ( execute ("YES")->display(); execute ((argument * (test (logical_test (comparison (expr (atom (name k))))))))->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=0 for i in range(a): x,y,n=map(int,input().split()) b=n//x if b*x+y>n : print((b-1)*x+y) else : print(b*x+y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := 0 ; for i : Integer.subrange(0, a-1) do ( var x : OclAny := null; var y : OclAny := null; var n : OclAny := null; Sequence{x,y,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; b := n div x ; if (b * x + y->compareTo(n)) > 0 then ( execute ((b - 1) * x + y)->display() ) else ( execute (b * x + y)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) values=[] val1=-1 val2=-1 for i in range(n): inp=int(input()) values.append(inp) if(val1==-1): val1=inp if(inp!=val1): val2=inp count1=values.count(val1) count2=values.count(val2) if((count1==count2)and(count1+count2==n)): print("YES") print(val1,val2) else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var values : Sequence := Sequence{} ; var val1 : int := -1 ; var val2 : int := -1 ; for i : Integer.subrange(0, n-1) do ( var inp : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((inp) : values) ; if (val1 = -1) then ( val1 := inp ) else skip ; if (inp /= val1) then ( val2 := inp ) else skip) ; var count1 : int := values->count(val1) ; var count2 : int := values->count(val2) ; if ((count1 = count2) & (count1 + count2 = n)) then ( execute ("YES")->display() ; execute (val1)->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSurpasser(arr,n): for i in range(0,n): count=0 ; for j in range(i+1,n): if(arr[j]>arr[i]): count+=1 print(count,end=" ") def printArray(arr,n): for i in range(0,n): print(arr[i],end=" ") arr=[2,7,5,3,0,8,1] n=len(arr) print("Given array is") printArray(arr,n) print("\nSurpasser Count of array is"); findSurpasser(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{2}->union(Sequence{7}->union(Sequence{5}->union(Sequence{3}->union(Sequence{0}->union(Sequence{8}->union(Sequence{ 1 })))))) ; n := (arr)->size() ; execute ("Given array is")->display() ; printArray(arr, n) ; execute ("\nSurpasser Count of array is")->display(); ; findSurpasser(arr, n); operation findSurpasser(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( var count : int := 0; ; for j : Integer.subrange(i + 1, n-1) do ( if ((arr[j+1]->compareTo(arr[i+1])) > 0) then ( count := count + 1 ) else skip) ; execute (count)->display()); operation printArray(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def firstNonRepeating(arr,n): mp={} for i in range(n): if arr[i]not in mp : mp[arr[i]]=0 mp[arr[i]]+=1 for x in mp : if(mp[x]==1): print(x,end=" ") arr=[9,4,9,6,7,4] n=len(arr) firstNonRepeating(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{9}->union(Sequence{4}->union(Sequence{9}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 4 }))))) ; n := (arr)->size() ; firstNonRepeating(arr, n); operation firstNonRepeating(arr : OclAny, n : OclAny) pre: true post: true activity: var mp : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( if (mp)->excludes(arr[i+1]) then ( mp[arr[i+1]+1] := 0 ) else skip ; mp[arr[i+1]+1] := mp[arr[i+1]+1] + 1) ; for x : mp do ( if (mp[x+1] = 1) then ( execute (x)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def computeLPSArray(string): M=len(string) lps=[None]*M length=0 lps[0]=0 i=1 while idisplay() ) else skip; operation computeLPSArray(string : OclAny) : OclAny pre: true post: true activity: var M : int := (string)->size() ; var lps : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, M) ; var length : int := 0 ; lps->first() := 0 ; var i : int := 1 ; while (i->compareTo(M)) < 0 do ( if string[i+1] = string[length+1] then ( length := length + 1 ; lps[i+1] := length ; i := i + 1 ) else ( if length /= 0 then ( length := lps[length - 1+1] ) else ( lps[i+1] := 0 ; i := i + 1 ) )) ; return lps; operation getMinCharToAddedToMakeStringPalin(string : OclAny) : OclAny pre: true post: true activity: var revStr : OclAny := string(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var concat : String := string + "$" + revStr ; lps := computeLPSArray(concat) ; return (string)->size() - lps->last(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=set(map(int,input().split())) m=int(input()) b=set(map(int,input().split())) for i in sorted(a & b): print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; for i : MathLib.bitwiseAnd(a, b)->sort() do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def intersect(n,m,a,b): i,j=0,0 while ib[j]: j+=1 else : yield a[i] i+=1 j+=1 def run(): n=int(input()) a=[int(i)for i in input().split()] m=int(input()) b=[int(j)for j in input().split()] for v in intersect(n,m,a,b): print(v) if __name__=='__main__' : run() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( run() ) else skip; operation intersect(n : OclAny, m : OclAny, a : OclAny, b : OclAny) pre: true post: true activity: var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,0} ; while (i->compareTo(n)) < 0 & (j->compareTo(m)) < 0 do ( if (a[i+1]->compareTo(b[j+1])) < 0 then ( i := i + 1 ) else (if (a[i+1]->compareTo(b[j+1])) > 0 then ( j := j + 1 ) else ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return a[i+1] ; i := i + 1 ; j := j + 1 ) ) ); operation run() pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; m := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; b := input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; for v : intersect(n, m, a, b) do ( execute (v)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : input() A=set(map(int,input().split())) input() B=set(map(int,input().split())) I=A & B if I : print(*sorted(I),sep="\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( input() ; var A : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; input() ; var B : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var I : int := MathLib.bitwiseAnd(A, B) ; if I then ( execute ((argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name I)))))))) )))))))))->display() ) else skip ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) a=set([int(a)for a in input().split()]) m=int(input()) b=set([int(a)for a in input().split()]) c=a.intersection(b) sorted_c=sorted(c) for i in sorted_c : print(i) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Set := Set{}->union((input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())))) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Set := Set{}->union((input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())))) ; var c : OclAny := a->intersection(b) ; var sorted_c : Sequence := c->sort() ; for i : sorted_c do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) if N % 2==0 : print(0.5) else : print((N+1)/N/2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N mod 2 = 0 then ( execute (0.5)->display() ) else ( execute ((N + 1) / N / 2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) alist=list(map(int,input().split())) m=int(input()) blist=list(map(int,input().split())) anslist=set(alist)& set(blist) anslist=list(anslist) anslist.sort() for ans in anslist : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var alist : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var blist : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var anslist : int := MathLib.bitwiseAnd(Set{}->union((alist)), Set{}->union((blist))) ; anslist := (anslist) ; anslist := anslist->sort() ; for ans : anslist do ( execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calcAngle(hh,mm): hour_angle=0.5*(hh*60+mm) minute_angle=6*mm angle=abs(hour_angle-minute_angle) angle=min(360-angle,angle) return angle def printTime(theta): for hh in range(0,12): for mm in range(0,60): if(calcAngle(hh,mm)==theta): print(hh,":",mm,sep="") return print("Input angle not valid.") return theta=90.0 printTime(theta) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; theta := 90.0 ; printTime(theta); operation calcAngle(hh : OclAny, mm : OclAny) : OclAny pre: true post: true activity: var hour_angle : double := 0.5 * (hh * 60 + mm) ; var minute_angle : double := 6 * mm ; var angle : double := (hour_angle - minute_angle)->abs() ; angle := Set{360 - angle, angle}->min() ; return angle; operation printTime(theta : OclAny) pre: true post: true activity: for hh : Integer.subrange(0, 12-1) do ( for mm : Integer.subrange(0, 60-1) do ( if (calcAngle(hh, mm) = theta) then ( execute (hh)->display() ; return ) else skip)) ; execute ("Input angle not valid.")->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x,y,n=map(int,input().split()) ans=0 ans=n-n % x+y if ans<=n : print(ans) else : print(n-n % x-(x-y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; var n : OclAny := null; Sequence{x,y,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; ans := n - n mod x + y ; if (ans->compareTo(n)) <= 0 then ( execute (ans)->display() ) else ( execute (n - n mod x - (x - y))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class UnionFind : def __init__(self,size): self.table=[-1]*size def find(self,x): while self.table[x]>=0 : x=self.table[x] return x def union(self,x,y): x_root=self.find(x) y_root=self.find(y) if x_root!=y_root : if self.table[x_root]exists( _x | result = _x ); attribute table : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, size); operation initialise(size : OclAny) : UnionFind pre: true post: true activity: self.table := MatrixLib.elementwiseMult(Sequence{ -1 }, size); return self; operation find(x : OclAny) : OclAny pre: true post: true activity: while self.table[x+1] >= 0 do ( x := self.table[x+1]) ; return x; operation union(x : OclAny,y : OclAny) pre: true post: true activity: var x_root : int := self->indexOf(x) - 1 ; var y_root : int := self->indexOf(y) - 1 ; if x_root /= y_root then ( if (self.table[x_root+1]->compareTo(self.table[y_root+1])) < 0 then ( self.table[x_root+1] := self.table[x_root+1] + self.table[y_root+1] ; self.table[y_root+1] := x_root ) else ( self.table[y_root+1] := self.table[y_root+1] + self.table[x_root+1] ; self.table[x_root+1] := y_root ) ) else skip; operation isDisjoint(x : OclAny,y : OclAny) : OclAny pre: true post: true activity: return self->indexOf(x) - 1 /= self->indexOf(y) - 1; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; solve(); operation solve() pre: true post: true activity: skip ; var file_input : OclFile := OclFile["System.in"] ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (file_input.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var piles : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((file_input.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var fences : Sequence := Sequence{} ; for i : Integer.subrange(0, M-1) do ( var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := (file_input.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; p := p - 1 ; q := q - 1 ; var px : OclAny := null; var py : OclAny := null; Sequence{px,py} := piles[p+1] ; var qx : OclAny := null; var qy : OclAny := null; Sequence{qx,qy} := piles[q+1] ; var fence_len : double := ((((px - qx))->pow(2) + ((py - qy))->pow(2)))->pow(0.5) ; execute ((Sequence{fence_len, p, q}) : fences)) ; fences := fences->sort() ; var S : UnionFind := (UnionFind.newUnionFind()).initialise(N) ; var fences_len : int := 0 ; for _tuple : fences do (var _indx : int := 1; var f_len : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p2 : OclAny := _tuple->at(_indx); if S.isDisjoint(p1, p2) then ( S.union(p1, p2) ) else ( fences_len := fences_len + f_len )) ; execute (fences_len)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def swapBits(x): even_bits=x & 0xAAAAAAAA odd_bits=x & 0x55555555 even_bits>>=1 odd_bits<<=1 return(even_bits | odd_bits) x=23 print(swapBits(x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := 23 ; execute (swapBits(x))->display(); operation swapBits(x : OclAny) : OclAny pre: true post: true activity: var even_bits : int := MathLib.bitwiseAnd(x, 0xAAAAAAAA) ; var odd_bits : int := MathLib.bitwiseAnd(x, 0x55555555) ; even_bits := even_bits div (2->pow(1)) ; odd_bits := odd_bits * (2->pow(1)) ; return (MathLib.bitwiseOr(even_bits, odd_bits)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkCentrosymmetricted(n,m): mid_row=0 ; if((n & 1)>0): mid_row=n/2+1 ; else : mid_row=n/2 ; for i in range(int(mid_row)): for j in range(n): if(m[i][j]!=m[n-i-1][n-j-1]): return False ; return True ; n=3 ; m=[[1,3,5],[6,8,6],[5,3,1]]; if(checkCentrosymmetricted(n,m)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3; ; m := Sequence{Sequence{1}->union(Sequence{3}->union(Sequence{ 5 }))}->union(Sequence{Sequence{6}->union(Sequence{8}->union(Sequence{ 6 }))}->union(Sequence{ Sequence{5}->union(Sequence{3}->union(Sequence{ 1 })) })); ; if (checkCentrosymmetricted(n, m)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ); operation checkCentrosymmetricted(n : OclAny, m : OclAny) pre: true post: true activity: var mid_row : int := 0; ; if ((MathLib.bitwiseAnd(n, 1)) > 0) then ( mid_row := n / 2 + 1; ) else ( mid_row := n / 2; ) ; for i : Integer.subrange(0, ("" + ((mid_row)))->toInteger()-1) do ( for j : Integer.subrange(0, n-1) do ( if (m[i+1][j+1] /= m[n - i - 1+1][n - j - 1+1]) then ( return false; ) else skip)) ; return true;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def replaceOriginal(s,n): r=[' ']*n for i in range(n): r[i]=s[n-1-i] if(s[i]!='a' and s[i]!='e' and s[i]!='i' and s[i]!='o' and s[i]!='u'): print(r[i],end="") print() if __name__=="__main__" : s="geeksforgeeks" n=len(s) replaceOriginal(s,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "geeksforgeeks" ; n := (s)->size() ; replaceOriginal(s, n) ) else skip; operation replaceOriginal(s : OclAny, n : OclAny) pre: true post: true activity: var r : Sequence := MatrixLib.elementwiseMult(Sequence{ ' ' }, n) ; for i : Integer.subrange(0, n-1) do ( r[i+1] := s[n - 1 - i+1] ; if (s[i+1] /= 'a' & s[i+1] /= 'e' & s[i+1] /= 'i' & s[i+1] /= 'o' & s[i+1] /= 'u') then ( execute (r[i+1])->display() ) else skip) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def factorial(a,b): res=1 for i in range(1,a+b+1): res=res*i for i in range(1,a+1): res=res//i for i in range(1,b+1): res=res//i return res def Ksmallest(x,y,k): if x==0 and y==0 : return elif x==0 : y-=1 print("V",end="") Ksmallest(x,y,k) elif y==0 : x-=1 print("H",end="") Ksmallest(x,y,k) else : if factorial(x-1,y)>k : print("H",end="") Ksmallest(x-1,y,k) else : print("V",end="") Ksmallest(x,y-1,k-factorial(x-1,y)) if __name__=="__main__" : x,y,k=2,2,2 Ksmallest(x,y,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( Sequence{x,y,k} := Sequence{2,2,2} ; Ksmallest(x, y, k) ) else skip; operation factorial(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; for i : Integer.subrange(1, a + b + 1-1) do ( res := res * i) ; for i : Integer.subrange(1, a + 1-1) do ( res := res div i) ; for i : Integer.subrange(1, b + 1-1) do ( res := res div i) ; return res; operation Ksmallest(x : OclAny, y : OclAny, k : OclAny) pre: true post: true activity: if x = 0 & y = 0 then ( return ) else (if x = 0 then ( y := y - 1 ; execute ("V")->display() ; Ksmallest(x, y, k) ) else (if y = 0 then ( x := x - 1 ; execute ("H")->display() ; Ksmallest(x, y, k) ) else ( if (factorial(x - 1, y)->compareTo(k)) > 0 then ( execute ("H")->display() ; Ksmallest(x - 1, y, k) ) else ( execute ("V")->display() ; Ksmallest(x, y - 1, k - factorial(x - 1, y)) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numofstring(n,m): if n==1 : return m if n==2 : return m*(m-1) return m*(m-1)*pow(m-2,n-2) n=2 m=3 print(numofstring(n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 2 ; m := 3 ; execute (numofstring(n, m))->display(); operation numofstring(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: if n = 1 then ( return m ) else skip ; if n = 2 then ( return m * (m - 1) ) else skip ; return m * (m - 1) * (m - 2)->pow(n - 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) mod=998244353 c=[0]*(n+1) for i in range(1,n+1): for j in range(i,n+1,i): c[j]+=1 ans=c[n] p=1 for i in range(n-1,0,-1): ans+=p*c[i]% mod ans %=mod p*=2 p %=mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mod : int := 998244353 ; var c : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(i, n + 1-1)->select( $x | ($x - i) mod i = 0 ) do ( c[j+1] := c[j+1] + 1)) ; var ans : OclAny := c[n+1] ; var p : int := 1 ; for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( ans := ans + p * c[i+1] mod mod ; ans := ans mod mod ; p := p * 2 ; p := p mod mod) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math num=float(input()) odd_cnt=math.ceil(num/2) ratio=odd_cnt/num print(format(ratio,'.10f')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var num : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; var odd_cnt : double := (num / 2)->ceil() ; var ratio : double := odd_cnt / num ; execute ((ratio + ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p=998244353 n=int(input()) s=0 div=n*[0] for k in range(n): x=k+1 for l in range(1,n//x+1): if l*x<=n : div[l*x-1]+=1 dp=n*[0] dp[0]=1 for k in range(1,n): dp[k]=((div[k]-div[k-1])+2*dp[k-1])% p print(dp[n-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : int := 998244353 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : int := 0 ; var div : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for k : Integer.subrange(0, n-1) do ( var x : OclAny := k + 1 ; for l : Integer.subrange(1, n div x + 1-1) do ( if (l * x->compareTo(n)) <= 0 then ( div[l * x - 1+1] := div[l * x - 1+1] + 1 ) else skip)) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; dp->first() := 1 ; for k : Integer.subrange(1, n-1) do ( dp[k+1] := ((div[k+1] - div[k - 1+1]) + 2 * dp[k - 1+1]) mod p) ; execute (dp[n - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import Counter def distinct_factors(n): ans=1 for x in range(2,n): ans+=(n % x==0) return ans def main(): n=int(input()) mod=998244353 dp=[-1]*(n+1) pre=0 d=[0]*(n+1) for i in range(1,n+1): for j in range(i,n+1,i): d[j]+=1 for i in range(1,n+1): dp[i]=(pre+d[i])% mod pre+=dp[i] return(dp[n])% mod print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; execute (main())->display(); operation distinct_factors(n : OclAny) : OclAny pre: true post: true activity: var ans : int := 1 ; for x : Integer.subrange(2, n-1) do ( ans := ans + (n mod x = 0)) ; return ans; operation main() : OclAny pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mod : int := 998244353 ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (n + 1)) ; var pre : int := 0 ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(i, n + 1-1)->select( $x | ($x - i) mod i = 0 ) do ( d[j+1] := d[j+1] + 1)) ; for i : Integer.subrange(1, n + 1-1) do ( dp[i+1] := (pre + d[i+1]) mod mod ; pre := pre + dp[i+1]) ; return (dp[n+1]) mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys mod=998244353 dp=[0]*1000001 for i in range(1,1000001): j=i+i while j<1000001 : dp[j]+=1 j+=i sum=dp[0]=1 for i in range(1,1000001): dp[i]=(dp[i]+sum)% mod sum=(sum+dp[i])% mod n=int(input()) print(dp[n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var mod : int := 998244353 ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 1000001) ; for i : Integer.subrange(1, 1000001-1) do ( var j : OclAny := i + i ; while j < 1000001 do ( dp[j+1] := dp[j+1] + 1 ; j := j + i)) ; var sum : OclAny := 1; var dp->first() : int := 1 ; for i : Integer.subrange(1, 1000001-1) do ( dp[i+1] := (dp[i+1] + sum) mod mod ; sum := (sum + dp[i+1]) mod mod) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (dp[n+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x,y,n=map(int,input().split()) a=n % x if(a>=y): print(n-a+y) else : print(n-a-x+y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; var n : OclAny := null; Sequence{x,y,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : int := n mod x ; if ((a->compareTo(y)) >= 0) then ( execute (n - a + y)->display() ) else ( execute (n - a - x + y)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sieve(n): n=max(n,6) prime=[-1 for i in range(n+1)] p=2 while(p*p<=n): if(prime[p]==-1): for i in range(p*p,n+1,p): if(prime[i]==-1): prime[i]=p p+=(1+(p % 2)) for i in range(2,n+1): if(prime[i]==-1): prime[i]=i return prime n=int(input()) if(n==1): print(1) exit() s=1 p=sieve(n) mod=998244353 for i in range(2,n+1): curr=i dic={} while(curr!=1): if(p[curr]in dic): dic[p[curr]]+=1 else : dic[p[curr]]=1 curr=curr//p[curr] ans=1 for j in dic : ans*=(1+dic[j]) ans=s+ans ans %=mod s+=ans s %=mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n = 1) then ( execute (1)->display() ; exit() ) else skip ; var s : int := 1 ; p := sieve(n) ; var mod : int := 998244353 ; for i : Integer.subrange(2, n + 1-1) do ( var curr : OclAny := i ; var dic : OclAny := Set{} ; while (curr /= 1) do ( if ((dic)->includes(p[curr+1])) then ( dic[p[curr+1]+1] := dic[p[curr+1]+1] + 1 ) else ( dic[p[curr+1]+1] := 1 ) ; curr := curr div p[curr+1]) ; var ans : int := 1 ; for j : dic do ( ans := ans * (1 + dic[j+1])) ; ans := s + ans ; ans := ans mod mod ; s := s + ans ; s := s mod mod) ; execute (ans)->display(); operation sieve(n : OclAny) : OclAny pre: true post: true activity: n := Set{n, 6}->max() ; var prime : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (-1)) ; var p : int := 2 ; while ((p * p->compareTo(n)) <= 0) do ( if (prime[p+1] = -1) then ( for i : Integer.subrange(p * p, n + 1-1)->select( $x | ($x - p * p) mod p = 0 ) do ( if (prime[i+1] = -1) then ( prime[i+1] := p ) else skip) ) else skip ; p := p + (1 + (p mod 2))) ; for i : Integer.subrange(2, n + 1-1) do ( if (prime[i+1] = -1) then ( prime[i+1] := i ) else skip) ; return prime; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,val): self.data=val self.left=None self.right=None prev=None def isbst(root): global prev prev=None return isbst_rec(root) def isbst_rec(root): global prev if root is None : return True if isbst_rec(root.left)is False : return False if prev is not None and prev.data>root.data : return False prev=root return isbst_rec(root.right) root=Node(4) root.left=Node(2) root.right=Node(5) root.left.left=Node(1) root.left.right=Node(3) if isbst(root): print("is BST") else : print("not a BST") ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := val; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(val : OclAny) : Node pre: true post: true activity: self.data := val ; self.left := null ; self.right := null; return self; } class FromPython { attribute prev : OclAny; attribute prev : OclAny; operation initialise() pre: true post: true activity: skip ; var prev : OclAny := null ; skip ; skip ; root := (Node.newNode()).initialise(4) ; root.left := (Node.newNode()).initialise(2) ; root.right := (Node.newNode()).initialise(5) ; root.left.left := (Node.newNode()).initialise(1) ; root.left.right := (Node.newNode()).initialise(3) ; if isbst(root) then ( execute ("is BST")->display() ) else ( execute ("not a BST")->display() ); operation isbst(root : OclAny) : OclAny pre: true post: true activity: skip ; prev := null ; return isbst_rec(root); operation isbst_rec(root : OclAny) : OclAny pre: true post: true activity: skip ; if root <>= null then ( return true ) else skip ; if isbst_rec(root.left) <>= false then ( return false ) else skip ; if not(prev <>= null) & (prev.data->compareTo(root.data)) > 0 then ( return false ) else skip ; prev := root ; return isbst_rec(root.right); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPowerOfTwo(x): if(x==0): return False if((x &(x-1))==0): return True else : return False def countNum(a,n): count=0 for i in range(0,n,1): if(isPowerOfTwo(a[i])or isPowerOfTwo(a[i]+1)): count+=1 return count if __name__=='__main__' : arr=[5,6,9,3,1] n=len(arr) print(countNum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var arr : Sequence := Sequence{5}->union(Sequence{6}->union(Sequence{9}->union(Sequence{3}->union(Sequence{ 1 })))) ; n := (arr)->size() ; execute (countNum(arr, n))->display() ) else skip; operation isPowerOfTwo(x : OclAny) : OclAny pre: true post: true activity: if (x = 0) then ( return false ) else skip ; if ((MathLib.bitwiseAnd(x, (x - 1))) = 0) then ( return true ) else ( return false ); operation countNum(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (isPowerOfTwo(a[i+1]) or isPowerOfTwo(a[i+1] + 1)) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def firstDigit(x): while(x>=10): x=x//10 return x print(firstDigit(12345)) print(firstDigit(5432)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (firstDigit(12345))->display() ; execute (firstDigit(5432))->display(); operation firstDigit(x : OclAny) : OclAny pre: true post: true activity: while (x >= 10) do ( x := x div 10) ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ceilSearch(arr,low,high,x): if x<=arr[low]: return low i=low for i in range(high): if arr[i]==x : return i if arr[i]=x : return i+1 return-1 arr=[1,2,8,10,10,12,19] n=len(arr) x=3 index=ceilSearch(arr,0,n-1,x); if index==-1 : print("Ceiling of %d doesn't exist in array " % x) else : print("ceiling of %d is %d" %(x,arr[index])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{8}->union(Sequence{10}->union(Sequence{10}->union(Sequence{12}->union(Sequence{ 19 })))))) ; var n : int := (arr)->size() ; x := 3 ; var index : OclAny := ceilSearch(arr, 0, n - 1, x); ; if index = -1 then ( execute (StringLib.format("Ceiling of %d doesn't exist in array ",x))->display() ) else ( execute (StringLib.format("ceiling of %d is %d",Sequence{x, arr[index+1]}))->display() ); operation ceilSearch(arr : OclAny, low : OclAny, high : OclAny, x : OclAny) : OclAny pre: true post: true activity: if (x->compareTo(arr[low+1])) <= 0 then ( return low ) else skip ; var i : OclAny := low ; for i : Integer.subrange(0, high-1) do ( if arr[i+1] = x then ( return i ) else skip ; if (arr[i+1]->compareTo(x)) < 0 & (arr[i + 1+1]->compareTo(x)) >= 0 then ( return i + 1 ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNums(arr,n): S=0 ; X=0 ; for i in range(n): S+=arr[i]; X ^=arr[i]; print(X,X+S); if __name__=="__main__" : arr=[1,7]; n=len(arr); findNums(arr,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{ 7 }); ; n := (arr)->size(); ; findNums(arr, n); ) else skip; operation findNums(arr : OclAny, n : OclAny) pre: true post: true activity: var S : int := 0; var X : int := 0; ; for i : Integer.subrange(0, n-1) do ( S := S + arr[i+1]; ; X := X xor arr[i+1];) ; execute (X)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* def next_int(): return int(input()) def next_ints(): return list(map(int,input().split())) n=next_int() t=0 for i in range(n): if i+1 & 1 : t+=1 print(t/n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var n : OclAny := next_int() ; var t : int := 0 ; for i : Integer.subrange(0, n-1) do ( if MathLib.bitwiseAnd(i + 1, 1) then ( t := t + 1 ) else skip) ; execute (t / n)->display(); operation next_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation next_ints() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): ans=0 digits=tuple(range(10)) for b in digits : for c in digits : for d in digits : for e in digits : for i in digits : m=b+c+d-e-i if m<0 or m>9 : continue for k in digits : f=b+c+d*2-e-i-k if f<0 or f>9 : continue for a in digits : for g in digits : o=a+b+d-g-k if o<0 or o>9 : continue j=a+b+c-g-m if j<0 or j>9 : continue l=a+b+c+d-i-j-k if l<0 or l>9 : continue h=a+b+c+d-e-f-g if h<0 or h>9 : continue n=a+c+d-f-j if n<0 or n>9 : continue p=a+b+c-h-l if p<0 or p>9 : continue ans+=1 return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : int := 0 ; var digits : Sequence := (Integer.subrange(0, 10-1)) ; for b : digits do ( for c : digits do ( for d : digits do ( for e : digits do ( for i : digits do ( var m : double := b + c + d - e - i ; if m < 0 or m > 9 then ( continue ) else skip ; for k : digits do ( var f : double := b + c + d * 2 - e - i - k ; if f < 0 or f > 9 then ( continue ) else skip ; for a : digits do ( for g : digits do ( var o : double := a + b + d - g - k ; if o < 0 or o > 9 then ( continue ) else skip ; var j : double := a + b + c - g - m ; if j < 0 or j > 9 then ( continue ) else skip ; var l : double := a + b + c + d - i - j - k ; if l < 0 or l > 9 then ( continue ) else skip ; var h : double := a + b + c + d - e - f - g ; if h < 0 or h > 9 then ( continue ) else skip ; var n : double := a + c + d - f - j ; if n < 0 or n > 9 then ( continue ) else skip ; var p : double := a + b + c - h - l ; if p < 0 or p > 9 then ( continue ) else skip ; ans := ans + 1)))))))) ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def conv_avacus(num_txt): abacus=['*=****','*=****','*=****','*=****','*=****','*=****','*=****','*=****','*=****','*=****'] ans=[abacus[int(num_txt[4])],abacus[int(num_txt[3])],abacus[int(num_txt[2])],abacus[int(num_txt[1])],abacus[int(num_txt[0])]] return ans def rotate_and_print(data): y_size=len(data) x_size=len(data[0]) A=[['']*y_size for _ in range(x_size)] for i in range(x_size): for j in range(y_size): A[i][j]=data[y_size-1-j][i] for l in A : print(''.join(l)) def main(args): first_case=True for line in sys.stdin : if not first_case : print() num_txt=line.strip().zfill(5) result=conv_avacus(num_txt) rotate_and_print(result) first_case=False if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation conv_avacus(num_txt : OclAny) : OclAny pre: true post: true activity: var abacus : Sequence := Sequence{'*=****'}->union(Sequence{'*=****'}->union(Sequence{'*=****'}->union(Sequence{'*=****'}->union(Sequence{'*=****'}->union(Sequence{'*=****'}->union(Sequence{'*=****'}->union(Sequence{'*=****'}->union(Sequence{'*=****'}->union(Sequence{ '*=****' }))))))))) ; var ans : Sequence := Sequence{abacus[("" + ((num_txt[4+1])))->toInteger()+1]}->union(Sequence{abacus[("" + ((num_txt[3+1])))->toInteger()+1]}->union(Sequence{abacus[("" + ((num_txt[2+1])))->toInteger()+1]}->union(Sequence{abacus[("" + ((num_txt[1+1])))->toInteger()+1]}->union(Sequence{ abacus[("" + ((num_txt->first())))->toInteger()+1] })))) ; return ans; operation rotate_and_print(data : OclAny) pre: true post: true activity: var y_size : int := (data)->size() ; var x_size : int := (data->first())->size() ; var A : Sequence := Integer.subrange(0, x_size-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ '' }, y_size))) ; for i : Integer.subrange(0, x_size-1) do ( for j : Integer.subrange(0, y_size-1) do ( A[i+1][j+1] := data[y_size - 1 - j+1][i+1])) ; for l : A do ( execute (StringLib.sumStringsWithSeparator((l), ''))->display()); operation main(args : OclAny) pre: true post: true activity: var first_case : boolean := true ; for line : OclFile["System.in"] do ( if not(first_case) then ( execute (->display() ) else skip ; num_txt := line->trim().zfill(5) ; var result : OclAny := conv_avacus(num_txt) ; rotate_and_print(result) ; first_case := false); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_input(): while True : try : yield ''.join(input()) except EOFError : break table=["*=****","*=****","*=****","*=****","*=****","*=****","*=****","*=****","*=****","*=****"] N=list(get_input()) for l in range(len(N)): if l>0 : print("") num=int(N[l]) ans=[] for i in range(5): ans.append(table[num//10**(4-i)]) num=num % 10**(4-i) for i in range(8): for j in range(5): print(ans[j][i],end="") print("") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var table : Sequence := Sequence{"*=****"}->union(Sequence{"*=****"}->union(Sequence{"*=****"}->union(Sequence{"*=****"}->union(Sequence{"*=****"}->union(Sequence{"*=****"}->union(Sequence{"*=****"}->union(Sequence{"*=****"}->union(Sequence{"*=****"}->union(Sequence{ "*=****" }))))))))) ; var N : Sequence := (OclIterator.newOclIterator_Function(lambda _i : int in self.get_input(_i))) ; for l : Integer.subrange(0, (N)->size()-1) do ( if l > 0 then ( execute ("")->display() ) else skip ; var num : int := ("" + ((N[l+1])))->toInteger() ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, 5-1) do ( execute ((table[num div (10)->pow((4 - i))+1]) : ans) ; num := num mod (10)->pow((4 - i))) ; for i : Integer.subrange(0, 8-1) do ( for j : Integer.subrange(0, 5-1) do ( execute (ans[j+1][i+1])->display()) ; execute ("")->display())); operation get_input(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; while true do ( try ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return StringLib.sumStringsWithSeparator(((OclFile["System.in"]).readLine()), '')) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys isnewLine=False pattern={"0" : "*=****","1" : "*=****","2" : "*=****","3" : "*=****","4" : "*=****","5" : "*=****","6" : "*=****","7" : "*=****","8" : "*=****","9" : "*=****",} for line in sys.stdin : if isnewLine : print() else : isnewLine=True line=line[:-1] line="0"*(5-len(line))+line bar=[pattern[item]for item in line] for i1,i2,i3,i4,i5 in zip(bar[0],bar[1],bar[2],bar[3],bar[4]): print(i1+i2+i3+i4+i5) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var isnewLine : boolean := false ; var pattern : Map := Map{ "0" |-> "*=****" }->union(Map{ "1" |-> "*=****" }->union(Map{ "2" |-> "*=****" }->union(Map{ "3" |-> "*=****" }->union(Map{ "4" |-> "*=****" }->union(Map{ "5" |-> "*=****" }->union(Map{ "6" |-> "*=****" }->union(Map{ "7" |-> "*=****" }->union(Map{ "8" |-> "*=****" }->union((dictorsetmaker (test (logical_test (comparison (expr (atom "9"))))) : (test (logical_test (comparison (expr (atom "*=****"))))) ,)))))))))) ; for line : OclFile["System.in"] do ( if isnewLine then ( execute (->display() ) else ( isnewLine := true ) ; var line : OclAny := line->front() ; line := StringLib.nCopies("0", (5 - (line)->size())) + line ; var bar : Sequence := line->select(item | true)->collect(item | (pattern[item+1])) ; for _tuple : Integer.subrange(1, bar->first()->size())->collect( _indx | Sequence{bar->first()->at(_indx), bar[1+1]->at(_indx)} ) do (var _indx : int := 1; var i1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i2 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i3 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i4 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i5 : OclAny := _tuple->at(_indx); execute (i1 + i2 + i3 + i4 + i5)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def foo(): return 0 ; def my_rand(): i=0 ; i=(5*foo())+(foo()-5); if(i<22): if(i<0): return(i % 7-7)+1 ; else : return(i % 7)+1 ; return my_rand(); if __name__=='__main__' : print(my_rand()); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( execute (my_rand())->display(); ) else skip; operation foo() pre: true post: true activity: return 0;; operation my_rand() pre: true post: true activity: var i : int := 0; ; i := (5 * foo()) + (foo() - 5); ; if (i < 22) then ( if (i < 0) then ( return (i mod 7 - 7) + 1; ) else ( return (i mod 7) + 1; ) ) else skip ; return my_rand();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- L=["*=****","*=****","*=****","*=****","*=****","*=****","*=****","*=****","*=****","*=****"] c=0 while True : try : num=int(input()) except EOFError : break if c>0 : print() c+=1 str="{:05}".format(num) s=[int(x)for x in list(str)] for i in range(len(L[0])): t=[] for j in range(len(s)): t.append(L[s[j]][i]) print("".join(t)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var L : Sequence := Sequence{"*=****"}->union(Sequence{"*=****"}->union(Sequence{"*=****"}->union(Sequence{"*=****"}->union(Sequence{"*=****"}->union(Sequence{"*=****"}->union(Sequence{"*=****"}->union(Sequence{"*=****"}->union(Sequence{"*=****"}->union(Sequence{ "*=****" }))))))))) ; var c : int := 0 ; while true do ( try ( var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))) ; if c > 0 then ( execute (->display() ) else skip ; c := c + 1 ; var OclType["String"] : String := StringLib.interpolateStrings("{:05}", Sequence{num}) ; var s : Sequence := (OclType["String"])->characters()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for i : Integer.subrange(0, (L->first())->size()-1) do ( var t : Sequence := Sequence{} ; for j : Integer.subrange(0, (s)->size()-1) do ( execute ((L[s[j+1]+1][i+1]) : t)) ; execute (StringLib.sumStringsWithSeparator((t), ""))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- abacus=[['*','*','*','*','*','','','','',''],['','','','','','*','*','*','*','*'],['=','=','=','=','=','=','=','=','=','='],['','*','*','*','*','','*','*','*','*'],['*','','*','*','*','*','','*','*','*'],['*','*','','*','*','*','*','','*','*'],['*','*','*','','*','*','*','*','','*'],['*','*','*','*','','*','*','*','*','']] ans=[['' for c in range(5)]for r in range(8)] first=True while True : try : n=list(input()) except : break for i in range(5-len(n)): for r in range(8): ans[r][i]=abacus[r][0] for i in range(len(n)): for r in range(8): ans[r][5-len(n)+i]=abacus[r][int(n[i])] if first : first=False else : print() for r in range(8): print(*ans[r],sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var abacus : Sequence := Sequence{Sequence{'*'}->union(Sequence{'*'}->union(Sequence{'*'}->union(Sequence{'*'}->union(Sequence{'*'}->union(Sequence{''}->union(Sequence{''}->union(Sequence{''}->union(Sequence{''}->union(Sequence{ '' })))))))))}->union(Sequence{Sequence{''}->union(Sequence{''}->union(Sequence{''}->union(Sequence{''}->union(Sequence{''}->union(Sequence{'*'}->union(Sequence{'*'}->union(Sequence{'*'}->union(Sequence{'*'}->union(Sequence{ '*' })))))))))}->union(Sequence{Sequence{'='}->union(Sequence{'='}->union(Sequence{'='}->union(Sequence{'='}->union(Sequence{'='}->union(Sequence{'='}->union(Sequence{'='}->union(Sequence{'='}->union(Sequence{'='}->union(Sequence{ '=' })))))))))}->union(Sequence{Sequence{''}->union(Sequence{'*'}->union(Sequence{'*'}->union(Sequence{'*'}->union(Sequence{'*'}->union(Sequence{''}->union(Sequence{'*'}->union(Sequence{'*'}->union(Sequence{'*'}->union(Sequence{ '*' })))))))))}->union(Sequence{Sequence{'*'}->union(Sequence{''}->union(Sequence{'*'}->union(Sequence{'*'}->union(Sequence{'*'}->union(Sequence{'*'}->union(Sequence{''}->union(Sequence{'*'}->union(Sequence{'*'}->union(Sequence{ '*' })))))))))}->union(Sequence{Sequence{'*'}->union(Sequence{'*'}->union(Sequence{''}->union(Sequence{'*'}->union(Sequence{'*'}->union(Sequence{'*'}->union(Sequence{'*'}->union(Sequence{''}->union(Sequence{'*'}->union(Sequence{ '*' })))))))))}->union(Sequence{Sequence{'*'}->union(Sequence{'*'}->union(Sequence{'*'}->union(Sequence{''}->union(Sequence{'*'}->union(Sequence{'*'}->union(Sequence{'*'}->union(Sequence{'*'}->union(Sequence{''}->union(Sequence{ '*' })))))))))}->union(Sequence{ Sequence{'*'}->union(Sequence{'*'}->union(Sequence{'*'}->union(Sequence{'*'}->union(Sequence{''}->union(Sequence{'*'}->union(Sequence{'*'}->union(Sequence{'*'}->union(Sequence{'*'}->union(Sequence{ '' }))))))))) }))))))) ; var ans : Sequence := Integer.subrange(0, 8-1)->select(r | true)->collect(r | (Integer.subrange(0, 5-1)->select(c | true)->collect(c | ('')))) ; var first : boolean := true ; while true do ( try ( var n : Sequence := ((OclFile["System.in"]).readLine())->characters()) catch (_e : OclException) do ( break) ; for i : Integer.subrange(0, 5 - (n)->size()-1) do ( for r : Integer.subrange(0, 8-1) do ( ans[r+1][i+1] := abacus[r+1]->first())) ; for i : Integer.subrange(0, (n)->size()-1) do ( for r : Integer.subrange(0, 8-1) do ( ans[r+1][5 - (n)->size() + i+1] := abacus[r+1][("" + ((n[i+1])))->toInteger()+1])) ; if first then ( first := false ) else ( execute (->display() ) ; for r : Integer.subrange(0, 8-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ]))))))))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def xorGivenSetBits(arr,n,k): v=[] for i in range(0,n,1): if(bin(arr[i]).count('1')==k): v.append(arr[i]) result=v[0] for i in range(1,len(v),1): result=result ^ v[i] return result if __name__=='__main__' : arr=[2,13,1,19,7] n=len(arr) k=3 print(xorGivenSetBits(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{2}->union(Sequence{13}->union(Sequence{1}->union(Sequence{19}->union(Sequence{ 7 })))) ; n := (arr)->size() ; k := 3 ; execute (xorGivenSetBits(arr, n, k))->display() ) else skip; operation xorGivenSetBits(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var v : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (bin(arr[i+1])->count('1') = k) then ( execute ((arr[i+1]) : v) ) else skip) ; var result : OclAny := v->first() ; for i : Integer.subrange(1, (v)->size()-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( result := MathLib.bitwiseXor(result, v[i+1])) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k,n,s,p=map(int,input().split()) sheets_per_person=(n+s-1)//s sheets=k*sheets_per_person print((sheets+p-1)//p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : OclAny := null; var n : OclAny := null; var s : OclAny := null; var p : OclAny := null; Sequence{k,n,s,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sheets_per_person : int := (n + s - 1) div s ; var sheets : double := k * sheets_per_person ; execute ((sheets + p - 1) div p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (people,airplanes_each_people_make,airplanes_in_1_sheets,sheets_in_1_pack)=map(int,input().split(' ')) if airplanes_in_1_sheets>=airplanes_each_people_make : total_needed_sheets=people if total_needed_sheets % sheets_in_1_pack==0 : print(total_needed_sheets//sheets_in_1_pack) else : print(total_needed_sheets//sheets_in_1_pack+1) else : if airplanes_each_people_make % airplanes_in_1_sheets==0 : total_needed_sheets=airplanes_each_people_make//airplanes_in_1_sheets*people if total_needed_sheets % sheets_in_1_pack==0 : print(total_needed_sheets//sheets_in_1_pack) else : print(total_needed_sheets//sheets_in_1_pack+1) else : total_needed_sheets=(airplanes_each_people_make//airplanes_in_1_sheets+1)*people if total_needed_sheets % sheets_in_1_pack==0 : print(total_needed_sheets//sheets_in_1_pack) else : print(total_needed_sheets//sheets_in_1_pack+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{people, airplanes_each_people_make, airplanes_inairplanes_each_people_make_sheets, sheets_inairplanes_inairplanes_each_people_make_sheets_pack} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; if (airplanes_in var Sequence{people, airplanes_each_people_make, airplanes_inairplanes_each_people_make_sheets, sheets_inairplanes_inairplanes_each_people_make_sheets_pack} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )_sheets->compareTo(airplanes_each_people_make)) >= 0 then ( var total_needed_sheets : OclAny := people ; if total_needed_sheets mod sheets_in var total_needed_sheets : OclAny := people_pack = 0 then ( execute (total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in var total_needed_sheets : OclAny := people_pack)_pack)_pack_pack)->display()_pack)_pack)_pack_pack)->display()_pack)_pack)_pack_pack)->display()_pack)_pack)_pack_pack)->display()_pack)_pack)_pack_pack)->display()_pack)_pack)_pack_pack)->display()_pack)_pack)_pack_pack)->display() ) else ( execute (total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in var total_needed_sheets : OclAny := people_pack + 1)_pack + 1)_pack + 1_pack + 1)->display()_pack + 1)_pack + 1)_pack + 1_pack + 1)->display()_pack + 1)_pack + 1)_pack + 1_pack + 1)->display()_pack + 1)_pack + 1)_pack + 1_pack + 1)->display()_pack + 1)_pack + 1)_pack + 1_pack + 1)->display()_pack + 1)_pack + 1)_pack + 1_pack + 1)->display()_pack + 1)_pack + 1)_pack + 1_pack + 1)->display() ) ) else ( if airplanes_each_people_make mod airplanes_in var Sequence{people, airplanes_each_people_make, airplanes_inairplanes_each_people_make_sheets, sheets_inairplanes_inairplanes_each_people_make_sheets_pack} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )_sheets = 0 then ( total_needed_sheets := airplanes_each_people_make div airplanes_in var Sequence{people, airplanes_each_people_make, airplanes_inairplanes_each_people_make_sheets, sheets_inairplanes_inairplanes_each_people_make_sheets_pack} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )_sheets * people ; if total_needed_sheets mod sheets_in total_needed_sheets := airplanes_each_people_make div airplanes_in var Sequence{people, airplanes_each_people_make, airplanes_inairplanes_each_people_make_sheets, sheets_inairplanes_inairplanes_each_people_make_sheets_pack} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )_sheets * people_pack = 0 then ( execute (total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in total_needed_sheets := airplanes_each_people_make div airplanes_in var Sequence{people, airplanes_each_people_make, airplanes_inairplanes_each_people_make_sheets, sheets_inairplanes_inairplanes_each_people_make_sheets_pack} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )_sheets * people_pack)_pack)_pack_pack)->display()_pack)_pack)_pack_pack)->display()_pack)_pack)_pack_pack)->display()_pack)_pack)_pack_pack)->display()_pack)_pack)_pack_pack)->display()_pack)_pack)_pack_pack)->display()_pack)_pack)_pack_pack)->display() ) else ( execute (total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in total_needed_sheets := airplanes_each_people_make div airplanes_in var Sequence{people, airplanes_each_people_make, airplanes_inairplanes_each_people_make_sheets, sheets_inairplanes_inairplanes_each_people_make_sheets_pack} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )_sheets * people_pack + 1)_pack + 1)_pack + 1_pack + 1)->display()_pack + 1)_pack + 1)_pack + 1_pack + 1)->display()_pack + 1)_pack + 1)_pack + 1_pack + 1)->display()_pack + 1)_pack + 1)_pack + 1_pack + 1)->display()_pack + 1)_pack + 1)_pack + 1_pack + 1)->display()_pack + 1)_pack + 1)_pack + 1_pack + 1)->display()_pack + 1)_pack + 1)_pack + 1_pack + 1)->display() ) ) else ( total_needed_sheets := (airplanes_each_people_make div airplanes_in var Sequence{people, airplanes_each_people_make, airplanes_inairplanes_each_people_make_sheets, sheets_inairplanes_inairplanes_each_people_make_sheets_pack} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )_sheets + 1) * people ; if total_needed_sheets mod sheets_in total_needed_sheets := (airplanes_each_people_make div airplanes_in var Sequence{people, airplanes_each_people_make, airplanes_inairplanes_each_people_make_sheets, sheets_inairplanes_inairplanes_each_people_make_sheets_pack} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )_sheets + 1) * people_pack = 0 then ( execute (total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in total_needed_sheets := (airplanes_each_people_make div airplanes_in var Sequence{people, airplanes_each_people_make, airplanes_inairplanes_each_people_make_sheets, sheets_inairplanes_inairplanes_each_people_make_sheets_pack} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )_sheets + 1) * people_pack)_pack)_pack_pack)->display()_pack)_pack)_pack_pack)->display()_pack)_pack)_pack_pack)->display()_pack)_pack)_pack_pack)->display()_pack)_pack)_pack_pack)->display()_pack)_pack)_pack_pack)->display()_pack)_pack)_pack_pack)->display() ) else ( execute (total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_intotal_needed_sheets div sheets_in(total_needed_sheets div sheets_in(total_needed_sheets div sheets_in total_needed_sheets := (airplanes_each_people_make div airplanes_in var Sequence{people, airplanes_each_people_make, airplanes_inairplanes_each_people_make_sheets, sheets_inairplanes_inairplanes_each_people_make_sheets_pack} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )_sheets + 1) * people_pack + 1)_pack + 1)_pack + 1_pack + 1)->display()_pack + 1)_pack + 1)_pack + 1_pack + 1)->display()_pack + 1)_pack + 1)_pack + 1_pack + 1)->display()_pack + 1)_pack + 1)_pack + 1_pack + 1)->display()_pack + 1)_pack + 1)_pack + 1_pack + 1)->display()_pack + 1)_pack + 1)_pack + 1_pack + 1)->display()_pack + 1)_pack + 1)_pack + 1_pack + 1)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) print((N-N//2)/N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((N - N div 2) / N)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k,n,s,p=map(int,input().split()) print(-(-n//s*k//p)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : OclAny := null; var n : OclAny := null; var s : OclAny := null; var p : OclAny := null; Sequence{k,n,s,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (-(-n div s * k div p))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil k,n,s,p=map(int,input().split()) def paper_packs(people,planes_foreach,planes_from_sheet,sheets_in_pack): sheets_foreach=int(ceil(planes_foreach/planes_from_sheet)) sheets_needed=sheets_foreach*people packs_needed=int(ceil(sheets_needed/sheets_in_pack)) return packs_needed print(paper_packs(k,n,s,p)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var k : OclAny := null; var n : OclAny := null; var s : OclAny := null; var p : OclAny := null; Sequence{k,n,s,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; execute (paper_packs(k, n, s, p))->display(); operation paper_packs(people : OclAny, planes_foreach : OclAny, planes_from_sheet : OclAny, sheets_in_pack : OclAny) : OclAny pre: true post: true activity: var sheets_foreach : int := ("" + ((ceil(planes_foreach / planes_from_sheet))))->toInteger() ; var sheets_needed : double := sheets_foreach * people ; var packs_needed : int := ("" + ((ceil(sheets_needed / sheets_in_pack))))->toInteger() ; return packs_needed; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def solution(k,n,s,p): first_ceil=math.ceil(n/s) second_ceil=math.ceil((first_ceil*k)/p) return second_ceil k,n,s,p=[int(x)for x in input().strip().split(" ")] print(solution(k,n,s,p)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{k,n,s,p} := input()->trim().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (solution(k, n, s, p))->display(); operation solution(k : OclAny, n : OclAny, s : OclAny, p : OclAny) : OclAny pre: true post: true activity: var first_ceil : double := (n / s)->ceil() ; var second_ceil : double := ((first_ceil * k) / p)->ceil() ; return second_ceil; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isSquare(num): root=int(num**(1/2)) return(root*root)==num def isCube(num): root=int(num**(1/3)) return(root*root*root)==num def countSC(N): count=0 for i in range(1,N+1): if isSquare(i): count+=1 elif isCube(i): count+=1 return count if __name__=="__main__" : N=20 print("Number of squares and cubes is ",countSC(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( N := 20 ; execute ("Number of squares and cubes is ")->display() ) else skip; operation isSquare(num : OclAny) : OclAny pre: true post: true activity: var root : int := ("" + (((num)->pow((1 / 2)))))->toInteger() ; return (root * root) = num; operation isCube(num : OclAny) : OclAny pre: true post: true activity: root := ("" + (((num)->pow((1 / 3)))))->toInteger() ; return (root * root * root) = num; operation countSC(N : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(1, N + 1-1) do ( if isSquare(i) then ( count := count + 1 ) else (if isCube(i) then ( count := count + 1 ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from operator import itemgetter from itertools import chain N=int(input()) L=[] R=[] for i in range(N): S=input() low=0 var=0 for s in S : if s=='(' : var+=1 else : var-=1 low=min(low,var) if var>=0 : L.append((low,var)) else : R.append((low,var)) L.sort(key=itemgetter(0),reverse=True) R.sort(key=lambda x : x[0]-x[1]) pos=0 for i,(low,var)in enumerate(chain(L,R)): if pos+low<0 : ans='No' break pos+=var else : ans='Yes' if pos==0 else 'No' print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var L : Sequence := Sequence{} ; var R : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var S : String := (OclFile["System.in"]).readLine() ; var low : int := 0 ; var var : int := 0 ; for s : S->characters() do ( if s = '(' then ( var := var + 1 ) else ( var := var - 1 ) ; low := Set{low, var}->min()) ; if var >= 0 then ( execute ((Sequence{low, var}) : L) ) else ( execute ((Sequence{low, var}) : R) )) ; L := L->sort() ; R := R->sort() ; var pos : int := 0 ; (compound_stmt for (exprlist (expr (atom (name i))) , (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name low)))))) , (test (logical_test (comparison (expr (atom (name var))))))) )))) in (testlist (test (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name chain)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L))))))) , (argument (test (logical_test (comparison (expr (atom (name R)))))))) ))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name pos))) + (expr (atom (name low))))) < (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom 'No'))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name pos)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name var)))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom 'Yes')))) if (logical_test (comparison (comparison (expr (atom (name pos)))) == (comparison (expr (atom (number (integer 0))))))) else (test (logical_test (comparison (expr (atom 'No'))))))))))))))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(lis,N): x=(lis[0][0]+lis[N//2][0]) y=(lis[0][1]+lis[N//2][1]) for i in range(1,N//2): if(lis[i][0]+lis[i+N//2][0])!=x or(lis[i][1]+lis[i+N//2][1])!=y : return "NA" return str(x/2)+" "+str(y/2) N=int(input()) if N % 2==1 : print("NA") else : lis=[] for i in range(N): lis.append(tuple(map(int,input().split()))) ans=solve(lis,N) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N mod 2 = 1 then ( execute ("NA")->display() ) else ( lis := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : lis)) ; var ans : OclAny := solve(lis, N) ; execute (ans)->display() ); operation solve(lis : OclAny, N : OclAny) : OclAny pre: true post: true activity: var x : OclAny := (lis->first()->first() + lis[N div 2+1]->first()) ; var y : OclAny := (lis->first()[1+1] + lis[N div 2+1][1+1]) ; for i : Integer.subrange(1, N div 2-1) do ( if (lis[i+1]->first() + lis[i + N div 2+1]->first()) /= x or (lis[i+1][1+1] + lis[i + N div 2+1][1+1]) /= y then ( return "NA" ) else skip) ; return ("" + ((x / 2))) + " " + ("" + ((y / 2))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(): N=int(input()) plus,minus=[],[] for i in range(N): S=input() now=0 mini=0 for s in S : if s=='(' : now+=1 else : now-=1 mini=min(mini,now) if now>=0 : plus.append([mini,now]) else : minus.append([now-mini,now]) plus.sort(reverse=True) minus.sort(reverse=True) now=0 for a,b in plus : if now+a<0 : return 'No' now+=b for a,b in minus : if now+b-a<0 : return 'No' now+=b if now>0 : return 'No' return 'Yes' print(check()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (check())->display(); operation check() : OclAny pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var plus : OclAny := null; var minus : OclAny := null; Sequence{plus,minus} := Sequence{Sequence{},Sequence{}} ; for i : Integer.subrange(0, N-1) do ( var S : String := (OclFile["System.in"]).readLine() ; var now : int := 0 ; var mini : int := 0 ; for s : S->characters() do ( if s = '(' then ( now := now + 1 ) else ( now := now - 1 ; mini := Set{mini, now}->min() )) ; if now >= 0 then ( execute ((Sequence{mini}->union(Sequence{ now })) : plus) ) else ( execute ((Sequence{now - mini}->union(Sequence{ now })) : minus) )) ; plus := plus->sort() ; minus := minus->sort() ; now := 0 ; for _tuple : plus do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if now + a < 0 then ( return 'No' ) else skip ; now := now + b) ; for _tuple : minus do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if now + b - a < 0 then ( return 'No' ) else skip ; now := now + b) ; if now > 0 then ( return 'No' ) else skip ; return 'Yes'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def count_scan(s): max_min=0 compare=0 for c in s : if c=='(' : compare+=1 elif c==')' : compare-=1 max_min=min(max_min,compare) return min(max_min,compare),compare def key(lst): m,c=lst if c>0 : return 1,m else : return-1,c-m def main(): n=int(input()) lst=[input()for _ in range(n)] txt='No' ans=0 for max_min,c in sorted([count_scan(s)for s in lst],reverse=True,key=key): if max_min+ans<0 : break ans+=c else : if ans==0 : txt='Yes' print(txt) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation count_scan(s : OclAny) : OclAny pre: true post: true activity: var max_min : int := 0 ; var compare : int := 0 ; for c : s do ( if c = '(' then ( compare := compare + 1 ) else (if c = ')' then ( compare := compare - 1 ; max_min := Set{max_min, compare}->min() ) else skip)) ; return Set{max_min, compare}->min(), compare; operation key(lst : OclAny) : OclAny pre: true post: true activity: var m : OclAny := null; var c : OclAny := null; Sequence{m,c} := lst ; if c > 0 then ( return 1, m ) else ( return -1, c - m ); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; lst := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var txt : String := 'No' ; var ans : int := 0 ; (compound_stmt for (exprlist (expr (atom (name max_min))) , (expr (atom (name c)))) in (testlist (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name count_scan)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name lst))))))) ])))))) , (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True))))))) , (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name key)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name max_min))) + (expr (atom (name ans))))) < (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name c)))))))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name ans)))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name txt)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom 'Yes'))))))))))))))))) ; execute (txt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) left=[] right=[] last=None for i in range(N): s=input() l=len(s) r_needed=0 l_needed=0 for j in range(l): if s[j]=="(" : r_needed+=1 elif s[j]==")" and r_needed>0 : r_needed-=1 if s[l-1-j]==")" : l_needed+=1 elif s[l-1-j]=="(" and l_needed>0 : l_needed-=1 if r_neededtoInteger() ; var left : Sequence := Sequence{} ; var right : Sequence := Sequence{} ; var last : OclAny := null ; for i : Integer.subrange(0, N-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var l : int := (s)->size() ; var r_needed : int := 0 ; var l_needed : int := 0 ; for j : Integer.subrange(0, l-1) do ( if s[j+1] = "(" then ( r_needed := r_needed + 1 ) else (if s[j+1] = ")" & r_needed > 0 then ( r_needed := r_needed - 1 ) else skip) ; if s[l - 1 - j+1] = ")" then ( l_needed := l_needed + 1 ) else (if s[l - 1 - j+1] = "(" & l_needed > 0 then ( l_needed := l_needed - 1 ) else skip)) ; if (r_needed->compareTo(l_needed)) < 0 then ( execute ((Sequence{-r_needed, l_needed}) : right) ) else ( execute ((Sequence{l_needed, -r_needed}) : left) )) ; left := left->sort() ; right := right->sort() ; var rest_l : int := 0 ; for l : left do ( l_needed := l->first() ; r_needed := -l[1+1] ; if (rest_l->compareTo(l_needed)) < 0 then ( execute ("No")->display() ; exit() ) else skip ; rest_l := rest_l + r_needed - l_needed) ; for r : right do ( l_needed := r[1+1] ; r_needed := -r->first() ; if (rest_l->compareTo(l_needed)) < 0 then ( execute ("No")->display() ; exit() ) else skip ; rest_l := rest_l - l_needed ; rest_l := rest_l + r_needed) ; if rest_l /= 0 then ( execute ("No")->display() ) else ( execute ("Yes")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) cnt=[] for i in range(n): s=input().rstrip() l=s.count("(") r=s.count(")") minus=0 now=0 for j in range(len(s)): if s[j]=="(" : now+=1 else : now-=1 minus=min(minus,now) cnt.append((l,r,s,minus)) cnt.sort(key=lambda x : x[1]-x[0]) plus=[] minus=[] first=[] for x in cnt : if x[3]>=0 : first.append(x) elif x[0]-x[1]>0 : plus.append(x) else : minus.append(x) plus.sort(key=lambda x :-x[3]) minus.sort(key=lambda x :-(x[0]-x[1]-x[3])) l=r=0 for x in first+plus+minus : for i in range(len(x[2])): if x[2][i]=="(" : l+=1 else : r+=1 if ltoInteger() ; var cnt : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var s : OclAny := input().rstrip() ; var l : int := s->count("(") ; var r : int := s->count(")") ; var minus : int := 0 ; var now : int := 0 ; for j : Integer.subrange(0, (s)->size()-1) do ( if s[j+1] = "(" then ( now := now + 1 ) else ( now := now - 1 ; minus := Set{minus, now}->min() )) ; execute ((Sequence{l, r, s, minus}) : cnt)) ; cnt := cnt->sort() ; var plus : Sequence := Sequence{} ; minus := Sequence{} ; var first : Sequence := Sequence{} ; for x : cnt do ( if x[3+1] >= 0 then ( execute ((x) : first) ) else (if x->first() - x[1+1] > 0 then ( execute ((x) : plus) ) else ( execute ((x) : minus) ) ) ) ; plus := plus->sort() ; minus := minus->sort() ; l := 0; r := 0 ; for x : MatrixLib.elementwiseAdd(first->union(plus), minus) do ( for i : Integer.subrange(0, (x[2+1])->size()-1) do ( if x[2+1][i+1] = "(" then ( l := l + 1 ) else ( r := r + 1 ) ; if (l->compareTo(r)) < 0 then ( execute ("No")->display() ; exit() ) else skip)) ; if l = r then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) odds=0 for i in range(N): if(i+1)% 2==0 : continue else : odds=odds+1 print(float(odds)/float(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var odds : int := 0 ; for i : Integer.subrange(0, N-1) do ( if (i + 1) mod 2 = 0 then ( continue ) else ( odds := odds + 1 )) ; execute (("" + ((odds)))->toReal() / ("" + ((N)))->toReal())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countDe(arr,n): i=0 v=arr.copy() arr.sort() count1=0 i=0 while(itoInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sum_A : double := (A->first())->abs() ; for i : Integer.subrange(1, N-1) do ( sum_A := sum_A + (A[i - 1+1] - A[i+1])->abs()) ; sum_A := sum_A + (A[N - 1+1])->abs() ; for i : Integer.subrange(0, N-1) do ( if i = 0 then ( execute (sum_A - (A->first())->abs() - (A[1+1] - A->first())->abs() + (A[1+1])->abs())->display() ) else (if i = N - 1 then ( execute (sum_A - (A[N - 1+1] - A[N - 2+1])->abs() - (A[N - 1+1])->abs() + (A[N - 2+1])->abs())->display() ) else ( execute (sum_A - (A[i+1] - A[i - 1+1])->abs() - (A[i + 1+1] - A[i+1])->abs() + (A[i + 1+1] - A[i - 1+1])->abs())->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(1<<25) read=sys.stdin.readline ra=range enu=enumerate def mina(*argv,sub=1): return list(map(lambda x : x-sub,argv)) def a_int(): return int(read()) def ints(): return list(map(int,read().split())) def read_col(H): ret=[] for _ in range(H): ret.append(list(map(int,read().split()))) return tuple(map(list,zip(*ret))) def read_tuple(H): ret=[] for _ in range(H): ret.append(tuple(map(int,read().split()))) return ret def read_matrix(H): ret=[] for _ in range(H): ret.append(list(map(int,read().split()))) return ret MOD=10**9+7 INF=2**31 from collections import defaultdict,Counter,deque from operator import itemgetter,xor,add from itertools import product,permutations,combinations from bisect import bisect_left,bisect_right from functools import reduce N=a_int() A=[0]+ints()+[0] d_nx=[abs(x-y)for x,y in zip(A,A[1 :])] d_nnx=[abs(x-y)for x,y in zip(A,A[2 :])] total=sum(d_nx) ans=[] for i in range(N): ans.append(total-(d_nx[i]+d_nx[i+1])+d_nnx[i]) print(*ans,sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(1 * (2->pow(25))) ; var read : OclAny := (OclFile["System.in"]).readline ; var ra : OclAny := range ; var enu : OclAny := enumerate ; skip ; skip ; skip ; skip ; skip ; skip ; var MOD : double := (10)->pow(9) + 7 ; var INF : double := (2)->pow(31) ; skip ; skip ; skip ; skip ; skip ; var N : OclAny := a_int() ; var A : Sequence := Sequence{ 0 }->union(ints())->union(Sequence{ 0 }) ; var d_nx : Sequence := Integer.subrange(1, A->size())->collect( _indx | Sequence{A->at(_indx), A->tail()->at(_indx)} )->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in ((x - y)->abs())) ; var d_nnx : Sequence := Integer.subrange(1, A->size())->collect( _indx | Sequence{A->at(_indx), A.subrange(2+1)->at(_indx)} )->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in ((x - y)->abs())) ; var total : OclAny := (d_nx)->sum() ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute ((total - (d_nx[i+1] + d_nx[i + 1+1]) + d_nnx[i+1]) : ans)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); operation mina(argv : OclAny : Sequence(OclAny), sub : int) : OclAny pre: true post: true activity: (args * (named_parameter (name argv))) if sub->oclIsUndefined() then sub := 1 else skip; return ((argv)->collect( _x | (lambda x : OclAny in (x - sub))->apply(_x) )); operation a_int() : OclAny pre: true post: true activity: return ("" + ((read())))->toInteger(); operation ints() : OclAny pre: true post: true activity: return ((read().split())->collect( _x | (OclType["int"])->apply(_x) )); operation read_col(H : OclAny) : OclAny pre: true post: true activity: var ret : Sequence := Sequence{} ; for _anon : Integer.subrange(0, H-1) do ( execute ((((read().split())->collect( _x | (OclType["int"])->apply(_x) ))) : ret)) ; return ((Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name ret)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name ret)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name ret)))))))`third->at(_indx)} ))->collect( _x | (OclType["Sequence"])->apply(_x) )); operation read_tuple(H : OclAny) : OclAny pre: true post: true activity: ret := Sequence{} ; for _anon : Integer.subrange(0, H-1) do ( execute ((((read().split())->collect( _x | (OclType["int"])->apply(_x) ))) : ret)) ; return ret; operation read_matrix(H : OclAny) : OclAny pre: true post: true activity: ret := Sequence{} ; for _anon : Integer.subrange(0, H-1) do ( execute ((((read().split())->collect( _x | (OclType["int"])->apply(_x) ))) : ret)) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import deque,defaultdict from math import sqrt,factorial,gcd def solve(): n=int(input()) a=[0]+[int(x)for x in input().split()]+[0] sm=0 for i in range(n+1): sm+=abs(a[i]-a[i+1]) for i in range(n): x=abs(a[i]-a[i+2])-(abs(a[i]-a[i+1])+abs(a[i+2]-a[i+1])) print(sm+x) t=1 for case in range(1,t+1): ans=solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var t : int := 1 ; for case : Integer.subrange(1, t + 1-1) do ( var ans : OclAny := solve()); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{ 0 }->union(input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))->union(Sequence{ 0 }) ; var sm : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( sm := sm + (a[i+1] - a[i + 1+1])->abs()) ; for i : Integer.subrange(0, n-1) do ( var x : double := (a[i+1] - a[i + 2+1])->abs() - ((a[i+1] - a[i + 1+1])->abs() + (a[i + 2+1] - a[i + 1+1])->abs()) ; execute (sm + x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,*alst=map(int,open(0).read().split()) alst+=[0] s=abs(alst[0])+sum(abs(alst[i]-alst[i+1])for i in range(n)) print(s+abs(alst[1])-(abs(alst[0])+abs(alst[0]-alst[1]))) for i in range(1,n): print(s+abs(alst[i-1]-alst[i+1])-(abs(alst[i-1]-alst[i])+abs(alst[i]-alst[i+1]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var alst : OclAny := null; Sequence{n,alst} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; alst := alst + Sequence{ 0 } ; var s : double := (alst->first())->abs() + ((argument (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name alst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name alst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->sum() ; execute (s + (alst[1+1])->abs() - ((alst->first())->abs() + (alst->first() - alst[1+1])->abs()))->display() ; for i : Integer.subrange(1, n-1) do ( execute (s + (alst[i - 1+1] - alst[i + 1+1])->abs() - ((alst[i - 1+1] - alst[i+1])->abs() + (alst[i+1] - alst[i + 1+1])->abs()))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.readline().strip() def resolve(): n=int(input()) l=[0]+list(map(int,input().split()))+[0] max=0 for i in range(n+1): max+=abs(l[i+1]-l[i]) for j in range(1,n+1): if l[j-1]l[j]>l[j+1]: print(max) else : x=abs(l[j+1]-l[j]) y=abs(l[j]-l[j-1]) z=abs(l[j+1]-l[j-1]) print(max-x-y+z) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; resolve(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation resolve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->union(Sequence{ 0 }) ; var max : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( max := max + (l[i + 1+1] - l[i+1])->abs()) ; for j : Integer.subrange(1, n + 1-1) do ( if (l[j - 1+1]->compareTo(l[j+1])) < 0 & (l[j+1] < l[j + 1+1]) or (l[j - 1+1]->compareTo(l[j+1])) > 0 & (l[j+1] > l[j + 1+1]) then ( execute (max)->display() ) else ( var x : double := (l[j + 1+1] - l[j+1])->abs() ; var y : double := (l[j+1] - l[j - 1+1])->abs() ; var z : double := (l[j + 1+1] - l[j - 1+1])->abs() ; execute (max - x - y + z)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- eps=0.0001 n=int(input()) x_sum=0 y_sum=0 data=[] for i in range(n): x,y=map(int,input().split()) x_sum+=x y_sum+=y data.append((x,y)) x_sum/=n y_sum/=n if n % 2!=0 : print('NA') exit() for i in range(n//2): if abs(((data[i][0]-x_sum)**2+(data[i][1]-y_sum)**2)**0.5-((data[i+n//2][0]-x_sum)**2+(data[i+n//2][1]-y_sum)**2)**0.5)<=eps : pass else : print('NA') exit() print(x_sum,y_sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var eps : double := 0.0001 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x_sum : int := 0 ; var y_sum : int := 0 ; var data : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; x_sum := x_sum + x ; y_sum := y_sum + y ; execute ((Sequence{x, y}) : data)) ; x_sum := x_sum / n ; y_sum := y_sum / n ; if n mod 2 /= 0 then ( execute ('NA')->display() ; exit() ) else skip ; for i : Integer.subrange(0, n div 2-1) do ( if ((((((data[i+1]->first() - x_sum))->pow(2) + ((data[i+1][1+1] - y_sum))->pow(2)))->pow(0.5) - ((((data[i + n div 2+1]->first() - x_sum))->pow(2) + ((data[i + n div 2+1][1+1] - y_sum))->pow(2)))->pow(0.5))->abs()->compareTo(eps)) <= 0 then ( skip ) else ( execute ('NA')->display() ; exit() )) ; execute (x_sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def orgazineInOrder(vec,op,n): result=[0]*n ; vec.sort(); i=0 ; j=n-1 ; k=0 ; while(i<=j and k<=n-2): if(op[k]=='<'): result[k]=vec[i]; i+=1 ; else : result[k]=vec[j]; j-=1 ; k+=1 ; result[n-1]=vec[i]; return result ; if __name__=="__main__" : vec=[8,2,7,1,5,9]; op=['>','>','<','>','<']; result=orgazineInOrder(vec,op,len(vec)); for i in range(len(result)): print(result[i],end=" "); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( vec := Sequence{8}->union(Sequence{2}->union(Sequence{7}->union(Sequence{1}->union(Sequence{5}->union(Sequence{ 9 }))))); ; op := Sequence{'>'}->union(Sequence{'>'}->union(Sequence{'<'}->union(Sequence{'>'}->union(Sequence{ '<' })))); ; result := orgazineInOrder(vec, op, (vec)->size()); ; for i : Integer.subrange(0, (result)->size()-1) do ( execute (result[i+1])->display();) ) else skip; operation orgazineInOrder(vec : OclAny, op : OclAny, n : OclAny) pre: true post: true activity: var result : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; vec := vec->sort(); ; var i : int := 0; ; var j : double := n - 1; ; var k : int := 0; ; while ((i->compareTo(j)) <= 0 & (k->compareTo(n - 2)) <= 0) do ( if (op[k+1] = '<') then ( result[k+1] := vec[i+1]; ; i := i + 1; ) else ( result[k+1] := vec[j+1]; ; j := j - 1; ) ; k := k + 1;) ; result[n - 1+1] := vec[i+1]; ; return result;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPossible(arr,n,dist,k): req=0 curr=0 prev=0 for i in range(0,n): while(curr!=n and(arr[curr]-arr[prev])<=dist): curr=curr+1 req=req+1 if(curr==n): break prev=curr-1 if(curr!=n): return False if(req<=k): return True return False def minDistance(arr,n,k): l=0 h=arr[n-1] ans=0 while(l<=h): m=(l+h)//2 ; if(isPossible(arr,n,m,k)): ans=m h=m-1 else : l=m+1 return ans arr=[2,15,36,43] n=len(arr) k=2 print(minDistance(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{2}->union(Sequence{15}->union(Sequence{36}->union(Sequence{ 43 }))) ; n := (arr)->size() ; k := 2 ; execute (minDistance(arr, n, k))->display(); operation isPossible(arr : OclAny, n : OclAny, dist : OclAny, k : OclAny) : OclAny pre: true post: true activity: var req : int := 0 ; var curr : int := 0 ; var prev : int := 0 ; for i : Integer.subrange(0, n-1) do ( while (curr /= n & ((arr[curr+1] - arr[prev+1])->compareTo(dist)) <= 0) do ( curr := curr + 1) ; req := req + 1 ; if (curr = n) then ( break ) else skip ; prev := curr - 1) ; if (curr /= n) then ( return false ) else skip ; if ((req->compareTo(k)) <= 0) then ( return true ) else skip ; return false; operation minDistance(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var l : int := 0 ; var h : OclAny := arr[n - 1+1] ; var ans : int := 0 ; while ((l->compareTo(h)) <= 0) do ( var m : int := (l + h) div 2; ; if (isPossible(arr, n, m, k)) then ( ans := m ; h := m - 1 ) else ( l := m + 1 )) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=map(int,input().split()) if abs(a-c)<=d : print("Yes") else : if(abs(a-b)<=d)and(abs(b-c)<=d): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if ((a - c)->abs()->compareTo(d)) <= 0 then ( execute ("Yes")->display() ) else ( if (((a - b)->abs()->compareTo(d)) <= 0) & (((b - c)->abs()->compareTo(d)) <= 0) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for testcase in range(t): n=int(input()) s=input() lef,rig,sw=1,1,0 for i in range(n-1): if(s[i]>s[i+1]): sw=1 break if(sw==0): print(s) continue for i in range(n): if(s[i]=='1'): lef=i break for i in range(n-1,0,-1): if(s[i]=='0'): rig=i break st=s[: lef]+'0'+s[rig+1 :] print(st) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for testcase : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var lef : OclAny := null; var rig : OclAny := null; var sw : OclAny := null; Sequence{lef,rig,sw} := Sequence{1,1,0} ; for i : Integer.subrange(0, n - 1-1) do ( if ((s[i+1]->compareTo(s[i + 1+1])) > 0) then ( var sw : int := 1 ; break ) else skip) ; if (sw = 0) then ( execute (s)->display() ; continue ) else skip ; for i : Integer.subrange(0, n-1) do ( if (s[i+1] = '1') then ( var lef : OclAny := i ; break ) else skip) ; for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( if (s[i+1] = '0') then ( var rig : OclAny := i ; break ) else skip) ; var st : OclAny := s.subrange(1,lef) + '0' + s.subrange(rig + 1+1) ; execute (st)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INT=lambda : int(input()) INTM=lambda : map(int,input().split()) STRM=lambda : map(str,input().split()) STR=lambda : str(input()) LIST=lambda : list(map(int,input().split())) LISTS=lambda : list(map(str,input().split())) def do(): a,b,c,d=INTM() if(a-d<=c<=a+d)or(a-d<=b<=a+d and c-d<=b<=c+d): print('Yes') else : print('No') if __name__=='__main__' : do() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INT : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var INTM : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var STRM : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["String"])->apply(_x) )) ; var STR : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))) ; var LIST : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var LISTS : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["String"])->apply(_x) ))) ; skip ; if __name__ = '__main__' then ( do() ) else skip; operation do() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := INTM->apply() ; if ((a - d->compareTo(c)) <= 0 & (c <= a + d)) or ((a - d->compareTo(b)) <= 0 & (b <= a + d) & (c - d->compareTo(b)) <= 0 & (b <= c + d)) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def read_input(): a,b,c,d=map(int,input().split()) return a,b,c,d def submit(): a,b,c,d=read_input() if abs(c-a)<=d : print('Yes') return if abs(b-a)<=d and abs(c-b)<=d : print('Yes') return print('No') if __name__=='__main__' : submit() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( submit() ) else skip; operation read_input() : OclAny pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; return a, b, c, d; operation submit() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := read_input() ; if ((c - a)->abs()->compareTo(d)) <= 0 then ( execute ('Yes')->display() ; return ) else skip ; if ((b - a)->abs()->compareTo(d)) <= 0 & ((c - b)->abs()->compareTo(d)) <= 0 then ( execute ('Yes')->display() ; return ) else skip ; execute ('No')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=list(map(int,input().split())) b=a[: 3] c=sorted(b) if abs(b[2]-b[0])<=a[3]or(abs(b[2]-b[1])<=a[3]and abs(b[1]-b[0])<=a[3]): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : OclAny := a.subrange(1,3) ; var c : Sequence := b->sort() ; if ((b[2+1] - b->first())->abs()->compareTo(a[3+1])) <= 0 or (((b[2+1] - b[1+1])->abs()->compareTo(a[3+1])) <= 0 & ((b[1+1] - b->first())->abs()->compareTo(a[3+1])) <= 0) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=map(int,input().split()) if d>=abs(a-c)or(d>=abs(a-b)and d>=abs(b-c)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (d->compareTo((a - c)->abs())) >= 0 or ((d->compareTo((a - b)->abs())) >= 0 & (d->compareTo((b - c)->abs())) >= 0) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def square(n): mp=[[0 for _ in range(n)]for _ in range(n)] x,y=n//2,n//2+1 mp[y][x]=1 for i in range(2,n**2+1): x=(x+1)% n y=(y+1)% n while mp[y][x]: y=(y+1)% n x=(x-1)% n mp[y][x]=i for line in mp : s="" for i in line : si=str(i) s+=si.rjust(4) print(s) while True : n=int(input()) if not n : break square(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(n) then ( break ) else skip ; square(n)); operation square(n : OclAny) pre: true post: true activity: var mp : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)))) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{n div 2,n div 2 + 1} ; mp[y+1][x+1] := 1 ; for i : Integer.subrange(2, (n)->pow(2) + 1-1) do ( var x : int := (x + 1) mod n ; var y : int := (y + 1) mod n ; while mp[y+1][x+1] do ( y := (y + 1) mod n ; x := (x - 1) mod n) ; mp[y+1][x+1] := i) ; for line : mp do ( var s : String := "" ; for i : line do ( var si : String := ("" + ((i))) ; s := s + StringLib.padLeftWithInto(si, 4`third, 4)) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") def magic_square(n): sq=[[0 for _ in range(16)]for __ in range(16)] nowx,nowy=n//2,n//2+1 sq[nowy][nowx]=1 for i in range(2,n**2+1): nowx+=1 nowy+=1 while True : if nowx>=n : nowx=0 if nowx<0 : nowx=n-1 if nowy>=n : nowy=0 if sq[nowy][nowx]!=0 : nowx-=1 nowy+=1 if sq[nowy][nowx]==0 and 0<=nowx and nowxtoInteger() ; if n = 0 then ( break ) else skip ; sq := magic_square(n) ; for row : sq do ( var out : String := "" ; for k : row.subrange(1,n) do ( var ks : String := ("" + ((k))) ; ks := StringLib.nCopies(' ', (4 - (ks)->size())) + ks ; out := out + ks) ; execute (out)->display())); operation magic_square(n : OclAny) : OclAny pre: true post: true activity: var sq : Sequence := Integer.subrange(0, 16-1)->select(__ | true)->collect(__ | (Integer.subrange(0, 16-1)->select(_anon | true)->collect(_anon | (0)))) ; var nowx : OclAny := null; var nowy : OclAny := null; Sequence{nowx,nowy} := Sequence{n div 2,n div 2 + 1} ; sq[nowy+1][nowx+1] := 1 ; for i : Integer.subrange(2, (n)->pow(2) + 1-1) do ( nowx := nowx + 1 ; nowy := nowy + 1 ; while true do ( if (nowx->compareTo(n)) >= 0 then ( var nowx : int := 0 ) else skip ; if nowx < 0 then ( nowx := n - 1 ) else skip ; if (nowy->compareTo(n)) >= 0 then ( var nowy : int := 0 ) else skip ; if sq[nowy+1][nowx+1] /= 0 then ( nowx := nowx - 1 ; nowy := nowy + 1 ) else skip ; if sq[nowy+1][nowx+1] = 0 & 0 <= nowx & (nowx->compareTo(n)) < 0 & 0 <= nowy & (nowy->compareTo(n)) < 0 then ( break ) else skip) ; sq[nowy+1][nowx+1] := i) ; return sq.subrange(1,n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline write=sys.stdout.write def solve(): N=int(readline()) if N==0 : return False x=N//2 ; y=x+1 P=[[-1]*N for i in range(N)] c=0 N2=N*N while ctoInteger() ; if N = 0 then ( return false ) else skip ; var x : int := N div 2; var y : int := x + 1 ; var P : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ -1 }, N))) ; var c : int := 0 ; var N2 : int := N * N ; while (c->compareTo(N2)) < 0 do ( if P[y+1][x+1] = -1 then ( c := c + 1 ; P[y+1][x+1] := c ; x := (x + 1) mod N; y := (y + 1) mod N ) else ( x := (x - 1) mod N; y := (y + 1) mod N )) ; for line : P do ( write(StringLib.sumStringsWithSeparator(((line)->collect( _x | (StringLib.interpolateStrings("{:4d}", (trailer . (name format))))->apply(_x) )), "")) ; write("\n")) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heappush,heappop def solve(): N=int(input()) *A,=map(int,input().split()) M=2*10**5 INF=10**18 dist=[[INF]*(M+1)for i in range(N+1)] que=[(0,0,1)] while que : cost,i,p=heappop(que) if i==N : break if dist[i][p]+1e-10collect( _x | (OclType["int"])->apply(_x) ); operation solve() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for e in iter(input,'0'): n=int(e); m,f=[[0]*n for _ in[0]*n],'{:4}'*n j=n//2 ; i=j+1 m[i][j]=1 for k in range(2,n*n+1): i,j,t=-~ i % n,-~ j % n,j if m[i][j]: i,j=-~ i % n,t m[i][j]=k for r in m : print(f.format(*r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for e : OclIterator.newOclIterator_Sequence(input, '0') do ( var n : int := ("" + ((e)))->toInteger(); var m : OclAny := null; var f : OclAny := null; Sequence{m,f} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, n)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, n))),StringLib.nCopies('{:4}', n)} ; var j : int := n div 2; var i : int := j + 1 ; m[i+1][j+1] := 1 ; for k : Integer.subrange(2, n * n + 1-1) do ( var t : OclAny := null; Sequence{i,j,t} := Sequence{-MathLib.bitwiseNot(i) mod n,-MathLib.bitwiseNot(j) mod n,j} ; if m[i+1][j+1] then ( Sequence{i,j} := Sequence{-MathLib.bitwiseNot(i) mod n,t} ) else skip ; m[i+1][j+1] := k) ; for r : m do ( execute (StringLib.interpolateStrings(f, Sequence{(argument * (test (logical_test (comparison (expr (atom (name r)))))))}))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if n==0 : break c=1 nx=ny=int((n-1)/2) b=[[0 for _ in range(n)]for _ in range(n)] ny=ny+1 b[ny][nx]=c for _ in range(n*n-1): c+=1 nx+=1 ny+=1 while 1 : if 0<=nx<=n-1 and 0<=ny<=n-1 and b[ny][nx]==0 : break if nx>n-1 : nx=0 if nx<0 : nx=n-1 if ny>n-1 : ny=0 if b[ny][nx]==0 : break else : nx-=1 ny+=1 b[ny][nx]=c for i in b : print(("".join([str(l).rjust(4)for l in i]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var c : int := 1 ; var nx : OclAny := ("" + (((n - 1) / 2)))->toInteger(); var ny : int := ("" + (((n - 1) / 2)))->toInteger() ; var b : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)))) ; ny := ny + 1 ; b[ny+1][nx+1] := c ; for _anon : Integer.subrange(0, n * n - 1-1) do ( c := c + 1 ; nx := nx + 1 ; ny := ny + 1 ; while 1 do ( if 0 <= nx & (nx <= n - 1) & 0 <= ny & (ny <= n - 1) & b[ny+1][nx+1] = 0 then ( break ) else skip ; if (nx->compareTo(n - 1)) > 0 then ( nx := 0 ) else skip ; if nx < 0 then ( nx := n - 1 ) else skip ; if (ny->compareTo(n - 1)) > 0 then ( ny := 0 ) else skip ; if b[ny+1][nx+1] = 0 then ( break ) else ( nx := nx - 1 ; ny := ny + 1 )) ; b[ny+1][nx+1] := c) ; for i : b do ( execute ((StringLib.sumStringsWithSeparator((i->select(l | true)->collect(l | (OclType["String"](l).rjust(4)))), "")))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(0,t): n=int(input()) s=input() numb1=n-1 flag=False while numb1>=0 : if s[numb1]=='0' : break numb1-=1 numb2=0 flag=False while numb2numb1 : print(s) else : print(s[0 : numb2]+s[numb1 : n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var numb1 : double := n - 1 ; var flag : boolean := false ; while numb1 >= 0 do ( if s[numb1+1] = '0' then ( break ) else skip ; numb1 := numb1 - 1) ; var numb2 : int := 0 ; flag := false ; while (numb2->compareTo(n)) < 0 do ( if s[numb2+1] = '1' then ( break ) else skip ; numb2 := numb2 + 1) ; if (numb2->compareTo(numb1)) > 0 then ( execute (s)->display() ) else ( execute (s.subrange(0+1, numb2) + s.subrange(numb1+1, n))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) x=list(map(int,input().split())) ans=10**9 for i in range(n-k+1): if x[i+k-1]<=0 : ans=min(ans,-x[i]) elif x[i]>=0 : ans=min(ans,x[i+k-1]) else : ans=min(ans,x[i+k-1]-x[i]+min(x[i+k-1],-x[i])) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : double := (10)->pow(9) ; for i : Integer.subrange(0, n - k + 1-1) do ( if x[i + k - 1+1] <= 0 then ( ans := Set{ans, -x[i+1]}->min() ) else (if x[i+1] >= 0 then ( ans := Set{ans, x[i + k - 1+1]}->min() ) else ( ans := Set{ans, x[i + k - 1+1] - x[i+1] + Set{x[i + k - 1+1], -x[i+1]}->min()}->min() ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque N,K=map(int,input().split()) Xlist=list(map(int,input().split())) Ans=10**13 for i in range(len(Xlist)-K+1): Xleft=Xlist[i] Xright=Xlist[i+K-1] Dis=min(abs(Xleft),abs(Xright))+(Xright-Xleft) Ans=min(Dis,Ans) print(Ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var Xlist : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var Ans : double := (10)->pow(13) ; for i : Integer.subrange(0, (Xlist)->size() - K + 1-1) do ( var Xleft : OclAny := Xlist[i+1] ; var Xright : OclAny := Xlist[i + K - 1+1] ; var Dis : OclAny := Set{(Xleft)->abs(), (Xright)->abs()}->min() + (Xright - Xleft) ; Ans := Set{Dis, Ans}->min()) ; execute (Ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=[int(i)for i in input().split()] x=[int(i)for i in input().split()] plus=[0] minus=[] zeroExist=0 for i in range(n): if x[i]>0 : plus.append(x[i]) elif x[i]==0 : zeroExist=1 else : minus.append(-x[i]) minus.append(0) minus=list(reversed(minus)) if zeroExist==1 : k-=1 cost=10**9 for i in range(k+1): if iselect(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var x : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var plus : Sequence := Sequence{ 0 } ; var minus : Sequence := Sequence{} ; var zeroExist : int := 0 ; for i : Integer.subrange(0, n-1) do ( if x[i+1] > 0 then ( execute ((x[i+1]) : plus) ) else (if x[i+1] = 0 then ( zeroExist := 1 ) else ( execute ((-x[i+1]) : minus) ) ) ) ; execute ((0) : minus) ; minus := ((minus)->reverse()) ; if zeroExist = 1 then ( k := k - 1 ) else skip ; var cost : double := (10)->pow(9) ; for i : Integer.subrange(0, k + 1-1) do ( if (i->compareTo((plus)->size())) < 0 & (k - i->compareTo((minus)->size())) < 0 then ( if i = 0 or i = k then ( cost := Set{cost, plus[i+1] + minus[k - i+1]}->min() ) else ( cost := Set{cost, plus[i+1] + minus[k - i+1] + Set{plus[i+1], minus[k - i+1]}->min()}->min() ) ) else skip) ; execute (cost)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,input().split()) X=list(map(int,input().split())) pos_start_index=0 if X[0]>0 : pos_start_index=0 elif X[N-1]<0 : pos_start_index=N for n in range(N-1): if X[n]==0 : pos_start_index=n break elif X[n]<0 and X[n+1]>0 : pos_start_index=n+1 break neg_sum_list=[] for j,idx in enumerate(range(pos_start_index-1,-1,-1)): neg_sum_list.append(-X[idx]) pos_sum_list=[] for j,idx in enumerate(range(pos_start_index,N)): pos_sum_list.append(X[idx]) res=[] for j,neg_sum in enumerate(neg_sum_list): neg_count=j+1 pos_count=K-neg_count if neg_count==K : res.append(neg_sum) break if pos_count<=len(pos_sum_list): pos_sum=pos_sum_list[pos_count-1] res.append(2*neg_sum+pos_sum) for j,pos_sum in enumerate(pos_sum_list): pos_count=j+1 neg_count=K-pos_count if pos_count==K : res.append(pos_sum) break if neg_count<=len(neg_sum_list): neg_sum=neg_sum_list[neg_count-1] res.append(2*pos_sum+neg_sum) print(min(res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var X : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var pos_start_index : int := 0 ; if X->first() > 0 then ( pos_start_index := 0 ) else (if X[N - 1+1] < 0 then ( pos_start_index := N ) else skip) ; for n : Integer.subrange(0, N - 1-1) do ( if X[n+1] = 0 then ( pos_start_index := n ; break ) else (if X[n+1] < 0 & X[n + 1+1] > 0 then ( pos_start_index := n + 1 ; break ) else skip)) ; var neg_sum_list : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (Integer.subrange(-1 + 1, pos_start_index - 1)->reverse())->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(-1 + 1, pos_start_index - 1)->reverse())->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var idx : OclAny := _tuple->at(_indx); execute ((-X[idx+1]) : neg_sum_list)) ; var pos_sum_list : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (Integer.subrange(pos_start_index, N-1))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(pos_start_index, N-1))->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var idx : OclAny := _tuple->at(_indx); execute ((X[idx+1]) : pos_sum_list)) ; var res : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (neg_sum_list)->size())->collect( _indx | Sequence{_indx-1, (neg_sum_list)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var neg_sum : OclAny := _tuple->at(_indx); var neg_count : OclAny := j + 1 ; var pos_count : double := K - neg_count ; if neg_count = K then ( execute ((neg_sum) : res) ; break ) else skip ; if (pos_count->compareTo((pos_sum_list)->size())) <= 0 then ( var pos_sum : OclAny := pos_sum_list[pos_count - 1+1] ; execute ((2 * neg_sum + pos_sum) : res) ) else skip) ; for _tuple : Integer.subrange(1, (pos_sum_list)->size())->collect( _indx | Sequence{_indx-1, (pos_sum_list)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var pos_sum : OclAny := _tuple->at(_indx); pos_count := j + 1 ; neg_count := K - pos_count ; if pos_count = K then ( execute ((pos_sum) : res) ; break ) else skip ; if (neg_count->compareTo((neg_sum_list)->size())) <= 0 then ( var neg_sum : OclAny := neg_sum_list[neg_count - 1+1] ; execute ((2 * pos_sum + neg_sum) : res) ) else skip) ; execute ((res)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect def solve(): n,k=map(int,input().split()) al=[int(i)for i in input().split()] ans=sum(abs(i)for i in al) flag0=0 in al if flag0 : k-=1 n-=1 if k==0 : print(0) return al.remove(0) nc=bisect.bisect_left(al,0) for i in range(n): if i<0 or i+k-1>=n : break if al[i]<0 and al[i+k-1]<0 : t1=abs(al[i]) else : t1=min(abs(al[i])*2+abs(al[i+k-1]),abs(al[i])+abs(al[i+k-1])*2) if al[i]>0 and al[i+k-1]>0 : t2=abs(al[i+k-1]) else : t2=min(abs(al[i])*2+abs(al[i+k-1]),abs(al[i])+abs(al[i+k-1])*2) t=min(t1,t2) ans=min(ans,t) print(ans) if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation solve() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var al : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name al))))))))->sum() ; var flag0 : boolean := (al)->includes(0) ; if flag0 then ( k := k - 1 ; n := n - 1 ; if k = 0 then ( execute (0)->display() ; return ) else skip ; execute ((0) /: al) ) else skip ; var nc : OclAny := bisect.bisect_left(al, 0) ; for i : Integer.subrange(0, n-1) do ( if i < 0 or (i + k - 1->compareTo(n)) >= 0 then ( break ) else skip ; if al[i+1] < 0 & al[i + k - 1+1] < 0 then ( var t1 : double := (al[i+1])->abs() ) else ( t1 := Set{(al[i+1])->abs() * 2 + (al[i + k - 1+1])->abs(), (al[i+1])->abs() + (al[i + k - 1+1])->abs() * 2}->min() ) ; if al[i+1] > 0 & al[i + k - 1+1] > 0 then ( var t2 : double := (al[i + k - 1+1])->abs() ) else ( t2 := Set{(al[i+1])->abs() * 2 + (al[i + k - 1+1])->abs(), (al[i+1])->abs() + (al[i + k - 1+1])->abs() * 2}->min() ) ; var t : OclAny := Set{t1, t2}->min() ; ans := Set{ans, t}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calc(x,k): i=0 ans=0 while x>=k**i : ans+=x//(k**i) i+=1 return ans n,k=list(map(int,input().split())) ori=n x=n//k n-=x y=int(n/k) curr=y*k while True : ans=calc(curr,k) if ans>=ori : print(curr) exit() curr+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ori : OclAny := n ; x := n div k ; n := n - x ; var y : int := ("" + ((n / k)))->toInteger() ; var curr : double := y * k ; while true do ( ans := calc(curr, k) ; if (ans->compareTo(ori)) >= 0 then ( execute (curr)->display() ; exit() ) else skip ; curr := curr + 1); operation calc(x : OclAny, k : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; var ans : int := 0 ; while (x->compareTo((k)->pow(i))) >= 0 do ( ans := ans + x div ((k)->pow(i)) ; i := i + 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=[int(i)for i in input().split(" ")] maximum=n minimum=0 def brings_sucess(v,k,n): summed=v expression=int(v/k) idx=1 while(expression): summed+=expression idx+=1 expression=int(v/(k**idx)) return summed>=n while(maximum!=minimum): purposed=int((maximum+minimum)/2) was_sucessful=brings_sucess(purposed,k,n) if(was_sucessful): maximum=purposed else : minimum=purposed+1 print(maximum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var maximum : OclAny := n ; var minimum : int := 0 ; skip ; while (maximum /= minimum) do ( var purposed : int := ("" + (((maximum + minimum) / 2)))->toInteger() ; var was_sucessful : OclAny := brings_sucess(purposed, k, n) ; if (was_sucessful) then ( maximum := purposed ) else ( minimum := purposed + 1 )) ; execute (maximum)->display(); operation brings_sucess(v : OclAny, k : OclAny, n : OclAny) : OclAny pre: true post: true activity: var summed : OclAny := v ; var expression : int := ("" + ((v / k)))->toInteger() ; var idx : int := 1 ; while (expression) do ( summed := summed + expression ; idx := idx + 1 ; expression := ("" + ((v / ((k)->pow(idx)))))->toInteger()) ; return (summed->compareTo(n)) >= 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n_total,k_rate=(int(_)for _ in input().split()) def predicate(v): sum=0 count=0 org_v=v while(v>0): sum+=v count+=1 v=org_v//(k_rate**count) return sumdisplay(); operation predicate(v : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; var count : int := 0 ; var org_v : OclAny := v ; while (v > 0) do ( sum := sum + v ; count := count + 1 ; v := org_v div ((k_rate)->pow(count))) ; return (sum->compareTo(n_total)) < 0; operation binary_search() : OclAny pre: true post: true activity: var lo : int := 0 ; var hi : OclAny := n_total ; while (1) do ( if (hi - lo = 1) then ( return hi ) else skip ; var mid : int := (lo) + (hi - lo) div 2 ; if (predicate(mid)) then ( lo := mid ) else ( hi := mid )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline INF=float('inf') MOD=10**9+7 def inpl(): return list(map(int,input().split())) def solve(N): A=inpl() dp=[INF]*(A[0]*2) for i in range(A[0]//2,A[0]*2): dp[i]=abs(i-A[0])/A[0] for i in range(N-1): a1=A[i+1] nn=a1*2 ndp=[INF]*nn for j in range(1,len(dp)): if dp[j]==INF : continue t=dp[j] for k in range(j,nn,j): u=abs(a1-k)/a1 if uu : ndp[k]=u dp=ndp return '{:0.12f}'.format(min(dp)) N=int(input()) if N!=0 : print(solve(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var INF : double := ("" + (('inf')))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N /= 0 then ( execute (solve(N))->display() ) else skip; operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation solve(N : OclAny) : OclAny pre: true post: true activity: var A : OclAny := inpl() ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, (A->first() * 2)) ; for i : Integer.subrange(A->first() div 2, A->first() * 2-1) do ( dp[i+1] := (i - A->first())->abs() / A->first()) ; for i : Integer.subrange(0, N - 1-1) do ( var a1 : OclAny := A[i + 1+1] ; var nn : double := a1 * 2 ; var ndp : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, nn) ; for j : Integer.subrange(1, (dp)->size()-1) do ( if dp[j+1] = INF then ( continue ) else skip ; var t : OclAny := dp[j+1] ; for k : Integer.subrange(j, nn-1)->select( $x | ($x - j) mod j = 0 ) do ( var u : double := (a1 - k)->abs() / a1 ; if (u->compareTo(t)) < 0 then ( u := t ) else skip ; if (ndp[k+1]->compareTo(u)) > 0 then ( ndp[k+1] := u ) else skip)) ; dp := ndp) ; return StringLib.interpolateStrings('{:0.12f}', Sequence{(dp)->min()}); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) def f(v): global n global k total=0 t=1 while(v//t!=0): total+=v//t t*=k return total>=n if(True): r=1 while(not(f(r))): r*=2 l=0 while(r>(l+1)): m=(r+l)//2 if(f(m)==0): l=m else : r=m print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute n : OclAny; attribute k : OclAny; operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; if (true) then ( var r : int := 1 ; while (not((f(r)))) do ( r := r * 2) ; var l : int := 0 ; while ((r->compareTo((l + 1))) > 0) do ( var m : int := (r + l) div 2 ; if (f(m) = 0) then ( l := m ) else ( r := m )) ; execute (r)->display() ) else skip; operation f(v : OclAny) : OclAny pre: true post: true activity: skip ; skip ; var total : int := 0 ; var t : int := 1 ; while (v div t /= 0) do ( total := total + v div t ; t := t * k) ; return (total->compareTo(n)) >= 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) s=input() one=0 zero=0 one=s.find('1') zero=s.rfind('0') if one>zero : print(s) else : c=s[0 : one] d=s[zero : n] print(c+d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var one : int := 0 ; var zero : int := 0 ; one := s->indexOf('1') - 1 ; zero := s.rfind('0') ; if (one->compareTo(zero)) > 0 then ( execute (s)->display() ) else ( var c : OclAny := s.subrange(0+1, one) ; var d : OclAny := s.subrange(zero+1, n) ; execute (c + d)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minOperations(n,a,b,c): ans=0 for i in range(n): x=a[i] y=b[i] z=c[i] if(x==y and y==z): continue elif(x==y or y==z or x==z): ans+=1 else : ans+=2 return ans if __name__=='__main__' : a="place" b="abcde" c="plybe" n=len(a) print(minOperations(n,a,b,c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := "place" ; b := "abcde" ; c := "plybe" ; n := (a)->size() ; execute (minOperations(n, a, b, c))->display() ) else skip; operation minOperations(n : OclAny, a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := a[i+1] ; var y : OclAny := b[i+1] ; var z : OclAny := c[i+1] ; if (x = y & y = z) then ( continue ) else (if (x = y or y = z or x = z) then ( ans := ans + 1 ) else ( ans := ans + 2 ) ) ) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lenFasten=input() fastened=list(map(int,input().split())) def checkBerlandFashion(fastened): if len(fastened)==1 : return fastened[0]==1 else : countNotFasten=0 for i in range(len(fastened)): if fastened[i]==0 : countNotFasten+=1 return countNotFasten==1 if(checkBerlandFashion(fastened)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lenFasten : String := (OclFile["System.in"]).readLine() ; var fastened : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; if (checkBerlandFashion(fastened)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); operation checkBerlandFashion(fastened : OclAny) : OclAny pre: true post: true activity: if (fastened)->size() = 1 then ( return fastened->first() = 1 ) else ( var countNotFasten : int := 0 ; for i : Integer.subrange(0, (fastened)->size()-1) do ( if fastened[i+1] = 0 then ( countNotFasten := countNotFasten + 1 ) else skip) ; return countNotFasten = 1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) if n==1 : if a[0]==1 : print("YES") else : print("NO") else : if a.count(0)==1 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = 1 then ( if a->first() = 1 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else ( if a->count(0) = 1 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input().strip()) arr=list(map(int,input().strip().split())) itr=0 for i in arr : if i==0 : itr+=1 if n==1 and itr==0 : print("YES") return 0 if(itr==1)and(n>1): print("YES") else : print("NO") solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() : OclAny pre: true post: true activity: var n : int := ("" + ((input()->trim())))->toInteger() ; var arr : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var itr : int := 0 ; for i : arr do ( if i = 0 then ( itr := itr + 1 ) else skip) ; if n = 1 & itr = 0 then ( execute ("YES")->display() ; return 0 ) else skip ; if (itr = 1) & (n > 1) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) if len(a)==1 : if a[0]==1 : print("YES") else : print("NO") else : a.sort() if a[0]==1 : print("NO") else : if a[1]==0 : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (a)->size() = 1 then ( if a->first() = 1 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else ( a := a->sort() ; if a->first() = 1 then ( execute ("NO")->display() ) else ( if a[1+1] = 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): m=int(input()) buttons=list(map(int,input().strip().split())) countOpen=buttons.count(0) if(countOpen==1 and m>1)or(countOpen==0 and m==1): print("YES") else : print("NO") solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var buttons : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var countOpen : int := buttons->count(0) ; if (countOpen = 1 & m > 1) or (countOpen = 0 & m = 1) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=3 C=3 def pathCountRec(mat,m,n,k): if m<0 or n<0 : return 0 elif m==0 and n==0 : return k==mat[m][n] return(pathCountRec(mat,m-1,n,k-mat[m][n])+pathCountRec(mat,m,n-1,k-mat[m][n])) def pathCount(mat,k): return pathCountRec(mat,R-1,C-1,k) k=12 mat=[[1,2,3],[4,6,5],[3,2,1]] print(pathCount(mat,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : int := 3 ; var C : int := 3 ; skip ; skip ; k := 12 ; mat := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{Sequence{4}->union(Sequence{6}->union(Sequence{ 5 }))}->union(Sequence{ Sequence{3}->union(Sequence{2}->union(Sequence{ 1 })) })) ; execute (pathCount(mat, k))->display(); operation pathCountRec(mat : OclAny, m : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if m < 0 or n < 0 then ( return 0 ) else (if m = 0 & n = 0 then ( return k = mat[m+1][n+1] ) else skip) ; return (pathCountRec(mat, m - 1, n, k - mat[m+1][n+1]) + pathCountRec(mat, m, n - 1, k - mat[m+1][n+1])); operation pathCount(mat : OclAny, k : OclAny) : OclAny pre: true post: true activity: return pathCountRec(mat, R - 1, C - 1, k); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def evenDecimalValue(str,n): result=0 for i in range(0,n): if(str[i]=='0'): result+=(n-i) return result str="10010" n=5 print(evenDecimalValue(str,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclType["String"] := "10010" ; n := 5 ; execute (evenDecimalValue(OclType["String"], n))->display(); operation evenDecimalValue(OclType["String"] : OclAny, n : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (("" + ([i+1])) = '0') then ( result := result + (n - i) ) else skip) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inp=open('./B-large.in','r') outp=open('./B.out','w') T=int(inp.readline()) def solve(i): I=inp.readline().replace('\n','').split('') D=float(I[0]) N=int(I[1]) A=int(I[2]) Ns=[] for n in range(N): Ns.append([float(x)for x in inp.readline().replace('\n','').split('')]) if Ns[n][1]>D : if n!=0 : Ns[n][0]=Ns[n-1][0]+(D-Ns[n-1][1])/(Ns[n][1]-Ns[n-1][1])*(Ns[n][0]-Ns[n-1][0]) Ns[n][1]=D As=[float(x)for x in inp.readline().replace('\n','').split('')] Mx=[0]*A for n in range(N): for a in range(A): Mx[a]=max(Mx[a],Ns[n][0]-(2*Ns[n][1]/As[a])**0.5) outp.write('Case #'+str(i)+':\n') for a in range(A): x=(2*D/As[a])**0.5+Mx[a] outp.write(str(x)+'\n') for k in range(T): solve(k+1) inp.close() outp.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inp : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('./B-large.in')) ; var outp : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('./B.out')) ; var T : int := ("" + ((inp.readLine())))->toInteger() ; skip ; for k : Integer.subrange(0, T-1) do ( solve(k + 1)) ; inp.closeFile() ; outp.closeFile(); operation solve(i : OclAny) pre: true post: true activity: var I : OclAny := inp.readLine().replace(' ', '').split('') ; var D : double := ("" + ((I->first())))->toReal() ; var N : int := ("" + ((I[1+1])))->toInteger() ; var A : int := ("" + ((I[2+1])))->toInteger() ; var Ns : Sequence := Sequence{} ; for n : Integer.subrange(0, N-1) do ( execute ((inp.readLine().replace(' ', '').split('')->select(x | true)->collect(x | (("" + ((x)))->toReal()))) : Ns) ; if (Ns[n+1][1+1]->compareTo(D)) > 0 then ( if n /= 0 then ( Ns[n+1]->first() := Ns[n - 1+1]->first() + (D - Ns[n - 1+1][1+1]) / (Ns[n+1][1+1] - Ns[n - 1+1][1+1]) * (Ns[n+1]->first() - Ns[n - 1+1]->first()) ) else skip ; Ns[n+1][1+1] := D ) else skip) ; var As : Sequence := inp.readLine().replace(' ', '').split('')->select(x | true)->collect(x | (("" + ((x)))->toReal())) ; var Mx : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, A) ; for n : Integer.subrange(0, N-1) do ( for a : Integer.subrange(0, A-1) do ( Mx[a+1] := Set{Mx[a+1], Ns[n+1]->first() - ((2 * Ns[n+1][1+1] / As[a+1]))->pow(0.5)}->max())) ; outp.write('Case #' + ("" + ((i))) + ': ') ; for a : Integer.subrange(0, A-1) do ( var x : double := ((2 * D / As[a+1]))->pow(0.5) + Mx[a+1] ; outp.write(("" + ((x))) + ' ')); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a1,a2,a3,a4,a5,a6=input().split() print((int(a1)+int(a2)+int(a3))**2-int(a1)**2-int(a3)**2-int(a5)**2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a1 : OclAny := null; var a2 : OclAny := null; var a3 : OclAny := null; var a4 : OclAny := null; var a5 : OclAny := null; var a6 : OclAny := null; Sequence{a1,a2,a3,a4,a5,a6} := input().split() ; execute (((("" + ((a1)))->toInteger() + ("" + ((a2)))->toInteger() + ("" + ((a3)))->toInteger()))->pow(2) - (("" + ((a1)))->toInteger())->pow(2) - (("" + ((a3)))->toInteger())->pow(2) - (("" + ((a5)))->toInteger())->pow(2))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(s): stack=[] for i in range(len(s)-1,-1,-1): if s[i]=='0' : stack.append('0') elif s[i]=='1' : if len(stack)and stack[-1]=='0' : while len(stack)and stack[-1]=='0' : stack.pop() stack.append('0') else : stack.append('1') ans='' for i in range(len(stack)-1,-1,-1): ans+=stack[i] return ans t=int(input()) for _ in range(t): n=int(input()) s=input() print(solve(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; s := (OclFile["System.in"]).readLine() ; execute (solve(s))->display()); operation solve(s : OclAny) : OclAny pre: true post: true activity: var stack : Sequence := Sequence{} ; for i : Integer.subrange(-1 + 1, (s)->size() - 1)->reverse() do ( if s[i+1] = '0' then ( execute (('0') : stack) ) else (if s[i+1] = '1' then ( if (stack)->size() & stack->last() = '0' then ( while (stack)->size() & stack->last() = '0' do ( stack := stack->front()) ; execute (('0') : stack) ) else ( execute (('1') : stack) ) ) else skip)) ; var ans : String := '' ; for i : Integer.subrange(-1 + 1, (stack)->size() - 1)->reverse() do ( ans := ans + stack[i+1]) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input('')) l=list(map(int,input().split())) a,b,c=l.count(1),l.count(2),l.count(3) k=[a,b,c] m=max(k) print(sum(k)-m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{l->count(1),l->count(2),l->count(3)} ; var k : Sequence := Sequence{a}->union(Sequence{b}->union(Sequence{ c })) ; var m : OclAny := (k)->max() ; execute ((k)->sum() - m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from fractions import Fraction from math import sqrt line=sys.stdin.readline() fields=line.split() assert len(fields)==1 ntc=int(fields[0]) def solve(d,a,other_car): wait_time=Fraction(0) first=True for time,distance in other_car : if distance>d : if first : break time=last_time+(time-last_time)*(d-last_distance)/(distance-last_distance) distance=d first=False arrival_time=sqrt(2*distance/a) if arrival_timecost2 : cost1=cost1+a count+=1 if count % b!=0 : cost2=(box*c) elif count % b==0 : box+=1 cost2=(box*c) ans1=count return ans1 def solve2(a,b,c): if(c/b)>=a : return-1 count=b cost1=(a*b) cost2=c while cost2>cost1 : cost1=cost1+(a*b) if cost2toInteger() ; for i : Integer.subrange(0, t-1) do ( Sequence{a,b,c} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : OclAny := (solve(a, b, c)) ; for i : ans do ( execute (i)->display()) ; execute (->display()); operation solve(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: skip ; skip ; ans1 := solve1(a, b, c) ; ans2 := solve2(a, b, c) ; return ans1, ans2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- hoge=input().split() W=int(hoge[0]) H=int(hoge[1]) x=int(hoge[2]) y=int(hoge[3]) r=int(hoge[4]) if(x+r)<=W and(y+r)<=H and(x-r)>=0 and(y+r)>=0 : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var hoge : OclAny := input().split() ; var W : int := ("" + ((hoge->first())))->toInteger() ; var H : int := ("" + ((hoge[1+1])))->toInteger() ; var x : int := ("" + ((hoge[2+1])))->toInteger() ; var y : int := ("" + ((hoge[3+1])))->toInteger() ; var r : int := ("" + ((hoge[4+1])))->toInteger() ; if ((x + r)->compareTo(W)) <= 0 & ((y + r)->compareTo(H)) <= 0 & (x - r) >= 0 & (y + r) >= 0 then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: a,b,c=map(int,s.split()); print(2*(ac]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ); execute (2 * ((a->compareTo(c)) < 0) - 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- test=int(input()) counter=0 while(countertoInteger() ; var counter : int := 0 ; while ((counter->compareTo(test)) < 0) do ( var prices : OclAny := input().split() ; var a : int := ("" + ((prices->first())))->toInteger() ; var b : int := ("" + ((prices[1+1])))->toInteger() ; var c : int := ("" + ((prices[2+1])))->toInteger() ; var ans1 : String := "-1" ; if ((a->compareTo(c)) < 0) then ( ans1 := "1" ) else skip ; var ans2 : String := "-1" ; if ((c->compareTo(a * b)) < 0) then ( ans2 := ("" + ((b))) ) else skip ; execute (ans1 + " " + ans2)->display() ; counter := counter + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gukiz(n): ls=list(map(int,input().split()))[: n] for i in range(n): c=1 for j in range(n): if(ls[i]toInteger() ; gukiz(a); operation gukiz(n : OclAny) pre: true post: true activity: var ls : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ; for i : Integer.subrange(0, n-1) do ( var c : int := 1 ; for j : Integer.subrange(0, n-1) do ( if ((ls[i+1]->compareTo(ls[j+1])) < 0) then ( c := c + 1 ) else skip) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- rajay=int(input()) rna=list(map(int,input().split())) for i in range(len(rna)): k=[j for j in rna if(j>rna[i])] print(len(k)+1,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var rajay : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var rna : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, (rna)->size()-1) do ( var k : Sequence := rna->select(j | ((j->compareTo(rna[i+1])) > 0))->collect(j | (j)) ; execute ((k)->size() + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : n=int(input()) arr=[] if n % 2==0 : for i in range(n): if(i+1)% 2==1 : arr.append(i+2) else : arr.append(i) print(arr[i],end=" ") else : arr.append(1) print(arr[0],end=" ") for i in range(1,n): if(i+1)% 2==0 : arr.append(i+2) else : arr.append(i) print(arr[i],end=" ") print() t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Sequence{} ; if n mod 2 = 0 then ( for i : Integer.subrange(0, n-1) do ( if (i + 1) mod 2 = 1 then ( execute ((i + 2) : arr) ) else ( execute ((i) : arr) ) ; execute (arr[i+1])->display()) ) else ( execute ((1) : arr) ; execute (arr->first())->display() ; for i : Integer.subrange(1, n-1) do ( if (i + 1) mod 2 = 0 then ( execute ((i + 2) : arr) ) else ( execute ((i) : arr) ) ; execute (arr[i+1])->display()) ) ; execute (->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=list(map(int,input().split())) for i in range(len(b)): c=[j for j in b if(j>b[i])] print(len(c)+1,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, (b)->size()-1) do ( var c : Sequence := b->select(j | ((j->compareTo(b[i+1])) > 0))->collect(j | (j)) ; execute ((c)->size() + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=list(map(int,input().split())) for i in range(len(b)): c=[j for j in b if(j>b[i])] print(len(c)+1,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, (b)->size()-1) do ( var c : Sequence := b->select(j | ((j->compareTo(b[i+1])) > 0))->collect(j | (j)) ; execute ((c)->size() + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) l=list(map(int,input().split())) for i in range(len(l)): k=[j for j in l if(j>l[i])] print(len(k)+1,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, (l)->size()-1) do ( var k : Sequence := l->select(j | ((j->compareTo(l[i+1])) > 0))->collect(j | (j)) ; execute ((k)->size() + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import os import random import re import sys from math import gcd from math import sqrt for _ in range(int(input())): n=int(input()) count=[False for i in range(n)] ans=-1 for i in range(n): arr=[int(x)-1 for x in input().split()][1 :] for j in arr : if not count[j]: count[j]=True break else : ans=i if ans==-1 : print('OPTIMAL') else : fi=count.index(False) print('IMPROVE\n'+str(ans+1)+" "+str(fi+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (false)) ; var ans : int := -1 ; for i : Integer.subrange(0, n-1) do ( var arr : OclAny := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1))->tail() ; (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name arr))))))) : (suite (stmt (compound_stmt if (test (logical_test not (logical_test (comparison (expr (atom (name count)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name count)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name True)))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))))))))))) ; if ans = -1 then ( execute ('OPTIMAL')->display() ) else ( var fi : int := count->indexOf(false) - 1 ; execute ('IMPROVE ' + ("" + ((ans + 1))) + " " + ("" + ((fi + 1))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): empty=[] t=int(input()) found=[0]*t for j in range(t): preference=list(map(int,input().split()))[1 :] flag=True for k in preference : if found[k-1]==0 : found[k-1]=1 flag=False break if flag==True : empty+=[j] if len(empty)==0 : print("OPTIMAL") else : print("IMPROVE") for i in range(t): if found[i]==0 : print(str(empty[0]+1)+" "+str(i+1)) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var empty : Sequence := Sequence{} ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var found : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, t) ; for j : Integer.subrange(0, t-1) do ( var preference : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->tail() ; var flag : boolean := true ; for k : preference do ( if found[k - 1+1] = 0 then ( found[k - 1+1] := 1 ; flag := false ; break ) else skip) ; if flag = true then ( empty := empty + Sequence{ j } ) else skip) ; if (empty)->size() = 0 then ( execute ("OPTIMAL")->display() ) else ( execute ("IMPROVE")->display() ; for i : Integer.subrange(0, t-1) do ( if found[i+1] = 0 then ( execute (("" + ((empty->first() + 1))) + " " + ("" + ((i + 1))))->display() ; break ) else skip) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=input() print("YES" if n.count("5")==2 and n.count("7")==1 else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : String := (OclFile["System.in"]).readLine() ; execute (if n->count("5") = 2 & n->count("7") = 1 then "YES" else "NO" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline inp=lambda : list(map(int,input().split())) def answer(): done=[False for i in range(n+1)] ans,p=0,-1 for i in range(n): got=False for j in range(1,want[i][0]+1): if(done[want[i][j]]): continue done[want[i][j]]=True got=True break if(not got): p=i+1 if(p==-1): print('OPTIMAL') return for i in range(1,n+1): if(done[i]): continue prince=i break print('IMPROVE') print(p,prince) for T in range(int(input())): n=int(input()) want=[] for i in range(n): want.append(inp()) answer() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; var inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; skip ; for T : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var want : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((inp->apply()) : want)) ; answer()); operation answer() pre: true post: true activity: var done : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (false)) ; var ans : OclAny := null; var p : OclAny := null; Sequence{ans,p} := Sequence{0,-1} ; for i : Integer.subrange(0, n-1) do ( var got : boolean := false ; for j : Integer.subrange(1, want[i+1]->first() + 1-1) do ( if (done[want[i+1][j+1]+1]) then ( continue ) else skip ; done[want[i+1][j+1]+1] := true ; got := true ; break) ; if (not(got)) then ( var p : OclAny := i + 1 ) else skip) ; if (p = -1) then ( execute ('OPTIMAL')->display() ; return ) else skip ; for i : Integer.subrange(1, n + 1-1) do ( if (done[i+1]) then ( continue ) else skip ; var prince : OclAny := i ; break) ; execute ('IMPROVE')->display() ; execute (p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) preferences=[] for _ in range(n): preferences.append([int(x)-1 for x in input().split()][1 :]) prince=[False]*n princess=[-1]*n for i in range(n): for x in preferences[i]: if not prince[x]: princess[i]=x prince[x]=True break flag=True for x in prince : if not x : flag=False break if flag : print("OPTIMAL") else : print("IMPROVE") num=princess.index(-1) num2=prince.index(False) print(num+1,num2+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var preferences : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1))->tail()) : preferences)) ; var prince : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ; var princess : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; for i : Integer.subrange(0, n-1) do ( for x : preferences[i+1] do ( if not(prince[x+1]) then ( princess[i+1] := x ; prince[x+1] := true ; break ) else skip)) ; var flag : boolean := true ; for x : prince do ( if not(x) then ( flag := false ; break ) else skip) ; if flag then ( execute ("OPTIMAL")->display() ) else ( execute ("IMPROVE")->display() ; var num : int := princess->indexOf(-1) - 1 ; var num2 : int := prince->indexOf(false) - 1 ; execute (num + 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) sp=[] minsp=[] isit=[False for ljkl in range(n)] for zz in range(n): lk=list(map(int,input().split())) lk.pop(0) if len(lk)==0 : minsp.append(0) continue sp.append(lk) ho=min(lk) az=lk.copy() while isit[ho-1]: az.remove(ho) if len(az)==0 : ho=0 break ho=min(az) if ho!=0 : isit[ho-1]=True minsp.append(ho) abbo=True while isit.count(True)!=len(isit)and minsp.count(0)!=0 : al=minsp.index(0) abbo=False mn=isit.index(False) minsp[al]=mn print('IMPROVE') print(al+1,mn+1) break if abbo : print('OPTIMAL') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sp : Sequence := Sequence{} ; var minsp : Sequence := Sequence{} ; var isit : Sequence := Integer.subrange(0, n-1)->select(ljkl | true)->collect(ljkl | (false)) ; for zz : Integer.subrange(0, n-1) do ( var lk : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; lk := lk->excludingAt(0+1) ; if (lk)->size() = 0 then ( execute ((0) : minsp) ; continue ) else skip ; execute ((lk) : sp) ; var ho : OclAny := (lk)->min() ; var az : OclAny := lk->copy() ; while isit[ho - 1+1] do ( execute ((ho) /: az) ; if (az)->size() = 0 then ( ho := 0 ; break ) else skip ; ho := (az)->min()) ; if ho /= 0 then ( isit[ho - 1+1] := true ) else skip ; execute ((ho) : minsp)) ; var abbo : boolean := true ; while isit->count(true) /= (isit)->size() & minsp->count(0) /= 0 do ( var al : int := minsp->indexOf(0) - 1 ; abbo := false ; var mn : int := isit->indexOf(false) - 1 ; minsp[al+1] := mn ; execute ('IMPROVE')->display() ; execute (al + 1)->display() ; break) ; if abbo then ( execute ('OPTIMAL')->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import itertools as itr def fact(n): for i in range(2,n//2+1): if n % i==0 : return False return True idx=1 i=6 ans=[] while(len(ans)<=56): if fact(i): ans.append(i) i+=5 n=int(input()) for i in range(n): print(ans[i],end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var idx : int := 1 ; var i : int := 6 ; var ans : Sequence := Sequence{} ; while ((ans)->size() <= 56) do ( if fact(i) then ( execute ((i) : ans) ) else skip ; i := i + 5) ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( execute (ans[i+1])->display()) ; execute (->display(); operation fact(n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(2, n div 2 + 1-1) do ( if n mod i = 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) def mark(s,x): for i in range(x+x,len(s),x): s[i]=False def eratosthenes(n): s=[True]*n for x in range(2,int(n**0.5)+1): if s[x]: mark(s,x) return[i for i in range(0,n)if s[i]and i>1] P=eratosthenes(55555) ans=[p for p in P if p % 5==1] print(*ans[: N]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; skip ; var P : OclAny := eratosthenes(55555) ; var ans : Sequence := P->select(p | p mod 5 = 1)->collect(p | (p)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name N)))))))) ]))))))))->display(); operation mark(s : OclAny, x : OclAny) pre: true post: true activity: for i : Integer.subrange(x + x, (s)->size()-1)->select( $x | ($x - x + x) mod x = 0 ) do ( s[i+1] := false); operation eratosthenes(n : OclAny) : OclAny pre: true post: true activity: s := MatrixLib.elementwiseMult(Sequence{ true }, n) ; for x : Integer.subrange(2, ("" + (((n)->pow(0.5))))->toInteger() + 1-1) do ( if s[x+1] then ( mark(s, x) ) else skip) ; return Integer.subrange(0, n-1)->select(i | s[i+1] & i > 1)->collect(i | (i)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) end_mprint=[] for i in range(0,t): n=int(input()) end_print=[] if n % 2==1 : a=1 end_print.append(1) for i in range(1,(n+1)//2): end_print.append(a+2) a+=1 end_print.append(a) a+=1 else : a=0 for i in range(0,n//2): end_print.append(a+2) a+=1 end_print.append(a) a+=1 end_text_1=str(end_print) end_text_2=end_text_1.replace('[','') end_text_3=end_text_2.replace(']','') end_text_4=end_text_3.replace(',','') end_mprint.append(end_text_4) for i in range(0,t): print(end_mprint[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var end_mprint : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var end_print : Sequence := Sequence{} ; if n mod 2 = 1 then ( var a : int := 1 ; execute ((1) : end_print) ; for i : Integer.subrange(1, (n + 1) div 2-1) do ( execute ((a + 2) : end_print) ; a := a + 1 ; execute ((a) : end_print) ; a := a + 1) ) else ( a := 0 ; for i : Integer.subrange(0, n div 2-1) do ( execute ((a + 2) : end_print) ; a := a + 1 ; execute ((a) : end_print) ; a := a + 1) ) ; var end_text var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() : String := ("" + ((end_print))) ; var end_text:= end_text var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger().replace('[', '') : String := end_text var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger().replace('[', '') ; var end_text_3 : String := end_text_2.replace(']', '') ; var end_text_4 : String := end_text_3.replace(',', '') ; execute ((end_text_4) : end_mprint)) ; for i : Integer.subrange(0, t-1) do ( execute (end_mprint[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict from collections import deque from heapq import heappush,heappop import sys import math import bisect import random def LI(): return list(map(int,sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return list(map(list,sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l=[None for i in range(n)] for i in range(n): l[i]=I() return l def LIR(n): l=[None for i in range(n)] for i in range(n): l[i]=LI() return l def SR(n): l=[None for i in range(n)] for i in range(n): l[i]=S() return l def LSR(n): l=[None for i in range(n)] for i in range(n): l[i]=SR() return l mod=1000000007 n=I() f=[i for i in range(55555)] z=2 ans=[] while 1 : if z % 5==1 : ans.append(z) for i in range(2,55555//z+1): if z*i<55555 : f[z*i]=0 for j in range(z+1,55555): if f[j]: z=j break if j==55554 : break print(*ans[: n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : int := 1000000007 ; n := I() ; var f : Sequence := Integer.subrange(0, 55555-1)->select(i | true)->collect(i | (i)) ; var z : int := 2 ; var ans : Sequence := Sequence{} ; while 1 do ( if z mod 5 = 1 then ( execute ((z) : ans) ) else skip ; for i : Integer.subrange(2, 55555 div z + 1-1) do ( if z * i < 55555 then ( f[z * i+1] := 0 ) else skip) ; for j : Integer.subrange(z + 1, 55555-1) do ( if f[j+1] then ( z := j ; break ) else skip) ; if j = 55554 then ( break ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name n)))))))) ]))))))))->display(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["Sequence"])->apply(_x) )); operation S() : OclAny pre: true post: true activity: return OclType["Sequence"]((OclFile["System.in"]).readLine())->front(); operation IR(n : OclAny) : OclAny pre: true post: true activity: var l : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; for i : Integer.subrange(0, n-1) do ( l[i+1] := I()) ; return l; operation LIR(n : OclAny) : OclAny pre: true post: true activity: l := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; for i : Integer.subrange(0, n-1) do ( l[i+1] := LI()) ; return l; operation SR(n : OclAny) : OclAny pre: true post: true activity: l := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; for i : Integer.subrange(0, n-1) do ( l[i+1] := S()) ; return l; operation LSR(n : OclAny) : OclAny pre: true post: true activity: l := Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)) ; for i : Integer.subrange(0, n-1) do ( l[i+1] := SR()) ; return l; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def is_prime(n): if n==1 : return False for k in range(2,int(math.sqrt(n))+1): if n % k==0 : return False return True x=[i for i in range(2,55556)if is_prime(i)and i % 5==1] print(*x[: int(input())]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var x : Sequence := Integer.subrange(2, 55556-1)->select(i | is_prime(i) & i mod 5 = 1)->collect(i | (i)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))) ]))))))))->display(); operation is_prime(n : OclAny) : OclAny pre: true post: true activity: if n = 1 then ( return false ) else skip ; for k : Integer.subrange(2, ("" + (((n)->sqrt())))->toInteger() + 1-1) do ( if n mod k = 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np import sys,collections as cl def seachPrimeNum(N): max=int(np.sqrt(N)) seachList=[i for i in range(2,N+1)] primeNum=[] while seachList[0]<=max : primeNum.append(seachList[0]) tmp=seachList[0] seachList=[i for i in seachList if i % tmp!=0] primeNum.extend(seachList) return primeNum Max=sys.maxsize def l(): return list(map(int,input().split())) def m(): return map(int,input().split()) def s(x): a=[] aa=x[i] su=1 for i in range(len(x)-1): if aa==x[i+1]: a.append([aa,su]) aa=x[i+1] su=1 else : su+=1 a.append([aa,su]) return a n=int(input()) a=seachPrimeNum(55555) aa=[] for i in range(len(a)): if a[i]% 5==1 : aa.append(a[i]) print(" ".join(map(str,aa[: n]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var Max : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := seachPrimeNum(55555) ; aa := Sequence{} ; for i : Integer.subrange(0, (a)->size()-1) do ( if a[i+1] mod 5 = 1 then ( execute ((a[i+1]) : aa) ) else skip) ; execute (StringLib.sumStringsWithSeparator(((aa.subrange(1,n))->collect( _x | (OclType["String"])->apply(_x) )), " "))->display(); operation seachPrimeNum(N : OclAny) : OclAny pre: true post: true activity: var max : int := ("" + ((MatrixLib.elementwiseApply(N, lambda x : double in (x->sqrt())))))->toInteger() ; var seachList : Sequence := Integer.subrange(2, N + 1-1)->select(i | true)->collect(i | (i)) ; var primeNum : Sequence := Sequence{} ; while (seachList->first()->compareTo(max)) <= 0 do ( execute ((seachList->first()) : primeNum) ; var tmp : OclAny := seachList->first() ; seachList := seachList->select(i | i mod tmp /= 0)->collect(i | (i))) ; primeNum := primeNum->union(seachList) ; return primeNum; operation l() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation m() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation s(x : OclAny) : OclAny pre: true post: true activity: var a : Sequence := Sequence{} ; var aa : OclAny := x[i+1] ; var su : int := 1 ; for i : Integer.subrange(0, (x)->size() - 1-1) do ( if aa = x[i + 1+1] then ( execute ((Sequence{aa}->union(Sequence{ su })) : a) ; aa := x[i + 1+1] ; su := 1 ) else ( su := su + 1 )) ; execute ((Sequence{aa}->union(Sequence{ su })) : a) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findElement(arr,n): prefixSum=[0]*n prefixSum[0]=arr[0] for i in range(1,n): prefixSum[i]=prefixSum[i-1]+arr[i] suffixSum=[0]*n suffixSum[n-1]=arr[n-1] for i in range(n-2,-1,-1): suffixSum[i]=suffixSum[i+1]+arr[i] for i in range(1,n-1,1): if prefixSum[i]==suffixSum[i]: return arr[i] return-1 if __name__=="__main__" : arr=[1,4,2,5] n=len(arr) print(findElement(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{4}->union(Sequence{2}->union(Sequence{ 5 }))) ; n := (arr)->size() ; execute (findElement(arr, n))->display() ) else skip; operation findElement(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var prefixSum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; prefixSum->first() := arr->first() ; for i : Integer.subrange(1, n-1) do ( prefixSum[i+1] := prefixSum[i - 1+1] + arr[i+1]) ; var suffixSum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; suffixSum[n - 1+1] := arr[n - 1+1] ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( suffixSum[i+1] := suffixSum[i + 1+1] + arr[i+1]) ; for i : Integer.subrange(1, n - 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if prefixSum[i+1] = suffixSum[i+1] then ( return arr[i+1] ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- W,H,x,y,r=[int(i)for i in input().split()] if 0<=x-r and x+r<=W and 0<=y-r and H>=y+r : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var W : OclAny := null; var H : OclAny := null; var x : OclAny := null; var y : OclAny := null; var r : OclAny := null; Sequence{W,H,x,y,r} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if 0 <= x - r & (x + r->compareTo(W)) <= 0 & 0 <= y - r & (H->compareTo(y + r)) >= 0 then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,s=(int(i)for i in input().split()) a=[int(i)for i in input().split()] res="YES" if s>=sum(a)-max(a)else "NO" print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var res : String := if (s->compareTo((a)->sum() - (a)->max())) >= 0 then "YES" else "NO" endif ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,s=map(int,input().split()) print(["NO","YES"][sum(sorted(map(int,input().split()))[:-1])<=s]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Sequence{"NO"}->union(Sequence{ "YES" })->select(((sorted((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->front())->sum()->compareTo(s)) <= 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,s=map(int,input().split()) w=sorted(map(int,input().split())) print("YES" if sum(w[:-1])<=s else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; execute (if ((w->front())->sum()->compareTo(s)) <= 0 then "YES" else "NO" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import* from decimal import* from operator import index from re import I import sys from tkinter import N input_=sys.stdin.readline def _input(): return map(int,input().split()) def _list(): return list(map(int,input().split())) def solves(): n,m=_input() lst=sorted(_list()) s=sum(lst)-lst[-1] if(s<=m): print("YES") else : print("NO") t=1 for _ in range(0,t): solves() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var input_ : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solves()); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation _list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation solves() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := _input() ; var lst : Sequence := _list()->sort() ; var s : double := (lst)->sum() - lst->last() ; if ((s->compareTo(m)) <= 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) l=[int(i)for i in input().split()] l.sort() count=0 for i in l : if i<=k : count+=1 k-=i if count>=n-1 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; l := l->sort() ; var count : int := 0 ; for i : l do ( if (i->compareTo(k)) <= 0 then ( count := count + 1 ; k := k - i ) else skip) ; if (count->compareTo(n - 1)) >= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): BASE=10**14 SEARCH_RANGE=10000000 MODULUS=1234567891011 iscomposite=[False]*SEARCH_RANGE primes=eulerlib.list_primes(eulerlib.sqrt(BASE+SEARCH_RANGE)) for p in primes : for i in range((BASE+p-1)//p*p-BASE,len(iscomposite),p): iscomposite[i]=True def next_prime(n): while True : n+=1 if n>=len(iscomposite): raise AssertionError("Search range exhausted") if not iscomposite[n]: return n ans=0 p=0 for i in range(100000): p=next_prime(p) ans=(ans+fibonacci_mod(BASE+p,MODULUS))% MODULUS return str(ans) def fibonacci_mod(n,mod): a,b=0,1 binary=bin(n)[2 :] for bit in binary : a,b=a*(b*2-a),a*a+b*b if bit=="1" : a,b=b,a+b a %=mod b %=mod return a if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var BASE : double := (10)->pow(14) ; var SEARCH_RANGE : int := 10000000 ; var MODULUS : int := 1234567891011 ; var iscomposite : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, SEARCH_RANGE) ; var primes : OclAny := eulerlib.list_primes(eulerlib.sqrt(BASE + SEARCH_RANGE)) ; for p : primes do ( for i : Integer.subrange((BASE + p - 1) div p * p - BASE, (iscomposite)->size()-1)->select( $x | ($x - (BASE + p - 1) div p * p - BASE) mod p = 0 ) do ( iscomposite[i+1] := true)) ; skip ; var ans : int := 0 ; var p : int := 0 ; for i : Integer.subrange(0, 100000-1) do ( p := next_prime(p) ; ans := (ans + fibonacci_mod(BASE + p, MODULUS)) mod MODULUS) ; return ("" + ((ans))); operation fibonacci_mod(n : OclAny, mod : OclAny) : OclAny pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{0,1} ; var binary : OclAny := bin(n).subrange(2+1) ; for bit : binary do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{a * (b * 2 - a),a * a + b * b} ; if bit = "1" then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a + b} ) else skip ; a := a mod mod ; b := b mod mod) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) result=[] for i in range(t): n=int(input()) if(n % 2==0): ch='' init=1 else : ch='1 ' init=2 for j in range(init,n+1,2): ch+=str(j+1)+' '+str(j)+' ' result.append(ch) for i in result : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var result : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n mod 2 = 0) then ( var ch : String := '' ; var init : int := 1 ) else ( ch := '1 ' ; init := 2 ) ; for j : Integer.subrange(init, n + 1-1)->select( $x | ($x - init) mod 2 = 0 ) do ( ch := ch + ("" + ((j + 1))) + ' ' + ("" + ((j))) + ' ') ; execute ((ch) : result)) ; for i : result do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : a=10 b=5 if b>0 : while b>0 : a=a+1 b=b-1 if b<0 : while b<0 : a=a-1 b=b+1 print("Sum is: ",a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var a : int := 10 ; var b : int := 5 ; if b > 0 then ( while b > 0 do ( a := a + 1 ; b := b - 1) ) else skip ; if b < 0 then ( while b < 0 do ( a := a - 1 ; b := b + 1) ) else skip ; execute ("Sum is: ")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def subsetCount(arr,n): return 1<union(Sequence{2}->union(Sequence{ 3 })) ; n := (A)->size() ; execute (subsetCount(A, n))->display(); operation subsetCount(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: return 1 * (2->pow(n)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def sortArray(arr,n,A,B,C): for i in range(n): arr[i]=(A*arr[i]*arr[i]+B*arr[i]+C) index=-(sys.maxsize-1) maximum=-(sys.maxsize-1) for i in range(n): if maximumindex : if arr[i]index : new_arr[k]=arr[j] k+=1 j-=1 new_arr[n-1]=maximum for i in range(n): arr[i]=new_arr[i] arr=[-21,-15,12,13,14] n=len(arr) A=-6 B=-7 C=2 sortArray(arr,n,A,B,C) print("Array after sorting is:") for i in range(n): print(arr[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{-21}->union(Sequence{-15}->union(Sequence{12}->union(Sequence{13}->union(Sequence{ 14 })))) ; n := (arr)->size() ; A := -6 ; B := -7 ; C := 2 ; sortArray(arr, n, A, B, C) ; execute ("Array after sorting is:")->display() ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); operation sortArray(arr : OclAny, n : OclAny, A : OclAny, B : OclAny, C : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( arr[i+1] := (A * arr[i+1] * arr[i+1] + B * arr[i+1] + C)) ; var index : double := -((trailer . (name maxsize)) - 1) ; var maximum : double := -((trailer . (name maxsize)) - 1) ; for i : Integer.subrange(0, n-1) do ( if (maximum->compareTo(arr[i+1])) < 0 then ( index := i ; maximum := arr[i+1] ) else skip) ; var i : int := 0; var j : double := n - 1; ; var new_arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var k : int := 0 ; while (i->compareTo(index)) < 0 & (j->compareTo(index)) > 0 do ( if (arr[i+1]->compareTo(arr[j+1])) < 0 then ( new_arr[k+1] := arr[i+1] ; k := k + 1 ; i := i + 1 ) else ( new_arr[k+1] := arr[j+1] ; k := k + 1 ; j := j - 1 )) ; while (i->compareTo(index)) < 0 do ( new_arr[k+1] := arr[i+1] ; k := k + 1 ; i := i + 1) ; while (j->compareTo(index)) > 0 do ( new_arr[k+1] := arr[j+1] ; k := k + 1 ; j := j - 1 ; new_arr[n - 1+1] := maximum) ; for i : Integer.subrange(0, n-1) do ( arr[i+1] := new_arr[i+1]); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- W,H,x,y,r=map(int,input().split()) if xcollect( _x | (OclType["int"])->apply(_x) ) ; if (x->compareTo(r)) < 0 or (W->compareTo(x + r)) < 0 then ( execute ('No')->display() ) else (if (y->compareTo(r)) < 0 or (H->compareTo(y + r)) < 0 then ( execute ('No')->display() ) else ( execute ('Yes')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break mes=list(input()) mes=[ord(c)-ord("a")for c in mes] ablst=[tuple(map(int,input().split()))for _ in range(n)] ablst.reverse() for a,b in ablst : a-=1 b-=1 mes[b],mes[a]=(mes[a]+(b-a))% 26,(mes[b]+(b-a))% 26 mes=[chr(i+ord("a"))for i in mes] print("".join(mes)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var mes : Sequence := ((OclFile["System.in"]).readLine())->characters() ; mes := mes->select(c | true)->collect(c | ((c)->char2byte() - ("a")->char2byte())) ; var ablst : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; ablst := ablst->reverse() ; for _tuple : ablst do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); a := a - 1 ; b := b - 1 ; var mes[b+1] : OclAny := null; var mes[a+1] : OclAny := null; Sequence{mes[b+1],mes[a+1]} := Sequence{(mes[a+1] + (b - a)) mod 26,(mes[b+1] + (b - a)) mod 26}) ; mes := mes->select(i | true)->collect(i | ((i + ("a")->char2byte())->byte2char())) ; execute (StringLib.sumStringsWithSeparator((mes), ""))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if n==0 : break s=list(input()) c=[list(map(int,input().split()))for _ in range(n)] for i,j in c[: :-1]: d,i,j=j-i,i-1,j-1 s[i],s[j]=chr((ord(s[j])-97+d)% 26+97),chr((ord(s[i])-97+d)% 26+97) print("".join(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var c : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for _tuple : c(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); var d : OclAny := null; var i : OclAny := null; var j : OclAny := null; Sequence{d,i,j} := Sequence{j - i,i - 1,j - 1} ; var s[i+1] : OclAny := null; var s[j+1] : OclAny := null; Sequence{s[i+1],s[j+1]} := Sequence{(((s[j+1])->char2byte() - 97 + d) mod 26 + 97)->byte2char(),(((s[i+1])->char2byte() - 97 + d) mod 26 + 97)->byte2char()}) ; execute (StringLib.sumStringsWithSeparator((s), ""))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def previousFibonacci(n): a=n/((1+sqrt(5))/2.0) return round(a) def nextFibonacci(n): a=n*(1+sqrt(5))/2.0 return round(a) def isPerfectSquare(x): s=sqrt(x) return(s*s==x) def isFibonacci(n): return(isPerfectSquare(5*n*n+4)or isPerfectSquare(5*n*n-4)) def countFibonacciPairs(arr,n): res=0 for i in range(n): for j in range(i+1,n): if(isFibonacci(arr[i])and isFibonacci(arr[j])): prevFib=previousFibonacci(arr[i]) nextFib=nextFibonacci(arr[i]) if(prevFib==arr[j]or nextFib==arr[j]): res+=1 return res a=[3,5,8,11] n=len(a) print(countFibonacciPairs(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; a := Sequence{3}->union(Sequence{5}->union(Sequence{8}->union(Sequence{ 11 }))) ; n := (a)->size() ; execute (countFibonacciPairs(a, n))->display(); operation previousFibonacci(n : OclAny) : OclAny pre: true post: true activity: var a : double := n / ((1 + sqrt(5)) / 2.0) ; return (a)->round(); operation nextFibonacci(n : OclAny) : OclAny pre: true post: true activity: a := n * (1 + sqrt(5)) / 2.0 ; return (a)->round(); operation isPerfectSquare(x : OclAny) : OclAny pre: true post: true activity: var s : OclAny := sqrt(x) ; return (s * s = x); operation isFibonacci(n : OclAny) : OclAny pre: true post: true activity: return (isPerfectSquare(5 * n * n + 4) or isPerfectSquare(5 * n * n - 4)); operation countFibonacciPairs(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if (isFibonacci(arr[i+1]) & isFibonacci(arr[j+1])) then ( var prevFib : OclAny := previousFibonacci(arr[i+1]) ; var nextFib : OclAny := nextFibonacci(arr[i+1]) ; if (prevFib = arr[j+1] or nextFib = arr[j+1]) then ( res := res + 1 ) else skip ) else skip)) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def perfectCube(N): cube_root=round(N**(1/3)); if cube_root*cube_root*cube_root==N : print("Yes"); return ; else : print("NO"); return ; if __name__=="__main__" : N=125 ; perfectCube(N); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := 125; ; perfectCube(N); ) else skip; operation perfectCube(N : OclAny) : OclAny pre: true post: true activity: var cube_root : double := ((N)->pow((1 / 3)))->round(); ; if cube_root * cube_root * cube_root = N then ( execute ("Yes")->display(); ; return; ) else ( execute ("NO")->display(); ; return; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt N=100005 MAX=1000002 lpd=[0 for i in range(MAX)] def preCompute(): lpd[0],lpd[1]=1,1 for i in range(2,mt.ceil(mt.sqrt(MAX))): for j in range(2*i,MAX,i): if(lpd[j]==0): lpd[j]=i for i in range(2,MAX): if(lpd[i]==0): lpd[i]=i def maxLengthSubsequence(arr,n): dp=[1 for i in range(N+1)] pos=dict() for i in range(1,n): while(arr[i]>1): p=lpd[arr[i]] if(p in pos.keys()): dp[i]=max(dp[i],1+dp[pos[p]]) pos[p]=i while(arr[i]% p==0): arr[i]//=p ans=1 for i in range(1,n+1): ans=max(ans,dp[i]) return ans arr=[13,2,8,6,3,1,9] n=len(arr) preCompute() print(maxLengthSubsequence(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 100005 ; var MAX : int := 1000002 ; var lpd : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)) ; skip ; skip ; arr := Sequence{13}->union(Sequence{2}->union(Sequence{8}->union(Sequence{6}->union(Sequence{3}->union(Sequence{1}->union(Sequence{ 9 })))))) ; n := (arr)->size() ; preCompute() ; execute (maxLengthSubsequence(arr, n))->display(); operation preCompute() pre: true post: true activity: var lpd->first() : OclAny := null; var lpd[1+1] : OclAny := null; Sequence{lpd->first(),lpd[1+1]} := Sequence{1,1} ; for i : Integer.subrange(2, mt.ceil(mt.sqrt(MAX))-1) do ( for j : Integer.subrange(2 * i, MAX-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ( if (lpd[j+1] = 0) then ( lpd[j+1] := i ) else skip)) ; for i : Integer.subrange(2, MAX-1) do ( if (lpd[i+1] = 0) then ( lpd[i+1] := i ) else skip); operation maxLengthSubsequence(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (1)) ; var pos : Map := (arguments ( )) ; for i : Integer.subrange(1, n-1) do ( while (arr[i+1] > 1) do ( var p : OclAny := lpd[arr[i+1]+1] ; if ((pos.keys())->includes(p)) then ( dp[i+1] := Set{dp[i+1], 1 + dp[pos[p+1]+1]}->max() ) else skip ; pos[p+1] := i ; while (arr[i+1] mod p = 0) do ( arr[i+1] := arr[i+1] div p))) ; var ans : int := 1 ; for i : Integer.subrange(1, n + 1-1) do ( ans := Set{ans, dp[i+1]}->max()) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) arr=[0 for i in range(N)] for i in range(M): A,B=map(int,input().split()) arr[A-1]+=1 arr[B-1]+=1 for j in arr : print(j) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, M-1) do ( var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; arr[A - 1+1] := arr[A - 1+1] + 1 ; arr[B - 1+1] := arr[B - 1+1] + 1) ; for j : arr do ( execute (j)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=[int(x)for x in input().split()] array=[] for i in range(num[1]): array.append([int(x)for x in input().split()]) res=[0 for x in range(num[0])] for j in array : res[j[0]-1]=res[j[0]-1]+1 res[j[1]-1]=res[j[1]-1]+1 for k in res : print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var array : Sequence := Sequence{} ; for i : Integer.subrange(0, num[1+1]-1) do ( execute ((input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) : array)) ; var res : Sequence := Integer.subrange(0, num->first()-1)->select(x | true)->collect(x | (0)) ; for j : array do ( res[j->first() - 1+1] := res[j->first() - 1+1] + 1 ; res[j[1+1] - 1+1] := res[j[1+1] - 1+1] + 1) ; for k : res do ( execute (k)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=*map(int,input().split()), l=0 r=n while l+10 and a[r-2]>a[r-1]: r-=1 print('YNEOS'[len({*a[l : r]})!=1 : : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := (testlist_star_expr (star_expr * (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))) ,) ; var l : int := 0 ; var r : int := n ; while (l + 1->compareTo(n)) < 0 & (a[l+1]->compareTo(a[l + 1+1])) < 0 do ( l := l + 1) ; while r > 0 & (a[r - 2+1]->compareTo(a[r - 1+1])) > 0 do ( r := r - 1) ; execute ('YNEOS'(subscript (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom { (dictorsetmaker (testlist_comp (star_expr * (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name l)))))) : (test (logical_test (comparison (expr (atom (name r)))))))) ])))))) }))))))) ))))) != (comparison (expr (atom (number (integer 1)))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(inp): (N,M)=map(int,inp.readline().split(' ')) AB=[list(map(int,inp.readline().split(' ')))for i in range(M)] roads=[0 for i in range(N)] for ab in AB : roads[ab[0]-1]+=1 roads[ab[1]-1]+=1 for i in range(N): print(roads[i]) return "" def main(): result=solve(sys.stdin) if result : print(result) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(inp : OclAny) pre: true post: true activity: ; var Sequence{N, M} : Sequence := (inp.readLine().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var AB : Sequence := Integer.subrange(0, M-1)->select(i | true)->collect(i | (((inp.readLine().split(' '))->collect( _x | (OclType["int"])->apply(_x) )))) ; var roads : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; for ab : AB do ( roads[ab->first() - 1+1] := roads[ab->first() - 1+1] + 1 ; roads[ab[1+1] - 1+1] := roads[ab[1+1] - 1+1] + 1) ; for i : Integer.subrange(0, N-1) do ( execute (roads[i+1])->display()) ; return ""; operation main() pre: true post: true activity: var result : OclAny := solve(OclFile["System.in"]) ; if result then ( execute (result)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n,m=map(int,input().split()) ab=[] for i in range(m): a,b=map(int,input().split()) ab.append(a) ab.append(b) ab_cnt=Counter(ab) for i in range(n): print(ab_cnt[i+1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ab : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a) : ab) ; execute ((b) : ab)) ; var ab_cnt : OclAny := Counter(ab) ; for i : Integer.subrange(0, n-1) do ( execute (ab_cnt[i + 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- W,H,x,y,r=[int(x)for x in input().split()] if x-r>=0 and x+r<=W and y-r>=0 and y+r<=H : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var W : OclAny := null; var H : OclAny := null; var x : OclAny := null; var y : OclAny := null; var r : OclAny := null; Sequence{W,H,x,y,r} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if x - r >= 0 & (x + r->compareTo(W)) <= 0 & y - r >= 0 & (y + r->compareTo(H)) <= 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a_list=[] b_list=[] for i in range(m): a,b=map(int,input().split()) a_list.append(a) b_list.append(b) for i in range(1,n+1): cnt=0 for j in range(m): if a_list[j]==i or b_list[j]==i : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a_list : Sequence := Sequence{} ; var b_list : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a) : a_list) ; execute ((b) : b_list)) ; for i : Integer.subrange(1, n + 1-1) do ( var cnt : int := 0 ; for j : Integer.subrange(0, m-1) do ( if a_list[j+1] = i or b_list[j+1] = i then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def prod(arr): ans=1 for n in arr : ans*=n return ans def solve(A): A.sort() ans=float("-INF") for i in range(5): ans=max(ans,prod(A[-i-1 :])*prod(A[: 4-i])) return ans t=int(input()) for _ in range(t): n=int(input()) arr=list(map(int,input().split()))[: n] print(solve(arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; arr := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ; execute (solve(arr))->display()); operation prod(arr : OclAny) : OclAny pre: true post: true activity: var ans : int := 1 ; for n : arr do ( ans := ans * n) ; return ans; operation solve(A : OclAny) : OclAny pre: true post: true activity: A := A->sort() ; ans := ("" + (("-INF")))->toReal() ; for i : Integer.subrange(0, 5-1) do ( ans := Set{ans, prod(A.subrange(-i - 1+1)) * prod(A.subrange(1,4 - i))}->max()) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def _input(): return map(int,input().split()) def f(): n=int(input()) lst=sorted(list(_input())) r=[0]*6 r[0]=lst[0]*lst[1]*lst[2]*lst[3]*lst[4] r[1]=lst[-1]*lst[-2]*lst[-3]*lst[-4]*lst[-5] r[2]=lst[0]*lst[1]*lst[-1]*lst[-2]*lst[-3] r[3]=lst[0]*lst[1]*lst[2]*lst[-1]*lst[-2] r[4]=lst[0]*lst[1]*lst[2]*lst[3]*lst[-1] r[5]=lst[0]*lst[-4]*lst[-2]*lst[-3]*lst[-1] print(max(r)) for _ in range(int(input())): f() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( f()); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation f() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := (_input())->sort() ; var r : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 6) ; r->first() := lst->first() * lst[1+1] * lst[2+1] * lst[3+1] * lst[4+1] ; r[1+1] := lst->last() * lst->front()->last() * lst->reverse()->at(-(-3)) * lst->reverse()->at(-(-4)) * lst->reverse()->at(-(-5)) ; r[2+1] := lst->first() * lst[1+1] * lst->last() * lst->front()->last() * lst->reverse()->at(-(-3)) ; r[3+1] := lst->first() * lst[1+1] * lst[2+1] * lst->last() * lst->front()->last() ; r[4+1] := lst->first() * lst[1+1] * lst[2+1] * lst[3+1] * lst->last() ; r[5+1] := lst->first() * lst->reverse()->at(-(-4)) * lst->front()->last() * lst->reverse()->at(-(-3)) * lst->last() ; execute ((r)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import count t=int(input()) for i in range(t): n=int(input()) a=[int(x)for x in input().split()] a.sort() l=[] for k in range(6): l1=1 for beg in range(0,5-k): l1*=a[beg] for ende in range(0,k): l1*=a[len(a)-1-ende] l.append(l1) print(max(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; a := a->sort() ; var l : Sequence := Sequence{} ; for k : Integer.subrange(0, 6-1) do ( var l1 : int := 1 ; for beg : Integer.subrange(0, 5 - k-1) do ( l1 := l1 * a[beg+1]) ; for ende : Integer.subrange(0, k-1) do ( l1 := l1 * a[(a)->size() - 1 - ende+1]) ; execute ((l1) : l)) ; execute ((l)->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for i in[*open(0)][2 : : 2]: a=sorted(map(int,i.split(' '))) print(max(math.prod(a[: i]+a[i-5 :])for i in range(5))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var a : Sequence := (i.split(' '))->collect( _x | (OclType["int"])->apply(_x) )->sort() ; execute (((argument (test (logical_test (comparison (expr (atom (name math)) (trailer . (name prod) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 5)))))))) :)) ]))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 5))))))))) )))))))))->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq def check(A,B,N): pq1=[] pq2=[] for i in range(N): heapq.heappush(pq1,-A[i]) for i in range(N): heapq.heappush(pq2,-B[i]) c=0 for i in range(N): if-pq1[0]>-pq2[0]: c+=1 heapq.heappop(pq1) heapq.heappop(pq2) else : if len(pq2)==0 : break heapq.heappop(pq2) return(c) A=[10,3,7,5,8] B=[8,6,2,5,9] N=len(A) print(check(A,B,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; A := Sequence{10}->union(Sequence{3}->union(Sequence{7}->union(Sequence{5}->union(Sequence{ 8 })))) ; B := Sequence{8}->union(Sequence{6}->union(Sequence{2}->union(Sequence{5}->union(Sequence{ 9 })))) ; N := (A)->size() ; execute (check(A, B, N))->display(); operation check(A : OclAny, B : OclAny, N : OclAny) : OclAny pre: true post: true activity: var pq1 : Sequence := Sequence{} ; var pq2 : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( heapq.heappush(pq1, -A[i+1])) ; for i : Integer.subrange(0, N-1) do ( heapq.heappush(pq2, -B[i+1])) ; var c : int := 0 ; for i : Integer.subrange(0, N-1) do ( if (-pq1->first()->compareTo(-pq2->first())) > 0 then ( c := c + 1 ; heapq.heappop(pq1) ; heapq.heappop(pq2) ) else ( if (pq2)->size() = 0 then ( break ) else skip ; heapq.heappop(pq2) )) ; return (c); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) lst=list(map(int,input().split())) lst.sort() ans=0 for i in range(n): ans+=(lst[i]*lst[i]*(1-i % 2*2)) z=round(math.asin(1)*2*ans,10) if z<0 : print(z*-1) else : print(z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; lst := lst->sort() ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( ans := ans + (lst[i+1] * lst[i+1] * (1 - i mod 2 * 2))) ; var z : double := MathLib.roundN((1)->asin() * 2 * ans, 10) ; if z < 0 then ( execute (z * -1)->display() ) else ( execute (z)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() L=sorted(int(x)*int(x)for x in input().split()) print(3.1415926536*(sum(L[: :-2])-sum(L[-2 : :-2]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var L : Sequence := (argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) * (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))->sort() ; execute (3.1415926536 * ((L(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 2))))))))))->sum() - (L(subscript (test (logical_test (comparison (expr (atom - (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 2))))))))))->sum()))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from collections import Counter n=int(input()) w=list(map(int,input().split())) d=max(w) a=w.index(d) b=sorted(w[: a]) c=sorted(w[a :],reverse=True) b1=Counter(b) c1=Counter(c) for i in b1 : if i!=d and b1[i]>1 : print("NO") break else : for i in c1 : if i!=d and c1[i]>1 : print("NO") break else : if w!=b+c : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := (w)->max() ; var a : int := w->indexOf(d) - 1 ; var b : Sequence := w.subrange(1,a)->sort() ; var c : Sequence := w.subrange(a+1)->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var b1 : OclAny := Counter(b) ; var c1 : OclAny := Counter(c) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name b1))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name i)))) != (comparison (expr (atom (name d)))))) and (logical_test (comparison (comparison (expr (atom (name b1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) > (comparison (expr (atom (number (integer 1))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name c1))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name i)))) != (comparison (expr (atom (name d)))))) and (logical_test (comparison (comparison (expr (atom (name c1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) > (comparison (expr (atom (number (integer 1))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name w)))) != (comparison (expr (expr (atom (name b))) + (expr (atom (name c)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) ))))))))))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline def ii(): return int(input()) def li(): return list(map(int,input().split())) from math import sqrt def perfect_sq(n): x=int(sqrt(n)) while x*xn : x-=1 return(x*x==n) n=ii() a=li() a.sort(reverse=True) from math import pi ans=0 for i in range(n): if i % 2 : ans-=pi*(a[i]**2) else : ans+=pi*(a[i]**2) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; skip ; skip ; skip ; skip ; n := ii() ; var a : OclAny := li() ; a := a->sort() ; skip ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if i mod 2 then ( ans := ans - pi * ((a[i+1])->pow(2)) ) else ( ans := ans + pi * ((a[i+1])->pow(2)) )) ; execute (ans)->display(); operation ii() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation li() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation perfect_sq(n : OclAny) : OclAny pre: true post: true activity: var x : int := ("" + ((sqrt(n))))->toInteger() ; while (x * x->compareTo(n)) < 0 do ( x := x + 1) ; while (x * x->compareTo(n)) > 0 do ( x := x - 1) ; return (x * x = n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPrime(n): if n<=1 : return False for i in range(2,n): if n % i==0 : return False return True def findPrime(n): num=n+1 while(num): if isPrime(num): return num num+=1 return 0 def minNumber(arr): s=0 for i in range(0,len(arr)): s+=arr[i] if isPrime(s): return 0 num=findPrime(s) return num-s arr=[2,4,6,8,12] print(minNumber(arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; arr := Sequence{2}->union(Sequence{4}->union(Sequence{6}->union(Sequence{8}->union(Sequence{ 12 })))) ; execute (minNumber(arr))->display(); operation isPrime(n : OclAny) : OclAny pre: true post: true activity: if n <= 1 then ( return false ) else skip ; for i : Integer.subrange(2, n-1) do ( if n mod i = 0 then ( return false ) else skip) ; return true; operation findPrime(n : OclAny) : OclAny pre: true post: true activity: var num : OclAny := n + 1 ; while (num) do ( if isPrime(num) then ( return num ) else skip ; num := num + 1) ; return 0; operation minNumber(arr : OclAny) : OclAny pre: true post: true activity: var s : int := 0 ; for i : Integer.subrange(0, (arr)->size()-1) do ( s := s + arr[i+1]) ; if isPrime(s) then ( return 0 ) else skip ; num := findPrime(s) ; return num - s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=sorted(list(map(int,input().split())),reverse=True) ans=0 i=0 pi=3.1415926536 while itoInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var ans : int := 0 ; var i : int := 0 ; var pi : double := 3.1415926536 ; while (i->compareTo(n)) < 0 do ( if i mod 2 = 0 then ( ans := ans + pi * l[i+1] * l[i+1] ) else ( ans := ans - pi * l[i+1] * l[i+1] ) ; i := i + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): n=int(input()) arr=list(map(int,input().split())) arr.sort(reverse=True) res=0 for i in range(len(arr)): cur=arr[i]**2 if i % 2==0 : res+=cur else : res-=cur print(res*math.pi) def main(): t=1 for _ in range(t): solution() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; main(); operation solution() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := arr->sort() ; var res : int := 0 ; for i : Integer.subrange(0, (arr)->size()-1) do ( var cur : double := (arr[i+1])->pow(2) ; if i mod 2 = 0 then ( res := res + cur ) else ( res := res - cur )) ; execute (res * )->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- line=input().split() m=int(line[0]) n=int(line[1]) result=0 for current in range(m,0,-1): result+=current*(pow(current/m,n)-pow((current-1)/m,n)) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var line : OclAny := input().split() ; var m : int := ("" + ((line->first())))->toInteger() ; var n : int := ("" + ((line[1+1])))->toInteger() ; var result : int := 0 ; for current : Integer.subrange(0 + 1, m)->reverse() do ( result := result + current * ((current / m)->pow(n) - ((current - 1) / m)->pow(n))) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,n=map(int,input().split()) expected_max=m for i in range(0,m): expected_max-=pow((i/m),n) print(expected_max) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var expected_max : OclAny := m ; for i : Integer.subrange(0, m-1) do ( expected_max := expected_max - ((i / m))->pow(n)) ; execute (expected_max)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- entrada=input() itens=entrada.split() m,n=float(itens[0]),int(itens[1]) t=1 esperado=0 while(t<=m): esperado+=t*((t/m)**n-((t-1)/m)**n) t+=1 print(esperado) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var entrada : String := (OclFile["System.in"]).readLine() ; var itens : OclAny := entrada.split() ; var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := Sequence{("" + ((itens->first())))->toReal(),("" + ((itens[1+1])))->toInteger()} ; var t : int := 1 ; var esperado : int := 0 ; while ((t->compareTo(m)) <= 0) do ( esperado := esperado + t * (((t / m))->pow(n) - (((t - 1) / m))->pow(n)) ; t := t + 1) ; execute (esperado)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def main(): txt=input() txt=txt.split() m=int(txt[0]) n=int(txt[1]) p=0.0 i=m while(i): p=p+(pow(i/m,n)-pow((i-1)/m,n))*i i-=1 print(f'{p:.16}') if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var txt : String := (OclFile["System.in"]).readLine() ; txt := txt.split() ; var m : int := ("" + ((txt->first())))->toInteger() ; var n : int := ("" + ((txt[1+1])))->toInteger() ; var p : double := 0.0 ; var i : int := m ; while (i) do ( p := p + ((i / m)->pow(n) - ((i - 1) / m)->pow(n)) * i ; i := i - 1) ; execute (StringLib.formattedString('{p:.16}'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def main(): txt=input() txt=txt.split() m=int(txt[0]) n=int(txt[1]) p=0.0 i=m while(i): p=p+(pow(i/m,n)-pow((i-1)/m,n))*i i-=1 print(f'{p:.16}') if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var txt : String := (OclFile["System.in"]).readLine() ; txt := txt.split() ; var m : int := ("" + ((txt->first())))->toInteger() ; var n : int := ("" + ((txt[1+1])))->toInteger() ; var p : double := 0.0 ; var i : int := m ; while (i) do ( p := p + ((i / m)->pow(n) - ((i - 1) / m)->pow(n)) * i ; i := i - 1) ; execute (StringLib.formattedString('{p:.16}'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(S,X): A=(S-X)//2 a=0 b=0 for i in range(64): Xi=(X &(1<0): a=((1<0 and Ai==0): a=((1<display() ; return ) ) ) ) ; execute ("a=")->display() ; execute ("b=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) b=list(map(int,input().split())) d={} for i in range(n): if i-b[i]in d : d[i-b[i]].append(i) else : d[i-b[i]]=[i] mx=0 for x in d : r=0 for m in d[x]: r+=b[m] mx=max(mx,r) print(mx) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( if (d)->includes(i - b[i+1]) then ( (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ) else ( d[i - b[i+1]+1] := Sequence{ i } )) ; var mx : int := 0 ; for x : d do ( var r : int := 0 ; for m : d[x+1] do ( r := r + b[m+1]) ; mx := Set{mx, r}->max()) ; execute (mx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) h=list(map(int,input().split())) p=0 s=0 for i in range(n-1): if h[i]=1 : print("NO") quit() if p>=1 : print("NO") quit() elif h[i]>h[i+1]: p+=1 elif h[i]==h[i+1]: s+=1 if p>=1 : print("NO") quit() print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var h : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var p : int := 0 ; var s : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if (h[i+1]->compareTo(h[i + 1+1])) < 0 then ( if s >= 1 then ( execute ("NO")->display() ; quit() ) else skip ; if p >= 1 then ( execute ("NO")->display() ; quit() ) else skip ) else (if (h[i+1]->compareTo(h[i + 1+1])) > 0 then ( p := p + 1 ) else (if h[i+1] = h[i + 1+1] then ( s := s + 1 ; if p >= 1 then ( execute ("NO")->display() ; quit() ) else skip ) else skip ) ) ) ; execute ("YES")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def compositeProduct(arr,n): max_val=max(arr) prime=[True for i in range(max_val+1)] prime[0]=True prime[1]=True for p in range(2,mt.ceil(mt.sqrt(max_val))): if prime[p]: for i in range(p*2,max_val+1,p): prime[i]=False product=1 for i in range(n): if prime[arr[i]]==False : product*=arr[i] return product arr=[2,3,4,5,6,7] n=len(arr) print(compositeProduct(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 7 }))))) ; n := (arr)->size() ; execute (compositeProduct(arr, n))->display(); operation compositeProduct(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var max_val : OclAny := (arr)->max() ; var prime : Sequence := Integer.subrange(0, max_val + 1-1)->select(i | true)->collect(i | (true)) ; prime->first() := true ; prime[1+1] := true ; for p : Integer.subrange(2, mt.ceil(mt.sqrt(max_val))-1) do ( if prime[p+1] then ( for i : Integer.subrange(p * 2, max_val + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip) ; var product : int := 1 ; for i : Integer.subrange(0, n-1) do ( if prime[arr[i+1]+1] = false then ( product := product * arr[i+1] ) else skip) ; return product; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) b_list=list(map(int,input().split())) dp=dict() for i in range(n): if(b_list[i]-(i+1))not in dp : dp[b_list[i]-(i+1)]=[b_list[i]] continue dp[b_list[i]-(i+1)].append(b_list[i]) result=0 for key in dp.keys(): beuties=sum(dp[key]) if(beuties>result): result=beuties print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dp : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( if (dp)->excludes((b_list[i+1] - (i + 1))) then ( dp[b_list[i+1] - (i + 1)+1] := Sequence{ b_list[i+1] } ; continue ) else skip ; (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name b_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) ))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))) ; var result : int := 0 ; for key : dp.keys() do ( var beuties : OclAny := (dp[key+1])->sum() ; if ((beuties->compareTo(result)) > 0) then ( result := beuties ) else skip) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) beauty=list(map(int,input().split())) dic={} for i in range(n): dic[i-beauty[i]]=dic.get(i-beauty[i],0)+beauty[i] print(max(dic.values())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var beauty : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dic : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( dic[i - beauty[i+1]+1] := dic.get(i - beauty[i+1], 0) + beauty[i+1]) ; execute ((dic.values())->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n=int(input()) b=list(map(int,input().split())) b1=b.copy() dct={} for i in range(n): b1[i]-=(i+1) for i,item in enumerate(b1): if item in dct : dct[item]+=b[i] else : dct[item]=b[i] l=list(dct.values()) l.sort(reverse=True) print(l[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b1 : OclAny := b->copy() ; var dct : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( b1[i+1] := b1[i+1] - (i + 1)) ; for _tuple : Integer.subrange(1, (b1)->size())->collect( _indx | Sequence{_indx-1, (b1)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var item : OclAny := _tuple->at(_indx); if (dct)->includes(item) then ( dct[item+1] := dct[item+1] + b[i+1] ) else ( dct[item+1] := b[i+1] )) ; var l : Sequence := (dct.values()) ; l := l->sort() ; execute (l->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def numOfIncSubseqOfSizeK(arr,n,k): dp=[[0 for i in range(n)]for i in range(k)] for i in range(n): dp[0][i]=1 for l in range(1,k): for i in range(l,n): dp[l][i]=0 for j in range(l-1,i): if(arr[j]display(); operation numOfIncSubseqOfSizeK(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, k-1)->select(i | true)->collect(i | (Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, n-1) do ( dp->first()[i+1] := 1) ; for l : Integer.subrange(1, k-1) do ( for i : Integer.subrange(l, n-1) do ( dp[l+1][i+1] := 0 ; for j : Integer.subrange(l - 1, i-1) do ( if ((arr[j+1]->compareTo(arr[i+1])) < 0) then ( dp[l+1][i+1] := dp[l+1][i+1] + dp[l - 1+1][j+1] ) else skip))) ; var Sum : int := 0 ; for i : Integer.subrange(k - 1, n-1) do ( Sum := Sum + dp[k - 1+1][i+1]) ; return Sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def addOne(x): return(-(~ x)); print(addOne(13)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (addOne(13))->display(); operation addOne(x : OclAny) pre: true post: true activity: return (-(MathLib.bitwiseNot(x)));; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fifthPowerSum(n): return((2*n*n*n*n*n*n)+(6*n*n*n*n*n)+(5*n*n*n*n)-(n*n))//12 n=5 print(fifthPowerSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; execute (fifthPowerSum(n))->display(); operation fifthPowerSum(n : OclAny) : OclAny pre: true post: true activity: return ((2 * n * n * n * n * n * n) + (6 * n * n * n * n * n) + (5 * n * n * n * n) - (n * n)) div 12; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nextPowerOf2(n): n-=1 n |=n>>1 n |=n>>2 n |=n>>4 n |=n>>8 n |=n>>16 n+=1 return n n=5 print(nextPowerOf2(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; execute (nextPowerOf2(n))->display(); operation nextPowerOf2(n : OclAny) : OclAny pre: true post: true activity: n := n - 1 ; n := n or n /(2->pow(1)) ; n := n or n /(2->pow(2)) ; n := n or n /(2->pow(4)) ; n := n or n /(2->pow(8)) ; n := n or n /(2->pow(16)) ; n := n + 1 ; return n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) drinks={'VODKA','BEER','CHAMPAGNE','TEQUILA','BRANDY','ABSINTH','WHISKEY','WINE','GIN','RUM','SAKE'} result=0 for _ in range(n): x=input() if x in drinks or(x.isnumeric()and int(x)<18): result+=1 print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var drinks : Set := Set{'VODKA'}->union(Set{'BEER'}->union(Set{'CHAMPAGNE'}->union(Set{'TEQUILA'}->union(Set{'BRANDY'}->union(Set{'ABSINTH'}->union(Set{'WHISKEY'}->union(Set{'WINE'}->union(Set{'GIN'}->union(Set{'RUM'}->union(Set{ 'SAKE' })))))))))) ; var result : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var x : String := (OclFile["System.in"]).readLine() ; if (drinks)->includes(x) or (x->matches("[0-9]*") & ("" + ((x)))->toInteger() < 18) then ( result := result + 1 ) else skip) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=['ABSINTH','BEER','BRANDY','CHAMPAGNE','GIN','RUM','SAKE','TEQUILA','VODKA','WHISKEY','WINE'] c=0 for _ in range(int(input())): s=input() if s.isnumeric(): if int(s)<18 : c+=1 else : if s in l : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := Sequence{'ABSINTH'}->union(Sequence{'BEER'}->union(Sequence{'BRANDY'}->union(Sequence{'CHAMPAGNE'}->union(Sequence{'GIN'}->union(Sequence{'RUM'}->union(Sequence{'SAKE'}->union(Sequence{'TEQUILA'}->union(Sequence{'VODKA'}->union(Sequence{'WHISKEY'}->union(Sequence{ 'WINE' })))))))))) ; var c : int := 0 ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if s->matches("[0-9]*") then ( if ("" + ((s)))->toInteger() < 18 then ( c := c + 1 ) else skip ) else ( if (l)->includes(s) then ( c := c + 1 ) else skip )) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) l="ABSINTH,BEER,BRANDY,CHAMPAGNE,GIN,RUM,SAKE,TEQUILA,VODKA,WHISKEY,WINE".split(",") print(len(list(filter(lambda v :(v in l)or(v.isdigit()and int(v)<18),[input()for i in range(int(input()))])))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : OclAny := "ABSINTH,BEER,BRANDY,CHAMPAGNE,GIN,RUM,SAKE,TEQUILA,VODKA,WHISKEY,WINE".split(",") ; execute ((((Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())))->select( _x | (lambda v : OclAny in (((l)->includes(v)) or (v->matches("[0-9]*") & ("" + ((v)))->toInteger() < 18)))->apply(_x) = true )))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=input().split() a=int(a) b=int(b) if(a==0 and b>0): print("Impossible") else : c=int(max(0,int(b)-int(a))+int(a)) d=int(max(0,int(b)-1)+int(a)) print(c,d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; if (a = 0 & b > 0) then ( execute ("Impossible")->display() ) else ( var c : int := ("" + ((Set{0, ("" + ((b)))->toInteger() - ("" + ((a)))->toInteger()}->max() + ("" + ((a)))->toInteger())))->toInteger() ; var d : int := ("" + ((Set{0, ("" + ((b)))->toInteger() - 1}->max() + ("" + ((a)))->toInteger())))->toInteger() ; execute (c)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : x,y=map(int,input().split()) if x==0 and y==0 : break liste=[x,y] liste.sort() print(liste[0],liste[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x = 0 & y = 0 then ( break ) else skip ; var liste : Sequence := Sequence{x}->union(Sequence{ y }) ; liste := liste->sort() ; execute (liste->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.buffer.readline def process(A): n=len(A) if n<=2 : sys.stdout.write('YES\n') return else : inc=[] dec=[] for i in range(n-1): if A[i]A[i+1]: dec.append(i) if len(inc)>0 : l,r=inc[0],inc[-1] if l!=0 : sys.stdout.write('NO\n') return if len(inc)!=r-l+1 : sys.stdout.write('NO\n') return if len(dec)>0 : l,r=dec[0],dec[-1] if r!=n-2 : sys.stdout.write('NO\n') return if len(dec)!=r-l+1 : sys.stdout.write('NO\n') return sys.stdout.write('YES\n') return n=int(input()) A=[int(x)for x in input().split()] process(A) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := sys.stdin.buffer.readline ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; A := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; process(A); operation process(A : OclAny) pre: true post: true activity: var n : int := (A)->size() ; if n <= 2 then ( (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES '))))))) )))) ; return ) else ( var inc : Sequence := Sequence{} ; var dec : Sequence := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( if (A[i+1]->compareTo(A[i + 1+1])) < 0 then ( execute ((i) : inc) ) else (if (A[i+1]->compareTo(A[i + 1+1])) > 0 then ( execute ((i) : dec) ) else skip)) ; if (inc)->size() > 0 then ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{inc->first(),inc->last()} ; if l /= 0 then ( (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO '))))))) )))) ; return ) else skip ; if (inc)->size() /= r - l + 1 then ( (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO '))))))) )))) ; return ) else skip ) else skip ; if (dec)->size() > 0 then ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{dec->first(),dec->last()} ; if r /= n - 2 then ( (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO '))))))) )))) ; return ) else skip ; if (dec)->size() /= r - l + 1 then ( (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO '))))))) )))) ; return ) else skip ) else skip ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES '))))))) )))) ; return ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os import math TC=False def solve(): n=int(input()) drinks=["ABSINTH","BEER","BRANDY","CHAMPAGNE","GIN","RUM","SAKE","TEQUILA","VODKA","WHISKEY","WINE"] cnt=0 for i in range(n): s=str(input()) if s.isnumeric(): if int(s)<18 : cnt+=1 else : if s in drinks : cnt+=1 print(cnt) if os.path.exists('input.txt'): debug=True sys.stdin=open("input.txt","r") if TC : for _ in range(int(input())): solve() else : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var TC : boolean := false ; skip ; if os.path.exists('input.txt') then ( var debug : boolean := true ; OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ) else skip ; if TC then ( for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve()) ) else ( solve() ); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var drinks : Sequence := Sequence{"ABSINTH"}->union(Sequence{"BEER"}->union(Sequence{"BRANDY"}->union(Sequence{"CHAMPAGNE"}->union(Sequence{"GIN"}->union(Sequence{"RUM"}->union(Sequence{"SAKE"}->union(Sequence{"TEQUILA"}->union(Sequence{"VODKA"}->union(Sequence{"WHISKEY"}->union(Sequence{ "WINE" })))))))))) ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; if s->matches("[0-9]*") then ( if ("" + ((s)))->toInteger() < 18 then ( cnt := cnt + 1 ) else skip ) else ( if (drinks)->includes(s) then ( cnt := cnt + 1 ) else skip )) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) count=0 l=['0','1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','ABSINTH','BEER','BRANDY','CHAMPAGNE','GIN','RUM','SAKE','TEQUILA','VODKA','WHISKEY','WINE'] for _ in range(n): s=input() if s in l : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := 0 ; var l : Sequence := Sequence{'0'}->union(Sequence{'1'}->union(Sequence{'2'}->union(Sequence{'3'}->union(Sequence{'4'}->union(Sequence{'5'}->union(Sequence{'6'}->union(Sequence{'7'}->union(Sequence{'8'}->union(Sequence{'9'}->union(Sequence{'10'}->union(Sequence{'11'}->union(Sequence{'12'}->union(Sequence{'13'}->union(Sequence{'14'}->union(Sequence{'15'}->union(Sequence{'16'}->union(Sequence{'17'}->union(Sequence{'ABSINTH'}->union(Sequence{'BEER'}->union(Sequence{'BRANDY'}->union(Sequence{'CHAMPAGNE'}->union(Sequence{'GIN'}->union(Sequence{'RUM'}->union(Sequence{'SAKE'}->union(Sequence{'TEQUILA'}->union(Sequence{'VODKA'}->union(Sequence{'WHISKEY'}->union(Sequence{ 'WINE' })))))))))))))))))))))))))))) ; for _anon : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if (l)->includes(s) then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,data): self.data=data self.left=None self.right=None def printPaths(root): path=[] printPathsRec(root,path,0) def printPathsRec(root,path,pathLen): if root is None : return if(len(path)>pathLen): path[pathLen]=root.data else : path.append(root.data) pathLen=pathLen+1 if root.left is None and root.right is None : printArray(path,pathLen) else : printPathsRec(root.left,path,pathLen) printPathsRec(root.right,path,pathLen) def printArray(ints,len): for i in ints[0 : len]: print(i,"",end="") print() root=Node(10) root.left=Node(8) root.right=Node(2) root.left.left=Node(3) root.left.right=Node(5) root.right.left=Node(2) printPaths(root) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.left := null ; self.right := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; root := (Node.newNode()).initialise(10) ; root.left := (Node.newNode()).initialise(8) ; root.right := (Node.newNode()).initialise(2) ; root.left.left := (Node.newNode()).initialise(3) ; root.left.right := (Node.newNode()).initialise(5) ; root.right.left := (Node.newNode()).initialise(2) ; printPaths(root); operation printPaths(root : OclAny) pre: true post: true activity: var path : Sequence := Sequence{} ; printPathsRec(root, path, 0); operation printPathsRec(root : OclAny, path : OclAny, pathLen : OclAny) pre: true post: true activity: if root <>= null then ( return ) else skip ; if (((path)->size()->compareTo(pathLen)) > 0) then ( path[pathLen+1] := root.data ) else ( execute ((root.data) : path) ) ; pathLen := pathLen + 1 ; if root.left <>= null & root.right <>= null then ( printArray(path, pathLen) ) else ( printPathsRec(root.left, path, pathLen) ; printPathsRec(root.right, path, pathLen) ); operation printArray(ints : OclAny, len : OclAny) pre: true post: true activity: for i : ints.subrange(0+1, len) do ( execute (i)->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,data): self.data=data self.right=None self.left=None def printRoute(stack,root): if root==None : return stack.append(root.data) if(root.left==None and root.right==None): print(' '.join([str(i)for i in stack])) printRoute(stack,root.left) printRoute(stack,root.right) stack.pop() root=Node(1); root.left=Node(2); root.right=Node(3); root.left.left=Node(4); root.left.right=Node(5); printRoute([],root) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute right : OclAny := null; attribute left : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.right := null ; self.left := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; root := (Node.newNode()).initialise(1); ; root.left := (Node.newNode()).initialise(2); ; root.right := (Node.newNode()).initialise(3); ; root.left.left := (Node.newNode()).initialise(4); ; root.left.right := (Node.newNode()).initialise(5); ; printRoute(Sequence{}, root); operation printRoute(stack : OclAny, root : OclAny) pre: true post: true activity: if root = null then ( return ) else skip ; execute ((root.data) : stack) ; if (root.left = null & root.right = null) then ( execute (StringLib.sumStringsWithSeparator((stack->select(i | true)->collect(i | (("" + ((i)))))), ' '))->display() ) else skip ; printRoute(stack, root.left) ; printRoute(stack, root.right) ; stack := stack->front(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def findLargestDivisor(n): for i in range(2,int(math.sqrt(n))+1): while(n %(i*i)==0): n=n//i return n if __name__=="__main__" : n=12 print(findLargestDivisor(n)) n=97 print(findLargestDivisor(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 12 ; execute (findLargestDivisor(n))->display() ; n := 97 ; execute (findLargestDivisor(n))->display() ) else skip; operation findLargestDivisor(n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(2, ("" + (((n)->sqrt())))->toInteger() + 1-1) do ( while (n mod (i * i) = 0) do ( n := n div i)) ; return n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,p=map(int,input().split()) b=(3*a+p)//2 print(b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var p : OclAny := null; Sequence{a,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : int := (3 * a + p) div 2 ; execute (b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def LI(): return[int(x)for x in sys.stdin.readline().split()] def II(): return int(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() sys.setrecursionlimit(10**7) INF=10**18 MOD=10**9+7 def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def SI(): return input() YN=lambda b : print('YES')if b else print('NO') yn=lambda b : print('Yes')if b else print('No') def main(): A,P=LI() print((3*A+P)//2) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; var INF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; var YN : Function := lambda b : OclAny in (if b then ('YES')->display() else ('NO')->display() endif) ; var yn : Function := lambda b : OclAny in (if b then ('Yes')->display() else ('No')->display() endif) ; skip ; main(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation SI() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation main() pre: true post: true activity: var A : OclAny := null; var P : OclAny := null; Sequence{A,P} := LI() ; execute ((3 * A + P) div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num1,num2=[int(i)for i in input().split()] print((((num1*3)+num2)//2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num1 : OclAny := null; var num2 : OclAny := null; Sequence{num1,num2} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute ((((num1 * 3) + num2) div 2))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from collections import deque def main(): A,P=map(int,input().split()) P+=A*3 print(P//2) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var A : OclAny := null; var P : OclAny := null; Sequence{A,P} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; P := P + A * 3 ; execute (P div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ex(x,y): if x>y : tmp=x x=y y=tmp return x,y def ex2num(): r1,r2=input().split(" ") r1=int(r1) r2=int(r2) while(0!=r1)or(0!=r2): r1,r2=ex(r1,r2) print(r1,r2) r1,r2=input().split(" ") r1=int(r1) r2=int(r2) return 0 if __name__=="__main__" : ret=ex2num() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var ret : OclAny := ex2num() ) else skip; operation ex(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (x->compareTo(y)) > 0 then ( var tmp : OclAny := x ; x := y ; y := tmp ) else skip ; return x, y; operation ex2num() : OclAny pre: true post: true activity: var r1 : OclAny := null; var r2 : OclAny := null; Sequence{r1,r2} := input().split(" ") ; var r1 : int := ("" + ((r1)))->toInteger() ; var r2 : int := ("" + ((r2)))->toInteger() ; while (0 /= r1) or (0 /= r2) do ( Sequence{r1,r2} := ex(r1, r2) ; execute (r1)->display() ; Sequence{r1,r2} := input().split(" ") ; r1 := ("" + ((r1)))->toInteger() ; r2 := ("" + ((r2)))->toInteger()) ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin a,p=[int(x)for x in stdin.readline().rstrip().split()] p=p+a*3 ans=p//2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var p : OclAny := null; Sequence{a,p} := stdin.readLine().rstrip().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var p : OclAny := p + a * 3 ; var ans : int := p div 2 ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) n=list(map(int,input().split())) x=len(n) o=1 while on[o]: o=o+1 if o==x : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : int := (n)->size() ; var o : int := 1 ; while (o->compareTo(x)) < 0 & (n[o - 1+1]->compareTo(n[o+1])) < 0 do ( o := o + 1) ; while (o->compareTo(x)) < 0 & n[o - 1+1] = n[o+1] do ( o := o + 1) ; while (o->compareTo(x)) < 0 & (n[o - 1+1]->compareTo(n[o+1])) > 0 do ( o := o + 1) ; if o = x then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=1000000007 ; def exponentiation(bas,exp): t=1 ; while(exp>0): if(exp % 2!=0): t=(t*bas)% N ; bas=(bas*bas)% N ; exp=int(exp/2); return t % N ; bas=5 ; exp=100000 ; modulo=exponentiation(bas,exp); print(modulo); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 1000000007; ; skip ; bas := 5; ; exp := 100000; ; var modulo : OclAny := exponentiation(bas, exp); ; execute (modulo)->display();; operation exponentiation(bas : OclAny, exp : OclAny) pre: true post: true activity: var t : int := 1; ; while (exp > 0) do ( if (exp mod 2 /= 0) then ( t := (t * bas) mod N; ) else skip ; bas := (bas * bas) mod N; ; exp := ("" + ((exp / 2)))->toInteger();) ; return t mod N;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=1000000007 ; def exponentiation(bas,exp): if(exp==0): return 1 ; if(exp==1): return bas % N ; t=exponentiation(bas,int(exp/2)); t=(t*t)% N ; if(exp % 2==0): return t ; else : return((bas % N)*t)% N ; bas=5 ; exp=100000 ; modulo=exponentiation(bas,exp); print(modulo); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 1000000007; ; skip ; bas := 5; ; exp := 100000; ; var modulo : OclAny := exponentiation(bas, exp); ; execute (modulo)->display();; operation exponentiation(bas : OclAny, exp : OclAny) pre: true post: true activity: if (exp = 0) then ( return 1; ) else skip ; if (exp = 1) then ( return bas mod N; ) else skip ; var t : OclAny := exponentiation(bas, ("" + ((exp / 2)))->toInteger()); ; t := (t * t) mod N; ; if (exp mod 2 = 0) then ( return t; ) else ( return ((bas mod N) * t) mod N; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def distinctDigitSum(n): used=[False]*10 sum=0 while(n>0): digit=n % 10 if(not used[digit]): used[digit]=True sum+=digit n=n//10 return sum def checkSum(m,n): sumM=distinctDigitSum(m) sumN=distinctDigitSum(n) if(sumM==sumN): return "YES" return "NO" if __name__=="__main__" : m=2452 n=9222 print(checkSum(m,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( m := 2452 ; n := 9222 ; execute (checkSum(m, n))->display() ) else skip; operation distinctDigitSum(n : OclAny) : OclAny pre: true post: true activity: var used : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, 10) ; var sum : int := 0 ; while (n > 0) do ( var digit : int := n mod 10 ; if (not(used[digit+1])) then ( used[digit+1] := true ; sum := sum + digit ) else skip ; n := n div 10) ; return sum; operation checkSum(m : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sumM : OclAny := distinctDigitSum(m) ; var sumN : OclAny := distinctDigitSum(n) ; if (sumM = sumN) then ( return "YES" ) else skip ; return "NO"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(A,B): p=B/2 M=int(4*p) N=1 O=-2*A Q=int(A*A+4*p*p) return[M,N,O,Q] a=1 b=1 print(*solve(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : int := 1 ; var b : int := 1 ; execute ((argument * (test (logical_test (comparison (expr (atom (name solve)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))))))))->display(); operation solve(A : OclAny, B : OclAny) : OclAny pre: true post: true activity: var p : double := B / 2 ; var M : int := ("" + ((4 * p)))->toInteger() ; var N : int := 1 ; var O : double := -2 * A ; var Q : int := ("" + ((A * A + 4 * p * p)))->toInteger() ; return Sequence{M}->union(Sequence{N}->union(Sequence{O}->union(Sequence{ Q }))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sortArrays(arr,length): j=0 while(jd2): temp=arr[j] arr[j]=arr[j+1] arr[j+1]=temp j=-1 j+=1 return arr geeks="GEEKSFORGEEKS" n=len(geeks) arr=[0]*n for i in range(n): arr[i]=geeks[i] print("Original array:[",end="") for i in range(n): print(arr[i],end="") if(i+1!=n): print(",",end="") print("]") ansarr=sortArrays(arr,n) print("Sorted array:[",end="") for i in range(n): print(ansarr[i],end="") if(i+1!=n): print(",",end="") print("]") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var geeks : String := "GEEKSFORGEEKS" ; var n : int := (geeks)->size() ; arr := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( arr[i+1] := geeks[i+1]) ; execute ("Original array:[")->display() ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display() ; if (i + 1 /= n) then ( execute (",")->display() ) else skip) ; execute ("]")->display() ; var ansarr : OclAny := sortArrays(arr, n) ; execute ("Sorted array:[")->display() ; for i : Integer.subrange(0, n-1) do ( execute (ansarr[i+1])->display() ; if (i + 1 /= n) then ( execute (",")->display() ) else skip) ; execute ("]")->display(); operation sortArrays(arr : OclAny, length : OclAny) : OclAny pre: true post: true activity: var j : int := 0 ; while ((j->compareTo(length - 1)) < 0) do ( var d1 : OclAny := arr[j+1] ; var d2 : OclAny := arr[j + 1+1] ; if ((d1->compareTo(d2)) > 0) then ( var temp : OclAny := arr[j+1] ; arr[j+1] := arr[j + 1+1] ; arr[j + 1+1] := temp ; j := -1 ) else skip ; j := j + 1) ; return arr; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(min_v,max_v,min_limit,max_limit,n): prev=min_v min_v=max(min_limit,min_v-n) n-=prev-min_v max_v=max(max_limit,max_v-n) return max_v*min_v def main(): t=int(input()) for _ in range(t): a,b,x,y,n=map(int,input().split()) if a>=b : min_v=b min_limit=y max_v=a max_limit=x else : min_v=a min_limit=x max_v=b max_limit=y m1=solve(min_v,max_v,min_limit,max_limit,n) m2=solve(max_v,min_v,max_limit,min_limit,n) print(min(m1,m2)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation solve(min_v : OclAny, max_v : OclAny, min_limit : OclAny, max_limit : OclAny, n : OclAny) : OclAny pre: true post: true activity: var prev : OclAny := min_v ; min_v := Set{min_limit, min_v - n}->max() ; n := n - prev - min_v ; max_v := Set{max_limit, max_v - n}->max() ; return max_v * min_v; operation main() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{a,b,x,y,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(b)) >= 0 then ( min_v := b ; min_limit := y ; max_v := a ; max_limit := x ) else ( min_v := a ; min_limit := x ; max_v := b ; max_limit := y ) ; var m1 : OclAny := solve(min_v, max_v, min_limit, max_limit, n) ; var m2 : OclAny := solve(max_v, min_v, max_limit, min_limit, n) ; execute (Set{m1, m2}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for T in range(int(input())): a,b,x,y,n=map(int,input().split()) p=max(a-n,x) q=max(b-(n-a+p),y) Q=max(b-n,y) P=max(a-(n-b+Q),x) print(min(p*q,P*Q)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for T : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var x : OclAny := null; var y : OclAny := null; var n : OclAny := null; Sequence{a,b,x,y,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : OclAny := Set{a - n, x}->max() ; var q : OclAny := Set{b - (n - a + p), y}->max() ; var Q : OclAny := Set{b - n, y}->max() ; var P : OclAny := Set{a - (n - b + Q), x}->max() ; execute (Set{p * q, P * Q}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b,x,y,n=map(int,input().split()) m1=max(a-n,x) m2=max(b-n,y) m1=m1*max(a-n-m1+b,y) m2=m2*max(a-n-m2+b,x) print(min(m1,m2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var x : OclAny := null; var y : OclAny := null; var n : OclAny := null; Sequence{a,b,x,y,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m1 : OclAny := Set{a - n, x}->max() ; var m2 : OclAny := Set{b - n, y}->max() ; m1 := m1 * Set{a - n - m1 + b, y}->max() ; m2 := m2 * Set{a - n - m2 + b, x}->max() ; execute (Set{m1, m2}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math for i in sys.stdin.readlines(): i=i.rstrip() i=i.split() x=int(i[0]) y=int(i[1]) if x==0 and y==0 : break print(str(min(x,y))+" "+str(max(x,y))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for i : (OclFile["System.in"]).readlines() do ( var i : String := StringLib.rightTrim(i) ; i := i.split() ; var x : int := ("" + ((i->first())))->toInteger() ; var y : int := ("" + ((i[1+1])))->toInteger() ; if x = 0 & y = 0 then ( break ) else skip ; execute (("" + ((Set{x, y}->min()))) + " " + ("" + ((Set{x, y}->max()))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): s=input() a,b,x,y,n=list(map(int,s.split())) fir_a=0 fir_b=0 dif_a=a-x dif_b=b-y if dif_a<=n : a-=dif_a n-=dif_a if dif_b<=n : b-=dif_b n-=dif_b fir_a=a*b else : b-=n n=0 fir_a=a*b else : a-=n n=0 fir_a=a*b a,b,x,y,n=list(map(int,s.split())) if dif_b<=n : b-=dif_b n-=dif_b if dif_a<=n : a-=dif_a n-=dif_b fir_b=a*b else : a-=n n=0 fir_b=a*b else : b-=n n=0 fir_b=a*b print(min(fir_a,fir_b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var a : OclAny := null; var b : OclAny := null; var x : OclAny := null; var y : OclAny := null; var n : OclAny := null; Sequence{a,b,x,y,n} := ((s.split())->collect( _x | (OclType["int"])->apply(_x) )) ; var fir_a : int := 0 ; var fir_b : int := 0 ; var dif_a : double := a - x ; var dif_b : double := b - y ; if (dif_a->compareTo(n)) <= 0 then ( a := a - dif_a ; n := n - dif_a ; if (dif_b->compareTo(n)) <= 0 then ( b := b - dif_b ; n := n - dif_b ; fir_a := a * b ) else ( b := b - n ; var n : int := 0 ; fir_a := a * b ) ) else ( a := a - n ; n := 0 ; fir_a := a * b ) ; var a : OclAny := null; var b : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{a,b,x,y,n} := ((s.split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (dif_b->compareTo(n)) <= 0 then ( b := b - dif_b ; n := n - dif_b ; if (dif_a->compareTo(n)) <= 0 then ( a := a - dif_a ; n := n - dif_b ; fir_b := a * b ) else ( a := a - n ; n := 0 ; fir_b := a * b ) ) else ( b := b - n ; n := 0 ; fir_b := a * b ) ; execute (Set{fir_a, fir_b}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): s=input() buf=list(map(int,s.split())) a,b,x,y,n=buf fir_a=0 fir_b=0 dif_a=a-x dif_b=b-y if dif_a<=n : a-=dif_a n-=dif_a if dif_b<=n : b-=dif_b n-=dif_b fir_a=a*b else : b-=n n=0 fir_a=a*b else : a-=n n=0 fir_a=a*b a,b,x,y,n=buf if dif_b<=n : b-=dif_b n-=dif_b if dif_a<=n : a-=dif_a n-=dif_b fir_b=a*b else : a-=n n=0 fir_b=a*b else : b-=n n=0 fir_b=a*b print(min(fir_a,fir_b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var buf : Sequence := ((s.split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := null; var b : OclAny := null; var x : OclAny := null; var y : OclAny := null; var n : OclAny := null; Sequence{a,b,x,y,n} := buf ; var fir_a : int := 0 ; var fir_b : int := 0 ; var dif_a : double := a - x ; var dif_b : double := b - y ; if (dif_a->compareTo(n)) <= 0 then ( a := a - dif_a ; n := n - dif_a ; if (dif_b->compareTo(n)) <= 0 then ( b := b - dif_b ; n := n - dif_b ; fir_a := a * b ) else ( b := b - n ; var n : int := 0 ; fir_a := a * b ) ) else ( a := a - n ; n := 0 ; fir_a := a * b ) ; var a : OclAny := null; var b : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{a,b,x,y,n} := buf ; if (dif_b->compareTo(n)) <= 0 then ( b := b - dif_b ; n := n - dif_b ; if (dif_a->compareTo(n)) <= 0 then ( a := a - dif_a ; n := n - dif_b ; fir_b := a * b ) else ( a := a - n ; n := 0 ; fir_b := a * b ) ) else ( b := b - n ; n := 0 ; fir_b := a * b ) ; execute (Set{fir_a, fir_b}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def merge(tS,left,mid,right): global cnt n1=mid-left ; n2=right-mid ; tL=tS[left : mid]; tR=tS[mid : right]; tL.append(1000000001) tR.append(1000000001) i=j=0 for k in range(left,right): cnt+=1 if tL[i]<=tR[j]: tS[k]=tL[i] i+=1 else : tS[k]=tR[j] j+=1 def mergeSort(tS,left,right): if left+1toInteger() ; var arrS : Sequence := input().split(' ')->select(val | true)->collect(val | (("" + ((val)))->toInteger())) ; cnt := 0 ; mergeSort(arrS, 0, n) ; execute (StringLib.sumStringsWithSeparator(((arrS)->collect( _x | (OclType["String"])->apply(_x) )), " "))->display() ; execute (cnt)->display(); operation merge(tS : OclAny, left : OclAny, mid : OclAny, right : OclAny) pre: true post: true activity: skip ; var n1 : double := mid - left; ; var n2 : double := right - mid; ; var tL : OclAny := tS.subrange(left+1, mid); ; var tR : OclAny := tS.subrange(mid+1, right); ; execute ((1000000001) : tL) ; execute ((1000000001) : tR) ; var i : OclAny := 0; var j : int := 0 ; for k : Integer.subrange(left, right-1) do ( cnt := cnt + 1 ; if (tL[i+1]->compareTo(tR[j+1])) <= 0 then ( tS[k+1] := tL[i+1] ; i := i + 1 ) else ( tS[k+1] := tR[j+1] ; j := j + 1 )); operation mergeSort(tS : OclAny, left : OclAny, right : OclAny) pre: true post: true activity: if (left + 1->compareTo(right)) < 0 then ( mid := (left + right) div 2 ; mergeSort(tS, left, mid) ; mergeSort(tS, mid, right) ; merge(tS, left, mid, right) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=list(map(int,input().split())) if n==1 : print(a[0]) else : res=-1e9 for i in range(n): for j in range(n): b=a[i : j+1] if not b : continue if i>0 and j0 and j==n-1 : c=a[: i] b.sort() c.sort(reverse=True) b1=0 c1=0 l=0 while lcollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = 1 then ( execute (a->first())->display() ) else ( var res : double := -("1e9")->toReal() ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( var b : OclAny := a.subrange(i+1, j + 1) ; if not(b) then ( continue ) else skip ; if i > 0 & (j->compareTo(n - 1)) < 0 then ( var c : OclAny := a.subrange(1,i) + a.subrange(j + 1+1) ) else (if i = 0 & (j->compareTo(n - 1)) < 0 then ( c := a.subrange(j + 1+1) ) else (if i > 0 & j = n - 1 then ( c := a.subrange(1,i) ) else skip ) ) ; b := b->sort() ; c := c->sort() ; var b1 : int := 0 ; var c1 : int := 0 ; var l : int := 0 ; while (l->compareTo(k)) < 0 & (b1->compareTo((b)->size())) < 0 & (c1->compareTo((c)->size())) < 0 do ( if (b[b1+1]->compareTo(c[c1+1])) < 0 then ( var b[b1+1] : OclAny := null; var c[c1+1] : OclAny := null; Sequence{b[b1+1],c[c1+1]} := Sequence{c[c1+1],b[b1+1]} ; b1 := b1 + 1 ; c1 := c1 + 1 ; l := l + 1 ) else ( break )) ; res := Set{res, (b)->sum()}->max())) ; execute (Set{res, (a)->sum()}->max())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from operator import itemgetter from sys import stdin,stdout def solve(a,k): aa=list(map(lambda x :[x[1],x[0]],enumerate(a))) aa.sort(reverse=True,key=itemgetter(0)) if aa[0][0]<0 : return aa[0][0] best=-float("inf") for i in range(len(a)): for j in range(1,len(a)+1): in_range=sorted(a[i : j],reverse=True) out_of_range=sorted(a[: i]+a[j :]) additional=[] for kk in range(k): if len(out_of_range)>0 and len(in_range)>0 and in_range[-1]collect( _x | (OclType["int"])->apply(_x) ) ; a := stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; stdout.write(StringLib.interpolateStrings("{}\n", Sequence{solve(a, k)})) ) else skip; operation solve(a : OclAny, k : OclAny) : OclAny pre: true post: true activity: var aa : Sequence := ((Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ))->collect( _x | (lambda x : OclAny in (Sequence{x[1+1]}->union(Sequence{ x->first() })))->apply(_x) )) ; aa := aa->sort() ; if aa->first()->first() < 0 then ( return aa->first()->first() ) else skip ; var best : double := -("" + (("inf")))->toReal() ; for i : Integer.subrange(0, (a)->size()-1) do ( for j : Integer.subrange(1, (a)->size() + 1-1) do ( var in_range : Sequence := a.subrange(i+1, j)->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var out_of_range : Sequence := a.subrange(1,i) + a.subrange(j+1)->sort() ; var additional : Sequence := Sequence{} ; for kk : Integer.subrange(0, k-1) do ( if (out_of_range)->size() > 0 & (in_range)->size() > 0 & (in_range->last()->compareTo(out_of_range->last())) < 0 then ( in_range := in_range->front() ; execute ((out_of_range->last()) : additional) ) else skip) ; best := Set{best, (in_range->union(additional))->sum()}->max())) ; return best; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(a,k): ans=-float("inf") for i in range(len(a)+1): for j in range(i): mid=a[j : i] l=a[: j]+a[i :] l=sorted(l,reverse=True) mid=sorted(mid) s=sum(mid) ans=max(ans,s) kk=k while kk : if l and mid and s-mid[0]+l[0]>s : s=s-mid[0]+l[0] l.pop(0) mid.pop(0) kk-=1 ans=max(ans,s) else : break return ans n,k=map(int,input().strip().split()) a=list(map(int,input().strip().split())) print(f(a,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; Sequence{n,k} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (f(a, k))->display(); operation f(a : OclAny, k : OclAny) : OclAny pre: true post: true activity: var ans : double := -("" + (("inf")))->toReal() ; for i : Integer.subrange(0, (a)->size() + 1-1) do ( for j : Integer.subrange(0, i-1) do ( var mid : OclAny := a.subrange(j+1, i) ; var l : OclAny := a.subrange(1,j) + a.subrange(i+1) ; l := l->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; mid := mid->sort() ; var s : OclAny := (mid)->sum() ; ans := Set{ans, s}->max() ; var kk : OclAny := k ; while kk do ( if l & mid & (s - mid->first() + l->first()->compareTo(s)) > 0 then ( s := s - mid->first() + l->first() ; l := l->excludingAt(0+1) ; mid := mid->excludingAt(0+1) ; kk := kk - 1 ; ans := Set{ans, s}->max() ) else ( break )))) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(a,k): ans=-float("inf") for i in range(len(a)+1): for j in range(i): mid=a[j : i] l=a[: j]+a[i :] l=sorted(l,reverse=True) mid=sorted(mid) s=sum(mid) ans=max(ans,s) kk=k while kk : if l and mid and s-mid[0]+l[0]>s : s=s-mid[0]+l[0] l.pop(0) mid.pop(0) kk-=1 ans=max(ans,s) else : break return ans n,k=map(int,input().strip().split()) a=list(map(int,input().strip().split())) print(f(a,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; Sequence{n,k} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (f(a, k))->display(); operation f(a : OclAny, k : OclAny) : OclAny pre: true post: true activity: var ans : double := -("" + (("inf")))->toReal() ; for i : Integer.subrange(0, (a)->size() + 1-1) do ( for j : Integer.subrange(0, i-1) do ( var mid : OclAny := a.subrange(j+1, i) ; var l : OclAny := a.subrange(1,j) + a.subrange(i+1) ; l := l->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; mid := mid->sort() ; var s : OclAny := (mid)->sum() ; ans := Set{ans, s}->max() ; var kk : OclAny := k ; while kk do ( if l & mid & (s - mid->first() + l->first()->compareTo(s)) > 0 then ( s := s - mid->first() + l->first() ; l := l->excludingAt(0+1) ; mid := mid->excludingAt(0+1) ; kk := kk - 1 ; ans := Set{ans, s}->max() ) else ( break )))) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=input().split(" ") max_=-1000 ls=[] for i in range(n): ls.append(int(a[i])) len_=len(ls) if len_==1 : print(ls[0]) else : for i in range(0,len_-1): ls_mid=[] ls_lt=[] ls_rt=[] ls_out=[] for j in range(i+1,len_): sum_=0 v=k ls_mid=ls[i : j+1] ls_mid.sort(reverse=True) ls_lt=ls[0 : i] ls_rt=ls[j+1 : len_] ls_out.extend(ls_lt) ls_out.extend(ls_rt) ls_out.sort() while True : if len(ls_mid)==0 : break else : Min=ls_mid.pop() if len(ls_out)==0 : ls_mid.append(Min) break else : Max=ls_out.pop() if Mincollect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := input().split(" ") ; var max_ : int := -1000 ; var ls : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + ((a[i+1])))->toInteger()) : ls)) ; var len_ : int := (ls)->size() ; if len_ = 1 then ( execute (ls->first())->display() ) else ( for i : Integer.subrange(0, len_ - 1-1) do ( var ls_mid : Sequence := Sequence{} ; var ls_lt : Sequence := Sequence{} ; var ls_rt : Sequence := Sequence{} ; var ls_out : Sequence := Sequence{} ; for j : Integer.subrange(i + 1, len_-1) do ( var sum_ : int := 0 ; var v : OclAny := k ; ls_mid := ls.subrange(i+1, j + 1) ; ls_mid := ls_mid->sort() ; ls_lt := ls.subrange(0+1, i) ; ls_rt := ls.subrange(j + 1+1, len_) ; ls_out := ls_out->union(ls_lt) ; ls_out := ls_out->union(ls_rt) ; ls_out := ls_out->sort() ; while true do ( if (ls_mid)->size() = 0 then ( break ) else ( var Min : OclAny := ls_mid->last() ; ls_mid := ls_mid->front() ) ; if (ls_out)->size() = 0 then ( execute ((Min) : ls_mid) ; break ) else ( var Max : OclAny := ls_out->last() ; ls_out := ls_out->front() ; if (Min->compareTo(Max)) < 0 then ( sum_ := sum_ + Max ; v := v - 1 ; if v = 0 then ( break ) else ( continue ) ) else ( execute ((Min) : ls_mid) ; break ) )) ; if v = k then ( max_ := Set{max_, (ls_mid)->max(), (ls_mid)->sum()}->max() ) else ( max_ := Set{max_, sum_ + (ls_mid)->sum()}->max() ) ; execute (ls_out /<: ls_out))) ; execute (max_)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dfs(graph,node,dist,vis,c): if(vis[node]): return ; vis[node]=True ; dist[node]=c ; for i in range(len(graph[node])): if(not vis[graph[node][i]]): dfs(graph,graph[node][i],dist,vis,c+1); def countOfNodes(graph,n): vis=[False]*(n+1); dist=[0]*(n+1); dfs(graph,1,dist,vis,0); even=0 ; odd=0 ; for i in range(1,n+1): if(dist[i]% 2==0): even+=1 ; else : odd+=1 ; ans=((even*(even-1))+(odd*(odd-1)))//2 ; return ans ; if __name__=="__main__" : n=5 ; graph=[[],[2],[1,3],[2]]; ans=countOfNodes(graph,n); print(ans); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 5; ; graph := Sequence{Sequence{}}->union(Sequence{Sequence{ 2 }}->union(Sequence{Sequence{1}->union(Sequence{ 3 })}->union(Sequence{ Sequence{ 2 } }))); ; ans := countOfNodes(graph, n); ; execute (ans)->display(); ) else skip; operation dfs(graph : OclAny, node : OclAny, dist : OclAny, vis : OclAny, c : OclAny) : OclAny pre: true post: true activity: if (vis[node+1]) then ( return; ) else skip ; vis[node+1] := true; ; dist[node+1] := c; ; for i : Integer.subrange(0, (graph[node+1])->size()-1) do ( if (not(vis[graph[node+1][i+1]+1])) then ( dfs(graph, graph[node+1][i+1], dist, vis, c + 1); ) else skip); operation countOfNodes(graph : OclAny, n : OclAny) pre: true post: true activity: vis := MatrixLib.elementwiseMult(Sequence{ false }, (n + 1)); ; dist := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); ; dfs(graph, 1, dist, vis, 0); ; var even : int := 0; var odd : int := 0; ; for i : Integer.subrange(1, n + 1-1) do ( if (dist[i+1] mod 2 = 0) then ( even := even + 1; ) else ( odd := odd + 1; )) ; var ans : int := ((even * (even - 1)) + (odd * (odd - 1))) div 2; ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- size=[60,80,100,120,140,160] weight=[2,5,10,15,20,25] fee=[600,800,1000,1200,1400,1600] while True : n=int(input()) if n==0 : break total=0 for _ in range(n): [x,y,h,wt]=list(map(int,input().strip().split())) sz=x+y+h if sz<=size[-1]and wt<=weight[-1]: isz=len(list(filter(lambda x : xunion(Sequence{80}->union(Sequence{100}->union(Sequence{120}->union(Sequence{140}->union(Sequence{ 160 }))))) ; var weight : Sequence := Sequence{2}->union(Sequence{5}->union(Sequence{10}->union(Sequence{15}->union(Sequence{20}->union(Sequence{ 25 }))))) ; var fee : Sequence := Sequence{600}->union(Sequence{800}->union(Sequence{1000}->union(Sequence{1200}->union(Sequence{1400}->union(Sequence{ 1600 }))))) ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var total : int := 0 ; for _anon : Integer.subrange(0, n-1) do (suite)) ; Sequence{x}->union(Sequence{y}->union(Sequence{h}->union(Sequence{ wt }))) := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(1,3001): x,y=input().split() x=int(x) y=int(y) if x==0 and y==0 : break else : if x<=y : print(x,y) else : print(y,x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(1, 3001-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := input().split() ; var x : int := ("" + ((x)))->toInteger() ; var y : int := ("" + ((y)))->toInteger() ; if x = 0 & y = 0 then ( break ) else ( if (x->compareTo(y)) <= 0 then ( execute (x)->display() ) else ( execute (y)->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def process(x,y,h,w): if x+y+h<=60 and w<=2 : return 600 elif x+y+h<=80 and w<=5 : return 800 elif x+y+h<=100 and w<=10 : return 1000 elif x+y+h<=120 and w<=15 : return 1200 elif x+y+h<=140 and w<=20 : return 1400 elif x+y+h<=160 and w<=25 : return 1600 else : return 0 result=[] while True : n=int(input()) if n==0 : break total=0 for _ in range(n): x,y,h,w=map(int,input().split()) total+=process(x,y,h,w) result.append(total) print('\n'.join(map(str,result))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var result : Sequence := Sequence{} ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var total : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( Sequence{x,y,h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; total := total + process(x, y, h, w)) ; execute ((total) : result)) ; execute (StringLib.sumStringsWithSeparator(((result)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); operation process(x : OclAny, y : OclAny, h : OclAny, w : OclAny) : OclAny pre: true post: true activity: if x + y + h <= 60 & w <= 2 then ( return 600 ) else (if x + y + h <= 80 & w <= 5 then ( return 800 ) else (if x + y + h <= 100 & w <= 10 then ( return 1000 ) else (if x + y + h <= 120 & w <= 15 then ( return 1200 ) else (if x + y + h <= 140 & w <= 20 then ( return 1400 ) else (if x + y + h <= 160 & w <= 25 then ( return 1600 ) else ( return 0 ) ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,bisect PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") tariff={'A' :{"size" : 60,"weight" : 2,"price" : 600},'B' :{"size" : 80,"weight" : 5,"price" : 800},'C' :{"size" : 100,"weight" : 10,"price" : 1000},'D' :{"size" : 120,"weight" : 15,"price" : 1200},'E' :{"size" : 140,"weight" : 20,"price" : 1400},'F' :{"size" : 160,"weight" : 25,"price" : 1600}} def get_fee(s,w): for t in['A','B','C','D','E','F']: if s<=tariff[t]["size"]and w<=tariff[t]["weight"]: return tariff[t]["price"] return 0 while True : n=int(input()) if n==0 : break fee=0 for _ in range(n): x,y,z,w=[int(__)for __ in input().split()] s=x+y+z fee+=get_fee(s,w) print(fee) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; var tariff : Map := Map{ 'A' |-> Map{ "size" |-> 60 }->union(Map{ "weight" |-> 2 }->union(Map{ "price" |-> 600 })) }->union(Map{ 'B' |-> Map{ "size" |-> 80 }->union(Map{ "weight" |-> 5 }->union(Map{ "price" |-> 800 })) }->union(Map{ 'C' |-> Map{ "size" |-> 100 }->union(Map{ "weight" |-> 10 }->union(Map{ "price" |-> 1000 })) }->union(Map{ 'D' |-> Map{ "size" |-> 120 }->union(Map{ "weight" |-> 15 }->union(Map{ "price" |-> 1200 })) }->union(Map{ 'E' |-> Map{ "size" |-> 140 }->union(Map{ "weight" |-> 20 }->union(Map{ "price" |-> 1400 })) }->union(Map{ 'F' |-> Map{ "size" |-> 160 }->union(Map{ "weight" |-> 25 }->union(Map{ "price" |-> 1600 })) }))))) ; skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var fee : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z,w} := input().split()->select(__ | true)->collect(__ | (("" + ((__)))->toInteger())) ; s := x + y + z ; fee := fee + get_fee(s, w)) ; execute (fee)->display()); operation get_fee(s : OclAny, w : OclAny) : OclAny pre: true post: true activity: for t : Sequence{'A'}->union(Sequence{'B'}->union(Sequence{'C'}->union(Sequence{'D'}->union(Sequence{'E'}->union(Sequence{ 'F' }))))) do ( if (s->compareTo(tariff[t+1]->at("size"))) <= 0 & (w->compareTo(tariff[t+1]->at("weight"))) <= 0 then ( return tariff[t+1]->at("price") ) else skip) ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : counter=int(input()) if counter==0 : break deliv_price=0 for i in range(0,counter): data=input().split(" ") size=int(data[0])+int(data[1])+int(data[2]) weight=int(data[3]) if size<=60 and weight<=2 : deliv_price+=600 elif size<=80 and weight<=5 : deliv_price+=800 elif size<=100 and weight<=10 : deliv_price+=1000 elif size<=120 and weight<=15 : deliv_price+=1200 elif size<=140 and weight<=20 : deliv_price+=1400 elif size<=160 and weight<=25 : deliv_price+=1600 print(deliv_price) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var counter : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if counter = 0 then ( break ) else skip ; var deliv_price : int := 0 ; for i : Integer.subrange(0, counter-1) do ( var data : OclAny := input().split(" ") ; var size : int := ("" + ((data->first())))->toInteger() + ("" + ((data[1+1])))->toInteger() + ("" + ((data[2+1])))->toInteger() ; var weight : int := ("" + ((data[3+1])))->toInteger() ; if size <= 60 & weight <= 2 then ( deliv_price := deliv_price + 600 ) else (if size <= 80 & weight <= 5 then ( deliv_price := deliv_price + 800 ) else (if size <= 100 & weight <= 10 then ( deliv_price := deliv_price + 1000 ) else (if size <= 120 & weight <= 15 then ( deliv_price := deliv_price + 1200 ) else (if size <= 140 & weight <= 20 then ( deliv_price := deliv_price + 1400 ) else (if size <= 160 & weight <= 25 then ( deliv_price := deliv_price + 1600 ) else skip ) ) ) ) ) ) ; execute (deliv_price)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def deleteElement(A,L,R,N): j=0 for i in range(N): if i<=L or i>=R : A[j]=A[i] j+=1 return j if __name__=="__main__" : A=[5,8,11,15,26,14,19,17,10,14] L,R=2,7 n=len(A) res_size=deleteElement(A,L,R,n) for i in range(res_size): print(A[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( A := Sequence{5}->union(Sequence{8}->union(Sequence{11}->union(Sequence{15}->union(Sequence{26}->union(Sequence{14}->union(Sequence{19}->union(Sequence{17}->union(Sequence{10}->union(Sequence{ 14 }))))))))) ; Sequence{L,R} := Sequence{2,7} ; var n : int := (A)->size() ; var res_size : OclAny := deleteElement(A, L, R, n) ; for i : Integer.subrange(0, res_size-1) do ( execute (A[i+1])->display()) ) else skip; operation deleteElement(A : OclAny, L : OclAny, R : OclAny, N : OclAny) : OclAny pre: true post: true activity: var j : int := 0 ; for i : Integer.subrange(0, N-1) do ( if (i->compareTo(L)) <= 0 or (i->compareTo(R)) >= 0 then ( A[j+1] := A[i+1] ; j := j + 1 ) else skip) ; return j; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) INF=1000000000 count=0 def merge(A,left,mid,right): L=A[left : mid]+[INF] R=A[mid : right]+[INF] global count i,j=0,0 for k in range(left,right): if L[i]<=R[j]: A[k]=L[i] i+=1 count+=1 else : A[k]=R[j] j+=1 count+=1 def mergeSort(A,left,right): if left+1toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var INF : int := 1000000000 ; var count : int := 0 ; skip ; skip ; mergeSort(a, 0, n) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display() ; execute (count)->display(); operation merge(A : OclAny, left : OclAny, mid : OclAny, right : OclAny) pre: true post: true activity: var L : OclAny := A.subrange(left+1, mid)->union(Sequence{ INF }) ; var R : OclAny := A.subrange(mid+1, right)->union(Sequence{ INF }) ; skip ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,0} ; for k : Integer.subrange(left, right-1) do ( if (L[i+1]->compareTo(R[j+1])) <= 0 then ( A[k+1] := L[i+1] ; i := i + 1 ; count := count + 1 ) else ( A[k+1] := R[j+1] ; j := j + 1 ; count := count + 1 )); operation mergeSort(A : OclAny, left : OclAny, right : OclAny) pre: true post: true activity: if (left + 1->compareTo(right)) < 0 then ( mid := ("" + (((left + right) / 2)))->toInteger() ; mergeSort(A, left, mid) ; mergeSort(A, mid, right) ; merge(A, left, mid, right) ) else skip ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math j=0 while j<20 : n=int(input()) if(n==0): break i=0 a=0 b=0 c=0 d=0 e=0 f=0 while itoInteger() ; if (n = 0) then ( break ) else skip ; var i : int := 0 ; var a : int := 0 ; var b : int := 0 ; var c : int := 0 ; var d : int := 0 ; var e : int := 0 ; var f : int := 0 ; while (i->compareTo(n)) < 0 do ( var x : OclAny := null; var y : OclAny := null; var h : OclAny := null; var w : OclAny := null; Sequence{x,y,h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var size : OclAny := x + y + h ; if (size <= 60 & w <= 2) then ( a := a + 1 ) else (if (size <= 80 & w <= 5) then ( b := b + 1 ) else (if (size <= 100 & w <= 10) then ( c := c + 1 ) else (if (size <= 120 & w <= 15) then ( d := d + 1 ) else (if (size <= 140 & w <= 20) then ( e := e + 1 ) else (if (size <= 160 & w <= 25) then ( f := f + 1 ) else skip ) ) ) ) ) ; i := i + 1) ; var total_money : int := (a * 600) + (b * 800) + (c * 1000) + (d * 1200) + (e * 1400) + (f * 1600) ; execute (("" + ((total_money))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isMultipleOf3(n): odd_count=0 even_count=0 if(n<0): n=-n if(n==0): return 1 if(n==1): return 0 while(n): if(n & 1): odd_count+=1 if(n & 2): even_count+=1 n=n>>2 return isMultipleOf3(abs(odd_count-even_count)) num=24 if(isMultipleOf3(num)): print(num,'is multiple of 3') else : print(num,'is not a multiple of 3') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var num : int := 24 ; if (isMultipleOf3(num)) then ( execute (num)->display() ) else ( execute (num)->display() ); operation isMultipleOf3(n : OclAny) : OclAny pre: true post: true activity: var odd_count : int := 0 ; var even_count : int := 0 ; if (n < 0) then ( n := -n ) else skip ; if (n = 0) then ( return 1 ) else skip ; if (n = 1) then ( return 0 ) else skip ; while (n) do ( if (MathLib.bitwiseAnd(n, 1)) then ( odd_count := odd_count + 1 ) else skip ; if (MathLib.bitwiseAnd(n, 2)) then ( even_count := even_count + 1 ) else skip ; n := n /(2->pow(2))) ; return isMultipleOf3((odd_count - even_count)->abs()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lineFromPoints(P,Q): a=Q[1]-P[1] b=P[0]-Q[0] c=a*(P[0])+b*(P[1]) if(b<0): print("The line passing through points P and Q is:",a,"x ",b,"y=",c,"\n") else : print("The line passing through points P and Q is: ",a,"x+",b,"y=",c,"\n") if __name__=='__main__' : P=[3,2] Q=[2,6] lineFromPoints(P,Q) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( P := Sequence{3}->union(Sequence{ 2 }) ; Q := Sequence{2}->union(Sequence{ 6 }) ; lineFromPoints(P, Q) ) else skip; operation lineFromPoints(P : OclAny, Q : OclAny) pre: true post: true activity: var a : double := Q[1+1] - P[1+1] ; var b : double := P->first() - Q->first() ; var c : double := a * (P->first()) + b * (P[1+1]) ; if (b < 0) then ( execute ("The line passing through points P and Q is:")->display() ) else ( execute ("The line passing through points P and Q is: ")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculateSum(n): if(n<=0): return 0 fibo=[0]*(n+1) fibo[1]=1 sm=fibo[0]+fibo[1] for i in range(2,n+1): fibo[i]=fibo[i-1]+fibo[i-2] sm=sm+fibo[i] return sm n=4 print("Sum of Fibonacci numbers is : ",calculateSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute ("Sum of Fibonacci numbers is : ")->display(); operation calculateSum(n : OclAny) : OclAny pre: true post: true activity: if (n <= 0) then ( return 0 ) else skip ; var fibo : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; fibo[1+1] := 1 ; var sm : OclAny := fibo->first() + fibo[1+1] ; for i : Integer.subrange(2, n + 1-1) do ( fibo[i+1] := fibo[i - 1+1] + fibo[i - 2+1] ; sm := sm + fibo[i+1]) ; return sm; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* def calculateSum(n): r1,r2=2,3 a1,a2=1,1 return(a1*(pow(r1,n)-1)//(r1-1)+a2*(pow(r2,n)-1)//(r2-1)) if __name__=="__main__" : n=4 print("SUM=",calculateSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 4 ; execute ("SUM=")->display() ) else skip; operation calculateSum(n : OclAny) : OclAny pre: true post: true activity: var r1 : OclAny := null; var r2 : OclAny := null; Sequence{r1,r2} := Sequence{2,3} ; var a1 : OclAny := null; var a2 : OclAny := null; Sequence{a1,a2} := Sequence{1,1} ; return (a1 * ((r1)->pow(n) - 1) div (r1 - 1) + a2 * ((r2)->pow(n) - 1) div (r2 - 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : A=[int(x)for x in input().split(' ')] if A[0]==A[1]==0 : break A.sort() print(A[0],A[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var A : Sequence := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if A->first() = A[1+1] & (A[1+1] == 0) then ( break ) else skip ; A := A->sort() ; execute (A->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countMaxSetBits(left,right): max_count=-1 for i in range(left,right+1): temp=i cnt=0 while temp : if temp & 1 : cnt+=1 temp=temp>>1 if cnt>max_count : max_count=cnt num=i return num l=1 r=5 print(countMaxSetBits(l,r)) l=1 r=10 print(countMaxSetBits(l,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var l : int := 1 ; var r : int := 5 ; execute (countMaxSetBits(l, r))->display() ; l := 1 ; r := 10 ; execute (countMaxSetBits(l, r))->display(); operation countMaxSetBits(left : OclAny, right : OclAny) : OclAny pre: true post: true activity: var max_count : int := -1 ; for i : Integer.subrange(left, right + 1-1) do ( var temp : OclAny := i ; var cnt : int := 0 ; while temp do ( if MathLib.bitwiseAnd(temp, 1) then ( cnt := cnt + 1 ) else skip ; temp := temp /(2->pow(1))) ; if (cnt->compareTo(max_count)) > 0 then ( max_count := cnt ; var num : OclAny := i ) else skip) ; return num; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minJumps(arr,n): jumps=[0 for i in range(n)] if(n==0)or(arr[0]==0): return float('inf') jumps[0]=0 for i in range(1,n): jumps[i]=float('inf') for j in range(i): if(i<=j+arr[j])and(jumps[j]!=float('inf')): jumps[i]=min(jumps[i],jumps[j]+1) break return jumps[n-1] arr=[1,3,6,1,0,9] size=len(arr) print('Minimum number of jumps to reach','end is',minJumps(arr,size)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{3}->union(Sequence{6}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 9 }))))) ; var size : int := (arr)->size() ; execute ('Minimum number of jumps to reach')->display(); operation minJumps(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var jumps : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; if (n = 0) or (arr->first() = 0) then ( return ("" + (('inf')))->toReal() ) else skip ; jumps->first() := 0 ; for i : Integer.subrange(1, n-1) do ( jumps[i+1] := ("" + (('inf')))->toReal() ; for j : Integer.subrange(0, i-1) do ( if ((i->compareTo(j + arr[j+1])) <= 0) & (jumps[j+1] /= ("" + (('inf')))->toReal()) then ( jumps[i+1] := Set{jumps[i+1], jumps[j+1] + 1}->min() ; break ) else skip)) ; return jumps[n - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minJumps(arr,n): jumps=[0 for i in range(n)] for i in range(n-2,-1,-1): if(arr[i]==0): jumps[i]=float('inf') elif(arr[i]>=n-i-1): jumps[i]=1 else : min=float('inf') for j in range(i+1,n): if(j<=arr[i]+i): if(min>jumps[j]): min=jumps[j] if(min!=float('inf')): jumps[i]=min+1 else : jumps[i]=min return jumps[0] arr=[1,3,6,3,2,3,6,8,9,5] n=len(arr) print('Minimum number of jumps to reach','end is',minJumps(arr,n-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{3}->union(Sequence{6}->union(Sequence{3}->union(Sequence{2}->union(Sequence{3}->union(Sequence{6}->union(Sequence{8}->union(Sequence{9}->union(Sequence{ 5 }))))))))) ; n := (arr)->size() ; execute ('Minimum number of jumps to reach')->display(); operation minJumps(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var jumps : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( if (arr[i+1] = 0) then ( jumps[i+1] := ("" + (('inf')))->toReal() ) else (if ((arr[i+1]->compareTo(n - i - 1)) >= 0) then ( jumps[i+1] := 1 ) else ( var min : double := ("" + (('inf')))->toReal() ; for j : Integer.subrange(i + 1, n-1) do ( if ((j->compareTo(arr[i+1] + i)) <= 0) then ( if ((min->compareTo(jumps[j+1])) > 0) then ( min := jumps[j+1] ) else skip ) else skip) ; if (min /= ("" + (('inf')))->toReal()) then ( jumps[i+1] := min + 1 ) else ( jumps[i+1] := min ) ) ) ) ; return jumps->first(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from queue import deque n,s=map(int,input().split()) q=deque() t=0 ans=1e6 for a in map(int,input().split()): t+=a q.append(a) if t=s : t-=q.popleft() ans=min(ans,len(q)+1) print(ans if ans<1e6 else 0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var q : Sequence := () ; var t : int := 0 ; var ans : double := ("1e6")->toReal() ; for a : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( t := t + a ; execute ((a) : q) ; if (t->compareTo(s)) < 0 then ( continue ) else skip ; while (t->compareTo(s)) >= 0 do ( t := t - q->first() ; q := q->tail()) ; ans := Set{ans, (q)->size() + 1}->min()) ; execute (if ans < ("1e6")->toReal() then ans else 0 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy BIG_NUM=2000000000 MOD=1000000007 EPS=0.000000001 N,S=map(int,input().split()) table=list(map(int,input().split())) ans=BIG_NUM left=0 right=0 tmp_sum=table[0] while left=S : ans=min(ans,right-left+1) break if right==len(table)-1 : break right+=1 tmp_sum+=table[right] if tmp_sumright : break tmp_sum-=table[left] left+=1 if tmp_sum>=S : ans=min(ans,right-left+1) else : break right=max(right,left) if ans==BIG_NUM : print("0") else : print("%d" %(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; var N : OclAny := null; var S : OclAny := null; Sequence{N,S} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var table : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := BIG_NUM ; var left : int := 0 ; var right : int := 0 ; var tmp_sum : OclAny := table->first() ; while (left->compareTo((table)->size())) < 0 do ( while true do ( if (tmp_sum->compareTo(S)) >= 0 then ( ans := Set{ans, right - left + 1}->min() ; break ) else skip ; if right = (table)->size() - 1 then ( break ) else skip ; right := right + 1 ; tmp_sum := tmp_sum + table[right+1]) ; if (tmp_sum->compareTo(S)) < 0 then ( break ) else skip ; while true do ( if (left->compareTo(right)) > 0 then ( break ) else skip ; tmp_sum := tmp_sum - table[left+1] ; left := left + 1 ; if (tmp_sum->compareTo(S)) >= 0 then ( ans := Set{ans, right - left + 1}->min() ) else ( break )) ; right := Set{right, left}->max()) ; if ans = BIG_NUM then ( execute ("0")->display() ) else ( execute (StringLib.format("%d",(ans)))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys _exchange=0 def merge_sort(A,left,right): if left+1toInteger() ; A := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; merge_sort(A, 0, n) ; execute ((argument * (test (logical_test (comparison (expr (atom (name A))))))))->display() ; execute (_exchange)->display() ) else skip; operation merge_sort(A : OclAny, left : OclAny, right : OclAny) pre: true post: true activity: if (left + 1->compareTo(right)) < 0 then ( var mid : int := (left + right) div 2 ; merge_sort(A, left, mid) ; merge_sort(A, mid, right) ; merge(A, left, mid, right) ) else skip; operation merge(A : OclAny, left : OclAny, mid : OclAny, right : OclAny) pre: true post: true activity: var first : OclAny := A.subrange(left+1, mid) ; execute (() : first) ; var second : OclAny := A.subrange(mid+1, right) ; execute (() : second) ; skip ; var i : OclAny := 0; var j : int := 0 ; for k : Integer.subrange(left, right-1) do ( _exchange := _exchange + 1 ; if (first[i+1]->compareTo(second[j+1])) <= 0 then ( A[k+1] := first[i+1] ; i := i + 1 ) else ( A[k+1] := second[j+1] ; j := j + 1 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find(xs,size,s): sum_=sum(xs[: size]) if s<=sum_ : return True for i in range(len(xs)-size): sum_-=xs[i] sum_+=xs[i+size] if s<=sum_ : return True return False def run(): n,s=[int(i)for i in input().split()] li=[int(i)for i in input().split()] if s>sum(li): print(0) return elif ssum() ; if (s->compareTo(sum_)) <= 0 then ( return true ) else skip ; for i : Integer.subrange(0, (xs)->size() - size-1) do ( sum_ := sum_ - xs[i+1] ; sum_ := sum_ + xs[i + size+1] ; if (s->compareTo(sum_)) <= 0 then ( return true ) else skip) ; return false; operation run() pre: true post: true activity: var n : OclAny := null; Sequence{n,s} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var li : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if (s->compareTo((li)->sum())) > 0 then ( execute (0)->display() ; return ) else (if (s->compareTo((li)->max())) < 0 then ( execute (1)->display() ; return ) else skip) ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,n} ; while (i + 1->compareTo(j)) < 0 do ( var mid : int := (i + j) div 2 ; if find(li, mid, s) then ( var j : int := mid ) else ( var i : int := mid )) ; execute (j)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,setrecursionlimit from bisect import bisect_left setrecursionlimit(10**6) input=stdin.readline n,s=map(int,input().split()) a=[int(i)for i in input().split()] nows=0 ans=2<<20 left=0 for right in range(n): nows+=a[right] while left<=right and right=s : ans=min(ans,right-left+1) nows-=a[left] left+=1 else : break print(ans %(2<<20)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; setrecursionlimit((10)->pow(6)) ; var input : OclAny := stdin.readline ; var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var nows : int := 0 ; var ans : int := 2 * (2->pow(20)) ; var left : int := 0 ; for right : Integer.subrange(0, n-1) do ( nows := nows + a[right+1] ; while (left->compareTo(right)) <= 0 & (right->compareTo(n)) < 0 do ( if (nows->compareTo(s)) >= 0 then ( ans := Set{ans, right - left + 1}->min() ; nows := nows - a[left+1] ; left := left + 1 ) else ( break ))) ; execute (ans mod (2 * (2->pow(20))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def LI(): return list(map(int,input().split())) def II(): return int(input()) def LS(): return input().split() def S(): return input() def LIR(n): return[LI()for i in range(n)] def MI(): return map(int,input().split()) n,s=MI() a=LI() for i in range(1,n): a[i]+=a[i-1] a.insert(0,0) l=0 r=0 ans=float("inf") if a[1]>=s : print(1) quit() while r=s : while a[r]-a[l]>=s and ltoReal() ; if (a[1+1]->compareTo(s)) >= 0 then ( execute (1)->display() ; quit() ) else skip ; while (r->compareTo(n)) < 0 do ( r := r + 1 ; if (a[r+1] - a[l+1]->compareTo(s)) >= 0 then ( while (a[r+1] - a[l+1]->compareTo(s)) >= 0 & (l->compareTo(r)) < 0 do ( l := l + 1) ; ans := Set{ans, r - l + 1}->min() ) else skip) ; if ans = ("" + (("inf")))->toReal() then ( execute (0)->display() ; quit() ) else skip ; execute (ans)->display(); operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return input().split(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation MI() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil h1,h2=map(int,input().split()) a,b=map(int,input().split()) h1+=8*a if h1>=h2 : k=0 else : delta=12*(a-b) if delta : k=int(ceil((h2-h1)/delta)) if k<=0 : k=-1 else : k=-1 print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var h1 : OclAny := null; var h2 : OclAny := null; Sequence{h1,h2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; h1 := h1 + 8 * a ; if (h1->compareTo(h2)) >= 0 then ( var k : int := 0 ) else ( var delta : double := 12 * (a - b) ; if delta then ( k := ("" + ((ceil((h2 - h1) / delta))))->toInteger() ; if k <= 0 then ( k := -1 ) else skip ) else ( k := -1 ) ) ; execute (k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B,C=map(int,input().split()) x=dict() x[5]=0 x[7]=0 if A==5 : x[5]+=1 elif A==7 : x[7]+=1 if B==5 : x[5]+=1 elif B==7 : x[7]+=1 if C==5 : x[5]+=1 elif C==7 : x[7]+=1 flag=False if x[5]==2 : if x[7]==1 : flag=True if flag : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{A,B,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Map := (arguments ( )) ; x[5+1] := 0 ; x[7+1] := 0 ; if A = 5 then ( x[5+1] := x[5+1] + 1 ) else (if A = 7 then ( x[7+1] := x[7+1] + 1 ) else skip) ; if B = 5 then ( x[5+1] := x[5+1] + 1 ) else (if B = 7 then ( x[7+1] := x[7+1] + 1 ) else skip) ; if C = 5 then ( x[5+1] := x[5+1] + 1 ) else (if C = 7 then ( x[7+1] := x[7+1] + 1 ) else skip) ; var flag : boolean := false ; if x[5+1] = 2 then ( if x[7+1] = 1 then ( flag := true ) else skip ) else skip ; if flag then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h1,h2=map(int,input().split()) a,b=map(int,input().split()) d,v=h2-h1-8*a,12*(a-b) if d<=0 : print(0) elif b>=a : print(-1) else : print((d+v-1)//v) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h1 : OclAny := null; var h2 : OclAny := null; Sequence{h1,h2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : OclAny := null; var v : OclAny := null; Sequence{d,v} := Sequence{h2 - h1 - 8 * a,12 * (a - b)} ; if d <= 0 then ( execute (0)->display() ) else (if (b->compareTo(a)) >= 0 then ( execute (-1)->display() ) else ( execute ((d + v - 1) div v)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def get_ints(): return map(int,sys.stdin.readline().strip().split()) def get_array(): return list(map(int,sys.stdin.readline().strip().split())) def input(): return sys.stdin.readline().strip() MOD=1000000007 h1,h2=get_ints() a,b=get_ints() i=0 cnt=0 ans=h1 start=0 end=0 if h1+8*a

=h2 : break else : cnt+=1 else : start=ans+12*a end=12*b ans=start-end if start>=h2 : break else : cnt+=1 i+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var MOD : int := 1000000007 ; var h1 : OclAny := null; var h2 : OclAny := null; Sequence{h1,h2} := get_ints() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := get_ints() ; var i : int := 0 ; var cnt : int := 0 ; var ans : OclAny := h1 ; var start : int := 0 ; var end : int := 0 ; if (h1 + 8 * a->compareTo(h2)) < 0 & (a->compareTo(b)) <= 0 then ( execute (-1)->display() ) else ( while (start->compareTo(h2)) <= 0 do ( if i = 0 then ( start := ans + 8 * a ; end := 12 * b ; ans := start - end ; if (start->compareTo(h2)) >= 0 then ( break ) else ( cnt := cnt + 1 ) ) else ( start := ans + 12 * a ; end := 12 * b ; ans := start - end ; if (start->compareTo(h2)) >= 0 then ( break ) else ( cnt := cnt + 1 ) ) ; i := i + 1) ; execute (cnt)->display() ); operation get_ints() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ); operation get_array() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math h1,h2=map(int,input().split()) a,b=map(int,input().split()) full_way=h2-h1 days=0 passed=a*8 if passed>=full_way : print(days) exit(0) full_way-=passed delta_per_day=(a-b)*12 if delta_per_day<=0 : print(-1) exit(0) print(math.ceil(full_way/delta_per_day)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var h1 : OclAny := null; var h2 : OclAny := null; Sequence{h1,h2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var full_way : double := h2 - h1 ; var days : int := 0 ; var passed : double := a * 8 ; if (passed->compareTo(full_way)) >= 0 then ( execute (days)->display() ; exit(0) ) else skip ; full_way := full_way - passed ; var delta_per_day : double := (a - b) * 12 ; if delta_per_day <= 0 then ( execute (-1)->display() ; exit(0) ) else skip ; execute ((full_way / delta_per_day)->ceil())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000001 def countNum(N,K): sumPF=[0]*MAX ; for i in range(2,N): if(sumPF[i]==0): for j in range(i,N,i): sumPF[j]+=i ; count=0 ; for i in range(2,N): if(sumPF[i]==K): count+=1 ; return count ; if __name__=="__main__" : N=20 ; K=7 ; print(countNum(N,K)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1000001 ; skip ; if __name__ = "__main__" then ( N := 20; K := 7; ; execute (countNum(N, K))->display(); ) else skip; operation countNum(N : OclAny, K : OclAny) pre: true post: true activity: var sumPF : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX); ; for i : Integer.subrange(2, N-1) do ( if (sumPF[i+1] = 0) then ( for j : Integer.subrange(i, N-1)->select( $x | ($x - i) mod i = 0 ) do ( sumPF[j+1] := sumPF[j+1] + i;) ) else skip) ; var count : int := 0; ; for i : Integer.subrange(2, N-1) do ( if (sumPF[i+1] = K) then ( count := count + 1; ) else skip) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=input().lower() p=set(m) if len(p)==26 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : OclAny := input()->toLowerCase() ; var p : Set := Set{}->union((m)) ; if (p)->size() = 26 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r=int(input()) u=input()[: r] x=u.lower() alpbts="abcdefghijklmnopqrstuvwxyz" flag=0 for char in alpbts : if char not in x : flag=1 if flag==1 : print("NO"); else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var u : OclAny := input().subrange(1,r) ; var x : String := u->toLowerCase() ; var alpbts : String := "abcdefghijklmnopqrstuvwxyz" ; var flag : int := 0 ; for char : alpbts->characters() do ( if (x)->characters()->excludes(char) then ( flag := 1 ) else skip) ; if flag = 1 then ( execute ("NO")->display(); ) else ( execute ("YES")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from typing import List import math n=int(input()) S=[int(i)for i in input().split()] hikaku=0 def merge(A : List[int],left : int,mid : int,right : int)->None : global hikaku left_list=A[left : mid] right_list=A[mid : right] left_list.append(sys.maxsize) right_list.append(sys.maxsize) i=0 j=0 for k in range(left,right): hikaku+=1 if left_list[i]<=right_list[j]: A[k]=left_list[i] i+=1 else : A[k]=right_list[j] j+=1 def merge_sort(A : List[int],left : int,right : int)->int : if left+1toInteger() ; var S : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var hikaku : int := 0 ; skip ; skip ; merge_sort(S, 0, (S)->size()) ; execute (StringLib.sumStringsWithSeparator(((S)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ; execute (hikaku)->display(); operation merge(A : List[OclType["int"]+1], left : int, mid : int, right : int) : OclAny pre: true post: true activity: skip ; var left_list : OclAny := A.subrange(left+1, mid) ; var right_list : OclAny := A.subrange(mid+1, right) ; execute (((trailer . (name maxsize))) : left_list) ; execute (((trailer . (name maxsize))) : right_list) ; var i : int := 0 ; var j : int := 0 ; for k : Integer.subrange(left, right-1) do ( hikaku := hikaku + 1 ; if (left_list[i+1]->compareTo(right_list[j+1])) <= 0 then ( A[k+1] := left_list[i+1] ; i := i + 1 ) else ( A[k+1] := right_list[j+1] ; j := j + 1 )); operation merge_sort(A : List[OclType["int"]+1], left : int, right : int) : int pre: true post: true activity: if (left + 1->compareTo(right)) < 0 then ( var mid : double := ((left + right) / 2)->floor() ; merge_sort(A, left, mid) ; merge_sort(A, mid, right) ; merge(A, left, mid, right) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- y=input() x=input() result="".join(dict.fromkeys(x.lower())) if len(result)==26 : print('YES') else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var y : String := (OclFile["System.in"]).readLine() ; var x : String := (OclFile["System.in"]).readLine() ; var result : String := StringLib.sumStringsWithSeparator(((trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)) (trailer . (name lower) (arguments ( ))))))))) )))), "") ; if (result)->size() = 26 then ( execute ('YES')->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) k=0 s=input() alph={"a","b","c","d",'e','f',"g","h","i","j","k","l","m","n","o","p",'q','r','s','t','u','v','w','x','y','z'} for i in s : k=i.lower() if k in alph : alph.remove(k) if len(alph)==0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := 0 ; var s : String := (OclFile["System.in"]).readLine() ; var alph : Set := Set{"a"}->union(Set{"b"}->union(Set{"c"}->union(Set{"d"}->union(Set{'e'}->union(Set{'f'}->union(Set{"g"}->union(Set{"h"}->union(Set{"i"}->union(Set{"j"}->union(Set{"k"}->union(Set{"l"}->union(Set{"m"}->union(Set{"n"}->union(Set{"o"}->union(Set{"p"}->union(Set{'q'}->union(Set{'r'}->union(Set{'s'}->union(Set{'t'}->union(Set{'u'}->union(Set{'v'}->union(Set{'w'}->union(Set{'x'}->union(Set{'y'}->union(Set{ 'z' }))))))))))))))))))))))))) ; for i : s->characters() do ( k := i->toLowerCase() ; if (alph)->includes(k) then ( execute ((k) /: alph) ) else skip) ; if (alph)->size() = 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) word=set(input().lower()) print("YNEOS"[len(word)!=26 : : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var word : Set := Set{}->union((input()->toLowerCase())) ; execute ("YNEOS"(subscript (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name word)))))))) ))))) != (comparison (expr (atom (number (integer 26)))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=input()[: :-1] if n[: 2]=='op' : print('FILIPINO') elif n[: 5]=='adinm' : print('KOREAN') else : print('JAPANESE') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := input()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; if n.subrange(1,2) = 'op' then ( execute ('FILIPINO')->display() ) else (if n.subrange(1,5) = 'adinm' then ( execute ('KOREAN')->display() ) else ( execute ('JAPANESE')->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import* n=int(input()) R=[list(map(int,input().split()))for _ in range(n)] sx,sy,mx,my=1e5,1e5,0,0 for x1,y1,x2,y2 in R : sx=min(sx,x1) sy=min(sy,y1) mx=max(mx,x2) my=max(my,y2) if mx-sx!=my-sy : print("NO") exit(0) A=(mx-sx)*(my-sy) for x1,y1,x2,y2 in R : A-=(x2-x1)*(y2-y1) if A==0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var R : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var sx : OclAny := null; var sy : OclAny := null; var mx : OclAny := null; var my : OclAny := null; Sequence{sx,sy,mx,my} := Sequence{("1e5")->toReal(),("1e5")->toReal(),0,0} ; for _tuple : R do (var _indx : int := 1; var x1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x2 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y2 : OclAny := _tuple->at(_indx); var sx : OclAny := Set{sx, x1}->min() ; var sy : OclAny := Set{sy, y1}->min() ; var mx : OclAny := Set{mx, x2}->max() ; var my : OclAny := Set{my, y2}->max()) ; if mx - sx /= my - sy then ( execute ("NO")->display() ; exit(0) ) else skip ; var A : double := (mx - sx) * (my - sy) ; for _tuple : R do (var _indx : int := 1; var x1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x2 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y2 : OclAny := _tuple->at(_indx); A := A - (x2 - x1) * (y2 - y1)) ; if A = 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x0=[]; x1=[]; y0=[]; y1=[] n=int(input()) s=0 for i in range(n): l=list(map(int,input().split())) x0.extend([l[0]]) x1.extend([l[2]]) y0.extend([l[1]]) y1.extend([l[3]]) s+=(l[3]-l[1])*(l[2]-l[0]) lx=max(x1)-min(x0) ly=max(y1)-min(y0) if lx==ly and lx*ly==s : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x0 : Sequence := Sequence{}; var x1 : Sequence := Sequence{}; var y0 : Sequence := Sequence{}; var y1 : Sequence := Sequence{} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : int := 0 ; for i : Integer.subrange(0, n-1) do ( var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; x0 := x0->union(Sequence{ l->first() }) ; x1 := x1->union(Sequence{ l[2+1] }) ; y0 := y0->union(Sequence{ l[1+1] }) ; y1 := y1->union(Sequence{ l[3+1] }) ; s := s + (l[3+1] - l[1+1]) * (l[2+1] - l->first())) ; var lx : double := (x1)->max() - (x0)->min() ; var ly : double := (y1)->max() - (y0)->min() ; if lx = ly & lx * ly = s then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x1,y1,x2,y2=map(int,input().split()) l,r,u,d=x1,x2,y2,y1 s=(x2-x1)*(y2-y1) for i in range(n-1): x1,y1,x2,y2=map(int,input().split()) s+=(x2-x1)*(y2-y1) l=min(l,x1) r=max(r,x2) u=max(u,y2) d=min(d,y1) if r-l==u-d and(r-l)*(u-d)==s : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : OclAny := null; var r : OclAny := null; var u : OclAny := null; var d : OclAny := null; Sequence{l,r,u,d} := Sequence{x1,x2,y2,y1} ; var s : double := (x2 - x1) * (y2 - y1) ; for i : Integer.subrange(0, n - 1-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; s := s + (x2 - x1) * (y2 - y1) ; var l : OclAny := Set{l, x1}->min() ; var r : OclAny := Set{r, x2}->max() ; var u : OclAny := Set{u, y2}->max() ; var d : OclAny := Set{d, y1}->min()) ; if r - l = u - d & (r - l) * (u - d) = s then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(l,i): return min(l)if i<2 else max(l) class CodeforcesTask325ASolution : def __init__(self): self.result='' self.n=0 self.rectangles=[] def read_input(self): self.n=int(input()) for _ in range(self.n): self.rectangles.append([int(x)for x in input().split(" ")]) def process_task(self): cords=[f([x[i]for x in self.rectangles],i)for i in range(4)] fields=[(x[3]-x[1])*(x[2]-x[0])for x in self.rectangles] ff=sum(fields) if ff==(cords[3]-cords[1])*(cords[2]-cords[0])and cords[3]-cords[1]==cords[2]-cords[0]: self.result="YES" else : self.result="NO" def get_result(self): return self.result if __name__=="__main__" : Solution=CodeforcesTask325ASolution() Solution.read_input() Solution.process_task() print(Solution.get_result()) ------------------------------------------------------------ OCL File: --------- class CodeforcesTask325ASolution { static operation newCodeforcesTask325ASolution() : CodeforcesTask325ASolution pre: true post: CodeforcesTask325ASolution->exists( _x | result = _x ); attribute result : String := ''; attribute n : int := 0; attribute rectangles : Sequence := Sequence{}; operation initialise() : CodeforcesTask325ASolution pre: true post: true activity: self.result := '' ; self.n := 0 ; self.rectangles := Sequence{}; return self; operation read_input() pre: true post: true activity: self.n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, self.n-1) do ((expr (atom (name self)) (trailer . (name rectangles)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " "))))))) )))))))) ]))))))) ))))); operation process_task() pre: true post: true activity: var cords : Sequence := Integer.subrange(0, 4-1)->select(i | true)->collect(i | (f(self.rectangles->select(x | true)->collect(x | (x[i+1])), i))) ; var fields : Sequence := self.rectangles->select(x | true)->collect(x | ((x[3+1] - x[1+1]) * (x[2+1] - x->first()))) ; var ff : OclAny := (fields)->sum() ; if ff = (cords[3+1] - cords[1+1]) * (cords[2+1] - cords->first()) & cords[3+1] - cords[1+1] = cords[2+1] - cords->first() then ( self.result := "YES" ) else ( self.result := "NO" ); operation get_result() : OclAny pre: true post: true activity: return self.result; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var Solution : CodeforcesTask325ASolution := (CodeforcesTask325ASolution.newCodeforcesTask325ASolution()).initialise() ; Solution.read_input() ; Solution.process_task() ; execute (Solution.get_result())->display() ) else skip; operation f(l : OclAny, i : OclAny) : OclAny pre: true post: true activity: return if i < 2 then (l)->min() else (l)->max() endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- xmin,ymin,xmax,ymax,a=31400,31400,0,0,0 for i in range(int(input())): x1,y1,x2,y2=map(int,input().split()) xmin=min(xmin,x1) ymin=min(ymin,y1) xmax=max(xmax,x2) ymax=max(ymax,y2) a+=(x2-x1)*(y2-y1) print('YES' if xmax-xmin==ymax-ymin and a==(xmax-xmin)**2 else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var xmin : OclAny := null; var ymin : OclAny := null; var xmax : OclAny := null; var ymax : OclAny := null; var a : OclAny := null; Sequence{xmin,ymin,xmax,ymax,a} := Sequence{31400,31400,0,0,0} ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var xmin : OclAny := Set{xmin, x1}->min() ; var ymin : OclAny := Set{ymin, y1}->min() ; var xmax : OclAny := Set{xmax, x2}->max() ; var ymax : OclAny := Set{ymax, y2}->max() ; a := a + (x2 - x1) * (y2 - y1)) ; execute (if xmax - xmin = ymax - ymin & a = ((xmax - xmin))->pow(2) then 'YES' else 'NO' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math C=3 def solveQuery(arr,n,Q,query): even=[0]*(n+1) odd=[0]*(n+1) even[0]=0 odd[0]=0 for i in range(n): if(arr[i]& 1): odd[i+1]=odd[i]+1 even[i+1]=even[i] else : even[i+1]=even[i]+1 odd[i+1]=odd[i] for i in range(Q): r=query[i][2] l=query[i][1] k=query[i][0] q=r-l+1 if(k): p=odd[r]-odd[l-1] else : p=even[r]-even[l-1] if(not p): print("0") elif(p==q): print("1") else : g=math.gcd(p,q) print((p//g),(q//g)) if __name__=="__main__" : arr=[6,5,2,1,7] n=len(arr) Q=2 query=[[0,2,2],[1,2,5]] solveQuery(arr,n,Q,query) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var C : int := 3 ; skip ; if __name__ = "__main__" then ( arr := Sequence{6}->union(Sequence{5}->union(Sequence{2}->union(Sequence{1}->union(Sequence{ 7 })))) ; n := (arr)->size() ; Q := 2 ; query := Sequence{Sequence{0}->union(Sequence{2}->union(Sequence{ 2 }))}->union(Sequence{ Sequence{1}->union(Sequence{2}->union(Sequence{ 5 })) }) ; solveQuery(arr, n, Q, query) ) else skip; operation solveQuery(arr : OclAny, n : OclAny, Q : OclAny, query : OclAny) pre: true post: true activity: var even : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var odd : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; even->first() := 0 ; odd->first() := 0 ; for i : Integer.subrange(0, n-1) do ( if (MathLib.bitwiseAnd(arr[i+1], 1)) then ( odd[i + 1+1] := odd[i+1] + 1 ; even[i + 1+1] := even[i+1] ) else ( even[i + 1+1] := even[i+1] + 1 ; odd[i + 1+1] := odd[i+1] )) ; for i : Integer.subrange(0, Q-1) do ( var r : OclAny := query[i+1][2+1] ; var l : OclAny := query[i+1][1+1] ; var k : OclAny := query[i+1]->first() ; var q : double := r - l + 1 ; if (k) then ( var p : double := odd[r+1] - odd[l - 1+1] ) else ( p := even[r+1] - even[l - 1+1] ) ; if (not(p)) then ( execute ("0")->display() ) else (if (p = q) then ( execute ("1")->display() ) else ( var g : long := (p)->gcd(q) ; execute ((p div g))->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMaxProduct(arr,n): ans=-float('inf') maxval=1 minval=1 for i in range(0,n): if arr[i]>0 : maxval=maxval*arr[i] minval=min(1,minval*arr[i]) elif arr[i]==0 : minval=1 maxval=0 elif arr[i]<0 : prevMax=maxval maxval=minval*arr[i] minval=prevMax*arr[i] ans=max(ans,maxval) if maxval<=0 : maxval=1 return ans if __name__=="__main__" : arr=[0,-4,0,-2] n=len(arr) print(findMaxProduct(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{0}->union(Sequence{-4}->union(Sequence{0}->union(Sequence{ -2 }))) ; n := (arr)->size() ; execute (findMaxProduct(arr, n))->display() ) else skip; operation findMaxProduct(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : double := -("" + (('inf')))->toReal() ; var maxval : int := 1 ; var minval : int := 1 ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] > 0 then ( maxval := maxval * arr[i+1] ; minval := Set{1, minval * arr[i+1]}->min() ) else (if arr[i+1] = 0 then ( minval := 1 ; maxval := 0 ) else (if arr[i+1] < 0 then ( var prevMax : int := maxval ; maxval := minval * arr[i+1] ; minval := prevMax * arr[i+1] ) else skip ) ) ; ans := Set{ans, maxval}->max() ; if maxval <= 0 then ( maxval := 1 ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def m(L,R): T=[] for l in L[: :-1]: while R and R[-1]>l : T+=[R.pop()] T+=[l] return R+T[: :-1] def d(A): l=len(A); global c ; c+=l s=l//2 ; return m(d(A[: s]),d(A[s :]))if l>1 else A c=-int(input()) print(*d(list(map(int,input().split())))) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; c := -("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((argument * (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))))))) )))))))))->display() ; execute (c)->display(); operation m(L : OclAny, R : OclAny) : OclAny pre: true post: true activity: var T : Sequence := Sequence{} ; for l : L(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( while R & (R->last()->compareTo(l)) > 0 do ( T := T + Sequence{ R->last() }) ; T := T + Sequence{ l }) ; return R + T(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); operation d(A : OclAny) : OclAny pre: true post: true activity: var l : int := (A)->size(); skip; c := c + l ; var s : int := l div 2; return if l > 1 then m(d(A.subrange(1,s)), d(A.subrange(s+1))) else A endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a,b=1023,0 for _ in range(n): c,d=input().split() d=int(d) if c=='|' : a,b=a | d,b | d elif c=='&' : a,b=a & d,b & d elif c=='^' : a,b=a ^ d,b ^ d print(f'2\n|{a^b^1023}\n^{a^1023}') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{1023,0} ; for _anon : Integer.subrange(0, n-1) do ( var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := input().split() ; var d : int := ("" + ((d)))->toInteger() ; if c = '|' then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{MathLib.bitwiseOr(a, d),MathLib.bitwiseOr(b, d)} ) else (if c = '&' then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{MathLib.bitwiseAnd(a, d),MathLib.bitwiseAnd(b, d)} ) else (if c = '^' then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{MathLib.bitwiseXor(a, d),MathLib.bitwiseXor(b, d)} ) else skip ) ) ) ; execute (StringLib.formattedString('2 |{a^b^1023} ^{a^1023}'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import operator func={'|' : operator.or_,'^' : operator.xor,'&' : operator.and_} n,x0,x1=int(input()),0,1023 ops,nums=zip(*[input().split()for _ in range(n)]) for op,x in zip(ops,nums): x=int(x) x0=func[op](x0,x) x1=func[op](x1,x) print(2) print('&',x0 ^ x1) print('^',x0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var func : Map := Map{ '|' |-> operator.or_ }->union(Map{ '^' |-> operator.xor }->union(Map{ '&' |-> operator.and_ })) ; var n : OclAny := null; var x0 : OclAny := null; var x1 : OclAny := null; Sequence{n,x0,x1} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),0,1023} ; var ops : OclAny := null; var nums : OclAny := null; Sequence{ops,nums} := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) ]))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) ]))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) ]))))))`third->at(_indx)} ) ; for _tuple : Integer.subrange(1, ops->size())->collect( _indx | Sequence{ops->at(_indx), nums->at(_indx)} ) do (var _indx : int := 1; var op : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); var x : int := ("" + ((x)))->toInteger() ; var x0 : OclAny := func[op+1](x0, x) ; var x1 : OclAny := func[op+1](x1, x)) ; execute (2)->display() ; execute ('&')->display() ; execute ('^')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): string=input() if string.endswith('po'): print('FILIPINO') elif string.endswith('desu')or string.endswith('masu'): print('JAPANESE') elif string.endswith('mnida'): print('KOREAN') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var string : String := (OclFile["System.in"]).readLine() ; if string->hasSuffix('po') then ( execute ('FILIPINO')->display() ) else (if string->hasSuffix('desu') or string->hasSuffix('masu') then ( execute ('JAPANESE')->display() ) else (if string->hasSuffix('mnida') then ( execute ('KOREAN')->display() ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s=input() return(list(s[: len(s)-1])) def invr(): return(map(int,input().split())) def main(): cases=inp() for foo in range(cases): holder=inp() skill_type=inlt() damage=inlt() frost=[] fire=[] for i in range(len(damage)): if skill_type[i]==0 : frost.append(damage[i]) else : fire.append(damage[i]) fire.sort() frost.sort() fire.reverse() frost.reverse() ans=0 j=min(len(frost),len(fire)) for i in range(j): ans+=2*frost[i]+2*fire[i] for i in range(j,len(frost)): ans+=frost[i] for i in range(j,len(fire)): ans+=fire[i] if len(frost)==len(fire): ans-=min(frost[-1],fire[-1]) print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation inp() : OclAny pre: true post: true activity: return (("" + (((OclFile["System.in"]).readLine())))->toInteger()); operation inlt() : OclAny pre: true post: true activity: return (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))); operation insr() : OclAny pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; return ((s.subrange(1,(s)->size() - 1))); operation invr() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation main() pre: true post: true activity: var cases : OclAny := inp() ; for foo : Integer.subrange(0, cases-1) do ( var holder : OclAny := inp() ; var skill_type : OclAny := inlt() ; var damage : OclAny := inlt() ; var frost : Sequence := Sequence{} ; var fire : Sequence := Sequence{} ; for i : Integer.subrange(0, (damage)->size()-1) do ( if skill_type[i+1] = 0 then ( execute ((damage[i+1]) : frost) ) else ( execute ((damage[i+1]) : fire) )) ; fire := fire->sort() ; frost := frost->sort() ; fire := fire->reverse() ; frost := frost->reverse() ; var ans : int := 0 ; var j : OclAny := Set{(frost)->size(), (fire)->size()}->min() ; for i : Integer.subrange(0, j-1) do ( ans := ans + 2 * frost[i+1] + 2 * fire[i+1]) ; for i : Integer.subrange(j, (frost)->size()-1) do ( ans := ans + frost[i+1]) ; for i : Integer.subrange(j, (fire)->size()-1) do ( ans := ans + fire[i+1]) ; if (frost)->size() = (fire)->size() then ( ans := ans - Set{frost->last(), fire->last()}->min() ) else skip ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input s=sorted for _ in[0]*int(I()): I(); a=[[],[]] for x,y in zip(I()[: : 2],I().split()): a[x>'0']+=int(y), a,b=s(a,key=len); l=len(a); print(sum(a*2+b+s(b)[: :-1][: l])-(l==len(b))*min(a+b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; var s : OclAny := sorted ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + ((I())))->toInteger()) do ( I(); var a : Sequence := Sequence{Sequence{}}->union(Sequence{ Sequence{} }) ; for _tuple : Integer.subrange(1, I()(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{I()(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->at(_indx), I().split()->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); a->select(x > '0') := a->select(x > '0') + (testlist (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) ))))))) ,)) ; var b : OclAny := null; Sequence{a,b} := s(a, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name len)))))))); var l : int := (a)->size(); execute ((MatrixLib.elementwiseMult(a, 2)->union(b)->union(s(b)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))).subrange(1,l)))->sum() - (l = (b)->size()) * (a->union(b))->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input s=sorted for _ in[0]*int(I()): I(); a=[[],[]] for x,y in zip(I()[: : 2],I().split()): a[x>'0']+=int(y), a,b=s(a,key=len); l=len(a); print(sum(a*2+b+s(b)[: :-1][: l])-(l==len(b))*min(a+b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; var s : OclAny := sorted ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + ((I())))->toInteger()) do ( I(); var a : Sequence := Sequence{Sequence{}}->union(Sequence{ Sequence{} }) ; for _tuple : Integer.subrange(1, I()(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->size())->collect( _indx | Sequence{I()(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))->at(_indx), I().split()->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); a->select(x > '0') := a->select(x > '0') + (testlist (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) ))))))) ,)) ; var b : OclAny := null; Sequence{a,b} := s(a, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name len)))))))); var l : int := (a)->size(); execute ((MatrixLib.elementwiseMult(a, 2)->union(b)->union(s(b)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))).subrange(1,l)))->sum() - (l = (b)->size()) * (a->union(b))->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input("")) for z in range(t): n=int(input("")) A=list(map(int,input('').split()))[: n] B=list(map(int,input('').split()))[: n] aL=[] bL=[] a=A.count(1) b=n-a if a==b : print((sum(B)*2)-min(B)) else : for i in range(n): if A[i]==1 : aL.append(B[i]) else : bL.append(B[i]) aL=sorted(aL) bL=sorted(bL) if btoInteger() ; for z : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine(""))))->toInteger() ; var A : OclAny := OclType["Sequence"]((input('').split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ; var B : OclAny := OclType["Sequence"]((input('').split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ; var aL : Sequence := Sequence{} ; var bL : Sequence := Sequence{} ; var a : int := A->count(1) ; var b : double := n - a ; if a = b then ( execute (((B)->sum() * 2) - (B)->min())->display() ) else ( for i : Integer.subrange(0, n-1) do ( if A[i+1] = 1 then ( execute ((B[i+1]) : aL) ) else ( execute ((B[i+1]) : bL) )) ; aL := aL->sort() ; bL := bL->sort() ; if (b->compareTo(a)) < 0 then ( var c : double := a - b ; execute (((B)->sum() * 2) - (aL.subrange(1,c))->sum())->display() ) else ( c := b - a ; execute (((B)->sum() * 2) - (bL.subrange(1,c))->sum())->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def print_sequence(n,k): b=int(n/(k*(k+1)/2)); if b==0 : print("-1") else : r=1 ; x=1 while x**2<=n : if n % x!=0 : continue ; elif x<=b and x>r : r=x elif n/x<=b and n/x>r : r=n/x x=x+1 i=1 while itoInteger(); ; if b = 0 then ( execute ("-1")->display() ) else ( var r : int := 1; ; var x : int := 1 ; while ((x)->pow(2)->compareTo(n)) <= 0 do ( if n mod x /= 0 then ( continue; ) else (if (x->compareTo(b)) <= 0 & (x->compareTo(r)) > 0 then ( r := x ) else (if (n / x->compareTo(b)) <= 0 & (n / x->compareTo(r)) > 0 then ( r := n / x ) else skip ) ) ; x := x + 1) ; var i : int := 1 ; while (i->compareTo(k)) < 0 do ( execute (r * i)->display() ; i := i + 1) ; var last_term : double := n - (r * (k * (k - 1) / 2)) ; execute (last_term)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minOperations(x,y,p,q): if(y % x!=0): return-1 d=y//x a=0 while(d % p==0): d//=p a+=1 b=0 while(d % q==0): d//=q b+=1 if(d!=1): return-1 return(a+b) x=12 y=2592 p=2 q=3 print(minOperations(x,y,p,q)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := 12 ; y := 2592 ; p := 2 ; q := 3 ; execute (minOperations(x, y, p, q))->display(); operation minOperations(x : OclAny, y : OclAny, p : OclAny, q : OclAny) : OclAny pre: true post: true activity: if (y mod x /= 0) then ( return -1 ) else skip ; var d : int := y div x ; var a : int := 0 ; while (d mod p = 0) do ( d := d div p ; a := a + 1) ; var b : int := 0 ; while (d mod q = 0) do ( d := d div q ; b := b + 1) ; if (d /= 1) then ( return -1 ) else skip ; return (a + b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) S=[int(input())for _ in range(N)] S.sort() ans=sum(S) for s in S : if ans % 10==0 : if s % 10!=0 : ans-=s break elif s==S[-1]: ans=0 else : break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; S := S->sort() ; var ans : OclAny := (S)->sum() ; for s : S do ( if ans mod 10 = 0 then ( if s mod 10 /= 0 then ( ans := ans - s ; break ) else (if s = S->last() then ( ans := 0 ) else skip) ) else ( break )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(): mod=1000000007 inf=float('inf') sys.setrecursionlimit(10**6) def input(): return sys.stdin.readline().rstrip() def ii(): return int(input()) def mi(): return map(int,input().split()) def mi_0(): return map(lambda x : int(x)-1,input().split()) def lmi(): return list(map(int,input().split())) def lmi_0(): return list(map(lambda x : int(x)-1,input().split())) def li(): return list(input()) n=ii() scores=[ii()for _ in range(n)] scores.sort() if sum(scores)% 10!=0 : print(sum(scores)) else : dec=sum(scores) for elm in scores : if elm % 10!=0 : dec=elm break print(sum(scores)-dec) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var mod : int := 1000000007 ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; sys.setrecursionlimit((10)->pow(6)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := ii() ; var scores : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (ii())) ; scores := scores->sort() ; if (scores)->sum() mod 10 /= 0 then ( execute ((scores)->sum())->display() ) else ( var dec : OclAny := (scores)->sum() ; for elm : scores do ( if elm mod 10 /= 0 then ( dec := elm ; break ) else skip) ; execute ((scores)->sum() - dec)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def aux(v): [xa,ya,ra,xb,yb,rb]=v ab=math.sqrt((xb-xa)**2+(yb-ya)**2) if ab>ra+rb : rst=0 elif ab+rbtoInteger() ; for i : Integer.subrange(0, n-1) do ( v := ((input().split())->collect( _x | (OclType["double"])->apply(_x) )) ; execute (aux(v))->display()) ) else skip; operation aux(v : OclAny) pre: true post: true activity: ; Sequence{xa}->union(Sequence{ya}->union(Sequence{ra}->union(Sequence{xb}->union(Sequence{yb}->union(Sequence{ rb }))))) := v ; var ab : double := (((xb - xa))->pow(2) + ((yb - ya))->pow(2))->sqrt() ; if (ab->compareTo(ra + rb)) > 0 then ( var rst : int := 0 ) else (if (ab + rb->compareTo(ra)) < 0 then ( rst := 2 ) else (if (ab + ra->compareTo(rb)) < 0 then ( rst := -2 ) else ( rst := 1 ) ) ) ; return (rst); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) s=[] nin=10**7 for i in range(N): temp=int(input()) if temp % 10!=0 : nin=min(nin,temp) s.append(temp) ans=sum(s) if ans % 10==0 : ans-=nin print(max(ans,0)) else : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := Sequence{} ; var nin : double := (10)->pow(7) ; for i : Integer.subrange(0, N-1) do ( var temp : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if temp mod 10 /= 0 then ( nin := Set{nin, temp}->min() ) else skip ; execute ((temp) : s)) ; var ans : OclAny := (s)->sum() ; if ans mod 10 = 0 then ( ans := ans - nin ; execute (Set{ans, 0}->max())->display() ) else ( execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for cas in range(int(input())): print({'o' : "FILIPINO",'a' : "KOREAN",'u' : "JAPANESE"}[input()[-1]]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for cas : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (Map{ 'o' |-> "FILIPINO" }->union(Map{ 'a' |-> "KOREAN" }->union(Map{ 'u' |-> "JAPANESE" }))[input()->last()+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) s=[int(input())for _ in range(N)] DP=[-1]*(100*100+1) DP[0]=1 for i in range(N): for j in reversed(range(10001)): if DP[j]!=-1 : DP[j+s[i]]=1 for j in reversed(range(10001)): if(DP[j]!=-1 and j % 10!=0)or j==0 : print(j) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var DP : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (100 * 100 + 1)) ; DP->first() := 1 ; for i : Integer.subrange(0, N-1) do ( for j : (Integer.subrange(0, 10001-1))->reverse() do ( if DP[j+1] /= -1 then ( DP[j + s[i+1]+1] := 1 ) else skip)) ; for j : (Integer.subrange(0, 10001-1))->reverse() do ( if (DP[j+1] /= -1 & j mod 10 /= 0) or j = 0 then ( execute (j)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy import random import bisect import fractions import math mod=10**9+7 N=int(input()) s=[] for i in range(N): s.append(int(input())) ans=sum(s) s.sort() if ans % 10==0 : for i in range(N): if s[i]% 10!=0 : ans-=s[i] break if ans % 10==0 : ans=0 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : s)) ; var ans : OclAny := (s)->sum() ; s := s->sort() ; if ans mod 10 = 0 then ( for i : Integer.subrange(0, N-1) do ( if s[i+1] mod 10 /= 0 then ( ans := ans - s[i+1] ; break ) else skip) ) else skip ; if ans mod 10 = 0 then ( ans := 0 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from itertools import accumulate f=sys.stdin while True : n=int(f.readline()) if n==0 : break p=list(map(int,f.readline().split())) j=list(map(int,f.readline().split())) j.sort(reverse=True) j.insert(0,0) total_length=sum(p) num_of_pipe=len(p) print(max((num_of_pipe-i)*(total_length+ji)for i,ji in enumerate(accumulate(j)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var f : OclFile := OclFile["System.in"] ; while true do ( var n : int := ("" + ((f.readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var p : Sequence := ((f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var j : Sequence := ((f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; j := j->sort() ; j := j.insertAt(0+1, 0) ; var total_length : OclAny := (p)->sum() ; var num_of_pipe : int := (p)->size() ; execute (((argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name num_of_pipe))) - (expr (atom (name i)))))))) ))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name total_length))) + (expr (atom (name ji)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name ji)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name accumulate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) ))))))))) )))))))))->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(n): pipes=[int(p)for p in input().split()] joints=sorted([int(j)for j in input().split()]) total_length=sum(pipes) record=total_length*n while joints : total_length+=joints.pop() n-=1 if total_length*n>record : record=total_length*n else : break return record def main(args): while True : n=int(input()) if n==0 : break ans=solve(n) print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(n : OclAny) : OclAny pre: true post: true activity: var pipes : Sequence := input().split()->select(p | true)->collect(p | (("" + ((p)))->toInteger())) ; var joints : Sequence := input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger()))->sort() ; var total_length : OclAny := (pipes)->sum() ; var record : double := total_length * n ; while joints do ( total_length := total_length + joints->last() ; joints := joints->front() ; n := n - 1 ; if (total_length * n->compareTo(record)) > 0 then ( record := total_length * n ) else ( break )) ; return record; operation main(args : OclAny) pre: true post: true activity: while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var ans : OclAny := solve(n) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break totalp=0 P=list(map(int,input().split())) for p in P : totalp+=p J=list(map(int,input().split())) maxv=0 J.sort(reverse=True) J.append(0); totalj=0 t=n j=0 while t>=1 : v=t*(totalj+totalp) totalj+=J[j] maxv=max(v,maxv) t=t-1 j=j+1 print(maxv) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var totalp : int := 0 ; var P : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for p : P do ( totalp := totalp + p) ; var J : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var maxv : int := 0 ; J := J->sort() ; execute ((0) : J); ; var totalj : int := 0 ; var t : int := n ; var j : int := 0 ; while t >= 1 do ( var v : int := t * (totalj + totalp) ; totalj := totalj + J[j+1] ; maxv := Set{v, maxv}->max() ; t := t - 1 ; j := j + 1) ; execute (maxv)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if n==0 : break l=sum(map(int,input().split())) j=sorted(map(int,input().split()),reverse=True) d=[0]*n for i in range(n): d[i]=(l+sum(j[: i]))*(n-i) if d[i]toInteger() ; if n = 0 then ( break ) else skip ; var l : OclAny := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum() ; var j : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name l))) + (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))))))) ))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (name i)))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) < (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break p=[int(i)for i in input().split()] j=[int(i)for i in input().split()] s=0 for i in range(len(p)): s+=p[i] for i in range(len(j)): s+=j[i] ans=s j.sort() for i in range(len(j)): s-=j[i] ans=max(ans,s*(i+2)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var p : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var j : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var s : int := 0 ; for i : Integer.subrange(0, (p)->size()-1) do ( s := s + p[i+1]) ; for i : Integer.subrange(0, (j)->size()-1) do ( s := s + j[i+1]) ; var ans : int := s ; j := j->sort() ; for i : Integer.subrange(0, (j)->size()-1) do ( s := s - j[i+1] ; ans := Set{ans, s * (i + 2)}->max()) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sum(a,b,c,d,x): ans=((x*(a+b)*(c-d))/((a*d)-(b*c))); return ans ; if __name__=='__main__' : a,b,c,d,x=1,2,9,13,5 ; print(sum(a,b,c,d,x)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( Sequence{a,b,c,d,x} := Sequence{1,2,9,13,5}; ; execute ((a, b, c, d, x)->sum())->display(); ) else skip; operation sum(a : OclAny, b : OclAny, c : OclAny, d : OclAny, x : OclAny) pre: true post: true activity: var ans : double := ((x * (a + b) * (c - d)) / ((a * d) - (b * c))); ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) arr=[int(x)for x in input().split()] pos=neg=zero=0 for i in range(n): if arr[i]>0 : pos+=1 elif arr[i]<0 : neg+=1 else : zero+=1 req=math.ceil(n/2) if pos>=req : print(1) elif neg>=req : print(-1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; pos := pos(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name neg)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name zero)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] > 0 then ( pos := pos + 1 ) else (if arr[i+1] < 0 then ( neg := neg + 1 ) else ( zero := zero + 1 ) ) ) ; var req : double := (n / 2)->ceil() ; if (pos->compareTo(req)) >= 0 then ( execute (1)->display() ) else (if (neg->compareTo(req)) >= 0 then ( execute (-1)->display() ) else ( execute (0)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x1,y1,r1,x2,y2,r2=[float(x)for x in input().split()] distance=((x1-x2)**2+(y1-y2)**2)**0.5 if distance>r1+r2 : print(0) else : if r1>r2 and distance+r2toInteger()-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; var r1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; var r2 : OclAny := null; Sequence{x1,y1,r1,x2,y2,r2} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())) ; var distance : double := ((((x1 - x2))->pow(2) + ((y1 - y2))->pow(2)))->pow(0.5) ; if (distance->compareTo(r1 + r2)) > 0 then ( execute (0)->display() ) else ( if (r1->compareTo(r2)) > 0 & (distance + r2->compareTo(r1)) < 0 then ( execute (2)->display() ) else (if (r1->compareTo(r2)) < 0 & (distance + r1->compareTo(r2)) < 0 then ( execute (-2)->display() ) else ( execute (1)->display() ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input(''))): s=input('') if(s[-2 :]=='po'): print('FILIPINO') elif s[-4 :]=='desu' or s[-4 :]=='masu' : print('JAPANESE') else : print('KOREAN') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine(''))))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine('') ; if (s.subrange(-2+1) = 'po') then ( execute ('FILIPINO')->display() ) else (if s.subrange(-4+1) = 'desu' or s.subrange(-4+1) = 'masu' then ( execute ('JAPANESE')->display() ) else ( execute ('KOREAN')->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) count=0 countn=0 a=list(map(int,input().strip().split())) for i in range(n): if(a[i]>0): count=count+1 if(a[i]<0): countn=countn+1 if(count>=math.ceil(n/2)): print("1") elif(countn>=math.ceil(n/2)): print("-1") else : print('0') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := 0 ; var countn : int := 0 ; var a : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] > 0) then ( count := count + 1 ) else skip ; if (a[i+1] < 0) then ( countn := countn + 1 ) else skip) ; if ((count->compareTo((n / 2)->ceil())) >= 0) then ( execute ("1")->display() ) else (if ((countn->compareTo((n / 2)->ceil())) >= 0) then ( execute ("-1")->display() ) else ( execute ('0')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=l=(int(input())-1)//2 for x in map(int,input().split()): k-=x>0 ; l-=x<0 print((0,1,-1,1)[(k<0)+2*(l<0)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : OclAny := (("" + (((OclFile["System.in"]).readLine())))->toInteger() - 1) div 2; var l : int := (("" + (((OclFile["System.in"]).readLine())))->toInteger() - 1) div 2 ; for x : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( k := k - x > 0; l := l - x < 0) ; execute (Sequence{0, 1, -1, 1}->select((k < 0) + 2 * (l < 0)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=(int(input())-1)//2 b=c=0 for i in map(int,input().split()): if i>0 : b+=1 if i<0 : c+=1 print((b>n or c>n)and[-1,1][b>n]or 0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := (("" + (((OclFile["System.in"]).readLine())))->toInteger() - 1) div 2 ; var b : OclAny := 0; var c : int := 0 ; for i : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( if i > 0 then ( b := b + 1 ) else skip ; if i < 0 then ( c := c + 1 ) else skip) ; execute (((b->compareTo(n)) > 0 or (c->compareTo(n)) > 0) & Sequence{-1}->union(Sequence{ 1 })->select((b->compareTo(n)) > 0) or 0)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) a=list(map(int,input().split())) c1,c2=0,0 for i in a : if i>0 : c1+=1 elif i<0 : c2+=1 if c1>=(n+1)//2 : ans=1 elif c2>=(n+1)//2 : ans=-1 else : ans=0 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c1 : OclAny := null; var c2 : OclAny := null; Sequence{c1,c2} := Sequence{0,0} ; for i : a do ( if i > 0 then ( c1 := c1 + 1 ) else (if i < 0 then ( c2 := c2 + 1 ) else skip)) ; if (c1->compareTo((n + 1) div 2)) >= 0 then ( var ans : int := 1 ) else (if (c2->compareTo((n + 1) div 2)) >= 0 then ( ans := -1 ) else ( ans := 0 ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=10001 def sieveOfEratosthenes(s): prime=[False for i in range(MAX+1)] for i in range(2,MAX+1,2): s[i]=2 ; for i in range(3,MAX,2): if(prime[i]==False): s[i]=i for j in range(i,MAX+1,2): if j*j>MAX : break if(prime[i*j]==False): prime[i*j]=True s[i*j]=i def kPrimeFactor(n,k,s): while(n>1): if(k==1): return s[n] k-=1 n//=s[n] return-1 s=[-1 for i in range(MAX+1)] sieveOfEratosthenes(s) n=12 k=3 print(kPrimeFactor(n,k,s)) n=14 k=3 print(kPrimeFactor(n,k,s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 10001 ; skip ; skip ; s := Integer.subrange(0, MAX + 1-1)->select(i | true)->collect(i | (-1)) ; sieveOfEratosthenes(s) ; n := 12 ; k := 3 ; execute (kPrimeFactor(n, k, s))->display() ; n := 14 ; k := 3 ; execute (kPrimeFactor(n, k, s))->display(); operation sieveOfEratosthenes(s : OclAny) pre: true post: true activity: var prime : Sequence := Integer.subrange(0, MAX + 1-1)->select(i | true)->collect(i | (false)) ; for i : Integer.subrange(2, MAX + 1-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( s[i+1] := 2;) ; for i : Integer.subrange(3, MAX-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if (prime[i+1] = false) then ( s[i+1] := i ; for j : Integer.subrange(i, MAX + 1-1)->select( $x | ($x - i) mod 2 = 0 ) do ( if (j * j->compareTo(MAX)) > 0 then ( break ) else skip ; if (prime[i * j+1] = false) then ( prime[i * j+1] := true ; s[i * j+1] := i ) else skip) ) else skip); operation kPrimeFactor(n : OclAny, k : OclAny, s : OclAny) : OclAny pre: true post: true activity: while (n > 1) do ( if (k = 1) then ( return s[n+1] ) else skip ; k := k - 1 ; n := n div s[n+1]) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def isPerfectSquare(x): sq=(int)(math.sqrt(x)) return(x==sq*sq) def countPerfectDivisors(n): cnt=0 for i in range(1,(int)(math.sqrt(n))+1): if(n % i==0): if isPerfectSquare(i): cnt=cnt+1 if n/i!=i and isPerfectSquare(n/i): cnt=cnt+1 return cnt print("Total perfect divisor of 16=",countPerfectDivisors(16)) print("Total perfect divisor of 12=",countPerfectDivisors(12)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; execute ("Total perfect divisor of 16=")->display() ; execute ("Total perfect divisor of 12=")->display(); operation isPerfectSquare(x : OclAny) : OclAny pre: true post: true activity: var sq : OclAny := (OclType["int"])((x)->sqrt()) ; return (x = sq * sq); operation countPerfectDivisors(n : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; for i : Integer.subrange(1, (OclType["int"])((n)->sqrt()) + 1-1) do ( if (n mod i = 0) then ( if isPerfectSquare(i) then ( cnt := cnt + 1 ) else skip ; if n / i /= i & isPerfectSquare(n / i) then ( cnt := cnt + 1 ) else skip ) else skip) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minMovesToSort(arr,n): moves=0 mn=arr[n-1] for i in range(n-1,-1,-1): if(arr[i]>mn): moves+=arr[i]-mn mn=arr[i] return moves if __name__=="__main__" : arr=[3,5,2,8,4] n=len(arr) print(minMovesToSort(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{3}->union(Sequence{5}->union(Sequence{2}->union(Sequence{8}->union(Sequence{ 4 })))) ; n := (arr)->size() ; execute (minMovesToSort(arr, n))->display() ) else skip; operation minMovesToSort(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var moves : int := 0 ; var mn : OclAny := arr[n - 1+1] ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if ((arr[i+1]->compareTo(mn)) > 0) then ( moves := moves + arr[i+1] - mn ) else skip ; mn := arr[i+1]) ; return moves; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reachTarget(target): target=abs(target) sum=0 step=0 while(sumdisplay(); operation reachTarget(target : OclAny) : OclAny pre: true post: true activity: target := (target)->abs() ; var sum : int := 0 ; var step : int := 0 ; while ((sum->compareTo(target)) < 0 or (sum - target) mod 2 /= 0) do ( step := step + 1 ; sum := sum + step) ; return step; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solveEven(n,arr,b): left=n-1 for i in range((n//2)): b[i]=arr[left] left=left-2 if(left<0): break right=0 for i in range(n//2,n,1): b[i]=arr[right] right=right+2 if(right>n-2): break def solveOdd(n,arr,b): left=n-1 for i in range(n//2+1): b[i]=arr[left] left=left-2 if(left<0): break right=1 for i in range(n//2+1,n,1): b[i]=arr[right] right=right+2 if(right>n-2): break def solve(n,arr): b=[0 for i in range(n)] if(n % 2==0): solveEven(n,arr,b) else : solveOdd(n,arr,b) for i in range(n): print(b[i],end=" ") if __name__=='__main__' : arr=[1,2,3,4] n=len(arr) solve(n,arr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))) ; n := (arr)->size() ; solve(n, arr) ) else skip; operation solveEven(n : OclAny, arr : OclAny, b : OclAny) pre: true post: true activity: var left : double := n - 1 ; for i : Integer.subrange(0, (n div 2)-1) do ( b[i+1] := arr[left+1] ; left := left - 2 ; if (left < 0) then ( break ) else skip) ; var right : int := 0 ; for i : Integer.subrange(n div 2, n-1)->select( $x | ($x - n div 2) mod 1 = 0 ) do ( b[i+1] := arr[right+1] ; right := right + 2 ; if ((right->compareTo(n - 2)) > 0) then ( break ) else skip); operation solveOdd(n : OclAny, arr : OclAny, b : OclAny) pre: true post: true activity: left := n - 1 ; for i : Integer.subrange(0, n div 2 + 1-1) do ( b[i+1] := arr[left+1] ; left := left - 2 ; if (left < 0) then ( break ) else skip) ; right := 1 ; for i : Integer.subrange(n div 2 + 1, n-1)->select( $x | ($x - n div 2 + 1) mod 1 = 0 ) do ( b[i+1] := arr[right+1] ; right := right + 2 ; if ((right->compareTo(n - 2)) > 0) then ( break ) else skip); operation solve(n : OclAny, arr : OclAny) pre: true post: true activity: b := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; if (n mod 2 = 0) then ( solveEven(n, arr, b) ) else ( solveOdd(n, arr, b) ) ; for i : Integer.subrange(0, n-1) do ( execute (b[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) s=list(map(int,input().split(" "))) for k in range(1,1024): s1=set([s[i]^ k for i in range(n)]) s2=set(s) if s1==s2 : print(k) return print(-1) for _ in range(int(input())): solve(); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve();); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; for k : Integer.subrange(1, 1024-1) do ( var s1 : Set := Set{}->union((Integer.subrange(0, n-1)->select(i | true)->collect(i | (MathLib.bitwiseXor(s[i+1], k))))) ; var s2 : Set := Set{}->union((s)) ; if s1 = s2 then ( execute (k)->display() ; return ) else skip) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) if a<1 and b : print('Impossible'); exit() print(max(a,b),a+max(b-1,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a < 1 & b then ( execute ('Impossible')->display(); exit() ) else skip ; execute (Set{a, b}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for cas in range(int(input())): print({'o' : "FILIPINO",'a' : "KOREAN",'u' : "JAPANESE"}[input()[-1]]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for cas : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (Map{ 'o' |-> "FILIPINO" }->union(Map{ 'a' |-> "KOREAN" }->union(Map{ 'u' |-> "JAPANESE" }))[input()->last()+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(circleA,circleB): xa,ya,ra=circleA xb,yb,rb=circleB if ra<=rb : if distancePow2(xa,ya,xb,yb)toInteger() ; for i : Integer.subrange(0, n-1) do ( var inStr : String := (OclFile["System.in"]).readLine() ; var circleAInfo : Sequence := inStr.split(" ").subrange(0+1, 3)->select(data | true)->collect(data | (("" + ((data)))->toReal())) ; var circleBInfo : Sequence := inStr.split(" ").subrange(3+1, 6)->select(data | true)->collect(data | (("" + ((data)))->toReal())) ; execute (solve(circleAInfo, circleBInfo))->display()); operation solve(circleA : OclAny, circleB : OclAny) : OclAny pre: true post: true activity: var xa : OclAny := null; var ya : OclAny := null; var ra : OclAny := null; Sequence{xa,ya,ra} := circleA ; var xb : OclAny := null; var yb : OclAny := null; var rb : OclAny := null; Sequence{xb,yb,rb} := circleB ; if (ra->compareTo(rb)) <= 0 then ( if (distancePow2(xa, ya, xb, yb)->compareTo((rb - ra)->pow(2))) < 0 then ( return -2 ) else skip ) else ( if (distancePow2(xa, ya, xb, yb)->compareTo((rb - ra)->pow(2))) < 0 then ( return 2 ) else skip ) ; if ((rb - ra)->pow(2)->compareTo(distancePow2(xa, ya, xb, yb))) <= 0 & (distancePow2(xa, ya, xb, yb) <= (rb + ra)->pow(2)) then ( return 1 ) else skip ; return 0; operation distancePow2(xa : OclAny, ya : OclAny, xb : OclAny, yb : OclAny) : OclAny pre: true post: true activity: return (xb - xa)->pow(2) + (yb - ya)->pow(2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=set(map(int,input().split())) ans=-1 for i in range(1,1025): flag=True for j in a : if i ^ j not in a : flag=False break if flag : ans=i break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ans : int := -1 ; for i : Integer.subrange(1, 1025-1) do ( var flag : boolean := true ; for j : a do ( if (a)->excludes(MathLib.bitwiseXor(i, j)) then ( flag := false ; break ) else skip) ; if flag then ( ans := i ; break ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) S=set(map(int,input().split())) S2=set() r=-1 for num in range(1,1025): flag=True for i in S : if i ^ num not in S : flag=False break if flag : r=num break print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var S2 : Set := Set{}->union(()) ; var r : int := -1 ; for num : Integer.subrange(1, 1025-1) do ( var flag : boolean := true ; for i : S do ( if (S)->excludes(MathLib.bitwiseXor(i, num)) then ( flag := false ; break ) else skip) ; if flag then ( r := num ; break ) else skip) ; execute (r)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys t=int(input()) while t>0 : n=int(input()) nums=list(map(int,input().split())) k=1 flag=True j=0 while jtoInteger() ; while t > 0 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nums : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k : int := 1 ; var flag : boolean := true ; var j : int := 0 ; while (j->compareTo(n)) < 0 do ( while ((nums.subrange(1,j) + nums.subrange(j + 1+1)))->excludes(MathLib.bitwiseXor(nums[j+1], k)) do ( k := k + 1 ; j := 0 ; if k = 1025 then ( flag := false ; break ) else skip) ; j := j + 1 ; if not(flag) then ( break ) else skip) ; execute (if flag then k else -1 endif)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys t=int(input()) while t>0 : n=int(input()) nums=list(map(int,input().split())) k=1 flag=True j=0 while jtoInteger() ; while t > 0 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nums : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k : int := 1 ; var flag : boolean := true ; var j : int := 0 ; while (j->compareTo(n)) < 0 do ( while ((nums.subrange(1,j) + nums.subrange(j + 1+1)))->excludes(MathLib.bitwiseXor(nums[j+1], k)) do ( k := k + 1 ; j := 0 ; if k = 1025 then ( flag := false ; break ) else skip) ; j := j + 1 ; if not(flag) then ( break ) else skip) ; execute (if flag then k else -1 endif)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMaxGCD(arr,n): high=0 for i in range(0,n): high=max(high,arr[i]) count=[0]*(high+1) for i in range(0,n): count[arr[i]]+=1 counter=0 for i in range(high,0,-1): j=i while(j<=high): if(count[j]>0): counter+=count[j] j+=i if(counter==2): return i counter=0 arr=[1,2,4,8,8,12] n=len(arr) print(findMaxGCD(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{8}->union(Sequence{8}->union(Sequence{ 12 }))))) ; n := (arr)->size() ; execute (findMaxGCD(arr, n))->display(); operation findMaxGCD(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var high : int := 0 ; for i : Integer.subrange(0, n-1) do ( high := Set{high, arr[i+1]}->max()) ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (high + 1)) ; for i : Integer.subrange(0, n-1) do ( count[arr[i+1]+1] := count[arr[i+1]+1] + 1) ; var counter : int := 0 ; for i : Integer.subrange(0 + 1, high)->reverse() do ( var j : OclAny := i ; while ((j->compareTo(high)) <= 0) do ( if (count[j+1] > 0) then ( counter := counter + count[j+1] ) else skip ; j := j + i ; if (counter = 2) then ( return i ) else skip) ; counter := 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=998244353 n=int(input()) a=list(map(lambda x : ord(x)% 3,list(input()))) g=[list()for _ in range(3)] for i in range(3*n): g[a[i]].append(i) l=[0]*3*n for i in range(n): a,b,c=sorted([g[0][i],g[1][i],g[2][i]]) l[b]=1 l[c]=2 ans=1 for i in range(n): ans=ans*(i+1)% mod c=0 for x in l : if x==0 : c+=1 elif x==1 : ans=ans*c % mod c-=1 for x in reversed(l): if x==2 : c+=1 elif x==1 : ans=ans*c % mod c-=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : int := 998244353 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((((OclFile["System.in"]).readLine())->characters())->collect( _x | (lambda x : OclAny in ((x)->char2byte() mod 3))->apply(_x) )) ; var g : Sequence := Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (())) ; for i : Integer.subrange(0, 3 * n-1) do ((expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var l : Sequence := MatrixLib.elementwiseMult(MatrixLib.elementwiseMult(Sequence{ 0 }, 3), n) ; for i : Integer.subrange(0, n-1) do ( var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{g->first()[i+1]}->union(Sequence{g[1+1][i+1]}->union(Sequence{ g[2+1][i+1] }))->sort() ; l[b+1] := 1 ; l[c+1] := 2) ; var ans : int := 1 ; for i : Integer.subrange(0, n-1) do ( ans := ans * (i + 1) mod mod) ; var c : int := 0 ; for x : l do ( if x = 0 then ( c := c + 1 ) else (if x = 1 then ( ans := ans * c mod mod ; c := c - 1 ) else skip)) ; for x : (l)->reverse() do ( if x = 2 then ( c := c + 1 ) else (if x = 1 then ( ans := ans * c mod mod ; c := c - 1 ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from bisect import bisect_left INF=float("inf") MOD=998244353 def solve(N : int,S : str): count=1 nums={"B" : 0,"R" : 0,"G" : 0} other={"B" : "RG","R" : "BG","G" : "BR"} for c in S : buf=sorted(nums.values()) if nums[c]==buf[2]: count*=N-nums[c] count %=MOD elif buf[1]==nums[c]: count*=buf[2]-buf[1] count %=MOD else : count*=buf[1]-buf[0] count %=MOD pre="C" nums[c]+=1 print(count) return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() N=int(next(tokens)) S=next(tokens) solve(N,S) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var INF : double := ("" + (("inf")))->toReal() ; var MOD : int := 998244353 ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(N : int, S : String) pre: true post: true activity: var count : int := 1 ; var nums : Map := Map{ "B" |-> 0 }->union(Map{ "R" |-> 0 }->union(Map{ "G" |-> 0 })) ; var other : Map := Map{ "B" |-> "RG" }->union(Map{ "R" |-> "BG" }->union(Map{ "G" |-> "BR" })) ; for c : S->characters() do ( var buf : Sequence := nums.values()->sort() ; if nums[c+1] = buf[2+1] then ( count := count * N - nums[c+1] ; count := count mod MOD ) else (if buf[1+1] = nums[c+1] then ( count := count * buf[2+1] - buf[1+1] ; count := count mod MOD ) else ( count := count * buf[1+1] - buf->first() ; count := count mod MOD ; var pre : String := "C" ) ) ; nums[c+1] := nums[c+1] + 1) ; execute (count)->display() ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var N : int := ("" + (((tokens).next())))->toInteger() ; var S : OclAny := (tokens).next() ; solve(N, S); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) S=input().strip() mod=998244353 def mul(a,b): return(a*b)% mod ff=1 for i in range(n): ff=mul(ff,i+1) def mkrgb(): return{"R" : 0,"G" : 0,"B" : 0} def ogb(c): if c=="R" : return "GB" if c=="G" : return "BR" if c=="B" : return "RG" cc={"R" : 0,"G" : 0,"B" : 0} cc2={"R" : 0,"G" : 0,"B" : 0} t=0 l="" result=1 for c in S : if cc2[c]!=0 : result=mul(result,cc2[c]) cc2[c]-=1 elif cc[c]==0 : x,y=ogb(c) if cc[x]!=0 : cc2[y]+=1 result=mul(result,cc[x]) cc[x]-=1 elif cc[y]!=0 : cc2[x]+=1 result=mul(result,cc[y]) cc[y]-=1 else : cc[c]+=1 else : cc[c]+=1 print(mul(result,ff)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : OclAny := input()->trim() ; var mod : int := 998244353 ; skip ; var ff : int := 1 ; for i : Integer.subrange(0, n-1) do ( ff := mul(ff, i + 1)) ; skip ; skip ; var cc : Map := Map{ "R" |-> 0 }->union(Map{ "G" |-> 0 }->union(Map{ "B" |-> 0 })) ; var cc2 : Map := Map{ "R" |-> 0 }->union(Map{ "G" |-> 0 }->union(Map{ "B" |-> 0 })) ; var t : int := 0 ; var l : String := "" ; var result : int := 1 ; for c : S do ( if cc2[c+1] /= 0 then ( result := mul(result, cc2[c+1]) ; cc2[c+1] := cc2[c+1] - 1 ) else (if cc[c+1] = 0 then ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ogb(c) ; if cc[x+1] /= 0 then ( cc2[y+1] := cc2[y+1] + 1 ; result := mul(result, cc[x+1]) ; cc[x+1] := cc[x+1] - 1 ) else (if cc[y+1] /= 0 then ( cc2[x+1] := cc2[x+1] + 1 ; result := mul(result, cc[y+1]) ; cc[y+1] := cc[y+1] - 1 ) else ( cc[c+1] := cc[c+1] + 1 ) ) ) else ( cc[c+1] := cc[c+1] + 1 ) ) ) ; execute (mul(result, ff))->display(); operation mul(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a * b) mod mod; operation mkrgb() : OclAny pre: true post: true activity: return Map{ "R" |-> 0 }->union(Map{ "G" |-> 0 }->union(Map{ "B" |-> 0 })); operation ogb(c : OclAny) : OclAny pre: true post: true activity: if c = "R" then ( return "GB" ) else skip ; if c = "G" then ( return "BR" ) else skip ; if c = "B" then ( return "RG" ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import sys import numpy as np if os.getenv("LOCAL"): sys.stdin=open("_in.txt","r") sys.setrecursionlimit(2147483647) INF=float("inf") IINF=10**18 MOD=998244353 N=int(sys.stdin.readline()) S=sys.stdin.readline().rstrip() LMR=np.zeros(N*3,dtype=str) counts=np.zeros(N,dtype=int) rgb={'R' : 0,'G' : 0,'B' : 0} for i,c in enumerate(S): LMR[i]='LMR'[counts[rgb[c]]] counts[rgb[c]]+=1 rgb[c]+=1 LC=(LMR=='L').cumsum() RC=(LMR=='R')[: :-1].cumsum()[: :-1] ans=1 for i,mi in enumerate(np.where(LMR=='M')[0]): ans*=(LC[mi]-i)*(RC[mi]-(N-i-1)) ans %=MOD for i in range(1,N+1): ans*=i ans %=MOD print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if os.getenv("LOCAL") then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("_in.txt")) ) else skip ; sys.setrecursionlimit(2147483647) ; var INF : double := ("" + (("inf")))->toReal() ; var IINF : double := (10)->pow(18) ; var MOD : int := 998244353 ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : OclAny := sys.stdin.readLine().rstrip() ; var LMR : Sequence := MatrixLib.singleValueMatrix(N * 3, 0.0) ; var counts : Sequence := MatrixLib.singleValueMatrix(N, 0.0) ; var rgb : Map := Map{ 'R' |-> 0 }->union(Map{ 'G' |-> 0 }->union(Map{ 'B' |-> 0 })) ; for _tuple : Integer.subrange(1, (S)->size())->collect( _indx | Sequence{_indx-1, (S)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); LMR[i+1] := 'LMR'[counts[rgb[c+1]+1]+1] ; counts[rgb[c+1]+1] := counts[rgb[c+1]+1] + 1 ; rgb[c+1] := rgb[c+1] + 1) ; var LC : OclAny := (LMR = 'L').cumsum() ; var RC : OclAny := (LMR = 'R')(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))).cumsum()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var ans : int := 1 ; for _tuple : Integer.subrange(1, (np.where(LMR = 'M')->first())->size())->collect( _indx | Sequence{_indx-1, (np.where(LMR = 'M')->first())->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var mi : OclAny := _tuple->at(_indx); ans := ans * (LC[mi+1] - i) * (RC[mi+1] - (N - i - 1)) ; ans := ans mod MOD) ; for i : Integer.subrange(1, N + 1-1) do ( ans := ans * i ; ans := ans mod MOD) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSum(arr,n,left,right): k=right-left ; d=arr[1]-arr[0]; ans=arr[left-1]*(k+1); ans=ans+(d*(k*(k+1)))//2 ; return ans ; if __name__=='__main__' : arr=[2,4,6,8,10,12,14,16]; queries=3 ; q=[[2,4],[2,6],[5,6]]; n=len(arr); for i in range(queries): print(findSum(arr,n,q[i][0],q[i][1])); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{2}->union(Sequence{4}->union(Sequence{6}->union(Sequence{8}->union(Sequence{10}->union(Sequence{12}->union(Sequence{14}->union(Sequence{ 16 }))))))); ; var queries : int := 3; ; var q : Sequence := Sequence{Sequence{2}->union(Sequence{ 4 })}->union(Sequence{Sequence{2}->union(Sequence{ 6 })}->union(Sequence{ Sequence{5}->union(Sequence{ 6 }) })); ; n := (arr)->size(); ; for i : Integer.subrange(0, queries-1) do ( execute (findSum(arr, n, q[i+1]->first(), q[i+1][1+1]))->display();) ) else skip; operation findSum(arr : OclAny, n : OclAny, left : OclAny, right : OclAny) pre: true post: true activity: var k : double := right - left; ; var d : double := arr[1+1] - arr->first(); ; var ans : double := arr[left - 1+1] * (k + 1); ; ans := ans + (d * (k * (k + 1))) div 2; ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict mod=998244353 N=int(input()) S=input() colors=['R','G','B'] invs={'R' : 'GB','G' : 'BR','B' : 'RG'} cnt=defaultdict(int) ans=1 for i in range(N*3): s=S[i] inv=invs[s] if cnt[inv]!=0 : ans*=cnt[inv] ans %=mod cnt[inv]-=1 continue flag=False for c in colors : if c==s : continue if cnt[c]: ans*=cnt[c] ans %=mod cnt[c]-=1 cnt[c+s]+=1 cnt[s+c]+=1 flag=True if not flag : cnt[s]+=1 ans %=mod for i in range(1,N+1): ans*=i ans %=mod print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var mod : int := 998244353 ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : String := (OclFile["System.in"]).readLine() ; var colors : Sequence := Sequence{'R'}->union(Sequence{'G'}->union(Sequence{ 'B' })) ; var invs : Map := Map{ 'R' |-> 'GB' }->union(Map{ 'G' |-> 'BR' }->union(Map{ 'B' |-> 'RG' })) ; var cnt : OclAny := defaultdict(OclType["int"]) ; var ans : int := 1 ; for i : Integer.subrange(0, N * 3-1) do ( var s : OclAny := S[i+1] ; var inv : OclAny := invs[s+1] ; if cnt[inv+1] /= 0 then ( ans := ans * cnt[inv+1] ; ans := ans mod mod ; cnt[inv+1] := cnt[inv+1] - 1 ; continue ) else skip ; var flag : boolean := false ; for c : colors do ( if c = s then ( continue ) else skip ; if cnt[c+1] then ( ans := ans * cnt[c+1] ; ans := ans mod mod ; cnt[c+1] := cnt[c+1] - 1 ; cnt[c + s+1] := cnt[c + s+1] + 1 ; cnt[s + c+1] := cnt[s + c+1] + 1 ; flag := true ) else skip) ; if not(flag) then ( cnt[s+1] := cnt[s+1] + 1 ) else skip ; ans := ans mod mod) ; for i : Integer.subrange(1, N + 1-1) do ( ans := ans * i ; ans := ans mod mod) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(): ax,ay,ar,bx,by,br=map(float,input().split()) d=((ax-bx)*(ax-bx))+((ay-by)*(ay-by)) r1=(ar+br)*(ar+br) r2=(ar-br)*(ar-br) if d<=r1 and d>=r2 : return 1 ; elif d=br : return 2 elif dtoInteger()-1) do ( execute (f())->display()); operation f() pre: true post: true activity: var ax : OclAny := null; var ay : OclAny := null; var ar : OclAny := null; var bx : OclAny := null; var by : OclAny := null; var br : OclAny := null; Sequence{ax,ay,ar,bx,by,br} := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; var d : double := ((ax - bx) * (ax - bx)) + ((ay - by) * (ay - by)) ; var r1 : double := (ar + br) * (ar + br) ; var r2 : double := (ar - br) * (ar - br) ; if (d->compareTo(r1)) <= 0 & (d->compareTo(r2)) >= 0 then ( return 1; ) else (if (d->compareTo(r2)) < 0 & (ar->compareTo(br)) >= 0 then ( return 2 ) else (if (d->compareTo(r2)) < 0 & (ar->compareTo(br)) <= 0 then ( return -2 ) else ( return 0 ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() vowels={'A','E','I','O','U','Y'} max_jump=0 temp=1 for ch in s : if ch in vowels : max_jump=max(max_jump,temp) temp=0 temp+=1 max_jump=max(max_jump,temp) print(max_jump) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var vowels : Set := Set{'A'}->union(Set{'E'}->union(Set{'I'}->union(Set{'O'}->union(Set{'U'}->union(Set{ 'Y' }))))) ; var max_jump : int := 0 ; var temp : int := 1 ; for ch : s->characters() do ( if (vowels)->includes(ch) then ( max_jump := Set{max_jump, temp}->max() ; temp := 0 ) else skip ; temp := temp + 1) ; max_jump := Set{max_jump, temp}->max() ; execute (max_jump)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s='A'+input()+'A' f=b=0 v=['A','E','I','O','U','Y'] for i in range(1,len(s)): if s[i]in v : e=i k=e-b b=e if k>f : f=k print(f) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := 'A' + (OclFile["System.in"]).readLine() + 'A' ; var f : OclAny := 0; var b : int := 0 ; var v : Sequence := Sequence{'A'}->union(Sequence{'E'}->union(Sequence{'I'}->union(Sequence{'O'}->union(Sequence{'U'}->union(Sequence{ 'Y' }))))) ; for i : Integer.subrange(1, (s)->size()-1) do ( if (v)->includes(s[i+1]) then ( var e : OclAny := i ; var k : double := e - b ; b := e ; if (k->compareTo(f)) > 0 then ( f := k ) else skip ) else skip) ; execute (f)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(s): ln=len(s) ans=0 tmp=-1 i=0 while idisplay(); operation solve(s : OclAny) : OclAny pre: true post: true activity: var ln : int := (s)->size() ; var ans : int := 0 ; var tmp : int := -1 ; var i : int := 0 ; while (i->compareTo(ln)) < 0 do ( if s[i+1] = 'A' or s[i+1] = 'E' or s[i+1] = 'I' or s[i+1] = 'O' or s[i+1] = 'U' or s[i+1] = 'Y' then ( ans := Set{ans, i - tmp}->max() ; tmp := i ) else skip ; i := i + 1) ; ans := Set{ans, ln - tmp}->max() ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(s): ln=len(s) ans=0 tmp=-1 i=0 for i in range(ln): if s[i]=='A' or s[i]=='E' or s[i]=='I' or s[i]=='O' or s[i]=='U' or s[i]=='Y' : ans=max(ans,i-tmp) tmp=i ans=max(ans,ln-tmp) return ans s=input() print(solve(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := (OclFile["System.in"]).readLine() ; execute (solve(s))->display(); operation solve(s : OclAny) : OclAny pre: true post: true activity: var ln : int := (s)->size() ; var ans : int := 0 ; var tmp : int := -1 ; var i : int := 0 ; for i : Integer.subrange(0, ln-1) do ( if s[i+1] = 'A' or s[i+1] = 'E' or s[i+1] = 'I' or s[i+1] = 'O' or s[i+1] = 'U' or s[i+1] = 'Y' then ( ans := Set{ans, i - tmp}->max() ; tmp := i ) else skip) ; ans := Set{ans, ln - tmp}->max() ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() convert_to_list_and_append_2_vowels_to_s=['A']+list(s)+['A'] vowels=['A','E','I','O','U','Y'] jumps=[] j=0 k=0 while junion((s)->characters())->union(Sequence{ 'A' })_vowels_to_s : Sequence := Sequence{ 'A' }->union((s)->characters())->union(Sequence{ 'A' }) ; var vowels : Sequence := Sequence{'A'}->union(Sequence{'E'}->union(Sequence{'I'}->union(Sequence{'O'}->union(Sequence{'U'}->union(Sequence{ 'Y' }))))) ; var jumps : Sequence := Sequence{} ; var j : int := 0 ; var k : int := 0 ; while (j->compareTo((convert_to_list_and_append if (vowels)->includes(convert_to_list_and_appendvowels_vowels_to_s[j+1]) then ( execute ((j - k) : jumps) ; k := j ) else skip ; j := j + 1_vowels_to_s)->size())) < 0 do ( if (vowels)->includes(convert_to_list_and_appendvowels_vowels_to_s[j+1]) then ( execute ((j - k) : jumps) ; k := j ) else skip ; j := j + 1) ; execute ((jumps)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") def is_straight(hand): if hand==[1,10,11,12,13]: return True m=min(hand) if hand==list(range(m,m+5)): return True return False def poker_hand(hand): hand=sorted(hand) counts={} for card in hand : counts[card]=counts.get(card,0)+1 counts=sorted(list(counts.values())) if counts==[1,4]: return "four card" elif counts==[2,3]: return "full house" elif is_straight(hand): return "straight" elif counts==[1,1,3]: return "three card" elif counts==[1,2,2]: return "two pair" elif counts==[1,1,1,2]: return "one pair" else : return "null" while True : try : hand=[int(_)for _ in input().split(',')] except EOFError : break print(poker_hand(hand)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; skip ; skip ; while true do ( try ( hand := input().split(',')->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger()))) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))) ; execute (poker_hand(hand))->display()); operation is_straight(hand : OclAny) : OclAny pre: true post: true activity: if hand = Sequence{1}->union(Sequence{10}->union(Sequence{11}->union(Sequence{12}->union(Sequence{ 13 })))) then ( return true ) else skip ; var m : OclAny := (hand)->min() ; if hand = (Integer.subrange(m, m + 5-1)) then ( return true ) else skip ; return false; operation poker_hand(hand : OclAny) : OclAny pre: true post: true activity: hand := hand->sort() ; var counts : OclAny := Set{} ; for card : hand do ( counts[card+1] := counts.get(card, 0) + 1) ; counts := (counts.values())->sort() ; if counts = Sequence{1}->union(Sequence{ 4 }) then ( return "four card" ) else (if counts = Sequence{2}->union(Sequence{ 3 }) then ( return "full house" ) else (if is_straight(hand) then ( return "straight" ) else (if counts = Sequence{1}->union(Sequence{1}->union(Sequence{ 3 })) then ( return "three card" ) else (if counts = Sequence{1}->union(Sequence{2}->union(Sequence{ 2 })) then ( return "two pair" ) else (if counts = Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 2 }))) then ( return "one pair" ) else ( return "null" ) ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import Counter class Poker(object): def __init__(self,cards): self.cards=cards[:] self.cards.sort(reverse=True) def evaluate_hand(self): if(self.cards[0]==self.cards[1]+1==self.cards[2]+2==self.cards[3]+3==self.cards[4]+4)or(self.cards[0]==13 and self.cards[1]==12 and self.cards[2]==11 and self.cards[3]==10 and self.cards[4]==1): return 'straight' else : c=Counter(self.cards) hand=c.most_common() if hand[0][1]==4 : return 'four card' elif hand[0][1]==3 and hand[1][1]==2 : return 'full house' elif hand[0][1]==3 : return 'three card' elif hand[0][1]==2 and hand[1][1]==2 : return 'two pair' elif hand[0][1]==2 : return 'one pair' else : return 'null' if __name__=='__main__' : for line in sys.stdin : cards=[int(x)for x in line.strip().split(',')] p1=Poker(cards) result=p1.evaluate_hand() print(result) ------------------------------------------------------------ OCL File: --------- class Poker extends object { static operation newPoker() : Poker pre: true post: Poker->exists( _x | result = _x ); attribute cards : Sequence := cards; operation initialise(cards : OclAny) : pre: true post: true activity: self.cards := cards ; (expr (atom (name self)) (trailer . (name cards)) (trailer . (name sort) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) )))); return self; operation evaluate_hand() : OclAny pre: true post: true activity: if (self.cards->first() = self.cards[1+1] + 1 & (self.cards[1+1] + 1 == self.cards[2+1] + 2) & (self.cards[2+1] + 2 == self.cards[3+1] + 3) & (self.cards[3+1] + 3 == self.cards[4+1] + 4)) or (self.cards->first() = 13 & self.cards[1+1] = 12 & self.cards[2+1] = 11 & self.cards[3+1] = 10 & self.cards[4+1] = 1) then ( return 'straight' ) else ( var c : OclAny := Counter(self.cards) ; var hand : OclAny := c.most_common() ; if hand->first()[1+1] = 4 then ( return 'four card' ) else (if hand->first()[1+1] = 3 & hand[1+1][1+1] = 2 then ( return 'full house' ) else (if hand->first()[1+1] = 3 then ( return 'three card' ) else (if hand->first()[1+1] = 2 & hand[1+1][1+1] = 2 then ( return 'two pair' ) else (if hand->first()[1+1] = 2 then ( return 'one pair' ) else ( return 'null' ) ) ) ) ) ); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( for line : OclFile["System.in"] do ( cards := line->trim().split(',')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var p1 : Poker := (Poker.newPoker()).initialise(cards) ; var result : OclAny := p1.evaluate_hand() ; execute (result)->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- straight='12345678910111213110111213' while True : try : lst=list(map(int,input().split(','))) lst.sort() clst=[] for i in lst : clst.append(lst.count(i)) if clst.count(4)==4 : print('four card') elif clst.count(3)==3 : if clst.count(2)==2 : print('full house') else : print('three card') elif clst.count(2)==4 : print('two pair') elif clst.count(2)==2 : print('one pair') else : s=str(lst[0])+str(lst[1])+str(lst[2])+str(lst[3])+str(lst[4]) if s in straight : print('straight') else : print('null') except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var straight : String := '12345678910111213110111213' ; while true do ( try ( var lst : Sequence := ((input().split(','))->collect( _x | (OclType["int"])->apply(_x) )) ; lst := lst->sort() ; var clst : Sequence := Sequence{} ; for i : lst do ( execute ((lst->count(i)) : clst)) ; if clst->count(4) = 4 then ( execute ('four card')->display() ) else (if clst->count(3) = 3 then ( if clst->count(2) = 2 then ( execute ('full house')->display() ) else ( execute ('three card')->display() ) ) else (if clst->count(2) = 4 then ( execute ('two pair')->display() ) else (if clst->count(2) = 2 then ( execute ('one pair')->display() ) else ( var s : String := ("" + ((lst->first()))) + ("" + ((lst[1+1]))) + ("" + ((lst[2+1]))) + ("" + ((lst[3+1]))) + ("" + ((lst[4+1]))) ; if (straight)->characters()->includes(s) then ( execute ('straight')->display() ) else ( execute ('null')->display() ) ) ) ) ) ) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import*; def maxResult(n,a,b,c): maxVal=0 ; for i in range(0,n+1,a): for j in range(0,n-i+1,b): z=(n-(i+j))/c ; if(floor(z)==ceil(z)): x=i//a ; y=j//b ; maxVal=max(maxVal,x+y+int(z)); return maxVal ; if __name__=="__main__" : n=10 a=5 b=3 c=4 print(maxResult(n,a,b,c)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; ; skip ; if __name__ = "__main__" then ( n := 10 ; a := 5 ; b := 3 ; c := 4 ; execute (maxResult(n, a, b, c))->display(); ) else skip; operation maxResult(n : OclAny, a : OclAny, b : OclAny, c : OclAny) pre: true post: true activity: var maxVal : int := 0; ; for i : Integer.subrange(0, n + 1-1)->select( $x | ($x - 0) mod a = 0 ) do ( for j : Integer.subrange(0, n - i + 1-1)->select( $x | ($x - 0) mod b = 0 ) do ( var z : double := (n - (i + j)) / c; ; if (floor(z) = ceil(z)) then ( var x : int := i div a; ; var y : int := j div b; ; maxVal := Set{maxVal, x + y + ("" + ((z)))->toInteger()}->max(); ) else skip)) ; return maxVal;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import Counter straight=[list(range(i,i+5))for i in range(1,10)]+[[1,10,11,12,13]] def hantei(hand): l=sorted(Counter(hand).values(),reverse=True) if l[0]==4 : return "four card" if l[0]==3 and l[1]==2 : return "full house" if hand in straight : return "straight" if l[0]==3 : return "three card" if l[0]==l[1]==2 : return "two pair" if l[0]==2 : return "one pair" return "null" for line in sys.stdin : hand=sorted(map(int,line.split(','))) print(hantei(hand)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var straight : Sequence := Integer.subrange(1, 10-1)->select(i | true)->collect(i | ((Integer.subrange(i, i + 5-1))))->union(Sequence{ Sequence{1}->union(Sequence{10}->union(Sequence{11}->union(Sequence{12}->union(Sequence{ 13 })))) }) ; skip ; for line : OclFile["System.in"] do ( hand := (line.split(','))->collect( _x | (OclType["int"])->apply(_x) )->sort() ; execute (hantei(hand))->display()); operation hantei(hand : OclAny) : OclAny pre: true post: true activity: var l : Sequence := Counter(hand).values()->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; if l->first() = 4 then ( return "four card" ) else skip ; if l->first() = 3 & l[1+1] = 2 then ( return "full house" ) else skip ; if (straight)->includes(hand) then ( return "straight" ) else skip ; if l->first() = 3 then ( return "three card" ) else skip ; if l->first() = l[1+1] & (l[1+1] == 2) then ( return "two pair" ) else skip ; if l->first() = 2 then ( return "one pair" ) else skip ; return "null"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_input(): while True : try : yield ''.join(input()) except EOFError : break N=list(get_input()) for l in range(len(N)): table=[0 for i in range(15)] cards=[int(i)for i in N[l].split(",")] for i in range(5): table[cards[i]]+=1 two,three,four,ren=0,0,0,0 for i in range(15): if table[i]==2 : two+=1 elif table[i]==3 : three+=1 elif table[i]==4 : four+=1 for i in range(14): if table[i]==1 and table[i+1]==1 : ren+=1 if table[10]==1 and table[11]==1 and table[12]==1 and table[13]==1 and table[1]==1 : ren=4 ans="null" if four==1 : ans="four card" elif two==1 and three==1 : ans="full house" elif ren==4 : ans="straight" elif three==1 : ans="three card" elif two==2 : ans="two pair" elif two==1 : ans="one pair" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : Sequence := (OclIterator.newOclIterator_Function(lambda _i : int in self.get_input(_i))) ; for l : Integer.subrange(0, (N)->size()-1) do ( var table : Sequence := Integer.subrange(0, 15-1)->select(i | true)->collect(i | (0)) ; var cards : Sequence := N[l+1].split(",")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; for i : Integer.subrange(0, 5-1) do ( table[cards[i+1]+1] := table[cards[i+1]+1] + 1) ; var two : OclAny := null; var three : OclAny := null; var four : OclAny := null; var ren : OclAny := null; Sequence{two,three,four,ren} := Sequence{0,0,0,0} ; for i : Integer.subrange(0, 15-1) do ( if table[i+1] = 2 then ( two := two + 1 ) else (if table[i+1] = 3 then ( three := three + 1 ) else (if table[i+1] = 4 then ( four := four + 1 ) else skip ) ) ) ; for i : Integer.subrange(0, 14-1) do ( if table[i+1] = 1 & table[i + 1+1] = 1 then ( ren := ren + 1 ) else skip) ; if table[10+1] = 1 & table[11+1] = 1 & table[12+1] = 1 & table[13+1] = 1 & table[1+1] = 1 then ( var ren : int := 4 ) else skip ; var ans : String := "null" ; if four = 1 then ( ans := "four card" ) else (if two = 1 & three = 1 then ( ans := "full house" ) else (if ren = 4 then ( ans := "straight" ) else (if three = 1 then ( ans := "three card" ) else (if two = 2 then ( ans := "two pair" ) else (if two = 1 then ( ans := "one pair" ) else skip ) ) ) ) ) ; execute (ans)->display()); operation get_input(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; while true do ( try ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return StringLib.sumStringsWithSeparator(((OclFile["System.in"]).readLine()), '')) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) x_a=[0]*N y_a=[0]*N r_a=[0]*N x_b=[0]*N y_b=[0]*N r_b=[0]*N for i in range(N): x_a[i],y_a[i],r_a[i],x_b[i],y_b[i],r_b[i]=map(float,input().split()) for i in range(N): AB=((x_a[i]-x_b[i])**2+(y_a[i]-y_b[i])**2)**(1/2) r_diff=abs(r_a[i]-r_b[i]) if AB>r_a[i]+r_b[i]: print(0) elif r_a[i]+r_b[i]>=AB and AB>=r_diff : print(1) else : if r_a[i]>r_b[i]: print(2) else : print(-2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x_a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var y_a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var r_a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var x_b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var y_b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var r_b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for i : Integer.subrange(0, N-1) do ( var x_a[i+1] : OclAny := null; var y_a[i+1] : OclAny := null; var r_a[i+1] : OclAny := null; var x_b[i+1] : OclAny := null; var y_b[i+1] : OclAny := null; var r_b[i+1] : OclAny := null; Sequence{x_a[i+1],y_a[i+1],r_a[i+1],x_b[i+1],y_b[i+1],r_b[i+1]} := (input().split())->collect( _x | (OclType["double"])->apply(_x) )) ; for i : Integer.subrange(0, N-1) do ( var AB : double := ((((x_a[i+1] - x_b[i+1]))->pow(2) + ((y_a[i+1] - y_b[i+1]))->pow(2)))->pow((1 / 2)) ; var r_diff : double := (r_a[i+1] - r_b[i+1])->abs() ; if (AB->compareTo(r_a[i+1] + r_b[i+1])) > 0 then ( execute (0)->display() ) else (if (r_a[i+1] + r_b[i+1]->compareTo(AB)) >= 0 & (AB->compareTo(r_diff)) >= 0 then ( execute (1)->display() ) else ( if (r_a[i+1]->compareTo(r_b[i+1])) > 0 then ( execute (2)->display() ) else ( execute (-2)->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def prime_seive(MAX,isprime,prime): i=2 while(i*i<=MAX): if(isprime[i]==1): prime.append(i) for j in range(i*2,MAX,i): isprime[j]=0 i+=1 def printNearest(N): MAX=10**6 isprime=[1]*MAX isprime[0]=isprime[1]=0 prime=[] i=0 prime_seive(MAX,isprime,prime) while not isprime[N]: N+=prime[i] i+=1 return N N=8 print(printNearest(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; N := 8 ; execute (printNearest(N))->display(); operation prime_seive(MAX : OclAny, isprime : OclAny, prime : OclAny) pre: true post: true activity: var i : int := 2 ; while ((i * i->compareTo(MAX)) <= 0) do ( if (isprime[i+1] = 1) then ( execute ((i) : prime) ; for j : Integer.subrange(i * 2, MAX-1)->select( $x | ($x - i * 2) mod i = 0 ) do ( isprime[j+1] := 0) ) else skip ; i := i + 1); operation printNearest(N : OclAny) : OclAny pre: true post: true activity: MAX := (10)->pow(6) ; isprime := MatrixLib.elementwiseMult(Sequence{ 1 }, MAX) ; isprime->first() := 0; var isprime[1+1] : int := 0 ; prime := Sequence{} ; i := 0 ; prime_seive(MAX, isprime, prime) ; while not(isprime[N+1]) do ( N := N + prime[i+1] ; i := i + 1) ; return N; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSum(n): sum=0 i=1 while((1<display(); operation findSum(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; var i : int := 1 ; while (((1 * (2->pow(i)))->compareTo(n)) < 0) do ( for j : Integer.subrange(0, i-1) do ( var num : int := (1 * (2->pow(i))) + (1 * (2->pow(j))) ; if ((num->compareTo(n)) <= 0) then ( sum := sum + num ) else skip) ; i := i + 1) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isMultipleof5(n): while(n>0): n=n-5 if(n==0): return 1 return 0 i=19 if(isMultipleof5(i)==1): print(i,"is multiple of 5") else : print(i,"is not a multiple of 5") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var i : int := 19 ; if (isMultipleof5(i) = 1) then ( execute (i)->display() ) else ( execute (i)->display() ); operation isMultipleof5(n : OclAny) : OclAny pre: true post: true activity: while (n > 0) do ( n := n - 5) ; if (n = 0) then ( return 1 ) else skip ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=set(map(int,input().split())) m=int(input()) b=set(map(int,input().split())) if b-a : print(0) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; if b - a then ( execute (0)->display() ) else ( execute (1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def includes(li1,li2): def partition(li,x): if len(li)==0 : return 0 mid=len(li)//2 if li[mid]x : return partition(li[: mid],x) else : return mid def binsearch(li,x): i=partition(li,x) if 0<=i1 : mid=len(li2)//2 i=partition(li1,li2[mid]) if i>=len(li1)or li2[mid]!=li1[i]: return False else : return(includes(li1[: i],li2[: mid])and includes(li1[i+1 :],li2[mid+1 :])) elif len(li2)==1 : return binsearch(li1,li2[0]) else : return True def run(): n=int(input()) la=[int(x)for x in input().split()] assert(n==len(la)) m=int(input()) lb=[int(x)for x in input().split()] assert(m==len(lb)) if includes(la,lb): print(1) else : print(0) if __name__=='__main__' : run() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( run() ) else skip; operation includes(li1 : OclAny, li2 : OclAny) : OclAny pre: true post: true activity: skip ; skip ; if ((li1)->size()->compareTo((li2)->size())) < 0 then ( return false ) else skip ; if (li2)->size() > 1 then ( mid := (li2)->size() div 2 ; i := partition(li1, li2[mid+1]) ; if (i->compareTo((li1)->size())) >= 0 or li2[mid+1] /= li1[i+1] then ( return false ) else ( return (includes(li1.subrange(1,i), li2.subrange(1,mid)) & includes(li1.subrange(i + 1+1), li2.subrange(mid + 1+1))) ) ) else (if (li2)->size() = 1 then ( return binsearch(li1, li2->first()) ) else ( return true ) ) ; operation run() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var la : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; assert (n = (la)->size()) do "assertion failed" ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lb : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; assert (m = (lb)->size()) do "assertion failed" ; if includes(la, lb) then ( execute (1)->display() ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect n=int(input()) A=list(map(int,input().split())) m=int(input()) B=list(map(int,input().split())) minA=A[0] maxA=A[-1] answer=False for i in range(m): if(B[i]toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var minA : OclAny := A->first() ; var maxA : OclAny := A->last() ; var answer : boolean := false ; for i : Integer.subrange(0, m-1) do ( if ((B[i+1]->compareTo(minA)) < 0) or ((maxA->compareTo(B[i+1])) < 0) then ( answer := false ; break ) else ( if A[bisect.bisect_left(A, B[i+1])+1] = B[i+1] then ( answer := true ) else ( answer := false ; break ) )) ; if answer then ( execute (1)->display() ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- readline=open(0).readline N=int(readline()) A=set(map(int,readline().split())) M=int(readline()) B=set(map(int,readline().split())) print(+(len(A & B)==M)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var readline : OclAny := open(0).readline ; var N : int := ("" + ((readline())))->toInteger() ; var A : Set := Set{}->union(((readline().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var M : int := ("" + ((readline())))->toInteger() ; var B : Set := Set{}->union(((readline().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; execute (((MathLib.bitwiseAnd(A, B))->size() = M))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[int(input())for i in range(10)] a.sort() for i in range(1,4): print("%d" % a[-i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Integer.subrange(0, 10-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; a := a->sort() ; for i : Integer.subrange(1, 4-1) do ( execute (StringLib.format("%d",a->reverse()->at(-(-i))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def binsearch(d,l): max=len(l)-1 min=0 mid=max//2 while True : if(l[mid]>d): max=mid elif(l[mid]==d): return True else : min=mid mid=(max+min)//2 if(mid==max or mid==min): if(l[mid]==d or l[max]==d): return True return False def main(): n1=int(input()) l1=list(map(int,input().split())) n2=int(input()) l2=list(map(int,input().split())) for i in l2 : result=binsearch(i,l1) if(result==False): print(0) return else : print(1) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation binsearch(d : OclAny, l : OclAny) : OclAny pre: true post: true activity: var max : double := (l)->size() - 1 ; var min : int := 0 ; var mid : int := max div 2 ; while true do ( if ((l[mid+1]->compareTo(d)) > 0) then ( max := mid ) else (if (l[mid+1] = d) then ( return true ) else ( min := mid ) ) ; mid := (max + min) div 2 ; if (mid = max or mid = min) then ( if (l[mid+1] = d or l[max+1] = d) then ( return true ) else skip ; return false ) else skip); operation main() pre: true post: true activity: var n1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n2 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name l2))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name result)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name binsearch)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (name l1)))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name result)))) == (comparison (expr (atom (name False)))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))))))))))) (stmt (simple_stmt (small_stmt return))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def val(c): if(ord(c)>=ord('0')and ord(c)<=ord('9')): return ord(c)-ord('0') else : return ord(c)-ord('A')+10 def toDeci(str,base): Len=len(str) power=1 num=0 for i in range(Len-1,-1,-1): if(val(str[i])>=base): print("Invalid Number") return-1 num+=val(str[i])*power power=power*base return num def isEven(num,N): deci=toDeci(num,N) return(deci % 2==0) if __name__=='__main__' : num="11A" N=16 if(isEven(num,N)): print("Even") else : print("Odd") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( num := "11A" ; N := 16 ; if (isEven(num, N)) then ( execute ("Even")->display() ) else ( execute ("Odd")->display() ) ) else skip; operation val(c : OclAny) : OclAny pre: true post: true activity: if (((c)->char2byte()->compareTo(('0')->char2byte())) >= 0 & ((c)->char2byte()->compareTo(('9')->char2byte())) <= 0) then ( return (c)->char2byte() - ('0')->char2byte() ) else ( return (c)->char2byte() - ('A')->char2byte() + 10 ); operation toDeci(OclType["String"] : OclAny, base : OclAny) : OclAny pre: true post: true activity: var Len : int := (OclType["String"])->size() ; var power : int := 1 ; var num : int := 0 ; for i : Integer.subrange(-1 + 1, Len - 1)->reverse() do ( if ((val(("" + ([i+1])))->compareTo(base)) >= 0) then ( execute ("Invalid Number")->display() ; return -1 ) else skip ; num := num + val(("" + ([i+1]))) * power ; power := power * base) ; return num; operation isEven(num : OclAny, N : OclAny) : OclAny pre: true post: true activity: var deci : OclAny := toDeci(num, N) ; return (deci mod 2 = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printRepeatingEven(arr,n): axor=0 ; for i in range(0,n): pos=1<union(Sequence{12}->union(Sequence{23}->union(Sequence{10}->union(Sequence{12}->union(Sequence{12}->union(Sequence{15}->union(Sequence{23}->union(Sequence{14}->union(Sequence{12}->union(Sequence{ 15 })))))))))); ; n := (arr)->size(); ; printRepeatingEven(arr, n);; operation printRepeatingEven(arr : OclAny, n : OclAny) pre: true post: true activity: var axor : int := 0; ; for i : Integer.subrange(0, n-1) do ( var pos : int := 1 * (2->pow(arr[i+1])); ; axor := axor xor pos;) ; for i : Integer.subrange(0, n - 1-1) do ( pos := 1 * (2->pow(arr[i+1])); ; if (not((MathLib.bitwiseAnd(pos, axor)))) then ( execute (arr[i+1])->display(); ; axor := axor xor pos; ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): primes=eulerlib.list_primes(100000) ans=sum(p for p in primes if p==2 or p==5 or not has_divisible_repunit(p)) return str(ans) def has_divisible_repunit(p): return(pow(10,10**16,p*9)-1)//9 % p==0 if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var primes : OclAny := eulerlib.list_primes(100000) ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name p)))))) (comp_for for (exprlist (expr (atom (name p)))) in (logical_test (comparison (expr (atom (name primes))))) (comp_iter if (test (logical_test (logical_test (logical_test (comparison (comparison (expr (atom (name p)))) == (comparison (expr (atom (number (integer 2))))))) or (logical_test (comparison (comparison (expr (atom (name p)))) == (comparison (expr (atom (number (integer 5)))))))) or (logical_test not (logical_test (comparison (expr (atom (name has_divisible_repunit)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p)))))))) )))))))))))))->sum() ; return ("" + ((ans))); operation has_divisible_repunit(p : OclAny) : OclAny pre: true post: true activity: return ((10)->pow((10)->pow(16)) - 1) div 9 mod p = 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkFibinnary(n): prev_last=0 while(n): if((n & 1)and prev_last): return False prev_last=n & 1 n>>=1 return True n=10 if(checkFibinnary(n)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 10 ; if (checkFibinnary(n)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); operation checkFibinnary(n : OclAny) : OclAny pre: true post: true activity: var prev_last : int := 0 ; while (n) do ( if ((MathLib.bitwiseAnd(n, 1)) & prev_last) then ( return false ) else skip ; prev_last := MathLib.bitwiseAnd(n, 1) ; n := n div (2->pow(1))) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import* inp=lambda : stdin.readline() def main(): n,m=[int(i)for i in inp().split()] f,b=[int(i)for i in inp().split()],[int(i)for i in inp().split()] d={} for i in range(len(f)): if f[i]not in d : d[f[i]]=[] d[f[i]].append(i+1) sb,fb=set(b),set(f) ans=[] if not sb.issubset(fb): print("Impossible") else : for i in b : if len(d[i])>1 : print("Ambiguity") exit(0) else : ans.append(d[i][0]) print("Possible") print(" ".join([str(i)for i in ans])) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var inp : Function := lambda $$ : OclAny in (stdin.readLine()) ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := inp->apply().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var f : OclAny := null; var b : OclAny := null; Sequence{f,b} := Sequence{inp->apply().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())),inp->apply().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))} ; var d : OclAny := Set{} ; for i : Integer.subrange(0, (f)->size()-1) do ( if (d)->excludes(f[i+1]) then ( d[f[i+1]+1] := Sequence{} ) else skip ; (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name f)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ))))) ; var sb : OclAny := null; var fb : OclAny := null; Sequence{sb,fb} := Sequence{Set{}->union((b)),Set{}->union((f))} ; var ans : Sequence := Sequence{} ; if not(sb <: (fb)) then ( execute ("Impossible")->display() ) else ( for i : b do ( if (d[i+1])->size() > 1 then ( execute ("Ambiguity")->display() ; exit(0) ) else ( execute ((d[i+1]->first()) : ans) )) ; execute ("Possible")->display() ; execute (StringLib.sumStringsWithSeparator((ans->select(i | true)->collect(i | (("" + ((i)))))), " "))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(): n,m=map(int,input().split()) f=list(map(int,sys.stdin.readline().split())) b=list(map(int,sys.stdin.readline().split())) f=[0]+f b=[0]+b imf=set() d=set() g=[0]*(n+1) for i in range(1,n+1): if f[i]in imf : d.add(f[i]) else : imf.add(f[i]) g[f[i]]=i for i in range(1,m+1): if b[i]not in imf : print("Impossible") return for i in range(1,m+1): if b[i]in d : print("Ambiguity") return print("Possible") for i in range(1,m): print(g[b[i]],end=" ") print(g[b[m]]) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var f : Sequence := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; f := Sequence{ 0 }->union(f) ; b := Sequence{ 0 }->union(b) ; var imf : Set := Set{}->union(()) ; var d : Set := Set{}->union(()) ; var g : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(1, n + 1-1) do ( if (imf)->includes(f[i+1]) then ( execute ((f[i+1]) : d) ) else ( execute ((f[i+1]) : imf) ) ; g[f[i+1]+1] := i) ; for i : Integer.subrange(1, m + 1-1) do ( if (imf)->excludes(b[i+1]) then ( execute ("Impossible")->display() ; return ) else skip) ; for i : Integer.subrange(1, m + 1-1) do ( if (d)->includes(b[i+1]) then ( execute ("Ambiguity")->display() ; return ) else skip) ; execute ("Possible")->display() ; for i : Integer.subrange(1, m-1) do ( execute (g[b[i+1]+1])->display()) ; execute (g[b[m+1]+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools n,m=[int(i)for i in input().split()] inp=[int(i)for i in input().split()] f=[list()for i in range(n+2)] for i in range(len(inp)): if 1<=inp[i]<=n : f[inp[i]].append(i) b=[int(i)for i in input().split()] for item in b : if not f[item]: print("Impossible") exit(0) ans=[] for item in b : if len(f[item])<=1 : ans.append(str(f[item][0]+1)) else : print("Ambiguity") exit(0) print("Possible") print(" ".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var inp : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var f : Sequence := Integer.subrange(0, n + 2-1)->select(i | true)->collect(i | (())) ; for i : Integer.subrange(0, (inp)->size()-1) do ( if 1 <= inp[i+1] & (inp[i+1] <= n) then ( (expr (atom (name f)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name inp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ) else skip) ; var b : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; for item : b do ( if not(f[item+1]) then ( execute ("Impossible")->display() ; exit(0) ) else skip) ; var ans : Sequence := Sequence{} ; for item : b do ( if (f[item+1])->size() <= 1 then ( execute ((("" + ((f[item+1]->first() + 1)))) : ans) ) else ( execute ("Ambiguity")->display() ; exit(0) )) ; execute ("Possible")->display() ; execute (StringLib.sumStringsWithSeparator((ans), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,m=map(int,input().split()) ff=list(map(int,input().split())) bb=list(map(int,input().split())) xlat,res=[-1]*(n+1),[0]*m for i,f in enumerate(ff,1): x=xlat[f] if x==-1 : xlat[f]=i elif x>-1 : xlat[f]=-2 s="Possible" for i,b in enumerate(bb): x=xlat[b] if x>=0 : res[i]=x else : if x==-1 : print("Impossible") return s="Ambiguity" print(s) if s=="Possible" : print(' '.join(map(str,res))) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ff : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var bb : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var xlat : OclAny := null; var res : OclAny := null; Sequence{xlat,res} := Sequence{MatrixLib.elementwiseMult(Sequence{ -1 }, (n + 1)),MatrixLib.elementwiseMult(Sequence{ 0 }, m)} ; for _tuple : Integer.subrange(1, (ff, 1)->size())->collect( _indx | Sequence{_indx-1, (ff, 1)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var f : OclAny := _tuple->at(_indx); var x : OclAny := xlat[f+1] ; if x = -1 then ( xlat[f+1] := i ) else (if x > -1 then ( xlat[f+1] := -2 ) else skip)) ; var s : String := "Possible" ; for _tuple : Integer.subrange(1, (bb)->size())->collect( _indx | Sequence{_indx-1, (bb)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); x := xlat[b+1] ; if x >= 0 then ( res[i+1] := x ) else ( if x = -1 then ( execute ("Impossible")->display() ; return ) else skip ; s := "Ambiguity" )) ; execute (s)->display() ; if s = "Possible" then ( execute (StringLib.sumStringsWithSeparator(((res)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,m=map(int,input().split()) xlat,res,s=[-1]*(n+1),[0]*m,"Possible" for i,f in enumerate(map(int,input().split()),1): x=xlat[f] if x==-1 : xlat[f]=i elif x>-1 : xlat[f]=-2 for i,b in enumerate(map(int,input().split())): x=xlat[b] if x>=0 : res[i]=x else : if x==-1 : print("Impossible") return s="Ambiguity" print(s) if s is "Possible" : print(' '.join(map(str,res))) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var xlat : OclAny := null; var res : OclAny := null; var s : OclAny := null; Sequence{xlat,res,s} := Sequence{MatrixLib.elementwiseMult(Sequence{ -1 }, (n + 1)),MatrixLib.elementwiseMult(Sequence{ 0 }, m),"Possible"} ; for _tuple : Integer.subrange(1, ((input().split())->collect( _x | (OclType["int"])->apply(_x) ), 1)->size())->collect( _indx | Sequence{_indx-1, ((input().split())->collect( _x | (OclType["int"])->apply(_x) ), 1)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var f : OclAny := _tuple->at(_indx); var x : OclAny := xlat[f+1] ; if x = -1 then ( xlat[f+1] := i ) else (if x > -1 then ( xlat[f+1] := -2 ) else skip)) ; for _tuple : Integer.subrange(1, ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->size())->collect( _indx | Sequence{_indx-1, ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); x := xlat[b+1] ; if x >= 0 then ( res[i+1] := x ) else ( if x = -1 then ( execute ("Impossible")->display() ; return ) else skip ; var s : String := "Ambiguity" )) ; execute (s)->display() ; if s <>= "Possible" then ( execute (StringLib.sumStringsWithSeparator(((res)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[] for i in range(10): a.append(input()) j=0 while j<10 : k=0 while k<9 : if int(a[k])toInteger()->compareTo(("" + ((a[k + 1+1])))->toInteger())) < 0 then ( var tmp : OclAny := a[k+1] ; a[k+1] := a[k + 1+1] ; a[k + 1+1] := tmp ) else skip ; k := k + 1) ; j := j + 1) ; execute (a->first())->display() ; execute (a[1+1])->display() ; execute (a[2+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printDistinct(arr,n): for i in range(0,n): d=0 for j in range(0,i): if(arr[i]==arr[j]): d=1 break if(d==0): print(arr[i]) arr=[6,10,5,4,9,120,4,6,10] n=len(arr) printDistinct(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{6}->union(Sequence{10}->union(Sequence{5}->union(Sequence{4}->union(Sequence{9}->union(Sequence{120}->union(Sequence{4}->union(Sequence{6}->union(Sequence{ 10 })))))))) ; n := (arr)->size() ; printDistinct(arr, n); operation printDistinct(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( var d : int := 0 ; for j : Integer.subrange(0, i-1) do ( if (arr[i+1] = arr[j+1]) then ( d := 1 ; break ) else skip) ; if (d = 0) then ( execute (arr[i+1])->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def breakEvenPoint(exp,S,M): earn=S-M res=math.ceil(exp/earn) return res if __name__=="__main__" : exp=3550 S=90 M=65 print(int(breakEvenPoint(exp,S,M))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( exp := 3550 ; S := 90 ; M := 65 ; execute (("" + ((breakEvenPoint(exp, S, M))))->toInteger())->display() ) else skip; operation breakEvenPoint(exp : OclAny, S : OclAny, M : OclAny) : OclAny pre: true post: true activity: var earn : double := S - M ; var res : double := (exp / earn)->ceil() ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) first=-1 last=-1 f=0 c=0 s=0 for i in range(1,n): if(l[i]toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var first : int := -1 ; var last : int := -1 ; var f : int := 0 ; var c : int := 0 ; var s : int := 0 ; for i : Integer.subrange(1, n-1) do ( if ((l[i+1]->compareTo(l[i - 1+1])) < 0) then ( if (first = -1) then ( first := i - 1 ) else skip ; if (first /= -1 & f /= 1) then ( last := i ) else skip ; if (f = 1) then ( s := 1 ; execute ("no")->display() ; break ) else skip ) else ( if (first /= -1) then ( f := 1 ; c := 0 ) else skip )) ; if (first = -1 & last = -1) then ( c := 1 ) else skip ; if (c = 1) then ( execute ("yes")->display() ; execute (n)->display() ) else ( if (s /= 1) then ( l.subrange(first+1, last + 1) := l.subrange(first+1, last + 1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; if (l->sort() = l) then ( execute ("yes")->display() ; execute (first + 1)->display() ) else ( execute ("no")->display() ) ) else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split(" "))) i=0 x=0 while ia[j+1]: j+=1 if a[: i]+sorted(a[i : j+1])+a[j+1 :]==sorted(a): print(f"yes\n{i+1}{j+1}") else : print("no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var i : int := 0 ; var x : int := 0 ; while (i->compareTo(n - 1)) < 0 & (a[i+1]->compareTo(a[i + 1+1])) < 0 do ( i := i + 1) ; if i = n - 1 then ( execute ("yes\n1 1")->display() ; exit() ) else skip ; var j : int := i ; while (j->compareTo(n - 1)) < 0 & (a[j+1]->compareTo(a[j + 1+1])) > 0 do ( j := j + 1) ; if a.subrange(1,i)->union(a.subrange(i+1, j + 1)->sort()) + a.subrange(j + 1+1) = a->sort() then ( execute (StringLib.formattedString("yes\n{i+1}{j+1}"))->display() ) else ( execute ("no")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input(),2) c=1 if c>=x : print(0) else : for i in range(1,100000000): c=4**i if c>=x : print(i) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine(), 2)))->toInteger() ; var c : int := 1 ; if (c->compareTo(x)) >= 0 then ( execute (0)->display() ) else ( for i : Integer.subrange(1, 100000000-1) do ( c := (4)->pow(i) ; if (c->compareTo(x)) >= 0 then ( execute (i)->display() ; break ) else skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,n=map(int,input().split()) a=list(map(int,input().split())) if m==2 : ans=n for i in range(2): t=0 for j in range(n): idx=(i+j)% 2+1 if idx!=a[j]: t+=1 ans=min(ans,t) else : ans=0 prev=a[0] for i in range(1,n): if prev==a[i]: ans+=1 a[i]=-1 prev=a[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if m = 2 then ( var ans : OclAny := n ; for i : Integer.subrange(0, 2-1) do ( var t : int := 0 ; for j : Integer.subrange(0, n-1) do ( var idx : int := (i + j) mod 2 + 1 ; if idx /= a[j+1] then ( t := t + 1 ) else skip) ; ans := Set{ans, t}->min()) ) else ( ans := 0 ; var prev : OclAny := a->first() ; for i : Integer.subrange(1, n-1) do ( if prev = a[i+1] then ( ans := ans + 1 ; a[i+1] := -1 ) else skip ; prev := a[i+1]) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): n=1000000000 ndigits=[0]*10 temp=n for i in range(len(ndigits)): ndigits[i]=temp % 10 temp//=10 n2digits=[0]*19 temp=n*n for i in range(len(n2digits)): n2digits[i]=temp % 10 temp//=10 while not is_concealed_square(n2digits): add_20n(ndigits,n2digits) add_10pow(n2digits,2) n+=10 add_10pow(ndigits,1) return str(n) def is_concealed_square(n): for i in range(1,10): if n[20-i*2]!=i : return False return n[0]==0 def add_10pow(n,i): while n[i]==9 : n[i]=0 i+=1 n[i]+=1 def add_20n(n,n2): carry=0 i=0 while i0 : sum=n2[i]+carry n2[i]=sum % 10 carry=sum//10 i+=1 if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var n : int := 1000000000 ; var ndigits : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; var temp : int := n ; for i : Integer.subrange(0, (ndigits)->size()-1) do ( ndigits[i+1] := temp mod 10 ; temp := temp div 10) ; var n2digits : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 19) ; temp := n * n ; for i : Integer.subrange(0, (n2digits)->size()-1) do ( n2digits[i+1] := temp mod 10 ; temp := temp div 10) ; while not(is_concealed_square(n2digits)) do ( add(ndigits, n2digits)0n(ndigits, n2digits) ; addaddaddaddaddaddadd add(ndigits, n2digits)0n(ndigits, n2digits)0pow(n2digits, 2)0pow(n2digits, 2)0pow(n2digits, 2)0pow(n2digits, 2)0pow(n2digits, 2)0pow(n2digits, 2)0pow(n2digits, 2) ; n := n + 10 ; addaddaddaddaddaddadd add(ndigits, n2digits)0n(ndigits, n2digits)0pow(ndigits, 1)0pow(ndigits, 1)0pow(ndigits, 1)0pow(ndigits, 1)0pow(ndigits, 1)0pow(ndigits, 1)0pow(ndigits, 1)) ; return ("" + ((n))); operation is_concealed_square(n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(1, 10-1) do ( if n[20 - i * 2+1] /= i then ( return false ) else skip) ; return n->first() = 0; operation add skip0pow(n : OclAny, i : OclAny) pre: true post: true activity: while n[i+1] = 9 do ( n[i+1] := 0 ; i := i + 1) ; n[i+1] := n[i+1] + 1; operation addn : OclAny, n2 : OclAny0n(n : OclAny, n2 : OclAny) pre: true post: true activity: var carry : int := 0 ; i := 0 ; while (i->compareTo((n)->size())) < 0 do ( var sum : double := n[i+1] * 2 + n2[i + 1+1] + carry ; n2[i + 1+1] := sum mod 10 ; carry := sum div 10 ; i := i + 1) ; i := i + 1 ; while carry > 0 do ( sum := n2[i+1] + carry ; n2[i+1] := sum mod 10 ; carry := sum div 10 ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) sortA=a.copy(); sortA.sort(); c=0 ; l=[] if a==sortA : print('yes','\n',1,1) else : for el,cp in zip(a,sortA): if el!=cp : l.extend([a.index(el),a.index(cp)]); l.sort(); break if l[0]==0 : x=a[l[1]: :-1]+a[l[1]+1 :] else : x=a[: l[0]]+a[l[1]: l[0]-1 :-1]+a[l[1]+1 :] if x==sortA : print("yes") print(l[0]+1,l[1]+1) else : print('no') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sortA : OclAny := a->copy(); sortA := sortA->sort(); var c : int := 0; var l : Sequence := Sequence{} ; if a = sortA then ( execute ('yes')->display() ) else ( for _tuple : Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), sortA->at(_indx)} ) do (var _indx : int := 1; var el : OclAny := _tuple->at(_indx); _indx := _indx + 1; var cp : OclAny := _tuple->at(_indx); if el /= cp then ( l := l->union(Sequence{a->indexOf(el) - 1}->union(Sequence{ a->indexOf(cp) - 1 })); l := l->sort(); break ) else skip) ; if l->first() = 0 then ( var x : OclAny := a(subscript (test (logical_test (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))) : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) + a.subrange(l[1+1] + 1+1) ) else ( x := a.subrange(1,l->first()) + a(subscript (test (logical_test (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))) : (test (logical_test (comparison (expr (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) - (expr (atom (number (integer 1)))))))) (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) + a.subrange(l[1+1] + 1+1) ) ; if x = sortA then ( execute ("yes")->display() ; execute (l->first() + 1)->display() ) else ( execute ('no')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) nn=[int(i)for i in input().split()] i=0 c=0 g=[] k=[] h=0 while i<=n-2 : if nn[i]>nn[i+1]: k.append(i) g.append(nn[i]) h=i break i+=1 i+=1 while i<=n-2 : if nn[i]>nn[i+1]and i-h==1 : k.append(i) g.append(nn[i]) h=i i+=1 if len(k)==len(g)==0 : print("yes") print("1 1") else : a=k[0] p=k[-1] k.append(p+1) g.append(nn[p+1]) g.reverse() b=k[-1] o=nn[: a]+g+nn[b+1 :] u=o[0] c=0 for y in o : if ytoInteger() ; var nn : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var i : int := 0 ; var c : int := 0 ; var g : Sequence := Sequence{} ; var k : Sequence := Sequence{} ; var h : int := 0 ; while (i->compareTo(n - 2)) <= 0 do ( if (nn[i+1]->compareTo(nn[i + 1+1])) > 0 then ( execute ((i) : k) ; execute ((nn[i+1]) : g) ; h := i ; break ) else skip ; i := i + 1) ; i := i + 1 ; while (i->compareTo(n - 2)) <= 0 do ( if (nn[i+1]->compareTo(nn[i + 1+1])) > 0 & i - h = 1 then ( execute ((i) : k) ; execute ((nn[i+1]) : g) ; h := i ) else skip ; i := i + 1) ; if (k)->size() = (g)->size() & ((g)->size() == 0) then ( execute ("yes")->display() ; execute ("1 1")->display() ) else ( var a : OclAny := k->first() ; var p : OclAny := k->last() ; execute ((p + 1) : k) ; execute ((nn[p + 1+1]) : g) ; g := g->reverse() ; var b : OclAny := k->last() ; var o : OclAny := nn.subrange(1,a)->union(g) + nn.subrange(b + 1+1) ; var u : OclAny := o->first() ; c := 0 ; for y : o do ( if (y->compareTo(u)) < 0 then ( c := c + 1 ) else skip ; u := y) ; if c = 0 then ( execute ("yes")->display() ; execute (("" + ((a + 1))) + " " + ("" + ((b + 1))))->display() ) else ( execute ("no")->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def __gcd(a,b): if(a==0 or b==0): return 0 if(a==b): return a if(a>b): return __gcd(a-b,b) return __gcd(a,b-a) def lcm(a,b): return(a*b)/__gcd(a,b) def printArray(a,n): print(str(a[0])+" ") for i in range(0,n-1): print(str(lcm(a[i],a[i+1]))+" ") print(a[n-1]) a=[1,2,3] n=len(a) printArray(a,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; a := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; n := (a)->size() ; printArray(a, n); operation __gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0 or b = 0) then ( return 0 ) else skip ; if (a = b) then ( return a ) else skip ; if ((a->compareTo(b)) > 0) then ( return __gcd(a - b, b) ) else skip ; return __gcd(a, b - a); operation lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a * b) / __gcd(a, b); operation printArray(a : OclAny, n : OclAny) pre: true post: true activity: execute (("" + ((a->first()))) + " ")->display() ; for i : Integer.subrange(0, n - 1-1) do ( execute (("" + ((lcm(a[i+1], a[i + 1+1])))) + " ")->display()) ; execute (a[n - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys heights=sorted([int(h)for h in sys.stdin],reverse=True) print(heights[0]) print(heights[1]) print(heights[2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var heights : Sequence := OclFile["System.in"]->select(h | true)->collect(h | (("" + ((h)))->toInteger()))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; execute (heights->first())->display() ; execute (heights[1+1])->display() ; execute (heights[2+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def isPowerful(n): while(n % 2==0): power=0 while(n % 2==0): n=n//2 power=power+1 if(power==1): return False for factor in range(3,int(math.sqrt(n))+1,2): power=0 while(n % factor==0): n=n//factor power=power+1 if(power==1): return false return(n==1) print("YES" if isPowerful(20)else "NO") print("YES" if isPowerful(27)else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; execute (if isPowerful(20) then "YES" else "NO" endif)->display() ; execute (if isPowerful(27) then "YES" else "NO" endif)->display(); operation isPowerful(n : OclAny) : OclAny pre: true post: true activity: while (n mod 2 = 0) do ( var power : int := 0 ; while (n mod 2 = 0) do ( n := n div 2 ; power := power + 1) ; if (power = 1) then ( return false ) else skip) ; for factor : Integer.subrange(3, ("" + (((n)->sqrt())))->toInteger() + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( power := 0 ; while (n mod factor = 0) do ( n := n div factor ; power := power + 1) ; if (power = 1) then ( return false ) else skip) ; return (n = 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) grid=[list(map(int,input().split()))for i in range(n)] for i in range(n-1): if(grid[i][0]+grid[i][1])% 2!=(grid[i+1][0]+grid[i+1][1])% 2 : print(-1) exit() m=31 D=[2**i for i in range(m)] if(grid[0][0]+grid[0][1])% 2==0 : D.insert(0,1) m+=1 w=[[]for i in range(n)] for i,g in enumerate(grid): x,y=g for d in D[: :-1]: if abs(x)>=abs(y): if x>0 : x-=d w[i].append('R') else : x+=d w[i].append('L') else : if y>0 : y-=d w[i].append('U') else : y+=d w[i].append('D') print(m) print(*D) for ans in w : print(*ans[: :-1],sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var grid : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for i : Integer.subrange(0, n - 1-1) do ( if (grid[i+1]->first() + grid[i+1][1+1]) mod 2 /= (grid[i + 1+1]->first() + grid[i + 1+1][1+1]) mod 2 then ( execute (-1)->display() ; exit() ) else skip) ; var m : int := 31 ; var D : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | ((2)->pow(i))) ; if (grid->first()->first() + grid->first()[1+1]) mod 2 = 0 then ( D := D.insertAt(0+1, 1) ; m := m + 1 ) else skip ; var w : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for _tuple : Integer.subrange(1, (grid)->size())->collect( _indx | Sequence{_indx-1, (grid)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var g : OclAny := _tuple->at(_indx); var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := g ; for d : D(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if ((x)->abs()->compareTo((y)->abs())) >= 0 then ( if x > 0 then ( x := x - d ; (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'R'))))))) )))) ) else ( x := x + d ; (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'L'))))))) )))) ) ) else ( if y > 0 then ( y := y - d ; (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'U'))))))) )))) ) else ( y := y + d ; (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'D'))))))) )))) ) ))) ; execute (m)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name D))))))))->display() ; for ans : w do ( execute ((argument * (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ]))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) int1=lambda x : int(x)-1 p2D=lambda x : print(*x,sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int,sys.stdin.readline().split()) def LI(): return list(map(int,sys.stdin.readline().split())) def LLI(rows_number): return[LI()for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] def parity(): res=sum(xy[0])% 2 for x,y in xy : if(x+y)% 2!=res : return-1 return res n=II() xy=LLI(n) p=parity() if p==-1 : print(-1) exit() dd=[1] if p==0 : dd.append(1) lim=10**12 while len(dd)<40 and dd[-1]*2<=lim : dd.append(dd[-1]*2) print(40) print(*dd) for x,y in xy : ans="" for d in dd[: :-1]: if abs(x)>abs(y): if x>0 : x-=d ans+="R" else : x+=d ans+="L" else : if y>0 : y-=d ans+="U" else : y+=d ans+="D" print(ans[: :-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; var p2D : Function := lambda x : OclAny in (((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ; skip ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := II() ; var xy : OclAny := LLI(n) ; var p : OclAny := parity() ; if p = -1 then ( execute (-1)->display() ; exit() ) else skip ; var dd : Sequence := Sequence{ 1 } ; if p = 0 then ( execute ((1) : dd) ) else skip ; var lim : double := (10)->pow(12) ; while (dd)->size() < 40 & (dd->last() * 2->compareTo(lim)) <= 0 do ( execute ((dd->last() * 2) : dd)) ; execute (40)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name dd))))))))->display() ; for _tuple : xy do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); var ans : String := "" ; for d : dd(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if ((x)->abs()->compareTo((y)->abs())) > 0 then ( if x > 0 then ( x := x - d ; ans := ans + "R" ) else ( x := x + d ; ans := ans + "L" ) ) else ( if y > 0 then ( y := y - d ; ans := ans + "U" ) else ( y := y + d ; ans := ans + "D" ) )) ; execute (ans(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->display()); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LLI(rows_number : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows_number-1)->select(_anon | true)->collect(_anon | (LI())); operation SI() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation parity() : OclAny pre: true post: true activity: var res : int := (xy->first())->sum() mod 2 ; for _tuple : xy do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if (x + y) mod 2 /= res then ( return -1 ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(x,y,d,m): ret="" dx=[-1,0,0,1] dy=[0,-1,1,0] mode=['R','U','D','L'] for i in range(m): dir=0 t=abs(x+d[i]*dx[0])+abs(y+d[i]*dy[0]) for j in range(4): nx=x+d[i]*dx[j] ny=y+d[i]*dy[j] if abs(nx)+abs(ny)union(Sequence{0}->union(Sequence{0}->union(Sequence{ 1 }))) ; var dy : Sequence := Sequence{0}->union(Sequence{-1}->union(Sequence{1}->union(Sequence{ 0 }))) ; var mode : Sequence := Sequence{'R'}->union(Sequence{'U'}->union(Sequence{'D'}->union(Sequence{ 'L' }))) ; for i : Integer.subrange(0, m-1) do ( var dir : int := 0 ; var t : double := (x + d[i+1] * dx->first())->abs() + (y + d[i+1] * dy->first())->abs() ; for j : Integer.subrange(0, 4-1) do ( var nx : OclAny := x + d[i+1] * dx[j+1] ; var ny : OclAny := y + d[i+1] * dy[j+1] ; if ((nx)->abs() + (ny)->abs()->compareTo(t)) < 0 then ( t := (nx)->abs() + (ny)->abs() ; dir := j ) else skip) ; x := x + d[i+1] * dx[dir+1] ; y := y + d[i+1] * dy[dir+1] ; ret := ret + mode[dir+1]) ; execute (ret)->display(); operation main() : OclAny pre: true post: true activity: m := 34 ; var X : OclAny := null; var Y : OclAny := null; Sequence{X,Y,d} := Sequence{Sequence{},Sequence{},Sequence{}} ; for i : Integer.subrange(0 + 1, 32)->reverse() do ( d := d + Sequence{ (2)->pow(i) }) ; d := d + Sequence{ 1 } ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var even : OclAny := null; var odd : OclAny := null; Sequence{even,odd} := Sequence{0,0} ; for i : Integer.subrange(0, N-1) do ( Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; X := X + Sequence{ x }; Y := Y + Sequence{ y } ; if ((x)->abs() + (y)->abs()) mod 2 = 0 then ( even := even + 1 ) else ( odd := odd + 1 )) ; if even & odd then ( execute (-1)->display() ; return 0 ) else skip ; if odd then ( m := m - 1 ) else ( d := d + Sequence{ 1 } ) ; execute (m)->display() ; execute (StringLib.sumStringsWithSeparator(((d)->collect( _x | (OclType["String"])->apply(_x) )), " "))->display() ; for i : Integer.subrange(0, N-1) do ( solve(X[i+1], Y[i+1], d, m)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inf=float('inf') n=int(input()) coordinates=[tuple(map(int,input().split()))for _ in range(n)] parity=None can_make=True for coordinate in coordinates : if parity is None : parity=sum(coordinate)% 2 else : if parity!=sum(coordinate)% 2 : can_make=False break if not can_make : print(-1) exit() m=40 if parity==0 : d=[pow(2,i)for i in range(39)]+[1] else : d=[pow(2,i)for i in range(40)] d.sort(reverse=True) ans=[] for x,y in coordinates : curx,cury=0,0 ops='' for dd in d : dist=inf op='' det_dx,det_dy=0,0 for c,(dx,dy)in zip('LRDU',[(-1,0),(1,0),(0,-1),(0,1)]): t=abs(curx+dx*dd-x)+abs(cury+dy*dd-y) if dist>t : op=c dist=t det_dx=dx det_dy=dy ops+=op curx+=det_dx*dd cury+=det_dy*dd if(curx,cury)==(x,y): ans.append(ops) else : print(-1) print(m) print(*d) print(*ans,sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var coordinates : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var parity : OclAny := null ; var can_make : boolean := true ; for coordinate : coordinates do ( if parity <>= null then ( parity := (coordinate)->sum() mod 2 ) else ( if parity /= (coordinate)->sum() mod 2 then ( can_make := false ; break ) else skip )) ; if not(can_make) then ( execute (-1)->display() ; exit() ) else skip ; var m : int := 40 ; if parity = 0 then ( var d : Sequence := Integer.subrange(0, 39-1)->select(i | true)->collect(i | ((2)->pow(i)))->union(Sequence{ 1 }) ) else ( d := Integer.subrange(0, 40-1)->select(i | true)->collect(i | ((2)->pow(i))) ) ; d := d->sort() ; var ans : Sequence := Sequence{} ; for _tuple : coordinates do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); var curx : OclAny := null; var cury : OclAny := null; Sequence{curx,cury} := Sequence{0,0} ; var ops : String := '' ; for dd : d do ( var dist : double := Math_PINFINITY ; var op : String := '' ; var det_dx : OclAny := null; var det_dy : OclAny := null; Sequence{det_dx,det_dy} := Sequence{0,0} ; for _tuple : Integer.subrange(1, 'LRDU'->size())->collect( _indx | Sequence{'LRDU'->at(_indx), Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{0, -1}}->union(Sequence{ Sequence{0, 1} })))->at(_indx)} ) do (var _indx : int := 1; var c : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{dx, dy} : OclAny := _tuple->at(_indx); var t : double := (curx + dx * dd - x)->abs() + (cury + dy * dd - y)->abs() ; if (dist->compareTo(t)) > 0 then ( op := c ; dist := t ; var det_dx : OclAny := dx ; var det_dy : OclAny := dy ) else skip) ; ops := ops + op ; curx := curx + det_dx * dd ; cury := cury + det_dy * dd) ; if Sequence{curx, cury} = Sequence{x, y} then ( execute ((ops) : ans) ) else ( execute (-1)->display() )) ; execute (m)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name d))))))))->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) place=[tuple(map(int,input().split()))for _ in range(n)] m=0 def bitlist(x): ret=[0]*31 for i in reversed(range(31)): if x>0 : x-=1<toInteger() ; var place : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var m : int := 0 ; skip ; var pre : int := (place->first()->first() + place->first()[1+1] + 1) mod 2 ; for _tuple : place do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if (x + y + 1) mod 2 /= pre then ( execute (-1)->display() ; exit() ) else skip) ; execute (31 + pre)->display() ; if pre then ( execute (1)->display() ) else skip ; for i : (Integer.subrange(0, 31-1))->reverse() do ( execute (1 * (2->pow(i)))->display()) ; execute (->display() ; for _tuple : place do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); var u : OclAny := x + y ; var v : double := x - y ; if pre then ( u := u - 1 ; v := v - 1 ) else skip ; var ubit : OclAny := bitlist(u) ; var vbit : OclAny := bitlist(v) ; if pre then ( execute ('R')->display() ) else skip ; for i : (Integer.subrange(0, 31-1))->reverse() do ( if ubit[i+1] = 1 & vbit[i+1] = 1 then ( execute ('R')->display() ) else (if ubit[i+1] = 1 & vbit[i+1] = -1 then ( execute ('U')->display() ) else (if ubit[i+1] = -1 & vbit[i+1] = -1 then ( execute ('L')->display() ) else ( execute ('D')->display() ) ) ) ) ; execute (->display()); operation bitlist(x : OclAny) : OclAny pre: true post: true activity: var ret : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 31) ; for i : (Integer.subrange(0, 31-1))->reverse() do ( if x > 0 then ( x := x - 1 * (2->pow(i)) ; ret[i+1] := 1 ) else ( x := x + 1 * (2->pow(i)) ; ret[i+1] := -1 )) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rightmostNonZero(a,n): c5=0 for i in range(n): while(a[i]>0 and a[i]% 5==0): a[i]//=5 c5+=1 for i in range(n): while(c5 and a[i]>0 and(a[i]& 1)==0): a[i]>>=1 c5-=1 ans=1 for i in range(n): ans=(ans*a[i]% 10)% 10 if(c5): ans=(ans*5)% 10 if(ans): return ans return-1 a=[7,42,11,64] n=len(a) print(rightmostNonZero(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{7}->union(Sequence{42}->union(Sequence{11}->union(Sequence{ 64 }))) ; n := (a)->size() ; execute (rightmostNonZero(a, n))->display(); operation rightmostNonZero(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var c5 : int := 0 ; for i : Integer.subrange(0, n-1) do ( while (a[i+1] > 0 & a[i+1] mod 5 = 0) do ( a[i+1] := a[i+1] div 5 ; c5 := c5 + 1)) ; for i : Integer.subrange(0, n-1) do ( while (c5 & a[i+1] > 0 & (MathLib.bitwiseAnd(a[i+1], 1)) = 0) do ( a[i+1] := a[i+1] div (2->pow(1)) ; c5 := c5 - 1)) ; var ans : int := 1 ; for i : Integer.subrange(0, n-1) do ( ans := (ans * a[i+1] mod 10) mod 10) ; if (c5) then ( ans := (ans * 5) mod 10 ) else skip ; if (ans) then ( return ans ) else skip ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,m,k,l=map(int,input().split()) x=(k+l+m-1)//m if m*x<=n : print(x) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; var l : OclAny := null; Sequence{n,m,k,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : int := (k + l + m - 1) div m ; if (m * x->compareTo(n)) <= 0 then ( execute (x)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil n=int(input()) x=list(map(int,input().split())) x.sort() flag=False for i in range(n-2): a=x[i] b=x[i+1] c=x[i+2] if(a+b>c and b+c>a and a+c>b): flag=True break if(flag): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; x := x->sort() ; var flag : boolean := false ; for i : Integer.subrange(0, n - 2-1) do ( var a : OclAny := x[i+1] ; var b : OclAny := x[i + 1+1] ; var c : OclAny := x[i + 2+1] ; if ((a + b->compareTo(c)) > 0 & (b + c->compareTo(a)) > 0 & (a + c->compareTo(b)) > 0) then ( flag := true ; break ) else skip) ; if (flag) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input(); a=sorted(map(int,input().split())) print(("NO","YES")[any(x+y>z for x,y,z in zip(a,a[1 :],a[2 :]))]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input(); var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; execute (Sequence{"NO", "YES"}->select(((argument (test (logical_test (comparison (comparison (expr (expr (atom (name x))) + (expr (atom (name y))))) > (comparison (expr (atom (name z))))))) (comp_for for (exprlist (expr (atom (name x))) , (expr (atom (name y))) , (expr (atom (name z)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) :)) ])))))))) )))))))))->exists( _x | _x = true )))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,Z,W=list(map(int,input().split())) A=[W]+list(map(int,input().split())) X=[0]*(N+1) Y=[1e9]*(N+1) for i in range(N,0,-1): X[i]=max([abs(A[i-1]-A[N])]+[Y[j]for j in range(i+1,N+1)]) Y[i]=min([abs(A[i-1]-A[N])]+[X[j]for j in range(i+1,N+1)]) print(X[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var Z : OclAny := null; var W : OclAny := null; Sequence{N,Z,W} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var A : Sequence := Sequence{ W }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var X : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; var Y : Sequence := MatrixLib.elementwiseMult(Sequence{ ("1e9")->toReal() }, (N + 1)) ; for i : Integer.subrange(0 + 1, N)->reverse() do ( X[i+1] := (Sequence{ (A[i - 1+1] - A[N+1])->abs() }->union(Integer.subrange(i + 1, N + 1-1)->select(j | true)->collect(j | (Y[j+1]))))->max() ; Y[i+1] := (Sequence{ (A[i - 1+1] - A[N+1])->abs() }->union(Integer.subrange(i + 1, N + 1-1)->select(j | true)->collect(j | (X[j+1]))))->min()) ; execute (X[1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=sorted(list(map(int,input().split()))) for i in range(0,len(l)-2): if l[i]+l[i+1]>l[i+2]: print("YES") exit() else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)))))))) )))) - (expr (atom (number (integer 2)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))))) > (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 2)))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name exit)) (trailer (arguments ( )))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) li=list(sorted(map(int,input().split()))) flag=False for i in range(n-2): if li[i]+li[i+1]>li[i+2]: flag=True ; break print('YES' if flag else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort()) ; var flag : boolean := false ; for i : Integer.subrange(0, n - 2-1) do ( if (li[i+1] + li[i + 1+1]->compareTo(li[i + 2+1])) > 0 then ( flag := true; break ) else skip) ; execute (if flag then 'YES' else 'NO' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=sorted([int(i)for i in input().split()],reverse=True) ans='NO' for i in range(n-2): if a[i]toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var ans : String := 'NO' ; for i : Integer.subrange(0, n - 2-1) do ( if (a[i+1]->compareTo(a[i + 1+1] + a[i + 2+1])) < 0 then ( ans := 'YES' ; break ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isDivisibleRec(x,a,b,n): if(x>n): return False if(n % x==0): return True return(isDivisibleRec(x*10+a,a,b,n)or isDivisibleRec(x*10+b,a,b,n)) def isDivisible(a,b,n): return(isDivisibleRec(a,a,b,n)or isDivisibleRec(b,a,b,n)) a=3 ; b=5 ; n=53 ; if(isDivisible(a,b,n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 3; b := 5; n := 53; ; if (isDivisible(a, b, n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isDivisibleRec(x : OclAny, a : OclAny, b : OclAny, n : OclAny) : OclAny pre: true post: true activity: if ((x->compareTo(n)) > 0) then ( return false ) else skip ; if (n mod x = 0) then ( return true ) else skip ; return (isDivisibleRec(x * 10 + a, a, b, n) or isDivisibleRec(x * 10 + b, a, b, n)); operation isDivisible(a : OclAny, b : OclAny, n : OclAny) : OclAny pre: true post: true activity: return (isDivisibleRec(a, a, b, n) or isDivisibleRec(b, a, b, n)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : h,w,n=map(int,input().split()) if h==0 : break mapp=[] for i in range(h): hoge=list(map(int,input().split())) hoge.append(0) mapp.append(hoge) mapp.append([0]*(w+1)) n-=1 nmap=[[0]*(w+1)for _ in range(h+1)] nmap[0][0]=n for i in range(h): for j in range(w): nmap[i+1][j]+=(nmap[i][j]+1-mapp[i][j])//2 nmap[i][j+1]+=(nmap[i][j]+mapp[i][j])//2 mapp[i][j]=(nmap[i][j]+mapp[i][j])% 2 i,j=0,0 while icollect( _x | (OclType["int"])->apply(_x) ) ; if h = 0 then ( break ) else skip ; var mapp : Sequence := Sequence{} ; for i : Integer.subrange(0, h-1) do ( var hoge : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((0) : hoge) ; execute ((hoge) : mapp)) ; execute ((MatrixLib.elementwiseMult(Sequence{ 0 }, (w + 1))) : mapp) ; n := n - 1 ; var nmap : Sequence := Integer.subrange(0, h + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (w + 1)))) ; nmap->first()->first() := n ; for i : Integer.subrange(0, h-1) do ( for j : Integer.subrange(0, w-1) do ( nmap[i + 1+1][j+1] := nmap[i + 1+1][j+1] + (nmap[i+1][j+1] + 1 - mapp[i+1][j+1]) div 2 ; nmap[i+1][j + 1+1] := nmap[i+1][j + 1+1] + (nmap[i+1][j+1] + mapp[i+1][j+1]) div 2 ; mapp[i+1][j+1] := (nmap[i+1][j+1] + mapp[i+1][j+1]) mod 2)) ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,0} ; while (i->compareTo(h)) < 0 & (j->compareTo(w)) < 0 do ( if mapp[i+1][j+1] = 0 then ( i := i + 1 ) else ( j := j + 1 )) ; execute (i + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): while True : import sys input=sys.stdin.readline h,w,n=map(int,input().split()) if h==0 : break grid=[list(map(int,input().split()))for _ in[0]*h] dp=[[0]*(w+1)for _ in[0]*(h+1)] dp[0][0]=n-1 for k in range(h+w-1): for i in range(max(0,k-w+1),min(h,k+1)): j=k-i x=dp[i][j] if grid[i][j]==1 : dp[i+1][j]+=x//2 dp[i][j+1]+=x-x//2 else : dp[i][j+1]+=x//2 dp[i+1][j]+=x-x//2 for i in range(h): for j in range(w): dp[i][j]=(grid[i][j]+dp[i][j])% 2 i,j=1,1 while True : if dp[i-1][j-1]==1 : j+=1 else : i+=1 if i>h or j>w : break print(i,j) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: while true do ( skip ; var input : OclAny := (OclFile["System.in"]).readline ; var h : OclAny := null; var w : OclAny := null; var n : OclAny := null; Sequence{h,w,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if h = 0 then ( break ) else skip ; var grid : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, h)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (h + 1))->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (w + 1)))) ; dp->first()->first() := n - 1 ; for k : Integer.subrange(0, h + w - 1-1) do ( for i : Integer.subrange(Set{0, k - w + 1}->max(), Set{h, k + 1}->min()-1) do ( var j : double := k - i ; var x : OclAny := dp[i+1][j+1] ; if grid[i+1][j+1] = 1 then ( dp[i + 1+1][j+1] := dp[i + 1+1][j+1] + x div 2 ; dp[i+1][j + 1+1] := dp[i+1][j + 1+1] + x - x div 2 ) else ( dp[i+1][j + 1+1] := dp[i+1][j + 1+1] + x div 2 ; dp[i + 1+1][j+1] := dp[i + 1+1][j+1] + x - x div 2 ))) ; for i : Integer.subrange(0, h-1) do ( for j : Integer.subrange(0, w-1) do ( dp[i+1][j+1] := (grid[i+1][j+1] + dp[i+1][j+1]) mod 2)) ; var i : OclAny := null; Sequence{i,j} := Sequence{1,1} ; while true do ( if dp[i - 1+1][j - 1+1] = 1 then ( j := j + 1 ) else ( i := i + 1 ) ; if (i->compareTo(h)) > 0 or (j->compareTo(w)) > 0 then ( break ) else skip) ; execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : h,w,n=map(int,input().split()) if not h : break sss=[[1 if s=="1" else 0 for s in input().split()]for i in range(h)] dp=[[0 for i in range(w+1)]for j in range(h+1)] dp[0][0]=n-1 for x in range(h): for y in range(w): a=dp[x][y] if sss[x][y]: if a % 2 : dp[x+1][y]+=a//2 dp[x][y+1]+=a//2+1 else : dp[x+1][y]+=a//2 dp[x][y+1]+=a//2 else : if a % 2 : dp[x+1][y]+=a//2+1 dp[x][y+1]+=a//2 else : dp[x+1][y]+=a//2 dp[x][y+1]+=a//2 sss[x][y]=(sss[x][y]+dp[x][y])% 2 x=y=0 while xcollect( _x | (OclType["int"])->apply(_x) ) ; if not(h) then ( break ) else skip ; var sss : Sequence := Integer.subrange(0, h-1)->select(i | true)->collect(i | (input().split()->select(s | true)->collect(s | (if s = "1" then 1 else 0 endif)))) ; var dp : Sequence := Integer.subrange(0, h + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, w + 1-1)->select(i | true)->collect(i | (0)))) ; dp->first()->first() := n - 1 ; for x : Integer.subrange(0, h-1) do ( for y : Integer.subrange(0, w-1) do ( var a : OclAny := dp[x+1][y+1] ; if sss[x+1][y+1] then ( if a mod 2 then ( dp[x + 1+1][y+1] := dp[x + 1+1][y+1] + a div 2 ; dp[x+1][y + 1+1] := dp[x+1][y + 1+1] + a div 2 + 1 ) else ( dp[x + 1+1][y+1] := dp[x + 1+1][y+1] + a div 2 ; dp[x+1][y + 1+1] := dp[x+1][y + 1+1] + a div 2 ) ) else ( if a mod 2 then ( dp[x + 1+1][y+1] := dp[x + 1+1][y+1] + a div 2 + 1 ; dp[x+1][y + 1+1] := dp[x+1][y + 1+1] + a div 2 ) else ( dp[x + 1+1][y+1] := dp[x + 1+1][y+1] + a div 2 ; dp[x+1][y + 1+1] := dp[x+1][y + 1+1] + a div 2 ) ) ; sss[x+1][y+1] := (sss[x+1][y+1] + dp[x+1][y+1]) mod 2)) ; var x : OclAny := 0; var y : int := 0 ; while (x->compareTo(h)) < 0 & (y->compareTo(w)) < 0 do ( if sss[x+1][y+1] then ( y := y + 1 ) else ( x := x + 1 )) ; execute (x + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): while True : h,w,n=map(int,input().split()) if not h : break sss=[[1 if s=="1" else 0 for s in input().split()]for i in range(h)] dp=[[0 for i in range(w+1)]for j in range(h+1)] dp[0][0]=n-1 for x in range(h): for y in range(w): a=dp[x][y] b=sss[x][y] if b : if a % 2 : dp[x+1][y]+=a//2 dp[x][y+1]+=a//2+1 else : dp[x+1][y]+=a//2 dp[x][y+1]+=a//2 else : if a % 2 : dp[x+1][y]+=a//2+1 dp[x][y+1]+=a//2 else : dp[x+1][y]+=a//2 dp[x][y+1]+=a//2 sss[x][y]=(a+b)% 2 x=y=0 while xcollect( _x | (OclType["int"])->apply(_x) ) ; if not(h) then ( break ) else skip ; var sss : Sequence := Integer.subrange(0, h-1)->select(i | true)->collect(i | (input().split()->select(s | true)->collect(s | (if s = "1" then 1 else 0 endif)))) ; var dp : Sequence := Integer.subrange(0, h + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, w + 1-1)->select(i | true)->collect(i | (0)))) ; dp->first()->first() := n - 1 ; for x : Integer.subrange(0, h-1) do ( for y : Integer.subrange(0, w-1) do ( var a : OclAny := dp[x+1][y+1] ; var b : OclAny := sss[x+1][y+1] ; if b then ( if a mod 2 then ( dp[x + 1+1][y+1] := dp[x + 1+1][y+1] + a div 2 ; dp[x+1][y + 1+1] := dp[x+1][y + 1+1] + a div 2 + 1 ) else ( dp[x + 1+1][y+1] := dp[x + 1+1][y+1] + a div 2 ; dp[x+1][y + 1+1] := dp[x+1][y + 1+1] + a div 2 ) ) else ( if a mod 2 then ( dp[x + 1+1][y+1] := dp[x + 1+1][y+1] + a div 2 + 1 ; dp[x+1][y + 1+1] := dp[x+1][y + 1+1] + a div 2 ) else ( dp[x + 1+1][y+1] := dp[x + 1+1][y+1] + a div 2 ; dp[x+1][y + 1+1] := dp[x+1][y + 1+1] + a div 2 ) ) ; sss[x+1][y+1] := (a + b) mod 2)) ; var x : OclAny := 0; var y : int := 0 ; while (x->compareTo(h)) < 0 & (y->compareTo(w)) < 0 do ( if sss[x+1][y+1] then ( y := y + 1 ) else ( x := x + 1 )) ; execute (x + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k,l=(int(x)for x in input().split()) q,r=divmod((l+k),m) v=(q+1)if r else q print(v if m*v<=n else-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; var l : OclAny := null; Sequence{n,m,k,l} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var q : OclAny := null; var r : OclAny := null; Sequence{q,r} := Sequence{((l + k) div m), ((l + k) mod m)} ; var v : OclAny := if r then (q + 1) else q endif ; execute (if (m * v->compareTo(n)) <= 0 then v else -1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): while True : h,w,n=map(int,input().split()) if not h : break mp=[[int(s)for s in input().split()]for i in range(h)] dp=[[0 for i in range(w+1)]for j in range(h+1)] dp[0][0]=n-1 for x in range(h): dpx=dp[x] dpxp=dp[x+1] mpx=mp[x] for y in range(w): a=dpx[y] b=mpx[y] if b : if a % 2 : dpxp[y]+=a//2 dpx[y+1]+=a//2+1 else : dpxp[y]+=a//2 dpx[y+1]+=a//2 else : if a % 2 : dpxp[y]+=a//2+1 dpx[y+1]+=a//2 else : dpxp[y]+=a//2 dpx[y+1]+=a//2 mpx[y]=(a+b)% 2 x=y=0 while xcollect( _x | (OclType["int"])->apply(_x) ) ; if not(h) then ( break ) else skip ; var mp : Sequence := Integer.subrange(0, h-1)->select(i | true)->collect(i | (input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())))) ; var dp : Sequence := Integer.subrange(0, h + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, w + 1-1)->select(i | true)->collect(i | (0)))) ; dp->first()->first() := n - 1 ; for x : Integer.subrange(0, h-1) do ( var dpx : OclAny := dp[x+1] ; var dpxp : OclAny := dp[x + 1+1] ; var mpx : OclAny := mp[x+1] ; for y : Integer.subrange(0, w-1) do ( var a : OclAny := dpx[y+1] ; var b : OclAny := mpx[y+1] ; if b then ( if a mod 2 then ( dpxp[y+1] := dpxp[y+1] + a div 2 ; dpx[y + 1+1] := dpx[y + 1+1] + a div 2 + 1 ) else ( dpxp[y+1] := dpxp[y+1] + a div 2 ; dpx[y + 1+1] := dpx[y + 1+1] + a div 2 ) ) else ( if a mod 2 then ( dpxp[y+1] := dpxp[y+1] + a div 2 + 1 ; dpx[y + 1+1] := dpx[y + 1+1] + a div 2 ) else ( dpxp[y+1] := dpxp[y+1] + a div 2 ; dpx[y + 1+1] := dpx[y + 1+1] + a div 2 ) ) ; mpx[y+1] := (a + b) mod 2)) ; var x : OclAny := 0; var y : int := 0 ; while (x->compareTo(h)) < 0 & (y->compareTo(w)) < 0 do ( if mp[x+1][y+1] then ( y := y + 1 ) else ( x := x + 1 )) ; execute (x + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mt=[] high=[0,0,0] for i in range(10): mt.append(int(input())) if mt[i]>high[0]: high=[mt[i]]+high[: 2] elif mt[i]>high[1]: high=[high[0]]+[mt[i]]+[high[1]] elif mt[i]>high[2]: high=high[: 2]+[mt[i]] print('\n'.join(map(str,high))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mt : Sequence := Sequence{} ; var high : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) ; for i : Integer.subrange(0, 10-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : mt) ; if (mt[i+1]->compareTo(high->first())) > 0 then ( high := Sequence{ mt[i+1] }->union(high.subrange(1,2)) ) else (if (mt[i+1]->compareTo(high[1+1])) > 0 then ( high := Sequence{ high->first() }->union(Sequence{ mt[i+1] })->union(Sequence{ high[1+1] }) ) else (if (mt[i+1]->compareTo(high[2+1])) > 0 then ( high := high.subrange(1,2)->union(Sequence{ mt[i+1] }) ) else skip ) ) ) ; execute (StringLib.sumStringsWithSeparator(((high)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countToMake0lternate(s): result=0 for i in range(len(s)-1): if(s[i]==s[i+1]): result+=1 return result if __name__=="__main__" : print(countToMake0lternate("000111")) print(countToMake0lternate("11111")) print(countToMake0lternate("01010101")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (countToMake0lternate("000111"))->display() ; execute (countToMake0lternate("11111"))->display() ; execute (countToMake0lternate("01010101"))->display() ) else skip; operation countToMake0lternate(s : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; for i : Integer.subrange(0, (s)->size() - 1-1) do ( if (s[i+1] = s[i + 1+1]) then ( result := result + 1 ) else skip) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while(t>0): n,x=map(int,input().split()) print(x*2) t=t-1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (t > 0) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (x * 2)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: print(2*int(s.split()[1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( execute (2 * ("" + ((s.split()[1+1])))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for i in range(T): print(int(input().split()[1])*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, T-1) do ( execute (("" + ((input().split()[1+1])))->toInteger() * 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=list(map(int,input().split())) print(2*n[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (2 * n[1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- queries=int(input()) for i in range(queries): (n,x)=map(int,input().split(' ')) print(x*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var queries : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, queries-1) do ( ; var Sequence{n, x} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; execute (x * 2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findArea(a,b,c): if(a<0 or b<0 or c<0 or(a+b<=c)or(a+c<=b)or(b+c<=a)): print('Not a valid trianglen') return s=(a+b+c)/2 area=(s*(s-a)*(s-b)*(s-c))**0.5 print('Area of a traingle is %f' % area) a=3.0 b=4.0 c=5.0 findArea(a,b,c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 3.0 ; b := 4.0 ; c := 5.0 ; findArea(a, b, c); operation findArea(a : OclAny, b : OclAny, c : OclAny) pre: true post: true activity: if (a < 0 or b < 0 or c < 0 or ((a + b->compareTo(c)) <= 0) or ((a + c->compareTo(b)) <= 0) or ((b + c->compareTo(a)) <= 0)) then ( execute ('Not a valid trianglen')->display() ; return ) else skip ; var s : double := (a + b + c) / 2 ; var area : double := ((s * (s - a) * (s - b) * (s - c)))->pow(0.5) ; execute (StringLib.format('Area of a traingle is %f',area))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,l=map(int,input().split()) a=list(map(int,input().split())) ma=0 midx=0 for i in range(n-1): if mama : print('Impossible') else : print('Possible') for i in range(midx): print(i+1) for i in range(n-1,midx,-1): print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; Sequence{n,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ma : int := 0 ; var midx : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if (ma->compareTo(a[i+1] + a[i + 1+1])) < 0 then ( midx := i ; ma := a[i+1] + a[i + 1+1] ) else skip) ; if (l->compareTo(ma)) > 0 then ( execute ('Impossible')->display() ) else ( execute ('Possible')->display() ; for i : Integer.subrange(0, midx-1) do ( execute (i + 1)->display()) ; for i : Integer.subrange(midx + 1, n - 1)->reverse() do ( execute (i)->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(): input=sys.stdin.readline N,L=map(int,input().split()) A=[int(a)for a in input().split()] for i in range(N-1): if A[i]+A[i+1]>=L : print("Possible") for k in range(i): print(k+1) for k in reversed(range(i+1,N-1)): print(k+1) print(i+1) break else : print("Impossible") return 0 if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation solve() : OclAny pre: true post: true activity: var input : OclAny := (OclFile["System.in"]).readline ; var N : OclAny := null; var L : OclAny := null; Sequence{N,L} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name N))) - (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))))) >= (comparison (expr (atom (name L))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Possible"))))))) )))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name k)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))) : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name k))) + (expr (atom (number (integer 1)))))))))) )))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name k)))) in (testlist (test (logical_test (comparison (expr (atom (name reversed)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name N))) - (expr (atom (number (integer 1)))))))))) ))))))))) )))))))) : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name k))) + (expr (atom (number (integer 1)))))))))) )))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Impossible"))))))) )))))))))))))) ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M,k,L=map(int,input().split()) X=0 X=(L+k+M-1)//M if(X*M)>N : print(-1) else : print(X) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; var k : OclAny := null; var L : OclAny := null; Sequence{N,M,k,L} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var X : int := 0 ; X := (L + k + M - 1) div M ; if ((X * M)->compareTo(N)) > 0 then ( execute (-1)->display() ) else ( execute (X)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inputList=[] while True : try : num=int(input()) except EOFError : break inputList.append(num) inputList.sort() length=len(inputList) for i in range(3): print(inputList[length-i-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inputList : Sequence := Sequence{} ; while true do ( try ( var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))) ; execute ((num) : inputList)) ; inputList := inputList->sort() ; var length : int := (inputList)->size() ; for i : Integer.subrange(0, 3-1) do ( execute (inputList[length - i - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- yes="Possible" no="Impossible" N,L=map(int,input().split()) a=[0]+list(map(int,input().split())) c=0 Mi=-1 for i in range(1,N): if ccollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var c : int := 0 ; var Mi : int := -1 ; for i : Integer.subrange(1, N-1) do ( if (c->compareTo(a[i+1] + a[i + 1+1])) < 0 then ( c := Set{c, a[i+1] + a[i + 1+1]}->max() ; Mi := i ) else skip) ; if (c->compareTo(L)) < 0 then ( execute (no)->display() ) else ( execute (yes)->display() ; for i : Integer.subrange(1, N-1) do ( if i /= Mi then ( execute (i)->display() ) else ( break )) ; for i : (Integer.subrange(1, N-1))->reverse() do ( if i /= Mi then ( execute (i)->display() ) else ( break )) ; execute (Mi)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,l,*a=map(int,open(0).read().split()) i=0 for a,b in zip(a,a[1 :]): i+=1 ; a+b>=l>exit(print('Possible',*range(1,i),*range(n-1,i-1,-1))) print('Impossible') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; var a : OclAny := null; Sequence{n,l,a} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var i : int := 0 ; for _tuple : Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), a->tail()->at(_indx)} ) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); i := i + 1;(comparison (comparison (comparison (expr (expr (atom (name a))) + (expr (atom (name b))))) >= (comparison (expr (atom (name l))))) > (comparison (expr (atom (name exit)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'Possible')))))) , (argument * (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))) , (argument * (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ))))))))) ))))))))) ))))))) ; execute ('Impossible')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,L=(int(i)for i in input().split()) a=[int(i)for i in input().split()] P="Possible" for i in range(N-1): if a[i]+a[i+1]>=L : start=i break else : P="Impossible" print(P) if P=="Possible" : ans=[start] if start>0 : ans+=reversed(list(range(start))) if start!=N-2 : ans+=list(range(start+1,N-1)) ans.reverse() for a in ans : print(a+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var L : OclAny := null; Sequence{N,L} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var P : String := "Possible" ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name N))) - (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))))) >= (comparison (expr (atom (name L))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name start)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name P)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom "Impossible")))))))))))))) ; execute (P)->display() ; if P = "Possible" then ( var ans : Sequence := Sequence{ start } ; if start > 0 then ( ans := ans + ((Integer.subrange(0, start-1)))->reverse() ) else skip ; if start /= N - 2 then ( ans := ans + (Integer.subrange(start + 1, N - 1-1)) ) else skip ; ans := ans->reverse() ; for a : ans do ( execute (MatrixLib.elementwiseAdd(a, 1))->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def SieveOfEratosthenes(): MAX=1000001 prime=[True for i in range(MAX+1)] prime[1]=False for p in range(2,int(sqrt(MAX))+1,1): if(prime[p]==True): for i in range(p*2,MAX+1,p): prime[i]=False return prime def find_Prime(sum): prime=SieveOfEratosthenes() i=int(sum/2) while(i>1): if(prime[i]and prime[sum-i]): print(i,(sum-i)) return i-=1 print("Cannot be represented as sum","of two primes") if __name__=='__main__' : sum=1002 find_Prime(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( sum := 1002 ; find_Prime(sum) ) else skip; operation SieveOfEratosthenes() : OclAny pre: true post: true activity: var MAX : int := 1000001 ; var prime : Sequence := Integer.subrange(0, MAX + 1-1)->select(i | true)->collect(i | (true)) ; prime[1+1] := false ; for p : Integer.subrange(2, ("" + ((sqrt(MAX))))->toInteger() + 1-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (prime[p+1] = true) then ( for i : Integer.subrange(p * 2, MAX + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip) ; return prime; operation find_Prime(sum : OclAny) pre: true post: true activity: prime := SieveOfEratosthenes() ; var i : int := ("" + ((sum / 2)))->toInteger() ; while (i > 1) do ( if (prime[i+1] & prime[sum - i+1]) then ( execute (i)->display() ; return ) else skip ; i := i - 1) ; execute ("Cannot be represented as sum")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c='^>v<' a,b=map(c.index,input().split()) n=int(input()) print([['ccw','cw'][(a+n)% 4==b],'undefined'][abs(a-b)% 2==0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : String := '^>v<' ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (c.index)->apply(_x) ) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (Sequence{Sequence{'ccw'}->union(Sequence{ 'cw' })->select((a + n) mod 4 = b)}->union(Sequence{ 'undefined' })->select((a - b)->abs() mod 2 = 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c='^>v<' a,b=map(c.index,input().split()) n=int(input()) print([['ccw','cw'][(a+n)% 4==b],'undefined'][abs(a-b)% 2==0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : String := '^>v<' ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (c.index)->apply(_x) ) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (Sequence{Sequence{'ccw'}->union(Sequence{ 'cw' })->select((a + n) mod 4 = b)}->union(Sequence{ 'undefined' })->select((a - b)->abs() mod 2 = 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- line=input() a,b=line.split() n=int(input()) positions={'^' : 0,'>' : 1,'v' : 2,'<' : 3} n %=4 i=(positions[a]+n)% 4==positions[b] j=(positions[a]-n)% 4==positions[b] if i and j : print('undefined') elif i : print('cw') else : print('ccw') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var line : String := (OclFile["System.in"]).readLine() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := line.split() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var positions : Map := Map{ '^' |-> 0 }->union(Map{ '>' |-> 1 }->union(Map{ 'v' |-> 2 }->union(Map{ '<' |-> 3 }))) ; n := n mod 4 ; var i : boolean := (positions[a+1] + n) mod 4 = positions[b+1] ; var j : boolean := (positions[a+1] - n) mod 4 = positions[b+1] ; if i & j then ( execute ('undefined')->display() ) else (if i then ( execute ('cw')->display() ) else ( execute ('ccw')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d,s,n='^>v<',input(),int(input()) if n % 2==0 : print("undefined") elif(d.find(s[0])+n)% 4==d.find(s[2]): print("cw") else : print("ccw") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : OclAny := null; var s : OclAny := null; var n : OclAny := null; Sequence{d,s,n} := Sequence{'^>v<',(OclFile["System.in"]).readLine(),("" + (((OclFile["System.in"]).readLine())))->toInteger()} ; if n mod 2 = 0 then ( execute ("undefined")->display() ) else (if (d->indexOf(s->first()) - 1 + n) mod 4 = d->indexOf(s[2+1]) - 1 then ( execute ("cw")->display() ) else ( execute ("ccw")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ch1,ch2=input().split() n=int(input())% 4 ch=['v','<','^','>'] _ch1=ch[(ch.index(ch1)+n)% 4] _ch2=ch[(ch.index(ch1)-n)] if _ch1==ch2 : ans='cw' elif _ch2==ch2 : ans='ccw' else : ans='undefined' if _ch1==_ch2==ch2 : ans='undefined' print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ch1 : OclAny := null; var ch2 : OclAny := null; Sequence{ch1,ch2} := input().split() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() mod 4 ; var ch : Sequence := Sequence{'v'}->union(Sequence{'<'}->union(Sequence{'^'}->union(Sequence{ '>' }))) ; var _ch1 : OclAny := ch[(ch->indexOf(ch1) - 1 + n) mod 4+1] ; var _ch2 : OclAny := ch[(ch->indexOf(ch1) - 1 - n)+1] ; if _ch1 = ch2 then ( var ans : String := 'cw' ) else (if _ch2 = ch2 then ( ans := 'ccw' ) else ( ans := 'undefined' ) ) ; if _ch1 = _ch2 & (_ch2 == ch2) then ( ans := 'undefined' ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def qui(l): num=len(l) if num==0 : return[] if num==1 : return l piv=l[0] mini=[] maxi=[] for i in range(1,len(l)): (mini if l[i]compareTo(piv)) < 0 then mini else maxi endif)); operation qui(l : OclAny) : OclAny pre: true post: true activity: var num : int := (l)->size() ; if num = 0 then ( return Sequence{} ) else skip ; if num = 1 then ( return l ) else skip ; var piv : OclAny := l->first() ; var mini : Sequence := Sequence{} ; var maxi : Sequence := Sequence{} ; for i : Integer.subrange(1, (l)->size()-1) do (suite); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def fact(n): ans=1 for i in range(1,n+1): ans=ans*i return(ans) def numberOfPossiblePallindrome(string,n): mp=dict() for i in range(n): if string[i]in mp.keys(): mp[string[i]]+=1 else : mp[string[i]]=1 k=0 num=0 den=1 fi=0 for it in mp : if(mp[it]% 2==0): fi=mp[it]//2 else : fi=(mp[it]-1)//2 k+=1 num=num+fi den=den*fact(fi) if(num!=0): num=fact(num) ans=num//den if(k!=0): ans=ans*k return(ans) string="ababab" n=len(string) print(numberOfPossiblePallindrome(string,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; string := "ababab" ; n := (string)->size() ; execute (numberOfPossiblePallindrome(string, n))->display(); operation fact(n : OclAny) : OclAny pre: true post: true activity: var ans : int := 1 ; for i : Integer.subrange(1, n + 1-1) do ( ans := ans * i) ; return (ans); operation numberOfPossiblePallindrome(string : OclAny, n : OclAny) : OclAny pre: true post: true activity: var mp : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( if (mp.keys())->includes(string[i+1]) then ( mp[string[i+1]+1] := mp[string[i+1]+1] + 1 ) else ( mp[string[i+1]+1] := 1 )) ; var k : int := 0 ; var num : int := 0 ; var den : int := 1 ; var fi : int := 0 ; for it : mp->keys() do ( if (mp[it+1] mod 2 = 0) then ( fi := mp[it+1] div 2 ) else ( fi := (mp[it+1] - 1) div 2 ; k := k + 1 ) ; num := num + fi ; den := den * fact(fi)) ; if (num /= 0) then ( num := fact(num) ) else skip ; ans := num div den ; if (k /= 0) then ( ans := ans * k ) else skip ; return (ans); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k,l=map(int,input().split()) if k+l>n : print(-1) elif m>n : print(-1) else : rm=(l+k)% m if rm is 0 : x=int((l+k)/m) else : x=int((l+k)/m)+1 if(x*m)>n : print(-1) else : print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; var l : OclAny := null; Sequence{n,m,k,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (k + l->compareTo(n)) > 0 then ( execute (-1)->display() ) else (if (m->compareTo(n)) > 0 then ( execute (-1)->display() ) else ( var rm : int := (l + k) mod m ; if rm <>= 0 then ( var x : int := ("" + (((l + k) / m)))->toInteger() ) else ( x := ("" + (((l + k) / m)))->toInteger() + 1 ) ; if ((x * m)->compareTo(n)) > 0 then ( execute (-1)->display() ) else ( execute (x)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() l=map(int,raw_input().split()) l.sort() for i in xrange(n): print(l[i]), ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var l : Sequence := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; l := l->sort() ; for i : xrange(n) do ((testlist_star_expr (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))))) ,)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function raw_input() gen=(int(s)for s in raw_input().split()) print(' '.join(str(i)for i in sorted(gen))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; raw_input() ; var gen : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name raw_input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name gen)))))))) ))))))))), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input().strip()) numbers=list(map(int,input().strip().split(" "))) numbers=numbers[: n] numbers.sort() numbers=list(map(str,numbers)) print(" ".join(numbers)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + ((input()->trim())))->toInteger() ; var numbers : Sequence := ((input()->trim().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; numbers := numbers.subrange(1,n) ; numbers := numbers->sort() ; numbers := ((numbers)->collect( _x | (OclType["String"])->apply(_x) )) ; execute (StringLib.sumStringsWithSeparator((numbers), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() lst=list(map(int,input().split())) lst.sort() a="" for i in lst : a+=str(i)+" " print(a.strip()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; lst := lst->sort() ; var a : String := "" ; for i : lst do ( a := a + ("" + ((i))) + " ") ; execute (a->trim())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def kthSmallest(arr,l,r,k): if(k>0 and k<=r-l+1): pos=partition(arr,l,r) if(pos-l==k-1): return arr[pos] if(pos-l>k-1): return kthSmallest(arr,l,pos-1,k) return kthSmallest(arr,pos+1,r,k-pos+l-1) return sys.maxsize def partition(arr,l,r): x=arr[r] i=l for j in range(l,r): if(arr[j]<=x): arr[i],arr[j]=arr[j],arr[i] i+=1 arr[i],arr[r]=arr[r],arr[i] return i if __name__=="__main__" : arr=[12,3,5,7,4,19,26] n=len(arr) k=3 ; print("K'th smallest element is",kthSmallest(arr,0,n-1,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{12}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{4}->union(Sequence{19}->union(Sequence{ 26 })))))) ; var n : int := (arr)->size() ; k := 3; ; execute ("K'th smallest element is")->display() ) else skip; operation kthSmallest(arr : OclAny, l : OclAny, r : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (k > 0 & (k->compareTo(r - l + 1)) <= 0) then ( var pos : OclAny := partition(arr, l, r) ; if (pos - l = k - 1) then ( return arr[pos+1] ) else skip ; if ((pos - l->compareTo(k - 1)) > 0) then ( return kthSmallest(arr, l, pos - 1, k) ) else skip ; return kthSmallest(arr, pos + 1, r, k - pos + l - 1) ) else skip ; return (trailer . (name maxsize)); operation partition(arr : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var x : OclAny := arr[r+1] ; var i : OclAny := l ; for j : Integer.subrange(l, r-1) do ( if ((arr[j+1]->compareTo(x)) <= 0) then ( var arr[i+1] : OclAny := null; var arr[j+1] : OclAny := null; Sequence{arr[i+1],arr[j+1]} := Sequence{arr[j+1],arr[i+1]} ; i := i + 1 ) else skip) ; var arr[i+1] : OclAny := null; var arr[r+1] : OclAny := null; Sequence{arr[i+1],arr[r+1]} := Sequence{arr[r+1],arr[i+1]} ; return i; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : m,f,r=map(int,raw_input().split()) s=m+f if m==f==r==-1 : break elif m==-1 or f==-1 or s<30 : print('F') elif s>=80 : print('A') elif 65<=s<80 : print('B') elif 50<=s<65 : print('C') elif 30<=s<50 and r>=50 : print('C') else : print('D') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var m : OclAny := null; var f : OclAny := null; var r : OclAny := null; Sequence{m,f,r} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := m + f ; if m = f & (f == r) & (r == -1) then ( break ) else (if m = -1 or f = -1 or s < 30 then ( execute ('F')->display() ) else (if s >= 80 then ( execute ('A')->display() ) else (if 65 <= s & (s < 80) then ( execute ('B')->display() ) else (if 50 <= s & (s < 65) then ( execute ('C')->display() ) else (if 30 <= s & (s < 50) & r >= 50 then ( execute ('C')->display() ) else ( execute ('D')->display() ) ) ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function import sys def judge(m,f,r): assert-1<=m<=50 assert-1<=f<=50 assert-1<=r<=100 if m==-1 or f==-1 : return 'F' total=m+f if 80<=total : return 'A' if 65<=total : return 'B' if 50<=total : return 'C' if 30<=total : return 'C' if 50<=r else 'D' return 'F' if __name__=='__main__' : for line in sys.stdin : L=[int(n)for n in line.split()] if all(n==-1 for n in L): break print(judge(*L)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( for line : OclFile["System.in"] do ( var L : Sequence := line.split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; if ((argument (test (logical_test (comparison (comparison (expr (atom (name n)))) == (comparison (expr (atom - (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name L))))))))->forAll( _x | _x = true ) then ( break ) else skip ; execute (judge((argument * (test (logical_test (comparison (expr (atom (name L)))))))))->display()) ) else skip; operation judge(m : OclAny, f : OclAny, r : OclAny) : OclAny pre: true post: true activity: assert -1 <= m & (m <= 50) do "assertion failed" ; assert -1 <= f & (f <= 50) do "assertion failed" ; assert -1 <= r & (r <= 100) do "assertion failed" ; if m = -1 or f = -1 then ( return 'F' ) else skip ; var total : OclAny := m + f ; if 80 <= total then ( return 'A' ) else skip ; if 65 <= total then ( return 'B' ) else skip ; if 50 <= total then ( return 'C' ) else skip ; if 30 <= total then ( return if 50 <= r then 'C' else 'D' endif ) else skip ; return 'F'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while(True): m,f,r=map(int,raw_input().split()) if(m==f==r==-1): break if(m==-1 or f==-1 or m+f<30): print("F") elif(m+f>=80): print("A") elif(m+f>=65): print("B") elif(m+f>=50): print("C") elif(m+f>=30): if(r>=50): print("C") else : print("D") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while (true) do ( var m : OclAny := null; var f : OclAny := null; var r : OclAny := null; Sequence{m,f,r} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (m = f & (f == r) & (r == -1)) then ( break ) else skip ; if (m = -1 or f = -1 or m + f < 30) then ( execute ("F")->display() ) else (if (m + f >= 80) then ( execute ("A")->display() ) else (if (m + f >= 65) then ( execute ("B")->display() ) else (if (m + f >= 50) then ( execute ("C")->display() ) else (if (m + f >= 30) then ( if (r >= 50) then ( execute ("C")->display() ) else ( execute ("D")->display() ) ) else skip ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : s,t,r=map(int,input().split()) if s+t+r==-3 : break Sum=s+t if s==-1 or t==-1 or Sum<30 : print("F") elif Sum>=30 and Sum<50 : if r>=50 : print("C") else : print("D") elif Sum>=50 and Sum<65 : print("C") elif Sum>=65 and Sum<80 : print("B") elif Sum>=80 : print("A") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var s : OclAny := null; var t : OclAny := null; var r : OclAny := null; Sequence{s,t,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if s + t + r = -3 then ( break ) else skip ; var Sum : OclAny := s + t ; if s = -1 or t = -1 or Sum < 30 then ( execute ("F")->display() ) else (if Sum >= 30 & Sum < 50 then ( if r >= 50 then ( execute ("C")->display() ) else ( execute ("D")->display() ) ) else (if Sum >= 50 & Sum < 65 then ( execute ("C")->display() ) else (if Sum >= 65 & Sum < 80 then ( execute ("B")->display() ) else (if Sum >= 80 then ( execute ("A")->display() ) else skip ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(i)for i in input().split()] if n==0 and m!=0 : print("Impossible") elif m==0 : print(n,n) else : print(max(n,m),max(0,n+m-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if n = 0 & m /= 0 then ( execute ("Impossible")->display() ) else (if m = 0 then ( execute (n)->display() ) else ( execute (Set{n, m}->max())->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[int(i)for i in input().split()] if(n==1): print('1') else : while(n>1): if(l==sorted(l,reverse=True)): print('1') break elif(l==sorted(l)): print(n) break elif(l[: n//2]!=sorted(l[: n//2])): l=l[n//2 :] n//=2 else : l=l[: n//2] n//=2 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if (n = 1) then ( execute ('1')->display() ) else ( while (n > 1) do ( if (l = l->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True))))))))) then ( execute ('1')->display() ; break ) else (if (l = l->sort()) then ( execute (n)->display() ; break ) else (if (l.subrange(1,n div 2) /= l.subrange(1,n div 2)->sort()) then ( l := l.subrange(n div 2+1) ; n := n div 2 ) else ( l := l.subrange(1,n div 2) ; n := n div 2 ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : m,f,r=map(int,input().split()) if m==-1 and f==-1 and r==-1 : break if m==-1 or f==-1 : print('F') elif(m+f)>=80 : print('A') elif(m+f)>=65 : print('B') elif(m+f)>=50 : print('C') elif(m+f)>=30 : if r>=50 : print('C') else : print('D') else : print('F') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var m : OclAny := null; var f : OclAny := null; var r : OclAny := null; Sequence{m,f,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if m = -1 & f = -1 & r = -1 then ( break ) else skip ; if m = -1 or f = -1 then ( execute ('F')->display() ) else (if (m + f) >= 80 then ( execute ('A')->display() ) else (if (m + f) >= 65 then ( execute ('B')->display() ) else (if (m + f) >= 50 then ( execute ('C')->display() ) else (if (m + f) >= 30 then ( if r >= 50 then ( execute ('C')->display() ) else ( execute ('D')->display() ) ) else ( execute ('F')->display() ) ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def findRoots(b,c): a=1 d=b*b-4*a*c sqrt_val=sqrt(abs(d)) if(d>0): x=-b+sqrt_val y=-b-sqrt_val root1=(x)//(2*a) root2=(y)//(2*a) if(root1+root2==-1*b and root1*root2==c): print(int(root1),",",int(root2)) else : print(-1) elif(d==0): root=-b//(2*a) if(root+root==-1*b and root*root==c): print(root,",",root) else : print(-1) else : print(-1) if __name__=='__main__' : S=5 P=6 findRoots(-S,P) S=5 P=9 findRoots(-S,P) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var S : int := 5 ; var P : int := 6 ; findRoots(-S, P) ; S := 5 ; P := 9 ; findRoots(-S, P) ) else skip; operation findRoots(b : OclAny, c : OclAny) pre: true post: true activity: var a : int := 1 ; var d : double := b * b - 4 * a * c ; var sqrt_val : OclAny := sqrt((d)->abs()) ; if (d > 0) then ( var x : OclAny := -b + sqrt_val ; var y : double := -b - sqrt_val ; var root1 : int := (x) div (2 * a) ; var root2 : int := (y) div (2 * a) ; if (root1 + root2 = -1 * b & root1 * root2 = c) then ( execute (("" + ((root1)))->toInteger())->display() ) else ( execute (-1)->display() ) ) else (if (d = 0) then ( var root : int := -b div (2 * a) ; if (root + root = -1 * b & root * root = c) then ( execute (root)->display() ) else ( execute (-1)->display() ) ) else ( execute (-1)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1e9 def minJumps(arr,N): fib=[0 for i in range(30)] fib[0]=0 fib[1]=1 for i in range(2,30): fib[i]=fib[i-1]+fib[i-2] DP=[0 for i in range(N+2)] DP[0]=0 for i in range(1,N+2): DP[i]=MAX for i in range(1,N+2): for j in range(1,30): if((arr[i-1]==1 or i==N+1)and i-fib[j]>=0): DP[i]=min(DP[i],1+DP[i-fib[j]]) if(DP[N+1]!=MAX): return DP[N+1] else : return-1 arr=[0,0,0,1,1,0,1,0,0,0,0,0] n=len(arr) print(minJumps(arr,n-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : double := ("1e9")->toReal() ; skip ; arr := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))))))))))) ; var n : int := (arr)->size() ; execute (minJumps(arr, n - 1))->display(); operation minJumps(arr : OclAny, N : OclAny) : OclAny pre: true post: true activity: var fib : Sequence := Integer.subrange(0, 30-1)->select(i | true)->collect(i | (0)) ; fib->first() := 0 ; fib[1+1] := 1 ; for i : Integer.subrange(2, 30-1) do ( fib[i+1] := fib[i - 1+1] + fib[i - 2+1]) ; var DP : Sequence := Integer.subrange(0, N + 2-1)->select(i | true)->collect(i | (0)) ; DP->first() := 0 ; for i : Integer.subrange(1, N + 2-1) do ( DP[i+1] := MAX) ; for i : Integer.subrange(1, N + 2-1) do ( for j : Integer.subrange(1, 30-1) do ( if ((arr[i - 1+1] = 1 or i = N + 1) & i - fib[j+1] >= 0) then ( DP[i+1] := Set{DP[i+1], 1 + DP[i - fib[j+1]+1]}->min() ) else skip)) ; if (DP[N + 1+1] /= MAX) then ( return DP[N + 1+1] ) else ( return -1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findPattern(n): prev=n % 2 n=n//2 while(n>0): curr=n % 2 if(curr==prev): return False prev=curr n=n//2 return True n=10 print("Yes")if(findPattern(n))else print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 10 ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Yes"))))))) )))))) if (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name findPattern)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) ))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "No"))))))) )))))))); operation findPattern(n : OclAny) : OclAny pre: true post: true activity: var prev : int := n mod 2 ; n := n div 2 ; while (n > 0) do ( var curr : int := n mod 2 ; if (curr = prev) then ( return false ) else skip ; prev := curr ; n := n div 2) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMaximum(arr,low,high): if low==high : return arr[low] if high==low+1 and arr[low]>=arr[high]: return arr[low]; if high==low+1 and arr[low]arr[mid+1]and arr[mid]>arr[mid-1]: return arr[mid] if arr[mid]>arr[mid+1]and arr[mid]union(Sequence{3}->union(Sequence{50}->union(Sequence{10}->union(Sequence{9}->union(Sequence{7}->union(Sequence{ 6 })))))) ; var n : int := (arr)->size() ; execute (StringLib.format("The maximum element is %d",findMaximum(arr, 0, n - 1)))->display(); operation findMaximum(arr : OclAny, low : OclAny, high : OclAny) : OclAny pre: true post: true activity: if low = high then ( return arr[low+1] ) else skip ; if high = low + 1 & (arr[low+1]->compareTo(arr[high+1])) >= 0 then ( return arr[low+1]; ) else skip ; if high = low + 1 & (arr[low+1]->compareTo(arr[high+1])) < 0 then ( return arr[high+1] ) else skip ; var mid : int := (low + high) div 2 ; if (arr[mid+1]->compareTo(arr[mid + 1+1])) > 0 & (arr[mid+1]->compareTo(arr[mid - 1+1])) > 0 then ( return arr[mid+1] ) else skip ; if (arr[mid+1]->compareTo(arr[mid + 1+1])) > 0 & (arr[mid+1]->compareTo(arr[mid - 1+1])) < 0 then ( return findMaximum(arr, low, mid - 1) ) else ( return findMaximum(arr, mid + 1, high) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) d=list(map(int,input().split())) life=[] for i in range(N): for j in range(i+1,N): life.append(d[i]*d[j]) print(sum(life)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var life : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(i + 1, N-1) do ( execute ((d[i+1] * d[j+1]) : life))) ; execute ((life)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin n=int(stdin.readline().rstrip()) tasty=list(map(int,stdin.readline().rstrip().split())) res=0 for i in range(n): for j in range(i+1,n): res+=tasty[i]*tasty[j] print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + ((stdin.readLine().rstrip())))->toInteger() ; var tasty : Sequence := ((stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( res := res + tasty[i+1] * tasty[j+1])) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools n=int(input()) lst=list(map(int,input().split())) ans=[] for v,k in itertools.combinations(lst,2): ans.append(v*k) print(sum(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : Sequence := Sequence{} ; for _tuple : itertools.combinations(lst, 2) do (var _indx : int := 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var k : OclAny := _tuple->at(_indx); execute ((v * k) : ans)) ; execute ((ans)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ABC143B_TakoyakiFes(): N=int(input()) d=[int(i)for i in input().split()] sum=0 for i in range(0,N-1): for j in range(i+1,N): sum+=d[i]*d[j] print(sum) def main(): ABC143B_TakoyakiFes() if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation ABC143B_TakoyakiFes() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var sum : int := 0 ; for i : Integer.subrange(0, N - 1-1) do ( for j : Integer.subrange(i + 1, N-1) do ( sum := sum + d[i+1] * d[j+1])) ; execute (sum)->display(); operation main() pre: true post: true activity: ABC143B_TakoyakiFes(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) d=[int(i)for i in input().split()] de=0 for i in range(1,N): for j in range(i): de=de+d[j]*d[i] print(de) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var de : int := 0 ; for i : Integer.subrange(1, N-1) do ( for j : Integer.subrange(0, i-1) do ( de := de + d[j+1] * d[i+1])) ; execute (de)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def thanos_good(a,l,r): for i in range(l+1,r+1): if a[i]toInteger() ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (thanos_sort(a, 0, n - 1))->display() ) else skip; operation thanos_good(a : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(l + 1, r + 1-1) do ( if (a[i+1]->compareTo(a[i - 1+1])) < 0 then ( return false ) else skip) ; return true; operation thanos_sort(a : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: if (thanos_good(a, l, r)) then ( return r - l + 1; ) else skip ; var m : int := (l + r) div 2; ; return Set{thanos_sort(a, l, m), thanos_sort(a, m + 1, r)}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from copy import deepcopy N=int(input()) def check(case,bounds,targets): for i in range(4): if case &(1<targets[i]or bounds[i][1]toInteger() ; skip ; for i : Integer.subrange(0, N-1) do ( targets := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var maxx : OclAny := targets->at(0`firstArg+1) ; targets := targets->excludingAt(0+1) ; bounds := Integer.subrange(0, 4-1)->select(i | true)->collect(i | (Sequence{0}->union(Sequence{ maxx }))) ; (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 16))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name check)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j))))))) , (argument (test (logical_test (comparison (expr (atom (name deepcopy)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name bounds)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name targets)))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))))))); operation check(case : OclAny, bounds : OclAny, targets : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, 4-1) do ( if MathLib.bitwiseAnd(case, (1 * (2->pow(i)))) then ( bounds[i+1][1+1] := bounds[i+1][1+1] - 1 ; bounds[(i + 1) mod 4+1][1+1] := bounds[(i + 1) mod 4+1][1+1] - 1 ) else ( bounds[i+1]->first() := bounds[i+1]->first() + 1 ; bounds[(i + 1) mod 4+1]->first() := bounds[(i + 1) mod 4+1]->first() + 1 )) ; for i : Integer.subrange(0, 4-1) do ( if (bounds[i+1]->first()->compareTo(targets[i+1])) > 0 or (bounds[i+1][1+1]->compareTo(targets[i+1])) < 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def solve(): arr=list(map(int,input().split())) n=arr[0] arr=arr[1 :] stack=[] for i in range(4): stack.append([i]) while stack : seq=stack.pop() if len(seq)==4 : fail=False board=[[0,0]for _ in range(4)] for i in range(4): pos=seq[i] if pos & 1 : board[i][0]+=1 board[(i-1)% 4][1]+=1 pos>>=1 if pos & 1 : board[i][1]+=1 board[(i+1)% 4][0]+=1 for i in range(4): l,r=board[i] m=arr[i]-(l+r) if m<0 or m>n-2 : fail=True break if max(l,r)==2 : fail=True break if not fail : return "YES" continue for i in range(4): ns=list(seq) ns.append(i) stack.append(ns) return "NO" for _ in range(int(input())): print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (solve())->display()); operation solve() : OclAny pre: true post: true activity: var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := arr->first() ; arr := arr->tail() ; var stack : Sequence := Sequence{} ; for i : Integer.subrange(0, 4-1) do ( execute ((Sequence{ i }) : stack)) ; while stack do ( var seq : OclAny := stack->last() ; stack := stack->front() ; if (seq)->size() = 4 then ( var fail : boolean := false ; var board : Sequence := Integer.subrange(0, 4-1)->select(_anon | true)->collect(_anon | (Sequence{0}->union(Sequence{ 0 }))) ; for i : Integer.subrange(0, 4-1) do ( var pos : OclAny := seq[i+1] ; if MathLib.bitwiseAnd(pos, 1) then ( board[i+1]->first() := board[i+1]->first() + 1 ; board[(i - 1) mod 4+1][1+1] := board[(i - 1) mod 4+1][1+1] + 1 ) else skip ; pos := pos div (2->pow(1)) ; if MathLib.bitwiseAnd(pos, 1) then ( board[i+1][1+1] := board[i+1][1+1] + 1 ; board[(i + 1) mod 4+1]->first() := board[(i + 1) mod 4+1]->first() + 1 ) else skip) ; for i : Integer.subrange(0, 4-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := board[i+1] ; var m : double := arr[i+1] - (l + r) ; if m < 0 or (m->compareTo(n - 2)) > 0 then ( fail := true ; break ) else skip ; if Set{l, r}->max() = 2 then ( fail := true ; break ) else skip) ; if not(fail) then ( return "YES" ) else skip ; continue ) else skip ; for i : Integer.subrange(0, 4-1) do ( var ns : Sequence := (seq) ; execute ((i) : ns) ; execute ((ns) : stack))) ; return "NO"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isShuffledSubstring(A,B): n=len(A) m=len(B) if(n>m): return False else : A=sorted(A) for i in range(m): if(i+n-1>=m): return False Str="" for j in range(n): Str+=(B[i+j]) Str=sorted(Str) if(Str==A): return True if __name__=='__main__' : Str1="geekforgeeks" Str2="ekegorfkeegsgeek" a=isShuffledSubstring(Str1,Str2) if(a): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var Str1 : String := "geekforgeeks" ; var Str2 : String := "ekegorfkeegsgeek" ; var a : OclAny := isShuffledSubstring(Str1, Str2) ; if (a) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; operation isShuffledSubstring(A : OclAny, B : OclAny) : OclAny pre: true post: true activity: var n : int := (A)->size() ; var m : int := (B)->size() ; if ((n->compareTo(m)) > 0) then ( return false ) else ( A := A->sort() ; for i : Integer.subrange(0, m-1) do ( if ((i + n - 1->compareTo(m)) >= 0) then ( return false ) else skip ; var Str : String := "" ; for j : Integer.subrange(0, n-1) do ( Str := Str + (B[i + j+1])) ; Str := Str->sort() ; if (Str = A) then ( return true ) else skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def solve(): arr=list(map(int,input().split())) n=arr[0] arr=arr[1 :] for i in range(16): f=False board=[0,0,0,0] for j in range(4): if i & 1 : board[j]+=1 i>>=1 for k in range(4): l,r=board[k],board[(k+1)% 4] m=arr[k]-(l+r) if m<0 or m>n-2 : f=True break if not f : return "YES" return "NO" for _ in range(int(input())): print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (solve())->display()); operation solve() : OclAny pre: true post: true activity: var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := arr->first() ; arr := arr->tail() ; for i : Integer.subrange(0, 16-1) do ( var f : boolean := false ; var board : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))) ; for j : Integer.subrange(0, 4-1) do ( if MathLib.bitwiseAnd(i, 1) then ( board[j+1] := board[j+1] + 1 ) else skip ; i := i div (2->pow(1))) ; for k : Integer.subrange(0, 4-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{board[k+1],board[(k + 1) mod 4+1]} ; var m : double := arr[k+1] - (l + r) ; if m < 0 or (m->compareTo(n - 2)) > 0 then ( f := true ; break ) else skip) ; if not(f) then ( return "YES" ) else skip) ; return "NO"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,U,R,D,L=map(int,input().split()) for mask in range(16): rU,rR,rD,rL=U,R,D,L if mask & 1 : rU-=1 rL-=1 if mask & 2 : rL-=1 rD-=1 if mask & 4 : rD-=1 rR-=1 if mask & 8 : rR-=1 rU-=1 if min(rU,rR,rD,rL)>=0 and max(rU,rR,rD,rL)<=n-2 : print("YES") break else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var U : OclAny := null; var R : OclAny := null; var D : OclAny := null; var L : OclAny := null; Sequence{n,U,R,D,L} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (compound_stmt for (exprlist (expr (atom (name mask)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 16))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name rU)))))) , (test (logical_test (comparison (expr (atom (name rR)))))) , (test (logical_test (comparison (expr (atom (name rD)))))) , (test (logical_test (comparison (expr (atom (name rL))))))) (assign_part = (testlist_star_expr (test (logical_test (comparison (expr (atom (name U)))))) , (test (logical_test (comparison (expr (atom (name R)))))) , (test (logical_test (comparison (expr (atom (name D)))))) , (test (logical_test (comparison (expr (atom (name L))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (expr (atom (name mask))) & (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name rU)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name rL)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (expr (atom (name mask))) & (expr (atom (number (integer 2)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name rL)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name rD)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (expr (atom (name mask))) & (expr (atom (number (integer 4)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name rD)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name rR)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (expr (atom (name mask))) & (expr (atom (number (integer 8)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name rR)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name rU)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name rU))))))) , (argument (test (logical_test (comparison (expr (atom (name rR))))))) , (argument (test (logical_test (comparison (expr (atom (name rD))))))) , (argument (test (logical_test (comparison (expr (atom (name rL)))))))) ))))) >= (comparison (expr (atom (number (integer 0))))))) and (logical_test (comparison (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name rU))))))) , (argument (test (logical_test (comparison (expr (atom (name rR))))))) , (argument (test (logical_test (comparison (expr (atom (name rD))))))) , (argument (test (logical_test (comparison (expr (atom (name rL)))))))) ))))) <= (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 2)))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,U,R,D,L=map(int,input().split()) for mask in range(16): rU,rR,rD,rL=U,R,D,L if mask & 1 : rU-=1 rL-=1 if mask & 2 : rL-=1 rD-=1 if mask & 4 : rD-=1 rR-=1 if mask & 8 : rR-=1 rU-=1 if min(rU,rR,rD,rL)>=0 and max(rU,rR,rD,rL)<=n-2 : print("YES") break else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var U : OclAny := null; var R : OclAny := null; var D : OclAny := null; var L : OclAny := null; Sequence{n,U,R,D,L} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (compound_stmt for (exprlist (expr (atom (name mask)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 16))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name rU)))))) , (test (logical_test (comparison (expr (atom (name rR)))))) , (test (logical_test (comparison (expr (atom (name rD)))))) , (test (logical_test (comparison (expr (atom (name rL))))))) (assign_part = (testlist_star_expr (test (logical_test (comparison (expr (atom (name U)))))) , (test (logical_test (comparison (expr (atom (name R)))))) , (test (logical_test (comparison (expr (atom (name D)))))) , (test (logical_test (comparison (expr (atom (name L))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (expr (atom (name mask))) & (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name rU)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name rL)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (expr (atom (name mask))) & (expr (atom (number (integer 2)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name rL)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name rD)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (expr (atom (name mask))) & (expr (atom (number (integer 4)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name rD)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name rR)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (expr (atom (name mask))) & (expr (atom (number (integer 8)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name rR)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name rU)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name rU))))))) , (argument (test (logical_test (comparison (expr (atom (name rR))))))) , (argument (test (logical_test (comparison (expr (atom (name rD))))))) , (argument (test (logical_test (comparison (expr (atom (name rL)))))))) ))))) >= (comparison (expr (atom (number (integer 0))))))) and (logical_test (comparison (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name rU))))))) , (argument (test (logical_test (comparison (expr (atom (name rR))))))) , (argument (test (logical_test (comparison (expr (atom (name rD))))))) , (argument (test (logical_test (comparison (expr (atom (name rL)))))))) ))))) <= (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 2)))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def number_of_teams(M): N1,N2,sqr=0,0,0 sqr=math.sqrt(1+(8*M)) N1=(1+sqr)/2 N2=(1-sqr)/2 if(N1>0): return int(N1) return int(N2) def main(): M=45 print(number_of_teams(M)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation number_of_teams(M : OclAny) : OclAny pre: true post: true activity: var N1 : OclAny := null; var N2 : OclAny := null; var sqr : OclAny := null; Sequence{N1,N2,sqr} := Sequence{0,0,0} ; var sqr : double := (1 + (8 * M))->sqrt() ; var N1 : double := (1 + sqr) / 2 ; var N2 : double := (1 - sqr) / 2 ; if (N1 > 0) then ( return ("" + ((N1)))->toInteger() ) else skip ; return ("" + ((N2)))->toInteger(); operation main() pre: true post: true activity: M := 45 ; execute (number_of_teams(M))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math class Node : def __init__(self,data): self.data=data self.next=None def addToEmpty(head,data): if(head!=None): return head temp=Node(data) temp.data=data head=temp head.next=head return head def addBegin(head,data): if(head==None): return addToEmpty(head,data) temp=Node(data) temp.data=data temp.next=head.next head.next=temp return head def traverse(head): if(head==None): print("List is empty.") return p=head print(p.data,end="") p=p.next while(p!=head): print(p.data,end="") p=p.next def exchangeNodes(head): p=head while(p.next.next!=head): p=p.next p.next.next=head.next head.next=p.next p.next=head head=head.next return head if __name__=='__main__' : head=None head=addToEmpty(head,6) for x in range(5,0,-1): head=addBegin(head,x) print("List Before: ",end="") traverse(head) print() print("List After: ",end="") head=exchangeNodes(head) traverse(head) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.next := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( head := null ; head := addToEmpty(head, 6) ; for x : Integer.subrange(0 + 1, 5)->reverse() do ( head := addBegin(head, x)) ; execute ("List Before: ")->display() ; traverse(head) ; execute (->display() ; execute ("List After: ")->display() ; head := exchangeNodes(head) ; traverse(head) ) else skip; operation addToEmpty(head : OclAny, data : OclAny) : OclAny pre: true post: true activity: if (head /= null) then ( return head ) else skip ; var temp : Node := (Node.newNode()).initialise(data) ; temp.data := data ; head := temp ; head.next := head ; return head; operation addBegin(head : OclAny, data : OclAny) : OclAny pre: true post: true activity: if (head = null) then ( return addToEmpty(head, data) ) else skip ; temp := (Node.newNode()).initialise(data) ; temp.data := data ; temp.next := head.next ; head.next := temp ; return head; operation traverse(head : OclAny) pre: true post: true activity: if (head = null) then ( execute ("List is empty.")->display() ; return ) else skip ; var p : OclAny := head ; execute (p.data)->display() ; p := p.next ; while (p /= head) do ( execute (p.data)->display() ; p := p.next); operation exchangeNodes(head : OclAny) : OclAny pre: true post: true activity: p := head ; while (p.next.next /= head) do ( p := p.next) ; p.next.next := head.next ; head.next := p.next ; p.next := head ; head := head.next ; return head; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def circlearea(a): if a<0 : return-1 A=(3.14*3*pow(a,2))/4 return A if __name__=="__main__" : a=4 print(circlearea(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := 4 ; execute (circlearea(a))->display() ) else skip; operation circlearea(a : OclAny) : OclAny pre: true post: true activity: if a < 0 then ( return -1 ) else skip ; var A : double := (3.14 * 3 * (a)->pow(2)) / 4 ; return A; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def search(ar,size): a=0 b=size-1 mid=0 while b>a+1 : mid=(a+b)//2 if(ar[a]-a)!=(ar[mid]-mid): b=mid elif(ar[b]-b)!=(ar[mid]-mid): a=mid return ar[mid]+1 a=[1,2,3,4,5,6,8] n=len(a) print("Missing number:",search(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 8 })))))) ; var n : int := (a)->size() ; execute ("Missing number:")->display(); operation search(ar : OclAny, size : OclAny) : OclAny pre: true post: true activity: var a : int := 0 ; var b : double := size - 1 ; var mid : int := 0 ; while (b->compareTo(a + 1)) > 0 do ( mid := (a + b) div 2 ; if (ar[a+1] - a) /= (ar[mid+1] - mid) then ( b := mid ) else (if (ar[b+1] - b) /= (ar[mid+1] - mid) then ( a := mid ) else skip)) ; return ar[mid+1] + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(lst): global s if len(lst)>s : a,b=[],[] temp=lst[0] for i in lst[1 :]: if itoInteger() ; lst := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; s := 0 ; check(lst) ; execute (s)->display(); operation check(lst : OclAny) pre: true post: true activity: skip ; if ((lst)->size()->compareTo(s)) > 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{Sequence{},Sequence{}} ; var temp : OclAny := lst->first() ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name i)))) < (comparison (expr (atom (name temp))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name b))))))) (assign_part = (testlist_star_expr (test (logical_test (comparison (expr (atom (name lst)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name lst)))))))) )))) // (expr (atom (number (integer 2)))))))))) ])))))) , (test (logical_test (comparison (expr (atom (name lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name lst)))))))) )))) // (expr (atom (number (integer 2)))))))) :)) ]))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name check)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name check)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name temp)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name lst)))))))) )))))))))))))))) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=[] def check(): for i in range(10): for j in range(10): if j+4<10 : th='' for k in range(5): th+=s[i][j+k] if th=='XXXXX' : return True for i in range(10): for j in range(10): if i+4<10 : th='' for k in range(5): th+=s[i+k][j] if th=='XXXXX' : return True for i in range(10): for j in range(10): if i+4<10 and j+4<10 : th='' for k in range(5): th+=s[i+k][j+k] if th=='XXXXX' : return True for i in range(10): for j in range(10): if i+4<10 and j-4>=0 : th='' for k in range(5): th+=s[i+k][j-k] if th=='XXXXX' : return True return False for i in range(10): s.append(list(input())) flag=False if check(): flag=True for i in range(10): for j in range(10): if s[i][j]=='.' : s[i][j]='X' if check(): flag=True s[i][j]='.' if flag : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := Sequence{} ; skip ; for i : Integer.subrange(0, 10-1) do ( execute ((((OclFile["System.in"]).readLine())->characters()) : s)) ; var flag : boolean := false ; if check() then ( flag := true ) else skip ; for i : Integer.subrange(0, 10-1) do ( for j : Integer.subrange(0, 10-1) do ( if s[i+1][j+1] = '.' then ( s[i+1][j+1] := 'X' ; if check() then ( flag := true ) else skip ; s[i+1][j+1] := '.' ) else skip)) ; if flag then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); operation check() : OclAny pre: true post: true activity: for i : Integer.subrange(0, 10-1) do ( for j : Integer.subrange(0, 10-1) do ( if j + 4 < 10 then ( var th : String := '' ; for k : Integer.subrange(0, 5-1) do ( th := th + s[i+1][j + k+1]) ; if th = 'XXXXX' then ( return true ) else skip ) else skip)) ; for i : Integer.subrange(0, 10-1) do ( for j : Integer.subrange(0, 10-1) do ( if i + 4 < 10 then ( th := '' ; for k : Integer.subrange(0, 5-1) do ( th := th + s[i + k+1][j+1]) ; if th = 'XXXXX' then ( return true ) else skip ) else skip)) ; for i : Integer.subrange(0, 10-1) do ( for j : Integer.subrange(0, 10-1) do ( if i + 4 < 10 & j + 4 < 10 then ( th := '' ; for k : Integer.subrange(0, 5-1) do ( th := th + s[i + k+1][j + k+1]) ; if th = 'XXXXX' then ( return true ) else skip ) else skip)) ; for i : Integer.subrange(0, 10-1) do ( for j : Integer.subrange(0, 10-1) do ( if i + 4 < 10 & j - 4 >= 0 then ( th := '' ; for k : Integer.subrange(0, 5-1) do ( th := th + s[i + k+1][j - k+1]) ; if th = 'XXXXX' then ( return true ) else skip ) else skip)) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mat1=[input()for l in range(10)] mat2=list(reversed(mat1)) mat3=[] for l in mat1 : mat3.append(l[: :-1]) def horizontal(inp,i,j): s='' for k in range(j,j+5): s=s+inp[i][k] return s def vertical(inp,i,j): s='' for k in range(i,i+5): s=s+inp[k][j] return s def diagonal(inp,i,j): first=range(i,i+5,1) second=range(j,j+5,1) s='' for k,l in zip(first,second): s+=inp[k][l] return s def checker(s): if '0' in s : return False else : if s.count('X')<4 : return False else : if '.' not in s : return False return True def solve(mat): for i in range(6): for j in range(6): if(checker(horizontal(mat,i,j))): return True if(checker(vertical(mat,i,j))): return True if checker(diagonal(mat,i,j)): return True return False a=solve(mat1) b=solve(mat2) c=solve(mat3) if a or b or c : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mat1 : Sequence := Integer.subrange(0, 10-1)->select(l | true)->collect(l | ((OclFile["System.in"]).readLine())) ; var mat2 : Sequence := ((mat1)->reverse()) ; var mat3 : Sequence := Sequence{} ; for l : mat1 do ( execute ((l(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) : mat3)) ; skip ; skip ; skip ; skip ; skip ; var a : OclAny := solve(mat1) ; var b : OclAny := solve(mat2) ; var c : OclAny := solve(mat3) ; if a or b or c then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); operation horizontal(inp : OclAny, i : OclAny, j : OclAny) : OclAny pre: true post: true activity: var s : String := '' ; for k : Integer.subrange(j, j + 5-1) do ( s := s + inp[i+1][k+1]) ; return s; operation vertical(inp : OclAny, i : OclAny, j : OclAny) : OclAny pre: true post: true activity: s := '' ; for k : Integer.subrange(i, i + 5-1) do ( s := s + inp[k+1][j+1]) ; return s; operation diagonal(inp : OclAny, i : OclAny, j : OclAny) : OclAny pre: true post: true activity: var first : Sequence := Integer.subrange(i, i + 5-1)->select( $x | ($x - i) mod 1 = 0 ) ; var second : Sequence := Integer.subrange(j, j + 5-1)->select( $x | ($x - j) mod 1 = 0 ) ; s := '' ; for _tuple : Integer.subrange(1, first->size())->collect( _indx | Sequence{first->at(_indx), second->at(_indx)} ) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var l : OclAny := _tuple->at(_indx); s := s + inp[k+1][l+1]) ; return s; operation checker(s : OclAny) : OclAny pre: true post: true activity: if (s)->characters()->includes('0') then ( return false ) else ( if s->count('X') < 4 then ( return false ) else ( if (s)->characters()->excludes('.') then ( return false ) else skip ) ) ; return true; operation solve(mat : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, 6-1) do ( for j : Integer.subrange(0, 6-1) do ( if (checker(horizontal(mat, i, j))) then ( return true ) else skip ; if (checker(vertical(mat, i, j))) then ( return true ) else skip ; if checker(diagonal(mat, i, j)) then ( return true ) else skip)) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPerfectCube(x): x=abs(x) return int(round(x**(1./3)))**3==x def checkCube(a,b): s1=str(a) s2=str(b) c=int(s1+s2) if(isPerfectCube(c)): print("Yes") else : print("No") if __name__=='__main__' : a=6 b=4 checkCube(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( a := 6 ; b := 4 ; checkCube(a, b) ) else skip; operation isPerfectCube(x : OclAny) : OclAny pre: true post: true activity: x := (x)->abs() ; return (("" + ((((x)->pow((1. / 3)))->round())))->toInteger())->pow(3) = x; operation checkCube(a : OclAny, b : OclAny) pre: true post: true activity: var s1 : String := ("" + ((a))) ; var s2 : String := ("" + ((b))) ; var c : int := ("" + ((s1 + s2)))->toInteger() ; if (isPerfectCube(c)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSubArrays(arr,n,x): len=0 count=0 binaryArr=[0 for i in range(n)] for i in range(0,n,1): if(arr[i]<=x): binaryArr[i]=1 else : binaryArr[i]=0 for i in range(0,n,1): if(binaryArr[i]==1): for j in range(i+1,n,1): if(binaryArr[j]!=1): break len=j-i count+=(len)*(int)((len+1)/2) i=j return count if __name__=='__main__' : arr=[1,5,7,8,2,3,9] x=6 n=len(arr) print(int(countSubArrays(arr,n,x))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{5}->union(Sequence{7}->union(Sequence{8}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 9 })))))) ; x := 6 ; n := (arr)->size() ; execute (("" + ((countSubArrays(arr, n, x))))->toInteger())->display() ) else skip; operation countSubArrays(arr : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: var len : int := 0 ; var count : int := 0 ; var binaryArr : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if ((arr[i+1]->compareTo(x)) <= 0) then ( binaryArr[i+1] := 1 ) else ( binaryArr[i+1] := 0 )) ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (binaryArr[i+1] = 1) then ( for j : Integer.subrange(i + 1, n-1)->select( $x | ($x - i + 1) mod 1 = 0 ) do ( if (binaryArr[j+1] /= 1) then ( break ) else skip) ; len := j - i ; count := count + (len) * (OclType["int"])((len + 1) / 2) ; var i : OclAny := j ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for x in range(1000): print("Hello World") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for x : Integer.subrange(0, 1000-1) do ( execute ("Hello World")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print('Hello World\n'*1000,end='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (StringLib.nCopies('Hello World ', 1000))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function for i in range(1000): print('Hello World') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, 1000-1) do ( execute ('Hello World')->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print("Hello World\n"*1000)[:-1] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom "Hello World\n")) * (expr (atom (number (integer 1000)))))))))) ))) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s="Hello World" for i in range(1000): print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := "Hello World" ; for i : Integer.subrange(0, 1000-1) do ( execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countNum(arr,n): s=dict() count,maxm,minm=0,-10**9,10**9 for i in range(n): s[arr[i]]=1 if(arr[i]maxm): maxm=arr[i] for i in range(minm,maxm+1): if i not in s.keys(): count+=1 return count arr=[3,5,8,6] n=len(arr) print(countNum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{3}->union(Sequence{5}->union(Sequence{8}->union(Sequence{ 6 }))) ; n := (arr)->size() ; execute (countNum(arr, n))->display(); operation countNum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var s : Map := (arguments ( )) ; var count : OclAny := null; var maxm : OclAny := null; var minm : OclAny := null; Sequence{count,maxm,minm} := Sequence{0,(-10)->pow(9),(10)->pow(9)} ; for i : Integer.subrange(0, n-1) do ( s[arr[i+1]+1] := 1 ; if ((arr[i+1]->compareTo(minm)) < 0) then ( var minm : OclAny := arr[i+1] ) else skip ; if ((arr[i+1]->compareTo(maxm)) > 0) then ( var maxm : OclAny := arr[i+1] ) else skip) ; for i : Integer.subrange(minm, maxm + 1-1) do ( if (s.keys())->excludes(i) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) ni=n po=0 while n>1 : po+=1 n//=2 for i in range(po,-1,-1): size=2**i for ii in range(0,ni,size): if l[ii : ii+size]==sorted(l[ii : ii+size]): print(size) exit() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ni : int := n ; var po : int := 0 ; while n > 1 do ( po := po + 1 ; n := n div 2) ; for i : Integer.subrange(-1 + 1, po)->reverse() do ( var size : double := (2)->pow(i) ; for ii : Integer.subrange(0, ni-1)->select( $x | ($x - 0) mod size = 0 ) do ( if l.subrange(ii+1, ii + size) = l.subrange(ii+1, ii + size)->sort() then ( execute (size)->display() ; exit() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def ST(): return input().rstrip() def I(): return int(input()) def MI(): return map(int,input().split()) def LI(): return list(MI()) S=ST() Q=I() switch=True prefix="" suffix="" for _ in range(Q): query=list(input().split()) if query[0]=="1" : if switch : switch=False else : switch=True else : if switch : if query[1]=="1" : prefix=query[2]+prefix else : suffix=suffix+query[2] else : if query[1]=="1" : suffix=suffix+query[2] else : prefix=query[2]+prefix ans=prefix+S+suffix if switch : print(ans) else : print(ans[: :-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; var S : OclAny := ST() ; var Q : OclAny := I() ; var switch : boolean := true ; var prefix : String := "" ; var suffix : String := "" ; for _anon : Integer.subrange(0, Q-1) do ( var query : Sequence := (input().split()) ; if query->first() = "1" then ( if switch then ( switch := false ) else ( switch := true ) ) else ( if switch then ( if query[1+1] = "1" then ( prefix := query[2+1] + prefix ) else ( suffix := suffix + query[2+1] ) ) else ( if query[1+1] = "1" then ( suffix := suffix + query[2+1] ) else ( prefix := query[2+1] + prefix ) ) )) ; var ans : String := prefix + S + suffix ; if switch then ( execute (ans)->display() ) else ( execute (ans(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->display() ); operation ST() : OclAny pre: true post: true activity: return input().rstrip(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return (MI()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() N=int(input()) Q=[[]for _ in range(N)] for i in range(N): line=input().split() Q[i]=line reverse=0 r_b="" r_f="" for i in range(N): if Q[i][0]=='1' : reverse=(reverse+1)% 2 else : if reverse==0 : if Q[i][1]=='1' : r_f=Q[i][2]+r_f else : r_b=r_b+Q[i][2] else : if Q[i][1]=='1' : r_b=r_b+Q[i][2] else : r_f=Q[i][2]+r_f if reverse==0 : print(r_f+S+r_b) else : r_f=r_f[: :-1] r_b=r_b[: :-1] S=S[: :-1] print(r_b+S+r_f) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var Q : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, N-1) do ( var line : OclAny := input().split() ; Q[i+1] := line) ; var reverse : int := 0 ; var r_b : String := "" ; var r_f : String := "" ; for i : Integer.subrange(0, N-1) do ( if Q[i+1]->first() = '1' then ( reverse := (reverse + 1) mod 2 ) else ( if reverse = 0 then ( if Q[i+1][1+1] = '1' then ( r_f := Q[i+1][2+1] + r_f ) else ( r_b := r_b + Q[i+1][2+1] ) ) else ( if Q[i+1][1+1] = '1' then ( r_b := r_b + Q[i+1][2+1] ) else ( r_f := Q[i+1][2+1] + r_f ) ) )) ; if reverse = 0 then ( execute (r_f + S + r_b)->display() ) else ( r_f := r_f(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; r_b := r_b(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; S := S(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; execute (r_b + S + r_f)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque S=deque(list(input())) Q=int(input()) r_count=0 for query in range(Q): query=deque(list(input().split())) t=query[0] if(t=='1'): r_count+=1 elif(t=='2'): f=query[1] if(f=='1' and(r_count % 2==0)): S.appendleft(query[2]) elif(f=='1' and(r_count % 2==1)): S.append(query[2]) elif(f=='2' and(r_count % 2==0)): S.append(query[2]) elif(f=='2' and(r_count % 2==1)): S.appendleft(query[2]) if(r_count % 2==1): for i,s in enumerate(reversed(S)): if(i==len(S)-1): print(s) else : print(s,end="") else : for i,s in enumerate(S): if(i==len(S)-1): print(s) else : print(s,end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var S : Sequence := (((OclFile["System.in"]).readLine())->characters()) ; var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r_count : int := 0 ; for query : Integer.subrange(0, Q-1) do ( var query : Sequence := ((input().split())) ; var t : OclAny := query->first() ; if (t = '1') then ( r_count := r_count + 1 ) else (if (t = '2') then ( var f : OclAny := query[1+1] ; if (f = '1' & (r_count mod 2 = 0)) then ( S := S->prepend(query[2+1]) ) else (if (f = '1' & (r_count mod 2 = 1)) then ( execute ((query[2+1]) : S) ) else (if (f = '2' & (r_count mod 2 = 0)) then ( execute ((query[2+1]) : S) ) else (if (f = '2' & (r_count mod 2 = 1)) then ( S := S->prepend(query[2+1]) ) else skip ) ) ) ) else skip)) ; if (r_count mod 2 = 1) then ( for _tuple : Integer.subrange(1, ((S)->reverse())->size())->collect( _indx | Sequence{_indx-1, ((S)->reverse())->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); if (i = (S)->size() - 1) then ( execute (s)->display() ) else ( execute (s)->display() )) ) else ( for _tuple : Integer.subrange(1, (S)->size())->collect( _indx | Sequence{_indx-1, (S)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); if (i = (S)->size() - 1) then ( execute (s)->display() ) else ( execute (s)->display() )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sl=list(input()) q=int(input()) l=[list(map(str,input().split()))for i in range(q)] count=0 isR=False from collections import deque sl=deque(sl) for i in range(q): order=l[i] if order[0]=="1" : count+=1 if count % 2==0 : isR=False else : isR=True if order[0]!="1" : f=order[1] c=order[2] temp_f=f if isR : if temp_f=="1" : temp_f="2" else : temp_f="1" if temp_f=="1" : sl.appendleft(c) else : sl.append(c) sl=list(sl) ln=len(sl) ansl=[] if isR : for i in range(ln-1,-1,-1): ansl.append(sl[i]) else : ansl=sl ans=''.join(ansl) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sl : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Integer.subrange(0, q-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["String"])->apply(_x) )))) ; var count : int := 0 ; var isR : boolean := false ; skip ; sl := (sl) ; for i : Integer.subrange(0, q-1) do ( var order : OclAny := l[i+1] ; if order->first() = "1" then ( count := count + 1 ) else skip ; if count mod 2 = 0 then ( isR := false ) else ( isR := true ) ; if order->first() /= "1" then ( var f : OclAny := order[1+1] ; var c : OclAny := order[2+1] ; var temp_f : OclAny := f ; if isR then ( if temp_f = "1" then ( temp_f := "2" ) else ( temp_f := "1" ) ) else skip ; if temp_f = "1" then ( sl := sl->prepend(c) ) else ( execute ((c) : sl) ) ) else skip) ; sl := (sl) ; var ln : int := (sl)->size() ; var ansl : Sequence := Sequence{} ; if isR then ( for i : Integer.subrange(-1 + 1, ln - 1)->reverse() do ( execute ((sl[i+1]) : ansl)) ) else ( ansl := sl ) ; var ans : String := StringLib.sumStringsWithSeparator((ansl), '') ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(sys.stdin.readline()) data=[[None]*3 for i in range(n)] for i in range(n): s=sys.stdin.readline().split() data[i][0]="*"+s[0] data[i][1]="*"+s[1] data[i][2]=s[2] q=int(sys.stdin.readline()) for i in range(q): qb,qa,f,t=sys.stdin.readline().split() if t=="*" : t="9"+t for b,a,d in data : if qb in b and qa in a and f<=d<=t : print(b[1 :]) if itoInteger() ; var data : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ null }, 3))) ; for i : Integer.subrange(0, n-1) do ( var s : OclAny := sys.stdin.readLine().split() ; data[i+1]->first() := "*" + s->first() ; data[i+1][1+1] := "*" + s[1+1] ; data[i+1][2+1] := s[2+1]) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( var qb : OclAny := null; var qa : OclAny := null; var f : OclAny := null; var t : OclAny := null; Sequence{qb,qa,f,t} := sys.stdin.readLine().split() ; if t = "*" then ( var t : String := "9" + t ) else skip ; for _tuple : data do (var _indx : int := 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); if (b)->includes(qb) & (a)->includes(qa) & (f->compareTo(d)) <= 0 & (d <= t) then ( execute (b->tail())->display() ) else skip) ; if (i->compareTo(q - 1)) < 0 then ( execute (->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline s=input().rstrip('\n') n=int(input()) s_f=[] s_b=[] muki=True for i in range(n): line=input().rstrip('\n') if line=="1" : muki=not muki continue q,f,c=map(str,line.split()) q,f=int(q),int(f) if(f==1 and muki)or(f==2 and not muki): s_f.append(c) else : s_b.append(c) ans="".join(s_f[: :-1])+s+"".join(s_b) if muki : print(ans) else : print(ans[: :-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var s : OclAny := input().rstrip(' ') ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s_f : Sequence := Sequence{} ; var s_b : Sequence := Sequence{} ; var muki : boolean := true ; for i : Integer.subrange(0, n-1) do ( var line : OclAny := input().rstrip(' ') ; if line = "1" then ( muki := not(muki) ; continue ) else skip ; var q : OclAny := null; var f : OclAny := null; var c : OclAny := null; Sequence{q,f,c} := (line.split())->collect( _x | (OclType["String"])->apply(_x) ) ; var q : OclAny := null; var f : OclAny := null; Sequence{q,f} := Sequence{("" + ((q)))->toInteger(),("" + ((f)))->toInteger()} ; if (f = 1 & muki) or (f = 2 & not(muki)) then ( execute ((c) : s_f) ) else ( execute ((c) : s_b) )) ; var ans : String := StringLib.sumStringsWithSeparator((s_f(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))), "") + s + StringLib.sumStringsWithSeparator((s_b), "") ; if muki then ( execute (ans)->display() ) else ( execute (ans(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) d={1 : 0,2 : 0,3 : 0,4 : 0,5 : 0,6 : 0,7 : 0,8 : 0,9 : 0} flag=True for i in range(4): s=input() for i in s : if i=="." : continue else : i=int(i) d[i]+=1 for s,v in d.items(): if v>(2*k): print("NO") flag=False break if flag : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Map := Map{ 1 |-> 0 }->union(Map{ 2 |-> 0 }->union(Map{ 3 |-> 0 }->union(Map{ 4 |-> 0 }->union(Map{ 5 |-> 0 }->union(Map{ 6 |-> 0 }->union(Map{ 7 |-> 0 }->union(Map{ 8 |-> 0 }->union(Map{ 9 |-> 0 })))))))) ; var flag : boolean := true ; for i : Integer.subrange(0, 4-1) do ( var s : String := (OclFile["System.in"]).readLine() ; for i : s->characters() do ( if i = "." then ( continue ) else ( var i : int := ("" + ((i)))->toInteger() ; d[i+1] := d[i+1] + 1 ))) ; for _tuple : d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if (v->compareTo((2 * k))) > 0 then ( execute ("NO")->display() ; flag := false ; break ) else skip) ; if flag then ( execute ("YES")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k,s=int(input()),'' for i in range(4): s=s+input() for i in range(1,10): if(s.count(str(i))>k*2): exit(print('NO')) print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : OclAny := null; var s : OclAny := null; Sequence{k,s} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),''} ; for i : Integer.subrange(0, 4-1) do ( var s : OclAny := s + (OclFile["System.in"]).readLine()) ; for i : Integer.subrange(1, 10-1) do ( if ((s->count(("" + ((i))))->compareTo(k * 2)) > 0) then ( exit(('NO')->display()) ) else skip) ; execute ('YES')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter number_of_panels_Cucumber_can_press_with_one_hand=int(input()) tables_panels_need_to_press=[] for i in range(4): table_of_panels=input() for panel in table_of_panels : if panel!='.' : tables_panels_need_to_press.append(panel) counts=Counter(tables_panels_need_to_press) for panels in counts.values(): if panels>number_of_panels_Cucumber_can_press_with_one_hand*2 : print('NO') break else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var number_of_panels_Cucumber_can_press_with_one_hand : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var tables_panels_need_to_press : Sequence := Sequence{} ; for i : Integer.subrange(0, 4-1) do ( var table_of_panels : String := (OclFile["System.in"]).readLine() ; for panel : table_of_panels->characters() do ( if panel /= '.' then ( execute ((panel) : tables_panels_need_to_press) ) else skip)) ; var counts : OclAny := Counter(tables_panels_need_to_press) ; (compound_stmt for (exprlist (expr (atom (name panels)))) in (testlist (test (logical_test (comparison (expr (atom (name counts)) (trailer . (name values) (arguments ( )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name panels)))) > (comparison (expr (expr (atom (name number_of_panels_Cucumber_can_press_with_one_hand))) * (expr (atom (number (integer 2))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input k=int(I())*2 s='' for _ in '0'*4 : s+=I() print('YNEOS'[any(s.count(str(i))>k for i in range(10)): : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; var k : int := ("" + ((I())))->toInteger() * 2 ; var s : String := '' ; for _anon : StringLib.nCopies('0', 4) do ( s := s + I()) ; execute ('YNEOS'(subscript (test (logical_test (comparison (expr (atom (name any)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (comparison (expr (atom (name s)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))) ))))) > (comparison (expr (atom (name k))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 10))))))))) ))))))))) ))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys maxlen=0 def built_list(): len_of_arr=int(sys.stdin.readline()) list_nums=(list(map(int,sys.stdin.readline().split()))) return Thanos_Sort(list_nums) def Thanos_Sort(list_nums): global maxlen if sorted(list_nums)==list_nums : a=list(list_nums) cur_len=len(a) if cur_len>maxlen : maxlen=cur_len else : if len(list_nums)>1 : return Thanos_Sort(list_nums[0 : len(list_nums)//2]),Thanos_Sort(list_nums[len(list_nums)//2 :]) built_list() print(maxlen) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute maxlen : OclAny; operation initialise() pre: true post: true activity: skip ; var maxlen : int := 0 ; skip ; skip ; built_list() ; execute (maxlen)->display(); operation built_list() : OclAny pre: true post: true activity: var len_of_arr : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var list_nums : Sequence := (((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; return Thanos_Sort(list_nums); operation Thanos_Sort(list_nums : OclAny) : OclAny pre: true post: true activity: skip ; if list_nums->sort() = list_nums then ( var a : Sequence := (list_nums) ; var cur_len : int := (a)->size() ; if (cur_len->compareTo(maxlen)) > 0 then ( maxlen := cur_len ) else skip ) else ( if (list_nums)->size() > 1 then ( return Thanos_Sort(list_nums.subrange(0+1, (list_nums)->size() div 2)), Thanos_Sort(list_nums.subrange((list_nums)->size() div 2+1)) ) else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) l=[] for i in range(4): s=input() for j in s : l.append(j) b='YES' for num in l : if l.count(num)>2*k and num!='.' : b='NO' break print(b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, 4-1) do ( var s : String := (OclFile["System.in"]).readLine() ; for j : s->characters() do ( execute ((j) : l))) ; var b : String := 'YES' ; for num : l do ( if (l->count(num)->compareTo(2 * k)) > 0 & num /= '.' then ( b := 'NO' ; break ) else skip) ; execute (b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculate(array,size): count=0 for i in range(size): if(array[i]% 2==0 and array[i]!=0 and array[i]!=2): count+=1 return count if __name__=="__main__" : a=[1,3,4,6] size=len(a) print(calculate(a,size)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var a : Sequence := Sequence{1}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 6 }))) ; size := (a)->size() ; execute (calculate(a, size))->display() ) else skip; operation calculate(array : OclAny, size : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, size-1) do ( if (array[i+1] mod 2 = 0 & array[i+1] /= 0 & array[i+1] /= 2) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def printArr(b,n): for i in range(0,n,1): print(b[i],end=" ") def ModifiedArray(a,n): l=0 r=sys.maxsize b=[0 for i in range(n)] for i in range(0,int(n/2),1): b[i]=max(l,a[i]-r) b[n-i-1]=a[i]-b[i] l=b[i] r=b[n-i-1] printArr(b,n) if __name__=='__main__' : a=[5,6] n=len(a) ModifiedArray(a,2*n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( a := Sequence{5}->union(Sequence{ 6 }) ; n := (a)->size() ; ModifiedArray(a, 2 * n) ) else skip; operation printArr(b : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( execute (b[i+1])->display()); operation ModifiedArray(a : OclAny, n : OclAny) pre: true post: true activity: var l : int := 0 ; var r : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; b := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, ("" + ((n / 2)))->toInteger()-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( b[i+1] := Set{l, a[i+1] - r}->max() ; b[n - i - 1+1] := a[i+1] - b[i+1] ; l := b[i+1] ; r := b[n - i - 1+1]) ; printArr(b, n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countXorPair(arr,n): odd=0 even=0 for i in range(n): if arr[i]% 2==0 : even+=1 else : odd+=1 return odd*even if __name__=="__main__" : arr=[1,2,3] n=len(arr) print(countXorPair(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; n := (arr)->size() ; execute (countXorPair(arr, n))->display() ) else skip; operation countXorPair(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var odd : int := 0 ; var even : int := 0 ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] mod 2 = 0 then ( even := even + 1 ) else ( odd := odd + 1 )) ; return odd * even; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=[int(x)for x in input().split()] x.sort() if 1 in x : print(-1) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; x := x->sort() ; if (x)->includes(1) then ( execute (-1)->display() ) else ( execute (1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N=int(input()) books=[] for i in range(N): title,author,date=input().split() date=list(map(int,date.split('/'))) books.append((title,author,date)) Q=int(input()) for i in range(Q): title,author,date_from,date_to=input().split() if date_from!='*' : date_from=list(map(int,date_from .split('/'))) if date_to!='*' : date_to=list(map(int,date_to.split('/'))) resp=books[:] resp=[book for book in resp if title=='*' or title in book[0]] resp=[book for book in resp if author=='*' or author in book[1]] resp=[book for book in resp if date_from=='*' or date_from<=book[2]] resp=[book for book in resp if date_to=='*' or date_to>=book[2]] for book in resp : print(book[0]) if i+1toInteger() ; var books : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var title : OclAny := null; var author : OclAny := null; var date : OclAny := null; Sequence{title,author,date} := input().split() ; var date : Sequence := ((date.split('/'))->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((Sequence{title, author, date}) : books)) ; var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, Q-1) do ( var title : OclAny := null; var author : OclAny := null; var date_from : OclAny := null; var date_to : OclAny := null; Sequence{title,author,date_from,date_to} := input().split() ; if date_from /= '*' then ( var date_from : Sequence := ((date_from.split('/'))->collect( _x | (OclType["int"])->apply(_x) )) ) else skip ; if date_to /= '*' then ( var date_to : Sequence := ((date_to.split('/'))->collect( _x | (OclType["int"])->apply(_x) )) ) else skip ; var resp : Sequence := books ; resp := resp->select(book | title = '*' or (book->first())->includes(title))->collect(book | (book)) ; resp := resp->select(book | author = '*' or (book[1+1])->includes(author))->collect(book | (book)) ; resp := resp->select(book | date_from = '*' or (date_from->compareTo(book[2+1])) <= 0)->collect(book | (book)) ; resp := resp->select(book | date_to = '*' or (date_to->compareTo(book[2+1])) >= 0)->collect(book | (book)) ; for book : resp do ( execute (book->first())->display()) ; if (i + 1->compareTo(Q)) < 0 then ( execute (->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input(); print(-1 if "1" in[i for i in input().split()]else 1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input(); execute (if (input().split()->select(i | true)->collect(i | (i)))->includes("1") then -1 else 1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[int(i)for i in input().split()] if 1 in l : print(-1) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if (l)->includes(1) then ( execute (-1)->display() ) else ( execute (1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) if 1 in a : print(-1) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (a)->includes(1) then ( execute (-1)->display() ) else ( execute (1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=[int(x)for x in input().split()] if 1 in x : print(-1) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if (x)->includes(1) then ( execute (-1)->display() ) else ( execute (1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def toggleLastMBits(n,m): num=(1<display(); operation toggleLastMBits(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var num : double := (1 * (2->pow(m))) - 1 ; return (MathLib.bitwiseXor(n, num)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cnt_neg=0 ; exists_zero=None ; def preProcess(arr,n): global cnt_neg for i in range(n): if(arr[i]<0): cnt_neg+=1 ; if(arr[i]==0): exists_zero=True ; def isPossible(k): if(not exists_zero): if(k>=cnt_neg and(k-cnt_neg)% 2==0): return True ; else : return False ; else : if(k>=cnt_neg): return True ; else : return False ; if __name__=="__main__" : arr=[-1,2,-3,4,5]; n=len(arr); preProcess(arr,n); queries=[1,2,3,4]; q=len(queries); for i in range(q): if(isPossible(queries[i])): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { attribute cnt_neg : OclAny; operation initialise() pre: true post: true activity: var cnt_neg : int := 0; ; var exists_zero : OclAny := null; ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{-1}->union(Sequence{2}->union(Sequence{-3}->union(Sequence{4}->union(Sequence{ 5 })))); ; n := (arr)->size(); ; preProcess(arr, n); ; var queries : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))); ; var q : int := (queries)->size(); ; for i : Integer.subrange(0, q-1) do ( if (isPossible(queries[i+1])) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); )) ) else skip; operation preProcess(arr : OclAny, n : OclAny) pre: true post: true activity: skip ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] < 0) then ( cnt_neg := cnt_neg + 1; ) else skip ; if (arr[i+1] = 0) then ( exists_zero := true; ) else skip); operation isPossible(k : OclAny) pre: true post: true activity: if (not(exists_zero)) then ( if ((k->compareTo(cnt_neg)) >= 0 & (k - cnt_neg) mod 2 = 0) then ( return true; ) else ( return false; ) ) else ( if ((k->compareTo(cnt_neg)) >= 0) then ( return true; ) else ( return false; ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,data=0): self.data=data self.next=None class treeNode : def __init__(self,data): self.data=data self.left=None self.right=None def print_(head): if(head==None): return temp=head while(temp!=None): print(temp.data,end=" ") temp=temp.next def sortedList(head,root): if(root==None): return head head=sortedList(head,root.left) newNode=Node(root.data) temp=head prev=None if(temp==None): head=newNode else : while(temp!=None): if(temp.data>root.data): break else : prev=temp temp=temp.next if(temp==None): prev.next=newNode else : if(prev==None): newNode.next=temp head=newNode else : newNode.next=temp prev.next=newNode head=sortedList(head,root.right) return head root=treeNode(10) root.left=treeNode(15) root.right=treeNode(2) root.left.left=treeNode(1) root.left.right=treeNode(5) head=sortedList(None,root) print_(head) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : int := data; attribute next : OclAny := null; operation initialise(data : int) : Node pre: true post: true activity: self.data := data ; self.next := null; return self; } class treeNode { static operation newtreeNode() : treeNode pre: true post: treeNode->exists( _x | result = _x ); attribute data : int := data; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(data : OclAny) : treeNode pre: true post: true activity: self.data := data ; self.left := null ; self.right := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; root := (treeNode.newtreeNode()).initialise(10) ; root.left := (treeNode.newtreeNode()).initialise(15) ; root.right := (treeNode.newtreeNode()).initialise(2) ; root.left.left := (treeNode.newtreeNode()).initialise(1) ; root.left.right := (treeNode.newtreeNode()).initialise(5) ; head := sortedList(null, root) ; print_(head); operation print_(head : OclAny) pre: true post: true activity: if (head = null) then ( return ) else skip ; var temp : OclAny := head ; while (temp /= null) do ( execute (temp.data)->display() ; temp := temp.next); operation sortedList(head : OclAny, root : OclAny) : OclAny pre: true post: true activity: if (root = null) then ( return head ) else skip ; head := sortedList(head, root.left) ; var newNode : Node := (Node.newNode()).initialise(root.data) ; temp := head ; var prev : OclAny := null ; if (temp = null) then ( head := newNode ) else ( while (temp /= null) do ( if ((temp.data->compareTo(root.data)) > 0) then ( break ) else ( prev := temp ; temp := temp.next )) ; if (temp = null) then ( prev.next := newNode ) else ( if (prev = null) then ( newNode.next := temp ; head := newNode ) else ( newNode.next := temp ; prev.next := newNode ) ) ) ; head := sortedList(head, root.right) ; return head; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- st="GfG" if(st[0]==st[-1]): print("Equal") else : print("Not Equal") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var st : String := "GfG" ; if (st->first() = st->last()) then ( execute ("Equal")->display() ) else ( execute ("Not Equal")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def func(x): return x*x*x-x*x+2 def derivFunc(x): return 3*x*x-2*x def newtonRaphson(x): h=func(x)/derivFunc(x) while abs(h)>=0.0001 : h=func(x)/derivFunc(x) x=x-h print("The value of the root is : ","%.4f" % x) x0=-20 newtonRaphson(x0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var x0 : int := -20 ; newtonRaphson(x0); operation func(x : OclAny) : OclAny pre: true post: true activity: return x * x * x - x * x + 2; operation derivFunc(x : OclAny) : OclAny pre: true post: true activity: return 3 * x * x - 2 * x; operation newtonRaphson(x : OclAny) pre: true post: true activity: var h : double := func(x) / derivFunc(x) ; while (h)->abs() >= 0.0001 do ( h := func(x) / derivFunc(x) ; x := x - h) ; execute ("The value of the root is : ")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict from math import inf n=int(input()) r=[] d=defaultdict(int) for i in range(n): x=input().split() name,score=x[0],int(x[1]) d[name]+=score r.append((name,score)) winners=set() best=0 for name in d : if d[name]>best : best=d[name] winners={name} elif d[name]==best : winners.add(name) d=defaultdict(int) for i in range(n): name,score=r[i] d[name]+=score if name in winners and d[name]>=best : print(name) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r : Sequence := Sequence{} ; var d : OclAny := defaultdict(OclType["int"]) ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := input().split() ; var name : OclAny := null; var score : OclAny := null; Sequence{name,score} := Sequence{x->first(),("" + ((x[1+1])))->toInteger()} ; d[name+1] := d[name+1] + score ; execute ((Sequence{name, score}) : r)) ; var winners : Set := Set{}->union(()) ; var best : int := 0 ; for name : d do ( if (d[name+1]->compareTo(best)) > 0 then ( best := d[name+1] ; winners := Set{ name } ) else (if d[name+1] = best then ( execute ((name) : winners) ) else skip)) ; d := defaultdict(OclType["int"]) ; for i : Integer.subrange(0, n-1) do ( var name : OclAny := null; var score : OclAny := null; Sequence{name,score} := r[i+1] ; d[name+1] := d[name+1] + score ; if (winners)->includes(name) & (d[name+1]->compareTo(best)) >= 0 then ( execute (name)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict n=int(input()) scores=defaultdict(int) rounds=[] for round in range(1,n+1): name,score=input().split() score=int(score) scores[name]+=score rounds.append([scores[name],name]) max_score=max(scores.values()) for score,name in rounds : if score>=max_score and scores[name]==max_score : print(name) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var scores : OclAny := defaultdict(OclType["int"]) ; var rounds : Sequence := Sequence{} ; for round : Integer.subrange(1, n + 1-1) do ( var name : OclAny := null; var score : OclAny := null; Sequence{name,score} := input().split() ; var score : int := ("" + ((score)))->toInteger() ; scores[name+1] := scores[name+1] + score ; execute ((Sequence{scores[name+1]}->union(Sequence{ name })) : rounds)) ; var max_score : OclAny := (scores.values())->max() ; for _tuple : rounds do (var _indx : int := 1; var score : OclAny := _tuple->at(_indx); _indx := _indx + 1; var name : OclAny := _tuple->at(_indx); if (score->compareTo(max_score)) >= 0 & scores[name+1] = max_score then ( execute (name)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import* from bisect import* from math import* from collections import* from heapq import* from random import* import sys sys.setrecursionlimit(10**6) int1=lambda x : int(x)-1 p2D=lambda x : print(*x,sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int,sys.stdin.readline().split()) def MI1(): return map(int1,sys.stdin.readline().split()) def MF(): return map(float,sys.stdin.readline().split()) def LI(): return list(map(int,sys.stdin.readline().split())) def LI1(): return list(map(int1,sys.stdin.readline().split())) def LF(): return list(map(float,sys.stdin.readline().split())) def LLI(rows_number): return[LI()for _ in range(rows_number)] dij=[(1,0),(0,1),(-1,0),(0,-1)] def main(): m,n=MI() aa=LI() ans=0 if m==2 : for i,a in enumerate(aa): if i % 2+1==a : ans+=1 ans=min(ans,n-ans) else : cnt=1 for a0,a1 in zip(aa,aa[1 :]): if a0==a1 : cnt+=1 else : ans+=cnt//2 cnt=1 ans+=cnt//2 print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(6)) ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; var p2D : Function := lambda x : OclAny in (((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var dij : Sequence := Sequence{Sequence{1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{-1, 0}}->union(Sequence{ Sequence{0, -1} }))) ; skip ; main(); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation MI1() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (int1)->apply(_x) ); operation MF() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LI1() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (int1)->apply(_x) )); operation LF() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) )); operation LLI(rows_number : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows_number-1)->select(_anon | true)->collect(_anon | (LI())); operation main() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := MI() ; var aa : OclAny := LI() ; var ans : int := 0 ; if m = 2 then ( for _tuple : Integer.subrange(1, (aa)->size())->collect( _indx | Sequence{_indx-1, (aa)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); if i mod 2 + 1 = a then ( ans := ans + 1 ) else skip) ; ans := Set{ans, n - ans}->min() ) else ( var cnt : int := 1 ; for _tuple : Integer.subrange(1, aa->size())->collect( _indx | Sequence{aa->at(_indx), aa->tail()->at(_indx)} ) do (var _indx : int := 1; var a0 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a1 : OclAny := _tuple->at(_indx); if a0 = a1 then ( cnt := cnt + 1 ) else ( ans := ans + cnt div 2 ; cnt := 1 )) ; ans := ans + cnt div 2 ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) books=[input().split()for _ in range(n)] q=int(input()) for i in range(q): qt,qa,qdf,qdt=input().split() for title,auther,date in books : if(qt=="*" or qt in title)and(qa=="*" or qa in auther)and(qdf=="*" or qdf<=date)and(qdt=="*" or date<=qdt): print(title) if i!=q-1 : print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var books : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (input().split())) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( var qt : OclAny := null; var qa : OclAny := null; var qdf : OclAny := null; var qdt : OclAny := null; Sequence{qt,qa,qdf,qdt} := input().split() ; for _tuple : books do (var _indx : int := 1; var title : OclAny := _tuple->at(_indx); _indx := _indx + 1; var auther : OclAny := _tuple->at(_indx); _indx := _indx + 1; var date : OclAny := _tuple->at(_indx); if (qt = "*" or (title)->includes(qt)) & (qa = "*" or (auther)->includes(qa)) & (qdf = "*" or (qdf->compareTo(date)) <= 0) & (qdt = "*" or (date->compareTo(qdt)) <= 0) then ( execute (title)->display() ) else skip) ; if i /= q - 1 then ( execute (->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) v_k=list() for _ in range(n): v_k.append(input().split()) l_s={} for i in range(n): k=v_k[i][0] s=int(v_k[i][1]) if k not in l_s : l_s[k]=int(s) else : l_s[k]+=int(s) m=max(l_s[x]for x in l_s) l_s_2={} for i in range(n): k=v_k[i][0] s=int(v_k[i][1]) if k not in l_s_2 : l_s_2[k]=int(s) else : l_s_2[k]+=int(s) if l_s_2[k]>=m and l_s[k]==m : print(k) quit() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var v_k : Sequence := () ; for _anon : Integer.subrange(0, n-1) do ( execute ((input().split()) : v_k)) ; var l_s : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var k : OclAny := v_k[i+1]->first() ; var s : int := ("" + ((v_k[i+1][1+1])))->toInteger() ; if (l_s)->excludes(k) then ( l_s[k+1] := ("" + ((s)))->toInteger() ) else ( l_s[k+1] := l_s[k+1] + ("" + ((s)))->toInteger() )) ; var m : OclAny := ((argument (test (logical_test (comparison (expr (atom (name l_s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name l_s))))))))->max() ; var l_s:= Set{} : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( k := v_k[i+1]->first() ; s := ("" + ((v_k[i+1][1+1])))->toInteger() ; if (l_s l_s:= ("" + ((s)))->toInteger()[k+1] := ("" + ((s)))->toInteger())->excludes(k) then ( l_s:= ("" + ((s)))->toInteger()[k+1] := ("" + ((s)))->toInteger() ) else ( l_s + ("" + ((s)))->toInteger()[k+1] := l_s + ("" + ((s)))->toInteger()[k+1] + ("" + ((s)))->toInteger() ) ; if (l_sm[k+1]->compareTo(m)) >= 0 & l_s[k+1] = m then ( execute (k)->display() ; quit() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) mxp=-1001 mx='' dic={} res=[] for i in range(n): a,b=input().split() b=int(b) if a in dic : dic[a]+=b else : dic[a]=b res.append((a,dic[a])) mxp=max(dic.values()) for i,j in res : if dic[i]==mxp and j>=mxp : print(i) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mxp : int := -1001 ; var mx : String := '' ; var dic : OclAny := Set{} ; var res : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; var b : int := ("" + ((b)))->toInteger() ; if (dic)->includes(a) then ( dic[a+1] := dic[a+1] + b ) else ( dic[a+1] := b ) ; execute ((Sequence{a, dic[a+1]}) : res)) ; mxp := (dic.values())->max() ; for _tuple : res do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if dic[i+1] = mxp & (j->compareTo(mxp)) >= 0 then ( execute (i)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : s=input() flag=False if s[-1]!='B' else True if flag : summ=0 for c in s : if c=='A' : summ+=1 else : summ-=1 if summ<0 : flag=False break if flag : print("YES") else : print("NO") t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( var s : String := (OclFile["System.in"]).readLine() ; var flag : boolean := if s->last() /= 'B' then false else true endif ; if flag then ( var summ : int := 0 ; for c : s->characters() do ( if c = 'A' then ( summ := summ + 1 ) else ( summ := summ - 1 ) ; if summ < 0 then ( flag := false ; break ) else skip) ) else skip ; if flag then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) c={} v=[] for i in range(x): d=input().split() a,b=d[0],int(d[1]) v.append([a,b]) if a in c : c[a]+=b else : c[a]=b ms=0 for i in c : if c[i]>ms : ms=c[i] c1={} for i in c : if c[i]==ms : c1[i]=0 for i in v : if i[0]in c1 : c1[i[0]]+=i[1] if c1[i[0]]>=ms : print(i[0]) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : OclAny := Set{} ; var v : Sequence := Sequence{} ; for i : Integer.subrange(0, x-1) do ( var d : OclAny := input().split() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{d->first(),("" + ((d[1+1])))->toInteger()} ; execute ((Sequence{a}->union(Sequence{ b })) : v) ; if (c)->includes(a) then ( c[a+1] := c[a+1] + b ) else ( c[a+1] := b )) ; var ms : int := 0 ; for i : c do ( if (c[i+1]->compareTo(ms)) > 0 then ( ms := c[i+1] ) else skip) ; var c1 : OclAny := Set{} ; for i : c do ( if c[i+1] = ms then ( c1[i+1] := 0 ) else skip) ; for i : v do ( if (c1)->includes(i->first()) then ( c1[i->first()+1] := c1[i->first()+1] + i[1+1] ; if (c1[i->first()+1]->compareTo(ms)) >= 0 then ( execute (i->first())->display() ; break ) else skip ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil,floor def printArr(arr,n): for i in range(n): print(arr[i],end=" ") def generateArr(arr,n): flip=True for i in range(n): if(arr[i]& 1): flip ^=True if(flip): print(int(ceil((arr[i])/2)),end=" ") else : print(int(floor((arr[i])/2)),end=" ") else : print(int(arr[i]/2),end=" ") arr=[3,-5,-7,9,2,-2] n=len(arr) generateArr(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; arr := Sequence{3}->union(Sequence{-5}->union(Sequence{-7}->union(Sequence{9}->union(Sequence{2}->union(Sequence{ -2 }))))) ; n := (arr)->size() ; generateArr(arr, n); operation printArr(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); operation generateArr(arr : OclAny, n : OclAny) pre: true post: true activity: var flip : boolean := true ; for i : Integer.subrange(0, n-1) do ( if (MathLib.bitwiseAnd(arr[i+1], 1)) then ( flip := flip xor true ; if (flip) then ( execute (("" + ((ceil((arr[i+1]) / 2))))->toInteger())->display() ) else ( execute (("" + ((floor((arr[i+1]) / 2))))->toInteger())->display() ) ) else ( execute (("" + ((arr[i+1] / 2)))->toInteger())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumofsquare(n): C=[[0 for i in range(n+1)]for j in range(n+1)] for i in range(0,n+1): for j in range(0,min(i,n)+1): if(j==0 or j==i): C[i][j]=1 else : C[i][j]=(C[i-1][j-1]+C[i-1][j]) sum=0 for i in range(0,n+1): sum=sum+(C[n][i]*C[n][i]) return sum n=4 print(sumofsquare(n),end="\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute (sumofsquare(n))->display(); operation sumofsquare(n : OclAny) : OclAny pre: true post: true activity: var C : Sequence := Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, n + 1-1) do ( for j : Integer.subrange(0, Set{i, n}->min() + 1-1) do ( if (j = 0 or j = i) then ( C[i+1][j+1] := 1 ) else ( C[i+1][j+1] := (C[i - 1+1][j - 1+1] + C[i - 1+1][j+1]) ))) ; var sum : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( sum := sum + (C[n+1][i+1] * C[n+1][i+1])) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lengthOfSmallestSubsequence(K,v): pq=[] for i in v : pq.append(i) pq.sort() sum=0 count=0 while(len(pq)>0 and sumunion(Sequence{3}->union(Sequence{1}->union(Sequence{5}->union(Sequence{6}->union(Sequence{3}->union(Sequence{7}->union(Sequence{9}->union(Sequence{14}->union(Sequence{10}->union(Sequence{2}->union(Sequence{ 5 }))))))))))) ; K := 35 ; execute (lengthOfSmallestSubsequence(K, v))->display(); operation lengthOfSmallestSubsequence(K : OclAny, v : OclAny) : OclAny pre: true post: true activity: var pq : Sequence := Sequence{} ; for i : v do ( execute ((i) : pq)) ; pq := pq->sort() ; var sum : int := 0 ; var count : int := 0 ; while ((pq)->size() > 0 & (sum->compareTo(K)) < 0) do ( sum := sum + pq->last() ; execute (pq->last())->isDeleted() ; count := count + 1) ; if ((sum->compareTo(K)) < 0) then ( return -1 ) else skip ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countnndSay(n): if(n==1): return "1" if(n==2): return "11" s="11" for i in range(3,n+1): s+='$' l=len(s) cnt=1 tmp="" for j in range(1,l): if(s[j]!=s[j-1]): tmp+=str(cnt+0) tmp+=s[j-1] cnt=1 else : cnt+=1 s=tmp return s ; N=3 print(countnndSay(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 3 ; execute (countnndSay(N))->display(); operation countnndSay(n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return "1" ) else skip ; if (n = 2) then ( return "11" ) else skip ; var s : String := "11" ; for i : Integer.subrange(3, n + 1-1) do ( s := s + '$' ; var l : int := (s)->size() ; var cnt : int := 1 ; var tmp : String := "" ; for j : Integer.subrange(1, l-1) do ( if (s[j+1] /= s[j - 1+1]) then ( tmp := tmp + ("" + ((cnt + 0))) ; tmp := tmp + s[j - 1+1] ; cnt := 1 ) else ( cnt := cnt + 1 )) ; s := tmp) ; return s;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def largestPalindrome(self,n): if n==1 : return 9 for a in xrange(2,9*10**(n-1)): hi=(10**n)-a lo=int(str(hi)[: :-1]) if a**2-4*lo<0 : continue if(a**2-4*lo)**.5==int((a**2-4*lo)**.5): return(lo+10**n*(10**n-a))% 1337 ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation largestPalindrome(n : OclAny) : OclAny pre: true post: true activity: if n = 1 then ( return 9 ) else skip ; for a : xrange(2, 9 * (10)->pow((n - 1))) do ( var hi : double := ((10)->pow(n)) - a ; var lo : int := ("" + ((OclType["String"](hi)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))))->toInteger() ; if (a)->pow(2) - 4 * lo < 0 then ( continue ) else skip ; if (((a)->pow(2) - 4 * lo))->pow(.5) = ("" + (((((a)->pow(2) - 4 * lo))->pow(.5))))->toInteger() then ( return (lo + (10)->pow(n) * ((10)->pow(n) - a)) mod 1337 ) else skip); } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math def best3(a,b,c): (ax,ay,ar)=a (bx,by,br)=b (cx,cy,cr)=c return(max(ar,(math.sqrt((bx-cx)**2+(by-cy)**2)+float(br)+float(cr))/2.0)) rdln=sys.stdin.readline C=int(rdln()) for c in range(C): N=int(rdln()) p=[[int(x)for x in rdln().split()]for w in range(N)] ans=0.0 if N==1 : ans=p[0][2] elif N==2 : ans=max(p[0][2],p[1][2]) else : assert(N==3) ans=min(best3(p[0],p[1],p[2]),best3(p[1],p[2],p[0]),best3(p[2],p[0],p[1])) print("Case #",c+1,": ",ans,sep="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var rdln : OclAny := (OclFile["System.in"]).readline ; var C : int := ("" + ((rdln())))->toInteger() ; for c : Integer.subrange(0, C-1) do ( var N : int := ("" + ((rdln())))->toInteger() ; var p : Sequence := Integer.subrange(0, N-1)->select(w | true)->collect(w | (rdln().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))) ; var ans : double := 0.0 ; if N = 1 then ( ans := p->first()[2+1] ) else (if N = 2 then ( ans := Set{p->first()[2+1], p[1+1][2+1]}->max() ) else ( assert (N = 3) do "assertion failed" ; ans := Set{best3(p->first(), p[1+1], p[2+1]), best3(p[1+1], p[2+1], p->first()), best3(p[2+1], p->first(), p[1+1])}->min() ) ) ; execute ("Case #")->display()); operation best3(a : OclAny, b : OclAny, c : OclAny) pre: true post: true activity: ; var Sequence{ax, ay, ar} : OclAny := a ; var Sequence{bx, by, br} : OclAny := b ; var Sequence{cx, cy, cr} : OclAny := c ; return (Set{ar, ((((bx - cx))->pow(2) + ((by - cy))->pow(2))->sqrt() + ("" + ((br)))->toReal() + ("" + ((cr)))->toReal()) / 2.0}->max()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math fi=open(sys.argv[1],"r") fo=open(sys.argv[2],"w") cases=int(fi.readline()) for C in range(cases): plants=int(fi.readline()) P=[] for plant in range(plants): P.append(map(int,fi.readline().split())) R={} for a in range(plants): for b in range(a,plants): R[(a,b)]=math.sqrt((P[a][0]-P[b][0])**2+(P[a][1]-P[b][1])**2)+P[a][2]+P[b][2] if(plants==1): fo.write("Case: #%d: %f\n" %(C+1,P[0][2])) if(plants==2): fo.write("Case: #%d: %f\n" %(C+1,max(P[0][2],P[1][2]))) if(plants==3): m=min(R[(0,1)],R[(0,2)],R[(1,2)]) if R[(0,1)]==m : fo.write("Case #%d: %f\n" %(C+1,max(m/2.0,P[2][2]))) elif R[(0,2)]==m : fo.write("Case #%d: %f\n" %(C+1,max(m/2.0,P[1][2]))) elif R[(1,2)]==m : fo.write("Case #%d: %f\n" %(C+1,max(m/2.0,P[0][2]))) fi.close() fo.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var fi : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) ; var fo : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))) ; var cases : int := ("" + ((fi.readLine())))->toInteger() ; for C : Integer.subrange(0, cases-1) do ( var plants : int := ("" + ((fi.readLine())))->toInteger() ; var P : Sequence := Sequence{} ; for plant : Integer.subrange(0, plants-1) do ( execute (((fi.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) : P)) ; var R : OclAny := Set{} ; for a : Integer.subrange(0, plants-1) do ( for b : Integer.subrange(a, plants-1) do ( R[Sequence{a, b}+1] := (((P[a+1]->first() - P[b+1]->first()))->pow(2) + ((P[a+1][1+1] - P[b+1][1+1]))->pow(2))->sqrt() + P[a+1][2+1] + P[b+1][2+1])) ; if (plants = 1) then ( fo.write(StringLib.format("Case: #%d: %f\n",Sequence{C + 1, P->first()[2+1]})) ) else skip ; if (plants = 2) then ( fo.write(StringLib.format("Case: #%d: %f\n",Sequence{C + 1, Set{P->first()[2+1], P[1+1][2+1]}->max()})) ) else skip ; if (plants = 3) then ( var m : OclAny := Set{R[Sequence{0, 1}+1], R[Sequence{0, 2}+1], R[Sequence{1, 2}+1]}->min() ; if R[Sequence{0, 1}+1] = m then ( fo.write(StringLib.format("Case #%d: %f\n",Sequence{C + 1, Set{m / 2.0, P[2+1][2+1]}->max()})) ) else (if R[Sequence{0, 2}+1] = m then ( fo.write(StringLib.format("Case #%d: %f\n",Sequence{C + 1, Set{m / 2.0, P[1+1][2+1]}->max()})) ) else (if R[Sequence{1, 2}+1] = m then ( fo.write(StringLib.format("Case #%d: %f\n",Sequence{C + 1, Set{m / 2.0, P->first()[2+1]}->max()})) ) else skip ) ) ) else skip) ; fi.closeFile() ; fo.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def product(x,y): if xdisplay(); operation product(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (x->compareTo(y)) < 0 then ( return product(y, x) ) else (if y /= 0 then ( return (x + product(x, y - 1)) ) else ( return 0 ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def Cover(C): if len(C)==0 : return 0.0 if len(C)==1 : return C[0][2] return(C[0][2]+C[1][2]+math.sqrt((C[0][0]-C[1][0])**2+(C[0][1]-C[1][1])**2))/2.0 for tc in range(1,int(input())+1): n=int(input()) circles=[] for i in range(n): x,y,r=map(int,input().split()) circles.append((x,y,r)) ans=None for i in range(n): nans=max(Cover(circles[i : i+1]),Cover(circles[0 : i]+circles[i+1 : n])) if ans is None or nanstoInteger() + 1-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var circles : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; var r : OclAny := null; Sequence{x,y,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{x, y, r}) : circles)) ; var ans : OclAny := null ; for i : Integer.subrange(0, n-1) do ( var nans : OclAny := Set{Cover(circles.subrange(i+1, i + 1)), Cover(circles.subrange(0+1, i) + circles.subrange(i + 1+1, n))}->max() ; if ans <>= null or (nans->compareTo(ans)) < 0 then ( ans := nans ) else skip) ; execute (StringLib.format("Case #%d: %.6f",Sequence{tc, ans}))->display()); operation Cover(C : OclAny) : OclAny pre: true post: true activity: if (C)->size() = 0 then ( return 0.0 ) else skip ; if (C)->size() = 1 then ( return C->first()[2+1] ) else skip ; return (C->first()[2+1] + C[1+1][2+1] + (((C->first()->first() - C[1+1]->first()))->pow(2) + ((C->first()[1+1] - C[1+1][1+1]))->pow(2))->sqrt()) / 2.0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import io import math import scipy.sparse nim,mike,kite=map(int,input().split()) array=list(map(int,input().split())) print(max(abs(kite-array[nim-1]),abs(array[nim-1]-array[nim-2]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var nim : OclAny := null; var mike : OclAny := null; var kite : OclAny := null; Sequence{nim,mike,kite} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var array : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (Set{(kite - array[nim - 1+1])->abs(), (array[nim - 1+1] - array[nim - 2+1])->abs()}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools import math def distance(p1,p2): return math.sqrt((p1[0]-p2[0])**2+(p1[1]-p2[1])**2) def solve_third_case(points): solution=10**10 for p in itertools.permutations([0,1,2],3): foobar=distance(points[p[0]],points[p[1]]) foobar=(foobar+points[p[0]][2]+points[p[1]][2])/2 if foobar>=points[p[2]][2]: solution=min([solution,foobar]) else : solution=min([solution,points[p[2]][2]]) return solution def solve(points): if len(points)==1 : return points[0][2] elif len(points)==2 : return max(points[0][2],points[1][2]) elif len(points)==3 : return solve_third_case(points) def main(): file=open("input.in") tests=int(file.readline()) for case in range(1,tests+1): N=int(file.readline()) points=[] for i in range(N): points.append([int(x)for x in file.readline().split()]) print("Case #",case,": ",solve(points),sep="") if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation distance(p1 : OclAny, p2 : OclAny) : OclAny pre: true post: true activity: return (((p1->first() - p2->first()))->pow(2) + ((p1[1+1] - p2[1+1]))->pow(2))->sqrt(); operation solve_third_case(points : OclAny) : OclAny pre: true post: true activity: var solution : double := (10)->pow(10) ; for p : itertools.permutations(Sequence{0}->union(Sequence{1}->union(Sequence{ 2 })), 3) do ( var foobar : OclAny := distance(points[p->first()+1], points[p[1+1]+1]) ; foobar := (foobar + points[p->first()+1][2+1] + points[p[1+1]+1][2+1]) / 2 ; if (foobar->compareTo(points[p[2+1]+1][2+1])) >= 0 then ( solution := (Sequence{solution}->union(Sequence{ foobar }))->min() ) else ( solution := (Sequence{solution}->union(Sequence{ points[p[2+1]+1][2+1] }))->min() )) ; return solution; operation solve(points : OclAny) : OclAny pre: true post: true activity: if (points)->size() = 1 then ( return points->first()[2+1] ) else (if (points)->size() = 2 then ( return Set{points->first()[2+1], points[1+1][2+1]}->max() ) else (if (points)->size() = 3 then ( return solve_third_case(points) ) else skip ) ) ; operation main() pre: true post: true activity: var file : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("input.in")) ; var tests : int := ("" + ((file.readLine())))->toInteger() ; for case : Integer.subrange(1, tests + 1-1) do ( var N : int := ("" + ((file.readLine())))->toInteger() ; points := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute ((file.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) : points)) ; execute ("Case #")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def totalSumDivisibleByNum(digit,number): firstnum=pow(10,digit-1) lastnum=pow(10,digit) firstnum=(firstnum-firstnum % number)+number lastnum=(lastnum-lastnum % number) count=((lastnum-firstnum)/number+1) return int(((lastnum+firstnum)*count)/2) digit=3 ; num=7 print(totalSumDivisibleByNum(digit,num)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; digit := 3; var num : int := 7 ; execute (totalSumDivisibleByNum(digit, num))->display(); operation totalSumDivisibleByNum(digit : OclAny, number : OclAny) : OclAny pre: true post: true activity: var firstnum : double := (10)->pow(digit - 1) ; var lastnum : double := (10)->pow(digit) ; firstnum := (firstnum - firstnum mod number) + number ; lastnum := (lastnum - lastnum mod number) ; var count : double := ((lastnum - firstnum) / number + 1) ; return ("" + ((((lastnum + firstnum) * count) / 2)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numberofterm(digit,number): firstnum=pow(10,digit-1) lastnum=pow(10,digit) firstnum=(firstnum-firstnum % number)+number lastnum=(lastnum-lastnum % number) return((lastnum-firstnum)//number+1); n=3 ; number=7 print(numberofterm(n,number)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := 3; number := 7 ; execute (numberofterm(n, number))->display(); operation numberofterm(digit : OclAny, number : OclAny) pre: true post: true activity: var firstnum : double := (10)->pow(digit - 1) ; var lastnum : double := (10)->pow(digit) ; firstnum := (firstnum - firstnum mod number) + number ; lastnum := (lastnum - lastnum mod number) ; return ((lastnum - firstnum) div number + 1);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) E=[[]]*n for i in range(n): inputs=list(map(int,input().split())) if inputs[1]==0 : continue else : for j in inputs[2 :]: E[i]=E[i]+[j-1] beg=[-1]*n fin=[-1]*n t=0 def f(i): global t t+=1 beg[i]=t for c in E[i]: if beg[c]>0 : continue else : f(c) t+=1 fin[i]=t for i in range(n): if beg[i]<0 : f(i) for i in range(n): print(i+1,beg[i],fin[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute t : OclAny; operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var E : Sequence := MatrixLib.elementwiseMult(Sequence{ Sequence{} }, n) ; for i : Integer.subrange(0, n-1) do ( var inputs : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if inputs[1+1] = 0 then ( continue ) else ( for j : inputs.subrange(2+1) do ( E[i+1] := E[i+1]->union(Sequence{ j - 1 })) )) ; var beg : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; var fin : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; var t : int := 0 ; skip ; for i : Integer.subrange(0, n-1) do ( if beg[i+1] < 0 then ( f(i) ) else skip) ; for i : Integer.subrange(0, n-1) do ( execute (i + 1)->display()); operation f(i : OclAny) pre: true post: true activity: skip ; t := t + 1 ; beg[i+1] := t ; for c : E[i+1] do ( if beg[c+1] > 0 then ( continue ) else ( f(c) )) ; t := t + 1 ; fin[i+1] := t; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def conv_list(n): adj_matrix=[] for _ in range(n): adj_list=input().split() adj_list=list(map(int,adj_list)) adj_row=[False]*n if adj_list[1]>0 : for i in adj_list[2 :]: adj_row[i-1]=True adj_matrix.append(adj_row) return adj_matrix def depth_first_search(adj_matrix,n): visited=[None]*n count=1 searched=[None]*n start=0 stack=deque() stack.append(start) visited[start]=1 while count<=2*n : has_edge=adj_matrix[start] i=0 while i0 : start=stack[-1] elif count<2*n : start=visited.index(None) stack.append(start) count+=1 visited[start]=count else : break return visited,searched def main(): n=int(input()) adj_matrix=conv_list(n) visited,searched=depth_first_search(adj_matrix,n) for i in range(n): print("{}{}{}".format(i+1,visited[i],searched[i])) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation conv_list(n : OclAny) : OclAny pre: true post: true activity: var adj_matrix : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var adj_list : OclAny := input().split() ; adj_list := ((adj_list)->collect( _x | (OclType["int"])->apply(_x) )) ; var adj_row : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ; if adj_list[1+1] > 0 then ( for i : adj_list.subrange(2+1) do ( adj_row[i - 1+1] := true) ) else skip ; execute ((adj_row) : adj_matrix)) ; return adj_matrix; operation depth_first_search(adj_matrix : OclAny, n : OclAny) : OclAny pre: true post: true activity: var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; var count : int := 1 ; var searched : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; var start : int := 0 ; var stack : Sequence := () ; execute ((start) : stack) ; visited[start+1] := 1 ; while (count->compareTo(2 * n)) <= 0 do ( var has_edge : OclAny := adj_matrix[start+1] ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( if has_edge[i+1] & visited[i+1] <>= null then ( execute ((i) : stack) ; count := count + 1 ; visited[i+1] := count ; break ) else skip ; i := i + 1) ; if (i->compareTo(n)) < 0 then ( start := i ) else ( var searched_node : OclAny := stack->last() ; stack := stack->front() ; count := count + 1 ; searched[searched_node+1] := count ; if (stack)->size() > 0 then ( start := stack->last() ) else (if (count->compareTo(2 * n)) < 0 then ( start := visited->indexOf(null) - 1 ; execute ((start) : stack) ; count := count + 1 ; visited[start+1] := count ) else ( break ) ) )) ; return visited, searched; operation main() pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; adj_matrix := conv_list(n) ; Sequence{visited,searched} := depth_first_search(adj_matrix, n) ; for i : Integer.subrange(0, n-1) do ( execute (StringLib.interpolateStrings("{}{}{}", Sequence{i + 1, visited[i+1], searched[i+1]}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cin=open(0).read().strip().split('\n') n=int(cin[0]) g=[list(map(lambda x : int(x)-1,a.split(' ')[2 :]))for a in cin[1 :]] first_order=[-1]*n last_order=[-1]*n ptr=1 def dfs(g,seen,idx): global first_order,first_order,ptr first_order[idx]=ptr ptr+=1 seen[idx]=True for i in g[idx]: if seen[i]: continue dfs(g,seen,i) last_order[idx]=ptr ptr+=1 seen=[False]*n dfs(g,seen,0) for i in range(n): if not seen[i]: ans=dfs(g,seen,i) for idx,(f,l)in enumerate(zip(first_order,last_order)): print(idx+1,f,l) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute first_order : OclAny; attribute first_order : OclAny; attribute ptr : OclAny; operation initialise() pre: true post: true activity: var cin : OclAny := open(0).readAll()->trim().split(' ') ; var n : int := ("" + ((cin->first())))->toInteger() ; var g : Sequence := cin->tail()->select(a | true)->collect(a | (((a.split(' ').subrange(2+1))->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) )))) ; var first_order : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; var last_order : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; var ptr : int := 1 ; skip ; seen := MatrixLib.elementwiseMult(Sequence{ false }, n) ; dfs(g, seen, 0) ; for i : Integer.subrange(0, n-1) do ( if not(seen[i+1]) then ( var ans : OclAny := dfs(g, seen, i) ) else skip) ; for _tuple : Integer.subrange(1, (Integer.subrange(1, first_order->size())->collect( _indx | Sequence{first_order->at(_indx), last_order->at(_indx)} ))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(1, first_order->size())->collect( _indx | Sequence{first_order->at(_indx), last_order->at(_indx)} ))->at(_indx)} ) do (var _indx : int := 1; var idx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{f, l} : OclAny := _tuple->at(_indx); execute (idx + 1)->display()); operation dfs(g : OclAny, seen : OclAny, idx : OclAny) pre: true post: true activity: skip; skip; skip ; first_order[idx+1] := ptr ; ptr := ptr + 1 ; seen[idx+1] := true ; for i : g[idx+1] do ( if seen[i+1] then ( continue ) else skip ; dfs(g, seen, i)) ; last_order[idx+1] := ptr ; ptr := ptr + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) graph={} ans=[] np=set(range(1,n+1)) for i in range(n): t=list(map(int,input().split())) v=t[0] k=t[1] graph[v]=[t[i+2]for i in range(k)] np=np-set(graph[v]) ans.append([v,None,None]) class Time : def __init__(self): self.time=0 def getTime(self): self.time+=1 return self.time t=Time() visited=set() def dfs(graph,target): visited.add(target) if ans[target-1][1]is None : ans[target-1][1]=t.getTime() if graph[target]==[]: if ans[target-1][2]is None : ans[target-1][2]=t.getTime() return for v in sorted(graph[target]): if v not in visited : if ans[v-1][1]is None : ans[v-1][1]=t.getTime() visited.add(target) dfs(graph,v) if ans[target-1][2]is None : ans[target-1][2]=t.getTime() if np==set(): np=[1] for v in sorted(list(np)): dfs(graph,v) for row in ans : print(*row) ------------------------------------------------------------ OCL File: --------- class Time { static operation newTime() : Time pre: true post: Time->exists( _x | result = _x ); attribute time : int := 0; operation initialise() : Time pre: true post: true activity: self.time := 0; return self; operation getTime() : OclAny pre: true post: true activity: self.time := self.time + 1 ; return self.time; } class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var graph : OclAny := Set{} ; var ans : Sequence := Sequence{} ; var np : Set := Set{}->union((Integer.subrange(1, n + 1-1))) ; for i : Integer.subrange(0, n-1) do ( var t : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var v : OclAny := t->first() ; var k : OclAny := t[1+1] ; graph[v+1] := Integer.subrange(0, k-1)->select(i | true)->collect(i | (t[i + 2+1])) ; np := np - Set{}->union((graph[v+1])) ; execute ((Sequence{v}->union(Sequence{null}->union(Sequence{ null }))) : ans)) ; skip ; t := (Time.newTime()).initialise() ; var visited : Set := Set{}->union(()) ; skip ; if np = Set{}->union(()) then ( np := Sequence{ 1 } ) else skip ; for v : (np)->sort() do ( dfs(graph, v)) ; for row : ans do ( execute ((argument * (test (logical_test (comparison (expr (atom (name row))))))))->display()); operation dfs(graph : OclAny, target : OclAny) pre: true post: true activity: execute ((target) : visited) ; if ans[target - 1+1][1+1] <>= null then ( ans[target - 1+1][1+1] := t.getTime() ) else skip ; if graph[target+1] = Sequence{} then ( if ans[target - 1+1][2+1] <>= null then ( ans[target - 1+1][2+1] := t.getTime() ) else skip ; return ) else skip ; for v : graph[target+1]->sort() do ( if (visited)->excludes(v) then ( if ans[v - 1+1][1+1] <>= null then ( ans[v - 1+1][1+1] := t.getTime() ) else skip ; execute ((target) : visited) ; dfs(graph, v) ) else skip) ; if ans[target - 1+1][2+1] <>= null then ( ans[target - 1+1][2+1] := t.getTime() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush,heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod=10**9+7 inf=float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) cnt=1 def dfs(x): global cnt if s[x]==None : s[x]=cnt cnt+=1 for v in edges[x]: if s[v]==None : dfs(v) g[x]=cnt cnt+=1 return n=I() edges=[[]for _ in range(n)] for i in range(n): edges[i]=list(map(lambda x : x-1,LI()[2 :])) s=[None]*n g=[None]*n for i in range(n): if s[i]==None : dfs(i) for i in range(n): print(i+1,s[i],g[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute cnt : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; sys.setrecursionlimit(2147483647) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; skip ; skip ; var cnt : int := 1 ; skip ; var n : OclAny := I() ; var edges : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, n-1) do ( edges[i+1] := ((LI().subrange(2+1))->collect( _x | (lambda x : OclAny in (x - 1))->apply(_x) ))) ; var s : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; var g : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = null then ( dfs(i) ) else skip) ; for i : Integer.subrange(0, n-1) do ( execute (i + 1)->display()); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation dfs(x : OclAny) pre: true post: true activity: skip ; if s[x+1] = null then ( s[x+1] := cnt ; cnt := cnt + 1 ) else skip ; for v : edges[x+1] do ( if s[v+1] = null then ( dfs(v) ) else skip) ; g[x+1] := cnt ; cnt := cnt + 1 ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printArray(a,n): for i in a : print(i,end=" ") print() arr=[1,-3,5,6,-3,6,7,-4,9,10] n=len(arr) printArray(arr,n) for i in range(n): if(arr[i]>=0 and i % 2==1): for j in range(i+1,n): if(arr[j]<0 and j % 2==0): arr[i],arr[j]=arr[j],arr[i] break elif(arr[i]<0 and i % 2==0): for j in range(i+1,n): if(arr[j]>=0 and j % 2==1): arr[i],arr[j]=arr[j],arr[i] break printArray(arr,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var arr : Sequence := Sequence{1}->union(Sequence{-3}->union(Sequence{5}->union(Sequence{6}->union(Sequence{-3}->union(Sequence{6}->union(Sequence{7}->union(Sequence{-4}->union(Sequence{9}->union(Sequence{ 10 }))))))))) ; n := (arr)->size() ; printArray(arr, n) ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] >= 0 & i mod 2 = 1) then ( for j : Integer.subrange(i + 1, n-1) do ( if (arr[j+1] < 0 & j mod 2 = 0) then ( var arr[i+1] : OclAny := null; var arr[j+1] : OclAny := null; Sequence{arr[i+1],arr[j+1]} := Sequence{arr[j+1],arr[i+1]} ; break ) else skip) ) else (if (arr[i+1] < 0 & i mod 2 = 0) then ( for j : Integer.subrange(i + 1, n-1) do ( if (arr[j+1] >= 0 & j mod 2 = 1) then ( var arr[i+1] : OclAny := null; var arr[j+1] : OclAny := null; Sequence{arr[i+1],arr[j+1]} := Sequence{arr[j+1],arr[i+1]} ; break ) else skip) ) else skip)) ; printArray(arr, n);; operation printArray(a : OclAny, n : OclAny) pre: true post: true activity: for i : a do ( execute (i)->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def XorSum(arr,n): result=0 for i in range(n): if(arr[i]% 2!=0): result+=arr[i] return result arr=[1,2,6,3,4,5] n=len(arr) print(XorSum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{6}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 }))))) ; n := (arr)->size() ; execute (XorSum(arr, n))->display(); operation XorSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] mod 2 /= 0) then ( result := result + arr[i+1] ) else skip) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import re def main(): s=sys.stdin.read().strip().split('\n') r=[] for x in s[1 :]: ca,cb=0,0 if 'B' not in x or x.endswith('A'): r.append('NO'); continue for i in x : if i=='A' : ca+=1 elif i=='B' : ca-=1 if ca<0 : break r.append(('NO','YES')[ca>=0]) return r print(*main(),sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; execute ((argument * (test (logical_test (comparison (expr (atom (name main)) (trailer (arguments ( )))))))))->display(); operation main() : OclAny pre: true post: true activity: var s : OclAny := sys.stdin.readAll()->trim().split(' ') ; var r : Sequence := Sequence{} ; for x : s->tail() do ( var ca : OclAny := null; var cb : OclAny := null; Sequence{ca,cb} := Sequence{0,0} ; if (x)->excludes('B') or x->hasSuffix('A') then ( execute (('NO') : r); continue ) else skip ; for i : x do ( if i = 'A' then ( ca := ca + 1 ) else (if i = 'B' then ( ca := ca - 1 ; if ca < 0 then ( break ) else skip ) else skip)) ; execute ((Sequence{'NO', 'YES'}->select(ca >= 0)) : r)) ; return r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.stdin=open("input.txt","r") sys.stdout=open("output.txt","w") a=input() t=int(input()) if a=="front" and t==1 : print("L") elif t==1 : print("R") elif a=="front" and t==2 : print("R") else : print("L") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ; var a : String := (OclFile["System.in"]).readLine() ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if a = "front" & t = 1 then ( execute ("L")->display() ) else (if t = 1 then ( execute ("R")->display() ) else (if a = "front" & t = 2 then ( execute ("R")->display() ) else ( execute ("L")->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=open("input.txt","r") f1=open("output.txt","w") a=f.readline() n=f.readline() n=int(n) if a=="front\n" : if n==1 : f1.write("L"); elif n==2 : f1.write("R") elif a=="back\n" : if n==1 : f1.write("R") elif n==2 : f1.write("L") f.close(); f1.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ; var f1 : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ; var a : String := f.readLine() ; var n : String := f.readLine() ; n := ("" + ((n)))->toInteger() ; if a = "front\n" then ( if n = 1 then ( f1.write("L"); ) else (if n = 2 then ( f1.write("R") ) else skip) ) else (if a = "back\n" then ( if n = 1 then ( f1.write("R") ) else (if n = 2 then ( f1.write("L") ) else skip) ) else skip) ; f.closeFile(); f1.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=open("input.txt") a=s.read().split() b=open("output.txt",mode="w") if(a[0][0]=="f")^(bool(int(a[1])-1)): b.write("L") else : b.write("R") s.close() b.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ; var a : OclAny := s.readAll().split() ; var b : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ; if MathLib.bitwiseXor((a->first()->first() = "f"), ((("" + ((a[1+1])))->toInteger() - 1)->toBoolean())) then ( b.write("L") ) else ( b.write("R") ) ; s.closeFile() ; b.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): results={'front1' : 'L','front2' : 'R','back1' : 'R','back2' : 'L'} with open('./input.txt','r')as f : s=f.readline().replace('\n','').replace('','').strip()+f.readline().replace('\n','').replace('','').strip() result=results[s] with open('./output.txt','w')as g : g.write(result) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var results : Map := Map{ 'front1' |-> 'L' }->union(Map{ 'front2' |-> 'R' }->union(Map{ 'back1' |-> 'R' }->union(Map{ 'back2' |-> 'L' }))) ; try (var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('./input.txt')); var s : OclAny := f.readLine().replace(' ', '').replace('', '')->trim() + f.readLine().replace(' ', '').replace('', '')->trim() ; var result : OclAny := results[s+1] ; try (var g : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('./output.txt')); g.write(result)) catch (_e : OclException) do skip) catch (_e : OclException) do skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.stdin=open("input.txt",'r') sys.stdout=open("output.txt",'w') d=input() r=int(input()) if d=="front" : if r==1 : print("L") else : print("R") else : if r==1 : print("R") else : print("L") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ; var d : String := (OclFile["System.in"]).readLine() ; var r : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if d = "front" then ( if r = 1 then ( execute ("L")->display() ) else ( execute ("R")->display() ) ) else ( if r = 1 then ( execute ("R")->display() ) else ( execute ("L")->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def newString(s): l=len(s) freq=[0]*(26) for i in range(0,l): freq[ord(s[i])-ord('a')]+=1 ans="" for i in range(0,26): for j in range(0,freq[i]): ans+=chr(97+i) return ans if __name__=="__main__" : s="aabab" print(newString(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "aabab" ; execute (newString(s))->display() ) else skip; operation newString(s : OclAny) : OclAny pre: true post: true activity: var l : int := (s)->size() ; var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (26)) ; for i : Integer.subrange(0, l-1) do ( freq[(s[i+1])->char2byte() - ('a')->char2byte()+1] := freq[(s[i+1])->char2byte() - ('a')->char2byte()+1] + 1) ; var ans : String := "" ; for i : Integer.subrange(0, 26-1) do ( for j : Integer.subrange(0, freq[i+1]-1) do ( ans := ans + (97 + i)->byte2char())) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- L=int(input()) def divideBin(n): d=1 ans=[] while n>0 : r,q=divmod(n,2) ans.append(q*d) d*=2 n=r return(ans) divided=divideBin(L) N=len(divided) M=2*(N-1)+len([x for x in divided if x!=0])-1 print(N,M) for i in range(1,N): print(i,i+1,0) print(i,i+1,pow(2,i-1)) node=N-1 value=divided[N-1] while node>0 : if divided[node-1]!=0 : print(node,N,value) value+=divided[node-1] node-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var L : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; var divided : OclAny := divideBin(L) ; var N : int := (divided)->size() ; var M : double := 2 * (N - 1) + (divided->select(x | x /= 0)->collect(x | (x)))->size() - 1 ; execute (N)->display() ; for i : Integer.subrange(1, N-1) do ( execute (i)->display() ; execute (i)->display()) ; var node : double := N - 1 ; var value : OclAny := divided[N - 1+1] ; while node > 0 do ( if divided[node - 1+1] /= 0 then ( execute (node)->display() ; value := value + divided[node - 1+1] ) else skip ; node := node - 1); operation divideBin(n : OclAny) : OclAny pre: true post: true activity: var d : int := 1 ; var ans : Sequence := Sequence{} ; while n > 0 do ( var r : OclAny := null; var q : OclAny := null; Sequence{r,q} := Sequence{(n div 2), (n mod 2)} ; execute ((q * d) : ans) ; d := d * 2 ; n := r) ; return (ans); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ge(k,array,ind): return array[ind]>=k def lower_bound(k,array,func=ge): lb=-1 ub=len(array) while ub-lb>1 : mid=(lb+ub)//2 if func(k,array,mid): ub=mid else : lb=mid return ub def lt(k,array,ind): return array[ind]1 : mid=(lb+ub)//2 if func(k,array,mid): lb=mid else : ub=mid return ub-1 def main(): l=int(input()) ans=[] array=[i for i in range(60)] ind=upper_bound(l,array,lambda k,array,mid : 2**mid<=k) r=array[ind] n=r+1 for i in range(1,n): ans.append((i,i+1,0)) ans.append((i,i+1,2**(i-1))) for t in range(n-1,0,-1): if l-2**(t-1)>=2**r : ans.append((t,n,l-2**(t-1))) l-=2**(t-1) print(n,len(ans)) for f,t,c in ans : print(f,t,c) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation ge(k : OclAny, array : OclAny, ind : OclAny) : OclAny pre: true post: true activity: return (array[ind+1]->compareTo(k)) >= 0; operation lower_bound(k : OclAny, array : OclAny, func : OclAny) : OclAny pre: true post: true activity: if func->oclIsUndefined() then func := ge else skip; var lb : int := -1 ; var ub : int := (array)->size() ; while ub - lb > 1 do ( var mid : int := (lb + ub) div 2 ; if func(k, array, mid) then ( ub := mid ) else ( lb := mid )) ; return ub; operation lt(k : OclAny, array : OclAny, ind : OclAny) : OclAny pre: true post: true activity: return (array[ind+1]->compareTo(k)) < 0; operation upper_bound(k : OclAny, array : OclAny, func : OclAny) : OclAny pre: true post: true activity: if func->oclIsUndefined() then func := lt else skip; lb := -1 ; ub := (array)->size() ; while ub - lb > 1 do ( mid := (lb + ub) div 2 ; if func(k, array, mid) then ( lb := mid ) else ( ub := mid )) ; return ub - 1; operation main() pre: true post: true activity: var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; array := Integer.subrange(0, 60-1)->select(i | true)->collect(i | (i)) ; ind := upper_bound(l, array, lambda k : OclAny, array : OclAny, mid : OclAny in (((2)->pow(mid)->compareTo(k)) <= 0)) ; var r : OclAny := array[ind+1] ; var n : OclAny := r + 1 ; for i : Integer.subrange(1, n-1) do ( execute ((Sequence{i, i + 1, 0}) : ans) ; execute ((Sequence{i, i + 1, (2)->pow((i - 1))}) : ans)) ; for t : Integer.subrange(0 + 1, n - 1)->reverse() do ( if (l - (2)->pow((t - 1))->compareTo((2)->pow(r))) >= 0 then ( execute ((Sequence{t, n, l - (2)->pow((t - 1))}) : ans) ; l := l - (2)->pow((t - 1)) ) else skip) ; execute (n)->display() ; for _tuple : ans do (var _indx : int := 1; var f : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); execute (f)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- L=int(input()); S=bin(L); N=len(S)-2 ; print(N,2*N+S.count("1")-3) for i in range(N-1): print(i+1,i+2,0,"\n"+str(i+1),i+2,2**i) if S[N+1-i]=="1" : L-=2**i ; print(i+1,N,L) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var L : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var S : OclAny := bin(L); var N : double := (S)->size() - 2; execute (N)->display() ; for i : Integer.subrange(0, N - 1-1) do ( execute (i + 1)->display() ; if S[N + 1 - i+1] = "1" then ( L := L - (2)->pow(i); execute (i + 1)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math l=int(input()) n=int(math.log2(l))+1 m=0 ed=[] for i in range(n,1,-1): if l % 2 : ed.append([1,i,l-1]) m+=1 l-=1 m+=2 ed.append([i-1,i,0]) ed.append([i-1,i,l//2]) l=l//2 print(n,m) for i in ed : print(i[0],i[1],i[2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := ("" + (()))->toInteger() + 1 ; var m : int := 0 ; var ed : Sequence := Sequence{} ; for i : Integer.subrange(1 + 1, n)->reverse() do ( if l mod 2 then ( execute ((Sequence{1}->union(Sequence{i}->union(Sequence{ l - 1 }))) : ed) ; m := m + 1 ; l := l - 1 ) else skip ; m := m + 2 ; execute ((Sequence{i - 1}->union(Sequence{i}->union(Sequence{ 0 }))) : ed) ; execute ((Sequence{i - 1}->union(Sequence{i}->union(Sequence{ l div 2 }))) : ed) ; l := l div 2) ; execute (n)->display() ; for i : ed do ( execute (i->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): s=input() b=0 bad=False if s[-1]=="A" : bad=True for c in s : if c=='B' : b-=1 else : b+=1 if b<0 : bad=True break print("NO" if bad else "YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var b : int := 0 ; var bad : boolean := false ; if s->last() = "A" then ( bad := true ) else skip ; for c : s->characters() do ( if c = 'B' then ( b := b - 1 ) else ( b := b + 1 ) ; if b < 0 then ( bad := true ; break ) else skip) ; execute (if bad then "NO" else "YES" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() t=input() l=['a','e','i','o','u'] if len(s)!=len(t): print('NO') else : c=k=0 for i in range(len(s)): if s[i]in l : if t[i]in l : c+=1 if s[i]not in l : if t[i]not in l : k+=1 if c+k==len(s): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var l : Sequence := Sequence{'a'}->union(Sequence{'e'}->union(Sequence{'i'}->union(Sequence{'o'}->union(Sequence{ 'u' })))) ; if (s)->size() /= (t)->size() then ( execute ('NO')->display() ) else ( var c : OclAny := 0; var k : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if (l)->includes(s[i+1]) then ( if (l)->includes(t[i+1]) then ( c := c + 1 ) else skip ) else skip ; if (l)->excludes(s[i+1]) then ( if (l)->excludes(t[i+1]) then ( k := k + 1 ) else skip ) else skip) ; if c + k = (s)->size() then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ll=int(input()) l=ll-1 bb=format(l,'b') x=len(bb)-1 ans=[] for i in range(x): ans.append((i+1,i+2,0)) ans.append((i+1,i+2,2**(x-i-1))) a=l-2**x+1 acum=2**x n=x+1 while a!=0 : bb=format(a,'b') y=len(bb)-1 if x+1-y==1 : ans.append((x+1,x+2,0)) ans.append((x+1,x+2,2**x)) n+=1 a=0 else : ans.append((1,x+1-y,acum)) a=a-2**y acum+=2**y m=len(ans) print(n,m) for a,b,c in ans : print(a,b,c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ll : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : double := ll - 1 ; var bb : String := (l + "") ; var x : double := (bb)->size() - 1 ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, x-1) do ( execute ((Sequence{i + 1, i + 2, 0}) : ans) ; execute ((Sequence{i + 1, i + 2, (2)->pow((x - i - 1))}) : ans)) ; var a : double := l - (2)->pow(x) + 1 ; var acum : double := (2)->pow(x) ; var n : OclAny := x + 1 ; while a /= 0 do ( bb := (a + "") ; var y : double := (bb)->size() - 1 ; if x + 1 - y = 1 then ( execute ((Sequence{x + 1, x + 2, 0}) : ans) ; execute ((Sequence{x + 1, x + 2, (2)->pow(x)}) : ans) ; n := n + 1 ; a := 0 ) else ( execute ((Sequence{1, x + 1 - y, acum}) : ans) ; a := a - (2)->pow(y) ; acum := acum + (2)->pow(y) )) ; var m : int := (ans)->size() ; execute (n)->display() ; for _tuple : ans do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=int(input()) if(i % 10)<5 : print(i-(i % 10)) else : print(i+(10-(i % 10))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (i mod 10) < 5 then ( execute (i - (i mod 10))->display() ) else ( execute (i + (10 - (i mod 10)))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() if len(s)==1 : if int(s)<=5 : print(0) else : print('10') else : a=int(s[len(s)-1]) if a==0 : print(s) elif a>0 and a<=5 : print(int(s)-a) else : b=10-a print(int(s)+b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; if (s)->size() = 1 then ( if ("" + ((s)))->toInteger() <= 5 then ( execute (0)->display() ) else ( execute ('10')->display() ) ) else ( var a : int := ("" + ((s[(s)->size() - 1+1])))->toInteger() ; if a = 0 then ( execute (s)->display() ) else (if a > 0 & a <= 5 then ( execute (("" + ((s)))->toInteger() - a)->display() ) else ( var b : double := 10 - a ; execute (("" + ((s)))->toInteger() + b)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=str(n) if n % 10!=0 : if int(s[-1])<=5 : print(n-(int(s[-1]))) else : p=10-(int(s[-1])) print(n+p) else : print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := ("" + ((n))) ; if n mod 10 /= 0 then ( if ("" + ((s->last())))->toInteger() <= 5 then ( execute (n - (("" + ((s->last())))->toInteger()))->display() ) else ( var p : double := 10 - (("" + ((s->last())))->toInteger()) ; execute (n + p)->display() ) ) else ( execute (n)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(round(int(input()),-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (MathLib.roundN(("" + (((OclFile["System.in"]).readLine())))->toInteger(), -1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 10==0 : print(n) elif n % 10>=5 : print(n+(10-n % 10)) else : print(n-n % 10) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 10 = 0 then ( execute (n)->display() ) else (if n mod 10 >= 5 then ( execute (n + (10 - n mod 10))->display() ) else ( execute (n - n mod 10)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSum(N): return((N*(N+1)*(2*N-5)+4*N)/2) if __name__=='__main__' : N=3 print(findSum(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( N := 3 ; execute (findSum(N))->display() ) else skip; operation findSum(N : OclAny) : OclAny pre: true post: true activity: return ((N * (N + 1) * (2 * N - 5) + 4 * N) / 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSum(N): return(2*N*(N+1)*(4*N+17)+54*N)/6 if __name__=='__main__' : N=4 print(findSum(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( N := 4 ; execute (findSum(N))->display() ) else skip; operation findSum(N : OclAny) : OclAny pre: true post: true activity: return (2 * N * (N + 1) * (4 * N + 17) + 54 * N) / 6; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- fib=[0]*100005 ; def computeFibonacci(): fib[0]=1 ; fib[1]=1 ; for i in range(2,100005): fib[i]=fib[i-1]+fib[i-2]; def countString(string): ans=1 ; cnt=1 ; for i in range(1,len(string)): if(string[i]==string[i-1]): cnt+=1 ; else : ans=ans*fib[cnt]; cnt=1 ; ans=ans*fib[cnt]; return ans ; if __name__=="__main__" : string="abdllldefkkkk" ; computeFibonacci(); print(countString(string)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var fib : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100005); ; skip ; skip ; if __name__ = "__main__" then ( string := "abdllldefkkkk"; ; computeFibonacci(); ; execute (countString(string))->display(); ) else skip; operation computeFibonacci() pre: true post: true activity: fib->first() := 1; ; fib[1+1] := 1; ; for i : Integer.subrange(2, 100005-1) do ( fib[i+1] := fib[i - 1+1] + fib[i - 2+1];); operation countString(string : OclAny) pre: true post: true activity: var ans : int := 1; ; var cnt : int := 1; ; for i : Integer.subrange(1, (string)->size()-1) do ( if (string[i+1] = string[i - 1+1]) then ( cnt := cnt + 1; ) else ( ans := ans * fib[cnt+1]; ; cnt := 1; )) ; ans := ans * fib[cnt+1]; ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n,m=map(int,input().split()) if n<=0 and m>0 : print("Impossible") return r=n if m-n>0 : r+=m-n r2=n if m-1>0 : r2+=m-1 print(f"{r}{r2}") solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n <= 0 & m > 0 then ( execute ("Impossible")->display() ; return ) else skip ; var r : OclAny := n ; if m - n > 0 then ( r := r + m - n ) else skip ; var r2 : OclAny := n ; if m - 1 > 0 then ( r2 := r2 + m - 1 ) else skip ; execute (StringLib.formattedString("{r}{r2}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ma=[] for i in range(n): x=input() k=0 if x[-1]=='B' and x[0]=='A' : for j in x : if j=='A' : k+=1 if j=='B' : k-=1 if k<0 : ma.append('NO') break if k>=0 : ma.append('YES') else : ma.append('NO') for i in ma : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ma : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x : String := (OclFile["System.in"]).readLine() ; var k : int := 0 ; if x->last() = 'B' & x->first() = 'A' then ( for j : x->characters() do ( if j = 'A' then ( k := k + 1 ) else skip ; if j = 'B' then ( k := k - 1 ) else skip ; if k < 0 then ( execute (('NO') : ma) ; break ) else skip) ; if k >= 0 then ( execute (('YES') : ma) ) else skip ) else ( execute (('NO') : ma) )) ; for i : ma do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=3 def minSteps(arr): v=[[0 for i in range(n)]for j in range(n)] q=[[0,0]] depth=0 while(len(q)!=0): x=len(q) while(x>0): y=q[0] i=y[0] j=y[1] q.remove(q[0]) x-=1 if(v[i][j]): continue if(i==n-1 and j==n-1): return depth v[i][j]=1 if(i+arr[i][j]union(Sequence{1}->union(Sequence{ 1 }))}->union(Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))}->union(Sequence{ Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })) })) ; execute (minSteps(arr))->display() ) else skip; operation minSteps(arr : OclAny) : OclAny pre: true post: true activity: var v : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)))) ; var q : Sequence := Sequence{ Sequence{0}->union(Sequence{ 0 }) } ; var depth : int := 0 ; while ((q)->size() /= 0) do ( var x : int := (q)->size() ; while (x > 0) do ( var y : OclAny := q->first() ; var i : OclAny := y->first() ; var j : OclAny := y[1+1] ; execute ((q->first()) /: q) ; x := x - 1 ; if (v[i+1][j+1]) then ( continue ) else skip ; if (i = n - 1 & j = n - 1) then ( return depth ) else skip ; v[i+1][j+1] := 1 ; if ((i + arr[i+1][j+1]->compareTo(n)) < 0) then ( execute ((Sequence{i + arr[i+1][j+1]}->union(Sequence{ j })) : q) ) else skip ; if ((j + arr[i+1][j+1]->compareTo(n)) < 0) then ( execute ((Sequence{i}->union(Sequence{ j + arr[i+1][j+1] })) : q) ) else skip) ; depth := depth + 1) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A=input().lower() B=input().lower() c1=0 c2=0 c3=0 v=['a','e','i','o','u'] if(len(A)!=len(B)): print("NO") exit() for j in range(0,len(A)): if A[j]in v and B[j]not in v : print("NO") exit() elif B[j]in v and A[j]not in v : print("NO") exit() print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := input()->toLowerCase() ; var B : OclAny := input()->toLowerCase() ; var c1 : int := 0 ; var c2 : int := 0 ; var c3 : int := 0 ; var v : Sequence := Sequence{'a'}->union(Sequence{'e'}->union(Sequence{'i'}->union(Sequence{'o'}->union(Sequence{ 'u' })))) ; if ((A)->size() /= (B)->size()) then ( execute ("NO")->display() ; exit() ) else skip ; for j : Integer.subrange(0, (A)->size()-1) do ( if (v)->includes(A[j+1]) & (v)->excludes(B[j+1]) then ( execute ("NO")->display() ; exit() ) else (if (v)->includes(B[j+1]) & (v)->excludes(A[j+1]) then ( execute ("NO")->display() ; exit() ) else skip)) ; execute ("YES")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reArrange(words,n): mp={} for i in range(n): mp[words[i]]=i+1 words.sort(); for i in range(n): print(mp[words[i]],end=" ") words=["live","place","travel","word","sky"] n=len(words) reArrange(words,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; words := Sequence{"live"}->union(Sequence{"place"}->union(Sequence{"travel"}->union(Sequence{"word"}->union(Sequence{ "sky" })))) ; n := (words)->size() ; reArrange(words, n);; operation reArrange(words : OclAny, n : OclAny) pre: true post: true activity: var mp : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( mp[words[i+1]+1] := i + 1) ; words := words->sort(); ; for i : Integer.subrange(0, n-1) do ( execute (mp[words[i+1]+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find_Solution(x,n): Sum=x e=2 o=1 p=1 for i in range(2,n+1): p+=2 Sum+=(o/e)*(pow(x,p)/p) o=o*(o+2) e=e*(e+2) print(round(Sum,10)) x=-0.5 if(abs(x)>=1): print("Invalid Input\n") n=8 find_Solution(x,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := -0.5 ; if ((x)->abs() >= 1) then ( execute ("Invalid Input\n")->display() ) else skip ; n := 8 ; find_Solution(x, n); operation find_Solution(x : OclAny, n : OclAny) pre: true post: true activity: var Sum : OclAny := x ; var e : int := 2 ; var o : int := 1 ; var p : int := 1 ; for i : Integer.subrange(2, n + 1-1) do ( p := p + 2 ; Sum := Sum + (o / e) * ((x)->pow(p) / p) ; o := o * (o + 2) ; e := e * (e + 2)) ; execute (MathLib.roundN(Sum, 10))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) intervals=[] for i in range(n): l,r=map(int,input().split()) intervals.append((l,r)) intervals.sort(key=lambda interval : interval[1]) r0=intervals[0][1] ans=1 for i in range(1,n): if intervals[i][0]>r0 : ans+=1 r0=intervals[i][1] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var intervals : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{l, r}) : intervals)) ; intervals := intervals->sort() ; var r0 : OclAny := intervals->first()[1+1] ; var ans : int := 1 ; for i : Integer.subrange(1, n-1) do ( if (intervals[i+1]->first()->compareTo(r0)) > 0 then ( ans := ans + 1 ; r0 := intervals[i+1][1+1] ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=d=0 t=[list(map(int,input().split()))for i in range(int(input()))] for l,r in sorted(t,key=lambda q : q[1]): if l>d : s,d=s+1,r print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := 0; var d : int := 0 ; var t : Sequence := Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for _tuple : t->sortedBy($x | (lambda q : OclAny in (q[1+1]))->apply($x)) do (var _indx : int := 1; var l : OclAny := _tuple->at(_indx); _indx := _indx + 1; var r : OclAny := _tuple->at(_indx); if (l->compareTo(d)) > 0 then ( Sequence{s,d} := Sequence{s + 1,r} ) else skip) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sort(t): _,x2=t return x2 def solve(ls): ls.sort(key=sort) curr=ls[0][1] out=1 for elm in ls[1 :]: a,b=elm if a>curr : out+=1 curr=b return out n=int(input()) ls=[] for i in range(n): s,l=map(int,input().split()) ls.append((s,l)) print(solve(ls)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; ls := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var s : OclAny := null; var l : OclAny := null; Sequence{s,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{s, l}) : ls)) ; execute (solve(ls))->display(); operation sort(t : OclAny) : OclAny pre: true post: true activity: var _anon : OclAny := null; var x2 : OclAny := null; Sequence{_anon,x2} := t ; return x2; operation solve(ls : OclAny) : OclAny pre: true post: true activity: ls := ls->sort() ; var curr : OclAny := ls->first()[1+1] ; var out : int := 1 ; for elm : ls->tail() do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := elm ; if (a->compareTo(curr)) > 0 then ( out := out + 1 ; curr := b ) else skip) ; return out; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(ls): ls.sort(key=lambda a : a[1]) curr=ls[0][1] out=1 for elm in ls[1 :]: if elm[0]>curr : out+=1 curr=elm[1] return out n=int(input()) ls=[] for i in range(n): s,l=map(int,input().split()) ls.append([s,l]) print(solve(ls)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; ls := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var s : OclAny := null; var l : OclAny := null; Sequence{s,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{s}->union(Sequence{ l })) : ls)) ; execute (solve(ls))->display(); operation solve(ls : OclAny) : OclAny pre: true post: true activity: ls := ls->sort() ; var curr : OclAny := ls->first()[1+1] ; var out : int := 1 ; for elm : ls->tail() do ( if (elm->first()->compareTo(curr)) > 0 then ( out := out + 1 ; curr := elm[1+1] ) else skip) ; return out; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def mySort(arr): n=len(arr); arr1=arr[: n//2] arr2=arr[n//2 :] arr1.sort() arr2.sort() arr=arr1+arr2 low=n//2 ; high=n-1 ; while(lowunion(Sequence{4}->union(Sequence{6}->union(Sequence{2}->union(Sequence{1}->union(Sequence{3}->union(Sequence{8}->union(Sequence{9}->union(Sequence{ 7 })))))))); ; arr := mySort(arr); ; execute ("Modified Array : ")->display() ; execute (arr)->display() ) else skip; operation mySort(arr : OclAny) pre: true post: true activity: var n : int := (arr)->size(); ; var arr1 : OclAny := arr.subrange(1,n div 2) ; var arr2 : OclAny := arr.subrange(n div 2+1) ; arr1 := arr1->sort() ; arr2 := arr2->sort() ; arr := arr1 + arr2 ; var low : int := n div 2; ; var high : double := n - 1; ; while ((low->compareTo(high)) < 0) do ( var temp : OclAny := arr[low+1]; ; arr[low+1] := arr[high+1]; ; arr[high+1] := temp; ; low := low + 1; ; high := high - 1;) ; return arr;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def min_subarray(a,n): st=[]; for i in range(n): count=1 ; while len(st)!=0 and st[-1][0]>a[i]: count+=st[-1][1]; st.pop(); st.append((a[i],count)); print(count,end=" "); if __name__=="__main__" : a=[5,4,3,2,1]; n=len(a); min_subarray(a,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{5}->union(Sequence{4}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 1 })))); ; n := (a)->size(); ; min_subarray(a, n); ) else skip; operation min_subarray(a : OclAny, n : OclAny) pre: true post: true activity: var st : Sequence := Sequence{}; ; for i : Integer.subrange(0, n-1) do ( var count : int := 1; ; while (st)->size() /= 0 & (st->last()->first()->compareTo(a[i+1])) > 0 do ( count := count + st->last()[1+1]; ; st := st->front();) ; execute ((Sequence{a[i+1], count}) : st); ; execute (count)->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): s=str(input()) cnt=0 flag=(s[len(s)-1]=='B') flag*=len(s)>1 for j in range(len(s)): if s[j]=='A' : cnt+=1 else : cnt-=1 if cnt<0 : flag=0 if flag : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; var cnt : int := 0 ; var flag : boolean := (s[(s)->size() - 1+1] = 'B') ; flag := flag * (s)->size() > 1 ; for j : Integer.subrange(0, (s)->size()-1) do ( if s[j+1] = 'A' then ( cnt := cnt + 1 ) else ( cnt := cnt - 1 ) ; if cnt < 0 then ( flag := 0 ) else skip) ; if flag then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def getMin(arr,n,k): res=sys.maxsize for i in range(n): if(arr[i]% k==0): res=min(res,arr[i]) return res def getMax(arr,n,k): res=0 for i in range(1,n): if(arr[i]% k==0): res=max(res,arr[i]) return res if __name__=="__main__" : arr=[10,1230,45,67,1] k=10 n=len(arr) print("Minimum element of array which","is divisible by k: ",getMin(arr,n,k)) print("Maximum element of array which","is divisible by k: ",getMax(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{10}->union(Sequence{1230}->union(Sequence{45}->union(Sequence{67}->union(Sequence{ 1 })))) ; k := 10 ; n := (arr)->size() ; execute ("Minimum element of array which")->display() ; execute ("Maximum element of array which")->display() ) else skip; operation getMin(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var res : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] mod k = 0) then ( res := Set{res, arr[i+1]}->min() ) else skip) ; return res; operation getMax(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: res := 0 ; for i : Integer.subrange(1, n-1) do ( if (arr[i+1] mod k = 0) then ( res := Set{res, arr[i+1]}->max() ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- rr=[0,0,0,1,1,1,2,2,2] cc=[0,1,2,0,1,2,0,1,2] A=ord('A') for i in range(1000): buf=list(input()) j=0 r,c=rr[ord(buf[j])-A],cc[ord(buf[j])-A] j,f=j+1,True while junion(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 2 })))))))) ; var cc : Sequence := Sequence{0}->union(Sequence{1}->union(Sequence{2}->union(Sequence{0}->union(Sequence{1}->union(Sequence{2}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 2 })))))))) ; var A : int := ('A')->char2byte() ; for i : Integer.subrange(0, 1000-1) do ( var buf : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var j : int := 0 ; var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := Sequence{rr[(buf[j+1])->char2byte() - A+1],cc[(buf[j+1])->char2byte() - A+1]} ; var f : OclAny := null; Sequence{j,f} := Sequence{j + 1,true} ; while (j->compareTo((buf)->size())) < 0 & f do ( var f : boolean := false ; var r2 : OclAny := null; var c2 : OclAny := null; Sequence{r2,c2} := Sequence{rr[(buf[j+1])->char2byte() - A+1],cc[(buf[j+1])->char2byte() - A+1]} ; j := j + 1 ; if r2 = r then ( if c2 = c + 1 or c2 = c - 1 then ( f := true ) else skip ) else (if c2 = c then ( if r2 = r + 1 or r2 = r - 1 then ( f := true ) else skip ) else skip) ; var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := Sequence{r2,c2}) ; if f then ( execute ((argument * (test (logical_test (comparison (expr (atom (name buf))))))))->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l1=['a','e','i','o','u'] l2=[] for i in range(97,97+26): if chr(i)not in l1 : l2+=chr(i) a=input() b=input() c=0 if len(a)==len(b): for i in range(min(len(a),len(b))): if a[i]in l1 and b[i]in l1 : c+=1 elif a[i]in l2 and b[i]in l2 : c+=1 else : break if c==min(len(a),len(b)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l1 : Sequence := Sequence{'a'}->union(Sequence{'e'}->union(Sequence{'i'}->union(Sequence{'o'}->union(Sequence{ 'u' })))) ; var l2 : Sequence := Sequence{} ; for i : Integer.subrange(97, 97 + 26-1) do ( if (l1)->excludes((i)->byte2char()) then ( l2 := l2 + (i)->byte2char() ) else skip) ; var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var c : int := 0 ; if (a)->size() = (b)->size() then ( for i : Integer.subrange(0, Set{(a)->size(), (b)->size()}->min()-1) do ( if (l1)->includes(a[i+1]) & (l1)->includes(b[i+1]) then ( c := c + 1 ) else (if (l2)->includes(a[i+1]) & (l2)->includes(b[i+1]) then ( c := c + 1 ) else ( break ) ) ) ) else skip ; if c = Set{(a)->size(), (b)->size()}->min() then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dic={} dic["A"]="BD" dic["B"]="ACE" dic["C"]="BF" dic["D"]="AEG" dic["E"]="BDFH" dic["F"]="CEI" dic["G"]="DH" dic["H"]="EGI" dic["I"]="FH" results=[] for i in range(1000): pwd=input() frag=1 for j in range(len(pwd)-1): if pwd[j]in dic[pwd[j+1]]: a=1 else : frag=0 break if frag : results.append(pwd) for i in range(len(results)): print(results[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dic : OclAny := Set{} ; dic->at("A") := "BD" ; dic->at("B") := "ACE" ; dic->at("C") := "BF" ; dic->at("D") := "AEG" ; dic->at("E") := "BDFH" ; dic->at("F") := "CEI" ; dic->at("G") := "DH" ; dic->at("H") := "EGI" ; dic->at("I") := "FH" ; var results : Sequence := Sequence{} ; for i : Integer.subrange(0, 1000-1) do ( var pwd : String := (OclFile["System.in"]).readLine() ; var frag : int := 1 ; for j : Integer.subrange(0, (pwd)->size() - 1-1) do ( if (dic[pwd[j + 1+1]+1])->includes(pwd[j+1]) then ( var a : int := 1 ) else ( frag := 0 ; break )) ; if frag then ( execute ((pwd) : results) ) else skip) ; for i : Integer.subrange(0, (results)->size()-1) do ( execute (results[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=1000 A=["B","D"] B=["A","C","E"] C=["B","F"] D=["A","E","G"] E=["B","D","F","H"] F=["C","E","I"] G=["D","H"] H=["E","G","I"] I=["F","H"] def check(string): if len(string)==1 : return True for i in range(len(string)-1): if string[i]=="A" and not(string[i+1]in A): return False if string[i]=="B" and not(string[i+1]in B): return False if string[i]=="C" and not(string[i+1]in C): return False if string[i]=="D" and not(string[i+1]in D): return False if string[i]=="E" and not(string[i+1]in E): return False if string[i]=="F" and not(string[i+1]in F): return False if string[i]=="G" and not(string[i+1]in G): return False if string[i]=="H" and not(string[i+1]in H): return False if string[i]=="I" and not(string[i+1]in I): return False return True for i in range(N): s=str(input()) if check(s): print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 1000 ; var A : Sequence := Sequence{"B"}->union(Sequence{ "D" }) ; var B : Sequence := Sequence{"A"}->union(Sequence{"C"}->union(Sequence{ "E" })) ; var C : Sequence := Sequence{"B"}->union(Sequence{ "F" }) ; var D : Sequence := Sequence{"A"}->union(Sequence{"E"}->union(Sequence{ "G" })) ; var E : Sequence := Sequence{"B"}->union(Sequence{"D"}->union(Sequence{"F"}->union(Sequence{ "H" }))) ; var F : Sequence := Sequence{"C"}->union(Sequence{"E"}->union(Sequence{ "I" })) ; var G : Sequence := Sequence{"D"}->union(Sequence{ "H" }) ; var H : Sequence := Sequence{"E"}->union(Sequence{"G"}->union(Sequence{ "I" })) ; var I : Sequence := Sequence{"F"}->union(Sequence{ "H" }) ; skip ; for i : Integer.subrange(0, N-1) do ( var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; if check(s) then ( execute (s)->display() ) else skip); operation check(string : OclAny) : OclAny pre: true post: true activity: if (string)->size() = 1 then ( return true ) else skip ; for i : Integer.subrange(0, (string)->size() - 1-1) do ( if string[i+1] = "A" & not(((A)->includes(string[i + 1+1]))) then ( return false ) else skip ; if string[i+1] = "B" & not(((B)->includes(string[i + 1+1]))) then ( return false ) else skip ; if string[i+1] = "C" & not(((C)->includes(string[i + 1+1]))) then ( return false ) else skip ; if string[i+1] = "D" & not(((D)->includes(string[i + 1+1]))) then ( return false ) else skip ; if string[i+1] = "E" & not(((E)->includes(string[i + 1+1]))) then ( return false ) else skip ; if string[i+1] = "F" & not(((F)->includes(string[i + 1+1]))) then ( return false ) else skip ; if string[i+1] = "G" & not(((G)->includes(string[i + 1+1]))) then ( return false ) else skip ; if string[i+1] = "H" & not(((H)->includes(string[i + 1+1]))) then ( return false ) else skip ; if string[i+1] = "I" & not(((I)->includes(string[i + 1+1]))) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxSumArrangement(A,R,N,M): count=[0 for i in range(N)] for i in range(M): l=R[i][0] r=R[i][1]+1 l=l-1 r=r-1 count[l]=count[l]+1 if(runion(Sequence{6}->union(Sequence{10}->union(Sequence{1}->union(Sequence{5}->union(Sequence{ 6 }))))) ; R := Sequence{Sequence{1}->union(Sequence{ 3 })}->union(Sequence{Sequence{4}->union(Sequence{ 6 })}->union(Sequence{ Sequence{3}->union(Sequence{ 4 }) })) ; N := (A)->size() ; M := (R)->size() ; execute (maxSumArrangement(A, R, N, M))->display(); operation maxSumArrangement(A : OclAny, R : OclAny, N : OclAny, M : OclAny) : OclAny pre: true post: true activity: var count : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, M-1) do ( var l : OclAny := R[i+1]->first() ; var r : OclAny := R[i+1][1+1] + 1 ; l := l - 1 ; r := r - 1 ; count[l+1] := count[l+1] + 1 ; if ((r->compareTo(N)) < 0) then ( count[r+1] := count[r+1] - 1 ) else skip) ; for i : Integer.subrange(1, N-1) do ( count[i+1] := count[i+1] + count[i - 1+1]) ; var ans : int := 0 ; count := count->sort() ; A := A->sort() ; for i : Integer.subrange(-1 + 1, N - 1)->reverse() do ( ans := ans + A[i+1] * count[i+1]) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def product_subarrays(arr,n): product=1 ; for i in range(n): for j in range(i,n): product*=arr[j]; print(product); if __name__=='__main__' : arr=[10,3,7]; n=len(arr); product_subarrays(arr,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{10}->union(Sequence{3}->union(Sequence{ 7 })); ; n := (arr)->size(); ; product_subarrays(arr, n); ) else skip; operation product_subarrays(arr : OclAny, n : OclAny) pre: true post: true activity: var product : int := 1; ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i, n-1) do ( product := product * arr[j+1];)) ; execute (product)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=[] while True : try : m.append(float(input())) except : print(max(m)-min(m)) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : Sequence := Sequence{} ; while true do ( try ( execute ((("" + (((OclFile["System.in"]).readLine())))->toReal()) : m)) catch (_e : OclException) do ( execute ((m)->max() - (m)->min())->display() ; break) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import string import collections import fractions import random from operator import itemgetter import itertools from collections import deque import copy import heapq import bisect MOD=10**9+7 INF=float('inf') input=lambda : sys.stdin.readline().strip() sys.setrecursionlimit(10**8) height=list(map(float,open(0).read().split())) print(max(height)-min(height)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var MOD : double := (10)->pow(9) + 7 ; var INF : double := ("" + (('inf')))->toReal() ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine()->trim()) ; sys.setrecursionlimit((10)->pow(8)) ; var height : Sequence := ((open(0).readAll().split())->collect( _x | (OclType["double"])->apply(_x) )) ; execute ((height)->max() - (height)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import(division,absolute_import,print_function,unicode_literals) from sys import stdin upper=lower=float(stdin.readline()) for line in stdin : h=float(line) if h>upper : upper=h elif htoReal(); var lower : double := ("" + ((stdin.readLine())))->toReal() ; for line : stdin do ( var h : double := ("" + ((line)))->toReal() ; if (h->compareTo(upper)) > 0 then ( upper := h ) else (if (h->compareTo(lower)) < 0 then ( lower := h ) else skip)) ; execute (upper - lower)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def first_substring(s): n=len(s); c=0 ; mpp={}; for i in range(n): if(s[i]==' ' or s[i]=='#'): s1=s[c : i]; mpp[s1]=1 ; c=i+1 ; for i in range(n): if(s[i]==' '): continue ; for j in range(n): if(s[j]==' '): break ; s1=s[i : j+1]; s2=s1 ; s1=s1[: :-1]; if s1 in mpp : if mpp[s1]: return s2 ; return "-1" ; if __name__=="__main__" : s="mango is sweet when nam en tastes it#" ; s1=first_substring(s); print(s1); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "mango is sweet when nam en tastes it#"; ; s1 := first_substring(s); ; execute (s1)->display(); ) else skip; operation first_substring(s : OclAny) pre: true post: true activity: var n : int := (s)->size(); var c : int := 0; ; var mpp : OclAny := Set{}; ; for i : Integer.subrange(0, n-1) do ( if (s[i+1] = ' ' or s[i+1] = '#') then ( var s1 : OclAny := s.subrange(c+1, i); ; mpp[s1+1] := 1; ; c := i + 1; ) else skip) ; for i : Integer.subrange(0, n-1) do ( if (s[i+1] = ' ') then ( continue; ) else skip ; for j : Integer.subrange(0, n-1) do ( if (s[j+1] = ' ') then ( break; ) else skip ; s1 := s.subrange(i+1, j + 1); ; var s2 : OclAny := s1; ; s1 := s1(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); ; if (mpp)->includes(s1) then ( if mpp[s1+1] then ( return s2; ) else skip ) else skip)) ; return "-1";; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") heights=[float(line)for line in sys.stdin] diff=max(heights)-min(heights) print(diff) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; var heights : Sequence := OclFile["System.in"]->select(line | true)->collect(line | (("" + ((line)))->toReal())) ; var diff : double := (heights)->max() - (heights)->min() ; execute (diff)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math maxv=0 minv=math.inf for i in map(float,sys.stdin): maxv=max([i,maxv]) minv=min([i,minv]) print(maxv-minv) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var maxv : int := 0 ; var minv : OclAny := ; for i : (OclFile["System.in"])->collect( _x | (OclType["double"])->apply(_x) ) do ( maxv := (Sequence{i}->union(Sequence{ maxv }))->max() ; minv := (Sequence{i}->union(Sequence{ minv }))->min()) ; execute (maxv - minv)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printAns(ans): for i in range(len(ans)): if i==0 : print(ans[i],end="") else : print("",end="") print(ans[i],end="") print("") N=int(input()) for l in range(N): a,b=[int(i)for i in input().split()] ans=[] if atoInteger() ; for l : Integer.subrange(0, N-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; ans := Sequence{} ; if (a->compareTo(b)) < 0 then ( for i : Integer.subrange(a, b + 1-1) do ( execute ((i) : ans)) ) else ( if a <= 5 then ( for i : Integer.subrange(b - 1 + 1, a)->reverse() do ( execute ((i) : ans)) ) else ( if b <= 5 then ( for i : Integer.subrange(a, 10-1) do ( execute ((i) : ans)) ; for i : Integer.subrange(b - 1 + 1, 5)->reverse() do ( execute ((i) : ans)) ) else ( for i : Integer.subrange(a, 10-1) do ( execute ((i) : ans)) ; for i : Integer.subrange(0 + 1, 5)->reverse() do ( execute ((i) : ans)) ; for i : Integer.subrange(0, b + 1-1) do ( execute ((i) : ans)) ) ) ) ; printAns(ans)); operation printAns(ans : OclAny) pre: true post: true activity: for i : Integer.subrange(0, (ans)->size()-1) do ( if i = 0 then ( execute (ans[i+1])->display() ) else ( execute ("")->display() ; execute (ans[i+1])->display() )) ; execute ("")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s,t,v=input(),input(),"aeiou" if len(s)!=len(t): print("No") else : f=0 for i in range(len(s)): if s[i]==t[i]: continue else : if s[i]in v and t[i]in v : continue elif s[i]not in v and t[i]not in v : continue f=1 break if f : print("No") else : print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := null; var t : OclAny := null; var v : OclAny := null; Sequence{s,t,v} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine(),"aeiou"} ; if (s)->size() /= (t)->size() then ( execute ("No")->display() ) else ( var f : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = t[i+1] then ( continue ) else ( if (v)->includes(s[i+1]) & (v)->includes(t[i+1]) then ( continue ) else (if (v)->excludes(s[i+1]) & (v)->excludes(t[i+1]) then ( continue ) else skip) ) ; f := 1 ; break) ; if f then ( execute ("No")->display() ) else ( execute ("Yes")->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A="012345678954321012345678" B="6789543210123456789" n=int(input()) for i in range(n): a,b=input().split() if int(a)toInteger() ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; if (("" + ((a)))->toInteger()->compareTo(("" + ((b)))->toInteger())) < 0 then ( execute (StringLib.sumStringsWithSeparator((A.subrange(A->indexOf(a) - 1+1, A->indexOf(b, A->indexOf(a) - 1) - 1 + 1)), " "))->display() ) else ( execute (StringLib.sumStringsWithSeparator((B.subrange(B->indexOf(a) - 1+1, B->indexOf(b, B->indexOf(a) - 1) - 1 + 1)), " "))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- stops=[0,1,2,3,4,5,6,7,8,9,5,4,3,2,1] istops=[[0],[1,14],[2,13],[3,12],[4,11],[5,10],[6],[7],[8],[9]] def asloop(cur,end): result=[] for i in range(cur,cur+len(stops)): x=stops[i % len(stops)] result.append(x) if x==end : return result def asrecurse(cur,end,result=None): if result is None : result=[] x=stops[cur] result.append(x) next=(cur+1)% len(stops) if x==end : return result return asrecurse(next,end,result) def loop(start,end): result=[i for i in range(len(stops)+1)] for i in istops[start]: a=asloop(i,end) if len(a)union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{5}->union(Sequence{4}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 1 })))))))))))))) ; var istops : Sequence := Sequence{Sequence{ 0 }}->union(Sequence{Sequence{1}->union(Sequence{ 14 })}->union(Sequence{Sequence{2}->union(Sequence{ 13 })}->union(Sequence{Sequence{3}->union(Sequence{ 12 })}->union(Sequence{Sequence{4}->union(Sequence{ 11 })}->union(Sequence{Sequence{5}->union(Sequence{ 10 })}->union(Sequence{Sequence{ 6 }}->union(Sequence{Sequence{ 7 }}->union(Sequence{Sequence{ 8 }}->union(Sequence{ Sequence{ 9 } }))))))))) ; skip ; skip ; skip ; var nloop : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, nloop-1) do ( var inputs : OclAny := input().split() ; result := loop(("" + ((inputs->first())))->toInteger(), ("" + ((inputs[1+1])))->toInteger()) ; execute (StringLib.sumStringsWithSeparator((result->select(x | true)->collect(x | (("" + ((x)))))), ' '))->display()); operation asloop(cur : OclAny, end : OclAny) : OclAny pre: true post: true activity: var result : Sequence := Sequence{} ; for i : Integer.subrange(cur, cur + (stops)->size()-1) do ( var x : OclAny := stops[i mod (stops)->size()+1] ; execute ((x) : result) ; if x = end then ( return result ) else skip); operation asrecurse(cur : OclAny, end : OclAny, result : OclAny) : OclAny pre: true post: true activity: if result->oclIsUndefined() then result := null else skip; if result <>= null then ( result := Sequence{} ) else skip ; x := stops[cur+1] ; execute ((x) : result) ; var next : int := (cur + 1) mod (stops)->size() ; if x = end then ( return result ) else skip ; return asrecurse(next, end, result); operation loop(start : OclAny, end : OclAny) : OclAny pre: true post: true activity: result := Integer.subrange(0, (stops)->size() + 1-1)->select(i | true)->collect(i | (i)) ; for i : istops[start+1] do ( var a : OclAny := asloop(i, end) ; if ((a)->size()->compareTo((result)->size())) < 0 then ( result := a ) else skip) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def line(i,j): retval=[] if i<=5 and j<=5 : if i5 : for k in range(i,j+1): retval.append(k) elif i>5 and j>5 : if itoInteger() ; for i : Integer.subrange(0, N-1) do ( execute (line((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) ))))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " "))))))) )))))))) ]))))))))->display()); operation line(i : OclAny, j : OclAny) : OclAny pre: true post: true activity: var retval : Sequence := Sequence{} ; if i <= 5 & j <= 5 then ( if (i->compareTo(j)) < 0 then ( for k : Integer.subrange(i, j + 1-1) do ( execute ((k) : retval)) ) else ( for k : Integer.subrange(j - 1 + 1, i)->reverse() do ( execute ((k) : retval)) ) ) else (if i <= 5 & j > 5 then ( for k : Integer.subrange(i, j + 1-1) do ( execute ((k) : retval)) ) else (if i > 5 & j > 5 then ( if (i->compareTo(j)) < 0 then ( for k : Integer.subrange(i, j + 1-1) do ( execute ((k) : retval)) ) else ( for k : Integer.subrange(i, 10-1) do ( execute ((k) : retval)) ; retval := retval + Sequence{5}->union(Sequence{4}->union(Sequence{3}->union(Sequence{2}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))))))))) ; for k : Integer.subrange(6, j + 1-1) do ( execute ((k) : retval)) ) ) else ( for k : Integer.subrange(i, 10-1) do ( execute ((k) : retval)) ; for k : Integer.subrange(j - 1 + 1, 5)->reverse() do ( execute ((k) : retval)) ) ) ) ; return StringLib.sumStringsWithSeparator((retval->select(i | true)->collect(i | (("" + ((i)))))), " "); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,copy PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") def bus_line(a,b): line=[] if max(a,b)<=5 : if atoInteger() ; for __ : Integer.subrange(0, n-1) do ( Sequence{a,b} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; execute (StringLib.sumStringsWithSeparator((bus_line(a, b)->select(_anon | true)->collect(_anon | (("" + ((_anon)))))), ' '))->display()); operation bus_line(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var line : Sequence := Sequence{} ; if Set{a, b}->max() <= 5 then ( if (a->compareTo(b)) < 0 then ( return (Integer.subrange(a, b + 1-1)) ) else ( return (Integer.subrange(b - 1 + 1, a)->reverse()) ) ) else skip ; if a <= 5 then ( return (Integer.subrange(a, b + 1-1)) ) else skip ; if b <= 5 then ( return (Integer.subrange(a, 10-1))->union((Integer.subrange(b - 1 + 1, 5)->reverse())) ) else skip ; if (a->compareTo(b)) < 0 then ( return (Integer.subrange(a, b + 1-1)) ) else ( return (Integer.subrange(a, 10-1))->union(Sequence{5}->union(Sequence{4}->union(Sequence{3}->union(Sequence{2}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))))))))))->union((Integer.subrange(6, b + 1-1))) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def findNumber(n): x=int(math.floor((-1+math.sqrt(1+8*n-8))/2)) base=(x*(x+1))/2+1 return n-base+1 n=55 print(findNumber(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 55 ; execute (findNumber(n))->display(); operation findNumber(n : OclAny) : OclAny pre: true post: true activity: var x : int := ("" + ((((-1 + (1 + 8 * n - 8)->sqrt()) / 2)->floor())))->toInteger() ; var base : double := (x * (x + 1)) / 2 + 1 ; return n - base + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def evenOddInsertionSort(arr,n): for i in range(2,n): j=i-2 temp=arr[i] if((i+1)& 1==1): while(temp>=arr[j]and j>=0): arr[j+2]=arr[j] j-=2 arr[j+2]=temp else : while(temp<=arr[j]and j>=0): arr[j+2]=arr[j] j-=2 arr[j+2]=temp def printArray(arr,n): for i in range(0,n): print(arr[i],end=" ") arr=[12,11,13,5,6] n=len(arr) evenOddInsertionSort(arr,n) printArray(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{12}->union(Sequence{11}->union(Sequence{13}->union(Sequence{5}->union(Sequence{ 6 })))) ; n := (arr)->size() ; evenOddInsertionSort(arr, n) ; printArray(arr, n); operation evenOddInsertionSort(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(2, n-1) do ( var j : double := i - 2 ; var temp : OclAny := arr[i+1] ; if (MathLib.bitwiseAnd((i + 1), 1) = 1) then ( while ((temp->compareTo(arr[j+1])) >= 0 & j >= 0) do ( arr[j + 2+1] := arr[j+1] ; j := j - 2) ; arr[j + 2+1] := temp ) else ( while ((temp->compareTo(arr[j+1])) <= 0 & j >= 0) do ( arr[j + 2+1] := arr[j+1] ; j := j - 2) ; arr[j + 2+1] := temp )); operation printArray(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countConsecutive(n): s=str(n) count=0 for i in range(len(s)-1): if(s[i]==s[i+1]): count+=1 return count if __name__=="__main__" : n=44522255 print(countConsecutive(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 44522255 ; execute (countConsecutive(n))->display() ) else skip; operation countConsecutive(n : OclAny) : OclAny pre: true post: true activity: var s : String := ("" + ((n))) ; var count : int := 0 ; for i : Integer.subrange(0, (s)->size() - 1-1) do ( if (s[i+1] = s[i + 1+1]) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[[0]*5 for _ in[0]*(1<<15)] for i in range(int((1<<15)**.5)+1): a[i*i][1]+=1 for j in range(i*i+1,min(4*i*i+1,1<<15)): for k in range(2,5): a[j][k]+=a[j-i*i][k-1] while 1 : n=int(input()) if n==0 : break print(sum(a[n])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (1 * (2->pow(15))))->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 5))) ; for i : Integer.subrange(0, ("" + ((((1 * (2->pow(15))))->pow(.5))))->toInteger() + 1-1) do ( a[i * i+1][1+1] := a[i * i+1][1+1] + 1 ; for j : Integer.subrange(i * i + 1, Set{4 * i * i + 1, 1 * (2->pow(15))}->min()-1) do ( for k : Integer.subrange(2, 5-1) do ( a[j+1][k+1] := a[j+1][k+1] + a[j - i * i+1][k - 1+1]))) ; while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; execute ((a[n+1])->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAXN=2**15 MAXRT=int(MAXN**0.5) MAXTERM=4 dp=[[0 for n in range(MAXN+1)]for t in range(MAXTERM+1)] dp[0][0]=1 for r in range(MAXRT,0,-1): for t in range(MAXTERM): for n in range(MAXN+1-r*r): if dp[t][n]==0 : continue dp[t+1][n+r*r]+=dp[t][n] while True : N=int(input()) if N==0 : break print(sum(map(lambda x : x[N],dp))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAXN : double := (2)->pow(15) ; var MAXRT : int := ("" + (((MAXN)->pow(0.5))))->toInteger() ; var MAXTERM : int := 4 ; var dp : Sequence := Integer.subrange(0, MAXTERM + 1-1)->select(t | true)->collect(t | (Integer.subrange(0, MAXN + 1-1)->select(n | true)->collect(n | (0)))) ; dp->first()->first() := 1 ; for r : Integer.subrange(0 + 1, MAXRT)->reverse() do ( for t : Integer.subrange(0, MAXTERM-1) do ( for n : Integer.subrange(0, MAXN + 1 - r * r-1) do ( if dp[t+1][n+1] = 0 then ( continue ) else skip ; dp[t + 1+1][n + r * r+1] := dp[t + 1+1][n + r * r+1] + dp[t+1][n+1]))) ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; execute (((dp)->collect( _x | (lambda x : OclAny in (x[N+1]))->apply(_x) ))->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] m=2**15 a=[[0]*(m+1)for _ in range(5)] a[0][0]=1 for i in range(1,m): ii=i**2 if ii>m : break for k in range(4): for j in range(ii,m+1): a[k+1][j]+=a[k][j-ii] def f(n): r=0 for i in range(5): r+=a[i][n] return r while True : n=I() if n==0 : break rr.append(f(n)) return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; var m : double := (2)->pow(15) ; var a : Sequence := Integer.subrange(0, 5-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (m + 1)))) ; a->first()->first() := 1 ; for i : Integer.subrange(1, m-1) do ( var ii : double := (i)->pow(2) ; if (ii->compareTo(m)) > 0 then ( break ) else skip ; for k : Integer.subrange(0, 4-1) do ( for j : Integer.subrange(ii, m + 1-1) do ( a[k + 1+1][j+1] := a[k + 1+1][j+1] + a[k+1][j - ii+1]))) ; skip ; while true do ( n := I() ; if n = 0 then ( break ) else skip ; execute ((f(n)) : rr)) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): LIMIT=50000000 sequence=[(2*i*i-1)for i in range(LIMIT+1)] sequence[0]=sequence[1]=-1 ans=0 for(i,term)in enumerate(sequence): if i<2 : continue if term==2*i*i-1 : ans+=1 if 1display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LIMIT : int := 50000000 ; var sequence : Sequence := Integer.subrange(0, LIMIT + 1-1)->select(i | true)->collect(i | ((2 * i * i - 1))) ; sequence->first() := -1; var sequence[1+1] : int := -1 ; var ans : int := 0 ; for Sequence{i, term} : Integer.subrange(1, (sequence)->size())->collect( _indx | Sequence{_indx-1, (sequence)->at(_indx)} ) do ( if i < 2 then ( continue ) else skip ; if term = 2 * i * i - 1 then ( ans := ans + 1 ) else skip ; if 1 < term & (term <= LIMIT * 2) then ( var p : OclAny := term ; for j : Integer.subrange(i + p, LIMIT + 1-1)->select( $x | ($x - i + p) mod p = 0 ) do ( while true do ( sequence[j+1] := sequence[j+1] div p ; if sequence[j+1] mod p /= 0 then ( break ) else skip)) ; for j : Integer.subrange(i + (p - i) * 2 mod p, LIMIT + 1-1)->select( $x | ($x - i + (p - i) * 2 mod p) mod p = 0 ) do ( while true do ( sequence[j+1] := sequence[j+1] div p ; if sequence[j+1] mod p /= 0 then ( break ) else skip)) ) else skip) ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() t=input() vowel="aeiou" flag=0 if(len(s)==len(t)): for i in range(len(s)): x=vowel.find(s[i]) y=vowel.find(t[i]) if((x==-1 and y==-1)or(x>=0 and y>=0)): flag=1 continue else : flag=0 break if(flag==0): print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var vowel : String := "aeiou" ; var flag : int := 0 ; if ((s)->size() = (t)->size()) then ( for i : Integer.subrange(0, (s)->size()-1) do ( var x : int := vowel->indexOf(s[i+1]) - 1 ; var y : int := vowel->indexOf(t[i+1]) - 1 ; if ((x = -1 & y = -1) or (x >= 0 & y >= 0)) then ( flag := 1 ; continue ) else ( flag := 0 ; break )) ) else skip ; if (flag = 0) then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Pair : def __init__(self,x,y): self.x=x self.y=y queries=int(input()) intervals=[None] def dfs(target,reachable): reachable.add(target) t=intervals[target] for i in range(1,len(intervals)): if i not in reachable : r=intervals[i] if(t.x>r.x and t.xr.x and t.yexists( _x | result = _x ); attribute x : OclAny := x; attribute y : OclAny := y; operation initialise(x : OclAny,y : OclAny) : Pair pre: true post: true activity: self.x := x ; self.y := y; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; var queries : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var intervals : Sequence := Sequence{ null } ; skip ; for i : Integer.subrange(0, queries-1) do ( var kind : OclAny := null; Sequence{kind,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if kind = 1 then ( execute (((Pair.newPair()).initialise(x, y)) : intervals) ) else ( reachable := Set{}->union(()) ; dfs(x, reachable) ; if (reachable)->includes(y) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) )); operation dfs(target : OclAny, reachable : OclAny) pre: true post: true activity: execute ((target) : reachable) ; var t : OclAny := intervals[target+1] ; for i : Integer.subrange(1, (intervals)->size()-1) do ( if (reachable)->excludes(i) then ( var r : OclAny := intervals[i+1] ; if ((t.x->compareTo(r.x)) > 0 & (t.x->compareTo(r.y)) < 0) or ((t.y->compareTo(r.x)) > 0 & (t.y->compareTo(r.y)) < 0) then ( dfs(i, reachable) ) else skip ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- intervals=[] def dfs(src_id,visited): stack=[src_id] while len(stack)>0 : id=stack.pop() if not visited[id]: visited[id]=True for i in range(len(visited)): a,b=intervals[id] c,d=intervals[i] if(src_id!=i)and not visited[i]: edge_exists=(ctoInteger() ; for q : Integer.subrange(0, q_queries-1) do ( var type : OclAny := null; var num1 : OclAny := null; var num2 : OclAny := null; Sequence{type,num1,num2} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name _)))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; if type = 1 then ( assert (num1->compareTo(num2)) < 0 do "assertion failed" ; execute ((Sequence{num1, num2}) : intervals) ) else ( visited := Integer.subrange(0, (intervals)->size()-1)->select(n | true)->collect(n | (false)) ; var ath_interval_indx : double := num1 - 1 ; var bth_interval_indx : double := num2 - 1 ; dfs(ath_interval_indx, visited) ; execute (if visited[bth_interval_indx+1] then "YES" else "NO" endif)->display() )); operation dfs(src_id : OclAny, visited : OclAny) pre: true post: true activity: var stack : Sequence := Sequence{ src_id } ; while (stack)->size() > 0 do ( var id : OclAny := stack->last() ; stack := stack->front() ; if not(visited[id+1]) then ( visited[id+1] := true ; for i : Integer.subrange(0, (visited)->size()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := intervals[id+1] ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := intervals[i+1] ; if (src_id /= i) & not(visited[i+1]) then ( var edge_exists : boolean := ((c->compareTo(a)) < 0 & (a < d)) or ((c->compareTo(b)) < 0 & (b < d)) ; if edge_exists then ( execute ((i) : stack) ) else skip ) else skip) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import deque input=sys.stdin.readline def inlt(): return(list(map(int,input().split()))) n=int(input()) edges=[] for i in range(n): query=inlt() if query[0]==1 : edges.append((query[1],query[2])) else : start=query[1] dest=query[2] Q=deque() Q.append(start) visited=set() found=False while Q : node=Q.popleft() if node==dest : found=True break if node in visited : continue visited.add(node) a,b=edges[node-1] for i in range(1,len(edges)+1): if i!=node : c,d=edges[i-1] if ctoInteger() ; var edges : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var query : OclAny := inlt() ; if query->first() = 1 then ( execute ((Sequence{query[1+1], query[2+1]}) : edges) ) else ( var start : OclAny := query[1+1] ; var dest : OclAny := query[2+1] ; var Q : Sequence := () ; execute ((start) : Q) ; var visited : Set := Set{}->union(()) ; var found : boolean := false ; while Q do ( var node : OclAny := Q->first() ; Q := Q->tail() ; if node = dest then ( found := true ; break ) else skip ; if (visited)->includes(node) then ( continue ) else skip ; execute ((node) : visited) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := edges[node - 1+1] ; for i : Integer.subrange(1, (edges)->size() + 1-1) do ( if i /= node then ( var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := edges[i - 1+1] ; if (c->compareTo(a)) < 0 & (a < d) or (c->compareTo(b)) < 0 & (b < d) then ( execute ((i) : Q) ) else skip ) else skip)) ; if found then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) )); operation inlt() : OclAny pre: true post: true activity: return (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def query_add(x,y,intervals): intervals.append((x,y)) def can_move(a,b,c,d): return c0 : cur=stack.pop() a,b=intervals[cur-1] for i in range(0,len(intervals)): if visited[i]: continue c,d=intervals[i] if can_move(a,b,c,d): if i+1==param2 : print("YES") return visited[i]=True stack.append(i+1) print("NO") def parse_queries(num_queries): queries=[] intervals=[] for i in range(0,num_queries): queries.append(input().split()) for t,param1,param2 in queries : if t=="1" : query_add(int(param1),int(param2),intervals) else : query_has_path(int(param1),int(param2),intervals) if __name__=='__main__' : n=int(input()) parse_queries(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; parse_queries(n) ) else skip; operation query_add(x : OclAny, y : OclAny, intervals : OclAny) pre: true post: true activity: execute ((Sequence{x, y}) : intervals); operation can_move(a : OclAny, b : OclAny, c : OclAny, d : OclAny) : OclAny pre: true post: true activity: return (c->compareTo(a)) < 0 & (a < d) or (c->compareTo(b)) < 0 & (b < d); operation query_has_path(param1 : OclAny, param2 : OclAny, intervals : OclAny) pre: true post: true activity: var stack : Sequence := Sequence{ param1 } ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (intervals)->size()) ; visited[param1 - 1+1] := true ; while (stack)->size() > 0 do ( var cur : OclAny := stack->last() ; stack := stack->front() ; Sequence{a,b} := intervals[cur - 1+1] ; for i : Integer.subrange(0, (intervals)->size()-1) do ( if visited[i+1] then ( continue ) else skip ; Sequence{c,d} := intervals[i+1] ; if can_move(a, b, c, d) then ( if i + 1 = param2 then ( execute ("YES")->display() ; return ) else skip ; visited[i+1] := true ; execute ((i + 1) : stack) ) else skip)) ; execute ("NO")->display(); operation parse_queries(num_queries : OclAny) pre: true post: true activity: var queries : Sequence := Sequence{} ; intervals := Sequence{} ; for i : Integer.subrange(0, num_queries-1) do ( execute ((input().split()) : queries)) ; for _tuple : queries do (var _indx : int := 1; var t : OclAny := _tuple->at(_indx); _indx := _indx + 1; var param1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var param2 : OclAny := _tuple->at(_indx); if t = "1" then ( query_add(("" + ((param1)))->toInteger(), ("" + ((param2)))->toInteger(), intervals) ) else ( query_has_path(("" + ((param1)))->toInteger(), ("" + ((param2)))->toInteger(), intervals) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools def compute(): numdigits=0 data={} for i in itertools.count(): digits=[int(c)for c in str(i**3)] digits.sort() numclass="".join(str(d)for d in digits) if len(numclass)>numdigits : candidates=[lowest for(lowest,count)in data.values()if count==5] if len(candidates)>0 : return str(min(candidates)**3) data={} numdigits=len(numclass) lowest,count=data.get(numclass,(i,0)) data[numclass]=(lowest,count+1) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var numdigits : int := 0 ; var data : OclAny := Set{} ; for i : itertools->count() do ( var digits : Sequence := ("" + (((i)->pow(3))))->select(c | true)->collect(c | (("" + ((c)))->toInteger())) ; digits := digits->sort() ; var numclass : String := StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name d)))))))) ))))))) (comp_for for (exprlist (expr (atom (name d)))) in (logical_test (comparison (expr (atom (name digits)))))))), "") ; if ((numclass)->size()->compareTo(numdigits)) > 0 then ( var candidates : Sequence := data.values()->select(Sequence{lowest, count} | count = 5)->collect(Sequence{lowest, count} | (lowest)) ; if (candidates)->size() > 0 then ( return ("" + ((((candidates)->min())->pow(3)))) ) else skip ; data := Set{} ; numdigits := (numclass)->size() ) else skip ; var lowest : OclAny := null; var count : OclAny := null; Sequence{lowest,count} := data.get(numclass, Sequence{i, 0}) ; data->at(numclass) := Sequence{lowest, count + 1}); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findAngle(n): interiorAngle=int((n-2)*180/n) exteriorAngle=int(360/n) print("Interior angle: ",interiorAngle) print("Exterior angle: ",exteriorAngle) n=10 findAngle(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 10 ; findAngle(n); operation findAngle(n : OclAny) pre: true post: true activity: var interiorAngle : int := ("" + (((n - 2) * 180 / n)))->toInteger() ; var exteriorAngle : int := ("" + ((360 / n)))->toInteger() ; execute ("Interior angle: ")->display() ; execute ("Exterior angle: ")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) MOD=10**9+7 ans=pow(10,n,MOD)-2*pow(9,n,MOD)+pow(8,n,MOD) ans %=MOD print(int(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var MOD : double := (10)->pow(9) + 7 ; var ans : double := (10)->pow(n) - 2 * (9)->pow(n) + (8)->pow(n) ; ans := ans mod MOD ; execute (("" + ((ans)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import base64 import subprocess import zlib exe_bin="c%1E9eQ*=U6<`Xcwu^Y+R0z_EJjc;rfW!yQ<;(NN9OPj3$Sc4>he?zN*2Qh&fltZE_IVjU7F*Jf3elRJgo?V7UBe-@5w`k5;{M_Y=RVp1ZwjOZ8tKZ|uafr%mi{H^HkA^-O)*Y+~PGBEQZA|A9%pcp~PaO4PzBS`Oj}Pap-~ezk&EQU?M5NJydJb=P5^ScL>($3QG9B&0xG5(Fgp{F{VOI3C_1CZurOzo{(}i-!Gy-bh#}GcLKUqg#w8yj`N4jYSe(oa>ev!qHH~7wnc?u3E=ci!C?$MBueS@ZmA!$47!+a&DIN|C`22#uUhsCW5@gktK`|;@lbXa>LIBZlgD)yd9+!6)gS#3N!_lCyTa@~tBOx*7?KRSDQ#7Gf!B|ql0}-TS0NoGn6oUObg}#6o0U(e_gkeAk7aR%*0VzBrN`&bXqk)LH2YN1GGi3M%0?_1*?Y`DFVTH3n&8=`YD)}v2gq46Jyy9%|!+&kCcC7LWv>~NL;VkgC#G?2~J^U&}u?(-!0Kt-r#A2+o(?Z?ABCkohe@Jy-E5g=xlXALm(0!1bqtJc^pDtGDAcLPJ&z&Mpk5m41l|lR`Ohri5WjyyvSv>6BPWU`)$&Z^wNR8TCwm(rV1(u1}qo`9+w=Q#myu^Ybu|hhXZc%$HyucYW%J%v&*!yF4{6^Ovp!9(Q$Wugt%TdED%&L76`feBU^2pS#EHcV&9Ip&zyUSfnN|#E<4Jt;Ib{d1@+M6X}~ki63ijtArk={=uKhU$Rgcigc%3a#u|S;HNw_6?nYTe}}GM&;ej-5?}`&uJlU;E(O?~Istg8j2|O-kvsKE#Y_=)*Yx9nd+O3q@%N#m>G)ED!p_N<-qZnYtO!=a0|W_|!CiJbfc?Imw@ykt)HUix@1$2F>j4ZGH&+1tqWNN1Fdw0l6OBo>J&`38<%EznsaWdFaB)d=cao_YII4E&n<8O09hG0$={aclfabcoO;MvWFXY@46cI=EJx7vAh+0>RtZ$r5pL<7nksLr+IM#i`AV}#P?q)=chsaMSkoajrtXQ>IMG8zwyVkd6_}(PhL&&aypFeFvPp|mpq$mwLgM)*pms{V=)sywQDHcjb0`VLC>$$<$?r^*|7>gz(E(>3?j8mYVYwEb$@w1upbIlw)pVzJxqf&TBJP;9Ni9l4k0gz>!tDdCQ>(_BTAPneM+?K_*bv)SzJzKJP}UoFgf1vpL!_!{v4mw>(x)B|`3JmsK8dB4TUvZo7Kh8&i~rG-V~mO=-{@tNi+uydVeUp1Bo`&9l?CL?cRcE<*LJs*leS4rpf)WA_g10npwP7_dHP$IqiC_(|}a2D|cusMYQmv$onR58B%7+<`o|y>=wuWAC*7wZvWvh}&KX60P5|W{J()HvpPw%27Qm~Nl^uB#D;ptuTB0}l?I{l7H?*=}Y$;2={Ob*xd4tWc?WTtn=6QrEpsgIEM(Yy3YLgyoWqIcLsudI4>3p&sun(6^f-_0v0PTL0&eUhdP+Np7{X(OJKIWm4u`Uv)J(>l^A6^wZe1!RR*`T;AYsQhr0+h9pBgPxVthp0E0+9xqV+SdSN~^Q*^;^dC!9yjb-=Jzk>vsUDxBu2(%?iaHJPGIZ7ux1(u8yj)%Xdfb8b8sc-+xB)#r4{b5TuTb|BJzk;iBYJ$kpOmFl|J~M2*FeF)!6=BfX}rqQ1?@sQYP|`n&3xl7|&hr$4ulG+mv?FxGnl^;bjx~t+IUXe)TSCKRf<2R^#}O`8H*~*m>C|&toOpTdl{dZ3@oXciN2G*-iRIUx>m451PpDu^Gp;93plGi5>dbc+zGZzjDmP{;MYT&zsMA^6;K^hQ(IQ}Mq1R)d?c0^*m(5jFWizkFYatH-u1A~#U6b?C8uUgY&EQF(2L?IB52Zn`kREiIyzIb3DEQFE+1H+)A;RM_iov0ve=yGrJ3f>M6?uW3kqet-a1mrzkNbua+;ojtHgEF0RNDs)7GwL{O-mszD>lgg))^;yg4Tl0!013X$a#&APNG8IePmcX*Y0*a8=mU008HvgfK9jlqA0nODriKzRp+5kYv@unzkR~>X>5e8)i7nAbIAu$*LI0*UI*&9uDyLyE5p=GE-b8}tjiansZ8=6Nm`KVKpA8XX#Qt6AS=I!0S~Wn-u%c`*7CQ*Jp>C$(Yz9$h`pS?qF+3mzdVxxDh4#}NcBS|razstTbClBi1a|yr|L-OGt%RrNK1wGv?Z47M{{f_pVb0#?P)hGTXkzC-#pu&>B&Fkwyn~?+Gy3$rNhv#CMGXBmqfg(1Dcz?HRz&((N1VRP=+pOEN{bnJw*TKl`t?iS^C`Wbk>?oxSw`P1p5Cnf=NWx^ZdNJd@a%ZLh?ICyI!xL4dWC1liyi;pAtkPq>eKVp;1c8dSp7dCW$e}aIQ9P*2tYbk!06F-9Y#w3+55bqDuuuA6Y4+D=&R=hPG1kJPt!EPsJ?psAo?xL{Z9*{{{g9=y|AMCbqsEFFKZNk)I#)|$UcCdGftGd{);tj*QTK_kop;iWB1RwCi;((1KtdSv-`Xcwu^Y+R0z_EJjc;rfW!yQ<;(NN9OPj3$Sc4>he?zN*2Qh&fltZE_IVjU7F*Jf3elRJgo?V7UBe-@5w`k5;{M_Y=RVp1ZwjOZ8tKZ|uafr%mi{H^HkA^-O)*Y+~PGBEQZA|A9%pcp~PaO4PzBS`Oj}Pap-~ezk&EQU?M5NJydJb=P5^ScL>($3QG9B&0xG5(Fgp{F{VOI3C_1CZurOzo{(}i-!Gy-bh#}GcLKUqg#w8yj`N4jYSe(oa>ev!qHH~7wnc?u3E=ci!C?$MBueS@ZmA!$47!+a&DIN|C`22#uUhsCW5@gktK`|;@lbXa>LIBZlgD)yd9+!6)gS#3N!_lCyTa@~tBOx*7?KRSDQ#7Gf!B|ql0}-TS0NoGn6oUObg}#6o0U(e_gkeAk7aR%*0VzBrN`&bXqk)LH2YN1GGi3M%0?_1*?Y`DFVTH3n&8=`YD)}v2gq46Jyy9%|!+&kCcC7LWv>~NL;VkgC#G?2~J^U&}u?(-!0Kt-r#A2+o(?Z?ABCkohe@Jy-E5g=xlXALm(0!1bqtJc^pDtGDAcLPJ&z&Mpk5m41l|lR`Ohri5WjyyvSv>6BPWU`)$&Z^wNR8TCwm(rV1(u1}qo`9+w=Q#myu^Ybu|hhXZc%$HyucYW%J%v&*!yF4{6^Ovp!9(Q$Wugt%TdED%&L76`feBU^2pS#EHcV&9Ip&zyUSfnN|#E<4Jt;Ib{d1@+M6X}~ki63ijtArk={=uKhU$Rgcigc%3a#u|S;HNw_6?nYTe}}GM&;ej-5?}`&uJlU;E(O?~Istg8j2|O-kvsKE#Y_=)*Yx9nd+O3q@%N#m>G)ED!p_N<-qZnYtO!=a0|W_|!CiJbfc?Imw@ykt)HUix@1$2F>j4ZGH&+1tqWNN1Fdw0l6OBo>J&`38<%EznsaWdFaB)d=cao_YII4E&n<8O09hG0$={aclfabcoO;MvWFXY@46cI=EJx7vAh+0>RtZ$r5pL<7nksLr+IM#i`AV}#P?q)=chsaMSkoajrtXQ>IMG8zwyVkd6_}(PhL&&aypFeFvPp|mpq$mwLgM)*pms{V=)sywQDHcjb0`VLC>$$<$?r^*|7>gz(E(>3?j8mYVYwEb$@w1upbIlw)pVzJxqf&TBJP;9Ni9l4k0gz>!tDdCQ>(_BTAPneM+?K_*bv)SzJzKJP}UoFgf1vpL!_!{v4mw>(x)B|`3JmsK8dB4TUvZo7Kh8&i~rG-V~mO=-{@tNi+uydVeUp1Bo`&9l?CL?cRcE<*LJs*leS4rpf)WA_g10npwP7_dHP$IqiC_(|}a2D|cusMYQmv$onR58B%7+<`o|y>=wuWAC*7wZvWvh}&KX60P5|W{J()HvpPw%27Qm~Nl^uB#D;ptuTB0}l?I{l7H?*=}Y$;2={Ob*xd4tWc?WTtn=6QrEpsgIEM(Yy3YLgyoWqIcLsudI4>3p&sun(6^f-_0v0PTL0&eUhdP+Np7{X(OJKIWm4u`Uv)J(>l^A6^wZe1!RR*`T;AYsQhr0+h9pBgPxVthp0E0+9xqV+SdSN~^Q*^;^dC!9yjb-=Jzk>vsUDxBu2(%?iaHJPGIZ7ux1(u8yj)%Xdfb8b8sc-+xB)#r4{b5TuTb|BJzk;iBYJ$kpOmFl|J~M2*FeF)!6=BfX}rqQ1?@sQYP|`n&3xl7|&hr$4ulG+mv?FxGnl^;bjx~t+IUXe)TSCKRf<2R^#}O`8H*~*m>C|&toOpTdl{dZ3@oXciN2G*-iRIUx>m451PpDu^Gp;93plGi5>dbc+zGZzjDmP{;MYT&zsMA^6;K^hQ(IQ}Mq1R)d?c0^*m(5jFWizkFYatH-u1A~#U6b?C8uUgY&EQF(2L?IB52Zn`kREiIyzIb3DEQFE+1H+)A;RM_iov0ve=yGrJ3f>M6?uW3kqet-a1mrzkNbua+;ojtHgEF0RNDs)7GwL{O-mszD>lgg))^;yg4Tl0!013X$a#&APNG8IePmcX*Y0*a8=mU008HvgfK9jlqA0nODriKzRp+5kYv@unzkR~>X>5e8)i7nAbIAu$*LI0*UI*&9uDyLyE5p=GE-b8}tjiansZ8=6Nm`KVKpA8XX#Qt6AS=I!0S~Wn-u%c`*7CQ*Jp>C$(Yz9$h`pS?qF+3mzdVxxDh4#}NcBS|razstTbClBi1a|yr|L-OGt%RrNK1wGv?Z47M{{f_pVb0#?P)hGTXkzC-#pu&>B&Fkwyn~?+Gy3$rNhv#CMGXBmqfg(1Dcz?HRz&((N1VRP=+pOEN{bnJw*TKl`t?iS^C`Wbk>?oxSw`P1p5Cnf=NWx^ZdNJd@a%ZLh?ICyI!xL4dWC1liyi;pAtkPq>eKVp;1c8dSp7dCW$e}aIQ9P*2tYbk!06F-9Y#w3+55bqDuuuA6Y4+D=&R=hPG1kJPt!EPsJ?psAo?xL{Z9*{{{g9=y|AMCbqsEFFKZNk)I#)|$UcCdGftGd{);tj*QTK_kop;iWB1RwCi;((1KtdSv-zKJP}UoFgf1vpL!_!{v4mw>(x)B|`3JmsK8dB4TUvZo7Kh8&i~rG-V~mO=-{@tNi+uydVeUp1Bo`&9l?CL?cRcE<*LJs*leS4rpf)WA_g10npwP7_dHP$IqiC_(|}a2D|cusMYQmv$onR58B%7+<`o|y>=wuWAC*7wZvWvh}&KX60P5|W{J()HvpPw%27Qm~Nl^uB#D;ptuTB0}l?I{l7H?*=}Y$;2={Ob*xd4tWc?WTtn=6QrEpsgIEM(Yy3YLgyoWqIcLsudI4>3p&sun(6^f-_0v0PTL0&eUhdP+Np7{X(OJKIWm4u`Uv)J(>l^A6^wZe1!RR*`T;AYsQhr0+h9pBgPxVthp0E0+9xqV+SdSN~^Q*^;^dC!9yjb-=Jzk>vsUDxBu2(%?iaHJPGIZ7ux1(u8yj)%Xdfb8b8sc-+xB)#r4{b5TuTb|BJzk;iBYJ$kpOmFl|J~M2*FeF)!6=BfX}rqQ1?@sQYP|`n&3xl7|&hr$4ulG+mv?FxGnl^;bjx~t+IUXe)TSCKRf<2R^#}O`8H*~*m>C|&toOpTdl{dZ3@oXciN2G*-iRIUx>m451PpDu^Gp;93plGi5>dbc+zGZzjDmP{;MYT&zsMA^6;K^hQ(IQ}Mq1R)d?c0^*m(5jFWizkFYatH-u1A~#U6b?C8uUgY&EQF(2L?IB52Zn`kREiIyzIb3DEQFE+1H+)A;RM_iov0ve=yGrJ3f>M6?uW3kqet-a1mrzkNbua+;ojtHgEF0RNDs)7GwL{O-mszD>lgg))^;yg4Tl0!013X$a#&APNG8IePmcX*Y0*a8=mU008HvgfK9jlqA0nODriKzRp+5kYv@unzkR~>X>5e8)i7nAbIAu$*LI0*UI*&9uDyLyE5p=GE-b8}tjiansZ8=6Nm`KVKpA8XX#Qt6AS=I!0S~Wn-u%c`*7CQ*Jp>C$(Yz9$h`pS?qF+3mzdVxxDh4#}NcBS|razstTbClBi1a|yr|L-OGt%RrNK1wGv?Z47M{{f_pVb0#?P)hGTXkzC-#pu&>B&Fkwyn~?+Gy3$rNhv#CMGXBmqfg(1Dcz?HRz&((N1VRP=+pOEN{bnJw*TKl`t?iS^C`Wbk>?oxSw`P1p5Cnf=NWx^ZdNJd@a%ZLh?ICyI!xL4dWC1liyi;pAtkPq>eKVp;1c8dSp7dCW$e}aIQ9P*2tYbk!06F-9Y#w3+55bqDuuuA6Y4+D=&R=hPG1kJPt!EPsJ?psAo?xL{Z9*{{{g9=y|AMCbqsEFFKZNk)I#)|$UcCdGftGd{);tj*QTK_kop;iWB1RwCi;((1KtdSv-toInteger() ; if N = 1 then ( execute (0)->display() ; exit() ) else skip ; if N = 2 then ( execute (2)->display() ; exit() ) else skip ; var mod : int := ("" + (((10)->pow(9) + 7)))->toInteger() ; var zeronai : int := 1 ; for i : Integer.subrange(0, N-1) do ( zeronai := zeronai * 9 ; zeronai := zeronai mod mod) ; var dottimonai : int := 1 ; for i : Integer.subrange(0, N-1) do ( dottimonai := dottimonai * 8 ; dottimonai := dottimonai mod mod) ; var aru : int := 1 ; for i : Integer.subrange(0, N-1) do ( aru := aru * 10 ; aru := aru mod mod) ; execute ((aru - 2 * zeronai + dottimonai) mod mod)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**8) input=sys.stdin.readline def main(): N=int(input()) MOD=10**9+7 fact=[1,1] factinv=[1,1] inv=[0,1] def cmb(n,k,p): if(k<0)or(npow(8)) ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var MOD : double := (10)->pow(9) + 7 ; var fact : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var factinv : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var inv : Sequence := Sequence{0}->union(Sequence{ 1 }) ; skip ; for i : Integer.subrange(2, N + 1-1) do ( execute (((fact->last() * i) mod MOD) : fact) ; execute (((-inv[MOD mod i+1] * (MOD div i)) mod MOD) : inv) ; execute (((factinv->last() * inv->last()) mod MOD) : factinv)) ; var ans : double := (10)->pow(N) ; ans := ans - (8)->pow(N) ; ans := ans mod MOD ; for i : Integer.subrange(1, N + 1-1) do ( ans := ans - (8)->pow(N - i) * cmb(N, i, MOD) * 2 ; ans := ans mod MOD) ; ans := ans mod MOD ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) print((10**n-2*(9**n)+8**n)%(10**9+7)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (((10)->pow(n) - 2 * ((9)->pow(n)) + (8)->pow(n)) mod ((10)->pow(9) + 7))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isTriPerfect(n): sum=1+n i=2 while i*i<=n : if n % i==0 : if n/i==i : sum=sum+i else : sum=sum+i+n/i i+=1 return(True if sum==3*n and n!=1 else False) n=120 if isTriPerfect(n): print(n,"is a Triperfect number") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 120 ; if isTriPerfect(n) then ( execute (n)->display() ) else skip; operation isTriPerfect(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 1 + n ; var i : int := 2 ; while (i * i->compareTo(n)) <= 0 do ( if n mod i = 0 then ( if n / i = i then ( sum := sum + i ) else ( sum := sum + i + n / i ) ) else skip ; i := i + 1) ; return (if sum = 3 * n & n /= 1 then true else false endif); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin from math import asin,pi,sqrt,degrees input=stdin.readline def main(args): triangle=0 right_triangle=0 acute_triangle=0 obtuse_triangle=0 while True : lines=[int(x)for x in input().split()] lines.sort() a,b,c=lines[0],lines[1],lines[2] if a+b<=c : break triangle+=1 if a**2+b**2==c**2 : right_triangle+=1 continue s=(a+b+c)/2 area=sqrt(s*(s-a)*(s-b)*(s-c)) h=(2*area)/c A=degrees(asin(h/b)) B=degrees(asin(h/a)) C=180-(A+B) if A<90 and B<90 and C<90 : acute_triangle+=1 else : obtuse_triangle+=1 print(triangle,right_triangle,acute_triangle,obtuse_triangle) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := stdin.readline ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation main(args : OclAny) pre: true post: true activity: var triangle : int := 0 ; var right_triangle : int := 0 ; var acute_triangle : int := 0 ; var obtuse_triangle : int := 0 ; while true do ( var lines : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; lines := lines->sort() ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{lines->first(),lines[1+1],lines[2+1]} ; if (a + b->compareTo(c)) <= 0 then ( break ) else skip ; triangle := triangle + 1 ; if (a)->pow(2) + (b)->pow(2) = (c)->pow(2) then ( right_triangle := right_triangle + 1 ; continue ) else skip ; var s : double := (a + b + c) / 2 ; var area : OclAny := sqrt(s * (s - a) * (s - b) * (s - c)) ; var h : double := (2 * area) / c ; var A : OclAny := degrees(asin(h / b)) ; var B : OclAny := degrees(asin(h / a)) ; var C : double := 180 - (A + B) ; if A < 90 & B < 90 & C < 90 then ( acute_triangle := acute_triangle + 1 ) else ( obtuse_triangle := obtuse_triangle + 1 )) ; execute (triangle)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- countTri=0 countTriCho=0 countTriSma=0 countTriLar=0 while(True): hens=list(map(int,input().split())) MAX=max(hens) hens.remove(MAX) SUM=0 for hen in hens : SUM+=hen if MAX>=SUM : print(countTri,countTriCho,countTriSma,countTriLar) break else : countTri+=1 SUM_2=0 for hen in hens : SUM_2+=(hen**2) MAX_2=(MAX**2) if(MAX_2==SUM_2): countTriCho+=1 elif(MAX_2collect( _x | (OclType["int"])->apply(_x) )) ; var MAX : OclAny := (hens)->max() ; execute ((MAX) /: hens) ; var SUM : int := 0 ; for hen : hens do ( SUM := SUM + hen) ; if (MAX->compareTo(SUM)) >= 0 then ( execute (countTri)->display() ; break ) else ( countTri := countTri + 1 ; var SUM:= 0 : int := 0 ; for hen : hens do ( SUM + ((hen)->pow(2)) := SUM + ((hen)->pow(2)) + ((hen)->pow(2))) ; var MAX:= ((MAX)->pow(2)) : double := ((MAX)->pow(2)) ; if (MAXSUM countTriCho := countTriCho + 1 = SUM countTriCho := countTriCho + 1) then ( countTriCho := countTriCho + 1 ) else (if ((MAXSUM countTriSma := countTriSma + 1->compareTo(SUM countTriSma := countTriSma + 1)) < 0) then ( countTriSma := countTriSma + 1 ) else ( countTriLar := countTriLar + 1 ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def t_check(a,b,c): if a+b>c : if b+c>a : if a+c>b : return True return False def f_check(a_,b_,c_): tmp=[] tmp.append(a_) tmp.append(b_) tmp.append(c_) sqrts=[] for i in range(3): sqrts.append(tmp[i]**2) m=max(sqrts) s=sum(sqrts) if m==(s-m): return(0) if m>(s-m): return(2) if m<(s-m): return(1) counter=[0,0,0] while(1): input_f=input() t=input_f.split() fn,sn,tn=int(t[0]),int(t[1]),int(t[2]) if t_check(fn,sn,tn): counter[f_check(fn,sn,tn)]+=1 else : break print(sum(counter),counter[0],counter[1],counter[2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var counter : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) ; while (1) do ( var input_f : String := (OclFile["System.in"]).readLine() ; var t : OclAny := input_f.split() ; var fn : OclAny := null; var sn : OclAny := null; var tn : OclAny := null; Sequence{fn,sn,tn} := Sequence{("" + ((t->first())))->toInteger(),("" + ((t[1+1])))->toInteger(),("" + ((t[2+1])))->toInteger()} ; if t_check(fn, sn, tn) then ( counter[f_check(fn, sn, tn)+1] := counter[f_check(fn, sn, tn)+1] + 1 ) else ( break )) ; execute ((counter)->sum())->display(); operation t_check(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: if (a + b->compareTo(c)) > 0 then ( if (b + c->compareTo(a)) > 0 then ( if (a + c->compareTo(b)) > 0 then ( return true ) else skip ) else skip ) else skip ; return false; operation f_check(a_ : OclAny, b_ : OclAny, c_ : OclAny) : OclAny pre: true post: true activity: var tmp : Sequence := Sequence{} ; execute ((a_) : tmp) ; execute ((b_) : tmp) ; execute ((c_) : tmp) ; var sqrts : Sequence := Sequence{} ; for i : Integer.subrange(0, 3-1) do ( execute (((tmp[i+1])->pow(2)) : sqrts)) ; var m : OclAny := (sqrts)->max() ; var s : OclAny := (sqrts)->sum() ; if m = (s - m) then ( return (0) ) else skip ; if (m->compareTo((s - m))) > 0 then ( return (2) ) else skip ; if (m->compareTo((s - m))) < 0 then ( return (1) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(sides): ans=[0,0,0,0] for a,b,c in sides : if a+b>c and b+c>a and c+a>b : ans[0]+=1 if c**2==a**2+b**2 : ans[1]+=1 elif c**2a**2+b**2 : ans[3]+=1 else : break return ' '.join(map(str,ans)) if __name__=='__main__' : while True : sides=[] try : while True : temp=list(map(int,input().split())) sides.append(sorted(temp)) except EOFError : break print(solve(sides)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( while true do ( sides := Sequence{} ; try ( while true do ( var temp : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((temp->sort()) : sides))) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))) ; execute (solve(sides))->display() ) else skip; operation solve(sides : OclAny) : OclAny pre: true post: true activity: var ans : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))) ; for _tuple : sides do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if (a + b->compareTo(c)) > 0 & (b + c->compareTo(a)) > 0 & (c + a->compareTo(b)) > 0 then ( ans->first() := ans->first() + 1 ; if (c)->pow(2) = (a)->pow(2) + (b)->pow(2) then ( ans[1+1] := ans[1+1] + 1 ) else (if ((c)->pow(2)->compareTo((a)->pow(2) + (b)->pow(2))) < 0 then ( ans[2+1] := ans[2+1] + 1 ) else (if ((c)->pow(2)->compareTo((a)->pow(2) + (b)->pow(2))) > 0 then ( ans[3+1] := ans[3+1] + 1 ) else skip ) ) ) else ( break )) ; return StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def nDigitPerfectSquares(n): print(pow(math.ceil(math.sqrt(pow(10,n-1))),2),end=" "); print(pow(math.ceil(math.sqrt(pow(10,n)))-1,2)); n=4 ; nDigitPerfectSquares(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 4; ; nDigitPerfectSquares(n);; operation nDigitPerfectSquares(n : OclAny) pre: true post: true activity: execute (((((10)->pow(n - 1))->sqrt())->ceil())->pow(2))->display(); ; execute (((((10)->pow(n))->sqrt())->ceil() - 1)->pow(2))->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sankaku=0 tyokkaku=0 eikaku=0 donkaku=0 while True : inputed_line=input() data_str=inputed_line.split(' ') data=[int(i)for i in data_str] data.sort() if data[-1]data[0]**2+data[1]**2 : donkaku+=1 else : break answer_list=[sankaku,tyokkaku,eikaku,donkaku] answer_list_str=[str(i)for i in answer_list] answer_str=' '.join(answer_list_str) print(answer_str) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sankaku : int := 0 ; var tyokkaku : int := 0 ; var eikaku : int := 0 ; var donkaku : int := 0 ; while true do ( var inputed_line : String := (OclFile["System.in"]).readLine() ; var data_str : OclAny := inputed_line.split(' ') ; var data : Sequence := data_str->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; data := data->sort() ; if (data->last()->compareTo(data->first() + data[1+1])) < 0 then ( sankaku := sankaku + 1 ; if (data->last())->pow(2) = (data->first())->pow(2) + (data[1+1])->pow(2) then ( tyokkaku := tyokkaku + 1 ) else (if ((data->last())->pow(2)->compareTo((data->first())->pow(2) + (data[1+1])->pow(2))) < 0 then ( eikaku := eikaku + 1 ) else (if ((data->last())->pow(2)->compareTo((data->first())->pow(2) + (data[1+1])->pow(2))) > 0 then ( donkaku := donkaku + 1 ) else skip ) ) ) else ( break )) ; var answer_list : Sequence := Sequence{sankaku}->union(Sequence{tyokkaku}->union(Sequence{eikaku}->union(Sequence{ donkaku }))) ; var answer_list_str : Sequence := answer_list->select(i | true)->collect(i | (("" + ((i))))) ; var answer_str : String := StringLib.sumStringsWithSeparator((answer_list_str), ' ') ; execute (answer_str)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) l1=list(map(int,input().split())) l2=list(map(int,input().split())) a=0 b=0 if 1 in l1 and 1 in l2 : print(1) elif 2 in l1 and 2 in l2 : print(2) elif 3 in l1 and 3 in l2 : print(3) elif 4 in l1 and 4 in l2 : print(4) elif 5 in l1 and 5 in l2 : print(5) elif 6 in l1 and 6 in l2 : print(6) elif 7 in l1 and 7 in l2 : print(7) elif 8 in l1 and 8 in l2 : print(8) elif 9 in l1 and 9 in l2 : print(9) else : l1.sort() l2.sort() if l1[0]<=l2[0]: a=l1[0]*10+l2[0] print(a) else : b=l2[0]*10+l1[0] print(b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : int := 0 ; var b : int := 0 ; if (l1)->includes(1) & (l2)->includes(1) then ( execute (1)->display() ) else (if (l1)->includes(2) & (l2)->includes(2) then ( execute (2)->display() ) else (if (l1)->includes(3) & (l2)->includes(3) then ( execute (3)->display() ) else (if (l1)->includes(4) & (l2)->includes(4) then ( execute (4)->display() ) else (if (l1)->includes(5) & (l2)->includes(5) then ( execute (5)->display() ) else (if (l1)->includes(6) & (l2)->includes(6) then ( execute (6)->display() ) else (if (l1)->includes(7) & (l2)->includes(7) then ( execute (7)->display() ) else (if (l1)->includes(8) & (l2)->includes(8) then ( execute (8)->display() ) else (if (l1)->includes(9) & (l2)->includes(9) then ( execute (9)->display() ) else ( l1 := l1->sort() ; l2 := l2->sort() ; if (l1->first()->compareTo(l2->first())) <= 0 then ( a := l1->first() * 10 + l2->first() ; execute (a)->display() ) else ( b := l2->first() * 10 + l1->first() ; execute (b)->display() ) ) ) ) ) ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) o=input().split() d=input().split() o.sort() d.sort() num=0 for i in range(0,10): if o.count(str(i))==d.count(str(i))and o.count(str(i))!=0 : num=i break if num==0 : num=min(o[0],d[0])+max(o[0],d[0]) print(num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var o : OclAny := input().split() ; var d : OclAny := input().split() ; o := o->sort() ; d := d->sort() ; var num : int := 0 ; for i : Integer.subrange(0, 10-1) do ( if o->count(("" + ((i)))) = d->count(("" + ((i)))) & o->count(("" + ((i)))) /= 0 then ( num := i ; break ) else skip) ; if num = 0 then ( num := Set{o->first(), d->first()}->min() + Set{o->first(), d->first()}->max() ) else skip ; execute (num)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- nm=input().split() n=set(map(int,input().split())) m=set(map(int,input().split())) min_n=min(n) min_m=min(m) sorted=sorted((str(min_n)+str(min_m))) m_n=n & m if m_n : print(min(m_n)) else : print(sorted[0]+sorted[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var nm : OclAny := input().split() ; var n : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var m : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var min_n : OclAny := (n)->min() ; var min_m : OclAny := (m)->min() ; var sorted : Sequence := (("" + ((min_n))) + ("" + ((min_m))))->sort() ; var m_n : int := MathLib.bitwiseAnd(n, m) ; if m_n then ( execute ((m_n)->min())->display() ) else ( execute ((arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])->union((arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- li1,li2=[int(x)for x in input().split()] lista1=[] lista2=[] lista1=[int(x)for x in input().split()] lista2=[int(x)for x in input().split()] lista1=sorted(lista1) lista2=sorted(lista2) i=0 menor=0 for x in lista1 : if(x in lista2): menor=x break if(menor==0): if(lista1[0]>lista2[0]): print(lista2[0],end="") print(lista1[0]) else : print(lista1[0],end="") print(lista2[0]) else : print(menor) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var li1 : OclAny := null; var li2 : OclAny := null; Sequence{li1,li2} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var lista1 : Sequence := Sequence{} ; var lista2 : Sequence := Sequence{} ; lista1 := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; lista2 := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; lista1 := lista1->sort() ; lista2 := lista2->sort() ; var i : int := 0 ; var menor : int := 0 ; for x : lista1 do ( if ((lista2)->includes(x)) then ( menor := x ; break ) else skip) ; if (menor = 0) then ( if ((lista1->first()->compareTo(lista2->first())) > 0) then ( execute (lista2->first())->display() ; execute (lista1->first())->display() ) else ( execute (lista1->first())->display() ; execute (lista2->first())->display() ) ) else ( execute (menor)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- li1,li2=[int(x)for x in input().split()] lista1=[] lista2=[] lista1=[int(x)for x in input().split()] lista2=[int(x)for x in input().split()] lista1=sorted(lista1) lista2=sorted(lista2) i=0 menor=0 for x in lista1 : if(x in lista2): menor=x break if(menor==0): if(lista1[0]>lista2[0]): print(lista2[0],end="") print(lista1[0]) else : print(lista1[0],end="") print(lista2[0]) else : print(menor) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var li1 : OclAny := null; var li2 : OclAny := null; Sequence{li1,li2} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var lista1 : Sequence := Sequence{} ; var lista2 : Sequence := Sequence{} ; lista1 := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; lista2 := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; lista1 := lista1->sort() ; lista2 := lista2->sort() ; var i : int := 0 ; var menor : int := 0 ; for x : lista1 do ( if ((lista2)->includes(x)) then ( menor := x ; break ) else skip) ; if (menor = 0) then ( if ((lista1->first()->compareTo(lista2->first())) > 0) then ( execute (lista2->first())->display() ; execute (lista1->first())->display() ) else ( execute (lista1->first())->display() ; execute (lista2->first())->display() ) ) else ( execute (menor)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def modify(arr,n): if n<=1 : return prev=arr[0] arr[0]=arr[0]*arr[1] for i in range(1,n-1): curr=arr[i]; arr[i]=prev*arr[i+1] prev=curr arr[n-1]=prev*arr[n-1] arr=[2,3,4,5,6] n=len(arr) modify(arr,n) for i in range(0,n): print(arr[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 })))) ; n := (arr)->size() ; modify(arr, n) ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); operation modify(arr : OclAny, n : OclAny) pre: true post: true activity: if n <= 1 then ( return ) else skip ; var prev : OclAny := arr->first() ; arr->first() := arr->first() * arr[1+1] ; for i : Integer.subrange(1, n - 1-1) do ( var curr : OclAny := arr[i+1]; ; arr[i+1] := prev * arr[i + 1+1] ; prev := curr) ; arr[n - 1+1] := prev * arr[n - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countOccurrence(n,arr,k): cnt,ans=0,0 Hash=dict() for i in range(n): cnt=0 if(arr[i]in Hash.keys()): continue Hash[arr[i]]=1 for j in range(i+1,n): if(arr[j]==arr[i]): cnt+=1 if(cnt>=k): break if(cnt>=k): ans+=1 return ans arr=[1,2,1,3] n=len(arr) k=1 print(countOccurrence(n,arr,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{ 3 }))) ; n := (arr)->size() ; k := 1 ; execute (countOccurrence(n, arr, k))->display(); operation countOccurrence(n : OclAny, arr : OclAny, k : OclAny) : OclAny pre: true post: true activity: var cnt : OclAny := null; var ans : OclAny := null; Sequence{cnt,ans} := Sequence{0,0} ; var Hash : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( var cnt : int := 0 ; if ((Hash.keys())->includes(arr[i+1])) then ( continue ) else skip ; Hash[arr[i+1]+1] := 1 ; for j : Integer.subrange(i + 1, n-1) do ( if (arr[j+1] = arr[i+1]) then ( cnt := cnt + 1 ) else skip ; if ((cnt->compareTo(k)) >= 0) then ( break ) else skip) ; if ((cnt->compareTo(k)) >= 0) then ( ans := ans + 1 ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R,C=3,3 def safe(x,y): if x=0 and y>=0 : return True return False def matrixJump(M,R1,C1): q=[] q.append((1,(R1,C1))) while len(q)!=0 : x=q[0][1][0] y=q[0][1][1] no_of_cells=q[0][0] q.pop(0) if x==R-1 and y==C-1 : return no_of_cells v=M[x][y] if safe(x+v,y): q.append((no_of_cells+1,(x+v,y))) if safe(x,y+v): q.append((no_of_cells+1,(x,y+v))) return-1 if __name__=="__main__" : M=[[2,4,2],[5,3,8],[1,1,1]] print(matrixJump(M,0,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : OclAny := null; var C : OclAny := null; Sequence{R,C} := Sequence{3,3} ; skip ; skip ; if __name__ = "__main__" then ( M := Sequence{Sequence{2}->union(Sequence{4}->union(Sequence{ 2 }))}->union(Sequence{Sequence{5}->union(Sequence{3}->union(Sequence{ 8 }))}->union(Sequence{ Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })) })) ; execute (matrixJump(M, 0, 0))->display() ) else skip; operation safe(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (x->compareTo(R)) < 0 & (y->compareTo(C)) < 0 & x >= 0 & y >= 0 then ( return true ) else skip ; return false; operation matrixJump(M : OclAny, R1 : OclAny, C1 : OclAny) : OclAny pre: true post: true activity: var q : Sequence := Sequence{} ; execute ((Sequence{1, Sequence{R1, C1}}) : q) ; while (q)->size() /= 0 do ( x := q->first()[1+1]->first() ; y := q->first()[1+1][1+1] ; var no_of_cells : OclAny := q->first()->first() ; q := q->excludingAt(0+1) ; if x = R - 1 & y = C - 1 then ( return no_of_cells ) else skip ; var v : OclAny := M[x+1][y+1] ; if safe(x + v, y) then ( execute ((Sequence{no_of_cells + 1, Sequence{x + v, y}}) : q) ) else skip ; if safe(x, y + v) then ( execute ((Sequence{no_of_cells + 1, Sequence{x, y + v}}) : q) ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countEvenOdd(arr,n,K): even=0 ; odd=0 ; for i in range(n): x=bin(arr[i]).count('1'); if(x % 2==0): even+=1 ; else : odd+=1 ; y=bin(K).count('1'); if(y & 1): print("Even=",odd,",Odd=",even); else : print("Even=",even,",Odd=",odd); if __name__=="__main__" : arr=[4,2,15,9,8,8]; K=3 ; n=len(arr); countEvenOdd(arr,n,K); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{4}->union(Sequence{2}->union(Sequence{15}->union(Sequence{9}->union(Sequence{8}->union(Sequence{ 8 }))))); ; K := 3; ; n := (arr)->size(); ; countEvenOdd(arr, n, K); ) else skip; operation countEvenOdd(arr : OclAny, n : OclAny, K : OclAny) pre: true post: true activity: var even : int := 0; var odd : int := 0; ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := bin(arr[i+1])->count('1'); ; if (x mod 2 = 0) then ( even := even + 1; ) else ( odd := odd + 1; )) ; var y : OclAny := bin(K)->count('1'); ; if (MathLib.bitwiseAnd(y, 1)) then ( execute ("Even=")->display(); ) else ( execute ("Even=")->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for l in range(t): input() strm=input() ls=len(strm) strm=strm.rstrip(')') if ls-len(strm)>len(strm): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for l : Integer.subrange(0, t-1) do ( input() ; var strm : String := (OclFile["System.in"]).readLine() ; var ls : int := (strm)->size() ; strm := strm.rstrip(')') ; if (ls - (strm)->size()->compareTo((strm)->size())) > 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter k=int(input()) for _ in range(k): key=input() s=input() length=len(key) ref=Counter(key) cur=Counter() ans=False for i,ch in enumerate(s): cur[ch]+=1 if i>=len(key): cur[s[i-len(key)]]-=1 if i>=len(key)-1 : ans=ans or all(cur[i]==ref[i]for i in ref) print("YES" if ans else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, k-1) do ( var key : String := (OclFile["System.in"]).readLine() ; var s : String := (OclFile["System.in"]).readLine() ; var length : int := (key)->size() ; var ref : OclAny := Counter(key) ; var cur : OclAny := Counter() ; var ans : boolean := false ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var ch : OclAny := _tuple->at(_indx); cur[ch+1] := cur[ch+1] + 1 ; if (i->compareTo((key)->size())) >= 0 then ( cur[s[i - (key)->size()+1]+1] := cur[s[i - (key)->size()+1]+1] - 1 ) else skip ; if (i->compareTo((key)->size() - 1)) >= 0 then ( ans := ans or ((argument (test (logical_test (comparison (comparison (expr (atom (name cur)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (name ref)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name ref))))))))->forAll( _x | _x = true ) ) else skip) ; execute (if ans then "YES" else "NO" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) out=[] for _ in range(t): password=input() hash=input() n=len(password) m=len(hash) if mtoInteger() ; var out : Sequence := Sequence{} ; for _anon : Integer.subrange(0, t-1) do ( var password : String := (OclFile["System.in"]).readLine() ; var hash : String := (OclFile["System.in"]).readLine() ; var n : int := (password)->size() ; var m : int := (hash)->size() ; if (m->compareTo(n)) < 0 then ( execute (("NO") : out) ; continue ) else skip ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for i : Integer.subrange(0, n-1) do ( a[(password[i+1])->char2byte() - 97+1] := a[(password[i+1])->char2byte() - 97+1] + 1 ; b[(hash[i+1])->char2byte() - 97+1] := b[(hash[i+1])->char2byte() - 97+1] + 1) ; if a = b then ( execute (("YES") : out) ; continue ) else skip ; var f : int := 0 ; for i : Integer.subrange(n, m-1) do ( b[(hash[i - n+1])->char2byte() - 97+1] := b[(hash[i - n+1])->char2byte() - 97+1] - 1 ; b[(hash[i+1])->char2byte() - 97+1] := b[(hash[i+1])->char2byte() - 97+1] + 1 ; if a = b then ( execute (("YES") : out) ; f := 1 ; break ) else skip) ; if f = 0 then ( execute (("NO") : out) ) else skip) ; for i : out do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for j in range(int(input())): str1=input() str2=input() flag=False for i in range(len(str2)-len(str1)+1): if sorted(str1)==sorted(str2[i : i+len(str1)]): flag=True break if flag : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for j : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var str1 : String := (OclFile["System.in"]).readLine() ; var str2 : String := (OclFile["System.in"]).readLine() ; var flag : boolean := false ; for i : Integer.subrange(0, (str2)->size() - (str1)->size() + 1-1) do ( if str1->sort() = str2.subrange(i+1, i + (str1)->size())->sort() then ( flag := true ; break ) else skip) ; if flag then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lista=list() for i in range(0,n): a=input() b=input() ad=sorted(a) bs=sorted(b) if(len(a)==len(b)): if(ad==bs): lista.append('YES') else : lista.append('NO') elif(len(b)toInteger() ; var lista : Sequence := () ; for i : Integer.subrange(0, n-1) do ( var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var ad : Sequence := a->sort() ; var bs : Sequence := b->sort() ; if ((a)->size() = (b)->size()) then ( if (ad = bs) then ( execute (('YES') : lista) ) else ( execute (('NO') : lista) ) ) else (if (((b)->size()->compareTo((a)->size())) < 0) then ( execute (('NO') : lista) ) else ( var x : int := 0 ; for i : Integer.subrange(0, ((b)->size() - (a)->size()) + 1-1) do ( var st : OclAny := b.subrange(i+1, (a)->size() + i) ; var sortb : Sequence := st->sort() ; if (ad = sortb) then ( execute (('YES') : lista) ; x := 0 ; break ) else ( x := 1 )) ; if x = 1 then ( execute (('NO') : lista) ) else skip ) ) ) ; for i : Integer.subrange(0, n-1) do ( execute (lista[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): p=input() h=input() n=len(p) N=len(h) p=sorted(p) check=False for i in range(N-n+1): if sorted(h[i : i+n])==p : check=True break ans="YES" if check else "NO" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var p : String := (OclFile["System.in"]).readLine() ; var h : String := (OclFile["System.in"]).readLine() ; var n : int := (p)->size() ; var N : int := (h)->size() ; p := p->sort() ; var check : boolean := false ; for i : Integer.subrange(0, N - n + 1-1) do ( if h.subrange(i+1, i + n)->sort() = p then ( check := true ; break ) else skip) ; var ans : String := if check then "YES" else "NO" endif ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import combinations as comb def main(): while True : n=int(input()) if n==0 : break m=int(input()) result=[[None]*n for _ in range(n)] for _ in range(m): x,y=map(int,input().split()) x-=1 y-=1 result[x][y]=True result[y][x]=False t_count=[lst.count(True)for lst in result] empty_index=[[]for _ in range(n)] empty_nums=[0]*n for i in range(n): for j in range(i+1,n): if result[i][j]==None : empty_index[i].append(j) empty_nums[i]+=1 limit=n//2 def search(x,t_count): if x==n : return 1 choice_num=limit-t_count[x] if choice_num<0 or choice_num>empty_nums[x]: return 0 rest_num=empty_nums[x]-choice_num ret=0 for inds in comb(empty_index[x],rest_num): new_count=t_count[:] for ind in inds : new_count[ind]+=1 ret+=search(x+1,new_count) return ret print(search(0,t_count)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var result : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ null }, n))) ; for _anon : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; x := x - 1 ; y := y - 1 ; result[x+1][y+1] := true ; result[y+1][x+1] := false) ; var t_count : Sequence := result->select(lst | true)->collect(lst | (lst->count(true))) ; var empty_index : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var empty_nums : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if result[i+1][j+1] = null then ( (expr (atom (name empty_index)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) ; empty_nums[i+1] := empty_nums[i+1] + 1 ) else skip)) ; var limit : int := n div 2 ; skip ; execute (search(0, t_count))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import combinations as comb def main(): while True : n=int(input()) if n==0 : break m=int(input()) result=[[None]*n for _ in range(n)] for _ in range(m): x,y=map(int,input().split()) x-=1 y-=1 result[x][y]=True result[y][x]=False t_count=[lst.count(True)for lst in result] empty_index=[[]for _ in range(n)] empty_nums=[0]*n for i in range(n): for j in range(i+1,n): if result[i][j]==None : empty_index[i].append(j) empty_nums[i]+=1 memo={} limit=n//2 def search(x,t_count): if(x,tuple(t_count))in memo : return memo[(x,tuple(t_count))] if x==n : return 1 choice_num=limit-t_count[x] if choice_num<0 or choice_num>empty_nums[x]: return 0 rest_num=empty_nums[x]-choice_num ret=0 for inds in comb(empty_index[x],rest_num): new_count=t_count[:] for ind in inds : new_count[ind]+=1 ret+=search(x+1,new_count) memo[(x,tuple(t_count))]=ret return ret print(search(0,t_count)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var result : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ null }, n))) ; for _anon : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; x := x - 1 ; y := y - 1 ; result[x+1][y+1] := true ; result[y+1][x+1] := false) ; var t_count : Sequence := result->select(lst | true)->collect(lst | (lst->count(true))) ; var empty_index : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var empty_nums : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if result[i+1][j+1] = null then ( (expr (atom (name empty_index)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) ; empty_nums[i+1] := empty_nums[i+1] + 1 ) else skip)) ; var memo : OclAny := Set{} ; var limit : int := n div 2 ; skip ; execute (search(0, t_count))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline M,N=map(int,input().split()) A=list(map(int,input().split())) if M==2 : ANS0=0 ANS1=0 for i in range(N): if A[i]% 2==i % 2 : ANS0+=1 else : ANS1+=1 print(min(ANS0,ANS1)) else : A.append(10**10) count=0 ANS=0 for i in range(N+1): if A[i]==A[i-1]: count+=1 else : ANS+=count//2 count=1 print(ANS) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var M : OclAny := null; var N : OclAny := null; Sequence{M,N} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if M = 2 then ( var ANS0 : int := 0 ; var ANS1 : int := 0 ; for i : Integer.subrange(0, N-1) do ( if A[i+1] mod 2 = i mod 2 then ( ANS0 := ANS0 + 1 ) else ( ANS1 := ANS1 + 1 )) ; execute (Set{ANS0, ANS1}->min())->display() ) else ( execute (((10)->pow(10)) : A) ; var count : int := 0 ; var ANS : int := 0 ; for i : Integer.subrange(0, N + 1-1) do ( if A[i+1] = A[i - 1+1] then ( count := count + 1 ) else ( ANS := ANS + count div 2 ; count := 1 )) ; execute (ANS)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,v,p=map(int,input().split()) a=list(map(int,input().split())) a.sort() def solve(ind): if a[ind]+mn-p : votes.append(m) else : votes.append(thr-a[i]) sm=sum(votes) return sm>=m*v ok=n-1 ng=-1 while abs(ng-ok)>1 : mid=(ng+ok)//2 if solve(mid): ok=mid else : ng=mid print(n-ok) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var v : OclAny := null; var p : OclAny := null; Sequence{n,m,v,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; skip ; var ok : double := n - 1 ; var ng : int := -1 ; while (ng - ok)->abs() > 1 do ( var mid : int := (ng + ok) div 2 ; if solve(mid) then ( ok := mid ) else ( ng := mid )) ; execute (n - ok)->display(); operation solve(ind : OclAny) : OclAny pre: true post: true activity: if (a[ind+1] + m->compareTo(a->reverse()->at(-(-p)))) < 0 then ( return false ) else skip ; var thr : OclAny := a[ind+1] + m ; var votes : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if (i->compareTo(ind)) <= 0 or (i->compareTo(n - p)) > 0 then ( execute ((m) : votes) ) else ( execute ((thr - a[i+1]) : votes) )) ; var sm : OclAny := (votes)->sum() ; return (sm->compareTo(m * v)) >= 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def main(n): m=int(input()) d=defaultdict(int) k=0 for i in range(1,n+1): for j in range(i+1,n+1): d[k]=(i,j) k+=1 p=defaultdict(int) for i in range(m): x,y=map(int,input().split()) p[(x,y)]=1 p[(y,x)]=-1 ans=defaultdict(int) tmp=[0]*n ans[tuple(tmp)]=1 for i in range(k): nd=defaultdict(int) for key,value in ans.items(): key=list(key) x,y=d[i] if p[(x,y)]: if p[(x,y)]==1 : if key[x-1]==n//2 : continue key[x-1]+=1 nd[tuple(key)]+=value else : if key[y-1]==n//2 : continue key[y-1]+=1 nd[tuple(key)]+=value else : if key[y-1]!=n//2 : key[y-1]+=1 nd[tuple(key)]+=value key[y-1]+=-1 if key[x-1]!=n//2 : key[x-1]+=1 nd[tuple(key)]+=value ans=nd print(ans[tuple([n//2]*n)]) if __name__=="__main__" : while 1 : n=int(input()) if n : main(n) else : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( while 1 do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n then ( main(n) ) else ( break )) ) else skip; operation main(n : OclAny) pre: true post: true activity: var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : OclAny := defaultdict(OclType["int"]) ; var k : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(i + 1, n + 1-1) do ( d[k+1] := Sequence{i, j} ; k := k + 1)) ; var p : OclAny := defaultdict(OclType["int"]) ; for i : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; p[Sequence{x, y}+1] := 1 ; p[Sequence{y, x}+1] := -1) ; var ans : OclAny := defaultdict(OclType["int"]) ; var tmp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; ans->restrict((tmp)) := 1 ; for i : Integer.subrange(0, k-1) do ( var nd : OclAny := defaultdict(OclType["int"]) ; for _tuple : ans->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); var key : Sequence := (key) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := d[i+1] ; if p[Sequence{x, y}+1] then ( if p[Sequence{x, y}+1] = 1 then ( if key[x - 1+1] = n div 2 then ( continue ) else skip ; key[x - 1+1] := key[x - 1+1] + 1 ; nd->restrict((key)) := nd->restrict((key)) + value ) else ( if key[y - 1+1] = n div 2 then ( continue ) else skip ; key[y - 1+1] := key[y - 1+1] + 1 ; nd->restrict((key)) := nd->restrict((key)) + value ) ) else ( if key[y - 1+1] /= n div 2 then ( key[y - 1+1] := key[y - 1+1] + 1 ; nd->restrict((key)) := nd->restrict((key)) + value ; key[y - 1+1] := key[y - 1+1] + -1 ) else skip ; if key[x - 1+1] /= n div 2 then ( key[x - 1+1] := key[x - 1+1] + 1 ; nd->restrict((key)) := nd->restrict((key)) + value ) else skip )) ; ans := nd) ; execute (ans->restrict((MatrixLib.elementwiseMult(Sequence{ n div 2 }, n))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import* from math import* from decimal import* from collections import* import numbers from operator import index import sys def _input(): return map(int,input().split()) def _list(): return list(map(int,input().split())) def _int(): return int(input()) def solves(): n=int(input()) s=list(input()) indx=0 for i in range(n-1,-1,-1): if s[i]==')' : indx+=1 else : break if(n-indxtoInteger() ; for _anon : Integer.subrange(0, t-1) do ( solves()); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation _list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation _int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation solves() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var indx : int := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if s[i+1] = ')' then ( indx := indx + 1 ) else ( break )) ; if ((n - indx->compareTo(indx)) < 0) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from itertools import combinations def dfs(idx,N,win_cnt,will_match): if(idx==N): return 1 need_win=(N-1)//2-win_cnt[idx] need_lose=len(will_match[idx])-need_win if(need_win>len(will_match[idx])or need_win<0): return 0 res=0 for it in combinations(will_match[idx],need_lose): tmp=win_cnt.copy() for i in it : tmp[i]+=1 res+=dfs(idx+1,N,tmp,will_match) return res def solve(N): M=int(input()) XY=[[int(i)-1 for i in input().split()]for _ in range(M)] win_cnt=[0]*N match=[[-1]*N for _ in range(N)] for x,y in XY : match[x][y]=1 match[y][x]=0 win_cnt[x]+=1 if(x>y): x,y=y,x will_match=[[]for _ in range(N)] for i in range(N): for j in range(i+1,N): if(match[i][j]==-1): will_match[i].append(j) ans=dfs(0,N,win_cnt,will_match) print(ans) def main(): input=sys.stdin.readline while True : N=int(input()) if(not N): break solve(N) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation dfs(idx : OclAny, N : OclAny, win_cnt : OclAny, will_match : OclAny) : OclAny pre: true post: true activity: if (idx = N) then ( return 1 ) else skip ; var need_win : double := (N - 1) div 2 - win_cnt[idx+1] ; var need_lose : double := (will_match[idx+1])->size() - need_win ; if ((need_win->compareTo((will_match[idx+1])->size())) > 0 or need_win < 0) then ( return 0 ) else skip ; var res : int := 0 ; for it : combinations(will_match[idx+1], need_lose) do ( var tmp : OclAny := win_cnt->copy() ; for i : it do ( tmp[i+1] := tmp[i+1] + 1) ; res := res + dfs(idx + 1, N, tmp, will_match)) ; return res; operation solve(N : OclAny) pre: true post: true activity: var M : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var XY : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger() - 1)))) ; win_cnt := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var match : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ -1 }, N))) ; for _tuple : XY do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); match[x+1][y+1] := 1 ; match[y+1][x+1] := 0 ; win_cnt[x+1] := win_cnt[x+1] + 1 ; if ((x->compareTo(y)) > 0) then ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{y,x} ) else skip) ; will_match := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(i + 1, N-1) do ( if (match[i+1][j+1] = -1) then ( (expr (atom (name will_match)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) ) else skip)) ; var ans : OclAny := dfs(0, N, win_cnt, will_match) ; execute (ans)->display(); operation main() pre: true post: true activity: var input : OclAny := (OclFile["System.in"]).readline ; while true do ( N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (not(N)) then ( break ) else skip ; solve(N)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import product while 1 : N=int(input()) if N==0 : break M=int(input()) S=[0]*N A=[[None]*N for i in range(N)] for i in range(M): x,y=map(int,input().split()); x-=1 ; y-=1 S[x]+=1 A[x][y]=1 ; A[y][x]=0 B=[] for i in range(N): for j in range(i+1,N): if A[i][j]is None : B.append((i,j)) L=len(B) memo=[{}for i in range(L)] def dfs(k,s): if L==k : return all(e<=N//2 for e in s) key=tuple(s) v=memo[k] if key in v : return v[key] res=0 i,j=B[k] if s[i]+1<=N//2 : s[i]+=1 res+=dfs(k+1,s) s[i]-=1 if s[j]+1<=N//2 : s[j]+=1 res+=dfs(k+1,s) s[j]-=1 v[key]=res return res print(dfs(0,S)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while 1 do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var M : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var A : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ null }, N))) ; for i : Integer.subrange(0, M-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); x := x - 1; y := y - 1 ; S[x+1] := S[x+1] + 1 ; A[x+1][y+1] := 1; A[y+1][x+1] := 0) ; var B : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(i + 1, N-1) do ( if A[i+1][j+1] <>= null then ( execute ((Sequence{i, j}) : B) ) else skip)) ; var L : int := (B)->size() ; var memo : Sequence := Integer.subrange(0, L-1)->select(i | true)->collect(i | (Set{})) ; skip ; execute (dfs(0, S))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) from collections import Counter c=Counter(a) a100=c[100] a200=c[200] rest_pair=a200 % 2 rest_100=a100-2*rest_pair if rest_100>=0 and rest_100 % 2==0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; var c : OclAny := Counter(a) ; var a100 : OclAny := c[100+1] ; var a200 : OclAny := c[200+1] ; var rest_pair : int := a200 mod 2 ; var rest var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()00 : double := a100 - 2 * rest_pair ; if rest var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()00 >= 0 & rest var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()00 mod 2 = 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) fg=0 if a.count(100)% 2==1 : fg=1 print('NO') if sum(a)% 2==1 and fg==0 : fg=1 print('NO') elif fg==0 : if a.count(100)>0 : print('YES') else : if n % 2 : print('NO') else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var fg : int := 0 ; if a->count(100) mod 2 = 1 then ( fg := 1 ; execute ('NO')->display() ) else skip ; if (a)->sum() mod 2 = 1 & fg = 0 then ( fg := 1 ; execute ('NO')->display() ) else (if fg = 0 then ( if a->count(100) > 0 then ( execute ('YES')->display() ) else ( if n mod 2 then ( execute ('NO')->display() ) else ( execute ('YES')->display() ) ) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=0 b=0 apples=[int(i)for i in input().split()] a=apples.count(100) b=apples.count(200) if(a % 2==0): if(b % 2==0): print("YES") elif(a>=2): print("YES") else : print("NO") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := 0 ; var b : int := 0 ; var apples : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; a := apples->count(100) ; b := apples->count(200) ; if (a mod 2 = 0) then ( if (b mod 2 = 0) then ( execute ("YES")->display() ) else (if (a >= 2) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) L=list(map(int,input().split())) if(sum(L)/2)% 100!=0 : print("NO") elif 100 not in L and n % 2!=0 : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var L : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if ((L)->sum() / 2) mod 100 /= 0 then ( execute ("NO")->display() ) else (if (L)->excludes(100) & n mod 2 /= 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) elems=list(sorted(map(int,input().split(' ')))) s1,s2=0,0 while elems : x=elems.pop() if s1>s2 : s2+=x else : s1+=x print("YES" if s1==s2 else "NO") if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var elems : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )->sort()) ; var s1 : OclAny := null; var s2 : OclAny := null; Sequence{s1,s2} := Sequence{0,0} ; while elems do ( var x : OclAny := elems->last() ; elems := elems->front() ; if (s1->compareTo(s2)) > 0 then ( s2 := s2 + x ) else ( s1 := s1 + x )) ; execute (if s1 = s2 then "YES" else "NO" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=2005 ans=dict() def dfs(n,left,ct): if(ct>=15): return if(left==0): ans[n]=1 for i in range(min(left,9)+1): dfs(n*10+i,left-i,ct+1) def getKthNum(m,k): dfs(0,m,0) c=0 for it in sorted(ans.keys()): c+=1 if(c==k): return it return-1 m=5 k=3 print(getKthNum(m,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 2005 ; var ans : Map := (arguments ( )) ; skip ; skip ; m := 5 ; k := 3 ; execute (getKthNum(m, k))->display(); operation dfs(n : OclAny, left : OclAny, ct : OclAny) pre: true post: true activity: if (ct >= 15) then ( return ) else skip ; if (left = 0) then ( ans[n+1] := 1 ) else skip ; for i : Integer.subrange(0, Set{left, 9}->min() + 1-1) do ( dfs(n * 10 + i, left - i, ct + 1)); operation getKthNum(m : OclAny, k : OclAny) : OclAny pre: true post: true activity: dfs(0, m, 0) ; var c : int := 0 ; for it : ans.keys()->sort() do ( c := c + 1 ; if (c = k) then ( return it ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) P=[list(map(int,input().split()))for i in range(N)] P.sort() su=0 S=-P[0][0] ans=-10**19 for a,b in P : S=min(S,su-a) ans=max(ans,su+b-a-S) su+=b print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var P : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; P := P->sort() ; var su : int := 0 ; var S : OclAny := -P->first()->first() ; var ans : double := (-10)->pow(19) ; for _tuple : P do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); S := Set{S, su - a}->min() ; ans := Set{ans, su + b - a - S}->max() ; su := su + b) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input=raw_input def answer(): n,m,v,p=map(int,input().split(" ")) nums=sorted(map(int,input().split(" ")),reverse=True) num_last=nums[p-1] nokori_sum=sum(nums[p-1 : n]) out=p count=0 if v>p : cumsum={} cur=0 cur=0 for i in range(p-1,n): x=nums[i] cur+=x cumsum[i]=cur for i in range(p,n): x=nums[i] if x+mnokori_yoyuu : break count+=1 out+=count else : for x in nums[p :]: if x+mcollect( _x | (OclType["int"])->apply(_x) ) ; var nums : Sequence := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var num_last : OclAny := nums[p - 1+1] ; var nokori_sum : OclAny := (nums.subrange(p - 1+1, n))->sum() ; var out : OclAny := p ; var count : int := 0 ; if (v->compareTo(p)) > 0 then ( var cumsum : OclAny := Set{} ; var cur : int := 0 ; cur := 0 ; for i : Integer.subrange(p - 1, n-1) do ( var x : OclAny := nums[i+1] ; cur := cur + x ; cumsum[i+1] := cur) ; for i : Integer.subrange(p, n-1) do ( x := nums[i+1] ; if (x + m->compareTo(num_last)) < 0 then ( break ) else skip ; var area1 : double := (x + m) * (i - p + 1) - cumsum[i - 1+1] ; var area2 : double := (n - i - 1) * m ; var nokori_yoyuu : OclAny := area1 + area2 ; var cost : double := (v - p) * m ; if (cost->compareTo(nokori_yoyuu)) > 0 then ( break ) else skip ; count := count + 1) ; out := out + count ) else ( for x : nums.subrange(p+1) do ( if (x + m->compareTo(num_last)) < 0 then ( break ) else skip ; count := count + 1) ; out := out + count ) ; execute (out)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getN(): return int(input()) def getNM(): return map(int,input().split()) def getList(): return list(map(int,input().split())) def getArray(intn): return[int(input())for i in range(intn)] def input(): return sys.stdin.readline().rstrip() def rand_N(ran1,ran2): return random.randint(ran1,ran2) def rand_List(ran1,ran2,rantime): return[random.randint(ran1,ran2)for i in range(rantime)] def rand_ints_nodup(ran1,ran2,rantime): ns=[] while len(ns)pow(9) + 7 ; var N : OclAny := null; var Z : OclAny := null; var W : OclAny := null; Sequence{N,Z,W} := getNM() ; var A : OclAny := getList() ; if N = 1 then ( execute ((A->first() - W)->abs())->display() ) else ( execute (Set{(A->last() - W)->abs(), (A->last() - A->front()->last())->abs()}->max())->display() ); operation getN() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation getNM() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation getList() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation getArray(intn : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, intn-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation rand_N(ran1 : OclAny, ran2 : OclAny) : OclAny pre: true post: true activity: return (ran1 + (OclRandom.defaultInstanceOclRandom()).nextInt(ran2 - ran1)); operation rand_List(ran1 : OclAny, ran2 : OclAny, rantime : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rantime-1)->select(i | true)->collect(i | ((ran1 + (OclRandom.defaultInstanceOclRandom()).nextInt(ran2 - ran1)))); operation rand_ints_nodup(ran1 : OclAny, ran2 : OclAny, rantime : OclAny) : OclAny pre: true post: true activity: var ns : Sequence := Sequence{} ; while ((ns)->size()->compareTo(rantime)) < 0 do ( var n : int := (ran1 + (OclRandom.defaultInstanceOclRandom()).nextInt(ran2 - ran1)) ; if not((ns)->includes(n)) then ( execute ((n) : ns) ) else skip) ; return ns->sort(); operation rand_query(ran1 : OclAny, ran2 : OclAny, rantime : OclAny) : OclAny pre: true post: true activity: var r_query : Sequence := Sequence{} ; while ((r_query)->size()->compareTo(rantime)) < 0 do ( var n_q : OclAny := rand_ints_nodup(ran1, ran2, 2) ; if not((r_query)->includes(n_q)) then ( execute ((n_q) : r_query) ) else skip) ; return r_query->sort(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(2000000000) input=lambda : sys.stdin.readline().rstrip('\n') n=int(input()) data=[] s=[0] for i in range(n): data.append(tuple(map(int,input().split()))) data=[(0,0)]+sorted(data) for i in range(n): s.append(s[-1]+data[i+1][1]) mx=0 ans=0 mn=10**18 for i in range(1,n+1): if mn>s[i-1]-data[i][0]: mn=s[i-1]-data[i][0] if anstoInteger() ; var data : Sequence := Sequence{} ; var s : Sequence := Sequence{ 0 } ; for i : Integer.subrange(0, n-1) do ( execute ((((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))) : data)) ; data := Sequence{ Sequence{0, 0} }->union(data->sort()) ; for i : Integer.subrange(0, n-1) do ( execute ((s->last() + data[i + 1+1][1+1]) : s)) ; var mx : int := 0 ; var ans : int := 0 ; var mn : double := (10)->pow(18) ; for i : Integer.subrange(1, n + 1-1) do ( if (mn->compareTo(s[i - 1+1] - data[i+1]->first())) > 0 then ( mn := s[i - 1+1] - data[i+1]->first() ) else skip ; if (ans->compareTo(s[i+1] - data[i+1]->first() - mn)) < 0 then ( ans := s[i+1] - data[i+1]->first() - mn ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def makePolygon(a): n=360/(180-a) if n==int(n): print("YES") else : print("NO") if __name__=="__main__" : a=90 makePolygon(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := 90 ; makePolygon(a) ) else skip; operation makePolygon(a : OclAny) pre: true post: true activity: var n : double := 360 / (180 - a) ; if n = ("" + ((n)))->toInteger() then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAXN=100000 MOD=1000000007 fact=[0]*MAXN ; def factorial(): fact[0]=1 for i in range(1,MAXN): fact[i]=(fact[i-1]*i)% MOD def power(x,y,p): res=1 x=x % p while(y>0): if(y & 1): res=(res*x)% p y=y>>1 ; x=(x*x)% p return res def modInverse(x,p): return power(x,p-2,p) def countDifferentNumbers(arr,P): factorial(); res=0 ; X=0 ; for i in range(10): X+=arr[i] res=fact[X] for i in range(10): if(arr[i]>1): res=(res*modInverse(fact[arr[i]],P))% P ; return res ; if __name__=="__main__" : arr=[1,0,2,0,0,7,4,0,0,3] print(countDifferentNumbers(arr,MOD)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAXN : int := 100000 ; var MOD : int := 1000000007 ; var fact : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAXN); ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{0}->union(Sequence{2}->union(Sequence{0}->union(Sequence{0}->union(Sequence{7}->union(Sequence{4}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 3 }))))))))) ; execute (countDifferentNumbers(arr, MOD))->display() ) else skip; operation factorial() pre: true post: true activity: fact->first() := 1 ; for i : Integer.subrange(1, MAXN-1) do ( fact[i+1] := (fact[i - 1+1] * i) mod MOD); operation power(x : OclAny, y : OclAny, p : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; x := x mod p ; while (y > 0) do ( if (MathLib.bitwiseAnd(y, 1)) then ( res := (res * x) mod p ) else skip ; y := y /(2->pow(1)); ; x := (x * x) mod p) ; return res; operation modInverse(x : OclAny, p : OclAny) : OclAny pre: true post: true activity: return power(x, p - 2, p); operation countDifferentNumbers(arr : OclAny, P : OclAny) pre: true post: true activity: factorial(); ; res := 0; var X : int := 0; ; for i : Integer.subrange(0, 10-1) do ( X := X + arr[i+1]) ; res := fact[X+1] ; for i : Integer.subrange(0, 10-1) do ( if (arr[i+1] > 1) then ( res := (res * modInverse(fact[arr[i+1]+1], P)) mod P; ) else skip) ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def countPairs(N): count=0 for i in range(1,int(math.pow(N,1/3)+1)): cb=i*i*i diff=N-cb cbrtDiff=int(math.pow(diff,1/3)) if(cbrtDiff*cbrtDiff*cbrtDiff==diff): count+=1 return count for i in range(1,11): print('For n=',i,',',countPairs(i),' pair exists') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for i : Integer.subrange(1, 11-1) do ( execute ('For n=')->display()); operation countPairs(N : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(1, ("" + (((N)->pow(1 / 3) + 1)))->toInteger()-1) do ( var cb : double := i * i * i ; var diff : double := N - cb ; var cbrtDiff : int := ("" + (((diff)->pow(1 / 3))))->toInteger() ; if (cbrtDiff * cbrtDiff * cbrtDiff = diff) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : marks=[25,65,46,98,78,65] max_marks=len(marks)*100 total=0 grade='F' for i in range(len(marks)): total+=marks[i] percentage=((total)/max_marks)*100 if(percentage>=90): grade='A' else : if(percentage>=80 and percentage<=89): grade='B' else : if(percentage>=60 and percentage<=79): grade='C' else : if(percentage>=33 and percentage<=59): grade='D' else : grade='F' print(grade) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var marks : Sequence := Sequence{25}->union(Sequence{65}->union(Sequence{46}->union(Sequence{98}->union(Sequence{78}->union(Sequence{ 65 }))))) ; var max_marks : int := (marks)->size() * 100 ; var total : int := 0 ; var grade : String := 'F' ; for i : Integer.subrange(0, (marks)->size()-1) do ( total := total + marks[i+1]) ; var percentage : double := ((total) / max_marks) * 100 ; if (percentage >= 90) then ( grade := 'A' ) else ( if (percentage >= 80 & percentage <= 89) then ( grade := 'B' ) else ( if (percentage >= 60 & percentage <= 79) then ( grade := 'C' ) else ( if (percentage >= 33 & percentage <= 59) then ( grade := 'D' ) else ( grade := 'F' ) ) ) ) ; execute (grade)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getMaxLength(arr,n): l=n ; i=0 ; maxlen=0 ; while(iunion(Sequence{ 4 }); ; n := (arr)->size() ; execute (getMaxLength(arr, n))->display(); ) else skip; operation getMaxLength(arr : OclAny, n : OclAny) pre: true post: true activity: var l : OclAny := n; ; var i : int := 0; var maxlen : int := 0; ; while ((i->compareTo(l)) < 0) do ( var j : int := i; ; while ((i + 1->compareTo(l)) < 0 & ((arr[i+1] - arr[i + 1+1])->abs() = 1 or (arr[i+1] - arr[i + 1+1])->abs() = 0)) do ( i := i + 1;) ; var currLen : double := i - j + 1; ; if ((maxlen->compareTo(currLen)) < 0) then ( maxlen := currLen; ) else skip ; if (j = i) then ( i := i + 1; ) else skip) ; return maxlen;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def subarrayXor(arr,n,m): ans=0 xorArr=[0 for _ in range(n)] mp=dict() xorArr[0]=arr[0] for i in range(1,n): xorArr[i]=xorArr[i-1]^ arr[i] for i in range(n): tmp=m ^ xorArr[i] if tmp in mp.keys(): ans=ans+(mp[tmp]) if(xorArr[i]==m): ans+=1 mp[xorArr[i]]=mp.get(xorArr[i],0)+1 return ans arr=[4,2,2,6,4] n=len(arr) m=6 print("Number of subarrays having given XOR is",subarrayXor(arr,n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{4}->union(Sequence{2}->union(Sequence{2}->union(Sequence{6}->union(Sequence{ 4 })))) ; n := (arr)->size() ; m := 6 ; execute ("Number of subarrays having given XOR is")->display(); operation subarrayXor(arr : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; var xorArr : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)) ; var mp : Map := (arguments ( )) ; xorArr->first() := arr->first() ; for i : Integer.subrange(1, n-1) do ( xorArr[i+1] := MathLib.bitwiseXor(xorArr[i - 1+1], arr[i+1])) ; for i : Integer.subrange(0, n-1) do ( var tmp : int := MathLib.bitwiseXor(m, xorArr[i+1]) ; if (mp.keys())->includes(tmp) then ( ans := ans + (mp[tmp+1]) ) else skip ; if (xorArr[i+1] = m) then ( ans := ans + 1 ) else skip ; mp[xorArr[i+1]+1] := mp.get(xorArr[i+1], 0) + 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nth_term(n): a=1 b=1 c=1 for i in range(0,n): c=a+b a=b b=c return c n=10 c=nth_term(n) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 10 ; c := nth_term(n) ; execute (c)->display(); operation nth_term(n : OclAny) : OclAny pre: true post: true activity: var a : int := 1 ; var b : int := 1 ; var c : int := 1 ; for i : Integer.subrange(0, n-1) do ( c := a + b ; a := b ; b := c) ; return c; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def factorial(n): result=1 for i in range(1,n+1): result*=i return result def nCr(n,r): return(factorial(n)//(factorial(r)*factorial(n-r))) def calculate_result(n): result=2*nCr((n-2),(n//2-1)) return result if __name__=="__main__" : a,b=2,4 print(calculate_result(2*a)) print(calculate_result(2*b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{2,4} ; execute (calculate_result(2 * a))->display() ; execute (calculate_result(2 * b))->display() ) else skip; operation factorial(n : OclAny) : OclAny pre: true post: true activity: var result : int := 1 ; for i : Integer.subrange(1, n + 1-1) do ( result := result * i) ; return result; operation nCr(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: return (factorial(n) div (factorial(r) * factorial(n - r))); operation calculate_result(n : OclAny) : OclAny pre: true post: true activity: result := 2 * nCr((n - 2), (n div 2 - 1)) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): sums=list(map(int,input().split())) num1=sums[0] num2=sums[1] num3=0 if sums[2]!=num1+num2 : num3=sums[2] else : num3=sums[3] print(str(num1)+" "+str(num2)+" "+str(num3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var sums : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var num1 : OclAny := sums->first() ; var num2 : OclAny := sums[1+1] ; var num3 : int := 0 ; if sums[2+1] /= num1 + num2 then ( num3 := sums[2+1] ) else ( num3 := sums[3+1] ) ; execute (("" + ((num1))) + " " + ("" + ((num2))) + " " + ("" + ((num3))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) s=input() x=s.rstrip(')') p=len(s)-len(x) if p>len(x): print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var x : String := s.rstrip(')') ; var p : double := (s)->size() - (x)->size() ; if (p->compareTo((x)->size())) > 0 then ( execute ('Yes')->display() ) else ( execute ('No')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 input=lambda : sys.stdin.readline().rstrip() def bisection(l,r,f,left=True,discrete=True): eps=1 if(discrete)else 10**-8 if((not left)^ f(r)): return r if(left)else r+1 elif(left ^ f(l)): return l-1 if(left)else l while(r-l>eps): h=(l+r)//2 if(discrete)else(l+r)/2 if((not left)^ f(h)): l=h else : r=h return(l+r)/2 if(not discrete)else l if(left)else r def resolve(): n,m,v,p=map(int,input().split()) A=list(map(int,input().split())) A.sort() def check(i): rest=(v-(i+1)-(p-1))*m s=A[i]+m for j in range(i+1,n-p+1): if(stoReal() ; var MOD : double := (10)->pow(9) + 7 ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; skip ; skip ; resolve(); operation bisection(l : OclAny, r : OclAny, f : OclAny, left : OclAny, discrete : OclAny) : OclAny pre: true post: true activity: if left->oclIsUndefined() then left := true else skip; if discrete->oclIsUndefined() then discrete := true else skip; var eps : int := if (discrete) then 1 else (10)->pow(-8) endif ; if (MathLib.bitwiseXor((not(left)), f(r))) then ( return if (left) then r else r + 1 endif ) else (if (MathLib.bitwiseXor(left, f(l))) then ( return if (left) then l - 1 else l endif ) else skip) ; while ((r - l->compareTo(eps)) > 0) do ( var h : int := if (discrete) then (l + r) div 2 else (l + r) / 2 endif ; if (MathLib.bitwiseXor((not(left)), f(h))) then ( l := h ) else ( r := h )) ; return if (not(discrete)) then (l + r) / 2 else if (left) then l else r endif endif; operation resolve() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var v : OclAny := null; var p : OclAny := null; Sequence{n,m,v,p} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; A := A->sort() ; skip ; execute (n - bisection(0, n - 1, check, (argument (test (logical_test (comparison (expr (atom (name left)))))) = (test (logical_test (comparison (expr (atom (name False)))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): lst=list(map(int,input().split())) print(lst[0],lst[1],lst[6]-lst[0]-lst[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (lst->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): a=list(map(int,input().split())) x=a[-1]-a[-2] y=a[-1]-a[-3] z=a[-1]-x-y print(x,y,z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : double := a->last() - a->front()->last() ; var y : double := a->last() - a->reverse()->at(-(-3)) ; var z : double := a->last() - x - y ; execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): L=list(map(int,input().split())) a,b=L[0],L[1] if L[2]==a+b : c=L[3] else : c=L[2] print(a,b,c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var L : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{L->first(),L[1+1]} ; if L[2+1] = a + b then ( var c : OclAny := L[3+1] ) else ( c := L[2+1] ) ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for x in range(int(input())): a=list(map(int,input().split())) print(a[0],a[1],a[-1]-a[0]-a[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for x : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (a->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def maxVol(P,A): l=(P-sqrt(P*P-24*A))/12 V=l*(A/2.0-l*(P/4.0-l)) return V if __name__=='__main__' : P=20 A=16 print(maxVol(P,A)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( P := 20 ; A := 16 ; execute (maxVol(P, A))->display() ) else skip; operation maxVol(P : OclAny, A : OclAny) : OclAny pre: true post: true activity: var l : double := (P - sqrt(P * P - 24 * A)) / 12 ; var V : double := l * (A / 2.0 - l * (P / 4.0 - l)) ; return V; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): MOD=1000000007 s,t=input(),input() n,m=len(s),len(t) dp=[[0 for i in range(m+1)]for j in range(n+1)] dp[0][0]=1 for i in range(n): for j in range(m-1,-1,-1): dp[i+1][j]+=dp[i][j] dp[i+1][j]%=MOD if s[i]==t[j]: dp[i+1][j+1]+=dp[i][j] dp[i+1][j+1]%=MOD sum=0 for i in range(n+1): sum+=dp[i][m] print(sum % MOD) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var MOD : int := 1000000007 ; var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine()} ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{(s)->size(),(t)->size()} ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, m + 1-1)->select(i | true)->collect(i | (0)))) ; dp->first()->first() := 1 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(-1 + 1, m - 1)->reverse() do ( dp[i + 1+1][j+1] := dp[i + 1+1][j+1] + dp[i+1][j+1] ; dp[i + 1+1][j+1] := dp[i + 1+1][j+1] mod MOD ; if s[i+1] = t[j+1] then ( dp[i + 1+1][j + 1+1] := dp[i + 1+1][j + 1+1] + dp[i+1][j+1] ; dp[i + 1+1][j + 1+1] := dp[i + 1+1][j + 1+1] mod MOD ) else skip)) ; var sum : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( sum := sum + dp[i+1][m+1]) ; execute (sum mod MOD)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=input() b=input() MOD=10**9+7 cnts=[0]*(len(b)+1) cnts[0]=1 for c in t : for i in range(len(b)-1,-1,-1): if c==b[i]: cnts[i+1]=(cnts[i+1]+cnts[i])% MOD print(cnts[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var MOD : double := (10)->pow(9) + 7 ; var cnts : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((b)->size() + 1)) ; cnts->first() := 1 ; for c : t->characters() do ( for i : Integer.subrange(-1 + 1, (b)->size() - 1)->reverse() do ( if c = b[i+1] then ( cnts[i + 1+1] := (cnts[i + 1+1] + cnts[i+1]) mod MOD ) else skip)) ; execute (cnts->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=1000000007 t=input() b=input() lent=len(t) lenb=len(b) dp=[[0]*(lenb+1)for _ in range(lent+1)] for i in range(lent+1): dp[i][0]=1 for x in range(1,lent+1): for y in range(1,lenb+1): dp[x][y]=(dp[x-1][y]+dp[x-1][y-1]*(t[x-1]==b[y-1]))% MOD print(dp[lent][lenb]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : int := 1000000007 ; var t : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var lent : int := (t)->size() ; var lenb : int := (b)->size() ; var dp : Sequence := Integer.subrange(0, lent + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (lenb + 1)))) ; for i : Integer.subrange(0, lent + 1-1) do ( dp[i+1]->first() := 1) ; for x : Integer.subrange(1, lent + 1-1) do ( for y : Integer.subrange(1, lenb + 1-1) do ( dp[x+1][y+1] := (dp[x - 1+1][y+1] + dp[x - 1+1][y - 1+1] * (t[x - 1+1] = b[y - 1+1])) mod MOD)) ; execute (dp[lent+1][lenb+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=1000000007 t=input() b=input() lent=len(t) lenb=len(b) dp=[0]*(lenb+1) dp[0]=1 for x in range(1,lent+1): ct=t[x-1] for y in range(lenb,0,-1): if ct==b[y-1]: dp[y]+=dp[y-1] dp[y]%=MOD print(dp[lenb]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : int := 1000000007 ; var t : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var lent : int := (t)->size() ; var lenb : int := (b)->size() ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (lenb + 1)) ; dp->first() := 1 ; for x : Integer.subrange(1, lent + 1-1) do ( var ct : OclAny := t[x - 1+1] ; for y : Integer.subrange(0 + 1, lenb)->reverse() do ( if ct = b[y - 1+1] then ( dp[y+1] := dp[y+1] + dp[y - 1+1] ; dp[y+1] := dp[y+1] mod MOD ) else skip)) ; execute (dp[lenb+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def func(x): return(float(1)/(1+x*x)) def calculate(lower_limit,upper_limit,interval_limit): interval_size=(float(upper_limit-lower_limit)/interval_limit) sum=func(lower_limit)+func(upper_limit); for i in range(1,interval_limit): if(i % 3==0): sum=sum+2*func(lower_limit+i*interval_size) else : sum=sum+3*func(lower_limit+i*interval_size) return((float(3*interval_size)/8)*sum) interval_limit=10 lower_limit=1 upper_limit=10 integral_res=calculate(lower_limit,upper_limit,interval_limit) print(round(integral_res,6)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; interval_limit := 10 ; lower_limit := 1 ; upper_limit := 10 ; var integral_res : OclAny := calculate(lower_limit, upper_limit, interval_limit) ; execute (MathLib.roundN(integral_res, 6))->display(); operation func(x : OclAny) : OclAny pre: true post: true activity: return (("" + ((1)))->toReal() / (1 + x * x)); operation calculate(lower_limit : OclAny, upper_limit : OclAny, interval_limit : OclAny) : OclAny pre: true post: true activity: var interval_size : double := (("" + ((upper_limit - lower_limit)))->toReal() / interval_limit) ; var sum : OclAny := func(lower_limit) + func(upper_limit); ; for i : Integer.subrange(1, interval_limit-1) do ( if (i mod 3 = 0) then ( sum := sum + 2 * func(lower_limit + i * interval_size) ) else ( sum := sum + 3 * func(lower_limit + i * interval_size) )) ; return ((("" + ((3 * interval_size)))->toReal() / 8) * sum); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) s=input() t=s.rstrip(")") print("Yes" if n-len(t)>len(t)else "No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var t : String := s.rstrip(")") ; execute (if (n - (t)->size()->compareTo((t)->size())) > 0 then "Yes" else "No" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=input() b=input() table=[[0 for i in range(len(t))]for j in range(len(b))] if len(t)>len(b): if t[0]==b[0]: table[0][0]=1 for i in range(1,len(t)): if t[i]==b[0]: table[0][i]=table[0][i-1]+1 else : table[0][i]=table[0][i-1] for i in range(1,len(b)): if b[i]==t[i]: table[i][i]=table[i-1][i-1] for j in range(i+1,len(t)): if b[i]==t[j]: table[i][j]=table[i-1][j-1]+table[i][j-1] else : table[i][j]=table[i][j-1] print(table[len(b)-1][len(t)-1]% 1000000007) elif len(t)==len(b): if t==b : print(1) else : print(0) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var table : Sequence := Integer.subrange(0, (b)->size()-1)->select(j | true)->collect(j | (Integer.subrange(0, (t)->size()-1)->select(i | true)->collect(i | (0)))) ; if ((t)->size()->compareTo((b)->size())) > 0 then ( if t->first() = b->first() then ( table->first()->first() := 1 ) else skip ; for i : Integer.subrange(1, (t)->size()-1) do ( if t[i+1] = b->first() then ( table->first()[i+1] := table->first()[i - 1+1] + 1 ) else ( table->first()[i+1] := table->first()[i - 1+1] )) ; for i : Integer.subrange(1, (b)->size()-1) do ( if b[i+1] = t[i+1] then ( table[i+1][i+1] := table[i - 1+1][i - 1+1] ) else skip ; for j : Integer.subrange(i + 1, (t)->size()-1) do ( if b[i+1] = t[j+1] then ( table[i+1][j+1] := table[i - 1+1][j - 1+1] + table[i+1][j - 1+1] ) else ( table[i+1][j+1] := table[i+1][j - 1+1] ))) ; execute (table[(b)->size() - 1+1][(t)->size() - 1+1] mod 1000000007)->display() ) else (if (t)->size() = (b)->size() then ( if t = b then ( execute (1)->display() ) else ( execute (0)->display() ) ) else ( execute (0)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines import numpy as np N,M,V,P=map(int,readline().split()) A=np.array(read().split(),np.int64) A.sort() def test(i): if N-i<=P : return True me=A[i]+M C=np.zeros(N,np.int64) C=me-A C=np.minimum(C,M) C[N-P+1 :]=M if(C<0).any(): return False C[i]=0 x=C.sum() return C.sum()>=M*(V-1) left=-1 right=N-1 while left+1collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := (read().split(), ) ; A := A->sort() ; skip ; var left : int := -1 ; var right : double := N - 1 ; while (left + 1->compareTo(right)) < 0 do ( x := (left + right) div 2 ; if test(x) then ( right := x ) else ( left := x )) ; var answer : double := N - right ; execute (answer)->display(); operation test(i : OclAny) : OclAny pre: true post: true activity: if (N - i->compareTo(P)) <= 0 then ( return true ) else skip ; var me : OclAny := A[i+1] + M ; var C : Sequence := MatrixLib.singleValueMatrix(N, 0.0) ; C := me - A ; C := ; C.subrange(N - P + 1+1) := M ; if (MatrixLib.elementwiseLess(C,0)).any() then ( return false ) else skip ; C[i+1] := 0 ; var x : OclAny := C.sum() ; return (C.sum()->compareTo(M * (V - 1))) >= 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkpossible(mask,arr,prefix,n,k): dp=[[0 for i in range(k+1)]for i in range(n+1)] dp[0][0]=1 for i in range(1,n+1): for j in range(1,k+1): for l in range(i-1,-1,-1): if(dp[l][j-1]and(((prefix[i]-prefix[l])& mask)==mask)): dp[i][j]=1 break return dp[n][k] def Partition(arr,n,k): prefix=[0 for i in range(n+1)] for i in range(1,n+1): prefix[i]=prefix[i-1]+arr[i] LOGS=20 ans=0 for i in range(LOGS,-1,-1): if(checkpossible(ans |(1<union(Sequence{1}->union(Sequence{2}->union(Sequence{7}->union(Sequence{10}->union(Sequence{23}->union(Sequence{21}->union(Sequence{6}->union(Sequence{8}->union(Sequence{7}->union(Sequence{ 3 })))))))))) ; k := 2 ; n := (arr)->size() - 1 ; execute (Partition(arr, n, k))->display(); operation checkpossible(mask : OclAny, arr : OclAny, prefix : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Integer.subrange(0, k + 1-1)->select(i | true)->collect(i | (0)))) ; dp->first()->first() := 1 ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, k + 1-1) do ( for l : Integer.subrange(-1 + 1, i - 1)->reverse() do ( if (dp[l+1][j - 1+1] & ((MathLib.bitwiseAnd((prefix[i+1] - prefix[l+1]), mask)) = mask)) then ( dp[i+1][j+1] := 1 ; break ) else skip))) ; return dp[n+1][k+1]; operation Partition(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: prefix := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(1, n + 1-1) do ( prefix[i+1] := prefix[i - 1+1] + arr[i+1]) ; var LOGS : int := 20 ; var ans : int := 0 ; for i : Integer.subrange(-1 + 1, LOGS)->reverse() do ( if (checkpossible(MathLib.bitwiseOr(ans, (1 * (2->pow(i)))), arr, prefix, n, k)) then ( ans := MathLib.bitwiseOr(ans, (1 * (2->pow(i)))) ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Log2n(n): return 1+Log2n(n/2)if(n>1)else 0 n=32 print(Log2n(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 32 ; execute (Log2n(n))->display(); operation Log2n(n : OclAny) : OclAny pre: true post: true activity: return if (n > 1) then 1 + Log2n(n / 2) else 0 endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) d,d1={},{} for i in range(n): a,b=map(int,input().split()) d[a],d1[b]=b,a r=[list(filter(lambda f : d1.get(f)==None,d.keys()))[0],d.get(0)] for i in range(2,n): r.append(d.get(r[i-2])) print(*r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : OclAny := null; var d1 : OclAny := null; Sequence{d,d1} := Sequence{Set{},Set{}} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d[a+1] : OclAny := null; var d1[b+1] : OclAny := null; Sequence{d[a+1],d1[b+1]} := Sequence{b,a}) ; var r : Sequence := Sequence{OclType["Sequence"]((d.keys())->select( _x | (lambda f : OclAny in (d1.get(f) = null))->apply(_x) = true ))->first()}->union(Sequence{ d.get(0) }) ; for i : Integer.subrange(2, n-1) do ( execute ((d.get(r[i - 2+1])) : r)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name r))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[0 for i in range(1000001)] b=[0 for i in range(1000001)] times=[0 for i in range(1000001)] number=[0 for i in range(n)] for i in range(n): ai,bi=input().split() ai=int(ai) bi=int(bi) a[ai]=bi times[ai]+=1 times[bi]+=1 number[i]=ai if ai==0 : second=bi for i in range(n): if times[number[i]]==1 : first=number[i] break a1=first a2=second print('%d %d' %(a1,a2),end='') if n % 2==0 : for i in range(n//2-1): a1=a[a1] a2=a[a2] print(' %d %d' %(a1,a2),end='') else : for i in range(n//2-1): a1=a[a1] a2=a[a2] print(' %d %d' %(a1,a2),end='') print(' %d' %(a[a1])) print('') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(0, 1000001-1)->select(i | true)->collect(i | (0)) ; var b : Sequence := Integer.subrange(0, 1000001-1)->select(i | true)->collect(i | (0)) ; var times : Sequence := Integer.subrange(0, 1000001-1)->select(i | true)->collect(i | (0)) ; var number : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( var ai : OclAny := null; var bi : OclAny := null; Sequence{ai,bi} := input().split() ; var ai : int := ("" + ((ai)))->toInteger() ; var bi : int := ("" + ((bi)))->toInteger() ; a[ai+1] := bi ; times[ai+1] := times[ai+1] + 1 ; times[bi+1] := times[bi+1] + 1 ; number[i+1] := ai ; if ai = 0 then ( var second : int := bi ) else skip) ; for i : Integer.subrange(0, n-1) do ( if times[number[i+1]+1] = 1 then ( var first : OclAny := number[i+1] ; break ) else skip) ; var a1 : OclAny := first ; var a2 : int := second ; execute (StringLib.format('%d %d',Sequence{a1, a2}))->display() ; if n mod 2 = 0 then ( for i : Integer.subrange(0, n div 2 - 1-1) do ( a1 := a[a1+1] ; a2 := a[a2+1] ; execute (StringLib.format(' %d %d',Sequence{a1, a2}))->display()) ) else ( for i : Integer.subrange(0, n div 2 - 1-1) do ( a1 := a[a1+1] ; a2 := a[a2+1] ; execute (StringLib.format(' %d %d',Sequence{a1, a2}))->display()) ; execute (StringLib.format(' %d',(a[a1+1])))->display() ) ; execute ('')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) d1,d2={},{} for i in range(n): a,b=map(int,input().split()) d2[a],d1[b]=b,a r=[list(filter(lambda f : d1.get(f)==None,d2.keys()))[0],d2.get(0)] for i in range(2,n): r.append(d2.get(r[i-2])) print(*r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d1 : OclAny := null; var d2 : OclAny := null; Sequence{d1,d2} := Sequence{Set{},Set{}} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d2[a+1] : OclAny := null; var d1[b+1] : OclAny := null; Sequence{d2[a+1],d1[b+1]} := Sequence{b,a}) ; var r : Sequence := Sequence{OclType["Sequence"]((d2.keys())->select( _x | (lambda f : OclAny in (d1.get(f) = null))->apply(_x) = true ))->first()}->union(Sequence{ d2.get(0) }) ; for i : Integer.subrange(2, n-1) do ( execute ((d2.get(r[i - 2+1])) : r)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name r))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) front={}; back={} for i in range(n): inp=tuple(map(int,input().split())) front[inp[0]]=inp[1] back[inp[1]]=inp[0] fi=list((set(front)-set(back)))[0] e=[]; i=0 while(i in front)and front[i]!=0 : e.append(front[i]); i=front[i] i=fi ; o=[fi] while(i in front)and front[i]!=0 : o.append(front[i]); i=front[i] a=[0 for i in range(n+1)] for i in range(1,n+1): if i % 2!=0 : a[i]=o[i//2] else : a[i]=e[i//2-1] print(*a[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var front : OclAny := Set{}; var back : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var inp : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; front[inp->first()+1] := inp[1+1] ; back[inp[1+1]+1] := inp->first()) ; var fi : OclAny := OclType["Sequence"]((Set{}->union((front)) - Set{}->union((back))))->first() ; var e : Sequence := Sequence{}; var i : int := 0 ; while ((front)->includes(i)) & front[i+1] /= 0 do ( execute ((front[i+1]) : e); i := front[i+1]) ; i := fi; var o : Sequence := Sequence{ fi } ; while ((front)->includes(i)) & front[i+1] /= 0 do ( execute ((front[i+1]) : o); i := front[i+1]) ; var a : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(1, n + 1-1) do ( if i mod 2 /= 0 then ( a[i+1] := o[i div 2+1] ) else ( a[i+1] := e[i div 2 - 1+1] )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m={} a=[] for i in range(n): f,b=[int(k)for k in input().split()] m[f]=b a.append(b) ans=list(set(m.keys())-set(a)) ans.append(m.get(0)) for i in range(n-2): ans.append(m.get(ans[i])) print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : OclAny := Set{} ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var f : OclAny := null; var b : OclAny := null; Sequence{f,b} := input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger())) ; m[f+1] := b ; execute ((b) : a)) ; var ans : Sequence := (Set{}->union((m.keys())) - Set{}->union((a))) ; execute ((m.get(0)) : ans) ; for i : Integer.subrange(0, n - 2-1) do ( execute ((m.get(ans[i+1])) : ans)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMinimumK(a,n,s): maximum=a[0] for i in range(n): maximum=max(maximum,a[i]) low=1 high=maximum+1 ans=high while(low<=high): mid=(low+high)//2 sum=0 for i in range(n): sum+=(a[i]//mid) if(sum>s): low=mid+1 else : ans=min(ans,mid) high=mid-1 return ans a=[10,7,8,10,12,19] n=len(a) s=27 print(findMinimumK(a,n,s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{10}->union(Sequence{7}->union(Sequence{8}->union(Sequence{10}->union(Sequence{12}->union(Sequence{ 19 }))))) ; n := (a)->size() ; s := 27 ; execute (findMinimumK(a, n, s))->display(); operation findMinimumK(a : OclAny, n : OclAny, s : OclAny) : OclAny pre: true post: true activity: var maximum : OclAny := a->first() ; for i : Integer.subrange(0, n-1) do ( maximum := Set{maximum, a[i+1]}->max()) ; var low : int := 1 ; var high : OclAny := maximum + 1 ; var ans : OclAny := high ; while ((low->compareTo(high)) <= 0) do ( var mid : int := (low + high) div 2 ; var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + (a[i+1] div mid)) ; if ((sum->compareTo(s)) > 0) then ( low := mid + 1 ) else ( ans := Set{ans, mid}->min() ; high := mid - 1 )) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) st=len(input().rstrip(')')) print('YES' if n-st>st else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var st : int := (input().rstrip(')'))->size() ; execute (if (n - st->compareTo(st)) > 0 then 'YES' else 'NO' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def longOddEvenIncSeq(arr,n): lioes=list() maxLen=0 for i in range(n): lioes.append(1) i=1 for i in range(n): for j in range(i): if(arr[i]>arr[j]and(arr[i]+arr[j])% 2!=0 and lioes[i]union(Sequence{12}->union(Sequence{2}->union(Sequence{22}->union(Sequence{5}->union(Sequence{30}->union(Sequence{31}->union(Sequence{14}->union(Sequence{17}->union(Sequence{ 11 }))))))))) ; n := (arr)->size() ; execute ("Longest Increasing Odd Even " + "Subsequence: ")->display(); operation longOddEvenIncSeq(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var lioes : Sequence := () ; var maxLen : int := 0 ; for i : Integer.subrange(0, n-1) do ( execute ((1) : lioes)) ; var i : int := 1 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, i-1) do ( if ((arr[i+1]->compareTo(arr[j+1])) > 0 & (arr[i+1] + arr[j+1]) mod 2 /= 0 & (lioes[i+1]->compareTo(lioes[j+1] + 1)) < 0) then ( lioes[i+1] := lioes[j+1] + 1 ) else skip)) ; for i : Integer.subrange(0, n-1) do ( if (maxLen->compareTo(lioes[i+1])) < 0 then ( maxLen := lioes[i+1] ) else skip) ; return maxLen; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def mostFrequent(arr,n): Hash=dict() for i in range(n): if arr[i]in Hash.keys(): Hash[arr[i]]+=1 else : Hash[arr[i]]=1 max_count=0 res=-1 for i in Hash : if(max_countunion(Sequence{5}->union(Sequence{2}->union(Sequence{1}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 1 })))))) ; n := (arr)->size() ; execute (mostFrequent(arr, n))->display(); operation mostFrequent(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var Hash : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( if (Hash.keys())->includes(arr[i+1]) then ( Hash[arr[i+1]+1] := Hash[arr[i+1]+1] + 1 ) else ( Hash[arr[i+1]+1] := 1 )) ; var max_count : int := 0 ; var res : int := -1 ; for i : Hash->keys() do ( if ((max_count->compareTo(Hash[i+1])) < 0) then ( res := i ; max_count := Hash[i+1] ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(N : int,M : int,V : int,P : int,A : 'list[int]')->int : from itertools import accumulate def is_ok(j): if j

display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : int := 0 ; var primes : OclAny := eulerlib.list_primes(2000000) ; for i : itertools->count(2) do ( var p : OclAny := primes[i+1] ; var q : OclAny := primes[i + 1+1] ; if p > 1000000 then ( break ) else skip ; var k : int := 1 ; while (k->compareTo(p)) < 0 do ( k := k * 10) ; var m : int := (q - p) * eulerlib.reciprocal_mod(k mod q, q) mod q ; ans := ans + m * k + p) ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) B=list(map(int,input().split(" "))) ans=B[0] for i in range(1,N-1): ans+=min(B[i-1],B[i]) ans+=B[-1] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : OclAny := B->first() ; for i : Integer.subrange(1, N - 1-1) do ( ans := ans + Set{B[i - 1+1], B[i+1]}->min()) ; ans := ans + B->last() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(sys.stdin.readline()) B=list(map(int,input().split())) A=[1000001 for i in range(n)] for i in range(n-1): if A[i]>B[i]: A[i]=B[i] if A[i+1]>B[i]: A[i+1]=B[i] print(sum(A)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var A : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (1000001)) ; for i : Integer.subrange(0, n - 1-1) do ( if (A[i+1]->compareTo(B[i+1])) > 0 then ( A[i+1] := B[i+1] ) else skip ; if (A[i + 1+1]->compareTo(B[i+1])) > 0 then ( A[i + 1+1] := B[i+1] ) else skip) ; execute ((A)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) numbers=[int(i)for i in input().split()] res=0 for i in range(n): res+=min(numbers[max(i-1,0)],numbers[min(i,n-2)]) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var numbers : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( res := res + Set{numbers[Set{i - 1, 0}->max()+1], numbers[Set{i, n - 2}->min()+1]}->min()) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=[] B=[int(i)for i in input().split()] ans=0 for i in range(N): if(i==0): A.append(B[0]) continue if(i==N-1): A.append(B[N-2]) continue a=B[i-1] b=B[i] if(atoInteger() ; var A : Sequence := Sequence{} ; var B : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( if (i = 0) then ( execute ((B->first()) : A) ; continue ) else skip ; if (i = N - 1) then ( execute ((B[N - 2+1]) : A) ; continue ) else skip ; var a : OclAny := B[i - 1+1] ; var b : OclAny := B[i+1] ; if ((a->compareTo(b)) < 0) then ( execute ((a) : A) ) else ( execute ((b) : A) )) ; for i : A do ( ans := ans + i) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) B=[int(i)for i in input().split()] A=[0 for i in range(N)] for i in range(len(B)): if i==0 : A[i]=B[i] else : if A[i]>=B[i]: A[i]=B[i] A[i+1]=B[i] print(sum(A)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var A : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, (B)->size()-1) do ( if i = 0 then ( A[i+1] := B[i+1] ) else ( if (A[i+1]->compareTo(B[i+1])) >= 0 then ( A[i+1] := B[i+1] ) else skip ) ; A[i + 1+1] := B[i+1]) ; execute ((A)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getProduct(n): product=1 while(n!=0): product=product*(n % 10) n=n//10 return product n=4513 print(getProduct(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4513 ; execute (getProduct(n))->display(); operation getProduct(n : OclAny) : OclAny pre: true post: true activity: var product : int := 1 ; while (n /= 0) do ( product := product * (n mod 10) ; n := n div 10) ; return product; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,c=list(map(str,input().split())) n=int(n) m=int(m) P={} room=[] for i in range(n): line=input() tmp=[] P[i]=[] for j in range(m): if line[j]==c : P[i].append(j) tmp.append(line[j]) room.append(tmp) color=set() for i in range(n): if len(P[i])!=0 : if P[i][0]>0 : if room[i][P[i][0]-1]!="." : color.add(room[i][P[i][0]-1]) if P[i][len(P[i])-1]0 : for k in range(j,last): if room[i-1][k]!="." and room[i-1][k]!=c : color.add(room[i-1][k]) if icollect( _x | (OclType["String"])->apply(_x) )) ; var n : int := ("" + ((n)))->toInteger() ; var m : int := ("" + ((m)))->toInteger() ; var P : OclAny := Set{} ; var room : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var line : String := (OclFile["System.in"]).readLine() ; var tmp : Sequence := Sequence{} ; P[i+1] := Sequence{} ; for j : Integer.subrange(0, m-1) do ( if line[j+1] = c then ( (expr (atom (name P)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) ) else skip ; execute ((line[j+1]) : tmp)) ; execute ((tmp) : room)) ; var color : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( if (P[i+1])->size() /= 0 then ( if P[i+1]->first() > 0 then ( if room[i+1][P[i+1]->first() - 1+1] /= "." then ( execute ((room[i+1][P[i+1]->first() - 1+1]) : color) ) else skip ) else skip ; if (P[i+1][(P[i+1])->size() - 1+1]->compareTo(m - 1)) < 0 then ( if room[i+1][P[i+1][(P[i+1])->size() - 1+1] + 1+1] /= "." then ( execute ((room[i+1][P[i+1][(P[i+1])->size() - 1+1] + 1+1]) : color) ) else skip ) else skip ; var j : OclAny := P[i+1]->first() ; var last : OclAny := j + (P[i+1])->size() ; if i > 0 then ( for k : Integer.subrange(j, last-1) do ( if room[i - 1+1][k+1] /= "." & room[i - 1+1][k+1] /= c then ( execute ((room[i - 1+1][k+1]) : color) ) else skip) ) else skip ; if (i->compareTo(n - 1)) < 0 then ( for k : Integer.subrange(j, last-1) do ( if room[i + 1+1][k+1] /= "." & room[i + 1+1][k+1] /= c then ( execute ((room[i + 1+1][k+1]) : color) ) else skip) ) else skip ) else skip) ; var count : int := (color)->size() ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input().split() s=[] for i in range(int(a[0])): s+=[input()] k=set() l=set() for i in range(int(a[0])): for j in range(int(a[1])): if s[i][j]==a[-1]: k.update(((i-1,j),(i+1,j),(i,j+1),(i,j-1))) for i in range(int(a[0])): for j in range(int(a[1])): if s[i][j]!='.' and s[i][j]!=a[-1]and(i,j)in k : l.add(s[i][j]) print(len(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := input().split() ; var s : Sequence := Sequence{} ; for i : Integer.subrange(0, ("" + ((a->first())))->toInteger()-1) do ( s := s + Sequence{ (OclFile["System.in"]).readLine() }) ; var k : Set := Set{}->union(()) ; var l : Set := Set{}->union(()) ; for i : Integer.subrange(0, ("" + ((a->first())))->toInteger()-1) do ( for j : Integer.subrange(0, ("" + ((a[1+1])))->toInteger()-1) do ( if s[i+1][j+1] = a->last() then ( execute ((Sequence{Sequence{i - 1, j}, Sequence{i + 1, j}, Sequence{i, j + 1}, Sequence{i, j - 1}}) <: k) ) else skip)) ; for i : Integer.subrange(0, ("" + ((a->first())))->toInteger()-1) do ( for j : Integer.subrange(0, ("" + ((a[1+1])))->toInteger()-1) do ( if s[i+1][j+1] /= '.' & s[i+1][j+1] /= a->last() & (k)->includes(Sequence{i, j}) then ( execute ((s[i+1][j+1]) : l) ) else skip)) ; execute ((l)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,c=input().split() n,m=int(n),int(m) a=[] for i in range(n): a.append(input()) d=set() for i in range(n): for j in range(m): if a[i][j]!=c : continue if i-1>=0 and a[i-1][j]!='.' and a[i-1][j]!=c : d.add(a[i-1][j]) if j-1>=0 and a[i][j-1]!='.' and a[i][j-1]!=c : d.add(a[i][j-1]) if i+1toInteger(),("" + ((m)))->toInteger()} ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : a)) ; var d : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if a[i+1][j+1] /= c then ( continue ) else skip ; if i - 1 >= 0 & a[i - 1+1][j+1] /= '.' & a[i - 1+1][j+1] /= c then ( execute ((a[i - 1+1][j+1]) : d) ) else skip ; if j - 1 >= 0 & a[i+1][j - 1+1] /= '.' & a[i+1][j - 1+1] /= c then ( execute ((a[i+1][j - 1+1]) : d) ) else skip ; if (i + 1->compareTo(n)) < 0 & a[i + 1+1][j+1] /= '.' & a[i + 1+1][j+1] /= c then ( execute ((a[i + 1+1][j+1]) : d) ) else skip ; if (j + 1->compareTo(m)) < 0 & a[i+1][j + 1+1] /= '.' & a[i+1][j + 1+1] /= c then ( execute ((a[i+1][j + 1+1]) : d) ) else skip)) ; execute ((d)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,color=map(str,input().split()) n,m=int(n),int(m) l,lst,st=[],[],[] for i in range(n): l=list(input()) lst+=l for el in range(m): if l[el]==color : if(el-1)>=0 and l[el-1]!='.' and l[el-1]!=color : st.append(l[el-1]) if len(l)>(el+1)and l[el+1]!='.' and l[el+1]!=color : st.append(l[el+1]) for k in range(len(lst)): if lst[k]==color : if(k-m)>=0 and lst[k-m]!='.' and lst[k-m]!=color : st.append(lst[k-m]) if len(lst)>(k+m)and lst[k+m]!='.' and lst[k+m]!=color : st.append(lst[k+m]) print(len(set(st))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var color : OclAny := null; Sequence{n,m,color} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{("" + ((n)))->toInteger(),("" + ((m)))->toInteger()} ; var l : OclAny := null; var lst : OclAny := null; var st : OclAny := null; Sequence{l,lst,st} := Sequence{Sequence{},Sequence{},Sequence{}} ; for i : Integer.subrange(0, n-1) do ( var l : Sequence := ((OclFile["System.in"]).readLine())->characters() ; lst := lst + l ; for el : Integer.subrange(0, m-1) do ( if l[el+1] = color then ( if (el - 1) >= 0 & l[el - 1+1] /= '.' & l[el - 1+1] /= color then ( execute ((l[el - 1+1]) : st) ) else skip ; if ((l)->size()->compareTo((el + 1))) > 0 & l[el + 1+1] /= '.' & l[el + 1+1] /= color then ( execute ((l[el + 1+1]) : st) ) else skip ) else skip)) ; for k : Integer.subrange(0, (lst)->size()-1) do ( if lst[k+1] = color then ( if (k - m) >= 0 & lst[k - m+1] /= '.' & lst[k - m+1] /= color then ( execute ((lst[k - m+1]) : st) ) else skip ; if ((lst)->size()->compareTo((k + m))) > 0 & lst[k + m+1] /= '.' & lst[k + m+1] /= color then ( execute ((lst[k + m+1]) : st) ) else skip ) else skip) ; execute ((Set{}->union((st)))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() print(S[: 3]) T=[] T.append(S[: 3]) S=S[3 :] a=0 while True : if S[1]!='/' : Nb=T[-1].count(' ') if '/' in T[-1]: Ch=' '*(Nb)+S[: 3] else : Ch=' '*(Nb+1)+S[: 3] print(Ch) T.append(Ch) S=S[3 :] a=0 else : Nb=T[-1].count(' ') if '/' in T[-1]: Ch=' '*(Nb-1)+S[: 4] else : Ch=' '*(Nb)+S[: 4] print(Ch) T.append(Ch) S=S[4 :] a+=1 if S=='' : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; execute (S.subrange(1,3))->display() ; var T : Sequence := Sequence{} ; execute ((S.subrange(1,3)) : T) ; S := S.subrange(3+1) ; var a : int := 0 ; while true do ( if S[1+1] /= '/' then ( var Nb : OclAny := T->last()->count(' ') ; if (T->last())->includes('/') then ( var Ch : String := StringLib.nCopies(' ', (Nb)) + S.subrange(1,3) ) else ( Ch := StringLib.nCopies(' ', (Nb + 1)) + S.subrange(1,3) ) ; execute (Ch)->display() ; execute ((Ch) : T) ; S := S.subrange(3+1) ; a := 0 ) else ( Nb := T->last()->count(' ') ; if (T->last())->includes('/') then ( Ch := StringLib.nCopies(' ', (Nb - 1)) + S.subrange(1,4) ) else ( Ch := StringLib.nCopies(' ', (Nb)) + S.subrange(1,4) ) ; execute (Ch)->display() ; execute ((Ch) : T) ; S := S.subrange(4+1) ; a := a + 1 ) ; if S = '' then ( break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys ; R=sys.stdin.readline n,m,p=R().split() n,m=int(n),int(m) room=[R().rstrip()for _ in range(n)] dep=set() for i in range(n): for j in range(m): if room[i][j]==p : for a,b in(i+1,j),(i-1,j),(i,j+1),(i,j-1): if 0<=atoInteger(),("" + ((m)))->toInteger()} ; var room : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (R().rstrip())) ; var dep : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if room[i+1][j+1] = p then ( for _tuple : Sequence{i + 1, j}, Sequence{i - 1, j}, Sequence{i, j + 1}, Sequence{i, j - 1} do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if 0 <= a & (a < n) & 0 <= b & (b < m) then ( execute ((room[a+1][b+1]) : dep) ) else skip) ) else skip)) ; dep := dep - Set{}->union(('.' + p)) ; execute ((dep)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n=int(input()) arr=list(map(int,input().split())) count=dict(Counter(arr)) two=0 four=0 for i in count.values(): two+=i//2 four+=i//4 t=int(input()) while t : t-=1 operation,stick=input().split() stick=int(stick) if operation=="+" : if stick in count : count[stick]+=1 else : count[stick]=1 if count[stick]% 2==0 : two+=1 if count[stick]% 4==0 : four+=1 else : if count[stick]% 2==0 : two-=1 if count[stick]% 4==0 : four-=1 count[stick]-=1 if two>=4 and four>=1 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : Map := ((expr (atom (name Counter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr)))))))) ))))) ; var two : int := 0 ; var four : int := 0 ; for i : count.values() do ( two := two + i div 2 ; four := four + i div 4) ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( t := t - 1 ; var operation : OclAny := null; var stick : OclAny := null; Sequence{operation,stick} := input().split() ; var stick : int := ("" + ((stick)))->toInteger() ; if operation = "+" then ( if (count)->includes(stick) then ( count[stick+1] := count[stick+1] + 1 ) else ( count[stick+1] := 1 ) ; if count[stick+1] mod 2 = 0 then ( two := two + 1 ) else skip ; if count[stick+1] mod 4 = 0 then ( four := four + 1 ) else skip ) else ( if count[stick+1] mod 2 = 0 then ( two := two - 1 ) else skip ; if count[stick+1] mod 4 = 0 then ( four := four - 1 ) else skip ; count[stick+1] := count[stick+1] - 1 ) ; if two >= 4 & four >= 1 then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lst=list(map(int,input().split())) dct={} for item in lst : try : dct[item]+=1 except : dct[item]=1 num_square=0 num_rect_side=0 for value in dct.values(): num_square+=value//4 num_rect_side+=value % 4//2 q=int(input()) for _ in range(q): o=int(''.join(input().split())) if o>0 : try : dct[o]+=1 if dct[o]% 4==0 : num_square+=1 num_rect_side-=1 elif dct[o]% 4==2 : num_rect_side+=1 except : dct[o]=1 else : o=-o if dct[o]% 4==0 : num_square=max(0,num_square-1) num_rect_side+=1 elif dct[o]% 4==2 : num_rect_side=max(0,num_rect_side-1) dct[o]-=1 if num_square>=2 : print('yes') else : if num_square==0 : print('no') else : if num_rect_side>=2 : print('yes') else : print('no') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dct : OclAny := Set{} ; for item : lst do ( try ( dct[item+1] := dct[item+1] + 1) catch (_e : OclException) do ( dct[item+1] := 1) ) ; var num_square : int := 0 ; var num_rect_side : int := 0 ; for value : dct.values() do ( num_square := num_square + value div 4 ; num_rect_side := num_rect_side + value mod 4 div 2) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( var o : int := ("" + ((StringLib.sumStringsWithSeparator((input().split()), ''))))->toInteger() ; if o > 0 then ( try ( dct[o+1] := dct[o+1] + 1 ; if dct[o+1] mod 4 = 0 then ( num_square := num_square + 1 ; num_rect_side := num_rect_side - 1 ) else (if dct[o+1] mod 4 = 2 then ( num_rect_side := num_rect_side + 1 ) else skip)) catch (_e : OclException) do ( dct[o+1] := 1) ) else ( o := -o ; if dct[o+1] mod 4 = 0 then ( num_square := Set{0, num_square - 1}->max() ; num_rect_side := num_rect_side + 1 ) else (if dct[o+1] mod 4 = 2 then ( num_rect_side := Set{0, num_rect_side - 1}->max() ) else skip) ; dct[o+1] := dct[o+1] - 1 ) ; if num_square >= 2 then ( execute ('yes')->display() ) else ( if num_square = 0 then ( execute ('no')->display() ) else ( if num_rect_side >= 2 then ( execute ('yes')->display() ) else ( execute ('no')->display() ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) cnt=[0]*(10**6+1) for i in a : cnt[i]+=1 unique=[] for i in range(10**6+1): if cnt[i]==1 : unique.append(i) cnt=[0]*(10**6+1) a=list(set(a)) for i in a : for j in range(i*2,10**6+1,i): cnt[j]=1 ans=0 for i in unique : if cnt[i]==0 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((10)->pow(6) + 1)) ; for i : a do ( cnt[i+1] := cnt[i+1] + 1) ; var unique : Sequence := Sequence{} ; for i : Integer.subrange(0, (10)->pow(6) + 1-1) do ( if cnt[i+1] = 1 then ( execute ((i) : unique) ) else skip) ; cnt := MatrixLib.elementwiseMult(Sequence{ 0 }, ((10)->pow(6) + 1)) ; a := (Set{}->union((a))) ; for i : a do ( for j : Integer.subrange(i * 2, (10)->pow(6) + 1-1)->select( $x | ($x - i * 2) mod i = 0 ) do ( cnt[j+1] := 1)) ; var ans : int := 0 ; for i : unique do ( if cnt[i+1] = 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines from collections import defaultdict from collections import Counter def main(): N=int(readline()) A=[int(i)for i in readline().split()] dc=Counter(A) dd=defaultdict(int) A.sort() mx=A[-1] for i in A : j=i while j<=mx : dd[j]+=1 j+=i cnt=0 for e in A : cnt+=(dd[e]==1) print(cnt) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : int := ("" + ((readline())))->toInteger() ; var A : Sequence := readline().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var dc : OclAny := Counter(A) ; var dd : OclAny := defaultdict(OclType["int"]) ; A := A->sort() ; var mx : OclAny := A->last() ; for i : A do ( var j : OclAny := i ; while (j->compareTo(mx)) <= 0 do ( dd[j+1] := dd[j+1] + 1 ; j := j + i)) ; var cnt : int := 0 ; for e : A do ( cnt := cnt + (dd[e+1] = 1)) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : b,r,g,c,s,t=list(map(int,input().split())) if t==0 : break cnt=b*5+r*3+s coins=(b*5+r*3)*(15-2) coins+=b*15 coins+=r*15 coins+=7*g coins+=2*c coins+=100-(t-cnt)*3 print(coins) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var b : OclAny := null; var r : OclAny := null; var g : OclAny := null; var c : OclAny := null; var s : OclAny := null; var t : OclAny := null; Sequence{b,r,g,c,s,t} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if t = 0 then ( break ) else skip ; var cnt : double := b * 5 + r * 3 + s ; var coins : double := (b * 5 + r * 3) * (15 - 2) ; coins := coins + b * 15 ; coins := coins + r * 15 ; coins := coins + 7 * g ; coins := coins + 2 * c ; coins := coins + 100 - (t - cnt) * 3 ; execute (coins)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) A=[int(i)for i in input().split()] max_dp=max(A)+1 dp=[0]*max_dp for a in A : if dp[a]>=2 : continue dp[a]+=1 for i in range(a<<1,max_dp,a): dp[i]+=2 print(dp.count(1)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var max_dp : OclAny := (A)->max() + 1 ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, max_dp) ; for a : A do ( if dp[a+1] >= 2 then ( continue ) else skip ; dp[a+1] := dp[a+1] + 1 ; for i : Integer.subrange(a * (2->pow(1)), max_dp-1)->select( $x | ($x - a * (2->pow(1))) mod a = 0 ) do ( dp[i+1] := dp[i+1] + 2)) ; execute (dp->count(1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=list(map(int,input().split())) A.sort() m=max(A) sieve=[True]*(m+1) sieve[0]=False ct=0 for i in range(N): n=A[i] if sieve[n]==False : continue if itoInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; A := A->sort() ; var m : OclAny := (A)->max() ; var sieve : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (m + 1)) ; sieve->first() := false ; var ct : int := 0 ; for i : Integer.subrange(0, N-1) do ( var n : OclAny := A[i+1] ; if sieve[n+1] = false then ( continue ) else skip ; if (i->compareTo(N - 1)) < 0 & n = A[i + 1+1] then ( sieve[n+1] := false ) else skip ; if sieve[n+1] = true then ( ct := ct + 1 ) else skip ; for k : Integer.subrange(n * 2, m + 1-1)->select( $x | ($x - n * 2) mod n = 0 ) do ( sieve[k+1] := false)) ; execute (ct)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter N=int(input()) anslist=set([]) A=list(map(int,input().split())) Amax=max(A) for i in A : j=i*2 while j<=Amax : anslist.add(j) j+=i anslist=list(anslist) anslist.extend(A) anslist=Counter(anslist) A=Counter(A) cnt=0 for k,v in A.items(): if v!=1 : del anslist[k] else : cnt+=1 ans=Counter(anslist.values()) print(cnt-ans[2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var anslist : Set := Set{}->union((Sequence{})) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var Amax : OclAny := (A)->max() ; for i : A do ( var j : double := i * 2 ; while (j->compareTo(Amax)) <= 0 do ( execute ((j) : anslist) ; j := j + i)) ; anslist := (anslist) ; anslist := anslist->union(A) ; anslist := Counter(anslist) ; A := Counter(A) ; var cnt : int := 0 ; for _tuple : A->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if v /= 1 then ( execute (anslist[k+1])->isDeleted() ) else ( cnt := cnt + 1 )) ; var ans : OclAny := Counter(anslist.values()) ; execute (cnt - ans[2+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def last_digit(X,Y): print(X % Y); if __name__=="__main__" : X=55 ; Y=3 ; last_digit(X,Y); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( X := 55; Y := 3; ; last_digit(X, Y); ) else skip; operation last_digit(X : OclAny, Y : OclAny) pre: true post: true activity: execute (X mod Y)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) if a[-1]>a[0]: for k in range(1,n): if a[k]a[j+1]: res2=j break if res!=res2 : print(-1) exit() if res==-1 : print(0) exit() print(n-j-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (a->last()->compareTo(a->first())) > 0 then ( for k : Integer.subrange(1, n-1) do ( if (a[k+1]->compareTo(a[k - 1+1])) < 0 then ( execute (-1)->display() ; exit() ) else skip) ; execute (0)->display() ; exit() ) else skip ; var res : int := -1 ; for i : Integer.subrange(1, n-1) do ( if (a[i+1]->compareTo(a[i - 1+1])) < 0 then ( res := i - 1 ; break ) else skip) ; var res2 : int := -1 ; for j : Integer.subrange(-1 + 1, n - 2)->reverse() do ( if (a[j+1]->compareTo(a[j + 1+1])) > 0 then ( res2 := j ; break ) else skip) ; if res /= res2 then ( execute (-1)->display() ; exit() ) else skip ; if res = -1 then ( execute (0)->display() ; exit() ) else skip ; execute (n - j - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() h=-1 prev='\'' tmp='' chars={chr(i+97): 0 for i in range(26)} chars['\'']=1 slash=False prev_slash=False for c in s : if c=='<' : tmp+=c elif c=='>' : prev_slash=slash tmp+=c print(''*(2*h),end='') print(tmp) tmp='' slash=False elif c=='/' : tmp+=c slash=True else : tmp+=c if slash : chars[c]-=1 if prev!=c : h-=1 else : if prev_slash : h-=1 else : chars[c]+=1 if not prev_slash : h+=1 prev=c ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var h : int := -1 ; var prev : String := '\'' ; var tmp : String := '' ; var chars : Map := Integer.subrange(0, 26-1)->select(i | true)->collect(i | Map{(i + 97)->byte2char() |-> 0})->unionAll() ; chars->at('\'') := 1 ; var slash : boolean := false ; var prev_slash : boolean := false ; for c : s->characters() do ( if c = '<' then ( tmp := tmp + c ) else (if c = '>' then ( prev_slash := slash ; tmp := tmp + c ; execute (StringLib.nCopies('', (2 * h)))->display() ; execute (tmp)->display() ; tmp := '' ; slash := false ) else (if c = '/' then ( tmp := tmp + c ; slash := true ) else ( tmp := tmp + c ; if slash then ( chars[c+1] := chars[c+1] - 1 ; if prev /= c then ( h := h - 1 ) else ( if prev_slash then ( h := h - 1 ) else skip ) ) else ( chars[c+1] := chars[c+1] + 1 ; if not(prev_slash) then ( h := h + 1 ) else skip ) ; prev := c ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) ans=-1 i=0 while i<2*len(l): ans=(max(0,n-i))% n count=0 while count+1toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := -1 ; var i : int := 0 ; while (i->compareTo(2 * (l)->size())) < 0 do ( ans := (Set{0, n - i}->max()) mod n ; var count : int := 0 ; while (count + 1->compareTo(n)) < 0 & (l[i mod n+1]->compareTo(l[(i + 1) mod n+1])) <= 0 do ( count := count + 1 ; i := i + 1) ; if count /= n - 1 then ( ans := -1 ) else ( break ) ; i := i + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque,Counter from math import* import sys import random from bisect import* from functools import reduce from sys import stdin import copy n=int(input()) arr=list(map(int,input().split())) i=n-1 while i>0 and arr[i]>=arr[i-1]: i-=1 if i==0 : print(0) sys.exit() temp=arr[0 : i] arr.sort() if arr[n-i :]==temp : print(n-i) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var i : double := n - 1 ; while i > 0 & (arr[i+1]->compareTo(arr[i - 1+1])) >= 0 do ( i := i - 1) ; if i = 0 then ( execute (0)->display() ; sys.exit() ) else skip ; var temp : OclAny := arr.subrange(0+1, i) ; arr := arr->sort() ; if arr.subrange(n - i+1) = temp then ( execute (n - i)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) w=list(map(int,input().split())) c=0 for i in range(n-1): if w[i]>w[i+1]: w=w[i+1 :]+w[: i+1] c=n-i-1 break if w==sorted(w): print(c) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if (w[i+1]->compareTo(w[i + 1+1])) > 0 then ( w := w.subrange(i + 1+1) + w.subrange(1,i + 1) ; c := n - i - 1 ; break ) else skip) ; if w = w->sort() then ( execute (c)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): n=int(input()) arr=list(map(int,input().split())) mn=min(arr) mx=max(arr) if mn==mx : print(0) return ; first=-1 for i in range(len(arr)): if arr[i]==mn : first=i while 0<=first-1 and arr[first-1]==arr[first]: first-=1 shSorted=arr[first :]+arr[: first] if shSorted==sorted(arr): print((len(arr)-first)*(first>0)) else : print(-1) def main(): t=1 for _ in range(t): solution() import sys import threading sys.setrecursionlimit(1<<30) threading.stack_size(1<<27) thread=threading.Thread(target=main) thread.start(); thread.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1 * (2->pow(30))) ; threading.stack_size(1 * (2->pow(27))) ; var thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ; thread.start(); thread.join(); operation solution() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mn : OclAny := (arr)->min() ; var mx : OclAny := (arr)->max() ; if mn = mx then ( execute (0)->display() ; return; ) else skip ; var first : int := -1 ; for i : Integer.subrange(0, (arr)->size()-1) do ( if arr[i+1] = mn then ( first := i ) else skip) ; while 0 <= first - 1 & arr[first - 1+1] = arr[first+1] do ( first := first - 1) ; var shSorted : OclAny := arr.subrange(first+1) + arr.subrange(1,first) ; if shSorted = arr->sort() then ( execute (((arr)->size() - first) * (first > 0))->display() ) else ( execute (-1)->display() ); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,bisect PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") while True : b,r,g,c,s,t=[int(_)for _ in input().split()] if t==0 : break print(100+95*b+63*r+7*g+2*c-3*(t-s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; while true do ( var b : OclAny := null; var r : OclAny := null; var g : OclAny := null; var c : OclAny := null; var s : OclAny := null; var t : OclAny := null; Sequence{b,r,g,c,s,t} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; if t = 0 then ( break ) else skip ; execute (100 + 95 * b + 63 * r + 7 * g + 2 * c - 3 * (t - s))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) a.reverse() for i in range(n-1): print(a[i],end=" ") print(a[n-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->reverse() ; for i : Integer.subrange(0, n - 1-1) do ( execute (a[i+1])->display()) ; execute (a[n - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=int(input()) series=list(map(int,input().split())) series.reverse() print(' '.join(map(str,series))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var series : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; series := series->reverse() ; execute (StringLib.sumStringsWithSeparator(((series)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) a=input().split() str="" while(n>0): n=n-1 if(n>=1): str=str+a[n]+" " else : str=str+a[n] print(str) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := input().split() ; var OclType["String"] : String := "" ; while (n > 0) do ( n := n - 1 ; if (n >= 1) then ( OclType["String"] := OclType["String"] + a[n+1] + " " ) else ( OclType["String"] := OclType["String"] + a[n+1] )) ; execute (OclType["String"])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() print(*reversed(input().split())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; execute ((argument * (test (logical_test (comparison (expr (atom (name reversed)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.stdin.readline() data=sys.stdin.readline().strip().split(' ') data.reverse() print(' '.join(data)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; (expr (atom (name sys)) (trailer . (name stdin)) (trailer . (name readline) (arguments ( )))) ; var data : OclAny := sys.stdin.readLine()->trim().split(' ') ; data := data->reverse() ; execute (StringLib.sumStringsWithSeparator((data), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import log10,ceil,pow def findPermutation(n): len=ceil(log10(n)) for i in range(0,len,1): if n % 2!=0 : return n else : n=((n/10)+(n % 10)*pow(10,len-i-1)) continue return-1 if __name__=='__main__' : n=132 print(int(findPermutation(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( n := 132 ; execute (("" + ((findPermutation(n))))->toInteger())->display() ) else skip; operation findPermutation(n : OclAny) : OclAny pre: true post: true activity: var len : OclAny := ceil(log10(n)) ; for i : Integer.subrange(0, len-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if n mod 2 /= 0 then ( return n ) else ( n := ((n / 10) + (n mod 10) * (10)->pow(len - i - 1)) ; continue )) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() h=-1 prev='\'' tmp='' chars={chr(i+97): 0 for i in range(26)} chars['\'']=1 slash=False prev_slash=False for c in s : if c=='<' : tmp+=c elif c=='>' : prev_slash=slash tmp+=c print(''*(2*h),end='') print(tmp) tmp='' slash=False elif c=='/' : tmp+=c slash=True else : tmp+=c if slash : chars[c]-=1 if prev!=c : h-=1 else : if prev_slash : h-=1 else : chars[c]+=1 if not prev_slash : h+=1 prev=c ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var h : int := -1 ; var prev : String := '\'' ; var tmp : String := '' ; var chars : Map := Integer.subrange(0, 26-1)->select(i | true)->collect(i | Map{(i + 97)->byte2char() |-> 0})->unionAll() ; chars->at('\'') := 1 ; var slash : boolean := false ; var prev_slash : boolean := false ; for c : s->characters() do ( if c = '<' then ( tmp := tmp + c ) else (if c = '>' then ( prev_slash := slash ; tmp := tmp + c ; execute (StringLib.nCopies('', (2 * h)))->display() ; execute (tmp)->display() ; tmp := '' ; slash := false ) else (if c = '/' then ( tmp := tmp + c ; slash := true ) else ( tmp := tmp + c ; if slash then ( chars[c+1] := chars[c+1] - 1 ; if prev /= c then ( h := h - 1 ) else ( if prev_slash then ( h := h - 1 ) else skip ) ) else ( chars[c+1] := chars[c+1] + 1 ; if not(prev_slash) then ( h := h + 1 ) else skip ) ; prev := c ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) l=[] for _ in range(k): d=int(input()) a=list(map(int,input().split())) for i in range(d): l.append(a[i]) print(n-len(set(l))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := Sequence{} ; for _anon : Integer.subrange(0, k-1) do ( var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, d-1) do ( execute ((a[i+1]) : l))) ; execute (n - (Set{}->union((l)))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N,K=map(int,input().split()) A=[0 for a in range(N)] for i in range(K): d=int(input()) O=[int(a)for a in input().split()] for j in range(d): A[O[j]-1]+=1 cnt=0 for i in range(N): if A[i]==0 : cnt+=1 print(cnt) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := Integer.subrange(0, N-1)->select(a | true)->collect(a | (0)) ; for i : Integer.subrange(0, K-1) do ( var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var O : Sequence := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; for j : Integer.subrange(0, d-1) do ( A[O[j+1] - 1+1] := A[O[j+1] - 1+1] + 1)) ; var cnt : int := 0 ; for i : Integer.subrange(0, N-1) do ( if A[i+1] = 0 then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): pass if __name__=='__main__' : N,K=list(map(int,input().split())) snukes=[0]*N for i in range(K): d=input() A=list(map(int,input().split())) for a in A : snukes[a-1]+=1 cnt=0 for snuke in snukes : if snuke==0 : cnt+=1 print(cnt) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var snukes : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for i : Integer.subrange(0, K-1) do ( var d : String := (OclFile["System.in"]).readLine() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for a : A do ( snukes[a - 1+1] := snukes[a - 1+1] + 1)) ; var cnt : int := 0 ; for snuke : snukes do ( if snuke = 0 then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display() ; main() ) else skip; operation main() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys f=sys.stdin while True : seven,bar,grape,cherry,star,all_game=map(int,f.readline().split()) if seven==bar==grape==cherry==star==all_game==0 : break init_coin=100 free_game=star bonus_game=seven*5+bar*3 nomal_game=all_game-free_game-bonus_game last_coin=init_coin-bonus_game*2-nomal_game*3+(bonus_game+seven+bar)*15+grape*7+cherry*2 print(last_coin) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var f : OclFile := OclFile["System.in"] ; while true do ( var seven : OclAny := null; var bar : OclAny := null; var grape : OclAny := null; var cherry : OclAny := null; var star : OclAny := null; var all_game : OclAny := null; Sequence{seven,bar,grape,cherry,star,all_game} := (f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if seven = bar & (bar == grape) & (grape == cherry) & (cherry == star) & (star == all_game) & (all_game == 0) then ( break ) else skip ; var init_coin : int := 100 ; var free_game : OclAny := star ; var bonus_game : double := seven * 5 + bar * 3 ; var nomal_game : double := all_game - free_game - bonus_game ; var last_coin : double := init_coin - bonus_game * 2 - nomal_game * 3 + (bonus_game + seven + bar) * 15 + grape * 7 + cherry * 2 ; execute (last_coin)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) d=[] A=[] for i in range(k): d.append(int(input())) A.append(list(map(int,input().split()))) b=[False]*n for lst in A : for i in lst : b[i-1]=True print(n-sum(b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := Sequence{} ; var A : Sequence := Sequence{} ; for i : Integer.subrange(0, k-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : d) ; execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : A)) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ; for lst : A do ( for i : lst do ( b[i - 1+1] := true)) ; execute (n - (b)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,input().split()) li=[] for i in range(1,N+1): li.append(i) for i in range(K): s1=input() s2=list(map(int,input().split())) for j in s2 : if j in li : li.remove(j) print(len(li)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var li : Sequence := Sequence{} ; for i : Integer.subrange(1, N + 1-1) do ( execute ((i) : li)) ; for i : Integer.subrange(0, K-1) do ( var s1 : String := (OclFile["System.in"]).readLine() ; var s2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : s2 do ( if (li)->includes(j) then ( execute ((j) /: li) ) else skip)) ; execute ((li)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- [num_lanes,num_rows,santa_desk]=map(int,input().split()) if santa_desk % 2==0 : l_or_r="R" santa_desk//=2 else : l_or_r="L" santa_desk+=1 santa_desk//=2 if santa_desk % num_rows==0 : lane=santa_desk//num_rows else : lane=(santa_desk//num_rows)+1 row=santa_desk-((lane-1)*num_rows) print(lane,end=" ") print(row,end=" ") print(l_or_r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: Sequence{num_lanes}->union(Sequence{num_rows}->union(Sequence{ santa_desk })) := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if santa_desk mod 2 = 0 then ( var l_or_r : String := "R" ; santa_desk := santa_desk div 2 ) else ( l_or_r := "L" ; santa_desk := santa_desk + 1 ; santa_desk := santa_desk div 2 ) ; if santa_desk mod num_rows = 0 then ( var lane : int := santa_desk div num_rows ) else ( lane := (santa_desk div num_rows) + 1 ) ; var row : double := santa_desk - ((lane - 1) * num_rows) ; execute (lane)->display() ; execute (row)->display() ; execute (l_or_r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,m,k=map(int,input().split()) r=math.ceil(k/(2*m)) d=math.ceil(abs(k-(r-1)*2*m)/2) print(r,d,'L' if k % 2!=0 else 'R') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var r : double := (k / (2 * m))->ceil() ; var d : double := ((k - (r - 1) * 2 * m)->abs() / 2)->ceil() ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,m,k=map(int,input().split()) f=(k+2*m-1)//(2*m) tmp=(k+2*m-1)%(2*m)+1 s=(tmp+1)//2 t='L' if tmp % 2==1 else 'R' print(f,s,t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var f : int := (k + 2 * m - 1) div (2 * m) ; var tmp : int := (k + 2 * m - 1) mod (2 * m) + 1 ; var s : int := (tmp + 1) div 2 ; var t : String := if tmp mod 2 = 1 then 'L' else 'R' endif ; execute (f)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) d=m*2 ; k-=1 print(k//d+1,k % d//2+1,'LR'[k % d % 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : double := m * 2; k := k - 1 ; execute (k div d + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def solution(n,m,k): l=math.ceil(k/(2*m)) d=math.ceil((k-(2*m*(l-1)))/2) left_or_right='R' if k % 2==0 else 'L' return[l,d,left_or_right] n,m,k=[int(x)for x in input().strip().split(" ")] ans=solution(n,m,k) print(ans[0],ans[1],ans[2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{n,m,k} := input()->trim().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : OclAny := solution(n, m, k) ; execute (ans->first())->display(); operation solution(n : OclAny, m : OclAny, k : OclAny) : OclAny pre: true post: true activity: var l : double := (k / (2 * m))->ceil() ; var d : double := ((k - (2 * m * (l - 1))) / 2)->ceil() ; var left_or_right : String := if k mod 2 = 0 then 'R' else 'L' endif ; return Sequence{l}->union(Sequence{d}->union(Sequence{ left_or_right })); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSubStr(st,n): m=0 for i in range(0,n): if(st[i]=='1'): m=m+1 return m*(m-1)//2 st="00100101" ; list(st) n=len(st) print(countSubStr(st,n),end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; st := "00100101"; ; OclType["Sequence"](st) ; n := (st)->size() ; execute (countSubStr(st, n))->display(); operation countSubStr(st : OclAny, n : OclAny) : OclAny pre: true post: true activity: var m : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (st[i+1] = '1') then ( m := m + 1 ) else skip) ; return m * (m - 1) div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printPascal(n): for line in range(0,n): for i in range(0,line+1): print(binomialCoeff(line,i),"",end="") print() def binomialCoeff(n,k): res=1 if(k>n-k): k=n-k for i in range(0,k): res=res*(n-i) res=res//(i+1) return res n=7 printPascal(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 7 ; printPascal(n); operation printPascal(n : OclAny) pre: true post: true activity: for line : Integer.subrange(0, n-1) do ( for i : Integer.subrange(0, line + 1-1) do ( execute (binomialCoeff(line, i))->display()) ; execute (->display()); operation binomialCoeff(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; if ((k->compareTo(n - k)) > 0) then ( k := n - k ) else skip ; for i : Integer.subrange(0, k-1) do ( res := res * (n - i) ; res := res div (i + 1)) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for num in range(1,T+1): n,l,h=input().split() n=int(n) l=int(l) h=int(h) F=list(map(int,input().split())) print("Case #",num,":",sep='',end=' ') for ans in range(l,h+1): good=True for elem in F : if elem % ans!=0 and ans % elem!=0 : good=False if good : print(ans) break else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for num : Integer.subrange(1, T + 1-1) do ( var n : OclAny := null; var l : OclAny := null; var h : OclAny := null; Sequence{n,l,h} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var l : int := ("" + ((l)))->toInteger() ; var h : int := ("" + ((h)))->toInteger() ; var F : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ("Case #")->display() ; (compound_stmt for (exprlist (expr (atom (name ans)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name h))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name good)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name True)))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name elem)))) in (testlist (test (logical_test (comparison (expr (atom (name F))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (expr (atom (name elem))) % (expr (atom (name ans))))) != (comparison (expr (atom (number (integer 0))))))) and (logical_test (comparison (comparison (expr (expr (atom (name ans))) % (expr (atom (name elem))))) != (comparison (expr (atom (number (integer 0))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name good)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name False)))))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name good)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : b,r,g,c,s,t=map(int,input().split()) if t==0 : break ans=100 ans+=(15-2)*(5*b)+(15-3)*b t-=6*b ans+=(15-2)*(3*r)+(15-3)*r t-=4*r ans+=(7-3)*g t-=g ans+=(2-3)*c t-=c t-=s ans+=(0-3)*t print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var b : OclAny := null; var r : OclAny := null; var g : OclAny := null; var c : OclAny := null; var s : OclAny := null; var t : OclAny := null; Sequence{b,r,g,c,s,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if t = 0 then ( break ) else skip ; var ans : int := 100 ; ans := ans + (15 - 2) * (5 * b) + (15 - 3) * b ; t := t - 6 * b ; ans := ans + (15 - 2) * (3 * r) + (15 - 3) * r ; t := t - 4 * r ; ans := ans + (7 - 3) * g ; t := t - g ; ans := ans + (2 - 3) * c ; t := t - c ; t := t - s ; ans := ans + (0 - 3) * t ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import division import sys def calc(a,b): n,l,h=a freq=b for i in range(l,h+1): harmony=True for f in freq : if not(f % i==0 or i % f==0): harmony=False break if harmony : return "%d" % i return "NO" def getints(): return[int(x)for x in sys.stdin.readline().strip().split(" ")] numTestCases=getints()[0] for i in range(numTestCases): result=calc(getints(),getints()) print("Case #%d: %s" %(i+1,result)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var numTestCases : OclAny := getints()->first() ; for i : Integer.subrange(0, numTestCases-1) do ( var result : OclAny := calc(getints(), getints()) ; execute (StringLib.format("Case #%d: %s",Sequence{i + 1, result}))->display()); operation calc(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; var h : OclAny := null; Sequence{n,l,h} := a ; var freq : OclAny := b ; for i : Integer.subrange(l, h + 1-1) do ( var harmony : boolean := true ; for f : freq do ( if not((f mod i = 0 or i mod f = 0)) then ( harmony := false ; break ) else skip) ; if harmony then ( return StringLib.format("%d",i) ) else skip) ; return "NO"; operation getints() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math inf=open("in.txt","r") ouf=open('out.txt','w') def close_files(): inf.close ouf.close def precount(): pass printcounter=0 def printstr(a): global printcounter printcounter+=1 print>>ouf,'Case #%d: %s' %(printcounter,a) def solvetest(): inp=inf.readline().split() [n,l,h]=map(int,inp) inp=inf.readline().split() a=map(int,inp) f=0 for i in xrange(l,h+1): bad=0 for j in xrange(n): if(i % a[j]==0)or(a[j]% i==0): pass else : bad=1 if not bad : f=i break if f : printstr(str(f)) else : printstr('NO') precount() testnum=int(inf.readline()) for test in xrange(testnum): solvetest() close_files() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute printcounter : OclAny; operation initialise() pre: true post: true activity: skip ; var Math_PINFINITY : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("in.txt")) ; var ouf : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('out.txt')) ; skip ; skip ; var printcounter : int := 0 ; skip ; skip ; Sequence{n}->union(Sequence{l}->union(Sequence{ h })) := (inp)->collect( _x | (OclType["int"])->apply(_x) ); operation close_files() pre: true post: true activity: Math_PINFINITY.closeFile() ; ouf.closeFile(); operation precount() pre: true post: true activity: skip; operation printstr(a : OclAny) pre: true post: true activity: skip ; printcounter := printcounter + 1 ; print /(2->pow(ouf)) ; (expr (expr (atom 'Case #%d: %s')) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name printcounter)))))) , (test (logical_test (comparison (expr (atom (name a))))))) )))); operation solvetest() pre: true post: true activity: var inp : OclAny := Math_PINFINITY.readLine().split(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys def printe(*st): return True sys.stderr.write(",".join([str(x)for x in st])+"\n") def generator(N,l): a=0 i=0 while atoInteger()-1) do ( execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{i + 1, simulate()}))->display()) ) else skip; operation printe(st : OclAny : Sequence(OclAny)) : OclAny pre: true post: true activity: (args * (named_parameter (name st))) return true ; (expr (atom (name sys)) (trailer . (name stderr)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ",") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name st))))))) ]))))))) )))) + (expr (atom "\n")))))))) )))); operation generator(N : OclAny, l : OclAny) pre: true post: true activity: var a : int := 0 ; var i : int := 0 ; while (a->compareTo(N)) < 0 do ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return l[i+1] ; i := i + 1 ; if i = (l)->size() then ( i := 0 ) else skip ; a := a + 1); operation simulate() pre: true post: true activity: ; Sequence{n}->union(Sequence{l}->union(Sequence{ h })) := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; var orchestra : Sequence := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; var notes : Sequence := Sequence{} ; for i : Integer.subrange(l, h + 1-1) do ( execute ((i) : notes)) ; for l : orchestra do ( i := 0 ; while (i->compareTo((notes)->size())) < 0 do ( if notes[i+1] mod l = 0 or l mod notes[i+1] = 0 then ( i := i + 1 ) else ( notes := notes->excludingAt(i+1) )) ; printe(notes)) ; if (notes)->size() = 0 then ( return "NO" ) else ( return notes->first() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSubarrCnt(arr,n): ans=0 ; XOR=0 ; prefix=[0]*n ; for i in range(n): XOR=XOR ^ arr[i]; prefix[i]=XOR ; oddGroup=dict.fromkeys(prefix,0) evenGroup=dict.fromkeys(prefix,0) oddGroup[0]=1 ; for i in range(n): if(i & 1): ans+=oddGroup[prefix[i]]; oddGroup[prefix[i]]+=1 ; else : ans+=evenGroup[prefix[i]]; evenGroup[prefix[i]]+=1 ; return ans ; if __name__=="__main__" : N=6 ; arr=[3,2,2,3,7,6]; print(findSubarrCnt(arr,N)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var N : int := 6; ; arr := Sequence{3}->union(Sequence{2}->union(Sequence{2}->union(Sequence{3}->union(Sequence{7}->union(Sequence{ 6 }))))); ; execute (findSubarrCnt(arr, N))->display(); ) else skip; operation findSubarrCnt(arr : OclAny, n : OclAny) pre: true post: true activity: var ans : int := 0; var XOR : int := 0; ; var prefix : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; for i : Integer.subrange(0, n-1) do ( XOR := MathLib.bitwiseXor(XOR, arr[i+1]); ; prefix[i+1] := XOR;) ; var oddGroup : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name prefix))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))) ; var evenGroup : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name prefix))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))) ; oddGroup->first() := 1; ; for i : Integer.subrange(0, n-1) do ( if (MathLib.bitwiseAnd(i, 1)) then ( ans := ans + oddGroup[prefix[i+1]+1]; ; oddGroup[prefix[i+1]+1] := oddGroup[prefix[i+1]+1] + 1; ) else ( ans := ans + evenGroup[prefix[i+1]+1]; ; evenGroup[prefix[i+1]+1] := evenGroup[prefix[i+1]+1] + 1; )) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,n=input().split() H=int(h) N=int(n) a=[int(x)for x in input().split()] total=0 for i in range(N): total+=a[i] if(total>=H): print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var n : OclAny := null; Sequence{h,n} := input().split() ; var H : int := ("" + ((h)))->toInteger() ; var N : int := ("" + ((n)))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var total : int := 0 ; for i : Integer.subrange(0, N-1) do ( total := total + a[i+1]) ; if ((total->compareTo(H)) >= 0) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,N=map(int,input().split()) A=list(map(int,input().split())) print("Yes" if sum(A)>=H else "No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var N : OclAny := null; Sequence{H,N} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (if ((A)->sum()->compareTo(H)) >= 0 then "Yes" else "No" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=list(map(int,input().split())) a=list(map(int,input().split())) a.sort(reverse=True) flag=0 damage=0 for i in range(c[1]): damage+=a[i] if damage>=c[0]: flag=1 break if flag==1 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var flag : int := 0 ; var damage : int := 0 ; for i : Integer.subrange(0, c[1+1]-1) do ( damage := damage + a[i+1] ; if (damage->compareTo(c->first())) >= 0 then ( flag := 1 ; break ) else skip) ; if flag = 1 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import combinations H,N=map(int,input().split()) ASUM=sum(map(int,input().split())) if H<=ASUM : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var H : OclAny := null; var N : OclAny := null; Sequence{H,N} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ASUM : OclAny := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum() ; if (H->compareTo(ASUM)) <= 0 then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math h,n=map(int,input().split()) sum=0 li=list(map(int,input().split())) for val in li : sum+=val if sum>=h : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var h : OclAny := null; var n : OclAny := null; Sequence{h,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sum : int := 0 ; var li : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for val : li do ( sum := sum + val) ; if (sum->compareTo(h)) >= 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000001 def numofAP(a,n): minarr=+2147483647 maxarr=-2147483648 for i in range(n): minarr=min(minarr,a[i]) maxarr=max(maxarr,a[i]) dp=[0 for i in range(n+1)] ans=n+1 for d in range((minarr-maxarr),(maxarr-minarr)+1): sum=[0 for i in range(MAX+1)] for i in range(n): dp[i]=1 if(a[i]-d>=1 and a[i]-d<=1000000): dp[i]+=sum[a[i]-d] ans+=dp[i]-1 sum[a[i]]+=dp[i] return ans arr=[1,2,3] n=len(arr) print(numofAP(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1000001 ; skip ; var arr : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; n := (arr)->size() ; execute (numofAP(arr, n))->display(); operation numofAP(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var minarr : int := 2147483647 ; var maxarr : int := -2147483648 ; for i : Integer.subrange(0, n-1) do ( minarr := Set{minarr, a[i+1]}->min() ; maxarr := Set{maxarr, a[i+1]}->max()) ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; var ans : OclAny := n + 1 ; for d : Integer.subrange((minarr - maxarr), (maxarr - minarr) + 1-1) do ( var sum : Sequence := Integer.subrange(0, MAX + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( dp[i+1] := 1 ; if (a[i+1] - d >= 1 & a[i+1] - d <= 1000000) then ( dp[i+1] := dp[i+1] + [a[i+1] - d+1]->sum() ) else skip ; ans := ans + dp[i+1] - 1 ; [a[i+1]+1]->sum() := [a[i+1]+1]->sum() + dp[i+1])) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _,k=map(int,input().split()) arr=list(map(int,input().split())) if k==1 : print(min(arr)) elif k==2 : print(max(arr[0],arr[-1])) else : print(max(arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _anon : OclAny := null; var k : OclAny := null; Sequence{_anon,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if k = 1 then ( execute ((arr)->min())->display() ) else (if k = 2 then ( execute (Set{arr->first(), arr->last()}->max())->display() ) else ( execute ((arr)->max())->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _,a,*l=map(int,open(0).read().split()) for i in l : x,y=a,i while y : x,y=y,x % y a*=i//x print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _anon : OclAny := null; var a : OclAny := null; var l : OclAny := null; Sequence{_anon,a,l} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : l do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{a,i} ; while y do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{y,x mod y}) ; a := a * i div x) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): r=a % b return b if r==0 else gcd(b,r) def lcm(a,b): return a*b//gcd(a,b) n=int(input()) T=[int(input())for _ in range(n)] answer=1 for t in T : answer=lcm(answer,t) print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var T : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var answer : int := 1 ; for t : T do ( answer := lcm(answer, t)) ; execute (answer)->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var r : int := a mod b ; return if r = 0 then b else gcd(b, r) endif; operation lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a * b div gcd(a, b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def two_int(): N,K=map(int,input().split()) return N,K def one_int(): return int(input()) def one_str(): return input() def many_int(): return list(map(int,input().split())) import fractions def lcm(x,y): return(x*y)//fractions.gcd(x,y) N=one_int() temp=one_int() for i in range(N-1): temp=lcm(temp,one_int()) print(temp) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var N : OclAny := one_int() ; var temp : OclAny := one_int() ; for i : Integer.subrange(0, N - 1-1) do ( temp := lcm(temp, one_int())) ; execute (temp)->display(); operation two_int() : OclAny pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; return N, K; operation one_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation one_str() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation many_int() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation lcm(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return (x * y) div fractions.gcd(x, y); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import fractions n=int(input()) t=[] for _ in range(n): t.append(int(input())) l=[] ans=t[0] for i in range(1,n): if t[i]in l : continue else : l.append(t[i]) ans=ans*t[i]//fractions.gcd(ans,t[i]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : t)) ; var l : Sequence := Sequence{} ; var ans : OclAny := t->first() ; for i : Integer.subrange(1, n-1) do ( if (l)->includes(t[i+1]) then ( continue ) else ( execute ((t[i+1]) : l) ; ans := ans * t[i+1] div fractions.gcd(ans, t[i+1]) )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import fractions as f n=int(input()) t=int(input()) ans=0 if n==1 : print(t) else : for i in range(n-1): s=int(input()) t=s*t//f.gcd(t,s) if anstoInteger() ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; if n = 1 then ( execute (t)->display() ) else ( for i : Integer.subrange(0, n - 1-1) do ( var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; t := s * t div f.gcd(t, s) ; if (ans->compareTo(t)) < 0 then ( ans := t ) else skip) ; execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(0,int(input())): m,x=map(int,input().split()) n=m-1 w=n r=n % 4 if r==0 : w=n elif r==1 : w=1 elif r==2 : w=n+1 elif r==3 : w=0 t=x ^ w a=0 if w!=x : a+=1 a+=(m==t) print(m+a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var m : OclAny := null; var x : OclAny := null; Sequence{m,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : double := m - 1 ; var w : OclAny := n ; var r : int := n mod 4 ; if r = 0 then ( w := n ) else (if r = 1 then ( w := 1 ) else (if r = 2 then ( w := n + 1 ) else (if r = 3 then ( w := 0 ) else skip ) ) ) ; var t : int := MathLib.bitwiseXor(x, w) ; var a : int := 0 ; if w /= x then ( a := a + 1 ; a := a + (m = t) ) else skip ; execute (m + a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) for i in range(x): a,b=input().split() a=int(a) b=int(b) l=[] ix=a//4 aux=0 for i in range(ix*4,(ix*4)+4): aux=aux ^ i l.append(aux) if(a % 4)-1<0 : lv=0 else : lv=l[(a % 4)-1] if lv==b : print(a) elif lv ^ b==a : print(a+2) else : print(a+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, x-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; var l : Sequence := Sequence{} ; var ix : int := a div 4 ; var aux : int := 0 ; for i : Integer.subrange(ix * 4, (ix * 4) + 4-1) do ( aux := MathLib.bitwiseXor(aux, i) ; execute ((aux) : l)) ; if (a mod 4) - 1 < 0 then ( var lv : int := 0 ) else ( lv := l[(a mod 4) - 1+1] ) ; if lv = b then ( execute (a)->display() ) else (if MathLib.bitwiseXor(lv, b) = a then ( execute (a + 2)->display() ) else ( execute (a + 1)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) for i in range(x): a,b=input().split() a=int(a) b=int(b) l=[] ix=a//4 aux=0 for i in range(ix*4,(ix*4)+4): aux=aux ^ i l.append(aux) if(a % 4)-1<0 : lv=0 else : lv=l[(a % 4)-1] if lv==b : print(a) elif lv ^ a==b : print(a+2) else : print(a+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, x-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; var l : Sequence := Sequence{} ; var ix : int := a div 4 ; var aux : int := 0 ; for i : Integer.subrange(ix * 4, (ix * 4) + 4-1) do ( aux := MathLib.bitwiseXor(aux, i) ; execute ((aux) : l)) ; if (a mod 4) - 1 < 0 then ( var lv : int := 0 ) else ( lv := l[(a mod 4) - 1+1] ) ; if lv = b then ( execute (a)->display() ) else (if MathLib.bitwiseXor(lv, a) = b then ( execute (a + 2)->display() ) else ( execute (a + 1)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(3e5+5) xor_precomputed=[] xor_precomputed.append(0) for i in range(1,n): xor_precomputed.append(xor_precomputed[i-1]^ i) t=int(input()) while t : x,y=map(int,input().split()) xor_array=xor_precomputed[x-1] if xor_array==y : print(x) else : res=xor_array ^ y if res==x : print(x+2) else : print(x+1) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + ((("3e5")->toReal() + 5)))->toInteger() ; var xor_precomputed : Sequence := Sequence{} ; execute ((0) : xor_precomputed) ; for i : Integer.subrange(1, n-1) do ( execute ((MathLib.bitwiseXor(xor_precomputed[i - 1+1], i)) : xor_precomputed)) ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var xor_array : OclAny := xor_precomputed[x - 1+1] ; if xor_array = y then ( execute (x)->display() ) else ( var res : int := MathLib.bitwiseXor(xor_array, y) ; if res = x then ( execute (x + 2)->display() ) else ( execute (x + 1)->display() ) ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans=[] x=3*(10**5) xor=0 for i in range(x+1): xor ^=i ans.append(xor) for _ in range(int(input())): mex,xor=map(int,input().split()) x=ans[mex-1] if x ^ xor==mex : print(mex+2) else : if x==xor : print(mex) else : print(mex+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ans : Sequence := Sequence{} ; var x : double := 3 * ((10)->pow(5)) ; var xor : int := 0 ; for i : Integer.subrange(0, x + 1-1) do ( xor := xor xor i ; execute ((xor) : ans)) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var mex : OclAny := null; Sequence{mex,xor} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; x := ans[mex - 1+1] ; if MathLib.bitwiseXor(x, xor) = mex then ( execute (mex + 2)->display() ) else ( if x = xor then ( execute (mex)->display() ) else ( execute (mex + 1)->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : b,r,g,c,s,t=map(int,input().split()) if b+r+g+c+s+t==0 : break normal_game=t-b*5-r*3 bonus_game=b*5+r*3 print(100+bonus_game*16+15*b+15*r+7*g+2*c+3*s-t*3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var b : OclAny := null; var r : OclAny := null; var g : OclAny := null; var c : OclAny := null; var s : OclAny := null; var t : OclAny := null; Sequence{b,r,g,c,s,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if b + r + g + c + s + t = 0 then ( break ) else skip ; var normal_game : double := t - b * 5 - r * 3 ; var bonus_game : double := b * 5 + r * 3 ; execute (100 + bonus_game * 16 + 15 * b + 15 * r + 7 * g + 2 * c + 3 * s - t * 3)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): divisorsum=[0]*10000 for i in range(1,len(divisorsum)): for j in range(i*2,len(divisorsum),i): divisorsum[j]+=i ans=0 for i in range(1,len(divisorsum)): j=divisorsum[i] if j!=i and jdisplay() ) else skip; operation compute() : OclAny pre: true post: true activity: var divisorsum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10000) ; for i : Integer.subrange(1, (divisorsum)->size()-1) do ( for j : Integer.subrange(i * 2, (divisorsum)->size()-1)->select( $x | ($x - i * 2) mod i = 0 ) do ( divisorsum[j+1] := divisorsum[j+1] + i)) ; var ans : int := 0 ; for i : Integer.subrange(1, (divisorsum)->size()-1) do ( var j : OclAny := divisorsum[i+1] ; if j /= i & (j->compareTo((divisorsum)->size())) < 0 & divisorsum[j+1] = i then ( ans := ans + i ) else skip) ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print("vowel" if input()in "aiueo" else "consonant") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (if ("aiueo")->characters()->includes((OclFile["System.in"]).readLine()) then "vowel" else "consonant" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INT=lambda : int(input()) INTM=lambda : map(int,input().split()) STRM=lambda : map(str,input().split()) STR=lambda : str(input()) LIST=lambda : list(map(int,input().split())) def do(): boin=('a','e','u','i','o') c=STR() if c in boin : print('vowel') else : print('consonant') if __name__=='__main__' : do() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INT : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var INTM : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var STRM : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["String"])->apply(_x) )) ; var STR : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))) ; var LIST : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; skip ; if __name__ = '__main__' then ( do() ) else skip; operation do() pre: true post: true activity: var boin : OclAny := Sequence{'a', 'e', 'u', 'i', 'o'} ; var c : OclAny := STR->apply() ; if (boin)->includes(c) then ( execute ('vowel')->display() ) else ( execute ('consonant')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=input() vowel=['a','e','i','o','u'] if c in vowel : print('vowel') else : print('consonant') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : String := (OclFile["System.in"]).readLine() ; var vowel : Sequence := Sequence{'a'}->union(Sequence{'e'}->union(Sequence{'i'}->union(Sequence{'o'}->union(Sequence{ 'u' })))) ; if (vowel)->includes(c) then ( execute ('vowel')->display() ) else ( execute ('consonant')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=input() ans="consonant" if c=="a" or c=="i" or c=="u" or c=="e" or c=="o" : ans="vowel" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : String := (OclFile["System.in"]).readLine() ; var ans : String := "consonant" ; if c = "a" or c = "i" or c = "u" or c = "e" or c = "o" then ( ans := "vowel" ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=input() boin=["a","e","i","o","u"] print("vowel" if c in boin else "consonant") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : String := (OclFile["System.in"]).readLine() ; var boin : Sequence := Sequence{"a"}->union(Sequence{"e"}->union(Sequence{"i"}->union(Sequence{"o"}->union(Sequence{ "u" })))) ; execute (if (boin)->includes(c) then "vowel" else "consonant" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d={} for _ in[0]*int(input()): a,v=map(int,input().split()) d[v]=min(a,d[v])if v in d else a m=max(d) print(d[m],m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : OclAny := Set{} ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var a : OclAny := null; var v : OclAny := null; Sequence{a,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; d[v+1] := if (d)->includes(v) then Set{a, d[v+1]}->min() else a endif) ; var m : OclAny := (d)->max() ; execute (d[m+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) tbl=[0]*(n+1) vmax=0 for i in range(n): a,v=list(map(int,input().split())) tbl[a]+=v if tbl[a]>vmax : vmax=tbl[a] for i in range(1,n+1): if tbl[i]==vmax : print(i,vmax) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var tbl : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var vmax : int := 0 ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var v : OclAny := null; Sequence{a,v} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; tbl[a+1] := tbl[a+1] + v ; if (tbl[a+1]->compareTo(vmax)) > 0 then ( vmax := tbl[a+1] ) else skip) ; for i : Integer.subrange(1, n + 1-1) do ( if tbl[i+1] = vmax then ( execute (i)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") N=int(input()) A=sorted([[int(_)for _ in input().split()]for __ in range(N)],key=lambda x :(-x[1],x[0])) print(A[0][0],A[0][1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := Integer.subrange(0, N-1)->select(__ | true)->collect(__ | (input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger()))))->sortedBy($x | (lambda x : OclAny in (Sequence{-x[1+1], x->first()}))->apply($x)) ; execute (A->first()->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin n=int(input()) book=[0]*(n+1) for _ in stdin.readlines(): if 0 not in book : break a,v=map(int,_.split()) book[a]=v+1 max_val=max(book) print(book.index(max_val),max_val-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var book : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for _anon : stdin.readlines() do ( if (book)->excludes(0) then ( break ) else skip ; var a : OclAny := null; var v : OclAny := null; Sequence{a,v} := (_anon.split())->collect( _x | (OclType["int"])->apply(_x) ) ; book[a+1] := v + 1) ; var max_val : OclAny := (book)->max() ; execute (book->indexOf(max_val) - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : try : x=int(input()) h=int(input()) if x==h==0 : break ans=x**2 he=(h**2+x**2/4)**0.5 tri=he*x*0.5 ans+=tri*4 print(f"{ans:.7f}") except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( try ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var h : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if x = h & (h == 0) then ( break ) else skip ; var ans : double := (x)->pow(2) ; var he : double := (((h)->pow(2) + (x)->pow(2) / 4))->pow(0.5) ; var tri : double := he * x * 0.5 ; ans := ans + tri * 4 ; execute (StringLib.formattedString("{ans:.7f}"))->display()) catch (_e : OclException) do ( break) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- maxn=1010 mod=1000000007 comb=[[0 for i in range(maxn)]for i in range(maxn)] comb[0][0]=1 for i in range(1,maxn): comb[i][0]=1 for j in range(1,i+1): comb[i][j]=comb[i-1][j]+comb[i-1][j-1]% mod k=int(input()) color=[int(input())for i in range(k)] res=1 total=0 for i in range(k): res=(res*comb[total+color[i]-1][color[i]-1])% mod total+=color[i]% mod print(res % mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var maxn : int := 1010 ; var mod : int := 1000000007 ; var comb : Sequence := Integer.subrange(0, maxn-1)->select(i | true)->collect(i | (Integer.subrange(0, maxn-1)->select(i | true)->collect(i | (0)))) ; comb->first()->first() := 1 ; for i : Integer.subrange(1, maxn-1) do ( comb[i+1]->first() := 1 ; for j : Integer.subrange(1, i + 1-1) do ( comb[i+1][j+1] := comb[i - 1+1][j+1] + comb[i - 1+1][j - 1+1] mod mod)) ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var color : Sequence := Integer.subrange(0, k-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var res : int := 1 ; var total : int := 0 ; for i : Integer.subrange(0, k-1) do ( res := (res * comb[total + color[i+1] - 1+1][color[i+1] - 1+1]) mod mod ; total := total + color[i+1] mod mod) ; execute (res mod mod)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import operator v={} n=int(input().strip()) for _ in range(n): i,ip=map(int,input().strip().split()) v[i]=ip w=sorted(v.items(),key=operator.itemgetter(1),reverse=True) print("%d %d" % w[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var v : OclAny := Set{} ; var n : int := ("" + ((input()->trim())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var i : OclAny := null; var ip : OclAny := null; Sequence{i,ip} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; v[i+1] := ip) ; var w : Sequence := v->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sortedBy($x | (operator.itemgetter(1))->apply($x)) ; execute (StringLib.format("%d %d",w->first()))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def result(s,n): st=set(); for i in range(len(s)): ans="" ; for j in range(i,len(s)): ans+=s[j]; if(len(ans)==n): st.add(ans); break ; for it in st : print(it,end=" "); if __name__=="__main__" : s="abca" ; n=3 ; result(s,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "abca"; ; n := 3; ; result(s, n); ) else skip; operation result(s : OclAny, n : OclAny) pre: true post: true activity: var st : Set := Set{}->union(()); ; for i : Integer.subrange(0, (s)->size()-1) do ( var ans : String := ""; ; for j : Integer.subrange(i, (s)->size()-1) do ( ans := ans + s[j+1]; ; if ((ans)->size() = n) then ( execute ((ans) : st); ; break; ) else skip)) ; for it : st do ( execute (it)->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rearrange(arr,n): for i in range(n-1): if(i % 2==0 and arr[i]>arr[i+1]): temp=arr[i] arr[i]=arr[i+1] arr[i+1]=temp if(i % 2!=0 and arr[i]union(Sequence{4}->union(Sequence{2}->union(Sequence{1}->union(Sequence{8}->union(Sequence{ 3 }))))) ; n := (arr)->size() ; execute ("Before rearranging: ")->display() ; printArray(arr, n) ; rearrange(arr, n) ; execute ("After rearranging:")->display() ; printArray(arr, n);; operation rearrange(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n - 1-1) do ( if (i mod 2 = 0 & (arr[i+1]->compareTo(arr[i + 1+1])) > 0) then ( var temp : OclAny := arr[i+1] ; arr[i+1] := arr[i + 1+1] ; arr[i + 1+1] := temp ) else skip ; if (i mod 2 /= 0 & (arr[i+1]->compareTo(arr[i + 1+1])) < 0) then ( temp := arr[i+1] ; arr[i+1] := arr[i + 1+1] ; arr[i + 1+1] := temp ) else skip); operation printArray(arr : OclAny, size : OclAny) pre: true post: true activity: for i : Integer.subrange(0, size-1) do ( execute (arr[i+1])->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Player : def __init__(self): self.score=0 self.card='' a=Player() b=Player() no_gemes=int(input()) for _ in range(no_gemes): a.card,b.card=input().split() if a.card==b.card : a.score+=1 b.score+=1 elif a.card>b.card : a.score+=3 elif a.cardexists( _x | result = _x ); attribute score : int := 0; attribute card : String := ''; operation initialise() : Player pre: true post: true activity: self.score := 0 ; self.card := ''; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; var a : Player := (Player.newPlayer()).initialise() ; var b : Player := (Player.newPlayer()).initialise() ; var no_gemes : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, no_gemes-1) do ( var a.card : OclAny := null; var b.card : OclAny := null; Sequence{a.card,b.card} := input().split() ; if a.card = b.card then ( a.score := a.score + 1 ; b.score := b.score + 1 ) else (if (a.card->compareTo(b.card)) > 0 then ( a.score := a.score + 3 ) else (if (a.card->compareTo(b.card)) < 0 then ( b.score := b.score + 3 ) else skip ) ) ) ; execute (a.score)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- score=[0,0] n=int(input().strip()) for i in range(n): line=input().strip().split(" ") if line[0]>line[1]: score[0]+=3 elif line[0]union(Sequence{ 0 }) ; var n : int := ("" + ((input()->trim())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var line : OclAny := input()->trim().split(" ") ; if (line->first()->compareTo(line[1+1])) > 0 then ( score->first() := score->first() + 3 ) else (if (line->first()->compareTo(line[1+1])) < 0 then ( score[1+1] := score[1+1] + 3 ) else ( score->first() := score->first() + 1 ; score[1+1] := score[1+1] + 1 ) ) ) ; execute (StringLib.sumStringsWithSeparator((((score)->collect( _x | (OclType["String"])->apply(_x) ))), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def judge_battle(tcard : str,hcard : str)->str : if tcard>hcard : return 'win' elif tcard==hcard : return 'equal' else : return 'lose' if __name__=='__main__' : score_list=[0,0] n=int(input()) for i in range(n): card1,card2=input().split() battle_result=judge_battle(card1,card2) if battle_result=='win' : score_list[0]+=3 elif battle_result=='equal' : score_list[0]+=1 score_list[1]+=1 else : score_list[1]+=3 print(' '.join(map(str,score_list))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var score_list : Sequence := Sequence{0}->union(Sequence{ 0 }) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var card1 : OclAny := null; var card2 : OclAny := null; Sequence{card1,card2} := input().split() ; var battle_result : OclAny := judge_battle(card1, card2) ; if battle_result = 'win' then ( score_list->first() := score_list->first() + 3 ) else (if battle_result = 'equal' then ( score_list->first() := score_list->first() + 1 ; score_list[1+1] := score_list[1+1] + 1 ) else ( score_list[1+1] := score_list[1+1] + 3 ) ) ) ; execute (StringLib.sumStringsWithSeparator(((score_list)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display() ) else skip; operation judge_battle(tcard : String, hcard : String) : String pre: true post: true activity: if tcard > hcard then ( return 'win' ) else (if tcard = hcard then ( return 'equal' ) else ( return 'lose' ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function num=int(raw_input()) taro,hanako=(0,0) for i in(cmp(*raw_input().split())for n in xrange(num)): if i>0 : taro+=3 elif i==0 : taro+=1 hanako+=1 else : hanako+=3 print(taro,hanako) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var num : int := ("" + ((raw_input())))->toInteger() ; var taro : OclAny := null; var hanako : OclAny := null; Sequence{taro,hanako} := Sequence{0, 0} ; for i : Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name cmp)) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom (name raw_input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name xrange)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) ))))))))} do ( if i > 0 then ( taro := taro + 3 ) else (if i = 0 then ( taro := taro + 1 ; hanako := hanako + 1 ) else ( hanako := hanako + 3 ) ) ) ; execute (taro)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() Taro=0 Hanako=0 for i in range(n): a,b=raw_input().split() if(ab): Taro+=3 else : Taro+=1 Hanako+=1 print(Taro), print(Hanako) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var Taro : int := 0 ; var Hanako : int := 0 ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := raw_input().split() ; if ((a->compareTo(b)) < 0) then ( Hanako := Hanako + 3 ) else (if ((a->compareTo(b)) > 0) then ( Taro := Taro + 3 ) else ( Taro := Taro + 1 ; Hanako := Hanako + 1 ) ) ) ; (testlist_star_expr (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name Taro)))))))) ))))))) ,) ; execute (Hanako)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math d,h,v,e=map(int,input().split()) x=((4*v)/(math.pi*d**2))-e if x>0 : print("YES") print(h/x) else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var d : OclAny := null; var h : OclAny := null; var v : OclAny := null; var e : OclAny := null; Sequence{d,h,v,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : double := ((4 * v) / ( * (d)->pow(2))) - e ; if x > 0 then ( execute ("YES")->display() ; execute (h / x)->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import pi d,h,v,e=map(int,input().split()) a=pi*(d/2)**2 ; t=(h*a)/(v-e*a) if t<0 : print('NO') else : print("YES"); print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var d : OclAny := null; var h : OclAny := null; var v : OclAny := null; var e : OclAny := null; Sequence{d,h,v,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : double := pi * ((d / 2))->pow(2); var t : double := (h * a) / (v - e * a) ; if t < 0 then ( execute ('NO')->display() ) else ( execute ("YES")->display(); execute (t)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=10**9+7 comb=[[0 for i in range(1005)]for j in range(1005)] comb[0][0]=1 for i in range(1,1005): comb[i][0]=1 for j in range(1,i+1): comb[i][j]=(comb[i-1][j]+comb[i-1][j-1])% mod n=int(input()) ans,cur=1,0 for i in range(n): a=int(input()) ans=(ans*comb[cur+a-1][a-1])% mod cur+=a print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : double := (10)->pow(9) + 7 ; var comb : Sequence := Integer.subrange(0, 1005-1)->select(j | true)->collect(j | (Integer.subrange(0, 1005-1)->select(i | true)->collect(i | (0)))) ; comb->first()->first() := 1 ; for i : Integer.subrange(1, 1005-1) do ( comb[i+1]->first() := 1 ; for j : Integer.subrange(1, i + 1-1) do ( comb[i+1][j+1] := (comb[i - 1+1][j+1] + comb[i - 1+1][j - 1+1]) mod mod)) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : OclAny := null; var cur : OclAny := null; Sequence{ans,cur} := Sequence{1,0} ; for i : Integer.subrange(0, n-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := (ans * comb[cur + a - 1+1][a - 1+1]) mod mod ; cur := cur + a) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math [d,h,v,e]=list(map(int,input().split(" "))) den=(4*v)/(math.pi*(d**2))-e if den>0 : print("YES") print(h/den) else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{d}->union(Sequence{h}->union(Sequence{v}->union(Sequence{ e }))) := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var den : double := (4 * v) / ( * ((d)->pow(2))) - e ; if den > 0 then ( execute ("YES")->display() ; execute (h / den)->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math d,h,v,e=map(int,input().split()) print('YES\n',h/(4*v/(math.pi*(d**2))-e),sep='')if v>math.pi*e*(d**2)/4 else print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var d : OclAny := null; var h : OclAny := null; var v : OclAny := null; var e : OclAny := null; Sequence{d,h,v,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES ')))))) , (argument (test (logical_test (comparison (expr (expr (atom (name h))) / (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (expr (atom (number (integer 4)))) * (expr (atom (name v)))) / (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name math)) (trailer . (name pi))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name d))) ** (expr (atom (number (integer 2))))))))) )))))))) )))) - (expr (atom (name e)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name sep)))))) = (test (logical_test (comparison (expr (atom ''))))))) )))))) if (logical_test (comparison (comparison (expr (atom (name v)))) > (comparison (expr (expr (expr (expr (atom (name math)) (trailer . (name pi))) * (expr (atom (name e)))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name d))) ** (expr (atom (number (integer 2))))))))) )))) / (expr (atom (number (integer 4)))))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) )))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) print(41,100) for _ in range(10): for _ in range(50): print('.',end='') if b>1 : print('#',end='') b-=1 else : print('.',end='') print() print('.'*100) print('#'*100) for _ in range(10): for _ in range(50): print('#',end='') if a>1 : print('.',end='') a-=1 else : print('#',end='') print() print('#'*100) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (41)->display() ; for _anon : Integer.subrange(0, 10-1) do ( for _anon : Integer.subrange(0, 50-1) do ( execute ('.')->display() ; if b > 1 then ( execute ('#')->display() ; b := b - 1 ) else ( execute ('.')->display() )) ; execute (->display() ; execute (StringLib.nCopies('.', 100))->display()) ; execute (StringLib.nCopies('#', 100))->display() ; for _anon : Integer.subrange(0, 10-1) do ( for _anon : Integer.subrange(0, 50-1) do ( execute ('#')->display() ; if a > 1 then ( execute ('.')->display() ; a := a - 1 ) else ( execute ('#')->display() )) ; execute (->display() ; execute (StringLib.nCopies('#', 100))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math d,h,v,e=map(int,input().split()) drink_s=(4*v)/(math.pi*(d**2)) if drink_s>e : print("YES") result=(h/(drink_s-e)) print(round(result,12)) else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var d : OclAny := null; var h : OclAny := null; var v : OclAny := null; var e : OclAny := null; Sequence{d,h,v,e} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var drink_s : double := (4 * v) / ( * ((d)->pow(2))) ; if (drink_s->compareTo(e)) > 0 then ( execute ("YES")->display() ; var result : double := (h / (drink_s - e)) ; execute (MathLib.roundN(result, 12))->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) if b % a==0 : print(a+b) else : print(b-a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if b mod a = 0 then ( execute (a + b)->display() ) else ( execute (b - a)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.readline().strip() def main(): a,b=map(int,input().split()) if b % a : print(b-a) else : print(a+b) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; main(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation main() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if b mod a then ( execute (b - a)->display() ) else ( execute (a + b)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): a,b=list(map(int,input().split())) if b % a==0 : print(a+b) else : print(b-a) return 0 if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() : OclAny pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if b mod a = 0 then ( execute (a + b)->display() ) else ( execute (b - a)->display() ) ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()); print((b-a)*(b % a>0)or a+b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); execute ((b - a) * (b mod a > 0) or a + b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=list(map(int,input().split())) A,B=a[0],a[1] if B % A==0 : print(A+B) else : print(B-A) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := Sequence{a->first(),a[1+1]} ; if B mod A = 0 then ( execute (A + B)->display() ) else ( execute (B - A)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) mat=[] mat1=[] mat2=[] for _ in range(n): t=list(map(int,input().split())) mat.append(t) for i in range(n): m=[] m1=[] for j in range(n): if(i==j): m.append("{0:.8f}".format(mat[i][j])) m1.append("{0:.8f}".format(0)) elif(itoInteger() ; var mat : Sequence := Sequence{} ; var mat1 : Sequence := Sequence{} ; var mat2 : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var t : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((t) : mat)) ; for i : Integer.subrange(0, n-1) do ( var m : Sequence := Sequence{} ; var m1 : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( if (i = j) then ( execute ((StringLib.interpolateStrings("{0:.8f}", Sequence{mat[i+1][j+1]})) : m) ; execute ((StringLib.interpolateStrings("{0:.8f}", Sequence{0})) : m1) ) else (if ((i->compareTo(j)) < 0) then ( var a : double := (mat[i+1][j+1] + mat[j+1][i+1]) / 2 ; execute ((StringLib.interpolateStrings("{0:.8f}", Sequence{a})) : m) ; execute ((StringLib.interpolateStrings("{0:.8f}", Sequence{mat[i+1][j+1] - a})) : m1) ) else ( execute ((mat1[j+1][i+1]) : m) ; if (mat2[j+1][i+1]->first() /= "-") then ( execute (("-" + (mat2[j+1][i+1])) : m1) ) else ( execute ((mat2[j+1][i+1]->tail()) : m1) ) ) ) ) ; execute ((m) : mat1) ; execute ((m1) : mat2)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( execute (mat1[i+1][j+1])->display()) ; execute (->display()) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( execute (mat2[i+1][j+1])->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def mod_exp(a : int,b : int,mod : int)->int : a=a % mod res=1 while b>0 : if b & 1 : res=(res*a)% mod a=(a*a)% mod b>>=1 return res def modprimeinverse(a : int,mod : int)->int : return mod_exp(a,mod-2,mod) def comb(x : int,y : int,mod : int)->int : if xunion(MatrixLib.elementwiseMult(Sequence{ 0 }, N)) ; var invfact : Sequence := Sequence{ 1 }->union(MatrixLib.elementwiseMult(Sequence{ 0 }, N)) ; var MOD : int := ("" + ((("1e9")->toReal() + 7)))->toInteger() ; for i : Integer.subrange(1, N-1) do ( fact[i+1] := (i * fact[i - 1+1]) mod MOD ; invfact[i+1] := modprimeinverse(fact[i+1], MOD)) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sums : int := 0 ; res := 1 ; for i : Integer.subrange(0, n-1) do ( a := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; sums := sums + a ; res := (res * comb(sums - 1, a - 1, MOD)) mod MOD) ; execute (res)->display(); operation mod_exp(a : int, b : int, mod : int) : int pre: true post: true activity: var a : int := a mod mod ; var res : int := 1 ; while b > 0 do ( if MathLib.bitwiseAnd(b, 1) then ( res := (res * a) mod mod ) else skip ; a := (a * a) mod mod ; b := b div (2->pow(1))) ; return res; operation modprimeinverse(a : int, mod : int) : int pre: true post: true activity: return mod_exp(a, mod - 2, mod); operation comb(x : int, y : int, mod : int) : int pre: true post: true activity: if (x->compareTo(y)) < 0 then ( return 0 ) else ( return ((fact[x+1] * invfact[y+1]) mod mod * invfact[x - y+1]) mod mod ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=[] n=int(input()) for _ in range(n): l.append(list(map(int,input().split()))) a=[[0 for i in range(n)]for j in range(n)] b=[[0 for i in range(n)]for j in range(n)] for i in range(n): for j in range(n): a[i][j]=(l[i][j]+l[j][i])/2 for i in range(n): for j in range(n): print(a[i][j],end=" ") b[i][j]=l[i][j]-a[i][j] print() for i in range(n): for j in range(n): print(b[i][j],end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := Sequence{} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : l)) ; var a : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)))) ; var b : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( a[i+1][j+1] := (l[i+1][j+1] + l[j+1][i+1]) / 2)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( execute (a[i+1][j+1])->display() ; b[i+1][j+1] := l[i+1][j+1] - a[i+1][j+1]) ; execute (->display()) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( execute (b[i+1][j+1])->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lis=[] for x in range(n): lis.append(list(map(int,input().split()))) A=[] B=[] for x in range(n): A.append([(lis[x][i]+lis[i][x])/2 for i in range(n)]) B.append([lis[x][i]-A[x][i]for i in range(n)]) for x in A : for y in x : print(y,end=' ') print() for x in B : for y in x : print(y,end=' ') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lis : Sequence := Sequence{} ; for x : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : lis)) ; var A : Sequence := Sequence{} ; var B : Sequence := Sequence{} ; for x : Integer.subrange(0, n-1) do ( execute ((Integer.subrange(0, n-1)->select(i | true)->collect(i | ((lis[x+1][i+1] + lis[i+1][x+1]) / 2))) : A) ; execute ((Integer.subrange(0, n-1)->select(i | true)->collect(i | (lis[x+1][i+1] - A[x+1][i+1]))) : B)) ; for x : A do ( for y : x do ( execute (y)->display()) ; execute (->display()) ; for x : B do ( for y : x do ( execute (y)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import bisect import heapq from bisect import bisect_right from sys import stdin,stdout def get_ints_in_variables(): return map(int,sys.stdin.readline().strip().split()) def get_int(): return int(sys.stdin.readline()) def get_ints_in_list(): return list(map(int,sys.stdin.readline().strip().split())) def get_list_of_list(n): return[list(map(int,sys.stdin.readline().strip().split()))for _ in range(n)] def get_string(): return sys.stdin.readline().strip() def myceil(x,y): return(x+y-1)//y def Solution(arr,n): A=[[0 for _ in range(n)]for _ in range(n)] B=[[0 for _ in range(n)]for _ in range(n)] for i in range(n): for j in range(n): if i==j : A[i][j]=arr[i][j] B[i][j]=0 else : s=(arr[i][j]+arr[j][i])/2 diff=arr[i][j]-s A[i][j]=s A[j][i]=s B[i][j]=diff B[j][i]=-diff if diff>=0 else abs(diff) for itm in A : print(*itm) for itm in B : print(*itm) def main(): n=get_int() arr=get_list_of_list(n) Solution(arr,n) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation get_ints_in_variables() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ); operation get_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation get_ints_in_list() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation get_list_of_list(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )))); operation get_string() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation myceil(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return (x + y - 1) div y; operation Solution(arr : OclAny, n : OclAny) pre: true post: true activity: var A : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)))) ; var B : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (0)))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if i = j then ( A[i+1][j+1] := arr[i+1][j+1] ; B[i+1][j+1] := 0 ) else ( var s : double := (arr[i+1][j+1] + arr[j+1][i+1]) / 2 ; var diff : double := arr[i+1][j+1] - s ; A[i+1][j+1] := s ; A[j+1][i+1] := s ; B[i+1][j+1] := diff ; B[j+1][i+1] := if diff >= 0 then -diff else (diff)->abs() endif ))) ; for itm : A do ( execute ((argument * (test (logical_test (comparison (expr (atom (name itm))))))))->display()) ; for itm : B do ( execute ((argument * (test (logical_test (comparison (expr (atom (name itm))))))))->display()); operation main() pre: true post: true activity: n := get_int() ; arr := get_list_of_list(n) ; Solution(arr, n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ma=lambda : map(int,input().split()) lma=lambda : list(map(int,input().split())) tma=lambda : tuple(map(int,input().split())) ni=lambda : int(input()) yn=lambda fl : print("Yes")if fl else print("No") import collections import math import itertools import heapq as hq ceil=math.ceil a,b=ma() wh="." bl="#" if a>b : a,b=b,a wh,bl=bl,wh area=[[wh]*100 for i in range(100)] def cycle(y,x,f=True): for i in range(y,y+3): for j in range(x,x+3): area[i][j]=bl if f : area[y+1][x+1]=wh def solve(): cnt=0 iy=0 ix=0 while cnt=95 : ix=0 iy+=4 cnt+=1 solve() print(100,100) for ar in area : print("".join(ar)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ma : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lma : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var tma : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ni : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var yn : Function := lambda fl : OclAny in (if fl then ("Yes")->display() else ("No")->display() endif) ; skip ; skip ; skip ; skip ; var ceil : OclAny := ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ma->apply() ; var wh : String := "." ; var bl : String := "#" ; if (a->compareTo(b)) > 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a} ; Sequence{wh,bl} := Sequence{bl,wh} ) else skip ; var area : Sequence := Integer.subrange(0, 100-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ wh }, 100))) ; skip ; skip ; solve() ; execute (100)->display() ; for ar : area do ( execute (StringLib.sumStringsWithSeparator((ar), ""))->display()); operation cycle(y : OclAny, x : OclAny, f : OclAny) pre: true post: true activity: if f->oclIsUndefined() then f := true else skip; for i : Integer.subrange(y, y + 3-1) do ( for j : Integer.subrange(x, x + 3-1) do ( area[i+1][j+1] := bl)) ; if f then ( area[y + 1+1][x + 1+1] := wh ) else skip; operation solve() pre: true post: true activity: var cnt : int := 0 ; var iy : int := 0 ; var ix : int := 0 ; while (cnt->compareTo(b)) < 0 do ( if (cnt + 1->compareTo(a)) < 0 then ( cycle(iy, ix) ) else ( cycle(iy, ix, (argument (test (logical_test (comparison (expr (atom (name f)))))) = (test (logical_test (comparison (expr (atom (name False)))))))) ) ; ix := ix + 4 ; if ix >= 95 then ( ix := 0 ; iy := iy + 4 ) else skip ; cnt := cnt + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=[] for i in range(n): arr1=[int(x)for x in input().split()] arr.append(arr1) dasharr=[[None for j in range(n)]for i in range(n)] for i in range(n): for j in range(n): dasharr[i][j]=arr[j][i] a=[[None for i in range(n)]for i in range(n)] b=[[None for i in range(n)]for i in range(n)] for i in range(n): for j in range(n): a[i][j]=arr[i][j]/2+dasharr[i][j]/2 b[i][j]=arr[i][j]/2-dasharr[i][j]/2 for sub in a : print(*sub) for sub in b : print(*sub) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var arr1 : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((arr1) : arr)) ; var dasharr : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, n-1)->select(j | true)->collect(j | (null)))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( dasharr[i+1][j+1] := arr[j+1][i+1])) ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)))) ; var b : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, n-1)->select(i | true)->collect(i | (null)))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( a[i+1][j+1] := arr[i+1][j+1] / 2 + dasharr[i+1][j+1] / 2 ; b[i+1][j+1] := arr[i+1][j+1] / 2 - dasharr[i+1][j+1] / 2)) ; for sub : a do ( execute ((argument * (test (logical_test (comparison (expr (atom (name sub))))))))->display()) ; for sub : b do ( execute ((argument * (test (logical_test (comparison (expr (atom (name sub))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) a=list(map(int,input().split())) if len(set(a))==1 : print(n) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (Set{}->union((a)))->size() = 1 then ( execute (n)->display() ) else ( execute (1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): m=int(input()) k=list(map(int,input().split())) a=set(k) h=len(a) d=len(k) if h==1 : print(d) else : print("1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Set := Set{}->union((k)) ; var h : int := (a)->size() ; var d : int := (k)->size() ; if h = 1 then ( execute (d)->display() ) else ( execute ("1")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for z in range(t): n=int(input()) a=list(map(int,input().split())) kol=0 for i in range(1,n): if a[0]!=a[i]: kol+=1 if kol>=1 : print(1) else : print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for z : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var kol : int := 0 ; for i : Integer.subrange(1, n-1) do ( if a->first() /= a[i+1] then ( kol := kol + 1 ) else skip) ; if kol >= 1 then ( execute (1)->display() ) else ( execute (n)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout import sys def get_ints(): return map(int,sys.stdin.readline().strip().split()) def get_arr(): return list(map(int,sys.stdin.readline().strip().split())) def get_string(): return sys.stdin.readline().strip() t=int(input()) while t : t-=1 n=int(input()) a=get_arr() x=a[0] cnt=1 check=True for i in range(1,len(a)): if x!=a[i]: check=False if check==False : print(1) else : print(len(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( t := t - 1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := get_arr() ; var x : OclAny := a->first() ; var cnt : int := 1 ; var check : boolean := true ; for i : Integer.subrange(1, (a)->size()-1) do ( if x /= a[i+1] then ( check := false ) else skip) ; if check = false then ( execute (1)->display() ) else ( execute ((a)->size())->display() )); operation get_ints() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ); operation get_arr() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation get_string() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=map(int,input().split()) print(n if len(set(a))==1 else 1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if (Set{}->union((a)))->size() = 1 then n else 1 endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def mod_exp(a : int,b : int,mod : int)->int : a=a % mod res=1 while b>0 : if b & 1 : res=(res*a)% mod a=(a*a)% mod b>>=1 return res def modprimeinverse(a : int,mod : int)->int : return mod_exp(a,mod-2,mod) def comb(x : int,y : int,mod : int)->int : if xunion(MatrixLib.elementwiseMult(Sequence{ 0 }, N)) ; var invfact : Sequence := Sequence{ 1 }->union(MatrixLib.elementwiseMult(Sequence{ 0 }, N)) ; var MOD : int := ("" + ((("1e9")->toReal() + 7)))->toInteger() ; for i : Integer.subrange(1, N-1) do ( fact[i+1] := (i * fact[i - 1+1]) mod MOD ; invfact[i+1] := modprimeinverse(fact[i+1], MOD)) ; var r : Sequence := (sys.stdin.readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : OclAny := (r).next() ; var sums : int := 0 ; res := 1 ; for i : Integer.subrange(0, n-1) do ( a := (r).next() ; sums := sums + a ; res := (res * comb(sums - 1, a - 1, MOD)) mod MOD) ; execute (res)->display(); operation mod_exp(a : int, b : int, mod : int) : int pre: true post: true activity: var a : int := a mod mod ; var res : int := 1 ; while b > 0 do ( if MathLib.bitwiseAnd(b, 1) then ( res := (res * a) mod mod ) else skip ; a := (a * a) mod mod ; b := b div (2->pow(1))) ; return res; operation modprimeinverse(a : int, mod : int) : int pre: true post: true activity: return mod_exp(a, mod - 2, mod); operation comb(x : int, y : int, mod : int) : int pre: true post: true activity: if (x->compareTo(y)) < 0 then ( return 0 ) else ( return ((fact[x+1] * invfact[y+1]) mod mod * invfact[x - y+1]) mod mod ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(0,t): n,k,r,s=map(int,input().split()) m=r % k if m==0 : m=k p=s % k if p==0 : p=k l=[] if p+m-2>k-1 : bl=True j=0 while bl==True : if m+p-k-2-j<0 : break l.append((m+p-k-2-j)*"."+"X"+(2*k+j-m-p+1)*".") j=j+1 for j in range(0,k-len(l)): l.append((k-j-1)*"."+"X"+j*".") else : bl2=True j=0 while bl2==True : if p+m-2-j<0 : break l.append((p+m-2-j)*"."+"X"+(k+1-p-m+j)*".") j=j+1 for j in range(0,k-len(l)): l.append((k-j-1)*"."+"X"+j*".") for j in range(0,n): print((n//k)*l[j % k]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; var r : OclAny := null; var s : OclAny := null; Sequence{n,k,r,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : int := r mod k ; if m = 0 then ( m := k ) else skip ; var p : int := s mod k ; if p = 0 then ( p := k ) else skip ; var l : Sequence := Sequence{} ; if (p + m - 2->compareTo(k - 1)) > 0 then ( var bl : boolean := true ; var j : int := 0 ; while bl = true do ( if m + p - k - 2 - j < 0 then ( break ) else skip ; execute (((m + p - k - 2 - j) * "." + "X" + (2 * k + j - m - p + 1) * ".") : l) ; j := j + 1) ; for j : Integer.subrange(0, k - (l)->size()-1) do ( execute (((k - j - 1) * "." + "X" + j * ".") : l)) ) else ( var bl2 : boolean := true ; j := 0 ; while bl2 = true do ( if p + m - 2 - j < 0 then ( break ) else skip ; execute (((p + m - 2 - j) * "." + "X" + (k + 1 - p - m + j) * ".") : l) ; j := j + 1) ; for j : Integer.subrange(0, k - (l)->size()-1) do ( execute (((k - j - 1) * "." + "X" + j * ".") : l)) ) ; for j : Integer.subrange(0, n-1) do ( execute ((n div k) * l[j mod k+1])->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): n,k,r,c=(int(x)for x in input().split()) remainder=(r+c-2)% k for i in range(n): for j in range(n): if(i+j)% k==remainder : print('X',end='') else : print('.',end='') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; var r : OclAny := null; var c : OclAny := null; Sequence{n,k,r,c} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var remainder : int := (r + c - 2) mod k ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if (i + j) mod k = remainder then ( execute ('X')->display() ) else ( execute ('.')->display() )) ; execute (->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,k,r,c=[int(v)for v in input().split()] r,c=r-1,c-1 for i in range(n): for j in range(n): print("X" if((j-c)% k==(i-r)% k)else ".",end="") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; var r : OclAny := null; var c : OclAny := null; Sequence{n,k,r,c} := input().split()->select(v | true)->collect(v | (("" + ((v)))->toInteger())) ; var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := Sequence{r - 1,c - 1} ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( execute (if ((j - c) mod k = (i - r) mod k) then "X" else "." endif)->display()) ; execute (->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(x): n,k,r,c=x new_r=(r-1)% k new_c=(c-1)% k matrix=[['.']*k for _ in range(k)] matrix[new_r][new_c]='X' row_visited={new_r} col_visited={new_c} for i in range(k): for j in range(k): if i in row_visited : break if j in col_visited : continue matrix[i][j]='X' row_visited.add(i) col_visited.add(j) break res=[] for i in range(k): res.append(''.join(matrix[i])) t=n//k return[res[i]*t for _ in range(t)for i in range(k)] if __name__=='__main__' : n=int(input()) res=[] for i in range(n): res.append(list(map(int,input().split(' ')))) for x in res : ans=solve(x) for i in range(x[0]): print(ans[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; res := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ))) : res)) ; for x : res do ( var ans : OclAny := solve(x) ; for i : Integer.subrange(0, x->first()-1) do ( execute (ans[i+1])->display())) ) else skip; operation solve(x : OclAny) : OclAny pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var r : OclAny := null; var c : OclAny := null; Sequence{n,k,r,c} := x ; var new_r : int := (r - 1) mod k ; var new_c : int := (c - 1) mod k ; var matrix : Sequence := Integer.subrange(0, k-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ '.' }, k))) ; matrix[new_r+1][new_c+1] := 'X' ; var row_visited : Set := Set{ new_r } ; var col_visited : Set := Set{ new_c } ; for i : Integer.subrange(0, k-1) do ( for j : Integer.subrange(0, k-1) do ( if (row_visited)->includes(i) then ( break ) else skip ; if (col_visited)->includes(j) then ( continue ) else skip ; matrix[i+1][j+1] := 'X' ; execute ((i) : row_visited) ; execute ((j) : col_visited) ; break)) ; var res : Sequence := Sequence{} ; for i : Integer.subrange(0, k-1) do ( execute ((StringLib.sumStringsWithSeparator((matrix[i+1]), '')) : res)) ; var t : int := n div k ; return Integer.subrange(0, t-1)->select(_anon; i : Integer.subrange(0, k-1) | true)->collect(_anon; i : Integer.subrange(0, k-1) | (res[i+1] * t)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil A,B=map(int,input().split()) W=52 R1=ceil((A-1)/((W-2)//2)) R2=ceil((B-1)/(W//2)) H=1+R1*2+R2*2 print(H,W) print('#'*(W-1)+'.') A-=1 for i in range(R1): num=min(max(A,0),(W-2)//2) print('#'+'.#'*num+'..'*((W-2)//2-num)+'.') print('#'*(W-1)+'.') A-=(W-2)//2 B-=1 for i in range(R2): num=min(max(B,0),W//2) print('.'*W) print('#.'*num+'..'*(W//2-num)) B-=W//2 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var W : int := 52 ; var R1 : OclAny := ceil((A - 1) / ((W - 2) div 2)) ; var R2 : OclAny := ceil((B - 1) / (W div 2)) ; var H : int := 1 + R1 * 2 + R2 * 2 ; execute (H)->display() ; execute (StringLib.nCopies('#', (W - 1)) + '.')->display() ; A := A - 1 ; for i : Integer.subrange(0, R1-1) do ( var num : OclAny := Set{Set{A, 0}->max(), (W - 2) div 2}->min() ; execute ('#' + StringLib.nCopies('.#', num) + StringLib.nCopies('..', ((W - 2) div 2 - num)) + '.')->display() ; execute (StringLib.nCopies('#', (W - 1)) + '.')->display() ; A := A - (W - 2) div 2) ; B := B - 1 ; for i : Integer.subrange(0, R2-1) do ( num := Set{Set{B, 0}->max(), W div 2}->min() ; execute (StringLib.nCopies('.', W))->display() ; execute (StringLib.nCopies('#.', num) + StringLib.nCopies('..', (W div 2 - num)))->display() ; B := B - W div 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getmatrix(n,k,r,c): r,c=(r-1)% k,(c-1)% k A=[] for i in range(n): B=[] for j in range(n): B.append(0) pass A.append(B) pass for i in range(n//k): for j in range(n//k): for x in range(k): A[(i*k)+r][(j*k)+c]=1 r,c=(r+1)% k,(c+1)% k pass return A pass for _ in range(int(input())): n,k,r,c=map(int,input().split()) A=getmatrix(n,k,r,c) for i in A : for j in i : print('X' if j else '.',end='') pass print() pass pass ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( Sequence{n,k,r,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; A := getmatrix(n, k, r, c) ; for i : A do ( for j : i do ( execute (if j then 'X' else '.' endif)->display() ; skip) ; execute (->display() ; skip) ; skip); operation getmatrix(n : OclAny, k : OclAny, r : OclAny, c : OclAny) : OclAny pre: true post: true activity: Sequence{r,c} := Sequence{(r - 1) mod k,(c - 1) mod k} ; var A : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var B : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( execute ((0) : B) ; skip) ; execute ((B) : A) ; skip) ; for i : Integer.subrange(0, n div k-1) do ( for j : Integer.subrange(0, n div k-1) do ( for x : Integer.subrange(0, k-1) do ( A[(i * k) + r+1][(j * k) + c+1] := 1 ; Sequence{r,c} := Sequence{(r + 1) mod k,(c + 1) mod k})) ; skip) ; return A ; skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(A,B): count=0 for i in range(0,32): if(((A>>i)& 1)!=((B>>i)& 1)): count=count+1 print("Number of different bits :",count) A=12 B=15 solve(A,B) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; A := 12 ; B := 15 ; solve(A, B); operation solve(A : OclAny, B : OclAny) pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, 32-1) do ( if ((MathLib.bitwiseAnd((A /(2->pow(i))), 1)) /= (MathLib.bitwiseAnd((B /(2->pow(i))), 1))) then ( count := count + 1 ) else skip) ; execute ("Number of different bits :")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): isprime=eulerlib.list_primality(999999) def is_circular_prime(n): s=str(n) return all(isprime[int(s[i :]+s[: i])]for i in range(len(s))) ans=sum(1 for i in range(len(isprime))if is_circular_prime(i)) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var isprime : OclAny := eulerlib.list_primality(999999) ; skip ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name isprime)))))))) ))))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (atom (name is_circular_prime)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))))->sum() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def factorize(n): count=0 ; while((n % 2>0)==False): n>>=1 ; count+=1 ; if(count>0): print(2,count); for i in range(3,int(math.sqrt(n))+1): count=0 ; while(n % i==0): count+=1 ; n=int(n/i); if(count>0): print(i,count); i+=2 ; if(n>2): print(n,1); n=1000000000000000000 ; factorize(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 1000000000000000000; ; factorize(n);; operation factorize(n : OclAny) pre: true post: true activity: var count : int := 0; ; while ((n mod 2 > 0) = false) do ( n := n div (2->pow(1)); ; count := count + 1;) ; if (count > 0) then ( execute (2)->display(); ) else skip ; for i : Integer.subrange(3, ("" + (((n)->sqrt())))->toInteger() + 1-1) do ( count := 0; ; while (n mod i = 0) do ( count := count + 1; ; n := ("" + ((n / i)))->toInteger();) ; if (count > 0) then ( execute (i)->display(); ) else skip ; i := i + 2;) ; if (n > 2) then ( execute (n)->display(); ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) d=2 for i in range(t): n=int(input()) m=[] b=n//2 a1=[q for q in range(1,b+1,2)] a2=[q for q in range((b)+((b)% 2)+1,n+1,2)] for j in a1 : m.append(j) a=2 while j*a<=n : m.append(j*a) a*=2 m=m+a2 print(d) for j in range(n): print(m[j],end=" ") print('') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : int := 2 ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : Sequence := Sequence{} ; var b : int := n div 2 ; var a1 : Sequence := Integer.subrange(1, b + 1-1)->select( $x | ($x - 1) mod 2 = 0 )->select(q | true)->collect(q | (q)) ; var a2 : Sequence := Integer.subrange((b) + ((b) mod 2) + 1, n + 1-1)->select( $x | ($x - (b) + ((b) mod 2) + 1) mod 2 = 0 )->select(q | true)->collect(q | (q)) ; for j : a1 do ( execute ((j) : m) ; var a : int := 2 ; while (j * a->compareTo(n)) <= 0 do ( execute ((j * a) : m) ; a := a * 2)) ; m := m->union(a2) ; execute (d)->display() ; for j : Integer.subrange(0, n-1) do ( execute (m[j+1])->display()) ; execute ('')->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from typing import List def ways_to_draw_balls_from_bag(k : int,cs : List[int])->int : size=min(1005,sum(cs)) mod=int(1e9)+7 per=[[0 for i in range(size)]for j in range(size)] for i in range(size): per[i][0]=1 per[i][i]=1 for i in range(1,size): for j in range(1,i): per[i][j]=(per[i-1][j-1]+per[i-1][j])% mod answer=1 total=0 for c in cs : total+=c way=per[total-1][c-1] answer=(answer*way)% mod return answer t=int(input()) a=[] for i in range(t): a.append(int(input())) print(ways_to_draw_balls_from_bag(t,a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : a)) ; execute (ways_to_draw_balls_from_bag(t, a))->display(); operation ways_to_draw_balls_from_bag(k : int, cs : List[OclType["int"]+1]) : int pre: true post: true activity: var size : OclAny := Set{1005, (cs)->sum()}->min() ; var mod : int := ("" + ((("1e9")->toReal())))->toInteger() + 7 ; var per : Sequence := Integer.subrange(0, size-1)->select(j | true)->collect(j | (Integer.subrange(0, size-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, size-1) do ( per[i+1]->first() := 1 ; per[i+1][i+1] := 1) ; for i : Integer.subrange(1, size-1) do ( for j : Integer.subrange(1, i-1) do ( per[i+1][j+1] := (per[i - 1+1][j - 1+1] + per[i - 1+1][j+1]) mod mod)) ; var answer : int := 1 ; var total : int := 0 ; for c : cs do ( total := total + c ; var way : OclAny := per[total - 1+1][c - 1+1] ; answer := (answer * way) mod mod) ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) print(2) for i in range(1,n+1,2): num=i while(num<=n): print(str(num),end=" ") num*=2 print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (2)->display() ; for i : Integer.subrange(1, n + 1-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( var num : OclAny := i ; while ((num->compareTo(n)) <= 0) do ( execute (("" + ((num))))->display() ; num := num * 2)) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) z=[0]*(n+1) r=[] for i in range(1,n+1): if z[i]==0 : j=i while j<=n : r.append(j) z[j]=1 j*=2 print(2) print(*r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var z : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var r : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( if z[i+1] = 0 then ( var j : OclAny := i ; while (j->compareTo(n)) <= 0 do ( execute ((j) : r) ; z[j+1] := 1 ; j := j * 2) ) else skip) ; execute (2)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name r))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for Pythonic__Python in range(int(input())): n=int(input()) d={} ans=[1,2] for i in range(1,n+1): d[i]=True d[2]=False i=2 j=i while i<=n : if i==n and d[i]: ans.append(i) break if d[i]: ans.append(i) d[i]=False if 2*i<=n and d[2*i]: ans.append(2*i) d[2*i]=False i=2*i else : i=j+1 j=i print(2) print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for Pythonic__Python : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : OclAny := Set{} ; var ans : Sequence := Sequence{1}->union(Sequence{ 2 }) ; for i : Integer.subrange(1, n + 1-1) do ( d[i+1] := true) ; d[2+1] := false ; var i : int := 2 ; var j : int := i ; while (i->compareTo(n)) <= 0 do ( if i = n & d[i+1] then ( execute ((i) : ans) ; break ) else skip ; if d[i+1] then ( execute ((i) : ans) ; d[i+1] := false ) else skip ; if (2 * i->compareTo(n)) <= 0 & d[2 * i+1] then ( execute ((2 * i) : ans) ; d[2 * i+1] := false ; i := 2 * i ) else ( i := j + 1 ; j := i )) ; execute (2)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) print(2) for i in range(1,n+1,2): while i<=n : print(i,end=' ') i*=2 print("",end="\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (2)->display() ; for i : Integer.subrange(1, n + 1-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( while (i->compareTo(n)) <= 0 do ( execute (i)->display() ; i := i * 2)) ; execute ("")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() s=sorted(set(map(int,input().split()))) c=m=0 d=[] for b in s : d+=[c]*(b-c) c=b for b in s[-1 : :-1]: if bunion(((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->sort() ; var c : OclAny := 0; var m : int := 0 ; var d : Sequence := Sequence{} ; for b : s do ( d := d + MatrixLib.elementwiseMult(Sequence{ c }, (b - c)) ; c := b) ; for b : s(subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if (b->compareTo(m + 2)) < 0 then ( break ) else skip ; m := Set{m, c mod b, (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name a))) % (expr (atom (name b))))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (number (integer 2)))) * (expr (atom (name b)))) - (expr (atom (number (integer 1)))))))) : (sliceop : (test (logical_test (comparison (expr (atom (name b))))))))) ]))))))) )))))))}->max()) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def makelist(n,m): return[['.' for _ in range(m)]for _ in range(n)] a,b=map(int,input().split()) N=100 h=N//2 d=makelist(N,N) for y in range(h): for x in range(N): d[y][x]="#" a,b=a-1,b-1 for y in range(h): for x in range(N): if a==0 : break if y % 2==0 and x % 2==0 : a-=1 d[y][x]="." for y in reversed(range(h,N)): for x in range(N): if b==0 : break if y % 2==1 and x % 2==1 : b-=1 d[y][x]="#" print(N,N) for y in range(N): print("".join(d[y])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var N : int := 100 ; var h : int := N div 2 ; var d : OclAny := makelist(N, N) ; for y : Integer.subrange(0, h-1) do ( for x : Integer.subrange(0, N-1) do ( d[y+1][x+1] := "#")) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{a - 1,b - 1} ; for y : Integer.subrange(0, h-1) do ( for x : Integer.subrange(0, N-1) do ( if a = 0 then ( break ) else skip ; if y mod 2 = 0 & x mod 2 = 0 then ( a := a - 1 ; d[y+1][x+1] := "." ) else skip)) ; for y : (Integer.subrange(h, N-1))->reverse() do ( for x : Integer.subrange(0, N-1) do ( if b = 0 then ( break ) else skip ; if y mod 2 = 1 & x mod 2 = 1 then ( b := b - 1 ; d[y+1][x+1] := "#" ) else skip)) ; execute (N)->display() ; for y : Integer.subrange(0, N-1) do ( execute (StringLib.sumStringsWithSeparator((d[y+1]), ""))->display()); operation makelist(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | ('.')))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect n=int(input()) arr=set(map(int,input().split())) ls=sorted(arr) ans=0 mx=max(arr) for c in ls[: :-1]: if c-1toInteger() ; var arr : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ls : Sequence := arr->sort() ; var ans : int := 0 ; var mx : OclAny := (arr)->max() ; for c : ls(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if (c - 1->compareTo(ans)) < 0 then ( break ) else skip ; var kc : OclAny := c + c ; while (kc->compareTo(2 * mx)) <= 0 do ( var ind : OclAny := bisect.bisect_left(ls, kc) ; ans := Set{ans, ls[ind - 1+1] mod c}->max() ; kc := kc + c)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect n=int(input()) a=sorted(set(map(int,input().split()))) ans=0 mx=max(a) for x in a[: :-1]: if x-1toInteger() ; var a : Sequence := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->sort() ; var ans : int := 0 ; var mx : OclAny := (a)->max() ; for x : a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if (x - 1->compareTo(ans)) < 0 then ( break ) else skip ; var kx : double := 2 * x ; while (kx->compareTo(2 * mx)) <= 0 do ( var index : OclAny := bisect.bisect_left(a, kx) ; ans := Set{ans, a[index - 1+1] mod x}->max() ; kx := kx + x)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cntRotations(s,n): str=s+s ; pre=[0]*(2*n); for i in range(2*n): if(i!=0): pre[i]+=pre[i-1]; if(str[i]=='a' or str[i]=='e' or str[i]=='i' or str[i]=='o' or str[i]=='u'): pre[i]+=1 ; ans=0 ; for i in range(n-1,2*n-1,1): r=i ; l=i-n ; x1=pre[r]; if(l>=0): x1-=pre[l]; r=(int)(i-n/2); left=pre[r]; if(l>=0): left-=pre[l]; right=x1-left ; if(left>right): ans+=1 ; return ans ; s="abecidft" ; n=len(s); print(cntRotations(s,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := "abecidft"; ; n := (s)->size(); ; execute (cntRotations(s, n))->display();; operation cntRotations(s : OclAny, n : OclAny) pre: true post: true activity: var OclType["String"] : OclAny := s + s; ; var pre : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * n)); ; for i : Integer.subrange(0, 2 * n-1) do ( if (i /= 0) then ( pre[i+1] := pre[i+1] + pre[i - 1+1]; ) else skip ; if (("" + ([i+1])) = 'a' or ("" + ([i+1])) = 'e' or ("" + ([i+1])) = 'i' or ("" + ([i+1])) = 'o' or ("" + ([i+1])) = 'u') then ( pre[i+1] := pre[i+1] + 1; ) else skip) ; var ans : int := 0; ; for i : Integer.subrange(n - 1, 2 * n - 1-1)->select( $x | ($x - n - 1) mod 1 = 0 ) do ( var r : OclAny := i; var l : double := i - n; ; var x1 : OclAny := pre[r+1]; ; if (l >= 0) then ( x1 := x1 - pre[l+1]; ) else skip ; r := (OclType["int"])(i - n / 2); ; var left : OclAny := pre[r+1]; ; if (l >= 0) then ( left := left - pre[l+1]; ) else skip ; var right : double := x1 - left; ; if ((left->compareTo(right)) > 0) then ( ans := ans + 1; ) else skip) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def longestPrefixSuffix(s): n=len(s) lps=[0]*n l=0 i=1 while(in/2): return n//2 else : return res s="abcab" print(longestPrefixSuffix(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := "abcab" ; execute (longestPrefixSuffix(s))->display(); operation longestPrefixSuffix(s : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; var lps : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var l : int := 0 ; var i : int := 1 ; while ((i->compareTo(n)) < 0) do ( if (s[i+1] = s[l+1]) then ( l := l + 1 ; lps[i+1] := l ; i := i + 1 ) else ( if (l /= 0) then ( l := lps[l - 1+1] ) else ( lps[i+1] := 0 ; i := i + 1 ) )) ; var res : OclAny := lps[n - 1+1] ; if ((res->compareTo(n / 2)) > 0) then ( return n div 2 ) else ( return res ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- PI=3.14159265 def length_rope(r): return((2*PI*r)+6*r) r=7 print(length_rope(r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var PI : double := 3.14159265 ; skip ; r := 7 ; execute (length_rope(r))->display(); operation length_rope(r : OclAny) : OclAny pre: true post: true activity: return ((2 * PI * r) + 6 * r); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMaxAverage(arr,n,k): if(k>n): return-1 sum=arr[0] for i in range(1,k): sum+=arr[i] max_sum=sum max_end=k-1 for i in range(k,n): sum=sum+arr[i]-arr[i-k] if(sum>max_sum): max_sum=sum max_end=i return max_end-k+1 arr=[1,12,-5,-6,50,3] k=4 n=len(arr) print("The maximum average subarray of length",k,"begins at index",findMaxAverage(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{12}->union(Sequence{-5}->union(Sequence{-6}->union(Sequence{50}->union(Sequence{ 3 }))))) ; k := 4 ; n := (arr)->size() ; execute ("The maximum average subarray of length")->display(); operation findMaxAverage(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if ((k->compareTo(n)) > 0) then ( return -1 ) else skip ; var sum : OclAny := arr->first() ; for i : Integer.subrange(1, k-1) do ( sum := sum + arr[i+1]) ; var max_sum : OclAny := sum ; var max_end : double := k - 1 ; for i : Integer.subrange(k, n-1) do ( sum := sum + arr[i+1] - arr[i - k+1] ; if ((sum->compareTo(max_sum)) > 0) then ( max_sum := sum ; max_end := i ) else skip) ; return max_end - k + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMaxAverage(arr,n,k): if k>n : return-1 csum=[0]*n csum[0]=arr[0] for i in range(1,n): csum[i]=csum[i-1]+arr[i]; max_sum=csum[k-1] max_end=k-1 for i in range(k,n): curr_sum=csum[i]-csum[i-k] if curr_sum>max_sum : max_sum=curr_sum max_end=i return max_end-k+1 arr=[1,12,-5,-6,50,3] k=4 n=len(arr) print("The maximum average subarray of length",k,"begins at index",findMaxAverage(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{12}->union(Sequence{-5}->union(Sequence{-6}->union(Sequence{50}->union(Sequence{ 3 }))))) ; k := 4 ; n := (arr)->size() ; execute ("The maximum average subarray of length")->display(); operation findMaxAverage(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (k->compareTo(n)) > 0 then ( return -1 ) else skip ; var csum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; csum->first() := arr->first() ; for i : Integer.subrange(1, n-1) do ( csum[i+1] := csum[i - 1+1] + arr[i+1];) ; var max_sum : OclAny := csum[k - 1+1] ; var max_end : double := k - 1 ; for i : Integer.subrange(k, n-1) do ( var curr_sum : double := csum[i+1] - csum[i - k+1] ; if (curr_sum->compareTo(max_sum)) > 0 then ( max_sum := curr_sum ; max_end := i ) else skip) ; return max_end - k + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def FindPoints(n): v=[]; v.append([0,0]); v.append([0,n]); v.append([n,0]); v.append([n,n]); if(n % 2==0): v.append([n//2,n//2]); return v ; if __name__=="__main__" : N=8 ; v=FindPoints(N); for element in v : print("(",element[0],",",element[1],")",end=" "); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var N : int := 8; ; v := FindPoints(N); ; for element : v do ( execute ("(")->display();) ) else skip; operation FindPoints(n : OclAny) pre: true post: true activity: var v : Sequence := Sequence{}; ; execute ((Sequence{0}->union(Sequence{ 0 })) : v); ; execute ((Sequence{0}->union(Sequence{ n })) : v); ; execute ((Sequence{n}->union(Sequence{ 0 })) : v); ; execute ((Sequence{n}->union(Sequence{ n })) : v); ; if (n mod 2 = 0) then ( execute ((Sequence{n div 2}->union(Sequence{ n div 2 })) : v); ) else skip ; return v;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def areDistinct(arr): n=len(arr) s=set() for i in range(0,n): s.add(arr[i]) return(len(s)==len(arr)) arr=[1,2,3,2] if(areDistinct(arr)): print("All Elements are Distinct") else : print("Not all Elements are Distinct") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 2 }))) ; if (areDistinct(arr)) then ( execute ("All Elements are Distinct")->display() ) else ( execute ("Not all Elements are Distinct")->display() ); operation areDistinct(arr : OclAny) : OclAny pre: true post: true activity: var n : int := (arr)->size() ; var s : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( execute ((arr[i+1]) : s)) ; return ((s)->size() = (arr)->size()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxProduct(arr,n,p): minVal=arr[0] maxVal=arr[0] maxProduct=arr[0] for i in range(1,n): if(arr[i]<0): maxVal,minVal=minVal,maxVal maxVal=max(arr[i],maxVal*arr[i]) minVal=min(arr[i],minVal*arr[i]) if(minVal==p or maxVal==p): return True maxProduct=max(maxProduct,maxVal) return False if __name__=="__main__" : arr=[1,2,-5,-4] product=-10 n=len(arr) if(maxProduct(arr,n,product)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{-5}->union(Sequence{ -4 }))) ; var product : int := -10 ; n := (arr)->size() ; if (maxProduct(arr, n, product)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; operation maxProduct(arr : OclAny, n : OclAny, p : OclAny) : OclAny pre: true post: true activity: var minVal : OclAny := arr->first() ; var maxVal : OclAny := arr->first() ; var maxProduct : OclAny := arr->first() ; for i : Integer.subrange(1, n-1) do ( if (arr[i+1] < 0) then ( Sequence{maxVal,minVal} := Sequence{minVal,maxVal} ) else skip ; maxVal := Set{arr[i+1], maxVal * arr[i+1]}->max() ; minVal := Set{arr[i+1], minVal * arr[i+1]}->min() ; if (minVal = p or maxVal = p) then ( return true ) else skip ; maxProduct := Set{maxProduct, maxVal}->max()) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printCombinations(a,n,m): for i in range(0,(1<0): sum+=a[j] else : sum+=(-1*a[j]) num=num>>1 if(sum % m==0): num=1<<(n-1) for j in range(0,n): if((i & num)>0): print("+",a[j],end="",sep="") else : print("-",a[j],end="",sep="") num=num>>1 print("") a=[3,5,6,8] n=len(a) m=5 printCombinations(a,n,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{3}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 8 }))) ; n := (a)->size() ; m := 5 ; printCombinations(a, n, m); operation printCombinations(a : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: for i : Integer.subrange(0, (1 * (2->pow(n)))-1) do ( var sum : int := 0 ; var num : int := 1 * (2->pow((n - 1))) ; for j : Integer.subrange(0, n-1) do ( if ((MathLib.bitwiseAnd(i, num)) > 0) then ( sum := sum + a[j+1] ) else ( sum := sum + (-1 * a[j+1]) ) ; num := num /(2->pow(1))) ; if (sum mod m = 0) then ( num := 1 * (2->pow((n - 1))) ; for j : Integer.subrange(0, n-1) do ( if ((MathLib.bitwiseAnd(i, num)) > 0) then ( execute ("+")->display() ) else ( execute ("-")->display() ) ; num := num /(2->pow(1))) ; execute ("")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B=[int(x)for x in input().split()] K=50 h,w=2*K,2*K cntA=A-1 cntB=B-1 print(h,w) for i in range(h): pr='' if(i0): if((i % 2==0 and j % 2==0)): pr+='.' cntA-=1 else : pr+='#' else : pr+='#' else : pr='' for j in range(w): if(cntB>0 and i>K): if((i % 2==0 and j % 2==0)): pr+='#' cntB-=1 else : pr+='.' else : pr+='.' print(pr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var K : int := 50 ; var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := Sequence{2 * K,2 * K} ; var cntA : double := A - 1 ; var cntB : double := B - 1 ; execute (h)->display() ; for i : Integer.subrange(0, h-1) do ( var pr : String := '' ; if ((i->compareTo(K)) < 0) then ( for j : Integer.subrange(0, w-1) do ( if (cntA > 0) then ( if ((i mod 2 = 0 & j mod 2 = 0)) then ( pr := pr + '.' ; cntA := cntA - 1 ) else ( pr := pr + '#' ) ) else ( pr := pr + '#' )) ) else ( pr := '' ; for j : Integer.subrange(0, w-1) do ( if (cntB > 0 & (i->compareTo(K)) > 0) then ( if ((i mod 2 = 0 & j mod 2 = 0)) then ( pr := pr + '#' ; cntB := cntB - 1 ) else ( pr := pr + '.' ) ) else ( pr := pr + '.' )) ) ; execute (pr)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def bfs(bldg): dict={} que=deque([(bldg[0][0],0,0),(bldg[1][0],1,0)]) while len(que): h,b,t=que.popleft() try : if dict[(h,b)]<=t : continue except KeyError : dict[(h,b)]=t if h==len(bldg[0])-3 : return t t+=1 if 100toInteger() ; if n = 0 then ( break ) else skip ; execute (bfs(Sequence{building()}->union(Sequence{ building() })))->display()); operation bfs(bldg : OclAny) : OclAny pre: true post: true activity: var OclType["Map"] : OclAny := Set{} ; var que : Sequence := (Sequence{Sequence{bldg->first()->first(), 0, 0}}->union(Sequence{ Sequence{bldg[1+1]->first(), 1, 0} })) ; while (que)->size() do ( var h : OclAny := null; var b : OclAny := null; var t : OclAny := null; Sequence{h,b,t} := que->first() ; que := que->tail() ; try ( if ((arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name h)))))) , (test (logical_test (comparison (expr (atom (name b))))))) )))))))) ])->compareTo(t)) <= 0 then ( continue ) else skip) (except_clause except (test (logical_test (comparison (expr (atom (name KeyError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dict)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name h)))))) , (test (logical_test (comparison (expr (atom (name b))))))) )))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name t)))))))))))))) ; if h = (bldg->first())->size() - 3 then ( return t ) else skip ; t := t + 1 ; if 100 < t then ( break ) else skip ; execute ((Sequence{bldg[MathLib.bitwiseXor(b, 1)+1][h + 2+1], MathLib.bitwiseXor(b, 1), t}) : que)) ; return 'NA'; operation building() : OclAny pre: true post: true activity: bldg := f.readLine().split()->union(Sequence{'2'}->union(Sequence{ '2' })) ; var scaffold : int := 0 ; for i : Integer.subrange(0, (bldg)->size()-1) do ( if '2' = bldg[i+1] then ( bldg[i+1] := scaffold ) else ( scaffold := i ) ; if '0' = bldg[i+1] then ( bldg[i+1] := i ) else skip) ; scaffold := null ; for i : (Integer.subrange(0, (bldg)->size()-1))->reverse() do ( if '1' = bldg[i+1] then ( if scaffold <>= null then ( scaffold := i ) else skip ; bldg[i+1] := scaffold ) else ( scaffold := null )) ; return bldg; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def fix(alst,blst,floar,buil,n): if buil==0 : lst=alst else : lst=blst if lst[floar]==0 : return floar if lst[floar]==1 : while floar+1=n : break to=fix(alst,blst,floar+i,next_buil,n) if to==n-1 : print(total+1) return if(to,next_buil)not in dic : dic[(to,next_buil)]=total+1 que.append((total+1,to,next_buil)) print("NA") while True : n=int(input()) if n==0 : break alst=list(map(int,input().split())) blst=list(map(int,input().split())) search(alst,blst,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; alst := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; blst := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; search(alst, blst, n)); operation fix(alst : OclAny, blst : OclAny, floar : OclAny, buil : OclAny, n : OclAny) : OclAny pre: true post: true activity: if buil = 0 then ( var lst : OclAny := alst ) else ( lst := blst ) ; if lst[floar+1] = 0 then ( return floar ) else skip ; if lst[floar+1] = 1 then ( while (floar + 1->compareTo(n)) < 0 & lst[floar + 1+1] = 1 do ( floar := floar + 1) ; return floar ) else skip ; if lst[floar+1] = 2 then ( while lst[floar+1] = 2 do ( floar := floar - 1) ; return floar ) else skip; operation search(alst : OclAny, blst : OclAny, n : OclAny) pre: true post: true activity: var que : Sequence := () ; var init_floar_a : OclAny := fix(alst, blst, 0, 0, n) ; var init_floar_b : OclAny := fix(alst, blst, 0, 1, n) ; if (Sequence{init_floar_a, init_floar_b})->includes(n - 1) then ( execute (0)->display() ; return ) else skip ; execute ((Sequence{0, init_floar_a, 0}) : que) ; execute ((Sequence{0, init_floar_b, 1}) : que) ; var dic : OclAny := Set{} ; dic[Sequence{0, init_floar_a}+1] := 0 ; dic[Sequence{0, init_floar_b}+1] := 0 ; while que do ( var total : OclAny := null; Sequence{total,floar,buil} := que->first() ; que := que->tail() ; var next_buil : int := (buil + 1) mod 2 ; for i : Integer.subrange(0, 3-1) do ( if (floar + i->compareTo(n)) >= 0 then ( break ) else skip ; var to : OclAny := fix(alst, blst, floar + i, next_buil, n) ; if to = n - 1 then ( execute (total + 1)->display() ; return ) else skip ; if (dic)->excludes(Sequence{to, next_buil}) then ( dic[Sequence{to, next_buil}+1] := total + 1 ; execute ((Sequence{total + 1, to, next_buil}) : que) ) else skip)) ; execute ("NA")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if n==0 : break a=[int(input()),1] for i in range(n-1): b=int(input()) if a[-2]==b : a[-1]+=1 if i & 1 and a[-2]!=b : a+=[b]+[1] elif a[-2]!=b : if len(a)>2 : a[-3]+=a[-1]+1 a=a[:-2] else : a[-2]=b a[-1]+=1 print(sum(a[2*i+1]for i,x in enumerate(a[: : 2])if x==0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var a : Sequence := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger()}->union(Sequence{ 1 }) ; for i : Integer.subrange(0, n - 1-1) do ( var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if a->front()->last() = b then ( a->last() := a->last() + 1 ) else skip ; if MathLib.bitwiseAnd(i, 1) & a->front()->last() /= b then ( a := a + Sequence{ b }->union(Sequence{ 1 }) ) else (if a->front()->last() /= b then ( if (a)->size() > 2 then ( a->reverse()->at(-(-3)) := a->reverse()->at(-(-3)) + a->last() + 1 ; a := a->front()->front() ) else ( a->front()->last() := b ; a->last() := a->last() + 1 ) ) else skip)) ; execute (((argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (number (integer 2)))) * (expr (atom (name i)))) + (expr (atom (number (integer 1)))))))))) ])))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))) ])))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name x)))) == (comparison (expr (atom (number (integer 0))))))))))))->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reverseDigits(num): rev_num=0 ; while(num>0): rev_num=rev_num*10+num % 10 num=num//10 return rev_num def isPalindrome(n): rev_n=reverseDigits(n); if(rev_n==n): return 1 else : return 0 if __name__=="__main__" : n=4562 if isPalindrome(n)==1 : print("Is",n,"a Palindrome number?->",True) else : print("Is",n,"a Palindrome number?->",False) n=2002 if isPalindrome(n)==1 : print("Is",n,"a Palindrome number?->",True) else : print("Is",n,"a Palindrome number?->",False) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 4562 ; if isPalindrome(n) = 1 then ( execute ("Is")->display() ) else ( execute ("Is")->display() ) ; n := 2002 ; if isPalindrome(n) = 1 then ( execute ("Is")->display() ) else ( execute ("Is")->display() ) ) else skip; operation reverseDigits(num : OclAny) : OclAny pre: true post: true activity: var rev_num : int := 0; ; while (num > 0) do ( rev_num := rev_num * 10 + num mod 10 ; num := num div 10) ; return rev_num; operation isPalindrome(n : OclAny) : OclAny pre: true post: true activity: var rev_n : OclAny := reverseDigits(n); ; if (rev_n = n) then ( return 1 ) else ( return 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy from test.support import _MemoryWatchdog BIG_NUM=2000000000 HUGE_NUM=99999999999999999 MOD=1000000007 EPS=0.000000001 sys.setrecursionlimit(100000) class Info : def __init__(self,arg_color,arg_length): self.color=arg_color self.length=arg_length while True : N=int(input()) if N==0 : break S=[] tmp=int(input()) S.append(Info(tmp,1)) for i in range(1,N): tmp=int(input()) if i % 2==0 : if tmp==S[len(S)-1].color : S[len(S)-1].length+=1 else : S.append(Info(tmp,1)) continue if tmp==S[len(S)-1].color : S[len(S)-1].length+=1 else : tmp_len=S[len(S)-1].length S.pop() if len(S)==0 : S.append(Info(tmp,tmp_len+1)) else : S[len(S)-1].length+=tmp_len+1 ans=0 for i in range(len(S)): if S[i].color==0 : ans+=S[i].length print("%d" %(ans)) ------------------------------------------------------------ OCL File: --------- class Info { static operation newInfo() : Info pre: true post: Info->exists( _x | result = _x ); attribute color : OclAny := arg_color; attribute length : OclAny := arg_length; operation initialise(arg_color : OclAny,arg_length : OclAny) : Info pre: true post: true activity: self.color := arg_color ; self.length := arg_length; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var HUGE_NUM : int := 99999999999999999 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; sys.setrecursionlimit(100000) ; skip ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var S : Sequence := Sequence{} ; var tmp : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (((Info.newInfo()).initialise(tmp, 1)) : S) ; for i : Integer.subrange(1, N-1) do ( tmp := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if i mod 2 = 0 then ( if tmp = S[(S)->size() - 1+1].color then ( S[(S)->size() - 1+1].length := S[(S)->size() - 1+1].length + 1 ) else ( execute (((Info.newInfo()).initialise(tmp, 1)) : S) ) ; continue ) else skip ; if tmp = S[(S)->size() - 1+1].color then ( S[(S)->size() - 1+1].length := S[(S)->size() - 1+1].length + 1 ) else ( var tmp_len : OclAny := S[(S)->size() - 1+1].length ; S := S->front() ; if (S)->size() = 0 then ( execute (((Info.newInfo()).initialise(tmp, tmp_len + 1)) : S) ) else ( S[(S)->size() - 1+1].length := S[(S)->size() - 1+1].length + tmp_len + 1 ) )) ; var ans : int := 0 ; for i : Integer.subrange(0, (S)->size()-1) do ( if S[i+1].color = 0 then ( ans := ans + S[i+1].length ) else skip) ; execute (StringLib.format("%d",(ans)))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if not n : break count=0 flag=-1 lst=[0] for i in range(n): a=int(input()) if flag==a : lst[-1]+=1 else : if i % 2==0 : lst.append(1) flag=a else : if len(lst)==1 : lst[-1]+=1 flag=a elif len(lst)>=2 : lst.append(lst.pop()+lst.pop()+1) flag=a ans=0 if flag==0 : for i in range(-1,len(lst)*(-1)-1,-2): ans+=lst[i] elif flag==1 : for i in range(-2,len(lst)*(-1)-1,-2): ans+=lst[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(n) then ( break ) else skip ; var count : int := 0 ; var flag : int := -1 ; var lst : Sequence := Sequence{ 0 } ; for i : Integer.subrange(0, n-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if flag = a then ( lst->last() := lst->last() + 1 ) else ( if i mod 2 = 0 then ( execute ((1) : lst) ; flag := a ) else ( if (lst)->size() = 1 then ( lst->last() := lst->last() + 1 ; flag := a ) else (if (lst)->size() >= 2 then ( execute ((lst->last() + lst->last() + 1) : lst) ; flag := a ) else skip) ) )) ; var ans : int := 0 ; if flag = 0 then ( for i : Integer.subrange(-1, (lst)->size() * (-1) - 1-1)->select( $x | ($x - -1) mod -2 = 0 ) do ( ans := ans + lst[i+1]) ) else (if flag = 1 then ( for i : Integer.subrange(-2, (lst)->size() * (-1) - 1-1)->select( $x | ($x - -2) mod -2 = 0 ) do ( ans := ans + lst[i+1]) ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break com=[int(input())for i in range(n)] seq=[1] isW=com[0]==0 stW=isW for i in range(1,n): if i % 2!=0 : if len(seq)!=1 : if(isW and com[i]==1)or(not isW and com[i]==0): seq[len(seq)-2]+=seq.pop()+1 else : seq[len(seq)-1]+=1 else : seq[0]+=1 if(isW and com[i]==1)or(not isW and com[i]==0): stW=not stW isW=com[i]==0 else : if isW : if com[i]==0 : seq[len(seq)-1]+=1 else : seq.append(1) isW=False else : if com[i]==0 : seq.append(1) isW=True else : seq[len(seq)-1]+=1 total=0 if stW : total=sum(seq[0 : : 2]) else : total=sum(seq[1 : : 2]) print(total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var com : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var seq : Sequence := Sequence{ 1 } ; var isW : boolean := com->first() = 0 ; var stW : OclAny := isW ; for i : Integer.subrange(1, n-1) do ( if i mod 2 /= 0 then ( if (seq)->size() /= 1 then ( if (isW & com[i+1] = 1) or (not(isW) & com[i+1] = 0) then ( seq[(seq)->size() - 2+1] := seq[(seq)->size() - 2+1] + seq->last() + 1 ) else ( seq[(seq)->size() - 1+1] := seq[(seq)->size() - 1+1] + 1 ) ) else ( seq->first() := seq->first() + 1 ; if (isW & com[i+1] = 1) or (not(isW) & com[i+1] = 0) then ( stW := not(stW) ) else skip ) ; isW := com[i+1] = 0 ) else ( if isW then ( if com[i+1] = 0 then ( seq[(seq)->size() - 1+1] := seq[(seq)->size() - 1+1] + 1 ) else ( execute ((1) : seq) ; isW := false ) ) else ( if com[i+1] = 0 then ( execute ((1) : seq) ; isW := true ) else ( seq[(seq)->size() - 1+1] := seq[(seq)->size() - 1+1] + 1 ) ) )) ; var total : int := 0 ; if stW then ( total := (seq(subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->sum() ) else ( total := (seq(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->sum() ) ; execute (total)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : N=int(input()) if N==0 : break st=[] last=None for i in range(N): s=int(input()) if last is None : last=[1,s] st.append(last) continue if last[1]==s : last[0]+=1 else : if i % 2 : P=st.pop() if st : last=st[-1] last[0]+=P[0]+1 else : last=[P[0]+1,s] st.append(last) else : last=[1,s] st.append(last) ans=0 for s,c in st : if c==0 : ans+=s print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var st : Sequence := Sequence{} ; var last : OclAny := null ; for i : Integer.subrange(0, N-1) do ( var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if last <>= null then ( last := Sequence{1}->union(Sequence{ s }) ; execute ((last) : st) ; continue ) else skip ; if last[1+1] = s then ( last->first() := last->first() + 1 ) else ( if i mod 2 then ( var P : OclAny := st->last() ; st := st->front() ; if st then ( last := st->last() ; last->first() := last->first() + P->first() + 1 ) else ( last := Sequence{P->first() + 1}->union(Sequence{ s }) ; execute ((last) : st) ) ) else ( last := Sequence{1}->union(Sequence{ s }) ; execute ((last) : st) ) )) ; var ans : int := 0 ; for _tuple : st do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if c = 0 then ( ans := ans + s ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) def s(a): r=0 while a>0 : r+=a % 10 a//=10 return r def d(a,b): r=0 for i in range(6): if a % 10!=b % 10 : r+=1 a//=10 b//=10 return r c=6 for i in range(1000000): if s(i % 1000)==s(i//1000): c=min(c,d(x,i)) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; skip ; var c : int := 6 ; for i : Integer.subrange(0, 1000000-1) do ( if s(i mod 1000) = s(i div 1000) then ( c := Set{c, d(x, i)}->min() ) else skip) ; execute (c)->display(); operation s(a : OclAny) : OclAny pre: true post: true activity: var r : int := 0 ; while a > 0 do ( r := r + a mod 10 ; a := a div 10) ; return r; operation d(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: r := 0 ; for i : Integer.subrange(0, 6-1) do ( if a mod 10 /= b mod 10 then ( r := r + 1 ) else skip ; a := a div 10 ; b := b div 10) ; return r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from bisect import bisect_left as lb from bisect import bisect_right as rb from collections import deque from queue import PriorityQueue as pq from math import gcd input_=lambda : sys.stdin.readline().strip("\n") ii=lambda : int(input_()) il=lambda : list(map(int,input_().split())) ilf=lambda : list(map(float,input_().split())) lii=lambda : list(map(int,list(ip()))) ip=lambda : input_() fi=lambda : float(input_()) ap=lambda ab,bc,cd : ab[bc].append(cd) li=lambda : list(input_()) pr=lambda x : print(x) prinT=lambda x : print(x) f=lambda : sys.stdout.flush() inv=lambda x : pow(x,mod-2,mod) dx=[0,0,1,-1] dy=[1,-1,0,0] mod=10**9+7 mod1=998244353 s=list(ip()) s=[int(i)for i in s] a=s[: 3] b=s[3 :] if(sum(a)>sum(b)): b,a=a,b t=sum(b)-sum(a) if(t==0): print(0) exit(0) a=[9-i for i in a] a=a+b a.sort(reverse=True) if(a[0]>=t): print(1) elif(a[0]+a[1]>=t): print(2) else : print(3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var input_ : Function := lambda $$ : OclAny in (sys.stdin.readLine()->trim()) ; var ii : Function := lambda $$ : OclAny in (("" + ((input_->apply())))->toInteger()) ; var il : Function := lambda $$ : OclAny in (((input_->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ilf : Function := lambda $$ : OclAny in (((input_->apply().split())->collect( _x | (OclType["double"])->apply(_x) ))) ; var lii : Function := lambda $$ : OclAny in ((((ip()))->collect( _x | (OclType["int"])->apply(_x) ))) ; var ip : Function := lambda $$ : OclAny in (input_->apply()) ; var fi : Function := lambda $$ : OclAny in (("" + ((input_->apply())))->toReal()) ; var ap : Function := lambda ab : OclAny, bc : OclAny, cd : OclAny in (ab[bc+1].append(cd)) ; var li : Function := lambda $$ : OclAny in ((input_->apply())) ; var pr : Function := lambda x : OclAny in ((x)->display()) ; var prinT : Function := lambda x : OclAny in ((x)->display()) ; var f : Function := lambda $$ : OclAny in ((OclFile["System.out"]).flush()) ; var inv : Function := lambda x : OclAny in ((x)->pow(mod - 2)) ; var dx : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ -1 }))) ; var dy : Sequence := Sequence{1}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{ 0 }))) ; var mod : double := (10)->pow(9) + 7 ; var mod1 : int := 998244353 ; var s : Sequence := (ip->apply()) ; s := s->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a : OclAny := s.subrange(1,3) ; var b : OclAny := s.subrange(3+1) ; if (((a)->sum()->compareTo((b)->sum())) > 0) then ( Sequence{b,a} := Sequence{a,b} ) else skip ; var t : double := (b)->sum() - (a)->sum() ; if (t = 0) then ( execute (0)->display() ; exit(0) ) else skip ; a := a->select(i | true)->collect(i | (9 - i)) ; a := a + b ; a := a->sort() ; if ((a->first()->compareTo(t)) >= 0) then ( execute (1)->display() ) else (if ((a->first() + a[1+1]->compareTo(t)) >= 0) then ( execute (2)->display() ) else ( execute (3)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def positiveNegativeZero(arr): length=len(arr); positiveCount=0 ; negativeCount=0 ; zeroCount=0 ; for i in range(length): if(arr[i]>0): positiveCount+=1 ; elif(arr[i]<0): negativeCount+=1 ; elif(arr[i]==0): zeroCount+=1 ; print("{0:.4f}".format((positiveCount/length)),end=" "); print("%1.4f " %(negativeCount/length),end=" "); print("%1.4f " %(zeroCount/length),end=" "); print(); if __name__=='__main__' : a1=[2,-1,5,6,0,-3]; positiveNegativeZero(a1); a2=[4,0,-2,-9,-7,1]; positiveNegativeZero(a2); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var a1 : Sequence := Sequence{2}->union(Sequence{-1}->union(Sequence{5}->union(Sequence{6}->union(Sequence{0}->union(Sequence{ -3 }))))); ; positiveNegativeZero(a1); ; var a2 : Sequence := Sequence{4}->union(Sequence{0}->union(Sequence{-2}->union(Sequence{-9}->union(Sequence{-7}->union(Sequence{ 1 }))))); ; positiveNegativeZero(a2); ) else skip; operation positiveNegativeZero(arr : OclAny) pre: true post: true activity: var length : int := (arr)->size(); ; var positiveCount : int := 0; ; var negativeCount : int := 0; ; var zeroCount : int := 0; ; for i : Integer.subrange(0, length-1) do ( if (arr[i+1] > 0) then ( positiveCount := positiveCount + 1; ) else (if (arr[i+1] < 0) then ( negativeCount := negativeCount + 1; ) else (if (arr[i+1] = 0) then ( zeroCount := zeroCount + 1; ) else skip ) ) ) ; execute (StringLib.interpolateStrings("{0:.4f}", Sequence{(positiveCount / length)}))->display(); ; execute (StringLib.format("%1.4f ",(negativeCount / length)))->display(); ; execute (StringLib.format("%1.4f ",(zeroCount / length)))->display(); ; execute (->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,input().split()) R,S,P=map(int,input().split()) T=input() dp=[0] kl=[-1 for i in range(N)] for i in range(N): tmp=dp[i] k=-1 if kl[N-K+i]!=2 and T[i]=="r" : tmp+=P k=2 elif kl[N-K+i]!=0 and T[i]=="s" : tmp+=R k=0 elif kl[N-K+i]!=1 and T[i]=="p" : tmp+=S k=1 dp.append(tmp) kl.append(k) print(dp[N]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var R : OclAny := null; var S : OclAny := null; var P : OclAny := null; Sequence{R,S,P} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var T : String := (OclFile["System.in"]).readLine() ; var dp : Sequence := Sequence{ 0 } ; var kl : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (-1)) ; for i : Integer.subrange(0, N-1) do ( var tmp : OclAny := dp[i+1] ; var k : int := -1 ; if kl[N - K + i+1] /= 2 & T[i+1] = "r" then ( tmp := tmp + P ; k := 2 ) else (if kl[N - K + i+1] /= 0 & T[i+1] = "s" then ( tmp := tmp + R ; k := 0 ) else (if kl[N - K + i+1] /= 1 & T[i+1] = "p" then ( tmp := tmp + S ; k := 1 ) else skip ) ) ; execute ((tmp) : dp) ; execute ((k) : kl)) ; execute (dp[N+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.read readline=sys.stdin.readline n,r,*a=map(int,read().split()) high=a[-1] delta=-1 for ai in a[: :-1]: if highdelta : delta=high-ai high=a[-1] hs=0 ls=0 ans=0 for ai in a[: :-1]: if highcollect( _x | (OclType["int"])->apply(_x) ) ; var high : OclAny := a->last() ; var delta : int := -1 ; for ai : a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if (high->compareTo(ai)) < 0 then ( high := ai ) else skip ; if (high - ai->compareTo(delta)) > 0 then ( delta := high - ai ) else skip) ; high := a->last() ; var hs : int := 0 ; var ls : int := 0 ; var ans : int := 0 ; for ai : a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if (high->compareTo(ai)) < 0 then ( high := ai ; hs := 1 ; ans := ans + Set{hs, ls}->min() ; ls := 0 ) else (if high = ai then ( hs := hs + 1 ) else skip) ; if high - ai = delta then ( ls := ls + 1 ) else skip) ; execute (ans + Set{hs, ls}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np input() a=np.array(input().split(),dtype=np.int) diff=a-np.minimum.accumulate(a) print((diff==diff.max()).sum()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; input() ; var a : Sequence := (input().split(), (argument (test (logical_test (comparison (expr (atom (name dtype)))))) = (test (logical_test (comparison (expr (atom (name np)) (trailer . (name int)))))))) ; var diff : double := a - np.minimum.accumulate(a) ; execute ((diff = diff->max()).sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math h,a=map(int,input().split()) print(math.ceil(h/a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var h : OclAny := null; var a : OclAny := null; Sequence{h,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((h / a)->ceil())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline N,T=map(int,input().split()) prices=list(map(int,input().split())) last=10000000000 highestTally=[prices[-1]] highestCount=[1] for price in prices[-2 :-N-1 :-1]: if price==highestTally[-1]: highestCount.append(highestCount[-1]+1) else : highestCount.append(1) highestTally.append(max(highestTally[-1],price)) highestTally.reverse() highestCount.reverse() indexOfHighest={} for i in range(N-1,-1,-1): if highestTally[i]==prices[i]: indexOfHighest[highestTally[i]]=i biggestJump=0 sellingPriceForBiggestJump=0 HPcount=0 LPcount=0 HPGroups=[] LPGroups=[] for index,price in enumerate(prices): if index==N-1 : break bestSellingPrice=highestTally[index+1] jump=bestSellingPrice-price if jump>biggestJump : biggestJump=jump LPGroups=[] HPGroups=[] LPGroups.append(1) sellingPriceForBiggestJump=bestSellingPrice HPGroups.append(highestCount[indexOfHighest[bestSellingPrice]]) elif jump==biggestJump : if bestSellingPrice!=sellingPriceForBiggestJump : sellingPriceForBiggestJump=bestSellingPrice HPGroups.append(highestCount[indexOfHighest[bestSellingPrice]]) LPGroups.append(0) LPGroups[-1]+=1 count=0 bs=T//2 for a,b in zip(HPGroups,LPGroups): if bs>min(a,b): count+=min(a,b) else : count+=bs print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; var N : OclAny := null; var T : OclAny := null; Sequence{N,T} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var prices : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var last : int := 10000000000 ; var highestTally : Sequence := Sequence{ prices->last() } ; var highestCount : Sequence := Sequence{ 1 } ; for price : prices(subscript (test (logical_test (comparison (expr (atom - (number (integer 2))))))) : (test (logical_test (comparison (expr (expr - (expr (atom (name N)))) - (expr (atom (number (integer 1)))))))) (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if price = highestTally->last() then ( execute ((highestCount->last() + 1) : highestCount) ) else ( execute ((1) : highestCount) ) ; execute ((Set{highestTally->last(), price}->max()) : highestTally)) ; highestTally := highestTally->reverse() ; highestCount := highestCount->reverse() ; var indexOfHighest : OclAny := Set{} ; for i : Integer.subrange(-1 + 1, N - 1)->reverse() do ( if highestTally[i+1] = prices[i+1] then ( indexOfHighest[highestTally[i+1]+1] := i ) else skip) ; var biggestJump : int := 0 ; var sellingPriceForBiggestJump : int := 0 ; var HPcount : int := 0 ; var LPcount : int := 0 ; var HPGroups : Sequence := Sequence{} ; var LPGroups : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (prices)->size())->collect( _indx | Sequence{_indx-1, (prices)->at(_indx)} ) do (var _indx : int := 1; var index : OclAny := _tuple->at(_indx); _indx := _indx + 1; var price : OclAny := _tuple->at(_indx); if index = N - 1 then ( break ) else skip ; var bestSellingPrice : OclAny := highestTally[index + 1+1] ; var jump : double := bestSellingPrice - price ; if (jump->compareTo(biggestJump)) > 0 then ( biggestJump := jump ; LPGroups := Sequence{} ; HPGroups := Sequence{} ; execute ((1) : LPGroups) ; sellingPriceForBiggestJump := bestSellingPrice ; execute ((highestCount[indexOfHighest[bestSellingPrice+1]+1]) : HPGroups) ) else (if jump = biggestJump then ( if bestSellingPrice /= sellingPriceForBiggestJump then ( sellingPriceForBiggestJump := bestSellingPrice ; execute ((highestCount[indexOfHighest[bestSellingPrice+1]+1]) : HPGroups) ; execute ((0) : LPGroups) ) else skip ; LPGroups->last() := LPGroups->last() + 1 ) else skip)) ; var count : int := 0 ; var bs : int := T div 2 ; for _tuple : Integer.subrange(1, HPGroups->size())->collect( _indx | Sequence{HPGroups->at(_indx), LPGroups->at(_indx)} ) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if (bs->compareTo(Set{a, b}->min())) > 0 then ( count := count + Set{a, b}->min() ) else ( count := count + bs )) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter N,T=map(int,input().split()) A=list(map(int,input().split())) maxA=[0 for _ in range(N+1)] minA=[float('inf')for _ in range(N+1)] for i,a in enumerate(A): minA[i+1]=min(minA[i],a) for i,a in enumerate(reversed(A)): maxA[-1-i]=max(maxA[-1-(i-1)],a) maxProfit=0 for i in range(1,N): if maxProfitcollect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var maxA : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (0)) ; var minA : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (("" + (('inf')))->toReal())) ; for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); minA[i + 1+1] := Set{minA[i+1], a}->min()) ; for _tuple : Integer.subrange(1, ((A)->reverse())->size())->collect( _indx | Sequence{_indx-1, ((A)->reverse())->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); maxA->reverse()->at(-(-1 - i)) := Set{maxA->reverse()->at(-(-1 - (i - 1))), a}->max()) ; var maxProfit : int := 0 ; for i : Integer.subrange(1, N-1) do ( if (maxProfit->compareTo(maxA[i + 1+1] - minA[i+1])) < 0 then ( maxProfit := maxA[i + 1+1] - minA[i+1] ) else skip) ; var pairs : Set := Set{}->union((Sequence{})) ; for i : Integer.subrange(1, N-1) do ( if maxProfit = maxA[i + 1+1] - minA[i+1] then ( execute ((Sequence{minA[i+1], maxA[i + 1+1]}) : pairs) ) else skip) ; var ans : int := (pairs)->size() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getlist(): return list(map(int,input().split())) N,T=getlist() A=getlist() m=A[0] plus=-float("inf") cost=1 for i in range(1,N): if A[i]-m==plus : cost+=1 elif A[i]-m>plus : plus=A[i]-m cost=1 else : pass m=min(m,A[i]) print(cost) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var T : OclAny := null; Sequence{N,T} := getlist() ; var A : OclAny := getlist() ; var m : OclAny := A->first() ; var plus : double := -("" + (("inf")))->toReal() ; var cost : int := 1 ; for i : Integer.subrange(1, N-1) do ( if A[i+1] - m = plus then ( cost := cost + 1 ) else (if (A[i+1] - m->compareTo(plus)) > 0 then ( plus := A[i+1] - m ; cost := 1 ) else ( skip ) ) ; m := Set{m, A[i+1]}->min()) ; execute (cost)->display(); operation getlist() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import heapq import sys import math import itertools import bisect from io import BytesIO,IOBase import os def value(): return tuple(map(int,input().split())) def values(): return tuple(map(int,sys.stdin.readline().split())) def inlst(): return[int(i)for i in input().split()] def inlsts(): return[int(i)for i in sys.stdin.readline().split()] def inp(): return int(input()) def inps(): return int(sys.stdin.readline()) def instr(): return input() def stlst(): return[i for i in input().split()] def solve(): n=inp() nums=list(input()) mn=float('inf') for j in range(n): num=nums.copy() num=num[j :]+num[: j] for i in range(n): num[i]=str((int(num[i])-int(nums[j])+10)% 10) mn=min(mn,int("".join(num))) print(str(mn).zfill(n)) if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation value() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation values() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inlsts() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inps() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation instr() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation stlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (i)); operation solve() pre: true post: true activity: var n : OclAny := inp() ; var nums : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var mn : double := ("" + (('inf')))->toReal() ; for j : Integer.subrange(0, n-1) do ( var num : OclAny := nums->copy() ; num := num.subrange(j+1) + num.subrange(1,j) ; for i : Integer.subrange(0, n-1) do ( num[i+1] := ("" + (((("" + ((num[i+1])))->toInteger() - ("" + ((nums[j+1])))->toInteger() + 10) mod 10)))) ; mn := Set{mn, ("" + ((StringLib.sumStringsWithSeparator((num), ""))))->toInteger()}->min()) ; execute (OclType["String"](mn).zfill(n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) curr=[int(x)for x in input()] finals=[] for start in range(-n,0): l=[] x=curr[start] for i in range(start,start+n): l.append(str((curr[i]-x)% 10)) finals.append(int("".join(l))) print(str(min(finals)).zfill(len(curr))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var curr : Sequence := (OclFile["System.in"]).readLine()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var finals : Sequence := Sequence{} ; for start : Integer.subrange(-n, 0-1) do ( var l : Sequence := Sequence{} ; var x : OclAny := curr[start+1] ; for i : Integer.subrange(start, start + n-1) do ( execute ((("" + (((curr[i+1] - x) mod 10)))) : l)) ; execute ((("" + ((StringLib.sumStringsWithSeparator((l), ""))))->toInteger()) : finals)) ; execute (OclType["String"]((finals)->min()).zfill((curr)->size()))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def read_input(input_path=None): if input_path is None : f=sys.stdin else : f=open(input_path,'r') n=int(f.readline()) key=f.readline().strip() return n,key def sol(n,key): ph=key t=[] for i in range(10): dh=ph ph="" l=[] for i in range(0,n): b=int(dh[i]) if((b+1)>9): c=b+1-10 else : c=b+1 ph+=str(c) l.append(dh[i+1 :]+dh[: i+1]) t.append(min(min(l),ph)) return[f"{min(t)}"] def solve(input_path=None): return sol(*read_input(input_path)) def main(): for line in sol(*read_input()): print(f"{line}") if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation read_input(input_path : OclAny) : OclAny pre: true post: true activity: if input_path->oclIsUndefined() then input_path := null else skip; if input_path <>= null then ( var f : OclFile := OclFile["System.in"] ) else ( f := OclFile.newOclFile_Write(OclFile.newOclFile(input_path)) ) ; var n : int := ("" + ((f.readLine())))->toInteger() ; var key : OclAny := f.readLine()->trim() ; return n, key; operation sol(n : OclAny, key : OclAny) : OclAny pre: true post: true activity: var ph : OclAny := key ; var t : Sequence := Sequence{} ; for i : Integer.subrange(0, 10-1) do ( var dh : OclAny := ph ; ph := "" ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var b : int := ("" + ((dh[i+1])))->toInteger() ; if ((b + 1) > 9) then ( var c : double := b + 1 - 10 ) else ( c := b + 1 ) ; ph := ph + ("" + ((c))) ; execute ((dh.subrange(i + 1+1) + dh.subrange(1,i + 1)) : l)) ; execute ((Set{(l)->min(), ph}->min()) : t)) ; return Sequence{ StringLib.formattedString("{min(t)}") }; operation solve(input_path : OclAny) : OclAny pre: true post: true activity: if input_path->oclIsUndefined() then input_path := null else skip; return sol((argument * (test (logical_test (comparison (expr (atom (name read_input)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input_path)))))))) ))))))))); operation main() pre: true post: true activity: for line : sol((argument * (test (logical_test (comparison (expr (atom (name read_input)) (trailer (arguments ( ))))))))) do ( execute (StringLib.formattedString("{line}"))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() a=[] for i in s : a.append(int(i)) x=100 for i in range(n-1): l=a[i] r=a[i+1] if l==r : x=0 break elif lr : q=10-l w=r+q x=min(x,w) bank=[] for k in range(n): temp=[] ad=10-a[k] for i in range(k,n): temp.append((a[i]+ad)% 10) for i in range(0,k): temp.append((a[i]+ad)% 10) bank.append(temp) bank.sort() print(*bank[0],sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var a : Sequence := Sequence{} ; for i : s->characters() do ( execute ((("" + ((i)))->toInteger()) : a)) ; var x : int := 100 ; for i : Integer.subrange(0, n - 1-1) do ( var l : OclAny := a[i+1] ; var r : OclAny := a[i + 1+1] ; if l = r then ( x := 0 ; break ) else (if (l->compareTo(r)) < 0 then ( x := Set{x, r - l}->min() ) else (if (l->compareTo(r)) > 0 then ( var q : double := 10 - l ; var w : OclAny := r + q ; x := Set{x, w}->min() ) else skip ) ) ) ; var bank : Sequence := Sequence{} ; for k : Integer.subrange(0, n-1) do ( var temp : Sequence := Sequence{} ; var ad : double := 10 - a[k+1] ; for i : Integer.subrange(k, n-1) do ( execute (((a[i+1] + ad) mod 10) : temp)) ; for i : Integer.subrange(0, k-1) do ( execute (((a[i+1] + ad) mod 10) : temp)) ; execute ((temp) : bank)) ; bank := bank->sort() ; execute ((argument * (test (logical_test (comparison (expr (atom (name bank)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import sys from io import BytesIO,IOBase from collections import Counter,defaultdict from sys import stdin,stdout import io import math import heapq import bisect import collections import copy import collections,sys,threading def ceil(a,b): return(a+b-1)//b inf=float('inf') def get(): return stdin.readline().rstrip() mod=10**9+7 import collections,sys,threading sys.setrecursionlimit(1500) n=int(get()) l1=[] l=list(get()) for k in range(n): for i in range(10): x=l l2=[] for j in range(n): l2.append(str((int(l[j])+i)% 10)) l1.append(l2) l=l[-1 :]+l[:-1] print("".join(min(l1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; skip ; var mod : double := (10)->pow(9) + 7 ; skip ; sys.setrecursionlimit(1500) ; var n : int := ("" + ((get())))->toInteger() ; var l1 : Sequence := Sequence{} ; var l : Sequence := (get()) ; for k : Integer.subrange(0, n-1) do ( for i : Integer.subrange(0, 10-1) do ( var x : Sequence := l ; var l2 : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( execute ((("" + (((("" + ((l[j+1])))->toInteger() + i) mod 10)))) : l2)) ; execute ((l2) : l1)) ; l := l.subrange(-1+1) + l->front()) ; execute (StringLib.sumStringsWithSeparator(((l1)->min()), ""))->display(); operation ceil(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a + b - 1) div b; operation get() : OclAny pre: true post: true activity: return stdin.readLine().rstrip(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import pow def printPalindrome(n): if(n==1): print("Smallest Palindrome: 0") print("Largest Palindrome: 9") else : print("Smallest Palindrome:",int(pow(10,n-1))+1) print("Largest Palindrome:",int(pow(10,n))-1) if __name__=='__main__' : n=4 printPalindrome(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( n := 4 ; printPalindrome(n) ) else skip; operation printPalindrome(n : OclAny) pre: true post: true activity: if (n = 1) then ( execute ("Smallest Palindrome: 0")->display() ; execute ("Largest Palindrome: 9")->display() ) else ( execute ("Smallest Palindrome:")->display() ; execute ("Largest Palindrome:")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def I(): return int(sys.stdin.readline()) def LI(): return[int(x)for x in sys.stdin.readline().split()] N,K=LI() R,S,P=LI() T=list(input()) dp=[[0]*3 for _ in range(N+1)] def main(): for i in range(1,N+1): if icharacters() ; var dp : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 3))) ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation main() pre: true post: true activity: for i : Integer.subrange(1, N + 1-1) do ( if (i->compareTo(K)) < 0 then ( if T[i - 1+1] = 's' then ( dp[i+1] := Sequence{R}->union(Sequence{0}->union(Sequence{ 0 })) ) else skip ; if T[i - 1+1] = 'p' then ( dp[i+1] := Sequence{0}->union(Sequence{S}->union(Sequence{ 0 })) ) else skip ; if T[i - 1+1] = 'r' then ( dp[i+1] := Sequence{0}->union(Sequence{0}->union(Sequence{ P })) ) else skip ) else ( dp[i+1]->first() := Set{dp[i - K+1][1+1], dp[i - K+1][2+1]}->max() ; dp[i+1][1+1] := Set{dp[i - K+1]->first(), dp[i - K+1][2+1]}->max() ; dp[i+1][2+1] := Set{dp[i - K+1]->first(), dp[i - K+1][1+1]}->max() ; if T[i - 1+1] = 's' then ( dp[i+1]->first() := dp[i+1]->first() + R ) else skip ; if T[i - 1+1] = 'p' then ( dp[i+1][1+1] := dp[i+1][1+1] + S ) else skip ; if T[i - 1+1] = 'r' then ( dp[i+1][2+1] := dp[i+1][2+1] + P ) else skip )) ; var ans : int := 0 ; for i : Integer.subrange(0, K-1) do ( ans := ans + (dp[N - i+1])->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,a=map(int,input().split(" ")) sho=int(h/a) am=int(h % a) if am!=0 : sho+=1 else : pass print(sho) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var a : OclAny := null; Sequence{h,a} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var sho : int := ("" + ((h / a)))->toInteger() ; var am : int := ("" + ((h mod a)))->toInteger() ; if am /= 0 then ( sho := sho + 1 ) else ( skip ) ; execute (sho)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minNum(num,k): len_=len(num) if len_==0 or k==0 : return num if len_==1 : return "0" if num[0]!='1' : num='1'+num[1 :] k-=1 i=1 while k>0 and idisplay(); operation minNum(num : OclAny, k : OclAny) : OclAny pre: true post: true activity: var len_ : int := (num)->size() ; if len_ = 0 or k = 0 then ( return num ) else skip ; if len_ = 1 then ( return "0" ) else skip ; if num->first() /= '1' then ( num := '1' + num->tail() ; k := k - 1 ) else skip ; var i : int := 1 ; while k > 0 & (i->compareTo(len_)) < 0 do ( if num[i+1] /= '0' then ( num := num.subrange(1,i) + '0' + num.subrange(i + 1+1) ; k := k - 1 ) else skip ; i := i + 1) ; return num; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def squareRoot(n): x=n y=1 e=0.000001 while(x-y>e): x=(x+y)/2 y=n/x return x n=50 print("Square root of",n,"is",round(squareRoot(n),6)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 50 ; execute ("Square root of")->display(); operation squareRoot(n : OclAny) : OclAny pre: true post: true activity: var x : OclAny := n ; var y : int := 1 ; var e : double := 0.000001 ; while ((x - y->compareTo(e)) > 0) do ( x := (x + y) / 2 ; y := n / x) ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque number_list=[float("inf")for i in range(1000+1)] number_list[1]=0 que=deque([[1,[1],0]]) while len(que)>0 : n,array,depth=que.popleft() if depth>16 : continue for i in array : if n+i<=1000 and number_list[n+i]>=depth+1 : number_list[n+i]=depth+1 que.append([n+i,array+[n+i],depth+1]) if n-i>0 and number_list[n-i]>=depth+1 : number_list[n-i]=depth+1 que.append([n-i,array+[n-i],depth+1]) while True : N=int(input()) if N==0 : break print(number_list[N]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var number_list : Sequence := Integer.subrange(0, 1000 + 1-1)->select(i | true)->collect(i | (("" + (("inf")))->toReal())) ; number_list[1+1] := 0 ; var que : Sequence := (Sequence{ Sequence{1}->union(Sequence{Sequence{ 1 }}->union(Sequence{ 0 })) }) ; while (que)->size() > 0 do ( var n : OclAny := null; var array : OclAny := null; var depth : OclAny := null; Sequence{n,array,depth} := que->first() ; que := que->tail() ; if depth > 16 then ( continue ) else skip ; for i : array do ( if n + i <= 1000 & (number_list[n + i+1]->compareTo(depth + 1)) >= 0 then ( number_list[n + i+1] := depth + 1 ; execute ((Sequence{n + i}->union(Sequence{array->union(Sequence{ n + i })}->union(Sequence{ depth + 1 }))) : que) ) else skip ; if n - i > 0 & (number_list[n - i+1]->compareTo(depth + 1)) >= 0 then ( number_list[n - i+1] := depth + 1 ; execute ((Sequence{n - i}->union(Sequence{array->union(Sequence{ n - i })}->union(Sequence{ depth + 1 }))) : que) ) else skip)) ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; execute (number_list[N+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def motomeruyuo(): d=deque([(0,1,[1])]) num_list=[float('inf')for i in range(2001)] num_list[1]=0 while d : times,now,nums=d.popleft() for i in nums : tmp=i+now if tmp>2000 : continue if num_list[tmp]>=times : num_list[tmp]=times d.append((times+1,tmp,nums+[tmp])) for i in nums : tmp=max(now-i,i-now) if tmp<=0 : continue if num_list[tmp]>=times : num_list[tmp]=times d.append((times+1,tmp,nums+[tmp])) return num_list from collections import deque ans=[] num_list=motomeruyuo() while True : a=int(input()) if not a : break if a==1 : ans.append(num_list[a]) else : ans.append(num_list[a]+1) [print(i)for i in ans] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var ans : Sequence := Sequence{} ; num_list := motomeruyuo() ; while true do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if not(a) then ( break ) else skip ; if a = 1 then ( execute ((num_list[a+1]) : ans) ) else ( execute ((num_list[a+1] + 1) : ans) )) ; ; operation motomeruyuo() : OclAny pre: true post: true activity: var d : Sequence := (Sequence{ Sequence{0, 1, Sequence{ 1 }} }) ; var num_list : Sequence := Integer.subrange(0, 2001-1)->select(i | true)->collect(i | (("" + (('inf')))->toReal())) ; num_list[1+1] := 0 ; while d do ( var times : OclAny := null; var now : OclAny := null; var nums : OclAny := null; Sequence{times,now,nums} := d->first() ; d := d->tail() ; for i : nums do ( var tmp : OclAny := i + now ; if tmp > 2000 then ( continue ) else skip ; if (num_list[tmp+1]->compareTo(times)) >= 0 then ( num_list[tmp+1] := times ; execute ((Sequence{times + 1, tmp, nums->union(Sequence{ tmp })}) : d) ) else skip) ; for i : nums do ( tmp := Set{now - i, i - now}->max() ; if tmp <= 0 then ( continue ) else skip ; if (num_list[tmp+1]->compareTo(times)) >= 0 then ( num_list[tmp+1] := times ; execute ((Sequence{times + 1, tmp, nums->union(Sequence{ tmp })}) : d) ) else skip)) ; return num_list; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=100005 mod=1000000007 cnt=[0]*N ; def Divisors(): for i in range(1,N): for j in range(1,N//i): cnt[i*j]+=1 ; def Sumofdivisors(A,B,C): sum=0 ; Divisors(); for i in range(1,A+1): for j in range(1,B+1): for k in range(1,C+1): x=i*j*k ; sum+=cnt[x]; if(sum>=mod): sum-=mod ; return sum ; if __name__=="__main__" : A=5 ; B=6 ; C=7 ; print(Sumofdivisors(A,B,C)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 100005 ; var mod : int := 1000000007 ; var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N); ; skip ; skip ; if __name__ = "__main__" then ( A := 5; B := 6; C := 7; ; execute (Sumofdivisors(A, B, C))->display(); ) else skip; operation Divisors() pre: true post: true activity: for i : Integer.subrange(1, N-1) do ( for j : Integer.subrange(1, N div i-1) do ( cnt[i * j+1] := cnt[i * j+1] + 1;)); operation Sumofdivisors(A : OclAny, B : OclAny, C : OclAny) pre: true post: true activity: var sum : int := 0; ; Divisors(); ; for i : Integer.subrange(1, A + 1-1) do ( for j : Integer.subrange(1, B + 1-1) do ( for k : Integer.subrange(1, C + 1-1) do ( var x : double := i * j * k; ; sum := sum + cnt[x+1]; ; if ((sum->compareTo(mod)) >= 0) then ( sum := sum - mod; ) else skip))) ; return sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=32768 arr=[None]*(2*MAX) def gouldSequence(): arr[0]=1 i=1 p=1 while i<=MAX : j=0 while jfirst() := 1 ; var i : int := 1 ; var p : int := 1 ; while (i->compareTo(MAX)) <= 0 do ( var j : int := 0 ; while (j->compareTo(i)) < 0 do ( arr[i + j+1] := 2 * arr[j+1] ; j := j + 1) ; i := (1 * (2->pow(p))) ; p := p + 1); operation printSequence(n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNumber(n): i=n-1 while(i>=0): count=[0 for i in range(10)] x=i count1=0 count2=0 while(x): count[x % 10]+=1 x=int(x/10) count1+=1 for j in range(0,10,1): if(count[j]==1): count2+=1 if(count1==count2): return i i-=1 if __name__=='__main__' : n=8490 print(findNumber(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 8490 ; execute (findNumber(n))->display() ) else skip; operation findNumber(n : OclAny) : OclAny pre: true post: true activity: var i : double := n - 1 ; while (i >= 0) do ( var count : Sequence := Integer.subrange(0, 10-1)->select(i | true)->collect(i | (0)) ; var x : OclAny := i ; var count1 : int := 0 ; var count2 : int := 0 ; while (x) do ( count[x mod 10+1] := count[x mod 10+1] + 1 ; x := ("" + ((x / 10)))->toInteger() ; count1 := count1 + 1) ; for j : Integer.subrange(0, 10-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (count[j+1] = 1) then ( count2 := count2 + 1 ) else skip) ; if (count1 = count2) then ( return i ) else skip ; i := i - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() if s[: 3]=="ftp" : idx=0 for i in range(4,len(s)-1): if s[i]+s[i+1]=='ru' : idx=i ; break S='ftp://' S+=s[3 : i]+'.ru' S+='/'+s[i+2 :] else : idx=0 for i in range(5,len(s)-1): if s[i]+s[i+1]=='ru' : idx=i ; break S='http://' S+=s[4 : i]+'.ru' S+='/'+s[i+2 :] if S[-1]=='/' : S=S[:-1] print(S) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; if s.subrange(1,3) = "ftp" then ( var idx : int := 0 ; for i : Integer.subrange(4, (s)->size() - 1-1) do ( if s[i+1] + s[i + 1+1] = 'ru' then ( idx := i; break ) else skip) ; var S : String := 'ftp://' ; S := S + s.subrange(3+1, i) + '.ru' ; S := S + '/' + s.subrange(i + 2+1) ) else ( idx := 0 ; for i : Integer.subrange(5, (s)->size() - 1-1) do ( if s[i+1] + s[i + 1+1] = 'ru' then ( idx := i; break ) else skip) ; S := 'http://' ; S := S + s.subrange(4+1, i) + '.ru' ; S := S + '/' + s.subrange(i + 2+1) ) ; if S->last() = '/' then ( S := S->front() ) else skip ; execute (S)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- adress=input() if adress[0]=='h' : protocol='http' adress=adress[4 :] c=adress.rfind('ru')+2 domen=f'{adress[:c][:-2]}.ru' context=adress[c :] else : protocol='ftp' adress=adress[3 :] c=adress.rfind('ru')+2 domen=f'{adress[:c][:-2]}.ru' context=adress[c :] if context!='' : print(f'{protocol}://{domen}/{context}') else : print(f'{protocol}://{domen}') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var adress : String := (OclFile["System.in"]).readLine() ; if adress->first() = 'h' then ( var protocol : String := 'http' ; adress := adress.subrange(4+1) ; var c : OclAny := adress.rfind('ru') + 2 ; var domen : String := StringLib.formattedString('{adress[:c][:-2]}.ru') ; var context : OclAny := adress.subrange(c+1) ) else ( protocol := 'ftp' ; adress := adress.subrange(3+1) ; c := adress.rfind('ru') + 2 ; domen := StringLib.formattedString('{adress[:c][:-2]}.ru') ; context := adress.subrange(c+1) ) ; if context /= '' then ( execute (StringLib.formattedString('{protocol}://{domen}/{context}'))->display() ) else ( execute (StringLib.formattedString('{protocol}://{domen}'))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline s=input()[:-1] if s[0]=='h' : a=s.find('ru',5,len(s)) s=s[: 4]+'://'+s[4 : a]+'.'+s[a : a+2]+'/'+s[a+2 :] else : a=s.find('ru',4,len(s)) s=s[: 3]+'://'+s[3 : a]+'.'+s[a : a+2]+'/'+s[a+2 :] print(s.strip('/')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var s : OclAny := input()->front() ; if s->first() = 'h' then ( var a : int := s->indexOf('ru', 5, (s)->size()) - 1 ; s := s.subrange(1,4) + '://' + s.subrange(4+1, a) + '.' + s.subrange(a+1, a + 2) + '/' + s.subrange(a + 2+1) ) else ( a := s->indexOf('ru', 4, (s)->size()) - 1 ; s := s.subrange(1,3) + '://' + s.subrange(3+1, a) + '.' + s.subrange(a+1, a + 2) + '/' + s.subrange(a + 2+1) ) ; execute (s->trim())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=list(map(int,input().split())) if k>=3 : print(max(a)) elif k==2 : print(max(a[0],a[-1])) else : print(min(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if k >= 3 then ( execute ((a)->max())->display() ) else (if k = 2 then ( execute (Set{a->first(), a->last()}->max())->display() ) else ( execute ((a)->min())->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.readline def read_ints(): return list(map(int,read().split())) def read_a_int(): return int(read()) def read_matrix(H): return[list(map(int,read().split()))for _ in range(H)] def read_map(H): return[read()[:-1]for _ in range(H)] def read_col(H,n_cols): ret=[[]for _ in range(n_cols)] for _ in range(H): tmp=list(map(int,read().split())) for col in range(n_cols): ret[col].append(tmp[col]) return ret N,K=read_ints() R,S,P=read_ints() T=read()[:-1] points={'r' : P,'s' : R,'p' : S} handsls=[] ans=0 for i in range(N): now=T[i] if ifront() ; var points : Map := Map{ 'r' |-> P }->union(Map{ 's' |-> R }->union(Map{ 'p' |-> S })) ; var handsls : Sequence := Sequence{} ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( var now : OclAny := T[i+1] ; if (i->compareTo(K)) < 0 then ( ans := ans + points[now+1] ; execute ((now) : handsls) ) else ( if now = handsls[i - K+1] then ( execute (('n') : handsls) ; continue ) else skip ; ans := ans + points[now+1] ; execute ((now) : handsls) )) ; execute (ans)->display(); operation read_ints() : OclAny pre: true post: true activity: return ((read().split())->collect( _x | (OclType["int"])->apply(_x) )); operation read_a_int() : OclAny pre: true post: true activity: return ("" + ((read())))->toInteger(); operation read_matrix(H : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (((read().split())->collect( _x | (OclType["int"])->apply(_x) )))); operation read_map(H : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (read()->front())); operation read_col(H : OclAny, n_cols : OclAny) : OclAny pre: true post: true activity: var ret : Sequence := Integer.subrange(0, n_cols-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, H-1) do ( var tmp : Sequence := ((read().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for col : Integer.subrange(0, n_cols-1) do ((expr (atom (name ret)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name col)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name tmp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name col)))))))) ])))))))) )))))) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() if s[0 : 3]=="ftp" : s="ftp://"+s[3 :] else : s="http://"+s[4 :] s=s.split("ru",2) if len(s)>2 : s=[s[0]+"ru"+s[1],s[2]] if len(s[1])!=0 : print(s[0]+".ru/"+s[1]) else : print(s[0]+".ru") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; if s.subrange(0+1, 3) = "ftp" then ( s := "ftp://" + s.subrange(3+1) ) else ( s := "http://" + s.subrange(4+1) ) ; s := s.split("ru", 2) ; if (s)->size() > 2 then ( s := Sequence{s->first() + "ru" + s[1+1]}->union(Sequence{ s[2+1] }) ) else skip ; if (s[1+1])->size() /= 0 then ( execute (s->first() + ".ru/" + s[1+1])->display() ) else ( execute (s->first() + ".ru")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() t=3+(s[0]>'f') p=s.find('ru',t+1) print(s[: t]+'://'+s[t : p]+'.ru'+('/'[p+2first() > 'f') ; var p : int := s->indexOf('ru', t + 1) - 1 ; execute (s.subrange(1,t) + '://' + s.subrange(t+1, p) + '.ru' + ('/'->select((p + 2->compareTo((s)->size())) < 0)) + s.subrange(p + 2+1))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil k=int(input()) gabarit_k=[list(map(int,input().split()))for i in range(k)] o=int(input()) gabarit_o=[list(map(int,input().split()))for i in range(o)] summa=0 for i in gabarit_k : a,b,h=i perimetr=a*2+b*2 end_price=10**6 for j in gabarit_o : x,y,price=j r=x//h*y if r==0 : continue end_price=min((ceil(perimetr/r)*price),end_price) summa+=end_price print(summa) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var gabarit_k : Sequence := Integer.subrange(0, k-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var o : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var gabarit_o : Sequence := Integer.subrange(0, o-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var summa : int := 0 ; for i : gabarit_k do ( var a : OclAny := null; var b : OclAny := null; var h : OclAny := null; Sequence{a,b,h} := i ; var perimetr : double := a * 2 + b * 2 ; var end_price : double := (10)->pow(6) ; for j : gabarit_o do ( var x : OclAny := null; var y : OclAny := null; var price : OclAny := null; Sequence{x,y,price} := j ; var r : double := x div h * y ; if r = 0 then ( continue ) else skip ; end_price := Set{(ceil(perimetr / r) * price), end_price}->min()) ; summa := summa + end_price) ; execute (summa)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a=int(input()),[] for i in range(n): a.append(list(map(int,input().split()))) m,b=int(input()),[] for i in range(m): b.append(list(map(int,input().split()))) ans=0 for room in a : p,c_room=2*(room[0]+room[1]),10**10 for ob in b : z=ob[0]//room[2]*ob[1] if z==0 : continue c_room=min((p+z-1)//z*ob[2],c_room) ans+=c_room print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),Sequence{}} ; for i : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : a)) ; var m : OclAny := null; var b : OclAny := null; Sequence{m,b} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),Sequence{}} ; for i : Integer.subrange(0, m-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : b)) ; var ans : int := 0 ; for room : a do ( var p : OclAny := null; var c_room : OclAny := null; Sequence{p,c_room} := Sequence{2 * (room->first() + room[1+1]),(10)->pow(10)} ; for ob : b do ( var z : double := ob->first() div room[2+1] * ob[1+1] ; if z = 0 then ( continue ) else skip ; var c_room : OclAny := Set{(p + z - 1) div z * ob[2+1], c_room}->min()) ; ans := ans + c_room) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil n=int(input()) mas=[] matrix=[] for i in range(n): d,l,h=map(int,input().split()) mas.append((d,l,h)) m=int(input()) for i in range(m): matrix.append(tuple(map(int,input().split()))) ans=0 for i in range(len(mas)): minimum=10**9 per=2*(mas[i][0]+mas[i][1]) for j in range(len(matrix)): foring=matrix[j][0]//mas[i][2] if foring!=0 : minimum=min(minimum,ceil(per/(foring*matrix[j][1]))*matrix[j][2]) ans+=minimum print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mas : Sequence := Sequence{} ; var matrix : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var d : OclAny := null; var l : OclAny := null; var h : OclAny := null; Sequence{d,l,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{d, l, h}) : mas)) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, m-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : matrix)) ; var ans : int := 0 ; for i : Integer.subrange(0, (mas)->size()-1) do ( var minimum : double := (10)->pow(9) ; var per : double := 2 * (mas[i+1]->first() + mas[i+1][1+1]) ; for j : Integer.subrange(0, (matrix)->size()-1) do ( var foring : int := matrix[j+1]->first() div mas[i+1][2+1] ; if foring /= 0 then ( minimum := Set{minimum, ceil(per / (foring * matrix[j+1][1+1])) * matrix[j+1][2+1]}->min() ) else skip) ; ans := ans + minimum) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[] for i in range(n): z=list(map(int,input().split())) a.append([2*(z[0]+z[1]),z[2]]) b=[] m=int(input()) for i in range(m): b.append(list(map(int,input().split()))) c=0 for i in a : d=-1 for j in b : e=j[2]*(-(-i[0]//(j[1]*(j[0]//i[1]))))if j[0]>=i[1]else float('inf') if d==-1 or etoInteger() ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var z : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((Sequence{2 * (z->first() + z[1+1])}->union(Sequence{ z[2+1] })) : a)) ; var b : Sequence := Sequence{} ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, m-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : b)) ; var c : int := 0 ; for i : a do ( var d : int := -1 ; for j : b do ( var e : double := if (j->first()->compareTo(i[1+1])) >= 0 then j[2+1] * (-(-i->first() div (j[1+1] * (j->first() div i[1+1])))) else ("" + (('inf')))->toReal() endif ; if d = -1 or (e->compareTo(d)) < 0 then ( d := e ) else skip) ; c := c + d) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil k=int(input()) gabarit_k=[list(map(int,input().split()))for i in range(k)] o=int(input()) gabarit_o=[list(map(int,input().split()))for i in range(o)] summa=0 for i in gabarit_k : a,b,h=i perimetr=a*2+b*2 end_price=10**6 for j in gabarit_o : x,y,price=j r=x//h*y if r==0 : continue option_price=ceil(perimetr/r)*price if option_pricetoInteger() ; var gabarit_k : Sequence := Integer.subrange(0, k-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var o : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var gabarit_o : Sequence := Integer.subrange(0, o-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var summa : int := 0 ; for i : gabarit_k do ( var a : OclAny := null; var b : OclAny := null; var h : OclAny := null; Sequence{a,b,h} := i ; var perimetr : double := a * 2 + b * 2 ; var end_price : double := (10)->pow(6) ; for j : gabarit_o do ( var x : OclAny := null; var y : OclAny := null; var price : OclAny := null; Sequence{x,y,price} := j ; var r : double := x div h * y ; if r = 0 then ( continue ) else skip ; var option_price : double := ceil(perimetr / r) * price ; if (option_price->compareTo(end_price)) < 0 then ( end_price := option_price ) else skip) ; summa := summa + end_price) ; execute (summa)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=list(map(int,input().split(' '))) b=list(map(int,input().split(' '))) if a!=sorted(a): if b.count(0)==0 or b.count(1)==0 : print('No') else : print("Yes") else : print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; if a /= a->sort() then ( if b->count(0) = 0 or b->count(1) = 0 then ( execute ('No')->display() ) else ( execute ("Yes")->display() ) ) else ( execute ("Yes")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def is_asc(a): for i in range(1,len(a)): if a[i]toInteger()-1) do ( input() ; a := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var b : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; if is_asc((a)) then ( execute ('Yes')->display() ) else ( var q : int := 0 ; var k : int := 0 ; for i : b do ( k := k + 1 ; q := q + i) ; if q = k or q = 0 then ( execute ('No')->display() ) else ( execute ('Yes')->display() ) )); operation is_asc(a : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(1, (a)->size()-1) do ( if (a[i+1]->compareTo(a[i - 1+1])) < 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import os import math for s in sys.stdin : x=int(s) h=int(input()) if x==h==0 : break area=x*x+2*x*math.sqrt(h*h+x*x/4) print(area) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; for s : OclFile["System.in"] do ( var x : int := ("" + ((s)))->toInteger() ; var h : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if x = h & (h == 0) then ( break ) else skip ; var area : int := x * x + 2 * x * (h * h + x * x / 4)->sqrt() ; execute (area)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 def input(): return sys.stdin.readline().rstrip() def main(): H,A=map(int,input().split()) print(-(-H//A)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation main() pre: true post: true activity: var H : OclAny := null; var A : OclAny := null; Sequence{H,A} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (-(-H div A))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for p in range(int(input())): n,x,y,f=int(input()),[],[],0 a=list(map(int,input().split())) b=list(map(int,input().split())) if 0 in b and 1 in b : print("Yes") else : if a==sorted(a): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for p : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; var y : OclAny := null; var f : OclAny := null; Sequence{n,x,y,f} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),Sequence{},Sequence{},0} ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (b)->includes(0) & (b)->includes(1) then ( execute ("Yes")->display() ) else ( if a = a->sort() then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import groupby import sys def input(): return sys.stdin.readline().rstrip() def main(): n,k=map(int,input().split()) r,s,p=map(int,input().split()) t=input() ans=0 for i in range(k): x=i li=[] while xcollect( _x | (OclType["int"])->apply(_x) ) ; var r : OclAny := null; var s : OclAny := null; var p : OclAny := null; Sequence{r,s,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; for i : Integer.subrange(0, k-1) do ( var x : OclAny := i ; var li : Sequence := Sequence{} ; while (x->compareTo(n)) < 0 do ( execute ((t[x+1]) : li) ; x := x + k) ; for _tuple : groupby(li) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); if key = 'r' then ( var a : OclAny := p ) else (if key = 's' then ( a := r ) else ( a := s ) ) ; ans := ans + ((((value))->size() + 1) div 2) * a)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for p in range(t): n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) c=a.copy() c.sort() count_0=b.count(0) count_1=b.count(1) if c==a : print("YES") elif count_1!=0 and count_0!=0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for p : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : OclAny := a->copy() ; c := c->sort() ; var count_0 : int := b->count(0) ; var count var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() : int := b->count(1) ; if c = a then ( execute ("YES")->display() ) else (if count var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() /= 0 & count_0 /= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math input=sys.stdin.readline t=int(input()) for _ in range(t): n=int(input()) ar=list(map(int,input().split())) z=list(map(int,input().split())) if ar==sorted(ar): print("YES") else : if 1 in z and 0 in z : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ar : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var z : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if ar = ar->sort() then ( execute ("YES")->display() ) else ( if (z)->includes(1) & (z)->includes(0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def averageValue(s): sum_char=0 for i in range(len(s)): sum_char+=ord(s[i]) return sum_char//len(s) if __name__=="__main__" : s="GeeksforGeeks" print(averageValue(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "GeeksforGeeks" ; execute (averageValue(s))->display() ) else skip; operation averageValue(s : OclAny) : OclAny pre: true post: true activity: var sum_char : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( sum_char := sum_char + (s[i+1])->char2byte()) ; return sum_char div (s)->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,data): self.data=data self.left=None self.right=None def treeToString(root : Node,string : list): if root is None : return string.append(str(root.data)) if not root.left and not root.right : return string.append('(') treeToString(root.left,string) string.append(')') if root.right : string.append('(') treeToString(root.right,string) string.append(')') if __name__=="__main__" : root=Node(1) root.left=Node(2) root.right=Node(3) root.left.left=Node(4) root.left.right=Node(5) root.right.right=Node(6) string=[] treeToString(root,string) print(''.join(string)) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.left := null ; self.right := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var root : Node := (Node.newNode()).initialise(1) ; root.left := (Node.newNode()).initialise(2) ; root.right := (Node.newNode()).initialise(3) ; root.left.left := (Node.newNode()).initialise(4) ; root.left.right := (Node.newNode()).initialise(5) ; root.right.right := (Node.newNode()).initialise(6) ; var string : Sequence := Sequence{} ; treeToString(root, string) ; execute (StringLib.sumStringsWithSeparator((string), ''))->display() ) else skip; operation treeToString(root : Node, string : Sequence(OclAny)) pre: true post: true activity: if root <>= null then ( return ) else skip ; execute ((("" + ((root.data)))) : string) ; if not(root.left) & not(root.right) then ( return ) else skip ; execute (('(') : string) ; treeToString(root.left, string) ; execute ((')') : string) ; if root.right then ( execute (('(') : string) ; treeToString(root.right, string) ; execute ((')') : string) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkconv(a,b,n): c=[0]*n ; flag=0 ; for i in range(n): c[i]=b[i]-a[i]; idxs=[]; for i in range(n): if(c[i]!=0): idxs.append((i,c[i])); for i in range(len(idxs)-1): if(idxs[i+1][0]-idxs[i][0]!=1 or idxs[i+1][1]!=idxs[i][1]): flag=1 ; break ; return not flag ; def diffofarrays(a,b,n): c=[0]*n ; ans=0 ; for i in range(n): c[i]=b[i]-a[i]; for i in range(n): if(c[i]!=0): ans=c[i]; break ; return ans ; if __name__=="__main__" : A=[3,7,1,4,0,2,2]; B=[3,7,3,6,2,2,2]; arr_size=len(A); if(checkconv(A,B,arr_size)): print(diffofarrays(A,B,arr_size)); else : print("NA"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var A : Sequence := Sequence{3}->union(Sequence{7}->union(Sequence{1}->union(Sequence{4}->union(Sequence{0}->union(Sequence{2}->union(Sequence{ 2 })))))); ; var B : Sequence := Sequence{3}->union(Sequence{7}->union(Sequence{3}->union(Sequence{6}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 2 })))))); ; var arr_size : int := (A)->size(); ; if (checkconv(A, B, arr_size)) then ( execute (diffofarrays(A, B, arr_size))->display(); ) else ( execute ("NA")->display(); ) ) else skip; operation checkconv(a : OclAny, b : OclAny, n : OclAny) pre: true post: true activity: var c : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); var flag : int := 0; ; for i : Integer.subrange(0, n-1) do ( c[i+1] := b[i+1] - a[i+1];) ; var idxs : Sequence := Sequence{}; ; for i : Integer.subrange(0, n-1) do ( if (c[i+1] /= 0) then ( execute ((Sequence{i, c[i+1]}) : idxs); ) else skip) ; for i : Integer.subrange(0, (idxs)->size() - 1-1) do ( if (idxs[i + 1+1]->first() - idxs[i+1]->first() /= 1 or idxs[i + 1+1][1+1] /= idxs[i+1][1+1]) then ( flag := 1; ; break; ) else skip) ; return not(flag);; operation diffofarrays(a : OclAny, b : OclAny, n : OclAny) pre: true post: true activity: c := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; var ans : int := 0; ; for i : Integer.subrange(0, n-1) do ( c[i+1] := b[i+1] - a[i+1];) ; for i : Integer.subrange(0, n-1) do ( if (c[i+1] /= 0) then ( ans := c[i+1]; ; break; ) else skip) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): X=int(input()) if X==1 or X==2 or X==3 : print(1) else : li=[] for p in range(2,10): for n in range(2,100): if n**p<=X : li.append(n**p) else : break li.sort(reverse=True) print(li[0]) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var X : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if X = 1 or X = 2 or X = 3 then ( execute (1)->display() ) else ( var li : Sequence := Sequence{} ; for p : Integer.subrange(2, 10-1) do ( for n : Integer.subrange(2, 100-1) do ( if ((n)->pow(p)->compareTo(X)) <= 0 then ( execute (((n)->pow(p)) : li) ) else ( break ))) ; li := li->sort() ; execute (li->first())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) while sum(round(x**(1/k))**k!=x for k in[2,3,5,7])==4 : x-=1 print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while ((argument (test (logical_test (comparison (comparison (expr (expr (atom (name round)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) ** (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) / (expr (atom (name k)))))))) ))))))))) )))) ** (expr (atom (name k))))) != (comparison (expr (atom (name x))))))) (comp_for for (exprlist (expr (atom (name k)))) in (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 2))))))) , (test (logical_test (comparison (expr (atom (number (integer 3))))))) , (test (logical_test (comparison (expr (atom (number (integer 5))))))) , (test (logical_test (comparison (expr (atom (number (integer 7)))))))) ])))))))->sum() = 4 do ( x := x - 1) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import gcd from itertools import combinations,permutations,accumulate from collections import deque,defaultdict,Counter import decimal import re import sys sys.setrecursionlimit(10000000) mod=10**9+7 def readInts(): return list(map(int,input().split())) def I(): return int(input()) x=I() ma=1 for b in range(1,x+1): for p in range(2,x+1): if b**p<=x : ma=max(ma,b**p) else : break print(ma) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(10000000) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; var x : OclAny := I() ; var ma : int := 1 ; for b : Integer.subrange(1, x + 1-1) do ( for p : Integer.subrange(2, x + 1-1) do ( if ((b)->pow(p)->compareTo(x)) <= 0 then ( ma := Set{ma, (b)->pow(p)}->max() ) else ( break ))) ; execute (ma)->display(); operation readInts() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,a=(int(x)for x in input().split()) rep=int(h/a) if rep*atoInteger() ; if (rep * a->compareTo(h)) < 0 then ( rep := rep + 1 ) else skip ; execute (rep)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=0 if n==1 or n==2 or n==3 : ans=1 for i in range(2,10001): b=i c=i cnt=0 while True : if c*b>n : break cnt+=1 c*=b if cnt!=0 : ans=max(ans,c) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; if n = 1 or n = 2 or n = 3 then ( ans := 1 ) else skip ; for i : Integer.subrange(2, 10001-1) do ( var b : OclAny := i ; var c : OclAny := i ; var cnt : int := 0 ; while true do ( if (c * b->compareTo(n)) > 0 then ( break ) else skip ; cnt := cnt + 1 ; c := c * b) ; if cnt /= 0 then ( ans := Set{ans, c}->max() ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=set([]) for i in range(1,32): for s in range(2,32): if i**s<1001 : t.add(i**s) t=list(t) t.append(1001) t.sort(reverse=True) x=int(input()) for i in range(len(t)-1): if t[i]>x>=t[i+1]: print(t[i+1]) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : Set := Set{}->union((Sequence{})) ; for i : Integer.subrange(1, 32-1) do ( for s : Integer.subrange(2, 32-1) do ( if (i)->pow(s) < 1001 then ( execute (((i)->pow(s)) : t) ) else skip)) ; t := (t) ; execute ((1001) : t) ; t := t->sort() ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, (t)->size() - 1-1) do ( if (t[i+1]->compareTo(x)) > 0 & (x >= t[i + 1+1]) then ( execute (t[i + 1+1])->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fu(st): global r,s,p if(st=='r'): return p elif(st=='p'): return s return r n,k=[int(i)for i in input().split()] r,s,p=[int(i)for i in input().split()] t=list(input()) dp=[0]*(10**5+11) res=0 for i in range(k): res+=fu(t[i]) dp[i]=res for i in range(k,len(t)): if(t[i-k]==t[i]): dp[i]=max(dp[i-k],dp[i-1]) t[i]='0' else : dp[i]=dp[i-1]+fu(t[i]) print(dp[n-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute r : OclAny; attribute s : OclAny; attribute p : OclAny; operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; Sequence{r,s,p} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var t : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((10)->pow(5) + 11)) ; var res : int := 0 ; for i : Integer.subrange(0, k-1) do ( res := res + fu(t[i+1]) ; dp[i+1] := res) ; for i : Integer.subrange(k, (t)->size()-1) do ( if (t[i - k+1] = t[i+1]) then ( dp[i+1] := Set{dp[i - k+1], dp[i - 1+1]}->max() ; t[i+1] := '0' ) else ( dp[i+1] := dp[i - 1+1] + fu(t[i+1]) )) ; execute (dp[n - 1+1])->display(); operation fu(st : OclAny) : OclAny pre: true post: true activity: skip; skip; skip ; if (st = 'r') then ( return p ) else (if (st = 'p') then ( return s ) else skip) ; return r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) x=a y=b count=0 while x!=1 and y!=1 : if x>=y : num=x den=y new1=num//den count+=new1 new2=num-(new1*den) x=new2 else : num=y den=x new1=num//den count+=new1 new2=num-(new1*den) y=new2 print(count+max(x,y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := a ; var y : OclAny := b ; var count : int := 0 ; while x /= 1 & y /= 1 do ( if (x->compareTo(y)) >= 0 then ( var num : OclAny := x ; var den : OclAny := y ; var new1 : int := num div den ; count := count + new1 ; var new2 : double := num - (new1 * den) ; x := new2 ) else ( num := y ; den := x ; new1 := num div den ; count := count + new1 ; new2 := num - (new1 * den) ; y := new2 )) ; execute (count + Set{x, y}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def es(i,j): ans=0 while i>0 and j>0 : tmp=i//j ans+=tmp i=i % j i,j=j,i return ans i,j=map(int,input().split()) print(es(i,j)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{i,j} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (es(i, j))->display(); operation es(i : OclAny, j : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; while i > 0 & j > 0 do ( var tmp : int := i div j ; ans := ans + tmp ; i := i mod j ; Sequence{i,j} := Sequence{j,i}) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=0 while m : a+=n//m n,m=m,n % m print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : int := 0 ; while m do ( a := a + n div m ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{m,n mod m}) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve_gcd(a,b): if(a % b==0): return a return a//b+solve_gcd(b,a % b) def solve_lcm(a,b): return int(a*b/solve_gcd(a,b)) a,b=map(int,input().split()) print(solve_gcd(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (solve_gcd(a, b))->display(); operation solve_gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a mod b = 0) then ( return a ) else skip ; return a div b + solve_gcd(b, a mod b); operation solve_lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return ("" + ((a * b / solve_gcd(a, b))))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import gc import math import sqlite3 from collections import Counter,deque,defaultdict from sys import stdout import time from math import factorial,log,gcd import sys from decimal import Decimal import threading from heapq import* def S(): return sys.stdin.readline().split() def I(): return[int(i)for i in sys.stdin.readline().split()] def II(): return int(sys.stdin.readline()) def IS(): return sys.stdin.readline().replace('\n','') def main(): a,b=I() if aselect(i | true)->collect(i | (("" + ((i)))->toInteger())); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation IS() : OclAny pre: true post: true activity: return sys.stdin.readLine().replace(' ', ''); operation main() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := I() ; if (a->compareTo(b)) < 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a} ) else skip ; var ans : int := 1 ; while a /= 1 or b /= 1 do ( if b = 1 then ( ans := ans + a - 1 ; break ) else skip ; var d : int := a div b ; ans := ans + d ; a := a - d * b ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a}) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a6=['espeon'] a7=['jolteon','flareon','umbreon','leafeon','glaceon','sylveon'] a8=['vaporeon'] k=int(input()) n=input() z=0 if k==6 : print('espeon') elif k==8 : print('vaporeon') else : n1=list(n) for i in a7 : i1=list(i) for j in range(len(i1)): if n[j]=='.' or n[j]==i1[j]: z+=1 if z==7 : print(i) break z=0 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a6 : Sequence := Sequence{ 'espeon' } ; var a7 : Sequence := Sequence{'jolteon'}->union(Sequence{'flareon'}->union(Sequence{'umbreon'}->union(Sequence{'leafeon'}->union(Sequence{'glaceon'}->union(Sequence{ 'sylveon' }))))) ; var a8 : Sequence := Sequence{ 'vaporeon' } ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : String := (OclFile["System.in"]).readLine() ; var z : int := 0 ; if k = 6 then ( execute ('espeon')->display() ) else (if k = 8 then ( execute ('vaporeon')->display() ) else ( var n1 : Sequence := (n)->characters() ; for i : a7 do ( var i1 : Sequence := (i) ; for j : Integer.subrange(0, (i1)->size()-1) do ( if n[j+1] = '.' or n[j+1] = i1[j+1] then ( z := z + 1 ) else skip) ; if z = 7 then ( execute (i)->display() ; break ) else skip ; z := 0) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re input() print(next(filter(re.compile(input()[:-3]+'$').match,['vapor','jolt','flar','esp','umbr','leaf','glac','sylv']))+'eon') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; input() ; execute (((Sequence{'vapor'}->union(Sequence{'jolt'}->union(Sequence{'flar'}->union(Sequence{'esp'}->union(Sequence{'umbr'}->union(Sequence{'leaf'}->union(Sequence{'glac'}->union(Sequence{ 'sylv' }))))))))->select( _x | (re.compile(input().subrange(1,-3) + '$').match)->apply(_x) = true )).next() + 'eon')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import logging logging.basicConfig(level=logging.DEBUG) H,A=map(int,input().split()) print(-(-H//A)) logging.info(H,A) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; logging.basicConfig((argument (test (logical_test (comparison (expr (atom (name level)))))) = (test (logical_test (comparison (expr (atom (name logging)) (trailer . (name DEBUG)))))))) ; var H : OclAny := null; var A : OclAny := null; Sequence{H,A} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (-(-H div A))->display() ; logging.info(H, A); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) import re input() print(next(filter(re.compile(input()[:-3]+'$').match,['vapor','jolt','flar','esp','umbr','leaf','glac','sylv']))+'eon') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; input() ; execute (((Sequence{'vapor'}->union(Sequence{'jolt'}->union(Sequence{'flar'}->union(Sequence{'esp'}->union(Sequence{'umbr'}->union(Sequence{'leaf'}->union(Sequence{'glac'}->union(Sequence{ 'sylv' }))))))))->select( _x | (re.compile(input().subrange(1,-3) + '$').match)->apply(_x) = true )).next() + 'eon')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() l=list(s) names=["vaporeon","jolteon","flareon","espeon","umbreon","leafeon","glaceon","sylveon"] names.pop(0) names.pop(2) if len(s)==8 : print("vaporeon") elif len(s)==6 : print("espeon") else : for k in names : count=0 for b in range(7): if s[b]!="." and s[b]==k[b]: count+=1 if count==(7-s.count(".")): print(k) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var l : Sequence := (s)->characters() ; var names : Sequence := Sequence{"vaporeon"}->union(Sequence{"jolteon"}->union(Sequence{"flareon"}->union(Sequence{"espeon"}->union(Sequence{"umbreon"}->union(Sequence{"leafeon"}->union(Sequence{"glaceon"}->union(Sequence{ "sylveon" }))))))) ; names := names->excludingAt(0+1) ; names := names->excludingAt(2+1) ; if (s)->size() = 8 then ( execute ("vaporeon")->display() ) else (if (s)->size() = 6 then ( execute ("espeon")->display() ) else ( for k : names do ( var count : int := 0 ; for b : Integer.subrange(0, 7-1) do ( if s[b+1] /= "." & s[b+1] = k[b+1] then ( count := count + 1 ) else skip ; if count = (7 - s->count(".")) then ( execute (k)->display() ; break ) else skip)) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re _=input() pattern=input() a=["vaporeon","jolteon","flareon","espeon","umbreon","leafeon","glaceon","sylveon"] for i in a : if re.match(pattern,i)is not None and(re.match(pattern,i).span()[1]-re.match(pattern,i).span()[0])==len(i): print(i) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var _anon : String := (OclFile["System.in"]).readLine() ; var pattern : String := (OclFile["System.in"]).readLine() ; var a : Sequence := Sequence{"vaporeon"}->union(Sequence{"jolteon"}->union(Sequence{"flareon"}->union(Sequence{"espeon"}->union(Sequence{"umbreon"}->union(Sequence{"leafeon"}->union(Sequence{"glaceon"}->union(Sequence{ "sylveon" }))))))) ; for i : a do ( if not((i)->firstMatch("^" + pattern + ".*") <>= null) & (re.match(pattern, i).span()[1+1] - re.match(pattern, i).span()->first()) = (i)->size() then ( execute (i)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sortStringArray(s,a,n): a=sorted(a,key=lambda word :[s.index(c)for c in word]) for i in a : print(i,end=' ') s="fguecbdavwyxzhijklmnopqrst" a=["geeksforgeeks","is","the","best","place","for","learning"] n=len(a) sortStringArray(s,a,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := "fguecbdavwyxzhijklmnopqrst" ; a := Sequence{"geeksforgeeks"}->union(Sequence{"is"}->union(Sequence{"the"}->union(Sequence{"best"}->union(Sequence{"place"}->union(Sequence{"for"}->union(Sequence{ "learning" })))))) ; n := (a)->size() ; sortStringArray(s, a, n); operation sortStringArray(s : OclAny, a : OclAny, n : OclAny) pre: true post: true activity: a := a->sortedBy($x | (lambda word : OclAny in (word->select(c | true)->collect(c | (s->indexOf(c) - 1))))->apply($x)) ; for i : a do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def block(x): v=[] print("Blocks for %d : " % x,end="") while(x>0): v.append(int(x % 2)) x=int(x/2) for i in range(0,len(v)): if(v[i]==1): print(i,end="") if(i!=len(v)-1): print(",",end="") print("\n") block(71307) block(1213) block(29) block(100) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; block(71307) ; block(1213) ; block(29) ; block(100); operation block(x : OclAny) pre: true post: true activity: var v : Sequence := Sequence{} ; execute (StringLib.format("Blocks for %d : ",x))->display() ; while (x > 0) do ( execute ((("" + ((x mod 2)))->toInteger()) : v) ; x := ("" + ((x / 2)))->toInteger()) ; for i : Integer.subrange(0, (v)->size()-1) do ( if (v[i+1] = 1) then ( execute (i)->display() ; if (i /= (v)->size() - 1) then ( execute (",")->display() ) else skip ) else skip) ; execute ("\n")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def doesContainB(a,b,c): if(a==b): return True if((b-a)*c>0 and(b-a)% c==0): return True return False if __name__=='__main__' : a,b,c=1,7,3 if(doesContainB(a,b,c)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( Sequence{a,b,c} := Sequence{1,7,3} ; if (doesContainB(a, b, c)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation doesContainB(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: if (a = b) then ( return true ) else skip ; if ((b - a) * c > 0 & (b - a) mod c = 0) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isRectangle(a,b,c,d): if a ^ b ^ c ^ d : return False return True a,b,c,d=3,2,3,2 print("Yes" if isRectangle(a,b,c,d)else "No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{a,b,c,d} := Sequence{3,2,3,2} ; execute (if isRectangle(a, b, c, d) then "Yes" else "No" endif)->display(); operation isRectangle(a : OclAny, b : OclAny, c : OclAny, d : OclAny) : OclAny pre: true post: true activity: if MathLib.bitwiseXor(MathLib.bitwiseXor(MathLib.bitwiseXor(a, b), c), d) then ( return false ) else skip ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() N=int(x) A=list(map(int,input().split())) a=0 b=0 for i in range(N-1): a=a+A[i+1] for i in range(N-1): b=b+A[i]*a a=a-A[i+1] print(b %(10**9+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := (OclFile["System.in"]).readLine() ; var N : int := ("" + ((x)))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : int := 0 ; var b : int := 0 ; for i : Integer.subrange(0, N - 1-1) do ( a := a + A[i + 1+1]) ; for i : Integer.subrange(0, N - 1-1) do ( b := b + A[i+1] * a ; a := a - A[i + 1+1]) ; execute (b mod ((10)->pow(9) + 7))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- LI=lambda : list(map(int,input().split())) N=int(input()) A=LI() MOD=10**9+7 def modinv(x): return pow(x,MOD-2,MOD) def main(): s=sum(A)% MOD ans=s*s % MOD for a in A : ans=(ans-a**2)% MOD ans=ans*modinv(2)% MOD print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var LI : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : OclAny := LI->apply() ; var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation modinv(x : OclAny) : OclAny pre: true post: true activity: return (x)->pow(MOD - 2); operation main() pre: true post: true activity: var s : int := (A)->sum() mod MOD ; var ans : int := s * s mod MOD ; for a : A do ( ans := (ans - (a)->pow(2)) mod MOD) ; ans := ans * modinv(2) mod MOD ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate N=int(input()) A=list(map(int,input().split())) S=list(accumulate(A)) MOD=10**9+7 res=0 for i in reversed(range(1,N)): res+=S[i-1]*A[i] res %=MOD print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var S : Sequence := (accumulate(A)) ; var MOD : double := (10)->pow(9) + 7 ; var res : int := 0 ; for i : (Integer.subrange(1, N-1))->reverse() do ( res := res + S[i - 1+1] * A[i+1] ; res := res mod MOD) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def addStrings(self,num1,num2): res=[] pos1=len(num1)-1 pos2=len(num2)-1 carry=0 while pos1>=0 or pos2>=0 or carry==1 : digit1=digit2=0 if pos1>=0 : digit1=ord(num1[pos1])-ord('0') if pos2>=0 : digit2=ord(num2[pos2])-ord('0') res.append(str((digit1+digit2+carry)% 10)) carry=(digit1+digit2+carry)/10 pos1-=1 pos2-=1 return ''.join(res[: :-1]) ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation addStrings(num1 : OclAny,num2 : OclAny) : OclAny pre: true post: true activity: var res : Sequence := Sequence{} ; var pos1 : double := (num1)->size() - 1 ; var pos2 : double := (num2)->size() - 1 ; var carry : int := 0 ; while pos1 >= 0 or pos2 >= 0 or carry = 1 do ( var digit1 : OclAny := 0; var digit2 : int := 0 ; if pos1 >= 0 then ( digit1 := (num1[pos1+1])->char2byte() - ('0')->char2byte() ) else skip ; if pos2 >= 0 then ( digit2 := (num2[pos2+1])->char2byte() - ('0')->char2byte() ) else skip ; execute ((("" + (((digit1 + digit2 + carry) mod 10)))) : res) ; carry := (digit1 + digit2 + carry) / 10 ; pos1 := pos1 - 1 ; pos2 := pos2 - 1) ; return StringLib.sumStringsWithSeparator((res(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))), ''); } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=1000000007 n=int(input()) str_ary=input().split() ary=[int(c)for c in str_ary] result=0 sum=sum(ary[i]for i in range(n)) for i in range(n): sum-=ary[i] result+=ary[i]*sum print(result % MOD) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : int := 1000000007 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var str_ary : OclAny := input().split() ; var ary : Sequence := str_ary->select(c | true)->collect(c | (("" + ((c)))->toInteger())) ; var result : int := 0 ; var sum : OclAny := ((argument (test (logical_test (comparison (expr (atom (name ary)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->sum() ; for i : Integer.subrange(0, n-1) do ( sum := sum - ary[i+1] ; result := result + ary[i+1] * sum) ; execute (result mod MOD)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findProductSum(A,n): array_sum=0 for i in range(0,n,1): array_sum+=A[i] array_sum_square=(array_sum*array_sum) individual_square_sum=0 for i in range(0,n,1): individual_square_sum+=(A[i]*A[i]) return(array_sum_square-individual_square_sum)//2 n=int(input()) a=[int(x)for x in input().split()] MOD=10**9+7 print(int(findProductSum(a,n))% MOD) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var MOD : double := (10)->pow(9) + 7 ; execute (("" + ((findProductSum(a, n))))->toInteger() mod MOD)->display(); operation findProductSum(A : OclAny, n : OclAny) : OclAny pre: true post: true activity: var array_sum : int := 0 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( array_sum := array_sum + A[i+1]) ; var array_sum_square : int := (array_sum * array_sum) ; var individual_square_sum : int := 0 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( individual_square_sum := individual_square_sum + (A[i+1] * A[i+1])) ; return (array_sum_square - individual_square_sum) div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=lambda : map(int,input().split()) P=print n,b=I() a=list(I()) x=(b+sum(a))/n if any(i>x for i in a): P(-1) else :[P(x-i)for i in a] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var P : OclAny := print ; var n : OclAny := null; var b : OclAny := null; Sequence{n,b} := I->apply() ; var a : Sequence := (I->apply()) ; var x : double := (b + (a)->sum()) / n ; if ((argument (test (logical_test (comparison (comparison (expr (atom (name i)))) > (comparison (expr (atom (name x))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name a))))))))->exists( _x | _x = true ) then ( P(-1) ) else ( ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=[int(i)for i in input().split()] n=x[0] y=[int(i)for i in input().split()] if x[1]select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var n : OclAny := x->first() ; var y : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if (x[1+1]->compareTo((y)->max() * n - (y)->sum())) < 0 then ( execute (-1)->display() ; error SystemExit.newSystemExit ) else skip ; for i : Integer.subrange(0, n-1) do ( var s : double := x[1+1] / n - y[i+1] + (y)->sum() / n ; execute (StringLib.format('%.6f',s))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(): read=lambda : sys.stdin.readline().rstrip() b,c=map(int,read().split()) print(b*c) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var read : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := (read->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (b * c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(): n,b,=rv() a,=rl(1) musthave=max(a) pour=[0]*n for i in range(n): pour[i]=musthave-a[i] alreadypoured=sum(pour) if alreadypoured>b : print(-1) return morepour=(b-alreadypoured)/n for i in range(n): pour[i]+=morepour print('\n'.join(map(str,pour))) def prt(l): return print(' '.join(l)) def rv(): return map(int,input().split()) def rl(n): return[list(map(int,input().split()))for _ in range(n)] if sys.hexversion==50594544 : sys.stdin=open("test.txt") solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if (trailer . (name hexversion)) = 50594544 then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("test.txt")) ) else skip ; solve(); operation solve() pre: true post: true activity: var n : OclAny := null; (declareIfNecessary (test (logical_test (comparison (expr (atom (name b)))))) ,) Sequence{n,(testlist_star_expr (test (logical_test (comparison (expr (atom (name b)))))) ,)} := rv() ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name a)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name a)))))) ,)} := rl(1) ; var musthave : OclAny := (a)->max() ; var pour : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( pour[i+1] := musthave - a[i+1]) ; var alreadypoured : OclAny := (pour)->sum() ; if (alreadypoured->compareTo(b)) > 0 then ( execute (-1)->display() ; return ) else skip ; var morepour : double := (b - alreadypoured) / n ; for i : Integer.subrange(0, n-1) do ( pour[i+1] := pour[i+1] + morepour) ; execute (StringLib.sumStringsWithSeparator(((pour)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); operation prt(l : OclAny) : OclAny pre: true post: true activity: return (StringLib.sumStringsWithSeparator((l), ' '))->display(); operation rv() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation rl(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_friends,remaining=map(int,input().split()) volumes=list(map(int,input().split())) max_volume=max(volumes) pour=[max_volume-volume for volume in volumes] if sum(pour)>remaining : print(-1) else : part=(remaining-sum(pour))/len(pour) for i,volume in enumerate(pour): volume+=part print('%.8f' % volume) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_friends : OclAny := null; var remaining : OclAny := null; Sequence{num_friends,remaining} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var volumes : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var max_volume : OclAny := (volumes)->max() ; var pour : Sequence := volumes->select(volume | true)->collect(volume | (max_volume - volume)) ; if ((pour)->sum()->compareTo(remaining)) > 0 then ( execute (-1)->display() ) else ( var part : double := (remaining - (pour)->sum()) / (pour)->size() ; for _tuple : Integer.subrange(1, (pour)->size())->collect( _indx | Sequence{_indx-1, (pour)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var volume : OclAny := _tuple->at(_indx); volume := volume + part ; execute (StringLib.format('%.8f',volume))->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- strLine=input() strLineSplit=strLine.split() nNum=int(strLineSplit[0]) fBig=float(strLineSplit[1]) strLine=input() strLineSplit=strLine.split() lList=[] for str in strLineSplit : lList.append(float(str)) fMax=max(lList) fSum=0.0 for i in lList : fSum+=fMax-i if fSum>fBig : print('-1') else : fLa=(fBig-fSum)/nNum for i in lList : print('%.6f' %(fLa+fMax-i)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var strLine : String := (OclFile["System.in"]).readLine() ; var strLineSplit : OclAny := strLine.split() ; var nNum : int := ("" + ((strLineSplit->first())))->toInteger() ; var fBig : double := ("" + ((strLineSplit[1+1])))->toReal() ; strLine := (OclFile["System.in"]).readLine() ; strLineSplit := strLine.split() ; var lList : Sequence := Sequence{} ; for OclType["String"] : strLineSplit do ( execute ((("" + ((OclType["String"])))->toReal()) : lList)) ; var fMax : OclAny := (lList)->max() ; var fSum : double := 0.0 ; for i : lList do ( fSum := fSum + fMax - i) ; if (fSum->compareTo(fBig)) > 0 then ( execute ('-1')->display() ) else ( var fLa : double := (fBig - fSum) / nNum ; for i : lList do ( execute (StringLib.format('%.6f',(fLa + fMax - i)))->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : n=int(input()) m=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) b+=[b[0]] try : x=1 for i in range(n): fuel=x/a[i] x=x-fuel fuel=x/b[i+1] x=x-fuel ans=(m/x)-m print(f"{ans:.6f}") except : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; b := b + Sequence{ b->first() } ; try ( var x : int := 1 ; for i : Integer.subrange(0, n-1) do ( var fuel : double := x / a[i+1] ; x := x - fuel ; fuel := x / b[i + 1+1] ; x := x - fuel) ; var ans : double := (m / x) - m ; execute (StringLib.formattedString("{ans:.6f}"))->display()) catch (_e : OclException) do ( execute (-1)->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pos(a,b,f,fuel): i=0 flag=0 while flag==0 : f-=(f/a[i]) i+=1 if i==len(a): flag=1 i=0 f-=(f/b[i]) return f>=fuel n=float(input()) init=float(input()) a=list(map(float,input().split())) b=list(map(float,input().split())) lo=0 hi=10000000000 ans=100000000000 while lotoReal() ; var init : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; a := ((input().split())->collect( _x | (OclType["double"])->apply(_x) )) ; b := ((input().split())->collect( _x | (OclType["double"])->apply(_x) )) ; var lo : int := 0 ; var hi : int := 10000000000 ; var ans : int := 100000000000 ; while (lo->compareTo(hi)) < 0 do ( var mid : double := (lo + hi) / 2 ; if pos(a, b, init + mid, init) then ( if (((mid - ans)->abs() / mid)->compareTo((10)->pow((-12)))) < 0 then ( break ) else skip ; ans := Set{ans, mid}->min() ; hi := mid ) else ( lo := mid )) ; if ans = 100000000000 then ( execute (-1)->display() ) else ( execute (ans)->display() ); operation pos(a : OclAny, b : OclAny, f : OclAny, fuel : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; var flag : int := 0 ; while flag = 0 do ( f := f - (f / a[i+1]) ; i := i + 1 ; if i = (a)->size() then ( flag := 1 ; i := 0 ) else skip ; f := f - (f / b[i+1])) ; return (f->compareTo(fuel)) >= 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPerfect(n): sum=1 i=2 while i*i<=n : if n % i==0 : sum=sum+i+n/i i+=1 return(True if sum==n and n!=1 else False) print("Below are all perfect numbers till 10000") n=2 for n in range(10000): if isPerfect(n): print(n," is a perfect number") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute ("Below are all perfect numbers till 10000")->display() ; n := 2 ; for n : Integer.subrange(0, 10000-1) do ( if isPerfect(n) then ( execute (n)->display() ) else skip); operation isPerfect(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 1 ; var i : int := 2 ; while (i * i->compareTo(n)) <= 0 do ( if n mod i = 0 then ( sum := sum + i + n / i ) else skip ; i := i + 1) ; return (if sum = n & n /= 1 then true else false endif); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) n=int(input()) sw=int(input()) lifts=list(R()) lands=list(R()) l,r=0,10**9+1 while r-l>10**-6 : fuel=(l+r)/2 rem=fuel for i in range(n): rem-=(rem+sw)/lifts[i] if rem<0 : break rem-=(rem+sw)/lands[(i+1)% n] if rem<0 : break if rem<0 : l=fuel else : r=fuel print(l if l<=10**9 else-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sw : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lifts : Sequence := (R->apply())->characters() ; var lands : Sequence := (R->apply())->characters() ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,(10)->pow(9) + 1} ; while (r - l->compareTo((10)->pow(-6))) > 0 do ( var fuel : double := (l + r) / 2 ; var rem : OclAny := fuel ; for i : Integer.subrange(0, n-1) do ( rem := rem - (rem + sw) / lifts[i+1] ; if rem < 0 then ( break ) else skip ; rem := rem - (rem + sw) / lands[(i + 1) mod n+1] ; if rem < 0 then ( break ) else skip) ; if rem < 0 then ( var l : OclAny := fuel ) else ( var r : OclAny := fuel )) ; execute (if (l->compareTo((10)->pow(9))) <= 0 then l else -1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) m=int(input()) s=m a=list(map(int,input().split())) b=list(map(int,input().split())) def cal(n,m,s,a,b): if b[0]<=1.00 : return-1 k=s/(b[0]-1) s+=k for i in range(n-1,0,-1): if a[i]<=1.00 : return-1 k=s/(a[i]-1) s+=k if b[i]<=1.00 : return-1 k=s/(b[i]-1) s+=k if a[0]<=1.00 : return-1 k=s/(a[0]-1) s+=k return s-m ans=cal(n,m,s,a,b) if ans!=-1 : print('{:.8f}'.format(ans)) else : print(-1) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : int := m ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; var ans : OclAny := cal(n, m, s, a, b) ; if ans /= -1 then ( execute (StringLib.interpolateStrings('{:.8f}', Sequence{ans}))->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=input i() m=int(i()) v=m try : for a in map(int,(i()+' '+i()).split()): v*=a/(a-1) except : v=m-1 print(v-m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : OclAny := input ; i() ; var m : int := ("" + ((i())))->toInteger() ; var v : int := m ; try ( for a : ((i() + ' ' + i()).split())->collect( _x | (OclType["int"])->apply(_x) ) do ( v := v * a / (a - 1))) catch (_e : OclException) do ( v := m - 1) ; execute (v - m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def removeDuplicate(str,n): index=0 for i in range(0,n): for j in range(0,i+1): if(str[i]==str[j]): break if(j==i): str[index]=str[i] index+=1 return "".join(str[: index]) str="geeksforgeeks" n=len(str) print(removeDuplicate(list(str),n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclType["String"] := "geeksforgeeks" ; n := (OclType["String"])->size() ; execute (removeDuplicate((OclType["String"])->characters(), n))->display(); operation removeDuplicate(OclType["String"] : OclAny, n : OclAny) : OclAny pre: true post: true activity: var index : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, i + 1-1) do ( if (("" + ([i+1])) = ("" + ([j+1]))) then ( break ) else skip) ; if (j = i) then ( ("" + ([index+1])) := ("" + ([i+1])) ; index := index + 1 ) else skip) ; return StringLib.sumStringsWithSeparator((("" + (.subrange(1,index)))), ""); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def commonPrefixUtil(str1,str2): result="" ; n1=len(str1) n2=len(str2) i=0 j=0 while i<=n1-1 and j<=n2-1 : if(str1[i]!=str2[j]): break result+=str1[i] i+=1 j+=1 return(result) def commonPrefix(arr,n): prefix=arr[0] for i in range(1,n): prefix=commonPrefixUtil(prefix,arr[i]) return(prefix) if __name__=="__main__" : arr=["geeksforgeeks","geeks","geek","geezer"] n=len(arr) ans=commonPrefix(arr,n) if(len(ans)): print("The longest common prefix is-",ans); else : print("There is no common prefix") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{"geeksforgeeks"}->union(Sequence{"geeks"}->union(Sequence{"geek"}->union(Sequence{ "geezer" }))) ; n := (arr)->size() ; var ans : OclAny := commonPrefix(arr, n) ; if ((ans)->size()) then ( execute ("The longest common prefix is-")->display(); ) else ( execute ("There is no common prefix")->display() ) ) else skip; operation commonPrefixUtil(str1 : OclAny, str2 : OclAny) : OclAny pre: true post: true activity: var result : String := ""; ; var n1 : int := (str1)->size() ; var n2 : int := (str2)->size() ; var i : int := 0 ; var j : int := 0 ; while (i->compareTo(n1 - 1)) <= 0 & (j->compareTo(n2 - 1)) <= 0 do ( if (str1[i+1] /= str2[j+1]) then ( break ) else skip ; result := result + str1[i+1] ; i := i + 1 ; j := j + 1) ; return (result); operation commonPrefix(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var prefix : OclAny := arr->first() ; for i : Integer.subrange(1, n-1) do ( prefix := commonPrefixUtil(prefix, arr[i+1])) ; return (prefix); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from itertools import permutations from sys import stdin,stdout from bisect import bisect_left,bisect_right from copy import deepcopy import heapq int_input=lambda : int(stdin.readline()) string_input=lambda : stdin.readline().split() multi_int_input=lambda : map(int,stdin.readline().split()) multi_input=lambda : stdin.readline().split() list_input=lambda : list(map(int,stdin.readline().split())) string_list_input=lambda : list(string_input()) MOD=pow(10,9)+7 a,b=multi_int_input() print(a*b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var int_input : Function := lambda $$ : OclAny in (("" + ((stdin.readLine())))->toInteger()) ; var string_input : Function := lambda $$ : OclAny in (stdin.readLine().split()) ; var multi_int_input : Function := lambda $$ : OclAny in ((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var multi_input : Function := lambda $$ : OclAny in (stdin.readLine().split()) ; var list_input : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var string_list_input : Function := lambda $$ : OclAny in ((string_input->apply())) ; var MOD : double := (10)->pow(9) + 7 ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := multi_int_input->apply() ; execute (a * b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getRemainder(num,divisor): if(divisor==0): return False if(divisor<0): divisor=-divisor if(num<0): num=-num i=1 product=0 while(product<=num): product=divisor*i i+=1 return num-(product-divisor) num=100 divisor=7 print(getRemainder(num,divisor)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; num := 100 ; divisor := 7 ; execute (getRemainder(num, divisor))->display(); operation getRemainder(num : OclAny, divisor : OclAny) : OclAny pre: true post: true activity: if (divisor = 0) then ( return false ) else skip ; if (divisor < 0) then ( divisor := -divisor ) else skip ; if (num < 0) then ( num := -num ) else skip ; var i : int := 1 ; var product : int := 0 ; while ((product->compareTo(num)) <= 0) do ( product := divisor * i ; i := i + 1) ; return num - (product - divisor); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- power=[] def nextPower(N): global power carry=0 for i in range(0,len(power)): prod=(power[i]*N)+carry power[i]=prod % 10 carry=(int)(prod/10) while(carry): power.append(carry % 10) carry=(int)(carry/10) def printPowerNumber(X,N): global power power.append(1) res=[] for i in range(1,X+1): nextPower(N) res.append(power[-1]) res.append(power[0]) for i in range(0,len(res)): print(res[i],end="") N=19 X=4 printPowerNumber(X,N) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute power : OclAny; attribute power : OclAny; operation initialise() pre: true post: true activity: var power : Sequence := Sequence{} ; skip ; skip ; N := 19 ; X := 4 ; printPowerNumber(X, N); operation nextPower(N : OclAny) pre: true post: true activity: skip ; var carry : int := 0 ; for i : Integer.subrange(0, (power)->size()-1) do ( var prod : double := (power[i+1] * N) + carry ; power[i+1] := prod mod 10 ; carry := (OclType["int"])(prod / 10)) ; while (carry) do ( execute ((carry mod 10) : power) ; carry := (OclType["int"])(carry / 10)); operation printPowerNumber(X : OclAny, N : OclAny) pre: true post: true activity: skip ; execute ((1) : power) ; var res : Sequence := Sequence{} ; for i : Integer.subrange(1, X + 1-1) do ( nextPower(N) ; execute ((power->last()) : res) ; execute ((power->first()) : res)) ; for i : Integer.subrange(0, (res)->size()-1) do ( execute (res[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CountWords(str,k): sum=0 NumberOfWords=0 counter=0 l=len(str) for i in range(l): if(str[i]==' '): if(sumsize() ; for i : Integer.subrange(0, l-1) do ( if (("" + ([i+1])) = ' ') then ( if ((sum->compareTo(k)) < 0) then ( counter := counter + 1 ) else skip ; sum := 0 ; NumberOfWords := NumberOfWords + 1 ) else ( sum := sum + (("" + ([i+1])))->char2byte() )) ; NumberOfWords := NumberOfWords + 1 ; if ((sum->compareTo(k)) < 0) then ( counter := counter + 1 ) else skip ; execute ("Number of words having sum of ASCII")->display() ; execute ("Number of words having sum of ASCII values")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,m=map(int,input().split()) a=list(map(int,input().split())) a.sort() x=0 for i in a : x=min(i,x+1) ans=sum(a)-(n+a[-1]-x)if n ^ 1 else 0 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var x : int := 0 ; for i : a do ( x := Set{i, x + 1}->min()) ; var ans : double := if MathLib.bitwiseXor(n, 1) then (a)->sum() - (n + a->last() - x) else 0 endif ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def isPower(n): if(n==1): return True for x in range(2,(int)(math.sqrt(n))+1): y=2 p=(int)(math.pow(x,y)) while(p<=n and p>0): if(p==n): return True y=y+1 p=math.pow(x,y) return False for i in range(2,100): if(isPower(i)): print(i,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for i : Integer.subrange(2, 100-1) do ( if (isPower(i)) then ( execute (i)->display() ) else skip); operation isPower(n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return true ) else skip ; for x : Integer.subrange(2, (OclType["int"])((n)->sqrt()) + 1-1) do ( var y : int := 2 ; var p : OclAny := (OclType["int"])((x)->pow(y)) ; while ((p->compareTo(n)) <= 0 & p > 0) do ( if (p = n) then ( return true ) else skip ; y := y + 1 ; p := (x)->pow(y))) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(x)for x in input().split()] a=[int(x)for x in input().split()] mx=max(a) top=len(a)-a.count(0) a.sort(reverse=True) ans=0 cnt=0 a+=[0,0] rest=0 for i in range(n): cnt+=1 if ia[i]-a[i+1]-rest : ans+=cnt rest+=max(0,cnt-(a[i]-a[i+1])) else : ans+=a[i]-a[i+1]-rest rest=0 cnt=0 print(sum(a)-ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var mx : OclAny := (a)->max() ; var top : double := (a)->size() - a->count(0) ; a := a->sort() ; var ans : int := 0 ; var cnt : int := 0 ; a := a + Sequence{0}->union(Sequence{ 0 }) ; var rest : int := 0 ; for i : Integer.subrange(0, n-1) do ( cnt := cnt + 1 ; if (i->compareTo(n)) < 0 & a[i + 1+1] = a[i+1] then ( continue ) else skip ; if a[i+1] = 0 then ( break ) else skip ; if (cnt->compareTo(a[i+1] - a[i + 1+1] - rest)) > 0 then ( ans := ans + cnt ; rest := rest + Set{0, cnt - (a[i+1] - a[i + 1+1])}->max() ) else ( ans := ans + a[i+1] - a[i + 1+1] - rest ; rest := 0 ) ; cnt := 0) ; execute ((a)->sum() - ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=sorted([int(x)for x in input().split()]) total=0 m=max(a) for i in range(n): if a[i]>total : total+=1 print(sum(a)-(n+m-total)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))->sort() ; var total : int := 0 ; var m : OclAny := (a)->max() ; for i : Integer.subrange(0, n-1) do ( if (a[i+1]->compareTo(total)) > 0 then ( total := total + 1 ) else skip) ; execute ((a)->sum() - (n + m - total))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().strip() n,h=[int(i)for i in input().split()] heights=[int(i)for i in input().split()] heights.sort() total=sum(heights) req=1 x=0 y=1 while x=y+1 : y+=1 req+=1 req+=heights[-1]-y print(total-req) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine()->trim()) ; var n : OclAny := null; var h : OclAny := null; Sequence{n,h} := input->apply().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var heights : Sequence := input->apply().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; heights := heights->sort() ; var total : OclAny := (heights)->sum() ; var req : int := 1 ; var x : int := 0 ; var y : int := 1 ; while (x->compareTo(n - 1)) < 0 do ( x := x + 1 ; if (heights[x+1]->compareTo(y + 1)) >= 0 then ( y := y + 1 ) else skip ; req := req + 1) ; req := req + heights->last() - y ; execute (total - req)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printExpansion(str): suff="" for i in range(len(str)-1,-1,-1): suff=suff+str[i] print(suff,end="") if __name__=="__main__" : str="geeks" printExpansion(str) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( OclType["String"] := "geeks" ; printExpansion(OclType["String"]) ) else skip; operation printExpansion(OclType["String"] : OclAny) pre: true post: true activity: var suff : String := "" ; for i : Integer.subrange(-1 + 1, (OclType["String"])->size() - 1)->reverse() do ( suff := suff + ("" + ([i+1])) ; execute (suff)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def seriesSum(n): i=1 ; res=0.0 ; sign=True ; while(n>0): n=n-1 ; if(sign): sign=False ; res=res+(i+1)/(i+2); i=i+2 ; else : sign=True ; res=res-(i+1)/(i+2); i=i+2 ; return res ; n=5 ; print(round(seriesSum(n),6)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5; ; execute (MathLib.roundN(seriesSum(n), 6))->display();; operation seriesSum(n : OclAny) pre: true post: true activity: var i : int := 1; ; var res : double := 0.0; ; var sign : boolean := true; ; while (n > 0) do ( n := n - 1; ; if (sign) then ( sign := false; ; res := res + (i + 1) / (i + 2); ; i := i + 2; ) else ( sign := true; ; res := res - (i + 1) / (i + 2); ; i := i + 2; )) ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def toggleBitsFromLToR(n,l,r): if(rdisplay(); operation toggleBitsFromLToR(n : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: if ((r->compareTo(l)) < 0) then ( return n ) else skip ; var num : int := MathLib.bitwiseXor(((1 * (2->pow(r))) - 1), ((1 * (2->pow((l - 1)))) - 1)) ; return (MathLib.bitwiseXor(n, num)); operation smallNumWithNSetAndMUnsetBits(n : OclAny, m : OclAny) pre: true post: true activity: num := (1 * (2->pow((n + m)))) - 1 ; return toggleBitsFromLToR(num, n, n + m - 1);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input().split() print(int(s[0])*int(s[1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := input().split() ; execute (("" + ((s->first())))->toInteger() * ("" + ((s[1+1])))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math N=int(input()) W=math.ceil(math.sqrt(N)) H=math.ceil(N/W) result=2*(W+H) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var W : double := ((N)->sqrt())->ceil() ; var H : double := (N / W)->ceil() ; var result : double := 2 * (W + H) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) x=int(n**0.5) print(x*4+(0 if n-x**2==0 else 2 if n-x**2<=x else 4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := ("" + (((n)->pow(0.5))))->toInteger() ; execute (x * 4 + (if n - (x)->pow(2) = 0 then 0 else if (n - (x)->pow(2)->compareTo(x)) <= 0 then 2 else 4 endif endif))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() import math n=int(input()) print(math.ceil(math.sqrt(n)*2)*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (((n)->sqrt() * 2)->ceil() * 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def isPower(n): if(n<=1): return True for x in range(2,(int)(math.sqrt(n))+1): p=x while(p<=n): p=p*x if(p==n): return True return False for i in range(2,100): if(isPower(i)): print(i,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for i : Integer.subrange(2, 100-1) do ( if (isPower(i)) then ( execute (i)->display() ) else skip); operation isPower(n : OclAny) : OclAny pre: true post: true activity: if (n <= 1) then ( return true ) else skip ; for x : Integer.subrange(2, (OclType["int"])((n)->sqrt()) + 1-1) do ( var p : OclAny := x ; while ((p->compareTo(n)) <= 0) do ( p := p * x ; if (p = n) then ( return true ) else skip)) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) f=int(n**(1/2)) r=n-f**2 m=2 if r==0 : m=0 elif r>f : m=4 print((f*4)+m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var f : int := ("" + (((n)->pow((1 / 2)))))->toInteger() ; var r : double := n - (f)->pow(2) ; var m : int := 2 ; if r = 0 then ( m := 0 ) else (if (r->compareTo(f)) > 0 then ( m := 4 ) else skip) ; execute ((f * 4) + m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,ceil,floor a=int(input()) a1,a2,a3=floor(sqrt(a)),sqrt(a),ceil(sqrt(a)) if a1==a2 : print(4*a1) elif a1*a3>=a : print(2*(a1+a3)) else : print(4*a3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a1 : OclAny := null; var a2 : OclAny := null; var a3 : OclAny := null; Sequence{a1,a2,a3} := Sequence{floor(sqrt(a)),sqrt(a),ceil(sqrt(a))} ; if a1 = a2 then ( execute (4 * a1)->display() ) else (if (a1 * a3->compareTo(a)) >= 0 then ( execute (2 * (a1 + a3))->display() ) else ( execute (4 * a3)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def s(): for e in iter(input,'0 0'): w,h=map(int,e.split()) M=[[[1,0]*2 for _ in[0]*h]for _ in[0]*w] for i in range(1,w): for j in range(1,h): a,b=M[i-1][j][: 2] c,d=M[i][j-1][2 :] M[i][j]=[d,a+b,b,c+d] print((sum(M[w-2][h-1][: 2])+sum(M[w-1][h-2][2 :]))% 10**5) if '__main__'==__name__ : s() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if '__main__' = __name__ then ( s() ) else skip; operation s() pre: true post: true activity: for e : OclIterator.newOclIterator_Sequence(input, '0 0') do ( var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := (e.split())->collect( _x | (OclType["int"])->apply(_x) ) ; var M : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, w)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, h)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{1}->union(Sequence{ 0 }), 2))))) ; for i : Integer.subrange(1, w-1) do ( for j : Integer.subrange(1, h-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := M[i - 1+1][j+1].subrange(1,2) ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := M[i+1][j - 1+1].subrange(2+1) ; M[i+1][j+1] := Sequence{d}->union(Sequence{a + b}->union(Sequence{b}->union(Sequence{ c + d }))))) ; execute (((M[w - 2+1][h - 1+1].subrange(1,2))->sum() + (M[w - 1+1][h - 2+1].subrange(2+1))->sum()) mod (10)->pow(5))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(width,height): dp=[[None]*width for _ in range(height)] dp[0][0]=[0,1,0,1] for h in range(height): for w in range(width): if h==0 : dp[0][w]=[0,0,0,1] elif w==0 : dp[h][0]=[0,1,0,0] else : dp[h][w]=[dp[h-1][w][3],dp[h-1][w][0]+dp[h-1][w][1],dp[h][w-1][1],dp[h][w-1][2]+dp[h][w-1][3]] return sum(dp[-1][-1])% 100000 def main(args): while True : w,h=map(int,input().split()) if w==0 and h==0 : break result=solve(w,h) print(result) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(width : OclAny, height : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, height-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ null }, width))) ; dp->first()->first() := Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 1 }))) ; for h : Integer.subrange(0, height-1) do ( for w : Integer.subrange(0, width-1) do ( if h = 0 then ( dp->first()[w+1] := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 1 }))) ) else (if w = 0 then ( dp[h+1]->first() := Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 0 }))) ) else ( dp[h+1][w+1] := Sequence{dp[h - 1+1][w+1][3+1]}->union(Sequence{dp[h - 1+1][w+1]->first() + dp[h - 1+1][w+1][1+1]}->union(Sequence{dp[h+1][w - 1+1][1+1]}->union(Sequence{ dp[h+1][w - 1+1][2+1] + dp[h+1][w - 1+1][3+1] }))) ) ) )) ; return (dp->last()->last())->sum() mod 100000; operation main(args : OclAny) pre: true post: true activity: while true do ( var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if w = 0 & h = 0 then ( break ) else skip ; var result : OclAny := solve(w, h) ; execute (result)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dpw=[[0 for i in range(105)]for j in range(105)] dph=[[0 for i in range(105)]for j in range(105)] while 1 : w,h=map(int,raw_input().split()) if w==0 and h==0 : break for i in range(h+2): for j in range(w+2): dpw[i][j]=dph[i][j]=0 ; dpw[1][0]=dph[0][1]=1 for i in range(h): for j in range(w): if i==h-1 and j==w-1 : break dph[j][i+1]+=dph[j][i]; dpw[j+1][i]+=dpw[j][i]; dph[j][i+2]+=dpw[j][i]; dpw[j+2][i]+=dph[j][i]; print(dpw[w-1][h-1]+dpw[w][h-1]+dph[w-1][h-1]+dph[w-1][h])% 10**5 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dpw : Sequence := Integer.subrange(0, 105-1)->select(j | true)->collect(j | (Integer.subrange(0, 105-1)->select(i | true)->collect(i | (0)))) ; var dph : Sequence := Integer.subrange(0, 105-1)->select(j | true)->collect(j | (Integer.subrange(0, 105-1)->select(i | true)->collect(i | (0)))) ; while 1 do ( var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if w = 0 & h = 0 then ( break ) else skip ; for i : Integer.subrange(0, h + 2-1) do ( for j : Integer.subrange(0, w + 2-1) do ( dpw[i+1][j+1] := 0; var dph[i+1][j+1] : int := 0;)) ; dpw[1+1]->first() := 1; var dph->first()[1+1] : int := 1 ; for i : Integer.subrange(0, h-1) do ( for j : Integer.subrange(0, w-1) do ( if i = h - 1 & j = w - 1 then ( break ) else skip ; dph[j+1][i + 1+1] := dph[j+1][i + 1+1] + dph[j+1][i+1]; dpw[j + 1+1][i+1] := dpw[j + 1+1][i+1] + dpw[j+1][i+1]; ; dph[j+1][i + 2+1] := dph[j+1][i + 2+1] + dpw[j+1][i+1]; dpw[j + 2+1][i+1] := dpw[j + 2+1][i+1] + dph[j+1][i+1];)) ; (expr (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (expr (atom (name dpw)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name w))) - (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name h))) - (expr (atom (number (integer 1)))))))))) ]))) + (expr (atom (name dpw)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name w)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name h))) - (expr (atom (number (integer 1)))))))))) ])))) + (expr (atom (name dph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name w))) - (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name h))) - (expr (atom (number (integer 1)))))))))) ])))) + (expr (atom (name dph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name w))) - (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name h)))))))) ]))))))))) )))) % (expr (expr (atom (number (integer 10)))) ** (expr (atom (number (integer 5))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : w,h=map(int,input().split()) if w==0 : break mapp=[[[0]*2 for _ in range(w+2)]for _ in range(h+2)] mapp[0][0][0]=mapp[0][0][1]=1 mapp[0][2][0]=mapp[2][0][1]=-1 for i in range(0,h): for j in range(0,w): if i==h-1 and j==w-1 : break mapp[i][j+1][0]+=mapp[i][j][0] if mapp[i][j+1][0]>=100000 : mapp[i][j+1][0]-=100000 mapp[i][j+2][0]+=mapp[i][j][1] if mapp[i][j+2][0]>=100000 : mapp[i][j+2][0]-=100000 mapp[i+1][j][1]+=mapp[i][j][1] if mapp[i+1][j][1]>=100000 : mapp[i+1][j][0]-=100000 mapp[i+2][j][1]+=mapp[i][j][0] if mapp[i+2][j][1]>=100000 : mapp[i+2][j][0]-=100000 print(sum(mapp[h-1][w-1]+mapp[h][w-1]+mapp[h-1][w])% 100000) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if w = 0 then ( break ) else skip ; var mapp : Sequence := Integer.subrange(0, h + 2-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, w + 2-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 2))))) ; mapp->first()->first()->first() := 1; var mapp->first()->first()[1+1] : int := 1 ; mapp->first()[2+1]->first() := -1; var mapp[2+1]->first()[1+1] : int := -1 ; for i : Integer.subrange(0, h-1) do ( for j : Integer.subrange(0, w-1) do ( if i = h - 1 & j = w - 1 then ( break ) else skip ; mapp[i+1][j + 1+1]->first() := mapp[i+1][j + 1+1]->first() + mapp[i+1][j+1]->first() ; if mapp[i+1][j + 1+1]->first() >= 100000 then ( mapp[i+1][j + 1+1]->first() := mapp[i+1][j + 1+1]->first() - 100000 ) else skip ; mapp[i+1][j + 2+1]->first() := mapp[i+1][j + 2+1]->first() + mapp[i+1][j+1][1+1] ; if mapp[i+1][j + 2+1]->first() >= 100000 then ( mapp[i+1][j + 2+1]->first() := mapp[i+1][j + 2+1]->first() - 100000 ) else skip ; mapp[i + 1+1][j+1][1+1] := mapp[i + 1+1][j+1][1+1] + mapp[i+1][j+1][1+1] ; if mapp[i + 1+1][j+1][1+1] >= 100000 then ( mapp[i + 1+1][j+1]->first() := mapp[i + 1+1][j+1]->first() - 100000 ) else skip ; mapp[i + 2+1][j+1][1+1] := mapp[i + 2+1][j+1][1+1] + mapp[i+1][j+1]->first() ; if mapp[i + 2+1][j+1][1+1] >= 100000 then ( mapp[i + 2+1][j+1]->first() := mapp[i + 2+1][j+1]->first() - 100000 ) else skip)) ; execute ((mapp[h - 1+1][w - 1+1] + mapp[h+1][w - 1+1] + mapp[h - 1+1][w+1])->sum() mod 100000)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): while True : import sys input=sys.stdin.readline w,h=map(int,input().split()) if w==0 : break dp=[[[0,0,0,0]for _ in[0]*(w+1)]for _ in[0]*(h+1)] dp[1][0]=[0,1,0,0] dp[0][1]=[1,0,0,0] mod=10**5 for k in range(1,w+h-2): for j in range(max(0,k-h+1),min(w,k+1)): i=k-j dp[i+1][j][1]=(dp[i+1][j][1]+dp[i][j][1]+dp[i][j][3])% mod dp[i+1][j][3]=(dp[i+1][j][3]+dp[i][j][0])% mod dp[i][j+1][0]=(dp[i][j+1][0]+dp[i][j][0]+dp[i][j][2])% mod dp[i][j+1][2]=(dp[i][j+1][2]+dp[i][j][1])% mod print(sum(dp[h-1][w-1])% mod) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: while true do ( skip ; var input : OclAny := (OclFile["System.in"]).readline ; var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if w = 0 then ( break ) else skip ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (h + 1))->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (w + 1))->select(_anon | true)->collect(_anon | (Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))))))) ; dp[1+1]->first() := Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 0 }))) ; dp->first()[1+1] := Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))) ; var mod : double := (10)->pow(5) ; for k : Integer.subrange(1, w + h - 2-1) do ( for j : Integer.subrange(Set{0, k - h + 1}->max(), Set{w, k + 1}->min()-1) do ( var i : double := k - j ; dp[i + 1+1][j+1][1+1] := (dp[i + 1+1][j+1][1+1] + dp[i+1][j+1][1+1] + dp[i+1][j+1][3+1]) mod mod ; dp[i + 1+1][j+1][3+1] := (dp[i + 1+1][j+1][3+1] + dp[i+1][j+1]->first()) mod mod ; dp[i+1][j + 1+1]->first() := (dp[i+1][j + 1+1]->first() + dp[i+1][j+1]->first() + dp[i+1][j+1][2+1]) mod mod ; dp[i+1][j + 1+1][2+1] := (dp[i+1][j + 1+1][2+1] + dp[i+1][j+1][1+1]) mod mod)) ; execute ((dp[h - 1+1][w - 1+1])->sum() mod mod)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B=(int(i)for i in input().split()) print(A*B) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; execute (A * B)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=input() if a==b : print("-1") else : x=len(a) z=len(b) print(max(x,z)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; if a = b then ( execute ("-1")->display() ) else ( var x : int := (a)->size() ; var z : int := (b)->size() ; execute (Set{x, z}->max())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s1=input() s2=input() if s1==s2 : print(-1) else : print(max(len(s1),len(s2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s1 : String := (OclFile["System.in"]).readLine() ; var s2 : String := (OclFile["System.in"]).readLine() ; if s1 = s2 then ( execute (-1)->display() ) else ( execute (Set{(s1)->size(), (s2)->size()}->max())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd as __gcd def findTwoNumbers(sum,gcd): if(__gcd(gcd,sum-gcd)==gcd and sum!=gcd): print("a=",min(gcd,sum-gcd),",b=",sum-min(gcd,sum-gcd)) else : print(-1) if __name__=='__main__' : sum=8 gcd=2 findTwoNumbers(sum,gcd) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( sum := 8 ; gcd := 2 ; findTwoNumbers(sum, gcd) ) else skip; operation findTwoNumbers(sum : OclAny, gcd : OclAny) pre: true post: true activity: if (__gcd(gcd, sum - gcd) = gcd & sum /= gcd) then ( execute ("a=")->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s1=input() s2=input() if s1==s2 : print(-1) else : print(max(len(s1),len(s2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s1 : String := (OclFile["System.in"]).readLine() ; var s2 : String := (OclFile["System.in"]).readLine() ; if s1 = s2 then ( execute (-1)->display() ) else ( execute (Set{(s1)->size(), (s2)->size()}->max())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s1=input() s2=input() if s1==s2 : print(-1) else : print(max(len(s1),len(s2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s1 : String := (OclFile["System.in"]).readLine() ; var s2 : String := (OclFile["System.in"]).readLine() ; if s1 = s2 then ( execute (-1)->display() ) else ( execute (Set{(s1)->size(), (s2)->size()}->max())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s1=input() s2=input() if s1==s2 : print(-1) else : print(max(len(s1),len(s2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s1 : String := (OclFile["System.in"]).readLine() ; var s2 : String := (OclFile["System.in"]).readLine() ; if s1 = s2 then ( execute (-1)->display() ) else ( execute (Set{(s1)->size(), (s2)->size()}->max())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() if s=="zyxwvutsrqponmlkjihgfedcba" : print(-1) elif len(s)==26 : l=[] for i in range(26)[: :-1]: ds=s[i] l.append(ds) if ds!=max(l): l.sort() for j in l : if dsdisplay() ) else (if (s)->size() = 26 then ( var l : Sequence := Sequence{} ; for i : range(26)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( var ds : OclAny := s[i+1] ; execute ((ds) : l) ; if ds /= (l)->max() then ( l := l->sort() ; for j : l do ( if (ds->compareTo(j)) < 0 then ( break ) else skip) ; execute (s.subrange(1,i) + j)->display() ; break ) else skip) ) else ( for i : ("abcdefghijklmnopqrstuvwxyz")->characters() do ( if (s)->characters()->includes(i) then ( continue ) else ( execute (s + i)->display() ; break )) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import string s=input() rem=set(string.ascii_lowercase).difference(set(s)) answer=-1 for r in reversed(range(len(s)+1)): if runion((string.ascii_lowercase)) - (Set{}->union((s))) ; var answer : int := -1 ; for r : (Integer.subrange(0, (s)->size() + 1-1))->reverse() do ( if (r->compareTo((s)->size())) < 0 then ( execute ((s[r+1]) : rem) ) else skip ; for c : rem do ( var t : OclAny := s.subrange(1,r) + c ; if s < t & (answer = -1 or (t->compareTo(answer)) < 0) then ( answer := t ) else skip)) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(s): cnt="abcdefghijklmnopqrstuvwxyz" res=[0 for x in range(26)] for i in range(len(s)): a=cnt.index(s[i]) res[a]+=1 for i in range(26): if res[i]==0 : return s+cnt[i] def solve26(ss): s=ss cnt="abcdefghijklmnopqrstuvwxyz" pos=s[-1] res=cnt.index(pos)+1 s=s[:-1] for i in range(res,26): jud=True pos=cnt[i] for j in range(len(s)): if s[j]==cnt[i]: jud=False break if jud : return s+pos return solve26(s) S=input() if len(S)==26 and S=='zyxwvutsrqponmlkjihgfedcba' : print(-1) elif len(S)==26 : S=solve26(S) print(S) else : S=solve(S) print(S) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var S : String := (OclFile["System.in"]).readLine() ; if (S)->size() = 26 & S = 'zyxwvutsrqponmlkjihgfedcba' then ( execute (-1)->display() ) else (if (S)->size() = 26 then ( S := solve26(S) ; execute (S)->display() ) else ( S := solve(S) ; execute (S)->display() ) ) ; operation solve(s : OclAny) : OclAny pre: true post: true activity: var cnt : String := "abcdefghijklmnopqrstuvwxyz" ; var res : Sequence := Integer.subrange(0, 26-1)->select(x | true)->collect(x | (0)) ; for i : Integer.subrange(0, (s)->size()-1) do ( var a : int := cnt->indexOf(s[i+1]) - 1 ; res[a+1] := res[a+1] + 1) ; for i : Integer.subrange(0, 26-1) do ( if res[i+1] = 0 then ( return s + cnt[i+1] ) else skip); operation solve26(ss : OclAny) : OclAny pre: true post: true activity: s := ss ; cnt := "abcdefghijklmnopqrstuvwxyz" ; var pos : OclAny := s->last() ; res := cnt->indexOf(pos) - 1 + 1 ; s := s->front() ; for i : Integer.subrange(res, 26-1) do ( var jud : boolean := true ; pos := cnt[i+1] ; for j : Integer.subrange(0, (s)->size()-1) do ( if s[j+1] = cnt[i+1] then ( jud := false ; break ) else skip) ; if jud then ( return s + pos ) else skip) ; return solve26(s); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections s=list(input()) n=len(s) alp="abcdefghijklmnopqrstuvwxyz" alp=list(alp) co_alp=collections.Counter(alp) if n==26 : for i in range(n-1): if s[-i-1]>s[-i-2]: q="z" for sj in s[-i-1 :]: if sj>s[-i-2]: q=min(q,sj) l=s[:-i-2] l.append(q) print("".join(l)) break else : print(-1) exit() for i in range(n): co_alp[s[i]]+=1 for w,num in sorted(co_alp.items()): if num==1 : s.append(w) break print("".join(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var n : int := (s)->size() ; var alp : String := "abcdefghijklmnopqrstuvwxyz" ; alp := (alp)->characters() ; var co_alp : OclAny := .Counter(alp) ; if n = 26 then ( (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr - (expr (atom (name i)))) - (expr (atom (number (integer 1)))))))))) ])))) > (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr - (expr (atom (name i)))) - (expr (atom (number (integer 2)))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name q)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom "z"))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name sj)))) in (testlist (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr - (expr (atom (name i)))) - (expr (atom (number (integer 1)))))))) :)) ]))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name sj)))) > (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr - (expr (atom (name i)))) - (expr (atom (number (integer 2)))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name q)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name q))))))) , (argument (test (logical_test (comparison (expr (atom (name sj)))))))) ))))))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (expr - (expr (atom (name i)))) - (expr (atom (number (integer 2)))))))))) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name q)))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)))))))) ))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ))))))))))))))) ; exit() ) else skip ; for i : Integer.subrange(0, n-1) do ( co_alp[s[i+1]+1] := co_alp[s[i+1]+1] + 1) ; for _tuple : co_alp->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sort() do (var _indx : int := 1; var w : OclAny := _tuple->at(_indx); _indx := _indx + 1; var num : OclAny := _tuple->at(_indx); if num = 1 then ( execute ((w) : s) ; break ) else skip) ; execute (StringLib.sumStringsWithSeparator((s), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() old='' flag=0 sample=[chr(i)for i in range(97,97+26)] if len(s)==26 : for i,s1 in enumerate(s[: :-1]): if i!=0 and s1s1]) print(out) exit() old+=s1 if flag==0 : out=-1 else : out=s+min(set(sample)-set(s)) print(out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var old : String := '' ; var flag : int := 0 ; var sample : Sequence := Integer.subrange(97, 97 + 26-1)->select(i | true)->collect(i | ((i)->byte2char())) ; if (s)->size() = 26 then ( for _tuple : Integer.subrange(1, (s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->size())->collect( _indx | Sequence{_indx-1, (s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s1 : OclAny := _tuple->at(_indx); if i /= 0 & (s1->compareTo(old->last())) < 0 then ( var out : OclAny := s.subrange(1,(s)->size() - i - 1) + (old->characters()->select(o | (o->compareTo(s1)) > 0)->collect(o | (o)))->min() ; execute (out)->display() ; exit() ) else skip ; old := old + s1) ; if flag = 0 then ( out := -1 ) else skip ) else ( out := s + (Set{}->union((sample)) - Set{}->union((s)))->min() ) ; execute (out)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=input().split(' ') print(int(a)*int(b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split(' ') ; execute (("" + ((a)))->toInteger() * ("" + ((b)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(input()) while True : if "o" not in s : print("x") break if s[-1]=="x" : while s[-1]=="x" : s.pop() elif s[0]=="x" : while s[0]=="x" : s.pop(0) if "x" not in s : print("o") break if s[-1]=="o" : while s[-1]=="o" : s.pop() elif s[0]=="o" : while s[0]=="o" : s.pop(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; while true do ( if (s)->excludes("o") then ( execute ("x")->display() ; break ) else skip ; if s->last() = "x" then ( while s->last() = "x" do ( s := s->front()) ) else (if s->first() = "x" then ( while s->first() = "x" do ( s := s->excludingAt(0+1)) ) else skip) ; if (s)->excludes("x") then ( execute ("o")->display() ; break ) else skip ; if s->last() = "o" then ( while s->last() = "o" do ( s := s->front()) ) else (if s->first() = "o" then ( while s->first() = "o" do ( s := s->excludingAt(0+1)) ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- filename="A-large" fin=open(filename+".in","r") fout=open(filename+".out","w") casenum=int(fin.readline()) for ite in range(casenum): num_count=int(fin.readline()) fulllist=['0','1','2','3','4','5','6','7','8','9'] currlist=[] total_num=0 if num_count==0 : return_str='INSOMNIA' else : while len(currlist)toInteger() ; for ite : Integer.subrange(0, casenum-1) do ( var num_count : int := ("" + ((fin.readLine())))->toInteger() ; var fulllist : Sequence := Sequence{'0'}->union(Sequence{'1'}->union(Sequence{'2'}->union(Sequence{'3'}->union(Sequence{'4'}->union(Sequence{'5'}->union(Sequence{'6'}->union(Sequence{'7'}->union(Sequence{'8'}->union(Sequence{ '9' }))))))))) ; var currlist : Sequence := Sequence{} ; var total_num : int := 0 ; if num_count = 0 then ( var return_str : String := 'INSOMNIA' ) else ( while ((currlist)->size()->compareTo((fulllist)->size())) < 0 do ( total_num := total_num + num_count ; var numstr : String := ("" + ((total_num))) ; for s : numstr->characters() do ( if (currlist)->excludes(s) then ( execute ((s) : currlist) ) else skip)) ; return_str := numstr ) ; fout.write(StringLib.interpolateStrings("Case #{0}:{1}\n", Sequence{ite + 1, return_str}))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() print('o' if s[0]=='o' else s[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; execute (if s->first() = 'o' then 'o' else s->last() endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() print([s[-1],'o'][s[0]=='o']) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; execute (Sequence{s->last()}->union(Sequence{ 'o' })->select(s->first() = 'o'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() while "oo" in s or "xx" in s : s=s.replace("oo","o").replace("xx","x") if len(s)% 2==1 : print(s[0]) else : print("o") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; while (s)->characters()->includes("oo") or (s)->characters()->includes("xx") do ( s := s.replace("oo", "o").replace("xx", "x")) ; if (s)->size() mod 2 = 1 then ( execute (s->first())->display() ) else ( execute ("o")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def plusOne(self,digits): ls=len(digits) for index in reversed(range(ls)): if digits[index]<9 : digits[index]+=1 return digits else : digits[index]=0 digits.insert(0,1) return digits ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation plusOne(digits : OclAny) : OclAny pre: true post: true activity: var ls : int := (digits)->size() ; for index : (Integer.subrange(0, ls-1))->reverse() do ( if digits[index+1] < 9 then ( digits[index+1] := digits[index+1] + 1 ; return digits ) else ( digits[index+1] := 0 )) ; digits := digits.insertAt(0+1, 1) ; return digits; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minBinary(n): digit=[0 for i in range(3)] len=0 while(n>0): digit[len]=n % 10 len+=1 n//=10 digit=digit[: :-1] ans=0 for i in range(len): ans=max(ans,digit[i]) print("Minimum Number of binary strings needed:",ans) for i in range(1,ans+1,1): num=0 for j in range(0,len,1): if(digit[j]>0): num=num*10+1 digit[j]-=1 else : num*=10 print(num,end=" ") if __name__=='__main__' : n=564 minBinary(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 564 ; minBinary(n) ) else skip; operation minBinary(n : OclAny) pre: true post: true activity: var digit : Sequence := Integer.subrange(0, 3-1)->select(i | true)->collect(i | (0)) ; var len : int := 0 ; while (n > 0) do ( digit[len+1] := n mod 10 ; len := len + 1 ; n := n div 10) ; digit := digit(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var ans : int := 0 ; for i : Integer.subrange(0, len-1) do ( ans := Set{ans, digit[i+1]}->max()) ; execute ("Minimum Number of binary strings needed:")->display() ; for i : Integer.subrange(1, ans + 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( var num : int := 0 ; for j : Integer.subrange(0, len-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (digit[j+1] > 0) then ( num := num * 10 + 1 ; digit[j+1] := digit[j+1] - 1 ) else ( num := num * 10 )) ; execute (num)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re bracket=re.compile(r'\[([\w?+-]+)\]') incr=re.compile(r'([+-]*)([\w?])') def f(s,c): if c=='?' : return 'A' return chr(ord('A')+(ord(c)-ord('A')+s.count('+')-s.count('-'))% 26) while True : s=input().strip() if s=='.' : break s=incr.sub(lambda m : f(*m.group(1,2)),s) while '[' in s : s=bracket.sub(lambda m : m.group(1)[: :-1],s) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var bracket : OclRegex := OclRegex.compile(StringLib.rawString('\[([\w?+-]+)\]')) ; var incr : OclRegex := OclRegex.compile(StringLib.rawString('([+-]*)([\w?])')) ; skip ; while true do ( s := input()->trim() ; if s = '.' then ( break ) else skip ; s := incr.sub(lambda m : OclAny in (f((argument * (test (logical_test (comparison (expr (atom (name m)) (trailer . (name group) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))))))))), s) ; while (s)->includes('[') do ( s := bracket.sub(lambda m : OclAny in (m.group(1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))), s)) ; execute (s)->display()); operation f(s : OclAny, c : OclAny) : OclAny pre: true post: true activity: if c = '?' then ( return 'A' ) else skip ; return (('A')->char2byte() + ((c)->char2byte() - ('A')->char2byte() + s->count('+') - s->count('-')) mod 26)->byte2char(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def make(s): d=[] i=0 ans='' while idisplay()) ; execute (->display()); operation make(s : OclAny) : OclAny pre: true post: true activity: var d : Sequence := Sequence{} ; var i : int := 0 ; var ans : String := '' ; while (i->compareTo((s)->size())) < 0 do ( if ('+-[]')->characters()->excludes(s[(s)->size() - i - 1+1]) then ( execute (((s[(s)->size() - i - 1+1])->char2byte()) : d) ) else ( if s[(s)->size() - i - 1+1] = '+' then ( if d->last() /= ('?')->char2byte() then ( d->last() := ((d->last() + 1) - ('A')->char2byte()) mod 26 + ('A')->char2byte() ) else skip ) else (if s[(s)->size() - i - 1+1] = '-' then ( if d->last() /= ('?')->char2byte() then ( d->last() := ((d->last() - 1) - ('A')->char2byte()) mod 26 + ('A')->char2byte() ) else skip ) else ( var end : double := (s)->size() - i - 1 ; var st : double := (s)->size() - i - 2 ; var p : int := 1 ; while 1 do ( if s[st+1] = ']' then ( p := p + 1 ) else (if s[st+1] = '[' then ( p := p - 1 ) else skip) ; if p = 0 then ( for j : Integer.subrange(0, (d)->size()-1) do ( ans := ans + (d[j+1])->byte2char()) ; ans := ans + make(s.subrange(st + 1+1, end)) ; d := Sequence{} ; i := (s)->size() - st - 1 ; break ) else skip ; st := st - 1) ) ) ) ; i := i + 1) ; for j : Integer.subrange(0, (d)->size()-1) do ( ans := ans + (d[j+1])->byte2char()) ; return ans(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from itertools import product from collections import deque read=sys.stdin.read def enc(S : str,p : int): return chr((ord(S)+p-ord("A"))% 26+ord("A")) def f(S : str): res=[] plus_minus=0 stack=[] for s in S : if("A"<=s<="Z"): s=enc(s,plus_minus) plus_minus=0 res.append(s) elif s=="-" : plus_minus-=1 elif s=="+" : plus_minus+=1 elif s=="[" : stack.append(len(res)) else : if not stack : return None rev_i=stack.pop() res[rev_i :]=res[rev_i :][: :-1] if(stack or plus_minus): raise Exception return None return "".join(res) def solve(S : str): ans="Z"*len(S) L=[chr(ord("A")+i)for i in range(26)] for it in product(L,repeat=S.count("?")): *it,=it idx=0 T="" for s in S : if(s=="?"): T+=it[idx] idx+=1 else : T+=s res=f(T) if(res is None): continue ans=min(ans,res) print(ans) def main(): S=read() for s in S.split("\n"): if(s=="."): break solve(s) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { suite`nestedAttributeDefinitions operation initialise() pre: true post: true activity: skip ; skip ; skip ; var read : OclAny := (OclFile["System.in"]).read ; skip ; skip ; skip ; (testlist_star_expr (star_expr * (expr (atom (name it)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name it)))) ,)} := it; operation enc(S : String, p : int) : OclAny pre: true post: true activity: return (((S)->char2byte() + p - ("A")->char2byte()) mod 26 + ("A")->char2byte())->byte2char(); operation f(S : String) : OclAny pre: true post: true activity: var res : Sequence := Sequence{} ; var plus_minus : int := 0 ; var stack : Sequence := Sequence{} ; for s : S->characters() do ( if ("A" <= s & (s <= "Z")) then ( var s : OclAny := enc(s, plus_minus) ; plus_minus := 0 ; execute ((s) : res) ) else (if s = "-" then ( plus_minus := plus_minus - 1 ) else (if s = "+" then ( plus_minus := plus_minus + 1 ) else (if s = "[" then ( execute (((res)->size()) : stack) ) else ( if not(stack) then ( return null ) else skip ; var rev_i : OclAny := stack->last() ; stack := stack->front() ; res.subrange(rev_i+1) := res.subrange(rev_i+1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ) ) ) ) ) ; if (stack or plus_minus) then ( error ProgramException.newProgramException ; return null ) else skip ; return StringLib.sumStringsWithSeparator((res), ""); operation solve(S : String) pre: true post: true activity: var ans : String := StringLib.nCopies("Z", (S)->size()) ; var L : Sequence := Integer.subrange(0, 26-1)->select(i | true)->collect(i | ((("A")->char2byte() + i)->byte2char())) ; for it : product(L, (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (name S)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "?"))))))) ))))))))) do (suite); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- alps="ABCDEFGHIJKLMNOPQRSTUVWXYZ" def reverse(data): ret="" while(True): if data[0]=="[" and(not("[" in data[1 :])or data.index("[")>data.index("]")): tmp=data[1 : data.index("]")][: :-1] ret+=tmp ret+=data[data.index("]")+1 :] return(ret) else : ret+=data[0] data=data[1 :] while(True): a=input() if a=="." : quit() ans="" plus=0 count=0 while(a!=""): if a[0]in["[","]"]: ans+=a[0] plus=0 count+=1 elif a[0]=="?" : ans+="A" plus=0 elif a[0]=="+" : plus+=1 elif a[0]=="-" : plus-=1 else : t=alps.index(a[0]) ans+=alps[(t+plus)% 26] plus=0 a=a[1 :] count//=2 indl=[i for i,x in enumerate(a)if x=="["] indr=[i for i,x in enumerate(a)if x=="]"] for i in range(count): ans=reverse(ans) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var alps : String := "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; skip ; while (true) do ( var a : String := (OclFile["System.in"]).readLine() ; if a = "." then ( quit() ) else skip ; var ans : String := "" ; var plus : int := 0 ; var count : int := 0 ; while (a /= "") do ( if (Sequence{"["}->union(Sequence{ "]" }))->includes(a->first()) then ( ans := ans + a->first() ; plus := 0 ; count := count + 1 ) else (if a->first() = "?" then ( ans := ans + "A" ; plus := 0 ) else (if a->first() = "+" then ( plus := plus + 1 ) else (if a->first() = "-" then ( plus := plus - 1 ) else ( var t : int := alps->indexOf(a->first()) - 1 ; ans := ans + alps[(t + plus) mod 26+1] ; plus := 0 ) ) ) ) ; a := a->tail()) ; count := count div 2 ; var indl : Sequence := Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} )->select(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in x = "[")->collect(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in (i)) ; var indr : Sequence := Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} )->select(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in x = "]")->collect(_tuple | let i : OclAny = _tuple->at(1) in let x : OclAny = _tuple->at(2) in (i)) ; for i : Integer.subrange(0, count-1) do ( ans := reverse(ans)) ; execute (ans)->display()); operation reverse(data : OclAny) : OclAny pre: true post: true activity: var ret : String := "" ; while (true) do ( if data->first() = "[" & (not(((data->tail())->includes("["))) or (data->indexOf("[") - 1->compareTo(data->indexOf("]") - 1)) > 0) then ( var tmp : OclAny := data.subrange(1+1, data->indexOf("]") - 1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; ret := ret + tmp ; ret := ret + data.subrange(data->indexOf("]") - 1 + 1+1) ; return (ret) ) else ( ret := ret + data->first() ; data := data->tail() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) a_tmp=input().split() a=[[]for i in range(n)] for i in range(n): a[i]=int(a_tmp[i]) a2=[[]for i in range(n)] for i in range(n): tmp=a[i] coun=0 while 1 : if tmp % 2==0 : tmp=tmp/2 coun+=1 else : break a2[i]=coun print(sum(a2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a_tmp : OclAny := input().split() ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, n-1) do ( a[i+1] := ("" + ((a_tmp[i+1])))->toInteger()) ; var a2 : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, n-1) do ( var tmp : OclAny := a[i+1] ; var coun : int := 0 ; while 1 do ( if tmp mod 2 = 0 then ( tmp := tmp / 2 ; coun := coun + 1 ) else ( break )) ; a2[i+1] := coun) ; execute ((a2)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.stdin=open("data.txt") sys.stdout=open("out.txt","w") input=sys.stdin.readline for case in range(int(input())): n=int(input()) if n==0 : print("Case #%s: INSOMNIA" %(case+1)) else : left=[1]*10 count=10 for i in range(1,10000000): for ch in map(int,str(n*i)): if left[ch]: left[ch]=0 count-=1 if count==0 : print("Case #%s: %s" %(case+1,n*i)) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("data.txt")) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile("out.txt")) ; var input : OclAny := (OclFile["System.in"]).readline ; for case : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( execute (StringLib.format("Case #%s: INSOMNIA",(case + 1)))->display() ) else ( var left : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, 10) ; var count : int := 10 ; for i : Integer.subrange(1, 10000000-1) do ( for ch : (("" + ((n * i))))->collect( _x | (OclType["int"])->apply(_x) ) do ( if left[ch+1] then ( left[ch+1] := 0 ; count := count - 1 ) else skip) ; if count = 0 then ( execute (StringLib.format("Case #%s: %s",Sequence{case + 1, n * i}))->display() ; break ) else skip) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def swap(l,i,j): aux=l[i] l[i]=l[j] l[j]=aux def maximize(l,k): for i in range(len(l)-1): if k==0 : break j=max((j for j in range(i+1,min(len(l),i+1+k))),key=lambda j :(l[j],-j)) if l[i]toInteger())), ''))->display(); operation swap(l : OclAny, i : OclAny, j : OclAny) pre: true post: true activity: var aux : OclAny := l[i+1] ; l[i+1] := l[j+1] ; l[j+1] := aux; operation maximize(l : OclAny, k : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, (l)->size() - 1-1) do ( if k = 0 then ( break ) else skip ; j := Set{Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name j)))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)))))))) )))))))) , (argument (test (logical_test (comparison (expr (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))) + (expr (atom (name k))))))))) ))))))))) ))))))))}, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name j)))) : (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))) , (test (logical_test (comparison (expr - (expr (atom (name j)))))))) ))))))))}->max() ; if (l[i+1]->compareTo(l[j+1])) < 0 then ( for p : Integer.subrange(i - 1 + 1, j - 1)->reverse() do ( swap(l, p, p + 1)) ; k := k - j - i ) else skip) ; return l; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def c_to_int(char): return ord(char)-65 def solve(s): count=0 table=[] for str in s : if str=='+' : count+=1 elif str=='-' : count-=1 elif str=='[' : table.append(str) elif str==']' : table.append(str) elif str=='?' : table.append(str) count=0 else : table.append((c_to_int(str)+count)% 26) count=0 for i in range(len(table)): if table[i]=='?' : table[i]=0 return(table) def rev(table): ret="" i=0 while i0 : if table[i_]=='[' : c+=1 if table[i_]==']' : c-=1 i_+=1 ret+=rev(table[i+1 : i_-1])[: :-1] i=i_-1 elif table[i]==']' : pass else : ret+=chr(table[i]+65) i+=1 return ret while True : S=input() if S[0]=='.' : break ans=rev(solve(S)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; while true do ( var S : String := (OclFile["System.in"]).readLine() ; if S->first() = '.' then ( break ) else skip ; var ans : OclAny := rev(solve(S)) ; execute (ans)->display()); operation c_to_int(char : OclAny) : OclAny pre: true post: true activity: return (char)->char2byte() - 65; operation solve(s : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var table : Sequence := Sequence{} ; for OclType["String"] : s do ( if OclType["String"] = '+' then ( count := count + 1 ) else (if OclType["String"] = '-' then ( count := count - 1 ) else (if OclType["String"] = '[' then ( execute ((OclType["String"]) : table) ) else (if OclType["String"] = ']' then ( execute ((OclType["String"]) : table) ) else (if OclType["String"] = '?' then ( execute ((OclType["String"]) : table) ; count := 0 ) else ( execute (((c_to_int(OclType["String"]) + count) mod 26) : table) ; count := 0 ) ) ) ) ) ) ; for i : Integer.subrange(0, (table)->size()-1) do ( if table[i+1] = '?' then ( table[i+1] := 0 ) else skip) ; return (table); operation rev(table : OclAny) : OclAny pre: true post: true activity: var ret : String := "" ; var i : int := 0 ; while (i->compareTo((table)->size())) < 0 do ( if table[i+1] = '[' then ( var c : int := 1 ; var i_ : int := i + 1 ; while c > 0 do ( if table[i_+1] = '[' then ( c := c + 1 ) else skip ; if table[i_+1] = ']' then ( c := c - 1 ) else skip ; i_ := i_ + 1) ; ret := ret + rev(table.subrange(i + 1+1, i_ - 1))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; i := i_ - 1 ) else (if table[i+1] = ']' then ( skip ) else ( ret := ret + (table[i+1] + 65)->byte2char() ) ) ; i := i + 1) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def find_LCM(x,y): return(x*y)//gcd(x,y) def CountPairs(n,m,A,B): cnt=0 lcm=find_LCM(A,B) for i in range(1,n+1): cnt+=(m+(i % lcm))//lcm return cnt if __name__=="__main__" : n,m,A,B=60,90,5,10 print(CountPairs(n,m,A,B)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( Sequence{n,m,A,B} := Sequence{60,90,5,10} ; execute (CountPairs(n, m, A, B))->display() ) else skip; operation find_LCM(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return (x * y) div gcd(x, y); operation CountPairs(n : OclAny, m : OclAny, A : OclAny, B : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; var lcm : OclAny := find_LCM(A, B) ; for i : Integer.subrange(1, n + 1-1) do ( cnt := cnt + (m + (i mod lcm)) div lcm) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_input(): while True : try : yield ''.join(input()) except EOFError : break N=list(get_input()) for ll in range(len(N)): a=[int(i)for i in N[ll].split(",")] l=[] totalLen=0 for i in range(10): l.append(a[i]) totalLen+=a[i] v1=a[10] v2=a[11] midPoint=totalLen*v1/(v1+v2) ans=10 for i in range(10): midPoint-=l[i] if midPoint<=0 : ans=i+1 break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : Sequence := (OclIterator.newOclIterator_Function(lambda _i : int in self.get_input(_i))) ; for ll : Integer.subrange(0, (N)->size()-1) do ( var a : Sequence := N[ll+1].split(",")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var l : Sequence := Sequence{} ; var totalLen : int := 0 ; for i : Integer.subrange(0, 10-1) do ( execute ((a[i+1]) : l) ; totalLen := totalLen + a[i+1]) ; var v1 : OclAny := a[10+1] ; var v2 : OclAny := a[11+1] ; var midPoint : double := totalLen * v1 / (v1 + v2) ; var ans : int := 10 ; for i : Integer.subrange(0, 10-1) do ( midPoint := midPoint - l[i+1] ; if midPoint <= 0 then ( ans := i + 1 ; break ) else skip) ; execute (ans)->display()); operation get_input(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; while true do ( try ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return StringLib.sumStringsWithSeparator(((OclFile["System.in"]).readLine()), '')) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import array import sys def solve(ls,v1,v2): lsum=sum(ls) d1=v1*lsum/(v1+v2) d=0.0 for i in range(len(ls)): d+=ls[i] if d>=d1 : break else : continue return i+1 if __name__=="__main__" : for line in sys.stdin : vals=array.array("d",map(float,line.split(","))) ls=vals[: 10] v1,v2=vals[-2 :] print(solve(ls,v1,v2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( for line : OclFile["System.in"] do ( var vals : OclAny := array.array("d", (line.split(","))->collect( _x | (OclType["double"])->apply(_x) )) ; ls := vals.subrange(1,10) ; Sequence{v1,v2} := vals.subrange(-2+1) ; execute (solve(ls, v1, v2))->display()) ) else skip; operation solve(ls : OclAny, v1 : OclAny, v2 : OclAny) : OclAny pre: true post: true activity: var lsum : OclAny := (ls)->sum() ; var d1 : double := v1 * lsum / (v1 + v2) ; var d : double := 0.0 ; for i : Integer.subrange(0, (ls)->size()-1) do ( d := d + ls[i+1] ; if (d->compareTo(d1)) >= 0 then ( break ) else ( continue )) ; return i + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,v1,v2=map(int,input().split(",")) kyo=0 for i in l1,l2,l3,l4,l5,l6,l7,l8,l9,l10 : kyo+=i v=v1+v2 x=kyo/v ans=v1*x flag=0 for j in l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,0 : if ans>0 : ans-=j flag+=1 else : print(flag) break except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var l1 : OclAny := null; var l2 : OclAny := null; var l3 : OclAny := null; var l4 : OclAny := null; var l5 : OclAny := null; var l6 : OclAny := null; var l7 : OclAny := null; var l8 : OclAny := null; var l9 : OclAny := null; var l10 : OclAny := null; var v1 : OclAny := null; var v2 : OclAny := null; Sequence{l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,v1,v2} := (input().split(","))->collect( _x | (OclType["int"])->apply(_x) ) ; var kyo : int := 0 ; for i : l1, l2, l3, l4, l5, l6, l7, l8, l9, l10 do ( kyo := kyo + i) ; var v : OclAny := v1 + v2 ; var x : double := kyo / v ; var ans : double := v1 * x ; var flag : int := 0 ; for j : l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, 0 do ( if ans > 0 then ( ans := ans - j ; flag := flag + 1 ) else ( execute (flag)->display() ; break ))) catch (_e : OclException) do ( break) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : temp=[int(_)for _ in input().split(',')] length,x,y=0,0,0 for _ in temp[: 10]: length+=_ y=(length*temp[-1])/(temp[-1]+temp[-2]) x=length-y for number,_ in enumerate(temp[: 10]): if x-_>=0 : x-=_ else : if x==0 : break else : number+=1 break print(number) except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var temp : Sequence := input().split(',')->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var length : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{length,x,y} := Sequence{0,0,0} ; for _anon : temp.subrange(1,10) do ( length := length + _anon) ; var y : double := (length * temp->last()) / (temp->last() + temp->front()->last()) ; var x : double := length - y ; for _tuple : Integer.subrange(1, (temp.subrange(1,10))->size())->collect( _indx | Sequence{_indx-1, (temp.subrange(1,10))->at(_indx)} ) do (var _indx : int := 1; var number : OclAny := _tuple->at(_indx); _indx := _indx + 1; var _anon : OclAny := _tuple->at(_indx); if x - _anon >= 0 then ( x := x - _anon ) else ( if x = 0 then ( break ) else ( number := number + 1 ; break ) )) ; execute (number)->display()) catch (_e : OclException) do ( break) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : try : a=list(map(int,input().split(','))) except : break pos=[0]*12 v1,v2=a[10],a[11] for i in range(10): pos[i+2]=pos[i+1]+a[i] L=pos[11] pq=(L*v1)//(v1+v2); pr=(L*v1)%(v1+v2); i=10 while pqcollect( _x | (OclType["int"])->apply(_x) ))) catch (_e : OclException) do ( break) ; var pos : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 12) ; var v1 : OclAny := null; var v2 : OclAny := null; Sequence{v1,v2} := Sequence{a[10+1],a[11+1]} ; for i : Integer.subrange(0, 10-1) do ( pos[i + 2+1] := pos[i + 1+1] + a[i+1]) ; var L : OclAny := pos[11+1] ; var pq : int := (L * v1) div (v1 + v2); ; var pr : int := (L * v1) mod (v1 + v2); ; var i : int := 10 ; while (pq->compareTo(pos[i+1])) < 0 do ( i := i - 1) ; if pq = pos[i+1] & pr = 0 then ( i := i - 1 ) else skip ; execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) values=[1000,100,10,1] ranges=[[1,2],range(10),range(10),range(10)] def attempt(previous,digits,x): least=None for i in range(4): for d in ranges[i]: y=x+(d-digits[i])*values[i] if y<=2011 and y>=previous and(least==None or ytoInteger() ; var values : Sequence := Sequence{1000}->union(Sequence{100}->union(Sequence{10}->union(Sequence{ 1 }))) ; var ranges : Sequence := Sequence{Sequence{1}->union(Sequence{ 2 })}->union(Sequence{Integer.subrange(0, 10-1)}->union(Sequence{Integer.subrange(0, 10-1)}->union(Sequence{ Integer.subrange(0, 10-1) }))) ; skip ; previous := 0 ; var result : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; digits := (((s)->characters())->collect( _x | (OclType["int"])->apply(_x) )) ; x := ("" + ((s)))->toInteger() ; y := attempt(previous, digits, x) ; if y = null then ( execute ('No solution')->display() ; skip; sys.exit() ) else skip ; execute ((y) : result) ; previous := y) ; execute (StringLib.sumStringsWithSeparator(((result)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); operation attempt(previous : OclAny, digits : OclAny, x : OclAny) : OclAny pre: true post: true activity: var least : OclAny := null ; for i : Integer.subrange(0, 4-1) do ( for d : ranges[i+1] do ( var y : OclAny := x + (d - digits[i+1]) * values[i+1] ; if y <= 2011 & (y->compareTo(previous)) >= 0 & (least = null or (y->compareTo(least)) < 0) then ( least := y ) else skip)) ; return least; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(input()) d=[] for i in range(n): d.append(input()) ans=[] bad='No solution' low=1000 for date in d : lowest=100500 for i in range(10): for j in range(i==0,5): changed=date[: j]+str(i)+date[j+1 :] if lowest>int(changed)>=low : lowest=int(changed) if lowest>2011 : print(bad) sys.exit(0) ans.append(str(lowest)) low=lowest print('\n'.join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : d)) ; var ans : Sequence := Sequence{} ; var bad : String := 'No solution' ; var low : int := 1000 ; for date : d do ( var lowest : int := 100500 ; for i : Integer.subrange(0, 10-1) do ( for j : Integer.subrange(i = 0, 5-1) do ( var changed : OclAny := date.subrange(1,j) + ("" + ((i))) + date.subrange(j + 1+1) ; if (lowest->compareTo(("" + ((changed)))->toInteger())) > 0 & (("" + ((changed)))->toInteger() >= low) then ( lowest := ("" + ((changed)))->toInteger() ) else skip)) ; if lowest > 2011 then ( execute (bad)->display() ; sys.exit(0) ) else skip ; execute ((("" + ((lowest)))) : ans) ; low := lowest) ; execute (StringLib.sumStringsWithSeparator((ans), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(): S,W=map(int,input().split()) print("unsafe")if(S<=W)else print("safe") if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var S : OclAny := null; var W : OclAny := null; Sequence{S,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "unsafe"))))))) )))))) if (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name S)))) <= (comparison (expr (atom (name W)))))))) ))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "safe"))))))) )))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,k=map(int,input().split()) w=list(map(int,input().split())) if k==1 : print(min(w)) elif k>2 : print(max(w)) else : print(max(w[0],w[-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if k = 1 then ( execute ((w)->min())->display() ) else (if k > 2 then ( execute ((w)->max())->display() ) else ( execute (Set{w->first(), w->last()}->max())->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(input()) d=[] for i in range(n): d.append(input()) ans=[] bad='No solution' low=1000 for date in d : lowest=100500 for i in range(10): for j in range(i==0,5): changed=date[: j]+str(i)+date[j+1 :] if lowest>int(changed)>=low : lowest=int(changed) if lowest>2011 : print(bad) sys.exit(0) ans.append(str(lowest)) low=lowest print('\n'.join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : d)) ; var ans : Sequence := Sequence{} ; var bad : String := 'No solution' ; var low : int := 1000 ; for date : d do ( var lowest : int := 100500 ; for i : Integer.subrange(0, 10-1) do ( for j : Integer.subrange(i = 0, 5-1) do ( var changed : OclAny := date.subrange(1,j) + ("" + ((i))) + date.subrange(j + 1+1) ; if (lowest->compareTo(("" + ((changed)))->toInteger())) > 0 & (("" + ((changed)))->toInteger() >= low) then ( lowest := ("" + ((changed)))->toInteger() ) else skip)) ; if lowest > 2011 then ( execute (bad)->display() ; sys.exit(0) ) else skip ; execute ((("" + ((lowest)))) : ans) ; low := lowest) ; execute (StringLib.sumStringsWithSeparator((ans), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num,k=input().split("") num=[int(i)for i in num] k=int(k) def findMax(lst,k): if k>=len(lst): k=len(lst)-1 maxNum=lst[0] index=0 for i in range(1,k+1): if lst[i]>maxNum : maxNum=lst[i] index=i if maxNum==9 : break return index def shiftLeft(end,start,lst): for i in range(start,end,-1): lst[i],lst[i-1]=lst[i-1],lst[i] return lst curPos=0 ans=[] while k!=0 and curPosselect(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var k : int := ("" + ((k)))->toInteger() ; skip ; skip ; var curPos : int := 0 ; var ans : Sequence := Sequence{} ; while k /= 0 & (curPos->compareTo((num)->size())) < 0 do ( index := findMax(num.subrange(curPos+1), k) ; shiftLeft(curPos, curPos + index, num) ; k := k - index ; curPos := curPos + 1) ; for ele : num do ( execute (ele)->display()); operation findMax(lst : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (k->compareTo((lst)->size())) >= 0 then ( k := (lst)->size() - 1 ) else skip ; var maxNum : OclAny := lst->first() ; var index : int := 0 ; for i : Integer.subrange(1, k + 1-1) do ( if (lst[i+1]->compareTo(maxNum)) > 0 then ( maxNum := lst[i+1] ; index := i ; if maxNum = 9 then ( break ) else skip ) else skip) ; return index; operation shiftLeft(end : OclAny, start : OclAny, lst : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(end + 1, start)->reverse() do ( var lst[i+1] : OclAny := null; var lst[i - 1+1] : OclAny := null; Sequence{lst[i+1],lst[i - 1+1]} := Sequence{lst[i - 1+1],lst[i+1]}) ; return lst; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(input()) d=[] for i in range(n): d.append(input()) ans=[] bad='No solution' low=1000 for date in d : lowest=100500 for i in range(10): for j in range(i==0,5): changed=date[: j]+str(i)+date[j+1 :] if lowest>int(changed)>=low : lowest=int(changed) if lowest>2011 : print(bad) sys.exit(0) ans.append(str(lowest)) low=lowest print('\n'.join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : d)) ; var ans : Sequence := Sequence{} ; var bad : String := 'No solution' ; var low : int := 1000 ; for date : d do ( var lowest : int := 100500 ; for i : Integer.subrange(0, 10-1) do ( for j : Integer.subrange(i = 0, 5-1) do ( var changed : OclAny := date.subrange(1,j) + ("" + ((i))) + date.subrange(j + 1+1) ; if (lowest->compareTo(("" + ((changed)))->toInteger())) > 0 & (("" + ((changed)))->toInteger() >= low) then ( lowest := ("" + ((changed)))->toInteger() ) else skip)) ; if lowest > 2011 then ( execute (bad)->display() ; sys.exit(0) ) else skip ; execute ((("" + ((lowest)))) : ans) ; low := lowest) ; execute (StringLib.sumStringsWithSeparator((ans), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter import sys input=sys.stdin.readline def print(*args,end='\n',sep=' ')->None : sys.stdout.write(sep.join(map(str,args))+end) def Solve(): s=input().strip(); t=input().strip(); z=s ; e=True sc=dict(Counter(s)); tc=dict(Counter(t)) for i in t : if i not in sc.keys()or sc[i]==0 or len(t)>len(s): print("need tree") return else : sc[i]-=1 if i not in z : e=False else : z=z[z.index(i)+1 :] if e : print("automaton") else : if len(t)==len(s): print("array") else : print("both") if __name__=="__main__" : Solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; if __name__ = "__main__" then ( Solve() ) else skip; (funcdef def name print ( (typedargslist (args * (named_parameter (name args))) , (def_parameters (def_parameter (named_parameter (name end)) = (test (logical_test (comparison (expr (atom ' ')))))) , (def_parameter (named_parameter (name sep)) = (test (logical_test (comparison (expr (atom ' ')))))))) ) -> (test (logical_test (comparison (expr (atom None))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name sep)) (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name args)))))))) ))))))))) )))) + (expr (atom (name end))))))))) )))))))))))))) operation Solve() pre: true post: true activity: var s : OclAny := input()->trim(); var t : OclAny := input()->trim(); var z : OclAny := s; var e : boolean := true ; var sc : Map := ((expr (atom (name Counter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))); var tc : Map := ((expr (atom (name Counter)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) ))))) ; for i : t do ( if (sc.keys())->excludes(i) or sc[i+1] = 0 or ((t)->size()->compareTo((s)->size())) > 0 then ( execute ("need tree")->display() ; return ) else ( sc[i+1] := sc[i+1] - 1 ) ; if (z)->excludes(i) then ( e := false ) else ( z := z.subrange(z->indexOf(i) - 1 + 1+1) )) ; if e then ( execute ("automaton")->display() ) else ( if (t)->size() = (s)->size() then ( execute ("array")->display() ) else ( execute ("both")->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- str1=input(); str2=input(); str3=list(str1); str4=list(str1) if len(str1)==len(str2): for i in str2 : if i not in str3 : print("need tree") break str3.remove(i) else : print("array") elif len(str1)characters(); var str4 : Sequence := (str1)->characters() ; if (str1)->size() = (str2)->size() then ( (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name str2))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name i)))) not in (comparison (expr (atom (name str3))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "need tree"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name str3)) (trailer . (name remove) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "array"))))))) ))))))))))))))) ) else (if ((str1)->size()->compareTo((str2)->size())) < 0 then ( execute ("need tree")->display() ) else ( var s : String := ""; var ind : int := 0 ; for i : str2->characters() do ( if (str3)->includes(i) then ( s := s + i; ind := str3->indexOf(i) - 1; str3 := str3.subrange(ind + 1+1) ) else ( break )) ; if (s)->characters()->includes(str2) then ( execute ("automaton")->display() ) else ( (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name str2))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name i)))) not in (comparison (expr (atom (name str4))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "need tree"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name str4)) (trailer . (name remove) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "both"))))))) ))))))))))))))) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() t=input() def is_same_order(): current=0 for letter in t : index=s.find(letter,current) if index==-1 : return False current=index+1 return True def is_same_chars(): for char in set(t): if t.count(char)>s.count(char): return False return True if is_same_chars(): if len(t)==len(s): print("array") elif is_same_order(): print("automaton") else : print("both") else : print("need tree") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; skip ; skip ; if is_same_chars() then ( if (t)->size() = (s)->size() then ( execute ("array")->display() ) else (if is_same_order() then ( execute ("automaton")->display() ) else ( execute ("both")->display() ) ) ) else ( execute ("need tree")->display() ); operation is_same_order() : OclAny pre: true post: true activity: var current : int := 0 ; for letter : t->characters() do ( var index : int := s->indexOf(letter, current) - 1 ; if index = -1 then ( return false ) else skip ; current := index + 1) ; return true; operation is_same_chars() : OclAny pre: true post: true activity: for char : Set{}->union((t)) do ( if (t->count(char)->compareTo(s->count(char))) > 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): s=input() t=input() scount=Counter(s) tcount=Counter(t) for i in range(ord('a'),ord('z')+1): val=chr(i) if val not in tcount : continue if(val not in scount)or tcount[val]>scount[val]: return print("need tree") i=0 j=0 while i=len(t): return print("automaton") if len(t)==len(s): return print("array") return print("both") def main(): t=1 for _ in range(t): solution() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; main(); operation solution() : OclAny pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var scount : OclAny := Counter(s) ; var tcount : OclAny := Counter(t) ; for i : Integer.subrange(('a')->char2byte(), ('z')->char2byte() + 1-1) do ( var val : String := (i)->byte2char() ; if (tcount)->excludes(val) then ( continue ) else skip ; if ((scount)->excludes(val)) or (tcount->at(val)->compareTo(scount->at(val))) > 0 then ( return ("need tree")->display() ) else skip) ; var i : int := 0 ; var j : int := 0 ; while (i->compareTo((t)->size())) < 0 & (j->compareTo((s)->size())) < 0 do ( if t[i+1] = s[j+1] then ( i := i + 1 ) else skip ; j := j + 1) ; if (i->compareTo((t)->size())) >= 0 then ( return ("automaton")->display() ) else skip ; if (t)->size() = (s)->size() then ( return ("array")->display() ) else skip ; return ("both")->display(); operation main() pre: true post: true activity: t := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count(N): a=0 ; a=(N*(N+1))/2 ; return int(a); N=4 ; print(count(N)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 4; ; execute (count(N))->display();; operation count(N : OclAny) pre: true post: true activity: var a : int := 0; ; a := (N * (N + 1)) / 2; ; return ("" + ((a)))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkPrime(number): num=int(number) for i in range(2,int(num**0.5)): if((num % i)==0): return False return True def splitIntoPrimes(number): if(number==''): return 0 if(len(number)<=6 and checkPrime(number)): return 1 else : numLen=len(number) ans=1000000 for i in range(1,(min(6,numLen)+1)): if(checkPrime(number[: i])): val=splitIntoPrimes(number[i :]) if(val!=-1): ans=min(ans,1+val) if(ans==1000000): return-1 return ans print(splitIntoPrimes("13499315")) print(splitIntoPrimes("43")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; execute (splitIntoPrimes("13499315"))->display() ; execute (splitIntoPrimes("43"))->display(); operation checkPrime(number : OclAny) : OclAny pre: true post: true activity: var num : int := ("" + ((number)))->toInteger() ; for i : Integer.subrange(2, ("" + (((num)->pow(0.5))))->toInteger()-1) do ( if ((num mod i) = 0) then ( return false ) else skip) ; return true; operation splitIntoPrimes(number : OclAny) : OclAny pre: true post: true activity: if (number = '') then ( return 0 ) else skip ; if ((number)->size() <= 6 & checkPrime(number)) then ( return 1 ) else ( var numLen : int := (number)->size() ; var ans : int := 1000000 ; for i : Integer.subrange(1, (Set{6, numLen}->min() + 1)-1) do ( if (checkPrime(number.subrange(1,i))) then ( var val : OclAny := splitIntoPrimes(number.subrange(i+1)) ; if (val /= -1) then ( ans := Set{ans, 1 + val}->min() ) else skip ) else skip) ; if (ans = 1000000) then ( return -1 ) else skip ; return ans ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() ans=0 def knocked(left,right,s,n,idx): if left==-1 and right==n : return False if left==-1 : return s[right]=='L' if right==n : return s[left]=='R' if s[left]=='R' and s[right]=='L' : if(right-left)% 2==0 and right-(right-left)//2==idx : return False else : return True elif s[left]=='R' or s[right]=='L' : return True else : return False for i in range(n): if s[i]!='.' : continue ; dl=i-1 dr=i+1 while dl>=0 and s[dl]=='.' : dl-=1 while drtoInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; skip ; for i : Integer.subrange(0, n-1) do ( if s[i+1] /= '.' then ( continue; ) else skip ; var dl : double := i - 1 ; var dr : OclAny := i + 1 ; while dl >= 0 & s[dl+1] = '.' do ( dl := dl - 1) ; while (dr->compareTo(n)) < 0 & s[dr+1] = '.' do ( dr := dr + 1) ; if not(knocked(dl, dr, s, n, i)) then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); operation knocked(left : OclAny, right : OclAny, s : OclAny, n : OclAny, idx : OclAny) : OclAny pre: true post: true activity: if left = -1 & right = n then ( return false ) else skip ; if left = -1 then ( return s[right+1] = 'L' ) else skip ; if right = n then ( return s[left+1] = 'R' ) else skip ; if s[left+1] = 'R' & s[right+1] = 'L' then ( if (right - left) mod 2 = 0 & right - (right - left) div 2 = idx then ( return false ) else ( return true ) ) else (if s[left+1] = 'R' or s[right+1] = 'L' then ( return true ) else ( return false ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,inspect problemName='counting_sheep' runOnRealData=False def digits(N): return set(map(int,str(N))) def solution(N): if N==0 : return 'INSOMNIA' allDigits=set(range(10)) multiple=0 while len(allDigits)>0 : multiple+=N allDigits=allDigits.difference(digits(multiple)) return multiple currentDir=os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) inputString='A-large.in' outputString=problemName+'_output' inFile=os.path.join(currentDir,'inputfiles',inputString) outFile=os.path.join(currentDir,'outputfiles','%s.txt' % outputString) if os.path.exists(outFile): os.remove(outFile) with open(inFile,'r')as inputfile : numberOfCases=int(inputfile.readline()) for case in xrange(1,numberOfCases+1): N=int(inputfile.readline()) result=solution(N) with open(outFile,'a')as f : f.write('Case #%d: %s\n' %(case,str(result))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var problemName : String := 'counting_sheep' ; var runOnRealData : boolean := false ; skip ; skip ; var currentDir : OclAny := os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) ; var inputString : String := 'A-large.in' ; var outputString : String := problemName + '_output' ; var inFile : OclAny := os.path.join(currentDir, 'inputfiles', inputString) ; var outFile : OclAny := os.path.join(currentDir, 'outputfiles', StringLib.format('%s.txt',outputString)) ; if os.path.exists(outFile) then ( execute ((outFile) /: os) ) else skip ; try (var inputfile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(inFile)); var numberOfCases : int := ("" + ((inputfile.readLine())))->toInteger() ; for case : xrange(1, numberOfCases + 1) do ( N := ("" + ((inputfile.readLine())))->toInteger() ; var result : OclAny := solution(N) ; try (var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(outFile)); f.write(StringLib.format('Case #%d: %s ',Sequence{case, ("" + ((result)))}))) catch (_e : OclException) do skip)) catch (_e : OclException) do skip; operation digits(N : OclAny) : OclAny pre: true post: true activity: return Set{}->union(((("" + ((N))))->collect( _x | (OclType["int"])->apply(_x) ))); operation solution(N : OclAny) : OclAny pre: true post: true activity: if N = 0 then ( return 'INSOMNIA' ) else skip ; var allDigits : Set := Set{}->union((Integer.subrange(0, 10-1))) ; var multiple : int := 0 ; while (allDigits)->size() > 0 do ( multiple := multiple + N ; allDigits := allDigits - (digits(multiple))) ; return multiple; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=list(input()) cnt=0 ans=0 k=0 for i in range(n): if s[i]=='.' : cnt+=1 elif s[i]=='L' : ans=ans+cnt+1 if k==2 and cnt % 2==0 : ans+=1 cnt=0 k=1 elif s[i]=='R' : cnt=0 k=2 if k==2 : ans=ans+cnt+1 print(n-ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var cnt : int := 0 ; var ans : int := 0 ; var k : int := 0 ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = '.' then ( cnt := cnt + 1 ) else (if s[i+1] = 'L' then ( ans := ans + cnt + 1 ; if k = 2 & cnt mod 2 = 0 then ( ans := ans + 1 ) else skip ; cnt := 0 ; k := 1 ) else (if s[i+1] = 'R' then ( cnt := 0 ; k := 2 ) else skip ) ) ) ; if k = 2 then ( ans := ans + cnt + 1 ) else skip ; execute (n - ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) string=input() result=0 some_point_left=0 find_R='' count_point=0 count_L=0 find_L='' if string.count('L')==0 and string.count('R')==0 : result=len(string) else : for i in range(num): if string[i]=='R' : find_R='R' if find_L=='L' : result+=count_point count_point=0 find_L='' else : result+=count_point count_point=0 elif string[i]=='L' : find_L='L' if find_R=='R' : result+=count_point % 2 count_point=0 find_R='' else : count_point=0 else : count_point+=1 if count_point>0 and find_L=='L' : print(result+count_point) else : print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var string : String := (OclFile["System.in"]).readLine() ; var result : int := 0 ; var some_point_left : int := 0 ; var find_R : String := '' ; var count_point : int := 0 ; var count_L : int := 0 ; var find_L : String := '' ; if string->count('L') = 0 & string->count('R') = 0 then ( result := (string)->size() ) else ( for i : Integer.subrange(0, num-1) do ( if string[i+1] = 'R' then ( find_R := 'R' ; if find_L = 'L' then ( result := result + count_point ; count_point := 0 ; find_L := '' ) else ( result := result + count_point ; count_point := 0 ) ) else (if string[i+1] = 'L' then ( find_L := 'L' ; if find_R = 'R' then ( result := result + count_point mod 2 ; count_point := 0 ; find_R := '' ) else ( count_point := 0 ) ) else ( count_point := count_point + 1 ) ) ) ) ; if count_point > 0 & find_L = 'L' then ( execute (result + count_point)->display() ) else ( execute (result)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re import sys def array_to_string(l): s='' for i in l : s+=str(i) return s lst=[] for line in sys.stdin : lst.append(line.rstrip("\n")) regex=[[int(r)for r in re.findall("(\d+)",line)]for line in lst] for r in regex : n=[int(i)for i in list(str(r[0]))] i=r[1] while i>0 : j=0 while j0): if n[j]>n[j-1]: aux=n[j] n[j]=n[j-1] n[j-1]=aux i-=1 print(array_to_string(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var lst : Sequence := Sequence{} ; for line : OclFile["System.in"] do ( execute ((line.rstrip("\n")) : lst)) ; var regex : Sequence := lst->select(line | true)->collect(line | ((line)->allMatches("(\d+)")->select(r | true)->collect(r | (("" + ((r)))->toInteger())))) ; for r : regex do ( var n : Sequence := (("" + ((r->first()))))->characters()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var i : String := r[1+1] ; while i > 0 do ( var j : int := 0 ; while (j->compareTo((n)->size() - 1)) < 0 & n.subrange(j+1, Set{(n)->size(), i + 1 + j}->min())->indexOf((n.subrange(j+1, Set{(n)->size(), i + 1 + j}->min()))->max()) - 1 = 0 do ( j := j + 1) ; j := n.subrange(j+1, Set{(n)->size(), i + 1 + j}->min())->indexOf((n.subrange(j+1, Set{(n)->size(), i + 1 + j}->min()))->max()) - 1 + j ; if (j > 0) then ( if (n[j+1]->compareTo(n[j - 1+1])) > 0 then ( var aux : OclAny := n[j+1] ; n[j+1] := n[j - 1+1] ; n[j - 1+1] := aux ) else skip ) else skip ; i := i - 1) ; execute (array_to_string(n))->display()); operation array_to_string(l : OclAny) : OclAny pre: true post: true activity: var s : String := '' ; for i : l do ( s := s + ("" + ((i)))) ; return s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=list(input()) cnt=ans=k=0 for i in range(n): if s[i]=='L' : ans+=cnt+1 if k==2 and cnt % 2==0 : ans+=1 cnt=0 k=1 elif s[i]=='.' : cnt+=1 elif s[i]=='R' : cnt=0 k=2 if k==2 : ans+=cnt+1 print(n-ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; cnt := cnt(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name k)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = 'L' then ( ans := ans + cnt + 1 ; if k = 2 & cnt mod 2 = 0 then ( ans := ans + 1 ) else skip ; var cnt : int := 0 ; var k : int := 1 ) else (if s[i+1] = '.' then ( cnt := cnt + 1 ) else (if s[i+1] = 'R' then ( cnt := 0 ; k := 2 ) else skip ) ) ) ; if k = 2 then ( ans := ans + cnt + 1 ) else skip ; execute (n - ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) w=input()[:-1] c,d,e=1,1,0 for i in range(n): if w[i]=='R' : if d==1 : e+=c-1 c=0 d=0 elif w[i]=='L' : if d==0 : if c % 2==0 : e+=1 c=0 d=1 c+=1 if d==1 : e+=c-1 print(e) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : OclAny := input()->front() ; var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; Sequence{c,d,e} := Sequence{1,1,0} ; for i : Integer.subrange(0, n-1) do ( if w[i+1] = 'R' then ( if d = 1 then ( e := e + c - 1 ; var c : int := 0 ) else skip ; var d : int := 0 ) else (if w[i+1] = 'L' then ( if d = 0 then ( if c mod 2 = 0 then ( e := e + 1 ) else skip ) else skip ; c := 0 ; d := 1 ) else skip) ; c := c + 1) ; if d = 1 then ( e := e + c - 1 ) else skip ; execute (e)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) ans=[0]*(2*n) for i in range(2*n): ans[i]=i+1 flag=True i=0 while k>0 : if flag : i+=2 flag=False else : flag=True k-=1 if i<2*n-1 : ans[i],ans[i+1]=ans[i+1],ans[i] for i in range(len(ans)): print(ans[i],end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * n)) ; for i : Integer.subrange(0, 2 * n-1) do ( ans[i+1] := i + 1) ; var flag : boolean := true ; var i : int := 0 ; while k > 0 do ( if flag then ( i := i + 2 ; flag := false ) else ( flag := true ; k := k - 1 ; if (i->compareTo(2 * n - 1)) < 0 then ( var ans[i+1] : OclAny := null; var ans[i + 1+1] : OclAny := null; Sequence{ans[i+1],ans[i + 1+1]} := Sequence{ans[i + 1+1],ans[i+1]} ) else skip )) ; for i : Integer.subrange(0, (ans)->size()-1) do ( execute (ans[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) res=[] for i in range(2*n,0,-1): res.append(str(i)) for i in range(0,2*n,2): if k : res[i],res[i+1]=res[i+1],res[i] k-=1 else : break print(' '.join(res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var res : Sequence := Sequence{} ; for i : Integer.subrange(0 + 1, 2 * n)->reverse() do ( execute ((("" + ((i)))) : res)) ; for i : Integer.subrange(0, 2 * n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( if k then ( var res[i+1] : OclAny := null; var res[i + 1+1] : OclAny := null; Sequence{res[i+1],res[i + 1+1]} := Sequence{res[i + 1+1],res[i+1]} ; k := k - 1 ) else ( break )) ; execute (StringLib.sumStringsWithSeparator((res), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): ans=[x+1 for x in range(2*n)] for i in range(k): ans[2*i],ans[2*i+1]=ans[2*i+1],ans[2*i] return ans from sys import stdin input=stdin.readline n,k=[int(x)for x in input().split()] print(*solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((argument * (test (logical_test (comparison (expr (atom (name solve)) (trailer (arguments ( )))))))))->display(); operation solve() : OclAny pre: true post: true activity: var ans : Sequence := Integer.subrange(0, 2 * n-1)->select(x | true)->collect(x | (x + 1)) ; for i : Integer.subrange(0, k-1) do ( var ans[2 * i+1] : OclAny := null; var ans[2 * i + 1+1] : OclAny := null; Sequence{ans[2 * i+1],ans[2 * i + 1+1]} := Sequence{ans[2 * i + 1+1],ans[2 * i+1]}) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input().split(); print(int(s[1])+1,end=' ') for i in range(1,1+2*int(s[0])): if i!=int(s[1])+1 : print(i,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := input().split(); execute (("" + ((s[1+1])))->toInteger() + 1)->display() ; for i : Integer.subrange(1, 1 + 2 * ("" + ((s->first())))->toInteger()-1) do ( if i /= ("" + ((s[1+1])))->toInteger() + 1 then ( execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=4 M=4 def isPairWithDiff(mat,k): s=dict() for i in range(N): for j in range(M): s[mat[i][j]]=1 for i in range(N): for j in range(M): if k+mat[i][j]in s : return True return False n,m=4,4 mat=[[5,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,100]] k=85 if isPairWithDiff(mat,k): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 4 ; var M : int := 4 ; skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{4,4} ; mat := Sequence{Sequence{5}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })))}->union(Sequence{Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 8 })))}->union(Sequence{Sequence{9}->union(Sequence{10}->union(Sequence{11}->union(Sequence{ 12 })))}->union(Sequence{ Sequence{13}->union(Sequence{14}->union(Sequence{15}->union(Sequence{ 100 }))) }))) ; k := 85 ; if isPairWithDiff(mat, k) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isPairWithDiff(mat : OclAny, k : OclAny) : OclAny pre: true post: true activity: var s : Map := (arguments ( )) ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, M-1) do ( s[mat[i+1][j+1]+1] := 1)) ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, M-1) do ( if (s)->includes(k + mat[i+1][j+1]) then ( return true ) else skip)) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys def base10(N): t=[] while(N>0): t.append(N % 10) N=int((N-t[-1])/10) return t def findsol(N): if(N==0): return 'INSOMNIA' z=[0,0,0,0,0,0,0,0,0,0] f=0 b=1 while 1 : a=base10(N*b) for jj in a : if(z[jj]==0): f+=1 z[jj]=1 if(f==10): return N*b b+=1 return b def convertnums(s): a=[] ii=0 for jj in range(len(s)): if s[jj]==' ' : if(iitoInteger() ; for ii : Integer.subrange(1, T + 1-1) do ( N := ("" + ((fidi.readLine())))->toInteger() ; a := findsol(N) ; fido.write('Case #' + ("" + ((ii))) + ': ' + ("" + ((a))) + ' ') ; execute ('Case #' + ("" + ((ii))))->display()) ; fidi.closeFile() ; fido.closeFile(); operation base10(N : OclAny) : OclAny pre: true post: true activity: var t : Sequence := Sequence{} ; while (N > 0) do ( execute ((N mod 10) : t) ; N := ("" + (((N - t->last()) / 10)))->toInteger()) ; return t; operation findsol(N : OclAny) : OclAny pre: true post: true activity: if (N = 0) then ( return 'INSOMNIA' ) else skip ; var z : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 }))))))))) ; var f : int := 0 ; var b : int := 1 ; while 1 do ( var a : OclAny := base10(N * b) ; for jj : a do ( if (z[jj+1] = 0) then ( f := f + 1 ) else skip ; z[jj+1] := 1) ; if (f = 10) then ( return N * b ) else skip ; b := b + 1) ; return b; operation convertnums(s : OclAny) : OclAny pre: true post: true activity: a := Sequence{} ; var ii : int := 0 ; for jj : Integer.subrange(0, (s)->size()-1) do ( if s[jj+1] = ' ' then ( if ((ii->compareTo(jj)) < 0) then ( execute ((("" + ((s.subrange(ii+1, jj))))->toInteger()) : a) ; ii := jj + 1 ) else skip ) else skip) ; execute ((("" + ((s.subrange(ii+1, jj))))->toInteger()) : a) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_CHAR=256 def countSub(ss): last=[-1 for i in range(MAX_CHAR+1)] n=len(ss) dp=[-2 for i in range(n+1)] dp[0]=1 for i in range(1,n+1): dp[i]=2*dp[i-1] if last[ord(ss[i-1])]!=-1 : dp[i]=dp[i]-dp[last[ord(ss[i-1])]] last[ord(ss[i-1])]=i-1 return dp[n] print(countSub("gfg")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_CHAR : int := 256 ; skip ; execute (countSub("gfg"))->display(); operation countSub(ss : OclAny) : OclAny pre: true post: true activity: var last : Sequence := Integer.subrange(0, MAX_CHAR + 1-1)->select(i | true)->collect(i | (-1)) ; var n : int := (ss)->size() ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (-2)) ; dp->first() := 1 ; for i : Integer.subrange(1, n + 1-1) do ( dp[i+1] := 2 * dp[i - 1+1] ; if last[(ss[i - 1+1])->char2byte()+1] /= -1 then ( dp[i+1] := dp[i+1] - dp[last[(ss[i - 1+1])->char2byte()+1]+1] ) else skip ; last[(ss[i - 1+1])->char2byte()+1] := i - 1) ; return dp[n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minCost(N,P,Q): cost=0 while(N>0): if(N & 1): cost+=P N-=1 else : temp=N//2 ; if(temp*P>Q): cost+=Q else : cost+=P*temp N//=2 return cost N=9 P=5 Q=1 print(minCost(N,P,Q)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 9 ; P := 5 ; Q := 1 ; execute (minCost(N, P, Q))->display(); operation minCost(N : OclAny, P : OclAny, Q : OclAny) : OclAny pre: true post: true activity: var cost : int := 0 ; while (N > 0) do ( if (MathLib.bitwiseAnd(N, 1)) then ( cost := cost + P ; N := N - 1 ) else ( var temp : int := N div 2; ; if ((temp * P->compareTo(Q)) > 0) then ( cost := cost + Q ) else ( cost := cost + P * temp ) ; N := N div 2 )) ; return cost; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=4 C=3 def isSafe(x,y): return(xunion(Sequence{4}->union(Sequence{ 2 }))}->union(Sequence{Sequence{9}->union(Sequence{2}->union(Sequence{ 1 }))}->union(Sequence{Sequence{2}->union(Sequence{5}->union(Sequence{ 9 }))}->union(Sequence{ Sequence{1}->union(Sequence{3}->union(Sequence{ 11 })) }))) ; execute (minJump(height, 0, 0))->display(); operation isSafe(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return ((x->compareTo(R)) < 0 & (y->compareTo(C)) < 0); operation minJump(height : OclAny, x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (x = R - 1 & y = C - 1) then ( return 0 ) else skip ; var diag : double := (10)->pow(9) ; if (isSafe(x + 1, y + 1)) then ( diag := (minJump(height, x + 1, y + 1) + (height[x+1][y+1] - height[x + 1+1][y + 1+1])->abs()) ) else skip ; var down : double := (10)->pow(9) ; if (isSafe(x + 1, y)) then ( down := (minJump(height, x + 1, y) + (height[x+1][y+1] - height[x + 1+1][y+1])->abs()) ) else skip ; var right : double := (10)->pow(9) ; if (isSafe(x, y + 1)) then ( right := (minJump(height, x, y + 1) + (height[x+1][y+1] - height[x+1][y + 1+1])->abs()) ) else skip ; return (Sequence{down}->union(Sequence{right}->union(Sequence{ diag })))->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import copy n,k=map(str,input().split()) n=list(n) for x in n : x=int(x) k=int(k) i=0 while k>0 and in[i]: for j in range(i+pos+1,i,-1): n[j]=n[j-1] n[i]=d k-=pos+1 i+=1 for x in n : print(x,end='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; var n : Sequence := (n) ; for x : n do ( var x : int := ("" + ((x)))->toInteger()) ; var k : int := ("" + ((k)))->toInteger() ; var i : int := 0 ; while k > 0 & (i->compareTo((n)->size() - 1)) < 0 do ( var arr : OclAny := n.subrange(i + 1+1, i + 1 + k) ; var d : OclAny := (arr)->max() ; var pos : int := arr->indexOf(d) - 1 ; if (d->compareTo(n[i+1])) > 0 then ( for j : Integer.subrange(i + 1, i + pos + 1)->reverse() do ( n[j+1] := n[j - 1+1]) ; n[i+1] := d ; k := k - pos + 1 ) else skip ; i := i + 1) ; for x : n do ( execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) ans=[0 for i in range(N)] arr1=[[0 for i in range(N)]for j in range(3)] for i in range(N): num=list(map(int,input().split())) arr1[0][i]=num[0] arr1[1][i]=num[1] arr1[2][i]=num[2] for i in range(3): check=[0 for i in range(100)] for j in range(N): check[arr1[i][j]-1]+=1 for j in range(N): if check[arr1[i][j]-1]==1 : ans[j]+=arr1[i][j] for i in range(N): print(ans[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; var arr1 : Sequence := Integer.subrange(0, 3-1)->select(j | true)->collect(j | (Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, N-1) do ( var num : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr1->first()[i+1] := num->first() ; arr1[1+1][i+1] := num[1+1] ; arr1[2+1][i+1] := num[2+1]) ; for i : Integer.subrange(0, 3-1) do ( var check : Sequence := Integer.subrange(0, 100-1)->select(i | true)->collect(i | (0)) ; for j : Integer.subrange(0, N-1) do ( check[arr1[i+1][j+1] - 1+1] := check[arr1[i+1][j+1] - 1+1] + 1) ; for j : Integer.subrange(0, N-1) do ( if check[arr1[i+1][j+1] - 1+1] = 1 then ( ans[j+1] := ans[j+1] + arr1[i+1][j+1] ) else skip)) ; for i : Integer.subrange(0, N-1) do ( execute (ans[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def line(): return sys.stdin.readline().strip() N=int(line()) a=[[int(i)for i in line().split()]for _ in range(N)] s=[0]*N for i in range(3): c=[0]*101 for j in range(N): c[a[j][i]]+=1 for j in range(N): if(c[a[j][i]]==1): s[j]+=a[j][i] for i in range(N): print(s[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := ("" + ((line())))->toInteger() ; var a : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (line().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())))) ; var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for i : Integer.subrange(0, 3-1) do ( var c : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 101) ; for j : Integer.subrange(0, N-1) do ( c[a[j+1][i+1]+1] := c[a[j+1][i+1]+1] + 1) ; for j : Integer.subrange(0, N-1) do ( if (c[a[j+1][i+1]+1] = 1) then ( s[j+1] := s[j+1] + a[j+1][i+1] ) else skip)) ; for i : Integer.subrange(0, N-1) do ( execute (s[i+1])->display()); operation line() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[] b=[] c=[] for i in range(n): x,y,z=map(int,input().split()) a.append(x) b.append(y) c.append(z) for i in range(n): score=0 if a.count(a[i])==1 : score+=a[i] if b.count(b[i])==1 : score+=b[i] if c.count(c[i])==1 : score+=c[i] print(score) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; var c : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((x) : a) ; execute ((y) : b) ; execute ((z) : c)) ; for i : Integer.subrange(0, n-1) do ( var score : int := 0 ; if a->count(a[i+1]) = 1 then ( score := score + a[i+1] ) else skip ; if b->count(b[i+1]) = 1 then ( score := score + b[i+1] ) else skip ; if c->count(c[i+1]) = 1 then ( score := score + c[i+1] ) else skip ; execute (score)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=[list(map(int,input().split()))for _ in range(n)] point=[0]*n for j in range(3): r=[row[j]for row in p] for i in range(n): if i==0 : if r[i]not in r[1 :]: point[0]+=r[i] elif i==n-1 : if r[i]not in r[: n-1]: point[n-1]+=r[i] else : p0=r[: i]+r[i+1 :] if r[i]not in p0 : point[i]+=r[i] for i in point : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var point : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for j : Integer.subrange(0, 3-1) do ( var r : Sequence := p->select(row | true)->collect(row | (row[j+1])) ; for i : Integer.subrange(0, n-1) do ( if i = 0 then ( if (r->tail())->excludes(r[i+1]) then ( point->first() := point->first() + r[i+1] ) else skip ) else (if i = n - 1 then ( if (r.subrange(1,n - 1))->excludes(r[i+1]) then ( point[n - 1+1] := point[n - 1+1] + r[i+1] ) else skip ) else ( var p0 : String := r.subrange(1,i) + r.subrange(i + 1+1) ; if (p0)->characters()->excludes(r[i+1]) then ( point[i+1] := point[i+1] + r[i+1] ) else skip ) ) )) ; for i : point do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=[[0 for j in range(3)]for i in range(101)] n=int(input()) p=[[0 for j in range(3)]for i in range(n)] for i in range(n): p[i]=list(map(int,input().split())) for j in range(3): c[p[i][j]][j]+=1 for i in range(n): s=0 for j in range(3): if c[p[i][j]][j]==1 : s+=p[i][j] print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : Sequence := Integer.subrange(0, 101-1)->select(i | true)->collect(i | (Integer.subrange(0, 3-1)->select(j | true)->collect(j | (0)))) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, 3-1)->select(j | true)->collect(j | (0)))) ; for i : Integer.subrange(0, n-1) do ( p[i+1] := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, 3-1) do ( c[p[i+1][j+1]+1][j+1] := c[p[i+1][j+1]+1][j+1] + 1)) ; for i : Integer.subrange(0, n-1) do ( var s : int := 0 ; for j : Integer.subrange(0, 3-1) do ( if c[p[i+1][j+1]+1][j+1] = 1 then ( s := s + p[i+1][j+1] ) else skip) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt size=1000 prime=[0 for i in range(size)] freq=[0 for i in range(size)] def sieve(a,b): prime[1]=1 for i in range(2,int(sqrt(size))+1,1): if(prime[i]==0): for j in range(i*2,size,i): prime[j]=1 for p in range(1,size,1): for q in range(1,size,1): if(prime[p]==0 and prime[q]==0 and a*p+b*qselect(i | true)->collect(i | (0)) ; var freq : Sequence := Integer.subrange(0, size-1)->select(i | true)->collect(i | (0)) ; skip ; if __name__ = '__main__' then ( var queries : int := 2 ; a := 1 ; b := 2 ; sieve(a, b) ; var arr : Sequence := Sequence{15}->union(Sequence{ 25 }) ; for i : Integer.subrange(0, queries-1) do ( execute (freq[arr[i+1]+1])->display()) ) else skip; operation sieve(a : OclAny, b : OclAny) pre: true post: true activity: prime[1+1] := 1 ; for i : Integer.subrange(2, ("" + ((sqrt(size))))->toInteger() + 1-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (prime[i+1] = 0) then ( for j : Integer.subrange(i * 2, size-1)->select( $x | ($x - i * 2) mod i = 0 ) do ( prime[j+1] := 1) ) else skip) ; for p : Integer.subrange(1, size-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( for q : Integer.subrange(1, size-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if (prime[p+1] = 0 & prime[q+1] = 0 & (a * p + b * q->compareTo(size)) < 0) then ( freq[a * p + b * q+1] := freq[a * p + b * q+1] + 1 ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,sys,ljqpy,time time.clock() def Run(N): st=set() m=0 for i in range(10000000): m+=N for ch in str(m): st.add(ch) if len(st)==10 : return str(m) return 'INSOMNIA' lst=ljqpy.LoadList('A-large.in') with open('A-large.out','w')as fout : for k,v in enumerate(lst[1 :]): fout.write('Case #%d: %s\n' %(1+k,Run(int(v)))) print('completed') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; time.clock() ; skip ; var lst : OclAny := ljqpy.LoadList('A-large.in') ; try (var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('A-large.out')); for _tuple : Integer.subrange(1, (lst->tail())->size())->collect( _indx | Sequence{_indx-1, (lst->tail())->at(_indx)} ) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); fout.write(StringLib.format('Case #%d: %s ',Sequence{1 + k, Run(("" + ((v)))->toInteger())})))) catch (_e : OclException) do skip ; execute ('completed')->display(); operation Run(N : OclAny) : OclAny pre: true post: true activity: var st : Set := Set{}->union(()) ; var m : int := 0 ; for i : Integer.subrange(0, 10000000-1) do ( m := m + N ; for ch : ("" + ((m))) do ( execute ((ch) : st)) ; if (st)->size() = 10 then ( return ("" + ((m))) ) else skip) ; return 'INSOMNIA'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fun(s,t): first=t[0] l=[] for j in range(len(s)): if first==s[j]: l.append(j) if len(l)==0 : return "NO" for j in range(len(l)): for i in range(len(t)): first_index=l[j] ans="" pointer=0 var=i while var>pointer and first_index-1 : if t[pointer]==s[first_index]: ans+=t[pointer] first_index-=1 pointer+=1 else : break if ans==t : return "YES" return "NO" i=int(input()) for p in range(i): s=input() t=input() print(fun(s,t)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var i : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for p : Integer.subrange(0, i-1) do ( s := (OclFile["System.in"]).readLine() ; t := (OclFile["System.in"]).readLine() ; execute (fun(s, t))->display()); operation fun(s : OclAny, t : OclAny) : OclAny pre: true post: true activity: var first : OclAny := t->first() ; var l : Sequence := Sequence{} ; for j : Integer.subrange(0, (s)->size()-1) do ( if first = s[j+1] then ( execute ((j) : l) ) else skip) ; if (l)->size() = 0 then ( return "NO" ) else skip ; for j : Integer.subrange(0, (l)->size()-1) do ( for i : Integer.subrange(0, (t)->size()-1) do ( var first_index : OclAny := l[j+1] ; var ans : String := "" ; var pointer : int := 0 ; var var : OclAny := i ; while (var->compareTo(pointer)) > 0 & (first_index->compareTo((s)->size())) < 0 & (pointer->compareTo((t)->size())) < 0 do ( if t[pointer+1] = s[first_index+1] then ( ans := ans + t[pointer+1] ; pointer := pointer + 1 ; first_index := first_index + 1 ) else ( first_index := first_index - 2 ; break )) ; if first_index = (s)->size() then ( first_index := first_index - 2 ) else skip ; while (pointer->compareTo((t)->size())) < 0 & first_index > -1 do ( if t[pointer+1] = s[first_index+1] then ( ans := ans + t[pointer+1] ; first_index := first_index - 1 ; pointer := pointer + 1 ) else ( break )) ; if ans = t then ( return "YES" ) else skip)) ; return "NO"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) while q : s=input() t=input() flag=0 for i in range(len(s)): if t in s[: i]+s[i : :-1]: flag=1 break if flag : print("YES") else : print("NO") q-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while q do ( var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var flag : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if (s.subrange(1,i) + s(subscript (test (logical_test (comparison (expr (atom (name i)))))) : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->includes(t) then ( flag := 1 ; break ) else skip) ; if flag then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ; q := q - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) for i in range(q): s=input() t=input() n=len(s) m=len(t) ans=False for i in range(n): for j in range(0,n-i): k=m-1-j if i+jtoInteger() ; for i : Integer.subrange(0, q-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var n : int := (s)->size() ; var m : int := (t)->size() ; var ans : boolean := false ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n - i-1) do ( var k : double := m - 1 - j ; if (i + j->compareTo(k)) < 0 then ( continue ) else skip ; var l1 : OclAny := i ; var r : OclAny := i + j ; var l2 : double := r - k ; if s.subrange(l1+1, r + 1) + s.subrange(l2+1, r)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) = t then ( ans := true ) else skip)) ; execute (if ans then 'YES' else 'NO' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): s=input() s2=input() for j in range(len(s)): if s2 in(s[: j]+s[j : :-1]): print("YES") break else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var s2 : String := (OclFile["System.in"]).readLine() ; (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name s2)))) in (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name j)))))))) ]))) + (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))) : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ])))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import collections import bisect def get_ints(): return map(int,sys.stdin.readline().strip().split()) def get_list(): return list(map(int,sys.stdin.readline().strip().split())) def get_string(): return sys.stdin.readline().strip() for t in range(1): a,b=input().split() a=list(a) b=int(b) start=0 while b>0 : maxim=int(a[start]) pos=start for i in range(start+1,min(start+1+b,len(a))): if int(a[i])>maxim : pos=i maxim=int(a[i]) b-=abs(pos-start) a.pop(pos) a.insert(start,maxim) start+=1 if start>=len(a)-1 : break print(*a,sep="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; for t : Integer.subrange(0, 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; var a : Sequence := (a) ; var b : int := ("" + ((b)))->toInteger() ; var start : int := 0 ; while b > 0 do ( var maxim : int := ("" + ((a[start+1])))->toInteger() ; var pos : int := start ; for i : Integer.subrange(start + 1, Set{start + 1 + b, (a)->size()}->min()-1) do ( if (("" + ((a[i+1])))->toInteger()->compareTo(maxim)) > 0 then ( pos := i ; maxim := ("" + ((a[i+1])))->toInteger() ) else skip) ; b := b - (pos - start)->abs() ; a := a->excludingAt(pos+1) ; a := a.insertAt(start+1, maxim) ; start := start + 1 ; if (start->compareTo((a)->size() - 1)) >= 0 then ( break ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display()); operation get_ints() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ); operation get_list() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation get_string() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) def solve(s,t): answer=False for i in range(len(s)): if s[i]==t[0]: answer=answer or recur(s,t,i,direction=1,goal_index=0)or recur(s,t,i,direction=0,goal_index=0) if answer : print("yes") else : print("no") def recur(s,t,position,direction,goal_index): if goal_index>=len(t): return True if position>=len(s)or position<0 : return False if s[position]!=t[goal_index]: return False if direction==1 : return recur(s,t,position+1,1,goal_index+1)or recur(s,t,position-1,0,goal_index+1) else : return recur(s,t,position-1,0,goal_index+1) n=int(input().strip()) for i in range(n): s=input().strip() t=input().strip() solve(s,t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; skip ; skip ; var n : int := ("" + ((input()->trim())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( s := input()->trim() ; t := input()->trim() ; solve(s, t)); operation solve(s : OclAny, t : OclAny) pre: true post: true activity: var answer : boolean := false ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = t->first() then ( answer := answer or recur(s, t, i, (argument (test (logical_test (comparison (expr (atom (name direction)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))), (argument (test (logical_test (comparison (expr (atom (name goal_index)))))) = (test (logical_test (comparison (expr (atom (number (integer 0))))))))) or recur(s, t, i, (argument (test (logical_test (comparison (expr (atom (name direction)))))) = (test (logical_test (comparison (expr (atom (number (integer 0)))))))), (argument (test (logical_test (comparison (expr (atom (name goal_index)))))) = (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ) else skip) ; if answer then ( execute ("yes")->display() ) else ( execute ("no")->display() ); operation recur(s : OclAny, t : OclAny, position : OclAny, direction : OclAny, goal_index : OclAny) : OclAny pre: true post: true activity: if (goal_index->compareTo((t)->size())) >= 0 then ( return true ) else skip ; if (position->compareTo((s)->size())) >= 0 or position < 0 then ( return false ) else skip ; if s[position+1] /= t[goal_index+1] then ( return false ) else skip ; if direction = 1 then ( return recur(s, t, position + 1, 1, goal_index + 1) or recur(s, t, position - 1, 0, goal_index + 1) ) else ( return recur(s, t, position - 1, 0, goal_index + 1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def edgeCover(n): result=0 result=math.ceil(n/2.0) return result if __name__=="__main__" : n=5 print(int(edgeCover(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 5 ; execute (("" + ((edgeCover(n))))->toInteger())->display() ) else skip; operation edgeCover(n : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; result := (n / 2.0)->ceil() ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printSeries(n): for i in range(1,n+1): num=i*(i+1)*(i+2)//6 print(num,end=' ') n=10 printSeries(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 10 ; printSeries(n); operation printSeries(n : OclAny) pre: true post: true activity: for i : Integer.subrange(1, n + 1-1) do ( var num : int := i * (i + 1) * (i + 2) div 6 ; execute (num)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a={int(i)for i in input().split()} m=int(input()) b={int(i)for i in input().split()} c=tuple(sorted(a-b)) for i in c : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Set := input().split()->select(i | true)->collect(i | ("" + ((i)))->toInteger())->asSet() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Set := input().split()->select(i | true)->collect(i | ("" + ((i)))->toInteger())->asSet() ; var c : Sequence := (a - b->sort()) ; for i : c do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def diff(n,m,a,b): i,j=0,0 while ib[j]: j+=1 else : i+=1 j+=1 while icompareTo(n)) < 0 & (j->compareTo(m)) < 0 do ( if (a[i+1]->compareTo(b[j+1])) < 0 then ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return a[i+1] ; i := i + 1 ) else (if (a[i+1]->compareTo(b[j+1])) > 0 then ( j := j + 1 ) else ( i := i + 1 ; j := j + 1 ) ) ) ; while (i->compareTo(n)) < 0 do ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return a[i+1] ; i := i + 1); operation run() pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; m := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; b := input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; for v : diff(n, m, a, b) do ( execute (v)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m,rb,cb,rd,cd=map(int,input().split()); t=0 df,dp=1,1 while True : if rb==n : df=-1*df if cb==m : dp=-1*dp if rb==rd or cb==cd : break rb+=df ; cb+=dp ; t+=1 print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; var rb : OclAny := null; var cb : OclAny := null; var rd : OclAny := null; var cd : OclAny := null; Sequence{n,m,rb,cb,rd,cd} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var t : int := 0 ; var df : OclAny := null; var dp : OclAny := null; Sequence{df,dp} := Sequence{1,1} ; while true do ( if rb = n then ( var df : double := -1 * df ) else skip ; if cb = m then ( var dp : double := -1 * dp ) else skip ; if rb = rd or cb = cd then ( break ) else skip ; rb := rb + df; cb := cb + dp; t := t + 1) ; execute (t)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=set(map(int,input().split())) M=int(input()) B=set(map(int,input().split())) C=A-B if C : print(*sorted(C),sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var M : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var C : double := A - B ; if C then ( execute ((argument * (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name C)))))))) )))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _=input() A=set([int(a)for a in input().split()]) _=input() B=set([int(b)for b in input().split()]) C=sorted([d for d in(A-B)]) if C : print(*C,sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _anon : String := (OclFile["System.in"]).readLine() ; var A : Set := Set{}->union((input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())))) ; _anon := (OclFile["System.in"]).readLine() ; var B : Set := Set{}->union((input().split()->select(b | true)->collect(b | (("" + ((b)))->toInteger())))) ; var C : Sequence := (A - B)->select(d | true)->collect(d | (d))->sort() ; if C then ( execute ((argument * (test (logical_test (comparison (expr (atom (name C))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) a=set([int(a)for a in input().split()]) m=int(input()) b=set([int(a)for a in input().split()]) c=a.difference(b) sorted_c=sorted(c) for i in sorted_c : print(i) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Set := Set{}->union((input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())))) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Set := Set{}->union((input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())))) ; var c : OclAny := a - (b) ; var sorted_c : Sequence := c->sort() ; for i : sorted_c do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printArraystring(string,n): for i in range(n): print(string[i],end=" ") def sort(s,n): for i in range(1,n): temp=s[i] j=i-1 while j>=0 and len(temp)union(Sequence{"I"}->union(Sequence{"from"}->union(Sequence{ "am" }))) ; n := (arr)->size() ; sort(arr, n) ; printArraystring(arr, n) ) else skip; operation printArraystring(string : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (string[i+1])->display()); operation sort(s : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(1, n-1) do ( var temp : OclAny := s[i+1] ; var j : double := i - 1 ; while j >= 0 & ((temp)->size()->compareTo((s[j+1])->size())) < 0 do ( s[j + 1+1] := s[j+1] ; j := j - 1) ; s[j + 1+1] := temp); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- M=1000000007 def power(x,y,p): res=1 x=x % p while(y>0): if(y & 1): res=(res*x)% p y=y>>1 x=(x*x)% p return res def modInverse(n,p): return power(n,p-2,p) def nCrModPFermat(n,r,p): if(r==0): return 1 fac=[0]*(n+1) fac[0]=1 for i in range(1,n+1): fac[i]=fac[i-1]*i % p return(fac[n]*modInverse(fac[r],p)% p*modInverse(fac[n-r],p)% p)% p def countOdd(n): x=n//2 if(n % 2==1): x+=1 return x def counteEven(n): x=n//2 return x def CountEvenSumSequences(n): count=0 for i in range(n+1): even=i odd=n-i if(odd % 2==1): continue tot=(power(countOdd(n),odd,M)*nCrModPFermat(n,odd,M))% M tot=(tot*power(counteEven(n),i,M))% M count+=tot count %=M return count n=5 print(CountEvenSumSequences(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var M : int := 1000000007 ; skip ; skip ; skip ; skip ; skip ; skip ; n := 5 ; execute (CountEvenSumSequences(n))->display(); operation power(x : OclAny, y : OclAny, p : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; x := x mod p ; while (y > 0) do ( if (MathLib.bitwiseAnd(y, 1)) then ( res := (res * x) mod p ) else skip ; y := y /(2->pow(1)) ; x := (x * x) mod p) ; return res; operation modInverse(n : OclAny, p : OclAny) : OclAny pre: true post: true activity: return power(n, p - 2, p); operation nCrModPFermat(n : OclAny, r : OclAny, p : OclAny) : OclAny pre: true post: true activity: if (r = 0) then ( return 1 ) else skip ; var fac : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; fac->first() := 1 ; for i : Integer.subrange(1, n + 1-1) do ( fac[i+1] := fac[i - 1+1] * i mod p) ; return (fac[n+1] * modInverse(fac[r+1], p) mod p * modInverse(fac[n - r+1], p) mod p) mod p; operation countOdd(n : OclAny) : OclAny pre: true post: true activity: x := n div 2 ; if (n mod 2 = 1) then ( x := x + 1 ) else skip ; return x; operation counteEven(n : OclAny) : OclAny pre: true post: true activity: x := n div 2 ; return x; operation CountEvenSumSequences(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( var even : OclAny := i ; var odd : double := n - i ; if (odd mod 2 = 1) then ( continue ) else skip ; var tot : int := (power(countOdd(n), odd, M) * nCrModPFermat(n, odd, M)) mod M ; tot := (tot * power(counteEven(n), i, M)) mod M ; count := count + tot ; count := count mod M) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def power(num,n): if(n==0): return 1 elif(n % 2==0): return power(num,n//2)*power(num,n//2) else : return num*power(num,n//2)*power(num,n//2) def checkRecursive(x,n,curr_num=1,curr_sum=0): results=0 p=power(curr_num,n) while(p+curr_sumdisplay() ) else skip; operation power(num : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return 1 ) else (if (n mod 2 = 0) then ( return power(num, n div 2) * power(num, n div 2) ) else ( return num * power(num, n div 2) * power(num, n div 2) ) ) ; operation checkRecursive(x : OclAny, n : OclAny, curr_num : int, curr_sum : int) : OclAny pre: true post: true activity: if curr_num->oclIsUndefined() then curr_num := 1 else skip; if curr_sum->oclIsUndefined() then curr_sum := 0 else skip; var results : int := 0 ; var p : OclAny := power(curr_num, n) ; while ((p + curr_sum->compareTo(x)) < 0) do ( results := results + checkRecursive(x, n, curr_num + 1, p + curr_sum) ; curr_num := curr_num + 1 ; p := power(curr_num, n)) ; if (p + curr_sum = x) then ( results := results + 1 ) else skip ; return results; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfTheSeries(n): sum=0 for i in range(0,n+1): k=2 for j in range(1,i+1): sum=sum+k ; k=k+2 return sum ; n=5 ans=sumOfTheSeries(n); print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; var ans : OclAny := sumOfTheSeries(n); ; execute (ans)->display(); operation sumOfTheSeries(n : OclAny) pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( var k : int := 2 ; for j : Integer.subrange(1, i + 1-1) do ( sum := sum + k; ; k := k + 2)) ; return sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict N=int(input()) A=list(map(int,input().split())) if all(a==0 for a in A): print(0) exit() position=defaultdict(list) for i,a in enumerate(A): position[a].append(i) ans=0 use=0 link=0 for a in sorted(set(A),reverse=True): use+=len(position[a]) for i in position[a]: if i>0 and A[i]toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if ((argument (test (logical_test (comparison (comparison (expr (atom (name a)))) == (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name A))))))))->forAll( _x | _x = true ) then ( execute (0)->display() ; exit() ) else skip ; var position : OclAny := defaultdict(OclType["Sequence"]) ; for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); (expr (atom (name position)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var ans : int := 0 ; var use : int := 0 ; var link : int := 0 ; for a : Set{}->union((A))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) do ( use := use + (position[a+1])->size() ; for i : position[a+1] do ( if i > 0 & (A[i+1]->compareTo(A[i - 1+1])) < 0 then ( link := link + 1 ) else skip ; if (i->compareTo(N - 1)) < 0 & (A[i+1]->compareTo(A[i + 1+1])) <= 0 then ( link := link + 1 ) else skip) ; ans := Set{ans, use - link}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import array from fractions import Fraction import functools import itertools import math import os import sys def main(): N=read_int() A=read_ints() print(solve(N,A)) def solve(N,A): height_map={} for i,a in enumerate(A): if a not in height_map : height_map[a]=[] height_map[a].append(i+1) heights=list(height_map) heights.sort(reverse=True) landscape=[0]*(N+2) count=0 best=0 for h in heights : if h==0 : break for i in height_map[h]: l,r=landscape[i-1],landscape[i+1] if l==0 and r==0 : count+=1 elif l==1 and r==1 : count-=1 landscape[i]=1 best=max(best,count) return best DEBUG='DEBUG' in os.environ def inp(): return sys.stdin.readline().rstrip() def read_int(): return int(inp()) def read_ints(): return[int(e)for e in inp().split()] def dprint(*value,sep=' ',end='\n'): if DEBUG : print(*value,sep=sep,end=end) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var DEBUG : boolean := (os.environ)->includes('DEBUG') ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := read_int() ; var A : OclAny := read_ints() ; execute (solve(N, A))->display(); operation solve(N : OclAny, A : OclAny) : OclAny pre: true post: true activity: var height_map : OclAny := Set{} ; for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); if (height_map)->excludes(a) then ( height_map[a+1] := Sequence{} ) else skip ; (expr (atom (name height_map)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ))))) ; var heights : Sequence := (height_map) ; heights := heights->sort() ; var landscape : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 2)) ; var count : int := 0 ; var best : int := 0 ; for h : heights do ( if h = 0 then ( break ) else skip ; for i : height_map[h+1] do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{landscape[i - 1+1],landscape[i + 1+1]} ; if l = 0 & r = 0 then ( count := count + 1 ) else (if l = 1 & r = 1 then ( count := count - 1 ) else skip) ; landscape[i+1] := 1) ; best := Set{best, count}->max()) ; return best; operation inp() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation read_int() : OclAny pre: true post: true activity: return ("" + ((inp())))->toInteger(); operation read_ints() : OclAny pre: true post: true activity: return inp().split()->select(e | true)->collect(e | (("" + ((e)))->toInteger())); operation dprint(value : OclAny : Sequence(OclAny), sep : String, end : String) pre: true post: true activity: (args * (named_parameter (name value))) if sep->oclIsUndefined() then sep := ' ' else skip; if end->oclIsUndefined() then end := ' ' else skip; if DEBUG then ( execute ((argument * (test (logical_test (comparison (expr (atom (name value))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) R={} *A,=map(int,input().split()) for i,a in enumerate(A): R.setdefault(a,[]).append(i) if N==1 : print(+(min(A)>0)) else : res=1 ; ans=+(min(A)>0) for k in sorted(R): for i in R[k]: if 0A[i+1]: res-=1 if A[i-1]>A[i]<=A[i+1]: res+=1 elif i==0 : if A[i]>A[i+1]: res-=1 else : if A[i-1]<=A[i]: res-=1 ans=max(ans,res) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var R : OclAny := Set{} ; (testlist_star_expr (star_expr * (expr (atom (name A)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name A)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); (expr (atom (name R)) (trailer . (name setdefault) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom [ ]))))))) ))) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; if N = 1 then ( execute (((A)->min() > 0))->display() ) else ( var res : int := 1; var ans : boolean := ((A)->min() > 0) ; for k : R->sort() do ( for i : R[k+1] do ( if 0 < i & (i < N - 1) then ( if (A[i - 1+1]->compareTo(A[i+1])) <= 0 & (A[i+1] > A[i + 1+1]) then ( res := res - 1 ) else skip ; if (A[i - 1+1]->compareTo(A[i+1])) > 0 & (A[i+1] <= A[i + 1+1]) then ( res := res + 1 ) else skip ) else (if i = 0 then ( if (A[i+1]->compareTo(A[i + 1+1])) > 0 then ( res := res - 1 ) else skip ) else ( if (A[i - 1+1]->compareTo(A[i+1])) <= 0 then ( res := res - 1 ) else skip ) ) ) ; ans := Set{ans, res}->max()) ; execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): n,m,rb,cb,rd,cd=map(int,input().split()) x_status=True y_status=True answer=0 while True : if rb==rd or cb==cd : break if rb==n : x_status=False if cb==m : y_status=False if rb==1 : x_status=True if cb==1 : y_status=True if x_status : rb+=1 else : rb-=1 if y_status : cb+=1 else : cb-=1 answer+=1 print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; var rb : OclAny := null; var cb : OclAny := null; var rd : OclAny := null; var cd : OclAny := null; Sequence{n,m,rb,cb,rd,cd} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x_status : boolean := true ; var y_status : boolean := true ; var answer : int := 0 ; while true do ( if rb = rd or cb = cd then ( break ) else skip ; if rb = n then ( x_status := false ) else skip ; if cb = m then ( y_status := false ) else skip ; if rb = 1 then ( x_status := true ) else skip ; if cb = 1 then ( y_status := true ) else skip ; if x_status then ( rb := rb + 1 ) else ( rb := rb - 1 ) ; if y_status then ( cb := cb + 1 ) else ( cb := cb - 1 ) ; answer := answer + 1) ; execute (answer)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) height_list=[0]+list(map(int,input().split()))+[0] use_list=[] up_flag=True for i in range(len(height_list)-1): if up_flag : if height_list[i]>height_list[i+1]: use_list.append(height_list[i]) up_flag=False else : if height_list[i]0 and not sink_list[location-1])and(location<(len_list-1)and not sink_list[location+1]): count+=1 if(location>0 and sink_list[location-1])and(location<(len_list-1)and sink_list[location+1]): count-=1 elif location==0 and sink_list[1]: count-=1 elif location==(len_list-1)and sink_list[len_list-1]: count-=1 pre_height=height print(max_count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var height_list : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->union(Sequence{ 0 }) ; var use_list : Sequence := Sequence{} ; var up_flag : boolean := true ; for i : Integer.subrange(0, (height_list)->size() - 1-1) do ( if up_flag then ( if (height_list[i+1]->compareTo(height_list[i + 1+1])) > 0 then ( execute ((height_list[i+1]) : use_list) ; up_flag := false ) else skip ) else ( if (height_list[i+1]->compareTo(height_list[i + 1+1])) < 0 then ( execute ((height_list[i+1]) : use_list) ; up_flag := true ) else skip )) ; var len_list : int := (use_list)->size() ; var use_list2 : Sequence := Integer.subrange(1, use_list->size())->collect( _indx | Sequence{use_list->at(_indx), Integer.subrange(0, len_list-1)->at(_indx)} )->sort() ; var sink_list : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, len_list) ; var max_count : int := 0 ; var count : int := 1 ; var pre_height : int := -1 ; if len_list = 1 then ( max_count := 1 ) else ( for _tuple : use_list2 do (var _indx : int := 1; var height : OclAny := _tuple->at(_indx); _indx := _indx + 1; var location : OclAny := _tuple->at(_indx); if pre_height /= height then ( max_count := Set{max_count, count}->max() ) else skip ; sink_list[location+1] := true ; if (location > 0 & not(sink_list[location - 1+1])) & ((location->compareTo((len_list - 1))) < 0 & not(sink_list[location + 1+1])) then ( count := count + 1 ) else skip ; if (location > 0 & sink_list[location - 1+1]) & ((location->compareTo((len_list - 1))) < 0 & sink_list[location + 1+1]) then ( count := count - 1 ) else (if location = 0 & sink_list[1+1] then ( count := count - 1 ) else (if location = (len_list - 1) & sink_list[len_list - 1+1] then ( count := count - 1 ) else skip ) ) ; pre_height := height) ) ; execute (max_count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict n,*h=map(int,open(0).read().split()) h=[y for x,y in zip([-1]+h,h)if x!=y] d=defaultdict(list) for i,x in enumerate(h): d[x].append(i+1) t=ans=int(h!=[0]) h=[-1]+h+[-1] for y,l in sorted(d.items()): for i in l : if h[i-1]h[i+1]: t-=1 elif(h[i-1]>y)^(h[i+1]>y): pass else : t+=1 ans=max(t,ans) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var h : OclAny := null; Sequence{n,h} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h : Sequence := Integer.subrange(1, Sequence{ -1 }->union(h)->size())->collect( _indx | Sequence{Sequence{ -1 }->union(h)->at(_indx), h->at(_indx)} )->select(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in x /= y)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (y)) ; var d : OclAny := defaultdict(OclType["Sequence"]) ; for _tuple : Integer.subrange(1, (h)->size())->collect( _indx | Sequence{_indx-1, (h)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ))))) ; var t : OclAny := ("" + ((h /= Sequence{ 0 })))->toInteger(); var ans : int := ("" + ((h /= Sequence{ 0 })))->toInteger() ; h := Sequence{ -1 }->union(h)->union(Sequence{ -1 }) ; for _tuple : d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sort() do (var _indx : int := 1; var y : OclAny := _tuple->at(_indx); _indx := _indx + 1; var l : OclAny := _tuple->at(_indx); for i : l do ( if (h[i - 1+1]->compareTo(y)) < 0 & (y > h[i + 1+1]) then ( t := t - 1 ) else (if MathLib.bitwiseXor(((h[i - 1+1]->compareTo(y)) > 0), ((h[i + 1+1]->compareTo(y)) > 0)) then ( skip ) else ( t := t + 1 ) ) ) ; ans := Set{t, ans}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nobleInteger(arr): arr.sort() n=len(arr) for i in range(n-1): if arr[i]==arr[i+1]: continue if arr[i]==n-i-1 : return arr[i] if arr[n-1]==0 : return arr[n-1] return-1 arr=[10,3,20,40,2] res=nobleInteger(arr) if res!=-1 : print("The noble integer is",res) else : print("No Noble Intger Found") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{10}->union(Sequence{3}->union(Sequence{20}->union(Sequence{40}->union(Sequence{ 2 })))) ; var res : OclAny := nobleInteger(arr) ; if res /= -1 then ( execute ("The noble integer is")->display() ) else ( execute ("No Noble Intger Found")->display() ); operation nobleInteger(arr : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var n : int := (arr)->size() ; for i : Integer.subrange(0, n - 1-1) do ( if arr[i+1] = arr[i + 1+1] then ( continue ) else skip ; if arr[i+1] = n - i - 1 then ( return arr[i+1] ) else skip) ; if arr[n - 1+1] = 0 then ( return arr[n - 1+1] ) else skip ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from collections import deque def is_ok(x,y): return 0<=x<8 and 0<=y<8 n=int(input()) for aa in range(n): g=[input()[:-1]for _ in range(8)] if aa!=n-1 : input() d=[] for i in range(8): for j in range(8): if g[i][j]=='K' : s={(i,j,0)} q=deque([(i,j,0)]) while 1 : a,b,c=q.popleft() if c==5 : break for u,v in[(2,2),(-2,-2),(-2,2),(2,-2)]: if is_ok(a+u,b+v): q.append((a+u,b+v,c+1)) s.add((a+u,b+v,c+1)) d.append(s) x=d[0]& d[1] for i,j,p in x : if g[i][j]in '.K' : print('YES') break else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for aa : Integer.subrange(0, n-1) do ( var g : Sequence := Integer.subrange(0, 8-1)->select(_anon | true)->collect(_anon | (input()->front())) ; if aa /= n - 1 then ( input() ) else skip ; var d : Sequence := Sequence{} ; for i : Integer.subrange(0, 8-1) do ( for j : Integer.subrange(0, 8-1) do ( if g[i+1][j+1] = 'K' then ( var s : Set := Set{ Sequence{i, j, 0} } ; var q : Sequence := (Sequence{ Sequence{i, j, 0} }) ; while 1 do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := q->first() ; q := q->tail() ; if c = 5 then ( break ) else skip ; for _tuple : Sequence{Sequence{2, 2}}->union(Sequence{Sequence{-2, -2}}->union(Sequence{Sequence{-2, 2}}->union(Sequence{ Sequence{2, -2} }))) do (var _indx : int := 1; var u : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if is_ok(a + u, b + v) then ( execute ((Sequence{a + u, b + v, c + 1}) : q) ; execute ((Sequence{a + u, b + v, c + 1}) : s) ) else skip)) ; execute ((s) : d) ) else skip)) ; x := MathLib.bitwiseAnd(d->first(), d[1+1]) ; (compound_stmt for (exprlist (expr (atom (name i))) , (expr (atom (name j))) , (expr (atom (name p)))) in (testlist (test (logical_test (comparison (expr (atom (name x))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) in (comparison (expr (atom '.K')))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) )))))))))))))))); operation is_ok(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return 0 <= x & (x < 8) & 0 <= y & (y < 8); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lst=[[]*8 for i in range(n)] for i in range(n): for j in range(8): lst[i].append(input()) if i!=n-1 : input() for i in range(n): s=lst[i] strk1=stlb1=-1 for j in range(8): if s[j].find('K')!=-1 : if strk1==-1 : strk1=j stlb1=s[j].index('K') else : strk2=j stlb2=s[j].index('K') s[j]=s[j].replace('K','.',1) if s[j].find('K')!=-1 : if strk1==-1 : strk1=j stlb1=s[j].index('K') else : strk2=j stlb2=s[j].index('K') if abs(strk1-strk2)% 4==abs(stlb1-stlb2)% 4==0 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{}, 8))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, 8-1) do ((expr (atom (name lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))) ; if i /= n - 1 then ( input() ) else skip) ; for i : Integer.subrange(0, n-1) do ( var s : OclAny := lst[i+1] ; var strk1 : OclAny := -1; var stlb1 : int := -1 ; for j : Integer.subrange(0, 8-1) do ( if s[j+1]->indexOf('K') - 1 /= -1 then ( if strk1 = -1 then ( strk1 := j ; stlb1 := s[j+1]->indexOf('K') - 1 ) else ( var strk2 : OclAny := j ; var stlb2 : OclAny := s[j+1]->indexOf('K') - 1 ) ) else skip ; s[j+1] := s[j+1].replace('K', '.', 1) ; if s[j+1]->indexOf('K') - 1 /= -1 then ( if strk1 = -1 then ( strk1 := j ; stlb1 := s[j+1]->indexOf('K') - 1 ) else ( strk2 := j ; stlb2 := s[j+1]->indexOf('K') - 1 ) ) else skip) ; if (strk1 - strk2)->abs() mod 4 = (stlb1 - stlb2)->abs() mod 4 & ((stlb1 - stlb2)->abs() mod 4 == 0) then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) out="" for t in range(n): knights=[0 for i in range(16)] valid=[False for i in range(16)] for i in range(8): line=input() for j in range(8): if line[j]!='#' : valid[get(i,j)]=True if line[j]=='K' : knights[get(i,j)]+=1 for i in range(16): if knights[i]==2 and valid[i]: out+="YES\n" break else : out+="NO\n" if t!=n-1 : input() print(out[:-1]) def get(i,j): return[[0,1,2,3],[4,5,6,7],[8,9,10,11],[12,13,14,15]][i % 4][j % 4] if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var out : String := "" ; for t : Integer.subrange(0, n-1) do ( var knights : Sequence := Integer.subrange(0, 16-1)->select(i | true)->collect(i | (0)) ; var valid : Sequence := Integer.subrange(0, 16-1)->select(i | true)->collect(i | (false)) ; for i : Integer.subrange(0, 8-1) do ( var line : String := (OclFile["System.in"]).readLine() ; for j : Integer.subrange(0, 8-1) do ( if line[j+1] /= '#' then ( valid[get(i, j)+1] := true ) else skip ; if line[j+1] = 'K' then ( knights[get(i, j)+1] := knights[get(i, j)+1] + 1 ) else skip)) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 16))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name knights)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (number (integer 2))))))) and (logical_test (comparison (expr (atom (name valid)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name out)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom "YES\n")))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name out)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom "NO\n"))))))))))))) ; if t /= n - 1 then ( input() ) else skip) ; execute (out->front())->display(); operation get(i : OclAny, j : OclAny) : OclAny pre: true post: true activity: return Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })))}->union(Sequence{Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 7 })))}->union(Sequence{Sequence{8}->union(Sequence{9}->union(Sequence{10}->union(Sequence{ 11 })))}->union(Sequence{ Sequence{12}->union(Sequence{13}->union(Sequence{14}->union(Sequence{ 15 }))) })))[i mod 4+1][j mod 4+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMax(arr,n): res=0 for i in range(1,n): count=0 for j in range(0,i): if arr[j]% arr[i]==0 : count+=1 res=max(count,res) return res arr=[8,1,28,4,2,6,7] n=len(arr) print(findMax(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{8}->union(Sequence{1}->union(Sequence{28}->union(Sequence{4}->union(Sequence{2}->union(Sequence{6}->union(Sequence{ 7 })))))) ; n := (arr)->size() ; execute (findMax(arr, n))->display(); operation findMax(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; for i : Integer.subrange(1, n-1) do ( var count : int := 0 ; for j : Integer.subrange(0, i-1) do ( if arr[j+1] mod arr[i+1] = 0 then ( count := count + 1 ) else skip) ; res := Set{count, res}->max()) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for l in range(n): pos=[] for i in range(8): s=input() for j in range(8): if s[j]=='K' : pos.append((i,j)) print('YES' if abs(pos[0][0]-pos[1][0])% 4==abs(pos[0][1]-pos[1][1])% 4==0 else 'NO') if l!=n-1 : input() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for l : Integer.subrange(0, n-1) do ( var pos : Sequence := Sequence{} ; for i : Integer.subrange(0, 8-1) do ( var s : String := (OclFile["System.in"]).readLine() ; for j : Integer.subrange(0, 8-1) do ( if s[j+1] = 'K' then ( execute ((Sequence{i, j}) : pos) ) else skip)) ; execute (if (pos->first()->first() - pos[1+1]->first())->abs() mod 4 = (pos->first()[1+1] - pos[1+1][1+1])->abs() mod 4 & ((pos->first()[1+1] - pos[1+1][1+1])->abs() mod 4 == 0) then 'YES' else 'NO' endif)->display() ; if l /= n - 1 then ( input() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from collections import deque def is_ok(x,y): return 0<=x<8 and 0<=y<8 n=int(input()) for aa in range(n): g=[input()[:-1]for _ in range(8)] if aa!=n-1 : input() d=[] for i in range(8): for j in range(8): if g[i][j]=='K' : s={(i,j,0)} q=deque([(i,j,0)]) while 1 : a,b,c=q.popleft() if c==8 : break for u,v in[(2,2),(-2,-2),(-2,2),(2,-2)]: if is_ok(a+u,b+v): q.append((a+u,b+v,c+1)) s.add((a+u,b+v,c+1)) d.append(s) x=d[0]& d[1] for i,j,p in x : if g[i][j]in '.K' : print('YES') break else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for aa : Integer.subrange(0, n-1) do ( var g : Sequence := Integer.subrange(0, 8-1)->select(_anon | true)->collect(_anon | (input()->front())) ; if aa /= n - 1 then ( input() ) else skip ; var d : Sequence := Sequence{} ; for i : Integer.subrange(0, 8-1) do ( for j : Integer.subrange(0, 8-1) do ( if g[i+1][j+1] = 'K' then ( var s : Set := Set{ Sequence{i, j, 0} } ; var q : Sequence := (Sequence{ Sequence{i, j, 0} }) ; while 1 do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := q->first() ; q := q->tail() ; if c = 8 then ( break ) else skip ; for _tuple : Sequence{Sequence{2, 2}}->union(Sequence{Sequence{-2, -2}}->union(Sequence{Sequence{-2, 2}}->union(Sequence{ Sequence{2, -2} }))) do (var _indx : int := 1; var u : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if is_ok(a + u, b + v) then ( execute ((Sequence{a + u, b + v, c + 1}) : q) ; execute ((Sequence{a + u, b + v, c + 1}) : s) ) else skip)) ; execute ((s) : d) ) else skip)) ; x := MathLib.bitwiseAnd(d->first(), d[1+1]) ; (compound_stmt for (exprlist (expr (atom (name i))) , (expr (atom (name j))) , (expr (atom (name p)))) in (testlist (test (logical_test (comparison (expr (atom (name x))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) in (comparison (expr (atom '.K')))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) )))))))))))))))); operation is_ok(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return 0 <= x & (x < 8) & 0 <= y & (y < 8); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_tests=int(input()) a,b=map(int,input().split()) answer=[] answer.append(max(a,b)) for i in range(num_tests-1): two=list(map(int,input().split())) if min(two)<=answer[-1]: answer.append(max([i for i in two if i<=answer[-1]])) else : print('NO') break if len(answer)==num_tests : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_tests : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var answer : Sequence := Sequence{} ; execute ((Set{a, b}->max()) : answer) ; for i : Integer.subrange(0, num_tests - 1-1) do ( var two : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if ((two)->min()->compareTo(answer->last())) <= 0 then ( execute (((two->select(i | (i->compareTo(answer->last())) <= 0)->collect(i | (i)))->max()) : answer) ) else ( execute ('NO')->display() ; break )) ; if (answer)->size() = num_tests then ( execute ('YES')->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- te=int(input()) while te>0 : te-=1 X=[int(x)for x in input().split(' ')] n,m,rb,cb,rd,cd=X[0],X[1],X[2],X[3],X[4],X[5] count=0 r=c=1 while True : if rb==rd or cb==cd : break if rb+r<1 or rb+r>n : r*=-1 if cb+c<1 or cb+c>m : c*=-1 rb+=r cb+=c count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var te : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while te > 0 do ( te := te - 1 ; var X : Sequence := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var n : OclAny := null; var m : OclAny := null; var rb : OclAny := null; var cb : OclAny := null; var rd : OclAny := null; var cd : OclAny := null; Sequence{n,m,rb,cb,rd,cd} := Sequence{X->first(),X[1+1],X[2+1],X[3+1],X[4+1],X[5+1]} ; var count : int := 0 ; var r : OclAny := 1; var c : int := 1 ; while true do ( if rb = rd or cb = cd then ( break ) else skip ; if rb + r < 1 or (rb + r->compareTo(n)) > 0 then ( r := r * -1 ) else skip ; if cb + c < 1 or (cb + c->compareTo(m)) > 0 then ( c := c * -1 ) else skip ; rb := rb + r ; cb := cb + c ; count := count + 1) ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from collections import defaultdict def input_ints(): return list(map(int,input().split())) def solve(): n=int(input()) x=10**10 for i in range(n): a=sorted(input_ints()) if a[1]<=x : x=a[1] elif a[0]<=x : x=a[0] else : print('NO') return print('YES') if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation input_ints() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : double := (10)->pow(10) ; for i : Integer.subrange(0, n-1) do ( var a : Sequence := input_ints()->sort() ; if (a[1+1]->compareTo(x)) <= 0 then ( x := a[1+1] ) else (if (a->first()->compareTo(x)) <= 0 then ( x := a->first() ) else ( execute ('NO')->display() ; return ) ) ) ; execute ('YES')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() n=int(input()) x=10**9 for _ in[0]*n : w,h=sorted(map(int,input().split())); x=h if h<=x else w if w<=x else 0 print(('NO','YES')[x>0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : double := (10)->pow(9) ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, n) do ( var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort(); x := if (h->compareTo(x)) <= 0 then h else if (w->compareTo(x)) <= 0 then w else 0 endif endif) ; execute (Sequence{'NO', 'YES'}->select(x > 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys num=int(sys.stdin.readline()) arr=[] isPass=True for i in range(0,num): line=sys.stdin.readline() line=line.split() line=[int(numeric_string)for numeric_string in line] line=sorted(line) if arr==[]: arr.append(line[1]) if arr[-1]>=line[1]: arr.append(line[1]) elif arr[-1]>=line[0]: arr.append(line[0]) else : isPass=False if isPass : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Sequence{} ; var isPass : boolean := true ; for i : Integer.subrange(0, num-1) do ( var line : String := (OclFile["System.in"]).readLine() ; line := line.split() ; line := line->characters()->select(numeric_string | true)->collect(numeric_string | (("" + ((numeric_string)))->toInteger())) ; line := line->sort() ; if arr = Sequence{} then ( execute ((line[1+1]) : arr) ) else skip ; if (arr->last()->compareTo(line[1+1])) >= 0 then ( execute ((line[1+1]) : arr) ) else (if (arr->last()->compareTo(line->first())) >= 0 then ( execute ((line->first()) : arr) ) else ( isPass := false ) ) ) ; if isPass then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) inf=pow(10,9)+1 ma=inf ans="YES" for _ in range(n): h,w=map(int,input().split()) if ma>=max(h,w): ma=max(h,w) elif ma>=min(h,w): ma=min(h,w) else : ans="NO" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var Math_PINFINITY : double := (10)->pow(9) + 1 ; var ma : double := Math_PINFINITY ; var ans : String := "YES" ; for _anon : Integer.subrange(0, n-1) do ( var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (ma->compareTo(Set{h, w}->max())) >= 0 then ( ma := Set{h, w}->max() ) else (if (ma->compareTo(Set{h, w}->min())) >= 0 then ( ma := Set{h, w}->min() ) else ( ans := "NO" ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxSquare(b,m): return(b/m-1)*(b/m)/2 b=10 m=2 print(int(maxSquare(b,m))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; b := 10 ; m := 2 ; execute (("" + ((maxSquare(b, m))))->toInteger())->display(); operation maxSquare(b : OclAny, m : OclAny) : OclAny pre: true post: true activity: return (b / m - 1) * (b / m) / 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def MinOfCubed(k): if(k<8): return k ; res=k ; for i in range(1,k+1): if((i*i*i)>k): return res ; res=min(res,MinOfCubed(k-(i*i*i))+1); return res ; num=15 ; print(MinOfCubed(num)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var num : int := 15; ; execute (MinOfCubed(num))->display();; operation MinOfCubed(k : OclAny) pre: true post: true activity: if (k < 8) then ( return k; ) else skip ; var res : OclAny := k; ; for i : Integer.subrange(1, k + 1-1) do ( if (((i * i * i)->compareTo(k)) > 0) then ( return res; ) else skip ; res := Set{res, MinOfCubed(k - (i * i * i)) + 1}->min();) ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def findGCD(arr,n): result=arr[0] for i in range(1,n): result=gcd(arr[i],result) return result def compute(arr,n): answer=[] GCD_of_array=findGCD(arr,n) if(GCD_of_array==arr[0]): answer.append(arr[0]) for i in range(1,n): answer.append(arr[0]) answer.append(arr[i]) for i in range(len(answer)): print(answer[i],end=" ") else : print("No array can be build") if __name__=='__main__' : n=3 input=[2,5,6,7,11] GCD=set() for i in range(len(input)): GCD.add(input[i]) arr=[] for i in GCD : arr.append(i) compute(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( n := 3 ; var input : Sequence := Sequence{2}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 11 })))) ; var GCD : Set := Set{}->union(()) ; for i : Integer.subrange(0, (input)->size()-1) do ( execute (((OclFile["System.in"]).readLine[i+1]) : GCD)) ; arr := Sequence{} ; for i : GCD do ( execute ((i) : arr)) ; compute(arr, n) ) else skip; operation findGCD(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var result : OclAny := arr->first() ; for i : Integer.subrange(1, n-1) do ( result := gcd(arr[i+1], result)) ; return result; operation compute(arr : OclAny, n : OclAny) pre: true post: true activity: var answer : Sequence := Sequence{} ; var GCD_of_array : OclAny := findGCD(arr, n) ; if (GCD_of_array = arr->first()) then ( execute ((arr->first()) : answer) ; for i : Integer.subrange(1, n-1) do ( execute ((arr->first()) : answer) ; execute ((arr[i+1]) : answer)) ; for i : Integer.subrange(0, (answer)->size()-1) do ( execute (answer[i+1])->display()) ) else ( execute ("No array can be build")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMax(arr,n): divisible=[False]*n ; res=0 ; for i in range(n-1,-1,-1): if(divisible[i]): continue ; cnt=0 ; for j in range(i): if((arr[j]% arr[i])==0): divisible[j]=True ; cnt+=1 ; res=max(res,cnt); return res ; if __name__=="__main__" : arr=[8,1,28,4,2,6,7]; n=len(arr); print(findMax(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{8}->union(Sequence{1}->union(Sequence{28}->union(Sequence{4}->union(Sequence{2}->union(Sequence{6}->union(Sequence{ 7 })))))); ; n := (arr)->size(); ; execute (findMax(arr, n))->display(); ) else skip; operation findMax(arr : OclAny, n : OclAny) pre: true post: true activity: var divisible : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n); ; var res : int := 0; ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (divisible[i+1]) then ( continue; ) else skip ; var cnt : int := 0; ; for j : Integer.subrange(0, i-1) do ( if ((arr[j+1] mod arr[i+1]) = 0) then ( divisible[j+1] := true; ; cnt := cnt + 1; ) else skip) ; res := Set{res, cnt}->max();) ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r=p=0 l=[0,0] for c in input(): f=c=='<' if c!=p : p=c if f : r-=min(l) l=[0,0] l[f]+=1 r+=l[f] if not f : r-=min(l) print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : OclAny := 0; var p : int := 0 ; var l : Sequence := Sequence{0}->union(Sequence{ 0 }) ; for c : (OclFile["System.in"]).readLine() do ( var f : boolean := c = '<' ; if c /= p then ( p := c ; if f then ( r := r - (l)->min() ; l := Sequence{0}->union(Sequence{ 0 }) ) else skip ) else skip ; l[f+1] := l[f+1] + 1 ; r := r + l[f+1]) ; if not(f) then ( r := r - (l)->min() ) else skip ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): S=input() from itertools import groupby ans=0 SL=[(k,len(list(v)))for k,v in groupby(S)] if SL[0][0]==">" : ans+=(SL[0][1])*(SL[0][1]+1)//2 pre_v=SL[0][1] for k,v in SL[1 :]: if k=="<" : pre_v=v continue else : if pre_v>v : ans+=pre_v*(pre_v+1)//2 ans+=v*(v-1)//2 else : ans+=(pre_v-1)*pre_v//2 ans+=v*(v+1)//2 pre_v=v else : pre_v=0 for k,v in SL : if k=="<" : pre_v=v continue else : if pre_v>v : ans+=pre_v*(pre_v+1)//2 ans+=v*(v-1)//2 else : ans+=(pre_v-1)*pre_v//2 ans+=v*(v+1)//2 pre_v=v if SL[-1][0]=="<" : ans+=(SL[-1][1])*(SL[-1][1]+1)//2 print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; skip ; var ans : int := 0 ; var SL : Sequence := groupby(S)->select(_tuple | true)->collect(_tuple | let k : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in (Sequence{k, ((v))->size()})) ; if SL->first()->first() = ">" then ( ans := ans + (SL->first()[1+1]) * (SL->first()[1+1] + 1) div 2 ; var pre_v : OclAny := SL->first()[1+1] ; for _tuple : SL->tail() do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if k = "<" then ( pre_v := v ; continue ) else ( if (pre_v->compareTo(v)) > 0 then ( ans := ans + pre_v * (pre_v + 1) div 2 ; ans := ans + v * (v - 1) div 2 ) else ( ans := ans + (pre_v - 1) * pre_v div 2 ; ans := ans + v * (v + 1) div 2 ) ) ; pre_v := v) ) else ( pre_v := 0 ; for _tuple : SL do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if k = "<" then ( pre_v := v ; continue ) else ( if (pre_v->compareTo(v)) > 0 then ( ans := ans + pre_v * (pre_v + 1) div 2 ; ans := ans + v * (v - 1) div 2 ) else ( ans := ans + (pre_v - 1) * pre_v div 2 ; ans := ans + v * (v + 1) div 2 ) ) ; pre_v := v) ) ; if SL->last()->first() = "<" then ( ans := ans + (SL->last()[1+1]) * (SL->last()[1+1] + 1) div 2 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,m,row,col,target_row,target_col=map(int,input().split()) seconds=0 if target_rowtoInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; var row : OclAny := null; var col : OclAny := null; var target_row : OclAny := null; var target_col : OclAny := null; Sequence{n,m,row,col,target_row,target_col} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var seconds : int := 0 ; if (target_row->compareTo(row)) < 0 then ( var target_row : double := (n - row) + (n - target_row) ) else ( target_row := target_row - row ) ; if (target_col->compareTo(col)) < 0 then ( var target_col : double := (m - col) + (m - target_col) ) else ( target_col := target_col - col ) ; execute (Set{target_row, target_col}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() if s[0]==">" : s="<"+s if s[-1]=="<" : s=s+">" tmps="<" tmp1,tmp2=0,0 ans=0 for i in s : if tmps=="<" : if i=="<" : tmp1+=1 else : tmps=i tmp2+=1 else : if i==">" : tmp2+=1 else : ans+=tmp1*(tmp1+1)//2+tmp2*(tmp2+1)//2-min(tmp1,tmp2) tmp1,tmp2=1,0 tmps=i ans+=tmp1*(tmp1+1)//2+tmp2*(tmp2+1)//2-min(tmp1,tmp2) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; if s->first() = ">" then ( s := "<" + s ) else skip ; if s->last() = "<" then ( s := s + ">" ) else skip ; var tmps : String := "<" ; var tmp1 : OclAny := null; var tmp2 : OclAny := null; Sequence{tmp1,tmp2} := Sequence{0,0} ; var ans : int := 0 ; for i : s->characters() do ( if tmps = "<" then ( if i = "<" then ( tmp1 := tmp1 + 1 ) else ( tmps := i ; tmp2 := tmp2 + 1 ) ) else ( if i = ">" then ( tmp2 := tmp2 + 1 ) else ( ans := ans + tmp1 * (tmp1 + 1) div 2 + tmp2 * (tmp2 + 1) div 2 - Set{tmp1, tmp2}->min() ; var tmp1 : OclAny := null; var tmp2 : OclAny := null; Sequence{tmp1,tmp2} := Sequence{1,0} ; tmps := i ) )) ; ans := ans + tmp1 * (tmp1 + 1) div 2 + tmp2 * (tmp2 + 1) div 2 - Set{tmp1, tmp2}->min() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() inc=0 dec=0 sum=0 def solve(i,d): ans=0 if i>=d : i+=1 elif i0 : sum+=solve(inc,dec) inc=0 dec=0 inc+=1 if S[i]=='>' : dec+=1 sum+=solve(inc,dec) print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var inc : int := 0 ; var dec : int := 0 ; var sum : int := 0 ; skip ; for i : Integer.subrange(0, (S)->size()-1) do ( if S[i+1] = '<' then ( if dec > 0 then ( sum := sum + solve(inc, dec) ; inc := 0 ; dec := 0 ) else skip ; inc := inc + 1 ) else skip ; if S[i+1] = '>' then ( dec := dec + 1 ) else skip) ; sum := sum + solve(inc, dec) ; execute (sum)->display(); operation solve(i : OclAny, d : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; if (i->compareTo(d)) >= 0 then ( i := i + 1 ) else (if (i->compareTo(d)) < 0 then ( d := d + 1 ) else skip) ; for c : Integer.subrange(0, i-1) do ( ans := ans + c) ; for c : Integer.subrange(0, d-1) do ( ans := ans + c) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math input=sys.stdin.readline S=input() a=[] b=[] for num,i in enumerate(S): if num!=0 and num!=len(S)-1 : if i=="<" : if S[num-1]==">" : b.append("".join(a)) a=[] elif S[-1]=="<" : if S[num-1]==">" : b.append("".join(a)) a=[] a.append(i) b.append("".join(a)) ans=0 for j in range(len(b)): mx=max(b[j].count("<"),b[j].count(">")) mn=min(b[j].count("<"),b[j].count(">")) ans+=mx*(mx+1)//2 if mn>=2 : ans+=(mn-1)*mn//2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var S : String := (OclFile["System.in"]).readLine() ; var a : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; for _tuple : Integer.subrange(1, (S)->size())->collect( _indx | Sequence{_indx-1, (S)->at(_indx)} ) do (var _indx : int := 1; var num : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); if num /= 0 & num /= (S)->size() - 1 then ( if i = "<" then ( if S[num - 1+1] = ">" then ( execute ((StringLib.sumStringsWithSeparator((a), "")) : b) ; a := Sequence{} ) else skip ) else skip ) else (if S->last() = "<" then ( if S[num - 1+1] = ">" then ( execute ((StringLib.sumStringsWithSeparator((a), "")) : b) ; a := Sequence{} ) else skip ) else skip) ; execute ((i) : a)) ; execute ((StringLib.sumStringsWithSeparator((a), "")) : b) ; var ans : int := 0 ; for j : Integer.subrange(0, (b)->size()-1) do ( var mx : OclAny := Set{b[j+1]->count("<"), b[j+1]->count(">")}->max() ; var mn : OclAny := Set{b[j+1]->count("<"), b[j+1]->count(">")}->min() ; ans := ans + mx * (mx + 1) div 2 ; if mn >= 2 then ( ans := ans + (mn - 1) * mn div 2 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def polygonArea(X,Y,n): area=0.0 j=n-1 for i in range(0,n): area+=(X[j]+X[i])*(Y[j]-Y[i]) j=i return int(abs(area/2.0)) X=[0,2,4] Y=[1,3,7] n=len(X) print(polygonArea(X,Y,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; X := Sequence{0}->union(Sequence{2}->union(Sequence{ 4 })) ; Y := Sequence{1}->union(Sequence{3}->union(Sequence{ 7 })) ; n := (X)->size() ; execute (polygonArea(X, Y, n))->display(); operation polygonArea(X : OclAny, Y : OclAny, n : OclAny) : OclAny pre: true post: true activity: var area : double := 0.0 ; var j : double := n - 1 ; for i : Integer.subrange(0, n-1) do ( area := area + (X[j+1] + X[i+1]) * (Y[j+1] - Y[i+1]) ; j := i) ; return ("" + (((area / 2.0)->abs())))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def polygonArea(X,Y,n): area=0.0 j=n-1 for i in range(0,n): area=area+(X[j]+X[i])*(Y[j]-Y[i]) j=i return abs(area//2.0) X=[0,2,4] Y=[1,3,7] n=len(X) print(polygonArea(X,Y,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; X := Sequence{0}->union(Sequence{2}->union(Sequence{ 4 })) ; Y := Sequence{1}->union(Sequence{3}->union(Sequence{ 7 })) ; n := (X)->size() ; execute (polygonArea(X, Y, n))->display(); operation polygonArea(X : OclAny, Y : OclAny, n : OclAny) : OclAny pre: true post: true activity: var area : double := 0.0 ; var j : double := n - 1 ; for i : Integer.subrange(0, n-1) do ( area := area + (X[j+1] + X[i+1]) * (Y[j+1] - Y[i+1]) ; j := i) ; return (area div 2.0)->abs(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) flag=0 xo=[] for i in range(n): s=input() xo.append(s) for i in range(n): for j in range(len(xo[i])): c=0 if(j-1>=0 and xo[i][j-1]=='o'): c+=1 if(i-1>=0 and xo[i-1][j]=='o'): c+=1 if(i+1toInteger() ; var flag : int := 0 ; var xo : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; execute ((s) : xo)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, (xo[i+1])->size()-1) do ( var c : int := 0 ; if (j - 1 >= 0 & xo[i+1][j - 1+1] = 'o') then ( c := c + 1 ) else skip ; if (i - 1 >= 0 & xo[i - 1+1][j+1] = 'o') then ( c := c + 1 ) else skip ; if ((i + 1->compareTo(n)) < 0 & xo[i + 1+1][j+1] = 'o') then ( c := c + 1 ) else skip ; if ((j + 1->compareTo((xo[i+1])->size())) < 0 & xo[i+1][j + 1+1] = 'o') then ( c := c + 1 ) else skip ; if (c mod 2 /= 0) then ( flag := 1 ; break ) else skip)) ; if (flag = 1) then ( execute ('NO')->display() ) else ( execute ('YES')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) l=[] bo=True for i in range(x): l.append(input()) for i in range(x): for j in range(x): counter=0 if i-1>=0 and l[i-1][j]=='o' : counter+=1 if i+1=0 and l[i][j-1]=='o' : counter+=1 if counter % 2==1 : bo=False print('NO') exit() if bo : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; var bo : boolean := true ; for i : Integer.subrange(0, x-1) do ( execute (((OclFile["System.in"]).readLine()) : l)) ; for i : Integer.subrange(0, x-1) do ( for j : Integer.subrange(0, x-1) do ( var counter : int := 0 ; if i - 1 >= 0 & l[i - 1+1][j+1] = 'o' then ( counter := counter + 1 ) else skip ; if (i + 1->compareTo(x)) < 0 & l[i + 1+1][j+1] = 'o' then ( counter := counter + 1 ) else skip ; if (j + 1->compareTo(x)) < 0 & l[i+1][j + 1+1] = 'o' then ( counter := counter + 1 ) else skip ; if j - 1 >= 0 & l[i+1][j - 1+1] = 'o' then ( counter := counter + 1 ) else skip ; if counter mod 2 = 1 then ( bo := false ; execute ('NO')->display() ; exit() ) else skip)) ; if bo then ( execute ('YES')->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): n=int(input()) grid=[] for _ in range(n): grid.append(input()) for i in range(n): for j in range(n): count=0 for di,dj in[(0,1),(1,0),(0,-1),(-1,0)]: ni=i+di nj=j+dj if ni<0 or nj<0 or ni>=n or nj>=n : continue count+=grid[ni][nj]=="o" if count % 2==1 : print("NO") return print("YES") def main(): t=1 for _ in range(t): solution() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; main(); operation solution() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var grid : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : grid)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( var count : int := 0 ; for _tuple : Sequence{Sequence{0, 1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{0, -1}}->union(Sequence{ Sequence{-1, 0} }))) do (var _indx : int := 1; var di : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dj : OclAny := _tuple->at(_indx); var ni : OclAny := i + di ; var nj : OclAny := j + dj ; if ni < 0 or nj < 0 or (ni->compareTo(n)) >= 0 or (nj->compareTo(n)) >= 0 then ( continue ) else skip ; count := count + grid[ni+1][nj+1] = "o") ; if count mod 2 = 1 then ( execute ("NO")->display() ; return ) else skip)) ; execute ("YES")->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) for i in range(a): b=int(input()) n=b//2 n1=(b-2)//2 c=(n+1)*n-n1**2 if c % 2==1 : print("YES") for j in range(2,b+2,2): print(j,end=" ") for j in range(1,b-2,2): print(j,end=" ") print(c) else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, a-1) do ( var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n : int := b div 2 ; var n1 : int := (b - 2) div 2 ; var c : double := (n + 1) * n - (n1)->pow(2) ; if c mod 2 = 1 then ( execute ("YES")->display() ; for j : Integer.subrange(2, b + 2-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( execute (j)->display()) ; for j : Integer.subrange(1, b - 2-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( execute (j)->display()) ; execute (c)->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- X='' for i in range(int(input())): X+=input() print("YES" if X==X[: :-1]else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var X : String := '' ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( X := X + (OclFile["System.in"]).readLine()) ; execute (if X = X(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then "YES" else "NO" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): r,c,i,j,a,b=list(map(int,input().split())) x,y=b-j,a-i ox=oy=0 if x>0 and y>0 : oy=a-i ox=b-j elif x>0 and y<0 : oy=2*r-a-i ox=b-j elif x<0 and y>0 : oy=a-i ox=2*c-j-b elif x<0 and y<0 : ox=2*c-b-j oy=2*r-a-i print(min(ox,oy)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var r : OclAny := null; var c : OclAny := null; var i : OclAny := null; var j : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{r,c,i,j,a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{b - j,a - i} ; var ox : OclAny := 0; var oy : int := 0 ; if x > 0 & y > 0 then ( oy := a - i ; ox := b - j ) else (if x > 0 & y < 0 then ( oy := 2 * r - a - i ; ox := b - j ) else (if x < 0 & y > 0 then ( oy := a - i ; ox := 2 * c - j - b ) else (if x < 0 & y < 0 then ( ox := 2 * c - b - j ; oy := 2 * r - a - i ) else skip ) ) ) ; execute (Set{ox, oy}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100001 ; def find_distinct(a,n,q,queries): check=[0]*MAX ; idx=[0]*MAX ; cnt=1 ; for i in range(n-1,-1,-1): if(check[a[i]]==0): idx[i]=cnt ; check[a[i]]=1 ; cnt+=1 ; else : idx[i]=cnt-1 ; for i in range(0,q): m=queries[i]; print(idx[m],end=" "); a=[1,2,3,1,2,3,4,5]; n=len(a); queries=[0,3,5,7]; q=len(queries); find_distinct(a,n,q,queries); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 100001; ; skip ; a := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 }))))))); ; n := (a)->size(); ; queries := Sequence{0}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 7 }))); ; q := (queries)->size(); ; find_distinct(a, n, q, queries);; operation find_distinct(a : OclAny, n : OclAny, q : OclAny, queries : OclAny) pre: true post: true activity: var check : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX); ; var idx : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX); ; var cnt : int := 1; ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (check[a[i+1]+1] = 0) then ( idx[i+1] := cnt; ; check[a[i+1]+1] := 1; ; cnt := cnt + 1; ) else ( idx[i+1] := cnt - 1; )) ; for i : Integer.subrange(0, q-1) do ( var m : OclAny := queries[i+1]; ; execute (idx[m+1])->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) p=list(map(int,input().split())) score=[0]*101 for x in p : score[x]+=1 print(max(i*(sum(score[i :])>=i)for i in range(101))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var score : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 101) ; for x : p do ( score[x+1] := score[x+1] + 1) ; execute (((argument (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name score)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))) :)) ])))))))) ))))) >= (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 101))))))))) )))))))))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy from test.support import _MemoryWatchdog BIG_NUM=2000000000 HUGE_NUM=99999999999999999 MOD=1000000007 EPS=0.000000001 sys.setrecursionlimit(100000) SIZE=105 table=[0]*SIZE N=int(input()) input_array=list(map(int,input().split())) maximum=0 for i in range(N): table[0]-=1 table[input_array[i]]+=1 maximum=max(maximum,input_array[i]) for i in range(maximum-1,-1,-1): table[i]+=table[i+1] ans=0 for i in range(1,maximum+1): if i<=table[i]: ans=i print("%d" %(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var HUGE_NUM : int := 99999999999999999 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; sys.setrecursionlimit(100000) ; var SIZE : int := 105 ; var table : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, SIZE) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var input_array : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var maximum : int := 0 ; for i : Integer.subrange(0, N-1) do ( table->first() := table->first() - 1 ; table[input_array[i+1]+1] := table[input_array[i+1]+1] + 1 ; maximum := Set{maximum, input_array[i+1]}->max()) ; for i : Integer.subrange(-1 + 1, maximum - 1)->reverse() do ( table[i+1] := table[i+1] + table[i + 1+1]) ; var ans : int := 0 ; for i : Integer.subrange(1, maximum + 1-1) do ( if (i->compareTo(table[i+1])) <= 0 then ( ans := i ) else skip) ; execute (StringLib.format("%d",(ans)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : N=int(input()) score_list=list(map(int,input().split())) score_list.sort(reverse=True) ctr=1 for element in score_list : if ctr>element : print(ctr-1) break ctr+=1 else : print(ctr-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var score_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; score_list := score_list->sort() ; var ctr : int := 1 ; (compound_stmt for (exprlist (expr (atom (name element)))) in (testlist (test (logical_test (comparison (expr (atom (name score_list))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name ctr)))) > (comparison (expr (atom (name element))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name ctr))) - (expr (atom (number (integer 1)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ctr)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name ctr))) - (expr (atom (number (integer 1)))))))))) ))))))))))))))) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(p,A): cnt=0 for a in p : if a>=A : cnt+=1 return cnt>=A def main(): N=int(input()) p=list(map(int,input().split())) for A in range(100,-1,-1): if check(p,A): print(A) return if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation check(p : OclAny, A : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; for a : p do ( if (a->compareTo(A)) >= 0 then ( cnt := cnt + 1 ) else skip) ; return (cnt->compareTo(A)) >= 0; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; p := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for A : Integer.subrange(-1 + 1, 100)->reverse() do ( if check(p, A) then ( execute (A)->display() ; return ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) p=[int(i)for i in input().split()] p.sort() p.reverse() ans=0 for i in range(len(p)): if p[i]>=i+1 : ans=i+1 else : break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; p := p->sort() ; p := p->reverse() ; var ans : int := 0 ; for i : Integer.subrange(0, (p)->size()-1) do ( if (p[i+1]->compareTo(i + 1)) >= 0 then ( ans := i + 1 ) else ( break )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumDigitSquare(n): sq=0 while(n): digit=n % 10 sq=sq+digit*digit n=n//10 return sq def isHappy(n): while(1): if(n==1): return True n=sumDigitSquare(n) if(n==4): return False return False n=23 if(isHappy(n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 23 ; if (isHappy(n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation sumDigitSquare(n : OclAny) : OclAny pre: true post: true activity: var sq : int := 0 ; while (n) do ( var digit : int := n mod 10 ; sq := sq + digit * digit ; n := n div 10) ; return sq; operation isHappy(n : OclAny) : OclAny pre: true post: true activity: while (1) do ( if (n = 1) then ( return true ) else skip ; n := sumDigitSquare(n) ; if (n = 4) then ( return false ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def exponential(n,x): sum=1.0 for i in range(n,0,-1): sum=1+x*sum/i print("e^x=",sum) n=10 x=1.0 exponential(n,x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 10 ; x := 1.0 ; exponential(n, x); operation exponential(n : OclAny, x : OclAny) pre: true post: true activity: var sum : double := 1.0 ; for i : Integer.subrange(0 + 1, n)->reverse() do ( sum := 1 + x * sum / i) ; execute ("e^x=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def trailingZero(x): i=5 count=0 while(x>i): count=count+x//i i=i*5 return count def countProductTrailing(M,N): return trailingZero(N)+trailingZero(M) N=67 M=98 print(countProductTrailing(N,M)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; N := 67 ; M := 98 ; execute (countProductTrailing(N, M))->display(); operation trailingZero(x : OclAny) : OclAny pre: true post: true activity: var i : int := 5 ; var count : int := 0 ; while ((x->compareTo(i)) > 0) do ( count := count + x div i ; i := i * 5) ; return count; operation countProductTrailing(M : OclAny, N : OclAny) : OclAny pre: true post: true activity: return trailingZero(N) + trailingZero(M); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) if n % 4==0 : print("YES") for i in range(n//2): print((i+1)*2,end=' ') for i in range(n//2): if i==n//2-1 : print((i+1)*2-1+n//2) break print((i+1)*2-1,end=' ') else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 4 = 0 then ( execute ("YES")->display() ; for i : Integer.subrange(0, n div 2-1) do ( execute ((i + 1) * 2)->display()) ; for i : Integer.subrange(0, n div 2-1) do ( if i = n div 2 - 1 then ( execute ((i + 1) * 2 - 1 + n div 2)->display() ; break ) else skip ; execute ((i + 1) * 2 - 1)->display()) ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,A,B,C,D=map(int,input().split()) if(A<=N or C<=N): if N % A==0 : X=int(N/A)*B else : X=int(N/A+1)*B if N % C==0 : Y=int(N/C)*D else : Y=int(N/C+1)*D else : X=B Y=D if X<=Y : print(int(X)) else : print(int(Y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var D : OclAny := null; Sequence{N,A,B,C,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if ((A->compareTo(N)) <= 0 or (C->compareTo(N)) <= 0) then ( if N mod A = 0 then ( var X : double := ("" + ((N / A)))->toInteger() * B ) else ( X := ("" + ((N / A + 1)))->toInteger() * B ) ; if N mod C = 0 then ( var Y : double := ("" + ((N / C)))->toInteger() * D ) else ( Y := ("" + ((N / C + 1)))->toInteger() * D ) ) else ( X := B ; Y := D ) ; if (X->compareTo(Y)) <= 0 then ( execute (("" + ((X)))->toInteger())->display() ) else ( execute (("" + ((Y)))->toInteger())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) def A(n): ans=1 while(n!=1): ans=ans*n % 1000000007 n-=1 return ans if(a==b): t=A(a) print(t*t*2 % 1000000007) elif(a==b+1 or b==a+1): print(A(a)*A(b)% 1000000007) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; if (a = b) then ( var t : OclAny := A(a) ; execute (t * t * 2 mod 1000000007)->display() ) else (if (a = b + 1 or b = a + 1) then ( execute (A(a) * A(b) mod 1000000007)->display() ) else ( execute (0)->display() ) ) ; operation A(n : OclAny) : OclAny pre: true post: true activity: var ans : int := 1 ; while (n /= 1) do ( ans := ans * n mod 1000000007 ; n := n - 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def ini(): return int(input()) def inli(): return list(map(int,input().split())) def inf(): return float(input()) def inlf(): return list(map(float,input().split())) def inl(): return list(input()) def pli(): return "".join(list(map(str,ans))) a=inli() n=a[0] m=a[1] if n-m==1 or m-n==1 : if nfirst() ; var m : OclAny := a[1+1] ; if n - m = 1 or m - n = 1 then ( if (n->compareTo(m)) < 0 then ( var tmp : long := MathLib.factorial(n) ; execute ((tmp * tmp * m) mod 1000000007)->display() ) else ( tmp := MathLib.factorial(m) ; execute ((tmp * tmp * n) mod 1000000007)->display() ) ) else (if n = m then ( tmp := MathLib.factorial(m) ; execute ((tmp * tmp * 2) mod 1000000007)->display() ) else ( execute (0)->display() ) ) ; operation ini() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inli() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation Math_PINFINITY() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation inlf() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["double"])->apply(_x) )); operation inl() : OclAny pre: true post: true activity: return ((OclFile["System.in"]).readLine())->characters(); operation pli() : OclAny pre: true post: true activity: return StringLib.sumStringsWithSeparator((((ans)->collect( _x | (OclType["String"])->apply(_x) ))), ""); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def factorial_mod(x : int)->int : MOD=10**9+7 ret=1 for i in range(1,x+1): ret=(ret*i)% MOD return ret def main(): n,m=list(map(int,input().rstrip().split())) MOD=10**9+7 n,m=min(n,m),max(n,m) dif=m-n if dif>1 : print(0) else : if dif==0 : ans=(factorial_mod(n)**2*2)% MOD else : ans=(factorial_mod(n)**2*m)% MOD print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation factorial_mod(x : int) : int pre: true post: true activity: var MOD : double := (10)->pow(9) + 7 ; var ret : int := 1 ; for i : Integer.subrange(1, x + 1-1) do ( ret := (ret * i) mod MOD) ; return ret; operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; MOD := (10)->pow(9) + 7 ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{Set{n, m}->min(),Set{n, m}->max()} ; var dif : double := m - n ; if dif > 1 then ( execute (0)->display() ) else ( if dif = 0 then ( var ans : int := ((factorial_mod(n))->pow(2) * 2) mod MOD ) else ( ans := ((factorial_mod(n))->pow(2) * m) mod MOD ) ; execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools from collections import Counter from collections import defaultdict import bisect import math import heapq def main(): N,M=map(int,input().split()) mod=10**9+7 if abs(N-M)>1 : print(0) exit() n=1 m=1 for i in range(1,N+1): n=(n*i)% mod for i in range(1,M+1): m=(m*i)% mod if N==M : print((n*m*2)% mod) else : print((n*m)% mod) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mod : double := (10)->pow(9) + 7 ; if (N - M)->abs() > 1 then ( execute (0)->display() ; exit() ) else skip ; var n : int := 1 ; var m : int := 1 ; for i : Integer.subrange(1, N + 1-1) do ( n := (n * i) mod mod) ; for i : Integer.subrange(1, M + 1-1) do ( m := (m * i) mod mod) ; if N = M then ( execute ((n * m * 2) mod mod)->display() ) else ( execute ((n * m) mod mod)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,Counter import math from bisect import bisect_left,bisect_right import numpy as np mod=1000000007 def mul(a,b): return((a % mod)*(b % mod))% mod n,m=map(int,input().split()) if n==m : a=math.factorial(n) print(mul(mul(a,a),2)) elif n==m-1 or n-1==m : if ncollect( _x | (OclType["int"])->apply(_x) ) ; if n = m then ( a := MathLib.factorial(n) ; execute (mul(mul(a, a), 2))->display() ) else (if n = m - 1 or n - 1 = m then ( if (n->compareTo(m)) < 0 then ( a := MathLib.factorial(n) ; b := a * m ) else ( a := MathLib.factorial(m) ; b := a * n ) ; execute (mul(a, b))->display() ) else ( execute (0)->display() ) ) ; operation mul(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return ((a mod mod) * (b mod mod)) mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=list(map(int,input().split())) m=int(input()) a=list(map(int,input().split())) for v in a : if x[v-1]+1 in x or x[v-1]==2019 : x[v-1]=x[v-1] else : x[v-1]+=1 for i in range(n): print(x[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for v : a do ( if (x)->includes(x[v - 1+1] + 1) or x[v - 1+1] = 2019 then ( x[v - 1+1] := x[v - 1+1] ) else ( x[v - 1+1] := x[v - 1+1] + 1 )) ; for i : Integer.subrange(0, n-1) do ( execute (x[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) X=[int(x)for x in input().split()] M=int(input()) A=[int(x)for x in input().split()] peace={x : 0 for x in range(1,N+1)} square={x : 0 for x in range(1,2020)} for i in range(N): peace[i+1]=X[i] square[X[i]]=i+1 for i in range(M): if peace[A[i]]<2019 and square[peace[A[i]]+1]==0 : square[peace[A[i]]+1]=A[i] square[peace[A[i]]]=0 peace[A[i]]+=1 for i in range(1,N+1): print(peace[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var X : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var M : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var peace : Map := Integer.subrange(1, N + 1-1)->select(x | true)->collect(x | Map{x |-> 0})->unionAll() ; var square : Map := Integer.subrange(1, 2020-1)->select(x | true)->collect(x | Map{x |-> 0})->unionAll() ; for i : Integer.subrange(0, N-1) do ( peace[i + 1+1] := X[i+1] ; square[X[i+1]+1] := i + 1) ; for i : Integer.subrange(0, M-1) do ( if peace[A[i+1]+1] < 2019 & square[peace[A[i+1]+1] + 1+1] = 0 then ( square[peace[A[i+1]+1] + 1+1] := A[i+1] ; square[peace[A[i+1]+1]+1] := 0 ; peace[A[i+1]+1] := peace[A[i+1]+1] + 1 ) else skip) ; for i : Integer.subrange(1, N + 1-1) do ( execute (peace[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def keisan(a,b): if a>2019 : return True i=0 while itoInteger() ; var koma : OclAny := input().rstrip().split() ; var komaI : Sequence := koma->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; var idou_kazu : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var idou : OclAny := input().rstrip().split() ; var idouI : Sequence := idou->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; i := 0 ; while (i->compareTo(idou_kazu)) < 0 do ( if keisan(komaI[idouI[i+1] - 1+1] + 1, komaI) = false then ( komaI[idouI[i+1] - 1+1] := komaI[idouI[i+1] - 1+1] + 1 ) else skip ; i := i + 1) ; i := 0 ; while (i->compareTo(koma_kazu)) < 0 do ( execute (komaI[i+1])->display() ; i := i + 1); operation keisan(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a > 2019 then ( return true ) else skip ; var i : int := 0 ; while (i->compareTo((b)->size())) < 0 do ( if b[i+1] = a then ( return true ) else skip ; i := i + 1) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys class Piece : def __init__(self,pos): self.pos=pos def main(args): _=input() board=[None]*2020 pieces=[Piece(0)] for p in map(int,input().split()): x=Piece(p) board[p]=x pieces.append(x) _=input() for p in map(int,input().split()): if pieces[p].pos==2019 or board[pieces[p].pos+1]!=None : continue pos=pieces[p].pos pieces[p].pos+=1 board[pos]=None board[pos+1]=pieces[p] for p in pieces[1 :]: print(p.pos) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class Piece { static operation newPiece() : Piece pre: true post: Piece->exists( _x | result = _x ); attribute pos : OclAny := pos; operation initialise(pos : OclAny) : Piece pre: true post: true activity: self.pos := pos; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation main(args : OclAny) pre: true post: true activity: var _anon : String := (OclFile["System.in"]).readLine() ; var board : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, 2020) ; var pieces : Sequence := Sequence{ (Piece.newPiece()).initialise(0) } ; for p : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( var x : Piece := (Piece.newPiece()).initialise(p) ; board[p+1] := x ; execute ((x) : pieces)) ; _anon := (OclFile["System.in"]).readLine() ; for p : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( if pieces[p+1].pos = 2019 or board[pieces[p+1].pos + 1+1] /= null then ( continue ) else skip ; pos := pieces[p+1].pos ; pieces[p+1].pos := pieces[p+1].pos + 1 ; board[pos+1] := null ; board[pos + 1+1] := pieces[p+1]) ; for p : pieces->tail() do ( execute (p.pos)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) d={i+1 : v for i,v in enumerate(list(map(int,input().split())))} m=int(input()) a=list(map(int,input().split())) for i in a : if d[i]+1 not in d.values()and d[i]!=2019 : d[i]+=1 print(*d.values(),sep="\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Map := Integer.subrange(1, (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->size())->collect( _indx | Sequence{_indx-1, (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->at(_indx)} )->select(_tuple | true)->collect(_tuple | Map{i + 1 |-> v})->unionAll() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : a do ( if (d.values())->excludes(d[i+1] + 1) & d[i+1] /= 2019 then ( d[i+1] := d[i+1] + 1 ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name d)) (trailer . (name values) (arguments ( )))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculate_product(number=10): multiplier = 100 result_value = number print(f"Multiplying {result_value} by {multiplier}.") return multiplier * result_value ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; operation calculate_product(number : int) : OclAny pre: true post: true activity: if number->oclIsUndefined() then number := 10 else skip; var multiplier : int := 100 ; var result_value : int := number ; execute (StringLib.formattedString("Multiplying {result_value} by {multiplier}."))->display() ; return multiplier * result_value; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculate_rectangle_area(length=5.5, width=3.2): print(f"Computing area: Length = {length}, Width = {width}") area = length * width return f"The calculated area is {area} square units." ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; operation calculate_rectangle_area(length : double, width : double) : OclAny pre: true post: true activity: if length->oclIsUndefined() then length := 5.5 else skip; if width->oclIsUndefined() then width := 3.2 else skip; execute (StringLib.formattedString("Computing area: Length = {length}, Width = {width}"))->display() ; var area : double := length * width ; return StringLib.formattedString("The calculated area is {area} square units."); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def full_name(first_name="John", last_name="Doe"): greeting = f"Hello, {first_name} {last_name}! Welcome aboard." return greeting ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; operation full_name(first_name : String, last_name : String) : OclAny pre: true post: true activity: if first_name->oclIsUndefined() then first_name := "John" else skip; if last_name->oclIsUndefined() then last_name := "Doe" else skip; var greeting : String := StringLib.formattedString("Hello, {first_name} {last_name}! Welcome aboard.") ; return greeting; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check_eligibility(age_check=True, has_license=False): print("Evaluating eligibility criteria...") if age_check and has_license: return "Congratulations! You meet all the requirements." return "Unfortunately, you do not meet the necessary conditions." ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; operation check_eligibility(age_check : OclAny, has_license : OclAny) : OclAny pre: true post: true activity: if age_check->oclIsUndefined() then age_check := true else skip; if has_license->oclIsUndefined() then has_license := false else skip; execute ("Evaluating eligibility criteria...")->display() ; if age_check & has_license then ( return "Congratulations! You meet all the requirements." ) else skip ; return "Unfortunately, you do not meet the necessary conditions."; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculate_final_price(price=100, discount=0.2, tax=0.1): discounted_price = price - (price * discount) final_price = discounted_price + (discounted_price * tax) return f"Original price: ${price}, Final price after discount and tax: ${final_price:.2f}" ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; operation calculate_final_price(price : int, discount : double, tax : double) : OclAny pre: true post: true activity: if price->oclIsUndefined() then price := 100 else skip; if discount->oclIsUndefined() then discount := 0.2 else skip; if tax->oclIsUndefined() then tax := 0.1 else skip; var discounted_price : double := price - (price * discount) ; var final_price : OclAny := discounted_price + (discounted_price * tax) ; return StringLib.formattedString("Original price: ${price}, Final price after discount and tax: ${final_price:.2f}"); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check_student_pass(score1=50, score2=50, score3=50): average = (score1 + score2 + score3) / 3 if average >= 50: return f"Average Score: {average:.2f}. The student has passed." return f"Average Score: {average:.2f}. The student has failed." ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; operation check_student_pass(score1 : int, score2 : int, score3 : int) : OclAny pre: true post: true activity: if score1->oclIsUndefined() then score1 := 50 else skip; if score2->oclIsUndefined() then score2 := 50 else skip; if score3->oclIsUndefined() then score3 := 50 else skip; var average : double := (score1 + score2 + score3) / 3 ; if average >= 50 then ( return StringLib.formattedString("Average Score: {average:.2f}. The student has passed.") ) else skip ; return StringLib.formattedString("Average Score: {average:.2f}. The student has failed."); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- greeting_text = "good morning" capitalized_greeting = greeting_text.capitalize() modified_greeting = greeting_text.replace(" ", "_") print(capitalized_greeting) print(modified_greeting) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var greeting_text : String := "good morning" ; var capitalized_greeting : String := StringLib.capitalise(greeting_text) ; var modified_greeting : String := greeting_text.replace(" ", "_") ; execute (capitalized_greeting)->display() ; execute (modified_greeting)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- user_input = "hello user" capitalized_input = user_input.capitalize() formatted_input = user_input.replace(" ", "-") print(capitalized_input) print(formatted_input) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var user_input : String := "hello user" ; var capitalized_input : String := StringLib.capitalise(user_input) ; var formatted_input : String := user_input.replace(" ", "-") ; execute (capitalized_input)->display() ; execute (formatted_input)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sentence = "this is a test" capitalized_sentence = sentence.capitalize() underscore_sentence = sentence.replace(" ", "_") print(capitalized_sentence) print(underscore_sentence) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sentence : String := "this is a test" ; var capitalized_sentence : String := StringLib.capitalise(sentence) ; var underscore_sentence : String := sentence.replace(" ", "_") ; execute (capitalized_sentence)->display() ; execute (underscore_sentence)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- quote = "the early bird catches the worm" capitalized_quote = quote.capitalize() hyphenated_quote = quote.replace(" ", "-") print(capitalized_quote) print(hyphenated_quote) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var quote : String := "the early bird catches the worm" ; var capitalized_quote : String := StringLib.capitalise(quote) ; var hyphenated_quote : String := quote.replace(" ", "-") ; execute (capitalized_quote)->display() ; execute (hyphenated_quote)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- name = "john doe" capitalized_name = name.capitalize() name_with_asterisks = name.replace(" ", "*") print(capitalized_name) print(name_with_asterisks) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var name : String := "john doe" ; var capitalized_name : String := StringLib.capitalise(name) ; var name_with_asterisks : String := name.replace(" ", "*") ; execute (capitalized_name)->display() ; execute (name_with_asterisks)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def square_number(num=5): print(f"Squaring the number {num}.") return num ** 2 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; operation square_number(num : int) : OclAny pre: true post: true activity: if num->oclIsUndefined() then num := 5 else skip; execute (StringLib.formattedString("Squaring the number {num}."))->display() ; return (num)->pow(2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- message = "welcome to python" capitalized_message = message.capitalize() message_with_dashes = message.replace(" ", "--") print(capitalized_message) print(message_with_dashes) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var message : String := "welcome to python" ; var capitalized_message : String := StringLib.capitalise(message) ; var message_with_dashes : String := message.replace(" ", "--") ; execute (capitalized_message)->display() ; execute (message_with_dashes)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- city = "new york" capitalized_city = city.capitalize() city_with_periods = city.replace(" ", ".") print(capitalized_city) print(city_with_periods) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var city : String := "new york" ; var capitalized_city : String := StringLib.capitalise(city) ; var city_with_periods : String := city.replace(" ", ".") ; execute (capitalized_city)->display() ; execute (city_with_periods)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- title = "learning python programming" capitalized_title = title.capitalize() title_with_plus = title.replace(" ", "+") print(capitalized_title) print(title_with_plus) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var title : String := "learning python programming" ; var capitalized_title : String := StringLib.capitalise(title) ; var title_with_plus : String := title.replace(" ", "+") ; execute (capitalized_title)->display() ; execute (title_with_plus)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import pandas as pd student_data = pd.read_csv("Data/Students.csv") score_column = student_data["Score"] highest_score = score_column.max() print(f"The highest score among the students is {highest_score}.") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var student_data : Map := OclFile.newOclFile_Read(OclFile.newOclFile(("Data/Students.csv"))).readMap() ; var score_column : OclAny := student_data->at("Score") ; var highest_score : double := score_column->max() ; execute (StringLib.formattedString("The highest score among the students is {highest_score}."))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import pandas as pd employee_info = pd.read_csv("Data/EmployeeData.csv") salary_column = employee_info["Salary"] total_salary = salary_column.sum() print(f"The total salary expenditure across all employees is {total_salary}.") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var employee_info : Map := OclFile.newOclFile_Read(OclFile.newOclFile(("Data/EmployeeData.csv"))).readMap() ; var salary_column : OclAny := employee_info->at("Salary") ; var total_salary : OclAny := salary_column.sum() ; execute (StringLib.formattedString("The total salary expenditure across all employees is {total_salary}."))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import pandas as pd sales_data = pd.read_csv("Data/Sales.csv") revenue_column = sales_data["Revenue"] average_revenue = revenue_column.mean() print(f"Each sale on average generates a revenue of ${average_revenue:.2f}.") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var sales_data : Map := OclFile.newOclFile_Read(OclFile.newOclFile(("Data/Sales.csv"))).readMap() ; var revenue_column : OclAny := sales_data->at("Revenue") ; var average_revenue : double := MathLib.mean(revenue_column) ; execute (StringLib.formattedString("Each sale on average generates a revenue of ${average_revenue:.2f}."))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import pandas as pd exam_results = pd.read_csv("Data/ExamResults.csv") marks_column = exam_results["Marks"] pass_percentage = (marks_column > 50).sum() / len(marks_column) * 100 print(f"{pass_percentage:.2f}% of students have passed the exam.") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var exam_results : Map := OclFile.newOclFile_Read(OclFile.newOclFile(("Data/ExamResults.csv"))).readMap() ; var marks_column : OclAny := exam_results->at("Marks") ; var pass_percentage : double := (marks_column > 50).sum() / (marks_column)->size() * 100 ; execute (StringLib.formattedString("{pass_percentage:.2f}% of students have passed the exam."))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import pandas as pd product_data = pd.read_csv("Data/Products.csv") price_column = product_data["Price"] max_price = price_column.max() print(f"The most expensive product in the catalog is priced at ${max_price}.") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var product_data : Map := OclFile.newOclFile_Read(OclFile.newOclFile(("Data/Products.csv"))).readMap() ; var price_column : OclAny := product_data->at("Price") ; var max_price : double := price_column->max() ; execute (StringLib.formattedString("The most expensive product in the catalog is priced at ${max_price}."))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import pandas as pd customer_data = pd.read_csv("Data/Customers.csv") age_column = customer_data["Age"] oldest_customer = age_column.max() print(f"The oldest customer in the dataset is {oldest_customer} years old.") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var customer_data : Map := OclFile.newOclFile_Read(OclFile.newOclFile(("Data/Customers.csv"))).readMap() ; var age_column : OclAny := customer_data->at("Age") ; var oldest_customer : double := age_column->max() ; execute (StringLib.formattedString("The oldest customer in the dataset is {oldest_customer} years old."))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import pandas as pd movie_data = pd.read_csv("Data/Movies.csv") rating_column = movie_data["Rating"] best_rated_movie = rating_column.max() print(f"The best-rated movie has a rating of {best_rated_movie}.") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var movie_data : Map := OclFile.newOclFile_Read(OclFile.newOclFile(("Data/Movies.csv"))).readMap() ; var rating_column : OclAny := movie_data->at("Rating") ; var best_rated_movie : double := rating_column->max() ; execute (StringLib.formattedString("The best-rated movie has a rating of {best_rated_movie}."))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def convert_to_celsius(fahrenheit=98.6): print(f"Converting {fahrenheit}°F to Celsius.") return (fahrenheit - 32) * 5 / 9 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; operation convert_to_celsius(fahrenheit : double) : OclAny pre: true post: true activity: if fahrenheit->oclIsUndefined() then fahrenheit := 98.6 else skip; execute (StringLib.formattedString("Converting {fahrenheit}�F to Celsius."))->display() ; return (fahrenheit - 32) * 5 / 9; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import pandas as pd weather_data = pd.read_csv("Data/Weather.csv") temperature_column = weather_data["Temperature"] average_temperature = temperature_column.mean() print(f"The average temperature recorded over the week is {average_temperature}°C.") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var weather_data : Map := OclFile.newOclFile_Read(OclFile.newOclFile(("Data/Weather.csv"))).readMap() ; var temperature_column : OclAny := weather_data->at("Temperature") ; var average_temperature : double := MathLib.mean(temperature_column) ; execute (StringLib.formattedString("The average temperature recorded over the week is {average_temperature}�C."))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculate_area(radius=3.14): print(f"Calculating the area of a circle with radius {radius}.") return 3.14159 * radius * radius ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; operation calculate_area(radius : double) : OclAny pre: true post: true activity: if radius->oclIsUndefined() then radius := 3.14 else skip; execute (StringLib.formattedString("Calculating the area of a circle with radius {radius}."))->display() ; return 3.14159 * radius * radius; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def greet_user(name="John"): print(f"Greeting the user: {name}.") return f"Hello, {name}!" ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; operation greet_user(name : String) : OclAny pre: true post: true activity: if name->oclIsUndefined() then name := "John" else skip; execute (StringLib.formattedString("Greeting the user: {name}."))->display() ; return StringLib.formattedString("Hello, {name}!"); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def repeat_message(message="Welcome!"): print(f"Repeating the message: {message}.") return message * 3 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; operation repeat_message(message : String) : OclAny pre: true post: true activity: if message->oclIsUndefined() then message := "Welcome!" else skip; execute (StringLib.formattedString("Repeating the message: {message}."))->display() ; return StringLib.nCopies(message, 3); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def is_adult(age_check=True): if age_check: print("User is considered an adult.") return "You are an adult" else: print("User is considered not an adult.") return "You are not an adult" ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; operation is_adult(age_check : OclAny) : OclAny pre: true post: true activity: if age_check->oclIsUndefined() then age_check := true else skip; if age_check then ( execute ("User is considered an adult.")->display() ; return "You are an adult" ) else ( execute ("User is considered not an adult.")->display() ; return "You are not an adult" ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def add_element(numbers=[1, 2, 3]): print(f"Adding an element to the list: {numbers}.") numbers.append(4) return numbers ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; operation add_element(numbers : OclAny) : OclAny pre: true post: true activity: if numbers->oclIsUndefined() then numbers := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) else skip; execute (StringLib.formattedString("Adding an element to the list: {numbers}."))->display() ; execute ((4) : numbers) ; return numbers; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def add_numbers(num1=5, num2=10): total = num1 + num2 message = f"The sum of {num1} and {num2} is {total}." return message ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; operation add_numbers(num1 : int, num2 : int) : OclAny pre: true post: true activity: if num1->oclIsUndefined() then num1 := 5 else skip; if num2->oclIsUndefined() then num2 := 10 else skip; var total : int := num1 + num2 ; var message : String := StringLib.formattedString("The sum of {num1} and {num2} is {total}.") ; return message; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from enum import Enum def minSum(A) : min_val = min(A) return min_val*(len(A) - 1) class jZryE: def __init__(self): pass tst = [3,2,8] print(minSum(tst)) ------------------------------------------------------------ OCL File: --------- class jZryE { static operation newjZryE() : jZryE pre: true post: jZryE->exists( _x | result = _x ); operation initialise() : jZryE pre: true post: true activity: skip; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var tst : Sequence := Sequence{3}->union(Sequence{2}->union(Sequence{ 8 })) ; execute (minSum(tst))->display(); operation minSum(A : OclAny) : OclAny pre: true post: true activity: var min_val : OclAny := (A)->min() ; return min_val * ((A)->size() - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import ocl import math def M294(N): return math.ceil(math.log2(N + 1)) - 1 def M295(n): return n * (2 * n - 1) def M296(m, x, revenue, n, t): maxRev = [0] * (m + 1) nxtbb = 0 for i in range(1, m + 1): if nxtbb < n: if x[nxtbb] != i: maxRev[i] = maxRev[i - 1] else: if i <= t: maxRev[i] = max(maxRev[i - 1], revenue[nxtbb]) else: maxRev[i] = max(maxRev[i - t - 1] + revenue[nxtbb], maxRev[i - 1]) nxtbb += 1 else: maxRev[i] = maxRev[i - 1] return maxRev[m] class WWmaggJDvjEI : def __init__(self): self.mMj = 437 self.qyJgcUz = 191 self.yFsPnret = None def M297(poly, n, x): result = poly[0] for i in range(1, n): result = result * x + poly[i] return result def M298(n): sum = 0 while(n != 0): sum = sum + int(n % 10) n = int(n / 10) return sum def M299(n): sum = 0 while(n > 0): sum += int(n % 10) n = int(n / 10) return sum class FCvpYJQ : def __init__(self): self.daWp = 202 self.BKLrOJh = set({}) self.kttGEzJoyi = None def M302(arr,i,n): if i>int((n-2)/2): return True if (arr[i]>=arr[2*i+1] and arr[i]>=arr[2*i+2] and M302(arr,2*i+1,n) and M302(arr,2*i+2,n)): return True return False class fzpmRRkPHSByt(FCvpYJQ) : def __init__(self): self.qXiUYtD = set({}) self.ZOHxIhgbc = 324 self.RxH = set({}) self.nRQ = None class qyBl : def __init__(self): self.fmC = set({}) self.pXAFKQwvRuA = "" self.ZKVqxDAKgbu = [] self.GTdk = True self.CRzPRHfupYp = False self.zTVwurUdT = 993 self.udxBvgV = set({}) self.nRpXjuP = None class GkzqCBE : def __init__(self): self.XCmfja = set({}) self.fjsEX = 30 self.ReofrPGPE = 355 self.Ogn = [] self.NdQJeEyD = 366 self.tJCampqutF = "" self.SBc = False self.AZKPutp = None self.iKbyAMVE = None class aXBImTmNOKyTk : def __init__(self): self.yJlnpuOQKy = set({}) self.usBjsizOpvu = set({}) self.BSlLkb = 546.191 self.uXGnatvu = set({}) self.PQW = "b" self.VARTho = set({}) self.FeXy = 347 self.FUB = None class cJZPvVIvAY : def __init__(self): self.IiN = "" self.qodi = "gHRZGMQH" self.qYWQg = 573 self.IraMEKft = 125 self.ZKwa = 796 self.jHroDG = set({}) self.xJEoQMEsK = None class HaRqFErJaUNdb(cJZPvVIvAY) : def __init__(self): self.BIsbnCGZ = True self.aUrGMfO = 289.893 self.peAF = False self.hjRkR = [] class QEfqBqLC(cJZPvVIvAY) : def __init__(self): self.bFR = True self.zraocYq = 334.955 self.bnX = True self.BnIlvvTeU = True self.zgFqChaej = set({}) self.zmWbxxyNu = None self.QxSurF = None def M300(no): return 0 if no == 0 else int(no % 10) + M300(int(no / 10)) class ybqKk(cJZPvVIvAY) : def __init__(self): self.HORobOaOlh = "ifXVCPhsO" self.HKzFnnyIv = 531 self.ygR = 188 self.qtTYYEqB = True def M301(a,b,mod): res=0; a=a%mod; while(b>0): if(b%2==1): res=(res+a)%mod; a=(a*2)%mod; b//=2; return res%mod; ------------------------------------------------------------ OCL File: --------- class WWmaggJDvjEI { static operation newWWmaggJDvjEI() : WWmaggJDvjEI pre: true post: WWmaggJDvjEI->exists( _x | result = _x ); attribute mMj : int := 437; attribute qyJgcUz : int := 191; attribute yFsPnret : OclAny := null; operation initialise() : WWmaggJDvjEI pre: true post: true activity: self.mMj := 437 ; self.qyJgcUz := 191 ; self.yFsPnret := null; return self; operation M297(poly : OclAny , n : OclAny,x : OclAny) : OclAny pre: true post: true activity: var result : OclAny := poly->first() ; for i : Integer.subrange(1, n-1) do ( result := result * x + poly[i+1]) ; return result; operation M298((def_parameters (def_parameter (named_parameter (name n))))) : OclAny pre: true post: true activity: var sum : int := 0 ; while (n /= 0) do ( sum := sum + ("" + ((n mod 10)))->toInteger() ; n := ("" + ((n / 10)))->toInteger()) ; return sum; operation M299((def_parameters (def_parameter (named_parameter (name n))))) : OclAny pre: true post: true activity: sum := 0 ; while (n > 0) do ( sum := sum + ("" + ((n mod 10)))->toInteger() ; n := ("" + ((n / 10)))->toInteger()) ; return sum; } class FCvpYJQ { static operation newFCvpYJQ() : FCvpYJQ pre: true post: FCvpYJQ->exists( _x | result = _x ); attribute daWp : int := 202; attribute BKLrOJh : Set := Set{}->union((Set{})); attribute kttGEzJoyi : OclAny := null; operation initialise() : FCvpYJQ pre: true post: true activity: self.daWp := 202 ; self.BKLrOJh := Set{}->union((Set{})) ; self.kttGEzJoyi := null; return self; operation M302(arr : OclAny , i : OclAny,n : OclAny) : OclAny pre: true post: true activity: if (i->compareTo(("" + (((n - 2) / 2)))->toInteger())) > 0 then ( return true ) else skip ; if ((arr[i+1]->compareTo(arr[2 * i + 1+1])) >= 0 & (arr[i+1]->compareTo(arr[2 * i + 2+1])) >= 0 & M302(arr, 2 * i + 1, n) & M302(arr, 2 * i + 2, n)) then ( return true ) else skip ; return false; } class fzpmRRkPHSByt extends FCvpYJQ { static operation newfzpmRRkPHSByt() : fzpmRRkPHSByt pre: true post: fzpmRRkPHSByt->exists( _x | result = _x ); attribute qXiUYtD : Set := Set{}->union((Set{})); attribute ZOHxIhgbc : int := 324; attribute RxH : Set := Set{}->union((Set{})); attribute nRQ : OclAny := null; operation initialise() : FCvpYJQ pre: true post: true activity: self.qXiUYtD := Set{}->union((Set{})) ; self.ZOHxIhgbc := 324 ; self.RxH := Set{}->union((Set{})) ; self.nRQ := null; return self; } class qyBl { static operation newqyBl() : qyBl pre: true post: qyBl->exists( _x | result = _x ); attribute fmC : Set := Set{}->union((Set{})); attribute pXAFKQwvRuA : String := ""; attribute ZKVqxDAKgbu : Sequence := Sequence{}; attribute GTdk : boolean := true; attribute CRzPRHfupYp : boolean := false; attribute zTVwurUdT : int := 993; attribute udxBvgV : Set := Set{}->union((Set{})); attribute nRpXjuP : OclAny := null; operation initialise() : qyBl pre: true post: true activity: self.fmC := Set{}->union((Set{})) ; self.pXAFKQwvRuA := "" ; self.ZKVqxDAKgbu := Sequence{} ; self.GTdk := true ; self.CRzPRHfupYp := false ; self.zTVwurUdT := 993 ; self.udxBvgV := Set{}->union((Set{})) ; self.nRpXjuP := null; return self; } class GkzqCBE { static operation newGkzqCBE() : GkzqCBE pre: true post: GkzqCBE->exists( _x | result = _x ); attribute XCmfja : Set := Set{}->union((Set{})); attribute fjsEX : int := 30; attribute ReofrPGPE : int := 355; attribute Ogn : Sequence := Sequence{}; attribute NdQJeEyD : int := 366; attribute tJCampqutF : String := ""; attribute SBc : boolean := false; attribute AZKPutp : OclAny := null; attribute iKbyAMVE : OclAny := null; operation initialise() : GkzqCBE pre: true post: true activity: self.XCmfja := Set{}->union((Set{})) ; self.fjsEX := 30 ; self.ReofrPGPE := 355 ; self.Ogn := Sequence{} ; self.NdQJeEyD := 366 ; self.tJCampqutF := "" ; self.SBc := false ; self.AZKPutp := null ; self.iKbyAMVE := null; return self; } class aXBImTmNOKyTk { static operation newaXBImTmNOKyTk() : aXBImTmNOKyTk pre: true post: aXBImTmNOKyTk->exists( _x | result = _x ); attribute yJlnpuOQKy : Set := Set{}->union((Set{})); attribute usBjsizOpvu : Set := Set{}->union((Set{})); attribute BSlLkb : double := 546.191; attribute uXGnatvu : Set := Set{}->union((Set{})); attribute PQW : String := "b"; attribute VARTho : Set := Set{}->union((Set{})); attribute FeXy : int := 347; attribute FUB : OclAny := null; operation initialise() : aXBImTmNOKyTk pre: true post: true activity: self.yJlnpuOQKy := Set{}->union((Set{})) ; self.usBjsizOpvu := Set{}->union((Set{})) ; self.BSlLkb := 546.191 ; self.uXGnatvu := Set{}->union((Set{})) ; self.PQW := "b" ; self.VARTho := Set{}->union((Set{})) ; self.FeXy := 347 ; self.FUB := null; return self; } class cJZPvVIvAY { static operation newcJZPvVIvAY() : cJZPvVIvAY pre: true post: cJZPvVIvAY->exists( _x | result = _x ); attribute IiN : String := ""; attribute qodi : String := "gHRZGMQH"; attribute qYWQg : int := 573; attribute IraMEKft : int := 125; attribute ZKwa : int := 796; attribute jHroDG : Set := Set{}->union((Set{})); attribute xJEoQMEsK : OclAny := null; operation initialise() : cJZPvVIvAY pre: true post: true activity: self.IiN := "" ; self.qodi := "gHRZGMQH" ; self.qYWQg := 573 ; self.IraMEKft := 125 ; self.ZKwa := 796 ; self.jHroDG := Set{}->union((Set{})) ; self.xJEoQMEsK := null; return self; } class HaRqFErJaUNdb extends cJZPvVIvAY { static operation newHaRqFErJaUNdb() : HaRqFErJaUNdb pre: true post: HaRqFErJaUNdb->exists( _x | result = _x ); attribute BIsbnCGZ : boolean := true; attribute aUrGMfO : double := 289.893; attribute peAF : boolean := false; attribute hjRkR : Sequence := Sequence{}; operation initialise() : cJZPvVIvAY pre: true post: true activity: self.BIsbnCGZ := true ; self.aUrGMfO := 289.893 ; self.peAF := false ; self.hjRkR := Sequence{}; return self; } class QEfqBqLC extends cJZPvVIvAY { static operation newQEfqBqLC() : QEfqBqLC pre: true post: QEfqBqLC->exists( _x | result = _x ); attribute bFR : boolean := true; attribute zraocYq : double := 334.955; attribute bnX : boolean := true; attribute BnIlvvTeU : boolean := true; attribute zgFqChaej : Set := Set{}->union((Set{})); attribute zmWbxxyNu : OclAny := null; attribute QxSurF : OclAny := null; operation initialise() : cJZPvVIvAY pre: true post: true activity: self.bFR := true ; self.zraocYq := 334.955 ; self.bnX := true ; self.BnIlvvTeU := true ; self.zgFqChaej := Set{}->union((Set{})) ; self.zmWbxxyNu := null ; self.QxSurF := null; return self; operation M300((def_parameters (def_parameter (named_parameter (name no))))) : OclAny pre: true post: true activity: return if no = 0 then 0 else ("" + ((no mod 10)))->toInteger() + M300(("" + ((no / 10)))->toInteger()) endif; } class ybqKk extends cJZPvVIvAY { static operation newybqKk() : ybqKk pre: true post: ybqKk->exists( _x | result = _x ); attribute HORobOaOlh : String := "ifXVCPhsO"; attribute HKzFnnyIv : int := 531; attribute ygR : int := 188; attribute qtTYYEqB : boolean := true; operation initialise() : cJZPvVIvAY pre: true post: true activity: self.HORobOaOlh := "ifXVCPhsO" ; self.HKzFnnyIv := 531 ; self.ygR := 188 ; self.qtTYYEqB := true; return self; operation M301(a : OclAny , b : OclAny,mod : OclAny) pre: true post: true activity: var res : int := 0; ; a := a mod mod; ; while (b > 0) do ( if (b mod 2 = 1) then ( res := (res + a) mod mod; ) else skip ; a := (a * 2) mod mod; ; b := b div 2;) ; return res mod mod;; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip; operation M294(N : OclAny) : OclAny pre: true post: true activity: return ()->ceil() - 1; operation M295(n : OclAny) : OclAny pre: true post: true activity: return n * (2 * n - 1); operation M296(m : OclAny, x : OclAny, revenue : OclAny, n : OclAny, t : OclAny) : OclAny pre: true post: true activity: var maxRev : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (m + 1)) ; var nxtbb : int := 0 ; for i : Integer.subrange(1, m + 1-1) do ( if (nxtbb->compareTo(n)) < 0 then ( if x[nxtbb+1] /= i then ( maxRev[i+1] := maxRev[i - 1+1] ) else ( if (i->compareTo(t)) <= 0 then ( maxRev[i+1] := Set{maxRev[i - 1+1], revenue[nxtbb+1]}->max() ) else ( maxRev[i+1] := Set{maxRev[i - t - 1+1] + revenue[nxtbb+1], maxRev[i - 1+1]}->max() ) ; nxtbb := nxtbb + 1 ) ) else ( maxRev[i+1] := maxRev[i - 1+1] )) ; return maxRev[m+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import ocl def M367(base): base=(base-2) base=base/2 return base*(base+1)/2 class FwOOZgqtMn : def __init__(self): self.HkxUQGmOk = 803 self.WeEcgT = 637 self.KbzrBWpuJA = set({}) self.EUBj = 755 self.ReUbxT = 475 self.SJZ = None self.WLHV = None self.ucsG = None self.DmVwDrQr = None def M368(str): n=len(str) res=-1 for i in range(0,n-1): for j in range(i+1,n): if(str[i]==str[j]): res=max(res,abs(j-i-1)) return res def M369(arr,n,k): um,curr_rem,maxSum={},0,0 sm=[0]*n sm[0]=arr[0] for i in range(1,n): sm[i]=sm[i-1]+arr[i] for i in range(n): curr_rem=sm[i]%k if(not curr_rem and maxSum 0: SubsetSum_1 += arr[i] else: SubsetSum_2 += arr[i] return abs(SubsetSum_1 - SubsetSum_2) class zskNzYEVNqUkm : def __init__(self): self.ejtZIdV = 668.574 self.nNm = "" self.jqMdANNdwY = set({}) self.aVpRGzqmpAX = "bXZL" self.dfeHGMwKL = 142.814 class rGghWIdoqS : def __init__(self): self.CqMvDK = 980.122 self.XtfiVJFxD = True self.paXSv = None class Atm : def __init__(self): self.zPE = 980 self.DompTp = 237 self.STrhkZppqgr = 714 self.sYpM = 192 self.vyele = set({}) self.bvzfOH = None def gfgff(arr,n): mls=[] max=0 for i in range(n): mls.append(1) for i in range(n): for j in range(i): if(abs(arr[i]-arr[j])<=1 and mls[i]exists( _x | result = _x ); attribute HkxUQGmOk : int := 803; attribute WeEcgT : int := 637; attribute KbzrBWpuJA : Set := Set{}->union((Set{})); attribute EUBj : int := 755; attribute ReUbxT : int := 475; attribute SJZ : OclAny := null; attribute WLHV : OclAny := null; attribute ucsG : OclAny := null; attribute DmVwDrQr : OclAny := null; operation initialise() : FwOOZgqtMn pre: true post: true activity: self.HkxUQGmOk := 803 ; self.WeEcgT := 637 ; self.KbzrBWpuJA := Set{}->union((Set{})) ; self.EUBj := 755 ; self.ReUbxT := 475 ; self.SJZ := null ; self.WLHV := null ; self.ucsG := null ; self.DmVwDrQr := null; return self; operation M368((def_parameters (def_parameter (named_parameter (name str))))) : OclAny pre: true post: true activity: var n : int := (OclType["String"])->size() ; var res : int := -1 ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if (("" + ([i+1])) = ("" + ([j+1]))) then ( res := Set{res, (j - i - 1)->abs()}->max() ) else skip)) ; return res; operation M369(arr : OclAny , n : OclAny,k : OclAny) : OclAny pre: true post: true activity: var um : OclAny := null; var curr_rem : OclAny := null; var maxSum : OclAny := null; Sequence{um,curr_rem,maxSum} := Sequence{Set{},0,0} ; var sm : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; sm->first() := arr->first() ; for i : Integer.subrange(1, n-1) do ( sm[i+1] := sm[i - 1+1] + arr[i+1]) ; for i : Integer.subrange(0, n-1) do ( var curr_rem : int := sm[i+1] mod k ; if (not(curr_rem) & (maxSum->compareTo(sm[i+1])) < 0) then ( var maxSum : OclAny := sm[i+1] ) else (if (not((um)->includes(curr_rem))) then ( um[curr_rem+1] := i ) else (if ((maxSum->compareTo((sm[i+1] - sm[um[curr_rem+1]+1]))) < 0) then ( maxSum := sm[i+1] - sm[um[curr_rem+1]+1] ) else skip ) ) ) ; return maxSum div k; } class FtaK { static operation newFtaK() : FtaK pre: true post: FtaK->exists( _x | result = _x ); attribute aISdPGC : int := 895; attribute cWQ : String := ""; attribute UmAlaWtKme : double := 887.729; operation initialise() : FtaK pre: true post: true activity: self.aISdPGC := 895 ; self.cWQ := "" ; self.UmAlaWtKme := 887.729; return self; } class ggzBMkVzpef { static operation newggzBMkVzpef() : ggzBMkVzpef pre: true post: ggzBMkVzpef->exists( _x | result = _x ); attribute LsLTXGjEulz : int := 410; attribute zQPAVjdT : Set := Set{}->union((Set{})); attribute YcFROIQjcT : int := 686; attribute lJhcvr : int := 311; attribute vBUCoJ : int := 591; operation initialise() : ggzBMkVzpef pre: true post: true activity: self.LsLTXGjEulz := 410 ; self.zQPAVjdT := Set{}->union((Set{})) ; self.YcFROIQjcT := 686 ; self.lJhcvr := 311 ; self.vBUCoJ := 591; return self; operation M370(b : OclAny , m : OclAny) : OclAny pre: true post: true activity: return (b / m - 1) * (b / m) / 2; operation M371(n : OclAny , a : OclAny,b : OclAny,c : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (n + 10)) ; dp->first() := 0 ; for i : Integer.subrange(0, n-1) do ( if dp[i+1] /= -1 then ( if (i + a->compareTo(n)) <= 0 then ( dp[i + a+1] := Set{dp[i+1] + 1, dp[i + a+1]}->max() ) else skip ; if (i + b->compareTo(n)) <= 0 then ( dp[i + b+1] := Set{dp[i+1] + 1, dp[i + b+1]}->max() ) else skip ; if (i + c->compareTo(n)) <= 0 then ( dp[i + c+1] := Set{dp[i+1] + 1, dp[i + c+1]}->max() ) else skip ) else skip) ; return dp[n+1]; } class fCpNqjsBwu { static operation newfCpNqjsBwu() : fCpNqjsBwu pre: true post: fCpNqjsBwu->exists( _x | result = _x ); attribute oICCSjZm : Set := Set{}->union((Set{})); attribute wbOkUIO : int := 89; operation initialise() : fCpNqjsBwu pre: true post: true activity: self.oICCSjZm := Set{}->union((Set{})) ; self.wbOkUIO := 89; return self; } class nekKuYLVBE extends FwOOZgqtMn { static operation newnekKuYLVBE() : nekKuYLVBE pre: true post: nekKuYLVBE->exists( _x | result = _x ); attribute oDP : boolean := false; attribute rLAhdvd : String := "SMYPOsdSG"; attribute aXUEFEJ : String := ""; attribute LzIZmwD : String := "Guk"; attribute liIwNMMdDhX : Sequence := Sequence{}; attribute OYfKbIq : String := "lShnaxx"; attribute YalHh : OclAny := null; attribute yOsemI : OclAny := null; attribute ASl : int := 888; attribute nmK : int := 767; attribute EGHKfddatF : Set := Set{}->union((Set{})); attribute FovSiexGWQG : int := 827; attribute MEqPnTuVEz : int := 55; attribute RQeDinuq : OclAny := null; attribute KpsCKzyPOv : OclAny := null; attribute lIozisT : OclAny := null; attribute qiZ : OclAny := null; operation initialise() : fCpNqjsBwu pre: true post: true activity: self.oDP := false ; self.rLAhdvd := "SMYPOsdSG" ; self.aXUEFEJ := "" ; self.LzIZmwD := "Guk" ; self.liIwNMMdDhX := Sequence{} ; self.OYfKbIq := "lShnaxx" ; self.YalHh := null ; self.yOsemI := null ; self.ASl := 888 ; self.nmK := 767 ; self.EGHKfddatF := Set{}->union((Set{})) ; self.FovSiexGWQG := 827 ; self.MEqPnTuVEz := 55 ; self.RQeDinuq := null ; self.KpsCKzyPOv := null ; self.lIozisT := null ; self.qiZ := null; return self; operation M372((def_parameters (def_parameter (named_parameter (name n))))) pre: true post: true activity: return n * (n - 1);; operation M373(arr : OclAny , n : OclAny) : OclAny pre: true post: true activity: var SubsetSum operation M373(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var SubsetSum skip : int := 0 ; var SubsetSum:= 0 : int := 0 ; for i : Integer.subrange(0, n-1) do ( var isSingleOccurance : boolean := true ; for j : Integer.subrange(i + 1, n-1) do ( if arr[i+1] = arr[j+1] then ( isSingleOccurance := false ; arr[i+1] := 0; var arr[j+1] : int := 0 ; break ) else skip) ; if isSingleOccurance = true then ( if arr[i+1] > 0 then ( SubsetSum var isSingleOccurance : boolean := true := SubsetSum var isSingleOccurance : boolean := true + arr[i+1] ) else ( SubsetSum + arr[i+1] := SubsetSum + arr[i+1] + arr[i+1] ) ) else skip) ; return (SubsetSum var SubsetSum skip : int := 0 - SubsetSumFwOOZgqtMn)->abs(); : int := 0 ; var SubsetSum:= 0 : int := 0 ; for i : Integer.subrange(0, n-1) do ( var isSingleOccurance : boolean := true ; for j : Integer.subrange(i + 1, n-1) do ( if arr[i+1] = arr[j+1] then ( isSingleOccurance := false ; arr[i+1] := 0; var arr[j+1] : int := 0 ; break ) else skip) ; if isSingleOccurance = true then ( if arr[i+1] > 0 then ( SubsetSum var isSingleOccurance : boolean := true := SubsetSum var isSingleOccurance : boolean := true + arr[i+1] ) else ( SubsetSum + arr[i+1] := SubsetSum + arr[i+1] + arr[i+1] ) ) else skip) ; return (SubsetSum var SubsetSum operation M373(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var SubsetSum skip : int := 0 ; var SubsetSum:= 0 : int := 0 ; for i : Integer.subrange(0, n-1) do ( var isSingleOccurance : boolean := true ; for j : Integer.subrange(i + 1, n-1) do ( if arr[i+1] = arr[j+1] then ( isSingleOccurance := false ; arr[i+1] := 0; var arr[j+1] : int := 0 ; break ) else skip) ; if isSingleOccurance = true then ( if arr[i+1] > 0 then ( SubsetSum var isSingleOccurance : boolean := true := SubsetSum var isSingleOccurance : boolean := true + arr[i+1] ) else ( SubsetSum + arr[i+1] := SubsetSum + arr[i+1] + arr[i+1] ) ) else skip) ; return (SubsetSum var SubsetSum skip : int := 0 - SubsetSumFwOOZgqtMn)->abs(); : int := 0 - SubsetSumFwOOZgqtMn)->abs(); } class zskNzYEVNqUkm { static operation newzskNzYEVNqUkm() : zskNzYEVNqUkm pre: true post: zskNzYEVNqUkm->exists( _x | result = _x ); attribute ejtZIdV : double := 668.574; attribute nNm : String := ""; attribute jqMdANNdwY : Set := Set{}->union((Set{})); attribute aVpRGzqmpAX : String := "bXZL"; attribute dfeHGMwKL : double := 142.814; operation initialise() : zskNzYEVNqUkm pre: true post: true activity: self.ejtZIdV := 668.574 ; self.nNm := "" ; self.jqMdANNdwY := Set{}->union((Set{})) ; self.aVpRGzqmpAX := "bXZL" ; self.dfeHGMwKL := 142.814; return self; } class rGghWIdoqS { static operation newrGghWIdoqS() : rGghWIdoqS pre: true post: rGghWIdoqS->exists( _x | result = _x ); attribute CqMvDK : double := 980.122; attribute XtfiVJFxD : boolean := true; attribute paXSv : OclAny := null; operation initialise() : rGghWIdoqS pre: true post: true activity: self.CqMvDK := 980.122 ; self.XtfiVJFxD := true ; self.paXSv := null; return self; } class Atm { static operation newAtm() : Atm pre: true post: Atm->exists( _x | result = _x ); attribute zPE : int := 980; attribute DompTp : int := 237; attribute STrhkZppqgr : int := 714; attribute sYpM : int := 192; attribute vyele : Set := Set{}->union((Set{})); attribute bvzfOH : OclAny := null; operation initialise() : Atm pre: true post: true activity: self.zPE := 980 ; self.DompTp := 237 ; self.STrhkZppqgr := 714 ; self.sYpM := 192 ; self.vyele := Set{}->union((Set{})) ; self.bvzfOH := null; return self; operation gfgff(arr : OclAny , n : OclAny) : OclAny pre: true post: true activity: var mls : Sequence := Sequence{} ; var max : int := 0 ; for i : Integer.subrange(0, n-1) do ( execute ((1) : mls)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, i-1) do ( if ((arr[i+1] - arr[j+1])->abs() <= 1 & (mls[i+1]->compareTo(mls[j+1] + 1)) < 0) then ( mls[i+1] := mls[j+1] + 1 ) else skip)) ; for i : Integer.subrange(0, n-1) do ( if ((max->compareTo(mls[i+1])) < 0) then ( max := mls[i+1] ) else skip) ; return max; } class iwgqaLGEwmoQ { static operation newiwgqaLGEwmoQ() : iwgqaLGEwmoQ pre: true post: iwgqaLGEwmoQ->exists( _x | result = _x ); attribute hNrLN : int := 573; attribute LCY : Set := Set{}->union((Set{})); attribute xHakIIhtUTS : int := 173; attribute kJSfgZA : Set := Set{}->union((Set{})); operation initialise() : iwgqaLGEwmoQ pre: true post: true activity: self.hNrLN := 573 ; self.LCY := Set{}->union((Set{})) ; self.xHakIIhtUTS := 173 ; self.kJSfgZA := Set{}->union((Set{})); return self; } class DbuIfQOCPRja extends iwgqaLGEwmoQ { static operation newDbuIfQOCPRja() : DbuIfQOCPRja pre: true post: DbuIfQOCPRja->exists( _x | result = _x ); attribute jOSGeoi : boolean := false; attribute smP : Set := Set{}->union((Set{})); attribute Ibx : boolean := true; attribute LLVQF : int := 393; attribute WJyIJsN : String := ""; attribute KXAPnAOv : double := 901.647; attribute tKA : String := "yIknsDthGy"; attribute EtrhYXkAm : String := "VrHsuuiglr"; attribute PDNzb : int := 309; attribute mboJYml : int := 66; attribute QNvureA : Set := Set{}->union((Set{})); attribute NqyH : int := 202; attribute MGpgjJ : Set := Set{}->union((Set{})); operation initialise() : iwgqaLGEwmoQ pre: true post: true activity: self.jOSGeoi := false ; self.smP := Set{}->union((Set{})) ; self.Ibx := true ; self.LLVQF := 393 ; self.WJyIJsN := "" ; self.KXAPnAOv := 901.647 ; self.tKA := "yIknsDthGy" ; self.EtrhYXkAm := "VrHsuuiglr" ; self.PDNzb := 309 ; self.mboJYml := 66 ; self.QNvureA := Set{}->union((Set{})) ; self.NqyH := 202 ; self.MGpgjJ := Set{}->union((Set{})); return self; operation M365(a : OclAny , n : OclAny) : OclAny pre: true post: true activity: return (-1 + ("" + (((1 + (8 * n))->sqrt())))->toInteger()) div 2; } class zSHuRNznXZ { static operation newzSHuRNznXZ() : zSHuRNznXZ pre: true post: zSHuRNznXZ->exists( _x | result = _x ); attribute OztJDK : int := 966; attribute yrMgORJ : int := 251; attribute nPYUkMZidI : OclAny := null; operation initialise() : zSHuRNznXZ pre: true post: true activity: self.OztJDK := 966 ; self.yrMgORJ := 251 ; self.nPYUkMZidI := null; return self; operation fgfd(a : OclAny , n : OclAny) : OclAny pre: true post: true activity: var result : int := 1 ; for i : Integer.subrange(1, n-1) do ( var y : double := (i * (i + 1)) / 2 ; if ((y->compareTo(n)) < 0) then ( result := i ) else ( break )) ; return result; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip; operation M367(base : OclAny) : OclAny pre: true post: true activity: base := (base - 2) ; base := base / 2 ; return base * (base + 1) / 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import ocl import math def M451(x,y): if(y==0): return 0 if(y>0): return(x+M451(x,y-1)) if(y<0): return-M451(x,-y) class oHGnzOhDp : def __init__(self): self.upfpKhiDxv = 745.208 self.UdmUHo = [] self.eIUZSbHnET = 576.696 self.VvEtY = [] def wwww(x): next=0 if(x): rightOne=x&-(x) nextHigherOneBit=x+int(rightOne) rightOnesPattern=x^int(nextHigherOneBit) rightOnesPattern=(int(rightOnesPattern)/int(rightOne)) rightOnesPattern=int(rightOnesPattern)>>2 next=nextHigherOneBit|rightOnesPattern return next class eDedUgR : def __init__(self): self.EVE = 684 self.pqOBCcpKBAu = False self.AUCPjMr = 395.779 self.puNBbRjl = True self.JlhLahg = True self.OVlRTwmZKGn = set({}) self.dNXXWoNb = None self.drSfX = None def gggg(n): count=0; if(n and not(n&(n-1))): return n while(n!=0): n>>=1 count+=1 return 1<>1 n|=n>>2 n|=n>>4 n|=n>>8 n|=n>>16 n+=1 return n def uuuu(arr,n): for i in range(n): j=0 while(j0: prevPrev=prev prev=curr curr=prevPrev+prev n=n-(curr-prev-1) n=n+(curr-prev-1) return prev+n class GNSllpqQ : def __init__(self): self.ZHHHCA = 490 self.IppNDQfKwwE = 986 self.opOOLw = True self.AUtGf = True class nHKLZ : def __init__(self): self.VrsBJvAILaP = 162.12 self.yoWVlFOpo = None def pop(n): return (3*n*n-n)/2 class jMkebLPK : def __init__(self): self.HBdtT = 413.515 self.CNIXtDzNNxd = False self.SmcnLSWzDO = None def nnn(C,l): if(l>=C):return C eq_root=(math.sqrt(1+8*(C-l))-1)/2 return math.ceil(eq_root)+l class bLUsua : def __init__(self): self.KYcq = [] self.uXPUoDI = [] self.nLZVb = 509 self.IKWnIomS = None self.nvoaOsGoYKN = None self.aIRLY = None ------------------------------------------------------------ OCL File: --------- class oHGnzOhDp { static operation newoHGnzOhDp() : oHGnzOhDp pre: true post: oHGnzOhDp->exists( _x | result = _x ); attribute upfpKhiDxv : double := 745.208; attribute UdmUHo : Sequence := Sequence{}; attribute eIUZSbHnET : double := 576.696; attribute VvEtY : Sequence := Sequence{}; operation initialise() : oHGnzOhDp pre: true post: true activity: self.upfpKhiDxv := 745.208 ; self.UdmUHo := Sequence{} ; self.eIUZSbHnET := 576.696 ; self.VvEtY := Sequence{}; return self; operation wwww((def_parameters (def_parameter (named_parameter (name x))))) : OclAny pre: true post: true activity: var next : int := 0 ; if (x) then ( var rightOne : int := MathLib.bitwiseAnd(x, -(x)) ; var nextHigherOneBit : OclAny := x + ("" + ((rightOne)))->toInteger() ; var rightOnesPattern : int := MathLib.bitwiseXor(x, ("" + ((nextHigherOneBit)))->toInteger()) ; rightOnesPattern := (("" + ((rightOnesPattern)))->toInteger() / ("" + ((rightOne)))->toInteger()) ; rightOnesPattern := ("" + ((rightOnesPattern)))->toInteger() /(2->pow(2)) ; next := MathLib.bitwiseOr(nextHigherOneBit, rightOnesPattern) ) else skip ; return next; } class eDedUgR { static operation neweDedUgR() : eDedUgR pre: true post: eDedUgR->exists( _x | result = _x ); attribute EVE : int := 684; attribute pqOBCcpKBAu : boolean := false; attribute AUCPjMr : double := 395.779; attribute puNBbRjl : boolean := true; attribute JlhLahg : boolean := true; attribute OVlRTwmZKGn : Set := Set{}->union((Set{})); attribute dNXXWoNb : OclAny := null; attribute drSfX : OclAny := null; operation initialise() : eDedUgR pre: true post: true activity: self.EVE := 684 ; self.pqOBCcpKBAu := false ; self.AUCPjMr := 395.779 ; self.puNBbRjl := true ; self.JlhLahg := true ; self.OVlRTwmZKGn := Set{}->union((Set{})) ; self.dNXXWoNb := null ; self.drSfX := null; return self; operation gggg((def_parameters (def_parameter (named_parameter (name n))))) : OclAny pre: true post: true activity: var count : int := 0; ; if (n & not((MathLib.bitwiseAnd(n, (n - 1))))) then ( return n ) else skip ; while (n /= 0) do ( n := n div (2->pow(1)) ; count := count + 1) ; return 1 * (2->pow(count));; } class palPup { static operation newpalPup() : palPup pre: true post: palPup->exists( _x | result = _x ); attribute qBOjMPEOru : String := ""; attribute aWZIaY : double := 357.605; attribute AfxhAreEDhu : double := 772.297; attribute RoHDM : double := 597.647; attribute hEC : double := 515.773; attribute pQn : OclAny := null; operation initialise() : palPup pre: true post: true activity: self.qBOjMPEOru := "" ; self.aWZIaY := 357.605 ; self.AfxhAreEDhu := 772.297 ; self.RoHDM := 597.647 ; self.hEC := 515.773 ; self.pQn := null; return self; operation kkkk((def_parameters (def_parameter (named_parameter (name n))))) : OclAny pre: true post: true activity: var p : int := 1 ; if (n & not((MathLib.bitwiseAnd(n, (n - 1))))) then ( return n ) else skip ; while ((p->compareTo(n)) < 0) do ( p := p * (2->pow(1))) ; return p;; operation jjjj((def_parameters (def_parameter (named_parameter (name n))))) : OclAny pre: true post: true activity: n := n - 1 ; n := n or n /(2->pow(1)) ; n := n or n /(2->pow(2)) ; n := n or n /(2->pow(4)) ; n := n or n /(2->pow(8)) ; n := n or n /(2->pow(16)) ; n := n + 1 ; return n; operation uuuu(arr : OclAny , n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( var j : int := 0 ; while ((j->compareTo(n)) < 0) do ( if (i /= j & arr[i+1] = arr[j+1]) then ( break ) else skip ; j := j + 1) ; if (j = n) then ( return arr[i+1] ) else skip) ; return -1; } class COjXwZ { static operation newCOjXwZ() : COjXwZ pre: true post: COjXwZ->exists( _x | result = _x ); attribute GFKChiQGm : String := ""; attribute QOjlX : int := 541; attribute yQpAPdIGy : String := "IyuLJcBL"; operation initialise() : COjXwZ pre: true post: true activity: self.GFKChiQGm := "" ; self.QOjlX := 541 ; self.yQpAPdIGy := "IyuLJcBL"; return self; } class jcKfxJeDESG { static operation newjcKfxJeDESG() : jcKfxJeDESG pre: true post: jcKfxJeDESG->exists( _x | result = _x ); attribute dnaVQCumqg : double := 461.721; operation initialise() : jcKfxJeDESG pre: true post: true activity: self.dnaVQCumqg := 461.721; return self; operation iiii((def_parameters (def_parameter (named_parameter (name n))))) : OclAny pre: true post: true activity: var res : OclAny := n ; for j : Integer.subrange(-1 + 1, (n)->size() - 1)->reverse() do ( res := res + n[j+1]) ; return res; } class EGiAlAaKPzZtX { static operation newEGiAlAaKPzZtX() : EGiAlAaKPzZtX pre: true post: EGiAlAaKPzZtX->exists( _x | result = _x ); attribute KQgnv : OclAny := null; operation initialise() : EGiAlAaKPzZtX pre: true post: true activity: self.KQgnv := null; return self; } class TGsnewZTmAI { static operation newTGsnewZTmAI() : TGsnewZTmAI pre: true post: TGsnewZTmAI->exists( _x | result = _x ); attribute WMhwlhehZHX : String := "SpMSDLvQ"; operation initialise() : TGsnewZTmAI pre: true post: true activity: self.WMhwlhehZHX := "SpMSDLvQ"; return self; operation ooo(k : OclAny , n : OclAny) : OclAny pre: true post: true activity: var f1 : int := 0 ; var f2 : int := 1 ; var i : int := 2 ; while i /= 0 do ( var f3 : int := f1 + f2 ; f1 := f2 ; f2 := f3 ; if f2 mod k = 0 then ( return n * i ) else skip ; i := i + 1) ; return; } class RguWqwQoH { static operation newRguWqwQoH() : RguWqwQoH pre: true post: RguWqwQoH->exists( _x | result = _x ); attribute TJgdRPNNpQT : int := 867; attribute giaXtp : OclAny := null; operation initialise() : RguWqwQoH pre: true post: true activity: self.TJgdRPNNpQT := 867 ; self.giaXtp := null; return self; operation ooo((def_parameters (def_parameter (named_parameter (name n))))) : OclAny pre: true post: true activity: var prevPrev : int := 1 ; var prev : int := 2 ; var curr : int := 3 ; while n > 0 do ( prevPrev := prev ; prev := curr ; curr := prevPrev + prev ; n := n - (curr - prev - 1)) ; n := n + (curr - prev - 1) ; return prev + n; } class GNSllpqQ { static operation newGNSllpqQ() : GNSllpqQ pre: true post: GNSllpqQ->exists( _x | result = _x ); attribute ZHHHCA : int := 490; attribute IppNDQfKwwE : int := 986; attribute opOOLw : boolean := true; attribute AUtGf : boolean := true; operation initialise() : GNSllpqQ pre: true post: true activity: self.ZHHHCA := 490 ; self.IppNDQfKwwE := 986 ; self.opOOLw := true ; self.AUtGf := true; return self; } class nHKLZ { static operation newnHKLZ() : nHKLZ pre: true post: nHKLZ->exists( _x | result = _x ); attribute VrsBJvAILaP : double := 162.12; attribute yoWVlFOpo : OclAny := null; operation initialise() : nHKLZ pre: true post: true activity: self.VrsBJvAILaP := 162.12 ; self.yoWVlFOpo := null; return self; operation pop((def_parameters (def_parameter (named_parameter (name n))))) : OclAny pre: true post: true activity: return (3 * n * n - n) / 2; } class jMkebLPK { static operation newjMkebLPK() : jMkebLPK pre: true post: jMkebLPK->exists( _x | result = _x ); attribute HBdtT : double := 413.515; attribute CNIXtDzNNxd : boolean := false; attribute SmcnLSWzDO : OclAny := null; operation initialise() : jMkebLPK pre: true post: true activity: self.HBdtT := 413.515 ; self.CNIXtDzNNxd := false ; self.SmcnLSWzDO := null; return self; operation nnn(C : OclAny , l : OclAny) : OclAny pre: true post: true activity: if ((l->compareTo(C)) >= 0) then ( return C ) else skip ; var eq_root : double := ((1 + 8 * (C - l))->sqrt() - 1) / 2 ; return (eq_root)->ceil() + l; } class bLUsua { static operation newbLUsua() : bLUsua pre: true post: bLUsua->exists( _x | result = _x ); attribute KYcq : Sequence := Sequence{}; attribute uXPUoDI : Sequence := Sequence{}; attribute nLZVb : int := 509; attribute IKWnIomS : OclAny := null; attribute nvoaOsGoYKN : OclAny := null; attribute aIRLY : OclAny := null; operation initialise() : bLUsua pre: true post: true activity: self.KYcq := Sequence{} ; self.uXPUoDI := Sequence{} ; self.nLZVb := 509 ; self.IKWnIomS := null ; self.nvoaOsGoYKN := null ; self.aIRLY := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip; operation M451(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (y = 0) then ( return 0 ) else skip ; if (y > 0) then ( return (x + M451(x, y - 1)) ) else skip ; if (y < 0) then ( return -M451(x, -y) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import copy def M546(mat,N): for i in range(N): for j in range(N): if(mat[i][j] != mat[j][i]): return False return True class HEuRKyBSSwzS : def __init__(self): self.soLyhy = [] self.HTd = "" self.KtsuJYnlMFS = 245 self.idzxpnpFBW = [] self.Hgbd = set({}) self.pvMxlMrECc = 833 self.xmVBvpOD = False def kkkk(num,divisor): return(num-divisor*(num//divisor)) class uWTVTBbTJB : def __init__(self): self.wNM = [] class NZxTxa : def __init__(self): self.unzEJeDBM = "NoD" self.EAgRUIdqPe = "rYJiOpQJt" def hhhh(num, divisor): if (divisor == 0): return False if (divisor < 0): divisor = -divisor if (num < 0): num = -num i = 1 product = 0 while (product <= num): product = divisor * i i += 1 return num - (product - divisor) class eWGDtFWIt : def __init__(self): self.LcFq = 277 self.eEN = False self.UYAUXqcn = "j" self.njfwVJ = [] self.NgAjo = [] self.wkJYh = [] self.ZnicWL = set({}) def hjhj(num, divisor): while (num >= divisor): num -= divisor; return num; class NrMpv : def __init__(self): self.vpmlDuTC = 88.474 self.JGSUl = 224 self.OPkshZ = [] self.xXBviO = None def ffff(a): area = (sqrt(5 * (5 + 2 * (sqrt(5)))) * a * a) / 4 return area class SMRyrr : def __init__(self): self.yWREXmdYj = 369 self.uRpTaDAkX = 878 class GYtxpIehLb : def __init__(self): self.JTGVhkxoRY = "" self.LSBzbuG = 780.436 self.kBvZpU = 28.323 self.IPeoIwdV = 331 self.sLTmqQWKciB = "PwBEVg" self.YMCZyTY = None def M551(l, b, h): return ((l * b * h) / 2) class khWon : def __init__(self): self.LyUjizLGEP = 459 class iCQrzqkzVY : def __init__(self): self.yLmBiQyM = 599 def llll(blockSize, m, processSize, n): allocation = [-1] * n for i in range(n): wstIdx = -1 for j in range(m): if blockSize[j] >= processSize[i]: if wstIdx == -1: wstIdx = j elif blockSize[wstIdx] < blockSize[j]: wstIdx = j if wstIdx != -1: allocation[i] = wstIdx blockSize[wstIdx] -= processSize[i] print("Process No.Process Size Block no.") for i in range(n): print(i + 1, " ", processSize[i], end=" ") if allocation[i] != -1: print(allocation[i] + 1) else: print("Not Allocated") class VoLGosmTXjgz : def __init__(self): self.FJsay = 405.578 self.fhc = True self.bMZsigc = True class snnSvtGsx : def __init__(self): self.NPzNhU = False def M553(a, b, c, d): sum = a * a + b * b + c * c; if (d * d == sum): return True else: return False class kSSCOE(VoLGosmTXjgz) : def __init__(self): self.gHmCSbs = [] self.cQCmHc = "" self.aIV = 332 self.FuTZsZi = True self.hAJpjfgtbx = None self.XgBad = 8.501 self.tSKIHi = False self.IWQicCxeM = True self.lELZSLplhGu = True class hxqbc : def __init__(self): self.qgRnJqvqlt = set({}) self.lUc = 204 self.sgrLqK = "hsqHHnXESn" self.TDhj = [] self.kILDgxISnMd = 586 self.jzCkv = None def M545(n): ar=[0]*10 while(n>0): digit=math.floor(n%10) if(ar[digit]): return 0 ar[digit]=1 n=n/10 return 1 ------------------------------------------------------------ OCL File: --------- class HEuRKyBSSwzS { static operation newHEuRKyBSSwzS() : HEuRKyBSSwzS pre: true post: HEuRKyBSSwzS->exists( _x | result = _x ); attribute soLyhy : Sequence := Sequence{}; attribute HTd : String := ""; attribute KtsuJYnlMFS : int := 245; attribute idzxpnpFBW : Sequence := Sequence{}; attribute Hgbd : Set := Set{}->union((Set{})); attribute pvMxlMrECc : int := 833; attribute xmVBvpOD : boolean := false; operation initialise() : HEuRKyBSSwzS pre: true post: true activity: self.soLyhy := Sequence{} ; self.HTd := "" ; self.KtsuJYnlMFS := 245 ; self.idzxpnpFBW := Sequence{} ; self.Hgbd := Set{}->union((Set{})) ; self.pvMxlMrECc := 833 ; self.xmVBvpOD := false; return self; operation kkkk(num : OclAny , divisor : OclAny) : OclAny pre: true post: true activity: return (num - divisor * (num div divisor)); } class uWTVTBbTJB { static operation newuWTVTBbTJB() : uWTVTBbTJB pre: true post: uWTVTBbTJB->exists( _x | result = _x ); attribute wNM : Sequence := Sequence{}; operation initialise() : uWTVTBbTJB pre: true post: true activity: self.wNM := Sequence{}; return self; } class NZxTxa { static operation newNZxTxa() : NZxTxa pre: true post: NZxTxa->exists( _x | result = _x ); attribute unzEJeDBM : String := "NoD"; attribute EAgRUIdqPe : String := "rYJiOpQJt"; operation initialise() : NZxTxa pre: true post: true activity: self.unzEJeDBM := "NoD" ; self.EAgRUIdqPe := "rYJiOpQJt"; return self; operation hhhh(num : OclAny , divisor : OclAny) : OclAny pre: true post: true activity: if (divisor = 0) then ( return false ) else skip ; if (divisor < 0) then ( divisor := -divisor ) else skip ; if (num < 0) then ( num := -num ) else skip ; var i : int := 1 ; var product : int := 0 ; while ((product->compareTo(num)) <= 0) do ( product := divisor * i ; i := i + 1) ; return num - (product - divisor); } class eWGDtFWIt { static operation neweWGDtFWIt() : eWGDtFWIt pre: true post: eWGDtFWIt->exists( _x | result = _x ); attribute LcFq : int := 277; attribute eEN : boolean := false; attribute UYAUXqcn : String := "j"; attribute njfwVJ : Sequence := Sequence{}; attribute NgAjo : Sequence := Sequence{}; attribute wkJYh : Sequence := Sequence{}; attribute ZnicWL : Set := Set{}->union((Set{})); operation initialise() : eWGDtFWIt pre: true post: true activity: self.LcFq := 277 ; self.eEN := false ; self.UYAUXqcn := "j" ; self.njfwVJ := Sequence{} ; self.NgAjo := Sequence{} ; self.wkJYh := Sequence{} ; self.ZnicWL := Set{}->union((Set{})); return self; operation hjhj(num : OclAny , divisor : OclAny) pre: true post: true activity: while ((num->compareTo(divisor)) >= 0) do ( num := num - divisor;) ; return num;; } class NrMpv { static operation newNrMpv() : NrMpv pre: true post: NrMpv->exists( _x | result = _x ); attribute vpmlDuTC : double := 88.474; attribute JGSUl : int := 224; attribute OPkshZ : Sequence := Sequence{}; attribute xXBviO : OclAny := null; operation initialise() : NrMpv pre: true post: true activity: self.vpmlDuTC := 88.474 ; self.JGSUl := 224 ; self.OPkshZ := Sequence{} ; self.xXBviO := null; return self; operation ffff((def_parameters (def_parameter (named_parameter (name a))))) : OclAny pre: true post: true activity: var area : double := (sqrt(5 * (5 + 2 * (sqrt(5)))) * a * a) / 4 ; return area; } class SMRyrr { static operation newSMRyrr() : SMRyrr pre: true post: SMRyrr->exists( _x | result = _x ); attribute yWREXmdYj : int := 369; attribute uRpTaDAkX : int := 878; operation initialise() : SMRyrr pre: true post: true activity: self.yWREXmdYj := 369 ; self.uRpTaDAkX := 878; return self; } class GYtxpIehLb { static operation newGYtxpIehLb() : GYtxpIehLb pre: true post: GYtxpIehLb->exists( _x | result = _x ); attribute JTGVhkxoRY : String := ""; attribute LSBzbuG : double := 780.436; attribute kBvZpU : double := 28.323; attribute IPeoIwdV : int := 331; attribute sLTmqQWKciB : String := "PwBEVg"; attribute YMCZyTY : OclAny := null; operation initialise() : GYtxpIehLb pre: true post: true activity: self.JTGVhkxoRY := "" ; self.LSBzbuG := 780.436 ; self.kBvZpU := 28.323 ; self.IPeoIwdV := 331 ; self.sLTmqQWKciB := "PwBEVg" ; self.YMCZyTY := null; return self; operation M551(l : OclAny , b : OclAny,h : OclAny) : OclAny pre: true post: true activity: return ((l * b * h) / 2); } class khWon { static operation newkhWon() : khWon pre: true post: khWon->exists( _x | result = _x ); attribute LyUjizLGEP : int := 459; operation initialise() : khWon pre: true post: true activity: self.LyUjizLGEP := 459; return self; } class iCQrzqkzVY { static operation newiCQrzqkzVY() : iCQrzqkzVY pre: true post: iCQrzqkzVY->exists( _x | result = _x ); attribute yLmBiQyM : int := 599; operation initialise() : iCQrzqkzVY pre: true post: true activity: self.yLmBiQyM := 599; return self; operation llll(blockSize : OclAny , m : OclAny,processSize : OclAny,n : OclAny) pre: true post: true activity: var allocation : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; for i : Integer.subrange(0, n-1) do ( var wstIdx : int := -1 ; for j : Integer.subrange(0, m-1) do ( if (blockSize[j+1]->compareTo(processSize[i+1])) >= 0 then ( if wstIdx = -1 then ( wstIdx := j ) else (if (blockSize[wstIdx+1]->compareTo(blockSize[j+1])) < 0 then ( wstIdx := j ) else skip) ) else skip) ; if wstIdx /= -1 then ( allocation[i+1] := wstIdx ; blockSize[wstIdx+1] := blockSize[wstIdx+1] - processSize[i+1] ) else skip) ; execute ("Process No.Process Size Block no.")->display() ; for i : Integer.subrange(0, n-1) do ( execute (i + 1)->display() ; if allocation[i+1] /= -1 then ( execute (allocation[i+1] + 1)->display() ) else ( execute ("Not Allocated")->display() )); } class VoLGosmTXjgz { static operation newVoLGosmTXjgz() : VoLGosmTXjgz pre: true post: VoLGosmTXjgz->exists( _x | result = _x ); attribute FJsay : double := 405.578; attribute fhc : boolean := true; attribute bMZsigc : boolean := true; operation initialise() : VoLGosmTXjgz pre: true post: true activity: self.FJsay := 405.578 ; self.fhc := true ; self.bMZsigc := true; return self; } class snnSvtGsx { static operation newsnnSvtGsx() : snnSvtGsx pre: true post: snnSvtGsx->exists( _x | result = _x ); attribute NPzNhU : boolean := false; operation initialise() : snnSvtGsx pre: true post: true activity: self.NPzNhU := false; return self; operation M553(a : OclAny , b : OclAny,c : OclAny,d : OclAny) : OclAny pre: true post: true activity: var sum : double := a * a + b * b + c * c; ; if (d * d = sum) then ( return true ) else ( return false ); } class kSSCOE extends VoLGosmTXjgz { static operation newkSSCOE() : kSSCOE pre: true post: kSSCOE->exists( _x | result = _x ); attribute gHmCSbs : Sequence := Sequence{}; attribute cQCmHc : String := ""; attribute aIV : int := 332; attribute FuTZsZi : boolean := true; attribute hAJpjfgtbx : OclAny := null; attribute XgBad : double := 8.501; attribute tSKIHi : boolean := false; attribute IWQicCxeM : boolean := true; attribute lELZSLplhGu : boolean := true; operation initialise() : snnSvtGsx pre: true post: true activity: self.gHmCSbs := Sequence{} ; self.cQCmHc := "" ; self.aIV := 332 ; self.FuTZsZi := true ; self.hAJpjfgtbx := null ; self.XgBad := 8.501 ; self.tSKIHi := false ; self.IWQicCxeM := true ; self.lELZSLplhGu := true; return self; } class hxqbc { static operation newhxqbc() : hxqbc pre: true post: hxqbc->exists( _x | result = _x ); attribute qgRnJqvqlt : Set := Set{}->union((Set{})); attribute lUc : int := 204; attribute sgrLqK : String := "hsqHHnXESn"; attribute TDhj : Sequence := Sequence{}; attribute kILDgxISnMd : int := 586; attribute jzCkv : OclAny := null; operation initialise() : hxqbc pre: true post: true activity: self.qgRnJqvqlt := Set{}->union((Set{})) ; self.lUc := 204 ; self.sgrLqK := "hsqHHnXESn" ; self.TDhj := Sequence{} ; self.kILDgxISnMd := 586 ; self.jzCkv := null; return self; operation M545((def_parameters (def_parameter (named_parameter (name n))))) : OclAny pre: true post: true activity: var ar : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; while (n > 0) do ( var digit : double := (n mod 10)->floor() ; if (ar[digit+1]) then ( return 0 ) else skip ; ar[digit+1] := 1 ; n := n / 10) ; return 1; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip; operation M546(mat : OclAny, N : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( if (mat[i+1][j+1] /= mat[j+1][i+1]) then ( return false ) else skip)) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import ocl import math class EcOKtOPobp : def __init__(self): self.vGbKQRe = "" self.YIsDhldnTP = 740.628 self.uzhE = 557.40 self.bhsGaCZu = 869.529 self.tIRCbu = 867.367 self.mzXOLEJ = 561 self.OTBzDaViWSS = True def M647(n): return n * (n + 1) * (n + 2) * (3 * n + 1) / 24 def Mgfd(n, d): return n * 7 def fdfdfgf(n,k,l): return n * k * l class GjlK : def __init__(self): self.RodQyhiLtZN = [] self.OvuQJ = set({}) self.eKQK = True self.EQautI = True self.bXZDYfqL = 582 self.MPUUaozW = [] self.GLiudJV = 631 class VCHUnLaCt : def __init__(self): self.SxLhPa = [] self.KpHHxGPw = "YIqqoLKr" self.oKODaazR = False self.duMhI = 592 self.XbpORMkZS = 2 self.tjApbhvpkSI = 244 self.ehknxAxEx = "zRJUPViWv" self.rXAwmP = True def M645(n): sm = 0 for i in range(1, n + 1): for j in range(i, n + 1): sm = sm + i * j return sm class eCXRMOV : def __init__(self): self.rkSjoIRMXf = 642 self.jtWqG = 15.338 self.DnYnRCYf = True self.xdHIX = 565.505 self.oCJgJzo = set({}) self.MdtLze = None self.aVbzMOnp = None def M646(n): multiTerms = n * (n + 1) // 2 sm = multiTerms for i in range(2, n + 1): multiTerms = multiTerms - (i - 1) sm = sm + multiTerms * i return sm class lSOxs(EcOKtOPobp) : def __init__(self): self.OmbTk = "bR" self.ktzvPCl = "" self.ZtTh = "jpzuYsDc" self.iTDZEQ = 122.90 self.jJpTObh = 991.302 self.JdHC = 458.414 self.myXTIflZ = 863.961 self.KWRZNnRsQm = 912 self.thCLsNEVQm = False class ikVOZcpQUIq(GjlK) : def __init__(self): self.qzz = 139 self.WkUR = 432 self.aqwW = True self.OZRYpLmCOv = 506 self.DvhyFSdKGE = [] self.DbktKAN = None self.htPgKxCISgB = [] self.rEN = set({}) self.DgJpgmXtpYj = True self.oNkz = True self.ydiuYpFI = 127 self.DRR = [] self.aOdkZoAw = 765 def M644(num): result = 0 i = 2 while i <= (math.sqrt(num)): if (num % i == 0): if (i == (num / i)): result = result + i; else: result = result + (i + num / i); i = i + 1 return (result + 1); class PTMjmAeRvtfx : def __init__(self): self.AuYL = True self.CwNFEdI = set({}) self.OWsrfPjtsS = 275 self.PpZVxabVW = None self.vXSPOQSkXJP = None class WISmX : def __init__(self): self.VRG = 466 self.CHRkuWSfb = 107 class RSxsIHmlnuDtL(WISmX) : def __init__(self): self.DwhxT = 688 def kkkmk(n): return 0.0246 * (math.pow(10, n) - 1 - (9 * n)) class QlaY : def __init__(self): self.ZxtcAPpPVGe = [] self.ioIfiotVK = "m" self.xGlv = "" self.aKj = 172.829 self.FDVslEj = [] self.rTHY = 463.410 self.mSOYoBem = 850 self.WxEzyRfWZIE = 149 self.DffIGVGQtni = 433.221 def M643(n): sum = 0 sum = 1 << n return (sum - 1) class cvWm(QlaY) : def __init__(self): self.XHk = "FrfglRdD" self.GDUp = True self.fSIhcu = None self.eRSfj = [] self.LpVwEBtrbmM = "GjBkGjXhN" self.AlgsTbPvfq = "PlwUuftMbq" self.dmNSWWli = 677.776 self.PhlNOvlThiq = [] self.gYYKtyxJ = 360.403 self.IDKVUokhVg = 52 self.knmKBLDBrT = 854 self.lCsm = 504.48 def jkjk(n): return 0.0246 * n class BiB : def __init__(self): self.JYeRvg = True self.HZUvhljbE = 172 self.ACmkeuifGe = "" def M642(n): sum = 0 for row in range(n): sum = sum + (1 << row) return sum class vSVDCnRTvH(QlaY) : def __init__(self): self.cDF = 558.376 self.zPB = set({}) self.MMUVUzhrsR = [] self.AnaXvpzHH = "UDr" self.alaNRhxKa = "hAxtSE" self.nLXRVuPkWo = 390.697 self.BMQKKryebd = [] self.Jtwv = 685.809 self.ShcRasVU = 976 self.Rby = 658 self.CorAnzSX = 864.278 class kDwxEZZXS(QlaY) : def __init__(self): self.pDbhiboP = [] self.xqd = "" self.GgzWvHKQx = "" self.RPsRnMWO = 176.337 self.atZhDChqbYP = [] self.joFuBGKO = 854.495 self.QuoONWeoui = 396 self.bzqvqFARtIL = 307 self.SHld = 808.909 def M641(tree, k): level = -1 sum = 0 n = len(tree) for i in range(n): if tree[i] == '(': level += 1 elif tree[i] == ')': level -= 1 else: if level == k: sum += (ord(tree[i]) - ord('0')) return sum ------------------------------------------------------------ OCL File: --------- class EcOKtOPobp { static operation newEcOKtOPobp() : EcOKtOPobp pre: true post: EcOKtOPobp->exists( _x | result = _x ); attribute vGbKQRe : String := ""; attribute YIsDhldnTP : double := 740.628; attribute uzhE : double := 557.40; attribute bhsGaCZu : double := 869.529; attribute tIRCbu : double := 867.367; attribute mzXOLEJ : int := 561; attribute OTBzDaViWSS : boolean := true; operation initialise() : EcOKtOPobp pre: true post: true activity: self.vGbKQRe := "" ; self.YIsDhldnTP := 740.628 ; self.uzhE := 557.40 ; self.bhsGaCZu := 869.529 ; self.tIRCbu := 867.367 ; self.mzXOLEJ := 561 ; self.OTBzDaViWSS := true; return self; operation M647((def_parameters (def_parameter (named_parameter (name n))))) : OclAny pre: true post: true activity: return n * (n + 1) * (n + 2) * (3 * n + 1) / 24; operation Mgfd(n : OclAny , d : OclAny) : OclAny pre: true post: true activity: return n * 7; operation fdfdfgf(n : OclAny , k : OclAny,l : OclAny) : OclAny pre: true post: true activity: return n * k * l; } class GjlK { static operation newGjlK() : GjlK pre: true post: GjlK->exists( _x | result = _x ); attribute RodQyhiLtZN : Sequence := Sequence{}; attribute OvuQJ : Set := Set{}->union((Set{})); attribute eKQK : boolean := true; attribute EQautI : boolean := true; attribute bXZDYfqL : int := 582; attribute MPUUaozW : Sequence := Sequence{}; attribute GLiudJV : int := 631; operation initialise() : GjlK pre: true post: true activity: self.RodQyhiLtZN := Sequence{} ; self.OvuQJ := Set{}->union((Set{})) ; self.eKQK := true ; self.EQautI := true ; self.bXZDYfqL := 582 ; self.MPUUaozW := Sequence{} ; self.GLiudJV := 631; return self; } class VCHUnLaCt { static operation newVCHUnLaCt() : VCHUnLaCt pre: true post: VCHUnLaCt->exists( _x | result = _x ); attribute SxLhPa : Sequence := Sequence{}; attribute KpHHxGPw : String := "YIqqoLKr"; attribute oKODaazR : boolean := false; attribute duMhI : int := 592; attribute XbpORMkZS : int := 2; attribute tjApbhvpkSI : int := 244; attribute ehknxAxEx : String := "zRJUPViWv"; attribute rXAwmP : boolean := true; operation initialise() : VCHUnLaCt pre: true post: true activity: self.SxLhPa := Sequence{} ; self.KpHHxGPw := "YIqqoLKr" ; self.oKODaazR := false ; self.duMhI := 592 ; self.XbpORMkZS := 2 ; self.tjApbhvpkSI := 244 ; self.ehknxAxEx := "zRJUPViWv" ; self.rXAwmP := true; return self; operation M645((def_parameters (def_parameter (named_parameter (name n))))) : OclAny pre: true post: true activity: var sm : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(i, n + 1-1) do ( sm := sm + i * j)) ; return sm; } class eCXRMOV { static operation neweCXRMOV() : eCXRMOV pre: true post: eCXRMOV->exists( _x | result = _x ); attribute rkSjoIRMXf : int := 642; attribute jtWqG : double := 15.338; attribute DnYnRCYf : boolean := true; attribute xdHIX : double := 565.505; attribute oCJgJzo : Set := Set{}->union((Set{})); attribute MdtLze : OclAny := null; attribute aVbzMOnp : OclAny := null; operation initialise() : eCXRMOV pre: true post: true activity: self.rkSjoIRMXf := 642 ; self.jtWqG := 15.338 ; self.DnYnRCYf := true ; self.xdHIX := 565.505 ; self.oCJgJzo := Set{}->union((Set{})) ; self.MdtLze := null ; self.aVbzMOnp := null; return self; operation M646((def_parameters (def_parameter (named_parameter (name n))))) : OclAny pre: true post: true activity: var multiTerms : int := n * (n + 1) div 2 ; sm := multiTerms ; for i : Integer.subrange(2, n + 1-1) do ( multiTerms := multiTerms - (i - 1) ; sm := sm + multiTerms * i) ; return sm; } class lSOxs extends EcOKtOPobp { static operation newlSOxs() : lSOxs pre: true post: lSOxs->exists( _x | result = _x ); attribute OmbTk : String := "bR"; attribute ktzvPCl : String := ""; attribute ZtTh : String := "jpzuYsDc"; attribute iTDZEQ : double := 122.90; attribute jJpTObh : double := 991.302; attribute JdHC : double := 458.414; attribute myXTIflZ : double := 863.961; attribute KWRZNnRsQm : int := 912; attribute thCLsNEVQm : boolean := false; operation initialise() : eCXRMOV pre: true post: true activity: self.OmbTk := "bR" ; self.ktzvPCl := "" ; self.ZtTh := "jpzuYsDc" ; self.iTDZEQ := 122.90 ; self.jJpTObh := 991.302 ; self.JdHC := 458.414 ; self.myXTIflZ := 863.961 ; self.KWRZNnRsQm := 912 ; self.thCLsNEVQm := false; return self; } class ikVOZcpQUIq extends GjlK { static operation newikVOZcpQUIq() : ikVOZcpQUIq pre: true post: ikVOZcpQUIq->exists( _x | result = _x ); attribute qzz : int := 139; attribute WkUR : int := 432; attribute aqwW : boolean := true; attribute OZRYpLmCOv : int := 506; attribute DvhyFSdKGE : Sequence := Sequence{}; attribute DbktKAN : OclAny := null; attribute htPgKxCISgB : Sequence := Sequence{}; attribute rEN : Set := Set{}->union((Set{})); attribute DgJpgmXtpYj : boolean := true; attribute oNkz : boolean := true; attribute ydiuYpFI : int := 127; attribute DRR : Sequence := Sequence{}; attribute aOdkZoAw : int := 765; operation initialise() : eCXRMOV pre: true post: true activity: self.qzz := 139 ; self.WkUR := 432 ; self.aqwW := true ; self.OZRYpLmCOv := 506 ; self.DvhyFSdKGE := Sequence{} ; self.DbktKAN := null ; self.htPgKxCISgB := Sequence{} ; self.rEN := Set{}->union((Set{})) ; self.DgJpgmXtpYj := true ; self.oNkz := true ; self.ydiuYpFI := 127 ; self.DRR := Sequence{} ; self.aOdkZoAw := 765; return self; operation M644((def_parameters (def_parameter (named_parameter (name num))))) pre: true post: true activity: var result : int := 0 ; var i : int := 2 ; while (i->compareTo(((num)->sqrt()))) <= 0 do ( if (num mod i = 0) then ( if (i = (num / i)) then ( result := result + i; ) else ( result := result + (i + num / i); ) ) else skip ; i := i + 1) ; return (result + 1);; } class PTMjmAeRvtfx { static operation newPTMjmAeRvtfx() : PTMjmAeRvtfx pre: true post: PTMjmAeRvtfx->exists( _x | result = _x ); attribute AuYL : boolean := true; attribute CwNFEdI : Set := Set{}->union((Set{})); attribute OWsrfPjtsS : int := 275; attribute PpZVxabVW : OclAny := null; attribute vXSPOQSkXJP : OclAny := null; operation initialise() : PTMjmAeRvtfx pre: true post: true activity: self.AuYL := true ; self.CwNFEdI := Set{}->union((Set{})) ; self.OWsrfPjtsS := 275 ; self.PpZVxabVW := null ; self.vXSPOQSkXJP := null; return self; } class WISmX { static operation newWISmX() : WISmX pre: true post: WISmX->exists( _x | result = _x ); attribute VRG : int := 466; attribute CHRkuWSfb : int := 107; operation initialise() : WISmX pre: true post: true activity: self.VRG := 466 ; self.CHRkuWSfb := 107; return self; } class RSxsIHmlnuDtL extends WISmX { static operation newRSxsIHmlnuDtL() : RSxsIHmlnuDtL pre: true post: RSxsIHmlnuDtL->exists( _x | result = _x ); attribute DwhxT : int := 688; operation initialise() : WISmX pre: true post: true activity: self.DwhxT := 688; return self; operation kkkmk((def_parameters (def_parameter (named_parameter (name n))))) : OclAny pre: true post: true activity: return 0.0246 * ((10)->pow(n) - 1 - (9 * n)); } class QlaY { static operation newQlaY() : QlaY pre: true post: QlaY->exists( _x | result = _x ); attribute ZxtcAPpPVGe : Sequence := Sequence{}; attribute ioIfiotVK : String := "m"; attribute xGlv : String := ""; attribute aKj : double := 172.829; attribute FDVslEj : Sequence := Sequence{}; attribute rTHY : double := 463.410; attribute mSOYoBem : int := 850; attribute WxEzyRfWZIE : int := 149; attribute DffIGVGQtni : double := 433.221; operation initialise() : QlaY pre: true post: true activity: self.ZxtcAPpPVGe := Sequence{} ; self.ioIfiotVK := "m" ; self.xGlv := "" ; self.aKj := 172.829 ; self.FDVslEj := Sequence{} ; self.rTHY := 463.410 ; self.mSOYoBem := 850 ; self.WxEzyRfWZIE := 149 ; self.DffIGVGQtni := 433.221; return self; operation M643((def_parameters (def_parameter (named_parameter (name n))))) : OclAny pre: true post: true activity: var sum : int := 0 ; sum := 1 * (2->pow(n)) ; return (sum - 1); } class cvWm extends QlaY { static operation newcvWm() : cvWm pre: true post: cvWm->exists( _x | result = _x ); attribute XHk : String := "FrfglRdD"; attribute GDUp : boolean := true; attribute fSIhcu : OclAny := null; attribute eRSfj : Sequence := Sequence{}; attribute LpVwEBtrbmM : String := "GjBkGjXhN"; attribute AlgsTbPvfq : String := "PlwUuftMbq"; attribute dmNSWWli : double := 677.776; attribute PhlNOvlThiq : Sequence := Sequence{}; attribute gYYKtyxJ : double := 360.403; attribute IDKVUokhVg : int := 52; attribute knmKBLDBrT : int := 854; attribute lCsm : double := 504.48; operation initialise() : QlaY pre: true post: true activity: self.XHk := "FrfglRdD" ; self.GDUp := true ; self.fSIhcu := null ; self.eRSfj := Sequence{} ; self.LpVwEBtrbmM := "GjBkGjXhN" ; self.AlgsTbPvfq := "PlwUuftMbq" ; self.dmNSWWli := 677.776 ; self.PhlNOvlThiq := Sequence{} ; self.gYYKtyxJ := 360.403 ; self.IDKVUokhVg := 52 ; self.knmKBLDBrT := 854 ; self.lCsm := 504.48; return self; operation jkjk((def_parameters (def_parameter (named_parameter (name n))))) : OclAny pre: true post: true activity: return 0.0246 * n; } class BiB { static operation newBiB() : BiB pre: true post: BiB->exists( _x | result = _x ); attribute JYeRvg : boolean := true; attribute HZUvhljbE : int := 172; attribute ACmkeuifGe : String := ""; operation initialise() : BiB pre: true post: true activity: self.JYeRvg := true ; self.HZUvhljbE := 172 ; self.ACmkeuifGe := ""; return self; operation M642((def_parameters (def_parameter (named_parameter (name n))))) : OclAny pre: true post: true activity: sum := 0 ; for row : Integer.subrange(0, n-1) do ( sum := sum + (1 * (2->pow(row)))) ; return sum; } class vSVDCnRTvH extends QlaY { static operation newvSVDCnRTvH() : vSVDCnRTvH pre: true post: vSVDCnRTvH->exists( _x | result = _x ); attribute cDF : double := 558.376; attribute zPB : Set := Set{}->union((Set{})); attribute MMUVUzhrsR : Sequence := Sequence{}; attribute AnaXvpzHH : String := "UDr"; attribute alaNRhxKa : String := "hAxtSE"; attribute nLXRVuPkWo : double := 390.697; attribute BMQKKryebd : Sequence := Sequence{}; attribute Jtwv : double := 685.809; attribute ShcRasVU : int := 976; attribute Rby : int := 658; attribute CorAnzSX : double := 864.278; operation initialise() : BiB pre: true post: true activity: self.cDF := 558.376 ; self.zPB := Set{}->union((Set{})) ; self.MMUVUzhrsR := Sequence{} ; self.AnaXvpzHH := "UDr" ; self.alaNRhxKa := "hAxtSE" ; self.nLXRVuPkWo := 390.697 ; self.BMQKKryebd := Sequence{} ; self.Jtwv := 685.809 ; self.ShcRasVU := 976 ; self.Rby := 658 ; self.CorAnzSX := 864.278; return self; } class kDwxEZZXS extends QlaY { static operation newkDwxEZZXS() : kDwxEZZXS pre: true post: kDwxEZZXS->exists( _x | result = _x ); attribute pDbhiboP : Sequence := Sequence{}; attribute xqd : String := ""; attribute GgzWvHKQx : String := ""; attribute RPsRnMWO : double := 176.337; attribute atZhDChqbYP : Sequence := Sequence{}; attribute joFuBGKO : double := 854.495; attribute QuoONWeoui : int := 396; attribute bzqvqFARtIL : int := 307; attribute SHld : double := 808.909; operation initialise() : BiB pre: true post: true activity: self.pDbhiboP := Sequence{} ; self.xqd := "" ; self.GgzWvHKQx := "" ; self.RPsRnMWO := 176.337 ; self.atZhDChqbYP := Sequence{} ; self.joFuBGKO := 854.495 ; self.QuoONWeoui := 396 ; self.bzqvqFARtIL := 307 ; self.SHld := 808.909; return self; operation M641(tree : OclAny , k : OclAny) : OclAny pre: true post: true activity: var level : int := -1 ; sum := 0 ; n := (tree)->size() ; for i : Integer.subrange(0, n-1) do ( if tree[i+1] = '(' then ( level := level + 1 ) else (if tree[i+1] = ')' then ( level := level - 1 ) else ( if level = k then ( sum := sum + ((tree[i+1])->char2byte() - ('0')->char2byte()) ) else skip ) ) ) ; return sum; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minSum(A : list) : min_val = min(A) return min_val*(len(A) - 1) class NrGavHu : def __init__(self): self.dJrFfaHEGv = False def M13(n): bell=[[0 for i in range(n+1)]for j in range(n+1)] bell[0][0]=1 for i in range(1,n+1): bell[i][0]=bell[i-1][i-1] for j in range(1,i+1): bell[i][j]=bell[i-1][j-1]+bell[i][j-1] return bell[n][0] class HiACUFKtGYpfU : def __init__(self): self.hnXpVkMHjT = 0.0 self.yzqtzOQRpJ = [] self.kMapBnDvTA = 0 self.ybyDuGTePY = 0 self.xhITgtLaYK = False def M14(num1): l=len(num1); num=list(num1); i=l-1; while(i>=0): if(num[i]=='0'): num[i]='1'; break; else: num[i]='0'; i-=1; num1=''.join(num); if(i<0): num1='1'+num1; return num1; tst = [3,2,8] print(minSum(tst)) ------------------------------------------------------------ OCL File: --------- class NrGavHu { static operation newNrGavHu() : NrGavHu pre: true post: NrGavHu->exists( _x | result = _x ); attribute dJrFfaHEGv : boolean := false; operation initialise() : NrGavHu pre: true post: true activity: self.dJrFfaHEGv := false; return self; operation M13((def_parameters (def_parameter (named_parameter (name n))))) : OclAny pre: true post: true activity: var bell : Sequence := Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)))) ; bell->first()->first() := 1 ; for i : Integer.subrange(1, n + 1-1) do ( bell[i+1]->first() := bell[i - 1+1][i - 1+1] ; for j : Integer.subrange(1, i + 1-1) do ( bell[i+1][j+1] := bell[i - 1+1][j - 1+1] + bell[i+1][j - 1+1])) ; return bell[n+1]->first(); } class HiACUFKtGYpfU { static operation newHiACUFKtGYpfU() : HiACUFKtGYpfU pre: true post: HiACUFKtGYpfU->exists( _x | result = _x ); attribute hnXpVkMHjT : double := 0.0; attribute yzqtzOQRpJ : Sequence := Sequence{}; attribute kMapBnDvTA : int := 0; attribute ybyDuGTePY : int := 0; attribute xhITgtLaYK : boolean := false; operation initialise() : HiACUFKtGYpfU pre: true post: true activity: self.hnXpVkMHjT := 0.0 ; self.yzqtzOQRpJ := Sequence{} ; self.kMapBnDvTA := 0 ; self.ybyDuGTePY := 0 ; self.xhITgtLaYK := false; return self; operation M14((def_parameters (def_parameter (named_parameter (name num1))))) pre: true post: true activity: var l : int := (num1)->size(); ; var num : Sequence := (num1); ; var i : double := l - 1; ; while (i >= 0) do ( if (num[i+1] = '0') then ( num[i+1] := '1'; ; break; ) else ( num[i+1] := '0'; ) ; i := i - 1;) ; num1 := StringLib.sumStringsWithSeparator((num), ''); ; if (i < 0) then ( num1 := '1' + num1; ) else skip ; return num1;; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var tst : Sequence := Sequence{3}->union(Sequence{2}->union(Sequence{ 8 })) ; execute (minSum(tst))->display(); operation minSum(A : Sequence(OclAny)) : OclAny pre: true post: true activity: var min_val : OclAny := (A)->min() ; return min_val * ((A)->size() - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class oOpCrrxJ : def __init__(self): self.nXmiqrER = False self.fRzYcjjlnu = "" self.iLdQXvuXZL = 0 self.ygCwPXZ = 0.0 self.fBmOuoeOOz = False self.yrUnmoJfXb = "" self.jIwsYSO = set({}) self.tJExyDUGnU = set({}) self.hIFyjc = [] class QumAyldx : def __init__(self): self.fIvDyrO = 0.0 self.qKOMqavVwe = 0 self.dSjOhMn = 0 self.eKrWxIcwjC = 0 self.imjnRYK = set({}) self.idqdLAqMIu = False self.mliFNM = set({}) self.rqRRBmAqDJ = True class ichCphba(oOpCrrxJ) : def __init__(self): self.nUHTrdw = [] self.yZrVxddXrL = set({}) self.iBhYaME = False self.ySBNeSRAHU = set({}) self.vZwSsNZ = False self.rCFsHYzcjS = False self.hVILkgK = True self.nXmERxJ = False self.fRzYcjjlnu = "" self.iLdQXvuXZL = 10 self.ygCpUXZ = 0.05 self.fBmOuoeOOz = False self.yrUJfXb = "" self.jIoiUwsYSO = set({}) self.tJExGnU = set({}) self.hFjFyjc = [] ------------------------------------------------------------ OCL File: --------- class oOpCrrxJ { static operation newoOpCrrxJ() : oOpCrrxJ pre: true post: oOpCrrxJ->exists( _x | result = _x ); attribute nXmiqrER : boolean := false; attribute fRzYcjjlnu : String := ""; attribute iLdQXvuXZL : int := 0; attribute ygCwPXZ : double := 0.0; attribute fBmOuoeOOz : boolean := false; attribute yrUnmoJfXb : String := ""; attribute jIwsYSO : Set := Set{}->union((Set{})); attribute tJExyDUGnU : Set := Set{}->union((Set{})); attribute hIFyjc : Sequence := Sequence{}; operation initialise() : oOpCrrxJ pre: true post: true activity: self.nXmiqrER := false ; self.fRzYcjjlnu := "" ; self.iLdQXvuXZL := 0 ; self.ygCwPXZ := 0.0 ; self.fBmOuoeOOz := false ; self.yrUnmoJfXb := "" ; self.jIwsYSO := Set{}->union((Set{})) ; self.tJExyDUGnU := Set{}->union((Set{})) ; self.hIFyjc := Sequence{}; return self; } class QumAyldx { static operation newQumAyldx() : QumAyldx pre: true post: QumAyldx->exists( _x | result = _x ); attribute fIvDyrO : double := 0.0; attribute qKOMqavVwe : int := 0; attribute dSjOhMn : int := 0; attribute eKrWxIcwjC : int := 0; attribute imjnRYK : Set := Set{}->union((Set{})); attribute idqdLAqMIu : boolean := false; attribute mliFNM : Set := Set{}->union((Set{})); attribute rqRRBmAqDJ : boolean := true; operation initialise() : QumAyldx pre: true post: true activity: self.fIvDyrO := 0.0 ; self.qKOMqavVwe := 0 ; self.dSjOhMn := 0 ; self.eKrWxIcwjC := 0 ; self.imjnRYK := Set{}->union((Set{})) ; self.idqdLAqMIu := false ; self.mliFNM := Set{}->union((Set{})) ; self.rqRRBmAqDJ := true; return self; } class ichCphba extends oOpCrrxJ { static operation newichCphba() : ichCphba pre: true post: ichCphba->exists( _x | result = _x ); attribute nUHTrdw : Sequence := Sequence{}; attribute yZrVxddXrL : Set := Set{}->union((Set{})); attribute iBhYaME : boolean := false; attribute ySBNeSRAHU : Set := Set{}->union((Set{})); attribute vZwSsNZ : boolean := false; attribute rCFsHYzcjS : boolean := false; attribute hVILkgK : boolean := true; attribute nXmERxJ : boolean := false; attribute fRzYcjjlnu : String := ""; attribute iLdQXvuXZL : int := 10; attribute ygCpUXZ : double := 0.05; attribute fBmOuoeOOz : boolean := false; attribute yrUJfXb : String := ""; attribute jIoiUwsYSO : Set := Set{}->union((Set{})); attribute tJExGnU : Set := Set{}->union((Set{})); attribute hFjFyjc : Sequence := Sequence{}; operation initialise() : QumAyldx pre: true post: true activity: self.nUHTrdw := Sequence{} ; self.yZrVxddXrL := Set{}->union((Set{})) ; self.iBhYaME := false ; self.ySBNeSRAHU := Set{}->union((Set{})) ; self.vZwSsNZ := false ; self.rCFsHYzcjS := false ; self.hVILkgK := true ; self.nXmERxJ := false ; self.fRzYcjjlnu := "" ; self.iLdQXvuXZL := 10 ; self.ygCpUXZ := 0.05 ; self.fBmOuoeOOz := false ; self.yrUJfXb := "" ; self.jIoiUwsYSO := Set{}->union((Set{})) ; self.tJExGnU := Set{}->union((Set{})) ; self.hFjFyjc := Sequence{}; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calcMaxValue(s : str) : res = ord(s[0]) - 48 for i in range(1, len(s)) : if (s[i] == '0' or s[i] == '1' or res < 2) : res += ord(s[i]) - 48 else : res += ord(s[i]) - 48 return res class nULqpVdQu : def __init__(self): self.wswwdNLvUF = 0 self.wkiJFbXuJi = set({}) self.nmBccRdNRt = 0 self.cwYbcVLtwi = 0 self.uUNwqfGkWt = [] self.tiTmrXFOEx = None class btxcmdd : def __init__(self): self.jUfjZVIPqa = 0.0 def M50(str1,str2): if (len(str1) != len(str2)): return False clock_rot = "" anticlock_rot = "" l = len(str2) anticlock_rot = (anticlock_rot + str2[l - 2:] + str2[0:l - 2]) clock_rot = clock_rot + str2[2:] + str2[0:2] return (str1 == clock_rot or str1 == anticlock_rot) class hbhZaFI(nULqpVdQu) : def __init__(self): self.wswwdNLvUF = 0 self.wkiJFbXuJi = set({}) self.nmBccRdNRt = 0 self.cwYbcVLtwi = 0 self.uUNwqfGkWt = [] self.tiTmrXFOEx = None def M49(arr,n): if (n == 1): return True i = 1 for i in range(1,n): if arr[i - 1] < arr[i]: if (i == n): return True j = i while (arr[j] < arr[j - 1]): if (i > 1 and arr[j] < arr[i - 2]): return False j += 1 if (j == n): return True k = j if (arr[k] < arr[i - 1]): return False while (k > 1 and k < n): if (arr[k] < arr[k - 1]): return False k += 1 return True class EfPIVepxh(btxcmdd) : def __init__(self): self.xpsHidgdjJ = 0.0 self.qIzQilHlCl = None self.vLZoMXMDkt = [] print(calcMaxValue("normal string")) ------------------------------------------------------------ OCL File: --------- class nULqpVdQu { static operation newnULqpVdQu() : nULqpVdQu pre: true post: nULqpVdQu->exists( _x | result = _x ); attribute wswwdNLvUF : int := 0; attribute wkiJFbXuJi : Set := Set{}->union((Set{})); attribute nmBccRdNRt : int := 0; attribute cwYbcVLtwi : int := 0; attribute uUNwqfGkWt : Sequence := Sequence{}; attribute tiTmrXFOEx : OclAny := null; operation initialise() : nULqpVdQu pre: true post: true activity: self.wswwdNLvUF := 0 ; self.wkiJFbXuJi := Set{}->union((Set{})) ; self.nmBccRdNRt := 0 ; self.cwYbcVLtwi := 0 ; self.uUNwqfGkWt := Sequence{} ; self.tiTmrXFOEx := null; return self; } class btxcmdd { static operation newbtxcmdd() : btxcmdd pre: true post: btxcmdd->exists( _x | result = _x ); attribute jUfjZVIPqa : double := 0.0; operation initialise() : btxcmdd pre: true post: true activity: self.jUfjZVIPqa := 0.0; return self; operation M50(str1 : OclAny , str2 : OclAny) : OclAny pre: true post: true activity: if ((str1)->size() /= (str2)->size()) then ( return false ) else skip ; var clock_rot : String := "" ; var anticlock_rot : String := "" ; var l : int := (str2)->size() ; anticlock_rot := (anticlock_rot + str2.subrange(l - 2+1) + str2.subrange(0+1, l - 2)) ; clock_rot := clock_rot + str2.subrange(2+1) + str2.subrange(0+1, 2) ; return (str1 = clock_rot or str1 = anticlock_rot); } class hbhZaFI extends nULqpVdQu { static operation newhbhZaFI() : hbhZaFI pre: true post: hbhZaFI->exists( _x | result = _x ); attribute wswwdNLvUF : int := 0; attribute wkiJFbXuJi : Set := Set{}->union((Set{})); attribute nmBccRdNRt : int := 0; attribute cwYbcVLtwi : int := 0; attribute uUNwqfGkWt : Sequence := Sequence{}; attribute tiTmrXFOEx : OclAny := null; operation initialise() : btxcmdd pre: true post: true activity: self.wswwdNLvUF := 0 ; self.wkiJFbXuJi := Set{}->union((Set{})) ; self.nmBccRdNRt := 0 ; self.cwYbcVLtwi := 0 ; self.uUNwqfGkWt := Sequence{} ; self.tiTmrXFOEx := null; return self; operation M49(arr : OclAny , n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return true ) else skip ; var i : int := 1 ; for i : Integer.subrange(1, n-1) do ( if (arr[i - 1+1]->compareTo(arr[i+1])) < 0 then ( if (i = n) then ( return true ) else skip ) else skip) ; var j : int := i ; while ((arr[j+1]->compareTo(arr[j - 1+1])) < 0) do ( if (i > 1 & (arr[j+1]->compareTo(arr[i - 2+1])) < 0) then ( return false ) else skip ; j := j + 1) ; if (j = n) then ( return true ) else skip ; var k : int := j ; if ((arr[k+1]->compareTo(arr[i - 1+1])) < 0) then ( return false ) else skip ; while (k > 1 & (k->compareTo(n)) < 0) do ( if ((arr[k+1]->compareTo(arr[k - 1+1])) < 0) then ( return false ) else skip ; k := k + 1) ; return true; } class EfPIVepxh extends btxcmdd { static operation newEfPIVepxh() : EfPIVepxh pre: true post: EfPIVepxh->exists( _x | result = _x ); attribute xpsHidgdjJ : double := 0.0; attribute qIzQilHlCl : OclAny := null; attribute vLZoMXMDkt : Sequence := Sequence{}; operation initialise() : btxcmdd pre: true post: true activity: self.xpsHidgdjJ := 0.0 ; self.qIzQilHlCl := null ; self.vLZoMXMDkt := Sequence{}; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; execute (calcMaxValue("normal string"))->display(); operation calcMaxValue(s : String) : OclAny pre: true post: true activity: var res : double := (s->first())->char2byte() - 48 ; for i : Integer.subrange(1, (s)->size()-1) do ( if (s[i+1] = '0' or s[i+1] = '1' or res < 2) then ( res := res + (s[i+1])->char2byte() - 48 ) else ( res := res + (s[i+1])->char2byte() - 48 )) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import shutil class NMlExtraBQBA : def __init__(self): self.xgjFBbpinv = 0 self.tqMfAwUVKL = False self.cmmpBbsLVe = 0 self.jRFzCJOpxW = set({}) def M83(n): if(n<0): return 0; if(n<=1): return 1; digits=0; for i in range(2,n+1): digits+=math.log10(i); return math.floor(digits)+1; class iRZFozXBTkIZz : def __init__(self): self.jBbplvREkN = set({}) self.alhBergGxg = 0 self.ngXWGTaaag = "" self.yEyZcUzvxW = set({}) self.zItgSrTshp = None def M84(n): if(n<0): return 0; if(n<=1): return 1; x=((n*math.log10(n/math.e)+math.log10(2*math.pi*n)/2.0)); return math.floor(x)+1; class MjkAnOlluUht : def __init__(self): self.ikPtGIIvbI = 0.0 self.iSmiqZqkOa = 0.0 self.ozxkZnpAXL = "" self.biRUjvopZy = False self.oTBCxmPYHo = None class TWzJdV : def __init__(self): self.pCeBgdernt = False def Mjjjh85(n): res=0 x=0 while(x*xexists( _x | result = _x ); attribute xgjFBbpinv : int := 0; attribute tqMfAwUVKL : boolean := false; attribute cmmpBbsLVe : int := 0; attribute jRFzCJOpxW : Set := Set{}->union((Set{})); operation initialise() : NMlExtraBQBA pre: true post: true activity: self.xgjFBbpinv := 0 ; self.tqMfAwUVKL := false ; self.cmmpBbsLVe := 0 ; self.jRFzCJOpxW := Set{}->union((Set{})); return self; operation M83((def_parameters (def_parameter (named_parameter (name n))))) pre: true post: true activity: if (n < 0) then ( return 0; ) else skip ; if (n <= 1) then ( return 1; ) else skip ; var digits : int := 0; ; for i : Integer.subrange(2, n + 1-1) do ( digits := digits + (i)->log10();) ; return (digits)->floor() + 1;; } class iRZFozXBTkIZz { static operation newiRZFozXBTkIZz() : iRZFozXBTkIZz pre: true post: iRZFozXBTkIZz->exists( _x | result = _x ); attribute jBbplvREkN : Set := Set{}->union((Set{})); attribute alhBergGxg : int := 0; attribute ngXWGTaaag : String := ""; attribute yEyZcUzvxW : Set := Set{}->union((Set{})); attribute zItgSrTshp : OclAny := null; operation initialise() : iRZFozXBTkIZz pre: true post: true activity: self.jBbplvREkN := Set{}->union((Set{})) ; self.alhBergGxg := 0 ; self.ngXWGTaaag := "" ; self.yEyZcUzvxW := Set{}->union((Set{})) ; self.zItgSrTshp := null; return self; operation M84((def_parameters (def_parameter (named_parameter (name n))))) pre: true post: true activity: if (n < 0) then ( return 0; ) else skip ; if (n <= 1) then ( return 1; ) else skip ; var x : double := ((n * (n / )->log10() + (2 * * n)->log10() / 2.0)); ; return (x)->floor() + 1;; } class MjkAnOlluUht { static operation newMjkAnOlluUht() : MjkAnOlluUht pre: true post: MjkAnOlluUht->exists( _x | result = _x ); attribute ikPtGIIvbI : double := 0.0; attribute iSmiqZqkOa : double := 0.0; attribute ozxkZnpAXL : String := ""; attribute biRUjvopZy : boolean := false; attribute oTBCxmPYHo : OclAny := null; operation initialise() : MjkAnOlluUht pre: true post: true activity: self.ikPtGIIvbI := 0.0 ; self.iSmiqZqkOa := 0.0 ; self.ozxkZnpAXL := "" ; self.biRUjvopZy := false ; self.oTBCxmPYHo := null; return self; } class TWzJdV { static operation newTWzJdV() : TWzJdV pre: true post: TWzJdV->exists( _x | result = _x ); attribute pCeBgdernt : boolean := false; operation initialise() : TWzJdV pre: true post: true activity: self.pCeBgdernt := false; return self; operation Mjjjh85((def_parameters (def_parameter (named_parameter (name n))))) : OclAny pre: true post: true activity: var res : int := 0 ; x := 0 ; while ((x * x->compareTo(n)) < 0) do ( var y : int := 0 ; while ((x * x + y * y->compareTo(n)) < 0) do ( res := res + 1 ; y := y + 1) ; x := x + 1) ; return res; } class GrWUbx { static operation newGrWUbx() : GrWUbx pre: true post: GrWUbx->exists( _x | result = _x ); attribute xYFVuEzfPI : int := 0; attribute oEFsmODAwX : String := ""; attribute bksPEaVsXB : boolean := false; attribute sQGIvdwmSC : String := ""; attribute kBJwyQducZ : String := ""; attribute zKIoiimWkN : double := 0.0; operation initialise() : GrWUbx pre: true post: true activity: self.xYFVuEzfPI := 0 ; self.oEFsmODAwX := "" ; self.bksPEaVsXB := false ; self.sQGIvdwmSC := "" ; self.kBJwyQducZ := "" ; self.zKIoiimWkN := 0.0; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re import copy import math class rXboUeiytH : def __init__(self): self.nUUEsWe = 0 self.vhoTuY = 0.0 class kmcy : def __init__(self): self.jqjtRnAq = "" self.mrUJcIt = "" self.ymgNMqP = None def Mdsd_dsdsd(s): b_count=0 res=0 for i in range(len(s)): if s[~i]=='a': res=(res+b_count) b_count=(b_count*2) else: b_count+=1 return res class BZPHrNr : def __init__(self): self.hPXcFYk = set({}) self.gsOwhVF = 0 self.aRLrKKvm = "" self.uizxeRu = None def M116(arr,n,k): count=0 for i in range(0,n): for j in range(i+1,n): if arr[i]-arr[j]==k or arr[j]-arr[i]==k: count+=1 return count def M118(arr1,arr2,m,n,x): count=0 for i in range(m): for j in range(n): if arr1[i]+arr2[j]==x: count=count+1 return count class emGx : def __init__(self): self.wlVCPFK = 0.0 def M117(arr,n,k): count=0 arr.sort() l=0 r=0 while rk: l+=1 else: r+=1 return count class qPAcWJ : def __init__(self): self.qJUEEac = False self.ivLpDYTB = 0.0 self.upKxFdghJz = "" self.tYsxyGKSkl = "" self.vtaOUu = [] class KYWajGF : def __init__(self): self.nkzEhqK = set({}) self.elXngGf = set({}) self.iZJSX = set({}) self.ekJaAZ = set({}) def Mmmm(arr1,arr2,m,n,x): count=0 us=set() for i in range(m): us.add(arr1[i]) for j in range(n): if x-arr2[j] in us: count+=1 return count ------------------------------------------------------------ OCL File: --------- class rXboUeiytH { static operation newrXboUeiytH() : rXboUeiytH pre: true post: rXboUeiytH->exists( _x | result = _x ); attribute nUUEsWe : int := 0; attribute vhoTuY : double := 0.0; operation initialise() : rXboUeiytH pre: true post: true activity: self.nUUEsWe := 0 ; self.vhoTuY := 0.0; return self; } class kmcy { static operation newkmcy() : kmcy pre: true post: kmcy->exists( _x | result = _x ); attribute jqjtRnAq : String := ""; attribute mrUJcIt : String := ""; attribute ymgNMqP : OclAny := null; operation initialise() : kmcy pre: true post: true activity: self.jqjtRnAq := "" ; self.mrUJcIt := "" ; self.ymgNMqP := null; return self; operation Mdsd_dsdsd((def_parameters (def_parameter (named_parameter (name s))))) : OclAny pre: true post: true activity: var b_count : int := 0 ; var res : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[MathLib.bitwiseNot(i)+1] = 'a' then ( res := (res + b_count) ; b_count := (b_count * 2) ) else ( b_count := b_count + 1 )) ; return res; } class BZPHrNr { static operation newBZPHrNr() : BZPHrNr pre: true post: BZPHrNr->exists( _x | result = _x ); attribute hPXcFYk : Set := Set{}->union((Set{})); attribute gsOwhVF : int := 0; attribute aRLrKKvm : String := ""; attribute uizxeRu : OclAny := null; operation initialise() : BZPHrNr pre: true post: true activity: self.hPXcFYk := Set{}->union((Set{})) ; self.gsOwhVF := 0 ; self.aRLrKKvm := "" ; self.uizxeRu := null; return self; operation M116(arr : OclAny , n : OclAny,k : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if arr[i+1] - arr[j+1] = k or arr[j+1] - arr[i+1] = k then ( count := count + 1 ) else skip)) ; return count; operation M118(arr1 : OclAny , arr2 : OclAny,m : OclAny,n : OclAny,x : OclAny) : OclAny pre: true post: true activity: count := 0 ; for i : Integer.subrange(0, m-1) do ( for j : Integer.subrange(0, n-1) do ( if arr1[i+1] + arr2[j+1] = x then ( count := count + 1 ) else skip)) ; return count; } class emGx { static operation newemGx() : emGx pre: true post: emGx->exists( _x | result = _x ); attribute wlVCPFK : double := 0.0; operation initialise() : emGx pre: true post: true activity: self.wlVCPFK := 0.0; return self; operation M117(arr : OclAny , n : OclAny,k : OclAny) : OclAny pre: true post: true activity: count := 0 ; arr := arr->sort() ; var l : int := 0 ; var r : int := 0 ; while (r->compareTo(n)) < 0 do ( if arr[r+1] - arr[l+1] = k then ( count := count + 1 ; l := l + 1 ; r := r + 1 ) else (if (arr[r+1] - arr[l+1]->compareTo(k)) > 0 then ( l := l + 1 ) else ( r := r + 1 ) ) ) ; return count; } class qPAcWJ { static operation newqPAcWJ() : qPAcWJ pre: true post: qPAcWJ->exists( _x | result = _x ); attribute qJUEEac : boolean := false; attribute ivLpDYTB : double := 0.0; attribute upKxFdghJz : String := ""; attribute tYsxyGKSkl : String := ""; attribute vtaOUu : Sequence := Sequence{}; operation initialise() : qPAcWJ pre: true post: true activity: self.qJUEEac := false ; self.ivLpDYTB := 0.0 ; self.upKxFdghJz := "" ; self.tYsxyGKSkl := "" ; self.vtaOUu := Sequence{}; return self; } class KYWajGF { static operation newKYWajGF() : KYWajGF pre: true post: KYWajGF->exists( _x | result = _x ); attribute nkzEhqK : Set := Set{}->union((Set{})); attribute elXngGf : Set := Set{}->union((Set{})); attribute iZJSX : Set := Set{}->union((Set{})); attribute ekJaAZ : Set := Set{}->union((Set{})); operation initialise() : KYWajGF pre: true post: true activity: self.nkzEhqK := Set{}->union((Set{})) ; self.elXngGf := Set{}->union((Set{})) ; self.iZJSX := Set{}->union((Set{})) ; self.ekJaAZ := Set{}->union((Set{})); return self; operation Mmmm(arr1 : OclAny , arr2 : OclAny,m : OclAny,n : OclAny,x : OclAny) : OclAny pre: true post: true activity: count := 0 ; var us : Set := Set{}->union(()) ; for i : Integer.subrange(0, m-1) do ( execute ((arr1[i+1]) : us)) ; for j : Integer.subrange(0, n-1) do ( if (us)->includes(x - arr2[j+1]) then ( count := count + 1 ) else skip) ; return count; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def foo(x) : return bar(x) + 1 def area(r) : return 2 * PI * r ** 2 class xrIA : def __init__(self): self.tweIVlvLnQ = [] def M154(n): if (n==0): return "0" bin="" while (n>0): if (n&1==0): bin='0'+bin else: bin='1'+bin n=n>>1 return bin class UcHCjB(xrIA) : def __init__(self): self.weCiEVltcM = [] self.tweIVlvLnQ = [] def M155(bin): n=len(bin) if (bin[n-1]=='1'): return False sum=0 i=n-2 while i>=0: if (bin[i]=='1'): posFromRight=n-i-1 if (posFromRight%4==1): sum=sum+2 elif (posFromRight%4==2): sum=sum+4 elif (posFromRight%4==3): sum=sum+8 elif (posFromRight%4==0): sum=sum+6 i=i-1 if (sum%10==0): return True return False class SiOcFJTYFlT : def __init__(self): self.fILIAXCqmP = "" self.yyzCIUbiiV = [] self.seeSRKFuEs = 0 self.vIMvswk = [] self.vgbiuCSwYe = [] self.yApiwupfgv = 0 self.hkoMMtSHwd = set({}) self.mItAoIiIQJ = 0.0 class UsqJCAS(UcHCjB) : def __init__(self): self.aekNNw = False self.amEhhgYOYE = [] self.hEEpKJ = "" self.hzhfXjvZtF = False self.jdogYGERde = 0 self.abjjPo = 0.0 self.weCiEVltcM = [] self.tweIVl = [] def M156(s): l=len(s) s1="" if (l%2==0): isEven=True else: isEven=False for i in range(0,l,2): if (isEven): s1=s[i]+s1 s1+=s[i+1] else: if (l-i>1): s1+=s[i] s1=s[i+1]+s1 else: s1+=s[i] return s1 class rcZuWGoIOz : def __init__(self): self.eaMKqPn = False self.eizSFmVSFX = 0 self.qfAWwOT = set({}) self.fEXKxOCyvN = False self.dGDqcAdCfu = 0 class CJrHFTSRasusK : def __init__(self): self.poSoxrDqCS = set({}) def M157(x,y): return ((x^y)<0) def M158(m,n): for i in range(0,n): sum=0 for j in range(0,n): sum=sum+abs(m[i][j]) sum=sum-abs(m[i][i]) if (abs(m[i][i])exists( _x | result = _x ); attribute tweIVlvLnQ : Sequence := Sequence{}; operation initialise() : xrIA pre: true post: true activity: self.tweIVlvLnQ := Sequence{}; return self; operation M154((def_parameters (def_parameter (named_parameter (name n))))) : OclAny pre: true post: true activity: if (n = 0) then ( return "0" ) else skip ; var bin : String := "" ; while (n > 0) do ( if (MathLib.bitwiseAnd(n, 1) = 0) then ( bin := '0' + bin ) else ( bin := '1' + bin ) ; n := n /(2->pow(1))) ; return bin; } class UcHCjB extends xrIA { static operation newUcHCjB() : UcHCjB pre: true post: UcHCjB->exists( _x | result = _x ); attribute weCiEVltcM : Sequence := Sequence{}; attribute tweIVlvLnQ : Sequence := Sequence{}; operation initialise() : xrIA pre: true post: true activity: self.weCiEVltcM := Sequence{} ; self.tweIVlvLnQ := Sequence{}; return self; operation M155((def_parameters (def_parameter (named_parameter (name bin))))) : OclAny pre: true post: true activity: n := (bin)->size() ; if (bin[n - 1+1] = '1') then ( return false ) else skip ; var sum : int := 0 ; var i : double := n - 2 ; while i >= 0 do ( if (bin[i+1] = '1') then ( var posFromRight : double := n - i - 1 ; if (posFromRight mod 4 = 1) then ( sum := sum + 2 ) else (if (posFromRight mod 4 = 2) then ( sum := sum + 4 ) else (if (posFromRight mod 4 = 3) then ( sum := sum + 8 ) else (if (posFromRight mod 4 = 0) then ( sum := sum + 6 ) else skip ) ) ) ) else skip ; i := i - 1) ; if (sum mod 10 = 0) then ( return true ) else skip ; return false; } class SiOcFJTYFlT { static operation newSiOcFJTYFlT() : SiOcFJTYFlT pre: true post: SiOcFJTYFlT->exists( _x | result = _x ); attribute fILIAXCqmP : String := ""; attribute yyzCIUbiiV : Sequence := Sequence{}; attribute seeSRKFuEs : int := 0; attribute vIMvswk : Sequence := Sequence{}; attribute vgbiuCSwYe : Sequence := Sequence{}; attribute yApiwupfgv : int := 0; attribute hkoMMtSHwd : Set := Set{}->union((Set{})); attribute mItAoIiIQJ : double := 0.0; operation initialise() : SiOcFJTYFlT pre: true post: true activity: self.fILIAXCqmP := "" ; self.yyzCIUbiiV := Sequence{} ; self.seeSRKFuEs := 0 ; self.vIMvswk := Sequence{} ; self.vgbiuCSwYe := Sequence{} ; self.yApiwupfgv := 0 ; self.hkoMMtSHwd := Set{}->union((Set{})) ; self.mItAoIiIQJ := 0.0; return self; } class UsqJCAS extends UcHCjB { static operation newUsqJCAS() : UsqJCAS pre: true post: UsqJCAS->exists( _x | result = _x ); attribute aekNNw : boolean := false; attribute amEhhgYOYE : Sequence := Sequence{}; attribute hEEpKJ : String := ""; attribute hzhfXjvZtF : boolean := false; attribute jdogYGERde : int := 0; attribute abjjPo : double := 0.0; attribute weCiEVltcM : Sequence := Sequence{}; attribute tweIVl : Sequence := Sequence{}; operation initialise() : SiOcFJTYFlT pre: true post: true activity: self.aekNNw := false ; self.amEhhgYOYE := Sequence{} ; self.hEEpKJ := "" ; self.hzhfXjvZtF := false ; self.jdogYGERde := 0 ; self.abjjPo := 0.0 ; self.weCiEVltcM := Sequence{} ; self.tweIVl := Sequence{}; return self; operation M156((def_parameters (def_parameter (named_parameter (name s))))) : OclAny pre: true post: true activity: var l : int := (s)->size() ; var s1 : String := "" ; if (l mod 2 = 0) then ( var isEven : boolean := true ) else ( isEven := false ) ; for i : Integer.subrange(0, l-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( if (isEven) then ( s1 := s[i+1] + s1 ; s1 := s1 + s[i + 1+1] ) else ( if (l - i > 1) then ( s1 := s1 + s[i+1] ; s1 := s[i + 1+1] + s1 ) else ( s1 := s1 + s[i+1] ) )) ; return s1; } class rcZuWGoIOz { static operation newrcZuWGoIOz() : rcZuWGoIOz pre: true post: rcZuWGoIOz->exists( _x | result = _x ); attribute eaMKqPn : boolean := false; attribute eizSFmVSFX : int := 0; attribute qfAWwOT : Set := Set{}->union((Set{})); attribute fEXKxOCyvN : boolean := false; attribute dGDqcAdCfu : int := 0; operation initialise() : rcZuWGoIOz pre: true post: true activity: self.eaMKqPn := false ; self.eizSFmVSFX := 0 ; self.qfAWwOT := Set{}->union((Set{})) ; self.fEXKxOCyvN := false ; self.dGDqcAdCfu := 0; return self; } class CJrHFTSRasusK { static operation newCJrHFTSRasusK() : CJrHFTSRasusK pre: true post: CJrHFTSRasusK->exists( _x | result = _x ); attribute poSoxrDqCS : Set := Set{}->union((Set{})); operation initialise() : CJrHFTSRasusK pre: true post: true activity: self.poSoxrDqCS := Set{}->union((Set{})); return self; operation M157(x : OclAny , y : OclAny) : OclAny pre: true post: true activity: return ((MathLib.bitwiseXor(x, y)) < 0); operation M158(m : OclAny , n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( sum := 0 ; for j : Integer.subrange(0, n-1) do ( sum := sum + (m[i+1][j+1])->abs()) ; sum := sum - (m[i+1][i+1])->abs() ; if (((m[i+1][i+1])->abs()->compareTo(sum)) < 0) then ( return false ) else skip) ; return true; } class ooGwCouy { static operation newooGwCouy() : ooGwCouy pre: true post: ooGwCouy->exists( _x | result = _x ); attribute gOecMt : int := 0; attribute yMmhkjwthh : Sequence := Sequence{}; attribute aGHXLItCCB : boolean := false; attribute xGSEtvUGxB : double := 0.0; attribute hmizRtm : int := 0; operation initialise() : ooGwCouy pre: true post: true activity: self.gOecMt := 0 ; self.yMmhkjwthh := Sequence{} ; self.aGHXLItCCB := false ; self.xGSEtvUGxB := 0.0 ; self.hmizRtm := 0; return self; operation M159(m : OclAny , n : OclAny,x : OclAny) : OclAny pre: true post: true activity: var table : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (x + 1)))) ; for j : Integer.subrange(1, Set{m + 1, x + 1}->min()-1) do ( table[1+1][j+1] := 1) ; for i : Integer.subrange(2, n + 1-1) do ( for j : Integer.subrange(1, x + 1-1) do ( for k : Integer.subrange(1, Set{m + 1, j}->min()-1) do ( table[i+1][j+1] := table[i+1][j+1] + table[i - 1+1][j - k+1]))) ; return table->last()->last(); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip; operation foo(x : OclAny) : OclAny pre: true post: true activity: return bar(x) + 1; operation area(r : OclAny) : OclAny pre: true post: true activity: return 2 * PI * (r)->pow(2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class mkSXLfqvt : def __init__(self): self.qDnsatzz = 0 def M194(A,arr_size,sum): for i in range(0,arr_size-1): s=set() curr_sum=sum-A[i] for j in range(i+1,arr_size): if(curr_sum-A[j]) in s: print("Triplet is",A[i],",",A[j],",",curr_sum-A[j]) return True s.add(A[j]) return False def M195(arr,n): d1=0 d2=0 for i in range(0,n): for j in range(0,n): if(i==j): d1+=arr[i][j] if(i==n-j-1): d2+=arr[i][j] return abs(d1-d2) class AqBnBhu : def __init__(self): self.mtXfPu = "" self.uDpdhpROrT = 0 self.fzPFFk = 0.0 self.yqZVPtenju = False self.ovUlo = [] def M193(A,arr_size,sum): A.sort() for i in range(0,arr_size-2): l=i+1 r=arr_size-1 while(lexists( _x | result = _x ); attribute qDnsatzz : int := 0; operation initialise() : mkSXLfqvt pre: true post: true activity: self.qDnsatzz := 0; return self; operation M194(A : OclAny , arr_size : OclAny,sum : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, arr_size - 1-1) do ( var s : Set := Set{}->union(()) ; var curr_sum : double := sum - A[i+1] ; for j : Integer.subrange(i + 1, arr_size-1) do ( if (s)->includes((curr_sum - A[j+1])) then ( execute ("Triplet is")->display() ; return true ) else skip ; execute ((A[j+1]) : s))) ; return false; operation M195(arr : OclAny , n : OclAny) : OclAny pre: true post: true activity: var d1 : int := 0 ; var d2 : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if (i = j) then ( d1 := d1 + arr[i+1][j+1] ) else skip ; if (i = n - j - 1) then ( d2 := d2 + arr[i+1][j+1] ) else skip)) ; return (d1 - d2)->abs(); } class AqBnBhu { static operation newAqBnBhu() : AqBnBhu pre: true post: AqBnBhu->exists( _x | result = _x ); attribute mtXfPu : String := ""; attribute uDpdhpROrT : int := 0; attribute fzPFFk : double := 0.0; attribute yqZVPtenju : boolean := false; attribute ovUlo : Sequence := Sequence{}; operation initialise() : AqBnBhu pre: true post: true activity: self.mtXfPu := "" ; self.uDpdhpROrT := 0 ; self.fzPFFk := 0.0 ; self.yqZVPtenju := false ; self.ovUlo := Sequence{}; return self; operation M193(A : OclAny , arr_size : OclAny,sum : OclAny) : OclAny pre: true post: true activity: A := A->sort() ; for i : Integer.subrange(0, arr_size - 2-1) do ( var l : OclAny := i + 1 ; var r : double := arr_size - 1 ; while ((l->compareTo(r)) < 0) do ( if (A[i+1] + A[l+1] + A[r+1] = sum) then ( execute ("Triplet is")->display() ; return true ) else (if ((A[i+1] + A[l+1] + A[r+1]->compareTo(sum)) < 0) then ( l := l + 1 ) else ( r := r - 1 ) ) )) ; return false; } class uOeOSybqCxRoe { static operation newuOeOSybqCxRoe() : uOeOSybqCxRoe pre: true post: uOeOSybqCxRoe->exists( _x | result = _x ); attribute bvSkR : double := 0.0; attribute qTZfadsNsr : boolean := false; attribute bKTC : int := 0; attribute yGgbKcF : Set := Set{}->union((Set{})); operation initialise() : uOeOSybqCxRoe pre: true post: true activity: self.bvSkR := 0.0 ; self.qTZfadsNsr := false ; self.bKTC := 0 ; self.yGgbKcF := Set{}->union((Set{})); return self; } class iWxHft extends uOeOSybqCxRoe { static operation newiWxHft() : iWxHft pre: true post: iWxHft->exists( _x | result = _x ); attribute uJFxWq : boolean := false; attribute qrKMYDGMKK : double := 0.0; attribute xWPuomM : String := ""; attribute xPbATYdQpu : boolean := false; attribute pcazDyn : int := 0; attribute xWDbioMZol : String := ""; attribute nLYsLdy : Set := Set{}->union((Set{})); attribute uSLlGBrvxh : Set := Set{}->union((Set{})); attribute SkR : double := 0.0; attribute qTZfadsNsr : boolean := false; attribute yKcF : Set := Set{}->union((Set{})); operation initialise() : uOeOSybqCxRoe pre: true post: true activity: self.uJFxWq := false ; self.qrKMYDGMKK := 0.0 ; self.xWPuomM := "" ; self.xPbATYdQpu := false ; self.pcazDyn := 0 ; self.xWDbioMZol := "" ; self.nLYsLdy := Set{}->union((Set{})) ; self.uSLlGBrvxh := Set{}->union((Set{})) ; self.SkR := 0.0 ; self.qTZfadsNsr := false ; self.yKcF := Set{}->union((Set{})); return self; } class ycLaaT { static operation newycLaaT() : ycLaaT pre: true post: ycLaaT->exists( _x | result = _x ); attribute baiKTC : int := 0; operation initialise() : ycLaaT pre: true post: true activity: self.baiKTC := 0; return self; operation M192(A : OclAny , arr_size : OclAny,sum : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, arr_size - 2-1) do ( for j : Integer.subrange(i + 1, arr_size - 1-1) do ( for k : Integer.subrange(j + 1, arr_size-1) do ( if A[i+1] + A[j+1] + A[k+1] = sum then ( execute ("Triplet is")->display() ; return true ) else skip))) ; return false; } class QFNv extends AqBnBhu { static operation newQFNv() : QFNv pre: true post: QFNv->exists( _x | result = _x ); attribute gZzFWP : int := 0; attribute yWMGytw : double := 0.0; attribute zKCXbkYhYR : int := 0; attribute uvaAWky : OclAny := null; attribute mtXpfPu : String := ""; attribute uDpdhpROrT : int := 0; attribute fzvFFk : double := 0.0; attribute yqenju : boolean := false; attribute ovUIFlo : Sequence := Sequence{}; operation initialise() : ycLaaT pre: true post: true activity: self.gZzFWP := 0 ; self.yWMGytw := 0.0 ; self.zKCXbkYhYR := 0 ; self.uvaAWky := null ; self.mtXpfPu := "" ; self.uDpdhpROrT := 0 ; self.fzvFFk := 0.0 ; self.yqenju := false ; self.ovUIFlo := Sequence{}; return self; operation M191(arr : OclAny , n : OclAny) : OclAny pre: true post: true activity: var brr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * n + 1)) ; for i : Integer.subrange(0, n-1) do ( brr[i+1] := arr[i+1]) ; for i : Integer.subrange(0, n-1) do ( brr[n + i+1] := arr[i+1]) ; var maxHam : int := 0 ; for i : Integer.subrange(1, n-1) do ( var currHam : int := 0 ; var k : int := 0 ; for j : Integer.subrange(i, i + n-1) do ( if brr[j+1] /= arr[k+1] then ( currHam := currHam + 1 ; k := k + 1 ) else skip) ; if currHam = n then ( return n ) else skip ; maxHam := Set{maxHam, currHam}->max()) ; return maxHam; } class gbDHiDeizr { static operation newgbDHiDeizr() : gbDHiDeizr pre: true post: gbDHiDeizr->exists( _x | result = _x ); attribute rzZdcj : double := 0.0; attribute gqVBzdRFhu : double := 0.0; attribute vTmgjRE : Sequence := Sequence{}; attribute rKhpttr : boolean := false; attribute cmWtQRpnQx : Sequence := Sequence{}; attribute dYnDNFY : boolean := false; attribute dpUPcsjogI : Set := Set{}->union((Set{})); operation initialise() : gbDHiDeizr pre: true post: true activity: self.rzZdcj := 0.0 ; self.gqVBzdRFhu := 0.0 ; self.vTmgjRE := Sequence{} ; self.rKhpttr := false ; self.cmWtQRpnQx := Sequence{} ; self.dYnDNFY := false ; self.dpUPcsjogI := Set{}->union((Set{})); return self; } class WcBNItEdvaPf extends QFNv { static operation newWcBNItEdvaPf() : WcBNItEdvaPf pre: true post: WcBNItEdvaPf->exists( _x | result = _x ); attribute mPVd : Sequence := Sequence{}; attribute zQOsmmz : OclAny := null; operation initialise() : gbDHiDeizr pre: true post: true activity: self.mPVd := Sequence{} ; self.zQOsmmz := null; return self; operation M190(arr : OclAny , n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if arr[i+1] <>= i then ( return i ) else skip) ; return -1; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import ocl from ocldatasource import * import math from enum import Enum class vDXsH : def __init__(self): self.KIlcEvTmaDf = 937.90 self.fANdApYXj = 491 self.cIob = 468 self.GNQzXVDHaX = 317 def M240(n): if(n%2!=0): return 0 res=1 for i in range(2,int(math.sqrt(n))+1): count=0 curr_sum=1 curr_term=1 while(n%i==0): count=count+1 n=n//i if(i==2 and count==1): curr_sum=0 curr_term=curr_term*i curr_sum=curr_sum+curr_term res=res*curr_sum if(n>=2): res=res*(1+n) return res class btaEVa : def __init__(self): self.YnMP = 200.584 self.TzSYyYOHb = "" self.avahGZ = 293 self.fqeDmaH = 64.467 self.RoaP = "sqprSaxjO" self.MFPBypEXG = set({}) self.tCYtkQ = False self.ZsDXY = None def M239(arr,n,sum): curr_sum=arr[0] start=0 i=1 while i<=n: while curr_sum>sum and startsum or j==n: break curr_sum=curr_sum+arr[j] j+=1 print("No subarray found") return 0 class pHjka : def __init__(self): self.qyPkto = "" self.ysj = set({}) self.RGha = False self.ihoU = "elraBBpeb" self.VjrQm = set({}) self.DnZhStdBF = 83 self.hThk = set({}) self.enahD = set({}) self.sDxFBq = [] class rICLqJQE : def __init__(self): self.BiuMwr = "f" self.cPvuqgaTyVf = set({}) self.xmCcej = 439.43 self.lthHeznsC = False self.VjrJgKlcO = 267 self.Cgl = 155 self.yMPB = False self.vjiyAWOsTSc = "XTzj" self.LGyMJ = True def M237(arr,n): res=1 for i in range(0,n): if arr[i]<=res: res=res+arr[i] else: break return res class vbWHXipHkAoM : def __init__(self): self.bBbHKuRRnO = 349 self.FPOz = set({}) self.uOnqm = 408 self.uscUW = [] self.jQGFlF = 718 self.CNEzmaaoGN = set({}) self.xbBQVqifXFh = [] self.SJvzeAi = None class fSzqOxWskQKFY : def __init__(self): self.ifNP = 776 self.gcqXM = [] self.wgilwV = set({}) self.MfwGEZhA = False self.BMvKyvV = "" self.DEDRgoOaxrs = set({}) self.hlKaZMncrdz = 451 self.QmERrt = [] self.OQugjsTwhFF = None class poVah(fSzqOxWskQKFY) : def __init__(self): self.UmqhY = True self.Vnuiq = 263 self.KxxtZXBohe = 423 self.sXlNo = 987 self.ksmFGUckqUW = 65 self.OvQyMRiCV = None class VsTnDiSjhi(fSzqOxWskQKFY) : def __init__(self): self.wFz = "yDpkmpf" self.JsB = set({}) self.qjrlhEmBX = 805 def M236(arr,low,high): if(highlow and arr[mid]arr[mid]): return M236(arr,low,mid-1); return M236(arr,mid+1,high) ------------------------------------------------------------ OCL File: --------- class vDXsH { static operation newvDXsH() : vDXsH pre: true post: vDXsH->exists( _x | result = _x ); attribute KIlcEvTmaDf : double := 937.90; attribute fANdApYXj : int := 491; attribute cIob : int := 468; attribute GNQzXVDHaX : int := 317; operation initialise() : vDXsH pre: true post: true activity: self.KIlcEvTmaDf := 937.90 ; self.fANdApYXj := 491 ; self.cIob := 468 ; self.GNQzXVDHaX := 317; return self; operation M240((def_parameters (def_parameter (named_parameter (name n))))) : OclAny pre: true post: true activity: if (n mod 2 /= 0) then ( return 0 ) else skip ; var res : int := 1 ; for i : Integer.subrange(2, ("" + (((n)->sqrt())))->toInteger() + 1-1) do ( var count : int := 0 ; var curr_sum : int := 1 ; var curr_term : int := 1 ; while (n mod i = 0) do ( count := count + 1 ; n := n div i ; if (i = 2 & count = 1) then ( curr_sum := 0 ) else skip ; curr_term := curr_term * i ; curr_sum := curr_sum + curr_term) ; res := res * curr_sum) ; if (n >= 2) then ( res := res * (1 + n) ) else skip ; return res; } class btaEVa { static operation newbtaEVa() : btaEVa pre: true post: btaEVa->exists( _x | result = _x ); attribute YnMP : double := 200.584; attribute TzSYyYOHb : String := ""; attribute avahGZ : int := 293; attribute fqeDmaH : double := 64.467; attribute RoaP : String := "sqprSaxjO"; attribute MFPBypEXG : Set := Set{}->union((Set{})); attribute tCYtkQ : boolean := false; attribute ZsDXY : OclAny := null; operation initialise() : btaEVa pre: true post: true activity: self.YnMP := 200.584 ; self.TzSYyYOHb := "" ; self.avahGZ := 293 ; self.fqeDmaH := 64.467 ; self.RoaP := "sqprSaxjO" ; self.MFPBypEXG := Set{}->union((Set{})) ; self.tCYtkQ := false ; self.ZsDXY := null; return self; operation M239(arr : OclAny , n : OclAny,sum : OclAny) : OclAny pre: true post: true activity: curr_sum := arr->first() ; var start : int := 0 ; var i : int := 1 ; while (i->compareTo(n)) <= 0 do ( while (curr_sum->compareTo(sum)) > 0 & (start->compareTo(i - 1)) < 0 do ( curr_sum := curr_sum - arr[start+1] ; start := start + 1) ; if curr_sum = sum then ( execute ("Sum found between indexes")->display() ; execute (StringLib.format("%d and %d",Sequence{start, i - 1}))->display() ; return 1 ) else skip ; if (i->compareTo(n)) < 0 then ( curr_sum := curr_sum + arr[i+1] ) else skip ; i := i + 1) ; execute ("No subarray found")->display() ; return 0; } class txbie { static operation newtxbie() : txbie pre: true post: txbie->exists( _x | result = _x ); attribute fUKKlGKQRFB : OclAny := null; operation initialise() : txbie pre: true post: true activity: self.fUKKlGKQRFB := null; return self; operation M238(arr : OclAny , n : OclAny,sum : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( curr_sum := arr[i+1] ; var j : int := i + 1 ; while (j->compareTo(n)) <= 0 do ( if curr_sum = sum then ( execute ("Sum found between")->display() ; execute (StringLib.format("indexes %d and %d",Sequence{i, j - 1}))->display() ; return 1 ) else skip ; if (curr_sum->compareTo(sum)) > 0 or j = n then ( break ) else skip ; curr_sum := curr_sum + arr[j+1] ; j := j + 1)) ; execute ("No subarray found")->display() ; return 0; } class pHjka { static operation newpHjka() : pHjka pre: true post: pHjka->exists( _x | result = _x ); attribute qyPkto : String := ""; attribute ysj : Set := Set{}->union((Set{})); attribute RGha : boolean := false; attribute ihoU : String := "elraBBpeb"; attribute VjrQm : Set := Set{}->union((Set{})); attribute DnZhStdBF : int := 83; attribute hThk : Set := Set{}->union((Set{})); attribute enahD : Set := Set{}->union((Set{})); attribute sDxFBq : Sequence := Sequence{}; operation initialise() : pHjka pre: true post: true activity: self.qyPkto := "" ; self.ysj := Set{}->union((Set{})) ; self.RGha := false ; self.ihoU := "elraBBpeb" ; self.VjrQm := Set{}->union((Set{})) ; self.DnZhStdBF := 83 ; self.hThk := Set{}->union((Set{})) ; self.enahD := Set{}->union((Set{})) ; self.sDxFBq := Sequence{}; return self; } class rICLqJQE { static operation newrICLqJQE() : rICLqJQE pre: true post: rICLqJQE->exists( _x | result = _x ); attribute BiuMwr : String := "f"; attribute cPvuqgaTyVf : Set := Set{}->union((Set{})); attribute xmCcej : double := 439.43; attribute lthHeznsC : boolean := false; attribute VjrJgKlcO : int := 267; attribute Cgl : int := 155; attribute yMPB : boolean := false; attribute vjiyAWOsTSc : String := "XTzj"; attribute LGyMJ : boolean := true; operation initialise() : rICLqJQE pre: true post: true activity: self.BiuMwr := "f" ; self.cPvuqgaTyVf := Set{}->union((Set{})) ; self.xmCcej := 439.43 ; self.lthHeznsC := false ; self.VjrJgKlcO := 267 ; self.Cgl := 155 ; self.yMPB := false ; self.vjiyAWOsTSc := "XTzj" ; self.LGyMJ := true; return self; operation M237(arr : OclAny , n : OclAny) : OclAny pre: true post: true activity: res := 1 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1]->compareTo(res)) <= 0 then ( res := res + arr[i+1] ) else ( break )) ; return res; } class vbWHXipHkAoM { static operation newvbWHXipHkAoM() : vbWHXipHkAoM pre: true post: vbWHXipHkAoM->exists( _x | result = _x ); attribute bBbHKuRRnO : int := 349; attribute FPOz : Set := Set{}->union((Set{})); attribute uOnqm : int := 408; attribute uscUW : Sequence := Sequence{}; attribute jQGFlF : int := 718; attribute CNEzmaaoGN : Set := Set{}->union((Set{})); attribute xbBQVqifXFh : Sequence := Sequence{}; attribute SJvzeAi : OclAny := null; operation initialise() : vbWHXipHkAoM pre: true post: true activity: self.bBbHKuRRnO := 349 ; self.FPOz := Set{}->union((Set{})) ; self.uOnqm := 408 ; self.uscUW := Sequence{} ; self.jQGFlF := 718 ; self.CNEzmaaoGN := Set{}->union((Set{})) ; self.xbBQVqifXFh := Sequence{} ; self.SJvzeAi := null; return self; } class fSzqOxWskQKFY { static operation newfSzqOxWskQKFY() : fSzqOxWskQKFY pre: true post: fSzqOxWskQKFY->exists( _x | result = _x ); attribute ifNP : int := 776; attribute gcqXM : Sequence := Sequence{}; attribute wgilwV : Set := Set{}->union((Set{})); attribute MfwGEZhA : boolean := false; attribute BMvKyvV : String := ""; attribute DEDRgoOaxrs : Set := Set{}->union((Set{})); attribute hlKaZMncrdz : int := 451; attribute QmERrt : Sequence := Sequence{}; attribute OQugjsTwhFF : OclAny := null; operation initialise() : fSzqOxWskQKFY pre: true post: true activity: self.ifNP := 776 ; self.gcqXM := Sequence{} ; self.wgilwV := Set{}->union((Set{})) ; self.MfwGEZhA := false ; self.BMvKyvV := "" ; self.DEDRgoOaxrs := Set{}->union((Set{})) ; self.hlKaZMncrdz := 451 ; self.QmERrt := Sequence{} ; self.OQugjsTwhFF := null; return self; } class poVah extends fSzqOxWskQKFY { static operation newpoVah() : poVah pre: true post: poVah->exists( _x | result = _x ); attribute UmqhY : boolean := true; attribute Vnuiq : int := 263; attribute KxxtZXBohe : int := 423; attribute sXlNo : int := 987; attribute ksmFGUckqUW : int := 65; attribute OvQyMRiCV : OclAny := null; operation initialise() : fSzqOxWskQKFY pre: true post: true activity: self.UmqhY := true ; self.Vnuiq := 263 ; self.KxxtZXBohe := 423 ; self.sXlNo := 987 ; self.ksmFGUckqUW := 65 ; self.OvQyMRiCV := null; return self; } class VsTnDiSjhi extends fSzqOxWskQKFY { static operation newVsTnDiSjhi() : VsTnDiSjhi pre: true post: VsTnDiSjhi->exists( _x | result = _x ); attribute wFz : String := "yDpkmpf"; attribute JsB : Set := Set{}->union((Set{})); attribute qjrlhEmBX : int := 805; operation initialise() : fSzqOxWskQKFY pre: true post: true activity: self.wFz := "yDpkmpf" ; self.JsB := Set{}->union((Set{})) ; self.qjrlhEmBX := 805; return self; operation M236(arr : OclAny , low : OclAny,high : OclAny) : OclAny pre: true post: true activity: if ((high->compareTo(low)) < 0) then ( return 0 ) else skip ; if (high = low) then ( return low ) else skip ; var mid : OclAny := low + (high - low) / 2; ; mid := ("" + ((mid)))->toInteger() ; if ((mid->compareTo(high)) < 0 & (arr[mid + 1+1]->compareTo(arr[mid+1])) < 0) then ( return (mid + 1) ) else skip ; if ((mid->compareTo(low)) > 0 & (arr[mid+1]->compareTo(arr[mid - 1+1])) < 0) then ( return mid ) else skip ; if ((arr[high+1]->compareTo(arr[mid+1])) > 0) then ( return M236(arr, low, mid - 1); ) else skip ; return M236(arr, mid + 1, high); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- is_active: bool is_active = True max_value: int = 500 min_value: int = 10 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var is_active : boolean ; is_active := true ; var max_value : int := 500 ; var min_value : int := 10; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import asyncio async def greet(index): print("operation " + str(index) + " initiated") await asyncio.sleep(2) print("operation " + str(index) + " completed") async def execute_tasks(): operation1 = asyncio.create_task(greet(3)) await asyncio.sleep(1) operation2 = asyncio.create_task(greet(4)) await operation1 await operation2 asyncio.run(execute_tasks()) ------------------------------------------------------------ OCL File: --------- class Async$greet { stereotype active; attribute index : OclAny; static operation newAsync$greet(index : OclAny) : Async$greet pre: true post: Async$greet->exists( resx | resx.index = index & result = resx ); operation run() pre: true post: true activity: execute ("operation " + ("" + ((index))) + " initiated")->display() ; OclProcess.sleepSeconds(2) ; execute ("operation " + ("" + ((index))) + " completed")->display(); } class Async$execute_tasks { stereotype active; static operation newAsync$execute_tasks() : Async$execute_tasks pre: true post: Async$execute_tasks->exists( resx | result = resx ); operation run() pre: true post: true activity: var operation1 : OclProcess := (OclProcess.newOclProcess(Async$greet.newAsync$greet(3), "")).startProcess() ; OclProcess.sleepSeconds(1) ; var operation2 : OclProcess := (OclProcess.newOclProcess(Async$greet.newAsync$greet(4), "")).startProcess() ; operation1.join() ; operation2.join(); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; (OclProcess.newOclProcess(Async$execute_tasks.newAsync$execute_tasks(), "")).start(); operation greet(index : OclAny) pre: true post: true activity: execute ("operation " + ("" + ((index))) + " initiated")->display() ; OclProcess.sleepSeconds(2) ; execute ("operation " + ("" + ((index))) + " completed")->display(); operation execute_tasks() pre: true post: true activity: var operation1 : OclProcess := (OclProcess.newOclProcess(Async$greet.newAsync$greet(3), "")).startProcess() ; OclProcess.sleepSeconds(1) ; var operation2 : OclProcess := (OclProcess.newOclProcess(Async$greet.newAsync$greet(4), "")).startProcess() ; operation1.join() ; operation2.join(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- data = [7, 8, 9] list_combined = [0, *data, 10] print(list_combined) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var data : Sequence := Sequence{7}->union(Sequence{8}->union(Sequence{ 9 })) ; var list_combined : Sequence := Sequence{0}->union(data->union(Sequence{ 10 })) ; execute (list_combined)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- items = [6, 7, 8,77,98,45,12] squares = [i * i for i in items] print(squares) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var items : Sequence := Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{77}->union(Sequence{98}->union(Sequence{45}->union(Sequence{ 12 })))))) ; var squares : Sequence := items->select(i | true)->collect(i | (i * i)) ; execute (squares)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- values = [10, -5, 3, 8, -1] element1 = values[2] print(element1) element2 = values[4] print(element2) element3 = values[-3] print(element3) element4 = values[-5] print(element4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var values : Sequence := Sequence{10}->union(Sequence{-5}->union(Sequence{3}->union(Sequence{8}->union(Sequence{ -1 })))) ; var element1 : OclAny := values[2+1] ; execute (element1)->display() ; var element2 : OclAny := values[4+1] ; execute (element2)->display() ; var element3 : OclAny := values->reverse()->at(-(-3)) ; execute (element3)->display() ; var element4 : OclAny := values->reverse()->at(-(-5)) ; execute (element4)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numbers = [7, -3, 4, 9, 2] subset1 = numbers[2:] print(subset1) subset2 = numbers[:-2] print(subset2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var numbers : Sequence := Sequence{7}->union(Sequence{-3}->union(Sequence{4}->union(Sequence{9}->union(Sequence{ 2 })))) ; var subset1 : OclAny := numbers.subrange(2+1) ; execute (subset1)->display() ; var subset2 : OclAny := numbers->front()->front() ; execute (subset2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- elements = [4, -1, 6, 8, -3] slice1 = elements[2:-3] print(slice1) slice2 = elements[-4:-2] print(slice2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var elements : Sequence := Sequence{4}->union(Sequence{-1}->union(Sequence{6}->union(Sequence{8}->union(Sequence{ -3 })))) ; var slice1 : OclAny := elements.subrange(2+1, -3) ; execute (slice1)->display() ; var slice2 : OclAny := elements.subrange(-4+1, -2) ; execute (slice2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- values = [8, -4, 7, 1, 5] last_element = values[-2] print(last_element) new_list = [last_element] combined_list = new_list + values print(combined_list) sum_elements = sum(combined_list) average = sum_elements / len(combined_list) print("Sum:", sum_elements) print("Average:", average) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var values : Sequence := Sequence{8}->union(Sequence{-4}->union(Sequence{7}->union(Sequence{1}->union(Sequence{ 5 })))) ; var last_element : OclAny := values->front()->last() ; execute (last_element)->display() ; var new_list : Sequence := Sequence{ last_element } ; var combined_list : Sequence := new_list->union(values) ; execute (combined_list)->display() ; var sum_elements : OclAny := (combined_list)->sum() ; var average : double := sum_elements / (combined_list)->size() ; execute ("Sum:")->display() ; execute ("Average:")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numbers_set = {4, 7, 1, 8} print(len(numbers_set)) additional_items = {10, 5} numbers_set.update(additional_items) print(numbers_set) print("Updated set length:", len(numbers_set)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var numbers_set : Set := Set{4}->union(Set{7}->union(Set{1}->union(Set{ 8 }))) ; execute ((numbers_set)->size())->display() ; var additional_items : Set := Set{10}->union(Set{ 5 }) ; execute ((additional_items) <: numbers_set) ; execute (numbers_set)->display() ; execute ("Updated set length:")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- unique_values = {2, 4, 6, 8} set1 = {10, 12} set2 = {14, 16} unique_values.update(set1, set2) print("Updated set:", unique_values) unique_values.discard(6) print("After discarding 6:", unique_values) additional_elements = {18, 20} unique_values.update(additional_elements) print("After adding more elements:", unique_values) total_elements = len(unique_values) print("Total number of elements:", total_elements) if 10 in unique_values: print("10 is in the set") else: print("10 is not in the set") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var unique_values : Set := Set{2}->union(Set{4}->union(Set{6}->union(Set{ 8 }))) ; var set1 : Set := Set{10}->union(Set{ 12 }) ; var set2 : Set := Set{14}->union(Set{ 16 }) ; execute ((set1, set2) <: unique_values) ; execute ("Updated set:")->display() ; execute ((6) /: unique_values) ; execute ("After discarding 6:")->display() ; var additional_elements : Set := Set{18}->union(Set{ 20 }) ; execute ((additional_elements) <: unique_values) ; execute ("After adding more elements:")->display() ; var total_elements : int := (unique_values)->size() ; execute ("Total number of elements:")->display() ; if (unique_values)->includes(10) then ( execute ("10 is in the set")->display() ) else ( execute ("10 is not in the set")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numbers_set = {4, 5, 6} item = numbers_set.pop() print(item) print(numbers_set) more_items = {7, 8, 9} numbers_set.update(more_items) print("Updated set:", numbers_set) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var numbers_set : Set := Set{4}->union(Set{5}->union(Set{ 6 })) ; var item : OclAny := numbers_set->last() ; numbers_set := numbers_set->front() ; execute (item)->display() ; execute (numbers_set)->display() ; var more_items : Set := Set{7}->union(Set{8}->union(Set{ 9 })) ; execute ((more_items) <: numbers_set) ; execute ("Updated set:")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- char_set = {'x', 'y', 'z'} char_set.intersection_update({'x', 'y', 'a'}) print(char_set) char_set.add('b') char_set.add('c') char_set.clear() print(char_set) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var char_set : Set := Set{'x'}->union(Set{'y'}->union(Set{ 'z' })) ; execute ((char_set - (Set{'x'}->union(Set{'y'}->union(Set{ 'a' })))) /<: char_set) ; execute (char_set)->display() ; execute (('b') : char_set) ; execute (('c') : char_set) ; execute (char_set /<: char_set) ; execute (char_set)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Individual: full_name = "" years_old = 0 def __init__(self, full_name, years_old): self.full_name = full_name self.years_old = years_old person1 = Individual("Alice", 30) person2 = Individual("Bob", 25) ------------------------------------------------------------ OCL File: --------- class Individual { static operation newIndividual() : Individual pre: true post: Individual->exists( _x | result = _x ); static attribute full_name : String := ""; static attribute years_old : int := 0; attribute full_name : String := full_name; attribute years_old : int := years_old; operation initialise(full_name : OclAny,years_old : OclAny) : Individual pre: true post: true activity: self.full_name := full_name ; self.years_old := years_old; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; var person1 : Individual := (Individual.newIndividual()).initialise("Alice", 30) ; var person2 : Individual := (Individual.newIndividual()).initialise("Bob", 25); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numbers = [10, 20, 30, 40] removed_item = numbers.pop(1) print("Removed item:", removed_item) print("Remaining list:", numbers) numbers.append(50) print("List after appending 50:", numbers) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var numbers : Sequence := Sequence{10}->union(Sequence{20}->union(Sequence{30}->union(Sequence{ 40 }))) ; var removed_item : OclAny := numbers->at(1`firstArg+1) ; numbers := numbers->excludingAt(1+1) ; execute ("Removed item:")->display() ; execute ("Remaining list:")->display() ; execute ((50) : numbers) ; execute ("List after appending 50:")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- user_input = input("Please enter a value: ") data_type = type(user_input) slice_one = slice(5) slice_two = slice(1, 8) print("Data type of input:", data_type) print("Slice one:", user_input[slice_one]) print("Slice two:", user_input[slice_two]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var user_input : String := (OclFile["System.in"]).readLine("Please enter a value: ") ; var data_type : OclType := (user_input)->oclType() ; var slice_one : Sequence := Integer.subrange(1,5) ; var slice_two : Sequence := Integer.subrange(1+1,8) ; execute ("Data type of input:")->display() ; execute ("Slice one:")->display() ; execute ("Slice two:")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Pupil: def __init__(self, fullname, score, years): self.fullname = fullname self.score = score self.years = years def __repr__(self): return repr((self.fullname, self.score, self.years)) pupil_list = [ Pupil('aaa', 'A', 14), Pupil('bbb', 'C', 13), Pupil('ccc', 'B', 11) ] sorted_pupils = sorted(pupil_list, key=lambda pupil: pupil.years) print(sorted_pupils) ------------------------------------------------------------ OCL File: --------- class Pupil { static operation newPupil() : Pupil pre: true post: Pupil->exists( _x | result = _x ); attribute fullname : OclAny := fullname; attribute score : OclAny := score; attribute years : OclAny := years; operation initialise(fullname : OclAny,score : OclAny,years : OclAny) : Pupil pre: true post: true activity: self.fullname := fullname ; self.score := score ; self.years := years; return self; operation __repr__() : OclAny pre: true post: true activity: return ("" + ((Sequence{self.fullname, self.score, self.years}))); } class FromPython { operation initialise() pre: true post: true activity: skip ; var pupil_list : Sequence := Sequence{(Pupil.newPupil()).initialise('aaa', 'A', 14)}->union(Sequence{(Pupil.newPupil()).initialise('bbb', 'C', 13)}->union(Sequence{ (Pupil.newPupil()).initialise('ccc', 'B', 11) })) ; var sorted_pupils : Sequence := pupil_list->sortedBy($x | (lambda pupil : OclAny in (pupil.years))->apply($x)) ; execute (sorted_pupils)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- data_dict = {"x": 10, "z": 5, "y": 8, "w": 12} sorted_keys = sorted(data_dict) print(sorted_keys) sorted_values = sorted(data_dict.values()) print(sorted_values) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var data_dict : Map := Map{ "x" |-> 10 }->union(Map{ "z" |-> 5 }->union(Map{ "y" |-> 8 }->union(Map{ "w" |-> 12 }))) ; var sorted_keys : Sequence := data_dict->keys()->sort() ; execute (sorted_keys)->display() ; var sorted_values : Sequence := data_dict.values()->sort() ; execute (sorted_values)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num = -7.3 absolute_value = abs(num) print(absolute_value) positive_num = abs(-12.8) print(positive_num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : double := -7.3 ; var absolute_value : double := (num)->abs() ; execute (absolute_value)->display() ; var positive_num : double := (-12.8)->abs() ; execute (positive_num)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class MathOps: def __init__(self, value): self.total = value def add_and_double(self, num): self.total = num + self.total self.total = self.total + self.total return num * self.total def update_and_divide(self, num): self.total = num + self.total self.total = self.total + self.total return self.total // num calculator = MathOps(5) print(calculator.add_and_double(3)) print(calculator.update_and_divide(2)) ------------------------------------------------------------ OCL File: --------- class MathOps { static operation newMathOps() : MathOps pre: true post: MathOps->exists( _x | result = _x ); attribute total : OclAny := value; operation initialise(value : OclAny) : MathOps pre: true post: true activity: self.total := value; return self; operation add_and_double(num : OclAny) : OclAny pre: true post: true activity: self.total := num + self.total ; self.total := self.total + self.total ; return num * self.total; operation update_and_divide(num : OclAny) : OclAny pre: true post: true activity: self.total := num + self.total ; self.total := self.total + self.total ; return self.total div num; } class FromPython { operation initialise() pre: true post: true activity: skip ; var calculator : MathOps := (MathOps.newMathOps()).initialise(5) ; execute (calculator.add_and_double(3))->display() ; execute (calculator.update_and_divide(2))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Processor: def __init__(self, start_value): self.value = start_value def compute(self, input_value): if input_value > 0: self.value = input_value + self.value self.value = self.value + self.value return input_value * self.value return input_value def evaluate(self, input_value): if input_value > 1: self.value = input_value + self.value self.value = self.value + self.value return self.value // input_value return input_value handler = Processor(4) print(handler.compute(2)) print(handler.evaluate(5)) ------------------------------------------------------------ OCL File: --------- class Processor { static operation newProcessor() : Processor pre: true post: Processor->exists( _x | result = _x ); attribute value : OclAny := start_value; operation initialise(start_value : OclAny) : Processor pre: true post: true activity: self.value := start_value; return self; operation compute(input_value : OclAny) : OclAny pre: true post: true activity: if input_value > 0 then ( self.value := input_value + self.value ; self.value := self.value + self.value ; return input_value * self.value ) else skip ; return input_value; operation evaluate(input_value : OclAny) : OclAny pre: true post: true activity: if input_value > 1 then ( self.value := input_value + self.value ; self.value := self.value + self.value ; return self.value div input_value ) else skip ; return input_value; } class FromPython { operation initialise() pre: true post: true activity: skip ; var handler : Processor := (Processor.newProcessor()).initialise(4) ; execute (handler.compute(2))->display() ; execute (handler.evaluate(5))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- data = [4, 1, -3, 7, 2] print(min(data)) print(max(data)) if largest in {2, 4}: print(largest + 2) smallest = min(5, 2) largest = max(5, 2) print(smallest) print(largest) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var data : Sequence := Sequence{4}->union(Sequence{1}->union(Sequence{-3}->union(Sequence{7}->union(Sequence{ 2 })))) ; execute ((data)->min())->display() ; execute ((data)->max())->display() ; if (Set{2}->union(Set{ 4 }))->includes(largest) then ( execute (largest + 2)->display() ) else skip ; var smallest : OclAny := Set{5, 2}->min() ; var largest : OclAny := Set{5, 2}->max() ; execute (smallest)->display() ; execute (largest)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- text = "another example" ascii_values = [ord(char) for char in text] unique_chars = set(text) char_count = {char: text.count(char) for char in unique_chars} print(ascii_values) print(unique_chars) print(char_count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var text : String := "another example" ; var ascii_values : Sequence := text->characters()->select(char | true)->collect(char | ((char)->char2byte())) ; var unique_chars : Set := Set{}->union((text)) ; var char_count : Map := unique_chars->select(char | true)->collect(char | Map{char |-> text->count(char)})->unionAll() ; execute (ascii_values)->display() ; execute (unique_chars)->display() ; execute (char_count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- str1 = "hi" str2 = str1 print(str1) str2 += " there" print(str2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var str1 : String := "hi" ; var str2 : String := str1 ; execute (str1)->display() ; str2 := str2 + " there" ; execute (str2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class User: username = "" def __init__(self): self.birth_year = 1990 user_instance = User() user_instance.username = "JohnDoe" user_instance.birth_year = 1985 another_user = User() another_user.username = "JaneSmith" another_user.birth_year = 1992 ------------------------------------------------------------ OCL File: --------- class User { static operation newUser() : User pre: true post: User->exists( _x | result = _x ); static attribute username : String := ""; attribute birth_year : int := 1990; operation initialise() : User pre: true post: true activity: self.birth_year := 1990; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; var user_instance : User := (User.newUser()).initialise() ; user_instance.username := "JohnDoe" ; user_instance.birth_year := 1985 ; var another_user : User := (User.newUser()).initialise() ; another_user.username := "JaneSmith" ; another_user.birth_year := 1992; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- text = "example text data" count_n = text.count("t") modified_text = text.capitalize() modified_text = text.title() modified_text = text.replace(" ", "-") modified_text = text.lstrip() modified_text = text.strip() new_text = text.lower() print(new_text) split_text = text.split(" ") print(split_text) joined_text = ", ".join(split_text) print(joined_text) substring = text[8:13] print(substring) text_length = len(text) print(text_length) print(count_n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var text : String := "example text data" ; var count_n : int := text->count("t") ; var modified_text : String := StringLib.capitalise(text) ; modified_text := StringLib.toTitleCase(text) ; modified_text := text.replace(" ", "-") ; modified_text := StringLib.leftTrim(text) ; modified_text := text->trim() ; var new_text : String := text->toLowerCase() ; execute (new_text)->display() ; var split_text : OclAny := text.split(" ") ; execute (split_text)->display() ; var joined_text : String := StringLib.sumStringsWithSeparator((split_text), ", ") ; execute (joined_text)->display() ; var substring : OclAny := text.subrange(8+1, 13) ; execute (substring)->display() ; var text_length : int := (text)->size() ; execute (text_length)->display() ; execute (count_n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sq = ['a', 'b', 'c', 'd', 'e', 'f'] print(sq[1:4]) chars = ['x', 'y', 'z', 'm', 'n', 'o'] print(chars[2:5]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sq : Sequence := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{'c'}->union(Sequence{'d'}->union(Sequence{'e'}->union(Sequence{ 'f' }))))) ; execute (sq.subrange(1+1, 4))->display() ; var chars : Sequence := Sequence{'x'}->union(Sequence{'y'}->union(Sequence{'z'}->union(Sequence{'m'}->union(Sequence{'n'}->union(Sequence{ 'o' }))))) ; execute (chars.subrange(2+1, 5))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- items = ['x', 'y', 'z', 'w', 'v', 'u' , 'p'] print(items[:5]) subset = items[:3] print(subset) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var items : Sequence := Sequence{'x'}->union(Sequence{'y'}->union(Sequence{'z'}->union(Sequence{'w'}->union(Sequence{'v'}->union(Sequence{'u'}->union(Sequence{ 'p' })))))) ; execute (items.subrange(1,5))->display() ; var subset : OclAny := items.subrange(1,3) ; execute (subset)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- elements = ['p', 'q', 'r'] new_item = 'z' elements.extend('s') print(elements) elements.insert(1, new_item) print(elements) elements.sort() print(elements) # Additional operations elements.remove('p') print(elements) elements.reverse() print(elements) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var elements : Sequence := Sequence{'p'}->union(Sequence{'q'}->union(Sequence{ 'r' })) ; var new_item : String := 'z' ; elements := elements->union('s') ; execute (elements)->display() ; elements := elements.insertAt(1+1, new_item) ; execute (elements)->display() ; elements := elements->sort() ; execute (elements)->display() ; execute (('p') /: elements) ; execute (elements)->display() ; elements := elements->reverse() ; execute (elements)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numbers = [4, 5, 6] numbers.pop(1) print(numbers.index(6)) new_list = [7, 8, 9] new_list.pop() print(new_list.index(7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var numbers : Sequence := Sequence{4}->union(Sequence{5}->union(Sequence{ 6 })) ; numbers := numbers->excludingAt(1+1) ; execute (numbers->indexOf(6) - 1)->display() ; var new_list : Sequence := Sequence{7}->union(Sequence{8}->union(Sequence{ 9 })) ; new_list := new_list->front() ; execute (new_list->indexOf(7) - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a = 10 b = 25 c = 8 a, b, c = c, a, b print(a) print(b) print(c) d = 20 e = 35 f = 12 d, e, f = f, d, e print(d) print(e) print(f) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := 10 ; var b : int := 25 ; var c : int := 8 ; Sequence{a,b,c} := Sequence{c,a,b} ; execute (a)->display() ; execute (b)->display() ; execute (c)->display() ; var d : int := 20 ; var e : int := 35 ; var f : int := 12 ; Sequence{d,e,f} := Sequence{f,d,e} ; execute (d)->display() ; execute (e)->display() ; execute (f)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- pairs = [(2,3), (3,4), (5,7), (6,30)] results = [a * b for a, b in pairs] print(results) values = [(2, 5), (1, 6), (4, 9)] products = [m * n for m, n in values] print(products) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var pairs : Sequence := Sequence{Sequence{2, 3}}->union(Sequence{Sequence{3, 4}}->union(Sequence{Sequence{5, 7}}->union(Sequence{ Sequence{6, 30} }))) ; var results : Sequence := pairs->select(_tuple | true)->collect(_tuple | let a : OclAny = _tuple->at(1) in let b : OclAny = _tuple->at(2) in (a * b)) ; execute (results)->display() ; var values : Sequence := Sequence{Sequence{2, 5}}->union(Sequence{Sequence{1, 6}}->union(Sequence{ Sequence{4, 9} })) ; var products : Sequence := values->select(_tuple | true)->collect(_tuple | let m : OclAny = _tuple->at(1) in let n : OclAny = _tuple->at(2) in (m * n)) ; execute (products)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- pairs = [(2,3), (3,4), (5,7), (6,30)] for a, b in pairs: print(a * b) more_pairs = [(1,2), (2,5), (3,9), (4,8)] for p, q in more_pairs: print(p + q) additional_pairs = [(7,1), (8,3), (9,5)] for u, v in additional_pairs: print(u - v) complex_pairs = [(10, 5), (12, 4), (14, 3)] for m, n in complex_pairs: print(m / n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var pairs : Sequence := Sequence{Sequence{2, 3}}->union(Sequence{Sequence{3, 4}}->union(Sequence{Sequence{5, 7}}->union(Sequence{ Sequence{6, 30} }))) ; for _tuple : pairs do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); execute (a * b)->display()) ; var more_pairs : Sequence := Sequence{Sequence{1, 2}}->union(Sequence{Sequence{2, 5}}->union(Sequence{Sequence{3, 9}}->union(Sequence{ Sequence{4, 8} }))) ; for _tuple : more_pairs do (var _indx : int := 1; var p : OclAny := _tuple->at(_indx); _indx := _indx + 1; var q : OclAny := _tuple->at(_indx); execute (p + q)->display()) ; var additional_pairs : Sequence := Sequence{Sequence{7, 1}}->union(Sequence{Sequence{8, 3}}->union(Sequence{ Sequence{9, 5} })) ; for _tuple : additional_pairs do (var _indx : int := 1; var u : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); execute (u - v)->display()) ; var complex_pairs : Sequence := Sequence{Sequence{10, 5}}->union(Sequence{Sequence{12, 4}}->union(Sequence{ Sequence{14, 3} })) ; for _tuple : complex_pairs do (var _indx : int := 1; var m : OclAny := _tuple->at(_indx); _indx := _indx + 1; var n : OclAny := _tuple->at(_indx); execute (m / n)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- first = "x" second = "y" third = "z" trio = (first, second, third) alpha, beta, gamma = trio print(alpha) print(beta) print(gamma) new_first = "p" new_second = "q" new_third = "r" new_trio = (new_first, new_second, new_third) one, two, three = new_trio print(one) print(two) print(three) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var first : String := "x" ; var second : String := "y" ; var third : String := "z" ; var trio : OclAny := Sequence{first, second, third} ; var alpha : OclAny := null; var beta : OclAny := null; var gamma : OclAny := null; Sequence{alpha,beta,gamma} := trio ; execute (alpha)->display() ; execute (beta)->display() ; execute (gamma)->display() ; var new_first : String := "p" ; var new_second : String := "q" ; var new_third : String := "r" ; var new_trio : OclAny := Sequence{new_first, new_second, new_third} ; var one : OclAny := null; var two : OclAny := null; var three : OclAny := null; Sequence{one,two,three} := new_trio ; execute (one)->display() ; execute (two)->display() ; execute (three)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math items = ["xx", "yy", "zz"] count1 = len(items) squared = math.pow(count, 3) result = math.sin(1.5) print("Count:", count1) print("Cubed:", squared) print("Cosine Result:", result) extra = math.sqrt(25) log_value = math.log(10) print("Square Root:", extra) print("Logarithm:", log_value) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var items : Sequence := Sequence{"xx"}->union(Sequence{"yy"}->union(Sequence{ "zz" })) ; var count1 : int := (items)->size() ; var squared : double := (count)->pow(3) ; var result : double := (1.5)->sin() ; execute ("Count:")->display() ; execute ("Cubed:")->display() ; execute ("Cosine Result:")->display() ; var extra : double := (25)->sqrt() ; var log_value : double := (10)->log() ; execute ("Square Root:")->display() ; execute ("Logarithm:")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Employee: employee_id = "" def __init__(self): self.years_experience = 0 def add_experience(self, years): self.years_experience += years worker = Employee() worker.add_experience(3) print(worker.years_experience) new_worker = Employee() new_worker.add_experience(7) print(new_worker.years_experience) ------------------------------------------------------------ OCL File: --------- class Employee { static operation newEmployee() : Employee pre: true post: Employee->exists( _x | result = _x ); static attribute employee_id : String := ""; attribute years_experience : int := 0; operation initialise() : Employee pre: true post: true activity: self.years_experience := 0; return self; operation add_experience(years : OclAny) pre: true post: true activity: self.years_experience := self.years_experience + years; } class FromPython { operation initialise() pre: true post: true activity: skip ; var worker : Employee := (Employee.newEmployee()).initialise() ; worker.add_experience(3) ; execute (worker.years_experience)->display() ; var new_worker : Employee := (Employee.newEmployee()).initialise() ; new_worker.add_experience(7) ; execute (new_worker.years_experience)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- flt = 45.0e-8 num = 200 unique_values = set({num, flt}) data_dict = dict({'alpha': num, 'beta': flt}) list_vals = [num, flt, num] print(list_vals + [7, 100]) print(num + flt) text = "sample text" print(text + ' extended') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var flt : double := ("45.0e-8")->toReal() ; var num : int := 200 ; var unique_values : Set := Set{}->union((Set{num}->union(Set{ flt }))) ; var data_dict : Map := (Map{ 'alpha' |-> num }->union(Map{ 'beta' |-> flt })) ; var list_vals : Sequence := Sequence{num}->union(Sequence{flt}->union(Sequence{ num })) ; execute (list_vals->union(Sequence{7}->union(Sequence{ 100 })))->display() ; execute (num + flt)->display() ; var text : String := "sample text" ; execute (text + ' extended')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- count2 = 0 factorial = 1 while count2 < 8: count2 = count2 + 1 factorial = count2 * factorial ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var count2 : int := 0 ; var factorial : int := 1 ; while count2 < 8 do ( count2 := count2 + 1 ; factorial := count2 * factorial); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- content = "different content\nwith multiple lines\nfour lines\n" with open('output.txt', 'w') as file_out, open('input.txt', 'r') as file_in: data = file_in.read() file_out.write(data) file_out.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var content : String := "different content\nwith multiple lines\nfour lines\n" ; try (var file_out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('output.txt')); var file_in : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('input.txt')); var data : String := file_in.readAll() ; file_out.write(data) ; file_out.closeFile()) catch (_e : OclException) do skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- content = "new data\nwith different lines\nadditional text\n" with open('file_output.txt', 'w') as file_out: file_out.write(content) file_out.close() additional_info = "extra information\n" with open('file_output.txt', 'a') as file_out: file_out.write(additional_info) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var content : String := "new data\nwith different lines\nadditional text\n" ; try (var file_out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('file_output.txt')); file_out.write(content) ; file_out.closeFile()) catch (_e : OclException) do skip ; var additional_info : String := "extra information\n" ; try (var file_out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('file_output.txt')); file_out.write(additional_info)) catch (_e : OclException) do skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def generate_numbers(): yield 5 yield 10 yield 15 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; operation generate_numbers(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return 5 ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return 10 ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return 15; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def number_generator(): yield 4 yield 8 yield 12 gen_instance = number_generator() print(next(gen_instance)) print(next(gen_instance)) print(next(gen_instance)) additional_gen = (i + 5 for i in [1, 2, 3]) for value in additional_gen: print(value) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var gen_instance : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.number_generator(_i)) ; execute ((gen_instance).next())->display() ; execute ((gen_instance).next())->display() ; execute ((gen_instance).next())->display() ; var additional_gen : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 5)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1))))))) , (test (logical_test (comparison (expr (atom (number (integer 2))))))) , (test (logical_test (comparison (expr (atom (number (integer 3)))))))) ]))))))} ; for value : additional_gen do ( execute (value)->display()); operation number_generator(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return 4 ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return 8 ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return 12; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import pandas as pd student_data = pd.read_csv("data/student_info.csv") student_ages = student_data["Age"] average_student_age = student_ages.mean() print(average_student_age) age_grade_statistics = student_data[["Age", "Grade"]].median() print(age_grade_statistics) total_students = len(student_data) print(total_students) highest_grade = student_data["Grade"].max() print(highest_grade) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var student_data : Map := OclFile.newOclFile_Read(OclFile.newOclFile(("data/student_info.csv"))).readMap() ; var student_ages : OclAny := student_data->at("Age") ; var average_student_age : double := MathLib.mean(student_ages) ; execute (average_student_age)->display() ; var age_grade_statistics : OclAny := MathLib.median(student_data->restrict(Sequence{"Age"}->union(Sequence{ "Grade" }))) ; execute (age_grade_statistics)->display() ; var total_students : int := (student_data)->size() ; execute (total_students)->display() ; var highest_grade : OclAny := student_data->at("Grade")->max() ; execute (highest_grade)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Customer: def __init__(self, full_name): self.full_name = full_name self.years = 0 def retrieve_age(self): return self.years client = Customer("aaa bbb") client.years = 29 new_client = Customer("nnn mmmm") new_client.years = 34 ------------------------------------------------------------ OCL File: --------- class Customer { static operation newCustomer() : Customer pre: true post: Customer->exists( _x | result = _x ); attribute full_name : OclAny := full_name; attribute years : int := 0; operation initialise(full_name : OclAny) : Customer pre: true post: true activity: self.full_name := full_name ; self.years := 0; return self; operation retrieve_age() : OclAny pre: true post: true activity: return self.years; } class FromPython { operation initialise() pre: true post: true activity: skip ; var client : Customer := (Customer.newCustomer()).initialise("aaa bbb") ; client.years := 29 ; var new_client : Customer := (Customer.newCustomer()).initialise("nnn mmmm") ; new_client.years := 34; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Member: def __init__(self, user_name): self.user_name = user_name self.experience = 0 def increment_experience(self): self.experience += 2 return self.experience user1 = Member("amna") user1.increment_experience() user1.increment_experience() user2 = Member("ali") user2.increment_experience() ------------------------------------------------------------ OCL File: --------- class Member { static operation newMember() : Member pre: true post: Member->exists( _x | result = _x ); attribute user_name : OclAny := user_name; attribute experience : int := 0; operation initialise(user_name : OclAny) : Member pre: true post: true activity: self.user_name := user_name ; self.experience := 0; return self; operation increment_experience() : OclAny pre: true post: true activity: self.experience := self.experience + 2 ; return self.experience; } class FromPython { operation initialise() pre: true post: true activity: skip ; var user1 : Member := (Member.newMember()).initialise("amna") ; user1.increment_experience() ; user1.increment_experience() ; var user2 : Member := (Member.newMember()).initialise("ali") ; user2.increment_experience(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numbers = [5, 6, 7, 8, 6, 9, 2] squared_dict = { num: num*num for num in numbers } print(squared_dict) values = [9, 10] cubed_dict = { val: val*val*val for val in values } print(cubed_dict) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var numbers : Sequence := Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{6}->union(Sequence{9}->union(Sequence{ 2 })))))) ; var squared_dict : Map := numbers->select(num | true)->collect(num | Map{num |-> num * num})->unionAll() ; execute (squared_dict)->display() ; var values : Sequence := Sequence{9}->union(Sequence{ 10 }) ; var cubed_dict : Map := values->select(val | true)->collect(val | Map{val |-> val * val * val})->unionAll() ; execute (cubed_dict)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numbers = [7, 8, 9, 10, 11, 12] squared_even = [num*num for num in numbers if num % 2 != 0] print(squared_even) new_numbers = [13, 14, 15, 16] cubed_odd = [num**3 for num in new_numbers if num % 2 != 0] print(cubed_odd) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var numbers : Sequence := Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{10}->union(Sequence{11}->union(Sequence{ 12 }))))) ; var squared_even : Sequence := numbers->select(num | num mod 2 /= 0)->collect(num | (num * num)) ; execute (squared_even)->display() ; var new_numbers : Sequence := Sequence{13}->union(Sequence{14}->union(Sequence{15}->union(Sequence{ 16 }))) ; var cubed_odd : Sequence := new_numbers->select(num | num mod 2 /= 0)->collect(num | ((num)->pow(3))) ; execute (cubed_odd)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numbers_set = {5, 6, 7, 8, 6, 3} squared_set = {num*num for num in numbers_set} print(squared_set) additional_numbers = {9, 10} cubed_set = {num**3 for num in additional_numbers} print(cubed_set) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var numbers_set : Set := Set{5}->union(Set{6}->union(Set{7}->union(Set{8}->union(Set{6}->union(Set{ 3 }))))) ; var squared_set : Set := numbers_set->select(num | true)->collect(num | num * num)->asSet() ; execute (squared_set)->display() ; var additional_numbers : Set := Set{9}->union(Set{ 10 }) ; var cubed_set : Set := additional_numbers->select(num | true)->collect(num | (num)->pow(3))->asSet() ; execute (cubed_set)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tuple1 = (2, 4, 6) tuple2 = (2, 4, 5) if tuple1 < tuple2: print(True) else: print(False) char1 = "A" char2 = "B" print(char1 < char2) print(7 < 10) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var tuple1 : OclAny := Sequence{2, 4, 6} ; var tuple2 : OclAny := Sequence{2, 4, 5} ; if (tuple1->compareTo(tuple2)) < 0 then ( execute (true)->display() ) else ( execute (false)->display() ) ; var char1 : String := "A" ; var char2 : String := "B" ; execute (char1 < char2)->display() ; execute (7 < 10)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- is_enabled: bool = False threshold: int = 500 flag: bool = True limit: int = 250 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var is_enabled : boolean := false ; var threshold : int := 500 ; var flag : boolean := true ; var limit : int := 250; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numbers_list = [5, 6, 7, 6, 5, 8, 5] target = 5 print(numbers_list.count(target)) new_list = [9, 10, 9, 11, 10] search_value = 10 print(new_list.count(search_value)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var numbers_list : Sequence := Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{6}->union(Sequence{5}->union(Sequence{8}->union(Sequence{ 5 })))))) ; var target : int := 5 ; execute (numbers_list->count(target))->display() ; var new_list : Sequence := Sequence{9}->union(Sequence{10}->union(Sequence{9}->union(Sequence{11}->union(Sequence{ 10 })))) ; var search_value : int := 10 ; execute (new_list->count(search_value))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from datetime import * current_date = datetime.now() print(current_date.year) print(current_date.month) print(current_date.day) future_date = datetime.now() print(future_date.year) print(future_date.month) print(future_date.day) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var current_date : OclDate := OclDate.newOclDate() ; execute (current_date.getYear())->display() ; execute (current_date.getMonth())->display() ; execute (current_date.getDate())->display() ; var future_date : OclDate := OclDate.newOclDate() ; execute (future_date.getYear())->display() ; execute (future_date.getMonth())->display() ; execute (future_date.getDate())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def action1(a): pass def action2(a, b): pass def action3(a): pass def action4(a, b): pass def action5(a, b): pass def evaluate(a, b): if a > 5: action1(a) if b > 5: action2(a, b) return 10 else: action3(a) return 20 else: if b > 5: action4(a, b) return 30 else: action5(a, b) return 40 print(evaluate(6, 6)) print(evaluate(6, 4)) print(evaluate(4, 6)) print(evaluate(4, 4)) value1 = evaluate(7, 8) value2 = evaluate(2, 3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; execute (evaluate(6, 6))->display() ; execute (evaluate(6, 4))->display() ; execute (evaluate(4, 6))->display() ; execute (evaluate(4, 4))->display() ; var value1 : OclAny := evaluate(7, 8) ; var value2 : OclAny := evaluate(2, 3); operation action1(a : OclAny) pre: true post: true activity: skip; operation action2(a : OclAny, b : OclAny) pre: true post: true activity: skip; operation action3(a : OclAny) pre: true post: true activity: skip; operation action4(a : OclAny, b : OclAny) pre: true post: true activity: skip; operation action5(a : OclAny, b : OclAny) pre: true post: true activity: skip; operation evaluate(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a > 5 then ( action1(a) ; if b > 5 then ( action2(a, b) ; return 10 ) else ( action3(a) ; return 20 ) ) else ( if b > 5 then ( action4(a, b) ; return 30 ) else ( action5(a, b) ; return 40 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def evaluate(a, b): if a > 10: if b > 10: return 100 else: return 200 else: if b > 10: return 300 else: return 400 print(evaluate(11, 11)) print(evaluate(11, 5)) print(evaluate(5, 11)) print(evaluate(5, 5)) result1 = evaluate(12, 9) result2 = evaluate(8, 15) print(result1) print(result2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (evaluate(11, 11))->display() ; execute (evaluate(11, 5))->display() ; execute (evaluate(5, 11))->display() ; execute (evaluate(5, 5))->display() ; var result1 : OclAny := evaluate(12, 9) ; var result2 : OclAny := evaluate(8, 15) ; execute (result1)->display() ; execute (result2)->display(); operation evaluate(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a > 10 then ( if b > 10 then ( return 100 ) else ( return 200 ) ) else ( if b > 10 then ( return 300 ) else ( return 400 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(a, b = 2.0): result = 2.0 result = result + a / b print(result) compute(6, 3) compute(8) def calculate(m, n = 4.0): total = 3.0 total = total + m / n print(total) calculate(10, 5) calculate(7) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; compute(6, 3) ; compute(8) ; skip ; calculate(10, 5) ; calculate(7); operation compute(a : OclAny, b : double) pre: true post: true activity: if b->oclIsUndefined() then b := 2.0 else skip; var result : double := 2.0 ; result := result + a / b ; execute (result)->display(); operation calculate(m : OclAny, n : double) pre: true post: true activity: if n->oclIsUndefined() then n := 4.0 else skip; var total : double := 3.0 ; total := total + m / n ; execute (total)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_list = [4, 5, 6] char_list = ['x', 'y', 'z'] paired = zip(num_list, char_list) print(list(paired)) values = [7, 8, 9] labels = ['p', 'q', 'r'] combined = zip(values, labels) print(list(combined)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_list : Sequence := Sequence{4}->union(Sequence{5}->union(Sequence{ 6 })) ; var char_list : Sequence := Sequence{'x'}->union(Sequence{'y'}->union(Sequence{ 'z' })) ; var paired : Sequence := Integer.subrange(1, num_list->size())->collect( _indx | Sequence{num_list->at(_indx), char_list->at(_indx)} ) ; execute ((paired))->display() ; var values : Sequence := Sequence{7}->union(Sequence{8}->union(Sequence{ 9 })) ; var labels : Sequence := Sequence{'p'}->union(Sequence{'q'}->union(Sequence{ 'r' })) ; var combined : Sequence := Integer.subrange(1, values->size())->collect( _indx | Sequence{values->at(_indx), labels->at(_indx)} ) ; execute ((combined))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- unique_set = set({'x', 'y', 'z'}) del unique_set print(unique_set) another_set = set({'m', 'n', 'o'}) del another_set print(another_set) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var unique_set : Set := Set{}->union((Set{'x'}->union(Set{'y'}->union(Set{ 'z' })))) ; execute (unique_set)->isDeleted() ; execute (unique_set)->display() ; var another_set : Set := Set{}->union((Set{'m'}->union(Set{'n'}->union(Set{ 'o' })))) ; execute (another_set)->isDeleted() ; execute (another_set)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- letters = ['g', 'h', 'i', 'j', 'k', 'l'] del letters[2] del letters[2:4] numbers = [1, 2, 3, 4, 5, 6] del numbers[0] del numbers[1:3] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var letters : Sequence := Sequence{'g'}->union(Sequence{'h'}->union(Sequence{'i'}->union(Sequence{'j'}->union(Sequence{'k'}->union(Sequence{ 'l' }))))) ; execute (letters[2+1])->isDeleted() ; execute (letters.subrange(2+1, 4))->isDeleted() ; var numbers : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))))) ; execute (numbers->first())->isDeleted() ; execute (numbers.subrange(1+1, 3))->isDeleted(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections deque1 = collections.deque(['x', 'y', 'z']) deque1.appendleft('m') deque1.appendleft('n') print(deque1) deque1.extendleft(['o', 'p']) print(deque1) item = deque1.pop() print(deque1) deque1.popleft() print(deque1) print(deque1.maxlen) deque2 = collections.deque(['u', 'v', 'w']) deque2.appendleft('a') deque2.appendleft('b') print(deque2) deque2.extendleft(['c', 'd']) print(deque2) item2 = deque2.pop() print(deque2) deque2.popleft() print(deque2) print(deque2.maxlen) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var deque1 : Sequence := (Sequence{'x'}->union(Sequence{'y'}->union(Sequence{ 'z' }))) ; deque1 := deque1->prepend('m') ; deque1 := deque1->prepend('n') ; execute (deque1)->display() ; deque1 := deque1->reverse()->union(Sequence{'o'}->union(Sequence{ 'p' }))->reverse() ; execute (deque1)->display() ; var item : OclAny := deque1->last() ; deque1 := deque1->front() ; execute (deque1)->display() ; deque1 := deque1->tail() ; execute (deque1)->display() ; execute (deque1->size())->display() ; var deque2 : Sequence := (Sequence{'u'}->union(Sequence{'v'}->union(Sequence{ 'w' }))) ; deque2 := deque2->prepend('a') ; deque2 := deque2->prepend('b') ; execute (deque2)->display() ; deque2 := deque2->reverse()->union(Sequence{'c'}->union(Sequence{ 'd' }))->reverse() ; execute (deque2)->display() ; var item2 : OclAny := deque2->last() ; deque2 := deque2->front() ; execute (deque2)->display() ; deque2 := deque2->tail() ; execute (deque2)->display() ; execute (deque2->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- value = 3 if value > 2: result = value * value print(result + value) elif value > 0: result = value * value * value print(result + value) else: result = -value print(result) num = 5 if num > 4: square = num * num print(square + num) elif num > 1: cube = num * num * num print(cube + num) else: neg = -num print(neg) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var value : int := 3 ; if value > 2 then ( var result : int := value * value ; execute (result + value)->display() ) else (if value > 0 then ( result := value * value * value ; execute (result + value)->display() ) else ( result := -value ; execute (result)->display() ) ) ; var num : int := 5 ; if num > 4 then ( var square : int := num * num ; execute (square + num)->display() ) else (if num > 1 then ( var cube : int := num * num * num ; execute (cube + num)->display() ) else ( var neg : int := -num ; execute (neg)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num = 14 array = [8, 10, num] print(array) additional_num = 21 array.append(additional_num) print(array) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := 14 ; var array : Sequence := Sequence{8}->union(Sequence{10}->union(Sequence{ num })) ; execute (array)->display() ; var additional_num : int := 21 ; execute ((additional_num) : array) ; execute (array)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num = 4 if num > 3: value = num * num print(value + num) else: value = num * num * num print(value + num) factor = 2 if factor > 1: result = factor * factor print(result + factor) else: result = factor * factor * factor print(result + factor) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := 4 ; if num > 3 then ( var value : int := num * num ; execute (value + num)->display() ) else ( value := num * num * num ; execute (value + num)->display() ) ; var factor : int := 2 ; if factor > 1 then ( var result : int := factor * factor ; execute (result + factor)->display() ) else ( result := factor * factor * factor ; execute (result + factor)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def absolute_value(num): if num < 0: result = -num else: result = num return result print(absolute_value(-7)) print(absolute_value(4)) def magnitude(value): if value < 5: magnitude_value = -value else: magnitude_value = value return magnitude_value print(magnitude(-10)) print(magnitude(6)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (absolute_value(-7))->display() ; execute (absolute_value(4))->display() ; skip ; execute (magnitude(-10))->display() ; execute (magnitude(6))->display(); operation absolute_value(num : OclAny) : OclAny pre: true post: true activity: if num < 0 then ( var result : OclAny := -num ) else ( result := num ) ; return result; operation magnitude(value : OclAny) : OclAny pre: true post: true activity: if value < 5 then ( var magnitude_value : OclAny := -value ) else ( magnitude_value := value ) ; return magnitude_value; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- value = 7 a = 0 b = 0 if value > 10: a = value elif value < 10: b = value else: a = 1 new_value = 3 result_a = 0 result_b = 0 if new_value > 2: result_a = new_value elif new_value < 2: result_b = new_value else: result_a = 10 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var value : int := 7 ; var a : int := 0 ; var b : int := 0 ; if value > 10 then ( a := value ) else (if value < 10 then ( b := value ) else ( a := 1 ) ) ; var new_value : int := 3 ; var result_a : int := 0 ; var result_b : int := 0 ; if new_value > 2 then ( result_a := new_value ) else (if new_value < 2 then ( result_b := new_value ) else ( result_a := 10 ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from enum import Enum class Shade(Enum): crimson = 1 emerald = 2 sapphire = 3 print(Shade.emerald.value) class Fruit(Enum): apple = 1 banana = 2 cherry = 3 print(Fruit.banana.value) ------------------------------------------------------------ OCL File: --------- class Shade { static operation newShade() : Shade pre: true post: Shade->exists( _x | result = _x ); static attribute crimson : int := 1; static attribute emerald : int := 2; static attribute sapphire : int := 3; } class Fruit { static operation newFruit() : Fruit pre: true post: Fruit->exists( _x | result = _x ); static attribute apple : int := 1; static attribute banana : int := 2; static attribute cherry : int := 3; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; execute (Shade.emerald)->display() ; skip ; execute (Fruit.banana)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from enum import Enum class Color(Enum): yellow = 1 purple = 2 class Fruit(Enum): mango = 1 peach = 2 plum = 3 ------------------------------------------------------------ OCL File: --------- class Color { static operation newColor() : Color pre: true post: Color->exists( _x | result = _x ); static attribute yellow : int := 1; static attribute purple : int := 2; } class Fruit { static operation newFruit() : Fruit pre: true post: Fruit->exists( _x | result = _x ); static attribute mango : int := 1; static attribute peach : int := 2; static attribute plum : int := 3; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def calculatePrice(rate, start, end, payment, calendar, interval): return (payment * (end - start)) / math.pow((1 + rate), end - start) def computeInterest(startDate, endDate, interval, payment, calendar, maturityDate): numPeriods = int(12 / interval) return (endDate - startDate) * payment / numPeriods def adjustedPrice(rate, start, end, maturity, payment, calendar, interval): return calculatePrice(rate, start, end, payment, calendar, interval) - computeInterest(start, end, interval, payment, calendar, maturity) result = adjustedPrice(0.03, 2020.0, 2020.5, 2024.0, 0.02, "30/360", 4) print(result) newResult = adjustedPrice(0.04, 2021.0, 2021.75, 2025.0, 0.025, "30/360", 3) print(newResult) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var result : OclAny := adjustedPrice(0.03, 2020.0, 2020.5, 2024.0, 0.02, "30/360", 4) ; execute (result)->display() ; var newResult : OclAny := adjustedPrice(0.04, 2021.0, 2021.75, 2025.0, 0.025, "30/360", 3) ; execute (newResult)->display(); operation calculatePrice(rate : OclAny, start : OclAny, end : OclAny, payment : OclAny, calendar : OclAny, interval : OclAny) : OclAny pre: true post: true activity: return (payment * (end - start)) / ((1 + rate))->pow(end - start); operation computeInterest(startDate : OclAny, endDate : OclAny, interval : OclAny, payment : OclAny, calendar : OclAny, maturityDate : OclAny) : OclAny pre: true post: true activity: var numPeriods : int := ("" + ((12 / interval)))->toInteger() ; return (endDate - startDate) * payment / numPeriods; operation adjustedPrice(rate : OclAny, start : OclAny, end : OclAny, maturity : OclAny, payment : OclAny, calendar : OclAny, interval : OclAny) : OclAny pre: true post: true activity: return calculatePrice(rate, start, end, payment, calendar, interval) - computeInterest(start, end, interval, payment, calendar, maturity); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(eval("3**4")) expression = "2**6" result = eval(expression) print(result) calc = "7**2" value = eval(calc) print(value) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((3)->pow(4))->display() ; var expression : String := "2**6" ; var result : OclAny := expression ; execute (result)->display() ; var calc : String := "7**2" ; var value : OclAny := calc ; execute (value)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- date = 45 try: if date > 30: raise ValueError("day out of range") except ValueError as error: print(error) hour = 50 try: if hour > 24: raise ValueError("hour exceeds limit") except ValueError as err: print(err) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var date : int := 45 ; try ( if date > 30 then ( error IncorrectElementException.newIncorrectElementException("day out of range") ) else skip) catch (error : IncorrectElementException) do ( execute (error)->display()) ; var hour : int := 50 ; try ( if hour > 24 then ( error IncorrectElementException.newIncorrectElementException("hour exceeds limit") ) else skip) catch (err : IncorrectElementException) do ( execute (err)->display()) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- value = 20 exec("value = 7") print(value) num = 15 exec("num = 8") print(num) data = 30 exec("data = 12") print(data) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var value : int := 20 ; value := 7 ; execute (value)->display() ; var num : int := 15 ; num := 8 ; execute (num)->display() ; var data : int := 30 ; data := 12 ; execute (data)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- exec("num = 3; print(num*num)") exec("value = 6; print(value*value)") exec("data = 4; print(data*data)") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := 3; execute (num * num)->display() ; var value : int := 6; execute (value * value)->display() ; var data : int := 4; execute (data * data)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- value = 20.75 assert type(value) is float, 'Argument must be float!' another_value = 15 assert type(another_value) is int, 'Argument must be integer!' ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var value : double := 20.75 ; assert (value)->oclType() <>= OclType["double"] do 'Argument must be float!' ; var another_value : int := 15 ; assert (another_value)->oclType() <>= OclType["int"] do 'Argument must be integer!'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(a, b): if a > 2: if b > 2: return (a + b) * (a + b) else: return (a - b) * (a - b) else: if b > 2: return (a + b) * (a + b) else: return (a - b) * (a + b) print(compute(3, 3)) print(compute(3, -2)) print(compute(-2, 3)) print(compute(-2, -3)) def evaluate(p, q): if p > 5: if q > 5: return (p + q) * (p + q) else: return (p - q) * (p - q) else: if q > 5: return (p + q) * (p + q) else: return (p - q) * (p + q) print(evaluate(7, 7)) print(evaluate(7, 4)) print(evaluate(4, 7)) print(evaluate(4, 4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (compute(3, 3))->display() ; execute (compute(3, -2))->display() ; execute (compute(-2, 3))->display() ; execute (compute(-2, -3))->display() ; skip ; execute (evaluate(7, 7))->display() ; execute (evaluate(7, 4))->display() ; execute (evaluate(4, 7))->display() ; execute (evaluate(4, 4))->display(); operation compute(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a > 2 then ( if b > 2 then ( return (a + b) * (a + b) ) else ( return (a - b) * (a - b) ) ) else ( if b > 2 then ( return (a + b) * (a + b) ) else ( return (a - b) * (a + b) ) ); operation evaluate(p : OclAny, q : OclAny) : OclAny pre: true post: true activity: if p > 5 then ( if q > 5 then ( return (p + q) * (p + q) ) else ( return (p - q) * (p - q) ) ) else ( if q > 5 then ( return (p + q) * (p + q) ) else ( return (p - q) * (p + q) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculate(a, b): if a > 2: if b > 2: return ((a + b) * (a + b)) ** 3 else: return (a - b) * (a - b) else: if b > 2: return ((a + b) * (a + b)) ** 2 else: return (a - b) * (a + b) print(calculate(3, 3)) print(calculate(3, 1)) print(calculate(1, 3)) print(calculate(1, 1)) def process(p, q): if p > 5: if q > 5: return ((p + q) * (p + q)) ** 4 else: return (p - q) * (p - q) else: if q > 5: return ((p + q) * (p + q)) ** 3 else: return (p - q) * (p + q) print(process(6, 6)) print(process(6, 4)) print(process(4, 6)) print(process(4, 4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (calculate(3, 3))->display() ; execute (calculate(3, 1))->display() ; execute (calculate(1, 3))->display() ; execute (calculate(1, 1))->display() ; skip ; execute (process(6, 6))->display() ; execute (process(6, 4))->display() ; execute (process(4, 6))->display() ; execute (process(4, 4))->display(); operation calculate(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a > 2 then ( if b > 2 then ( return (((a + b) * (a + b)))->pow(3) ) else ( return (a - b) * (a - b) ) ) else ( if b > 2 then ( return (((a + b) * (a + b)))->pow(2) ) else ( return (a - b) * (a + b) ) ); operation process(p : OclAny, q : OclAny) : OclAny pre: true post: true activity: if p > 5 then ( if q > 5 then ( return (((p + q) * (p + q)))->pow(4) ) else ( return (p - q) * (p - q) ) ) else ( if q > 5 then ( return (((p + q) * (p + q)))->pow(3) ) else ( return (p - q) * (p + q) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- file_reader = open('datafile', 'r') content = file_reader.read() file_reader.close() file_writer = open('datafile', 'a') file_writer.write(content) new_file = open('datafile', 'r') new_content = new_file.read() new_file.close() print(new_content) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var file_reader : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('datafile')) ; var content : String := file_reader.readAll() ; file_reader.closeFile() ; var file_writer : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('datafile')) ; file_writer.write(content) ; var new_file : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('datafile')) ; var new_content : String := new_file.readAll() ; new_file.closeFile() ; execute (new_content)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- items = ["a", "bb", "ccc", "ddd", "fffff"] check_length = lambda text: len(text) > 3 filtered_items = filter(check_length, items) for element in filtered_items: print(element) names = ["cat", "dog", "elephant", "ant", "tiger"] length_filter = lambda name: len(name) >= 4 filtered_names = filter(length_filter, names) for name in filtered_names: print(name) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var items : Sequence := Sequence{"a"}->union(Sequence{"bb"}->union(Sequence{"ccc"}->union(Sequence{"ddd"}->union(Sequence{ "fffff" })))) ; var check_length : Function := lambda text : OclAny in ((text)->size() > 3) ; var filtered_items : Sequence := (items)->select( _x | (check_length)->apply(_x) = true ) ; for element : filtered_items do ( execute (element)->display()) ; var names : Sequence := Sequence{"cat"}->union(Sequence{"dog"}->union(Sequence{"elephant"}->union(Sequence{"ant"}->union(Sequence{ "tiger" })))) ; var length_filter : Function := lambda name : OclAny in ((name)->size() >= 4) ; var filtered_names : Sequence := (names)->select( _x | (length_filter)->apply(_x) = true ) ; for name : filtered_names do ( execute (name)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- data_map = dict({ "alpha": 10, "beta": 20 }) for key in data_map: print(key) info = dict({ "name": "Alice", "age": 30 }) for key in info: print(key) inventory = dict({ "apple": 5, "banana": 3 }) for item in inventory: print(item) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var data_map : Map := (Map{ "alpha" |-> 10 }->union(Map{ "beta" |-> 20 })) ; for key : data_map->keys() do ( execute (key)->display()) ; var info : Map := (Map{ "name" |-> "Alice" }->union(Map{ "age" |-> 30 })) ; for key : info->keys() do ( execute (key)->display()) ; var inventory : Map := (Map{ "apple" |-> 5 }->union(Map{ "banana" |-> 3 })) ; for item : inventory->keys() do ( execute (item)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- amount = 1500 rate = 7.5 label = 'Coupon' formatted_string = f"{label}: {amount} {rate:.2f}\n\n" print(formatted_string) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var amount : int := 1500 ; var rate : double := 7.5 ; var label : String := 'Coupon' ; var formatted_string : String := StringLib.formattedString("{label}: {amount} {rate:.2f}\n\n") ; execute (formatted_string)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- quantity = 2000 price = 15.75 result = "{0} units at ${1:.2f}\n\n".format(quantity, price) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var quantity : int := 2000 ; var price : double := 15.75 ; var result : String := StringLib.interpolateStrings("{0} units at ${1:.2f}\n\n", Sequence{quantity, price}) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- date = 15 season = 12 calendar_year = 2024 formatted_date = f"{date:02d}-{season:02d}-{calendar_year:04d}" print(formatted_date) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var date : int := 15 ; var season : int := 12 ; var calendar_year : int := 2024 ; var formatted_date : String := StringLib.formattedString("{date:02d}-{season:02d}-{calendar_year:04d}") ; execute (formatted_date)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- amount = 2500 rate = 12.5 output = "%d %.1f\n\n" % (amount, rate) print(output) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var amount : int := 2500 ; var rate : double := 12.5 ; var output : String := StringLib.format("%d %.1f\n\n",Sequence{amount, rate}) ; execute (output)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- items = ["apple", "banana", "cherry", "date","kewi"] for element in items: print(element) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var items : Sequence := Sequence{"apple"}->union(Sequence{"banana"}->union(Sequence{"cherry"}->union(Sequence{"date"}->union(Sequence{ "kewi" })))) ; for element : items do ( execute (element)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- result = 8 * 6 multiplier = 4 product = multiplier * 9 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var result : int := 8 * 6 ; var multiplier : int := 4 ; var product : int := multiplier * 9; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- text = "hello world" for character in text: print(character) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var text : String := "hello world" ; for character : text->characters() do ( execute (character)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def increment(value: int): return value + 2 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; operation increment(value : int) : OclAny pre: true post: true activity: return value + 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute_square(number: int) -> int: return number * number result = compute_square(7) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var result : OclAny := compute_square(7) ; execute (result)->display(); operation compute_square(number : int) : int pre: true post: true activity: return number * number; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def increment_and_square(value): return square(value + 2) def square(number): return number * number output1 = increment_and_square(3) output2 = increment_and_square(6) print(output1) print(output2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var output1 : OclAny := increment_and_square(3) ; var output2 : OclAny := increment_and_square(6) ; execute (output1)->display() ; execute (output2)->display(); operation increment_and_square(value : OclAny) : OclAny pre: true post: true activity: return square(value + 2); operation square(number : OclAny) : OclAny pre: true post: true activity: return number * number; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def multiply_with_constant(base=15): constant = 200 result = base return constant * result output_value = multiply_with_constant(5) print(output_value) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var output_value : OclAny := multiply_with_constant(5) ; execute (output_value)->display(); operation multiply_with_constant(base : int) : OclAny pre: true post: true activity: if base->oclIsUndefined() then base := 15 else skip; var constant : int := 200 ; var result : int := base ; return constant * result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check_and_set(value): if value < 0: global temp_var temp_var = 5 else: pass check_and_set(-3) print(temp_var) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute temp_var : OclAny; operation initialise() pre: true post: true activity: skip ; check_and_set(-3) ; execute (temp_var)->display(); operation check_and_set(value : OclAny) pre: true post: true activity: if value < 0 then ( skip ; temp_var := 5 ) else ( skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def update_values(factor): global alpha, beta alpha = 3 * factor beta = 5 * factor update_values(4) print(alpha) print(beta) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute alpha : OclAny; attribute beta : OclAny; operation initialise() pre: true post: true activity: skip ; update_values(4) ; execute (alpha)->display() ; execute (beta)->display(); operation update_values(factor : OclAny) pre: true post: true activity: skip; skip ; alpha := 3 * factor ; beta := 5 * factor; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def initialize_and_return(): global value value = 7 return value initialize_and_return() print(value) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute value : OclAny; operation initialise() pre: true post: true activity: skip ; initialize_and_return() ; execute (value)->display(); operation initialize_and_return() : OclAny pre: true post: true activity: skip ; value := 7 ; return value; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- flag = False num1 = 5 num2 = 15 if flag: num1 = 12 num2 = 20 print(num1) print(num2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var flag : boolean := false ; var num1 : int := 5 ; var num2 : int := 15 ; if flag then ( num1 := 12 ; num2 := 20 ) else skip ; execute (num1)->display() ; execute (num2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- status = False quantity = 12 divider = 3 if status: quantity = quantity // divider else: quantity = 7 print(quantity) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var status : boolean := false ; var quantity : int := 12 ; var divider : int := 3 ; if status then ( quantity := quantity div divider ) else ( quantity := 7 ) ; execute (quantity)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- matrix = [[7, 8, 9], [10, 11, 12]] print(matrix[1][2]) num = 20 alpha = beta = num print(alpha) print(beta) new_value = 30 gamma = delta = new_value print(gamma) print(delta) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var matrix : Sequence := Sequence{Sequence{7}->union(Sequence{8}->union(Sequence{ 9 }))}->union(Sequence{ Sequence{10}->union(Sequence{11}->union(Sequence{ 12 })) }) ; execute (matrix[1+1][2+1])->display() ; var num : int := 20 ; var alpha : OclAny := num; var beta : int := num ; execute (alpha)->display() ; execute (beta)->display() ; var new_value : int := 30 ; var gamma : OclAny := new_value; var delta : int := new_value ; execute (gamma)->display() ; execute (delta)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- octal_value = 0o1234 hex_value = 0xABC binary_value = 0b1010 print(octal_value) print(hex_value) print(binary_value) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var octal_value : int := 0o1234 ; var hex_value : int := 0xABC ; var binary_value : int := 0b1010 ; execute (octal_value)->display() ; execute (hex_value)->display() ; execute (binary_value)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- data = {'x': 4, 'y': 5, 'z': 6} pairs = data.items() print(pairs) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var data : Map := Map{ 'x' |-> 4 }->union(Map{ 'y' |-> 5 }->union(Map{ 'z' |-> 6 })) ; var pairs : Sequence := data->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) ; execute (pairs)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cube = lambda n: n ** 3 result = cube(3) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cube : Function := lambda n : OclAny in ((n)->pow(3)) ; var result : OclAny := cube->apply(3) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- power_two = lambda num: num ** 2 power_three = lambda val: val ** 3 functions = [power_two, power_three] for function in functions: print(function(4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var power_two : Function := lambda num : OclAny in ((num)->pow(2)) ; var power_three : Function := lambda val : OclAny in ((val)->pow(3)) ; var functions : Sequence := Sequence{power_two}->union(Sequence{ power_three }) ; for function : functions do ( execute (function(4))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- letters = ['x', 'y', 'z', 'w', 'v'] print(len(letters)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var letters : Sequence := Sequence{'x'}->union(Sequence{'y'}->union(Sequence{'z'}->union(Sequence{'w'}->union(Sequence{ 'v' })))) ; execute ((letters)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- list_a = [4, 5, 6] list_b = [4, 5, 6] print(str(list_a is list_b)) print(str(list_a == list_b)) list_c = list_a print(str(list_a is list_c)) print(str(list_a == list_c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var list_a : Sequence := Sequence{4}->union(Sequence{5}->union(Sequence{ 6 })) ; var list_b : Sequence := Sequence{4}->union(Sequence{5}->union(Sequence{ 6 })) ; execute (("" + ((list_a <>= list_b))))->display() ; execute (("" + ((list_a = list_b))))->display() ; var list_c : Sequence := list_a ; execute (("" + ((list_a <>= list_c))))->display() ; execute (("" + ((list_a = list_c))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- first = 'x' second = 'y' third = 'z' mapping = {first: 7, second: 8, third: 9} print(mapping['second']) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var first : String := 'x' ; var second : String := 'y' ; var third : String := 'z' ; var mapping : Map := Map{ first |-> 7 }->union(Map{ second |-> 8 }->union(Map{ third |-> 9 })) ; execute (mapping->at('second'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- key_one = 'p' key_two = 'q' key_three = 'r' dict_part = {key_three: 5} combined_dict = {key_one: 4, **dict_part, key_two: 6} print(combined_dict['r']) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var key_one : String := 'p' ; var key_two : String := 'q' ; var key_three : String := 'r' ; var dict_part : Map := Map{ key_three |-> 5 } ; var combined_dict : Map := Map{ key_one |-> 4 }->union(dict_part->union(Map{ key_two |-> 6 })) ; execute (combined_dict->at('r'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- info = dict({"apple": 10, "banana": 20, "cherry": 30}) print(info["apple"]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var info : Map := (Map{ "apple" |-> 10 }->union(Map{ "banana" |-> 20 }->union(Map{ "cherry" |-> 30 }))) ; execute (info->at("apple"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- data_map = dict({"alpha": 7, "beta": 8, "gamma": 9}) keys_list = [key for key in data_map] print(keys_list) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var data_map : Map := (Map{ "alpha" |-> 7 }->union(Map{ "beta" |-> 8 }->union(Map{ "gamma" |-> 9 }))) ; var keys_list : Sequence := data_map->keys()->select(key | true)->collect(key | (key)) ; execute (keys_list)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num = 2048 num <<= 3 num >>= 4 num **= 2 value = 500 value <<= 1 value >>= 2 value **= 3 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := 2048 ; num := num * (2->pow(3)) ; num := num div (2->pow(4)) ; num := num->pow(2) ; var value : int := 500 ; value := value * (2->pow(1)) ; value := value div (2->pow(2)) ; value := value->pow(3); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- strings = ["apple", "banana", "kiwi", "fig", "grapefruit"] check_length = lambda word: len(word) > 3 results = map(check_length, strings) print(any(results)) print(all(results)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var strings : Sequence := Sequence{"apple"}->union(Sequence{"banana"}->union(Sequence{"kiwi"}->union(Sequence{"fig"}->union(Sequence{ "grapefruit" })))) ; var check_length : Function := lambda word : OclAny in ((word)->size() > 3) ; var results : Sequence := (strings)->collect( _x | (check_length)->apply(_x) ) ; execute ((results)->exists( _x | _x = true ))->display() ; execute ((results)->forAll( _x | _x = true ))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- first_dict = dict({"one": 10, "two": 20, "three": 30}) second_dict = dict({"two": 25, "three": 15, "four": 40}) merged_dict = first_dict | second_dict print(merged_dict) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var first_dict : Map := (Map{ "one" |-> 10 }->union(Map{ "two" |-> 20 }->union(Map{ "three" |-> 30 }))) ; var second_dict : Map := (Map{ "two" |-> 25 }->union(Map{ "three" |-> 15 }->union(Map{ "four" |-> 40 }))) ; var merged_dict : Map := first_dict->union(second_dict) ; execute (merged_dict)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math result_cosh = math.cosh(1.0) result_prod = math.prod([2, 3, 4, 5, 6]) result_pow = math.pow(2, 4) result_comb = math.comb(6, 3) result_factorial = math.factorial(7) result_trunc = math.trunc(4.8) result_sqrt = math.sqrt(9.0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var result_cosh : double := (1.0)->cosh() ; var result_prod : double := (Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 })))))->prd() ; var result_pow : double := (2)->pow(4) ; var result_comb : long := MathLib.combinatorial(6, 3) ; var result_factorial : long := MathLib.factorial(7) ; var result_trunc : int := (4.8)->oclAsType(int) ; var result_sqrt : double := (9.0)->sqrt(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lista = [5, 6, 7, 8, 7, 6, 5] listb = [1, 2, 4, 8, 3, 4, 5] productlist = [m * n for m in lista for n in listb] print(productlist) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lista : Sequence := Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{7}->union(Sequence{6}->union(Sequence{ 5 })))))) ; var listb : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{8}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))))) ; var productlist : Sequence := lista->select(m; n : listb | true)->collect(m; n : listb | (m * n)) ; execute (productlist)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class BaseClass: def display(self): print("In BaseClass") class DerivedOne(BaseClass): def display(self): print("In DerivedOne") class DerivedTwo(BaseClass): def display(self): print("In DerivedTwo") class ExtraClass(BaseClass): def display(self): print("In ExtraClass") class CombinedClass(DerivedOne, DerivedTwo, ExtraClass): pass instance = CombinedClass() instance.display() # result is: In DerivedOne. ------------------------------------------------------------ OCL File: --------- class BaseClass { static operation newBaseClass() : BaseClass pre: true post: BaseClass->exists( _x | result = _x ); operation display() pre: true post: true activity: execute ("In BaseClass")->display(); } class DerivedOne extends BaseClass { static operation newDerivedOne() : DerivedOne pre: true post: DerivedOne->exists( _x | result = _x ); operation display() pre: true post: true activity: execute ("In DerivedOne")->display(); } class DerivedTwo extends BaseClass { static operation newDerivedTwo() : DerivedTwo pre: true post: DerivedTwo->exists( _x | result = _x ); operation display() pre: true post: true activity: execute ("In DerivedTwo")->display(); } class ExtraClass extends BaseClass { static operation newExtraClass() : ExtraClass pre: true post: ExtraClass->exists( _x | result = _x ); operation display() pre: true post: true activity: execute ("In ExtraClass")->display(); } class CombinedClass extends DerivedOne, DerivedTwo, ExtraClass { static operation newCombinedClass() : CombinedClass pre: true post: CombinedClass->exists( _x | result = _x ); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var instance : CombinedClass := (CombinedClass.newCombinedClass()).initialise() ; instance.display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Individual: identifier = "" class Position: title = "" class Department: name = "" class Supervisor(Individual, Position): responsibilities = [] class TeamLead(Supervisor, Department): team = [] person = Individual() person.identifier = "Alice" role = Position() role.title = "Engineer" department = Department() department.name = "Development" manager = Supervisor() manager.responsibilities = ["Project A", "Project B"] team_lead = TeamLead() team_lead.team = ["Member1", "Member2"] ------------------------------------------------------------ OCL File: --------- class Individual { static operation newIndividual() : Individual pre: true post: Individual->exists( _x | result = _x ); static attribute identifier : String := ""; } class Position { static operation newPosition() : Position pre: true post: Position->exists( _x | result = _x ); static attribute title : String := ""; } class Department { static operation newDepartment() : Department pre: true post: Department->exists( _x | result = _x ); static attribute name : String := ""; } class Supervisor extends Individual, Position { static operation newSupervisor() : Supervisor pre: true post: Supervisor->exists( _x | result = _x ); static attribute responsibilities : Sequence := Sequence{}; } class TeamLead extends Supervisor, Department { static operation newTeamLead() : TeamLead pre: true post: TeamLead->exists( _x | result = _x ); static attribute team : Sequence := Sequence{}; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var person : Individual := (Individual.newIndividual()).initialise() ; person.identifier := "Alice" ; var role : Position := (Position.newPosition()).initialise() ; role.title := "Engineer" ; var department : Department := (Department.newDepartment()).initialise() ; department.name := "Development" ; var manager : Supervisor := (Supervisor.newSupervisor()).initialise() ; manager.responsibilities := Sequence{"Project A"}->union(Sequence{ "Project B" }) ; var team_lead : TeamLead := (TeamLead.newTeamLead()).initialise() ; team_lead.team := Sequence{"Member1"}->union(Sequence{ "Member2" }); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- val = 456 print(type(val)) val = 3.14 print(type(val)) val = "example text" print(type(val)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var val : int := 456 ; execute ((val)->oclType())->display() ; val := 3.14 ; execute ((val)->oclType())->display() ; val := "example text" ; execute ((val)->oclType())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- char = 'd' list1 = ['x', 'y', 'd','p'] list2 = [['x', 'y', 'd','p'], ['u', 'v', 'w','y']] if char in list1 in list2: print(list1) else: print(list2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var char : String := 'd' ; var list1 : Sequence := Sequence{'x'}->union(Sequence{'y'}->union(Sequence{'d'}->union(Sequence{ 'p' }))) ; var list2 : Sequence := Sequence{Sequence{'x'}->union(Sequence{'y'}->union(Sequence{'d'}->union(Sequence{ 'p' })))}->union(Sequence{ Sequence{'u'}->union(Sequence{'v'}->union(Sequence{'w'}->union(Sequence{ 'y' }))) }) ; if (list1)->includes(char) & (list2->includes(list1)) then ( execute (list1)->display() ) else ( execute (list2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def modify_var(): global num num = 5 return num num = 50 modify_var() print(num) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute num : OclAny; operation initialise() pre: true post: true activity: skip ; num := 50 ; modify_var() ; execute (num)->display(); operation modify_var() : OclAny pre: true post: true activity: skip ; num := 5 ; return num; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np matrix = [[7, 8, 9], [10, 11, 12]] print(np.shape(matrix)) array1 = np.arange(5) print(array1) array2 = np.arange(4.0) print(array2) array3 = np.arange(5, 10) print(array3) array4 = np.arange(2, 10, 3) print(array4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var matrix : Sequence := Sequence{Sequence{7}->union(Sequence{8}->union(Sequence{ 9 }))}->union(Sequence{ Sequence{10}->union(Sequence{11}->union(Sequence{ 12 })) }) ; execute (MatrixLib.shape(matrix))->display() ; var array1 : Sequence := MathLib.numericRange(0, (5), 1) ; execute (array1)->display() ; var array2 : Sequence := MathLib.numericRange(0, (4.0), 1) ; execute (array2)->display() ; var array3 : Sequence := MathLib.numericRange(5, 10, 1) ; execute (array3)->display() ; var array4 : Sequence := MathLib.numericRange(2, 10, 3) ; execute (array4)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num = 8 num += 7 num *= 4 num /= 3 num //= 1 value = 15 value += 5 value *= 2 value /= 5 value //= 3 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := 8 ; num := num + 7 ; num := num * 4 ; num := num / 3 ; num := num div 1 ; var value : int := 15 ; value := value + 5 ; value := value * 2 ; value := value / 5 ; value := value div 3; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np matrix = [[10, 20, 30], [40, 50, 60]] array1 = np.empty((3, 3)) print(array1) array2 = np.empty_like(matrix) print(array2) array3 = np.eye(4) print(array3) array4 = np.identity(5) print(array4) array5 = np.ones_like(matrix) print(array5) array6 = np.full([4], 15) print(array6) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var matrix : Sequence := Sequence{Sequence{10}->union(Sequence{20}->union(Sequence{ 30 }))}->union(Sequence{ Sequence{40}->union(Sequence{50}->union(Sequence{ 60 })) }) ; var array1 : Sequence := MatrixLib.singleValueMatrix(Sequence{3, 3}, 0.0) ; execute (array1)->display() ; var array2 : Sequence := MatrixLib.singleValueMatrix(MatrixLib.shape(matrix), 0.0) ; execute (array2)->display() ; var array3 : Sequence := MatrixLib.identityMatrix(4) ; execute (array3)->display() ; var array4 : Sequence := MatrixLib.identityMatrix(5) ; execute (array4)->display() ; var array5 : Sequence := MatrixLib.singleValueMatrix(MatrixLib.shape(matrix), 1.0) ; execute (array5)->display() ; var array6 : Sequence := MatrixLib.singleValueMatrix(Sequence{ 4 }, 15) ; execute (array6)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np matrix = np.ones([3, 4]) shape_info = matrix.shape print(shape_info[1]) matrix[:, 1] = matrix[:, 1] * 4 matrix[:, 2] = matrix[:, 2] + 6 print(matrix) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var matrix : Sequence := MatrixLib.singleValueMatrix(Sequence{3}->union(Sequence{ 4 }), 1.0) ; var shape_info : Sequence := MatrixLib.shape(matrix) ; execute (shape_info[1+1])->display() ; matrix->collect( _r | _r[1+1] ) := MatrixLib.elementwiseMult(matrix->collect( _r | _r[1+1] ), 4) ; matrix->collect( _r | _r[2+1] ) := MatrixLib.elementwiseAdd(matrix->collect( _r | _r[2+1] ), 6) ; execute (matrix)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np matrix = np.ones([3, 4]) matrix[:, 1] = matrix[:, 1] * 7 matrix[:, 2] = np.sqrt(matrix[:, 1]) matrix[:, 0] = matrix[:, 0] * 4e+9 print(matrix) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var matrix : Sequence := MatrixLib.singleValueMatrix(Sequence{3}->union(Sequence{ 4 }), 1.0) ; matrix->collect( _r | _r[1+1] ) := MatrixLib.elementwiseMult(matrix->collect( _r | _r[1+1] ), 7) ; matrix->collect( _r | _r[2+1] ) := MatrixLib.elementwiseApply(matrix->collect( _r | _r[1+1] ), lambda x : double in (x->sqrt())) ; matrix->collect( _r | _r->first() ) := MatrixLib.elementwiseMult(matrix->collect( _r | _r->first() ), ("4e+9")->toReal()) ; execute (matrix)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np array = np.ones([3, 4]) array[2, :] = 6 array[:, 0] = 4 print(array) transposed_array = np.transpose(array) squared_array = array * array print(squared_array) print(transposed_array) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var array : Sequence := MatrixLib.singleValueMatrix(Sequence{3}->union(Sequence{ 4 }), 1.0) ; array[2+1] := 6 ; array->collect( _r | _r->first() ) := 4 ; execute (array)->display() ; var transposed_array : Sequence := MatrixLib.transpose(array) ; var squared_array : Sequence := MatrixLib.dotProduct(array,array) ; execute (squared_array)->display() ; execute (transposed_array)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np grid = np.ones([4, 4]) grid[2, :] = 8 grid[:, 1] = 7 total_sum = np.sum(grid) total_product = np.prod(grid) print(total_product) print(grid < 10) print(total_sum) print(grid) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var grid : Sequence := MatrixLib.singleValueMatrix(Sequence{4}->union(Sequence{ 4 }), 1.0) ; grid[2+1] := 8 ; grid->collect( _r | _r[1+1] ) := 7 ; var total_sum : double := MatrixLib.sumMatrix(grid) ; var total_product : double := MatrixLib.prdMatrix(grid) ; execute (total_product)->display() ; execute (MatrixLib.elementwiseLess(grid,10))->display() ; execute (total_sum)->display() ; execute (grid)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections ordered_dict = collections.OrderedDict({"one": 10, "two": 20, "three": 30}) ordered_dict["two"] = 25 ordered_dict["four"] = 40 print(ordered_dict) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var ordered_dict : Map := (Map{ "one" |-> 10 }->union(Map{ "two" |-> 20 }->union(Map{ "three" |-> 30 }))) ; ordered_dict->at("two") := 25 ; ordered_dict->at("four") := 40 ; execute (ordered_dict)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- string_value = "sample" char_list = ['x', 'y', 'z'] def modify_elements(text, chars): text = text + 'y' chars[2] = 'w' print(char_list) print(string_value) print("") modify_elements(string_value, char_list) print(char_list) print(string_value) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var string_value : String := "sample" ; var char_list : Sequence := Sequence{'x'}->union(Sequence{'y'}->union(Sequence{ 'z' })) ; skip ; execute (char_list)->display() ; execute (string_value)->display() ; execute ("")->display() ; modify_elements(string_value, char_list) ; execute (char_list)->display() ; execute (string_value)->display(); operation modify_elements(text : OclAny, chars : OclAny) pre: true post: true activity: text := text + 'y' ; chars[2+1] := 'w'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- unique_items = set({'x', 'y', 'z'}) def update_set(item_set): item_set.add('a') item_set.update(set({'b', 'c'})) item_set.difference_update(set({'x', 'y'})) item_set.discard('z') print(unique_items) print("") update_set(unique_items) print(unique_items) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var unique_items : Set := Set{}->union((Set{'x'}->union(Set{'y'}->union(Set{ 'z' })))) ; skip ; execute (unique_items)->display() ; execute ("")->display() ; update_set(unique_items) ; execute (unique_items)->display(); operation update_set(item_set : OclAny) pre: true post: true activity: execute (('a') : item_set) ; execute ((Set{}->union((Set{'b'}->union(Set{ 'c' })))) <: item_set) ; execute ((Set{}->union((Set{'x'}->union(Set{ 'y' })))) /<: item_set) ; execute (('z') /: item_set); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- value = 200 items = ['x', 'y', 'z'] class Individual: def __init__(self): self.identifier = "" self.years = 30 individual = Individual() def update_vars(number, collection, person): number = number + 20 collection.append('e') person.identifier = "Jordan" person.years = person.years + 2 print(value) print(items) print(individual.identifier) print(individual.years) print("") update_vars(value, items, individual) print(value) print(items) print(individual.identifier) print(individual.years) ------------------------------------------------------------ OCL File: --------- class Individual { static operation newIndividual() : Individual pre: true post: Individual->exists( _x | result = _x ); attribute identifier : String := ""; attribute years : int := 30; operation initialise() : Individual pre: true post: true activity: self.identifier := "" ; self.years := 30; return self; } class FromPython { operation initialise() pre: true post: true activity: var value : int := 200 ; var items : Sequence := Sequence{'x'}->union(Sequence{'y'}->union(Sequence{ 'z' })) ; skip ; var individual : Individual := (Individual.newIndividual()).initialise() ; skip ; execute (value)->display() ; execute (items)->display() ; execute (individual.identifier)->display() ; execute (individual.years)->display() ; execute ("")->display() ; update_vars(value, items, individual) ; execute (value)->display() ; execute (items)->display() ; execute (individual.identifier)->display() ; execute (individual.years)->display(); operation update_vars(number : OclAny, collection : OclAny, person : OclAny) pre: true post: true activity: number := number + 20 ; execute (('e') : collection) ; person.identifier := "Jordan" ; person.years := person.years + 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- data = ["x", "y", "z","r"] pickle.dump(data, file_handle) loaded_data = pickle.load(file_handle) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var data : Sequence := Sequence{"x"}->union(Sequence{"y"}->union(Sequence{"z"}->union(Sequence{ "r" }))) ; file_handle.writeObject(data) ; var loaded_data : OclAny := (file_handle).readObject(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from datetime import * current_date = datetime.now() print(hasattr(current_date, 'month')) print(hasattr(current_date, 'day')) print(getattr(current_date, 'minute')) future_date = datetime.now() print(hasattr(future_date, 'second')) print(getattr(future_date, 'year')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var current_date : OclDate := OclDate.newOclDate() ; execute (OclType.hasAttribute(current_date, 'month'))->display() ; execute (OclType.hasAttribute(current_date, 'day'))->display() ; execute (OclType.getAttributeValue(current_date, 'minute'))->display() ; var future_date : OclDate := OclDate.newOclDate() ; execute (OclType.hasAttribute(future_date, 'second'))->display() ; execute (OclType.getAttributeValue(future_date, 'year'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- identifier = "Employee" print(identifier + " details") print(identifier) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var identifier : String := "Employee" ; execute (identifier + " details")->display() ; execute (identifier)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import random generator = random.Random() value1 = generator.gauss(2.0, 3.0) value2 = generator.randrange(20) value3 = generator.uniform(1.0, 7.0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var generator : OclRandom := OclRandom.newOclRandom() ; var value1 : double := generator.nextNormal(2.0, (3.0)->sqr()) ; var value2 : int := generator.nextInt(20) ; var value3 : double := generator.nextUniform(1.0, 7.0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import random value = random.random() numbers = [7, 8, 9, 10, 11, 12] draw = random.sample(numbers, 4) print(value) print(draw) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var value : double := (OclRandom.defaultInstanceOclRandom()).nextDouble() ; var numbers : Sequence := Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{10}->union(Sequence{11}->union(Sequence{ 12 }))))) ; var draw : Sequence := OclRandom.randomUniqueElements(numbers, 4) ; execute (value)->display() ; execute (draw)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sequence1 = range(6) sequence2 = range(2, 7) sequence3 = range(2, 20, 5) letters = ['X', 'Y', 'Z'] indexed_letters = enumerate(letters) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sequence1 : Sequence := Integer.subrange(0, 6-1) ; var sequence2 : Sequence := Integer.subrange(2, 7-1) ; var sequence3 : Sequence := Integer.subrange(2, 20-1)->select( $x | ($x - 2) mod 5 = 0 ) ; var letters : Sequence := Sequence{'X'}->union(Sequence{'Y'}->union(Sequence{ 'Z' })) ; var indexed_letters : Sequence := Integer.subrange(1, (letters)->size())->collect( _indx | Sequence{_indx-1, (letters)->at(_indx)} ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(r"\t\r\v") text = "Sample text" number = 42 result = f"Text: {text}, Number: {number}" print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (StringLib.rawString("\t\r\v"))->display() ; var text : String := "Sample text" ; var number : int := 42 ; var result : String := StringLib.formattedString("Text: {text}, Number: {number}") ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re match = re.fullmatch("[A-Z]*", "HELLO") replacement = re.sub("O", "0", "HELLO") matches = re.findall("[A-Z]*", "A QUICK BROWN FOX") print(match) print(replacement) print(matches) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var match : String := ("HELLO")->firstMatch("^" + "[A-Z]*" + "$") ; var replacement : String := ("HELLO").replaceAllMatches("O", "0") ; var matches : Sequence(String) := ("A QUICK BROWN FOX")->allMatches("[A-Z]*") ; execute (match)->display() ; execute (replacement)->display() ; execute (matches)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sequence = list(["xx", "yyy", "zz", "ww", "ffff"]) reversed_seq = reversed(sequence) sorted_seq = sorted(reversed_seq) smallest = min(sequence) largest = max(sequence) print(smallest) print(sorted_seq) print(largest) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sequence : Sequence := (Sequence{"xx"}->union(Sequence{"yyy"}->union(Sequence{"zz"}->union(Sequence{"ww"}->union(Sequence{ "ffff" }))))) ; var reversed_seq : Sequence := (sequence)->reverse() ; var sorted_seq : Sequence := reversed_seq->sort() ; var smallest : OclAny := (sequence)->min() ; var largest : OclAny := (sequence)->max() ; execute (smallest)->display() ; execute (sorted_seq)->display() ; execute (largest)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numbers = [2, 3, 4, 5, 6,7,8,9,10] squares = [n * n for n in numbers if n % 2 == 0 if n < 10] print(squares) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var numbers : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{ 10 })))))))) ; var squares : Sequence := numbers->select(n | n mod 2 = 0 & n < 10)->collect(n | (n * n)) ; execute (squares)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- values = [8, 9, 10, 11, 12,13,14,15,16,17] squares = [n * n for n in values if n % 2 == 0] print(squares) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var values : Sequence := Sequence{8}->union(Sequence{9}->union(Sequence{10}->union(Sequence{11}->union(Sequence{12}->union(Sequence{13}->union(Sequence{14}->union(Sequence{15}->union(Sequence{16}->union(Sequence{ 17 }))))))))) ; var squares : Sequence := values->select(n | n mod 2 = 0)->collect(n | (n * n)) ; execute (squares)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mm = [34, 48, 4] print(mm) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mm : Sequence := Sequence{34}->union(Sequence{48}->union(Sequence{ 4 })) ; execute (mm)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- is_enabled: bool is_enabled = False upper_limit: int = 300 lower_limit: int = 25 additional_value: int = 45 status_flag: bool = True ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var is_enabled : boolean ; is_enabled := false ; var upper_limit : int := 300 ; var lower_limit : int := 25 ; var additional_value : int := 45 ; var status_flag : boolean := true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import asyncio async def process(task_id): print("task " + str(task_id) + " started") await asyncio.sleep(3) print("task " + str(task_id) + " finished") async def run_operations(): job1 = asyncio.create_task(process(7)) await asyncio.sleep(2) job2 = asyncio.create_task(process(8)) await job1 await job2 asyncio.run(run_operations()) ------------------------------------------------------------ OCL File: --------- class Async$process { stereotype active; attribute task_id : OclAny; static operation newAsync$process(task_id : OclAny) : Async$process pre: true post: Async$process->exists( resx | resx.task_id = task_id & result = resx ); operation run() pre: true post: true activity: execute ("task " + ("" + ((task_id))) + " started")->display() ; OclProcess.sleepSeconds(3) ; execute ("task " + ("" + ((task_id))) + " finished")->display(); } class Async$run_operations { stereotype active; static operation newAsync$run_operations() : Async$run_operations pre: true post: Async$run_operations->exists( resx | result = resx ); operation run() pre: true post: true activity: var job1 : OclProcess := (OclProcess.newOclProcess(Async$process.newAsync$process(7), "")).startProcess() ; OclProcess.sleepSeconds(2) ; var job2 : OclProcess := (OclProcess.newOclProcess(Async$process.newAsync$process(8), "")).startProcess() ; job1.join() ; job2.join(); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; (OclProcess.newOclProcess(Async$run_operations.newAsync$run_operations(), "")).start(); operation process(task_id : OclAny) pre: true post: true activity: execute ("task " + ("" + ((task_id))) + " started")->display() ; OclProcess.sleepSeconds(3) ; execute ("task " + ("" + ((task_id))) + " finished")->display(); operation run_operations() pre: true post: true activity: var job1 : OclProcess := (OclProcess.newOclProcess(Async$process.newAsync$process(7), "")).startProcess() ; OclProcess.sleepSeconds(2) ; var job2 : OclProcess := (OclProcess.newOclProcess(Async$process.newAsync$process(8), "")).startProcess() ; job1.join() ; job2.join(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- values = [12, 13, 14] combined_list = [5, *values, 20] jj=90 jj=jj+9*6-3 print(combined_list) print(jj) extra_values = [25, 30] jj=jj+9 print(extra_values) print(jj) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var values : Sequence := Sequence{12}->union(Sequence{13}->union(Sequence{ 14 })) ; var combined_list : Sequence := Sequence{5}->union(values->union(Sequence{ 20 })) ; var jj : int := 90 ; jj := jj + 9 * 6 - 3 ; execute (combined_list)->display() ; execute (jj)->display() ; var extra_values : Sequence := Sequence{25}->union(Sequence{ 30 }) ; jj := jj + 9 ; execute (extra_values)->display() ; execute (jj)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- elements = [14, 23, 31, 45, 67, 89, 123,55,33,65] multiples = [j * j+5 for j in elements] k=10 output = multiples k=k+100 print(k) print(output) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var elements : Sequence := Sequence{14}->union(Sequence{23}->union(Sequence{31}->union(Sequence{45}->union(Sequence{67}->union(Sequence{89}->union(Sequence{123}->union(Sequence{55}->union(Sequence{33}->union(Sequence{ 65 }))))))))) ; var multiples : Sequence := elements->select(j | true)->collect(j | (j * j + 5)) ; var k : int := 10 ; var output : Sequence := multiples ; k := k + 100 ; execute (k)->display() ; execute (output)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- data = [15, -7, 4, 9, -3,7,4,66,33] itemA = data[2] itemB = data[4] itemC = data[-3] itemD = data[-5] print(itemA) print(itemB) print(itemC) print(itemD) extra_item = data[1] print(extra_item) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var data : Sequence := Sequence{15}->union(Sequence{-7}->union(Sequence{4}->union(Sequence{9}->union(Sequence{-3}->union(Sequence{7}->union(Sequence{4}->union(Sequence{66}->union(Sequence{ 33 })))))))) ; var itemA : OclAny := data[2+1] ; var itemB : OclAny := data[4+1] ; var itemC : OclAny := data->reverse()->at(-(-3)) ; var itemD : OclAny := data->reverse()->at(-(-5)) ; execute (itemA)->display() ; execute (itemB)->display() ; execute (itemC)->display() ; execute (itemD)->display() ; var extra_item : OclAny := data[1+1] ; execute (extra_item)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- digits = [12, -6, 8, 15, 5,6,4,8,9] partA = digits[2:] partB = digits[:-2] a=90 print(partB) b=88 print(partA) print(a+b*10) additional_part = digits[1:4] print(additional_part) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var digits : Sequence := Sequence{12}->union(Sequence{-6}->union(Sequence{8}->union(Sequence{15}->union(Sequence{5}->union(Sequence{6}->union(Sequence{4}->union(Sequence{8}->union(Sequence{ 9 })))))))) ; var partA : OclAny := digits.subrange(2+1) ; var partB : OclAny := digits->front()->front() ; var a : int := 90 ; execute (partB)->display() ; var b : int := 88 ; execute (partA)->display() ; execute (a + b * 10)->display() ; var additional_part : OclAny := digits.subrange(1+1, 4) ; execute (additional_part)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- items = [11, -5, 9, 14, -7,6,4,8,9,5,6,7,8,6,4] segmentA = items[2:-3] segmentB = items[-4:-2] j=10 segmentC = items[1:3] print(j) print(segmentC) print(segmentA) print(segmentB) print(j+7*80) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var items : Sequence := Sequence{11}->union(Sequence{-5}->union(Sequence{9}->union(Sequence{14}->union(Sequence{-7}->union(Sequence{6}->union(Sequence{4}->union(Sequence{8}->union(Sequence{9}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{6}->union(Sequence{ 4 })))))))))))))) ; var segmentA : OclAny := items.subrange(2+1, -3) ; var segmentB : OclAny := items.subrange(-4+1, -2) ; var j : int := 10 ; var segmentC : OclAny := items.subrange(1+1, 3) ; execute (j)->display() ; execute (segmentC)->display() ; execute (segmentA)->display() ; execute (segmentB)->display() ; execute (j + 7 * 80)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- data = [10, -3, 12, 4, 8] final_item = data[-2] print(final_item) x=10 x=x+5 merged_list = [final_item] m=3 expanded_list = merged_list + data print(m) print(expanded_list) total = sum(expanded_list) mean = total / len(expanded_list)+4 print(m+x) print("Sum:", total) print("Average:", mean) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var data : Sequence := Sequence{10}->union(Sequence{-3}->union(Sequence{12}->union(Sequence{4}->union(Sequence{ 8 })))) ; var final_item : OclAny := data->front()->last() ; execute (final_item)->display() ; var x : int := 10 ; x := x + 5 ; var merged_list : Sequence := Sequence{ final_item } ; var m : int := 3 ; var expanded_list : Sequence := merged_list->union(data) ; execute (m)->display() ; execute (expanded_list)->display() ; var total : OclAny := (expanded_list)->sum() ; var mean : double := total / (expanded_list)->size() + 4 ; execute (m + x)->display() ; execute ("Sum:")->display() ; execute ("Average:")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_collection = {3, 9, 2, 6,5,8,9} m=10 print(m) print(len(num_collection)) extra_elements = {12, 7,6,8,9} num_collection.update(extra_elements) print(num_collection) print(m) print("Updated set length:", len(num_collection)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_collection : Set := Set{3}->union(Set{9}->union(Set{2}->union(Set{6}->union(Set{5}->union(Set{8}->union(Set{ 9 })))))) ; var m : int := 10 ; execute (m)->display() ; execute ((num_collection)->size())->display() ; var extra_elements : Set := Set{12}->union(Set{7}->union(Set{6}->union(Set{8}->union(Set{ 9 })))) ; execute ((extra_elements) <: num_collection) ; execute (num_collection)->display() ; execute (m)->display() ; execute ("Updated set length:")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- group1 = {11, 13} group2 = {17, 19} distinct_nums = {1, 3, 5, 7} m = 90 distinct_nums.update(group1, group2) m = m + 90 print("Updated set:", distinct_nums) n = 10 distinct_nums.discard(5) n = n + 10 print("After discarding 5:", distinct_nums) if 11 in distinct_nums: print("11 is in the set") else: print("11 is not in the set") print("Hi") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var group1 : Set := Set{11}->union(Set{ 13 }) ; var group2 : Set := Set{17}->union(Set{ 19 }) ; var distinct_nums : Set := Set{1}->union(Set{3}->union(Set{5}->union(Set{ 7 }))) ; var m : int := 90 ; execute ((group1, group2) <: distinct_nums) ; m := m + 90 ; execute ("Updated set:")->display() ; var n : int := 10 ; execute ((5) /: distinct_nums) ; n := n + 10 ; execute ("After discarding 5:")->display() ; if (distinct_nums)->includes(11) then ( execute ("11 is in the set")->display() ) else ( execute ("11 is not in the set")->display() ) ; execute ("Hi")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_group = {2, 3, 4,6,7} removed_item = num_group.pop() additional_numbers = {5, 6, 7,4,5} num_group.update(additional_numbers) print("Updated set:", num_group) print(removed_item) print(num_group) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_group : Set := Set{2}->union(Set{3}->union(Set{4}->union(Set{6}->union(Set{ 7 })))) ; var removed_item : OclAny := num_group->last() ; num_group := num_group->front() ; var additional_numbers : Set := Set{5}->union(Set{6}->union(Set{7}->union(Set{4}->union(Set{ 5 })))) ; execute ((additional_numbers) <: num_group) ; execute ("Updated set:")->display() ; execute (removed_item)->display() ; execute (num_group)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- symbol_set = {'m', 'n', 'o','y','p'} symbol_set.intersection_update({'m', 'n', 'p','a','b'}) x=44 print(symbol_set) x=x*9 symbol_set.add('q') symbol_set.add('r') y=8 y=y+x symbol_set.clear() print(y) print(symbol_set) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var symbol_set : Set := Set{'m'}->union(Set{'n'}->union(Set{'o'}->union(Set{'y'}->union(Set{ 'p' })))) ; execute ((symbol_set - (Set{'m'}->union(Set{'n'}->union(Set{'p'}->union(Set{'a'}->union(Set{ 'b' })))))) /<: symbol_set) ; var x : int := 44 ; execute (symbol_set)->display() ; x := x * 9 ; execute (('q') : symbol_set) ; execute (('r') : symbol_set) ; var y : int := 8 ; y := y + x ; execute (symbol_set /<: symbol_set) ; execute (y)->display() ; execute (symbol_set)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class aaaa: name = "" age = 0 def __init__(self, name, age): self.name = name self.age = age cc1 = aaaa("aaa", 40) cc2 = aaaa("ffff", 35) ------------------------------------------------------------ OCL File: --------- class aaaa { static operation newaaaa() : aaaa pre: true post: aaaa->exists( _x | result = _x ); static attribute name : String := ""; static attribute age : int := 0; attribute name : String := name; attribute age : int := age; operation initialise(name : OclAny,age : OclAny) : aaaa pre: true post: true activity: self.name := name ; self.age := age; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; var cc1 : aaaa := (aaaa.newaaaa()).initialise("aaa", 40) ; var cc2 : aaaa := (aaaa.newaaaa()).initialise("ffff", 35); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- values = [5, 15, 25, 35,66,77,88,44] deleted_item = values.pop(2) f=9 g=7 print("Removed item:", deleted_item) print(f+g) print("Remaining list:", values) print(f*g) values.append(45) print("List after appending 45:", values) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var values : Sequence := Sequence{5}->union(Sequence{15}->union(Sequence{25}->union(Sequence{35}->union(Sequence{66}->union(Sequence{77}->union(Sequence{88}->union(Sequence{ 44 }))))))) ; var deleted_item : OclAny := values->at(2`firstArg+1) ; values := values->excludingAt(2+1) ; var f : int := 9 ; var g : int := 7 ; execute ("Removed item:")->display() ; execute (f + g)->display() ; execute ("Remaining list:")->display() ; execute (f * g)->display() ; execute ((45) : values) ; execute ("List after appending 45:")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=10 entry = input("Enter a value: ") m=m+8 value_type = type(entry) print(m) segment_one = slice(4) n=7 segment_two = slice(2, 9) n=n+m print("Type of entry:", value_type) print(n) print("Segment one:", entry[segment_one]) print("Segment two:", entry[segment_two]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : int := 10 ; var entry : String := (OclFile["System.in"]).readLine("Enter a value: ") ; m := m + 8 ; var value_type : OclType := (entry)->oclType() ; execute (m)->display() ; var segment_one : Sequence := Integer.subrange(1,4) ; var n : int := 7 ; var segment_two : Sequence := Integer.subrange(2+1,9) ; n := n + m ; execute ("Type of entry:")->display() ; execute (n)->display() ; execute ("Segment one:")->display() ; execute ("Segment two:")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Student: def __init__(self, name, age): self.name = name self.age = age def __repr__(self): return repr((self.name, self.age)) student_group = [ Student('hjhghg', 15), Student('gfdgdg', 12), Student('dsadad', 14) ] sorted_students = sorted(student_group, key=lambda student: student.age) print(sorted_students) ------------------------------------------------------------ OCL File: --------- class Student { static operation newStudent() : Student pre: true post: Student->exists( _x | result = _x ); attribute name : int := name; attribute age : OclAny := age; operation initialise(name : OclAny,age : OclAny) : Student pre: true post: true activity: self.name := name ; self.age := age; return self; operation __repr__() : OclAny pre: true post: true activity: return ("" + ((Sequence{self.name, self.age}))); } class FromPython { operation initialise() pre: true post: true activity: skip ; var student_group : Sequence := Sequence{(Student.newStudent()).initialise('hjhghg', 15)}->union(Sequence{(Student.newStudent()).initialise('gfdgdg', 12)}->union(Sequence{ (Student.newStudent()).initialise('dsadad', 14) })) ; var sorted_students : Sequence := student_group->sortedBy($x | (lambda student : OclAny in (student.age))->apply($x)) ; execute (sorted_students)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- info_dict = {"a": 7, "d": 3, "b": 9, "c": 11, "k": 19, "l": 81} n=10 ordered_keys = sorted(info_dict) print(n) print(ordered_keys) n=n+90 ordered_values = sorted(info_dict.values()) print(n*9) print(ordered_values) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var info_dict : Map := Map{ "a" |-> 7 }->union(Map{ "d" |-> 3 }->union(Map{ "b" |-> 9 }->union(Map{ "c" |-> 11 }->union(Map{ "k" |-> 19 }->union(Map{ "l" |-> 81 }))))) ; var n : int := 10 ; var ordered_keys : Sequence := info_dict->keys()->sort() ; execute (n)->display() ; execute (ordered_keys)->display() ; n := n + 90 ; var ordered_values : Sequence := info_dict.values()->sort() ; execute (n * 9)->display() ; execute (ordered_values)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- value = -9.6 magnitude = abs(value) m=889 print(magnitude) print(m) positive_value = abs(-15.3) print(m+8) print(positive_value) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var value : double := -9.6 ; var magnitude : double := (value)->abs() ; var m : int := 889 ; execute (magnitude)->display() ; execute (m)->display() ; var positive_value : double := (-15.3)->abs() ; execute (m + 8)->display() ; execute (positive_value)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class MathCalc: def __init__(self, initial_value): self.value = initial_value def multiply_add_square(self, number): self.value += number self.value *= self.value return number * self.value def add_half_divide(self, number): self.value += number self.value //= 2 return self.value // number math_instance = MathCalc(8) print(math_instance.multiply_add_square(5)) print(math_instance.add_half_divide(4)) ------------------------------------------------------------ OCL File: --------- class MathCalc { static operation newMathCalc() : MathCalc pre: true post: MathCalc->exists( _x | result = _x ); attribute value : OclAny := initial_value; operation initialise(initial_value : OclAny) : MathCalc pre: true post: true activity: self.value := initial_value; return self; operation multiply_add_square(number : OclAny) : OclAny pre: true post: true activity: self.value := self.value + number ; self.value := self.value * self.value ; return number * self.value; operation add_half_divide(number : OclAny) : OclAny pre: true post: true activity: self.value := self.value + number ; self.value := self.value div 2 ; return self.value div number; } class FromPython { operation initialise() pre: true post: true activity: skip ; var math_instance : MathCalc := (MathCalc.newMathCalc()).initialise(8) ; execute (math_instance.multiply_add_square(5))->display() ; execute (math_instance.add_half_divide(4))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Evaluator: def __init__(self, initial_amount): self.total = initial_amount def process(self, value): if value > 0: self.total += value doubled_total = self.total * 2 result = value * doubled_total return result return value def analyze(self, value): if value > 1: self.total += value doubled_total = self.total * 2 result = doubled_total // value return result return value assessor = Evaluator(7) print(assessor.process(4)) print(assessor.analyze(8)) ------------------------------------------------------------ OCL File: --------- class Evaluator { static operation newEvaluator() : Evaluator pre: true post: Evaluator->exists( _x | result = _x ); attribute total : OclAny := initial_amount; operation initialise(initial_amount : OclAny) : Evaluator pre: true post: true activity: self.total := initial_amount; return self; operation process(value : OclAny) : OclAny pre: true post: true activity: if value > 0 then ( self.total := self.total + value ; var doubled_total : double := self.total * 2 ; var result : double := value * doubled_total ; return result ) else skip ; return value; operation analyze(value : OclAny) : OclAny pre: true post: true activity: if value > 1 then ( self.total := self.total + value ; doubled_total := self.total * 2 ; result := doubled_total div value ; return result ) else skip ; return value; } class FromPython { operation initialise() pre: true post: true activity: skip ; var assessor : Evaluator := (Evaluator.newEvaluator()).initialise(7) ; execute (assessor.process(4))->display() ; execute (assessor.analyze(8))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numbers = [10, -5, 6, 8, 3,7,3,5] biggest = max(9, 3) if biggest in {6, 10}: print(biggest + 3) smallest_value = min(7, 4) m=90 biggest_value = max(7, 4) print(m*9) print(smallest_value) print(biggest_value) print(min(numbers)) print(max(numbers)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var numbers : Sequence := Sequence{10}->union(Sequence{-5}->union(Sequence{6}->union(Sequence{8}->union(Sequence{3}->union(Sequence{7}->union(Sequence{3}->union(Sequence{ 5 }))))))) ; var biggest : OclAny := Set{9, 3}->max() ; if (Set{6}->union(Set{ 10 }))->includes(biggest) then ( execute (biggest + 3)->display() ) else skip ; var smallest_value : OclAny := Set{7, 4}->min() ; var m : int := 90 ; var biggest_value : OclAny := Set{7, 4}->max() ; execute (m * 9)->display() ; execute (smallest_value)->display() ; execute (biggest_value)->display() ; execute ((numbers)->min())->display() ; execute ((numbers)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- phrase = "sample string" nn=89 ascii_codes = [ord(letter) for letter in phrase] nn=nn*3 distinct_chars = set(phrase) print(nn) char_frequency = {letter: phrase.count(letter) for letter in distinct_chars} print(distinct_chars) print(ascii_codes) sorted_ascii = sorted(ascii_codes) print(char_frequency) print("Sorted ASCII values:", sorted_ascii) mm=10 most_frequent_char = max(char_frequency, key=char_frequency.get) print(mm+nn) print("Most frequent character:", most_frequent_char) ascii_sum = sum(ascii_codes) print("Sum of ASCII values:", ascii_sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var phrase : String := "sample string" ; var nn : int := 89 ; var ascii_codes : Sequence := phrase->characters()->select(letter | true)->collect(letter | ((letter)->char2byte())) ; nn := nn * 3 ; var distinct_chars : Set := Set{}->union((phrase)) ; execute (nn)->display() ; var char_frequency : Map := distinct_chars->select(letter | true)->collect(letter | Map{letter |-> phrase->count(letter)})->unionAll() ; execute (distinct_chars)->display() ; execute (ascii_codes)->display() ; var sorted_ascii : Sequence := ascii_codes->sort() ; execute (char_frequency)->display() ; execute ("Sorted ASCII values:")->display() ; var mm : int := 10 ; var most_frequent_char : OclAny := Set{char_frequency, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name char_frequency)) (trailer . (name get)))))))}->max() ; execute (mm + nn)->display() ; execute ("Most frequent character:")->display() ; var ascii_sum : OclAny := (ascii_codes)->sum() ; execute ("Sum of ASCII values:")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- greeting = "hello" message = "goodbye" print(message) duplicate = greeting duplicate += " world" print(greeting) print(duplicate) message += " everyone" print(message) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var greeting : String := "hello" ; var message : String := "goodbye" ; execute (message)->display() ; var duplicate : String := greeting ; duplicate := duplicate + " world" ; execute (greeting)->display() ; execute (duplicate)->display() ; message := message + " everyone" ; execute (message)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Account: handle = "" def __init__(self): self.registration_year = 2000 account1 = Account() account1.handle = "zzzz" account1.registration_year = 1988 account2 = Account() account2.handle = "fffff" account2.registration_year = 1995 extra_account = Account() extra_account.handle = "rrrrrrrr" extra_account.registration_year = 1982 ------------------------------------------------------------ OCL File: --------- class Account { static operation newAccount() : Account pre: true post: Account->exists( _x | result = _x ); static attribute handle : String := ""; attribute registration_year : int := 2000; operation initialise() : Account pre: true post: true activity: self.registration_year := 2000; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; var account1 : Account := (Account.newAccount()).initialise() ; account1.handle := "zzzz" ; account1.registration_year := 1988 ; var account2 : Account := (Account.newAccount()).initialise() ; account2.handle := "fffff" ; account2.registration_year := 1995 ; var extra_account : Account := (Account.newAccount()).initialise() ; extra_account.handle := "rrrrrrrr" ; extra_account.registration_year := 1982; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sentence = "sample text string" count_s = sentence.count("s") formatted_sentence = sentence.capitalize() h=10 formatted_sentence = sentence.title() h=h*10 formatted_sentence = sentence.replace(" ", "_") print(h) formatted_sentence = sentence.rstrip() h=h+2 formatted_sentence = sentence.strip() i=10 lowercase_sentence = sentence.lower() i=i+h print(lowercase_sentence) split_sentence = sentence.split(" ") print(split_sentence) joined_sentence = " - ".join(split_sentence) print(joined_sentence) print(i) part_sentence = sentence[7:11] print(part_sentence) print(h) sentence_length = len(sentence) print(sentence_length) print(count_s) print(i+h) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sentence : String := "sample text string" ; var count_s : int := sentence->count("s") ; var formatted_sentence : String := StringLib.capitalise(sentence) ; var h : int := 10 ; formatted_sentence := StringLib.toTitleCase(sentence) ; h := h * 10 ; formatted_sentence := sentence.replace(" ", "_") ; execute (h)->display() ; formatted_sentence := StringLib.rightTrim(sentence) ; h := h + 2 ; formatted_sentence := sentence->trim() ; var i : int := 10 ; var lowercase_sentence : String := sentence->toLowerCase() ; i := i + h ; execute (lowercase_sentence)->display() ; var split_sentence : OclAny := sentence.split(" ") ; execute (split_sentence)->display() ; var joined_sentence : String := StringLib.sumStringsWithSeparator((split_sentence), " - ") ; execute (joined_sentence)->display() ; execute (i)->display() ; var part_sentence : OclAny := sentence.subrange(7+1, 11) ; execute (part_sentence)->display() ; execute (h)->display() ; var sentence_length : int := (sentence)->size() ; execute (sentence_length)->display() ; execute (count_s)->display() ; execute (i + h)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- letters = ['p', 'q', 'r', 's', 't', 'u','o','t','w'] print(letters[1:4]) symbols = ['w', 'x', 'y', 'z', 'a', 'b','v','f','k'] print(symbols[2:5]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var letters : Sequence := Sequence{'p'}->union(Sequence{'q'}->union(Sequence{'r'}->union(Sequence{'s'}->union(Sequence{'t'}->union(Sequence{'u'}->union(Sequence{'o'}->union(Sequence{'t'}->union(Sequence{ 'w' })))))))) ; execute (letters.subrange(1+1, 4))->display() ; var symbols : Sequence := Sequence{'w'}->union(Sequence{'x'}->union(Sequence{'y'}->union(Sequence{'z'}->union(Sequence{'a'}->union(Sequence{'b'}->union(Sequence{'v'}->union(Sequence{'f'}->union(Sequence{ 'k' })))))))) ; execute (symbols.subrange(2+1, 5))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- elements = ['m', 'n', 'o', 'p', 'q', 'r','u','a'] print(elements[:3]) central_segment = elements[1:4] print(central_segment) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var elements : Sequence := Sequence{'m'}->union(Sequence{'n'}->union(Sequence{'o'}->union(Sequence{'p'}->union(Sequence{'q'}->union(Sequence{'r'}->union(Sequence{'u'}->union(Sequence{ 'a' }))))))) ; execute (elements.subrange(1,3))->display() ; var central_segment : OclAny := elements.subrange(1+1, 4) ; execute (central_segment)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- items = ['a', 'b', 'c','h'] additional = 'x' items.extend('y') print(items) items.reverse() print(items) items.remove('a') print(items) items.insert(2, additional) print(items) items.sort() print(items) items.append('z') print(items) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var items : Sequence := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{'c'}->union(Sequence{ 'h' }))) ; var additional : String := 'x' ; items := items->union('y') ; execute (items)->display() ; items := items->reverse() ; execute (items)->display() ; execute (('a') /: items) ; execute (items)->display() ; items := items.insertAt(2+1, additional) ; execute (items)->display() ; items := items->sort() ; execute (items)->display() ; execute (('z') : items) ; execute (items)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- values = [10, 20, 30,67,34,12,88,90] values.pop(0) print(values.index(30)) updated_list = [11, 12, 13,67] updated_list.pop() print(updated_list.index(11)) i=78 i=i+90 additional_values = [14, 15,16] print(additional_values.index(14)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var values : Sequence := Sequence{10}->union(Sequence{20}->union(Sequence{30}->union(Sequence{67}->union(Sequence{34}->union(Sequence{12}->union(Sequence{88}->union(Sequence{ 90 }))))))) ; values := values->excludingAt(0+1) ; execute (values->indexOf(30) - 1)->display() ; var updated_list : Sequence := Sequence{11}->union(Sequence{12}->union(Sequence{13}->union(Sequence{ 67 }))) ; updated_list := updated_list->front() ; execute (updated_list->indexOf(11) - 1)->display() ; var i : int := 78 ; i := i + 90 ; var additional_values : Sequence := Sequence{14}->union(Sequence{15}->union(Sequence{ 16 })) ; execute (additional_values->indexOf(14) - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = 15 y = 30 z = 5 m = 40 n = 50 o = 25 x, y, z = z, x, y m, n, o = o, m, n print(m) print(n) print(o) print(x) print(y) print(z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 15 ; var y : int := 30 ; var z : int := 5 ; var m : int := 40 ; var n : int := 50 ; var o : int := 25 ; Sequence{x,y,z} := Sequence{z,x,y} ; Sequence{m,n,o} := Sequence{o,m,n} ; execute (m)->display() ; execute (n)->display() ; execute (o)->display() ; execute (x)->display() ; execute (y)->display() ; execute (z)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tuples = [(3, 4), (2, 6), (7, 9), (8, 15)] computations = [x * y for x, y in tuples] data = [(5, 8), (2, 7), (6, 10), (4, 14)] calculations = [p * q for p, q in data] print(computations) print(calculations) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var tuples : Sequence := Sequence{Sequence{3, 4}}->union(Sequence{Sequence{2, 6}}->union(Sequence{Sequence{7, 9}}->union(Sequence{ Sequence{8, 15} }))) ; var computations : Sequence := tuples->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (x * y)) ; var data : Sequence := Sequence{Sequence{5, 8}}->union(Sequence{Sequence{2, 7}}->union(Sequence{Sequence{6, 10}}->union(Sequence{ Sequence{4, 14} }))) ; var calculations : Sequence := data->select(_tuple | true)->collect(_tuple | let p : OclAny = _tuple->at(1) in let q : OclAny = _tuple->at(2) in (p * q)) ; execute (computations)->display() ; execute (calculations)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- groupings = [(4, 5), (2, 8), (7, 6), (3, 12), (4, 32)] for x, y in groupings: print(x * y) extra_pairs = [(2, 3), (6, 4), (5, 7), (8, 9), (5, 12)] for a, b in extra_pairs: print(a + b) new_pairs = [(10, 2), (6, 4), (8, 3), (13, 82)] for p, q in new_pairs: print(p - q) complex_groupings = [(15, 3), (20, 5), (18, 6), (63, 12)] for i, j in complex_groupings: print(i / j) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var groupings : Sequence := Sequence{Sequence{4, 5}}->union(Sequence{Sequence{2, 8}}->union(Sequence{Sequence{7, 6}}->union(Sequence{Sequence{3, 12}}->union(Sequence{ Sequence{4, 32} })))) ; for _tuple : groupings do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); execute (x * y)->display()) ; var extra_pairs : Sequence := Sequence{Sequence{2, 3}}->union(Sequence{Sequence{6, 4}}->union(Sequence{Sequence{5, 7}}->union(Sequence{Sequence{8, 9}}->union(Sequence{ Sequence{5, 12} })))) ; for _tuple : extra_pairs do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); execute (a + b)->display()) ; var new_pairs : Sequence := Sequence{Sequence{10, 2}}->union(Sequence{Sequence{6, 4}}->union(Sequence{Sequence{8, 3}}->union(Sequence{ Sequence{13, 82} }))) ; for _tuple : new_pairs do (var _indx : int := 1; var p : OclAny := _tuple->at(_indx); _indx := _indx + 1; var q : OclAny := _tuple->at(_indx); execute (p - q)->display()) ; var complex_groupings : Sequence := Sequence{Sequence{15, 3}}->union(Sequence{Sequence{20, 5}}->union(Sequence{Sequence{18, 6}}->union(Sequence{ Sequence{63, 12} }))) ; for _tuple : complex_groupings do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); execute (i / j)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- item1 = "a" item2 = "b" item3 = "c" set_of_items = (item1, item2, item3) x, y, z = set_of_items updated_item1 = "m" updated_item2 = "n" updated_item3 = "o" print(9+5*9) updated_set = (updated_item1, updated_item2, updated_item3) first, second, third = updated_set k=100 print(first) print(second) print(third) print(k) print(x) print(y) print(z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var item1 : String := "a" ; var item2 : String := "b" ; var item3 : String := "c" ; var set_of_items : OclAny := Sequence{item1, item2, item3} ; var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := set_of_items ; var updated_item1 : String := "m" ; var updated_item2 : String := "n" ; var updated_item3 : String := "o" ; execute (9 + 5 * 9)->display() ; var updated_set : OclAny := Sequence{updated_item1, updated_item2, updated_item3} ; var first : OclAny := null; var second : OclAny := null; var third : OclAny := null; Sequence{first,second,third} := updated_set ; var k : int := 100 ; execute (first)->display() ; execute (second)->display() ; execute (third)->display() ; execute (k)->display() ; execute (x)->display() ; execute (y)->display() ; execute (z)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math elements = ["aa", "bb", "cc","hh","uu"] total = len(elements) cubed_value = math.pow(total, 2) cosine_result = math.sin(0.5) p=10 logarithm = math.log(20) additional = math.sqrt(16) print("Total:", total) print("Squared:", cubed_value) print("Cosine Result:", cosine_result) print("Square Root:", additional) print("Logarithm:", logarithm) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var elements : Sequence := Sequence{"aa"}->union(Sequence{"bb"}->union(Sequence{"cc"}->union(Sequence{"hh"}->union(Sequence{ "uu" })))) ; var total : int := (elements)->size() ; var cubed_value : double := (total)->pow(2) ; var cosine_result : double := (0.5)->sin() ; var p : int := 10 ; var logarithm : double := (20)->log() ; var additional : double := (16)->sqrt() ; execute ("Total:")->display() ; execute ("Squared:")->display() ; execute ("Cosine Result:")->display() ; execute ("Square Root:")->display() ; execute ("Logarithm:")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class StaffMember: staff_number = "" def __init__(self): self.experience_years = 0 def increase_experience(self, years): self.experience_years += years employee1 = StaffMember() employee1.increase_experience(4) print(employee1.experience_years) employee2 = StaffMember() employee2.increase_experience(6) print(employee2.experience_years) additional_employee = StaffMember() additional_employee.increase_experience(5) print(additional_employee.experience_years) ------------------------------------------------------------ OCL File: --------- class StaffMember { static operation newStaffMember() : StaffMember pre: true post: StaffMember->exists( _x | result = _x ); static attribute staff_number : String := ""; attribute experience_years : int := 0; operation initialise() : StaffMember pre: true post: true activity: self.experience_years := 0; return self; operation increase_experience(years : OclAny) pre: true post: true activity: self.experience_years := self.experience_years + years; } class FromPython { operation initialise() pre: true post: true activity: skip ; var employee1 : StaffMember := (StaffMember.newStaffMember()).initialise() ; employee1.increase_experience(4) ; execute (employee1.experience_years)->display() ; var employee2 : StaffMember := (StaffMember.newStaffMember()).initialise() ; employee2.increase_experience(6) ; execute (employee2.experience_years)->display() ; var additional_employee : StaffMember := (StaffMember.newStaffMember()).initialise() ; additional_employee.increase_experience(5) ; execute (additional_employee.experience_years)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- value = 150 decimal = 30.0e-5 m=88 info_dict = dict({'x': value, 'y': decimal}) distinct_items = set({value, decimal}) values_list = [value, decimal, value] print(value + decimal) print(values_list + [3, 50]) message = "test message" print(message + ' modified') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var value : int := 150 ; var decimal : double := ("30.0e-5")->toReal() ; var m : int := 88 ; var info_dict : Map := (Map{ 'x' |-> value }->union(Map{ 'y' |-> decimal })) ; var distinct_items : Set := Set{}->union((Set{value}->union(Set{ decimal }))) ; var values_list : Sequence := Sequence{value}->union(Sequence{decimal}->union(Sequence{ value })) ; execute (value + decimal)->display() ; execute (values_list->union(Sequence{3}->union(Sequence{ 50 })))->display() ; var message : String := "test message" ; execute (message + ' modified')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- number = 1 product = 1 while number <= 6: number += 1 product *= number final_result = product print(final_result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var number : int := 1 ; var product : int := 1 ; while number <= 6 do ( number := number + 1 ; product := product * number) ; var final_result : int := product ; execute (final_result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- text_block = "varied text\nspanning several lines\nwith multiple entries\n" i=1 j=1 with open('results.txt', 'w') as output_file, open('source.txt', 'r') as input_file: text = input_file.read() i=i+10 output_file.write(text) output_file.close() print(i*j) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var text_block : String := "varied text\nspanning several lines\nwith multiple entries\n" ; var i : int := 1 ; var j : int := 1 ; try (var output_file : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('results.txt')); var input_file : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('source.txt')); var text : String := input_file.readAll() ; i := i + 10 ; output_file.write(text) ; output_file.closeFile() ; execute (i * j)->display()) catch (_e : OclException) do skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- text_data = "updated information\nwith various lines\nmore details\n" with open('result_file.txt', 'w') as output_file: output_file.write(text_data) output_file.close() extra_text = "supplementary details\n" with open('result_file.txt', 'a') as output_file: output_file.write(extra_text) with open('result_file.txt', 'r') as input_file: content = input_file.read() print("File content read:", content) line_count = content.count('\n') print("Number of lines in file:", line_count) new_text = "new lines added here\n" with open('result_file.txt', 'a') as output_file: output_file.write(new_text) with open('result_file.txt', 'r') as input_file: final_content = input_file.readlines() print("Final content of file:") for line in final_content: print(line.strip()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var text_data : String := "updated information\nwith various lines\nmore details\n" ; try (var output_file : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('result_file.txt')); output_file.write(text_data) ; output_file.closeFile()) catch (_e : OclException) do skip ; var extra_text : String := "supplementary details\n" ; try (var output_file : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('result_file.txt')); output_file.write(extra_text)) catch (_e : OclException) do skip ; try (var input_file : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('result_file.txt')); var content : String := input_file.readAll() ; execute ("File content read:")->display()) catch (_e : OclException) do skip ; var line_count : int := content->count(' ') ; execute ("Number of lines in file:")->display() ; var new_text : String := "new lines added here\n" ; try (var output_file : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('result_file.txt')); output_file.write(new_text)) catch (_e : OclException) do skip ; try (var input_file : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('result_file.txt')); var final_content : OclAny := input_file.readlines() ; execute ("Final content of file:")->display() ; for line : final_content do ( execute (line->trim())->display())) catch (_e : OclException) do skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def produce_values(): yield 7 yield 14 yield 21 yield 28 for value in produce_values(): print(value) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for value : OclIterator.newOclIterator_Function(lambda _i : int in self.produce_values(_i)) do ( execute (value)->display()); operation produce_values(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return 7 ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return 14 ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return 21 ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return 28; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def value_producer(): yield 3 yield 6 yield 9 yield 5 yield 13 gen_obj = value_producer() extra_gen = (x * 2 for x in [2, 4, 6,8,10]) for item in extra_gen: print(item) print(next(gen_obj)) print(next(gen_obj)) print(next(gen_obj)) print(next(gen_obj)) print(next(gen_obj)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var gen_obj : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.value_producer(_i)) ; var extra_gen : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) * (expr (atom (number (integer 2)))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 2))))))) , (test (logical_test (comparison (expr (atom (number (integer 4))))))) , (test (logical_test (comparison (expr (atom (number (integer 6))))))) , (test (logical_test (comparison (expr (atom (number (integer 8))))))) , (test (logical_test (comparison (expr (atom (number (integer 10)))))))) ]))))))} ; for item : extra_gen do ( execute (item)->display()) ; execute ((gen_obj).next())->display() ; execute ((gen_obj).next())->display() ; execute ((gen_obj).next())->display() ; execute ((gen_obj).next())->display() ; execute ((gen_obj).next())->display(); operation value_producer(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return 3 ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return 6 ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return 9 ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return 5 ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return 13; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import pandas as pd health_records = pd.read_csv("data/medical_data.csv") patient_age_data = health_records["Age"] avg_age_of_patients = patient_age_data.mean() print(avg_age_of_patients) median_values = health_records[["Age", "Treatment_Cost"]].median() print(median_values) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var health_records : Map := OclFile.newOclFile_Read(OclFile.newOclFile(("data/medical_data.csv"))).readMap() ; var patient_age_data : OclAny := health_records->at("Age") ; var avg_age_of_patients : double := MathLib.mean(patient_age_data) ; execute (avg_age_of_patients)->display() ; var median_values : OclAny := MathLib.median(health_records->restrict(Sequence{"Age"}->union(Sequence{ "Treatment_Cost" }))) ; execute (median_values)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Client: def __init__(self, name): self.name = name self.age = 0 def get_age(self): return self.age user1 = Client("ssss") user1.age = 27 user2 = Client("Jjjjjj") user2.age = 31 extra_user = Client("ttttt") extra_user.age = 22 ------------------------------------------------------------ OCL File: --------- class Client { static operation newClient() : Client pre: true post: Client->exists( _x | result = _x ); attribute name : int := name; attribute age : int := 0; operation initialise(name : OclAny) : Client pre: true post: true activity: self.name := name ; self.age := 0; return self; operation get_age() : OclAny pre: true post: true activity: return self.age; } class FromPython { operation initialise() pre: true post: true activity: skip ; var user1 : Client := (Client.newClient()).initialise("ssss") ; user1.age := 27 ; var user2 : Client := (Client.newClient()).initialise("Jjjjjj") ; user2.age := 31 ; var extra_user : Client := (Client.newClient()).initialise("ttttt") ; extra_user.age := 22; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Contributor: def __init__(self, handle): self.handle = handle self.skill_level = 0 def boost_skill(self): self.skill_level += 3 return self.skill_level participant1 = Contributor("aaaaa") participant1.boost_skill() participant1.boost_skill() participant2 = Contributor("sssssss") participant2.boost_skill() participant3 = Contributor("yyyyyy") participant3.boost_skill() additional_participant = Contributor("gggg") additional_participant.boost_skill() ------------------------------------------------------------ OCL File: --------- class Contributor { static operation newContributor() : Contributor pre: true post: Contributor->exists( _x | result = _x ); attribute handle : OclAny := handle; attribute skill_level : int := 0; operation initialise(handle : OclAny) : Contributor pre: true post: true activity: self.handle := handle ; self.skill_level := 0; return self; operation boost_skill() : OclAny pre: true post: true activity: self.skill_level := self.skill_level + 3 ; return self.skill_level; } class FromPython { operation initialise() pre: true post: true activity: skip ; var participant1 : Contributor := (Contributor.newContributor()).initialise("aaaaa") ; participant1.boost_skill() ; participant1.boost_skill() ; var participant2 : Contributor := (Contributor.newContributor()).initialise("sssssss") ; participant2.boost_skill() ; var participant3 : Contributor := (Contributor.newContributor()).initialise("yyyyyy") ; participant3.boost_skill() ; var additional_participant : Contributor := (Contributor.newContributor()).initialise("gggg") ; additional_participant.boost_skill(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- data_points = [3, 4, 5, 6, 4, 7, 1] squared_values = { num: num*num for num in data_points } print(squared_values) entries = [2, 3] cubed_values = { entry: entry**3 for entry in entries } print(cubed_values) additional_points = [8, 9] additional_squared = { point: point**2 for point in additional_points } print(additional_squared) extra_entries = [1, 5] extra_cubed = { extra: extra**3 for extra in extra_entries } print(extra_cubed) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var data_points : Sequence := Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{4}->union(Sequence{7}->union(Sequence{ 1 })))))) ; var squared_values : Map := data_points->select(num | true)->collect(num | Map{num |-> num * num})->unionAll() ; execute (squared_values)->display() ; var entries : Sequence := Sequence{2}->union(Sequence{ 3 }) ; var cubed_values : Map := entries->select(entry | true)->collect(entry | Map{entry |-> (entry)->pow(3)})->unionAll() ; execute (cubed_values)->display() ; var additional_points : Sequence := Sequence{8}->union(Sequence{ 9 }) ; var additional_squared : Map := additional_points->select(point | true)->collect(point | Map{point |-> (point)->pow(2)})->unionAll() ; execute (additional_squared)->display() ; var extra_entries : Sequence := Sequence{1}->union(Sequence{ 5 }) ; var extra_cubed : Map := extra_entries->select(extra | true)->collect(extra | Map{extra |-> (extra)->pow(3)})->unionAll() ; execute (extra_cubed)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- values = [4, 5, 6, 7, 8, 9] squared_odd_numbers = [item**2 for item in values if item % 2 == 1] print(squared_odd_numbers) additional_values = [10, 11, 12, 13] cubed_even_numbers = [item**3 for item in additional_values if item % 2 == 0] print(cubed_even_numbers) extra_values = [14, 15, 16, 17] squared_odd = [value**2 for value in extra_values if value % 2 == 1] print(squared_odd) further_values = [18, 19, 20, 21] cubed_even = [value**3 for value in further_values if value % 2 == 0] print(cubed_even) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var values : Sequence := Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 9 }))))) ; var squared_odd_numbers : Sequence := values->select(item | item mod 2 = 1)->collect(item | ((item)->pow(2))) ; execute (squared_odd_numbers)->display() ; var additional_values : Sequence := Sequence{10}->union(Sequence{11}->union(Sequence{12}->union(Sequence{ 13 }))) ; var cubed_even_numbers : Sequence := additional_values->select(item | item mod 2 = 0)->collect(item | ((item)->pow(3))) ; execute (cubed_even_numbers)->display() ; var extra_values : Sequence := Sequence{14}->union(Sequence{15}->union(Sequence{16}->union(Sequence{ 17 }))) ; var squared_odd : Sequence := extra_values->select(value | value mod 2 = 1)->collect(value | ((value)->pow(2))) ; execute (squared_odd)->display() ; var further_values : Sequence := Sequence{18}->union(Sequence{19}->union(Sequence{20}->union(Sequence{ 21 }))) ; var cubed_even : Sequence := further_values->select(value | value mod 2 = 0)->collect(value | ((value)->pow(3))) ; execute (cubed_even)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- unique_values = {2, 3, 4, 5, 6,8,9,56} squared_values_set = {value**2 for value in unique_values} print(squared_values_set) more_values = {7, 8,7,4,6,8} cubed_values_set = {value**3 for value in more_values} print(cubed_values_set) extra_unique_values = {1, 2, 3, 4,8,9,6,4} squared_extra_set = {value**2 for value in extra_unique_values} print(squared_extra_set) additional_unique_values = {5, 6, 7} cubed_extra_set = {value**3 for value in additional_unique_values} print(cubed_extra_set) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var unique_values : Set := Set{2}->union(Set{3}->union(Set{4}->union(Set{5}->union(Set{6}->union(Set{8}->union(Set{9}->union(Set{ 56 }))))))) ; var squared_values_set : Set := unique_values->select(value | true)->collect(value | (value)->pow(2))->asSet() ; execute (squared_values_set)->display() ; var more_values : Set := Set{7}->union(Set{8}->union(Set{7}->union(Set{4}->union(Set{6}->union(Set{ 8 }))))) ; var cubed_values_set : Set := more_values->select(value | true)->collect(value | (value)->pow(3))->asSet() ; execute (cubed_values_set)->display() ; var extra_unique_values : Set := Set{1}->union(Set{2}->union(Set{3}->union(Set{4}->union(Set{8}->union(Set{9}->union(Set{6}->union(Set{ 4 }))))))) ; var squared_extra_set : Set := extra_unique_values->select(value | true)->collect(value | (value)->pow(2))->asSet() ; execute (squared_extra_set)->display() ; var additional_unique_values : Set := Set{5}->union(Set{6}->union(Set{ 7 })) ; var cubed_extra_set : Set := additional_unique_values->select(value | true)->collect(value | (value)->pow(3))->asSet() ; execute (cubed_extra_set)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- set1 = (3, 5, 7) set2 = (3, 5, 8) if set1 < set2: print(True) else: print(False) letter1 = "C" letter2 = "D" print(letter1 < letter2) print(9 < 15) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var set1 : OclAny := Sequence{3, 5, 7} ; var set2 : OclAny := Sequence{3, 5, 8} ; if (set1->compareTo(set2)) < 0 then ( execute (true)->display() ) else ( execute (false)->display() ) ; var letter1 : String := "C" ; var letter2 : String := "D" ; execute (letter1 < letter2)->display() ; execute (9 < 15)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- is_active: bool = True max_value: int = 750 status: bool = False min_value: int = 100 additional_flag: bool = True upper_bound: int = 350 activation_status: bool = True limit_value: int = 50 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var is_active : boolean := true ; var max_value : int := 750 ; var status : boolean := false ; var min_value : int := 100 ; var additional_flag : boolean := true ; var upper_bound : int := 350 ; var activation_status : boolean := true ; var limit_value : int := 50; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- values_array = [3, 4, 5, 4, 3, 6, 3,7] search_item = 3 print(values_array.count(search_item)) other_list = [8, 9, 8, 10, 9,5,8,9] find_value = 9 print(other_list.count(find_value)) additional_array = [11, 12, 11, 13, 12,11,22,33,44,55,66,77,88] look_for = 12 print(additional_array.count(look_for)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var values_array : Sequence := Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{4}->union(Sequence{3}->union(Sequence{6}->union(Sequence{3}->union(Sequence{ 7 }))))))) ; var search_item : int := 3 ; execute (values_array->count(search_item))->display() ; var other_list : Sequence := Sequence{8}->union(Sequence{9}->union(Sequence{8}->union(Sequence{10}->union(Sequence{9}->union(Sequence{5}->union(Sequence{8}->union(Sequence{ 9 }))))))) ; var find_value : int := 9 ; execute (other_list->count(find_value))->display() ; var additional_array : Sequence := Sequence{11}->union(Sequence{12}->union(Sequence{11}->union(Sequence{13}->union(Sequence{12}->union(Sequence{11}->union(Sequence{22}->union(Sequence{33}->union(Sequence{44}->union(Sequence{55}->union(Sequence{66}->union(Sequence{77}->union(Sequence{ 88 })))))))))))) ; var look_for : int := 12 ; execute (additional_array->count(look_for))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from datetime import * recent_time = datetime.now() print(recent_time.year) print(recent_time.month) print(recent_time.day) next_time = datetime.now() print(next_time.year) print(next_time.month) print(next_time.day) current_time = datetime.now() print(current_time.year) print(current_time.month) print(current_time.day) upcoming_time = datetime.now() print(upcoming_time.year) print(upcoming_time.month) print(upcoming_time.day) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var recent_time : OclDate := OclDate.newOclDate() ; execute (recent_time.getYear())->display() ; execute (recent_time.getMonth())->display() ; execute (recent_time.getDate())->display() ; var next_time : OclDate := OclDate.newOclDate() ; execute (next_time.getYear())->display() ; execute (next_time.getMonth())->display() ; execute (next_time.getDate())->display() ; var current_time : OclDate := OclDate.newOclDate() ; execute (current_time.getYear())->display() ; execute (current_time.getMonth())->display() ; execute (current_time.getDate())->display() ; var upcoming_time : OclDate := OclDate.newOclDate() ; execute (upcoming_time.getYear())->display() ; execute (upcoming_time.getMonth())->display() ; execute (upcoming_time.getDate())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def process1(x): pass def process2(x, y): pass def process3(x): pass def process4(x, y): pass def process5(x, y): pass def assess(x, y): if x > 4: process1(x) if y > 4: process2(x, y) return 15 else: process3(x) return 25 else: if y > 4: process4(x, y) return 35 else: process5(x, y) return 45 print(assess(5, 5)) print(assess(5, 3)) print(assess(3, 2)) print(assess(3, 3)) print(assess(8, 8)) print(assess(7, 5)) result1 = assess(8, 9) result2 = assess(1, 2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; execute (assess(5, 5))->display() ; execute (assess(5, 3))->display() ; execute (assess(3, 2))->display() ; execute (assess(3, 3))->display() ; execute (assess(8, 8))->display() ; execute (assess(7, 5))->display() ; var result1 : OclAny := assess(8, 9) ; var result2 : OclAny := assess(1, 2); operation process1(x : OclAny) pre: true post: true activity: skip; operation process2(x : OclAny, y : OclAny) pre: true post: true activity: skip; operation process3(x : OclAny) pre: true post: true activity: skip; operation process4(x : OclAny, y : OclAny) pre: true post: true activity: skip; operation process5(x : OclAny, y : OclAny) pre: true post: true activity: skip; operation assess(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if x > 4 then ( process1(x) ; if y > 4 then ( process2(x, y) ; return 15 ) else ( process3(x) ; return 25 ) ) else ( if y > 4 then ( process4(x, y) ; return 35 ) else ( process5(x, y) ; return 45 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def assess(x, y): if x > 15: if y > 15: return 120 else: return 250 else: if y > 15: return 350 else: return 450 print(assess(16, 16)) print(assess(16, 10)) print(assess(10, 16)) print(assess(10, 10)) outcome1 = assess(18, 14) outcome2 = assess(7, 20) print(outcome1) print(outcome2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (assess(16, 16))->display() ; execute (assess(16, 10))->display() ; execute (assess(10, 16))->display() ; execute (assess(10, 10))->display() ; var outcome1 : OclAny := assess(18, 14) ; var outcome2 : OclAny := assess(7, 20) ; execute (outcome1)->display() ; execute (outcome2)->display(); operation assess(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if x > 15 then ( if y > 15 then ( return 120 ) else ( return 250 ) ) else ( if y > 15 then ( return 350 ) else ( return 450 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculate(value1, divisor = 3.5): result = 4.5 m=10 result = result +m + value1 / divisor print(result) calculate(7, 2.5) calculate(10) def assess(num1, num2 = 5.5): total = 6.0 n=7 total = total +n + num1 / num2 print(total) assess(12, 4.0) assess(9) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; calculate(7, 2.5) ; calculate(10) ; skip ; assess(12, 4.0) ; assess(9); operation calculate(value1 : OclAny, divisor : double) pre: true post: true activity: if divisor->oclIsUndefined() then divisor := 3.5 else skip; var result : double := 4.5 ; var m : int := 10 ; result := result + m + value1 / divisor ; execute (result)->display(); operation assess(num1 : OclAny, num2 : double) pre: true post: true activity: if num2->oclIsUndefined() then num2 := 5.5 else skip; var total : double := 6.0 ; var n : int := 7 ; total := total + n + num1 / num2 ; execute (total)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- int_list = [2, 3, 4] str_list = ['a', 'b', 'c'] combined_pairs = zip(int_list, str_list) print(list(combined_pairs)) numbers = [10, 20, 30] names = ['alpha', 'beta', 'gamma'] merged_pairs = zip(numbers, names) print(list(merged_pairs)) extra_numbers = [1, 2, 3,4] extra_names = ['delta', 'epsilon', 'zeta','yyyy'] new_pairs = zip(extra_numbers, extra_names) print(list(new_pairs)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var int_list : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })) ; var str_list : Sequence := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{ 'c' })) ; var combined_pairs : Sequence := Integer.subrange(1, int_list->size())->collect( _indx | Sequence{int_list->at(_indx), str_list->at(_indx)} ) ; execute ((combined_pairs))->display() ; var numbers : Sequence := Sequence{10}->union(Sequence{20}->union(Sequence{ 30 })) ; var names : Sequence := Sequence{'alpha'}->union(Sequence{'beta'}->union(Sequence{ 'gamma' })) ; var merged_pairs : Sequence := Integer.subrange(1, numbers->size())->collect( _indx | Sequence{numbers->at(_indx), names->at(_indx)} ) ; execute ((merged_pairs))->display() ; var extra_numbers : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))) ; var extra_names : Sequence := Sequence{'delta'}->union(Sequence{'epsilon'}->union(Sequence{'zeta'}->union(Sequence{ 'yyyy' }))) ; var new_pairs : Sequence := Integer.subrange(1, extra_numbers->size())->collect( _indx | Sequence{extra_numbers->at(_indx), extra_names->at(_indx)} ) ; execute ((new_pairs))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- distinct_set = set({'a', 'b', 'c'}) del distinct_set new_set = set({'p', 'q', 'r'}) del new_set print(new_set) print(distinct_set) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var distinct_set : Set := Set{}->union((Set{'a'}->union(Set{'b'}->union(Set{ 'c' })))) ; execute (distinct_set)->isDeleted() ; var new_set : Set := Set{}->union((Set{'p'}->union(Set{'q'}->union(Set{ 'r' })))) ; execute (new_set)->isDeleted() ; execute (new_set)->display() ; execute (distinct_set)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- characters = ['a', 'b', 'c', 'd', 'e', 'f','g','h'] del characters[1] del characters[1:3] digits = [10, 20, 30, 40, 50, 60,80,90] del digits[2] del digits[1:4] extra_list = ['m', 'n', 'o', 'p', 'q','r'] del extra_list[0] del extra_list[1:3] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var characters : Sequence := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{'c'}->union(Sequence{'d'}->union(Sequence{'e'}->union(Sequence{'f'}->union(Sequence{'g'}->union(Sequence{ 'h' }))))))) ; execute (characters[1+1])->isDeleted() ; execute (characters.subrange(1+1, 3))->isDeleted() ; var digits : Sequence := Sequence{10}->union(Sequence{20}->union(Sequence{30}->union(Sequence{40}->union(Sequence{50}->union(Sequence{60}->union(Sequence{80}->union(Sequence{ 90 }))))))) ; execute (digits[2+1])->isDeleted() ; execute (digits.subrange(1+1, 4))->isDeleted() ; var extra_list : Sequence := Sequence{'m'}->union(Sequence{'n'}->union(Sequence{'o'}->union(Sequence{'p'}->union(Sequence{'q'}->union(Sequence{ 'r' }))))) ; execute (extra_list->first())->isDeleted() ; execute (extra_list.subrange(1+1, 3))->isDeleted(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections queue1 = collections.deque(['a', 'b', 'c']) queue1.appendleft('x') queue1.appendleft('y') print(queue1) queue1.extendleft(['z', 'w']) print(queue1) element = queue1.pop() print(queue1) queue1.popleft() print(queue1) print(queue1.maxlen) queue2 = collections.deque(['m', 'n', 'o']) queue2.appendleft('p') queue2.appendleft('q') print(queue2) queue2.extendleft(['r', 's']) print(queue2) element2 = queue2.pop() print(queue2) queue2.popleft() print(queue2) print(queue2.maxlen) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var queue1 : Sequence := (Sequence{'a'}->union(Sequence{'b'}->union(Sequence{ 'c' }))) ; queue1 := queue1->prepend('x') ; queue1 := queue1->prepend('y') ; execute (queue1)->display() ; queue1 := queue1->reverse()->union(Sequence{'z'}->union(Sequence{ 'w' }))->reverse() ; execute (queue1)->display() ; var element : OclAny := queue1->last() ; queue1 := queue1->front() ; execute (queue1)->display() ; queue1 := queue1->tail() ; execute (queue1)->display() ; execute (queue1->size())->display() ; var queue2 : Sequence := (Sequence{'m'}->union(Sequence{'n'}->union(Sequence{ 'o' }))) ; queue2 := queue2->prepend('p') ; queue2 := queue2->prepend('q') ; execute (queue2)->display() ; queue2 := queue2->reverse()->union(Sequence{'r'}->union(Sequence{ 's' }))->reverse() ; execute (queue2)->display() ; var element2 : OclAny := queue2->last() ; queue2 := queue2->front() ; execute (queue2)->display() ; queue2 := queue2->tail() ; execute (queue2)->display() ; execute (queue2->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- number = 4 if number > 3: outcome = number * number print(outcome + number) elif number > 1: outcome = number * number * number print(outcome + number) else: outcome = -number print(outcome) value = 6 if value > 3: square_value = value * value print(square_value + value) elif value > 0: cube_value = value * value * value print(cube_value + value) else: negative_value = -value print(negative_value) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var number : int := 4 ; if number > 3 then ( var outcome : int := number * number ; execute (outcome + number)->display() ) else (if number > 1 then ( outcome := number * number * number ; execute (outcome + number)->display() ) else ( outcome := -number ; execute (outcome)->display() ) ) ; var value : int := 6 ; if value > 3 then ( var square_value : int := value * value ; execute (square_value + value)->display() ) else (if value > 0 then ( var cube_value : int := value * value * value ; execute (cube_value + value)->display() ) else ( var negative_value : int := -value ; execute (negative_value)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- count = 28 elements = [3, 15, count] print(elements) extra_value = 35 elements.append(extra_value) print(elements) another_count = 12 elements.append(another_count) print(elements) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var count : int := 28 ; var elements : Sequence := Sequence{3}->union(Sequence{15}->union(Sequence{ count })) ; execute (elements)->display() ; var extra_value : int := 35 ; execute ((extra_value) : elements) ; execute (elements)->display() ; var another_count : int := 12 ; execute ((another_count) : elements) ; execute (elements)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- quantity = 6 if quantity > 4: result = quantity * quantity print(result + quantity) else: result = quantity * quantity * quantity print(result + quantity) multiplier = 4 if multiplier > 2: calculation = multiplier * multiplier print(calculation + multiplier) else: calculation = multiplier * multiplier * multiplier print(calculation + multiplier) extra_value = 8 if extra_value > 3: squared_value = extra_value * extra_value print(squared_value + extra_value) else: cubed_value = extra_value * extra_value * extra_value print(cubed_value + extra_value) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var quantity : int := 6 ; if quantity > 4 then ( var result : int := quantity * quantity ; execute (result + quantity)->display() ) else ( result := quantity * quantity * quantity ; execute (result + quantity)->display() ) ; var multiplier : int := 4 ; if multiplier > 2 then ( var calculation : int := multiplier * multiplier ; execute (calculation + multiplier)->display() ) else ( calculation := multiplier * multiplier * multiplier ; execute (calculation + multiplier)->display() ) ; var extra_value : int := 8 ; if extra_value > 3 then ( var squared_value : int := extra_value * extra_value ; execute (squared_value + extra_value)->display() ) else ( var cubed_value : int := extra_value * extra_value * extra_value ; execute (cubed_value + extra_value)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def positive_value(number): if number < 0: outcome = -number else: outcome = number return outcome def size(amount): if amount < 3: size_value = -amount else: size_value = amount return size_value print(positive_value(-5)) print(positive_value(9)) print(size(-8)) print(size(4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; execute (positive_value(-5))->display() ; execute (positive_value(9))->display() ; execute (size(-8))->display() ; execute (size(4))->display(); operation positive_value(number : OclAny) : OclAny pre: true post: true activity: if number < 0 then ( var outcome : int := -number ) else ( outcome := number ) ; return outcome; operation size(amount : OclAny) : OclAny pre: true post: true activity: if amount < 3 then ( var size_value : OclAny := -amount ) else ( size_value := amount ) ; return size_value; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- score = 12 x = 0 y = 0 if score > 8: x = score elif score < 8: y = score else: x = 2 current_score = 4 outcome_x = 0 outcome_y = 0 if current_score > 5: outcome_x = current_score elif current_score < 5: outcome_y = current_score else: outcome_x = 15 extra_value = 6 temp_x = 0 temp_y = 0 if extra_value > 5: temp_x = extra_value elif extra_value < 5: temp_y = extra_value else: temp_x = 20 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var score : int := 12 ; var x : int := 0 ; var y : int := 0 ; if score > 8 then ( x := score ) else (if score < 8 then ( y := score ) else ( x := 2 ) ) ; var current_score : int := 4 ; var outcome_x : int := 0 ; var outcome_y : int := 0 ; if current_score > 5 then ( outcome_x := current_score ) else (if current_score < 5 then ( outcome_y := current_score ) else ( outcome_x := 15 ) ) ; var extra_value : int := 6 ; var temp_x : int := 0 ; var temp_y : int := 0 ; if extra_value > 5 then ( temp_x := extra_value ) else (if extra_value < 5 then ( temp_y := extra_value ) else ( temp_x := 20 ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from enum import Enum class Color(Enum): ruby = 1 jade = 2 topaz = 3 print(Color.jade.value) class Vegetable(Enum): carrot = 1 beet = 2 spinach = 3 print(Vegetable.beet.value) class Animal(Enum): lion = 1 tiger = 2 bear = 3 print(Animal.tiger.value) class Vehicle(Enum): car = 1 bike = 2 truck = 3 print(Vehicle.bike.value) ------------------------------------------------------------ OCL File: --------- class Color { static operation newColor() : Color pre: true post: Color->exists( _x | result = _x ); static attribute ruby : int := 1; static attribute jade : int := 2; static attribute topaz : int := 3; } class Vegetable { static operation newVegetable() : Vegetable pre: true post: Vegetable->exists( _x | result = _x ); static attribute carrot : int := 1; static attribute beet : int := 2; static attribute spinach : int := 3; } class Animal { static operation newAnimal() : Animal pre: true post: Animal->exists( _x | result = _x ); static attribute lion : int := 1; static attribute tiger : int := 2; static attribute bear : int := 3; } class Vehicle { static operation newVehicle() : Vehicle pre: true post: Vehicle->exists( _x | result = _x ); static attribute car : int := 1; static attribute bike : int := 2; static attribute truck : int := 3; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; execute (Color.jade)->display() ; skip ; execute (Vegetable.beet)->display() ; skip ; execute (Animal.tiger)->display() ; skip ; execute (Vehicle.bike)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from enum import Enum class Tint(Enum): teal = 1 magenta = 2 class Fruit(Enum): pineapple = 1 raspberry = 2 blackberry = 3 class Vehicle(Enum): bicycle = 1 scooter = 2 skateboard = 3 print(Tint.magenta.value) print(Fruit.raspberry.value) print(Vehicle.skateboard.value) ------------------------------------------------------------ OCL File: --------- class Tint { static operation newTint() : Tint pre: true post: Tint->exists( _x | result = _x ); static attribute teal : int := 1; static attribute magenta : int := 2; } class Fruit { static operation newFruit() : Fruit pre: true post: Fruit->exists( _x | result = _x ); static attribute pineapple : int := 1; static attribute raspberry : int := 2; static attribute blackberry : int := 3; } class Vehicle { static operation newVehicle() : Vehicle pre: true post: Vehicle->exists( _x | result = _x ); static attribute bicycle : int := 1; static attribute scooter : int := 2; static attribute skateboard : int := 3; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; execute (Tint.magenta)->display() ; execute (Fruit.raspberry)->display() ; execute (Vehicle.skateboard)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def determineCost(rate, begin, finish, amount, schedule, period): return (amount * (finish - begin)) / math.pow((1 + rate), finish - begin) def calculateEarnings(startYear, endYear, period, amount, schedule, dueYear): totalPeriods = int(12 / period) return (endYear - startYear) * amount / totalPeriods def modifiedCost(rate, begin, finish, due, amount, schedule, period): return determineCost(rate, begin, finish, amount, schedule, period) - calculateEarnings(begin, finish, period, amount, schedule, due) output = modifiedCost(0.05, 2021.0, 2021.5, 2024.0, 0.03, "30/360", 6) print(output) updatedOutput = modifiedCost(0.06, 2022.0, 2022.75, 2026.0, 0.035, "30/360", 5) print(updatedOutput) extraOutput = modifiedCost(0.02, 2023.0, 2023.25, 2027.0, 0.015, "30/360", 2) print(extraOutput) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var output : OclAny := modifiedCost(0.05, 2021.0, 2021.5, 2024.0, 0.03, "30/360", 6) ; execute (output)->display() ; var updatedOutput : OclAny := modifiedCost(0.06, 2022.0, 2022.75, 2026.0, 0.035, "30/360", 5) ; execute (updatedOutput)->display() ; var extraOutput : OclAny := modifiedCost(0.02, 2023.0, 2023.25, 2027.0, 0.015, "30/360", 2) ; execute (extraOutput)->display(); operation determineCost(rate : OclAny, begin : OclAny, finish : OclAny, amount : OclAny, schedule : OclAny, period : OclAny) : OclAny pre: true post: true activity: return (amount * (finish - begin)) / ((1 + rate))->pow(finish - begin); operation calculateEarnings(startYear : OclAny, endYear : OclAny, period : OclAny, amount : OclAny, schedule : OclAny, dueYear : OclAny) : OclAny pre: true post: true activity: var totalPeriods : int := ("" + ((12 / period)))->toInteger() ; return (endYear - startYear) * amount / totalPeriods; operation modifiedCost(rate : OclAny, begin : OclAny, finish : OclAny, due : OclAny, amount : OclAny, schedule : OclAny, period : OclAny) : OclAny pre: true post: true activity: return determineCost(rate, begin, finish, amount, schedule, period) - calculateEarnings(begin, finish, period, amount, schedule, due); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(eval("5**3")) formula = "4**5" outcome = eval(formula) print(outcome) power_expr = "8**2" computed_value = eval(power_expr) print(computed_value) additional_expr = "6**4" additional_value = eval(additional_expr) print(additional_value) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((5)->pow(3))->display() ; var formula : String := "4**5" ; var outcome : OclAny := formula ; execute (outcome)->display() ; var power_expr : String := "8**2" ; var computed_value : OclAny := power_expr ; execute (computed_value)->display() ; var additional_expr : String := "6**4" ; var additional_value : OclAny := additional_expr ; execute (additional_value)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- day = 50 try: if day > 31: raise ValueError("day out of valid range") except ValueError as issue: print(issue) minute = 100 try: if minute > 60: raise ValueError("minute exceeds maximum limit") except ValueError as issue: print(issue) second = 75 try: if second > 60: raise ValueError("second exceeds allowed range") except ValueError as issue: print(issue) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var day : int := 50 ; try ( if day > 31 then ( error IncorrectElementException.newIncorrectElementException("day out of valid range") ) else skip) catch (issue : IncorrectElementException) do ( execute (issue)->display()) ; var minute : int := 100 ; try ( if minute > 60 then ( error IncorrectElementException.newIncorrectElementException("minute exceeds maximum limit") ) else skip) catch (issue : IncorrectElementException) do ( execute (issue)->display()) ; var second : int := 75 ; try ( if second > 60 then ( error IncorrectElementException.newIncorrectElementException("second exceeds allowed range") ) else skip) catch (issue : IncorrectElementException) do ( execute (issue)->display()) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- amount = 25 exec("amount = 10") print(amount) total = 18 exec("total = 6") print(total) info = 40 exec("info = 22") print(info) extra = 50 exec("extra = 33") print(extra) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var amount : int := 25 ; amount := 10 ; execute (amount)->display() ; var total : int := 18 ; total := 6 ; execute (total)->display() ; var info : int := 40 ; info := 22 ; execute (info)->display() ; var extra : int := 50 ; extra := 33 ; execute (extra)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- exec("mm = 5; print(mm*mm)") exec("factor = 8; print(factor * factor * factor)") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mm : int := 5; execute (mm * mm)->display() ; var factor : int := 8; execute (factor * factor * factor)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- amount = 45.60 assert type(amount) is float, 'Argument must be float!' number = 30 assert type(number) is int, 'Argument must be integer!' extra_amount = 22.10 assert type(extra_amount) is float, 'Argument must be float!' additional_number = 50 assert type(additional_number) is int, 'Argument must be integer!' ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var amount : double := 45.60 ; assert (amount)->oclType() <>= OclType["double"] do 'Argument must be float!' ; var number : int := 30 ; assert (number)->oclType() <>= OclType["int"] do 'Argument must be integer!' ; var extra_amount : double := 22.10 ; assert (extra_amount)->oclType() <>= OclType["double"] do 'Argument must be float!' ; var additional_number : int := 50 ; assert (additional_number)->oclType() <>= OclType["int"] do 'Argument must be integer!'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculate_area(x, y): if x > 4: if y > 4: return (x + y) ** 2 else: return (x - y) ** 2 else: if y > 4: return (x + y) ** 2 else: return (x - y) * (x + y) print(calculate_area(6, 6)) print(calculate_area(6, -4)) print(calculate_area(-4, 6)) print(calculate_area(-4, -5)) def evaluate_expression(a, b): if a > 7: if b > 7: return (a + b) ** 2 else: return (a - b) ** 2 else: if b > 7: return (a + b) ** 2 else: return (a - b) * (a + b) print(evaluate_expression(9, 9)) print(evaluate_expression(9, 6)) print(evaluate_expression(6, 9)) print(evaluate_expression(6, 6)) additional_computation = evaluate_expression(11, 4) print(additional_computation) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (calculate_area(6, 6))->display() ; execute (calculate_area(6, -4))->display() ; execute (calculate_area(-4, 6))->display() ; execute (calculate_area(-4, -5))->display() ; skip ; execute (evaluate_expression(9, 9))->display() ; execute (evaluate_expression(9, 6))->display() ; execute (evaluate_expression(6, 9))->display() ; execute (evaluate_expression(6, 6))->display() ; var additional_computation : OclAny := evaluate_expression(11, 4) ; execute (additional_computation)->display(); operation calculate_area(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if x > 4 then ( if y > 4 then ( return ((x + y))->pow(2) ) else ( return ((x - y))->pow(2) ) ) else ( if y > 4 then ( return ((x + y))->pow(2) ) else ( return (x - y) * (x + y) ) ); operation evaluate_expression(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a > 7 then ( if b > 7 then ( return ((a + b))->pow(2) ) else ( return ((a - b))->pow(2) ) ) else ( if b > 7 then ( return ((a + b))->pow(2) ) else ( return (a - b) * (a + b) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def process(value1, value2): if value1 > 10: if value2 > 10: return ((value1 + value2) * (value1 + value2)) ** 2 else: return (value1 - value2) * (value1 - value2) else: if value2 > 10: return ((value1 + value2) * (value1 + value2)) ** 4 else: return (value1 - value2) * (value1 + value2) print(process(12, 11)) print(process(12, 8)) print(process(8, 11)) print(process(8, 8)) def analyze(num1, num2): if num1 > 6: if num2 > 6: return ((num1 + num2) * (num1 + num2)) ** 3 else: return (num1 - num2) * (num1 - num2) else: if num2 > 6: return ((num1 + num2) * (num1 + num2)) ** 2 else: return (num1 - num2) * (num1 + num2) print(analyze(7, 7)) print(analyze(7, 5)) print(analyze(5, 7)) print(analyze(5, 5)) additional_result = analyze(8, 9) print(additional_result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (process(12, 11))->display() ; execute (process(12, 8))->display() ; execute (process(8, 11))->display() ; execute (process(8, 8))->display() ; skip ; execute (analyze(7, 7))->display() ; execute (analyze(7, 5))->display() ; execute (analyze(5, 7))->display() ; execute (analyze(5, 5))->display() ; var additional_result : OclAny := analyze(8, 9) ; execute (additional_result)->display(); operation process(value1 : OclAny, value2 : OclAny) : OclAny pre: true post: true activity: if value1 > 10 then ( if value2 > 10 then ( return (((value1 + value2) * (value1 + value2)))->pow(2) ) else ( return (value1 - value2) * (value1 - value2) ) ) else ( if value2 > 10 then ( return (((value1 + value2) * (value1 + value2)))->pow(4) ) else ( return (value1 - value2) * (value1 + value2) ) ); operation analyze(num1 : OclAny, num2 : OclAny) : OclAny pre: true post: true activity: if num1 > 6 then ( if num2 > 6 then ( return (((num1 + num2) * (num1 + num2)))->pow(3) ) else ( return (num1 - num2) * (num1 - num2) ) ) else ( if num2 > 6 then ( return (((num1 + num2) * (num1 + num2)))->pow(2) ) else ( return (num1 - num2) * (num1 + num2) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- file_input = open('sample.txt', 'r') file_contents = file_input.read() file_input.close() file_output = open('sample.txt', 'a') file_output.write(file_contents) modified_file = open('sample.txt', 'r') file_data = modified_file.read() modified_file.close() print(file_data) extra_text = "Extra information." file_extender = open('sample.txt', 'a') file_extender.write(extra_text) file_extender.close() final_file = open('sample.txt', 'r') complete_data = final_file.read() final_file.close() print(complete_data) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var file_input : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('sample.txt')) ; var file_contents : String := file_input.readAll() ; file_input.closeFile() ; var file_output : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('sample.txt')) ; file_output.write(file_contents) ; var modified_file : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('sample.txt')) ; var file_data : String := modified_file.readAll() ; modified_file.closeFile() ; execute (file_data)->display() ; var extra_text : String := "Extra information." ; var file_extender : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('sample.txt')) ; file_extender.write(extra_text) ; file_extender.closeFile() ; var final_file : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('sample.txt')) ; var complete_data : String := final_file.readAll() ; final_file.closeFile() ; execute (complete_data)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- strings = ["apple", "banana", "cherry", "date", "elderberry"] length_check = lambda string: len(string) > 5 selected_strings = filter(length_check, strings) for item in selected_strings: print(item) animals = ["lion", "wolf", "giraffe", "antelope", "bear"] size_filter = lambda animal: len(animal) <= 5 filtered_animals = filter(size_filter, animals) for animal in filtered_animals: print(animal) additional_items = ["kiwi", "grape", "blueberry", "melon"] new_filter = lambda fruit: len(fruit) == 6 filtered_fruits = filter(new_filter, additional_items) for fruit in filtered_fruits: print(fruit) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var strings : Sequence := Sequence{"apple"}->union(Sequence{"banana"}->union(Sequence{"cherry"}->union(Sequence{"date"}->union(Sequence{ "elderberry" })))) ; var length_check : Function := lambda string : OclAny in ((string)->size() > 5) ; var selected_strings : Sequence := (strings)->select( _x | (length_check)->apply(_x) = true ) ; for item : selected_strings do ( execute (item)->display()) ; var animals : Sequence := Sequence{"lion"}->union(Sequence{"wolf"}->union(Sequence{"giraffe"}->union(Sequence{"antelope"}->union(Sequence{ "bear" })))) ; var size_filter : Function := lambda animal : OclAny in ((animal)->size() <= 5) ; var filtered_animals : Sequence := (animals)->select( _x | (size_filter)->apply(_x) = true ) ; for animal : filtered_animals do ( execute (animal)->display()) ; var additional_items : Sequence := Sequence{"kiwi"}->union(Sequence{"grape"}->union(Sequence{"blueberry"}->union(Sequence{ "melon" }))) ; var new_filter : Function := lambda fruit : OclAny in ((fruit)->size() = 6) ; var filtered_fruits : Sequence := (additional_items)->select( _x | (new_filter)->apply(_x) = true ) ; for fruit : filtered_fruits do ( execute (fruit)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- info_dict = dict({ "gamma": 12, "delta": 22 }) for key in info_dict: print(key) attributes = dict({ "username": "Charlie", "years_old": 35 }) for key in attributes: print(key) products = dict({ "kiwi": 8, "peach": 5 }) for item in products: print(item) stock_levels = dict({ "blueberry": 12, "strawberry": 7 }) for fruit in stock_levels: print(fruit) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var info_dict : Map := (Map{ "gamma" |-> 12 }->union(Map{ "delta" |-> 22 })) ; for key : info_dict->keys() do ( execute (key)->display()) ; var attributes : Map := (Map{ "username" |-> "Charlie" }->union(Map{ "years_old" |-> 35 })) ; for key : attributes->keys() do ( execute (key)->display()) ; var products : Map := (Map{ "kiwi" |-> 8 }->union(Map{ "peach" |-> 5 })) ; for item : products->keys() do ( execute (item)->display()) ; var stock_levels : Map := (Map{ "blueberry" |-> 12 }->union(Map{ "strawberry" |-> 7 })) ; for fruit : stock_levels->keys() do ( execute (fruit)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- total = 2500 interest_rate = 5.25 title = 'Voucher' output_string = f"{title}: {total} {interest_rate:.2f}\n\n" print(output_string) discount = 300 percent = 10.0 identifier = 'Discount' formatted_output = f"{identifier}: {discount} {percent:.1f}\n\n" print(formatted_output) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var total : int := 2500 ; var interest_rate : double := 5.25 ; var title : String := 'Voucher' ; var output_string : String := StringLib.formattedString("{title}: {total} {interest_rate:.2f}\n\n") ; execute (output_string)->display() ; var discount : int := 300 ; var percent : double := 10.0 ; var identifier : String := 'Discount' ; var formatted_output : String := StringLib.formattedString("{identifier}: {discount} {percent:.1f}\n\n") ; execute (formatted_output)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- amount = 3500 cost = 22.50 output = "{0} items at ${1:.2f}\n\n".format(amount, cost) print(output) count = 500 unit_price = 12.99 formatted_output = "{0} pieces at ${1:.2f}\n\n".format(count, unit_price) print(formatted_output) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var amount : int := 3500 ; var cost : double := 22.50 ; var output : String := StringLib.interpolateStrings("{0} items at ${1:.2f}\n\n", Sequence{amount, cost}) ; execute (output)->display() ; var count : int := 500 ; var unit_price : double := 12.99 ; var formatted_output : String := StringLib.interpolateStrings("{0} pieces at ${1:.2f}\n\n", Sequence{count, unit_price}) ; execute (formatted_output)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- day = 22 month = 7 year = 2025 formatted_date = f"{day:02d}/{month:02d}/{year:04d}" print(formatted_date) day_of_month = 9 month_of_year = 11 current_year = 2023 formatted_date = f"{day_of_month:02d}-{month_of_year:02d}-{current_year:04d}" print(formatted_date) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var day : int := 22 ; var month : int := 7 ; var year : int := 2025 ; var formatted_date : String := StringLib.formattedString("{day:02d}/{month:02d}/{year:04d}") ; execute (formatted_date)->display() ; var day_of_month : int := 9 ; var month_of_year : int := 11 ; var current_year : int := 2023 ; formatted_date := StringLib.formattedString("{day_of_month:02d}-{month_of_year:02d}-{current_year:04d}") ; execute (formatted_date)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- percentage = 15.3 total = 3500 result = "%d %.2f\n\n" % (total, percentage) interest_rate = 8.7 sum_value = 4000 formatted_output = "%d %.1f\n\n" % (sum_value, interest_rate) print(formatted_output) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var percentage : double := 15.3 ; var total : int := 3500 ; var result : String := StringLib.format("%d %.2f\n\n",Sequence{total, percentage}) ; var interest_rate : double := 8.7 ; var sum_value : int := 4000 ; var formatted_output : String := StringLib.format("%d %.1f\n\n",Sequence{sum_value, interest_rate}) ; execute (formatted_output)->display() ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- produce_list = ["strawberry", "blueberry", "raspberry", "kiwi", "fig","fdfd","fdfdfd"] for item in produce_list: print(item) snacks = ["cookie", "cracker", "chip", "nut", "bar","dfdfd","fdfdfdf"] for snack in snacks: print(snack) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var produce_list : Sequence := Sequence{"strawberry"}->union(Sequence{"blueberry"}->union(Sequence{"raspberry"}->union(Sequence{"kiwi"}->union(Sequence{"fig"}->union(Sequence{"fdfd"}->union(Sequence{ "fdfdfd" })))))) ; for item : produce_list do ( execute (item)->display()) ; var snacks : Sequence := Sequence{"cookie"}->union(Sequence{"cracker"}->union(Sequence{"chip"}->union(Sequence{"nut"}->union(Sequence{"bar"}->union(Sequence{"dfdfd"}->union(Sequence{ "fdfdfdf" })))))) ; for snack : snacks do ( execute (snack)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- factor = 5 resultant = factor * 11 outcome = 10 * 7 new_result = 3 * 8 additional_factor = 6 new_product = additional_factor * 12 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var factor : int := 5 ; var resultant : int := factor * 11 ; var outcome : int := 10 * 7 ; var new_result : int := 3 * 8 ; var additional_factor : int := 6 ; var new_product : int := additional_factor * 12; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- message = "goodbye moon" for letter in message: i=i+1 print(letter) phrase = "welcome home" for ch in phrase: j=10 print(ch) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var message : String := "goodbye moon" ; for letter : message->characters() do ( var i : OclAny := i + 1 ; execute (letter)->display()) ; var phrase : String := "welcome home" ; for ch : phrase->characters() do ( var j : int := 10 ; execute (ch)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def increase(number: int): return number + 5*10 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; operation increase(number : int) : OclAny pre: true post: true activity: return number + 5 * 10; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculate_power(base: int) -> int: return base * base def calculate_sum(x: int, y: int) -> int: return x + y output_value = calculate_power(9) print("Square:", output_value) sum_result = calculate_sum(5, 3) print("Sum:", sum_result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var output_value : OclAny := calculate_power(9) ; execute ("Square:")->display() ; var sum_result : OclAny := calculate_sum(5, 3) ; execute ("Sum:")->display(); operation calculate_power(base : int) : int pre: true post: true activity: return base * base; operation calculate_sum(x : int, y : int) : int pre: true post: true activity: return x + y; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def increase_and_square(num): return square_value(num + 4) def square_value(n): return n * n result1 = increase_and_square(5) result2 = increase_and_square(8) print(result1) print(result2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var result1 : OclAny := increase_and_square(5) ; var result2 : OclAny := increase_and_square(8) ; execute (result1)->display() ; execute (result2)->display(); operation increase_and_square(num : OclAny) : OclAny pre: true post: true activity: return square_value(num + 4); operation square_value(n : OclAny) : OclAny pre: true post: true activity: return n * n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def scale_by_factor(initial=12): factor = 300 final_result = initial return factor * final_result+90 computed_value = scale_by_factor(7) print(computed_value) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var computed_value : OclAny := scale_by_factor(7) ; execute (computed_value)->display(); operation scale_by_factor(initial : int) : OclAny pre: true post: true activity: if initial->oclIsUndefined() then initial := 12 else skip; var factor : int := 300 ; var final_result : int := initial ; return factor * final_result + 90; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def validate_and_assign(number): if number < 0: global temporary_value temporary_value = 8 else: pass validate_and_assign(-7) print(temporary_value) additional_value = 12 print(additional_value) total = temporary_value + additional_value print("The total is:", total) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute temporary_value : OclAny; operation initialise() pre: true post: true activity: skip ; validate_and_assign(-7) ; execute (temporary_value)->display() ; var additional_value : int := 12 ; execute (additional_value)->display() ; var total : OclAny := temporary_value + additional_value ; execute ("The total is:")->display(); operation validate_and_assign(number : OclAny) pre: true post: true activity: if number < 0 then ( skip ; temporary_value := 8 ) else ( skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def modify_parameters(multiplier): global first_value, second_value first_value = 2 * 9*multiplier second_value = 6 * multiplier+8 modify_parameters(7) print(first_value) print(second_value) extra_value = 10 result_sum = first_value + second_value + extra_value print(result_sum) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute first_value : OclAny; attribute second_value : OclAny; operation initialise() pre: true post: true activity: skip ; modify_parameters(7) ; execute (first_value)->display() ; execute (second_value)->display() ; var extra_value : int := 10 ; var result_sum : OclAny := first_value + second_value + extra_value ; execute (result_sum)->display(); operation modify_parameters(multiplier : OclAny) pre: true post: true activity: skip; skip ; first_value := 2 * 9 * multiplier ; second_value := 6 * multiplier + 8; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def set_and_get(): global result_value result_value = 9 return result_value set_and_get() print(result_value) additional_value = 4 final_result = result_value + additional_value print(final_result) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute result_value : OclAny; operation initialise() pre: true post: true activity: skip ; set_and_get() ; execute (result_value)->display() ; var additional_value : int := 4 ; var final_result : OclAny := result_value + additional_value ; execute (final_result)->display(); operation set_and_get() : OclAny pre: true post: true activity: skip ; result_value := 9 ; return result_value; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- status = True value1 = 8 value2 = 22 if status: value1 = 14 value2 = 30 else: value1 = 10 value2 = 25 print(value1) print(value2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var status : boolean := true ; var value1 : int := 8 ; var value2 : int := 22 ; if status then ( value1 := 14 ; value2 := 30 ) else ( value1 := 10 ; value2 := 25 ) ; execute (value1)->display() ; execute (value2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- status = True quantity = 18 divider = 6 threshold = 10 if status: if quantity > threshold: quantity = quantity // divider else: quantity = quantity * 2 else: quantity = 9 print(quantity) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var status : boolean := true ; var quantity : int := 18 ; var divider : int := 6 ; var threshold : int := 10 ; if status then ( if (quantity->compareTo(threshold)) > 0 then ( quantity := quantity div divider ) else ( quantity := quantity * 2 ) ) else ( quantity := 9 ) ; execute (quantity)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- grid = [[15, 16, 17], [18, 19, 20]] print(grid[1][2]) value = 25 x = y = value extra_grid = [[21, 22, 23], [24, 25, 26]] print(extra_grid[1][1]) print(y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var grid : Sequence := Sequence{Sequence{15}->union(Sequence{16}->union(Sequence{ 17 }))}->union(Sequence{ Sequence{18}->union(Sequence{19}->union(Sequence{ 20 })) }) ; execute (grid[1+1][2+1])->display() ; var value : int := 25 ; var x : OclAny := value; var y : int := value ; var extra_grid : Sequence := Sequence{Sequence{21}->union(Sequence{22}->union(Sequence{ 23 }))}->union(Sequence{ Sequence{24}->union(Sequence{25}->union(Sequence{ 26 })) }) ; execute (extra_grid[1+1][1+1])->display() ; execute (y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- base8_num = 0o567 print(base8_num) base16_num = 0x123 print(base16_num) base2_num = 0b1101 print(base2_num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var base8_num : int := 0o567 ; execute (base8_num)->display() ; var base16_num : int := 0x123 ; execute (base16_num)->display() ; var base2_num : int := 0b1101 ; execute (base2_num)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- details = {'m': 7, 'n': 14, 'o': 21, 'p': 28} additional_value1 = 40 additional_value2 = 45 extra_value = 50 data_pairs = details.items() print(extra_value) print(additional_value1, additional_value2) print(data_pairs) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var details : Map := Map{ 'm' |-> 7 }->union(Map{ 'n' |-> 14 }->union(Map{ 'o' |-> 21 }->union(Map{ 'p' |-> 28 }))) ; var additional_value1 : int := 40 ; var additional_value2 : int := 45 ; var extra_value : int := 50 ; var data_pairs : Sequence := details->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) ; execute (extra_value)->display() ; execute (additional_value1)->display() ; execute (data_pairs)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- triple = lambda x: x ** 3 another_value = 10 output = triple(5) print(another_value) print(output) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var triple : Function := lambda x : OclAny in ((x)->pow(3)) ; var another_value : int := 10 ; var output : OclAny := triple->apply(5) ; execute (another_value)->display() ; execute (output)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- square = lambda a: a ** 2 cube = lambda b: b ** 3 extra_value1 = 8 calculations = [square, cube] extra_value2 = 12 for calc in calculations: print(calc(6)) print(extra_value1, extra_value2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var square : Function := lambda a : OclAny in ((a)->pow(2)) ; var cube : Function := lambda b : OclAny in ((b)->pow(3)) ; var extra_value1 : int := 8 ; var calculations : Sequence := Sequence{square}->union(Sequence{ cube }) ; var extra_value2 : int := 12 ; for calc : calculations do ( execute (calc(6))->display()) ; execute (extra_value1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- chars = ['a', 'b', 'c', 'd', 'e', 'f','o','t'] print(len(chars)) extra_item = 'g' chars.append(extra_item) print(chars) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var chars : Sequence := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{'c'}->union(Sequence{'d'}->union(Sequence{'e'}->union(Sequence{'f'}->union(Sequence{'o'}->union(Sequence{ 't' }))))))) ; execute ((chars)->size())->display() ; var extra_item : String := 'g' ; execute ((extra_item) : chars) ; execute (chars)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- group1 = [7, 8, 9,10,11,12] group2 = [7, 8, 9,10,11,12] additional_var1 = 10 additional_var2 = 20 print(str(group1 is group2)) print(str(group1 == group2)) print(additional_var1, additional_var2) group3 = group1 print(str(group1 is group3)) print(str(group1 == group3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var group1 : Sequence := Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{10}->union(Sequence{11}->union(Sequence{ 12 }))))) ; var group2 : Sequence := Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{10}->union(Sequence{11}->union(Sequence{ 12 }))))) ; var additional_var1 : int := 10 ; var additional_var2 : int := 20 ; execute (("" + ((group1 <>= group2))))->display() ; execute (("" + ((group1 = group2))))->display() ; execute (additional_var1)->display() ; var group3 : Sequence := group1 ; execute (("" + ((group1 <>= group3))))->display() ; execute (("" + ((group1 = group3))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- alpha = 'p' beta = 'q' gamma = 'r' additional_val = 17 assoc = {alpha: 14, beta: 15, gamma: 16} print(additional_val) print(assoc[beta]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var alpha : String := 'p' ; var beta : String := 'q' ; var gamma : String := 'r' ; var additional_val : int := 17 ; var assoc : Map := Map{ alpha |-> 14 }->union(Map{ beta |-> 15 }->union(Map{ gamma |-> 16 })) ; execute (additional_val)->display() ; execute (assoc->at(beta))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- item1 = 'm' item2 = 'n' item3 = 'o' extra_key = 'p' extra_value = 14 sub_dict = {item3: 12} full_dict = {item1: 11, **sub_dict, item2: 13} print(full_dict[item3]) i=100 full_dict[extra_key] = extra_value print(full_dict) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var item1 : String := 'm' ; var item2 : String := 'n' ; var item3 : String := 'o' ; var extra_key : String := 'p' ; var extra_value : int := 14 ; var sub_dict : Map := Map{ item3 |-> 12 } ; var full_dict : Map := Map{ item1 |-> 11 }->union(sub_dict->union(Map{ item2 |-> 13 })) ; execute (full_dict->at(item3))->display() ; var i : int := 100 ; full_dict->at(extra_key) := extra_value ; execute (full_dict)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- data = dict({"carrot": 15, "broccoli": 25, "spinach": 35}) print(data["carrot"]) o=3 new_entry = {"lettuce": 40} o=o+10 data.update(new_entry) print(data) print(o) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var data : Map := (Map{ "carrot" |-> 15 }->union(Map{ "broccoli" |-> 25 }->union(Map{ "spinach" |-> 35 }))) ; execute (data->at("carrot"))->display() ; var o : int := 3 ; var new_entry : Map := Map{ "lettuce" |-> 40 } ; o := o + 10 ; execute ((new_entry) <: data) ; execute (data)->display() ; execute (o)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- info_dict = dict({"dog": 10, "cat": 11, "rabbit": 12, "bird": 20}) key_names = [k for k in info_dict] print(key_names) tt=10.5 extra_key = "hamster" print(tt) info_dict[extra_key] = 13 print(info_dict) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var info_dict : Map := (Map{ "dog" |-> 10 }->union(Map{ "cat" |-> 11 }->union(Map{ "rabbit" |-> 12 }->union(Map{ "bird" |-> 20 })))) ; var key_names : Sequence := info_dict->keys()->select(k | true)->collect(k | (k)) ; execute (key_names)->display() ; var tt : double := 10.5 ; var extra_key : String := "hamster" ; execute (tt)->display() ; info_dict->at(extra_key) := 13 ; execute (info_dict)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- amount = 1000 amount >>= 3 amount <<= 2 amount **= 2 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var amount : int := 1000 ; amount := amount div (2->pow(3)) ; amount := amount * (2->pow(2)) ; amount := amount->pow(2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- words_list = ["mango", "pear", "plum", "date", "pomegranate"] verify_size = lambda item: len(item) > 4 rs=9 outcomes = map(verify_size, words_list) rs=rs*10 additional_count = 5 print(rs) print(any(outcomes)) print(all(outcomes)) print(additional_count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var words_list : Sequence := Sequence{"mango"}->union(Sequence{"pear"}->union(Sequence{"plum"}->union(Sequence{"date"}->union(Sequence{ "pomegranate" })))) ; var verify_size : Function := lambda item : OclAny in ((item)->size() > 4) ; var rs : int := 9 ; var outcomes : Sequence := (words_list)->collect( _x | (verify_size)->apply(_x) ) ; rs := rs * 10 ; var additional_count : int := 5 ; execute (rs)->display() ; execute ((outcomes)->exists( _x | _x = true ))->display() ; execute ((outcomes)->forAll( _x | _x = true ))->display() ; execute (additional_count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- first_dict = dict({"one": 10, "two": 20, "three": 30}) second_dict = dict({"two": 25, "three": 15, "four": 40}) merged_dict = first_dict | second_dict print(merged_dict) alpha = dict({"apple": 50, "banana": 60, "cherry": 70, , "grey": 90}) beta = dict({"banana": 65, "cherry": 45, "date": 80, , "kewi": 40}) gamma = alpha | beta a=10 delta = dict({"kiwi": 30, "lime": 35}) a=a*30 print(gamma) epsilon = dict({"mango": 90, "orange": 100}) print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var first_dict : Map := (Map{ "one" |-> 10 }->union(Map{ "two" |-> 20 }->union(Map{ "three" |-> 30 }))) ; var second_dict : Map := (Map{ "two" |-> 25 }->union(Map{ "three" |-> 15 }->union(Map{ "four" |-> 40 }))) ; var merged_dict : Map := first_dict->union(second_dict) ; execute (merged_dict)->display() ; var alpha : int := testlist_star_expr(stmt (simple_stmt (small_stmt (testlist_star_expr dict)) ( )) (stmt (simple_stmt (small_stmt (testlist_star_expr {)) "apple" :)) (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (number (integer 50))))))) , (test (logical_test (comparison (expr (atom "banana")))))) (assign_part : (test (logical_test (comparison (expr (atom (number (integer 60))))))))) ,)) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom "cherry"))))))) (assign_part : (test (logical_test (comparison (expr (atom (number (integer 70))))))))) , ,)) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom "grey"))))))) (assign_part : (test (logical_test (comparison (expr (atom (number (integer 90))))))))) }))) ; var beta : int := testlist_star_expr(stmt (simple_stmt (small_stmt (testlist_star_expr dict)) ( )) (stmt (simple_stmt (small_stmt (testlist_star_expr {)) "banana" :)) (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (number (integer 65))))))) , (test (logical_test (comparison (expr (atom "cherry")))))) (assign_part : (test (logical_test (comparison (expr (atom (number (integer 45))))))))) ,)) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom "date"))))))) (assign_part : (test (logical_test (comparison (expr (atom (number (integer 80))))))))) , ,)) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom "kewi"))))))) (assign_part : (test (logical_test (comparison (expr (atom (number (integer 40))))))))) }))) ; var gamma : int := MathLib.bitwiseOr(alpha, beta) ; var a : int := 10 ; var delta : Map := (Map{ "kiwi" |-> 30 }->union(Map{ "lime" |-> 35 })) ; a := a * 30 ; execute (gamma)->display() ; var epsilon : Map := (Map{ "mango" |-> 90 }->union(Map{ "orange" |-> 100 })) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math extra_value = math.sin(1.5) value_factorial_result = math.factorial(8) value_exponent = math.pow(3, 3) value_combination = math.comb(7, 4) value_truncate = math.trunc(5.9) value_square_root = math.sqrt(16.0) value_hyperbolic = math.cosh(2.0) value_multiplication = math.prod([3, 4, 5, 6, 7]) another_value = math.log(10) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var extra_value : double := (1.5)->sin() ; var value_factorial_result : long := MathLib.factorial(8) ; var value_exponent : double := (3)->pow(3) ; var value_combination : long := MathLib.combinatorial(7, 4) ; var value_truncate : int := (5.9)->oclAsType(int) ; var value_square_root : double := (16.0)->sqrt() ; var value_hyperbolic : double := (2.0)->cosh() ; var value_multiplication : double := (Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 7 })))))->prd() ; var another_value : double := (10)->log(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- arrayx = [10, 11, 12, 13, 14, 15, 16,50,89,56,55,66,77,88] arrayy = [2, 3, 5, 7, 9, 11, 13,44,66,77,88,99,94,23] result_product = [p + q -1 for p in arrayx for q in arrayy] print(result_product) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var arrayx : Sequence := Sequence{10}->union(Sequence{11}->union(Sequence{12}->union(Sequence{13}->union(Sequence{14}->union(Sequence{15}->union(Sequence{16}->union(Sequence{50}->union(Sequence{89}->union(Sequence{56}->union(Sequence{55}->union(Sequence{66}->union(Sequence{77}->union(Sequence{ 88 }))))))))))))) ; var arrayy : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{9}->union(Sequence{11}->union(Sequence{13}->union(Sequence{44}->union(Sequence{66}->union(Sequence{77}->union(Sequence{88}->union(Sequence{99}->union(Sequence{94}->union(Sequence{ 23 }))))))))))))) ; var result_product : Sequence := arrayx->select(p; q : arrayy | true)->collect(p; q : arrayy | (p + q - 1)) ; execute (result_product)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class MainClass: def show(self): print("In MainClass") class SubClassA(MainClass): def show(self): print("In SubClassA") class SubClassB(MainClass): def show(self): print("In SubClassB") class AdditionalClass(MainClass): def show(self): print("In AdditionalClass") class ExtraClassOne(MainClass): def show(self): print("In ExtraClassOne") class ExtraClassTwo(MainClass): def show(self): print("In ExtraClassTwo") class UnifiedClass(SubClassA, SubClassB, AdditionalClass, ExtraClassOne, ExtraClassTwo): def __init__(self): self.data = 10 self.info = "Sample" self.value = 42 self.description = "Extended Example" instance = UnifiedClass() instance.show() ------------------------------------------------------------ OCL File: --------- class MainClass { static operation newMainClass() : MainClass pre: true post: MainClass->exists( _x | result = _x ); operation show() pre: true post: true activity: execute ("In MainClass")->display(); } class SubClassA extends MainClass { static operation newSubClassA() : SubClassA pre: true post: SubClassA->exists( _x | result = _x ); operation show() pre: true post: true activity: execute ("In SubClassA")->display(); } class SubClassB extends MainClass { static operation newSubClassB() : SubClassB pre: true post: SubClassB->exists( _x | result = _x ); operation show() pre: true post: true activity: execute ("In SubClassB")->display(); } class AdditionalClass extends MainClass { static operation newAdditionalClass() : AdditionalClass pre: true post: AdditionalClass->exists( _x | result = _x ); operation show() pre: true post: true activity: execute ("In AdditionalClass")->display(); } class ExtraClassOne extends MainClass { static operation newExtraClassOne() : ExtraClassOne pre: true post: ExtraClassOne->exists( _x | result = _x ); operation show() pre: true post: true activity: execute ("In ExtraClassOne")->display(); } class ExtraClassTwo extends MainClass { static operation newExtraClassTwo() : ExtraClassTwo pre: true post: ExtraClassTwo->exists( _x | result = _x ); operation show() pre: true post: true activity: execute ("In ExtraClassTwo")->display(); } class UnifiedClass extends SubClassA, SubClassB, AdditionalClass, ExtraClassOne, ExtraClassTwo { static operation newUnifiedClass() : UnifiedClass pre: true post: UnifiedClass->exists( _x | result = _x ); attribute data : int := 10; attribute info : String := "Sample"; attribute value : int := 42; attribute description : String := "Extended Example"; operation initialise() : MainClass pre: true post: true activity: self.data := 10 ; self.info := "Sample" ; self.value := 42 ; self.description := "Extended Example"; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var instance : UnifiedClass := (UnifiedClass.newUnifiedClass()).initialise() ; instance.show(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Person: id_number = "" class JobRole: designation = "" class Division: department_name = "" class Project: project_name = "" class Office: location = "" class Schedule: work_hours = "" class Manager(Person, JobRole): duties = [] class TeamManager(Manager, Division): members = [] class SeniorManager(TeamManager, Project): projects_handled = [] class RegionalManager(SeniorManager, Office): regions = [] class HRManager(RegionalManager, Schedule): hr_tasks = [] employee = Person() employee.id_number = "E123" role = JobRole() role.designation = "Analyst" division = Division() division.department_name = "Sales" project = Project() project.project_name = "Expansion" office = Office() office.location = "tripoli" schedule = Schedule() schedule.work_hours = "9am - 5pm" manager = Manager() manager.duties = ["Planning", "Execution"] team_manager = TeamManage ------------------------------------------------------------ OCL File: --------- class Person { static operation newPerson() : Person pre: true post: Person->exists( _x | result = _x ); static attribute id_number : String := ""; } class JobRole { static operation newJobRole() : JobRole pre: true post: JobRole->exists( _x | result = _x ); static attribute designation : String := ""; } class Division { static operation newDivision() : Division pre: true post: Division->exists( _x | result = _x ); static attribute department_name : String := ""; } class Project { static operation newProject() : Project pre: true post: Project->exists( _x | result = _x ); static attribute project_name : String := ""; } class Office { static operation newOffice() : Office pre: true post: Office->exists( _x | result = _x ); static attribute location : String := ""; } class Schedule { static operation newSchedule() : Schedule pre: true post: Schedule->exists( _x | result = _x ); static attribute work_hours : String := ""; } class Manager extends Person, JobRole { static operation newManager() : Manager pre: true post: Manager->exists( _x | result = _x ); static attribute duties : Sequence := Sequence{}; } class TeamManager extends Manager, Division { static operation newTeamManager() : TeamManager pre: true post: TeamManager->exists( _x | result = _x ); static attribute members : Sequence := Sequence{}; } class SeniorManager extends TeamManager, Project { static operation newSeniorManager() : SeniorManager pre: true post: SeniorManager->exists( _x | result = _x ); static attribute projects_handled : Sequence := Sequence{}; } class RegionalManager extends SeniorManager, Office { static operation newRegionalManager() : RegionalManager pre: true post: RegionalManager->exists( _x | result = _x ); static attribute regions : Sequence := Sequence{}; } class HRManager extends RegionalManager, Schedule { static operation newHRManager() : HRManager pre: true post: HRManager->exists( _x | result = _x ); static attribute hr_tasks : Sequence := Sequence{}; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var employee : Person := (Person.newPerson()).initialise() ; employee.id_number := "E123" ; var role : JobRole := (JobRole.newJobRole()).initialise() ; role.designation := "Analyst" ; var division : Division := (Division.newDivision()).initialise() ; division.department_name := "Sales" ; var project : Project := (Project.newProject()).initialise() ; project.project_name := "Expansion" ; var office : Office := (Office.newOffice()).initialise() ; office.location := "tripoli" ; var schedule : Schedule := (Schedule.newSchedule()).initialise() ; schedule.work_hours := "9am - 5pm" ; var manager : Manager := (Manager.newManager()).initialise() ; manager.duties := Sequence{"Planning"}->union(Sequence{ "Execution" }) ; var team_manager : OclAny := TeamManage; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- number = 789 print(type(number)) number = "Hanan" print(type(number)) status = True print(type(status)) data = [1, 2, 3] print(type(data)) number = 2.718 print(type(number)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var number : int := 789 ; execute ((number)->oclType())->display() ; number := "Hanan" ; execute ((number)->oclType())->display() ; var status : boolean := true ; execute ((status)->oclType())->display() ; var data : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; execute ((data)->oclType())->display() ; number := 2.718 ; execute ((number)->oclType())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- letter = 'a' array1 = ['a', 'b', 'c', 'd','e'] array2 = [['a', 'b', 'c', 'd','e'], ['e', 'f', 'g', 'h','r']] if letter in array1 in array2: print(array1) else: print(array2) i=90 extra = 'z' array3 = [1, 2, 3, 5] i=i*8 array4 = [[1, 2, 3,6], [4, 5, 6,8]] print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var letter : String := 'a' ; var array1 : Sequence := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{'c'}->union(Sequence{'d'}->union(Sequence{ 'e' })))) ; var array2 : Sequence := Sequence{Sequence{'a'}->union(Sequence{'b'}->union(Sequence{'c'}->union(Sequence{'d'}->union(Sequence{ 'e' }))))}->union(Sequence{ Sequence{'e'}->union(Sequence{'f'}->union(Sequence{'g'}->union(Sequence{'h'}->union(Sequence{ 'r' })))) }) ; if (array1)->includes(letter) & (array2->includes(array1)) then ( execute (array1)->display() ) else ( execute (array2)->display() ) ; var i : int := 90 ; var extra : String := 'z' ; var array3 : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 5 }))) ; i := i * 8 ; var array4 : Sequence := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 6 })))}->union(Sequence{ Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 8 }))) }) ; execute (i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def update_value(): global value value = 7 return value value = 100 update_value() print(value) additional = 42 k=90 result = additional * 2 print(result) k=k+6 print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute value : OclAny; operation initialise() pre: true post: true activity: skip ; value := 100 ; update_value() ; execute (value)->display() ; var additional : int := 42 ; var k : int := 90 ; var result : int := additional * 2 ; execute (result)->display() ; k := k + 6 ; execute (k)->display(); operation update_value() : OclAny pre: true post: true activity: skip ; value := 7 ; return value; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np grid = [[1, 2, 3], [4, 5, 6]] print(np.shape(grid)) i=9 sequence1 = np.arange(8) k=8 print(sequence1) j=7 sequence2 = np.arange(3.0) i=i+j print(sequence2) j=j*10 sequence3 = np.arange(4, 12) k=100 print(sequence3) print(k) sequence4 = np.arange(1, 15, 4) print(k+i+j) print(sequence4) k=90 extra = np.linspace(0, 1, 5) print(extra) print(k+10) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var grid : Sequence := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{ Sequence{4}->union(Sequence{5}->union(Sequence{ 6 })) }) ; execute (MatrixLib.shape(grid))->display() ; var i : int := 9 ; var sequence1 : Sequence := MathLib.numericRange(0, (8), 1) ; var k : int := 8 ; execute (sequence1)->display() ; var j : int := 7 ; var sequence2 : Sequence := MathLib.numericRange(0, (3.0), 1) ; i := i + j ; execute (sequence2)->display() ; j := j * 10 ; var sequence3 : Sequence := MathLib.numericRange(4, 12, 1) ; k := 100 ; execute (sequence3)->display() ; execute (k)->display() ; var sequence4 : Sequence := MathLib.numericRange(1, 15, 4) ; execute (k + i + j)->display() ; execute (sequence4)->display() ; k := 90 ; var extra : Sequence := MathLib.numericSeries(0, 1, 5->oclAsType(int)) ; execute (extra)->display() ; execute (k + 10)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- total = 12 total += 9 total *= 6 total /= 2 total //= 2 quantity = 25 quantity += 10 quantity *= 3 quantity /= 7 quantity //= 4 new_total = 18 new_total += 11 new_total *= 5 new_total /= 4 new_total //= 2 adjustment = 30 adjustment += 8 adjustment *= 2 adjustment /= 6 adjustment //= 3 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var total : int := 12 ; total := total + 9 ; total := total * 6 ; total := total / 2 ; total := total div 2 ; var quantity : int := 25 ; quantity := quantity + 10 ; quantity := quantity * 3 ; quantity := quantity / 7 ; quantity := quantity div 4 ; var new_total : int := 18 ; new_total := new_total + 11 ; new_total := new_total * 5 ; new_total := new_total / 4 ; new_total := new_total div 2 ; var adjustment : int := 30 ; adjustment := adjustment + 8 ; adjustment := adjustment * 2 ; adjustment := adjustment / 6 ; adjustment := adjustment div 3; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np grid = [[1, 2, 3], [4, 5, 6]] array_a = np.empty((2, 4)) array_b = np.empty_like(grid) array_c = np.eye(3) array_d = np.identity(4) array_e = np.ones_like(grid) array_f = np.full([3], 7) additional_array = np.zeros((2, 5)) print(additional_array) print(array_a) print(array_b) print(array_c) print(array_d) print(array_e) print(array_f) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var grid : Sequence := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{ Sequence{4}->union(Sequence{5}->union(Sequence{ 6 })) }) ; var array_a : Sequence := MatrixLib.singleValueMatrix(Sequence{2, 4}, 0.0) ; var array_b : Sequence := MatrixLib.singleValueMatrix(MatrixLib.shape(grid), 0.0) ; var array_c : Sequence := MatrixLib.identityMatrix(3) ; var array_d : Sequence := MatrixLib.identityMatrix(4) ; var array_e : Sequence := MatrixLib.singleValueMatrix(MatrixLib.shape(grid), 1.0) ; var array_f : Sequence := MatrixLib.singleValueMatrix(Sequence{ 3 }, 7) ; var additional_array : Sequence := MatrixLib.singleValueMatrix(Sequence{2, 5}, 0.0) ; execute (additional_array)->display() ; execute (array_a)->display() ; execute (array_b)->display() ; execute (array_c)->display() ; execute (array_d)->display() ; execute (array_e)->display() ; execute (array_f)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np grid = np.ones([2, 5]) dimensions = grid.shape print(dimensions[0]) grid[:, 1] = grid[:, 1] + 1 grid[:, 0] = grid[:, 0] * 2 print(grid) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var grid : Sequence := MatrixLib.singleValueMatrix(Sequence{2}->union(Sequence{ 5 }), 1.0) ; var dimensions : Sequence := MatrixLib.shape(grid) ; execute (dimensions->first())->display() ; grid->collect( _r | _r[1+1] ) := MatrixLib.elementwiseAdd(grid->collect( _r | _r[1+1] ), 1) ; grid->collect( _r | _r->first() ) := MatrixLib.elementwiseMult(grid->collect( _r | _r->first() ), 2) ; execute (grid)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np array = np.ones([2, 5]) array[:, 0] = array[:, 0] * 6 array[:, 1] = np.sqrt(array[:, 0]) array[:, 2] = array[:, 2] * 2e+6 print(array) new_array = np.full([2, 5], 9) print(new_array) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var array : Sequence := MatrixLib.singleValueMatrix(Sequence{2}->union(Sequence{ 5 }), 1.0) ; array->collect( _r | _r->first() ) := MatrixLib.elementwiseMult(array->collect( _r | _r->first() ), 6) ; array->collect( _r | _r[1+1] ) := MatrixLib.elementwiseApply(array->collect( _r | _r->first() ), lambda x : double in (x->sqrt())) ; array->collect( _r | _r[2+1] ) := MatrixLib.elementwiseMult(array->collect( _r | _r[2+1] ), ("2e+6")->toReal()) ; execute (array)->display() ; var new_array : Sequence := MatrixLib.singleValueMatrix(Sequence{2}->union(Sequence{ 5 }), 9) ; execute (new_array)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np grid = np.ones([4, 5]) grid[1, :] = 8 grid[:, 0] = 4 rotated_grid = np.transpose(grid) doubled_grid = grid * 2+100 print(rotated_grid) print(grid) print(doubled_grid) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var grid : Sequence := MatrixLib.singleValueMatrix(Sequence{4}->union(Sequence{ 5 }), 1.0) ; grid[1+1] := 8 ; grid->collect( _r | _r->first() ) := 4 ; var rotated_grid : Sequence := MatrixLib.transpose(grid) ; var doubled_grid : Sequence := MatrixLib.elementwiseAdd(MatrixLib.elementwiseMult(grid, 2), 100) ; execute (rotated_grid)->display() ; execute (grid)->display() ; execute (doubled_grid)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np matrix = np.ones([5, 5]) i=10 matrix[3, :] = 9 matrix[:, 2] = 5 sum_total = np.sum(matrix) product_total = np.prod(matrix) jj=90 new_array = np.random.rand(3, 3) print(jj) print(new_array) print(product_total) print(matrix > 2) print(sum_total) print(matrix) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var matrix : Sequence := MatrixLib.singleValueMatrix(Sequence{5}->union(Sequence{ 5 }), 1.0) ; var i : int := 10 ; matrix[3+1] := 9 ; matrix->collect( _r | _r[2+1] ) := 5 ; var sum_total : double := MatrixLib.sumMatrix(matrix) ; var product_total : double := MatrixLib.prdMatrix(matrix) ; var jj : int := 90 ; var new_array : Sequence := OclRandom.randomValuesMatrix(3, 3) ; execute (jj)->display() ; execute (new_array)->display() ; execute (product_total)->display() ; execute (matrix > 2)->display() ; execute (sum_total)->display() ; execute (matrix)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections sorted_dict = collections.OrderedDict({"apple": 5, "banana": 15, "cherry": 25}) sorted_dict["banana"] = 18 n=9 sorted_dict["date"] = 30 n=n+9 print(sorted_dict) print(n) additional_dict = collections.OrderedDict({"kiwi": 50, "lemon": 60}) print(additional_dict) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var sorted_dict : Map := (Map{ "apple" |-> 5 }->union(Map{ "banana" |-> 15 }->union(Map{ "cherry" |-> 25 }))) ; sorted_dict->at("banana") := 18 ; var n : int := 9 ; sorted_dict->at("date") := 30 ; n := n + 9 ; execute (sorted_dict)->display() ; execute (n)->display() ; var additional_dict : Map := (Map{ "kiwi" |-> 50 }->union(Map{ "lemon" |-> 60 })) ; execute (additional_dict)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- text_value = "example" character_list = ['a', 'b', 'c'] def update_values(text, chars): text = text + 'z' chars[1] = 'd' i=10 print(character_list) i=i+9 print(text_value) print("") update_values(text_value, character_list) print('**************') print(character_list) i=i+56 print(text_value) extra_list = ['p', 'q', 'r'] extra_value = "test" print(i) print(extra_list) print(extra_value) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var text_value : String := "example" ; var character_list : Sequence := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{ 'c' })) ; skip ; var i : int := 10 ; execute (character_list)->display() ; i := i + 9 ; execute (text_value)->display() ; execute ("")->display() ; update_values(text_value, character_list) ; execute ('**************')->display() ; execute (character_list)->display() ; i := i + 56 ; execute (text_value)->display() ; var extra_list : Sequence := Sequence{'p'}->union(Sequence{'q'}->union(Sequence{ 'r' })) ; var extra_value : String := "test" ; execute (i)->display() ; execute (extra_list)->display() ; execute (extra_value)->display(); operation update_values(text : OclAny, chars : OclAny) pre: true post: true activity: text := text + 'z' ; chars[1+1] := 'd'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- distinct_elements = set({'a', 'b', 'c'}) def modify_set(elements): elements.add('d') elements.update(set({'e', 'f'})) elements.difference_update(set({'a', 'b'})) elements.discard('c') oo=9 print(distinct_elements) print("") oo=oo-9 modify_set(distinct_elements) print(distinct_elements) g=9 additional_set = set({'g', 'h', 'i'}) g=g*8 print(additional_set) print(g+oo) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var distinct_elements : Set := Set{}->union((Set{'a'}->union(Set{'b'}->union(Set{ 'c' })))) ; skip ; var oo : int := 9 ; execute (distinct_elements)->display() ; execute ("")->display() ; oo := oo - 9 ; modify_set(distinct_elements) ; execute (distinct_elements)->display() ; var g : int := 9 ; var additional_set : Set := Set{}->union((Set{'g'}->union(Set{'h'}->union(Set{ 'i' })))) ; g := g * 8 ; execute (additional_set)->display() ; execute (g + oo)->display(); operation modify_set(elements : OclAny) pre: true post: true activity: execute (('d') : elements) ; execute ((Set{}->union((Set{'e'}->union(Set{ 'f' })))) <: elements) ; execute ((Set{}->union((Set{'a'}->union(Set{ 'b' })))) /<: elements) ; execute (('c') /: elements); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- count = 150 elements = ['a', 'b', 'c','d','e','f','g','h'] class User: def __init__(self): self.name = "" self.age = 25 user_instance = User() def modify_parameters(num, list_items, user_obj): num = num + 15 list_items.append('f') user_obj.name = "Taylor" user_obj.age = user_obj.age + 7 print(count) print(elements) print(user_instance.name) print(user_instance.age) print("") modify_parameters(count, elements, user_instance) print(count) print(elements) print(user_instance.name) print(user_instance.age) extra_list = ['j', 'k','p','t'] extra_value = 300 print(extra_list) print(extra_value) ------------------------------------------------------------ OCL File: --------- class User { static operation newUser() : User pre: true post: User->exists( _x | result = _x ); attribute name : String := ""; attribute age : int := 25; operation initialise() : User pre: true post: true activity: self.name := "" ; self.age := 25; return self; } class FromPython { operation initialise() pre: true post: true activity: var count : int := 150 ; var elements : Sequence := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{'c'}->union(Sequence{'d'}->union(Sequence{'e'}->union(Sequence{'f'}->union(Sequence{'g'}->union(Sequence{ 'h' }))))))) ; skip ; var user_instance : User := (User.newUser()).initialise() ; skip ; execute (count)->display() ; execute (elements)->display() ; execute (user_instance.name)->display() ; execute (user_instance.age)->display() ; execute ("")->display() ; modify_parameters(count, elements, user_instance) ; execute (count)->display() ; execute (elements)->display() ; execute (user_instance.name)->display() ; execute (user_instance.age)->display() ; var extra_list : Sequence := Sequence{'j'}->union(Sequence{'k'}->union(Sequence{'p'}->union(Sequence{ 't' }))) ; var extra_value : int := 300 ; execute (extra_list)->display() ; execute (extra_value)->display(); operation modify_parameters(num : OclAny, list_items : OclAny, user_obj : OclAny) pre: true post: true activity: num := num + 15 ; execute (('f') : list_items) ; user_obj.name := "Taylor" ; user_obj.age := user_obj.age + 7; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import pickle info = ["a", "b", "c", "d","r"] with open("datafile.pkl", "wb") as file_handle: pickle.dump(info, file_handle) t=10 with open("datafile.pkl", "rb") as file_handle: retrieved_info = pickle.load(file_handle) t=t+8 print(retrieved_info) print(t) additional_info = ["e", "f", "g", "r", "y"] print(additional_info) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var info : Sequence := Sequence{"a"}->union(Sequence{"b"}->union(Sequence{"c"}->union(Sequence{"d"}->union(Sequence{ "r" })))) ; try (var file_handle : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("datafile.pkl")); file_handle.writeObject(info)) catch (_e : OclException) do skip ; var t : int := 10 ; try (var file_handle : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("datafile.pkl")); var retrieved_info : OclAny := (file_handle).readObject()) catch (_e : OclException) do skip ; t := t + 8 ; execute (retrieved_info)->display() ; execute (t)->display() ; var additional_info : Sequence := Sequence{"e"}->union(Sequence{"f"}->union(Sequence{"g"}->union(Sequence{"r"}->union(Sequence{ "y" })))) ; execute (additional_info)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from datetime import * today = datetime.now() print(hasattr(today, 'hour')) print(hasattr(today, 'minute')) print(getattr(today, 'second')) next_moment = datetime.now() print(hasattr(next_moment, 'microsecond')) print(getattr(next_moment, 'month')) additional_date = datetime.now() print(hasattr(additional_date, 'day')) print(getattr(additional_date, 'hour')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var today : OclDate := OclDate.newOclDate() ; execute (OclType.hasAttribute(today, 'hour'))->display() ; execute (OclType.hasAttribute(today, 'minute'))->display() ; execute (OclType.getAttributeValue(today, 'second'))->display() ; var next_moment : OclDate := OclDate.newOclDate() ; execute (OclType.hasAttribute(next_moment, 'microsecond'))->display() ; execute (OclType.getAttributeValue(next_moment, 'month'))->display() ; var additional_date : OclDate := OclDate.newOclDate() ; execute (OclType.hasAttribute(additional_date, 'day'))->display() ; execute (OclType.getAttributeValue(additional_date, 'hour'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- designation = "Manager" jj=90 print(designation + " profile") print(jj) print(designation) status = "Active" department = "HR" print(status) print(department) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var designation : String := "Manager" ; var jj : int := 90 ; execute (designation + " profile")->display() ; execute (jj)->display() ; execute (designation)->display() ; var status : String := "Active" ; var department : String := "HR" ; execute (status)->display() ; execute (department)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import random randomizer = random.Random() number1 = randomizer.randrange(50) number2 = randomizer.gauss(5.0, 1.5) number3 = randomizer.uniform(10.0, 20.0) additional_value = randomizer.randint(1, 100) print(number1) print(number2) print(number3) print(additional_value) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var randomizer : OclRandom := OclRandom.newOclRandom() ; var number1 : int := randomizer.nextInt(50) ; var number2 : double := randomizer.nextNormal(5.0, (1.5)->sqr()) ; var number3 : double := randomizer.nextUniform(10.0, 20.0) ; var additional_value : int := randomizer.nextInt(100 - 1) + 1 ; execute (number1)->display() ; execute (number2)->display() ; execute (number3)->display() ; execute (additional_value)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import random ratio = random.random() digits = [15, 22, 33, 44, 55, 66] selection = random.sample(digits, 3) o=10 print(ratio) print(selection) print(o) extra_values = random.sample(digits, 5) print(extra_values) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var ratio : double := (OclRandom.defaultInstanceOclRandom()).nextDouble() ; var digits : Sequence := Sequence{15}->union(Sequence{22}->union(Sequence{33}->union(Sequence{44}->union(Sequence{55}->union(Sequence{ 66 }))))) ; var selection : Sequence := OclRandom.randomUniqueElements(digits, 3) ; var o : int := 10 ; execute (ratio)->display() ; execute (selection)->display() ; execute (o)->display() ; var extra_values : Sequence := OclRandom.randomUniqueElements(digits, 5) ; execute (extra_values)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- range_a = range(4) f=9 range_b = range(1, 8) m=8 range_c = range(3, 25, 6) d=77 chars = ['A', 'B', 'C','d','e','f','g'] enumerated_chars = enumerate(chars) print(list(range_a)) print(list(range_b)) print(list(range_c)) print(list(enumerated_chars)) additional_range = range(10, 15) print(list(additional_range)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var range_a : Sequence := Integer.subrange(0, 4-1) ; var f : int := 9 ; var range_b : Sequence := Integer.subrange(1, 8-1) ; var m : int := 8 ; var range_c : Sequence := Integer.subrange(3, 25-1)->select( $x | ($x - 3) mod 6 = 0 ) ; var d : int := 77 ; var chars : Sequence := Sequence{'A'}->union(Sequence{'B'}->union(Sequence{'C'}->union(Sequence{'d'}->union(Sequence{'e'}->union(Sequence{'f'}->union(Sequence{ 'g' })))))) ; var enumerated_chars : Sequence := Integer.subrange(1, (chars)->size())->collect( _indx | Sequence{_indx-1, (chars)->at(_indx)} ) ; execute ((range_a))->display() ; execute ((range_b))->display() ; execute ((range_c))->display() ; execute ((enumerated_chars))->display() ; var additional_range : Sequence := Integer.subrange(10, 15-1) ; execute ((additional_range))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(r"\n\t\b") message = "Example message" value = 58 g=9 output = f"Message: {message}, Value: {value}" print(output) print(g) extra_text = "Additional info" extra_number = 99 t=6+extra_number extra_result = f"Extra: {extra_text}, Extra Value: {extra_number}" print(extra_result) print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (StringLib.rawString("\n\t\b"))->display() ; var message : String := "Example message" ; var value : int := 58 ; var g : int := 9 ; var output : String := StringLib.formattedString("Message: {message}, Value: {value}") ; execute (output)->display() ; execute (g)->display() ; var extra_text : String := "Additional info" ; var extra_number : int := 99 ; var t : int := 6 + extra_number ; var extra_result : String := StringLib.formattedString("Extra: {extra_text}, Extra Value: {extra_number}") ; execute (extra_result)->display() ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re substitution = re.sub("E", "3", "HELLO") pattern_match = re.fullmatch("[a-z]*", "hello") found_matches = re.findall("[A-Z]+", "A QUICK BROWN FOX") print(substitution) print(found_matches) print(pattern_match) additional_text = "EXAMPLE TEXT" i=97 additional_replacement = re.sub("E", "1", additional_text) print(additional_replacement) print(i*8) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var substitution : String := ("HELLO").replaceAllMatches("E", "3") ; var pattern_match : String := ("hello")->firstMatch("^" + "[a-z]*" + "$") ; var found_matches : Sequence(String) := ("A QUICK BROWN FOX")->allMatches("[A-Z]+") ; execute (substitution)->display() ; execute (found_matches)->display() ; execute (pattern_match)->display() ; var additional_text : String := "EXAMPLE TEXT" ; var i : int := 97 ; var additional_replacement : String := (additional_text).replaceAllMatches("E", "1") ; execute (additional_replacement)->display() ; execute (i * 8)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- items = list(["apple", "banana", "cherry", "date", "fig"]) reversed_items = reversed(items) smallest_item = min(items) sorted_items = sorted(reversed_items) largest_item = max(items) print(smallest_item) print(largest_item) print(sorted_items) extra_items = ["grape", "kiwi", "lemon","gfgfgf","fdfd"] print(extra_items) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var items : Sequence := (Sequence{"apple"}->union(Sequence{"banana"}->union(Sequence{"cherry"}->union(Sequence{"date"}->union(Sequence{ "fig" }))))) ; var reversed_items : Sequence := (items)->reverse() ; var smallest_item : OclAny := (items)->min() ; var sorted_items : Sequence := reversed_items->sort() ; var largest_item : OclAny := (items)->max() ; execute (smallest_item)->display() ; execute (largest_item)->display() ; execute (sorted_items)->display() ; var extra_items : Sequence := Sequence{"grape"}->union(Sequence{"kiwi"}->union(Sequence{"lemon"}->union(Sequence{"gfgfgf"}->union(Sequence{ "fdfd" })))) ; execute (extra_items)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10,88,77,66,55,44] cubes = [x ** 3+2 for x in values if x % 2 != 0 if x > 5] print(cubes) hh=8 additional_values = [11, 12, 13,45,22] print(hh+9) print(additional_values) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var values : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{10}->union(Sequence{88}->union(Sequence{77}->union(Sequence{66}->union(Sequence{55}->union(Sequence{ 44 })))))))))))))) ; var cubes : Sequence := values->select(x | x mod 2 /= 0 & x > 5)->collect(x | ((x)->pow(3) + 2)) ; execute (cubes)->display() ; var hh : int := 8 ; var additional_values : Sequence := Sequence{11}->union(Sequence{12}->union(Sequence{13}->union(Sequence{45}->union(Sequence{ 22 })))) ; execute (hh + 9)->display() ; execute (additional_values)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- items = [3, 5, 7, 9, 11, 13, 15, 17, 19, 21,66,44,33] cubes = [x ** 3+6*10 for x in items if x % 2 != 0] print(cubes) k=10 extra_items = [22, 24, 26,44,55,33,66,77] k=k*10+6 print(extra_items) print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var items : Sequence := Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{9}->union(Sequence{11}->union(Sequence{13}->union(Sequence{15}->union(Sequence{17}->union(Sequence{19}->union(Sequence{21}->union(Sequence{66}->union(Sequence{44}->union(Sequence{ 33 })))))))))))) ; var cubes : Sequence := items->select(x | x mod 2 /= 0)->collect(x | ((x)->pow(3) + 6 * 10)) ; execute (cubes)->display() ; var k : int := 10 ; var extra_items : Sequence := Sequence{22}->union(Sequence{24}->union(Sequence{26}->union(Sequence{44}->union(Sequence{55}->union(Sequence{33}->union(Sequence{66}->union(Sequence{ 77 }))))))) ; k := k * 10 + 6 ; execute (extra_items)->display() ; execute (k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dd = [10, 20, 30] print(dd) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dd : Sequence := Sequence{10}->union(Sequence{20}->union(Sequence{ 30 })) ; execute (dd)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x : bool x = False y : int = 1000 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : boolean ; x := false ; var y : int := 1000; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import asyncio async def hello(i): print("task " + str(i) + " started") await asyncio.sleep(4) print("task " + str(i) + " done") async def mainop(): task1 = asyncio.create_task(hello(1)) await asyncio.sleep(3) task2 = asyncio.create_task(hello(2)) await task1 await task2 asyncio.run(mainop()) ------------------------------------------------------------ OCL File: --------- class Async$hello { stereotype active; attribute i : OclAny; static operation newAsync$hello(i : OclAny) : Async$hello pre: true post: Async$hello->exists( resx | resx.i = i & result = resx ); operation run() pre: true post: true activity: execute ("task " + ("" + ((i))) + " started")->display() ; OclProcess.sleepSeconds(4) ; execute ("task " + ("" + ((i))) + " done")->display(); } class Async$mainop { stereotype active; static operation newAsync$mainop() : Async$mainop pre: true post: Async$mainop->exists( resx | result = resx ); operation run() pre: true post: true activity: var task1 : OclProcess := (OclProcess.newOclProcess(Async$hello.newAsync$hello(1), "")).startProcess() ; OclProcess.sleepSeconds(3) ; var task2 : OclProcess := (OclProcess.newOclProcess(Async$hello.newAsync$hello(2), "")).startProcess() ; task1.join() ; task2.join(); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; (OclProcess.newOclProcess(Async$mainop.newAsync$mainop(), "")).start(); operation hello(i : OclAny) pre: true post: true activity: execute ("task " + ("" + ((i))) + " started")->display() ; OclProcess.sleepSeconds(4) ; execute ("task " + ("" + ((i))) + " done")->display(); operation mainop() pre: true post: true activity: var task1 : OclProcess := (OclProcess.newOclProcess(Async$hello.newAsync$hello(1), "")).startProcess() ; OclProcess.sleepSeconds(3) ; var task2 : OclProcess := (OclProcess.newOclProcess(Async$hello.newAsync$hello(2), "")).startProcess() ; task1.join() ; task2.join(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ss = [3,4,5] x = [1,*ss,2] print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ss : Sequence := Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })) ; var x : Sequence := Sequence{1}->union(ss->union(Sequence{ 2 })) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ss = [3,4,5] res = [x*x for x in ss] print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ss : Sequence := Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })) ; var res : Sequence := ss->select(x | true)->collect(x | (x * x)) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sq = [1, 0, -2, 5, 3] mm = sq[-2] print(mm) mm = sq[-4] print(mm) mm = sq[0] print(mm) mm = sq[1] print(mm) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sq : Sequence := Sequence{1}->union(Sequence{0}->union(Sequence{-2}->union(Sequence{5}->union(Sequence{ 3 })))) ; var mm : OclAny := sq->front()->last() ; execute (mm)->display() ; mm := sq->reverse()->at(-(-4)) ; execute (mm)->display() ; mm := sq->first() ; execute (mm)->display() ; mm := sq[1+1] ; execute (mm)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sq = [1, 0, -2, 5, 3] mm = sq[:-1] print(mm) mm = sq[1:] print(mm) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sq : Sequence := Sequence{1}->union(Sequence{0}->union(Sequence{-2}->union(Sequence{5}->union(Sequence{ 3 })))) ; var mm : OclAny := sq->front() ; execute (mm)->display() ; mm := sq->tail() ; execute (mm)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sq = [1, 0, -2, 5, 3] mm = sq[-3:-1] print(mm) mm = sq[1:-2] print(mm) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sq : Sequence := Sequence{1}->union(Sequence{0}->union(Sequence{-2}->union(Sequence{5}->union(Sequence{ 3 })))) ; var mm : OclAny := sq.subrange(-3+1, -1) ; execute (mm)->display() ; mm := sq.subrange(1+1, -2) ; execute (mm)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sq = [1, 0, -2, 5, 3] mm = sq[-1] print(mm) sq2 = [mm] sq3 = sq2 + sq print(sq3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sq : Sequence := Sequence{1}->union(Sequence{0}->union(Sequence{-2}->union(Sequence{5}->union(Sequence{ 3 })))) ; var mm : OclAny := sq->last() ; execute (mm)->display() ; var sq2 : Sequence := Sequence{ mm } ; var sq3 : Sequence := sq2->union(sq) ; execute (sq3)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- st = {1,2,3} print(len(st)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var st : Set := Set{1}->union(Set{2}->union(Set{ 3 })) ; execute ((st)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- stt = {1, 3, 5, 6} st1 = {7, 8} st2 = {9, 11} stt.update(st1,st2) print(stt) stt.discard(5) print(stt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var stt : Set := Set{1}->union(Set{3}->union(Set{5}->union(Set{ 6 }))) ; var st1 : Set := Set{7}->union(Set{ 8 }) ; var st2 : Set := Set{9}->union(Set{ 11 }) ; execute ((st1, st2) <: stt) ; execute (stt)->display() ; execute ((5) /: stt) ; execute (stt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s = {1, 2, 3} x = s.pop() print(x) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Set := Set{1}->union(Set{2}->union(Set{ 3 })) ; var x : OclAny := s->last() ; s := s->front() ; execute (x)->display() ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- st = set({'a', 'b', 'c'}) st.intersection_update(set({'a', 'b', 'd'})) print(st) st.clear() print(st) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var st : Set := Set{}->union((Set{'a'}->union(Set{'b'}->union(Set{ 'c' })))) ; execute ((st - (Set{}->union((Set{'a'}->union(Set{'b'}->union(Set{ 'd' })))))) /<: st) ; execute (st)->display() ; execute (st /<: st) ; execute (st)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Person : name = "" age = 0 ------------------------------------------------------------ OCL File: --------- class Person { static operation newPerson() : Person pre: true post: Person->exists( _x | result = _x ); static attribute name : String := ""; static attribute age : int := 0; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s = [1,2,4] x = s.pop(2) ------------------------------------------------------------ OCL File: --------- file_input ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = input("Enter a value ") t = type(x) slce = slice(4) slce = slice(2,10) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := (OclFile["System.in"]).readLine("Enter a value ") ; var t : OclType := (x)->oclType() ; var slce : Sequence := Integer.subrange(1,4) ; slce := Integer.subrange(2+1,10); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Student: def __init__(self, name, grade, age): self.name = name self.grade = grade self.age = age def __repr__(self): return repr((self.name, self.grade, self.age)) student_objects = [ Student('john', 'A', 15), Student('jane', 'B', 12), Student('dave', 'B', 10) ] stds = sorted(student_objects, key=lambda student: student.age) print(stds) ------------------------------------------------------------ OCL File: --------- class Student { static operation newStudent() : Student pre: true post: Student->exists( _x | result = _x ); attribute name : int := name; attribute grade : OclAny := grade; attribute age : OclAny := age; operation initialise(name : OclAny,grade : OclAny,age : OclAny) : Student pre: true post: true activity: self.name := name ; self.grade := grade ; self.age := age; return self; operation __repr__() : OclAny pre: true post: true activity: return ("" + ((Sequence{self.name, self.grade, self.age}))); } class FromPython { operation initialise() pre: true post: true activity: skip ; var student_objects : Sequence := Sequence{(Student.newStudent()).initialise('john', 'A', 15)}->union(Sequence{(Student.newStudent()).initialise('jane', 'B', 12)}->union(Sequence{ (Student.newStudent()).initialise('dave', 'B', 10) })) ; var stds : Sequence := student_objects->sortedBy($x | (lambda student : OclAny in (student.age))->apply($x)) ; execute (stds)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dct = dict({"a" : 1, "c" : 3, "d" : 4, "b" : 2}) print(sorted(dct)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dct : Map := (Map{ "a" |-> 1 }->union(Map{ "c" |-> 3 }->union(Map{ "d" |-> 4 }->union(Map{ "b" |-> 2 })))) ; execute (dct->keys()->sort())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- y = -5.5 x = abs(y) print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var y : double := -5.5 ; var x : double := (y)->abs() ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Calc : def __init__(self,x) : self.n = x def f(self,x) : self.n = x + self.n self.n = self.n + self.n return x*self.n def g(self,x) : self.n = x + self.n self.n = self.n + self.n return self.n//x c = Calc(2) print(c.f(1)) print(c.g(3)) ------------------------------------------------------------ OCL File: --------- class Calc { static operation newCalc() : Calc pre: true post: Calc->exists( _x | result = _x ); attribute n : OclAny := x; operation initialise(x : OclAny) : Calc pre: true post: true activity: self.n := x; return self; operation f(x : OclAny) : OclAny pre: true post: true activity: self.n := x + self.n ; self.n := self.n + self.n ; return x * self.n; operation g(x : OclAny) : OclAny pre: true post: true activity: self.n := x + self.n ; self.n := self.n + self.n ; return self.n div x; } class FromPython { operation initialise() pre: true post: true activity: skip ; var c : Calc := (Calc.newCalc()).initialise(2) ; execute (c.f(1))->display() ; execute (c.g(3))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Calc : def __init__(self,x) : self.n = x def f(self,x) : if x > 0 : self.n = x + self.n self.n = self.n + self.n return x*self.n return x def g(self,x) : if x > 1 : self.n = x + self.n self.n = self.n + self.n return self.n//x return x c = Calc(2) print(c.f(1)) print(c.g(3)) ------------------------------------------------------------ OCL File: --------- class Calc { static operation newCalc() : Calc pre: true post: Calc->exists( _x | result = _x ); attribute n : OclAny := x; operation initialise(x : OclAny) : Calc pre: true post: true activity: self.n := x; return self; operation f(x : OclAny) : OclAny pre: true post: true activity: if x > 0 then ( self.n := x + self.n ; self.n := self.n + self.n ; return x * self.n ) else skip ; return x; operation g(x : OclAny) : OclAny pre: true post: true activity: if x > 1 then ( self.n := x + self.n ; self.n := self.n + self.n ; return self.n div x ) else skip ; return x; } class FromPython { operation initialise() pre: true post: true activity: skip ; var c : Calc := (Calc.newCalc()).initialise(2) ; execute (c.f(1))->display() ; execute (c.g(3))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sq = [1, 0, -2, 5, 3] print(min(sq)) print(max(sq)) mm = min(3,1) nn = max(3,1) print(mm) print(nn) if nn == (2 or 3) : print(nn + 1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sq : Sequence := Sequence{1}->union(Sequence{0}->union(Sequence{-2}->union(Sequence{5}->union(Sequence{ 3 })))) ; execute ((sq)->min())->display() ; execute ((sq)->max())->display() ; var mm : OclAny := Set{3, 1}->min() ; var nn : OclAny := Set{3, 1}->max() ; execute (mm)->display() ; execute (nn)->display() ; if nn = (if 2 /= 0 then 2 else 3 endif) then ( execute (nn + 1)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- stq = "a long string" fsq = [ord(x) for x in stq] print(fsq) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var stq : String := "a long string" ; var fsq : Sequence := stq->characters()->select(x | true)->collect(x | ((x)->char2byte())) ; execute (fsq)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s1 = "hello" s2 = s1 s2 += " world" print(s1) print(s2) # This is an example that Copilot gets incorrect. ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s1 : String := "hello" ; var s2 : String := s1 ; s2 := s2 + " world" ; execute (s1)->display() ; execute (s2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Person : name = "" def __init__(self) : self.age = 0 pp = Person() ------------------------------------------------------------ OCL File: --------- class Person { static operation newPerson() : Person pre: true post: Person->exists( _x | result = _x ); static attribute name : String := ""; attribute age : int := 0; operation initialise() : Person pre: true post: true activity: self.age := 0; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; var pp : Person := (Person.newPerson()).initialise(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s = "a long string" x = s.count("n") s1 = s.capitalize() s1 = s.title() s1 = s.replace(" ", "*") s1 = s.lstrip() s1 = s.strip() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := "a long string" ; var x : int := s->count("n") ; var s1 : String := StringLib.capitalise(s) ; s1 := StringLib.toTitleCase(s) ; s1 := s.replace(" ", "*") ; s1 := StringLib.leftTrim(s) ; s1 := s->trim(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sq = ['a', 'b', 'c', 'd', 'e', 'f'] print(sq[1:4]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sq : Sequence := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{'c'}->union(Sequence{'d'}->union(Sequence{'e'}->union(Sequence{ 'f' }))))) ; execute (sq.subrange(1+1, 4))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sq = ['a', 'b', 'c', 'd', 'e', 'f'] print(sq[:4]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sq : Sequence := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{'c'}->union(Sequence{'d'}->union(Sequence{'e'}->union(Sequence{ 'f' }))))) ; execute (sq.subrange(1,4))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- v = ['a', 'b', 'c'] x = 'x' v.extend('d') print(v) v.insert(2,x) print(v) v.sort() print(v) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var v : Sequence := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{ 'c' })) ; var x : String := 'x' ; v := v->union('d') ; execute (v)->display() ; v := v.insertAt(2+1, x) ; execute (v)->display() ; v := v->sort() ; execute (v)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s = [1,2,3] s.pop(2) print(s.index(3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; s := s->excludingAt(2+1) ; execute (s->indexOf(3) - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = 15 y = 32 z = 6 x,y,z = z,x,y print(x) print(y) print(z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 15 ; var y : int := 32 ; var z : int := 6 ; Sequence{x,y,z} := Sequence{z,x,y} ; execute (x)->display() ; execute (y)->display() ; execute (z)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sq = [(1,1), (2,2), (3,6), (4,24)] fsq = [x*y for x,y in sq] print(fsq) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sq : Sequence := Sequence{Sequence{1, 1}}->union(Sequence{Sequence{2, 2}}->union(Sequence{Sequence{3, 6}}->union(Sequence{ Sequence{4, 24} }))) ; var fsq : Sequence := sq->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (x * y)) ; execute (fsq)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sq = [(1,1), (2,2), (3,6), (4,24)] for x,y in sq : print(x*y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sq : Sequence := Sequence{Sequence{1, 1}}->union(Sequence{Sequence{2, 2}}->union(Sequence{Sequence{3, 6}}->union(Sequence{ Sequence{4, 24} }))) ; for _tuple : sq do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); execute (x * y)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = "a" y = "b" z = "c" tple = (x, y, z) a , b , c = tple ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := "a" ; var y : String := "b" ; var z : String := "c" ; var tple : OclAny := Sequence{x, y, z} ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := tple; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math sq = ["aa", "bb", "cc"] x = len(sq) y = math.pow(x,2) d = math.sin(3.0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var sq : Sequence := Sequence{"aa"}->union(Sequence{"bb"}->union(Sequence{ "cc" })) ; var x : int := (sq)->size() ; var y : double := (x)->pow(2) ; var d : double := (3.0)->sin(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Person : name = "" def __init__(self) : self.age = 0 def incr(self,n) : self.age = self.age + n pp = Person() pp.incr(5) print(pp.age) ------------------------------------------------------------ OCL File: --------- class Person { static operation newPerson() : Person pre: true post: Person->exists( _x | result = _x ); static attribute name : String := ""; attribute age : int := 0; operation initialise() : Person pre: true post: true activity: self.age := 0; return self; operation incr(n : OclAny) pre: true post: true activity: self.age := self.age + n; } class FromPython { operation initialise() pre: true post: true activity: skip ; var pp : Person := (Person.newPerson()).initialise() ; pp.incr(5) ; execute (pp.age)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = 100 y = 33.0e-10 s = set({x,y}) m = dict({'a' : x, 'b' : y}) sq = [x,y,x] t = "string value" print(sq + [4,50]) print(x + y) print(t + ' non-empty') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 100 ; var y : double := ("33.0e-10")->toReal() ; var s : Set := Set{}->union((Set{x}->union(Set{ y }))) ; var m : Map := (Map{ 'a' |-> x }->union(Map{ 'b' |-> y })) ; var sq : Sequence := Sequence{x}->union(Sequence{y}->union(Sequence{ x })) ; var t : String := "string value" ; execute (sq->union(Sequence{4}->union(Sequence{ 50 })))->display() ; execute (x + y)->display() ; execute (t + ' non-empty')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i = 0 f = 1 while i < 10 : i = i + 1 f = f*i ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : int := 0 ; var f : int := 1 ; while i < 10 do ( i := i + 1 ; f := f * i); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- text = "some lines\nof text\nthree lines\n" with open('f.txt', 'w') as fle, open('g.txt', '+r') as gg : v = gg.read() fle.write(v) fle.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var text : String := "some lines\nof text\nthree lines\n" ; try (var fle : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('f.txt')); var gg : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('g.txt')); var v : String := gg.readAll() ; fle.write(v) ; fle.closeFile()) catch (_e : OclException) do skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- text = "some lines\nof text\nthree lines\n" with open('f.txt', 'w') as fle : fle.write(text) fle.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var text : String := "some lines\nof text\nthree lines\n" ; try (var fle : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('f.txt')); fle.write(text) ; fle.closeFile()) catch (_e : OclException) do skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def yfunc() : yield 1 yield 2 yield 3 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; operation yfunc(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return 1 ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return 2 ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return 3; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def yfunc() : yield 1 yield 2 yield 3 ff = yfunc() print(next(ff)) print(next(ff)) print(next(ff)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var ff : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.yfunc(_i)) ; execute ((ff).next())->display() ; execute ((ff).next())->display() ; execute ((ff).next())->display(); operation yfunc(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return 1 ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return 2 ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return 3; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import pandas as pd titanic = pd.read_csv("data/titanic.csv") ages = titanic["Age"] mn = ages.mean() print(mn) md = titanic[["Age", "Fare"]].median() print(md) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var titanic : Map := OclFile.newOclFile_Read(OclFile.newOclFile(("data/titanic.csv"))).readMap() ; var ages : OclAny := titanic->at("Age") ; var mn : double := MathLib.mean(ages) ; execute (mn)->display() ; var md : OclAny := MathLib.median(titanic->restrict(Sequence{"Age"}->union(Sequence{ "Fare" }))) ; execute (md)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Person : def __init__(self,nme) : self.name = nme self.age = 0 def getAge(self) : return self.age ------------------------------------------------------------ OCL File: --------- class Person { static operation newPerson() : Person pre: true post: Person->exists( _x | result = _x ); attribute name : OclAny := nme; attribute age : int := 0; operation initialise(nme : OclAny) : Person pre: true post: true activity: self.name := nme ; self.age := 0; return self; operation getAge() : OclAny pre: true post: true activity: return self.age; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Person : def __init__(self,nme) : self.name = nme self.age = 0 def birthday(self) : self.age += 1 return self.age pp = Person("Tom") pp.birthday() pp.birthday() ------------------------------------------------------------ OCL File: --------- class Person { static operation newPerson() : Person pre: true post: Person->exists( _x | result = _x ); attribute name : OclAny := nme; attribute age : int := 0; operation initialise(nme : OclAny) : Person pre: true post: true activity: self.name := nme ; self.age := 0; return self; operation birthday() : OclAny pre: true post: true activity: self.age := self.age + 1 ; return self.age; } class FromPython { operation initialise() pre: true post: true activity: skip ; var pp : Person := (Person.newPerson()).initialise("Tom") ; pp.birthday() ; pp.birthday(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s = [1, 2, 3, 4] res = { x : x*x for x in s } print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))) ; var res : Map := s->select(x | true)->collect(x | Map{x |-> x * x})->unionAll() ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ss = [1,2,3,4,5,6] res = [x*x for x in ss if x % 2 == 0] print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ss : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))))) ; var res : Sequence := ss->select(x | x mod 2 = 0)->collect(x | (x * x)) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s = {1,2,3,4} print({ x*x for x in s }) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Set := Set{1}->union(Set{2}->union(Set{3}->union(Set{ 4 }))) ; execute (s->select(x | true)->collect(x | x * x)->asSet())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t1 = (1,3,3) t2 = (1,3,4) if t1 < t2 : print(True) else : print(False) x = "X" y = "Y" print(x < y) print(3 < 5) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t1 : OclAny := Sequence{1, 3, 3} ; var t2 : OclAny := Sequence{1, 3, 4} ; if (t1->compareTo(t2)) < 0 then ( execute (true)->display() ) else ( execute (false)->display() ) ; var x : String := "X" ; var y : String := "Y" ; execute (x < y)->display() ; execute (3 < 5)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x : bool = True y : int = 1000 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : boolean := true ; var y : int := 1000; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ss = [1,2,3,4,3,2,1] x = 2 print(ss.count(x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ss : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 1 })))))) ; var x : int := 2 ; execute (ss->count(x))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from datetime import * today = datetime.today() print(today.year) print(today.month) print(today.day) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var today : OclDate := OclDate.newOclDate() ; execute (today.getYear())->display() ; execute (today.getMonth())->display() ; execute (today.getDate())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def proc1(x) : pass def proc2(x,y) : pass def proc3(x) : pass def proc4(x,y) : pass def proc5(x,y) : pass def f(x,y) : if x > 0 : proc1(x) if y > 0 : proc2(x,y) return 1 else : proc3(x) return 2 else : if y > 0 : proc4(x,y) return 3 else : proc5(x,y) return 4 print(f(1,1)) print(f(1,-1)) print(f(-1,1)) print(f(-1,-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; execute (f(1, 1))->display() ; execute (f(1, -1))->display() ; execute (f(-1, 1))->display() ; execute (f(-1, -1))->display(); operation proc1(x : OclAny) pre: true post: true activity: skip; operation proc2(x : OclAny, y : OclAny) pre: true post: true activity: skip; operation proc3(x : OclAny) pre: true post: true activity: skip; operation proc4(x : OclAny, y : OclAny) pre: true post: true activity: skip; operation proc5(x : OclAny, y : OclAny) pre: true post: true activity: skip; operation f(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if x > 0 then ( proc1(x) ; if y > 0 then ( proc2(x, y) ; return 1 ) else ( proc3(x) ; return 2 ) ) else ( if y > 0 then ( proc4(x, y) ; return 3 ) else ( proc5(x, y) ; return 4 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(x,y) : if x > 0 : if y > 0 : return 1 else : return 2 else : if y > 0 : return 3 else : return 4 print(f(1,1)) print(f(1,-1)) print(f(-1,1)) print(f(-1,-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (f(1, 1))->display() ; execute (f(1, -1))->display() ; execute (f(-1, 1))->display() ; execute (f(-1, -1))->display(); operation f(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if x > 0 then ( if y > 0 then ( return 1 ) else ( return 2 ) ) else ( if y > 0 then ( return 3 ) else ( return 4 ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def op(x, y = 1.0) : z = 1.0 z = z + x/y print(z) op(3,2) op(4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; op(3, 2) ; op(4); operation op(x : OclAny, y : double) pre: true post: true activity: if y->oclIsUndefined() then y := 1.0 else skip; var z : double := 1.0 ; z := z + x / y ; execute (z)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a = [1, 2, 3] b = ['a', 'b', 'c'] x = zip(a,b) print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; var b : Sequence := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{ 'c' })) ; var x : Sequence := Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), b->at(_indx)} ) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- st = set({'a', 'b', 'c'}) del st print(st) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var st : Set := Set{}->union((Set{'a'}->union(Set{'b'}->union(Set{ 'c' })))) ; execute (st)->isDeleted() ; execute (st)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s = ['a', 'b', 'c', 'd', 'e', 'f'] del s[1] del s[1:3] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{'c'}->union(Sequence{'d'}->union(Sequence{'e'}->union(Sequence{ 'f' }))))) ; execute (s[1+1])->isDeleted() ; execute (s.subrange(1+1, 3))->isDeleted(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d4 = collections.deque(['a', 'b', 'c']) d4.appendleft('q') d4.appendleft('p') print(d4) d4.extendleft(['w','q']) print(d4) p = d4.pop() print(d4) d4.popleft() print(d4) # d4.rotate(), rotate(n) > right print(d4.maxlen) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d4 : Sequence := (Sequence{'a'}->union(Sequence{'b'}->union(Sequence{ 'c' }))) ; d4 := d4->prepend('q') ; d4 := d4->prepend('p') ; execute (d4)->display() ; d4 := d4->reverse()->union(Sequence{'w'}->union(Sequence{ 'q' }))->reverse() ; execute (d4)->display() ; var p : OclAny := d4->last() ; d4 := d4->front() ; execute (d4)->display() ; d4 := d4->tail() ; execute (d4)->display() ; execute (d4->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = 1 if x > 1 : z = x*x print(z + x) elif x > 0 : z = x*x*x print(z + x) else : z = -x print(z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 1 ; if x > 1 then ( var z : int := x * x ; execute (z + x)->display() ) else (if x > 0 then ( z := x * x * x ; execute (z + x)->display() ) else ( z := -x ; execute (z)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = 7 arr = [3,5,x] print(arr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 7 ; var arr : Sequence := Sequence{3}->union(Sequence{5}->union(Sequence{ x })) ; execute (arr)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = 1 if x > 0 : z = x*x print(z + x) else : z = x*x*x print(z + x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 1 ; if x > 0 then ( var z : int := x * x ; execute (z + x)->display() ) else ( z := x * x * x ; execute (z + x)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(x) : if x < 0 : y = -x else : y = x return y print(f(-3)) print(f(1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (f(-3))->display() ; execute (f(1))->display(); operation f(x : OclAny) : OclAny pre: true post: true activity: if x < 0 then ( var y : OclAny := -x ) else ( y := x ) ; return y; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num = 11 x = 0 y = 0 if num > 5 : x = num elif num < 5 : y = num else: x = 0 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := 11 ; var x : int := 0 ; var y : int := 0 ; if num > 5 then ( x := num ) else (if num < 5 then ( y := num ) else ( x := 0 ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from enum import Enum class Colour(Enum) : red = 1 green = 2 blue = 3 print(Colour.green.value) ------------------------------------------------------------ OCL File: --------- class Colour { static operation newColour() : Colour pre: true post: Colour->exists( _x | result = _x ); static attribute red : int := 1; static attribute green : int := 2; static attribute blue : int := 3; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; execute (Colour.green)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from enum import Enum class Colour(Enum) : red = 1 green = 2 ------------------------------------------------------------ OCL File: --------- class Colour { static operation newColour() : Colour pre: true post: Colour->exists( _x | result = _x ); static attribute red : int := 1; static attribute green : int := 2; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def bondPrice(yld,settle,matur,coup,dayCount,freq) : return (coup*(matur-settle))/math.pow((1 + yld), matur-settle) def accumulatedInterest(issue,settle,freq,coup,dayCount,matur) : period = int(12/freq) return (settle - issue)*coup/period def bondPriceClean(yld,issue,settle,matur,coup,dayCount,freq) : return bondPrice(yld,settle,matur,coup,dayCount,freq) - accumulatedInterest(issue,settle,freq,coup,dayCount,matur) v = bondPriceClean(0.02, 2019.0, 2019.25, 2023.0, 0.015, "Actual/Actual", 2) print(v) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var v : OclAny := bondPriceClean(0.02, 2019.0, 2019.25, 2023.0, 0.015, "Actual/Actual", 2) ; execute (v)->display(); operation bondPrice(yld : OclAny, settle : OclAny, matur : OclAny, coup : OclAny, dayCount : OclAny, freq : OclAny) : OclAny pre: true post: true activity: return (coup * (matur - settle)) / ((1 + yld))->pow(matur - settle); operation accumulatedInterest(issue : OclAny, settle : OclAny, freq : OclAny, coup : OclAny, dayCount : OclAny, matur : OclAny) : OclAny pre: true post: true activity: var period : int := ("" + ((12 / freq)))->toInteger() ; return (settle - issue) * coup / period; operation bondPriceClean(yld : OclAny, issue : OclAny, settle : OclAny, matur : OclAny, coup : OclAny, dayCount : OclAny, freq : OclAny) : OclAny pre: true post: true activity: return bondPrice(yld, settle, matur, coup, dayCount, freq) - accumulatedInterest(issue, settle, freq, coup, dayCount, matur); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(eval("5**5")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((5)->pow(5))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- day = 24 try : if day > 31 : raise ValueError("invalid day") except ValueError as msg : print(msg) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var day : int := 24 ; try ( if day > 31 then ( error IncorrectElementException.newIncorrectElementException("invalid day") ) else skip) catch (msg : IncorrectElementException) do ( execute (msg)->display()) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = 10 exec("x = 5") print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 10 ; x := 5 ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- exec("x = 5; print(x*x)") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 5; execute (x * x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = 12.5 assert type(x) is int, 'Argument must be integer!' ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : double := 12.5 ; assert (x)->oclType() <>= OclType["int"] do 'Argument must be integer!'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(x,y) : if x > 0 : if y > 0 : return (x + y)*(x + y) else : return (x - y)*(x - y) else : if y > 0 : return (x + y)*(x + y) else : return (x - y)*(x + y) print(f(1,1)) print(f(1,-1)) print(f(-1,1)) print(f(-1,-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (f(1, 1))->display() ; execute (f(1, -1))->display() ; execute (f(-1, 1))->display() ; execute (f(-1, -1))->display(); operation f(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if x > 0 then ( if y > 0 then ( return (x + y) * (x + y) ) else ( return (x - y) * (x - y) ) ) else ( if y > 0 then ( return (x + y) * (x + y) ) else ( return (x - y) * (x + y) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(x,y) : if x > 0 : if y > 0 : return ((x + y)*(x + y))**2 else : return (x - y)*(x - y) else : if y > 0 : return ((x + y)*(x + y))**3 else : return (x - y)*(x + y) print(f(1,1)) print(f(1,-1)) print(f(-1,1)) print(f(-1,-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (f(1, 1))->display() ; execute (f(1, -1))->display() ; execute (f(-1, 1))->display() ; execute (f(-1, -1))->display(); operation f(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if x > 0 then ( if y > 0 then ( return (((x + y) * (x + y)))->pow(2) ) else ( return (x - y) * (x - y) ) ) else ( if y > 0 then ( return (((x + y) * (x + y)))->pow(3) ) else ( return (x - y) * (x + y) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f = open('myfile', 'r') s = f.read() f.close() g = open('myfile', 'a') g.write(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('myfile')) ; var s : String := f.readAll() ; f.closeFile() ; var g : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('myfile')) ; g.write(s); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sq = ["aa", "bbb", "cc", "dd", "eeee"] f = lambda x : len(x) > 2 sq1 = filter(f,sq) for y in sq1 : print(y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sq : Sequence := Sequence{"aa"}->union(Sequence{"bbb"}->union(Sequence{"cc"}->union(Sequence{"dd"}->union(Sequence{ "eeee" })))) ; var f : Function := lambda x : OclAny in ((x)->size() > 2) ; var sq1 : Sequence := (sq)->select( _x | (f)->apply(_x) = true ) ; for y : sq1 do ( execute (y)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d = dict({ "a" : 1, "b" : 2 }) for x in d : print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : Map := (Map{ "a" |-> 1 }->union(Map{ "b" |-> 2 })) ; for x : d->keys() do ( execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = 1000 y = 9.9 s = 'Token' ss = "%s: %d %f\n\n" % (s,x,y) print(ss) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 1000 ; var y : double := 9.9 ; var s : String := 'Token' ; var ss : String := StringLib.format("%s: %d %f\n\n",Sequence{s, x, y}) ; execute (ss)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = 1000 y = 9.9 ss = "{0} and {1}\n\n".format(x,y) print(ss) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 1000 ; var y : double := 9.9 ; var ss : String := StringLib.interpolateStrings("{0} and {1}\n\n", Sequence{x, y}) ; execute (ss)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- day = 31 month = 7 year = 2023 ss = f"{day:02d}/{month:02d}/{year:04d}" print(ss) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var day : int := 31 ; var month : int := 7 ; var year : int := 2023 ; var ss : String := StringLib.formattedString("{day:02d}/{month:02d}/{year:04d}") ; execute (ss)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = 1000 y = 9.9 ss = "%d %f\n\n" % (x,y) print(ss) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 1000 ; var y : double := 9.9 ; var ss : String := StringLib.format("%d %f\n\n",Sequence{x, y}) ; execute (ss)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sq = ["a", "b", "c", "d"] for x in sq : print x ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sq : Sequence := Sequence{"a"}->union(Sequence{"b"}->union(Sequence{"c"}->union(Sequence{ "d" }))) ; for x : sq do ( execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = 5*7 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 5 * 7; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ss = "a long string" for x in ss : print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ss : String := "a long string" ; for x : ss->characters() do ( execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ff(x : int) : return x + 1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; operation ff(x : int) : OclAny pre: true post: true activity: return x + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ff(x : int) -> int : return x*x print(ff(4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (ff(4))->display(); operation ff(x : int) : int pre: true post: true activity: return x * x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ff(x) : return gg(x+1) def gg(y) : return y*y print(ff(1)) print(ff(4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; execute (ff(1))->display() ; execute (ff(4))->display(); operation ff(x : OclAny) : OclAny pre: true post: true activity: return gg(x + 1); operation gg(y : OclAny) : OclAny pre: true post: true activity: return y * y; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ff(x = 10) : y = 100 z = x return y*z ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; operation ff(x : int) : OclAny pre: true post: true activity: if x->oclIsUndefined() then x := 10 else skip; var y : int := 100 ; var z : int := x ; return y * z; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(y) : if y > 0 : global x x = 2 else : pass f(1) print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute x : OclAny; operation initialise() pre: true post: true activity: skip ; f(1) ; execute (x)->display(); operation f(y : OclAny) pre: true post: true activity: if y > 0 then ( skip ; x := 2 ) else ( skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(z) : global x, y x = 2*z y = 4*z f(2) print(x) print(y) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute x : OclAny; attribute y : OclAny; operation initialise() pre: true post: true activity: skip ; f(2) ; execute (x)->display() ; execute (y)->display(); operation f(z : OclAny) pre: true post: true activity: skip; skip ; x := 2 * z ; y := 4 * z; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f() : global x x = 2 return x f() print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute x : OclAny; operation initialise() pre: true post: true activity: skip ; f() ; execute (x)->display(); operation f() : OclAny pre: true post: true activity: skip ; x := 2 ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t = True x = 0 y = 0 if t : x = 8 y = 10 print(x) print(y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : boolean := true ; var x : int := 0 ; var y : int := 0 ; if t then ( x := 8 ; y := 10 ) else skip ; execute (x)->display() ; execute (y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t = True y = 5 x = 2 if t : y = y//x else : y = 0 print(y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : boolean := true ; var y : int := 5 ; var x : int := 2 ; if t then ( y := y div x ) else ( y := 0 ) ; execute (y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sq = [[1,2,3], [4,5,6]] print(sq[1][2]) z = 10 x = y = z print(x) print(y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sq : Sequence := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{ Sequence{4}->union(Sequence{5}->union(Sequence{ 6 })) }) ; execute (sq[1+1][2+1])->display() ; var z : int := 10 ; var x : OclAny := z; var y : int := z ; execute (x)->display() ; execute (y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = 0o3454 y = 0xFFF z = 0b1100 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 0o3454 ; var y : int := 0xFFF ; var z : int := 0b1100; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d = dict({'a':1, 'b':2, 'c':3}) sq = d.items() print(sq) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : Map := (Map{ 'a' |-> 1 }->union(Map{ 'b' |-> 2 }->union(Map{ 'c' |-> 3 }))) ; var sq : Sequence := d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) ; execute (sq)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- square = lambda x : x**2 y = square(5) print(y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var square : Function := lambda x : OclAny in ((x)->pow(2)) ; var y : OclAny := square->apply(5) ; execute (y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- square = lambda x : x**2 cube = lambda y : y**3 vec = [square,cube] for x in vec : print(x(5)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var square : Function := lambda x : OclAny in ((x)->pow(2)) ; var cube : Function := lambda y : OclAny in ((y)->pow(3)) ; var vec : Sequence := Sequence{square}->union(Sequence{ cube }) ; for x : vec do ( execute (x(5))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ss = ['a', 'b', 'c', 'd'] print(len(ss)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ss : Sequence := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{'c'}->union(Sequence{ 'd' }))) ; execute ((ss)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l1 = [1,2,3] l2 = [1,2,3] print(str(l1 is l2)) print(str(l1 == l2)) l3 = l1 print(str(l1 is l3)) print(str(l1 == l3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l1 : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; var l2 : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; execute (("" + ((l1 <>= l2))))->display() ; execute (("" + ((l1 = l2))))->display() ; var l3 : Sequence := l1 ; execute (("" + ((l1 <>= l3))))->display() ; execute (("" + ((l1 = l3))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a = 'a' b = 'b' c = 'c' m = {a:1, b:2, c:3} print(m['b']) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := 'a' ; var b : String := 'b' ; var c : String := 'c' ; var m : Map := Map{ a |-> 1 }->union(Map{ b |-> 2 }->union(Map{ c |-> 3 })) ; execute (m->at('b'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a = 'a' b = 'b' c = 'c' m = {c : 3} mm = {a:1, **m, b:2} print(mm['c']) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := 'a' ; var b : String := 'b' ; var c : String := 'c' ; var m : Map := Map{ c |-> 3 } ; var mm : Map := Map{ a |-> 1 }->union(m->union(Map{ b |-> 2 })) ; execute (mm->at('c'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a = dict({"x":1, "y":2, "z":3}) print(a["x"]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Map := (Map{ "x" |-> 1 }->union(Map{ "y" |-> 2 }->union(Map{ "z" |-> 3 }))) ; execute (a->at("x"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mm = dict({"a" : 1, "b" : 2, "c" : 3}) fsq = [x for x in mm] print(fsq) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mm : Map := (Map{ "a" |-> 1 }->union(Map{ "b" |-> 2 }->union(Map{ "c" |-> 3 }))) ; var fsq : Sequence := mm->keys()->select(x | true)->collect(x | (x)) ; execute (fsq)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = 1024 x <<= 2 x >>= 3 x **= 4 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 1024 ; x := x * (2->pow(2)) ; x := x div (2->pow(3)) ; x := x->pow(4); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sq = ["aa", "bbb", "cc", "dd", "eeee"] f = lambda x : len(x) > 2 sq1 = map(f,sq) print(any(sq1)) print(all(sq1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sq : Sequence := Sequence{"aa"}->union(Sequence{"bbb"}->union(Sequence{"cc"}->union(Sequence{"dd"}->union(Sequence{ "eeee" })))) ; var f : Function := lambda x : OclAny in ((x)->size() > 2) ; var sq1 : Sequence := (sq)->collect( _x | (f)->apply(_x) ) ; execute ((sq1)->exists( _x | _x = true ))->display() ; execute ((sq1)->forAll( _x | _x = true ))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d1 = dict({"a":1, "b":2, "c":3}) d2 = dict({"b":4, "c":1, "d":4}) d = d1 | d2 print(d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d1 : Map := (Map{ "a" |-> 1 }->union(Map{ "b" |-> 2 }->union(Map{ "c" |-> 3 }))) ; var d2 : Map := (Map{ "b" |-> 4 }->union(Map{ "c" |-> 1 }->union(Map{ "d" |-> 4 }))) ; var d : Map := d1->union(d2) ; execute (d)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = math.pow(3,5) y = math.trunc(3.6) n = math.comb(5,2) n = math.factorial(11) x = math.prod([1,2,3,4,5]) x = math.cosh(0.5) x = math.sqrt(2.0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : double := (3)->pow(5) ; var y : int := (3.6)->oclAsType(int) ; var n : long := MathLib.combinatorial(5, 2) ; n := MathLib.factorial(11) ; x := (Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))))->prd() ; x := (0.5)->cosh() ; x := (2.0)->sqrt(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sq1 = [1, 2, 3, 4] sq2 = [2, 3, 6, 24] fsq = [x*y for x in sq1 for y in sq2] print(fsq) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sq1 : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))) ; var sq2 : Sequence := Sequence{2}->union(Sequence{3}->union(Sequence{6}->union(Sequence{ 24 }))) ; var fsq : Sequence := sq1->select(x; y : sq2 | true)->collect(x; y : sq2 | (x * y)) ; execute (fsq)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Class1: def m(self): print("In Class1") class Class2(Class1): def m(self): print("In Class2") class Class3(Class1): def m(self): print("In Class3") class Class4(Class2, Class3): pass obj = Class4() obj.m() # result is: In Class 2. ------------------------------------------------------------ OCL File: --------- class Class1 { static operation newClass1() : Class1 pre: true post: Class1->exists( _x | result = _x ); operation m() pre: true post: true activity: execute ("In Class1")->display(); } class Class2 extends Class1 { static operation newClass2() : Class2 pre: true post: Class2->exists( _x | result = _x ); operation m() pre: true post: true activity: execute ("In Class2")->display(); } class Class3 extends Class1 { static operation newClass3() : Class3 pre: true post: Class3->exists( _x | result = _x ); operation m() pre: true post: true activity: execute ("In Class3")->display(); } class Class4 extends Class2, Class3 { static operation newClass4() : Class4 pre: true post: Class4->exists( _x | result = _x ); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var obj : Class4 := (Class4.newClass4()).initialise() ; obj.m(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Person : name = "" class Role : rolename = "" class Manager(Person,Role) : manages = [] ------------------------------------------------------------ OCL File: --------- class Person { static operation newPerson() : Person pre: true post: Person->exists( _x | result = _x ); static attribute name : String := ""; } class Role { static operation newRole() : Role pre: true post: Role->exists( _x | result = _x ); static attribute rolename : String := ""; } class Manager extends Person, Role { static operation newManager() : Manager pre: true post: Manager->exists( _x | result = _x ); static attribute manages : Sequence := Sequence{}; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = 123 print(type(x)) x = 0.9 print(type(x)) x = "a string" print(type(x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 123 ; execute ((x)->oclType())->display() ; x := 0.9 ; execute ((x)->oclType())->display() ; x := "a string" ; execute ((x)->oclType())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = 'b' y = ['a', 'b', 'c'] z = [['a', 'b', 'c'], ['e', 'd', 'f']] if x in y in z : print(y) else : print(z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := 'b' ; var y : Sequence := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{ 'c' })) ; var z : Sequence := Sequence{Sequence{'a'}->union(Sequence{'b'}->union(Sequence{ 'c' }))}->union(Sequence{ Sequence{'e'}->union(Sequence{'d'}->union(Sequence{ 'f' })) }) ; if (y)->includes(x) & (z->includes(y)) then ( execute (y)->display() ) else ( execute (z)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f() : nonlocal x x = 2 return x x = 100 f() print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute x : OclAny; operation initialise() pre: true post: true activity: skip ; x := 100 ; f() ; execute (x)->display(); operation f() : OclAny pre: true post: true activity: skip ; x := 2 ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np x = [[1,2,3], [4,5,6]] print(np.shape(x)) y = np.arange(3) print(y) y = np.arange(3.0) print(y) y = np.arange(3,7) print(y) y = np.arange(3,7,2) print(y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : Sequence := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{ Sequence{4}->union(Sequence{5}->union(Sequence{ 6 })) }) ; execute (MatrixLib.shape(x))->display() ; var y : Sequence := MathLib.numericRange(0, (3), 1) ; execute (y)->display() ; y := MathLib.numericRange(0, (3.0), 1) ; execute (y)->display() ; y := MathLib.numericRange(3, 7, 1) ; execute (y)->display() ; y := MathLib.numericRange(3, 7, 2) ; execute (y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = 5 x += 10 x *= 3 x /= 2 x //= 2 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 5 ; x := x + 10 ; x := x * 3 ; x := x / 2 ; x := x div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np x = [[1,2,3], [4,5,6]] y = np.empty((2,2)) print(y) y = np.empty_like(x) print(y) y = np.eye(3) print(y) y = np.identity(7) print(y) y = np.ones_like(x) print(y) y = np.full([3],10) print(y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : Sequence := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{ Sequence{4}->union(Sequence{5}->union(Sequence{ 6 })) }) ; var y : Sequence := MatrixLib.singleValueMatrix(Sequence{2, 2}, 0.0) ; execute (y)->display() ; y := MatrixLib.singleValueMatrix(MatrixLib.shape(x), 0.0) ; execute (y)->display() ; y := MatrixLib.identityMatrix(3) ; execute (y)->display() ; y := MatrixLib.identityMatrix(7) ; execute (y)->display() ; y := MatrixLib.singleValueMatrix(MatrixLib.shape(x), 1.0) ; execute (y)->display() ; y := MatrixLib.singleValueMatrix(Sequence{ 3 }, 10) ; execute (y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np x = np.ones([2,3]) y = x.shape print(y[0]) x[:,0] = x[:,0] * 3 x[:,1] = x[:,1] + 5 print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : Sequence := MatrixLib.singleValueMatrix(Sequence{2}->union(Sequence{ 3 }), 1.0) ; var y : Sequence := MatrixLib.shape(x) ; execute (y->first())->display() ; x->collect( _r | _r->first() ) := MatrixLib.elementwiseMult(x->collect( _r | _r->first() ), 3) ; x->collect( _r | _r[1+1] ) := MatrixLib.elementwiseAdd(x->collect( _r | _r[1+1] ), 5) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np x = np.ones([2,3]) x[:,0] = x[:,0] * 3e+10 x[:,1] = x[:,1] * 5 x[:,2] = np.sqrt(x[:,1]) print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : Sequence := MatrixLib.singleValueMatrix(Sequence{2}->union(Sequence{ 3 }), 1.0) ; x->collect( _r | _r->first() ) := MatrixLib.elementwiseMult(x->collect( _r | _r->first() ), ("3e+10")->toReal()) ; x->collect( _r | _r[1+1] ) := MatrixLib.elementwiseMult(x->collect( _r | _r[1+1] ), 5) ; x->collect( _r | _r[2+1] ) := MatrixLib.elementwiseApply(x->collect( _r | _r[1+1] ), lambda x : double in (x->sqrt())) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np x = np.ones([2,3]) x[:,0] = 3 x[1,:] = 5 print(x) y = np.transpose(x) print(y) z = x * x print(z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : Sequence := MatrixLib.singleValueMatrix(Sequence{2}->union(Sequence{ 3 }), 1.0) ; x->collect( _r | _r->first() ) := 3 ; x[1+1] := 5 ; execute (x)->display() ; var y : Sequence := MatrixLib.transpose(x) ; execute (y)->display() ; var z : Sequence := MatrixLib.dotProduct(x,x) ; execute (z)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np x = np.ones([3,3]) x[:,0] = 3 x[1,:] = 5 print(x) y = np.sum(x) print(y) z = np.prod(x) print(z) print(x < 5) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : Sequence := MatrixLib.singleValueMatrix(Sequence{3}->union(Sequence{ 3 }), 1.0) ; x->collect( _r | _r->first() ) := 3 ; x[1+1] := 5 ; execute (x)->display() ; var y : double := MatrixLib.sumMatrix(x) ; execute (y)->display() ; var z : double := MatrixLib.prdMatrix(x) ; execute (z)->display() ; execute (MatrixLib.elementwiseLess(x,5))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d3 = collections.OrderedDict({"a":1, "b":2, "c":3}) d3["b"] = 4 d3["d"] = 4 print(d3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d3 : Map := (Map{ "a" |-> 1 }->union(Map{ "b" |-> 2 }->union(Map{ "c" |-> 3 }))) ; d3->at("b") := 4 ; d3->at("d") := 4 ; execute (d3)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = "text" lst = ['a', 'b', 'c'] def oper(y,sq) : y = y + 'x' sq[1] = 'd' print(x) print(lst) print("") oper(x,lst) print(x) # not changed print(lst) # changed ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := "text" ; var lst : Sequence := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{ 'c' })) ; skip ; execute (x)->display() ; execute (lst)->display() ; execute ("")->display() ; oper(x, lst) ; execute (x)->display() ; execute (lst)->display(); operation oper(y : OclAny, sq : OclAny) pre: true post: true activity: y := y + 'x' ; sq[1+1] := 'd'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- st = set({'a', 'b', 'c'}) def oper(stx) : stx.add('d') stx.update(set({'e', 'f'})) stx.difference_update(set({'a', 'b'})) stx.discard('c') print(st) print("") oper(st) print(st) # changed ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var st : Set := Set{}->union((Set{'a'}->union(Set{'b'}->union(Set{ 'c' })))) ; skip ; execute (st)->display() ; execute ("")->display() ; oper(st) ; execute (st)->display(); operation oper(stx : OclAny) pre: true post: true activity: execute (('d') : stx) ; execute ((Set{}->union((Set{'e'}->union(Set{ 'f' })))) <: stx) ; execute ((Set{}->union((Set{'a'}->union(Set{ 'b' })))) /<: stx) ; execute (('c') /: stx); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = 100 lst = ['a', 'b', 'c'] class Person : def __init__(self) : self.name = "" self.age = 45 p = Person() def oper(y,sq,per) : y = y + 10 sq.append('d') per.name = "Alex" per.age = per.age + 1 print(x) print(lst) print(p.name) print(p.age) print("") oper(x,lst,p) print(x) # not changed print(lst) # changed print(p.name) # changed print(p.age) # changed ------------------------------------------------------------ OCL File: --------- class Person { static operation newPerson() : Person pre: true post: Person->exists( _x | result = _x ); attribute name : String := ""; attribute age : int := 45; operation initialise() : Person pre: true post: true activity: self.name := "" ; self.age := 45; return self; } class FromPython { operation initialise() pre: true post: true activity: var x : int := 100 ; var lst : Sequence := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{ 'c' })) ; skip ; var p : Person := (Person.newPerson()).initialise() ; skip ; execute (x)->display() ; execute (lst)->display() ; execute (p.name)->display() ; execute (p.age)->display() ; execute ("")->display() ; oper(x, lst, p) ; execute (x)->display() ; execute (lst)->display() ; execute (p.name)->display() ; execute (p.age)->display(); operation oper(y : OclAny, sq : OclAny, per : OclAny) pre: true post: true activity: y := y + 10 ; execute (('d') : sq) ; per.name := "Alex" ; per.age := per.age + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lst = ["a", "b", "c"] pickle.dump(lst,f) rst = pickle.load(f) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lst : Sequence := Sequence{"a"}->union(Sequence{"b"}->union(Sequence{ "c" })) ; f.writeObject(lst) ; var rst : OclAny := (f).readObject(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from datetime import * today = datetime.today() print(hasattr(today,'year')) print(hasattr(today,'weekday')) print(getattr(today,'hour')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var today : OclDate := OclDate.newOclDate() ; execute (OclType.hasAttribute(today, 'year'))->display() ; execute (OclType.hasAttribute(today, 'weekday'))->display() ; execute (OclType.getAttributeValue(today, 'hour'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = "Person" print(x + " name") print x ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := "Person" ; execute (x + " name")->display() ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import random rr = random.Random() x = rr.gauss(0.0,1.0) y = rr.uniform(5.0,10.0) z = rr.randrange(10) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var rr : OclRandom := OclRandom.newOclRandom() ; var x : double := rr.nextNormal(0.0, (1.0)->sqr()) ; var y : double := rr.nextUniform(5.0, 10.0) ; var z : int := rr.nextInt(10); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = random.random() sq = [1,2,3,4,5,6] dices = random.sample(sq,2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : double := (OclRandom.defaultInstanceOclRandom()).nextDouble() ; var sq : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))))) ; var dices : Sequence := OclRandom.randomUniqueElements(sq, 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s1 = range(5) s2 = range(1,5) s3 = range(1,14,4) chars = ['A', 'B', 'C'] rs = enumerate(chars) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s1 : Sequence := Integer.subrange(0, 5-1) ; var s2 : Sequence := Integer.subrange(1, 5-1) ; var s3 : Sequence := Integer.subrange(1, 14-1)->select( $x | ($x - 1) mod 4 = 0 ) ; var chars : Sequence := Sequence{'A'}->union(Sequence{'B'}->union(Sequence{ 'C' })) ; var rs : Sequence := Integer.subrange(1, (chars)->size())->collect( _indx | Sequence{_indx-1, (chars)->at(_indx)} ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(r"\b\f\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (StringLib.rawString("\b\f\n"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- b = re.fullmatch("[a-z]*", "test") ss = re.sub("e", "x", "testes") lst = re.findall("[a-z]*", "a long string") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var b : String := ("test")->firstMatch("^" + "[a-z]*" + "$") ; var ss : String := ("testes").replaceAllMatches("e", "x") ; var lst : Sequence(String) := ("a long string")->allMatches("[a-z]*"); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sq = list(["aa", "bbb", "cc", "dd", "eeee"]) sq1 = reversed(sq) y = max(sq) z = min(sq) sq2 = sorted(sq1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sq : Sequence := (Sequence{"aa"}->union(Sequence{"bbb"}->union(Sequence{"cc"}->union(Sequence{"dd"}->union(Sequence{ "eeee" }))))) ; var sq1 : Sequence := (sq)->reverse() ; var y : OclAny := (sq)->max() ; var z : OclAny := (sq)->min() ; var sq2 : Sequence := sq1->sort(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ss = [3,4,5,6,7] res = [x*x for x in ss if x % 2 == 1 if x > 3] print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ss : Sequence := Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 7 })))) ; var res : Sequence := ss->select(x | x mod 2 = 1 & x > 3)->collect(x | (x * x)) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ss = [3,4,5,6,7] res = [x*x for x in ss if x % 2 == 1] print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ss : Sequence := Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 7 })))) ; var res : Sequence := ss->select(x | x mod 2 = 1)->collect(x | (x * x)) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = [1,2] print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : Sequence := Sequence{1}->union(Sequence{ 2 }) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print("x = 0.0") print("y = 0.0") print("m = 0.0") print("x0 = 0.0") print("x = 1") print("y = 1") print("x0 = 10") print("m = 1") for i in range(1,160) : print("m = m*(x0/" + str(i) + ")") print("y = y + m") print("print(y)") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ("x = 0.0")->display() ; execute ("y = 0.0")->display() ; execute ("m = 0.0")->display() ; execute ("x0 = 0.0")->display() ; execute ("x = 1")->display() ; execute ("y = 1")->display() ; execute ("x0 = 10")->display() ; execute ("m = 1")->display() ; for i : Integer.subrange(1, 160-1) do ( execute ("m = m*(x0/" + ("" + ((i))) + ")")->display() ; execute ("y = y + m")->display() ; execute ("print(y)")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = 0.0 y = 0.0 m = 0.0 x0 = 0.0 x = 1 y = 1 x0 = 10 m = 1 m = m*(x0/1) y = y + m print(y) m = m*(x0/2) y = y + m print(y) m = m*(x0/3) y = y + m print(y) m = m*(x0/4) y = y + m print(y) m = m*(x0/5) y = y + m print(y) m = m*(x0/6) y = y + m print(y) m = m*(x0/7) y = y + m print(y) m = m*(x0/8) y = y + m print(y) m = m*(x0/9) y = y + m print(y) m = m*(x0/10) y = y + m print(y) m = m*(x0/11) y = y + m print(y) m = m*(x0/12) y = y + m print(y) m = m*(x0/13) y = y + m print(y) m = m*(x0/14) y = y + m print(y) m = m*(x0/15) y = y + m print(y) m = m*(x0/16) y = y + m print(y) m = m*(x0/17) y = y + m print(y) m = m*(x0/18) y = y + m print(y) m = m*(x0/19) y = y + m print(y) m = m*(x0/20) y = y + m print(y) m = m*(x0/21) y = y + m print(y) m = m*(x0/22) y = y + m print(y) m = m*(x0/23) y = y + m print(y) m = m*(x0/24) y = y + m print(y) m = m*(x0/25) y = y + m print(y) m = m*(x0/26) y = y + m print(y) m = m*(x0/27) y = y + m print(y) m = m*(x0/28) y = y + m print(y) m = m*(x0/29) y = y + m print(y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : double := 0.0 ; var y : double := 0.0 ; var m : double := 0.0 ; var x0 : double := 0.0 ; x := 1 ; y := 1 ; x0 := 10 ; m := 1 ; m := m * (x0 / 1) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 2) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 3) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 4) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 5) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 6) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 7) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 8) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 9) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 10) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 11) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 12) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 13) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 14) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 15) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 16) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 17) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 18) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 19) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 20) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 21) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 22) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 23) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 24) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 25) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 26) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 27) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 28) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 29) ; y := y + m ; execute (y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = 0.0 y = 0.0 m = 0.0 x0 = 0.0 x = 1 y = 1 x0 = 10 m = 1 m = m*(x0/1) y = y + m print(y) m = m*(x0/2) y = y + m print(y) m = m*(x0/3) y = y + m print(y) m = m*(x0/4) y = y + m print(y) m = m*(x0/5) y = y + m print(y) m = m*(x0/6) y = y + m print(y) m = m*(x0/7) y = y + m print(y) m = m*(x0/8) y = y + m print(y) m = m*(x0/9) y = y + m print(y) m = m*(x0/10) y = y + m print(y) m = m*(x0/11) y = y + m print(y) m = m*(x0/12) y = y + m print(y) m = m*(x0/13) y = y + m print(y) m = m*(x0/14) y = y + m print(y) m = m*(x0/15) y = y + m print(y) m = m*(x0/16) y = y + m print(y) m = m*(x0/17) y = y + m print(y) m = m*(x0/18) y = y + m print(y) m = m*(x0/19) y = y + m print(y) m = m*(x0/20) y = y + m print(y) m = m*(x0/21) y = y + m print(y) m = m*(x0/22) y = y + m print(y) m = m*(x0/23) y = y + m print(y) m = m*(x0/24) y = y + m print(y) m = m*(x0/25) y = y + m print(y) m = m*(x0/26) y = y + m print(y) m = m*(x0/27) y = y + m print(y) m = m*(x0/28) y = y + m print(y) m = m*(x0/29) y = y + m print(y) m = m*(x0/30) y = y + m print(y) m = m*(x0/31) y = y + m print(y) m = m*(x0/32) y = y + m print(y) m = m*(x0/33) y = y + m print(y) m = m*(x0/34) y = y + m print(y) m = m*(x0/35) y = y + m print(y) m = m*(x0/36) y = y + m print(y) m = m*(x0/37) y = y + m print(y) m = m*(x0/38) y = y + m print(y) m = m*(x0/39) y = y + m print(y) m = m*(x0/40) y = y + m print(y) m = m*(x0/41) y = y + m print(y) m = m*(x0/42) y = y + m print(y) m = m*(x0/43) y = y + m print(y) m = m*(x0/44) y = y + m print(y) m = m*(x0/45) y = y + m print(y) m = m*(x0/46) y = y + m print(y) m = m*(x0/47) y = y + m print(y) m = m*(x0/48) y = y + m print(y) m = m*(x0/49) y = y + m print(y) m = m*(x0/50) y = y + m print(y) m = m*(x0/51) y = y + m print(y) m = m*(x0/52) y = y + m print(y) m = m*(x0/53) y = y + m print(y) m = m*(x0/54) y = y + m print(y) m = m*(x0/55) y = y + m print(y) m = m*(x0/56) y = y + m print(y) m = m*(x0/57) y = y + m print(y) m = m*(x0/58) y = y + m print(y) m = m*(x0/59) y = y + m print(y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : double := 0.0 ; var y : double := 0.0 ; var m : double := 0.0 ; var x0 : double := 0.0 ; x := 1 ; y := 1 ; x0 := 10 ; m := 1 ; m := m * (x0 / 1) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 2) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 3) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 4) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 5) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 6) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 7) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 8) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 9) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 10) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 11) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 12) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 13) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 14) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 15) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 16) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 17) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 18) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 19) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 20) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 21) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 22) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 23) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 24) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 25) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 26) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 27) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 28) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 29) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 30) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 31) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 32) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 33) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 34) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 35) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 36) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 37) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 38) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 39) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 40) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 41) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 42) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 43) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 44) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 45) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 46) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 47) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 48) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 49) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 50) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 51) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 52) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 53) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 54) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 55) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 56) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 57) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 58) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 59) ; y := y + m ; execute (y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = 0.0 y = 0.0 m = 0.0 x0 = 0.0 x = 1 y = 1 x0 = 10 m = 1 m = m*(x0/1) y = y + m print(y) m = m*(x0/2) y = y + m print(y) m = m*(x0/3) y = y + m print(y) m = m*(x0/4) y = y + m print(y) m = m*(x0/5) y = y + m print(y) m = m*(x0/6) y = y + m print(y) m = m*(x0/7) y = y + m print(y) m = m*(x0/8) y = y + m print(y) m = m*(x0/9) y = y + m print(y) m = m*(x0/10) y = y + m print(y) m = m*(x0/11) y = y + m print(y) m = m*(x0/12) y = y + m print(y) m = m*(x0/13) y = y + m print(y) m = m*(x0/14) y = y + m print(y) m = m*(x0/15) y = y + m print(y) m = m*(x0/16) y = y + m print(y) m = m*(x0/17) y = y + m print(y) m = m*(x0/18) y = y + m print(y) m = m*(x0/19) y = y + m print(y) m = m*(x0/20) y = y + m print(y) m = m*(x0/21) y = y + m print(y) m = m*(x0/22) y = y + m print(y) m = m*(x0/23) y = y + m print(y) m = m*(x0/24) y = y + m print(y) m = m*(x0/25) y = y + m print(y) m = m*(x0/26) y = y + m print(y) m = m*(x0/27) y = y + m print(y) m = m*(x0/28) y = y + m print(y) m = m*(x0/29) y = y + m print(y) m = m*(x0/30) y = y + m print(y) m = m*(x0/31) y = y + m print(y) m = m*(x0/32) y = y + m print(y) m = m*(x0/33) y = y + m print(y) m = m*(x0/34) y = y + m print(y) m = m*(x0/35) y = y + m print(y) m = m*(x0/36) y = y + m print(y) m = m*(x0/37) y = y + m print(y) m = m*(x0/38) y = y + m print(y) m = m*(x0/39) y = y + m print(y) m = m*(x0/40) y = y + m print(y) m = m*(x0/41) y = y + m print(y) m = m*(x0/42) y = y + m print(y) m = m*(x0/43) y = y + m print(y) m = m*(x0/44) y = y + m print(y) m = m*(x0/45) y = y + m print(y) m = m*(x0/46) y = y + m print(y) m = m*(x0/47) y = y + m print(y) m = m*(x0/48) y = y + m print(y) m = m*(x0/49) y = y + m print(y) m = m*(x0/50) y = y + m print(y) m = m*(x0/51) y = y + m print(y) m = m*(x0/52) y = y + m print(y) m = m*(x0/53) y = y + m print(y) m = m*(x0/54) y = y + m print(y) m = m*(x0/55) y = y + m print(y) m = m*(x0/56) y = y + m print(y) m = m*(x0/57) y = y + m print(y) m = m*(x0/58) y = y + m print(y) m = m*(x0/59) y = y + m print(y) m = m*(x0/60) y = y + m print(y) m = m*(x0/61) y = y + m print(y) m = m*(x0/62) y = y + m print(y) m = m*(x0/63) y = y + m print(y) m = m*(x0/64) y = y + m print(y) m = m*(x0/65) y = y + m print(y) m = m*(x0/66) y = y + m print(y) m = m*(x0/67) y = y + m print(y) m = m*(x0/68) y = y + m print(y) m = m*(x0/69) y = y + m print(y) m = m*(x0/70) y = y + m print(y) m = m*(x0/71) y = y + m print(y) m = m*(x0/72) y = y + m print(y) m = m*(x0/73) y = y + m print(y) m = m*(x0/74) y = y + m print(y) m = m*(x0/75) y = y + m print(y) m = m*(x0/76) y = y + m print(y) m = m*(x0/77) y = y + m print(y) m = m*(x0/78) y = y + m print(y) m = m*(x0/79) y = y + m print(y) m = m*(x0/80) y = y + m print(y) m = m*(x0/81) y = y + m print(y) m = m*(x0/82) y = y + m print(y) m = m*(x0/83) y = y + m print(y) m = m*(x0/84) y = y + m print(y) m = m*(x0/85) y = y + m print(y) m = m*(x0/86) y = y + m print(y) m = m*(x0/87) y = y + m print(y) m = m*(x0/88) y = y + m print(y) m = m*(x0/89) y = y + m print(y) m = m*(x0/90) y = y + m print(y) m = m*(x0/91) y = y + m print(y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : double := 0.0 ; var y : double := 0.0 ; var m : double := 0.0 ; var x0 : double := 0.0 ; x := 1 ; y := 1 ; x0 := 10 ; m := 1 ; m := m * (x0 / 1) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 2) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 3) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 4) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 5) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 6) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 7) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 8) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 9) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 10) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 11) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 12) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 13) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 14) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 15) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 16) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 17) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 18) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 19) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 20) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 21) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 22) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 23) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 24) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 25) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 26) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 27) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 28) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 29) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 30) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 31) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 32) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 33) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 34) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 35) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 36) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 37) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 38) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 39) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 40) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 41) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 42) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 43) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 44) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 45) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 46) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 47) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 48) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 49) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 50) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 51) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 52) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 53) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 54) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 55) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 56) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 57) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 58) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 59) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 60) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 61) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 62) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 63) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 64) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 65) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 66) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 67) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 68) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 69) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 70) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 71) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 72) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 73) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 74) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 75) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 76) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 77) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 78) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 79) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 80) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 81) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 82) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 83) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 84) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 85) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 86) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 87) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 88) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 89) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 90) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 91) ; y := y + m ; execute (y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = 0.0 y = 0.0 m = 0.0 x0 = 0.0 x = 1 y = 1 x0 = 10 m = 1 m = m*(x0/1) y = y + m print(y) m = m*(x0/2) y = y + m print(y) m = m*(x0/3) y = y + m print(y) m = m*(x0/4) y = y + m print(y) m = m*(x0/5) y = y + m print(y) m = m*(x0/6) y = y + m print(y) m = m*(x0/7) y = y + m print(y) m = m*(x0/8) y = y + m print(y) m = m*(x0/9) y = y + m print(y) m = m*(x0/10) y = y + m print(y) m = m*(x0/11) y = y + m print(y) m = m*(x0/12) y = y + m print(y) m = m*(x0/13) y = y + m print(y) m = m*(x0/14) y = y + m print(y) m = m*(x0/15) y = y + m print(y) m = m*(x0/16) y = y + m print(y) m = m*(x0/17) y = y + m print(y) m = m*(x0/18) y = y + m print(y) m = m*(x0/19) y = y + m print(y) m = m*(x0/20) y = y + m print(y) m = m*(x0/21) y = y + m print(y) m = m*(x0/22) y = y + m print(y) m = m*(x0/23) y = y + m print(y) m = m*(x0/24) y = y + m print(y) m = m*(x0/25) y = y + m print(y) m = m*(x0/26) y = y + m print(y) m = m*(x0/27) y = y + m print(y) m = m*(x0/28) y = y + m print(y) m = m*(x0/29) y = y + m print(y) m = m*(x0/30) y = y + m print(y) m = m*(x0/31) y = y + m print(y) m = m*(x0/32) y = y + m print(y) m = m*(x0/33) y = y + m print(y) m = m*(x0/34) y = y + m print(y) m = m*(x0/35) y = y + m print(y) m = m*(x0/36) y = y + m print(y) m = m*(x0/37) y = y + m print(y) m = m*(x0/38) y = y + m print(y) m = m*(x0/39) y = y + m print(y) m = m*(x0/40) y = y + m print(y) m = m*(x0/41) y = y + m print(y) m = m*(x0/42) y = y + m print(y) m = m*(x0/43) y = y + m print(y) m = m*(x0/44) y = y + m print(y) m = m*(x0/45) y = y + m print(y) m = m*(x0/46) y = y + m print(y) m = m*(x0/47) y = y + m print(y) m = m*(x0/48) y = y + m print(y) m = m*(x0/49) y = y + m print(y) m = m*(x0/50) y = y + m print(y) m = m*(x0/51) y = y + m print(y) m = m*(x0/52) y = y + m print(y) m = m*(x0/53) y = y + m print(y) m = m*(x0/54) y = y + m print(y) m = m*(x0/55) y = y + m print(y) m = m*(x0/56) y = y + m print(y) m = m*(x0/57) y = y + m print(y) m = m*(x0/58) y = y + m print(y) m = m*(x0/59) y = y + m print(y) m = m*(x0/60) y = y + m print(y) m = m*(x0/61) y = y + m print(y) m = m*(x0/62) y = y + m print(y) m = m*(x0/63) y = y + m print(y) m = m*(x0/64) y = y + m print(y) m = m*(x0/65) y = y + m print(y) m = m*(x0/66) y = y + m print(y) m = m*(x0/67) y = y + m print(y) m = m*(x0/68) y = y + m print(y) m = m*(x0/69) y = y + m print(y) m = m*(x0/70) y = y + m print(y) m = m*(x0/71) y = y + m print(y) m = m*(x0/72) y = y + m print(y) m = m*(x0/73) y = y + m print(y) m = m*(x0/74) y = y + m print(y) m = m*(x0/75) y = y + m print(y) m = m*(x0/76) y = y + m print(y) m = m*(x0/77) y = y + m print(y) m = m*(x0/78) y = y + m print(y) m = m*(x0/79) y = y + m print(y) m = m*(x0/80) y = y + m print(y) m = m*(x0/81) y = y + m print(y) m = m*(x0/82) y = y + m print(y) m = m*(x0/83) y = y + m print(y) m = m*(x0/84) y = y + m print(y) m = m*(x0/85) y = y + m print(y) m = m*(x0/86) y = y + m print(y) m = m*(x0/87) y = y + m print(y) m = m*(x0/88) y = y + m print(y) m = m*(x0/89) y = y + m print(y) m = m*(x0/90) y = y + m print(y) m = m*(x0/91) y = y + m print(y) m = m*(x0/92) y = y + m print(y) m = m*(x0/93) y = y + m print(y) m = m*(x0/94) y = y + m print(y) m = m*(x0/95) y = y + m print(y) m = m*(x0/96) y = y + m print(y) m = m*(x0/97) y = y + m print(y) m = m*(x0/98) y = y + m print(y) m = m*(x0/99) y = y + m print(y) m = m*(x0/100) y = y + m print(y) m = m*(x0/101) y = y + m print(y) m = m*(x0/102) y = y + m print(y) m = m*(x0/103) y = y + m print(y) m = m*(x0/104) y = y + m print(y) m = m*(x0/105) y = y + m print(y) m = m*(x0/106) y = y + m print(y) m = m*(x0/107) y = y + m print(y) m = m*(x0/108) y = y + m print(y) m = m*(x0/109) y = y + m print(y) m = m*(x0/110) y = y + m print(y) m = m*(x0/111) y = y + m print(y) m = m*(x0/112) y = y + m print(y) m = m*(x0/113) y = y + m print(y) m = m*(x0/114) y = y + m print(y) m = m*(x0/115) y = y + m print(y) m = m*(x0/116) y = y + m print(y) m = m*(x0/117) y = y + m print(y) m = m*(x0/118) y = y + m print(y) m = m*(x0/119) y = y + m print(y) m = m*(x0/120) y = y + m print(y) m = m*(x0/121) y = y + m print(y) m = m*(x0/122) y = y + m print(y) m = m*(x0/123) y = y + m print(y) m = m*(x0/124) y = y + m print(y) m = m*(x0/125) y = y + m print(y) m = m*(x0/126) y = y + m print(y) m = m*(x0/127) y = y + m print(y) m = m*(x0/128) y = y + m print(y) m = m*(x0/129) y = y + m print(y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : double := 0.0 ; var y : double := 0.0 ; var m : double := 0.0 ; var x0 : double := 0.0 ; x := 1 ; y := 1 ; x0 := 10 ; m := 1 ; m := m * (x0 / 1) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 2) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 3) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 4) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 5) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 6) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 7) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 8) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 9) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 10) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 11) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 12) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 13) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 14) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 15) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 16) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 17) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 18) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 19) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 20) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 21) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 22) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 23) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 24) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 25) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 26) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 27) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 28) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 29) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 30) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 31) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 32) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 33) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 34) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 35) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 36) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 37) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 38) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 39) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 40) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 41) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 42) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 43) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 44) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 45) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 46) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 47) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 48) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 49) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 50) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 51) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 52) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 53) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 54) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 55) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 56) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 57) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 58) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 59) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 60) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 61) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 62) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 63) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 64) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 65) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 66) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 67) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 68) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 69) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 70) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 71) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 72) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 73) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 74) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 75) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 76) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 77) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 78) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 79) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 80) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 81) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 82) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 83) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 84) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 85) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 86) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 87) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 88) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 89) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 90) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 91) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 92) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 93) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 94) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 95) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 96) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 97) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 98) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 99) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 100) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 101) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 102) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 103) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 104) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 105) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 106) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 107) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 108) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 109) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 110) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 111) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 112) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 113) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 114) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 115) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 116) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 117) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 118) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 119) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 120) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 121) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 122) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 123) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 124) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 125) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 126) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 127) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 128) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 129) ; y := y + m ; execute (y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x = 0.0 y = 0.0 m = 0.0 x0 = 0.0 x = 1 y = 1 x0 = 10 m = 1 m = m*(x0/1) y = y + m print(y) m = m*(x0/2) y = y + m print(y) m = m*(x0/3) y = y + m print(y) m = m*(x0/4) y = y + m print(y) m = m*(x0/5) y = y + m print(y) m = m*(x0/6) y = y + m print(y) m = m*(x0/7) y = y + m print(y) m = m*(x0/8) y = y + m print(y) m = m*(x0/9) y = y + m print(y) m = m*(x0/10) y = y + m print(y) m = m*(x0/11) y = y + m print(y) m = m*(x0/12) y = y + m print(y) m = m*(x0/13) y = y + m print(y) m = m*(x0/14) y = y + m print(y) m = m*(x0/15) y = y + m print(y) m = m*(x0/16) y = y + m print(y) m = m*(x0/17) y = y + m print(y) m = m*(x0/18) y = y + m print(y) m = m*(x0/19) y = y + m print(y) m = m*(x0/20) y = y + m print(y) m = m*(x0/21) y = y + m print(y) m = m*(x0/22) y = y + m print(y) m = m*(x0/23) y = y + m print(y) m = m*(x0/24) y = y + m print(y) m = m*(x0/25) y = y + m print(y) m = m*(x0/26) y = y + m print(y) m = m*(x0/27) y = y + m print(y) m = m*(x0/28) y = y + m print(y) m = m*(x0/29) y = y + m print(y) m = m*(x0/30) y = y + m print(y) m = m*(x0/31) y = y + m print(y) m = m*(x0/32) y = y + m print(y) m = m*(x0/33) y = y + m print(y) m = m*(x0/34) y = y + m print(y) m = m*(x0/35) y = y + m print(y) m = m*(x0/36) y = y + m print(y) m = m*(x0/37) y = y + m print(y) m = m*(x0/38) y = y + m print(y) m = m*(x0/39) y = y + m print(y) m = m*(x0/40) y = y + m print(y) m = m*(x0/41) y = y + m print(y) m = m*(x0/42) y = y + m print(y) m = m*(x0/43) y = y + m print(y) m = m*(x0/44) y = y + m print(y) m = m*(x0/45) y = y + m print(y) m = m*(x0/46) y = y + m print(y) m = m*(x0/47) y = y + m print(y) m = m*(x0/48) y = y + m print(y) m = m*(x0/49) y = y + m print(y) m = m*(x0/50) y = y + m print(y) m = m*(x0/51) y = y + m print(y) m = m*(x0/52) y = y + m print(y) m = m*(x0/53) y = y + m print(y) m = m*(x0/54) y = y + m print(y) m = m*(x0/55) y = y + m print(y) m = m*(x0/56) y = y + m print(y) m = m*(x0/57) y = y + m print(y) m = m*(x0/58) y = y + m print(y) m = m*(x0/59) y = y + m print(y) m = m*(x0/60) y = y + m print(y) m = m*(x0/61) y = y + m print(y) m = m*(x0/62) y = y + m print(y) m = m*(x0/63) y = y + m print(y) m = m*(x0/64) y = y + m print(y) m = m*(x0/65) y = y + m print(y) m = m*(x0/66) y = y + m print(y) m = m*(x0/67) y = y + m print(y) m = m*(x0/68) y = y + m print(y) m = m*(x0/69) y = y + m print(y) m = m*(x0/70) y = y + m print(y) m = m*(x0/71) y = y + m print(y) m = m*(x0/72) y = y + m print(y) m = m*(x0/73) y = y + m print(y) m = m*(x0/74) y = y + m print(y) m = m*(x0/75) y = y + m print(y) m = m*(x0/76) y = y + m print(y) m = m*(x0/77) y = y + m print(y) m = m*(x0/78) y = y + m print(y) m = m*(x0/79) y = y + m print(y) m = m*(x0/80) y = y + m print(y) m = m*(x0/81) y = y + m print(y) m = m*(x0/82) y = y + m print(y) m = m*(x0/83) y = y + m print(y) m = m*(x0/84) y = y + m print(y) m = m*(x0/85) y = y + m print(y) m = m*(x0/86) y = y + m print(y) m = m*(x0/87) y = y + m print(y) m = m*(x0/88) y = y + m print(y) m = m*(x0/89) y = y + m print(y) m = m*(x0/90) y = y + m print(y) m = m*(x0/91) y = y + m print(y) m = m*(x0/92) y = y + m print(y) m = m*(x0/93) y = y + m print(y) m = m*(x0/94) y = y + m print(y) m = m*(x0/95) y = y + m print(y) m = m*(x0/96) y = y + m print(y) m = m*(x0/97) y = y + m print(y) m = m*(x0/98) y = y + m print(y) m = m*(x0/99) y = y + m print(y) m = m*(x0/100) y = y + m print(y) m = m*(x0/101) y = y + m print(y) m = m*(x0/102) y = y + m print(y) m = m*(x0/103) y = y + m print(y) m = m*(x0/104) y = y + m print(y) m = m*(x0/105) y = y + m print(y) m = m*(x0/106) y = y + m print(y) m = m*(x0/107) y = y + m print(y) m = m*(x0/108) y = y + m print(y) m = m*(x0/109) y = y + m print(y) m = m*(x0/110) y = y + m print(y) m = m*(x0/111) y = y + m print(y) m = m*(x0/112) y = y + m print(y) m = m*(x0/113) y = y + m print(y) m = m*(x0/114) y = y + m print(y) m = m*(x0/115) y = y + m print(y) m = m*(x0/116) y = y + m print(y) m = m*(x0/117) y = y + m print(y) m = m*(x0/118) y = y + m print(y) m = m*(x0/119) y = y + m print(y) m = m*(x0/120) y = y + m print(y) m = m*(x0/121) y = y + m print(y) m = m*(x0/122) y = y + m print(y) m = m*(x0/123) y = y + m print(y) m = m*(x0/124) y = y + m print(y) m = m*(x0/125) y = y + m print(y) m = m*(x0/126) y = y + m print(y) m = m*(x0/127) y = y + m print(y) m = m*(x0/128) y = y + m print(y) m = m*(x0/129) y = y + m print(y) m = m*(x0/130) y = y + m print(y) m = m*(x0/131) y = y + m print(y) m = m*(x0/132) y = y + m print(y) m = m*(x0/133) y = y + m print(y) m = m*(x0/134) y = y + m print(y) m = m*(x0/135) y = y + m print(y) m = m*(x0/136) y = y + m print(y) m = m*(x0/137) y = y + m print(y) m = m*(x0/138) y = y + m print(y) m = m*(x0/139) y = y + m print(y) m = m*(x0/140) y = y + m print(y) m = m*(x0/141) y = y + m print(y) m = m*(x0/142) y = y + m print(y) m = m*(x0/143) y = y + m print(y) m = m*(x0/144) y = y + m print(y) m = m*(x0/145) y = y + m print(y) m = m*(x0/146) y = y + m print(y) m = m*(x0/147) y = y + m print(y) m = m*(x0/148) y = y + m print(y) m = m*(x0/149) y = y + m print(y) m = m*(x0/150) y = y + m print(y) m = m*(x0/151) y = y + m print(y) m = m*(x0/152) y = y + m print(y) m = m*(x0/153) y = y + m print(y) m = m*(x0/154) y = y + m print(y) m = m*(x0/155) y = y + m print(y) m = m*(x0/156) y = y + m print(y) m = m*(x0/157) y = y + m print(y) m = m*(x0/158) y = y + m print(y) m = m*(x0/159) y = y + m print(y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : double := 0.0 ; var y : double := 0.0 ; var m : double := 0.0 ; var x0 : double := 0.0 ; x := 1 ; y := 1 ; x0 := 10 ; m := 1 ; m := m * (x0 / 1) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 2) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 3) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 4) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 5) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 6) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 7) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 8) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 9) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 10) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 11) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 12) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 13) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 14) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 15) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 16) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 17) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 18) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 19) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 20) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 21) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 22) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 23) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 24) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 25) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 26) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 27) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 28) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 29) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 30) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 31) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 32) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 33) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 34) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 35) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 36) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 37) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 38) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 39) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 40) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 41) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 42) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 43) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 44) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 45) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 46) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 47) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 48) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 49) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 50) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 51) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 52) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 53) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 54) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 55) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 56) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 57) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 58) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 59) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 60) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 61) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 62) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 63) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 64) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 65) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 66) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 67) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 68) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 69) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 70) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 71) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 72) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 73) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 74) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 75) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 76) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 77) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 78) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 79) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 80) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 81) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 82) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 83) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 84) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 85) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 86) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 87) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 88) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 89) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 90) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 91) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 92) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 93) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 94) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 95) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 96) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 97) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 98) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 99) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 100) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 101) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 102) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 103) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 104) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 105) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 106) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 107) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 108) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 109) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 110) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 111) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 112) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 113) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 114) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 115) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 116) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 117) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 118) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 119) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 120) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 121) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 122) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 123) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 124) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 125) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 126) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 127) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 128) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 129) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 130) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 131) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 132) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 133) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 134) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 135) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 136) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 137) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 138) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 139) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 140) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 141) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 142) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 143) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 144) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 145) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 146) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 147) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 148) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 149) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 150) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 151) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 152) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 153) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 154) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 155) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 156) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 157) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 158) ; y := y + m ; execute (y)->display() ; m := m * (x0 / 159) ; y := y + m ; execute (y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # 1. x if x < y else y x = 5 y = 10 if x < y: min_value = x else: min_value = y print(f"Minimum value between {x} and {y}: {min_value}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 5 ; var y : int := 10 ; if (x->compareTo(y)) < 0 then ( var min_value : int := x ) else ( min_value := y ) ; execute (StringLib.formattedString("Minimum value between {x} and {y}: {min_value}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables z = 5 w = 5 # 1. z == w if z == w: print(f"z equals w: {z} == {w}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var z : int := 5 ; var w : int := 5 ; if z = w then ( execute (StringLib.formattedString("z equals w: {z} == {w}"))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables ss = ['apple', 'banana', 'cherry', 'banana'] pp = {1, 2, 3, 7} # 10. ss.issubset(pp) is_subset = set(ss).issubset(pp) # Converting ss to set since ss is a list print(f"Is ss a subset of pp? {is_subset}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ss : Sequence := Sequence{'apple'}->union(Sequence{'banana'}->union(Sequence{'cherry'}->union(Sequence{ 'banana' }))) ; var pp : Set := Set{1}->union(Set{2}->union(Set{3}->union(Set{ 7 }))) ; var is_subset : OclAny := Set{}->union((ss)) <: (pp) ; execute (StringLib.formattedString("Is ss a subset of pp? {is_subset}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables ss = ['apple', 'banana', 'cherry', 'banana'] qq = {2, 3, 5} # 11. ss.issuperset(qq) is_superset = set(ss).issuperset(qq) print(f"Is ss a superset of qq? {is_superset}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ss : Sequence := Sequence{'apple'}->union(Sequence{'banana'}->union(Sequence{'cherry'}->union(Sequence{ 'banana' }))) ; var qq : Set := Set{2}->union(Set{3}->union(Set{ 5 })) ; var is_superset : OclAny := Set{}->union((ss))->includesAll(qq) ; execute (StringLib.formattedString("Is ss a superset of qq? {is_superset}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables pp = {1, 2, 3, 7} qq = {2, 3, 5} # 12. pp.symmetric_difference(qq) symmetric_difference_pp_qq = pp.symmetric_difference(qq) print(f"Symmetric difference of pp and qq: {symmetric_difference_pp_qq}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var pp : Set := Set{1}->union(Set{2}->union(Set{3}->union(Set{ 7 }))) ; var qq : Set := Set{2}->union(Set{3}->union(Set{ 5 })) ; var symmetric_difference_pp_qq : OclAny := pp->symmetricDifference(qq) ; execute (StringLib.formattedString("Symmetric difference of pp and qq: {symmetric_difference_pp_qq}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables sx = {1, 2, 3} # 13. p.remove(x) (Demonstrates removing an element from a set; we will use set 'sx' here) sx.remove(1) print(f"Set sx after removing 1: {sx}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sx : Set := Set{1}->union(Set{2}->union(Set{ 3 })) ; execute ((1) /: sx) ; execute (StringLib.formattedString("Set sx after removing 1: {sx}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables qx = {3, 4, 5, 6} # 14. q.discard(y) (Demonstrates discarding an element from a set; we will use set 'qx' here) qx.discard(5) print(f"Set qx after discarding 5: {qx}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var qx : Set := Set{3}->union(Set{4}->union(Set{5}->union(Set{ 6 }))) ; execute ((5) /: qx) ; execute (StringLib.formattedString("Set qx after discarding 5: {qx}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables d = {'key1': 'value1', 'key2': 'value2'} # 15. d.items() (Retrieves items from a dictionary as (key, value) pairs) dict_items = d.items() print(f"Items in dictionary d: {dict_items}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : Map := Map{ 'key1' |-> 'value1' }->union(Map{ 'key2' |-> 'value2' }) ; var dict_items : Sequence := d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) ; execute (StringLib.formattedString("Items in dictionary d: {dict_items}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables s = "Hello World" # 1. s.upper() upper_s = s.upper() print(f"s.upper(): {upper_s}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := "Hello World" ; var upper_s : String := s->toUpperCase() ; execute (StringLib.formattedString("s.upper(): {upper_s}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables s = "Hello World" # 2. s.lower() lower_s = s.lower() print(f"s.lower(): {lower_s}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := "Hello World" ; var lower_s : String := s->toLowerCase() ; execute (StringLib.formattedString("s.lower(): {lower_s}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables p = " Trim me " # 3. p.strip() stripped_p = p.strip() print(f"p.strip(): {stripped_p}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : String := " Trim me " ; var stripped_p : String := p->trim() ; execute (StringLib.formattedString("p.strip(): {stripped_p}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables ss = "hello world" x = "world" y = "Python" # 4. ss.replace(x, y) replaced_ss = ss.replace(x, y) print(f"ss.replace(x, y): {replaced_ss}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ss : String := "hello world" ; var x : String := "world" ; var y : String := "Python" ; var replaced_ss : String := ss.replace(x, y) ; execute (StringLib.formattedString("ss.replace(x, y): {replaced_ss}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables r = 3 s = 4 # 2. r != s (Note: '<>' is not supported in Python 3, so use '!=' instead) if r != s: print(f"r is not equal to s: {r} != {s}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : int := 3 ; var s : int := 4 ; if r /= s then ( execute (StringLib.formattedString("r is not equal to s: {r} != {s}"))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables ss = "hello world" x = "world" # 5. ss.find(x) find_x = ss.find(x) print(f"ss.find(x): {find_x}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ss : String := "hello world" ; var x : String := "world" ; var find_x : int := ss->indexOf(x) - 1 ; execute (StringLib.formattedString("ss.find(x): {find_x}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables ss = "hello world" sx = "Hello" # 6. ss.startswith(sx) starts_with_sx = ss.startswith(sx) print(f"ss.startswith(sx): {starts_with_sx}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ss : String := "hello world" ; var sx : String := "Hello" ; var starts_with_sx : boolean := ss->hasPrefix(sx) ; execute (StringLib.formattedString("ss.startswith(sx): {starts_with_sx}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables ss = "hello world" sf = "world" # 7. ss.endswith(sf) ends_with_sf = ss.endswith(sf) print(f"ss.endswith(sf): {ends_with_sf}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ss : String := "hello world" ; var sf : String := "world" ; var ends_with_sf : boolean := ss->hasSuffix(sf) ; execute (StringLib.formattedString("ss.endswith(sf): {ends_with_sf}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables txt = "12345" # 8. txt.isalpha() is_alpha_txt = txt.isalpha() print(f"txt.isalpha(): {is_alpha_txt}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var txt : String := "12345" ; var is_alpha_txt : boolean := txt->matches("[a-zA-Z]*") ; execute (StringLib.formattedString("txt.isalpha(): {is_alpha_txt}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables txt = "12345" # 9. txt.isnumeric() is_numeric_txt = txt.isnumeric() print(f"txt.isnumeric(): {is_numeric_txt}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var txt : String := "12345" ; var is_numeric_txt : boolean := txt->matches("[0-9]*") ; execute (StringLib.formattedString("txt.isnumeric(): {is_numeric_txt}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables ss = "hello world" # 10. ss.isalnum() is_alnum_ss = ss.isalnum() print(f"ss.isalnum(): {is_alnum_ss}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ss : String := "hello world" ; var is_alnum_ss : boolean := ss->matches("[a-zA-Z0-9]*") ; execute (StringLib.formattedString("ss.isalnum(): {is_alnum_ss}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables sng = "hello" # 11. sng.islower() islower_sng = sng.islower() print(f"sng.islower(): {islower_sng}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sng : String := "hello" ; var islower_sng : boolean := sng->matches("[a-z ]*") ; execute (StringLib.formattedString("sng.islower(): {islower_sng}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables ss = "hello world" # 12. ss.isupper() isupper_ss = ss.isupper() print(f"ss.isupper(): {isupper_ss}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ss : String := "hello world" ; var isupper_ss : boolean := ss->matches("[A-Z ]*") ; execute (StringLib.formattedString("ss.isupper(): {isupper_ss}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables txt = "12345" # 13. txt.isspace() isspace_txt = txt.isspace() print(f"txt.isspace(): {isspace_txt}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var txt : String := "12345" ; var isspace_txt : boolean := txt->matches("[ \t\n\r]*") ; execute (StringLib.formattedString("txt.isspace(): {isspace_txt}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables ss = "hello world" # 14. ss.isdigit() isdigit_ss = ss.isdigit() print(f"ss.isdigit(): {isdigit_ss}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ss : String := "hello world" ; var isdigit_ss : boolean := ss->matches("[0-9]*") ; execute (StringLib.formattedString("ss.isdigit(): {isdigit_ss}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables s = 4 p = 4 # 3. p != s if p != s: print(f"p is not equal to s: {p} != {s}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : int := 4 ; var p : int := 4 ; if p /= s then ( execute (StringLib.formattedString("p is not equal to s: {p} != {s}"))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables txt = "12345" # 15. txt.isdecimal() isdecimal_txt = txt.isdecimal() print(f"txt.isdecimal(): {isdecimal_txt}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var txt : String := "12345" ; var isdecimal_txt : boolean := txt->matches("[0-9]*") ; execute (StringLib.formattedString("txt.isdecimal(): {isdecimal_txt}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables x = 45 # Angle in degrees # Convert degrees to radians for trigonometric functions x_rad = math.radians(x) # 1. math.cos(x) cosx = math.cos(x_rad) print(f"math.cos(x) with x = {x}: {cosx}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := 45 ; var x_rad : OclAny := ; var cosx : OclAny := ; execute (StringLib.formattedString("math.cos(x) with x = {x}: {cosx}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables x = 45 # Angle in degrees y = 2.5 # Number # Convert degrees to radians for trigonometric functions x_rad = math.radians(x) # 2. math.sin(y) sin_y = math.sin(y) print(f"math.sin(y) with y = {y}: {sin_y}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := 45 ; var y : double := 2.5 ; var x_rad : OclAny := ; var sin_y : double := (y)->sin() ; execute (StringLib.formattedString("math.sin(y) with y = {y}: {sin_y}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables x = 45 # Angle in degrees z = 16 # Number # Convert degrees to radians for trigonometric functions x_rad = math.radians(x) # 3. math.tan(z) tanz = math.tan(z) print(f"math.tan(z) with z = {z}: {tanz}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := 45 ; var z : int := 16 ; var x_rad : OclAny := ; var tanz : double := (z)->tan() ; execute (StringLib.formattedString("math.tan(z) with z = {z}: {tanz}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables x = 45 # Angle in degrees xx = 3.7 # Number # Convert degrees to radians for trigonometric functions x_rad = math.radians(x) # 4. math.ceil(xx) ceilxx = math.ceil(xx) print(f"math.ceil(xx) with xx = {xx}: {ceilxx}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := 45 ; var xx : double := 3.7 ; var x_rad : OclAny := ; var ceilxx : double := (xx)->ceil() ; execute (StringLib.formattedString("math.ceil(xx) with xx = {xx}: {ceilxx}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables x = 45 # Angle in degrees xx = 3.7 # Number # Convert degrees to radians for trigonometric functions x_rad = math.radians(x) # 5. math.floor(xx) floorxx = math.floor(xx) print(f"math.floor(xx) with xx = {xx}: {floorxx}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := 45 ; var xx : double := 3.7 ; var x_rad : OclAny := ; var floorxx : double := (xx)->floor() ; execute (StringLib.formattedString("math.floor(xx) with xx = {xx}: {floorxx}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables x = 45 # Angle in degrees y = 2.5 # Number # Convert degrees to radians for trigonometric functions x_rad = math.radians(x) # 6. math.trunc(y) truncy = math.trunc(y) print(f"math.trunc(y) with y = {y}: {truncy}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := 45 ; var y : double := 2.5 ; var x_rad : OclAny := ; var truncy : int := (y)->oclAsType(int) ; execute (StringLib.formattedString("math.trunc(y) with y = {y}: {truncy}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables x = 45 # Angle in degrees z = 16 # Number # Convert degrees to radians for trigonometric functions x_rad = math.radians(x) # 7. math.sqrt(z) sqrtz = math.sqrt(z) print(f"math.sqrt(z) with z = {z}: {sqrtz}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := 45 ; var z : int := 16 ; var x_rad : OclAny := ; var sqrtz : double := (z)->sqrt() ; execute (StringLib.formattedString("math.sqrt(z) with z = {z}: {sqrtz}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables x = 45 # Angle in degrees # Convert degrees to radians for trigonometric functions x_rad = math.radians(x) # 8. math.cbrt(x) (Note: math.cbrt is not available in the standard math module; using an alternative) cbrtx = x ** (1/3) print(f"math.cbrt(x) with x = {x} (computed as x ** (1/3)): {cbrtx}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := 45 ; var x_rad : OclAny := ; var cbrtx : double := (x)->pow((1 / 3)) ; execute (StringLib.formattedString("math.cbrt(x) with x = {x} (computed as x ** (1/3)): {cbrtx}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables x = 45 # Angle in degrees y = 2.5 # Number # Convert degrees to radians for trigonometric functions x_rad = math.radians(x) # 9. math.exp(y) expy = math.exp(y) print(f"math.exp(y) with y = {y}: {expy}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := 45 ; var y : double := 2.5 ; var x_rad : OclAny := ; var expy : double := (y)->exp() ; execute (StringLib.formattedString("math.exp(y) with y = {y}: {expy}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables x = 'a' ss = "hello" # 4. x not in ss if x not in ss: print("x is not in ss") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := 'a' ; var ss : String := "hello" ; if (ss)->characters()->excludes(x) then ( execute ("x is not in ss")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables x = 45 # Angle in degrees p = 10 # Number # Convert degrees to radians for trigonometric functions x_rad = math.radians(x) # 10. math.log(p) logp = math.log(p) print(f"math.log(p) with p = {p}: {logp}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := 45 ; var p : int := 10 ; var x_rad : OclAny := ; var logp : double := (p)->log() ; execute (StringLib.formattedString("math.log(p) with p = {p}: {logp}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables x = 45 # Angle in degrees xx = 3.7 # Number # Convert degrees to radians for trigonometric functions x_rad = math.radians(x) # 11. math.log10(xx) log10xx = math.log10(xx) print(f"math.log10(xx) with xx = {xx}: {log10xx}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := 45 ; var xx : double := 3.7 ; var x_rad : OclAny := ; var log10xx : double := (xx)->log10() ; execute (StringLib.formattedString("math.log10(xx) with xx = {xx}: {log10xx}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables r = 0.5 # Cosine of an angle (for acos) # 1. math.acos(r) acos_r = math.acos(r) print(f"math.acos(r) with r = {r}: {acos_r} radians, {math.degrees(acos_r)} degrees") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var r : double := 0.5 ; var acos_r : double := (r)->acos() ; execute (StringLib.formattedString("math.acos(r) with r = {r}: {acos_r} radians, {math.degrees(acos_r)} degrees"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables deg = 0.5 # Sine of an angle (for asin) # 2. math.asin(deg) asin_deg = math.asin(deg) print(f"math.asin(deg) with deg = {deg}: {asin_deg} radians, {math.degrees(asin_deg)} degrees") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var deg : double := 0.5 ; var asin_deg : double := (deg)->asin() ; execute (StringLib.formattedString("math.asin(deg) with deg = {deg}: {asin_deg} radians, {math.degrees(asin_deg)} degrees"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables a = 1.0 # Tangent of an angle (for atan) # 3. math.atan(a) atan_a = math.atan(a) print(f"math.atan(a) with a = {a}: {atan_a} radians, {math.degrees(atan_a)} degrees") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : double := 1.0 ; var atan_a : double := (a)->atan() ; execute (StringLib.formattedString("math.atan(a) with a = {a}: {atan_a} radians, {math.degrees(atan_a)} degrees"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables m = 1.5 # Value (for acosh) # 4. math.acosh(m) acosh_m = math.acosh(m) print(f"math.acosh(m) with m = {m}: {acosh_m}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var m : double := 1.5 ; var acosh_m : double := MathLib.acosh(m) ; execute (StringLib.formattedString("math.acosh(m) with m = {m}: {acosh_m}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables x = 1.0 # Value (for asinh and tanh) # 5. math.asinh(x) asinh_x = math.asinh(x) print(f"math.asinh(x) with x = {x}: {asinh_x}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : double := 1.0 ; var asinh_x : double := MathLib.asinh(x) ; execute (StringLib.formattedString("math.asinh(x) with x = {x}: {asinh_x}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables y = 0.5 # Value (for atanh) # 6. math.atanh(y) atanh_y = math.atanh(y) print(f"math.atanh(y) with y = {y}: {atanh_y}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var y : double := 0.5 ; var atanh_y : double := MathLib.atanh(y) ; execute (StringLib.formattedString("math.atanh(y) with y = {y}: {atanh_y}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables z = 1.0 # Value (for cosh) # 7. math.cosh(z) cosh_z = math.cosh(z) print(f"math.cosh(z) with z = {z}: {cosh_z}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var z : double := 1.0 ; var cosh_z : double := (z)->cosh() ; execute (StringLib.formattedString("math.cosh(z) with z = {z}: {cosh_z}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables p = 0.5 # Value (for sinh) # 8. math.sinh(p) sinh_p = math.sinh(p) print(f"math.sinh(p) with p = {p}: {sinh_p}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var p : double := 0.5 ; var sinh_p : double := (p)->sinh() ; execute (StringLib.formattedString("math.sinh(p) with p = {p}: {sinh_p}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables x = 'a' exs = ['a', 'b', 'c'] # 5. x in exs if x in exs: print("x is in exs") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := 'a' ; var exs : Sequence := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{ 'c' })) ; if (exs)->includes(x) then ( execute ("x is in exs")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables x = 1.0 # Value (for asinh and tanh) # 9. math.tanh(x) tanh_x = math.tanh(x) print(f"math.tanh(x) with x = {x}: {tanh_x}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : double := 1.0 ; var tanh_x : double := (x)->tanh() ; execute (StringLib.formattedString("math.tanh(x) with x = {x}: {tanh_x}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables x = 2 p = 3 # 1. math.pow(x, p) pow_x_p = math.pow(x, p) print(f"math.pow(x, p) with x = {x} and p = {p}: {pow_x_p}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := 2 ; var p : int := 3 ; var pow_x_p : double := (x)->pow(p) ; execute (StringLib.formattedString("math.pow(x, p) with x = {x} and p = {p}: {pow_x_p}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables n = 5 m = 3 # 2. math.comb(n, m) comb_n_m = math.comb(n, m) print(f"math.comb(n, m) with n = {n} and m = {m}: {comb_n_m}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := 5 ; var m : int := 3 ; var comb_n_m : long := MathLib.combinatorial(n, m) ; execute (StringLib.formattedString("math.comb(n, m) with n = {n} and m = {m}: {comb_n_m}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables rx = -7.5 # 3. math.fabs(rx) fabs_rx = math.fabs(rx) print(f"math.fabs(rx) with rx = {rx}: {fabs_rx}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var rx : double := -7.5 ; var fabs_rx : double := (rx)->abs() ; execute (StringLib.formattedString("math.fabs(rx) with rx = {rx}: {fabs_rx}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables K = 4 # 4. math.factorial(K) factorial_K = math.factorial(K) print(f"math.factorial(K) with K = {K}: {factorial_K}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var K : int := 4 ; var factorial_K : long := MathLib.factorial(K) ; execute (StringLib.formattedString("math.factorial(K) with K = {K}: {factorial_K}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables xs = [1.1, 2.2, 3.3, 4.4] # List of numbers # 5. math.fsum(xs) fsum_xs = math.fsum(xs) print(f"math.fsum(xs) with xs = {xs}: {fsum_xs}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var xs : Sequence := Sequence{1.1}->union(Sequence{2.2}->union(Sequence{3.3}->union(Sequence{ 4.4 }))) ; var fsum_xs : double := (xs)->sum() ; execute (StringLib.formattedString("math.fsum(xs) with xs = {xs}: {fsum_xs}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables ws = [1, 2, 3, 4] # List of numbers for product # 6. math.prod(ws) prod_ws = math.prod(ws) print(f"math.prod(ws) with ws = {ws}: {prod_ws}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var ws : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))) ; var prod_ws : double := (ws)->prd() ; execute (StringLib.formattedString("math.prod(ws) with ws = {ws}: {prod_ws}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables x = 2 y = 15 # 7. math.gcd(x, y) gcd_x_y = math.gcd(x, y) print(f"math.gcd(x, y) with x = {x} and y = {y}: {gcd_x_y}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := 2 ; var y : int := 15 ; var gcd_x_y : long := (x)->gcd(y) ; execute (StringLib.formattedString("math.gcd(x, y) with x = {x} and y = {y}: {gcd_x_y}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables p = 3 r = 20 # 8. math.lcm(p, r) (Note: math.lcm is available in Python 3.9+) lcmpr = math.lcm(p, r) print(f"math.lcm(p, r) with p = {p} and r = {r}: {lcmpr}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var p : int := 3 ; var r : int := 20 ; var lcmpr : int := MathLib.lcm(p, r) ; execute (StringLib.formattedString("math.lcm(p, r) with p = {p} and r = {r}: {lcmpr}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables d = -10 # 6. abs(d) absolute_value = abs(d) print(f"Absolute value of d ({d}) is: {absolute_value}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : int := -10 ; var absolute_value : double := (d)->abs() ; execute (StringLib.formattedString("Absolute value of d ({d}) is: {absolute_value}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables exs = ['a', 'b', 'c'] # 7. all(exs) if all(exs): print("All elements in exs are truthy") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var exs : Sequence := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{ 'c' })) ; if (exs)->forAll( _x | _x = true ) then ( execute ("All elements in exs are truthy")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables ps = [False, False, True] # 8. any(ps) if any(ps): print("At least one element in ps is truthy") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ps : Sequence := Sequence{false}->union(Sequence{false}->union(Sequence{ true })) ; if (ps)->exists( _x | _x = true ) then ( execute ("At least one element in ps is truthy")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables s_str = "hello" # 9. ascii(s_str) ascii_representation = ascii(s_str) print(f"ASCII representation of s_str is: {ascii_representation}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s_str : String := "hello" ; var ascii_representation : String := ((s_str) + "") ; execute (StringLib.formattedString("ASCII representation of s_str is: {ascii_representation}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables s_str = "hello" # 10. bool(s_str) if bool(s_str): print("s_str is truthy") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s_str : String := "hello" ; if (s_str)->toBoolean() then ( execute ("s_str is truthy")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # 2. lambda z : z*z square = lambda z: z * z num = 7 if square(num) == num * num: print(f"Square of {num}: {square(num)}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var square : Function := lambda z : OclAny in (z * z) ; var num : int := 7 ; if square->apply(num) = num * num then ( execute (StringLib.formattedString("Square of {num}: {square(num)}"))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # 11. await (Not applicable in a non-async context; here's an example of where it might be used) # This requires an asynchronous context (like async def), so I'll simulate it with a basic example import asyncio async def example_async_function(): return 42 async def main(): p = example_async_function() result = await p print(f"Result of await(p): {result}") # To run the async example, you'd typically use: # asyncio.run(main()) ------------------------------------------------------------ OCL File: --------- class Async$example_async_function { stereotype active; static operation newAsync$example_async_function() : Async$example_async_function pre: true post: Async$example_async_function->exists( resx | result = resx ); operation run() pre: true post: true activity: return 42; } class Async$main { stereotype active; static operation newAsync$main() : Async$main pre: true post: Async$main->exists( resx | result = resx ); operation run() pre: true post: true activity: var p : OclAny := example_async_function() ; var result : OclAny := p.join() ; execute (StringLib.formattedString("Result of await(p): {result}"))->display(); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip; operation example_async_function() : OclAny pre: true post: true activity: return 42; operation main() pre: true post: true activity: var p : OclAny := example_async_function() ; var result : OclAny := p.join() ; execute (StringLib.formattedString("Result of await(p): {result}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables x = 10 y = 20 # 1. dict({1:x, 2:y}) my_dict = dict({1: x, 2: y}) print(f"Dictionary with 1:x and 2:y: {my_dict}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 10 ; var y : int := 20 ; var my_dict : Map := (Map{ 1 |-> x }->union(Map{ 2 |-> y })) ; execute (StringLib.formattedString("Dictionary with 1:x and 2:y: {my_dict}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # 2. dict({}) empty_dict = dict({}) print(f"Empty dictionary: {empty_dict}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var empty_dict : Map := (Map{}) ; execute (StringLib.formattedString("Empty dictionary: {empty_dict}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables a = 15 b = 4 # 3. divmod(a, b) quotient, remainder = divmod(a, b) print(f"Quotient and remainder of {a} divided by {b}: ({quotient}, {remainder})") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := 15 ; var b : int := 4 ; var quotient : OclAny := null; var remainder : OclAny := null; Sequence{quotient,remainder} := Sequence{(a div b), (a mod b)} ; execute (StringLib.formattedString("Quotient and remainder of {a} divided by {b}: ({quotient}, {remainder})"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables s = [1, 2, 3, 4, 5] f = lambda x: x > 2 # 4. filter(f, s) filtered_list = list(filter(f, s)) print(f"Filtered list where elements are greater than 2: {filtered_list}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ; var f : Function := lambda x : OclAny in (x > 2) ; var filtered_list : Sequence := ((s)->select( _x | (f)->apply(_x) = true )) ; execute (StringLib.formattedString("Filtered list where elements are greater than 2: {filtered_list}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables s = [1, 2, 3, 4, 5] f = lambda x: x > 2 # 5. map(f, s) mapped_list = list(map(f, s)) print(f"Mapped list (whether each element is greater than 2): {mapped_list}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ; var f : Function := lambda x : OclAny in (x > 2) ; var mapped_list : Sequence := ((s)->collect( _x | (f)->apply(_x) )) ; execute (StringLib.formattedString("Mapped list (whether each element is greater than 2): {mapped_list}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables ss = "hello" # 6. len(ss) length = len(ss) print(length) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ss : String := "hello" ; var length : int := (ss)->size() ; execute (length)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # 7. list([3,5,7]) list_of_numbers = list([3, 5, 7]) print(f"List created with [3, 5, 7]: {list_of_numbers}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var list_of_numbers : Sequence := (Sequence{3}->union(Sequence{5}->union(Sequence{ 7 }))) ; execute (StringLib.formattedString("List created with [3, 5, 7]: {list_of_numbers}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables x = 10 z = 30 # 8. list([x,z]) list_of_vars = list([x, z]) print(f"List created with [x, z]: {list_of_vars}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 10 ; var z : int := 30 ; var list_of_vars : Sequence := (Sequence{x}->union(Sequence{ z })) ; execute (StringLib.formattedString("List created with [x, z]: {list_of_vars}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # 9. list([]) empty_list = list([]) print(f"Empty list: {empty_list}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var empty_list : Sequence := (Sequence{}) ; execute (StringLib.formattedString("Empty list: {empty_list}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # 3. not x < y x = 15 y = 10 if not x < y: print(f"It is not true that {x} is less than {y}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 15 ; var y : int := 10 ; if not((x->compareTo(y)) < 0) then ( execute (StringLib.formattedString("It is not true that {x} is less than {y}"))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables sx = [3, 7, 1, 9, 4] # 1. max(sx) max_sx = max(sx) print(f"Maximum value in list sx {sx}: {max_sx}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sx : Sequence := Sequence{3}->union(Sequence{7}->union(Sequence{1}->union(Sequence{9}->union(Sequence{ 4 })))) ; var max_sx : OclAny := (sx)->max() ; execute (StringLib.formattedString("Maximum value in list sx {sx}: {max_sx}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables a = 15 b = 10 # 2. max(a, b) max_ab = max(a, b) print(f"Maximum value between a ({a}) and b ({b}): {max_ab}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := 15 ; var b : int := 10 ; var max_ab : OclAny := Set{a, b}->max() ; execute (StringLib.formattedString("Maximum value between a ({a}) and b ({b}): {max_ab}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables ss = "hello" # 3. min(ss) min_ss = min(ss) print(f"Minimum value (character) in string ss ({ss}): {min_ss}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ss : String := "hello" ; var min_ss : OclAny := (ss)->min() ; execute (StringLib.formattedString("Minimum value (character) in string ss ({ss}): {min_ss}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables a = 15 b = 10 c = 5 # 4. min(a, b, c) min_abc = min(a, b, c) print(f"Minimum value between a ({a}), b ({b}), and c ({c}): {min_abc}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := 15 ; var b : int := 10 ; var c : int := 5 ; var min_abc : OclAny := Set{a, b, c}->min() ; execute (StringLib.formattedString("Minimum value between a ({a}), b ({b}), and c ({c}): {min_abc}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables px = 3.756 # 5. round(px) rounded_px = round(px) print(f"Rounded value of px ({px}): {rounded_px}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var px : double := 3.756 ; var rounded_px : double := (px)->round() ; execute (StringLib.formattedString("Rounded value of px ({px}): {rounded_px}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables nx = 5 # 6. slice(nx) slice_nx = slice(nx) print(f"Slice object for nx ({nx}): {slice_nx}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var nx : int := 5 ; var slice_nx : Sequence := Integer.subrange(1,nx) ; execute (StringLib.formattedString("Slice object for nx ({nx}): {slice_nx}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables st = 1 en = 4 # 7. slice(st, en) slice_st_en = slice(st, en) print(f"Slice object from st ({st}) to en ({en}): {slice_st_en}") # Demonstrating the slice objects sample_list = [10, 20, 30, 40, 50] # Using the slice object `slice(nx)` print(f"Using slice({nx}) on sample_list {sample_list}: {sample_list[slice_nx]}") # Using the slice object `slice(st, en)` print(f"Using slice({st}, {en}) on sample_list {sample_list}: {sample_list[slice_st_en]}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var st : int := 1 ; var en : int := 4 ; var slice_st_en : Sequence := Integer.subrange(st+1,en) ; execute (StringLib.formattedString("Slice object from st ({st}) to en ({en}): {slice_st_en}"))->display() ; var sample_list : Sequence := Sequence{10}->union(Sequence{20}->union(Sequence{30}->union(Sequence{40}->union(Sequence{ 50 })))) ; execute (StringLib.formattedString("Using slice({nx}) on sample_list {sample_list}: {sample_list[slice_nx]}"))->display() ; execute (StringLib.formattedString("Using slice({st}, {en}) on sample_list {sample_list}: {sample_list[slice_st_en]}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables sx = [3, 7, 1, 9, 4] # 1. sum(sx) sum_sx = sum(sx) print(f"Sum of the elements in list sx {sx}: {sum_sx}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sx : Sequence := Sequence{3}->union(Sequence{7}->union(Sequence{1}->union(Sequence{9}->union(Sequence{ 4 })))) ; var sum_sx : OclAny := (sx)->sum() ; execute (StringLib.formattedString("Sum of the elements in list sx {sx}: {sum_sx}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables x = 10 # 2. type(x) x_type = type(x) print(f"Type of x ({x}): {x_type}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 10 ; var x_type : OclType := (x)->oclType() ; execute (StringLib.formattedString("Type of x ({x}): {x_type}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables v = 100 # 3. print(v) print(f"Value of v: {v}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var v : int := 100 ; execute (StringLib.formattedString("Value of v: {v}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # 4. a > 1 and b > a a = 3 b = 5 if a > 1 and b > a: print(f"Both {a} > 1 and {b} > {a} are true") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := 3 ; var b : int := 5 ; if a > 1 & (b->compareTo(a)) > 0 then ( execute (StringLib.formattedString("Both {a} > 1 and {b} > {a} are true"))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables y = "20" # 4. int(y) int_y = int(y) print(f"String y ({y}) converted to integer: {int_y}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var y : String := "20" ; var int_y : int := ("" + ((y)))->toInteger() ; execute (StringLib.formattedString("String y ({y}) converted to integer: {int_y}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables z = "3.14" # 5. float(z) float_z = float(z) print(f"String z ({z}) converted to float: {float_z}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var z : String := "3.14" ; var float_z : double := ("" + ((z)))->toReal() ; execute (StringLib.formattedString("String z ({z}) converted to float: {float_z}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables v = 100 # 6. str(v) str_v = str(v) print(f"Integer v ({v}) converted to string: {str_v}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var v : int := 100 ; var str_v : String := ("" + ((v))) ; execute (StringLib.formattedString("Integer v ({v}) converted to string: {str_v}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables x = 10 # 7. chr(x) chr_x = chr(x) print(f"Character corresponding to ASCII value x ({x}): {chr_x}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 10 ; var chr_x : String := (x)->byte2char() ; execute (StringLib.formattedString("Character corresponding to ASCII value x ({x}): {chr_x}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables c = 'A' # 8. ord(c) ord_c = ord(c) print(f"ASCII value of character c ({c}): {ord_c}") # Note: 'unichr()' is not available in Python 3. In Python 2, it would convert a Unicode code point to a string. # However, Python 3's 'chr()' function performs this role, handling both standard ASCII and Unicode characters. ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : String := 'A' ; var ord_c : int := (c)->char2byte() ; execute (StringLib.formattedString("ASCII value of character c ({c}): {ord_c}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables x = 2 y = 3 # 1. pow(x, y) power = pow(x, y) print(f"{x} raised to the power of {y} is: {power}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 2 ; var y : int := 3 ; var power : double := (x)->pow(y) ; execute (StringLib.formattedString("{x} raised to the power of {y} is: {power}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables s = "Hello, World!" # 2. repr(s) repr_s = repr(s) print(f"repr of string s: {repr_s}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := "Hello, World!" ; var repr_s : String := ("" + ((s))) ; execute (StringLib.formattedString("repr of string s: {repr_s}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables lst = [3, 1, 4, 1, 5, 9] # 3. reversed(lst) reversed_lst = list(reversed(lst)) print(f"List lst reversed: {reversed_lst}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lst : Sequence := Sequence{3}->union(Sequence{1}->union(Sequence{4}->union(Sequence{1}->union(Sequence{5}->union(Sequence{ 9 }))))) ; var reversed_lst : Sequence := ((lst)->reverse()) ; execute (StringLib.formattedString("List lst reversed: {reversed_lst}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables lst = [3, 1, 4, 1, 5, 9] # 4. sorted(lst) sorted_lst = sorted(lst) print(f"List lst sorted: {sorted_lst}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lst : Sequence := Sequence{3}->union(Sequence{1}->union(Sequence{4}->union(Sequence{1}->union(Sequence{5}->union(Sequence{ 9 }))))) ; var sorted_lst : Sequence := lst->sort() ; execute (StringLib.formattedString("List lst sorted: {sorted_lst}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables a, b, c = 10, 20, 30 # 5. tuple(a, b, c) abc_tuple = tuple([a, b, c]) print(f"Tuple created from a, b, c: {abc_tuple}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{10,20,30} ; var abc_tuple : Sequence := (Sequence{a}->union(Sequence{b}->union(Sequence{ c }))) ; execute (StringLib.formattedString("Tuple created from a, b, c: {abc_tuple}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # 5. P or Q P = True Q = False if P or Q: print(f"At least one of P or Q is true") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var P : boolean := true ; var Q : boolean := false ; if P or Q then ( execute (StringLib.formattedString("At least one of P or Q is true"))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables x = 2 y = 3 # 6. (x, y) xy_tuple = (x, y) print(f"Tuple created from x and y: {xy_tuple}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 2 ; var y : int := 3 ; var xy_tuple : OclAny := Sequence{x, y} ; execute (StringLib.formattedString("Tuple created from x and y: {xy_tuple}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables x = 2 y = 3 # 7. range(x, y) range_xy = list(range(x, y)) print(f"Range from x ({x}) to y ({y}): {range_xy}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 2 ; var y : int := 3 ; var range_xy : Sequence := (Integer.subrange(x, y-1)) ; execute (StringLib.formattedString("Range from x ({x}) to y ({y}): {range_xy}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables lst = [3, 1, 4, 1, 5, 9] # 8. enumerate(lst) enumerated_lst = list(enumerate(lst)) print(f"Enumerated list lst: {enumerated_lst}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lst : Sequence := Sequence{3}->union(Sequence{1}->union(Sequence{4}->union(Sequence{1}->union(Sequence{5}->union(Sequence{ 9 }))))) ; var enumerated_lst : Sequence := (Integer.subrange(1, (lst)->size())->collect( _indx | Sequence{_indx-1, (lst)->at(_indx)} )) ; execute (StringLib.formattedString("Enumerated list lst: {enumerated_lst}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables s1 = ['a', 'b', 'c'] s2 = [1, 2, 3] # 9. zip(s1, s2) zipped_lists = list(zip(s1, s2)) print(f"Zipped lists s1 and s2: {zipped_lists}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s1 : Sequence := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{ 'c' })) ; var s2 : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; var zipped_lists : Sequence := (Integer.subrange(1, s1->size())->collect( _indx | Sequence{s1->at(_indx), s2->at(_indx)} )) ; execute (StringLib.formattedString("Zipped lists s1 and s2: {zipped_lists}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables x = 2 p = 3 # 1. x**p power_result = x**p print(f"{x} raised to the power of {p} (x**p): {power_result}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 2 ; var p : int := 3 ; var power_result : double := (x)->pow(p) ; execute (StringLib.formattedString("{x} raised to the power of {p} (x**p): {power_result}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables d = 5 # 2. +d (Unary plus, which leaves the value unchanged) positive_d = +d print(f"Unary plus applied to d ({d}): {positive_d}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : int := 5 ; var positive_d : int := d ; execute (StringLib.formattedString("Unary plus applied to d ({d}): {positive_d}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables x = 2 # 3. -x (Unary minus, negates the value) negative_x = -x print(f"Unary minus applied to x ({x}): {negative_x}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 2 ; var negative_x : int := -x ; execute (StringLib.formattedString("Unary minus applied to x ({x}): {negative_x}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables y = 10 # 4. ~y (Bitwise NOT, inverts the bits of y) bitwise_not_y = ~y print(f"Bitwise NOT applied to y ({y}): {bitwise_not_y}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var y : int := 10 ; var bitwise_not_y : int := MathLib.bitwiseNot(y) ; execute (StringLib.formattedString("Bitwise NOT applied to y ({y}): {bitwise_not_y}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np # Sample variables r = 6 q = 7 # 1. r*q (Multiplication) multiplication_result = r * q print(f"r * q (6 * 7): {multiplication_result}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var r : int := 6 ; var q : int := 7 ; var multiplication_result : int := r * q ; execute (StringLib.formattedString("r * q (6 * 7): {multiplication_result}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np # Sample variables p = 8 s = 4 # 2. p/s (Division) division_result = p / s print(f"p / s (8 / 4): {division_result}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var p : int := 8 ; var s : int := 4 ; var division_result : double := p / s ; execute (StringLib.formattedString("p / s (8 / 4): {division_result}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # 6. x < y x = 4 y = 9 if x < y: print(f"{x} is less than {y}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 4 ; var y : int := 9 ; if (x->compareTo(y)) < 0 then ( execute (StringLib.formattedString("{x} is less than {y}"))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np # Sample variables m = 10 n = 3 # 3. m%n (Modulus) modulus_result = m % n print(f"m % n (10 % 3): {modulus_result}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var m : int := 10 ; var n : int := 3 ; var modulus_result : int := m mod n ; execute (StringLib.formattedString("m % n (10 % 3): {modulus_result}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np # Sample variables m = 10 n = 3 # 4. m//n (Floor Division) floor_division_result = m // n print(f"m // n (10 // 3): {floor_division_result}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var m : int := 10 ; var n : int := 3 ; var floor_division_result : int := m div n ; execute (StringLib.formattedString("m // n (10 // 3): {floor_division_result}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np # Sample variables r = 6 p = 8 # 5. r @ p (Matrix multiplication; for scalar values it will require converting them to 1x1 matrices) # Here we'll use numpy to demonstrate matrix multiplication matrix_r = np.array([[r]]) matrix_p = np.array([[p]]) matrix_multiplication_result = matrix_r @ matrix_p print(f"r @ p (Matrix multiplication of [[6]] @ [[8]]): {matrix_multiplication_result}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var r : int := 6 ; var p : int := 8 ; var matrix_r : Sequence := (Sequence{ Sequence{ r } }) ; var matrix_p : Sequence := (Sequence{ Sequence{ p } }) ; var matrix_multiplication_result : Sequence := MatrixLib.matrixMultiplication(matrix_r,matrix_p) ; execute (StringLib.formattedString("r @ p (Matrix multiplication of [[6]] @ [[8]]): {matrix_multiplication_result}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables x = 3 y = 7 z = 4 # 1. [y, z] + [x] list_concatenation_1 = [y, z] + [x] print(f"[{y}, {z}] + [{x}]: {list_concatenation_1}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 3 ; var y : int := 7 ; var z : int := 4 ; var list_concatenation var x : int := 3 : Sequence := Sequence{y}->union(Sequence{ z })->union(Sequence{ x }) ; execute (StringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenationStringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenation(StringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenation(StringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenation(StringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenationStringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenation(StringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenation(StringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenation(StringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenationStringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenation(StringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenation(StringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenation(StringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenationStringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenation(StringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenation(StringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenation(StringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenationStringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenation(StringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenation(StringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenation(StringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenationStringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenation(StringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenation(StringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenation(StringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenationStringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenation(StringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenation(StringLib.formattedString("[{y}, {z}] + [{x}]: {list_concatenation var x : int := 3}"))}"))}")}"))->display()}"))}"))}")}"))->display()}"))}"))}")}"))->display()}"))}"))}")}"))->display()}"))}"))}")}"))->display()}"))}"))}")}"))->display()}"))}"))}")}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables a = "Hello" ss = "World" # 2. [a] + ss (Since ss is a string, this will actually raise an error) # To concatenate a list containing a string with another string, we need to convert ss to a list of characters list_concatenation = [a] + [ss] print(f"[{a}] + [{ss}]: {list_concatenation}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := "Hello" ; var ss : String := "World" ; var list_concatenation : Sequence := Sequence{ a }->union(Sequence{ ss }) ; execute (StringLib.formattedString("[{a}] + [{ss}]: {list_concatenation}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables w = 10 # 3. 5 + w sum_integer = 5 + w print(f"5 + {w}: {sum_integer}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : int := 10 ; var sum_integer : int := 5 + w ; execute (StringLib.formattedString("5 + {w}: {sum_integer}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables x = 3 # 4. 0.1 + x sum_float = 0.1 + x print(f"0.1 + {x}: {sum_float}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 3 ; var sum_float : double := 0.1 + x ; execute (StringLib.formattedString("0.1 + {x}: {sum_float}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables a = 15 b = 5 # 1. a - b (Subtraction) subtraction_result = a - b print(f"a - b ({a} - {b}): {subtraction_result}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := 15 ; var b : int := 5 ; var subtraction_result : double := a - b ; execute (StringLib.formattedString("a - b ({a} - {b}): {subtraction_result}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables x = 8 n = 2 # 2. x << n (Left shift) left_shift_result = x << n print(f"x << n ({x} << {n}): {left_shift_result}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 8 ; var n : int := 2 ; var left_shift_result : int := x * (2->pow(n)) ; execute (StringLib.formattedString("x << n ({x} << {n}): {left_shift_result}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables n = 2 y = 16 # 3. y >> n (Right shift) right_shift_result = y >> n print(f"y >> n ({y} >> {n}): {right_shift_result}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := 2 ; var y : int := 16 ; var right_shift_result : int := y /(2->pow(n)) ; execute (StringLib.formattedString("y >> n ({y} >> {n}): {right_shift_result}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # 7. x > z z = 2 x=3 if x > z: print(f"{x} is greater than {z}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var z : int := 2 ; var x : int := 3 ; if (x->compareTo(z)) > 0 then ( execute (StringLib.formattedString("{x} is greater than {z}"))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables n = 2 m = 3 # 4. n & m (Bitwise AND) bitwise_and_result = n & m print(f"n & m ({n} & {m}): {bitwise_and_result}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := 2 ; var m : int := 3 ; var bitwise_and_result : int := MathLib.bitwiseAnd(n, m) ; execute (StringLib.formattedString("n & m ({n} & {m}): {bitwise_and_result}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables i = 12 j = 7 # 5. i ^ j (Bitwise XOR) bitwise_xor_result = i ^ j print(f"i ^ j ({i} ^ {j}): {bitwise_xor_result}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : int := 12 ; var j : int := 7 ; var bitwise_xor_result : int := MathLib.bitwiseXor(i, j) ; execute (StringLib.formattedString("i ^ j ({i} ^ {j}): {bitwise_xor_result}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables p = 5 q = 9 # 6. p | q (Bitwise OR) bitwise_or_result = p | q print(f"p | q ({p} | {q}): {bitwise_or_result}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : int := 5 ; var q : int := 9 ; var bitwise_or_result : int := MathLib.bitwiseOr(p, q) ; execute (StringLib.formattedString("p | q ({p} | {q}): {bitwise_or_result}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample strings s = "hello world" # 1. s.capitalize() capitalized_s = s.capitalize() print(f"s.capitalize(): {capitalized_s}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := "hello world" ; var capitalized_s : String := StringLib.capitalise(s) ; execute (StringLib.formattedString("s.capitalize(): {capitalized_s}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample strings s = "hello world" # 2. s.join(c) joined_s = s.join(c) print(f"s.join(c): {joined_s}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := "hello world" ; var joined_s : String := StringLib.sumStringsWithSeparator((c), s) ; execute (StringLib.formattedString("s.join(c): {joined_s}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample strings s = "hello world" # 3. s.title() title_s = s.title() print(f"s.title(): {title_s}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := "hello world" ; var title_s : String := StringLib.toTitleCase(s) ; execute (StringLib.formattedString("s.title(): {title_s}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample strings s = "hello world" # 4. s.swapcase() swappedcase_s = s.swapcase() print(f"s.swapcase(): {swappedcase_s}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := "hello world" ; var swappedcase_s : String := StringLib.swapCase(s) ; execute (StringLib.formattedString("s.swapcase(): {swappedcase_s}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample strings x = " hello " # 5. x.lstrip() lstripped_x = x.lstrip() print(f"x.lstrip(): {lstripped_x}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := " hello " ; var lstripped_x : OclAny := StringLib.leftTrim(x) ; execute (StringLib.formattedString("x.lstrip(): {lstripped_x}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample strings x = " hello " # 6. x.rstrip() rstripped_x = x.rstrip() print(f"x.rstrip(): {rstripped_x}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := " hello " ; var rstripped_x : String := StringLib.rightTrim(x) ; execute (StringLib.formattedString("x.rstrip(): {rstripped_x}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample strings s = "hello world" # 7. s.istitle() istitle_s = s.istitle() print(f"s.istitle(): {istitle_s}") # Note: The string 's' needs to be updated if you want 's.istitle()' to return True. # For example: s_title_example = "Hello World" istitle_example = s_title_example.istitle() print(f"Example s.istitle() with updated string: {istitle_example}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := "hello world" ; var istitle_s : boolean := (s = StringLib.toTitleCase(s)) ; execute (StringLib.formattedString("s.istitle(): {istitle_s}"))->display() ; var s_title_example : String := "Hello World" ; var istitle_example : boolean := (s_title_example = StringLib.toTitleCase(s_title_example)) ; execute (StringLib.formattedString("Example s.istitle() with updated string: {istitle_example}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # 8. p <= y p = 9 y=90 if p <= y: print(f"{p} is less than or equal to {y}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : int := 9 ; var y : int := 90 ; if (p->compareTo(y)) <= 0 then ( execute (StringLib.formattedString("{p} is less than or equal to {y}"))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # 1. Empty list empty_list = [] print(f"Empty list: {empty_list}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var empty_list : Sequence := Sequence{} ; execute (StringLib.formattedString("Empty list: {empty_list}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables a = 10 b = 20 # 2. List with elements list_with_elements = [a, b] print(f"List with elements [a, b]: {list_with_elements}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : int := 10 ; var b : int := 20 ; var list_with_elements : Sequence := Sequence{a}->union(Sequence{ b }) ; execute (StringLib.formattedString("List with elements [a, b]: {list_with_elements}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # 3. Empty dictionary empty_dict = dict({}) print(f"Empty dictionary: {empty_dict}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var empty_dict : Map := (Map{}) ; execute (StringLib.formattedString("Empty dictionary: {empty_dict}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables x = 30 y = 40 z = 50 # 4. Set with elements set_with_elements = {x, y, z} print(f"Set with elements {{x, y, z}}: {set_with_elements}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : int := 30 ; var y : int := 40 ; var z : int := 50 ; var set_with_elements : Set := Set{x}->union(Set{y}->union(Set{ z })) ; execute (StringLib.formattedString("Set with elements {{x, y, z}}: {set_with_elements}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # Sample variables a = 10 b = 20 x = 30 y = 40 # 5. Dictionary with key-value pairs dict_with_pairs = {a: x, b: y} print(f"Dictionary with pairs {{a: x, b: y}}: {dict_with_pairs}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : int := 10 ; var b : int := 20 ; var x : int := 30 ; var y : int := 40 ; var dict_with_pairs : Map := Map{ a |-> x }->union(Map{ b |-> y }) ; execute (StringLib.formattedString("Dictionary with pairs {{a: x, b: y}}: {dict_with_pairs}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # 6. None none_value = None print(f"None: {none_value}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var none_value : OclAny := null ; execute (StringLib.formattedString("None: {none_value}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # 7. True true_value = True print(f"True: {true_value}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var true_value : boolean := true ; execute (StringLib.formattedString("True: {true_value}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # 8. False false_value = False print(f"False: {false_value}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var false_value : boolean := false ; execute (StringLib.formattedString("False: {false_value}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # 9. Positive infinity positive_inf = float('inf') print(f"Positive infinity: {positive_inf}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var positive_inf : double := ("" + (('inf')))->toReal() ; execute (StringLib.formattedString("Positive infinity: {positive_inf}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # 10. Negative infinity (for completeness) negative_inf = float('-inf') print(f"Negative infinity: {negative_inf}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var negative_inf : double := ("" + (('-inf')))->toReal() ; execute (StringLib.formattedString("Negative infinity: {negative_inf}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # 9. x >= y x=9 y=8 if x >= y: print(f"{x} is greater than or equal to {y}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := 9 ; var y : int := 8 ; if (x->compareTo(y)) >= 0 then ( execute (StringLib.formattedString("{x} is greater than or equal to {y}"))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math # 11. NaN (Not a Number) nan_value = float('nan') print(f"NaN (Not a Number): {nan_value}") # Note: Infinity and NaN are represented in Python using floats. ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var nan_value : double := ("" + (('nan')))->toReal() ; execute (StringLib.formattedString("NaN (Not a Number): {nan_value}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables ss = ['apple', 'banana', 'cherry', 'banana'] x = 'banana' # 1. ss.count(x) count_x = ss.count(x) print(f"Count of {x} in ss: {count_x}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ss : Sequence := Sequence{'apple'}->union(Sequence{'banana'}->union(Sequence{'cherry'}->union(Sequence{ 'banana' }))) ; var x : String := 'banana' ; var count_x : int := ss->count(x) ; execute (StringLib.formattedString("Count of {x} in ss: {count_x}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables ss = ['apple', 'banana', 'cherry', 'banana'] y = 'cherry' # 2. ss.index(y) index_y = ss.index(y) print(f"Index of {y} in ss: {index_y}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ss : Sequence := Sequence{'apple'}->union(Sequence{'banana'}->union(Sequence{'cherry'}->union(Sequence{ 'banana' }))) ; var y : String := 'cherry' ; var index_y : int := ss->indexOf(y) - 1 ; execute (StringLib.formattedString("Index of {y} in ss: {index_y}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables ss = ['apple', 'banana', 'cherry', 'banana'] # 3. ss.sort() (Sorting list ss in-place) ss.sort() print(f"Sorted ss: {ss}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ss : Sequence := Sequence{'apple'}->union(Sequence{'banana'}->union(Sequence{'cherry'}->union(Sequence{ 'banana' }))) ; ss := ss->sort() ; execute (StringLib.formattedString("Sorted ss: {ss}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables ss = ['apple', 'banana', 'cherry', 'banana'] # 4. ss.reverse() (Reversing list ss in-place) ss.reverse() print(f"Reversed ss: {ss}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ss : Sequence := Sequence{'apple'}->union(Sequence{'banana'}->union(Sequence{'cherry'}->union(Sequence{ 'banana' }))) ; ss := ss->reverse() ; execute (StringLib.formattedString("Reversed ss: {ss}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables sx = {1, 2, 3} # 5. sx.add(y) (Note: 'y' is not an integer, so it will raise an error if used here.) # To demonstrate, we'll use a value that is valid for the set 'sx'. sx.add(4) print(f"Set sx after adding 4: {sx}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sx : Set := Set{1}->union(Set{2}->union(Set{ 3 })) ; execute ((4) : sx) ; execute (StringLib.formattedString("Set sx after adding 4: {sx}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables ss = ['apple', 'banana', 'cherry', 'banana'] # 6. ss.copy() (Creating a copy of list ss) ss_copy = ss.copy() print(f"Copy of ss: {ss_copy}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ss : Sequence := Sequence{'apple'}->union(Sequence{'banana'}->union(Sequence{'cherry'}->union(Sequence{ 'banana' }))) ; var ss_copy : OclAny := ss->copy() ; execute (StringLib.formattedString("Copy of ss: {ss_copy}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables pp = {1, 2, 3, 7} qq = {2, 3, 5} # 7. pp.intersection(qq) intersection_pp_qq = pp.intersection(qq) print(f"Intersection of pp and qq: {intersection_pp_qq}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var pp : Set := Set{1}->union(Set{2}->union(Set{3}->union(Set{ 7 }))) ; var qq : Set := Set{2}->union(Set{3}->union(Set{ 5 })) ; var intersection_pp_qq : OclAny := pp->intersection(qq) ; execute (StringLib.formattedString("Intersection of pp and qq: {intersection_pp_qq}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables px = {1, 2, 3, 4} qx = {3, 4, 5, 6} # 8. px.difference(qx) difference_px_qx = px.difference(qx) print(f"Difference of px and qx: {difference_px_qx}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var px : Set := Set{1}->union(Set{2}->union(Set{3}->union(Set{ 4 }))) ; var qx : Set := Set{3}->union(Set{4}->union(Set{5}->union(Set{ 6 }))) ; var difference_px_qx : OclAny := px - (qx) ; execute (StringLib.formattedString("Difference of px and qx: {difference_px_qx}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- # Sample variables ss = ['apple', 'banana', 'cherry', 'banana'] rr = {10, 20, 30} # 9. ss.isdisjoint(rr) is_disjoint = ss.isdisjoint(rr) print(f"Is ss disjoint with rr? {is_disjoint}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ss : Sequence := Sequence{'apple'}->union(Sequence{'banana'}->union(Sequence{'cherry'}->union(Sequence{ 'banana' }))) ; var rr : Set := Set{10}->union(Set{20}->union(Set{ 30 })) ; var is_disjoint : boolean := ss->intersection(rr)->isEmpty() ; execute (StringLib.formattedString("Is ss disjoint with rr? {is_disjoint}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------

=M*(V-(P+N-j)) def binary_search(): ok=1 ng=N+1 while abs(ok-ng)>1 : mid=(ok+ng)//2 if is_ok(mid): ok=mid else : ng=mid return ok *A,=sorted(A,reverse=True) A=[0]+A acc=tuple(accumulate(A)) return binary_search() def main(): import sys input=sys.stdin.readline N,M,V,P=map(int,input().split()) A=map(int,input().split()) print(solve(N,M,V,P,A)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; (testlist_star_expr (star_expr * (expr (atom (name A)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name A)))) ,)} := A->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))); operation solve(N : int, M : int, V : int, P : int, A : 'list[int]') : int pre: true post: true activity: skip ; skip ; skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fact(n): if n==1 : return 1 else : return n*fact(n-1) def sum(x,n): total=1.0 for i in range(1,n+1,1): total=total+(pow(x,i)/fact(i+1)) return total if __name__=='__main__' : x=5 n=4 print("Sum is:{0:.4f}".format(sum(x,n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( x := 5 ; n := 4 ; execute (StringLib.interpolateStrings("Sum is:{0:.4f}", Sequence{(x, n)->sum()}))->display() ) else skip; operation fact(n : OclAny) : OclAny pre: true post: true activity: if n = 1 then ( return 1 ) else ( return n * fact(n - 1) ); operation sum(x : OclAny, n : OclAny) : OclAny pre: true post: true activity: var total : double := 1.0 ; for i : Integer.subrange(1, n + 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( total := total + ((x)->pow(i) / fact(i + 1))) ; return total; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(0,t): a,b=map(int,input().split()) if a!=b : c=abs(a-b) r=a % c print(c,min(r,c-r)) else : print(0,0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a /= b then ( var c : double := (a - b)->abs() ; var r : int := a mod c ; execute (c)->display() ) else ( execute (0)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a,b=map(int,input().split()) if a==b : print("0 0") else : c=abs(a-b) r=a % c print(c,min(r,c-r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = b then ( execute ("0 0")->display() ) else ( var c : double := (a - b)->abs() ; var r : int := a mod c ; execute (c)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for i in range(int(input())): a,b=map(int,input().split()) if(a==b): print(0,0) else : d=abs(a-b) p=d-a % d q=a % d print(d,min(p,q)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a = b) then ( execute (0)->display() ) else ( var d : double := (a - b)->abs() ; var p : double := d - a mod d ; var q : int := a mod d ; execute (d)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) ans=[] for i in range(t): a,b=tuple(map(int,input().split())) maks=max(a,b) diff=abs(a-b) moves=0 if(diff==0): moves=diff elif(maks % diff>(((maks//diff)+1)*diff)-maks): moves=(((maks//diff)+1)*diff)-maks else : moves=maks % diff ans.append([str(diff),str(moves)]) for case in tuple(ans): print(' '.join(case).strip()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var maks : OclAny := Set{a, b}->max() ; var diff : double := (a - b)->abs() ; var moves : int := 0 ; if (diff = 0) then ( moves := diff ) else (if ((maks mod diff->compareTo((((maks div diff) + 1) * diff) - maks)) > 0) then ( moves := (((maks div diff) + 1) * diff) - maks ) else ( moves := maks mod diff ) ) ; execute ((Sequence{("" + ((diff)))}->union(Sequence{ ("" + ((moves))) })) : ans)) ; for case : (ans) do ( execute (' '.join(case)->trim())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) P=list(map(int,input().split())) A=[45678*i for i in range(1,N+1)] B=A[: :-1] for i,p in enumerate(P): A[p-1]+=i B[p-1]+=i print(*A) print(*B) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var P : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var A : Sequence := Integer.subrange(1, N + 1-1)->select(i | true)->collect(i | (45678 * i)) ; var B : OclAny := A(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; for _tuple : Integer.subrange(1, (P)->size())->collect( _indx | Sequence{_indx-1, (P)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p : OclAny := _tuple->at(_indx); A[p - 1+1] := A[p - 1+1] + i ; B[p - 1+1] := B[p - 1+1] + i) ; execute ((argument * (test (logical_test (comparison (expr (atom (name A))))))))->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name B))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin def li(): return[int(x)for x in stdin.readline().split()] def li_(): return[int(x)-1 for x in stdin.readline().split()] def lf(): return[float(x)for x in stdin.readline().split()] def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(ns()) def nf(): return float(ns()) n=ni() p=li_() a=[i*n+1 for i in range(n)] b=a[: :-1] ad=0 for pi in p : a[pi]+=ad b[pi]+=ad ad+=1 print(*a) print(*b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stdin : OclFile := OclFile["System.in"] ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := ni() ; var p : OclAny := li_() ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i * n + 1)) ; var b : OclAny := a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var ad : int := 0 ; for pi : p do ( a[pi+1] := a[pi+1] + ad ; b[pi+1] := b[pi+1] + ad ; ad := ad + 1) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name b))))))))->display(); operation li() : OclAny pre: true post: true activity: return stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation li_() : OclAny pre: true post: true activity: return stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation lf() : OclAny pre: true post: true activity: return stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation ls() : OclAny pre: true post: true activity: return stdin.readLine().split(); operation ns() : OclAny pre: true post: true activity: return stdin.readLine().rstrip(); operation lc() : OclAny pre: true post: true activity: return (ns()); operation ni() : OclAny pre: true post: true activity: return ("" + ((ns())))->toInteger(); operation nf() : OclAny pre: true post: true activity: return ("" + ((ns())))->toReal(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=input() s="" count=0 for i in range(0,len(x)-1,2): k=x[i : i+2] if k.count("a")==2 or k.count("b")==2 : k="ab" count=count+1 s=s+k print(count) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : String := (OclFile["System.in"]).readLine() ; var s : String := "" ; var count : int := 0 ; for i : Integer.subrange(0, (x)->size() - 1-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( var k : OclAny := x.subrange(i+1, i + 2) ; if k->count("a") = 2 or k->count("b") = 2 then ( k := "ab" ; count := count + 1 ) else skip ; s := s + k) ; execute (count)->display() ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import exit,setrecursionlimit from functools import reduce from itertools import* from collections import defaultdict from bisect import bisect def read(): return int(input()) def reads(): return[int(x)for x in input().split()] setrecursionlimit(1000000) N=read() p=reads() q=[0]*N for i in range(N): q[p[i]-1]=i+1 a=[0]*N b=[0]*N a[0]=1 b[-1]=1 for i in range(1,N): a[i]=a[i-1]+q[i] b[-1-i]=b[-i]+q[-1-i] print(" ".join(str(x)for x in a)) print(" ".join(str(x)for x in b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; setrecursionlimit(1000000) ; var N : OclAny := read() ; var p : OclAny := reads() ; var q : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for i : Integer.subrange(0, N-1) do ( q[p[i+1] - 1+1] := i + 1) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; a->first() := 1 ; b->last() := 1 ; for i : Integer.subrange(1, N-1) do ( a[i+1] := a[i - 1+1] + q[i+1] ; b->reverse()->at(-(-1 - i)) := b->reverse()->at(-(-i)) + q->reverse()->at(-(-1 - i))) ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a)))))))), " "))->display() ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name b)))))))), " "))->display(); operation read() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation reads() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gen_ordinary_lists(n): up_lis=list(range(1,n*20001,20001)) return up_lis,up_lis[: :-1] def argsort(lis): tpls=[(l,i)for i,l in enumerate(lis)] return sorted(tpls) def solve(N,lis): up_list,down_list=gen_ordinary_lists(N) arg_tpls=argsort(lis) for val,idx in arg_tpls : up_list[val-1]+=idx print(*up_list) print(*down_list) N=int(input()) lis=list(map(int,input().split())) solve(N,lis) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; lis := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; solve(N, lis); operation gen_ordinary_lists(n : OclAny) : OclAny pre: true post: true activity: var up_lis : Sequence := (Integer.subrange(1, n * 20001-1)->select( $x | ($x - 1) mod 20001 = 0 )) ; return up_lis, up_lis(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); operation argsort(lis : OclAny) : OclAny pre: true post: true activity: var tpls : Sequence := Integer.subrange(1, (lis)->size())->collect( _indx | Sequence{_indx-1, (lis)->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let l : OclAny = _tuple->at(2) in (Sequence{l, i})) ; return tpls->sort(); operation solve(N : OclAny, lis : OclAny) pre: true post: true activity: var up_list : OclAny := null; var down_list : OclAny := null; Sequence{up_list,down_list} := gen_ordinary_lists(N) ; var arg_tpls : OclAny := argsort(lis) ; for _tuple : arg_tpls do (var _indx : int := 1; var val : OclAny := _tuple->at(_indx); _indx := _indx + 1; var idx : OclAny := _tuple->at(_indx); up_list[val - 1+1] := up_list[val - 1+1] + idx) ; execute ((argument * (test (logical_test (comparison (expr (atom (name up_list))))))))->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name down_list))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=list(map(int,input().split())) a=[(i+1)*n for i in range(n)] b=[(n-i)*n for i in range(n)] for i in range(n): a[p[i]-1]-=n-i-1 sa="" sb="" for i in range(n): sa=sa+str(a[i]) sb=sb+str(b[i]) if i!=n-1 : sa=sa+' ' sb=sb+' ' print(sa) print(sb) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((i + 1) * n)) ; var b : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((n - i) * n)) ; for i : Integer.subrange(0, n-1) do ( a[p[i+1] - 1+1] := a[p[i+1] - 1+1] - n - i - 1) ; var sa : String := "" ; var sb : String := "" ; for i : Integer.subrange(0, n-1) do ( sa := sa + ("" + ((a[i+1]))) ; sb := sb + ("" + ((b[i+1]))) ; if i /= n - 1 then ( sa := sa + ' ' ; sb := sb + ' ' ) else skip) ; execute (sa)->display() ; execute (sb)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def spiralFill(m,n,a): val=1 k,l=0,0 while(kselect(i | true)->collect(i | (Integer.subrange(0, m-1)->select(j | true)->collect(j | (0)))) ; spiralFill(m, n, a) ; for i : Integer.subrange(0, m-1) do ( for j : Integer.subrange(0, n-1) do ( execute (a[i+1][j+1])->display()) ; execute ('')->display()) ) else skip; operation spiralFill(m : OclAny, n : OclAny, a : OclAny) pre: true post: true activity: var val : int := 1 ; var k : OclAny := null; var l : OclAny := null; Sequence{k,l} := Sequence{0,0} ; while ((k->compareTo(m)) < 0 & (l->compareTo(n)) < 0) do ( for i : Integer.subrange(l, n-1) do ( a[k+1][i+1] := val ; val := val + 1) ; k := k + 1 ; for i : Integer.subrange(k, m-1) do ( a[i+1][n - 1+1] := val ; val := val + 1) ; n := n - 1 ; if ((k->compareTo(m)) < 0) then ( for i : Integer.subrange(l - 1 + 1, n - 1)->reverse() do ( a[m - 1+1][i+1] := val ; val := val + 1) ; m := m - 1 ) else skip ; if ((l->compareTo(n)) < 0) then ( for i : Integer.subrange(k - 1 + 1, m - 1)->reverse() do ( a[i+1][l+1] := val ; val := val + 1) ; l := l + 1 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): MOD=10**16 subsets=[0]*250 subsets[0]=1 for i in range(1,250250+1): offset=pow(i,i,250) subsets=[(val+subsets[(j-offset)% 250])% MOD for(j,val)in enumerate(subsets)] ans=(subsets[0]-1)% MOD return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var MOD : double := (10)->pow(16) ; var subsets : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 250) ; subsets->first() := 1 ; for i : Integer.subrange(1, 250250 + 1-1) do ( var offset : double := (i)->pow(i) ; subsets := Integer.subrange(1, (subsets)->size())->collect( _indx | Sequence{_indx-1, (subsets)->at(_indx)} )->select(Sequence{j, val} | true)->collect(Sequence{j, val} | ((val + subsets[(j - offset) mod 250+1]) mod MOD))) ; var ans : int := (subsets->first() - 1) mod MOD ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt pref=[0]*10000 ; def isPerfect(n): sum=1 ; for i in range(2,int(sqrt(n))+1): if(n % i==0): if(i*i!=n): sum=sum+i+n//i ; else : sum=sum+i ; if(sum==n and n!=1): return n ; return 0 ; def precomputation(): for i in range(1,10000): pref[i]=pref[i-1]+isPerfect(i); if __name__=="__main__" : L=6 ; R=28 ; precomputation(); print(pref[R]-pref[L-1]); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var pref : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10000); ; skip ; skip ; if __name__ = "__main__" then ( var L : int := 6; var R : int := 28; ; precomputation(); ; execute (pref[R+1] - pref[L - 1+1])->display(); ) else skip; operation isPerfect(n : OclAny) pre: true post: true activity: var sum : int := 1; ; for i : Integer.subrange(2, ("" + ((sqrt(n))))->toInteger() + 1-1) do ( if (n mod i = 0) then ( if (i * i /= n) then ( sum := sum + i + n div i; ) else ( sum := sum + i; ) ) else skip) ; if (sum = n & n /= 1) then ( return n; ) else skip ; return 0;; operation precomputation() pre: true post: true activity: for i : Integer.subrange(1, 10000-1) do ( pref[i+1] := pref[i - 1+1] + isPerfect(i);); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout def solve(): x=list(input()) n=len(x) twoDigit=None oneDigit=None x[0]=int(x[0]) for i in range(1,n): x[i]=int(x[i]) if x[i]+x[i-1]>=10 : twoDigit=i elif 0<=x[i]+x[i-1]<10 and not oneDigit : oneDigit=i ignore=-1 if twoDigit : n=x[twoDigit]+x[twoDigit-1] n=str(n) x[twoDigit-1]=n[0] x[twoDigit]=n[1] elif oneDigit : n=x[oneDigit]+x[oneDigit-1] ignore=oneDigit x[oneDigit-1]=n for i in range(len(x)): if i!=ignore : stdout.write(str(x[i])) stdout.write('\n') for tc in range(int(input())): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for tc : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve()); operation solve() pre: true post: true activity: var x : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var n : int := (x)->size() ; var twoDigit : OclAny := null ; var oneDigit : OclAny := null ; x->first() := ("" + ((x->first())))->toInteger() ; for i : Integer.subrange(1, n-1) do ( x[i+1] := ("" + ((x[i+1])))->toInteger() ; if x[i+1] + x[i - 1+1] >= 10 then ( twoDigit := i ) else (if 0 <= x[i+1] + x[i - 1+1] & (x[i+1] + x[i - 1+1] < 10) & not(oneDigit) then ( oneDigit := i ) else skip)) ; var ignore : int := -1 ; if twoDigit then ( n := x[twoDigit+1] + x[twoDigit - 1+1] ; n := ("" + ((n))) ; x[twoDigit - 1+1] := n->first() ; x[twoDigit+1] := n[1+1] ) else (if oneDigit then ( n := x[oneDigit+1] + x[oneDigit - 1+1] ; ignore := oneDigit ; x[oneDigit - 1+1] := n ) else skip) ; for i : Integer.subrange(0, (x)->size()-1) do ( if i /= ignore then ( stdout.write(("" + ((x[i+1])))) ) else skip) ; stdout.write(' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : s=list(input()) s.reverse() q=1 for i in range(1,len(s)): if(int(s[i])+int(s[i-1]))>9 : s[i],s[i-1]=str(int(s[i])+int(s[i-1]))[0],str(int(s[i])+int(s[i-1]))[1] q=0 break s.reverse() if q==0 : pass if q : r=str(int(s[0])+int(s[1])) s[0],s[1]=r,'' print(''.join(s)) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; s := s->reverse() ; var q : int := 1 ; for i : Integer.subrange(1, (s)->size()-1) do ( if (("" + ((s[i+1])))->toInteger() + ("" + ((s[i - 1+1])))->toInteger()) > 9 then ( var s[i+1] : OclAny := null; var s[i - 1+1] : OclAny := null; Sequence{s[i+1],s[i - 1+1]} := Sequence{OclType["String"](("" + ((s[i+1])))->toInteger() + ("" + ((s[i - 1+1])))->toInteger())->first(),OclType["String"](("" + ((s[i+1])))->toInteger() + ("" + ((s[i - 1+1])))->toInteger())[1+1]} ; q := 0 ; break ) else skip) ; s := s->reverse() ; if q = 0 then ( skip ) else skip ; if q then ( var r : String := ("" + ((("" + ((s->first())))->toInteger() + ("" + ((s[1+1])))->toInteger()))) ; var s->first() : OclAny := null; var s[1+1] : OclAny := null; Sequence{s->first(),s[1+1]} := Sequence{r,''} ) else skip ; execute (StringLib.sumStringsWithSeparator((s), ''))->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout def solve(): x=list(input()) n=len(x) twoDigit=None oneDigit=None x[0]=int(x[0]) for i in range(1,n): x[i]=int(x[i]) if x[i]+x[i-1]>=10 : twoDigit=i elif 1<=x[i]+x[i-1]<10 and not oneDigit : oneDigit=i ignore=-1 if twoDigit : n=x[twoDigit]+x[twoDigit-1] n=str(n) x[twoDigit-1]=n[0] x[twoDigit]=n[1] elif oneDigit : n=x[oneDigit]+x[oneDigit-1] ignore=oneDigit x[oneDigit-1]=n for i in range(len(x)): if i!=ignore : stdout.write(str(x[i])) stdout.write('\n') for tc in range(int(input())): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for tc : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve()); operation solve() pre: true post: true activity: var x : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var n : int := (x)->size() ; var twoDigit : OclAny := null ; var oneDigit : OclAny := null ; x->first() := ("" + ((x->first())))->toInteger() ; for i : Integer.subrange(1, n-1) do ( x[i+1] := ("" + ((x[i+1])))->toInteger() ; if x[i+1] + x[i - 1+1] >= 10 then ( twoDigit := i ) else (if 1 <= x[i+1] + x[i - 1+1] & (x[i+1] + x[i - 1+1] < 10) & not(oneDigit) then ( oneDigit := i ) else skip)) ; var ignore : int := -1 ; if twoDigit then ( n := x[twoDigit+1] + x[twoDigit - 1+1] ; n := ("" + ((n))) ; x[twoDigit - 1+1] := n->first() ; x[twoDigit+1] := n[1+1] ) else (if oneDigit then ( n := x[oneDigit+1] + x[oneDigit - 1+1] ; ignore := oneDigit ; x[oneDigit - 1+1] := n ) else skip) ; for i : Integer.subrange(0, (x)->size()-1) do ( if i /= ignore then ( stdout.write(("" + ((x[i+1])))) ) else skip) ; stdout.write(' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout def solve(): x=list(input()) n=len(x) twoDigit=None oneDigit=None x[0]=int(x[0]) for i in range(1,n): x[i]=int(x[i]) if x[i]+x[i-1]>=10 : twoDigit=i elif 0<=x[i]+x[i-1]<10 and not oneDigit : oneDigit=i ignore=-1 if twoDigit : n=x[twoDigit]+x[twoDigit-1] n=str(n) x[twoDigit-1]=n[0] x[twoDigit]=n[1] elif oneDigit : n=x[oneDigit]+x[oneDigit-1] ignore=oneDigit x[oneDigit-1]=n for i in range(len(x)): if i!=ignore : stdout.write(str(x[i])) stdout.write('\n') for tc in range(int(input())): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for tc : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve()); operation solve() pre: true post: true activity: var x : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var n : int := (x)->size() ; var twoDigit : OclAny := null ; var oneDigit : OclAny := null ; x->first() := ("" + ((x->first())))->toInteger() ; for i : Integer.subrange(1, n-1) do ( x[i+1] := ("" + ((x[i+1])))->toInteger() ; if x[i+1] + x[i - 1+1] >= 10 then ( twoDigit := i ) else (if 0 <= x[i+1] + x[i - 1+1] & (x[i+1] + x[i - 1+1] < 10) & not(oneDigit) then ( oneDigit := i ) else skip)) ; var ignore : int := -1 ; if twoDigit then ( n := x[twoDigit+1] + x[twoDigit - 1+1] ; n := ("" + ((n))) ; x[twoDigit - 1+1] := n->first() ; x[twoDigit+1] := n[1+1] ) else (if oneDigit then ( n := x[oneDigit+1] + x[oneDigit - 1+1] ; ignore := oneDigit ; x[oneDigit - 1+1] := n ) else skip) ; for i : Integer.subrange(0, (x)->size()-1) do ( if i /= ignore then ( stdout.write(("" + ((x[i+1])))) ) else skip) ; stdout.write(' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=list(input()) c=0 for i in range(0,n,2): if s[i]==s[i+1]: s[i]="b" s[i+1]="a" c+=1 print(c) print("".join(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var c : int := 0 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( if s[i+1] = s[i + 1+1] then ( s[i+1] := "b" ; s[i + 1+1] := "a" ; c := c + 1 ) else skip) ; execute (c)->display() ; execute (StringLib.sumStringsWithSeparator((s), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solver(object): @ classmethod def setup(cls,infile): cls.data={} def __init__(self,infile,tc): self.tc=tc self.I=I=map(int,infile.next().split()) def solve(self): JJ=J=self.I[1 :] X=float(sum(J)) win=[] lw=-1 while len(win)>lw : lw=len(win) win.extend([j for j in J if j>((X+sum(J))/len(J))]) J=[j for j in J if j<=((X+sum(J))/len(J))] res=dict((w,0.)for w in win) for j in J : res[j]=((X+sum(J))/len(J)-j)/X*100. return 'Case #%s: %s\n' %(self.tc,' '.join('%f' % res[j]for j in JJ)) if __name__=='__main__' : import sys T=int(sys.stdin.next()) Solver.setup(sys.stdin) for t in xrange(1,T+1): sys.stdout.write(Solver(sys.stdin,t).solve()) ------------------------------------------------------------ OCL File: --------- class Solver extends object { static operation newSolver() : Solver pre: true post: Solver->exists( _x | result = _x ); attribute tc : OclAny := tc; attribute I : OclAny := (infile.next().split())->collect( _x | (OclType["int"])->apply(_x) ); var I : Sequence := (infile.next().split())->collect( _x | (OclType["int"])->apply(_x) ); operation initialise(infile : OclAny,tc : OclAny) : pre: true post: true activity: self.tc := tc ; self.I := (infile.next().split())->collect( _x | (OclType["int"])->apply(_x) ); var I : Sequence := (infile.next().split())->collect( _x | (OclType["int"])->apply(_x) ); return self; operation solve() : OclAny pre: true post: true activity: var JJ : OclAny := self.I->tail(); var J : OclAny := self.I->tail() ; var X : double := ("" + (((J)->sum())))->toReal() ; var win : Sequence := Sequence{} ; var lw : int := -1 ; while ((win)->size()->compareTo(lw)) > 0 do ( lw := (win)->size() ; win := win->union(J->select(j | (j->compareTo(((X + (J)->sum()) / (J)->size()))) > 0)->collect(j | (j))) ; J := J->select(j | (j->compareTo(((X + (J)->sum()) / (J)->size()))) <= 0)->collect(j | (j))) ; var res : Map := ((argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name w)))))) , (test (logical_test (comparison (expr (atom (number 0.))))))) )))))) (comp_for for (exprlist (expr (atom (name w)))) in (logical_test (comparison (expr (atom (name win)))))))) ; for j : J do ( res[j+1] := ((X + (J)->sum()) / (J)->size() - j) / X * 100.) ; return StringLib.format('Case #%s: %s ',Sequence{self.tc, StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (expr (atom '%f')) % (expr (atom (name res)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name JJ)))))))), ' ')}); } class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( skip ; var T : int := ("" + (((OclFile["System.in"]).next())))->toInteger() ; Solver.setup(OclFile["System.in"]) ; for t : xrange(1, T + 1) do ((expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name Solver)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin))))))) , (argument (test (logical_test (comparison (expr (atom (name t)))))))) ))) (trailer . (name solve) (arguments ( ))))))))) ))))) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def readline_ints(): return[int(num)for num in fin.readline().strip().split()] from collections import Counter def tideline(scores,X): cc=Counter(scores) floating=0 for score in range(max(scores)+1): floating+=cc[score] if floating>X : break X-=floating else : score+=1 return score+X/floating def find_min_vote_proportions(scores): X=sum(scores) points_limit=tideline(scores,X) print(points_limit) proportions_needed=[] for s in scores : if s>=points_limit : proportions_needed.append(0.0) else : points_needed=points_limit-s proportions_needed.append(100*points_needed/X) return proportions_needed fname="A-large" with open(fname+".in","r")as fin,open(fname+".out","w")as fout : numcases=readline_ints()[0] print(numcases,"cases") for caseno in range(1,numcases+1): N,*scores=readline_ints() result=find_min_vote_proportions(scores) result_str=" ".join("%f" % p for p in result) outstr="Case #%d: %s" %(caseno,result_str) fout.write(outstr+"\n") print(outstr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var fname : String := "A-large" ; try (var fin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(fname + ".in")); var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(fname + ".out")); var numcases : OclAny := readline_ints()->first() ; execute (numcases)->display() ; for caseno : Integer.subrange(1, numcases + 1-1) do ( var N : OclAny := null; var scores : OclAny := null; Sequence{N,scores} := readline_ints() ; var result : OclAny := find_min_vote_proportions(scores) ; var result_str : String := StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (expr (atom "%f")) % (expr (atom (name p))))))) (comp_for for (exprlist (expr (atom (name p)))) in (logical_test (comparison (expr (atom (name result)))))))), " ") ; var outstr : String := StringLib.format("Case #%d: %s",Sequence{caseno, result_str}) ; fout.write(outstr + "\n") ; execute (outstr)->display())) catch (_e : OclException) do skip; operation readline_ints() : OclAny pre: true post: true activity: return fin.readLine()->trim().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())); operation tideline(scores : OclAny, X : OclAny) : OclAny pre: true post: true activity: var cc : OclAny := Counter(scores) ; var floating : int := 0 ; (compound_stmt for (exprlist (expr (atom (name score)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name scores)))))))) )))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name floating)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name cc)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name score)))))))) ]))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name floating)))) > (comparison (expr (atom (name X))))))) : (suite (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name X)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (name floating)))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name score)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) ; return score + X / floating; operation find_min_vote_proportions(scores : OclAny) : OclAny pre: true post: true activity: X := (scores)->sum() ; var points_limit : OclAny := tideline(scores, X) ; execute (points_limit)->display() ; var proportions_needed : Sequence := Sequence{} ; for s : scores do ( if (s->compareTo(points_limit)) >= 0 then ( execute ((0.0) : proportions_needed) ) else ( var points_needed : double := points_limit - s ; execute ((100 * points_needed / X) : proportions_needed) )) ; return proportions_needed; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdout def fill(si,tot): for j in xrange(len(si)-1): if si[j]toInteger() ; for case : xrange(1, t + 1) do ( var s : OclAny := raw_input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))->tail() ; s := solve(s) ; stdout.write(StringLib.format("Case #%d:",case)) ; for a : s do ( stdout.write(StringLib.format(" %.10f",(a * 100.0)))) ; stdout.write("\n")); operation fill(si : OclAny, tot : OclAny) pre: true post: true activity: for j : xrange((si)->size() - 1) do ( if (si[j+1]->compareTo(si[j + 1+1])) < 0 then ( var diff : OclAny := Set{tot, (si[j + 1+1] - si[j+1]) * (j + 1)}->min() ; si[j+1] := si[j+1] + ("" + ((diff)))->toReal() / (j + 1) ; tot := tot - diff ; for k : xrange(0, j) do ( s[k+1] := s[j+1]) ; if tot <= 0.0 then ( break ) else skip ) else skip) ; diff := ("" + ((tot)))->toReal() / (si)->size() ; for k : xrange(0, (si)->size()) do ( si[k+1] := si[k+1] + diff); operation solve(si : OclAny) : OclAny pre: true post: true activity: var ans : Sequence := Sequence{} ; tot := (si)->sum() ; var xi : Sequence := Integer.subrange(1, (si)->size())->collect( _indx | Sequence{_indx-1, (si)->at(_indx)} )->select(_tuple | true)->collect(_tuple | let j : OclAny = _tuple->at(1) in let s : OclAny = _tuple->at(2) in (Sequence{s, j})) ; xi := xi->sort() ; si := si->sort() ; fill(si, tot) ; si := xrange((si)->size())->select(j | true)->collect(j | (Sequence{xi[j+1][1+1], ("" + ((si[j+1] - xi[j+1]->first())))->toReal() / tot})) ; si := si->sort() ; si := si->select(s | true)->collect(s | (s[1+1])) ; return si; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lds(arr,n): lds=[0 for i in range(n)] lds[0]=1 for i in range(n): lds[i]=1 for j in range(i): if(lds[j]!=0 and arr[i]% arr[j]==0): lds[i]=max(lds[i],lds[j]+1) return max(lds) arr=[2,11,16,12,36,60,71,17,29,144,288,129,432,993] print("Length of lds is",lds(arr,len(arr))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{11}->union(Sequence{16}->union(Sequence{12}->union(Sequence{36}->union(Sequence{60}->union(Sequence{71}->union(Sequence{17}->union(Sequence{29}->union(Sequence{144}->union(Sequence{288}->union(Sequence{129}->union(Sequence{432}->union(Sequence{ 993 }))))))))))))) ; execute ("Length of lds is")->display(); operation lds(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var lds : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; lds->first() := 1 ; for i : Integer.subrange(0, n-1) do ( lds[i+1] := 1 ; for j : Integer.subrange(0, i-1) do ( if (lds[j+1] /= 0 & arr[i+1] mod arr[j+1] = 0) then ( lds[i+1] := Set{lds[i+1], lds[j+1] + 1}->max() ) else skip)) ; return (lds)->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout l=[int(x)for x in stdin.readline().split()] n,d,lx=l l1=list() flag=0 for i in range(n): l1.append(1) s_o=sum(l1[0 : : 2]) s_e=sum(l1)-s_o if(d<0): i=1 elif(d>0): i=0 elif(d==0 and n % 2): i=n-2 while(s_o-s_e!=d and l1[i]select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var n : OclAny := null; var d : OclAny := null; var lx : OclAny := null; Sequence{n,d,lx} := l ; var l1 : Sequence := () ; var flag : int := 0 ; for i : Integer.subrange(0, n-1) do ( execute ((1) : l1)) ; var s_o : OclAny := (l1(subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->sum() ; var s_e : double := (l1)->sum() - s_o ; if (d < 0) then ( var i : int := 1 ) else (if (d > 0) then ( i := 0 ) else (if (d = 0 & n mod 2) then ( i := n - 2 ) else skip ) ) ; while (s_o - s_e /= d & (l1[i+1]->compareTo(lx)) < 0) do ( if ((l1[i+1]->compareTo(lx)) < 0) then ( flag := 1 ; l1[i+1] := l1[i+1] + 1 ; if (i mod 2) then ( s_e := s_e + 1 ) else ( s_o := s_o + 1 ) ) else skip ; if (s_o - s_e = d) then ( break ) else skip ; if (l1[i+1] = lx & ((i + 2)->compareTo(n - 1)) <= 0) then ( i := i + 2 ) else skip) ; if (s_o - s_e /= d) then ( execute (-1)->display() ) else ( for i : l1 do ( execute (i)->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : R0,W0,C,R=map(int,input().split()) if R0+W0+C+R==0 : break n=0 while True : if(n*R+R0)/W0>=C : break n+=1 print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var R0 : OclAny := null; var W0 : OclAny := null; var C : OclAny := null; var R : OclAny := null; Sequence{R0,W0,C,R} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if R0 + W0 + C + R = 0 then ( break ) else skip ; var n : int := 0 ; while true do ( if ((n * R + R0) / W0->compareTo(C)) >= 0 then ( break ) else skip ; n := n + 1) ; execute (n)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from heapq import heappush,heappop import sys import math import bisect import random def LI(): return[int(x)for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return[list(x)for x in sys.stdin.readline().split()] def S(): return list(sys.stdin.readline())[:-1] def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] sys.setrecursionlimit(1000000) mod=1000000007 def solve(r0,w,c,r): c0=r0/w if c0>=c : print(0) return x=math.ceil((w*c-r0)/r) print(x) return if __name__=="__main__" : while 1 : r0,w,c,r=LI() if r0==w==c==r==0 : break solve(r0,w,c,r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1000000) ; var mod : int := 1000000007 ; skip ; if __name__ = "__main__" then ( while 1 do ( Sequence{r0,w,c,r} := LI() ; if r0 = w & (w == c) & (c == r) & (r == 0) then ( break ) else skip ; solve(r0, w, c, r)) ) else skip; operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | ((x))); operation S() : OclAny pre: true post: true activity: return OclType["Sequence"]((OclFile["System.in"]).readLine())->front(); operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation solve(r0 : OclAny, w : OclAny, c : OclAny, r : OclAny) pre: true post: true activity: var c0 : double := r0 / w ; if (c0->compareTo(c)) >= 0 then ( execute (0)->display() ; return ) else skip ; var x : double := ((w * c - r0) / r)->ceil() ; execute (x)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] while True : a,b,c,d=LI() if a==0 : break for r in range(10000): if 1.0*(a+d*r)/b>=c : rr.append(r) break return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := LI() ; if a = 0 then ( break ) else skip ; for r : Integer.subrange(0, 10000-1) do ( if (1.0 * (a + d * r) / b->compareTo(c)) >= 0 then ( execute ((r) : rr) ; break ) else skip)) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_four_int(): four_int=input().split() for i,v in enumerate(four_int): four_int[i]=int(v) return four_int def get_min_roux_num(initial_roux,initial_water,ideal_concentration,min_unit): roux=initial_roux min_roux_num=0 min_required_roux=initial_water*ideal_concentration while True : if roux>=min_required_roux : return min_roux_num roux+=min_unit min_roux_num+=1 if __name__=="__main__" : while True : initial_roux,initial_water,ideal_concentration,min_unit=get_four_int() if initial_roux==0 : break min_roux_num=get_min_roux_num(initial_roux,initial_water,ideal_concentration,min_unit) print(min_roux_num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( while true do ( Sequence{initial_roux,initial_water,ideal_concentration,min_unit} := get_four_int() ; if initial_roux = 0 then ( break ) else skip ; min_roux_num := get_min_roux_num(initial_roux, initial_water, ideal_concentration, min_unit) ; execute (min_roux_num)->display()) ) else skip; operation get_four_int() : OclAny pre: true post: true activity: var four_int : OclAny := input().split() ; for _tuple : Integer.subrange(1, (four_int)->size())->collect( _indx | Sequence{_indx-1, (four_int)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); four_int[i+1] := ("" + ((v)))->toInteger()) ; return four_int; operation get_min_roux_num(initial_roux : OclAny, initial_water : OclAny, ideal_concentration : OclAny, min_unit : OclAny) : OclAny pre: true post: true activity: var roux : OclAny := initial_roux ; var min_roux_num : int := 0 ; var min_required_roux : double := initial_water * ideal_concentration ; while true do ( if (roux->compareTo(min_required_roux)) >= 0 then ( return min_roux_num ) else skip ; roux := roux + min_unit ; min_roux_num := min_roux_num + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def main(): while True : r0,w0,c,r=map(int,input().split()) if not r0 and not w0 and not c and not r : return current=r0/w0 ans=0 if ccollect( _x | (OclType["int"])->apply(_x) ) ; if not(r0) & not(w0) & not(c) & not(r) then ( return ) else skip ; var current : double := r0 / w0 ; var ans : int := 0 ; if (c->compareTo(current)) < 0 then ( ans := 0 ) else ( ans := ((c * w0 - r0) / r)->ceil() ) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=list(input()) ans=0 for i in range(0,n,2): if s[i]==s[i+1]: if s[i]=='a' : s[i]='b' ans+=1 else : s[i]='a' ans+=1 print(ans) print(*s,sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var ans : int := 0 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( if s[i+1] = s[i + 1+1] then ( if s[i+1] = 'a' then ( s[i+1] := 'b' ; ans := ans + 1 ) else ( s[i+1] := 'a' ; ans := ans + 1 ) ) else skip) ; execute (ans)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name s))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def search(a,x): lo=0 hi=len(a) while hi>lo : mid=(lo+hi)//2 if a[mid]=len(a): print(-1) flag=1 for i in range(min(k+1,len(a))): v=search(b,a[i]+ta) if(v+k-i)>=m : if flag==0 : print(-1) flag=1 break z=max(z,b[v+k-i]+tb) if flag==0 : print(z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; var ta : OclAny := null; var tb : OclAny := null; var k : OclAny := null; Sequence{n,m,ta,tb,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var z : int := -1 ; var flag : int := 0 ; if (k->compareTo((a)->size())) >= 0 then ( execute (-1)->display() ; flag := 1 ) else skip ; for i : Integer.subrange(0, Set{k + 1, (a)->size()}->min()-1) do ( var v : OclAny := search(b, a[i+1] + ta) ; if ((v + k - i)->compareTo(m)) >= 0 then ( if flag = 0 then ( execute (-1)->display() ) else skip ; flag := 1 ; break ) else skip ; z := Set{z, b[v + k - i+1] + tb}->max()) ; if flag = 0 then ( execute (z)->display() ) else skip; operation search(a : OclAny, x : OclAny) : OclAny pre: true post: true activity: var lo : int := 0 ; var hi : int := (a)->size() ; while (hi->compareTo(lo)) > 0 do ( var mid : int := (lo + hi) div 2 ; if (a[mid+1]->compareTo(x)) < 0 then ( lo := mid + 1 ) else ( hi := mid )) ; return hi; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) n,m,ta,tb,k=R() arra,arrb=list(R()),list(R())+[10**10] j=0 res=0 for i in range(min(n,k+1)): while jarrb[j]: j+=1 bidx=min(m,k-i+j) res=max(res,arrb[bidx]+tb) print(res if res<3*10**9 and n>k else-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var m : OclAny := null; var ta : OclAny := null; var tb : OclAny := null; var k : OclAny := null; Sequence{n,m,ta,tb,k} := R->apply() ; var arra : OclAny := null; var arrb : OclAny := null; Sequence{arra,arrb} := Sequence{(R->apply())->characters(),(R->apply())->characters()->union(Sequence{ (10)->pow(10) })} ; var j : int := 0 ; var res : int := 0 ; for i : Integer.subrange(0, Set{n, k + 1}->min()-1) do ( while (j->compareTo(m)) < 0 & (arra[i+1] + ta->compareTo(arrb[j+1])) > 0 do ( j := j + 1) ; var bidx : OclAny := Set{m, k - i + j}->min() ; res := Set{res, arrb[bidx+1] + tb}->max()) ; execute (if (res->compareTo(3 * (10)->pow(9))) < 0 & (n->compareTo(k)) > 0 then res else -1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,heapq input=sys.stdin.readline n,m,ta,tb,k=map(int,input().split()) ab=list(map(int,input().split())) bc=list(map(int,input().split())) for i in range(n): ab[i]+=ta i=0 j=0 is_pos=True ans=-1 for x in range(k+1): while j=m or i>=n or not is_pos : is_pos=False ans=-1 continue else : ans=max(ans,bc[j+k-x]+tb) i+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; var ta : OclAny := null; var tb : OclAny := null; var k : OclAny := null; Sequence{n,m,ta,tb,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ab : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var bc : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( ab[i+1] := ab[i+1] + ta) ; var i : int := 0 ; var j : int := 0 ; var is_pos : boolean := true ; var ans : int := -1 ; for x : Integer.subrange(0, k + 1-1) do ( while (j->compareTo(m)) < 0 & (i->compareTo(n)) < 0 & (bc[j+1]->compareTo(ab[i+1])) < 0 do ( j := j + 1) ; if (j + k - x->compareTo(m)) >= 0 or (i->compareTo(n)) >= 0 or not(is_pos) then ( is_pos := false ; ans := -1 ; continue ) else ( ans := Set{ans, bc[j + k - x+1] + tb}->max() ) ; i := i + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,m,ta,tb,k=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) inf=2*pow(10,9)+1 a.append(inf) c1,c2=0,0 c=0 j=0 ans=-1 for i in b : c1+=1 while a[j]+ta<=i : j+=1 c2+=1 if not c2 : c1=0 continue if c2<=c1 : c+=c2 c1,c2=0,0 if c+c1>k : ans=i+tb break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; var ta : OclAny := null; var tb : OclAny := null; var k : OclAny := null; Sequence{n,m,ta,tb,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var Math_PINFINITY : double := 2 * (10)->pow(9) + 1 ; execute ((Math_PINFINITY) : a) ; var c1 : OclAny := null; var c2 : OclAny := null; Sequence{c1,c2} := Sequence{0,0} ; var c : int := 0 ; var j : int := 0 ; var ans : int := -1 ; for i : b do ( c1 := c1 + 1 ; while (a[j+1] + ta->compareTo(i)) <= 0 do ( j := j + 1 ; c2 := c2 + 1) ; if not(c2) then ( var c1 : int := 0 ; continue ) else skip ; if (c2->compareTo(c1)) <= 0 then ( c := c + c2 ; var c2 : OclAny := null; Sequence{c1,c2} := Sequence{0,0} ) else skip ; if (c + c1->compareTo(k)) > 0 then ( ans := i + tb ; break ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMissing(a,b,n,m): for i in range(n): for j in range(m): if(a[i]==b[j]): break if(j==m-1): print(a[i],end=" ") if __name__=="__main__" : a=[1,2,6,3,4,5] b=[2,4,3,1,0] n=len(a) m=len(b) findMissing(a,b,n,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{1}->union(Sequence{2}->union(Sequence{6}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 }))))) ; b := Sequence{2}->union(Sequence{4}->union(Sequence{3}->union(Sequence{1}->union(Sequence{ 0 })))) ; n := (a)->size() ; m := (b)->size() ; findMissing(a, b, n, m) ) else skip; operation findMissing(a : OclAny, b : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if (a[i+1] = b[j+1]) then ( break ) else skip) ; if (j = m - 1) then ( execute (a[i+1])->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[] n,d,l=list(map(int,input().split())) for i in range(1,n): if d<=0 : k=1 else : k=l a.append(k) d=k-d if 1<=d<=l : print(*a+[d]) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Sequence{} ; var n : OclAny := null; var d : OclAny := null; var l : OclAny := null; Sequence{n,d,l} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(1, n-1) do ( if d <= 0 then ( var k : int := 1 ) else ( k := l ) ; execute ((k) : a) ; var d : double := k - d) ; if 1 <= d & (d <= l) then ( execute ((argument * (test (logical_test (comparison (expr (expr (atom (name a))) + (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name d))))))) ]))))))))->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a,b=map(int,input().split()) c,d=map(int,input().split()) a-=1 b-=1 c-=1 d-=1 ans=10**3 for w in range(1,n+1): ax,ay=a % w,a//w bx,by=b % w,b//w cx,cy=c % w,c//w dx,dy=d % w,d//w ans=min(ans,abs(ax-bx)+abs(ay-by)+abs(cx-dx)+abs(cy-dy)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := a - 1 ; b := b - 1 ; c := c - 1 ; d := d - 1 ; var ans : double := (10)->pow(3) ; for w : Integer.subrange(1, n + 1-1) do ( var ax : OclAny := null; var ay : OclAny := null; Sequence{ax,ay} := Sequence{a mod w,a div w} ; var bx : OclAny := null; var by : OclAny := null; Sequence{bx,by} := Sequence{b mod w,b div w} ; var cx : OclAny := null; var cy : OclAny := null; Sequence{cx,cy} := Sequence{c mod w,c div w} ; var dx : OclAny := null; var dy : OclAny := null; Sequence{dx,dy} := Sequence{d mod w,d div w} ; ans := Set{ans, (ax - bx)->abs() + (ay - by)->abs() + (cx - dx)->abs() + (cy - dy)->abs()}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a,b=map(int,input().split()) c,d=map(int,input().split()) def get_dist(w,a,b): return sum(map(lambda x,y : abs(x-y),divmod(a,w),divmod(b,w))) print(min(get_dist(w,a-1,b-1)+get_dist(w,c-1,d-1)for w in range(1,n+1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; execute (((argument (test (logical_test (comparison (expr (expr (atom (name get_dist)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name w))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) )))) + (expr (atom (name get_dist)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name w))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name c))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name d))) - (expr (atom (number (integer 1)))))))))) )))))))) (comp_for for (exprlist (expr (atom (name w)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) )))))))))->min())->display(); operation get_dist(w : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return ((Sequence{(a div w), (a mod w)})->collect( _x | (lambda x : OclAny, y : OclAny in ((x - y)->abs()))->apply(_x) ))->sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a,b=map(int,input().split()) c,d=map(int,input().split()) a-=1 ; b-=1 ; c-=1 ; d-=1 def f(x,y,z): return abs(x//(z+1)-y//(z+1))+abs(x %(z+1)-y %(z+1)) print(min([f(a,b,i+1)+f(c,d,i+1)for i in range(n)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := a - 1; b := b - 1; c := c - 1; d := d - 1 ; skip ; execute ((Integer.subrange(0, n-1)->select(i | true)->collect(i | (f(a, b, i + 1) + f(c, d, i + 1))))->min())->display(); operation f(x : OclAny, y : OclAny, z : OclAny) : OclAny pre: true post: true activity: return (x div (z + 1) - y div (z + 1))->abs() + (x mod (z + 1) - y mod (z + 1))->abs(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkEquality(s): return(ord(s[0])==ord(s[len(s)-1])); def countSubstringWithEqualEnds(s): result=0 ; n=len(s); for i in range(n): for j in range(1,n-i+1): if(checkEquality(s[i : i+j])): result+=1 ; return result ; s="abcab" ; print(countSubstringWithEqualEnds(s)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; s := "abcab"; ; execute (countSubstringWithEqualEnds(s))->display();; operation checkEquality(s : OclAny) pre: true post: true activity: return ((s->first())->char2byte() = (s[(s)->size() - 1+1])->char2byte());; operation countSubstringWithEqualEnds(s : OclAny) pre: true post: true activity: var result : int := 0; ; var n : int := (s)->size(); ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(1, n - i + 1-1) do ( if (checkEquality(s.subrange(i+1, i + j))) then ( result := result + 1; ) else skip)) ; return result;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() a=0 b=2 c=0 w='' for _ in range(n//2): if s[a : b]not in['ab','ba']: c+=1 w+='ab' else : w+=s[a : b] a+=2 b+=2 print(c) print(w) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var a : int := 0 ; var b : int := 2 ; var c : int := 0 ; var w : String := '' ; for _anon : Integer.subrange(0, n div 2-1) do ( if (Sequence{'ab'}->union(Sequence{ 'ba' }))->excludes(s.subrange(a+1, b)) then ( c := c + 1 ; w := w + 'ab' ) else ( w := w + s.subrange(a+1, b) ) ; a := a + 2 ; b := b + 2) ; execute (c)->display() ; execute (w)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) b=list(map(int,input().split())) cnt=0 for i in range(n): j=i-1 while(j>=0): if b[j]>b[i]: cnt+=1 j+=-1 i+=-1 print(2*cnt-cnt % 2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( var j : double := i - 1 ; while (j >= 0) do ( if (b[j+1]->compareTo(b[i+1])) > 0 then ( cnt := cnt + 1 ) else skip ; j := j + -1) ; i := i + -1) ; execute (2 * cnt - cnt mod 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def merge_sort(a,l,r): res=0 if lselect(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var n : int := (a)->size() ; var ans : OclAny := merge_sort(a, 0, n - 1) ; if MathLib.bitwiseAnd(ans, 1) = 0 then ( ans := ans * 2 ) else ( ans := ans * 2 - 1 ) ; execute (ans)->display(); operation merge_sort(a : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; if (l->compareTo(r)) < 0 then ( var m : int := (l + r) div 2 ; res := res + merge_sort(a, l, m) ; res := res + merge_sort(a, m + 1, r) ; var i : OclAny := l ; var j : int := m + 1 ; var b : Sequence := Sequence{} ; while (i->compareTo(m)) <= 0 & (j->compareTo(r)) <= 0 do ( if (a[i+1]->compareTo(a[j+1])) <= 0 then ( execute ((a[i+1]) : b) ; i := i + 1 ) else ( execute ((a[j+1]) : b) ; j := j + 1 ; res := res + m - i + 1 )) ; while (i->compareTo(m)) <= 0 do ( execute ((a[i+1]) : b) ; i := i + 1) ; while (j->compareTo(r)) <= 0 do ( execute ((a[j+1]) : b) ; j := j + 1) ; for _tuple : Integer.subrange(1, (b)->size())->collect( _indx | Sequence{_indx-1, (b)->at(_indx)} ) do (var _indx : int := 1; var idx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var val : OclAny := _tuple->at(_indx); a[idx + l+1] := val) ) else skip ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def merge_sort(a,l,r): res=0 if lselect(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var n : int := (a)->size() ; var ans : OclAny := merge_sort(a, 0, n - 1) ; if MathLib.bitwiseAnd(ans, 1) = 0 then ( ans := ans * 2 ) else ( ans := ans * 2 - 1 ) ; execute (ans)->display(); operation merge_sort(a : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; if (l->compareTo(r)) < 0 then ( var m : int := (l + r) div 2 ; res := res + merge_sort(a, l, m) ; res := res + merge_sort(a, m + 1, r) ; var i : OclAny := l ; var j : int := m + 1 ; var b : Sequence := Sequence{} ; while (i->compareTo(m)) <= 0 & (j->compareTo(r)) <= 0 do ( if (a[i+1]->compareTo(a[j+1])) <= 0 then ( execute ((a[i+1]) : b) ; i := i + 1 ) else ( execute ((a[j+1]) : b) ; j := j + 1 ; res := res + m - i + 1 )) ; while (i->compareTo(m)) <= 0 do ( execute ((a[i+1]) : b) ; i := i + 1) ; while (j->compareTo(r)) <= 0 do ( execute ((a[j+1]) : b) ; j := j + 1) ; for _tuple : Integer.subrange(1, (b)->size())->collect( _indx | Sequence{_indx-1, (b)->at(_indx)} ) do (var _indx : int := 1; var idx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var val : OclAny := _tuple->at(_indx); a[idx + l+1] := val) ) else skip ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count(a): n=len(a) cnt=0 for i in range(n): for j in range(i+1,n): if a[i]>a[j]: cnt+=1 return cnt n=int(input()) p=list(map(int,input().split())) num=count(p) print(num*2-num % 2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var num : OclAny := count(p) ; execute (num * 2 - num mod 2)->display(); operation count(a : OclAny) : OclAny pre: true post: true activity: var n : int := (a)->size() ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if (a[i+1]->compareTo(a[j+1])) > 0 then ( cnt := cnt + 1 ) else skip)) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input().strip()) p=[0]+list(map(int,input().split())) c=[0]*(n+1) def lowbit(x): return x &(-x) def add(x,v): while x<=n : c[x]+=v x+=lowbit(x) def get(x): ans=0 while x : ans+=c[x] x-=lowbit(x) return ans ans=0 for i in range(n,0,-1): ans+=get(p[i]) add(p[i],1) if ans % 2 : print(2*ans-1) else : print(2*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + ((input()->trim())))->toInteger() ; var p : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var c : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; skip ; skip ; skip ; ans := 0 ; for i : Integer.subrange(0 + 1, n)->reverse() do ( ans := ans + get(p[i+1]) ; add(p[i+1], 1)) ; if ans mod 2 then ( execute (2 * ans - 1)->display() ) else ( execute (2 * ans)->display() ); operation lowbit(x : OclAny) : OclAny pre: true post: true activity: return MathLib.bitwiseAnd(x, (-x)); operation add(x : OclAny, v : OclAny) pre: true post: true activity: while (x->compareTo(n)) <= 0 do ( c[x+1] := c[x+1] + v ; x := x + lowbit(x)); operation get(x : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; while x do ( ans := ans + c[x+1] ; x := x - lowbit(x)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): x,y,a,b=map(int,input().split()) if(x-y)%(a+b): print('-1') else : print((y-x)//(a+b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{x,y,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (x - y) mod (a + b) then ( execute ('-1')->display() ) else ( execute ((y - x) div (a + b))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from sys import stdin,stdout def get_ints_in_variables(): return map(int,sys.stdin.readline().strip().split()) def get_int(): return int(input()) def get_ints_in_list(): return list(map(int,sys.stdin.readline().strip().split())) def get_list_of_list(n): return[list(map(int,sys.stdin.readline().strip().split()))for _ in range(n)] def get_string(): return sys.stdin.readline().strip() def main(): n,d,l=get_ints_in_variables() arr=[] for _ in range(0,n): arr.append(0) for i in range(0,n): if i & 1 : arr[i]=1 else : arr[i]=l mx_ans=0 start=n-1 while start>-1 : mx_ans=arr[start]-mx_ans start-=1 if d>mx_ans : print(-1) return else : for i in range(0,n): if mx_ans>d : if i & 1 : arr[i]+=min(l-1,mx_ans-d) mx_ans-=(arr[i]-1) else : arr[i]-=min(l-1,mx_ans-d) mx_ans-=(l-arr[i]) if mx_ans!=d : print(-1) else : for i in range(0,n): print(arr[i],end=" ") if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation get_ints_in_variables() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ); operation get_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation get_ints_in_list() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation get_list_of_list(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )))); operation get_string() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation main() pre: true post: true activity: var d : OclAny := null; var l : OclAny := null; Sequence{n,d,l} := get_ints_in_variables() ; var arr : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((0) : arr)) ; for i : Integer.subrange(0, n-1) do ( if MathLib.bitwiseAnd(i, 1) then ( arr[i+1] := 1 ) else ( arr[i+1] := l )) ; var mx_ans : int := 0 ; var start : double := n - 1 ; while start > -1 do ( mx_ans := arr[start+1] - mx_ans ; start := start - 1) ; if (d->compareTo(mx_ans)) > 0 then ( execute (-1)->display() ; return ) else ( for i : Integer.subrange(0, n-1) do ( if (mx_ans->compareTo(d)) > 0 then ( if MathLib.bitwiseAnd(i, 1) then ( arr[i+1] := arr[i+1] + Set{l - 1, mx_ans - d}->min() ; mx_ans := mx_ans - (arr[i+1] - 1) ) else ( arr[i+1] := arr[i+1] - Set{l - 1, mx_ans - d}->min() ; mx_ans := mx_ans - (l - arr[i+1]) ) ) else skip) ) ; if mx_ans /= d then ( execute (-1)->display() ) else ( for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): x,y,a,b=map(int,input().split()) p=y-x q=a+b if p % q==0 : print(p//q) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{x,y,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : double := y - x ; var q : OclAny := a + b ; if p mod q = 0 then ( execute (p div q)->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): x,y,a,b=map(int,input().split(" ")) if x>y : print(-1) continue if abs(x-y)%(a+b)==0 : print(int(abs(x-y)/(a+b))) else : print("-1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var x : OclAny := null; var y : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{x,y,a,b} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; if (x->compareTo(y)) > 0 then ( execute (-1)->display() ; continue ) else skip ; if (x - y)->abs() mod (a + b) = 0 then ( execute (("" + (((x - y)->abs() / (a + b))))->toInteger())->display() ) else ( execute ("-1")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(x,y,a,b): if(y-x)%(a+b)==0 : print(int((y-x)/(a+b))) return 0 else : print(-1) return 0 row=int(input()) for c in range(row): l1=input().split(' ') x=int(l1[0]) y=int(l1[1]) a=int(l1[2]) b=int(l1[3]) f(x,y,a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var row : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for c : Integer.subrange(0, row-1) do ( var l1 : OclAny := input().split(' ') ; x := ("" + ((l1->first())))->toInteger() ; y := ("" + ((l1[1+1])))->toInteger() ; a := ("" + ((l1[2+1])))->toInteger() ; b := ("" + ((l1[3+1])))->toInteger() ; f(x, y, a, b)); operation f(x : OclAny, y : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (y - x) mod (a + b) = 0 then ( execute (("" + (((y - x) / (a + b))))->toInteger())->display() ; return 0 ) else ( execute (-1)->display() ; return 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() s=input() cnt=0 new_s='' for i in range(0,len(s),2): if s[i]==s[i+1]: if s[i]=='a' : new_s+='ba' elif s[i]=='b' : new_s+='ab' cnt+=1 else : new_s+=s[i : i+2] print(cnt) print(new_s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var s : String := (OclFile["System.in"]).readLine() ; var cnt : int := 0 ; var new_s : String := '' ; for i : Integer.subrange(0, (s)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( if s[i+1] = s[i + 1+1] then ( if s[i+1] = 'a' then ( new_s := new_s + 'ba' ) else (if s[i+1] = 'b' then ( new_s := new_s + 'ab' ) else skip) ; cnt := cnt + 1 ) else ( new_s := new_s + s.subrange(i+1, i + 2) )) ; execute (cnt)->display() ; execute (new_s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x,y,a,b=map(int,input().split()) if(y-x)%(b+a)==0 : print((y-x)//(a+b)) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{x,y,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (y - x) mod (b + a) = 0 then ( execute ((y - x) div (a + b))->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) l1=[] l2=[] l3=[] l4=[] for k in range(t): n,m,i,j=map(int,input().split()) l1.append(n) l2.append(m) l3.append(i) l4.append(j) for i in range(len(l1)): print(1,1,l1[i],l2[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l1 : Sequence := Sequence{} ; var l2 : Sequence := Sequence{} ; var l3 : Sequence := Sequence{} ; var l4 : Sequence := Sequence{} ; for k : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; var i : OclAny := null; var j : OclAny := null; Sequence{n,m,i,j} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((n) : l1) ; execute ((m) : l2) ; execute ((i) : l3) ; execute ((j) : l4)) ; for i : Integer.subrange(0, (l1)->size()-1) do ( execute (1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m,i,j=map(int,input().split()) print(1,1,n,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; var i : OclAny := null; var j : OclAny := null; Sequence{n,m,i,j} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math def get_dist(x1,y1,x2,y2): return abs(x1-x2)+abs(y1-y2) tc=int(sys.stdin.readline()) for _ in range(tc): n,m,x,y=map(int,sys.stdin.readline().split()) dist1=get_dist(x,y,n,1)+get_dist(n,1,1,m)+get_dist(1,m,x,y) dist2=get_dist(x,y,1,1)+get_dist(1,1,n,m)+get_dist(n,m,x,y) if dist1>dist2 : print(n,1,1,m) else : print(1,1,n,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var tc : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, tc-1) do ( var n : OclAny := null; var m : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,m,x,y} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dist1 : OclAny := get_dist(x, y, n, 1) + get_dist(n, 1, 1, m) + get_dist(1, m, x, y) ; var dist2 : OclAny := get_dist(x, y, 1, 1) + get_dist(1, 1, n, m) + get_dist(n, m, x, y) ; if (dist1->compareTo(dist2)) > 0 then ( execute (n)->display() ) else ( execute (1)->display() )); operation get_dist(x1 : OclAny, y1 : OclAny, x2 : OclAny, y2 : OclAny) : OclAny pre: true post: true activity: return (x1 - x2)->abs() + (y1 - y2)->abs(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(): m,n,x,y=map(int,input().split()) if(m==1 and n==1)and(x==1 and y==1): print("1 1 1 1") return if((m==1)or n==1): if(x==1 or y==1): print("1 1{}{}".format(m,n)) else : print(1,n,m,1) t=int(input()) while(t!=0): solve() t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (t /= 0) do ( solve() ; t := t - 1); operation solve() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{m,n,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (m = 1 & n = 1) & (x = 1 & y = 1) then ( execute ("1 1 1 1")->display() ; return ) else skip ; if ((m = 1) or n = 1) then ( if (x = 1 or y = 1) then ( execute (StringLib.interpolateStrings("1 1{}{}", Sequence{m, n}))->display() ) else skip ) else ( execute (1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,m,a,b=map(int,input().split()) print(1,1,n,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,m,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(X): res=0 if X % 4 in[1,2]: res+=1 p=4 for i in range(50): if X % p>=p//2 and(X % p-p//2+1)% 2==1 : res+=2**(i+1) p*=2 return res A,B=map(int,input().split()) if A==0 : print(f(B)) else : print(f(B)^ f(A-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if A = 0 then ( execute (f(B))->display() ) else ( execute (MathLib.bitwiseXor(f(B), f(A - 1)))->display() ); operation f(X : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; if (Sequence{1}->union(Sequence{ 2 }))->includes(X mod 4) then ( res := res + 1 ) else skip ; var p : int := 4 ; for i : Integer.subrange(0, 50-1) do ( if (X mod p->compareTo(p div 2)) >= 0 & (X mod p - p div 2 + 1) mod 2 = 1 then ( res := res + (2)->pow((i + 1)) ) else skip ; p := p * 2) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def foo(v): sign=1 ret=0 for x in v : ret+=x*sign sign*=-1 return ret def go(n,d,l): nplus=(n+1)//2 nminus=n-nplus maxval=l*nplus-nminus minval=nplus-l*nminus if dmaxval : return(-1,) ret=[1]*n for i in range(n): val=foo(ret) if vald and i % 2==1 : ret[i]+=min(l-1,val-d) return ret print(" ".join(str(a)for a in go(*(int(x)for x in input().split(" "))))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name go)) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " "))))))) )))))))) )))))))) ))))))))), " "))->display(); operation foo(v : OclAny) : OclAny pre: true post: true activity: var sign : int := 1 ; var ret : int := 0 ; for x : v do ( ret := ret + x * sign ; sign := sign * -1) ; return ret; operation go(n : OclAny, d : OclAny, l : OclAny) : OclAny pre: true post: true activity: var nplus : int := (n + 1) div 2 ; var nminus : double := n - nplus ; var maxval : double := l * nplus - nminus ; var minval : double := nplus - l * nminus ; if (d->compareTo(minval)) < 0 or (d->compareTo(maxval)) > 0 then ( return Sequence{(testlist_comp (test (logical_test (comparison (expr (atom - (number (integer 1))))))) ,)} ) else skip ; ret := MatrixLib.elementwiseMult(Sequence{ 1 }, n) ; for i : Integer.subrange(0, n-1) do ( var val : OclAny := foo(ret) ; if (val->compareTo(d)) < 0 & i mod 2 = 0 then ( ret[i+1] := ret[i+1] + Set{l - 1, d - val}->min() ) else skip ; if (val->compareTo(d)) > 0 & i mod 2 = 1 then ( ret[i+1] := ret[i+1] + Set{l - 1, val - d}->min() ) else skip) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- printn=lambda x : print(x,end='') inn=lambda : int(input()) inl=lambda : list(map(int,input().split())) inm=lambda : map(int,input().split()) ins=lambda : input().strip() DBG=True BIG=10**18 R=10**9+7 def ddprint(x): if DBG : print(x) a,b=inm() s=[1 if(a % 4,b % 4)in[(0,1),(0,2),(1,1),(1,2),(2,3),(2,0),(3,3),(3,0)]else 0] for i in range(1,44): bit=1<display()) ; var inn : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var inl : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var inm : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ins : Function := lambda $$ : OclAny in (input()->trim()) ; var DBG : boolean := true ; var BIG : double := (10)->pow(18) ; var R : double := (10)->pow(9) + 7 ; skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := inm->apply() ; var s : Sequence := Sequence{ if (Sequence{Sequence{0, 1}}->union(Sequence{Sequence{0, 2}}->union(Sequence{Sequence{1, 1}}->union(Sequence{Sequence{1, 2}}->union(Sequence{Sequence{2, 3}}->union(Sequence{Sequence{2, 0}}->union(Sequence{Sequence{3, 3}}->union(Sequence{ Sequence{3, 0} }))))))))->includes(Sequence{a mod 4, b mod 4}) then 1 else 0 endif } ; for i : Integer.subrange(1, 44-1) do ( var bit : int := 1 * (2->pow(i)) ; var aa : int := if MathLib.bitwiseAnd(a, bit) = 0 then 0 else a mod 2 endif ; var bb : int := if MathLib.bitwiseAnd(b, bit) = 0 then 0 else (b + 1) mod 2 endif ; execute (((aa + bb) mod 2) : s)) ; execute ((Integer.subrange(0, (s)->size()-1)->select(i | true)->collect(i | (s[i+1] * (2)->pow(i))))->sum())->display(); operation ddprint(x : OclAny) pre: true post: true activity: if DBG then ( execute (x)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B=map(int,input().split()) A-=1 if A % 4==1 : A=1 elif A % 4==2 : A+=1 elif A % 4==3 : A=0 if B % 4==1 : B=1 elif B % 4==2 : B+=1 elif B % 4==3 : B=0 answer=A ^ B print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; A := A - 1 ; if A mod 4 = 1 then ( var A : int := 1 ) else (if A mod 4 = 2 then ( A := A + 1 ) else (if A mod 4 = 3 then ( A := 0 ) else skip ) ) ; if B mod 4 = 1 then ( var B : int := 1 ) else (if B mod 4 = 2 then ( B := B + 1 ) else (if B mod 4 = 3 then ( B := 0 ) else skip ) ) ; var answer : int := MathLib.bitwiseXor(A, B) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import log2 discard_count=0 def power(a,n): if(n==0): return 1 p=power(a,n//2) p=p*p if(n & 1): p=p*a return p def solve(i,n,sum,k,a,prefix): global discard_count if(sum>k): discard_count+=power(2,n-i) return ; if(i==n): return rem=prefix[n-1]-prefix[i] if(sum+a[i]+rem>k): solve(i+1,n,sum+a[i],k,a,prefix) if(sum+rem>k): solve(i+1,n,sum,k,a,prefix) def countSubsequences(arr,n,K): sum=0.0 k=log2(K) prefix=[0]*n a=[0]*n for i in range(n): a[i]=log2(arr[i]) sum+=a[i] prefix[0]=a[0] for i in range(1,n): prefix[i]=prefix[i-1]+a[i] total=power(2,n)-1 if(sum<=k): return total solve(0,n,0.0,k,a,prefix) return total-discard_count if __name__=="__main__" : arr=[4,8,7,2] n=len(arr) k=50 ; print(countSubsequences(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute discard_count : OclAny; operation initialise() pre: true post: true activity: skip ; var discard_count : int := 0 ; skip ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{4}->union(Sequence{8}->union(Sequence{7}->union(Sequence{ 2 }))) ; n := (arr)->size() ; k := 50; ; execute (countSubsequences(arr, n, k))->display() ) else skip; operation power(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return 1 ) else skip ; var p : OclAny := power(a, n div 2) ; p := p * p ; if (MathLib.bitwiseAnd(n, 1)) then ( p := p * a ) else skip ; return p; operation solve(i : OclAny, n : OclAny, sum : OclAny, k : OclAny, a : OclAny, prefix : OclAny) : OclAny pre: true post: true activity: skip ; if ((sum->compareTo(k)) > 0) then ( discard_count := discard_count + power(2, n - i) ; return; ) else skip ; if (i = n) then ( return ) else skip ; var rem : double := prefix[n - 1+1] - prefix[i+1] ; if ((sum + a[i+1] + rem->compareTo(k)) > 0) then ( solve(i + 1, n, sum + a[i+1], k, a, prefix) ) else skip ; if ((sum + rem->compareTo(k)) > 0) then ( solve(i + 1, n, sum, k, a, prefix) ) else skip; operation countSubsequences(arr : OclAny, n : OclAny, K : OclAny) : OclAny pre: true post: true activity: sum := 0.0 ; k := log2(K) ; prefix := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; a := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( a[i+1] := log2(arr[i+1]) ; sum := sum + a[i+1]) ; prefix->first() := a->first() ; for i : Integer.subrange(1, n-1) do ( prefix[i+1] := prefix[i - 1+1] + a[i+1]) ; var total : double := power(2, n) - 1 ; if ((sum->compareTo(k)) <= 0) then ( return total ) else skip ; solve(0, n, 0.0, k, a, prefix) ; return total - discard_count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.readline().strip() def I(): return int(input()) def LI(): return list(map(int,input().split())) def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def S(): return input() def LS(): return input().split() INF=float('inf') def ruiseki_xor(n): if n % 2!=0 : if(n+1)//2 % 2==0 : return 0 else : return 1 return ruiseki_xor(n+1)^(n+1) a,b=LI() ans=ruiseki_xor(b)^ ruiseki_xor(a-1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var INF : double := ("" + (('inf')))->toReal() ; skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := LI() ; var ans : int := MathLib.bitwiseXor(ruiseki_xor(b), ruiseki_xor(a - 1)) ; execute (ans)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation LS() : OclAny pre: true post: true activity: return input().split(); operation ruiseki_xor(n : OclAny) : OclAny pre: true post: true activity: if n mod 2 /= 0 then ( if (n + 1) div 2 mod 2 = 0 then ( return 0 ) else ( return 1 ) ) else skip ; return MathLib.bitwiseXor(ruiseki_xor(n + 1), (n + 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=[int(item)for item in input().split()] ans=0 for i in range(4-a % 4): ans ^=a+i for j in range(b % 4+1): ans ^=b-j print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; var ans : int := 0 ; for i : Integer.subrange(0, 4 - a mod 4-1) do ( ans := ans xor a + i) ; for j : Integer.subrange(0, b mod 4 + 1-1) do ( ans := ans xor b - j) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isMember(a,d,x): if d==0 : return x==a return((x-a)% d==0 & int((x-a)/d)>=0) a=1 x=7 d=3 if isMember(a,d,x): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 1 ; x := 7 ; d := 3 ; if isMember(a, d, x) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isMember(a : OclAny, d : OclAny, x : OclAny) : OclAny pre: true post: true activity: if d = 0 then ( return x = a ) else skip ; return ((x - a) mod d = MathLib.bitwiseAnd(0, ("" + (((x - a) / d)))->toInteger()) & (MathLib.bitwiseAnd(0, ("" + (((x - a) / d)))->toInteger()) >= 0)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def resultSur97(x): return x %(1000000000+7) if __name__=='__main__' : n=int(input()) x=n aList=[list(map(int,input().split()))for _ in range(x)] zmin=aList[0][0]+aList[0][1] zmax=aList[0][0]+aList[0][1] wmin=aList[0][0]-aList[0][1] wmax=aList[0][0]-aList[0][1] for i in range(len(aList)): x=aList[i][0] y=aList[i][1] z=x+y w=x-y if zzmax : zmax=z if wwmax : wmax=w disMax=max(zmax-zmin,wmax-wmin) print("{}".format(disMax)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; x := n ; var aList : Sequence := Integer.subrange(0, x-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var zmin : OclAny := aList->first()->first() + aList->first()[1+1] ; var zmax : OclAny := aList->first()->first() + aList->first()[1+1] ; var wmin : double := aList->first()->first() - aList->first()[1+1] ; var wmax : double := aList->first()->first() - aList->first()[1+1] ; for i : Integer.subrange(0, (aList)->size()-1) do ( x := aList[i+1]->first() ; var y : OclAny := aList[i+1][1+1] ; var z : OclAny := x + y ; var w : double := x - y ; if (z->compareTo(zmin)) < 0 then ( zmin := z ) else skip ; if (z->compareTo(zmax)) > 0 then ( zmax := z ) else skip ; if (w->compareTo(wmin)) < 0 then ( wmin := w ) else skip ; if (w->compareTo(wmax)) > 0 then ( wmax := w ) else skip) ; var disMax : OclAny := Set{zmax - zmin, wmax - wmin}->max() ; execute (StringLib.interpolateStrings("{}", Sequence{disMax}))->display() ) else skip; operation resultSur97(x : OclAny) : OclAny pre: true post: true activity: return x mod (1000000000 + 7); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) XY=[list(map(int,input().split()))for _ in range(N)] def measure(originX,originY): origin=[originX,originY] XY.sort(key=lambda x : abs(x[0]-origin[0])+abs(x[1]-origin[1])) return abs(XY[-1][0]-origin[0])+abs(XY[-1][1]-origin[1])-(abs(XY[0][0]-origin[0])+abs(XY[0][1]-origin[1])) ans=0 ans=max(ans,measure(1,1)) ans=max(ans,measure(1,10**9)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var XY : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; skip ; var ans : int := 0 ; ans := Set{ans, measure(1, 1)}->max() ; ans := Set{ans, measure(1, (10)->pow(9))}->max() ; execute (ans)->display(); operation measure(originX : OclAny, originY : OclAny) : OclAny pre: true post: true activity: var origin : Sequence := Sequence{originX}->union(Sequence{ originY }) ; XY := XY->sort() ; return (XY->last()->first() - origin->first())->abs() + (XY->last()[1+1] - origin[1+1])->abs() - ((XY->first()->first() - origin->first())->abs() + (XY->first()[1+1] - origin[1+1])->abs()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ma=lambda : map(int,input().split()) lma=lambda : list(map(int,input().split())) tma=lambda : tuple(map(int,input().split())) ni=lambda : int(input()) yn=lambda fl : print("Yes")if fl else print("No") import collections import math import itertools import heapq as hq import sys gcd=math.gcd n=ni() xpy=[] xmy=[] for i in range(n): x,y=ma() xpy.append(x+y) xmy.append(x-y) xpy.sort() xmy.sort() a1=abs(xpy[0]-xpy[-1]) a2=abs(xmy[0]-xmy[-1]) print(max(a1,a2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ma : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lma : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var tma : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ni : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var yn : Function := lambda fl : OclAny in (if fl then ("Yes")->display() else ("No")->display() endif) ; skip ; skip ; skip ; skip ; skip ; var gcd : OclAny := ; var n : OclAny := ni->apply() ; var xpy : Sequence := Sequence{} ; var xmy : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ma->apply() ; execute ((x + y) : xpy) ; execute ((x - y) : xmy)) ; xpy := xpy->sort() ; xmy := xmy->sort() ; var a1 : double := (xpy->first() - xpy->last())->abs() ; var a2 : double := (xmy->first() - xmy->last())->abs() ; execute (Set{a1, a2}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sysread=sys.stdin.buffer.readline read=sys.stdin.buffer.read sys.setrecursionlimit(10**7) INF=1<<50 EPS=1e-8 mod=10**9+7 def run(): N=int(sysread()) lis1=[] lis2=[] lis3=[] lis4=[] for i in range(N): x,y=map(int,sysread().split()) lis1.append((x+y,x,y)) lis2.append((x-y,x,y)) lis3.append((-x+y,x,y)) lis4.append((-x-y,x,y)) lis1.sort() lis2.sort() lis3.sort() lis4.sort() ans=0 val1,x1,y1=lis1[-1] val2,x2,y2=lis1[0] if x1>=x2 and y1>=y2 : ans=max(val1-val2,ans) val1,x1,y1=lis2[-1] val2,x2,y2=lis2[0] if x1>=x2 and y1<=y2 : ans=max(val1-val2,ans) val1,x1,y1=lis3[-1] val2,x2,y2=lis3[0] if x1<=x2 and y1>=y2 : ans=max(val1-val2,ans) val1,x1,y1=lis1[-1] val2,x2,y2=lis1[0] if x1<=x2 and y1<=y2 : ans=max(val1-val2,ans) print(ans) if __name__=="__main__" : run() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var sysread : OclAny := sys.stdin.buffer.readline ; var read : OclAny := sys.stdin.buffer.read ; sys.setrecursionlimit((10)->pow(7)) ; var INF : int := 1 * (2->pow(50)) ; var EPS : double := ("1e-8")->toReal() ; var mod : double := (10)->pow(9) + 7 ; skip ; if __name__ = "__main__" then ( run() ) else skip; operation run() pre: true post: true activity: var N : int := ("" + ((sysread())))->toInteger() ; var lis1 : Sequence := Sequence{} ; var lis2 : Sequence := Sequence{} ; var lis3 : Sequence := Sequence{} ; var lis4 : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (sysread().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{x + y, x, y}) : lis1) ; execute ((Sequence{x - y, x, y}) : lis2) ; execute ((Sequence{-x + y, x, y}) : lis3) ; execute ((Sequence{-x - y, x, y}) : lis4)) ; lis1 := lis1->sort() ; lis2 := lis2->sort() ; lis3 := lis3->sort() ; lis4 := lis4->sort() ; var ans : int := 0 ; var val1 : OclAny := null; var x1 : OclAny := null; var y1 : OclAny := null; Sequence{val1,x1,y1} := lis1->last() ; var val2 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{val2,x2,y2} := lis1->first() ; if (x1->compareTo(x2)) >= 0 & (y1->compareTo(y2)) >= 0 then ( ans := Set{val1 - val2, ans}->max() ) else skip ; var val1 : OclAny := null; var x1 : OclAny := null; var y1 : OclAny := null; Sequence{val1,x1,y1} := lis2->last() ; var val2 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{val2,x2,y2} := lis2->first() ; if (x1->compareTo(x2)) >= 0 & (y1->compareTo(y2)) <= 0 then ( ans := Set{val1 - val2, ans}->max() ) else skip ; var val1 : OclAny := null; var x1 : OclAny := null; var y1 : OclAny := null; Sequence{val1,x1,y1} := lis3->last() ; var val2 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{val2,x2,y2} := lis3->first() ; if (x1->compareTo(x2)) <= 0 & (y1->compareTo(y2)) >= 0 then ( ans := Set{val1 - val2, ans}->max() ) else skip ; var val1 : OclAny := null; var x1 : OclAny := null; var y1 : OclAny := null; Sequence{val1,x1,y1} := lis1->last() ; var val2 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{val2,x2,y2} := lis1->first() ; if (x1->compareTo(x2)) <= 0 & (y1->compareTo(y2)) <= 0 then ( ans := Set{val1 - val2, ans}->max() ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(1000000) import itertools def d(p1,p2): return abs(p1[0]-p2[0])+abs(p1[1]-p2[1]) def dx(p1,p2): return abs(p1[0]+p2[0])//2 def dy(p1,p2): return abs(p1[0]-p2[0])//2 def slow_solve(N,XYs): ans=0 for points in itertools.combinations(XYs,2): ans=max(ans,d(points[0],points[1])) return ans def solve(N,XYs): def transrate(XYs): return[(A[0]-A[1],A[0]+A[1])for A in XYs] XYs=transrate(XYs) def candidates(): return[max(XYs,key=lambda x : x[0]),min(XYs,key=lambda x : x[0]),max(XYs,key=lambda x : x[1]),min(XYs,key=lambda x : x[1]),] XYs.sort(key=lambda p : p[0],reverse=True) xmax=XYs[0][0]-XYs[-1][0] XYs.sort(key=lambda p : p[1],reverse=True) ymax=XYs[0][1]-XYs[-1][1] return max(xmax,ymax) if __name__=="__main__" : N=int(input()) XYs=[tuple(map(int,input().split(" ")))for _ in range(N)] print(solve(N,XYs)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(1000000) ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; XYs := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )))) ; execute (solve(N, XYs))->display() ) else skip; operation d(p1 : OclAny, p2 : OclAny) : OclAny pre: true post: true activity: return (p1->first() - p2->first())->abs() + (p1[1+1] - p2[1+1])->abs(); operation dx(p1 : OclAny, p2 : OclAny) : OclAny pre: true post: true activity: return (p1->first() + p2->first())->abs() div 2; operation dy(p1 : OclAny, p2 : OclAny) : OclAny pre: true post: true activity: return (p1->first() - p2->first())->abs() div 2; operation slow_solve(N : OclAny, XYs : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for points : itertools.combinations(XYs, 2) do ( ans := Set{ans, d(points->first(), points[1+1])}->max()) ; return ans; operation solve(N : OclAny, XYs : OclAny) : OclAny pre: true post: true activity: skip ; XYs := transrate(XYs) ; skip ; XYs := XYs->sort() ; var xmax : double := XYs->first()->first() - XYs->last()->first() ; XYs := XYs->sort() ; var ymax : double := XYs->first()[1+1] - XYs->last()[1+1] ; return Set{xmax, ymax}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- M,N=map(int,input().split()) A=[int(i)for i in input().split()] if M==2 : a,b=0,0 for i in range(N): if(i % 2)==(A[i]% 2): a+=1 else : b+=1 print(min(a,b)) else : ret=0 for i in range(1,N): if A[i]==A[i-1]: ret+=1 A[i]=0 print(ret) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var M : OclAny := null; var N : OclAny := null; Sequence{M,N} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if M = 2 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{0,0} ; for i : Integer.subrange(0, N-1) do ( if (i mod 2) = (A[i+1] mod 2) then ( a := a + 1 ) else ( b := b + 1 )) ; execute (Set{a, b}->min())->display() ) else ( var ret : int := 0 ; for i : Integer.subrange(1, N-1) do ( if A[i+1] = A[i - 1+1] then ( ret := ret + 1 ; A[i+1] := 0 ) else skip) ; execute (ret)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d,l=map(int,input().split()) ans=[None]*n k=0 chet=(n//2)+(n % 2) nechet=n//2 if(d>(nechet*(l-1)+l*(n % 2)))or(d<(-nechet*(l-1)+(n % 2))): print(-1) else : if d>0 : for i in range(n): if(i % 2)==0 : if kd : ans[0]=l-1 k-=1 else : for i in range(n): if(i % 2)==0 : if k>=d : ans[i]=1 k+=1 else : ans[i]=d-k k=d else : if k>d : ans[i]=min(abs(d-k),l) k-=min(abs(d-k),l) else : ans[i]=1 k-=1 if k>d : ans[n-2]+=1 k-=1 ans1='' for i in range(n): ans1+=str(ans[i])+' ' print(ans1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; var l : OclAny := null; Sequence{n,d,l} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; var k : int := 0 ; var chet : int := (n div 2) + (n mod 2) ; var nechet : int := n div 2 ; if ((d->compareTo((nechet * (l - 1) + l * (n mod 2)))) > 0) or ((d->compareTo((-nechet * (l - 1) + (n mod 2)))) < 0) then ( execute (-1)->display() ) else ( if d > 0 then ( for i : Integer.subrange(0, n-1) do ( if (i mod 2) = 0 then ( if (k->compareTo(d)) < 0 then ( ans[i+1] := l ; k := k + l ) else ( ans[i+1] := 1 ; k := k + 1 ) ) else ( if (k->compareTo(d)) <= 0 then ( ans[i+1] := 1 ; k := k - 1 ) else ( ans[i+1] := k - d ; k := d ) )) ; if (k->compareTo(d)) > 0 then ( ans->first() := l - 1 ; k := k - 1 ) else skip ) else ( for i : Integer.subrange(0, n-1) do ( if (i mod 2) = 0 then ( if (k->compareTo(d)) >= 0 then ( ans[i+1] := 1 ; k := k + 1 ) else ( ans[i+1] := d - k ; k := d ) ) else ( if (k->compareTo(d)) > 0 then ( ans[i+1] := Set{(d - k)->abs(), l}->min() ; k := k - Set{(d - k)->abs(), l}->min() ) else ( ans[i+1] := 1 ; k := k - 1 ) )) ; if (k->compareTo(d)) > 0 then ( ans[n - 2+1] := ans[n - 2+1] + 1 ; k := k - 1 ) else skip ) ; var ans1 : String := '' ; for i : Integer.subrange(0, n-1) do ( ans1 := ans1 + ("" + ((ans[i+1]))) + ' ') ; execute (ans1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class newNode : def __init__(self,data): self.data=data self.left=None self.right=None def inorder(root): if(root==None): return inorder(root.left) print(root.data,end=" ") inorder(root.right) def isIdentical(root1,root2): if(root1==None and root2==None): return 1 elif(root1!=None and root2==None): return 0 elif(root1==None and root2!=None): return 0 else : if(root1.data==root2.data and isIdentical(root1.left,root2.left)and isIdentical(root1.right,root2.right)): return 1 else : return 0 if __name__=='__main__' : root1=newNode(5) root2=newNode(5) root1.left=newNode(3) root1.right=newNode(8) root1.left.left=newNode(2) root1.left.right=newNode(4) root2.left=newNode(3) root2.right=newNode(8) root2.left.left=newNode(2) root2.left.right=newNode(4) if(isIdentical(root1,root2)): print("Both BSTs are identical") else : print("BSTs are not identical") ------------------------------------------------------------ OCL File: --------- class newNode { static operation newnewNode() : newNode pre: true post: newNode->exists( _x | result = _x ); attribute data : OclAny := data; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(data : OclAny) : newNode pre: true post: true activity: self.data := data ; self.left := null ; self.right := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( root1 := (newNode.newnewNode()).initialise(5) ; root2 := (newNode.newnewNode()).initialise(5) ; root1.left := (newNode.newnewNode()).initialise(3) ; root1.right := (newNode.newnewNode()).initialise(8) ; root1.left.left := (newNode.newnewNode()).initialise(2) ; root1.left.right := (newNode.newnewNode()).initialise(4) ; root2.left := (newNode.newnewNode()).initialise(3) ; root2.right := (newNode.newnewNode()).initialise(8) ; root2.left.left := (newNode.newnewNode()).initialise(2) ; root2.left.right := (newNode.newnewNode()).initialise(4) ; if (isIdentical(root1, root2)) then ( execute ("Both BSTs are identical")->display() ) else ( execute ("BSTs are not identical")->display() ) ) else skip; operation inorder(root : OclAny) pre: true post: true activity: if (root = null) then ( return ) else skip ; inorder(root.left) ; execute (root.data)->display() ; inorder(root.right); operation isIdentical(root1 : OclAny, root2 : OclAny) : OclAny pre: true post: true activity: if (root1 = null & root2 = null) then ( return 1 ) else (if (root1 /= null & root2 = null) then ( return 0 ) else (if (root1 = null & root2 /= null) then ( return 0 ) else ( if (root1.data = root2.data & isIdentical(root1.left, root2.left) & isIdentical(root1.right, root2.right)) then ( return 1 ) else ( return 0 ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if n==0 : break h=list(map(int,input().split())) sa=[] for i in range(n): sa.append(h[i+1]-h[i]) v=sorted(set(sa),key=lambda x : sa.count(x))[-1] for i in range(n): if i==0 and h[i+1]-h[i]!=v : if h[i+2]-h[i+1]==v : print(h[i]) else : print(h[i+1]) break elif h[i+1]-h[i]!=v : print(h[i+1]) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var h : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sa : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((h[i + 1+1] - h[i+1]) : sa)) ; var v : OclAny := sorted(Set{}->union((sa)), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name sa)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))))))->last() ; for i : Integer.subrange(0, n-1) do ( if i = 0 & h[i + 1+1] - h[i+1] /= v then ( if h[i + 2+1] - h[i + 1+1] = v then ( execute (h[i+1])->display() ) else ( execute (h[i + 1+1])->display() ) ; break ) else (if h[i + 1+1] - h[i+1] /= v then ( execute (h[i + 1+1])->display() ; break ) else skip))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy while True : n=int(input()) if n==0 : break h=list(map(int,input().split())) for i in range(n+1): k=copy.deepcopy(h) kanade=k.pop(i) res=[] for j in range(n-1): res.append(k[j+1]-k[j]) if all([1 if x==res[0]else 0 for x in res]): print(kanade) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var h : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n + 1-1) do ( var k : OclAny := copy.deepcopy(h) ; var kanade : OclAny := k->at(i`firstArg+1) ; k := k->excludingAt(i+1) ; var res : Sequence := Sequence{} ; for j : Integer.subrange(0, n - 1-1) do ( execute ((k[j + 1+1] - k[j+1]) : res)) ; if (res->select(x | true)->collect(x | (if x = res->first() then 1 else 0 endif)))->forAll( _x | _x = true ) then ( execute (kanade)->display() ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter while 1 : n=int(input()) if n==0 : break a=tuple(map(int,input().split())) b=[a[i+1]-a[i]for i in range(n)] d=Counter(b).most_common()[0][0] for i in range(n): if b[i]!=d : if itoInteger() ; if n = 0 then ( break ) else skip ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (a[i + 1+1] - a[i+1])) ; var d : OclAny := Counter(b).most_common()->first()->first() ; for i : Integer.subrange(0, n-1) do ( if b[i+1] /= d then ( if (i->compareTo(n - 1)) < 0 & b[i + 1+1] = d then ( execute (a[i+1])->display() ) else ( execute (a[i + 1+1])->display() ) ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import count def get_weed(h): d10=h[1]-h[0] d21=h[2]-h[1] d32=h[3]-h[2] if d10==d21==d32 : for hi,expect in zip(h,count(h[0],d10)): if hi!=expect : return hi d43=h[4]-h[3] if d21==d32==d43 : return h[0] elif h[2]-h[0]==d32==d43 : return h[1] elif d10==h[3]-h[1]==d43 : return h[2] elif d10==d21==h[4]-h[2]: return h[3] import sys f=sys.stdin while True : n=int(f.readline()) if n==0 : break h=list(map(int,f.readline().split())) print(get_weed(h)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var f : OclFile := OclFile["System.in"] ; while true do ( var n : int := ("" + ((f.readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; h := ((f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (get_weed(h))->display()); operation get_weed(h : OclAny) : OclAny pre: true post: true activity: var d10 : double := h[1+1] - h->first() ; var d21 : double := h[2+1] - h[1+1] ; var d32 : double := h[3+1] - h[2+1] ; if d10 = d21 & (d21 == d32) then ( for _tuple : Integer.subrange(1, h->size())->collect( _indx | Sequence{h->at(_indx), count(h->first(), d10)->at(_indx)} ) do (var _indx : int := 1; var hi : OclAny := _tuple->at(_indx); _indx := _indx + 1; var expect : OclAny := _tuple->at(_indx); if hi /= expect then ( return hi ) else skip) ) else skip ; var d43 : double := h[4+1] - h[3+1] ; if d21 = d32 & (d32 == d43) then ( return h->first() ) else (if h[2+1] - h->first() = d32 & (d32 == d43) then ( return h[1+1] ) else (if d10 = h[3+1] - h[1+1] & (h[3+1] - h[1+1] == d43) then ( return h[2+1] ) else (if d10 = d21 & (d21 == h[4+1] - h[2+1]) then ( return h[3+1] ) else skip ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(h): flag=True for i in range(len(h)-2): if h[i+1]-h[i]!=h[i+2]-h[i+1]: flag=False break return flag while True : n=int(input()) if n==0 : break h=[int(i)for i in input().split()] ans=-1 for k in range(n+1): tmp=h.pop(k) if check(h): print(tmp) break h.insert(k,tmp) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; h := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : int := -1 ; for k : Integer.subrange(0, n + 1-1) do ( var tmp : OclAny := h->at(k`firstArg+1) ; h := h->excludingAt(k+1) ; if check(h) then ( execute (tmp)->display() ; break ) else skip ; h := h.insertAt(k+1, tmp))); operation check(h : OclAny) : OclAny pre: true post: true activity: var flag : boolean := true ; for i : Integer.subrange(0, (h)->size() - 2-1) do ( if h[i + 1+1] - h[i+1] /= h[i + 2+1] - h[i + 1+1] then ( flag := false ; break ) else skip) ; return flag; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cyl(r,R,h): if(h<0 and r<0 and R<0): return-1 r1=r h1=h V=3.14*pow(r1,2)*h1 return round(V,2) if __name__=="__main__" : r,R,h=7,11,6 print(cyl(r,R,h)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{r,R,h} := Sequence{7,11,6} ; execute (cyl(r, R, h))->display() ) else skip; operation cyl(r : OclAny, R : OclAny, h : OclAny) : OclAny pre: true post: true activity: if (h < 0 & r < 0 & R < 0) then ( return -1 ) else skip ; var r1 : OclAny := r ; var h1 : OclAny := h ; var V : double := 3.14 * (r1)->pow(2) * h1 ; return MathLib.roundN(V, 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMissing(arr,n): l,h=0,n-1 mid=0 while(h>l): mid=l+(h-l)//2 if(arr[mid]-mid==arr[0]): if(arr[mid+1]-arr[mid]>1): return arr[mid]+1 else : l=mid+1 else : if(arr[mid]-arr[mid-1]>1): return arr[mid]-1 else : h=mid-1 return-1 arr=[-9,-8,-7,-5,-4,-3,-2,-1,0] n=len(arr) print(findMissing(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{-9}->union(Sequence{-8}->union(Sequence{-7}->union(Sequence{-5}->union(Sequence{-4}->union(Sequence{-3}->union(Sequence{-2}->union(Sequence{-1}->union(Sequence{ 0 })))))))) ; n := (arr)->size() ; execute (findMissing(arr, n))->display(); operation findMissing(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var l : OclAny := null; var h : OclAny := null; Sequence{l,h} := Sequence{0,n - 1} ; var mid : int := 0 ; while ((h->compareTo(l)) > 0) do ( mid := l + (h - l) div 2 ; if (arr[mid+1] - mid = arr->first()) then ( if (arr[mid + 1+1] - arr[mid+1] > 1) then ( return arr[mid+1] + 1 ) else ( var l : int := mid + 1 ) ) else ( if (arr[mid+1] - arr[mid - 1+1] > 1) then ( return arr[mid+1] - 1 ) else ( var h : double := mid - 1 ) )) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def areaCube(a): return(a*a*a) def surfaceCube(a): return(6*a*a) a=5 print("Area=",areaCube(a)) print("Total surface area=",surfaceCube(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 5 ; execute ("Area=")->display() ; execute ("Total surface area=")->display(); operation areaCube(a : OclAny) : OclAny pre: true post: true activity: return (a * a * a); operation surfaceCube(a : OclAny) : OclAny pre: true post: true activity: return (6 * a * a); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumoflength(arr,n): s=[] j=0 ans=0 for i in range(n): while(junion(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))) ; n := (arr)->size() ; execute (sumoflength(arr, n))->display() ) else skip; operation sumoflength(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var s : Sequence := Sequence{} ; var j : int := 0 ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( while ((j->compareTo(n)) < 0 & ((s)->excludes(arr[j+1]))) do ( execute ((arr[j+1]) : s) ; j := j + 1) ; ans := ans + ((j - i) * (j - i + 1)) div 2 ; execute ((arr[i+1]) /: s)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from queue import Queue class newNode : def __init__(self,data): self.data=data self.left=self.right=None def heightoftree(root): if(root==None): return 0 left=heightoftree(root.left) right=heightoftree(root.right) if left>right : return left+1 else : return right+1 def printPerLevelMinimum(root): if(root==None): return q=Queue() q.put(root) q.put(None) Min=9999999999999 level=0 while(q.empty()==False): node=q.queue[0] q.get() if(node==None): print("level",level,"min is=",Min) if(q.empty()): break q.put(None) level+=1 Min=999999999999 continue if(Min>node.data): Min=node.data if(node.left!=None): q.put(node.left) if(node.right!=None): q.put(node.right) if __name__=='__main__' : root=newNode(7) root.left=newNode(6) root.right=newNode(5) root.left.left=newNode(4) root.left.right=newNode(3) root.right.left=newNode(2) root.right.right=newNode(1) print("Every Level minimum is") printPerLevelMinimum(root) ------------------------------------------------------------ OCL File: --------- class newNode { static operation newnewNode() : newNode pre: true post: newNode->exists( _x | result = _x ); attribute data : OclAny := data; attribute left : OclAny := null; var self.right : OclAny := null; operation initialise(data : OclAny) : newNode pre: true post: true activity: self.data := data ; self.left := null; var self.right : OclAny := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( root := (newNode.newnewNode()).initialise(7) ; root.left := (newNode.newnewNode()).initialise(6) ; root.right := (newNode.newnewNode()).initialise(5) ; root.left.left := (newNode.newnewNode()).initialise(4) ; root.left.right := (newNode.newnewNode()).initialise(3) ; root.right.left := (newNode.newnewNode()).initialise(2) ; root.right.right := (newNode.newnewNode()).initialise(1) ; execute ("Every Level minimum is")->display() ; printPerLevelMinimum(root) ) else skip; operation heightoftree(root : OclAny) : OclAny pre: true post: true activity: if (root = null) then ( return 0 ) else skip ; var left : OclAny := heightoftree(root.left) ; var right : OclAny := heightoftree(root.right) ; if (left->compareTo(right)) > 0 then ( return left + 1 ) else ( return right + 1 ); operation printPerLevelMinimum(root : OclAny) pre: true post: true activity: if (root = null) then ( return ) else skip ; var q : OclAny := Queue() ; q.put(root) ; q.put(null) ; var Min : int := 9999999999999 ; var level : int := 0 ; while (q.empty() = false) do ( var node : OclAny := q.queue->first() ; q.get() ; if (node = null) then ( execute ("level")->display() ; if (q.empty()) then ( break ) else skip ; q.put(null) ; level := level + 1 ; Min := 999999999999 ; continue ) else skip ; if ((Min->compareTo(node.data)) > 0) then ( Min := node.data ) else skip ; if (node.left /= null) then ( q.put(node.left) ) else skip ; if (node.right /= null) then ( q.put(node.right) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import functools import os import sys import numpy as np def debug(fn): if not os.getenv('LOCAL'): return fn @ functools.wraps(fn) def wrapper(*args,**kwargs): ret=fn(*args,**kwargs) print('DEBUG:{}({})->'.format(fn.__name__,','.join(list(map(str,args))+['{}={}'.format(k,str(v))for k,v in kwargs.items()])),end='') print(ret) return ret return wrapper sys.setrecursionlimit(10000) INF=float('inf') N,Z,W=list(map(int,input().split())) A=list(map(int,input().split())) dpx=np.empty(N+1) dpy=np.empty(N+1) dpx.fill(np.inf) dpy.fill(-np.inf) for i in reversed(range(1,N)): y=A[i-1]if i>0 else W dpx[i]=max(abs(A[-1]-A[i-1]),dpy[i+1]) dpx[i]=min(dpx[i],dpx[i+1]) dpy[i]=min(abs(A[-1]-A[i-1]),dpx[i+1]) dpy[i]=max(dpy[i],dpy[i+1]) print(int(max(abs(A[-1]-W),dpy[1]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(10000) ; var INF : double := ("" + (('inf')))->toReal() ; var N : OclAny := null; var Z : OclAny := null; var W : OclAny := null; Sequence{N,Z,W} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dpx : Sequence := MatrixLib.singleValueMatrix(N + 1, 0.0) ; var dpy : Sequence := MatrixLib.singleValueMatrix(N + 1, 0.0) ; dpx.fill(Math_PINFINITY) ; dpy.fill(-Math_PINFINITY) ; for i : (Integer.subrange(1, N-1))->reverse() do ( var y : OclAny := if i > 0 then A[i - 1+1] else W endif ; dpx[i+1] := Set{(A->last() - A[i - 1+1])->abs(), dpy[i + 1+1]}->max() ; dpx[i+1] := Set{dpx[i+1], dpx[i + 1+1]}->min() ; dpy[i+1] := Set{(A->last() - A[i - 1+1])->abs(), dpx[i + 1+1]}->min() ; dpy[i+1] := Set{dpy[i+1], dpy[i + 1+1]}->max()) ; execute (("" + ((Set{(A->last() - W)->abs(), dpy[1+1]}->max())))->toInteger())->display(); operation debug(fn : OclAny) : OclAny pre: true post: true activity: if not(os.getenv('LOCAL')) then ( return fn ) else skip ; (compound_stmt (decorator @ (dotted_name (dotted_name (name functools)) . (name wraps)) ( (arglist (argument (test (logical_test (comparison (expr (atom (name fn)))))))) )) (funcdef def (name wrapper) ( (typedargslist (args * (named_parameter (name args))) , (kwargs ** (named_parameter (name kwargs)))) ) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ret)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name fn)) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom (name args))))))) , (argument ** (test (logical_test (comparison (expr (atom (name kwargs)))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'DEBUG:{}({})->') (trailer . (name format) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name fn)) (trailer . (name __name__))))))) , (argument (test (logical_test (comparison (expr (atom ',') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name args)))))))) ))))))))) )))) + (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom '{}={}') (trailer . (name format) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name k))))))) , (argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name k))) , (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name kwargs)) (trailer . (name items) (arguments ( )))))))) ])))))))) ))))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom ''))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ret)))))))) )))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name ret))))))))))))) ; return wrapper; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findEqualPoint(arr,n): distArr=[0]*n i=0 di=0 while(i>1]if(di & 1)else-1 arr=[1,2,3,4,4,5,6,6,6,7] n=len(arr) index=findEqualPoint(arr,n) if(index!=-1): print("Equal Point=",arr[index]) else : print("Equal Point does "+"not exists") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{6}->union(Sequence{6}->union(Sequence{ 7 }))))))))) ; n := (arr)->size() ; var index : OclAny := findEqualPoint(arr, n) ; if (index /= -1) then ( execute ("Equal Point=")->display() ) else ( execute ("Equal Point does " + "not exists")->display() ); operation findEqualPoint(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var distArr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var i : int := 0 ; var di : int := 0 ; while ((i->compareTo(n)) < 0) do ( distArr[di+1] := i ; di := di + 1 ; i := i + 1 ; while ((i->compareTo(n)) < 0 & arr[i+1] = arr[i - 1+1]) do ( i := i + 1)) ; return if (MathLib.bitwiseAnd(di, 1)) then distArr[di /(2->pow(1))+1] else -1 endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def KthCharacter(m,n,k): distance=pow(2,n) Block_number=int(k/distance) remaining=k % distance s=[0]*32 x=0 while(m>0): s[x]=m % 2 m=int(m/2) x+=1 root=s[x-1-Block_number] if(remaining==0): print(root) return flip=True while(remaining>1): if(remaining & 1): flip=not(flip) remaining=remaining>>1 if(flip): print(not(root)) else : print(root) m=5 k=5 n=3 KthCharacter(m,n,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; m := 5 ; k := 5 ; n := 3 ; KthCharacter(m, n, k); operation KthCharacter(m : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var distance : double := (2)->pow(n) ; var Block_number : int := ("" + ((k / distance)))->toInteger() ; var remaining : int := k mod distance ; var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 32) ; var x : int := 0 ; while (m > 0) do ( s[x+1] := m mod 2 ; m := ("" + ((m / 2)))->toInteger() ; x := x + 1) ; var root : OclAny := s[x - 1 - Block_number+1] ; if (remaining = 0) then ( execute (root)->display() ; return ) else skip ; var flip : boolean := true ; while (remaining > 1) do ( if (MathLib.bitwiseAnd(remaining, 1)) then ( flip := not((flip)) ) else skip ; remaining := remaining /(2->pow(1))) ; if (flip) then ( execute (not((root)))->display() ) else ( execute (root)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def NthTerm(N): x=(3*N*N)% 1000000009 return((x-N+1000000009)% 1000000009) if __name__=="__main__" : N=4 print(NthTerm(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := 4 ; execute (NthTerm(N))->display() ) else skip; operation NthTerm(N : OclAny) : OclAny pre: true post: true activity: var x : int := (3 * N * N) mod 1000000009 ; return ((x - N + 1000000009) mod 1000000009); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def inProportion(arr): n=4 ; arr.sort() extremes=arr[0]*arr[3]; means=arr[1]*arr[2]; if(extremes==means): return True ; return False ; if __name__=="__main__" : arr=[1,2,4,2]; if(inProportion(arr)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 2 }))); ; if (inProportion(arr)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ) else skip; operation inProportion(arr : OclAny) pre: true post: true activity: var n : int := 4; ; arr := arr->sort() ; var extremes : double := arr->first() * arr[3+1]; ; var means : double := arr[1+1] * arr[2+1]; ; if (extremes = means) then ( return true; ) else skip ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(i,x,dp): if(i<0): return x==3 if(dp[i][x]!=-1): return dp[i][x] dp[i][x]=solve(i-1,0,dp) dp[i][x]+=solve(i-1,x+1,dp) return dp[i][x] if __name__=="__main__" : n=4 ; dp=[[0 for i in range(n)]for j in range(4)] for i in range(n): for j in range(4): dp[i][j]=-1 for i in range(n): dp[i][3]=(1<<(i+1)) print(solve(n-1,0,dp)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var n : int := 4; ; dp := Integer.subrange(0, 4-1)->select(j | true)->collect(j | (Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, 4-1) do ( dp[i+1][j+1] := -1)) ; for i : Integer.subrange(0, n-1) do ( dp[i+1][3+1] := (1 * (2->pow((i + 1))))) ; execute (solve(n - 1, 0, dp))->display() ) else skip; operation solve(i : OclAny, x : OclAny, dp : OclAny) : OclAny pre: true post: true activity: if (i < 0) then ( return x = 3 ) else skip ; if (dp[i+1][x+1] /= -1) then ( return dp[i+1][x+1] ) else skip ; dp[i+1][x+1] := solve(i - 1, 0, dp) ; dp[i+1][x+1] := dp[i+1][x+1] + solve(i - 1, x + 1, dp) ; return dp[i+1][x+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x=int(input()) y=list(map(int,input().split())) sort=list(sorted(y)) dupli=[] nondupli=[sort[0]] for i in range(1,x): if sort[i]==sort[i-1]: dupli.append(sort[i]) else : nondupli.append(sort[i]) print(*nondupli+dupli) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var y : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sort : Sequence := (y->sort()) ; var dupli : Sequence := Sequence{} ; var nondupli : Sequence := Sequence{ sort->first() } ; for i : Integer.subrange(1, x-1) do ( if sort[i+1] = sort[i - 1+1] then ( execute ((sort[i+1]) : dupli) ) else ( execute ((sort[i+1]) : nondupli) )) ; execute ((argument * (test (logical_test (comparison (expr (expr (atom (name nondupli))) + (expr (atom (name dupli)))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) count=[0]*101 a=list(map(int,input().split())) for i in range(n): count[a[i]]+=1 ans=[] for i in range(101): if(count[i]>0): ans.append(i) count[i]-=1 for i in range(101): while(count[i]>0): ans.append(i) count[i]-=1 for i in range(n): print(ans[i],end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 101) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( count[a[i+1]+1] := count[a[i+1]+1] + 1) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, 101-1) do ( if (count[i+1] > 0) then ( execute ((i) : ans) ; count[i+1] := count[i+1] - 1 ) else skip) ; for i : Integer.subrange(0, 101-1) do ( while (count[i+1] > 0) do ( execute ((i) : ans) ; count[i+1] := count[i+1] - 1)) ; for i : Integer.subrange(0, n-1) do ( execute (ans[i+1])->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: r=a,b=[[],[]] for x in sorted(s.split(),key=int): r[x in a]+=x, print(*a+b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var r : OclAny := Sequence{Sequence{}}->union(Sequence{ Sequence{} }); var a,b : Sequence := Sequence{Sequence{}}->union(Sequence{ Sequence{} }) ; for x : s.split()->sortedBy($x | (OclType["int"])->apply($x)) do ( r->select((a)->includes(x)) := r->select((a)->includes(x)) + (testlist (test (logical_test (comparison (expr (atom (name x)))))) ,)) ; execute ((argument * (test (logical_test (comparison (expr (expr (atom (name a))) + (expr (atom (name b)))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for j in range(int(input())): n=int(input()) a=list(map(int,input().split())) a.sort() i=1 if len(a)==1 : print(*a) else : while a[i]!=max(a): if a[i]==a[i-1]: del a[i] a.append(a[i-1]) else : i+=1 print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for j : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var i : int := 1 ; if (a)->size() = 1 then ( execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display() ) else ( while a[i+1] /= (a)->max() do ( if a[i+1] = a[i - 1+1] then ( execute (a[i+1])->isDeleted() ; execute ((a[i - 1+1]) : a) ) else ( i := i + 1 )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def max_cuts(n,a,b,c): if(n==0): return 0 elif(n<0): return-1 result=max(max_cuts(n-a,a,b,c),max_cuts(n-b,a,b,c),max_cuts(n-c,a,b,c)) if(result==-1): return-1 return result+1 def freq(list1): freq_count={} for i in list1 : if(i in freq_count): freq_count[i]+=1 else : freq_count[i]=1 return freq_count t=int(input()) for t1 in range(t): n=int(input()) a=sorted(list(map(int,input().split()))) uniq=sorted(list(set(a))) for i in uniq : a.remove(i) ans=uniq+a print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t1 : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var uniq : Sequence := (Set{}->union((a)))->sort() ; for i : uniq do ( execute ((i) /: a)) ; var ans : Sequence := uniq->union(a) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()); operation max_cuts(n : OclAny, a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return 0 ) else (if (n < 0) then ( return -1 ) else skip) ; var result : OclAny := Set{max_cuts(n - a, a, b, c), max_cuts(n - b, a, b, c), max_cuts(n - c, a, b, c)}->max() ; if (result = -1) then ( return -1 ) else skip ; return result + 1; operation freq(list1 : OclAny) : OclAny pre: true post: true activity: var freq_count : OclAny := Set{} ; for i : list1 do ( if ((freq_count)->includes(i)) then ( freq_count[i+1] := freq_count[i+1] + 1 ) else ( freq_count[i+1] := 1 )) ; return freq_count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) K=int(input()) X=int(input()) Y=int(input()) if N<=K : print(int(N*X)) else : print(int(K*X+(N-K)*Y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var X : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var Y : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (N->compareTo(K)) <= 0 then ( execute (("" + ((N * X)))->toInteger())->display() ) else ( execute (("" + ((K * X + (N - K) * Y)))->toInteger())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline n=int(input()) si,sj=[0]*(n+1),[0]*(n+1) s=input().strip() for i in range(n): sj[i+1]=sj[i]+(s[i]=='J') si[i+1]=si[i]+(s[i]=='I') ans=a=b=c=0 for i in range(1,n): a=max(a,sj[i]*(si[n]-si[i])) for i in range(n): if s[i]=='O' : b+=si[n]-si[i+1] c+=sj[i] ans+=(si[n]-si[i+1])*sj[i] print(ans+max(a,b,c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var si : OclAny := null; var sj : OclAny := null; Sequence{si,sj} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)),MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1))} ; var s : OclAny := input()->trim() ; for i : Integer.subrange(0, n-1) do ( sj[i + 1+1] := sj[i+1] + (s[i+1] = 'J') ; si[i + 1+1] := si[i+1] + (s[i+1] = 'I')) ; ans := ans(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name a)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for i : Integer.subrange(1, n-1) do ( var a : OclAny := Set{a, sj[i+1] * (si[n+1] - si[i+1])}->max()) ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = 'O' then ( b := b + si[n+1] - si[i + 1+1] ; c := c + sj[i+1] ; ans := ans + (si[n+1] - si[i + 1+1]) * sj[i+1] ) else skip) ; execute (ans + Set{a, b, c}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def LexicographicalMaxString(str): mx="" for i in range(len(str)): mx=max(mx,str[i :]) return mx if __name__=='__main__' : str="ababaa" print(LexicographicalMaxString(str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( OclType["String"] := "ababaa" ; execute (LexicographicalMaxString(OclType["String"]))->display() ) else skip; operation LexicographicalMaxString(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var mx : String := "" ; for i : Integer.subrange(0, (OclType["String"])->size()-1) do ( mx := Set{mx, ("" + (.subrange(i+1)))}->max()) ; return mx; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math [a,b]=list(map(int,input().split(' '))) while a>0 and b>0 : if a>=2*b : a=a %(2*b) elif b>=2*a : b=b %(2*a) else : break print(f"{a}{b}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{a}->union(Sequence{ b }) := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; while a > 0 & b > 0 do ( if (a->compareTo(2 * b)) >= 0 then ( var a : int := a mod (2 * b) ) else (if (b->compareTo(2 * a)) >= 0 then ( var b : int := b mod (2 * a) ) else ( break ) ) ) ; execute (StringLib.formattedString("{a}{b}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def MinDeletion(a,n): __gcd=0 ; for i in range(n): __gcd=gcd(__gcd,a[i]); if(__gcd>1): return-1 ; else : return 0 ; if __name__=="__main__" : a=[3,6,12,81,9]; n=len(a) print(MinDeletion(a,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( a := Sequence{3}->union(Sequence{6}->union(Sequence{12}->union(Sequence{81}->union(Sequence{ 9 })))); ; n := (a)->size() ; execute (MinDeletion(a, n))->display(); ) else skip; operation MinDeletion(a : OclAny, n : OclAny) pre: true post: true activity: var __gcd : int := 0; ; for i : Integer.subrange(0, n-1) do ( __gcd := gcd(__gcd, a[i+1]);) ; if (__gcd > 1) then ( return -1; ) else ( return 0; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd from functools import reduce from collections import Counter class Osa_k : def __init__(self,maximum): self.table=[-1]*(maximum+1) for i in range(2,maximum+1): for j in range(2,int(i**0.5)+1): if i % j==0 : self.table[i]=j break def factorize(self,n): res=Counter() b=n while 1 : if self.table[b]==-1 : break res[self.table[b]]+=1 b//=self.table[b] res[b]+=1 return res N=int(input()) *A,=map(int,input().split()) def f(): cnt=Counter() ins=Osa_k(max(A)) for i in A : res=ins.factorize(i)if i!=1 else{} for j in res.keys(): cnt[j]+=1 if cnt[j]>=2 : return False return True cond1=f() cond2=(reduce(gcd,A)==1) if cond1 : print("pairwise coprime") elif cond2 : print("setwise coprime") else : print("not coprime") ------------------------------------------------------------ OCL File: --------- class Osa_k { static operation newOsa_k() : Osa_k pre: true post: Osa_k->exists( _x | result = _x ); attribute table : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (maximum + 1)); operation initialise(maximum : OclAny) : Osa_k pre: true post: true activity: self.table := MatrixLib.elementwiseMult(Sequence{ -1 }, (maximum + 1)) ; for i : Integer.subrange(2, maximum + 1-1) do ( for j : Integer.subrange(2, ("" + (((i)->pow(0.5))))->toInteger() + 1-1) do ( if i mod j = 0 then ( self.table[i+1] := j ; break ) else skip)); return self; operation factorize(n : OclAny) : OclAny pre: true post: true activity: var res : OclAny := Counter() ; var b : OclAny := n ; while 1 do ( if self.table[b+1] = -1 then ( break ) else skip ; res[self.table[b+1]+1] := res[self.table[b+1]+1] + 1 ; b := b div self.table[b+1]) ; res[b+1] := res[b+1] + 1 ; return res; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (testlist_star_expr (star_expr * (expr (atom (name A)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name A)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; var cond1 : String := f() ; var cond2 : boolean := (reduce(gcd, A) = 1) ; if cond1 then ( execute ("pairwise coprime")->display() ) else (if cond2 then ( execute ("setwise coprime")->display() ) else ( execute ("not coprime")->display() ) ) ; operation f() : OclAny pre: true post: true activity: var cnt : OclAny := Counter() ; var ins : Osa_k := (Osa_k.newOsa_k()).initialise((A)->max()) ; for i : A do ( res := if i /= 1 then ins.factorize(i) else Set{} endif ; for j : res.keys() do ( cnt[j+1] := cnt[j+1] + 1 ; if cnt[j+1] >= 2 then ( return false ) else skip)) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.readline().rstrip() class Sieve : def __init__(self,n): self.primes=[] self.f=[0]*(n+1) self.f[0]=self.f[1]=-1 self.f_lis=[0]*(n+1) for i in range(2,n+1): if self.f[i]: continue self.primes.append(i) self.f[i]=i for j in range(i*i,n+1,i): if not self.f[j]: self.f[j]=i def prime_fact(self,A): for x in A : while x!=1 : p=self.f[x] x//=p if x % p>0 : if self.f_lis[p]>0 : return False self.f_lis[p]+=1 return True import math from functools import reduce def gcd_all(numbers): return reduce(math.gcd,numbers) def main(): n=int(input()) A=list(map(int,input().split())) Sieve_a=Sieve(max(A)+1) if Sieve_a.prime_fact(A): print("pairwise coprime") elif gcd_all(A)==1 : print("setwise coprime") else : print("not coprime") if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class Sieve { static operation newSieve() : Sieve pre: true post: Sieve->exists( _x | result = _x ); attribute primes : Sequence := Sequence{}; attribute f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); attribute (trailer . (name f) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) : OclAny := -1; var self.f[1+1] : int := -1; attribute f_lis : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)); operation initialise(n : OclAny) : Sieve pre: true post: true activity: self.primes := Sequence{} ; self.f := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; self.f->first() := -1; var self.f[1+1] : int := -1 ; self.f_lis := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(2, n + 1-1) do ( if self.f[i+1] then ( continue ) else skip ; (expr (atom (name self)) (trailer . (name primes)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ; self.f[i+1] := i ; for j : Integer.subrange(i * i, n + 1-1)->select( $x | ($x - i * i) mod i = 0 ) do ( if not(self.f[j+1]) then ( self.f[j+1] := i ) else skip)); return self; operation prime_fact(A : OclAny) : OclAny pre: true post: true activity: for x : A do ( while x /= 1 do ( var p : OclAny := self.f[x+1] ; x := x div p ; if x mod p > 0 then ( if self.f_lis[p+1] > 0 then ( return false ) else skip ; self.f_lis[p+1] := self.f_lis[p+1] + 1 ) else skip)) ; return true; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation gcd_all(numbers : OclAny) : OclAny pre: true post: true activity: return reduce(, numbers); operation main() pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; A := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var Sieve_a : Sieve := (Sieve.newSieve()).initialise((A)->max() + 1) ; if Sieve_a.prime_fact(A) then ( execute ("pairwise coprime")->display() ) else (if gcd_all(A) = 1 then ( execute ("setwise coprime")->display() ) else ( execute ("not coprime")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline import math def solve(): n=int(input()) a=list(map(int,input().split())) cur=0 for i in a : cur=math.gcd(i,cur) if cur>1 : print('not coprime') return m=max(a) prime=[True]*(m+1) c={} for i in a : c[i]=c.get(i,0)+1 for i in range(2,m+1): if prime[i]: cnt=0 for j in range(i,m+1,i): prime[j]=False cnt+=c.get(j,0) if cnt>1 : print('setwise coprime') return print('pairwise coprime') if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; skip ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cur : int := 0 ; for i : a do ( cur := (i)->gcd(cur)) ; if cur > 1 then ( execute ('not coprime')->display() ; return ) else skip ; var m : OclAny := (a)->max() ; var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (m + 1)) ; var c : OclAny := Set{} ; for i : a do ( c[i+1] := c.get(i, 0) + 1) ; for i : Integer.subrange(2, m + 1-1) do ( if prime[i+1] then ( var cnt : int := 0 ; for j : Integer.subrange(i, m + 1-1)->select( $x | ($x - i) mod i = 0 ) do ( prime[j+1] := false ; cnt := cnt + c.get(j, 0) ; if cnt > 1 then ( execute ('setwise coprime')->display() ; return ) else skip) ) else skip) ; execute ('pairwise coprime')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) *A,=map(int,input().split()) m=max(2,max(A)) P={p : True for p in range(2,m+1)} for i in range(2,m+1): for j in range(2*i,m+1,i): P[j]=False Pmap={p : 0 for p in P if P[p]} Amap={a : 0 for a in range(1,m+1)} for a in A : Amap[a]+=1 for p in Pmap : for a in range(p,m+1,p): Pmap[p]+=Amap[a] s=max(Pmap.values()) if s<2 : print('pairwise coprime') elif stoInteger() ; (testlist_star_expr (star_expr * (expr (atom (name A)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name A)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : OclAny := Set{2, (A)->max()}->max() ; var P : Map := Integer.subrange(2, m + 1-1)->select(p | true)->collect(p | Map{p |-> true})->unionAll() ; for i : Integer.subrange(2, m + 1-1) do ( for j : Integer.subrange(2 * i, m + 1-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ( P[j+1] := false)) ; var Pmap : Map := P->keys()->select(p | P[p+1])->collect(p | Map{p |-> 0})->unionAll() ; var Amap : Map := Integer.subrange(1, m + 1-1)->select(a | true)->collect(a | Map{a |-> 0})->unionAll() ; for a : A do ( Amap[a+1] := Amap[a+1] + 1) ; for p : Pmap->keys() do ( for a : Integer.subrange(p, m + 1-1)->select( $x | ($x - p) mod p = 0 ) do ( Pmap[p+1] := Pmap[p+1] + Amap[a+1])) ; var s : OclAny := (Pmap.values())->max() ; if s < 2 then ( execute ('pairwise coprime')->display() ) else (if (s->compareTo(n)) < 0 then ( execute ('setwise coprime')->display() ) else ( execute ('not coprime')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd N=int(input()) A=list(map(int,input().split())) tmp=0 for a in A : tmp=gcd(tmp,a) isSetwise=(tmp==1) M=10**6 sieve=[0]*(M+1) for a in A : sieve[a]+=1 cnt=0 for i in range(2,M+1): tmp=0 for j in range(i,M+1,i): tmp+=sieve[j] cnt=max(cnt,tmp) isPairwise=(cnt<=1) if isPairwise : ans='pairwise coprime' elif isSetwise : ans='setwise coprime' else : ans='not coprime' print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var tmp : int := 0 ; for a : A do ( tmp := gcd(tmp, a)) ; var isSetwise : boolean := (tmp = 1) ; var M : double := (10)->pow(6) ; var sieve : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (M + 1)) ; for a : A do ( sieve[a+1] := sieve[a+1] + 1) ; var cnt : int := 0 ; for i : Integer.subrange(2, M + 1-1) do ( tmp := 0 ; for j : Integer.subrange(i, M + 1-1)->select( $x | ($x - i) mod i = 0 ) do ( tmp := tmp + sieve[j+1]) ; cnt := Set{cnt, tmp}->max()) ; var isPairwise : boolean := (cnt <= 1) ; if isPairwise then ( var ans : String := 'pairwise coprime' ) else (if isSetwise then ( ans := 'setwise coprime' ) else ( ans := 'not coprime' ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getPairs(arr,n): h=set() for i in range(n-1): for j in range(i+1,n): h.add((arr[i],arr[j])); return len(h); if __name__=="__main__" : arr=[1,2,2,4,2,5,3,5] n=len(arr) print(getPairs(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{4}->union(Sequence{2}->union(Sequence{5}->union(Sequence{3}->union(Sequence{ 5 }))))))) ; n := (arr)->size() ; execute (getPairs(arr, n))->display() ) else skip; operation getPairs(arr : OclAny, n : OclAny) pre: true post: true activity: var h : Set := Set{}->union(()) ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(i + 1, n-1) do ( execute ((Sequence{arr[i+1], arr[j+1]}) : h);)) ; return (h)->size();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find_ans(arr : list)->list : if len(arr)==0 : return[] if len(arr)==1 : return arr if len(arr)==2 : return[min(arr),max(arr)] i=arr.index(min(arr)) if i!=0 : return[min(arr)]+arr[: i-1]+find_ans([arr[i-1]]+arr[i+1 :]) else : return[min(arr)]+find_ans(arr[1 :]) for _ in range(int(input())): n=int(input()) arr=list(map(int,input().split())) print(*find_ans(arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name find_ans)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr)))))))) )))))))))->display()); operation find_ans(arr : Sequence(OclAny)) : Sequence pre: true post: true activity: if (arr)->size() = 0 then ( return Sequence{} ) else skip ; if (arr)->size() = 1 then ( return arr ) else skip ; if (arr)->size() = 2 then ( return Sequence{(arr)->min()}->union(Sequence{ (arr)->max() }) ) else skip ; var i : int := arr->indexOf((arr)->min()) - 1 ; if i /= 0 then ( return Sequence{ (arr)->min() }->union(arr.subrange(1,i - 1))->union(find_ans(Sequence{ arr[i - 1+1] }->union(arr.subrange(i + 1+1)))) ) else ( return Sequence{ (arr)->min() }->union(find_ans(arr->tail())) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) S=input() a0=0 ; a1=0 ; a2=0 P=[0]*N for i,c in enumerate(S): if c=='J' : a0+=1 elif c=='O' : a1+=a0 else : a2+=a1 P[i]=a0 b0=0 ; b1=0 ; b2=0 Q=[0]*N for i,c in enumerate(reversed(S)): if c=='I' : b0+=1 elif c=='O' : b1+=b0 else : b2+=b1 Q[-1-i]=b0 res=max(a1,b1) for i in range(N): res=max(res,P[i]*Q[i]) print(res+a2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : String := (OclFile["System.in"]).readLine() ; var a0 : int := 0; var a1 : int := 0; var a2 : int := 0 ; var P : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for _tuple : Integer.subrange(1, (S)->size())->collect( _indx | Sequence{_indx-1, (S)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if c = 'J' then ( a0 := a0 + 1 ) else (if c = 'O' then ( a1 := a1 + a0 ) else ( a2 := a2 + a1 ) ) ; P[i+1] := a0) ; var b0 : int := 0; var b1 : int := 0; var b2 : int := 0 ; var Q : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for _tuple : Integer.subrange(1, ((S)->reverse())->size())->collect( _indx | Sequence{_indx-1, ((S)->reverse())->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if c = 'I' then ( b0 := b0 + 1 ) else (if c = 'O' then ( b1 := b1 + b0 ) else ( b2 := b2 + b1 ) ) ; Q->reverse()->at(-(-1 - i)) := b0) ; var res : OclAny := Set{a1, b1}->max() ; for i : Integer.subrange(0, N-1) do ( res := Set{res, P[i+1] * Q[i+1]}->max()) ; execute (res + a2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) i=0 k=n-1 ans=[x for x in a] while k>0 and ia[j]: mn=a[j] mi=j if mi is not None : ans[i]=mn for j in range(i,mi): ans[j+1]=a[j] for j in range(i,mi+1): a[j]=ans[j] i=mi k-=mi-i+1 else : i=i+1 for x in ans : print(x,end=' ') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var i : int := 0 ; var k : double := n - 1 ; var ans : Sequence := a->select(x | true)->collect(x | (x)) ; while k > 0 & (i->compareTo(n)) < 0 do ( var mn : OclAny := a[i+1] ; var mi : OclAny := null ; for j : Integer.subrange(i, Set{i + k + 1, n}->min()-1) do ( if (mn->compareTo(a[j+1])) > 0 then ( mn := a[j+1] ; mi := j ) else skip) ; if not(mi <>= null) then ( ans[i+1] := mn ; for j : Integer.subrange(i, mi-1) do ( ans[j + 1+1] := a[j+1]) ; for j : Integer.subrange(i, mi + 1-1) do ( a[j+1] := ans[j+1]) ; i := mi ; k := k - mi - i + 1 ) else ( i := i + 1 )) ; for x : ans do ( execute (x)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) pos=0 while pos!=n-1 : nxt=pos mn=l[pos] for i in range(pos+1,n): if l[i]toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var pos : int := 0 ; while pos /= n - 1 do ( var nxt : int := pos ; var mn : OclAny := l[pos+1] ; for i : Integer.subrange(pos + 1, n-1) do ( if (l[i+1]->compareTo(mn)) < 0 then ( mn := l[i+1] ; nxt := i ) else skip) ; var q : int := nxt ; while q /= pos do ( var l[q+1] : OclAny := null; var l[q - 1+1] : OclAny := null; Sequence{l[q+1],l[q - 1+1]} := Sequence{l[q - 1+1],l[q+1]} ; q := q - 1) ; if nxt = pos then ( pos := pos + 1 ) else ( pos := nxt )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name l))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) if acollect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(b)) < 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a} ; var swap : int := 1 ) else ( swap := 0 ) ; while b do ( var div : OclAny := null; var mod : OclAny := null; Sequence{div,mod} := Sequence{(a div b), (a mod b)} ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,mod} ; swap := 1 - swap ; if div mod 2 then ( b := b + a ; break ) else skip) ; if swap then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a} ) else skip ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for p in[0]*int(input()): input(); a=[*map(int,input().split())]; i=0 while a[i :]: j=a.index(min(a[i :])); a[i : i]=a.pop(j),; i=j+(j==i) print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for p : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( input(); var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var i : int := 0 ; while a.subrange(i+1) do ( var j : int := a->indexOf((a.subrange(i+1))->min()) - 1; a.subrange(i+1, i) := (testlist_star_expr (test (logical_test (comparison (expr (atom (name a)) (trailer . (name pop) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) ))))))) ,); i := j + (j = i)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input for _ in[0]*int(I()): I(); a=[*map(int,I().split())]; i=0 while a[i :]: j=a.index(min(a[i :])); a[i : i]=a.pop(j),; i=j+(j==i) print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + ((I())))->toInteger()) do ( I(); var a : Sequence := (I().split())->collect( _x | (OclType["int"])->apply(_x) ); var i : int := 0 ; while a.subrange(i+1) do ( var j : int := a->indexOf((a.subrange(i+1))->min()) - 1; a.subrange(i+1, i) := (testlist_star_expr (test (logical_test (comparison (expr (atom (name a)) (trailer . (name pop) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) ))))))) ,); i := j + (j = i)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def digit_product_Sum(N): a=[0]*(N+1); product=1 ; a[0]=1 ; for i in range(1,N+1): product=int(a[i-1]/10); if(product==0): product=1 ; else : product=a[i-1]% 10 ; val=int(a[i-1]/10); if(val==0): val=a[i-1]; a[i]=a[i-1]+(val*product); for i in range(N): print(a[i],end=" "); N=10 ; digit_product_Sum(N); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 10; ; digit_product_Sum(N);; operation digit_product_Sum(N : OclAny) pre: true post: true activity: var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)); ; var product : int := 1; ; a->first() := 1; ; for i : Integer.subrange(1, N + 1-1) do ( product := ("" + ((a[i - 1+1] / 10)))->toInteger(); ; if (product = 0) then ( product := 1; ) else ( product := a[i - 1+1] mod 10; ) ; var val : int := ("" + ((a[i - 1+1] / 10)))->toInteger(); ; if (val = 0) then ( val := a[i - 1+1]; ) else skip ; a[i+1] := a[i - 1+1] + (val * product);) ; for i : Integer.subrange(0, N-1) do ( execute (a[i+1])->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMax(num): num_copy=num j=4*8-1 ; i=0 while(i>i)& 1 n=(num_copy>>j)& 1 if(m>n): x=(1<display() ) else skip; operation findMax(num : OclAny) : OclAny pre: true post: true activity: var num_copy : OclAny := num ; var j : double := 4 * 8 - 1; ; var i : int := 0 ; while ((i->compareTo(j)) < 0) do ( var m : int := MathLib.bitwiseAnd((num_copy /(2->pow(i))), 1) ; var n : int := MathLib.bitwiseAnd((num_copy /(2->pow(j))), 1) ; if ((m->compareTo(n)) > 0) then ( var x : int := (MathLib.bitwiseOr(1 * (2->pow(i)), 1 * (2->pow(j)))) ; num := MathLib.bitwiseXor(num, x) ) else skip ; i := i + 1 ; j := j - 1) ; return num; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def sumDigits(n): digit_sum=0 ; while(n>0): digit_sum+=n % 10 ; n/=10 ; return digit_sum ; def productOfNumbers(arr,n): sum=-sys.maxsize-1 ; for i in range(n-1): for j in range(i+1,n): product=arr[i]*arr[j]; sum=max(sum,sumDigits(product)); return sum ; if __name__=='__main__' : arr=[4,3,5]; n=len(arr); print(int(productOfNumbers(arr,n))); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{4}->union(Sequence{3}->union(Sequence{ 5 })); ; n := (arr)->size(); ; execute (("" + ((productOfNumbers(arr, n))))->toInteger())->display(); ) else skip; operation sumDigits(n : OclAny) pre: true post: true activity: var digit_sum : int := 0; ; while (n > 0) do ( digit_sum := digit_sum + n mod 10; ; n := n / 10;) ; return digit_sum;; operation productOfNumbers(arr : OclAny, n : OclAny) pre: true post: true activity: var sum : double := -(trailer . (name maxsize)) - 1; ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(i + 1, n-1) do ( var product : double := arr[i+1] * arr[j+1]; ; sum := Set{sum, sumDigits(product)}->max();)) ; return sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMinX(num,rem,k): x=1 ; while(True): j=0 ; while(junion(Sequence{4}->union(Sequence{ 5 })); ; rem := Sequence{2}->union(Sequence{3}->union(Sequence{ 1 })); ; k := (num)->size(); ; execute ("x is")->display();; operation findMinX(num : OclAny, rem : OclAny, k : OclAny) pre: true post: true activity: var x : int := 1; ; while (true) do ( var j : int := 0; ; while ((j->compareTo(k)) < 0) do ( if (x mod num[j+1] /= rem[j+1]) then ( break; ) else skip ; j := j + 1;) ; if (j = k) then ( return x; ) else skip ; x := x + 1;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt n,k=[int(i)for i in input().split()] d=[] for i in range(1,int(sqrt(n))+1): if n % i==0 : d.append(i) if i!=n//i : d.append(n//i) d=sorted(d) try : print(d[k-1]) except IndexError : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var d : Sequence := Sequence{} ; for i : Integer.subrange(1, ("" + ((sqrt(n))))->toInteger() + 1-1) do ( if n mod i = 0 then ( execute ((i) : d) ; if i /= n div i then ( execute ((n div i) : d) ) else skip ) else skip) ; d := d->sort() ; try ( execute (d[k - 1+1])->display()) (except_clause except (test (logical_test (comparison (expr (atom (name IndexError)))))) : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))) ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy from test.support import _MemoryWatchdog BIG_NUM=2000000000 HUGE_NUM=99999999999999999 MOD=1000000007 EPS=0.000000001 sys.setrecursionlimit(100000) J=0 O=1 I=2 JO=3 OI=4 num_JOI=0 N=int(input()) input_str=input() dp=[[0]*(5)for _ in range(N+1)] for i in range(1,(N+1)): if input_str[i-1]=="J" : dp[i][J]+=1 elif input_str[i-1]=="O" : dp[i][O]+=1 dp[i][JO]+=dp[i-1][J] else : dp[i][I]+=1 dp[i][OI]+=dp[i-1][O] num_JOI+=dp[i-1][JO] for k in range(5): dp[i][k]+=dp[i-1][k] maximum=max(dp[N][JO],dp[N][OI]) for i in range(1,(N+1)): if input_str[i-1]=="J" : maximum=max(maximum,dp[i][J]*(dp[N][I]-dp[i][I])) elif input_str[i-1]=="O" : maximum=max(maximum,dp[i-1][J]*(dp[N][I]-dp[i][I])) else : maximum=max(maximum,dp[i-1][J]*(dp[N][I]-dp[i][I]+1)) print("%d" %(num_JOI+maximum)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var HUGE_NUM : int := 99999999999999999 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; sys.setrecursionlimit(100000) ; var J : int := 0 ; var O : int := 1 ; var I : int := 2 ; var JO : int := 3 ; var OI : int := 4 ; var num_JOI : int := 0 ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var input_str : String := (OclFile["System.in"]).readLine() ; var dp : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (5)))) ; for i : Integer.subrange(1, (N + 1)-1) do ( if input_str[i - 1+1] = "J" then ( dp[i+1][J+1] := dp[i+1][J+1] + 1 ) else (if input_str[i - 1+1] = "O" then ( dp[i+1][O+1] := dp[i+1][O+1] + 1 ; dp[i+1][JO+1] := dp[i+1][JO+1] + dp[i - 1+1][J+1] ) else ( dp[i+1][I+1] := dp[i+1][I+1] + 1 ; dp[i+1][OI+1] := dp[i+1][OI+1] + dp[i - 1+1][O+1] ; num_JOI := num_JOI + dp[i - 1+1][JO+1] ) ) ; for k : Integer.subrange(0, 5-1) do ( dp[i+1][k+1] := dp[i+1][k+1] + dp[i - 1+1][k+1])) ; var maximum : OclAny := Set{dp[N+1][JO+1], dp[N+1][OI+1]}->max() ; for i : Integer.subrange(1, (N + 1)-1) do ( if input_str[i - 1+1] = "J" then ( maximum := Set{maximum, dp[i+1][J+1] * (dp[N+1][I+1] - dp[i+1][I+1])}->max() ) else (if input_str[i - 1+1] = "O" then ( maximum := Set{maximum, dp[i - 1+1][J+1] * (dp[N+1][I+1] - dp[i+1][I+1])}->max() ) else ( maximum := Set{maximum, dp[i - 1+1][J+1] * (dp[N+1][I+1] - dp[i+1][I+1] + 1)}->max() ) ) ) ; execute (StringLib.format("%d",(num_JOI + maximum)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=[int(x)for x in input().split()] s=set() arr=[] for i in range(1,int(n**.5)+1): if n % i==0 : s.add(i) s.add(n//i) arr=[i for i in s] arr.sort() if k>len(arr): print(-1) else : print(arr[k-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var s : Set := Set{}->union(()) ; var arr : Sequence := Sequence{} ; for i : Integer.subrange(1, ("" + (((n)->pow(.5))))->toInteger() + 1-1) do ( if n mod i = 0 then ( execute ((i) : s) ; execute ((n div i) : s) ) else skip) ; arr := s->select(i | true)->collect(i | (i)) ; arr := arr->sort() ; if (k->compareTo((arr)->size())) > 0 then ( execute (-1)->display() ) else ( execute (arr[k - 1+1])->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def prime(num): b=num for i in range(2,num): if i*i>num : break if b % i==0 : return False return True for i in range(1): n,k=map(int,input().split()) L=[] for i in range(1,int(n**.5)+1): if n % i==0 : L.append(i) if i*i!=n : L.append(n//i) L.sort() if len(L)collect( _x | (OclType["int"])->apply(_x) ) ; var L : Sequence := Sequence{} ; for i : Integer.subrange(1, ("" + (((n)->pow(.5))))->toInteger() + 1-1) do ( if n mod i = 0 then ( execute ((i) : L) ; if i * i /= n then ( execute ((n div i) : L) ) else skip ) else skip) ; L := L->sort() ; if ((L)->size()->compareTo(k)) < 0 then ( execute (-1)->display() ) else ( execute (L[k - 1+1])->display() )); operation prime(num : OclAny) : OclAny pre: true post: true activity: var b : OclAny := num ; for i : Integer.subrange(2, num-1) do ( if (i * i->compareTo(num)) > 0 then ( break ) else skip ; if b mod i = 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=[int(i)for i in input().split()] z=n**(0.5) flag=0 if(z==int(z)): z=int(z) flag=1 arr=[] if(flag==0): count=0 for i in range(1,int(z)+1): if(n % i==0): arr.append(i) arr.append(n//i) arr.sort() try : print(arr[k-1]) except : print('-1') else : count=0 for i in range(1,int(z)+1): if(n % i==0 and i!=int(z)): arr.append(i) arr.append(n//i) elif(n % i==0 and i==int(z)): arr.append(i) arr.sort() try : print(arr[k-1]) except : print('-1') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var z : double := (n)->pow((0.5)) ; var flag : int := 0 ; if (z = ("" + ((z)))->toInteger()) then ( z := ("" + ((z)))->toInteger() ; flag := 1 ) else skip ; var arr : Sequence := Sequence{} ; if (flag = 0) then ( var count : int := 0 ; for i : Integer.subrange(1, ("" + ((z)))->toInteger() + 1-1) do ( if (n mod i = 0) then ( execute ((i) : arr) ; execute ((n div i) : arr) ) else skip) ; arr := arr->sort() ; try ( execute (arr[k - 1+1])->display()) catch (_e : OclException) do ( execute ('-1')->display()) ) else ( count := 0 ; for i : Integer.subrange(1, ("" + ((z)))->toInteger() + 1-1) do ( if (n mod i = 0 & i /= ("" + ((z)))->toInteger()) then ( execute ((i) : arr) ; execute ((n div i) : arr) ) else (if (n mod i = 0 & i = ("" + ((z)))->toInteger()) then ( execute ((i) : arr) ) else skip)) ; arr := arr->sort() ; try ( execute (arr[k - 1+1])->display()) catch (_e : OclException) do ( execute ('-1')->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline a,b=map(int,input().split()) while a and b : if a>=2*b : a %=(2*b) elif b>=2*a : b %=2*a else : break print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; while a & b do ( if (a->compareTo(2 * b)) >= 0 then ( a := a mod (2 * b) ) else (if (b->compareTo(2 * a)) >= 0 then ( b := b mod 2 * a ) else ( break ) ) ) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=[int(i)for i in input().split()] l=[] i=1 while i*i<=n : if n % i==0 : l.append(i) if i!=n//i : l.append(n//i) i+=1 l=sorted(l) if k<=len(l): print(l[k-1]) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var l : Sequence := Sequence{} ; var i : int := 1 ; while (i * i->compareTo(n)) <= 0 do ( if n mod i = 0 then ( execute ((i) : l) ; if i /= n div i then ( execute ((n div i) : l) ) else skip ) else skip ; i := i + 1) ; l := l->sort() ; if (k->compareTo((l)->size())) <= 0 then ( execute (l[k - 1+1])->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math MAX=10000 ; primes=[]; def Sieve(): n=MAX ; nNew=int(math.sqrt(n)); marked=[0]*(int(n/2+500)); for i in range(1,int((nNew-1)/2)+1): for j in range(((i*(i+1))<<1),(int(n/2)+1),(2*i+1)): marked[j]=1 ; primes.append(2); for i in range(1,int(n/2)+1): if(marked[i]==0): primes.append(2*i+1); def binarySearch(left,right,n): if(left<=right): mid=int((left+right)/2); if(mid==0 or mid==len(primes)-1): return primes[mid]; if(primes[mid]==n): return primes[mid-1]; if(primes[mid]n): return primes[mid]; if(nsize() - 1, n))->display();; operation Sieve() pre: true post: true activity: var n : int := MAX; ; var nNew : int := ("" + (((n)->sqrt())))->toInteger(); ; var marked : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (("" + ((n / 2 + 500)))->toInteger())); ; for i : Integer.subrange(1, ("" + (((nNew - 1) / 2)))->toInteger() + 1-1) do ( for j : Integer.subrange(((i * (i + 1)) * (2->pow(1))), (("" + ((n / 2)))->toInteger() + 1)-1)->select( $x | ($x - ((i * (i + 1)) * (2->pow(1)))) mod (2 * i + 1) = 0 ) do ( marked[j+1] := 1;)) ; execute ((2) : primes); ; for i : Integer.subrange(1, ("" + ((n / 2)))->toInteger() + 1-1) do ( if (marked[i+1] = 0) then ( execute ((2 * i + 1) : primes); ) else skip); operation binarySearch(left : OclAny, right : OclAny, n : OclAny) pre: true post: true activity: if ((left->compareTo(right)) <= 0) then ( var mid : int := ("" + (((left + right) / 2)))->toInteger(); ; if (mid = 0 or mid = (primes)->size() - 1) then ( return primes[mid+1]; ) else skip ; if (primes[mid+1] = n) then ( return primes[mid - 1+1]; ) else skip ; if ((primes[mid+1]->compareTo(n)) < 0 & (primes[mid + 1+1]->compareTo(n)) > 0) then ( return primes[mid+1]; ) else skip ; if ((n->compareTo(primes[mid+1])) < 0) then ( return binarySearch(left, mid - 1, n); ) else ( return binarySearch(mid + 1, right, n); ) ) else skip ; return 0;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def valid(cnt): for i in range(0,26): if cnt[i]>=2 : return False return True def getGoodString(s,n): if n<26 : return "-1" for i in range(25,n): cnt=[0]*26 for j in range(i,i-26,-1): if s[j]!='?' : cnt[ord(s[j])-ord('a')]+=1 if valid(cnt): cur=0 while cur<26 and cnt[cur]>0 : cur+=1 for j in range(i-25,i+1): if s[j]=='?' : s[j]=chr(cur+ord('a')) cur+=1 while cur<26 and cnt[cur]>0 : cur+=1 return ''.join(s) return "-1" if __name__=="__main__" : s="abcdefghijkl?nopqrstuvwxy?" n=len(s) print(getGoodString(list(s),n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( s := "abcdefghijkl?nopqrstuvwxy?" ; n := (s)->size() ; execute (getGoodString((s), n))->display() ) else skip; operation valid(cnt : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, 26-1) do ( if cnt[i+1] >= 2 then ( return false ) else skip) ; return true; operation getGoodString(s : OclAny, n : OclAny) : OclAny pre: true post: true activity: if n < 26 then ( return "-1" ) else skip ; for i : Integer.subrange(25, n-1) do ( cnt := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for j : Integer.subrange(i - 26 + 1, i)->reverse() do ( if s[j+1] /= '?' then ( cnt[(s[j+1])->char2byte() - ('a')->char2byte()+1] := cnt[(s[j+1])->char2byte() - ('a')->char2byte()+1] + 1 ) else skip) ; if valid(cnt) then ( var cur : int := 0 ; while cur < 26 & cnt[cur+1] > 0 do ( cur := cur + 1) ; for j : Integer.subrange(i - 25, i + 1-1) do ( if s[j+1] = '?' then ( s[j+1] := (cur + ('a')->char2byte())->byte2char() ; cur := cur + 1 ; while cur < 26 & cnt[cur+1] > 0 do ( cur := cur + 1) ) else skip) ; return StringLib.sumStringsWithSeparator((s), '') ) else skip) ; return "-1"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isBinary(number): set1=set() while(number>0): digit=number % 10 set1.add(digit) number=int(number/10) set1.discard(0) set1.discard(1) if(len(set1)==0): return True return False if __name__=='__main__' : n=1000111 if(isBinary(n)==1): print("true") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var n : int := 1000111 ; if (isBinary(n) = 1) then ( execute ("true")->display() ) else ( execute ("No")->display() ) ) else skip; operation isBinary(number : OclAny) : OclAny pre: true post: true activity: var set1 : Set := Set{}->union(()) ; while (number > 0) do ( var digit : int := number mod 10 ; execute ((digit) : set1) ; number := ("" + ((number / 10)))->toInteger()) ; execute ((0) /: set1) ; execute ((1) /: set1) ; if ((set1)->size() = 0) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def longestSubarray(input,length): prev=-1 prevCount=0 currentCount=1 longest=1 current=input[0] for i in range(1,length): next=input[i] if next==current : currentCount+=1 elif next==prev : prevCount+=currentCount prev=current current=next currentCount=1 else : longest=max(longest,currentCount+prevCount) prev=current prevCount=currentCount current=next currentCount=1 return max(longest,currentCount+prevCount) if __name__=="__main__" : input=[5,5,6,7,6] n=len(input) print(longestSubarray(input,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( input := Sequence{5}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 6 })))) ; var n : int := (input)->size() ; execute (longestSubarray(input, n))->display() ) else skip; operation longestSubarray(input : OclAny, length : OclAny) : OclAny pre: true post: true activity: var prev : int := -1 ; var prevCount : int := 0 ; var currentCount : int := 1 ; var longest : int := 1 ; var current : String := (OclFile["System.in"]).readLine->first() ; for i : Integer.subrange(1, length-1) do ( var next : String := (OclFile["System.in"]).readLine[i+1] ; if next = current then ( currentCount := currentCount + 1 ) else (if next = prev then ( prevCount := prevCount + currentCount ; prev := current ; current := next ; currentCount := 1 ) else ( longest := Set{longest, currentCount + prevCount}->max() ; prev := current ; prevCount := currentCount ; current := next ; currentCount := 1 ) ) ) ; return Set{longest, currentCount + prevCount}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def alphabetPattern(N): Top,Bottom,Diagonal=1,1,N-1 for index in range(N): print(Top,end='') Top+=1 print() for index in range(1,N-1): for side_index in range(2*(N-index-1)): print('',end='') print(Diagonal,end='') Diagonal-=1 print() for index in range(N): print(Bottom,end='') Bottom+=1 N=5 alphabetPattern(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 5 ; alphabetPattern(N); operation alphabetPattern(N : OclAny) pre: true post: true activity: var Top : OclAny := null; var Bottom : OclAny := null; var Diagonal : OclAny := null; Sequence{Top,Bottom,Diagonal} := Sequence{1,1,N - 1} ; for index : Integer.subrange(0, N-1) do ( execute (Top)->display() ; Top := Top + 1) ; execute (->display() ; for index : Integer.subrange(1, N - 1-1) do ( for side_index : Integer.subrange(0, 2 * (N - index - 1)-1) do ( execute ('')->display()) ; execute (Diagonal)->display() ; Diagonal := Diagonal - 1 ; execute (->display()) ; for index : Integer.subrange(0, N-1) do ( execute (Bottom)->display() ; Bottom := Bottom + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() jo_cnt=0 oi_cnt=0 j_cnt=0 o_cnt=0 i_cnt=0 joi_cnt=0 j_acc=[] o_acc=[] i_acc=[] for c in s : if c=="J" : j_cnt+=1 elif c=="O" : o_cnt+=1 jo_cnt+=j_cnt else : i_cnt+=1 oi_cnt+=o_cnt joi_cnt+=jo_cnt j_acc.append(j_cnt) o_acc.append(o_cnt) i_acc.append(i_cnt) ji_cnt=max(j_acc[i]*(i_acc[-1]-i_acc[i])for i in range(n)) print(joi_cnt+max(jo_cnt,oi_cnt,ji_cnt)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var jo_cnt : int := 0 ; var oi_cnt : int := 0 ; var j_cnt : int := 0 ; var o_cnt : int := 0 ; var i_cnt : int := 0 ; var joi_cnt : int := 0 ; var j_acc : Sequence := Sequence{} ; var o_acc : Sequence := Sequence{} ; var i_acc : Sequence := Sequence{} ; for c : s->characters() do ( if c = "J" then ( j_cnt := j_cnt + 1 ) else (if c = "O" then ( o_cnt := o_cnt + 1 ; jo_cnt := jo_cnt + j_cnt ) else ( i_cnt := i_cnt + 1 ; oi_cnt := oi_cnt + o_cnt ; joi_cnt := joi_cnt + jo_cnt ) ) ; execute ((j_cnt) : j_acc) ; execute ((o_cnt) : o_acc) ; execute ((i_cnt) : i_acc)) ; var ji_cnt : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name j_acc)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i_acc)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))) - (expr (atom (name i_acc)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->max() ; execute (joi_cnt + Set{jo_cnt, oi_cnt, ji_cnt}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minRotation(input,unlock_code): rotation=0 ; while(input>0 or unlock_code>0): input_digit=input % 10 ; code_digit=unlock_code % 10 ; rotation+=min(abs(input_digit-code_digit),10-abs(input_digit-code_digit)); input=int(input/10); unlock_code=int(unlock_code/10); return rotation ; input=28756 ; unlock_code=98234 ; print("Minimum Rotation=",minRotation(input,unlock_code)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; input := 28756; ; unlock_code := 98234; ; execute ("Minimum Rotation=")->display();; operation minRotation(input : OclAny, unlock_code : OclAny) pre: true post: true activity: var rotation : int := 0; ; while (input > 0 or unlock_code > 0) do ( var input_digit : int := input mod 10; ; var code_digit : int := unlock_code mod 10; ; rotation := rotation + Set{(input_digit - code_digit)->abs(), 10 - (input_digit - code_digit)->abs()}->min(); ; input := ("" + ((input / 10)))->toInteger(); ; unlock_code := ("" + ((unlock_code / 10)))->toInteger();) ; return rotation;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- itr=int(input()) for i in range(0,itr): num=int(input()) x=list(map(int,input().split())) arr=sorted(x) ans=[] if len(arr)% 2!=0 : ans.append(arr[len(arr)//2]) for i in range(len(arr)//2): ans.append(arr[(len(arr)//2)+1+i]) ans.append(arr[(len(arr)//2)-1-i]) for item in ans : print(item,end=" ") print('') else : for i in range(len(arr)//2): ans.append(arr[(len(arr)//2)+i]) ans.append(arr[(len(arr)//2)-i-1]) for item in ans : print(item,end=" ") print('') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var itr : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, itr-1) do ( var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var arr : Sequence := x->sort() ; var ans : Sequence := Sequence{} ; if (arr)->size() mod 2 /= 0 then ( execute ((arr[(arr)->size() div 2+1]) : ans) ; for i : Integer.subrange(0, (arr)->size() div 2-1) do ( execute ((arr[((arr)->size() div 2) + 1 + i+1]) : ans) ; execute ((arr[((arr)->size() div 2) - 1 - i+1]) : ans)) ; for item : ans do ( execute (item)->display() ; execute ('')->display()) ) else ( for i : Integer.subrange(0, (arr)->size() div 2-1) do ( execute ((arr[((arr)->size() div 2) + i+1]) : ans) ; execute ((arr[((arr)->size() div 2) - i - 1+1]) : ans)) ; for item : ans do ( execute (item)->display()) ) ; execute ('')->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for _ in range(T): n=int(input()) A=list(map(int,input().split())) A.sort() res=[] l,r=0,len(A)-1 while ltoInteger() ; for _anon : Integer.subrange(0, T-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; A := A->sort() ; var res : Sequence := Sequence{} ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,(A)->size() - 1} ; while (l->compareTo(r)) < 0 do ( execute ((A[l+1]) : res) ; execute ((A[r+1]) : res) ; l := l + 1 ; r := r - 1) ; if l = r then ( execute ((A[l+1]) : res) ) else skip ; res := res->reverse() ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): l=[] n=int(input()) a=[int(x)for x in input().split()] a.sort() for k in range(0,int(len(a)/2)): l.append(a[int(len(a)/2)+k]) l.append(a[int(len(a)/2)-1-k]) if len(a)% 2!=0 : l.append(a[len(a)-1]) c="" for k in l : c+=str(k)+" " print(c[: len(c)-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var l : Sequence := Sequence{} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; a := a->sort() ; for k : Integer.subrange(0, ("" + (((a)->size() / 2)))->toInteger()-1) do ( execute ((a[("" + (((a)->size() / 2)))->toInteger() + k+1]) : l) ; execute ((a[("" + (((a)->size() / 2)))->toInteger() - 1 - k+1]) : l)) ; if (a)->size() mod 2 /= 0 then ( execute ((a[(a)->size() - 1+1]) : l) ) else skip ; var c : String := "" ; for k : l do ( c := c + ("" + ((k))) + " ") ; execute (c.subrange(1,(c)->size() - 1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) while(True): if(a==0 or b==0): break if(a>=2*b): a %=2*b elif(b>=2*a): b %=2*a else : break print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; while (true) do ( if (a = 0 or b = 0) then ( break ) else skip ; if ((a->compareTo(2 * b)) >= 0) then ( a := a mod 2 * b ) else (if ((b->compareTo(2 * a)) >= 0) then ( b := b mod 2 * a ) else ( break ) ) ) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) l=list(map(int,input().split())) l.sort() l1=l[: n//2] l2=l[n//2 :] l2.reverse() out=[] for i in range(n): if len(l1)==0 or len(l2)==0 : out+=l1 out+=l2 break out.append(l2[-1]) out.append(l1[-1]) l1.pop(-1) l2.pop(-1) print(*out,sep=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := l->sort() ; var l1 : OclAny := l.subrange(1,n div 2) ; var l2 : OclAny := l.subrange(n div 2+1) ; l2 := l2->reverse() ; var out : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if (l1)->size() = 0 or (l2)->size() = 0 then ( out := out + l1 ; out := out + l2 ; break ) else skip ; execute ((l2->last()) : out) ; execute ((l1->last()) : out) ; l1 := l1->excludingAt(-1+1) ; l2 := l2->excludingAt(-1+1)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name out))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import lru_cache digits=list(map(lambda x : str(x),range(1,10))) @ lru_cache(maxsize=None) def check(s,n): return ' '.join([s]*n) def down(x): x=list(x[: :-1]) while '0' in x : x.remove('0') x.append('#') return x def main(n): data='\n'.join(map(lambda x : input(),range(n))) score=0 while True : removed=False for d in digits : if check(d,3)in data : for i in range(5,2,-1): if check(d,i)in data : score+=int(d)*(data.count(check(d,i))*i) data=data.replace(check(d,i),check('0',i)) removed=True if removed==False : break data=zip(*map(lambda x : x.split(),data.split('\n'))) data=map(lambda x : down(x),data) data=list(map(lambda x : ' '.join(x),zip(*data))) data='\n'.join(data[: :-1]) print(score) while True : n=int(input()) if n==0 : break main(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var digits : Sequence := ((Integer.subrange(1, 10-1))->collect( _x | (lambda x : OclAny in (("" + ((x)))))->apply(_x) )) ; (compound_stmt (decorator @ (dotted_name (name lru_cache)) ( (arglist (argument (test (logical_test (comparison (expr (atom (name maxsize)))))) = (test (logical_test (comparison (expr (atom None))))))) )) (funcdef def (name check) ( (typedargslist (def_parameters (def_parameter (named_parameter (name s))) , (def_parameter (named_parameter (name n))))) ) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom ' ') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name s))))))) ])) * (expr (atom (name n))))))))) )))))))))))))) ; skip ; skip ; while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; main(n)); operation down(x : OclAny) : OclAny pre: true post: true activity: x := (x(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ; while (x)->includes('0') do ( execute (('0') /: x) ; execute (('#') : x)) ; return x; operation main(n : OclAny) pre: true post: true activity: var data : String := StringLib.sumStringsWithSeparator(((Integer.subrange(0, n-1))->collect( _x | (lambda x : OclAny in ((OclFile["System.in"]).readLine()))->apply(_x) )), ' ') ; var score : int := 0 ; while true do ( var removed : boolean := false ; for d : digits do ( if (data)->characters()->includes(check(d, 3)) then ( for i : Integer.subrange(2 + 1, 5)->reverse() do ( if (data)->characters()->includes(check(d, i)) then ( score := score + ("" + ((d)))->toInteger() * (data->count(check(d, i)) * i) ; data := data.replace(check(d, i), check('0', i)) ; removed := true ) else skip) ) else skip) ; if removed = false then ( break ) else skip ; data := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name x)) (trailer . (name split) (arguments ( ))))))))) , (argument (test (logical_test (comparison (expr (atom (name data)) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ' '))))))) ))))))))) ))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name x)) (trailer . (name split) (arguments ( ))))))))) , (argument (test (logical_test (comparison (expr (atom (name data)) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ' '))))))) ))))))))) ))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name x)) (trailer . (name split) (arguments ( ))))))))) , (argument (test (logical_test (comparison (expr (atom (name data)) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ' '))))))) ))))))))) ))))))))`third->at(_indx)} ) ; data := (data)->collect( _x | (lambda x : OclAny in (down(x)))->apply(_x) ) ; data := ((Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name data)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name data)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name data)))))))`third->at(_indx)} ))->collect( _x | (lambda x : OclAny in (StringLib.sumStringsWithSeparator((x), ' ')))->apply(_x) )) ; data := StringLib.sumStringsWithSeparator((data(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))), ' ')) ; execute (score)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : h=int(input()) if h==0 : break puyo=[list(map(int,input().split()))for _ in range(h)] p=0 fin=0 turn=1 while fin==0 : fin=1 for i in range(h): cnt=1 for j in range(1,5): if puyo[i][j-1]==puyo[i][j]and puyo[i][j]>0 : cnt+=1 else : if cnt>=3 : p+=cnt*puyo[i][j-1] for k in range(cnt): puyo[i][j-k-1]=-1 fin=0 cnt=1 if j==4 : if cnt>=3 : p+=cnt*puyo[i][j-1] for k in range(cnt): puyo[i][j-k]=-1 fin=0 for i in range(5): d_fin=0 while d_fin==0 : d_fin=1 for j in range(h-1,0,-1): if puyo[j][i]==-1 and puyo[j-1][i]>0 : puyo[j][i]=puyo[j-1][i] puyo[j-1][i]=-1 d_fin=0 turn+=1 print(p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var h : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if h = 0 then ( break ) else skip ; var puyo : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var p : int := 0 ; var fin : int := 0 ; var turn : int := 1 ; while fin = 0 do ( fin := 1 ; for i : Integer.subrange(0, h-1) do ( var cnt : int := 1 ; for j : Integer.subrange(1, 5-1) do ( if puyo[i+1][j - 1+1] = puyo[i+1][j+1] & puyo[i+1][j+1] > 0 then ( cnt := cnt + 1 ) else ( if cnt >= 3 then ( p := p + cnt * puyo[i+1][j - 1+1] ; for k : Integer.subrange(0, cnt-1) do ( puyo[i+1][j - k - 1+1] := -1 ; fin := 0) ) else skip ; cnt := 1 ) ; if j = 4 then ( if cnt >= 3 then ( p := p + cnt * puyo[i+1][j - 1+1] ; for k : Integer.subrange(0, cnt-1) do ( puyo[i+1][j - k+1] := -1 ; fin := 0) ) else skip ) else skip)) ; for i : Integer.subrange(0, 5-1) do ( var d_fin : int := 0 ; while d_fin = 0 do ( d_fin := 1 ; for j : Integer.subrange(0 + 1, h - 1)->reverse() do ( if puyo[j+1][i+1] = -1 & puyo[j - 1+1][i+1] > 0 then ( puyo[j+1][i+1] := puyo[j - 1+1][i+1] ; puyo[j - 1+1][i+1] := -1 ; d_fin := 0 ) else skip))) ; turn := turn + 1) ; execute (p)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calc(puzzle,H,score): flag=False for i in range(H-1,-1,-1): stones=[] for j in range(5): now=[j,puzzle[j][i]] if(len(stones)==0 or stones[-1][1]==now[1])and now[1]!=0 : stones.append(now) elif len(stones)<3 : stones=[now] else : break if len(stones)>2 : flag=True score+=stones[0][1]*len(stones) for stone in stones : puzzle[stone[0]].pop(i) puzzle[stone[0]].append(0) if flag==True : return calc(puzzle,H,score) else : return score if __name__=="__main__" : while True : score=0 H=int(input()) if H==0 : break puzzle=[[]for _ in range(5)] for i in range(H): temp=list(map(int,input().split())) for j in range(5): puzzle[j].insert(0,temp[j]) score=calc(puzzle,H,score) print(score) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( while true do ( score := 0 ; H := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if H = 0 then ( break ) else skip ; puzzle := Integer.subrange(0, 5-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, H-1) do ( var temp : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, 5-1) do ((expr (atom (name puzzle)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name insert) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom (name temp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) )))))) ; score := calc(puzzle, H, score) ; execute (score)->display()) ) else skip; operation calc(puzzle : OclAny, H : OclAny, score : OclAny) : OclAny pre: true post: true activity: var flag : boolean := false ; for i : Integer.subrange(-1 + 1, H - 1)->reverse() do ( var stones : Sequence := Sequence{} ; for j : Integer.subrange(0, 5-1) do ( var now : Sequence := Sequence{j}->union(Sequence{ puzzle[j+1][i+1] }) ; if ((stones)->size() = 0 or stones->last()[1+1] = now[1+1]) & now[1+1] /= 0 then ( execute ((now) : stones) ) else (if (stones)->size() < 3 then ( stones := Sequence{ now } ) else ( break ) ) ) ; if (stones)->size() > 2 then ( flag := true ; score := score + stones->first()[1+1] * (stones)->size() ; for stone : stones do ((expr (atom (name puzzle)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name stone)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])) (trailer . (name pop) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ; (expr (atom (name puzzle)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name stone)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))))) ) else skip) ; if flag = true then ( return calc(puzzle, H, score) ) else ( return score ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from inspect import currentframe def debug_print(s): return def debug_key(*args): names={id(v): k for k,v in currentframe().f_back.f_locals.items()} debug_print(','.join(names.get(id(arg),'???')+'='+repr(arg)for arg in args)) def solve(H,stone): debug_print("\n-----solve-----") debug_key(stone) ans=-1 tmp=1 while tmp : ans+=tmp tmp=0 erase=[set()for _ in range(5)] for i in range(H): for j in range(1,4): if stone[i][j-1]==stone[i][j]==stone[i][j+1]: for k in range(j-1,j+2): erase[k].add(i) stone2=list(map(list,zip(*stone))) for j in range(5): for i in sorted(erase[j],reverse=True): tmp+=stone[i][j] del stone2[j][i] stone2[j]=[0]*len(erase[j])+stone2[j] stone=list(map(list,zip(*stone2))) print(ans) return if __name__=='__main__' : while True : H_input=int(input()) if H_input==0 : break stone_input=[list(map(int,input().split()))for _ in range(H_input)] solve(H_input,stone_input) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( while true do ( var H_input : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if H_input = 0 then ( break ) else skip ; var stone_input : Sequence := Integer.subrange(0, H_input-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; solve(H_input, stone_input)) ) else skip; operation debug_print(s : OclAny) pre: true post: true activity: return; operation debug_key(args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) var names : Map := currentframe().f_back.f_locals->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->select(_tuple | true)->collect(_tuple | Map{?(v) |-> k})->unionAll() ; debug_print(StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (expr (expr (atom (name names)) (trailer . (name get) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name id)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arg)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom '???'))))))) )))) + (expr (atom '='))) + (expr (atom (name repr)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arg)))))))) )))))))) (comp_for for (exprlist (expr (atom (name arg)))) in (logical_test (comparison (expr (atom (name args)))))))), ',')); operation solve(H : OclAny, stone : OclAny) pre: true post: true activity: debug_print("\n-----solve-----") ; debug_key(stone) ; var ans : int := -1 ; var tmp : int := 1 ; while tmp do ( ans := ans + tmp ; tmp := 0 ; var erase : Sequence := Integer.subrange(0, 5-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; for i : Integer.subrange(0, H-1) do ( for j : Integer.subrange(1, 4-1) do ( if stone[i+1][j - 1+1] = stone[i+1][j+1] & (stone[i+1][j+1] == stone[i+1][j + 1+1]) then ( for k : Integer.subrange(j - 1, j + 2-1) do ((expr (atom (name erase)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ) else skip)) ; var stone2 : Sequence := ((Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name stone)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name stone)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name stone)))))))`third->at(_indx)} ))->collect( _x | (OclType["Sequence"])->apply(_x) )) ; for j : Integer.subrange(0, 5-1) do ( for i : erase[j+1]->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) do ( tmp := tmp + stone[i+1][j+1] ; execute (stone2[j+1][i+1])->isDeleted()) ; stone2[j+1] := MatrixLib.elementwiseMult(Sequence{ 0 }, (erase[j+1])->size())->union(stone2[j+1])) ; stone := ((Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name stone2)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name stone2)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name stone2)))))))`third->at(_indx)} ))->collect( _x | (OclType["Sequence"])->apply(_x) ))) ; execute (ans)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Dice : def __init__(self,eyes): self._eyes=['dummy']+eyes @ property def eye(self): return self._eyes[1] def roll(self,direction): a=self._eyes if direction=='N' : self._eyes=['dummy',a[2],a[6],a[3],a[4],a[1],a[5]] elif direction=='S' : self._eyes=['dummy',a[5],a[1],a[3],a[4],a[6],a[2]] elif direction=='W' : self._eyes=['dummy',a[3],a[2],a[6],a[1],a[5],a[4]] elif direction=='E' : self._eyes=['dummy',a[4],a[2],a[1],a[6],a[5],a[3]] else : raise ValueError('NEWS') eyes=input().split() dice=Dice(eyes) direction_text=input() for d in direction_text : dice.roll(d) print(dice.eye) ------------------------------------------------------------ OCL File: --------- class Dice { static operation newDice() : Dice pre: true post: Dice->exists( _x | result = _x ); attribute _eyes : Sequence := Sequence{ 'dummy' }->union(eyes); operation initialise(eyes : OclAny) : Dice pre: true post: true activity: self._eyes := Sequence{ 'dummy' }->union(eyes); return self; operation roll(direction : OclAny) pre: true post: true activity: var a : OclAny := self._eyes ; if direction = 'N' then ( self._eyes := Sequence{'dummy'}->union(Sequence{a[2+1]}->union(Sequence{a[6+1]}->union(Sequence{a[3+1]}->union(Sequence{a[4+1]}->union(Sequence{a[1+1]}->union(Sequence{ a[5+1] })))))) ) else (if direction = 'S' then ( self._eyes := Sequence{'dummy'}->union(Sequence{a[5+1]}->union(Sequence{a[1+1]}->union(Sequence{a[3+1]}->union(Sequence{a[4+1]}->union(Sequence{a[6+1]}->union(Sequence{ a[2+1] })))))) ) else (if direction = 'W' then ( self._eyes := Sequence{'dummy'}->union(Sequence{a[3+1]}->union(Sequence{a[2+1]}->union(Sequence{a[6+1]}->union(Sequence{a[1+1]}->union(Sequence{a[5+1]}->union(Sequence{ a[4+1] })))))) ) else (if direction = 'E' then ( self._eyes := Sequence{'dummy'}->union(Sequence{a[4+1]}->union(Sequence{a[2+1]}->union(Sequence{a[1+1]}->union(Sequence{a[6+1]}->union(Sequence{a[5+1]}->union(Sequence{ a[3+1] })))))) ) else ( error IncorrectElementException.newIncorrectElementException('NEWS') ) ) ) ) ; } class FromPython { operation initialise() pre: true post: true activity: skip ; eyes := input().split() ; var dice : Dice := (Dice.newDice()).initialise(eyes) ; var direction_text : String := (OclFile["System.in"]).readLine() ; for d : direction_text->characters() do ( dice.roll(d)) ; execute (dice.eye)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter def inpl(): return list(map(int,input().split())) N=int(input()) while N : B=[inpl()for _ in range(N)] ans=-1 tmp=1 while tmp : ans+=tmp tmp=0 erase=[set()for _ in range(5)] for i in range(N): for j in range(1,4): if B[i][j-1]==B[i][j]==B[i][j+1]: for k in range(j-1,j+2): erase[k].add(i) B2=list(map(list,zip(*B))) for j in range(5): for i in sorted(erase[j],reverse=True): tmp+=B[i][j] del B2[j][i] B2[j]=[0]*len(erase[j])+B2[j] B=list(map(list,zip(*B2))) print(ans) N=int(input()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while N do ( var B : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (inpl())) ; var ans : int := -1 ; var tmp : int := 1 ; while tmp do ( ans := ans + tmp ; tmp := 0 ; var erase : Sequence := Integer.subrange(0, 5-1)->select(_anon | true)->collect(_anon | (Set{}->union(()))) ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(1, 4-1) do ( if B[i+1][j - 1+1] = B[i+1][j+1] & (B[i+1][j+1] == B[i+1][j + 1+1]) then ( for k : Integer.subrange(j - 1, j + 2-1) do ((expr (atom (name erase)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ) else skip)) ; var B2 : Sequence := ((Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name B)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name B)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name B)))))))`third->at(_indx)} ))->collect( _x | (OclType["Sequence"])->apply(_x) )) ; for j : Integer.subrange(0, 5-1) do ( for i : erase[j+1]->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) do ( tmp := tmp + B[i+1][j+1] ; execute (B2[j+1][i+1])->isDeleted()) ; B2[j+1] := MatrixLib.elementwiseMult(Sequence{ 0 }, (erase[j+1])->size())->union(B2[j+1])) ; B := ((Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name B2)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name B2)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name B2)))))))`third->at(_indx)} ))->collect( _x | (OclType["Sequence"])->apply(_x) ))) ; execute (ans)->display() ; N := ("" + (((OclFile["System.in"]).readLine())))->toInteger()); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def search(a,k,x): for j in range(k-1,-1,-1): if(a[j]==x): return j return-1 def genArray(arr,N): for i in range(0,N-1,1): if(search(arr,i,arr[i])==-1): arr[i+1]=0 else : arr[i+1]=(i-search(arr,i,arr[i])) if __name__=="__main__" : N=5 size=N+1 a=[0]*N genArray(a,N) print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( N := 5 ; var size : OclAny := N + 1 ; a := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; genArray(a, N) ; execute (a)->display() ) else skip; operation search(a : OclAny, k : OclAny, x : OclAny) : OclAny pre: true post: true activity: for j : Integer.subrange(-1 + 1, k - 1)->reverse() do ( if (a[j+1] = x) then ( return j ) else skip) ; return -1; operation genArray(arr : OclAny, N : OclAny) pre: true post: true activity: for i : Integer.subrange(0, N - 1-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (search(arr, i, arr[i+1]) = -1) then ( arr[i + 1+1] := 0 ) else ( arr[i + 1+1] := (i - search(arr, i, arr[i+1])) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans=0 graph=[[]for i in range(100)] weight=[0]*100 def isEvenParity(x): parity=0 while(x!=0): x=x &(x-1) parity+=1 if(parity % 2==0): return True else : return False def dfs(node,parent): global ans if(isEvenParity(weight[node])): ans+=1 for to in graph[node]: if(to==parent): continue dfs(to,node) weight[1]=5 weight[2]=10 weight[3]=11 weight[4]=8 weight[5]=6 graph[1].append(2) graph[2].append(3) graph[2].append(4) graph[1].append(5) dfs(1,1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute ans : OclAny; operation initialise() pre: true post: true activity: var ans : int := 0 ; var graph : Sequence := Integer.subrange(0, 100-1)->select(i | true)->collect(i | (Sequence{})) ; var weight : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100) ; skip ; skip ; weight[1+1] := 5 ; weight[2+1] := 10 ; weight[3+1] := 11 ; weight[4+1] := 8 ; weight[5+1] := 6 ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 3))))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 4))))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 5))))))))) )))) ; dfs(1, 1) ; execute (ans)->display(); operation isEvenParity(x : OclAny) : OclAny pre: true post: true activity: var parity : int := 0 ; while (x /= 0) do ( x := MathLib.bitwiseAnd(x, (x - 1)) ; parity := parity + 1) ; if (parity mod 2 = 0) then ( return true ) else ( return false ); operation dfs(node : OclAny, parent : OclAny) pre: true post: true activity: skip ; if (isEvenParity(weight[node+1])) then ( ans := ans + 1 ) else skip ; for to : graph[node+1] do ( if (to = parent) then ( continue ) else skip ; dfs(to, node)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isVowel(c): return(c=='a' or c=='A' or c=='e' or c=='E' or c=='i' or c=='I' or c=='o' or c=='O' or c=='u' or c=='U') def reverseVowel(str): i=0 j=len(str)-1 while(idisplay() ) else skip; operation isVowel(c : OclAny) : OclAny pre: true post: true activity: return (c = 'a' or c = 'A' or c = 'e' or c = 'E' or c = 'i' or c = 'I' or c = 'o' or c = 'O' or c = 'u' or c = 'U'); operation reverseVowel(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; var j : double := (OclType["String"])->size() - 1 ; while ((i->compareTo(j)) < 0) do ( if not(isVowel(("" + ([i+1])))) then ( i := i + 1 ; continue ) else skip ; if (not(isVowel(("" + ([j+1]))))) then ( j := j - 1 ; continue ) else skip ; var ("" + ([i+1])) : OclAny := null; var ("" + ([j+1])) : OclAny := null; Sequence{("" + ([i+1])),("" + ([j+1]))} := Sequence{("" + ([j+1])),("" + ([i+1]))} ; i := i + 1 ; j := j - 1) ; return OclType["String"]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def areAllBitsSet(n): if(n==0): return False ; if(((n+1)& n)==0): return True ; return False ; def isOnesComplementOfOther(a,b): return areAllBitsSet(a ^ b) a=1 b=14 if(isOnesComplementOfOther(a,b)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 1 ; b := 14 ; if (isOnesComplementOfOther(a, b)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation areAllBitsSet(n : OclAny) pre: true post: true activity: if (n = 0) then ( return false; ) else skip ; if ((MathLib.bitwiseAnd((n + 1), n)) = 0) then ( return true; ) else skip ; return false;; operation isOnesComplementOfOther(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return areAllBitsSet(MathLib.bitwiseXor(a, b)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys def _input(): return map(int,input().split()) a,b=_input() while a!=0 and b!=0 and(a>=2*b or b>=2*a): if a>=2*b : a-=(a//(2*b))*2*b else : b-=(b//(2*a))*2*a print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := _input() ; while a /= 0 & b /= 0 & ((a->compareTo(2 * b)) >= 0 or (b->compareTo(2 * a)) >= 0) do ( if (a->compareTo(2 * b)) >= 0 then ( a := a - (a div (2 * b)) * 2 * b ) else ( b := b - (b div (2 * a)) * 2 * a )) ; execute (a)->display(); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- SIZE=26 from math import sqrt def SieveOfEratosthenes(prime,p_size): prime[0]=False prime[1]=False for p in range(2,int(sqrt(p_size)),1): if(prime[p]): for i in range(p*2,p_size,p): prime[i]=False def printChar(str,n): prime=[True for i in range(n+1)] SieveOfEratosthenes(prime,len(str)+1) freq=[0 for i in range(SIZE)] for i in range(n): freq[ord(str[i])-ord('a')]+=1 for i in range(n): if(prime[freq[ord(str[i])-ord('a')]]): print(str[i],end="") if __name__=='__main__' : str="geeksforgeeks" n=len(str) printChar(str,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var SIZE : int := 26 ; skip ; skip ; skip ; if __name__ = '__main__' then ( OclType["String"] := "geeksforgeeks" ; n := (OclType["String"])->size() ; printChar(OclType["String"], n) ) else skip; operation SieveOfEratosthenes(prime : OclAny, p_size : OclAny) pre: true post: true activity: prime->first() := false ; prime[1+1] := false ; for p : Integer.subrange(2, ("" + ((sqrt(p_size))))->toInteger()-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (prime[p+1]) then ( for i : Integer.subrange(p * 2, p_size-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip); operation printChar(OclType["String"] : OclAny, n : OclAny) pre: true post: true activity: prime := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (true)) ; SieveOfEratosthenes(prime, (OclType["String"])->size() + 1) ; var freq : Sequence := Integer.subrange(0, SIZE-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( freq[(("" + ([i+1])))->char2byte() - ('a')->char2byte()+1] := freq[(("" + ([i+1])))->char2byte() - ('a')->char2byte()+1] + 1) ; for i : Integer.subrange(0, n-1) do ( if (prime[freq[(("" + ([i+1])))->char2byte() - ('a')->char2byte()+1]+1]) then ( execute (("" + ([i+1])))->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) b.sort() ans=m for i in a : x=(b[0]-i)% m a0=[(j+x)% m for j in a] a0.sort() ok=1 for j,k in zip(a0,b): if j ^ k : ok=0 break if ok : ans=min(ans,x) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; b := b->sort() ; var ans : OclAny := m ; for i : a do ( var x : int := (b->first() - i) mod m ; var a0 : Sequence := a->select(j | true)->collect(j | ((j + x) mod m)) ; a0 := a0->sort() ; var ok : int := 1 ; for _tuple : Integer.subrange(1, a0->size())->collect( _indx | Sequence{a0->at(_indx), b->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var k : OclAny := _tuple->at(_indx); if MathLib.bitwiseXor(j, k) then ( ok := 0 ; break ) else skip) ; if ok then ( ans := Set{ans, x}->min() ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) a.sort() b.sort() cont=m for i in range(n): c=(b[i]-a[0]+m)% m flag=False for j in range(n): if(a[j]+c)% m!=b[(i+j)% n]: flag=True if not flag : cont=cont if contcollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; b := b->sort() ; var cont : OclAny := m ; for i : Integer.subrange(0, n-1) do ( var c : int := (b[i+1] - a->first() + m) mod m ; var flag : boolean := false ; for j : Integer.subrange(0, n-1) do ( if (a[j+1] + c) mod m /= b[(i + j) mod n+1] then ( flag := true ) else skip) ; if not(flag) then ( cont := if (cont->compareTo(c)) < 0 then cont else c endif ) else skip) ; execute (cont)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) a.sort() b.sort() b+=b r=m for i in range(n): x=(b[i]+m-a[0])% m ok=True j=0 while jcollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; b := b->sort() ; b := b + b ; var r : OclAny := m ; for i : Integer.subrange(0, n-1) do ( var x : int := (b[i+1] + m - a->first()) mod m ; var ok : boolean := true ; var j : int := 0 ; while (j->compareTo(n)) < 0 do ( if (a[j+1] + x) mod m /= b[i + j+1] then ( ok := false ; break ) else skip ; j := j + 1) ; if ok then ( r := Set{r, x}->min() ) else skip) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dice=[0 for i in range(6)] dice=list(input().split()) order=list(input()) for i in range(0,len(order)): if order[i]=="S" : temp=dice[0] dice[0]=dice[4] dice[4]=dice[5] dice[5]=dice[1] dice[1]=temp elif order[i]=="E" : temp=dice[0] dice[0]=dice[3] dice[3]=dice[5] dice[5]=dice[2] dice[2]=temp elif order[i]=="W" : temp=dice[0] dice[0]=dice[2] dice[2]=dice[5] dice[5]=dice[3] dice[3]=temp elif order[i]=="N" : temp=dice[0] dice[0]=dice[1] dice[1]=dice[5] dice[5]=dice[4] dice[4]=temp print("{0}".format(dice[0])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dice : Sequence := Integer.subrange(0, 6-1)->select(i | true)->collect(i | (0)) ; dice := (input().split()) ; var order : Sequence := ((OclFile["System.in"]).readLine())->characters() ; for i : Integer.subrange(0, (order)->size()-1) do ( if order[i+1] = "S" then ( var temp : OclAny := dice->first() ; dice->first() := dice[4+1] ; dice[4+1] := dice[5+1] ; dice[5+1] := dice[1+1] ; dice[1+1] := temp ) else (if order[i+1] = "E" then ( temp := dice->first() ; dice->first() := dice[3+1] ; dice[3+1] := dice[5+1] ; dice[5+1] := dice[2+1] ; dice[2+1] := temp ) else (if order[i+1] = "W" then ( temp := dice->first() ; dice->first() := dice[2+1] ; dice[2+1] := dice[5+1] ; dice[5+1] := dice[3+1] ; dice[3+1] := temp ) else (if order[i+1] = "N" then ( temp := dice->first() ; dice->first() := dice[1+1] ; dice[1+1] := dice[5+1] ; dice[5+1] := dice[4+1] ; dice[4+1] := temp ) else skip ) ) ) ) ; execute (StringLib.interpolateStrings("{0}", Sequence{dice->first()}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) b.sort() aux=[] for i in range(n): aux.append((b[0]-a[i])% m) aux=list(set(aux)) temp=[] res=0 while temp!=b : for i in aux : res=i temp=[] for j in range(n): temp.append((a[j]+i)% m) temp.sort() if temp==b : break print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; b := b->sort() ; var aux : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((b->first() - a[i+1]) mod m) : aux)) ; aux := (Set{}->union((aux))) ; var temp : Sequence := Sequence{} ; var res : int := 0 ; while temp /= b do ( for i : aux do ( res := i ; temp := Sequence{} ; for j : Integer.subrange(0, n-1) do ( execute (((a[j+1] + i) mod m) : temp)) ; temp := temp->sort() ; if temp = b then ( break ) else skip)) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict tc=list(map(int,input().rstrip().split())) n=tc[0] m=tc[1] arr=list(map(int,input().rstrip().split())) brr=list(map(int,input().rstrip().split())) for i in range(n): brr[i]%=m arr.sort() brr.sort() ans=-1 crr=[] for i in range(n): df=brr[0]-arr[0] zen=0 if(df<0): df+=(m % 1000000007) for j in range(1,n): diff=brr[j]-arr[j] if(diff<0): diff+=(m % 1000000007) if(diff!=df): zen=1 break if(zen==0): ans=df crr.append(ans) tmp=arr[0] arr.pop(0) arr.append(tmp) print(min(crr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var tc : Sequence := ((input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := tc->first() ; var m : OclAny := tc[1+1] ; var arr : Sequence := ((input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var brr : Sequence := ((input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( brr[i+1] := brr[i+1] mod m) ; arr := arr->sort() ; brr := brr->sort() ; var ans : int := -1 ; var crr : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var df : double := brr->first() - arr->first() ; var zen : int := 0 ; if (df < 0) then ( df := df + (m mod 1000000007) ) else skip ; for j : Integer.subrange(1, n-1) do ( var diff : double := brr[j+1] - arr[j+1] ; if (diff < 0) then ( diff := diff + (m mod 1000000007) ) else skip ; if (diff /= df) then ( zen := 1 ; break ) else skip) ; if (zen = 0) then ( ans := df ; execute ((ans) : crr) ) else skip ; var tmp : OclAny := arr->first() ; arr := arr->excludingAt(0+1) ; execute ((tmp) : arr)) ; execute ((crr)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(" ".join([str(y)for y in sorted([int(x)for x in input().split(" ")])])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (StringLib.sumStringsWithSeparator((input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger()))->sort()->select(y | true)->collect(y | (("" + ((y)))))), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) if a>b : if b>c : print("{}{}{}".format(c,b,a)) else : if a>c : print("{}{}{}".format(b,c,a)) else : print("{}{}{}".format(b,a,c)) else : if a>c : print("{}{}{}".format(c,a,b)) else : if b>c : print("{}{}{}".format(a,c,b)) else : print("{}{}{}".format(a,b,c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(b)) > 0 then ( if (b->compareTo(c)) > 0 then ( execute (StringLib.interpolateStrings("{}{}{}", Sequence{c, b, a}))->display() ) else ( if (a->compareTo(c)) > 0 then ( execute (StringLib.interpolateStrings("{}{}{}", Sequence{b, c, a}))->display() ) else ( execute (StringLib.interpolateStrings("{}{}{}", Sequence{b, a, c}))->display() ) ) ) else ( if (a->compareTo(c)) > 0 then ( execute (StringLib.interpolateStrings("{}{}{}", Sequence{c, a, b}))->display() ) else ( if (b->compareTo(c)) > 0 then ( execute (StringLib.interpolateStrings("{}{}{}", Sequence{a, c, b}))->display() ) else ( execute (StringLib.interpolateStrings("{}{}{}", Sequence{a, b, c}))->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- nums=input().split() a=int(nums[0]) b=int(nums[1]) c=int(nums[2]) if a>b : tmp=a a=b b=tmp if b>c : tmp=b b=c c=tmp if a>b : tmp=a a=b b=tmp print(a,b,c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var nums : OclAny := input().split() ; var a : int := ("" + ((nums->first())))->toInteger() ; var b : int := ("" + ((nums[1+1])))->toInteger() ; var c : int := ("" + ((nums[2+1])))->toInteger() ; if (a->compareTo(b)) > 0 then ( var tmp : int := a ; a := b ; b := tmp ) else skip ; if (b->compareTo(c)) > 0 then ( tmp := b ; b := c ; c := tmp ) else skip ; if (a->compareTo(b)) > 0 then ( tmp := a ; a := b ; b := tmp ) else skip ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=map(int,raw_input().split()) i=min(l) l.remove(min(l)) n=min(l) l.remove(min(l)) m=min(l) print("{0}{1}{2}".format(i,n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var i : OclAny := (l)->min() ; execute (((l)->min()) /: l) ; var n : OclAny := (l)->min() ; execute (((l)->min()) /: l) ; var m : OclAny := (l)->min() ; execute (StringLib.interpolateStrings("{0}{1}{2}", Sequence{i, n, m}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(idx=None): n=int(input()) time=input() ans=0 for s in time[:-1]: if s!='0' : ans+=int(s)+1 ans+=int(time[-1]) print(ans) if __name__=='__main__' : for i in range(int(input())): solve(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve(i)) ) else skip; operation solve(idx : OclAny) pre: true post: true activity: if idx->oclIsUndefined() then idx := null else skip; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var time : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; for s : time->front() do ( if s /= '0' then ( ans := ans + ("" + ((s)))->toInteger() + 1 ) else skip) ; ans := ans + ("" + ((time->last())))->toInteger() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() sss=s.split() sss.sort() a=int(sss[0]) b=int(sss[1]) c=int(sss[2]) print(a,b,c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var sss : OclAny := s.split() ; sss := sss->sort() ; var a : int := ("" + ((sss->first())))->toInteger() ; var b : int := ("" + ((sss[1+1])))->toInteger() ; var c : int := ("" + ((sss[2+1])))->toInteger() ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys N=50001 lst=[True]*N lst[0]=False lst[1]=False for i in range(2,int(N**0.5)+1): if lst[i]: for j in range(i*i,N,i): lst[j]=False primes=[i for i in range(1,N)if lst[i]] for s in sys.stdin : n=int(s) if n==0 : break elif n % 2==1 : if lst[n-2]: print(1) else : print(0) elif n==4 : print(1) else : counter=0 for prime0 in primes : prime1=n-prime0 if prime0<=prime1 and lst[prime1]: counter+=1 print(counter) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 50001 ; var lst : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, N) ; lst->first() := false ; lst[1+1] := false ; for i : Integer.subrange(2, ("" + (((N)->pow(0.5))))->toInteger() + 1-1) do ( if lst[i+1] then ( for j : Integer.subrange(i * i, N-1)->select( $x | ($x - i * i) mod i = 0 ) do ( lst[j+1] := false) ) else skip) ; var primes : Sequence := Integer.subrange(1, N-1)->select(i | lst[i+1])->collect(i | (i)) ; for s : OclFile["System.in"] do ( var n : int := ("" + ((s)))->toInteger() ; if n = 0 then ( break ) else (if n mod 2 = 1 then ( if lst[n - 2+1] then ( execute (1)->display() ) else ( execute (0)->display() ) ) else (if n = 4 then ( execute (1)->display() ) else ( var counter : int := 0 ; for prime0 : primes do ( var prime1 : double := n - prime0 ; if (prime0->compareTo(prime1)) <= 0 & lst[prime1+1] then ( counter := counter + 1 ) else skip) ; execute (counter)->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect,sys from itertools import* n=range(50001); a=list(n); a[1]=0 for i in range(2,224): a[i*2 : : i]=[0]*len(a[i*2 : : i]) p=list(compress(n,a)) for x in map(int,sys.stdin): if x : print(len([1 for d in p[: bisect.bisect(p,x//2)]if a[x-d]])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : Sequence := Integer.subrange(0, 50001-1); var a : Sequence := (n); a[1+1] := 0 ; for i : Integer.subrange(2, 224-1) do ( a(subscript (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom (number (integer 2)))))))) : (sliceop : (test (logical_test (comparison (expr (atom (name i)))))))) := MatrixLib.elementwiseMult(Sequence{ 0 }, (a(subscript (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom (number (integer 2)))))))) : (sliceop : (test (logical_test (comparison (expr (atom (name i)))))))))->size())) ; var p : Sequence := (compress(n, a)) ; for x : (OclFile["System.in"])->collect( _x | (OclType["int"])->apply(_x) ) do ( if x then ( execute ((p.subrange(1,bisect.bisect(p, x div 2))->select(d | a[x - d+1])->collect(d | (1)))->size())->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Dice : __slots__=['n1','n2','n3','n4','n5','n6'] def __init__(self,n_tup): self.n1=n_tup[0] self.n2=n_tup[1] self.n3=n_tup[2] self.n4=n_tup[3] self.n5=n_tup[4] self.n6=n_tup[5] def roll(self,direction): if direction=="N" : self.n1,self.n2,self.n6,self.n5=self.n2,self.n6,self.n5,self.n1 elif direction=="E" : self.n1,self.n3,self.n6,self.n4=self.n4,self.n1,self.n3,self.n6 if direction=="S" : self.n1,self.n2,self.n6,self.n5=self.n5,self.n1,self.n2,self.n6 if direction=="W" : self.n1,self.n3,self.n6,self.n4=self.n3,self.n6,self.n4,self.n1 dice=Dice([int(x)for x in input().split()]) cmd=input() for i in range(len(cmd)): dice.roll(cmd[i]) print(dice.n1) ------------------------------------------------------------ OCL File: --------- class Dice { static operation newDice() : Dice pre: true post: Dice->exists( _x | result = _x ); static attribute __slots__ : Sequence := Sequence{'n1'}->union(Sequence{'n2'}->union(Sequence{'n3'}->union(Sequence{'n4'}->union(Sequence{'n5'}->union(Sequence{ 'n6' }))))); attribute n1 : OclAny := n_tup->first(); attribute n2 : OclAny := n_tup[1+1]; attribute n3 : OclAny := n_tup[2+1]; attribute n4 : OclAny := n_tup[3+1]; attribute n5 : OclAny := n_tup[4+1]; attribute n6 : OclAny := n_tup[5+1]; operation initialise(n_tup : OclAny) : Dice pre: true post: true activity: self.n1 := n_tup->first() ; self.n2 := n_tup[1+1] ; self.n3 := n_tup[2+1] ; self.n4 := n_tup[3+1] ; self.n5 := n_tup[4+1] ; self.n6 := n_tup[5+1]; return self; operation roll(direction : OclAny) pre: true post: true activity: if direction = "N" then ( var self.n1 : OclAny := null; var self.n2 : OclAny := null; var self.n6 : OclAny := null; var self.n5 : OclAny := null; Sequence{self.n1,self.n2,self.n6,self.n5} := Sequence{self.n2,self.n6,self.n5,self.n1} ) else (if direction = "E" then ( var self.n1 : OclAny := null; var self.n3 : OclAny := null; var self.n6 : OclAny := null; var self.n4 : OclAny := null; Sequence{self.n1,self.n3,self.n6,self.n4} := Sequence{self.n4,self.n1,self.n3,self.n6} ) else skip) ; if direction = "S" then ( var self.n1 : OclAny := null; var self.n2 : OclAny := null; var self.n6 : OclAny := null; var self.n5 : OclAny := null; Sequence{self.n1,self.n2,self.n6,self.n5} := Sequence{self.n5,self.n1,self.n2,self.n6} ) else skip ; if direction = "W" then ( var self.n1 : OclAny := null; var self.n3 : OclAny := null; var self.n6 : OclAny := null; var self.n4 : OclAny := null; Sequence{self.n1,self.n3,self.n6,self.n4} := Sequence{self.n3,self.n6,self.n4,self.n1} ) else skip; } class FromPython { operation initialise() pre: true post: true activity: skip ; var dice : Dice := (Dice.newDice()).initialise(input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) ; var cmd : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, (cmd)->size()-1) do ( dice.roll(cmd[i+1])) ; execute (dice.n1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline write=sys.stdout.write L=50000 sq=int(L**.5) p=[1]*(L+1) p[0]=p[1]=0 pn=[] for x in range(sq+1): if not p[x]: continue for y in range(x*x,L+1,x): p[y]=0 pn.append(x) for x in range(sq+1,L+1): if not p[x]: continue pn.append(x) pp=[0]*(L+1) L0=len(pn) for i in range(L0): x=pn[i] for j in range(i+1): z=x+pn[j] if z>L : break pp[z]+=1 def solve(): N=int(readline()) if N==0 : return False write("%d\n" % pp[N]) return True while solve(): ... ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var write : OclAny := (OclFile["System.out"]).write ; var L : int := 50000 ; var sq : int := ("" + (((L)->pow(.5))))->toInteger() ; var p : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (L + 1)) ; p->first() := 0; var p[1+1] : int := 0 ; var pn : Sequence := Sequence{} ; for x : Integer.subrange(0, sq + 1-1) do ( if not(p[x+1]) then ( continue ) else skip ; for y : Integer.subrange(x * x, L + 1-1)->select( $x | ($x - x * x) mod x = 0 ) do ( p[y+1] := 0) ; execute ((x) : pn)) ; for x : Integer.subrange(sq + 1, L + 1-1) do ( if not(p[x+1]) then ( continue ) else skip ; execute ((x) : pn)) ; var pp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (L + 1)) ; var L0 : int := (pn)->size() ; for i : Integer.subrange(0, L0-1) do ( var x : OclAny := pn[i+1] ; for j : Integer.subrange(0, i + 1-1) do ( var z : OclAny := x + pn[j+1] ; if (z->compareTo(L)) > 0 then ( break ) else skip ; pp[z+1] := pp[z+1] + 1)) ; skip ; while solve() do (); operation solve() : OclAny pre: true post: true activity: var N : int := ("" + ((readline())))->toInteger() ; if N = 0 then ( return false ) else skip ; write(StringLib.format("%d\n",pp[N+1])) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def primes(n): l=[1 for i in range(n+1)] l[0]=l[1]=0 for i in range(2,int((n)**(1/2))+1): if l[i]==1 : for j in range(2,n//i+1): l[i*j]=0 return l l=primes(50000) while True : n=int(input()) if n==0 : break count=0 if not(n % 2): for i in range(3,n//2+1,2): if(l[i]and l[n-i]): count+=1 if n==4 : count=1 else : if l[n-2]: count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; l := primes(50000) ; while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var count : int := 0 ; if not((n mod 2)) then ( for i : Integer.subrange(3, n div 2 + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if (l[i+1] & l[n - i+1]) then ( count := count + 1 ) else skip) ; if n = 4 then ( count := 1 ) else skip ) else ( if l[n - 2+1] then ( count := count + 1 ) else skip ) ; execute (count)->display()); operation primes(n : OclAny) : OclAny pre: true post: true activity: var l : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (1)) ; l->first() := 0; var l[1+1] : int := 0 ; for i : Integer.subrange(2, ("" + ((((n))->pow((1 / 2)))))->toInteger() + 1-1) do ( if l[i+1] = 1 then ( for j : Integer.subrange(2, n div i + 1-1) do ( l[i * j+1] := 0) ) else skip) ; return l; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- LIM=50001 is_prime=[True for _ in range(LIM)] is_prime[0]=is_prime[1]=False for x in range(LIM//2+1): if is_prime[x]: for y in range(x*x,LIM,x): is_prime[y]=False primes=[x for x in range(LIM)if is_prime[x]] count_arr=[0 for x in range(LIM)] len_primes=len(primes) for x in range(len_primes): p=primes[x] for y in range(x,len_primes): q=primes[y] if p+q>=LIM : break count_arr[p+q]+=1 while True : n=int(input()) if n==0 : break print(count_arr[n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var LIM : int := 50001 ; var is_prime : Sequence := Integer.subrange(0, LIM-1)->select(_anon | true)->collect(_anon | (true)) ; is_prime->first() := false; var is_prime[1+1] : boolean := false ; for x : Integer.subrange(0, LIM div 2 + 1-1) do ( if is_prime[x+1] then ( for y : Integer.subrange(x * x, LIM-1)->select( $x | ($x - x * x) mod x = 0 ) do ( is_prime[y+1] := false) ) else skip) ; var primes : Sequence := Integer.subrange(0, LIM-1)->select(x | is_prime[x+1])->collect(x | (x)) ; var count_arr : Sequence := Integer.subrange(0, LIM-1)->select(x | true)->collect(x | (0)) ; var len_primes : int := (primes)->size() ; for x : Integer.subrange(0, len_primes-1) do ( var p : OclAny := primes[x+1] ; for y : Integer.subrange(x, len_primes-1) do ( var q : OclAny := primes[y+1] ; if (p + q->compareTo(LIM)) >= 0 then ( break ) else skip ; count_arr[p + q+1] := count_arr[p + q+1] + 1)) ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; execute (count_arr[n+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math class pannukakku : radius=0 height=0 size_h=0 size_r=0 def size(self,current_r): if(self.radius>current_r): return self.size_h+self.size_r-math.pi*current_r*current_r ; return self.size_h ; def poista_isoin(kakut,current_r): isoin_index=0 ; isoin_size=kakut[0].size(current_r); for p in range(1,len(kakut)): if(kakut[p].size(current_r)>isoin_size): isoin_index=p ; isoin_size=kakut[p].size(current_r); return kakut.pop(isoin_index); t=int(input()) for i in range(1,t+1): pannukakkuja,tilauksen_koko=[int(s)for s in input().split(" ")]; radiuses=[0 for h in range(pannukakkuja)] heigths=[0 for h in range(pannukakkuja)] sizes=[0 for h in range(pannukakkuja)] kakut=[pannukakku()for h in range(pannukakkuja)] for h in range(0,pannukakkuja): r,s=[int(s)for s in input().split(" ")]; kakut[h].radius=r ; kakut[h].heigth=s ; kakut[h].size_h=math.pi*2*r*s ; kakut[h].size_r=math.pi*r*r ; total=0 ; current_r=0 ; for p in range(tilauksen_koko): isoin=poista_isoin(kakut,current_r); total+=isoin.size(current_r); current_r=max(current_r,isoin.radius); print("Case #{0:.0f}:{1:.6f}".format(i,total)); ------------------------------------------------------------ OCL File: --------- class pannukakku { static operation newpannukakku() : pannukakku pre: true post: pannukakku->exists( _x | result = _x ); static attribute radius : int := 0; static attribute height : int := 0; static attribute size_h : int := 0; static attribute size_r : int := 0; operation size(current_r : OclAny) pre: true post: true activity: if ((self.radius->compareTo(current_r)) > 0) then ( return self.size_h + self.size_r - * current_r * current_r; ) else skip ; return self.size_h;; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(1, t + 1-1) do ( var pannukakkuja : OclAny := null; var tilauksen_koko : OclAny := null; Sequence{pannukakkuja,tilauksen_koko} := input().split(" ")->select(s | true)->collect(s | (("" + ((s)))->toInteger())); ; var radiuses : Sequence := Integer.subrange(0, pannukakkuja-1)->select(h | true)->collect(h | (0)) ; var heigths : Sequence := Integer.subrange(0, pannukakkuja-1)->select(h | true)->collect(h | (0)) ; var sizes : Sequence := Integer.subrange(0, pannukakkuja-1)->select(h | true)->collect(h | (0)) ; kakut := Integer.subrange(0, pannukakkuja-1)->select(h | true)->collect(h | ((pannukakku.newpannukakku()).initialise())) ; for h : Integer.subrange(0, pannukakkuja-1) do ( var r : OclAny := null; var s : OclAny := null; Sequence{r,s} := input().split(" ")->select(s | true)->collect(s | (("" + ((s)))->toInteger())); ; kakut[h+1].radius := r; ; kakut[h+1].heigth := s; ; kakut[h+1].size_h := * 2 * r * s; ; kakut[h+1].size_r := * r * r;) ; var total : int := 0; ; current_r := 0; ; for p : Integer.subrange(0, tilauksen_koko-1) do ( var isoin : OclAny := poista_isoin(kakut, current_r); ; total := total + isoin.size(current_r); ; current_r := Set{current_r, isoin.radius}->max();) ; execute (StringLib.interpolateStrings("Case #{0:.0f}:{1:.6f}", Sequence{i, total}))->display();); operation poista_isoin(kakut : OclAny, current_r : OclAny) pre: true post: true activity: var isoin_index : int := 0; ; var isoin_size : OclAny := kakut->first().size(current_r); ; for p : Integer.subrange(1, (kakut)->size()-1) do ( if ((kakut[p+1].size(current_r)->compareTo(isoin_size)) > 0) then ( isoin_index := p; ; isoin_size := kakut[p+1].size(current_r); ) else skip) ; return kakut->at(isoin_index`firstArg+1);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools import math def score(stack): syrup=math.pi*max(x[0]for x in stack)**2 for item in stack : syrup+=2*math.pi*item[0]*item[1] return syrup def ring_score(item): return 2*math.pi*item[0]*item[1] def solve(pancakes,k): return max(itertools.combinations(pancakes,k),key=score) with open('A-large.in')as infile : with open('A-large.out','w')as outfile : cases=int(next(infile)) for case in range(1,cases+1): n,k=map(int,next(infile).split()) pancakes=[] for _ in range(n): pancakes.append(tuple(map(int,next(infile).split()))) pancakes.sort(key=ring_score,reverse=True) preliminary=pancakes[: k] remaining=pancakes[k :] curr_score=score(preliminary) if remaining : other_score=score(preliminary[:-1]+[max(remaining)]) if other_score>curr_score : curr_score=other_score print(case,curr_score) print("Case #{}:{}".format(case,curr_score),file=outfile) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; try (var infile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('A-large.in')); try (var outfile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('A-large.out')); var cases : int := ("" + (((infile).next())))->toInteger() ; for case : Integer.subrange(1, cases + 1-1) do ( var n : OclAny := null; Sequence{n,k} := (next(infile).split())->collect( _x | (OclType["int"])->apply(_x) ) ; pancakes := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((((next(infile).split())->collect( _x | (OclType["int"])->apply(_x) ))) : pancakes)) ; pancakes := pancakes->sort() ; var preliminary : OclAny := pancakes.subrange(1,k) ; var remaining : OclAny := pancakes.subrange(k+1) ; var curr_score : OclAny := score(preliminary) ; if remaining then ( var other_score : OclAny := score(preliminary->front()->union(Sequence{ (remaining)->max() })) ; if (other_score->compareTo(curr_score)) > 0 then ( curr_score := other_score ) else skip ) else skip ; execute (case)->display() ; execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{case, curr_score}))->display())) catch (_e : OclException) do skip) catch (_e : OclException) do skip; operation score(stack : OclAny) : OclAny pre: true post: true activity: var syrup : double := * (((argument (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name stack))))))))->max())->pow(2) ; for item : stack do ( syrup := syrup + 2 * * item->first() * item[1+1]) ; return syrup; operation ring_score(item : OclAny) : OclAny pre: true post: true activity: return 2 * * item->first() * item[1+1]; operation solve(pancakes : OclAny, k : OclAny) : OclAny pre: true post: true activity: return Set{itertools.combinations(pancakes, k), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name score)))))))}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def main(): tt=I() rr=[] for ti in range(1,tt+1): n,k=LI() a=[] for _ in range(n): b,c=LI() m=b*b*math.pi l=b*2*math.pi*c a.append([b,m,l]) a=sorted(a,reverse=True) r=0 for i in range(n-k+1): tr=a[i][1]+a[i][2] ta=sorted(a[i+1 :],key=lambda x :-x[2]) tr+=sum(map(lambda x : x[2],ta[: k-1])) if rpow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation main() : OclAny pre: true post: true activity: var tt : OclAny := I() ; var rr : Sequence := Sequence{} ; for ti : Integer.subrange(1, tt + 1-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := LI() ; var a : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := LI() ; var m : double := b * b * ; var l : double := b * 2 * * c ; execute ((Sequence{b}->union(Sequence{m}->union(Sequence{ l }))) : a)) ; a := a->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var r : int := 0 ; for i : Integer.subrange(0, n - k + 1-1) do ( var tr : OclAny := a[i+1][1+1] + a[i+1][2+1] ; var ta : Sequence := a.subrange(i + 1+1)->sortedBy($x | (lambda x : OclAny in (-x[2+1]))->apply($x)) ; tr := tr + ((ta.subrange(1,k - 1))->collect( _x | (lambda x : OclAny in (x[2+1]))->apply(_x) ))->sum() ; if (r->compareTo(tr)) < 0 then ( r := tr ) else skip) ; execute ((StringLib.interpolateStrings('Case #{}:{}', Sequence{ti, r})) : rr)) ; return StringLib.sumStringsWithSeparator((rr), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math filename="A-large.in" f=open(filename,'r') out=open("output.txt",'w') Cases=int(f.readline()) for T in range(Cases): [N,K]=[int(j)for j in f.readline().split(" ")] C=[[int(j)for j in f.readline().split(" ")]for i in range(N)] C=[[C[i][0],C[i][1],2*C[i][0]*C[i][1]]for i in range(len(C))] C=sorted(C,key=lambda x :-x[2]) maxR=0 side=0 for i in range(K-1): maxR=max(maxR,C[i][0]) side+=C[i][2] cura=maxR**2+side maxA=cura for i in range(K-1,N): maxA=max(maxA,cura+C[i][2]+max(0,C[i][0]**2-maxR**2)) ret=str(math.pi*maxA) ret="Case #"+str(T+1)+": "+ret print(ret) out.write(ret+"\n") f.close() out.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var filename : String := "A-large.in" ; var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(filename)) ; var out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("output.txt")) ; var Cases : int := ("" + ((f.readLine())))->toInteger() ; for T : Integer.subrange(0, Cases-1) do ( ; Sequence{N}->union(Sequence{ K }) := f.readLine().split(" ")->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; var C : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (f.readLine().split(" ")->select(j | true)->collect(j | (("" + ((j)))->toInteger())))) ; C := Integer.subrange(0, (C)->size()-1)->select(i | true)->collect(i | (Sequence{C[i+1]->first()}->union(Sequence{C[i+1][1+1]}->union(Sequence{ 2 * C[i+1]->first() * C[i+1][1+1] })))) ; C := C->sortedBy($x | (lambda x : OclAny in (-x[2+1]))->apply($x)) ; var maxR : int := 0 ; var side : int := 0 ; for i : Integer.subrange(0, K - 1-1) do ( maxR := Set{maxR, C[i+1]->first()}->max() ; side := side + C[i+1][2+1]) ; var cura : double := (maxR)->pow(2) + side ; var maxA : OclAny := cura ; for i : Integer.subrange(K - 1, N-1) do ( maxA := Set{maxA, cura + C[i+1][2+1] + Set{0, (C[i+1]->first())->pow(2) - (maxR)->pow(2)}->max()}->max()) ; var ret : String := ("" + (( * maxA))) ; ret := "Case #" + ("" + ((T + 1))) + ": " + ret ; execute (ret)->display() ; out.write(ret + "\n")) ; f.closeFile() ; out.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,s=int(input()),input() res=sum(int(d)+(1 if d!="0" and i!=n-1 else 0)for i,d in enumerate(s)) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),(OclFile["System.in"]).readLine()} ; var res : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name d)))))))) )))) + (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 1)))))) if (logical_test (logical_test (comparison (comparison (expr (atom (name d)))) != (comparison (expr (atom "0"))))) and (logical_test (comparison (comparison (expr (atom (name i)))) != (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1))))))))) else (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name d)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))))))))->sum() ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math def problem(pancakes,order_size): pancakes.sort(key=lambda x : 2*math.pi*x[0]*x[1],reverse=True) take=pancakes[: order_size-1] if len(take)!=0 : max_radius=max(x[0]for x in take) else : max_radius=0 outsides=sum(2*math.pi*x[0]*x[1]for x in take) best=0 for n in pancakes[order_size-1 :]: radius=max(max_radius,n[0]) size=outsides+2*math.pi*n[0]*n[1]+math.pi*radius*radius best=max(best,size) return best def nextline(input_file): data="" while not data : data=input_file.readline() return data[:-1] def intsplit(s): return[int(x)for x in s.split("")] def main(): result="" with sys.stdin if len(sys.argv)==1 else open(sys.argv[1],'r')as infile : number=int(nextline(infile)) for run in range(number): case=nextline(infile) size,order_size=intsplit(case) pancakes=[] for _ in range(size): pancakes.append(intsplit(nextline(infile))) result+='Case #{}:{}\n'.format(1+run,problem(pancakes,order_size)) if len(sys.argv)==1 : print(result,end='') else : with open(sys.argv[1].replace('in','sol'),'w')as result_file : result_file.write(result) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation problem(pancakes : OclAny, order_size : OclAny) : OclAny pre: true post: true activity: pancakes := pancakes->sort() ; var take : OclAny := pancakes.subrange(1,order_size - 1) ; if (take)->size() /= 0 then ( var max_radius : OclAny := ((argument (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name take))))))))->max() ) else ( max_radius := 0 ) ; var outsides : OclAny := ((argument (test (logical_test (comparison (expr (expr (expr (expr (atom (number (integer 2)))) * (expr (atom (name math)) (trailer . (name pi)))) * (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) * (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name take))))))))->sum() ; var best : int := 0 ; for n : pancakes.subrange(order_size - 1+1) do ( var radius : OclAny := Set{max_radius, n->first()}->max() ; var size : OclAny := outsides + 2 * * n->first() * n[1+1] + * radius * radius ; best := Set{best, size}->max()) ; return best; operation nextline(input_file : OclAny) : OclAny pre: true post: true activity: var data : String := "" ; while not(data = "") do ( data := input_file.readLine()) ; return data->front(); operation intsplit(s : OclAny) : OclAny pre: true post: true activity: return s.split("")->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation main() pre: true post: true activity: var result : String := "" ; try (var infile : OclFile := if ((trailer . (name argv)))->size() = 1 then OclFile["System.in"] else OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) endif; var number : int := ("" + ((nextline(infile))))->toInteger() ; for run : Integer.subrange(0, number-1) do ( var case : OclAny := nextline(infile) ; Sequence{size,order_size} := intsplit(case) ; pancakes := Sequence{} ; for _anon : Integer.subrange(0, size-1) do ( execute ((intsplit(nextline(infile))) : pancakes)) ; result := result + StringLib.interpolateStrings('Case #{}:{} ', Sequence{1 + run, problem(pancakes, order_size)}))) catch (_e : OclException) do skip ; if ((trailer . (name argv)))->size() = 1 then ( execute (result)->display() ) else ( try (var result_file : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))).replace('in', 'sol'))); result_file.write(result)) catch (_e : OclException) do skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def countWays(string,m): Set=set() for i in range(0,len(string)): Set.add(string[i]) result=0 for i in range(1,len(string)): first_map=defaultdict(lambda : 0) second_map=defaultdict(lambda : 0) for j in range(0,i): first_map[string[j]]+=1 for k in range(i,len(string)): second_map[string[k]]+=1 total_count=0 for ch in Set : first_count,second_count=0,0 if ch in first_map : first_count=first_map[ch] if ch in second_map : second_count=second_map[ch] if first_count==second_count and first_count!=0 : total_count+=1 if total_count>=m : result+=1 return result if __name__=="__main__" : string="aabbccaa" m=2 print(countWays(string,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( string := "aabbccaa" ; m := 2 ; execute (countWays(string, m))->display() ) else skip; operation countWays(string : OclAny, m : OclAny) : OclAny pre: true post: true activity: var Set : Set := Set{}->union(()) ; for i : Integer.subrange(0, (string)->size()-1) do ( execute ((string[i+1]) : Set)) ; var result : int := 0 ; for i : Integer.subrange(1, (string)->size()-1) do ( var first_map : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; var second_map : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; for j : Integer.subrange(0, i-1) do ( first_map[string[j+1]+1] := first_map[string[j+1]+1] + 1) ; for k : Integer.subrange(i, (string)->size()-1) do ( second_map[string[k+1]+1] := second_map[string[k+1]+1] + 1) ; var total_count : int := 0 ; for ch : Set do ( var first_count : OclAny := null; var second_count : OclAny := null; Sequence{first_count,second_count} := Sequence{0,0} ; if (first_map)->includes(ch) then ( var first_count : OclAny := first_map[ch+1] ) else skip ; if (second_map)->includes(ch) then ( var second_count : OclAny := second_map[ch+1] ) else skip ; if first_count = second_count & first_count /= 0 then ( total_count := total_count + 1 ) else skip) ; if (total_count->compareTo(m)) >= 0 then ( result := result + 1 ) else skip) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque class Dice : def __init__(self,*surface): self._surface=surface self._mapping_sn=deque([0,1,5,4],maxlen=4) self._mapping_we=deque([0,3,5,2],maxlen=4) @ property def top(self): return self._surface[self._mapping_sn[0]] def roll_s(self): self._mapping_sn.rotate(1) self._mapping_we[0]=self._mapping_sn[0] self._mapping_we[2]=self._mapping_sn[2] def roll_n(self): self._mapping_sn.rotate(-1) self._mapping_we[0]=self._mapping_sn[0] self._mapping_we[2]=self._mapping_sn[2] def roll_w(self): self._mapping_we.rotate(1) self._mapping_sn[0]=self._mapping_we[0] self._mapping_sn[2]=self._mapping_we[2] def roll_e(self): self._mapping_we.rotate(-1) self._mapping_sn[0]=self._mapping_we[0] self._mapping_sn[2]=self._mapping_we[2] if __name__=='__main__' : surface=map(int,input().split()) d=Dice(*surface) commands=list(input().lower()) for c in commands : getattr(d,'roll_'+c)() print(d.top) ------------------------------------------------------------ OCL File: --------- class Dice { static operation newDice() : Dice pre: true post: Dice->exists( _x | result = _x ); attribute _surface : Sequence := surface; attribute _mapping_sn : Sequence := (Sequence{0}->union(Sequence{1}->union(Sequence{5}->union(Sequence{ 4 }))), (argument (test (logical_test (comparison (expr (atom (name maxlen)))))) = (test (logical_test (comparison (expr (atom (number (integer 4))))))))); attribute _mapping_we : Sequence := (Sequence{0}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 2 }))), (argument (test (logical_test (comparison (expr (atom (name maxlen)))))) = (test (logical_test (comparison (expr (atom (number (integer 4))))))))); operation initialise(surface : OclAny : Sequence(OclAny)) : Dice pre: true post: true activity: self._surface := surface ; self._mapping_sn := (Sequence{0}->union(Sequence{1}->union(Sequence{5}->union(Sequence{ 4 }))), (argument (test (logical_test (comparison (expr (atom (name maxlen)))))) = (test (logical_test (comparison (expr (atom (number (integer 4))))))))) ; self._mapping_we := (Sequence{0}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 2 }))), (argument (test (logical_test (comparison (expr (atom (name maxlen)))))) = (test (logical_test (comparison (expr (atom (number (integer 4))))))))); return self; operation roll_s() pre: true post: true activity: (expr (atom (name self)) (trailer . (name _mapping_sn)) (trailer . (name rotate) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))) ; self._mapping_we->first() := self._mapping_sn->first() ; self._mapping_we[2+1] := self._mapping_sn[2+1]; operation roll_n() pre: true post: true activity: (expr (atom (name self)) (trailer . (name _mapping_sn)) (trailer . (name rotate) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))) ; self._mapping_we->first() := self._mapping_sn->first() ; self._mapping_we[2+1] := self._mapping_sn[2+1]; operation roll_w() pre: true post: true activity: (expr (atom (name self)) (trailer . (name _mapping_we)) (trailer . (name rotate) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))) ; self._mapping_sn->first() := self._mapping_we->first() ; self._mapping_sn[2+1] := self._mapping_we[2+1]; operation roll_e() pre: true post: true activity: (expr (atom (name self)) (trailer . (name _mapping_we)) (trailer . (name rotate) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))) ; self._mapping_sn->first() := self._mapping_we->first() ; self._mapping_sn[2+1] := self._mapping_we[2+1]; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var surface : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Dice := (Dice.newDice()).initialise((argument * (test (logical_test (comparison (expr (atom (name surface)))))))) ; var commands : Sequence := (input()->toLowerCase()) ; for c : commands do ((expr (atom (name getattr)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name d))))))) , (argument (test (logical_test (comparison (expr (expr (atom 'roll_')) + (expr (atom (name c))))))))) ))) (trailer (arguments ( ))))) ; execute (d.top)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) N_Dict={} for i in range(N): moji=str(input()) if moji in N_Dict : N_Dict.pop(moji) else : N_Dict[moji]=1 print(len(N_Dict)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var N_Dict : OclAny := Set{} ; for i : Integer.subrange(0, N-1) do ( var moji : String := ("" + (((OclFile["System.in"]).readLine()))) ; if (N_Dict)->includes(moji) then ( N_Dict := N_Dict->excludingAt(moji+1) ) else ( N_Dict->at(moji) := 1 )) ; execute ((N_Dict)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from math import gcd,pi,sqrt INF=float("inf") import sys sys.setrecursionlimit(10**6) import itertools from collections import Counter,deque def i_input(): return int(input()) def i_map(): return map(int,input().split()) def i_list(): return list(i_map()) def i_row(N): return[i_input()for _ in range(N)] def i_row_list(N): return[i_list()for _ in range(N)] def s_input(): return input() def s_map(): return input().split() def s_list(): return list(s_map()) def s_row(N): return[s_input for _ in range(N)] def s_row_str(N): return[s_list()for _ in range(N)] def s_row_list(N): return[list(s_input())for _ in range(N)] def main(): n=i_input() dic={} for i in range(n): a=i_input() dic[a]=dic.get(a,0)+1 ans=0 for i,k in dic.items(): if k % 2==1 : ans+=1 print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var INF : double := ("" + (("inf")))->toReal() ; skip ; sys.setrecursionlimit((10)->pow(6)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation i_input() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation i_map() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation i_list() : OclAny pre: true post: true activity: return (i_map()); operation i_row(N : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (i_input())); operation i_row_list(N : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (i_list())); operation s_input() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation s_map() : OclAny pre: true post: true activity: return input().split(); operation s_list() : OclAny pre: true post: true activity: return (s_map()); operation s_row(N : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (s_input)); operation s_row_str(N : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (s_list())); operation s_row_list(N : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | ((s_input()))); operation main() pre: true post: true activity: var n : OclAny := i_input() ; var dic : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := i_input() ; dic[a+1] := dic.get(a, 0) + 1) ; var ans : int := 0 ; for _tuple : dic->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var k : OclAny := _tuple->at(_indx); if k mod 2 = 1 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections N=int(input()) A=[int(input())for _ in range(N)] c=collections.Counter(A) ans=0 for i in c.values(): if i % 2!=0 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var c : OclAny := .Counter(A) ; var ans : int := 0 ; for i : c.values() do ( if i mod 2 /= 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def solve(): dic=defaultdict(int) n=int(input()) ans=0 for _ in range(n): a=int(input()) dic[a]=(dic[a]+1)% 2 print(sum(dic.values())) if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var dic : OclAny := defaultdict(OclType["int"]) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; dic[a+1] := (dic[a+1] + 1) mod 2) ; execute ((dic.values())->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[input()for i in range(n)] from collections import Counter S=Counter(a) cnt=0 for i in S.values(): if i % 2!=0 : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; skip ; var S : OclAny := Counter(a) ; var cnt : int := 0 ; for i : S.values() do ( if i mod 2 /= 0 then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getMSB(n): n |=n>>1 n |=n>>2 n |=n>>4 n |=n>>8 n |=n>>16 return((n+1)>>2) def multiply(F,M): x=F[0][0]*M[0][0]+F[0][1]*M[1][0] y=F[0][0]*M[0][1]+F[0][1]*M[1][1] z=F[1][0]*M[0][0]+F[1][1]*M[1][0] w=F[1][0]*M[0][1]+F[1][1]*M[1][1] F[0][0]=x F[0][1]=y F[1][0]=z F[1][1]=w def power(F,n): if(n==0 or n==1): return M=[[1,1],[1,0]] m=getMSB(n) while m : multiply(F,F) if(n & m): multiply(F,M) m=m>>1 def fib(n): F=[[1,1],[1,0]] if(n==0): return 0 power(F,n-1) return F[0][0] n=6 print(fib(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; n := 6 ; execute (fib(n))->display(); operation getMSB(n : OclAny) : OclAny pre: true post: true activity: n := n or n /(2->pow(1)) ; n := n or n /(2->pow(2)) ; n := n or n /(2->pow(4)) ; n := n or n /(2->pow(8)) ; n := n or n /(2->pow(16)) ; return ((n + 1) /(2->pow(2))); operation multiply(F : OclAny, M : OclAny) pre: true post: true activity: var x : double := F->first()->first() * M->first()->first() + F->first()[1+1] * M[1+1]->first() ; var y : double := F->first()->first() * M->first()[1+1] + F->first()[1+1] * M[1+1][1+1] ; var z : double := F[1+1]->first() * M->first()->first() + F[1+1][1+1] * M[1+1]->first() ; var w : double := F[1+1]->first() * M->first()[1+1] + F[1+1][1+1] * M[1+1][1+1] ; F->first()->first() := x ; F->first()[1+1] := y ; F[1+1]->first() := z ; F[1+1][1+1] := w; operation power(F : OclAny, n : OclAny) pre: true post: true activity: if (n = 0 or n = 1) then ( return ) else skip ; M := Sequence{Sequence{1}->union(Sequence{ 1 })}->union(Sequence{ Sequence{1}->union(Sequence{ 0 }) }) ; var m : OclAny := getMSB(n) ; while m do ( multiply(F, F) ; if (MathLib.bitwiseAnd(n, m)) then ( multiply(F, M) ) else skip ; m := m /(2->pow(1))); operation fib(n : OclAny) : OclAny pre: true post: true activity: F := Sequence{Sequence{1}->union(Sequence{ 1 })}->union(Sequence{ Sequence{1}->union(Sequence{ 0 }) }) ; if (n = 0) then ( return 0 ) else skip ; power(F, n - 1) ; return F->first()->first(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fib(n): F=[[1,1],[1,0]] if(n==0): return 0 power(F,n-1) return F[0][0] def multiply(F,M): x=(F[0][0]*M[0][0]+F[0][1]*M[1][0]) y=(F[0][0]*M[0][1]+F[0][1]*M[1][1]) z=(F[1][0]*M[0][0]+F[1][1]*M[1][0]) w=(F[1][0]*M[0][1]+F[1][1]*M[1][1]) F[0][0]=x F[0][1]=y F[1][0]=z F[1][1]=w def power(F,n): M=[[1,1],[1,0]] for i in range(2,n+1): multiply(F,M) if __name__=="__main__" : n=9 print(fib(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( n := 9 ; execute (fib(n))->display() ) else skip; operation fib(n : OclAny) : OclAny pre: true post: true activity: var F : Sequence := Sequence{Sequence{1}->union(Sequence{ 1 })}->union(Sequence{ Sequence{1}->union(Sequence{ 0 }) }) ; if (n = 0) then ( return 0 ) else skip ; power(F, n - 1) ; return F->first()->first(); operation multiply(F : OclAny, M : OclAny) pre: true post: true activity: var x : double := (F->first()->first() * M->first()->first() + F->first()[1+1] * M[1+1]->first()) ; var y : double := (F->first()->first() * M->first()[1+1] + F->first()[1+1] * M[1+1][1+1]) ; var z : double := (F[1+1]->first() * M->first()->first() + F[1+1][1+1] * M[1+1]->first()) ; var w : double := (F[1+1]->first() * M->first()[1+1] + F[1+1][1+1] * M[1+1][1+1]) ; F->first()->first() := x ; F->first()[1+1] := y ; F[1+1]->first() := z ; F[1+1][1+1] := w; operation power(F : OclAny, n : OclAny) pre: true post: true activity: M := Sequence{Sequence{1}->union(Sequence{ 1 })}->union(Sequence{ Sequence{1}->union(Sequence{ 0 }) }) ; for i : Integer.subrange(2, n + 1-1) do ( multiply(F, M)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fib(n): F=[[1,1],[1,0]] if(n==0): return 0 power(F,n-1) return F[0][0] def multiply(F,M): x=(F[0][0]*M[0][0]+F[0][1]*M[1][0]) y=(F[0][0]*M[0][1]+F[0][1]*M[1][1]) z=(F[1][0]*M[0][0]+F[1][1]*M[1][0]) w=(F[1][0]*M[0][1]+F[1][1]*M[1][1]) F[0][0]=x F[0][1]=y F[1][0]=z F[1][1]=w def power(F,n): if(n==0 or n==1): return ; M=[[1,1],[1,0]]; power(F,n//2) multiply(F,F) if(n % 2!=0): multiply(F,M) if __name__=="__main__" : n=9 print(fib(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( n := 9 ; execute (fib(n))->display() ) else skip; operation fib(n : OclAny) : OclAny pre: true post: true activity: var F : Sequence := Sequence{Sequence{1}->union(Sequence{ 1 })}->union(Sequence{ Sequence{1}->union(Sequence{ 0 }) }) ; if (n = 0) then ( return 0 ) else skip ; power(F, n - 1) ; return F->first()->first(); operation multiply(F : OclAny, M : OclAny) pre: true post: true activity: var x : double := (F->first()->first() * M->first()->first() + F->first()[1+1] * M[1+1]->first()) ; var y : double := (F->first()->first() * M->first()[1+1] + F->first()[1+1] * M[1+1][1+1]) ; var z : double := (F[1+1]->first() * M->first()->first() + F[1+1][1+1] * M[1+1]->first()) ; var w : double := (F[1+1]->first() * M->first()[1+1] + F[1+1][1+1] * M[1+1][1+1]) ; F->first()->first() := x ; F->first()[1+1] := y ; F[1+1]->first() := z ; F[1+1][1+1] := w; operation power(F : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n = 0 or n = 1) then ( return; ) else skip ; M := Sequence{Sequence{1}->union(Sequence{ 1 })}->union(Sequence{ Sequence{1}->union(Sequence{ 0 }) }); ; power(F, n div 2) ; multiply(F, F) ; if (n mod 2 /= 0) then ( multiply(F, M) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) l=list(map(int,list(input()))) print(sum(l)+sum([x!=0 for x in l])-int(l[-1]>0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((((OclFile["System.in"]).readLine())->characters())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((l)->sum() + (l->select(x | true)->collect(x | (x /= 0)))->sum() - ("" + ((l->last() > 0)))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def multiply(F,M): x=F[0][0]*M[0][0]+F[0][1]*M[1][0] y=F[0][0]*M[0][1]+F[0][1]*M[1][1] z=F[1][0]*M[0][0]+F[1][1]*M[1][0] w=F[1][0]*M[0][1]+F[1][1]*M[1][1] F[0][0]=x F[0][1]=y F[1][0]=z F[1][1]=w def power(F,n): M=[[1,1],[1,0]] for i in range(2,n+1): multiply(F,M) def fib(n): F=[[1,1],[1,0]] if(n==0): return 0 power(F,n-1) return F[0][0] def leonardo(n): if(n==0 or n==1): return 1 return(2*fib(n+1)-1) print(leonardo(3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; execute (leonardo(3))->display(); operation multiply(F : OclAny, M : OclAny) pre: true post: true activity: var x : double := F->first()->first() * M->first()->first() + F->first()[1+1] * M[1+1]->first() ; var y : double := F->first()->first() * M->first()[1+1] + F->first()[1+1] * M[1+1][1+1] ; var z : double := F[1+1]->first() * M->first()->first() + F[1+1][1+1] * M[1+1]->first() ; var w : double := F[1+1]->first() * M->first()[1+1] + F[1+1][1+1] * M[1+1][1+1] ; F->first()->first() := x ; F->first()[1+1] := y ; F[1+1]->first() := z ; F[1+1][1+1] := w; operation power(F : OclAny, n : OclAny) pre: true post: true activity: M := Sequence{Sequence{1}->union(Sequence{ 1 })}->union(Sequence{ Sequence{1}->union(Sequence{ 0 }) }) ; for i : Integer.subrange(2, n + 1-1) do ( multiply(F, M)); operation fib(n : OclAny) : OclAny pre: true post: true activity: F := Sequence{Sequence{1}->union(Sequence{ 1 })}->union(Sequence{ Sequence{1}->union(Sequence{ 0 }) }) ; if (n = 0) then ( return 0 ) else skip ; power(F, n - 1) ; return F->first()->first(); operation leonardo(n : OclAny) : OclAny pre: true post: true activity: if (n = 0 or n = 1) then ( return 1 ) else skip ; return (2 * fib(n + 1) - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n1,n2,n3,n4,n5,n6=map(int,raw_input().split()) act=raw_input() for i in act : if i=="N" : n11=n1 n1=n2 n2=n6 n6=n5 n5=n11 elif i=="S" : n11=n1 n1=n5 n5=n6 n6=n2 n2=n11 elif i=="E" : n11=n1 n1=n4 n4=n6 n6=n3 n3=n11 else : n11=n1 n1=n3 n3=n6 n6=n4 n4=n11 print(n1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n1 : OclAny := null; var n2 : OclAny := null; var n3 : OclAny := null; var n4 : OclAny := null; var n5 : OclAny := null; var n6 : OclAny := null; Sequence{n1,n2,n3,n4,n5,n6} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var act : OclAny := raw_input() ; for i : act do ( if i = "N" then ( var n11 : OclAny := n1 ; var n1 : OclAny := n2 ; var n2 : OclAny := n6 ; var n6 : OclAny := n5 ; var n5 : OclAny := n11 ) else (if i = "S" then ( n11 := n1 ; n1 := n5 ; n5 := n6 ; n6 := n2 ; n2 := n11 ) else (if i = "E" then ( n11 := n1 ; n1 := n4 ; var n4 : OclAny := n6 ; n6 := n3 ; var n3 : OclAny := n11 ) else ( n11 := n1 ; n1 := n3 ; n3 := n6 ; n6 := n4 ; n4 := n11 ) ) ) ) ; execute (n1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def multiply(F,M): x=F[0][0]*M[0][0]+F[0][1]*M[1][0] y=F[0][0]*M[0][1]+F[0][1]*M[1][1] z=F[1][0]*M[0][0]+F[1][1]*M[1][0] w=F[1][0]*M[0][1]+F[1][1]*M[1][1] F[0][0]=x F[0][1]=y F[1][0]=z F[1][1]=w def power(F,n): if(n==0 or n==1): return M=[[1,1],[1,0]] power(F,n//2) multiply(F,F) if(n % 2!=0): multiply(F,M) def countWays(n): F=[[1,1],[1,0]] if(n==0): return 0 power(F,n) return F[0][0] n=5 print(countWays(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 5 ; execute (countWays(n))->display(); operation multiply(F : OclAny, M : OclAny) pre: true post: true activity: var x : double := F->first()->first() * M->first()->first() + F->first()[1+1] * M[1+1]->first() ; var y : double := F->first()->first() * M->first()[1+1] + F->first()[1+1] * M[1+1][1+1] ; var z : double := F[1+1]->first() * M->first()->first() + F[1+1][1+1] * M[1+1]->first() ; var w : double := F[1+1]->first() * M->first()[1+1] + F[1+1][1+1] * M[1+1][1+1] ; F->first()->first() := x ; F->first()[1+1] := y ; F[1+1]->first() := z ; F[1+1][1+1] := w; operation power(F : OclAny, n : OclAny) pre: true post: true activity: if (n = 0 or n = 1) then ( return ) else skip ; M := Sequence{Sequence{1}->union(Sequence{ 1 })}->union(Sequence{ Sequence{1}->union(Sequence{ 0 }) }) ; power(F, n div 2) ; multiply(F, F) ; if (n mod 2 /= 0) then ( multiply(F, M) ) else skip; operation countWays(n : OclAny) : OclAny pre: true post: true activity: F := Sequence{Sequence{1}->union(Sequence{ 1 })}->union(Sequence{ Sequence{1}->union(Sequence{ 0 }) }) ; if (n = 0) then ( return 0 ) else skip ; power(F, n) ; return F->first()->first(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin readline=stdin.readline def cross(a,b): return a.real*b.imag-a.imag*b.real def dot(a,b): return a.real*b.real+a.imag*b.imag def diff(p,i): return p[(i+1)% len(p)]-p[i] def convex_diameter(p): js=ks=0 for i in range(1,len(p)): if p[i].imag>p[js].imag : js=i if p[i].imag=0 : k=(k+1)% len(p) else : j=(j+1)% len(p) if maxdtoInteger() ; p := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((readline().split())->collect( _x | (OclType["double"])->apply(_x) ))) ; p := p->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (x + y * 1j)) ; execute (StringLib.interpolateStrings('{:.6f}', Sequence{convex_diameter(p)}))->display(); operation cross(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a.real * b.imag - a.imag * b.real; operation dot(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a.real * b.real + a.imag * b.imag; operation diff(p : OclAny, i : OclAny) : OclAny pre: true post: true activity: return p[(i + 1) mod (p)->size()+1] - p[i+1]; operation convex_diameter(p : OclAny) : OclAny pre: true post: true activity: var js : OclAny := 0; var ks : int := 0 ; for i : Integer.subrange(1, (p)->size()-1) do ( if (p[i+1].imag->compareTo(p[js+1].imag)) > 0 then ( js := i ) else skip ; if (p[i+1].imag->compareTo(p[ks+1].imag)) < 0 then ( ks := i ) else skip) ; var maxd : double := (p[js+1] - p[ks+1])->abs() ; var j : OclAny := null; var k : OclAny := null; Sequence{j,k} := Sequence{js,ks} ; while true do ( if cross(diff(p, j), diff(p, k)) >= 0 then ( var k : int := (k + 1) mod (p)->size() ) else ( var j : int := (j + 1) mod (p)->size() ) ; if (maxd->compareTo((p[j+1] - p[k+1])->abs())) < 0 then ( maxd := (p[j+1] - p[k+1])->abs() ) else skip ; if j = js & k = ks then ( break ) else skip) ; return maxd; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def diff(i): cp,np=points[i : i+2] return np-cp def cross(a,b): return a.real*b.imag-a.imag*b.real def diameter(i,j): return abs(points[i]-points[j]) n=int(input()) t_points=[tuple(map(float,input().split()))for _ in range(n)] i=min(range(n),key=lambda x : t_points[x]) j=max(range(n),key=lambda x : t_points[x]) points=[re+1j*im for re,im in t_points] points.append(points[0]) tentative_diameter=diameter(i,j) it,jt=i,j while True : if cross(diff(it),diff(jt))>=0 : jt=(jt+1)% n else : it=(it+1)% n tentative_diameter=max(tentative_diameter,diameter(it,jt)) if it==i and jt==j : break print(tentative_diameter) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t_points : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["double"])->apply(_x) )))) ; i := Set{Integer.subrange(0, n-1), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name t_points)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ]))))))))}->min() ; j := Set{Integer.subrange(0, n-1), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name t_points)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ]))))))))}->max() ; var points : Sequence := t_points->select(_tuple | true)->collect(_tuple | let re : OclAny = _tuple->at(1) in let im : OclAny = _tuple->at(2) in (re + 1j * im)) ; execute ((points->first()) : points) ; var tentative_diameter : OclAny := diameter(i, j) ; var it : OclAny := null; var jt : OclAny := null; Sequence{it,jt} := Sequence{i,j} ; while true do ( if cross(diff(it), diff(jt)) >= 0 then ( var jt : int := (jt + 1) mod n ) else ( var it : int := (it + 1) mod n ) ; tentative_diameter := Set{tentative_diameter, diameter(it, jt)}->max() ; if it = i & jt = j then ( break ) else skip) ; execute (tentative_diameter)->display(); operation diff(i : OclAny) : OclAny pre: true post: true activity: var cp : OclAny := null; var np : OclAny := null; Sequence{cp,np} := points.subrange(i+1, i + 2) ; return np - cp; operation cross(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a.real * b.imag - a.imag * b.real; operation diameter(i : OclAny, j : OclAny) : OclAny pre: true post: true activity: return (points[i+1] - points[j+1])->abs(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cross(p1,p2,q1,q2): p=p2-p1 q=q2-q1 return p.real*q.imag-p.imag*q.real er=1e-16 def convex_diameter(points,n): points.append(points[0]) p0=points[0] p1=points[1] for i,(q1,q2)in enumerate(zip(points[1 :],points[2 :]),start=1): if cross(p0,p1,q1,q2)<-er : break max_d=abs(points[i]-points[0]) points.append(points[1]) side1=zip(points[0 : i+1],points[1 : i+2]) side2=zip(points[i : n+1],points[i+1 :]) p1,p2=side1.__next__() q1,q2=side2.__next__() for i in range(n-1): if cross(p1,p2,q1,q2)>er : q1,q2=side2.__next__() else : p1,p2=side1.__next__() max_d=max(max_d,abs(p1-q1)) return max_d def string_to_complex(s): x,y=map(float,s.split()) return x+y*1j import sys file_input=sys.stdin n=int(file_input.readline()) P=[string_to_complex(line)for line in file_input] ans=convex_diameter(P,n) print('{:f}'.format(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var er : double := ("1e-16")->toReal() ; skip ; skip ; skip ; var file_input : OclFile := OclFile["System.in"] ; n := ("" + ((file_input.readLine())))->toInteger() ; var P : Sequence := file_input->select(line | true)->collect(line | (string_to_complex(line))) ; var ans : OclAny := convex_diameter(P, n) ; execute (StringLib.interpolateStrings('{:f}', Sequence{ans}))->display(); operation cross(p1 : OclAny, p2 : OclAny, q1 : OclAny, q2 : OclAny) : OclAny pre: true post: true activity: var p : double := p2 - p1 ; var q : double := q2 - q1 ; return p.real * q.imag - p.imag * q.real; operation convex_diameter(points : OclAny, n : OclAny) : OclAny pre: true post: true activity: execute ((points->first()) : points) ; var p0 : OclAny := points->first() ; p1 := points[1+1] ; for _tuple : Integer.subrange(1, (Integer.subrange(1, points->tail()->size())->collect( _indx | Sequence{points->tail()->at(_indx), points.subrange(2+1)->at(_indx)} ), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(1, points->tail()->size())->collect( _indx | Sequence{points->tail()->at(_indx), points.subrange(2+1)->at(_indx)} ), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{q1, q2} : OclAny := _tuple->at(_indx); if (cross(p0, p1, q1, q2)->compareTo(-er)) < 0 then ( break ) else skip) ; var max_d : double := (points[i+1] - points->first())->abs() ; execute ((points[1+1]) : points) ; var side1 : Sequence := Integer.subrange(1, points.subrange(0+1, i + 1)->size())->collect( _indx | Sequence{points.subrange(0+1, i + 1)->at(_indx), points.subrange(1+1, i + 2)->at(_indx)} ) ; var side2 : Sequence := Integer.subrange(1, points.subrange(i+1, n + 1)->size())->collect( _indx | Sequence{points.subrange(i+1, n + 1)->at(_indx), points.subrange(i + 1+1)->at(_indx)} ) ; Sequence{p1,p2} := side1.__next__() ; Sequence{q1,q2} := side2.__next__() ; for i : Integer.subrange(0, n - 1-1) do ( if (cross(p1, p2, q1, q2)->compareTo(er)) > 0 then ( Sequence{q1,q2} := side2.__next__() ) else ( Sequence{p1,p2} := side1.__next__() ) ; max_d := Set{max_d, (p1 - q1)->abs()}->max()) ; return max_d; operation string_to_complex(s : OclAny) : OclAny pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (s.split())->collect( _x | (OclType["double"])->apply(_x) ) ; return x + y * 1j; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from typing import List def cross(a : complex,b : complex)->float : return a.real*b.imag-a.imag*b.real def distance(i : int,j : int,coordinates : List[complex])->float : return abs(coordinates[i]-coordinates[j]) if __name__=="__main__" : n=int(input()) points=[tuple(map(float,input().split()))for _ in range(n)] min_x_idx=min(range(n),key=lambda x : points[x]) max_x_idx=max(range(n),key=lambda x : points[x]) coordinates=[re+1j*im for re,im in points] coordinates.append(coordinates[0]) ans=distance(min_x_idx,max_x_idx,coordinates) i,j=min_x_idx,max_x_idx while True : if 0<=cross(coordinates[i+1]-coordinates[i],coordinates[j+1]-coordinates[j]): j=(j+1)% n else : i=(i+1)% n ans=max(ans,distance(i,j,coordinates)) if min_x_idx==i and max_x_idx==j : break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var points : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["double"])->apply(_x) )))) ; var min_x_idx : OclAny := Set{Integer.subrange(0, n-1), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name points)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ]))))))))}->min() ; var max_x_idx : OclAny := Set{Integer.subrange(0, n-1), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom (name points)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ]))))))))}->max() ; var coordinates : Sequence := points->select(_tuple | true)->collect(_tuple | let re : OclAny = _tuple->at(1) in let im : OclAny = _tuple->at(2) in (re + 1j * im)) ; execute ((coordinates->first()) : coordinates) ; var ans : OclAny := distance(min_x_idx, max_x_idx, coordinates) ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{min_x_idx,max_x_idx} ; while true do ( if 0 <= cross(coordinates[i + 1+1] - coordinates[i+1], coordinates[j + 1+1] - coordinates[j+1]) then ( var j : int := (j + 1) mod n ) else ( var i : int := (i + 1) mod n ) ; ans := Set{ans, distance(i, j, coordinates)}->max() ; if min_x_idx = i & max_x_idx = j then ( break ) else skip) ; execute (ans)->display() ) else skip; operation cross(a : complex, b : complex) : double pre: true post: true activity: return a.real * b.imag - a.imag * b.real; operation distance(i : int, j : int, coordinates : List[complex+1]) : double pre: true post: true activity: return (coordinates[i+1] - coordinates[j+1])->abs(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import cmath EPS=1e-10 def OuterProduct(one,two): tmp=one.conjugate()*two return tmp.imag def CCW(p,q,r): one,two=q-p,r-q if OuterProduct(one,two)>-EPS : return True else : return False def ConvexDiameter(qs): n=len(qs) if n==2 : return abs(qs[0]-qs[1]) i,j=0,0 for k in range(n): if qs[k].realtoReal() ; skip ; skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var dots : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; execute ((complex(x, y)) : dots)) ; execute (StringLib.interpolateStrings("{:.12f}", Sequence{ConvexDiameter(dots)}))->display(); operation OuterProduct(one : OclAny, two : OclAny) : OclAny pre: true post: true activity: var tmp : double := one.conjugate() * two ; return tmp.imag; operation CCW(p : OclAny, q : OclAny, r : OclAny) : OclAny pre: true post: true activity: Sequence{one,two} := Sequence{q - p,r - q} ; if (OuterProduct(one, two)->compareTo(-EPS)) > 0 then ( return true ) else ( return false ); operation ConvexDiameter(qs : OclAny) : OclAny pre: true post: true activity: var n : int := (qs)->size() ; if n = 2 then ( return (qs->first() - qs[1+1])->abs() ) else skip ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,0} ; for k : Integer.subrange(0, n-1) do ( if (qs[k+1].real->compareTo(qs[i+1].real)) < 0 then ( var i : OclAny := k ) else skip ; if (qs[j+1].real->compareTo(qs[k+1].real)) < 0 then ( var j : OclAny := k ) else skip) ; var res : int := 0 ; var si : OclAny := null; var sj : OclAny := null; Sequence{si,sj} := Sequence{i,j} ; while i /= sj or j /= si do ( res := Set{res, (qs[i+1] - qs[j+1])->abs()}->max() ; if (OuterProduct(qs[i - n + 1+1] - qs[i+1], qs[j - n + 1+1] - qs[j+1])->compareTo(-EPS)) < 0 then ( i := (i + 1) mod n ) else ( j := (j + 1) mod n )) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=input().split('|') z=list(input()) for i in range(len(z)): if len(x)>=len(y)and len(z)!=0 : y+=z.pop(0) elif len(y)>=len(x)and len(z)!=0 : x+=z.pop(0) else : f='Impossible' break if len(x)==len(y)and len(z)% 2==0 : if len(z)!=0 : r=len(z)//2 x=x+str(z[: r]) y=y+str(z[r :]) f=f'{x}|{y}' else : f=f'{x}|{y}' else : f='Impossible' print(f) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := input().split('|') ; var z : Sequence := ((OclFile["System.in"]).readLine())->characters() ; for i : Integer.subrange(0, (z)->size()-1) do ( if ((x)->size()->compareTo((y)->size())) >= 0 & (z)->size() /= 0 then ( y := y + z->at(0`firstArg+1) ; z := z->excludingAt(0+1) ) else (if ((y)->size()->compareTo((x)->size())) >= 0 & (z)->size() /= 0 then ( x := x + z->at(0`firstArg+1) ; z := z->excludingAt(0+1) ) else ( var f : String := 'Impossible' ; break ) ) ) ; if (x)->size() = (y)->size() & (z)->size() mod 2 = 0 then ( if (z)->size() /= 0 then ( var r : int := (z)->size() div 2 ; var x : OclAny := x + ("" + ((z.subrange(1,r)))) ; var y : OclAny := y + ("" + ((z.subrange(r+1)))) ; f := StringLib.formattedString('{x}|{y}') ) else ( f := StringLib.formattedString('{x}|{y}') ) ) else ( f := 'Impossible' ) ; execute (f)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() dl=s.find('|') av=list(input()) lenf=len(s[: dl]); lenl=len(s[dl+1 :]) if lenfindexOf('|') - 1 ; var av : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var lenf : int := (s.subrange(1,dl))->size(); var lenl : int := (s.subrange(dl + 1+1))->size() ; if (lenf->compareTo(lenl)) < 0 then ( while (lenf->compareTo(lenl)) < 0 & av do ( s := av->last() + s ; lenf := lenf + 1) ) else ( while (lenl->compareTo(lenf)) < 0 & av do ( s := s + av->last() ; lenl := lenl + 1) ) ; if (av)->size() mod 2 = 0 then ( s := s + StringLib.sumStringsWithSeparator((av.subrange(1,(av)->size() div 2)), '') ; s := StringLib.sumStringsWithSeparator((av.subrange((av)->size() div 2+1)), '') + s ; execute (av /<: av) ) else skip ; var x : int := s->indexOf('|') - 1 ; execute (if (av)->size() = 0 & ((s)->size() div 2 = x) then s else "Impossible" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- g1,g2=map(str,input().split("|")) s=input() for i in s : if len(g1)>len(g2): g2+=i else : g1+=i print(f"{g1}|{g2}" if len(g1)==len(g2)else "Impossible") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var g1 : OclAny := null; var g2 : OclAny := null; Sequence{g1,g2} := (input().split("|"))->collect( _x | (OclType["String"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; for i : s->characters() do ( if ((g1)->size()->compareTo((g2)->size())) > 0 then ( g2 := g2 + i ) else ( g1 := g1 + i )) ; execute (if (g1)->size() = (g2)->size() then StringLib.formattedString("{g1}|{g2}") else "Impossible" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,n=map(int,input().split()) a=list(map(int,input().split())) if m==2 : x=y=0 for i in range(n): b=i % 2+1 c=(i+1)% 2+1 if a[i]!=b : x+=1 if a[i]!=c : y+=1 print(min(x,y)) exit() x=0 for i in range(1,n): if a[i-1]==a[i]: a[i]=-1 ; x+=1 print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if m = 2 then ( var x : OclAny := 0; var y : int := 0 ; for i : Integer.subrange(0, n-1) do ( var b : int := i mod 2 + 1 ; var c : int := (i + 1) mod 2 + 1 ; if a[i+1] /= b then ( x := x + 1 ) else skip ; if a[i+1] /= c then ( y := y + 1 ) else skip) ; execute (Set{x, y}->min())->display() ; exit() ) else skip ; x := 0 ; for i : Integer.subrange(1, n-1) do ( if a[i - 1+1] = a[i+1] then ( a[i+1] := -1; x := x + 1 ) else skip) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class node : def __init__(self,data): self.data=data self.next=None def add(data): newnode=node(0) newnode.data=data newnode.next=None return newnode def printArr(a,n): i=0 while(iexists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := null; operation initialise(data : OclAny) : node pre: true post: true activity: self.data := data ; self.next := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; head := (node.newnode()).initialise(0) ; head := add(1) ; head.next := add(2) ; head.next.next := add(3) ; head.next.next.next := add(4) ; head.next.next.next.next := add(5) ; convertArr(head); operation add(data : OclAny) : OclAny pre: true post: true activity: var newnode : node := (node.newnode()).initialise(0) ; newnode.data := data ; newnode.next := null ; return newnode; operation printArr(a : OclAny, n : OclAny) pre: true post: true activity: var i : int := 0 ; while ((i->compareTo(n)) < 0) do ( execute (a[i+1])->display() ; i := i + 1); operation findlength(head : OclAny) : OclAny pre: true post: true activity: var curr : OclAny := head ; var cnt : int := 0 ; while (curr /= null) do ( cnt := cnt + 1 ; curr := curr.next) ; return cnt; operation convertArr(head : OclAny) pre: true post: true activity: var len1 : OclAny := findlength(head) ; var arr : Sequence := Sequence{} ; var index : int := 0 ; curr := head ; while (curr /= null) do ( execute ((curr.data) : arr) ; curr := curr.next) ; printArr(arr, len1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) s=input() c=int(s[-1]) l=[int(s[i])for i in range(n-1)if s[i]!='0'] c+=sum(l)+len(l) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var c : int := ("" + ((s->last())))->toInteger() ; var l : Sequence := Integer.subrange(0, n - 1-1)->select(i | s[i+1] /= '0')->collect(i | (("" + ((s[i+1])))->toInteger())) ; c := c + (l)->sum() + (l)->size() ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(str,input().split("|")) c=input() boolean=True for i in range(len(c)): if len(a)len(b): b+=c[i] else : a+=c[i] if len(a)==len(b): print(a+"|"+b) else : print("Impossible") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split("|"))->collect( _x | (OclType["String"])->apply(_x) ) ; var c : String := (OclFile["System.in"]).readLine() ; var boolean : boolean := true ; for i : Integer.subrange(0, (c)->size()-1) do ( if ((a)->size()->compareTo((b)->size())) < 0 then ( a := a + c[i+1] ) else (if ((a)->size()->compareTo((b)->size())) > 0 then ( b := b + c[i+1] ) else ( a := a + c[i+1] ) ) ) ; if (a)->size() = (b)->size() then ( execute (a + "|" + b)->display() ) else ( execute ("Impossible")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- parts=input().split('|') weights=input() stack=[w for w in weights] left,right=parts[0],parts[1] i=0 while icharacters()->select(w | true)->collect(w | (w)) ; var left : OclAny := null; var right : OclAny := null; Sequence{left,right} := Sequence{parts->first(),parts[1+1]} ; var i : int := 0 ; while (i->compareTo((weights)->size())) < 0 & ((left)->size()->compareTo((right)->size())) < 0 do ( left := left + stack->at(0`firstArg+1) ; stack := stack->excludingAt(0+1) ; i := i + 1) ; while (i->compareTo((weights)->size())) < 0 & ((right)->size()->compareTo((left)->size())) < 0 do ( right := right + stack->at(0`firstArg+1) ; stack := stack->excludingAt(0+1) ; i := i + 1) ; if (stack)->size() mod 2 = 0 & (left)->size() = (right)->size() then ( i := 1 ; while stack do ( if i = 1 then ( left := left + stack->at(0`firstArg+1) ; stack := stack->excludingAt(0+1) ) else ( right := right + stack->at(0`firstArg+1) ; stack := stack->excludingAt(0+1) ) ; i := i * (-1)) ; execute (left + "|" + right)->display() ) else ( execute ("Impossible")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines import itertools N,K,*A=map(int,read().split()) A=[x if x<=K else K+1 for x in A] A.sort() mask=(1<K : return True dp=1 for a in itertools.chain(A[: x],A[x+1 :]): dp |=(dp<>=(K-A[x]) return(dp>0) left=-1 right=N while left+1collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := A->select(x | true)->collect(x | (if (x->compareTo(K)) <= 0 then x else K + 1 endif)) ; A := A->sort() ; var mask : double := (1 * (2->pow(K))) - 1 ; skip ; var left : int := -1 ; var right : OclAny := N ; while (left + 1->compareTo(right)) < 0 do ( x := (left + right) div 2 ; if test(x) then ( right := x ) else ( left := x )) ; var answer : int := left + 1 ; execute (answer)->display(); operation test(x : OclAny) : OclAny pre: true post: true activity: if (A[x+1]->compareTo(K)) > 0 then ( return true ) else skip ; var dp : int := 1 ; for a : itertools.chain(A.subrange(1,x), A.subrange(x + 1+1)) do ( dp := dp or (dp * (2->pow(a))) ; dp := dp & mask) ; dp := dp div (2->pow((K - A[x+1]))) ; return (dp > 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def inpl(): return list(map(int,input().split())) N,K=inpl() A=sorted(inpl()) S=[] s=0 for a in A : s+=a S.append(s) A=A[: :-1] DP=[True]+[False for _ in range(K-1)] OK=[False for _ in range(N)] for i,a in enumerate(A): DP1=[False for _ in range(K)] if a>=K : OK[i]=True continue for j,d in enumerate(DP): if d : DP1[j]=True if j+a>=K : OK[i]=True else : DP1[j+a]=True DP=DP1 if sum(OK)==0 : print(N) else : print(OK[: :-1].index(True)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := inpl() ; var A : Sequence := inpl()->sort() ; var S : Sequence := Sequence{} ; var s : int := 0 ; for a : A do ( s := s + a ; execute ((s) : S)) ; A := A(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var DP : Sequence := Sequence{ true }->union(Integer.subrange(0, K - 1-1)->select(_anon | true)->collect(_anon | (false))) ; var OK : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (false)) ; for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); var DP1 : Sequence := Integer.subrange(0, K-1)->select(_anon | true)->collect(_anon | (false)) ; if (a->compareTo(K)) >= 0 then ( OK[i+1] := true ; continue ) else skip ; for _tuple : Integer.subrange(1, (DP)->size())->collect( _indx | Sequence{_indx-1, (DP)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); if d then ( DP1[j+1] := true ; if (j + a->compareTo(K)) >= 0 then ( OK[i+1] := true ) else ( DP1[j + a+1] := true ) ) else skip) ; DP := DP1) ; if (OK)->sum() = 0 then ( execute (N)->display() ) else ( execute (OK(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->indexOf(true) - 1)->display() ); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=list(map(int,input().split())) a.sort(reverse=True) dp=[False]*(k) dp[0]=True min_n=10**10 for i in a : for j in range(k-1,-1,-1): if(dp[j]): if(j+i>=k): min_n=i else : dp[j+i]=True ans=0 for i in a : ans+=(icollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (k)) ; dp->first() := true ; var min_n : double := (10)->pow(10) ; for i : a do ( for j : Integer.subrange(-1 + 1, k - 1)->reverse() do ( if (dp[j+1]) then ( if ((j + i->compareTo(k)) >= 0) then ( min_n := i ) else ( dp[j + i+1] := true ) ) else skip)) ; var ans : int := 0 ; for i : a do ( ans := ans + ((i->compareTo(min_n)) < 0)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect def solve(k,aaa): aaa=aaa[: bisect.bisect_left(aaa,k)] dp=[False]*k dp[0]=True curr_max=0 ans=len(aaa) for i,a in reversed(list(enumerate(aaa))): if curr_max+a>=k : ans=i f=True for j in range(min(curr_max,k-a-1),-1,-1): if dp[j]: dp[j+a]=True if f : curr_max=max(curr_max,j+a) f=False return ans n,k=map(int,input().split()) aaa=list(map(int,input().split())) aaa.sort() print(solve(k,aaa)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; aaa := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; aaa := aaa->sort() ; execute (solve(k, aaa))->display(); operation solve(k : OclAny, aaa : OclAny) : OclAny pre: true post: true activity: aaa := aaa.subrange(1,bisect.bisect_left(aaa, k)) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, k) ; dp->first() := true ; var curr_max : int := 0 ; var ans : int := (aaa)->size() ; for _tuple : ((Integer.subrange(1, (aaa)->size())->collect( _indx | Sequence{_indx-1, (aaa)->at(_indx)} )))->reverse() do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); if (curr_max + a->compareTo(k)) >= 0 then ( ans := i ) else skip ; var f : boolean := true ; for j : Integer.subrange(-1 + 1, Set{curr_max, k - a - 1}->min())->reverse() do ( if dp[j+1] then ( dp[j + a+1] := true ; if f then ( curr_max := Set{curr_max, j + a}->max() ; f := false ) else skip ) else skip)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left,bisect_right def solve(): N,K=map(int,input().split()) As=list(map(int,input().split())) As.sort() i=bisect_left(As,K) Bs=As[: i] M=len(Bs) def isOK(x): bitset=1<<(K-1) for i,B in enumerate(Bs): if i==x : continue bitset |=bitset>>B return bitset &((1<1 : mid=(ng+ok)//2 if isOK(mid): ok=mid else : ng=mid print(ok) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; solve(); operation solve() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var As : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; As := As->sort() ; var i : OclAny := bisect_left(As, K) ; var Bs : OclAny := As.subrange(1,i) ; var M : int := (Bs)->size() ; skip ; var ng : OclAny := null; var ok : OclAny := null; Sequence{ng,ok} := Sequence{-1,M} ; while (ok - ng)->abs() > 1 do ( var mid : int := (ng + ok) div 2 ; if isOK(mid) then ( var ok : int := mid ) else ( var ng : int := mid )) ; execute (ok)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): s=input() a=0 b=0 c=0 for i in s : if(i=="A"): a+=1 elif(i=="B"): b+=1 elif(i=="C"): c+=1 if(a+c==b): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var a : int := 0 ; var b : int := 0 ; var c : int := 0 ; for i : s->characters() do ( if (i = "A") then ( a := a + 1 ) else (if (i = "B") then ( b := b + 1 ) else (if (i = "C") then ( c := c + 1 ) else skip ) ) ) ; if (a + c = b) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): m=[*input()] a_c=0 b_c=0 c_c=0 for char in m : if char=='A' : a_c+=1 elif char=='B' : b_c+=1 else : c_c+=1 if a_c==b_c and c_c==0 or b_c==a_c+c_c : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var m : Sequence := (OclFile["System.in"]).readLine() ; var a_c : int := 0 ; var b_c : int := 0 ; var c_c : int := 0 ; for char : m do ( if char = 'A' then ( a_c := a_c + 1 ) else (if char = 'B' then ( b_c := b_c + 1 ) else ( c_c := c_c + 1 ) ) ) ; if a_c = b_c & c_c = 0 or b_c = a_c + c_c then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) k=int(input()) x=int(input()) y=int(input()) ans=0 for i in range(1,n+1): if i>k : ans+=y continue ans+=x print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var y : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( if (i->compareTo(k)) > 0 then ( ans := ans + y ; continue ) else skip ; ans := ans + x) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt MAX=100000 prime=[True]*MAX arr=[] def SieveOfEratosthenes(): for p in range(2,int(sqrt(MAX))+1): if prime[p]==True : for i in range(p*2,MAX,p): prime[i]=False for p in range(2,MAX): if prime[p]: arr.append(p) def isPrimorialPrime(n): if not prime[n]: return False product,i=1,0 while productdisplay() ) else ( execute ("NO")->display() ) ) else skip; operation SieveOfEratosthenes() pre: true post: true activity: for p : Integer.subrange(2, ("" + ((sqrt(MAX))))->toInteger() + 1-1) do ( if prime[p+1] = true then ( for i : Integer.subrange(p * 2, MAX-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip) ; for p : Integer.subrange(2, MAX-1) do ( if prime[p+1] then ( execute ((p) : arr) ) else skip); operation isPrimorialPrime(n : OclAny) : OclAny pre: true post: true activity: if not(prime[n+1]) then ( return false ) else skip ; var product : OclAny := null; var i : OclAny := null; Sequence{product,i} := Sequence{1,0} ; while (product->compareTo(n)) < 0 do ( product := product * arr[i+1] ; if product + 1 = n or product - 1 = n then ( return true ) else skip ; i := i + 1) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: print('YNEOS'[2*s.count('B')!=len(s)-1 : : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( execute ('YNEOS'(subscript (test (logical_test (comparison (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name s)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'B'))))))) )))))) != (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))) - (expr (atom (number (integer 1))))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(idx=None): n=int(input()) time=input() ans=0 for s in time[:-1]: if s!='0' : ans+=int(s)+1 ans+=int(time[-1]) print(ans) if __name__=='__main__' : for i in range(int(input())): solve(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve(i)) ) else skip; operation solve(idx : OclAny) pre: true post: true activity: if idx->oclIsUndefined() then idx := null else skip; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var time : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; for s : time->front() do ( if s /= '0' then ( ans := ans + ("" + ((s)))->toInteger() + 1 ) else skip) ; ans := ans + ("" + ((time->last())))->toInteger() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for test in range(t): s=input() number_A=0 number_B=0 number_C=0 for x in s : if x=='A' : number_A+=1 elif x=='B' : number_B+=1 elif x=='C' : number_C+=1 if(number_A+number_C)==number_B : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for test : Integer.subrange(0, t-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var number_A : int := 0 ; var number_B : int := 0 ; var number_C : int := 0 ; for x : s->characters() do ( if x = 'A' then ( number_A := number_A + 1 ) else (if x = 'B' then ( number_B := number_B + 1 ) else (if x = 'C' then ( number_C := number_C + 1 ) else skip ) ) ) ; if (number_A + number_C) = number_B then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_CHAR=256 ; count=[0]*(MAX_CHAR+1); def fact(n): return 1 if(n<=1)else(n*fact(n-1)); def populateAndIncreaseCount(str): for i in range(len(str)): count[ord(str[i])]+=1 ; for i in range(1,MAX_CHAR): count[i]+=count[i-1]; def updatecount(ch): for i in range(ord(ch),MAX_CHAR): count[i]-=1 ; def findRank(str): len1=len(str); mul=fact(len1); rank=1 ; populateAndIncreaseCount(str); for i in range(len1): mul=mul//(len1-i); rank+=count[ord(str[i])-1]*mul ; updatecount(str[i]); return rank ; str="string" ; print(findRank(str)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_CHAR : int := 256; ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX_CHAR + 1)); ; skip ; skip ; skip ; skip ; OclType["String"] := "string"; ; execute (findRank(OclType["String"]))->display();; operation fact(n : OclAny) pre: true post: true activity: return if (n <= 1) then 1 else (n * fact(n - 1)) endif;; operation populateAndIncreaseCount(OclType["String"] : OclAny) pre: true post: true activity: for i : Integer.subrange(0, (OclType["String"])->size()-1) do ( count[(("" + ([i+1])))->char2byte()+1] := count[(("" + ([i+1])))->char2byte()+1] + 1;) ; for i : Integer.subrange(1, MAX_CHAR-1) do ( count[i+1] := count[i+1] + count[i - 1+1];); operation updatecount(ch : OclAny) pre: true post: true activity: for i : Integer.subrange((ch)->char2byte(), MAX_CHAR-1) do ( count[i+1] := count[i+1] - 1;); operation findRank(OclType["String"] : OclAny) pre: true post: true activity: var len1 : int := (OclType["String"])->size(); ; var mul : OclAny := fact(len1); ; var rank : int := 1; ; populateAndIncreaseCount(OclType["String"]); ; for i : Integer.subrange(0, len1-1) do ( mul := mul div (len1 - i); ; rank := rank + count[(("" + ([i+1])))->char2byte() - 1+1] * mul; ; updatecount(("" + ([i+1])));) ; return rank;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def trailingZeroes(n): cnt=0 while n>0 : n=int(n/5) cnt+=n return cnt def binarySearch(n): low=0 high=1e6 while low 0 do ( n := ("" + ((n / 5)))->toInteger() ; cnt := cnt + n) ; return cnt; operation binarySearch(n : OclAny) pre: true post: true activity: var low : int := 0 ; var high : double := ("1e6")->toReal() ; while (low->compareTo(high)) < 0 do ( var mid : int := ("" + (((low + high) / 2)))->toInteger() ; var count : OclAny := trailingZeroes(mid) ; if (count->compareTo(n)) < 0 then ( low := mid + 1 ) else ( high := mid )) ; var result : Sequence := () ; while trailingZeroes(low) = n do ( execute ((low) : result) ; low := low + 1) ; for i : Integer.subrange(0, (result)->size()-1) do ( execute (result[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def MDAS_Factorial(N): if N<=2 : return N if N<=4 : return N+3 if(N-4)% 4==0 : return N+1 elif(N-4)% 4<=2 : return N+2 else : return N-1 N=4 print(MDAS_Factorial(N)) N=10 print(MDAS_Factorial(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 4 ; execute (MDAS_Factorial(N))->display() ; N := 10 ; execute (MDAS_Factorial(N))->display(); operation MDAS_Factorial(N : OclAny) : OclAny pre: true post: true activity: if N <= 2 then ( return N ) else skip ; if N <= 4 then ( return N + 3 ) else skip ; if (N - 4) mod 4 = 0 then ( return N + 1 ) else (if (N - 4) mod 4 <= 2 then ( return N + 2 ) else ( return N - 1 ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys line=sys.stdin.readline() ret="" for s in line : ret+=s.upper() print(ret,end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var line : String := (OclFile["System.in"]).readLine() ; var ret : String := "" ; for s : line->characters() do ( ret := ret + s->toUpperCase()) ; execute (ret)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(input().upper()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (input()->toUpperCase())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin def toupper(x): return chr(ord(x)-32)if x.islower()else x s=stdin.readline() print("".join(map(toupper,s)[:-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var s : String := stdin.readLine() ; execute (StringLib.sumStringsWithSeparator((map(toupper, s)->front()), ""))->display(); operation toupper(x : OclAny) : OclAny pre: true post: true activity: return if x->matches("[a-z ]*") then ((x)->char2byte() - 32)->byte2char() else x endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=str(input()) print(str.upper(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := ("" + (((OclFile["System.in"]).readLine()))) ; execute (("" + (->toUpperCase())))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines in_n=lambda : int(readline()) in_nn=lambda : map(int,readline().split()) in_s=lambda : readline().rstrip().decode('utf-8') in_nl=lambda : list(map(int,readline().split())) in_nl2=lambda H :[in_nl()for _ in range(H)] in_map=lambda :[s==ord('.')for s in readline()if s!=ord('\n')] in_map2=lambda H :[in_map()for _ in range(H)] in_all=lambda : map(int,read().split()) def main(): N,Z,W=in_nn() A=in_nl() if N==1 : ans=abs(W-A[0]) else : ans=max(abs(A[-1]-A[-2]),abs(A[-1]-W)) print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; var in_n : Function := lambda $$ : OclAny in (("" + ((readline())))->toInteger()) ; var in_nn : Function := lambda $$ : OclAny in ((readline().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var in_s : Function := lambda $$ : OclAny in (readline().rstrip().decode('utf-8')) ; var in_nl : Function := lambda $$ : OclAny in (((readline().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var in_nl2 : Function := lambda H : OclAny in (Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (in_nl->apply()))) ; var in_map : Function := lambda $$ : OclAny in (readline()->select(s | s /= (' ')->char2byte())->collect(s | (s = ('.')->char2byte()))) ; var in_map2 : Function := lambda H : OclAny in (Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (in_map->apply()))) ; var in_all : Function := lambda $$ : OclAny in ((read().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var Z : OclAny := null; var W : OclAny := null; Sequence{N,Z,W} := in_nn->apply() ; var A : OclAny := in_nl->apply() ; if N = 1 then ( var ans : double := (W - A->first())->abs() ) else ( ans := Set{(A->last() - A->front()->last())->abs(), (A->last() - W)->abs()}->max() ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys if __name__=='__main__' : for line in sys.stdin : print(line.strip().upper()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( for line : OclFile["System.in"] do ( execute (line->trim()->toUpperCase())->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect def search(li,x): i=bisect(li,x) return 0size()) & li[i - 1+1] = x; operation run() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; assert (n = (a)->size()) do "assertion failed" ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if search(a, k) then ( execute (1)->display() ) else ( execute (0)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- turn=int(input()) count=0 def game(x): x.sort() while len(x)>1 and 2048 not in x : if x.count(min(x))<2 : del x[0] else : for i in range(x.count(min(x))//2): x.append(2*min(x)) x.sort() del x[0 : x.count(min(x))//2*2] return x while counttoInteger() ; var count : int := 0 ; skip ; while (count->compareTo(turn)) < 0 do ( count := count + 1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var test : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if (game(test))->includes(2048) then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); operation game(x : OclAny) : OclAny pre: true post: true activity: x := x->sort() ; while (x)->size() > 1 & (x)->excludes(2048) do ( if x->count((x)->min()) < 2 then ( execute (x->first())->isDeleted() ) else ( for i : Integer.subrange(0, x->count((x)->min()) div 2-1) do ( execute ((2 * (x)->min()) : x)) ; x := x->sort() ; execute (x.subrange(0+1, x->count((x)->min()) div 2 * 2))->isDeleted() )) ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=set(map(int,input().split())) q=int(input()) while q : q-=1 k=int(input()) print(+(k in a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while q do ( q := q - 1 ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (((a)->includes(k)))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy BIG_NUM=2000000000 MOD=1000000007 EPS=0.000000001 N=int(input()) table=list(map(int,input().split())) num_query=int(input()) for _ in range(num_query): tmp=int(input()) L=0 R=len(table)-1 mid=(L+R)//2 loc=BIG_NUM while L<=R : if table[mid]==tmp : loc=mid break elif table[mid]>tmp : R=mid-1 else : L=mid+1 mid=(L+R)//2 if loc==BIG_NUM : print("0") else : print("1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var table : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var num_query : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, num_query-1) do ( var tmp : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var L : int := 0 ; var R : double := (table)->size() - 1 ; var mid : int := (L + R) div 2 ; var loc : int := BIG_NUM ; while (L->compareTo(R)) <= 0 do ( if table[mid+1] = tmp then ( loc := mid ; break ) else (if (table[mid+1]->compareTo(tmp)) > 0 then ( R := mid - 1 ) else ( L := mid + 1 ) ) ; mid := (L + R) div 2) ; if loc = BIG_NUM then ( execute ("0")->display() ) else ( execute ("1")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect if __name__=="__main__" : n=int(input()) nums=list(map(lambda x : int(x),input().split())) num_query=int(input()) for _ in range(num_query): k=int(input()) if nums[bisect(nums,k)-1]==k : print(1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nums : Sequence := ((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) )) ; var num_query : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, num_query-1) do ( var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if nums[bisect(nums, k) - 1+1] = k then ( execute (1)->display() ) else ( execute (0)->display() )) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(input()) a=tuple(map(int,sys.stdin.readline().split())) q=int(input()) for k in sys.stdin : k=int(k.strip()) if ktoInteger() ; var a : Sequence := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for k : OclFile["System.in"] do ( var k : int := ("" + ((k->trim())))->toInteger() ; if (k->compareTo(a->first())) < 0 or (a->last()->compareTo(k)) < 0 then ( execute ('0')->display() ) else ( var j1 : int := 0 ; var j2 : int := (a)->size() ; for _anon : Integer.subrange(0, (a)->size()-1) do ( var j : int := (j1 + j2) div 2 ; if k = a[j+1] then ( execute ('1')->display() ; break ) else ( if (a[j+1]->compareTo(k)) < 0 then ( j1 := j ) else ( j2 := j ) ; if j1 + 1 = j2 then ( if k = a[j1+1] or k = a[j2+1] then ( execute ('1')->display() ; break ) else ( execute ('0')->display() ; break ) ) else skip ) ; if _anon = (a)->size() - 1 then ( execute ('0')->display() ) else skip) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): string=str(input()) tamanho_das_sequencias=[] for sequencia in string.split("0"): if sequencia : tamanho_das_sequencias.append(len(sequencia)) tamanho_das_sequencias.sort(reverse=True) pontuacao_alice=0 for i in range(len(tamanho_das_sequencias)): if i % 2==0 : pontuacao_alice+=tamanho_das_sequencias[i] print(pontuacao_alice) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var string : String := ("" + (((OclFile["System.in"]).readLine()))) ; var tamanho_das_sequencias : Sequence := Sequence{} ; for sequencia : string.split("0") do ( if sequencia then ( execute (((sequencia)->size()) : tamanho_das_sequencias) ) else skip) ; tamanho_das_sequencias := tamanho_das_sequencias->sort() ; var pontuacao_alice : int := 0 ; for i : Integer.subrange(0, (tamanho_das_sequencias)->size()-1) do ( if i mod 2 = 0 then ( pontuacao_alice := pontuacao_alice + tamanho_das_sequencias[i+1] ) else skip) ; execute (pontuacao_alice)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): s=input() s+='0' a=[] count=0 for x in s : if x=='1' : count+=1 elif count : a.append(count) count=0 a.sort(reverse=True) print(sum(a[: : 2])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var s : String := (OclFile["System.in"]).readLine() ; s := s + '0' ; var a : Sequence := Sequence{} ; var count : int := 0 ; for x : s->characters() do ( if x = '1' then ( count := count + 1 ) else (if count then ( execute ((count) : a) ; count := 0 ) else skip)) ; a := a->sort() ; execute ((a(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): s=[len(i)for i in input().split('0')] s.sort(reverse=True) print(sum(s[: : 2])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : Sequence := input().split('0')->select(i | true)->collect(i | ((i)->size())) ; s := s->sort() ; execute ((s(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np def nonDecNums(n): a=np.zeros((n+1,10)) for i in range(10): a[0][i]=1 for i in range(1,n+1): a[i][9]=1 for i in range(1,n+1): for j in range(8,-1,-1): a[i][j]=a[i-1][j]+a[i][j+1] return int(a[n][0]) if __name__=="__main__" : n=2 print("Non-decreasing digits=",nonDecNums(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 2 ; execute ("Non-decreasing digits=")->display() ) else skip; operation nonDecNums(n : OclAny) : OclAny pre: true post: true activity: var a : Sequence := MatrixLib.singleValueMatrix(Sequence{n + 1, 10}, 0.0) ; for i : Integer.subrange(0, 10-1) do ( a->first()[i+1] := 1) ; for i : Integer.subrange(1, n + 1-1) do ( a[i+1][9+1] := 1) ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(-1 + 1, 8)->reverse() do ( a[i+1][j+1] := a[i - 1+1][j+1] + a[i+1][j + 1+1])) ; return ("" + ((a[n+1]->first())))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re def solve(s): one_groups=re.split("0+",s) one_groups.sort(reverse=True) alice_points=0 for i in range(0,len(one_groups),2): alice_points+=len(one_groups[i]) return alice_points if __name__=="__main__" : t=int(input()) for i in range(0,t): s=input() print(solve(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( s := (OclFile["System.in"]).readLine() ; execute (solve(s))->display()) ) else skip; operation solve(s : OclAny) : OclAny pre: true post: true activity: var one_groups : Sequence(String) := (s)->split("0+") ; one_groups := one_groups->sort() ; var alice_points : int := 0 ; for i : Integer.subrange(0, (one_groups)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( alice_points := alice_points + (one_groups[i+1])->size()) ; return alice_points; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): string=str(input()) tamanho_das_sequencias=[] for sequencia in string.split("0"): if sequencia : tamanho_das_sequencias.append(len(sequencia)) tamanho_das_sequencias.sort(reverse=True) pontuacao_alice=0 for i in range(len(tamanho_das_sequencias)): if i % 2==0 : pontuacao_alice+=tamanho_das_sequencias[i] print(pontuacao_alice) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var string : String := ("" + (((OclFile["System.in"]).readLine()))) ; var tamanho_das_sequencias : Sequence := Sequence{} ; for sequencia : string.split("0") do ( if sequencia then ( execute (((sequencia)->size()) : tamanho_das_sequencias) ) else skip) ; tamanho_das_sequencias := tamanho_das_sequencias->sort() ; var pontuacao_alice : int := 0 ; for i : Integer.subrange(0, (tamanho_das_sequencias)->size()-1) do ( if i mod 2 = 0 then ( pontuacao_alice := pontuacao_alice + tamanho_das_sequencias[i+1] ) else skip) ; execute (pontuacao_alice)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections def minimumBox(arr,n): q=collections.deque([]) arr.sort() q.append(arr[0]) for i in range(1,n): now=q[0] if(arr[i]>=2*now): q.popleft() q.append(arr[i]) return len(q) if __name__=='__main__' : arr=[4,1,2,8] n=len(arr) print(minimumBox(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{4}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 8 }))) ; n := (arr)->size() ; execute (minimumBox(arr, n))->display() ) else skip; operation minimumBox(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var q : Sequence := (Sequence{}) ; arr := arr->sort() ; execute ((arr->first()) : q) ; for i : Integer.subrange(1, n-1) do ( var now : OclAny := q->first() ; if ((arr[i+1]->compareTo(2 * now)) >= 0) then ( q := q->tail() ) else skip ; execute ((arr[i+1]) : q)) ; return (q)->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) answer="" for i in range(q): n=int(input()) n_list=list(map(int,input().split())) n_list.sort() for j in range(0,n-1): if n_list.count(2048)!=0 : break elif n_list[j]==n_list[j+1]: n_list[j+1]*=2 n_list[j]=0 n_list.sort() if n_list.count(2048)!=0 : answer+="YES\n" else : answer+="NO\n" print(answer.strip()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var answer : String := "" ; for i : Integer.subrange(0, q-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var n_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; n_list := n_list->sort() ; for j : Integer.subrange(0, n - 1-1) do ( if n_list->count(2048) /= 0 then ( break ) else (if n_list[j+1] = n_list[j + 1+1] then ( n_list[j + 1+1] := n_list[j + 1+1] * 2 ; n_list[j+1] := 0 ) else skip) ; n_list := n_list->sort()) ; if n_list->count(2048) /= 0 then ( answer := answer + "YES\n" ) else ( answer := answer + "NO\n" )) ; execute (answer->trim())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) c=list(map(int,input().split())) d={} for i in range(n): if d.get(c[i],None)is None : d[c[i]]=[1,i % 2] elif d[c[i]][1]!=i % 2 : d[c[i]][0]+=1 d[c[i]][1]^=1 print(*(d.get(i,[0])[0]for i in range(1,n+1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( if d.get(c[i+1], null) <>= null then ( d[c[i+1]+1] := Sequence{1}->union(Sequence{ i mod 2 }) ) else (if d[c[i+1]+1][1+1] /= i mod 2 then ( d[c[i+1]+1]->first() := d[c[i+1]+1]->first() + 1 ; d[c[i+1]+1][1+1] := d[c[i+1]+1][1+1] xor 1 ) else skip)) ; execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name d)) (trailer . (name get) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ]))))))) ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) )))))))) ))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdout nmbr=lambda : int(input()) lst=lambda : list(map(int,input().split())) from collections import defaultdict for _ in range(nmbr()): n=nmbr() ans=[] a=lst() g=defaultdict(list) for i in range(n): g[a[i]].append(i & 1) for col in range(1,n+1): mx=0 if col in g : req=g[col][0] for v in g[col]: if v==req : mx+=1 req ^=1 ans.append(mx) print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var nmbr : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var lst : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; skip ; for _anon : Integer.subrange(0, nmbr->apply()-1) do ( var n : OclAny := nmbr->apply() ; var ans : Sequence := Sequence{} ; var a : OclAny := lst->apply() ; var g : OclAny := defaultdict(OclType["Sequence"]) ; for i : Integer.subrange(0, n-1) do ((expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) & (expr (atom (number (integer 1)))))))))) ))))) ; for col : Integer.subrange(1, n + 1-1) do ( var mx : int := 0 ; if (g)->includes(col) then ( var req : OclAny := g[col+1]->first() ; for v : g[col+1] do ( if v = req then ( mx := mx + 1 ; req := req xor 1 ) else skip) ) else skip ; execute ((mx) : ans)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) arr=list(map(int,input().split())) output_arr=[0]*(n+1) curr=[0]*(n+1) d={} for i in range(n): if arr[i]not in d : d[arr[i]]=i curr[arr[i]]=1 output_arr[arr[i]]=max(output_arr[arr[i]],curr[arr[i]]) else : if(d[arr[i]]-i)% 2==1 : d[arr[i]]=i curr[arr[i]]+=1 output_arr[arr[i]]=max(output_arr[arr[i]],curr[arr[i]]) print(*output_arr[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var output_arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var curr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var d : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( if (d)->excludes(arr[i+1]) then ( d[arr[i+1]+1] := i ; curr[arr[i+1]+1] := 1 ; output_arr[arr[i+1]+1] := Set{output_arr[arr[i+1]+1], curr[arr[i+1]+1]}->max() ) else ( if (d[arr[i+1]+1] - i) mod 2 = 1 then ( d[arr[i+1]+1] := i ; curr[arr[i+1]+1] := curr[arr[i+1]+1] + 1 ; output_arr[arr[i+1]+1] := Set{output_arr[arr[i+1]+1], curr[arr[i+1]+1]}->max() ) else skip )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name output_arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) last=[None]*n count=[0]*n for i,x in enumerate(input().split()): x=int(x)-1 if last[x]is None or(last[x]+i)% 2==1 : last[x]=i count[x]+=1 print(" ".join(map(str,count))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var last : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for _tuple : Integer.subrange(1, (input().split())->size())->collect( _indx | Sequence{_indx-1, (input().split())->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); var x : double := ("" + ((x)))->toInteger() - 1 ; if last[x+1] <>= null or (last[x+1] + i) mod 2 = 1 then ( last[x+1] := i ; count[x+1] := count[x+1] + 1 ) else skip) ; execute (StringLib.sumStringsWithSeparator(((count)->collect( _x | (OclType["String"])->apply(_x) )), " "))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) last=[None]*n count=[0]*n for i,x in enumerate(input().split()): x=int(x)-1 if last[x]is None or(last[x]+i)% 2==1 : last[x]=i count[x]+=1 print(*count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var last : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for _tuple : Integer.subrange(1, (input().split())->size())->collect( _indx | Sequence{_indx-1, (input().split())->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); var x : double := ("" + ((x)))->toInteger() - 1 ; if last[x+1] <>= null or (last[x+1] + i) mod 2 = 1 then ( last[x+1] := i ; count[x+1] := count[x+1] + 1 ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name count))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def SieveOfAtkin(limit): if(limit>2): print(2,end=" ") if(limit>3): print(3,end=" ") sieve=[False]*limit for i in range(0,limit): sieve[i]=False x=1 while(x*xy and n<=limit and n % 12==11): sieve[n]^=True y+=1 x+=1 r=5 while(r*r 2) then ( execute (2)->display() ) else skip ; if (limit > 3) then ( execute (3)->display() ) else skip ; var sieve : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, limit) ; for i : Integer.subrange(0, limit-1) do ( sieve[i+1] := false) ; var x : int := 1 ; while ((x * x->compareTo(limit)) < 0) do ( var y : int := 1 ; while ((y * y->compareTo(limit)) < 0) do ( var n : int := (4 * x * x) + (y * y) ; if ((n->compareTo(limit)) <= 0 & (n mod 12 = 1 or n mod 12 = 5)) then ( sieve[n+1] := sieve[n+1] xor true ) else skip ; n := (3 * x * x) + (y * y) ; if ((n->compareTo(limit)) <= 0 & n mod 12 = 7) then ( sieve[n+1] := sieve[n+1] xor true ) else skip ; n := (3 * x * x) - (y * y) ; if ((x->compareTo(y)) > 0 & (n->compareTo(limit)) <= 0 & n mod 12 = 11) then ( sieve[n+1] := sieve[n+1] xor true ) else skip ; y := y + 1) ; x := x + 1) ; var r : int := 5 ; while ((r * r->compareTo(limit)) < 0) do ( if (sieve[r+1]) then ( for i : Integer.subrange(r * r, limit-1)->select( $x | ($x - r * r) mod r * r = 0 ) do ( sieve[i+1] := false) ) else skip) ; for a : Integer.subrange(5, limit-1) do ( if (sieve[a+1]) then ( execute (a)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) d={} f=0 for i in range(n): x=(i+l[i])% n if x in d : f=1 break else : d[x]=1 if f==1 : print('NO') else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := Set{} ; var f : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x : int := (i + l[i+1]) mod n ; if (d)->includes(x) then ( f := 1 ; break ) else ( d[x+1] := 1 )) ; if f = 1 then ( execute ('NO')->display() ) else ( execute ('YES')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMinimumZ(n,a,b): if(a>b): temp=a a=b b=temp distClock=b-a distAntiClock=(a-1)+(n-b+1) minDist=min(distClock,distAntiClock) if(minDist==1): return 3 return minDist if __name__=='__main__' : n=4 a=1 b=2 print(findMinimumZ(n,a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 4 ; a := 1 ; b := 2 ; execute (findMinimumZ(n, a, b))->display() ) else skip; operation findMinimumZ(n : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if ((a->compareTo(b)) > 0) then ( var temp : OclAny := a ; a := b ; b := temp ) else skip ; var distClock : double := b - a ; var distAntiClock : double := (a - 1) + (n - b + 1) ; var minDist : OclAny := Set{distClock, distAntiClock}->min() ; if (minDist = 1) then ( return 3 ) else skip ; return minDist; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calcDeterminant(arr,n): determinant=0 for i in range(n): determinant+=pow(arr[i],3) determinant-=3*arr[0]*arr[1]*arr[2] return determinant arr=[4,5,3] n=len(arr) print(calcDeterminant(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{4}->union(Sequence{5}->union(Sequence{ 3 })) ; n := (arr)->size() ; execute (calcDeterminant(arr, n))->display(); operation calcDeterminant(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var determinant : int := 0 ; for i : Integer.subrange(0, n-1) do ( determinant := determinant + (arr[i+1])->pow(3)) ; determinant := determinant - 3 * arr->first() * arr[1+1] * arr[2+1] ; return determinant; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def AllIndexesRecursive(input,x,start): if(start==len(input)): ans=[] return ans smallIndex=AllIndexesRecursive(input,x,start+1) if(input[start]==x): myAns=[0 for i in range(len(smallIndex)+1)] myAns[0]=start for i in range(len(smallIndex)): myAns[i+1]=smallIndex[i] return myAns else : return smallIndex def AllIndexes(input,x): return AllIndexesRecursive(input,x,0) arr=[1,2,3,2,2,5] x=2 output=AllIndexes(arr,x) for i in output : print(i,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var arr : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 5 }))))) ; x := 2 ; var output : OclAny := AllIndexes(arr, x) ; for i : output do ( execute (i)->display()); operation AllIndexesRecursive(input : OclAny, x : OclAny, start : OclAny) : OclAny pre: true post: true activity: if (start = (input)->size()) then ( var ans : Sequence := Sequence{} ; return ans ) else skip ; var smallIndex : OclAny := AllIndexesRecursive(input, x, start + 1) ; if ((OclFile["System.in"]).readLine[start+1] = x) then ( var myAns : Sequence := Integer.subrange(0, (smallIndex)->size() + 1-1)->select(i | true)->collect(i | (0)) ; myAns->first() := start ; for i : Integer.subrange(0, (smallIndex)->size()-1) do ( myAns[i + 1+1] := smallIndex[i+1]) ; return myAns ) else ( return smallIndex ); operation AllIndexes(input : OclAny, x : OclAny) : OclAny pre: true post: true activity: return AllIndexesRecursive(input, x, 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def LeibnizHarmonicTriangle(n): C=[[0 for x in range(n+1)]for y in range(n+1)]; for i in range(0,n+1): for j in range(0,min(i,n)+1): if(j==0 or j==i): C[i][j]=1 ; else : C[i][j]=(C[i-1][j-1]+C[i-1][j]); for i in range(1,n+1): for j in range(1,i+1): print("1/",end=""); print(i*C[i-1][j-1],end=" "); print(); LeibnizHarmonicTriangle(4); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; LeibnizHarmonicTriangle(4);; operation LeibnizHarmonicTriangle(n : OclAny) pre: true post: true activity: var C : Sequence := Integer.subrange(0, n + 1-1)->select(y | true)->collect(y | (Integer.subrange(0, n + 1-1)->select(x | true)->collect(x | (0)))); ; for i : Integer.subrange(0, n + 1-1) do ( for j : Integer.subrange(0, Set{i, n}->min() + 1-1) do ( if (j = 0 or j = i) then ( C[i+1][j+1] := 1; ) else ( C[i+1][j+1] := (C[i - 1+1][j - 1+1] + C[i - 1+1][j+1]); ))) ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, i + 1-1) do ( execute ("1/")->display(); ; execute (i * C[i - 1+1][j - 1+1])->display();) ; execute (->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): input() s=[int(c)for c in input().split()if int(c)<=2048] print("YES" if sum(s)>=2048 else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( input() ; var s : Sequence := input().split()->select(c | ("" + ((c)))->toInteger() <= 2048)->collect(c | (("" + ((c)))->toInteger())) ; execute (if (s)->sum() >= 2048 then "YES" else "NO" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printpascalmatrix(n): C=[[0 for x in range(2*n+1)]for y in range(2*n+1)] for i in range(2*n+1): for j in range(min(i,2*n)+1): if(j==0 or j==i): C[i][j]=1 ; else : C[i][j]=(C[i-1][j-1]+C[i-1][j]); for i in range(n): for j in range(n): print(C[i+j][i],end=" "); print(); n=5 ; printpascalmatrix(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5; ; printpascalmatrix(n);; operation printpascalmatrix(n : OclAny) pre: true post: true activity: var C : Sequence := Integer.subrange(0, 2 * n + 1-1)->select(y | true)->collect(y | (Integer.subrange(0, 2 * n + 1-1)->select(x | true)->collect(x | (0)))) ; for i : Integer.subrange(0, 2 * n + 1-1) do ( for j : Integer.subrange(0, Set{i, 2 * n}->min() + 1-1) do ( if (j = 0 or j = i) then ( C[i+1][j+1] := 1; ) else ( C[i+1][j+1] := (C[i - 1+1][j - 1+1] + C[i - 1+1][j+1]); ))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( execute (C[i + j+1][i+1])->display();) ; execute (->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findK(n,k): if(n % 2==0): pos=n//2 ; else : pos=(n//2)+1 ; if(k<=pos): return(k*2-1); else : return((k-pos)*2); def countSetBits(n,k): kth=findK(n,k); return bin(kth).count('1'); if __name__=="__main__" : n=18 ; k=12 ; print(countSetBits(n,k)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 18; k := 12; ; execute (countSetBits(n, k))->display(); ) else skip; operation findK(n : OclAny, k : OclAny) pre: true post: true activity: if (n mod 2 = 0) then ( var pos : int := n div 2; ) else ( pos := (n div 2) + 1; ) ; if ((k->compareTo(pos)) <= 0) then ( return (k * 2 - 1); ) else ( return ((k - pos) * 2); ); operation countSetBits(n : OclAny, k : OclAny) pre: true post: true activity: var kth : OclAny := findK(n, k); ; return bin(kth)->count('1');; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) minMex=float("inf") for i in range(m): l,r=map(int,input().split()) minMex=min(minMex,r-l+1) print(minMex) a=0 for i in range(n): print(a,end=" ") a+=1 if a==minMex : a=0 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var minMex : double := ("" + (("inf")))->toReal() ; for i : Integer.subrange(0, m-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; minMex := Set{minMex, r - l + 1}->min()) ; execute (minMex)->display() ; var a : int := 0 ; for i : Integer.subrange(0, n-1) do ( execute (a)->display() ; a := a + 1 ; if a = minMex then ( a := 0 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) mn=n for _ in range(m): l,r=map(int,input().split()) mn=min(mn,r-l+1) print(mn) print(*[i % mn for i in range(n)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mn : OclAny := n ; for _anon : Integer.subrange(0, m-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; mn := Set{mn, r - l + 1}->min()) ; execute (mn)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) % (expr (atom (name mn))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) ])))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,m=map(int,input().split()) seg=[list(map(int,input().split()))for i in range(m)] min_l=10**18 for l,r in seg : min_l=min(min_l,r-l+1) ans=[i for i in range(min_l)]*((n+min_l-1)//min_l) ans=ans[: n] print(min_l) print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var seg : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var min_l : double := (10)->pow(18) ; for _tuple : seg do (var _indx : int := 1; var l : OclAny := _tuple->at(_indx); _indx := _indx + 1; var r : OclAny := _tuple->at(_indx); min_l := Set{min_l, r - l + 1}->min()) ; var ans : Sequence := MatrixLib.elementwiseMult(Integer.subrange(0, min_l-1)->select(i | true)->collect(i | (i)), ((n + min_l - 1) div min_l)) ; ans := ans.subrange(1,n) ; execute (min_l)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) a=list(map(int,input().split())) for i in range(n): a[i]=a[i]% n l=[0]*(2*n) for k in range(n): l[k+a[k]]+=1 if l[k]==2 : print("NO") return for j in range(n): if l[j]+l[n+j]!=1 : print("NO") return print("YES") for _ in range(int(input())): main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( main()); operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( a[i+1] := a[i+1] mod n) ; var l : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * n)) ; for k : Integer.subrange(0, n-1) do ( l[k + a[k+1]+1] := l[k + a[k+1]+1] + 1 ; if l[k+1] = 2 then ( execute ("NO")->display() ; return ) else skip) ; for j : Integer.subrange(0, n-1) do ( if l[j+1] + l[n + j+1] /= 1 then ( execute ("NO")->display() ; return ) else skip) ; execute ("YES")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) w=10**18 for i in range(m): a,b=map(int,input().split()) w=min(w,b-a+1) print(w) print(*[i % w for i in range(n)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : double := (10)->pow(18) ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; w := Set{w, b - a + 1}->min()) ; execute (w)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) % (expr (atom (name w))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) ])))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math MAX=10000 ; primes=[]; def sieveSundaram(): marked=[False]*int(MAX/2+1); for i in range(1,int((math.sqrt(MAX)-1)/2)+1): for j in range((i*(i+1))<<1,int(MAX/2)+1,2*i+1): marked[j]=True ; primes.append(2); for i in range(1,int(MAX/2)+1): if(marked[i]==False): primes.append(2*i+1); def isEquidigital(n): if(n==1): return True ; original_no=n ; sumDigits=0 ; while(original_no>0): sumDigits+=1 ; original_no=int(original_no/10); pDigit=0 ; count_exp=0 ; p=0 ; i=0 ; while(primes[i]<=int(n/2)): while(n % primes[i]==0): p=primes[i]; n=int(n/p); count_exp+=1 ; while(p>0): pDigit+=1 ; p=int(p/10); while(count_exp>1): pDigit+=1 ; count_exp=int(count_exp/10); i+=1 ; if(n!=1): while(n>0): pDigit+=1 ; n=int(n/10); return(pDigit==sumDigits); sieveSundaram(); print("Printing first few Equidigital","Numbers using isEquidigital()"); for i in range(1,20): if(isEquidigital(i)): print(i,end=" "); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MAX : int := 10000; ; var primes : Sequence := Sequence{}; ; skip ; skip ; sieveSundaram(); ; execute ("Printing first few Equidigital")->display(); ; for i : Integer.subrange(1, 20-1) do ( if (isEquidigital(i)) then ( execute (i)->display(); ) else skip); operation sieveSundaram() pre: true post: true activity: var marked : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, ("" + ((MAX / 2 + 1)))->toInteger()); ; for i : Integer.subrange(1, ("" + ((((MAX)->sqrt() - 1) / 2)))->toInteger() + 1-1) do ( for j : Integer.subrange((i * (i + 1)) * (2->pow(1)), ("" + ((MAX / 2)))->toInteger() + 1-1)->select( $x | ($x - (i * (i + 1)) * (2->pow(1))) mod 2 * i + 1 = 0 ) do ( marked[j+1] := true;)) ; execute ((2) : primes); ; for i : Integer.subrange(1, ("" + ((MAX / 2)))->toInteger() + 1-1) do ( if (marked[i+1] = false) then ( execute ((2 * i + 1) : primes); ) else skip); operation isEquidigital(n : OclAny) pre: true post: true activity: if (n = 1) then ( return true; ) else skip ; var original_no : OclAny := n; ; var sumDigits : int := 0; ; while (original_no > 0) do ( sumDigits := sumDigits + 1; ; original_no := ("" + ((original_no / 10)))->toInteger();) ; var pDigit : int := 0; ; var count_exp : int := 0; ; var p : int := 0; ; var i : int := 0; ; while ((primes[i+1]->compareTo(("" + ((n / 2)))->toInteger())) <= 0) do ( while (n mod primes[i+1] = 0) do ( p := primes[i+1]; ; n := ("" + ((n / p)))->toInteger(); ; count_exp := count_exp + 1;) ; while (p > 0) do ( pDigit := pDigit + 1; ; p := ("" + ((p / 10)))->toInteger();) ; while (count_exp > 1) do ( pDigit := pDigit + 1; ; count_exp := ("" + ((count_exp / 10)))->toInteger();) ; i := i + 1;) ; if (n /= 1) then ( while (n > 0) do ( pDigit := pDigit + 1; ; n := ("" + ((n / 10)))->toInteger();) ) else skip ; return (pDigit = sumDigits);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re from pprint import pprint fi=open('C-large.in','r') fo=open('C-large.out','w') t=int(fi.readline()) for _ in range(1,t+1): n=int(fi.readline()) v=map(int,fi.readline().split()) s=0 ss=0 for x in v : s ^=x ss+=x if s>0 : fo.write('Case #%d: NO\n' % _) else : fo.write('Case #%d: %d\n' %(_,ss-min(v))) fi.close() fo.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var fi : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('C-large.in')) ; var fo : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('C-large.out')) ; var t : int := ("" + ((fi.readLine())))->toInteger() ; for _anon : Integer.subrange(1, t + 1-1) do ( var n : int := ("" + ((fi.readLine())))->toInteger() ; var v : Sequence := (fi.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : int := 0 ; var ss : int := 0 ; for x : v do ( s := s xor x ; ss := ss + x) ; if s > 0 then ( fo.write(StringLib.format('Case #%d: NO ',_anon)) ) else ( fo.write(StringLib.format('Case #%d: %d ',Sequence{_anon, ss - (v)->min()})) )) ; fi.closeFile() ; fo.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- data=[l.strip()for l in open("infile","r").readlines()] out=open("outfile","w") ncases=int(data.pop(0)) for case in range(ncases): numcandies=int(data.pop(0)) candies=[int(c)for c in data.pop(0).split(' ')] truesum=0 xorsum=0 minimum=candies[0] for i in candies : truesum+=i xorsum ^=i if iselect(l | true)->collect(l | (l->trim())) ; var out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("outfile")) ; var ncases : int := ("" + ((data->at(0`firstArg+1))))->toInteger() ; for case : Integer.subrange(0, ncases-1) do ( var numcandies : int := ("" + ((data->at(0`firstArg+1))))->toInteger() ; var candies : Sequence := data->at(0`firstArg+1).split(' ')->select(c | true)->collect(c | (("" + ((c)))->toInteger())) ; var truesum : int := 0 ; var xorsum : int := 0 ; var minimum : OclAny := candies->first() ; for i : candies do ( truesum := truesum + i ; xorsum := xorsum xor i ; if (i->compareTo(minimum)) < 0 then ( minimum := i ) else skip) ; var ans : String := 'NO' ; if xorsum = 0 then ( ans := ("" + ((truesum - minimum))) ) else skip ; out.write("Case #" + ("" + ((case + 1))) + ": " + ans + "\n")); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printPrevSmaller(arr,n): print("_,",end="") for i in range(1,n): for j in range(i-1,-2,-1): if(arr[j]union(Sequence{3}->union(Sequence{0}->union(Sequence{2}->union(Sequence{ 5 })))) ; n := (arr)->size() ; printPrevSmaller(arr, n); operation printPrevSmaller(arr : OclAny, n : OclAny) pre: true post: true activity: execute ("_,")->display() ; for i : Integer.subrange(1, n-1) do ( for j : Integer.subrange(-2 + 1, i - 1)->reverse() do ( if ((arr[j+1]->compareTo(arr[i+1])) < 0) then ( execute (arr[j+1])->display() ; break ) else skip) ; if (j = -1) then ( execute ("_,")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) for i in range(x): a=input() b=input().split() c=[int(x)for x in b] c.sort() d=0 i=0 if 2048 in c : d=1 print("YES") else : while i<=len(c)-2 : if c[i]==c[i+1]: c.insert(i,c[i]*2) del(c[i+1]) del(c[i+1]) c.sort() i=0 else : i+=1 if 2048 in c : print("YES") d=1 break if d==0 : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, x-1) do ( var a : String := (OclFile["System.in"]).readLine() ; var b : OclAny := input().split() ; var c : Sequence := b->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; c := c->sort() ; var d : int := 0 ; var i : int := 0 ; if (c)->includes(2048) then ( d := 1 ; execute ("YES")->display() ) else ( while (i->compareTo((c)->size() - 2)) <= 0 do ( if c[i+1] = c[i + 1+1] then ( c := c.insertAt(i+1, c[i+1] * 2) ; execute ((c[i + 1+1]))->isDeleted() ; execute ((c[i + 1+1]))->isDeleted() ; c := c->sort() ; i := 0 ) else ( i := i + 1 ) ; if (c)->includes(2048) then ( execute ("YES")->display() ; d := 1 ; break ) else skip) ) ; if d = 0 then ( execute ("NO")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for sol in[*open(0)][2 : : 2]: y,*x=map(int,sol.split()); print('YNEOS'[any(p % y for p in x): : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for sol : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var y : OclAny := null; var x : OclAny := null; Sequence{y,x} := (sol.split())->collect( _x | (OclType["int"])->apply(_x) ); execute ('YNEOS'(subscript (test (logical_test (comparison (expr (atom (name any)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name p))) % (expr (atom (name y))))))) (comp_for for (exprlist (expr (atom (name p)))) in (logical_test (comparison (expr (atom (name x)))))))) ))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=lambda : stdin.readline()[:-1] for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) cnt=0 for i in range(1,n): if a[i]% a[0]!=0 : cnt+=1 if len(set(a))==1 : print("YES") elif a[0]==1 : print("YES") elif cnt==0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (stdin.readLine()->front()) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : int := 0 ; for i : Integer.subrange(1, n-1) do ( if a[i+1] mod a->first() /= 0 then ( cnt := cnt + 1 ) else skip) ; if (Set{}->union((a)))->size() = 1 then ( execute ("YES")->display() ) else (if a->first() = 1 then ( execute ("YES")->display() ) else (if cnt = 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) a=list(map(int,input().split())) for j in range(1,n): if a[j]% a[0]==0 : continue else : print('NO') break else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))) % (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt continue)))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=input() a=list(map(int,input().split())) ans="YES" for x in a[1 :]: if x % a[0]: ans="NO" break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : String := (OclFile["System.in"]).readLine() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : String := "YES" ; for x : a->tail() do ( if x mod a->first() then ( ans := "NO" ; break ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: a=s.split(); n=len(a); print('YNEOS'[len({(k+int(a[k]))% n for k in range(n)})size(); execute ('YNEOS'(subscript (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom { (dictorsetmaker (testlist_comp (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name k))) + (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])))))))) ))))))))) ))) % (expr (atom (name n))))))) (comp_for for (exprlist (expr (atom (name k)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))) }))))))) ))))) < (comparison (expr (atom (name n))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): N=int(input()) arr=[int(e)for e in input().split()] for n in arr[1 :]: if n % arr[0]!=0 : return "NO" return "YES" T=int(input()) for _ in range(T): s=solve() print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, T-1) do ( var s : OclAny := solve() ; execute (s)->display()); operation solve() : OclAny pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := input().split()->select(e | true)->collect(e | (("" + ((e)))->toInteger())) ; for n : arr->tail() do ( if n mod arr->first() /= 0 then ( return "NO" ) else skip) ; return "YES"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkBisymmetric(m,n): for i in range(0,n): for j in range(0,i): if(m[i][j]!=m[j][i]): return false for i in range(0,n): for j in range(0,n-i): if(m[i][j]!=m[n-j-1][n-i-1]): return False return True ; n=3 ; m=[[1,2,3],[2,5,2],[3,2,1]] if(checkBisymmetric(m,n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3; ; m := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{Sequence{2}->union(Sequence{5}->union(Sequence{ 2 }))}->union(Sequence{ Sequence{3}->union(Sequence{2}->union(Sequence{ 1 })) })) ; if (checkBisymmetric(m, n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation checkBisymmetric(m : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, i-1) do ( if (m[i+1][j+1] /= m[j+1][i+1]) then ( return false ) else skip)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n - i-1) do ( if (m[i+1][j+1] /= m[n - j - 1+1][n - i - 1+1]) then ( return false ) else skip)) ; return true;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def __gcd(a,b): if(a==0): return b return __gcd(b % a,a) def minimumMoves(A,N): one=0 for i in range(N): if(A[i]==1): one+=1 if(one!=0): return N-one minimum=+2147483647 for i in range(N): g=A[i] for j in range(i+1,N): g=__gcd(A[j],g) if(g==1): minimum=min(minimum,j-i) break if(minimum==+2147483647): return-1 else : return N+minimum-1 ; A=[2,4,3,9] N=len(A) print(minimumMoves(A,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; A := Sequence{2}->union(Sequence{4}->union(Sequence{3}->union(Sequence{ 9 }))) ; N := (A)->size() ; execute (minimumMoves(A, N))->display(); operation __gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0) then ( return b ) else skip ; return __gcd(b mod a, a); operation minimumMoves(A : OclAny, N : OclAny) : OclAny pre: true post: true activity: var one : int := 0 ; for i : Integer.subrange(0, N-1) do ( if (A[i+1] = 1) then ( one := one + 1 ) else skip) ; if (one /= 0) then ( return N - one ) else skip ; var minimum : int := 2147483647 ; for i : Integer.subrange(0, N-1) do ( var g : OclAny := A[i+1] ; for j : Integer.subrange(i + 1, N-1) do ( g := __gcd(A[j+1], g) ; if (g = 1) then ( minimum := Set{minimum, j - i}->min() ; break ) else skip)) ; if (minimum = 2147483647) then ( return -1 ) else ( return N + minimum - 1; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : in1=list(input()) if in1[0]=='-' : break in2=list(input()) out=list(input()) k=in2.pop(0) ans,f='',True while len(in1)or len(in2): if len(out)and out[0]==k : k=in1.pop(0) del out[0] else : ans+=k if len(in2): k=in2.pop(0) else : f=False break if f : ans+=k print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var in1 : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if in1->first() = '-' then ( break ) else skip ; var in2 : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var out : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var k : OclAny := in2->at(0`firstArg+1) ; in2 := in2->excludingAt(0+1) ; var ans : OclAny := null; var f : OclAny := null; Sequence{ans,f} := Sequence{'',true} ; while (in1)->size() or (in2)->size() do ( if (out)->size() & out->first() = k then ( k := in1->at(0`firstArg+1) ; in1 := in1->excludingAt(0+1) ; execute (out->first())->isDeleted() ) else ( ans := ans + k ; if (in2)->size() then ( k := in2->at(0`firstArg+1) ; in2 := in2->excludingAt(0+1) ) else ( var f : boolean := false ; break ) )) ; if f then ( ans := ans + k ) else skip ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : s1=list(input()) if s1==["-"]: break s2=list(input()) s1.reverse() s2.reverse() under=list(input()) under.reverse() right=[] center=s2.pop() while s1 or s2 : if under and center==under[-1]: center=s1.pop() under.pop() else : right.append(center) center=s2.pop() if not under : right.append(center) print("".join(right)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var s1 : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if s1 = Sequence{ "-" } then ( break ) else skip ; var s2 : Sequence := ((OclFile["System.in"]).readLine())->characters() ; s1 := s1->reverse() ; s2 := s2->reverse() ; var under : Sequence := ((OclFile["System.in"]).readLine())->characters() ; under := under->reverse() ; var right : Sequence := Sequence{} ; var center : OclAny := s2->last() ; s2 := s2->front() ; while s1 or s2 do ( if under & center = under->last() then ( center := s1->last() ; s1 := s1->front() ; under := under->front() ) else ( execute ((center) : right) ; center := s2->last() ; s2 := s2->front() )) ; if not(under) then ( execute ((center) : right) ) else skip ; execute (StringLib.sumStringsWithSeparator((right), ""))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMinimumOperation(n,d,arrays): cnt=0 first=-10**9 end=10**9 while(n): arr=[arrays[cnt][0],arrays[cnt][1]] arr=sorted(arr) first=max(first,arr[0]) end=min(end,arr[1]) cnt+=1 n-=1 if(first>end): print("-1",end="") else : if(d>=first and d<=end): print("0",end="") else : print(min(abs(first-d),abs(d-end)),end="") if __name__=='__main__' : n=3 d=3 arrays=[[0,7],[2,14],[4,6]] findMinimumOperation(n,d,arrays) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 3 ; d := 3 ; arrays := Sequence{Sequence{0}->union(Sequence{ 7 })}->union(Sequence{Sequence{2}->union(Sequence{ 14 })}->union(Sequence{ Sequence{4}->union(Sequence{ 6 }) })) ; findMinimumOperation(n, d, arrays) ) else skip; operation findMinimumOperation(n : OclAny, d : OclAny, arrays : OclAny) pre: true post: true activity: var cnt : int := 0 ; var first : double := (-10)->pow(9) ; var end : double := (10)->pow(9) ; while (n) do ( var arr : Sequence := Sequence{arrays[cnt+1]->first()}->union(Sequence{ arrays[cnt+1][1+1] }) ; arr := arr->sort() ; first := Set{first, arr->first()}->max() ; end := Set{end, arr[1+1]}->min() ; cnt := cnt + 1 ; n := n - 1) ; if ((first->compareTo(end)) > 0) then ( execute ("-1")->display() ) else ( if ((d->compareTo(first)) >= 0 & (d->compareTo(end)) <= 0) then ( execute ("0")->display() ) else ( execute (Set{(first - d)->abs(), (d - end)->abs()}->min())->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) for i in range(q): n=input() m=[int(x)for x in input().split()if int(x)<=2048] print('YES' if sum(m)>=2048 else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( var n : String := (OclFile["System.in"]).readLine() ; var m : Sequence := input().split()->select(x | ("" + ((x)))->toInteger() <= 2048)->collect(x | (("" + ((x)))->toInteger())) ; execute (if (m)->sum() >= 2048 then 'YES' else 'NO' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findTransitionPoint(arr,n): for i in range(n): if(arr[i]==1): return i return-1 arr=[0,0,0,0,1,1] n=len(arr) point=findTransitionPoint(arr,n) if point>=0 : print("Transition point is",point) else : print("There is no transition point") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 1 }))))) ; n := (arr)->size() ; var point : OclAny := findTransitionPoint(arr, n) ; if point >= 0 then ( execute ("Transition point is")->display() ) else ( execute ("There is no transition point")->display() ); operation findTransitionPoint(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if (arr[i+1] = 1) then ( return i ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) for _ in range(n): x=int(input()) l=list(map(int,input().split())) a=sum(l) a=a/x print(int(math.ceil(a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := (l)->sum() ; a := a / x ; execute (("" + (((a)->ceil())))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input for _ in[0]*int(I()): n=int(I()); print(0--sum(map(int,I().split()))//n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + ((I())))->toInteger()) do ( var n : int := ("" + ((I())))->toInteger(); execute (0 - -((I().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum() div n)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def hilberts_hotel(n,array): s=set() for k in range(n): new_room=(k+array[k])% n if new_room in s : return "NO" s.add(new_room) return "YES" data_size=int(input()) for _ in range(data_size): n=int(input()) a=list(map(int,input().split(' '))) print(hilberts_hotel(n,a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var data_size : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, data_size-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; execute (hilberts_hotel(n, a))->display()); operation hilberts_hotel(n : OclAny, array : OclAny) : OclAny pre: true post: true activity: var s : Set := Set{}->union(()) ; for k : Integer.subrange(0, n-1) do ( var new_room : int := (k + array[k+1]) mod n ; if (s)->includes(new_room) then ( return "NO" ) else skip ; execute ((new_room) : s)) ; return "YES"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math num=int(input()) for i in range(num): lenz=int(input()) arr=input() arr=arr.split(" ") arr=[int(x)for x in arr] summ=sum(arr) print(math.ceil(summ/lenz)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, num-1) do ( var lenz : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : String := (OclFile["System.in"]).readLine() ; arr := arr.split(" ") ; arr := arr->characters()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var summ : OclAny := (arr)->sum() ; execute ((summ / lenz)->ceil())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil for s in[*open(0)][2 : : 2]: s=list(map(int,s.split())); print(ceil(sum(s)/len(s))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var s : Sequence := ((s.split())->collect( _x | (OclType["int"])->apply(_x) )); execute (ceil((s)->sum() / (s)->size()))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* from collections import* from itertools import* for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) print(ceil(sum(l)/n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (ceil((l)->sum() / n))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) def solve(x): x.sort() return x[len(x)//2]-x[(len(x)-1)//2]+1 for i in range(t): n=int(input()) x,y=[],[] for j in range(n): px,py=map(int,input().split()) x.append(px) y.append(py) print(solve(x)*solve(y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var y : OclAny := null; Sequence{x,y} := Sequence{Sequence{},Sequence{}} ; for j : Integer.subrange(0, n-1) do ( var px : OclAny := null; var py : OclAny := null; Sequence{px,py} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((px) : x) ; execute ((py) : y)) ; execute (solve(x) * solve(y))->display()); operation solve(x : OclAny) : OclAny pre: true post: true activity: x := x->sort() ; return x[(x)->size() div 2+1] - x[((x)->size() - 1) div 2+1] + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) xaxis=[] yaxis=[] for x in range(n): a,b=map(int,input().split()) xaxis.append(a) yaxis.append(b) xaxis.sort() yaxis.sort() if n % 2==0 : i=abs(xaxis[(n//2)-1]-xaxis[n//2]) j=abs(yaxis[(n//2)-1]-yaxis[n//2]) else : i=0 j=0 print((i+1)*(j+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var xaxis : Sequence := Sequence{} ; var yaxis : Sequence := Sequence{} ; for x : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a) : xaxis) ; execute ((b) : yaxis)) ; xaxis := xaxis->sort() ; yaxis := yaxis->sort() ; if n mod 2 = 0 then ( var i : double := (xaxis[(n div 2) - 1+1] - xaxis[n div 2+1])->abs() ; var j : double := (yaxis[(n div 2) - 1+1] - yaxis[n div 2+1])->abs() ) else ( i := 0 ; j := 0 ) ; execute ((i + 1) * (j + 1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) def solve(x): x.sort() return x[len(x)//2]-x[(len(x)-1)//2]+1 for i in range(t): n=int(input()) x,y=[],[] for j in range(n): px,py=map(int,input().split()) x.append(px) y.append(py) print(solve(x)*solve(y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var y : OclAny := null; Sequence{x,y} := Sequence{Sequence{},Sequence{}} ; for j : Integer.subrange(0, n-1) do ( var px : OclAny := null; var py : OclAny := null; Sequence{px,py} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((px) : x) ; execute ((py) : y)) ; execute (solve(x) * solve(y))->display()); operation solve(x : OclAny) : OclAny pre: true post: true activity: x := x->sort() ; return x[(x)->size() div 2+1] - x[((x)->size() - 1) div 2+1] + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) x=[] y=[] for j in range(n): b=list(map(int,input().split())) x.append(b[0]) y.append(b[1]) if n % 2!=0 : print(1) else : x.sort() y.sort() print((x[n//2]-x[n//2-1]+1)*(y[n//2]-y[n//2-1]+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := Sequence{} ; var y : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((b->first()) : x) ; execute ((b[1+1]) : y)) ; if n mod 2 /= 0 then ( execute (1)->display() ) else ( x := x->sort() ; y := y->sort() ; execute ((x[n div 2+1] - x[n div 2 - 1+1] + 1) * (y[n div 2+1] - y[n div 2 - 1+1] + 1))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def highest_score(): s1=input().split(' ') n=int(s1[0]) m=int(s1[1]) s2=input().split(' ') score=0 for i in s2 : score+=int(i) if score>m : print(m) else : print(score) row=int(input()) for r in range(row): highest_score() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var row : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for r : Integer.subrange(0, row-1) do ( highest_score()); operation highest_score() pre: true post: true activity: var s1 : OclAny := input().split(' ') ; var n : int := ("" + ((s1->first())))->toInteger() ; var m : int := ("" + ((s1[1+1])))->toInteger() ; var s2 : OclAny := input().split(' ') ; var score : int := 0 ; for i : s2 do ( score := score + ("" + ((i)))->toInteger()) ; if (score->compareTo(m)) > 0 then ( execute (m)->display() ) else ( execute (score)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().rstrip() from collections import defaultdict import math for _ in range(int(input())): N=int(input()) X,Y=[],[] for _ in range(N): x,y=map(int,input().split()) X.append(x) Y.append(y) if N % 2 : print(1) else : X.sort() Y.sort() ans=(X[N//2]-X[N//2-1]+1)*(Y[N//2]-Y[N//2-1]+1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var X : OclAny := null; var Y : OclAny := null; Sequence{X,Y} := Sequence{Sequence{},Sequence{}} ; for _anon : Integer.subrange(0, N-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((x) : X) ; execute ((y) : Y)) ; if N mod 2 then ( execute (1)->display() ) else ( X := X->sort() ; Y := Y->sort() ; var ans : double := (X[N div 2+1] - X[N div 2 - 1+1] + 1) * (Y[N div 2+1] - Y[N div 2 - 1+1] + 1) ; execute (ans)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- hight,width=map(int,input().split()) ans=10**18 def F(H,W): global ans for h in range(1,H): sa=h*W h2=(H-h)//2 sb=h2*W sc=(H-h-h2)*W ans=min(ans,max(sa,sb,sc)-min(sa,sb,sc)) w=W//2 sb=(H-h)*w sc=(H-h)*(W-w) ans=min(ans,max(sa,sb,sc)-min(sa,sb,sc)) F(hight,width) F(width,hight) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute ans : OclAny; operation initialise() pre: true post: true activity: var hight : OclAny := null; var width : OclAny := null; Sequence{hight,width} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : double := (10)->pow(18) ; skip ; F(hight, width) ; F(width, hight) ; execute (ans)->display(); operation F(H : OclAny, W : OclAny) pre: true post: true activity: skip ; for h : Integer.subrange(1, H-1) do ( var sa : double := h * W ; var h2 : int := (H - h) div 2 ; var sb : double := h2 * W ; var sc : double := (H - h - h2) * W ; ans := Set{ans, Set{sa, sb, sc}->max() - Set{sa, sb, sc}->min()}->min() ; var w : int := W div 2 ; sb := (H - h) * w ; sc := (H - h) * (W - w) ; ans := Set{ans, Set{sa, sb, sc}->max() - Set{sa, sb, sc}->min()}->min()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) v=[0]*n for i,k in enumerate(a): v[(i+k)% n]+=1 print("NO" if max(v)>1 else "YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var v : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var k : OclAny := _tuple->at(_indx); v[(i + k) mod n+1] := v[(i + k) mod n+1] + 1) ; execute (if (v)->max() > 1 then "NO" else "YES" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def è§£(): iH,iW=[int(_)for _ in input().split()] if iH % 3==0 or iW % 3==0 : print(0) else : w3=iW//3 w2=iW//2 h3=iH//3 h2=iH//2 aY1=[iH*w3,(iH-h2)*(iW-w3),h2*(iW-w3)] aY2=[iH*(w3+1),(iH-h2)*(iW-w3-1),h2*(iW-w3-1)] aT1=[iW*h3,(iW-w2)*(iH-h3),w2*(iH-h3)] aT2=[iW*(h3+1),(iW-w2)*(iH-h3-1),w2*(iH-h3-1)] aH31=[iW*h3,iW*(iH-2*h3)] aH32=[iW*(h3+1),iW*(iH-2*(h3+1))] aW31=[iH*w3,iH*(iW-2*w3)] aW32=[iH*(w3+1),iH*(iW-2*(w3+1))] iMin=iH*iW for ea in[aY1,aY2,aT1,aT2,aH31,aH32,aW31,aW32]: iMin=min(iMin,max(ea)-min(ea)) print(iMin) è§£() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; ?(); operation ?() pre: true post: true activity: var iH : OclAny := null; var iW : OclAny := null; Sequence{iH,iW} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; if iH mod 3 = 0 or iW mod 3 = 0 then ( execute (0)->display() ) else ( var w3 : int := iW div 3 ; var w2 : int := iW div 2 ; var h3 : int := iH div 3 ; var h2 : int := iH div 2 ; var aY1 : Sequence := Sequence{iH * w3}->union(Sequence{(iH - h2) * (iW - w3)}->union(Sequence{ h2 * (iW - w3) })) ; var aY2 : Sequence := Sequence{iH * (w3 + 1)}->union(Sequence{(iH - h2) * (iW - w3 - 1)}->union(Sequence{ h2 * (iW - w3 - 1) })) ; var aT1 : Sequence := Sequence{iW * h3}->union(Sequence{(iW - w2) * (iH - h3)}->union(Sequence{ w2 * (iH - h3) })) ; var aT2 : Sequence := Sequence{iW * (h3 + 1)}->union(Sequence{(iW - w2) * (iH - h3 - 1)}->union(Sequence{ w2 * (iH - h3 - 1) })) ; var aH31 : Sequence := Sequence{iW * h3}->union(Sequence{ iW * (iH - 2 * h3) }) ; var aH32 : Sequence := Sequence{iW * (h3 + 1)}->union(Sequence{ iW * (iH - 2 * (h3 + 1)) }) ; var aW31 : Sequence := Sequence{iH * w3}->union(Sequence{ iH * (iW - 2 * w3) }) ; var aW32 : Sequence := Sequence{iH * (w3 + 1)}->union(Sequence{ iH * (iW - 2 * (w3 + 1)) }) ; var iMin : double := iH * iW ; for ea : Sequence{aY1}->union(Sequence{aY2}->union(Sequence{aT1}->union(Sequence{aT2}->union(Sequence{aH31}->union(Sequence{aH32}->union(Sequence{aW31}->union(Sequence{ aW32 }))))))) do ( iMin := Set{iMin, (ea)->max() - (ea)->min()}->min()) ; execute (iMin)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin from math import ceil input=stdin.readline def main(args): H,W=map(int,input().split()) p1=-1 p2=-1 p3=-1 min_diff=H*W for i in range(1,(H//2)+1): p1=i*W reH=H-i p2=ceil(reH/2)*W p3=(H*W)-p1-p2 diff=max(p1,p2,p3)-min(p1,p2,p3) if diffcollect( _x | (OclType["int"])->apply(_x) ) ; var p1 : int := -1 ; var p2 : int := -1 ; var p3 : int := -1 ; var min_diff : double := H * W ; for i : Integer.subrange(1, (H div 2) + 1-1) do ( p1 := i * W ; var reH : double := H - i ; p2 := ceil(reH / 2) * W ; p3 := (H * W) - p1 - p2 ; var diff : double := Set{p1, p2, p3}->max() - Set{p1, p2, p3}->min() ; if (diff->compareTo(min_diff)) < 0 then ( min_diff := diff ) else skip ; p2 := ceil(W / 2) * reH ; p3 := (H * W) - p1 - p2 ; diff := Set{p1, p2, p3}->max() - Set{p1, p2, p3}->min() ; if (diff->compareTo(min_diff)) < 0 then ( min_diff := diff ) else skip) ; var temp : OclAny := H ; var H : OclAny := W ; var W : OclAny := temp ; for i : Integer.subrange(1, (H div 2) + 1-1) do ( p1 := i * W ; reH := H - i ; p2 := ceil(reH / 2) * W ; p3 := (H * W) - p1 - p2 ; diff := Set{p1, p2, p3}->max() - Set{p1, p2, p3}->min() ; if (diff->compareTo(min_diff)) < 0 then ( min_diff := diff ) else skip ; p2 := ceil(W / 2) * reH ; p3 := (H * W) - p1 - p2 ; diff := Set{p1, p2, p3}->max() - Set{p1, p2, p3}->min() ; if (diff->compareTo(min_diff)) < 0 then ( min_diff := diff ) else skip) ; execute (min_diff)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys H,W=list(map(int,input().rstrip().split())) def check(h,w): area_diff=h*w for i in range(1,h//2+1): area=[i*w,((h-i)//2)*w,((h-i)//2+(h-i)% 2)*w] area.sort() diff=area[2]-area[0] area_diff=min(area_diff,diff) area=[i*w,(h-i)*(w//2),(h-i)*(w//2+w % 2)] area.sort() diff=area[2]-area[0] area_diff=min(area_diff,diff) return area_diff if(H % 3)==0 or(W % 3)==0 : print(0) sys.exit() res1=check(H,W) res2=check(W,H) print(min(res1,res2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := ((input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; if (H mod 3) = 0 or (W mod 3) = 0 then ( execute (0)->display() ; sys.exit() ) else skip ; var res1 : OclAny := check(H, W) ; var res2 : OclAny := check(W, H) ; execute (Set{res1, res2}->min())->display(); operation check(h : OclAny, w : OclAny) : OclAny pre: true post: true activity: var area_diff : double := h * w ; for i : Integer.subrange(1, h div 2 + 1-1) do ( var area : Sequence := Sequence{i * w}->union(Sequence{((h - i) div 2) * w}->union(Sequence{ ((h - i) div 2 + (h - i) mod 2) * w })) ; area := area->sort() ; var diff : double := area[2+1] - area->first() ; area_diff := Set{area_diff, diff}->min() ; area := Sequence{i * w}->union(Sequence{(h - i) * (w div 2)}->union(Sequence{ (h - i) * (w div 2 + w mod 2) })) ; area := area->sort() ; diff := area[2+1] - area->first() ; area_diff := Set{area_diff, diff}->min()) ; return area_diff; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=map(int,input().split()) h,w=min(x,y),max(x,y) if h % 3==0 or w % 3==0 : print(0) exit() ans1=h k=h//2 if h % 2 : for i in range(1,w): l=w-i s1=h*i s2=k*l s3=(k+1)*l mn=min(s1,s2) mx=max(s1,s3) ans1=min(ans1,mx-mn) else : for i in range(1,w): l=w-i s1=h*i s2=k*l mn=min(s1,s2) mx=max(s1,s2) ans1=min(ans1,mx-mn) w,h=min(x,y),max(x,y) ans2=h k=h//2 if h % 2 : for i in range(1,w): l=w-i s1=h*i s2=k*l s3=(k+1)*l mn=min(s1,s2) mx=max(s1,s3) ans2=min(ans2,mx-mn) else : for i in range(1,w): l=w-i s1=h*i s2=k*l mn=min(s1,s2) mx=max(s1,s2) ans2=min(ans2,mx-mn) print(min(ans1,ans2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := Sequence{Set{x, y}->min(),Set{x, y}->max()} ; if h mod 3 = 0 or w mod 3 = 0 then ( execute (0)->display() ; exit() ) else skip ; var ans1 : OclAny := h ; var k : int := h div 2 ; if h mod 2 then ( for i : Integer.subrange(1, w-1) do ( var l : double := w - i ; var s1 : double := h * i ; var s2 : double := k * l ; var s3 : double := (k + 1) * l ; var mn : OclAny := Set{s1, s2}->min() ; var mx : OclAny := Set{s1, s3}->max() ; ans1 := Set{ans1, mx - mn}->min()) ) else ( for i : Integer.subrange(1, w-1) do ( l := w - i ; s1 := h * i ; s2 := k * l ; mn := Set{s1, s2}->min() ; mx := Set{s1, s2}->max() ; ans1 := Set{ans1, mx - mn}->min()) ) ; var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := Sequence{Set{x, y}->min(),Set{x, y}->max()} ; var ans2 : OclAny := h ; k := h div 2 ; if h mod 2 then ( for i : Integer.subrange(1, w-1) do ( l := w - i ; s1 := h * i ; s2 := k * l ; s3 := (k + 1) * l ; mn := Set{s1, s2}->min() ; mx := Set{s1, s3}->max() ; ans2 := Set{ans2, mx - mn}->min()) ) else ( for i : Integer.subrange(1, w-1) do ( l := w - i ; s1 := h * i ; s2 := k * l ; mn := Set{s1, s2}->min() ; mx := Set{s1, s2}->max() ; ans2 := Set{ans2, mx - mn}->min()) ) ; execute (Set{ans1, ans2}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def term(n): x=(((1)+math.sqrt(1+(8*n)))/2) return x n=5 print(int(term(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 5 ; execute (("" + ((term(n))))->toInteger())->display(); operation term(n : OclAny) : OclAny pre: true post: true activity: var x : double := (((1) + (1 + (8 * n))->sqrt()) / 2) ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxDistance(array): max1=-2147483648 min1=+2147483647 max2=-2147483648 min2=+2147483647 for i in range(len(array)): max1=max(max1,array[i]+i) min1=min(min1,array[i]+i) max2=max(max2,array[i]-i) min2=min(min2,array[i]-i) return max(max1-min1,max2-min2) array=[-70,-64,-6,-56,64,61,-57,16,48,-98] print(maxDistance(array)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; array := Sequence{-70}->union(Sequence{-64}->union(Sequence{-6}->union(Sequence{-56}->union(Sequence{64}->union(Sequence{61}->union(Sequence{-57}->union(Sequence{16}->union(Sequence{48}->union(Sequence{ -98 }))))))))) ; execute (maxDistance(array))->display(); operation maxDistance(array : OclAny) : OclAny pre: true post: true activity: var max1 : int := -2147483648 ; var min1 : int := 2147483647 ; var max2 : int := -2147483648 ; var min2 : int := 2147483647 ; for i : Integer.subrange(0, (array)->size()-1) do ( max1 := Set{max1, array[i+1] + i}->max() ; min1 := Set{min1, array[i+1] + i}->min() ; max2 := Set{max2, array[i+1] - i}->max() ; min2 := Set{min2, array[i+1] - i}->min()) ; return Set{max1 - min1, max2 - min2}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class AdjNode : def __init__(self,data): self.vertex=data self.next=None class Graph : def __init__(self,vertices): self.V=vertices self.graph=[None]*self.V def add_edge(self,src,dest): node=AdjNode(dest) node.next=self.graph[src] self.graph[src]=node node=AdjNode(src) node.next=self.graph[dest] self.graph[dest]=node def print_graph(self): for i in range(self.V): print("Adjacency list of vertex{}\n head".format(i),end="") temp=self.graph[i] while temp : print("->{}".format(temp.vertex),end="") temp=temp.next print(" \n") if __name__=="__main__" : V=5 graph=Graph(V) graph.add_edge(0,1) graph.add_edge(0,4) graph.add_edge(1,2) graph.add_edge(1,3) graph.add_edge(1,4) graph.add_edge(2,3) graph.add_edge(3,4) graph.print_graph() ------------------------------------------------------------ OCL File: --------- class AdjNode { static operation newAdjNode() : AdjNode pre: true post: AdjNode->exists( _x | result = _x ); attribute vertex : OclAny := data; attribute next : OclAny := null; operation initialise(data : OclAny) : AdjNode pre: true post: true activity: self.vertex := data ; self.next := null; return self; } class Graph { static operation newGraph() : Graph pre: true post: Graph->exists( _x | result = _x ); attribute V : OclAny := vertices; attribute graph : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, self.V); operation initialise(vertices : OclAny) : Graph pre: true post: true activity: self.V := vertices ; self.graph := MatrixLib.elementwiseMult(Sequence{ null }, self.V); return self; operation add_edge(src : OclAny,dest : OclAny) pre: true post: true activity: var node : AdjNode := (AdjNode.newAdjNode()).initialise(dest) ; node.next := self.graph[src+1] ; self.graph[src+1] := node ; node := (AdjNode.newAdjNode()).initialise(src) ; node.next := self.graph[dest+1] ; self.graph[dest+1] := node; operation print_graph() pre: true post: true activity: for i : Integer.subrange(0, self.V-1) do ( execute (StringLib.interpolateStrings("Adjacency list of vertex{}\n head", Sequence{i}))->display() ; var temp : OclAny := self.graph[i+1] ; while temp do ( execute (StringLib.interpolateStrings("->{}", Sequence{temp.vertex}))->display() ; temp := temp.next) ; execute (" \n")->display()); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var V : int := 5 ; var graph : Graph := (Graph.newGraph()).initialise(V) ; graph.add_edge(0, 1) ; graph.add_edge(0, 4) ; graph.add_edge(1, 2) ; graph.add_edge(1, 3) ; graph.add_edge(1, 4) ; graph.add_edge(2, 3) ; graph.add_edge(3, 4) ; graph.print_graph() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def twoWaySort(arr,n): for i in range(0,n): if(arr[i]& 1): arr[i]*=-1 arr.sort() for i in range(0,n): if(arr[i]& 1): arr[i]*=-1 arr=[1,3,2,7,5,4] n=len(arr) twoWaySort(arr,n); for i in range(0,n): print(arr[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{3}->union(Sequence{2}->union(Sequence{7}->union(Sequence{5}->union(Sequence{ 4 }))))) ; n := (arr)->size() ; twoWaySort(arr, n); ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); operation twoWaySort(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if (MathLib.bitwiseAnd(arr[i+1], 1)) then ( arr[i+1] := arr[i+1] * -1 ) else skip) ; arr := arr->sort() ; for i : Integer.subrange(0, n-1) do ( if (MathLib.bitwiseAnd(arr[i+1], 1)) then ( arr[i+1] := arr[i+1] * -1 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque,defaultdict,Counter from heapq import heappush,heappop,heapify from math import inf,sqrt,ceil,log2 from functools import lru_cache from itertools import accumulate,combinations,permutations,product from typing import List from bisect import bisect_left,bisect_right import sys import string input=lambda : sys.stdin.readline().strip('\n') mis=lambda : map(int,input().split()) ii=lambda : int(input()) T=ii() for _ in range(T): N,M=mis() A=list(mis()) print(min(sum(A),M)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine()->trim()) ; var mis : Function := lambda $$ : OclAny in ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ii : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var T : OclAny := ii->apply() ; for _anon : Integer.subrange(0, T-1) do ( var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := mis->apply() ; var A : Sequence := (mis->apply()) ; execute (Set{(A)->sum(), M}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left as bl from bisect import bisect_right as br n=int(input()) alst=[float(input())for _ in range(n)] sorted_alst=sorted(alst) for a in alst : li=bl(sorted_alst,a) ri=br(sorted_alst,a) print(li*3+(ri-li-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var alst : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toReal())) ; var sorted_alst : Sequence := alst->sort() ; for a : alst do ( var li : OclAny := bl(sorted_alst, a) ; var ri : OclAny := br(sorted_alst, a) ; execute (li * 3 + (ri - li - 1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def minMoves(self,nums): if nums is None or len(nums)==0 : return 0 min_num=min(nums) return sum([i-min_num for i in nums]) ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation minMoves(nums : OclAny) : OclAny pre: true post: true activity: if nums <>= null or (nums)->size() = 0 then ( return 0 ) else skip ; var min_num : OclAny := (nums)->min() ; return (nums->select(i | true)->collect(i | (i - min_num)))->sum(); } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 def LI(): return list(map(int,input().split())) def LF(): return list(map(float,input().split())) def LS(): return input().split() def I(): return int(input()) def F(): return float(input()) def S(): return input() def main(): n=I() a=sorted([[F(),_]for _ in range(n)]) r=[0]*n ct=collections.defaultdict(int) for f,i in a : ct[f]+=1 m=-1 mi=0 for ai in range(n): c,i=a[ai] if mpow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LF() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["double"])->apply(_x) )); operation LS() : OclAny pre: true post: true activity: return input().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation main() : OclAny pre: true post: true activity: var n : OclAny := I() ; var a : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{F()}->union(Sequence{ _anon })))->sort() ; var r : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var ct : OclAny := .defaultdict(OclType["int"]) ; for _tuple : a do (var _indx : int := 1; var f : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); ct[f+1] := ct[f+1] + 1) ; var m : int := -1 ; var mi : int := 0 ; for ai : Integer.subrange(0, n-1) do ( var c : OclAny := null; var i : OclAny := null; Sequence{c,i} := a[ai+1] ; if (m->compareTo(c)) < 0 then ( m := c ; mi := ai ) else skip ; r[i+1] := mi * 3 + ct[c+1] - 1) ; return StringLib.sumStringsWithSeparator(((r)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : n=input() a=[0.0]*int(n) b=[0.0]*int(n) count={"6.909" : 0} for i in range(int(n)): a[i]=input() b[i]=a[i] b.sort() for i in range(int(n)-1): if float(b[i])==float(b[i+1]): if b[i]in count : x=count[b[i]] count[b[i]]=(x+1) else : count[b[i]]=2 i=0 while itoInteger()) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0.0 }, ("" + ((n)))->toInteger()) ; var count : Map := Map{ "6.909" |-> 0 } ; for i : Integer.subrange(0, ("" + ((n)))->toInteger()-1) do ( a[i+1] := (OclFile["System.in"]).readLine() ; b[i+1] := a[i+1]) ; b := b->sort() ; for i : Integer.subrange(0, ("" + ((n)))->toInteger() - 1-1) do ( if ("" + ((b[i+1])))->toReal() = ("" + ((b[i + 1+1])))->toReal() then ( if (count)->includes(b[i+1]) then ( var x : OclAny := count[b[i+1]+1] ; count[b[i+1]+1] := (x + 1) ) else ( count[b[i+1]+1] := 2 ) ) else skip) ; var i : int := 0 ; while (i->compareTo(("" + ((n)))->toInteger())) < 0 do ( if (count)->includes(b[i+1]) then ( x := count[b[i+1]+1] ; count[b[i+1]+1] := (3 * i + x - 1) ; i := i + x - 1 ) else ( count[b[i+1]+1] := (3 * i) ) ; i := i + 1) ; for i : Integer.subrange(0, ("" + ((n)))->toInteger()-1) do ( execute (count[a[i+1]+1])->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect n=int(input()) a=[] for i in range(n): a.append(float(input())) a2=sorted(a) for i in a : kati=bisect.bisect_left(a2,i) hiki=bisect.bisect_right(a2,i)-kati-1 print(kati*3+hiki) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toReal()) : a)) ; var a2 : Sequence := a->sort() ; for i : a do ( var kati : OclAny := bisect.bisect_left(a2, i) ; var hiki : double := bisect.bisect_right(a2, i) - kati - 1 ; execute (kati * 3 + hiki)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left as bl from bisect import bisect_right as br n=int(input()) gpa=[] for _ in range(n): gpa.append(float(input())) gpa_s=sorted(gpa) for g in gpa : less=bl(gpa_s,g) more=br(gpa_s,g) print(less*3+(more-less-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var gpa : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toReal()) : gpa)) ; var gpa_s : Sequence := gpa->sort() ; for g : gpa do ( var less : OclAny := bl(gpa_s, g) ; var more : OclAny := br(gpa_s, g) ; execute (less * 3 + (more - less - 1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPalindrome(s): i=0 ; j=len(s)-1 ; while(isize(); ; execute (getIndex(S1, S2, n))->display();; operation isPalindrome(s : OclAny) pre: true post: true activity: var i : int := 0; ; var j : double := (s)->size() - 1; ; while ((i->compareTo(j)) < 0) do ( if (not(s[i+1] <>= s[j+1])) then ( return false; ) else skip ; i := i + 1; ; j := j - 1;) ; return true;; operation getIndex(S1 : OclAny, S2 : OclAny, n : OclAny) pre: true post: true activity: var S : String := ""; ; for i : Integer.subrange(0, n-1) do ( S := S + S1[i+1]; ; var Temp : String := ""; ; for j : Integer.subrange(i + 1, n-1) do ( Temp := Temp + S2[j+1];) ; if (isPalindrome(S + Temp)) then ( return i; ) else skip) ; return -1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- name=input().split() b=list(name[1]) print("A"+b[0]+"C") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var name : OclAny := input().split() ; var b : Sequence := (name[1+1]) ; execute ("A" + b->first() + "C")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline sys.setrecursionlimit(10**7) from collections import Counter,deque from collections import defaultdict from itertools import combinations,permutations,accumulate,groupby,product from bisect import bisect_left,bisect_right from heapq import heapify,heappop,heappush from math import floor,ceil,pi,factorial from operator import itemgetter def I(): return int(input()) def MI(): return map(int,input().split()) def LI(): return list(map(int,input().split())) def LI2(): return[int(input())for i in range(n)] def MXI(): return[[LI()]for i in range(n)] def SI(): return input().rstrip() def printns(x): print('\n'.join(x)) def printni(x): print('\n'.join(list(map(str,x)))) inf=10**17 mod=10**9+7 lis=input().rstrip().split(" ") print("A"+lis[1][0]+"C") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; sys.setrecursionlimit((10)->pow(7)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var Math_PINFINITY : double := (10)->pow(17) ; var mod : double := (10)->pow(9) + 7 ; var lis : OclAny := input().rstrip().split(" ") ; execute ("A" + lis[1+1]->first() + "C")->display(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LI2() : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())); operation MXI() : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{ LI() })); operation SI() : OclAny pre: true post: true activity: return input().rstrip(); operation printns(x : OclAny) pre: true post: true activity: execute (StringLib.sumStringsWithSeparator((x), ' '))->display(); operation printni(x : OclAny) pre: true post: true activity: execute (StringLib.sumStringsWithSeparator((((x)->collect( _x | (OclType["String"])->apply(_x) ))), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin inf=1<<60 mod=1000000007 ni=lambda : int(ns()) nin=lambda y :[ni()for _ in range(y)] na=lambda : list(map(int,stdin.readline().split())) nan=lambda y :[na()for _ in range(y)] nf=lambda : float(ns()) nfn=lambda y :[nf()for _ in range(y)] nfa=lambda : list(map(float,stdin.readline().split())) nfan=lambda y :[nfa()for _ in range(y)] ns=lambda : stdin.readline().rstrip() nsn=lambda y :[ns()for _ in range(y)] ncl=lambda y :[list(ns())for _ in range(y)] nas=lambda : stdin.readline().split() a,s,c=nas() print(''.join(["A",s[0],"C"])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stdin : OclFile := OclFile["System.in"] ; var Math_PINFINITY : int := 1 * (2->pow(60)) ; var mod : int := 1000000007 ; var ni : Function := lambda $$ : OclAny in (("" + ((ns())))->toInteger()) ; var nin : Function := lambda y : OclAny in (Integer.subrange(0, y-1)->select(_anon | true)->collect(_anon | (ni->apply()))) ; var na : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var Math_NaN : Function := lambda y : OclAny in (Integer.subrange(0, y-1)->select(_anon | true)->collect(_anon | (na->apply()))) ; var nf : Function := lambda $$ : OclAny in (("" + ((ns())))->toReal()) ; var nfn : Function := lambda y : OclAny in (Integer.subrange(0, y-1)->select(_anon | true)->collect(_anon | (nf->apply()))) ; var nfa : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ))) ; var nfan : Function := lambda y : OclAny in (Integer.subrange(0, y-1)->select(_anon | true)->collect(_anon | (nfa->apply()))) ; var ns : Function := lambda $$ : OclAny in (stdin.readLine().rstrip()) ; var nsn : Function := lambda y : OclAny in (Integer.subrange(0, y-1)->select(_anon | true)->collect(_anon | (ns->apply()))) ; var ncl : Function := lambda y : OclAny in (Integer.subrange(0, y-1)->select(_anon | true)->collect(_anon | ((ns->apply())))) ; var nas : Function := lambda $$ : OclAny in (stdin.readLine().split()) ; var a : OclAny := null; var s : OclAny := null; var c : OclAny := null; Sequence{a,s,c} := nas->apply() ; execute (StringLib.sumStringsWithSeparator((Sequence{"A"}->union(Sequence{s->first()}->union(Sequence{ "C" }))), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import gcd from collections import Counter,deque,defaultdict from heapq import heappush,heappop,heappushpop,heapify,heapreplace,merge from bisect import bisect_left,bisect_right,bisect,insort_left,insort_right,insort from itertools import product,combinations,permutations from copy import deepcopy,copy from math import sqrt,log10 import sys sys.setrecursionlimit(4100000) if __name__=='__main__' : A,X,C=list(input().split()) print('A'+X[0]+'C') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(4100000) ; if __name__ = '__main__' then ( var A : OclAny := null; var X : OclAny := null; var C : OclAny := null; Sequence{A,X,C} := (input().split()) ; execute ('A' + X->first() + 'C')->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=[int(u)for u in input().split()] li=[int(i)for i in input().split()] print(m if sum(li)>=m else sum(li)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(u | true)->collect(u | (("" + ((u)))->toInteger())) ; var li : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute (if ((li)->sum()->compareTo(m)) >= 0 then m else (li)->sum() endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) if a<=0 and 0<=b : print("Zero") elif a<0 and min(b-a,-a)% 2==0 : print("Negative") else : print("Positive") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a <= 0 & 0 <= b then ( execute ("Zero")->display() ) else (if a < 0 & Set{b - a, -a}->min() mod 2 = 0 then ( execute ("Negative")->display() ) else ( execute ("Positive")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy import random import bisect import fractions import math import sys mod=10**9+7 sys.setrecursionlimit(mod) S=[str(i)for i in input().split()] ans="" for i in range(3): ans+=S[i][0] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; sys.setrecursionlimit(mod) ; var S : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i))))) ; var ans : String := "" ; for i : Integer.subrange(0, 3-1) do ( ans := ans + S[i+1]->first()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumArr(arr,n): sum=0 ; for i in range(n): sum+=arr[i]; return sum ; def sumModArr(arr,n): subSum=arr[n-1]; for i in range(n-2,-1,-1): curr=arr[i]; arr[i]-=subSum ; subSum+=curr ; return sumArr(arr,n); arr=[40,25,12,10]; n=len(arr); print(sumModArr(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{40}->union(Sequence{25}->union(Sequence{12}->union(Sequence{ 10 }))); ; n := (arr)->size(); ; execute (sumModArr(arr, n))->display();; operation sumArr(arr : OclAny, n : OclAny) pre: true post: true activity: var sum : int := 0; ; for i : Integer.subrange(0, n-1) do ( sum := sum + arr[i+1];) ; return sum;; operation sumModArr(arr : OclAny, n : OclAny) pre: true post: true activity: var subSum : OclAny := arr[n - 1+1]; ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( var curr : OclAny := arr[i+1]; ; arr[i+1] := arr[i+1] - subSum; ; subSum := subSum + curr;) ; return sumArr(arr, n);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMax(arr,low,high): if(highlow and arr[mid]arr[mid]): return findMax(arr,low,mid-1) else : return findMax(arr,mid+1,high) arr=[5,6,1,2,3,4] n=len(arr) print(findMax(arr,0,n-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{5}->union(Sequence{6}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))))) ; var n : int := (arr)->size() ; execute (findMax(arr, 0, n - 1))->display(); operation findMax(arr : OclAny, low : OclAny, high : OclAny) : OclAny pre: true post: true activity: if ((high->compareTo(low)) < 0) then ( return arr->first() ) else skip ; if (high = low) then ( return arr[low+1] ) else skip ; var mid : OclAny := low + (high - low) div 2 ; if ((mid->compareTo(high)) < 0 & (arr[mid + 1+1]->compareTo(arr[mid+1])) < 0) then ( return arr[mid+1] ) else skip ; if ((mid->compareTo(low)) > 0 & (arr[mid+1]->compareTo(arr[mid - 1+1])) < 0) then ( return arr[mid - 1+1] ) else skip ; if ((arr[low+1]->compareTo(arr[mid+1])) > 0) then ( return findMax(arr, low, mid - 1) ) else ( return findMax(arr, mid + 1, high) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findCount(m,n): num1=0 for i in range(0,m): num1=(num1*10)+9 num2=0 for i in range(0,(m-1)): num2=(num2*10)+9 return int((num1/n)-(num2/n)) m=2 ; n=6 print(findCount(m,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; m := 2; n := 6 ; execute (findCount(m, n))->display(); operation findCount(m : OclAny, n : OclAny) : OclAny pre: true post: true activity: var num1 : int := 0 ; for i : Integer.subrange(0, m-1) do ( num1 := (num1 * 10) + 9) ; var num2 : int := 0 ; for i : Integer.subrange(0, (m - 1)-1) do ( num2 := (num2 * 10) + 9) ; return ("" + (((num1 / n) - (num2 / n))))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,data,next): self.data=data self.next=next class LinkedList : def __init__(self): self.head=None def push(self,new_data): new_node=Node(new_data,self.head) self.head=new_node def reverseList(self): stk=[] ptr=self.head while ptr.next!=None : stk.append(ptr) ptr=ptr.next self.head=ptr while len(stk)!=0 : ptr.next=stk.pop() ptr=ptr.next ptr.next=None def printList(self): curr=self.head while curr : print(curr.data,end=" ") curr=curr.next if __name__=="__main__" : linkedList=LinkedList() linkedList.push(5) linkedList.push(4) linkedList.push(3) linkedList.push(2) linkedList.push(1) linkedList.reverseList() linkedList.printList() ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := next; operation initialise(data : OclAny,next : OclAny) : Node pre: true post: true activity: self.data := data ; self.next := next; return self; } class LinkedList { static operation newLinkedList() : LinkedList pre: true post: LinkedList->exists( _x | result = _x ); attribute head : OclAny := null; operation initialise() : LinkedList pre: true post: true activity: self.head := null; return self; operation push(new_data : OclAny) pre: true post: true activity: var new_node : Node := (Node.newNode()).initialise(new_data, self.head) ; self.head := new_node; operation reverseList() pre: true post: true activity: var stk : Sequence := Sequence{} ; var ptr : OclAny := self.head ; while ptr.next /= null do ( execute ((ptr) : stk) ; ptr := ptr.next) ; self.head := ptr ; while (stk)->size() /= 0 do ( ptr.next := stk->last() ; stk := stk->front() ; ptr := ptr.next) ; ptr.next := null; operation printList() pre: true post: true activity: var curr : OclAny := self.head ; while curr do ( execute (curr.data)->display() ; curr := curr.next); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var linkedList : LinkedList := (LinkedList.newLinkedList()).initialise() ; linkedList.push(5) ; linkedList.push(4) ; linkedList.push(3) ; linkedList.push(2) ; linkedList.push(1) ; linkedList.reverseList() ; linkedList.printList() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W,D=map(int,input().split()) A=[list(map(int,input().split()))for _ in range(H)] x=[0]*(H*W+D+1) y=[0]*(H*W+D+1) for k in range(W): for l in range(H): x[A[l][k]]=k+1 y[A[l][k]]=l+1 d=[0]*(H*W+D+1) for k in range(H*W,0,-1): d[k]=d[k+D]+abs(x[k]-x[k+D])+abs(y[k]-y[k+D]) for _ in range(int(input())): L,R=map(int,input().split()) print(d[L]-d[R]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; var D : OclAny := null; Sequence{H,W,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var x : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (H * W + D + 1)) ; var y : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (H * W + D + 1)) ; for k : Integer.subrange(0, W-1) do ( for l : Integer.subrange(0, H-1) do ( x[A[l+1][k+1]+1] := k + 1 ; y[A[l+1][k+1]+1] := l + 1)) ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (H * W + D + 1)) ; for k : Integer.subrange(0 + 1, H * W)->reverse() do ( d[k+1] := d[k + D+1] + (x[k+1] - x[k + D+1])->abs() + (y[k+1] - y[k + D+1])->abs()) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var L : OclAny := null; var R : OclAny := null; Sequence{L,R} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (d[L+1] - d[R+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate H,W,D=map(int,input().split()) A=[[int(e)-1 for e in input().split()]for _ in range(H)] Q=int(input()) query=[[int(e)-1 for e in input().split()]for _ in range(Q)] pos=[-1]*(H*W) for i,line in enumerate(A): for j,a in enumerate(line): pos[a]=(i,j) mp_list=[[0]for _ in range(D)] for r in range(D): res=[] for k in range(H*W): if r+k*D<=H*W-1 : res.append(pos[r+k*D]) else : break for l in range(len(res)-1): i,j=res[l] ni,nj=res[l+1] mp=abs(ni-i)+abs(nj-j) mp_list[r].append(mp) for i in range(D): mp_list[i]=list(accumulate(mp_list[i])) for left,right in query : r=left % D q1=(left-r)//D q2=(right-r)//D ans=mp_list[r][q2]-mp_list[r][q1] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var H : OclAny := null; var W : OclAny := null; var D : OclAny := null; Sequence{H,W,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | (input().split()->select(e | true)->collect(e | (("" + ((e)))->toInteger() - 1)))) ; var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var query : Sequence := Integer.subrange(0, Q-1)->select(_anon | true)->collect(_anon | (input().split()->select(e | true)->collect(e | (("" + ((e)))->toInteger() - 1)))) ; var pos : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (H * W)) ; for _tuple : Integer.subrange(1, (A)->size())->collect( _indx | Sequence{_indx-1, (A)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var line : OclAny := _tuple->at(_indx); for _tuple : Integer.subrange(1, (line)->size())->collect( _indx | Sequence{_indx-1, (line)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); pos[a+1] := Sequence{i, j})) ; var mp_list : Sequence := Integer.subrange(0, D-1)->select(_anon | true)->collect(_anon | (Sequence{ 0 })) ; for r : Integer.subrange(0, D-1) do ( var res : Sequence := Sequence{} ; for k : Integer.subrange(0, H * W-1) do ( if (r + k * D->compareTo(H * W - 1)) <= 0 then ( execute ((pos[r + k * D+1]) : res) ) else ( break )) ; for l : Integer.subrange(0, (res)->size() - 1-1) do ( var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := res[l+1] ; var ni : OclAny := null; var nj : OclAny := null; Sequence{ni,nj} := res[l + 1+1] ; var mp : double := (ni - i)->abs() + (nj - j)->abs() ; (expr (atom (name mp_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name mp)))))))) )))))) ; for i : Integer.subrange(0, D-1) do ( mp_list[i+1] := (accumulate(mp_list[i+1]))) ; for _tuple : query do (var _indx : int := 1; var left : OclAny := _tuple->at(_indx); _indx := _indx + 1; var right : OclAny := _tuple->at(_indx); var r : int := left mod D ; var q1 : int := (left - r) div D ; var q2 : int := (right - r) div D ; var ans : double := mp_list[r+1][q2+1] - mp_list[r+1][q1+1] ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify import sys,bisect,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod=10**9+7 mod2=998244353 INF=float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int,sys.stdin.readline().split())) def inpln(n): return list(int(sys.stdin.readline())for i in range(n)) h,w,d=inpl() a=[inpl()for i in range(h)] de=defaultdict(int) for i in range(h): for j in range(w): de[a[i][j]]=(i,j) li=dict() for i in range(d): c=0 tmp=0 while True : if de[i+d*c]==0 : c+=1 continue tmp=de[i+d*c] break li[i+d*c]=0 while True : c+=1 if de[i+d*c]==0 : break now=de[i+d*c] kyori=abs(now[0]-tmp[0])+abs(now[1]-tmp[1]) li[i+d*c]=li[i+d*(c-1)]+kyori tmp=now q=inp() lr=[inpl()for i in range(q)] for l,r in lr : print(li[r]-li[l]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; var mod : double := (10)->pow(9) + 7 ; var mod2 : int := 998244353 ; var INF : double := ("" + (('inf')))->toReal() ; skip ; skip ; skip ; var h : OclAny := null; var w : OclAny := null; var d : OclAny := null; Sequence{h,w,d} := inpl() ; var a : Sequence := Integer.subrange(0, h-1)->select(i | true)->collect(i | (inpl())) ; var de : OclAny := defaultdict(OclType["int"]) ; for i : Integer.subrange(0, h-1) do ( for j : Integer.subrange(0, w-1) do ( de[a[i+1][j+1]+1] := Sequence{i, j})) ; var li : Map := (arguments ( )) ; for i : Integer.subrange(0, d-1) do ( var c : int := 0 ; var tmp : int := 0 ; while true do ( if de[i + d * c+1] = 0 then ( c := c + 1 ; continue ) else skip ; tmp := de[i + d * c+1] ; break) ; li[i + d * c+1] := 0 ; while true do ( c := c + 1 ; if de[i + d * c+1] = 0 then ( break ) else skip ; var now : OclAny := de[i + d * c+1] ; var kyori : double := (now->first() - tmp->first())->abs() + (now[1+1] - tmp[1+1])->abs() ; li[i + d * c+1] := li[i + d * (c - 1)+1] + kyori ; tmp := now)) ; var q : OclAny := inp() ; var lr : Sequence := Integer.subrange(0, q-1)->select(i | true)->collect(i | (inpl())) ; for _tuple : lr do (var _indx : int := 1; var l : OclAny := _tuple->at(_indx); _indx := _indx + 1; var r : OclAny := _tuple->at(_indx); execute (li[r+1] - li[l+1])->display()); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inpl() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inpln(n : OclAny) : OclAny pre: true post: true activity: return ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdin)) (trailer . (name readline) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w,d=map(int,input().split()) a_array=[[int(x)for x in input().split()]for y in range(h)] q=int(input()) lr_array=[[int(x)for x in input().split()]for y in range(q)] whole=[] for i in range(h): for j in range(w): whole.append([a_array[i][j],i+1,j+1]) whole=[[x[1],x[2]]for x in sorted(whole,key=lambda x : x[0])] diff=[0 for x in range(h*w)] for i in range(d,h*w): if diff[i]!=0 : continue if i==0 : continue for j in range(i,h*w,d): base_x,base_y=whole[j] next_x,next_y=whole[j-d] diff[j]=diff[j-d]+abs(base_x-next_x)+abs(base_y-next_y) for l,r in lr_array : print(diff[r-1]-diff[l-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; var d : OclAny := null; Sequence{h,w,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a_array : Sequence := Integer.subrange(0, h-1)->select(y | true)->collect(y | (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lr_array : Sequence := Integer.subrange(0, q-1)->select(y | true)->collect(y | (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))) ; var whole : Sequence := Sequence{} ; for i : Integer.subrange(0, h-1) do ( for j : Integer.subrange(0, w-1) do ( execute ((Sequence{a_array[i+1][j+1]}->union(Sequence{i + 1}->union(Sequence{ j + 1 }))) : whole))) ; whole := whole->sortedBy($x | (lambda x : OclAny in (x->first()))->apply($x))->select(x | true)->collect(x | (Sequence{x[1+1]}->union(Sequence{ x[2+1] }))) ; var diff : Sequence := Integer.subrange(0, h * w-1)->select(x | true)->collect(x | (0)) ; for i : Integer.subrange(d, h * w-1) do ( if diff[i+1] /= 0 then ( continue ) else skip ; if i = 0 then ( continue ) else skip ; for j : Integer.subrange(i, h * w-1)->select( $x | ($x - i) mod d = 0 ) do ( var base_x : OclAny := null; var base_y : OclAny := null; Sequence{base_x,base_y} := whole[j+1] ; var next_x : OclAny := null; var next_y : OclAny := null; Sequence{next_x,next_y} := whole[j - d+1] ; diff[j+1] := diff[j - d+1] + (base_x - next_x)->abs() + (base_y - next_y)->abs())) ; for _tuple : lr_array do (var _indx : int := 1; var l : OclAny := _tuple->at(_indx); _indx := _indx + 1; var r : OclAny := _tuple->at(_indx); execute (diff[r - 1+1] - diff[l - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dist(d1,d2): return abs(d1[0]-d2[0])+abs(d1[1]-d2[1]) h,w,d=map(int,input().split()) table={} for i in range(h): a=list(map(int,input().split())) for j in range(w): table[a[j]]=(j+1,i+1) cum=[0]*(h*w+1) for i in range(h*w+1): if i>d : cum[i]=cum[i-d]+dist(table[i],table[i-d]) q=int(input()) for i in range(q): l,r=map(int,input().split()) print(cum[r]-cum[l]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var h : OclAny := null; var w : OclAny := null; var d : OclAny := null; Sequence{h,w,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var table : OclAny := Set{} ; for i : Integer.subrange(0, h-1) do ( var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, w-1) do ( table[a[j+1]+1] := Sequence{j + 1, i + 1})) ; var cum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (h * w + 1)) ; for i : Integer.subrange(0, h * w + 1-1) do ( if (i->compareTo(d)) > 0 then ( cum[i+1] := cum[i - d+1] + dist(table[i+1], table[i - d+1]) ) else skip) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (cum[r+1] - cum[l+1])->display()); operation dist(d1 : OclAny, d2 : OclAny) : OclAny pre: true post: true activity: return (d1->first() - d2->first())->abs() + (d1[1+1] - d2[1+1])->abs(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() n,t=map(int,input().split()) res={} for i in range(1,n+1): s,d=map(int,input().split()) res[(s-t)%(s,d)[stoInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var res : OclAny := Set{} ; for i : Integer.subrange(1, n + 1-1) do ( var s : OclAny := null; var d : OclAny := null; Sequence{s,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; res[(s - t) mod Sequence{s, d}->select((s->compareTo(t)) < 0)+1] := i) ; execute (res[(res)->min()+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def is_over_threshold_days(stay_days,threshold_days): if stay_days<=threshold_days : return False if stay_days>threshold_days : return True def calc_accomodation_fee(stay_days,threshold_days,first_fee,second_fee): if is_over_threshold_days(stay_days,threshold_days): sum_of_first_fee=first_fee*threshold_days sum_of_second_fee=second_fee*(stay_days-threshold_days) return sum_of_first_fee+sum_of_second_fee else : return stay_days*first_fee if __name__=='__main__' : stay_days,threshold_days,first_fee,second_fee=[int(input())for i in range(4)] print(calc_accomodation_fee(stay_days,threshold_days,first_fee,second_fee)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( Sequence{stay_days,threshold_days,first_fee,second_fee} := Integer.subrange(0, 4-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; execute (calc_accomodation_fee(stay_days, threshold_days, first_fee, second_fee))->display() ) else skip; operation is_over_threshold_days(stay_days : OclAny, threshold_days : OclAny) : OclAny pre: true post: true activity: if (stay_days->compareTo(threshold_days)) <= 0 then ( return false ) else skip ; if (stay_days->compareTo(threshold_days)) > 0 then ( return true ) else skip; operation calc_accomodation_fee(stay_days : OclAny, threshold_days : OclAny, first_fee : OclAny, second_fee : OclAny) : OclAny pre: true post: true activity: if is_over_threshold_days(stay_days, threshold_days) then ( var sum_of_first_fee : double := first_fee * threshold_days ; var sum_of_second_fee : double := second_fee * (stay_days - threshold_days) ; return sum_of_first_fee + sum_of_second_fee ) else ( return stay_days * first_fee ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect,collections,copy,heapq,itertools,math,numpy,string import sys def S(): return sys.stdin.readline().rstrip() def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LS(): return list(sys.stdin.readline().rstrip().split()) a,b=LI() if a>0 : print('Positive') elif a<=0 and b>=0 : print('Zero') else : if(a+b)% 2==0 : print('Negative') else : print('Positive') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := LI() ; if a > 0 then ( execute ('Positive')->display() ) else (if a <= 0 & b >= 0 then ( execute ('Zero')->display() ) else ( if (a + b) mod 2 = 0 then ( execute ('Negative')->display() ) else ( execute ('Positive')->display() ) ) ) ; operation S() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation I() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.readLine().rstrip())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LS() : OclAny pre: true post: true activity: return (sys.stdin.readLine().rstrip().split()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printArr(arr,n): for i in range(n): print(arr[i],end=" "); def findArray(n,k,s): vis=[0]*n ; cnt=0 ; arr=[0]*n ; i=0 ; while(idisplay();); operation findArray(n : OclAny, k : OclAny, s : OclAny) pre: true post: true activity: var vis : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; var cnt : int := 0; ; arr := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; var i : int := 0; ; while ((i->compareTo(n)) < 0 & (cnt->compareTo(k)) < 0) do ( arr[i+1] := s; ; vis[i+1] := 1; ; cnt := cnt + 1; ; i := i + 2;) ; var val : OclAny := s; ; if (s mod 2 = 0) then ( val := val + 1; ) else ( val := val + 2; ) ; for i : Integer.subrange(0, n-1) do ( if (vis[i+1] = 0) then ( arr[i+1] := val; ) else skip) ; printArr(arr, n);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- list_1=[[[int(w)for w in input().split()],[int(w)for w in input().split()]]for q in range(int(input()))] for q in range(len(list_1)): all=sum(list_1[q][1][1 :]) maxx=list_1[q][0][1] my_max=list_1[q][1][0]+all otv=int(my_max>=maxx)*maxx+int(my_maxtoInteger()-1)->select(q | true)->collect(q | (Sequence{input().split()->select(w | true)->collect(w | (("" + ((w)))->toInteger()))}->union(Sequence{ input().split()->select(w | true)->collect(w | (("" + ((w)))->toInteger())) }))) ; for q : Integer.subrange(0, (list(list((list((list var list_1 : Sequence := Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1)->select(q | true)->collect(q | (Sequence{input().split()->select(w | true)->collect(w | (("" + ((w)))->toInteger()))}->union(Sequence{ input().split()->select(w | true)->collect(w | (("" + ((w)))->toInteger())) }))))->size()))->size()))->size())->size()-1) do ( var all : OclAny := (list var list_1 : Sequence := Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1)->select(q | true)->collect(q | (Sequence{input().split()->select(w | true)->collect(w | (("" + ((w)))->toInteger()))}->union(Sequence{ input().split()->select(w | true)->collect(w | (("" + ((w)))->toInteger())) })))[q+1][1+1]->tail())->sum() ; var maxx : OclAny := list var all : OclAny := (list var list_1 : Sequence := Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1)->select(q | true)->collect(q | (Sequence{input().split()->select(w | true)->collect(w | (("" + ((w)))->toInteger()))}->union(Sequence{ input().split()->select(w | true)->collect(w | (("" + ((w)))->toInteger())) })))[q+1][1+1]->tail())->sum()[q+1]->first()[1+1] ; var my_max : OclAny := list var all : OclAny := (list var list_1 : Sequence := Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1)->select(q | true)->collect(q | (Sequence{input().split()->select(w | true)->collect(w | (("" + ((w)))->toInteger()))}->union(Sequence{ input().split()->select(w | true)->collect(w | (("" + ((w)))->toInteger())) })))[q+1][1+1]->tail())->sum()[q+1][1+1]->first() + all ; var otv : double := ("" + (((my_max->compareTo(maxx)) >= 0)))->toInteger() * maxx + ("" + (((my_max->compareTo(maxx)) < 0)))->toInteger() * my_max ; list var all : OclAny := (list var list_1 : Sequence := Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1)->select(q | true)->collect(q | (Sequence{input().split()->select(w | true)->collect(w | (("" + ((w)))->toInteger()))}->union(Sequence{ input().split()->select(w | true)->collect(w | (("" + ((w)))->toInteger())) })))[q+1][1+1]->tail())->sum()[q+1] := ("" + ((otv)))) ; execute (StringLib.sumStringsWithSeparator((list"\n"), "\n"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s,t=map(str,input().split()) a=t+s print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; var a : OclAny := t + s ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,collections as cl,bisect as bs sys.setrecursionlimit(100000) input=sys.stdin.readline mod=10**9+7 Max=sys.maxsize def l(): return list(map(int,input().split())) def m(): return map(int,input().split()) def onem(): return int(input()) def s(x): a=[] aa=x[0] su=1 for i in range(len(x)-1): if aa!=x[i+1]: a.append([aa,su]) aa=x[i+1] su=1 else : su+=1 a.append([aa,su]) return a def jo(x): return " ".join(map(str,x)) def max2(x): return max(map(max,x)) def In(x,a): k=bs.bisect_left(a,x) if k!=len(a)and a[k]==x : return True else : return False a,b=input().split() print(b+a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(100000) ; var input : OclAny := (OclFile["System.in"]).readline ; var mod : double := (10)->pow(9) + 7 ; var Max : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var b : OclAny := null; Sequence{a,b} := input().split() ; execute (b->union(a))->display(); operation l() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation m() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation onem() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation s(x : OclAny) : OclAny pre: true post: true activity: var a : Sequence := Sequence{} ; var aa : OclAny := x->first() ; var su : int := 1 ; for i : Integer.subrange(0, (x)->size() - 1-1) do ( if aa /= x[i + 1+1] then ( execute ((Sequence{aa}->union(Sequence{ su })) : a) ; aa := x[i + 1+1] ; su := 1 ) else ( su := su + 1 )) ; execute ((Sequence{aa}->union(Sequence{ su })) : a) ; return a; operation jo(x : OclAny) : OclAny pre: true post: true activity: return StringLib.sumStringsWithSeparator(((x)->collect( _x | (OclType["String"])->apply(_x) )), " "); operation max2(x : OclAny) : OclAny pre: true post: true activity: return ((x)->collect( _x | (max)->apply(_x) ))->max(); operation In(x : OclAny, a : OclAny) : OclAny pre: true post: true activity: var k : OclAny := bs.bisect_left(a, x) ; if k /= (a)->size() & a[k+1] = x then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) write=sys.stdout.write dbg=lambda*something : print(*something)if DEBUG else 0 DEBUG=False def main(given=sys.stdin.readline): input=lambda : given().rstrip() LMIIS=lambda : list(map(int,input().split())) II=lambda : int(input()) XLMIIS=lambda x :[LMIIS()for _ in range(x)] s=input().split() print(s[1]+s[0]) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; var write : OclAny := (OclFile["System.out"]).write ; var dbg : Function := lambda something : Sequence(OclAny) in (if DEBUG then ((argument * (test (logical_test (comparison (expr (atom (name something))))))))->display() else 0 endif) ; var DEBUG : boolean := false ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main(given : OclAny) pre: true post: true activity: if given->oclIsUndefined() then given := (OclFile["System.in"]).readline else skip; var input : Function := lambda $$ : OclAny in (given().rstrip()) ; var LMIIS : Function := lambda $$ : OclAny in (((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var II : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var XLMIIS : Function := lambda x : OclAny in (Integer.subrange(0, x-1)->select(_anon | true)->collect(_anon | (LMIIS->apply()))) ; var s : OclAny := input->apply().split() ; execute (s[1+1] + s->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline MOD=10**9+7 INF=float('INF') def main(): s,t=list(map(str,input().split())) print(t+s) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var MOD : double := (10)->pow(9) + 7 ; var INF : double := ("" + (('INF')))->toReal() ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := ((input().split())->collect( _x | (OclType["String"])->apply(_x) )) ; execute (t + s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print("".join(input().split()[: :-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (StringLib.sumStringsWithSeparator((input().split()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getCount(a,b,c): count=0 for i in range(1,82): cr=b*pow(i,a)+c tmp=cr sm=0 while(tmp): sm+=tmp % 10 tmp//=10 if(sm==i and cr<10**9): count+=1 return count a,b,c=3,2,8 print(getCount(a,b,c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{a,b,c} := Sequence{3,2,8} ; execute (getCount(a, b, c))->display(); operation getCount(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(1, 82-1) do ( var cr : double := b * (i)->pow(a) + c ; var tmp : OclAny := cr ; var sm : int := 0 ; while (tmp) do ( sm := sm + tmp mod 10 ; tmp := tmp div 10) ; if (sm = i & (cr->compareTo((10)->pow(9))) < 0) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPowerOfK(n,k): oneSeen=False while(n>0): digit=n % k if(digit>1): return False if(digit==1): if(oneSeen): return False oneSeen=True n//=k return True n=64 k=4 if(isPowerOfK(n,k)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 64 ; k := 4 ; if (isPowerOfK(n, k)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isPowerOfK(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var oneSeen : boolean := false ; while (n > 0) do ( var digit : int := n mod k ; if (digit > 1) then ( return false ) else skip ; if (digit = 1) then ( if (oneSeen) then ( return false ) else skip ; oneSeen := true ) else skip ; n := n div k) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math ; def getOccurence(n,d): result=0 ; itr=d ; while(itr<=n): if(itr % 10==d): result+=1 ; if(itr!=0 and math.floor(itr/10)==d): result+=1 ; itr+=1 ; elif(math.floor(itr/10)==d-1): itr=itr+(10-d); else : itr=itr+10 ; return result ; n=11 ; d=1 ; print(getOccurence(n,d)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; ; skip ; n := 11; ; d := 1; ; execute (getOccurence(n, d))->display();; operation getOccurence(n : OclAny, d : OclAny) pre: true post: true activity: var result : int := 0; ; var itr : OclAny := d; ; while ((itr->compareTo(n)) <= 0) do ( if (itr mod 10 = d) then ( result := result + 1; ) else skip ; if (itr /= 0 & (itr / 10)->floor() = d) then ( result := result + 1; ; itr := itr + 1; ) else (if ((itr / 10)->floor() = d - 1) then ( itr := itr + (10 - d); ) else ( itr := itr + 10; ) ) ) ; return result;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) def f(x): if x<0 : return-1 elif x>0 : return 1 else : return 0 if f(a)==0 or f(b)==0 : ans="Zero" elif f(a)==-1 and f(b)==-1 : diff=b-a if(diff+1)% 2==0 : ans="Positive" else : ans="Negative" elif f(a)==1 and f(b)==1 : ans="Positive" else : ans="Zero" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; if f(a) = 0 or f(b) = 0 then ( var ans : String := "Zero" ) else (if f(a) = -1 & f(b) = -1 then ( var diff : double := b - a ; if (diff + 1) mod 2 = 0 then ( ans := "Positive" ) else ( ans := "Negative" ) ) else (if f(a) = 1 & f(b) = 1 then ( ans := "Positive" ) else ( ans := "Zero" ) ) ) ; execute (ans)->display(); operation f(x : OclAny) : OclAny pre: true post: true activity: if x < 0 then ( return -1 ) else (if x > 0 then ( return 1 ) else ( return 0 ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import setrecursionlimit setrecursionlimit(10**6) import threading def dfs(node,g,size): l=0 for i in g[node]: l+=dfs(i,g,size) size[node]=l return size[node]+1 from collections import defaultdict def main(): g=defaultdict(list) n=int(input()) if n==1 : print(1) exit(0) ar=list(map(int,input().strip().split())) for i in range(n-1): g[ar[i]].append(i+2) ar=[0,0]+ar sz=[0]*(n+1) sz[1]=1 dfs(1,g,sz) time=[0]*(n+1) time[1]=1 for i in range(2,n+1): parent=ar[i] time[i]=time[parent]+(sz[parent]-sz[i]-1)/2+1 print(*time[1 :]) threading.stack_size(10**8) t=threading.Thread(target=main) t.start() t.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; setrecursionlimit((10)->pow(6)) ; skip ; skip ; skip ; skip ; threading.stack_size((10)->pow(8)) ; var t : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ; t.start() ; t.join(); operation dfs(node : OclAny, g : OclAny, size : OclAny) : OclAny pre: true post: true activity: var l : int := 0 ; for i : g[node+1] do ( l := l + dfs(i, g, size)) ; size[node+1] := l ; return size[node+1] + 1; operation main() pre: true post: true activity: g := defaultdict(OclType["Sequence"]) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (1)->display() ; exit(0) ) else skip ; var ar : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n - 1-1) do ((expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ar)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 2)))))))))) ))))) ; ar := Sequence{0}->union(Sequence{ 0 })->union(ar) ; var sz : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; sz[1+1] := 1 ; dfs(1, g, sz) ; var time : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; time[1+1] := 1 ; for i : Integer.subrange(2, n + 1-1) do ( var parent : OclAny := ar[i+1] ; time[i+1] := time[parent+1] + (sz[parent+1] - sz[i+1] - 1) / 2 + 1) ; execute ((argument * (test (logical_test (comparison (expr (atom (name time)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) par=[-1]+[int(i)-1 for i in input().split()] child=[[]for i in range(n)] for i in range(1,n): child[par[i]].append(i) size=[1]*n def dfs(): stack=[0] visit=[False]*n while stack : u=stack[-1] if not visit[u]: for v in child[u]: stack.append(v) visit[u]=True else : for v in child[u]: size[u]+=size[v] stack.pop() ans=[0]*n ans[0]=1 def dfs2(): stack=[0] while stack : u=stack.pop() sm=0 for v in child[u]: sm+=size[v] for v in child[u]: ans[v]=(sm-size[v])*0.5+1+ans[u] stack.append(v) dfs() dfs2() print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var par : Sequence := Sequence{ -1 }->union(input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger() - 1))) ; var child : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(1, n-1) do ((expr (atom (name child)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name par)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var size : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, n) ; skip ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; ans->first() := 1 ; skip ; dfs() ; dfs2() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); operation dfs() pre: true post: true activity: var stack : Sequence := Sequence{ 0 } ; var visit : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ; while stack do ( var u : OclAny := stack->last() ; if not(visit[u+1]) then ( for v : child[u+1] do ( execute ((v) : stack)) ; visit[u+1] := true ) else ( for v : child[u+1] do ( size[u+1] := size[u+1] + size[v+1]) ; stack := stack->front() )); operation dfs2() pre: true post: true activity: stack := Sequence{ 0 } ; while stack do ( u := stack->last() ; stack := stack->front() ; var sm : int := 0 ; for v : child[u+1] do ( sm := sm + size[v+1]) ; for v : child[u+1] do ( ans[v+1] := (sm - size[v+1]) * 0.5 + 1 + ans[u+1] ; execute ((v) : stack))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print("\n".join([str((lambda x,y : int(x>=y)*y+int(xtoInteger()-1)->select(_anon | true)->collect(_anon | (Sequence{input().split()->select(w | true)->collect(w | (("" + ((w)))->toInteger()))}->union(Sequence{ input().split()->select(w | true)->collect(w | (("" + ((w)))->toInteger())) })))->select(q | true)->collect(q | (("" + (((lambda x : OclAny, y : OclAny in (("" + (((x->compareTo(y)) >= 0)))->toInteger() * y + ("" + (((x->compareTo(y)) < 0)))->toInteger() * x))(q[1+1]->first() + (q[1+1]->tail())->sum(), q->first()[1+1]))))))), "\n"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==1 : print(1) exit(0) l=list(map(int,input().split())) w=[[]for i in range(n)] sz=[1]*n for i in range(n-1): w[l[i]-1].append(i+1) for i in range(n-1,-1,-1): for j in range(len(w[i])): sz[i]+=sz[w[i][j]] ans=[0]*n for i in range(n): for j in range(len(w[i])): ans[w[i][j]]=ans[i]+1+(sz[i]-1-sz[w[i][j]])/2 for i in range(n): print(ans[i]+1,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (1)->display() ; exit(0) ) else skip ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var w : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; var sz : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, n) ; for i : Integer.subrange(0, n - 1-1) do ((expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ))))) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( for j : Integer.subrange(0, (w[i+1])->size()-1) do ( sz[i+1] := sz[i+1] + sz[w[i+1][j+1]+1])) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, (w[i+1])->size()-1) do ( ans[w[i+1][j+1]+1] := ans[i+1] + 1 + (sz[i+1] - 1 - sz[w[i+1][j+1]+1]) / 2)) ; for i : Integer.subrange(0, n-1) do ( execute (ans[i+1] + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==1 : print(1) exit(0) l=list(map(int,input().split())) w=[[]for i in range(n)] sz=[1]*n for i in range(n-1): w[l[i]-1].append(i+1) for i in range(n-1,-1,-1): for j in range(len(w[i])): sz[i]+=sz[w[i][j]] ans=[0]*n for i in range(n): for j in range(len(w[i])): ans[w[i][j]]=ans[i]+1+(sz[i]-1-sz[w[i][j]])/2 for i in range(n): print(ans[i]+1,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (1)->display() ; exit(0) ) else skip ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var w : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; var sz : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, n) ; for i : Integer.subrange(0, n - 1-1) do ((expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ))))) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( for j : Integer.subrange(0, (w[i+1])->size()-1) do ( sz[i+1] := sz[i+1] + sz[w[i+1][j+1]+1])) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, (w[i+1])->size()-1) do ( ans[w[i+1][j+1]+1] := ans[i+1] + 1 + (sz[i+1] - 1 - sz[w[i+1][j+1]+1]) / 2)) ; for i : Integer.subrange(0, n-1) do ( execute (ans[i+1] + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n>1 : p=input().split(' ') else : p=[] g=[] ans=[] sz=[] for i in range(0,n): g.append([]) ans.append(0.0) sz.append(0) for i in range(0,n-1): g[int(p[i])-1].append(i+1) for i in range(0,n)[: :-1]: sz[i]=1 for to in g[i]: sz[i]+=sz[to] for i in range(0,n): for to in g[i]: ans[to]=ans[i]+1+(sz[i]-1-sz[to])*0.5 print(' '.join([str(a+1)for a in ans])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n > 1 then ( var p : OclAny := input().split(' ') ) else ( p := Sequence{} ) ; var g : Sequence := Sequence{} ; var ans : Sequence := Sequence{} ; var sz : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((Sequence{}) : g) ; execute ((0.0) : ans) ; execute ((0) : sz)) ; for i : Integer.subrange(0, n - 1-1) do ((expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ))))) ; for i : range(0, n)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( sz[i+1] := 1 ; for to : g[i+1] do ( sz[i+1] := sz[i+1] + sz[to+1])) ; for i : Integer.subrange(0, n-1) do ( for to : g[i+1] do ( ans[to+1] := ans[i+1] + 1 + (sz[i+1] - 1 - sz[to+1]) * 0.5)) ; execute (StringLib.sumStringsWithSeparator((ans->select(a | true)->collect(a | (("" + ((a + 1)))))), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools def compute(): M=50 ways=[1] for n in itertools.count(1): s=ways[n-1]+sum(ways[: max(n-M,0)]) if n>=M : s+=1 ways.append(s) if s>1000000 : return str(n) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var M : int := 50 ; var ways : Sequence := Sequence{ 1 } ; for n : itertools->count(1) do ( var s : OclAny := ways[n - 1+1] + (ways.subrange(1,Set{n - M, 0}->max()))->sum() ; if (n->compareTo(M)) >= 0 then ( s := s + 1 ) else skip ; execute ((s) : ways) ; if s > 1000000 then ( return ("" + ((n))) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,m=map(int,input().split()) for _ in range(m): input() ans=[i % 2 for i in range(n)] sys.stdout.write("".join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for _anon : Integer.subrange(0, m-1) do ( input()) ; var ans : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i mod 2)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n,m=map(int,input().split()) fb=["0"]*n for i in range(m): l,r=map(int,input().split()) l-=1 r-=1 temp=r-l+1 roses=temp//2 while l0 : if l % 2==0 : fb[l]="1" l+=2 roses-=1 else : l+=1 return "".join(fb) t=1 while t!=0 : res=solve() print(res) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := 1 ; while t /= 0 do ( var res : OclAny := solve() ; execute (res)->display() ; t := t - 1); operation solve() : OclAny pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var fb : Sequence := MatrixLib.elementwiseMult(Sequence{ "0" }, n) ; for i : Integer.subrange(0, m-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; l := l - 1 ; r := r - 1 ; var temp : double := r - l + 1 ; var roses : int := temp div 2 ; while (l->compareTo(r + 1)) < 0 & roses > 0 do ( if l mod 2 = 0 then ( fb[l+1] := "1" ; l := l + 2 ; roses := roses - 1 ) else ( l := l + 1 ))) ; return StringLib.sumStringsWithSeparator((fb), ""); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- arr=list(map(int,input().rstrip().split())) n=arr[0] m=arr[1] arr=[] for i in range(m): brr=[] crr=list(map(int,input().rstrip().split())) b=crr[1] a=crr[0] brr.append(b-a) brr.extend(crr) arr.append(brr) s="" for i in range(n): if(i % 2==0): s+='1' else : s+='0' print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var arr : Sequence := ((input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := arr->first() ; var m : OclAny := arr[1+1] ; arr := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var brr : Sequence := Sequence{} ; var crr : Sequence := ((input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : OclAny := crr[1+1] ; var a : OclAny := crr->first() ; execute ((b - a) : brr) ; brr := brr->union(crr) ; execute ((brr) : arr)) ; var s : String := "" ; for i : Integer.subrange(0, n-1) do ( if (i mod 2 = 0) then ( s := s + '1' ) else ( s := s + '0' )) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countEleLessThanOrEqual(arr1,arr2,m,n): for i in range(m): count=0 for j in range(n): if(arr2[j]<=arr1[i]): count+=1 print(count,end=" ") arr1=[1,2,3,4,7,9] arr2=[0,1,2,1,1,4] m=len(arr1) n=len(arr2) countEleLessThanOrEqual(arr1,arr2,m,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr1 := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{7}->union(Sequence{ 9 }))))) ; arr2 := Sequence{0}->union(Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 4 }))))) ; m := (arr1)->size() ; n := (arr2)->size() ; countEleLessThanOrEqual(arr1, arr2, m, n); operation countEleLessThanOrEqual(arr1 : OclAny, arr2 : OclAny, m : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, m-1) do ( var count : int := 0 ; for j : Integer.subrange(0, n-1) do ( if ((arr2[j+1]->compareTo(arr1[i+1])) <= 0) then ( count := count + 1 ) else skip) ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,m=map(int,input().split()) arr=[input().split()for _ in range(m)] answer_string="" for i in range(n): if i % 2==0 : answer_string+="1" else : answer_string+="0" print(answer_string) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (input().split())) ; var answer_string : String := "" ; for i : Integer.subrange(0, n-1) do ( if i mod 2 = 0 then ( answer_string := answer_string + "1" ) else ( answer_string := answer_string + "0" )) ; execute (answer_string)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,m=map(int,input().split()) if n & 1==0 : print('01'*(n>>1)) else : print('01'*(n>>1)+'0') if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if MathLib.bitwiseAnd(n, 1) = 0 then ( execute (StringLib.nCopies('01', (n /(2->pow(1)))))->display() ) else ( execute (StringLib.nCopies('01', (n /(2->pow(1)))) + '0')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getHermiteNumber(n): if n==0 : return 1 if n==1 : return 0 else : return(-2*(n-1)*getHermiteNumber(n-2)) n=6 print(getHermiteNumber(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 6 ; execute (getHermiteNumber(n))->display();; operation getHermiteNumber(n : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( return 1 ) else skip ; if n = 1 then ( return 0 ) else ( return (-2 * (n - 1) * getHermiteNumber(n - 2)) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(1,t+1): a,b,c,d=map(int,input().split()) e=a//b f=d//b g=(c-1)//b print(e-(f-g)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(1, t + 1-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var e : int := a div b ; var f : int := d div b ; var g : int := (c - 1) div b ; execute (e - (f - g))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math ; def printPowerSet(set,set_size): pow_set_size=(int)(math.pow(2,set_size)); counter=0 ; j=0 ; for counter in range(0,pow_set_size): for j in range(0,set_size): if((counter &(1<0): print(set[j],end=""); print(""); set=['a','b','c']; printPowerSet(set,3); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; ; skip ; OclType["Set"] := Sequence{'a'}->union(Sequence{'b'}->union(Sequence{ 'c' })); ; printPowerSet(OclType["Set"], 3);; operation printPowerSet(set : OclAny, set_size : OclAny) pre: true post: true activity: var pow_set_size : OclAny := (OclType["int"])((2)->pow(set_size)); ; var counter : int := 0; ; var j : int := 0; ; for counter : Integer.subrange(0, pow_set_size-1) do ( for j : Integer.subrange(0, set_size-1) do ( if ((MathLib.bitwiseAnd(counter, (1 * (2->pow(j))))) > 0) then ( execute (Set{}->union([j+1]))->display(); ) else skip) ; execute ("")->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) s='.'*n m=(k+1)//2 a='.'+'#'*m+'.'*(n-m-1) if k % 2==0 : b=a elif kcollect( _x | (OclType["int"])->apply(_x) ) ; var s : String := StringLib.nCopies('.', n) ; var m : int := (k + 1) div 2 ; var a : String := '.' + StringLib.nCopies('#', m) + StringLib.nCopies('.', (n - m - 1)) ; if k mod 2 = 0 then ( var b : String := a ) else (if (k->compareTo(n)) < 0 then ( var t : String := StringLib.nCopies('.', ((n - k) div 2)) ; Sequence{a,b} := Sequence{t + StringLib.nCopies('#', k) + t,s} ) else ( b := a.subrange(1,2) + '.' + a.subrange(3+1) ) ) ; execute ('YES')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- col,hotel=map(int,input().split()) if(col-2)*2collect( _x | (OclType["int"])->apply(_x) ) ; if ((col - 2) * 2->compareTo(hotel)) < 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ; if hotel mod 2 = 0 then ( var hotel_col : int := hotel div 2 ; execute (StringLib.nCopies(".", col))->display() ; execute ("." + StringLib.nCopies("#", hotel_col) + StringLib.nCopies(".", (col - 1 - hotel_col)))->display() ; execute ("." + StringLib.nCopies("#", hotel_col) + StringLib.nCopies(".", (col - 1 - hotel_col)))->display() ; execute (StringLib.nCopies(".", col))->display() ) else ( if (hotel->compareTo(col - 2)) <= 0 then ( execute (StringLib.nCopies(".", col))->display() ; execute (StringLib.nCopies(".", ((col - hotel) div 2)) + StringLib.nCopies("#", hotel) + StringLib.nCopies(".", ((col - hotel) div 2)))->display() ; execute (StringLib.nCopies(".", col))->display() ; execute (StringLib.nCopies(".", col))->display() ) else ( hotel_col := hotel - col + 2 ; execute (StringLib.nCopies(".", col))->display() ; execute ("." + StringLib.nCopies("#", (col - 2)) + ".")->display() ; execute (StringLib.nCopies(".", ((col - hotel_col - 1) div 2)) + StringLib.nCopies("#", (hotel_col div 2)) + "." + StringLib.nCopies("#", (hotel_col div 2)) + StringLib.nCopies(".", ((col - hotel_col - 1) div 2)))->display() ; execute (StringLib.nCopies(".", col))->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- EMPTY="." HOTEL="#" def main(): n,k=map(int,input().split()) print("YES") print(EMPTY*n) if k % 2==0 : m=k//2 s=EMPTY+HOTEL*m+EMPTY*(n-m-1) print(s) print(s) elif kcollect( _x | (OclType["int"])->apply(_x) ) ; execute ("YES")->display() ; execute (StringLib.nCopies(EMPTY, n))->display() ; if k mod 2 = 0 then ( var m : int := k div 2 ; var s : String := EMPTY + StringLib.nCopies(HOTEL, m) + StringLib.nCopies(EMPTY, (n - m - 1)) ; execute (s)->display() ; execute (s)->display() ) else (if (k->compareTo(n - 1)) < 0 then ( s := (StringLib.nCopies(HOTEL, k)).center(n, EMPTY) ; execute (s)->display() ; execute (StringLib.nCopies(EMPTY, n))->display() ) else ( execute (EMPTY + StringLib.nCopies(HOTEL, (n - 2)) + EMPTY)->display() ; execute (EMPTY + StringLib.nCopies(HOTEL, (k - n + 1)) + StringLib.nCopies(EMPTY, (2 * n - k - 4)) + HOTEL + EMPTY)->display() ) ) ; execute (StringLib.nCopies(EMPTY, n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=[] for i in range(4): b=[] for j in range(n): b.append('.') a.append(b) if k % 2==0 : print("YES") q=k//2 for i in range(1,q+1): a[1][i]='#' a[2][i]='#' for i in a : for j in i : print(j,end="") print() elif k<=n-2 : print("YES") print('.'*n) print('.'*((n-k)//2)+k*'#'+'.'*((n-k)//2)) print('.'*n) print('.'*n) else : print("YES") print('.'*n) print('.'+(n-2)*'#'+'.') print('.'+'#'*((k-n+2)//2)+'.'*((2*n-k-4))+'#'*((k-n+2)//2)+'.') print('.'*n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, 4-1) do ( var b : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( execute (('.') : b)) ; execute ((b) : a)) ; if k mod 2 = 0 then ( execute ("YES")->display() ; var q : int := k div 2 ; for i : Integer.subrange(1, q + 1-1) do ( a[1+1][i+1] := '#' ; a[2+1][i+1] := '#') ; for i : a do ( for j : i do ( execute (j)->display()) ; execute (->display()) ) else (if (k->compareTo(n - 2)) <= 0 then ( execute ("YES")->display() ; execute (StringLib.nCopies('.', n))->display() ; execute (StringLib.nCopies('.', ((n - k) div 2)) + k * '#' + StringLib.nCopies('.', ((n - k) div 2)))->display() ; execute (StringLib.nCopies('.', n))->display() ; execute (StringLib.nCopies('.', n))->display() ) else ( execute ("YES")->display() ; execute (StringLib.nCopies('.', n))->display() ; execute ('.' + (n - 2) * '#' + '.')->display() ; execute ('.' + StringLib.nCopies('#', ((k - n + 2) div 2)) + StringLib.nCopies('.', ((2 * n - k - 4))) + StringLib.nCopies('#', ((k - n + 2) div 2)) + '.')->display() ; execute (StringLib.nCopies('.', n))->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=['.'*n for i in 'iiii'] if k>n-2 : a[1]='.'+'#'*(n-2)+'.' k-=n-2 a[2]='.'+'#'*(k>>1)+'.'*(n-2-k>>1) a[2]=a[2]+('#' if k & 1 else '.')+a[2][: :-1] print('YES') print('\n'.join(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := 'iiii'->characters()->select(i | true)->collect(i | (StringLib.nCopies('.', n))) ; if (k->compareTo(n - 2)) > 0 then ( a[1+1] := '.' + StringLib.nCopies('#', (n - 2)) + '.' ; k := k - n - 2 ) else skip ; a[2+1] := '.' + StringLib.nCopies('#', (k /(2->pow(1)))) + StringLib.nCopies('.', (n - 2 - k /(2->pow(1)))) ; a[2+1] := a[2+1] + (if MathLib.bitwiseAnd(k, 1) then '#' else '.' endif) + a[2+1](subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; execute ('YES')->display() ; execute (StringLib.sumStringsWithSeparator((a), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): a,b=(int(i)for i in input().split()) if a<=0 and 0<=b : print("Zero") elif a>0 : print("Positive") elif b<0 : if(b-a)% 2==0 : print("Negative") else : print("Positive") if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; if a <= 0 & 0 <= b then ( execute ("Zero")->display() ) else (if a > 0 then ( execute ("Positive")->display() ) else (if b < 0 then ( if (b - a) mod 2 = 0 then ( execute ("Negative")->display() ) else ( execute ("Positive")->display() ) ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,m,x=map(int,input().split()) a=(x-1)% n b=(x-1)//n res=(m*a+b+1) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; var x : OclAny := null; Sequence{n,m,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : int := (x - 1) mod n ; var b : int := (x - 1) div n ; var res : double := (m * a + b + 1) ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math num=int(input()) for i in range(num): arr=input() arr=arr.split(" ") row=int(arr[0]) col=int(arr[1]) x=int(arr[2]) if x % row==0 : rows=int(x/row)*row else : rows=row+math.floor(x/row)*row cols=math.ceil(x/row) rows=row-(rows-x) cols=cols+col*(rows-1) print(cols) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, num-1) do ( var arr : String := (OclFile["System.in"]).readLine() ; arr := arr.split(" ") ; var row : int := ("" + ((arr->first())))->toInteger() ; var col : int := ("" + ((arr[1+1])))->toInteger() ; var x : int := ("" + ((arr[2+1])))->toInteger() ; if x mod row = 0 then ( var rows : int := ("" + ((x / row)))->toInteger() * row ) else ( rows := row + (x / row)->floor() * row ) ; var cols : double := (x / row)->ceil() ; rows := row - (rows - x) ; cols := cols + col * (rows - 1) ; execute (cols)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : n,m,x=map(int,input().split()) x-=1 print(x % n*m+x//n+1) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( var n : OclAny := null; var m : OclAny := null; var x : OclAny := null; Sequence{n,m,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; x := x - 1 ; execute (x mod n * m + x div n + 1)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n,m,x=map(int,input().split()) x-=1 print(x % n*m+x//n+1) for _ in range(int(input())): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve()); operation solve() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var x : OclAny := null; Sequence{n,m,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; x := x - 1 ; execute (x mod n * m + x div n + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def loop_test_cases(): return range(int(input())) def list_input(): return[int(i)for i in input().split()] for i in loop_test_cases(): L,v,l,r=map(int,input().split()) vv=v first=l//v if l % v==0 : first-=1 if v>=l : first=0 vv=v*(r//v)+v second=(L-max(r,vv))//v+1 if vv>L : second=0 count=first+second print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for i : loop_test_cases() do ( var L : OclAny := null; var v : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{L,v,l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var vv : OclAny := v ; var first : int := l div v ; if l mod v = 0 then ( first := first - 1 ) else skip ; if (v->compareTo(l)) >= 0 then ( first := 0 ) else skip ; vv := v * (r div v) + v ; var second : int := (L - Set{r, vv}->max()) div v + 1 ; if (vv->compareTo(L)) > 0 then ( second := 0 ) else skip ; var count : int := first + second ; execute (count)->display()); operation loop_test_cases() : OclAny pre: true post: true activity: return Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1); operation list_input() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n,m,cell=input().split() n=int(n) m=int(m) cell=int(cell) if cell % n!=0 : x=(cell//n)+1 y=cell % n else : x=cell//n y=n print(((y-1)*m)+x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; var cell : OclAny := null; Sequence{n,m,cell} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var m : int := ("" + ((m)))->toInteger() ; var cell : int := ("" + ((cell)))->toInteger() ; if cell mod n /= 0 then ( var x : int := (cell div n) + 1 ; var y : int := cell mod n ) else ( x := cell div n ; y := n ) ; execute (((y - 1) * m) + x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate n,k=map(int,input().split()) k2=k*2 req_b=[[0]*k for _ in range(k)] req_w=[[0]*k for _ in range(k)] bc,wc=0,0 for i in range(n): x,y,c=input().split() x,y=int(x),int(y) rx,ry=x % k2,y % k2 b=c=='B' if rx>=k : rx-=k if ry>=k : ry-=k else : b=not b elif ry>=k : ry-=k b=not b if b : req_b[rx][ry]+=1 bc+=1 else : req_w[rx][ry]+=1 wc+=1 req_b=[list(accumulate(req))for req in req_b] req_w=[list(accumulate(req))for req in req_w] req_b=[list(accumulate(req))for req in zip(*req_b)] req_w=[list(accumulate(req))for req in zip(*req_w)] ans=0 kb,kw=req_b[-1],req_w[-1] for dx,(dx_b,dx_w)in enumerate(zip(req_b,req_w)): dxk_b=dx_b[-1] dxk_w=dx_w[-1] for b1,w1,kyb,kyw in zip(dx_b,dx_w,kb,kw): b=bc-kyb-dxk_b+b1*2 w=wc-kyw-dxk_w+w1*2 a=b+wc-w ans=max(ans,a,n-a) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k2 : double := k * 2 ; var req_b : Sequence := Integer.subrange(0, k-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, k))) ; var req_w : Sequence := Integer.subrange(0, k-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, k))) ; var bc : OclAny := null; var wc : OclAny := null; Sequence{bc,wc} := Sequence{0,0} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; var c : OclAny := null; Sequence{x,y,c} := input().split() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{("" + ((x)))->toInteger(),("" + ((y)))->toInteger()} ; var rx : OclAny := null; var ry : OclAny := null; Sequence{rx,ry} := Sequence{x mod k2,y mod k2} ; var b : boolean := c = 'B' ; if (rx->compareTo(k)) >= 0 then ( rx := rx - k ; if (ry->compareTo(k)) >= 0 then ( ry := ry - k ) else ( b := not(b) ) ) else (if (ry->compareTo(k)) >= 0 then ( ry := ry - k ; b := not(b) ) else skip) ; if b then ( req_b[rx+1][ry+1] := req_b[rx+1][ry+1] + 1 ; bc := bc + 1 ) else ( req_w[rx+1][ry+1] := req_w[rx+1][ry+1] + 1 ; wc := wc + 1 )) ; req_b := req_b->select(req | true)->collect(req | ((accumulate(req)))) ; req_w := req_w->select(req | true)->collect(req | ((accumulate(req)))) ; req_b := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name req_b)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name req_b)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name req_b)))))))`third->at(_indx)} )->select(req | true)->collect(req | ((accumulate(req)))) ; req_w := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name req_w)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name req_w)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name req_w)))))))`third->at(_indx)} )->select(req | true)->collect(req | ((accumulate(req)))) ; var ans : int := 0 ; var kb : OclAny := null; var kw : OclAny := null; Sequence{kb,kw} := Sequence{req_b->last(),req_w->last()} ; for _tuple : Integer.subrange(1, (Integer.subrange(1, req_b->size())->collect( _indx | Sequence{req_b->at(_indx), req_w->at(_indx)} ))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(1, req_b->size())->collect( _indx | Sequence{req_b->at(_indx), req_w->at(_indx)} ))->at(_indx)} ) do (var _indx : int := 1; var dx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{dx_b, dx_w} : OclAny := _tuple->at(_indx); var dxk_b : OclAny := dx_b->last() ; var dxk_w : OclAny := dx_w->last() ; for _tuple : Integer.subrange(1, dx_b->size())->collect( _indx | Sequence{dx_b->at(_indx), dx_w->at(_indx)} ) do (var _indx : int := 1; var b1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var w1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var kyb : OclAny := _tuple->at(_indx); _indx := _indx + 1; var kyw : OclAny := _tuple->at(_indx); b := bc - kyb - dxk_b + b1 * 2 ; var w : double := wc - kyw - dxk_w + w1 * 2 ; var a : double := b + wc - w ; ans := Set{ans, a, n - a}->max())) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calc(K,xyc): K2=K*2 N=len(xyc) p=[[0]*K2 for i in range(K2)] for x,y,c in xyc : y+=c*K p[x % K2][y % K2]+=1 p[(x+K)% K2][(y+K)% K2]+=1 def isum(xs): r=0 yield r for x in xs : r+=x yield r psum=[list(isum(row))for row in p] pksum=[[b-a for a,b in zip(row,row[K :])]for row in psum] rmax=N/2 for y in range(K): rcount=sum(row[y]for row in pksum[: K]) for x in range(K): rmax=max(rmax,rcount,N-rcount) rcount+=-pksum[x][y]+pksum[x+K][y] return rmax if __name__=='__main__' : N,K=[int(e)for e in input().split()] xyc=[(int(x),int(y),c=="W")for x,y,c in[input().split()for i in range(N)]] print(calc(K,xyc)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( Sequence{N,K} := input().split()->select(e | true)->collect(e | (("" + ((e)))->toInteger())) ; xyc := Integer.subrange(0, N-1)->select(i | true)->collect(i | (input().split()))->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (Sequence{("" + ((x)))->toInteger(), ("" + ((y)))->toInteger(), c = "W"})) ; execute (calc(K, xyc))->display() ) else skip; operation calc(K : OclAny, xyc : OclAny) : OclAny pre: true post: true activity: var K2 : double := K * 2 ; var N : int := (xyc)->size() ; var p : Sequence := Integer.subrange(0, K2-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, K2))) ; for _tuple : xyc do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); y := y + c * K ; p[x mod K2+1][y mod K2+1] := p[x mod K2+1][y mod K2+1] + 1 ; p[(x + K) mod K2+1][(y + K) mod K2+1] := p[(x + K) mod K2+1][(y + K) mod K2+1] + 1) ; skip ; var psum : Sequence := p->select(row | true)->collect(row | ((isum(row)))) ; var pksum : Sequence := psum->select(row | true)->collect(row | (Integer.subrange(1, row->size())->collect( _indx | Sequence{row->at(_indx), row.subrange(K+1)->at(_indx)} )->select(_tuple | true)->collect(_tuple | let a : OclAny = _tuple->at(1) in let b : OclAny = _tuple->at(2) in (b - a)))) ; var rmax : double := N / 2 ; for y : Integer.subrange(0, K-1) do ( var rcount : OclAny := ((argument (test (logical_test (comparison (expr (atom (name row)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ])))))) (comp_for for (exprlist (expr (atom (name row)))) in (logical_test (comparison (expr (atom (name pksum)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name K)))))))) ]))))))))->sum() ; for x : Integer.subrange(0, K-1) do ( rmax := Set{rmax, rcount, N - rcount}->max() ; rcount := rcount + -pksum[x+1][y+1] + pksum[x + K+1][y+1])) ; return rmax; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from numpy import*; N,K=map(int,input().split()); m,L,o=zeros((3*K,3*K)),2*K,0 for _ in[0]*N : x,y,c=input().split(); t=c=='W' ; m[int(x)% L,int(y)% L]+=2*t-1 ; o+=t for _ in[0,0]: m[L :]=m[: K]; m=cumsum(m,0); m[: L]-=m[K :]; m=m.T m=m[: L,: L]; print(o-int((m+roll(roll(m,K,0),K,1)).min())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var m : OclAny := null; var L : OclAny := null; var o : OclAny := null; Sequence{m,L,o} := Sequence{zeros(Sequence{3 * K, 3 * K}),2 * K,0} ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, N) do ( var x : OclAny := null; var y : OclAny := null; var c : OclAny := null; Sequence{x,y,c} := input().split(); var t : boolean := c = 'W'; m[("" + ((x)))->toInteger() mod L+1][("" + ((y)))->toInteger() mod L+1] := m[("" + ((x)))->toInteger() mod L+1][("" + ((y)))->toInteger() mod L+1] + 2 * t - 1; o := o + t) ; for _anon : Sequence{0}->union(Sequence{ 0 }) do ( m.subrange(L+1) := m.subrange(1,K); var m : OclAny := cumsum(m, 0); m.subrange(1,L) := m.subrange(1,L) - m.subrange(K+1); m := m.T) ; m := m.subrange(1,L).subrange(1,L); execute (o - ("" + (((m + roll(roll(m, K, 0), K, 1))->min())))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import exit,setrecursionlimit from functools import reduce from itertools import* from collections import defaultdict from bisect import bisect def reads(): return[int(x)for x in input().split()] (N,K)=reads() L=K board=[[0]*K for _ in range(K)] NW=0 for _ in range(N): (x,y,c)=input().split() (x,y)=(int(x),int(y)) c=(x//K+y//K+int(c=="W"))& 1 (x,y)=(x % K,y % K) NW+=c board[y][x]+=1 if c==1 else-1 NB=N-NW psumr=[[0]*(K+1)for _ in range(K)] for i in range(K): for j in range(K): psumr[i][j+1]=psumr[i][j]+board[i][j] psum=[[0]*(K+1)for _ in range(K+1)] for i in range(K): for j in range(K): psum[i+1][j+1]=psum[i][j+1]+psumr[i][j+1] result=0 for i in range(K+1): for j in range(K+1): summ=psum[i][K]+psum[K][j]-2*psum[i][j] result=max(result,NB+summ,NW-summ) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var Sequence{N, K} : OclAny := reads() ; var L : OclAny := K ; var board : Sequence := Integer.subrange(0, K-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, K))) ; var NW : int := 0 ; for _anon : Integer.subrange(0, N-1) do ( ; var Sequence{x, y, c} : OclAny := input().split() ; var Sequence{x, y} : OclAny := Sequence{("" + ((x)))->toInteger(), ("" + ((y)))->toInteger()} ; var c : int := MathLib.bitwiseAnd((x div K + y div K + ("" + ((c = "W")))->toInteger()), 1)) ; Sequence{x, y} := Sequence{x mod K, y mod K}; operation reads() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=input().split(' ') a=int(a) b=int(b) if(a<=0 and b>=0)or a==0 or b==0 : print('Zero') elif a>0 and b>0 : print('Positive') else : X=(abs(a)-abs(b)) if X % 2==0 : print('Negative') else : print('Positive') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split(' ') ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; if (a <= 0 & b >= 0) or a = 0 or b = 0 then ( execute ('Zero')->display() ) else (if a > 0 & b > 0 then ( execute ('Positive')->display() ) else ( var X : double := ((a)->abs() - (b)->abs()) ; if X mod 2 = 0 then ( execute ('Negative')->display() ) else ( execute ('Positive')->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,input().split()) dK=2*K MeetDemand=[[0 for y in range(dK+1)]for x in range(K+1)] for i in range(N): x,y,c=input().split() x=int(x)% dK y=(int(y)+K if c=="W" else int(y))% dK if K<=x : if 0<=ycollect( _x | (OclType["int"])->apply(_x) ) ; var dK : double := 2 * K ; var MeetDemand : Sequence := Integer.subrange(0, K + 1-1)->select(x | true)->collect(x | (Integer.subrange(0, dK + 1-1)->select(y | true)->collect(y | (0)))) ; for i : Integer.subrange(0, N-1) do ( var x : OclAny := null; var y : OclAny := null; var c : OclAny := null; Sequence{x,y,c} := input().split() ; var x : int := ("" + ((x)))->toInteger() mod dK ; var y : int := (if c = "W" then ("" + ((y)))->toInteger() + K else ("" + ((y)))->toInteger() endif) mod dK ; if (K->compareTo(x)) <= 0 then ( if 0 <= y & (y < K) then ( x := x - K ; y := y + K ) else ( x := x mod K ; y := y mod K ) ) else skip ; if 0 <= y & (y < K) then ( MeetDemand->first()->first() := MeetDemand->first()->first() + 1 ; MeetDemand[x + 1+1][y + 1+1] := MeetDemand[x + 1+1][y + 1+1] + 2 ; MeetDemand->first()[y + 1+1] := MeetDemand->first()[y + 1+1] - 1 ; MeetDemand[x + 1+1]->first() := MeetDemand[x + 1+1]->first() - 1 ; MeetDemand->first()[y + K + 1+1] := MeetDemand->first()[y + K + 1+1] + 1 ; MeetDemand[x + 1+1][y + K + 1+1] := MeetDemand[x + 1+1][y + K + 1+1] - 2 ) else ( MeetDemand->first()[y - K + 1+1] := MeetDemand->first()[y - K + 1+1] + 1 ; MeetDemand[x + 1+1][y - K + 1+1] := MeetDemand[x + 1+1][y - K + 1+1] - 2 ; MeetDemand[x + 1+1]->first() := MeetDemand[x + 1+1]->first() + 1 ; MeetDemand->first()[y + 1+1] := MeetDemand->first()[y + 1+1] - 1 ; MeetDemand[x + 1+1][y + 1+1] := MeetDemand[x + 1+1][y + 1+1] + 2 )) ; for x : Integer.subrange(0, K-1) do ( for y : Integer.subrange(1, dK-1) do ( MeetDemand[x+1][y+1] := MeetDemand[x+1][y+1] + MeetDemand[x+1][y - 1+1])) ; for y : Integer.subrange(0, dK-1) do ( for x : Integer.subrange(1, K-1) do ( MeetDemand[x+1][y+1] := MeetDemand[x+1][y+1] + MeetDemand[x - 1+1][y+1])) ; var Ans : OclAny := (MeetDemand->first().subrange(1,dK))->max() ; for i : Integer.subrange(1, K-1) do ( Ans := Set{Ans, (MeetDemand[i+1].subrange(1,dK))->max()}->max()) ; execute (Ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=10000 prefix=[0]*(MAX+1) def buildPrefix(): prime=[1]*(MAX+1) p=2 while(p*p<=MAX): if(prime[p]==1): i=p*2 while(i<=MAX): prime[i]=0 i+=p p+=1 for p in range(2,MAX+1): prefix[p]=prefix[p-1] if(prime[p]==1): prefix[p]+=1 def query(L,R): return prefix[R]-prefix[L-1] if __name__=='__main__' : buildPrefix() L=5 R=10 print(query(L,R)) L=1 R=10 print(query(L,R)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 10000 ; var prefix : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX + 1)) ; skip ; skip ; if __name__ = '__main__' then ( buildPrefix() ; L := 5 ; R := 10 ; execute (query(L, R))->display() ; L := 1 ; R := 10 ; execute (query(L, R))->display() ) else skip; operation buildPrefix() pre: true post: true activity: var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (MAX + 1)) ; var p : int := 2 ; while ((p * p->compareTo(MAX)) <= 0) do ( if (prime[p+1] = 1) then ( var i : int := p * 2 ; while ((i->compareTo(MAX)) <= 0) do ( prime[i+1] := 0 ; i := i + p) ) else skip ; p := p + 1) ; for p : Integer.subrange(2, MAX + 1-1) do ( prefix[p+1] := prefix[p - 1+1] ; if (prime[p+1] = 1) then ( prefix[p+1] := prefix[p+1] + 1 ) else skip); operation query(L : OclAny, R : OclAny) : OclAny pre: true post: true activity: return prefix[R+1] - prefix[L - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.readline()[:-1] n=int(input()) p=[None]+list(map(float,input().split())) q=list(map(float,input().split())) T=[[500 for i in range(n+1)]for j in range(n+1)] psum=[0]*(n+1) qsum=[0]*(n+1) qsum[0]=q[0] for i in range(1,n+1): psum[i]=psum[i-1]+p[i] qsum[i]=qsum[i-1]+q[i] for i in range(1,n+1): T[i][i]=p[i]+(q[i-1]+q[i])*2 for l in range(2,n+1): for i in range(1,n-l+1+1): val_list=[T[i][j]+T[j+2][i+l-1]for j in range(i,i+l-2)] val_list.append(T[i][i+l-2]+q[i+l-1]) val_list.append(T[i+1][i+l-1]+q[i-1]) if i-2>=0 : w=psum[i+l-1]-psum[i-1]+qsum[i+l-1]-qsum[i-2] else : w=psum[i+l-1]-psum[i-1]+qsum[i+l-1] T[i][i+l-1]=min(val_list)+w print(T[1][n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := Sequence{ null }->union(((input().split())->collect( _x | (OclType["double"])->apply(_x) ))) ; var q : Sequence := ((input().split())->collect( _x | (OclType["double"])->apply(_x) )) ; var T : Sequence := Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (500)))) ; var psum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var qsum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; qsum->first() := q->first() ; for i : Integer.subrange(1, n + 1-1) do ( psum[i+1] := psum[i - 1+1] + p[i+1] ; qsum[i+1] := qsum[i - 1+1] + q[i+1]) ; for i : Integer.subrange(1, n + 1-1) do ( T[i+1][i+1] := p[i+1] + (q[i - 1+1] + q[i+1]) * 2) ; for l : Integer.subrange(2, n + 1-1) do ( for i : Integer.subrange(1, n - l + 1 + 1-1) do ( var val_list : Sequence := Integer.subrange(i, i + l - 2-1)->select(j | true)->collect(j | (T[i+1][j+1] + T[j + 2+1][i + l - 1+1])) ; execute ((T[i+1][i + l - 2+1] + q[i + l - 1+1]) : val_list) ; execute ((T[i + 1+1][i + l - 1+1] + q[i - 1+1]) : val_list) ; if i - 2 >= 0 then ( var w : double := psum[i + l - 1+1] - psum[i - 1+1] + qsum[i + l - 1+1] - qsum[i - 2+1] ) else ( w := psum[i + l - 1+1] - psum[i - 1+1] + qsum[i + l - 1+1] ) ; T[i+1][i + l - 1+1] := (val_list)->min() + w)) ; execute (T[1+1][n+1])->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def optimal_cost(n,kp,dp): sums=[sum(kp[0 : i])+sum(dp[0 : i+1])for i in range(n+1)] expects=[[kp[i]+(dp[i]+dp[i+1])*2 for i in range(n)]] for w in range(2,n+1): exps=[] for i in range(n-w+1): j=i+w exp=min(dp[i]+expects[j-i-2][i+1],expects[j-i-2][i]+dp[j]) for k in range(i+1,j-1): _exp=expects[k-i-1][i]+expects[j-k-2][k+1] if exp>_exp : exp=_exp exps.append(exp+sums[j]-sums[i]+dp[i]) expects.append(exps) return expects[-1][0] def run(): n=int(input()) ps=[float(x)for x in input().split()] qs=[float(x)for x in input().split()] print("{:.8f}".format(optimal_cost(n,ps,qs))) if __name__=='__main__' : run() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( run() ) else skip; operation optimal_cost(n : OclAny, kp : OclAny, dp : OclAny) : OclAny pre: true post: true activity: var sums : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | ((kp.subrange(0+1, i))->sum() + (dp.subrange(0+1, i + 1))->sum())) ; var expects : Sequence := Sequence{ Integer.subrange(0, n-1)->select(i | true)->collect(i | (kp[i+1] + (dp[i+1] + dp[i + 1+1]) * 2)) } ; for w : Integer.subrange(2, n + 1-1) do ( var exps : Sequence := Sequence{} ; for i : Integer.subrange(0, n - w + 1-1) do ( var j : OclAny := i + w ; var exp : OclAny := Set{dp[i+1] + expects[j - i - 2+1][i + 1+1], expects[j - i - 2+1][i+1] + dp[j+1]}->min() ; for k : Integer.subrange(i + 1, j - 1-1) do ( var _exp : OclAny := expects[k - i - 1+1][i+1] + expects[j - k - 2+1][k + 1+1] ; if (exp->compareTo(_exp)) > 0 then ( exp := _exp ) else skip) ; execute ((exp + sums[j+1] - sums[i+1] + dp[i+1]) : exps)) ; execute ((exps) : expects)) ; return expects->last()->first(); operation run() pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ps : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())) ; var qs : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())) ; execute (StringLib.interpolateStrings("{:.8f}", Sequence{optimal_cost(n, ps, qs)}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) A=[0.0]+[float(i)for i in input().split()] B=[float(i)for i in input().split()] W={} E={} for i in range(1,n+2): W[i,i-1]=B[i-1] E[i,i-1]=B[i-1],i for i in range(1,n+1): for j in range(i,n+1): W[i,j]=W[i,j-1]+A[j]+B[j] for i in range(1,n+1): E[i,i]=E[i,i-1][0]+E[i+1,i][0]+W[i,i],i for h in range(1,n): for i in range(1,n-h+1): e=1001,None j=i+h k0=E[i,j-1][1] k1=E[i+1,j][1] for r in range(k0,k1+1): tmp=E[i,r-1][0]+E[r+1,j][0]+W[i,j] if tmptoInteger() ; var A : Sequence := Sequence{ 0.0 }->union(input().split()->select(i | true)->collect(i | (("" + ((i)))->toReal()))) ; var B : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toReal())) ; var W : OclAny := Set{} ; var E : OclAny := Set{} ; for i : Integer.subrange(1, n + 2-1) do ( W[i+1][i - 1+1] := B[i - 1+1] ; E[i+1][i - 1+1] := B[i - 1+1],i) ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(i, n + 1-1) do ( W[i+1][j+1] := W[i+1][j - 1+1] + A[j+1] + B[j+1])) ; for i : Integer.subrange(1, n + 1-1) do ( E[i+1][i+1] := E[i+1][i - 1+1]->first() + E[i + 1+1][i+1]->first() + W[i+1][i+1],i) ; for h : Integer.subrange(1, n-1) do ( for i : Integer.subrange(1, n - h + 1-1) do ( var e : OclAny := 1001,null ; var j : OclAny := i + h ; var k0 : OclAny := E[i+1][j - 1+1][1+1] ; var k1 : OclAny := E[i + 1+1][j+1][1+1] ; for r : Integer.subrange(k0, k1 + 1-1) do ( var tmp : OclAny := E[i+1][r - 1+1]->first() + E[r + 1+1][j+1]->first() + W[i+1][j+1] ; if (tmp->compareTo(e->first())) < 0 then ( e := tmp,r ) else skip) ; E[i+1][j+1] := e)) ; execute (E[1+1][n+1]->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): L,v,l,r=map(int,input().split()) print(L//v-(r//v-(l-1)//v)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var L : OclAny := null; var v : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{L,v,l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (L div v - (r div v - (l - 1) div v))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline write=sys.stdout.write N=int(readline()) *P,=map(float,readline().split()) *Q,=map(float,readline().split()) K=[[None]*(N+1)for i in range(N+1)] C=[[None]*(N+1)for i in range(N+1)] S=[0]*(2*N+2) for i in range(2*N+1): S[i+1]=S[i]+(P[i//2]if i % 2 else Q[i//2]) for i in range(N+1): C[i][i]=Q[i] K[i][i]=i for l in range(1,N+1): for i in range(N+1-l): j=i+l k0=K[i][j-1]; k1=K[i+1][j] tmp=1e30 k2=None for k in range(k0,min(k1+1,j)): v=C[i][k]+C[k+1][j] if vtoInteger() ; (testlist_star_expr (star_expr * (expr (atom (name P)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name P)))) ,)} := (readline().split())->collect( _x | (OclType["double"])->apply(_x) ) ; (testlist_star_expr (star_expr * (expr (atom (name Q)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name Q)))) ,)} := (readline().split())->collect( _x | (OclType["double"])->apply(_x) ) ; var K : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ null }, (N + 1)))) ; var C : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ null }, (N + 1)))) ; var S : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * N + 2)) ; for i : Integer.subrange(0, 2 * N + 1-1) do ( S[i + 1+1] := S[i+1] + (if i mod 2 then P[i div 2+1] else Q[i div 2+1] endif)) ; for i : Integer.subrange(0, N + 1-1) do ( C[i+1][i+1] := Q[i+1] ; K[i+1][i+1] := i) ; for l : Integer.subrange(1, N + 1-1) do ( for i : Integer.subrange(0, N + 1 - l-1) do ( var j : OclAny := i + l ; var k0 : OclAny := K[i+1][j - 1+1]; var k1 : OclAny := K[i + 1+1][j+1] ; var tmp : double := ("1e30")->toReal() ; var k2 : OclAny := null ; for k : Integer.subrange(k0, Set{k1 + 1, j}->min()-1) do ( var v : OclAny := C[i+1][k+1] + C[k + 1+1][j+1] ; if (v->compareTo(tmp)) < 0 then ( k2 := k ; tmp := v ) else skip) ; K[i+1][j+1] := k2 ; C[i+1][j+1] := tmp + (S[2 * j + 1+1] - S[2 * i+1]))) ; write(StringLib.format("%.10f\n",C->first()[N+1])); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): inf=10*6 n=int(input()) P=[0.0]+list(map(float,input().split())) Q=list(map(float,input().split())) E=[[0.0]*(n+1)for _ in range(n+1)] W=[[0.0]*(n+1)for _ in range(n+1)] for i in range(1,n+1): W[i][i]=Q[i-1]+P[i]+Q[i] E[i][i]=P[i]+(Q[i-1]+Q[i])*2 for i in range(1,n+1): for j in range(i+1,n+1): W[i][j]=W[i][j-1]+P[j]+Q[j] for d in range(1,n): for i in range(1,n-d+1): j=i+d e=Q[i-1]+E[i+1][j]+W[i][j] for k in range(i+1,j): ne=E[i][k-1]+E[k+1][j]+W[i][j] if netoInteger() ; var P : Sequence := Sequence{ 0.0 }->union(((input().split())->collect( _x | (OclType["double"])->apply(_x) ))) ; var Q : Sequence := ((input().split())->collect( _x | (OclType["double"])->apply(_x) )) ; var E : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0.0 }, (n + 1)))) ; var W : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0.0 }, (n + 1)))) ; for i : Integer.subrange(1, n + 1-1) do ( W[i+1][i+1] := Q[i - 1+1] + P[i+1] + Q[i+1] ; E[i+1][i+1] := P[i+1] + (Q[i - 1+1] + Q[i+1]) * 2) ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(i + 1, n + 1-1) do ( W[i+1][j+1] := W[i+1][j - 1+1] + P[j+1] + Q[j+1])) ; for d : Integer.subrange(1, n-1) do ( for i : Integer.subrange(1, n - d + 1-1) do ( var j : OclAny := i + d ; var e : OclAny := Q[i - 1+1] + E[i + 1+1][j+1] + W[i+1][j+1] ; for k : Integer.subrange(i + 1, j-1) do ( var ne : OclAny := E[i+1][k - 1+1] + E[k + 1+1][j+1] + W[i+1][j+1] ; if (ne->compareTo(e)) < 0 then ( e := ne ) else skip) ; ne := E[i+1][j - 1+1] + Q[j+1] + W[i+1][j+1] ; if (ne->compareTo(e)) < 0 then ( e := ne ) else skip ; E[i+1][j+1] := e)) ; execute (E[1+1]->last())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def leastValue(P,A,N,a): ans=-1 tmp=float('inf') for i in range(N): t=P-a[i]*0.006 if abs(t-A)union(Sequence{ 2000 }) ; execute (leastValue(P, A, N, a))->display(); operation leastValue(P : OclAny, A : OclAny, N : OclAny, a : OclAny) : OclAny pre: true post: true activity: var ans : int := -1 ; var tmp : double := ("" + (('inf')))->toReal() ; for i : Integer.subrange(0, N-1) do ( var t : double := P - a[i+1] * 0.006 ; if ((t - A)->abs()->compareTo(tmp)) < 0 then ( tmp := (t - A)->abs() ; ans := i ) else skip) ; return a[ans+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printAllAPTriplets(arr,n): s=[]; for i in range(0,n-1): for j in range(i+1,n): diff=arr[j]-arr[i]; if((arr[i]-diff)in arr): print("{}{}{}".format((arr[i]-diff),arr[i],arr[j]),end="\n"); s.append(arr[i]); arr=[2,6,9,12,17,22,31,32,35,42]; n=len(arr); printAllAPTriplets(arr,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{6}->union(Sequence{9}->union(Sequence{12}->union(Sequence{17}->union(Sequence{22}->union(Sequence{31}->union(Sequence{32}->union(Sequence{35}->union(Sequence{ 42 }))))))))); ; n := (arr)->size(); ; printAllAPTriplets(arr, n);; operation printAllAPTriplets(arr : OclAny, n : OclAny) pre: true post: true activity: var s : Sequence := Sequence{}; ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(i + 1, n-1) do ( var diff : double := arr[j+1] - arr[i+1]; ; if ((arr)->includes((arr[i+1] - diff))) then ( execute (StringLib.interpolateStrings("{}{}{}", Sequence{(arr[i+1] - diff), arr[i+1], arr[j+1]}))->display(); ) else skip)) ; execute ((arr[i+1]) : s);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def firstSetBit(n): x=n &(n-1) return(n ^ x) n=12 print(firstSetBit(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 12 ; execute (firstSetBit(n))->display(); operation firstSetBit(n : OclAny) : OclAny pre: true post: true activity: var x : int := MathLib.bitwiseAnd(n, (n - 1)) ; return (MathLib.bitwiseXor(n, x)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,z=input().split() n,z=int(n),int(z) a=input().split() ans=int(a[0]) for i in range(n): ans=max(ans,int(a[i])| z) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var z : OclAny := null; Sequence{n,z} := input().split() ; var n : OclAny := null; var z : OclAny := null; Sequence{n,z} := Sequence{("" + ((n)))->toInteger(),("" + ((z)))->toInteger()} ; var a : OclAny := input().split() ; var ans : int := ("" + ((a->first())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( ans := Set{ans, MathLib.bitwiseOr(("" + ((a[i+1])))->toInteger(), z)}->max()) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : n,z=list(map(int,input().split(" "))) a=list(map(int,input().split(" "))) ans=0 for i in a : y=i | z ans=max(ans,y) print(ans) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( var n : OclAny := null; var z : OclAny := null; Sequence{n,z} := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : a do ( var y : int := MathLib.bitwiseOr(i, z) ; ans := Set{ans, y}->max()) ; execute (ans)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for loop in range(int(input())): n,z=[int(x)for x in input().split()] a=[int(x)for x in input().split()] m=max(a) for i in range(n): a[i]=a[i]| z print(max(m,max(a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for loop : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var z : OclAny := null; Sequence{n,z} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var m : OclAny := (a)->max() ; for i : Integer.subrange(0, n-1) do ( a[i+1] := MathLib.bitwiseOr(a[i+1], z)) ; execute (Set{m, (a)->max()}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : t=int(input()) while t : n,z=map(int,input().split()) lst=list(map(int,input().split())) for i in range(n): lst[i]=lst[i]| z z=z & lst[i] print(max(lst)) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( var n : OclAny := null; var z : OclAny := null; Sequence{n,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( lst[i+1] := MathLib.bitwiseOr(lst[i+1], z) ; var z : int := MathLib.bitwiseAnd(z, lst[i+1])) ; execute ((lst)->max())->display() ; t := t - 1) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): l,z=map(int,input().split()) a=map(int,input().split()) mx=0 for i in a : if i | z>mx : mx=i | z print(mx) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var l : OclAny := null; var z : OclAny := null; Sequence{l,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mx : int := 0 ; for i : a do ( if (MathLib.bitwiseOr(i, z)->compareTo(mx)) > 0 then ( mx := MathLib.bitwiseOr(i, z) ) else skip) ; execute (mx)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countOccurrence(n,arr,k): ans=0 ; hash=dict.fromkeys(arr,0); occurrence=dict.fromkeys(arr,0); for i in range(n-1,-1,-1): if(hash[arr[i]]==True): continue ; if(occurrence[arr[i]]>=k): ans+=1 ; hash[arr[i]]=True ; else : occurrence[arr[i]]+=1 ; return ans ; if __name__=="__main__" : arr=[1,2,1,3]; n=len(arr); k=1 ; print(countOccurrence(n,arr,k)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{ 3 }))); ; n := (arr)->size(); ; k := 1; ; execute (countOccurrence(n, arr, k))->display(); ) else skip; operation countOccurrence(n : OclAny, arr : OclAny, k : OclAny) pre: true post: true activity: var ans : int := 0; ; var hash : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))); ; var occurrence : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))); ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (hash[arr[i+1]+1] = true) then ( continue; ) else skip ; if ((occurrence[arr[i+1]+1]->compareTo(k)) >= 0) then ( ans := ans + 1; ; hash[arr[i+1]+1] := true; ) else ( occurrence[arr[i+1]+1] := occurrence[arr[i+1]+1] + 1; )) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys m=int(input()) for _ in range(m): n,t,l,r=map(int,sys.stdin.readline().split()) l-=1 ans=n//t l1=l//t r1=r//t p=r1-l1 print(ans-p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, m-1) do ( var n : OclAny := null; var t : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{n,t,l,r} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; l := l - 1 ; var ans : int := n div t ; var l1 : int := l div t ; var r1 : int := r div t ; var p : double := r1 - l1 ; execute (ans - p)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printArr(arr,n): for i in range(n): print(arr[i],end=" ") def pushBinaryToBorder(arr,n): count1=0 for i in range(n): if(arr[i]!=1): arr[count1]=arr[i] count1+=1 while(count1=0): arr[lastNonOne]=0 lastNonOne-=1 if __name__=="__main__" : arr=[1,2,0,0,0,3,6]; n=len(arr); pushBinaryToBorder(arr,n) printArr(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{3}->union(Sequence{ 6 })))))); ; n := (arr)->size(); ; pushBinaryToBorder(arr, n) ; printArr(arr, n) ) else skip; operation printArr(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); operation pushBinaryToBorder(arr : OclAny, n : OclAny) pre: true post: true activity: var count1 : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] /= 1) then ( arr[count1+1] := arr[i+1] ; count1 := count1 + 1 ) else skip) ; while ((count1->compareTo(n)) < 0) do ( arr[count1+1] := 1 ; count1 := count1 + 1) ; var lastNonOne : int := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (arr[i+1] = 1) then ( continue ) else skip ; if (not(lastNonOne)) then ( lastNonOne := i ) else skip ; if (arr[i+1] /= 0) then ( arr[lastNonOne+1] := arr[i+1] ; lastNonOne := lastNonOne - 1 ) else skip) ; while (lastNonOne >= 0) do ( arr[lastNonOne+1] := 0 ; lastNonOne := lastNonOne - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,m=list(map(int,input().split())) f=False for i in range(1000): p=a % m a+=p if p==0 : f=True break if f : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var m : OclAny := null; Sequence{a,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var f : boolean := false ; for i : Integer.subrange(0, 1000-1) do ( var p : int := a mod m ; a := a + p ; if p = 0 then ( f := true ; break ) else skip) ; if f then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): a,m=[int(x)for x in input().split(" ")] for i in range(0,10000): if a % m==0 : print("Yes") exit() a=a+a % m print("No") main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var a : OclAny := null; var m : OclAny := null; Sequence{a,m} := input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for i : Integer.subrange(0, 10000-1) do ( if a mod m = 0 then ( execute ("Yes")->display() ; exit() ) else skip ; var a : OclAny := a + a mod m) ; execute ("No")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_CHAR=256 def maximumChars(str1): n=len(str1) res=-1 firstInd=[-1 for i in range(MAX_CHAR)] for i in range(n): first_ind=firstInd[ord(str1[i])] if(first_ind==-1): firstInd[ord(str1[i])]=i else : res=max(res,abs(i-first_ind-1)) return res str1="abba" print(maximumChars(str1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_CHAR : int := 256 ; skip ; str1 := "abba" ; execute (maximumChars(str1))->display(); operation maximumChars(str1 : OclAny) : OclAny pre: true post: true activity: var n : int := (str1)->size() ; var res : int := -1 ; var firstInd : Sequence := Integer.subrange(0, MAX_CHAR-1)->select(i | true)->collect(i | (-1)) ; for i : Integer.subrange(0, n-1) do ( var first_ind : OclAny := firstInd[(str1[i+1])->char2byte()+1] ; if (first_ind = -1) then ( firstInd[(str1[i+1])->char2byte()+1] := i ) else ( res := Set{res, (i - first_ind - 1)->abs()}->max() )) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def producaoPara(a,m): for i in range(10000): if a % m==0 : return "Yes" a+=a % m return "No" a,m=map(int,input().split()) print(producaoPara(a,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{a,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (producaoPara(a, m))->display(); operation producaoPara(a : OclAny, m : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, 10000-1) do ( if a mod m = 0 then ( return "Yes" ) else skip ; a := a + a mod m) ; return "No"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def producaoPara(a,m): for i in range(10000): if a % m==0 : return "Yes" a+=a % m return "No" a,m=map(int,input().split()) print(producaoPara(a,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{a,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (producaoPara(a, m))->display(); operation producaoPara(a : OclAny, m : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, 10000-1) do ( if a mod m = 0 then ( return "Yes" ) else skip ; a := a + a mod m) ; return "No"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): a,m=map(int,input().split()) visited=set() while a not in visited : visited.add(a) a+=a % m a %=m if a==0 : print("Yes") return ; print("No") def main(): t=1 for _ in range(t): solution() import sys import threading sys.setrecursionlimit(1<<30) threading.stack_size(1<<27) thread=threading.Thread(target=main) thread.start(); thread.join() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1 * (2->pow(30))) ; threading.stack_size(1 * (2->pow(27))) ; var thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ; thread.start(); thread.join(); operation solution() : OclAny pre: true post: true activity: var a : OclAny := null; var m : OclAny := null; Sequence{a,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var visited : Set := Set{}->union(()) ; while (visited)->excludes(a) do ( execute ((a) : visited) ; a := a + a mod m ; a := a mod m ; if a = 0 then ( execute ("Yes")->display() ; return; ) else skip) ; execute ("No")->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def longestInteger(s,length): count=0 maximum=0 pos=-1 l=0 for i in range(length): pre_pos=pos pre_len=l count=0 l=0 if(s[i].isdecimal()): pos=i while(s[i].isdecimal()): count+=1 i+=1 l+=1 if(count>maximum): maximum=count else : pos=pre_pos l=pre_len return(s[pos : pos+l]) s="geeks100for1234geeks" length=len(s) print(longestInteger(s,length)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := "geeks100for1234geeks" ; length := (s)->size() ; execute (longestInteger(s, length))->display(); operation longestInteger(s : OclAny, length : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var maximum : int := 0 ; var pos : int := -1 ; var l : int := 0 ; for i : Integer.subrange(0, length-1) do ( var pre_pos : int := pos ; var pre_len : int := l ; count := 0 ; l := 0 ; if (s[i+1]->matches("[0-9]*")) then ( pos := i ) else skip ; while (s[i+1]->matches("[0-9]*")) do ( count := count + 1 ; i := i + 1 ; l := l + 1) ; if ((count->compareTo(maximum)) > 0) then ( maximum := count ) else ( pos := pre_pos ; l := pre_len )) ; return (s.subrange(pos+1, pos + l)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w=map(int,input().split()) for i in range(h): s=input() print(s) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, h-1) do ( var s : String := (OclFile["System.in"]).readLine() ; execute (s)->display() ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,radians from itertools import accumulate,permutations,combinations,product from operator import itemgetter,mul from copy import deepcopy from string import ascii_lowercase,ascii_uppercase,digits from bisect import bisect,bisect_left from fractions import gcd from heapq import heappush,heappop from functools import reduce import numpy as np def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) def ZIP(n): return zip(*(MAP()for _ in range(n))) sys.setrecursionlimit(10**9) INF=float('inf') mod=10**9+7 H,W=MAP() C=[input()for _ in range(H)] for i in range(H): print(C[i]) print(C[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := MAP() ; var C : Sequence := Integer.subrange(0, H-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; for i : Integer.subrange(0, H-1) do ( execute (C[i+1])->display() ; execute (C[i+1])->display()); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ZIP(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name MAP)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))`third->at(_indx)} ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- exec('print((input()+chr(10))*2,end="")\n'*int(input().split()[0])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: (expr (expr (atom 'print((input()+chr(10))*2,end="") ')) * (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) while n : L,v,l,r=[int(i)for i in input().split()] nbr_lan=(L)//v nbr_r=(r)//v nbr_l=(l-1)//v print(nbr_lan-nbr_r+nbr_l) n-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while n do ( var L : OclAny := null; var v : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{L,v,l,r} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var nbr_lan : int := (L) div v ; var nbr_r : int := (r) div v ; var nbr_l : int := (l - 1) div v ; execute (nbr_lan - nbr_r + nbr_l)->display() ; n := n - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def main(): H,W=map(int,input().split()) for _ in range(H): line=input() print(line) print(line) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for _anon : Integer.subrange(0, H-1) do ( var line : String := (OclFile["System.in"]).readLine() ; execute (line)->display() ; execute (line)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- nums=list(map(int,input().split())) k=[input()for i in range(nums[0])] for i in range(nums[0]): print(k[i]) print(k[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var nums : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k : Sequence := Integer.subrange(0, nums->first()-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; for i : Integer.subrange(0, nums->first()-1) do ( execute (k[i+1])->display() ; execute (k[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=map(int,input().split()) z=[] for i in range(n): z.append(list(map(int,input().split()))) z.sort() L=0 R=0 ans=0 ans1=0 while Lcollect( _x | (OclType["int"])->apply(_x) ) ; var z : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : z)) ; z := z->sort() ; var L : int := 0 ; var R : int := 0 ; var ans : int := 0 ; var ans1 : int := 0 ; while (L->compareTo(n)) < 0 & (R->compareTo(n)) < 0 do ( ans := Set{z[R+1][1+1], ans}->max() ; if ((z[L+1]->first() - z[R+1]->first())->abs()->compareTo(d)) < 0 then ( ans1 := ans1 + z[R+1][1+1] ; R := R + 1 ) else ( ans := Set{ans1, ans}->max() ; ans1 := ans1 - z[L+1][1+1] ; L := L + 1 )) ; execute (Set{ans, ans1}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys YES="YES" NO="NO" def solve(N : int,M : int,a : "List[int]",b : "List[int]"): edge_weights=[0]*(N+1) for i in range(M): edge_weights[a[i]]+=1 edge_weights[b[i]]-=1 from itertools import accumulate edge_weights=list(accumulate(edge_weights)) for i in range(N+1): if edge_weights[i]% 2==0 : continue else : print(NO) return print(YES) return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() N=int(next(tokens)) M=int(next(tokens)) a=[int()]*(M) b=[int()]*(M) for i in range(M): a[i]=int(next(tokens)) b[i]=int(next(tokens)) solve(N,M,a,b) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var YES : String := "YES" ; var NO : String := "NO" ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(N : int, M : int, a : "List[int]", b : "List[int]") pre: true post: true activity: var edge_weights : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; for i : Integer.subrange(0, M-1) do ( edge_weights[a[i+1]+1] := edge_weights[a[i+1]+1] + 1 ; edge_weights[b[i+1]+1] := edge_weights[b[i+1]+1] - 1) ; skip ; edge_weights := (accumulate(edge_weights)) ; for i : Integer.subrange(0, N + 1-1) do ( if edge_weights[i+1] mod 2 = 0 then ( continue ) else ( execute (NO)->display() ; return )) ; execute (YES)->display() ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var N : int := ("" + (((tokens).next())))->toInteger() ; var M : int := ("" + (((tokens).next())))->toInteger() ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (()))->toInteger() }, (M)) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (()))->toInteger() }, (M)) ; for i : Integer.subrange(0, M-1) do ( a[i+1] := ("" + (((tokens).next())))->toInteger() ; b[i+1] := ("" + (((tokens).next())))->toInteger()) ; solve(N, M, a, b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Imos_1 : def __init__(self,N): self.len=N self.list=[0]*(N+1) def Add(self,F,T,C=1): self.list[F]+=C self.list[T+1]-=C def Cumulative_Sum(self): Y=[0]*(self.len) S=0 for i in range(self.len): S+=self.list[i] Y[i]=S return Y N,M=map(int,input().split()) I=Imos_1(N) for _ in range(M): a,b=map(int,input().split()) a,b=min(a,b),max(a,b) I.Add(a,b-1,1) J=I.Cumulative_Sum() F=True for k in J : F &=not(k % 2) if F : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class Imos skip { static operation newImos skip() : Imos skip pre: true post: Imos skip->exists( _x | result = _x ); attribute len : OclAny := N; attribute list : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)); operation initialise(N : OclAny) : Imos operation __init__(self : OclAny, N : OclAny) pre: true post: true activity: self.len := N ; self.list := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)); pre: true post: true activity: self.len := N ; self.list := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)); return self; operation Add(F : OclAny,T : OclAny,C : int) pre: true post: true activity: self.list[F+1] := self.list[F+1] + C ; self.list[T + 1+1] := self.list[T + 1+1] - C; operation Cumulative_Sum() : OclAny pre: true post: true activity: var Y : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (self.len)) ; var S : int := 0 ; for i : Integer.subrange(0, self.len-1) do ( S := S + self.list[i+1] ; Y[i+1] := S) ; return Y; } class FromPython { operation initialise() pre: true post: true activity: skip ; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var I : Imos(Imos(Imos(Imos(Imos(Imos(ImosI.newImosI()).initialise(N).newImos(ImosI.newImosI()).initialise(N)()).initialise(N).newImos(Imos(ImosI.newImosI()).initialise(N).newImos(ImosI.newImosI()).initialise(N)()).initialise(N)()).initialise(N).newImos(Imos(Imos(ImosI.newImosI()).initialise(N).newImos(ImosI.newImosI()).initialise(N)()).initialise(N).newImos(Imos(ImosI.newImosI()).initialise(N).newImos(ImosI.newImosI()).initialise(N)()).initialise(N)()).initialise(N)()).initialise(N).newImos(Imos(Imos(Imos(ImosI.newImosI()).initialise(N).newImos(ImosI.newImosI()).initialise(N)()).initialise(N).newImos(Imos(ImosI.newImosI()).initialise(N).newImos(ImosI.newImosI()).initialise(N)()).initialise(N)()).initialise(N).newImos(Imos(Imos(ImosI.newImosI()).initialise(N).newImos(ImosI.newImosI()).initialise(N)()).initialise(N).newImos(Imos(ImosI.newImosI()).initialise(N).newImos(ImosI.newImosI()).initialise(N)()).initialise(N)()).initialise(N)()).initialise(N)()).initialise(N).newImos(Imos(Imos(Imos(Imos(ImosI.newImosI()).initialise(N).newImos(ImosI.newImosI()).initialise(N)()).initialise(N).newImos(Imos(ImosI.newImosI()).initialise(N).newImos(ImosI.newImosI()).initialise(N)()).initialise(N)()).initialise(N).newImos(Imos(Imos(ImosI.newImosI()).initialise(N).newImos(ImosI.newImosI()).initialise(N)()).initialise(N).newImos(Imos(ImosI.newImosI()).initialise(N).newImos(ImosI.newImosI()).initialise(N)()).initialise(N)()).initialise(N)()).initialise(N).newImos(Imos(Imos(Imos(ImosI.newImosI()).initialise(N).newImos(ImosI.newImosI()).initialise(N)()).initialise(N).newImos(Imos(ImosI.newImosI()).initialise(N).newImos(ImosI.newImosI()).initialise(N)()).initialise(N)()).initialise(N).newImos(Imos(Imos(ImosI.newImosI()).initialise(N).newImos(ImosI.newImosI()).initialise(N)()).initialise(N).newImos(Imos(ImosI.newImosI()).initialise(N).newImos(ImosI.newImosI()).initialise(N)()).initialise(N)()).initialise(N)()).initialise(N)()).initialise(N)()).initialise(N) := (Imos skip.newImos skip()).initialise(N) ; for _anon : Integer.subrange(0, M-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{Set{a, b}->min(),Set{a, b}->max()} ; I.Add(a, b - 1, 1)) ; var J : OclAny := I.Cumulative_Sum() ; F := true ; for k : J do ( F := F & not((k mod 2))) ; if F then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def i1(): return int(input()) def i2(): return[int(i)for i in input().split()] [n,m]=i2() e=[0 for i in range(n+1)] for i in range(m): [a,b]=i2() e[a]+=1 e[b]+=1 s="YES" for i in range(1,n+1): if e[i]% 2==1 : s="NO" print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{n}->union(Sequence{ m }) := i2() ; var e : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, m-1) do ( ; Sequence{a}->union(Sequence{ b }) := i2() ; e[a+1] := e[a+1] + 1 ; e[b+1] := e[b+1] + 1) ; var s : String := "YES" ; for i : Integer.subrange(1, n + 1-1) do ( if e[i+1] mod 2 = 1 then ( s := "NO" ) else skip) ; execute (s)->display(); operation i1() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation i2() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) info=[list(map(int,input().split()))for i in range(m)] memo={} for i in range(m): if info[i][0]not in memo : memo[info[i][0]]=1 else : memo[info[i][0]]+=1 if info[i][1]not in memo : memo[info[i][1]]=1 else : memo[info[i][1]]+=1 for i in memo : if memo[i]% 2==1 : print("NO") exit() print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var info : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var memo : OclAny := Set{} ; for i : Integer.subrange(0, m-1) do ( if (memo)->excludes(info[i+1]->first()) then ( memo[info[i+1]->first()+1] := 1 ) else ( memo[info[i+1]->first()+1] := memo[info[i+1]->first()+1] + 1 ) ; if (memo)->excludes(info[i+1][1+1]) then ( memo[info[i+1][1+1]+1] := 1 ) else ( memo[info[i+1][1+1]+1] := memo[info[i+1][1+1]+1] + 1 )) ; for i : memo do ( if memo[i+1] mod 2 = 1 then ( execute ("NO")->display() ; exit() ) else skip) ; execute ("YES")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline N,M=map(int,input().split()) AB=[[int(x)for x in input().split()]for _ in range(M)] counter=[0]*(N+1) for x,y in AB : counter[x]+=1 counter[y]+=1 answer='NO' if any(x & 1 for x in counter)else 'YES' print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var AB : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))) ; var counter : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; for _tuple : AB do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); counter[x+1] := counter[x+1] + 1 ; counter[y+1] := counter[y+1] + 1) ; var answer : String := if ((argument (test (logical_test (comparison (expr (expr (atom (name x))) & (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name counter))))))))->exists( _x | _x = true ) then 'NO' else 'YES' endif ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(m,a,b,p): for i in range(m,0,-1): for j in range(2,-~ int(i**.5)): if p[j]and i % j==0 : q=i//j if a*q<=b*j and j<=q and p[q]: print(j,q); return n=100000 p=[0]*2+[1]*(n-2) for i in range(2,-~ int(n**.5)): if p[i]: for j in range(i*i,n,i): p[j]=0 while 1 : m,a,b=map(int,input().split()) if m==0 : break f(m,a,b,p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := 100000 ; p := MatrixLib.elementwiseMult(Sequence{ 0 }, 2)->union(MatrixLib.elementwiseMult(Sequence{ 1 }, (n - 2))) ; for i : Integer.subrange(2, -MathLib.bitwiseNot(("" + (((n)->pow(.5))))->toInteger())-1) do ( if p[i+1] then ( for j : Integer.subrange(i * i, n-1)->select( $x | ($x - i * i) mod i = 0 ) do ( p[j+1] := 0) ) else skip) ; while 1 do ( Sequence{m,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if m = 0 then ( break ) else skip ; f(m, a, b, p)); operation f(m : OclAny, a : OclAny, b : OclAny, p : OclAny) pre: true post: true activity: for i : Integer.subrange(0 + 1, m)->reverse() do ( for j : Integer.subrange(2, -MathLib.bitwiseNot(("" + (((i)->pow(.5))))->toInteger())-1) do ( if p[j+1] & i mod j = 0 then ( var q : int := i div j ; if (a * q->compareTo(b * j)) <= 0 & (j->compareTo(q)) <= 0 & p[q+1] then ( execute (j)->display(); return ) else skip ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10000000) input=lambda : sys.stdin.readline().rstrip() def eratosthenes(n): prime_table=[False,False,True]+[False if i % 2!=0 else True for i in range(n-2)] i=3 primes=[] while i*i<=n : if prime_table[i]: j=i*i while j<=n : prime_table[j]=False j+=i i+=2 for i in range(len(prime_table)): if prime_table[i]: primes.append(i) return primes prime_table=eratosthenes(50001) while True : m,a,b=map(int,input().split()) if m==a==b==0 : break l=0 mx=(0,0,0) for r in range(len(prime_table)): while True : if mx[0]=a/b : mx=(prime_table[l]*prime_table[r],l,r) if prime_table[l]*prime_table[r]>m and l-1>=0 : l-=1 elif l+1<=r and(prime_table[l+1])*prime_table[r]<=m : l+=1 else : break print(prime_table[mx[1]],prime_table[mx[2]]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(10000000) ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; skip ; prime_table := eratosthenes(50001) ; while true do ( var m : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{m,a,b} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if m = a & (a == b) & (b == 0) then ( break ) else skip ; var l : int := 0 ; var mx : OclAny := Sequence{0, 0, 0} ; for r : Integer.subrange(0, (prime_table)->size()-1) do ( while true do ( if (mx->first()->compareTo(prime_table[l+1] * prime_table[r+1])) < 0 & (prime_table[l+1] * prime_table[r+1] <= m) & (prime_table[l+1] / prime_table[r+1]->compareTo(a / b)) >= 0 then ( mx := Sequence{prime_table[l+1] * prime_table[r+1], l, r} ) else skip ; if (prime_table[l+1] * prime_table[r+1]->compareTo(m)) > 0 & l - 1 >= 0 then ( l := l - 1 ) else (if (l + 1->compareTo(r)) <= 0 & ((prime_table[l + 1+1]) * prime_table[r+1]->compareTo(m)) <= 0 then ( l := l + 1 ) else ( break ) ) )) ; execute (prime_table[mx[1+1]+1])->display()); operation eratosthenes(n : OclAny) : OclAny pre: true post: true activity: var prime_table : Sequence := Sequence{false}->union(Sequence{false}->union(Sequence{ true }))->union(Integer.subrange(0, n - 2-1)->select(i | true)->collect(i | (if i mod 2 /= 0 then false else true endif))) ; var i : int := 3 ; var primes : Sequence := Sequence{} ; while (i * i->compareTo(n)) <= 0 do ( if prime_table[i+1] then ( var j : int := i * i ; while (j->compareTo(n)) <= 0 do ( prime_table[j+1] := false ; j := j + i) ) else skip ; i := i + 2) ; for i : Integer.subrange(0, (prime_table)->size()-1) do ( if prime_table[i+1] then ( execute ((i) : primes) ) else skip) ; return primes; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(m,a,b): ans=[0,0,0] for x in p : for y in p : if x*y>m : break if 1>=x/y>=a/b and x*y>ans[0]: ans=[x*y,x,y] print(ans[1],ans[2]) def primes(n): n,correction=n-n % 6+6,2-(n % 6>1) sieve=[True]*(n//3) for i in range(1,int(n**0.5)//3+1): if sieve[i]: k=3*i+1 | 1 sieve[k*k//3 : : 2*k]=[False]*((n//6-k*k//6-1)//k+1) sieve[k*(k-2*(i & 1)+4)//3 : : 2*k]=[False]*((n//6-k*(k-2*(i & 1)+4)//6-1)//k+1) return[2,3]+[3*i+1 | 1 for i in range(1,n//3-correction)if sieve[i]] if __name__=="__main__" : p=primes(10000) while 1 : m,a,b=map(int,input().split()) if m==a==b==0 : break else : main(m,a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var p : OclAny := primes(10000) ; while 1 do ( Sequence{m,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if m = a & (a == b) & (b == 0) then ( break ) else ( main(m, a, b) )) ) else skip; operation main(m : OclAny, a : OclAny, b : OclAny) pre: true post: true activity: var ans : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })) ; for x : p do ( for y : p do ( if (x * y->compareTo(m)) > 0 then ( break ) else skip ; if 1 >= x / y & (x / y >= a / b) & (x * y->compareTo(ans->first())) > 0 then ( ans := Sequence{x * y}->union(Sequence{x}->union(Sequence{ y })) ) else skip)) ; execute (ans[1+1])->display(); operation primes(n : OclAny) : OclAny pre: true post: true activity: var correction : OclAny := null; Sequence{n,correction} := Sequence{n - n mod 6 + 6,2 - (n mod 6 > 1)} ; var sieve : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (n div 3)) ; for i : Integer.subrange(1, ("" + (((n)->pow(0.5))))->toInteger() div 3 + 1-1) do ( if sieve[i+1] then ( var k : int := MathLib.bitwiseOr(3 * i + 1, 1) ; sieve(subscript (test (logical_test (comparison (expr (expr (expr (atom (name k))) * (expr (atom (name k)))) // (expr (atom (number (integer 3)))))))) : (sliceop : (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name k))))))))) := MatrixLib.elementwiseMult(Sequence{ false }, ((n div 6 - k * k div 6 - 1) div k + 1)) ; sieve(subscript (test (logical_test (comparison (expr (expr (expr (atom (name k))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name k))) - (expr (expr (atom (number (integer 2)))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) & (expr (atom (number (integer 1))))))))) ))))) + (expr (atom (number (integer 4))))))))) )))) // (expr (atom (number (integer 3)))))))) : (sliceop : (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name k))))))))) := MatrixLib.elementwiseMult(Sequence{ false }, ((n div 6 - k * (k - 2 * (MathLib.bitwiseAnd(i, 1)) + 4) div 6 - 1) div k + 1)) ) else skip) ; return Sequence{2}->union(Sequence{ 3 })->union(Integer.subrange(1, n div 3 - correction-1)->select(i | sieve[i+1])->collect(i | (MathLib.bitwiseOr(3 * i + 1, 1)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : a=2+2 n,k=(int(x)for x in input().split()) ans1=(2*(k-1)+(n-k))+n+(n+1) ans2=((k-1)+2*(n-k)+n+(n+1)) print(min(ans1,ans2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var a : int := 2 + 2 ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var ans1 : double := (2 * (k - 1) + (n - k)) + n + (n + 1) ; var ans2 : double := ((k - 1) + 2 * (n - k) + n + (n + 1)) ; execute (Set{ans1, ans2}->min())->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Eratosthenes(N): ans=[True for i in range(N+1)] ans[0],ans[1]=False,False for i in range(int(N**(1/2))+1): if ans[i]: for j in range(2*i,N,i): ans[j]=False return[i for i in range(N+1)if ans[i]] ans=[] while True : M,A,B=map(int,input().split()) if not M : break AdivB=A/B+0.0000001 prime_list=Eratosthenes(M) tmp_max=0 tmp_ans=[0,0] for i in range(len(prime_list)): for j in range(i+1,len(prime_list)): if prime_list[i]/prime_list[j]M : if tmp_maxcollect( _x | (OclType["int"])->apply(_x) ) ; if not(M) then ( break ) else skip ; var AdivB : double := A / B + 0.0000001 ; var prime_list : OclAny := Eratosthenes(M) ; var tmp_max : int := 0 ; var tmp_ans : Sequence := Sequence{0}->union(Sequence{ 0 }) ; for i : Integer.subrange(0, (prime_list)->size()-1) do ( for j : Integer.subrange(i + 1, (prime_list)->size()-1) do ( if (prime_list[i+1] / prime_list[j+1]->compareTo(AdivB)) < 0 or (prime_list[i+1] * prime_list[j+1]->compareTo(M)) > 0 then ( if (tmp_max->compareTo(prime_list[i+1] * prime_list[j - 1+1])) < 0 & (prime_list[i+1] * prime_list[j - 1+1]->compareTo(M)) <= 0 then ( tmp_max := prime_list[i+1] * prime_list[j - 1+1] ; tmp_ans := Sequence{prime_list[i+1]}->union(Sequence{ prime_list[j - 1+1] }) ) else skip ; break ) else skip)) ; execute ((tmp_ans) : ans)) ; ; operation Eratosthenes(N : OclAny) : OclAny pre: true post: true activity: var ans : Sequence := Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (true)) ; var ans->first() : OclAny := null; var ans[1+1] : OclAny := null; Sequence{ans->first(),ans[1+1]} := Sequence{false,false} ; for i : Integer.subrange(0, ("" + (((N)->pow((1 / 2)))))->toInteger() + 1-1) do ( if ans[i+1] then ( for j : Integer.subrange(2 * i, N-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ( ans[j+1] := false) ) else skip) ; return Integer.subrange(0, N + 1-1)->select(i | ans[i+1])->collect(i | (i)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque n,limit=[int(x)for x in input().split()] arr=[] for _ in range(n): val=[int(x)for x in input().split()] arr.append(val) arr.sort() nums=[] prefix=[] for i,j in arr : nums.append(i) prefix.append(j) i=max(prefix) j=sum(prefix) def check(mid): i=0 j=0 maxi=0 total=0 while j=mid while i<=j : mid=(i+j)//2 if check(mid): temp=mid i=mid+1 else : j=mid-1 print(temp) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var limit : OclAny := null; Sequence{n,limit} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var arr : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var val : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((val) : arr)) ; arr := arr->sort() ; var nums : Sequence := Sequence{} ; var prefix : Sequence := Sequence{} ; for _tuple : arr do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); execute ((i) : nums) ; execute ((j) : prefix)) ; var i : OclAny := (prefix)->max() ; var j : OclAny := (prefix)->sum() ; skip ; while (i->compareTo(j)) <= 0 do ( mid := (i + j) div 2 ; if check(mid) then ( var temp : OclAny := mid ; i := mid + 1 ) else ( j := mid - 1 )) ; execute (temp)->display(); operation check(mid : OclAny) : OclAny pre: true post: true activity: i := 0 ; j := 0 ; var maxi : int := 0 ; var total : int := 0 ; while (j->compareTo((nums)->size())) < 0 do ( if (nums[j+1] - nums[i+1]->compareTo(limit)) < 0 then ( total := total + prefix[j+1] ; j := j + 1 ) else ( maxi := Set{maxi, total}->max() ; if i /= j then ( total := total - prefix[i+1] ) else ( j := j + 1 ) ; i := i + 1 )) ; maxi := Set{maxi, total}->max() ; return (maxi->compareTo(mid)) >= 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def eratosthenes(n): primes=[i for i in range(n+1)] primes[1]=0 for prime in primes : if prime>math.sqrt(n): break if prime==0 : continue for non_prime in range(2*prime,n,prime): primes[non_prime]=0 prime_list=[] for prime in primes : if prime!=0 : prime_list.append(prime) return prime_list primes=eratosthenes(100000) while True : m,a,b=map(int,input().split()) if m<=4 or a==0 or b==0 : break p=0 q=0 max_s=0 for i in range(len(primes)): for j in range(i,len(primes)): if(primes[i]*primes[j]<=m)and(a/b<=primes[i]/primes[j]<=1): if primes[i]*primes[j]>=max_s : max_s=primes[i]*primes[j] p=primes[i] q=primes[j] else : break print("{0}{1}".format(p,q)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; primes := eratosthenes(100000) ; while true do ( var m : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{m,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if m <= 4 or a = 0 or b = 0 then ( break ) else skip ; var p : int := 0 ; var q : int := 0 ; var max_s : int := 0 ; for i : Integer.subrange(0, (primes)->size()-1) do ( for j : Integer.subrange(i, (primes)->size()-1) do ( if ((primes[i+1] * primes[j+1]->compareTo(m)) <= 0) & ((a / b->compareTo(primes[i+1] / primes[j+1])) <= 0 & (primes[i+1] / primes[j+1] <= 1)) then ( if (primes[i+1] * primes[j+1]->compareTo(max_s)) >= 0 then ( max_s := primes[i+1] * primes[j+1] ; p := primes[i+1] ; q := primes[j+1] ) else skip ) else ( break ))) ; execute (StringLib.interpolateStrings("{0}{1}", Sequence{p, q}))->display()); operation eratosthenes(n : OclAny) : OclAny pre: true post: true activity: var primes : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (i)) ; primes[1+1] := 0 ; for prime : primes do ( if (prime->compareTo((n)->sqrt())) > 0 then ( break ) else skip ; if prime = 0 then ( continue ) else skip ; for non_prime : Integer.subrange(2 * prime, n-1)->select( $x | ($x - 2 * prime) mod prime = 0 ) do ( primes[non_prime+1] := 0)) ; var prime_list : Sequence := Sequence{} ; for prime : primes do ( if prime /= 0 then ( execute ((prime) : prime_list) ) else skip) ; return prime_list; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import fractions def compute(): P=1009 Q=3643 TOTIENT=(P-1)*(Q-1) numunconcealedp=count_all_unconcealed(P) numunconcealedq=count_all_unconcealed(Q) minunconcealedp=min(numunconcealedp) minunconcealedq=min(numunconcealedq) ans=sum(e for e in range(TOTIENT)if numunconcealedp[e %(P-1)]==minunconcealedp and numunconcealedq[e %(Q-1)]==minunconcealedq) return str(ans) def count_all_unconcealed(prime): result=[] for e in range(prime-1): if fractions.gcd(e,prime-1)==1 : result.append(count_unconcealed(prime,e)) else : result.append(10**20) return result def count_unconcealed(modulus,e): result=0 for m in range(modulus): if pow(m,e,modulus)==m : result+=1 return result if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var P : int := 1009 ; var Q : int := 3643 ; var TOTIENT : double := (P - 1) * (Q - 1) ; var numunconcealedp : OclAny := count_all_unconcealed(P) ; var numunconcealedq : OclAny := count_all_unconcealed(Q) ; var minunconcealedp : OclAny := (numunconcealedp)->min() ; var minunconcealedq : OclAny := (numunconcealedq)->min() ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name e)))))) (comp_for for (exprlist (expr (atom (name e)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name TOTIENT)))))))) )))))) (comp_iter if (test (logical_test (logical_test (comparison (comparison (expr (atom (name numunconcealedp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name e))) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name P))) - (expr (atom (number (integer 1))))))))) ))))))))) ])))) == (comparison (expr (atom (name minunconcealedp)))))) and (logical_test (comparison (comparison (expr (atom (name numunconcealedq)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name e))) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name Q))) - (expr (atom (number (integer 1))))))))) ))))))))) ])))) == (comparison (expr (atom (name minunconcealedq))))))))))))->sum() ; return ("" + ((ans))); operation count_all_unconcealed(prime : OclAny) : OclAny pre: true post: true activity: var result : Sequence := Sequence{} ; for e : Integer.subrange(0, prime - 1-1) do ( if fractions.gcd(e, prime - 1) = 1 then ( execute ((count_unconcealed(prime, e)) : result) ) else ( execute (((10)->pow(20)) : result) )) ; return result; operation count_unconcealed(modulus : OclAny, e : OclAny) : OclAny pre: true post: true activity: result := 0 ; for m : Integer.subrange(0, modulus-1) do ( if (m)->pow(e) = m then ( result := result + 1 ) else skip) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sentence=input() sentence=sentence.swapcase() print(sentence) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sentence : String := (OclFile["System.in"]).readLine() ; sentence := StringLib.swapCase(sentence) ; execute (sentence)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- string=input() for c in string : if c>='a' and c<='z' : c=c.upper() elif c>='A' and c<='Z' : c=c.lower() print(c,end="") print("") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var string : String := (OclFile["System.in"]).readLine() ; for c : string->characters() do ( if c >= 'a' & c <= 'z' then ( var c : String := c->toUpperCase() ) else (if c >= 'A' & c <= 'Z' then ( c := c->toLowerCase() ) else skip) ; execute (c)->display()) ; execute ("")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- base=raw_input() def toggleUpLo(char): if char.isupper(): return char.lower() else : return char.upper() new_str=[toggleUpLo(c)for c in base] print(''.join(new_str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var base : OclAny := raw_input() ; skip ; var new_str : Sequence := base->select(c | true)->collect(c | (toggleUpLo(c))) ; execute (StringLib.sumStringsWithSeparator((new_str), ''))->display(); operation toggleUpLo(char : OclAny) : OclAny pre: true post: true activity: if char->matches("[A-Z ]*") then ( return char->toLowerCase() ) else ( return char->toUpperCase() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(raw_input().swapcase()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (raw_input().swapcase())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() print(a.swapcase()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; execute (StringLib.swapCase(a))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b,c,d=map(int,input().split()) print(max(a,c)if max(a,c)<=min(b,d)else a+c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if (Set{a, c}->max()->compareTo(Set{b, d}->min())) <= 0 then Set{a, c}->max() else a + c endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for _ in range(n): a,b,c,d=map(int,input().split()) if max(a,c)<=min(b,d): print(max(a,c)) else : print(a+c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (Set{a, c}->max()->compareTo(Set{b, d}->min())) <= 0 then ( execute (Set{a, c}->max())->display() ) else ( execute (a + c)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) print(3*n+min(k-1,n-k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (3 * n + Set{k - 1, n - k}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect n,d=list(map(int,input().split())) friends=[] for i in range(n): friends.append(list(map(int,input().split()))) friends.sort(key=lambda x : x[0]) prefix=[0] for f in friends : prefix.append(prefix[-1]+f[1]) res=0 for start,f in enumerate(friends): end=bisect.bisect_right(friends,[f[0]+d-1,float('inf')]) res=max(res,prefix[end]-prefix[start]) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var friends : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : friends)) ; friends := friends->sort() ; var prefix : Sequence := Sequence{ 0 } ; for f : friends do ( execute ((prefix->last() + f[1+1]) : prefix)) ; var res : int := 0 ; for _tuple : Integer.subrange(1, (friends)->size())->collect( _indx | Sequence{_indx-1, (friends)->at(_indx)} ) do (var _indx : int := 1; var start : OclAny := _tuple->at(_indx); _indx := _indx + 1; var f : OclAny := _tuple->at(_indx); var end : OclAny := bisect.bisect_right(friends, Sequence{f->first() + d - 1}->union(Sequence{ ("" + (('inf')))->toReal() })) ; res := Set{res, prefix[end+1] - prefix[start+1]}->max()) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for j in range(int(input())): l1,r1,l2,r2=list(map(int,input().split())) if l1>r2 or l2>r1 : print(l2+l1) else : print(max(l1,l2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for j : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var l1 : OclAny := null; var r1 : OclAny := null; var l2 : OclAny := null; var r2 : OclAny := null; Sequence{l1,r1,l2,r2} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (l1->compareTo(r2)) > 0 or (l2->compareTo(r1)) > 0 then ( execute (l2 + l1)->display() ) else ( execute (Set{l1, l2}->max())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input for s in[*open(0)][1 : :]: a,b,c,d=map(int,s.split()); print((max(a,c),a+c)[a>d or c>b]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop :)) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ); execute (Sequence{Set{a, c}->max(), a + c}->select((a->compareTo(d)) > 0 or (c->compareTo(b)) > 0))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): l1,r1,l2,r2=map(int,input().split()) if max(l1,l2)<=min(r1,r2): print(max(l1,l2)) else : print(l1+l2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var l1 : OclAny := null; var r1 : OclAny := null; var l2 : OclAny := null; var r2 : OclAny := null; Sequence{l1,r1,l2,r2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (Set{l1, l2}->max()->compareTo(Set{r1, r2}->min())) <= 0 then ( execute (Set{l1, l2}->max())->display() ) else ( execute (l1 + l2)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def longestRepeatedSubstring(str): n=len(str) LCSRe=[[0 for x in range(n+1)]for y in range(n+1)] res="" res_length=0 index=0 for i in range(1,n+1): for j in range(i+1,n+1): if(str[i-1]==str[j-1]and LCSRe[i-1][j-1]<(j-i)): LCSRe[i][j]=LCSRe[i-1][j-1]+1 if(LCSRe[i][j]>res_length): res_length=LCSRe[i][j] index=max(i,index) else : LCSRe[i][j]=0 if(res_length>0): for i in range(index-res_length+1,index+1): res=res+str[i-1] return res if __name__=="__main__" : str="geeksforgeeks" print(longestRepeatedSubstring(str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( OclType["String"] := "geeksforgeeks" ; execute (longestRepeatedSubstring(OclType["String"]))->display() ) else skip; operation longestRepeatedSubstring(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var n : int := (OclType["String"])->size() ; var LCSRe : Sequence := Integer.subrange(0, n + 1-1)->select(y | true)->collect(y | (Integer.subrange(0, n + 1-1)->select(x | true)->collect(x | (0)))) ; var res : String := "" ; var res_length : int := 0 ; var index : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(i + 1, n + 1-1) do ( if (("" + ([i - 1+1])) = ("" + ([j - 1+1])) & (LCSRe[i - 1+1][j - 1+1]->compareTo((j - i))) < 0) then ( LCSRe[i+1][j+1] := LCSRe[i - 1+1][j - 1+1] + 1 ; if ((LCSRe[i+1][j+1]->compareTo(res_length)) > 0) then ( res_length := LCSRe[i+1][j+1] ; index := Set{i, index}->max() ) else skip ) else ( LCSRe[i+1][j+1] := 0 ))) ; if (res_length > 0) then ( for i : Integer.subrange(index - res_length + 1, index + 1-1) do ( res := res + ("" + ([i - 1+1]))) ) else skip ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) x=list(map(int,input().split())) x=sorted([[x[i],i]for i in range(n)]) for i in range(n): x[i].append(i % 2) x.sort(key=lambda el : el[1]) print(*map(lambda el : el[2],x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; x := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{x[i+1]}->union(Sequence{ i })))->sort() ; for i : Integer.subrange(0, n-1) do ((expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) % (expr (atom (number (integer 2)))))))))) ))))) ; x := x->sort() ; execute ((argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test lambda (varargslist (vardef_parameters (vardef_parameter (name el)))) : (test (logical_test (comparison (expr (atom (name el)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))) , (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(a,q): path=[-1]*(max(a)+1) ans=[0]*len(a) q.sort() q.sort(key=lambda s : s[1]-s[0],reverse=True) a=list(zip(range(len(a)),a)) a=sorted(a,key=lambda s : s[1]) res=0 for id,val in a : ans[id]=res res ^=1 return ans n,m=map(int,input().strip().split()) q=[] a=[*map(int,input().strip().split())] for i in range(m): l,r=map(int,input().strip().split()) q.append((l,r)) print(*f(a,q)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; q := Sequence{} ; a := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, m-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{l, r}) : q)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name f)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name q)))))))) )))))))))->display(); operation f(a : OclAny, q : OclAny) : OclAny pre: true post: true activity: var path : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, ((a)->max() + 1)) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (a)->size()) ; q := q->sort() ; q := q->sort() ; a := (Integer.subrange(1, Integer.subrange(0, (a)->size()-1)->size())->collect( _indx | Sequence{Integer.subrange(0, (a)->size()-1)->at(_indx), a->at(_indx)} )) ; a := a->sortedBy($x | (lambda s : OclAny in (s[1+1]))->apply($x)) ; var res : int := 0 ; for _tuple : a do (var _indx : int := 1; var id : OclAny := _tuple->at(_indx); _indx := _indx + 1; var val : OclAny := _tuple->at(_indx); ans[id+1] := res ; res := res xor 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for e in iter(input,'0'): a=[list(map(int,input().split()))for _ in[0]*int(e)] b=[list(map(int,input().split()))for _ in[0]*int(input())] for s,t in b : u,v=a[0] x,y=s-u,t-v for u,v in a : if[u+x,v+y]not in b : break else : print(x,y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for e : OclIterator.newOclIterator_Sequence(input, '0') do ( var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + ((e)))->toInteger())->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger())->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for _tuple : b do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := a->first() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{s - u,t - v} ; (compound_stmt for (exprlist (expr (atom (name u))) , (expr (atom (name v)))) in (testlist (test (logical_test (comparison (expr (atom (name a))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom (name u))) + (expr (atom (name x))))))) , (test (logical_test (comparison (expr (expr (atom (name v))) + (expr (atom (name y)))))))) ]))) not in (comparison (expr (atom (name b))))))) : (suite (simple_stmt (small_stmt break)))))) (else_clause else : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x))))))) , (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(dx,dy): f=True for x,y in goal : if(x+dx,y+dy)not in tbl : f=False break return f while True : m=int(input()) if m==0 : break goal,star,tbl=[],[],{} for i in range(m): goal.append(tuple(map(int,input().split()))) for i in range(int(input())): x,y=map(int,input().split()) star.append((x,y)) tbl[x,y]=1 for x,y in star : dx,dy=x-goal[0][0],y-goal[0][1] if check(dx,dy): break print(dx,dy) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if m = 0 then ( break ) else skip ; var goal : OclAny := null; var star : OclAny := null; var tbl : OclAny := null; Sequence{goal,star,tbl} := Sequence{Sequence{},Sequence{},Set{}} ; for i : Integer.subrange(0, m-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : goal)) ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{x, y}) : star) ; tbl[x+1][y+1] := 1) ; for _tuple : star do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); Sequence{dx,dy} := Sequence{x - goal->first()->first(),y - goal->first()[1+1]} ; if check(dx, dy) then ( break ) else skip) ; execute (dx)->display()); operation check(dx : OclAny, dy : OclAny) : OclAny pre: true post: true activity: var f : boolean := true ; for _tuple : goal do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if (tbl)->excludes(Sequence{x + dx, y + dy}) then ( f := false ; break ) else skip) ; return f; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def searchstar(i,j): global vector global star global n flag=False for k in range(n): if star[i][0]+vector[j][0]==star[k][0]and star[i][1]+vector[j][1]==star[k][1]: flag=True break return flag while True : m=int(input()) if m==0 : break vector=[] x1,y1=map(int,input().split()) for i in range(m-1): x2,y2=map(int,input().split()) vector.append([x2-x1,y2-y1]) star=[] n=int(input()) for i in range(n): a,b=map(int,input().split()) star.append([a,b]) for i in range(n-1,-1,-1): for j in range(m-1): if not searchstar(i,j): break else : print(star[i][0]-x1,star[i][1]-y1) break ------------------------------------------------------------ OCL File: --------- class FromPython { attribute vector : OclAny; attribute star : OclAny; attribute n : OclAny; operation initialise() pre: true post: true activity: skip ; while true do ( var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if m = 0 then ( break ) else skip ; vector := Sequence{} ; var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, m - 1-1) do ( var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{x2 - x1}->union(Sequence{ y2 - y1 })) : vector)) ; star := Sequence{} ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a}->union(Sequence{ b })) : star)) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ((compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name m))) - (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test not (logical_test (comparison (expr (atom (name searchstar)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name star)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) - (expr (atom (name x1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name star)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) - (expr (atom (name y1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))); operation searchstar(i : OclAny, j : OclAny) : OclAny pre: true post: true activity: skip ; skip ; skip ; var flag : boolean := false ; for k : Integer.subrange(0, n-1) do ( if star[i+1]->first() + vector[j+1]->first() = star[k+1]->first() & star[i+1][1+1] + vector[j+1][1+1] = star[k+1][1+1] then ( flag := true ; break ) else skip) ; return flag; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(e): a=[[*map(int,input().split())]for _ in[0]*int(e)] s,t=min(a) b={tuple(map(int,input().split()))for _ in[0]*int(input())} m=max(b)[0]-max(a)[0]+s for x,y in b : if x<=m : for u,v in a : if(x+u-s,y+v-t)not in b : break else : return print(x-s,y-t) for e in iter(input,'0'): f(e) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for e : OclIterator.newOclIterator_Sequence(input, '0') do ( f(e)); operation f(e : OclAny) pre: true post: true activity: var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + ((e)))->toInteger())->select(_anon | true)->collect(_anon | ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := (a)->min() ; var b : Set := MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger())->select(_anon | true)->collect(_anon | ((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->asSet() ; var m : double := max(b)->first() - max(a)->first() + s ; for _tuple : b do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if (x->compareTo(m)) <= 0 then ( (compound_stmt for (exprlist (expr (atom (name u))) , (expr (atom (name v)))) in (testlist (test (logical_test (comparison (expr (atom (name a))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name x))) + (expr (atom (name u)))) - (expr (atom (name s))))))) , (test (logical_test (comparison (expr (expr (expr (atom (name y))) + (expr (atom (name v)))) - (expr (atom (name t)))))))) )))) not in (comparison (expr (atom (name b))))))) : (suite (simple_stmt (small_stmt break)))))) (else_clause else : (suite (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (name s)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (name t))))))))) ))))))))))))) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def printMax(arr,n,k): Qi=deque() for i in range(k): while Qi and arr[i]>=arr[Qi[-1]]: Qi.pop() Qi.append(i); for i in range(k,n): print(str(arr[Qi[0]])+"",end="") while Qi and Qi[0]<=i-k : Qi.popleft() while Qi and arr[i]>=arr[Qi[-1]]: Qi.pop() Qi.append(i) print(str(arr[Qi[0]])) if __name__=="__main__" : arr=[12,1,78,90,57,89,56] k=3 printMax(arr,len(arr),k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{12}->union(Sequence{1}->union(Sequence{78}->union(Sequence{90}->union(Sequence{57}->union(Sequence{89}->union(Sequence{ 56 })))))) ; k := 3 ; printMax(arr, (arr)->size(), k) ) else skip; operation printMax(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var Qi : Sequence := () ; for i : Integer.subrange(0, k-1) do ( while Qi & (arr[i+1]->compareTo(arr[Qi->last()+1])) >= 0 do ( Qi := Qi->front()) ; execute ((i) : Qi);) ; for i : Integer.subrange(k, n-1) do ( execute (("" + ((arr[Qi->first()+1]))) + "")->display() ; while Qi & (Qi->first()->compareTo(i - k)) <= 0 do ( Qi := Qi->tail()) ; while Qi & (arr[i+1]->compareTo(arr[Qi->last()+1])) >= 0 do ( Qi := Qi->front()) ; execute ((i) : Qi)) ; execute (("" + ((arr[Qi->first()+1]))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=map(int,input().split()) z=[] for i in range(n): z.append(list(map(int,input().split()))) z.sort() L=0 R=0 ans=0 ans1=0 while L0 : ans1-=z[L][1] L+=1 print(max(ans,ans1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var z : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : z)) ; z := z->sort() ; var L : int := 0 ; var R : int := 0 ; var ans : int := 0 ; var ans1 : int := 0 ; while (L->compareTo(n)) < 0 & (R->compareTo(n)) < 0 do ( ans := Set{z[R+1][1+1], ans}->max() ; if ((z[L+1]->first() - z[R+1]->first())->abs()->compareTo(d)) < 0 then ( ans1 := ans1 + z[R+1][1+1] ; R := R + 1 ) else ( ans := Set{ans1, ans}->max() ; if ans1 > 0 then ( ans1 := ans1 - z[L+1][1+1] ) else skip ; L := L + 1 )) ; execute (Set{ans, ans1}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os.path if(os.path.exists('input.txt')): sys.stdin=open("input.txt","r") sys.stdout=open("outpput.txt","w") n,k=map(int,input().split()) print(2*(n-1)+3+n-1+min(n-k,k-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if (os.path.exists('input.txt')) then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile("outpput.txt")) ) else skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (2 * (n - 1) + 3 + n - 1 + Set{n - k, k - 1}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- board=[[False]*1000001]*1000001 while True : m=int(input()) if m==0 : break star=list(set(tuple(tuple(map(int,input().split()))for i in range(m)))) sx,sy=star[0] n=int(input()) starlist=list(set([tuple(map(int,input().split()))for i in range(n)])) for i in range(len(starlist)): board[starlist[i][0]][starlist[i][1]]=True for i in range(n): flag=True for j in range(len(star)-1): dx=starlist[i][0]+star[j+1][0]-sx dy=starlist[i][1]+star[j+1][1]-sy if dx<0 or 1000000toInteger() ; if m = 0 then ( break ) else skip ; var star : Sequence := (Set{}->union((((argument (test (logical_test (comparison (expr (atom (name tuple)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name m)))))))) )))))))))))) ; var sx : OclAny := null; var sy : OclAny := null; Sequence{sx,sy} := star->first() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var starlist : Sequence := (Set{}->union((Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))))) ; for i : Integer.subrange(0, (starlist)->size()-1) do ( board[starlist[i+1]->first()+1][starlist[i+1][1+1]+1] := true) ; for i : Integer.subrange(0, n-1) do ( var flag : boolean := true ; for j : Integer.subrange(0, (star)->size() - 1-1) do ( var dx : double := starlist[i+1]->first() + star[j + 1+1]->first() - sx ; var dy : double := starlist[i+1][1+1] + star[j + 1+1][1+1] - sy ; if dx < 0 or 1000000 < dx or dy < 0 or 1000000 < dy or board[dx+1][dy+1] = false then ( flag := false ; break ) else skip) ; if flag = true then ( execute (StringLib.interpolateStrings("{}{}", Sequence{starlist[i+1]->first() - sx, starlist[i+1][1+1] - sy}))->display() ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findPrevious(number,n): number=list(number) i,j=-1,-1 for i in range(n-1,0,-1): if number[i]number[greatest]): greatest=j (number[greatest],number[i-1])=(number[i-1],number[greatest]) l=number[i :] del number[i :] l.sort(reverse=True) number+=l number=''.join(number) print("Greatest smaller number with","same set of digits is",number) return if __name__=="__main__" : digits="262345" n=len(digits) findPrevious(digits,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{number[greatest+1], number[i - 1+1]} := Sequence{number[i - 1+1], number[greatest+1]}; operation findPrevious(number : OclAny, n : OclAny) pre: true post: true activity: number := (number) ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{-1,-1} ; for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( if (number[i+1]->compareTo(number[i - 1+1])) < 0 then ( break ) else skip) ; if i = 0 then ( execute ("Previous number is not possible")->display() ; return ) else skip ; var x : OclAny := null; var greatest : OclAny := null; Sequence{x,greatest} := Sequence{number[i - 1+1],i} ; for j : Integer.subrange(i, n-1) do ( if ((number[j+1]->compareTo(x)) < 0 & (number[j+1]->compareTo(number[greatest+1])) > 0) then ( var greatest : OclAny := j ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSubarrWithEqualZeroAndOne(arr,n): um=dict() curr_sum=0 for i in range(n): curr_sum+=(-1 if(arr[i]==0)else arr[i]) if um.get(curr_sum): um[curr_sum]+=1 else : um[curr_sum]=1 count=0 for itr in um : if um[itr]>1 : count+=((um[itr]*int(um[itr]-1))/2) if um.get(0): count+=um[0] return int(count) arr=[1,0,0,1,0,1,1] n=len(arr) print("Count=",countSubarrWithEqualZeroAndOne(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 1 })))))) ; n := (arr)->size() ; execute ("Count=")->display(); operation countSubarrWithEqualZeroAndOne(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var um : Map := (arguments ( )) ; var curr_sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( curr_sum := curr_sum + (if (arr[i+1] = 0) then -1 else arr[i+1] endif) ; if um.get(curr_sum) then ( um[curr_sum+1] := um[curr_sum+1] + 1 ) else ( um[curr_sum+1] := 1 )) ; var count : int := 0 ; for itr : um->keys() do ( if um[itr+1] > 1 then ( count := count + ((um[itr+1] * ("" + ((um[itr+1] - 1)))->toInteger()) / 2) ) else skip) ; if um.get(0) then ( count := count + um->first() ) else skip ; return ("" + ((count)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- points=int(input()) cards=[1,2,3,4,5,6,7,8,9,10,10,10,10,11] card=points-10 if card in cards : cnt=cards.count(card) if card==10 : print(4*cnt-1) else : if card<=0 or card>11 : print(0) else : print(4*cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var points : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cards : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{10}->union(Sequence{10}->union(Sequence{10}->union(Sequence{10}->union(Sequence{ 11 }))))))))))))) ; var card : double := points - 10 ; if (cards)->includes(card) then ( var cnt : int := cards->count(card) ) else skip ; if card = 10 then ( execute (4 * cnt - 1)->display() ) else ( if card <= 0 or card > 11 then ( execute (0)->display() ) else ( execute (4 * cnt)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) n-=10 if 0toInteger() ; n := n - 10 ; if 0 < n & (n < 10) or n = 11 then ( var res : int := 4 ) else (if n = 10 then ( res := 15 ) else ( res := 0 ) ) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=int(input()) val=l-10 if 1<=val<10 : print(4) elif val==10 : print(15) elif val==11 : print(4) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var val : double := l - 10 ; if 1 <= val & (val < 10) then ( execute (4)->display() ) else (if val = 10 then ( execute (15)->display() ) else (if val = 11 then ( execute (4)->display() ) else ( execute (0)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_ways(n): if n==10 : return 4*4-1 elif n<=0 or n>11 : return 0 else : return 4 def main(): n=int(input().strip())-10 ways=get_ways(n) print(str(ways)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation get_ways(n : OclAny) : OclAny pre: true post: true activity: if n = 10 then ( return 4 * 4 - 1 ) else (if n <= 0 or n > 11 then ( return 0 ) else ( return 4 ) ) ; operation main() pre: true post: true activity: n := ("" + ((input()->trim())))->toInteger() - 10 ; var ways : OclAny := get_ways(n) ; execute (("" + ((ways))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=n-10 if a<=0 : print(0) elif a<=9 or a==11 : print(4) elif a==10 : print(15) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : double := n - 10 ; if a <= 0 then ( execute (0)->display() ) else (if a <= 9 or a = 11 then ( execute (4)->display() ) else (if a = 10 then ( execute (15)->display() ) else ( execute (0)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import pow def sumOfTermsInNthRow(n): sum=n*(2*pow(n,2)+1) return sum if __name__=='__main__' : n=4 print("Sum of all the terms in nth row=",int(sumOfTermsInNthRow(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( n := 4 ; execute ("Sum of all the terms in nth row=")->display() ) else skip; operation sumOfTermsInNthRow(n : OclAny) : OclAny pre: true post: true activity: var sum : double := n * (2 * (n)->pow(2) + 1) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def findArea(a): area=5*sqrt(3)*a*a return area def findVolume(a): volume=((5/12)*(3+sqrt(5))*a*a*a) return volume a=5 print("Area: ",findArea(a)) print("Volume: ",findVolume(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; a := 5 ; execute ("Area: ")->display() ; execute ("Volume: ")->display(); operation findArea(a : OclAny) : OclAny pre: true post: true activity: var area : double := 5 * sqrt(3) * a * a ; return area; operation findVolume(a : OclAny) : OclAny pre: true post: true activity: var volume : double := ((5 / 12) * (3 + sqrt(5)) * a * a * a) ; return volume; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lagDuration(h1,m1,h2,m2,k): lag,t1,t2=0,0,0 t1=(h1+k)*60+m1 t2=h2*60+m2 lag=t1-t2 return lag h1,m1=12,0 h2,m2=12,58 k=1 lag=lagDuration(h1,m1,h2,m2,k) print("Lag=",lag,"minutes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{h1,m1} := Sequence{12,0} ; Sequence{h2,m2} := Sequence{12,58} ; k := 1 ; lag := lagDuration(h1, m1, h2, m2, k) ; execute ("Lag=")->display(); operation lagDuration(h1 : OclAny, m1 : OclAny, h2 : OclAny, m2 : OclAny, k : OclAny) : OclAny pre: true post: true activity: var lag : OclAny := null; var t1 : OclAny := null; var t2 : OclAny := null; Sequence{lag,t1,t2} := Sequence{0,0,0} ; var t1 : double := (h1 + k) * 60 + m1 ; var t2 : double := h2 * 60 + m2 ; var lag : double := t1 - t2 ; return lag; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) nums=[int(x)for x in input().split()] ans=[] for i in reversed(nums): if i not in ans : ans.append(i) print(len(ans)) for i in reversed(ans): print(i,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nums : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : Sequence := Sequence{} ; for i : (nums)->reverse() do ( if (ans)->excludes(i) then ( execute ((i) : ans) ) else skip) ; execute ((ans)->size())->display() ; for i : (ans)->reverse() do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,k=map(int,input().split()) ans=n+2*min(k-1,n-k)+max(k-1,n-k)+n+1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : OclAny := n + 2 * Set{k - 1, n - k}->min() + Set{k - 1, n - k}->max() + n + 1 ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dot(a,b): return a.real*b.real+a.imag*b.imag def cross(a,b): return a.real*b.imag-a.imag*b.real n=int(input()) vertices=[complex(*map(int,input().split()))for _ in range(n)] edges=[(p0,p1)for p0,p1 in zip(vertices,vertices[1 :]+[vertices[0]])] q=int(input()) while q : q-=1 p=complex(*map(int,input().split())) counter=0 for p0,p1 in edges : a,b=p0-p,p1-p if a.imag>b.imag : a,b=b,a crs=cross(a,b) if a.imag<=0 and 0toInteger() ; var vertices : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (complex((argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))))) ; var edges : Sequence := Integer.subrange(1, vertices->size())->collect( _indx | Sequence{vertices->at(_indx), vertices->tail()->union(Sequence{ vertices->first() })->at(_indx)} )->select(_tuple | true)->collect(_tuple | let p0 : OclAny = _tuple->at(1) in let p1 : OclAny = _tuple->at(2) in (Sequence{p0, p1})) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while q do ( q := q - 1 ; var p : OclAny := complex((argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ; var counter : int := 0 ; (compound_stmt for (exprlist (expr (atom (name p0))) , (expr (atom (name p1)))) in (testlist (test (logical_test (comparison (expr (atom (name edges))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name b))))))) (assign_part = (testlist_star_expr (test (logical_test (comparison (expr (expr (atom (name p0))) - (expr (atom (name p))))))) , (test (logical_test (comparison (expr (expr (atom (name p1))) - (expr (atom (name p)))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name a)) (trailer . (name imag)))) > (comparison (expr (atom (name b)) (trailer . (name imag))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name b))))))) (assign_part = (testlist_star_expr (test (logical_test (comparison (expr (atom (name b)))))) , (test (logical_test (comparison (expr (atom (name a)))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name crs)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cross)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name b)))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (logical_test (logical_test (comparison (comparison (expr (atom (name a)) (trailer . (name imag)))) <= (comparison (expr (atom (number (integer 0))))))) and (logical_test (comparison (comparison (expr (atom (number (integer 0))))) < (comparison (expr (atom (name b)) (trailer . (name imag))))))) and (logical_test (comparison (comparison (expr (atom (name crs)))) < (comparison (expr (atom (number (integer 0))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name counter)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name crs)))) == (comparison (expr (atom (number (integer 0))))))) and (logical_test (comparison (comparison (expr (atom (name dot)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name b)))))))) ))))) <= (comparison (expr (atom (number (integer 0))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))) if (logical_test (comparison (expr (expr (atom (name counter))) % (expr (atom (number (integer 2))))))) else (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) )))))))))))))))); operation dot(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a.real * b.real + a.imag * b.imag; operation cross(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a.real * b.imag - a.imag * b.real; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dot(c1,c2): return c1.real*c2.real+c1.imag*c2.imag def cross(c1,c2): return c1.real*c2.imag-c1.imag*c2.real def string_to_complex(s): x,y=map(int,s.split()) return x+y*1j def contains(polygon,point): flag=False for v1,v2 in zip(polygon[0 :],polygon[1 :]): a=v1-point b=v2-point if a.imag>b.imag : a,b=b,a cross_ab=cross(a,b) if cross_ab==0 and dot(a,b)<=0 : return 1 if a.imag<=0 and b.imag>0 and cross_ab>0 : flag=not flag if flag : return 2 else : return 0 import sys file_input=sys.stdin n=int(file_input.readline()) polygon=[string_to_complex(file_input.readline())for i in range(n)] polygon.append(polygon[0]) q=int(file_input.readline()) for line in file_input : t=string_to_complex(line) print(contains(polygon,t)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var file_input : OclFile := OclFile["System.in"] ; var n : int := ("" + ((file_input.readLine())))->toInteger() ; polygon := Integer.subrange(0, n-1)->select(i | true)->collect(i | (string_to_complex(file_input.readLine()))) ; execute ((polygon->first()) : polygon) ; var q : int := ("" + ((file_input.readLine())))->toInteger() ; for line : file_input do ( var t : OclAny := string_to_complex(line) ; execute (contains(polygon, t))->display()); operation dot(c1 : OclAny, c2 : OclAny) : OclAny pre: true post: true activity: return c1.real * c2.real + c1.imag * c2.imag; operation cross(c1 : OclAny, c2 : OclAny) : OclAny pre: true post: true activity: return c1.real * c2.imag - c1.imag * c2.real; operation string_to_complex(s : OclAny) : OclAny pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ) ; return x + y * 1j; operation contains(polygon : OclAny, point : OclAny) : OclAny pre: true post: true activity: var flag : boolean := false ; for _tuple : Integer.subrange(1, polygon.subrange(0+1)->size())->collect( _indx | Sequence{polygon.subrange(0+1)->at(_indx), polygon->tail()->at(_indx)} ) do (var _indx : int := 1; var v1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v2 : OclAny := _tuple->at(_indx); var a : double := v1 - point ; var b : double := v2 - point ; if (a.imag->compareTo(b.imag)) > 0 then ( Sequence{a,b} := Sequence{b,a} ) else skip ; var cross_ab : OclAny := cross(a, b) ; if cross_ab = 0 & dot(a, b) <= 0 then ( return 1 ) else skip ; if a.imag <= 0 & b.imag > 0 & cross_ab > 0 then ( flag := not(flag) ) else skip) ; if flag then ( return 2 ) else ( return 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys if sys.version_info[0]>=3 : raw_input=input cross=lambda a,b :(a.conjugate()*b).imag dot=lambda a,b :(a.conjugate()*b).real def solve(poly,p): f=False for i in range(len(poly)): a=poly[i]-p b=poly[(i+1)% len(poly)]-p if a.imag>b.imag : a,b=b,a if a.imag<=0 and 0= 3 then ( var raw_input : OclAny := input ) else skip ; var cross : Function := lambda a : OclAny, b : OclAny in ((a.conjugate() * b).imag) ; var dot : Function := lambda a : OclAny, b : OclAny in ((a.conjugate() * b).real) ; skip ; var checkio : Function := lambda data : OclAny in (solve(data->first()->select(e | true)->collect(e | (complex((argument * (test (logical_test (comparison (expr (atom (name e)))))))))), complex((argument * (test (logical_test (comparison (expr (atom (name data)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))))) ; var n : int := ("" + ((raw_input())))->toInteger() ; poly := Integer.subrange(0, n-1)->select(i | true)->collect(i | (raw_input().split()->select(e | true)->collect(e | (("" + ((e)))->toReal())))) ; n := ("" + ((raw_input())))->toInteger() ; try ( for i : Integer.subrange(0, n-1) do ( execute (checkio->apply(Sequence{poly}->union(Sequence{ raw_input().split()->select(e | true)->collect(e | (("" + ((e)))->toReal())) })))->display())) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt pass))))); operation solve(poly : OclAny, p : OclAny) : OclAny pre: true post: true activity: var f : boolean := false ; for i : Integer.subrange(0, (poly)->size()-1) do ( var a : double := poly[i+1] - p ; var b : double := poly[(i + 1) mod (poly)->size()+1] - p ; if (a.imag->compareTo(b.imag)) > 0 then ( Sequence{a,b} := Sequence{b,a} ) else skip ; if a.imag <= 0 & 0 < b.imag & cross->apply(a, b) < 0 then ( f := not(f) ) else skip ; if cross->apply(a, b) = 0 & dot->apply(a, b) <= 0 then ( return 1 ) else skip) ; return if f then 2 else 0 endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") def cross_product_test(A,B,C): if A[1]==B[1]==C[1]: if B[0]<=A[0]<=C[0]or C[0]<=A[0]<=B[0]: return 0 else : return 1 if B[1]>C[1]: B,C=C[:],B[:] if A[1]==B[1]and A[0]==B[0]: return 0 if A[1]<=B[1]or A[1]>C[1]: return 1 delta=(B[0]-A[0])*(C[1]-A[1])-(B[1]-A[1])*(C[0]-A[0]) if delta>0 : return-1 elif delta<0 : return 1 else : return 0 def point_in_polygon(polygon,point): t=-1 polygon.append(polygon[0]) for i in range(len(polygon)-1): t*=cross_product_test(point,polygon[i],polygon[i+1]) return t N=int(input()) P=[[int(_)for _ in input().split()]for __ in range(N)] Q=int(input()) for q in range(Q): x,y=[int(_)for _ in input().split()] print(point_in_polygon(P,[x,y])+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var P : Sequence := Integer.subrange(0, N-1)->select(__ | true)->collect(__ | (input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())))) ; var Q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for q : Integer.subrange(0, Q-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; execute (point_in_polygon(P, Sequence{x}->union(Sequence{ y })) + 1)->display()); operation cross_product_test(A : OclAny, B : OclAny, C : OclAny) : OclAny pre: true post: true activity: if A[1+1] = B[1+1] & (B[1+1] == C[1+1]) then ( if (B->first()->compareTo(A->first())) <= 0 & (A->first() <= C->first()) or (C->first()->compareTo(A->first())) <= 0 & (A->first() <= B->first()) then ( return 0 ) else ( return 1 ) ) else skip ; if (B[1+1]->compareTo(C[1+1])) > 0 then ( Sequence{B,C} := Sequence{C,B} ) else skip ; if A[1+1] = B[1+1] & A->first() = B->first() then ( return 0 ) else skip ; if (A[1+1]->compareTo(B[1+1])) <= 0 or (A[1+1]->compareTo(C[1+1])) > 0 then ( return 1 ) else skip ; var delta : double := (B->first() - A->first()) * (C[1+1] - A[1+1]) - (B[1+1] - A[1+1]) * (C->first() - A->first()) ; if delta > 0 then ( return -1 ) else (if delta < 0 then ( return 1 ) else ( return 0 ) ) ; operation point_in_polygon(polygon : OclAny, point : OclAny) : OclAny pre: true post: true activity: var t : int := -1 ; execute ((polygon->first()) : polygon) ; for i : Integer.subrange(0, (polygon)->size() - 1-1) do ( t := t * cross_product_test(point, polygon[i+1], polygon[i + 1+1])) ; return t; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) vec=[] for i in range(n): vec+=[list(map(int,input().split()))] vec+=[vec[0]] def cross(a,b): return a[0]*b[1]-a[1]*b[0] def ab(a,b): c=(b[0]-a[0],b[1]-a[1]) return c def dot(a,b): n=len(a) if n!=len(b): return None ans=0 for i,j in zip(a,b): ans+=i*j return ans def check(a,b): if abs(cross(a,b))b[1]: a,b=b,a if a[1]pow(10,-8)and cross(a,b)>0 : x+=1 if x % 2==1 : print(2) else : print(0) k=int(input()) for i in range(k): contain() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var vec : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( vec := vec + Sequence{ ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) }) ; vec := vec + Sequence{ vec->first() } ; skip ; skip ; skip ; skip ; skip ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, k-1) do ( contain()); operation cross(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a->first() * b[1+1] - a[1+1] * b->first(); operation ab(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var c : OclAny := Sequence{b->first() - a->first(), b[1+1] - a[1+1]} ; return c; operation dot(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: n := (a)->size() ; if n /= (b)->size() then ( return null ) else skip ; var ans : int := 0 ; for _tuple : Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), b->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); ans := ans + i * j) ; return ans; operation check(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if ((cross(a, b))->abs()->compareTo((10)->pow(-8))) < 0 & (dot(a, b)->compareTo((10)->pow(-8))) < 0 then ( return 1 ) else ( return 0 ); operation contain() pre: true post: true activity: var x : int := 0 ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for _tuple : Integer.subrange(1, vec->front()->size())->collect( _indx | Sequence{vec->front()->at(_indx), vec->tail()->at(_indx)} ) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); a := ab(p, a) ; b := ab(p, b) ; if check(a, b) = 1 then ( execute (1)->display() ; return ) else skip ; if (a[1+1]->compareTo(b[1+1])) > 0 then ( Sequence{a,b} := Sequence{b,a} ) else skip ; if (a[1+1]->compareTo((10)->pow(-8))) < 0 & (b[1+1]->compareTo((10)->pow(-8))) > 0 & cross(a, b) > 0 then ( x := x + 1 ) else skip) ; if x mod 2 = 1 then ( execute (2)->display() ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=5 a=[[1,2,3,4,5],[5,6,7,8,6],[9,5,6,8,7],[2,3,5,6,8],[1,2,3,4,5]] if(n % 2==0): print("NULL") else : mid=n//2 convergingele=a[mid][mid] print(convergingele) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := 5 ; var a : Sequence := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 }))))}->union(Sequence{Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 6 }))))}->union(Sequence{Sequence{9}->union(Sequence{5}->union(Sequence{6}->union(Sequence{8}->union(Sequence{ 7 }))))}->union(Sequence{Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 8 }))))}->union(Sequence{ Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) })))) ; if (n mod 2 = 0) then ( execute ("NULL")->display() ) else ( var mid : int := n div 2 ; var convergingele : OclAny := a[mid+1][mid+1] ; execute (convergingele)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def kWeakestRows(self,mat,k): res=[] num_row=len(mat) num_col=len(mat[0]) col=0 flag=1 while colexists( _x | result = _x ); operation kWeakestRows(mat : OclAny,k : OclAny) : OclAny pre: true post: true activity: var res : Sequence := Sequence{} ; var num_row : int := (mat)->size() ; var num_col : int := (mat->first())->size() ; var col : int := 0 ; var flag : int := 1 ; while (col->compareTo(num_col)) < 0 & flag do ( for i : Integer.subrange(0, num_row-1) do ( if (res)->includes(i) then ( continue ) else skip ; if mat[i+1][col+1] = 0 then ( execute ((i) : res) ) else skip ; if (res)->size() = k then ( flag := 0 ; break ) else skip) ; col := col + 1) ; if (res)->size() = k then ( return res ) else skip ; for i : Integer.subrange(0, num_row-1) do ( if (res)->includes(i) then ( continue ) else skip ; execute ((i) : res) ; if (res)->size() = k then ( break ) else skip) ; return res; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): nine_pyramidal_pdf=[1] PYRAMIDAL_DIE_PDF=[0,1,1,1,1] for i in range(9): nine_pyramidal_pdf=convolve(nine_pyramidal_pdf,PYRAMIDAL_DIE_PDF) six_cubic_pdf=[1] CUBIC_DIE_PDF=[0,1,1,1,1,1,1] for i in range(6): six_cubic_pdf=convolve(six_cubic_pdf,CUBIC_DIE_PDF) ans=0 for i in range(len(nine_pyramidal_pdf)): ans+=nine_pyramidal_pdf[i]*sum(six_cubic_pdf[: i]) ans=float(ans)/(sum(nine_pyramidal_pdf)*sum(six_cubic_pdf)) return f"{ans:.7f}" def convolve(a,b): c=[0]*(len(a)+len(b)-1) for i in range(len(a)): for j in range(len(b)): c[i+j]+=a[i]*b[j] return c if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var nine_pyramidal_pdf : Sequence := Sequence{ 1 } ; var PYRAMIDAL_DIE_PDF : Sequence := Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })))) ; for i : Integer.subrange(0, 9-1) do ( nine_pyramidal_pdf := convolve(nine_pyramidal_pdf, PYRAMIDAL_DIE_PDF)) ; var six_cubic_pdf : Sequence := Sequence{ 1 } ; var CUBIC_DIE_PDF : Sequence := Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })))))) ; for i : Integer.subrange(0, 6-1) do ( six_cubic_pdf := convolve(six_cubic_pdf, CUBIC_DIE_PDF)) ; var ans : int := 0 ; for i : Integer.subrange(0, (nine_pyramidal_pdf)->size()-1) do ( ans := ans + nine_pyramidal_pdf[i+1] * (six_cubic_pdf.subrange(1,i))->sum()) ; ans := ("" + ((ans)))->toReal() / ((nine_pyramidal_pdf)->sum() * (six_cubic_pdf)->sum()) ; return StringLib.formattedString("{ans:.7f}"); operation convolve(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var c : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((a)->size() + (b)->size() - 1)) ; for i : Integer.subrange(0, (a)->size()-1) do ( for j : Integer.subrange(0, (b)->size()-1) do ( c[i + j+1] := c[i + j+1] + a[i+1] * b[j+1])) ; return c; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) num=list(map(int,input().split())) num.sort(reverse=True) evenlist,oddlist=[],[] for i in range(n): if(num[i]% 2==0): evenlist.append(num[i]) else : oddlist.append(num[i]) ans=sum(num) e=len(evenlist) o=len(oddlist) x=min(e,o) for i in range(x): ans=ans-evenlist[i] ans=ans-oddlist[i] if(e>o): ans=ans-evenlist[x] if(o>e): ans=ans-oddlist[x] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var num : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; num := num->sort() ; var evenlist : OclAny := null; var oddlist : OclAny := null; Sequence{evenlist,oddlist} := Sequence{Sequence{},Sequence{}} ; for i : Integer.subrange(0, n-1) do ( if (num[i+1] mod 2 = 0) then ( execute ((num[i+1]) : evenlist) ) else ( execute ((num[i+1]) : oddlist) )) ; var ans : OclAny := (num)->sum() ; var e : int := (evenlist)->size() ; var o : int := (oddlist)->size() ; var x : OclAny := Set{e, o}->min() ; for i : Integer.subrange(0, x-1) do ( ans := ans - evenlist[i+1] ; ans := ans - oddlist[i+1]) ; if ((e->compareTo(o)) > 0) then ( ans := ans - evenlist[x+1] ) else skip ; if ((o->compareTo(e)) > 0) then ( ans := ans - oddlist[x+1] ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n1=int(input()) o=[] e=[] n=list(map(int,input().split())) for i in range(n1): if n[i]% 2==1 : o.append(n[i]) else : e.append(n[i]) if len(o)==len(e)or abs(len(o)-len(e))==1 : print(0) else : sum=0 f=1 if len(o)>len(e): o.sort() f=0 else : e.sort() for i in range(abs(len(o)-len(e))-1): if f==0 : sum+=o[i] else : sum+=e[i] print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var o : Sequence := Sequence{} ; var e : Sequence := Sequence{} ; var n : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n1-1) do ( if n[i+1] mod 2 = 1 then ( execute ((n[i+1]) : o) ) else ( execute ((n[i+1]) : e) )) ; if (o)->size() = (e)->size() or ((o)->size() - (e)->size())->abs() = 1 then ( execute (0)->display() ) else ( var sum : int := 0 ; var f : int := 1 ; if ((o)->size()->compareTo((e)->size())) > 0 then ( o := o->sort() ; f := 0 ) else ( e := e->sort() ) ; for i : Integer.subrange(0, ((o)->size() - (e)->size())->abs() - 1-1) do ( if f = 0 then ( sum := sum + o[i+1] ) else ( sum := sum + e[i+1] )) ; execute (sum)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() n=int(n) numbers=input() numbers=numbers.split() numbers=[int(i)for i in numbers] even=[] odd=[] for i in range(n): if numbers[i]% 2==0 : even.append(numbers[i]) else : odd.append(numbers[i]) even.sort() odd.sort() if len(even)-len(odd)==1 or len(odd)-len(even)==1 : print(0) elif len(even)-len(odd)==0 or len(odd)-len(even)==0 : print(0) else : if len(odd)>len(even): if len(even)==0 : summ=sum(odd[: len(odd)-1]) else : summ=sum(odd[: len(odd)-len(even)-1]) else : if len(odd)==0 : summ=sum(even[: len(even)-1]) else : summ=sum(even[: len(even)-len(odd)-1]) print(summ) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; n := ("" + ((n)))->toInteger() ; var numbers : String := (OclFile["System.in"]).readLine() ; numbers := numbers.split() ; numbers := numbers->characters()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var even : Sequence := Sequence{} ; var odd : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if numbers[i+1] mod 2 = 0 then ( execute ((numbers[i+1]) : even) ) else ( execute ((numbers[i+1]) : odd) )) ; even := even->sort() ; odd := odd->sort() ; if (even)->size() - (odd)->size() = 1 or (odd)->size() - (even)->size() = 1 then ( execute (0)->display() ) else (if (even)->size() - (odd)->size() = 0 or (odd)->size() - (even)->size() = 0 then ( execute (0)->display() ) else ( if ((odd)->size()->compareTo((even)->size())) > 0 then ( if (even)->size() = 0 then ( var summ : OclAny := (odd.subrange(1,(odd)->size() - 1))->sum() ) else ( summ := (odd.subrange(1,(odd)->size() - (even)->size() - 1))->sum() ) ) else ( if (odd)->size() = 0 then ( summ := (even.subrange(1,(even)->size() - 1))->sum() ) else ( summ := (even.subrange(1,(even)->size() - (odd)->size() - 1))->sum() ) ) ; execute (summ)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import heapq a,b=input().split(" ") n,k=int(a),int(b) def f(n,k): return 2*n+1+min(k-1,n-k)+n-1 print(f(n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split(" ") ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := Sequence{("" + ((a)))->toInteger(),("" + ((b)))->toInteger()} ; skip ; execute (f(n, k))->display(); operation f(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: return 2 * n + 1 + Set{k - 1, n - k}->min() + n - 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() a=[[],[]] for x in sorted(map(int,input().split())): a[x % 2]+=x, a.sort(key=len) print(sum(a[1][:-len(a[0])-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var a : Sequence := Sequence{Sequence{}}->union(Sequence{ Sequence{} }) ; for x : (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() do ( a[x mod 2+1] := a[x mod 2+1] + (testlist (test (logical_test (comparison (expr (atom (name x)))))) ,)) ; a := a->sort() ; execute ((a[1+1].subrange(1,-(a->first())->size() - 1))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) arr=list(map(int,input().split())) odds=[] evens=[] for i in range(n): if arr[i]% 2 : odds.append(arr[i]) else : evens.append(arr[i]) odds=sorted(odds,reverse=True) evens=sorted(evens,reverse=True) if len(odds)toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var odds : Sequence := Sequence{} ; var evens : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] mod 2 then ( execute ((arr[i+1]) : odds) ) else ( execute ((arr[i+1]) : evens) )) ; odds := odds->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; evens := evens->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; if ((odds)->size()->compareTo((evens)->size())) < 0 then ( execute ((evens.subrange((odds)->size() + 1+1))->sum())->display() ) else ( execute ((odds.subrange((evens)->size() + 1+1))->sum())->display() ) ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def substrDeletion(string,length): count0=0 ; count1=0 ; for i in range(length): if(string[i]=='0'): count0+=1 ; else : count1+=1 ; return min(count0,count1); if __name__=="__main__" : string="010" ; length=len(string); print(substrDeletion(string,length)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( string := "010"; ; length := (string)->size(); ; execute (substrDeletion(string, length))->display(); ) else skip; operation substrDeletion(string : OclAny, length : OclAny) pre: true post: true activity: var count0 : int := 0; ; var count1 : int := 0; ; for i : Integer.subrange(0, length-1) do ( if (string[i+1] = '0') then ( count0 := count0 + 1; ) else ( count1 := count1 + 1; )) ; return Set{count0, count1}->min();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countWays(n,arr): if(n==0): return 1 no_ways=0 for i in arr : if(n-i>=0): no_ways=no_ways+countWays(n-i,arr) return no_ways arr=[1,3,5] n=5 print(countWays(n,arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{3}->union(Sequence{ 5 })) ; n := 5 ; execute (countWays(n, arr))->display(); operation countWays(n : OclAny, arr : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return 1 ) else skip ; var no_ways : int := 0 ; for i : arr do ( if (n - i >= 0) then ( no_ways := no_ways + countWays(n - i, arr) ) else skip) ; return no_ways; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* def printNcR(n,r): p=1 k=1 if(n-rcompareTo(r)) < 0) then ( r := n - r ) else skip ; if (r /= 0) then ( while (r) do ( p := p * n ; k := k * r ; var m : OclAny := gcd(p, k) ; p := p div m ; k := k div m ; n := n - 1 ; r := r - 1) ) else ( p := 1 ) ; execute (p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- string=input() count=0 sum=0 str=len(string) def TheBoyerMooreHorspool(string,word): date=dict() arr=[] for i in range(0,len(word)-1): date[word[i]]=len(word)-i-1 pos=0 while pos<=len(string)-len(word): j=len(word)-1 ; while j>-1 and(word[j]==string[pos+j]): j-=1 if j==-1 : arr.append(pos) add=1 if j!=-1 : if string[pos+j]in date.keys(): add=date[string[pos+j]] else : add=len(word)-1 pos+=add return arr found=TheBoyerMooreHorspool(string,'bear') for i in found : x=string[slice(count,i+1)] count=i+1 sum+=len(x)*(len(string)-(i+3)) print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var string : String := (OclFile["System.in"]).readLine() ; var count : int := 0 ; var sum : int := 0 ; var OclType["String"] : int := (string)->size() ; skip ; var found : OclAny := TheBoyerMooreHorspool(string, 'bear') ; for i : found do ( var x : OclAny := string->restrict(Integer.subrange(count+1,i + 1)) ; count := i + 1 ; sum := sum + (x)->size() * ((string)->size() - (i + 3))) ; execute (sum)->display(); operation TheBoyerMooreHorspool(string : OclAny, word : OclAny) : OclAny pre: true post: true activity: var date : Map := (arguments ( )) ; var arr : Sequence := Sequence{} ; for i : Integer.subrange(0, (word)->size() - 1-1) do ( date[word[i+1]+1] := (word)->size() - i - 1) ; var pos : int := 0 ; while (pos->compareTo((string)->size() - (word)->size())) <= 0 do ( var j : double := (word)->size() - 1; ; while j > -1 & (word[j+1] = string[pos + j+1]) do ( j := j - 1) ; if j = -1 then ( execute ((pos) : arr) ) else skip ; var add : int := 1 ; if j /= -1 then ( if (date.keys())->includes(string[pos + j+1]) then ( add := date[string[pos + j+1]+1] ) else ( add := (word)->size() - 1 ) ) else skip ; pos := pos + add) ; return arr; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A=input().split() print(*A) S=int(input()) for _ in " "*S : B,C=input().split() A[A.index(B)]=C print(*A) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := input().split() ; execute ((argument * (test (logical_test (comparison (expr (atom (name A))))))))->display() ; var S : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : StringLib.nCopies(" ", S) do ( var B : OclAny := null; var C : OclAny := null; Sequence{B,C} := input().split() ; A[A->indexOf(B) - 1+1] := C ; execute ((argument * (test (logical_test (comparison (expr (atom (name A))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- str1=input(); count=str1.count("bear"); c=0 ; index=0 ; lenth=len(str1) for i in range(count): ind=str1.index("bear",index)+1 c+=(ind-index)*(lenth-(ind+2)) index=ind print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var str1 : String := (OclFile["System.in"]).readLine(); var count : int := str1->count("bear"); var c : int := 0; var index : int := 0; var lenth : int := (str1)->size() ; for i : Integer.subrange(0, count-1) do ( var ind : int := str1->indexOf("bear", index) - 1 + 1 ; c := c + (ind - index) * (lenth - (ind + 2)) ; index := ind) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input(); i=0 ; c=0 ; res=0 while icompareTo((s)->size())) < 0 & i /= -1 do ( i := s->indexOf('bear', i) - 1; var n : double := 1 + i - c ; if i /= -1 then ( i := i + 1; res := res + n * (s)->size() - ((i)->pow(2) - i * c) - 2 * n; c := i ) else skip) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- word="bear" my_word=input() ans=0 last_b=0 for i in range(len(my_word)-3): if my_word[i : i+4]==word : before=i-last_b after=len(my_word)-(i+4) ans+=(before+1)*(after+1) last_b=i+1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var word : String := "bear" ; var my_word : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; var last_b : int := 0 ; for i : Integer.subrange(0, (my_word)->size() - 3-1) do ( if my_word.subrange(i+1, i + 4) = word then ( var before : double := i - last_b ; var after : double := (my_word)->size() - (i + 4) ; ans := ans + (before + 1) * (after + 1) ; last_b := i + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- my_word=input() ans,last_b=0,0 for i in range(len(my_word)-3): if my_word[i : i+4]=="bear" : ans+=((i-last_b)+1)*((len(my_word)-(i+4))+1) last_b=i+1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var my_word : String := (OclFile["System.in"]).readLine() ; var ans : OclAny := null; var last_b : OclAny := null; Sequence{ans,last_b} := Sequence{0,0} ; for i : Integer.subrange(0, (my_word)->size() - 3-1) do ( if my_word.subrange(i+1, i + 4) = "bear" then ( ans := ans + ((i - last_b) + 1) * (((my_word)->size() - (i + 4)) + 1) ; var last_b : OclAny := i + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: x,y,k=map(int,s.split()); print(k-(1-y*k-k)//(x-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var x : OclAny := null; var y : OclAny := null; var k : OclAny := null; Sequence{x,y,k} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ); execute (k - (1 - y * k - k) div (x - 1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) n=int(input()) A=list(map(int,input().split())) print('Yes' if A[0]% 2 and A[-1]% 2 and n % 2 else 'No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (if A->first() mod 2 & A->last() mod 2 & n mod 2 then 'Yes' else 'No' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) l=[] k=0 temp=[a[0]] if(a[0]& 1==0 or a[n-1]& 1==0): print('No') elif(len(set(a))==1 and len(a)% 2==0): print('No') else : for i in range(1,n): temp.append(a[i]) if(a[i]& 1==1 and i+10): l.append(temp) temp=[] if(len(temp)>0 and temp[0]& 1==1 and temp[len(temp)-1]& 1==1 and len(temp)& 1==1): l.append(temp) if(len(l)& 1==1): print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : Sequence := Sequence{} ; var k : int := 0 ; var temp : Sequence := Sequence{ a->first() } ; if (MathLib.bitwiseAnd(a->first(), 1) = 0 or MathLib.bitwiseAnd(a[n - 1+1], 1) = 0) then ( execute ('No')->display() ) else (if ((Set{}->union((a)))->size() = 1 & (a)->size() mod 2 = 0) then ( execute ('No')->display() ) else ( for i : Integer.subrange(1, n-1) do ( execute ((a[i+1]) : temp) ; if (MathLib.bitwiseAnd(a[i+1], 1) = 1 & (i + 1->compareTo((a)->size())) < 0 & MathLib.bitwiseAnd(a[i + 1+1], 1) = 1 & MathLib.bitwiseAnd((temp)->size(), 1) = 1) then ( if ((temp)->size() > 0) then ( execute ((temp) : l) ) else skip ; temp := Sequence{} ) else skip) ; if ((temp)->size() > 0 & MathLib.bitwiseAnd(temp->first(), 1) = 1 & MathLib.bitwiseAnd(temp[(temp)->size() - 1+1], 1) = 1 & MathLib.bitwiseAnd((temp)->size(), 1) = 1) then ( execute ((temp) : l) ) else skip ; if (MathLib.bitwiseAnd((l)->size(), 1) = 1) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) if arr[0]% 2==0 or arr[n-1]% 2==0 or n % 2==0 : print("No") else : print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if arr->first() mod 2 = 0 or arr[n - 1+1] mod 2 = 0 or n mod 2 = 0 then ( execute ("No")->display() ) else ( execute ("Yes")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) w=list(map(int,input().split())) if n % 2==1 and w[0]% 2==1 and w[-1]% 2==1 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n mod 2 = 1 & w->first() mod 2 = 1 & w->last() mod 2 = 1 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) even=0 num=list(map(int,input().split())) for i in range(n): if(num[i]% 2==0): even+=1 odd=n-even if(n % 2==1): if(num[0]% 2!=0 and num[n-1]% 2!=0): print("YES") else : print("NO") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var even : int := 0 ; var num : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( if (num[i+1] mod 2 = 0) then ( even := even + 1 ) else skip) ; var odd : double := n - even ; if (n mod 2 = 1) then ( if (num->first() mod 2 /= 0 & num[n - 1+1] mod 2 /= 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=6 Even=N//2 Odd=N-Even print(Even*Odd) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 6 ; var Even : int := N div 2 ; var Odd : double := N - Even ; execute (Even * Odd)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=3000 ; def smartNumber(n): primes=[0]*MAX ; result=[]; for i in range(2,MAX): if(primes[i]==0): primes[i]=1 ; j=i*2 ; while(jdisplay();; operation smartNumber(n : OclAny) pre: true post: true activity: var primes : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX); ; var result : Sequence := Sequence{}; ; for i : Integer.subrange(2, MAX-1) do ( if (primes[i+1] = 0) then ( primes[i+1] := 1; ; var j : double := i * 2; ; while ((j->compareTo(MAX)) < 0) do ( primes[j+1] := primes[j+1] - 1; ; if ((primes[j+1] + 3) = 0) then ( execute ((j) : result); ) else skip ; j := j + i;) ) else skip) ; result := result->sort(); ; return result[n - 1+1];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def l2(x,y,z): return math.sqrt(x*x+y*y+z*z) while True : s=input() if s=='-1-1-1-1' : break a,b,c,d=map(float,s.split()) a=(a/360)*2*math.pi b=(b/360)*2*math.pi c=(c/360)*2*math.pi d=(d/360)*2*math.pi x1=math.cos(b)*math.cos(a) y1=math.sin(b)*math.cos(a) z1=math.sin(a) x2=math.cos(d)*math.cos(c) y2=math.sin(d)*math.cos(c) z2=math.sin(c) theta=math.acos(x1*x2+y1*y2+z1*z2) print(round(6378.1*theta)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( var s : String := (OclFile["System.in"]).readLine() ; if s = '-1-1-1-1' then ( break ) else skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (s.split())->collect( _x | (OclType["double"])->apply(_x) ) ; var a : double := (a / 360) * 2 * ; var b : double := (b / 360) * 2 * ; var c : double := (c / 360) * 2 * ; var d : double := (d / 360) * 2 * ; var x1 : double := * ; var y1 : double := (b)->sin() * ; var z1 : double := (a)->sin() ; var x2 : double := * ; var y2 : double := (d)->sin() * ; var z2 : double := (c)->sin() ; var theta : double := (x1 * x2 + y1 * y2 + z1 * z2)->acos() ; execute ((6378.1 * theta)->round())->display()); operation l2(x : OclAny, y : OclAny, z : OclAny) : OclAny pre: true post: true activity: return (x * x + y * y + z * z)->sqrt(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math r=6378.1 def getRadian(degree): return degree*math.pi/180 while(1): a,b,c,d=(float(x)for x in input().split()) if a==-1 and b==-1 and c==-1 and d==-1 : break cos=math.cos(getRadian(a))*math.cos(getRadian(c))*math.cos(getRadian(b)-getRadian(d))+math.sin(getRadian(a))*math.sin(getRadian(c)) dist=r*math.acos(cos) print(format(dist,'.0f')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var r : double := 6378.1 ; skip ; while (1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name float)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; if a = -1 & b = -1 & c = -1 & d = -1 then ( break ) else skip ; var cos : double := * * + (getRadian(a))->sin() * (getRadian(c))->sin() ; var dist : double := r * (cos)->acos() ; execute ((dist + ""))->display()); operation getRadian(degree : OclAny) : OclAny pre: true post: true activity: return degree * / 180; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,bisect PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") R=6378.1 while True : inp=input().split() if inp==['-1']*4 : break lat1,long1,lat2,long2=[float(_)*math.pi/180.for _ in inp] dist=round(R*math.acos(math.sin(lat1)*math.sin(lat2)+math.cos(lat1)*math.cos(lat2)*math.cos(long2-long1)),0) print(int(dist)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; var R : double := 6378.1 ; while true do ( var inp : OclAny := input().split() ; if inp = MatrixLib.elementwiseMult(Sequence{ '-1' }, 4) then ( break ) else skip ; var lat1 : OclAny := null; var long1 : OclAny := null; var lat2 : OclAny := null; var long2 : OclAny := null; Sequence{lat1,long1,lat2,long2} := inp->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toReal() * / 180.)) ; var dist : double := MathLib.roundN(R * ((lat1)->sin() * (lat2)->sin() + * * )->acos(), 0) ; execute (("" + ((dist)))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import acos,sin,cos,radians while 1 : a,b,c,d=map(float,input().split()) if a==b==c==d==-1 : break a,c=radians(a),radians(c) print(int(6378.1*acos(sin(a)*sin(c)+cos(a)*cos(c)*cos(radians(d)-radians(b)))+0.5)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while 1 do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; if a = b & (b == c) & (c == d) & (d == -1) then ( break ) else skip ; var a : OclAny := null; var c : OclAny := null; Sequence{a,c} := Sequence{radians(a),radians(c)} ; execute (("" + ((6378.1 * acos(sin(a) * sin(c) + cos(a) * cos(c) * cos(radians(d) - radians(b))) + 0.5)))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from decimal import Decimal def Trades(a,b,c): k=Decimal((((b+1)*c)-1)/Decimal(a-1)) if int(k)==k : return k+c else : return int(k)+c+1 n=int(input()) for i in range(0,n): a,b,c=input().split() print(Trades(int(a),int(b),int(c))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( Sequence{a,b,c} := input().split() ; execute (Trades(("" + ((a)))->toInteger(), ("" + ((b)))->toInteger(), ("" + ((c)))->toInteger()))->display()); operation Trades(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: var k : OclAny := Decimal((((b + 1) * c) - 1) / Decimal(a - 1)) ; if ("" + ((k)))->toInteger() = k then ( return k + c ) else ( return ("" + ((k)))->toInteger() + c + 1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- PI=3.1415926535897932384626433832795 M=(PI/180.0) import math while True : y1,x1,y2,x2=list(map(float,input().split())) if x1==-1 and y1==-1 and x2==-1 and y2==-1 : break a=math.cos(y1*M)*math.cos(y2*M)*math.cos((x1-x2)*M)+math.sin(y1*M)*math.sin(y2*M) print(int(6378.1*math.acos(a)+0.5)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var PI : double := 3.1415926535897932384626433832795 ; var M : double := (PI / 180.0) ; skip ; while true do ( var y1 : OclAny := null; var x1 : OclAny := null; var y2 : OclAny := null; var x2 : OclAny := null; Sequence{y1,x1,y2,x2} := ((input().split())->collect( _x | (OclType["double"])->apply(_x) )) ; if x1 = -1 & y1 = -1 & x2 = -1 & y2 = -1 then ( break ) else skip ; var a : double := * * + (y1 * M)->sin() * (y2 * M)->sin() ; execute (("" + ((6378.1 * (a)->acos() + 0.5)))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def isPerfectSquare(x): sr=math.sqrt(x) return((sr-math.floor(sr))==0) x=2500 if(isPerfectSquare(x)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; x := 2500 ; if (isPerfectSquare(x)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isPerfectSquare(x : OclAny) : OclAny pre: true post: true activity: var sr : double := (x)->sqrt() ; return ((sr - (sr)->floor()) = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=[int(i)for i in input().split()] b=[int(i)for i in input().split()] if sum(a)!=sum(b): print("-1") continue for i in range(n): a[i]-=b[i] p=sum(a[i]for i in range(n)if a[i]>0) print(p) i,j=0,0 while p : while i=0 : j+=1 a[i]-=1 a[j]+=1 print(i+1,j+1) p-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var b : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if (a)->sum() /= (b)->sum() then ( execute ("-1")->display() ; continue ) else skip ; for i : Integer.subrange(0, n-1) do ( a[i+1] := a[i+1] - b[i+1]) ; var p : OclAny := ((argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) > (comparison (expr (atom (number (integer 0))))))))))))->sum() ; execute (p)->display() ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,0} ; while p do ( while (i->compareTo(n)) < 0 & a[i+1] <= 0 do ( i := i + 1) ; while (j->compareTo(n)) < 0 & a[j+1] >= 0 do ( j := j + 1) ; a[i+1] := a[i+1] - 1 ; a[j+1] := a[j+1] + 1 ; execute (i + 1)->display() ; p := p - 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) arr=list(map(int,input().split())) lis=list(map(int,input().split())) if sum(arr)!=sum(lis): print(-1) continue ls,lst,bs,bst=[],[],[],[] for i in range(n): if arr[i]lis[i]: bs.append(i) bst.append(arr[i]-lis[i]) seq=[] i=0 j=0 while itoInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lis : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (arr)->sum() /= (lis)->sum() then ( execute (-1)->display() ; continue ) else skip ; var ls : OclAny := null; var lst : OclAny := null; var bs : OclAny := null; var bst : OclAny := null; Sequence{ls,lst,bs,bst} := Sequence{Sequence{},Sequence{},Sequence{},Sequence{}} ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1]->compareTo(lis[i+1])) < 0 then ( execute ((i) : ls) ; execute ((lis[i+1] - arr[i+1]) : lst) ) else (if (arr[i+1]->compareTo(lis[i+1])) > 0 then ( execute ((i) : bs) ; execute ((arr[i+1] - lis[i+1]) : bst) ) else skip)) ; var seq : Sequence := Sequence{} ; var i : int := 0 ; var j : int := 0 ; while (i->compareTo((lst)->size())) < 0 & (j->compareTo((bst)->size())) < 0 do ( execute ((Sequence{bs[j+1] + 1}->union(Sequence{ ls[i+1] + 1 })) : seq) ; bst[j+1] := bst[j+1] - 1 ; lst[i+1] := lst[i+1] - 1 ; if not(bst[j+1]) then ( j := j + 1 ) else skip ; if not(lst[i+1]) then ( i := i + 1 ) else skip) ; execute ((seq)->size())->display() ; for i : seq do ( execute ((argument * (test (logical_test (comparison (expr (atom (name i))))))))->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(M,N,s): if(N % s==0): N=N//s else : N=(N//s)+1 if(M % s==0): M=M//s else : M=(M//s)+1 return M*N if __name__=="__main__" : N,M,s=12,13,4 print(solve(M,N,s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{N,M,s} := Sequence{12,13,4} ; execute (solve(M, N, s))->display() ) else skip; operation solve(M : OclAny, N : OclAny, s : OclAny) : OclAny pre: true post: true activity: if (N mod s = 0) then ( N := N div s ) else ( N := (N div s) + 1 ) ; if (M mod s = 0) then ( M := M div s ) else ( M := (M div s) + 1 ) ; return M * N; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) if sum(a)!=sum(b): print(-1) continue ptr1=0 ptr2=0 for i in range(n): if a[i]>b[i]: ptr1=i break for j in range(n): if a[j]b[i]: ptr1=i break elif i==n-1 : flag=True break if flag : break if a[ptr2]==b[ptr2]: flag=False for j in range(ptr2,n): if a[j]toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (a)->sum() /= (b)->sum() then ( execute (-1)->display() ; continue ) else skip ; var ptr1 : int := 0 ; var ptr2 : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1]->compareTo(b[i+1])) > 0 then ( ptr1 := i ; break ) else skip) ; for j : Integer.subrange(0, n-1) do ( if (a[j+1]->compareTo(b[j+1])) < 0 then ( ptr2 := j ; break ) else skip) ; var ans : Sequence := Sequence{} ; while true do ( execute ((Sequence{ptr1, ptr2}) : ans) ; a[ptr1+1] := a[ptr1+1] - 1 ; a[ptr2+1] := a[ptr2+1] + 1 ; if a[ptr1+1] = b[ptr1+1] then ( var flag : boolean := false ; for i : Integer.subrange(ptr1, n-1) do ( if (a[i+1]->compareTo(b[i+1])) > 0 then ( ptr1 := i ; break ) else (if i = n - 1 then ( flag := true ; break ) else skip)) ; if flag then ( break ) else skip ) else skip ; if a[ptr2+1] = b[ptr2+1] then ( flag := false ; for j : Integer.subrange(ptr2, n-1) do ( if (a[j+1]->compareTo(b[j+1])) < 0 then ( ptr2 := j ; break ) else (if j = n - 1 then ( flag := true ; break ) else skip)) ; if flag then ( break ) else skip ) else skip) ; execute ((ans)->size())->display() ; for k : ans do ( execute (k->first() + 1)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for k in range(t): n=int(input()) a=list(map(int,input().split(' '))) b=list(map(int,input().split(' '))) if(sum(a)!=sum(b)): print(-1) else : s=sum(list(map(lambda x,y : abs(x-y),a,b))) print(s//2) for i in range(n): if(a[i]!=b[i]): if(a[i]>b[i]): for j in range(i+1,n): while(a[j]b[j]): print(j+1,i+1) a[j]-=1 a[i]+=1 if(a[i]==b[i]): break if(a[i]==b[i]): break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for k : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; if ((a)->sum() /= (b)->sum()) then ( execute (-1)->display() ) else ( var s : OclAny := (((a)->collect( _x | (lambda x : OclAny, y : OclAny in ((x - y)->abs()))->apply(_x) )))->sum() ; execute (s div 2)->display() ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] /= b[i+1]) then ( if ((a[i+1]->compareTo(b[i+1])) > 0) then ( for j : Integer.subrange(i + 1, n-1) do ( while ((a[j+1]->compareTo(b[j+1])) < 0) do ( execute (i + 1)->display() ; a[j+1] := a[j+1] + 1 ; a[i+1] := a[i+1] - 1 ; if (a[i+1] = b[i+1]) then ( break ) else skip) ; if (a[i+1] = b[i+1]) then ( break ) else skip) ) else ( for j : Integer.subrange(i + 1, n-1) do ( while ((a[j+1]->compareTo(b[j+1])) > 0) do ( execute (j + 1)->display() ; a[j+1] := a[j+1] - 1 ; a[i+1] := a[i+1] + 1 ; if (a[i+1] = b[i+1]) then ( break ) else skip) ; if (a[i+1] = b[i+1]) then ( break ) else skip) ) ) else skip) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) l1=list(map(int,input().split())) l2=[i-j for i,j in zip(l,l1)] l3=[] m=n for i in range(n): if l2[i]<0 : for j in range(n): if l2[i]==0 : break if j!=i and l2[j]>0 : while True : if l2[j]>0 and l2[i]<0 : l3.append([j+1,i+1]) l2[i]+=1 l2[j]-=1 else : break if set(l2)=={0}: print(len(l3)) for i in l3 : print(*i) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l2 : Sequence := Integer.subrange(1, l->size())->collect( _indx | Sequence{l->at(_indx), l1->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let j : OclAny = _tuple->at(2) in (i - j)) ; var l3 : Sequence := Sequence{} ; var m : int := n ; for i : Integer.subrange(0, n-1) do ( if l2[i+1] < 0 then ( for j : Integer.subrange(0, n-1) do ( if l2[i+1] = 0 then ( break ) else skip ; if j /= i & l2[j+1] > 0 then ( while true do ( if l2[j+1] > 0 & l2[i+1] < 0 then ( execute ((Sequence{j + 1}->union(Sequence{ i + 1 })) : l3) ; l2[i+1] := l2[i+1] + 1 ; l2[j+1] := l2[j+1] - 1 ) else ( break )) ) else skip) ) else skip) ; if Set{}->union((l2)) = Set{ 0 } then ( execute ((l3)->size())->display() ; for i : l3 do ( execute ((argument * (test (logical_test (comparison (expr (atom (name i))))))))->display()) ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def answer(): point={} number=[] number_n=[] while 1 : N=list(map(int,input().split(","))) if N==[0,0]: break number.append(N) number_n.append(N[1]) number_n=sorted(number_n)[: :-1] count=1 co=number_n[0] for i in number_n : if i in point : continue elif itoInteger()+1])->display()) catch (_e : OclException) do ( break) ); operation answer() : OclAny pre: true post: true activity: var point : OclAny := Set{} ; var number : Sequence := Sequence{} ; var number_n : Sequence := Sequence{} ; while 1 do ( var N : Sequence := ((input().split(","))->collect( _x | (OclType["int"])->apply(_x) )) ; if N = Sequence{0}->union(Sequence{ 0 }) then ( break ) else skip ; execute ((N) : number) ; execute ((N[1+1]) : number_n)) ; number_n := sorted(number_n)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var count : int := 1 ; var co : OclAny := number_n->first() ; for i : number_n do ( if (point)->includes(i) then ( continue ) else (if (i->compareTo(co)) < 0 then ( count := count + 1 ; co := i ; point[co+1] := count ) else ( point[i+1] := count ) ) ) ; var data : OclAny := Set{} ; for j : number do ( if (point)->includes(j[1+1]) then ( data[j->first()+1] := point[j[1+1]+1] ) else skip) ; return data; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys c,d=[],{} for x in iter(input,'0,0'): p,s=map(int,x.split(',')) c+=[s] d[p]=s for y in sys.stdin : print(sorted({*c})[: :-1].index(d[int(y)])+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := Sequence{Sequence{},Set{}} ; for x : OclIterator.newOclIterator_Sequence(input, '0,0') do ( var p : OclAny := null; var s : OclAny := null; Sequence{p,s} := (x.split(','))->collect( _x | (OclType["int"])->apply(_x) ) ; c := c + Sequence{ s } ; d[p+1] := s) ; for y : OclFile["System.in"] do ( execute (sorted(Set{ c })(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->indexOf(d[("" + ((y)))->toInteger()+1]) - 1 + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- lst=[] while True : p,s=map(int,input().split(",")) if not p : break lst.append((s,p)) lst.sort(reverse=True) dic={} rank=0 solve_num=0 for t in lst : if solve_num==t[0]: dic[t[1]]=rank else : rank+=1 solve_num=t[0] dic[t[1]]=rank while True : try : print(dic[int(input())]) except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var lst : Sequence := Sequence{} ; while true do ( var p : OclAny := null; var s : OclAny := null; Sequence{p,s} := (input().split(","))->collect( _x | (OclType["int"])->apply(_x) ) ; if not(p) then ( break ) else skip ; execute ((Sequence{s, p}) : lst)) ; lst := lst->sort() ; var dic : OclAny := Set{} ; var rank : int := 0 ; var solve_num : int := 0 ; for t : lst do ( if solve_num = t->first() then ( dic[t[1+1]+1] := rank ) else ( rank := rank + 1 ; solve_num := t->first() ; dic[t[1+1]+1] := rank )) ; while true do ( try ( execute (dic[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1])->display()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): x,y,k=map(int,input().split()) out=k want=k*y+k-1 div=x-1 out+=(want+div-1)//div print(out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var x : OclAny := null; var y : OclAny := null; var k : OclAny := null; Sequence{x,y,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var out : OclAny := k ; var want : double := k * y + k - 1 ; var div : double := x - 1 ; out := out + (want + div - 1) div div ; execute (out)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys f=sys.stdin teams={} scores=set() while True : team,score=map(int,f.readline().split(',')) if team==score==0 : break teams[team]=score scores.update([score]) scores=sorted(list(scores))[: :-1] for line in f : print(scores.index(teams[int(line)])+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var f : OclFile := OclFile["System.in"] ; var teams : OclAny := Set{} ; var scores : Set := Set{}->union(()) ; while true do ( var team : OclAny := null; var score : OclAny := null; Sequence{team,score} := (f.readLine().split(','))->collect( _x | (OclType["int"])->apply(_x) ) ; if team = score & (score == 0) then ( break ) else skip ; teams[team+1] := score ; execute ((Sequence{ score }) <: scores)) ; scores := sorted((scores))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; for line : f do ( execute (scores->indexOf(teams[("" + ((line)))->toInteger()+1]) - 1 + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- scorelist=[] while 1 : num,score=map(int,input().split(",")) if num==0 and score==0 : break scorelist.append(score) score_unique=list(set(scorelist)) score_unique.sort(reverse=True) while 1 : try : q=int(input()) except : break score=scorelist[q-1] for i,s in enumerate(score_unique): if score==s : print(i+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var scorelist : Sequence := Sequence{} ; while 1 do ( var num : OclAny := null; var score : OclAny := null; Sequence{num,score} := (input().split(","))->collect( _x | (OclType["int"])->apply(_x) ) ; if num = 0 & score = 0 then ( break ) else skip ; execute ((score) : scorelist)) ; var score_unique : Sequence := (Set{}->union((scorelist))) ; score_unique := score_unique->sort() ; while 1 do ( try ( var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) catch (_e : OclException) do ( break) ; var score : OclAny := scorelist[q - 1+1] ; for _tuple : Integer.subrange(1, (score_unique)->size())->collect( _indx | Sequence{_indx-1, (score_unique)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var s : OclAny := _tuple->at(_indx); if score = s then ( execute (i + 1)->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_CHAR=26 ; def countSubstringWithEqualEnds(s): result=0 ; n=len(s); count=[0]*MAX_CHAR ; for i in range(n): count[ord(s[i])-ord('a')]+=1 ; for i in range(MAX_CHAR): result+=(count[i]*(count[i]+1)/2); return result ; s="abcab" ; print(countSubstringWithEqualEnds(s)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_CHAR : int := 26; ; skip ; s := "abcab"; ; execute (countSubstringWithEqualEnds(s))->display();; operation countSubstringWithEqualEnds(s : OclAny) pre: true post: true activity: var result : int := 0; ; var n : int := (s)->size(); ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX_CHAR); ; for i : Integer.subrange(0, n-1) do ( count[(s[i+1])->char2byte() - ('a')->char2byte()+1] := count[(s[i+1])->char2byte() - ('a')->char2byte()+1] + 1;) ; for i : Integer.subrange(0, MAX_CHAR-1) do ( result := result + (count[i+1] * (count[i+1] + 1) / 2);) ; return result;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(a==0): return b ; return gcd(b % a,a); def lcm(a,b): return(a*b)/gcd(a,b); def countPairs(arr,n): ans=0 ; for i in range(n): for j in range(i+1,n): if(lcm(arr[i],arr[j])==gcd(arr[i],arr[j])): ans+=1 ; return ans ; if __name__=='__main__' : arr=[1,1,1]; n=len(arr); print(countPairs(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })); ; n := (arr)->size(); ; execute (countPairs(arr, n))->display(); ) else skip; operation gcd(a : OclAny, b : OclAny) pre: true post: true activity: if (a = 0) then ( return b; ) else skip ; return gcd(b mod a, a);; operation lcm(a : OclAny, b : OclAny) pre: true post: true activity: return (a * b) / gcd(a, b);; operation countPairs(arr : OclAny, n : OclAny) pre: true post: true activity: var ans : int := 0; ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if (lcm(arr[i+1], arr[j+1]) = gcd(arr[i+1], arr[j+1])) then ( ans := ans + 1; ) else skip)) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n_test_cases=int(input()) r=[] for _ in range(n_test_cases): n=int(input()) arr=[int(a)for a in input().split()] d={} for a in arr : if a in d : d[a]+=1 else : d[a]=1 s=0 for k,v in d.items(): if v>1 : s+=v-1 if s % 2==1 : s+=1 r.append(str(n-s)) print('\n'.join(r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n_test_cases : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n_test_cases-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; var d : OclAny := Set{} ; for a : arr do ( if (d)->includes(a) then ( d[a+1] := d[a+1] + 1 ) else ( d[a+1] := 1 )) ; var s : int := 0 ; for _tuple : d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if v > 1 then ( s := s + v - 1 ) else skip) ; if s mod 2 = 1 then ( s := s + 1 ) else skip ; execute ((("" + ((n - s)))) : r)) ; execute (StringLib.sumStringsWithSeparator((r), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): d=int(input()) s=[int(i)for i in input().split()] m=set(s) if(d-len(m))% 2==0 : print(len(m)) else : print(len(m)-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var m : Set := Set{}->union((s)) ; if (d - (m)->size()) mod 2 = 0 then ( execute ((m)->size())->display() ) else ( execute ((m)->size() - 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) arr=list(map(int,input().split())) store={} for i in range(len(arr)): if arr[i]in store : store[arr[i]]+=1 else : store[arr[i]]=1 l=len(store) hold=0 for i in store.values(): hold+=i if((hold-l)% 2==0): print(l) else : print(l-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var store : OclAny := Set{} ; for i : Integer.subrange(0, (arr)->size()-1) do ( if (store)->includes(arr[i+1]) then ( store[arr[i+1]+1] := store[arr[i+1]+1] + 1 ) else ( store[arr[i+1]+1] := 1 )) ; var l : int := (store)->size() ; var hold : int := 0 ; for i : store.values() do ( hold := hold + i) ; if ((hold - l) mod 2 = 0) then ( execute (l)->display() ) else ( execute (l - 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) arr=list(map(int,input().split())) print(len(arr)-(-(-(len(arr)-len(set(arr)))//2)*2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((arr)->size() - (-(-((arr)->size() - (Set{}->union((arr)))->size()) div 2) * 2))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) l=list(map(int,input().split())) s=set(l) if l==s : print(len(l)) p=[] q=[] for i in s : p.append(l.count(i)) q.append(p[-1]-1) if sum(q)% 2!=0 : print(len(s)-1) else : print(len(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Set := Set{}->union((l)) ; if l = s then ( execute ((l)->size())->display() ) else skip ; var p : Sequence := Sequence{} ; var q : Sequence := Sequence{} ; for i : s do ( execute ((l->count(i)) : p) ; execute ((p->last() - 1) : q)) ; if (q)->sum() mod 2 /= 0 then ( execute ((s)->size() - 1)->display() ) else ( execute ((s)->size())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd,sqrt MAX=100000 prime=[True]*MAX def sieve(): prime[0]=False prime[1]=False for i in range(2,MAX): if prime[i]: for j in range(2**i,MAX,i): prime[j]=False def checkArray(arr,n): sum=0 for i in range(n): if prime[arr[i]]: sum+=arr[i] if prime[sum]: return True return False if __name__=="__main__" : arr=[1,2,3] n=len(arr) sieve() if checkArray(arr,n): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MAX : int := 100000 ; var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, MAX) ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; n := (arr)->size() ; sieve() ; if checkArray(arr, n) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation sieve() pre: true post: true activity: prime->first() := false ; prime[1+1] := false ; for i : Integer.subrange(2, MAX-1) do ( if prime[i+1] then ( for j : Integer.subrange((2)->pow(i), MAX-1)->select( $x | ($x - (2)->pow(i)) mod i = 0 ) do ( prime[j+1] := false) ) else skip); operation checkArray(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( if prime[arr[i+1]+1] then ( sum := sum + arr[i+1] ) else skip) ; if prime[sum+1] then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def findValueAtK(n,m,k): positionOfRightmostSetbit=math.log2(k &-k)+1 return((m-1)+positionOfRightmostSetbit) k=100 n=9 m=74 print(findValueAtK(n,m,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; k := 100 ; n := 9 ; m := 74 ; execute (findValueAtK(n, m, k))->display(); operation findValueAtK(n : OclAny, m : OclAny, k : OclAny) : OclAny pre: true post: true activity: var positionOfRightmostSetbit : OclAny := + 1 ; return ((m - 1) + positionOfRightmostSetbit); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): x,y,k=map(int,input().split()) print(((y+1)*k-1+x-2)//(x-1)+k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; var k : OclAny := null; Sequence{x,y,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (((y + 1) * k - 1 + x - 2) div (x - 1) + k)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSequences(arr,n): count=1 arr.sort() for i in range(n-1): if(arr[i]+1!=arr[i+1]): count+=1 return count if __name__=="__main__" : arr=[1,7,3,5,10] n=len(arr) print(countSequences(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{7}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 10 })))) ; n := (arr)->size() ; execute (countSequences(arr, n))->display() ) else skip; operation countSequences(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count : int := 1 ; arr := arr->sort() ; for i : Integer.subrange(0, n - 1-1) do ( if (arr[i+1] + 1 /= arr[i + 1+1]) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countNum(arr,n): count=0 arr.sort() for i in range(0,n-1): if(arr[i]!=arr[i+1]and arr[i]!=arr[i+1]-1): count+=arr[i+1]-arr[i]-1 ; return count arr=[3,5,8,6] n=len(arr) print(countNum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{3}->union(Sequence{5}->union(Sequence{8}->union(Sequence{ 6 }))) ; n := (arr)->size() ; execute (countNum(arr, n))->display(); operation countNum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; arr := arr->sort() ; for i : Integer.subrange(0, n - 1-1) do ( if (arr[i+1] /= arr[i + 1+1] & arr[i+1] /= arr[i + 1+1] - 1) then ( count := count + arr[i + 1+1] - arr[i+1] - 1; ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- scores_of_the_participants=list(map(int,input().split(' '))) total_scores=sum(scores_of_the_participants) chosen_teams=0 for i in range(6): for j in range(i+1,6): for k in range(j+1,6): if scores_of_the_participants[i]+scores_of_the_participants[j]+scores_of_the_participants[k]==total_scores-(scores_of_the_participants[i]+scores_of_the_participants[j]+scores_of_the_participants[k]): chosen_teams+=1 if chosen_teams==0 : print('NO') else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var scores_of_the_participants : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var total_scores : OclAny := (scores_of_the_participants)->sum() ; var chosen_teams : int := 0 ; for i : Integer.subrange(0, 6-1) do ( for j : Integer.subrange(i + 1, 6-1) do ( for k : Integer.subrange(j + 1, 6-1) do ( if scores_of_the_participants[i+1] + scores_of_the_participants[j+1] + scores_of_the_participants[k+1] = total_scores - (scores_of_the_participants[i+1] + scores_of_the_participants[j+1] + scores_of_the_participants[k+1]) then ( chosen_teams := chosen_teams + 1 ) else skip))) ; if chosen_teams = 0 then ( execute ('NO')->display() ) else ( execute ('YES')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def indexOfFirstOne(arr,n): for i in range(0,n): if(arr[i]==1): return i return-1 arr=[0,0,0,0,0,0,1,1,1,1] n=len(arr) ans=indexOfFirstOne(arr,n) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))))))))) ; n := (arr)->size() ; var ans : OclAny := indexOfFirstOne(arr, n) ; execute (ans)->display(); operation indexOfFirstOne(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if (arr[i+1] = 1) then ( return i ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def toggleLastMBits(n,m): if(m==0): return n num=(1<display(); operation toggleLastMBits(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: if (m = 0) then ( return n ) else skip ; var num : double := (1 * (2->pow(m))) - 1 ; return (MathLib.bitwiseXor(n, num)); operation largeNumWithNSetAndMUnsetBits(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: num := (1 * (2->pow((n + m)))) - 1 ; return toggleLastMBits(num, m); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def valid_number(str): i=0 j=len(str)-1 while i=0 and str[j]==' ' : j-=1 if i>j : return False if(i==j and not(str[i]>='0' and str[i]<='9')): return False if(str[i]!='.' and str[i]!='+' and str[i]!='-' and not(str[i]>='0' and str[i]<='9')): return False flagDotOrE=False for i in range(j+1): if(str[i]!='e' and str[i]!='.' and str[i]!='+' and str[i]!='-' and not(str[i]>='0' and str[i]<='9')): return False if str[i]=='.' : if flagDotOrE : return False if i+1>len(str): return False if(not(str[i+1]>='0' and str[i+1]<='9')): return False elif str[i]=='e' : flagDotOrE=True if(not(str[i-1]>='0' and str[i-1]<='9')): return False if i+1>len(str): return False if(str[i+1]!='+' and str[i+1]!='-' and(str[i+1]>='0' and str[i]<='9')): return False return True if __name__=='__main__' : str="0.1e10" if valid_number(str): print('true') else : print('false') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( OclType["String"] := "0.1e10" ; if valid_number(OclType["String"]) then ( execute ('true')->display() ) else ( execute ('false')->display() ) ) else skip; operation valid_number(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; var j : double := (OclType["String"])->size() - 1 ; while (i->compareTo((OclType["String"])->size())) < 0 & ("" + ([i+1])) = ' ' do ( i := i + 1) ; while j >= 0 & ("" + ([j+1])) = ' ' do ( j := j - 1) ; if (i->compareTo(j)) > 0 then ( return false ) else skip ; if (i = j & not((("" + ([i+1])) >= '0' & ("" + ([i+1])) <= '9'))) then ( return false ) else skip ; if (("" + ([i+1])) /= '.' & ("" + ([i+1])) /= '+' & ("" + ([i+1])) /= '-' & not((("" + ([i+1])) >= '0' & ("" + ([i+1])) <= '9'))) then ( return false ) else skip ; var flagDotOrE : boolean := false ; for i : Integer.subrange(0, j + 1-1) do ( if (("" + ([i+1])) /= 'e' & ("" + ([i+1])) /= '.' & ("" + ([i+1])) /= '+' & ("" + ([i+1])) /= '-' & not((("" + ([i+1])) >= '0' & ("" + ([i+1])) <= '9'))) then ( return false ) else skip ; if ("" + ([i+1])) = '.' then ( if flagDotOrE then ( return false ) else skip ; if (i + 1->compareTo((OclType["String"])->size())) > 0 then ( return false ) else skip ; if (not((("" + ([i + 1+1])) >= '0' & ("" + ([i + 1+1])) <= '9'))) then ( return false ) else skip ) else (if ("" + ([i+1])) = 'e' then ( flagDotOrE := true ; if (not((("" + ([i - 1+1])) >= '0' & ("" + ([i - 1+1])) <= '9'))) then ( return false ) else skip ; if (i + 1->compareTo((OclType["String"])->size())) > 0 then ( return false ) else skip ; if (("" + ([i + 1+1])) /= '+' & ("" + ([i + 1+1])) /= '-' & (("" + ([i + 1+1])) >= '0' & ("" + ([i+1])) <= '9')) then ( return false ) else skip ) else skip)) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=10**9+7 def power(a,m1): if(m1==0): return 1 elif(m1==1): return a elif(m1==2): return(a*a)% mod elif(m1 & 1): return(a*power(power(a,m1//2),2))% mod else : return power(power(a,m1//2),2)% mod def factorial(x): ans=1 for i in range(1,x+1): ans=(ans*i)% mod return ans def inverse(x): return power(x,mod-2) def binomial(n,r): if(r>n): return 0 ans=factorial(n) ans=(ans*inverse(factorial(r)))% mod ans=(ans*inverse(factorial(n-r)))% mod return ans def number_of_sets(n,a,b): ans=power(2,n) ans=ans-binomial(n,a) if(ans<0): ans+=mod ans=ans-binomial(n,b) ans-=1 if(ans<0): ans+=mod return ans if __name__=='__main__' : N=4 A=1 B=3 print(number_of_sets(N,A,B)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var N : int := 4 ; var A : int := 1 ; var B : int := 3 ; execute (number_of_sets(N, A, B))->display() ) else skip; operation power(a : OclAny, m1 : OclAny) : OclAny pre: true post: true activity: if (m1 = 0) then ( return 1 ) else (if (m1 = 1) then ( return a ) else (if (m1 = 2) then ( return (a * a) mod mod ) else (if (MathLib.bitwiseAnd(m1, 1)) then ( return (a * power(power(a, m1 div 2), 2)) mod mod ) else ( return power(power(a, m1 div 2), 2) mod mod ) ) ) ) ; operation factorial(x : OclAny) : OclAny pre: true post: true activity: var ans : int := 1 ; for i : Integer.subrange(1, x + 1-1) do ( ans := (ans * i) mod mod) ; return ans; operation inverse(x : OclAny) : OclAny pre: true post: true activity: return power(x, mod - 2); operation binomial(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: if ((r->compareTo(n)) > 0) then ( return 0 ) else skip ; ans := factorial(n) ; ans := (ans * inverse(factorial(r))) mod mod ; ans := (ans * inverse(factorial(n - r))) mod mod ; return ans; operation number_of_sets(n : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: ans := power(2, n) ; ans := ans - binomial(n, a) ; if (ans < 0) then ( ans := ans + mod ) else skip ; ans := ans - binomial(n, b) ; ans := ans - 1 ; if (ans < 0) then ( ans := ans + mod ) else skip ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline R=lambda : map(int,input().split()) I=lambda : int(input()) S=lambda : input().rstrip('\n') L=lambda : list(R()) for _ in range(I()): n=I() a=L() cnt=[0]*30 for x in a : for j in range(30): if x &(1<collect( _x | (OclType["int"])->apply(_x) )) ; var I : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var S : Function := lambda $$ : OclAny in (input().rstrip(' ')) ; var L : Function := lambda $$ : OclAny in ((R->apply())->characters()) ; for _anon : Integer.subrange(0, I->apply()-1) do ( var n : OclAny := I->apply() ; var a : OclAny := L->apply() ; var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 30) ; for x : a do ( for j : Integer.subrange(0, 30-1) do ( if MathLib.bitwiseAnd(x, (1 * (2->pow(j)))) then ( cnt[j+1] := cnt[j+1] + 1 ) else skip)) ; var ans : String := "DRAW" ; for j : Integer.subrange(-1 + 1, 29)->reverse() do ( if cnt[j+1] mod 2 = 1 then ( var rem : double := n - cnt[j+1] ; if rem mod 2 = 0 & cnt[j+1] mod 4 = 3 then ( ans := 'LOSE' ) else ( ans := 'WIN' ) ; break ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline def bit(ar,n): for i in range(0,30): if(1<toInteger()-1) do ( var a : String := (OclFile["System.in"]).readLine() ; var lst : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (f(lst))->display()); operation bit(ar : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, 30-1) do ( if MathLib.bitwiseAnd((1 * (2->pow(i))), (n)) then ( ar[i+1] := ar[i+1] + 1 ) else skip) ; return ar; operation f(ar : OclAny) : OclAny pre: true post: true activity: var bt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (30)) ; for i : ar do ( bt := bit(bt, i)) ; for j : Integer.subrange(-1 + 1, 29)->reverse() do ( if bt[j+1] mod 2 = 1 then ( if bt[j+1] mod 4 = 3 & ((ar)->size() - bt[j+1]) mod 2 = 0 then ( return "LOSE" ) else ( return "WIN" ) ) else skip) ; return "DRAW"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) win=0 for i in range(31)[: :-1]: c1=0 ; c0=0 for j in range(n): if(a[j]>>i)& 1 : c1+=1 else : c0+=1 if c1 % 2==0 : continue if c1 % 4==3 and c0 % 2==0 : win=-1 break else : win=1 break if win==1 : print("WIN") elif win==0 : print("DRAW") else : print("LOSE") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var win : int := 0 ; for i : range(31)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( var c1 : int := 0; var c0 : int := 0 ; for j : Integer.subrange(0, n-1) do ( if MathLib.bitwiseAnd((a[j+1] /(2->pow(i))), 1) then ( c1 := c1 + 1 ) else ( c0 := c0 + 1 )) ; if c1 mod 2 = 0 then ( continue ) else skip ; if c1 mod 4 = 3 & c0 mod 2 = 0 then ( win := -1 ; break ) else ( win := 1 ; break )) ; if win = 1 then ( execute ("WIN")->display() ) else (if win = 0 then ( execute ("DRAW")->display() ) else ( execute ("LOSE")->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) li=[int(i)for i in input().split()] d1={} dn=False for i in li : bit=0 while i : d1[bit]=d1.get(bit,0)+(i & 1) bit+=1 i>>=1 for k,v in sorted(d1.items(),reverse=True): if v & 1 : if v % 4==3 and(n-v)& 1==0 : print('LOSE') dn=True break else : print('WIN') dn=True break if not dn : print('DRAW') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var d1 : OclAny := Set{} ; var dn : boolean := false ; for i : li do ( var bit : int := 0 ; while i do ( d1[bit+1] := d1.get(bit, 0) + (MathLib.bitwiseAnd(i, 1)) ; bit := bit + 1 ; i := i div (2->pow(1)))) ; for _tuple : d1->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if MathLib.bitwiseAnd(v, 1) then ( if v mod 4 = 3 & MathLib.bitwiseAnd((n - v), 1) = 0 then ( execute ('LOSE')->display() ; dn := true ; break ) else ( execute ('WIN')->display() ; dn := true ; break ) ) else skip) ; if not(dn) then ( execute ('DRAW')->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(0,int(input())): x,y,k=map(int,input().split()) s=(k-1)+(k*y) print((0--s//(x-1))+k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; var k : OclAny := null; Sequence{x,y,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : double := (k - 1) + (k * y) ; execute ((0 - -s div (x - 1)) + k)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s,maxh,smaxh=0,0,0 l=[] for _ in range(n): w,h=map(int,input().split()) l.append([w,h]) s+=w if h>=maxh : smaxh=maxh maxh=h elif h>smaxh : smaxh=h for i in range(n): totalWidth=s-l[i][0] maxHeight=maxh if l[i][1]!=maxh else smaxh print(totalWidth*maxHeight,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := null; var maxh : OclAny := null; var smaxh : OclAny := null; Sequence{s,maxh,smaxh} := Sequence{0,0,0} ; var l : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{w}->union(Sequence{ h })) : l) ; s := s + w ; if (h->compareTo(maxh)) >= 0 then ( var smaxh : OclAny := maxh ; var maxh : OclAny := h ) else (if (h->compareTo(smaxh)) > 0 then ( smaxh := h ) else skip)) ; for i : Integer.subrange(0, n-1) do ( var totalWidth : double := s - l[i+1]->first() ; var maxHeight : OclAny := if l[i+1][1+1] /= maxh then maxh else smaxh endif ; execute (totalWidth * maxHeight)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=sorted(list(map(int,input().split()))) sa=sum(a) for i in range(6): for j in range(i+1,6): for k in range(j+1,6): ps=a[i]+a[j]+a[k] if sa==2*ps : print("YES") raise SystemExit print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var sa : OclAny := (a)->sum() ; for i : Integer.subrange(0, 6-1) do ( for j : Integer.subrange(i + 1, 6-1) do ( for k : Integer.subrange(j + 1, 6-1) do ( var ps : OclAny := a[i+1] + a[j+1] + a[k+1] ; if sa = 2 * ps then ( execute ("YES")->display() ; error SystemExit.newSystemExit ) else skip))) ; execute ("NO")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) s=0 a=[tuple(map(int,input().split()))for i in range(n)] ma1=0 ma2=0 for i in range(n): s+=a[i][0] if ma1<=a[i][1]: ma2=ma1 ma1=a[i][1] elif ma2toInteger() ; var s : int := 0 ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ma1 : int := 0 ; var ma2 : int := 0 ; for i : Integer.subrange(0, n-1) do ( s := s + a[i+1]->first() ; if (ma1->compareTo(a[i+1][1+1])) <= 0 then ( ma2 := ma1 ; ma1 := a[i+1][1+1] ) else (if (ma2->compareTo(a[i+1][1+1])) < 0 then ( ma2 := a[i+1][1+1] ) else skip)) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var h : double := s - a[i+1]->first() ; if ma1 = a[i+1][1+1] then ( var w : int := ma2 ) else ( w := ma1 ) ; execute ((h * w) : ans)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) w_list=[] h_list=[] for i in range(n): w,h=map(int,input().split()) w_list.append(w) h_list.append(h) total_w=sum(w_list) sorted_h=sorted(h_list,reverse=True) result=[] for i in range(n): if(h_list[i]==sorted_h[0]): max_h_now=sorted_h[1] else : max_h_now=sorted_h[0] result.append((total_w-w_list[i])*(max_h_now)) print(*result,sep=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w_list : Sequence := Sequence{} ; var h_list : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((w) : w_list) ; execute ((h) : h_list)) ; var total_w : OclAny := (w_list)->sum() ; var sorted_h : Sequence := h_list->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var result : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if (h_list[i+1] = sorted_h->first()) then ( var max_h_now : OclAny := sorted_h[1+1] ) else ( max_h_now := sorted_h->first() ) ; execute (((total_w - w_list[i+1]) * (max_h_now)) : result)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name result))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[list(map(int,input().split()))for i in range(n)] mx1,mx2=-1,-1 for i in a : if i[1]>mx1 : mx2=mx1 mx1=i[1] elif i[1]>mx2 : mx2=i[1] s=0 for i in a : s+=i[0] ans=[] for i in range(len(a)): S=s S-=a[i][0] if a[i][1]==mx1 : ans.append(S*(mx2)) else : ans.append(S*mx1) print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var mx1 : OclAny := null; var mx2 : OclAny := null; Sequence{mx1,mx2} := Sequence{-1,-1} ; for i : a do ( if (i[1+1]->compareTo(mx1)) > 0 then ( var mx2 : OclAny := mx1 ; var mx1 : OclAny := i[1+1] ) else (if (i[1+1]->compareTo(mx2)) > 0 then ( mx2 := i[1+1] ) else skip)) ; var s : int := 0 ; for i : a do ( s := s + i->first()) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, (a)->size()-1) do ( var S : int := s ; S := S - a[i+1]->first() ; if a[i+1][1+1] = mx1 then ( execute ((S * (mx2)) : ans) ) else ( execute ((S * mx1) : ans) )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) g=[list(map(int,input().split()))for _ in range(n)] s=sum(i[0]for i in g) w=sorted([i[1]for i in g]) for i in g : if i[1]!=w[-1]: print((s-i[0])*w[-1],end=' ') else : print((s-i[0])*w[-2],end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var g : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var s : OclAny := ((argument (test (logical_test (comparison (expr (atom (name i)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name g))))))))->sum() ; var w : Sequence := g->select(i | true)->collect(i | (i[1+1]))->sort() ; for i : g do ( if i[1+1] /= w->last() then ( execute ((s - i->first()) * w->last())->display() ) else ( execute ((s - i->first()) * w->front()->last())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMod4(s,n): if(n==1): k=ord(s[0])-ord('0') else : k=((ord(s[n-2])-ord('0'))*10+ord(s[n-1])-ord('0')) return(k % 4) if __name__=='__main__' : s="81" n=len(s) print(findMod4(s,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( s := "81" ; n := (s)->size() ; execute (findMod4(s, n))->display() ) else skip; operation findMod4(s : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( var k : double := (s->first())->char2byte() - ('0')->char2byte() ) else ( k := (((s[n - 2+1])->char2byte() - ('0')->char2byte()) * 10 + (s[n - 1+1])->char2byte() - ('0')->char2byte()) ) ; return (k mod 4); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) for _ in range(m): c,*d=map(int,input().split()) a=set(d) for v in a : if-v in a : break else : print('YES') exit() print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for _anon : Integer.subrange(0, m-1) do ( var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Set := Set{}->union((d)) ; (compound_stmt for (exprlist (expr (atom (name v)))) in (testlist (test (logical_test (comparison (expr (atom (name a))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr - (expr (atom (name v))))) in (comparison (expr (atom (name a))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name exit)) (trailer (arguments ( )))))))))))))))) ; execute ('NO')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q,p=map(int,input().split()) destroy=False while p>0 : group=[int(grp)for grp in input().split()][1 :] if len(group)==1 : destroy=True break group=[abs(grp)for grp in list(set(group))] old_size=len(group) group=list(set(group)) if len(group)==old_size : destroy=True break p-=1 if destroy : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : OclAny := null; var p : OclAny := null; Sequence{q,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var destroy : boolean := false ; while p > 0 do ( var group : OclAny := input().split()->select(grp | true)->collect(grp | (("" + ((grp)))->toInteger()))->tail() ; if (group)->size() = 1 then ( destroy := true ; break ) else skip ; group := (Set{}->union((group)))->select(grp | true)->collect(grp | ((grp)->abs())) ; var old_size : int := (group)->size() ; group := (Set{}->union((group))) ; if (group)->size() = old_size then ( destroy := true ; break ) else skip ; p := p - 1) ; if destroy then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) f=0 for _ in range(m): arr=set(list(map(int,input().split()))[1 :]) sa=set(abs(x)for x in arr) if len(sa)!=len(arr): continue else : f=1 if f : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var f : int := 0 ; for _anon : Integer.subrange(0, m-1) do ( var arr : Set := Set{}->union((OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->tail())) ; var sa : Set := Set{}->union(((argument (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name arr))))))))) ; if (sa)->size() /= (arr)->size() then ( continue ) else ( f := 1 )) ; if f then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) flag=False for _ in range(m): g=set(list(map(int,input().split()))[1 :]) v=set(abs(i)for i in g) if(len(v)!=len(g)): continue else : flag=True if(flag): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var flag : boolean := false ; for _anon : Integer.subrange(0, m-1) do ( var g : Set := Set{}->union((OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->tail())) ; var v : Set := Set{}->union(((argument (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name g))))))))) ; if ((v)->size() /= (g)->size()) then ( continue ) else ( flag := true )) ; if (flag) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() if s[0]=='0' : c=0 for i in s : if i=='0' : c+=1 if i=='1' : break s=s[c :] a=s.count('0') b=s.count('1') if b==1 and a==6 and s.count('1000000')==0 : print('no') elif b>=1 and a>=6 : print('yes') else : print('no') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; if s->first() = '0' then ( var c : int := 0 ; for i : s->characters() do ( if i = '0' then ( c := c + 1 ) else skip ; if i = '1' then ( break ) else skip) ; s := s.subrange(c+1) ) else skip ; var a : int := s->count('0') ; var b : int := s->count('1') ; if b = 1 & a = 6 & s->count('1000000') = 0 then ( execute ('no')->display() ) else (if b >= 1 & a >= 6 then ( execute ('yes')->display() ) else ( execute ('no')->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import combinations A=list(map(int,input().split())) x=sum(A)/2 print('YES' if any(sum(team)==x for team in combinations(A,3))else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : double := (A)->sum() / 2 ; execute (if ((argument (test (logical_test (comparison (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name team)))))))) ))))) == (comparison (expr (atom (name x))))))) (comp_for for (exprlist (expr (atom (name team)))) in (logical_test (comparison (expr (atom (name combinations)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 3))))))))) )))))))))->exists( _x | _x = true ) then 'YES' else 'NO' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) destroy=False while m>0 : group=[int(g)for g in input().split()][1 :] if len(group)==1 : destroy=True break group=[abs(g)for g in list(set(group))] old_size=len(group) group=list(set(group)) if len(group)==old_size : destroy=True break m-=1 if destroy : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var destroy : boolean := false ; while m > 0 do ( var group : OclAny := input().split()->select(g | true)->collect(g | (("" + ((g)))->toInteger()))->tail() ; if (group)->size() = 1 then ( destroy := true ; break ) else skip ; group := (Set{}->union((group)))->select(g | true)->collect(g | ((g)->abs())) ; var old_size : int := (group)->size() ; group := (Set{}->union((group))) ; if (group)->size() = old_size then ( destroy := true ; break ) else skip ; m := m - 1) ; if destroy then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) ans=1 if a.count(0): print(0) exit() for i in a : ans*=i if ans>10**18 : print(-1) exit() print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 1 ; if a->count(0) then ( execute (0)->display() ; exit() ) else skip ; for i : a do ( ans := ans * i ; if (ans->compareTo((10)->pow(18))) > 0 then ( execute (-1)->display() ; exit() ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=input() A=[int(a)for a in input().split()] ans=1 if 0 in A : print(0) exit() for i in range(len(A)): if ans>10**18 : print(-1) exit() ans*=A[i] if ans>10**18 : print(-1) exit() print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : String := (OclFile["System.in"]).readLine() ; var A : Sequence := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; var ans : int := 1 ; if (A)->includes(0) then ( execute (0)->display() ; exit() ) else skip ; for i : Integer.subrange(0, (A)->size()-1) do ( if (ans->compareTo((10)->pow(18))) > 0 then ( execute (-1)->display() ; exit() ) else skip ; ans := ans * A[i+1]) ; if (ans->compareTo((10)->pow(18))) > 0 then ( execute (-1)->display() ; exit() ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) mylist=list(map(int,input().split(" "))) result=1 if 0 in mylist : result=0 else : for i in mylist : if result*i>10**18 : result=-1 break else : result*=i print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mylist : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var result : int := 1 ; if (mylist)->includes(0) then ( result := 0 ) else ( for i : mylist do ( if (result * i->compareTo((10)->pow(18))) > 0 then ( result := -1 ; break ) else ( result := result * i )) ) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=[int(x)for x in input().split()] A=sorted(A) p=1 limit=10**18 for a in A : if a==0 : print(0) exit() p*=a if p>limit : print(-1) exit() print(p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; A := A->sort() ; var p : int := 1 ; var limit : double := (10)->pow(18) ; for a : A do ( if a = 0 then ( execute (0)->display() ; exit() ) else skip ; p := p * a ; if (p->compareTo(limit)) > 0 then ( execute (-1)->display() ; exit() ) else skip) ; execute (p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=list(map(int,input().split())) t=A[0] for i in range(1,N): t*=A[i] if int(t)>1e18 : for j in range(i,N): if A[j]==0 : t=0 break if int(t)<=1e18 : print(int(t)) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : OclAny := A->first() ; for i : Integer.subrange(1, N-1) do ( t := t * A[i+1] ; if ("" + ((t)))->toInteger() > ("1e18")->toReal() then ( for j : Integer.subrange(i, N-1) do ( if A[j+1] = 0 then ( t := 0 ) else skip) ; break ) else skip) ; if ("" + ((t)))->toInteger() <= ("1e18")->toReal() then ( execute (("" + ((t)))->toInteger())->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[] for i in range(n): a+=[int(input())] a.sort() j,cnt=n//2,0 for i in range(n//2): while jtoInteger() ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( a := a + Sequence{ ("" + (((OclFile["System.in"]).readLine())))->toInteger() }) ; a := a->sort() ; var j : OclAny := null; var cnt : OclAny := null; Sequence{j,cnt} := Sequence{n div 2,0} ; for i : Integer.subrange(0, n div 2-1) do ( while (j->compareTo(n)) < 0 do ( if (a[i+1] * 2->compareTo(a[j+1])) <= 0 then ( cnt := cnt + 1 ; j := j + 1 ; break ) else ( j := j + 1 ))) ; execute (n - cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=sorted([int(input())for i in range(n)]) j=n-1 c=0 for i in range(n//2-1,-1,-1): if(l[i]*2<=l[j]): j-=1 c+=1 print(j+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))->sort() ; var j : double := n - 1 ; var c : int := 0 ; for i : Integer.subrange(-1 + 1, n div 2 - 1)->reverse() do ( if ((l[i+1] * 2->compareTo(l[j+1])) <= 0) then ( j := j - 1 ; c := c + 1 ) else skip) ; execute (j + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=sorted([int(input())for i in range(n)]) j=n-1 c=0 for i in range(n//2-1,-1,-1): if(l[i]*2<=l[j]): j-=1 c+=1 print(j+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))->sort() ; var j : double := n - 1 ; var c : int := 0 ; for i : Integer.subrange(-1 + 1, n div 2 - 1)->reverse() do ( if ((l[i+1] * 2->compareTo(l[j+1])) <= 0) then ( j := j - 1 ; c := c + 1 ) else skip) ; execute (j + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=sorted([int(input())for _ in range(n)]) r=n-1 count=0 for t in range((n//2)-1,-1,-1): if arr[t]*2<=arr[r]: r-=1 count+=1 print(n-count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))->sort() ; var r : double := n - 1 ; var count : int := 0 ; for t : Integer.subrange(-1 + 1, (n div 2) - 1)->reverse() do ( if (arr[t+1] * 2->compareTo(arr[r+1])) <= 0 then ( r := r - 1 ; count := count + 1 ) else skip) ; execute (n - count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import copy import collections from bisect import bisect_left from bisect import bisect_right from collections import defaultdict from heapq import heappop,heappush,heapify import math import itertools import random INF=float('inf') def inputInt(): return int(input()) def inputMap(): return map(int,input().split()) def inputList(): return list(map(int,input().split())) def main(): N=inputInt() K=inputInt() X=inputInt() Y=inputInt() if N<=K : print(N*X) else : print((K*X)+((N-K)*Y)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var INF : double := ("" + (('inf')))->toReal() ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation inputInt() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inputMap() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation inputList() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation main() pre: true post: true activity: var N : OclAny := inputInt() ; var K : OclAny := inputInt() ; var X : OclAny := inputInt() ; var Y : OclAny := inputInt() ; if (N->compareTo(K)) <= 0 then ( execute (N * X)->display() ) else ( execute ((K * X) + ((N - K) * Y))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=sorted(list(map(int,input().split()))) n=sum(l) if n % 2!=0 : print("NO") else : b=False for i in range(len(l)-2): for j in range(i+1,len(l)-1): for k in range(j+1,len(l)): if l[i]+l[j]+l[k]==n//2 : b=True ; break if b : break if b : break if b : break if b : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var n : OclAny := (l)->sum() ; if n mod 2 /= 0 then ( execute ("NO")->display() ) else ( var b : boolean := false ; for i : Integer.subrange(0, (l)->size() - 2-1) do ( for j : Integer.subrange(i + 1, (l)->size() - 1-1) do ( for k : Integer.subrange(j + 1, (l)->size()-1) do ( if l[i+1] + l[j+1] + l[k+1] = n div 2 then ( b := true; break ) else skip ; if b then ( break ) else skip) ; if b then ( break ) else skip) ; if b then ( break ) else skip) ; if b then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math t=input().lstrip("0") n=t.count("0") if n>=6 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : OclAny := input().lstrip("0") ; var n : int := t->count("0") ; if n >= 6 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def counting_kangaroos_is_fun(): sizes=[] for kangaroos in range(int(input())): sizes.append(int(input())) sizes.sort(reverse=True) half_length=len(sizes)//2+(len(sizes)//2*2=second_half[b]: visible-=1 a+=1 b+=1 elif btoInteger()-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : sizes)) ; sizes := sizes->sort() ; var half_length : int := (sizes)->size() div 2 + (((sizes)->size() div 2 * 2->compareTo((sizes)->size())) < 0) ; var first_half : OclAny := null; var second_half : OclAny := null; Sequence{first_half,second_half} := Sequence{sizes.subrange(1,half_length),sizes.subrange(half_length+1)} ; var visible : int := (sizes)->size() ; var a : int := 0 ; var b : int := 0 ; while (a->compareTo((first_half)->size())) < 0 & (b->compareTo((second_half)->size())) < 0 do ( if (first_half[a+1] / 2->compareTo(second_half[b+1])) >= 0 then ( visible := visible - 1 ; a := a + 1 ; b := b + 1 ) else (if (b->compareTo((second_half)->size())) < 0 then ( b := b + 1 ) else ( break ) ) ) ; execute (visible)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSet(arr,k,m): arr_size=len(arr); remainder_set=[0]*k ; for i in range(k): remainder_set[i]=[]; for i in range(arr_size): rem=arr[i]% k ; remainder_set[rem].append(arr[i]); for i in range(k): if(len(remainder_set[i])>=m): print("Yes"); for j in range(m): print(remainder_set[i][j],end=""); print("",end=""); return ; print("No"); arr=[5,8,9,12,13,7,11,15]; k=4 ; m=3 ; findSet(arr,k,m); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{5}->union(Sequence{8}->union(Sequence{9}->union(Sequence{12}->union(Sequence{13}->union(Sequence{7}->union(Sequence{11}->union(Sequence{ 15 }))))))); ; k := 4; ; m := 3; ; findSet(arr, k, m);; operation findSet(arr : OclAny, k : OclAny, m : OclAny) : OclAny pre: true post: true activity: var arr_size : int := (arr)->size(); ; var remainder_set : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, k); ; for i : Integer.subrange(0, k-1) do ( remainder_set[i+1] := Sequence{};) ; for i : Integer.subrange(0, arr_size-1) do ( var rem : int := arr[i+1] mod k; ; (expr (atom (name remainder_set)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name rem)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))));) ; for i : Integer.subrange(0, k-1) do ( if (((remainder_set[i+1])->size()->compareTo(m)) >= 0) then ( execute ("Yes")->display(); ; for j : Integer.subrange(0, m-1) do ( execute (remainder_set[i+1][j+1])->display(); ; execute ("")->display();) ; return; ) else skip) ; execute ("No")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findBalance(x,bal): if(x % 10==0 and(x+1.50)<=bal): print(round(bal-x-1.50,2)) else : print(round(bal,2)) x=50 bal=100.50 findBalance(x,bal) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := 50 ; bal := 100.50 ; findBalance(x, bal); operation findBalance(x : OclAny, bal : OclAny) pre: true post: true activity: if (x mod 10 = 0 & ((x + 1.50)->compareTo(bal)) <= 0) then ( execute (MathLib.roundN(bal - x - 1.50, 2))->display() ) else ( execute (MathLib.roundN(bal, 2))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def divisible(N,digit): ans=0 ; for i in range(len(N)): ans=(ans*10+(ord(N[i])-ord('0'))); ans %=digit ; return(ans==0); def allDigits(N): divide=[False]*10 ; divide[1]=True ; for digit in range(2,10): if(divisible(N,digit)): divide[digit]=True ; result=0 ; for i in range(len(N)): if(divide[(ord(N[i])-ord('0'))]==True): result+=1 ; return result ; N="122324" ; print(allDigits(N)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; N := "122324"; ; execute (allDigits(N))->display();; operation divisible(N : OclAny, digit : OclAny) pre: true post: true activity: var ans : int := 0; ; for i : Integer.subrange(0, (N)->size()-1) do ( ans := (ans * 10 + ((N[i+1])->char2byte() - ('0')->char2byte())); ; ans := ans mod digit;) ; return (ans = 0);; operation allDigits(N : OclAny) pre: true post: true activity: var divide : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, 10); ; divide[1+1] := true; ; for digit : Integer.subrange(2, 10-1) do ( if (divisible(N, digit)) then ( divide[digit+1] := true; ) else skip) ; var result : int := 0; ; for i : Integer.subrange(0, (N)->size()-1) do ( if (divide[((N[i+1])->char2byte() - ('0')->char2byte())+1] = true) then ( result := result + 1; ) else skip) ; return result;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n & 1 : x=n//2 else : if n % 4==0 : x=n//2-1 else : x=n//2-2 y=n-x print(x,y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if MathLib.bitwiseAnd(n, 1) then ( var x : int := n div 2 ) else ( if n mod 4 = 0 then ( x := n div 2 - 1 ) else ( x := n div 2 - 2 ) ) ; var y : double := n - x ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) if t % 2==0 : n=t//2 while n % 2==0 or n==t//2 : n-=1 print(f"{n}{t-n}") else : print(f"{t//2}{t//2+1}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if t mod 2 = 0 then ( var n : int := t div 2 ; while n mod 2 = 0 or n = t div 2 do ( n := n - 1) ; execute (StringLib.formattedString("{n}{t-n}"))->display() ) else ( execute (StringLib.formattedString("{t//2}{t//2+1}"))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a,b=0,0 listdiv1=[] listdiv2=[] if n % 2==0 : a=int(n/2)-1 b=int(n/2)+1 for i in range(2,a+1): if a % i==0 : listdiv1.append(i) for i in range(2,b): if b % i==0 : listdiv2.append(i) for i in listdiv1 : if i in listdiv2 : a-=1 b+=1 break else : a=int(n/2) b=int(n/2)+1 print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{0,0} ; var listdiv1 : Sequence := Sequence{} ; var listdiv2 : Sequence := Sequence{} ; if n mod 2 = 0 then ( var a : double := ("" + ((n / 2)))->toInteger() - 1 ; var b : int := ("" + ((n / 2)))->toInteger() + 1 ; for i : Integer.subrange(2, a + 1-1) do ( if a mod i = 0 then ( execute ((i) : listdiv1) ) else skip) ; for i : Integer.subrange(2, b-1) do ( if b mod i = 0 then ( execute ((i) : listdiv2) ) else skip) ; for i : listdiv1 do ( if (listdiv2)->includes(i) then ( a := a - 1 ; b := b + 1 ; break ) else skip) ) else ( a := ("" + ((n / 2)))->toInteger() ; b := ("" + ((n / 2)))->toInteger() + 1 ) ; execute (a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 4==0 : print(n//2-1,n//2+1) elif n % 2==0 : print(n//2-2,n//2+2) else : print(n//2,n//2+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 4 = 0 then ( execute (n div 2 - 1)->display() ) else (if n mod 2 = 0 then ( execute (n div 2 - 2)->display() ) else ( execute (n div 2)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): while b : a,b=b,a % b return abs(a) n=int(input()) a=n//2 b=n-a while gcd(a,b)!=1 : a-=1 b+=1 print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := n div 2 ; b := n - a ; while gcd(a, b) /= 1 do ( a := a - 1 ; b := b + 1) ; execute (a)->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: while b do ( Sequence{a,b} := Sequence{b,a mod b}) ; return (a)->abs(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- scores=list(map(int,input().split())) for a in range(len(scores)): for b in range(len(scores)): for c in range(len(scores)): for d in range(len(scores)): for e in range(len(scores)): for f in range(len(scores)): if a not in[b,c,d,e,f]and b not in[a,c,d,e,f]and c not in[a,b,d,e,f]and d not in[a,b,c,e,f]and e not in[a,b,c,d,f]and f not in[a,b,c,d,e]: if scores[a]+scores[b]+scores[c]==scores[d]+scores[e]+scores[f]: print("YES") exit() print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var scores : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for a : Integer.subrange(0, (scores)->size()-1) do ( for b : Integer.subrange(0, (scores)->size()-1) do ( for c : Integer.subrange(0, (scores)->size()-1) do ( for d : Integer.subrange(0, (scores)->size()-1) do ( for e : Integer.subrange(0, (scores)->size()-1) do ( for f : Integer.subrange(0, (scores)->size()-1) do ( if (Sequence{b}->union(Sequence{c}->union(Sequence{d}->union(Sequence{e}->union(Sequence{ f })))))->excludes(a) & (Sequence{a}->union(Sequence{c}->union(Sequence{d}->union(Sequence{e}->union(Sequence{ f })))))->excludes(b) & (Sequence{a}->union(Sequence{b}->union(Sequence{d}->union(Sequence{e}->union(Sequence{ f })))))->excludes(c) & (Sequence{a}->union(Sequence{b}->union(Sequence{c}->union(Sequence{e}->union(Sequence{ f })))))->excludes(d) & (Sequence{a}->union(Sequence{b}->union(Sequence{c}->union(Sequence{d}->union(Sequence{ f })))))->excludes(e) & (Sequence{a}->union(Sequence{b}->union(Sequence{c}->union(Sequence{d}->union(Sequence{ e })))))->excludes(f) then ( if scores[a+1] + scores[b+1] + scores[c+1] = scores[d+1] + scores[e+1] + scores[f+1] then ( execute ("YES")->display() ; exit() ) else skip ) else skip)))))) ; execute ("NO")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def getMinimumSum(arr,n): ans=sys.maxsize ; for i in range(n-2): for j in range(i+1,n-1): for k in range(j+1,n): ans=min(ans,arr[i]+arr[j]+arr[k]); return ans ; if __name__=='__main__' : arr=[1,2,3,4,5,-1,5,-2]; n=len(arr); print(getMinimumSum(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{-1}->union(Sequence{5}->union(Sequence{ -2 }))))))); ; n := (arr)->size(); ; execute (getMinimumSum(arr, n))->display(); ) else skip; operation getMinimumSum(arr : OclAny, n : OclAny) pre: true post: true activity: var ans : (trailer . (name maxsize)) := (trailer . (name maxsize)); ; for i : Integer.subrange(0, n - 2-1) do ( for j : Integer.subrange(i + 1, n - 1-1) do ( for k : Integer.subrange(j + 1, n-1) do ( ans := Set{ans, arr[i+1] + arr[j+1] + arr[k+1]}->min();))) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) s=str(a) count=0 for i in s : if i=="0" : count+=1 if(count>=6): print("yes") else : print("no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := ("" + ((a))) ; var count : int := 0 ; for i : s->characters() do ( if i = "0" then ( count := count + 1 ) else skip) ; if (count >= 6) then ( execute ("yes")->display() ) else ( execute ("no")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getPairsCount(arr,n,sum): count=0 for i in range(0,n): for j in range(i+1,n): if arr[i]+arr[j]==sum : count+=1 return count arr=[1,5,7,-1,5] n=len(arr) sum=6 print("Count of pairs is",getPairsCount(arr,n,sum)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{5}->union(Sequence{7}->union(Sequence{-1}->union(Sequence{ 5 })))) ; n := (arr)->size() ; sum := 6 ; execute ("Count of pairs is")->display(); operation getPairsCount(arr : OclAny, n : OclAny, sum : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if arr[i+1] + arr[j+1] = sum then ( count := count + 1 ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getInvCount(arr,n): inv_count=0 for i in range(n): for j in range(i+1,n): if(arr[i]>arr[j]): inv_count+=1 return inv_count arr=[1,20,6,4,5] n=len(arr) print("Number of inversions are",getInvCount(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{20}->union(Sequence{6}->union(Sequence{4}->union(Sequence{ 5 })))) ; n := (arr)->size() ; execute ("Number of inversions are")->display(); operation getInvCount(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var inv_count : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if ((arr[i+1]->compareTo(arr[j+1])) > 0) then ( inv_count := inv_count + 1 ) else skip)) ; return inv_count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPalindrome(str): n=len(str) for i in range(n//2): if(str[i]!=str[n-i-1]): return False return True def maxLengthNonPalinSubstring(str): n=len(str) ch=str[0] i=1 for i in range(1,n): if(str[i]!=ch): break if(i==n): return 0 if(isPalindrome(str)): return n-1 return n if __name__=="__main__" : str="abba" print("Maximum length=",maxLengthNonPalinSubstring(str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( OclType["String"] := "abba" ; execute ("Maximum length=")->display() ) else skip; operation isPalindrome(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var n : int := (OclType["String"])->size() ; for i : Integer.subrange(0, n div 2-1) do ( if (("" + ([i+1])) /= ("" + ([n - i - 1+1]))) then ( return false ) else skip) ; return true; operation maxLengthNonPalinSubstring(OclType["String"] : OclAny) : OclAny pre: true post: true activity: n := (OclType["String"])->size() ; var ch : String := ("" + (->first())) ; var i : int := 1 ; for i : Integer.subrange(1, n-1) do ( if (("" + ([i+1])) /= ch) then ( break ) else skip) ; if (i = n) then ( return 0 ) else skip ; if (isPalindrome(OclType["String"])) then ( return n - 1 ) else skip ; return n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def power(x,y,p): res=1 x=x % p while y>0 : if y & 1 : res=(res*x)% p y=y>>1 x=(x*x)% p return res def NearestElement(A,D,P): if A==0 : return 0 elif D==0 : return-1 else : X=power(D,P-2,P) return(X*(P-A))% P if __name__=="__main__" : A,D,P=4,9,11 A %=P D %=P print(NearestElement(A,D,P)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( Sequence{A,D,P} := Sequence{4,9,11} ; A := A mod P ; D := D mod P ; execute (NearestElement(A, D, P))->display() ) else skip; operation power(x : OclAny, y : OclAny, p : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; x := x mod p ; while y > 0 do ( if MathLib.bitwiseAnd(y, 1) then ( res := (res * x) mod p ) else skip ; y := y /(2->pow(1)) ; x := (x * x) mod p) ; return res; operation NearestElement(A : OclAny, D : OclAny, P : OclAny) : OclAny pre: true post: true activity: if A = 0 then ( return 0 ) else (if D = 0 then ( return -1 ) else ( var X : OclAny := power(D, P - 2, P) ; return (X * (P - A)) mod P ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Rate(N1,N2): rate=(N2-N1)*100//(N1); return rate if __name__=="__main__" : N1=100 N2=120 print(Rate(N1,N2)," %") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N1 := 100 ; N2 := 120 ; execute (Rate(N1, N2))->display() ) else skip; operation Rate(N1 : OclAny, N2 : OclAny) : OclAny pre: true post: true activity: var rate : int := (N2 - N1) * 100 div (N1); ; return rate; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,k1,k2=map(int,input().split()) w,b=map(int,input().split()) p=k1+k2 m=2*n q=m-p if p>=2*w and q>=2*b : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k1 : OclAny := null; var k2 : OclAny := null; Sequence{n,k1,k2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : OclAny := null; var b : OclAny := null; Sequence{w,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : OclAny := k1 + k2 ; var m : double := 2 * n ; var q : double := m - p ; if (p->compareTo(2 * w)) >= 0 & (q->compareTo(2 * b)) >= 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): n,k1,k2=map(int,input().split()) w,b=map(int,input().split()) s=k1+k2 g=2*n g-=s if(s//2>=w and g//2>=b): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var k1 : OclAny := null; var k2 : OclAny := null; Sequence{n,k1,k2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : OclAny := null; var b : OclAny := null; Sequence{w,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := k1 + k2 ; var g : int := 2 * n ; g := g - s ; if ((s div 2->compareTo(w)) >= 0 & (g div 2->compareTo(b)) >= 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k1,k2,=[int(x)for x in input().split()] w,b=[int(x)for x in input().split()] if(k1+k2)//2toInteger()-1) do ( var n : OclAny := null; var k1 : OclAny := null; (declareIfNecessary (test (logical_test (comparison (expr (atom (name k2)))))) ,) Sequence{n,k1,(testlist_star_expr (test (logical_test (comparison (expr (atom (name k2)))))) ,)} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var w : OclAny := null; var b : OclAny := null; Sequence{w,b} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if ((k1 + k2) div 2->compareTo(w)) < 0 or ((2 * n - k1 - k2) div 2->compareTo(b)) < 0 then ( execute ('NO')->display() ) else ( execute ('YES')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def _popcnt32(number): counter=0 while(number>0): if(number % 2==1): counter=counter+1 number=int(number/2) return counter def maximize(a): n=_popcnt32(a) res=0 for i in range(1,n+1): res=int(res |(1<<(32-i))) return abs(res) a=1 print(maximize(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := 1 ; execute (maximize(a))->display(); operation _popcnt32(number : OclAny) : OclAny pre: true post: true activity: var counter : int := 0 ; while (number > 0) do ( if (number mod 2 = 1) then ( counter := counter + 1 ) else skip ; number := ("" + ((number / 2)))->toInteger()) ; return counter; operation maximize(a : OclAny) : OclAny pre: true post: true activity: var n : OclAny := _popcnt32(a) ; var res : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( res := ("" + ((MathLib.bitwiseOr(res, (1 * (2->pow((32 - i))))))))->toInteger()) ; return (res)->abs(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while(t>0): n,k1,k2=map(int,input().split()) w,b=map(int,input().split()) if(b<=((n-k1)+(n-k2))/2 and w<=(k1+k2)/2): print("YES") else : print("NO") t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (t > 0) do ( var n : OclAny := null; var k1 : OclAny := null; var k2 : OclAny := null; Sequence{n,k1,k2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : OclAny := null; var b : OclAny := null; Sequence{w,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if ((b->compareTo(((n - k1) + (n - k2)) / 2)) <= 0 & (w->compareTo((k1 + k2) / 2)) <= 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) t,=R() exec(t*"n,*a=R();w,b=R();print('NYOE S'[2*w<=sum(a)<=n-b<<1::2]);") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := R->apply() ; (expr (expr (atom (name t))) * (expr (atom "n,*a=R();w,b=R();print('NYOE S'[2*w<=sum(a)<=n-b<<1::2]);"))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() sequencia=list(map(int,input().split())) elementos_filtrados=set() conta_elementos_filtrados=0 resultado="" for i in range(len(sequencia)-1,-1,-1): if not sequencia[i]in elementos_filtrados : elementos_filtrados.add(sequencia[i]) conta_elementos_filtrados+=1 if i==len(sequencia)-1 : resultado=str(sequencia[i])+resultado else : resultado=str(sequencia[i])+" "+resultado print(conta_elementos_filtrados) print(resultado) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var sequencia : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var elementos_filtrados : Set := Set{}->union(()) ; var conta_elementos_filtrados : int := 0 ; var resultado : String := "" ; for i : Integer.subrange(-1 + 1, (sequencia)->size() - 1)->reverse() do ( if not((elementos_filtrados)->includes(sequencia[i+1])) then ( execute ((sequencia[i+1]) : elementos_filtrados) ; conta_elementos_filtrados := conta_elementos_filtrados + 1 ; if i = (sequencia)->size() - 1 then ( resultado := ("" + ((sequencia[i+1]))) + resultado ) else ( resultado := ("" + ((sequencia[i+1]))) + " " + resultado ) ) else skip) ; execute (conta_elementos_filtrados)->display() ; execute (resultado)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(input().split())[0] first_1_found=False zero_cnt=0 for i in s : if i=='1' and not first_1_found : first_1_found=True elif i=='0' and first_1_found : zero_cnt+=1 if zero_cnt==6 : print("yes") exit(0) print("no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := OclType["Sequence"](input().split())->first() ; var first var s : OclAny := OclType["Sequence"](input().split())->first()_found : boolean := false ; var zero_cnt : int := 0 ; for i : s do ( if i = '1' & not(first var s : OclAny := OclType["Sequence"](input().split())->first()_found) then ( first var s : OclAny := OclType["Sequence"](input().split())->first()_found := true ) else (if i = '0' & first var s : OclAny := OclType["Sequence"](input().split())->first()_found then ( zero_cnt := zero_cnt + 1 ; if zero_cnt = 6 then ( execute ("yes")->display() ; exit(0) ) else skip ) else skip)) ; execute ("no")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() a=sorted(map(int,input().split())) b=[a.pop(0)] c=a[-1]>0 and[a.pop()]or[a.pop(0),a.pop(0)] for L in b,c,a : print(len(L),*L) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var b : Sequence := Sequence{ a->at(0`firstArg+1) } ; var c : boolean := a->last() > 0 & Sequence{ a->last() } or Sequence{a->at(0`firstArg+1)}->union(Sequence{ a->at(0`firstArg+1) }) ; for L : b, c, a do ( execute ((L)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=sorted(list(map(int,input().split()))) s1=[] s2=[] s3=[0] bz=s[: s.index(0)] az=s[s.index(0)+1 :] if len(bz)% 2==0 : s1.extend([bz[0]]) s2.extend(bz[2 :]) s3.extend([bz[1]]) elif len(bz)% 2!=0 and len(az)==0 : s1.extend([bz[0]]) s2.extend(bz[1 :]) elif len(bz)% 2!=0 : s1.extend(bz) s2.extend(az) print(len(s1),*s1) print(len(s2),*s2) print(len(s3),*s3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var s1 : Sequence := Sequence{} ; var s2 : Sequence := Sequence{} ; var s3 : Sequence := Sequence{ 0 } ; var bz : OclAny := s.subrange(1,s->indexOf(0) - 1) ; var az : OclAny := s.subrange(s->indexOf(0) - 1 + 1+1) ; if (bz)->size() mod 2 = 0 then ( s1 := s1->union(Sequence{ bz->first() }) ; s2 := s2->union(bz.subrange(2+1)) ; s3 := s3->union(Sequence{ bz[1+1] }) ) else (if (bz)->size() mod 2 /= 0 & (az)->size() = 0 then ( s1 := s1->union(Sequence{ bz->first() }) ; s2 := s2->union(bz->tail()) ) else (if (bz)->size() mod 2 /= 0 then ( s1 := s1->union(bz) ) else skip ) ) ; s2 := s2->union(az) ; execute ((s1)->size())->display() ; execute ((s2)->size())->display() ; execute ((s3)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) m=0 p=0 b=[] c=[] for i in a : if i<0 : b.append(i) m+=1 elif i>0 : c.append(i) p+=1 z=n-m-p print(1,b[0]) if p==0 : print(2,b[1],b[2]) print(m-3+z,*b[3 :],"0 "*z) else : print(p,*c) print(m-1+z,*b[1 :],"0 "*z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := 0 ; var p : int := 0 ; var b : Sequence := Sequence{} ; var c : Sequence := Sequence{} ; for i : a do ( if i < 0 then ( execute ((i) : b) ; m := m + 1 ) else (if i > 0 then ( execute ((i) : c) ; p := p + 1 ) else skip)) ; var z : double := n - m - p ; execute (1)->display() ; if p = 0 then ( execute (2)->display() ; execute (m - 3 + z)->display() ) else ( execute (p)->display() ; execute (m - 1 + z)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def divide_group(n,a): result=[[],[],[],] num_am=[] for item in a : if item<0 and len(result[0])<1 : result[0].append(item) elif item>0 : result[1].append(item) elif item==0 : result[2].append(item) else : num_am.append(item) if len(result[1])==0 and len(num_am)% 2==0 : for item in num_am : result[1].append(item) elif len(result[1])==0 and len(num_am)% 2!=0 : for i in range(0,len(num_am)): if i<2 : result[1].append(num_am[i]) elif i==2 : result[2].append(num_am[i]) else : result[0].append(num_am[i]) else : for item in num_am : result[2].append(item) return result n=int(input()) a=list(map(int,input().split())) result=divide_group(n,a) for item in result : print(len(item),end=" ") for var in item : print(var,end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; result := divide_group(n, a) ; for item : result do ( execute ((item)->size())->display() ; for var : item do ( execute (var)->display()) ; execute (->display()); operation divide_group(n : OclAny, a : OclAny) : OclAny pre: true post: true activity: var result : Sequence := Sequence{Sequence{}}->union(Sequence{Sequence{}}->union(Sequence{ Sequence{} })) ; var num_am : Sequence := Sequence{} ; for item : a do ( if item < 0 & (result->first())->size() < 1 then ( (expr (atom (name result)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name item)))))))) )))) ) else (if item > 0 then ( (expr (atom (name result)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name item)))))))) )))) ) else (if item = 0 then ( (expr (atom (name result)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name item)))))))) )))) ) else ( execute ((item) : num_am) ) ) ) ) ; if (result[1+1])->size() = 0 & (num_am)->size() mod 2 = 0 then ( for item : num_am do ((expr (atom (name result)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name item)))))))) ))))) ) else (if (result[1+1])->size() = 0 & (num_am)->size() mod 2 /= 0 then ( for i : Integer.subrange(0, (num_am)->size()-1) do ( if i < 2 then ( (expr (atom (name result)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num_am)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))) ) else (if i = 2 then ( (expr (atom (name result)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num_am)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))) ) else ( (expr (atom (name result)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num_am)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))) ) ) ) ) else ( for item : num_am do ((expr (atom (name result)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name item)))))))) ))))) ) ) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) aa=[] bb=[] cc=[] for i in a : if i<0 : aa.append(i) elif i>0 : bb.append(i) else : cc.append(i) l=[] g=[] z=[] l.append(aa[0]) minus=0 if len(bb)==0 : if(len(aa)-1)% 2==0 : g=aa[1 :] minus=len(g) else : g=aa[1 : len(aa)-1] minus=len(g) else : g=bb if len(aa)-(1+minus)==0 : z=[0] else : z=cc+aa[(1+minus):] ans="" for i in range(len(l)): if i==0 : ans+=str(len(l))+" " ans+=str(l[i])+" " ans+="\n" for i in range(len(g)): if i==0 : ans+=str(len(g))+" " ans+=str(g[i])+" " ans+="\n" for i in range(len(z)): if i==0 : ans+=str(len(z))+" " ans+=str(z[i])+" " print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var aa : Sequence := Sequence{} ; var bb : Sequence := Sequence{} ; var cc : Sequence := Sequence{} ; for i : a do ( if i < 0 then ( execute ((i) : aa) ) else (if i > 0 then ( execute ((i) : bb) ) else ( execute ((i) : cc) ) ) ) ; var l : Sequence := Sequence{} ; var g : Sequence := Sequence{} ; var z : Sequence := Sequence{} ; execute ((aa->first()) : l) ; var minus : int := 0 ; if (bb)->size() = 0 then ( if ((aa)->size() - 1) mod 2 = 0 then ( g := aa->tail() ; minus := (g)->size() ) else ( g := aa.subrange(1+1, (aa)->size() - 1) ; minus := (g)->size() ) ) else ( g := bb ) ; if (aa)->size() - (1 + minus) = 0 then ( z := Sequence{ 0 } ) else ( z := cc->union(aa.subrange((1 + minus)+1)) ) ; var ans : String := "" ; for i : Integer.subrange(0, (l)->size()-1) do ( if i = 0 then ( ans := ans + ("" + (((l)->size()))) + " " ) else skip ; ans := ans + ("" + ((l[i+1]))) + " ") ; ans := ans + "\n" ; for i : Integer.subrange(0, (g)->size()-1) do ( if i = 0 then ( ans := ans + ("" + (((g)->size()))) + " " ) else skip ; ans := ans + ("" + ((g[i+1]))) + " ") ; ans := ans + "\n" ; for i : Integer.subrange(0, (z)->size()-1) do ( if i = 0 then ( ans := ans + ("" + (((z)->size()))) + " " ) else skip ; ans := ans + ("" + ((z[i+1]))) + " ") ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthElement(a,b,n): seq=[]; for i in range(1,n+1): seq.append(a*i); seq.sort(); i=1 ; k=n ; while(i<=n and k>0): try : z=seq.index(b*i); except ValueError : seq.append(b*i); seq.sort(); k-=1 ; i+=1 ; return seq[n-1]; a=3 ; b=5 ; n=5 ; print(nthElement(a,b,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 3; ; b := 5; ; n := 5; ; execute (nthElement(a, b, n))->display();; operation nthElement(a : OclAny, b : OclAny, n : OclAny) pre: true post: true activity: var seq : Sequence := Sequence{}; ; for i : Integer.subrange(1, n + 1-1) do ( execute ((a * i) : seq);) ; seq := seq->sort(); ; var i : int := 1; ; var k : OclAny := n; ; while ((i->compareTo(n)) <= 0 & k > 0) do ( try ( var z : int := seq->indexOf(b * i) - 1;) (except_clause except (test (logical_test (comparison (expr (atom (name ValueError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name seq)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name b))) * (expr (atom (name i))))))))) )))))))))) ;)) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name seq)) (trailer . (name sort) (arguments ( )))))))))) ;)) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name k)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))) ;)))) ; i := i + 1;) ; return seq[n - 1+1];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,k=map(int,input().split()) lst=list(map(int,input().split())) cnt=0 for i in range(k): if lst[i]>k : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : int := 0 ; for i : Integer.subrange(0, k-1) do ( if (lst[i+1]->compareTo(k)) > 0 then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for iteretor in range(t): n=int(input()) lst=list(map(int,input().split())) if n<5 : print(0,0,0) continue dicts={} max=n//2 b=0 for i in lst : if i in dicts : dicts[i]+=1 else : dicts[i]=1 for i in dicts : if b+dicts[i]>max : break b+=dicts[i] i,g=1,dicts[list(dicts)[0]] b,s=b-g,0 while ig and s<=g : s+=dicts[list(dicts)[i]] b-=dicts[list(dicts)[i]] i+=1 if s<=g or b<=g : print(0,0,0) else : print(g,s,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for iteretor : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n < 5 then ( execute (0)->display() ; continue ) else skip ; var dicts : OclAny := Set{} ; var max : int := n div 2 ; var b : int := 0 ; for i : lst do ( if (dicts)->includes(i) then ( dicts[i+1] := dicts[i+1] + 1 ) else ( dicts[i+1] := 1 )) ; for i : dicts do ( if (b + dicts[i+1]->compareTo(max)) > 0 then ( break ) else skip ; b := b + dicts[i+1]) ; var i : OclAny := null; var g : OclAny := null; Sequence{i,g} := Sequence{1,dicts[OclType["Sequence"](dicts)->first()+1]} ; var s : OclAny := null; Sequence{b,s} := Sequence{b - g,0} ; while (i->compareTo(((dicts))->size())) < 0 & (b - dicts[OclType["Sequence"](dicts)[i+1]+1]->compareTo(g)) > 0 & (s->compareTo(g)) <= 0 do ( s := s + dicts[OclType["Sequence"](dicts)[i+1]+1] ; b := b - dicts[OclType["Sequence"](dicts)[i+1]+1] ; i := i + 1) ; if (s->compareTo(g)) <= 0 or (b->compareTo(g)) <= 0 then ( execute (0)->display() ) else ( execute (g)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) l2=[] o=1 for i in range(n//2): if l[i]==l[i+1]: o+=1 else : l2.append(o) o=1 q=len(l2) g,s,b=0,0,0 if q>2 : g=l2[0] i=1 while itoInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l2 : Sequence := Sequence{} ; var o : int := 1 ; for i : Integer.subrange(0, n div 2-1) do ( if l[i+1] = l[i + 1+1] then ( o := o + 1 ) else ( execute ((o) : l2) ; o := 1 )) ; var q : int := (l2)->size() ; var g : OclAny := null; var s : OclAny := null; var b : OclAny := null; Sequence{g,s,b} := Sequence{0,0,0} ; if q > 2 then ( var g : OclAny := l2->first() ; var i : int := 1 ; while (i->compareTo(q)) < 0 & (s->compareTo(g)) <= 0 do ( s := s + l2[i+1] ; i := i + 1) ; for j : Integer.subrange(i, q-1) do ( b := b + l2[j+1]) ) else skip ; if (g->compareTo(s)) < 0 & (g->compareTo(b)) < 0 then ( execute (g)->display() ) else ( execute (0)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t=int(input()) ans=[] inf=pow(10,9)+1 for _ in range(t): n=int(input()) p=list(map(int,input().split())) la=inf x=[] c=0 for i in p : if la ^ i : if c : x.append(c) c=1 la=i else : c+=1 x.append(c) l=len(x) for i in range(1,l): x[i]+=x[i-1] x.append(inf) g,s,b=0,0,0 g0=x[0] i,j=0,0 while itoInteger() ; var ans : Sequence := Sequence{} ; var Math_PINFINITY : double := (10)->pow(9) + 1 ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var la : double := Math_PINFINITY ; var x : Sequence := Sequence{} ; var c : int := 0 ; for i : p do ( if MathLib.bitwiseXor(la, i) then ( if c then ( execute ((c) : x) ) else skip ; c := 1 ; la := i ) else ( c := c + 1 )) ; execute ((c) : x) ; var l : int := (x)->size() ; for i : Integer.subrange(1, l-1) do ( x[i+1] := x[i+1] + x[i - 1+1]) ; execute ((Math_PINFINITY) : x) ; var g : OclAny := null; var s : OclAny := null; var b : OclAny := null; Sequence{g,s,b} := Sequence{0,0,0} ; var g0 : OclAny := x->first() ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,0} ; while (i->compareTo(l)) < 0 & (x[i+1] - g0->compareTo(g0)) <= 0 do ( i := i + 1) ; while (j->compareTo(l)) < 0 & (2 * x[j+1]->compareTo(n)) <= 0 do ( j := j + 1) ; j := j - 1 ; if (Set{i, j}->max()->compareTo(l)) < 0 then ( var s0 : OclAny := null; var b0 : OclAny := null; Sequence{s0,b0} := Sequence{x[i+1] - g0,x[j+1] - x[i+1]} ; if (g0->compareTo(s0)) < 0 & (g0->compareTo(b0)) < 0 then ( var g : OclAny := null; var s : OclAny := null; var b : OclAny := null; Sequence{g,s,b} := Sequence{g0,s0,b0} ) else skip ) else skip ; execute ((StringLib.sumStringsWithSeparator(((Sequence{g, s, b})->collect( _x | (OclType["String"])->apply(_x) )), " ")) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : t=t-1 n=int(input()) a=list(map(int,input().split())) cnt={} vals=[] for i in a : if i in cnt : cnt[i]=cnt[i]+1 else : vals.append(i) cnt[i]=1 gold=cnt[vals[0]] silver=0 p=1 while silver<=gold and pn or gold>=silver or gold>=bronze : print("0 0 0") continue print(gold,silver,bronze) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( t := t - 1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : OclAny := Set{} ; var vals : Sequence := Sequence{} ; for i : a do ( if (cnt)->includes(i) then ( cnt[i+1] := cnt[i+1] + 1 ) else ( execute ((i) : vals) ; cnt[i+1] := 1 )) ; var gold : OclAny := cnt[vals->first()+1] ; var silver : int := 0 ; var p : int := 1 ; while (silver->compareTo(gold)) <= 0 & (p->compareTo((vals)->size())) < 0 do ( silver := silver + cnt[vals[p+1]+1] ; p := p + 1) ; var bronze : int := 0 ; while (bronze->compareTo(gold)) <= 0 & (p->compareTo((vals)->size())) < 0 do ( bronze := bronze + cnt[vals[p+1]+1] ; p := p + 1) ; while (p->compareTo((vals)->size())) < 0 & (2 * (gold + silver + bronze + cnt[vals[p+1]+1])->compareTo(n)) <= 0 do ( bronze := bronze + cnt[vals[p+1]+1] ; p := p + 1) ; if (2 * (silver + bronze + gold)->compareTo(n)) > 0 or (gold->compareTo(silver)) >= 0 or (gold->compareTo(bronze)) >= 0 then ( execute ("0 0 0")->display() ; continue ) else skip ; execute (gold)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() i=s.find('1') cnt=0 for c in s[i :]: if c=='0' : cnt+=1 print("yes" if cnt>=6 else "no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var i : int := s->indexOf('1') - 1 ; var cnt : int := 0 ; for c : s.subrange(i+1) do ( if c = '0' then ( cnt := cnt + 1 ) else skip) ; execute (if cnt >= 6 then "yes" else "no" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) cnt={} vals=[] le=0 for i in a : if i in cnt : cnt[i]+=1 else : vals.append(i) le+=1 cnt[i]=1 gold=cnt[vals[0]] silver=0 i=1 while silver<=gold and in or gold>=silver or gold>=bronze : print("0 0 0") continue print(gold,silver,bronze) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : OclAny := Set{} ; var vals : Sequence := Sequence{} ; var le : int := 0 ; for i : a do ( if (cnt)->includes(i) then ( cnt[i+1] := cnt[i+1] + 1 ) else ( execute ((i) : vals) ; le := le + 1 ; cnt[i+1] := 1 )) ; var gold : OclAny := cnt[vals->first()+1] ; var silver : int := 0 ; var i : int := 1 ; while (silver->compareTo(gold)) <= 0 & (i->compareTo(le)) < 0 do ( silver := silver + cnt[vals[i+1]+1] ; i := i + 1) ; var bronze : int := 0 ; while (bronze->compareTo(gold)) <= 0 & (i->compareTo(le)) < 0 do ( bronze := bronze + cnt[vals[i+1]+1] ; i := i + 1) ; while (i->compareTo(le)) < 0 & (2 * (gold + silver + bronze + cnt[vals[i+1]+1])->compareTo(n)) <= 0 do ( bronze := bronze + cnt[vals[i+1]+1] ; i := i + 1) ; if (2 * (silver + bronze + gold)->compareTo(n)) > 0 or (gold->compareTo(silver)) >= 0 or (gold->compareTo(bronze)) >= 0 then ( execute ("0 0 0")->display() ; continue ) else skip ; execute (gold)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for tc in range(int(input())): n=int(input()) a=list(map(int,input().split())) m=int(input()) b=list(map(int,input().split())) x=sum(b) print(a[x % n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for tc : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := (b)->sum() ; execute (a[x mod n+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) m=int(input()) print(a[sum(map(int,input().split()))% n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (a[((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum() mod n+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) m=int(input()) c=0 for i in map(int,input().split()): c+=i c %=n print(a[c]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := 0 ; for i : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( c := c + i ; c := c mod n) ; execute (a[c+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solution(n,a,m,b): summ=0 for e in b : summ+=e summ=summ % n return a[summ] t=int(input()) while t : n=int(input()) a=[int(x)for x in input().strip().split(" ")] m=int(input()) b=[int(x)for x in input().strip().split(" ")] print(solution(n,a,m,b)) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := input()->trim().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; m := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; b := input()->trim().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (solution(n, a, m, b))->display() ; t := t - 1); operation solution(n : OclAny, a : OclAny, m : OclAny, b : OclAny) : OclAny pre: true post: true activity: var summ : int := 0 ; for e : b do ( summ := summ + e) ; summ := summ mod n ; return a[summ+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): pair=input().split() t=int(input()) print(pair[0],pair[1]) for _ in range(t): n1,n2=input().split() if pair[0]==n1 : pair=(n2,pair[1]) else : pair=(pair[0],n2) print(pair[0],pair[1]) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var pair : OclAny := input().split() ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (pair->first())->display() ; for _anon : Integer.subrange(0, t-1) do ( var n1 : OclAny := null; var n2 : OclAny := null; Sequence{n1,n2} := input().split() ; if pair->first() = n1 then ( pair := Sequence{n2, pair[1+1]} ) else ( pair := Sequence{pair->first(), n2} ) ; execute (pair->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): sum1=0 v=int(input()) ninp=input() n=ninp.split() j=int(input()) binp=input() b=binp.split() for x in b : sum1+=int(x) sum1 %=len(n) print(int(n[sum1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var sum1 : int := 0 ; var v : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ninp : String := (OclFile["System.in"]).readLine() ; var n : OclAny := ninp.split() ; var j : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var binp : String := (OclFile["System.in"]).readLine() ; var b : OclAny := binp.split() ; for x : b do ( sum1 := sum1 + ("" + ((x)))->toInteger()) ; sum1 := sum1 mod (n)->size() ; execute (("" + ((n[sum1+1])))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import functools def my_cmp(o1,o2): cnt=0 for i in range(5): if o1[i]=3 else 1 for _ in range(int(input())): n=int(input()) a=[list(map(int,input().split()))+[i+1]for i in range(n)] candidate=a[0] for i in range(1,n): if my_cmp(candidate,a[i])>0 : candidate=a[i] good=True for i in range(0,n): if a[i]!=candidate and my_cmp(candidate,a[i])>0 : good=False break if good : print(candidate[5]) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->union(Sequence{ i + 1 }))) ; var candidate : OclAny := a->first() ; for i : Integer.subrange(1, n-1) do ( if my_cmp(candidate, a[i+1]) > 0 then ( candidate := a[i+1] ) else skip) ; var good : boolean := true ; for i : Integer.subrange(0, n-1) do ( if a[i+1] /= candidate & my_cmp(candidate, a[i+1]) > 0 then ( good := false ; break ) else skip) ; if good then ( execute (candidate[5+1])->display() ) else ( execute (-1)->display() )); operation my_cmp(o1 : OclAny, o2 : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; for i : Integer.subrange(0, 5-1) do ( if (o1[i+1]->compareTo(o2[i+1])) < 0 then ( cnt := cnt + 1 ) else skip) ; return if cnt >= 3 then -1 else 1 endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for w in range(t): fl=True n=int(input()) C=[] asm=1 A=[[0]*5 for i in range(n)] i=0 for j in input().split(): C.append(int(j)) A[0][i]=int(j) i+=1 for i in range(n-1): B=[] iii=0 for j in input().split(): B.append(int(j)) A[i+1][iii]=int(j) iii+=1 CC=0 BB=0 for ii in range(5): if C[ii]BB : pass else : C=B asm=i+2 for i in range(n): AA=0 CC=0 for j in range(5): if A[i][j]CC : print(-1) fl=False break if fl : print(asm) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for w : Integer.subrange(0, t-1) do ( var fl : boolean := true ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var C : Sequence := Sequence{} ; var asm : int := 1 ; var A : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, 5))) ; var i : int := 0 ; for j : input().split() do ( execute ((("" + ((j)))->toInteger()) : C) ; A->first()[i+1] := ("" + ((j)))->toInteger() ; i := i + 1) ; for i : Integer.subrange(0, n - 1-1) do ( var B : Sequence := Sequence{} ; var iii : int := 0 ; for j : input().split() do ( execute ((("" + ((j)))->toInteger()) : B) ; A[i + 1+1][iii+1] := ("" + ((j)))->toInteger() ; iii := iii + 1) ; var CC : int := 0 ; var BB : int := 0 ; for ii : Integer.subrange(0, 5-1) do ( if (C[ii+1]->compareTo(B[ii+1])) < 0 then ( CC := CC + 1 ) else ( BB := BB + 1 )) ; if (CC->compareTo(BB)) > 0 then ( skip ) else ( C := B ; asm := i + 2 )) ; for i : Integer.subrange(0, n-1) do ( var AA : int := 0 ; CC := 0 ; for j : Integer.subrange(0, 5-1) do ( if (A[i+1][j+1]->compareTo(C[j+1])) < 0 then ( AA := AA + 1 ) else ( CC := CC + 1 )) ; if (AA->compareTo(CC)) > 0 then ( execute (-1)->display() ; fl := false ; break ) else skip) ; if fl then ( execute (asm)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): n=int(input()) pob=[500000001,5000000001,500000001,500000001,500000001] r=-1 k=[] for j in range(n): v=list(map(int,input().split())) c=0 for kk in zip(pob,v): if kk[0]toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var pob : Sequence := Sequence{500000001}->union(Sequence{5000000001}->union(Sequence{500000001}->union(Sequence{500000001}->union(Sequence{ 500000001 })))) ; var r : int := -1 ; var k : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( var v : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; for kk : Integer.subrange(1, pob->size())->collect( _indx | Sequence{pob->at(_indx), v->at(_indx)} ) do ( if (kk->first()->compareTo(kk[1+1])) < 0 then ( c := c + 1 ) else skip) ; if c < 3 then ( pob := v ; r := j + 1 ) else skip ; execute ((v) : k)) ; var no : boolean := false ; for v : k do ( c := 0 ; for kk : Integer.subrange(1, pob->size())->collect( _indx | Sequence{pob->at(_indx), v->at(_indx)} ) do ( if (kk->first()->compareTo(kk[1+1])) <= 0 then ( c := c + 1 ) else skip) ; if c < 3 then ( execute (-1)->display() ; no := true ; break ) else skip) ; if not(no) then ( execute (r)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().rstrip() def check(r,a,b): return sum([r[a][i]>r[b][i]for i in range(5)])>2 def solve(): N=int(input()) r=[list(map(int,input().split()))for i in range(N)] cand=0 for i in range(1,N): if check(r,cand,i): cand=i for i in range(N): if check(r,cand,i)and cand!=i : return-1 return cand+1 T=int(input()) for i in range(T): print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; skip ; skip ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, T-1) do ( execute (solve())->display()); operation check(r : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (Integer.subrange(0, 5-1)->select(i | true)->collect(i | ((r[a+1][i+1]->compareTo(r[b+1][i+1])) > 0)))->sum() > 2; operation solve() : OclAny pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; r := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var cand : int := 0 ; for i : Integer.subrange(1, N-1) do ( if check(r, cand, i) then ( cand := i ) else skip) ; for i : Integer.subrange(0, N-1) do ( if check(r, cand, i) & cand /= i then ( return -1 ) else skip) ; return cand + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) def solve(arr): minNeededAfterSwapToBeIncreasing=0 haveNumberAfterSwap=0 ans=True for i in range(len(arr)): minNeededAfterSwapToBeIncreasing+=i haveNumberAfterSwap+=arr[i] if haveNumberAfterSwaptoInteger() ; skip ; for _anon : Integer.subrange(0, N-1) do ( var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var stacks : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (if solve(stacks) then "YES" else "NO" endif)->display()); operation solve(arr : OclAny) : OclAny pre: true post: true activity: var minNeededAfterSwapToBeIncreasing : int := 0 ; var haveNumberAfterSwap : int := 0 ; var ans : boolean := true ; for i : Integer.subrange(0, (arr)->size()-1) do ( minNeededAfterSwapToBeIncreasing := minNeededAfterSwapToBeIncreasing + i ; haveNumberAfterSwap := haveNumberAfterSwap + arr[i+1] ; if (haveNumberAfterSwap->compareTo(minNeededAfterSwapToBeIncreasing)) < 0 then ( ans := false ; break ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compare_sportsmen(s1,s2): s1_counter=0 for i in range(5): if s1[i]<=s2[i]: s1_counter+=1 if s1_counter>=3 : return s1 return s2 t=int(input()) for i in range(t): n=int(input()) r=None r_num=-1 deleted=[] for j in range(n): sportsman=list(map(int,input().split())) if r is None : r=sportsman r_num=j+1 elif j==n-1 : if compare_sportsmen(r,sportsman)==r : pass else : r=sportsman r_num=j+1 else : if compare_sportsmen(r,sportsman)==r : deleted.append(sportsman) else : deleted.append(r) r=sportsman r_num=j+1 flag=True while flag and deleted!=[]: if compare_sportsmen(r,deleted[0])!=r : flag=False break else : del deleted[0] if flag : print(r_num) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r : OclAny := null ; var r_num : int := -1 ; var deleted : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( var sportsman : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if r <>= null then ( r := sportsman ; r_num := j + 1 ) else (if j = n - 1 then ( if compare_sportsmen(r, sportsman) = r then ( skip ) else ( r := sportsman ; r_num := j + 1 ) ) else ( if compare_sportsmen(r, sportsman) = r then ( execute ((sportsman) : deleted) ) else ( execute ((r) : deleted) ; r := sportsman ; r_num := j + 1 ) ) ) ) ; var flag : boolean := true ; while flag & deleted /= Sequence{} do ( if compare_sportsmen(r, deleted->first()) /= r then ( flag := false ; break ) else ( execute (deleted->first())->isDeleted() )) ; if flag then ( execute (r_num)->display() ) else ( execute (-1)->display() )); operation compare_sportsmen(s1 : OclAny, s2 : OclAny) : OclAny pre: true post: true activity: var s1_counter : int := 0 ; for i : Integer.subrange(0, 5-1) do ( if (s1[i+1]->compareTo(s2[i+1])) <= 0 then ( s1_counter := s1_counter + 1 ) else skip) ; if s1_counter >= 3 then ( return s1 ) else skip ; return s2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=map(int,input().split()) lst=list(map(int,input().split())) ans=sum([x-d for x in lst if x-d>=0]) print(ans if ans else "kusoge") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : OclAny := (lst->select(x | x - d >= 0)->collect(x | (x - d)))->sum() ; execute (if ans then ans else "kusoge" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printPattern(n): j,k=0,0 for i in range(1,n+1): if i % 2!=0 : for j in range(k+1,k+i): print(str(j)+"*",end="") j=k+i print(j) j+=1 k=j else : k=k+i-1 for j in range(k,k-i+1,-1): print(str(j)+"*",end="") j=k-i+1 print(j) if __name__=="__main__" : n=5 printPattern(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 5 ; printPattern(n) ) else skip; operation printPattern(n : OclAny) pre: true post: true activity: var j : OclAny := null; var k : OclAny := null; Sequence{j,k} := Sequence{0,0} ; for i : Integer.subrange(1, n + 1-1) do ( if i mod 2 /= 0 then ( for j : Integer.subrange(k + 1, k + i-1) do ( execute (("" + ((j))) + "*")->display()) ; var j : OclAny := k + i ; execute (j)->display() ; j := j + 1 ; var k : OclAny := j ) else ( k := k + i - 1 ; for j : Integer.subrange(k - i + 1 + 1, k)->reverse() do ( execute (("" + ((j))) + "*")->display()) ; j := k - i + 1 ; execute (j)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np def possibleToReach(a,b): c=np.cbrt(a*b) re1=a//c re2=b//c if((re1*re1*re2==a)and(re2*re2*re1==b)): return True else : return False if __name__=="__main__" : A=60 B=450 if(possibleToReach(A,B)): print("yes") else : print("no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var A : int := 60 ; var B : int := 450 ; if (possibleToReach(A, B)) then ( execute ("yes")->display() ) else ( execute ("no")->display() ) ) else skip; operation possibleToReach(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var c : (trailer . (name cbrt) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a))) * (expr (atom (name b))))))))) ))) := ; var re1 : int := a div c ; var re2 : int := b div c ; if ((re1 * re1 * re2 = a) & (re2 * re2 * re1 = b)) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=list(map(int,input().split(' '))) p=list(map(int,input().split(' '))) sol=0 for i in p[k :]: if i<=k : sol+=1 print(sol) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var p : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var sol : int := 0 ; for i : p.subrange(k+1) do ( if (i->compareTo(k)) <= 0 then ( sol := sol + 1 ) else skip) ; execute (sol)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import maxsize def maxSubArraySum(a,size): max_so_far=-maxsize-1 max_ending_here=0 start=0 end=0 s=0 for i in range(0,size): max_ending_here+=a[i] if max_so_farunion(Sequence{-3}->union(Sequence{4}->union(Sequence{-1}->union(Sequence{-2}->union(Sequence{1}->union(Sequence{5}->union(Sequence{ -3 }))))))) ; maxSubArraySum(a, (a)->size()); operation maxSubArraySum(a : OclAny, size : OclAny) pre: true post: true activity: var max_so_far : double := -maxsize - 1 ; var max_ending_here : int := 0 ; var start : int := 0 ; var end : int := 0 ; var s : int := 0 ; for i : Integer.subrange(0, size-1) do ( max_ending_here := max_ending_here + a[i+1] ; if (max_so_far->compareTo(max_ending_here)) < 0 then ( max_so_far := max_ending_here ; start := s ; end := i ) else skip ; if max_ending_here < 0 then ( max_ending_here := 0 ; s := i + 1 ) else skip) ; execute (StringLib.format("Maximum contiguous sum is %d",(max_so_far)))->display() ; execute (StringLib.format("Starting Index %d",(start)))->display() ; execute (StringLib.format("Ending Index %d",(end)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()); print(a*b)if max(a,b)<=9 else print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) );(test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a))) * (expr (atom (name b))))))))) )))))) if (logical_test (comparison (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name b)))))))) ))))) <= (comparison (expr (atom (number (integer 9))))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- line=input().split(" ") line[0]=int(line[0]) line[1]=int(line[1]) result=0 if line[0]>9 or line[1]>9 : result=-1 else : result=line[0]*line[1] print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var line : OclAny := input().split(" ") ; line->first() := ("" + ((line->first())))->toInteger() ; line[1+1] := ("" + ((line[1+1])))->toInteger() ; var result : int := 0 ; if line->first() > 9 or line[1+1] > 9 then ( result := -1 ) else ( result := line->first() * line[1+1] ) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B=map(int,input().split()) if A>=10 : print("-1") exit() if B>=10 : print("-1") exit() print(A*B) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if A >= 10 then ( execute ("-1")->display() ; exit() ) else skip ; if B >= 10 then ( execute ("-1")->display() ; exit() ) else skip ; execute (A * B)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin a,b=stdin.readline().rstrip().split() if(len(a)==1)and(len(b)==1): print(int(a)*int(b)) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := stdin.readLine().rstrip().split() ; if ((a)->size() = 1) & ((b)->size() = 1) then ( execute (("" + ((a)))->toInteger() * ("" + ((b)))->toInteger())->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) flg=True if a<=0 or a>=10 : flg=False if b<=0 or b>=10 : flg=False if flg : print(a*b) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var flg : boolean := true ; if a <= 0 or a >= 10 then ( flg := false ) else skip ; if b <= 0 or b >= 10 then ( flg := false ) else skip ; if flg then ( execute (a * b)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) arr=list(map(int,input().split())) cur=0 r=0 no=False for i in range(n): r+=i cur+=arr[i] if curtoInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cur : int := 0 ; var r : int := 0 ; var no : boolean := false ; for i : Integer.subrange(0, n-1) do ( r := r + i ; cur := cur + arr[i+1] ; if (cur->compareTo(r)) < 0 then ( no := true ) else skip) ; execute (if no then "NO" else "YES" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) print(a+b if a+b<10 else "error") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if a + b < 10 then a + b else "error" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline A,B=map(int,input().split()) if A+B>9 : print("error") else : print(A+B) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if A + B > 9 then ( execute ("error")->display() ) else ( execute (A + B)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=[int(i)for i in input().split()] if(a+b)>=10 : print("error") else : print(a+b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if (a + b) >= 10 then ( execute ("error")->display() ) else ( execute (a + b)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : n,k=map(int,input().split()) arr=list(map(int,input().split())) c=k for i in range(k): if arr[i]<=k : c-=1 print(c) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : OclAny := k ; for i : Integer.subrange(0, k-1) do ( if (arr[i+1]->compareTo(k)) <= 0 then ( c := c - 1 ) else skip) ; execute (c)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=(int(_)for _ in input().split()) print('error')if a+b>=10 else print(a+b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name _)))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'error'))))))) )))))) if (logical_test (comparison (comparison (expr (expr (atom (name a))) + (expr (atom (name b))))) >= (comparison (expr (atom (number (integer 10))))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a))) + (expr (atom (name b))))))))) )))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B=map(int,input().split()) total=A+B if total<10 : print(total) else : print("error") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var total : OclAny := A + B ; if total < 10 then ( execute (total)->display() ) else ( execute ("error")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) low=-2*10**9 high=-low for i in range(n): s=input() op,num,res=s.split() num=int(num) if op=="<" : if res=="Y" : high=min(high,num-1) else : low=max(low,num) elif op==">" : if res=="Y" : low=max(low,num+1) else : high=min(high,num) elif op=="<=" : if res=="Y" : high=min(high,num) else : low=max(low,num+1) elif op==">=" : if res=="Y" : low=max(low,num) else : high=min(high,num-1) if low>high : print("Impossible") else : print((low+high)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var low : double := -2 * (10)->pow(9) ; var high : OclAny := -low ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var op : OclAny := null; var num : OclAny := null; var res : OclAny := null; Sequence{op,num,res} := s.split() ; var num : int := ("" + ((num)))->toInteger() ; if op = "<" then ( if res = "Y" then ( high := Set{high, num - 1}->min() ) else ( low := Set{low, num}->max() ) ) else (if op = ">" then ( if res = "Y" then ( low := Set{low, num + 1}->max() ) else ( high := Set{high, num}->min() ) ) else (if op = "<=" then ( if res = "Y" then ( high := Set{high, num}->min() ) else ( low := Set{low, num + 1}->max() ) ) else (if op = ">=" then ( if res = "Y" then ( low := Set{low, num}->max() ) else ( high := Set{high, num - 1}->min() ) ) else skip ) ) ) ) ; if (low->compareTo(high)) > 0 then ( execute ("Impossible")->display() ) else ( execute ((low + high) div 2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=int(input()) m=-2*10**9 n=2*10**9 flag=0 for i in range(s): a,b,c=input().split() b=int(b) if c=="Y" and a==">=" or c=="N" and a=="<" : m=max(m,b) elif c=="Y" and a==">" or c=="N" and a=="<=" : m=max(m,b+1) elif c=="Y" and a=="<=" or c=="N" and a==">" : n=min(n,b) else : n=min(n,b-1) if m>n : flag=1 break if flag==1 : print("Impossible") else : print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : double := -2 * (10)->pow(9) ; var n : double := 2 * (10)->pow(9) ; var flag : int := 0 ; for i : Integer.subrange(0, s-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := input().split() ; var b : int := ("" + ((b)))->toInteger() ; if c = "Y" & a = ">=" or c = "N" & a = "<" then ( m := Set{m, b}->max() ) else (if c = "Y" & a = ">" or c = "N" & a = "<=" then ( m := Set{m, b + 1}->max() ) else (if c = "Y" & a = "<=" or c = "N" & a = ">" then ( n := Set{n, b}->min() ) else ( n := Set{n, b - 1}->min() ) ) ) ; if (m->compareTo(n)) > 0 then ( flag := 1 ; break ) else skip) ; if flag = 1 then ( execute ("Impossible")->display() ) else ( execute (m)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) lower_bound=-2*10**9 upper_bound=2*10**9 for iq in range(t): X=input().split() if X[2]=='Y' : if X[0]=='>=' : lower_bound=max(int(X[1]),lower_bound) elif X[0]=='<=' : upper_bound=min(int(X[1]),upper_bound) elif X[0]=='>' : lower_bound=max(int(X[1])+1,lower_bound) elif X[0]=='<' : upper_bound=min(int(X[1])-1,upper_bound) else : if X[0]=='>=' : upper_bound=min(int(X[1])-1,upper_bound) elif X[0]=='<=' : lower_bound=max(int(X[1])+1,lower_bound) elif X[0]=='>' : upper_bound=min(int(X[1]),upper_bound) elif X[0]=='<' : lower_bound=max(int(X[1]),lower_bound) if lower_bound>upper_bound : print("Impossible") else : print(lower_bound) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lower_bound : double := -2 * (10)->pow(9) ; var upper_bound : double := 2 * (10)->pow(9) ; for iq : Integer.subrange(0, t-1) do ( var X : OclAny := input().split() ; if X[2+1] = 'Y' then ( if X->first() = '>=' then ( lower_bound := Set{("" + ((X[1+1])))->toInteger(), lower_bound}->max() ) else (if X->first() = '<=' then ( upper_bound := Set{("" + ((X[1+1])))->toInteger(), upper_bound}->min() ) else (if X->first() = '>' then ( lower_bound := Set{("" + ((X[1+1])))->toInteger() + 1, lower_bound}->max() ) else (if X->first() = '<' then ( upper_bound := Set{("" + ((X[1+1])))->toInteger() - 1, upper_bound}->min() ) else skip ) ) ) ) else ( if X->first() = '>=' then ( upper_bound := Set{("" + ((X[1+1])))->toInteger() - 1, upper_bound}->min() ) else (if X->first() = '<=' then ( lower_bound := Set{("" + ((X[1+1])))->toInteger() + 1, lower_bound}->max() ) else (if X->first() = '>' then ( upper_bound := Set{("" + ((X[1+1])))->toInteger(), upper_bound}->min() ) else (if X->first() = '<' then ( lower_bound := Set{("" + ((X[1+1])))->toInteger(), lower_bound}->max() ) else skip ) ) ) )) ; if (lower_bound->compareTo(upper_bound)) > 0 then ( execute ("Impossible")->display() ) else ( execute (lower_bound)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=-2*10**9 r=2*10**9 for i in range(int(input())): s,v,f=input().split() v=int(v) if f=='N' : s={'<' : '>','>' : '<'}[s[0]]+s[1 :] if len(s)==1 : s+='=' else : s=s[0] if s[0]=='<' : if len(s)!=2 : v-=1 r=min(r,v) else : if len(s)!=2 : v+=1 l=max(l,v) if l<=r : print(l) else : print('Impossible') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : double := -2 * (10)->pow(9) ; var r : double := 2 * (10)->pow(9) ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : OclAny := null; var v : OclAny := null; var f : OclAny := null; Sequence{s,v,f} := input().split() ; var v : int := ("" + ((v)))->toInteger() ; if f = 'N' then ( var s : OclAny := Map{ '<' |-> '>' }->union(Map{ '>' |-> '<' })[s->first()+1] + s->tail() ; if (s)->size() = 1 then ( s := s + '=' ) else ( s := s->first() ) ) else skip ; if s->first() = '<' then ( if (s)->size() /= 2 then ( v := v - 1 ) else skip ; r := Set{r, v}->min() ) else ( if (s)->size() /= 2 then ( v := v + 1 ) else skip ; l := Set{l, v}->max() )) ; if (l->compareTo(r)) <= 0 then ( execute (l)->display() ) else ( execute ('Impossible')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=-2*10**9 r=2*10**9 for i in range(n): s,v,f=input().split() v=int(v) if f=='N' : s={'<' : '>','>' : '<'}[s[0]]+s[1 :] if len(s)==1 : s+='=' else : s=s[0] if s[0]=='<' : if len(s)!=2 : v-=1 r=min(r,v) else : if len(s)!=2 : v+=1 l=max(l,v) if l<=r : print(l) else : print('Impossible') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : double := -2 * (10)->pow(9) ; var r : double := 2 * (10)->pow(9) ; for i : Integer.subrange(0, n-1) do ( var s : OclAny := null; var v : OclAny := null; var f : OclAny := null; Sequence{s,v,f} := input().split() ; var v : int := ("" + ((v)))->toInteger() ; if f = 'N' then ( var s : OclAny := Map{ '<' |-> '>' }->union(Map{ '>' |-> '<' })[s->first()+1] + s->tail() ; if (s)->size() = 1 then ( s := s + '=' ) else ( s := s->first() ) ) else skip ; if s->first() = '<' then ( if (s)->size() /= 2 then ( v := v - 1 ) else skip ; r := Set{r, v}->min() ) else ( if (s)->size() /= 2 then ( v := v + 1 ) else skip ; l := Set{l, v}->max() )) ; if (l->compareTo(r)) <= 0 then ( execute (l)->display() ) else ( execute ('Impossible')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) curr_sum=0 is_possible=True for i,x in enumerate(a): curr_sum+=x if 2*curr_sumtoInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var curr_sum : int := 0 ; var is_possible : boolean := true ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); curr_sum := curr_sum + x ; if (2 * curr_sum->compareTo(i * (i + 1))) < 0 then ( is_possible := false ; break ) else skip) ; if is_possible then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find_n(a): j,k=0,0 x=max(a) for i in range(len(a)): if(a[i]==x): s=i break for i in a : if(i!=x and i<=min(a)and i!='\0'): a[j]+=1 a[s]-=1 x-=1 k+=1 j+=1 elif(i!='\0'): j+=1 for i in range(len(a)): if(a[i]!=x): k=-1 break return k a=[1,6,1,1,1] print(find_n(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{1}->union(Sequence{6}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })))) ; execute (find_n(a))->display(); operation find_n(a : OclAny) : OclAny pre: true post: true activity: var j : OclAny := null; var k : OclAny := null; Sequence{j,k} := Sequence{0,0} ; var x : OclAny := (a)->max() ; for i : Integer.subrange(0, (a)->size()-1) do ( if (a[i+1] = x) then ( var s : OclAny := i ; break ) else skip) ; for i : a do ( if (i /= x & (i->compareTo((a)->min())) <= 0 & i /= '\0') then ( a[j+1] := a[j+1] + 1 ; a[s+1] := a[s+1] - 1 ; x := x - 1 ; k := k + 1 ; j := j + 1 ) else (if (i /= '\0') then ( j := j + 1 ) else skip)) ; for i : Integer.subrange(0, (a)->size()-1) do ( if (a[i+1] /= x) then ( var k : int := -1 ) else skip ; break) ; return k; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np n=3 dp=np.zeros((n,n)) v=np.zeros((n,n)); def minSteps(i,j,arr): if(i==n-1 and j==n-1): return 0 ; if(i>n-1 or j>n-1): return 9999999 ; if(v[i][j]): return dp[i][j]; v[i][j]=1 ; dp[i][j]=9999999 ; for k in range(max(0,arr[i][j]+j-n+1),min(n-i-1,arr[i][j])+1): dp[i][j]=min(dp[i][j],minSteps(i+k,j+arr[i][j]-k,arr)); dp[i][j]+=1 ; return dp[i][j]; if __name__=="__main__" : arr=[[4,1,2],[1,1,1],[2,1,1]]; ans=minSteps(0,0,arr); if(ans>=9999999): print(-1); else : print(ans); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := 3 ; var dp : Sequence := MatrixLib.singleValueMatrix(Sequence{n, n}, 0.0) ; var v : Sequence := MatrixLib.singleValueMatrix(Sequence{n, n}, 0.0); ; skip ; if __name__ = "__main__" then ( arr := Sequence{Sequence{4}->union(Sequence{1}->union(Sequence{ 2 }))}->union(Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))}->union(Sequence{ Sequence{2}->union(Sequence{1}->union(Sequence{ 1 })) })); ; var ans : OclAny := minSteps(0, 0, arr); ; if (ans >= 9999999) then ( execute (-1)->display(); ) else ( execute (ans)->display(); ) ) else skip; operation minSteps(i : OclAny, j : OclAny, arr : OclAny) pre: true post: true activity: if (i = n - 1 & j = n - 1) then ( return 0; ) else skip ; if ((i->compareTo(n - 1)) > 0 or (j->compareTo(n - 1)) > 0) then ( return 9999999; ) else skip ; if (v[i+1][j+1]) then ( return dp[i+1][j+1]; ) else skip ; v[i+1][j+1] := 1; ; dp[i+1][j+1] := 9999999; ; for k : Integer.subrange(Set{0, arr[i+1][j+1] + j - n + 1}->max(), Set{n - i - 1, arr[i+1][j+1]}->min() + 1-1) do ( dp[i+1][j+1] := Set{dp[i+1][j+1], minSteps(i + k, j + arr[i+1][j+1] - k, arr)}->min();) ; dp[i+1][j+1] := dp[i+1][j+1] + 1; ; return dp[i+1][j+1];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- Res=lambda :[*map(int,input().split())] exec(Res()[0]*'n,key=Res();print(sum(a>key for a in Res()[:key]));') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Res : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (expr (expr (atom (name Res)) (trailer (arguments ( ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) * (expr (atom 'n,key=Res();print(sum(a>key for a in Res()[:key]));'))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np ; n=3 dp=np.zeros((n,n)); v=np.zeros((n,n)); def minSteps(i,j,arr): if(i==n-1 and j==n-1): return 0 ; if(i>n-1 or j>n-1): return 9999999 ; if(v[i][j]): return dp[i][j]; v[i][j]=1 ; dp[i][j]=1+min(minSteps(i+arr[i][j],j,arr),minSteps(i,j+arr[i][j],arr)); return dp[i][j]; arr=[[2,1,2],[1,1,1],[1,1,1]]; ans=minSteps(0,0,arr); if(ans>=9999999): print(-1); else : print(ans); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; ; var n : int := 3 ; var dp : Sequence := MatrixLib.singleValueMatrix(Sequence{n, n}, 0.0); ; var v : Sequence := MatrixLib.singleValueMatrix(Sequence{n, n}, 0.0); ; skip ; arr := Sequence{Sequence{2}->union(Sequence{1}->union(Sequence{ 2 }))}->union(Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))}->union(Sequence{ Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })) })); ; var ans : OclAny := minSteps(0, 0, arr); ; if (ans >= 9999999) then ( execute (-1)->display(); ) else ( execute (ans)->display(); ); operation minSteps(i : OclAny, j : OclAny, arr : OclAny) pre: true post: true activity: if (i = n - 1 & j = n - 1) then ( return 0; ) else skip ; if ((i->compareTo(n - 1)) > 0 or (j->compareTo(n - 1)) > 0) then ( return 9999999; ) else skip ; if (v[i+1][j+1]) then ( return dp[i+1][j+1]; ) else skip ; v[i+1][j+1] := 1; ; dp[i+1][j+1] := 1 + Set{minSteps(i + arr[i+1][j+1], j, arr), minSteps(i, j + arr[i+1][j+1], arr)}->min(); ; return dp[i+1][j+1];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calc(a,u,v): s=0 u=a[u] v=a[v] for i in range(100): if u[i]& v[i]: s+=1 return s k=int(input()) a=[] for i in range(100): a.append([0]*100) s=0 n=0 for i in range(100): for j in range(i): o=calc(a,i,j) if o+s<=k : a[i][j]=1 a[j][i]=1 if o : n=i s+=o n+=1 print(n) for i in range(n): for j in range(n): if a[i][j]: print(1,end="") else : print(0,end="") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := Sequence{} ; for i : Integer.subrange(0, 100-1) do ( execute ((MatrixLib.elementwiseMult(Sequence{ 0 }, 100)) : a)) ; s := 0 ; var n : int := 0 ; for i : Integer.subrange(0, 100-1) do ( for j : Integer.subrange(0, i-1) do ( var o : OclAny := calc(a, i, j) ; if (o + s->compareTo(k)) <= 0 then ( a[i+1][j+1] := 1 ; a[j+1][i+1] := 1 ; if o then ( n := i ) else skip ; s := s + o ) else skip)) ; n := n + 1 ; execute (n)->display() ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if a[i+1][j+1] then ( execute (1)->display() ) else ( execute (0)->display() )) ; execute (->display()); operation calc(a : OclAny, u : OclAny, v : OclAny) : OclAny pre: true post: true activity: var s : int := 0 ; u := a[u+1] ; v := a[v+1] ; for i : Integer.subrange(0, 100-1) do ( if MathLib.bitwiseAnd(u[i+1], v[i+1]) then ( s := s + 1 ) else skip) ; return s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) p=[['0']*100 for j in range(100)] i,n=0,0 g=lambda n : n*(n*n-1)//6 while g(n+1)<=k : n+=1 while itoInteger() ; var p : Sequence := Integer.subrange(0, 100-1)->select(j | true)->collect(j | (MatrixLib.elementwiseMult(Sequence{ '0' }, 100))) ; var i : OclAny := null; var n : OclAny := null; Sequence{i,n} := Sequence{0,0} ; var g : Function := lambda n : OclAny in (n * (n * n - 1) div 6) ; while (g->apply(n + 1)->compareTo(k)) <= 0 do ( n := n + 1) ; while (i->compareTo(n + 1)) < 0 do ( for j : Integer.subrange(0, i-1) do ( p[i+1][j+1] := '1'; var p[j+1][i+1] : String := '1') ; i := i + 1) ; k := k - g->apply(n) ; g := lambda n : OclAny in (n * (n - 1) div 2) ; while k do ( var n : int := 0 ; while (g->apply(n + 1)->compareTo(k)) <= 0 do ( n := n + 1) ; for j : Integer.subrange(0, n-1) do ( p[i+1][j+1] := '1'; p[j+1][i+1] := '1') ; k := k - g->apply(n) ; i := i + 1) ; execute (i)->display() ; for j : Integer.subrange(0, i-1) do ( execute (StringLib.sumStringsWithSeparator((p[j+1].subrange(1,i)), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) i=3 while(i-2)*(i-1)*i//6k : b-=i-2 a[j*2][j*2+1]=0 a[j*2+1][j*2]=0 j+=1 while k-b>0 : l=3 while(l-2)*(l-1)*l//6<=k-b : l+=1 l-=1 b+=(l-2)*(l-1)*l//6 for m in range(i): a[m]+=[0]*(l-2) for m in range(l-2): a.append([0]*(i+l-2)) for m in range(i-2,i-2+l): for n in range(i-2,i-2+l): a[m][n]=1 i+=l-2 for j in range(i): a[j][j]=0 print(i) for j in a : print(''.join([str(l)for l in j])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 3 ; while ((i - 2) * (i - 1) * i div 6->compareTo(k)) < 0 do ( i := i + 1) ; var a : Sequence := Integer.subrange(0, i-1)->select(k | true)->collect(k | (Integer.subrange(0, i-1)->select(j | true)->collect(j | (1)))) ; var b : int := (i - 2) * (i - 1) * i div 6 ; var j : int := 0 ; while (b->compareTo(k)) > 0 do ( b := b - i - 2 ; a[j * 2+1][j * 2 + 1+1] := 0 ; a[j * 2 + 1+1][j * 2+1] := 0 ; j := j + 1) ; while k - b > 0 do ( var l : int := 3 ; while ((l - 2) * (l - 1) * l div 6->compareTo(k - b)) <= 0 do ( l := l + 1) ; l := l - 1 ; b := b + (l - 2) * (l - 1) * l div 6 ; for m : Integer.subrange(0, i-1) do ( a[m+1] := a[m+1] + MatrixLib.elementwiseMult(Sequence{ 0 }, (l - 2))) ; for m : Integer.subrange(0, l - 2-1) do ( execute ((MatrixLib.elementwiseMult(Sequence{ 0 }, (i + l - 2))) : a)) ; for m : Integer.subrange(i - 2, i - 2 + l-1) do ( for n : Integer.subrange(i - 2, i - 2 + l-1) do ( a[m+1][n+1] := 1)) ; i := i + l - 2) ; for j : Integer.subrange(0, i-1) do ( a[j+1][j+1] := 0) ; execute (i)->display() ; for j : a do ( execute (StringLib.sumStringsWithSeparator((j->select(l | true)->collect(l | (("" + ((l)))))), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lst=list(map(int,input())) if lst[: n-10].count(8)>(n-11)/2 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := (((OclFile["System.in"]).readLine())->collect( _x | (OclType["int"])->apply(_x) )) ; if (lst.subrange(1,n - 10)->count(8)->compareTo((n - 11) / 2)) > 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) w=input()[:-1][: n-10] x=w.count('8') if x>=(n-9)//2 : print('YES') else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : OclAny := input()->front().subrange(1,n - 10) ; var x : int := w->count('8') ; if (x->compareTo((n - 9) div 2)) >= 0 then ( execute ('YES')->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) sn=input() tm=n-11 pt=tm//2 en=sn.count("8") if en<=pt : print("NO") else : eoc=pt+1 lol=0 for i in range(len(sn)): if sn[i]=="8" : lol+=1 if lol==eoc : xc=i break if tm-xc>=0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sn : String := (OclFile["System.in"]).readLine() ; var tm : double := n - 11 ; var pt : int := tm div 2 ; var en : int := sn->count("8") ; if (en->compareTo(pt)) <= 0 then ( execute ("NO")->display() ) else ( var eoc : int := pt + 1 ; var lol : int := 0 ; for i : Integer.subrange(0, (sn)->size()-1) do ( if sn[i+1] = "8" then ( lol := lol + 1 ) else skip ; if lol = eoc then ( var xc : OclAny := i ; break ) else skip) ; if tm - xc >= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline def ii(): return int(input()) def li(): return list(map(int,input().split())) from math import sqrt def perfect_sq(n): x=int(sqrt(n)) while x*xn : x-=1 return(x*x==n) n=ii() s=input().strip() rem=0 for i in range(n-10): if s[i]=='8' : rem+=1 else : rem-=1 print('YES' if rem>0 else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; skip ; skip ; skip ; skip ; n := ii() ; var s : OclAny := input()->trim() ; var rem : int := 0 ; for i : Integer.subrange(0, n - 10-1) do ( if s[i+1] = '8' then ( rem := rem + 1 ) else ( rem := rem - 1 )) ; execute (if rem > 0 then 'YES' else 'NO' endif)->display(); operation ii() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation li() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation perfect_sq(n : OclAny) : OclAny pre: true post: true activity: var x : int := ("" + ((sqrt(n))))->toInteger() ; while (x * x->compareTo(n)) < 0 do ( x := x + 1) ; while (x * x->compareTo(n)) > 0 do ( x := x - 1) ; return (x * x = n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(l): stok=0 for i in range(len(l)): if l[i]>i : stok+=(l[i]-i) l[i]=i elif l[i]toInteger() ; for i : Integer.subrange(0, t-1) do ( input() ; l := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; if solve(l) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); operation solve(l : OclAny) : OclAny pre: true post: true activity: var stok : int := 0 ; for i : Integer.subrange(0, (l)->size()-1) do ( if (l[i+1]->compareTo(i)) > 0 then ( stok := stok + (l[i+1] - i) ; l[i+1] := i ) else (if (l[i+1]->compareTo(i)) < 0 then ( if (stok->compareTo(i - l[i+1])) < 0 then ( return false ) else skip ; stok := stok - (i - l[i+1]) ; l[i+1] := l[i+1] + (i - l[i+1]) ) else skip)) ; l[(l)->size() - 1+1] := l[(l)->size() - 1+1] + stok ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input())) m=int((n-11)/2) b=a[0 : 2*m+1] if b.count(8)>m : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (((OclFile["System.in"]).readLine())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + (((n - 11) / 2)))->toInteger() ; var b : OclAny := a.subrange(0+1, 2 * m + 1) ; if (b->count(8)->compareTo(m)) > 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) p=list(map(int,input().split())) ans=0 for i in range(k): if p[i]>k : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(0, k-1) do ( if (p[i+1]->compareTo(k)) > 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def Area(r): if(r<0): return-1 x=(2*r)/mt.sqrt(5) A=0.70477*pow(x,2) return A r=5 print(Area(r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; r := 5 ; execute (Area(r))->display(); operation Area(r : OclAny) : OclAny pre: true post: true activity: if (r < 0) then ( return -1 ) else skip ; var x : double := (2 * r) / mt.sqrt(5) ; var A : double := 0.70477 * (x)->pow(2) ; return A; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countOdd(n): coun=0 i=n-2 while(i>=1): if(i & 1): m=int((n-i)/2) j=int((i*(i+1))/2) coun+=j*m else : m=int(((n-1)-i)/2) j=int((i*(i+1))/2) coun+=j*m i-=1 return coun def countEven(n): coun=0 i=n-2 while(i>=1): if(i & 1): m=int(((n-1)-i)/2) j=int((i*(i+1))/2) coun+=j*m else : m=int((n-i)/2) j=(i*(i+1))//2 coun+=j*m return coun if __name__=='__main__' : n=5 if(n & 1): print(countOdd(n)) else : print(countEven(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( n := 5 ; if (MathLib.bitwiseAnd(n, 1)) then ( execute (countOdd(n))->display() ) else ( execute (countEven(n))->display() ) ) else skip; operation countOdd(n : OclAny) : OclAny pre: true post: true activity: var coun : int := 0 ; var i : double := n - 2 ; while (i >= 1) do ( if (MathLib.bitwiseAnd(i, 1)) then ( var m : int := ("" + (((n - i) / 2)))->toInteger() ; var j : int := ("" + (((i * (i + 1)) / 2)))->toInteger() ; coun := coun + j * m ) else ( m := ("" + ((((n - 1) - i) / 2)))->toInteger() ; j := ("" + (((i * (i + 1)) / 2)))->toInteger() ; coun := coun + j * m ) ; i := i - 1) ; return coun; operation countEven(n : OclAny) : OclAny pre: true post: true activity: coun := 0 ; i := n - 2 ; while (i >= 1) do ( if (MathLib.bitwiseAnd(i, 1)) then ( m := ("" + ((((n - 1) - i) / 2)))->toInteger() ; j := ("" + (((i * (i + 1)) / 2)))->toInteger() ; coun := coun + j * m ) else ( m := ("" + (((n - i) / 2)))->toInteger() ; j := (i * (i + 1)) div 2 ; coun := coun + j * m )) ; return coun; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def myCopy(s1,s2,index): s2[index]=s1[index]; if(index==len(s1)-1): return ; myCopy(s1,s2,index+1); if __name__=='__main__' : s1="GEEKSFORGEEKS" ; s2=[0]*(len(s1)); index=0 ; myCopy(s1,s2,index); print("".join(s2)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( s1 := "GEEKSFORGEEKS"; ; s2 := MatrixLib.elementwiseMult(Sequence{ 0 }, ((s1)->size())); ; index := 0; ; myCopy(s1, s2, index); ; execute (StringLib.sumStringsWithSeparator((s2), ""))->display(); ) else skip; operation myCopy(s1 : OclAny, s2 : OclAny, index : OclAny) : OclAny pre: true post: true activity: s2[index+1] := s1[index+1]; ; if (index = (s1)->size() - 1) then ( return; ) else skip ; myCopy(s1, s2, index + 1);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isRotated(str1,str2): if(len(str1)!=len(str2)): return False clock_rot="" anticlock_rot="" l=len(str2) anticlock_rot=(anticlock_rot+str2[l-2 :]+str2[0 : l-2]) clock_rot=clock_rot+str2[2 :]+str2[0 : 2] return(str1==clock_rot or str1==anticlock_rot) if __name__=="__main__" : str1="geeks" str2="eksge" if isRotated(str1,str2): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( str1 := "geeks" ; str2 := "eksge" ) else skip ; if isRotated(str1, str2) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isRotated(str1 : OclAny, str2 : OclAny) : OclAny pre: true post: true activity: if ((str1)->size() /= (str2)->size()) then ( return false ) else skip ; var clock_rot : String := "" ; var anticlock_rot : String := "" ; var l : int := (str2)->size() ; anticlock_rot := (anticlock_rot + str2.subrange(l - 2+1) + str2.subrange(0+1, l - 2)) ; clock_rot := clock_rot + str2.subrange(2+1) + str2.subrange(0+1, 2) ; return (str1 = clock_rot or str1 = anticlock_rot); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPalindrome(s): s1="" N=len(s) i=(N-1) while(i>=0): s1+=s[i] i=i-1 if(s==s1): return True return False def createString(N): s2="" s=str(N) letters="abcdefghij" sum=0 substr="" for i in range(0,len(s)): digit=int(s[i]) substr+=letters[digit] sum+=digit while(len(s2)<=sum): s2+=substr s2=s2[: sum] return isPalindrome(s2) N=61 ; flag=createString(N) if(flag): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; N := 61; ; var flag : OclAny := createString(N) ; if (flag) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); operation isPalindrome(s : OclAny) : OclAny pre: true post: true activity: var s1 : String := "" ; var N : int := (s)->size() ; var i : double := (N - 1) ; while (i >= 0) do ( s1 := s1 + s[i+1] ; i := i - 1) ; if (s = s1) then ( return true ) else skip ; return false; operation createString(N : OclAny) : OclAny pre: true post: true activity: var s2 : String := "" ; s := ("" + ((N))) ; var letters : String := "abcdefghij" ; var sum : int := 0 ; var substr : String := "" ; for i : Integer.subrange(0, (s)->size()-1) do ( var digit : int := ("" + ((s[i+1])))->toInteger() ; substr := substr + letters[digit+1] ; sum := sum + digit) ; while (((s2)->size()->compareTo(sum)) <= 0) do ( s2 := s2 + substr) ; s2 := s2.subrange(1,sum) ; return isPalindrome(s2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools import math from math import gcd as gcd import sys import queue import itertools from heapq import heappop,heappush import random def solve(): def p(s): for i in range(len(s)//2): if s[i]!=s[-1-i]: return False return True def one_move_check(s): for i in range(len(s)): e=s[1+i : len(s)]+s[0 : i+1] if p(e)and e!=s : return True return False s=str(input()) if len(s)<=3 : print("Impossible") return if one_move_check(s): print(1) return if len(s)% 2==0 : for i in range(len(s)//2): if s[i]!=s[len(s)//2+i]: print(1) return if len(set(list(s[0 : len(s)//2])))==1 : print("Impossible") else : print(2) else : if len(set(list(s[0 : len(s)//2])))==1 : print("Impossible") else : print(2) if __name__=='__main__' : multi_test=0 if multi_test : t=int(sys.stdin.readline()) for _ in range(t): solve() else : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var multi_test : int := 0 ; if multi_test then ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( solve()) ) else ( solve() ) ) else skip; operation solve() pre: true post: true activity: skip ; skip ; s := ("" + (((OclFile["System.in"]).readLine()))) ; if (s)->size() <= 3 then ( execute ("Impossible")->display() ; return ) else skip ; if one_move_check(s) then ( execute (1)->display() ; return ) else skip ; if (s)->size() mod 2 = 0 then ( for i : Integer.subrange(0, (s)->size() div 2-1) do ( if s[i+1] /= s[(s)->size() div 2 + i+1] then ( execute (1)->display() ; return ) else skip) ; if (Set{}->union(((s.subrange(0+1, (s)->size() div 2)))))->size() = 1 then ( execute ("Impossible")->display() ) else ( execute (2)->display() ) ) else ( if (Set{}->union(((s.subrange(0+1, (s)->size() div 2)))))->size() = 1 then ( execute ("Impossible")->display() ) else ( execute (2)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys s=input().rstrip() n=len(s) same=True s1=s[: n//2] for i in range(len(s1)-1): if s1[i]!=s1[i+1]: same=False if same : print("Impossible") exit() for i in range(1,n): t=s[i :]+s[: i] flag=True for i in range(n//2): if t[i]!=t[n-1-i]: flag=False if flag and t!=s : print(1) exit() print(2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : OclAny := input().rstrip() ; var n : int := (s)->size() ; var same : boolean := true ; var s1 : OclAny := s.subrange(1,n div 2) ; for i : Integer.subrange(0, (s1)->size() - 1-1) do ( if s1[i+1] /= s1[i + 1+1] then ( same := false ) else skip) ; if same then ( execute ("Impossible")->display() ; exit() ) else skip ; for i : Integer.subrange(1, n-1) do ( var t : OclAny := s.subrange(i+1) + s.subrange(1,i) ; var flag : boolean := true ; for i : Integer.subrange(0, n div 2-1) do ( if t[i+1] /= t[n - 1 - i+1] then ( flag := false ) else skip) ; if flag & t /= s then ( execute (1)->display() ; exit() ) else skip) ; execute (2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): initial_name=input().strip() for ch in initial_name[: 2]: if initial_name.count(ch)>=len(initial_name)-1 : return "Impossible" for cut_point in range(1,len(initial_name)): new_name=initial_name[cut_point :]+initial_name[: cut_point] if new_name!=initial_name and list(new_name)==list(reversed(new_name)): return 1 return 2 if __name__=="__main__" : print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (solve())->display() ) else skip; operation solve() : OclAny pre: true post: true activity: var initial_name : OclAny := input()->trim() ; for ch : initial_name.subrange(1,2) do ( if (initial_name->count(ch)->compareTo((initial_name)->size() - 1)) >= 0 then ( return "Impossible" ) else skip) ; for cut_point : Integer.subrange(1, (initial_name)->size()-1) do ( var new_name : OclAny := initial_name.subrange(cut_point+1) + initial_name.subrange(1,cut_point) ; if new_name /= initial_name & (new_name) = ((new_name)->reverse()) then ( return 1 ) else skip) ; return 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().strip() def isPal(v): l,r=0,len(v)-1 while ltrim()) ; skip ; skip ; execute (solve())->display(); operation isPal(v : OclAny) : OclAny pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,(v)->size() - 1} ; while (l->compareTo(r)) < 0 do ( if v[l+1] /= v[r+1] then ( return false ) else skip ; l := l + 1 ; r := r - 1) ; return true; operation solve() : OclAny pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var n : int := (s)->size() ; if ((argument (test (logical_test (comparison (comparison (expr (atom (name c)))) != (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name s))))))))->sum() <= 1 then ( return 'Impossible' ) else skip ; var u : OclAny := null; Sequence{u,v} := Sequence{(s)->characters(),(s)->characters()} ; for _anon : Integer.subrange(0, n - 1-1) do ( execute ((v->at(0`firstArg+1)) : v) ; if v /= u & isPal(v) then ( return 1 ) else skip) ; return 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) for i in range(n-1): if(l[i]>=i): c=l[i] l[i]=i l[i+1]=l[i+1]+c-i else : print('NO') break else : if(l[n-1]toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) >= (comparison (expr (atom (name i)))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))) + (expr (atom (name c)))) - (expr (atom (name i)))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) ])))) < (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a1,a2=map(int,input().split()) t=0 if a1==1 and a2==1 : print(0) else : while a1>0 and a2>0 : if a1>a2 : a2+=1 a1-=2 else : a2-=2 a1+=1 t+=1 print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a1 : OclAny := null; var a2 : OclAny := null; Sequence{a1,a2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : int := 0 ; if a1 = 1 & a2 = 1 then ( execute (0)->display() ) else ( while a1 > 0 & a2 > 0 do ( if (a1->compareTo(a2)) > 0 then ( a2 := a2 + 1 ; a1 := a1 - 2 ) else ( a2 := a2 - 2 ; a1 := a1 + 1 ) ; t := t + 1) ; execute (t)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def recur(s): n=len(s) if(len(s)& 1): return 2 half=int(n//2) if(s[: half]!=s[half :]): return 1 return recur(s[: half]) s=input() n=len(s) if(n & 1): if(n==1): print("Impossible") else : if(s.count(s[0])>=n-1): print("Impossible") else : print(2) else : half=int(n//2) if(s.count(s[0])==n): print("Impossible") else : print(recur(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := (OclFile["System.in"]).readLine() ; n := (s)->size() ; if (MathLib.bitwiseAnd(n, 1)) then ( if (n = 1) then ( execute ("Impossible")->display() ) else ( if ((s->count(s->first())->compareTo(n - 1)) >= 0) then ( execute ("Impossible")->display() ) else ( execute (2)->display() ) ) ) else ( half := ("" + ((n div 2)))->toInteger() ; if (s->count(s->first()) = n) then ( execute ("Impossible")->display() ) else ( execute (recur(s))->display() ) ); operation recur(s : OclAny) : OclAny pre: true post: true activity: var n : int := (s)->size() ; if (MathLib.bitwiseAnd((s)->size(), 1)) then ( return 2 ) else skip ; var half : int := ("" + ((n div 2)))->toInteger() ; if (s.subrange(1,half) /= s.subrange(half+1)) then ( return 1 ) else skip ; return recur(s.subrange(1,half)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def FirstAndLast(string): arrOfStr=string.split(); res="" ; for a in arrOfStr : res+=a[1 : len(a)-1]+" " ; return res ; if __name__=="__main__" : string="Geeks for Geeks" ; print(string); print(FirstAndLast(string)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( string := "Geeks for Geeks"; ; execute (string)->display(); ; execute (FirstAndLast(string))->display(); ) else skip; operation FirstAndLast(string : OclAny) pre: true post: true activity: var arrOfStr : OclAny := string.split(); ; var res : String := ""; ; for a : arrOfStr do ( res := res + a.subrange(1+1, (a)->size() - 1) + " ";) ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printString(n,str): str2="" extraChar=n % 26 if(extraChar>=1): for i in range(26-(extraChar+1),26): str2+=str[i] countOfStr=n//26 for i in range(1,countOfStr+1): for j in range(26): str2+=str[j] return str2 if __name__=="__main__" : n=30 str="zyxwvutsrqponmlkjihgfedcba" print(printString(n,str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 30 ; OclType["String"] := "zyxwvutsrqponmlkjihgfedcba" ; execute (printString(n, OclType["String"]))->display() ) else skip; operation printString(n : OclAny, OclType["String"] : OclAny) : OclAny pre: true post: true activity: var str2 : String := "" ; var extraChar : int := n mod 26 ; if (extraChar >= 1) then ( for i : Integer.subrange(26 - (extraChar + 1), 26-1) do ( str2 := str2 + ("" + ([i+1]))) ) else skip ; var countOfStr : int := n div 26 ; for i : Integer.subrange(1, countOfStr + 1-1) do ( for j : Integer.subrange(0, 26-1) do ( str2 := str2 + ("" + ([j+1])))) ; return str2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def areaOctagon(side): return(2*(1+(math.sqrt(2)))*side*side) side=4 print("Area of Regular Octagon=",round(areaOctagon(side),4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; side := 4 ; execute ("Area of Regular Octagon=")->display(); operation areaOctagon(side : OclAny) : OclAny pre: true post: true activity: return (2 * (1 + ((2)->sqrt())) * side * side); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findString(n,k): res="" for i in range(k): res=res+chr(ord('a')+i) count=0 for i in range(n-k): res=res+chr(ord('a')+count) count+=1 if(count==k): count=0 ; return res if __name__=="__main__" : n=5 k=2 print(findString(n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 5 ; k := 2 ; execute (findString(n, k))->display() ) else skip; operation findString(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var res : String := "" ; for i : Integer.subrange(0, k-1) do ( res := res + (('a')->char2byte() + i)->byte2char()) ; var count : int := 0 ; for i : Integer.subrange(0, n - k-1) do ( res := res + (('a')->char2byte() + count)->byte2char() ; count := count + 1 ; if (count = k) then ( count := 0; ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=list(map(int,input().split())) r=set([]) c=set([]) s="" for i in range(m): x,y=list(map(int,input().split())) r.add(y) c.add(x) t=n**2-(len(r)*n+len(c)*(n-len(r))) s+=str(t)+" " print(s[:-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var r : Set := Set{}->union((Sequence{})) ; var c : Set := Set{}->union((Sequence{})) ; var s : String := "" ; for i : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((y) : r) ; execute ((x) : c) ; var t : double := (n)->pow(2) - ((r)->size() * n + (c)->size() * (n - (r)->size())) ; s := s + ("" + ((t))) + " ") ; execute (s->front())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) ax=set() ay=set() for i in range(m): x,y=map(int,input().split()) ax.add(x) ay.add(y) k=n-len(ax) l=n-len(ay) col=l*k print(col) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ax : Set := Set{}->union(()) ; var ay : Set := Set{}->union(()) ; for i : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((x) : ax) ; execute ((y) : ay) ; var k : double := n - (ax)->size() ; var l : double := n - (ay)->size() ; var col : double := l * k ; execute (col)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=list(map(int,input().split())) set_l=set() set_c=set() res=[] for a in range(n[1]): places=list(map(int,input().split())) set_l.add(places[0]) set_c.add(places[1]) ans=((n[0]-len(set_l))*(n[0]-len(set_c))) res.append(ans) print(*res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var set_l : Set := Set{}->union(()) ; var set_c : Set := Set{}->union(()) ; var res : Sequence := Sequence{} ; for a : Integer.subrange(0, n[1+1]-1) do ( var places : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((places->first()) : set_l) ; execute ((places[1+1]) : set_c) ; var ans : double := ((n->first() - (set_l)->size()) * (n->first() - (set_c)->size())) ; execute ((ans) : res)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=list(map(int,input().split())) set_l=set() set_c=set() res=[] for a in range(n[1]): places=list(map(int,input().split())) set_l.add(places[0]) set_c.add(places[1]) ans=((n[0]-len(set_l))*(n[0]-len(set_c))) res.append(ans) print(*res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var set_l : Set := Set{}->union(()) ; var set_c : Set := Set{}->union(()) ; var res : Sequence := Sequence{} ; for a : Integer.subrange(0, n[1+1]-1) do ( var places : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((places->first()) : set_l) ; execute ((places[1+1]) : set_c) ; var ans : double := ((n->first() - (set_l)->size()) * (n->first() - (set_c)->size())) ; execute ((ans) : res)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,m=map(int,input().split()) a=set() b=set() c=d=n for _ in range(m): x,y=map(int,input().split()) if x not in a : a.add(x) c-=1 if y not in b : b.add(y) d-=1 print(c*d,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Set := Set{}->union(()) ; var b : Set := Set{}->union(()) ; var c : OclAny := n; var d : OclAny := n ; for _anon : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a)->excludes(x) then ( execute ((x) : a) ; c := c - 1 ) else skip ; if (b)->excludes(y) then ( execute ((y) : b) ; d := d - 1 ) else skip ; execute (c * d)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K,X,Y=[int(input())for i in range(4)] X_days=min(N,K) Y_days=N-X_days ans=X*X_days+Y*Y_days print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; var X : OclAny := null; var Y : OclAny := null; Sequence{N,K,X,Y} := Integer.subrange(0, 4-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var X_days : OclAny := Set{N, K}->min() ; var Y_days : double := N - X_days ; var ans : double := X * X_days + Y * Y_days ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y=map(int,input().split()) print(max(x+y-3+((y-x)% 3>0),0)) num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{x + y - 3 + ((y - x) mod 3 > 0), 0}->max())->display() ; var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): x,y=list(map(int,input().split())) if(x+y)% 2==1 : print("-1-1") return if x % 2==1 : if(x>y): print((x-y)//2,y) else : print(x,(y-x)//2) else : print(x//2,y//2) T=int(input()) while T>0 : T-=1 solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while T > 0 do ( T := T - 1 ; solve()); operation solve() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (x + y) mod 2 = 1 then ( execute ("-1-1")->display() ; return ) else skip ; if x mod 2 = 1 then ( if ((x->compareTo(y)) > 0) then ( execute ((x - y) div 2)->display() ) else ( execute (x)->display() ) ) else ( execute (x div 2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def is_prime(num): count=0 for i in range(1,num+1): if i*i>num : break if((num)% i==0): if(i*i!=(num)): count+=2 else : count+=1 if(count==2): return True else : return False def is_divisible(n): if(n==1): return "YES" else : if(is_prime(n+1)): return "NO" else : return "YES" n=3 print(is_divisible(n)) n=4 print(is_divisible(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 3 ; execute (is_divisible(n))->display() ; n := 4 ; execute (is_divisible(n))->display(); operation is_prime(num : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(1, num + 1-1) do ( if (i * i->compareTo(num)) > 0 then ( break ) else skip ; if ((num) mod i = 0) then ( if (i * i /= (num)) then ( count := count + 2 ) else ( count := count + 1 ) ) else skip) ; if (count = 2) then ( return true ) else ( return false ); operation is_divisible(n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return "YES" ) else ( if (is_prime(n + 1)) then ( return "NO" ) else ( return "YES" ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def circleradius(l,b): if(l<0 or b<0): return-1 r=(l*b)/(2*sqrt((pow(l,2)+pow(b,2)))); return r if __name__=='__main__' : l=5 b=3 print("{0:.5}".format(circleradius(l,b))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( l := 5 ; b := 3 ; execute (StringLib.interpolateStrings("{0:.5}", Sequence{circleradius(l, b)}))->display() ) else skip; operation circleradius(l : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (l < 0 or b < 0) then ( return -1 ) else skip ; var r : double := (l * b) / (2 * sqrt(((l)->pow(2) + (b)->pow(2)))); ; return r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,d=map(int,input().split()) x=list(map(int,input().split())) x.sort() ans=2 for i in range(n-1): if x[i+1]-x[i]==2*d : ans+=1 elif x[i+1]-x[i]>=2*d : ans+=2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; x := x->sort() ; var ans : int := 2 ; for i : Integer.subrange(0, n - 1-1) do ( if x[i + 1+1] - x[i+1] = 2 * d then ( ans := ans + 1 ) else (if (x[i + 1+1] - x[i+1]->compareTo(2 * d)) >= 0 then ( ans := ans + 2 ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (n,d)=map(int,input().split(' ')) x=list(map(int,input().split(' '))) hotels=[] x.append(0) for i in range(n): if i==0 : if x[i]+d<=x[i+1]-d : hotels.append(x[i]+d) else : if x[i-1]+d<=x[i]-d : hotels.append(x[i]-d) if x[i]+d<=x[i+1]-d : hotels.append(x[i]+d) hotels.append(x[0]-d) hotels.append(x[-2]+d) print(len(set(hotels))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{n, d} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var hotels : Sequence := Sequence{} ; execute ((0) : x) ; for i : Integer.subrange(0, n-1) do ( if i = 0 then ( if (x[i+1] + d->compareTo(x[i + 1+1] - d)) <= 0 then ( execute ((x[i+1] + d) : hotels) ) else skip ) else ( if (x[i - 1+1] + d->compareTo(x[i+1] - d)) <= 0 then ( execute ((x[i+1] - d) : hotels) ) else skip ; if (x[i+1] + d->compareTo(x[i + 1+1] - d)) <= 0 then ( execute ((x[i+1] + d) : hotels) ) else skip )) ; execute ((x->first() - d) : hotels) ; execute ((x->front()->last() + d) : hotels) ; execute ((Set{}->union((hotels)))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=map(int,input().split()) a=list(map(int,input().split())) s=0 for i in range(n-1): if a[i+1]-a[i]-(2*d)>0 : s+=2 elif a[i+1]-a[i]-(2*d)==0 : s+=1 print(s+2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if a[i + 1+1] - a[i+1] - (2 * d) > 0 then ( s := s + 2 ) else (if a[i + 1+1] - a[i+1] - (2 * d) = 0 then ( s := s + 1 ) else skip)) ; execute (s + 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) n,d=R() a=[*R()] print(2+sum((y-x>=d*2)+(y-x>d*2)for x,y in zip(a,a[1 :]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := R->apply() ; var a : Sequence := R->apply() ; execute (2 + ((argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (expr (atom (name y))) - (expr (atom (name x))))) >= (comparison (expr (expr (atom (name d))) * (expr (atom (number (integer 2)))))))))) ))) + (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (expr (atom (name y))) - (expr (atom (name x))))) > (comparison (expr (expr (atom (name d))) * (expr (atom (number (integer 2)))))))))) ))))))) (comp_for for (exprlist (expr (atom (name x))) , (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))))))) )))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=map(int,input().split()) x=list(map(int,input().split())) ans=2 for i in range(n-1): if x[i+1]-x[i]>2*d : ans+=2 elif x[i+1]-x[i]==2*d : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 2 ; for i : Integer.subrange(0, n - 1-1) do ( if (x[i + 1+1] - x[i+1]->compareTo(2 * d)) > 0 then ( ans := ans + 2 ) else (if x[i + 1+1] - x[i+1] = 2 * d then ( ans := ans + 1 ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.readline().rstrip() t=int(input()) for i in range(t): n=int(input()) v=list(map(int,input().split())) adv=min(-1*abs(v[0]-v[1]),-1*abs(v[n-2]-v[n-1])) ans=0 for j in range(1,n): ans+=abs(v[j-1]-v[j]) for j in range(1,n-1): adv=min(adv,abs(v[j+1]-v[j-1])-abs(v[j-1]-v[j])-abs(v[j+1]-v[j])) print(ans+adv) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var v : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var adv : OclAny := Set{-1 * (v->first() - v[1+1])->abs(), -1 * (v[n - 2+1] - v[n - 1+1])->abs()}->min() ; var ans : int := 0 ; for j : Integer.subrange(1, n-1) do ( ans := ans + (v[j - 1+1] - v[j+1])->abs()) ; for j : Integer.subrange(1, n - 1-1) do ( adv := Set{adv, (v[j + 1+1] - v[j - 1+1])->abs() - (v[j - 1+1] - v[j+1])->abs() - (v[j + 1+1] - v[j+1])->abs()}->min()) ; execute (ans + adv)->display()); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) arr=list(map(int,input().split())) total=0 mx=max(abs(arr[1]-arr[0]),abs(arr[-1]-arr[-2])) for i in range(1,n): total+=abs(arr[i]-arr[i-1]) if i+1toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var total : int := 0 ; var mx : OclAny := Set{(arr[1+1] - arr->first())->abs(), (arr->last() - arr->front()->last())->abs()}->max() ; for i : Integer.subrange(1, n-1) do ( total := total + (arr[i+1] - arr[i - 1+1])->abs() ; if (i + 1->compareTo(n)) < 0 then ( mx := Set{mx, (arr[i+1] - arr[i - 1+1])->abs() + (arr[i + 1+1] - arr[i+1])->abs() - (arr[i + 1+1] - arr[i - 1+1])->abs()}->max() ) else skip) ; execute (total - mx)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a1,a2=list(map(int,input().split())) if a1==1 and a2==1 : print(0) else : i=0 while a1>1 or a2>1 : i+=1 if min(a1,a2)==a1 : a1+=1 a2-=2 else : a2+=1 a1-=2 print(i-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a1 : OclAny := null; var a2 : OclAny := null; Sequence{a1,a2} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if a1 = 1 & a2 = 1 then ( execute (0)->display() ) else ( var i : int := 0 ; while a1 > 1 or a2 > 1 do ( i := i + 1 ; if Set{a1, a2}->min() = a1 then ( a1 := a1 + 1 ; a2 := a2 - 2 ) else ( a2 := a2 + 1 ; a1 := a1 - 2 )) ; execute (i - 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) l=list(map(int,input().split())) arr=[0 for i in range(n)] for i in range(n-1,-1,-1): if(i==n-1): diff=abs(l[i]-l[i-1]) elif(i==0): diff=abs(l[i]-l[i+1]) else : diff=(abs(l[i]-l[i+1])+abs(l[i]-l[i-1]))-abs(l[i+1]-l[i-1]) arr[i]=diff ans=0 for i in range(n-1,0,-1): ans+=(abs(l[i]-l[i-1])) print(ans-max(arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var arr : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (i = n - 1) then ( var diff : double := (l[i+1] - l[i - 1+1])->abs() ) else (if (i = 0) then ( diff := (l[i+1] - l[i + 1+1])->abs() ) else ( diff := ((l[i+1] - l[i + 1+1])->abs() + (l[i+1] - l[i - 1+1])->abs()) - (l[i + 1+1] - l[i - 1+1])->abs() ) ) ; arr[i+1] := diff) ; var ans : int := 0 ; for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( ans := ans + ((l[i+1] - l[i - 1+1])->abs())) ; execute (ans - (arr)->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): ipt=list(map(int,input().split())) (x,y)=ipt[0],ipt[1] if((x+y)% 2==1): print(-1,-1) else : if(x % 2==1): print((x+1)//2,(y-1)//2) else : print(x//2,y//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var ipt : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var Sequence{x, y} : OclAny := ipt->first(),ipt[1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for z in range(t): n=int(input()) q=set() arr=list(map(int,input().split())) count=0 for i in range(n-1): count=count+abs(arr[i+1]-arr[i]) for i in range(1,n-1): q.add(count-abs(arr[i+1]-arr[i])-abs(arr[i]-arr[i-1])+abs(arr[i+1]-arr[i-1])) q.add(count-abs(arr[1]-arr[0])) q.add(count-abs(arr[n-1]-arr[n-2])) print(min(q)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for z : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var q : Set := Set{}->union(()) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( count := count + (arr[i + 1+1] - arr[i+1])->abs()) ; for i : Integer.subrange(1, n - 1-1) do ( execute ((count - (arr[i + 1+1] - arr[i+1])->abs() - (arr[i+1] - arr[i - 1+1])->abs() + (arr[i + 1+1] - arr[i - 1+1])->abs()) : q)) ; execute ((count - (arr[1+1] - arr->first())->abs()) : q) ; execute ((count - (arr[n - 1+1] - arr[n - 2+1])->abs()) : q) ; execute ((q)->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- test=int(input()) for _ in range(test): n=int(input()) arr=list(map(int,input().split())) cost=0 for i in range(n-1): cost+=abs(arr[i]-arr[i+1]) reduced=max(abs(arr[0]-arr[1]),abs(arr[n-1]-arr[n-2])) for i in range(1,n-1): reduced=max(reduced,abs(arr[i-1]-arr[i])+abs(arr[i]-arr[i+1])-abs(arr[i-1]-arr[i+1])) print(cost-reduced) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var test : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, test-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cost : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( cost := cost + (arr[i+1] - arr[i + 1+1])->abs()) ; var reduced : OclAny := Set{(arr->first() - arr[1+1])->abs(), (arr[n - 1+1] - arr[n - 2+1])->abs()}->max() ; for i : Integer.subrange(1, n - 1-1) do ( reduced := Set{reduced, (arr[i - 1+1] - arr[i+1])->abs() + (arr[i+1] - arr[i + 1+1])->abs() - (arr[i - 1+1] - arr[i + 1+1])->abs()}->max()) ; execute (cost - reduced)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a,b,c=map(int,input().split()) print(max(0,math.ceil((a*c)/100)-b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{0, ((a * c) / 100)->ceil() - b}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,x,y=map(int,input().split()) percentage=math.ceil(n*y/100) if xcollect( _x | (OclType["int"])->apply(_x) ) ; var percentage : double := (n * y / 100)->ceil() ; if (x->compareTo(percentage)) < 0 then ( execute (percentage - x)->display() ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x,y=map(int,input().split()) print(max(0,-(-n*y//100)-x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{0, -(-n * y div 100) - x}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt from collections import defaultdict,deque import sys from bisect import bisect_right as b_r from bisect import bisect_left as b_l from os import path from heapq import* mod=1000000007 INT_MAX=sys.maxsize-1 INT_MIN=-sys.maxsize def myyy__answer(): n,m,p=map(int,input().split()) req=mt.ceil((n*p)/100) if(m>=req): print(0) else : print(req-m) if __name__=="__main__" : myyy__answer() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : int := 1000000007 ; var INT_MAX : double := (trailer . (name maxsize)) - 1 ; var INT_MIN : (trailer . (name maxsize)) := -(trailer . (name maxsize)) ; skip ; if __name__ = "__main__" then ( myyy__answer() ) else skip; operation myyy__answer() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var p : OclAny := null; Sequence{n,m,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var req : int := mt.ceil((n * p) / 100) ; if ((m->compareTo(req)) >= 0) then ( execute (0)->display() ) else ( execute (req - m)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,x,y=map(int,input().split()) print(max(0,math.ceil((n*y)/100)-x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{0, ((n * y) / 100)->ceil() - x}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,q=map(int,input().split()) d={} a=list(map(int,input().split())) x=0 for i in range(n): d[i+1]=a[i] s=sum(a) for i in range(q): w=list(map(int,input().split())) if w[0]==1 : s+=w[2]-d.get(w[1],x) d[w[1]]=w[2] else : s=w[1]*n d.clear() x=w[1] print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : OclAny := Set{} ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : int := 0 ; for i : Integer.subrange(0, n-1) do ( d[i + 1+1] := a[i+1]) ; var s : OclAny := (a)->sum() ; for i : Integer.subrange(0, q-1) do ( var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if w->first() = 1 then ( s := s + w[2+1] - d.get(w[1+1], x) ; d[w[1+1]+1] := w[2+1] ) else ( s := w[1+1] * n ; execute (d /<: d) ; x := w[1+1] ) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=list(map(int,input().split())) ans=0 while a>0 and b>0 : if a==1 and b==1 : break if a>b : a-=2 b+=1 else : b-=2 a+=1 ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; while a > 0 & b > 0 do ( if a = 1 & b = 1 then ( break ) else skip ; if (a->compareTo(b)) > 0 then ( a := a - 2 ; b := b + 1 ) else ( b := b - 2 ; a := a + 1 ) ; ans := ans + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt from collections import defaultdict,deque import sys from bisect import bisect_right as b_r from bisect import bisect_left as b_l from os import path from heapq import* input=sys.stdin.readline mod=1000000007 INT_MAX=sys.maxsize-1 INT_MIN=-sys.maxsize def myyy__answer(): n,q=map(int,input().split()) a=list(map(int,input().split())) sm=sum(a) track=defaultdict(int) for i in range(n): track[i+1]+=1 st=0 for i in range(q): b=list(map(int,input().split())) if(b[0]==1): if(track[b[1]]): sm=sm-a[b[1]-1]+b[2] a[b[1]-1]=b[2] else : a[b[1]-1]=b[2] track[b[1]]+=1 sm=sm-st+b[2] else : sm=n*b[1] track.clear() st=b[1] print(sm) if __name__=="__main__" : myyy__answer() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var mod : int := 1000000007 ; var INT_MAX : double := (trailer . (name maxsize)) - 1 ; var INT_MIN : (trailer . (name maxsize)) := -(trailer . (name maxsize)) ; skip ; if __name__ = "__main__" then ( myyy__answer() ) else skip; operation myyy__answer() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sm : OclAny := (a)->sum() ; var track : OclAny := defaultdict(OclType["int"]) ; for i : Integer.subrange(0, n-1) do ( track[i + 1+1] := track[i + 1+1] + 1) ; var st : int := 0 ; for i : Integer.subrange(0, q-1) do ( var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (b->first() = 1) then ( if (track[b[1+1]+1]) then ( sm := sm - a[b[1+1] - 1+1] + b[2+1] ; a[b[1+1] - 1+1] := b[2+1] ) else ( a[b[1+1] - 1+1] := b[2+1] ; track[b[1+1]+1] := track[b[1+1]+1] + 1 ; sm := sm - st + b[2+1] ) ) else ( sm := n * b[1+1] ; execute (track /<: track) ; st := b[1+1] ) ; execute (sm)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt from collections import defaultdict,deque import sys from bisect import bisect_right as b_r from bisect import bisect_left as b_l from os import path from heapq import* input=sys.stdin.readline mod=1000000007 INT_MAX=sys.maxsize-1 INT_MIN=-sys.maxsize def myyy__answer(): n,q=map(int,input().split()) a=list(map(int,input().split())) sm=sum(a) track=defaultdict(int) for i in range(n): track[i+1]=0 st=0 cnt2=0 for i in range(q): b=list(map(int,input().split())) if(b[0]==1): if(track[b[1]]==cnt2): sm=sm-a[b[1]-1]+b[2] a[b[1]-1]=b[2] else : a[b[1]-1]=b[2] track[b[1]]=cnt2 sm=sm-st+b[2] else : sm=n*b[1] st=b[1] cnt2+=1 print(sm) if __name__=="__main__" : myyy__answer() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var mod : int := 1000000007 ; var INT_MAX : double := (trailer . (name maxsize)) - 1 ; var INT_MIN : (trailer . (name maxsize)) := -(trailer . (name maxsize)) ; skip ; if __name__ = "__main__" then ( myyy__answer() ) else skip; operation myyy__answer() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sm : OclAny := (a)->sum() ; var track : OclAny := defaultdict(OclType["int"]) ; for i : Integer.subrange(0, n-1) do ( track[i + 1+1] := 0) ; var st : int := 0 ; var cnt2 : int := 0 ; for i : Integer.subrange(0, q-1) do ( var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (b->first() = 1) then ( if (track[b[1+1]+1] = cnt2) then ( sm := sm - a[b[1+1] - 1+1] + b[2+1] ; a[b[1+1] - 1+1] := b[2+1] ) else ( a[b[1+1] - 1+1] := b[2+1] ; track[b[1+1]+1] := cnt2 ; sm := sm - st + b[2+1] ) ) else ( sm := n * b[1+1] ; st := b[1+1] ; cnt2 := cnt2 + 1 ) ; execute (sm)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while(t): x,y=[int(i)for i in input().split()] dab=(x+y)//2 if((x+y)% 2==0): xb,yb=0,0 if(x>=dab): xb=x-dab yb=dab-xb elif(y>=dab): yb=y-dab xb=dab-yb print(xb,yb) else : print(-1,-1) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (t) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var dab : int := (x + y) div 2 ; if ((x + y) mod 2 = 0) then ( var xb : OclAny := null; var yb : OclAny := null; Sequence{xb,yb} := Sequence{0,0} ; if ((x->compareTo(dab)) >= 0) then ( var xb : double := x - dab ; var yb : double := dab - xb ) else (if ((y->compareTo(dab)) >= 0) then ( yb := y - dab ; xb := dab - yb ) else skip) ; execute (xb)->display() ) else ( execute (-1)->display() ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt from collections import defaultdict,deque import sys from bisect import bisect_right as b_r from bisect import bisect_left as b_l from os import path from heapq import* input=sys.stdin.readline mod=1000000007 INT_MAX=sys.maxsize-1 INT_MIN=-sys.maxsize def myyy__answer(): n,q=map(int,input().split()) a=list(map(int,input().split())) sm=sum(a) track=defaultdict(int) for i in range(n): track[i+1]=0 st=0 cnt2=0 for i in range(q): b=list(map(int,input().split())) if(b[0]==1): if(track[b[1]]==cnt2): sm=sm-a[b[1]-1]+b[2] a[b[1]-1]=b[2] else : a[b[1]-1]=b[2] track[b[1]]=cnt2 sm=sm-st+b[2] else : sm=n*b[1] st=b[1] cnt2+=1 print(sm) if __name__=="__main__" : myyy__answer() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var mod : int := 1000000007 ; var INT_MAX : double := (trailer . (name maxsize)) - 1 ; var INT_MIN : (trailer . (name maxsize)) := -(trailer . (name maxsize)) ; skip ; if __name__ = "__main__" then ( myyy__answer() ) else skip; operation myyy__answer() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sm : OclAny := (a)->sum() ; var track : OclAny := defaultdict(OclType["int"]) ; for i : Integer.subrange(0, n-1) do ( track[i + 1+1] := 0) ; var st : int := 0 ; var cnt2 : int := 0 ; for i : Integer.subrange(0, q-1) do ( var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (b->first() = 1) then ( if (track[b[1+1]+1] = cnt2) then ( sm := sm - a[b[1+1] - 1+1] + b[2+1] ; a[b[1+1] - 1+1] := b[2+1] ) else ( a[b[1+1] - 1+1] := b[2+1] ; track[b[1+1]+1] := cnt2 ; sm := sm - st + b[2+1] ) ) else ( sm := n * b[1+1] ; st := b[1+1] ; cnt2 := cnt2 + 1 ) ; execute (sm)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,q=map(int,input().split()) a=list(map(int,input().split())) ans=sum(a) d=dict() for i in range(n): d[i+1]=a[i] for _ in range(q): query=list(map(int,input().split())) if query[0]==1 : t,i,x=query if i not in d : ans-=tmp else : ans-=d[i] ans+=x d[i]=x else : t,x=query tmp=x ans=tmp*n d.clear() print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : OclAny := (a)->sum() ; var d : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( d[i + 1+1] := a[i+1]) ; for _anon : Integer.subrange(0, q-1) do ( var query : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if query->first() = 1 then ( var t : OclAny := null; var i : OclAny := null; var x : OclAny := null; Sequence{t,i,x} := query ; if (d)->excludes(i) then ( ans := ans - tmp ) else ( ans := ans - d[i+1] ) ; ans := ans + x ; d[i+1] := x ) else ( var t : OclAny := null; var x : OclAny := null; Sequence{t,x} := query ; var tmp : OclAny := x ; ans := tmp * n ; execute (d /<: d) ) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class getNode : def __init__(self,data): self.data=data self.left=self.right=None def hasPath(root,arr,x): if(not root): return False arr.append(root.data) if(root.data==x): return True if(hasPath(root.left,arr,x)or hasPath(root.right,arr,x)): return True arr.pop(-1) return False def printPath(root,x): arr=[] if(hasPath(root,arr,x)): for i in range(len(arr)-1): print(arr[i],end="->") print(arr[len(arr)-1]) else : print("No Path") if __name__=='__main__' : root=getNode(1) root.left=getNode(2) root.right=getNode(3) root.left.left=getNode(4) root.left.right=getNode(5) root.right.left=getNode(6) root.right.right=getNode(7) x=5 printPath(root,x) ------------------------------------------------------------ OCL File: --------- class getNode { static operation newgetNode() : getNode pre: true post: getNode->exists( _x | result = _x ); attribute data : OclAny := data; attribute left : OclAny := null; var self.right : OclAny := null; operation initialise(data : OclAny) : getNode pre: true post: true activity: self.data := data ; self.left := null; var self.right : OclAny := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( root := (getNode.newgetNode()).initialise(1) ; root.left := (getNode.newgetNode()).initialise(2) ; root.right := (getNode.newgetNode()).initialise(3) ; root.left.left := (getNode.newgetNode()).initialise(4) ; root.left.right := (getNode.newgetNode()).initialise(5) ; root.right.left := (getNode.newgetNode()).initialise(6) ; root.right.right := (getNode.newgetNode()).initialise(7) ; x := 5 ; printPath(root, x) ) else skip; operation hasPath(root : OclAny, arr : OclAny, x : OclAny) : OclAny pre: true post: true activity: if (not(root)) then ( return false ) else skip ; execute ((root.data) : arr) ; if (root.data = x) then ( return true ) else skip ; if (hasPath(root.left, arr, x) or hasPath(root.right, arr, x)) then ( return true ) else skip ; arr := arr->excludingAt(-1+1) ; return false; operation printPath(root : OclAny, x : OclAny) pre: true post: true activity: arr := Sequence{} ; if (hasPath(root, arr, x)) then ( for i : Integer.subrange(0, (arr)->size() - 1-1) do ( execute (arr[i+1])->display()) ; execute (arr[(arr)->size() - 1+1])->display() ) else ( execute ("No Path")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil def solve(): n,l,r=map(int,input().split()) resp=[] for i in range(1,n+1): if l<=ceil(l/i)*i<=r : resp.append(ceil(l/i)*i) continue elif l<=(ceil(l/i)+1)*i<=r : resp.append((ceil(l/i)+1)*i) continue print('NO') return print('YES') for ai in resp : print(ai,end=" ") print() for tc in range(int(input())): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for tc : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve()); operation solve() pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{n,l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var resp : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( if (l->compareTo(ceil(l / i) * i)) <= 0 & (ceil(l / i) * i <= r) then ( execute ((ceil(l / i) * i) : resp) ; continue ) else (if (l->compareTo((ceil(l / i) + 1) * i)) <= 0 & ((ceil(l / i) + 1) * i <= r) then ( execute (((ceil(l / i) + 1) * i) : resp) ; continue ) else skip) ; execute ('NO')->display() ; return) ; execute ('YES')->display() ; for ai : resp do ( execute (ai)->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=eval(input()) from math import ceil for _ in range(t): n,l,r=map(int,input().split()) ans=[] for i in range(1,n+1): k=ceil(l/i)*i if k<=r : ans.append(k) else : print("no") break else : print("yes") print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := (OclFile["System.in"]).readLine() ; skip ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{n,l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := Sequence{} ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name k)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name ceil)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name l))) / (expr (atom (name i))))))))) )))) * (expr (atom (name i))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name k)))) <= (comparison (expr (atom (name r))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name k)))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "no"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "yes"))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom (name ans)))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil for _ in range(int(input())): n,l,r=map(int,input().split()) li=list() for i in range(1,n+1): val=ceil(l/i)*i if val<=r : li.append(val) else : print('NO') break else : print('YES') print(*li) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{n,l,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var li : Sequence := () ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name val)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name ceil)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name l))) / (expr (atom (name i))))))))) )))) * (expr (atom (name i))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name val)))) <= (comparison (expr (atom (name r))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name li)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name val)))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom (name li)))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from collections import defaultdict from itertools import product read_str=lambda : input() read_strs=lambda : input().split() read_int=lambda : int(read_str()) read_ints=lambda : list(map(int,read_str().split())) write_strs=lambda x,sep=' ' : sep.join(list(map(str,x))) def solve(n,l,r): res=[l] for i in range(1,n): res+=[math.ceil(l/(i+1))*(i+1)] if res[-1]>r : print('NO') return print('YES') print(write_strs(res)) T=read_int() for _ in range(T): N,L,R=read_ints() solve(N,L,R) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var read_str : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var read_strs : Function := lambda $$ : OclAny in (input().split()) ; var read_int : Function := lambda $$ : OclAny in (("" + ((read_str->apply())))->toInteger()) ; var read_ints : Function := lambda $$ : OclAny in (((read_str->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var write_strs : Function := lambda x : OclAny, sep : String in (StringLib.sumStringsWithSeparator((((x)->collect( _x | (OclType["String"])->apply(_x) ))), sep)) ; skip ; var T : OclAny := read_int->apply() ; for _anon : Integer.subrange(0, T-1) do ( var N : OclAny := null; var L : OclAny := null; var R : OclAny := null; Sequence{N,L,R} := read_ints->apply() ; solve(N, L, R)); operation solve(n : OclAny, l : OclAny, r : OclAny) pre: true post: true activity: var res : Sequence := Sequence{ l } ; for i : Integer.subrange(1, n-1) do ( res := res + Sequence{ (l / (i + 1))->ceil() * (i + 1) } ; if (res->last()->compareTo(r)) > 0 then ( execute ('NO')->display() ; return ) else skip) ; execute ('YES')->display() ; execute (write_strs->apply(res))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a,b=map(int,input().split()) ans=0 while a>0 and b>0 : ans+=1 if a>=b : a-=2 b+=1 else : a+=1 b-=2 if a<0 or b<0 : ans-=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; while a > 0 & b > 0 do ( ans := ans + 1 ; if (a->compareTo(b)) >= 0 then ( a := a - 2 ; b := b + 1 ) else ( a := a + 1 ; b := b - 2 )) ; if a < 0 or b < 0 then ( ans := ans - 1 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,l,r=list(map(int,input().split())) res=[0]*(n+1) ok=True for i in range(1,n+1): res[i]=((l-1)//i+1)*i ok=ok and res[i]<=r if not ok : print("NO"); continue print("YES") print(*res[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var l : OclAny := null; var r : OclAny := null; Sequence{n,l,r} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var ok : boolean := true ; for i : Integer.subrange(1, n + 1-1) do ( res[i+1] := ((l - 1) div i + 1) * i ; ok := ok & (res[i+1]->compareTo(r)) <= 0) ; if not(ok) then ( execute ("NO")->display(); continue ) else skip ; execute ("YES")->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name res)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=int(input()) h=int(s/3600) s=s-3600*h m=int(s/60) s=s-60*m print(str(h)+":"+str(m)+":"+str(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var h : int := ("" + ((s / 3600)))->toInteger() ; s := s - 3600 * h ; var m : int := ("" + ((s / 60)))->toInteger() ; s := s - 60 * m ; execute (("" + ((h))) + ":" + ("" + ((m))) + ":" + ("" + ((s))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=int(input()) h=S//3600 m=(S-h*3600)//60 s=S-h*3600-m*60 print(h,end='') print(':',end='') print(m,end='') print(':',end='') print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var h : int := S div 3600 ; var m : int := (S - h * 3600) div 60 ; var s : double := S - h * 3600 - m * 60 ; execute (h)->display() ; execute (':')->display() ; execute (m)->display() ; execute (':')->display() ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) lista=[] lis=[int(x)for x in input().split()] i=0 while(itoInteger() ; var lista : Sequence := Sequence{} ; var lis : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var i : int := 0 ; while ((i->compareTo(num)) < 0) do ( if ((lista)->includes(lis[i+1])) then ( execute ((lis[i+1]) /: lista) ) else skip ; execute ((lis[i+1]) : lista) ; i := i + 1) ; execute ((lista)->size())->display() ; i := 0 ; while ((i->compareTo((lista)->size())) < 0) do ( execute (lista[i+1])->display() ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import* from decimal import* import sys from tkinter import N input_=sys.stdin.readline def _input(): return map(int,input().split()) def _list(): return list(map(int,input().split())) def solves(): n,m=_input() k=(n+m)//2 if(m==0 and n==0): print(0,0) elif(m-n>0 and(m-n)% 2==0): print(k+n-m+(m-n)//2,(m-n)//2) elif(n-m>0 and(n-m)% 2==0): print((n-m)//2,(n-m)//2+k-n+m) elif m==n : print(0,n) else : print(-1,-1) t=1 t=int(input()) for _ in range(0,t): solves() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var input_ : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; var t : int := 1 ; t := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( solves()); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation _list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation solves() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := _input() ; var k : int := (n + m) div 2 ; if (m = 0 & n = 0) then ( execute (0)->display() ) else (if (m - n > 0 & (m - n) mod 2 = 0) then ( execute (k + n - m + (m - n) div 2)->display() ) else (if (n - m > 0 & (n - m) mod 2 = 0) then ( execute ((n - m) div 2)->display() ) else (if m = n then ( execute (0)->display() ) else ( execute (-1)->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=int(input()) ss=s % 60 hhmm=s//60 mm=hhmm % 60 hh=hhmm//60 print(hh,mm,ss,sep=':') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ss : int := s mod 60 ; var hhmm : int := s div 60 ; var mm : int := hhmm mod 60 ; var hh : int := hhmm div 60 ; execute (hh)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=int(input()) print(str(s//3600)+':'+str((s % 3600)//60)+':'+str((s % 3600)% 60)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (("" + ((s div 3600))) + ':' + ("" + (((s mod 3600) div 60))) + ':' + ("" + (((s mod 3600) mod 60))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- HOUR=3600 MIN=60 x=int(input()) H=x//HOUR x=x % HOUR M=x//MIN x=x % MIN S=x print('%d:%d:%d' %(H,M,S)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var HOUR : int := 3600 ; var MIN : int := 60 ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var H : int := x div HOUR ; x := x mod HOUR ; var M : int := x div MIN ; x := x mod MIN ; var S : int := x ; execute (StringLib.format('%d:%d:%d',Sequence{H, M, S}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def to_four(n): if n==0 : return "0" acc="" while n : acc=str(n % 4)+acc n//=4 return acc while True : n=int(input()) if n==-1 : break print(to_four(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = -1 then ( break ) else skip ; execute (to_four(n))->display()); operation to_four(n : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( return "0" ) else skip ; var acc : String := "" ; while n do ( acc := ("" + ((n mod 4))) + acc ; n := n div 4) ; return acc; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy from test.support import _MemoryWatchdog BIG_NUM=2000000000 HUGE_NUM=99999999999999999 MOD=1000000007 EPS=0.000000001 sys.setrecursionlimit(100000) MAX=10 POW=[1]*(MAX) for i in range(1,MAX): POW[i]=POW[i-1]*4 while True : NUM=int(input()) if NUM==-1 : break elif NUM==0 : print("0") continue First=True for i in range(MAX-1,-1,-1): if POW[i]<=NUM : print("%d" %(NUM//POW[i]),end="") NUM %=POW[i] First=False else : if First : pass else : print("0",end="") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var HUGE_NUM : int := 99999999999999999 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; sys.setrecursionlimit(100000) ; var MAX : int := 10 ; var POW : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (MAX)) ; for i : Integer.subrange(1, MAX-1) do ( POW[i+1] := POW[i - 1+1] * 4) ; while true do ( var NUM : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if NUM = -1 then ( break ) else (if NUM = 0 then ( execute ("0")->display() ; continue ) else skip) ; var First : boolean := true ; for i : Integer.subrange(-1 + 1, MAX - 1)->reverse() do ( if (POW[i+1]->compareTo(NUM)) <= 0 then ( execute (StringLib.format("%d",(NUM div POW[i+1])))->display() ; NUM := NUM mod POW[i+1] ; First := false ) else ( if First then ( skip ) else ( execute ("0")->display() ) )) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution : def xorQueries(self,arr : List[int],queries : List[List[int]])->List[int]: pref=[0] for e in arr : pref.append(e ^ pref[-1]) ans=[] for[l,r]in queries : ans.append(pref[r+1]^ pref[l]) return ans ------------------------------------------------------------ OCL File: --------- class Solution { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation xorQueries(arr : List[OclType["int"]+1],queries : List[List[OclType["int"]+1]+1]) : OclAny pre: true post: true activity: var pref : Sequence := Sequence{ 0 } ; for e : arr do ( execute ((MathLib.bitwiseXor(e, pref->last())) : pref)) ; var ans : Sequence := Sequence{} ; for Sequence{l}->union(Sequence{ r }) : queries do ( execute ((MathLib.bitwiseXor(pref[r + 1+1], pref[l+1])) : ans)) ; return ans; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,bisect PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") VALUES={chr(65+i): 10+i for i in range(26)} for i in range(10): VALUES[str(i)]=i INV_VALUES={value : key for key,value in VALUES.items()} POWERS={(base,power): base**power for base in range(1,37)for power in range(200)} def from_base(k,base_k): L=len(k) res=0 for i in range(L-1,-1,-1): res+=VALUES[k[i]]*POWERS[(base_k,L-1-i)] return res def to_base(d,to_base): if d==0 : return 0 res="" for p in range(50,-1,-1): power=POWERS[(to_base,p)] m=d//power res+=INV_VALUES[m] d=d % power while res[0]=='0' : res=res[1 :] return res while True : n=int(input()) if n==-1 : break print(to_base(n,4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; var VALUES : Map := Integer.subrange(0, 26-1)->select(i | true)->collect(i | Map{(65 + i)->byte2char() |-> 10 + i})->unionAll() ; for i : Integer.subrange(0, 10-1) do ( VALUES[("" + ((i)))+1] := i) ; var INV_VALUES : Map := VALUES->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->select(_tuple | true)->collect(_tuple | Map{value |-> key})->unionAll() ; var POWERS : Map := Integer.subrange(1, 37-1)->select(base; power : Integer.subrange(0, 200-1) | true)->collect(base; power : Integer.subrange(0, 200-1) | Map{Sequence{base, power} |-> (base)->pow(power)})->unionAll() ; skip ; skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = -1 then ( break ) else skip ; execute (to_base(n, 4))->display()); operation from_base(k : OclAny, base_k : OclAny) : OclAny pre: true post: true activity: var L : int := (k)->size() ; var res : int := 0 ; for i : Integer.subrange(-1 + 1, L - 1)->reverse() do ( res := res + VALUES[k[i+1]+1] * POWERS[Sequence{base_k, L - 1 - i}+1]) ; return res; operation to_base(d : OclAny, to_base : OclAny) : OclAny pre: true post: true activity: if d = 0 then ( return 0 ) else skip ; res := "" ; for p : Integer.subrange(-1 + 1, 50)->reverse() do ( var power : OclAny := POWERS[Sequence{to_base, p}+1] ; var m : int := d div power ; res := res + INV_VALUES[m+1] ; d := d mod power) ; while res->first() = '0' do ( res := res->tail()) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : a=input() if a<0 : break x='' while a : x=str(a % 4)+x a/=4 print[x,'0'][x==''] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var a : String := (OclFile["System.in"]).readLine() ; if a < 0 then ( break ) else skip ; var x : String := '' ; while a do ( x := ("" + ((StringLib.format(a,4)))) + x ; a := a / 4) ; (expr (atom print) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x))))))) , (subscript (test (logical_test (comparison (expr (atom '0'))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (comparison (expr (atom (name x)))) == (comparison (expr (atom '')))))))) ])))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(): for line in sys.stdin : n=int(line) if n==-1 : break else : if n!=0 : hoge=[] while True : foo=n//4 bar=n % 4 if foo>=4 : hoge.append(bar) n=foo elif foo<4 : hoge.append(bar) hoge.append(foo) break hoge.reverse() hoge=[str(hoge[i])for i in range(len(hoge))] fuga="" for i in range(len(hoge)): fuga+=hoge[i] print(int(fuga)) elif n==0 : print(n) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: for line : OclFile["System.in"] do ( var n : int := ("" + ((line)))->toInteger() ; if n = -1 then ( break ) else ( if n /= 0 then ( var hoge : Sequence := Sequence{} ; while true do ( var foo : int := n div 4 ; var bar : int := n mod 4 ; if foo >= 4 then ( execute ((bar) : hoge) ; n := foo ) else (if foo < 4 then ( execute ((bar) : hoge) ; execute ((foo) : hoge) ; break ) else skip)) ; hoge := hoge->reverse() ; hoge := Integer.subrange(0, (hoge)->size()-1)->select(i | true)->collect(i | (("" + ((hoge[i+1]))))) ; var fuga : String := "" ; for i : Integer.subrange(0, (hoge)->size()-1) do ( fuga := fuga + hoge[i+1]) ; execute (("" + ((fuga)))->toInteger())->display() ) else (if n = 0 then ( execute (n)->display() ) else skip) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def mostCommon(lower,higher): if(lower==higher): return lower else : return 2 lower=10 higher=20 print("The most frequent factor",mostCommon(lower,higher)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; lower := 10 ; higher := 20 ; execute ("The most frequent factor")->display(); operation mostCommon(lower : OclAny, higher : OclAny) : OclAny pre: true post: true activity: if (lower = higher) then ( return lower ) else ( return 2 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class newNode : def __init__(self,data): self.data=data self.left=None self.right=None self.visited=False def postorder(head): temp=head while(temp and temp.visited==False): if(temp.left and temp.left.visited==False): temp=temp.left elif(temp.right and temp.right.visited==False): temp=temp.right else : print(temp.data,end=" ") temp.visited=True temp=head if __name__=='__main__' : root=newNode(8) root.left=newNode(3) root.right=newNode(10) root.left.left=newNode(1) root.left.right=newNode(6) root.left.right.left=newNode(4) root.left.right.right=newNode(7) root.right.right=newNode(14) root.right.right.left=newNode(13) postorder(root) ------------------------------------------------------------ OCL File: --------- class newNode { static operation newnewNode() : newNode pre: true post: newNode->exists( _x | result = _x ); attribute data : OclAny := data; attribute left : OclAny := null; attribute right : OclAny := null; attribute visited : boolean := false; operation initialise(data : OclAny) : newNode pre: true post: true activity: self.data := data ; self.left := null ; self.right := null ; self.visited := false; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var root : newNode := (newNode.newnewNode()).initialise(8) ; root.left := (newNode.newnewNode()).initialise(3) ; root.right := (newNode.newnewNode()).initialise(10) ; root.left.left := (newNode.newnewNode()).initialise(1) ; root.left.right := (newNode.newnewNode()).initialise(6) ; root.left.right.left := (newNode.newnewNode()).initialise(4) ; root.left.right.right := (newNode.newnewNode()).initialise(7) ; root.right.right := (newNode.newnewNode()).initialise(14) ; root.right.right.left := (newNode.newnewNode()).initialise(13) ; postorder(root) ) else skip; operation postorder(head : OclAny) pre: true post: true activity: var temp : OclAny := head ; while (temp & temp.visited = false) do ( if (temp.left & temp.left.visited = false) then ( temp := temp.left ) else (if (temp.right & temp.right.visited = false) then ( temp := temp.right ) else ( execute (temp.data)->display() ; temp.visited := true ; temp := head ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): x,y=map(int,input().split()) if(x+y)% 2==0 : print(x//2,y//2+x % 2) else : print(-1,-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (x + y) mod 2 = 0 then ( execute (x div 2)->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter s=input() a=[s[i : j]for i in range(len(s))for j in range(i+1,len(s)+1)] res=0 b=Counter(a) for i in b.items(): if i[1]>1 : if len(i[0])>res : res=len(i[0]) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : String := (OclFile["System.in"]).readLine() ; var a : Sequence := Integer.subrange(0, (s)->size()-1)->select(i; j : Integer.subrange(i + 1, (s)->size() + 1-1) | true)->collect(i; j : Integer.subrange(i + 1, (s)->size() + 1-1) | (s.subrange(i+1, j))) ; var res : int := 0 ; var b : OclAny := Counter(a) ; for i : b->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do ( if i[1+1] > 1 then ( if ((i->first())->size()->compareTo(res)) > 0 then ( res := (i->first())->size() ) else skip ) else skip) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline s=input()[:-1] n=len(s) k=n ans=-1 while k : k-=1 for i in range(n-k): x=s[i : k+i] if s.find(x,i+1)!=-1 : ans=k break if ans!=-1 : break if ans==-1 : print(0) else : print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var s : OclAny := input()->front() ; var n : int := (s)->size() ; var k : int := n ; var ans : int := -1 ; while k do ( k := k - 1 ; for i : Integer.subrange(0, n - k-1) do ( var x : OclAny := s.subrange(i+1, k + i) ; if s->indexOf(x, i + 1) - 1 /= -1 then ( ans := k ; break ) else skip) ; if ans /= -1 then ( break ) else skip) ; if ans = -1 then ( execute (0)->display() ) else ( execute (k)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count_overlapping_substrings(haystack,needle): count=0 i=-1 while True : i=haystack.find(needle,i+1) if i==-1 : return count count+=1 k=str(input()) mx=0 for i in range(len(k)-1): for j in range(i+1,len(k)): if count_overlapping_substrings(k,k[i : j])>=2 and j-i>mx : mx=j-i print(mx) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var k : String := ("" + (((OclFile["System.in"]).readLine()))) ; var mx : int := 0 ; for i : Integer.subrange(0, (k)->size() - 1-1) do ( for j : Integer.subrange(i + 1, (k)->size()-1) do ( if count_overlapping_substrings(k, k.subrange(i+1, j)) >= 2 & (j - i->compareTo(mx)) > 0 then ( mx := j - i ) else skip)) ; execute (mx)->display(); operation count_overlapping_substrings(haystack : OclAny, needle : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var i : int := -1 ; while true do ( i := haystack->indexOf(needle, i + 1) - 1 ; if i = -1 then ( return count ) else skip ; count := count + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict s=input() d=defaultdict(int) for i in range(len(s)): for j in range(i,len(s)): t=s[i : j+1] d[t]+=1 ans=0 for i in d : if d[i]>=2 : ans=max(ans,len(i)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : String := (OclFile["System.in"]).readLine() ; var d : OclAny := defaultdict(OclType["int"]) ; for i : Integer.subrange(0, (s)->size()-1) do ( for j : Integer.subrange(i, (s)->size()-1) do ( var t : OclAny := s.subrange(i+1, j + 1) ; d[t+1] := d[t+1] + 1)) ; var ans : int := 0 ; for i : d do ( if d[i+1] >= 2 then ( ans := Set{ans, (i)->size()}->max() ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(str,input().split()) n=int(input()) for i in range(n+1): if i==0 : print(a,b) else : delete,replace=map(str,input().split()) if delete==a : print(replace,b) a,b=replace,b else : print(a,replace) a,b=a,replace ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n + 1-1) do ( if i = 0 then ( execute (a)->display() ) else ( var delete : OclAny := null; var replace : OclAny := null; Sequence{delete,replace} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; if delete = a then ( execute (replace)->display() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{replace,b} ) else ( execute (a)->display() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{a,replace} ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sum(N): global S1,S2,S3 S1=(((N//3))*(2*3+(N//3-1)*3)//2) S2=(((N//4))*(2*4+(N//4-1)*4)//2) S3=(((N//12))*(2*12+(N//12-1)*12)//2) return int(S1+S2-S3) if __name__=='__main__' : N=12 print(sum(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute S1 : OclAny; attribute S2 : OclAny; attribute S3 : OclAny; operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( N := 12 ; execute ((N)->sum())->display() ) else skip; operation sum(N : OclAny) : OclAny pre: true post: true activity: skip; skip; skip ; S1 := (((N div 3)) * (2 * 3 + (N div 3 - 1) * 3) div 2) ; S2 := (((N div 4)) * (2 * 4 + (N div 4 - 1) * 4) div 2) ; S3 := (((N div 12)) * (2 * 12 + (N div 12 - 1) * 12) div 2) ; return ("" + ((S1 + S2 - S3)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ksusha(): n,k=map(int,input().split()) inp_road=input() rocks=[0 for i in range(n)] i,j=0,0 for symb in inp_road : if symb=="#" : rocks[i]+=1 else : i+=1 if rocks[0]<=k and max(rocks[1 :])collect( _x | (OclType["int"])->apply(_x) ) ; var inp_road : String := (OclFile["System.in"]).readLine() ; var rocks : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,0} ; for symb : inp_road->characters() do ( if symb = "#" then ( rocks[i+1] := rocks[i+1] + 1 ) else ( i := i + 1 )) ; if (rocks->first()->compareTo(k)) <= 0 & ((rocks->tail())->max()->compareTo(k)) < 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (n,k)=map(int,input().split(' ')) s=input() furthest_jump=0 i=0 jump=0 while ifurthest_jump : furthest_jump=jump jump=0 i+=1 if furthest_jumpcollect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var furthest_jump : int := 0 ; var i : int := 0 ; var jump : int := 0 ; while (i->compareTo(n)) < 0 do ( if s[i+1] = '#' then ( jump := jump + 1 ) else ( if (jump->compareTo(furthest_jump)) > 0 then ( furthest_jump := jump ) else skip ; jump := 0 ) ; i := i + 1) ; if (furthest_jump->compareTo(k)) < 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) i=input() print(["YES","NO"]["#"*m in i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var i : String := (OclFile["System.in"]).readLine() ; execute (Sequence{"YES"}->union(Sequence{ "NO" })->select((i)->characters()->includes(StringLib.nCopies("#", m))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) i=input() print(["YES","NO"]["#"*m in i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var i : String := (OclFile["System.in"]).readLine() ; execute (Sequence{"YES"}->union(Sequence{ "NO" })->select((i)->characters()->includes(StringLib.nCopies("#", m))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) i=input() print(["YES","NO"]["#"*m in i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var i : String := (OclFile["System.in"]).readLine() ; execute (Sequence{"YES"}->union(Sequence{ "NO" })->select((i)->characters()->includes(StringLib.nCopies("#", m))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) print(len(set(a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((Set{}->union((a)))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def topsyTurvy(string): for i in range(len(string)): if(string[i]=='2' or string[i]=='4' or string[i]=='5' or string[i]=='6' or string[i]=='7' or string[i]=='9'): return False ; return True ; if __name__=="__main__" : string="1234" ; if(topsyTurvy(string)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( string := "1234"; ; if (topsyTurvy(string)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ) else skip; operation topsyTurvy(string : OclAny) pre: true post: true activity: for i : Integer.subrange(0, (string)->size()-1) do ( if (string[i+1] = '2' or string[i+1] = '4' or string[i+1] = '5' or string[i+1] = '6' or string[i+1] = '7' or string[i+1] = '9') then ( return false; ) else skip) ; return true;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSubstr(str,n,x,y): tot_count=0 count_x=0 for i in range(n): if str[i]==x : count_x+=1 if str[i]==y : tot_count+=count_x return tot_count str='abbcaceghcak' n=len(str) x,y='a','c' print('Count=',countSubstr(str,n,x,y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclType["String"] := 'abbcaceghcak' ; n := (OclType["String"])->size() ; Sequence{x,y} := Sequence{'a','c'} ; execute ('Count=')->display(); operation countSubstr(OclType["String"] : OclAny, n : OclAny, x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var tot_count : int := 0 ; var count_x : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ("" + ([i+1])) = x then ( count_x := count_x + 1 ) else skip ; if ("" + ([i+1])) = y then ( tot_count := tot_count + count_x ) else skip) ; return tot_count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): def count_reversibles(numdigits): if numdigits % 2==0 : return 20*30**(numdigits//2-1) elif numdigits % 4==3 : return 100*500**((numdigits-3)//4) elif numdigits % 4==1 : return 0 else : raise AssertionError() ans=sum(count_reversibles(d)for d in range(2,10)) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: skip ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name count_reversibles)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name d)))))))) ))))))) (comp_for for (exprlist (expr (atom (name d)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 10))))))))) )))))))))->sum() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def encodedChar(str,k): expand="" freq=0 i=0 while(i=ord('a')and ord(str[i])<=ord('z')): temp+=str[i] i+=1 while(i=ord('1')and ord(str[i])<=ord('9')): freq=freq*10+ord(str[i])-ord('0') i+=1 for j in range(1,freq+1,1): expand+=temp if(freq==0): expand+=temp return expand[k-1] if __name__=='__main__' : str="ab4c12ed3" k=21 print(encodedChar(str,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( OclType["String"] := "ab4c12ed3" ; k := 21 ; execute (encodedChar(OclType["String"], k))->display() ) else skip; operation encodedChar(OclType["String"] : OclAny, k : OclAny) : OclAny pre: true post: true activity: var expand : String := "" ; var freq : int := 0 ; var i : int := 0 ; while ((i->compareTo((OclType["String"])->size())) < 0) do ( var temp : String := "" ; freq := 0 ; while ((i->compareTo((OclType["String"])->size())) < 0 & ((("" + ([i+1])))->char2byte()->compareTo(('a')->char2byte())) >= 0 & ((("" + ([i+1])))->char2byte()->compareTo(('z')->char2byte())) <= 0) do ( temp := temp + ("" + ([i+1])) ; i := i + 1) ; while ((i->compareTo((OclType["String"])->size())) < 0 & ((("" + ([i+1])))->char2byte()->compareTo(('1')->char2byte())) >= 0 & ((("" + ([i+1])))->char2byte()->compareTo(('9')->char2byte())) <= 0) do ( freq := freq * 10 + (("" + ([i+1])))->char2byte() - ('0')->char2byte() ; i := i + 1) ; for j : Integer.subrange(1, freq + 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( expand := expand + temp)) ; if (freq = 0) then ( expand := expand + temp ) else skip ; return expand[k - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): a,b=map(int,input().split()) k=abs(a-b) p=k//5 k-=p*5 q=k//2 k-=q*2 s=k//1 k-=s print(p+q+s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : double := (a - b)->abs() ; var p : int := k div 5 ; k := k - p * 5 ; var q : int := k div 2 ; k := k - q * 2 ; var s : int := k div 1 ; k := k - s ; execute (p + q + s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): x,y=map(int,input().split()) c=0 r=abs(x-y) while r!=0 : if r>=5 : c=c+r//5 r=r % 5 elif r>=2 : c+=r//2 r=r % 2 else : r-=1 c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : int := 0 ; var r : double := (x - y)->abs() ; while r /= 0 do ( if r >= 5 then ( c := c + r div 5 ; r := r mod 5 ) else (if r >= 2 then ( c := c + r div 2 ; r := r mod 2 ) else ( r := r - 1 ; c := c + 1 ) ) ) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for j in range(t): a,b=map(int,input().split()) if a==b : print(0) else : k=0 s=abs(a-b) while s!=0 : if s>=5 : k+=s//5 s=s % 5 elif s>=2 : k+=s//2 s=s % 2 else : k+=1 s-=1 print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = b then ( execute (0)->display() ) else ( var k : int := 0 ; var s : double := (a - b)->abs() ; while s /= 0 do ( if s >= 5 then ( k := k + s div 5 ; s := s mod 5 ) else (if s >= 2 then ( k := k + s div 2 ; s := s mod 2 ) else ( k := k + 1 ; s := s - 1 ) ) ) ; execute (k)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import* from decimal import* from opcode import HAVE_ARGUMENT import sys from tkinter import N input_=sys.stdin.readline def _input(): return map(int,input().split()) def _list(): return list(map(int,input().split())) def solves(): n,m=_input() ans=abs((m-n))//5 k=abs((m-n))% 5 ans+=k//2 k=k % 2 ans+=k print(ans) t=1 t=int(input()) for _ in range(0,t): solves() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var input_ : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; var t : int := 1 ; t := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( solves()); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation _list() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation solves() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := _input() ; var ans : int := ((m - n))->abs() div 5 ; var k : int := ((m - n))->abs() mod 5 ; ans := ans + k div 2 ; k := k mod 2 ; ans := ans + k ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- butttons_up=[5,2,1] butttons_down=[-5,-2,-1] p=int(input()) for i in range(p): a,b=map(int,input().split()) change=abs(b-a) count=0 for button in butttons_up : count+=change//button change %=button print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var butttons_up : Sequence := Sequence{5}->union(Sequence{2}->union(Sequence{ 1 })) ; var butttons_down : Sequence := Sequence{-5}->union(Sequence{-2}->union(Sequence{ -1 })) ; var p : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, p-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var change : double := (b - a)->abs() ; var count : int := 0 ; for button : butttons_up do ( count := count + change div button ; change := change mod button) ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* N,K=[int(x)for x in input().strip().split()] print(ceil((N-1)/(K-1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := input()->trim().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (ceil((N - 1) / (K - 1)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=list(map(int,input().split())) p=min(a) a+=[p] ans,i,temp=0,0,0 while icollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var p : OclAny := (a)->min() ; a := a + Sequence{ p } ; var ans : OclAny := null; var i : OclAny := null; var temp : OclAny := null; Sequence{ans,i,temp} := Sequence{0,0,0} ; while (i->compareTo(n)) < 0 do ( if a[i+1] = p then ( var m : int := -(-(i - temp) div (k - 1)) ; ans := ans + m ; temp := temp + m * (k - 1) + 1 ; var i : OclAny := temp ) else ( i := i + 1 )) ; ans := ans + -(-(n - temp) div (k - 1)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def num(): return int(input()) def nums(): return list(map(int,input().split())) N=num() A=set(nums()) print(len(A)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := num() ; var A : Set := Set{}->union((nums())) ; execute ((A)->size())->display(); operation num() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation nums() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math N,K=map(int,input().split()) A=list(map(int,input().split())) Ain=A.index(1) if N==K : print("1") else : print(math.ceil(Ain/(K-1))+math.ceil((len(A)-(K-1)*(math.ceil(Ain/(K-1)))-1)/(K-1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var Ain : int := A->indexOf(1) - 1 ; if N = K then ( execute ("1")->display() ) else ( execute ((Ain / (K - 1))->ceil() + (((A)->size() - (K - 1) * ((Ain / (K - 1))->ceil()) - 1) / (K - 1))->ceil())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=[int(s)for s in input().split()] data=[int(s)for s in input().split()] i=1 while True : if(K-1)*i+1>=N : print(i) exit() else : i+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; var data : Sequence := input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; var i : int := 1 ; while true do ( if ((K - 1) * i + 1->compareTo(N)) >= 0 then ( execute (i)->display() ; exit() ) else ( i := i + 1 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printPossible(a,b,c): if((a+b+c)% 2!=0 or a+bcompareTo(c)) < 0) then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,raw_input().split(' ')) raw_input() N=N-K K=K-1 print(N+K-1)/K+1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (raw_input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; raw_input() ; var N : double := N - K ; var K : double := K - 1 ; (expr (expr (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name N))) + (expr (atom (name K)))) - (expr (atom (number (integer 1)))))))))) )))) / (expr (atom (name K)))) + (expr (atom (number (integer 1))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,*l=list(map(int,open(0).read().split())) l.sort(reverse=True) print('Yes' if l[0]collect( _x | (OclType["int"])->apply(_x) )) ; l := l->sort() ; execute (if (l->first()->compareTo((l->tail())->sum())) < 0 then 'Yes' else 'No' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sub(): N=int(input()) Ls=[int(e)for e in input().split()] Ls=sorted(Ls) a=sum(Ls[:-1]) b=Ls[-1] if btoInteger() ; var Ls : Sequence := input().split()->select(e | true)->collect(e | (("" + ((e)))->toInteger())) ; Ls := Ls->sort() ; var a : OclAny := (Ls->front())->sum() ; var b : OclAny := Ls->last() ; if (b->compareTo(a)) < 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() inp=list(map(int,input().split())) inp.sort() inp.reverse() l=sum(inp[1 :]) if inp[0]collect( _x | (OclType["int"])->apply(_x) )) ; inp := inp->sort() ; inp := inp->reverse() ; var l : OclAny := (inp->tail())->sum() ; if (inp->first()->compareTo(l)) < 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys N=int(input()) L=sys.stdin.readline().strip().split() L=[int(l)for l in L] L.sort(reverse=True) max_L=int(L.pop(0)) sum_L=sum(int(i)for i in L) if(max_LtoInteger() ; var L : OclAny := sys.stdin.readLine()->trim().split() ; L := L->select(l | true)->collect(l | (("" + ((l)))->toInteger())) ; L := L->sort() ; var max_L : int := ("" + ((L->at(0`firstArg+1))))->toInteger() ; var sum_L : OclAny := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name L))))))))->sum() ; if ((max_L->compareTo(sum_L)) < 0) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) L=list(map(int,input().split())) print("YNeos "[(max(L)>=(sum(L)-max(L))): : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var L : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ("YNeos "(subscript (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)))))))) ))))) >= (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)))))))) )))) - (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)))))))) ))))))))) )))))))) )))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dp=[0]+[1<<20]*10000 n=int(input()) for i in range(1,n): a=int(input()) for j in range(i//2+1): if dp[j]>dp[i-j]+a : dp[j]=dp[i-j]+a if dp[i-j]>dp[j]+a : dp[i-j]=dp[j]+a print(dp[n//2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dp : Sequence := Sequence{ 0 }->union(MatrixLib.elementwiseMult(Sequence{ 1 * (2->pow(20)) }, 10000)) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(1, n-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, i div 2 + 1-1) do ( if (dp[j+1]->compareTo(dp[i - j+1] + a)) > 0 then ( dp[j+1] := dp[i - j+1] + a ) else skip ; if (dp[i - j+1]->compareTo(dp[j+1] + a)) > 0 then ( dp[i - j+1] := dp[j+1] + a ) else skip)) ; execute (dp[n div 2+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) dp=[float('inf')]*(n+1) dp[0]=0 cost=[int(input())for _ in range(n-1)] for i in range(1,n): for j in range(i): if dp[i-j]+cost[i-1]toInteger() ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ ("" + (('inf')))->toReal() }, (n + 1)) ; dp->first() := 0 ; var cost : Sequence := Integer.subrange(0, n - 1-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; for i : Integer.subrange(1, n-1) do ( for j : Integer.subrange(0, i-1) do ( if (dp[i - j+1] + cost[i - 1+1]->compareTo(dp[j+1])) < 0 then ( dp[j+1] := dp[i - j+1] + cost[i - 1+1] ) else skip ; if (dp[j+1] + cost[i - 1+1]->compareTo(dp[i - j+1])) < 0 then ( dp[i - j+1] := dp[j+1] + cost[i - 1+1] ) else skip)) ; execute (dp[n div 2+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input(); print(len(set(list(map(int,input().split()))))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input(); execute ((Set{}->union((((input().split())->collect( _x | (OclType["int"])->apply(_x) )))))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline INF=0x7fffffff n=int(input()) dp=[INF]*(n+1) dp[0]=0 for i in range(1,n): t=int(input()) for j in range(1+(i>>1)): if dp[j]>dp[i-j]+t : dp[j]=dp[i-j]+t ; if dp[i-j]>dp[j]+t : dp[i-j]=dp[j]+t print(dp[n>>1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; var INF : int := 0x7fffffff ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, (n + 1)) ; dp->first() := 0 ; for i : Integer.subrange(1, n-1) do ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for j : Integer.subrange(0, 1 + (i /(2->pow(1)))-1) do ( if (dp[j+1]->compareTo(dp[i - j+1] + t)) > 0 then ( dp[j+1] := dp[i - j+1] + t; ) else skip ; if (dp[i - j+1]->compareTo(dp[j+1] + t)) > 0 then ( dp[i - j+1] := dp[j+1] + t ) else skip)) ; execute (dp[n /(2->pow(1))+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def summation(n): abs_sum=n*(n+1)//2 ; sign=1 if((n+1)% 2==0)else-1 ; result_sum=sign*abs_sum ; return result_sum ; if __name__=="__main__" : N=2 ; print(summation(N)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var N : int := 2; ; execute (summation(N))->display(); ) else skip; operation summation(n : OclAny) pre: true post: true activity: var abs_sum : int := n * (n + 1) div 2; ; var sign : int := if ((n + 1) mod 2 = 0) then 1 else -1 endif; ; var result_sum : int := sign * abs_sum; ; return result_sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) times=[int(input())for _ in range(n-1)] dp=[10**20 for i in range(n+1)] dp[0]=0 for i in range(1,n): for j in range(i): if dp[j]>dp[i-j]+times[i-1]: dp[j]=dp[i-j]+times[i-1] if dp[i-j]>dp[j]+times[i-1]: dp[i-j]=dp[j]+times[i-1] print(dp[n//2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var times : Sequence := Integer.subrange(0, n - 1-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | ((10)->pow(20))) ; dp->first() := 0 ; for i : Integer.subrange(1, n-1) do ( for j : Integer.subrange(0, i-1) do ( if (dp[j+1]->compareTo(dp[i - j+1] + times[i - 1+1])) > 0 then ( dp[j+1] := dp[i - j+1] + times[i - 1+1] ) else skip ; if (dp[i - j+1]->compareTo(dp[j+1] + times[i - 1+1])) > 0 then ( dp[i - j+1] := dp[j+1] + times[i - 1+1] ) else skip)) ; execute (dp[n div 2+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ascend(x,y): mini=min(A[x : x+L]) ans[x]=mini for i in range(x+1,y): if A[i+L-1]<=mini : mini=A[i+L-1] elif A[i-1]==mini : mini=min(A[i : i+L]) ans[i]=mini def descend(a,b): mini=min(A[b-1 : b+L-1]) ans[b-1]=mini for i in range(b-2,a-1,-1): if A[i]<=mini : mini=A[i] elif A[i+L]==mini : mini=min(A[i : i+L]) ans[i]=mini [N,L]=[int(x)for x in input().split()] A=[int(x)for x in input().split()] ans=[None]*(N-L+1) count=0 ; if N>10**4 : for i in range(100): if A[i+1]>A[i]: count+=1 if count>80 : descend(0,N-L+1) else : ascend(0,N-L+1) else : ascend(0,N-L+1) for i in ans[:-1]: print(i,end=" ") print(ans[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{N}->union(Sequence{ L }) := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (N - L + 1)) ; var count : int := 0; ; if (N->compareTo((10)->pow(4))) > 0 then ( for i : Integer.subrange(0, 100-1) do ( if (A[i + 1+1]->compareTo(A[i+1])) > 0 then ( count := count + 1 ) else skip) ; if count > 80 then ( descend(0, N - L + 1) ) else ( ascend(0, N - L + 1) ) ) else ( ascend(0, N - L + 1) ) ; for i : ans->front() do ( execute (i)->display()) ; execute (ans->last())->display(); operation ascend(x : OclAny, y : OclAny) pre: true post: true activity: var mini : OclAny := (A.subrange(x+1, x + L))->min() ; ans[x+1] := mini ; for i : Integer.subrange(x + 1, y-1) do ( if (A[i + L - 1+1]->compareTo(mini)) <= 0 then ( mini := A[i + L - 1+1] ) else (if A[i - 1+1] = mini then ( mini := (A.subrange(i+1, i + L))->min() ) else skip) ; ans[i+1] := mini); operation descend(a : OclAny, b : OclAny) pre: true post: true activity: mini := (A.subrange(b - 1+1, b + L - 1))->min() ; ans[b - 1+1] := mini ; for i : Integer.subrange(a - 1 + 1, b - 2)->reverse() do ( if (A[i+1]->compareTo(mini)) <= 0 then ( mini := A[i+1] ) else (if A[i + L+1] = mini then ( mini := (A.subrange(i+1, i + L))->min() ) else skip) ; ans[i+1] := mini); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate from collections import deque class SWAG : def __init__(self,operator_M,e_M): self.op_M=operator_M self.e_M=e_M self.q=deque([]) self.accL=[] self.accR=e_M self.L=self.R=0 def build(self,lst): self.q=deque(lst) self.L=len(lst) self.accL=list(accumulate(reversed(self.q),self.op_M)) def __len__(self): return self.L+self.R def fold_all(self): if self.L : return self.op_M(self.accL[-1],self.accR) else : return self.accR def append(self,x): self.q.append(x) self.accR=self.op_M(self.accR,x) self.R+=1 def popleft(self): if self.L : self.accL.pop() self.L-=1 return self.q.popleft() elif self.R : self.L,self.R=self.R-1,0 self.accL=list(accumulate(reversed(self.q),self.op_M)) self.accR=self.e_M self.accL.pop() return self.q.popleft() else : assert 0 import sys readline=sys.stdin.readline read=sys.stdin.read n,l,*a=[int(i)for i in read().split()] q=SWAG(min,10**9) q.build(a[: l]) ans=[q.fold_all()] for i in a[l :]: q.popleft() q.append(i) ans.append(q.fold_all()) print(*ans) ------------------------------------------------------------ OCL File: --------- class SWAG { static operation newSWAG() : SWAG pre: true post: SWAG->exists( _x | result = _x ); attribute op_M : OclAny := operator_M; attribute e_M : OclAny := e_M; attribute q : Sequence := (Sequence{}); attribute accL : Sequence := Sequence{}; attribute accR : OclAny := e_M; attribute L : OclAny := 0; var self.R : int := 0; operation initialise(operator_M : OclAny,e_M : OclAny) : SWAG pre: true post: true activity: self.op_M := operator_M ; self.e_M := e_M ; self.q := (Sequence{}) ; self.accL := Sequence{} ; self.accR := e_M ; self.L := 0; var self.R : int := 0; return self; operation build(lst : OclAny) pre: true post: true activity: self.q := (lst) ; self.L := (lst)->size() ; self.accL := (accumulate((self.q)->reverse(), self.op_M)); operation __len__() : OclAny pre: true post: true activity: return self.L + self.R; operation fold_all() : OclAny pre: true post: true activity: if self.L then ( return self.op_M(self.accL->last(), self.accR) ) else ( return self.accR ); operation append(x : OclAny) pre: true post: true activity: (expr (atom (name self)) (trailer . (name q)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) ; self.accR := self.op_M(self.accR, x) ; self.R := self.R + 1; operation popleft() : OclAny pre: true post: true activity: if self.L then ( (expr (atom (name self)) (trailer . (name accL)) (trailer . (name pop) (arguments ( )))) ; self.L := self.L - 1 ; return self.q->first() ) else (if self.R then ( var self.L : OclAny := null; Sequence{self.L,self.R} := Sequence{self.R - 1,0} ; self.accL := (accumulate((self.q)->reverse(), self.op_M)) ; self.accR := self.e_M ; (expr (atom (name self)) (trailer . (name accL)) (trailer . (name pop) (arguments ( )))) ; return self.q->first() ) else ( assert 0 do "assertion failed" ) ) ; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var read : OclAny := (OclFile["System.in"]).read ; var n : OclAny := null; var l : OclAny := null; var a : OclAny := null; Sequence{n,l,a} := read().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var q : SWAG := (SWAG.newSWAG()).initialise(min, (10)->pow(9)) ; q.build(a.subrange(1,l)) ; var ans : Sequence := Sequence{ q.fold_all() } ; for i : a.subrange(l+1) do ( q := q->tail() ; execute ((i) : q) ; execute ((q.fold_all()) : ans)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,itertools,collections,bisect input=lambda : sys.stdin.buffer.readline().rstrip().decode('utf-8') inf=float('inf'); mod=10**9+7 mans=inf ; ans=0 ; count=0 ; pro=1 class SWAG : def __init__(self,func,ide): self.ide=ide self.func=func self.front=[] self.back=[] def push(self,x): if self.back : y=self.func(self.back[-1][1],x) else : y=x self.back.append((x,y)) def pop(self): if not self.front : while self.back : x,y=self.back.pop() if self.front : y=self.func(self.front[-1][1],x) else : y=x self.front.append((x,y)) return self.front.pop()[1] def fold_all(self): y=self.ide if self.front : y=self.func(self.front[-1][1],y) if self.back : y=self.func(self.back[-1][1],y) return y ans=[] n,l=map(int,input().split()) data=list(map(int,input().split())) swag=SWAG(min,inf) for i in range(l-1): swag.push(data[i]) for i in range(l-1,n): swag.push(data[i]) ans.append(swag.fold_all()) swag.pop() print(*ans) ------------------------------------------------------------ OCL File: --------- class SWAG { static operation newSWAG() : SWAG pre: true post: SWAG->exists( _x | result = _x ); attribute ide : OclAny := ide; attribute func : OclAny := func; attribute front : Sequence := Sequence{}; attribute back : Sequence := Sequence{}; operation initialise(func : OclAny,ide : OclAny) : SWAG pre: true post: true activity: self.ide := ide ; self.func := func ; self.front := Sequence{} ; self.back := Sequence{}; return self; operation push(x : OclAny) pre: true post: true activity: if self.back then ( var y : OclAny := self.func(self.back->last()[1+1], x) ) else ( y := x ) ; (expr (atom (name self)) (trailer . (name back)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name x)))))) , (test (logical_test (comparison (expr (atom (name y))))))) )))))))) )))); operation pop() : OclAny pre: true post: true activity: if not(self.front) then ( while self.back do ( Sequence{x,y} := self.back->last() ; if self.front then ( y := self.func(self.front->last()[1+1], x) ) else ( y := x ) ; (expr (atom (name self)) (trailer . (name front)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name x)))))) , (test (logical_test (comparison (expr (atom (name y))))))) )))))))) ))))) ) else skip ; return self.front->last()[1+1]; operation fold_all() : OclAny pre: true post: true activity: y := self.ide ; if self.front then ( y := self.func(self.front->last()[1+1], y) ) else skip ; if self.back then ( y := self.func(self.back->last()[1+1], y) ) else skip ; return y; } class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.buffer.readLine().rstrip().decode('utf-8')) ; var Math_PINFINITY : double := ("" + (('inf')))->toReal(); var mod : double := (10)->pow(9) + 7 ; var mans : double := Math_PINFINITY; var ans : int := 0; var count : int := 0; var pro : int := 1 ; skip ; ans := Sequence{} ; var n : OclAny := null; var l : OclAny := null; Sequence{n,l} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var data : Sequence := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var swag : SWAG := (SWAG.newSWAG()).initialise(min, Math_PINFINITY) ; for i : Integer.subrange(0, l - 1-1) do ( swag.push(data[i+1])) ; for i : Integer.subrange(l - 1, n-1) do ( swag.push(data[i+1]) ; execute ((swag.fold_all()) : ans) ; swag := swag->front()) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INTMAX=(1<<31)-1 def ans(): for i in range(k): x=i+OFS A[x]=arr[i] while True : if(x<=0): break x=(x-1)//2 l=A[x*2+1] r=A[x*2+2] A[x]=l if lpow(31))) - 1 ; skip ; var _N : OclAny := null; var k : OclAny := null; Sequence{_N,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (testlist_star_expr (star_expr * (expr (atom (name arr)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name arr)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (k = 1) then ( execute ((argument * (test (logical_test (comparison (expr (atom (name arr))))))))->display() ) else ( var N : double := (2)->pow((_N - 1).bit_length()) ; var A : Sequence := MatrixLib.elementwiseMult(Sequence{ INTMAX }, (2 * N)) ; var OFS : double := N - 1 ; ans() ); operation ans() pre: true post: true activity: for i : Integer.subrange(0, k-1) do ( var x : OclAny := i + OFS ; A[x+1] := arr[i+1] ; while true do ( if (x <= 0) then ( break ) else skip ; x := (x - 1) div 2 ; var l : OclAny := A[x * 2 + 1+1] ; var r : OclAny := A[x * 2 + 2+1] ; A[x+1] := if (l->compareTo(r)) < 0 then l else r endif)) ; var res : Sequence := Sequence{} ; var c : int := 0 ; for i : Integer.subrange(0, _N - k-1) do ( execute ((A->first()) : res) ; x := c + OFS ; A[x+1] := arr[i + k+1] ; while true do ( if (x <= 0) then ( break ) else skip ; x := (x - 1) div 2 ; l := A[x * 2 + 1+1] ; r := A[x * 2 + 2+1] ; A[x+1] := if (l->compareTo(r)) < 0 then l else r endif) ; c := c + 1 ; if (c = k) then ( c := 0 ) else skip) ; execute ((A->first()) : res) ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections,numbers import random def compute(array,window,maximize): if not isinstance(window,numbers.Integral): raise TypeError() if not isinstance(maximize,bool): raise TypeError() if window<=0 : raise ValueError("Window size must be positive") result=[] deque=collections.deque() for i,val in enumerate(array): val=array[i] while len(deque)>0 and((not maximize and valdeque[-1])): deque.pop() deque.append(val) j=i+1-window if j>=0 : result.append(deque[0]) if array[j]==deque[0]: deque.popleft() return result if __name__=="__main__" : n,l=(int(x)for x in input().split()) array=list((int(x)for x in input().split())) answer=compute(array,l,False) print(*answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( var n : OclAny := null; var l : OclAny := null; Sequence{n,l} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; array := (Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))}) ; var answer : OclAny := compute(array, l, false) ; execute ((argument * (test (logical_test (comparison (expr (atom (name answer))))))))->display() ) else skip; operation compute(array : OclAny, window : OclAny, maximize : OclAny) : OclAny pre: true post: true activity: if not((numbers.Integral).isInstance(window)) then ( error CastingException.newCastingException() ) else skip ; if not((OclType["boolean"]).isInstance(maximize)) then ( error CastingException.newCastingException() ) else skip ; if window <= 0 then ( error IncorrectElementException.newIncorrectElementException("Window size must be positive") ) else skip ; var result : Sequence := Sequence{} ; var deque : Sequence := () ; for _tuple : Integer.subrange(1, (array)->size())->collect( _indx | Sequence{_indx-1, (array)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var val : OclAny := _tuple->at(_indx); var val : OclAny := array[i+1] ; while (deque)->size() > 0 & ((not(maximize) & (val->compareTo(->last())) < 0) or (maximize & (val->compareTo(->last())) > 0)) do ( deque := deque->front()) ; execute ((val) : deque) ; var j : double := i + 1 - window ; if j >= 0 then ( execute ((->first()) : result) ; if array[j+1] = ->first() then ( deque := deque->tail() ) else skip ) else skip) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input(" ")) for i in range(t): x,y,z=input(" ").split() x=int(x) y=int(y) z=int(z) if x==y and y==z and x==z : print("YES") print(x," ",y," ",z) elif x==y or x==z or y==z : M=max(x,y,z) m=min(x,y,z) if x+y+z==2*M+m : print("YES") print(M," ",m," ",m) else : print("NO") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine(" "))))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := input(" ").split() ; var x : int := ("" + ((x)))->toInteger() ; var y : int := ("" + ((y)))->toInteger() ; var z : int := ("" + ((z)))->toInteger() ; if x = y & y = z & x = z then ( execute ("YES")->display() ; execute (x)->display() ) else (if x = y or x = z or y = z then ( var M : OclAny := Set{x, y, z}->max() ; var m : OclAny := Set{x, y, z}->min() ; if x + y + z = 2 * M + m then ( execute ("YES")->display() ; execute (M)->display() ) else ( execute ("NO")->display() ) ) else ( execute ("NO")->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): list1=[] arr=[int(num)for num in input().split()] sorted_arr=sorted(arr) if sorted_arr[0]==sorted_arr[1]==sorted_arr[2]: print('YES') print(sorted_arr[0],sorted_arr[1],sorted_arr[2]) if sorted_arr[0]!=sorted_arr[1]!=sorted_arr[2]: print('NO') elif(sorted_arr[0]==sorted_arr[1])and(sorted_arr[1]!=sorted_arr[2]): print('NO') elif(sorted_arr[1]==sorted_arr[2])and(sorted_arr[1]!=sorted_arr[0]): print('YES') if sorted_arr[0]==1 : print(sorted_arr[2],1,1) else : print(sorted_arr[2],sorted_arr[0],sorted_arr[0]-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var list1 : Sequence := Sequence{} ; var arr : Sequence := input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var sorted_arr : Sequence := arr->sort() ; if sorted_arr->first() = sorted_arr[1+1] & (sorted_arr[1+1] == sorted_arr[2+1]) then ( execute ('YES')->display() ; execute (sorted_arr->first())->display() ) else skip ; if sorted_arr->first() /= sorted_arr[1+1] & (sorted_arr[1+1] != sorted_arr[2+1]) then ( execute ('NO')->display() ) else (if (sorted_arr->first() = sorted_arr[1+1]) & (sorted_arr[1+1] /= sorted_arr[2+1]) then ( execute ('NO')->display() ) else (if (sorted_arr[1+1] = sorted_arr[2+1]) & (sorted_arr[1+1] /= sorted_arr->first()) then ( execute ('YES')->display() ; if sorted_arr->first() = 1 then ( execute (sorted_arr[2+1])->display() ) else ( execute (sorted_arr[2+1])->display() ) ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][1 :]: x,y,z=sorted(map(int,s.split())); print(*(['YES',x,x,y],['NO'])[z>y]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := (s.split())->collect( _x | (OclType["int"])->apply(_x) )->sort(); execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom 'YES'))))) , (test (logical_test (comparison (expr (atom (name x)))))) , (test (logical_test (comparison (expr (atom (name x)))))) , (test (logical_test (comparison (expr (atom (name y))))))) ]))))) , (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom 'NO')))))) ])))))) )) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (comparison (expr (atom (name z)))) > (comparison (expr (atom (name y))))))))) ]))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=set() l=list(map(int,input().split())) for i in range(n): s.add(l[i]) print(len(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Set := Set{}->union(()) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( execute ((l[i+1]) : s)) ; execute ((s)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sortSquare(arr,n): for i in range(n): arr[i]=arr[i]*arr[i] arr.sort() arr=[-6,-3,-1,2,4,5] n=len(arr) print("Before sort") for i in range(n): print(arr[i],end=" ") print("\n") sortSquare(arr,n) print("After sort") for i in range(n): print(arr[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{-6}->union(Sequence{-3}->union(Sequence{-1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 5 }))))) ; n := (arr)->size() ; execute ("Before sort")->display() ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()) ; execute ("\n")->display() ; sortSquare(arr, n) ; execute ("After sort")->display() ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); operation sortSquare(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( arr[i+1] := arr[i+1] * arr[i+1]) ; arr := arr->sort(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): x,y,z=map(int,input().split()) if(x>y): (x,y)=(y,x) if(x>z): (x,z)=(z,x) if(y>z): (y,z)=(z,y) if(y!=z): print("NO") else : print("YES") print(x,x,z) ------------------------------------------------------------ OCL File: --------- class FromPython { suite`nestedAttributeDefinitions operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if ((x->compareTo(y)) > 0) then ( suite ) else skip) ; var Sequence{x, y} : OclAny := Sequence{y, x}; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): v=input().split(' ') v=[int(x)for x in v] maxValue=max(v) minValue=min(v) if v.count(maxValue)<2 : print('NO') elif v.count(maxValue)==3 : print('Yes') print(maxValue,maxValue,maxValue) else : print('YES') print(maxValue,minValue,minValue) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var v : OclAny := input().split(' ') ; v := v->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var maxValue : OclAny := (v)->max() ; var minValue : OclAny := (v)->min() ; if v->count(maxValue) < 2 then ( execute ('NO')->display() ) else (if v->count(maxValue) = 3 then ( execute ('Yes')->display() ; execute (maxValue)->display() ) else ( execute ('YES')->display() ; execute (maxValue)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout from collections import defaultdict input=stdin.readline from random import randint import math import sys for _ in range(int(input())): n=int(input()) A=input().strip() B=input().strip() L=set([(B[i],A[i])for i in range(n)if A[i]!=B[i]]) for i in range(n): if(A[i]>B[i]): print(-1) break else : answer=0 L=sorted([[item[0],item[1]]for item in L]) for i in range(len(L)): pivot=L[i][1] if(pivot!=L[i][0]): answer+=1 for j in range(i+1,len(L)): if(L[j][1]==pivot): L[j][1]=L[i][0] print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : OclAny := input()->trim() ; var B : OclAny := input()->trim() ; var L : Set := Set{}->union((Integer.subrange(0, n-1)->select(i | A[i+1] /= B[i+1])->collect(i | (Sequence{B[i+1], A[i+1]})))) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) > (comparison (expr (atom (name B)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name answer)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name L)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name item)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))) , (test (logical_test (comparison (expr (atom (name item)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))) ]))))) (comp_for for (exprlist (expr (atom (name item)))) in (logical_test (comparison (expr (atom (name L))))))) ]))))))) ))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)))))))) ))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name pivot)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name pivot)))) != (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name answer)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)))))))) ))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) == (comparison (expr (atom (name pivot)))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))))))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name answer)))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict t=int(input()) for _ in range(t): n=int(input()) s1=input() s2=input() cnt=0 d=defaultdict(str) possible=True s1=list(s1) s2=list(s2) while True : f=False last_bad='z' for c1,c2 in zip(s1,s2): if c1!=c2 : if c1>c2 : possible=False break f=True if not d[c1]: d[c1]=c2 else : d[c1]=min(d[c1],c2) last_bad=min(last_bad,c1) if not possible : break if not f : break for i,z in enumerate(zip(s1,s2)): c1,c2=z if c1!=c2 and c1==last_bad : s1[i]=d[c1] cnt+=1 print(-1 if not possible else cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s1 : String := (OclFile["System.in"]).readLine() ; var s2 : String := (OclFile["System.in"]).readLine() ; var cnt : int := 0 ; var d : OclAny := defaultdict(OclType["String"]) ; var possible : boolean := true ; s1 := (s1)->characters() ; s2 := (s2)->characters() ; while true do ( var f : boolean := false ; var last_bad : String := 'z' ; for _tuple : Integer.subrange(1, s1->size())->collect( _indx | Sequence{s1->at(_indx), s2->at(_indx)} ) do (var _indx : int := 1; var c1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c2 : OclAny := _tuple->at(_indx); if c1 /= c2 then ( if (c1->compareTo(c2)) > 0 then ( possible := false ; break ) else skip ; f := true ; if not(d[c1+1]) then ( d[c1+1] := c2 ) else ( d[c1+1] := Set{d[c1+1], c2}->min() ) ; last_bad := Set{last_bad, c1}->min() ) else skip) ; if not(possible) then ( break ) else skip ; if not(f) then ( break ) else skip ; for _tuple : Integer.subrange(1, (Integer.subrange(1, s1->size())->collect( _indx | Sequence{s1->at(_indx), s2->at(_indx)} ))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(1, s1->size())->collect( _indx | Sequence{s1->at(_indx), s2->at(_indx)} ))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var z : OclAny := _tuple->at(_indx); var c1 : OclAny := null; var c2 : OclAny := null; Sequence{c1,c2} := z ; if c1 /= c2 & c1 = last_bad then ( s1[i+1] := d[c1+1] ) else skip) ; cnt := cnt + 1) ; execute (if not(possible) then -1 else cnt endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,sys,bisect,copy from collections import defaultdict,Counter,deque if os.path.exists('in.txt'): sys.stdin=open('in.txt','r') if os.path.exists('out.txt'): sys.stdout=open('out.txt','w') def input(): return sys.stdin.readline() def mapi(arg=0): return map(int if arg==0 else str,input().split()) for _ in range(int(input())): n=int(input()) a=input().strip() b=input().strip() f=0 mp=defaultdict(list) res=0 par=[i for i in range(27)] def find(x): if par[x]==x : return x par[x]=find(par[x]) return par[x] def union(x,y): x=find(x) y=find(y) if x==y : return False par[x]=y return True orda=lambda x : ord(x)-ord("a") for i in range(n): if a[i]>b[i]: f=1 break if union(orda(a[i]),orda(b[i])): res+=1 if f==1 : print(-1) else : print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if os.path.exists('in.txt') then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('in.txt')) ) else skip ; if os.path.exists('out.txt') then ( OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile('out.txt')) ) else skip ; skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := input()->trim() ; var b : OclAny := input()->trim() ; var f : int := 0 ; var mp : OclAny := defaultdict(OclType["Sequence"]) ; var res : int := 0 ; var par : Sequence := Integer.subrange(0, 27-1)->select(i | true)->collect(i | (i)) ; skip ; skip ; var orda : Function := lambda x : OclAny in ((x)->char2byte() - ("a")->char2byte()) ; for i : Integer.subrange(0, n-1) do ( if (a[i+1]->compareTo(b[i+1])) > 0 then ( f := 1 ; break ) else skip ; if union(orda->apply(a[i+1]), orda->apply(b[i+1])) then ( res := res + 1 ) else skip) ; if f = 1 then ( execute (-1)->display() ) else ( execute (res)->display() )); operation input() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation mapi(arg : int) : OclAny pre: true post: true activity: if arg->oclIsUndefined() then arg := 0 else skip; return (input().split())->collect( _x | (if arg = 0 then OclType["int"] else OclType["String"] endif)->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout def ufind(ua,i): if ua[i]==i : return i ua[i]=ufind(ua,ua[i]) return ua[i] def union(ua,i,j): res=0 ri=ufind(ua,i) rj=ufind(ua,j) if ri!=rj : res=1 ua[ri]=rj return res def string_transformation_1(n,A,B): ans=0 ua=[i for i in range(20)] for i in range(n): a=ord(A[i])-ord('a') b=ord(B[i])-ord('a') if a>b : return-1 ans+=union(ua,a,b) return ans t=int(stdin.readline()) for _ in range(t): n=int(stdin.readline()) A=stdin.readline().strip() B=stdin.readline().strip() ans=string_transformation_1(n,A,B) stdout.write(str(ans)+'\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var t : int := ("" + ((stdin.readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( n := ("" + ((stdin.readLine())))->toInteger() ; A := stdin.readLine()->trim() ; B := stdin.readLine()->trim() ; ans := string_transformation n := ("" + ((stdin.readLine())))->toInteger()(n, A, B) ; stdout.write(("" + ((ans))) + ' ')); operation ufind(ua : OclAny, i : OclAny) : OclAny pre: true post: true activity: if ua[i+1] = i then ( return i ) else skip ; ua[i+1] := ufind(ua, ua[i+1]) ; return ua[i+1]; operation union(ua : OclAny, i : OclAny, j : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; var ri : OclAny := ufind(ua, i) ; var rj : OclAny := ufind(ua, j) ; if ri /= rj then ( res := 1 ; ua[ri+1] := rj ) else skip ; return res; operation string_transformation skip(n : OclAny, A : OclAny, B : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; ua := Integer.subrange(0, 20-1)->select(i | true)->collect(i | (i)) ; for i : Integer.subrange(0, n-1) do ( var a : double := (A[i+1])->char2byte() - ('a')->char2byte() ; var b : double := (B[i+1])->char2byte() - ('a')->char2byte() ; if (a->compareTo(b)) > 0 then ( return -1 ) else skip ; ans := ans + union(ua, a, b)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- test=int(input()) moves=[] for i in range(test): size=int(input()) current=list(input()) desired=list(input()) sum=0 if current==desired : moves.append(sum) else : unique=current+desired unique=list(set(unique)) unique.sort() for p in range(len(unique)): dupIndex=[] convertCur=[] convertDes=[] for j in range(size): if current[j]==unique[p]: dupIndex.append(j) convertCur.append(current[j]) convertDes.append(desired[j]) if dupIndex==[]: continue convertCur=list(set(convertCur)) convertDes=list(set(convertDes)) small=min(convertDes) if(small in convertDes)and(small in convertCur)and(len(convertDes)>1): convertDes.remove(small) small=min(convertDes) change=0 for j in dupIndex : if ord(desired[j])>ord(current[j]): current[j]=small change+=1 elif ord(desired[j])==ord(current[j]): continue else : sum=-1 break if change>0 and sum!=-1 : sum+=1 moves.append(sum) del unique del current for i in moves : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var test : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var moves : Sequence := Sequence{} ; for i : Integer.subrange(0, test-1) do ( var size : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var current : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var desired : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var sum : int := 0 ; if current = desired then ( execute ((sum) : moves) ) else ( var unique : Sequence := current->union(desired) ; unique := (Set{}->union((unique))) ; unique := unique->sort() ; for p : Integer.subrange(0, (unique)->size()-1) do ( var dupIndex : Sequence := Sequence{} ; var convertCur : Sequence := Sequence{} ; var convertDes : Sequence := Sequence{} ; for j : Integer.subrange(0, size-1) do ( if current[j+1] = unique[p+1] then ( execute ((j) : dupIndex) ; execute ((current[j+1]) : convertCur) ; execute ((desired[j+1]) : convertDes) ) else skip) ; if dupIndex = Sequence{} then ( continue ) else skip ; convertCur := (Set{}->union((convertCur))) ; convertDes := (Set{}->union((convertDes))) ; var small : OclAny := (convertDes)->min() ; if ((convertDes)->includes(small)) & ((convertCur)->includes(small)) & ((convertDes)->size() > 1) then ( execute ((small) /: convertDes) ; small := (convertDes)->min() ) else skip ; var change : int := 0 ; for j : dupIndex do ( if ((desired[j+1])->char2byte()->compareTo((current[j+1])->char2byte())) > 0 then ( current[j+1] := small ; change := change + 1 ) else (if (desired[j+1])->char2byte() = (current[j+1])->char2byte() then ( continue ) else ( sum := -1 ; break ) ) ) ; if change > 0 & sum /= -1 then ( sum := sum + 1 ) else skip) ; execute ((sum) : moves) ; execute (unique)->isDeleted() ; execute (current)->isDeleted() )) ; for i : moves do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=sorted([int(i)for i in input().split()]) i,j=0,0 c=0 while jtoInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))->sort() ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,0} ; var c : int := 0 ; while (j->compareTo(n - 1)) < 0 do ( if (a[j+1]->compareTo((i - j)->abs() + 1)) <= 0 then ( c := c + 1 ; j := j + 1 ; var i : OclAny := j ) else ( j := j + 1 )) ; if (a[j+1]->compareTo((i - j)->abs() + 1)) <= 0 then ( c := c + 1 ; j := j + 1 ; i := j ) else skip ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for testcase in range(t): n=int(input()) experience=input().split(' ') experience=[int(i)for i in experience] experience.sort() groups=0 i=0 group_size=1 while itoInteger() ; for testcase : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var experience : OclAny := input().split(' ') ; experience := experience->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; experience := experience->sort() ; var groups : int := 0 ; var i : int := 0 ; var group_size : int := 1 ; while (i->compareTo(n)) < 0 do ( while (i + group_size - 1->compareTo(n)) < 0 & (group_size->compareTo(experience[i + group_size - 1+1])) < 0 do ( group_size := experience[i + group_size - 1+1]) ; i := i + group_size ; group_size := 1 ; if (i->compareTo(n)) <= 0 then ( groups := groups + 1 ) else skip) ; execute (groups)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): input() a=sorted(map(int,input().split())) j,ans=1,0 for i in a : if j==i : ans+=1 ; j=0 j+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( input() ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var j : OclAny := null; var ans : OclAny := null; Sequence{j,ans} := Sequence{1,0} ; for i : a do ( if j = i then ( ans := ans + 1; var j : int := 0 ) else skip ; j := j + 1) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math while True : x=float(input()) if x==0 : break h=float(input()) l=math.sqrt(0.25*x**2+h**2) print(x**2+2*x*l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var x : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; if x = 0 then ( break ) else skip ; var h : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; var l : double := (0.25 * (x)->pow(2) + (h)->pow(2))->sqrt() ; execute ((x)->pow(2) + 2 * x * l)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=list(map(int,input().split())) a=list(map(int,input().split())) f=False c=1 i=0 while True : c=(i+1)+a[i] if(c-1)t : break i=c-1 if f : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var f : boolean := false ; var c : int := 1 ; var i : int := 0 ; while true do ( c := (i + 1) + a[i+1] ; if ((c - 1)->compareTo(i)) < 0 then ( break ) else skip ; if c = t then ( f := true ; break ) else skip ; if (c->compareTo(t)) > 0 then ( break ) else skip ; i := c - 1) ; if f then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[int(i)for i in input().split()] print(len(set(l))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute ((Set{}->union((l)))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(A): if len(A)==1 : if A[0]==1 : return 1 return 0 A.sort() n=0 l=0 ans=0 currmax=A[0] for i in range(len(A)): currmax=max(currmax,A[i]) if i-l+1>=currmax : ans+=1 l=i+1 currmax=float('-INF') return ans t=int(input()) for _ in range(t): n=int(input()) lst=list(map(int,input().split()))[: n] print(solve(lst)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["int"])->apply(_x) )).subrange(1,n) ; execute (solve(lst))->display()); operation solve(A : OclAny) : OclAny pre: true post: true activity: if (A)->size() = 1 then ( if A->first() = 1 then ( return 1 ) else skip ; return 0 ) else skip ; A := A->sort() ; var n : int := 0 ; var l : int := 0 ; var ans : int := 0 ; var currmax : OclAny := A->first() ; for i : Integer.subrange(0, (A)->size()-1) do ( currmax := Set{currmax, A[i+1]}->max() ; if (i - l + 1->compareTo(currmax)) >= 0 then ( ans := ans + 1 ; l := i + 1 ; currmax := ("" + (('-INF')))->toReal() ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numberOfDivisors(num): c=0 for i in range(1,num+1): if(num % i==0): c+=1 return c def countNumbers(n): c=0 for i in range(1,n+1): if(numberOfDivisors(i)==9): c+=1 return c if __name__=="__main__" : n=1000 print(countNumbers(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 1000 ; execute (countNumbers(n))->display() ) else skip; operation numberOfDivisors(num : OclAny) : OclAny pre: true post: true activity: var c : int := 0 ; for i : Integer.subrange(1, num + 1-1) do ( if (num mod i = 0) then ( c := c + 1 ) else skip) ; return c; operation countNumbers(n : OclAny) : OclAny pre: true post: true activity: c := 0 ; for i : Integer.subrange(1, n + 1-1) do ( if (numberOfDivisors(i) = 9) then ( c := c + 1 ) else skip) ; return c; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def oneDigit(num): return(num>=0 and num<10); def isPalUtil(num,dupNum): if(oneDigit(num)): return(num==(dupNum)% 10); if(not isPalUtil(int(num/10),dupNum)): return False ; dupNum=int(dupNum/10); return(num % 10==(dupNum)% 10); def isPal(num): if(num<0): num=-num ; dupNum=num ; return isPalUtil(num,dupNum); def printPalPrimesLessThanN(n): prime=[True]*(n+1); p=2 ; while(p*p<=n): if(prime[p]): for i in range(p*2,n+1,p): prime[i]=False ; p+=1 ; for p in range(2,n+1): if(prime[p]and isPal(p)): print(p,end=" "); n=100 ; print("Palindromic primes smaller","than or equal to",n,"are :"); printPalPrimesLessThanN(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; n := 100; ; execute ("Palindromic primes smaller")->display(); ; printPalPrimesLessThanN(n);; operation oneDigit(num : OclAny) pre: true post: true activity: return (num >= 0 & num < 10);; operation isPalUtil(num : OclAny, dupNum : OclAny) pre: true post: true activity: if (oneDigit(num)) then ( return (num = (dupNum) mod 10); ) else skip ; if (not(isPalUtil(("" + ((num / 10)))->toInteger(), dupNum))) then ( return false; ) else skip ; dupNum := ("" + ((dupNum / 10)))->toInteger(); ; return (num mod 10 = (dupNum) mod 10);; operation isPal(num : OclAny) pre: true post: true activity: if (num < 0) then ( num := -num; ) else skip ; dupNum := num; ; return isPalUtil(num, dupNum);; operation printPalPrimesLessThanN(n : OclAny) pre: true post: true activity: var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (n + 1)); ; var p : int := 2; ; while ((p * p->compareTo(n)) <= 0) do ( if (prime[p+1]) then ( for i : Integer.subrange(p * 2, n + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false;) ) else skip ; p := p + 1;) ; for p : Integer.subrange(2, n + 1-1) do ( if (prime[p+1] & isPal(p)) then ( execute (p)->display(); ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=[int(i)for i in input().split()] for i in range(n): if a[i]!=1 : break print('Second' if i & 1 else 'First') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; for i : Integer.subrange(0, n-1) do ( if a[i+1] /= 1 then ( break ) else skip) ; execute (if MathLib.bitwiseAnd(i, 1) then 'Second' else 'First' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) arr=list(map(int,input().split())) player=0 for i in range(n): if arr[i]!=1 : break if arr[i]==1 and i!=n-1 : player=1-player res='Second' if player else 'First' print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var player : int := 0 ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] /= 1 then ( break ) else skip ; if arr[i+1] = 1 & i /= n - 1 then ( player := 1 - player ) else skip) ; var res : String := if player then 'Second' else 'First' endif ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) arr=list(map(int,input().split())) player=0 for i in range(n): if arr[i]!=1 : break elif itoInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var player : int := 0 ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] /= 1 then ( break ) else (if (i->compareTo(n - 1)) < 0 then ( player := 1 - player ) else skip)) ; var res : String := if player then 'Second' else 'First' endif ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque from collections import OrderedDict import queue import heapq import math import sys sys.setrecursionlimit(10**6) def sf(): return[int(x)for x in input().split(" ")] def sfi(): return int(input()) def sfs(): return input() def printf(x): print(x) sys.stdout.flush() def main(): t=int(input()) for tc in range(t): n=int(input()) piles=[int(x)for x in input().split(" ")] winner=-1 ct=0 while ctpow(6)) ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation sf() : OclAny pre: true post: true activity: return input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation sfi() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation sfs() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation printf(x : OclAny) pre: true post: true activity: execute (x)->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name flush) (arguments ( )))); operation main() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for tc : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var piles : Sequence := input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var winner : int := -1 ; var ct : int := 0 ; while (ct->compareTo(n)) < 0 & piles[ct+1] = 1 do ( winner := winner /= 1 ; ct := ct + 1) ; if ct = n then ( winner := winner /= 1 ) else skip ; if winner <= 0 then ( execute ("First")->display() ) else ( execute ("Second")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math t=int(input()) while t>0 : t-=1 n=int(input()) a=[int(x)for x in input().split()] active=1 dain=0 for i in range(0,len(a)): if a[i]==1 : if active==1 : active=2 elif active==2 : active=1 elif a[i]!=1 : if active==1 : dain=1 print("First") break if active==2 : dain=1 print("Second") break if dain==0 : if active==1 : print("Second") else : print("First") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( t := t - 1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var active : int := 1 ; var dain : int := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( if a[i+1] = 1 then ( if active = 1 then ( active := 2 ) else (if active = 2 then ( active := 1 ) else skip) ) else (if a[i+1] /= 1 then ( if active = 1 then ( dain := 1 ; execute ("First")->display() ; break ) else skip ; if active = 2 then ( dain := 1 ; execute ("Second")->display() ; break ) else skip ) else skip)) ; if dain = 0 then ( if active = 1 then ( execute ("Second")->display() ) else ( execute ("First")->display() ) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSubsequence(arr,n): sign=[0]*n for i in range(n): if(arr[i]>0): sign[i]=1 else : sign[i]=-1 k=0 result=[0]*n i=0 while iunion(Sequence{9}->union(Sequence{4}->union(Sequence{11}->union(Sequence{-5}->union(Sequence{-17}->union(Sequence{9}->union(Sequence{-3}->union(Sequence{-5}->union(Sequence{ 2 }))))))))) ; n := (arr)->size() ; findSubsequence(arr, n) ) else skip; operation findSubsequence(arr : OclAny, n : OclAny) pre: true post: true activity: var sign : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] > 0) then ( sign[i+1] := 1 ) else ( sign[i+1] := -1 )) ; var k : int := 0 ; var result : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( var cur : OclAny := arr[i+1] ; var j : int := i ; while ((j->compareTo(n)) < 0 & sign[i+1] = sign[j+1]) do ( cur := Set{cur, arr[j+1]}->max() ; j := j + 1) ; result[k+1] := cur ; k := k + 1 ; i := j - 1 ; i := i + 1) ; for i : Integer.subrange(0, k-1) do ( execute (result[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cells,visit=input().split(); cells=int(cells); visit=int(visit) portals=list(map(int,input().split())) visited=False curr=1 for i in range(cells-1): if curr==cells : break move=curr+portals[curr-1] if move==visit : visited=True break curr=move if visited : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cells : OclAny := null; var visit : OclAny := null; Sequence{cells,visit} := input().split(); var cells : int := ("" + ((cells)))->toInteger(); var visit : int := ("" + ((visit)))->toInteger() ; var portals : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var visited : boolean := false ; var curr : int := 1 ; for i : Integer.subrange(0, cells - 1-1) do ( if curr = cells then ( break ) else skip ; var move : int := curr + portals[curr - 1+1] ; if move = visit then ( visited := true ; break ) else skip ; curr := move) ; if visited then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) diff=[] ti=int(input())+1 for _ in range(n-1): ti1=int(input()) diff.append(ti1-ti) ti=ti1+1 if n<=k : print(n) else : diff.sort() print(n+sum(diff[: n-k])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var diff : Sequence := Sequence{} ; var ti : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() + 1 ; for _anon : Integer.subrange(0, n - 1-1) do ( var ti1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((ti1 - ti) : diff) ; ti := ti1 + 1) ; if (n->compareTo(k)) <= 0 then ( execute (n)->display() ) else ( diff := diff->sort() ; execute (n + (diff.subrange(1,n - k))->sum())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- FILE_NAME_BASE='A-large' NUM_PROCESSES=0 MEM_LIMIT_GB=1.5 RECURSION_LIMIT=1000 def parse(inp): rows,cols,size=(int(x)for x in inp.readline().split()) return rows,cols,size def solve(rows,cols,size): toHit=cols/size hitFlex=cols % size toSink=size-1 if hitFlex==0 else size return rows*toHit+toSink def main(): import sys sys.setrecursionlimit(RECURSION_LIMIT) import resource soft,hard=resource.getrlimit(resource.RLIMIT_AS) resource.setrlimit(resource.RLIMIT_AS,(MEM_LIMIT_GB*1024**3,hard)) with open(FILE_NAME_BASE+'.in','r')as inp : numCases=int(inp.readline()) inputs=[parse(inp)for _ in xrange(numCases)] if NUM_PROCESSES==0 : runners=[lambda inp=inp : apply(solve,inp)for inp in inputs] else : from multiprocessing import Pool from signal import SIGINT,SIG_IGN,signal pool=Pool(NUM_PROCESSES,signal,(SIGINT,SIG_IGN)) runners=[pool.apply_async(solve,inp).get for inp in inputs] pool.close() caseFmt='%'+str(len(str(numCases)))+'d' progressFmt='[%s/%s]%%s\n' %(caseFmt,caseFmt) with open(FILE_NAME_BASE+'.out','w')as out : for case,runner in enumerate(runners,1): result=runner() out.write('Case #%d: %s\n' %(case,result)) out.flush() sys.stderr.write(progressFmt %(case,numCases,result)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var FILE_NAME_BASE : String := 'A-large' ; var NUM_PROCESSES : int := 0 ; var MEM_LIMIT_GB : double := 1.5 ; var RECURSION_LIMIT : int := 1000 ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation parse(inp : OclAny) : OclAny pre: true post: true activity: var rows : OclAny := null; var cols : OclAny := null; var size : OclAny := null; Sequence{rows,cols,size} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name inp)) (trailer . (name readline) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; return rows, cols, size; operation solve(rows : OclAny, cols : OclAny, size : OclAny) : OclAny pre: true post: true activity: var toHit : double := cols / size ; var hitFlex : int := cols mod size ; var toSink : double := if hitFlex = 0 then size - 1 else size endif ; return rows * toHit + toSink; operation main() pre: true post: true activity: skip ; sys.setrecursionlimit(RECURSION_LIMIT) ; skip ; var soft : OclAny := null; var hard : OclAny := null; Sequence{soft,hard} := resource.getrlimit(resource.RLIMIT_AS) ; resource.setrlimit(resource.RLIMIT_AS, Sequence{MEM_LIMIT_GB * (1024)->pow(3), hard}) ; try (var inp : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(FILE_NAME_BASE + '.in')); var numCases : int := ("" + ((inp.readLine())))->toInteger() ; var inputs : Sequence := xrange(numCases)->select(_anon | true)->collect(_anon | (parse(inp)))) catch (_e : OclException) do skip ; if NUM_PROCESSES = 0 then ( var runners : Sequence := inputs->select(inp | true)->collect(inp | (lambda inp : OclAny in (apply(solve, inp)))) ) else ( skip ; skip ; var pool : OclAny := Pool(NUM_PROCESSES, signal, Sequence{SIGINT, SIG_IGN}) ; runners := inputs->select(inp | true)->collect(inp | (pool.apply_async(solve, inp).get)) ; pool.closeFile() ) ; var caseFmt : String := '%' + ("" + (((("" + ((numCases))))->size()))) + 'd' ; var progressFmt : String := StringLib.format('[%s/%s]%%s ',Sequence{caseFmt, caseFmt}) ; try (var out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(FILE_NAME_BASE + '.out')); for _tuple : Integer.subrange(1, (runners, 1)->size())->collect( _indx | Sequence{_indx-1, (runners, 1)->at(_indx)} ) do (var _indx : int := 1; var case : OclAny := _tuple->at(_indx); _indx := _indx + 1; var runner : OclAny := _tuple->at(_indx); var result : OclAny := runner() ; out.write(StringLib.format('Case #%d: %s ',Sequence{case, result})) ; out.flush() ; (expr (atom (name sys)) (trailer . (name stderr)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name progressFmt))) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name case)))))) , (test (logical_test (comparison (expr (atom (name numCases)))))) , (test (logical_test (comparison (expr (atom (name result))))))) ))))))))) )))))) catch (_e : OclException) do skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import sys def main(): N,K=read_ints() T=[read_int()for _ in range(N)] print(solve(N,K,T)) def solve(N,K,T): diffs=[T[i+1]-T[i]for i in range(N-1)] diffs.sort() t=N for i in range(N-K): t+=diffs[i]-1 return t DEBUG='DEBUG' in os.environ def inp(): return sys.stdin.readline().rstrip() def read_int(): return int(inp()) def read_ints(): return[int(e)for e in inp().split()] def dprint(*value,sep=' ',end='\n'): if DEBUG : print(*value,sep=sep,end=end) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var DEBUG : boolean := (os.environ)->includes('DEBUG') ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := read_ints() ; var T : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (read_int())) ; execute (solve(N, K, T))->display(); operation solve(N : OclAny, K : OclAny, T : OclAny) : OclAny pre: true post: true activity: var diffs : Sequence := Integer.subrange(0, N - 1-1)->select(i | true)->collect(i | (T[i + 1+1] - T[i+1])) ; diffs := diffs->sort() ; var t : OclAny := N ; for i : Integer.subrange(0, N - K-1) do ( t := t + diffs[i+1] - 1) ; return t; operation inp() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation read_int() : OclAny pre: true post: true activity: return ("" + ((inp())))->toInteger(); operation read_ints() : OclAny pre: true post: true activity: return inp().split()->select(e | true)->collect(e | (("" + ((e)))->toInteger())); operation dprint(value : OclAny : Sequence(OclAny), sep : String, end : String) pre: true post: true activity: (args * (named_parameter (name value))) if sep->oclIsUndefined() then sep := ' ' else skip; if end->oclIsUndefined() then end := ' ' else skip; if DEBUG then ( execute ((argument * (test (logical_test (comparison (expr (atom (name value))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect N,K,*T=map(int,open(0).read().split()) S=[(T[i+1]-T[i])-1 for i in range(N-1)] S.sort(reverse=1) print((T[-1]-T[0]+1)-sum(S[: K-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var K : OclAny := null; var T : OclAny := null; Sequence{N,K,T} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var S : Sequence := Integer.subrange(0, N - 1-1)->select(i | true)->collect(i | ((T[i + 1+1] - T[i+1]) - 1)) ; S := S->sort() ; execute ((T->last() - T->first() + 1) - (S.subrange(1,K - 1))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) guest=[] interval=[] flag=0 for i in range(n): guest.append(int(input())) if flag==1 : interval.append(guest[-1]-guest[-2]-1) flag=1 interval.sort() ans=n if n>k : for i in range(n-k): ans+=interval[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var guest : Sequence := Sequence{} ; var interval : Sequence := Sequence{} ; var flag : int := 0 ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : guest) ; if flag = 1 then ( execute ((guest->last() - guest->front()->last() - 1) : interval) ) else skip ; flag := 1) ; interval := interval->sort() ; var ans : OclAny := n ; if (n->compareTo(k)) > 0 then ( for i : Integer.subrange(0, n - k-1) do ( ans := ans + interval[i+1]) ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) t=[int(input())for _ in range(n)] v=[0 for _ in range(n-1)] for i in range(n-1): v[i]=t[i+1]-t[i]-1 v.sort(reverse=True) print(t[-1]-t[0]+1-sum(v[:(k-1)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var v : Sequence := Integer.subrange(0, n - 1-1)->select(_anon | true)->collect(_anon | (0)) ; for i : Integer.subrange(0, n - 1-1) do ( v[i+1] := t[i + 1+1] - t[i+1] - 1) ; v := v->sort() ; execute (t->last() - t->first() + 1 - (v.subrange(1,(k - 1)))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def partitions(n): p=[0]*(n+1) p[0]=1 for i in range(1,n+1): k=1 while((k*(3*k-1))/2<=i): p[i]+=((1 if k % 2 else-1)*p[i-(k*(3*k-1))//2]) if(k>0): k*=-1 else : k=1-k return p[n] if __name__=="__main__" : N=20 print(partitions(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var N : int := 20 ; execute (partitions(N))->display() ) else skip; operation partitions(n : OclAny) : OclAny pre: true post: true activity: var p : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; p->first() := 1 ; for i : Integer.subrange(1, n + 1-1) do ( var k : int := 1 ; while (((k * (3 * k - 1)) / 2->compareTo(i)) <= 0) do ( p[i+1] := p[i+1] + ((if k mod 2 then 1 else -1 endif) * p[i - (k * (3 * k - 1)) div 2+1]) ; if (k > 0) then ( k := k * -1 ) else ( k := 1 - k ))) ; return p[n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def inversegrayCode(n): inv=0 ; while(n): inv=inv ^ n ; n=n>>1 ; return inv ; n=15 ; print(inversegrayCode(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 15; ; execute (inversegrayCode(n))->display();; operation inversegrayCode(n : OclAny) pre: true post: true activity: var inv : int := 0; ; while (n) do ( inv := MathLib.bitwiseXor(inv, n); ; n := n /(2->pow(1));) ; return inv;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countEvenOdd(num,n): even_count=0 ; odd_count=0 ; num=list(str(num)) for i in num : if i in('0','2','4','6','8'): even_count+=1 else : odd_count+=1 print("Even count : ",even_count); print("Odd count : ",odd_count); if(even_count % 2==0 and odd_count % 2!=0): return 1 ; else : return 0 ; num=(1,2,3); n=len(num); t=countEvenOdd(num,n); if t==1 : print("YES"); else : print("NO"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; num := Sequence{1, 2, 3}; ; n := (num)->size(); ; var t : OclAny := countEvenOdd(num, n); ; if t = 1 then ( execute ("YES")->display(); ) else ( execute ("NO")->display(); ); operation countEvenOdd(num : OclAny, n : OclAny) pre: true post: true activity: var even_count : int := 0; ; var odd_count : int := 0; ; num := (("" + ((num))))->characters() ; for i : num do ( if (Sequence{'0', '2', '4', '6', '8'})->includes(i) then ( even_count := even_count + 1 ) else ( odd_count := odd_count + 1 )) ; execute ("Even count : ")->display(); ; execute ("Odd count : ")->display(); ; if (even_count mod 2 = 0 & odd_count mod 2 /= 0) then ( return 1; ) else ( return 0; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def NotParallel(p,n): x_axis={}; y_axis={}; for i in range(n): if p[i][0]not in x_axis : x_axis[p[i][0]]=0 ; x_axis[p[i][0]]+=1 ; if p[i][1]not in y_axis : y_axis[p[i][1]]=0 ; y_axis[p[i][1]]+=1 ; total=(n*(n-1))//2 ; for i in x_axis : c=x_axis[i]; total-=(c*(c-1))//2 ; for i in y_axis : c=y_axis[i]; total-=(c*(c-1))//2 ; return total ; if __name__=="__main__" : p=[[1,2],[1,5],[1,15],[2,10]]; n=len(p); print(NotParallel(p,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( p := Sequence{Sequence{1}->union(Sequence{ 2 })}->union(Sequence{Sequence{1}->union(Sequence{ 5 })}->union(Sequence{Sequence{1}->union(Sequence{ 15 })}->union(Sequence{ Sequence{2}->union(Sequence{ 10 }) }))); ; n := (p)->size(); ; execute (NotParallel(p, n))->display(); ) else skip; operation NotParallel(p : OclAny, n : OclAny) pre: true post: true activity: var x_axis : OclAny := Set{}; var y_axis : OclAny := Set{}; ; for i : Integer.subrange(0, n-1) do ( if (x_axis)->excludes(p[i+1]->first()) then ( x_axis[p[i+1]->first()+1] := 0; ) else skip ; x_axis[p[i+1]->first()+1] := x_axis[p[i+1]->first()+1] + 1; ; if (y_axis)->excludes(p[i+1][1+1]) then ( y_axis[p[i+1][1+1]+1] := 0; ) else skip ; y_axis[p[i+1][1+1]+1] := y_axis[p[i+1][1+1]+1] + 1;) ; var total : int := (n * (n - 1)) div 2; ; for i : x_axis do ( var c : OclAny := x_axis[i+1]; ; total := total - (c * (c - 1)) div 2;) ; for i : y_axis do ( c := y_axis[i+1]; ; total := total - (c * (c - 1)) div 2;) ; return total;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()); x=1 l=list(map(int,input().split())) while xcollect( _x | (OclType["int"])->apply(_x) ); var x : int := 1 ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; while (x->compareTo(m)) < 0 do ( x := x + l[x - 1+1]) ; if x = m then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input('')) l=list(map(int,input().split())) s=sum(l) t=n*(n+1) r=int(t/2) print(r-s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : OclAny := (l)->sum() ; var t : int := n * (n + 1) ; var r : int := ("" + ((t / 2)))->toInteger() ; execute (r - s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() s=list(map(int,input().split())) s.sort() for i,x in enumerate(s): if i+1!=x : print(i+1) exit() print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; s := s->sort() ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); if i + 1 /= x then ( execute (i + 1)->display() ; exit() ) else skip) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculate(): r,c,w=[int(x)for x in input().split()] if c % w==0 : return r*int(c/w)+w-1 else : return r*int(c/w)+w def main(): ncase=int(input()) for i in range(ncase): print('Case #{}:{}'.format(i+1,calculate())) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation calculate() : OclAny pre: true post: true activity: var r : OclAny := null; var c : OclAny := null; var w : OclAny := null; Sequence{r,c,w} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if c mod w = 0 then ( return r * ("" + ((c / w)))->toInteger() + w - 1 ) else ( return r * ("" + ((c / w)))->toInteger() + w ); operation main() pre: true post: true activity: var ncase : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, ncase-1) do ( execute (StringLib.interpolateStrings('Case #{}:{}', Sequence{i + 1, calculate()}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split(" "))) summ=(n*(n+1))//2 summ1=sum(a) print(summ-summ1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var summ : int := (n * (n + 1)) div 2 ; var summ1 : OclAny := (a)->sum() ; execute (summ - summ1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) all_1_n=set(range(1,n+1)) his_1_n=set(map(int,input().split())) diff=list(all_1_n-his_1_n) print(diff[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var all var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()_n : Set := Set{}->union((Integer.subrange(1, n + 1-1))) ; var his var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()_n : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var diff : Sequence := (all var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()_n - his var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()_n) ; execute (diff->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(list(set(range(1,int(input())+1))-set(map(int,input().split())))[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (OclType["Sequence"](Set{}->union((Integer.subrange(1, ("" + (((OclFile["System.in"]).readLine())))->toInteger() + 1-1))) - Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pow(x,y): if(y==1): return x if(y==0): return 1 temp=pow(x,y//2) temp*=temp if(y & 1): temp*=x return temp def noOfPermutations(a,n): if(n==1): return 1 a.sort() if(a[n-1]==a[n-2]): return 0 x=0 for i in range(n-2): if(a[i]==a[i+1]): if(a[i]==a[i+2]): return 0 x+=1 i+=1 return pow(2,n-2*x-1) if __name__=="__main__" : a=[1,2,2,3,4] n=len(a) num=noOfPermutations(a,n) print(num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( a := Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })))) ; n := (a)->size() ; var num : OclAny := noOfPermutations(a, n) ; execute (num)->display() ) else skip; operation pow(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (y = 1) then ( return x ) else skip ; if (y = 0) then ( return 1 ) else skip ; var temp : double := (x)->pow(y div 2) ; temp := temp * temp ; if (MathLib.bitwiseAnd(y, 1)) then ( temp := temp * x ) else skip ; return temp; operation noOfPermutations(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return 1 ) else skip ; a := a->sort() ; if (a[n - 1+1] = a[n - 2+1]) then ( return 0 ) else skip ; x := 0 ; for i : Integer.subrange(0, n - 2-1) do ( if (a[i+1] = a[i + 1+1]) then ( if (a[i+1] = a[i + 2+1]) then ( return 0 ) else skip ; x := x + 1 ; i := i + 1 ) else skip) ; return (2)->pow(n - 2 * x - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printArr(arr,n): for i in range(0,n): print(arr[i],end="") def compare(num1,num2): A=str(num1) B=str(num2) return int(A+B)<=int(B+A) def sort(arr): for i in range(len(arr)): for j in range(i+1,len(arr)): if compare(arr[i],arr[j])==False : arr[i],arr[j]=arr[j],arr[i] def printSmallest(N,arr): sort(arr) printArr(arr,N) if __name__=="__main__" : arr=[5,6,2,9,21,1] N=len(arr) printSmallest(N,arr) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{5}->union(Sequence{6}->union(Sequence{2}->union(Sequence{9}->union(Sequence{21}->union(Sequence{ 1 }))))) ; N := (arr)->size() ; printSmallest(N, arr) ) else skip; operation printArr(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); operation compare(num1 : OclAny, num2 : OclAny) : OclAny pre: true post: true activity: var A : String := ("" + ((num1))) ; var B : String := ("" + ((num2))) ; return (("" + ((A + B)))->toInteger()->compareTo(("" + ((B + A)))->toInteger())) <= 0; operation sort(arr : OclAny) pre: true post: true activity: for i : Integer.subrange(0, (arr)->size()-1) do ( for j : Integer.subrange(i + 1, (arr)->size()-1) do ( if compare(arr[i+1], arr[j+1]) = false then ( var arr[i+1] : OclAny := null; var arr[j+1] : OclAny := null; Sequence{arr[i+1],arr[j+1]} := Sequence{arr[j+1],arr[i+1]} ) else skip)); operation printSmallest(N : OclAny, arr : OclAny) pre: true post: true activity: sort(arr) ; printArr(arr, N); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) i=1 while n>0 : print(i,end=" ") n-=1 print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 1 ; while n > 0 do ( execute (i)->display() ; n := n - 1) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : n=int(input()) print('1 '*n) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (StringLib.nCopies('1 ', n))->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n,t=map(int,input().split()) s=list([int(x)for x in input().split()]) current_cell=0 while current_cell<=t : current_cell+=s[current_cell-1] if current_cell==t : print("YES") sys.exit() else : continue print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := (input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) ; var current_cell : int := 0 ; while (current_cell->compareTo(t)) <= 0 do ( current_cell := current_cell + s[current_cell - 1+1] ; if current_cell = t then ( execute ("YES")->display() ; sys.exit() ) else ( continue )) ; execute ("NO")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): n=int(input()) t='4' s=t for i in range(n-1): s+=(' '+t) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : String := '4' ; var s : String := t ; for i : Integer.subrange(0, n - 1-1) do ( s := s + (' ' + t)) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) li=[2]*n print(' '.join(map(str,li))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li : Sequence := MatrixLib.elementwiseMult(Sequence{ 2 }, n) ; execute (StringLib.sumStringsWithSeparator(((li)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) print(" ".join(n*"1")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (StringLib.sumStringsWithSeparator((n * "1"), " "))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys iFile=open(sys.argv[1],"r") T=int(iFile.readline().strip()) for t in range(T): line=iFile.readline().strip().split() R=int(line[0]) C=int(line[1]) W=int(line[2]) shotsFailRows=0 shotsWinRow=0 remainingFields=C while remainingFields>=2*W : remainingFields-=W shotsFailRows+=1 shotsWinRow+=1 shotsWinRow+=min(remainingFields,W+1) shotsFailRows+=1 answer=(R-1)*shotsFailRows+shotsWinRow output=str(answer) print("Case #"+str(t+1)+": "+output) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var iFile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) ; var T : int := ("" + ((iFile.readLine()->trim())))->toInteger() ; for t : Integer.subrange(0, T-1) do ( var line : OclAny := iFile.readLine()->trim().split() ; var R : int := ("" + ((line->first())))->toInteger() ; var C : int := ("" + ((line[1+1])))->toInteger() ; var W : int := ("" + ((line[2+1])))->toInteger() ; var shotsFailRows : int := 0 ; var shotsWinRow : int := 0 ; var remainingFields : int := C ; while (remainingFields->compareTo(2 * W)) >= 0 do ( remainingFields := remainingFields - W ; shotsFailRows := shotsFailRows + 1 ; shotsWinRow := shotsWinRow + 1) ; shotsWinRow := shotsWinRow + Set{remainingFields, W + 1}->min() ; shotsFailRows := shotsFailRows + 1 ; var answer : double := (R - 1) * shotsFailRows + shotsWinRow ; var output : String := ("" + ((answer))) ; execute ("Case #" + ("" + ((t + 1))) + ": " + output)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W=map(int,input().split()) A=[input().split()for i in range(H)] X="#"*(W+2) for i in range(H): A[i][0]="#"+A[i][0]+"#" print(X) for i in range(H): print(A[i][0]) print(X) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := Integer.subrange(0, H-1)->select(i | true)->collect(i | (input().split())) ; var X : String := StringLib.nCopies("#", (W + 2)) ; for i : Integer.subrange(0, H-1) do ( A[i+1]->first() := "#" + A[i+1]->first() + "#") ; execute (X)->display() ; for i : Integer.subrange(0, H-1) do ( execute (A[i+1]->first())->display()) ; execute (X)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _,w,*s=open(0).read().split() t,k="#"*-~ int(w),"#\n#" print(t,*s,sep=k,end=k+t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _anon : OclAny := null; var w : OclAny := null; var s : OclAny := null; Sequence{_anon,w,s} := open(0).readAll().split() ; var t : OclAny := null; var k : OclAny := null; Sequence{t,k} := Sequence{StringLib.nCopies("#", -MathLib.bitwiseNot(("" + ((w)))->toInteger())),"#\n#"} ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def resolve(): H,W=map(int,input().split()) A=[str(input())for i in range(H)] for i in range(H+2): if i==0 or i==H+1 : print(''.join(['#']*(W+2))) else : print('#'+A[i-1]+'#') resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; resolve(); operation resolve() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := Integer.subrange(0, H-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine()))))) ; for i : Integer.subrange(0, H + 2-1) do ( if i = 0 or i = H + 1 then ( execute (StringLib.sumStringsWithSeparator((MatrixLib.elementwiseMult(Sequence{ '#' }, (W + 2))), ''))->display() ) else ( execute ('#' + A[i - 1+1] + '#')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W=map(int,input().split()) a=[] a.append(''.join(['#']*(W+2))) for i in range(H): s=input() a.append('#'+s+'#') a.append(''.join(['#']*(W+2))) for i in range(H+2): print(a[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{} ; execute ((StringLib.sumStringsWithSeparator((MatrixLib.elementwiseMult(Sequence{ '#' }, (W + 2))), '')) : a) ; for i : Integer.subrange(0, H-1) do ( var s : String := (OclFile["System.in"]).readLine() ; execute (('#' + s + '#') : a)) ; execute ((StringLib.sumStringsWithSeparator((MatrixLib.elementwiseMult(Sequence{ '#' }, (W + 2))), '')) : a) ; for i : Integer.subrange(0, H + 2-1) do ( execute (a[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w=map(int,input().split()) s=[list(input())for i in range(h)] s=[["#"]+i+["#"]for i in s] s=[["#" for i in range(w+2)]]+s+[["#" for i in range(w+2)]] for i in range(h+2): print("".join(s[i])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := Integer.subrange(0, h-1)->select(i | true)->collect(i | (((OclFile["System.in"]).readLine())->characters())) ; s := s->select(i | true)->collect(i | (Sequence{ "#" }->union(i)->union(Sequence{ "#" }))) ; s := Sequence{ Integer.subrange(0, w + 2-1)->select(i | true)->collect(i | ("#")) }->union(s)->union(Sequence{ Integer.subrange(0, w + 2-1)->select(i | true)->collect(i | ("#")) }) ; for i : Integer.subrange(0, h + 2-1) do ( execute (StringLib.sumStringsWithSeparator((s[i+1]), ""))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- SIZE=10 INT_MIN=-10000000 def maxSum(mat,n): if n==1 : return mat[0][0] dp=[[0 for i in range(n)]for i in range(n)] maxSum=INT_MIN for j in range(n): dp[n-1][j]=mat[n-1][j] for i in range(n-2,-1,-1): for j in range(n): maxi=INT_MIN if((((j-1)>=0)and(maxiapply(_x) ) ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var v : Sequence := Sequence{ 1 } ; while (v->last()->compareTo(n)) < 0 do ( execute ((v->last() + s[v->last() - 1+1]) : v)) ; execute (if (v)->includes(t) then 'YES' else 'NO' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (n,q),*t=[map(int,t.split())for t in open(0)] s=[0] d=s*n f=s*n e=[[]for _ in d] for a,b in t : if ~-n : n-=1 ; e[a-1]+=b-1,; e[b-1]+=a-1, else : d[a-1]+=b while s : v=s.pop(); f[v]=-1 for w in e[v]: if ~ f[w]: d[w]+=d[v]; s+=w, print(*d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{n, q} : OclAny := null; var t : OclAny := null; Sequence{Sequence{n, q},t} := OclFile.newOclFile_Write(OclFile.newOclFile(0))->select(t | true)->collect(t | ((t.split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var s : Sequence := Sequence{ 0 } ; var d : Sequence := MatrixLib.elementwiseMult(s, n) ; var f : Sequence := MatrixLib.elementwiseMult(s, n) ; var e : Sequence := d->select(_anon | true)->collect(_anon | (Sequence{})) ; for _tuple : t do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); if MathLib.bitwiseNot(-n) then ( n := n - 1; e[a - 1+1] := e[a - 1+1] + (testlist (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))) ,); e[b - 1+1] := e[b - 1+1] + (testlist (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))) ,) ) else ( d[a - 1+1] := d[a - 1+1] + b )) ; while s do ( var v : OclAny := s->last() ; s := s->front(); f[v+1] := -1 ; for w : e[v+1] do ( if MathLib.bitwiseNot(f[w+1]) then ( d[w+1] := d[w+1] + d[v+1]; s := s + (testlist (test (logical_test (comparison (expr (atom (name w)))))) ,) ) else skip)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name d))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np import sys import os atcoder = { 'name': 'numba_modules', 'file': 'numba_modules.cpython-34m.so', 'func': ['preface_px', 'preface_ind', 'dfs_stack'] } from numba_modules import preface_px, preface_ind, dfs_stack def main(): din = np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ') N = din[0] Q = din[1] ab = din[2: 2 * N].reshape(N - 1, 2).T - 1 ab = np.hstack((ab, ab[[1, 0], :])) px = din[2 * N: 2 * N + 2 * Q].reshape(Q, 2) arg = np.argsort(ab[0]) ab = ab[:, arg] ind = np.empty(N + 1, dtype=np.int32) preface_ind(ab[0], ind) plus = np.zeros(N, dtype=np.int32) preface_px(px, plus) ans = np.full(N, -1, dtype=np.int32) dfs_stack(ans, ind, ab[1], plus) print(*ans.tolist()) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var atcoder : Map := Map{ 'name' |-> 'numba_modules' }->union(Map{ 'file' |-> 'numba_modules.cpython-34m.so' }->union(Map{ 'func' |-> Sequence{'preface_px'}->union(Sequence{'preface_ind'}->union(Sequence{ 'dfs_stack' })) })) ; skip ; skip ; main(); operation main() pre: true post: true activity: var din : Sequence := ; var N : OclAny := din->first() ; var Q : OclAny := din[1+1] ; var ab : double := din.subrange(2+1, 2 * N).reshape(N - 1, 2).T - 1 ; ab := ; var px : OclAny := din.subrange(2 * N+1, 2 * N + 2 * Q).reshape(Q, 2) ; var arg : (trailer . (name argsort) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ab)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))) := ; ab := ab->collect( _r | _r[arg+1] ) ; var ind : Sequence := MatrixLib.singleValueMatrix(N + 1, 0.0) ; preface_ind(ab->first(), ind) ; var plus : Sequence := MatrixLib.singleValueMatrix(N, 0.0) ; preface_px(px, plus) ; var ans : Sequence := MatrixLib.singleValueMatrix(N, -1) ; dfs_stack(ans, ind, ab[1+1], plus) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans)) (trailer . (name tolist) (arguments ( )))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import factorial,ceil,floor from bisect import bisect_right as bsr from operator import itemgetter as ig from collections import defaultdict as dd from collections import deque args=None INF=float("inf") MOD=int(1e9+7) def int1(n): return int(n)-1 def input(): return next(args) def parse(*params): if len(params)==1 : return params[0](next(args)) return tuple(p(v)for p,v in zip(params,next(args).split())) def debug(*v): if __debug__ : print(*v,file=sys.stderr) def main(): N,Q=parse(int,int) edges=[[]for _ in range(N+1)] for _ in range(N-1): a,b=parse(int,int) edges[a]+=[b] edges[b]+=[a] vals=[0]*(N+1) for _ in range(Q): p,x=parse(int,int) vals[p]+=x counter=[0]*(N+1) que=deque() que.append((1,0)) alr=[False]*(N+1) while que : v,x=que.pop() alr[v]=True counter[v]+=x+vals[v] for n in edges[v]: if not alr[n]: que.append((n,counter[v])) print(*counter[1 :]) if __name__=='__main__' : args=iter(sys.stdin.read().split("\n")) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var args : OclAny := null ; var INF : double := ("" + (("inf")))->toReal() ; var MOD : int := ("" + ((("1e9")->toReal() + 7)))->toInteger() ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( args := OclIterator.newOclIterator_Sequence(sys.stdin.readAll().split("\n")) ; main() ) else skip; operation int1(n : OclAny) : OclAny pre: true post: true activity: return ("" + ((n)))->toInteger() - 1; operation input() : OclAny pre: true post: true activity: return (args).next(); operation parse(params : OclAny : Sequence(OclAny)) : OclAny pre: true post: true activity: (args * (named_parameter (name params))) if (params)->size() = 1 then ( return params->first()((args).next()) ) else skip ; return ((argument (test (logical_test (comparison (expr (atom (name p)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) ))))))) (comp_for for (exprlist (expr (atom (name p))) , (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name params))))))) , (argument (test (logical_test (comparison (expr (atom (name next)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name args)))))))) ))) (trailer . (name split) (arguments ( ))))))))) ))))))))); operation debug(v : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name v))) if __debug__ then ( execute ((argument * (test (logical_test (comparison (expr (atom (name v))))))))->display() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var Q : OclAny := null; Sequence{N,Q} := parse(OclType["int"], OclType["int"]) ; var edges : Sequence := Integer.subrange(0, N + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, N - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := parse(OclType["int"], OclType["int"]) ; edges[a+1] := edges[a+1] + Sequence{ b } ; edges[b+1] := edges[b+1] + Sequence{ a }) ; var vals : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; for _anon : Integer.subrange(0, Q-1) do ( var p : OclAny := null; var x : OclAny := null; Sequence{p,x} := parse(OclType["int"], OclType["int"]) ; vals[p+1] := vals[p+1] + x) ; var counter : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; var que : Sequence := () ; execute ((Sequence{1, 0}) : que) ; var alr : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (N + 1)) ; while que do ( var v : OclAny := null; var x : OclAny := null; Sequence{v,x} := que->last() ; que := que->front() ; alr->restrict(v) := true ; counter->restrict(v) := counter->restrict(v) + x + vals->restrict(v) ; for n : edges->restrict(v) do ( if not(alr[n+1]) then ( execute ((Sequence{n, counter->restrict(v)}) : que) ) else skip)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name counter)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,q=map(int,input().split()) l=[list(map(int,input().split()))for i in range(n-1)] connection=[[]for i in range(n)] for i in range(n-1): connection[l[i][0]-1].append(l[i][1]-1) connection[l[i][1]-1].append(l[i][0]-1) L=[list(map(int,input().split()))for i in range(q)] ctL=[0]*n for i in range(q): ctL[L[i][0]-1]+=L[i][1] def bfs(v): distance=[-1]*n distance[v]=ctL[v] next=[v] next2=set() visited=[-1]*n visitct=0 while len(next)!=0 and visitct!=n : for i in range(len(next)): if visited[next[i]]==-1 : visited[next[i]]=1 visitct+=1 for j in range(len(connection[next[i]])): if visited[connection[next[i]][j]]==-1 : distance[connection[next[i]][j]]=distance[next[i]]+ctL[connection[next[i]][j]] next2.add(connection[next[i]][j]) next=list(next2) next2=set() return distance x=bfs(0) for i in range(n): x[i]=str(x[i]) print(' '.join(x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := Integer.subrange(0, n - 1-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var connection : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, n - 1-1) do ((expr (atom (name connection)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name connection)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))) - (expr (atom (number (integer 1)))))))))) ))))) ; var L : Sequence := Integer.subrange(0, q-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ctL : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, q-1) do ( ctL[L[i+1]->first() - 1+1] := ctL[L[i+1]->first() - 1+1] + L[i+1][1+1]) ; skip ; var x : OclAny := bfs(0) ; for i : Integer.subrange(0, n-1) do ( x[i+1] := ("" + ((x[i+1])))) ; execute (StringLib.sumStringsWithSeparator((x), ' '))->display(); operation bfs(v : OclAny) : OclAny pre: true post: true activity: var distance : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; distance[v+1] := ctL[v+1] ; var next : Sequence := Sequence{ v } ; var next2 : Set := Set{}->union(()) ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; var visitct : int := 0 ; while (next)->size() /= 0 & visitct /= n do ( for i : Integer.subrange(0, (next)->size()-1) do ( if visited[[i+1].next()+1] = -1 then ( visited[[i+1].next()+1] := 1 ; visitct := visitct + 1 ; for j : Integer.subrange(0, (connection[[i+1].next()+1])->size()-1) do ( if visited[connection[[i+1].next()+1][j+1]+1] = -1 then ( distance[connection[[i+1].next()+1][j+1]+1] := distance[[i+1].next()+1] + ctL[connection[[i+1].next()+1][j+1]+1] ; execute ((connection[[i+1].next()+1][j+1]) : next2) ) else skip) ) else skip) ; next := (next2) ; next2 := Set{}->union(())) ; return distance; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) sequence=[int(x)for x in input().split()] count=0 list_new=[] for i in range(len(sequence)-1,-1,-1): if not sequence[i]in list_new : list_new.append(sequence[i]) count+=1 print(count) for i in list(reversed(list_new)): print(i,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sequence : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var count : int := 0 ; var list_new : Sequence := Sequence{} ; for i : Integer.subrange(-1 + 1, (sequence)->size() - 1)->reverse() do ( if not((list_new)->includes(sequence[i+1])) then ( execute ((sequence[i+1]) : list_new) ; count := count + 1 ) else skip) ; execute (count)->display() ; for i : ((list_new)->reverse()) do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import itertools import numpy as NP def read_case(f): return read_ints(f) def solve_small(case): R,C,W=case return(C//W)*R+W-(1 if C % W==0 else 0) def solve_large(case): return solve_small(case) def write_case(f,i,res): f.write('Case #%d: ' % i) f.write('%s' % res) f.write('\n') def read_word(f): return next(f).strip() def read_int(f,b=10): return int(read_word(f),b) def read_letters(f): return list(read_word(f)) def read_digits(f,b=10): return[int(x,b)for x in read_letters(f)] def read_words(f,d=' '): return read_word(f).split(d) def read_ints(f,b=10,d=' '): return[int(x,b)for x in read_words(f,d)] def read_floats(f,d=' '): return[float(x)for x in read_words(f,d)] def read_arr(f,R,reader=read_ints,*args,**kwargs): return[reader(f,*args,**kwargs)for i in range(R)] def solve(solver,fn,out_fn=None): in_fn=fn+'.in' if out_fn is None : out_fn=fn+'.out' with open(in_fn,'r')as fi : with open(out_fn,'w')as fo : T=read_int(fi) for i in range(T): case=read_case(fi) res=solver(case) write_case(fo,i,res) DEBUG='i' from run import* ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var DEBUG : String := 'i' ; skip; operation read_case(f : OclAny) : OclAny pre: true post: true activity: return read_ints(f); operation solve_small(case : OclAny) : OclAny pre: true post: true activity: var R : OclAny := null; var C : OclAny := null; var W : OclAny := null; Sequence{R,C,W} := case ; return (C div W) * R + W - (if C mod W = 0 then 1 else 0 endif); operation solve_large(case : OclAny) : OclAny pre: true post: true activity: return solve_small(case); operation write_case(f : OclAny, i : OclAny, res : OclAny) pre: true post: true activity: f.write(StringLib.format('Case #%d: ',i)) ; f.write(StringLib.format('%s',res)) ; f.write(' '); operation read_word(f : OclAny) : OclAny pre: true post: true activity: return next(f)->trim(); operation read_int(f : OclAny, b : int) : OclAny pre: true post: true activity: if b->oclIsUndefined() then b := 10 else skip; return ("" + ((read_word(f), b)))->toInteger(); operation read_letters(f : OclAny) : OclAny pre: true post: true activity: return (read_word(f)); operation read_digits(f : OclAny, b : int) : OclAny pre: true post: true activity: if b->oclIsUndefined() then b := 10 else skip; return read_letters(f)->select(x | true)->collect(x | (("" + ((x, b)))->toInteger())); operation read_words(f : OclAny, d : String) : OclAny pre: true post: true activity: if d->oclIsUndefined() then d := ' ' else skip; return read_word(f).split(d); operation read_ints(f : OclAny, b : int, d : String) : OclAny pre: true post: true activity: if b->oclIsUndefined() then b := 10 else skip; if d->oclIsUndefined() then d := ' ' else skip; return read_words(f, d)->select(x | true)->collect(x | (("" + ((x, b)))->toInteger())); operation read_floats(f : OclAny, d : String) : OclAny pre: true post: true activity: if d->oclIsUndefined() then d := ' ' else skip; return read_words(f, d)->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation read_arr(f : OclAny, R : OclAny, reader : OclAny, args : OclAny : Sequence(OclAny), kwargs : OclAny : Map(String, OclAny)) : OclAny pre: true post: true activity: if reader->oclIsUndefined() then reader := read_ints else skip; (args * (named_parameter (name args)))(kwargs ** (named_parameter (name kwargs))) return Integer.subrange(0, R-1)->select(i | true)->collect(i | (reader(f, (argument * (test (logical_test (comparison (expr (atom (name args))))))), (argument ** (test (logical_test (comparison (expr (atom (name kwargs)))))))))); operation solve(solver : OclAny, fn : OclAny, out_fn : OclAny) pre: true post: true activity: if out_fn->oclIsUndefined() then out_fn := null else skip; var in_fn : OclAny := fn + '.in' ; if out_fn <>= null then ( out_fn := fn + '.out' ) else skip ; try (var fi : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(in_fn)); try (var fo : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(out_fn)); var T : OclAny := read_int(fi) ; for i : Integer.subrange(0, T-1) do ( case := read_case(fi) ; res := solver(case) ; write_case(fo, i, res))) catch (_e : OclException) do skip) catch (_e : OclException) do skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import string import fractions import random from operator import itemgetter import itertools from collections import deque import copy import heapq import bisect sys.setrecursionlimit(10**6) MOD=10**9+7 INF=float('inf') input=lambda : sys.stdin.readline().strip() N,Q=map(int,input().split()) info=[[]for _ in range(N)] ans=[0 for _ in range(N)] check=[1 for _ in range(N)] for _ in range(N-1): a,b=map(int,input().split()) info[a-1].append(b-1) info[b-1].append(a-1) def plus(n,val): ans[n]+=val check[n]=0 for i in info[n]: if check[i]: plus(i,val+Query[i]) Query=[0 for _ in range(N)] for _ in range(Q): p,x=map(int,input().split()) Query[p-1]+=x plus(0,Query[0]) ans=list(map(str,ans)) print(" ".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(6)) ; var MOD : double := (10)->pow(9) + 7 ; var INF : double := ("" + (('inf')))->toReal() ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine()->trim()) ; var N : OclAny := null; var Q : OclAny := null; Sequence{N,Q} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var info : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var ans : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (0)) ; var check : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (1)) ; for _anon : Integer.subrange(0, N - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name info)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) )))) ; (expr (atom (name info)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name b))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (number (integer 1)))))))))) ))))) ; skip ; var Query : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (0)) ; for _anon : Integer.subrange(0, Q-1) do ( var p : OclAny := null; var x : OclAny := null; Sequence{p,x} := (input->apply().split())->collect( _x | (OclType["int"])->apply(_x) ) ; Query[p - 1+1] := Query[p - 1+1] + x) ; plus(0, Query->first()) ; ans := ((ans)->collect( _x | (OclType["String"])->apply(_x) )) ; execute (StringLib.sumStringsWithSeparator((ans), " "))->display(); operation plus(n : OclAny, val : OclAny) pre: true post: true activity: ans[n+1] := ans[n+1] + val ; check[n+1] := 0 ; for i : info[n+1] do ( if check[i+1] then ( plus(i, val + Query[i+1]) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys MOD=1000000007 def get_factors(n): fact=2 tmp=n ret=[] while fact*fact<=n : count=0 while tmp % fact==0 : tmp//=fact count+=1 if count>0 : ret.append(count) fact+=1 if tmp>1 : ret.append(1) return ret def comb(n,k): if k>n : return 0 ret=1 k=min(k,n-k) for i in range(k): ret*=n-i ret//=i+1 return ret def solve(N : int,M : int): facts=get_factors(M) ret=1 for c in facts : ret*=comb(c+N-1,N-1) print(ret % MOD) return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() N=int(next(tokens)) M=int(next(tokens)) solve(N,M) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MOD : int := 1000000007 ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation get_factors(n : OclAny) : OclAny pre: true post: true activity: var fact : int := 2 ; var tmp : OclAny := n ; var ret : Sequence := Sequence{} ; while (fact * fact->compareTo(n)) <= 0 do ( var count : int := 0 ; while tmp mod fact = 0 do ( tmp := tmp div fact ; count := count + 1) ; if count > 0 then ( execute ((count) : ret) ) else skip ; fact := fact + 1) ; if tmp > 1 then ( execute ((1) : ret) ) else skip ; return ret; operation comb(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (k->compareTo(n)) > 0 then ( return 0 ) else skip ; ret := 1 ; k := Set{k, n - k}->min() ; for i : Integer.subrange(0, k-1) do ( ret := ret * n - i ; ret := ret div i + 1) ; return ret; operation solve(N : int, M : int) pre: true post: true activity: var facts : OclAny := get_factors(M) ; ret := 1 ; for c : facts do ( ret := ret * comb(c + N - 1, N - 1)) ; execute (ret mod MOD)->display() ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var N : int := ("" + (((tokens).next())))->toInteger() ; var M : int := ("" + (((tokens).next())))->toInteger() ; solve(N, M); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=10**9+7 N,M=map(int,input().split()) def factoring(k): import math dic=dict() n=int(math.sqrt(k))+2 for i in range(2,n): count=0 while k % i==0 : count+=1 k=k//i if count!=0 : dic[i]=count if k!=1 : dic[k]=1 return dic class Factorial : def __init__(self,n,mod): self.f=[1] self.mod=mod for j in range(1,n+1): self.f.append(self.f[-1]*j % mod) self.i=[pow(self.f[-1],mod-2,mod)] for j in range(n,0,-1): self.i.append(self.i[-1]*j % mod) self.i.reverse() def factorial(self,j): return self.f[j] def ifactorial(self,j): return self.i[j] def comb(self,n,k): return self.f[n]*self.i[n-k]% self.mod*self.i[k]% self.mod if n>=k else 0 C=Factorial(N+100,MOD).comb ans=1 dic=factoring(M) for tmp in dic : ans*=C(dic[tmp]+N-1,dic[tmp]) ans %=MOD print(ans) ------------------------------------------------------------ OCL File: --------- class Factorial { static operation newFactorial() : Factorial pre: true post: Factorial->exists( _x | result = _x ); attribute f : Sequence := Sequence{ 1 }; attribute mod : OclAny := mod; attribute i : Sequence := Sequence{ (self.f->last())->pow(mod - 2) }; operation initialise(n : OclAny,mod : OclAny) : Factorial pre: true post: true activity: self.f := Sequence{ 1 } ; self.mod := mod ; for j : Integer.subrange(1, n + 1-1) do ((expr (atom (name self)) (trailer . (name f)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name self)) (trailer . (name f) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))) * (expr (atom (name j)))) % (expr (atom (name mod))))))))) ))))) ; self.i := Sequence{ (self.f->last())->pow(mod - 2) } ; for j : Integer.subrange(0 + 1, n)->reverse() do ((expr (atom (name self)) (trailer . (name i)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name self)) (trailer . (name i) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))) * (expr (atom (name j)))) % (expr (atom (name mod))))))))) ))))) ; (expr (atom (name self)) (trailer . (name i)) (trailer . (name reverse) (arguments ( )))); return self; operation factorial(j : OclAny) : OclAny pre: true post: true activity: return self.f[j+1]; operation ifactorial(j : OclAny) : OclAny pre: true post: true activity: return self.i[j+1]; operation comb(n : OclAny,k : OclAny) : OclAny pre: true post: true activity: return if (n->compareTo(k)) >= 0 then self.f[n+1] * self.i[n - k+1] mod self.mod * self.i[k+1] mod self.mod else 0 endif; } class FromPython { operation initialise() pre: true post: true activity: var MOD : double := (10)->pow(9) + 7 ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; skip ; var C : OclAny := Factorial(N + 100, MOD).comb ; var ans : int := 1 ; dic := factoring(M) ; for tmp : dic->keys() do ( ans := ans * C(dic[tmp+1] + N - 1, dic[tmp+1]) ; ans := ans mod MOD) ; execute (ans)->display(); operation factoring(k : OclAny) : OclAny pre: true post: true activity: skip ; var dic : Map := (arguments ( )) ; var n : int := ("" + (((k)->sqrt())))->toInteger() + 2 ; for i : Integer.subrange(2, n-1) do ( var count : int := 0 ; while k mod i = 0 do ( count := count + 1 ; k := k div i) ; if count /= 0 then ( dic[i+1] := count ) else skip) ; if k /= 1 then ( dic[k+1] := 1 ) else skip ; return dic; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import collections def alg_duplicate_combination_mod(n,r,mod): n=n+r-1 r=min(n-r,r) if r==0 : return 1 else : denominator=1 for i in range(n,n-r,-1): denominator=(denominator*i)% mod molecule=1 for i in range(1,r+1): molecule=(molecule*i)% mod return denominator*pow(molecule,mod-2,mod)% mod def solve(): input=sys.stdin.readline mod=10**9+7 n,m=list(map(int,input().rstrip('\n').split())) t=m d=collections.defaultdict(int) for i in range(2,int(t**0.5)+1): while True : if t % i==0 : d[i]+=1 t//=i else : break if t!=1 : d[t]+=1 cnt=1 for k,v in d.items(): cnt*=alg_duplicate_combination_mod(n,v,mod) cnt %=mod print(cnt) if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation alg_duplicate_combination_mod(n : OclAny, r : OclAny, mod : OclAny) : OclAny pre: true post: true activity: n := n + r - 1 ; r := Set{n - r, r}->min() ; if r = 0 then ( return 1 ) else ( var denominator : int := 1 ; for i : Integer.subrange(n - r + 1, n)->reverse() do ( denominator := (denominator * i) mod mod) ; var molecule : int := 1 ; for i : Integer.subrange(1, r + 1-1) do ( molecule := (molecule * i) mod mod) ; return denominator * (molecule)->pow(mod - 2) mod mod ); operation solve() pre: true post: true activity: var input : OclAny := (OclFile["System.in"]).readline ; mod := (10)->pow(9) + 7 ; var m : OclAny := null; Sequence{n,m} := ((input().rstrip(' ').split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : OclAny := m ; var d : OclAny := .defaultdict(OclType["int"]) ; for i : Integer.subrange(2, ("" + (((t)->pow(0.5))))->toInteger() + 1-1) do ( while true do ( if t mod i = 0 then ( d[i+1] := d[i+1] + 1 ; t := t div i ) else ( break ))) ; if t /= 1 then ( d[t+1] := d[t+1] + 1 ) else skip ; var cnt : int := 1 ; for _tuple : d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); cnt := cnt * alg_duplicate_combination_mod(n, v, mod) ; cnt := cnt mod mod) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) *A,=map(int,input().split()) l=[0]*n for i in range(n): if l[i]==0 : s=set() p=i can=1 while p not in s : if l[p]==1 : can=0 break s.add(p) l[p]=1 p=(p+A[p])% n if can : while l[p]==1 : l[p]=2 p=(p+A[p])% n print(sum(e==2 for e in l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (testlist_star_expr (star_expr * (expr (atom (name A)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name A)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( if l[i+1] = 0 then ( var s : Set := Set{}->union(()) ; var p : OclAny := i ; var can : int := 1 ; while (s)->excludes(p) do ( if l[p+1] = 1 then ( can := 0 ; break ) else skip ; execute ((p) : s) ; l[p+1] := 1 ; p := (p + A[p+1]) mod n) ; if can then ( while l[p+1] = 1 do ( l[p+1] := 2 ; p := (p + A[p+1]) mod n) ) else skip ) else skip) ; execute (((argument (test (logical_test (comparison (comparison (expr (atom (name e)))) == (comparison (expr (atom (number (integer 2)))))))) (comp_for for (exprlist (expr (atom (name e)))) in (logical_test (comparison (expr (atom (name l))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Factorials : def __init__(self,n=10**6,mod=10**9+7): self.mod=mod self.fac=[1] num=1 for i in range(1,n+1): num*=i num %=mod self.fac.append(num) num=pow(num,mod-2,mod) self.rec=[1 for i in range(n+1)] self.rec[n]=num for i in range(n-1,0,-1): num*=i+1 num %=mod self.rec[i]=num def comb(self,n,r): return self.fac[n]*self.rec[r]*self.rec[n-r]% self.mod def perm(self,n,r): return self.fac[n]*self.rec[n-r]% self.mod def fact(self,n): return self.fac[n] def main(): mod=10**9+7 n,m=map(int,input().split()) if m==1 : print(1) exit() factors=[] for i in range(2,m+1): if i*i>m : if m>1 : factors.append(1) break if m % i==0 : num=1 m//=i while m % i==0 : num+=1 m//=i factors.append(num) fct=Factorials(n=n+max(factors),mod=mod) ans=1 for i in factors : ans*=fct.comb(n+i-1,i) ans %=mod print(ans) main() ------------------------------------------------------------ OCL File: --------- class Factorials { static operation newFactorials() : Factorials pre: true post: Factorials->exists( _x | result = _x ); attribute mod : OclAny := mod; attribute fac : Sequence := Sequence{ 1 }; attribute rec : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (1)); attribute (trailer . (name rec) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n)))))))) ])) : int := num; operation initialise(n : OclAny,mod : OclAny) : Factorials pre: true post: true activity: self.mod := mod ; self.fac := Sequence{ 1 } ; var num : int := 1 ; for i : Integer.subrange(1, n + 1-1) do ( num := num * i ; num := num mod mod ; (expr (atom (name self)) (trailer . (name fac)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) ))))) ; num := (num)->pow(mod - 2) ; self.rec := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (1)) ; self.rec[n+1] := num ; for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( num := num * i + 1 ; num := num mod mod ; self.rec[i+1] := num); return self; operation comb(n : OclAny,r : OclAny) : OclAny pre: true post: true activity: return self.fac[n+1] * self.rec[r+1] * self.rec[n - r+1] mod self.mod; operation perm(n : OclAny,r : OclAny) : OclAny pre: true post: true activity: return self.fac[n+1] * self.rec[n - r+1] mod self.mod; operation fact(n : OclAny) : OclAny pre: true post: true activity: return self.fac[n+1]; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: mod := (10)->pow(9) + 7 ; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if m = 1 then ( execute (1)->display() ; exit() ) else skip ; var factors : Sequence := Sequence{} ; for i : Integer.subrange(2, m + 1-1) do ( if (i * i->compareTo(m)) > 0 then ( if m > 1 then ( execute ((1) : factors) ) else skip ; break ) else skip ; if m mod i = 0 then ( num := 1 ; m := m div i ; while m mod i = 0 do ( num := num + 1 ; m := m div i) ; execute ((num) : factors) ) else skip) ; var fct : Factorials := (Factorials.newFactorials()).initialise((argument (test (logical_test (comparison (expr (atom (name n)))))) = (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name factors)))))))) ))))))))), (argument (test (logical_test (comparison (expr (atom (name mod)))))) = (test (logical_test (comparison (expr (atom (name mod)))))))) ; var ans : int := 1 ; for i : factors do ( ans := ans * fct.comb(n + i - 1, i) ; ans := ans mod mod) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- 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,m=map(int,input().split()) chk=factorization(m) def make_array_for_comb(N,mod=10**9+7): fact=[1,1] fact_inv=[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) fact_inv.append((fact_inv[-1]*inv[i])% mod) return fact,fact_inv def comb(n,r,mod=10**9+7): if(r<0)or(ncollect( _x | (OclType["int"])->apply(_x) ) ; var chk : OclAny := factorization(m) ; skip ; skip ; mod := (10)->pow(9) + 7 ; var ans : int := 1 ; for i : chk do ( Sequence{fact,fact_inv} := make_array_for_comb(i[1+1] + n - 1, mod) ; ans := ans * comb(i[1+1] + n - 1, i[1+1], mod) ; ans := ans mod mod) ; if m = 1 then ( ans := 1 ) else skip ; execute (ans)->display(); operation factorization(n : OclAny) : OclAny pre: true post: true activity: var arr : Sequence := Sequence{} ; var temp : OclAny := n ; for i : Integer.subrange(2, ("" + ((-(-(n)->pow(0.5) div 1))))->toInteger() + 1-1) do ( if temp mod i = 0 then ( var cnt : int := 0 ; while temp mod i = 0 do ( cnt := cnt + 1 ; temp := temp div i) ; execute ((Sequence{i}->union(Sequence{ cnt })) : arr) ) else skip) ; if temp /= 1 then ( execute ((Sequence{temp}->union(Sequence{ 1 })) : arr) ) else skip ; if arr = Sequence{} then ( execute ((Sequence{n}->union(Sequence{ 1 })) : arr) ) else skip ; return arr; operation make_array_for_comb(N : OclAny, mod : OclAny) : OclAny pre: true post: true activity: if mod->oclIsUndefined() then mod := (10)->pow(9) + 7 else skip; var fact : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var fact_inv : Sequence := Sequence{1}->union(Sequence{ 1 }) ; var inv : Sequence := Sequence{0}->union(Sequence{ 1 }) ; for i : Integer.subrange(2, N + 1-1) do ( execute (((fact->last() * i) mod mod) : fact) ; execute (((-inv[mod mod i+1] * (mod div i)) mod mod) : inv) ; execute (((fact_inv->last() * inv[i+1]) mod mod) : fact_inv)) ; return fact, fact_inv; operation comb(n : OclAny, r : OclAny, mod : OclAny) : OclAny pre: true post: true activity: if mod->oclIsUndefined() then mod := (10)->pow(9) + 7 else skip; if (r < 0) or ((n->compareTo(r)) < 0) then ( return 0 ) else skip ; r := Set{r, n - r}->min() ; return fact[n+1] * fact_inv[r+1] * fact_inv[n - r+1] mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) ans=[0]*n ans[0]=sum(a[: : 2])-sum(a[1 : : 2]) for i in range(1,n): ans[i]=2*a[i-1]-ans[i-1] ans=list(map(str,ans)) print(" ".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; ans->first() := (a(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->sum() - (a(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->sum() ; for i : Integer.subrange(1, n-1) do ( ans[i+1] := 2 * a[i - 1+1] - ans[i - 1+1]) ; ans := ((ans)->collect( _x | (OclType["String"])->apply(_x) )) ; execute (StringLib.sumStringsWithSeparator((ans), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main2(): n=int(input()) water_list=list(map(int,input().split())) mw=water_list[-1] for i in range(mw+1): cv=mw-i init_cv=cv for w in water_list[: :-1]: cv=w-cv if cv<0 : break else : if init_cv==cv : ret=[0 for _ in range(n)] cv=init_cv for ii,ww in enumerate(water_list): ret[ii]=cv*2 cv=ww-cv return ret return 'hoge' def main(): n=int(input()) water_list=list(map(int,input().split())) a=sum(water_list)-2*sum(water_list[1 : : 2]) ret=[a] next=a for v in water_list[:-1]: next=(v*2-next) ret.append(next) print(*ret) if __name__=="__main__" : if sys.platform=='ios' : sys.stdin=open('inputFile.txt') ret=main() if ret is not None : print(' '.join([str(i)for i in ret])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( if OclProcess.getEnvironmentProperty("OS") = 'ios' then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('inputFile.txt')) ) else skip ; ret := main() ; if not(ret <>= null) then ( execute (StringLib.sumStringsWithSeparator((ret->select(i | true)->collect(i | (("" + ((i)))))), ' '))->display() ) else skip ) else skip; operation main2() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var water_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mw : OclAny := water_list->last() ; for i : Integer.subrange(0, mw + 1-1) do ( var cv : double := mw - i ; var init_cv : OclAny := cv ; (compound_stmt for (exprlist (expr (atom (name w)))) in (testlist (test (logical_test (comparison (expr (atom (name water_list)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cv)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name w))) - (expr (atom (name cv))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name cv)))) < (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name init_cv)))) == (comparison (expr (atom (name cv))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ret)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) ]))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cv)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name init_cv)))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name ii))) , (expr (atom (name ww)))) in (testlist (test (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name water_list)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ret)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ii)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name cv))) * (expr (atom (number (integer 2)))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cv)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name ww))) - (expr (atom (name cv)))))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name ret))))))))))))))))) ; return 'hoge'; operation main() pre: true post: true activity: n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; water_list := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : double := (water_list)->sum() - 2 * (water_list(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->sum() ; ret := Sequence{ a } ; var next : OclAny := a ; for v : water_list->front() do ( next := (v * 2 - next) ; execute ((next) : ret)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ret))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np N=int(input()) p=np.array(list(map(int,input().split()))) a0=0 for i in range(0,N,2): a0+=p[i] for i in range(1,N-1,2): a0-=p[i] ans2=[a0]*N for i,one in enumerate(p[1 :]): ans2[i+1]=2*p[i]-ans2[i] ans_s="" for one in ans2 : ans_s+="{}".format(one) ans_s=ans_s[:-1] print(ans_s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var a0 : int := 0 ; for i : Integer.subrange(0, N-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( a0 := a0 + p[i+1]) ; for i : Integer.subrange(1, N - 1-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( a0 := a0 - p[i+1]) ; var ans2 : Sequence := MatrixLib.elementwiseMult(Sequence{ a0 }, N) ; for _tuple : Integer.subrange(1, (p->tail())->size())->collect( _indx | Sequence{_indx-1, (p->tail())->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var one : OclAny := _tuple->at(_indx); ans2[i + 1+1] := 2 * p[i+1] - ans2[i+1]) ; var ans_s : String := "" ; for one : ans2 do ( ans_s := ans_s + StringLib.interpolateStrings("{}", Sequence{one})) ; ans_s := ans_s->front() ; execute (ans_s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) a=list(map(int,input().split())) suma=sum(a) x=[0]*n tmp=0 for i in range(1,n,2): tmp+=a[i] x[0]=suma-2*tmp for i in range(1,n): x[i]=2*a[i-1]-x[i-1] for i in x : print(i,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var suma : OclAny := (a)->sum() ; var x : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var tmp : int := 0 ; for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( tmp := tmp + a[i+1]) ; x->first() := suma - 2 * tmp ; for i : Integer.subrange(1, n-1) do ( x[i+1] := 2 * a[i - 1+1] - x[i - 1+1]) ; for i : x do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(test): r,c,w=map(int,input().split()) ans=(c/w+w-1)if c % w==0 else(c/w+w) ans+=(r-1)*c/w print("Case #%d: %d" %(test,ans)) t=int(input()) for i in range(t): solve(i+1); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( solve(i + 1);); operation solve(test : OclAny) pre: true post: true activity: var r : OclAny := null; var c : OclAny := null; var w : OclAny := null; Sequence{r,c,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : double := if c mod w = 0 then (c / w + w - 1) else (c / w + w) endif ; ans := ans + (r - 1) * c / w ; execute (StringLib.format("Case #%d: %d",Sequence{test, ans}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) bs=[int(x)for x in input().split()] sign=1 a_2=bs[0] for b in bs[1 :]: a_2+=sign*b sign*=-1 ans=str(a_2)+' ' for i in range(n-2): a_2=2*bs[i+1]-a_2 ans+=str(a_2)+' ' ans=str(2*bs[i+2]-a_2)+' '+ans print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var bs : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var sign : int := 1 ; var a:= bs->first() : OclAny := bs->first() ; for b : bs->tail() do ( a + sign * b := a + sign * b + sign * b ; sign := sign * -1) ; var ans : String := ("" + ((a' '))) + ' ' ; for i : Integer.subrange(0, n - 2-1) do ( a:= 2 * bs[i + 1+1] - a_2 := 2 * bs[i + 1+1] - a_2 ; ans := ans + ("" + ((a' '))) + ' ') ; ans := ("" + ((2 * bs[i + 2+1] - a' '))) + ' ' + ans ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re import sys r=re.compile(r'(\([a-z]*\)|[a-z])') def main(): [l,d,n]=[int(x)for x in raw_input().strip().split()] words=[] for _ in range(d): words.append(raw_input().strip()) for i in range(n): q=raw_input().strip() q=[c for c in r.split(q)if c] w=words for qq in q : w=[x[1 :]for x in w if x[0]in qq] sys.stdout.write("Case #%d: %d\n" %(i+1,len(w))) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var r : OclRegex := OclRegex.compile(StringLib.rawString('(\([a-z]*\)|[a-z])')) ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: ; Sequence{l}->union(Sequence{d}->union(Sequence{ n })) := raw_input()->trim().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var words : Sequence := Sequence{} ; for _anon : Integer.subrange(0, d-1) do ( execute ((raw_input()->trim()) : words)) ; for i : Integer.subrange(0, n-1) do ( var q : OclAny := raw_input()->trim() ; q := r.split(q)->select(c | c)->collect(c | (c)) ; var w : Sequence := words ; for qq : q do ( w := w->select(x | (qq)->includes(x->first()))->collect(x | (x->tail()))) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom "Case #%d: %d\n")) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name w)))))))) )))))))) ))))))))) ))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- filepath='' fileprefix='A-large' filepathname=filepath+fileprefix infilename=filepathname+'.in' outfilename=filepathname+'.out' lines=open(infilename,'rU').read().split("\n") outfile=open(outfilename,'w+') linenum=1 vars=lines[0].split(' ') cases=int(vars[2]) l=int(vars[0]) d=int(vars[1]) words=lines[1 : d+1] linenum=d+1 def explode(word): r=[] curset=[] inset=False for c in word : if c=='(' : inset=True elif c==')' : inset=False r.append(curset) curset=[] elif inset : curset.append(c) else : r.append([c]) return r def solve(word): possible=words[:] exploded=explode(word) for i in range(l): nposs=[] for p in possible : if p[i]in exploded[i]: nposs.append(p) possible=nposs return len(possible) for casenum in range(1,cases+1): out=solve(lines[linenum]) linenum+=1 casestr='Case #'+str(casenum)+': '+str(out) print(casestr) outfile.write(casestr+"\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var filepath : String := '' ; var fileprefix : String := 'A-large' ; var filepathname : String := filepath + fileprefix ; var infilename : String := filepathname + '.in' ; var outfilename : String := filepathname + '.out' ; var lines : OclAny := open(infilename, 'rU').readAll().split("\n") ; var outfile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(outfilename)) ; var linenum : int := 1 ; var vars : OclAny := lines->first().split(' ') ; var cases : int := ("" + ((vars[2+1])))->toInteger() ; var l : int := ("" + ((vars->first())))->toInteger() ; var d : int := ("" + ((vars[1+1])))->toInteger() ; var words : OclAny := lines.subrange(1+1, d + 1) ; linenum := d + 1 ; skip ; skip ; for casenum : Integer.subrange(1, cases + 1-1) do ( var out : OclAny := solve(lines[linenum+1]) ; linenum := linenum + 1 ; var casestr : String := 'Case #' + ("" + ((casenum))) + ': ' + ("" + ((out))) ; execute (casestr)->display() ; outfile.write(casestr + "\n")); operation explode(word : OclAny) : OclAny pre: true post: true activity: var r : Sequence := Sequence{} ; var curset : Sequence := Sequence{} ; var inset : boolean := false ; for c : word do ( if c = '(' then ( inset := true ) else (if c = ')' then ( inset := false ; execute ((curset) : r) ; curset := Sequence{} ) else (if inset then ( execute ((c) : curset) ) else ( execute ((Sequence{ c }) : r) ) ) ) ) ; return r; operation solve(word : OclAny) : OclAny pre: true post: true activity: var possible : Sequence := words ; var exploded : OclAny := explode(word) ; for i : Integer.subrange(0, l-1) do ( var nposs : Sequence := Sequence{} ; for p : possible do ( if (exploded[i+1])->includes(p[i+1]) then ( execute ((p) : nposs) ) else skip) ; possible := nposs) ; return (possible)->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input().split(); print(*a) for _ in " "*int(input()): b,c=input().split(); a[a.index(b)]=c ; print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := input().split(); execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display() ; for _anon : StringLib.nCopies(" ", ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := input().split(); a[a->indexOf(b) - 1+1] := c; execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from StringIO import StringIO import re def process(f,out=None): if isinstance(f,str): if not out : out=open(f+'.out.txt','wb') f=open(f,'rb') else : if not out : out=StringIO() l,d,n=map(int,f.readline().strip().split()) words=[] for i in range(d): words.append(f.readline().strip()) for i in range(n): pattern=f.readline().strip() pattern=pattern.replace('(','[').replace(')',']') expr=re.compile('^'+pattern+'$') count=len(filter(lambda x : expr.match(x),words)) out.write('Case #%d: %s\n' %(i+1,count)) if isinstance(out,StringIO): return out.getvalue() TEST_DATA=("""3 5 4 abc bca dac dbc cba (ab)(bc)(ca) abc (abc)(abc)(abc) (zyx)bc""","""Case #1: 2 Case #2: 1 Case #3: 3 Case #4: 0 """) def go(): assert process(StringIO(TEST_DATA[0]))==TEST_DATA[1] for x in['A-large.in.txt']: process(x) if __name__=='__main__' : go() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var TEST_DATA : OclAny := Sequence{(atom "" "3 5 4\r\nabc\r\nbca\r\ndac\r\ndbc\r\ncba\r\n(ab)(bc)(ca)\r\nabc\r\n(abc)(abc)(abc)\r\n(zyx)bc" ""), (atom "" "Case #1: 2\r\nCase #2: 1\r\nCase #3: 3\r\nCase #4: 0\r\n" "")} ; skip ; if __name__ = '__main__' then ( go() ) else skip; operation process(f : OclAny, out : OclAny) : OclAny pre: true post: true activity: if out->oclIsUndefined() then out := null else skip; if (OclType["String"]).isInstance(f) then ( if not(out) then ( out := OclFile.newOclFile_Write(OclFile.newOclFile(f + '.out.txt')) ) else skip ; f := OclFile.newOclFile_Write(OclFile.newOclFile(f)) ) else ( if not(out) then ( out := StringIO() ) else skip ) ; var l : OclAny := null; var d : OclAny := null; var n : OclAny := null; Sequence{l,d,n} := (f.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var words : Sequence := Sequence{} ; for i : Integer.subrange(0, d-1) do ( execute ((f.readLine()->trim()) : words)) ; for i : Integer.subrange(0, n-1) do ( var pattern : OclAny := f.readLine()->trim() ; pattern := pattern.replace('(', '[').replace(')', ']') ; var expr : OclRegex := OclRegex.compile('^' + pattern + '$') ; var count : int := ((words)->select( _x | (lambda x : OclAny in (expr.match(x)))->apply(_x) = true ))->size() ; out.write(StringLib.format('Case #%d: %s ',Sequence{i + 1, count}))) ; if (StringIO).isInstance(out) then ( return out.getvalue() ) else skip; operation go() pre: true post: true activity: assert process(StringIO(TEST_DATA->first())) = TEST_DATA[1+1] do "assertion failed" ; for x : Sequence{ 'A-large.in.txt' } do ( process(x)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import re def solve(dic,words): ret=[] for word in words : modified="" paropen=False for char in word : if char==")" : paropen=False modified=modified[:-1]+char elif char=="(" : paropen=True modified+=char else : if paropen : modified+=char+"|" else : modified+=char word=modified pattern=re.compile(word) cnt=0 for dic_word in dic : if pattern.match(dic_word)is not None : cnt+=1 ret.append(cnt) return ret if __name__=="__main__" : infile=open(sys.argv[1],"r") outfile=open("resultA.txt","w") input=[int(item)for item in infile.readline().strip().split("")if item!=""] L,D,N=input[0],input[1],input[2] dic=[] for i in range(D): dic.append(infile.readline().strip()) words=[] for i in range(N): words.append(infile.readline().strip()) solution=solve(dic,words) for i in range(len(solution)): outfile.write("Case #%d: %d\n" %(i+1,solution[i])) infile.close() outfile.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( var infile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) ; var outfile : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("resultA.txt")) ; var input : Sequence := infile.readLine()->trim().split("")->select(item | item /= "")->collect(item | (("" + ((item)))->toInteger())) ; var L : OclAny := null; var D : OclAny := null; var N : OclAny := null; Sequence{L,D,N} := Sequence{(OclFile["System.in"]).readLine->first(),(OclFile["System.in"]).readLine[1+1],(OclFile["System.in"]).readLine[2+1]} ; dic := Sequence{} ; for i : Integer.subrange(0, D-1) do ( execute ((infile.readLine()->trim()) : dic)) ; words := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute ((infile.readLine()->trim()) : words)) ; var solution : OclAny := solve(dic, words) ; for i : Integer.subrange(0, (solution)->size()-1) do ( outfile.write(StringLib.format("Case #%d: %d\n",Sequence{i + 1, solution[i+1]}))) ; infile.closeFile() ; outfile.closeFile() ) else skip; operation solve(dic : OclAny, words : OclAny) : OclAny pre: true post: true activity: var ret : Sequence := Sequence{} ; for word : words do ( var modified : String := "" ; var paropen : boolean := false ; for char : word do ( if char = ")" then ( paropen := false ; modified := modified->front() + char ) else (if char = "(" then ( paropen := true ; modified := modified + char ) else ( if paropen then ( modified := modified + char + "|" ) else ( modified := modified + char ) ) ) ) ; var word : String := modified ; var pattern : OclRegex := OclRegex.compile(word) ; var cnt : int := 0 ; for dic_word : dic do ( if not(pattern.match(dic_word) <>= null) then ( cnt := cnt + 1 ) else skip) ; execute ((cnt) : ret)) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout,stderr def solve_case(case): L,D,N,words,pattern=case words=set(words) i=0 j=0 while iunion((words)) ; var i : int := 0 ; var j : int := 0 ; while (i->compareTo((pattern)->size())) < 0 do ( if pattern[i+1] = "(" then ( var end : int := pattern->indexOf(")", i) - 1 ; var options : OclAny := pattern.subrange(i + 1+1, end) ; i := end + 1 ) else ( options := pattern[i+1] ; i := i + 1 ) ; var remove : Set := Set{}->union(()) ; for word : words do ( if (options)->excludes(word[j+1]) then ( execute ((word) : remove) ) else skip) ; for word : remove do ( execute ((word) /: words)) ; j := j + 1) ; return (words)->size(); operation print_case(i : OclAny, ans : OclAny) pre: true post: true activity: var s : String := StringLib.format("Case #%d: %s",Sequence{i, ans}) ; execute (s)->display(); operation main() pre: true post: true activity: var L : OclAny := null; var D : OclAny := null; var N : OclAny := null; Sequence{L,D,N} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; words := Integer.subrange(0, D-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; for i : Integer.subrange(1, N + 1-1) do ( var pattern : String := (OclFile["System.in"]).readLine() ; print_case(i, solve_case(Sequence{L, D, N, words, pattern}))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=(int(i)for i in input().split()) x=[int(i)for i in input().split()] y=[int(i)for i in input().split()] difx,dify,num,num2,mod=[],[],0,0,10**9+7 for i in range(1,n): difx.append(x[i]-x[i-1]) for i in range(1,m): dify.append(y[i]-y[i-1]) for i in range(n-1): num=(num+(i+1)*(n-i-1)*difx[i])% mod for i in range(m-1): num2=(num2+(i+1)*(m-i-1)*dify[i])% mod print(num*num2 % mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var x : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var y : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var difx : OclAny := null; var dify : OclAny := null; var num : OclAny := null; var num2 : OclAny := null; var mod : OclAny := null; Sequence{difx,dify,num,num2,mod} := Sequence{Sequence{},Sequence{},0,0,(10)->pow(9) + 7} ; for i : Integer.subrange(1, n-1) do ( execute ((x[i+1] - x[i - 1+1]) : difx)) ; for i : Integer.subrange(1, m-1) do ( execute ((y[i+1] - y[i - 1+1]) : dify)) ; for i : Integer.subrange(0, n - 1-1) do ( var num : int := (num + (i + 1) * (n - i - 1) * difx[i+1]) mod mod) ; for i : Integer.subrange(0, m - 1-1) do ( var num2 : int := (num2 + (i + 1) * (m - i - 1) * dify[i+1]) mod mod) ; execute (num * num2 mod mod)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.buffer.readline mod=10**9+7 n,m=map(int,input().split()) *x,=map(int,input().split()) *y,=map(int,input().split()) xd=[i-j for j,i in zip(x,x[1 :])] yd=[i-j for j,i in zip(y,y[1 :])] xs=ys=0 for i,d in enumerate(xd): xs+=d*(i+1)*(n-1-i)% mod xs %=mod for i,d in enumerate(yd): ys+=d*(i+1)*(m-1-i)% mod ys %=mod print(xs*ys % mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := sys.stdin.buffer.readline ; var mod : double := (10)->pow(9) + 7 ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (testlist_star_expr (star_expr * (expr (atom (name x)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name x)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (testlist_star_expr (star_expr * (expr (atom (name y)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name y)))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var xd : Sequence := Integer.subrange(1, x->size())->collect( _indx | Sequence{x->at(_indx), x->tail()->at(_indx)} )->select(_tuple | true)->collect(_tuple | let j : OclAny = _tuple->at(1) in let i : OclAny = _tuple->at(2) in (i - j)) ; var yd : Sequence := Integer.subrange(1, y->size())->collect( _indx | Sequence{y->at(_indx), y->tail()->at(_indx)} )->select(_tuple | true)->collect(_tuple | let j : OclAny = _tuple->at(1) in let i : OclAny = _tuple->at(2) in (i - j)) ; var xs : OclAny := 0; var ys : int := 0 ; for _tuple : Integer.subrange(1, (xd)->size())->collect( _indx | Sequence{_indx-1, (xd)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); xs := xs + d * (i + 1) * (n - 1 - i) mod mod ; xs := xs mod mod) ; for _tuple : Integer.subrange(1, (yd)->size())->collect( _indx | Sequence{_indx-1, (yd)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); ys := ys + d * (i + 1) * (m - 1 - i) mod mod ; ys := ys mod mod) ; execute (xs * ys mod mod)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): sys.setrecursionlimit(10**7) INF=10**18 MOD=10**9+7 LI=lambda :[int(x)for x in sys.stdin.readline().split()] _LI=lambda :[int(x)-1 for x in sys.stdin.readline().split()] NI=lambda : int(sys.stdin.readline()) SI=lambda : sys.stdin.readline().rstrip() DD=((1,0),(0,1),(-1,0),(0,-1)) n,m=LI() x=LI() y=LI() x.sort() y.sort() ysum=0 for j in range(1,m): ysum+=j*(m-j)*(y[j]-y[j-1]) ans=0 for i in range(1,n): ans=(ans+i*(n-i)*(x[i]-x[i-1])*ysum)% MOD print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: sys.setrecursionlimit((10)->pow(7)) ; var INF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; var LI : Function := lambda $$ : OclAny in (sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) ; var _LI : Function := lambda $$ : OclAny in (sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1))) ; var NI : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var SI : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var DD : OclAny := Sequence{Sequence{1, 0}, Sequence{0, 1}, Sequence{-1, 0}, Sequence{0, -1}} ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := LI->apply() ; var x : OclAny := LI->apply() ; var y : OclAny := LI->apply() ; x := x->sort() ; y := y->sort() ; var ysum : int := 0 ; for j : Integer.subrange(1, m-1) do ( ysum := ysum + j * (m - j) * (y[j+1] - y[j - 1+1])) ; var ans : int := 0 ; for i : Integer.subrange(1, n-1) do ( ans := (ans + i * (n - i) * (x[i+1] - x[i - 1+1]) * ysum) mod MOD) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) x=list(map(int,input().split())) y=list(map(int,input().split())) X=[] for i in range(1,len(x)): X.append(x[i]-x[i-1]) Y=[] for j in range(1,len(y)): Y.append(y[j]-y[j-1]) A=len(X) for a in range(int((len(X)+1)/2)): X[a]*=A if X[a]==X[len(X)-1-a]: pass else : X[len(X)-1-a]*=A A=A+len(X)-2*(a+1) SX=sum(X) B=len(Y) for b in range(int((len(Y)+1)/2)): Y[b]*=B if Y[b]==Y[len(Y)-1-b]: pass else : Y[len(Y)-1-b]*=B B=B+len(Y)-2*(b+1) SY=sum(Y) print((SX*SY)%(10**9+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var y : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var X : Sequence := Sequence{} ; for i : Integer.subrange(1, (x)->size()-1) do ( execute ((x[i+1] - x[i - 1+1]) : X)) ; var Y : Sequence := Sequence{} ; for j : Integer.subrange(1, (y)->size()-1) do ( execute ((y[j+1] - y[j - 1+1]) : Y)) ; var A : int := (X)->size() ; for a : Integer.subrange(0, ("" + ((((X)->size() + 1) / 2)))->toInteger()-1) do ( X[a+1] := X[a+1] * A ; if X[a+1] = X[(X)->size() - 1 - a+1] then ( skip ) else ( X[(X)->size() - 1 - a+1] := X[(X)->size() - 1 - a+1] * A ) ; A := A + (X)->size() - 2 * (a + 1)) ; var SX : OclAny := (X)->sum() ; var B : int := (Y)->size() ; for b : Integer.subrange(0, ("" + ((((Y)->size() + 1) / 2)))->toInteger()-1) do ( Y[b+1] := Y[b+1] * B ; if Y[b+1] = Y[(Y)->size() - 1 - b+1] then ( skip ) else ( Y[(Y)->size() - 1 - b+1] := Y[(Y)->size() - 1 - b+1] * B ) ; B := B + (Y)->size() - 2 * (b + 1)) ; var SY : OclAny := (Y)->sum() ; execute ((SX * SY) mod ((10)->pow(9) + 7))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math class Node : def __init__(self,data): self.data=data self.next=None def push(head_ref,data): ptr1=Node(data) temp=head_ref ptr1.data=data ptr1.next=head_ref if(head_ref!=None): while(temp.next!=head_ref): temp=temp.next temp.next=ptr1 else : ptr1.next=ptr1 head_ref=ptr1 return head_ref def deleteNode(head_ref,delete): temp=head_ref if(head_ref==delete): head_ref=delete.next while(temp.next!=delete): temp=temp.next temp.next=delete.next def deleteEvenNodes(head): ptr=head next=None next=ptr.next ptr=next while(ptr!=head): if(ptr.data % 2==0): deleteNode(head,ptr) next=ptr.next ptr=next return head def prList(head): temp=head if(head!=None): print(temp.data,end="") temp=temp.next while(temp!=head): print(temp.data,end="") temp=temp.next if __name__=='__main__' : head=None head=push(head,61) head=push(head,12) head=push(head,56) head=push(head,2) head=push(head,11) head=push(head,57) print("List after deletion : ",end="") head=deleteEvenNodes(head) prList(head) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.next := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( head := null ; head := push(head, 61) ; head := push(head, 12) ; head := push(head, 56) ; head := push(head, 2) ; head := push(head, 11) ; head := push(head, 57) ; execute ("List after deletion : ")->display() ; head := deleteEvenNodes(head) ; prList(head) ) else skip; operation push(head_ref : OclAny, data : OclAny) : OclAny pre: true post: true activity: var ptr1 : Node := (Node.newNode()).initialise(data) ; var temp : OclAny := head_ref ; ptr1.data := data ; ptr1.next := head_ref ; if (head_ref /= null) then ( while (temp.next /= head_ref) do ( temp := temp.next) ; temp.next := ptr1 ) else ( ptr1.next := ptr1 ) ; head_ref := ptr1 ; return head_ref; operation deleteNode(head_ref : OclAny, delete : OclAny) pre: true post: true activity: temp := head_ref ; if (head_ref = delete) then ( head_ref := delete.next ) else skip ; while (temp.next /= delete) do ( temp := temp.next) ; temp.next := delete.next; operation deleteEvenNodes(head : OclAny) : OclAny pre: true post: true activity: var ptr : OclAny := head ; var next : OclAny := null ; next := ptr.next ; ptr := next ; while (ptr /= head) do ( if (ptr.data mod 2 = 0) then ( deleteNode(head, ptr) ) else skip ; next := ptr.next ; ptr := next) ; return head; operation prList(head : OclAny) pre: true post: true activity: temp := head ; if (head /= null) then ( execute (temp.data)->display() ; temp := temp.next ; while (temp /= head) do ( execute (temp.data)->display() ; temp := temp.next) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=input().split() n=int(n) m=int(m) x=[int(i)for i in input().split()] y=[int(i)for i in input().split()] def sum(a,n): sum_a=0 for i in range(0,n): sum_a+=i*a[i]-(n-1-i)*a[i] return sum_a sum_x=sum(x,n) sum_y=sum(y,m) s=sum_x*sum_y %(10**9+7) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var m : int := ("" + ((m)))->toInteger() ; var x : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var y : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; skip ; var sum_x : OclAny := (x, n)->sum() ; var sum_y : OclAny := (y, m)->sum() ; var s : int := sum_x * sum_y mod ((10)->pow(9) + 7) ; execute (s)->display(); operation sum(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sum_a : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum_a := sum_a + i * a[i+1] - (n - 1 - i) * a[i+1]) ; return sum_a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t={} for i,c in enumerate(input()): if c not in t : t[c]=(i,1) elif(t[c][0]-i)& 1 : t[c]=(i,t[c][1]+1) print(max(b for a,b in t.values())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := Set{} ; for _tuple : Integer.subrange(1, ((OclFile["System.in"]).readLine())->size())->collect( _indx | Sequence{_indx-1, ((OclFile["System.in"]).readLine())->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if (t)->excludes(c) then ( t[c+1] := Sequence{i, 1} ) else (if MathLib.bitwiseAnd((t[c+1]->first() - i), 1) then ( t[c+1] := Sequence{i, t[c+1][1+1] + 1} ) else skip)) ; execute (((argument (test (logical_test (comparison (expr (atom (name b)))))) (comp_for for (exprlist (expr (atom (name a))) , (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name t)) (trailer . (name values) (arguments ( )))))))))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(1000000) n=int(input()) alst=list(map(int,input().split())) edges=[[]for _ in range(n)] rev_edges=[[]for _ in range(n)] for i in range(n): edges[i].append((i+alst[i])% n) rev_edges[(i+alst[i])% n].append(i) def dfs(x,ret,edges,visited): visited[x]=True for e in edges[x]: if not visited[e]: dfs(e,ret,edges,visited) ret.append(x) def dfs_rev(x,cycles,rev_edges,visited): visited[x]=True flag=False for e in rev_edges[x]: if not visited[e]: cycles.add(e) dfs_rev(e,cycles,rev_edges,visited) flag=True elif x==e : flag=True if flag : cycles.add(x) order=[] visited=[False]*n for i in range(n): if not visited[i]: dfs(i,order,edges,visited) order.reverse() visited=[False]*n cycles=set() for i in order : if not visited[i]: dfs_rev(i,cycles,rev_edges,visited) print(len(cycles)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(1000000) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var alst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var edges : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var rev_edges : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, n-1) do ((expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name alst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))) % (expr (atom (name n))))))))) )))) ; (expr (atom (name rev_edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name alst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))) % (expr (atom (name n))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; skip ; skip ; var order : Sequence := Sequence{} ; visited := MatrixLib.elementwiseMult(Sequence{ false }, n) ; for i : Integer.subrange(0, n-1) do ( if not(visited[i+1]) then ( dfs(i, order, edges, visited) ) else skip) ; order := order->reverse() ; visited := MatrixLib.elementwiseMult(Sequence{ false }, n) ; cycles := Set{}->union(()) ; for i : order do ( if not(visited[i+1]) then ( dfs_rev(i, cycles, rev_edges, visited) ) else skip) ; execute ((cycles)->size())->display(); operation dfs(x : OclAny, ret : OclAny, edges : OclAny, visited : OclAny) pre: true post: true activity: visited[x+1] := true ; for e : edges[x+1] do ( if not(visited[e+1]) then ( dfs(e, ret, edges, visited) ) else skip) ; execute ((x) : ret); operation dfs_rev(x : OclAny, cycles : OclAny, rev_edges : OclAny, visited : OclAny) pre: true post: true activity: visited[x+1] := true ; var flag : boolean := false ; for e : rev_edges[x+1] do ( if not(visited[e+1]) then ( execute ((e) : cycles) ; dfs_rev(e, cycles, rev_edges, visited) ; flag := true ) else (if x = e then ( flag := true ) else skip)) ; if flag then ( execute ((x) : cycles) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t={} for i,c in enumerate(input()): if c not in t : t[c]=(i,1) elif(t[c][0]-i)& 1 : t[c]=(i,t[c][1]+1) print(max(b for a,b in t.values())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := Set{} ; for _tuple : Integer.subrange(1, ((OclFile["System.in"]).readLine())->size())->collect( _indx | Sequence{_indx-1, ((OclFile["System.in"]).readLine())->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if (t)->excludes(c) then ( t[c+1] := Sequence{i, 1} ) else (if MathLib.bitwiseAnd((t[c+1]->first() - i), 1) then ( t[c+1] := Sequence{i, t[c+1][1+1] + 1} ) else skip)) ; execute (((argument (test (logical_test (comparison (expr (atom (name b)))))) (comp_for for (exprlist (expr (atom (name a))) , (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name t)) (trailer . (name values) (arguments ( )))))))))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t={} for i,c in enumerate(input()): if c not in t : t[c]=(i,1) elif(t[c][0]-i)& 1 : t[c]=(i,t[c][1]+1) print(max(b for a,b in t.values())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := Set{} ; for _tuple : Integer.subrange(1, ((OclFile["System.in"]).readLine())->size())->collect( _indx | Sequence{_indx-1, ((OclFile["System.in"]).readLine())->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if (t)->excludes(c) then ( t[c+1] := Sequence{i, 1} ) else (if MathLib.bitwiseAnd((t[c+1]->first() - i), 1) then ( t[c+1] := Sequence{i, t[c+1][1+1] + 1} ) else skip)) ; execute (((argument (test (logical_test (comparison (expr (atom (name b)))))) (comp_for for (exprlist (expr (atom (name a))) , (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name t)) (trailer . (name values) (arguments ( )))))))))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t={} for i,c in enumerate(input()): if c not in t : t[c]=(i,1) elif(t[c][0]-i)& 1 : t[c]=(i,t[c][1]+1) print(max(b for a,b in t.values())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := Set{} ; for _tuple : Integer.subrange(1, ((OclFile["System.in"]).readLine())->size())->collect( _indx | Sequence{_indx-1, ((OclFile["System.in"]).readLine())->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if (t)->excludes(c) then ( t[c+1] := Sequence{i, 1} ) else (if MathLib.bitwiseAnd((t[c+1]->first() - i), 1) then ( t[c+1] := Sequence{i, t[c+1][1+1] + 1} ) else skip)) ; execute (((argument (test (logical_test (comparison (expr (atom (name b)))))) (comp_for for (exprlist (expr (atom (name a))) , (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name t)) (trailer . (name values) (arguments ( )))))))))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t={} for i,c in enumerate(input()): if c not in t : t[c]=(i,1) elif(t[c][0]-i)& 1 : t[c]=(i,t[c][1]+1) print(max(b for a,b in t.values())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := Set{} ; for _tuple : Integer.subrange(1, ((OclFile["System.in"]).readLine())->size())->collect( _indx | Sequence{_indx-1, ((OclFile["System.in"]).readLine())->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if (t)->excludes(c) then ( t[c+1] := Sequence{i, 1} ) else (if MathLib.bitwiseAnd((t[c+1]->first() - i), 1) then ( t[c+1] := Sequence{i, t[c+1][1+1] + 1} ) else skip)) ; execute (((argument (test (logical_test (comparison (expr (atom (name b)))))) (comp_for for (exprlist (expr (atom (name a))) , (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name t)) (trailer . (name values) (arguments ( )))))))))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fun(x): y=(x//4)*4 ans=0 for i in range(y,x+1): ans ^=i return ans def query(x): if(x==0): return 0 k=(x+1)//2 if x % 2==0 : return((fun(k-1)*2)^(k & 1)) else : return(2*fun(k)) def allQueries(q,l,r): for i in range(q): print(query(r[i])^ query(l[i]-1)) q=3 l=[2,2,5] r=[4,8,9] allQueries(q,l,r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; q := 3 ; l := Sequence{2}->union(Sequence{2}->union(Sequence{ 5 })) ; r := Sequence{4}->union(Sequence{8}->union(Sequence{ 9 })) ; allQueries(q, l, r); operation fun(x : OclAny) : OclAny pre: true post: true activity: var y : int := (x div 4) * 4 ; var ans : int := 0 ; for i : Integer.subrange(y, x + 1-1) do ( ans := ans xor i) ; return ans; operation query(x : OclAny) : OclAny pre: true post: true activity: if (x = 0) then ( return 0 ) else skip ; var k : int := (x + 1) div 2 ; if x mod 2 = 0 then ( return (MathLib.bitwiseXor((fun(k - 1) * 2), (MathLib.bitwiseAnd(k, 1)))) ) else ( return (2 * fun(k)) ); operation allQueries(q : OclAny, l : OclAny, r : OclAny) pre: true post: true activity: for i : Integer.subrange(0, q-1) do ( execute (MathLib.bitwiseXor(query(r[i+1]), query(l[i+1] - 1)))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=[int(i)for i in input().split()] a=[int(i)for i in input().split()] u=[int(i)for i in input().split()] t=[] for i in a : t+=[i/s[1]+(((u[0]-i)**2+u[1]**2)**0.5)/s[2]] del t[0] if t.count(min(t))>1 : print(t.index(min(t))+2+t.count(min(t))-1) else : print(t.index(min(t))+2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var u : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var t : Sequence := Sequence{} ; for i : a do ( t := t + Sequence{ i / s[1+1] + (((((u->first() - i))->pow(2) + (u[1+1])->pow(2)))->pow(0.5)) / s[2+1] }) ; execute (t->first())->isDeleted() ; if t->count((t)->min()) > 1 then ( execute (t->indexOf((t)->min()) - 1 + 2 + t->count((t)->min()) - 1)->display() ) else ( execute (t->indexOf((t)->min()) - 1 + 2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,mbs,ss=map(int,input().split()) st=list(map(int,input().split())) x,y=map(int,input().split()) if ss>mbs : print(2) else : t=[] l=[] for i in st : u=i o=((x-i)**2+y**2)**0.5 tt=u/mbs+o/ss t.append(tt) l.append(o/ss) g=t.index(min(t)) if min(t)==max(t): g=l.index(min(l)) if g==0 : g+=1 print(g+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var mbs : OclAny := null; var ss : OclAny := null; Sequence{n,mbs,ss} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var st : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (ss->compareTo(mbs)) > 0 then ( execute (2)->display() ) else ( var t : Sequence := Sequence{} ; var l : Sequence := Sequence{} ; for i : st do ( var u : OclAny := i ; var o : double := ((((x - i))->pow(2) + (y)->pow(2)))->pow(0.5) ; var tt : double := u / mbs + o / ss ; execute ((tt) : t) ; execute ((o / ss) : l)) ; var g : int := t->indexOf((t)->min()) - 1 ; if (t)->min() = (t)->max() then ( g := l->indexOf((l)->min()) - 1 ) else skip ; if g = 0 then ( g := g + 1 ) else skip ; execute (g + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,vb,vs=map(int,input().split()) x=[int(i)for i in input().split()] x2,y2=map(int,input().split()) px,xd,tx=0,10**6,10**6 for i in range(1,n): d=((x2-x[i])**2+y2**2)**0.5 t=x[i]/vb+d/vs if tcollect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var px : OclAny := null; var xd : OclAny := null; var tx : OclAny := null; Sequence{px,xd,tx} := Sequence{0,(10)->pow(6),(10)->pow(6)} ; for i : Integer.subrange(1, n-1) do ( var d : double := ((((x2 - x[i+1]))->pow(2) + (y2)->pow(2)))->pow(0.5) ; var t : double := x[i+1] / vb + d / vs ; if (t->compareTo(tx)) < 0 or (t = tx & (d->compareTo(xd)) < 0) then ( var px : OclAny := null; var xd : OclAny := null; var tx : OclAny := null; Sequence{px,xd,tx} := Sequence{i,d,t} ) else skip) ; execute (px + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSolutions(n,val): total=0 if n==1 and val>=0 : return 1 for i in range(val+1): total+=countSolutions(n-1,val-i) return total n=5 val=20 print(countSolutions(n,val)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; val := 20 ; execute (countSolutions(n, val))->display(); operation countSolutions(n : OclAny, val : OclAny) : OclAny pre: true post: true activity: var total : int := 0 ; if n = 1 & val >= 0 then ( return 1 ) else skip ; for i : Integer.subrange(0, val + 1-1) do ( total := total + countSolutions(n - 1, val - i)) ; return total; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,vb,vs=map(int,input().split()) lis=list(map(int,input().split())) xs,ys=map(int,input().split()) tmin=10000000 dmin=10000000 ind=-1 for i in range(1,n): ds=math.sqrt(pow(xs-lis[i],2)+pow(ys,2)) t=lis[i]/vb+ds/vs if tds : dmin=ds ind=i+1 print(ind) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var vb : OclAny := null; var vs : OclAny := null; Sequence{n,vb,vs} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lis : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var xs : OclAny := null; var ys : OclAny := null; Sequence{xs,ys} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var tmin : int := 10000000 ; var dmin : int := 10000000 ; var ind : int := -1 ; for i : Integer.subrange(1, n-1) do ( var ds : double := ((xs - lis[i+1])->pow(2) + (ys)->pow(2))->sqrt() ; var t : double := lis[i+1] / vb + ds / vs ; if (t->compareTo(tmin)) < 0 then ( tmin := t ; dmin := ds ; ind := i + 1 ) else (if t = tmin & (dmin->compareTo(ds)) > 0 then ( dmin := ds ; ind := i + 1 ) else skip)) ; execute (ind)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(1000000) def dfs(x,order,edges,visited): visited[x]=True for e in edges[x]: if not visited[e]: dfs(e,order,edges,visited) order.append(x) def dfs_rev(x,rev_edges,visited): visited[x]=True ret=0 for e in rev_edges[x]: if not visited[e]: ret+=1 ret+=dfs_rev(e,rev_edges,visited) return ret n=int(input()) alst=list(map(int,input().split())) edges=[[]for _ in range(n)] rev_edges=[[]for _ in range(n)] for i in range(n): edges[i].append((i+alst[i])% n) rev_edges[(i+alst[i])% n].append(i) order=[] visited=[False]*n for i in range(n): if not visited[i]: dfs(i,order,edges,visited) order.reverse() visited=[False]*n cycles=0 for i in order : if not visited[i]: a=dfs_rev(i,rev_edges,visited) if a>0 or i in rev_edges[i]: a+=1 cycles+=a print(cycles) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(1000000) ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var alst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; edges := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; rev_edges := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, n-1) do ((expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name alst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))) % (expr (atom (name n))))))))) )))) ; (expr (atom (name rev_edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name alst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))) % (expr (atom (name n))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; order := Sequence{} ; visited := MatrixLib.elementwiseMult(Sequence{ false }, n) ; for i : Integer.subrange(0, n-1) do ( if not(visited[i+1]) then ( dfs(i, order, edges, visited) ) else skip) ; order := order->reverse() ; visited := MatrixLib.elementwiseMult(Sequence{ false }, n) ; var cycles : int := 0 ; for i : order do ( if not(visited[i+1]) then ( var a : OclAny := dfs_rev(i, rev_edges, visited) ; if a > 0 or (rev_edges[i+1])->includes(i) then ( a := a + 1 ) else skip ; cycles := cycles + a ) else skip) ; execute (cycles)->display(); operation dfs(x : OclAny, order : OclAny, edges : OclAny, visited : OclAny) pre: true post: true activity: visited[x+1] := true ; for e : edges[x+1] do ( if not(visited[e+1]) then ( dfs(e, order, edges, visited) ) else skip) ; execute ((x) : order); operation dfs_rev(x : OclAny, rev_edges : OclAny, visited : OclAny) : OclAny pre: true post: true activity: visited[x+1] := true ; var ret : int := 0 ; for e : rev_edges[x+1] do ( if not(visited[e+1]) then ( ret := ret + 1 ; ret := ret + dfs_rev(e, rev_edges, visited) ) else skip) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,vb,vs=map(int,input().split()) a=list(map(int,input().split())) x,y=map(int,input().split()) res=1e10 target=2 minTo=1e10 for i in range(1,len(a)): to=((a[i]-x)**2+y**2)**0.5 dis=a[i]/vb+to/vs if discollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var res : double := ("1e10")->toReal() ; var target : int := 2 ; var minTo : double := ("1e10")->toReal() ; for i : Integer.subrange(1, (a)->size()-1) do ( var to : double := ((((a[i+1] - x))->pow(2) + (y)->pow(2)))->pow(0.5) ; var dis : double := a[i+1] / vb + to / vs ; if (dis->compareTo(res)) < 0 or (dis = res & (to->compareTo(minTo)) < 0) then ( target := i + 1 ; res := dis ; minTo := to ) else skip) ; execute (target)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def previousNumber(num1): n=len(num1); num=list(num1); if(num1=="1"): return "0" ; i=n-1 ; while(i>=0): if(num[i]=='1'): num[i]='0' ; break ; else : num[i]='1' ; i-=1 ; if(i==0): return num[1 : n]; return ''.join(num); num="10110" ; print("Binary representation of previous number=",previousNumber(num)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; num := "10110"; ; execute ("Binary representation of previous number=")->display();; operation previousNumber(num1 : OclAny) pre: true post: true activity: var n : int := (num1)->size(); ; var num : Sequence := (num1); ; if (num1 = "1") then ( return "0"; ) else skip ; var i : double := n - 1; ; while (i >= 0) do ( if (num[i+1] = '1') then ( num[i+1] := '0'; ; break; ) else ( num[i+1] := '1'; ) ; i := i - 1;) ; if (i = 0) then ( return num.subrange(1+1, n); ) else skip ; return StringLib.sumStringsWithSeparator((num), '');; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): n,d=map(int,input().split(' ')) a=list(map(int,input().split(' '))) i=1 while(d>0 and itoInteger()-1) do ( var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var i : int := 1 ; while (d > 0 & (i->compareTo(n)) < 0) do ( var m : int := Set{d, a[i+1] * i}->min() div i ; d := d - m * i ; a->first() := a->first() + m ; i := i + 1) ; execute (a->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,d=map(int,input().split()) arr=list(map(int,input().split())) total=arr[0] i=1 while d>0 and itoInteger()-1) do ( var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var total : OclAny := arr->first() ; var i : int := 1 ; while d > 0 & (i->compareTo(n)) < 0 do ( var new : OclAny := Set{d div i, arr[i+1]}->min() ; total := total + new ; var d : double := d - (new * i) ; i := i + 1) ; execute (total)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,d,arr): i=1 while d>0 and i=i : d-=i arr[0]+=1 arr[i]-=1 return arr[0] if __name__=="__main__" : t=int(input()) results=list() for _ in range(0,t): n,d=list(map(int,input().split(" "))) arr=list(map(int,input().split(" "))) results.append(solve(n,d,arr)) for result in results : print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var results : Sequence := () ; for _anon : Integer.subrange(0, t-1) do ( Sequence{n,d} := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; arr := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((solve(n, d, arr)) : results)) ; for result : results do ( execute (result)->display()) ) else skip; operation solve(n : OclAny, d : OclAny, arr : OclAny) : OclAny pre: true post: true activity: var i : int := 1 ; while d > 0 & (i->compareTo(n)) < 0 do ( if arr[i+1] <= 0 or (d->compareTo(i)) < 0 then ( i := i + 1 ) else (if (d->compareTo(i)) >= 0 then ( d := d - i ; arr->first() := arr->first() + 1 ; arr[i+1] := arr[i+1] - 1 ) else skip)) ; return arr->first(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) t,=R() for _ in[0]*t : n,d=R(); r=i=0 for x in R(): m=min(d,i*x); r+=m//i if i else x ; d-=m ; i+=1 print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := R->apply() ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, t) do ( var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := R->apply(); var r : OclAny := 0; var i : int := 0 ; for x : R->apply() do ( var m : OclAny := Set{d, i * x}->min(); r := r + if i then m div i else x endif; d := d - m; i := i + 1) ; execute (r)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline t=int(input()) ans=[] for _ in range(t): n,d=map(int,input().split()) a=list(map(int,input().split())) ans0=a[0] for i in range(1,n): x=min(d//i,a[i]) ans0+=x d-=x*i ans.append(ans0) sys.stdout.write("\n".join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans0 : OclAny := a->first() ; for i : Integer.subrange(1, n-1) do ( var x : OclAny := Set{d div i, a[i+1]}->min() ; ans0 := ans0 + x ; d := d - x * i) ; execute ((ans0) : ans)) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "\n") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,ceil,floor def createHash(maxElement): prev=0 curr=1 d=dict() d[prev]=1 d[curr]=1 while(curr<=maxElement): temp=curr+prev d[temp]=1 prev=curr curr=temp return d def countFibonacciDivisors(n): hash=createHash(n) cnt=0 for i in range(1,ceil(sqrt(n))): if(n % i==0): if((n//i==i)and(n//i in hash)): cnt+=1 else : if(n//i in hash): cnt+=1 if(n//(n//i)in hash): cnt+=1 return cnt n=12 print(countFibonacciDivisors(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 12 ; execute (countFibonacciDivisors(n))->display(); operation createHash(maxElement : OclAny) : OclAny pre: true post: true activity: var prev : int := 0 ; var curr : int := 1 ; var d : Map := (arguments ( )) ; d[prev+1] := 1 ; d[curr+1] := 1 ; while ((curr->compareTo(maxElement)) <= 0) do ( var temp : int := curr + prev ; d[temp+1] := 1 ; prev := curr ; curr := temp) ; return d; operation countFibonacciDivisors(n : OclAny) : OclAny pre: true post: true activity: var hash : OclAny := createHash(n) ; var cnt : int := 0 ; for i : Integer.subrange(1, ceil(sqrt(n))-1) do ( if (n mod i = 0) then ( if ((n div i = i) & ((hash)->includes(n div i))) then ( cnt := cnt + 1 ) else ( if ((hash)->includes(n div i)) then ( cnt := cnt + 1 ) else skip ; if ((hash)->includes(n div (n div i))) then ( cnt := cnt + 1 ) else skip ) ) else skip) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) r=list(map(int,input().split())) m=int(input()) b=list(map(int,input().split())) x=s=0 for i in r : s+=i x=max(x,s) s=x for i in b : s+=i x=max(x,s) print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := 0; var s : int := 0 ; for i : r do ( s := s + i ; x := Set{x, s}->max()) ; s := x ; for i : b do ( s := s + i ; x := Set{x, s}->max()) ; execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math class Node : def __init__(self,data): self.data=data self.left=None self.right=None def newNode(data): return Node(data) def CheckPerfectTree(root): q=[] q.append(root) flag=0 while(q): temp=q[0] q.pop(0) if(temp.left and temp.right): if(flag==1): return False else : q.append(temp.left) q.append(temp.right) elif(not temp.left and not temp.right): flag=1 elif(not temp.left or not temp.right): return False return True if __name__=='__main__' : root=newNode(7) root.left=newNode(5) root.left.left=newNode(8) root.left.right=newNode(1) root.right=newNode(6) root.right.left=newNode(3) root.right.right=newNode(9) root.right.right.left=newNode(10) root.right.right.right=newNode(13) if CheckPerfectTree(root): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.left := null ; self.right := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( root := newNode(7) ; root.left := newNode(5) ; root.left.left := newNode(8) ; root.left.right := newNode(1) ; root.right := newNode(6) ; root.right.left := newNode(3) ; root.right.right := newNode(9) ; root.right.right.left := newNode(10) ; root.right.right.right := newNode(13) ; if CheckPerfectTree(root) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation newNode(data : OclAny) : OclAny pre: true post: true activity: return (Node.newNode()).initialise(data); operation CheckPerfectTree(root : OclAny) : OclAny pre: true post: true activity: var q : Sequence := Sequence{} ; execute ((root) : q) ; var flag : int := 0 ; while (q) do ( var temp : OclAny := q->first() ; q := q->excludingAt(0+1) ; if (temp.left & temp.right) then ( if (flag = 1) then ( return false ) else ( execute ((temp.left) : q) ; execute ((temp.right) : q) ) ) else (if (not(temp.left) & not(temp.right)) then ( flag := 1 ) else (if (not(temp.left) or not(temp.right)) then ( return false ) else skip ) ) ) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def isTriangular(num): if(num<0): return False c=(-2*num) b,a=1,1 d=(b*b)-(4*a*c) if(d<0): return False root1=(-b+math.sqrt(d))/(2*a) root2=(-b-math.sqrt(d))/(2*a) if(root1>0 and math.floor(root1)==root1): return True if(root2>0 and math.floor(root2)==root2): return True return False n=55 if(isTriangular(n)): print("The number is a triangular number") else : print("The number is NOT a triangular number") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := 55 ; if (isTriangular(n)) then ( execute ("The number is a triangular number")->display() ) else ( execute ("The number is NOT a triangular number")->display() ); operation isTriangular(num : OclAny) : OclAny pre: true post: true activity: if (num < 0) then ( return false ) else skip ; var c : double := (-2 * num) ; var b : OclAny := null; var a : OclAny := null; Sequence{b,a} := Sequence{1,1} ; var d : double := (b * b) - (4 * a * c) ; if (d < 0) then ( return false ) else skip ; var root1 : double := (-b + (d)->sqrt()) / (2 * a) ; var root2 : double := (-b - (d)->sqrt()) / (2 * a) ; if (root1 > 0 & (root1)->floor() = root1) then ( return true ) else skip ; if (root2 > 0 & (root2)->floor() = root2) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : t-=1 n=int(input()) r=[int(x)for x in input().split()] m=int(input()) b=[int(x)for x in input().split()] currentmaxr=r[0] globalmaxr=r[0] x=0 for i in range(1,len(r)): globalmaxr=max(currentmaxr,globalmaxr) if currentmaxr<=0 : currentmaxr=r[i] else : currentmaxr+=r[i] maxr=0 maxb=0 for i in r : x+=i maxr=max(maxr,x) x=0 for i in b : x+=i maxb=max(maxb,x) print(maxr+maxb) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( t := t - 1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var currentmaxr : String := r->first() ; var globalmaxr : String := r->first() ; var x : int := 0 ; for i : Integer.subrange(1, (r)->size()-1) do ( globalmaxr := Set{currentmaxr, globalmaxr}->max() ; if currentmaxr <= 0 then ( currentmaxr := r[i+1] ) else ( currentmaxr := currentmaxr + r[i+1] )) ; var maxr : int := 0 ; var maxb : int := 0 ; for i : r do ( x := x + i ; maxr := Set{maxr, x}->max()) ; x := 0 ; for i : b do ( x := x + i ; maxb := Set{maxb, x}->max()) ; execute (maxr + maxb)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import* f=lambda : max(0,*accumulate(map(int,input().split()))) exec(f()*'f();r=f();f();print(r+f());') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var f : Function := lambda $$ : OclAny in (Set{0, (argument * (test (logical_test (comparison (expr (atom (name accumulate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))))))}->max()) ; (expr (expr (atom (name f)) (trailer (arguments ( )))) * (expr (atom 'f();r=f();f();print(r+f());'))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for x in range(t): n=int(input()) ln=list(map(int,input().split())) for y in range(1,n): ln[y]+=ln[y-1] m=int(input()) lm=list(map(int,input().split())) for y in range(1,m): lm[y]+=lm[y-1] print(max([0,max(lm)+max(ln),max(lm),max(ln)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for x : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ln : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for y : Integer.subrange(1, n-1) do ( ln[y+1] := ln[y+1] + ln[y - 1+1]) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lm : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for y : Integer.subrange(1, m-1) do ( lm[y+1] := lm[y+1] + lm[y - 1+1]) ; execute ((Sequence{0}->union(Sequence{(lm)->max() + (ln)->max()}->union(Sequence{(lm)->max()}->union(Sequence{ (ln)->max() }))))->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) li=list(map(int,input().split())) m=int(input()) li1=list(map(int,input().split())) mx_li=0 mx_li1=0 tmp=0 tmp1=0 for i in range(n): tmp+=li[i] mx_li=max(tmp,mx_li) for j in range(m): tmp1+=li1[j] mx_li1=max(tmp1,mx_li1) print(mx_li+mx_li1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mx_li : int := 0 ; var mx_li1 : int := 0 ; var tmp : int := 0 ; var tmp1 : int := 0 ; for i : Integer.subrange(0, n-1) do ( tmp := tmp + li[i+1] ; mx_li := Set{tmp, mx_li}->max()) ; for j : Integer.subrange(0, m-1) do ( tmp1 := tmp1 + li1[j+1] ; mx_li1 := Set{tmp1, mx_li1}->max()) ; execute (mx_li + mx_li1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,Counter from itertools import product,groupby,count,permutations,combinations from math import pi,sqrt from collections import deque from bisect import bisect,bisect_left,bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF=float("inf") YES,Yes,yes,NO,No,no="YES","Yes","yes","NO","No","no" dy4,dx4=[0,1,0,-1],[1,0,-1,0] dy8,dx8=[0,-1,0,1,1,-1,-1,1],[1,0,-1,0,1,1,-1,-1] def inside(y,x,H,W): return 0<=ytoReal() ; var YES : OclAny := null; var Yes : OclAny := null; var yes : OclAny := null; var NO : OclAny := null; var No : OclAny := null; var no : OclAny := null; Sequence{YES,Yes,yes,NO,No,no} := Sequence{"YES","Yes","yes","NO","No","no"} ; var dy4 : OclAny := null; var dx4 : OclAny := null; Sequence{dy4,dx4} := Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ -1 }))),Sequence{1}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{ 0 })))} ; var dy8 : OclAny := null; var dx8 : OclAny := null; Sequence{dy8,dx8} := Sequence{Sequence{0}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{-1}->union(Sequence{-1}->union(Sequence{ 1 }))))))),Sequence{1}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{-1}->union(Sequence{ -1 })))))))} ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation inside(y : OclAny, x : OclAny, H : OclAny, W : OclAny) : OclAny pre: true post: true activity: return 0 <= y & (y < H) & 0 <= x & (x < W); operation ceil(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a + b - 1) div b; operation sum_of_arithmetic_progression(s : OclAny, d : OclAny, n : OclAny) : OclAny pre: true post: true activity: return n * (2 * s + (n - 1) * d) div 2; operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if b = 0 then ( return a ) else skip ; return gcd(b, a mod b); operation lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var g : OclAny := gcd(a, b) ; return a / g * b; operation solve() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var num : int := 0 ; for i : Integer.subrange(0, (S)->size() div 2-1) do ( num := num + S[i+1] /= S->reverse()->at(-(-i - 1))) ; execute (num)->display(); operation main() pre: true post: true activity: solve(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() list_S=list(S) str_len=int(len(list_S)/2) one=list(S[: str_len]) two=list(reversed(list(S[-str_len :]))) hug=0 for i in range(len(one)): if not one[i]==two[i]: hug=hug+1 print(hug) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var list_S : Sequence := (S)->characters() ; var str_len : int := ("" + (((list_S)->size() / 2)))->toInteger() ; var one : Sequence := (S.subrange(1,str_len)) ; var two : Sequence := (((S.subrange(-str_len+1)))->reverse()) ; var hug : int := 0 ; for i : Integer.subrange(0, (one)->size()-1) do ( if not(one[i+1] = two[i+1]) then ( hug := hug + 1 ) else skip) ; execute (hug)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s1=input() s2=s1[: :-1] print(sum([1 for i in range(len(s1))if s1[i]!=s2[i]])//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s1 : String := (OclFile["System.in"]).readLine() ; var s2 : OclAny := s1(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; execute ((Integer.subrange(0, (s1)->size()-1)->select(i | s1[i+1] /= s2[i+1])->collect(i | (1)))->sum() div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from bisect import bisect_left from bisect import bisect_right import collections import copy import heapq from collections import defaultdict from heapq import heappop,heappush import itertools input=sys.stdin.readline def inputInt(): return int(input()) def inputMap(): return map(int,input().split()) def inputList(): return list(map(int,input().split())) def main(): S=input() S=S[:-1] tmp=len(S) tmp=tmp//2 ans=0 for i in range(tmp): if S[i]==S[-1*(i+1)]: pass else : ans+=1 print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation inputInt() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inputMap() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation inputList() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation main() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; S := S->front() ; var tmp : int := (S)->size() ; tmp := tmp div 2 ; var ans : int := 0 ; for i : Integer.subrange(0, tmp-1) do ( if S[i+1] = S->reverse()->at(-(-1 * (i + 1))) then ( skip ) else ( ans := ans + 1 )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- word=input() num=len(word) cnt=0 for i in range(num): if word[i]!=word[-(i+1)]: cnt+=1 print(cnt//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var word : String := (OclFile["System.in"]).readLine() ; var num : int := (word)->size() ; var cnt : int := 0 ; for i : Integer.subrange(0, num-1) do ( if word[i+1] /= word->reverse()->at(-(-(i + 1))) then ( cnt := cnt + 1 ) else skip) ; execute (cnt div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def validate(n): count=[0 for i in range(10)] while(n>0): r=n % 10 if(count[r]==r): return False count[r]+=1 n=n//10 return True n=1552793 if(validate(n)): print("True") else : print("False") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 1552793 ; if (validate(n)) then ( execute ("True")->display() ) else ( execute ("False")->display() ); operation validate(n : OclAny) : OclAny pre: true post: true activity: var count : Sequence := Integer.subrange(0, 10-1)->select(i | true)->collect(i | (0)) ; while (n > 0) do ( var r : int := n mod 10 ; if (count[r+1] = r) then ( return false ) else skip ; count[r+1] := count[r+1] + 1 ; n := n div 10) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt while True : x=float(input()) h=float(input()) if x==h==0 : break ans=(sqrt(4*h*h+x**2)+x)*x print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var x : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; var h : double := ("" + (((OclFile["System.in"]).readLine())))->toReal() ; if x = h & (h == 0) then ( break ) else skip ; var ans : double := (sqrt(4 * h * h + (x)->pow(2)) + x) * x ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printNumberWithDR(k,d): if d==0 and k!=1 : print(-1,end="") else : print(d,end="") k-=1 while k : print(0,end="") k-=1 if __name__=="__main__" : k,d=4,4 printNumberWithDR(k,d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{k,d} := Sequence{4,4} ; printNumberWithDR(k, d) ) else skip; operation printNumberWithDR(k : OclAny, d : OclAny) pre: true post: true activity: if d = 0 & k /= 1 then ( execute (-1)->display() ) else ( execute (d)->display() ; k := k - 1 ; while k do ( execute (0)->display() ; k := k - 1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,data): self.data=data self.left=None self.right=None def CheckChildrenSum(root): q=[] q.append(root) while len(q)!=0 : temp=q.pop() if temp.left and temp.right : if(temp.data!=temp.left.data+temp.right.data): return False q.append(temp.left) q.append(temp.right) elif not temp.left and temp.right : if temp.data!=temp.right.data : return False q.append(temp.right) elif not temp.right and temp.left : if temp.data!=temp.left.data : return False q.append(temp.left) return True if __name__=="__main__" : root=Node(10) root.left=Node(8) root.right=Node(2) root.left.left=Node(3) root.left.right=Node(5) root.right.right=Node(2) if CheckChildrenSum(root): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.left := null ; self.right := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( root := (Node.newNode()).initialise(10) ; root.left := (Node.newNode()).initialise(8) ; root.right := (Node.newNode()).initialise(2) ; root.left.left := (Node.newNode()).initialise(3) ; root.left.right := (Node.newNode()).initialise(5) ; root.right.right := (Node.newNode()).initialise(2) ; if CheckChildrenSum(root) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation CheckChildrenSum(root : OclAny) : OclAny pre: true post: true activity: var q : Sequence := Sequence{} ; execute ((root) : q) ; while (q)->size() /= 0 do ( var temp : OclAny := q->last() ; q := q->front() ; if temp.left & temp.right then ( if (temp.data /= temp.left.data + temp.right.data) then ( return false ) else skip ; execute ((temp.left) : q) ; execute ((temp.right) : q) ) else (if not(temp.left) & temp.right then ( if temp.data /= temp.right.data then ( return false ) else skip ; execute ((temp.right) : q) ) else (if not(temp.right) & temp.left then ( if temp.data /= temp.left.data then ( return false ) else skip ; execute ((temp.left) : q) ) else skip ) ) ) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): h,w=map(int,input().split()) print(('10'*w)[: w]) for i in range(h-2): if i % 2==1 and itoInteger()-1) do ( var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((StringLib.nCopies('10', w)).subrange(1,w))->display() ; for i : Integer.subrange(0, h - 2-1) do ( if i mod 2 = 1 & (i->compareTo(h - 3)) < 0 then ( execute ('1' + StringLib.nCopies('0', (w - 2)) + '1')->display() ) else ( execute (StringLib.nCopies('0', w))->display() )) ; execute ((StringLib.nCopies('10', w)).subrange(1,w))->display() ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): h,w=map(int,input().split('')) flag=1 for i in range(h): if flag : flag=0 if i==0 or i==h-1 : for j in range(w): if j % 2==0 : print(1,end='') else : print(0,end='') elif i!=h-2 : for j in range(w): if j==0 or j==w-1 : print(1,end='') else : print(0,end='') else : flag=1 for _ in range(w): print(0,end='') else : flag=1 for _ in range(w): print(0,end='') print('') print('') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split(''))->collect( _x | (OclType["int"])->apply(_x) ) ; var flag : int := 1 ; for i : Integer.subrange(0, h-1) do ( if flag then ( flag := 0 ; if i = 0 or i = h - 1 then ( for j : Integer.subrange(0, w-1) do ( if j mod 2 = 0 then ( execute (1)->display() ) else ( execute (0)->display() )) ) else (if i /= h - 2 then ( for j : Integer.subrange(0, w-1) do ( if j = 0 or j = w - 1 then ( execute (1)->display() ) else ( execute (0)->display() )) ) else ( flag := 1 ; for _anon : Integer.subrange(0, w-1) do ( execute (0)->display()) ) ) ) else ( flag := 1 ; for _anon : Integer.subrange(0, w-1) do ( execute (0)->display()) ) ; execute ('')->display()) ; execute ('')->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): h,w=map(int,input().split()) global m m=[list('0'*w)for i in range(h)] for i in range(0,w,2): m[0][i]='1' if h<=4 : if h>2 : for i in range(0,w,2): m[h-1][i]='1' for i in range(h): print(*m[i],sep='') else : for i in range(0,w,2): m[h-1][i]='1' for i in range(2,h-2,2): m[i][0]='1' if w<=2 : for i in range(h): print(*m[i],sep='') else : for i in range(2,h-2,2): m[i][w-1]='1' for i in range(h): print(*m[i],sep='') print() t=int(input()) while t>0 : t-=1 solve() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute m : OclAny; operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( t := t - 1 ; solve()); operation solve() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; m := Integer.subrange(0, h-1)->select(i | true)->collect(i | ((StringLib.nCopies('0', w))->characters())) ; for i : Integer.subrange(0, w-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( m->first()[i+1] := '1') ; if h <= 4 then ( if h > 2 then ( for i : Integer.subrange(0, w-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( m[h - 1+1][i+1] := '1') ) else skip ; for i : Integer.subrange(0, h-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name m)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))->display()) ) else ( for i : Integer.subrange(0, w-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( m[h - 1+1][i+1] := '1') ; for i : Integer.subrange(2, h - 2-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( m[i+1]->first() := '1') ; if w <= 2 then ( for i : Integer.subrange(0, h-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name m)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))->display()) ) else ( for i : Integer.subrange(2, h - 2-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( m[i+1][w - 1+1] := '1') ; for i : Integer.subrange(0, h-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name m)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))->display()) ) ) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): h,w=map(int,input().split()) s='0'*w s1,s2=' ',' ' for i in range(0,w): if i==0 or i==w-1 : s1+='1' else : s1+='0' for i in range(0,w): if i % 2==0 : s2+='1' else : s2+='0' for i in range(0,h): if i==0 or i==h-1 : print(s2) elif i % 2==0 and i!=0 and itoInteger() ; for t : Integer.subrange(0, T-1) do ( solve()); operation solve() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := StringLib.nCopies('0', w) ; var s1 : OclAny := null; var s2 : OclAny := null; Sequence{s1,s2} := Sequence{' ',' '} ; for i : Integer.subrange(0, w-1) do ( if i = 0 or i = w - 1 then ( s1 := s1 + '1' ) else ( s1 := s1 + '0' )) ; for i : Integer.subrange(0, w-1) do ( if i mod 2 = 0 then ( s2 := s2 + '1' ) else ( s2 := s2 + '0' )) ; for i : Integer.subrange(0, h-1) do ( if i = 0 or i = h - 1 then ( execute (s2)->display() ) else (if i mod 2 = 0 & i /= 0 & (i->compareTo(h - 2)) < 0 then ( execute (s1)->display() ) else ( execute (s)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import tan def polyapothem(n,a): if(a<0 and n<0): return-1 return a/(2*tan((180/n)*3.14159/180)) if __name__=='__main__' : a=9 n=6 print('{0:.6}'.format(polyapothem(n,a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( a := 9 ; n := 6 ; execute (StringLib.interpolateStrings('{0:.6}', Sequence{polyapothem(n, a)}))->display() ) else skip; operation polyapothem(n : OclAny, a : OclAny) : OclAny pre: true post: true activity: if (a < 0 & n < 0) then ( return -1 ) else skip ; return a / (2 * tan((180 / n) * 3.14159 / 180)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate n,d,m=map(int,input().split()) a=list(map(int,input().split())) lo=[] hi=[] for x in a : if x<=m : lo.append(x) else : hi.append(x) lo.sort(reverse=True) lo_accum=list(accumulate(lo)) hi.sort(reverse=True) hi_accum=list(accumulate(hi)) best=0 if not hi : print(lo_accum[-1]) exit() for hi_chosen in range(1,len(hi)+1): rem_hi=len(hi)-hi_chosen can_cover=hi_chosen*d if can_coverlen(lo): continue cur=0 cur+=hi_accum[hi_chosen-1] if lo_coveredcollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lo : Sequence := Sequence{} ; var hi : Sequence := Sequence{} ; for x : a do ( if (x->compareTo(m)) <= 0 then ( execute ((x) : lo) ) else ( execute ((x) : hi) )) ; lo := lo->sort() ; var lo_accum : Sequence := (accumulate(lo)) ; hi := hi->sort() ; var hi_accum : Sequence := (accumulate(hi)) ; var best : int := 0 ; if not(hi) then ( execute (lo_accum->last())->display() ; exit() ) else skip ; for hi_chosen : Integer.subrange(1, (hi)->size() + 1-1) do ( var rem_hi : double := (hi)->size() - hi_chosen ; var can_cover : double := hi_chosen * d ; if (can_cover->compareTo(rem_hi)) < 0 then ( continue ) else skip ; var must_cover : OclAny := Set{(hi_chosen - 1) * d, rem_hi}->max() ; var lo_covered : OclAny := Set{0, must_cover - rem_hi}->max() ; if (lo_covered->compareTo((lo)->size())) > 0 then ( continue ) else skip ; var cur : int := 0 ; cur := cur + hi_accum[hi_chosen - 1+1] ; if (lo_covered->compareTo((lo)->size())) < 0 then ( cur := cur + lo_accum[(lo)->size() - lo_covered - 1+1] ) else skip ; best := Set{best, cur}->max()) ; execute (best)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.buffer.readline def solution(): n,d,m=map(int,input().split()) a=list(map(int,input().split())) g=[] l=[] for i in range(n): if a[i]>m : g.append(a[i]) else : l.append(a[i]) g.sort(reverse=True) l.sort(reverse=True) if(g==[]): print(sum(l)) else : for i in range(1,len(l)): l[i]+=l[i-1] for i in range(1,len(g)): g[i]+=g[i-1] l=[0]+l k=len(g) x=l[-1] for i in range(k,10**5+6): g.append(0) for i in range(len(l),10**5+6): l.append(x) ans=0 for i in range((k+d)//(1+d),k+1): x=(i-1)*(d+1)+1 if x<=n : s=g[i-1]+l[n-x] ans=max(ans,s) print(ans) t=1 for _ in range(t): solution() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := sys.stdin.buffer.readline ; skip ; var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); operation solution() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; var m : OclAny := null; Sequence{n,d,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var g : Sequence := Sequence{} ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if (a[i+1]->compareTo(m)) > 0 then ( execute ((a[i+1]) : g) ) else ( execute ((a[i+1]) : l) )) ; g := g->sort() ; l := l->sort() ; if (g = Sequence{}) then ( execute ((l)->sum())->display() ) else ( for i : Integer.subrange(1, (l)->size()-1) do ( l[i+1] := l[i+1] + l[i - 1+1]) ; for i : Integer.subrange(1, (g)->size()-1) do ( g[i+1] := g[i+1] + g[i - 1+1]) ; l := Sequence{ 0 }->union(l) ; var k : int := (g)->size() ; var x : OclAny := l->last() ; for i : Integer.subrange(k, (10)->pow(5) + 6-1) do ( execute ((0) : g)) ; for i : Integer.subrange((l)->size(), (10)->pow(5) + 6-1) do ( execute ((x) : l)) ; var ans : int := 0 ; for i : Integer.subrange((k + d) div (1 + d), k + 1-1) do ( x := (i - 1) * (d + 1) + 1 ; if (x->compareTo(n)) <= 0 then ( var s : OclAny := g[i - 1+1] + l[n - x+1] ; ans := Set{ans, s}->max() ) else skip) ; execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate def chat(n,d,m,arr): lem=[] gtm=[] for x in arr : if x<=m : lem.append(x) else : gtm.append(x) lem.sort(reverse=True) gtm.sort(reverse=True) prel=[0]+list(accumulate(lem)) preg=[0]+list(accumulate(gtm)) ans=prel[-1] for k in range(1,min(len(gtm),(n-1)//(d+1)+1)+1): ans=max(ans,preg[k]+prel[min(n-(k-1)*d-k,len(lem))]) return ans n,d,m=map(int,input().split()) arr=list(map(int,input().split())) print(chat(n,d,m,arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{n,d,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; arr := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (chat(n, d, m, arr))->display(); operation chat(n : OclAny, d : OclAny, m : OclAny, arr : OclAny) : OclAny pre: true post: true activity: var lem : Sequence := Sequence{} ; var gtm : Sequence := Sequence{} ; for x : arr do ( if (x->compareTo(m)) <= 0 then ( execute ((x) : lem) ) else ( execute ((x) : gtm) )) ; lem := lem->sort() ; gtm := gtm->sort() ; var prel : Sequence := Sequence{ 0 }->union((accumulate(lem))) ; var preg : Sequence := Sequence{ 0 }->union((accumulate(gtm))) ; var ans : OclAny := prel->last() ; for k : Integer.subrange(1, Set{(gtm)->size(), (n - 1) div (d + 1) + 1}->min() + 1-1) do ( ans := Set{ans, preg[k+1] + prel[Set{n - (k - 1) * d - k, (lem)->size()}->min()+1]}->max()) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,d,m=map(int,input().split()) a=list(map(int,input().split())) b=[] c=[] for e in a : if e>m : b.append(e) else : c.append(e) b.sort(reverse=True) c.sort(reverse=True) bb=[] cc=[] tmp=0 for e in b : tmp+=e bb.append(tmp) tmp=0 for e in c : tmp+=e cc.append(tmp) big=len(b) if len(b)==0 : print(sum(a)) elif len(c)==0 : q=0 while n>0 : q+=1 n-=d+1 print(bb[q-1]) else : res=0 for i in range(big): if big-i-1<=i*d<=n-i-1 : de=i*d elif i*d<=big-i-1<=(i+1)*d : de=big-i-1 else : continue plus=de+i+1-big if 0<=n-big-1-pluscollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := Sequence{} ; var c : Sequence := Sequence{} ; for e : a do ( if (e->compareTo(m)) > 0 then ( execute ((e) : b) ) else ( execute ((e) : c) )) ; b := b->sort() ; c := c->sort() ; var bb : Sequence := Sequence{} ; var cc : Sequence := Sequence{} ; var tmp : int := 0 ; for e : b do ( tmp := tmp + e ; execute ((tmp) : bb)) ; tmp := 0 ; for e : c do ( tmp := tmp + e ; execute ((tmp) : cc)) ; var big : int := (b)->size() ; if (b)->size() = 0 then ( execute ((a)->sum())->display() ) else (if (c)->size() = 0 then ( var q : int := 0 ; while n > 0 do ( q := q + 1 ; n := n - d + 1) ; execute (bb[q - 1+1])->display() ) else ( var res : int := 0 ; for i : Integer.subrange(0, big-1) do ( if (big - i - 1->compareTo(i * d)) <= 0 & (i * d <= n - i - 1) then ( var de : double := i * d ) else (if (i * d->compareTo(big - i - 1)) <= 0 & (big - i - 1 <= (i + 1) * d) then ( de := big - i - 1 ) else ( continue ) ) ; var plus : double := de + i + 1 - big ; if 0 <= n - big - 1 - plus & (n - big - 1 - plus < (cc)->size()) then ( tmp := bb[i+1] + cc[n - big - 1 - plus+1] ) else ( tmp := bb[i+1] ) ; res := Set{res, tmp}->max()) ; execute (res)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=3 ; def rotateMatrix(mat): i=N-1 ; while(i>=0): j=N-1 ; while(j>=0): print(mat[i][j],end=" "); j=j-1 ; print(); i=i-1 ; mat=[[1,2,3],[4,5,6],[7,8,9]]; rotateMatrix(mat); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 3; ; skip ; mat := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))}->union(Sequence{ Sequence{7}->union(Sequence{8}->union(Sequence{ 9 })) })); ; rotateMatrix(mat);; operation rotateMatrix(mat : OclAny) pre: true post: true activity: var i : double := N - 1; ; while (i >= 0) do ( var j : double := N - 1; ; while (j >= 0) do ( execute (mat[i+1][j+1])->display(); ; j := j - 1;) ; execute (->display(); ; i := i - 1;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,d,m=list(map(int,input().split())) a=list(map(int,input().split())) small=[] big=[] for num in a : if num>m : big.append(num) else : small.append(num) big.sort() big.reverse() small.sort() small.reverse() ans=0 small=[0]+small big=[0]+big for i in range(1,len(small)): small[i]=small[i-1]+small[i] for i in range(1,len(big)): big[i]=big[i-1]+big[i] for i in range(len(small)): tmp=small[i] ind=((n-i-1)//(d+1))+1 ind=min(ind,len(big)-1) tmp+=big[ind] ans=max(ans,tmp) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var d : OclAny := null; var m : OclAny := null; Sequence{n,d,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var small : Sequence := Sequence{} ; var big : Sequence := Sequence{} ; for num : a do ( if (num->compareTo(m)) > 0 then ( execute ((num) : big) ) else ( execute ((num) : small) )) ; big := big->sort() ; big := big->reverse() ; small := small->sort() ; small := small->reverse() ; var ans : int := 0 ; small := Sequence{ 0 }->union(small) ; big := Sequence{ 0 }->union(big) ; for i : Integer.subrange(1, (small)->size()-1) do ( small[i+1] := small[i - 1+1] + small[i+1]) ; for i : Integer.subrange(1, (big)->size()-1) do ( big[i+1] := big[i - 1+1] + big[i+1]) ; for i : Integer.subrange(0, (small)->size()-1) do ( var tmp : OclAny := small[i+1] ; var ind : int := ((n - i - 1) div (d + 1)) + 1 ; ind := Set{ind, (big)->size() - 1}->min() ; tmp := tmp + big[ind+1] ; ans := Set{ans, tmp}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- OUT=0 IN=1 def countWords(string): state=OUT wc=0 for i in range(len(string)): if(string[i]==' ' or string[i]=='\n' or string[i]=='\t'): state=OUT elif state==OUT : state=IN wc+=1 return wc string="One two three\n four\tfive " print("No.of words : "+str(countWords(string))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var OUT : int := 0 ; var IN : int := 1 ; skip ; string := "One two three\n four\tfive " ; execute ("No.of words : " + ("" + ((countWords(string)))))->display(); operation countWords(string : OclAny) : OclAny pre: true post: true activity: var state : int := OUT ; var wc : int := 0 ; for i : Integer.subrange(0, (string)->size()-1) do ( if (string[i+1] = ' ' or string[i+1] = ' ' or string[i+1] = '\t') then ( state := OUT ) else (if state = OUT then ( state := IN ; wc := wc + 1 ) else skip)) ; return wc; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def parse(p,i): global sz node[i][2]+=1 del p[0] if p[0]!=',' : if node[i][0]==0 : node[i][0]=sz sz+=1 parse(p,node[i][0]) del p[0] if p[0]!=')' : if node[i][1]==0 : node[i][1]=sz sz+=1 parse(p,node[i][1]) del p[0] def act(i,k): global ans if node[i][2]0 : act(node[i][0],k) ans+=',' if node[i][1]>0 : act(node[i][1],k) ans+=')' while True : try : op,a,b=input().split() except : break sz=1 node=[[0 for j in range(3)]for i in range(210)] parse(list(a),0) parse(list(b),0) ans='' act(0,2 if op=='i' else 1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute sz : OclAny; attribute ans : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; while true do ( try ( var op : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{op,a,b} := input().split()) catch (_e : OclException) do ( break) ; sz := 1 ; var node : Sequence := Integer.subrange(0, 210-1)->select(i | true)->collect(i | (Integer.subrange(0, 3-1)->select(j | true)->collect(j | (0)))) ; parse((a), 0) ; parse((b), 0) ; ans := '' ; act(0, if op = 'i' then 2 else 1 endif) ; execute (ans)->display()); operation parse(p : OclAny, i : OclAny) pre: true post: true activity: skip ; node[i+1][2+1] := node[i+1][2+1] + 1 ; execute (p->first())->isDeleted() ; if p->first() /= ',' then ( if node[i+1]->first() = 0 then ( node[i+1]->first() := sz ; sz := sz + 1 ) else skip ; parse(p, node[i+1]->first()) ) else skip ; execute (p->first())->isDeleted() ; if p->first() /= ')' then ( if node[i+1][1+1] = 0 then ( node[i+1][1+1] := sz ; sz := sz + 1 ) else skip ; parse(p, node[i+1][1+1]) ) else skip ; execute (p->first())->isDeleted(); operation act(i : OclAny, k : OclAny) pre: true post: true activity: skip ; if (node[i+1][2+1]->compareTo(k)) < 0 then ( return ) else skip ; ans := ans + '(' ; if node[i+1]->first() > 0 then ( act(node[i+1]->first(), k) ) else skip ; ans := ans + ',' ; if node[i+1][1+1] > 0 then ( act(node[i+1][1+1], k) ) else skip ; ans := ans + ')'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math print(math.ceil(math.log(int(input()))/math.log(3))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (((("" + (((OclFile["System.in"]).readLine())))->toInteger())->log() / (3)->log())->ceil())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left,bisect_right from collections import Counter,defaultdict,deque,OrderedDict from copy import deepcopy from fractions import gcd from functools import lru_cache,reduce from math import ceil,floor from sys import setrecursionlimit import heapq import itertools import operator inf=float('inf') N=0 def set_inputs(): global N N=get_int() return def main(): setrecursionlimit(100000) set_inputs() for i in range(100): if 3**i>=N : print(i) return return def get_int(): return int(input()) def get_float(): return float(input()) def get_str(): return input().strip() def get_li(): return[int(i)for i in input().split()] def get_lf(): return[float(f)for f in input().split()] def get_lc(): return list(input().strip()) def get_data(n,types,sep=None): if len(types)==1 : return[types[0](input())for _ in range(n)] return list(zip(*([t(x)for t,x in zip(types,input().split(sep=sep))]for _ in range(n)))) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute N : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; var N : int := 0 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation set_inputs() pre: true post: true activity: skip ; N := get_int() ; return; operation main() pre: true post: true activity: setrecursionlimit(100000) ; set_inputs() ; for i : Integer.subrange(0, 100-1) do ( if ((3)->pow(i)->compareTo(N)) >= 0 then ( execute (i)->display() ; return ) else skip) ; return; operation get_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation get_float() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation get_str() : OclAny pre: true post: true activity: return input()->trim(); operation get_li() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation get_lf() : OclAny pre: true post: true activity: return input().split()->select(f | true)->collect(f | (("" + ((f)))->toReal())); operation get_lc() : OclAny pre: true post: true activity: return (input()->trim()); operation get_data(n : OclAny, types : OclAny, sep : OclAny) : OclAny pre: true post: true activity: if sep->oclIsUndefined() then sep := null else skip; if (types)->size() = 1 then ( return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (types->first()((OclFile["System.in"]).readLine()))) ) else skip ; return (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name t)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name t))) , (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name types))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sep)))))) = (test (logical_test (comparison (expr (atom (name sep)))))))) ))))))))) )))))))) ]))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name t)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name t))) , (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name types))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sep)))))) = (test (logical_test (comparison (expr (atom (name sep)))))))) ))))))))) )))))))) ]))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name t)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name t))) , (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name types))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sep)))))) = (test (logical_test (comparison (expr (atom (name sep)))))))) ))))))))) )))))))) ]))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) )))))))`third->at(_indx)} )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] while True : n=I() i=0 while n>1 : n=math.ceil(n/3) i+=1 rr.append(i) break return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var n : OclAny := I() ; var i : int := 0 ; while n > 1 do ( n := (n / 3)->ceil() ; i := i + 1) ; execute ((i) : rr) ; break) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) count=1 val=3 while(valtoInteger() ; var count : int := 1 ; var val : int := 3 ; while ((val->compareTo(x)) < 0) do ( val := val * 3 ; count := count + 1) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque import sys,heapq,bisect,math,itertools,string,queue,copy,time sys.setrecursionlimit(10**8) INF=float('inf') mod=10**9+7 eps=10**-7 def inp(): return int(input()) def inpl(): return list(map(int,input().split())) def inpl_str(): return list(input().split()) N=inp() if N<=3 : print(1) else : ans=1 while True : N=(N+2)//3 ans+=1 if N<=3 : break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var eps : double := (10)->pow(-7) ; skip ; skip ; skip ; var N : OclAny := inp() ; if N <= 3 then ( execute (1)->display() ) else ( var ans : int := 1 ; while true do ( N := (N + 2) div 3 ; ans := ans + 1 ; if N <= 3 then ( break ) else skip) ; execute (ans)->display() ); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inpl_str() : OclAny pre: true post: true activity: return (input().split()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def peakIndexInMountainArray(self,A): lo,hi=0,len(A)-1 while loexists( _x | result = _x ); operation peakIndexInMountainArray(A : OclAny) : OclAny pre: true post: true activity: var lo : OclAny := null; var hi : OclAny := null; Sequence{lo,hi} := Sequence{0,(A)->size() - 1} ; while (lo->compareTo(hi)) < 0 do ( var mid : double := (lo + hi) / 2 ; if (A[mid+1]->compareTo(A[mid + 1+1])) < 0 then ( var lo : OclAny := mid + 1 ) else ( var hi : OclAny := mid )) ; return lo; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkIsAP(arr,n): if(n==1): return True arr.sort() d=arr[1]-arr[0] for i in range(2,n): if(arr[i]-arr[i-1]!=d): return False return True arr=[20,15,5,0,10] n=len(arr) print("Yes")if(checkIsAP(arr,n))else print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{20}->union(Sequence{15}->union(Sequence{5}->union(Sequence{0}->union(Sequence{ 10 })))) ; n := (arr)->size() ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Yes"))))))) )))))) if (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name checkIsAP)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) ))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "No"))))))) )))))))); operation checkIsAP(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return true ) else skip ; arr := arr->sort() ; var d : double := arr[1+1] - arr->first() ; for i : Integer.subrange(2, n-1) do ( if (arr[i+1] - arr[i - 1+1] /= d) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 500==0 : print(n) else : print((n//500)*500) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 500 = 0 then ( execute (n)->display() ) else ( execute ((n div 500) * 500)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkIsAP(arr,n): if(n==1): return True arr.sort() d=arr[1]-arr[0] for i in range(2,n): if(arr[i]-arr[i-1]!=d): return False return True arr=[20,15,5,0,10] n=len(arr) print("Yes")if(checkIsAP(arr,n))else print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{20}->union(Sequence{15}->union(Sequence{5}->union(Sequence{0}->union(Sequence{ 10 })))) ; n := (arr)->size() ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Yes"))))))) )))))) if (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name checkIsAP)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) ))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "No"))))))) )))))))); operation checkIsAP(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return true ) else skip ; arr := arr->sort() ; var d : double := arr[1+1] - arr->first() ; for i : Integer.subrange(2, n-1) do ( if (arr[i+1] - arr[i - 1+1] /= d) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def areElementsContiguous(arr,n): arr.sort() for i in range(1,n): if(arr[i]-arr[i-1]>1): return 0 return 1 arr=[5,2,3,6,4,4,6,6] n=len(arr) if areElementsContiguous(arr,n): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{5}->union(Sequence{2}->union(Sequence{3}->union(Sequence{6}->union(Sequence{4}->union(Sequence{4}->union(Sequence{6}->union(Sequence{ 6 }))))))) ; n := (arr)->size() ; if areElementsContiguous(arr, n) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation areElementsContiguous(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; for i : Integer.subrange(1, n-1) do ( if (arr[i+1] - arr[i - 1+1] > 1) then ( return 0 ) else skip) ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,n=map(int,input().split()) mod=1000000007 res=1 while n>0 : if n & 1==1 : res=res*m % mod m=m*m % mod n>>=1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mod : int := 1000000007 ; var res : int := 1 ; while n > 0 do ( if MathLib.bitwiseAnd(n, 1) = 1 then ( res := res * m mod mod ) else skip ; var m : int := m * m mod mod ; n := n div (2->pow(1))) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ifPossible(arr,n): cp=[0]*n cp=arr cp.sort() for i in range(0,n): if(not(arr[i]==cp[i])and not(arr[n-1-i]==cp[i])): return False return True arr=[1,7,6,4,5,3,2,8] n=len(arr) if(ifPossible(arr,n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{7}->union(Sequence{6}->union(Sequence{4}->union(Sequence{5}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 8 }))))))) ; n := (arr)->size() ; if (ifPossible(arr, n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation ifPossible(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var cp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; cp := arr ; cp := cp->sort() ; for i : Integer.subrange(0, n-1) do ( if (not((arr[i+1] = cp[i+1])) & not((arr[n - 1 - i+1] = cp[i+1]))) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=int(input()) l=len(str(s)) ans=0 for i in range(2**(l-1)): su=str(s)[0] for j in range(l-1): if i &(1<0 : ans+=int(su) su=str(s)[j+1] else : su+=str(s)[j+1] ans+=int(su) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : int := (("" + ((s))))->size() ; var ans : int := 0 ; for i : Integer.subrange(0, (2)->pow((l - 1))-1) do ( var su : OclAny := OclType["String"](s)->first() ; for j : Integer.subrange(0, l - 1-1) do ( if MathLib.bitwiseAnd(i, (1 * (2->pow(j)))) > 0 then ( ans := ans + ("" + ((su)))->toInteger() ; su := OclType["String"](s)[j + 1+1] ) else ( su := su + OclType["String"](s)[j + 1+1] )) ; ans := ans + ("" + ((su)))->toInteger()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import product S=tuple(input()) N=len(S) res=0 for ops in product(["+",""],repeat=N-1): exp="".join([n+op for n,op in zip(S,ops+("",))]).strip("+") res+=eval(exp) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var S : Sequence := ((OclFile["System.in"]).readLine()) ; var N : int := (S)->size() ; var res : int := 0 ; for ops : product(Sequence{"+"}->union(Sequence{ "" }), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (expr (atom (name N))) - (expr (atom (number (integer 1)))))))))) do ( var exp : OclAny := "".join(Integer.subrange(1, S->size())->collect( _indx | Sequence{S->at(_indx), ops + Sequence{(testlist_comp (test (logical_test (comparison (expr (atom ""))))) ,)}->at(_indx)} )->select(_tuple | true)->collect(_tuple | let n : OclAny = _tuple->at(1) in let op : OclAny = _tuple->at(2) in (n + op)))->trim() ; res := res + exp) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(S): from itertools import combinations from collections import deque n=len(S) answer=0 for i in range(n): for item in combinations(list(range(1,n,1)),i): char_list=[c for c in S] que=deque(item) while que : index=que.pop() char_list.insert(index,"") split_s="" for c in char_list : split_s+=c answer+=sum(map(int,split_s.split())) return answer def main(): S=input() print(solve(S)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation solve(S : OclAny) : OclAny pre: true post: true activity: skip ; skip ; var n : int := (S)->size() ; var answer : int := 0 ; for i : Integer.subrange(0, n-1) do ( for item : combinations((Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 1 = 0 )), i) do ( var char_list : Sequence := S->select(c | true)->collect(c | (c)) ; var que : Sequence := (item) ; while que do ( var index : OclAny := que->last() ; que := que->front() ; char_list := char_list.insertAt(index+1, "")) ; var split_s : String := "" ; for c : char_list do ( split_s := split_s + c) ; answer := answer + ((split_s.split())->collect( _x | (OclType["int"])->apply(_x) ))->sum())) ; return answer; operation main() pre: true post: true activity: S := (OclFile["System.in"]).readLine() ; execute (solve(S))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import bisect from statistics import* from collections import* from operator import itemgetter stdin=sys.stdin ni=lambda : int(ns()) na=lambda : list(map(int,stdin.readline().split())) ns=lambda : stdin.readline() s=input() li=[int(x)for x in s] l=len(s) ans=0 if l==1 : print(li[0]) else : for i in range(1<<(l-1)): k=li[0] ct=0 for j in range(l-1): if i>>j & 1 : ct+=k k=li[j+1] else : k=k*10+li[j+1] if j==l-2 : ct+=k ans+=ct print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var stdin : OclFile := OclFile["System.in"] ; var ni : Function := lambda $$ : OclAny in (("" + ((ns())))->toInteger()) ; var na : Function := lambda $$ : OclAny in (((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var ns : Function := lambda $$ : OclAny in (stdin.readLine()) ; var s : String := (OclFile["System.in"]).readLine() ; var li : Sequence := s->characters()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var l : int := (s)->size() ; var ans : int := 0 ; if l = 1 then ( execute (li->first())->display() ) else ( for i : Integer.subrange(0, 1 * (2->pow((l - 1)))-1) do ( var k : OclAny := li->first() ; var ct : int := 0 ; for j : Integer.subrange(0, l - 1-1) do ( if MathLib.bitwiseAnd(i /(2->pow(j)), 1) then ( ct := ct + k ; k := li[j + 1+1] ) else ( k := k * 10 + li[j + 1+1] ) ; if j = l - 2 then ( ct := ct + k ; ans := ans + ct ) else skip)) ; execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() def cal_sum(s,is_plus): s_idx=0 result=0 for p_idx,p in enumerate(is_plus): if p=='1' : result+=int(s[s_idx : p_idx+1]) s_idx=p_idx+1 result+=int(s[s_idx :]) return result res=0 for i in range(2**(len(s)-1)): is_plus='{i:0={width}b}'.format(i=i,width=len(s)-1) res+=cal_sum(s,is_plus) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; skip ; var res : int := 0 ; for i : Integer.subrange(0, (2)->pow(((s)->size() - 1))-1) do ( is_plus := StringLib.interpolateStrings('{i:0={width}b}', Sequence{(argument (test (logical_test (comparison (expr (atom (name i)))))) = (test (logical_test (comparison (expr (atom (name i))))))), (argument (test (logical_test (comparison (expr (atom (name width)))))) = (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))) - (expr (atom (number (integer 1)))))))))}) ; res := res + cal_sum(s, is_plus)) ; execute (res)->display(); operation cal_sum(s : OclAny, is_plus : OclAny) : OclAny pre: true post: true activity: var s_idx : int := 0 ; var result : int := 0 ; for _tuple : Integer.subrange(1, (is_plus)->size())->collect( _indx | Sequence{_indx-1, (is_plus)->at(_indx)} ) do (var _indx : int := 1; var p_idx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p : OclAny := _tuple->at(_indx); if p = '1' then ( result := result + ("" + ((s.subrange(s_idx+1, p_idx + 1))))->toInteger() ; s_idx := p_idx + 1 ) else skip) ; result := result + ("" + ((s.subrange(s_idx+1))))->toInteger() ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bsearch(prefixsum,n,k): ans,left,right=-1,1,n while(left<=right): mid=(left+right)//2 for i in range(mid,n+1): if(prefixsum[i]-prefixsum[i-mid]>k): i=i-1 break i=i+1 if(i==n+1): left=mid+1 ans=mid else : right=mid-1 return ans ; def maxSize(arr,n,k): prefixsum=[0 for x in range(n+1)] for i in range(n): prefixsum[i+1]=prefixsum[i]+arr[i] return bsearch(prefixsum,n,k); arr=[1,2,10,4] n=len(arr) k=14 print(maxSize(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{10}->union(Sequence{ 4 }))) ; n := (arr)->size() ; k := 14 ; execute (maxSize(arr, n, k))->display(); operation bsearch(prefixsum : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var ans : OclAny := null; var left : OclAny := null; var right : OclAny := null; Sequence{ans,left,right} := Sequence{-1,1,n} ; while ((left->compareTo(right)) <= 0) do ( var mid : int := (left + right) div 2 ; for i : Integer.subrange(mid, n + 1-1) do ( if ((prefixsum[i+1] - prefixsum[i - mid+1]->compareTo(k)) > 0) then ( var i : double := i - 1 ; break ) else skip) ; i := i + 1 ; if (i = n + 1) then ( var left : int := mid + 1 ; var ans : int := mid ) else ( var right : double := mid - 1 )) ; return ans;; operation maxSize(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: prefixsum := Integer.subrange(0, n + 1-1)->select(x | true)->collect(x | (0)) ; for i : Integer.subrange(0, n-1) do ( prefixsum[i + 1+1] := prefixsum[i+1] + arr[i+1]) ; return bsearch(prefixsum, n, k);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(int(int(input())//500*500)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (("" + ((("" + (((OclFile["System.in"]).readLine())))->toInteger() div 500 * 500)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count_pairs(n,a): frequency=dict.fromkeys(a,0) for i in range(n): frequency[a[i]]+=1 count=0 for f in frequency.values(): count+=f*(f-1)//2 return((n*(n-1))//2)-count if __name__=="__main__" : arr=[2,4,5,2,5,7,2,8] n=len(arr) print(count_pairs(n,arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var arr : Sequence := Sequence{2}->union(Sequence{4}->union(Sequence{5}->union(Sequence{2}->union(Sequence{5}->union(Sequence{7}->union(Sequence{2}->union(Sequence{ 8 }))))))) ; n := (arr)->size() ; execute (count_pairs(n, arr))->display() ) else skip; operation count_pairs(n : OclAny, a : OclAny) : OclAny pre: true post: true activity: var frequency : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))) ; for i : Integer.subrange(0, n-1) do ( frequency[a[i+1]+1] := frequency[a[i+1]+1] + 1) ; var count : int := 0 ; for f : frequency.values() do ( count := count + f * (f - 1) div 2) ; return ((n * (n - 1)) div 2) - count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from random import randint T=int(input()) out=[] for i in range(T): flag=0 x=int(input()) for i in range(10000): a=randint(0,x//3) b=randint(0,x//3) if 3*a+7*b==x and a>=0 and b>=0 : flag=1 break if flag==1 and a>=0 and b>=0 : out.append('YES') else : out.append('NO') for i in range(T): print(out[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var out : Sequence := Sequence{} ; for i : Integer.subrange(0, T-1) do ( var flag : int := 0 ; var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, 10000-1) do ( var a : OclAny := randint(0, x div 3) ; var b : OclAny := randint(0, x div 3) ; if 3 * a + 7 * b = x & a >= 0 & b >= 0 then ( flag := 1 ; break ) else skip) ; if flag = 1 & a >= 0 & b >= 0 then ( execute (('YES') : out) ) else ( execute (('NO') : out) )) ; for i : Integer.subrange(0, T-1) do ( execute (out[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CFK(m): if(m % 3==0)or(m % 7==0): ans=1 return ans elif m<7 : ans=0 return ans elif m>7 : return CFK(m-7) a=[] n=int(input()) for i in range(n): a.append(int(input())) if CFK(a[i]): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : Sequence := Sequence{} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : a) ; if CFK(a[i+1]) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); operation CFK(m : OclAny) : OclAny pre: true post: true activity: if (m mod 3 = 0) or (m mod 7 = 0) then ( var ans : int := 1 ; return ans ) else (if m < 7 then ( ans := 0 ; return ans ) else (if m > 7 then ( return CFK(m - 7) ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=10**9+7 m,n=map(int,input().split()) print(pow(m,n,MOD)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : double := (10)->pow(9) + 7 ; var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((m)->pow(n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): x=int(input()) f=0 for j in range(34): if f==1 : break for k in range(15): if 3*j+7*k==x : print("YES") f=1 break if f==0 : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var f : int := 0 ; for j : Integer.subrange(0, 34-1) do ( if f = 1 then ( break ) else skip ; for k : Integer.subrange(0, 15-1) do ( if 3 * j + 7 * k = x then ( execute ("YES")->display() ; f := 1 ; break ) else skip)) ; if f = 0 then ( execute ("NO")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): x=int(input()) if(((((x==1 or x==2)or x==4)or x==5)or x==8)or x==11): print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (((((x = 1 or x = 2) or x = 4) or x = 5) or x = 8) or x = 11) then ( execute ("NO")->display() ) else ( execute ("YES")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(x): if x % 3==0 or x % 7==0 or x % 10==0 : return 'YES' for i in range(101): for j in range(101): if 3*i+7*j==x : return 'YES' return 'NO' for _ in range(int(input())): n=int(input()) print(solve(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (solve(n))->display()); operation solve(x : OclAny) : OclAny pre: true post: true activity: if x mod 3 = 0 or x mod 7 = 0 or x mod 10 = 0 then ( return 'YES' ) else skip ; for i : Integer.subrange(0, 101-1) do ( for j : Integer.subrange(0, 101-1) do ( if 3 * i + 7 * j = x then ( return 'YES' ) else skip)) ; return 'NO'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- result="YES" n,m=map(int,input().split()) before="" for i in range(n): s=input() c=s[0 : 1] if m!=s.count(c): result="No" break if i==0 : before=c continue if c==before : result="No" break before=c print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var result : String := "YES" ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var before : String := "" ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var c : OclAny := s.subrange(0+1, 1) ; if m /= s->count(c) then ( result := "No" ; break ) else skip ; if i = 0 then ( before := c ; continue ) else skip ; if c = before then ( result := "No" ; break ) else skip ; before := c) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,n=map(int,input().split()) def flag(): result=m prev=10 for x in range(m): row=input() for a in row : if a!=row[0]: print("NO") result=m return if row==prev : print("NO") break else : result-=1 prev=row if result==0 : print("YES") flag() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; flag(); operation flag() pre: true post: true activity: var result : OclAny := m ; var prev : int := 10 ; for x : Integer.subrange(0, m-1) do ( var row : String := (OclFile["System.in"]).readLine() ; for a : row->characters() do ( if a /= row->first() then ( execute ("NO")->display() ; result := m ; return ) else skip) ; if row = prev then ( execute ("NO")->display() ; break ) else ( result := result - 1 ) ; prev := row) ; if result = 0 then ( execute ("YES")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,n=map(int,input().split()) def flag(): result=m prev=10 for x in range(m): row=input() a=sorted(row) if a[0]!=a[-1]: print("NO") result=m return if row==prev : print("NO") break else : result-=1 prev=row if result==0 : print("YES") flag() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; flag(); operation flag() pre: true post: true activity: var result : OclAny := m ; var prev : int := 10 ; for x : Integer.subrange(0, m-1) do ( var row : String := (OclFile["System.in"]).readLine() ; var a : Sequence := row->sort() ; if a->first() /= a->last() then ( execute ("NO")->display() ; result := m ; return ) else skip ; if row = prev then ( execute ("NO")->display() ; break ) else ( result := result - 1 ) ; prev := row) ; if result = 0 then ( execute ("YES")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p=int(input()) sum=0 if p>=10000 : sum+=p//10000*10000 p-=p//10000*10000 if p>=5000 : sum+=p//5000*5000 p-=p//5000*5000 if p>=1000 : sum+=p//1000*1000 p-=p//1000*1000 if p>=500 : sum+=p//500*500 p-=p//500*500 print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sum : int := 0 ; if p >= 10000 then ( sum := sum + p div 10000 * 10000 ; p := p - p div 10000 * 10000 ) else skip ; if p >= 5000 then ( sum := sum + p div 5000 * 5000 ; p := p - p div 5000 * 5000 ) else skip ; if p >= 1000 then ( sum := sum + p div 1000 * 1000 ; p := p - p div 1000 * 1000 ) else skip ; if p >= 500 then ( sum := sum + p div 500 * 500 ; p := p - p div 500 * 500 ) else skip ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) f=[] x=0 for i in range(n): h=input() if len(set(h))>1 : x+=1 if f : if h==f[-1]: x+=1 f.append(h) if x==0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var f : Sequence := Sequence{} ; var x : int := 0 ; for i : Integer.subrange(0, n-1) do ( var h : String := (OclFile["System.in"]).readLine() ; if (Set{}->union((h)))->size() > 1 then ( x := x + 1 ) else skip ; if f then ( if h = f->last() then ( x := x + 1 ) else skip ) else skip ; execute ((h) : f)) ; if x = 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) strips=[] for i in range(n): colors=input() strips.append(colors) bval=True mark=int('1'*m) for j in range(n-1): if int(strips[j])% mark!=0 or strips[j]==strips[j+1]: bval=False break else : pass if int(strips[-1])% mark==0 : pass else : bval=False if bval==True : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var strips : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var colors : String := (OclFile["System.in"]).readLine() ; execute ((colors) : strips)) ; var bval : boolean := true ; var mark : int := ("" + ((StringLib.nCopies('1', m))))->toInteger() ; for j : Integer.subrange(0, n - 1-1) do ( if ("" + ((strips[j+1])))->toInteger() mod mark /= 0 or strips[j+1] = strips[j + 1+1] then ( bval := false ; break ) else ( skip )) ; if ("" + ((strips->last())))->toInteger() mod mark = 0 then ( skip ) else ( bval := false ) ; if bval = true then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=map(int,input().split()) c=list(map(int,input().split())) d=c[: :-1] ans=0 if n % 2 : if c[n//2]==2 : ans=min(a,b) for i in range(n//2): t=(c[i],d[i]) if 1 in t : if 2 in t : ans+=b continue if 0 in t : if 2 in t : ans+=a continue if t==(2,2): ans+=2*min(a,b) elif c[i]==d[i]: continue else : ans=-1 break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := c(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var ans : int := 0 ; if n mod 2 then ( if c[n div 2+1] = 2 then ( ans := Set{a, b}->min() ) else skip ) else skip ; for i : Integer.subrange(0, n div 2-1) do ( var t : OclAny := Sequence{c[i+1], d[i+1]} ; if (t)->includes(1) then ( if (t)->includes(2) then ( ans := ans + b ; continue ) else skip ) else skip ; if (t)->includes(0) then ( if (t)->includes(2) then ( ans := ans + a ; continue ) else skip ) else skip ; if t = Sequence{2, 2} then ( ans := ans + 2 * Set{a, b}->min() ) else (if c[i+1] = d[i+1] then ( continue ) else ( ans := -1 ; break ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys rd=sys.stdin.readline n,a,b=map(int,rd().split()) c=list(map(int,rd().split())) res=0 for i in range(n//2): t=(c[i],c[n-1-i]) if 1 in t : if 2 in t : res+=b elif 0 in t : print(-1) break else : continue elif 0 in t : if 2 in t : res+=a elif 1 in t : print(-1) break else : continue else : res+=2*min(a,b) else : if n % 2==0 : print(res) else : if c[n//2]==2 : print(res+min(a,b)) else : print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var rd : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (rd().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : Sequence := ((rd().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : int := 0 ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) // (expr (atom (number (integer 2)))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name t)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))) , (test (logical_test (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name n))) - (expr (atom (number (integer 1))))) - (expr (atom (name i))))))))) ]))))))) )))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (number (integer 1))))) in (comparison (expr (atom (name t))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (number (integer 2))))) in (comparison (expr (atom (name t))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name res)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name b)))))))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (number (integer 0))))) in (comparison (expr (atom (name t))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt continue)))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (number (integer 0))))) in (comparison (expr (atom (name t))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (number (integer 2))))) in (comparison (expr (atom (name t))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name res)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name a)))))))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (number (integer 1))))) in (comparison (expr (atom (name t))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt continue))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name res)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))))))))))))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name n))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name res)))))))) ))))))))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name n))) // (expr (atom (number (integer 2)))))))))) ])))) == (comparison (expr (atom (number (integer 2)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name res))) + (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name res)))))))) ))))))))))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,n=(int(i)for i in input().split()) m2=1 while n>0 : m1=m l=1 while l*2<=n : m1*=m1 if m1>1000000007 : m1 %=1000000007 l*=2 n-=l m2*=m1 if m2>1000000007 : m2 %=1000000007 print(m2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var m2 : int := 1 ; while n > 0 do ( var m1 : OclAny := m ; var l : int := 1 ; while (l * 2->compareTo(n)) <= 0 do ( m1 := m1 * m1 ; if m1 > 1000000007 then ( m1 := m1 mod 1000000007 ) else skip ; l := l * 2) ; n := n - l ; m2 := m2 * m1 ; if m2 > 1000000007 then ( m2 := m2 mod 1000000007 ) else skip) ; execute (m2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from re import L import sys,bisect from collections import deque,OrderedDict,defaultdict import heapq from collections import Counter import copy def inp(): return sys.stdin.readline().rstrip() def mpp(): return map(int,inp().split()) def lis(): return list(mpp()) def yn(n): if n : return "YES" else : return "NO" def fn(arr,a,b): i=0 di={0 : a,1 : b} j=len(arr)-1 cost=0 while i<=j : if arr[i]!=2 and arr[j]!=2 : if arr[i]!=arr[j]: return-1 elif arr[i]==2 and arr[j]==2 : cost+=min(a,b)if i==j else 2*(min(a,b)) elif arr[i]==2 : cost+=di[arr[j]] else : cost+=di[arr[i]] i+=1 j-=1 return cost def main(): n,a,b=mpp() arr=lis() print(fn(arr,a,b)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation inp() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation mpp() : OclAny pre: true post: true activity: return (inp().split())->collect( _x | (OclType["int"])->apply(_x) ); operation lis() : OclAny pre: true post: true activity: return (mpp()); operation yn(n : OclAny) : OclAny pre: true post: true activity: if n then ( return "YES" ) else ( return "NO" ); operation fn(arr : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; var di : Map := Map{ 0 |-> a }->union(Map{ 1 |-> b }) ; var j : double := (arr)->size() - 1 ; var cost : int := 0 ; while (i->compareTo(j)) <= 0 do ( if arr[i+1] /= 2 & arr[j+1] /= 2 then ( if arr[i+1] /= arr[j+1] then ( return -1 ) else skip ) else (if arr[i+1] = 2 & arr[j+1] = 2 then ( cost := cost + if i = j then Set{a, b}->min() else 2 * (Set{a, b}->min()) endif ) else (if arr[i+1] = 2 then ( cost := cost + di[arr[j+1]+1] ) else ( cost := cost + di[arr[i+1]+1] ) ) ) ; i := i + 1 ; j := j - 1) ; return cost; operation main() pre: true post: true activity: Sequence{n,a,b} := mpp() ; arr := lis() ; execute (fn(arr, a, b))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=map(int,input().split()) l=list(map(int,input().split())) sum=0 costs={0 : a,1 : b} for i in range(len(l)//2 if len(l)% 2==0 else(len(l)//2)+1): if l[i]==l[-(i+1)]and l[i]!=2 : continue elif l[i]==l[-(i+1)]and l[i]==2 and(i==len(l)-(i+1)): sum+=min(a,b) elif l[i]==l[-(i+1)]and l[i]==2 : sum+=2*min(a,b) elif l[i]==2 or l[-(i+1)]==2 : if l[i]==2 : sum+=costs[l[-(i+1)]] else : sum+=costs[l[i]] else : print(-1) exit() print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sum : int := 0 ; var costs : Map := Map{ 0 |-> a }->union(Map{ 1 |-> b }) ; for i : Integer.subrange(0, if (l)->size() mod 2 = 0 then (l)->size() div 2 else ((l)->size() div 2) + 1 endif-1) do ( if l[i+1] = l->reverse()->at(-(-(i + 1))) & l[i+1] /= 2 then ( continue ) else (if l[i+1] = l->reverse()->at(-(-(i + 1))) & l[i+1] = 2 & (i = (l)->size() - (i + 1)) then ( sum := sum + Set{a, b}->min() ) else (if l[i+1] = l->reverse()->at(-(-(i + 1))) & l[i+1] = 2 then ( sum := sum + 2 * Set{a, b}->min() ) else (if l[i+1] = 2 or l->reverse()->at(-(-(i + 1))) = 2 then ( if l[i+1] = 2 then ( sum := sum + costs[l->reverse()->at(-(-(i + 1)))+1] ) else ( sum := sum + costs[l[i+1]+1] ) ) else ( execute (-1)->display() ; exit() ) ) ) ) ) ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,a,b=map(int,input().split()) c=list(map(int,input().split())) ans=0 for i in range(n//2): u,v=c[i],c[-i-1] if u==v==2 : ans+=2*min(a,b) elif max(u,v)==2 : ans+=b if min(u,v)else a elif u ^ v : ans=-1 break if n % 2 and c[n//2]==2 and ans ^-1 : ans+=min(a,b) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(0, n div 2-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := Sequence{c[i+1],c->reverse()->at(-(-i - 1))} ; if u = v & (v == 2) then ( ans := ans + 2 * Set{a, b}->min() ) else (if Set{u, v}->max() = 2 then ( ans := ans + if Set{u, v}->min() then b else a endif ) else (if MathLib.bitwiseXor(u, v) then ( ans := -1 ; break ) else skip ) ) ) ; if n mod 2 & c[n div 2+1] = 2 & MathLib.bitwiseXor(ans, -1) then ( ans := ans + Set{a, b}->min() ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minCost(cost,n): totalCost=0 boardingBus=0 for i in range(1,n): if(cost[boardingBus]>cost[i]): totalCost+=((i-boardingBus)*cost[boardingBus]) boardingBus=i totalCost+=((n-boardingBus)*cost[boardingBus]) return totalCost cost=[4,7,8,3,4] n=len(cost) print(minCost(cost,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; cost := Sequence{4}->union(Sequence{7}->union(Sequence{8}->union(Sequence{3}->union(Sequence{ 4 })))) ; n := (cost)->size() ; execute (minCost(cost, n))->display(); operation minCost(cost : OclAny, n : OclAny) : OclAny pre: true post: true activity: var totalCost : int := 0 ; var boardingBus : int := 0 ; for i : Integer.subrange(1, n-1) do ( if ((cost[boardingBus+1]->compareTo(cost[i+1])) > 0) then ( totalCost := totalCost + ((i - boardingBus) * cost[boardingBus+1]) ; boardingBus := i ) else skip) ; totalCost := totalCost + ((n - boardingBus) * cost[boardingBus+1]) ; return totalCost; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxSum(arr,n): sum=0 pivot=findPivot(arr,n) diff=n-1-pivot for i in range(n): sum=sum+((i+diff)% n)*arr[i]; return sum def findPivot(arr,n): for i in range(n): if(arr[i]>arr[(i+1)% n]): return i ; if __name__=="__main__" : arr=[8,3,1,2] n=len(arr) max=maxSum(arr,n) print(max) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{8}->union(Sequence{3}->union(Sequence{1}->union(Sequence{ 2 }))) ; n := (arr)->size() ; var max : OclAny := maxSum(arr, n) ; execute (max)->display() ) else skip; operation maxSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; var pivot : OclAny := findPivot(arr, n) ; var diff : double := n - 1 - pivot ; for i : Integer.subrange(0, n-1) do ( sum := sum + ((i + diff) mod n) * arr[i+1];) ; return sum; operation findPivot(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if ((arr[i+1]->compareTo(arr[(i + 1) mod n+1])) > 0) then ( return i; ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=0 l=[10000,5000,1000,500] for i in range(4): ans+=(n//l[i])*l[i] n=n % l[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; var l : Sequence := Sequence{10000}->union(Sequence{5000}->union(Sequence{1000}->union(Sequence{ 500 }))) ; for i : Integer.subrange(0, 4-1) do ( ans := ans + (n div l[i+1]) * l[i+1] ; n := n mod l[i+1]) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): n=2**1000 ans=sum(int(c)for c in str(n)) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var n : double := (2)->pow(1000) ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->sum() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque q=int(input()) S=deque() for i in range(q): query=list(map(int,input().split())) if query[0]==0 : if query[1]==0 : S.appendleft(query[2]) elif query[1]==1 : S.append(query[2]) elif query[0]==1 : print("{}".format(S[query[1]])) elif query[0]==2 : if query[1]==0 : S.popleft() elif query[1]==1 : S.pop() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : Sequence := () ; for i : Integer.subrange(0, q-1) do ( var query : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if query->first() = 0 then ( if query[1+1] = 0 then ( S := S->prepend(query[2+1]) ) else (if query[1+1] = 1 then ( execute ((query[2+1]) : S) ) else skip) ) else (if query->first() = 1 then ( execute (StringLib.interpolateStrings("{}", Sequence{S[query[1+1]+1]}))->display() ) else (if query->first() = 2 then ( if query[1+1] = 0 then ( S := S->tail() ) else (if query[1+1] = 1 then ( S := S->front() ) else skip) ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque import sys n=int(input()) A=deque([]) for i in range(n): S=input() if S[0]=='0' : if S[2]=='0' : A.appendleft(S[4 :]) elif S[2]=='1' : A.append(S[4 :]) elif S[0]=='1' : print(A[int(S[2 :])]) elif S[0]=='2' : if S[2]=='0' : A.popleft() if S[2]=='1' : A.pop() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := (Sequence{}) ; for i : Integer.subrange(0, n-1) do ( var S : String := (OclFile["System.in"]).readLine() ; if S->first() = '0' then ( if S[2+1] = '0' then ( A := A->prepend(S.subrange(4+1)) ) else (if S[2+1] = '1' then ( execute ((S.subrange(4+1)) : A) ) else skip) ) else (if S->first() = '1' then ( execute (A[("" + ((S.subrange(2+1))))->toInteger()+1])->display() ) else (if S->first() = '2' then ( if S[2+1] = '0' then ( A := A->tail() ) else skip ; if S[2+1] = '1' then ( A := A->front() ) else skip ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import deque A=deque() Q=int(sys.stdin.readline().rstrip()) for _ in range(Q): s=sys.stdin.readline().rstrip().split() if s[0]=="0" : if s[1]=="0" : A.appendleft(s[2]) else : A.append(s[2]) elif s[0]=="1" : print(A[int(s[1])]) else : if s[1]=="0" : A.popleft() else : A.pop() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var A : Sequence := () ; var Q : int := ("" + ((sys.stdin.readLine().rstrip())))->toInteger() ; for _anon : Integer.subrange(0, Q-1) do ( var s : OclAny := sys.stdin.readLine().rstrip().split() ; if s->first() = "0" then ( if s[1+1] = "0" then ( A := A->prepend(s[2+1]) ) else ( execute ((s[2+1]) : A) ) ) else (if s->first() = "1" then ( execute (A[("" + ((s[1+1])))->toInteger()+1])->display() ) else ( if s[1+1] = "0" then ( A := A->tail() ) else ( A := A->front() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import deque nq=int(input()) lines=sys.stdin.readlines() deq=deque() for i in range(nq): query,*arg=lines[i].split() if query=='0' : deq.appendleft(arg[1])if arg[0]=='0' else deq.append(arg[1]) elif query=='1' : print(deq[int(arg[0])]) elif query=='2' : deq.popleft()if arg[0]=='0' else deq.pop() else : raise AssertionError ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var nq : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lines : OclAny := (OclFile["System.in"]).readlines() ; var deq : Sequence := () ; for i : Integer.subrange(0, nq-1) do ( var query : OclAny := null; var arg : OclAny := null; Sequence{query,arg} := lines[i+1].split() ; if query = '0' then ( (test (logical_test (comparison (expr (atom (name deq)) (trailer . (name appendleft) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arg)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))))) if (logical_test (comparison (comparison (expr (atom (name arg)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) == (comparison (expr (atom '0'))))) else (test (logical_test (comparison (expr (atom (name deq)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arg)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))))))) ) else (if query = '1' then ( execute (deq[("" + ((arg->first())))->toInteger()+1])->display() ) else (if query = '2' then ( (test (logical_test (comparison (expr (atom (name deq)) (trailer . (name popleft) (arguments ( )))))) if (logical_test (comparison (comparison (expr (atom (name arg)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) == (comparison (expr (atom '0'))))) else (test (logical_test (comparison (expr (atom (name deq)) (trailer . (name pop) (arguments ( )))))))) ) else ( error AssertionException.newAssertionException ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() if(n=="0")or(n=="1"): print(0) elif(n[0]=='1')and(n[1 :]=='0'*(len(n)-1)): print((len(n))//2) else : print(((len(n)-1)//2)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; if (n = "0") or (n = "1") then ( execute (0)->display() ) else (if (n->first() = '1') & (n->tail() = StringLib.nCopies('0', ((n)->size() - 1))) then ( execute (((n)->size()) div 2)->display() ) else ( execute ((((n)->size() - 1) div 2) + 1)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- number=int(input()) if 1<=number and number<=50 : string_of_numbers=input().split()[: number] frequency_array={} list_of_numbers=[int(num)for num in string_of_numbers] final_numbers="" for index,value in enumerate(list_of_numbers): if value in frequency_array : if index>frequency_array[value]: frequency_array[value]=index else : frequency_array[value]=index unique_indexes=sorted(frequency_array.values()) for item in unique_indexes : final_numbers+=""+str(list_of_numbers[item])+" " print(len(unique_indexes)) print(final_numbers) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var number : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if 1 <= number & number <= 50 then ( var string_of_numbers : OclAny := input().split().subrange(1,number) ; var frequency_array : OclAny := Set{} ; var list_of_numbers : Sequence := string_of_numbers->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var final_numbers : String := "" ; for _tuple : Integer.subrange(1, (list_of_numbers)->size())->collect( _indx | Sequence{_indx-1, (list_of_numbers)->at(_indx)} ) do (var _indx : int := 1; var index : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); if (frequency_array)->includes(value) then ( if (index->compareTo(frequency_array[value+1])) > 0 then ( frequency_array[value+1] := index ) else skip ) else ( frequency_array[value+1] := index )) ; var unique_indexes : Sequence := frequency_array.values()->sort() ; for item : unique_indexes do ( final_numbers := final_numbers + "" + ("" + ((list_of_numbers[item+1]))) + " ") ; execute ((unique_indexes)->size())->display() ; execute (final_numbers)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=1e9+7 mod=int(mod) def pow(a,b): if(b==0): return 1 temp=pow(a,b//2)% mod temp=(temp**2)% mod if b % 2==0 : return temp % mod else : return(temp*a)% mod a,b=map(int,input().split()) print(pow(a,b)% mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : double := ("1e9")->toReal() + 7 ; mod := ("" + ((mod)))->toInteger() ; skip ; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a)->pow(b) mod mod)->display(); operation pow(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (b = 0) then ( return 1 ) else skip ; var temp : int := (a)->pow(b div 2) mod mod ; temp := ((temp)->pow(2)) mod mod ; if b mod 2 = 0 then ( return temp mod mod ) else ( return (temp * a) mod mod ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def main(): n=int(input()) deq=deque() for i in range(n): query=input() if(query[0]=='0'): vals=query.split(" ") d=int(vals[1]) elem=int(vals[2]) if d==0 : deq.appendleft(elem) else : deq.append(elem) elif(query[0]=='1'): vals=query.split(" ") idx=int(vals[1]) print(deq[idx]) elif(query[0]=='2'): vals=query.split(" ") d=int(vals[1]) if d==0 : deq.popleft() else : deq.pop() if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var deq : Sequence := () ; for i : Integer.subrange(0, n-1) do ( var query : String := (OclFile["System.in"]).readLine() ; if (query->first() = '0') then ( var vals : OclAny := query.split(" ") ; var d : int := ("" + ((vals[1+1])))->toInteger() ; var elem : int := ("" + ((vals[2+1])))->toInteger() ; if d = 0 then ( deq := deq->prepend(elem) ) else ( execute ((elem) : deq) ) ) else (if (query->first() = '1') then ( vals := query.split(" ") ; var idx : int := ("" + ((vals[1+1])))->toInteger() ; execute (deq[idx+1])->display() ) else (if (query->first() = '2') then ( vals := query.split(" ") ; d := ("" + ((vals[1+1])))->toInteger() ; if d = 0 then ( deq := deq->tail() ) else ( deq := deq->front() ) ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def maximumSumSubarray(arr,n): min_prefix_sum=0 res=-math.inf prefix_sum=[] prefix_sum.append(arr[0]) for i in range(1,n): prefix_sum.append(prefix_sum[i-1]+arr[i]) for i in range(n): res=max(res,prefix_sum[i]-min_prefix_sum) min_prefix_sum=min(min_prefix_sum,prefix_sum[i]) return res arr1=[-2,-3,4,-1,-2,1,5,-3] n1=len(arr1) print(maximumSumSubarray(arr1,n1)) arr2=[4,-8,9,-4,1,-8,-1,6] n2=len(arr2) print(maximumSumSubarray(arr2,n2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var arr1 : Sequence := Sequence{-2}->union(Sequence{-3}->union(Sequence{4}->union(Sequence{-1}->union(Sequence{-2}->union(Sequence{1}->union(Sequence{5}->union(Sequence{ -3 }))))))) ; var n1 : int := (arr1)->size() ; execute (maximumSumSubarray(arr1, n1))->display() ; var arr2 : Sequence := Sequence{4}->union(Sequence{-8}->union(Sequence{9}->union(Sequence{-4}->union(Sequence{1}->union(Sequence{-8}->union(Sequence{-1}->union(Sequence{ 6 }))))))) ; var n2 : int := (arr2)->size() ; execute (maximumSumSubarray(arr2, n2))->display(); operation maximumSumSubarray(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var min_prefix_sum : int := 0 ; var res : OclAny := - ; var prefix_sum : Sequence := Sequence{} ; execute ((arr->first()) : prefix_sum) ; for i : Integer.subrange(1, n-1) do ( execute ((prefix_sum[i - 1+1] + arr[i+1]) : prefix_sum)) ; for i : Integer.subrange(0, n-1) do ( res := Set{res, prefix_sum[i+1] - min_prefix_sum}->max() ; min_prefix_sum := Set{min_prefix_sum, prefix_sum[i+1]}->min()) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(int(input())//500*500) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (("" + (((OclFile["System.in"]).readLine())))->toInteger() div 500 * 500)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=100005 lpf=[0]*N ; def least_prime_factor(): for i in range(2,N): if(not lpf[i]): for j in range(i,N,i): if(not lpf[j]): lpf[j]=i ; def Mobius(n): mobius=[0]*N ; for i in range(1,N): if(i==1): mobius[i]=1 ; else : if(lpf[i//lpf[i]]==lpf[i]): mobius[i]=0 ; else : mobius[i]=-1*mobius[i//lpf[i]]; for i in range(1,n+1): print(mobius[i],end=" "); if __name__=="__main__" : n=5 ; least_prime_factor(); Mobius(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 100005 ; var lpf : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N); ; skip ; skip ; if __name__ = "__main__" then ( n := 5; ; least_prime_factor(); ; Mobius(n); ) else skip; operation least_prime_factor() pre: true post: true activity: for i : Integer.subrange(2, N-1) do ( if (not(lpf[i+1])) then ( for j : Integer.subrange(i, N-1)->select( $x | ($x - i) mod i = 0 ) do ( if (not(lpf[j+1])) then ( lpf[j+1] := i; ) else skip) ) else skip); operation Mobius(n : OclAny) pre: true post: true activity: var mobius : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N); ; for i : Integer.subrange(1, N-1) do ( if (i = 1) then ( mobius[i+1] := 1; ) else ( if (lpf[i div lpf[i+1]+1] = lpf[i+1]) then ( mobius[i+1] := 0; ) else ( mobius[i+1] := -1 * mobius[i div lpf[i+1]+1]; ) )) ; for i : Integer.subrange(1, n + 1-1) do ( execute (mobius[i+1])->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b,c,d=map(int,input().split()) ans=0 for l in range(1,n+1): k=c-b+l j=d-a+l i=c-b+j if i!=d-a+k : continue if i>=1 and j>=1 and k>=1 and i<=n and j<=n and k<=n : ans+=1 print(ans*n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{n,a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; for l : Integer.subrange(1, n + 1-1) do ( var k : double := c - b + l ; var j : double := d - a + l ; var i : double := c - b + j ; if i /= d - a + k then ( continue ) else skip ; if i >= 1 & j >= 1 & k >= 1 & (i->compareTo(n)) <= 0 & (j->compareTo(n)) <= 0 & (k->compareTo(n)) <= 0 then ( ans := ans + 1 ) else skip) ; execute (ans * n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b,c,d=tuple(map(int,input().split())) ans=0 sum=0 def ch(c): return(n>=c and c>0) for i in range(1,n+1): sum=i+a+b x2=sum-a-c x3=sum-c-d x4=sum-b-d if ch(i)and ch(x2)and ch(x3)and ch(x4): ans+=1 print(ans*n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{n,a,b,c,d} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; var sum : int := 0 ; skip ; for i : Integer.subrange(1, n + 1-1) do ( sum := i + a + b ; var x2 : double := sum - a - c ; var x3 : double := sum - c - d ; var x4 : double := sum - b - d ; if ch(i) & ch(x2) & ch(x3) & ch(x4) then ( ans := ans + 1 ) else skip) ; execute (ans * n)->display(); operation ch(c : OclAny) : OclAny pre: true post: true activity: return ((n->compareTo(c)) >= 0 & c > 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b,c,d=map(int,input().split()) mis=min(a+b,b+d,c+d,c+a) mas=max(a+b,b+d,c+d,c+a) dif=mas-mis res=0 for x3 in range(1,n+1): res+=n-dif print(max(res,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{n,a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mis : OclAny := Set{a + b, b + d, c + d, c + a}->min() ; var mas : OclAny := Set{a + b, b + d, c + d, c + a}->max() ; var dif : double := mas - mis ; var res : int := 0 ; for x3 : Integer.subrange(1, n + 1-1) do ( res := res + n - dif) ; execute (Set{res, 0}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b,c,d=map(int,input().split()) k=0 for u in range(1,n+1): v=u+b-c if(v>=1)and(v<=n): z=a+v-d if(z>=1)and(z<=n): y=c+z-b if(y>=1)and(y<=n): u=d+y-a if(u>=1)and(u<=n): k+=1 print(k*n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{n,a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : int := 0 ; for u : Integer.subrange(1, n + 1-1) do ( var v : double := u + b - c ; if (v >= 1) & ((v->compareTo(n)) <= 0) then ( var z : double := a + v - d ; if (z >= 1) & ((z->compareTo(n)) <= 0) then ( var y : double := c + z - b ; if (y >= 1) & ((y->compareTo(n)) <= 0) then ( var u : double := d + y - a ; if (u >= 1) & ((u->compareTo(n)) <= 0) then ( k := k + 1 ) else skip ) else skip ) else skip ) else skip) ; execute (k * n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,a,b,c,d=tuple([int(i)for i in input().split()]) ans=0 for i in range(1,n+1): t1=i t2=t1+a+b-a-c t3=t1+a+b-b-d t4=t1+a+b-c-d if t2>=1 and t2<=n and t3>=1 and t3<=n and t4>=1 and t4<=n : ans+=n print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{n,a,b,c,d} := (input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))) ; var ans : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( var t1 : OclAny := i ; var t2 : double := t1 + a + b - a - c ; var t3 : double := t1 + a + b - b - d ; var t4 : double := t1 + a + b - c - d ; if t2 >= 1 & (t2->compareTo(n)) <= 0 & t3 >= 1 & (t3->compareTo(n)) <= 0 & t4 >= 1 & (t4->compareTo(n)) <= 0 then ( ans := ans + n ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) b=sorted(a) cnt=0 for i in range(n): if(a[i]!=b[i]): cnt+=1 if(cnt<3): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := a->sort() ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] /= b[i+1]) then ( cnt := cnt + 1 ) else skip) ; if (cnt < 3) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) z=list(map(int,input().split())) t=z.copy() z.sort() count=0 for i in range(len(z)): if(z[i]!=t[i]): count+=1 print if(count==0 or count==2): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var z : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : OclAny := z->copy() ; z := z->sort() ; var count : int := 0 ; for i : Integer.subrange(0, (z)->size()-1) do ( if (z[i+1] /= t[i+1]) then ( count := count + 1 ) else skip) ; ; if (count = 0 or count = 2) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.read readline=sys.stdin.readline readlines=sys.stdin.readlines def main(): m,n=map(int,readline().split()) MOD=10**9+7 print(pow(m,n,MOD)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := (OclFile["System.in"]).read ; var readline : OclAny := (OclFile["System.in"]).readline ; var readlines : OclAny := (OclFile["System.in"]).readlines ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var MOD : double := (10)->pow(9) + 7 ; execute ((m)->pow(n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import* from math import* n=int(stdin.readline()) a=list(map(int,stdin.readline().split())) b=a.copy() b.sort() x=0 for i in range(n): if a[i]!=b[i]: x+=1 if x<=2 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + ((stdin.readLine())))->toInteger() ; var a : Sequence := ((stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : OclAny := a->copy() ; b := b->sort() ; var x : int := 0 ; for i : Integer.subrange(0, n-1) do ( if a[i+1] /= b[i+1] then ( x := x + 1 ) else skip) ; if x <= 2 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(a,b,v): ans=[] for i in range(len(v)): ans.append([a,b]) p1,p2=v[i][0],v[i][1] if p1==a : a=p2 else : b=p2 ans.append([a,b]) s="" for i in ans : s+=i[0]+" "+i[1]+"\n" return s a1,b1=input().split() n=int(input()) v=[] for i in range(n): a,b=input().split() v.append([a,b]) print(solve(a1,b1,v)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a1 : OclAny := null; var b1 : OclAny := null; Sequence{a1,b1} := input().split() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; v := Sequence{} ; for i : Integer.subrange(0, n-1) do ( Sequence{a,b} := input().split() ; execute ((Sequence{a}->union(Sequence{ b })) : v)) ; execute (solve(a1, b1, v))->display(); operation solve(a : OclAny, b : OclAny, v : OclAny) : OclAny pre: true post: true activity: var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, (v)->size()-1) do ( execute ((Sequence{a}->union(Sequence{ b })) : ans) ; var p1 : OclAny := null; var p2 : OclAny := null; Sequence{p1,p2} := Sequence{v[i+1]->first(),v[i+1][1+1]} ; if p1 = a then ( a := p2 ) else ( b := p2 )) ; execute ((Sequence{a}->union(Sequence{ b })) : ans) ; var s : String := "" ; for i : ans do ( s := s + i->first() + " " + i[1+1] + "\n") ; return s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ai=list(map(int,input().split())) ais=list(sorted(ai)) ct=0 for i in range(n): if ai[i]!=ais[i]: ct+=1 if ct==2 or ct==0 : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ai : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ais : Sequence := (ai->sort()) ; var ct : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ai[i+1] /= ais[i+1] then ( ct := ct + 1 ) else skip) ; if ct = 2 or ct = 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _=input() arr=list(map(int,input().split())) sorted_arr=sorted(arr) x=0 for i in range(len(arr)): if x<3 : if arr[i]!=sorted_arr[i]: x+=1 else : break print('YES' if x<3 else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _anon : String := (OclFile["System.in"]).readLine() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sorted_arr : Sequence := arr->sort() ; var x : int := 0 ; for i : Integer.subrange(0, (arr)->size()-1) do ( if x < 3 then ( if arr[i+1] /= sorted_arr[i+1] then ( x := x + 1 ) else skip ) else ( break )) ; execute (if x < 3 then 'YES' else 'NO' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(i,val): if i-val<0 : return False return True def MinimumPrimes(n): dp=[10**9]*(n+1) dp[0]=dp[2]=dp[3]=dp[5]=dp[7]=1 for i in range(1,n+1): if check(i,2): dp[i]=min(dp[i],1+dp[i-2]) if check(i,3): dp[i]=min(dp[i],1+dp[i-3]) if check(i,5): dp[i]=min(dp[i],1+dp[i-5]) if check(i,7): dp[i]=min(dp[i],1+dp[i-7]) if dp[n]==10**9 : return-1 else : return dp[n] if __name__=="__main__" : n=12 minimal=MinimumPrimes(n) if minimal!=-1 : print("Minimum number of single digit primes required : ",minimal) else : print("Not possible") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 12 ; var minimal : OclAny := MinimumPrimes(n) ; if minimal /= -1 then ( execute ("Minimum number of single digit primes required : ")->display() ) else ( execute ("Not possible")->display() ) ) else skip; operation check(i : OclAny, val : OclAny) : OclAny pre: true post: true activity: if i - val < 0 then ( return false ) else skip ; return true; operation MinimumPrimes(n : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ (10)->pow(9) }, (n + 1)) ; dp->first() := dp->first()(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 3))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 5))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 7))))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))) ; for i : Integer.subrange(1, n + 1-1) do ( if check(i, 2) then ( dp[i+1] := Set{dp[i+1], 1 + dp[i - 2+1]}->min() ) else skip ; if check(i, 3) then ( dp[i+1] := Set{dp[i+1], 1 + dp[i - 3+1]}->min() ) else skip ; if check(i, 5) then ( dp[i+1] := Set{dp[i+1], 1 + dp[i - 5+1]}->min() ) else skip ; if check(i, 7) then ( dp[i+1] := Set{dp[i+1], 1 + dp[i - 7+1]}->min() ) else skip) ; if dp[n+1] = (10)->pow(9) then ( return -1 ) else ( return dp[n+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=input().split() carry=0 base=int(max(a+b))+1 res='' while a or b or carry : s=int(a[-1 :]or '0')+int(b[-1 :]or '0')+carry a,b=a[:-1],b[:-1] carry,num=divmod(s,base) res=str(num)+res print(len(res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; var carry : int := 0 ; var base : int := ("" + (((a + b)->max())))->toInteger() + 1 ; var res : String := '' ; while a or b or carry do ( var s : int := ("" + ((a.subrange(-1+1) or '0')))->toInteger() + ("" + ((b.subrange(-1+1) or '0')))->toInteger() + carry ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{a->front(),b->front()} ; var num : OclAny := null; Sequence{carry,num} := Sequence{(s div base), (s mod base)} ; res := ("" + ((num))) + res) ; execute ((res)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(n,c): res=0 j=len(n)-1 step=int(c) for i in n : d=int(i) res+=d*(step**j) j-=1 return res def conv(n,radix): digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" r="" while(n>0): k=n % radix r=digits[k]+r n=n//radix return r a,b=input().split() m=0 for el in a : d=int(el)+1 if d>m : m=d for el in b : d=int(el)+1 if d>m : m=d x=f(a,m) y=f(b,m) res=x+y result=len(conv(res,m)) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; var m : int := 0 ; for el : a do ( d := ("" + ((el)))->toInteger() + 1 ; if (d->compareTo(m)) > 0 then ( m := d ) else skip) ; for el : b do ( d := ("" + ((el)))->toInteger() + 1 ; if (d->compareTo(m)) > 0 then ( m := d ) else skip) ; var x : String := f(a, m) ; var y : String := f(b, m) ; res := x + y ; var result : int := (conv(res, m))->size() ; execute (result)->display(); operation f(n : OclAny, c : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; var j : double := (n)->size() - 1 ; var step : int := ("" + ((c)))->toInteger() ; for i : n do ( var d : int := ("" + ((i)))->toInteger() ; res := res + d * ((step)->pow(j)) ; j := j - 1) ; return res; operation conv(n : OclAny, radix : OclAny) : OclAny pre: true post: true activity: var digits : String := "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" ; var r : String := "" ; while (n > 0) do ( var k : int := n mod radix ; r := digits[k+1] + r ; n := n div radix) ; return r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nti(a,x): r='' u='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' while a>0 : r+=u[a % x] a=a//x if r=='' : r='0' return r[: :-1] a,b=input().split() s=int(max(a+b))+1 print(len(nti(int(a,s)+int(b,s),s))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var b : OclAny := null; Sequence{a,b} := input().split() ; var s : int := ("" + (((a + b)->max())))->toInteger() + 1 ; execute ((nti(("" + ((a, s)))->toInteger() + ("" + ((b, s)))->toInteger(), s))->size())->display(); operation nti(a : OclAny, x : OclAny) : OclAny pre: true post: true activity: var r : String := '' ; var u : String := '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' ; while a > 0 do ( r := r + u[a mod x+1] ; a := a div x) ; if r = '' then ( r := '0' ) else skip ; return r(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- sizdvch=list(map(str,input().split())) isch=[] perch=int(sizdvch[0]) vtoch=int(sizdvch[1]) vivo=[] for i in range(2): for j in range(len(sizdvch[i])): isch.append(int(sizdvch[i][j])) maxch=max(isch) minsis=maxch+1 if minsis==10 : print(len(str(perch+vtoch))) else : for i in range(2): n=sizdvch[i] dlin=len(n) n1=0 ndp='' for j in range(dlin): ndp=n[j] n1=n1+(int(ndp)*minsis**(dlin-j-1)) vivo.append(n1) sumvivo=sum(vivo) b='' while sumvivo>0 : if sumvivo % minsis<10 : b=str(sumvivo % minsis)+b else : if sumvivo % minsis==10 : b='A'+b if sumvivo % minsis==11 : b='B'+b if sumvivo % minsis==12 : b='C'+b if sumvivo % minsis==13 : b='D'+b if sumvivo % minsis==14 : b='E'+b if sumvivo % minsis==15 : b='F'+b sumvivo=sumvivo//minsis print(len(b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var sizdvch : Sequence := ((input().split())->collect( _x | (OclType["String"])->apply(_x) )) ; var isch : Sequence := Sequence{} ; var perch : int := ("" + ((sizdvch->first())))->toInteger() ; var vtoch : int := ("" + ((sizdvch[1+1])))->toInteger() ; var vivo : Sequence := Sequence{} ; for i : Integer.subrange(0, 2-1) do ( for j : Integer.subrange(0, (sizdvch[i+1])->size()-1) do ( execute ((("" + ((sizdvch[i+1][j+1])))->toInteger()) : isch))) ; var maxch : OclAny := (isch)->max() ; var minsis : OclAny := maxch + 1 ; if minsis = 10 then ( execute ((("" + ((perch + vtoch))))->size())->display() ) else ( for i : Integer.subrange(0, 2-1) do ( var n : OclAny := sizdvch[i+1] ; var dlin : int := (n)->size() ; var n1 : int := 0 ; var ndp : String := '' ; for j : Integer.subrange(0, dlin-1) do ( ndp := n[j+1] ; n1 := n1 + (("" + ((ndp)))->toInteger() * (minsis)->pow((dlin - j - 1)))) ; execute ((n1) : vivo)) ; var sumvivo : OclAny := (vivo)->sum() ; var b : String := '' ; while sumvivo > 0 do ( if sumvivo mod minsis < 10 then ( b := ("" + ((sumvivo mod minsis))) + b ) else ( if sumvivo mod minsis = 10 then ( b := 'A' + b ) else skip ; if sumvivo mod minsis = 11 then ( b := 'B' + b ) else skip ; if sumvivo mod minsis = 12 then ( b := 'C' + b ) else skip ; if sumvivo mod minsis = 13 then ( b := 'D' + b ) else skip ; if sumvivo mod minsis = 14 then ( b := 'E' + b ) else skip ; if sumvivo mod minsis = 15 then ( b := 'F' + b ) else skip ) ; sumvivo := sumvivo div minsis) ; execute ((b)->size())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count_digits_in_new_base(number,new_base): if number==0 : return 1 digits=0 while number>=1 : digits+=1 number=int(number/new_base) return digits def get_min_base(number): digits=list(str(number)) min_base=int(max(digits))+1 return min_base def get_integer_value_for_given_base(number,base): result=0 weight=1 while number>=1 : remainder=number % 10 result+=remainder*weight weight*=base number=int(number/10) return result def find_length_of_longest_expression(a,b): min_base=max(get_min_base(a),get_min_base(b)) sum=get_integer_value_for_given_base(a,min_base)+get_integer_value_for_given_base(b,min_base) value=count_digits_in_new_base(sum,min_base) return value v=[int(x)for x in input().split(' ')] a=v[0] b=v[1] print(find_length_of_longest_expression(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var v : Sequence := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; a := v->first() ; b := v[1+1] ; execute (find_length_of_longest_expression(a, b))->display(); operation count_digits_in_new_base(number : OclAny, new_base : OclAny) : OclAny pre: true post: true activity: if number = 0 then ( return 1 ) else skip ; var digits : int := 0 ; while number >= 1 do ( digits := digits + 1 ; number := ("" + ((number / new_base)))->toInteger()) ; return digits; operation get_min_base(number : OclAny) : OclAny pre: true post: true activity: digits := (("" + ((number))))->characters() ; var min_base : int := ("" + (((digits)->max())))->toInteger() + 1 ; return min_base; operation get_integer_value_for_given_base(number : OclAny, base : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; var weight : int := 1 ; while number >= 1 do ( var remainder : int := number mod 10 ; result := result + remainder * weight ; weight := weight * base ; number := ("" + ((number / 10)))->toInteger()) ; return result; operation find_length_of_longest_expression(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: min_base := Set{get_min_base(a), get_min_base(b)}->max() ; var sum : OclAny := get_integer_value_for_given_base(a, min_base) + get_integer_value_for_given_base(b, min_base) ; var value : OclAny := count_digits_in_new_base(sum, min_base) ; return value; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def unboundedKnapsack(W,n,val,wt): dp=[0 for i in range(W+1)] ans=0 for i in range(W+1): for j in range(n): if(wt[j]<=i): dp[i]=max(dp[i],dp[i-wt[j]]+val[j]) return dp[W] W=100 val=[10,30,20] wt=[5,10,15] n=len(val) print(unboundedKnapsack(W,n,val,wt)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; W := 100 ; val := Sequence{10}->union(Sequence{30}->union(Sequence{ 20 })) ; wt := Sequence{5}->union(Sequence{10}->union(Sequence{ 15 })) ; n := (val)->size() ; execute (unboundedKnapsack(W, n, val, wt))->display(); operation unboundedKnapsack(W : OclAny, n : OclAny, val : OclAny, wt : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, W + 1-1)->select(i | true)->collect(i | (0)) ; var ans : int := 0 ; for i : Integer.subrange(0, W + 1-1) do ( for j : Integer.subrange(0, n-1) do ( if ((wt[j+1]->compareTo(i)) <= 0) then ( dp[i+1] := Set{dp[i+1], dp[i - wt[j+1]+1] + val[j+1]}->max() ) else skip)) ; return dp[W+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getnumbers(n): divisor=[] for i in range(2,n+1): while(n % i==0): divisor.append(i) n//=i if(n!=1): divisor.append(n) a,b,c,size=0,0,0,0 a=b=c=1 size=len(divisor) for i in range(size): if(a==1): a=a*divisor[i] elif(b==1 or b==a): b=b*divisor[i] else : c=c*divisor[i] if(a==1 or b==1 or c==1 or a==b or b==c or a==c): print("-1") else : print(a,b,c) n=64 getnumbers(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 64 ; getnumbers(n); operation getnumbers(n : OclAny) pre: true post: true activity: var divisor : Sequence := Sequence{} ; for i : Integer.subrange(2, n + 1-1) do ( while (n mod i = 0) do ( execute ((i) : divisor) ; n := n div i)) ; if (n /= 1) then ( execute ((n) : divisor) ) else skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var size : OclAny := null; Sequence{a,b,c,size} := Sequence{0,0,0,0} ; a := a(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))) ; var size : int := (divisor)->size() ; for i : Integer.subrange(0, size-1) do ( if (a = 1) then ( var a : double := a * divisor[i+1] ) else (if (b = 1 or b = a) then ( var b : double := b * divisor[i+1] ) else ( var c : double := c * divisor[i+1] ) ) ) ; if (a = 1 or b = 1 or c = 1 or a = b or b = c or a = c) then ( execute ("-1")->display() ) else ( execute (a)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(H : int,W : int,A : int,B : int): answer=[["0"]*W for _ in range(H)] for i in range(H): for j in range(W): if iselect(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ "0" }, W))) ; for i : Integer.subrange(0, H-1) do ( for j : Integer.subrange(0, W-1) do ( if (i->compareTo(B)) < 0 then ( if (j->compareTo(A)) < 0 then ( answer[i+1][j+1] := "0" ) else ( answer[i+1][j+1] := "1" ) ) else ( if (j->compareTo(A)) < 0 then ( answer[i+1][j+1] := "1" ) else ( answer[i+1][j+1] := "0" ) ))) ; for i : Integer.subrange(0, H-1) do ( execute (StringLib.sumStringsWithSeparator((answer[i+1]), ''))->display()) ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var H : int := ("" + (((tokens).next())))->toInteger() ; var W : int := ("" + (((tokens).next())))->toInteger() ; var A : int := ("" + (((tokens).next())))->toInteger() ; var B : int := ("" + (((tokens).next())))->toInteger() ; solve(H, W, A, B); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def rearrange(arr,n): i=0 j=n-1 while(i0): i+=1 while(arr[j]<0): j-=1 if(iunion(Sequence{3}->union(Sequence{-4}->union(Sequence{-1}->union(Sequence{6}->union(Sequence{ -9 }))))) ; n := (arr)->size() ; execute ("Given array is")->display() ; printArray(arr, n) ; rearrange(arr, n) ; execute ("Rearranged array is")->display() ; printArray(arr, n); operation rearrange(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; var j : double := n - 1 ; while ((i->compareTo(j)) < 0) do ( while (arr[i+1] > 0) do ( i := i + 1) ; while (arr[j+1] < 0) do ( j := j - 1) ; if ((i->compareTo(j)) < 0) then ( var temp : OclAny := arr[i+1] ; arr[i+1] := arr[j+1] ; arr[j+1] := temp ) else skip) ; if (i = 0 or i = n) then ( return 0 ) else skip ; var k : int := 0 ; while ((k->compareTo(n)) < 0 & (i->compareTo(n)) < 0) do ( temp := arr[k+1] ; arr[k+1] := arr[i+1] ; arr[i+1] := temp ; i := i + 1 ; k := k + 2); operation printArray(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()) ; execute ("\n")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isOddPrime(n): for i in range(3,int(n**.5)+1,2): if n % i==0 : return False return True ans=0 for i in range(int(input())): ans+=isOddPrime(2*int(input())+1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var ans : int := 0 ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( ans := ans + isOddPrime(2 * ("" + (((OclFile["System.in"]).readLine())))->toInteger() + 1)) ; execute (ans)->display(); operation isOddPrime(n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(3, ("" + (((n)->pow(.5))))->toInteger() + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if n mod i = 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ng=0 def prime(a): if a==1 : return 1 i=3 while i<=a/i : if a % i==0 : return 0 i+=2 return 1 for i in range(n): a=2*int(input())+1 ng+=prime(a) print(ng) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ng : int := 0 ; skip ; for i : Integer.subrange(0, n-1) do ( a := 2 * ("" + (((OclFile["System.in"]).readLine())))->toInteger() + 1 ; ng := ng + prime(a)) ; execute (ng)->display(); operation prime(a : OclAny) : OclAny pre: true post: true activity: if a = 1 then ( return 1 ) else skip ; var i : int := 3 ; while (i->compareTo(a / i)) <= 0 do ( if a mod i = 0 then ( return 0 ) else skip ; i := i + 2) ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isAvailableAreas(area): ymax=int(area**0.5) for i in range(1,ymax+1): if(area-i)%(2*i+1)==0 : return True return False n=int(input()) A=[] for i in range(n): A.append(int(input())) suma=0 for i in A : if not isAvailableAreas(i): suma=suma+1 print(suma) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : A)) ; var suma : int := 0 ; for i : A do ( if not(isAvailableAreas(i)) then ( suma := suma + 1 ) else skip) ; execute (suma)->display(); operation isAvailableAreas(area : OclAny) : OclAny pre: true post: true activity: var ymax : int := ("" + (((area)->pow(0.5))))->toInteger() ; for i : Integer.subrange(1, ymax + 1-1) do ( if (area - i) mod (2 * i + 1) = 0 then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[int(input())for _ in[0]*int(input())] m=a[-1]+1 def f(S): x=1 while 2*x*-~ xtoInteger())->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var m : OclAny := a->last() + 1 ; skip ; execute (((argument (test (logical_test (comparison (expr (atom (name f)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name S)))))))) ))))))) (comp_for for (exprlist (expr (atom (name S)))) in (logical_test (comparison (expr (atom (name a))))))))->sum())->display(); operation f(S : OclAny) : OclAny pre: true post: true activity: var x : int := 1 ; while (2 * x * -MathLib.bitwiseNot(x)->compareTo(m)) < 0 do ( if (S - x) mod (2 * x + 1) = 0 then ( return 0 ) else skip ; x := x + 1) ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def p(x): if x % 2==0 : return 0 for i in range(3,int(x**.5+1),2): if x % i==0 : return 0 return 1 def f(): print(sum(p(int(input())*2+1)for _ in[0]*int(input()))) if '__main__'==__name__ : f() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if '__main__' = __name__ then ( f() ) else skip; operation p(x : OclAny) : OclAny pre: true post: true activity: if x mod 2 = 0 then ( return 0 ) else skip ; for i : Integer.subrange(3, ("" + (((x)->pow(.5) + 1)))->toInteger()-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if x mod i = 0 then ( return 0 ) else skip) ; return 1; operation f() pre: true post: true activity: execute (((argument (test (logical_test (comparison (expr (atom (name p)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) )))) * (expr (atom (number (integer 2))))) + (expr (atom (number (integer 1)))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class newNode : def __init__(self,data): self.val=data self.left=self.right=None def length(node,ans): if(not node): return 0 left=length(node.left,ans) right=length(node.right,ans) Leftmax=0 Rightmax=0 if(node.left and node.left.val==node.val): Leftmax+=left+1 if(node.right and node.right.val==node.val): Rightmax+=right+1 ans[0]=max(ans[0],Leftmax+Rightmax) return max(Leftmax,Rightmax) def longestSameValuePath(root): ans=[0] length(root,ans) return ans[0] if __name__=='__main__' : root=None root=newNode(4) root.left=newNode(4) root.right=newNode(4) root.left.left=newNode(4) root.left.right=newNode(9) root.right.right=newNode(5) print(longestSameValuePath(root)) ------------------------------------------------------------ OCL File: --------- class newNode { static operation newnewNode() : newNode pre: true post: newNode->exists( _x | result = _x ); attribute val : OclAny := data; attribute left : OclAny := null; var self.right : OclAny := null; operation initialise(data : OclAny) : newNode pre: true post: true activity: self.val := data ; self.left := null; var self.right : OclAny := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( root := null ; root := (newNode.newnewNode()).initialise(4) ; root.left := (newNode.newnewNode()).initialise(4) ; root.right := (newNode.newnewNode()).initialise(4) ; root.left.left := (newNode.newnewNode()).initialise(4) ; root.left.right := (newNode.newnewNode()).initialise(9) ; root.right.right := (newNode.newnewNode()).initialise(5) ; execute (longestSameValuePath(root))->display() ) else skip; operation length(node : OclAny, ans : OclAny) : OclAny pre: true post: true activity: if (not(node)) then ( return 0 ) else skip ; var left : OclAny := length(node.left, ans) ; var right : OclAny := length(node.right, ans) ; var Leftmax : int := 0 ; var Rightmax : int := 0 ; if (node.left & node.left.val = node.val) then ( Leftmax := Leftmax + left + 1 ) else skip ; if (node.right & node.right.val = node.val) then ( Rightmax := Rightmax + right + 1 ) else skip ; ans->first() := Set{ans->first(), Leftmax + Rightmax}->max() ; return Set{Leftmax, Rightmax}->max(); operation longestSameValuePath(root : OclAny) : OclAny pre: true post: true activity: ans := Sequence{ 0 } ; length(root, ans) ; return ans->first(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy from test.support import _MemoryWatchdog BIG_NUM=2000000000 HUGE_NUM=99999999999999999 MOD=1000000007 EPS=0.000000001 sys.setrecursionlimit(100000) NUM=32 while True : N=int(input()) if N==0 : break table=list(map(int,input().split())) num_card=NUM tern=0 while num_card>0 : sente=(num_card-1)% 5 num_card-=sente print("%d" %(num_card)) gote=table[tern %(len(table))] num_card=max(0,num_card-gote) print("%d" %(num_card)) tern+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var HUGE_NUM : int := 99999999999999999 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; sys.setrecursionlimit(100000) ; var NUM : int := 32 ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var table : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var num_card : int := NUM ; var tern : int := 0 ; while num_card > 0 do ( var sente : int := (num_card - 1) mod 5 ; num_card := num_card - sente ; execute (StringLib.format("%d",(num_card)))->display() ; var gote : OclAny := table[tern mod ((table)->size())+1] ; num_card := Set{0, num_card - gote}->max() ; execute (StringLib.format("%d",(num_card)))->display() ; tern := tern + 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys if False : fh=open('vol1_0164.txt','r') else : fh=sys.stdin j=0 a=[] def ichi(n): n-=(n-1)% 5 return(n) def ji(n): global j if ntoInteger() ; if m = 0 then ( break ) else skip ; a := ((fh.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; j := 0 ; n := 32 ; while true do ( n := ichi(n) ; execute (n)->display() ; if n = 0 then ( break ) else skip ; n := ji(n) ; execute (n)->display() ; if n = 0 then ( break ) else skip)); operation ichi(n : OclAny) : OclAny pre: true post: true activity: n := n - (n - 1) mod 5 ; return (n); operation ji(n : OclAny) : OclAny pre: true post: true activity: skip ; if (n->compareTo(a[j+1])) < 0 then ( n := 0 ) else ( n := n - a[j+1] ) ; j := (j + 1) mod (a)->size() ; return (n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import cycle INITIALIZE=32 while True : input_count=int(input()) if input_count==0 : break get_list=[int(item)for item in input().split(" ")] ohajiki=INITIALIZE output=[] for get_count in cycle(get_list): ohajiki-=(ohajiki-1)% 5 output.append(ohajiki) if get_counttoInteger() ; if input_count = 0 then ( break ) else skip ; var get_list : Sequence := input().split(" ")->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; var ohajiki : int := INITIALIZE ; var output : Sequence := Sequence{} ; for get_count : cycle(get_list) do ( ohajiki := ohajiki - (ohajiki - 1) mod 5 ; execute ((ohajiki) : output) ; if (get_count->compareTo(ohajiki)) < 0 then ( ohajiki := ohajiki - get_count ; execute ((ohajiki) : output) ) else ( execute ((0) : output) ; break )) ; output := output->select(item | true)->collect(item | (("" + ((item))))) ; execute (StringLib.sumStringsWithSeparator((output), "\n"))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- h,w,a,b=list(map(int,input().split())) for i in range(b): print("1"*a+"0"*(w-a)) for i in range(h-b): print("0"*a+"1"*(w-a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{h,w,a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, b-1) do ( execute (StringLib.nCopies("1", a) + StringLib.nCopies("0", (w - a)))->display()) ; for i : Integer.subrange(0, h - b-1) do ( execute (StringLib.nCopies("0", a) + StringLib.nCopies("1", (w - a)))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def longestRepeatedSubSeq(str): n=len(str) dp=[[0 for i in range(n+1)]for j in range(n+1)] for i in range(1,n+1): for j in range(1,n+1): if(str[i-1]==str[j-1]and i!=j): dp[i][j]=1+dp[i-1][j-1] else : dp[i][j]=max(dp[i][j-1],dp[i-1][j]) res='' i=n j=n while(i>0 and j>0): if(dp[i][j]==dp[i-1][j-1]+1): res+=str[i-1] i-=1 j-=1 elif(dp[i][j]==dp[i-1][j]): i-=1 else : j-=1 res=''.join(reversed(res)) return res str='AABEBCDD' print(longestRepeatedSubSeq(str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclType["String"] := 'AABEBCDD' ; execute (longestRepeatedSubSeq(OclType["String"]))->display(); operation longestRepeatedSubSeq(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var n : int := (OclType["String"])->size() ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, n + 1-1) do ( if (("" + ([i - 1+1])) = ("" + ([j - 1+1])) & i /= j) then ( dp[i+1][j+1] := 1 + dp[i - 1+1][j - 1+1] ) else ( dp[i+1][j+1] := Set{dp[i+1][j - 1+1], dp[i - 1+1][j+1]}->max() ))) ; var res : String := '' ; var i : int := n ; var j : int := n ; while (i > 0 & j > 0) do ( if (dp[i+1][j+1] = dp[i - 1+1][j - 1+1] + 1) then ( res := res + ("" + ([i - 1+1])) ; i := i - 1 ; j := j - 1 ) else (if (dp[i+1][j+1] = dp[i - 1+1][j+1]) then ( i := i - 1 ) else ( j := j - 1 ) ) ) ; res := StringLib.sumStringsWithSeparator(((res)->reverse()), '') ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if n==0 : break alist=list(map(int,input().split())) ohajiki=32 cnt=0 while ohajiki!=0 : taro=(ohajiki-1)% 5 ohajiki-=taro print(ohajiki) jiro=alist[cnt % n] ohajiki-=jiro if ohajiki<0 : ohajiki=0 print(ohajiki) cnt+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var alist : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ohajiki : int := 32 ; var cnt : int := 0 ; while ohajiki /= 0 do ( var taro : int := (ohajiki - 1) mod 5 ; ohajiki := ohajiki - taro ; execute (ohajiki)->display() ; var jiro : OclAny := alist[cnt mod n+1] ; ohajiki := ohajiki - jiro ; if ohajiki < 0 then ( ohajiki := 0 ) else skip ; execute (ohajiki)->display() ; cnt := cnt + 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,bisect PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") while True : n=int(input()) if n==0 : break A=[int(_)for _ in input().split()] oha=32 i=0 while oha!=0 : oha-=(oha-1)% 5 print(oha) oha=max(oha-A[i % n],0) print(oha) i+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var A : Sequence := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var oha : int := 32 ; var i : int := 0 ; while oha /= 0 do ( oha := oha - (oha - 1) mod 5 ; execute (oha)->display() ; oha := Set{oha - A[i mod n+1], 0}->max() ; execute (oha)->display() ; i := i + 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minSteps(str): count=0 i=0 while idisplay(); operation minSteps(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var i : int := 0 ; while (i->compareTo((OclType["String"])->size() - 2)) < 0 do ( if ("" + ([i+1])) = '0' then ( if (("" + ([i + 1+1])) = '1') then ( if (("" + ([i + 2+1])) = '0') then ( count := count + 1 ; i := i + 2 ) else skip ) else skip ) else skip ; i := i + 1) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- prime=[True for i in range(100)] def sieve(n,prime): for i in range(1,n+1): prime[i]=True prime[0]=prime[1]=False for i in range(2,n+1): if(prime[i]): for j in range(2*i,n+1,i): prime[j]=False def SumOfSubset(a,n): maxi=max(a) sieve(maxi,prime) times=pow(2,n-1) Sum=1 for i in range(n): if(prime[a[i]]): Sum=Sum*(pow(a[i],times)) return Sum a=[3,7] n=len(a) print(SumOfSubset(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var prime : Sequence := Integer.subrange(0, 100-1)->select(i | true)->collect(i | (true)) ; skip ; skip ; a := Sequence{3}->union(Sequence{ 7 }) ; n := (a)->size() ; execute (SumOfSubset(a, n))->display(); operation sieve(n : OclAny, prime : OclAny) pre: true post: true activity: for i : Integer.subrange(1, n + 1-1) do ( prime[i+1] := true) ; prime->first() := false; var prime[1+1] : boolean := false ; for i : Integer.subrange(2, n + 1-1) do ( if (prime[i+1]) then ( for j : Integer.subrange(2 * i, n + 1-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ( prime[j+1] := false) ) else skip); operation SumOfSubset(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var maxi : OclAny := (a)->max() ; sieve(maxi, prime) ; var times : double := (2)->pow(n - 1) ; var Sum : int := 1 ; for i : Integer.subrange(0, n-1) do ( if (prime[a[i+1]+1]) then ( Sum := Sum * ((a[i+1])->pow(times)) ) else skip) ; return Sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=[int(input())for i in range(5)] if l[0]<0 : print((0-l[0])*l[2]+l[3]+l[1]*l[4]) elif l[0]==0 : print(l[3]+l[1]*l[4]) else : print((l[1]-l[0])*l[4]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := Integer.subrange(0, 5-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; if l->first() < 0 then ( execute ((0 - l->first()) * l[2+1] + l[3+1] + l[1+1] * l[4+1])->display() ) else (if l->first() = 0 then ( execute (l[3+1] + l[1+1] * l[4+1])->display() ) else ( execute ((l[1+1] - l->first()) * l[4+1])->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A=int(input()) B=int(input()) C=int(input()) D=int(input()) E=int(input()) t=0 if A<0 : t+=C*abs(A)+D t+=E*(B-max(0,A)) print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var C : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var D : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var E : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : int := 0 ; if A < 0 then ( t := t + C * (A)->abs() + D ) else skip ; t := t + E * (B - Set{0, A}->max()) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def frozen(A,t): if A>=B or A>=0 : return A,t return frozen(A+1,t+C) def normal_temperature(A,t): if A>=B : return A,t return normal_temperature(A+1,t+E) t=0 A=int(input()) B=int(input()) C=int(input()) D=int(input()) E=int(input()) if A<0 : A,t=frozen(A,t) if A==0 and A=0 : A,t=normal_temperature(A,t) print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; t := 0 ; A := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var C : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var D : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var E : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if A < 0 then ( Sequence{A,t} := frozen(A, t) ) else skip ; if A = 0 & (A->compareTo(B)) < 0 then ( t := t + D ) else skip ; if A >= 0 then ( Sequence{A,t} := normal_temperature(A, t) ) else skip ; execute (t)->display(); operation frozen(A : OclAny, t : OclAny) : OclAny pre: true post: true activity: if (A->compareTo(B)) >= 0 or A >= 0 then ( return A, t ) else skip ; return frozen(A + 1, t + C); operation normal_temperature(A : OclAny, t : OclAny) : OclAny pre: true post: true activity: if (A->compareTo(B)) >= 0 then ( return A, t ) else skip ; return normal_temperature(A + 1, t + E); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) c=int(input()) d=int(input()) e=int(input()) print(-a*c+d+b*e if a<0 else(b-a)*e) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var e : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (if a < 0 then -a * c + d + b * e else (b - a) * e endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d,e=[int(input())for i in range(5)] t=0 b+=(a<0) while a!=b : if a<0 : t+=c elif a==0 : t+=d else : t+=e a+=1 print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; Sequence{a,b,c,d,e} := Integer.subrange(0, 5-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var t : int := 0 ; b := b + (a < 0) ; while a /= b do ( if a < 0 then ( t := t + c ) else (if a = 0 then ( t := t + d ) else ( t := t + e ) ) ; a := a + 1) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import(division,absolute_import,print_function,unicode_literals) from sys import stdin from math import hypot while True : x=int(stdin.readline()) h=int(stdin.readline()) if not(x or h): break print('{:.6f}'.format(x*x+hypot(x,h*2)*x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; while true do ( var x : int := ("" + ((stdin.readLine())))->toInteger() ; var h : int := ("" + ((stdin.readLine())))->toInteger() ; if not((x or h)) then ( break ) else skip ; execute (StringLib.interpolateStrings('{:.6f}', Sequence{x * x + hypot(x, h * 2) * x}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math from functools import lru_cache from collections import defaultdict from decimal import Decimal sys.setrecursionlimit(10**9) MOD=10**9+7 def input(): return sys.stdin.readline()[:-1] def mi(): return map(int,input().split()) def ii(): return int(input()) def i2(n): tmp=[list(mi())for i in range(n)] return[list(i)for i in zip(*tmp)] def main(): H,W,A,B=mi() ans=[[None]*W for i in range(H)] for i in range(B): for j in range(A): ans[i][j]='0' for j in range(A,W): ans[i][j]='1' for i in range(B,H): for j in range(A): ans[i][j]='1' for j in range(A,W): ans[i][j]='0' print(*[''.join(ans[i])for i in range(H)],sep='\n') if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var MOD : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation mi() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation ii() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation i2(n : OclAny) : OclAny pre: true post: true activity: var tmp : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((mi()))) ; return Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name tmp)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name tmp)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name tmp)))))))`third->at(_indx)} )->select(i | true)->collect(i | ((i))); operation main() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{H,W,A,B} := mi() ; var ans : Sequence := Integer.subrange(0, H-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ null }, W))) ; for i : Integer.subrange(0, B-1) do ( for j : Integer.subrange(0, A-1) do ( ans[i+1][j+1] := '0') ; for j : Integer.subrange(A, W-1) do ( ans[i+1][j+1] := '1')) ; for i : Integer.subrange(B, H-1) do ( for j : Integer.subrange(0, A-1) do ( ans[i+1][j+1] := '1') ; for j : Integer.subrange(A, W-1) do ( ans[i+1][j+1] := '0')) ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom '') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name H)))))))) )))))))) ])))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter from sys import stdin input=stdin.readline string=input(); dic=Counter(string) if len(dic.keys())>1 : if dic["x"]>=dic["y"]: print("x"*(dic["x"]-dic["y"])) else : print("y"*abs(dic["x"]-dic["y"])) else : x=list(dic.keys())[0] print(x*dic[x]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; var string : String := (OclFile["System.in"]).readLine(); var dic : OclAny := Counter(string) ; if (dic.keys())->size() > 1 then ( if (dic->at("x")->compareTo(dic->at("y"))) >= 0 then ( execute (StringLib.nCopies("x", (dic->at("x") - dic->at("y"))))->display() ) else ( execute (StringLib.nCopies("y", (dic->at("x") - dic->at("y"))->abs()))->display() ) ) else ( var x : OclAny := OclType["Sequence"](dic.keys())->first() ; execute (x * dic[x+1])->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxProduct(a,n): product=[0]*n ; maxA=[0]*n ; maxProd=0 ; maxArr=0 ; for i in range(n): product[i]=a[(i+1)% n]*a[(i+(n-1))% n]; if(maxProdunion(Sequence{6}->union(Sequence{4}->union(Sequence{3}->union(Sequence{ 2 })))); ; n := (a)->size(); ; execute (maxProduct(a, n))->display(); ) else skip; operation maxProduct(a : OclAny, n : OclAny) pre: true post: true activity: var product : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; var maxA : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; var maxProd : int := 0; ; var maxArr : int := 0; ; for i : Integer.subrange(0, n-1) do ( product[i+1] := a[(i + 1) mod n+1] * a[(i + (n - 1)) mod n+1]; ; if ((maxProd->compareTo(product[i+1])) < 0) then ( maxProd := product[i+1]; ) else skip) ; return maxProd;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def main_function(): s=input() coun_x=0 count_y=0 for i in range(len(s)): if s[i]=="x" : coun_x+=1 else : count_y+=1 if count_y==coun_x : print("") elif coun_x>count_y : print("x"*(coun_x-count_y)) else : print("y"*(count_y-coun_x)) main_function() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main_function(); operation main_function() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var coun_x : int := 0 ; var count_y : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = "x" then ( coun_x := coun_x + 1 ) else ( count_y := count_y + 1 )) ; if count_y = coun_x then ( execute ("")->display() ) else (if (coun_x->compareTo(count_y)) > 0 then ( execute (StringLib.nCopies("x", (coun_x - count_y)))->display() ) else ( execute (StringLib.nCopies("y", (count_y - coun_x)))->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() x_count,y_count=0,0 for c in s : if(c=='x'): x_count+=1 else : y_count+=1 output="" if(x_count>y_count): output="x"*(x_count-y_count) else : output="y"*(y_count-x_count) print(output) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var x_count : OclAny := null; var y_count : OclAny := null; Sequence{x_count,y_count} := Sequence{0,0} ; for c : s->characters() do ( if (c = 'x') then ( x_count := x_count + 1 ) else ( y_count := y_count + 1 )) ; var output : String := "" ; if ((x_count->compareTo(y_count)) > 0) then ( output := StringLib.nCopies("x", (x_count - y_count)) ) else ( output := StringLib.nCopies("y", (y_count - x_count)) ) ; execute (output)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline s=input()[:-1] a=s.count('x') b=s.count('y') print('x'*(a-b)if a>=b else 'y'*(b-a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var s : OclAny := input()->front() ; var a : int := s->count('x') ; var b : int := s->count('y') ; execute (if (a->compareTo(b)) >= 0 then StringLib.nCopies('x', (a - b)) else StringLib.nCopies('y', (b - a)) endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() a=s.count("x") b=s.count("y") if a>b : print("x"*(a-b)) else : print("y"*(b-a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var a : int := s->count("x") ; var b : int := s->count("y") ; if (a->compareTo(b)) > 0 then ( execute (StringLib.nCopies("x", (a - b)))->display() ) else ( execute (StringLib.nCopies("y", (b - a)))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def EqualNumbers(a,n): for i in range(0,n): while a[i]% 2==0 : a[i]//=2 while a[i]% 3==0 : a[i]//=3 if a[i]!=a[0]: return False return True if __name__=="__main__" : a=[50,75,150] n=len(a) if EqualNumbers(a,n): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{50}->union(Sequence{75}->union(Sequence{ 150 })) ; n := (a)->size() ; if EqualNumbers(a, n) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation EqualNumbers(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( while a[i+1] mod 2 = 0 do ( a[i+1] := a[i+1] div 2) ; while a[i+1] mod 3 = 0 do ( a[i+1] := a[i+1] div 3) ; if a[i+1] /= a->first() then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) l=list(map(int,input().split())) c=0 m=l[: :-1] h=list(filter(lambda x : x>k,l)) for i in range(n): if l[0]<=k : c+=1 l.pop(0) else : break if len(h)>0 : for j in range(n): if m[0]<=k : c+=1 m.pop(0) else : break print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; var m : OclAny := l(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var h : Sequence := ((l)->select( _x | (lambda x : OclAny in ((x->compareTo(k)) > 0))->apply(_x) = true )) ; for i : Integer.subrange(0, n-1) do ( if (l->first()->compareTo(k)) <= 0 then ( c := c + 1 ; l := l->excludingAt(0+1) ) else ( break )) ; if (h)->size() > 0 then ( for j : Integer.subrange(0, n-1) do ( if (m->first()->compareTo(k)) <= 0 then ( c := c + 1 ; m := m->excludingAt(0+1) ) else ( break )) ) else skip ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (a,b)=[int(x)for x in input().split()] l=[int(x)for x in input().split()] c=0 while(bool(l)and(l[0]<=b or l[-1]<=b)): if l[0]<=b : c+=1 l=l[1 :] elif l[-1]<=b : c+=1 l.pop() print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{a, b} : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var l : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var c : int := 0 ; while ((l)->toBoolean() & ((l->first()->compareTo(b)) <= 0 or (l->last()->compareTo(b)) <= 0)) do ( if (l->first()->compareTo(b)) <= 0 then ( c := c + 1 ; l := l->tail() ) else (if (l->last()->compareTo(b)) <= 0 then ( c := c + 1 ; l := l->front() ) else skip)) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) arr=list(map(int,input().split())) count=0 i=0 j=len(arr)-1 while i=0 : if arr[i]<=k : i+=1 count+=1 elif arr[j]<=k : j-=1 count+=1 else : break print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : int := 0 ; var i : int := 0 ; var j : double := (arr)->size() - 1 ; while (i->compareTo((arr)->size())) < 0 & j >= 0 do ( if (arr[i+1]->compareTo(k)) <= 0 then ( i := i + 1 ; count := count + 1 ) else (if (arr[j+1]->compareTo(k)) <= 0 then ( j := j - 1 ; count := count + 1 ) else ( break ) ) ) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from collections import deque from collections import Counter h,w,a,b=map(int,input().split()) ans=[[0]*w for _ in range(h)] for i in range(h): for j in range(w): if(i=b and j>=a): ans[i][j]=1 for i in range(h): L=[str(x)for x in ans[i]] L="".join(L) print(L) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var h : OclAny := null; var w : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{h,w,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, w))) ; for i : Integer.subrange(0, h-1) do ( for j : Integer.subrange(0, w-1) do ( if ((i->compareTo(b)) < 0 & (j->compareTo(a)) < 0) or ((i->compareTo(b)) >= 0 & (j->compareTo(a)) >= 0) then ( ans[i+1][j+1] := 1 ) else skip)) ; for i : Integer.subrange(0, h-1) do ( var L : Sequence := ans[i+1]->select(x | true)->collect(x | (("" + ((x))))) ; L := StringLib.sumStringsWithSeparator((L), "") ; execute (L)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) A=list(map(int,input().split())) ans=0 for i in range(n): if A[i]<=k : ans+=1 else : break if ans==n : exit(print(n)) else : for i in range(n-1,-1,-1): if A[i]<=k : ans+=1 else : break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (A[i+1]->compareTo(k)) <= 0 then ( ans := ans + 1 ) else ( break )) ; if ans = n then ( exit((n)->display()) ) else ( for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (A[i+1]->compareTo(k)) <= 0 then ( ans := ans + 1 ) else ( break )) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) arr=list(map(int,input().split())) ans=0 q=0 ans0=0 for i in range(n): if arr[i]>m : q=(i+1) break else : ans+=1 q=i+1 e=arr[q :] e.reverse() for j in e : if j>m : break else : ans0+=1 print(ans+ans0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; var q : int := 0 ; var ans0 : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1]->compareTo(m)) > 0 then ( q := (i + 1) ; break ) else ( ans := ans + 1 )) ; q := i + 1 ; var e : OclAny := arr.subrange(q+1) ; e := e->reverse() ; for j : e do ( if (j->compareTo(m)) > 0 then ( break ) else ( ans0 := ans0 + 1 )) ; execute (ans + ans0)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input().replace('><','><').split() c=0 for i in a : if len(i)==3 : print(c*2*' '+i) c+=1 else : c-=1 print(c*2*' '+i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := input().replace('><', '><').split() ; var c : int := 0 ; for i : a do ( if (i)->size() = 3 then ( execute (c * 2 * ' ' + i)->display() ; c := c + 1 ) else ( c := c - 1 ; execute (c * 2 * ' ' + i)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline a,b,x,y=map(int,input().split()) g=math.gcd(x,y) x//=g y//=g ans=min(a//x,b//y) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var a : OclAny := null; var b : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{a,b,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var g : long := (x)->gcd(y) ; x := x div g ; y := y div g ; var ans : OclAny := Set{a div x, b div y}->min() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(m,n): if n==0 : return m else : return gcd(n,m % n) a,b,x,y=list(map(int,input().split())) div=gcd(x,y) x//=div y//=div print(min(a//x,b//y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{a,b,x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var div : OclAny := gcd(x, y) ; x := x div div ; y := y div div ; execute (Set{a div x, b div y}->min())->display(); operation gcd(m : OclAny, n : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( return m ) else ( return gcd(n, m mod n) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a,b,x,y=map(int,input().split()) val=math.gcd(x,y) while val!=1 : while x % val==0 and y % val==0 : x//=val y//=val val=math.gcd(x,y) print(min(a//x,b//y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{a,b,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var val : long := (x)->gcd(y) ; while val /= 1 do ( while x mod val = 0 & y mod val = 0 do ( x := x div val ; y := y div val) ; val := (x)->gcd(y)) ; execute (Set{a div x, b div y}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from fractions import Fraction (a,b,x,y)=map(int,input().split(' ')) reduced_fraction=Fraction(x,y) x=reduced_fraction.numerator y=reduced_fraction.denominator print(min(a//x,b//y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var Sequence{a, b, x, y} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var reduced_fraction : OclAny := Fraction(x, y) ; var x : OclAny := reduced_fraction.numerator ; var y : OclAny := reduced_fraction.denominator ; execute (Set{a div x, b div y}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() a,b,x,y=map(int,input().split()) import math q=math.gcd(x,y) print(min(b//(y//q),a//(x//q))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var a : OclAny := null; var b : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{a,b,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; var q : long := (x)->gcd(y) ; execute (Set{b div (y div q), a div (x div q)}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for _ in range(n): a,b,c=[int(x)for x in input().split()] t1=abs(a-1) t2=abs(b-c)+abs(c-1) if t1t2 : print(2) else : print(3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var t1 : double := (a - 1)->abs() ; var t2 : double := (b - c)->abs() + (c - 1)->abs() ; if (t1->compareTo(t2)) < 0 then ( execute (1)->display() ) else (if (t1->compareTo(t2)) > 0 then ( execute (2)->display() ) else ( execute (3)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b,c=map(int,input().split()) f1=abs(a-1) s1=abs(b-c) s2=abs(c-1) s=s1+s2 if f1s : print("2") else : print("3") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var f1 : double := (a - 1)->abs() ; var s1 : double := (b - c)->abs() ; var s2 : double := (c - 1)->abs() ; var s : OclAny := s1 + s2 ; if (f1->compareTo(s)) < 0 then ( execute ("1")->display() ) else (if (f1->compareTo(s)) > 0 then ( execute ("2")->display() ) else ( execute ("3")->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import numpy as np def input(): return sys.stdin.readline().rstrip() def ii(): return int(input()) def mi(): return map(int,input().split()) def li(): return list(mi()) def main(): h,w,a,b=mi() g=np.zeros((h,w),dtype=int) g[: b,: a]=1 g[b :,a :]=1 for i in range(h): print(*g[i],sep='') if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation ii() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation mi() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation li() : OclAny pre: true post: true activity: return (mi()); operation main() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{h,w,a,b} := mi() ; var g : Sequence := MatrixLib.singleValueMatrix(Sequence{h, w}, 0.0) ; g.subrange(1,b).subrange(1,a) := 1 ; g.subrange(b+1).subrange(a+1) := 1 ; for i : Integer.subrange(0, h-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _=int(input()) for __ in range(_): a,b,c=map(int,input().split()) if c>b : b=c+c-b if a>b : print(2) elif b>a : print(1) else : print(3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _anon : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for __ : Integer.subrange(0, _anon-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (c->compareTo(b)) > 0 then ( var b : double := c + c - b ) else skip ; if (a->compareTo(b)) > 0 then ( execute (2)->display() ) else (if (b->compareTo(a)) > 0 then ( execute (1)->display() ) else ( execute (3)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): a,b,c=map(int,input().split(' ')) if abs(a-1)abs(b-c)+abs(c-1): print(2) else : print(3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; if ((a - 1)->abs()->compareTo((b - c)->abs() + (c - 1)->abs())) < 0 then ( execute (1)->display() ) else (if ((a - 1)->abs()->compareTo((b - c)->abs() + (c - 1)->abs())) > 0 then ( execute (2)->display() ) else ( execute (3)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=eval(input()) for i in range(t): a,b,c=map(int,input().split()) x=abs(a-1) y=abs(b-c)+abs(c-1) if x==y : print(3) elif xcollect( _x | (OclType["int"])->apply(_x) ) ; var x : double := (a - 1)->abs() ; var y : double := (b - c)->abs() + (c - 1)->abs() ; if x = y then ( execute (3)->display() ) else (if (x->compareTo(y)) < 0 then ( execute (1)->display() ) else ( execute (2)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() print(S[: 3]) T=[] T.append(S[: 3]) S=S[3 :] a=0 while True : if S[1]!='/' : Nb=T[-1].count(' ') if '/' in T[-1]: Ch=' '*(Nb)+S[: 3] else : Ch=' '*(Nb)+' '+S[: 3] print(Ch) T.append(Ch) S=S[3 :] a=0 else : Nb=T[-1].count(' ') if '/' in T[-1]: Ch=' '*(Nb-1)+S[: 4] else : Ch=' '*(Nb)+S[: 4] print(Ch) T.append(Ch) S=S[4 :] a+=1 if S=='' : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; execute (S.subrange(1,3))->display() ; var T : Sequence := Sequence{} ; execute ((S.subrange(1,3)) : T) ; S := S.subrange(3+1) ; var a : int := 0 ; while true do ( if S[1+1] /= '/' then ( var Nb : OclAny := T->last()->count(' ') ; if (T->last())->includes('/') then ( var Ch : String := StringLib.nCopies(' ', (Nb)) + S.subrange(1,3) ) else ( Ch := StringLib.nCopies(' ', (Nb)) + ' ' + S.subrange(1,3) ) ; execute (Ch)->display() ; execute ((Ch) : T) ; S := S.subrange(3+1) ; a := 0 ) else ( Nb := T->last()->count(' ') ; if (T->last())->includes('/') then ( Ch := StringLib.nCopies(' ', (Nb - 1)) + S.subrange(1,4) ) else ( Ch := StringLib.nCopies(' ', (Nb)) + S.subrange(1,4) ) ; execute (Ch)->display() ; execute ((Ch) : T) ; S := S.subrange(4+1) ; a := a + 1 ) ; if S = '' then ( break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib,itertools def compute(): ans=0 primes=eulerlib.list_primes(2000000) for i in itertools.count(2): p=primes[i] q=primes[i+1] if p>1000000 : break k=1 while k

B/2+1 : break same=[] for c2 in numbers : if not c2 % c1 : same.append(c2-A) sets=merge_sets(sets,same) counted=[] c2=0 for c1 in sets : if not c1 in counted : counted.append(c1) c2+=1 return str(c2) def merge_sets(sets,same): to_change=[sets[c1]for c1 in same] for c1 in range(len(sets)): if sets[c1]in to_change : sets[c1]=to_change[0] return sets p_file=file("primes1000.txt") primes=[int(c1)for c1 in p_file.read().split("\n")] p_file.close() num=int(inp_file.readline()) for case in range(num): line=inp_file.readline()[:-1] out_file.write("Case #%s: " %(case+1)+solve(line)+"\n") inp_file.close() out_file.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inp_file : OclAny := file("B-small.in") ; var out_file : OclAny := file("B-small.out", "w") ; skip ; skip ; var p_file : OclAny := file("primes1000.txt") ; var primes : Sequence := p_file.readAll().split("\n")->select(c1 | true)->collect(c1 | (("" + ((c1)))->toInteger())) ; p_file.closeFile() ; var num : int := ("" + ((inp_file.readLine())))->toInteger() ; for case : Integer.subrange(0, num-1) do ( line := inp_file.readLine()->front() ; out_file.write(StringLib.format("Case #%s: ",(case + 1)) + solve(line) + "\n")) ; inp_file.closeFile() ; out_file.closeFile(); operation solve(line : OclAny) : OclAny pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var P : OclAny := null; Sequence{A,B,P} := line.split(" ")->select(c1 | true)->collect(c1 | (("" + ((c1)))->toInteger())) ; var numbers : Sequence := Integer.subrange(A, B + 1-1) ; var sets : Sequence := Integer.subrange(0, B - A + 1-1) ; for c1 : primes do ( if (c1->compareTo(P)) < 0 then ( continue ) else skip ; if (c1->compareTo(B / 2 + 1)) > 0 then ( break ) else skip ; var same : Sequence := Sequence{} ; for c2 : numbers do ( if not(c2 mod c1) then ( execute ((c2 - A) : same) ) else skip) ; sets := merge_sets(sets, same)) ; var counted : Sequence := Sequence{} ; var c2 : int := 0 ; for c1 : sets do ( if not((counted)->includes(c1)) then ( execute ((c1) : counted) ; c2 := c2 + 1 ) else skip) ; return ("" + ((c2))); operation merge_sets(sets : OclAny, same : OclAny) : OclAny pre: true post: true activity: var to_change : Sequence := same->select(c1 | true)->collect(c1 | (sets[c1+1])) ; for c1 : Integer.subrange(0, (sets)->size()-1) do ( if (to_change)->includes(sets[c1+1]) then ( sets[c1+1] := to_change->first() ) else skip) ; return sets; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def vol_of_dodecahedron(side): return(((15+(7*(math.sqrt(5))))/4)*(math.pow(side,3))) side=4 print("Volume of dodecahedron=",round(vol_of_dodecahedron(side),2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; side := 4 ; execute ("Volume of dodecahedron=")->display(); operation vol_of_dodecahedron(side : OclAny) : OclAny pre: true post: true activity: return (((15 + (7 * ((5)->sqrt()))) / 4) * ((side)->pow(3))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- X=[] while(True): h,w=map(int,input().split()) if(h,w)==(0,0): break else : X.append((h,w)) Y=[] N=200 for h in range(1,N+1): for w in range(h+1,N+1): Y.append((h*h+w*w,min(h,w),h,w)) Y.sort() Z=[[-1 for i in range(N+1)]for j in range(N+1)] for i in range(len(Y)): p,q,r,s=Y[i] Z[r][s]=i for seq in X : h,w=seq x,y,a,b=Y[Z[h][w]+1] print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var X : Sequence := Sequence{} ; while (true) do ( var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if Sequence{h, w} = Sequence{0, 0} then ( break ) else ( execute ((Sequence{h, w}) : X) )) ; var Y : Sequence := Sequence{} ; var N : int := 200 ; for h : Integer.subrange(1, N + 1-1) do ( for w : Integer.subrange(h + 1, N + 1-1) do ( execute ((Sequence{h * h + w * w, Set{h, w}->min(), h, w}) : Y))) ; Y := Y->sort() ; var Z : Sequence := Integer.subrange(0, N + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, N + 1-1)->select(i | true)->collect(i | (-1)))) ; for i : Integer.subrange(0, (Y)->size()-1) do ( var p : OclAny := null; var q : OclAny := null; var r : OclAny := null; var s : OclAny := null; Sequence{p,q,r,s} := Y[i+1] ; Z[r+1][s+1] := i) ; for seq : X do ( var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := seq ; var x : OclAny := null; var y : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{x,y,a,b} := Y[Z[h+1][w+1] + 1+1] ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import sqrt inf=1<<30 def solve(): while 1 : h,w=map(int,sys.stdin.readline().split()) if h==w==0 : return L=h**2+w**2 maxL=inf ansx=inf ansy=inf for x in range(1,L): if L-x**2<0 : break y=nibutan(L-x**2) if y<=x : break if x**2+y**2==L : if h1 : mid=(top+btm)//2 if mid**2>=a : top=mid else : btm=mid return top if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var Math_PINFINITY : int := 1 * (2->pow(30)) ; skip ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: while 1 do ( var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if h = w & (w == 0) then ( return ) else skip ; var L : double := (h)->pow(2) + (w)->pow(2) ; var maxL : int := Math_PINFINITY ; var ansx : int := Math_PINFINITY ; var ansy : int := Math_PINFINITY ; for x : Integer.subrange(1, L-1) do ( if L - (x)->pow(2) < 0 then ( break ) else skip ; var y : OclAny := nibutan(L - (x)->pow(2)) ; if (y->compareTo(x)) <= 0 then ( break ) else skip ; if (x)->pow(2) + (y)->pow(2) = L then ( if (h->compareTo(x)) < 0 then ( ansx := x ; ansy := y ; break ) else ( y := y + 1 ) ) else skip ; if ((x)->pow(2) + (y)->pow(2)->compareTo(maxL)) < 0 then ( maxL := (x)->pow(2) + (y)->pow(2) ; ansx := x ; ansy := y ) else skip) ; execute (ansx)->display()); operation nibutan(a : OclAny) : OclAny pre: true post: true activity: var top : int := Math_PINFINITY ; var btm : int := 0 ; while top - btm > 1 do ( var mid : int := (top + btm) div 2 ; if ((mid)->pow(2)->compareTo(a)) >= 0 then ( top := mid ) else ( btm := mid )) ; return top; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] t=[] for i in range(1,151): for j in range(i+1,151): t.append((i**2+j**2,(i,j))) t.sort() tt=list(map(lambda x : x[1],t)) while True : h,w=LI() if h==0 : break i=tt.index((h,w)) r=tt[i+1] rr.append(' '.join(map(str,r))) return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; var t : Sequence := Sequence{} ; for i : Integer.subrange(1, 151-1) do ( for j : Integer.subrange(i + 1, 151-1) do ( execute ((Sequence{(i)->pow(2) + (j)->pow(2), Sequence{i, j}}) : t))) ; t := t->sort() ; var tt : Sequence := ((t)->collect( _x | (lambda x : OclAny in (x[1+1]))->apply(_x) )) ; while true do ( var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := LI() ; if h = 0 then ( break ) else skip ; var i : int := tt->indexOf(Sequence{h, w}) - 1 ; var r : OclAny := tt[i + 1+1] ; execute ((StringLib.sumStringsWithSeparator(((r)->collect( _x | (OclType["String"])->apply(_x) )), ' ')) : rr)) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from inspect import currentframe def debug_print(s): return def debug_key(*args): names={id(v): k for k,v in currentframe().f_back.f_locals.items()} debug_print(','.join(names.get(id(arg),'???')+'='+repr(arg)for arg in args)) def solve(h,w): debug_print("\n-----solve-----") if h==0 : return d0=h*h+w*w ans=(10**9,h,w) for w in range(2,151): for heisght in range(1,w): d=heisght*heisght+w*w if(d,heisght,w)<(d0,h,w)or(heisght,w)==(h,w): continue ans=min(ans,(d,heisght,w)) break print('{0}{1}'.format(ans[1],ans[2])) return if __name__=='__main__' : while True : h_input,w_imput=map(int,input().split()) if h_input==w_imput==0 : break solve(h_input,w_imput) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( while true do ( var h_input : OclAny := null; var w_imput : OclAny := null; Sequence{h_input,w_imput} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if h_input = w_imput & (w_imput == 0) then ( break ) else skip ; solve(h_input, w_imput)) ) else skip; operation debug_print(s : OclAny) pre: true post: true activity: return; operation debug_key(args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) var names : Map := currentframe().f_back.f_locals->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->select(_tuple | true)->collect(_tuple | Map{?(v) |-> k})->unionAll() ; debug_print(StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (expr (expr (atom (name names)) (trailer . (name get) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name id)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arg)))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom '???'))))))) )))) + (expr (atom '='))) + (expr (atom (name repr)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arg)))))))) )))))))) (comp_for for (exprlist (expr (atom (name arg)))) in (logical_test (comparison (expr (atom (name args)))))))), ',')); operation solve(h : OclAny, w : OclAny) pre: true post: true activity: debug_print("\n-----solve-----") ; if h = 0 then ( return ) else skip ; var d0 : double := h * h + w * w ; var ans : OclAny := Sequence{(10)->pow(9), h, w} ; for w : Integer.subrange(2, 151-1) do ( for heisght : Integer.subrange(1, w-1) do ( var d : double := heisght * heisght + w * w ; if (Sequence{d, heisght, w}->compareTo(Sequence{d0, h, w})) < 0 or Sequence{heisght, w} = Sequence{h, w} then ( continue ) else skip ; ans := Set{ans, Sequence{d, heisght, w}}->min() ; break)) ; execute (StringLib.interpolateStrings('{0}{1}', Sequence{ans[1+1], ans[2+1]}))->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxProd(N): if(N==0): return 1 if(N<10): return N return max(maxProd(N//10)*(N % 10),maxProd(N//10-1)*9) N=390 print(maxProd(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 390 ; execute (maxProd(N))->display(); operation maxProd(N : OclAny) : OclAny pre: true post: true activity: if (N = 0) then ( return 1 ) else skip ; if (N < 10) then ( return N ) else skip ; return Set{maxProd(N div 10) * (N mod 10), maxProd(N div 10 - 1) * 9}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while(True): n=int(input()) if n==0 : exit() b=list(map(int,input().split())) even,odd=b[: n],b[n :] sq=even[0]*even[1]//odd[0] l,r=1,2**32 while r-l>1 : mid=(l+r)//2 if mid*mid<=sq : l=mid else : r=mid print(l) print(" ".join(map(str,sorted([x//l for x in even])))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while (true) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( exit() ) else skip ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var even : OclAny := null; var odd : OclAny := null; Sequence{even,odd} := Sequence{b.subrange(1,n),b.subrange(n+1)} ; var sq : int := even->first() * even[1+1] div odd->first() ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{1,(2)->pow(32)} ; while r - l > 1 do ( var mid : int := (l + r) div 2 ; if (mid * mid->compareTo(sq)) <= 0 then ( var l : int := mid ) else ( var r : int := mid )) ; execute (l)->display() ; execute (StringLib.sumStringsWithSeparator(((even->select(x | true)->collect(x | (x div l))->sort())->collect( _x | (OclType["String"])->apply(_x) )), " "))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools rects=sorted([(t[0]**2+t[1]**2,t[0],t[1])for t in itertools.combinations(range(1,151),2)],key=lambda x :(x[0],x[1])) while True : h,w=map(int,input().split(" ")) if h==0 and w==0 : break rect=h**2+w**2 for i in range(len(rects)): if rects[i][0]==rect and rects[i][1]==h and rects[i][2]==w : H,W=rects[i+1][1 :] print(H,W) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var rects : Sequence := itertools.combinations(Integer.subrange(1, 151-1), 2)->select(t | true)->collect(t | (Sequence{(t->first())->pow(2) + (t[1+1])->pow(2), t->first(), t[1+1]}))->sortedBy($x | (lambda x : OclAny in (Sequence{x->first(), x[1+1]}))->apply($x)) ; while true do ( var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; if h = 0 & w = 0 then ( break ) else skip ; var rect : double := (h)->pow(2) + (w)->pow(2) ; for i : Integer.subrange(0, (rects)->size()-1) do ( if rects[i+1]->first() = rect & rects[i+1][1+1] = h & rects[i+1][2+1] = w then ( var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := rects[i + 1+1]->tail() ; execute (H)->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import pow def findSum(N,k): sum=0 for i in range(1,N+1,1): sum+=pow(i,k) return sum if __name__=='__main__' : N=8 k=4 print(int(findSum(N,k))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( N := 8 ; k := 4 ; execute (("" + ((findSum(N, k))))->toInteger())->display() ) else skip; operation findSum(N : OclAny, k : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(1, N + 1-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( sum := sum + (i)->pow(k)) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count(N): sum=0 ; for i in range(N+1): sum+=7*(8**(i-1)); return int(sum); if __name__=="__main__" : N=4 ; print(count(N)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := 4; ; execute (count(N))->display(); ) else skip; operation count(N : OclAny) pre: true post: true activity: var sum : int := 0; ; for i : Integer.subrange(0, N + 1-1) do ( sum := sum + 7 * ((8)->pow((i - 1)));) ; return ("" + ((sum)))->toInteger();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def factorial(n): res=1 i=2 for i in(n+1): res=res*i return res def calculateSeries(n): return(2+(n*n+n-2)*math.factorial(n+1)) n=3 print(calculateSeries(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 3 ; execute (calculateSeries(n))->display(); operation factorial(n : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; var i : int := 2 ; for i : (n + 1) do ( res := res * i) ; return res; operation calculateSeries(n : OclAny) : OclAny pre: true post: true activity: return (2 + (n * n + n - 2) * MathLib.factorial(n + 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def factorial(n): res=1 for i in range(2,n+1): res=res*i return res def calculateSeries(n): return factorial(n+1)-1 n=3 print(calculateSeries(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 3 ; execute (calculateSeries(n))->display(); operation factorial(n : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; for i : Integer.subrange(2, n + 1-1) do ( res := res * i) ; return res; operation calculateSeries(n : OclAny) : OclAny pre: true post: true activity: return factorial(n + 1) - 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printTriangle(arr,n): tri=[[0 for i in range(n)]for i in range(n)] for i in range(n): tri[n-1][i]=arr[i] i=n-2 while(i>=0): for j in range(0,i+1,1): tri[i][j]=(tri[i+1][j]+tri[i+1][j+1]) i-=1 for i in range(0,n,1): for j in range(0,i+1,1): print(tri[i][j],end="") print("\n",end="") if __name__=='__main__' : arr=[4,7,3,6,7] n=len(arr) printTriangle(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{4}->union(Sequence{7}->union(Sequence{3}->union(Sequence{6}->union(Sequence{ 7 })))) ; n := (arr)->size() ; printTriangle(arr, n) ) else skip; operation printTriangle(arr : OclAny, n : OclAny) pre: true post: true activity: var tri : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, n-1) do ( tri[n - 1+1][i+1] := arr[i+1]) ; var i : double := n - 2 ; while (i >= 0) do ( for j : Integer.subrange(0, i + 1-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( tri[i+1][j+1] := (tri[i + 1+1][j+1] + tri[i + 1+1][j + 1+1])) ; i := i - 1) ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( for j : Integer.subrange(0, i + 1-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( execute (tri[i+1][j+1])->display()) ; execute ("\n")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): s=input() b=sorted(s) if b[0]==b[-1]: print(-1) elif s[0]==s[-1]and s[1]==s[-2]: print(''.join(b)) else : print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var b : Sequence := s->sort() ; if b->first() = b->last() then ( execute (-1)->display() ) else (if s->first() = s->last() & s[1+1] = s->front()->last() then ( execute (StringLib.sumStringsWithSeparator((b), ''))->display() ) else ( execute (s)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys rd=sys.stdin.readline for _ in range(int(rd())): s=list(rd().strip()) if len(s)==s.count(s[0]): print(-1) elif s==s[: :-1]: for i in range(len(s)): if s[i]!=s[0]: s[i],s[0]=s[0],s[i] break print(''.join(s)) else : print(''.join(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var rd : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + ((rd())))->toInteger()-1) do ( var s : Sequence := (rd()->trim()) ; if (s)->size() = s->count(s->first()) then ( execute (-1)->display() ) else (if s = s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] /= s->first() then ( var s[i+1] : OclAny := null; var s->first() : OclAny := null; Sequence{s[i+1],s->first()} := Sequence{s->first(),s[i+1]} ; break ) else skip) ; execute (StringLib.sumStringsWithSeparator((s), ''))->display() ) else ( execute (StringLib.sumStringsWithSeparator((s), ''))->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in[0]*int(input()): s=sorted(input()); print((-1,''.join(s))[s[0]toInteger()) do ( var s : Sequence := (OclFile["System.in"]).readLine()->sort(); execute (Sequence{-1, StringLib.sumStringsWithSeparator((s), '')}->select((s->first()->compareTo(s->last())) < 0))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=list(map(int,input().split())) max=1 for i in range(n): if s[i]==1 : count=2 for j in range(i+1,n): if s[j]==1 : count+=1 continue else : break if count>max : max=count print(max) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var max : int := 1 ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = 1 then ( var count : int := 2 ; for j : Integer.subrange(i + 1, n-1) do ( if s[j+1] = 1 then ( count := count + 1 ; continue ) else ( break )) ; if (count->compareTo(max)) > 0 then ( max := count ) else skip ) else skip) ; execute (max)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) a=[] for i in range(t): a=a+[input()] l=[] for i in a : i=''.join(sorted(i)) if i[0]==i[-1]and i==i[: :-1]: l=l+[-1] else : l=l+[i] for i in l : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( a := a->union(Sequence{ (OclFile["System.in"]).readLine() })) ; var l : Sequence := Sequence{} ; for i : a do ( var i : String := StringLib.sumStringsWithSeparator((i->sort()), '') ; if i->first() = i->last() & i = i(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( l := l->union(Sequence{ -1 }) ) else ( l := l->union(Sequence{ i }) )) ; for i : l do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000001 factor=[0]*MAX def cal_factor(): factor[1]=1 for i in range(2,MAX): factor[i]=i for i in range(4,MAX,2): factor[i]=2 i=3 while i*iunion(Sequence{4}->union(Sequence{ 4 })) ; n := (a)->size() ; execute (no_of_representations(a, n))->display() ) else skip; operation cal_factor() pre: true post: true activity: factor[1+1] := 1 ; for i : Integer.subrange(2, MAX-1) do ( factor[i+1] := i) ; for i : Integer.subrange(4, MAX-1)->select( $x | ($x - 4) mod 2 = 0 ) do ( factor[i+1] := 2) ; var i : int := 3 ; while (i * i->compareTo(MAX)) < 0 do ( if (factor[i+1] = i) then ( for j : Integer.subrange(i * i, MAX-1)->select( $x | ($x - i * i) mod i = 0 ) do ( if (factor[j+1] = j) then ( factor[j+1] := i ) else skip) ) else skip ; i := i + 1); operation no_of_representations(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( var temp : OclAny := a[i+1] ; var flag : int := 0 ; while (factor[temp+1] /= 1) do ( flag := -1 ; count := count + 1 ; temp := temp div factor[temp+1]) ; count := count + flag) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter def solve(s): c=Counter(s) if len(c)==1 : return-1 if s!=s[: :-1]: return s s=[i for i in s] for i in range(len(s)): if s[i]!=s[0]: s[0],s[i]=s[i],s[0] break return ''.join(s) for _ in range(int(input())): print(solve(input())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (solve((OclFile["System.in"]).readLine()))->display()); operation solve(s : OclAny) : OclAny pre: true post: true activity: var c : OclAny := Counter(s) ; if (c)->size() = 1 then ( return -1 ) else skip ; if s /= s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( return s ) else skip ; s := s->select(i | true)->collect(i | (i)) ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] /= s->first() then ( var s->first() : OclAny := null; var s[i+1] : OclAny := null; Sequence{s->first(),s[i+1]} := Sequence{s[i+1],s->first()} ; break ) else skip) ; return StringLib.sumStringsWithSeparator((s), ''); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()); x,y=map(int,input().split()); z=n+1 if x+y<=z : print("White") else : print("Black") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var z : int := n + 1 ; if (x + y->compareTo(z)) <= 0 then ( execute ("White")->display() ) else ( execute ("Black")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,[x,y]=int(input()),(int(i)for i in input().split()) res="White" if x-1+y-1<=n-x+n-y else "Black" print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var Sequence{x}->union(Sequence{ y }) : OclAny := null; Sequence{n,Sequence{x}->union(Sequence{ y })} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))}} ; var res : String := if (x - 1 + y - 1->compareTo(n - x + n - y)) <= 0 then "White" else "Black" endif ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) x,y=map(int,input().split()) u=max(x-1,y-1) v=max(n-x,n-y) ans="White" if u<=v else "Black" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var u : OclAny := Set{x - 1, y - 1}->max() ; var v : OclAny := Set{n - x, n - y}->max() ; var ans : String := if (u->compareTo(v)) <= 0 then "White" else "Black" endif ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x,y=map(int,input().split()) white=abs(x+y-2) black=abs(2*n-x-y) if white<=black : print('White') else : print('Black') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var white : double := (x + y - 2)->abs() ; var black : double := (2 * n - x - y)->abs() ; if (white->compareTo(black)) <= 0 then ( execute ('White')->display() ) else ( execute ('Black')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a,b=map(int,input().split()) x=(a-1)+(b-1) y=n-a+n-b if x<=y : print("White") else : print("Black") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : double := (a - 1) + (b - 1) ; var y : double := n - a + n - b ; if (x->compareTo(y)) <= 0 then ( execute ("White")->display() ) else ( execute ("Black")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def mulmod(a,b,mod): res=0 a=a % mod while(b>0): if(b % 2==1): res=(res+a)% mod a=(a*2)% mod b//=2 return res % mod def findProduct(N): product=1 ; fact=1 MOD=1e9+7 for i in range(1,N+1): fact=mulmod(fact,i,MOD) product=mulmod(product,fact,MOD) if not product : return 0 return int(product) N=3 print(findProduct(N)) N=5 print(findProduct(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; N := 3 ; execute (findProduct(N))->display() ; N := 5 ; execute (findProduct(N))->display(); operation mulmod(a : OclAny, b : OclAny, mod : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; a := a mod mod ; while (b > 0) do ( if (b mod 2 = 1) then ( res := (res + a) mod mod ) else skip ; a := (a * 2) mod mod ; b := b div 2) ; return res mod mod; operation findProduct(N : OclAny) : OclAny pre: true post: true activity: var product : int := 1; var fact : int := 1 ; var MOD : double := ("1e9")->toReal() + 7 ; for i : Integer.subrange(1, N + 1-1) do ( fact := mulmod(fact, i, MOD) ; product := mulmod(product, fact, MOD) ; if not(product) then ( return 0 ) else skip) ; return ("" + ((product)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for pratyush in range(int(input())): n=int(input()) a=list(map(int,input().split())) x=a.index(1) y=a.index(n) b=a[x :]+a[: x] c=a[y :]+a[: y] d,e=a.copy(),a.copy() d.sort() e.sort(reverse=True) if d==b or e==c : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for pratyush : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : int := a->indexOf(1) - 1 ; var y : int := a->indexOf(n) - 1 ; var b : OclAny := a.subrange(x+1) + a.subrange(1,x) ; var c : OclAny := a.subrange(y+1) + a.subrange(1,y) ; var d : OclAny := null; var e : OclAny := null; Sequence{d,e} := Sequence{a->copy(),a->copy()} ; d := d->sort() ; e := e->sort() ; if d = b or e = c then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def inpl(): return list(map(int,input().split())) R,N=inpl() while R : H=[0]*41 r0=0 l0=0 for _ in range(N): l,r,h=inpl() if l<0 and r>=0 : l0=max(l0,h) if l<=0 and r>0 : r0=max(r0,h) l+=(l<=0) r-=(r>=0) for i in range(l,r+1): if i!=0 : H[i+20]=max(H[i+20],h) H[20]=min(l0,r0) ans=20 for x in range(-R+1,R): time=R-sqrt(R**2-x**2)+H[x+20] ans=min(ans,time) print(ans) R,N=inpl() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var R : OclAny := null; var N : OclAny := null; Sequence{R,N} := inpl() ; while R do ( var H : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 41) ; var r0 : int := 0 ; var l0 : int := 0 ; for _anon : Integer.subrange(0, N-1) do ( var l : OclAny := null; var r : OclAny := null; var h : OclAny := null; Sequence{l,r,h} := inpl() ; if l < 0 & r >= 0 then ( l0 := Set{l0, h}->max() ) else skip ; if l <= 0 & r > 0 then ( r0 := Set{r0, h}->max() ) else skip ; l := l + (l <= 0) ; r := r - (r >= 0) ; for i : Integer.subrange(l, r + 1-1) do ( if i /= 0 then ( H[i + 20+1] := Set{H[i + 20+1], h}->max() ) else skip)) ; H[20+1] := Set{l0, r0}->min() ; var ans : int := 20 ; for x : Integer.subrange(-R + 1, R-1) do ( var time : double := R - sqrt((R)->pow(2) - (x)->pow(2)) + H[x + 20+1] ; ans := Set{ans, time}->min()) ; execute (ans)->display() ; var R : OclAny := null; var N : OclAny := null; Sequence{R,N} := inpl()); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import re def solve(s): return max([len(r.group())for r in re.finditer(r'1+',s)],default=0)+1 def main(args): _=input() ans=solve(input().replace('','')) print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(s : OclAny) : OclAny pre: true post: true activity: return Set{OclIterator.newOclIterator_Sequence((s)->allMatches(StringLib.rawString('1+')))->select(r | true)->collect(r | ((r.group())->size())), (argument (test (logical_test (comparison (expr (atom (name default)))))) = (test (logical_test (comparison (expr (atom (number (integer 0))))))))}->max() + 1; operation main(args : OclAny) pre: true post: true activity: var _anon : String := (OclFile["System.in"]).readLine() ; var ans : OclAny := solve(input().replace('', '')) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=list(int(c)for c in input().split()) p=i=0 while i1 : p+=1 i+=1 print('YES' if p<2 else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ; var p : OclAny := 0; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( if (a[i+1] - a[i - 1+1])->abs() > 1 then ( p := p + 1 ) else skip ; i := i + 1) ; execute (if p < 2 then 'YES' else 'NO' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) l=list(map(int,input().split())) x=l.index(1) t=l.index(n) ans='YES' if l[(x+1)% n]==2 : y=3 for i in range(2,n): if l[(x+i)% n]!=y : ans='NO' break y+=1 elif l[(t+1)% n]==n-1 : y=n-2 for i in range(2,n): if l[(t+i)% n]!=y : ans='NO' break y-=1 elif n!=1 : ans='NO' print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : int := l->indexOf(1) - 1 ; var t : int := l->indexOf(n) - 1 ; var ans : String := 'YES' ; if l[(x + 1) mod n+1] = 2 then ( var y : int := 3 ; for i : Integer.subrange(2, n-1) do ( if l[(x + i) mod n+1] /= y then ( ans := 'NO' ; break ) else skip ; y := y + 1) ) else (if l[(t + 1) mod n+1] = n - 1 then ( y := n - 2 ; for i : Integer.subrange(2, n-1) do ( if l[(t + i) mod n+1] /= y then ( ans := 'NO' ; break ) else skip ; y := y - 1) ) else (if n /= 1 then ( ans := 'NO' ) else skip ) ) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,received): not_relayed=received.copy() for t in range(n+1): if len(received)>=n : return t new_not_relayed=set() for person in not_relayed : if person>=1 : if(person-1)not in received : received.add(person-1) new_not_relayed.add(person-1) if person<=n-2 : if(person+1)not in received : received.add(person+1) new_not_relayed.add(person+1) not_relayed=new_not_relayed def main(): n,m=map(int,input().split()) received_people=set(map(lambda x : int(x)-1,input().split())) print(solve(n,received_people.copy())) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(n : OclAny, received : OclAny) : OclAny pre: true post: true activity: var not_relayed : OclAny := received->copy() ; for t : Integer.subrange(0, n + 1-1) do ( if ((received)->size()->compareTo(n)) >= 0 then ( return t ) else skip ; var new_not_relayed : Set := Set{}->union(()) ; for person : not_relayed do ( if person >= 1 then ( if (received)->excludes((person - 1)) then ( execute ((person - 1) : received) ; execute ((person - 1) : new_not_relayed) ) else skip ) else skip ; if (person->compareTo(n - 2)) <= 0 then ( if (received)->excludes((person + 1)) then ( execute ((person + 1) : received) ; execute ((person + 1) : new_not_relayed) ) else skip ) else skip) ; not_relayed := new_not_relayed); operation main() pre: true post: true activity: var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var received_people : Set := Set{}->union(((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ))) ; execute (solve(n, received_people->copy()))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def kmax(arr,k,n): for c in range(k): max_so_far=-float("inf") max_here=0 start=0 end=0 s=0 for i in range(n): max_here+=arr[i] if(max_so_farunion(Sequence{1}->union(Sequence{1}->union(Sequence{-1}->union(Sequence{-3}->union(Sequence{-5}->union(Sequence{6}->union(Sequence{2}->union(Sequence{-6}->union(Sequence{ -2 }))))))))) ; var k1 : int := 3 ; var n1 : int := (arr1)->size() ; kmax(arr1, k1, n1) ; var arr2 : Sequence := Sequence{5}->union(Sequence{1}->union(Sequence{2}->union(Sequence{-6}->union(Sequence{2}->union(Sequence{-1}->union(Sequence{3}->union(Sequence{ 1 }))))))) ; var k2 : int := 2 ; var n2 : int := (arr2)->size() ; kmax(arr2, k2, n2); operation kmax(arr : OclAny, k : OclAny, n : OclAny) pre: true post: true activity: for c : Integer.subrange(0, k-1) do ( var max_so_far : double := -("" + (("inf")))->toReal() ; var max_here : int := 0 ; var start : int := 0 ; var end : int := 0 ; var s : int := 0 ; for i : Integer.subrange(0, n-1) do ( max_here := max_here + arr[i+1] ; if ((max_so_far->compareTo(max_here)) < 0) then ( max_so_far := max_here ; start := s ; end := i ) else skip ; if (max_here < 0) then ( max_here := 0 ; s := i + 1 ) else skip) ; execute ("Maximum non-overlapping sub-array sum")->display() ; for l : Integer.subrange(start, end + 1-1) do ( arr[l+1] := -("" + (("inf")))->toReal())) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ordered(L,n): CW=CCW=True for i in range(n): if L[i]!=i+1 : CW=False for i in range(n): if L[i]!=n-i : CCW=False return CW or CCW q=int(input()) for i in range(q): n=int(input()) p=[int(x)for x in input().split()] status=False for j in range(n): if ordered(p[j :]+p[: j],n): status=True print('YES' if status else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, q-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var status : boolean := false ; for j : Integer.subrange(0, n-1) do ( if ordered(p.subrange(j+1) + p.subrange(1,j), n) then ( status := true ) else skip) ; execute (if status then 'YES' else 'NO' endif)->display()); operation ordered(L : OclAny, n : OclAny) : OclAny pre: true post: true activity: var CW : OclAny := true; var CCW : boolean := true ; for i : Integer.subrange(0, n-1) do ( if L[i+1] /= i + 1 then ( CW := false ) else skip) ; for i : Integer.subrange(0, n-1) do ( if L[i+1] /= n - i then ( CCW := false ) else skip) ; return CW or CCW; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) t=int(input()) while(t): n=int(input()) l=list(int(c)for c in input().split()) p=i=0 while i1 : p+=1 i+=1 print('YES' if p<2 else 'NO') t=t-1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (t) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ; var p : OclAny := 0; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( if (l[i+1] - l[i - 1+1])->abs() > 1 then ( p := p + 1 ) else skip ; i := i + 1) ; execute (if p < 2 then 'YES' else 'NO' endif)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def helper(n,m): c=0 while n!=0 and m!=0 : n-=1 m-=1 if c==0 : c=1 else : c=0 if c==0 : print('Malvika') return else : print('Akshat') n,m=list(map(int,input().split())) helper(n,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; helper(n, m); operation helper(n : OclAny, m : OclAny) pre: true post: true activity: var c : int := 0 ; while n /= 0 & m /= 0 do ( n := n - 1 ; m := m - 1 ; if c = 0 then ( c := 1 ) else ( c := 0 )) ; if c = 0 then ( execute ('Malvika')->display() ; return ) else ( execute ('Akshat')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gameWithSticks(): (m,n)=map(int,input().split()) if(min(m,n)% 2==0): print("Malvika") else : print("Akshat") return gameWithSticks() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; gameWithSticks(); operation gameWithSticks() pre: true post: true activity: ; var Sequence{m, n} : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (Set{m, n}->min() mod 2 = 0) then ( execute ("Malvika")->display() ) else ( execute ("Akshat")->display() ) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input().split() a[0]=min(int(a[0]),int(a[1])) if a[0]% 2==0 : print("Malvika") else : print("Akshat") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := input().split() ; a->first() := Set{("" + ((a->first())))->toInteger(), ("" + ((a[1+1])))->toInteger()}->min() ; if a->first() mod 2 = 0 then ( execute ("Malvika")->display() ) else ( execute ("Akshat")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input().split() a[0]=int(a[0]) a[1]=int(a[1]) d=min(a[0],a[1]) if d % 2==0 : print("Malvika") else : print("Akshat") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := input().split() ; a->first() := ("" + ((a->first())))->toInteger() ; a[1+1] := ("" + ((a[1+1])))->toInteger() ; var d : OclAny := Set{a->first(), a[1+1]}->min() ; if d mod 2 = 0 then ( execute ("Malvika")->display() ) else ( execute ("Akshat")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() a=[int(i)for i in input().split(" ")] cont=0 max_cont=0 for n in a : if n==1 : cont+=1 elif cont>max_cont : max_cont=cont cont=0 else : cont=0 if cont>max_cont : max_cont=cont print(max_cont+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var a : Sequence := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var cont : int := 0 ; var max_cont : int := 0 ; for n : a do ( if n = 1 then ( cont := cont + 1 ) else (if (cont->compareTo(max_cont)) > 0 then ( max_cont := cont ; cont := 0 ) else ( cont := 0 ) ) ) ; if (cont->compareTo(max_cont)) > 0 then ( max_cont := cont ) else skip ; execute (max_cont + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) step=1 while n>2 and m>2 : step+=1 n-=1 m-=1 if n==1 or m==1 : print('Akshat') else : if step % 2 : print('Malvika') else : print('Akshat') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var step : int := 1 ; while n > 2 & m > 2 do ( step := step + 1 ; n := n - 1 ; m := m - 1) ; if n = 1 or m = 1 then ( execute ('Akshat')->display() ) else ( if step mod 2 then ( execute ('Malvika')->display() ) else ( execute ('Akshat')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printParenthesis(str,n): if(n>0): _printParenthesis(str,0,n,0,0); return ; def _printParenthesis(str,pos,n,open,close): if(close==n): for i in str : print(i,end=""); print(); return ; else : if(open>close): str[pos]='}' ; _printParenthesis(str,pos+1,n,open,close+1); if(open; operation printParenthesis(OclType["String"] : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n > 0) then ( _printParenthesis(OclType["String"], 0, n, 0, 0); ) else skip ; return;; operation _printParenthesis(OclType["String"] : OclAny, pos : OclAny, n : OclAny, open : OclAny, close : OclAny) : OclAny pre: true post: true activity: if (close = n) then ( for i : OclType["String"] do ( execute (i)->display();) ; execute (->display(); ; return; ) else ( if ((open->compareTo(close)) > 0) then ( ("" + ([pos+1])) := '}'; ; _printParenthesis(OclType["String"], pos + 1, n, open, close + 1); ) else skip ; if ((open->compareTo(n)) < 0) then ( ("" + ([pos+1])) := '{'; ; _printParenthesis(OclType["String"], pos + 1, n, open + 1, close); ) else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def longestSubarray(a,n,x): count=0 length=0 for i in range(n): if(a[i]>x): count+=1 else : length=max(length,count) count=0 if(count>0): length=max(length,count) return length if __name__=='__main__' : a=[8,25,10,19,19,18,20,11,18] n=len(a) k=13 print(longestSubarray(a,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := Sequence{8}->union(Sequence{25}->union(Sequence{10}->union(Sequence{19}->union(Sequence{19}->union(Sequence{18}->union(Sequence{20}->union(Sequence{11}->union(Sequence{ 18 })))))))) ; n := (a)->size() ; var k : int := 13 ; execute (longestSubarray(a, n, k))->display() ) else skip; operation longestSubarray(a : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var length : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ((a[i+1]->compareTo(x)) > 0) then ( count := count + 1 ) else ( length := Set{length, count}->max() ; count := 0 )) ; if (count > 0) then ( length := Set{length, count}->max() ) else skip ; return length; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(input()) INF=10**18 a_ls=[int(i)for i in sys.stdin.readline().split()] max_ind=1 _max=a_ls[0] min_ind=1 _min=a_ls[0] for i,a in enumerate(a_ls,1): if a>_max : _max=a max_ind=i if a<_min : _min=a min_ind=i flg=abs(_max)>=abs(_min) ls=[] if flg : for i in range(1,n+1): if i!=max_ind : ls.append((max_ind,i)) for i in range(1,n): ls.append((i,i+1)) else : for i in range(1,n+1): if i!=min_ind : ls.append((min_ind,i)) for i in range(n,1,-1): ls.append((i,i-1)) print(len(ls)) for x,y in ls : print(x,y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var INF : double := (10)->pow(18) ; var a_ls : Sequence := sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var max_ind : int := 1 ; var _max : OclAny := a_ls->first() ; var min_ind : int := 1 ; var _min : OclAny := a_ls->first() ; for _tuple : Integer.subrange(1, (a_ls, 1)->size())->collect( _indx | Sequence{_indx-1, (a_ls, 1)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var a : OclAny := _tuple->at(_indx); if (a->compareTo(_max)) > 0 then ( _max := a ; max_ind := i ) else skip ; if (a->compareTo(_min)) < 0 then ( _min := a ; min_ind := i ) else skip) ; var flg : boolean := ((_max)->abs()->compareTo((_min)->abs())) >= 0 ; var ls : Sequence := Sequence{} ; if flg then ( for i : Integer.subrange(1, n + 1-1) do ( if i /= max_ind then ( execute ((Sequence{max_ind, i}) : ls) ) else skip) ; for i : Integer.subrange(1, n-1) do ( execute ((Sequence{i, i + 1}) : ls)) ) else ( for i : Integer.subrange(1, n + 1-1) do ( if i /= min_ind then ( execute ((Sequence{min_ind, i}) : ls) ) else skip) ; for i : Integer.subrange(1 + 1, n)->reverse() do ( execute ((Sequence{i, i - 1}) : ls)) ) ; execute ((ls)->size())->display() ; for _tuple : ls do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np def minimalLength(a,n): dp=np.ones((n+1,n+1))*-1 ; dp1=[0]*n ; for size in range(1,n+1): for i in range(n-size+1): j=i+size-1 ; if(i==j): dp[i][j]=a[i]; else : for k in range(i,j): if(dp[i][k]!=-1 and dp[i][k]==dp[k+1][j]): dp[i][j]=dp[i][k]+1 ; for i in range(n): dp1[i]=int(1e7); for i in range(n): for j in range(i+1): if(dp[j][i]!=-1): if(j==0): dp1[i]=1 ; else : dp1[i]=min(dp1[i],dp1[j-1]+1); return dp1[n-1]; if __name__=="__main__" : n=7 ; a=[3,3,4,4,4,3,3]; print(minimalLength(a,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 7; ; a := Sequence{3}->union(Sequence{3}->union(Sequence{4}->union(Sequence{4}->union(Sequence{4}->union(Sequence{3}->union(Sequence{ 3 })))))); ; execute (minimalLength(a, n))->display(); ) else skip; operation minimalLength(a : OclAny, n : OclAny) pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(MatrixLib.singleValueMatrix(Sequence{n + 1, n + 1}, 1.0), -1); ; var dp1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; for size : Integer.subrange(1, n + 1-1) do ( for i : Integer.subrange(0, n - size + 1-1) do ( var j : double := i + size - 1; ; if (i = j) then ( dp[i+1][j+1] := a[i+1]; ) else ( for k : Integer.subrange(i, j-1) do ( if (dp[i+1][k+1] /= -1 & dp[i+1][k+1] = dp[k + 1+1][j+1]) then ( dp[i+1][j+1] := dp[i+1][k+1] + 1; ) else skip) ))) ; for i : Integer.subrange(0, n-1) do ( dp1[i+1] := ("" + ((("1e7")->toReal())))->toInteger();) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, i + 1-1) do ( if (dp[j+1][i+1] /= -1) then ( if (j = 0) then ( dp1[i+1] := 1; ) else ( dp1[i+1] := Set{dp1[i+1], dp1[j - 1+1] + 1}->min(); ) ) else skip)) ; return dp1[n - 1+1];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def foo(xs,n): largest=-10**6 smallest=10**6 largest_i=-1 smallest_i=-1 for i,x in enumerate(xs): if largestx : smallest=x smallest_i=i ys=[] if smallest<0 and abs(smallest)>largest : for i in range(n-2,-1,-1): while xs[i+1]xs[i]: xs[i]+=largest ys.append((largest_i,i)) if xs[i]>largest : largest_i=i largest=xs[i] return ys if __name__=="__main__" : n=int(input()) xs=list(map(int,input().split())) ys=foo(xs,n) print(len(ys)) for i,j in ys : print("%d %d" %(i+1,j+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; xs := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; ys := foo(xs, n) ; execute ((ys)->size())->display() ; for _tuple : ys do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); execute (StringLib.format("%d %d",Sequence{i + 1, j + 1}))->display()) ) else skip; operation foo(xs : OclAny, n : OclAny) : OclAny pre: true post: true activity: var largest : double := (-10)->pow(6) ; var smallest : double := (10)->pow(6) ; var largest_i : int := -1 ; var smallest_i : int := -1 ; for _tuple : Integer.subrange(1, (xs)->size())->collect( _indx | Sequence{_indx-1, (xs)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); if (largest->compareTo(x)) < 0 then ( largest := x ; largest_i := i ) else skip ; if (smallest->compareTo(x)) > 0 then ( smallest := x ; smallest_i := i ) else skip) ; var ys : Sequence := Sequence{} ; if smallest < 0 & ((smallest)->abs()->compareTo(largest)) > 0 then ( for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( while (xs[i + 1+1]->compareTo(xs[i+1])) < 0 do ( xs[i+1] := xs[i+1] + smallest ; execute ((Sequence{smallest_i, i}) : ys) ; if (xs[i+1]->compareTo(smallest)) < 0 then ( smallest_i := i ; smallest := xs[i+1] ) else skip)) ) else ( for i : Integer.subrange(1, n-1) do ( while (xs[i - 1+1]->compareTo(xs[i+1])) > 0 do ( xs[i+1] := xs[i+1] + largest ; execute ((Sequence{largest_i, i}) : ys) ; if (xs[i+1]->compareTo(largest)) > 0 then ( largest_i := i ; largest := xs[i+1] ) else skip)) ) ; return ys; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.read n,*a=map(int,read().split()) def output(x,y): print('{}{}'.format(x+1,y+1)) mx=max(a) mxi=a.index(mx) mn=min(a) mni=a.index(mn) print(2*n-1) if abs(mx)>=abs(mn)and mx>=0 : for i in range(n): if mxi!=i : output(mxi,i) output(mxi,mxi) for i in range(1,n): output(i-1,i) elif abs(mx)collect( _x | (OclType["int"])->apply(_x) ) ; skip ; var mx : OclAny := (a)->max() ; var mxi : int := a->indexOf(mx) - 1 ; var mn : OclAny := (a)->min() ; var mni : int := a->indexOf(mn) - 1 ; execute (2 * n - 1)->display() ; if ((mx)->abs()->compareTo((mn)->abs())) >= 0 & mx >= 0 then ( for i : Integer.subrange(0, n-1) do ( if mxi /= i then ( output(mxi, i) ) else skip) ; output(mxi, mxi) ; for i : Integer.subrange(1, n-1) do ( output(i - 1, i)) ) else (if ((mx)->abs()->compareTo((mn)->abs())) < 0 & mn < 0 then ( for i : Integer.subrange(0, n-1) do ( if mni /= i then ( output(mni, i) ) else skip) ; output(mni, mni) ; for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( output(i, i - 1)) ) else skip); operation output(x : OclAny, y : OclAny) pre: true post: true activity: execute (StringLib.interpolateStrings('{}{}', Sequence{x + 1, y + 1}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) count=0 ans=[] mi=min(a) ma=max(a) plus=True if ma>=0 and mi<=0 : if abs(mi)0 if plus : for i in range(1,n): ans.append([i,i+1]) else : for i in range(n-1): ans.append([n-i,n-i-1]) print(count+n-1) for a in ans : print("{}{}".format(a[0],a[1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : int := 0 ; var ans : Sequence := Sequence{} ; var mi : OclAny := (a)->min() ; var ma : OclAny := (a)->max() ; var plus : boolean := true ; if ma >= 0 & mi <= 0 then ( if ((mi)->abs()->compareTo(ma)) < 0 then ( plus := true ; var idx : int := a->indexOf(ma) - 1 + 1 ) else ( plus := false ; idx := a->indexOf(mi) - 1 + 1 ) ; for i : Integer.subrange(1, n + 1-1) do ( if i = idx then ( continue ) else skip ; execute ((Sequence{idx}->union(Sequence{ i })) : ans)) ; count := count + n - 1 ) else ( plus := ma > 0 ) ; if plus then ( for i : Integer.subrange(1, n-1) do ( execute ((Sequence{i}->union(Sequence{ i + 1 })) : ans)) ) else ( for i : Integer.subrange(0, n - 1-1) do ( execute ((Sequence{n - i}->union(Sequence{ n - i - 1 })) : ans)) ) ; execute (count + n - 1)->display() ; for a : ans do ( execute (StringLib.interpolateStrings("{}{}", Sequence{a->first(), a[1+1]}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np n=int(input()) a=list(map(int,input().split())) print(2*n) if a[np.argmax(a)]<=-a[np.argmin(a)]: cnt=len(a)-1 for i in range(0,len(a)): print(str(np.argmin(a)+1)+" "+str(cnt+1)) a[cnt]+=a[np.argmin(a)] print(str(np.argmin(a)+1)+" "+str(cnt+1)) a[cnt]+=a[np.argmin(a)] cnt-=1 ; else : cnt=0 for i in range(0,len(a)): print(str(np.argmax(a)+1)+" "+str(cnt+1)) a[cnt]+=a[np.argmax(a)] print(str(np.argmax(a)+1)+" "+str(cnt+1)) a[cnt]+=a[np.argmax(a)] cnt+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (2 * n)->display() ; if (a[+1]->compareTo(-a[+1])) <= 0 then ( var cnt : double := (a)->size() - 1 ; for i : Integer.subrange(0, (a)->size()-1) do ( execute (("" + (( + 1))) + " " + ("" + ((cnt + 1))))->display() ; a[cnt+1] := a[cnt+1] + a[+1] ; execute (("" + (( + 1))) + " " + ("" + ((cnt + 1))))->display() ; a[cnt+1] := a[cnt+1] + a[+1] ; cnt := cnt - 1;) ) else ( cnt := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( execute (("" + (( + 1))) + " " + ("" + ((cnt + 1))))->display() ; a[cnt+1] := a[cnt+1] + a[+1] ; execute (("" + (( + 1))) + " " + ("" + ((cnt + 1))))->display() ; a[cnt+1] := a[cnt+1] + a[+1] ; cnt := cnt + 1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys class Node : __slots__=['key','left','right'] def __init__(self,key): self.key=key self.left=self.right=None class BST : __slots__=['root'] def __init__(self): self.root=None def insert(self,key): x,y=self.root,None while x!=None : x,y=x.left if keyexists( _x | result = _x ); static attribute __slots__ : Sequence := Sequence{'key'}->union(Sequence{'left'}->union(Sequence{ 'right' })); attribute key : OclAny := key; attribute left : OclAny := null; var self.right : OclAny := null; operation initialise(key : OclAny) : Node pre: true post: true activity: self.key := key ; self.left := null; var self.right : OclAny := null; return self; } class BST { static operation newBST() : BST pre: true post: BST->exists( _x | result = _x ); static attribute __slots__ : Sequence := Sequence{ 'root' }; attribute root : OclAny := null; operation initialise() : BST pre: true post: true activity: self.root := null; return self; operation insert(key : OclAny) pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{self.root,null} ; while x /= null do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{if (key->compareTo(x.key)) < 0 then x.left else x.right endif,x}) ; if y = null then ( self.root := (Node.newNode()).initialise(key) ) else (if (key->compareTo(y.key)) < 0 then ( y.left := (Node.newNode()).initialise(key) ) else ( y.right := (Node.newNode()).initialise(key) ) ) ; operation print_tree() pre: true post: true activity: skip ; skip ; execute (inorder(self.root))->display() ; execute (preorder(self.root))->display(); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var tree : BST := (BST.newBST()).initialise() ; input() ; for e : OclFile["System.in"] do ( if e->first() = 'i' then ( tree := tree.insertAt(("" + ((e.subrange(7+1))))->toInteger()+1, ("" + ((e.subrange(7+1))))->toInteger()) ) else ( tree.print_tree() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans=1 ; def one_count(data,i,count): global ans count+=1 if data[i+1]==1 : one_count(data,i+1,count) elif ans<=count : ans=count+1 N=int(input()) data=list(map(int,input().split())) data.append(0) for i in range(N): count=0 ; if data[i]==1 : one_count(data,i,count) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute ans : OclAny; operation initialise() pre: true post: true activity: var ans : int := 1; ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; data := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((0) : data) ; for i : Integer.subrange(0, N-1) do ( count := 0; ; if data[i+1] = 1 then ( one_count(data, i, count) ) else skip) ; execute (ans)->display(); operation one_count(data : OclAny, i : OclAny, count : OclAny) pre: true post: true activity: skip ; count := count + 1 ; if data[i + 1+1] = 1 then ( one_count(data, i + 1, count) ) else (if (ans->compareTo(count)) <= 0 then ( ans := count + 1 ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**9) def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) from collections import defaultdict class Node : def __init__(self,key): self.key=key self.par=-1 self.left=-1 self.right=-1 root=None nodes=defaultdict(lambda : None) def insert(z): global root y=None x=root while x is not None : y=x if z.keyexists( _x | result = _x ); attribute key : OclAny := key; attribute par : int := -1; attribute left : int := -1; attribute right : int := -1; operation initialise(key : OclAny) : Node pre: true post: true activity: self.key := key ; self.par := -1 ; self.left := -1 ; self.right := -1; return self; } class FromPython { attribute root : OclAny; operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(9)) ; skip ; skip ; skip ; skip ; skip ; skip ; var root : OclAny := null ; var nodes : OclAny := defaultdict(lambda $$ : OclAny in (null)) ; skip ; skip ; var N : OclAny := INT() ; for _anon : Integer.subrange(0, N-1) do ( var instr : String := (OclFile["System.in"]).readLine() ; if instr = 'print' then ( var preo : Sequence := Sequence{} ; var ino : Sequence := Sequence{} ; tree_walk(root) ; execute ('')->display() ; execute ('')->display() ) else ( var _anon : OclAny := null; Sequence{_anon,key} := instr.split() ; key := ("" + ((key)))->toInteger() ; node := (Node.newNode()).initialise(key) ; nodes[key+1] := node ; insert(node) )); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation insert(z : OclAny) pre: true post: true activity: skip ; var y : OclAny := null ; var x : OclAny := root ; while not(x <>= null) do ( y := x ; if (z.key->compareTo(x.key)) < 0 then ( x := nodes[x.left+1] ) else ( x := nodes[x.right+1] )) ; if y <>= null then ( z.par := -1 ) else ( z.par := y.key ) ; if y <>= null then ( root := z ) else (if (z.key->compareTo(y.key)) < 0 then ( y.left := z.key ) else ( y.right := z.key ) ) ; operation tree_walk(node : OclAny) pre: true post: true activity: execute ((node.key) : preo) ; if node.left /= -1 then ( tree_walk(nodes[node.left+1]) ) else skip ; execute ((node.key) : ino) ; if node.right /= -1 then ( tree_walk(nodes[node.right+1]) ) else skip ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class BinaryTreeNode(): def __init__(self,left=None,right=None,val=None): self.left=left self.right=right self.val=val class BinarySearchTree(): def __init__(self): self.root=None def insert(self,val): y=None x=self.root while x!=None : y=x if valexists( _x | result = _x ); attribute left : OclAny := left; attribute right : OclAny := right; attribute val : OclAny := val; operation initialise(left : OclAny,right : OclAny,val : OclAny) : pre: true post: true activity: self.left := left ; self.right := right ; self.val := val; return self; } class BinarySearchTree { static operation newBinarySearchTree() : BinarySearchTree pre: true post: BinarySearchTree->exists( _x | result = _x ); attribute root : OclAny := null; operation initialise() : pre: true post: true activity: self.root := null; return self; operation insert(val : OclAny) pre: true post: true activity: var y : OclAny := null ; var x : OclAny := self.root ; while x /= null do ( y := x ; if (val->compareTo(x.val)) < 0 then ( x := x.left ) else ( x := x.right )) ; var node : BinaryTreeNode := (BinaryTreeNode.newBinaryTreeNode()).initialise((argument (test (logical_test (comparison (expr (atom (name val)))))) = (test (logical_test (comparison (expr (atom (name val)))))))) ; if y = null then ( self.root := node ) else (if (node.val->compareTo(y.val)) < 0 then ( y.left := node ) else ( y.right := node ) ) ; operation preorder() : OclAny pre: true post: true activity: self.preorder_list := Sequence{} ; self.preorder_bfs(self.root) ; return self.preorder_list; operation preorder_bfs(u : OclAny) pre: true post: true activity: if u = null then ( return ) else skip ; (expr (atom (name self)) (trailer . (name preorder_list)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)) (trailer . (name val)))))))) )))) ; self.preorder_bfs(u.left) ; self.preorder_bfs(u.right); operation inorder() : OclAny pre: true post: true activity: self.inorder_list := Sequence{} ; self.inorder_dfs(self.root) ; return self.inorder_list; operation inorder_dfs(u : OclAny) pre: true post: true activity: if u = null then ( return ) else skip ; self.inorder_dfs(u.left) ; (expr (atom (name self)) (trailer . (name inorder_list)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)) (trailer . (name val)))))))) )))) ; self.inorder_dfs(u.right); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var bst : BinarySearchTree := (BinarySearchTree.newBinarySearchTree()).initialise() ; for i : Integer.subrange(0, m-1) do ( var op : String := (OclFile["System.in"]).readLine() ; if op = 'print' then ( print_elements(bst.inorder()) ; print_elements(bst.preorder()) ) else ( var num : int := ("" + ((op.subrange(7+1))))->toInteger() ; bst := bst.insertAt(num+1, num) )); operation print_elements(arr : OclAny) pre: true post: true activity: execute (' ' + StringLib.sumStringsWithSeparator((arr->select(item | true)->collect(item | (("" + ((item)))))), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque import sys readline=sys.stdin.readline write=sys.stdout.write root=None def insert(z): global root y=None x=root while x is not None : y=x if z[2]toInteger() ; var ans : Sequence := Sequence{} ; for m : Integer.subrange(0, M-1) do ( var cmd : OclAny := null; (declareIfNecessary (star_expr * (expr (atom (name V)))) ,) Sequence{cmd,(testlist_star_expr (star_expr * (expr (atom (name V)))) ,)} := readline().split() ; if cmd = "print" then ( ans := ans->union(debug()) ) else ( insert(Sequence{null}->union(Sequence{null}->union(Sequence{("" + ((V->first())))->toInteger()}->union(Sequence{ null })))) )) ; write(StringLib.sumStringsWithSeparator((ans), "\n")) ; write("\n"); operation insert(z : OclAny) pre: true post: true activity: skip ; var y : OclAny := null ; var x : OclAny := root ; while not(x <>= null) do ( y := x ; if (z[2+1]->compareTo(x[2+1])) < 0 then ( x := x->first() ) else ( x := x[1+1] )) ; z[3+1] := y ; if y <>= null then ( root := z ) else (if (z[2+1]->compareTo(y[2+1])) < 0 then ( y->first() := z ) else ( y[1+1] := z ) ) ; operation debug() : OclAny pre: true post: true activity: var s0 : Sequence := Sequence{ "" } ; var s1 : Sequence := Sequence{ "" } ; skip ; dfs(root) ; return StringLib.sumStringsWithSeparator((s1), " "), StringLib.sumStringsWithSeparator((s0), " "); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys class Node(object): def __init__(self,data): self.data=data self.left,self.right=None,None def insert(self,data): if dataexists( _x | result = _x ); attribute data : OclAny := data; attribute (testlist_star_expr (test (logical_test (comparison (expr (atom (name self)) (trailer . (name left)))))) , (test (logical_test (comparison (expr (atom (name self)) (trailer . (name right))))))) : OclAny := null,null; operation initialise(data : OclAny) : pre: true post: true activity: self.data := data ; var self.left : OclAny := null; var self.right : OclAny := null; Sequence{self.left,self.right} := Sequence{null,null}; return self; operation insert(data : OclAny) : OclAny pre: true post: true activity: if (data->compareTo(self.data)) < 0 then ( if self.left <>= null then ( self.left := Node(data) ) else ( (expr (atom (name self)) (trailer . (name left)) (trailer . (name insert) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name data)))))))) )))) ) ) else ( if self.right <>= null then ( self.right := Node(data) ) else ( (expr (atom (name self)) (trailer . (name right)) (trailer . (name insert) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name data)))))))) )))) ) ) ; return null; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var _input : OclAny := (OclFile["System.in"]).readlines() ; var array_length : int := ("" + ((_input->first())))->toInteger() ; var command_list : Sequence := ((_input->tail())->collect( _x | (lambda x : OclAny in (x.split()))->apply(_x) )) ; var flag : OclAny := null; var tree_root : OclAny := null; Sequence{flag,tree_root} := Sequence{false,null} ; for each : command_list do ( Sequence{command,content} := Sequence{each->first(),each->last()} ; if (not(flag)) & command->hasPrefix('in') then ( var tree_root : Node := (Node.newNode()).initialise((argument (test (logical_test (comparison (expr (atom (name data)))))) = (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name content)))))))) ))))))))) ; var flag : boolean := true ; continue ) else skip ; action((argument (test (logical_test (comparison (expr (atom (name command)))))) = (test (logical_test (comparison (expr (atom (name command))))))), (argument (test (logical_test (comparison (expr (atom (name content)))))) = (test (logical_test (comparison (expr (atom (name content))))))))) ) else skip; operation inorder(node : OclAny) pre: true post: true activity: if node.left then ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return inorder(node.left) ) else skip ; if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return node.data ; if node.right then ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return inorder(node.right) ) else skip; operation preorder(node : OclAny) pre: true post: true activity: if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return node.data ; for n : Sequence{node.left}->union(Sequence{ node.right }) do ( if n then ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return preorder(n) ) else skip); operation action(command : OclAny, content : OclAny) : OclAny pre: true post: true activity: if command->first() = 'i' then ( tree_root := tree_root.insertAt((argument (test (logical_test (comparison (expr (atom (name data)))))) = (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name content)))))))) ))))))))+1, ("" + ((content)))->toInteger()) ) else (if command->first() = 'p' then ( execute ('')->display() ; execute ('')->display() ) else skip) ; return null; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def possibleOrNot(a1,a2,b1,b2,c1,c2): dis1=(pow(b1-a1,2)+pow(b2-a2,2)) dis2=(pow(c1-b1,2)+pow(c2-b2,2)) if(dis1!=dis2): print("No") elif(b1==((a1+c1)//2.0)and b2==((a2+c2)//2.0)): print("No") else : print("Yes") a1,b1,c1=1,2,3 a2=b2=c2=0 possibleOrNot(a1,a2,b1,b2,c1,c2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{a1,b1,c1} := Sequence{1,2,3} ; a2 := a2(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b2)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c2)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; possibleOrNot(a1, a2, b1, b2, c1, c2); operation possibleOrNot(a1 : OclAny, a2 : OclAny, b1 : OclAny, b2 : OclAny, c1 : OclAny, c2 : OclAny) pre: true post: true activity: var dis1 : double := ((b1 - a1)->pow(2) + (b2 - a2)->pow(2)) ; var dis2 : double := ((c1 - b1)->pow(2) + (c2 - b2)->pow(2)) ; if (dis1 /= dis2) then ( execute ("No")->display() ) else (if (b1 = ((a1 + c1) div 2.0) & b2 = ((a2 + c2) div 2.0)) then ( execute ("No")->display() ) else ( execute ("Yes")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def findCount(n,sum): start=math.pow(10,n-1); end=math.pow(10,n)-1 ; count=0 ; i=start ; while(i<=end): cur=0 ; temp=i ; while(temp!=0): cur+=temp % 10 ; temp=temp//10 ; if(cur==sum): count=count+1 ; i+=9 ; else : i=i+1 ; print(count); n=3 ; sum=5 ; findCount(n,sum); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 3; ; sum := 5; ; findCount(n, sum);; operation findCount(n : OclAny, sum : OclAny) pre: true post: true activity: var start : double := (10)->pow(n - 1); ; var end : double := (10)->pow(n) - 1; ; var count : int := 0; ; var i : OclAny := start; ; while ((i->compareTo(end)) <= 0) do ( var cur : int := 0; ; var temp : OclAny := i; ; while (temp /= 0) do ( cur := cur + temp mod 10; ; temp := temp div 10;) ; if (cur = sum) then ( count := count + 1; ; i := i + 9; ) else ( i := i + 1; )) ; execute (count)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def getRightMostSetBit(n): return int(math.log2(n &-n))+1 def posOfRightMostSameBit(m,n): return getRightMostSetBit(~(m ^ n)) m,n=16,7 print("Position=",posOfRightMostSameBit(m,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; Sequence{m,n} := Sequence{16,7} ; execute ("Position=")->display(); operation getRightMostSetBit(n : OclAny) : OclAny pre: true post: true activity: return ("" + (()))->toInteger() + 1; operation posOfRightMostSameBit(m : OclAny, n : OclAny) : OclAny pre: true post: true activity: return getRightMostSetBit(MathLib.bitwiseNot((MathLib.bitwiseXor(m, n)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Calculate_GST(org_cost,N_price): return(((N_price-org_cost)*100)/org_cost); org_cost=100 N_price=120 print("GST=",end='') print(round(Calculate_GST(org_cost,N_price)),end='') print("%") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; org_cost := 100 ; N_price := 120 ; execute ("GST=")->display() ; execute ((Calculate_GST(org_cost, N_price))->round())->display() ; execute ("%")->display(); operation Calculate_GST(org_cost : OclAny, N_price : OclAny) pre: true post: true activity: return (((N_price - org_cost) * 100) / org_cost);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printInSortedOrder(arr,n): index=[0]*n for i in range(n): index[i]=i for i in range(n-1): min=i for j in range(i+1,n): if(arr[index[min]]>arr[index[j]]): min=j if(min!=i): index[min],index[i]=index[i],index[min] for i in range(n): print(arr[index[i]],end=" ") if __name__=="__main__" : arr=["geeks","quiz","geeks","for"] n=4 printInSortedOrder(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{"geeks"}->union(Sequence{"quiz"}->union(Sequence{"geeks"}->union(Sequence{ "for" }))) ; n := 4 ; printInSortedOrder(arr, n) ) else skip; operation printInSortedOrder(arr : OclAny, n : OclAny) pre: true post: true activity: var index : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( index[i+1] := i) ; for i : Integer.subrange(0, n - 1-1) do ( var min : OclAny := i ; for j : Integer.subrange(i + 1, n-1) do ( if ((arr[index[min+1]+1]->compareTo(arr[index[j+1]+1])) > 0) then ( min := j ) else skip) ; if (min /= i) then ( var index[min+1] : OclAny := null; var index[i+1] : OclAny := null; Sequence{index[min+1],index[i+1]} := Sequence{index[i+1],index[min+1]} ) else skip) ; for i : Integer.subrange(0, n-1) do ( execute (arr[index[i+1]+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=map(int,input().split()) s=x=y=0 for i in range(n): h=int(input()) s,x,y=s+x,h,max(h,y) print(max((t-x-s)//y+2,1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; s := s(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name y)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for i : Integer.subrange(0, n-1) do ( var h : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{s,x,y} := Sequence{s + x,h,Set{h, y}->max()} ; execute (Set{(t - x - s) div y + 2, 1}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=input() mi=m.replace('','') mi=list(map(str,mi.split("0"))) ans=1 for i in mi : ans=max(ans,len(i)+1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : String := (OclFile["System.in"]).readLine() ; var mi : String := m.replace('', '') ; mi := ((mi.split("0"))->collect( _x | (OclType["String"])->apply(_x) )) ; var ans : int := 1 ; for i : mi->characters() do ( ans := Set{ans, (i)->size() + 1}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,t=map(int,input().split()) h=[0]*n for i in range(n): h[i]=int(input()) t_first=[0]*(n+1) w=[0]*n print(math.ceil((t+0.5)/h[0])) t_first[1]=h[0] for i in range(1,n): if t_first[i]>t : print(1) t_first[i+1]=t_first[i]+h[i] continue if h[i-1]+w[i-1]>h[i]: w[i]=(h[i-1]+w[i-1])-h[i] t_first[i+1]=t_first[i]+h[i] delta_t=t-t_first[i] temp=math.ceil((delta_t+0.5)/(h[i]+w[i])) if delta_t %(h[i]+w[i])>=h[i]: print(temp+1) else : print(temp) else : w[i]=0 t_first[i+1]=t_first[i]+h[i] delta_t=t-t_first[i] print(math.ceil((delta_t+0.5)/h[i])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( h[i+1] := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var t_first : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var w : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; execute (((t + 0.5) / h->first())->ceil())->display() ; t_first[1+1] := h->first() ; for i : Integer.subrange(1, n-1) do ( if (t_first[i+1]->compareTo(t)) > 0 then ( execute (1)->display() ; t_first[i + 1+1] := t_first[i+1] + h[i+1] ; continue ) else skip ; if (h[i - 1+1] + w[i - 1+1]->compareTo(h[i+1])) > 0 then ( w[i+1] := (h[i - 1+1] + w[i - 1+1]) - h[i+1] ; t_first[i + 1+1] := t_first[i+1] + h[i+1] ; var delta_t : double := t - t_first[i+1] ; var temp : double := ((delta_t + 0.5) / (h[i+1] + w[i+1]))->ceil() ; if (delta_t mod (h[i+1] + w[i+1])->compareTo(h[i+1])) >= 0 then ( execute (temp + 1)->display() ) else ( execute (temp)->display() ) ) else ( w[i+1] := 0 ; t_first[i + 1+1] := t_first[i+1] + h[i+1] ; delta_t := t - t_first[i+1] ; execute (((delta_t + 0.5) / h[i+1])->ceil())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b=map(int,input().split()) if a==0 : print(1) elif b==0 : print(a+1) elif a>0 and b>0 : print(a+b*2+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 0 then ( execute (1)->display() ) else (if b = 0 then ( execute (a + 1)->display() ) else (if a > 0 & b > 0 then ( execute (a + b * 2 + 1)->display() ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(a,b): if a==0 : print(1) else : print(a+b*2+1) t=int(input()) while t : t-=1 a,b=map(int,input().split()) f(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( t := t - 1 ; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; f(a, b)); operation f(a : OclAny, b : OclAny) pre: true post: true activity: if a = 0 then ( execute (1)->display() ) else ( execute (a + b * 2 + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : t-=1 a,b=map(int,input().split()) if a==0 : print(1) else : print(a+2*b+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( t := t - 1 ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 0 then ( execute (1)->display() ) else ( execute (a + 2 * b + 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b=map(int,input().split()) if a==0 : b=0 print((b*2)+a+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 0 then ( var b : int := 0 ) else skip ; execute ((b * 2) + a + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a,b=map(int,input().split()) if(a==0): print(1) else : print(a+(b*2)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a = 0) then ( execute (1)->display() ) else ( execute (a + (b * 2) + 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,data): self.data=data self.left=None self.right=None def findPathUtil(root : Node,k : int,path : list,flag : int): global ans if root is None : return if root.data>=k : flag=1 if root.left is None and root.right is None : if flag : ans=1 print("(",end="") for i in range(len(path)): print(path[i],end=",") print(root.data,end="),") return path.append(root.data) findPathUtil(root.left,k,path,flag) findPathUtil(root.right,k,path,flag) path.pop() def findPath(root : Node,k : int): global ans flag=0 ans=0 v=[] findPathUtil(root,k,v,flag) if ans==0 : print(-1) if __name__=="__main__" : ans=0 k=25 root=Node(10) root.left=Node(5) root.right=Node(8) root.left.left=Node(29) root.left.right=Node(2) root.right.right=Node(98) root.right.left=Node(1) root.right.right.right=Node(50) root.left.left.left=Node(20) findPath(root,k) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.left := null ; self.right := null; return self; } class FromPython { attribute ans : OclAny; attribute ans : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( ans := 0 ; var k : int := 25 ; var root : Node := (Node.newNode()).initialise(10) ; root.left := (Node.newNode()).initialise(5) ; root.right := (Node.newNode()).initialise(8) ; root.left.left := (Node.newNode()).initialise(29) ; root.left.right := (Node.newNode()).initialise(2) ; root.right.right := (Node.newNode()).initialise(98) ; root.right.left := (Node.newNode()).initialise(1) ; root.right.right.right := (Node.newNode()).initialise(50) ; root.left.left.left := (Node.newNode()).initialise(20) ; findPath(root, k) ) else skip; operation findPathUtil(root : Node, k : int, path : Sequence(OclAny), flag : int) pre: true post: true activity: skip ; if root <>= null then ( return ) else skip ; if (root.data->compareTo(k)) >= 0 then ( var flag : int := 1 ) else skip ; if root.left <>= null & root.right <>= null then ( if flag then ( ans := 1 ; execute ("(")->display() ; for i : Integer.subrange(0, (path)->size()-1) do ( execute (path[i+1])->display()) ; execute (root.data)->display() ) else skip ; return ) else skip ; execute ((root.data) : path) ; findPathUtil(root.left, k, path, flag) ; findPathUtil(root.right, k, path, flag) ; path := path->front(); operation findPath(root : Node, k : int) pre: true post: true activity: skip ; flag := 0 ; ans := 0 ; var v : Sequence := Sequence{} ; findPathUtil(root, k, v, flag) ; if ans = 0 then ( execute (-1)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def equation_plane(x1,y1,z1,x2,y2,z2,x3,y3,z3,x,y,z): a1=x2-x1 b1=y2-y1 c1=z2-z1 a2=x3-x1 b2=y3-y1 c2=z3-z1 a=b1*c2-b2*c1 b=a2*c1-a1*c2 c=a1*b2-b1*a2 d=(-a*x1-b*y1-c*z1) if(a*x+b*y+c*z+d==0): print("Coplanar") else : print("Not Coplanar") x1=3 y1=2 z1=-5 x2=-1 y2=4 z2=-3 x3=-3 y3=8 z3=-5 x4=-3 y4=2 z4=1 equation_plane(x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x1 := 3 ; y1 := 2 ; z1 := -5 ; x2 := -1 ; y2 := 4 ; z2 := -3 ; x3 := -3 ; y3 := 8 ; z3 := -5 ; var x4 : int := -3 ; var y4 : int := 2 ; var z4 : int := 1 ; equation_plane(x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4); operation equation_plane(x1 : OclAny, y1 : OclAny, z1 : OclAny, x2 : OclAny, y2 : OclAny, z2 : OclAny, x3 : OclAny, y3 : OclAny, z3 : OclAny, x : OclAny, y : OclAny, z : OclAny) pre: true post: true activity: var a1 : double := x2 - x1 ; var b1 : double := y2 - y1 ; var c1 : double := z2 - z1 ; var a2 : double := x3 - x1 ; var b2 : double := y3 - y1 ; var c2 : double := z3 - z1 ; var a : double := b1 * c2 - b2 * c1 ; var b : double := a2 * c1 - a1 * c2 ; var c : double := a1 * b2 - b1 * a2 ; var d : double := (-a * x1 - b * y1 - c * z1) ; if (a * x + b * y + c * z + d = 0) then ( execute ("Coplanar")->display() ) else ( execute ("Not Coplanar")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=[[i-1 for i in list(map(int,input().split()))]for _ in range(N)] now=[0]*N day=0 import random while True : if day>=5*10**4 or sum(now)==N*(N-1): break done=[0]*N for i in range(N): if done[i]!=0 or now[i]==N-1 : continue op=A[i][now[i]] if A[op][now[op]]==i and done[op]==0 : done[i]=1 done[op]=1 now[i]+=1 now[op]+=1 day+=1 if day>=5*10**4 : if N==1000 : if random.random()<0.5 : print(N*(N-1)//2) else : print(-1) else : print(-1) else : print(day) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->select(i | true)->collect(i | (i - 1)))) ; var now : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var day : int := 0 ; skip ; while true do ( if (day->compareTo(5 * (10)->pow(4))) >= 0 or (now)->sum() = N * (N - 1) then ( break ) else skip ; var done : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for i : Integer.subrange(0, N-1) do ( if done[i+1] /= 0 or now[i+1] = N - 1 then ( continue ) else skip ; var op : OclAny := A[i+1][now[i+1]+1] ; if A[op+1][now[op+1]+1] = i & done[op+1] = 0 then ( done[i+1] := 1 ; done[op+1] := 1 ; now[i+1] := now[i+1] + 1 ; now[op+1] := now[op+1] + 1 ) else skip) ; day := day + 1) ; if (day->compareTo(5 * (10)->pow(4))) >= 0 then ( if N = 1000 then ( if (OclRandom.defaultInstanceOclRandom()).nextDouble() < 0.5 then ( execute (N * (N - 1) div 2)->display() ) else ( execute (-1)->display() ) ) else ( execute (-1)->display() ) ) else ( execute (day)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque N=int(input()) def trans(x): return int(x)-1 A=deque() for _ in range(N): A.append(deque(map(trans,input().split()))) Q=set() def check(i): if len(A[i])==0 : return j=A[i][0] if len(A[j])==0 : return if A[j][0]==i : if i>j : i,j=j,i Q.add((i,j)) for i in range(N): check(i) ans=0 while len(Q)>0 : ans+=1 Q2=Q.copy() Q=set() for q in Q2 : A[q[0]].popleft() A[q[1]].popleft() for q in Q2 : check(q[0]) check(q[1]) for i in range(N): if len(A[i])>0 : print(-1) exit() print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; var A : Sequence := () ; for _anon : Integer.subrange(0, N-1) do ( execute ((((input().split())->collect( _x | (trans)->apply(_x) ))) : A)) ; var Q : Set := Set{}->union(()) ; skip ; for i : Integer.subrange(0, N-1) do ( check(i)) ; var ans : int := 0 ; while (Q)->size() > 0 do ( ans := ans + 1 ; var Q2 : OclAny := Q->copy() ; Q := Set{}->union(()) ; for q : Q2 do ((expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name q)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])) (trailer . (name popleft) (arguments ( )))) ; (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name q)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ])) (trailer . (name popleft) (arguments ( ))))) ; for q : Q2 do ( check(q->first()) ; check(q[1+1]))) ; for i : Integer.subrange(0, N-1) do ( if (A[i+1])->size() > 0 then ( execute (-1)->display() ; exit() ) else skip) ; execute (ans)->display(); operation trans(x : OclAny) : OclAny pre: true post: true activity: return ("" + ((x)))->toInteger() - 1; operation check(i : OclAny) pre: true post: true activity: if (A[i+1])->size() = 0 then ( return ) else skip ; var j : OclAny := A[i+1]->first() ; if (A[j+1])->size() = 0 then ( return ) else skip ; if A[j+1]->first() = i then ( if (i->compareTo(j)) > 0 then ( Sequence{i,j} := Sequence{j,i} ) else skip ; execute ((Sequence{i, j}) : Q) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline for tt in range(int(input())): n=int(input()) A,B=[],[] for i in range(2*n): x,y=map(int,input().split()) if x==0 : B.append(abs(y)) else : A.append(abs(x)) A=sorted(A) B=sorted(B) ans=0 for i in range(n): ans+=((B[i])*(B[i])+(A[i])*(A[i]))**(0.5) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; for tt : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := Sequence{Sequence{},Sequence{}} ; for i : Integer.subrange(0, 2 * n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x = 0 then ( execute (((y)->abs()) : B) ) else ( execute (((x)->abs()) : A) )) ; var A : Sequence := A->sort() ; var B : Sequence := B->sort() ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( ans := ans + (((B[i+1]) * (B[i+1]) + (A[i+1]) * (A[i+1])))->pow((0.5))) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lst_to=[[]for i in range(n**2)] lst_from=[[]for i in range(n**2)] for i in range(n): a=list(map(int,input().split())) for j in range(n-2): i1=i i2=i b=a[j]-1 c=a[j+1]-1 if i1>b : i1,b=b,i1 if i2>c : i2,c=c,i2 lst_to[n*i1+b].append(n*i2+c) lst_from[n*i2+c].append(n*i1+b) que=[] for i in range(n): for j in range(i+1,n): if not lst_from[n*i+j]: que.append(n*i+j) count=0 while que : count+=1 h=[] for u in que : for v in lst_to[u]: lst_from[v].remove(u) if not lst_from[v]: h.append(v) que=h for i in range(n): for j in range(i+1,n): if lst_from[n*i+j]: print(-1) break else : continue break else : print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst_to : Sequence := Integer.subrange(0, (n)->pow(2)-1)->select(i | true)->collect(i | (Sequence{})) ; var lst_from : Sequence := Integer.subrange(0, (n)->pow(2)-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, n-1) do ( var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, n - 2-1) do ( var i1 : OclAny := i ; var i2 : OclAny := i ; var b : double := a[j+1] - 1 ; var c : double := a[j + 1+1] - 1 ; if (i1->compareTo(b)) > 0 then ( Sequence{i1,b} := Sequence{b,i1} ) else skip ; if (i2->compareTo(c)) > 0 then ( Sequence{i2,c} := Sequence{c,i2} ) else skip ; (expr (atom (name lst_to)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name n))) * (expr (atom (name i1)))) + (expr (atom (name b))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name n))) * (expr (atom (name i2)))) + (expr (atom (name c))))))))) )))) ; (expr (atom (name lst_from)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name n))) * (expr (atom (name i2)))) + (expr (atom (name c))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name n))) * (expr (atom (name i1)))) + (expr (atom (name b))))))))) )))))) ; var que : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if not(lst_from[n * i + j+1]) then ( execute ((n * i + j) : que) ) else skip)) ; var count : int := 0 ; while que do ( count := count + 1 ; var h : Sequence := Sequence{} ; for u : que do ( for v : lst_to[u+1] do ((expr (atom (name lst_from)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name remove) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)))))))) )))) ; if not(lst_from[v+1]) then ( execute ((v) : h) ) else skip)) ; que := h) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name lst_from)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (expr (atom (name n))) * (expr (atom (name i)))) + (expr (atom (name j))))))))) ])))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt continue))))))) (stmt (simple_stmt (small_stmt break)))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name count)))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque import sys input=sys.stdin.readline n=int(input()) a=[list(map(lambda x : int(x)-1,input().split()))for _ in range(n)] def calc_idx(x,y): if x>y : x,y=y,x return x+y*(y-1)//2 n_game=n*(n-1)//2 edge=[[]for i in range(n_game)] indegree=[0]*n_game for i in range(n): for j in range(1,n-1): g1=calc_idx(i,a[i][j-1]) g2=calc_idx(i,a[i][j]) edge[g1].append(g2) indegree[g2]+=1 ans=0 cand=[[i for i in range(n_game)if indegree[i]==0],[]] cand=deque([(i,1)for i in range(n_game)if indegree[i]==0]) n_ts=0 while cand : u,day=cand.popleft() ans=max(ans,day) n_ts+=1 for v in edge[u]: indegree[v]-=1 if indegree[v]==0 : cand.append((v,day+1)) if n_ts!=n_game : ans=-1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) )))) ; skip ; var n_game : int := n * (n - 1) div 2 ; var edge : Sequence := Integer.subrange(0, n_game-1)->select(i | true)->collect(i | (Sequence{})) ; var indegree : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n_game) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(1, n - 1-1) do ( var g1 : OclAny := calc_idx(i, a[i+1][j - 1+1]) ; var g2 : OclAny := calc_idx(i, a[i+1][j+1]) ; (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name g1)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name g2)))))))) )))) ; indegree[g2+1] := indegree[g2+1] + 1)) ; var ans : int := 0 ; var cand : Sequence := Sequence{Integer.subrange(0, n_game-1)->select(i | indegree[i+1] = 0)->collect(i | (i))}->union(Sequence{ Sequence{} }) ; cand := (Integer.subrange(0, n_game-1)->select(i | indegree[i+1] = 0)->collect(i | (Sequence{i, 1}))) ; var n_ts : int := 0 ; while cand do ( var u : OclAny := null; var day : OclAny := null; Sequence{u,day} := cand->first() ; cand := cand->tail() ; ans := Set{ans, day}->max() ; n_ts := n_ts + 1 ; for v : edge[u+1] do ( indegree[v+1] := indegree[v+1] - 1 ; if indegree[v+1] = 0 then ( execute ((Sequence{v, day + 1}) : cand) ) else skip)) ; if n_ts /= n_game then ( ans := -1 ) else skip ; execute (ans)->display(); operation calc_idx(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (x->compareTo(y)) > 0 then ( Sequence{x,y} := Sequence{y,x} ) else skip ; return x + y * (y - 1) div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.readline().strip() def input_int(): return int(input()) def input_int_list(): return[int(i)for i in input().split()] def main(): n=input_int() d=dict() for i in range(1,n+1): d[i]=input_int_list()[: :-1] day=0 candi=set(range(1,n+1)) rest=(n*(n-1))//2 while rest : played=set() for a in candi : if d[a]and d[d[a][-1]][-1]and a==d[d[a][-1]][-1]: played.add(a) played.add(d[a][-1]) if not played : break candi.clear() rest-=len(played)//2 for a in played : candi.add(a) d[a].pop() if d[a]: candi.add(d[a][-1]) day+=1 if rest==0 : print(day) else : print(-1) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation input_int() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation input_int_list() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation main() pre: true post: true activity: var n : OclAny := input_int() ; var d : Map := (arguments ( )) ; for i : Integer.subrange(1, n + 1-1) do ( d[i+1] := input_int_list()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ; var day : int := 0 ; var candi : Set := Set{}->union((Integer.subrange(1, n + 1-1))) ; var rest : int := (n * (n - 1)) div 2 ; while rest do ( var played : Set := Set{}->union(()) ; for a : candi do ( if d[a+1] & d[d[a+1]->last()+1]->last() & a = d[d[a+1]->last()+1]->last() then ( execute ((a) : played) ; execute ((d[a+1]->last()) : played) ) else skip) ; if not(played) then ( break ) else skip ; execute (candi /<: candi) ; rest := rest - (played)->size() div 2 ; for a : played do ( execute ((a) : candi) ; (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name pop) (arguments ( )))) ; if d[a+1] then ( execute ((d[a+1]->last()) : candi) ) else skip) ; day := day + 1) ; if rest = 0 then ( execute (day)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=2019 ; def min_modulo(l,r): if(r-l>=MOD): return 0 ; else : ans=MOD-1 ; for i in range(l,r+1): for j in range(i+1,r+1): ans=min(ans,(i*j)% MOD); return ans ; if __name__=="__main__" : l=2020 ; r=2040 ; print(min_modulo(l,r)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : int := 2019; ; skip ; if __name__ = "__main__" then ( l := 2020; r := 2040; ; execute (min_modulo(l, r))->display(); ) else skip; operation min_modulo(l : OclAny, r : OclAny) pre: true post: true activity: if ((r - l->compareTo(MOD)) >= 0) then ( return 0; ) else ( var ans : double := MOD - 1; ; for i : Integer.subrange(l, r + 1-1) do ( for j : Integer.subrange(i + 1, r + 1-1) do ( ans := Set{ans, (i * j) mod MOD}->min();)) ; return ans; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count(arr,N,K): count=0 ans=0 for i in range(N): if(arr[i]==K): count=count+1 else : ans+=(count*(count+1))//2 count=0 ans=ans+(count*(count+1))//2 return ans if __name__=='__main__' : arr=[1,0,0,1,1,0,0] N=len(arr) K=0 print(count(arr,N,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 0 })))))) ; N := (arr)->size() ; K := 0 ; execute (count(arr, N, K))->display() ) else skip; operation count(arr : OclAny, N : OclAny, K : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( if (arr[i+1] = K) then ( count := count + 1 ) else ( ans := ans + (count * (count + 1)) div 2 ; count := 0 )) ; ans := ans + (count * (count + 1)) div 2 ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math data=input().split() A1,A2,A3=int(data[0]),int(data[1]),int(data[2]) H=int(math.sqrt((A2*A3)//A1)) W=A3//H L=A1//W print(4*L+4*W+4*H) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var data : OclAny := input().split() ; var A1 : OclAny := null; var A2 : OclAny := null; var A3 : OclAny := null; Sequence{A1,A2,A3} := Sequence{("" + ((data->first())))->toInteger(),("" + ((data[1+1])))->toInteger(),("" + ((data[2+1])))->toInteger()} ; var H : int := ("" + ((((A2 * A3) div A1)->sqrt())))->toInteger() ; var W : int := A3 div H ; var L : int := A1 div W ; execute (4 * L + 4 * W + 4 * H)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math x,y,z=map(int,input().split()) a=int(x*z/y) b=int(y*z/x) c=int(x*y/z) p=int(math.sqrt(a)) q=int(math.sqrt(b)) r=int(math.sqrt(c)) print((p+q+r)*4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : int := ("" + ((x * z / y)))->toInteger() ; var b : int := ("" + ((y * z / x)))->toInteger() ; var c : int := ("" + ((x * y / z)))->toInteger() ; var p : int := ("" + (((a)->sqrt())))->toInteger() ; var q : int := ("" + (((b)->sqrt())))->toInteger() ; var r : int := ("" + (((c)->sqrt())))->toInteger() ; execute ((p + q + r) * 4)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=int(input()) if n==0 : break count=0 S_keep=list(map(int,input().split())) while 1 : S=[] for i in S_keep : S.append(S_keep.count(i)) if S_keep==S : print(count) print(" ".join(map(str,S))) break else : count+=1 S_keep=S ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var count : int := 0 ; var S_keep : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; while 1 do ( var S : Sequence := Sequence{} ; for i : S_keep do ( execute ((S_keep->count(i)) : S)) ; if S_keep = S then ( execute (count)->display() ; execute (StringLib.sumStringsWithSeparator(((S)->collect( _x | (OclType["String"])->apply(_x) )), " "))->display() ; break ) else ( count := count + 1 ; S_keep := S ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[int(x)for x in input().split()] import math val=math.sqrt(a[0]*a[1]*a[2]) ans=4*((val/a[0])+(val/a[1])+(val/a[2])) print(int(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; skip ; var val : double := (a->first() * a[1+1] * a[2+1])->sqrt() ; var ans : double := 4 * ((val / a->first()) + (val / a[1+1]) + (val / a[2+1])) ; execute (("" + ((ans)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math ab,bc,ca=map(int,input().split()) a=math.sqrt((ab/bc)*ca) b=(ab/a) c=(ca/a) print(int(4*(a+b+c))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var ab : OclAny := null; var bc : OclAny := null; var ca : OclAny := null; Sequence{ab,bc,ca} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : double := ((ab / bc) * ca)->sqrt() ; var b : double := (ab / a) ; var c : double := (ca / a) ; execute (("" + ((4 * (a + b + c))))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : inputStrings=str(input()) outputStrings=[] isNextA=True for i in inputStrings : if isNextA==True and i=="A" : outputStrings.append(i) isNextA=False elif isNextA==False and i=="Z" : outputStrings.append(i) isNextA=True if outputStrings!=[]: if outputStrings[-1]=="A" : outputStrings.pop(-1) output=str() for i in outputStrings : output+=i if len(output)>1 : print(output) else : print("-1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var inputStrings : String := ("" + (((OclFile["System.in"]).readLine()))) ; var outputStrings : Sequence := Sequence{} ; var isNextA : boolean := true ; for i : inputStrings->characters() do ( if isNextA = true & i = "A" then ( execute ((i) : outputStrings) ; isNextA := false ) else (if isNextA = false & i = "Z" then ( execute ((i) : outputStrings) ; isNextA := true ) else skip)) ; if outputStrings /= Sequence{} then ( if outputStrings->last() = "A" then ( outputStrings := outputStrings->excludingAt(-1+1) ) else skip ) else skip ; var output : String := ("" + (())) ; for i : outputStrings do ( output := output + i) ; if (output)->size() > 1 then ( execute (output)->display() ) else ( execute ("-1")->display() ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) x=(a*b*c)**0.5 print(int(4*(x//a+x//b+x//c))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : double := ((a * b * c))->pow(0.5) ; execute (("" + ((4 * (x div a + x div b + x div c))))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- left=int(input()) X=list() Y=list() out=False for i in range(left): x,y=map(int,input().split()) X.append(x) Y.append(y) if left<=1 : print(-1) elif left==2 : if X[0]!=X[1]and Y[0]!=Y[1]: print(abs(X[0]-X[1])*abs(Y[0]-Y[1])) else : print(-1) elif left==3 : for i in range(3): for j in range(3): if X[j]!=X[i]and Y[j]!=Y[i]: x1=X[i] y1=Y[i] x2=X[j] y2=Y[j] out=True break if out==True : break print(abs(x1-x2)*abs(y1-y2)) elif left==4 : for i in range(4): for j in range(4): if X[j]!=X[i]and Y[j]!=Y[i]: x1=X[i] y1=Y[i] x2=X[j] y2=Y[j] out=True break if out==True : break print(abs(x1-x2)*abs(y1-y2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var left : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var X : Sequence := () ; var Y : Sequence := () ; var out : boolean := false ; for i : Integer.subrange(0, left-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((x) : X) ; execute ((y) : Y)) ; if left <= 1 then ( execute (-1)->display() ) else (if left = 2 then ( if X->first() /= X[1+1] & Y->first() /= Y[1+1] then ( execute ((X->first() - X[1+1])->abs() * (Y->first() - Y[1+1])->abs())->display() ) else ( execute (-1)->display() ) ) else (if left = 3 then ( for i : Integer.subrange(0, 3-1) do ( for j : Integer.subrange(0, 3-1) do ( if X[j+1] /= X[i+1] & Y[j+1] /= Y[i+1] then ( var x1 : OclAny := X[i+1] ; var y1 : OclAny := Y[i+1] ; var x2 : OclAny := X[j+1] ; var y2 : OclAny := Y[j+1] ; out := true ; break ) else skip) ; if out = true then ( break ) else skip) ; execute ((x1 - x2)->abs() * (y1 - y2)->abs())->display() ) else (if left = 4 then ( for i : Integer.subrange(0, 4-1) do ( for j : Integer.subrange(0, 4-1) do ( if X[j+1] /= X[i+1] & Y[j+1] /= Y[i+1] then ( x1 := X[i+1] ; y1 := Y[i+1] ; x2 := X[j+1] ; y2 := Y[j+1] ; out := true ; break ) else skip) ; if out = true then ( break ) else skip) ; execute ((x1 - x2)->abs() * (y1 - y2)->abs())->display() ) else skip ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find_distinct_coordinate(coordinates): for i,coordinate in enumerate(coordinates): for c2 in coordinates[i+1 :]: if coordinate[0]!=c2[0]and coordinate[1]!=c2[1]: return[coordinate,c2] return None def swimming_pool(): num_of_coordinates=int(input()) coordinates=[] for i in range(num_of_coordinates): coordinates.append([int(x)for x in input().split(' ')]) if num_of_coordinates==1 : return-1 distinct=find_distinct_coordinate(coordinates) if not distinct : return-1 x1,y1=distinct[0][0],distinct[0][1] x2,y2=distinct[1][0],distinct[1][1] Xd=abs(x1-x2) Yd=abs(y1-y2) area=Xd*Yd return area if area else-1 if __name__=="__main__" : print(swimming_pool()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (swimming_pool())->display() ) else skip; operation find_distinct_coordinate(coordinates : OclAny) : OclAny pre: true post: true activity: for _tuple : Integer.subrange(1, (coordinates)->size())->collect( _indx | Sequence{_indx-1, (coordinates)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var coordinate : OclAny := _tuple->at(_indx); for c2 : coordinates.subrange(i + 1+1) do ( if coordinate->first() /= c2->first() & coordinate[1+1] /= c2[1+1] then ( return Sequence{coordinate}->union(Sequence{ c2 }) ) else skip)) ; return null; operation swimming_pool() : OclAny pre: true post: true activity: var num_of_coordinates : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; coordinates := Sequence{} ; for i : Integer.subrange(0, num_of_coordinates-1) do ( execute ((input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) : coordinates)) ; if num_of_coordinates = 1 then ( return -1 ) else skip ; var distinct : OclAny := find_distinct_coordinate(coordinates) ; if not(distinct) then ( return -1 ) else skip ; var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := Sequence{distinct->first()->first(),distinct->first()[1+1]} ; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x2,y2} := Sequence{distinct[1+1]->first(),distinct[1+1][1+1]} ; var Xd : double := (x1 - x2)->abs() ; var Yd : double := (y1 - y2)->abs() ; var area : double := Xd * Yd ; return if area then area else -1 endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math alph="abcdefghijklmnopqrstuvwxyz" n=int(input()) a=[] for i in range(n): x,y=map(int,input().split()) a.append([x,y]) if n==1 : print(-1) else : S=0 for i in range(n-1): for j in range(i+1,n): x1,y1,x2,y2=a[i][0],a[i][1],a[j][0],a[j][1] if x1!=x2 and y1!=y2 : S=abs(x1-x2)*abs(y1-y2) if S!=0 : print(S) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var alph : String := "abcdefghijklmnopqrstuvwxyz" ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{x}->union(Sequence{ y })) : a)) ; if n = 1 then ( execute (-1)->display() ) else ( var S : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(i + 1, n-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := Sequence{a[i+1]->first(),a[i+1][1+1],a[j+1]->first(),a[j+1][1+1]} ; if x1 /= x2 & y1 /= y2 then ( S := (x1 - x2)->abs() * (y1 - y2)->abs() ) else skip)) ; if S /= 0 then ( execute (S)->display() ) else ( execute (-1)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) coords=[] for i in range(n): coords.append([int(i)for i in input().split()]) if n==1 : print(-1) elif n==2 : if coords[0][0]!=coords[1][0]and coords[0][1]!=coords[1][1]: print(abs((coords[0][0]-coords[1][0])*(coords[0][1]-coords[1][1]))) else : print(-1) else : r=0 for coord1 in coords : for coord2 in coords : if coord1[0]!=coord2[0]and coord1[1]!=coord2[1]: print(abs((coord1[0]-coord2[0])*(coord1[1]-coord2[1]))) r=1 break if r==1 : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var coords : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))) : coords)) ; if n = 1 then ( execute (-1)->display() ) else (if n = 2 then ( if coords->first()->first() /= coords[1+1]->first() & coords->first()[1+1] /= coords[1+1][1+1] then ( execute (((coords->first()->first() - coords[1+1]->first()) * (coords->first()[1+1] - coords[1+1][1+1]))->abs())->display() ) else ( execute (-1)->display() ) ) else ( var r : int := 0 ; for coord1 : coords do ( for coord2 : coords do ( if coord1->first() /= coord2->first() & coord1[1+1] /= coord2[1+1] then ( execute (((coord1->first() - coord2->first()) * (coord1[1+1] - coord2[1+1]))->abs())->display() ; r := 1 ; break ) else skip) ; if r = 1 then ( break ) else skip) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- v=int(input()) def pl3(v): point=[] for i in range(v): point.append(input().split()) for k in point : for j in point : if k[0]!=j[0]and k[1]!=j[1]: return abs((int(k[0])-int(j[0]))*(int(k[1])-int(j[1]))) break return-1 if v==1 : print('-1') else : print(pl3(v)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var v : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; if v = 1 then ( execute ('-1')->display() ) else ( execute (pl3(v))->display() ); operation pl3(v : OclAny) : OclAny pre: true post: true activity: var point : Sequence := Sequence{} ; for i : Integer.subrange(0, v-1) do ( execute ((input().split()) : point)) ; for k : point do ( for j : point do ( if k->first() /= j->first() & k[1+1] /= j[1+1] then ( return ((("" + ((k->first())))->toInteger() - ("" + ((j->first())))->toInteger()) * (("" + ((k[1+1])))->toInteger() - ("" + ((j[1+1])))->toInteger()))->abs() ; break ) else skip)) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) R=[int(input())for _ in range(n)] maxv=-math.inf minv=R[0] for i in range(1,n): diff=R[i]-minv maxv=diff if diff>maxv else maxv minv=R[i]if R[i]toInteger() ; var R : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var maxv : OclAny := - ; var minv : String := R->first() ; for i : Integer.subrange(1, n-1) do ( var diff : double := R[i+1] - minv ; maxv := if (diff->compareTo(maxv)) > 0 then diff else maxv endif ; minv := if R[i+1] < minv then R[i+1] else minv endif) ; execute (maxv)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(): inputs=int(sys.stdin.readline().rstrip()) maxv=-100000000000 minv=int(sys.stdin.readline().rstrip()) for i in range(1,inputs): compv=int(sys.stdin.readline()) if compv-minv>maxv : maxv=compv-minv if compvtoInteger() ; var maxv : int := -100000000000 ; var minv : int := ("" + ((sys.stdin.readLine().rstrip())))->toInteger() ; for i : Integer.subrange(1, inputs-1) do ( var compv : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (compv - minv->compareTo(maxv)) > 0 then ( maxv := compv - minv ) else skip ; if (compv->compareTo(minv)) < 0 then ( minv := compv ) else skip) ; var bigprice : int := maxv ; execute (bigprice)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def transport(L,before_L=[],cnt=0): cnt+=1 if L==before_L : print(cnt-2) return cnt L_before=L[:] dic={} for i in L : dic[i]=0 for i in L : dic[i]+=1 for i in range(len(L)): L[i]=dic[L[i]] transport(L,L_before,cnt) return L while 1 : n=int(input()) if n==0 : break S=list(map(int,input().split())) P=transport(S) for i in range(len(P)-1): print(P[i],end=" ") print(P[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while 1 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var S : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var P : OclAny := transport(S) ; for i : Integer.subrange(0, (P)->size() - 1-1) do ( execute (P[i+1])->display()) ; execute (P->last())->display()); operation transport(L : OclAny, before_L : OclAny, cnt : int) : OclAny pre: true post: true activity: if before_L->oclIsUndefined() then before_L := Sequence{} else skip; if cnt->oclIsUndefined() then cnt := 0 else skip; cnt := cnt + 1 ; if L = before_L then ( execute (cnt - 2)->display() ; return cnt ) else skip ; var L_before : Sequence := L ; var dic : OclAny := Set{} ; for i : L do ( dic[i+1] := 0) ; for i : L do ( dic[i+1] := dic[i+1] + 1) ; for i : Integer.subrange(0, (L)->size()-1) do ( L[i+1] := dic[L[i+1]+1]) ; transport(L, L_before, cnt) ; return L; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[] minArray=[] m=int(1e10) for _ in range(n): x=int(input()) minArray.append(m) m=min([m,x]) a.append(x) t=0 ans=-int(1e10) for i in reversed(range(1,n)): t=max([t,a[i]]) ans=max(ans,t-minArray[i]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; var minArray : Sequence := Sequence{} ; var m : int := ("" + ((("1e10")->toReal())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((m) : minArray) ; m := (Sequence{m}->union(Sequence{ x }))->min() ; execute ((x) : a)) ; var t : int := 0 ; var ans : int := -("" + ((("1e10")->toReal())))->toInteger() ; for i : (Integer.subrange(1, n-1))->reverse() do ( t := (Sequence{t}->union(Sequence{ a[i+1] }))->max() ; ans := Set{ans, t - minArray[i+1]}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxSubArraySum(arr,size): max_so_far=arr[0] curr_max=arr[0] for i in range(1,size): curr_max=max(arr[i],curr_max+arr[i]) max_so_far=max(max_so_far,curr_max) return max_so_far def lenOfLongSubarrWithGivenSum(arr,n,k): um=dict() Sum,maxLen=0,0 for i in range(n): Sum+=arr[i] if(Sum==k): maxLen=i+1 if(Sum not in um.keys()): um[Sum]=i if(Sum in um.keys()): if((Sum-k)in um.keys()and maxLen<(i-um[Sum-k])): maxLen=i-um[Sum-k] return maxLen def lenLongSubarrWithMaxSum(arr,n): maxSum=maxSubArraySum(arr,n) return lenOfLongSubarrWithGivenSum(arr,n,maxSum) arr=[5,-2,-1,3,-4] n=len(arr) print("Length of longest subarray having maximum sum=",lenLongSubarrWithMaxSum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; arr := Sequence{5}->union(Sequence{-2}->union(Sequence{-1}->union(Sequence{3}->union(Sequence{ -4 })))) ; n := (arr)->size() ; execute ("Length of longest subarray having maximum sum=")->display(); operation maxSubArraySum(arr : OclAny, size : OclAny) : OclAny pre: true post: true activity: var max_so_far : OclAny := arr->first() ; var curr_max : OclAny := arr->first() ; for i : Integer.subrange(1, size-1) do ( curr_max := Set{arr[i+1], curr_max + arr[i+1]}->max() ; max_so_far := Set{max_so_far, curr_max}->max()) ; return max_so_far; operation lenOfLongSubarrWithGivenSum(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var um : Map := (arguments ( )) ; var Sum : OclAny := null; var maxLen : OclAny := null; Sequence{Sum,maxLen} := Sequence{0,0} ; for i : Integer.subrange(0, n-1) do ( Sum := Sum + arr[i+1] ; if (Sum = k) then ( var maxLen : OclAny := i + 1 ) else skip ; if ((um.keys())->excludes(Sum)) then ( um[Sum+1] := i ) else skip ; if ((um.keys())->includes(Sum)) then ( if ((um.keys())->includes((Sum - k)) & (maxLen->compareTo((i - um[Sum - k+1]))) < 0) then ( maxLen := i - um[Sum - k+1] ) else skip ) else skip) ; return maxLen; operation lenLongSubarrWithMaxSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var maxSum : OclAny := maxSubArraySum(arr, n) ; return lenOfLongSubarrWithGivenSum(arr, n, maxSum); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) min_num=int(input()) max_num=0 profit=-999999999 for i in range(0,n-1): num=int(input()) temp=num-min_num if temp>profit : profit=temp if nummax_num : max_num=num print(profit) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var min_num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var max_num : int := 0 ; var profit : int := -999999999 ; for i : Integer.subrange(0, n - 1-1) do ( var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var temp : double := num - min_num ; if (temp->compareTo(profit)) > 0 then ( profit := temp ) else skip ; if (num->compareTo(min_num)) < 0 then ( min_num := num ; max_num := num ) else skip ; if (num->compareTo(max_num)) > 0 then ( max_num := num ) else skip) ; execute (profit)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) list_price=[int(input())for i in range(N)] minv=list_price[0] maxv=-10**9 for x in list_price[1 :]: maxv=max(maxv,x-minv) minv=min(minv,x) print(maxv) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var list_price : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var minv : OclAny := list_price->first() ; var maxv : double := (-10)->pow(9) ; for x : list_price->tail() do ( maxv := Set{maxv, x - minv}->max() ; minv := Set{minv, x}->min()) ; execute (maxv)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def upper_bound(array,length,value): low=0 ; high=length ; while(low=array[mid]): low=mid+1 ; else : high=mid ; return low ; def lower_bound(array,length,value): low=0 ; high=length ; while(lowunion(Sequence{ 3 }); ; n := (arr)->size(); ; execute (findSextuplets(arr, n))->display();; operation upper_bound(array : OclAny, length : OclAny, value : OclAny) pre: true post: true activity: var low : int := 0; ; var high : OclAny := length; ; while ((low->compareTo(high)) < 0) do ( var mid : int := ("" + (((low + high) / 2)))->toInteger(); ; if ((value->compareTo(array[mid+1])) >= 0) then ( low := mid + 1; ) else ( high := mid; )) ; return low;; operation lower_bound(array : OclAny, length : OclAny, value : OclAny) pre: true post: true activity: low := 0; ; high := length; ; while ((low->compareTo(high)) < 0) do ( mid := ("" + (((low + high) / 2)))->toInteger(); ; if ((value->compareTo(array[mid+1])) <= 0) then ( high := mid; ) else ( low := mid + 1; )) ; return low;; operation findSextuplets(arr : OclAny, n : OclAny) pre: true post: true activity: var index : int := 0; ; var RHS : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n * n * n + 1)); ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] /= 0) then ( for j : Integer.subrange(0, n-1) do ( for k : Integer.subrange(0, n-1) do ( RHS[index+1] := arr[i+1] * (arr[j+1] + arr[k+1]); ; index := index + 1;)) ) else skip) ; RHS := RHS->sort(); ; var result : int := 0; ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( for k : Integer.subrange(0, n-1) do ( var val : double := arr[i+1] * arr[j+1] + arr[k+1]; ; result := result + (upper_bound(RHS, index, val) - lower_bound(RHS, index, val));))) ; return result;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dic=dict() while 1 : try : c,d=(int(x)for x in input().split(",")) except : break value=dic.get(c) if not value : dic.setdefault(c,-1) else : dic.update({c : value-1}) while 1 : try : c,d=(int(x)for x in input().split(",")) except : break value=dic.get(c) if value : if value<0 : value*=-1 dic.update({c : value+1}) dic=dict(sorted(dic.items())) for x,y in dic.items(): if y>0 : print(x,y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dic : Map := (arguments ( )) ; while 1 do ( try ( var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ","))))))) ))))))))}) catch (_e : OclException) do ( break) ; var value : OclAny := dic.get(c) ; if not(value) then ( dic.setdefault(c, -1) ) else ( execute ((Map{ c |-> value - 1 }) <: dic) )) ; while 1 do ( try ( var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ","))))))) ))))))))}) catch (_e : OclException) do ( break) ; value := dic.get(c) ; if value then ( if value < 0 then ( value := value * -1 ) else skip ; execute ((Map{ c |-> value + 1 }) <: dic) ) else skip) ; dic := ((expr (atom (name sorted)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name dic)) (trailer . (name items) (arguments ( ))))))))) ))))) ; for _tuple : dic->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if y > 0 then ( execute (x)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- fore={} aft={} cont={} while True : s=input().strip() if s=='' : break cst,n=map(int,s.split(',')) if cst in fore : fore[cst]+=1 else : fore[cst]=1 while True : try : s=input().strip() cst,n=map(int,s.split(',')) if cst in aft : aft[cst]+=1 else : aft[cst]=1 except EOFError : break for cst in fore : if cst in aft : cont[cst]=fore[cst]+aft[cst] for cst in sorted(cont.keys()): print(cst,cont[cst]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var fore : OclAny := Set{} ; var aft : OclAny := Set{} ; var cont : OclAny := Set{} ; while true do ( var s : OclAny := input()->trim() ; if s = '' then ( break ) else skip ; var cst : OclAny := null; var n : OclAny := null; Sequence{cst,n} := (s.split(','))->collect( _x | (OclType["int"])->apply(_x) ) ; if (fore)->includes(cst) then ( fore[cst+1] := fore[cst+1] + 1 ) else ( fore[cst+1] := 1 )) ; while true do ( try ( s := input()->trim() ; var cst : OclAny := null; var n : OclAny := null; Sequence{cst,n} := (s.split(','))->collect( _x | (OclType["int"])->apply(_x) ) ; if (aft)->includes(cst) then ( aft[cst+1] := aft[cst+1] + 1 ) else ( aft[cst+1] := 1 )) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))) ; for cst : fore do ( if (aft)->includes(cst) then ( cont[cst+1] := fore[cst+1] + aft[cst+1] ) else skip) ; for cst : cont.keys()->sort() do ( execute (cst)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys b=0 a=[{},{}] for e in sys.stdin : if '\n'==e : b=1 else : c,_=e.split(','); c=int(c); a[b].setdefault(c,0); a[b][c]+=1 for k in sorted({*a[0]}&{*a[1]}): print(k,a[0][k]+a[1][k]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var b : int := 0 ; var a : Sequence := Sequence{Set{}}->union(Sequence{ Set{} }) ; for e : OclFile["System.in"] do ( if ' ' = e then ( b := 1 ) else ( var c : OclAny := null; var _anon : OclAny := null; Sequence{c,_anon} := e.split(','); var c : int := ("" + ((c)))->toInteger();(expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name setdefault) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))); a[b+1][c+1] := a[b+1][c+1] + 1 )) ; for k : MathLib.bitwiseAnd(Set{ a->first() }, Set{ a[1+1] })->sort() do ( execute (k)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_input(): while True : try : yield ''.join(input()) except EOFError : break table=[[False for i in range(32)]for j in range(1001)] table2=[[False for i in range(32)]for j in range(1001)] C=[False for i in range(1001)] C2=[False for i in range(1001)] while True : N=input() if len(N)<=1 : break c,d=[int(i)for i in N.split(",")] table[c][d]=True C[c]=True M=list(get_input()) for l in range(len(M)): c,d=[int(i)for i in M[l].split(",")] table2[c][d]=True C2[c]=True for i in range(1001): if C[i]and C2[i]: cnt=0 for j in range(32): if table[i][j]: cnt+=1 if table2[i][j]: cnt+=1 print(i,cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var table : Sequence := Integer.subrange(0, 1001-1)->select(j | true)->collect(j | (Integer.subrange(0, 32-1)->select(i | true)->collect(i | (false)))) ; var table2 : Sequence := Integer.subrange(0, 1001-1)->select(j | true)->collect(j | (Integer.subrange(0, 32-1)->select(i | true)->collect(i | (false)))) ; var C : Sequence := Integer.subrange(0, 1001-1)->select(i | true)->collect(i | (false)) ; var C2 : Sequence := Integer.subrange(0, 1001-1)->select(i | true)->collect(i | (false)) ; while true do ( var N : String := (OclFile["System.in"]).readLine() ; if (N)->size() <= 1 then ( break ) else skip ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := N.split(",")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; table[c+1][d+1] := true ; C[c+1] := true) ; var M : Sequence := (OclIterator.newOclIterator_Function(lambda _i : int in self.get_input(_i))) ; for l : Integer.subrange(0, (M)->size()-1) do ( var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := M[l+1].split(",")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; table2[c+1][d+1] := true ; C2[c+1] := true) ; for i : Integer.subrange(0, 1001-1) do ( if C[i+1] & C2[i+1] then ( var cnt : int := 0 ; for j : Integer.subrange(0, 32-1) do ( if table[i+1][j+1] then ( cnt := cnt + 1 ) else skip ; if table2[i+1][j+1] then ( cnt := cnt + 1 ) else skip) ; execute (i)->display() ) else skip); operation get_input(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; while true do ( try ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return StringLib.sumStringsWithSeparator(((OclFile["System.in"]).readLine()), '')) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import(division,absolute_import,print_function,unicode_literals) from sys import stdin from collections import Counter cnt=Counter() cond=dict() for line in stdin : if line.isspace(): break id=int(line.partition(',')[0]) cnt[id]+=1 cond[id]=False for line in stdin : id=int(line.partition(',')[0]) cnt[id]+=1 if id in cond : cond[id]=True for id,flag in sorted(cond.items()): if flag : print(id,cnt[id]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var cnt : OclAny := Counter() ; var cond : Map := (arguments ( )) ; for line : stdin do ( if line->matches("[ \t\n\r]*") then ( break ) else skip ; var id : int := ("" + ((line.partition(',')->first())))->toInteger() ; cnt[id+1] := cnt[id+1] + 1 ; cond[id+1] := false) ; for line : stdin do ( id := ("" + ((line.partition(',')->first())))->toInteger() ; cnt[id+1] := cnt[id+1] + 1 ; if (cond)->includes(id) then ( cond[id+1] := true ) else skip) ; for _tuple : cond->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sort() do (var _indx : int := 1; var id : OclAny := _tuple->at(_indx); _indx := _indx + 1; var flag : OclAny := _tuple->at(_indx); if flag then ( execute (id)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def SieveOfEratosthenes(prime,p_size): prime[0]=False prime[1]=False for p in range(2,mt.ceil(mt.sqrt(p_size+1))): if(prime[p]): for i in range(p*2,p_size+1,p): prime[i]=False def SumOfElements(arr,n): prime=[True for i in range(n+1)] SieveOfEratosthenes(prime,n+1) i,j=0,0 m=dict() for i in range(n): if arr[i]in m.keys(): m[arr[i]]+=1 else : m[arr[i]]=1 Sum=0 for i in m : if(prime[m[i]]): Sum+=(i) return Sum arr=[5,4,6,5,4,6] n=len(arr) print(SumOfElements(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; arr := Sequence{5}->union(Sequence{4}->union(Sequence{6}->union(Sequence{5}->union(Sequence{4}->union(Sequence{ 6 }))))) ; n := (arr)->size() ; execute (SumOfElements(arr, n))->display(); operation SieveOfEratosthenes(prime : OclAny, p_size : OclAny) pre: true post: true activity: prime->first() := false ; prime[1+1] := false ; for p : Integer.subrange(2, mt.ceil(mt.sqrt(p_size + 1))-1) do ( if (prime[p+1]) then ( for i : Integer.subrange(p * 2, p_size + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip); operation SumOfElements(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: prime := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (true)) ; SieveOfEratosthenes(prime, n + 1) ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,0} ; var m : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( if (m.keys())->includes(arr[i+1]) then ( m[arr[i+1]+1] := m[arr[i+1]+1] + 1 ) else ( m[arr[i+1]+1] := 1 )) ; var Sum : int := 0 ; for i : m->keys() do ( if (prime[m[i+1]+1]) then ( Sum := Sum + (i) ) else skip) ; return Sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import division,print_function from sys import stdin,exit from itertools import count from collections import Counter def main(readline=stdin.readline): counter=Counter() while 1 : if not int(readline()): exit() ary=[int(digit)for digit in readline().split()] for num in count(): counter.clear() counter.update(ary) if all(key==value for key,value in counter.items()): break ary=[counter[value]for value in ary] print(num) print(*ary) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main(readline : OclAny) pre: true post: true activity: if readline->oclIsUndefined() then readline := stdin.readline else skip; var counter : OclAny := Counter() ; while 1 do ( if not(("" + ((readline())))->toInteger()) then ( exit() ) else skip ; var ary : Sequence := readline().split()->select(digit | true)->collect(digit | (("" + ((digit)))->toInteger())) ; for num : count() do ( execute (counter /<: counter) ; execute ((ary) <: counter) ; if ((argument (test (logical_test (comparison (comparison (expr (atom (name key)))) == (comparison (expr (atom (name value))))))) (comp_for for (exprlist (expr (atom (name key))) , (expr (atom (name value)))) in (logical_test (comparison (expr (atom (name counter)) (trailer . (name items) (arguments ( )))))))))->forAll( _x | _x = true ) then ( break ) else skip ; ary := ary->select(value | true)->collect(value | (counter[value+1]))) ; execute (num)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ary))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from decimal import* from random import randint def transformare_baza(numar,baza): transformare="" while numar>=baza : rest=numar % baza numar=numar//baza transformare+=str(rest) transformare+=str(numar) noua_baza=transformare[: :-1] return noua_baza return dictionar z=int(input()) for contorr in range(z): n=int(input()) mineri=[] diamante=[] matrice=[] for i in range(0,2*n): x,y=list(map(int,(input().split()))) matrice.append((abs(x),abs(y))) matrice=sorted(matrice,key=lambda x : x[0]) mineri=sorted(matrice[0 : n],key=lambda x : x[1]) diamante=matrice[n : 2*n] total=0 for i in range(0,n): total+=((mineri[i][1]**2+diamante[i][0]**2)**(1/2)) print(total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var z : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for contorr : Integer.subrange(0, z-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mineri : Sequence := Sequence{} ; var diamante : Sequence := Sequence{} ; var matrice : Sequence := Sequence{} ; for i : Integer.subrange(0, 2 * n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (((input().split()))->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((Sequence{(x)->abs(), (y)->abs()}) : matrice)) ; matrice := matrice->sortedBy($x | (lambda x : OclAny in (x->first()))->apply($x)) ; mineri := matrice.subrange(0+1, n)->sortedBy($x | (lambda x : OclAny in (x[1+1]))->apply($x)) ; diamante := matrice.subrange(n+1, 2 * n) ; var total : int := 0 ; for i : Integer.subrange(0, n-1) do ( total := total + ((((mineri[i+1][1+1])->pow(2) + (diamante[i+1]->first())->pow(2)))->pow((1 / 2)))) ; execute (total)->display()); operation transformare_baza(numar : OclAny, baza : OclAny) : OclAny pre: true post: true activity: var transformare : String := "" ; while (numar->compareTo(baza)) >= 0 do ( var rest : int := numar mod baza ; numar := numar div baza ; transformare := transformare + ("" + ((rest)))) ; transformare := transformare + ("" + ((numar))) ; var noua_baza : OclAny := transformare(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; return noua_baza ; return dictionar; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def SieveOfEratosthenes(prime,p_size): prime[0]=False ; prime[1]=False ; for p in range(2,int(sqrt(p_size))+1): if(prime[p]): for i in range(p*2,p_size+1,p): prime[i]=False ; return prime def xorPrimeFreq(arr,n): prime=[True]*(n+1); prime=SieveOfEratosthenes(prime,n+1); m=dict.fromkeys(arr,0); for i in range(n): m[arr[i]]+=1 ; xorVal=0 ; for key,value in m.items(): if(prime[value]): xorVal ^=key ; return xorVal ; if __name__=="__main__" : arr=[5,4,6,5,4,6]; n=len(arr); print(xorPrimeFreq(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{5}->union(Sequence{4}->union(Sequence{6}->union(Sequence{5}->union(Sequence{4}->union(Sequence{ 6 }))))); ; n := (arr)->size(); ; execute (xorPrimeFreq(arr, n))->display(); ) else skip; operation SieveOfEratosthenes(prime : OclAny, p_size : OclAny) : OclAny pre: true post: true activity: prime->first() := false; ; prime[1+1] := false; ; for p : Integer.subrange(2, ("" + ((sqrt(p_size))))->toInteger() + 1-1) do ( if (prime[p+1]) then ( for i : Integer.subrange(p * 2, p_size + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false;) ) else skip) ; return prime; operation xorPrimeFreq(arr : OclAny, n : OclAny) pre: true post: true activity: prime := MatrixLib.elementwiseMult(Sequence{ true }, (n + 1)); ; prime := SieveOfEratosthenes(prime, n + 1); ; var m : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))); ; for i : Integer.subrange(0, n-1) do ( m[arr[i+1]+1] := m[arr[i+1]+1] + 1;) ; var xorVal : int := 0; ; for _tuple : m->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); if (prime[value+1]) then ( xorVal := xorVal xor key; ) else skip) ; return xorVal;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_CHAR=256 def isPalindrome(Str,l,h): while(h>l): if(Str[l]!=Str[h]): l+=1 h-=1 return False return True def check(Str): n=len(Str) freq=[0 for i in range(MAX_CHAR)] for i in range(n): freq[ord(Str[i])]+=1 if(freq[ord(Str[i])]>2): return True k=0 for i in range(n): if(freq[ord(Str[i])]>1): Str[k]=Str[i] k+=1 Str[k]='\0' if(isPalindrome(Str,0,k-1)): if(k & 1): return Str[k//2]==Str[k//2-1] return False return True S="ABCABD" Str=[i for i in S] if(check(Str)): print("Repeated Subsequence Exists") else : print("Repeated Subsequence Doesn't Exists") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_CHAR : int := 256 ; skip ; skip ; var S : String := "ABCABD" ; Str := S->characters()->select(i | true)->collect(i | (i)) ; if (check(Str)) then ( execute ("Repeated Subsequence Exists")->display() ) else ( execute ("Repeated Subsequence Doesn't Exists")->display() ); operation isPalindrome(Str : OclAny, l : OclAny, h : OclAny) : OclAny pre: true post: true activity: while ((h->compareTo(l)) > 0) do ( if (Str[l+1] /= Str[h+1]) then ( l := l + 1 ; h := h - 1 ; return false ) else skip) ; return true; operation check(Str : OclAny) : OclAny pre: true post: true activity: var n : int := (Str)->size() ; var freq : Sequence := Integer.subrange(0, MAX_CHAR-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( freq[(Str[i+1])->char2byte()+1] := freq[(Str[i+1])->char2byte()+1] + 1 ; if (freq[(Str[i+1])->char2byte()+1] > 2) then ( return true ) else skip) ; var k : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (freq[(Str[i+1])->char2byte()+1] > 1) then ( Str[k+1] := Str[i+1] ; k := k + 1 ) else skip) ; Str[k+1] := '\0' ; if (isPalindrome(Str, 0, k - 1)) then ( if (MathLib.bitwiseAnd(k, 1)) then ( return Str[k div 2+1] = Str[k div 2 - 1+1] ) else skip ; return false ) else skip ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- X=int(input()) if X in[7,5,3]: print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var X : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (Sequence{7}->union(Sequence{5}->union(Sequence{ 3 })))->includes(X) then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(" YNEOS"[input()in '357' : : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (" YNEOS"(subscript (test (logical_test (comparison (comparison (expr (atom (name input)) (trailer (arguments ( ))))) in (comparison (expr (atom '357')))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): x=int(input()) if x==3 or x==5 or x==7 : print('YES') else : print('NO') if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if x = 3 or x = 5 or x = 7 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- X=int(input()) num=abs(X-5) ans="NO" if num==0 or num==2 : ans="YES" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var X : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var num : double := (X - 5)->abs() ; var ans : String := "NO" ; if num = 0 or num = 2 then ( ans := "YES" ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() x=int(x) if x==7 or x==5 or x==3 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := (OclFile["System.in"]).readLine() ; x := ("" + ((x)))->toInteger() ; if x = 7 or x = 5 or x = 3 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cubeSum(n): sum=0 for i in range(0,n): sum+=(2*i+1)*(2*i+1)*(2*i+1) return sum print(cubeSum(2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (cubeSum(2))->display(); operation cubeSum(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + (2 * i + 1) * (2 * i + 1) * (2 * i + 1)) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cubeSum(n): sum=0 for i in range(1,n+1): sum+=(2*i)*(2*i)*(2*i) return sum print(cubeSum(8)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (cubeSum(8))->display(); operation cubeSum(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( sum := sum + (2 * i) * (2 * i) * (2 * i)) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) a=[int(i)for i in input().split()] h=[] for i in range(len(a)): if a[i]==0 : continue if a[i]<=k : h.append(i+1) b=9999 for i in h : if abs(m-i)collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var h : Sequence := Sequence{} ; for i : Integer.subrange(0, (a)->size()-1) do ( if a[i+1] = 0 then ( continue ) else skip ; if (a[i+1]->compareTo(k)) <= 0 then ( execute ((i + 1) : h) ) else skip) ; var b : int := 9999 ; for i : h do ( if ((m - i)->abs()->compareTo(b)) < 0 then ( b := (m - i)->abs() ) else skip) ; execute (b * 10)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt for _ in range(int(input())): n=int(input()) a=[] b=[] for i in range(2*n): x,y=map(int,input().split()) if(x==0): a+=[abs(y)] else : b+=[abs(x)] a.sort() b.sort() dist=0 for i in range(n): dist+=sqrt(a[i]**2+b[i]**2) print(dist) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; var b : Sequence := Sequence{} ; for i : Integer.subrange(0, 2 * n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (x = 0) then ( a := a + Sequence{ (y)->abs() } ) else ( b := b + Sequence{ (x)->abs() } )) ; a := a->sort() ; b := b->sort() ; var dist : int := 0 ; for i : Integer.subrange(0, n-1) do ( dist := dist + sqrt((a[i+1])->pow(2) + (b[i+1])->pow(2))) ; execute (dist)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") def operation_of_frequency_of_appearance(S): S_old=S[:] steps=0 while True : unique=list(set(S)) counts={u : S.count(u)for u in unique} S=[counts[s]for s in S] if S==S_old : return steps,S S_old=S[:] steps+=1 while True : N=int(input()) if N==0 : break steps,S=operation_of_frequency_of_appearance([int(_)for _ in input().split()]) print(steps) print(' '.join([str(s)for s in S])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; skip ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; Sequence{steps,S} := operation_of_frequency_of_appearance(input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger()))) ; execute (steps)->display() ; execute (StringLib.sumStringsWithSeparator((S->select(s | true)->collect(s | (("" + ((s)))))), ' '))->display()); operation operation_of_frequency_of_appearance(S : OclAny) : OclAny pre: true post: true activity: var S_old : Sequence := S ; var steps : int := 0 ; while true do ( var unique : Sequence := (Set{}->union((S))) ; var counts : Map := unique->select(u | true)->collect(u | Map{u |-> S->count(u)})->unionAll() ; S := S->select(s | true)->collect(s | (counts[s+1])) ; if S = S_old then ( return steps, S ) else skip ; S_old := S ; steps := steps + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=list(map(int,input().split())) n1=list(map(int,input().split()[: n[0]])) lst=[] lst1=[] for i in range(n[0]): if(n1[i]!=0): if(n1[i]<=n[2]): lst.append(i+1) for i in lst : s=n[1]-i if(s<0): s=s*-1 lst1.append(s) print(min(lst1)*10) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n1 : Sequence := ((input().split().subrange(1,n->first()))->collect( _x | (OclType["int"])->apply(_x) )) ; var lst : Sequence := Sequence{} ; var lst1 : Sequence := Sequence{} ; for i : Integer.subrange(0, n->first()-1) do ( if (n1[i+1] /= 0) then ( if ((n1[i+1]->compareTo(n[2+1])) <= 0) then ( execute ((i + 1) : lst) ) else skip ) else skip) ; for i : lst do ( var s : double := n[1+1] - i ; if (s < 0) then ( s := s * -1 ) else skip ; execute ((s) : lst1)) ; execute ((lst1)->min() * 10)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=lambda : map(int,input().split()); d,e,f=a(); print(min(abs(i-e)for i,z in enumerate(a(),1)if 0collect( _x | (OclType["int"])->apply(_x) )); var d : OclAny := null; var e : OclAny := null; var f : OclAny := null; Sequence{d,e,f} := a->apply(); execute (((argument (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (name e))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name z)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments ( )))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (comparison (expr (atom (number (integer 0))))) < (comparison (expr (atom (name z))))) <= (comparison (expr (atom (name f)))))))))))->min() * 10)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) a=list(map(int,input().split())) k1=10000000 k2=-10000000 for i in range(m-1,n,1): if a[i]!=0 : if a[i]<=k : k1=i break for i in range(m-1,-1,-1): if a[i]!=0 : if a[i]<=k : k2=i break r=min(k1-(m-1),(m-1)-k2) print(r*10) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k1 : int := 10000000 ; var k2 : int := -10000000 ; for i : Integer.subrange(m - 1, n-1)->select( $x | ($x - m - 1) mod 1 = 0 ) do ( if a[i+1] /= 0 then ( if (a[i+1]->compareTo(k)) <= 0 then ( k1 := i ; break ) else skip ) else skip) ; for i : Integer.subrange(-1 + 1, m - 1)->reverse() do ( if a[i+1] /= 0 then ( if (a[i+1]->compareTo(k)) <= 0 then ( k2 := i ; break ) else skip ) else skip) ; var r : OclAny := Set{k1 - (m - 1), (m - 1) - k2}->min() ; execute (r * 10)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import os import random import re import sys from math import gcd from math import sqrt from collections import Counter def solve(): n,m,k=list(map(int,input().split())) arr=list(map(int,input().split())) ans=10*10 for i in range(n): if arr[i]<=k and arr[i]!=0 and abs(m-1-i)collect( _x | (OclType["int"])->apply(_x) )) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 10 * 10 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1]->compareTo(k)) <= 0 & arr[i+1] /= 0 & ((m - 1 - i)->abs()->compareTo(ans)) < 0 then ( ans := (m - 1 - i)->abs() ) else skip) ; execute (ans * 10)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) m=int(input()) b=list(map(int,input().split())) d={} for i in range(m): for j in range(n): if b[i]% a[j]==0 : div=b[i]//a[j] if div in d : d[div]+=1 else : d[div]=1 res=max(d) print(d[res]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : OclAny := Set{} ; for i : Integer.subrange(0, m-1) do ( for j : Integer.subrange(0, n-1) do ( if b[i+1] mod a[j+1] = 0 then ( var div : int := b[i+1] div a[j+1] ; if (d)->includes(div) then ( d[div+1] := d[div+1] + 1 ) else ( d[div+1] := 1 ) ) else skip)) ; var res : OclAny := (d)->max() ; execute (d[res+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split(" "))) m=int(input()) b=list(map(int,input().split(" "))) c=0 l=set() for i in range(n): for j in range(m): if b[j]% a[i]==0 : l.add(b[j]//a[i]) maximum=max(l) for i in range(n): if(a[i]*maximum)in b : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; var l : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if b[j+1] mod a[i+1] = 0 then ( execute ((b[j+1] div a[i+1]) : l) ) else skip)) ; var maximum : OclAny := (l)->max() ; for i : Integer.subrange(0, n-1) do ( if (b)->includes((a[i+1] * maximum)) then ( c := c + 1 ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input().split() a=[int(e)for e in s] m=int(input()) s=input().split() b=[int(e)for e in s] gears=[] ratio=[] for i in a : for j in b : if(j % i==0): ratio.append(j/i) maximum=max(ratio) indices=[i for i in ratio if i==maximum] print(len(indices)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := input().split() ; var a : Sequence := s->select(e | true)->collect(e | (("" + ((e)))->toInteger())) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; s := input().split() ; var b : Sequence := s->select(e | true)->collect(e | (("" + ((e)))->toInteger())) ; var gears : Sequence := Sequence{} ; var ratio : Sequence := Sequence{} ; for i : a do ( for j : b do ( if (j mod i = 0) then ( execute ((j / i) : ratio) ) else skip)) ; var maximum : OclAny := (ratio)->max() ; var indices : Sequence := ratio->select(i | i = maximum)->collect(i | (i)) ; execute ((indices)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) m=int(input()) b=list(map(int,input().split())) max_ratio=-1 max_counter=0 for _a in a : for _b in b : if _b % _a!=0 : continue ratio=_b//_a if ratio>max_ratio : max_ratio=ratio max_counter=1 elif ratio==max_ratio : max_counter+=1 print(max_counter) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var max_ratio : int := -1 ; var max_counter : int := 0 ; for _a : a do ( for _b : b do ( if _b mod _a /= 0 then ( continue ) else skip ; var ratio : int := _b div _a ; if (ratio->compareTo(max_ratio)) > 0 then ( max_ratio := ratio ; max_counter := 1 ) else (if ratio = max_ratio then ( max_counter := max_counter + 1 ) else skip))) ; execute (max_counter)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_pedal=int(input()) pedal_stars=list(map(int,input().split())) num_wheel=int(input()) wheel_stars=list(map(int,input().split())) max_ratio=-99999 count=0 for wheel_star in wheel_stars : for pedal_star in pedal_stars : if wheel_star % pedal_star==0 : if wheel_star//pedal_star>max_ratio : max_ratio=wheel_star//pedal_star count=1 elif wheel_star//pedal_star==max_ratio : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_pedal : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var pedal_stars : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var num_wheel : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var wheel_stars : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var max_ratio : int := -99999 ; var count : int := 0 ; for wheel_star : wheel_stars do ( for pedal_star : pedal_stars do ( if wheel_star mod pedal_star = 0 then ( if (wheel_star div pedal_star->compareTo(max_ratio)) > 0 then ( max_ratio := wheel_star div pedal_star ; count := 1 ) else (if wheel_star div pedal_star = max_ratio then ( count := count + 1 ) else skip) ) else skip)) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : n=int(input()) d=[] m=[] T=2*n while T : x,y=map(int,input().split()) if x==0 : m.append(abs(y)) else : d.append(abs(x)) T=T-1 m.sort() d.sort() ans=0 for i in range(n): ans=ans+(d[i]**2+m[i]**2)**0.5 print(ans) t=t-1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Sequence := Sequence{} ; var m : Sequence := Sequence{} ; var T : int := 2 * n ; while T do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x = 0 then ( execute (((y)->abs()) : m) ) else ( execute (((x)->abs()) : d) ) ; T := T - 1) ; m := m->sort() ; d := d->sort() ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( ans := ans + (((d[i+1])->pow(2) + (m[i+1])->pow(2)))->pow(0.5)) ; execute (ans)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys INT_MAX=sys.maxsize def min_index(p,n): ans=0 ; mini=INT_MAX ; for i in range(n): if(p[i]<=mini): mini=p[i]; if(mini==p[i]): ans+=1 ; return ans ; if __name__=="__main__" : P=[4,2,5,1,3]; n=len(P); print(min_index(P,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var INT_MAX : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; skip ; if __name__ = "__main__" then ( var P : Sequence := Sequence{4}->union(Sequence{2}->union(Sequence{5}->union(Sequence{1}->union(Sequence{ 3 })))); ; n := (P)->size(); ; execute (min_index(P, n))->display(); ) else skip; operation min_index(p : OclAny, n : OclAny) pre: true post: true activity: var ans : int := 0; ; var mini : OclAny := INT_MAX; ; for i : Integer.subrange(0, n-1) do ( if ((p[i+1]->compareTo(mini)) <= 0) then ( mini := p[i+1]; ) else skip ; if (mini = p[i+1]) then ( ans := ans + 1; ) else skip) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy from test.support import _MemoryWatchdog BIG_NUM=2000000000 HUGE_NUM=99999999999999999 MOD=1000000007 EPS=0.000000001 sys.setrecursionlimit(100000) SIZE=101 table=[None]*(SIZE) while True : N=int(input()) if N==0 : break TMP=list(map(int,input().split())) ans=-1 count=0 while True : for i in range(SIZE): table[i]=0 for i in range(len(TMP)): table[TMP[i]]+=1 WORK=[] for i in range(len(TMP)): WORK.append(table[TMP[i]]) FLG=True for i in range(len(TMP)): if TMP[i]!=WORK[i]: FLG=False break if FLG==True : ans=count break for i in range(len(WORK)): TMP[i]=WORK[i] count+=1 print("%d" %(ans)) print(' '.join(map(str,TMP))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var HUGE_NUM : int := 99999999999999999 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; sys.setrecursionlimit(100000) ; var SIZE : int := 101 ; var table : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (SIZE)) ; while true do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var TMP : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := -1 ; var count : int := 0 ; while true do ( for i : Integer.subrange(0, SIZE-1) do ( table[i+1] := 0) ; for i : Integer.subrange(0, (TMP)->size()-1) do ( table[TMP[i+1]+1] := table[TMP[i+1]+1] + 1) ; var WORK : Sequence := Sequence{} ; for i : Integer.subrange(0, (TMP)->size()-1) do ( execute ((table[TMP[i+1]+1]) : WORK)) ; var FLG : boolean := true ; for i : Integer.subrange(0, (TMP)->size()-1) do ( if TMP[i+1] /= WORK[i+1] then ( FLG := false ; break ) else skip) ; if FLG = true then ( ans := count ; break ) else skip ; for i : Integer.subrange(0, (WORK)->size()-1) do ( TMP[i+1] := WORK[i+1]) ; count := count + 1) ; execute (StringLib.format("%d",(ans)))->display() ; execute (StringLib.sumStringsWithSeparator(((TMP)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printRepeating(arr,size): xor=arr[0] n=size-2 x=0 y=0 for i in range(1,size): xor ^=arr[i] for i in range(1,n+1): xor ^=i set_bit_no=xor & ~(xor-1) for i in range(0,size): if(arr[i]& set_bit_no): x=x ^ arr[i] else : y=y ^ arr[i] for i in range(1,n+1): if(i & set_bit_no): x=x ^ i else : y=y ^ i print("The two repeating","elements are",y,x) arr=[4,2,4,5,2,3,1] arr_size=len(arr) printRepeating(arr,arr_size) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{4}->union(Sequence{2}->union(Sequence{4}->union(Sequence{5}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 1 })))))) ; var arr_size : int := (arr)->size() ; printRepeating(arr, arr_size); operation printRepeating(arr : OclAny, size : OclAny) pre: true post: true activity: var xor : OclAny := arr->first() ; var n : double := size - 2 ; var x : int := 0 ; var y : int := 0 ; for i : Integer.subrange(1, size-1) do ( xor := xor xor arr[i+1]) ; for i : Integer.subrange(1, n + 1-1) do ( xor := xor xor i) ; var set_bit_no : int := MathLib.bitwiseAnd(xor, MathLib.bitwiseNot((xor - 1))) ; for i : Integer.subrange(0, size-1) do ( if (MathLib.bitwiseAnd(arr[i+1], set_bit_no)) then ( x := MathLib.bitwiseXor(x, arr[i+1]) ) else ( y := MathLib.bitwiseXor(y, arr[i+1]) )) ; for i : Integer.subrange(1, n + 1-1) do ( if (MathLib.bitwiseAnd(i, set_bit_no)) then ( x := MathLib.bitwiseXor(x, i) ) else ( y := MathLib.bitwiseXor(y, i) )) ; execute ("The two repeating")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,a,b=map(int,input().split()) if abs(x-a)>abs(x-b): print('B') else : print('A') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{x,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if ((x - a)->abs()->compareTo((x - b)->abs())) > 0 then ( execute ('B')->display() ) else ( execute ('A')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify import sys,bisect,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod=10**9+7 INF=float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int,sys.stdin.readline().split())) x,a,b=inpl() print('A' if abs(x-a)pow(8)) ; var mod : double := (10)->pow(9) + 7 ; var INF : double := ("" + (('inf')))->toReal() ; skip ; skip ; var x : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{x,a,b} := inpl() ; execute (if ((x - a)->abs()->compareTo((x - b)->abs())) < 0 then 'A' else 'B' endif)->display(); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inpl() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) int1=lambda x : int(x)-1 p2D=lambda x : print(*x,sep="\n") def MI(): return map(int,sys.stdin.readline().split()) def LI(): return list(map(int,sys.stdin.readline().split())) def LLI(rows_number): return[LI()for _ in range(rows_number)] def main(): x,a,b=MI() if abs(x-a)pow(6)) ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; var p2D : Function := lambda x : OclAny in (((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ; skip ; skip ; skip ; skip ; main(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LLI(rows_number : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows_number-1)->select(_anon | true)->collect(_anon | (LI())); operation main() pre: true post: true activity: var x : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{x,a,b} := MI() ; if ((x - a)->abs()->compareTo((x - b)->abs())) < 0 then ( execute ("A")->display() ) else ( execute ("B")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,a,b=map(int,input().split()); print('AB'[abs(x-a)-abs(x-b)>=0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{x,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); execute ('AB'->select((x - a)->abs() - (x - b)->abs() >= 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def read_input(): x,a,b=map(int,input().split()) return x,a,b def submit(): x,a,b=read_input() if abs(x-a)collect( _x | (OclType["int"])->apply(_x) ) ; return x, a, b; operation submit() pre: true post: true activity: var x : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{x,a,b} := read_input() ; if ((x - a)->abs()->compareTo((x - b)->abs())) < 0 then ( execute ('A')->display() ) else ( execute ('B')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math class Node : def __init__(self,data): self.data=data self.next=None def push(head,data): if not head : head=Node(data) head.next=head return head lnode=head while(lnode and lnode.next is not head): lnode=lnode.next ptr1=Node(data) ptr1.next=head lnode.next=ptr1 head=ptr1 return head def sumOfList(head): temp=head tsum=temp.data temp=temp.next while(temp is not head): tsum+=temp.data temp=temp.next return tsum if __name__=='__main__' : head=None head=push(head,12) head=push(head,56) head=push(head,2) head=push(head,11) print("Sum of circular list is={}".format(sumOfList(head))) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.next := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( head := null ; head := push(head, 12) ; head := push(head, 56) ; head := push(head, 2) ; head := push(head, 11) ; execute (StringLib.interpolateStrings("Sum of circular list is={}", Sequence{sumOfList(head)}))->display() ) else skip; operation push(head : OclAny, data : OclAny) : OclAny pre: true post: true activity: if not(head) then ( head := (Node.newNode()).initialise(data) ; head.next := head ; return head ) else skip ; var lnode : OclAny := head ; while (lnode & not(lnode.next <>= head)) do ( lnode := lnode.next) ; var ptr1 : Node := (Node.newNode()).initialise(data) ; ptr1.next := head ; lnode.next := ptr1 ; head := ptr1 ; return head; operation sumOfList(head : OclAny) : OclAny pre: true post: true activity: var temp : OclAny := head ; var tsum : OclAny := temp.data ; temp := temp.next ; while (not(temp <>= head)) do ( tsum := tsum + temp.data ; temp := temp.next) ; return tsum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSymPairs(arr,row): hM=dict() for i in range(row): first=arr[i][0] sec=arr[i][1] if(sec in hM.keys()and hM[sec]==first): print("(",sec,",",first,")") else : hM[first]=sec if __name__=='__main__' : arr=[[0 for i in range(2)]for i in range(5)] arr[0][0],arr[0][1]=11,20 arr[1][0],arr[1][1]=30,40 arr[2][0],arr[2][1]=5,10 arr[3][0],arr[3][1]=40,30 arr[4][0],arr[4][1]=10,5 findSymPairs(arr,5) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Integer.subrange(0, 5-1)->select(i | true)->collect(i | (Integer.subrange(0, 2-1)->select(i | true)->collect(i | (0)))) ; var arr->first()->first() : OclAny := null; var arr->first()[1+1] : OclAny := null; Sequence{arr->first()->first(),arr->first()[1+1]} := Sequence{11,20} ; var arr[1+1]->first() : OclAny := null; var arr[1+1][1+1] : OclAny := null; Sequence{arr[1+1]->first(),arr[1+1][1+1]} := Sequence{30,40} ; var arr[2+1]->first() : OclAny := null; var arr[2+1][1+1] : OclAny := null; Sequence{arr[2+1]->first(),arr[2+1][1+1]} := Sequence{5,10} ; var arr[3+1]->first() : OclAny := null; var arr[3+1][1+1] : OclAny := null; Sequence{arr[3+1]->first(),arr[3+1][1+1]} := Sequence{40,30} ; var arr[4+1]->first() : OclAny := null; var arr[4+1][1+1] : OclAny := null; Sequence{arr[4+1]->first(),arr[4+1][1+1]} := Sequence{10,5} ; findSymPairs(arr, 5) ) else skip; operation findSymPairs(arr : OclAny, row : OclAny) pre: true post: true activity: var hM : Map := (arguments ( )) ; for i : Integer.subrange(0, row-1) do ( var first : OclAny := arr[i+1]->first() ; var sec : OclAny := arr[i+1][1+1] ; if ((hM.keys())->includes(sec) & hM[sec+1] = first) then ( execute ("(")->display() ) else ( hM[first+1] := sec )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque import sys,heapq,bisect,math,itertools,string,queue,datetime sys.setrecursionlimit(10**8) INF=float('inf') mod=10**9+7 eps=10**-7 def inpl(): return list(map(int,input().split())) def inpl_str(): return list(input().split()) def calc(p,x): return p*(100+x)//100 while True : r,n=inpl() if r==0 : break else : heights=defaultdict(int) ans=INF for _ in range(n): xl,xr,h=inpl() heights[xl+0.1]=max(heights[xl+0.1],h) heights[xr-0.1]=max(heights[xr-0.1],h) for x in range(xl+1,xr): heights[x-0.1]=max(heights[x-0.1],h) heights[x+0.1]=max(heights[x+0.1],h) for x in range(-23,23): h=min(heights[x-0.1],heights[x+0.1]) if r>abs(x): tmp=h-(r**2-x**2)**(1/2) ans=min(ans,tmp+r) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var eps : double := (10)->pow(-7) ; skip ; skip ; skip ; while true do ( var r : OclAny := null; var n : OclAny := null; Sequence{r,n} := inpl() ; if r = 0 then ( break ) else ( var heights : OclAny := defaultdict(OclType["int"]) ; var ans : OclAny := INF ; for _anon : Integer.subrange(0, n-1) do ( var xl : OclAny := null; var xr : OclAny := null; var h : OclAny := null; Sequence{xl,xr,h} := inpl() ; heights[xl + 0.1+1] := Set{heights[xl + 0.1+1], h}->max() ; heights[xr - 0.1+1] := Set{heights[xr - 0.1+1], h}->max() ; for x : Integer.subrange(xl + 1, xr-1) do ( heights[x - 0.1+1] := Set{heights[x - 0.1+1], h}->max() ; heights[x + 0.1+1] := Set{heights[x + 0.1+1], h}->max())) ; for x : Integer.subrange(-23, 23-1) do ( var h : OclAny := Set{heights[x - 0.1+1], heights[x + 0.1+1]}->min() ; if (r->compareTo((x)->abs())) > 0 then ( var tmp : double := h - (((r)->pow(2) - (x)->pow(2)))->pow((1 / 2)) ; ans := Set{ans, tmp + r}->min() ) else skip) ; execute (ans)->display() )); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inpl_str() : OclAny pre: true post: true activity: return (input().split()); operation calc(p : OclAny, x : OclAny) : OclAny pre: true post: true activity: return p * (100 + x) div 100; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline for _ in range(int(input())): n=int(input()) x=[] y=[] for i in range(2*n): a,b=input().split() a=int(a) b=int(b) if a==0 : y.append(abs(b)) else : x.append(abs(a)) x.sort() y.sort() ans=0 for i in range(n): ans+=(x[i]*x[i]+y[i]*y[i])**0.5 print((ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := Sequence{} ; var y : Sequence := Sequence{} ; for i : Integer.subrange(0, 2 * n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; if a = 0 then ( execute (((b)->abs()) : y) ) else ( execute (((a)->abs()) : x) )) ; x := x->sort() ; y := y->sort() ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( ans := ans + ((x[i+1] * x[i+1] + y[i+1] * y[i+1]))->pow(0.5)) ; execute ((ans))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Divisible(arr,n): count_even=0 for i in range(n): if(arr[i]% 2==0): count_even+=1 return count_even+(n-count_even)//2 arr=[1,2,3,4,5] n=len(arr) print(Divisible(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ; n := (arr)->size() ; execute (Divisible(arr, n))->display(); operation Divisible(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count_even : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] mod 2 = 0) then ( count_even := count_even + 1 ) else skip) ; return count_even + (n - count_even) div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(interval,N,Q): Mark=[0 for i in range(Q)] for i in range(N): l=interval[i][0]-1 r=interval[i][1]-1 for j in range(l,r+1): Mark[j]+=1 count=0 for i in range(Q): if(Mark[i]): count+=1 count1=[0 for i in range(Q)] if(Mark[0]==1): count1[0]=1 for i in range(1,Q): if(Mark[i]==1): count1[i]=count1[i-1]+1 else : count1[i]=count1[i-1] maxindex=0 maxcoverage=0 for i in range(N): l=interval[i][0]-1 r=interval[i][1]-1 elem1=0 if(l!=0): elem1=count1[r]-count1[l-1] else : elem1=count1[r] if(count-elem1>=maxcoverage): maxcoverage=count-elem1 maxindex=i print("Maximum Coverage is",maxcoverage,"after removing interval at index",maxindex) interval=[[1,4],[4,5],[5,6],[6,7],[3,5]] N=len(interval) Q=7 solve(interval,N,Q) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; interval := Sequence{Sequence{1}->union(Sequence{ 4 })}->union(Sequence{Sequence{4}->union(Sequence{ 5 })}->union(Sequence{Sequence{5}->union(Sequence{ 6 })}->union(Sequence{Sequence{6}->union(Sequence{ 7 })}->union(Sequence{ Sequence{3}->union(Sequence{ 5 }) })))) ; N := (interval)->size() ; Q := 7 ; solve(interval, N, Q); operation solve(interval : OclAny, N : OclAny, Q : OclAny) pre: true post: true activity: var Mark : Sequence := Integer.subrange(0, Q-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, N-1) do ( var l : double := interval[i+1]->first() - 1 ; var r : double := interval[i+1][1+1] - 1 ; for j : Integer.subrange(l, r + 1-1) do ( Mark[j+1] := Mark[j+1] + 1)) ; var count : int := 0 ; for i : Integer.subrange(0, Q-1) do ( if (Mark[i+1]) then ( count := count + 1 ) else skip) ; var count1 : Sequence := Integer.subrange(0, Q-1)->select(i | true)->collect(i | (0)) ; if (Mark->first() = 1) then ( count1->first() := 1 ) else skip ; for i : Integer.subrange(1, Q-1) do ( if (Mark[i+1] = 1) then ( count1[i+1] := count1[i - 1+1] + 1 ) else ( count1[i+1] := count1[i - 1+1] )) ; var maxindex : int := 0 ; var maxcoverage : int := 0 ; for i : Integer.subrange(0, N-1) do ( l := interval[i+1]->first() - 1 ; r := interval[i+1][1+1] - 1 ; var elem1 : int := 0 ; if (l /= 0) then ( elem1 := count1[r+1] - count1[l - 1+1] ) else ( elem1 := count1[r+1] ) ; if ((count - elem1->compareTo(maxcoverage)) >= 0) then ( maxcoverage := count - elem1 ; maxindex := i ) else skip) ; execute ("Maximum Coverage is")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isDivisible(n): while(n//100): d=n % 10 n//=10 n-=d*5 return(n % 17==0) if __name__=="__main__" : n=19877658 if isDivisible(n): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 19877658 ; if isDivisible(n) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isDivisible(n : OclAny) : OclAny pre: true post: true activity: while (n div 100) do ( var d : int := n mod 10 ; n := n div 10 ; n := n - d * 5) ; return (n mod 17 = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def convertOpposite(str): ln=len(str) for i in range(ln): if str[i]>='a' and str[i]<='z' : str[i]=chr(ord(str[i])-32) elif str[i]>='A' and str[i]<='Z' : str[i]=chr(ord(str[i])+32) if __name__=="__main__" : str="GeEkSfOrGeEkS" str=list(str) convertOpposite(str) str=''.join(str) print(str) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( OclType["String"] := "GeEkSfOrGeEkS" ; OclType["String"] := (OclType["String"])->characters() ; convertOpposite(OclType["String"]) ; OclType["String"] := StringLib.sumStringsWithSeparator((OclType["String"]), '') ; execute (OclType["String"])->display() ) else skip; operation convertOpposite(OclType["String"] : OclAny) pre: true post: true activity: var ln : int := (OclType["String"])->size() ; for i : Integer.subrange(0, ln-1) do ( if ("" + ([i+1])) >= 'a' & ("" + ([i+1])) <= 'z' then ( ("" + ([i+1])) := ((("" + ([i+1])))->char2byte() - 32)->byte2char() ) else (if ("" + ([i+1])) >= 'A' & ("" + ([i+1])) <= 'Z' then ( ("" + ([i+1])) := ((("" + ([i+1])))->char2byte() + 32)->byte2char() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def search(arr,n,x): for i in range(n): if arr[i]==x : return i return-1 arr=[1,10,30,15] x=30 n=len(arr) print(x,"is present at index",search(arr,n,x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{10}->union(Sequence{30}->union(Sequence{ 15 }))) ; x := 30 ; n := (arr)->size() ; execute (x)->display(); operation search(arr : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if arr[i+1] = x then ( return i ) else skip) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def getNeighbours(x,y,canyon,k): N=len(canyon[0]) inBound=lambda x,y : 0<=x<2 and y>=0 results=[] directions=[[1,k],[0,1],[-1,k],[0,-1]] for px,py in directions : nx,ny=x+px,y+py if inBound(nx,ny): results.append((nx,ny)) return results def canJump(canyon,k): queue=deque([(0,0)]) visited=set() level=-1 while queue : size=len(queue) for _ in range(size): x,y=queue.popleft() if y>=len(canyon[1]): return "YES" pos=canyon[x][y] if(x,y)not in visited and pos!='X' and y>level : visited.add((x,y)) for nei in getNeighbours(x,y,canyon,k): queue.append(nei) level+=1 return "NO" n,k=list(map(int,input().split())) canyon=[] for _ in range(2): canyon.append(list(input())) print(canJump(canyon,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var n : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; canyon := Sequence{} ; for _anon : Integer.subrange(0, 2-1) do ( execute ((((OclFile["System.in"]).readLine())->characters()) : canyon)) ; execute (canJump(canyon, k))->display(); operation getNeighbours(x : OclAny, y : OclAny, canyon : OclAny, k : OclAny) : OclAny pre: true post: true activity: var N : int := (canyon->first())->size() ; var inBound : Function := lambda x : OclAny, y : OclAny in (0 <= x & (x < 2) & y >= 0) ; var results : Sequence := Sequence{} ; var directions : Sequence := Sequence{Sequence{1}->union(Sequence{ k })}->union(Sequence{Sequence{0}->union(Sequence{ 1 })}->union(Sequence{Sequence{-1}->union(Sequence{ k })}->union(Sequence{ Sequence{0}->union(Sequence{ -1 }) }))) ; for _tuple : directions do (var _indx : int := 1; var px : OclAny := _tuple->at(_indx); _indx := _indx + 1; var py : OclAny := _tuple->at(_indx); var nx : OclAny := null; var ny : OclAny := null; Sequence{nx,ny} := Sequence{x + px,y + py} ; if inBound->apply(nx, ny) then ( execute ((Sequence{nx, ny}) : results) ) else skip) ; return results; operation canJump(canyon : OclAny, k : OclAny) : OclAny pre: true post: true activity: var queue : Sequence := (Sequence{ Sequence{0, 0} }) ; var visited : Set := Set{}->union(()) ; var level : int := -1 ; while queue do ( var size : int := (queue)->size() ; for _anon : Integer.subrange(0, size-1) do ( Sequence{x,y} := queue->first() ; queue := queue->tail() ; if (y->compareTo((canyon[1+1])->size())) >= 0 then ( return "YES" ) else skip ; var pos : OclAny := canyon[x+1][y+1] ; if (visited)->excludes(Sequence{x, y}) & pos /= 'X' & (y->compareTo(level)) > 0 then ( execute ((Sequence{x, y}) : visited) ; for nei : getNeighbours(x, y, canyon, k) do ( execute ((nei) : queue)) ) else skip) ; level := level + 1) ; return "NO"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) l=input() r=input() data=[0,' '+l,' '+r] dist=[[1000000]*100005 for _ in range(3)] visited=[[False]*100005 for _ in range(3)] dist[1][1]=0 visited[1][1]=True qx,qy=[1],[1] while qy : x,y=qx.pop(),qy.pop() if dist[x][y]>=y : continue if x==1 : poss=[[1,y+1],[1,y-1],[2,y+k]] else : poss=[[2,y+1],[2,y-1],[1,y+k]] for i,e in enumerate(poss): newx,newy=e[0],e[1] if newy>n : print('YES') from sys import exit exit() if 0collect( _x | (OclType["int"])->apply(_x) ) ; var l : String := (OclFile["System.in"]).readLine() ; var r : String := (OclFile["System.in"]).readLine() ; var data : Sequence := Sequence{0}->union(Sequence{' ' + l}->union(Sequence{ ' ' + r })) ; var dist : Sequence := Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 1000000 }, 100005))) ; var visited : Sequence := Integer.subrange(0, 3-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ false }, 100005))) ; dist[1+1][1+1] := 0 ; visited[1+1][1+1] := true ; var qx : OclAny := null; var qy : OclAny := null; Sequence{qx,qy} := Sequence{Sequence{ 1 },Sequence{ 1 }} ; while qy do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{qx->last(),qy->last()} ; if (dist[x+1][y+1]->compareTo(y)) >= 0 then ( continue ) else skip ; if x = 1 then ( var poss : Sequence := Sequence{Sequence{1}->union(Sequence{ y + 1 })}->union(Sequence{Sequence{1}->union(Sequence{ y - 1 })}->union(Sequence{ Sequence{2}->union(Sequence{ y + k }) })) ) else ( poss := Sequence{Sequence{2}->union(Sequence{ y + 1 })}->union(Sequence{Sequence{2}->union(Sequence{ y - 1 })}->union(Sequence{ Sequence{1}->union(Sequence{ y + k }) })) ) ; for _tuple : Integer.subrange(1, (poss)->size())->collect( _indx | Sequence{_indx-1, (poss)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var e : OclAny := _tuple->at(_indx); var newx : OclAny := null; var newy : OclAny := null; Sequence{newx,newy} := Sequence{e->first(),e[1+1]} ; if (newy->compareTo(n)) > 0 then ( execute ('YES')->display() ; skip ; exit() ) else skip ; if 0 < newy & (newy <= n) & not(visited[newx+1][newy+1]) & data[newx+1][newy+1] = '-' then ( visited[newx+1][newy+1] := true ; dist[newx+1][newy+1] := dist[x+1][y+1] + 1 ; var qx : Sequence := Sequence{ newx }->union(qx) ; var qy : Sequence := Sequence{ newy }->union(qy) ) else skip)) ; execute ('NO')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- yes_answer=False def g(d,s,a,b): global yes_answer if yes_answer : return if d>n-1 : print('YES') yes_answer=True return if not(a[d]or s>d): a[d]=1 t.append((d,s,a,b)) n,k=map(int,input().split()) t=[(0,0,[q!='-' for q in input()],[q!='-' for q in input()])] while t : d,s,a,b=t.pop() g(d+1,s+1,a,b) g(d-1,s+1,a,b) g(d+k,s+1,b,a) if not yes_answer : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { attribute yes_answer : OclAny; operation initialise() pre: true post: true activity: var yes_answer : boolean := false ; skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : Sequence := Sequence{ Sequence{0, 0, (OclFile["System.in"]).readLine()->select(q | true)->collect(q | (q /= '-')), (OclFile["System.in"]).readLine()->select(q | true)->collect(q | (q /= '-'))} } ; while t do ( Sequence{d,s,a,b} := t->last() ; t := t->front() ; g(d + 1, s + 1, a, b) ; g(d - 1, s + 1, a, b) ; g(d + k, s + 1, b, a)) ; if not(yes_answer) then ( execute ('NO')->display() ) else skip; operation g(d : OclAny, s : OclAny, a : OclAny, b : OclAny) pre: true post: true activity: skip ; if yes_answer then ( return ) else skip ; if (d->compareTo(n - 1)) > 0 then ( execute ('YES')->display() ; yes_answer := true ; return ) else skip ; if not((a[d+1] or (s->compareTo(d)) > 0)) then ( a[d+1] := 1 ; execute ((Sequence{d, s, a, b}) : t) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque import sys n,k=map(int,input().split()) s1=input() s2=input() que=deque() ans='NO' que.append([0,1,0]) burn=[[0,0,0]for i in range(n)] while que : cord,st,turn=que.popleft() if st==1 : cur=s1 pr=s2 else : cur=s2 pr=s1 if cord+k>=n : print('YES') sys.exit() if cord-1>turn : if cur[cord-1]!='X' and burn[cord-1][st]==0 : burn[cord-1][st]=1 que.append([cord-1,st,turn+1]) if cur[cord+1]!='X' and burn[cord+1][st]==0 : burn[cord+1][st]=1 que.append([cord+1,st,turn+1]) if pr[cord+k]!='X' : if st==1 : if burn[cord+k][st+1]==0 : burn[cord+k][st+1]=1 que.append([cord+k,2,turn+1]) else : if burn[cord+k][st-1]==0 : burn[cord+k][st-1]=1 que.append([cord+k,1,turn+1]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s1 : String := (OclFile["System.in"]).readLine() ; var s2 : String := (OclFile["System.in"]).readLine() ; var que : Sequence := () ; var ans : String := 'NO' ; execute ((Sequence{0}->union(Sequence{1}->union(Sequence{ 0 }))) : que) ; var burn : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))) ; while que do ( var cord : OclAny := null; var st : OclAny := null; var turn : OclAny := null; Sequence{cord,st,turn} := que->first() ; que := que->tail() ; if st = 1 then ( var cur : String := s1 ; var pr : String := s2 ) else ( cur := s2 ; pr := s1 ) ; if (cord + k->compareTo(n)) >= 0 then ( execute ('YES')->display() ; sys.exit() ) else skip ; if (cord - 1->compareTo(turn)) > 0 then ( if cur[cord - 1+1] /= 'X' & burn[cord - 1+1][st+1] = 0 then ( burn[cord - 1+1][st+1] := 1 ; execute ((Sequence{cord - 1}->union(Sequence{st}->union(Sequence{ turn + 1 }))) : que) ) else skip ) else skip ; if cur[cord + 1+1] /= 'X' & burn[cord + 1+1][st+1] = 0 then ( burn[cord + 1+1][st+1] := 1 ; execute ((Sequence{cord + 1}->union(Sequence{st}->union(Sequence{ turn + 1 }))) : que) ) else skip ; if pr[cord + k+1] /= 'X' then ( if st = 1 then ( if burn[cord + k+1][st + 1+1] = 0 then ( burn[cord + k+1][st + 1+1] := 1 ; execute ((Sequence{cord + k}->union(Sequence{2}->union(Sequence{ turn + 1 }))) : que) ) else skip ) else ( if burn[cord + k+1][st - 1+1] = 0 then ( burn[cord + k+1][st - 1+1] := 1 ; execute ((Sequence{cord + k}->union(Sequence{1}->union(Sequence{ turn + 1 }))) : que) ) else skip ) ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,input().split()) A=input() B=input() dat=[[]for _ in range(N*2)] for x in range(N): if A[x]=="X" : continue if x+1=0 and A[x-1]=="-" : dat[x].append(x-1) if x+KN-1 : dat[x].append(N*2-1) for x in range(N): if B[x]=="X" : continue if x+1=0 and B[x-1]=="-" : dat[x+N].append(x-1+N) if x+KN-1 : dat[x+N].append(N-1) def bfs(linked): visited=[0]*(N*2) visited[0]=1 num=1 while linked : i=[] for x in linked : if visited[x]==1 : continue if x==N-1 or x==N*2-1 : exit(print("YES")) visited[x]=1 for y in dat[x]: if visited[y]==1 or y % N<=num : continue i.append(y) linked=i num+=1 bfs(dat[0]) print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : String := (OclFile["System.in"]).readLine() ; var B : String := (OclFile["System.in"]).readLine() ; var dat : Sequence := Integer.subrange(0, N * 2-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for x : Integer.subrange(0, N-1) do ( if A[x+1] = "X" then ( continue ) else skip ; if (x + 1->compareTo(N)) < 0 & A[x + 1+1] = "-" then ( (expr (atom (name dat)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (number (integer 1)))))))))) )))) ) else skip ; if x - 1 >= 0 & A[x - 1+1] = "-" then ( (expr (atom (name dat)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) )))) ) else skip ; if (x + K->compareTo(N)) < 0 & B[x + K+1] = "-" then ( (expr (atom (name dat)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name N))) + (expr (atom (name x)))) + (expr (atom (name K))))))))) )))) ) else skip ; if (x + K->compareTo(N - 1)) > 0 then ( (expr (atom (name dat)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name N))) * (expr (atom (number (integer 2))))) - (expr (atom (number (integer 1)))))))))) )))) ) else skip) ; for x : Integer.subrange(0, N-1) do ( if B[x+1] = "X" then ( continue ) else skip ; if (x + 1->compareTo(N)) < 0 & B[x + 1+1] = "-" then ( (expr (atom (name dat)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (name N))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name x))) + (expr (atom (number (integer 1))))) + (expr (atom (name N))))))))) )))) ) else skip ; if x - 1 >= 0 & B[x - 1+1] = "-" then ( (expr (atom (name dat)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (name N))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name x))) - (expr (atom (number (integer 1))))) + (expr (atom (name N))))))))) )))) ) else skip ; if (x + K->compareTo(N)) < 0 & A[x + K+1] = "-" then ( (expr (atom (name dat)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (name N))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (name K))))))))) )))) ) else skip ; if (x + K->compareTo(N - 1)) > 0 then ( (expr (atom (name dat)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (name N))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name N))) - (expr (atom (number (integer 1)))))))))) )))) ) else skip) ; skip ; bfs(dat->first()) ; execute ("NO")->display(); operation bfs(linked : OclAny) pre: true post: true activity: var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N * 2)) ; visited->first() := 1 ; var num : int := 1 ; while linked do ( var i : Sequence := Sequence{} ; for x : linked do ( if visited[x+1] = 1 then ( continue ) else skip ; if x = N - 1 or x = N * 2 - 1 then ( exit(("YES")->display()) ) else skip ; visited[x+1] := 1 ; for y : dat[x+1] do ( if visited[y+1] = 1 or (y mod N->compareTo(num)) <= 0 then ( continue ) else skip ; execute ((y) : i))) ; linked := i ; num := num + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countNonDecreasing(n): N=10 count=1 for i in range(1,n+1): count=int(count*(N+i-1)) count=int(count/i) return count n=3 ; print(countNonDecreasing(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3; ; execute (countNonDecreasing(n))->display(); operation countNonDecreasing(n : OclAny) : OclAny pre: true post: true activity: var N : int := 10 ; var count : int := 1 ; for i : Integer.subrange(1, n + 1-1) do ( count := ("" + ((count * (N + i - 1))))->toInteger() ; count := ("" + ((count / i)))->toInteger()) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSubStr(strr,lenn): ans=0 for i in range(lenn): if(strr[i]=='0'): ans+=(i+1) return ans strr="10010" lenn=len(strr) print(countSubStr(strr,lenn)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; strr := "10010" ; lenn := (strr)->size() ; execute (countSubStr(strr, lenn))->display(); operation countSubStr(strr : OclAny, lenn : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, lenn-1) do ( if (strr[i+1] = '0') then ( ans := ans + (i + 1) ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def highestPower(str,lenngth): ans=0 ; for i in range(lenngth-1,-1,-1): if(str[i]=='0'): ans+=1 ; else : break ; return ans ; def main(): str="100100" ; lenngth=len(str); print(highestPower(str,lenngth)); if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation highestPower(OclType["String"] : OclAny, lenngth : OclAny) pre: true post: true activity: var ans : int := 0; ; for i : Integer.subrange(-1 + 1, lenngth - 1)->reverse() do ( if (("" + ([i+1])) = '0') then ( ans := ans + 1; ) else ( break; )) ; return ans;; operation main() pre: true post: true activity: OclType["String"] := "100100"; ; lenngth := (OclType["String"])->size(); ; execute (highestPower(OclType["String"], lenngth))->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def countdigits(N): count=0 ; while(N): count=count+1 ; N=int(math.floor(N/10)); return count ; def cyclic(N): num=N ; n=countdigits(N); while(1): print(int(num)); rem=num % 10 ; div=math.floor(num/10); num=((math.pow(10,n-1))*rem+div); if(num==N): break ; N=5674 ; cyclic(N); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; N := 5674; ; cyclic(N);; operation countdigits(N : OclAny) pre: true post: true activity: var count : int := 0; ; while (N) do ( count := count + 1; ; N := ("" + (((N / 10)->floor())))->toInteger();) ; return count;; operation cyclic(N : OclAny) pre: true post: true activity: var num : OclAny := N; ; var n : OclAny := countdigits(N); ; while (1) do ( execute (("" + ((num)))->toInteger())->display(); ; var rem : int := num mod 10; ; var div : double := (num / 10)->floor(); ; num := (((10)->pow(n - 1)) * rem + div); ; if (num = N) then ( break; ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) lst=[100000 for _ in range(n)] a_lst=list(map(int,input().split())) for a in a_lst : lst[a-1]=0 for i in range(n-1): lst[i+1]=min(lst[i]+1,lst[i+1]) for i in range(n-1,0,-1): lst[i-1]=min(lst[i-1],lst[i]+1) print(max(lst)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lst : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (100000)) ; var a_lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for a : a_lst do ( lst[a - 1+1] := 0) ; for i : Integer.subrange(0, n - 1-1) do ( lst[i + 1+1] := Set{lst[i+1] + 1, lst[i + 1+1]}->min()) ; for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( lst[i - 1+1] := Set{lst[i - 1+1], lst[i+1] + 1}->min()) ; execute ((lst)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isDivisible(n): while(int(n/100)): last_digit=int(n % 10) n=int(n/10) n+=last_digit*3 return(n % 29==0) n=348 if(isDivisible(n)!=0): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 348 ; if (isDivisible(n) /= 0) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isDivisible(n : OclAny) : OclAny pre: true post: true activity: while (("" + ((n / 100)))->toInteger()) do ( var last_digit : int := ("" + ((n mod 10)))->toInteger() ; n := ("" + ((n / 10)))->toInteger() ; n := n + last_digit * 3) ; return (n mod 29 = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def printArr(arr,n): for i in range(n): print(arr[i],end=" "); def constructArr(pair,n): size=int((1+sqrt(1+8*n))//2); arr=[0]*(size); arr[0]=int(sqrt((pair[0]*pair[1])/pair[size-1])); for i in range(1,size): arr[i]=pair[i-1]//arr[0]; printArr(arr,size); if __name__=="__main__" : pair=[48,18,24,24,32,12]; n=len(pair); constructArr(pair,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( pair := Sequence{48}->union(Sequence{18}->union(Sequence{24}->union(Sequence{24}->union(Sequence{32}->union(Sequence{ 12 }))))); ; n := (pair)->size(); ; constructArr(pair, n); ) else skip; operation printArr(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display();); operation constructArr(pair : OclAny, n : OclAny) pre: true post: true activity: var size : int := ("" + (((1 + sqrt(1 + 8 * n)) div 2)))->toInteger(); ; arr := MatrixLib.elementwiseMult(Sequence{ 0 }, (size)); ; arr->first() := ("" + ((sqrt((pair->first() * pair[1+1]) / pair[size - 1+1]))))->toInteger(); ; for i : Integer.subrange(1, size-1) do ( arr[i+1] := pair[i - 1+1] div arr->first();) ; printArr(arr, size);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) cnt=[6,2,5,5,4,5,6,3,7,6] res=0 for i in range(a,b+1): x=i while x>0 : res+=cnt[x % 10] x//=10 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cnt : Sequence := Sequence{6}->union(Sequence{2}->union(Sequence{5}->union(Sequence{5}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{3}->union(Sequence{7}->union(Sequence{ 6 }))))))))) ; var res : int := 0 ; for i : Integer.subrange(a, b + 1-1) do ( var x : OclAny := i ; while x > 0 do ( res := res + cnt[x mod 10+1] ; x := x div 10)) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=[6,2,5,5,4,5,6,3,7,6] a,b=map(int,input().split()) t=''.join(map(str,range(a,b+1))) print(sum(s[d]*t.count(str(d))for d in range(10))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := Sequence{6}->union(Sequence{2}->union(Sequence{5}->union(Sequence{5}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{3}->union(Sequence{7}->union(Sequence{ 6 }))))))))) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : String := StringLib.sumStringsWithSeparator(((Integer.subrange(a, b + 1-1))->collect( _x | (OclType["String"])->apply(_x) )), '') ; execute (((argument (test (logical_test (comparison (expr (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name d)))))))) ]))) * (expr (atom (name t)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name d)))))))) ))))))))) )))))))) (comp_for for (exprlist (expr (atom (name d)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 10))))))))) )))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=input() d=c.split(' ') a=int(d[0]) b=int(d[1]) suma=0 for j in range(a,b+1): k=str(j) for i in k : if i=='0' : suma+=6 elif i=='1' : suma+=2 elif i=='2' : suma+=5 elif i=='3' : suma+=5 elif i=='4' : suma+=4 elif i=='5' : suma+=5 elif i=='6' : suma+=6 elif i=='7' : suma+=3 elif i=='8' : suma+=7 elif i=='9' : suma+=6 print(suma) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : String := (OclFile["System.in"]).readLine() ; var d : OclAny := c.split(' ') ; var a : int := ("" + ((d->first())))->toInteger() ; var b : int := ("" + ((d[1+1])))->toInteger() ; var suma : int := 0 ; for j : Integer.subrange(a, b + 1-1) do ( var k : String := ("" + ((j))) ; for i : k->characters() do ( if i = '0' then ( suma := suma + 6 ) else (if i = '1' then ( suma := suma + 2 ) else (if i = '2' then ( suma := suma + 5 ) else (if i = '3' then ( suma := suma + 5 ) else (if i = '4' then ( suma := suma + 4 ) else (if i = '5' then ( suma := suma + 5 ) else (if i = '6' then ( suma := suma + 6 ) else (if i = '7' then ( suma := suma + 3 ) else (if i = '8' then ( suma := suma + 7 ) else (if i = '9' then ( suma := suma + 6 ) else skip ) ) ) ) ) ) ) ) ) )) ; execute (suma)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_segments=[6,2,5,5,4,5,6,3,7,6] a,b=[int(i)for i in input().split()] cycle=sum(num_segments) def sum_digits(number): if number=="" or number==[]: return 0 summ=0 for digit in str(number): summ+=num_segments[int(digit)] return summ S=0 current_number=a while current_number<=b : jump_number=current_number+10 if current_number==a : S+=sum_digits(current_number) current_number+=1 elif jump_numberunion(Sequence{2}->union(Sequence{5}->union(Sequence{5}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{3}->union(Sequence{7}->union(Sequence{ 6 }))))))))) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var cycle : OclAny := (num_segments)->sum() ; skip ; var S : int := 0 ; var current_number : OclAny := a ; while (current_number->compareTo(b)) <= 0 do ( var jump_number : OclAny := current_number + 10 ; if current_number = a then ( S := S + sum_digits(current_number) ; current_number := current_number + 1 ) else (if (jump_number->compareTo(b)) < 0 & (("" + ((jump_number))))->size() = (("" + ((current_number))))->size() & current_number mod 10 = 0 then ( S := S + cycle ; S := S + sum_digits(OclType["String"](current_number)->front()) * 10 ; current_number := current_number + 10 ) else ( S := S + sum_digits(current_number) ; current_number := current_number + 1 ) ) ) ; execute (S)->display(); operation sum_digits(number : OclAny) : OclAny pre: true post: true activity: if number = "" or number = Sequence{} then ( return 0 ) else skip ; var summ : int := 0 ; for digit : ("" + ((number))) do ( summ := summ + num_segments[("" + ((digit)))->toInteger()+1]) ; return summ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reduceString(s,l): count=1 ; steps=0 ; for i in range(1,l): if(s[i]is s[i-1]): count+=1 ; else : steps+=(int)(count/2); count=1 ; steps+=(int)(count/2); return steps ; s="geeksforgeeks" ; l=len(s); print(reduceString(s,l)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := "geeksforgeeks"; ; l := (s)->size(); ; execute (reduceString(s, l))->display();; operation reduceString(s : OclAny, l : OclAny) pre: true post: true activity: var count : int := 1; ; var steps : int := 0; ; for i : Integer.subrange(1, l-1) do ( if (s[i+1] <>= s[i - 1+1]) then ( count := count + 1; ) else ( steps := steps + (OclType["int"])(count / 2); ; count := 1; ) ; steps := steps + (OclType["int"])(count / 2);) ; return steps;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) N='6255456376' a,b=map(int,input().split()) s=''.join(map(str,range(a,b+1))) print(sum(int(N[d])*s.count(str(d))for d in range(10))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var N : String := '6255456376' ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := StringLib.sumStringsWithSeparator(((Integer.subrange(a, b + 1-1))->collect( _x | (OclType["String"])->apply(_x) )), '') ; execute (((argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name d)))))))) ])))))))) )))) * (expr (atom (name s)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name d)))))))) ))))))))) )))))))) (comp_for for (exprlist (expr (atom (name d)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 10))))))))) )))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=list(map(int,input().split())) for i in range(n): s=input() count=0 for j in range(len(s)): if s[j]=='a' or s[j]=='e' or s[j]=='i' or s[j]=='o' or s[j]=='u' or s[j]=='y' : count+=1 if count!=p[i]: print("NO") exit(0) print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var count : int := 0 ; for j : Integer.subrange(0, (s)->size()-1) do ( if s[j+1] = 'a' or s[j+1] = 'e' or s[j+1] = 'i' or s[j+1] = 'o' or s[j+1] = 'u' or s[j+1] = 'y' then ( count := count + 1 ) else skip) ; if count /= p[i+1] then ( execute ("NO")->display() ; exit(0) ) else skip) ; execute ("YES")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) p=list(map(int,input().split())) w=set() for i in list("aeiouy"): w.add(ord(i)) ans="YES" for i in p : s=list(input().rstrip()) cnt=0 for j in s : if j in w : cnt+=1 if i ^ cnt : ans="NO" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var w : Set := Set{}->union(()) ; for i : ("aeiouy")->characters() do ( execute (((i)->char2byte()) : w)) ; var ans : String := "YES" ; for i : p do ( var s : Sequence := (input().rstrip()) ; var cnt : int := 0 ; for j : s do ( if (w)->includes(j) then ( cnt := cnt + 1 ) else skip) ; if MathLib.bitwiseXor(i, cnt) then ( ans := "NO" ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline import re n=int(input()) w=list(map(int,input().split())) for i in range(n): c=re.findall(r'a|e|i|o|u|y',input()[:-1]) if len(c)!=w[i]: print("NO") break else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name re)) (trailer . (name findall) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom r 'a|e|i|o|u|y')))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))) != (comparison (expr (atom (name w)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,arrd,ans=int(input()),list(map(int,input().split())),"YES" for i in range(a): k=arrd[i] s=input() if s.count('a')+s.count('e')+s.count('i')+s.count('o')+s.count('u')+s.count('y')!=k : ans="NO" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var arrd : OclAny := null; var ans : OclAny := null; Sequence{a,arrd,ans} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),((input().split())->collect( _x | (OclType["int"])->apply(_x) )),"YES"} ; for i : Integer.subrange(0, a-1) do ( var k : OclAny := arrd[i+1] ; var s : String := (OclFile["System.in"]).readLine() ; if s->count('a') + s->count('e') + s->count('i') + s->count('o') + s->count('u') + s->count('y') /= k then ( var ans : String := "NO" ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isDivisible(n): while n//100 : d=n % 10 n//=10 n+=d*7 return(n % 23==0) if __name__=="__main__" : n=1191216 if(isDivisible(n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 1191216 ; if (isDivisible(n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isDivisible(n : OclAny) : OclAny pre: true post: true activity: while n div 100 do ( var d : int := n mod 10 ; n := n div 10 ; n := n + d * 7) ; return (n mod 23 = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p=list(map(int,input().split())) for i in range(n): s=input() count=0 for j in range(len(s)): if s[j]=='a' or s[j]=='e' or s[j]=='i' or s[j]=='o' or s[j]=='u' or s[j]=='y' : count+=1 if count!=p[i]: print("NO") exit(0) print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var count : int := 0 ; for j : Integer.subrange(0, (s)->size()-1) do ( if s[j+1] = 'a' or s[j+1] = 'e' or s[j+1] = 'i' or s[j+1] = 'o' or s[j+1] = 'u' or s[j+1] = 'y' then ( count := count + 1 ) else skip) ; if count /= p[i+1] then ( execute ("NO")->display() ; exit(0) ) else skip) ; execute ("YES")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def center_octadecagon_num(n): return(9*n*n-9*n+1) if __name__=='__main__' : n=3 print(n,"rd centered octadecagonal "+"number : ",center_octadecagon_num(n)) n=13 print(n,"th centered octadecagonal "+"number : ",center_octadecagon_num(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 3 ; execute (n)->display() ; n := 13 ; execute (n)->display() ) else skip; operation center_octadecagon_num(n : OclAny) : OclAny pre: true post: true activity: return (9 * n * n - 9 * n + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairs(arr1,arr2,m,n,x): count,l,r=0,0,n-1 while(l=0): if((arr1[l]+arr2[r])==x): l+=1 r-=1 count+=1 elif((arr1[l]+arr2[r])collect( _x | (OclType["int"])->apply(_x) ) ; if (A->compareTo(B)) <= 0 then ( execute ("Impossible")->display() ; exit(0) ) else skip ; var chain : Sequence := Sequence{} ; var N : OclAny := A + B ; skip ; for i : Integer.subrange(0, N-1) do ( if (chain)->size() = 0 then ( execute ((i) : chain) ; continue ) else skip ; var last : OclAny := chain->last() ; if ask(last, i) then ( execute ((i) : chain) ) else ( chain := chain->front() )) ; var main : OclAny := chain->last() ; chain := chain->front() ; var ret : Sequence := Integer.subrange(0, N-1)->select(x | true)->collect(x | ((if ask(main, x) then '1' else '0' endif))) ; execute (StringLib.format("! %s",(StringLib.sumStringsWithSeparator((ret), ""))))->display(); operation ask(i : OclAny, j : OclAny) : OclAny pre: true post: true activity: execute (StringLib.format("? %d %d",Sequence{i, j}))->display() ; return (OclFile["System.in"]).readLine() = 'Y'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,ceil N=10001 v=[[]for i in range(N)] def preprocess(): for i in range(1,N): num=i for j in range(2,ceil(sqrt(num))+1): if(num % j==0): v[i].append(j) while(num % j==0): num=num//j if(num>2): v[i].append(num) def query(number,n): return v[number][n-1] preprocess() number=6 n=1 print(query(number,n)) number=210 n=3 print(query(number,n)) number=210 n=2 print(query(number,n)) number=60 n=2 print(query(number,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 10001 ; var v : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{})) ; skip ; skip ; preprocess() ; number := 6 ; n := 1 ; execute (query(number, n))->display() ; number := 210 ; n := 3 ; execute (query(number, n))->display() ; number := 210 ; n := 2 ; execute (query(number, n))->display() ; number := 60 ; n := 2 ; execute (query(number, n))->display(); operation preprocess() pre: true post: true activity: for i : Integer.subrange(1, N-1) do ( var num : OclAny := i ; for j : Integer.subrange(2, ceil(sqrt(num)) + 1-1) do ( if (num mod j = 0) then ( (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) ; while (num mod j = 0) do ( num := num div j) ) else skip) ; if (num > 2) then ( (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) )))) ) else skip); operation query(number : OclAny, n : OclAny) : OclAny pre: true post: true activity: return v[number+1][n - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INT_MIN=-2147483648 def isPresent(B,m,x): for i in range(0,m): if B[i]==x : return True return False def findMaxSubarraySumUtil(A,B,n,m): max_so_far=INT_MIN curr_max=0 for i in range(0,n): if isPresent(B,m,A[i])==True : curr_max=0 continue curr_max=max(A[i],curr_max+A[i]) max_so_far=max(max_so_far,curr_max) return max_so_far def findMaxSubarraySum(A,B,n,m): maxSubarraySum=findMaxSubarraySumUtil(A,B,n,m) if maxSubarraySum==INT_MIN : print('Maximum Subarray Sum cant be found') else : print('The Maximum Subarray Sum=',maxSubarraySum) A=[3,4,5,-4,6] B=[1,8,5] n=len(A) m=len(B) findMaxSubarraySum(A,B,n,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INT_MIN : int := -2147483648 ; skip ; skip ; skip ; A := Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{-4}->union(Sequence{ 6 })))) ; B := Sequence{1}->union(Sequence{8}->union(Sequence{ 5 })) ; n := (A)->size() ; m := (B)->size() ; findMaxSubarraySum(A, B, n, m); operation isPresent(B : OclAny, m : OclAny, x : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, m-1) do ( if B[i+1] = x then ( return true ) else skip) ; return false; operation findMaxSubarraySumUtil(A : OclAny, B : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var max_so_far : int := INT_MIN ; var curr_max : int := 0 ; for i : Integer.subrange(0, n-1) do ( if isPresent(B, m, A[i+1]) = true then ( curr_max := 0 ; continue ) else skip ; curr_max := Set{A[i+1], curr_max + A[i+1]}->max() ; max_so_far := Set{max_so_far, curr_max}->max()) ; return max_so_far; operation findMaxSubarraySum(A : OclAny, B : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: var maxSubarraySum : OclAny := findMaxSubarraySumUtil(A, B, n, m) ; if maxSubarraySum = INT_MIN then ( execute ('Maximum Subarray Sum cant be found')->display() ) else ( execute ('The Maximum Subarray Sum=')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reversDigits(num): negativeFlag=False if(num<0): negativeFlag=True num=-num prev_rev_num=0 rev_num=0 while(num!=0): curr_digit=num % 10 rev_num=(rev_num*10)+curr_digit if(rev_num>=2147483647 or rev_num<=-2147483648): rev_num=0 if((rev_num-curr_digit)//10!=prev_rev_num): print("WARNING OVERFLOWED!!!") return 0 prev_rev_num=rev_num num=num//10 return-rev_num if(negativeFlag==True)else rev_num if __name__=="__main__" : num=12345 print("Reverse of no.is ",reversDigits(num)) num=1000000045 print("Reverse of no.is ",reversDigits(num)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( num := 12345 ; execute ("Reverse of no.is ")->display() ; num := 1000000045 ; execute ("Reverse of no.is ")->display() ) else skip; operation reversDigits(num : OclAny) : OclAny pre: true post: true activity: var negativeFlag : boolean := false ; if (num < 0) then ( negativeFlag := true ; num := -num ) else skip ; var prev_rev_num : int := 0 ; var rev_num : int := 0 ; while (num /= 0) do ( var curr_digit : int := num mod 10 ; rev_num := (rev_num * 10) + curr_digit ; if (rev_num >= 2147483647 or rev_num <= -2147483648) then ( rev_num := 0 ) else skip ; if ((rev_num - curr_digit) div 10 /= prev_rev_num) then ( execute ("WARNING OVERFLOWED!!!")->display() ; return 0 ) else skip ; prev_rev_num := rev_num ; num := num div 10) ; return if (negativeFlag = true) then -rev_num else rev_num endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=90 ; arr=[0]*(MAX); index1=[0]*(MAX); index2=[0]*(MAX); index3=[0]*(MAX); index4=[0]*(MAX); arr[0]=0 ; arr[1]=1 ; for i in range(2,MAX): arr[i]=arr[i-1]+arr[i-2]; c1,c2,c3,c4=0,0,0,0 ; for i in range(MAX): if(arr[i]% 2==0): index1[c1]=i ; c1+=1 ; if(arr[i]% 3==0): index2[c2]=i ; c2+=1 ; if(arr[i]% 5==0): index3[c3]=i ; c3+=1 ; if(arr[i]% 8==0): index4[c4]=i ; c4+=1 ; print("Index of Fibonacci numbers","divisible by 2 are :"); for i in range(c1): print(index1[i],end=""); print(""); print("Index of Fibonacci number","divisible by 3 are :"); for i in range(c2): print(index2[i],end=""); print(""); print("Index of Fibonacci number","divisible by 5 are :"); for i in range(c3): print(index3[i],end=""); print(""); print("Index of Fibonacci number","divisible by 8 are :"); for i in range(c4): print(index4[i],end=""); print(""); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 90; ; var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX)); ; var index1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX)); ; var index2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX)); ; var index3 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX)); ; var index4 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX)); ; arr->first() := 0; ; arr[1+1] := 1; ; for i : Integer.subrange(2, MAX-1) do ( arr[i+1] := arr[i - 1+1] + arr[i - 2+1];) ; var c1 : OclAny := null; var c2 : OclAny := null; var c3 : OclAny := null; var c4 : OclAny := null; Sequence{c1,c2,c3,c4} := Sequence{0,0,0,0}; ; for i : Integer.subrange(0, MAX-1) do ( if (arr[i+1] mod 2 = 0) then ( index1[c1+1] := i; ; c1 := c1 + 1; ) else skip ; if (arr[i+1] mod 3 = 0) then ( index2[c2+1] := i; ; c2 := c2 + 1; ) else skip ; if (arr[i+1] mod 5 = 0) then ( index3[c3+1] := i; ; c3 := c3 + 1; ) else skip ; if (arr[i+1] mod 8 = 0) then ( index4[c4+1] := i; ; c4 := c4 + 1; ) else skip) ; execute ("Index of Fibonacci numbers")->display(); ; for i : Integer.subrange(0, c1-1) do ( execute (index1[i+1])->display();) ; execute ("")->display(); ; execute ("Index of Fibonacci number")->display(); ; for i : Integer.subrange(0, c2-1) do ( execute (index2[i+1])->display();) ; execute ("")->display(); ; execute ("Index of Fibonacci number")->display(); ; for i : Integer.subrange(0, c3-1) do ( execute (index3[i+1])->display();) ; execute ("")->display(); ; execute ("Index of Fibonacci number")->display(); ; for i : Integer.subrange(0, c4-1) do ( execute (index4[i+1])->display();) ; execute ("")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Circumference(a): return(4*a) a=5 c=Circumference(a) print("Circumference of a "+"square is % d" %(c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 5 ; var c : OclAny := Circumference(a) ; execute ("Circumference of a " + StringLib.format("square is % d",(c)))->display(); operation Circumference(a : OclAny) : OclAny pre: true post: true activity: return (4 * a); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w,h,k=(int(i)for i in input().split()) res=0 while w>0 and h>2 and k>0 : res+=2*w+2*(h-2) w-=4 h-=4 k-=1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : OclAny := null; var h : OclAny := null; var k : OclAny := null; Sequence{w,h,k} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var res : int := 0 ; while w > 0 & h > 2 & k > 0 do ( res := res + 2 * w + 2 * (h - 2) ; w := w - 4 ; h := h - 4 ; k := k - 1) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isDivisible(n): while n//100 : d=n % 10 n//=10 n-=d*4 return n % 41==0 if __name__=="__main__" : n=104413920565933 if isDivisible(n): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 104413920565933 ; if isDivisible(n) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isDivisible(n : OclAny) : OclAny pre: true post: true activity: while n div 100 do ( var d : int := n mod 10 ; n := n div 10 ; n := n - d * 4) ; return n mod 41 = 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w,h,k=map(int,input().split()) s=0 for i in range(k,0,-1): s+=2*(w-4*(i-1))+2*(h-4*(i-1))-4 print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : OclAny := null; var h : OclAny := null; var k : OclAny := null; Sequence{w,h,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : int := 0 ; for i : Integer.subrange(0 + 1, k)->reverse() do ( s := s + 2 * (w - 4 * (i - 1)) + 2 * (h - 4 * (i - 1)) - 4) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=list(map(int,input().split())) x,y,n=l[0],l[1],l[2] t=2*n*x+2*n*y+4*n-(8*(n**2)) print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := null; var y : OclAny := null; var n : OclAny := null; Sequence{x,y,n} := Sequence{l->first(),l[1+1],l[2+1]} ; var t : double := 2 * n * x + 2 * n * y + 4 * n - (8 * ((n)->pow(2))) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w,h,k=input().split() w=int(w) h=int(h) k=int(k) ans=0 while True : if k==0 : break ans=ans+2*(w+h-2) w=w-4 h=h-4 k=k-1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : OclAny := null; var h : OclAny := null; var k : OclAny := null; Sequence{w,h,k} := input().split() ; var w : int := ("" + ((w)))->toInteger() ; var h : int := ("" + ((h)))->toInteger() ; var k : int := ("" + ((k)))->toInteger() ; var ans : int := 0 ; while true do ( if k = 0 then ( break ) else skip ; ans := ans + 2 * (w + h - 2) ; w := w - 4 ; h := h - 4 ; k := k - 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections,sys p=print def ask(x,y): p('?',x,y) return input()=='Y' A,B=map(int,input().split()) r=range(A+B) if A<=B : p('Impossible') sys.exit() c=collections.deque(r) while len(c)>2 : x,y=c.pop(),c.pop() if ask(x,y): c.appendleft(y) p('!',''.join(str(int(ask(c[0],i)))for i in r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var p : OclAny := print ; skip ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var r : Sequence := Integer.subrange(0, A + B-1) ; if (A->compareTo(B)) <= 0 then ( p('Impossible') ; sys.exit() ) else skip ; var c : Sequence := (r) ; while (c)->size() > 2 do ( Sequence{x,y} := Sequence{c->last(),c->last()} ; if ask(x, y) then ( c := c->prepend(y) ) else skip) ; p('!', StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ask)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))) , (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name r)))))))), '')); operation ask(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: p('?', x, y) ; return (OclFile["System.in"]).readLine() = 'Y'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w,h,k=map(int,input().split()) s=0 for i in range(k): s=s+2*(w+h)-4 w=w-4 h=h-4 print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : OclAny := null; var h : OclAny := null; var k : OclAny := null; Sequence{w,h,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : int := 0 ; for i : Integer.subrange(0, k-1) do ( s := s + 2 * (w + h) - 4 ; var w : double := w - 4 ; var h : double := h - 4) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T,A=1,1 for _ in range(int(input())): a,b=map(int,input().split()) r=max(-(-T//a),-(-A//b)) T=r*a A=r*b print(T+A) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : OclAny := null; var A : OclAny := null; Sequence{T,A} := Sequence{1,1} ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var r : OclAny := Set{-(-T div a), -(-A div b)}->max() ; var T : double := r * a ; var A : double := r * b) ; execute (T + A)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict import math def LI(): return list(map(int,input().split())) def II(): return int(input()) def LS(): return input().split() def S(): return input() def IIR(n): return[II()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] mod=1000000007 n=II() x,y=LI() for _ in range(n-1): a,b=LI() if a==b : x=max(x,y) y=x else : i=max(x//a,y//b) while 1 : if a*i>=x and b*i>=y : break i+=1 x=a*i y=b*i print(x+y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : int := 1000000007 ; n := II() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := LI() ; for _anon : Integer.subrange(0, n - 1-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := LI() ; if a = b then ( var x : OclAny := Set{x, y}->max() ; var y : OclAny := x ) else ( var i : OclAny := Set{x div a, y div b}->max() ; while 1 do ( if (a * i->compareTo(x)) >= 0 & (b * i->compareTo(y)) >= 0 then ( break ) else skip ; i := i + 1) ; x := a * i ; y := b * i )) ; execute (x + y)->display(); operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return input().split(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation IIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (II())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect,collections,copy,heapq,itertools,math,string,sys input=lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF=float('inf') def I(): return int(input()) def F(): return float(input()) def SS(): 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 LSS(): return input().split() def resolve(): N=I() TA=[LI()for _ in range(N)] t,a=TA[0] for i in range(1,N): T,A=TA[i] if t*A>a*T : rate=(t-1)//T+1 t=T*rate a=A*rate else : rate=(a-1)//A+1 t=T*rate a=A*rate print(t+a) if __name__=='__main__' : resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; sys.setrecursionlimit((10)->pow(7)) ; var INF : double := ("" + (('inf')))->toReal() ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( resolve() ) else skip; operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation SS() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation LI() : OclAny pre: true post: true activity: return input->apply().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return input->apply().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return input->apply().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LSS() : OclAny pre: true post: true activity: return input->apply().split(); operation resolve() pre: true post: true activity: var N : OclAny := I() ; var TA : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (LI())) ; var t : OclAny := null; var a : OclAny := null; Sequence{t,a} := TA->first() ; for i : Integer.subrange(1, N-1) do ( var T : OclAny := null; var A : OclAny := null; Sequence{T,A} := TA[i+1] ; if (t * A->compareTo(a * T)) > 0 then ( var rate : int := (t - 1) div T + 1 ; var t : double := T * rate ; var a : double := A * rate ) else ( rate := (a - 1) div A + 1 ; t := T * rate ; a := A * rate )) ; execute (t + a)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) ratio=[list(map(int,input().split()))for _ in range(N)] takahasi,aoki=ratio[0] for i in range(1,N): t_ratio,a_ratio=ratio[i] n=max(takahasi//t_ratio+min(1,takahasi % t_ratio),aoki//a_ratio+min(1,aoki % a_ratio)) takahasi=n*t_ratio aoki=n*a_ratio print(takahasi+aoki) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ratio : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var takahasi : OclAny := null; var aoki : OclAny := null; Sequence{takahasi,aoki} := ratio->first() ; for i : Integer.subrange(1, N-1) do ( var t_ratio : OclAny := null; var a_ratio : OclAny := null; Sequence{t_ratio,a_ratio} := ratio[i+1] ; var n : OclAny := Set{takahasi div t_ratio + Set{1, takahasi mod t_ratio}->min(), aoki div a_ratio + Set{1, aoki mod a_ratio}->min()}->max() ; var takahasi : double := n * t_ratio ; var aoki : double := n * a_ratio) ; execute (takahasi + aoki)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def read_values(): return map(int,input().split()) def read_list(): return list(read_values()) def f(p,q): t,a=q pt,pa=p nt=max((pt-1)//t+1,1) na=max((pa-1)//a+1,1) n=max(nt,na) return(n*t,n*a) def main(): N=int(input()) p=(1,1) for _ in range(N): q=read_list() p=f(p,q) print(sum(p)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation read_values() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation read_list() : OclAny pre: true post: true activity: return (read_values()); operation f(p : OclAny, q : OclAny) : OclAny pre: true post: true activity: var t : OclAny := null; var a : OclAny := null; Sequence{t,a} := q ; var pt : OclAny := null; var pa : OclAny := null; Sequence{pt,pa} := p ; var nt : OclAny := Set{(pt - 1) div t + 1, 1}->max() ; var na : OclAny := Set{(pa - 1) div a + 1, 1}->max() ; var n : OclAny := Set{nt, na}->max() ; return Sequence{n * t, n * a}; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; p := Sequence{1, 1} ; for _anon : Integer.subrange(0, N-1) do ( q := read_list() ; p := f(p, q)) ; execute ((p)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : t,n=input().split() t=int(t) if t==0 : exit() L=len(n) m=0 parts=[] f=False for b in range(1<<(L-1)): c=int(n[0]) s=0 li=[] for k in range(L-1): if b>>k & 1==1 : s+=c li.append(c) c=0 c=10*c+int(n[k+1]) s+=c li.append(c) c=0 if s>t : continue if s>=m : f=(s==m) m=s parts=li if f : print('rejected') elif m==0 : print('error') else : print(m,*parts,sep=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var t : OclAny := null; var n : OclAny := null; Sequence{t,n} := input().split() ; var t : int := ("" + ((t)))->toInteger() ; if t = 0 then ( exit() ) else skip ; var L : int := (n)->size() ; var m : int := 0 ; var parts : Sequence := Sequence{} ; var f : boolean := false ; for b : Integer.subrange(0, 1 * (2->pow((L - 1)))-1) do ( var c : int := ("" + ((n->first())))->toInteger() ; var s : int := 0 ; var li : Sequence := Sequence{} ; for k : Integer.subrange(0, L - 1-1) do ( if MathLib.bitwiseAnd(b /(2->pow(k)), 1) = 1 then ( s := s + c ; execute ((c) : li) ; c := 0 ) else skip ; c := 10 * c + ("" + ((n[k + 1+1])))->toInteger()) ; s := s + c ; execute ((c) : li) ; c := 0 ; if (s->compareTo(t)) > 0 then ( continue ) else skip ; if (s->compareTo(m)) >= 0 then ( f := (s = m) ; m := s ; parts := li ) else skip) ; if f then ( execute ('rejected')->display() ) else (if m = 0 then ( execute ('error')->display() ) else ( execute (m)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isDivisible(n): while(n//100): d=n % 10 n//=10 n+=d*2 return(n % 19==0) if __name__=="__main__" : n=101156 if(isDivisible(n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 101156 ; if (isDivisible(n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation isDivisible(n : OclAny) : OclAny pre: true post: true activity: while (n div 100) do ( var d : int := n mod 10 ; n := n div 10 ; n := n + d * 2) ; return (n mod 19 = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools from heapq import heappop,heappush from collections import defaultdict def main(t,num): num=list(str(num)) d=defaultdict(int) if t=tmp>a : a=tmp b=res heappush(q,[-a,b]) a,b=heappop(q) a*=-1 if d[a]or a==0 : print("rejected") else : ans=[] be=0 for i in b : ans.append(int("".join(num[be : i+1]))) be=i+1 ans.append(int("".join(num[be :]))) print(a,*ans) if __name__=="__main__" : while 1 : t,num=map(int,input().split()) if t==num==0 : break main(t,num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( while 1 do ( Sequence{t,num} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if t = num & (num == 0) then ( break ) else skip ; main(t, num)) ) else skip; operation main(t : OclAny, num : OclAny) pre: true post: true activity: num := (("" + ((num))))->characters() ; var d : OclAny := defaultdict(OclType["int"]) ; if (t->compareTo(((num)->collect( _x | (OclType["int"])->apply(_x) ))->sum())) < 0 then ( execute ("error")->display() ; return ) else skip ; var q : Sequence := Sequence{ Sequence{0}->union(Sequence{ Sequence{} }) } ; itertools.product() ; var fulls : OclAny := itertools.product(Integer.subrange(0, 2-1), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) )))) - (expr (atom (number (integer 1)))))))))) ; for full : fulls do ( var tmp : int := 0 ; var res : Sequence := Sequence{} ; var b : int := 0 ; var f : boolean := false ; for i : Integer.subrange(0, (num)->size() - 1-1) do ( if full[i+1] then ( execute ((i) : res) ; tmp := tmp + ("" + ((StringLib.sumStringsWithSeparator((num.subrange(b+1, i + 1)), ""))))->toInteger() ; b := i + 1 ) else skip) ; tmp := tmp + ("" + ((StringLib.sumStringsWithSeparator((num.subrange(b+1)), ""))))->toInteger() ; var a : OclAny := null; Sequence{a,b} := heappop(q) ; a := a * -1 ; if a = tmp then ( d[a+1] := d[a+1] + 1 ) else skip ; if (t->compareTo(tmp)) >= 0 & (tmp > a) then ( var a : int := tmp ; b := res ) else skip ; heappush(q, Sequence{-a}->union(Sequence{ b }))) ; Sequence{a,b} := heappop(q) ; a := a * -1 ; if d[a+1] or a = 0 then ( execute ("rejected")->display() ) else ( var ans : Sequence := Sequence{} ; var be : int := 0 ; for i : b do ( execute ((("" + ((StringLib.sumStringsWithSeparator((num.subrange(be+1, i + 1)), ""))))->toInteger()) : ans) ; be := i + 1) ; execute ((("" + ((StringLib.sumStringsWithSeparator((num.subrange(be+1)), ""))))->toInteger()) : ans) ; execute (a)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=list(input()) z='/' for i in range(len(n)): if n[i]=='/' and z[-1]!='/' : z+=n[i] if n[i]!='/' : z+=n[i] if len(z)>1 and z[-1]=='/' : print(z[0 :-1]) else : print(z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var z : String := '/' ; for i : Integer.subrange(0, (n)->size()-1) do ( if n[i+1] = '/' & z->last() /= '/' then ( z := z + n[i+1] ) else skip ; if n[i+1] /= '/' then ( z := z + n[i+1] ) else skip) ; if (z)->size() > 1 & z->last() = '/' then ( execute (z.subrange(0+1, -1))->display() ) else ( execute (z)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 def LI(): return list(map(int,input().split())) def LF(): return list(map(float,input().split())) def II(): return int(input()) def LS(): return input().split() def S(): return input() def pf(s): print(s,flush=True) def main(): a,b=LI() if a<=b : return 'Impossible' l=[] for i in range(a+b): if not l : l.append(i) continue pf('?{}{}'.format(i,l[-1])) if S()=='Y' : l.append(i) else : l=l[:-1] r=[] ai=l[0] for i in range(a+b): if i==ai : r.append('1') continue pf('?{}{}'.format(ai,i)) if S()=='Y' : r.append('1') else : r.append('0') return '!{}'.format(''.join(r)) print(main(),flush=True) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LF() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["double"])->apply(_x) )); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return input().split(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) pre: true post: true activity: execute (s)->display(); operation main() : OclAny pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := LI() ; if (a->compareTo(b)) <= 0 then ( return 'Impossible' ) else skip ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, a + b-1) do ( if not(l) then ( execute ((i) : l) ; continue ) else skip ; pf(StringLib.interpolateStrings('?{}{}', Sequence{i, l->last()})) ; if S() = 'Y' then ( execute ((i) : l) ) else ( l := l->front() )) ; var r : Sequence := Sequence{} ; var ai : OclAny := l->first() ; for i : Integer.subrange(0, a + b-1) do ( if i = ai then ( execute (('1') : r) ; continue ) else skip ; pf(StringLib.interpolateStrings('?{}{}', Sequence{ai, i})) ; if S() = 'Y' then ( execute (('1') : r) ) else ( execute (('0') : r) )) ; return StringLib.interpolateStrings('!{}', Sequence{StringLib.sumStringsWithSeparator((r), '')}); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() while '//' in x : x=x.replace('//','/') if len(x)==1 or x[-1]!='/' : print(x) else : print(x[:-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := (OclFile["System.in"]).readLine() ; while (x)->characters()->includes('//') do ( x := x.replace('//', '/')) ; if (x)->size() = 1 or x->last() /= '/' then ( execute (x)->display() ) else ( execute (x->front())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() s=a.replace('/','') s=s.split('') ans=[] for i in s : if i!='' : ans+=[i] if a[0]=='/' : print('/'+'/'.join(ans)) else : print('/'.join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var s : String := a.replace('/', '') ; s := s.split('') ; var ans : Sequence := Sequence{} ; for i : s->characters() do ( if i /= '' then ( ans := ans + Sequence{ i } ) else skip) ; if a->first() = '/' then ( execute ('/' + StringLib.sumStringsWithSeparator((ans), '/'))->display() ) else ( execute (StringLib.sumStringsWithSeparator((ans), '/'))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def spl(ss,tar): a,b=[],"" for i in range(len(ss)): if ss[i]!=tar : b+=ss[i] if ss[i]==tar and b!="" : a.append(b) b="" if b!="" : a.append(b) return a print("/"+"/".join(spl(input(),"/"))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute ("/" + StringLib.sumStringsWithSeparator((spl((OclFile["System.in"]).readLine(), "/")), "/"))->display(); operation spl(ss : OclAny, tar : OclAny) : OclAny pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{Sequence{},""} ; for i : Integer.subrange(0, (ss)->size()-1) do ( if ss[i+1] /= tar then ( b := b + ss[i+1] ) else skip ; if ss[i+1] = tar & b /= "" then ( execute ((b) : a) ; var b : String := "" ) else skip) ; if b /= "" then ( execute ((b) : a) ) else skip ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print("/"+"/".join(filter(None,input().split("/")))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ("/" + StringLib.sumStringsWithSeparator(((input().split("/"))->select( _x | (null)->apply(_x) = true )), "/"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,d=map(int,input().split()) d=d**2 key={} for i in range(26): key[chr(ord('a')+i)]=-1 key[chr(ord('A')+i)]=-1 a=[] for i in range(n): a.append(input()) shift=[] for i in range(n): for j in range(m): if a[i][j]=="S" : shift.append((i,j)) for i in range(n): for j in range(m): ch=a[i][j] if ch>="a" and ch<="z" : key[ch]=0 ch=ch.upper() if key[ch]<0 and len(shift)>0 : key[ch]=1 for(x,y)in shift : if(i-x)**2+(j-y)**2<=d : key[ch]=0 break res=0 input() for ch in input(): if key[ch]<0 : print(-1) exit() else : res+=key[ch] print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var d : OclAny := null; Sequence{n,m,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : double := (d)->pow(2) ; var key : OclAny := Set{} ; for i : Integer.subrange(0, 26-1) do ( key[(('a')->char2byte() + i)->byte2char()+1] := -1 ; key[(('A')->char2byte() + i)->byte2char()+1] := -1) ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : a)) ; var shift : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if a[i+1][j+1] = "S" then ( execute ((Sequence{i, j}) : shift) ) else skip)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( var ch : OclAny := a[i+1][j+1] ; if ch >= "a" & ch <= "z" then ( key[ch+1] := 0 ; ch := ch->toUpperCase() ; if key[ch+1] < 0 & (shift)->size() > 0 then ( key[ch+1] := 1 ) else skip ; for Sequence{x, y} : shift do ( if (((i - x))->pow(2) + ((j - y))->pow(2)->compareTo(d)) <= 0 then ( key[ch+1] := 0 ; break ) else skip) ) else skip)) ; var res : int := 0 ; input() ; for ch : (OclFile["System.in"]).readLine() do ( if key[ch+1] < 0 then ( execute (-1)->display() ; exit() ) else ( res := res + key[ch+1] )) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r_count,k_in_row,max_dis=map(int,input().split()) keyboard=[input()for _ in range(r_count)] query_size=input() word=input() used_letters=set(word) shift_indexes=[(row_index,l_i)for row_index,row in enumerate(keyboard)for l_i,l in enumerate(row)if l=='S'] for letter in used_letters : if not any([letter.lower()in row for row in keyboard])or(letter.isupper()and len(shift_indexes)==0): print(-1) exit(0) upper_letters=[letter for letter in used_letters if letter.isupper()] other_hand=0 for char in upper_letters : indexes=[(row_index,l_i)for row_index,row in enumerate(keyboard)for l_i,l in enumerate(row)if l==char.lower()] for y1,x1 in indexes : if any([pow(pow(abs(y2-y1),2)+pow(abs(x2-x1),2),0.5)<=max_dis for y2,x2 in shift_indexes]): break else : other_hand+=word.count(char) print(other_hand) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r_count : OclAny := null; var k_in_row : OclAny := null; var max_dis : OclAny := null; Sequence{r_count,k_in_row,max_dis} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var keyboard : Sequence := Integer.subrange(0, r_count-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var query_size : String := (OclFile["System.in"]).readLine() ; var word : String := (OclFile["System.in"]).readLine() ; var used_letters : Set := Set{}->union((word)) ; var shift_indexes : Sequence := Integer.subrange(1, (keyboard)->size())->collect( _indx | Sequence{_indx-1, (keyboard)->at(_indx)} )->select(_tuple | let row_index : OclAny = _tuple->at(1) in let row : OclAny = _tuple->at(2) in true)->collect(_tuple | let row_index : OclAny = _tuple->at(1) in let row : OclAny = _tuple->at(2) in (Sequence{row_index, l_i})) ; for letter : used_letters do ( if not((keyboard->select(row | true)->collect(row | ((row)->includes(letter->toLowerCase()))))->exists( _x | _x = true )) or (letter->matches("[A-Z ]*") & (shift_indexes)->size() = 0) then ( execute (-1)->display() ; exit(0) ) else skip) ; var upper_letters : Sequence := used_letters->select(letter | letter->matches("[A-Z ]*"))->collect(letter | (letter)) ; var other_hand : int := 0 ; for char : upper_letters do ( var indexes : Sequence := Integer.subrange(1, (keyboard)->size())->collect( _indx | Sequence{_indx-1, (keyboard)->at(_indx)} )->select(_tuple | let row_index : OclAny = _tuple->at(1) in let row : OclAny = _tuple->at(2) in true)->collect(_tuple | let row_index : OclAny = _tuple->at(1) in let row : OclAny = _tuple->at(2) in (Sequence{row_index, l_i})) ; (compound_stmt for (exprlist (expr (atom (name y1))) , (expr (atom (name x1)))) in (testlist (test (logical_test (comparison (expr (atom (name indexes))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name any)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name pow)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name pow)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name y2))) - (expr (atom (name y1))))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))) + (expr (atom (name pow)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x2))) - (expr (atom (name x1))))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ))))))))) , (argument (test (logical_test (comparison (expr (atom (number 0.5)))))))) ))))) <= (comparison (expr (atom (name max_dis))))))) (comp_for for (exprlist (expr (atom (name y2))) , (expr (atom (name x2)))) in (logical_test (comparison (expr (atom (name shift_indexes))))))) ]))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name other_hand)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name word)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name char)))))))) )))))))))))))))) ; execute (other_hand)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r_count,k_in_row,max_dis=map(int,input().split()) keyboard={} for i in range(r_count): row=input() for j,char in enumerate(row): if not keyboard.get(char): keyboard[char]=[] keyboard[char].append((i,j)) query_size=input() word=input() used_letters=set(word) for letter in used_letters : if not keyboard.get(letter.lower())or(letter.isupper()and not keyboard.get('S')): print(-1) exit(0) upper_letters=[letter for letter in used_letters if letter.isupper()] other_hand=0 for char in upper_letters : for location in keyboard[char.lower()]: y1,x1=location if any([pow(pow(abs(y2-y1),2)+pow(abs(x2-x1),2),0.5)<=max_dis for y2,x2 in keyboard['S']]): break else : other_hand+=word.count(char) print(other_hand) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r_count : OclAny := null; var k_in_row : OclAny := null; var max_dis : OclAny := null; Sequence{r_count,k_in_row,max_dis} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var keyboard : OclAny := Set{} ; for i : Integer.subrange(0, r_count-1) do ( var row : String := (OclFile["System.in"]).readLine() ; for _tuple : Integer.subrange(1, (row)->size())->collect( _indx | Sequence{_indx-1, (row)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var char : OclAny := _tuple->at(_indx); if not(keyboard.get(char)) then ( keyboard[char+1] := Sequence{} ) else skip ; (expr (atom (name keyboard)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name char)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) , (test (logical_test (comparison (expr (atom (name j))))))) )))))))) )))))) ; var query_size : String := (OclFile["System.in"]).readLine() ; var word : String := (OclFile["System.in"]).readLine() ; var used_letters : Set := Set{}->union((word)) ; for letter : used_letters do ( if not(keyboard.get(letter->toLowerCase())) or (letter->matches("[A-Z ]*") & not(keyboard.get('S'))) then ( execute (-1)->display() ; exit(0) ) else skip) ; var upper_letters : Sequence := used_letters->select(letter | letter->matches("[A-Z ]*"))->collect(letter | (letter)) ; var other_hand : int := 0 ; for char : upper_letters do ((compound_stmt for (exprlist (expr (atom (name location)))) in (testlist (test (logical_test (comparison (expr (atom (name keyboard)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name char)) (trailer . (name lower) (arguments ( ))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name y1)))))) , (test (logical_test (comparison (expr (atom (name x1))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name location)))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name any)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name pow)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name pow)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name y2))) - (expr (atom (name y1))))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))) + (expr (atom (name pow)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x2))) - (expr (atom (name x1))))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ))))))))) , (argument (test (logical_test (comparison (expr (atom (number 0.5)))))))) ))))) <= (comparison (expr (atom (name max_dis))))))) (comp_for for (exprlist (expr (atom (name y2))) , (expr (atom (name x2)))) in (logical_test (comparison (expr (atom (name keyboard)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'S'))))))) ]))))))) ]))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name other_hand)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name word)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name char)))))))) )))))))))))))))) ; execute (other_hand)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numb=int(input()) print(numb) for i in range(numb): print(1,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var numb : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (numb)->display() ; for i : Integer.subrange(0, numb-1) do ( execute (1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for rt in range(t): n=int(input()) s=input() sum=0 sum1=0 for i in range(n): if i==0 : sum+=2 else : for j in range(i): if s[j]==s[i]: sum1+=1 if sum1==0 : sum+=2 else : sum+=1 sum1=0 print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for rt : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var sum : int := 0 ; var sum1 : int := 0 ; for i : Integer.subrange(0, n-1) do ( if i = 0 then ( sum := sum + 2 ) else ( for j : Integer.subrange(0, i-1) do ( if s[j+1] = s[i+1] then ( sum1 := sum1 + 1 ) else skip) ; if sum1 = 0 then ( sum := sum + 2 ) else ( sum := sum + 1 ) ; sum1 := 0 )) ; execute (sum)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(n) ans=[1]*n print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n)->display() ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, n) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import deque A,B=map(int,input().split()) ask=lambda x,y : print('?',x,y,flush=True) if A<=B : print('Impossible',flush=True) sys.exit() N=A+B candidates=deque(range(N),N) while len(candidates)>2 : x,y=candidates.pop(),candidates.pop() ask(x,y) if input()=='Y' : candidates.appendleft(y) god=candidates[0] result=[] for i in range(N): ask(god,i) result.append(input()=='Y') print('!',''.join(str(int(s))for s in result),flush=True) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ask : Function := lambda x : OclAny, y : OclAny in (('?')->display()) ; if (A->compareTo(B)) <= 0 then ( execute ('Impossible')->display() ; sys.exit() ) else skip ; var N : OclAny := A + B ; var candidates : Sequence := (Integer.subrange(0, N-1), N) ; while (candidates)->size() > 2 do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{candidates->last(),candidates->last()} ; ask(x, y) ; if (OclFile["System.in"]).readLine() = 'Y' then ( candidates := candidates->prepend(y) ) else skip) ; var god : OclAny := candidates->first() ; var result : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( ask(god, i) ; execute (((OclFile["System.in"]).readLine() = 'Y') : result)) ; execute ('!')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) total='1 '*n print(n,total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var total : String := StringLib.nCopies('1 ', n) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==1 : print(f'{1}\n{1}') else : i=2 condicao=False while True : if n % i==0 and int(n/i)in[1,2,3,4,5,6,7,8,9]: r=int(n/i) saida=(str(r)+' ')*i condicao=True if condicao==True : break i+=1 print(i) print(saida.strip()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (StringLib.formattedString('{1} {1}'))->display() ) else ( var i : int := 2 ; var condicao : boolean := false ; while true do ( if n mod i = 0 & (Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{8}->union(Sequence{ 9 })))))))))->includes(("" + ((n / i)))->toInteger()) then ( var r : int := ("" + ((n / i)))->toInteger() ; var saida : double := (("" + ((r))) + ' ') * i ; condicao := true ) else skip ; if condicao = true then ( break ) else skip ; i := i + 1) ; execute (i)->display() ; execute (saida->trim())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) digito=9 encontrou=False while not encontrou and digito>1 : if digitotoInteger() ; var digito : int := 9 ; var encontrou : boolean := false ; while not(encontrou) & digito > 1 do ( if (digito->compareTo(num)) < 0 & num mod digito = 0 then ( encontrou := true ) else ( digito := digito - 1 )) ; var quantidade_digitos : int := num div digito ; var resultado : String := "" ; for i : Integer.subrange(0, quantidade_digitos-1) do ( if i = 0 then ( resultado := resultado + ("" + ((digito))) ) else ( resultado := resultado + " " + ("" + ((digito))) )) ; execute (quantidade_digitos)->display() ; execute (resultado)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def majority(a,p,q,size): start=0 ends=q arr=[None]*p k=0 while(k0): dist_one=0 for i in range(0,p): if(arr[i]>q/2): dist_one=dist_one+1 if(dist_one>p/2): found=1 print("Yes") return start=start-1 ends=ends-1 if(start<0): start=size+start st=start en=ends l=0 while(enunion(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 0 })))))))) ; majority(a, p, q, n); operation majority(a : OclAny, p : OclAny, q : OclAny, size : OclAny) pre: true post: true activity: var start : int := 0 ; var ends : OclAny := q ; var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, p) ; var k : int := 0 ; while ((k->compareTo(p)) < 0) do ( var one : int := 0 ; for j : Integer.subrange(start, ends-1) do ( if (a[j+1] = 1) then ( one := one + 1 ) else skip) ; start := ends ; ends := ends + q ; arr[k+1] := one ; k := k + 1) ; start := 0 ; ends := q ; var found : int := 0 ; while (ends > 0) do ( var dist_one : int := 0 ; for i : Integer.subrange(0, p-1) do ( if ((arr[i+1]->compareTo(q / 2)) > 0) then ( dist_one := dist_one + 1 ) else skip) ; if ((dist_one->compareTo(p / 2)) > 0) then ( found := 1 ; execute ("Yes")->display() ; return ) else skip ; start := start - 1 ; ends := ends - 1 ; if (start < 0) then ( start := size + start ) else skip ; var st : int := start ; var en : OclAny := ends ; var l : int := 0 ; while ((en->compareTo(size)) < 0) do ( if (a[st mod size+1] /= a[en mod size+1]) then ( if (a[st mod size+1] = 1) then ( arr[l+1] := arr[l+1] + 1 ) else ( arr[l+1] := arr[l+1] - 1 ) ) else skip ; l := l + 1 ; st := (st + q) ; en := en + q)) ; if (found = 0) then ( execute ("No")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumProductDifference(a,b,c,d,e): rootSum=(-1*b)/a rootProduct=e/a return abs(rootSum-rootProduct) print(sumProductDifference(8,4,6,4,1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (sumProductDifference(8, 4, 6, 4, 1))->display(); operation sumProductDifference(a : OclAny, b : OclAny, c : OclAny, d : OclAny, e : OclAny) : OclAny pre: true post: true activity: var rootSum : double := (-1 * b) / a ; var rootProduct : double := e / a ; return (rootSum - rootProduct)->abs(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def createHash(hash,maxElement): prev=0 curr=1 hash.add(prev) hash.add(curr) while(curr<=maxElement): temp=curr+prev hash.add(temp) prev=curr curr=temp def fibonacci(arr,n): max_val=max(arr) hash=set() createHash(hash,max_val) minimum=sys.maxsize maximum=-sys.maxsize-1 for i in range(n): if(arr[i]in hash): minimum=min(minimum,arr[i]) maximum=max(maximum,arr[i]) print(minimum,end=",") print(maximum) if __name__=='__main__' : arr=[1,2,3,4,5,6,7] n=len(arr) fibonacci(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 7 })))))) ; n := (arr)->size() ; fibonacci(arr, n) ) else skip; operation createHash(hash : OclAny, maxElement : OclAny) pre: true post: true activity: var prev : int := 0 ; var curr : int := 1 ; execute ((prev) : hash) ; execute ((curr) : hash) ; while ((curr->compareTo(maxElement)) <= 0) do ( var temp : int := curr + prev ; execute ((temp) : hash) ; prev := curr ; curr := temp); operation fibonacci(arr : OclAny, n : OclAny) pre: true post: true activity: var max_val : OclAny := (arr)->max() ; hash := Set{}->union(()) ; createHash(hash, max_val) ; var minimum : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; var maximum : double := -(trailer . (name maxsize)) - 1 ; for i : Integer.subrange(0, n-1) do ( if ((hash)->includes(arr[i+1])) then ( minimum := Set{minimum, arr[i+1]}->min() ; maximum := Set{maximum, arr[i+1]}->max() ) else skip) ; execute (minimum)->display() ; execute (maximum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys A=[] Q=int(sys.stdin.readline().rstrip()) for _ in range(Q): s=sys.stdin.readline().rstrip().split() if s[0]=="0" : A.append(s[1]) elif s[0]=="1" : print(A[int(s[1])]) else : A.pop() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var A : Sequence := Sequence{} ; var Q : int := ("" + ((sys.stdin.readLine().rstrip())))->toInteger() ; for _anon : Integer.subrange(0, Q-1) do ( var s : OclAny := sys.stdin.readLine().rstrip().split() ; if s->first() = "0" then ( execute ((s[1+1]) : A) ) else (if s->first() = "1" then ( execute (A[("" + ((s[1+1])))->toInteger()+1])->display() ) else ( A := A->front() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) commands=[input().split()for i in range(n)] a=[] for command in commands : if len(command)==2 : if command[0]=='0' : a.append(int(command[1])) elif command[0]=='1' : print(int(a[int(command[1])])) else : a.pop(len(a)-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var commands : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (input().split())) ; var a : Sequence := Sequence{} ; for command : commands do ( if (command)->size() = 2 then ( if command->first() = '0' then ( execute ((("" + ((command[1+1])))->toInteger()) : a) ) else (if command->first() = '1' then ( execute (("" + ((a[("" + ((command[1+1])))->toInteger()+1])))->toInteger())->display() ) else skip) ) else ( a := a->excludingAt((a)->size() - 1+1) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lst=[] for i in range(n): lst1=list(map(int,input().split())) lst.append(lst1) vec=[] for i in range(n): if lst[i][0]==0 : vec.append(lst[i][1]) elif lst[i][0]==2 : vec.pop() else : print(vec[lst[i][1]]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var lst1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((lst1) : lst)) ; var vec : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if lst[i+1]->first() = 0 then ( execute ((lst[i+1][1+1]) : vec) ) else (if lst[i+1]->first() = 2 then ( vec := vec->front() ) else ( execute (vec[lst[i+1][1+1]+1])->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input(''))): n=int(input('')) s=list(input('')) l=set(s) c=0 for i in l : if s.count(i)==1 : c+=2 else : c+=2 c+=(s.count(i)-1) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine(''))))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine(''))))->toInteger() ; var s : Sequence := ((OclFile["System.in"]).readLine(''))->characters() ; var l : Set := Set{}->union((s)) ; var c : int := 0 ; for i : l do ( if s->count(i) = 1 then ( c := c + 2 ) else ( c := c + 2 ; c := c + (s->count(i) - 1) )) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools def check(x : int)->bool : s=str(x) prev=ord(s[0]) for c in s[1 :]: if ord(c)!=prev+1 : return False prev=ord(c) return True def main()->None : n=int(input()) v=list(map(int,input().split(' '))) max_=-1 for c in itertools.combinations(sorted(v),2): p=c[0]*c[1] if check(p): max_=max(max_,p) print(max_) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation check(x : int) : boolean pre: true post: true activity: var s : String := ("" + ((x))) ; var prev : int := (s->first())->char2byte() ; for c : s->tail() do ( if (c)->char2byte() /= prev + 1 then ( return false ) else skip ; prev := (c)->char2byte()) ; return true; operation main() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var v : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var max_ : int := -1 ; for c : itertools.combinations(v->sort(), 2) do ( var p : double := c->first() * c[1+1] ; if check(p) then ( max_ := Set{max_, p}->max() ) else skip) ; execute (max_)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class vector : data=[] def pashBack(self,x): self.data.append(x) def randomAccess(self,p): return self.data[p] def popBack(self): deta_index=len(self.data)-1 del self.data[deta_index] q=int(input()) v=vector() for i in range(q): order=input().split() if order[0]=="0" : x=int(order[1]) v.pashBack(x) elif order[0]=="1" : x=int(order[1]) data=v.randomAccess(x) print(data) elif order[0]=="2" : v.popBack() ------------------------------------------------------------ OCL File: --------- class vector { static operation newvector() : vector pre: true post: vector->exists( _x | result = _x ); static attribute data : Sequence := Sequence{}; operation pashBack(x : OclAny) pre: true post: true activity: (expr (atom (name self)) (trailer . (name data)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))); operation randomAccess(p : OclAny) : OclAny pre: true post: true activity: return self.data[p+1]; operation popBack() pre: true post: true activity: var deta_index : double := (self.data)->size() - 1 ; execute (self.data[deta_index+1])->isDeleted(); } class FromPython { operation initialise() pre: true post: true activity: skip ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var v : vector := (vector.newvector()).initialise() ; for i : Integer.subrange(0, q-1) do ( var order : OclAny := input().split() ; if order->first() = "0" then ( x := ("" + ((order[1+1])))->toInteger() ; v.pashBack(x) ) else (if order->first() = "1" then ( x := ("" + ((order[1+1])))->toInteger() ; data := v.randomAccess(x) ; execute (data)->display() ) else (if order->first() = "2" then ( v.popBack() ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) lis=[] lq=[] for i in range(q): lq.append([int(x)for x in input().split(' ')]) for i in lq : order=i[0] if order==0 : lis.append(i[1]) elif order==1 : print(lis[i[1]]) elif order==2 : lis.pop(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lis : Sequence := Sequence{} ; var lq : Sequence := Sequence{} ; for i : Integer.subrange(0, q-1) do ( execute ((input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) : lq)) ; for i : lq do ( var order : OclAny := i->first() ; if order = 0 then ( execute ((i[1+1]) : lis) ) else (if order = 1 then ( execute (lis[i[1+1]+1])->display() ) else (if order = 2 then ( lis := lis->excludingAt(-1+1) ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=[int(i)for i in input().strip().split()] ans=0 s=set() for i in range(n): drink=int(input()) if drink in s : ans+=2 s.remove(drink) else : s.add(drink) n=len(s) print(ans+n//2+n % 2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input()->trim().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : int := 0 ; var s : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( var drink : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (s)->includes(drink) then ( ans := ans + 2 ; execute ((drink) /: s) ) else ( execute ((drink) : s) )) ; var n : int := (s)->size() ; execute (ans + n div 2 + n mod 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,k=map(int,input().split()) cnt=[0]*(k+10) for _ in range(n): cnt[int(input())]+=1 sm=0 for i in cnt : sm+=i//2 print(sm+(n+1)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (k + 10)) ; for _anon : Integer.subrange(0, n-1) do ( cnt[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1] := cnt[("" + (((OclFile["System.in"]).readLine())))->toInteger()+1] + 1) ; var sm : int := 0 ; for i : cnt do ( sm := sm + i div 2) ; execute (sm + (n + 1) div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) cntr={} for i in range(n): inp=input() cntr[inp]=cntr.get(inp,0)+1 rem,pairs=0,0 for k,v in cntr.items(): pairs+=v//2 rem+=v % 2 print(pairs*2+int(rem/2+0.5)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cntr : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( var inp : String := (OclFile["System.in"]).readLine() ; cntr->at(inp) := cntr.get(inp, 0) + 1) ; var rem : OclAny := null; var pairs : OclAny := null; Sequence{rem,pairs} := Sequence{0,0} ; for _tuple : cntr->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); pairs := pairs + v div 2 ; rem := rem + v mod 2) ; execute (pairs * 2 + ("" + ((rem / 2 + 0.5)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,k=list(map(int,input().split())) req_arr=[] for i in range(n): req_arr.append(int(input())) dict={} for i in req_arr : if i not in dict.keys(): dict[i]=1 else : dict[i]+=1 set_arr=[] for i in dict : set_arr.append(math.ceil(dict[i]/2)) if sum(set_arr)<=math.ceil(n/2): print(n) else : diff=sum(set_arr)-math.ceil(n/2) print(n-diff) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var req_arr : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : req_arr)) ; var OclType["Map"] : OclAny := Set{} ; for i : req_arr do ( if ((trailer . (name keys) (arguments ( ))))->excludes(i) then ( (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]) := 1 ) else ( (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]) := (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]) + 1 )) ; var set_arr : Sequence := Sequence{} ; for i : OclType["Map"] do ( execute ((((arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]) / 2)->ceil()) : set_arr)) ; if ((set_arr)->sum()->compareTo((n / 2)->ceil())) <= 0 then ( execute (n)->display() ) else ( var diff : double := (set_arr)->sum() - (n / 2)->ceil() ; execute (n - diff)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) cnt=dict() for i in range(n): tmp=int(input()) try : cnt[tmp]+=1 except KeyError : cnt[tmp]=1 sm,res=0,0 for key in cnt : sm+=cnt[key]% 2 res+=cnt[key]//2*2 res+=(sm+1)//2 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cnt : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( var tmp : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; try ( cnt[tmp+1] := cnt[tmp+1] + 1) (except_clause except (test (logical_test (comparison (expr (atom (name KeyError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cnt)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name tmp)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))))) ; var sm : OclAny := null; var res : OclAny := null; Sequence{sm,res} := Sequence{0,0} ; for key : cnt->keys() do ( sm := sm + cnt[key+1] mod 2 ; res := res + cnt[key+1] div 2 * 2) ; res := res + (sm + 1) div 2 ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(a,b): if a==b : return 1 f=1<<60 r=0 while f : if r==0 and b & f and a & f==0 : r=f elif r>0 and b & f : k=f<<1 break f>>=1 else : k=1 a &=r-1 if k>a : return(r<<1)-a return 2*(r-a)+k a=int(input()) b=int(input()) print(solve(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; b := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (solve(a, b))->display(); operation solve(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a = b then ( return 1 ) else skip ; var f : int := 1 * (2->pow(60)) ; var r : int := 0 ; (compound_stmt while (test (logical_test (comparison (expr (atom (name f)))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (logical_test (comparison (comparison (expr (atom (name r)))) == (comparison (expr (atom (number (integer 0))))))) and (logical_test (comparison (expr (expr (atom (name b))) & (expr (atom (name f))))))) and (logical_test (comparison (comparison (expr (expr (atom (name a))) & (expr (atom (name f))))) == (comparison (expr (atom (number (integer 0))))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name r)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name f))))))))))))) (elif_clause elif (test (logical_test (logical_test (comparison (comparison (expr (atom (name r)))) > (comparison (expr (atom (number (integer 0))))))) and (logical_test (comparison (expr (expr (atom (name b))) & (expr (atom (name f)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name k)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name f))) << (expr (atom (number (integer 1)))))))))))))) (stmt (simple_stmt (small_stmt break))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name f)))))))) (assign_part >>= (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name k)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))))) ; a := a & r - 1 ; if (k->compareTo(a)) > 0 then ( return (r * (2->pow(1))) - a ) else skip ; return 2 * (r - a) + k; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline readlines=sys.stdin.readlines from functools import lru_cache A=int(readline()) B=int(readline()) @ lru_cache(None) def can_make(A,B): if A==B : return False if B % 2==0 : return can_make((A+1)//2,B//2) return True @ lru_cache(None) def F(A,B): if A==B : return 1 ev=F((A+1)//2,B//2) if A % 2==0 : A+=1 if B % 2==1 : od=F(A//2,B//2) else : od=F(A//2,B//2) if not can_make(A//2,B//2): od-=1 return ev+od answer=F(A,B) print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var readlines : OclAny := (OclFile["System.in"]).readlines ; skip ; var A : int := ("" + ((readline())))->toInteger() ; var B : int := ("" + ((readline())))->toInteger() ; (compound_stmt (decorator @ (dotted_name (name lru_cache)) ( (arglist (argument (test (logical_test (comparison (expr (atom None))))))) )) (funcdef def (name can_make) ( (typedargslist (def_parameters (def_parameter (named_parameter (name A))) , (def_parameter (named_parameter (name B))))) ) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name A)))) == (comparison (expr (atom (name B))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name False))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name B))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name can_make)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name A))) + (expr (atom (number (integer 1))))))))) ))) // (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name B))) // (expr (atom (number (integer 2)))))))))) )))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name True))))))))))))) ; (compound_stmt (decorator @ (dotted_name (name lru_cache)) ( (arglist (argument (test (logical_test (comparison (expr (atom None))))))) )) (funcdef def (name F) ( (typedargslist (def_parameters (def_parameter (named_parameter (name A))) , (def_parameter (named_parameter (name B))))) ) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name A)))) == (comparison (expr (atom (name B))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ev)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name F)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name A))) + (expr (atom (number (integer 1))))))))) ))) // (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name B))) // (expr (atom (number (integer 2)))))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name A))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name A)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name B))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name od)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name F)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name A))) // (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name B))) // (expr (atom (number (integer 2)))))))))) )))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name od)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name F)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name A))) // (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name B))) // (expr (atom (number (integer 2)))))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test not (logical_test (comparison (expr (atom (name can_make)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name A))) // (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name B))) // (expr (atom (number (integer 2)))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name od)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (expr (atom (name ev))) + (expr (atom (name od)))))))))))))) ; var answer : OclAny := F(A, B) ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=int(input()),int(input()) if a==b : print(1) else : r=60 while(a &(1<=0 and(b &(1<(1<<(k+1)): ans-=a-(1<<(k+1)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),("" + (((OclFile["System.in"]).readLine())))->toInteger()} ; if a = b then ( execute (1)->display() ) else ( var r : int := 60 ; while (MathLib.bitwiseAnd(a, (1 * (2->pow(r))))) = (MathLib.bitwiseAnd(b, (1 * (2->pow(r))))) do ( r := r - 1) ; var t : int := (1 * (2->pow((r + 1)))) ; a := a & t - 1 ; b := b & t - 1 ; var k : double := r - 1 ; while k >= 0 & (MathLib.bitwiseAnd(b, (1 * (2->pow(k))))) = 0 do ( k := k - 1) ; var ans : double := t - a ; if (a->compareTo((1 * (2->pow((k + 1)))))) > 0 then ( ans := ans - a - (1 * (2->pow((k + 1)))) ) else skip ; execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import sys (a,b)=tuple(map(int,input().split(''))) if a<=b : print("Impossible") sys.exit() n=a+b def ask(i,j): print("? ",i,j) ans=input() if ans=='Y' : return True elif ans=='N' : return False path=[] nlen=b+1 for i in range(n): if len(path)==0 : path.append(i) if len(path)>=nlen : break else : if ask(path[-1],i): path.append(i) if len(path)>=nlen : break else : path.pop() nlen-=1 o1=path[-1] result='' for i in range(n): if i!=o1 : if ask(o1,i): result+='1' else : result+='0' else : result+='1' print('!',result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var Sequence{a, b} : Sequence := ((input().split(''))->collect( _x | (OclType["int"])->apply(_x) )) ; if (a->compareTo(b)) <= 0 then ( execute ("Impossible")->display() ; sys.exit() ) else skip ; var n : OclAny := a + b ; skip ; var path : Sequence := Sequence{} ; var nlen : OclAny := b + 1 ; for i : Integer.subrange(0, n-1) do ( if (path)->size() = 0 then ( execute ((i) : path) ; if ((path)->size()->compareTo(nlen)) >= 0 then ( break ) else skip ) else ( if ask(path->last(), i) then ( execute ((i) : path) ; if ((path)->size()->compareTo(nlen)) >= 0 then ( break ) else skip ) else ( path := path->front() ; nlen := nlen - 1 ) )) ; var o1 : OclAny := path->last() ; var result : String := '' ; for i : Integer.subrange(0, n-1) do ( if i /= o1 then ( if ask(o1, i) then ( result := result + '1' ) else ( result := result + '0' ) ) else ( result := result + '1' )) ; execute ('!')->display(); operation ask(i : OclAny, j : OclAny) : OclAny pre: true post: true activity: execute ("? ")->display() ; var ans : String := (OclFile["System.in"]).readLine() ; if ans = 'Y' then ( return true ) else (if ans = 'N' then ( return false ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) s=list(input()) kind=set(s) first_solved=len(kind) next_solved=len(s)-first_solved print(first_solved*2+next_solved) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var kind : Set := Set{}->union((s)) ; var first_solved : int := (kind)->size() ; var next_solved : double := (s)->size() - first_solved ; execute (first_solved * 2 + next_solved)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) if a==b : print(1) exit() abin=bin(a)[2 :] bbin=bin(b)[2 :] la=len(abin) lb=len(bbin) if la==lb : while abin[0]==bbin[0]: abin=abin[1 :] bbin=bbin[1 :] while len(abin)>1 and abin[0]=="0" : abin=abin[1 :] cbin=bbin[1 :] while cbin and cbin[0]=="0" : cbin=cbin[1 :] c=2**(len(cbin))-1 a=int(abin,2) b=int(bbin,2) lb=len(bbin) lbnd=2**(lb-1)+c hbnd=2**(lb-1)+a if lbnd>=hbnd : print(2**lb-a) else : print(2**(lb-1)-a+lbnd-a+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if a = b then ( execute (1)->display() ; exit() ) else skip ; var abin : OclAny := bin(a).subrange(2+1) ; var bbin : OclAny := bin(b).subrange(2+1) ; var la : int := (abin)->size() ; var lb : int := (bbin)->size() ; if la = lb then ( while abin->first() = bbin->first() do ( abin := abin->tail() ; bbin := bbin->tail()) ; while (abin)->size() > 1 & abin->first() = "0" do ( abin := abin->tail()) ) else skip ; var cbin : OclAny := bbin->tail() ; while cbin & cbin->first() = "0" do ( cbin := cbin->tail()) ; var c : double := (2)->pow(((cbin)->size())) - 1 ; a := ("" + ((abin, 2)))->toInteger() ; b := ("" + ((bbin, 2)))->toInteger() ; lb := (bbin)->size() ; var lbnd : double := (2)->pow((lb - 1)) + c ; var hbnd : double := (2)->pow((lb - 1)) + a ; if (lbnd->compareTo(hbnd)) >= 0 then ( execute ((2)->pow(lb) - a)->display() ) else ( execute ((2)->pow((lb - 1)) - a + lbnd - a + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- res=0 A=int(input()) B=int(input()) def pow2_floor_log2(x): res=1 while res*2<=x : res*=2 return res if A==B : res+=1 while AC : B_=C+pow2_floor_log2(B-C)*2-1 else : B_=C if C+A<=B_ : res+=C break else : res+=(C-A)+(B_-C+1) break else : A-=C B-=C print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var res : int := 0 ; var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; if A = B then ( res := res + 1 ) else skip ; while (A->compareTo(B)) < 0 do ( var C : OclAny := pow2_floor_log2(B) ; if (A->compareTo(C)) < 0 then ( res := res + C - A ; if (B->compareTo(C)) > 0 then ( var B_ : double := C + pow2_floor_log2(B - C) * 2 - 1 ) else ( B_ := C ) ; if (C + A->compareTo(B_)) <= 0 then ( res := res + C ; break ) else ( res := res + (C - A) + (B_ - C + 1) ; break ) ) else ( A := A - C ; B := B - C )) ; execute (res)->display(); operation pow2_floor_log2(x : OclAny) : OclAny pre: true post: true activity: res := 1 ; while (res * 2->compareTo(x)) <= 0 do ( res := res * 2) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumDigitSquare(n): sq=0 ; while(n!=0): digit=n % 10 sq+=digit*digit n=n//10 return sq ; def isHappy(n): s=set() s.add(n) while(True): if(n==1): return True ; n=sumDigitSquare(n) if n in s : return False s.add(n) return false ; n=4 if(isHappy(n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 4 ; if (isHappy(n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation sumDigitSquare(n : OclAny) pre: true post: true activity: var sq : int := 0; ; while (n /= 0) do ( var digit : int := n mod 10 ; sq := sq + digit * digit ; n := n div 10) ; return sq;; operation isHappy(n : OclAny) : OclAny pre: true post: true activity: var s : Set := Set{}->union(()) ; execute ((n) : s) ; while (true) do ( if (n = 1) then ( return true; ) else skip ; n := sumDigitSquare(n) ; if (s)->includes(n) then ( return false ) else skip ; execute ((n) : s)) ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) nums=list(map(int,input().split())) nums.sort() half=(n+1)//2 if sum(nums[: half])toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nums : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; nums := nums->sort() ; var half : int := (n + 1) div 2 ; if ((nums.subrange(1,half))->sum()->compareTo((nums(subscript : (test (logical_test (comparison (expr - (expr (atom (name half))))))) (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->sum())) < 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution : def paintJob(self,n,arr): arr.sort() red,blue=arr[-1],arr[0]+arr[1] l,r=2,n-2 while r>n//2 : if red>blue : print("Yes") return red+=arr[r] blue+=arr[l] l+=1 r-=1 if red>blue : print("Yes") else : print("No") j=Solution() rep=int(input()) for _ in range(rep): n=int(input()) arr=list(map(int,input().split())) j.paintJob(n,arr) ------------------------------------------------------------ OCL File: --------- class Solution { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation paintJob(n : OclAny,arr : OclAny) pre: true post: true activity: arr := arr->sort() ; var red : OclAny := null; var blue : OclAny := null; Sequence{red,blue} := Sequence{arr->last(),arr->first() + arr[1+1]} ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{2,n - 2} ; while (r->compareTo(n div 2)) > 0 do ( if (red->compareTo(blue)) > 0 then ( execute ("Yes")->display() ; return ) else skip ; red := red + arr[r+1] ; blue := blue + arr[l+1] ; l := l + 1 ; r := r - 1) ; if (red->compareTo(blue)) > 0 then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } class FromPython { operation initialise() pre: true post: true activity: skip ; var j : Solution := (Solution.newSolution()).initialise() ; var rep : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, rep-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; arr := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; j.paintJob(n, arr)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,a): a.sort() i=1 j=n-1 firstSum=a[0] secondSum=0 while itoInteger()-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (solve(n, a))->display()); operation solve(n : OclAny, a : OclAny) : OclAny pre: true post: true activity: a := a->sort() ; var i : int := 1 ; var j : double := n - 1 ; var firstSum : OclAny := a->first() ; var secondSum : int := 0 ; while (i->compareTo(j)) < 0 do ( firstSum := firstSum + a[i+1] ; secondSum := secondSum + a[j+1] ; i := i + 1 ; j := j - 1 ; if (firstSum->compareTo(secondSum)) < 0 then ( return 'YES' ) else skip) ; return 'NO'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) k=[int(x)for x in input().split()] k.sort() sum_blue=0 sum_red=0 count_red=0 count_blue=0 blue=0 red=len(k)-1 while True : sum_red+=k[red] red-=1 count_red+=1 while count_red>=count_blue : sum_blue+=k[blue] blue+=1 count_blue+=1 if sum_red>sum_blue and count_blue>count_red : print("YES") break elif redtoInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; k := k->sort() ; var sum_blue : int := 0 ; var sum_red : int := 0 ; var count_red : int := 0 ; var count_blue : int := 0 ; var blue : int := 0 ; var red : double := (k)->size() - 1 ; while true do ( sum_red := sum_red + k[red+1] ; red := red - 1 ; count_red := count_red + 1 ; while (count_red->compareTo(count_blue)) >= 0 do ( sum_blue := sum_blue + k[blue+1] ; blue := blue + 1 ; count_blue := count_blue + 1) ; if (sum_red->compareTo(sum_blue)) > 0 & (count_blue->compareTo(count_red)) > 0 then ( execute ("YES")->display() ; break ) else (if (red->compareTo(blue)) < 0 then ( execute ("NO")->display() ; break ) else skip))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for j in range(n): s=int(input()) a=list(map(int,input().split())) a.sort() pref=[a[0]] for i in range(1,len(a)): pref.append(pref[-1]+a[i]) suff=[a[-1]] for i in range(len(a)-2,-1,-1): suff.append(suff[-1]+a[i]) ans=False for j in range(s-1): if pref[j+1]toInteger() ; for j : Integer.subrange(0, n-1) do ( var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var pref : Sequence := Sequence{ a->first() } ; for i : Integer.subrange(1, (a)->size()-1) do ( execute ((pref->last() + a[i+1]) : pref)) ; var suff : Sequence := Sequence{ a->last() } ; for i : Integer.subrange(-1 + 1, (a)->size() - 2)->reverse() do ( execute ((suff->last() + a[i+1]) : suff)) ; var ans : boolean := false ; for j : Integer.subrange(0, s - 1-1) do ( if (pref[j + 1+1]->compareTo(suff[j+1])) < 0 then ( ans := true ) else skip) ; if ans then ( execute ("Yes")->display() ) else ( execute ("No")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isInGivenBase(Str,base): if(base>16): return False elif(base<=10): for i in range(len(Str)): if(Str[i].isnumeric()and(ord(Str[i])>=ord('0')and ord(Str[i])<(ord('0')+base))==False): return False else : for i in range(len(Str)): if(Str[i].isnumeric()and((ord(Str[i])>=ord('0')and ord(Str[i])<(ord('0')+base))or(ord(Str[i])>=ord('A')and ord(Str[i])<(ord('A')+base-10)))==False): return False return True Str="AF87" if(isInGivenBase(Str,16)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Str := "AF87" ; if (isInGivenBase(Str, 16)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isInGivenBase(Str : OclAny, base : OclAny) : OclAny pre: true post: true activity: if (base > 16) then ( return false ) else (if (base <= 10) then ( for i : Integer.subrange(0, (Str)->size()-1) do ( if (Str[i+1]->matches("[0-9]*") & (((Str[i+1])->char2byte()->compareTo(('0')->char2byte())) >= 0 & ((Str[i+1])->char2byte()->compareTo((('0')->char2byte() + base))) < 0) = false) then ( return false ) else skip) ) else ( for i : Integer.subrange(0, (Str)->size()-1) do ( if (Str[i+1]->matches("[0-9]*") & ((((Str[i+1])->char2byte()->compareTo(('0')->char2byte())) >= 0 & ((Str[i+1])->char2byte()->compareTo((('0')->char2byte() + base))) < 0) or (((Str[i+1])->char2byte()->compareTo(('A')->char2byte())) >= 0 & ((Str[i+1])->char2byte()->compareTo((('A')->char2byte() + base - 10))) < 0)) = false) then ( return false ) else skip) ) ) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y,a,b=[int(i)for i in input().split()] c=[[i,j]for i in range(a,x+1)for j in range(b,y+1)if i>j] print(len(c));[print(*i)for i in c] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{x,y,a,b} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var c : Sequence := Integer.subrange(a, x + 1-1)->select(i; j : Integer.subrange(b, y + 1-1) | true)->collect(i; j : Integer.subrange(b, y + 1-1) | (Sequence{i}->union(Sequence{ j }))) ; execute ((c)->size())->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- my=[0,1,1,1,2] mx=[0,0,-1,1,0] n=int(input()) board=[] for i in range(n): board.append(list(input())) flag=True for i in range(n): for j in range(n): if board[i][j]=='#' : for(dy,dx)in zip(my,mx): y=i+dy x=j+dx if y<0 or y>=n or x<0 or x>=n : flag=False break if board[y][x]=='.' : flag=False board[y][x]='.' if flag==False : break print('YES' if flag else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var my : Sequence := Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 2 })))) ; var mx : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{1}->union(Sequence{ 0 })))) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var board : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((((OclFile["System.in"]).readLine())->characters()) : board)) ; var flag : boolean := true ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if board[i+1][j+1] = '#' then ( for Sequence{dy, dx} : Integer.subrange(1, my->size())->collect( _indx | Sequence{my->at(_indx), mx->at(_indx)} ) do ( var y : OclAny := i + dy ; var x : OclAny := j + dx ; if y < 0 or (y->compareTo(n)) >= 0 or x < 0 or (x->compareTo(n)) >= 0 then ( flag := false ; break ) else skip ; if board[y+1][x+1] = '.' then ( flag := false ) else skip ; board[y+1][x+1] := '.') ) else skip) ; if flag = false then ( break ) else skip) ; execute (if flag then 'YES' else 'NO' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) while(n): tam=int(input()) str1=input() arr=[] cont=0 for letra in str1 : if letra in arr : cont=cont+1 else : arr.append(letra) cont=cont+2 print(cont) n=n-1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (n) do ( var tam : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var str1 : String := (OclFile["System.in"]).readLine() ; var arr : Sequence := Sequence{} ; var cont : int := 0 ; for letra : str1->characters() do ( if (arr)->includes(letra) then ( cont := cont + 1 ) else ( execute ((letra) : arr) ; cont := cont + 2 )) ; execute (cont)->display() ; n := n - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def produs_cifre(numar): produs=1 for i in numar : produs=produs*int(i) return(produs) n=int(input()) matrix=[] a=[] for i in range(0,n): stringul=input() a=[] for l in stringul : a.append(l) matrix.append(a) adev=1 if n<3 : adev=0 for i in range(0,n): for j in range(0,n): if matrix[i][j]=='#' and(j==0 or j==n-1 or i>n-2): i=n+1 j=n+1 adev=0 break elif adev==1 and matrix[i][j]=='#' : if matrix[i+1][j]!="#" or matrix[i+2][j]!="#" or matrix[i+1][j-1]!="#" or matrix[i+1][j+1]!="#" : adev=0 break else : matrix[i][j]='>' matrix[i+1][j]='>' matrix[i+2][j]='>' matrix[i+1][j-1]='>' matrix[i+1][j+1]='>' if adev==0 : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var matrix : Sequence := Sequence{} ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var stringul : String := (OclFile["System.in"]).readLine() ; a := Sequence{} ; for l : stringul->characters() do ( execute ((l) : a)) ; execute ((a) : matrix)) ; var adev : int := 1 ; if n < 3 then ( adev := 0 ) else skip ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if matrix[i+1][j+1] = '#' & (j = 0 or j = n - 1 or (i->compareTo(n - 2)) > 0) then ( var i : int := n + 1 ; var j : int := n + 1 ; adev := 0 ; break ) else (if adev = 1 & matrix[i+1][j+1] = '#' then ( if matrix[i + 1+1][j+1] /= "#" or matrix[i + 2+1][j+1] /= "#" or matrix[i + 1+1][j - 1+1] /= "#" or matrix[i + 1+1][j + 1+1] /= "#" then ( adev := 0 ; break ) else ( matrix[i+1][j+1] := '>' ; matrix[i + 1+1][j+1] := '>' ; matrix[i + 2+1][j+1] := '>' ; matrix[i + 1+1][j - 1+1] := '>' ; matrix[i + 1+1][j + 1+1] := '>' ) ) else skip))) ; if adev = 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); operation produs_cifre(numar : OclAny) : OclAny pre: true post: true activity: var produs : int := 1 ; for i : numar do ( produs := produs * ("" + ((i)))->toInteger()) ; return (produs); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[[x for x in input()]for x in range(n)] for i in range(n): for j in range(n): if(i>0 and i+10 and j+1toInteger() ; var a : Sequence := Integer.subrange(0, n-1)->select(x | true)->collect(x | ((OclFile["System.in"]).readLine()->select(x | true)->collect(x | (x)))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if (i > 0 & (i + 1->compareTo(n)) < 0 & j > 0 & (j + 1->compareTo(n)) < 0 & a[i - 1+1][j+1] = '#' & a[i+1][j+1] = '#' & a[i + 1+1][j+1] = '#' & a[i+1][j - 1+1] = '#' & a[i+1][j + 1+1] = '#') then ( a[i - 1+1][j+1] := a[i - 1+1][j+1](assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom '.')))))))) ; a[i+1][j - 1+1] := '.'; var a[i+1][j + 1+1] : String := '.' ) else skip)) ; var key : boolean := true ; for i : a do ( if (i)->includes('#') then ( key := false ) else skip) ; execute (if key then 'YES' else 'NO' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) g=['.'*(n+2)]+['.'+input()[:-1]+'.' for _ in range(n)]+['.'*(n+2)] d=[(1,0),(1,-1),(1,1),(2,0)] ans='YES' s=[] for i in range(1,n+1): for j in range(1,n+1): if(i,j)not in s and g[i][j]=='#' : for a,b in d : if g[i+a][j+b]!='#' or(i+a,j+b)in s : ans='NO' break else : for a,b in d : s.append((i+a,j+b)) s.append((i,j)) if ans=='NO' : break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var g : Sequence := Sequence{ StringLib.nCopies('.', (n + 2)) }->union(Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ('.' + input()->front() + '.')))->union(Sequence{ StringLib.nCopies('.', (n + 2)) }) ; var d : Sequence := Sequence{Sequence{1, 0}}->union(Sequence{Sequence{1, -1}}->union(Sequence{Sequence{1, 1}}->union(Sequence{ Sequence{2, 0} }))) ; var ans : String := 'YES' ; var s : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, n + 1-1) do ( if (s)->excludes(Sequence{i, j}) & g[i+1][j+1] = '#' then ( (compound_stmt for (exprlist (expr (atom (name a))) , (expr (atom (name b)))) in (testlist (test (logical_test (comparison (expr (atom (name d))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name a))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (name b))))))))) ])))) != (comparison (expr (atom '#'))))) or (logical_test (comparison (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name a))))))) , (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (name b)))))))) )))) in (comparison (expr (atom (name s)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom 'NO'))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt for (exprlist (expr (atom (name a))) , (expr (atom (name b)))) in (testlist (test (logical_test (comparison (expr (atom (name d))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name a))))))) , (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (name b)))))))) )))))))) ))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) , (test (logical_test (comparison (expr (atom (name j))))))) )))))))) ))))))))))))))) ) else skip) ; if ans = 'NO' then ( break ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(n): for i in range(n): for j in range(n): if list[i][j]=="#" : list[i][j]='.' try : if list[i+1][j]!='.' and list[i+2][j]!='.' and list[i+1][j+1]!='.' and list[i+1][j-1]!='.' : list[i+1][j]='.' list[i+2][j]='.' list[i+1][j+1]='.' list[i+1][j-1]='.' else : return "NO" except : return "NO" return "YES" n=int(input()) list=[] for i in range(n): list.append([i for i in input()]) print(main(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var OclType["Sequence"] : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()->select(i | true)->collect(i | (i))) : OclType["Sequence"])) ; execute (main(n))->display(); operation main(n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if OclType["Sequence"][i+1][j+1] = "#" then ( OclType["Sequence"][i+1][j+1] := '.' ; try ( if OclType["Sequence"][i + 1+1][j+1] /= '.' & OclType["Sequence"][i + 2+1][j+1] /= '.' & OclType["Sequence"][i + 1+1][j + 1+1] /= '.' & OclType["Sequence"][i + 1+1][j - 1+1] /= '.' then ( OclType["Sequence"][i + 1+1][j+1] := '.' ; OclType["Sequence"][i + 2+1][j+1] := '.' ; OclType["Sequence"][i + 1+1][j + 1+1] := '.' ; OclType["Sequence"][i + 1+1][j - 1+1] := '.' ) else ( return "NO" )) catch (_e : OclException) do ( return "NO") ) else skip)) ; return "YES"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def computePrime(N): Prime=[True]*(N+1) Prime[0]=False Prime[1]=False i=2 while i*i<=N : if(Prime[i]): for j in range(i*i,N,i): Prime[j]=False i+=1 return Prime def countTwinPairs(arr,n): maxE=max(arr) Prime=computePrime(maxE) count=0 freq=[0]*(maxE+2) for i in range(n): freq[arr[i]]+=1 arr.sort() for i in range(n): if(Prime[arr[i]]): if((arr[i]+2)<=(maxE)and freq[arr[i]+2]>0 and Prime[arr[i]+2]): count+=1 return count if __name__=="__main__" : arr=[2,4,3,5,7] n=len(arr) print(countTwinPairs(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{2}->union(Sequence{4}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 7 })))) ; n := (arr)->size() ; execute (countTwinPairs(arr, n))->display() ) else skip; operation computePrime(N : OclAny) : OclAny pre: true post: true activity: var Prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (N + 1)) ; Prime->first() := false ; Prime[1+1] := false ; var i : int := 2 ; while (i * i->compareTo(N)) <= 0 do ( if (Prime[i+1]) then ( for j : Integer.subrange(i * i, N-1)->select( $x | ($x - i * i) mod i = 0 ) do ( Prime[j+1] := false) ) else skip ; i := i + 1) ; return Prime; operation countTwinPairs(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var maxE : OclAny := (arr)->max() ; Prime := computePrime(maxE) ; var count : int := 0 ; var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (maxE + 2)) ; for i : Integer.subrange(0, n-1) do ( freq[arr[i+1]+1] := freq[arr[i+1]+1] + 1) ; arr := arr->sort() ; for i : Integer.subrange(0, n-1) do ( if (Prime[arr[i+1]+1]) then ( if (((arr[i+1] + 2)->compareTo((maxE))) <= 0 & freq[arr[i+1] + 2+1] > 0 & Prime[arr[i+1] + 2+1]) then ( count := count + 1 ) else skip ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSol(coeff,n,rhs): dp=[0 for i in range(rhs+1)] dp[0]=1 for i in range(n): for j in range(coeff[i],rhs+1): dp[j]+=dp[j-coeff[i]] return dp[rhs] coeff=[2,2,5] rhs=4 n=len(coeff) print(countSol(coeff,n,rhs)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; coeff := Sequence{2}->union(Sequence{2}->union(Sequence{ 5 })) ; rhs := 4 ; n := (coeff)->size() ; execute (countSol(coeff, n, rhs))->display(); operation countSol(coeff : OclAny, n : OclAny, rhs : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, rhs + 1-1)->select(i | true)->collect(i | (0)) ; dp->first() := 1 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(coeff[i+1], rhs + 1-1) do ( dp[j+1] := dp[j+1] + dp[j - coeff[i+1]+1])) ; return dp[rhs+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break lst=[sum(map(int,input().split()))for _ in range(n)] print(max(lst),min(lst)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var lst : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum())) ; execute ((lst)->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n,a,b=int(input()),0,500 if n==0 : break for _ in range(n): s=sum(map(int,input().split())) a=max(a,s) b=min(b,s) print(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),0,500} ; if n = 0 then ( break ) else skip ; for _anon : Integer.subrange(0, n-1) do ( var s : OclAny := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum() ; var a : OclAny := Set{a, s}->max() ; var b : OclAny := Set{b, s}->min()) ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict import sys sys.setrecursionlimit(10**9) input=sys.stdin.readline def main(): rr=[] while True : r,n=map(int,input().split()) if r==0 and n==0 : break a=[list(map(int,input().split()))for _ in range(n)] d=defaultdict(int) for xl,xr,h in a : for x in range(xl,xr): if d[x]xr : tr=xr rr.append('{:0.9f}'.format(tr)) return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; execute (main())->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var r : OclAny := null; var n : OclAny := null; Sequence{r,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if r = 0 & n = 0 then ( break ) else skip ; var a : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var d : OclAny := defaultdict(OclType["int"]) ; for _tuple : a do (var _indx : int := 1; var xl : OclAny := _tuple->at(_indx); _indx := _indx + 1; var xr : OclAny := _tuple->at(_indx); _indx := _indx + 1; var h : OclAny := _tuple->at(_indx); for x : Integer.subrange(xl, xr-1) do ( if (d[x+1]->compareTo(h)) < 0 then ( d[x+1] := h ) else skip)) ; var tr : double := ("" + (('inf')))->toReal() ; var r2 : double := (r)->pow(2) ; for x : Integer.subrange(-r, r-1) do ( var h : OclAny := d[x+1] ; var k : OclAny := Set{(x)->abs(), (x + 1)->abs()}->min() ; var t : double := ((r2 - (k)->pow(2)))->pow(0.5) ; var xr : double := r - t + h ; if (tr->compareTo(xr)) > 0 then ( tr := xr ) else skip) ; execute ((StringLib.interpolateStrings('{:0.9f}', Sequence{tr})) : rr)) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y,a,b=map(int,input().split()) ans=[] for i in range(a,x+1): for j in range(b,y+1): if i>j : ans.append((i,j)) print(len(ans)) ans.sort() for z in ans : print(z[0],z[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{x,y,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(a, x + 1-1) do ( for j : Integer.subrange(b, y + 1-1) do ( if (i->compareTo(j)) > 0 then ( execute ((Sequence{i, j}) : ans) ) else skip)) ; execute ((ans)->size())->display() ; ans := ans->sort() ; for z : ans do ( execute (z->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break max_sum=0 min_sum=500 for i in range(n): m_sum=0 m=list(map(int,input().split())) for j in range(5): m_sum+=m[j] if max_summ_sum : min_sum=m_sum print(max_sum,min_sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var max_sum : int := 0 ; var min_sum : int := 500 ; for i : Integer.subrange(0, n-1) do ( var m_sum : int := 0 ; var m : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for j : Integer.subrange(0, 5-1) do ( m_sum := m_sum + m[j+1]) ; if (max_sum->compareTo(m_sum)) < 0 then ( max_sum := m_sum ) else skip ; if (min_sum->compareTo(m_sum)) > 0 then ( min_sum := m_sum ) else skip) ; execute (max_sum)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : j=int(input()) if j==0 : break else : num_list=[] for _ in range(j): line=list(map(int,input().split())) num_list.append(sum(line)) print(str(max(num_list))+" "+str(min(num_list))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var j : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if j = 0 then ( break ) else ( var num_list : Sequence := Sequence{} ; for _anon : Integer.subrange(0, j-1) do ( var line : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (((line)->sum()) : num_list)) ; execute (("" + (((num_list)->max()))) + " " + ("" + (((num_list)->min()))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) s=input() ans="" c=0 for i in range(n): if(s[i]not in ans): ans+=s[i] c+=2 else : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var ans : String := "" ; var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ((ans)->characters()->excludes(s[i+1])) then ( ans := ans + s[i+1] ; c := c + 2 ) else ( c := c + 1 )) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break [print("{}{}".format(max(x),min(x)))for x in[[sum(map(int,input().split()))for i in range(n)]]] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip) ; ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,n=map(int,input().split()) print(max([sum(map(int,input().split()))for _ in range(m)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum())))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) max=0 count=0 for i in range(a): nums=input() for num in nums.split(): j=int(num) if j==1 : count+=1 if maxcollect( _x | (OclType["int"])->apply(_x) ) ; var max : int := 0 ; var count : int := 0 ; for i : Integer.subrange(0, a-1) do ( var nums : String := (OclFile["System.in"]).readLine() ; for num : nums.split() do ( var j : int := ("" + ((num)))->toInteger() ; if j = 1 then ( count := count + 1 ) else skip) ; if (max->compareTo(count)) < 0 then ( max := count ) else skip ; count := 0) ; execute (max)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=input().split(" ") line=[] num_list=[] for num in range(int(a)): iline=input().split(" ") ilist=[int(c)for c in iline] kei=0 for num1 in range(0,int(b)): kei+=ilist[num1] num_list.append(kei) num_list.sort() print(num_list[int(a)-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split(" ") ; var line : Sequence := Sequence{} ; var num_list : Sequence := Sequence{} ; for num : Integer.subrange(0, ("" + ((a)))->toInteger()-1) do ( var iline : OclAny := input().split(" ") ; var ilist : Sequence := iline->select(c | true)->collect(c | (("" + ((c)))->toInteger())) ; var kei : int := 0 ; for num1 : Integer.subrange(0, ("" + ((b)))->toInteger()-1) do ( kei := kei + ilist[num1+1]) ; execute ((kei) : num_list)) ; num_list := num_list->sort() ; execute (num_list[("" + ((a)))->toInteger() - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(x)for x in input().split()] m=0 for _ in range(n): l=[int(x)for x in input().split()] m=max(m,sum(l)) print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var m : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var l : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; m := Set{m, (l)->sum()}->max()) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(max([sum(map(int,input().split()))for _ in range(int(input().split()[0]))])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((Integer.subrange(0, ("" + ((input().split()->first())))->toInteger()-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum())))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkArray(arr,n): return((arr[0]% 2)and(arr[n-1]% 2)and(n % 2)) arr=[1,2,3,4,5] n=len(arr); if checkArray(arr,n): print(1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ; n := (arr)->size(); ; if checkArray(arr, n) then ( execute (1)->display() ) else ( execute (0)->display() ); operation checkArray(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: return ((arr->first() mod 2) & (arr[n - 1+1] mod 2) & (n mod 2)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter import math hpop=heappop hpush=heappush def solution(): x,y,a,b=map(int,input().split()) ans=[] for i in range(x+1): for j in range(y+1): if i>=a and j>=b and jpow(30))) ; threading.stack_size(1 * (2->pow(27))) ; var thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ; thread.start(); thread.join(); operation solution() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{x,y,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, x + 1-1) do ( for j : Integer.subrange(0, y + 1-1) do ( if (i->compareTo(a)) >= 0 & (j->compareTo(b)) >= 0 & (j->compareTo(i)) < 0 then ( execute ((Sequence{i, j}) : ans) ) else skip)) ; ans := ans->sort() ; execute ((ans)->size())->display() ; for _tuple : ans do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); execute (a)->display()); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* def find_angle(x,y,z): volume=x*x*y ; ans=0 ; if(zdisplay(); ) else skip; operation find_angle(x : OclAny, y : OclAny, z : OclAny) pre: true post: true activity: var volume : double := x * x * y; ; var ans : int := 0; ; if ((z->compareTo(volume div 2)) < 0) then ( var d : double := (x * y * y) / (2.0 * z); ; ans := atan(d); ) else ( z := volume - z; ; d := (2 * z) / (OclType["double"])(x * x * x); ; ans := atan(d); ) ; ans := (ans * 180) / 3.14159265; ; return MathLib.roundN(ans, 4);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n, m = map(int, input().split()) if m & 1: if n & 1: left1 = 1 right1 = n // 2 for _ in range(m // 2): print(left1, right1) left1 += 1 right1 -= 1 left2 = (n // 2) + 1 right2 = n for _ in range(m // 2, m): print(left2, right2) left2 += 1 right2 -= 1 else: left1 = 1 right1 = n // 2 - 1 for _ in range(m // 2): print(left1, right1) left1 += 1 right1 -= 1 left2 = (n // 2) + 1 right2 = n for _ in range(m // 2, m): print(left2, right2) left2 += 1 right2 -= 1 else: if n & 1: left1 = 1 right1 = n // 2 for _ in range(m // 2): print(left1, right1) left1 += 1 right1 -= 1 left2 = (n // 2) + 1 right2 = n for _ in range(m // 2, m): print(left2, right2) left2 += 1 right2 -= 1 else: left1 = 1 right1 = n // 2 - 1 for _ in range(m // 2): print(left1, right1) left1 += 1 right1 -= 1 left2 = (n // 2) + 1 right2 = n for _ in range(m // 2, m): print(left2, right2) left2 += 1 right2 -= 1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if MathLib.bitwiseAnd(m, 1) then ( if MathLib.bitwiseAnd(n, 1) then ( var left1 : int := 1 ; var right1 : int := n div 2 ; for _anon : Integer.subrange(0, m div 2-1) do ( execute (left1)->display() ; left1 := left1 + 1 ; right1 := right1 - 1) ; var left2 : int := (n div 2) + 1 ; var right2 : OclAny := n ; for _anon : Integer.subrange(m div 2, m-1) do ( execute (left2)->display() ; left2 := left2 + 1 ; right2 := right2 - 1) ) else ( left1 := 1 ; right1 := n div 2 - 1 ; for _anon : Integer.subrange(0, m div 2-1) do ( execute (left1)->display() ; left1 := left1 + 1 ; right1 := right1 - 1) ; left2 := (n div 2) + 1 ; right2 := n ; for _anon : Integer.subrange(m div 2, m-1) do ( execute (left2)->display() ; left2 := left2 + 1 ; right2 := right2 - 1) ) ) else ( if MathLib.bitwiseAnd(n, 1) then ( left1 := 1 ; right1 := n div 2 ; for _anon : Integer.subrange(0, m div 2-1) do ( execute (left1)->display() ; left1 := left1 + 1 ; right1 := right1 - 1) ; left2 := (n div 2) + 1 ; right2 := n ; for _anon : Integer.subrange(m div 2, m-1) do ( execute (left2)->display() ; left2 := left2 + 1 ; right2 := right2 - 1) ) else ( left1 := 1 ; right1 := n div 2 - 1 ; for _anon : Integer.subrange(0, m div 2-1) do ( execute (left1)->display() ; left1 := left1 + 1 ; right1 := right1 - 1) ; left2 := (n div 2) + 1 ; right2 := n ; for _anon : Integer.subrange(m div 2, m-1) do ( execute (left2)->display() ; left2 := left2 + 1 ; right2 := right2 - 1) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque,Counter from heapq import heappush,heappop,heapify import math import bisect import random from itertools import permutations,accumulate,combinations,product import sys import string from bisect import bisect_left,bisect_right from math import factorial,ceil,floor from operator import mul from functools import reduce from operator import mul sys.setrecursionlimit(2147483647) INF=10**20 def LI(): return list(map(int,sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] def SRL(n): return[list(S())for i in range(n)] def MSRL(n): return[[int(j)for j in list(S())]for i in range(n)] mod=1000000007 n,m=LI() if m==1 : print(1,2) else : l1=1 r1=l1+m l2=r1+1 r2=l2+m-1 while True : if l1>=r1 : break print(l1,r1) if l2>=r2 : break print(l2,r2) l1+=1 l2+=1 r1-=1 r2-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(2147483647) ; var INF : double := (10)->pow(20) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : int := 1000000007 ; var m : OclAny := null; Sequence{n,m} := LI() ; if m = 1 then ( execute (1)->display() ) else ( var l1 : int := 1 ; var r1 : int := l1 + m ; var l2 : int := r1 + 1 ; var r2 : double := l2 + m - 1 ; while true do ( if (l1->compareTo(r1)) >= 0 then ( break ) else skip ; execute (l1)->display() ; if (l2->compareTo(r2)) >= 0 then ( break ) else skip ; execute (l2)->display() ; l1 := l1 + 1 ; l2 := l2 + 1 ; r1 := r1 - 1 ; r2 := r2 - 1) ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.buffer.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation I() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.buffer.readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.buffer.readLine().rstrip().decode('utf-8').split(); operation S() : OclAny pre: true post: true activity: return sys.stdin.buffer.readLine().rstrip().decode('utf-8'); operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation SRL(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | ((S()))); operation MSRL(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | ((S())->select(j | true)->collect(j | (("" + ((j)))->toInteger())))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=input().split() a=int(a) b=int(b) c=int(c) f=0 for i in range(10000): ai=a*i if ai>c : break remaining=c-a*i if remaining % b==0 : print("YES") f=1 break if f==0 : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := input().split() ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; var c : int := ("" + ((c)))->toInteger() ; var f : int := 0 ; for i : Integer.subrange(0, 10000-1) do ( var ai : double := a * i ; if (ai->compareTo(c)) > 0 then ( break ) else skip ; var remaining : double := c - a * i ; if remaining mod b = 0 then ( execute ("YES")->display() ; f := 1 ; break ) else skip) ; if f = 0 then ( execute ("NO")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) ans=[] if M % 2!=0 : for i in range((M+1)//2): ans.append((1+i,M+1-i)) for j in range((M-1)//2): ans.append((M+2+j,2*M+1-j)) else : for i in range(M//2): ans.append((1+i,M+1-i)) ans.append((M+2+i,2*M+1-i)) for i in range(M): print(*ans[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := Sequence{} ; if M mod 2 /= 0 then ( for i : Integer.subrange(0, (M + 1) div 2-1) do ( execute ((Sequence{1 + i, M + 1 - i}) : ans)) ; for j : Integer.subrange(0, (M - 1) div 2-1) do ( execute ((Sequence{M + 2 + j, 2 * M + 1 - j}) : ans)) ) else ( for i : Integer.subrange(0, M div 2-1) do ( execute ((Sequence{1 + i, M + 1 - i}) : ans) ; execute ((Sequence{M + 2 + i, 2 * M + 1 - i}) : ans)) ) ; for i : Integer.subrange(0, M-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[0]*2 def format_input(filename=None): global n,m if filename==None : n,m=list(map(int,input().split())) elif filename=='__random__' : from random import randint as rng n=rng(3,10**5) m=rng(1,(n-1)//2) print(n,m) def get_answer(): median=n//2 for i in range(m): if n % 2==0 and i>=n//4 : print(median-i,median+i+2) else : print(median-i,median+i+1) if __name__=='__main__' : format_input() get_answer() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute n : OclAny; attribute m : OclAny; operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := MatrixLib.elementwiseMult(Sequence{ 0 }, 2) ; skip ; skip ; if __name__ = '__main__' then ( format_input() ; get_answer() ) else skip; operation format_input(filename : OclAny) pre: true post: true activity: if filename->oclIsUndefined() then filename := null else skip; skip; skip ; if filename = null then ( Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ) else (if filename = '__random__' then ( skip ; n := rng(3, (10)->pow(5)) ; m := rng(1, (n - 1) div 2) ; execute (n)->display() ) else skip); operation get_answer() pre: true post: true activity: var median : int := n div 2 ; for i : Integer.subrange(0, m-1) do ( if n mod 2 = 0 & (i->compareTo(n div 4)) >= 0 then ( execute (median - i)->display() ) else ( execute (median - i)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys int1=lambda x : int(x)-1 read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines sys.setrecursionlimit(500000) N,M=map(int,read().split()) l=M checked=[False]*(N+10) if N % 2==1 : for i in range(1,M+1): r=l+2*i-1 print(l,r) l-=1 else : p=(M+1)//2 for i in range(1,p+1): r=l+2*i-1 print(l,r) l-=1 for i in range(p+1,M+1): r=l+2*i-1+1 print(l,r) l-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; sys.setrecursionlimit(500000) ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (read().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : OclAny := M ; var checked : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (N + 10)) ; if N mod 2 = 1 then ( for i : Integer.subrange(1, M + 1-1) do ( var r : double := l + 2 * i - 1 ; execute (l)->display() ; l := l - 1) ) else ( var p : int := (M + 1) div 2 ; for i : Integer.subrange(1, p + 1-1) do ( r := l + 2 * i - 1 ; execute (l)->display() ; l := l - 1) ; for i : Integer.subrange(p + 1, M + 1-1) do ( r := l + 2 * i - 1 + 1 ; execute (l)->display() ; l := l - 1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from operator import xor v=int(input()) a=list(map(int,input().split())) n=0 for i in range(1,v-1): if a[i]>a[i+1]and a[i]>a[i-1]: n+=1 elif a[i]toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : int := 0 ; for i : Integer.subrange(1, v - 1-1) do ( if (a[i+1]->compareTo(a[i + 1+1])) > 0 & (a[i+1]->compareTo(a[i - 1+1])) > 0 then ( n := n + 1 ) else (if (a[i+1]->compareTo(a[i + 1+1])) < 0 & (a[i+1]->compareTo(a[i - 1+1])) < 0 then ( n := n + 1 ) else skip)) ; execute (n)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from cmath import* from dataclasses import dataclass from decimal import* def solves(): n=int(input()) lst=list(map(int,input().split())) ans=0 for i in range(1,n-1): if(lst[i]>lst[i-1]and lst[i]>lst[i+1])or(lst[i]toInteger() ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(1, n - 1-1) do ( if ((lst[i+1]->compareTo(lst[i - 1+1])) > 0 & (lst[i+1]->compareTo(lst[i + 1+1])) > 0) or ((lst[i+1]->compareTo(lst[i - 1+1])) < 0 & (lst[i+1]->compareTo(lst[i + 1+1])) < 0) then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) data=list(map(int,input().split())) ans=0 if n>2 : for i in range(1,n-1): if(data[i]>data[i+1]and data[i]>data[i-1])or(data[i]toInteger() ; var data : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; if n > 2 then ( for i : Integer.subrange(1, n - 1-1) do ( if ((data[i+1]->compareTo(data[i + 1+1])) > 0 & (data[i+1]->compareTo(data[i - 1+1])) > 0) or ((data[i+1]->compareTo(data[i + 1+1])) < 0 & (data[i+1]->compareTo(data[i - 1+1])) < 0) then ( ans := ans + 1 ) else skip) ; execute (ans)->display() ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,sys,io,math from tokenize import Triple from math import* I=lambda :[*map(int,sys.stdin.readline().split())] IS=lambda : input() IN=lambda : int(input()) IF=lambda : float(input()) x,y,a,b=map(int,input().split()) r=[] for i in range(a,x+1): for j in range(b,y+1): if i>j : r.append([i,j]) print(len(r)) for i in range(len(r)): print(r[i][0],r[i][1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var I : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var IS : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var IN : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var IF : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toReal()) ; var x : OclAny := null; var y : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{x,y,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var r : Sequence := Sequence{} ; for i : Integer.subrange(a, x + 1-1) do ( for j : Integer.subrange(b, y + 1-1) do ( if (i->compareTo(j)) > 0 then ( execute ((Sequence{i}->union(Sequence{ j })) : r) ) else skip)) ; execute ((r)->size())->display() ; for i : Integer.subrange(0, (r)->size()-1) do ( execute (r[i+1]->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) c=0 for i in range(1,n-1): if(a[i]a[i+1]and a[i]>a[i-1]): c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; for i : Integer.subrange(1, n - 1-1) do ( if ((a[i+1]->compareTo(a[i + 1+1])) < 0 & (a[i+1]->compareTo(a[i - 1+1])) < 0) or ((a[i+1]->compareTo(a[i + 1+1])) > 0 & (a[i+1]->compareTo(a[i - 1+1])) > 0) then ( c := c + 1 ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _=int(input()) a=list(map(int,input().split())) c=0 for i in range(1,len(a)-1): if a[i-1]a[i+1]: c+=1 elif a[i-1]>a[i]toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; for i : Integer.subrange(1, (a)->size() - 1-1) do ( if (a[i - 1+1]->compareTo(a[i+1])) < 0 & (a[i+1] > a[i + 1+1]) then ( c := c + 1 ) else (if (a[i - 1+1]->compareTo(a[i+1])) > 0 & (a[i+1] < a[i + 1+1]) then ( c := c + 1 ) else skip)) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): input() tempBool=False prev="_" res="" for item in input().split(""): if res=="" : prev=item[1] res=item elif(item[0]!=prev): prev=item[1] res+=item tempBool=True else : prev=item[1] res+=item[1] if(not tempBool): res+='b' print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( input() ; var tempBool : boolean := false ; var prev : String := "_" ; var res : String := "" ; for item : input().split("") do ( if res = "" then ( prev := item[1+1] ; res := item ) else (if (item->first() /= prev) then ( prev := item[1+1] ; res := res + item ; tempBool := true ) else ( prev := item[1+1] ; res := res + item[1+1] ) ) ) ; if (not(tempBool)) then ( res := res + 'b' ) else skip ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) s=input().split() for i in range(n-3): if s[i][1]!=s[i+1][0]: s.insert(i+1,s[i][1]+s[i+1][0]) break else : s.append(s[-1][1]+'a') print(s[0][0],end="") for i in range(n-1): print(s[i][1],end="") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := input().split() ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 3)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) != (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)) (trailer . (name insert) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) + (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) + (expr (atom 'a')))))))) ))))))))))))))) ; execute (s->first()->first())->display() ; for i : Integer.subrange(0, n - 1-1) do ( execute (s[i+1][1+1])->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) li=list(map(int,input().split())) print(max(li[0]-1,n-li[-1],*[(li[i]-li[i-1])//2 for i in range(1,m)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var li : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (Set{li->first() - 1, n - li->last(), (argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name li)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (name li)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])))))))) ))) // (expr (atom (number (integer 2)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name m)))))))) )))))))) ]))))))}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) if c % a==0 or c % b==0 : print("Yes") else : m=False while c>min(a,b): c-=min(a,b) if c % a==0 or c % b==0 : m=True break if m : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if c mod a = 0 or c mod b = 0 then ( execute ("Yes")->display() ) else ( var m : boolean := false ; while (c->compareTo(Set{a, b}->min())) > 0 do ( c := c - Set{a, b}->min() ; if c mod a = 0 or c mod b = 0 then ( m := true ; break ) else skip) ; if m then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: a,b=zip(*s.split()); r,*a=a for x,y in zip(b,a): r+=(x+y)[x==y :] print((r+2*b[-1])[: len(b)+2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name s)) (trailer . (name split) (arguments ( ))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name s)) (trailer . (name split) (arguments ( ))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name s)) (trailer . (name split) (arguments ( ))))))))`third->at(_indx)} ); var r : OclAny := null; var a : OclAny := null; Sequence{r,a} := a ; for _tuple : Integer.subrange(1, b->size())->collect( _indx | Sequence{b->at(_indx), a->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); r := r + (x + y).subrange(x = y+1)) ; execute ((r + 2 * b->last()).subrange(1,(b)->size() + 2))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): n=int(input()) b=input() b=b.replace("b b","b") b=b.replace("a a","a") b=b.replace("","") while(len(b)!=n): b+="a" print(b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : String := (OclFile["System.in"]).readLine() ; b := b.replace("b b", "b") ; b := b.replace("a a", "a") ; b := b.replace("", "") ; while ((b)->size() /= n) do ( b := b + "a") ; execute (b)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) S=list(input().split()) ans='' prev=None for i in range(n-2): s=S[i] if prev is None : ans+=s else : if prev[1]==s[0]: ans+=s[1] else : ans+=s prev=s if len(ans)==n-1 : if ans[len(ans)-1]==ans[len(ans)-2]=='a' : ans+='b' else : ans+='a' print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : Sequence := (input().split()) ; var ans : String := '' ; var prev : OclAny := null ; for i : Integer.subrange(0, n - 2-1) do ( var s : OclAny := S[i+1] ; if prev <>= null then ( ans := ans + s ) else ( if prev[1+1] = s->first() then ( ans := ans + s[1+1] ) else ( ans := ans + s ) ) ; prev := s) ; if (ans)->size() = n - 1 then ( if ans[(ans)->size() - 1+1] = ans[(ans)->size() - 2+1] & (ans[(ans)->size() - 2+1] == 'a') then ( ans := ans + 'b' ) else ( ans := ans + 'a' ) ) else skip ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=[] for i in range(int(input())): b.append(input()) b=sorted(b) for j in range(len(b)): if b[j][0 : len(a)]==a : print(b[j]) break else : print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : Sequence := Sequence{} ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (((OclFile["System.in"]).readLine()) : b)) ; b := b->sort() ; (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) ))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))) : (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))))))) ])))) == (comparison (expr (atom (name a))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y,a,b=map(int,input().split()) games=[] for i in range(a,x+1): if(i<=b): continue else : for j in range(b,y+1): if i>j : games.append((i,j)) print(len(games)) for i in games : print(f"{i[0]}{i[1]}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{x,y,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var games : Sequence := Sequence{} ; for i : Integer.subrange(a, x + 1-1) do ( if ((i->compareTo(b)) <= 0) then ( continue ) else ( for j : Integer.subrange(b, y + 1-1) do ( if (i->compareTo(j)) > 0 then ( execute ((Sequence{i, j}) : games) ) else skip) )) ; execute ((games)->size())->display() ; for i : games do ( execute (StringLib.formattedString("{i[0]}{i[1]}"))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- string=input() n=int(input()) arr=[] for i in range(n): x=input() arr.append(x) arr.sort() for i in arr : if i.startswith(string): string=i break print(string) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var string : String := (OclFile["System.in"]).readLine() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x : String := (OclFile["System.in"]).readLine() ; execute ((x) : arr)) ; arr := arr->sort() ; for i : arr do ( if i->hasPrefix(string) then ( string := i ; break ) else skip) ; execute (string)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- v=[] z=input() for i in range(int(input())): x=input() if x[0 : len(z)]==z : v.append(x) if len(v)==0 : print(z) else : print(min(v)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var v : Sequence := Sequence{} ; var z : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : String := (OclFile["System.in"]).readLine() ; if x.subrange(0+1, (z)->size()) = z then ( execute ((x) : v) ) else skip) ; if (v)->size() = 0 then ( execute (z)->display() ) else ( execute ((v)->min())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() res="z"*1000 n=int(input()) for i in range(n): t=input() if(t[: len(s)]==s): res=min(res,t) print(s if res=="z"*1000 else res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var res : String := StringLib.nCopies("z", 1000) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var t : String := (OclFile["System.in"]).readLine() ; if (t.subrange(1,(s)->size()) = s) then ( res := Set{res, t}->min() ) else skip) ; execute (if res = StringLib.nCopies("z", 1000) then s else res endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- current_input=input() num_history=int(input()) history_arr=[input()for _ in range(num_history)] relevant_arr=[history_element for history_element in history_arr if(history_element[: len(current_input)]==current_input)] relevant_arr.sort() print(relevant_arr[0]if len(relevant_arr)>0 else current_input) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var current_input : String := (OclFile["System.in"]).readLine() ; var num_history : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var history_arr : Sequence := Integer.subrange(0, num_history-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var relevant_arr : Sequence := history_arr->select(history_element | (history_element.subrange(1,(current_input)->size()) = current_input))->collect(history_element | (history_element)) ; relevant_arr := relevant_arr->sort() ; execute (if (relevant_arr)->size() > 0 then relevant_arr->first() else current_input endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) for i in range(a): b,c=map(int,input().split()) mas=[int(s)for s in input().split()] k=c//2 e=0 if c % 2==1 : k+=1 for j in range(len(mas)): if mas[j]toInteger() ; for i : Integer.subrange(0, a-1) do ( var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mas : Sequence := input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; var k : int := c div 2 ; var e : int := 0 ; if c mod 2 = 1 then ( k := k + 1 ) else skip ; for j : Integer.subrange(0, (mas)->size()-1) do ( if (mas[j+1]->compareTo(k)) < 0 then ( mas[j+1] := 0 ) else (if mas[j+1] = k & c mod 2 = 0 then ( if e then ( e := 0 ; mas[j+1] := 0 ) else ( e := 1 ; mas[j+1] := 1 ) ) else ( mas[j+1] := 1 ) ) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name mas))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,T=map(int,input().split()) a=list(map(int,input().split())) p=[] t=T//2 f=0 for item in a : if T % 2==0 and item==t : p.append(f) if f==1 : f=0 else : f=1 elif item<=t : p.append(0) else : p.append(1) print(*p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var T : OclAny := null; Sequence{n,T} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var p : Sequence := Sequence{} ; var t : int := T div 2 ; var f : int := 0 ; for item : a do ( if T mod 2 = 0 & item = t then ( execute ((f) : p) ; if f = 1 then ( f := 0 ) else ( f := 1 ) ) else (if (item->compareTo(t)) <= 0 then ( execute ((0) : p) ) else ( execute ((1) : p) ) ) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name p))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): a,b,c=map(int,input().split()) for i in range(c+1): for j in range(c+1): if i*a+j*b==c : print('YES') exit() print('NO') main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, c + 1-1) do ( for j : Integer.subrange(0, c + 1-1) do ( if i * a + j * b = c then ( execute ('YES')->display() ; exit() ) else skip)) ; execute ('NO')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math def get_ints(): return map(int,sys.stdin.readline().strip().split()) def get_ls(): return list(map(int,sys.stdin.readline().strip().split())) def main(): for _ in range(int(input())): n,t=get_ints() ls=get_ls() cnt=0 for i in range(n): if ls[i]t/2 : ls[i]=1 else : ls[i]=cnt % 2 cnt+=1 print(*ls) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation get_ints() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ); operation get_ls() : OclAny pre: true post: true activity: return ((sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); operation main() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := get_ints() ; var ls : OclAny := get_ls() ; var cnt : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (ls[i+1]->compareTo(t / 2)) < 0 then ( ls[i+1] := 0 ) else (if (ls[i+1]->compareTo(t / 2)) > 0 then ( ls[i+1] := 1 ) else ( ls[i+1] := cnt mod 2 ; cnt := cnt + 1 ) ) ) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ls))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) t,=R() f=0 exec(t*'n,T=R()\nfor x in R():print(+(2*x+f>T));f^=2*x==T\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := R->apply() ; var f : int := 0 ; (expr (expr (atom (name t))) * (expr (atom 'n,T=R() for x in R():print(+(2*x+f>T));f^=2*x==T '))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): x,y=map(int,input().split()) v=list(map(int,input().split())) if y % 2!=0 : t=(y-1)/2 for j in range(x): if v[j]<=t : print("0",end=" ") else : print("1",end=" ") print("\n") else : y/=2 r=v.count(y) w=r/2 w=(int)(w) r=r-w s=max(r,w) t=min(r,w) q=0 for j in range(x): if v[j]y : print("1",end=" ") else : if q==s : print("0",end=" ") else : print("1",end=" ") q+=1 print("\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var v : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if y mod 2 /= 0 then ( var t : double := (y - 1) / 2 ; for j : Integer.subrange(0, x-1) do ( if (v[j+1]->compareTo(t)) <= 0 then ( execute ("0")->display() ) else ( execute ("1")->display() )) ; execute ("\n")->display() ) else ( y := y / 2 ; var r : int := v->count(y) ; var w : double := r / 2 ; w := (OclType["int"])(w) ; r := r - w ; var s : OclAny := Set{r, w}->max() ; t := Set{r, w}->min() ; var q : int := 0 ; for j : Integer.subrange(0, x-1) do ( if (v[j+1]->compareTo(y)) < 0 then ( execute ("0")->display() ) else (if (v[j+1]->compareTo(y)) > 0 then ( execute ("1")->display() ) else ( if q = s then ( execute ("0")->display() ) else ( execute ("1")->display() ; q := q + 1 ) ) ) ) ; execute ("\n")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt mod=1000000007 def mult(a,b): return((a % mod)*(b % mod))% mod def calculate_factors(n): cnt=0 ans=1 while(n % 2==0): cnt+=1 n=n//2 if(cnt): ans=mult(ans,(cnt+1)) for i in range(3,int(sqrt(n)),2): cnt=0 while(n % i==0): cnt+=1 n=n//i if(cnt): ans=mult(ans,(cnt+1)) if(n>2): ans=mult(ans,2) return ans % mod if __name__=='__main__' : n=19374857 mod=17 print(calculate_factors(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var mod : int := 1000000007 ; skip ; skip ; if __name__ = '__main__' then ( n := 19374857 ; mod := 17 ; execute (calculate_factors(n))->display() ) else skip; operation mult(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return ((a mod mod) * (b mod mod)) mod mod; operation calculate_factors(n : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; var ans : int := 1 ; while (n mod 2 = 0) do ( cnt := cnt + 1 ; n := n div 2) ; if (cnt) then ( ans := mult(ans, (cnt + 1)) ) else skip ; for i : Integer.subrange(3, ("" + ((sqrt(n))))->toInteger()-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( cnt := 0 ; while (n mod i = 0) do ( cnt := cnt + 1 ; n := n div i) ; if (cnt) then ( ans := mult(ans, (cnt + 1)) ) else skip) ; if (n > 2) then ( ans := mult(ans, 2) ) else skip ; return ans mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import array,eulerlib def compute(): LIMIT=64000000 RESIDUE_TEST=3*5*7*11*13 isresidue=[False]*RESIDUE_TEST for i in range(RESIDUE_TEST): isresidue[i*i % RESIDUE_TEST]=True def is_perfect_square(x): return isresidue[x % RESIDUE_TEST]and eulerlib.is_square(x) sigma2=list_sigma2(LIMIT-1) ans=sum(i for i in range(1,LIMIT)if is_perfect_square(sigma2[i])) return str(ans) def list_sigma2(n): sqrt=eulerlib.sqrt(n) quasiprimefactor=array.array("H",(0 for _ in range(n+1))) for i in range(2,sqrt+1): if quasiprimefactor[i]==0 : quasiprimefactor[i]=i for j in range(i*i,n+1,i): if quasiprimefactor[j]==0 : quasiprimefactor[j]=i sigma2=array.array("Q",(0 for _ in range(n+1))) sigma2[1]=1 for i in range(2,len(sigma2)): p=quasiprimefactor[i] if p==0 : p=i sum=1 j=i p2=p*p k=p2 while j % p==0 : sum+=k j//=p k*=p2 sigma2[i]=sum*sigma2[j] return sigma2 if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LIMIT : int := 64000000 ; var RESIDUE_TEST : int := 3 * 5 * 7 * 11 * 13 ; var isresidue : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, RESIDUE_TEST) ; for i : Integer.subrange(0, RESIDUE_TEST-1) do ( isresidue[i * i mod RESIDUE_TEST+1] := true) ; skip ; var sigma2 : OclAny := list_sigma2(LIMIT - 1) ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name LIMIT)))))))) )))))) (comp_iter if (test (logical_test (comparison (expr (atom (name is_perfect_square)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name sigma2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))))))))))->sum() ; return ("" + ((ans))); operation list_sigma2(n : OclAny) : OclAny pre: true post: true activity: var sqrt : double := eulerlib.sqrt(n) ; var quasiprimefactor : OclAny := array.array("H", Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) ))))))))}) ; for i : Integer.subrange(2, sqrt + 1-1) do ( if quasiprimefactor[i+1] = 0 then ( quasiprimefactor[i+1] := i ; for j : Integer.subrange(i * i, n + 1-1)->select( $x | ($x - i * i) mod i = 0 ) do ( if quasiprimefactor[j+1] = 0 then ( quasiprimefactor[j+1] := i ) else skip) ) else skip) ; sigma2 := array.array("Q", Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) ))))))))}) ; sigma2[1+1] := 1 ; for i : Integer.subrange(2, (sigma2)->size()-1) do ( var p : OclAny := quasiprimefactor[i+1] ; if p = 0 then ( p := i ) else skip ; var sum : int := 1 ; var j : OclAny := i ; var p2 : double := p * p ; var k : OclAny := p2 ; while j mod p = 0 do ( sum := sum + k ; j := j div p ; k := k * p2) ; sigma2[i+1] := sum * sigma2[j+1]) ; return sigma2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getElement(a,n,S): a.sort(); sum=0 ; for i in range(n): if(sum+(a[i]*(n-i))==S): return a[i]; sum+=a[i]; return-1 ; if __name__=="__main__" : S=5 ; a=[1,3,2,5,8]; n=len(a); print(getElement(a,n,S)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( S := 5; ; a := Sequence{1}->union(Sequence{3}->union(Sequence{2}->union(Sequence{5}->union(Sequence{ 8 })))); ; n := (a)->size(); ; execute (getElement(a, n, S))->display(); ) else skip; operation getElement(a : OclAny, n : OclAny, S : OclAny) pre: true post: true activity: a := a->sort(); ; var sum : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (sum + (a[i+1] * (n - i)) = S) then ( return a[i+1]; ) else skip ; sum := sum + a[i+1];) ; return -1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def area(r): return(0.5)*(3.14)*(r*r) def perimeter(r): return(3.14)*(r) if __name__=='__main__' : r=10 print("The Area of Semicircle: ",area(r)) print("The Perimeter of Semicircle: ",perimeter(r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( r := 10 ; execute ("The Area of Semicircle: ")->display() ; execute ("The Perimeter of Semicircle: ")->display() ) else skip; operation area(r : OclAny) : OclAny pre: true post: true activity: return (0.5) * (3.14) * (r * r); operation perimeter(r : OclAny) : OclAny pre: true post: true activity: return (3.14) * (r); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def longestWord(self,words): Trie=lambda : collections.defaultdict(Trie) trie=Trie() END=True for i,word in enumerate(words): reduce(dict.__getitem__,word,trie)[END]=i stack=trie.values() ans="" while stack : cur=stack.pop() if END in cur : word=words[cur[END]] if len(word)>len(ans)or len(word)==len(ans)and wordexists( _x | result = _x ); operation longestWord(words : OclAny) : OclAny pre: true post: true activity: var Trie : Function := lambda $$ : OclAny in (.defaultdict(Trie)) ; var trie : OclAny := Trie->apply() ; var END : boolean := true ; for _tuple : Integer.subrange(1, (words)->size())->collect( _indx | Sequence{_indx-1, (words)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var word : OclAny := _tuple->at(_indx); reduce((trailer . (name __getitem__)), word, trie)[END+1] := i) ; var stack : OclAny := trie.values() ; var ans : String := "" ; while stack do ( var cur : OclAny := stack->last() ; stack := stack->front() ; if (cur)->includes(END) then ( var word : OclAny := words[cur[END+1]+1] ; if ((word)->size()->compareTo((ans)->size())) > 0 or (word)->size() = (ans)->size() & word < ans then ( ans := word ) else skip ; stack := stack->union(cur->select(letter | letter /= END)->collect(letter | (cur[letter+1]))) ) else skip) ; return ans; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countFactors(n,p): pwr=0 ; while(n>0 and n % p==0): n//=p ; pwr+=1 ; return pwr ; def getCount(l,r,p): cnt=0 ; for i in range(l,r+1): cnt+=countFactors(i,p); return cnt ; if __name__=="__main__" : l=2 ; r=8 ; p=2 ; print(getCount(l,r,p)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( l := 2; r := 8; p := 2; ; execute (getCount(l, r, p))->display(); ) else skip; operation countFactors(n : OclAny, p : OclAny) pre: true post: true activity: var pwr : int := 0; ; while (n > 0 & n mod p = 0) do ( n := n div p; ; pwr := pwr + 1;) ; return pwr;; operation getCount(l : OclAny, r : OclAny, p : OclAny) pre: true post: true activity: var cnt : int := 0; ; for i : Integer.subrange(l, r + 1-1) do ( cnt := cnt + countFactors(i, p);) ; return cnt;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=1000000007 def power(a,n): if(n==0): return 1 p=power(a,int(n/2))% mod ; p=(p*p)% mod if(n & 1): p=(p*a)% mod return p def countPermutations(n): if(n==1): return 0 return(power(2,n-1)-2)% mod if __name__=='__main__' : n=5 print(countPermutations(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : int := 1000000007 ; skip ; skip ; if __name__ = '__main__' then ( n := 5 ; execute (countPermutations(n))->display() ) else skip; operation power(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return 1 ) else skip ; var p : int := power(a, ("" + ((n / 2)))->toInteger()) mod mod; ; p := (p * p) mod mod ; if (MathLib.bitwiseAnd(n, 1)) then ( p := (p * a) mod mod ) else skip ; return p; operation countPermutations(n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return 0 ) else skip ; return (power(2, n - 1) - 2) mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countOperations(arr,n): count=0 ; for i in range(n-1): if(arr[i]& 1): arr[i]+=1 ; arr[i+1]+=1 ; count+=2 ; for i in range(n): if(arr[i]& 1): return-1 ; return count ; if __name__=="__main__" : arr=[2,3,4,5,6]; n=len(arr); print(countOperations(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 })))); ; n := (arr)->size(); ; execute (countOperations(arr, n))->display(); ) else skip; operation countOperations(arr : OclAny, n : OclAny) pre: true post: true activity: var count : int := 0; ; for i : Integer.subrange(0, n - 1-1) do ( if (MathLib.bitwiseAnd(arr[i+1], 1)) then ( arr[i+1] := arr[i+1] + 1; ; arr[i + 1+1] := arr[i + 1+1] + 1; ; count := count + 2; ) else skip) ; for i : Integer.subrange(0, n-1) do ( if (MathLib.bitwiseAnd(arr[i+1], 1)) then ( return -1; ) else skip) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a,b,c=map(int,input().split()) ans=False for i in range(0,1000): d=(c-a*i) if(d<0): ans=False break if(d % b==0): ans=True break if ans : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : boolean := false ; for i : Integer.subrange(0, 1000-1) do ( var d : double := (c - a * i) ; if (d < 0) then ( ans := false ; break ) else skip ; if (d mod b = 0) then ( ans := true ; break ) else skip) ; if ans then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def PROBLEM(): T=[] for _ in range(int(input())): n,k=map(int,input().split()) a=set(map(int,input().split())) mex=0 while mex in a : mex+=1 if mex>max(a)or k==0 : print(n+k) elif((max(a)+mex+1)//2)in a : print(n) else : print(n+1) PROBLEM() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; PROBLEM(); operation PROBLEM() pre: true post: true activity: var T : Sequence := Sequence{} ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var mex : int := 0 ; while (a)->includes(mex) do ( mex := mex + 1) ; if (mex->compareTo((a)->max())) > 0 or k = 0 then ( execute (n + k)->display() ) else (if (a)->includes((((a)->max() + mex + 1) div 2)) then ( execute (n)->display() ) else ( execute (n + 1)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def solve(): n,k=map(int,input().split()) arr=list(map(int,input().split())) S=set(arr) if k==0 : return len(S) m=len(S) arr.sort() mv=-1 for i in range(n): if mv+1toInteger()-1) do ( execute (solve())->display()); operation solve() : OclAny pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var S : Set := Set{}->union((arr)) ; if k = 0 then ( return (S)->size() ) else skip ; var m : int := (S)->size() ; arr := arr->sort() ; var mv : int := -1 ; for i : Integer.subrange(0, n-1) do ( if (mv + 1->compareTo(arr[i+1])) < 0 then ( mv := mv + 1 ; break ) else skip ; mv := arr[i+1]) ; if mv = arr->last() then ( return m + k ) else ( return if (S)->includes((arr->last() + mv) div 2 + (arr->last() + mv) mod 2) then m else m + 1 endif ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() result="" i=0 while icompareTo((s)->size())) < 0 do ( if s[i+1] = "." then ( result := result + '0' ) else ( i := i + 1 ; if s[i+1] = "." then ( result := result + '1' ) else ( result := result + '2' ) ) ; i := i + 1) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) a=set(map(int,input().split())) m=max(a) mex=0 while mex in a : mex+=1 if mex>m or k==0 : print(n+k) else : if(m+mex+1)//2 in a : print(n) else : print(n+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var m : OclAny := (a)->max() ; var mex : int := 0 ; while (a)->includes(mex) do ( mex := mex + 1) ; if (mex->compareTo(m)) > 0 or k = 0 then ( execute (n + k)->display() ) else ( if (a)->includes((m + mex + 1) div 2) then ( execute (n)->display() ) else ( execute (n + 1)->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=lambda : map(int,input().split()) for i in "*"*int(input()): n,k=I() a,q=set(I()),0 if k : while q in a : q+=1 w=max(a) e=(w+q+1)//2 if e!=q : a.add(e); k=0 print(len(a)+k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : StringLib.nCopies("*", ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := I->apply() ; var a : OclAny := null; var q : OclAny := null; Sequence{a,q} := Sequence{Set{}->union((I->apply())),0} ; if k then ( while (a)->includes(q) do ( q := q + 1) ; var w : OclAny := (a)->max() ; var e : int := (w + q + 1) div 2 ; if e /= q then ( execute ((e) : a); var k : int := 0 ) else skip ) else skip ; execute ((a)->size() + k)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import ceil input=lambda : sys.stdin.readline() T=int(input()) for _ in range(T): n,k=map(int,input().strip().split()) a=list(map(int,input().strip().split())) if k==0 : print(n) continue a.sort() t=n for i in range(n): if a[i]!=i : t=i break if t==n : print(n+k) continue x=ceil((t+a[-1])/2) if x not in a : print(n+1) else : print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, T-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input->apply()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input->apply()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if k = 0 then ( execute (n)->display() ; continue ) else skip ; a := a->sort() ; var t : OclAny := n ; for i : Integer.subrange(0, n-1) do ( if a[i+1] /= i then ( t := i ; break ) else skip) ; if t = n then ( execute (n + k)->display() ; continue ) else skip ; var x : OclAny := ceil((t + a->last()) / 2) ; if (a)->excludes(x) then ( execute (n + 1)->display() ) else ( execute (n)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in ' '*int(input()): a,b,d=map(int,input().split()) print("YES" if(d+1)*min(a,b)>=max(a,b)else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : StringLib.nCopies(' ', ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var a : OclAny := null; var b : OclAny := null; var d : OclAny := null; Sequence{a,b,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if ((d + 1) * Set{a, b}->min()->compareTo(Set{a, b}->max())) >= 0 then "YES" else "NO" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for l in range(t): r,b,d=map(int,input().split()) maxs=max(b,r) mins=min(b,r) if maxs>mins*(d+1): print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for l : Integer.subrange(0, t-1) do ( var r : OclAny := null; var b : OclAny := null; var d : OclAny := null; Sequence{r,b,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var maxs : OclAny := Set{b, r}->max() ; var mins : OclAny := Set{b, r}->min() ; if (maxs->compareTo(mins * (d + 1))) > 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): r,b,d=map(int,input().split()) res=min(r,b)*(d+1) if res>=max(r,b): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var r : OclAny := null; var b : OclAny := null; var d : OclAny := null; Sequence{r,b,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var res : double := Set{r, b}->min() * (d + 1) ; if (res->compareTo(Set{r, b}->max())) >= 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) tlist=[] for i in range(n): s=input().split(' ') r=int(s[0]) b=int(s[1]) d=int(s[2]) mi=min(r,b) ma=max(r,b) if mi+mi*d=ma : tlist.append('YES') for _ in tlist : print(_) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var tlist : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var s : OclAny := input().split(' ') ; var r : int := ("" + ((s->first())))->toInteger() ; var b : int := ("" + ((s[1+1])))->toInteger() ; var d : int := ("" + ((s[2+1])))->toInteger() ; var mi : OclAny := Set{r, b}->min() ; var ma : OclAny := Set{r, b}->max() ; if (mi + mi * d->compareTo(ma)) < 0 then ( execute (('NO') : tlist) ) else (if (mi + mi * d->compareTo(ma)) >= 0 then ( execute (('YES') : tlist) ) else skip)) ; for _anon : tlist do ( execute (_anon)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): r,b,d=list(map(int,input().split())) if r>b : r,b=b,r if r*(d+1)toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var r : OclAny := null; var b : OclAny := null; var d : OclAny := null; Sequence{r,b,d} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (r->compareTo(b)) > 0 then ( var r : OclAny := null; var b : OclAny := null; Sequence{r,b} := Sequence{b,r} ) else skip ; if (r * (d + 1)->compareTo(b)) < 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split(" ")) for i in range(max(a,b)+1): if(c-a*i)% b==0 and(c-a*i)>=0 : print("Yes") exit(0) print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, Set{a, b}->max() + 1-1) do ( if (c - a * i) mod b = 0 & (c - a * i) >= 0 then ( execute ("Yes")->display() ; exit(0) ) else skip) ; execute ("No")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPrime(n): i=2 while i*i<=n : if(n % i==0): return False i+=1 return True def sum(l,r): sum=0 for i in range(l,r+1): if(isPrime(i)): continue for j in range(2,i): if(i % j==0 and isPrime(j)): sum+=j return sum if __name__=="__main__" : l=18 r=25 print(sum(l,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( l := 18 ; r := 25 ; execute ((l, r)->sum())->display() ) else skip; operation isPrime(n : OclAny) : OclAny pre: true post: true activity: var i : int := 2 ; while (i * i->compareTo(n)) <= 0 do ( if (n mod i = 0) then ( return false ) else skip ; i := i + 1) ; return true; operation sum(l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(l, r + 1-1) do ( if (isPrime(i)) then ( continue ) else skip ; for j : Integer.subrange(2, i-1) do ( if (i mod j = 0 & isPrime(j)) then ( sum := sum + j ) else skip)) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() i=0 while icompareTo((n)->size())) < 0 do ( if (n[i+1] = '.') then ( execute (0)->display() ; i := i + 1 ) else (if (n[i+1] = '-') then ( if (n[i + 1+1] = '.') then ( execute (1)->display() ) else (if (n[i + 1+1] = '-') then ( execute (2)->display() ) else skip) ; i := i + 2 ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input(); print(len({s[i :]+s[: i]for i in range(len(s))})) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine(); execute ((Integer.subrange(0, (s)->size()-1)->select(i | true)->collect(i | s.subrange(i+1) + s.subrange(1,i))->asSet())->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(s): b=set() b.add(s) for i in range(len(s)): c=s[len(s)-1]+s[0 : len(s)-1] b.add(c) s=c print(len(b)) if __name__=="__main__" : s=input() main(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := (OclFile["System.in"]).readLine() ; main(s) ) else skip; operation main(s : OclAny) pre: true post: true activity: var b : Set := Set{}->union(()) ; execute ((s) : b) ; for i : Integer.subrange(0, (s)->size()-1) do ( var c : OclAny := s[(s)->size() - 1+1] + s.subrange(0+1, (s)->size() - 1) ; execute ((c) : b) ; s := c) ; execute ((b)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input(); print(len({s[i :]+s[: i]for i in range(len(s))})) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine(); execute ((Integer.subrange(0, (s)->size()-1)->select(i | true)->collect(i | s.subrange(i+1) + s.subrange(1,i))->asSet())->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input(); print(len({s[i :]+s[: i]for i in range(len(s))})) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine(); execute ((Integer.subrange(0, (s)->size()-1)->select(i | true)->collect(i | s.subrange(i+1) + s.subrange(1,i))->asSet())->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input(); print(len({s[i :]+s[: i]for i in range(len(s))})) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine(); execute ((Integer.subrange(0, (s)->size()-1)->select(i | true)->collect(i | s.subrange(i+1) + s.subrange(1,i))->asSet())->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=5 num=1 gap=n-1 for j in range(1,n+1): num=j for i in range(1,gap+1): print("",end="") gap=gap-1 for i in range(1,j+1): print(num,end="") num=num+1 num=num-2 for i in range(1,j): print(num,end="") num=num-1 print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := 5 ; var num : int := 1 ; var gap : double := n - 1 ; for j : Integer.subrange(1, n + 1-1) do ( num := j ; for i : Integer.subrange(1, gap + 1-1) do ( execute ("")->display()) ; gap := gap - 1 ; for i : Integer.subrange(1, j + 1-1) do ( execute (num)->display() ; num := num + 1) ; num := num - 2 ; for i : Integer.subrange(1, j-1) do ( execute (num)->display() ; num := num - 1) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def power(x,y): if(y==0): return 1 temp=power(x,int(y/2)) if(y % 2==0): return temp*temp else : if(y>0): return x*temp*temp else : return(temp*temp)/x x,y=2,-3 print('%.6f' %(power(x,y))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{x,y} := Sequence{2,-3} ; execute (StringLib.format('%.6f',(power(x, y))))->display(); operation power(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: if (y = 0) then ( return 1 ) else skip ; var temp : OclAny := power(x, ("" + ((y / 2)))->toInteger()) ; if (y mod 2 = 0) then ( return temp * temp ) else ( if (y > 0) then ( return x * temp * temp ) else ( return (temp * temp) / x ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def digitsum(n): r=n % 9 ; if(r==0): return 9 ; else : return r ; def find(n,d): minimum=10 ; for i in range(9): current=(n+i*d); minimum=min(minimum,digitsum(current)); return minimum ; n=2546 ; d=124 ; print("Minimum possible digitsum is :",find(n,d)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 2546; ; d := 124; ; execute ("Minimum possible digitsum is :")->display();; operation digitsum(n : OclAny) pre: true post: true activity: var r : int := n mod 9; ; if (r = 0) then ( return 9; ) else ( return r; ); operation find(n : OclAny, d : OclAny) pre: true post: true activity: var minimum : int := 10; ; for i : Integer.subrange(0, 9-1) do ( var current : OclAny := (n + i * d); ; minimum := Set{minimum, digitsum(current)}->min();) ; return minimum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printXYZ(n): if n==1 : print(-1) else : print("x is ",n) print("y is ",n+1) print("z is ",n*(n+1)) n=7 printXYZ(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 7 ; printXYZ(n); operation printXYZ(n : OclAny) pre: true post: true activity: if n = 1 then ( execute (-1)->display() ) else ( execute ("x is ")->display() ; execute ("y is ")->display() ; execute ("z is ")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): n,m=map(int,input().split()) grid=[] res=0 for _ in range(n): grid.append(input()) for i in range(n): for j in range(m): if grid[i][j]=="W" : for di,dj in[(0,1),(1,0),(0,-1),(-1,0)]: ni=i+di nj=j+dj if not(0<=nicollect( _x | (OclType["int"])->apply(_x) ) ; var grid : Sequence := Sequence{} ; var res : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : grid)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if grid[i+1][j+1] = "W" then ( for _tuple : Sequence{Sequence{0, 1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{0, -1}}->union(Sequence{ Sequence{-1, 0} }))) do (var _indx : int := 1; var di : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dj : OclAny := _tuple->at(_indx); var ni : OclAny := i + di ; var nj : OclAny := j + dj ; if not((0 <= ni & (ni < (grid)->size()) & 0 <= nj & (nj < (grid->first())->size()))) then ( continue ) else skip ; if grid[ni+1][nj+1] = "P" then ( res := res + 1 ; break; ) else skip) ) else skip)) ; execute (res)->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- borze_code=input() index=0 while True : if borze_code[index]=='.' : print('0',end="") else : index+=1 if borze_code[index]=='.' : print('1',end="") else : print('2',end="") index+=1 if index==len(borze_code): break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var borze_code : String := (OclFile["System.in"]).readLine() ; var index : int := 0 ; while true do ( if borze_code[index+1] = '.' then ( execute ('0')->display() ) else ( index := index + 1 ; if borze_code[index+1] = '.' then ( execute ('1')->display() ) else ( execute ('2')->display() ) ) ; index := index + 1 ; if index = (borze_code)->size() then ( break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def merge(arr,temp,left,mid,right): inv_count=0 i=left j=mid k=left while((i<=mid-1)and(j<=right)): if(arr[i]<=arr[j]): temp[k]=arr[i] k+=1 i+=1 else : temp[k]=arr[j] k+=1 j+=1 inv_count=inv_count+(mid-i) while(i<=mid-1): temp[k]=arr[i] k+=1 i+=1 while(j<=right): temp[k]=arr[j] k+=1 j+=1 for i in range(left,right+1,1): arr[i]=temp[i] return inv_count def _mergeSort(arr,temp,left,right): inv_count=0 if(right>left): mid=int((right+left)/2) inv_count=_mergeSort(arr,temp,left,mid) inv_count+=_mergeSort(arr,temp,mid+1,right) inv_count+=merge(arr,temp,left,mid+1,right) return inv_count def countSwaps(arr,n): temp=[0 for i in range(n)] return _mergeSort(arr,temp,0,n-1) if __name__=='__main__' : arr=[1,20,6,4,5] n=len(arr) print("Number of swaps is",countSwaps(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{20}->union(Sequence{6}->union(Sequence{4}->union(Sequence{ 5 })))) ; n := (arr)->size() ; execute ("Number of swaps is")->display() ) else skip; operation merge(arr : OclAny, temp : OclAny, left : OclAny, mid : OclAny, right : OclAny) : OclAny pre: true post: true activity: var inv_count : int := 0 ; var i : OclAny := left ; var j : OclAny := mid ; var k : OclAny := left ; while (((i->compareTo(mid - 1)) <= 0) & ((j->compareTo(right)) <= 0)) do ( if ((arr[i+1]->compareTo(arr[j+1])) <= 0) then ( temp[k+1] := arr[i+1] ; k := k + 1 ; i := i + 1 ) else ( temp[k+1] := arr[j+1] ; k := k + 1 ; j := j + 1 ; inv_count := inv_count + (mid - i) )) ; while ((i->compareTo(mid - 1)) <= 0) do ( temp[k+1] := arr[i+1] ; k := k + 1 ; i := i + 1) ; while ((j->compareTo(right)) <= 0) do ( temp[k+1] := arr[j+1] ; k := k + 1 ; j := j + 1) ; for i : Integer.subrange(left, right + 1-1)->select( $x | ($x - left) mod 1 = 0 ) do ( arr[i+1] := temp[i+1]) ; return inv_count; operation _mergeSort(arr : OclAny, temp : OclAny, left : OclAny, right : OclAny) : OclAny pre: true post: true activity: inv_count := 0 ; if ((right->compareTo(left)) > 0) then ( mid := ("" + (((right + left) / 2)))->toInteger() ; inv_count := _mergeSort(arr, temp, left, mid) ; inv_count := inv_count + _mergeSort(arr, temp, mid + 1, right) ; inv_count := inv_count + merge(arr, temp, left, mid + 1, right) ) else skip ; return inv_count; operation countSwaps(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: temp := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; return _mergeSort(arr, temp, 0, n - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from queue import PriorityQueue MAX_CHAR=26 def minStringValue(str,k): l=len(str) if(k>=l): return 0 frequency=[0]*MAX_CHAR for i in range(0,l): frequency[ord(str[i])-97]+=1 q=PriorityQueue() for i in range(0,MAX_CHAR): q.put(-frequency[i]) while(k>0): temp=q.get() temp=temp+1 q.put(temp,temp) k=k-1 result=0 ; while not q.empty(): temp=q.get() temp=temp*(-1) result+=temp*temp return result if __name__=="__main__" : str="abbccc" k=2 print(minStringValue(str,k)) str="aaab" k=2 print(minStringValue(str,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MAX_CHAR : int := 26 ; skip ; if __name__ = "__main__" then ( OclType["String"] := "abbccc" ; k := 2 ; execute (minStringValue(OclType["String"], k))->display() ; OclType["String"] := "aaab" ; k := 2 ; execute (minStringValue(OclType["String"], k))->display() ) else skip; operation minStringValue(OclType["String"] : OclAny, k : OclAny) : OclAny pre: true post: true activity: var l : int := (OclType["String"])->size() ; if ((k->compareTo(l)) >= 0) then ( return 0 ) else skip ; var frequency : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX_CHAR) ; for i : Integer.subrange(0, l-1) do ( frequency[(("" + ([i+1])))->char2byte() - 97+1] := frequency[(("" + ([i+1])))->char2byte() - 97+1] + 1) ; var q : OclAny := PriorityQueue() ; for i : Integer.subrange(0, MAX_CHAR-1) do ( q.put(-frequency[i+1])) ; while (k > 0) do ( var temp : OclAny := q.get() ; temp := temp + 1 ; q.put(temp, temp) ; k := k - 1) ; var result : int := 0; ; while not(q.empty()) do ( temp := q.get() ; temp := temp * (-1) ; result := result + temp * temp) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lenOfLongSubarr(arr,n): um={i : 0 for i in range(10)} sum=0 maxLen=0 for i in range(n): if arr[i]==0 : sum+=-1 else : sum+=1 if(sum==1): maxLen=i+1 elif(sum not in um): um[sum]=i if((sum-1)in um): if(maxLen<(i-um[sum-1])): maxLen=i-um[sum-1] return maxLen if __name__=='__main__' : arr=[0,1,1,0,0,1] n=len(arr) print("Length=",lenOfLongSubarr(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 1 }))))) ; n := (arr)->size() ; execute ("Length=")->display() ) else skip; operation lenOfLongSubarr(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var um : Map := Integer.subrange(0, 10-1)->select(i | true)->collect(i | Map{i |-> 0})->unionAll() ; var sum : int := 0 ; var maxLen : int := 0 ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] = 0 then ( sum := sum + -1 ) else ( sum := sum + 1 ) ; if (sum = 1) then ( maxLen := i + 1 ) else (if ((um)->excludes(sum)) then ( um[sum+1] := i ) else skip) ; if ((um)->includes((sum - 1))) then ( if ((maxLen->compareTo((i - um[sum - 1+1]))) < 0) then ( maxLen := i - um[sum - 1+1] ) else skip ) else skip) ; return maxLen; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printArr(arr,n): for i in range(n): print(arr[i],end=""); def findArrangement(arr,n): if(n<2): print("-1",end=""); return ; minVal=min(arr); for i in range(n): if(arr[i]==minVal): arr[i],arr[n-1]=arr[n-1],arr[i]; break ; andVal=arr[0]; for i in range(1,n-1): andVal &=arr[i]; if(andVal==arr[n-1]): printArr(arr,n); else : print("-1"); if __name__=="__main__" : arr=[1,5,3,3]; n=len(arr); findArrangement(arr,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{5}->union(Sequence{3}->union(Sequence{ 3 }))); ; n := (arr)->size(); ; findArrangement(arr, n); ) else skip; operation printArr(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display();); operation findArrangement(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n < 2) then ( execute ("-1")->display(); ; return; ) else skip ; var minVal : OclAny := (arr)->min(); ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] = minVal) then ( var arr[i+1] : OclAny := null; var arr[n - 1+1] : OclAny := null; Sequence{arr[i+1],arr[n - 1+1]} := Sequence{arr[n - 1+1],arr[i+1]}; ; break; ) else skip) ; var andVal : OclAny := arr->first(); ; for i : Integer.subrange(1, n - 1-1) do ( andVal := andVal & arr[i+1];) ; if (andVal = arr[n - 1+1]) then ( printArr(arr, n); ) else ( execute ("-1")->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findProduct(arr,n,k): prod=1 for i in range(n): if(arr[i]% k==0): prod*=arr[i] return prod if __name__=="__main__" : arr=[15,16,10,9,6,7,17] n=len(arr) k=3 print(findProduct(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{15}->union(Sequence{16}->union(Sequence{10}->union(Sequence{9}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 17 })))))) ; n := (arr)->size() ; k := 3 ; execute (findProduct(arr, n, k))->display() ) else skip; operation findProduct(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var prod : int := 1 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] mod k = 0) then ( prod := prod * arr[i+1] ) else skip) ; return prod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ways(n): if(n==1): return 1 ; if(n==2): return 2 ; else : return ways(n-1)+ways(n-2); if __name__=="__main__" : n=5 ; print("Number of ways=",ways(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 5; ; execute ("Number of ways=")->display(); ) else skip; operation ways(n : OclAny) pre: true post: true activity: if (n = 1) then ( return 1; ) else skip ; if (n = 2) then ( return 2; ) else ( return ways(n - 1) + ways(n - 2); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) s=input() out='' for i in s : if i=='U' : out+='D' elif i=='D' : out+='U' else : out+=i print(out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var out : String := '' ; for i : s->characters() do ( if i = 'U' then ( out := out + 'D' ) else (if i = 'D' then ( out := out + 'U' ) else ( out := out + i ) ) ) ; execute (out)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) s=input() l=[] for i in range(len(s)): if s[i]=='U' : l.append('D') elif s[i]=='D' : l.append('U') else : l.append(s[i]) for x in l : print(x,end='') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = 'U' then ( execute (('D') : l) ) else (if s[i+1] = 'D' then ( execute (('U') : l) ) else ( execute ((s[i+1]) : l) ) ) ) ; for x : l do ( execute (x)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(''.join([*open(0)][2 : : 2]).translate({85 : 68,68 : 85})) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (''.join(OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2)))))))))).translate(Map{ 85 |-> 68 }->union(Map{ 68 |-> 85 })))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) s=list(input()) for i,x in enumerate(s): if x=='U' : s[i]='D' if x=='D' : s[i]='U' print("".join(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); if x = 'U' then ( s[i+1] := 'D' ) else skip ; if x = 'D' then ( s[i+1] := 'U' ) else skip) ; execute (StringLib.sumStringsWithSeparator((s), ""))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=[int(x)for x in input().split()] ans=-1 for i in range(N): for j in range(i+1,N): num=[int(x)for x in str(A[i]*A[j])] if all(num[i]+1==num[i+1]for i in range(len(num)-1))and anstoInteger() ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : int := -1 ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(i + 1, N-1) do ( var num : Sequence := ("" + ((A[i+1] * A[j+1])))->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if ((argument (test (logical_test (comparison (comparison (expr (expr (atom (name num)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) + (expr (atom (number (integer 1)))))) == (comparison (expr (atom (name num)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) )))) - (expr (atom (number (integer 1)))))))))) )))))))))->forAll( _x | _x = true ) & (ans->compareTo(A[i+1] * A[j+1])) < 0 then ( ans := A[i+1] * A[j+1] ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(n)for n in input().split()] mat=[] for i in range(n): s=input() char=[] for index in s : char.append(index) mat.append(char) pigcount=0 for i in range(0,n): for j in range(0,m): if i!=n-1 and mat[i][j]=='W' and mat[i+1][j]=='P' : mat[i+1][j]='.' mat[i][j]='.' pigcount+=1 elif i!=n-1 and mat[i][j]=='P' and mat[i+1][j]=='W' : mat[i+1][j]='.' mat[i][j]='.' pigcount+=1 elif j!=m-1 and mat[i][j]=='W' and mat[i][j+1]=='P' : mat[i][j+1]='.' mat[i][j]='.' pigcount+=1 elif j!=m-1 and mat[i][j]=='P' and mat[i][j+1]=='W' : mat[i][j+1]='.' mat[i][j]='.' pigcount+=1 elif i!=n-1 and mat[i][j]=='W' and mat[i+1][j]=='P' : mat[i+1][j]='.' mat[i][j]='.' pigcount+=1 elif i!=n-1 and mat[i][j]=='P' and mat[i+1][j]=='W' : mat[i+1][j]='.' mat[i][j]='.' pigcount+=1 print(pigcount) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; var mat : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var char : Sequence := Sequence{} ; for index : s->characters() do ( execute ((index) : char)) ; execute ((char) : mat)) ; var pigcount : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if i /= n - 1 & mat[i+1][j+1] = 'W' & mat[i + 1+1][j+1] = 'P' then ( mat[i + 1+1][j+1] := '.' ; mat[i+1][j+1] := '.' ; pigcount := pigcount + 1 ) else (if i /= n - 1 & mat[i+1][j+1] = 'P' & mat[i + 1+1][j+1] = 'W' then ( mat[i + 1+1][j+1] := '.' ; mat[i+1][j+1] := '.' ; pigcount := pigcount + 1 ) else (if j /= m - 1 & mat[i+1][j+1] = 'W' & mat[i+1][j + 1+1] = 'P' then ( mat[i+1][j + 1+1] := '.' ; mat[i+1][j+1] := '.' ; pigcount := pigcount + 1 ) else (if j /= m - 1 & mat[i+1][j+1] = 'P' & mat[i+1][j + 1+1] = 'W' then ( mat[i+1][j + 1+1] := '.' ; mat[i+1][j+1] := '.' ; pigcount := pigcount + 1 ) else (if i /= n - 1 & mat[i+1][j+1] = 'W' & mat[i + 1+1][j+1] = 'P' then ( mat[i + 1+1][j+1] := '.' ; mat[i+1][j+1] := '.' ; pigcount := pigcount + 1 ) else (if i /= n - 1 & mat[i+1][j+1] = 'P' & mat[i + 1+1][j+1] = 'W' then ( mat[i + 1+1][j+1] := '.' ; mat[i+1][j+1] := '.' ; pigcount := pigcount + 1 ) else skip ) ) ) ) ) )) ; execute (pigcount)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(s): i=0 ret='' while itoInteger() ; for i : Integer.subrange(0, t-1) do ( input() ; execute (solve((OclFile["System.in"]).readLine()))->display()); operation solve(s : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; var ret : String := '' ; while (i->compareTo((s)->size())) < 0 do ( if s[i+1] = 'L' or s[i+1] = 'R' then ( ret := ret + 'LR' ; i := i + 2 ) else (if s[i+1] = 'U' then ( ret := ret + 'D' ; i := i + 1 ) else (if s[i+1] = 'D' then ( ret := ret + 'U' ; i := i + 1 ) else skip ) ) ) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) values=list(map(int,input().split())) od=0 ev=0 o=[] e=[] for val in values : if val % 2==0 : e.append(val) ev+=1 else : o.append(val) od+=1 if ev==od : print(od) elif od>ev : print(ev) else : if od!=0 : print(ev) else : total=ev-1 mi=1000000000 for val in e : x=0 while val % 2==0 : val/=2 x+=1 mi=min(mi,x) print(total+mi) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var values : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var od : int := 0 ; var ev : int := 0 ; var o : Sequence := Sequence{} ; var e : Sequence := Sequence{} ; for val : values do ( if val mod 2 = 0 then ( execute ((val) : e) ; ev := ev + 1 ) else ( execute ((val) : o) ; od := od + 1 )) ; if ev = od then ( execute (od)->display() ) else (if (od->compareTo(ev)) > 0 then ( execute (ev)->display() ) else ( if od /= 0 then ( execute (ev)->display() ) else ( var total : double := ev - 1 ; var mi : int := 1000000000 ; for val : e do ( var x : int := 0 ; while val mod 2 = 0 do ( val := val / 2 ; x := x + 1) ; mi := Set{mi, x}->min()) ; execute (total + mi)->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left from collections import defaultdict for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) odd=0 eve=0 for i in l : if i % 2==0 : eve+=1 else : odd+=1 if eve==0 : print(0) else : if n==1 : s=l[0] cnt=0 while s % 2==0 : cnt+=1 s//=2 print(cnt) else : s=min(l) cnt=10**9 if odd!=0 : print(eve) elif odd==0 : for i in l : c=0 while i % 2==0 : c+=1 i//=2 cnt=min(cnt,c) print(cnt+eve-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var odd : int := 0 ; var eve : int := 0 ; for i : l do ( if i mod 2 = 0 then ( eve := eve + 1 ) else ( odd := odd + 1 )) ; if eve = 0 then ( execute (0)->display() ) else ( if n = 1 then ( var s : OclAny := l->first() ; var cnt : int := 0 ; while s mod 2 = 0 do ( cnt := cnt + 1 ; s := s div 2) ; execute (cnt)->display() ) else ( s := (l)->min() ; cnt := (10)->pow(9) ; if odd /= 0 then ( execute (eve)->display() ) else (if odd = 0 then ( for i : l do ( var c : int := 0 ; while i mod 2 = 0 do ( c := c + 1 ; i := i div 2) ; cnt := Set{cnt, c}->min()) ; execute (cnt + eve - 1)->display() ) else skip) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.buffer.readline def process(A): n=len(A) evens=[] has_odd=False for x in A : if x % 2==0 : c=0 while x % 2==0 : x=x//2 c+=1 evens.append(c) else : has_odd=True if len(evens)==0 : print(0) else : if has_odd : answer=len(evens) else : m=min(evens) answer=m+len(evens)-1 print(answer) t=int(input()) for i in range(t): n=int(input()) A=[int(x)for x in input().split()] process(A) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := sys.stdin.buffer.readline ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; A := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; process(A)); operation process(A : OclAny) pre: true post: true activity: var n : int := (A)->size() ; var evens : Sequence := Sequence{} ; var has_odd : boolean := false ; for x : A do ( if x mod 2 = 0 then ( var c : int := 0 ; while x mod 2 = 0 do ( var x : int := x div 2 ; c := c + 1) ; execute ((c) : evens) ) else ( has_odd := true )) ; if (evens)->size() = 0 then ( execute (0)->display() ) else ( if has_odd then ( var answer : int := (evens)->size() ) else ( var m : OclAny := (evens)->min() ; answer := m + (evens)->size() - 1 ) ; execute (answer)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): input() a=[int(x)for x in input().split()] even_num=[] num_odd=0 num_even=0 for x in a : if x % 2 : num_odd+=1 else : even_num.append(x) num_even+=1 if num_odd==0 : m=1e9+7 for x in a : y=x &(-x) m=min(m,y) k=-1 for i in range(32): if(m &(1<toInteger() ; for _anon : Integer.subrange(0, t-1) do ( input() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var even_num : Sequence := Sequence{} ; var num_odd : int := 0 ; var num_even : int := 0 ; for x : a do ( if x mod 2 then ( num_odd := num_odd + 1 ) else ( execute ((x) : even_num) ; num_even := num_even + 1 )) ; if num_odd = 0 then ( var m : double := ("1e9")->toReal() + 7 ; for x : a do ( var y : int := MathLib.bitwiseAnd(x, (-x)) ; m := Set{m, y}->min()) ; var k : int := -1 ; for i : Integer.subrange(0, 32-1) do ( if (MathLib.bitwiseAnd(m, (1 * (2->pow(i))))) then ( k := i ; break ) else skip) ; execute (k + num_even - 1)->display() ) else ( execute (num_even)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): input() a=[int(x)for x in input().split()] even_num=[] num_odd=0 num_even=0 for x in a : if x % 2 : num_odd+=1 else : even_num.append(x) num_even+=1 if num_odd==0 : m=1e9+7 for x in a : y=x &(-x) m=min(m,y) k=0 while m % 2==0 : m=m//2 k+=1 print(k+num_even-1) else : print(num_even) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( input() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var even_num : Sequence := Sequence{} ; var num_odd : int := 0 ; var num_even : int := 0 ; for x : a do ( if x mod 2 then ( num_odd := num_odd + 1 ) else ( execute ((x) : even_num) ; num_even := num_even + 1 )) ; if num_odd = 0 then ( var m : double := ("1e9")->toReal() + 7 ; for x : a do ( var y : int := MathLib.bitwiseAnd(x, (-x)) ; m := Set{m, y}->min()) ; var k : int := 0 ; while m mod 2 = 0 do ( m := m div 2 ; k := k + 1) ; execute (k + num_even - 1)->display() ) else ( execute (num_even)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Sum(mat,r,c): i,j=0,0 ; upper_sum=0 ; lower_sum=0 ; for i in range(r): for j in range(c): if(i<=j): upper_sum+=mat[i][j]; print("Upper sum is ",upper_sum); for i in range(r): for j in range(c): if(j<=i): lower_sum+=mat[i][j]; print("Lower sum is ",lower_sum); r=3 ; c=3 ; mat=[[6,5,4],[1,2,5],[7,9,7]]; Sum(mat,r,c); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; r := 3; ; c := 3; ; mat := Sequence{Sequence{6}->union(Sequence{5}->union(Sequence{ 4 }))}->union(Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 5 }))}->union(Sequence{ Sequence{7}->union(Sequence{9}->union(Sequence{ 7 })) })); ; Sum(mat, r, c);; operation Sum(mat : OclAny, r : OclAny, c : OclAny) pre: true post: true activity: var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,0}; ; var upper_sum : int := 0; ; var lower_sum : int := 0; ; for i : Integer.subrange(0, r-1) do ( for j : Integer.subrange(0, c-1) do ( if ((i->compareTo(j)) <= 0) then ( upper_sum := upper_sum + mat[i+1][j+1]; ) else skip)) ; execute ("Upper sum is ")->display(); ; for i : Integer.subrange(0, r-1) do ( for j : Integer.subrange(0, c-1) do ( if ((j->compareTo(i)) <= 0) then ( lower_sum := lower_sum + mat[i+1][j+1]; ) else skip)) ; execute ("Lower sum is ")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lcs(dp,a,b,m,n): for i in range(100): for j in range(100): dp[i][j]=-1 if(m<0 or n<0): return 0 if(dp[m][n]!=-1): return dp[m][n] ans=0 if(a[m]==b[n]): ans=(ord(a[m])-48)+lcs(dp,a,b,m-1,n-1) else : ans=max(lcs(dp,a,b,m-1,n),lcs(dp,a,b,m,n-1)) dp[m][n]=ans return ans def costOfString(s): cost=0 for i in range(len(s)): cost+=(ord(s[i])-48) return cost if __name__=="__main__" : a="9142" b="1429" dp=[[0 for x in range(101)]for y in range(101)] print(costOfString(a)+costOfString(b)-2*lcs(dp,a,b,len(a)-1,len(b)-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( a := "9142" ; b := "1429" ; dp := Integer.subrange(0, 101-1)->select(y | true)->collect(y | (Integer.subrange(0, 101-1)->select(x | true)->collect(x | (0)))) ; execute (costOfString(a) + costOfString(b) - 2 * lcs(dp, a, b, (a)->size() - 1, (b)->size() - 1))->display() ) else skip; operation lcs(dp : OclAny, a : OclAny, b : OclAny, m : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, 100-1) do ( for j : Integer.subrange(0, 100-1) do ( dp[i+1][j+1] := -1)) ; if (m < 0 or n < 0) then ( return 0 ) else skip ; if (dp[m+1][n+1] /= -1) then ( return dp[m+1][n+1] ) else skip ; var ans : int := 0 ; if (a[m+1] = b[n+1]) then ( ans := ((a[m+1])->char2byte() - 48) + lcs(dp, a, b, m - 1, n - 1) ) else ( ans := Set{lcs(dp, a, b, m - 1, n), lcs(dp, a, b, m, n - 1)}->max() ) ; dp[m+1][n+1] := ans ; return ans; operation costOfString(s : OclAny) : OclAny pre: true post: true activity: var cost : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( cost := cost + ((s[i+1])->char2byte() - 48)) ; return cost; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def MinimumMail(n,k,x): m=((n-1)+int(math.ceil((n-1)*1.0/x)*(n-1)+math.ceil(n*1.0/x)*(k-n))); return m ; N=4 ; K=9 ; X=2 ; print(MinimumMail(N,K,X)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := 4; ; var K : int := 9; ; var X : int := 2; ; execute (MinimumMail(N, K, X))->display();; operation MinimumMail(n : OclAny, k : OclAny, x : OclAny) pre: true post: true activity: var m : double := ((n - 1) + ("" + ((((n - 1) * 1.0 / x)->ceil() * (n - 1) + (n * 1.0 / x)->ceil() * (k - n))))->toInteger()); ; return m;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() tele=[".","-.","--"] out="" while len(a)>0 : x=a[: 2] if x in tele : if x==tele[0]: out+="0" if x==tele[1]: out+="1" if x==tele[2]: out+="2" a=a[2 :] else : out+="0" a=a[1 :] print(out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var tele : Sequence := Sequence{"."}->union(Sequence{"-."}->union(Sequence{ "--" })) ; var out : String := "" ; while (a)->size() > 0 do ( var x : OclAny := a.subrange(1,2) ; if (tele)->includes(x) then ( if x = tele->first() then ( out := out + "0" ) else skip ; if x = tele[1+1] then ( out := out + "1" ) else skip ; if x = tele[2+1] then ( out := out + "2" ) else skip ; a := a.subrange(2+1) ) else ( out := out + "0" ; a := a->tail() )) ; execute (out)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getMin(arr,n): res=arr[0] for i in range(1,n): res=min(res,arr[i]) return res def getMax(arr,n): res=arr[0] for i in range(1,n): res=max(res,arr[i]) return res arr=[12,1234,45,67,1] n=len(arr) print("Minimum element of array:",getMin(arr,n)) print("Maximum element of array:",getMax(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{12}->union(Sequence{1234}->union(Sequence{45}->union(Sequence{67}->union(Sequence{ 1 })))) ; n := (arr)->size() ; execute ("Minimum element of array:")->display() ; execute ("Maximum element of array:")->display(); operation getMin(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var res : OclAny := arr->first() ; for i : Integer.subrange(1, n-1) do ( res := Set{res, arr[i+1]}->min()) ; return res; operation getMax(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: res := arr->first() ; for i : Integer.subrange(1, n-1) do ( res := Set{res, arr[i+1]}->max()) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkDistance(wolves,pigs): ans=0 for i in range(len(wolves)): for j in range(len(pigs)): dist=abs(wolves[i][0]-pigs[j][0])+abs(wolves[i][1]-pigs[j][1]) if dist==1 : ans+=1 break return ans row,column=map(int,input().split()) mat=[] pigIndex=[] wolfIndex=[] for i in range(row): rows=list(input()) mat.append(rows) for j in range(len(rows)): if rows[j]=="W" : wolfIndex.append([i,j]) elif rows[j]=="P" : pigIndex.append([i,j]) pigsEaten=checkDistance(wolfIndex,pigIndex) print(pigsEaten) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var row : OclAny := null; var column : OclAny := null; Sequence{row,column} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mat : Sequence := Sequence{} ; var pigIndex : Sequence := Sequence{} ; var wolfIndex : Sequence := Sequence{} ; for i : Integer.subrange(0, row-1) do ( var rows : Sequence := ((OclFile["System.in"]).readLine())->characters() ; execute ((rows) : mat) ; for j : Integer.subrange(0, (rows)->size()-1) do ( if rows[j+1] = "W" then ( execute ((Sequence{i}->union(Sequence{ j })) : wolfIndex) ) else (if rows[j+1] = "P" then ( execute ((Sequence{i}->union(Sequence{ j })) : pigIndex) ) else skip))) ; var pigsEaten : OclAny := checkDistance(wolfIndex, pigIndex) ; execute (pigsEaten)->display(); operation checkDistance(wolves : OclAny, pigs : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, (wolves)->size()-1) do ( for j : Integer.subrange(0, (pigs)->size()-1) do ( var dist : double := (wolves[i+1]->first() - pigs[j+1]->first())->abs() + (wolves[i+1][1+1] - pigs[j+1][1+1])->abs() ; if dist = 1 then ( ans := ans + 1 ; break ) else skip)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getMin(arr,n): return min(arr); def getMax(arr,n): return max(arr); arr=[12,1234,45,67,1] n=len(arr) print("Minimum element of array: ",getMin(arr,n)); print("Maximum element of array: ",getMax(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{12}->union(Sequence{1234}->union(Sequence{45}->union(Sequence{67}->union(Sequence{ 1 })))) ; n := (arr)->size() ; execute ("Minimum element of array: ")->display(); ; execute ("Maximum element of array: ")->display();; operation getMin(arr : OclAny, n : OclAny) pre: true post: true activity: return (arr)->min();; operation getMax(arr : OclAny, n : OclAny) pre: true post: true activity: return (arr)->max();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countHexadecimal(L,R): count=0 ; for i in range(L,R+1): if(i>=10 and i<=15): count+=1 ; elif(i>15): k=i ; while(k!=0): if(k % 16>=10): count+=1 ; k=k//16 ; return count ; if __name__=="__main__" : L=5 ; R=100 ; print(countHexadecimal(L,R)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( L := 5; R := 100; ; execute (countHexadecimal(L, R))->display(); ) else skip; operation countHexadecimal(L : OclAny, R : OclAny) pre: true post: true activity: var count : int := 0; ; for i : Integer.subrange(L, R + 1-1) do ( if (i >= 10 & i <= 15) then ( count := count + 1; ) else (if (i > 15) then ( var k : OclAny := i; ; while (k /= 0) do ( if (k mod 16 >= 10) then ( count := count + 1; ) else skip ; k := k div 16;) ) else skip)) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nextGreater(N): power_of_2=1 ; shift_count=0 ; while(True): if(((N>>shift_count)& 1)% 2==0): break ; shift_count+=1 ; power_of_2=power_of_2*2 ; return(N+power_of_2); N=11 ; print("The next number is=",nextGreater(N)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 11; ; execute ("The next number is=")->display();; operation nextGreater(N : OclAny) pre: true post: true activity: var power_of:= 1 : int := 1; ; var shift_count : int := 0; ; while (true) do ( if ((MathLib.bitwiseAnd((N /(2->pow(shift_count))), 1)) mod 2 = 0) then ( break; ) else skip ; shift_count := shift_count + 1; ; power_of:= power_of2 * 2 := power_of2 * 2;) ; return (N + power_of_2);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t,=map(int,input().split()); exec(t*'n,k=map(int,input().split());s,*a=map(int,input().split());r=0\nfor x in a:r=max(r,-s--x*100//k);s+=x\nprint(r)\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := (input().split())->collect( _x | (OclType["int"])->apply(_x) );(expr (expr (atom (name t))) * (expr (atom 'n,k=map(int,input().split());s,*a=map(int,input().split());r=0 for x in a:r=max(r,-s--x*100//k);s+=x print(r) '))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,k=map(int,input().split()) p=list(map(int,input().split())) ans=0 for j in range(1,n): x=0 if((p[j]/p[0])>(k/100)): x=((100*p[j]-k*p[0])+k-1)//k p[0]+=p[j]+x ans=ans+x print(int(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for j : Integer.subrange(1, n-1) do ( var x : int := 0 ; if (((p[j+1] / p->first())->compareTo((k / 100))) > 0) then ( x := ((100 * p[j+1] - k * p->first()) + k - 1) div k ) else skip ; p->first() := p->first() + p[j+1] + x ; ans := ans + x) ; execute (("" + ((ans)))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def solve(): n,k=map(int,input().split()) arr=list(map(int,input().split())) S=0 ans=0 for i in range(n-1): S+=arr[i] if 100*(arr[i+1]/S)<=k : continue d=(100*arr[i+1])//k-S if(100*arr[i+1])% k : d+=1 ans+=d S+=d return ans for _ in range(int(input())): print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (solve())->display()); operation solve() : OclAny pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var S : int := 0 ; var ans : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( S := S + arr[i+1] ; if (100 * (arr[i + 1+1] / S)->compareTo(k)) <= 0 then ( continue ) else skip ; var d : double := (100 * arr[i + 1+1]) div k - S ; if (100 * arr[i + 1+1]) mod k then ( d := d + 1 ) else skip ; ans := ans + d ; S := S + d) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil def main(): t=int(input()) for _ in range(t): n,percent=map(int,input().split()) prices=list(map(int,input().split())) prev=prices[0] result=0 for i in range(1,n): if prices[i]/prev>percent/100 : result=max([result,ceil(prices[i]*100/percent-prev)]) prev+=prices[i] print(result) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var percent : OclAny := null; Sequence{n,percent} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var prices : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var prev : OclAny := prices->first() ; var result : int := 0 ; for i : Integer.subrange(1, n-1) do ( if (prices[i+1] / prev->compareTo(percent / 100)) > 0 then ( result := (Sequence{result}->union(Sequence{ ceil(prices[i+1] * 100 / percent - prev) }))->max() ) else skip ; prev := prev + prices[i+1]) ; execute (result)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) arr=list(map(int,input().split())) if max(arr)-min(arr)>2*k : print(-1) else : print(min(arr)+k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if ((arr)->max() - (arr)->min()->compareTo(2 * k)) > 0 then ( execute (-1)->display() ) else ( execute ((arr)->min() + k)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() k=int(input()) if len(set(s))>=k : ans=0 elif len(s)>=k : ans=k-len(set(s)) else : ans='impossible' print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if ((Set{}->union((s)))->size()->compareTo(k)) >= 0 then ( var ans : int := 0 ) else (if ((s)->size()->compareTo(k)) >= 0 then ( ans := k - (Set{}->union((s)))->size() ) else ( ans := 'impossible' ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() n=len(s) i=0 ans="" while(isize() ; var i : int := 0 ; var ans : String := "" ; while ((i->compareTo(n)) < 0) do ( if s[i+1] = '.' then ( ans := ans + '0' ; i := i + 1 ) else ( if s[i + 1+1] = '.' then ( ans := ans + '1' ) else ( ans := ans + '2' ) ; i := i + 2 )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def input_int_list(): return list(map(lambda v : int(v),input().split(' '))) first_line=input() qty=int(first_line) def is_no_conflict(max_price,prices): for price in prices : if abs(price-max_price)>diff : return False return True results=[] for line in range(0,qty): [qty,diff]=input_int_list() prices=input_int_list() prices.sort() if prices[len(prices)-1]-prices[0]>=(diff*2)+1 : results.append('-1') continue max_price=prices[0]+diff for price in prices : if abs(price-max_price)<=diff and is_no_conflict(max(price,max_price),prices): max_price=max(price,max_price) else : max_price=min(price,max_price) results.append(str(max_price)) print('\n'.join(results)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var first_line : String := (OclFile["System.in"]).readLine() ; var qty : int := ("" + ((first_line)))->toInteger() ; skip ; var results : Sequence := Sequence{} ; for line : Integer.subrange(0, qty-1) do ( ; Sequence{qty}->union(Sequence{ diff }) := input_int_list() ; prices := input_int_list() ; prices := prices->sort() ; if (prices[(prices)->size() - 1+1] - prices->first()->compareTo((diff * 2) + 1)) >= 0 then ( execute (('-1') : results) ; continue ) else skip ; max_price := prices->first() + diff ; for price : prices do ( if ((price - max_price)->abs()->compareTo(diff)) <= 0 & is_no_conflict(Set{price, max_price}->max(), prices) then ( max_price := Set{price, max_price}->max() ) else ( max_price := Set{price, max_price}->min() )) ; execute ((("" + ((max_price)))) : results)) ; execute (StringLib.sumStringsWithSeparator((results), ' '))->display(); operation input_int_list() : OclAny pre: true post: true activity: return ((input().split(' '))->collect( _x | (lambda v : OclAny in (("" + ((v)))->toInteger()))->apply(_x) )); operation is_no_conflict(max_price : OclAny, prices : OclAny) : OclAny pre: true post: true activity: for price : prices do ( if ((price - max_price)->abs()->compareTo(diff)) > 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) def out(case,n,k): temp=0 bool=False temp=min(case)+k for i in range(len(case)): if abs(temp-case[i])>k : bool=True print("-1") break if bool==False : print(temp) for i in range(num): n,k=map(int,input().split(" ")) case=list(map(int,input().split(" "))) out(case,n,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; for i : Integer.subrange(0, num-1) do ( Sequence{n,k} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; case := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; out(case, n, k)); operation out(case : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var temp : int := 0 ; var OclType["boolean"] : boolean := false ; temp := (case)->min() + k ; for i : Integer.subrange(0, (case)->size()-1) do ( if ((temp - case[i+1])->abs()->compareTo(k)) > 0 then ( OclType["boolean"] := true ; execute ("-1")->display() ; break ) else skip) ; if OclType["boolean"] = false then ( execute (temp)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- rows,cols=map(int,input().split()) grid=[] dirs=[(1,0),(0,-1),(0,1),(-1,0)] for _ in range(rows): grid.append(input()) res=0 visited=set() for i in range(rows): for j in range(cols): if grid[i][j]=='W' : for x,y in dirs : x+=i y+=j if 0<=xcollect( _x | (OclType["int"])->apply(_x) ) ; var grid : Sequence := Sequence{} ; var dirs : Sequence := Sequence{Sequence{1, 0}}->union(Sequence{Sequence{0, -1}}->union(Sequence{Sequence{0, 1}}->union(Sequence{ Sequence{-1, 0} }))) ; for _anon : Integer.subrange(0, rows-1) do ( execute (((OclFile["System.in"]).readLine()) : grid)) ; var res : int := 0 ; var visited : Set := Set{}->union(()) ; for i : Integer.subrange(0, rows-1) do ( for j : Integer.subrange(0, cols-1) do ( if grid[i+1][j+1] = 'W' then ( for _tuple : dirs do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); x := x + i ; y := y + j ; if 0 <= x & (x < rows) & 0 <= y & (y < cols) & grid[x+1][y+1] = 'P' & (visited)->excludes(Sequence{x, y}) then ( res := res + 1 ; execute ((Sequence{x, y}) : visited) ; break ) else skip) ) else skip)) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math num_of_queries=eval(input()) list_input=[] new_price=0 for i in range(num_of_queries): input1=list(map(lambda x : eval(x),input().split(" "))) input2=list(map(lambda x : eval(x),input().split(" "))) list_input.append({'n' : input1[0],'k' : input1[1],'prices' : input2}) minimum=min(list_input[i]['prices']) maximum=max(list_input[i]['prices']) new_price=minimum+list_input[i]['k'] for j in range(minimum+list_input[i]['k'],0,-1): if math.fabs(new_price-maximum)>list_input[i]['k']: print(-1) break elif math.fabs(maximum-new_price)<=list_input[i]['k']and math.fabs(minimum-new_price)<=list_input[i]['k']: print(new_price) break else : new_price-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var num_of_queries : OclAny := (OclFile["System.in"]).readLine() ; var list_input : Sequence := Sequence{} ; var new_price : int := 0 ; for i : Integer.subrange(0, num_of_queries-1) do ( var input1 : Sequence := ((input().split(" "))->collect( _x | (lambda x : OclAny in (x))->apply(_x) )) ; var input2 : Sequence := ((input().split(" "))->collect( _x | (lambda x : OclAny in (x))->apply(_x) )) ; execute ((Map{ 'n' |-> input1->first() }->union(Map{ 'k' |-> input1[1+1] }->union(Map{ 'prices' |-> input2 }))) : list_input) ; var minimum : OclAny := (list_input[i+1]->at('prices'))->min() ; var maximum : OclAny := (list_input[i+1]->at('prices'))->max() ; new_price := minimum + list_input[i+1]->at('k') ; for j : Integer.subrange(0 + 1, minimum + list_input[i+1]->at('k'))->reverse() do ( if ((new_price - maximum)->abs()->compareTo(list_input[i+1]->at('k'))) > 0 then ( execute (-1)->display() ; break ) else (if ((maximum - new_price)->abs()->compareTo(list_input[i+1]->at('k'))) <= 0 & ((minimum - new_price)->abs()->compareTo(list_input[i+1]->at('k'))) <= 0 then ( execute (new_price)->display() ; break ) else ( new_price := new_price - 1 ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,k=map(int,input().split()) l=list(map(int,input().split())) a=min(l) if((max(l)-(a+k))<=k): print(a+k) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := (l)->min() ; if ((((l)->max() - (a + k))->compareTo(k)) <= 0) then ( execute (a + k)->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==1 : print(1) else : print(n*((n-1)*2)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (1)->display() ) else ( execute (n * ((n - 1) * 2) + 1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- z=[1,4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76,80,84,88,92,96,100,104,108,112,116,120,124,128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,208,212,216,220,224,228,232,236,240,244,248,252,256,260,264,268,272,276,280,284,288,292,296,300,304,308,312,316,320,324,328,332,336,340,344,348,352,356,360,364,368,372,376,380,384,388,392,396,400] n=int(input()) count=0 for i in range(n): count+=z[i] print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var z : Sequence := Sequence{1}->union(Sequence{4}->union(Sequence{8}->union(Sequence{12}->union(Sequence{16}->union(Sequence{20}->union(Sequence{24}->union(Sequence{28}->union(Sequence{32}->union(Sequence{36}->union(Sequence{40}->union(Sequence{44}->union(Sequence{48}->union(Sequence{52}->union(Sequence{56}->union(Sequence{60}->union(Sequence{64}->union(Sequence{68}->union(Sequence{72}->union(Sequence{76}->union(Sequence{80}->union(Sequence{84}->union(Sequence{88}->union(Sequence{92}->union(Sequence{96}->union(Sequence{100}->union(Sequence{104}->union(Sequence{108}->union(Sequence{112}->union(Sequence{116}->union(Sequence{120}->union(Sequence{124}->union(Sequence{128}->union(Sequence{132}->union(Sequence{136}->union(Sequence{140}->union(Sequence{144}->union(Sequence{148}->union(Sequence{152}->union(Sequence{156}->union(Sequence{160}->union(Sequence{164}->union(Sequence{168}->union(Sequence{172}->union(Sequence{176}->union(Sequence{180}->union(Sequence{184}->union(Sequence{188}->union(Sequence{192}->union(Sequence{196}->union(Sequence{200}->union(Sequence{204}->union(Sequence{208}->union(Sequence{212}->union(Sequence{216}->union(Sequence{220}->union(Sequence{224}->union(Sequence{228}->union(Sequence{232}->union(Sequence{236}->union(Sequence{240}->union(Sequence{244}->union(Sequence{248}->union(Sequence{252}->union(Sequence{256}->union(Sequence{260}->union(Sequence{264}->union(Sequence{268}->union(Sequence{272}->union(Sequence{276}->union(Sequence{280}->union(Sequence{284}->union(Sequence{288}->union(Sequence{292}->union(Sequence{296}->union(Sequence{300}->union(Sequence{304}->union(Sequence{308}->union(Sequence{312}->union(Sequence{316}->union(Sequence{320}->union(Sequence{324}->union(Sequence{328}->union(Sequence{332}->union(Sequence{336}->union(Sequence{340}->union(Sequence{344}->union(Sequence{348}->union(Sequence{352}->union(Sequence{356}->union(Sequence{360}->union(Sequence{364}->union(Sequence{368}->union(Sequence{372}->union(Sequence{376}->union(Sequence{380}->union(Sequence{384}->union(Sequence{388}->union(Sequence{392}->union(Sequence{396}->union(Sequence{ 400 })))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( count := count + z[i+1]) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(n**2+(n-1)**2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((n)->pow(2) + ((n - 1))->pow(2))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n<2 : print(n) else : j=1 m=1 while jtoInteger() ; if n < 2 then ( execute (n)->display() ) else ( var j : int := 1 ; var m : int := 1 ; while (j->compareTo(n)) < 0 do ( var p : int := j * 4 ; m := m + p ; j := j + 1) ; execute (m)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) alex=2*t*t-2*t+1 print(alex) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var alex : double := 2 * t * t - 2 * t + 1 ; execute (alex)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxAbsDiff(arr,n): minEle=arr[0] maxEle=arr[0] for i in range(1,n): minEle=min(minEle,arr[i]) maxEle=max(maxEle,arr[i]) return(maxEle-minEle) arr=[2,1,5,3] n=len(arr) print(maxAbsDiff(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{1}->union(Sequence{5}->union(Sequence{ 3 }))) ; n := (arr)->size() ; execute (maxAbsDiff(arr, n))->display(); operation maxAbsDiff(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var minEle : OclAny := arr->first() ; var maxEle : OclAny := arr->first() ; for i : Integer.subrange(1, n-1) do ( minEle := Set{minEle, arr[i+1]}->min() ; maxEle := Set{maxEle, arr[i+1]}->max()) ; return (maxEle - minEle); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculateCycleOperations(length): cycle_operations=0 while length>0 : length//=3 cycle_operations+=1 return cycle_operations-1 def minimumOperations(p,n): visited=[0]*(n+1) ans=0 for i in range(1,n+1): ele=p[i] if not visited[ele]: visited[ele]=1 length=1 ele=p[ele] while not visited[ele]: visited[ele]=1 length+=1 ele=p[ele] operations=calculateCycleOperations(length) num=pow(3,operations) if num!=length : return-1 ans=max(ans,operations) return ans if __name__=="__main__" : P=[-1,4,6,5,3,2,7,8,9,1] n=len(P)-1 print(minimumOperations(P,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var P : Sequence := Sequence{-1}->union(Sequence{4}->union(Sequence{6}->union(Sequence{5}->union(Sequence{3}->union(Sequence{2}->union(Sequence{7}->union(Sequence{8}->union(Sequence{9}->union(Sequence{ 1 }))))))))) ; n := (P)->size() - 1 ; execute (minimumOperations(P, n))->display() ) else skip; operation calculateCycleOperations(length : OclAny) : OclAny pre: true post: true activity: var cycle_operations : int := 0 ; while length > 0 do ( length := length div 3 ; cycle_operations := cycle_operations + 1) ; return cycle_operations - 1; operation minimumOperations(p : OclAny, n : OclAny) : OclAny pre: true post: true activity: var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var ans : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( var ele : OclAny := p[i+1] ; if not(visited[ele+1]) then ( visited[ele+1] := 1 ; length := 1 ; ele := p[ele+1] ; while not(visited[ele+1]) do ( visited[ele+1] := 1 ; length := length + 1 ; ele := p[ele+1]) ; var operations : OclAny := calculateCycleOperations(length) ; var num : double := (3)->pow(operations) ; if num /= length then ( return -1 ) else skip ; ans := Set{ans, operations}->max() ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) b=1 while True : if b*2<=n : b*=2 else : break print(b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := 1 ; while true do ( if (b * 2->compareTo(n)) <= 0 then ( b := b * 2 ) else ( break )) ; execute (b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) if 2**1<=N<2**2 : print(2**1) elif 2**2<=N<2**3 : print(2**2) elif 2**3<=N<2**4 : print(2**3) elif 2**4<=N<2**5 : print(2**4) elif 2**5<=N<2**6 : print(2**5) elif 2**6<=N<2**7 : print(2**6) elif 2**7<=N<2**8 : print(2**7) elif 2**8<=N<2**9 : print(2**8) elif 2**9<=N<2**10 : print(2**9) elif 2**10<=N<2**11 : print(2**10) elif 2**11<=N<2**12 : print(2**11) elif 2**12<=N<2**13 : print(2**12) elif 2**13<=N<2**14 : print(2**13) elif 2**14<=N<2**15 : print(2**14) elif 2**15<=N<2**16 : print(2**15) elif 2**16<=N<2**17 : print(2**16) elif 2**17<=N<2**18 : print(2**17) elif 2**18<=N<2**19 : print(2**18) elif 2**19<=N<2**20 : print(2**19) else : print(2**20) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if ((2)->pow(1)->compareTo(N)) <= 0 & (N < (2)->pow(2)) then ( execute ((2)->pow(1))->display() ) else (if ((2)->pow(2)->compareTo(N)) <= 0 & (N < (2)->pow(3)) then ( execute ((2)->pow(2))->display() ) else (if ((2)->pow(3)->compareTo(N)) <= 0 & (N < (2)->pow(4)) then ( execute ((2)->pow(3))->display() ) else (if ((2)->pow(4)->compareTo(N)) <= 0 & (N < (2)->pow(5)) then ( execute ((2)->pow(4))->display() ) else (if ((2)->pow(5)->compareTo(N)) <= 0 & (N < (2)->pow(6)) then ( execute ((2)->pow(5))->display() ) else (if ((2)->pow(6)->compareTo(N)) <= 0 & (N < (2)->pow(7)) then ( execute ((2)->pow(6))->display() ) else (if ((2)->pow(7)->compareTo(N)) <= 0 & (N < (2)->pow(8)) then ( execute ((2)->pow(7))->display() ) else (if ((2)->pow(8)->compareTo(N)) <= 0 & (N < (2)->pow(9)) then ( execute ((2)->pow(8))->display() ) else (if ((2)->pow(9)->compareTo(N)) <= 0 & (N < (2)->pow(10)) then ( execute ((2)->pow(9))->display() ) else (if ((2)->pow(10)->compareTo(N)) <= 0 & (N < (2)->pow(11)) then ( execute ((2)->pow(10))->display() ) else (if ((2)->pow(11)->compareTo(N)) <= 0 & (N < (2)->pow(12)) then ( execute ((2)->pow(11))->display() ) else (if ((2)->pow(12)->compareTo(N)) <= 0 & (N < (2)->pow(13)) then ( execute ((2)->pow(12))->display() ) else (if ((2)->pow(13)->compareTo(N)) <= 0 & (N < (2)->pow(14)) then ( execute ((2)->pow(13))->display() ) else (if ((2)->pow(14)->compareTo(N)) <= 0 & (N < (2)->pow(15)) then ( execute ((2)->pow(14))->display() ) else (if ((2)->pow(15)->compareTo(N)) <= 0 & (N < (2)->pow(16)) then ( execute ((2)->pow(15))->display() ) else (if ((2)->pow(16)->compareTo(N)) <= 0 & (N < (2)->pow(17)) then ( execute ((2)->pow(16))->display() ) else (if ((2)->pow(17)->compareTo(N)) <= 0 & (N < (2)->pow(18)) then ( execute ((2)->pow(17))->display() ) else (if ((2)->pow(18)->compareTo(N)) <= 0 & (N < (2)->pow(19)) then ( execute ((2)->pow(18))->display() ) else (if ((2)->pow(19)->compareTo(N)) <= 0 & (N < (2)->pow(20)) then ( execute ((2)->pow(19))->display() ) else ( execute ((2)->pow(20))->display() ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) grid=[input()for _ in range(n)] eaten=set() def eat(r,c,grid,eaten): dr=[-1,1,0,0] dc=[0,0,-1,1] for i in range(4): rr=r+dr[i] cc=c+dc[i] if rr<0 or cc<0 or rr>=n or cc>=m or(rr,cc)in eaten or grid[rr][cc]=='.' : continue if grid[rr][cc]=="P" : eaten.add((rr,cc)) return 1 return 0 res=0 for i in range(n): for j in range(m): if grid[i][j]=="W" : res+=eat(i,j,grid,eaten) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var grid : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var eaten : Set := Set{}->union(()) ; skip ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if grid[i+1][j+1] = "W" then ( res := res + eat(i, j, grid, eaten) ) else skip)) ; execute (res)->display(); operation eat(r : OclAny, c : OclAny, grid : OclAny, eaten : OclAny) : OclAny pre: true post: true activity: var dr : Sequence := Sequence{-1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 0 }))) ; var dc : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{ 1 }))) ; for i : Integer.subrange(0, 4-1) do ( var rr : OclAny := r + dr[i+1] ; var cc : OclAny := c + dc[i+1] ; if rr < 0 or cc < 0 or (rr->compareTo(n)) >= 0 or (cc->compareTo(m)) >= 0 or (eaten)->includes(Sequence{rr, cc}) or grid[rr+1][cc+1] = '.' then ( continue ) else skip ; if grid[rr+1][cc+1] = "P" then ( execute ((Sequence{rr, cc}) : eaten) ; return 1 ) else skip) ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import log2 print(2**int(log2(int(input())))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute ((2)->pow(("" + ((log2(("" + (((OclFile["System.in"]).readLine())))->toInteger()))))->toInteger()))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : n=int(input()) for i in range(21): s=pow(2,i) if ntoInteger() ; for i : Integer.subrange(0, 21-1) do ( var s : double := (2)->pow(i) ; if (n->compareTo(s)) < 0 then ( if i = 0 then ( execute (1)->display() ) else ( execute ((2)->pow(i - 1))->display() ) ; break ) else (if n = s then ( execute ((2)->pow(i))->display() ; break ) else skip)) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def p(x): answer=True while(x>1): if x % 2==0 : x=x//2 else : answer=False break return answer N=int(input()) for i in range(N,0,-1): if p(i)==True : print(i) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0 + 1, N)->reverse() do ( if p(i) = true then ( execute (i)->display() ; break ) else skip); operation p(x : OclAny) : OclAny pre: true post: true activity: var answer : boolean := true ; while (x > 1) do ( if x mod 2 = 0 then ( x := x div 2 ) else ( answer := false ; break )) ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def merge(arr,temp,left,mid,right): inv_count=0 i=left j=mid k=left while(i<=mid-1)and(j<=right): if arr[i]<=arr[j]: temp[k]=arr[i] k,i=k+1,i+1 else : temp[k]=arr[j] k,j=k+1,j+1 inv_count=inv_count+(mid-i) while i<=mid-1 : temp[k]=arr[i] k,i=k+1,i+1 while j<=right : temp[k]=arr[j] k,j=k+1,j+1 for i in range(left,right+1): arr[i]=temp[i] return inv_count def _mergeSort(arr,temp,left,right): inv_count=0 if right>left : mid=(right+left)//2 inv_count=_mergeSort(arr,temp,left,mid) inv_count+=_mergeSort(arr,temp,mid+1,right) inv_count+=merge(arr,temp,left,mid+1,right) return inv_count def mergeSort(arr,array_size): temp=[None]*array_size return _mergeSort(arr,temp,0,array_size-1) def minSwapToReachArr(arr,N): for i in range(0,N): if(arr[i]-1)-i>2 : return-1 numOfInversion=mergeSort(arr,N) return numOfInversion if __name__=="__main__" : arr=[1,2,5,3,4] N=len(arr) res=minSwapToReachArr(arr,N) if res==-1 : print("Not Possible") else : print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{5}->union(Sequence{3}->union(Sequence{ 4 })))) ; N := (arr)->size() ; var res : OclAny := minSwapToReachArr(arr, N) ; if res = -1 then ( execute ("Not Possible")->display() ) else ( execute (res)->display() ) ) else skip; operation merge(arr : OclAny, temp : OclAny, left : OclAny, mid : OclAny, right : OclAny) : OclAny pre: true post: true activity: var inv_count : int := 0 ; var i : OclAny := left ; var j : OclAny := mid ; var k : OclAny := left ; while ((i->compareTo(mid - 1)) <= 0) & ((j->compareTo(right)) <= 0) do ( if (arr[i+1]->compareTo(arr[j+1])) <= 0 then ( temp[k+1] := arr[i+1] ; Sequence{k,i} := Sequence{k + 1,i + 1} ) else ( temp[k+1] := arr[j+1] ; Sequence{k,j} := Sequence{k + 1,j + 1} ; inv_count := inv_count + (mid - i) )) ; while (i->compareTo(mid - 1)) <= 0 do ( temp[k+1] := arr[i+1] ; Sequence{k,i} := Sequence{k + 1,i + 1}) ; while (j->compareTo(right)) <= 0 do ( temp[k+1] := arr[j+1] ; Sequence{k,j} := Sequence{k + 1,j + 1}) ; for i : Integer.subrange(left, right + 1-1) do ( arr[i+1] := temp[i+1]) ; return inv_count; operation _mergeSort(arr : OclAny, temp : OclAny, left : OclAny, right : OclAny) : OclAny pre: true post: true activity: inv_count := 0 ; if (right->compareTo(left)) > 0 then ( mid := (right + left) div 2 ; inv_count := _mergeSort(arr, temp, left, mid) ; inv_count := inv_count + _mergeSort(arr, temp, mid + 1, right) ; inv_count := inv_count + merge(arr, temp, left, mid + 1, right) ) else skip ; return inv_count; operation mergeSort(arr : OclAny, array_size : OclAny) : OclAny pre: true post: true activity: temp := MatrixLib.elementwiseMult(Sequence{ null }, array_size) ; return _mergeSort(arr, temp, 0, array_size - 1); operation minSwapToReachArr(arr : OclAny, N : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, N-1) do ( if (arr[i+1] - 1) - i > 2 then ( return -1 ) else skip) ; var numOfInversion : OclAny := mergeSort(arr, N) ; return numOfInversion; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- worker_num=int(input()) num_director=input().split() count_director=[] for j in range(len(num_director)+1): count_director.append(int(0)) for i in num_director : count_director[int(i)-1]+=1 for out in count_director : print(out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var worker_num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var num_director : OclAny := input().split() ; var count_director : Sequence := Sequence{} ; for j : Integer.subrange(0, (num_director)->size() + 1-1) do ( execute ((("" + ((0)))->toInteger()) : count_director)) ; for i : num_director do ( count_director[("" + ((i)))->toInteger() - 1+1] := count_director[("" + ((i)))->toInteger() - 1+1] + 1) ; for out : count_director do ( execute (out)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=list(map(int,input().split())) buka={i : 0 for i in range(N)} import collections buka_count=collections.Counter(A) for i in range(1,N+1): if i in buka_count : print(buka_count[i]) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var buka : Map := Integer.subrange(0, N-1)->select(i | true)->collect(i | Map{i |-> 0})->unionAll() ; skip ; var buka_count : OclAny := .Counter(A) ; for i : Integer.subrange(1, N + 1-1) do ( if (buka_count)->includes(i) then ( execute (buka_count[i+1])->display() ) else ( execute (0)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy from test.support import _MemoryWatchdog BIG_NUM=2000000000 HUGE_NUM=99999999999999999 MOD=1000000007 EPS=0.000000001 sys.setrecursionlimit(100000) class Type(Enum): UNKOWN=0 OK=1 NOT=2 class Info : def __init__(self,arg_a,arg_b,arg_c): self.work=[arg_a,arg_b,arg_c] while True : A,B,C=map(int,input().split()) if A==0 and B==0 and C==0 : break table=[Type.UNKOWN]*((A+B+C)+1) N=int(input()) info=[] for _ in range(N): a,b,c,result=map(int,input().split()) if result==1 : table[a]=Type.OK table[b]=Type.OK table[c]=Type.OK else : info.append(Info(a,b,c)) for i in range(len(info)): count=0 tmp=-1 for k in range(3): if table[info[i].work[k]]==Type.OK : count+=1 elif table[info[i].work[k]]==Type.UNKOWN : tmp=info[i].work[k] if count!=2 or tmp==-1 : continue table[tmp]=Type.NOT for i in range(1,(A+B+C)+1): if table[i]==Type.OK : print("1") elif table[i]==Type.NOT : print("0") else : print("2") ------------------------------------------------------------ OCL File: --------- class Type { static operation newType() : Type pre: true post: Type->exists( _x | result = _x ); static attribute UNKOWN : int := 0; static attribute OK : int := 1; static attribute NOT : int := 2; } class Info { static operation newInfo() : Info pre: true post: Info->exists( _x | result = _x ); attribute work : Sequence := Sequence{arg_a}->union(Sequence{arg_b}->union(Sequence{ arg_c })); operation initialise(arg_a : OclAny,arg_b : OclAny,arg_c : OclAny) : Info pre: true post: true activity: self.work := Sequence{arg_a}->union(Sequence{arg_b}->union(Sequence{ arg_c })); return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var HUGE_NUM : int := 99999999999999999 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; sys.setrecursionlimit(100000) ; skip ; skip ; while true do ( var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{A,B,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if A = 0 & B = 0 & C = 0 then ( break ) else skip ; var table : Sequence := MatrixLib.elementwiseMult(Sequence{ (Type.newType()).initialise.UNKOWN }, ((A + B + C) + 1)) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var info : Sequence := Sequence{} ; for _anon : Integer.subrange(0, N-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var result : OclAny := null; Sequence{a,b,c,result} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if result = 1 then ( table[a+1] := (Type.newType()).initialise.OK ; table[b+1] := (Type.newType()).initialise.OK ; table[c+1] := (Type.newType()).initialise.OK ) else ( execute (((Info.newInfo()).initialise(a, b, c)) : info) )) ; for i : Integer.subrange(0, (info)->size()-1) do ( var count : int := 0 ; var tmp : int := -1 ; for k : Integer.subrange(0, 3-1) do ( if table[info[i+1].work[k+1]+1] = (Type.newType()).initialise.OK then ( count := count + 1 ) else (if table[info[i+1].work[k+1]+1] = (Type.newType()).initialise.UNKOWN then ( tmp := info[i+1].work[k+1] ) else skip)) ; if count /= 2 or tmp = -1 then ( continue ) else skip ; table[tmp+1] := (Type.newType()).initialise.NOT) ; for i : Integer.subrange(1, (A + B + C) + 1-1) do ( if table[i+1] = (Type.newType()).initialise.OK then ( execute ("1")->display() ) else (if table[i+1] = (Type.newType()).initialise.NOT then ( execute ("0")->display() ) else ( execute ("2")->display() ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import defaultdict sys.setrecursionlimit(10**7) rl=sys.stdin.readline def solve(): N=int(rl()) A=list(map(int,rl().split())) counter=defaultdict(int) for ai in A : counter[ai]+=1 for i in range(1,N+1): print(counter[i]) if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; var rl : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var N : int := ("" + ((rl())))->toInteger() ; var A : Sequence := ((rl().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var counter : OclAny := defaultdict(OclType["int"]) ; for ai : A do ( counter[ai+1] := counter[ai+1] + 1) ; for i : Integer.subrange(1, N + 1-1) do ( execute (counter[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict as dd n=int(input()) A=list(map(int,input().split())) dic=dd(lambda : 0) for a in A : dic[a]+=1 for i in range(1,n+1): print(dic[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dic : OclAny := dd(lambda $$ : OclAny in (0)) ; for a : A do ( dic[a+1] := dic[a+1] + 1) ; for i : Integer.subrange(1, n + 1-1) do ( execute (dic[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=[0]*n a=list(map(int,input().split())) for i in range(n-1): ans[a[i]-1]=ans[a[i]-1]+1 for i in ans : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n - 1-1) do ( ans[a[i+1] - 1+1] := ans[a[i+1] - 1+1] + 1) ; for i : ans do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq def SieveOfEratosthenes(max_val): prime=[True for i in range(max_val+1)] p=2 while p*p<=max_val : if(prime[p]==True): for j in range(2*p,max_val+1,p): prime[j]=False p+=1 return prime def primeSumAndProduct(arr,n,k): max_val=max(arr) prime=SieveOfEratosthenes(max_val) prime[0]=False prime[1]=False Heap=[] for i in range(n): if(prime[arr[i]]): Heap.append(arr[i]) minProduct=1 maxProduct=1 minSum=0 maxSum=0 min_k=heapq.nsmallest(k,Heap) max_k=heapq.nlargest(k,Heap) minSum=sum(min_k) maxSum=sum(max_k) for val in min_k : minProduct*=val for val in max_k : maxProduct*=val print("Sum of k-minimum prime numbers is",minSum) print("Sum of k-maximum prime numbers is",maxSum) print("Product of k-minimum prime numbers is",minProduct) print("Product of k-maximum prime numbers is",maxProduct) arr=[4,2,12,13,5,19] n=len(arr) k=3 primeSumAndProduct(arr,n,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; arr := Sequence{4}->union(Sequence{2}->union(Sequence{12}->union(Sequence{13}->union(Sequence{5}->union(Sequence{ 19 }))))) ; n := (arr)->size() ; k := 3 ; primeSumAndProduct(arr, n, k); operation SieveOfEratosthenes(max_val : OclAny) : OclAny pre: true post: true activity: var prime : Sequence := Integer.subrange(0, max_val + 1-1)->select(i | true)->collect(i | (true)) ; var p : int := 2 ; while (p * p->compareTo(max_val)) <= 0 do ( if (prime[p+1] = true) then ( for j : Integer.subrange(2 * p, max_val + 1-1)->select( $x | ($x - 2 * p) mod p = 0 ) do ( prime[j+1] := false) ) else skip ; p := p + 1) ; return prime; operation primeSumAndProduct(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: max_val := (arr)->max() ; prime := SieveOfEratosthenes(max_val) ; prime->first() := false ; prime[1+1] := false ; var Heap : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if (prime[arr[i+1]+1]) then ( execute ((arr[i+1]) : Heap) ) else skip) ; var minProduct : int := 1 ; var maxProduct : int := 1 ; var minSum : int := 0 ; var maxSum : int := 0 ; var min_k : OclAny := heapq.nsmallest(k, Heap) ; var max_k : OclAny := heapq.nlargest(k, Heap) ; minSum := (min_k)->sum() ; maxSum := (max_k)->sum() ; for val : min_k do ( minProduct := minProduct * val) ; for val : max_k do ( maxProduct := maxProduct * val) ; execute ("Sum of k-minimum prime numbers is")->display() ; execute ("Sum of k-maximum prime numbers is")->display() ; execute ("Product of k-minimum prime numbers is")->display() ; execute ("Product of k-maximum prime numbers is")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def indexOfFirstOne(arr,low,high): while(low<=high): mid=int((low+high)/2) if(arr[mid]==1 and(mid==0 or arr[mid-1]==0)): return mid elif(arr[mid]==1): high=mid-1 else : low=mid+1 return-1 ; arr=[0,0,0,0,0,0,1,1,1,1] n=len(arr) ans=indexOfFirstOne(arr,0,n-1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))))))))) ; var n : int := (arr)->size() ; var ans : OclAny := indexOfFirstOne(arr, 0, n - 1) ; execute (ans)->display(); operation indexOfFirstOne(arr : OclAny, low : OclAny, high : OclAny) : OclAny pre: true post: true activity: while ((low->compareTo(high)) <= 0) do ( var mid : int := ("" + (((low + high) / 2)))->toInteger() ; if (arr[mid+1] = 1 & (mid = 0 or arr[mid - 1+1] = 0)) then ( return mid ) else (if (arr[mid+1] = 1) then ( high := mid - 1 ) else ( low := mid + 1 ) ) ) ; return -1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for rt in range(n): s=input() if(s[0]=='Y' or s[0]=='y')and(s[1]=="e" or s[1]=='E')and(s[2]=='s' or s[2]=='S'): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for rt : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if (s->first() = 'Y' or s->first() = 'y') & (s[1+1] = "e" or s[1+1] = 'E') & (s[2+1] = 's' or s[2+1] = 'S') then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): a=input() b=a.lower() c='yes' if(b==c): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : String := (OclFile["System.in"]).readLine() ; var b : String := a->toLowerCase() ; var c : String := 'yes' ; if (b = c) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) inps=[input().lower()for _ in range(n)] print('\n'.join(['YES' if i=='yes' else 'NO' for i in inps])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var inps : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (input()->toLowerCase())) ; execute (StringLib.sumStringsWithSeparator((inps->select(i | true)->collect(i | (if i = 'yes' then 'YES' else 'NO' endif))), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): s=input() if 'yes' in s.lower(): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if (s->toLowerCase())->includes('yes') then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): s=input().strip() res=0 if s[0]in "yY" : res+=1 if s[1]in "eE" : res+=1 if s[2]in "sS" : res+=1 if res==3 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : OclAny := input()->trim() ; var res : int := 0 ; if ("yY")->characters()->includes(s->first()) then ( res := res + 1 ) else skip ; if ("eE")->characters()->includes(s[1+1]) then ( res := res + 1 ) else skip ; if ("sS")->characters()->includes(s[2+1]) then ( res := res + 1 ) else skip ; if res = 3 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : try : a,b,c=map(int,input().split()) parts=[2]*(a+b+c+1) N=int(input()) met_keep=[] for nn in range(N): i,j,k,r=map(int,input().split()) if r==1 : parts[i],parts[j],parts[k]=1,1,1 if r==0 : met_keep.append([i,j,k]) for i,j,k in met_keep : if parts[i]==1 and parts[j]==1 and parts[k]==2 : parts[k]=0 elif parts[i]==1 and parts[j]==2 and parts[k]==1 : parts[j]=0 elif parts[i]==2 and parts[j]==1 and parts[k]==1 : parts[i]=0 for i in parts[1 :]: print(i) except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( try ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var parts : Sequence := MatrixLib.elementwiseMult(Sequence{ 2 }, (a + b + c + 1)) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var met_keep : Sequence := Sequence{} ; for nn : Integer.subrange(0, N-1) do ( var i : OclAny := null; var j : OclAny := null; var k : OclAny := null; var r : OclAny := null; Sequence{i,j,k,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if r = 1 then ( var parts[i+1] : OclAny := null; var parts[j+1] : OclAny := null; var parts[k+1] : OclAny := null; Sequence{parts[i+1],parts[j+1],parts[k+1]} := Sequence{1,1,1} ) else skip ; if r = 0 then ( execute ((Sequence{i}->union(Sequence{j}->union(Sequence{ k }))) : met_keep) ) else skip) ; for _tuple : met_keep do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var k : OclAny := _tuple->at(_indx); if parts[i+1] = 1 & parts[j+1] = 1 & parts[k+1] = 2 then ( parts[k+1] := 0 ) else (if parts[i+1] = 1 & parts[j+1] = 2 & parts[k+1] = 1 then ( parts[j+1] := 0 ) else (if parts[i+1] = 2 & parts[j+1] = 1 & parts[k+1] = 1 then ( parts[i+1] := 0 ) else skip ) ) ) ; for i : parts->tail() do ( execute (i)->display())) catch (_e : OclException) do ( break) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import division import os import sys import operator import string import re import time from os.path import splitext from copy import copy from math import* from operator import* from collections import* from itertools import* from functools import* try : from do import report_working_on except ImportError : report_working_on=lambda a,b : None if len(sys.argv)>1 : fin=file(sys.argv[1],'r') fout=file(splitext(sys.argv[1])[0]+'.out','w+') else : fin=sys.stdin fout=sys.stdout def dorun(): cases=int(fin.next()) for case in xrange(cases): report_working_on(case,cases) print>>fout,'Case #%d: %s' %(1+case,solve(fin)) else : report_working_on(0,0) def solve(fin): N=int(fin.next().strip()) Lx=map(int,fin.next().split()) Px=map(int,fin.next().split()) LL=list(enumerate(Px)) LL.sort(key=lambda a :-a[1]) return ' '.join(str(a[0])for a in LL) if __name__=='__main__' : dorun() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; try ( skip) (except_clause except (test (logical_test (comparison (expr (atom (name ImportError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name report_working_on)))))))) (assign_part = (testlist_star_expr (testlist (test lambda (varargslist (vardef_parameters (vardef_parameter (name a)) , (vardef_parameter (name b)))) : (test (logical_test (comparison (expr (atom None)))))))))))))) ; if ((trailer . (name argv)))->size() > 1 then ( var fin : OclAny := file((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])), 'r') ; var fout : OclAny := file(splitext((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))->first() + '.out', 'w+') ) else ( fin := OclFile["System.in"] ; fout := OclFile["System.out"] ) ; skip ; skip ; if __name__ = '__main__' then ( dorun() ) else skip; operation dorun() pre: true post: true activity: var cases : int := ("" + ((fin.next())))->toInteger() ; (compound_stmt for (exprlist (expr (atom (name case)))) in (testlist (test (logical_test (comparison (expr (atom (name xrange)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name cases)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name report_working_on)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name case))))))) , (argument (test (logical_test (comparison (expr (atom (name cases)))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (expr (atom print)) >> (expr (atom (name fout))))))) , (test (logical_test (comparison (expr (expr (atom 'Case #%d: %s')) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) + (expr (atom (name case))))))) , (test (logical_test (comparison (expr (atom (name solve)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name fin)))))))) )))))))) )))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name report_working_on)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))))))))))))))); operation solve(fin : OclAny) : OclAny pre: true post: true activity: var N : int := ("" + ((fin.next()->trim())))->toInteger() ; var Lx : Sequence := (fin.next().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var Px : Sequence := (fin.next().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var LL : Sequence := (Integer.subrange(1, (Px)->size())->collect( _indx | Sequence{_indx-1, (Px)->at(_indx)} )) ; LL := LL->sort() ; return StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ))))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name LL)))))))), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- fin=open("A-small-attempt0.in","r") fout=open("A.out","w") numcases=int(fin.readline()) numcases+=1 for cas in xrange(1,numcases): fout.write("Case #"+str(cas)+":") n=int(fin.readline()) l=map(float,fin.readline().split()) p=map(float,fin.readline().split()) q=[p[i]/l[i]for i in xrange(n)] r=[(q[i],-i)for i in xrange(n)] r.sort() r.reverse() for i in r : fout.write(" "+str(-i[1])) fout.write("\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var fin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("A-small-attempt0.in")) ; var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("A.out")) ; var numcases : int := ("" + ((fin.readLine())))->toInteger() ; numcases := numcases + 1 ; for cas : xrange(1, numcases) do ( fout.write("Case #" + ("" + ((cas))) + ":") ; var n : int := ("" + ((fin.readLine())))->toInteger() ; var l : Sequence := (fin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ) ; var p : Sequence := (fin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ) ; var q : Sequence := xrange(n)->select(i | true)->collect(i | (p[i+1] / l[i+1])) ; var r : Sequence := xrange(n)->select(i | true)->collect(i | (Sequence{q[i+1], -i})) ; r := r->sort() ; r := r->reverse() ; for i : r do ( fout.write(" " + ("" + ((-i[1+1]))))) ; fout.write("\n")); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- testCount=int(raw_input()) for testIndex in range(testCount): ans="Case #"+str(testIndex+1)+": " n=int(raw_input()) l=[int(x)for x in raw_input().split(" ")] p=[int(x)for x in raw_input().split(" ")] a=[] for i in range(n): a+=[[i,1.0*p[i]/l[i],l[i]]] a.sort(key=lambda x :-x[1]) for i in a : ans+=str(i[0])+" " print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var testCount : int := ("" + ((raw_input())))->toInteger() ; for testIndex : Integer.subrange(0, testCount-1) do ( var ans : String := "Case #" + ("" + ((testIndex + 1))) + ": " ; var n : int := ("" + ((raw_input())))->toInteger() ; var l : Sequence := raw_input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var p : Sequence := raw_input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( a := a + Sequence{ Sequence{i}->union(Sequence{1.0 * p[i+1] / l[i+1]}->union(Sequence{ l[i+1] })) }) ; a := a->sort() ; for i : a do ( ans := ans + ("" + ((i->first()))) + " ") ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=open("data.txt",'r') g=open("data1.txt",'w') t=int(f.readline()) for i in range(1,t+1): n=int(f.readline()) l=[int(x)for x in(f.readline()).split()] p=[int(x)for x in(f.readline()).split()] result=0 m=[] for j in range(n): m.append([100-p[j],j]) m.sort() result=str(m[0][1]) for j in range(1,n): result=result+" "+str(m[j][1]) string="Case #"+str(i)+": "+str(result)+"\n" g.write(string) f.close() g.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("data.txt")) ; var g : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("data1.txt")) ; var t : int := ("" + ((f.readLine())))->toInteger() ; for i : Integer.subrange(1, t + 1-1) do ( var n : int := ("" + ((f.readLine())))->toInteger() ; var l : Sequence := (f.readLine()).split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var p : Sequence := (f.readLine()).split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var result : int := 0 ; var m : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( execute ((Sequence{100 - p[j+1]}->union(Sequence{ j })) : m)) ; m := m->sort() ; result := ("" + ((m->first()[1+1]))) ; for j : Integer.subrange(1, n-1) do ( result := result + " " + ("" + ((m[j+1][1+1])))) ; var string : String := "Case #" + ("" + ((i))) + ": " + ("" + ((result))) + "\n" ; g.write(string)) ; f.closeFile() ; g.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import sys bak=sys.stdin sys.stdin=open('input.txt') for kase in range(int(input())): print("Case #{}:".format(kase+1),end="") n=int(input()) l=input() p=input().split() p=[int(i)for i in p] s=[(100-p[i],i)for i in range(len(p))] s.sort() ans="" for i in s : ans+=' '+str(i[1]) print(ans) sys.stdin=bak input() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var bak : OclFile := OclFile["System.in"] ; OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('input.txt')) ; for kase : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (StringLib.interpolateStrings("Case #{}:", Sequence{kase + 1}))->display() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : String := (OclFile["System.in"]).readLine() ; var p : OclAny := input().split() ; p := p->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var s : Sequence := Integer.subrange(0, (p)->size()-1)->select(i | true)->collect(i | (Sequence{100 - p[i+1], i})) ; s := s->sort() ; var ans : String := "" ; for i : s do ( ans := ans + ' ' + ("" + ((i[1+1])))) ; execute (ans)->display()) ; OclFile["System.in"] := bak ; input(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=list(map(int,input().split())) ma=a[0]-1 for i in range(m-1): ma=max(ma,(a[i+1]-a[i])//2) ma=max(ma,n-a[-1]) print(ma) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ma : double := a->first() - 1 ; for i : Integer.subrange(0, m - 1-1) do ( ma := Set{ma, (a[i + 1+1] - a[i+1]) div 2}->max()) ; ma := Set{ma, n - a->last()}->max() ; execute (ma)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSmallest(arr,n): res=1 for i in range(0,n): if arr[i]<=res : res=res+arr[i] else : break return res arr1=[1,3,4,5] n1=len(arr1) print(findSmallest(arr1,n1)) arr2=[1,2,6,10,11,15] n2=len(arr2) print(findSmallest(arr2,n2)) arr3=[1,1,1,1] n3=len(arr3) print(findSmallest(arr3,n3)) arr4=[1,1,3,4] n4=len(arr4) print(findSmallest(arr4,n4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var arr1 : Sequence := Sequence{1}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 }))) ; var n1 : int := (arr1)->size() ; execute (findSmallest(arr1, n1))->display() ; var arr2 : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{6}->union(Sequence{10}->union(Sequence{11}->union(Sequence{ 15 }))))) ; var n2 : int := (arr2)->size() ; execute (findSmallest(arr2, n2))->display() ; var arr3 : Sequence := Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))) ; var n3 : int := (arr3)->size() ; execute (findSmallest(arr3, n3))->display() ; var arr4 : Sequence := Sequence{1}->union(Sequence{1}->union(Sequence{3}->union(Sequence{ 4 }))) ; var n4 : int := (arr4)->size() ; execute (findSmallest(arr4, n4))->display(); operation findSmallest(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1]->compareTo(res)) <= 0 then ( res := res + arr[i+1] ) else ( break )) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : N=input() if not N : break l=[] for i in range(N): c1,m1,s1,m2,s2,m3,s3,m4,s4=map(int,raw_input().split()) l.append(((m1+m2+m3+m4)*60+(s1+s2+s3+s4),c1)) l=sorted(l) print(l[0][1]) print(l[1][1]) print(l[-2][1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var N : String := (OclFile["System.in"]).readLine() ; if not(N = "") then ( break ) else skip ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var c1 : OclAny := null; var m1 : OclAny := null; var s1 : OclAny := null; var m2 : OclAny := null; var s2 : OclAny := null; var m3 : OclAny := null; var s3 : OclAny := null; var m4 : OclAny := null; var s4 : OclAny := null; Sequence{c1,m1,s1,m2,s2,m3,s3,m4,s4} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{(m1 + m2 + m3 + m4) * 60 + (s1 + s2 + s3 + s4), c1}) : l)) ; l := l->sort() ; execute (l->first()[1+1])->display() ; execute (l[1+1][1+1])->display() ; execute (l->front()->last()[1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import os for s in sys.stdin : N=int(s) if N==0 : break A=[] for i in range(N): lst=list(map(int,input().split())) id=lst[0] data=lst[1 :] time_sum=data[0]*60+data[1]+data[2]*60+data[3]+data[4]*60+data[5]+data[6]*60+data[7] A.append((time_sum,id)) A.sort() print(A[0][1]) print(A[1][1]) print(A[-2][1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for s : OclFile["System.in"] do ( var N : int := ("" + ((s)))->toInteger() ; if N = 0 then ( break ) else skip ; var A : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var id : OclAny := lst->first() ; var data : OclAny := lst->tail() ; var time_sum : double := data->first() * 60 + data[1+1] + data[2+1] * 60 + data[3+1] + data[4+1] * 60 + data[5+1] + data[6+1] * 60 + data[7+1] ; execute ((Sequence{time_sum, id}) : A)) ; A := A->sort() ; execute (A->first()[1+1])->display() ; execute (A[1+1][1+1])->display() ; execute (A->front()->last()[1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) if n==0 : return-1 score=[] for i in range(n): s=input().split() key=int(s[0]) sumTime=0 for j in range(1,len(s)): if j % 2==0 : sumTime+=int(s[j]) else : sumTime+=int(s[j])*60 score.append((sumTime,key)) score.sort() print(score[0][1],score[1][1],score[-2][1],sep='\n') while True : if solve()==-1 : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( if solve() = -1 then ( break ) else skip); operation solve() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( return -1 ) else skip ; var score : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var s : OclAny := input().split() ; var key : int := ("" + ((s->first())))->toInteger() ; var sumTime : int := 0 ; for j : Integer.subrange(1, (s)->size()-1) do ( if j mod 2 = 0 then ( sumTime := sumTime + ("" + ((s[j+1])))->toInteger() ) else ( sumTime := sumTime + ("" + ((s[j+1])))->toInteger() * 60 )) ; execute ((Sequence{sumTime, key}) : score)) ; score := score->sort() ; execute (score->first()[1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(5): a,b,c=[int(s)for s in input().strip().split(' ')] if a | b | c==0 : break n=int(input().strip()) rlist=[[int(s)for s in input().strip().split(' ')]for _ in range(n)] clist=[2,]*sum((a,b,c)) for success in filter(lambda r : r[3]==1,rlist): for i in success[: 3]: clist[i-1]=1 for fail in filter(lambda r : r[3]==0,rlist): plist=[clist[i-1]for i in fail[: 3]] if sorted(plist)==[1,1,2]: for i in fail[: 3]: if clist[i-1]==2 : clist[i-1]=0 break [print(r)for r in clist] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, 5-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := input()->trim().split(' ')->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; if MathLib.bitwiseOr(MathLib.bitwiseOr(a, b), c) = 0 then ( break ) else skip ; var n : int := ("" + ((input()->trim())))->toInteger() ; var rlist : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (input()->trim().split(' ')->select(s | true)->collect(s | (("" + ((s)))->toInteger())))) ; var clist : Sequence := MatrixLib.elementwiseMult(Sequence{ 2 }, (Sequence{a, b, c})->sum()) ; for success : (rlist)->select( _x | (lambda r : OclAny in (r[3+1] = 1))->apply(_x) = true ) do ( for i : success.subrange(1,3) do ( clist[i - 1+1] := 1 ; for fail : (rlist)->select( _x | (lambda r : OclAny in (r[3+1] = 0))->apply(_x) = true ) do ( var plist : Sequence := fail.subrange(1,3)->select(i | true)->collect(i | (clist[i - 1+1])) ; if plist->sort() = Sequence{1}->union(Sequence{1}->union(Sequence{ 2 })) then ( for i : fail.subrange(1,3) do ( if clist[i - 1+1] = 2 then ( clist[i - 1+1] := 0 ; break ) else skip) ) else skip)))) ; ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,bisect PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") while True : n=int(input()) if n==0 : break teams=[] for _ in range(n): team,m1,s1,m2,s2,m3,s3,m4,s4=[int(__)for __ in input().split()] time=60*m1+s1+60*m2+s2+60*m3+s3+60*m4+s4 teams.append([team,time]) teams=sorted(teams,key=lambda x :(x[1],x[0])) print(teams[0][0]) print(teams[1][0]) print(teams[-2][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var teams : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var team : OclAny := null; var m1 : OclAny := null; var s1 : OclAny := null; var m2 : OclAny := null; var s2 : OclAny := null; var m3 : OclAny := null; var s3 : OclAny := null; var m4 : OclAny := null; var s4 : OclAny := null; Sequence{team,m1,s1,m2,s2,m3,s3,m4,s4} := input().split()->select(__ | true)->collect(__ | (("" + ((__)))->toInteger())) ; var time : double := 60 * m1 + s1 + 60 * m2 + s2 + 60 * m3 + s3 + 60 * m4 + s4 ; execute ((Sequence{team}->union(Sequence{ time })) : teams)) ; teams := teams->sortedBy($x | (lambda x : OclAny in (Sequence{x[1+1], x->first()}))->apply($x)) ; execute (teams->first()->first())->display() ; execute (teams[1+1]->first())->display() ; execute (teams->front()->last()->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import operator while True : n=int(input()) if n==0 : break rst={} for _ in range(n): [id,m1,s1,m2,s2,m3,s3,m4,s4]=list(map(int,input().strip().split())) rst[id]=m1*60+s1+m2*60+s2+m3*60+s3+m4*60+s4 r=sorted(rst.items(),key=operator.itemgetter(1)) print(r[0][0]) print(r[1][0]) print(r[-2][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { suite`nestedAttributeDefinitions operation initialise() pre: true post: true activity: skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var rst : OclAny := Set{} ; for _anon : Integer.subrange(0, n-1) do (suite)) ; Sequence{id}->union(Sequence{m1}->union(Sequence{s1}->union(Sequence{m2}->union(Sequence{s2}->union(Sequence{m3}->union(Sequence{s3}->union(Sequence{m4}->union(Sequence{ s4 })))))))) := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minSet(nums): A=[] nums.sort() sum=0 for i in range(0,len(nums)): sum+=nums[i] temp=0 for i in range(len(nums)-1,-1,-1): if(temp>sum/2): break A.append(nums[i]) temp+=nums[i] for i in range(0,len(A)): print(A[i],end=' ') vec=[7,6,13,13,12,11] minSet(vec); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var vec : Sequence := Sequence{7}->union(Sequence{6}->union(Sequence{13}->union(Sequence{13}->union(Sequence{12}->union(Sequence{ 11 }))))) ; minSet(vec);; operation minSet(nums : OclAny) pre: true post: true activity: var A : Sequence := Sequence{} ; nums := nums->sort() ; var sum : int := 0 ; for i : Integer.subrange(0, (nums)->size()-1) do ( sum := sum + nums[i+1]) ; var temp : int := 0 ; for i : Integer.subrange(-1 + 1, (nums)->size() - 1)->reverse() do ( if ((temp->compareTo(sum / 2)) > 0) then ( break ) else skip ; execute ((nums[i+1]) : A) ; temp := temp + nums[i+1]) ; for i : Integer.subrange(0, (A)->size()-1) do ( execute (A[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l,r,x,y,k=map(int,input().split()) for i in range(x,y+1): if l<=i*k and i*k<=r : print('YES') break else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; var x : OclAny := null; var y : OclAny := null; var k : OclAny := null; Sequence{l,r,x,y,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name y))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name l)))) <= (comparison (expr (expr (atom (name i))) * (expr (atom (name k))))))) and (logical_test (comparison (comparison (expr (expr (atom (name i))) * (expr (atom (name k))))) <= (comparison (expr (atom (name r)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main_function(): l,r,x,y,k=[int(i)for i in input().split(" ")] remainder=r % k r-=remainder remainder=l % k if not remainder==0 : l+=k-remainder max_val=r/x min_val=l/y if r=k>=min_val : print("YES") else : print("NO") main_function() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main_function(); operation main_function() pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; var x : OclAny := null; var y : OclAny := null; var k : OclAny := null; Sequence{l,r,x,y,k} := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var remainder : int := r mod k ; r := r - remainder ; remainder := l mod k ; if not(remainder = 0) then ( l := l + k - remainder ) else skip ; var max_val : double := r / x ; var min_val : double := l / y ; if (r->compareTo(l)) < 0 then ( execute ("NO")->display() ) else ( max_val := r / x ; min_val := l / y ; if (max_val->compareTo(k)) >= 0 & (k >= min_val) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l,r,x,y,k=map(int,input().split()) for i in range(x,y+1): if l<=i*k<=r : print("YES") break else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; var x : OclAny := null; var y : OclAny := null; var k : OclAny := null; Sequence{l,r,x,y,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name y))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (comparison (expr (atom (name l)))) <= (comparison (expr (expr (atom (name i))) * (expr (atom (name k)))))) <= (comparison (expr (atom (name r))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l,r,x,y,k=map(int,input().split()) for i in range(x,y+1): if i*k<=r and i*k>=l : print('YES') break else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; var x : OclAny := null; var y : OclAny := null; var k : OclAny := null; Sequence{l,r,x,y,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name y))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (expr (atom (name i))) * (expr (atom (name k))))) <= (comparison (expr (atom (name r)))))) and (logical_test (comparison (comparison (expr (expr (atom (name i))) * (expr (atom (name k))))) >= (comparison (expr (atom (name l)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'YES'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NO'))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfDigitsFrom1ToN(n): result=0 for x in range(1,n+1): result=result+sumOfDigits(x) return result def sumOfDigits(x): sum=0 while(x!=0): sum=sum+x % 10 x=x//10 return sum n=328 print("Sum of digits in numbers from 1 to",n,"is",sumOfDigitsFrom1ToN(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 328 ; execute ("Sum of digits in numbers from 1 to")->display(); operation sumOfDigitsFrom1ToN(n : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; for x : Integer.subrange(1, n + 1-1) do ( result := result + sumOfDigits(x)) ; return result; operation sumOfDigits(x : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; while (x /= 0) do ( sum := sum + x mod 10 ; x := x div 10) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline l,r,x,y,k=map(int,input().split()) if x*k>r or y*kcollect( _x | (OclType["int"])->apply(_x) ) ; if (x * k->compareTo(r)) > 0 or (y * k->compareTo(l)) < 0 then ( execute ("NO")->display() ) else ( (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name y))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (comparison (expr (atom (name l)))) <= (comparison (expr (expr (atom (name i))) * (expr (atom (name k)))))) <= (comparison (expr (atom (name r))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) ))))))))))))))) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countTransformation(a,b): n=len(a) m=len(b) if m==0 : return 1 dp=[[0]*(n)for _ in range(m)] for i in range(m): for j in range(i,n): if i==0 : if j==0 : if a[j]==b[i]: dp[i][j]=1 else : dp[i][j]=0 elif a[j]==b[i]: dp[i][j]=dp[i][j-1]+1 else : dp[i][j]=dp[i][j-1] else : if a[j]==b[i]: dp[i][j]=(dp[i][j-1]+dp[i-1][j-1]) else : dp[i][j]=dp[i][j-1] return dp[m-1][n-1] if __name__=="__main__" : a="abcccdf" b="abccdf" print(countTransformation(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := "abcccdf" ; b := "abccdf" ; execute (countTransformation(a, b))->display() ) else skip; operation countTransformation(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var n : int := (a)->size() ; var m : int := (b)->size() ; if m = 0 then ( return 1 ) else skip ; var dp : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (n)))) ; for i : Integer.subrange(0, m-1) do ( for j : Integer.subrange(i, n-1) do ( if i = 0 then ( if j = 0 then ( if a[j+1] = b[i+1] then ( dp[i+1][j+1] := 1 ) else ( dp[i+1][j+1] := 0 ) ) else (if a[j+1] = b[i+1] then ( dp[i+1][j+1] := dp[i+1][j - 1+1] + 1 ) else ( dp[i+1][j+1] := dp[i+1][j - 1+1] ) ) ) else ( if a[j+1] = b[i+1] then ( dp[i+1][j+1] := (dp[i+1][j - 1+1] + dp[i - 1+1][j - 1+1]) ) else ( dp[i+1][j+1] := dp[i+1][j - 1+1] ) ))) ; return dp[m - 1+1][n - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : supply,motor,cable=(int(x)for x in input().split()) if supply==0 and motor==0 : break checknum=int(input()) reslist=[2]*(supply+motor+cable) stack=[] for i in range(checknum): no1,no2,no3,result=(int(x)-1 for x in input().split()) result+=1 if result==1 : reslist[no1],reslist[no2],reslist[no3]=1,1,1 else : stack.append((no1,no2,no3)) for i in range(len(stack)): t=stack[i] no1,no2,no3=t[0],t[1],t[2] if reslist[no1]==1 and reslist[no2]==1 : reslist[no3]=0 elif reslist[no3]==1 and reslist[no2]==1 : reslist[no1]=0 elif reslist[no3]==1 and reslist[no1]==1 : reslist[no2]=0 for i in range(len(reslist)): print(reslist[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var supply : OclAny := null; var motor : OclAny := null; var cable : OclAny := null; Sequence{supply,motor,cable} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; if supply = 0 & motor = 0 then ( break ) else skip ; var checknum : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var reslist : Sequence := MatrixLib.elementwiseMult(Sequence{ 2 }, (supply + motor + cable)) ; var stack : Sequence := Sequence{} ; for i : Integer.subrange(0, checknum-1) do ( var no1 : OclAny := null; var no2 : OclAny := null; var no3 : OclAny := null; var result : OclAny := null; Sequence{no1,no2,no3,result} := Sequence{(testlist_comp (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) - (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; result := result + 1 ; if result = 1 then ( var reslist[no1+1] : OclAny := null; var reslist[no2+1] : OclAny := null; var reslist[no3+1] : OclAny := null; Sequence{reslist[no1+1],reslist[no2+1],reslist[no3+1]} := Sequence{1,1,1} ) else ( execute ((Sequence{no1, no2, no3}) : stack) )) ; for i : Integer.subrange(0, (stack)->size()-1) do ( var t : OclAny := stack[i+1] ; var no1 : OclAny := null; var no2 : OclAny := null; var no3 : OclAny := null; Sequence{no1,no2,no3} := Sequence{t->first(),t[1+1],t[2+1]} ; if reslist[no1+1] = 1 & reslist[no2+1] = 1 then ( reslist[no3+1] := 0 ) else (if reslist[no3+1] = 1 & reslist[no2+1] = 1 then ( reslist[no1+1] := 0 ) else (if reslist[no3+1] = 1 & reslist[no1+1] = 1 then ( reslist[no2+1] := 0 ) else skip ) ) ) ; for i : Integer.subrange(0, (reslist)->size()-1) do ( execute (reslist[i+1])->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline g=[input()[:-1]for _ in range(int(input()))] while 1 : w=[] c=0 while g : a=g.pop() d=[] for i in range(len(g)): for j in range(len(g[i])): b=g[i][j] if b in a : x=a.index(b) a=(a[: x]if x>j else g[i][: j])+(a[x :]if(len(a)-x)>(len(g[i])-j)else g[i][j :]) c+=1 break else : d.append(g[i]) g=d.copy() w.append(a) g=w[: :-1] if c==0 : break print(''.join(w)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var g : Sequence := Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1)->select(_anon | true)->collect(_anon | (input()->front())) ; while 1 do ( var w : Sequence := Sequence{} ; var c : int := 0 ; while g do ( var a : OclAny := g->last() ; g := g->front() ; var d : Sequence := Sequence{} ; for i : Integer.subrange(0, (g)->size()-1) do ((compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name b)))) in (comparison (expr (atom (name a))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name a)) (trailer . (name index) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name a)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name x)))))))) ]))))) if (logical_test (comparison (comparison (expr (atom (name x)))) > (comparison (expr (atom (name j)))))) else (test (logical_test (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) ))) + (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))) :)) ]))))) if (logical_test (comparison (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))) - (expr (atom (name x)))))))) )))) > (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))) - (expr (atom (name j)))))))) )))))) else (test (logical_test (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))) :)) ])))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))))))))))))))) ; g := d->copy() ; execute ((a) : w)) ; g := w(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; if c = 0 then ( break ) else skip) ; execute (StringLib.sumStringsWithSeparator((w), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from typing import List from string import ascii_lowercase def to_idx(char : str)->int : return ord(char)-ord('a') def solve(n : int,genomes : List[str])->str : goto=[-1]*26 for g in genomes : for curr,nxt in zip(g,g[1 :]): goto[to_idx(curr)]=to_idx(nxt) sources=set([to_idx(g[0])for g in genomes if to_idx(g[0])not in goto]) ans=[] for source in sources : ptr=source ans.append(ascii_lowercase[ptr]) while goto[ptr]!=-1 : ptr=goto[ptr] ans.append(ascii_lowercase[ptr]) return ''.join(ans) n=int(input()) genomes=[input()for _ in range(n)] print(solve(n,genomes)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var genomes : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; execute (solve(n, genomes))->display(); operation to_idx(char : String) : int pre: true post: true activity: return (char)->char2byte() - ('a')->char2byte(); operation solve(n : int, genomes : List[OclType["String"]+1]) : String pre: true post: true activity: var goto : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, 26) ; for g : genomes do ( for _tuple : Integer.subrange(1, g->size())->collect( _indx | Sequence{g->at(_indx), g->tail()->at(_indx)} ) do (var _indx : int := 1; var curr : OclAny := _tuple->at(_indx); _indx := _indx + 1; var nxt : OclAny := _tuple->at(_indx); goto[to_idx(curr)+1] := to_idx(nxt))) ; var sources : Set := Set{}->union((genomes->select(g | (goto)->excludes(to_idx(g->first())))->collect(g | (to_idx(g->first()))))) ; var ans : Sequence := Sequence{} ; for source : sources do ( var ptr : OclAny := source ; execute ((ascii_lowercase[ptr+1]) : ans) ; while goto[ptr+1] /= -1 do ( ptr := goto[ptr+1] ; execute ((ascii_lowercase[ptr+1]) : ans))) ; return StringLib.sumStringsWithSeparator((ans), ''); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def alternative_input(): reads=[] n=int(input()) for i in range(n): read=input() flag=0 for num in range(len(reads)): if can_be_merged(reads[num],read): reads[num]=merge(reads[num],read) flag+=1 if flag==0 : reads.append(read) if flag>1 : reads=contigs_merger(reads) return reads def contigs_merger(reads): i,j=0,1 while idisplay(); operation alternative_input() : OclAny pre: true post: true activity: var reads : Sequence := Sequence{} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var read : String := (OclFile["System.in"]).readLine() ; var flag : int := 0 ; for num : Integer.subrange(0, (reads)->size()-1) do ( if can_be_merged(reads[num+1], read) then ( reads[num+1] := merge(reads[num+1], read) ; flag := flag + 1 ) else skip) ; if flag = 0 then ( execute ((read) : reads) ) else skip ; if flag > 1 then ( reads := contigs_merger(reads) ) else skip) ; return reads; operation contigs_merger(reads : OclAny) : OclAny pre: true post: true activity: var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,1} ; while (i->compareTo((reads)->size())) < 0 do ( while (j->compareTo((reads)->size())) < 0 do ( if can_be_merged(reads[i+1], reads[j+1]) then ( reads[i+1] := merge(reads[i+1], reads[j+1]) ; execute (reads[j+1])->isDeleted() ) else skip ; var j : OclAny := j + 1) ; var i : OclAny := i + 1 ; j := i + 1) ; return reads; operation can_be_merged(string1 : OclAny, string2 : OclAny) : OclAny pre: true post: true activity: i := string1->indexOf(string2->first()) - 1 ; j := string2->indexOf(string1->first()) - 1 ; return not((i = -1 & j = -1)); operation merge(string1 : OclAny, string2 : OclAny) : OclAny pre: true post: true activity: i := string1->indexOf(string2->first()) - 1 ; j := string2->indexOf(string1->first()) - 1 ; if (string2)->includes(string1) then ( return string2 ) else (if (string1)->includes(string2) then ( return string1 ) else (if i = -1 then ( return string2 + string1.subrange(string1->indexOf(string2->last()) - 1 + 1+1) ) else (if j = -1 then ( return string1 + string2.subrange(string2->indexOf(string1->last()) - 1 + 1+1) ) else skip ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_string_order(order,endings): result="" for ending in endings : current=ending result+=current while order[current]is not None : result+=order[current] current=order[current] return str(result[: :-1]) def genome(inputs): current_inputs=list(map(str,inputs.split("\n"))) genomes=list() closed=set() free=set() size=int(current_inputs[0]) for i in range(size): genomes.append(current_inputs[i+1]) genomes_order={} for genome_value in genomes : if genome_value[0]not in genomes_order : genomes_order[genome_value[0]]=None if genome_value[0]not in closed : free.add(genome_value[0]) for i in range(1,len(genome_value)): if genome_value[i]not in closed : free.add(genome_value[i]) if genome_value[i-1]not in closed : closed.add(genome_value[i-1]) free.discard(genome_value[i-1]) genomes_order[genome_value[i]]=genome_value[i-1] return get_string_order(genomes_order,free) inputs=input() for _ in range(int(inputs)): inputs+="\n"+input() print(genome(inputs)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; inputs := (OclFile["System.in"]).readLine() ; for _anon : Integer.subrange(0, ("" + ((inputs)))->toInteger()-1) do ( inputs := inputs + "\n" + (OclFile["System.in"]).readLine()) ; execute (genome(inputs))->display(); operation get_string_order(order : OclAny, endings : OclAny) : OclAny pre: true post: true activity: var result : String := "" ; for ending : endings do ( var current : OclAny := ending ; result := result + current ; while not(order[current+1] <>= null) do ( result := result + order[current+1] ; current := order[current+1])) ; return ("" + ((result(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))))); operation genome(inputs : OclAny) : OclAny pre: true post: true activity: var current_inputs : Sequence := ((inputs.split("\n"))->collect( _x | (OclType["String"])->apply(_x) )) ; var genomes : Sequence := () ; var closed : Set := Set{}->union(()) ; var free : Set := Set{}->union(()) ; var size : int := ("" + ((current_inputs->first())))->toInteger() ; for i : Integer.subrange(0, size-1) do ( execute ((current_inputs[i + 1+1]) : genomes)) ; var genomes_order : OclAny := Set{} ; for genome_value : genomes do ( if (genomes_order)->excludes(genome_value->first()) then ( genomes_order[genome_value->first()+1] := null ; if (closed)->excludes(genome_value->first()) then ( execute ((genome_value->first()) : free) ) else skip ) else skip ; for i : Integer.subrange(1, (genome_value)->size()-1) do ( if (closed)->excludes(genome_value[i+1]) then ( execute ((genome_value[i+1]) : free) ) else skip ; if (closed)->excludes(genome_value[i - 1+1]) then ( execute ((genome_value[i - 1+1]) : closed) ; execute ((genome_value[i - 1+1]) /: free) ) else skip ; genomes_order[genome_value[i+1]+1] := genome_value[i - 1+1])) ; return get_string_order(genomes_order, free); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- W,H=map(int,input().split()) N=int(input()) P=list(map(int,input().split())) ans=x=y=0 for p in P : if p==0 : x+=1 else : y+=1 if xcollect( _x | (OclType["int"])->apply(_x) ) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var P : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; ans := ans(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name y)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for p : P do ( if p = 0 then ( x := x + 1 ) else ( y := y + 1 ) ; if (x->compareTo(W - 1)) < 0 then ( if x = y then ( ans := ans + 1 ) else skip ) else (if x = W - 1 then ( skip ) else (if (x->compareTo(W + H - 2)) < 0 then ( if x = y + 2 then ( ans := ans + 1 ) else skip ) else (if x = W + H - 2 then ( skip ) else ( if x = y + 4 then ( ans := ans + 1 ) else skip ) ) ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- w,h=map(int,input().split()) n=int(input()) p=list(map(int,input().split())) u=m=cnt=0 for i in range(n): if p[i]==0 : u+=1 else : m+=1 if u<=w-2 : if u==m : cnt+=1 elif w<=u<=w+h-3 : if u==m+2 : cnt+=1 elif h+h-1<=u : if u==m+4 : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; u := u(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name m)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cnt)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for i : Integer.subrange(0, n-1) do ( if p[i+1] = 0 then ( u := u + 1 ) else ( m := m + 1 ) ; if (u->compareTo(w - 2)) <= 0 then ( if u = m then ( cnt := cnt + 1 ) else skip ) else (if (w->compareTo(u)) <= 0 & (u <= w + h - 3) then ( if u = m + 2 then ( cnt := cnt + 1 ) else skip ) else (if (h + h - 1->compareTo(u)) <= 0 then ( if u = m + 4 then ( cnt := cnt + 1 ) else skip ) else skip ) ) ) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- pos=[[0,0],[1,0]] way=[[0,1],[0,1]] ans=0 w,h=map(int,input().split()) n=int(input()) li=list(map(int,input().split())) for p in li : ni=pos[p][0]+way[p][0] nj=pos[p][1]+way[p][1] if p==0 : if nj>=w or ni>=h : way[p][0],way[p][1]=way[p][1],-way[p][0] ni=pos[p][0]+way[p][0] nj=pos[p][1]+way[p][1] else : if nj>=w-1 or ni>=h-1 : way[p][0],way[p][1]=way[p][1],-way[p][0] ni=pos[p][0]+way[p][0] nj=pos[p][1]+way[p][1] pos[p][0]=ni pos[p][1]=nj if abs(pos[0][0]-pos[1][0])+abs(pos[0][1]-pos[1][1])==1 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var pos : Sequence := Sequence{Sequence{0}->union(Sequence{ 0 })}->union(Sequence{ Sequence{1}->union(Sequence{ 0 }) }) ; var way : Sequence := Sequence{Sequence{0}->union(Sequence{ 1 })}->union(Sequence{ Sequence{0}->union(Sequence{ 1 }) }) ; var ans : int := 0 ; var w : OclAny := null; var h : OclAny := null; Sequence{w,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var li : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for p : li do ( var ni : OclAny := pos[p+1]->first() + way[p+1]->first() ; var nj : OclAny := pos[p+1][1+1] + way[p+1][1+1] ; if p = 0 then ( if (nj->compareTo(w)) >= 0 or (ni->compareTo(h)) >= 0 then ( var way[p+1]->first() : OclAny := null; var way[p+1][1+1] : OclAny := null; Sequence{way[p+1]->first(),way[p+1][1+1]} := Sequence{way[p+1][1+1],-way[p+1]->first()} ; ni := pos[p+1]->first() + way[p+1]->first() ; nj := pos[p+1][1+1] + way[p+1][1+1] ) else skip ) else ( if (nj->compareTo(w - 1)) >= 0 or (ni->compareTo(h - 1)) >= 0 then ( var way[p+1]->first() : OclAny := null; var way[p+1][1+1] : OclAny := null; Sequence{way[p+1]->first(),way[p+1][1+1]} := Sequence{way[p+1][1+1],-way[p+1]->first()} ; ni := pos[p+1]->first() + way[p+1]->first() ; nj := pos[p+1][1+1] + way[p+1][1+1] ) else skip ) ; pos[p+1]->first() := ni ; pos[p+1][1+1] := nj ; if (pos->first()->first() - pos[1+1]->first())->abs() + (pos->first()[1+1] - pos[1+1][1+1])->abs() = 1 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_CHAR=26 def checkCorrectOrNot(s): global MAX_CHAR count1=[0]*MAX_CHAR count2=[0]*MAX_CHAR n=len(s) if n==1 : return true i=0 ; j=n-1 while(idisplay(); operation checkCorrectOrNot(s : OclAny) : OclAny pre: true post: true activity: skip ; var count1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX_CHAR) ; var count2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX_CHAR) ; var n : int := (s)->size() ; if n = 1 then ( return true ) else skip ; var i : int := 0; var j : double := n - 1 ; while ((i->compareTo(j)) < 0) do ( count1[(s[i+1])->char2byte() - ('a')->char2byte()+1] := count1[(s[i+1])->char2byte() - ('a')->char2byte()+1] + 1 ; count2[(s[j+1])->char2byte() - ('a')->char2byte()+1] := count2[(s[j+1])->char2byte() - ('a')->char2byte()+1] + 1 ; i := i + 1; j := j - 1) ; for i : Integer.subrange(0, MAX_CHAR-1) do ( if count1[i+1] /= count2[i+1] then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans='YES' for _ in range(8): line=input() for i in range(7): if line[i]==line[i+1]: ans='NO' break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ans : String := 'YES' ; for _anon : Integer.subrange(0, 8-1) do ( var line : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, 7-1) do ( if line[i+1] = line[i + 1+1] then ( ans := 'NO' ; break ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_CHAR=26 def checkCorrectOrNot(s): global MAX_CHAR count=[0]*MAX_CHAR n=len(s) if n==1 : return true i=0 ; j=n-1 while idisplay(); operation checkCorrectOrNot(s : OclAny) : OclAny pre: true post: true activity: skip ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX_CHAR) ; var n : int := (s)->size() ; if n = 1 then ( return true ) else skip ; var i : int := 0; var j : double := n - 1 ; while (i->compareTo(j)) < 0 do ( count[(s[i+1])->char2byte() - ('a')->char2byte()+1] := count[(s[i+1])->char2byte() - ('a')->char2byte()+1] + 1 ; count[(s[j+1])->char2byte() - ('a')->char2byte()+1] := count[(s[j+1])->char2byte() - ('a')->char2byte()+1] - 1 ; i := i + 1; j := j - 1) ; for i : Integer.subrange(0, MAX_CHAR-1) do ( if count[i+1] /= 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for e in iter(input,'0 0 0'): d=[2]*-~ sum(map(int,e.split())) f=[] for _ in[0]*int(input()): s,t,u,v=map(int,input().split()) if v : d[s]=d[t]=d[u]=1 else : f+=[(s,t,u)] for s,t,u in f : if d[t]*d[u]==1 : d[s]=0 if d[u]*d[s]==1 : d[t]=0 if d[s]*d[t]==1 : d[u]=0 print(*d[1 :],sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for e : OclIterator.newOclIterator_Sequence(input, '0 0 0') do ( var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 2 }, -MathLib.bitwiseNot(((e.split())->collect( _x | (OclType["int"])->apply(_x) ))->sum())) ; var f : Sequence := Sequence{} ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var s : OclAny := null; var t : OclAny := null; var u : OclAny := null; var v : OclAny := null; Sequence{s,t,u,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if v then ( d[s+1] := d[s+1](assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))) ) else ( f := f + Sequence{ Sequence{s, t, u} } )) ; for _tuple : f do (var _indx : int := 1; var s : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); _indx := _indx + 1; var u : OclAny := _tuple->at(_indx); if d[t+1] * d[u+1] = 1 then ( d[s+1] := 0 ) else skip ; if d[u+1] * d[s+1] = 1 then ( d[t+1] := 0 ) else skip ; if d[s+1] * d[t+1] = 1 then ( d[u+1] := 0 ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,data): self.data=data self.next=None def printList(node): while node!=None : print(node.data,end=" ") node=node.next def replaceNodes(head): p=head x=None count=0 while p!=None : count=0 x=p while x!=None : if x.data>p.data : count+=1 x=x.next p.data=count p=p.next if __name__=="__main__" : head=Node(10) head.next=Node(12) head.next.next=Node(5) head.next.next.next=Node(40) head.next.next.next.next=Node(21) head.next.next.next.next.next=Node(70) head.next.next.next.next.next.next=Node(1) head.next.next.next.next.next.next.next=Node(49) head.next.next.next.next.next.next.next.next=Node(37) replaceNodes(head) printList(head) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.next := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( head := (Node.newNode()).initialise(10) ; head.next := (Node.newNode()).initialise(12) ; head.next.next := (Node.newNode()).initialise(5) ; head.next.next.next := (Node.newNode()).initialise(40) ; head.next.next.next.next := (Node.newNode()).initialise(21) ; head.next.next.next.next.next := (Node.newNode()).initialise(70) ; head.next.next.next.next.next.next := (Node.newNode()).initialise(1) ; head.next.next.next.next.next.next.next := (Node.newNode()).initialise(49) ; head.next.next.next.next.next.next.next.next := (Node.newNode()).initialise(37) ; replaceNodes(head) ; printList(head) ) else skip; operation printList(node : OclAny) pre: true post: true activity: while node /= null do ( execute (node.data)->display() ; node := node.next); operation replaceNodes(head : OclAny) pre: true post: true activity: var p : OclAny := head ; var x : OclAny := null ; var count : int := 0 ; while p /= null do ( count := 0 ; x := p ; while x /= null do ( if (x.data->compareTo(p.data)) > 0 then ( count := count + 1 ) else skip ; x := x.next) ; p.data := count ; p := p.next); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findGCDSum(n,a): GCDSum=0 ; tempGCD=0 ; for i in range(n): for j in range(i,n): tempGCD=0 ; for k in range(i,j+1): tempGCD=__gcd(tempGCD,a[k]); GCDSum+=tempGCD ; return GCDSum ; def __gcd(a,b): return a if(b==0)else __gcd(b,a % b); if __name__=='__main__' : n=5 ; a=[1,2,3,4,5]; totalSum=findGCDSum(n,a); print(totalSum); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( n := 5; ; a := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))); ; var totalSum : OclAny := findGCDSum(n, a); ; execute (totalSum)->display(); ) else skip; operation findGCDSum(n : OclAny, a : OclAny) pre: true post: true activity: var GCDSum : int := 0; ; var tempGCD : int := 0; ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i, n-1) do ( tempGCD := 0; ; for k : Integer.subrange(i, j + 1-1) do ( tempGCD := __gcd(tempGCD, a[k+1]);) ; GCDSum := GCDSum + tempGCD;)) ; return GCDSum;; operation __gcd(a : OclAny, b : OclAny) pre: true post: true activity: return if (b = 0) then a else __gcd(b, a mod b) endif;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def isSquare(n): sr=(int)(math.sqrt(n)) return(sr*sr==n) def printPrimeAndFib(n): prime=[True]*(n+1) p=2 while(p*p<=n): if(prime[p]==True): for i in range(p*2,n+1,p): prime[i]=False p=p+1 for i in range(2,n+1): if(prime[i]and(isSquare(5*i*i+4)>0 or isSquare(5*i*i-4)>0)): print(i,"",end="") n=30 printPrimeAndFib(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 30 ; printPrimeAndFib(n);; operation isSquare(n : OclAny) : OclAny pre: true post: true activity: var sr : OclAny := (OclType["int"])((n)->sqrt()) ; return (sr * sr = n); operation printPrimeAndFib(n : OclAny) pre: true post: true activity: var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (n + 1)) ; var p : int := 2 ; while ((p * p->compareTo(n)) <= 0) do ( if (prime[p+1] = true) then ( for i : Integer.subrange(p * 2, n + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false) ) else skip ; p := p + 1) ; for i : Integer.subrange(2, n + 1-1) do ( if (prime[i+1] & (isSquare(5 * i * i + 4) > 0 or isSquare(5 * i * i - 4) > 0)) then ( execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Ternary : def __init__(self,n): self.n=n def __int__(self): return self.n def __neg__(self): return Ternary(2-int(self)) def __mul__(self,o): return Ternary(min(int(self),int(o))) def __add__(self,o): return Ternary(max(int(self),int(o))) import sys,itertools from functools import reduce R=[0,1,2] while True : s=sys.stdin.readline().rstrip() if s=='.' : break r=0 for(a,b,c)in itertools.product(R,repeat=3): t=reduce(lambda t,e : t.replace(e[0],'Ternary(%d)' % e[1]),[['0',0],['1',1],['2',2],['P',a],['Q',b],['R',c]],s) if int(eval(t))==2 : r+=1 print(r) ------------------------------------------------------------ OCL File: --------- class Ternary { static operation newTernary() : Ternary pre: true post: Ternary->exists( _x | result = _x ); attribute n : OclAny := n; operation initialise(n : OclAny) : Ternary pre: true post: true activity: self.n := n; return self; operation __int__() : OclAny pre: true post: true activity: return self.n; operation __neg__() : OclAny pre: true post: true activity: return Ternary(2 - ("" + ((self)))->toInteger()); operation __mul__(o : OclAny) : OclAny pre: true post: true activity: return Ternary(Set{("" + ((self)))->toInteger(), ("" + ((o)))->toInteger()}->min()); operation __add__(o : OclAny) : OclAny pre: true post: true activity: return Ternary(Set{("" + ((self)))->toInteger(), ("" + ((o)))->toInteger()}->max()); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var R : Sequence := Sequence{0}->union(Sequence{1}->union(Sequence{ 2 })) ; while true do ( var s : OclAny := sys.stdin.readLine().rstrip() ; if s = '.' then ( break ) else skip ; var r : int := 0 ; for Sequence{a, b, c} : itertools.product(R, (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (number (integer 3))))))))) do ( var t : OclAny := reduce(lambda t : OclAny, e : OclAny in (t.replace(e->first(), StringLib.format('Ternary(%d)',e[1+1]))), Sequence{Sequence{'0'}->union(Sequence{ 0 })}->union(Sequence{Sequence{'1'}->union(Sequence{ 1 })}->union(Sequence{Sequence{'2'}->union(Sequence{ 2 })}->union(Sequence{Sequence{'P'}->union(Sequence{ a })}->union(Sequence{Sequence{'Q'}->union(Sequence{ b })}->union(Sequence{ Sequence{'R'}->union(Sequence{ c }) }))))), s) ; if ("" + ((t)))->toInteger() = 2 then ( r := r + 1 ) else skip) ; execute (r)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def AND(a,b): if a=="0" or b=="0" : return "0" elif a==b=="2" : return "2" else : return "1" def OR(a,b): if a=="2" or b=="2" : return 2 elif a==b=="0" : return "0" else : return "1" def NOT(a): if a.count("-")% 2==1 : if a[0]=="0" : return "2" elif a[0]=="2" : return "0" else : return "1" else : return a[0] def solve(S): que=deque() for s in S : if s==")" : formula="" while True : q=que.pop() if q=="(" : break formula+=q if "+" in formula : a,b=formula.split("+") a=NOT(a) b=NOT(b) que.append(str(OR(a,b))) if "*" in formula : a,b=formula.split("*") a=NOT(a) b=NOT(b) que.append(str(AND(a,b))) else : que.append(s) return NOT("".join(reversed(que))) while True : S=input() if S=="." : break count=0 for p in range(3): for q in range(3): for r in range(3): if solve(S.replace("P",str(p)).replace("Q",str(q)).replace("R",str(r)))=="2" : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; while true do ( S := (OclFile["System.in"]).readLine() ; if S = "." then ( break ) else skip ; var count : int := 0 ; for p : Integer.subrange(0, 3-1) do ( for q : Integer.subrange(0, 3-1) do ( for r : Integer.subrange(0, 3-1) do ( if solve(S.replace("P", ("" + ((p)))).replace("Q", ("" + ((q)))).replace("R", ("" + ((r))))) = "2" then ( count := count + 1 ) else skip))) ; execute (count)->display()); operation AND(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a = "0" or b = "0" then ( return "0" ) else (if a = b & (b == "2") then ( return "2" ) else ( return "1" ) ) ; operation OR(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a = "2" or b = "2" then ( return 2 ) else (if a = b & (b == "0") then ( return "0" ) else ( return "1" ) ) ; operation NOT(a : OclAny) : OclAny pre: true post: true activity: if a->count("-") mod 2 = 1 then ( if a->first() = "0" then ( return "2" ) else (if a->first() = "2" then ( return "0" ) else ( return "1" ) ) ) else ( return a->first() ); operation solve(S : OclAny) : OclAny pre: true post: true activity: var que : Sequence := () ; for s : S do ( if s = ")" then ( var formula : String := "" ; while true do ( var q : OclAny := que->last() ; que := que->front() ; if q = "(" then ( break ) else skip ; formula := formula + q) ; if (formula)->characters()->includes("+") then ( Sequence{a,b} := formula.split("+") ; a := NOT(a) ; b := NOT(b) ; execute ((("" + ((OR(a, b))))) : que) ) else skip ; if (formula)->characters()->includes("*") then ( Sequence{a,b} := formula.split("*") ; a := NOT(a) ; b := NOT(b) ; execute ((("" + ((AND(a, b))))) : que) ) else skip ) else ( execute ((s) : que) )) ; return NOT(StringLib.sumStringsWithSeparator(((que)->reverse()), "")); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def term(idx): x,idx=factor(idx) op=buf[idx] y,idx=factor(idx+1); if op=='*' : if x==2 and y==2 : x=2 elif x==0 or y==0 : x=0 else : x=1 else : if x==0 and y==0 : x=0 elif x==2 or y==2 : x=2 else : x=1 return[x,idx] def factor(idx): global p,q,r if buf[idx]=='(' : x,idx=term(idx+1) elif buf[idx]=='-' : x,idx=factor(idx+1) x=2-x ; idx-=1 elif '0'<=buf[idx]<='9' : x=int(buf[idx]) elif buf[idx]=='P' : x=p elif buf[idx]=='Q' : x=q else : x=r return[x,idx+1] while True : buf=list(input()) if buf[0]=='.' : break ans=0 for p in range(3): for q in range(3): for r in range(3): if factor(0)[0]==2 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute p : OclAny; attribute q : OclAny; attribute r : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; while true do ( var buf : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if buf->first() = '.' then ( break ) else skip ; var ans : int := 0 ; for p : Integer.subrange(0, 3-1) do ( for q : Integer.subrange(0, 3-1) do ( for r : Integer.subrange(0, 3-1) do ( if factor(0)->first() = 2 then ( ans := ans + 1 ) else skip))) ; execute (ans)->display()); operation term(idx : OclAny) : OclAny pre: true post: true activity: var x : OclAny := null; Sequence{x,idx} := factor(idx) ; var op : OclAny := buf[idx+1] ; var y : OclAny := null; Sequence{y,idx} := factor(idx + 1); ; if op = '*' then ( if x = 2 & y = 2 then ( var x : int := 2 ) else (if x = 0 or y = 0 then ( x := 0 ) else ( x := 1 ) ) ) else ( if x = 0 & y = 0 then ( x := 0 ) else (if x = 2 or y = 2 then ( x := 2 ) else ( x := 1 ) ) ) ; return Sequence{x}->union(Sequence{ idx }); operation factor(idx : OclAny) : OclAny pre: true post: true activity: skip; skip; skip ; if buf[idx+1] = '(' then ( Sequence{x,idx} := term(idx + 1) ) else (if buf[idx+1] = '-' then ( Sequence{x,idx} := factor(idx + 1) ; x := 2 - x; idx := idx - 1 ) else (if '0' <= buf[idx+1] & (buf[idx+1] <= '9') then ( x := ("" + ((buf[idx+1])))->toInteger() ) else (if buf[idx+1] = 'P' then ( x := p ) else (if buf[idx+1] = 'Q' then ( x := q ) else ( x := r ) ) ) ) ) ; return Sequence{x}->union(Sequence{ idx + 1 }); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import product class thee(int): def __add__(self,that): return thee(max(int(self),int(that))) def __mul__(self,that): return thee(min(int(self),int(that))) def __neg__(self): T=[2,1,0] return thee(T[int(self)]) S=input() while S!="." : for x in list("012PQR"): S=S.replace(x,"thee({})".format(x)) ans=0 for P,Q,R in product(range(3),repeat=3): ans+=2==int(eval(S)) print(ans) S=input() ------------------------------------------------------------ OCL File: --------- class thee extends OclType["int"] { static operation newthee() : thee pre: true post: thee->exists( _x | result = _x ); operation __add__(that : OclAny) : OclAny pre: true post: true activity: return thee(Set{("" + ((self)))->toInteger(), ("" + ((that)))->toInteger()}->max()); operation __mul__(that : OclAny) : OclAny pre: true post: true activity: return thee(Set{("" + ((self)))->toInteger(), ("" + ((that)))->toInteger()}->min()); operation __neg__() : OclAny pre: true post: true activity: var T : Sequence := Sequence{2}->union(Sequence{1}->union(Sequence{ 0 })) ; return thee(T[("" + ((self)))->toInteger()+1]); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var S : String := (OclFile["System.in"]).readLine() ; while S /= "." do ( for x : ("012PQR")->characters() do ( S := S.replace(x, StringLib.interpolateStrings("thee({})", Sequence{x}))) ; var ans : int := 0 ; for _tuple : product(Integer.subrange(0, 3-1), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (number (integer 3))))))))) do (var _indx : int := 1; var P : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Q : OclAny := _tuple->at(_indx); _indx := _indx + 1; var R : OclAny := _tuple->at(_indx); ans := ans + 2 = ("" + ((S)))->toInteger()) ; execute (ans)->display() ; S := (OclFile["System.in"]).readLine()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def parser(left,right): if S[left]=='(' and S[right-1]==')' : cnt=0 for i in range(left+1,right-1): if S[i]=='(' : cnt+=1 elif S[i]==')' : cnt-=1 elif cnt==0 and S[i]=='+' : return[max(x,y)for x,y in zip(parser(left+1,i),parser(i+1,right-1))] elif cnt==0 and S[i]=='*' : return[min(x,y)for x,y in zip(parser(left+1,i),parser(i+1,right-1))] elif S[left]=='-' : return[2-x for x in parser(left+1,right)] elif S[left]=='P' : return[i//9 % 3 for i in range(27)] elif S[left]=='Q' : return[i//3 % 3 for i in range(27)] elif S[left]=='R' : return[i % 3 for i in range(27)] else : return[int(S[left])for _ in range(27)] while True : S=input() if S=='.' : break print(parser(0,len(S)).count(2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var S : String := (OclFile["System.in"]).readLine() ; if S = '.' then ( break ) else skip ; execute (parser(0, (S)->size())->count(2))->display()); operation parser(left : OclAny, right : OclAny) pre: true post: true activity: if S[left+1] = '(' & S[right - 1+1] = ')' then ( var cnt : int := 0 ; for i : Integer.subrange(left + 1, right - 1-1) do ( if S[i+1] = '(' then ( cnt := cnt + 1 ) else (if S[i+1] = ')' then ( cnt := cnt - 1 ) else (if cnt = 0 & S[i+1] = '+' then ( return Integer.subrange(1, parser(left + 1, i)->size())->collect( _indx | Sequence{parser(left + 1, i)->at(_indx), parser(i + 1, right - 1)->at(_indx)} )->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (Set{x, y}->max())) ) else (if cnt = 0 & S[i+1] = '*' then ( return Integer.subrange(1, parser(left + 1, i)->size())->collect( _indx | Sequence{parser(left + 1, i)->at(_indx), parser(i + 1, right - 1)->at(_indx)} )->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (Set{x, y}->min())) ) else skip ) ) ) ) ) else (if S[left+1] = '-' then ( return parser(left + 1, right)->select(x | true)->collect(x | (2 - x)) ) else (if S[left+1] = 'P' then ( return Integer.subrange(0, 27-1)->select(i | true)->collect(i | (i div 9 mod 3)) ) else (if S[left+1] = 'Q' then ( return Integer.subrange(0, 27-1)->select(i | true)->collect(i | (i div 3 mod 3)) ) else (if S[left+1] = 'R' then ( return Integer.subrange(0, 27-1)->select(i | true)->collect(i | (i mod 3)) ) else ( return Integer.subrange(0, 27-1)->select(_anon | true)->collect(_anon | (("" + ((S[left+1])))->toInteger())) ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printBracketNumber(exp,n): left_bnum=1 right_bnum=list() for i in range(n): if exp[i]=='(' : print(left_bnum,end=" ") right_bnum.append(left_bnum) left_bnum+=1 elif exp[i]==')' : print(right_bnum[-1],end=" ") right_bnum.pop() if __name__=="__main__" : exp="(a+(b*c))+(d/e)" n=len(exp) printBracketNumber(exp,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( exp := "(a+(b*c))+(d/e)" ; n := (exp)->size() ; printBracketNumber(exp, n) ) else skip; operation printBracketNumber(exp : OclAny, n : OclAny) pre: true post: true activity: var left_bnum : int := 1 ; var right_bnum : Sequence := () ; for i : Integer.subrange(0, n-1) do ( if exp[i+1] = '(' then ( execute (left_bnum)->display() ; execute ((left_bnum) : right_bnum) ; left_bnum := left_bnum + 1 ) else (if exp[i+1] = ')' then ( execute (right_bnum->last())->display() ; right_bnum := right_bnum->front() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout if __name__=="__main__" : f=1 for i in range(8): s=input() if s!='WBWBWBWB' and s!='BWBWBWBW' : print('NO') f=0 break if f==1 : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var f : int := 1 ; for i : Integer.subrange(0, 8-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if s /= 'WBWBWBWB' & s /= 'BWBWBWBW' then ( execute ('NO')->display() ; f := 0 ; break ) else skip) ; if f = 1 then ( execute ("YES")->display() ) else skip ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minRemove(a,b,n,m): countA=dict() countB=dict() for i in range(n): countA[a[i]]=countA.get(a[i],0)+1 for i in range(n): countB[b[i]]=countB.get(b[i],0)+1 res=0 for x in countA : if x in countB.keys(): res+=min(countA[x],countB[x]) return res a=[1,2,3,4] b=[2,3,4,5,8] n=len(a) m=len(b) print(minRemove(a,b,n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))) ; b := Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 8 })))) ; n := (a)->size() ; m := (b)->size() ; execute (minRemove(a, b, n, m))->display(); operation minRemove(a : OclAny, b : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var countA : Map := (arguments ( )) ; var countB : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( countA[a[i+1]+1] := countA.get(a[i+1], 0) + 1) ; for i : Integer.subrange(0, n-1) do ( countB[b[i+1]+1] := countB.get(b[i+1], 0) + 1) ; var res : int := 0 ; for x : countA->keys() do ( if (countB.keys())->includes(x) then ( res := res + Set{countA[x+1], countB[x+1]}->min() ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minXOR(arr,n): arr.sort(); min_xor=999999 val=0 for i in range(0,n-1): for j in range(i+1,n-1): val=arr[i]^ arr[j] min_xor=min(min_xor,val) return min_xor arr=[9,5,3] n=len(arr) print(minXOR(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{9}->union(Sequence{5}->union(Sequence{ 3 })) ; n := (arr)->size() ; execute (minXOR(arr, n))->display(); operation minXOR(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: arr := arr->sort(); ; var min_xor : int := 999999 ; var val : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(i + 1, n - 1-1) do ( val := MathLib.bitwiseXor(arr[i+1], arr[j+1]) ; min_xor := Set{min_xor, val}->min())) ; return min_xor; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): for n in reversed(range(2,10)): arr=list(reversed(range(1,n+1))) while True : if arr[-1]not in NONPRIME_LAST_DIGITS : n=int("".join(str(x)for x in arr)) if eulerlib.is_prime(n): return str(n) if not prev_permutation(arr): break raise AssertionError() NONPRIME_LAST_DIGITS={0,2,4,5,6,8} def prev_permutation(arr): i=len(arr)-1 while i>0 and arr[i-1]<=arr[i]: i-=1 if i<=0 : return False j=len(arr)-1 while arr[j]>=arr[i-1]: j-=1 arr[i-1],arr[j]=arr[j],arr[i-1] arr[i :]=arr[len(arr)-1 : i-1 :-1] return True if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var NONPRIME_LAST_DIGITS : Set := Set{0}->union(Set{2}->union(Set{4}->union(Set{5}->union(Set{6}->union(Set{ 8 }))))) ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: for n : (Integer.subrange(2, 10-1))->reverse() do ( var arr : Sequence := ((Integer.subrange(1, n + 1-1))->reverse()) ; while true do ( if (NONPRIME_LAST_DIGITS)->excludes(arr->last()) then ( var n : int := ("" + ((StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name arr)))))))), ""))))->toInteger() ; if eulerlib.is_prime(n) then ( return ("" + ((n))) ) else skip ) else skip ; if not(prev_permutation(arr)) then ( break ) else skip)) ; error AssertionException.newAssertionException(); operation prev_permutation(arr : OclAny) : OclAny pre: true post: true activity: var i : double := (arr)->size() - 1 ; while i > 0 & (arr[i - 1+1]->compareTo(arr[i+1])) <= 0 do ( i := i - 1) ; if i <= 0 then ( return false ) else skip ; var j : double := (arr)->size() - 1 ; while (arr[j+1]->compareTo(arr[i - 1+1])) >= 0 do ( j := j - 1) ; var arr[i - 1+1] : OclAny := null; var arr[j+1] : OclAny := null; Sequence{arr[i - 1+1],arr[j+1]} := Sequence{arr[j+1],arr[i - 1+1]} ; arr.subrange(i+1) := arr(subscript (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr)))))))) )))) - (expr (atom (number (integer 1)))))))) : (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))) (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPalindrome(r): p=r p="".join(reversed(p)) return(r==p) def PrefixSuffixPalindrome(st): n=len(st) length=0 for i in range(n//2): if(st[i]!=st[n-i-1]): length=i break prefix="" suffix="" midPal="" prefix=st[: length] suffix=st[n-length :] st=st[length : n-2*length+length] for i in range(1,len(st)+1): y=st[0 : i] if(isPalindrome(y)): if(len(midPal)display() ) else skip; operation isPalindrome(r : OclAny) : OclAny pre: true post: true activity: var p : OclAny := r ; p := StringLib.sumStringsWithSeparator(((p)->reverse()), "") ; return (r = p); operation PrefixSuffixPalindrome(st : OclAny) : OclAny pre: true post: true activity: var n : int := (st)->size() ; var length : int := 0 ; for i : Integer.subrange(0, n div 2-1) do ( if (st[i+1] /= st[n - i - 1+1]) then ( length := i ; break ) else skip) ; var prefix : String := "" ; var suffix : String := "" ; var midPal : String := "" ; prefix := st.subrange(1,length) ; suffix := st.subrange(n - length+1) ; st := st.subrange(length+1, n - 2 * length + length) ; for i : Integer.subrange(1, (st)->size() + 1-1) do ( var y : OclAny := st.subrange(0+1, i) ; if (isPalindrome(y)) then ( if (((midPal)->size()->compareTo((y)->size())) < 0) then ( midPal := y ) else skip ) else skip) ; for i : Integer.subrange(1, (st)->size() + 1-1) do ( y := st[(st)->size() - i+1] ; if (isPalindrome(y)) then ( if (((midPal)->size()->compareTo((y)->size())) < 0) then ( midPal := y ) else skip ) else skip) ; var answer : String := prefix + midPal + suffix ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(s): area=(1.732*s**2)/8 return area if __name__=='__main__' : n=14 print(solve(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var n : int := 14 ; execute (solve(n))->display() ) else skip; operation solve(s : OclAny) : OclAny pre: true post: true activity: var area : double := (1.732 * (s)->pow(2)) / 8 ; return area; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def checkSquare(s1,s2): c=int(s1+s2) d=math.sqrt(c) if(d*d==c): print("Yes") else : print("No") if __name__=="__main__" : s1="12" s2="1" checkSquare(s1,s2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( s1 := "12" ; s2 := "1" ; checkSquare(s1, s2) ) else skip; operation checkSquare(s1 : OclAny, s2 : OclAny) pre: true post: true activity: var c : int := ("" + ((s1 + s2)))->toInteger() ; var d : double := (c)->sqrt() ; if (d * d = c) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxi(lst : list)->int : elem=-1 elemi=-1 for i,v in enumerate(lst): if v>elem : elem=v elemi=i return elemi n=int(input()) lst=list(map(int,input().split())) soln=maxi(lst) print(soln+1,end=" ") lst.pop(soln) print(max(lst)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var soln : OclAny := maxi(lst) ; execute (soln + 1)->display() ; lst := lst->excludingAt(soln+1) ; execute ((lst)->max())->display(); operation maxi(lst : Sequence(OclAny)) : int pre: true post: true activity: var elem : int := -1 ; var elemi : int := -1 ; for _tuple : Integer.subrange(1, (lst)->size())->collect( _indx | Sequence{_indx-1, (lst)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if (v->compareTo(elem)) > 0 then ( elem := v ; elemi := i ) else skip) ; return elemi; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_of_prices=int(input()) lst=[int(x)for x in input().split(" ")] second_max=lst[1] current_max_index=0 for i in range(1,num_of_prices): if lst[current_max_index]second_max : second_max=lst[i] print(current_max_index+1,second_max) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_of_prices : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var second_max : OclAny := lst[1+1] ; var current_max_index : int := 0 ; for i : Integer.subrange(1, num_of_prices-1) do ( if (lst[current_max_index+1]->compareTo(lst[i+1])) < 0 then ( second_max := lst[current_max_index+1] ; current_max_index := i ) else (if (lst[i+1]->compareTo(second_max)) > 0 then ( second_max := lst[i+1] ) else skip)) ; execute (current_max_index + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) temp=l.index(max(l)) l.remove(max(l)) print(temp+1,end=' ') print(max(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var temp : int := l->indexOf((l)->max()) - 1 ; execute (((l)->max()) /: l) ; execute (temp + 1)->display() ; execute ((l)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() l=list(map(int,input().split())) a=l.index(max(l)) l.sort(reverse=True) print(a+1,l[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : int := l->indexOf((l)->max()) - 1 ; l := l->sort() ; execute (a + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) L=[] for i in range(t): n=int(input()) x=1 y=1 z=1 ukupno=0 odgovor=0 while ukupno<=n : ukupno+=z odgovor+=1 x=z*2 y=y*4 z=x+y if ukupno>n : odgovor-=1 L.append(odgovor) for i in range(len(L)): print(L[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var L : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := 1 ; var y : int := 1 ; var z : int := 1 ; var ukupno : int := 0 ; var odgovor : int := 0 ; while (ukupno->compareTo(n)) <= 0 do ( ukupno := ukupno + z ; odgovor := odgovor + 1 ; x := z * 2 ; y := y * 4 ; z := x + y) ; if (ukupno->compareTo(n)) > 0 then ( odgovor := odgovor - 1 ) else skip ; execute ((odgovor) : L)) ; for i : Integer.subrange(0, (L)->size()-1) do ( execute (L[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count(l,r): cnt=0 for i in range(l,r): if(i<10): cnt+=1 else : n=i % 10 k=i while(k>=10): k=k//10 if(n==k): cnt+=1 return(cnt) L=2 ; R=60 ; print(count(L,R)) L=1 ; R=1000 ; print(count(L,R)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var L : int := 2; var R : int := 60; ; execute (count(L, R))->display() ; L := 1; R := 1000; ; execute (count(L, R))->display(); operation count(l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; for i : Integer.subrange(l, r-1) do ( if (i < 10) then ( cnt := cnt + 1 ) else ( var n : int := i mod 10 ; var k : OclAny := i ; while (k >= 10) do ( k := k div 10) ; if (n = k) then ( cnt := cnt + 1 ) else skip )) ; return (cnt); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) exec("print('YNEOS'[any('WW'in a or'BB' in a for a in["+8*"input(),"+"])::2])") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (small_stmt print ( 'YNEOS' [ any ( 'WW' in a or 'BB' in a for a in [ "+8*" input ( ) , "+" ] ) : : 2 ] )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) a=-1 x=0 while(x<=n): a+=1 k=2**(a+1)-1 x+=k*(k+1)//2 print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := -1 ; var x : int := 0 ; while ((x->compareTo(n)) <= 0) do ( a := a + 1 ; var k : double := (2)->pow((a + 1)) - 1 ; x := x + k * (k + 1) div 2) ; execute (a)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x=int(input()) s=0 i=1 ans=0 while sx : ans-=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : int := 0 ; var i : int := 1 ; var ans : int := 0 ; while (s->compareTo(x)) < 0 do ( s := s + (i * (i + 1)) div 2 ; i := 2 * (i + 1) - 1 ; ans := ans + 1) ; if (s->compareTo(x)) > 0 then ( ans := ans - 1 ) else skip ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tests=int(input()) for t in range(tests): n=int(input()) k=1 count=0 while n>-1 : n-=((2**k)-1)*(2**(k-1)) if n>=0 : count+=1 k+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var tests : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(0, tests-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := 1 ; var count : int := 0 ; while n > -1 do ( n := n - (((2)->pow(k)) - 1) * ((2)->pow((k - 1))) ; if n >= 0 then ( count := count + 1 ; k := k + 1 ) else skip) ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tests=int(input()) for t in range(tests): n=int(input()) k=1 i=0 count=0 cells=0 if n==1 : print(1) continue while n>-1 : j=(2**k)-1 n=n-(j*(2**(k-1))) if n>=0 : count+=1 k+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var tests : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t : Integer.subrange(0, tests-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := 1 ; var i : int := 0 ; var count : int := 0 ; var cells : int := 0 ; if n = 1 then ( execute (1)->display() ; continue ) else skip ; while n > -1 do ( var j : double := ((2)->pow(k)) - 1 ; n := n - (j * ((2)->pow((k - 1)))) ; if n >= 0 then ( count := count + 1 ; k := k + 1 ) else skip) ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def pivotIndex(self,nums): totalsum=sum(nums) leftsum=0 for i,v in enumerate(nums): if leftsum==totalsum-leftsum-v : return i leftsum+=v return-1 ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation pivotIndex(nums : OclAny) : OclAny pre: true post: true activity: var totalsum : OclAny := (nums)->sum() ; var leftsum : int := 0 ; for _tuple : Integer.subrange(1, (nums)->size())->collect( _indx | Sequence{_indx-1, (nums)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if leftsum = totalsum - leftsum - v then ( return i ) else skip ; leftsum := leftsum + v) ; return -1; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ispowerof2(num): if((num &(num-1))==0): return 1 return 0 if __name__=='__main__' : num=549755813888 print(ispowerof2(num)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( num := 549755813888 ; execute (ispowerof2(num))->display() ) else skip; operation ispowerof2(num : OclAny) : OclAny pre: true post: true activity: if ((MathLib.bitwiseAnd(num, (num - 1))) = 0) then ( return 1 ) else skip ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def insertion_sort(num_list,gap): global cnt for i in range(gap,len(num_list)): swap_num=num_list[i] j=i-gap while j>=0 and num_list[j]>swap_num : num_list[j+gap]=num_list[j] j-=gap cnt+=1 num_list[j+gap]=swap_num def shell_sort(num_list): global cnt cnt=0 m=1 m_list=[] while len(num_list)>=m : m_list.append(m) m=3*m+1 m_list.reverse() print(len(m_list)) print(' '.join([str(i)for i in m_list])) for i in range(len(m_list)): insertion_sort(num_list,m_list[i]) print(cnt) n=int(input()) num_list=[int(input())for _ in range(n)] shell_sort(num_list) for num in num_list : print(num) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute cnt : OclAny; attribute cnt : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; num_list := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; shell_sort(num_list) ; for num : num_list do ( execute (num)->display()); operation insertion_sort(num_list : OclAny, gap : OclAny) pre: true post: true activity: skip ; for i : Integer.subrange(gap, (num_list)->size()-1) do ( var swap_num : OclAny := num_list[i+1] ; var j : double := i - gap ; while j >= 0 & (num_list[j+1]->compareTo(swap_num)) > 0 do ( num_list[j + gap+1] := num_list[j+1] ; j := j - gap ; cnt := cnt + 1) ; num_list[j + gap+1] := swap_num); operation shell_sort(num_list : OclAny) pre: true post: true activity: skip ; cnt := 0 ; var m : int := 1 ; var m_list : Sequence := Sequence{} ; while ((num_list)->size()->compareTo(m)) >= 0 do ( execute ((m) : m_list) ; m := 3 * m + 1) ; m_list := m_list->reverse() ; execute ((m_list)->size())->display() ; execute (StringLib.sumStringsWithSeparator((m_list->select(i | true)->collect(i | (("" + ((i)))))), ' '))->display() ; for i : Integer.subrange(0, (m_list)->size()-1) do ( insertion_sort(num_list, m_list[i+1])) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(input()) A=list(map(int,sys.stdin)) cnt=0 def insertion_sort(L,n,g): global cnt for i in range(g,n): v=L[i] j=i-g while 0<=j and vtoInteger() ; var A : Sequence := ((OclFile["System.in"])->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : int := 0 ; skip ; skip ; G := Sequence{262913}->union(Sequence{65921}->union(Sequence{16577}->union(Sequence{4193}->union(Sequence{1073}->union(Sequence{281}->union(Sequence{77}->union(Sequence{23}->union(Sequence{8}->union(Sequence{ 1 })))))))))->select(i | (i->compareTo(n)) <= 0)->collect(i | (i)) ; shell_sort(A, n) ; execute ((G)->size())->display() ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name G)))))))), ' '))->display() ; execute (cnt)->display() ; for i : A do ( execute (i)->display()); operation insertion_sort(L : OclAny, n : OclAny, g : OclAny) pre: true post: true activity: skip ; for i : Integer.subrange(g, n-1) do ( var v : OclAny := L[i+1] ; var j : double := i - g ; while 0 <= j & (v->compareTo(L[j+1])) < 0 do ( L[j + g+1] := L[j+1] ; j := j - g ; cnt := cnt + 1) ; L[j + g+1] := v); operation shell_sort(L : OclAny, n : OclAny) pre: true post: true activity: skip ; for i : G do ( insertion_sort(L, n, i)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def insertionSort(A,n,g,cnt): i=g while n-1>=i : v=A[i] j=i-g while j>=0 and A[j]>v : A[j+g]=A[j] j=j-g cnt+=1 A[j+g]=v i+=1 return cnt def shellSort(A,n,cnt): G=[] e=1 while len(A)>=e : G.append(e) e=3*e+1 G.reverse() m=len(G) print(m) i=0 for g in G : if i!=m-1 : print("{}".format(g),end="") elif i==m-1 : print(g) i+=1 for g in G : cnt=insertionSort(A,n,g,cnt) print(cnt) for a in A : print(a) return cnt n=int(input()) a=[] cnt=0 for _ in range(n): a.append(int(input())) cnt=shellSort(a,n,cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; cnt := 0 ; for _anon : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : a)) ; cnt := shellSort(a, n, cnt); operation insertionSort(A : OclAny, n : OclAny, g : OclAny, cnt : OclAny) : OclAny pre: true post: true activity: var i : OclAny := g ; while (n - 1->compareTo(i)) >= 0 do ( var v : OclAny := A[i+1] ; var j : double := i - g ; while j >= 0 & (A[j+1]->compareTo(v)) > 0 do ( A[j + g+1] := A[j+1] ; j := j - g ; cnt := cnt + 1) ; A[j + g+1] := v ; i := i + 1) ; return cnt; operation shellSort(A : OclAny, n : OclAny, cnt : OclAny) : OclAny pre: true post: true activity: var G : Sequence := Sequence{} ; var e : int := 1 ; while ((A)->size()->compareTo(e)) >= 0 do ( execute ((e) : G) ; e := 3 * e + 1) ; G := G->reverse() ; var m : int := (G)->size() ; execute (m)->display() ; i := 0 ; for g : G do ( if i /= m - 1 then ( execute (StringLib.interpolateStrings("{}", Sequence{g}))->display() ) else (if i = m - 1 then ( execute (g)->display() ) else skip) ; i := i + 1) ; for g : G do ( cnt := insertionSort(A, n, g, cnt)) ; execute (cnt)->display() ; for a : A do ( execute (a)->display()) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] while True : n=I() a=LI() r=-1 for i in range(n): b=a[i] for c in a[i+1 :]: t=b*c if r>=t : continue s=str(t) if all([int(s[k])==int(s[k+1])-1 for k in range(len(s)-1)]): r=t rr.append(r) break return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var n : OclAny := I() ; var a : OclAny := LI() ; var r : int := -1 ; for i : Integer.subrange(0, n-1) do ( var b : OclAny := a[i+1] ; for c : a.subrange(i + 1+1) do ( var t : double := b * c ; if (r->compareTo(t)) >= 0 then ( continue ) else skip ; s := ("" + ((t))) ; if (Integer.subrange(0, (s)->size() - 1-1)->select(k | true)->collect(k | (("" + ((s[k+1])))->toInteger() = ("" + ((s[k + 1+1])))->toInteger() - 1)))->forAll( _x | _x = true ) then ( r := t ) else skip)) ; execute ((r) : rr) ; break) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(input()) A=[int(e)for e in sys.stdin] cnt=0 G=[int((2.1**i-1)/1.1)for i in range(19,1,-1)]+[1] G=[v for v in G if v<=n] def insertionSort(A,n,g): global cnt for i in range(g,n): v=A[i] j=i-g while j>=0 and A[j]>v : A[j+g]=A[j] j=j-g cnt+=1 A[j+g]=v for g in G : insertionSort(A,n,g) print(len(G)) print(*G) print(cnt) print(*A,sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { attribute cnt : OclAny; operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := OclFile["System.in"]->select(e | true)->collect(e | (("" + ((e)))->toInteger())) ; var cnt : int := 0 ; var G : Sequence := Integer.subrange(1 + 1, 19)->reverse()->select(i | true)->collect(i | (("" + ((((2.1)->pow(i) - 1) / 1.1)))->toInteger()))->union(Sequence{ 1 }) ; G := G->select(v | (v->compareTo(n)) <= 0)->collect(v | (v)) ; skip ; for g : G do ( insertionSort(A, n, g)) ; execute ((G)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name G))))))))->display() ; execute (cnt)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name A))))))))->display(); operation insertionSort(A : OclAny, n : OclAny, g : OclAny) pre: true post: true activity: skip ; for i : Integer.subrange(g, n-1) do ( var v : OclAny := A[i+1] ; var j : double := i - g ; while j >= 0 & (A[j+1]->compareTo(v)) > 0 do ( A[j + g+1] := A[j+1] ; j := j - g ; cnt := cnt + 1) ; A[j + g+1] := v); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- arr=[] count=0 for i in range(8): count+=1 x=input() a=x.count("W") if 2*a==len(x): if "WW" in x or "BB" in x : print("NO") break else : print("NO") break if count==8 : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var arr : Sequence := Sequence{} ; var count : int := 0 ; for i : Integer.subrange(0, 8-1) do ( count := count + 1 ; var x : String := (OclFile["System.in"]).readLine() ; var a : int := x->count("W") ; if 2 * a = (x)->size() then ( if (x)->characters()->includes("WW") or (x)->characters()->includes("BB") then ( execute ("NO")->display() ; break ) else skip ) else ( execute ("NO")->display() ; break ) ; if count = 8 then ( execute ("YES")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def insertion_sort(a,n,g): count=0 for i in range(g,n): v=a[i] j=i-g while j>=0 and a[j]>v : a[j+g]=a[j] j=j-g count+=1 a[j+g]=v return count def shell_sort(a,n): count=0 G=list([int((2.25**i-1)/1.25)for i in range(17,0,-1)]) G=[x for x in G if x<=n] m=len(G) for g in G : count+=insertion_sort(a,n,g) return m,G,count,a n=int(input()) a=list(map(int,sys.stdin)) m,G,count,a=shell_sort(a,n) print(len(G)) print(*G) print(count) print("\n".join(map(str,a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := ((OclFile["System.in"])->collect( _x | (OclType["int"])->apply(_x) )) ; Sequence{m,G,count,a} := shell_sort(a, n) ; execute ((G)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name G))))))))->display() ; execute (count)->display() ; execute (StringLib.sumStringsWithSeparator(((a)->collect( _x | (OclType["String"])->apply(_x) )), "\n"))->display(); operation insertion_sort(a : OclAny, n : OclAny, g : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(g, n-1) do ( var v : OclAny := a[i+1] ; var j : double := i - g ; while j >= 0 & (a[j+1]->compareTo(v)) > 0 do ( a[j + g+1] := a[j+1] ; j := j - g ; count := count + 1) ; a[j + g+1] := v) ; return count; operation shell_sort(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: count := 0 ; var G : Sequence := (Integer.subrange(0 + 1, 17)->reverse()->select(i | true)->collect(i | (("" + ((((2.25)->pow(i) - 1) / 1.25)))->toInteger()))) ; G := G->select(x | (x->compareTo(n)) <= 0)->collect(x | (x)) ; var m : int := (G)->size() ; for g : G do ( count := count + insertion_sort(a, n, g)) ; return m, G, count, a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMinSum(arr,n): sum=0 for i in range(0,n): sum+=arr[i]*(n-i) return sum arr=[3,5,7,8] n=len(arr) print(findMinSum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{ 8 }))) ; n := (arr)->size() ; execute (findMinSum(arr, n))->display(); operation findMinSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + arr[i+1] * (n - i)) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMinSum(arr,n): occ=n-1 Sum=0 for i in range(n): Sum+=arr[i]*pow(2,occ) occ-=1 return Sum arr=[1,2,4,5] n=len(arr) print(findMinSum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 5 }))) ; n := (arr)->size() ; execute (findMinSum(arr, n))->display(); operation findMinSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var occ : double := n - 1 ; var Sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( Sum := Sum + arr[i+1] * (2)->pow(occ) ; occ := occ - 1) ; return Sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(numbers): max=-sys.maxsize for i in range(0,len(numbers)): sum=0 for j in range(i,len(numbers)): sum+=numbers[j] if sum>max : max=sum return max while True : n=int(input()) if n==0 : break numbers=[] for i in range(0,n): numbers.append(int(input())) print(solve(numbers)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; numbers := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : numbers)) ; execute (solve(numbers))->display()); operation solve(numbers : OclAny) : OclAny pre: true post: true activity: var max : (trailer . (name maxsize)) := -(trailer . (name maxsize)) ; for i : Integer.subrange(0, (numbers)->size()-1) do ( var sum : int := 0 ; for j : Integer.subrange(i, (numbers)->size()-1) do ( sum := sum + numbers[j+1] ; if (sum->compareTo(max)) > 0 then ( max := sum ) else skip)) ; return max; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import os def max_seq(A): s=[] s.append(A[0]) for i in range(1,len(A)): v=max(A[i],A[i]+s[i-1]) s.append(v) return max(s) while True : s=input().strip() if s=='0' : break N=int(s) A=[] for i in range(N): v=int(input()) A.append(v) print(max_seq(A)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; while true do ( s := input()->trim() ; if s = '0' then ( break ) else skip ; var N : int := ("" + ((s)))->toInteger() ; A := Sequence{} ; for i : Integer.subrange(0, N-1) do ( v := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((v) : A)) ; execute (max_seq(A))->display()); operation max_seq(A : OclAny) : OclAny pre: true post: true activity: var s : Sequence := Sequence{} ; execute ((A->first()) : s) ; for i : Integer.subrange(1, (A)->size()-1) do ( var v : OclAny := Set{A[i+1], A[i+1] + s[i - 1+1]}->max() ; execute ((v) : s)) ; return (s)->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : a=[] n=int(input()) if n==0 : break a=[int(input())for i in range(n)] max=-111111111111111 for i in range(n): sum=0 for j in range(i,n): sum+=a[j] if sum>max : max=sum print(max) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var a : Sequence := Sequence{} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; a := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var max : int := -111111111111111 ; for i : Integer.subrange(0, n-1) do ( var sum : int := 0 ; for j : Integer.subrange(i, n-1) do ( sum := sum + a[j+1] ; if (sum->compareTo(max)) > 0 then ( max := sum ) else skip)) ; execute (max)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break l=[int(input())for i in range(n)] s=0 m=0 for li in l : s=max(0,s+li) m=max(m,s) print(m if m else max(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var l : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var s : int := 0 ; var m : int := 0 ; for li : l do ( s := Set{0, s + li}->max() ; m := Set{m, s}->max()) ; execute (if m then m else (l)->max() endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(a_list): if len(list(filter(lambda x : x>=0,a_list)))==0 : return max(a_list) dp=[0]*len(a_list) dp[0]=max(0,a_list[0]) for i in range(1,len(dp)): dp[i]=max(0,a_list[i]+dp[i-1]) return max(dp) def main(): while True : n=int(input()) if n==0 : break a_list=[int(input())for _ in range(n)] print(solve(a_list)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(a_list : OclAny) : OclAny pre: true post: true activity: if (((a_list)->select( _x | (lambda x : OclAny in (x >= 0))->apply(_x) = true )))->size() = 0 then ( return (a_list)->max() ) else skip ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (a_list)->size()) ; dp->first() := Set{0, a_list->first()}->max() ; for i : Integer.subrange(1, (dp)->size()-1) do ( dp[i+1] := Set{0, a_list[i+1] + dp[i - 1+1]}->max()) ; return (dp)->max(); operation main() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; a_list := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; execute (solve(a_list))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for s in[*open(0)][2 : : 2]: i=r=0 for x in sorted(map(int,s.split())): i+=1 ; r=(i,r)[x>i] print(r+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var i : OclAny := 0; var r : int := 0 ; for x : (s.split())->collect( _x | (OclType["int"])->apply(_x) )->sort() do ( i := i + 1; r := Sequence{i, r}->select((x->compareTo(i)) > 0)) ; execute (r + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- number=int(input()) arr=list(map(int,input().split())) counter=0 data={"found" : "NO",'first' : 0} for i in range(0,number): x=int(arr[i]) if x==1 : if counter==0 : counter=1 if data['found']=="yes" : y=i-data['first'] counter=counter*y data['first']=i else : data['found']="yes" data['first']=i print(counter) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var number : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var counter : int := 0 ; var data : Map := Map{ "found" |-> "NO" }->union(Map{ 'first' |-> 0 }) ; for i : Integer.subrange(0, number-1) do ( var x : int := ("" + ((arr[i+1])))->toInteger() ; if x = 1 then ( if counter = 0 then ( counter := 1 ) else skip ; if data->at('found') = "yes" then ( var y : double := i - data->at('first') ; counter := counter * y ; data->at('first') := i ) else ( data->at('found') := "yes" ; data->at('first') := i ) ) else skip) ; execute (counter)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_CHAR=26 def check(freq,k): for i in range(0,MAX_CHAR): if(freq[i]and freq[i]!=k): return False return True def substrings(s,k): res=0 for i in range(0,len(s)): freq=[0]*MAX_CHAR for j in range(i,len(s)): index=ord(s[j])-ord('a') freq[index]+=1 if(freq[index]>k): break elif(freq[index]==k and check(freq,k)==True): res+=1 return res if __name__=="__main__" : s="aabbcc" k=2 print(substrings(s,k)) s="aabbc" ; k=2 ; print(substrings(s,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_CHAR : int := 26 ; skip ; skip ; if __name__ = "__main__" then ( s := "aabbcc" ; k := 2 ; execute (substrings(s, k))->display() ; s := "aabbc"; ; k := 2; ; execute (substrings(s, k))->display() ) else skip; operation check(freq : OclAny, k : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, MAX_CHAR-1) do ( if (freq[i+1] & freq[i+1] /= k) then ( return false ) else skip) ; return true; operation substrings(s : OclAny, k : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( freq := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX_CHAR) ; for j : Integer.subrange(i, (s)->size()-1) do ( var index : double := (s[j+1])->char2byte() - ('a')->char2byte() ; freq[index+1] := freq[index+1] + 1 ; if ((freq[index+1]->compareTo(k)) > 0) then ( break ) else (if (freq[index+1] = k & check(freq, k) = true) then ( res := res + 1 ) else skip))) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=map(int,input().split()) t=list(map(int,input().split())) p=-1 ans=0 for ti in t : ans+=d-max(p-ti,0) p=ti+d print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var p : int := -1 ; var ans : int := 0 ; for ti : t do ( ans := ans + d - Set{p - ti, 0}->max() ; p := ti + d) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- array=[] count=0 for i in range(8): count+=1 k=input() a=k.count("W") if 2*a==len(k): if "WW" in k or "BB" in k : print("NO") break else : print("NO") break if count==8 : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var array : Sequence := Sequence{} ; var count : int := 0 ; for i : Integer.subrange(0, 8-1) do ( count := count + 1 ; var k : String := (OclFile["System.in"]).readLine() ; var a : int := k->count("W") ; if 2 * a = (k)->size() then ( if (k)->characters()->includes("WW") or (k)->characters()->includes("BB") then ( execute ("NO")->display() ; break ) else skip ) else ( execute ("NO")->display() ; break ) ; if count = 8 then ( execute ("YES")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,time=[int(_)for _ in input().split()] t=[int(_)for _ in input().split()] off_total=0 for i in range(0,n-1): if t[i+1]-t[i]>time : off_total+=t[i+1]-t[i]-time print(t[-1]+time-off_total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var time : OclAny := null; Sequence{n,time} := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var t : Sequence := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var off_total : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if (t[i + 1+1] - t[i+1]->compareTo(time)) > 0 then ( off_total := off_total + t[i + 1+1] - t[i+1] - time ) else skip) ; execute (t->last() + time - off_total)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans=0 N,T=list(map(int,input().split())) t=list(map(int,input().split())) for i in range(1,N): ans+=min(T,t[i]-t[i-1]) print(ans+T) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ans : int := 0 ; var N : OclAny := null; var T : OclAny := null; Sequence{N,T} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(1, N-1) do ( ans := ans + Set{T, t[i+1] - t[i - 1+1]}->min()) ; execute (ans + T)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque n,x=map(int,input().split()) t=list(map(int,input().split())) ans=0 t=deque(t) tmp=t.popleft() for _ in range(n-1): tmp2=t.popleft() if tmp2-tmp>x : ans+=x else : ans+=tmp2-tmp tmp=tmp2 ans+=x print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; t := (t) ; var tmp : OclAny := t->first() ; t := t->tail() ; for _anon : Integer.subrange(0, n - 1-1) do ( var tmp2 : OclAny := t->first() ; t := t->tail() ; if (tmp2 - tmp->compareTo(x)) > 0 then ( ans := ans + x ) else ( ans := ans + tmp2 - tmp ) ; tmp := tmp2) ; ans := ans + x ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,T=map(int,input().split()) t=[int(i)for i in input().split()] ct=0 ans=0 for p in t : if ct<=p : ans+=T ct=p+T else : ans=ans-(ct-p)+T ct=p+T print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var T : OclAny := null; Sequence{N,T} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ct : int := 0 ; var ans : int := 0 ; for p : t do ( if (ct->compareTo(p)) <= 0 then ( ans := ans + T ; ct := p + T ) else ( ans := ans - (ct - p) + T ; ct := p + T )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : cnt=0 n,x=map(int,input().split()) if n==x==0 : break for i in range(1,n-1): for j in range(i+1,n): for k in range(j+1,n+1): if i+j+k==x : cnt+=1 ; print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var cnt : int := 0 ; var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = x & (x == 0) then ( break ) else skip ; for i : Integer.subrange(1, n - 1-1) do ( for j : Integer.subrange(i + 1, n-1) do ( for k : Integer.subrange(j + 1, n + 1-1) do ( if i + j + k = x then ( cnt := cnt + 1; ) else skip))) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function import sys def solve(n,x): count=0 for a in xrange(1,n-1): if x<=a : break for b in xrange(1+a,n): ab=a+b if x<=ab : break for c in xrange(1+b,n+1): total=ab+c if x==total : count+=1 break if xselect(n | true)->collect(n | (("" + ((n)))->toInteger())) ; if not((L)->exists( _x | _x = true )) then ( break ) else skip ; execute (solve((argument * (test (logical_test (comparison (expr (atom (name L)))))))))->display()) ) else skip; operation solve(n : OclAny, x : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for a : xrange(1, n - 1) do ( if (x->compareTo(a)) <= 0 then ( break ) else skip ; for b : xrange(1 + a, n) do ( var ab : OclAny := a + b ; if (x->compareTo(ab)) <= 0 then ( break ) else skip ; for c : xrange(1 + b, n + 1) do ( var total : OclAny := ab + c ; if x = total then ( count := count + 1 ; break ) else skip ; if (x->compareTo(total)) < 0 then ( break ) else skip))) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : line=input().strip() if line=="0 0" : break else : line=line.split(" ") n=int(line[0])+1 x=int(line[1]) count=0 for i in range(1,n): for j in range(i+1,n): if i==j : continue else : for k in range(j+1,n): if i==k or j==k : continue else : if i+j+k==x : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var line : OclAny := input()->trim() ; if line = "0 0" then ( break ) else ( line := line.split(" ") ; var n : int := ("" + ((line->first())))->toInteger() + 1 ; var x : int := ("" + ((line[1+1])))->toInteger() ; var count : int := 0 ; for i : Integer.subrange(1, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if i = j then ( continue ) else ( for k : Integer.subrange(j + 1, n-1) do ( if i = k or j = k then ( continue ) else ( if i + j + k = x then ( count := count + 1 ) else skip )) ))) ; execute (count)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import prod input() a=input() print(0 if a.count("1")==0 else prod([i.count("0")+1 for i in a.strip("0 ").split('1')])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; input() ; var a : String := (OclFile["System.in"]).readLine() ; execute (if a->count("1") = 0 then 0 else prod(a->trim().split('1')->select(i | true)->collect(i | (i->count("0") + 1))) endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import itertools for line in sys.stdin : n,x=map(int,line.rstrip().split()) if n==0 and x==0 : break cnt=0 for case in itertools.combinations(range(1,n+1),3): if sum(case)==x : cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for line : OclFile["System.in"] do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (line.rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 & x = 0 then ( break ) else skip ; var cnt : int := 0 ; for case : itertools.combinations(Integer.subrange(1, n + 1-1), 3) do ( if (case)->sum() = x then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools import sys def main(): for line in sys.stdin : n,x=map(int,line.split()) if n==0 and x==0 : break else : seq=[i for i in range(1,n+1)] A=list(itertools.combinations(seq,3)) c=0 for i in range(len(A)): if sum(A[i])==x : c+=1 print(c) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: for line : OclFile["System.in"] do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (line.split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 & x = 0 then ( break ) else ( var seq : Sequence := Integer.subrange(1, n + 1-1)->select(i | true)->collect(i | (i)) ; var A : Sequence := (itertools.combinations(seq, 3)) ; var c : int := 0 ; for i : Integer.subrange(0, (A)->size()-1) do ( if (A[i+1])->sum() = x then ( c := c + 1 ) else skip) ; execute (c)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def computeXOR(n): switch={0 : n,1 : 1,2 : n+1,3 : 0,} return switch.get(n & 3,"") l=1 r=4 print(computeXOR(r)^ computeXOR(l-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var l : int := 1 ; var r : int := 4 ; execute (MathLib.bitwiseXor(computeXOR(r), computeXOR(l - 1)))->display(); operation computeXOR(n : OclAny) : OclAny pre: true post: true activity: var switch : Map := Map{ 0 |-> n }->union(Map{ 1 |-> 1 }->union(Map{ 2 |-> n + 1 }->union((dictorsetmaker (test (logical_test (comparison (expr (atom (number (integer 3))))))) : (test (logical_test (comparison (expr (atom (number (integer 0))))))) ,)))) ; return switch.get(MathLib.bitwiseAnd(n, 3), ""); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for s in[*open(0)][1 :]: a,b=map(int,s.split()); d=math.gcd(a,b); a=bin(a//d); b=bin(b//d); print((-1,0--abs(len(a)-len(b))//3)[{*a[3 :]}<={'0'}>={*b[3 :]}]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for s : OclFile.newOclFile_Write(OclFile.newOclFile(0))->tail() do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ); var d : long := (a)->gcd(b); var a : OclAny := bin(a div d); var b : OclAny := bin(b div d); execute (Sequence{-1, 0 - -((a)->size() - (b)->size())->abs() div 3}->select((Set{ a.subrange(3+1) }->compareTo(Set{ '0' })) <= 0 & (Set{ '0' } >= Set{ b.subrange(3+1) })))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def Topologicalsort(v): start=deque() for i in xrange(v): if indeg[i]==0 : start.append(i) if len(start)>1 : flag=True else : flag=False while len(start)>0 : i=start.popleft() ans.append(i) tmp=[] for j in g[i]: indeg[j]-=1 if indeg[j]==0 : tmp.append(j) start.append(j) if len(tmp)>1 : flag=True return ans,flag def solve(n,m): for i in xrange(m): wt,lt=map(int,raw_input().split()) wt-=1 ; lt-=1 g[wt].append(lt) indeg[lt]+=1 ans,flag=Topologicalsort(n) return ans,flag n=int(raw_input()) m=int(raw_input()) indeg=[0]*n g=[[]for _ in xrange(n)] ans=[] ans,flag=solve(n,m) if flag : for i in xrange(len(ans)): print(ans[i]+1) print(1) else : for i in xrange(n): print(ans[i]+1) print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := ("" + ((raw_input())))->toInteger() ; m := ("" + ((raw_input())))->toInteger() ; var indeg : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var g : Sequence := xrange(n)->select(_anon | true)->collect(_anon | (Sequence{})) ; var ans : Sequence := Sequence{} ; Sequence{ans,flag} := solve(n, m) ; if flag then ( for i : xrange((ans)->size()) do ( execute (ans[i+1] + 1)->display()) ; execute (1)->display() ) else ( for i : xrange(n) do ( execute (ans[i+1] + 1)->display()) ; execute (0)->display() ); operation Topologicalsort(v : OclAny) : OclAny pre: true post: true activity: var start : Sequence := () ; for i : xrange(v) do ( if indeg[i+1] = 0 then ( execute ((i) : start) ) else skip) ; if (start)->size() > 1 then ( var flag : boolean := true ) else ( flag := false ) ; while (start)->size() > 0 do ( var i : OclAny := start->first() ; start := start->tail() ; execute ((i) : ans) ; var tmp : Sequence := Sequence{} ; for j : g[i+1] do ( indeg[j+1] := indeg[j+1] - 1 ; if indeg[j+1] = 0 then ( execute ((j) : tmp) ; execute ((j) : start) ; if (tmp)->size() > 1 then ( flag := true ) else skip ) else skip)) ; return ans, flag; operation solve(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: for i : xrange(m) do ( var wt : OclAny := null; var lt : OclAny := null; Sequence{wt,lt} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; wt := wt - 1; lt := lt - 1 ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name wt)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name lt)))))))) )))) ; indeg[lt+1] := indeg[lt+1] + 1) ; var ans : OclAny := null; Sequence{ans,flag} := Topologicalsort(n) ; return ans, flag; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(100000) def main(): V,E=int(input()),int(input()) L=[] app=L.append visited=[0 for i in range(V)] edges=[[]for i in range(V)] def visit(x): if not visited[x]: visited[x]=1 for e in edges[x]: visit(e) app(x) for i in range(E): s,t=map(int,input().split()) edges[s-1].append(t-1) for i in range(V): if not visited[i]: visit(i) L.reverse() flag=0 temp=L[0] print(temp+1) for i in range(V-1): v=L[i+1] print(v+1) if not flag and itoInteger(),("" + (((OclFile["System.in"]).readLine())))->toInteger()} ; var L : Sequence := Sequence{} ; var app : OclAny := L.append ; var visited : Sequence := Integer.subrange(0, V-1)->select(i | true)->collect(i | (0)) ; var edges : Sequence := Integer.subrange(0, V-1)->select(i | true)->collect(i | (Sequence{})) ; skip ; for i : Integer.subrange(0, E-1) do ( var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name s))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name t))) - (expr (atom (number (integer 1)))))))))) ))))) ; for i : Integer.subrange(0, V-1) do ( if not(visited[i+1]) then ( visit(i) ) else skip) ; L := L->reverse() ; var flag : int := 0 ; var temp : OclAny := L->first() ; execute (temp + 1)->display() ; for i : Integer.subrange(0, V - 1-1) do ( var v : OclAny := L[i + 1+1] ; execute (v + 1)->display() ; if not(flag) & (i->compareTo(V - 1)) < 0 & ((edges[temp+1])->excludes(v)) then ( flag := 1 ) else skip ; temp := v) ; execute (flag)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=int(input()) edge=[[]for i in range(n)] visited=[0 for i in range(n)] maxpath=[-2 for i in range(n)] toposo=[] for i in range(m): x,y=map(int,input().split()) edge[y-1].append(x-1) def dfs(v): global visited,maxpath,toposo if visited[v]: return maxpath[v] visited[v]=1 if not(len(edge[v])): maxpath[v]=0 toposo.append(v) return 0 else : aa=0 for next in edge[v]: aa=max(aa,dfs(next)) maxpath[v]=aa+1 toposo.append(v) return aa+1 ansans=0 for vv in range(n): if not visited[vv]: ansans=max(ansans,dfs(vv)) for ans in toposo : print(ans+1) if ansans==n-1 : print("0") else : print("1") ------------------------------------------------------------ OCL File: --------- class FromPython { attribute visited : OclAny; attribute maxpath : OclAny; attribute toposo : OclAny; operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var edge : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Sequence{})) ; var visited : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var maxpath : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (-2)) ; var toposo : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name edge)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (number (integer 1)))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1)))))))))) ))))) ; skip ; var ansans : int := 0 ; for vv : Integer.subrange(0, n-1) do ( if not(visited[vv+1]) then ( ansans := Set{ansans, dfs(vv)}->max() ) else skip) ; for ans : toposo do ( execute (ans + 1)->display()) ; if ansans = n - 1 then ( execute ("0")->display() ) else ( execute ("1")->display() ); operation dfs(v : OclAny) : OclAny pre: true post: true activity: skip; skip; skip ; if visited[v+1] then ( return maxpath[v+1] ) else skip ; visited[v+1] := 1 ; if not(((edge[v+1])->size())) then ( maxpath[v+1] := 0 ; execute ((v) : toposo) ; return 0 ) else ( var aa : int := 0 ; for next : edge[v+1] do ( aa := Set{aa, dfs(next)}->max()) ; maxpath[v+1] := aa + 1 ; execute ((v) : toposo) ; return aa + 1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def output(i): global outputlist global winnerlist global reported if outputlist[i]: return else : outputlist[i]=1 for each in winnerlist[i]: output(each) print(i+1) reported.append(i) n=int(input()) m=int(input()) winnerlist=[[]for i in range(n+1)] outputlist=[0]*n reported=[] for i in range(m): winner,loser=map(int,input().split()) winner-=1 loser-=1 winnerlist[loser].append(winner) for i in range(n): output(i) isnotunique=0 for i in range(n-1): if not reported[i]in winnerlist[reported[i+1]]: isnotunique=1 break print(isnotunique) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute outputlist : OclAny; attribute winnerlist : OclAny; attribute reported : OclAny; operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; winnerlist := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Sequence{})) ; outputlist := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; reported := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var winner : OclAny := null; var loser : OclAny := null; Sequence{winner,loser} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; winner := winner - 1 ; loser := loser - 1 ; (expr (atom (name winnerlist)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name loser)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name winner)))))))) ))))) ; for i : Integer.subrange(0, n-1) do ( output(i)) ; var isnotunique : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if not((winnerlist[reported[i + 1+1]+1])->includes(reported[i+1])) then ( isnotunique := 1 ; break ) else skip) ; execute (isnotunique)->display(); operation output(i : OclAny) pre: true post: true activity: skip ; skip ; skip ; if outputlist[i+1] then ( return ) else ( outputlist[i+1] := 1 ) ; for each : winnerlist[i+1] do ( output(each)) ; execute (i + 1)->display() ; execute ((i) : reported); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys file_input=sys.stdin n=int(file_input.readline()) m=int(file_input.readline()) adj_list=[[]for i in range(n+1)] indeg=[0]*(n+1) for line in file_input : i,j=map(int,line.split()) adj_list[i].append(j) indeg[j]+=1 unvisited=[True]*(n+1) from collections import deque q=deque() ans=[] def bfs(s): q.append(s) unvisited[s]=False while q : u=q.popleft() ans.append(u) for v in adj_list[u]: indeg[v]-=1 if indeg[v]==0 and unvisited[v]: unvisited[v]=False q.append(v) for s in range(1,n+1): if indeg[s]==0 and unvisited[s]: bfs(s) print(*ans,sep='\n') for s,t in zip(ans,ans[1 :]): if t not in adj_list[s]: print(1) break else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var file_input : OclFile := OclFile["System.in"] ; var n : int := ("" + ((file_input.readLine())))->toInteger() ; var m : int := ("" + ((file_input.readLine())))->toInteger() ; var adj_list : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Sequence{})) ; var indeg : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for line : file_input do ( var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := (line.split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name adj_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) )))) ; indeg[j+1] := indeg[j+1] + 1) ; var unvisited : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (n + 1)) ; skip ; var q : Sequence := () ; var ans : Sequence := Sequence{} ; skip ; for s : Integer.subrange(1, n + 1-1) do ( if indeg[s+1] = 0 & unvisited[s+1] then ( bfs(s) ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ; (compound_stmt for (exprlist (expr (atom (name s))) , (expr (atom (name t)))) in (testlist (test (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans))))))) , (argument (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name t)))) not in (comparison (expr (atom (name adj_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))))))))))))))); operation bfs(s : OclAny) pre: true post: true activity: execute ((s) : q) ; unvisited[s+1] := false ; while q do ( var u : OclAny := q->first() ; q := q->tail() ; execute ((u) : ans) ; for v : adj_list[u+1] do ( indeg[v+1] := indeg[v+1] - 1 ; if indeg[v+1] = 0 & unvisited[v+1] then ( unvisited[v+1] := false ; execute ((v) : q) ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,m=map(int,input().split()) if n==0 : break lst=[] for _ in range(n): num,x=input().split() lst.append((num,int(x))) ans=0 for _ in range(m): b=input() for num,x in lst : for i in range(8): if num[i]=="*" or num[i]==b[i]: continue else : break else : ans+=x break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var lst : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var num : OclAny := null; var x : OclAny := null; Sequence{num,x} := input().split() ; execute ((Sequence{num, ("" + ((x)))->toInteger()}) : lst)) ; var ans : int := 0 ; for _anon : Integer.subrange(0, m-1) do ( var b : String := (OclFile["System.in"]).readLine() ; for _tuple : lst do (var _indx : int := 1; var num : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 8))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name num)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom "*"))))) or (logical_test (comparison (comparison (expr (atom (name num)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (name b)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) : (suite (simple_stmt (small_stmt continue))) (else_clause else : (suite (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name x))))))))))) (stmt (simple_stmt (small_stmt break)))))))) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() arr=list(map(int,input().split(" "))) one_indices=[] for i in range(len(arr)): if arr[i]==1 : one_indices.append(i) if len(one_indices)<=1 : print(len(one_indices)) elif len(one_indices)==len(arr): print(1) else : num_ways=1 for i in range(1,len(one_indices)): num_ways*=one_indices[i]-one_indices[i-1] print(num_ways) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var arr : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var one_indices : Sequence := Sequence{} ; for i : Integer.subrange(0, (arr)->size()-1) do ( if arr[i+1] = 1 then ( execute ((i) : one_indices) ) else skip) ; if (one_indices)->size() <= 1 then ( execute ((one_indices)->size())->display() ) else (if (one_indices)->size() = (arr)->size() then ( execute (1)->display() ) else ( var num_ways : int := 1 ; for i : Integer.subrange(1, (one_indices)->size()-1) do ( num_ways := num_ways * one_indices[i+1] - one_indices[i - 1+1]) ; execute (num_ways)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Com(a,b): list_a=list(a) list_b=list(b) list_a.reverse() list_b.reverse() while '*' in list_a : list_a.remove('*') ans=True for i in range(len(list_a)): if list_a[i]!=list_b[i]: ans=False break return ans while True : n,m=map(int,input().split()) if n==0 and m==0 : break atari=[] money=[] for i in range(n): a,b=input().split() atari.append(a) money.append(int(b)) cost=0 for i in range(m): s=input() for j in range(n): if Com(atari[j],s)==True : cost+=money[j] print(cost) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 & m = 0 then ( break ) else skip ; var atari : Sequence := Sequence{} ; var money : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( Sequence{a,b} := input().split() ; execute ((a) : atari) ; execute ((("" + ((b)))->toInteger()) : money)) ; var cost : int := 0 ; for i : Integer.subrange(0, m-1) do ( var s : String := (OclFile["System.in"]).readLine() ; for j : Integer.subrange(0, n-1) do ( if Com(atari[j+1], s) = true then ( cost := cost + money[j+1] ) else skip)) ; execute (cost)->display()); operation Com(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var list_a : Sequence := (a) ; var list_b : Sequence := (b) ; list_a := list_a->reverse() ; list_b := list_b->reverse() ; while (list_a)->includes('*') do ( execute (('*') /: list_a)) ; var ans : boolean := true ; for i : Integer.subrange(0, (list_a)->size()-1) do ( if list_a[i+1] /= list_b[i+1] then ( ans := false ; break ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,m=map(int,input().split()) if n==0 : break h=[input().split()for _ in range(n)] t=[input()for _ in range(m)] c=0 for kuji in t : for atari in h : for i in range(len(kuji)): if atari[0][i]!="*" and kuji[i]!=atari[0][i]: break else : c+=int(atari[1]) break print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var h : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (input().split())) ; var t : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var c : int := 0 ; for kuji : t do ( for atari : h do ((compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name kuji)))))))) ))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name atari)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) != (comparison (expr (atom "*"))))) and (logical_test (comparison (comparison (expr (atom (name kuji)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) != (comparison (expr (atom (name atari)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name atari)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re while 1 : n,m=map(int,input().split()) if n==0 : break p=[]; s=0 for _ in[0]*n : n,M=input().replace('*','[0-9]').split() p.append([re.compile(n),int(M)]) for _ in[0]*m : l=input() for n,M in p : if n.search(l): s+=M ; break print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while 1 do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var p : Sequence := Sequence{}; var s : int := 0 ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, n) do ( var n : OclAny := null; var M : OclAny := null; Sequence{n,M} := input().replace('*', '[0-9]').split() ; execute ((Sequence{OclRegex.compile(n)}->union(Sequence{ ("" + ((M)))->toInteger() })) : p)) ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, m) do ( var l : String := (OclFile["System.in"]).readLine() ; for _tuple : p do (var _indx : int := 1; var n : OclAny := _tuple->at(_indx); _indx := _indx + 1; var M : OclAny := _tuple->at(_indx); if n.search(l) then ( s := s + M; break ) else skip)) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,m=map(int,input().split()) if n==0 : break N,M=zip(*[[x.strip("*")if i==0 else int(x)for i,x in enumerate(input().split())]for _ in range(n)]) print(sum([M[i]for b in[input()for _ in range(m)]for i,x in enumerate(N)if b.endswith(x)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name x)) (trailer . (name strip) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "*"))))))) )))))) if (logical_test (comparison (comparison (expr (atom (name i)))) == (comparison (expr (atom (number (integer 0))))))) else (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))))) ]))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) ]))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name x)) (trailer . (name strip) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "*"))))))) )))))) if (logical_test (comparison (comparison (expr (atom (name i)))) == (comparison (expr (atom (number (integer 0))))))) else (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))))) ]))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) ]))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name x)) (trailer . (name strip) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "*"))))))) )))))) if (logical_test (comparison (comparison (expr (atom (name i)))) == (comparison (expr (atom (number (integer 0))))))) else (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))))))) (comp_for for (exprlist (expr (atom (name i))) , (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))))) ]))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) ]))))))`third->at(_indx)} ) ; execute ((Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine()))->select(b; _tuple : Integer.subrange(1, (N)->size())->collect( _indx | Sequence{_indx-1, (N)->at(_indx)} ) | true)->collect(b; _tuple : Integer.subrange(1, (N)->size())->collect( _indx | Sequence{_indx-1, (N)->at(_indx)} ) | (M[i+1])))->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def _input(): return map(int,input().split()) for _ in range(int(input())): a,b=_input() res=0 if(a % b==0)or(b % a==0): res=0 t=(a//b if a>=b else b//a) while t % 8==0 : t//=8 ; res+=1 while t % 4==0 : t//=4 ; res+=1 while t % 2==0 : t//=2 ; res+=1 if a==b : print(0) elif res==0 or t!=1 : print(-1) else : print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := _input() ; var res : int := 0 ; if (a mod b = 0) or (b mod a = 0) then ( res := 0 ; var t : int := (if (a->compareTo(b)) >= 0 then a div b else b div a endif) ; while t mod 8 = 0 do ( t := t div 8; res := res + 1) ; while t mod 4 = 0 do ( t := t div 4; res := res + 1) ; while t mod 2 = 0 do ( t := t div 2; res := res + 1) ) else skip ; if a = b then ( execute (0)->display() ) else (if res = 0 or t /= 1 then ( execute (-1)->display() ) else ( execute (res)->display() ) ) ); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) print(2*(min(a,b)+c)+(a!=b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (2 * (Set{a, b}->min() + c) + (a /= b))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) max_length=0 max_length=b*2 if ba else(0,a-b) if b!=0 : max_length+=1 elif a!=0 : max_length+=1 max_length+=c*2 print(max_length) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var max_length : int := 0 ; max_length := if (b->compareTo(a)) < 0 then b * 2 else a * 2 endif ; var b : OclAny := null; var a : OclAny := null; Sequence{b,a} := if (b->compareTo(a)) > 0 then Sequence{b - a, 0} else Sequence{0, a - b} endif ; if b /= 0 then ( max_length := max_length + 1 ) else (if a /= 0 then ( max_length := max_length + 1 ) else skip) ; max_length := max_length + c * 2 ; execute (max_length)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) print(2*c+min(a,b)*2+(a!=b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (2 * c + Set{a, b}->min() * 2 + (a /= b))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import os import random import re import sys from math import gcd from math import sqrt a,b,c=list(map(int,input().split())) d=2*c+min(a,b)+min(max(a,b),min(a,b)+1) print(d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : double := 2 * c + Set{a, b}->min() + Set{Set{a, b}->max(), Set{a, b}->min() + 1}->min() ; execute (d)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=input().split() a=int(a) b=int(b) c=int(c) b=min(a+1,b) a=min(b+1,a) print(c*2+a+b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := input().split() ; var a : int := ("" + ((a)))->toInteger() ; var b : int := ("" + ((b)))->toInteger() ; var c : int := ("" + ((c)))->toInteger() ; b := Set{a + 1, b}->min() ; a := Set{b + 1, a}->min() ; execute (c * 2 + a + b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) first_1=False ans=1 count=1 for i in a : if i==1 : first_1=True ans=ans*count count=1 else : if first_1==True : count+=1 if first_1==False : print(0) else : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var first var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() : boolean := false ; var ans : int := 1 ; var count : int := 1 ; for i : a do ( if i = 1 then ( first var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() := true ; ans := ans * count ; count := 1 ) else ( if first var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() = true then ( count := count + 1 ) else skip )) ; if first var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() = false then ( execute (0)->display() ) else ( execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def EvenOddAbsoluteDifference(arr,n): even=0 odd=0 for i in range(0,n,1): if(i % 2==0): even=abs(even-arr[i]); else : odd=abs(odd-arr[i]); print("Even Index absolute difference :",even) print("Odd Index absolute difference :",odd) if __name__=='__main__' : arr=[1,2,3,4,5,6] n=len(arr) EvenOddAbsoluteDifference(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))))) ; n := (arr)->size() ; EvenOddAbsoluteDifference(arr, n) ) else skip; operation EvenOddAbsoluteDifference(arr : OclAny, n : OclAny) pre: true post: true activity: var even : int := 0 ; var odd : int := 0 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (i mod 2 = 0) then ( even := (even - arr[i+1])->abs(); ) else ( odd := (odd - arr[i+1])->abs(); )) ; execute ("Even Index absolute difference :")->display() ; execute ("Odd Index absolute difference :")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- max=10000 dp=[0]*max def initDP(): for i in range(max): dp[i]=-1 def func(x): if(x==0): return 0 if(dp[x]==-1): dp[x]=x+func(x//2) return dp[x] def printFloor(arr,n): for i in range(n): print(func(arr[i]),end=" ") if __name__=="__main__" : initDP() arr=[8,6] n=len(arr) printFloor(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var max : int := 10000 ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, max) ; skip ; skip ; skip ; if __name__ = "__main__" then ( initDP() ; arr := Sequence{8}->union(Sequence{ 6 }) ; n := (arr)->size() ; printFloor(arr, n) ) else skip; operation initDP() pre: true post: true activity: for i : Integer.subrange(0, max-1) do ( dp[i+1] := -1); operation func(x : OclAny) : OclAny pre: true post: true activity: if (x = 0) then ( return 0 ) else skip ; if (dp[x+1] = -1) then ( dp[x+1] := x + func(x div 2) ) else skip ; return dp[x+1]; operation printFloor(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (func(arr[i+1]))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque n,q=map(int,input().split()) L=[deque()for _ in range(n)] for _ in range(q): command,*list_num=input().split() if command=="0" : t=int(list_num[0]) x=int(list_num[1]) L[t].append(x) elif command=="1" : t=int(list_num[0]) print(*L[t]) elif command=="2" : s=int(list_num[0]) t=int(list_num[1]) if not L[s]: continue if L[t]: if len(L[s])==1 : L[t].append(L[s][0]) elif len(L[t])==1 : L[s].appendleft(L[t][0]) L[t]=L[s] else : L[t].extend(L[s]) else : L[t]=L[s] L[s]=deque() else : raise ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var L : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (())) ; for _anon : Integer.subrange(0, q-1) do ( var command : OclAny := null; var list_num : OclAny := null; Sequence{command,list_num} := input().split() ; if command = "0" then ( var t : int := ("" + ((list_num->first())))->toInteger() ; var x : int := ("" + ((list_num[1+1])))->toInteger() ; (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) ) else (if command = "1" then ( t := ("" + ((list_num->first())))->toInteger() ; execute ((argument * (test (logical_test (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ]))))))))->display() ) else (if command = "2" then ( var s : int := ("" + ((list_num->first())))->toInteger() ; t := ("" + ((list_num[1+1])))->toInteger() ; if not(L[s+1]) then ( continue ) else skip ; if L[t+1] then ( if (L[s+1])->size() = 1 then ( (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))) ) else (if (L[t+1])->size() = 1 then ( (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])) (trailer . (name appendleft) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))) ; L[t+1] := L[s+1] ) else ( (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name extend) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])))))))) )))) ) ) ) else ( L[t+1] := L[s+1] ) ; L[s+1] := () ) else ( (small_stmt raise) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,value): self.value=value self.next=None class List : def __init__(self): self.head=None self.tail=None def insert(self,v): node=Node(v) if self.tail is None : self.head=node self.tail=node else : self.tail.next=node self.tail=node def dump(self): node=self.head while node is not None : yield node.value node=node.next def splice(self,li): if self.head is None : self.head=li.head self.tail=li.tail else : self.tail.next=li.head self.tail=li.tail li.clear() def clear(self): self.head=None self.tail=None def run(): n,q=[int(x)for x in input().split()] ls=[List()for _ in range(n)] for _ in range(q): com=[int(x)for x in input().split()] c=com[0] if c==0 : t,v=com[1 :] ls[t].insert(v) elif c==1 : t=com[1] values=[] for v in ls[t].dump(): values.append(str(v)) print(" ".join(values)) elif c==2 : s,t=com[1 :] ls[t].splice(ls[s]) else : raise ValueError('invalid command') if __name__=='__main__' : run() ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute value : OclAny := value; attribute next : OclAny := null; operation initialise(value : OclAny) : Node pre: true post: true activity: self.value := value ; self.next := null; return self; } class List { static operation newList() : List pre: true post: List->exists( _x | result = _x ); attribute head : OclAny := null; attribute tail : OclAny := null; operation initialise() : List pre: true post: true activity: self.head := null ; self.tail := null; return self; operation insert(v : OclAny) pre: true post: true activity: var node : Node := (Node.newNode()).initialise(v) ; if self.tail <>= null then ( self.head := node ; self.tail := node ) else ( self.tail.next := node ; self.tail := node ); operation dump() pre: true post: true activity: node := self.head ; while not(node <>= null) do ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return node.value ; node := node.next); operation splice(li : OclAny) pre: true post: true activity: if self.head <>= null then ( self.head := li.head ; self.tail := li.tail ) else ( self.tail.next := li.head ; self.tail := li.tail ) ; execute (li /<: li); operation clear() pre: true post: true activity: self.head := null ; self.tail := null; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( run() ) else skip; operation run() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ls : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((List.newList()).initialise())) ; for _anon : Integer.subrange(0, q-1) do ( var com : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var c : OclAny := com->first() ; if c = 0 then ( var t : OclAny := null; Sequence{t,v} := com->tail() ; (expr (atom (name ls)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name insert) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) ) else (if c = 1 then ( var t : OclAny := com[1+1] ; var values : Sequence := Sequence{} ; for v : ls[t+1].dump() do ( execute ((("" + ((v)))) : values)) ; execute (StringLib.sumStringsWithSeparator((values), " "))->display() ) else (if c = 2 then ( var s : OclAny := null; Sequence{s,t} := com->tail() ; (expr (atom (name ls)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name splice) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ls)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])))))))) )))) ) else ( error IncorrectElementException.newIncorrectElementException('invalid command') ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import defaultdict,deque sys.stdin.readline().split() A=defaultdict(deque) ans=[] for query in sys.stdin : if query[0]=='0' : t,x=query[2 :].split() A[t].append(x) elif query[0]=='1' : ans.append(' '.join(A[query[2 :-1]])+'\n') else : s,t=query[2 :].split() if A[t]: if len(A[s])==1 : A[t].append(A[s][0]) elif len(A[t])==1 : A[s].appendleft(A[t][0]) A[t]=A[s] else : A[t].extend(A[s]) else : A[t]=A[s] A[s]=deque() sys.stdout.writelines(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; (expr (atom (name sys)) (trailer . (name stdin)) (trailer . (name readline) (arguments ( ))) (trailer . (name split) (arguments ( )))) ; var A : OclAny := defaultdict(deque) ; var ans : Sequence := Sequence{} ; for query : OclFile["System.in"] do ( if query->first() = '0' then ( var t : OclAny := null; var x : OclAny := null; Sequence{t,x} := query.subrange(2+1).split() ; (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) )))) ) else (if query->first() = '1' then ( execute ((StringLib.sumStringsWithSeparator((A[query.subrange(2+1, -1)+1]), ' ') + ' ') : ans) ) else ( var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := query.subrange(2+1).split() ; if A[t+1] then ( if (A[s+1])->size() = 1 then ( (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))) ) else (if (A[t+1])->size() = 1 then ( (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])) (trailer . (name appendleft) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))) ; A[t+1] := A[s+1] ) else ( (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name extend) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])))))))) )))) ) ) ) else ( A[t+1] := A[s+1] ) ; A[s+1] := () ) ) ) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name writelines) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b=map(int,input().split()) step=0 while b>a : step+=1 if a*8<=b : a*=8 elif a*4<=b : a*=4 elif a*2<=b : a*=2 else : break while a>b : step+=1 if a//8>=b and a % 8==0 : a//=8 elif a//4>=b and a % 4==0 : a//=4 elif a//2>=b and a % 2==0 : a//=2 else : break if(a==b): print(step) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var step : int := 0 ; while (b->compareTo(a)) > 0 do ( step := step + 1 ; if (a * 8->compareTo(b)) <= 0 then ( a := a * 8 ) else (if (a * 4->compareTo(b)) <= 0 then ( a := a * 4 ) else (if (a * 2->compareTo(b)) <= 0 then ( a := a * 2 ) else ( break ) ) ) ) ; while (a->compareTo(b)) > 0 do ( step := step + 1 ; if (a div 8->compareTo(b)) >= 0 & a mod 8 = 0 then ( a := a div 8 ) else (if (a div 4->compareTo(b)) >= 0 & a mod 4 = 0 then ( a := a div 4 ) else (if (a div 2->compareTo(b)) >= 0 & a mod 2 = 0 then ( a := a div 2 ) else ( break ) ) ) ) ; if (a = b) then ( execute (step)->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq import collections import sys input=sys.stdin.readline n,q=map(int,input().split()) L=[collections.deque()for i in range(n)] queries=list() for i in range(q): queries.append(list(map(int,input().split()))) for query in queries : if query[0]==0 : L[query[1]].append(query[2]) elif query[0]==1 : print(*L[query[1]]) elif query[0]==2 : if L[query[2]]: if len(L[query[1]])==1 : L[query[2]].append(L[query[1]][0]) elif len(L[query[2]])==1 : L[query[1]].appendleft(L[query[2]][0]) L[query[2]]=L[query[1]] else : L[query[2]].extend(L[query[1]]) else : L[query[2]]=L[query[1]] L[query[1]]=collections.deque() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var L : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (())) ; var queries : Sequence := () ; for i : Integer.subrange(0, q-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : queries)) ; for query : queries do ( if query->first() = 0 then ( (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name query)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name query)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))) )))) ) else (if query->first() = 1 then ( execute ((argument * (test (logical_test (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name query)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ]))))))))->display() ) else (if query->first() = 2 then ( if L[query[2+1]+1] then ( if (L[query[1+1]+1])->size() = 1 then ( (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name query)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name query)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))) ) else (if (L[query[2+1]+1])->size() = 1 then ( (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name query)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ])) (trailer . (name appendleft) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name query)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))) ; L[query[2+1]+1] := L[query[1+1]+1] ) else ( (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name query)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))))))) ])) (trailer . (name extend) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name query)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ])))))))) )))) ) ) ) else ( L[query[2+1]+1] := L[query[1+1]+1] ) ; L[query[1+1]+1] := () ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,val=None,prev=None,next=None): self.val=val self.prev=prev self.next=next class DoublyLinkedList(): def __init__(self): self.start=Node(val='START',prev=None,next=None) self.end=Node(val='END',prev=self.start,next=None) self.start.next=self.end def insert(self,x): new_node=Node(val=x,prev=self.end.prev,next=self.end) self.end.prev.next=new_node self.end.prev=new_node def dump(self): node_list=[] crnode=self.start.next while crnode!=self.end : node_list.append(crnode.val) crnode=crnode.next print(' '.join(list(map(str,node_list)))) def extend(self,dll): self.end.prev.next=dll.start.next dll.start.next.prev=self.end.prev self.end=dll.end n,q=list(map(int,input().split(' '))) splice=[DoublyLinkedList()for i in range(n)] for i in range(q): op,*val=list(map(int,input().split(' '))) if op==0 : splice[val[0]].insert(val[1]) elif op==1 : splice[val[0]].dump() else : splice[val[1]].extend(splice[val[0]]) splice[val[0]]=DoublyLinkedList() ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute val : OclAny := val; attribute prev : OclAny := prev; attribute next : OclAny := next; operation initialise(val : OclAny,prev : OclAny,next : OclAny) : Node pre: true post: true activity: self.val := val ; self.prev := prev ; self.next := next; return self; } class DoublyLinkedList { static operation newDoublyLinkedList() : DoublyLinkedList pre: true post: DoublyLinkedList->exists( _x | result = _x ); attribute start : Node := (Node.newNode()).initialise((argument (test (logical_test (comparison (expr (atom (name val)))))) = (test (logical_test (comparison (expr (atom 'START')))))), (argument (test (logical_test (comparison (expr (atom (name prev)))))) = (test (logical_test (comparison (expr (atom None)))))), (argument (test (logical_test (comparison (expr (atom (name next)))))) = (test (logical_test (comparison (expr (atom None))))))); attribute end : Node := (Node.newNode()).initialise((argument (test (logical_test (comparison (expr (atom (name val)))))) = (test (logical_test (comparison (expr (atom 'END')))))), (argument (test (logical_test (comparison (expr (atom (name prev)))))) = (test (logical_test (comparison (expr (atom (name self)) (trailer . (name start))))))), (argument (test (logical_test (comparison (expr (atom (name next)))))) = (test (logical_test (comparison (expr (atom None))))))); attribute (expr (atom (name self)) (trailer . (name start)) (trailer . (name next))) : OclAny := self.end; operation initialise() : Node pre: true post: true activity: self.start := (Node.newNode()).initialise((argument (test (logical_test (comparison (expr (atom (name val)))))) = (test (logical_test (comparison (expr (atom 'START')))))), (argument (test (logical_test (comparison (expr (atom (name prev)))))) = (test (logical_test (comparison (expr (atom None)))))), (argument (test (logical_test (comparison (expr (atom (name next)))))) = (test (logical_test (comparison (expr (atom None))))))) ; self.end := (Node.newNode()).initialise((argument (test (logical_test (comparison (expr (atom (name val)))))) = (test (logical_test (comparison (expr (atom 'END')))))), (argument (test (logical_test (comparison (expr (atom (name prev)))))) = (test (logical_test (comparison (expr (atom (name self)) (trailer . (name start))))))), (argument (test (logical_test (comparison (expr (atom (name next)))))) = (test (logical_test (comparison (expr (atom None))))))) ; self.start.next := self.end; return self; operation insert(x : OclAny) pre: true post: true activity: var new_node : Node := (Node.newNode()).initialise((argument (test (logical_test (comparison (expr (atom (name val)))))) = (test (logical_test (comparison (expr (atom (name x))))))), (argument (test (logical_test (comparison (expr (atom (name prev)))))) = (test (logical_test (comparison (expr (atom (name self)) (trailer . (name end)) (trailer . (name prev))))))), (argument (test (logical_test (comparison (expr (atom (name next)))))) = (test (logical_test (comparison (expr (atom (name self)) (trailer . (name end)))))))) ; self.end.prev.next := new_node ; self.end.prev := new_node; operation dump() pre: true post: true activity: var node_list : Sequence := Sequence{} ; var crnode : OclAny := self.start.next ; while crnode /= self.end do ( execute ((crnode.val) : node_list) ; crnode := crnode.next) ; execute (StringLib.sumStringsWithSeparator((((node_list)->collect( _x | (OclType["String"])->apply(_x) ))), ' '))->display(); operation extend(dll : OclAny) pre: true post: true activity: self.end.prev.next := dll.start.next ; dll.start.next.prev := self.end.prev ; self.end := dll.end; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var splice : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((DoublyLinkedList.newDoublyLinkedList()).initialise())) ; for i : Integer.subrange(0, q-1) do ( var op : OclAny := null; var val : OclAny := null; Sequence{op,val} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; if op = 0 then ( (expr (atom (name splice)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name val)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])) (trailer . (name insert) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name val)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))) ) else (if op = 1 then ( (expr (atom (name splice)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name val)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])) (trailer . (name dump) (arguments ( )))) ) else ( (expr (atom (name splice)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name val)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ])) (trailer . (name extend) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name splice)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name val)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])))))))) )))) ; splice[val->first()+1] := (DoublyLinkedList.newDoublyLinkedList()).initialise() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): S=input() n=len(S) if(n>10): print(S[0]+str(n-2)+S[n-1]) return print(S) t=int(input()) for _ in range(t): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( solve()); operation solve() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var n : int := (S)->size() ; if (n > 10) then ( execute (S->first() + ("" + ((n - 2))) + S[n - 1+1])->display() ; return ) else skip ; execute (S)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): t=input() a=[x for x in t] if(len(t)<=10): print(t) else : l=len(t)-2 print(a[0]+str(l)+a[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var t : String := (OclFile["System.in"]).readLine() ; var a : Sequence := t->characters()->select(x | true)->collect(x | (x)) ; if ((t)->size() <= 10) then ( execute (t)->display() ) else ( var l : double := (t)->size() - 2 ; execute (a->first() + ("" + ((l))) + a->last())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=list(map(int,input().split())) if s.count(1)==1 : print(1) elif s.count(1)==0 : print(0) else : c=1 v=1 for i in s[s.index(1):]: if i==1 : c*=v v=1 elif i==0 : v+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if s->count(1) = 1 then ( execute (1)->display() ) else (if s->count(1) = 0 then ( execute (0)->display() ) else ( var c : int := 1 ; var v : int := 1 ; for i : s.subrange(s->indexOf(1) - 1+1) do ( if i = 1 then ( c := c * v ; v := 1 ) else (if i = 0 then ( v := v + 1 ) else skip)) ; execute (c)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): word=input() if len(word)>10 : print(word[0]+str(len(word)-2)+word[-1]) else : print(word) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var word : String := (OclFile["System.in"]).readLine() ; if (word)->size() > 10 then ( execute (word->first() + ("" + (((word)->size() - 2))) + word->last())->display() ) else ( execute (word)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): sl=input() if len(sl)>10 : print(sl[0]+str(len(sl)-2)+sl[-1]) else : print(sl) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var sl : String := (OclFile["System.in"]).readLine() ; if (sl)->size() > 10 then ( execute (sl->first() + ("" + (((sl)->size() - 2))) + sl->last())->display() ) else ( execute (sl)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): word=input() if len(word)>10 : print(word[0]+str(len(word)-2)+word[-1]) else : print(word) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var word : String := (OclFile["System.in"]).readLine() ; if (word)->size() > 10 then ( execute (word->first() + ("" + (((word)->size() - 2))) + word->last())->display() ) else ( execute (word)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys f=sys.stdin def drop(paper,x,y): if 0<=xselect(i | true)->collect(i | (Integer.subrange(0, 10-1)->select(j | true)->collect(j | (0)))) ; for line : f do ( var size : OclAny := null; Sequence{x,y,size} := (line.split(','))->collect( _x | (OclType["int"])->apply(_x) ) ; for _tuple : drop_range[size+1] do (var _indx : int := 1; var dx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dy : OclAny := _tuple->at(_indx); drop(paper, x + dx, y + dy))) ; paper := paper->select(y; x : y | true)->collect(y; x : y | (x)) ; execute (((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name thick)))) in (logical_test (comparison (expr (atom (name paper))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name thick)))) == (comparison (expr (atom (number (integer 0))))))))))))->sum())->display() ; execute ((paper)->max())->display(); operation drop(paper : OclAny, x : OclAny, y : OclAny) pre: true post: true activity: if 0 <= x & (x < (paper->first())->size()) & 0 <= y & (y < (paper)->size()) then ( paper[y+1][x+1] := paper[y+1][x+1] + 1 ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- Masu=[] def access(x,y): if x<0 or y<0 or x>9 or y>9 : return Masu[y][x]+=1 for i in range(10): Masu.append([0,0,0,0,0,0,0,0,0,0]) kosu=0 komax=0 while True : try : x,y,s=map(int,input().split(",")) if s==1 : for j in range(3): access(y+1-j,x) access(y,x-1) access(y,x+1) elif s==2 : for k in range(3): for l in range(3): access(y+1-k,x+1-l) elif s==3 : for k in range(3): for l in range(3): access(y+1-k,x+1-l) access(y-2,x) access(y+2,x) access(y,x+2) access(y,x-2) except(EOFError,ValueError): for i in range(10): kosu+=Masu[i].count(0) for j in range(10): if komaxunion(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))))))))) : Masu)) ; var kosu : int := 0 ; var komax : int := 0 ; while true do ( try ( var s : OclAny := null; Sequence{x,y,s} := (input().split(","))->collect( _x | (OclType["int"])->apply(_x) ) ; if s = 1 then ( for j : Integer.subrange(0, 3-1) do ( access(y + 1 - j, x)) ; access(y, x - 1) ; access(y, x + 1) ) else (if s = 2 then ( for k : Integer.subrange(0, 3-1) do ( for l : Integer.subrange(0, 3-1) do ( access(y + 1 - k, x + 1 - l))) ) else (if s = 3 then ( for k : Integer.subrange(0, 3-1) do ( for l : Integer.subrange(0, 3-1) do ( access(y + 1 - k, x + 1 - l))) ; access(y - 2, x) ; access(y + 2, x) ; access(y, x + 2) ; access(y, x - 2) ) else skip ) ) ) (except_clause except (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name EOFError)))))) , (test (logical_test (comparison (expr (atom (name ValueError))))))) )))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 10))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name kosu)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name Masu)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 10))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name komax)))) < (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name Masu)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name komax)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name Masu)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) ))))))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name kosu)))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name komax)))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))); operation access(x : OclAny, y : OclAny) pre: true post: true activity: if x < 0 or y < 0 or x > 9 or y > 9 then ( return ) else skip ; Masu[y+1][x+1] := Masu[y+1][x+1] + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readlines=sys.stdin.readlines write=sys.stdout.write def solve(): P=[] for line in readlines(): x,y,s=map(int,line.split(",")) P.append((x,y,s)) L=10 MP=[[0]*L for i in range(L)] def update(k,ps): for x,y,s in P : if k<=s : for dx,dy in ps : nx=x+dx ; ny=y+dy if not 0<=nxcollect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{x, y, s}) : P)) ; var L : int := 10 ; var MP : Sequence := Integer.subrange(0, L-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, L))) ; skip ; update(0, Sequence{ Sequence{0, 0} }) ; update(1, Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{0, -1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{ Sequence{0, 1} })))) ; update(2, Sequence{Sequence{-1, -1}}->union(Sequence{Sequence{1, -1}}->union(Sequence{Sequence{-1, 1}}->union(Sequence{ Sequence{1, 1} })))) ; update(3, Sequence{Sequence{-2, 0}}->union(Sequence{Sequence{0, -2}}->union(Sequence{Sequence{2, 0}}->union(Sequence{ Sequence{0, 2} })))) ; var z : OclAny := 0; var m : int := 0 ; for i : Integer.subrange(0, L-1) do ( for j : Integer.subrange(0, L-1) do ( if MP[i+1][j+1] = 0 then ( z := z + 1 ) else skip ; m := Set{m, MP[i+1][j+1]}->max())) ; write(StringLib.format("%d\n%d\n",Sequence{z, m})); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def GetMinSubarrayLength(a,n): ans=max(a[0],a[n-1]) lo=0 hi=n-1 while(lolo and a[hi]% ans==0): hi-=1 return(hi-lo+1) if __name__=='__main__' : arr=[4,8,2,1,4] N=len(arr) length=GetMinSubarrayLength(arr,N) print(length) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var arr : Sequence := Sequence{4}->union(Sequence{8}->union(Sequence{2}->union(Sequence{1}->union(Sequence{ 4 })))) ; var N : int := (arr)->size() ; var length : OclAny := GetMinSubarrayLength(arr, N) ; execute (length)->display() ) else skip; operation GetMinSubarrayLength(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : OclAny := Set{a->first(), a[n - 1+1]}->max() ; var lo : int := 0 ; var hi : double := n - 1 ; while ((lo->compareTo(n)) < 0 & a[lo+1] mod ans = 0) do ( lo := lo + 1) ; while ((hi->compareTo(lo)) > 0 & a[hi+1] mod ans = 0) do ( hi := hi - 1) ; return (hi - lo + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(0,int(input())): a,b=sorted(map(int,input().split())) v=b//a x=0 w=3 if(b % a==0)and(v &(v-1)==0): while v>1 : if v %(2**w)==0 : v//=(2**w) x+=1 else : w-=1 print(x) else : print("-1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var v : int := b div a ; var x : int := 0 ; var w : int := 3 ; if (b mod a = 0) & (MathLib.bitwiseAnd(v, (v - 1)) = 0) then ( while v > 1 do ( if v mod ((2)->pow(w)) = 0 then ( v := v div ((2)->pow(w)) ; x := x + 1 ) else ( w := w - 1 )) ; execute (x)->display() ) else ( execute ("-1")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def small(paper,x,y): paper[x][y]+=1 paper[x-1][y]+=1 paper[x][y-1]+=1 paper[x][y+1]+=1 paper[x+1][y]+=1 def medium(paper,x,y): small(paper,x,y) paper[x-1][y-1]+=1 paper[x-1][y+1]+=1 paper[x+1][y-1]+=1 paper[x+1][y+1]+=1 def large(paper,x,y): medium(paper,x,y) paper[x-2][y]+=1 paper[x][y-2]+=1 paper[x][y+2]+=1 paper[x+2][y]+=1 def drop(paper,x,y,size): if size==1 : small(paper,x,y) elif size==2 : medium(paper,x,y) else : large(paper,x,y) return paper paper=[[0 for i in range(14)]for j in range(14)] for s in sys.stdin : x,y,size=map(int,s.split(',')) paper=drop(paper,x+2,y+2,size) empty=0 deep=0 for i in range(10): for j in range(10): if paper[i+2][j+2]==0 : empty+=1 elif paper[i+2][j+2]>deep : deep=paper[i+2][j+2] print(empty) print(deep) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; paper := Integer.subrange(0, 14-1)->select(j | true)->collect(j | (Integer.subrange(0, 14-1)->select(i | true)->collect(i | (0)))) ; for s : OclFile["System.in"] do ( Sequence{x,y,size} := (s.split(','))->collect( _x | (OclType["int"])->apply(_x) ) ; paper := drop(paper, x + 2, y + 2, size)) ; var empty : int := 0 ; var deep : int := 0 ; for i : Integer.subrange(0, 10-1) do ( for j : Integer.subrange(0, 10-1) do ( if paper[i + 2+1][j + 2+1] = 0 then ( empty := empty + 1 ) else (if (paper[i + 2+1][j + 2+1]->compareTo(deep)) > 0 then ( deep := paper[i + 2+1][j + 2+1] ) else skip))) ; execute (empty)->display() ; execute (deep)->display(); operation small(paper : OclAny, x : OclAny, y : OclAny) pre: true post: true activity: paper[x+1][y+1] := paper[x+1][y+1] + 1 ; paper[x - 1+1][y+1] := paper[x - 1+1][y+1] + 1 ; paper[x+1][y - 1+1] := paper[x+1][y - 1+1] + 1 ; paper[x+1][y + 1+1] := paper[x+1][y + 1+1] + 1 ; paper[x + 1+1][y+1] := paper[x + 1+1][y+1] + 1; operation medium(paper : OclAny, x : OclAny, y : OclAny) pre: true post: true activity: small(paper, x, y) ; paper[x - 1+1][y - 1+1] := paper[x - 1+1][y - 1+1] + 1 ; paper[x - 1+1][y + 1+1] := paper[x - 1+1][y + 1+1] + 1 ; paper[x + 1+1][y - 1+1] := paper[x + 1+1][y - 1+1] + 1 ; paper[x + 1+1][y + 1+1] := paper[x + 1+1][y + 1+1] + 1; operation large(paper : OclAny, x : OclAny, y : OclAny) pre: true post: true activity: medium(paper, x, y) ; paper[x - 2+1][y+1] := paper[x - 2+1][y+1] + 1 ; paper[x+1][y - 2+1] := paper[x+1][y - 2+1] + 1 ; paper[x+1][y + 2+1] := paper[x+1][y + 2+1] + 1 ; paper[x + 2+1][y+1] := paper[x + 2+1][y+1] + 1; operation drop(paper : OclAny, x : OclAny, y : OclAny, size : OclAny) : OclAny pre: true post: true activity: if size = 1 then ( small(paper, x, y) ) else (if size = 2 then ( medium(paper, x, y) ) else ( large(paper, x, y) ) ) ; return paper; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import(absolute_import,division,print_function,unicode_literals) from sys import stdin from collections import Counter import sys NUM=[[0,0,1,0,0,1,1,1,0,0,1,0,0],[0,1,1,1,0,1,1,1,0,1,1,1,0],[1,1,1,1,1,1,1,1,1,1,1,1,1]] paper=Counter() for line in sys.stdin : x,y,size=(int(s)for s in line.split(',')) xidx=[x,x-1,x,x+1,x-2,x-1,x,x+1,x+2,x-1,x,x+1,x] yidx=[y-2,y-1,y-1,y-1,y,y,y,y,y,y+1,y+1,y+1,y+2] val=NUM[size-1] for a,b,i in zip(xidx,yidx,xrange(len(xidx))): if a<0 or 9union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 0 }))))))))))))}->union(Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 0 }))))))))))))}->union(Sequence{ Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })))))))))))) })) ; var paper : OclAny := Counter() ; for line : OclFile["System.in"] do ( var x : OclAny := null; var y : OclAny := null; var size : OclAny := null; Sequence{x,y,size} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name line)) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ','))))))) ))))))))} ; var xidx : Sequence := Sequence{x}->union(Sequence{x - 1}->union(Sequence{x}->union(Sequence{x + 1}->union(Sequence{x - 2}->union(Sequence{x - 1}->union(Sequence{x}->union(Sequence{x + 1}->union(Sequence{x + 2}->union(Sequence{x - 1}->union(Sequence{x}->union(Sequence{x + 1}->union(Sequence{ x })))))))))))) ; var yidx : Sequence := Sequence{y - 2}->union(Sequence{y - 1}->union(Sequence{y - 1}->union(Sequence{y - 1}->union(Sequence{y}->union(Sequence{y}->union(Sequence{y}->union(Sequence{y}->union(Sequence{y}->union(Sequence{y + 1}->union(Sequence{y + 1}->union(Sequence{y + 1}->union(Sequence{ y + 2 })))))))))))) ; var val : OclAny := NUM[size - 1+1] ; for _tuple : Integer.subrange(1, xidx->size())->collect( _indx | Sequence{xidx->at(_indx), yidx->at(_indx)} ) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); if a < 0 or 9 < a or b < 0 or 9 < b then ( continue ) else skip ; paper[a + b * 10+1] := paper[a + b * 10+1] + val[i+1])) ; execute (((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name xrange)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 100))))))))) )))))) (comp_iter if (test (logical_test not (logical_test (comparison (expr (atom (name paper)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))))))->sum())->display() ; execute (((argument (test (logical_test (comparison (expr (atom (name paper)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name xrange)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 100))))))))) )))))))))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input().strip() c1,c2=s[0],s[-1] if c1==c2 : if len(s)% 2 : print('Second') else : print('First') else : if len(s)% 2 : print('First') else : print('Second') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := input()->trim() ; var c1 : OclAny := null; var c2 : OclAny := null; Sequence{c1,c2} := Sequence{s->first(),s->last()} ; if c1 = c2 then ( if (s)->size() mod 2 then ( execute ('Second')->display() ) else ( execute ('First')->display() ) ) else ( if (s)->size() mod 2 then ( execute ('First')->display() ) else ( execute ('Second')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkPalin(word): if word.lower()==word.lower()[: :-1]: return True def countPalin(str): count=0 listOfWords=str.split(" ") for elements in listOfWords : if(checkPalin(elements)): count+=1 print(count) countPalin("Madam Arora teaches malayalam") countPalin("Nitin speaks malayalam") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; countPalin("Madam Arora teaches malayalam") ; countPalin("Nitin speaks malayalam"); operation checkPalin(word : OclAny) : OclAny pre: true post: true activity: if word->toLowerCase() = word->toLowerCase()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) then ( return true ) else skip; operation countPalin(OclType["String"] : OclAny) pre: true post: true activity: var count : int := 0 ; var listOfWords : String := ("" + (.split(" "))) ; for elements : listOfWords->characters() do ( if (checkPalin(elements)) then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) case=list(map(int,input().split(" "))) case=case+case temp=0 x=0 for i in range(len(case)): if case[i]==1 : x+=1 if x>temp : temp=x elif case[i]==0 : x=0 print(temp) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var case : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; case := case->union(case) ; var temp : int := 0 ; var x : int := 0 ; for i : Integer.subrange(0, (case)->size()-1) do ( if case[i+1] = 1 then ( x := x + 1 ; if (x->compareTo(temp)) > 0 then ( temp := x ) else skip ) else (if case[i+1] = 0 then ( x := 0 ) else skip)) ; execute (temp)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() print(max(map(len,(input()*2).replace("","").split('0')))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; execute (((((OclFile["System.in"]).readLine() * 2).replace("", "").split('0'))->collect( _x | (len)->apply(_x) ))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() x=[int(t)for t in input().strip().split()]*2 count=0 ms=[] for i in range(len(x)): if x[i]==1 : count+=1 else : ms.append(count) count=0 print(max(ms)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var x : Sequence := MatrixLib.elementwiseMult(input()->trim().split()->select(t | true)->collect(t | (("" + ((t)))->toInteger())), 2) ; var count : int := 0 ; var ms : Sequence := Sequence{} ; for i : Integer.subrange(0, (x)->size()-1) do ( if x[i+1] = 1 then ( count := count + 1 ) else ( execute ((count) : ms) ; count := 0 )) ; execute ((ms)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) l=l+l p=''.join(map(str,l)) a=p.split('0') x=[len(i)for i in a] print(max(x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := l->union(l) ; var p : String := StringLib.sumStringsWithSeparator(((l)->collect( _x | (OclType["String"])->apply(_x) )), '') ; var a : OclAny := p.split('0') ; var x : Sequence := a->select(i | true)->collect(i | ((i)->size())) ; execute ((x)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- continuousDays=0 maxDays=0 numInputs=int(input()) schedule=list(map(int,input().split())) scheduleDouble=schedule+schedule for i in range(len(scheduleDouble)): if(scheduleDouble[i]==1): continuousDays+=1 if(scheduleDouble[i]==0): continuousDays=0 if(continuousDays>maxDays): maxDays=continuousDays print(maxDays) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var continuousDays : int := 0 ; var maxDays : int := 0 ; var numInputs : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var schedule : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var scheduleDouble : Sequence := schedule->union(schedule) ; for i : Integer.subrange(0, (scheduleDouble)->size()-1) do ( if (scheduleDouble[i+1] = 1) then ( continuousDays := continuousDays + 1 ) else skip ; if (scheduleDouble[i+1] = 0) then ( continuousDays := 0 ) else skip ; if ((continuousDays->compareTo(maxDays)) > 0) then ( maxDays := continuousDays ) else skip) ; execute (maxDays)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lcs(X,Y,m,n): if(m==0 or n==0): return 0 if(X[m-1]==Y[n-1]): return 1+lcs(X,Y,m-1,n-1) else : return max(lcs(X,Y,m,n-1),lcs(X,Y,m-1,n)) if __name__=='__main__' : X="AGGTAB" Y="GXTXAYB" m=len(X) n=len(Y) print("Length of LCS:",lcs(X,Y,m,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( X := "AGGTAB" ; Y := "GXTXAYB" ; m := (X)->size() ; n := (Y)->size() ; execute ("Length of LCS:")->display() ) else skip; operation lcs(X : OclAny, Y : OclAny, m : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (m = 0 or n = 0) then ( return 0 ) else skip ; if (X[m - 1+1] = Y[n - 1+1]) then ( return 1 + lcs(X, Y, m - 1, n - 1) ) else ( return Set{lcs(X, Y, m, n - 1), lcs(X, Y, m - 1, n)}->max() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxSelectionCount(a,n): res=0 ; a.sort(); select=1 ; for i in range(n): if(a[i]>=select): res+=1 ; select+=1 ; return res ; arr=[4,2,1,3,5,1,4]; N=len(arr); print(maxSelectionCount(arr,N)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var arr : Sequence := Sequence{4}->union(Sequence{2}->union(Sequence{1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{1}->union(Sequence{ 4 })))))); ; var N : int := (arr)->size(); ; execute (maxSelectionCount(arr, N))->display();; operation maxSelectionCount(a : OclAny, n : OclAny) pre: true post: true activity: var res : int := 0; ; a := a->sort(); ; var select : int := 1; ; for i : Integer.subrange(0, n-1) do ( if ((a[i+1]->compareTo(select)) >= 0) then ( res := res + 1; ; select := select + 1; ) else skip) ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans=[] x=3*(10**5) xor=0 for i in range(x+1): xor ^=i ans.append(xor) for _ in range(int(input())): a,b=map(int,input().split()) l1=[] l2=[] if a==b : print(0) else : if al2[0]: cnt-=l2[0] for i,j in zip(l1,l2): if abs(i-cnt)!=j : print(-1) break else : ans=0 while cnt>0 : if cnt>=3 : ans+=1 cnt-=3 elif cnt>=2 : ans+=1 cnt-=2 elif cnt>=1 : cnt-=1 ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ans : Sequence := Sequence{} ; var x : double := 3 * ((10)->pow(5)) ; var xor : int := 0 ; for i : Integer.subrange(0, x + 1-1) do ( xor := xor xor i ; execute ((xor) : ans)) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l1 : Sequence := Sequence{} ; var l2 : Sequence := Sequence{} ; if a = b then ( execute (0)->display() ) else ( if (a->compareTo(b)) < 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a} ) else skip ; var cnt : int := 0 ; var f : int := 0 ; for i : Integer.subrange(0, 62-1) do ( if MathLib.bitwiseAnd(a, 1 * (2->pow(i))) = 0 & f = 0 then ( cnt := cnt + 1 ) else (if MathLib.bitwiseAnd(a, 1 * (2->pow(i))) then ( execute ((i) : l1) ; f := 1 ) else skip)) ; for i : Integer.subrange(0, 62-1) do ( if MathLib.bitwiseAnd(b, 1 * (2->pow(i))) then ( execute ((i) : l2) ) else skip) ; if (l1)->size() /= (l2)->size() then ( execute (-1)->display() ) else ( if (cnt->compareTo(l2->first())) > 0 then ( cnt := cnt - l2->first() ) else skip ; (compound_stmt for (exprlist (expr (atom (name i))) , (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l1))))))) , (argument (test (logical_test (comparison (expr (atom (name l2)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (name cnt))))))))) ))))) != (comparison (expr (atom (name j))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (compound_stmt while (test (logical_test (comparison (comparison (expr (atom (name cnt)))) > (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name cnt)))) >= (comparison (expr (atom (number (integer 3)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cnt)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 3))))))))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name cnt)))) >= (comparison (expr (atom (number (integer 2)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cnt)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 2)))))))))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name cnt)))) >= (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cnt)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))))))))) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_SIZE=10 def sortByRow(mat,n,ascending): for i in range(n): if(ascending): mat[i].sort() else : mat[i].sort(reverse=True) def transpose(mat,n): for i in range(n): for j in range(i+1,n): temp=mat[i][j] mat[i][j]=mat[j][i] mat[j][i]=temp def sortMatRowAndColWise(mat,n): sortByRow(mat,n,True) transpose(mat,n) sortByRow(mat,n,False) transpose(mat,n) def printMat(mat,n): for i in range(n): for j in range(n): print(mat[i][j],"",end="") print() n=3 mat=[[3,2,1],[9,8,7],[6,5,4]] print("Original Matrix:") printMat(mat,n) sortMatRowAndColWise(mat,n) print("Matrix After Sorting:") printMat(mat,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_SIZE : int := 10 ; skip ; skip ; skip ; skip ; n := 3 ; mat := Sequence{Sequence{3}->union(Sequence{2}->union(Sequence{ 1 }))}->union(Sequence{Sequence{9}->union(Sequence{8}->union(Sequence{ 7 }))}->union(Sequence{ Sequence{6}->union(Sequence{5}->union(Sequence{ 4 })) })) ; execute ("Original Matrix:")->display() ; printMat(mat, n) ; sortMatRowAndColWise(mat, n) ; execute ("Matrix After Sorting:")->display() ; printMat(mat, n); operation sortByRow(mat : OclAny, n : OclAny, ascending : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if (ascending) then ( (expr (atom (name mat)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name sort) (arguments ( )))) ) else ( (expr (atom (name mat)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name sort) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) )))) )); operation transpose(mat : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( var temp : OclAny := mat[i+1][j+1] ; mat[i+1][j+1] := mat[j+1][i+1] ; mat[j+1][i+1] := temp)); operation sortMatRowAndColWise(mat : OclAny, n : OclAny) pre: true post: true activity: sortByRow(mat, n, true) ; transpose(mat, n) ; sortByRow(mat, n, false) ; transpose(mat, n); operation printMat(mat : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( execute (mat[i+1][j+1])->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline s=str(input().strip()) n=len(s) if s[0]is s[n-1]: move=1 else : move=0 move=(n-move)% 2 if move is 1 : print('First') else : print('Second') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var s : String := ("" + ((input()->trim()))) ; var n : int := (s)->size() ; if s->first() <>= s[n - 1+1] then ( var move : int := 1 ) else ( move := 0 ) ; move := (n - move) mod 2 ; if move <>= 1 then ( execute ('First')->display() ) else ( execute ('Second')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) if ncollect( _x | (OclType["int"])->apply(_x) ) ; if (n->compareTo(m)) < 0 then ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{m,n} ) else skip ; if m = 1 then ( var x : OclAny := n ; var y : int := n mod 6 ; if y = 0 then ( y := 6 ) else skip ; if y < 4 then ( x := x - y ) else ( x := x - 6 - y ) ; execute (x)->display() ) else (if m = 2 then ( if n = 2 then ( execute (0)->display() ) else (if n = 3 then ( execute (4)->display() ) else (if n = 7 then ( execute (12)->display() ) else ( execute (n * m)->display() ) ) ) ) else ( execute (n * m - (n * m mod 2))->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(x)for x in input().split()] if n>m : n,m=m,n if n==1 : print((m//6*3+max(m % 6-3,0))*2) elif n==2 : if m==2 : print(0) elif m==3 : print(4) elif m==7 : print(12) else : print(n*m) else : print(n*m//2*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if (n->compareTo(m)) > 0 then ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{m,n} ) else skip ; if n = 1 then ( execute ((m div 6 * 3 + Set{m mod 6 - 3, 0}->max()) * 2)->display() ) else (if n = 2 then ( if m = 2 then ( execute (0)->display() ) else (if m = 3 then ( execute (4)->display() ) else (if m = 7 then ( execute (12)->display() ) else ( execute (n * m)->display() ) ) ) ) else ( execute (n * m div 2 * 2)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def process(n,m): if n==1 : x=[m//3,m//3,m//3] if m % 3==1 : x[1]+=1 if m % 3==2 : x[1]+=1 x[2]+=1 x=[x[0]% 2,x[1]% 2,x[2]% 2] return n*m-sum(x) if m==1 : x=[n//3,n//3,n//3] if n % 3==1 : x[1]+=1 if n % 3==2 : x[1]+=1 x[2]+=1 x=[x[0]% 2,x[1]% 2,x[2]% 2] return n*m-sum(x) if n==2 : if m==2 : return 0 if m==3 : return 4 if m==7 : return n*m-2 return n*m if m==2 : if n==2 : return 0 if n==3 : return 4 if n==7 : return n*m-2 return n*m if n % 4==0 : return n*m if m % 4==0 : return n*m if(n*m)% 2==0 : return n*m return n*m-1 n,m=[int(x)for x in input().split()] print(process(n,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{n,m} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (process(n, m))->display(); operation process(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: if n = 1 then ( var x : Sequence := Sequence{m div 3}->union(Sequence{m div 3}->union(Sequence{ m div 3 })) ; if m mod 3 = 1 then ( x[1+1] := x[1+1] + 1 ) else skip ; if m mod 3 = 2 then ( x[1+1] := x[1+1] + 1 ; x[2+1] := x[2+1] + 1 ) else skip ; x := Sequence{x->first() mod 2}->union(Sequence{x[1+1] mod 2}->union(Sequence{ x[2+1] mod 2 })) ; return n * m - (x)->sum() ) else skip ; if m = 1 then ( x := Sequence{n div 3}->union(Sequence{n div 3}->union(Sequence{ n div 3 })) ; if n mod 3 = 1 then ( x[1+1] := x[1+1] + 1 ) else skip ; if n mod 3 = 2 then ( x[1+1] := x[1+1] + 1 ; x[2+1] := x[2+1] + 1 ) else skip ; x := Sequence{x->first() mod 2}->union(Sequence{x[1+1] mod 2}->union(Sequence{ x[2+1] mod 2 })) ; return n * m - (x)->sum() ) else skip ; if n = 2 then ( if m = 2 then ( return 0 ) else skip ; if m = 3 then ( return 4 ) else skip ; if m = 7 then ( return n * m - 2 ) else skip ; return n * m ) else skip ; if m = 2 then ( if n = 2 then ( return 0 ) else skip ; if n = 3 then ( return 4 ) else skip ; if n = 7 then ( return n * m - 2 ) else skip ; return n * m ) else skip ; if n mod 4 = 0 then ( return n * m ) else skip ; if m mod 4 = 0 then ( return n * m ) else skip ; if (n * m) mod 2 = 0 then ( return n * m ) else skip ; return n * m - 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=sorted(map(int,input().split())) print(~ 1 & n*m-2*{1 : 1collect( _x | (OclType["int"])->apply(_x) )->sort() ; execute (MathLib.bitwiseAnd(MathLib.bitwiseNot(1), n * m - 2 * Map{ 1 |-> 1 < m mod 6 & (m mod 6 < 5) }->union(Map{ 2 |-> Map{ 2 |-> 2 }->union(Map{ 3 |-> 1 }->union(Map{ 7 |-> 1 })).get(m, 0) }).get(n, 0)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) if m>n : n,m=m,n if n+m<=4 : print(0) exit() if m==1 : p,q=n//6,n % 6 if q==4 : print(n-2) exit() elif q==5 : print(n-1) exit() else : print(p*6) exit() if(n,m)==(7,2)or(n,m)==(3,2): print(n*m-2) exit() if n % 2==0 or m % 2==0 : print(n*m) exit() print(n*m-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (m->compareTo(n)) > 0 then ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{m,n} ) else skip ; if n + m <= 4 then ( execute (0)->display() ; exit() ) else skip ; if m = 1 then ( var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := Sequence{n div 6,n mod 6} ; if q = 4 then ( execute (n - 2)->display() ; exit() ) else (if q = 5 then ( execute (n - 1)->display() ; exit() ) else ( execute (p * 6)->display() ; exit() ) ) ) else skip ; if Sequence{n, m} = Sequence{7, 2} or Sequence{n, m} = Sequence{3, 2} then ( execute (n * m - 2)->display() ; exit() ) else skip ; if n mod 2 = 0 or m mod 2 = 0 then ( execute (n * m)->display() ; exit() ) else skip ; execute (n * m - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(700+input().count("o")*100) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (700 + input()->count("o") * 100)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 input=lambda : sys.stdin.readline().rstrip() YesNo=lambda b : bool([print('Yes')]if b else print('No')) YESNO=lambda b : bool([print('YES')]if b else print('NO')) int1=lambda x : int(x)-1 def main(): print(700+input().count('o')*100) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var YesNo : Function := lambda b : OclAny in ((if b then Sequence{ ('Yes')->display() } else ('No')->display() endif)->toBoolean()) ; var YESNO : Function := lambda b : OclAny in ((if b then Sequence{ ('YES')->display() } else ('NO')->display() endif)->toBoolean()) ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: execute (700 + input->apply()->count('o') * 100)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() sum=700 for i in range(len(s)): if s[i]=='o' : sum+=100 print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var sum : int := 700 ; for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1] = 'o' then ( sum := sum + 100 ) else skip) ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() c=S.count('o') print(700+100*c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var c : int := S->count('o') ; execute (700 + 100 * c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=[] for i in range(n): t=input().split() t=[int(x)for x in t] ans.append(min(2,t[0]-1)*t[1]) for j in ans : print(j) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var t : OclAny := input().split() ; t := t->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((Set{2, t->first() - 1}->min() * t[1+1]) : ans)) ; for j : ans do ( execute (j)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() if len(S)% 2==0 and S[0]==S[len(S)-1]: print("First") elif len(S)% 2==0 and S[0]!=S[len(S)-1]: print("Second") elif len(S)% 2!=0 and S[0]==S[len(S)-1]: print("Second") else : print("First") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; if (S)->size() mod 2 = 0 & S->first() = S[(S)->size() - 1+1] then ( execute ("First")->display() ) else (if (S)->size() mod 2 = 0 & S->first() /= S[(S)->size() - 1+1] then ( execute ("Second")->display() ) else (if (S)->size() mod 2 /= 0 & S->first() = S[(S)->size() - 1+1] then ( execute ("Second")->display() ) else ( execute ("First")->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): s=input() ans=700 for l in s : if l=="o" : ans+=100 print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var ans : int := 700 ; for l : s->characters() do ( if l = "o" then ( ans := ans + 100 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkEvenParity(x): parity=0 while(x!=0): x=x &(x-1) parity+=1 if(parity % 2==0): return True else : return False def sumlist(a,n): sum=0 for i in range(n): if(checkEvenParity(a[i])): sum+=a[i] return sum if __name__=='__main__' : arr=[2,4,3,5,9] n=len(arr) print(sumlist(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var arr : Sequence := Sequence{2}->union(Sequence{4}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 9 })))) ; n := (arr)->size() ; execute (sumlist(arr, n))->display() ) else skip; operation checkEvenParity(x : OclAny) : OclAny pre: true post: true activity: var parity : int := 0 ; while (x /= 0) do ( x := MathLib.bitwiseAnd(x, (x - 1)) ; parity := parity + 1) ; if (parity mod 2 = 0) then ( return true ) else ( return false ); operation sumlist(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (checkEvenParity(a[i+1])) then ( sum := sum + a[i+1] ) else skip) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bubble_sort(arr,index_arr): def swap(i,j): arr[i],arr[j]=arr[j],arr[i] index_arr[i],index_arr[j]=index_arr[j],index_arr[i] n=len(arr) swapped=True x=-1 while swapped : swapped=False x=x+1 for i in range(1,n-x): if arr[i-1]=n : val+=n*kit_b[_] break else : val+=kit_a[_]*kit_b[_] n=n-kit_a[_] print(val) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var m : OclAny := null; Sequence{n,m} := input().split(" ") ; n := ("" + ((n)))->toInteger() ; var kit_a : Sequence := Sequence{} ; var kit_b : Sequence := Sequence{} ; for _anon : Integer.subrange(0, ("" + ((m)))->toInteger()-1) do ( var out : OclAny := input().split(" ") ; execute ((("" + ((out->first())))->toInteger()) : kit_a) ; execute ((("" + ((out[1+1])))->toInteger()) : kit_b)) ; bubble_sort(kit_b, kit_a) ; var val : int := 0 ; for _anon : Integer.subrange(0, (kit_b)->size()-1) do ( if (kit_a[_anon+1]->compareTo(n)) >= 0 then ( val := val + n * kit_b[_anon+1] ; break ) else ( val := val + kit_a[_anon+1] * kit_b[_anon+1] ; n := n - kit_a[_anon+1] )) ; execute (val)->display(); operation bubble_sort(arr : OclAny, index_arr : OclAny) pre: true post: true activity: skip ; var n : int := (arr)->size() ; var swapped : boolean := true ; var x : int := -1 ; while swapped do ( swapped := false ; x := x + 1 ; for i : Integer.subrange(1, n - x-1) do ( if (arr[i - 1+1]->compareTo(arr[i+1])) < 0 then ( swap(i - 1, i) ; swapped := true ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=list(map(int,input().split())) A=[] for i in range(0,m): j=list(map(int,input().split())) A.append(j) def sort(A): for i in range(0,len(A)): for j in range(i+1,len(A)): if A[i][1]=A[i][0]: count+=A[i][0]*A[i][1] n=n-A[i][0] pass else : count+=n*A[i][1] break return count print(Calcualte(A,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var A : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var j : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((j) : A)) ; skip ; sort(A) ; skip ; execute (Calcualte(A, n))->display(); operation sort(A : OclAny) pre: true post: true activity: for i : Integer.subrange(0, (A)->size()-1) do ( for j : Integer.subrange(i + 1, (A)->size()-1) do ( if (A[i+1][1+1]->compareTo(A->restrict(j)[1+1])) < 0 then ( var A[i+1] : OclAny := null; var A->restrict(j) : OclAny := null; Sequence{A[i+1],A->restrict(j)} := Sequence{A->restrict(j),A[i+1]} ) else skip)); operation Calcualte(A : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, (A)->size()-1) do ( if (n->compareTo(A[i+1]->first())) >= 0 then ( count := count + A[i+1]->first() * A[i+1][1+1] ; n := n - A[i+1]->first() ; skip ) else ( count := count + n * A[i+1][1+1] ; break )) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numbers=list(map(int,input().split())) date=[] for i in range(0,numbers[1]): x=list(map(int,input().split())) info={'cap' : x[1],'number' : x[0]} date.append(info) def num(date): return date['cap'] date.sort(key=num,reverse=True) counter=0 sum=0 for i in range(0,len(date)): if countercollect( _x | (OclType["int"])->apply(_x) )) ; var date : Sequence := Sequence{} ; for i : Integer.subrange(0, numbers[1+1]-1) do ( var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var info : Map := Map{ 'cap' |-> x[1+1] }->union(Map{ 'number' |-> x->first() }) ; execute ((info) : date)) ; skip ; date := date->sort() ; var counter : int := 0 ; var sum : int := 0 ; for i : Integer.subrange(0, (date)->size()-1) do ( if (counter->compareTo(numbers->first())) < 0 then ( if (counter + date[i+1]->at('number')->compareTo(numbers->first())) <= 0 then ( counter := counter + date[i+1]->at('number') ; sum := sum + date[i+1]->at('number') * date[i+1]->at('cap') ) else ( sum := sum + (numbers->first() - counter) * date[i+1]->at('cap') ; counter := counter + (numbers->first() - counter) ) ) else skip) ; execute (sum)->display(); operation num(date : OclAny) : OclAny pre: true post: true activity: return date->at('cap'); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) z=[] c=0 for i in range(m): line=list(map(int,input().split())) z.append([line[1],line[0]]) z.sort() z.reverse() for i in z : if i[1]<=n : c+=i[0]*i[1] n-=i[1] else : c+=i[0]*n n=0 if n==0 : break print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var z : Sequence := Sequence{} ; var c : int := 0 ; for i : Integer.subrange(0, m-1) do ( var line : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((Sequence{line[1+1]}->union(Sequence{ line->first() })) : z)) ; z := z->sort() ; z := z->reverse() ; for i : z do ( if (i[1+1]->compareTo(n)) <= 0 then ( c := c + i->first() * i[1+1] ; n := n - i[1+1] ) else ( c := c + i->first() * n ; var n : int := 0 ) ; if n = 0 then ( break ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) s=[] for i in range(m): a,b=map(int,input().split()) s.append([b,a]) s.sort(reverse=True) ss=0 for k in range(len(s)): if n<=0 : break else : ss+=min(n,s[k][1])*s[k][0] n-=s[k][1] print(ss) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{b}->union(Sequence{ a })) : s)) ; s := s->sort() ; var ss : int := 0 ; for k : Integer.subrange(0, (s)->size()-1) do ( if n <= 0 then ( break ) else ( ss := ss + Set{n, s[k+1][1+1]}->min() * s[k+1]->first() ; n := n - s[k+1][1+1] )) ; execute (ss)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=26 def largestSubSeq(arr,n): count=[0]*MAX for i in range(n): string=arr[i] _hash=[False]*MAX for j in range(len(string)): _hash[ord(string[j])-ord('a')]=True for j in range(MAX): if _hash[j]==True : count[j]+=1 return max(count) if __name__=="__main__" : arr=["ab","bc","de"] n=len(arr) print(largestSubSeq(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 26 ; skip ; if __name__ = "__main__" then ( arr := Sequence{"ab"}->union(Sequence{"bc"}->union(Sequence{ "de" })) ; n := (arr)->size() ; execute (largestSubSeq(arr, n))->display() ) else skip; operation largestSubSeq(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX) ; for i : Integer.subrange(0, n-1) do ( var string : OclAny := arr[i+1] ; var _hash : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, MAX) ; for j : Integer.subrange(0, (string)->size()-1) do ( _hash[(string[j+1])->char2byte() - ('a')->char2byte()+1] := true) ; for j : Integer.subrange(0, MAX-1) do ( if _hash[j+1] = true then ( count[j+1] := count[j+1] + 1 ) else skip)) ; return (count)->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxSumLCM(n): max_sum=0 i=1 while(i*i<=n): if(n % i==0): max_sum=max_sum+i if(n//i!=i): max_sum=max_sum+(n//i) i=i+1 return max_sum n=2 print(maxSumLCM(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 2 ; execute (maxSumLCM(n))->display(); operation maxSumLCM(n : OclAny) : OclAny pre: true post: true activity: var max_sum : int := 0 ; var i : int := 1 ; while ((i * i->compareTo(n)) <= 0) do ( if (n mod i = 0) then ( max_sum := max_sum + i ; if (n div i /= i) then ( max_sum := max_sum + (n div i) ) else skip ) else skip ; i := i + 1) ; return max_sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() for w in range(2,min([3,len(s)])+1): for st in range(0,len(s)-w+1): if s[st]==s[st+w-1]: print(st+1,st+w) exit() print(-1,-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; for w : Integer.subrange(2, (Sequence{3}->union(Sequence{ (s)->size() }))->min() + 1-1) do ( for st : Integer.subrange(0, (s)->size() - w + 1-1) do ( if s[st+1] = s[st + w - 1+1] then ( execute (st + 1)->display() ; exit() ) else skip)) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def remove(s): i=1 count=0 while icharacters() ; count := 0 ; while true do ( var tmp : OclAny := remove(s) ; if tmp = 0 then ( break ) else skip ; count := count + tmp) ; if count mod 2 = 0 then ( execute ("Second")->display() ) else ( execute ("First")->display() ); operation remove(s : OclAny) : OclAny pre: true post: true activity: var i : int := 1 ; var count : int := 0 ; while (i->compareTo((s)->size() - 1)) < 0 do ( if s[i - 1+1] /= s[i + 1+1] then ( s := s->excludingAt(i+1) ; count := count + 1 ) else skip ; i := i + 1) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): s=input() n,m=list(map(int,s.split())) if n==1 : print(0) elif n==2 : print(m) else : print(m*2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((s.split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n = 1 then ( execute (0)->display() ) else (if n = 2 then ( execute (m)->display() ) else ( execute (m * 2)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(300000) def solve(s : str): ret=(-1,-1) def is_unbalance(t): if t[0]==t[1]or t[0]==t[2]or t[1]==t[2]: return True return False for i in range(len(s)-2): if is_unbalance(s[i : i+3]): ret=(i+1,i+3) break if len(s)==2 and s[0]==s[1]: ret=(1,2) print(ret[0],ret[1]) return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() s=next(tokens) solve(s) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(300000) ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(s : String) pre: true post: true activity: var ret : OclAny := Sequence{-1, -1} ; skip ; for i : Integer.subrange(0, (s)->size() - 2-1) do ( if is_unbalance(s.subrange(i+1, i + 3)) then ( ret := Sequence{i + 1, i + 3} ; break ) else skip) ; if (s)->size() = 2 & s->first() = s[1+1] then ( ret := Sequence{1, 2} ) else skip ; execute (ret->first())->display() ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var s : OclAny := (tokens).next() ; solve(s); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() L=len(S) if L==2 : print('1 2' if S[0]==S[1]else '-1-1') else : result=False for i in range(L-2): s=S[i : i+3] if s[0]==s[1]or s[1]==s[2]or s[2]==s[0]: print(str(i+1)+' '+str(i+3)) result=True break result or print('-1-1') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var L : int := (S)->size() ; if L = 2 then ( execute (if S->first() = S[1+1] then '1 2' else '-1-1' endif)->display() ) else ( var result : boolean := false ; for i : Integer.subrange(0, L - 2-1) do ( var s : OclAny := S.subrange(i+1, i + 3) ; if s->first() = s[1+1] or s[1+1] = s[2+1] or s[2+1] = s->first() then ( execute (("" + ((i + 1))) + ' ' + ("" + ((i + 3))))->display() ; result := true ; break ) else skip) ; (logical_test (logical_test (comparison (expr (atom (name result))))) or (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '-1-1'))))))) ))))))) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,fractions,itertools def solve(s : str): N=len(s) for i in range(N-1): if s[i]==s[i+1]: print(i+1,i+2) return for i in range(N-2): if s[i]==s[i+2]: print(i+1,i+3) return print(-1,-1) return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() s=next(tokens) solve(s) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(s : String) pre: true post: true activity: var N : int := (s)->size() ; for i : Integer.subrange(0, N - 1-1) do ( if s[i+1] = s[i + 1+1] then ( execute (i + 1)->display() ; return ) else skip) ; for i : Integer.subrange(0, N - 2-1) do ( if s[i+1] = s[i + 2+1] then ( execute (i + 1)->display() ; return ) else skip) ; execute (-1)->display() ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var s : OclAny := (tokens).next() ; solve(s); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def is_unbalance(lst): res=False for x in lst : if lst.count(x)>=2 : res=True break return res s=input() i=0 a,b=-1,-1 for j in 2,1 : while i+jcompareTo((s)->size())) < 0 do ( if is_unbalance(s.subrange(i+1, i + j + 1)) then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{i + 1,i + j + 1} ; break ) else skip ; i := i + 1) ; if Sequence{a, b} /= Sequence{-1, -1} then ( break ) else skip) ; execute (a)->display(); operation is_unbalance(lst : OclAny) : OclAny pre: true post: true activity: var res : boolean := false ; for x : lst do ( if lst->count(x) >= 2 then ( res := true ; break ) else skip) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) stx=input().split() stx2=input() strm='' for m in stx : if m in stx2 : strm+=m+' ' print(strm) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var stx : OclAny := input().split() ; var stx2 : String := (OclFile["System.in"]).readLine() ; var strm : String := '' ; for m : stx do ( if (stx2)->characters()->includes(m) then ( strm := strm + m + ' ' ) else skip) ; execute (strm)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() a=input().split() c=input().split() for i in a : if i in c : print(i,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var a : OclAny := input().split() ; var c : OclAny := input().split() ; for i : a do ( if (c)->includes(i) then ( execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) s1=list(map(int,input().split())) s2=list(map(int,input().split())) for i in s1 : if i in s2 : print(i,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s2 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : s1 do ( if (s2)->includes(i) then ( execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() a=input().split() b=input().split() c=[] for i in a : if i in b : c.append(i) print(*c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var a : OclAny := input().split() ; var b : OclAny := input().split() ; var c : Sequence := Sequence{} ; for i : a do ( if (b)->includes(i) then ( execute ((i) : c) ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name c))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,m=map(int,input().split()) x=list(map(int,input().split())) y=list(map(int,input().split())) s=set(y) ans=[] for i in x : if i in s : ans.append(i) sys.stdout.write(" ".join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var y : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Set := Set{}->union((y)) ; var ans : Sequence := Sequence{} ; for i : x do ( if (s)->includes(i) then ( execute ((i) : ans) ) else skip) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " ") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input(); print(['Second','First'][(len(s)+(s[0]==s[-1]))% 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine(); execute (Sequence{'Second'}->union(Sequence{ 'First' })[((s)->size() + (s->first() = s->last())) mod 2+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,a,b=map(int,input().split()) if b>a*m : print(n*a) else : f=int(((n % m)*a)+((n-n % m)/m)*b) if f-a+bn*a : f=n*a if b=n : f=b print(f) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,m,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (b->compareTo(a * m)) > 0 then ( execute (n * a)->display() ) else ( var f : int := ("" + ((((n mod m) * a) + ((n - n mod m) / m) * b)))->toInteger() ; if (f - a + b->compareTo(f)) < 0 & n mod m /= 0 then ( f := f - ((n mod m) * a) + b ) else skip ; if (f->compareTo(n * a)) > 0 then ( f := n * a ) else skip ; if (b->compareTo(f)) < 0 & (m->compareTo(n)) >= 0 then ( f := b ) else skip ; execute (f)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,m=[int(i)for i in input().strip().split()] if n==1 : print(0) elif n==2 : print(m) else : print(2*m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input()->trim().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if n = 1 then ( execute (0)->display() ) else (if n = 2 then ( execute (m)->display() ) else ( execute (2 * m)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys ; input=sys.stdin.readline def solution(n,m,a,b): if m*a<=b : return n*a else : return n//m*b+min((n % m)*a,b) if __name__=='__main__' : print(solution(*map(int,input().split()))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; var input : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = '__main__' then ( execute (solution((argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))))->display() ) else skip; operation solution(n : OclAny, m : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (m * a->compareTo(b)) <= 0 then ( return n * a ) else ( return n div m * b + Set{(n mod m) * a, b}->min() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,m,a,b=list(map(int,input().split(" "))) sum=0 specialTicketAvg=b/m if specialTicketAvgcollect( _x | (OclType["int"])->apply(_x) )) ; var sum : int := 0 ; var specialTicketAvg : double := b / m ; if (specialTicketAvg->compareTo(a)) < 0 then ( sum := sum + (n / m)->floor() * b ; var n : int := n mod m ; if (n * a->compareTo(b)) < 0 then ( sum := sum + n * a ) else ( sum := sum + b ) ) else ( sum := n * a ) ; execute (("" + ((sum)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,a,b=list(map(int,input().split(" "))) sum=0 specialTicketAvg=b/m if specialTicketAvgcollect( _x | (OclType["int"])->apply(_x) )) ; var sum : int := 0 ; var specialTicketAvg : double := b / m ; if (specialTicketAvg->compareTo(a)) < 0 then ( sum := sum + ("" + ((n / m)))->toInteger() * b ; var n : int := n mod m ; if (n * a->compareTo(b)) < 0 then ( sum := sum + n * a ) else ( sum := sum + b ) ) else ( sum := n * a ) ; execute (("" + ((sum)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c=input() t=c.split() a=eval(t[0]) b=eval(t[1]) c=eval(t[2]) d=eval(t[3]) divi=a//b modi=a % b if(b*c>d): if(modi*c>d): print(divi*d+d) else : print(divi*d+modi*c) else : print(a*c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : String := (OclFile["System.in"]).readLine() ; var t : OclAny := c.split() ; var a : OclAny := t->first() ; var b : OclAny := t[1+1] ; c := t[2+1] ; var d : OclAny := t[3+1] ; var divi : int := a div b ; var modi : int := a mod b ; if ((b * c->compareTo(d)) > 0) then ( if ((modi * c->compareTo(d)) > 0) then ( execute (divi * d + d)->display() ) else ( execute (divi * d + modi * c)->display() ) ) else ( execute (a * c)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd,sqrt def countBits(n): if(n==0): return 0 else : return(((n & 1)==0)+countBits(n>>1)) def maxGcd(n): if(countBits(n)==0): for i in range(2,int(sqrt(n))+1): if(n % i==0): return int(n/i) else : val=0 power=1 dupn=n while(n): if((n & 1)==0): val+=power power=power*2 n=n>>1 return gcd(val ^ dupn,val & dupn) return 1 if __name__=='__main__' : n=5 print(maxGcd(n)) n=15 print(maxGcd(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( n := 5 ; execute (maxGcd(n))->display() ; n := 15 ; execute (maxGcd(n))->display() ) else skip; operation countBits(n : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return 0 ) else ( return (((MathLib.bitwiseAnd(n, 1)) = 0) + countBits(n /(2->pow(1)))) ); operation maxGcd(n : OclAny) : OclAny pre: true post: true activity: if (countBits(n) = 0) then ( for i : Integer.subrange(2, ("" + ((sqrt(n))))->toInteger() + 1-1) do ( if (n mod i = 0) then ( return ("" + ((n / i)))->toInteger() ) else skip) ) else ( var val : int := 0 ; var power : int := 1 ; var dupn : OclAny := n ; while (n) do ( if ((MathLib.bitwiseAnd(n, 1)) = 0) then ( val := val + power ) else skip ; power := power * 2 ; n := n /(2->pow(1))) ; return gcd(MathLib.bitwiseXor(val, dupn), MathLib.bitwiseAnd(val, dupn)) ) ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy BIG_NUM=2000000000 MOD=1000000007 EPS=0.000000001 class Info : def __init__(self,arg_num,arg_loc): self.num=arg_num self.loc=arg_loc def __lt__(self,another): if self.num!=another.num : return self.num>another.num else : return self.loc=need_out : continue info=heappop(Q) print("%d" %(info.num),end="") while len(Q)>0 and Q[0].loc<=info.loc : heappop(Q) print("") ------------------------------------------------------------ OCL File: --------- class Info { static operation newInfo() : Info pre: true post: Info->exists( _x | result = _x ); attribute num : OclAny := arg_num; attribute loc : OclAny := arg_loc; operation initialise(arg_num : OclAny,arg_loc : OclAny) : Info pre: true post: true activity: self.num := arg_num ; self.loc := arg_loc; return self; operation __lt__(another : OclAny) : OclAny pre: true post: true activity: if self.num /= another.num then ( return (self.num->compareTo(another.num)) > 0 ) else ( return (self.loc->compareTo(another.loc)) < 0 ); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; skip ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var Q : Sequence := Sequence{} ; var rest : OclAny := N ; var need_out : double := N - K ; var out : int := 0 ; var table : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for loc : Integer.subrange(0, N-1) do ( var tmp : OclAny := table[loc+1] ; heappush(Q, (Info.newInfo()).initialise(tmp, loc)) ; rest := rest - 1 ; if (out + rest->compareTo(need_out)) >= 0 then ( continue ) else skip ; var info : OclAny := heappop(Q) ; execute (StringLib.format("%d",(info.num)))->display() ; while (Q)->size() > 0 & (Q->first().loc->compareTo(info.loc)) <= 0 do ( heappop(Q))) ; execute ("")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def productAscii(str): prod=1 for i in range(0,len(str)): prod=prod*ord(str[i]) return prod if __name__=='__main__' : str="GfG" print(productAscii(str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( OclType["String"] := "GfG" ; execute (productAscii(OclType["String"]))->display() ) else skip; operation productAscii(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var prod : int := 1 ; for i : Integer.subrange(0, (OclType["String"])->size()-1) do ( prod := prod * (("" + ([i+1])))->char2byte()) ; return prod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,A,B,C=map(int,input().split()) print(N-A-B+C) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{N,A,B,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (N - A - B + C)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) arr=list(map(int,input().split())) arr.sort() ans=0 for i in range(0,n): if(arr[i]<=i+1): ans=i+1 print(ans+1) if __name__=="__main__" : t=int(input()) for _ in range(t): main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( main()) ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := arr->sort() ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ((arr[i+1]->compareTo(i + 1)) <= 0) then ( ans := i + 1 ) else skip) ; execute (ans + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input ; n=int(I()) def f(x): a=x % 10 ; x//=10 while x : if x % 10+1!=a : return 0 a=x % 10 ; x//=10 return 1 a=list(map(int,I().split())) b=-1 for i in range(n): for j in a[i+1 :]: c=a[i]*j if(f(c)and btoInteger() ; skip ; a := ((I().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : int := -1 ; for i : Integer.subrange(0, n-1) do ( for j : a.subrange(i + 1+1) do ( var c : double := a[i+1] * j ; if (f(c) & (b->compareTo(c)) < 0) then ( b := c ) else skip)) ; execute (b)->display(); operation f(x : OclAny) : OclAny pre: true post: true activity: var a : int := x mod 10; x := x div 10 ; while x do ( if x mod 10 + 1 /= a then ( return 0 ) else skip ; a := x mod 10; x := x div 10) ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,A,B,C=[int(x)for x in input().split()] ans=N-(A+B)+C print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{N,A,B,C} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : double := N - (A + B) + C ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b,c=map(int,input().split()) print((n+c)-(a+b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{n,a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((n + c) - (a + b))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): a,b=map(int,input().split()) if a==1 : print('0') if a==2 : print(b) if a>=3 : print(b+b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 1 then ( execute ('0')->display() ) else skip ; if a = 2 then ( execute (b)->display() ) else skip ; if a >= 3 then ( execute (b + b)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b,c=map(int,input().split()); print(n-a-b+c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{n,a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); execute (n - a - b + c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b,c=map(int,input().split()) print(n-(c+a-c+b-c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{n,a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (n - (c + a - c + b - c))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- X,Y,Z=map(int,input().split()) print(min(((X*Y)//2),(X*Z//2),(Y*Z//2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var X : OclAny := null; var Y : OclAny := null; var Z : OclAny := null; Sequence{X,Y,Z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{((X * Y) div 2), (X * Z div 2), (Y * Z div 2)}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- line=input().split() w=int(line[0])*int(line[1])//2 print(w) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var line : OclAny := input().split() ; var w : int := ("" + ((line->first())))->toInteger() * ("" + ((line[1+1])))->toInteger() div 2 ; execute (w)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- [a,b,c]=[int(j)for j in input().split()] x=[a,b,c] d=min(x) e=a+b+c-d-max(x) print(int(d*e/2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: Sequence{a}->union(Sequence{b}->union(Sequence{ c })) := input().split()->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; var x : Sequence := Sequence{a}->union(Sequence{b}->union(Sequence{ c })) ; var d : OclAny := (x)->min() ; var e : double := a + b + c - d - (x)->max() ; execute (("" + ((d * e / 2)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): A=list(map(int,input().split())) A.remove(max(A)) print(int(A[0]*A[1]/2)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (((A)->max()) /: A) ; execute (("" + ((A->first() * A[1+1] / 2)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math AB,BC,CA=map(int,input().split()) s=(AB+BC+CA)/2 S=math.sqrt(s*(s-AB)*(s-BC)*(s-CA)) print(int(S)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var AB : OclAny := null; var BC : OclAny := null; var CA : OclAny := null; Sequence{AB,BC,CA} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : double := (AB + BC + CA) / 2 ; var S : double := (s * (s - AB) * (s - BC) * (s - CA))->sqrt() ; execute (("" + ((S)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def bit(x): ans=0 while(x): x/=2 ans=ans+1 return ans def check(d,x): if(bit(x/d)<=bit(d)): return True return False ; def bs(n): l=1 r=int(math.sqrt(n)) while(ldisplay(); operation bit(x : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; while (x) do ( x := x / 2 ; ans := ans + 1) ; return ans; operation check(d : OclAny, x : OclAny) : OclAny pre: true post: true activity: if ((bit(x / d)->compareTo(bit(d))) <= 0) then ( return true ) else skip ; return false;; operation bs(n : OclAny) : OclAny pre: true post: true activity: var l : int := 1 ; var r : int := ("" + (((n)->sqrt())))->toInteger() ; while ((l->compareTo(r)) < 0) do ( var m : int := ("" + (((l + r) / 2)))->toInteger() ; if (check(m, n)) then ( r := m ) else ( l := m + 1 )) ; if (check(l, n) = false) then ( return (l + 1)->floor() ) else ( return (l)->floor() ); operation countDivisor(n : OclAny) : OclAny pre: true post: true activity: return n - bs(n) + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sieveOfEratosthenes(N,s): prime=[False]*(N+1) for i in range(2,N+1,2): s[i]=2 for i in range(3,N+1,2): if prime[i]==False : s[i]=i for j in range(i,(N+1)//i,2): if prime[i*j]==False : prime[i*j]=True s[i*j]=i def findSum(N): s=[0]*(N+1) ans=1 sieveOfEratosthenes(N,s) currFactor=s[N] power=1 while N>1 : N//=s[N] if currFactor==s[N]: power+=1 continue sum=0 for i in range(power+1): sum+=pow(currFactor,i) ans*=sum currFactor=s[N] power=1 return ans if __name__=="__main__" : n=12 print("Sum of the factors is :",end=" ") print(findSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var n : int := 12 ; execute ("Sum of the factors is :")->display() ; execute (findSum(n))->display() ) else skip; operation sieveOfEratosthenes(N : OclAny, s : OclAny) pre: true post: true activity: var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (N + 1)) ; for i : Integer.subrange(2, N + 1-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( s[i+1] := 2) ; for i : Integer.subrange(3, N + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if prime[i+1] = false then ( s[i+1] := i ; for j : Integer.subrange(i, (N + 1) div i-1)->select( $x | ($x - i) mod 2 = 0 ) do ( if prime[i * j+1] = false then ( prime[i * j+1] := true ; s[i * j+1] := i ) else skip) ) else skip); operation findSum(N : OclAny) : OclAny pre: true post: true activity: s := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; var ans : int := 1 ; sieveOfEratosthenes(N, s) ; var currFactor : OclAny := s[N+1] ; var power : int := 1 ; while N > 1 do ( N := N div s[N+1] ; if currFactor = s[N+1] then ( power := power + 1 ; continue ) else skip ; var sum : int := 0 ; for i : Integer.subrange(0, power + 1-1) do ( sum := sum + (currFactor)->pow(i)) ; ans := ans * sum ; currFactor := s[N+1] ; power := 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- D,T,S=map(int,input().split()) if D<=T*S : print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var D : OclAny := null; var T : OclAny := null; var S : OclAny := null; Sequence{D,T,S} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (D->compareTo(T * S)) <= 0 then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return[int(x)for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return input() def main(): D,T,S=LI() if T*Spow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var mod : double := (10)->pow(9) + 7 ; var dd : Sequence := Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{ Sequence{0, -1} }))) ; var ddn : Sequence := Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{-1, 1}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{1, 1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{1, -1}}->union(Sequence{Sequence{0, -1}}->union(Sequence{ Sequence{-1, -1} }))))))) ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation main() : OclAny pre: true post: true activity: var D : OclAny := null; var T : OclAny := null; var S : OclAny := null; Sequence{D,T,S} := LI() ; if (T * S->compareTo(D)) < 0 then ( return 'No' ) else skip ; return 'Yes'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=[] for i in range(n): t=input().split() t=[int(x)for x in t] if t[0]==1 : ans.append(0) elif t[0]==2 : ans.append(t[1]) else : ans.append(2*t[1]) for j in ans : print(j) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var t : OclAny := input().split() ; t := t->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if t->first() = 1 then ( execute ((0) : ans) ) else (if t->first() = 2 then ( execute ((t[1+1]) : ans) ) else ( execute ((2 * t[1+1]) : ans) ) ) ) ; for j : ans do ( execute (j)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d,t,s=map(int,input().split(" ")) print("Yes" if d/s<=t else "No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : OclAny := null; var t : OclAny := null; var s : OclAny := null; Sequence{d,t,s} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if (d / s->compareTo(t)) <= 0 then "Yes" else "No" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- L=input().split() D,T,S=[int(i)for i in L] if T*Sselect(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if (T * S->compareTo(D)) < 0 then ( execute ("No")->display() ) else ( execute ("Yes")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d,t,s=map(int,input().split()) print(['No','Yes'][t*s>=d]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : OclAny := null; var t : OclAny := null; var s : OclAny := null; Sequence{d,t,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Sequence{'No'}->union(Sequence{ 'Yes' })->select((t * s->compareTo(d)) >= 0))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* def nextPerfectCube(N): nextN=floor(N**(1/3))+1 return nextN**3 if __name__=="__main__" : n=35 print(nextPerfectCube(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var n : int := 35 ; execute (nextPerfectCube(n))->display() ) else skip; operation nextPerfectCube(N : OclAny) : OclAny pre: true post: true activity: var nextN : OclAny := floor((N)->pow((1 / 3))) + 1 ; return (nextN)->pow(3); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def perfectCube(N): cube=0 ; for i in range(N+1): cube=i*i*i ; if(cube==N): print("Yes"); return ; elif(cube>N): print("NO"); return ; if __name__=="__main__" : N=216 ; perfectCube(N); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := 216; ; perfectCube(N); ) else skip; operation perfectCube(N : OclAny) : OclAny pre: true post: true activity: var cube : int := 0; ; for i : Integer.subrange(0, N + 1-1) do ( cube := i * i * i; ; if (cube = N) then ( execute ("Yes")->display(); ; return; ) else (if ((cube->compareTo(N)) > 0) then ( execute ("NO")->display(); ; return; ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import pow def doubleFactorial(n): fact=1 for i in range(1,n+1,2): fact=fact*i return fact def hermiteNumber(n): if(n % 2==1): return 0 else : number=((pow(2,n/2))*doubleFactorial(n-1)) if((n/2)% 2==1): number=number*-1 return number if __name__=='__main__' : n=6 print(int(hermiteNumber(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( n := 6 ; execute (("" + ((hermiteNumber(n))))->toInteger())->display() ) else skip; operation doubleFactorial(n : OclAny) : OclAny pre: true post: true activity: var fact : int := 1 ; for i : Integer.subrange(1, n + 1-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( fact := fact * i) ; return fact; operation hermiteNumber(n : OclAny) : OclAny pre: true post: true activity: if (n mod 2 = 1) then ( return 0 ) else ( var number : double := (((2)->pow(n / 2)) * doubleFactorial(n - 1)) ; if ((n / 2) mod 2 = 1) then ( number := number * -1 ) else skip ; return number ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INT_MAX=100000000 def minimalSteps(s,n): dp=[INT_MAX for i in range(n)] s1="" s2="" dp[0]=1 s1+=s[0] for i in range(1,n): s1+=s[i] s2=s[i+1 : i+1+i+1] dp[i]=min(dp[i],dp[i-1]+1) if(s1==s2): dp[i*2+1]=min(dp[i]+1,dp[i*2+1]) return dp[n-1] s="aaaaaaaa" n=len(s) print(minimalSteps(s,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INT_MAX : int := 100000000 ; skip ; s := "aaaaaaaa" ; n := (s)->size() ; execute (minimalSteps(s, n))->display(); operation minimalSteps(s : OclAny, n : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (INT_MAX)) ; var s1 : String := "" ; var s2 : String := "" ; dp->first() := 1 ; s1 := s1 + s->first() ; for i : Integer.subrange(1, n-1) do ( s1 := s1 + s[i+1] ; s2 := s.subrange(i + 1+1, i + 1 + i + 1) ; dp[i+1] := Set{dp[i+1], dp[i - 1+1] + 1}->min() ; if (s1 = s2) then ( dp[i * 2 + 1+1] := Set{dp[i+1] + 1, dp[i * 2 + 1+1]}->min() ) else skip) ; return dp[n - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _=int(input()) bags=[int(x)for x in input().split()] pairs=[x for x in bags if x % 2==0] impairs=[x for x in bags if x % 2==1] if sum(bags)% 2==0 : print(len(pairs)) else : print(len(impairs)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _anon : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var bags : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var pairs : Sequence := bags->select(x | x mod 2 = 0)->collect(x | (x)) ; var impairs : Sequence := bags->select(x | x mod 2 = 1)->collect(x | (x)) ; if (bags)->sum() mod 2 = 0 then ( execute ((pairs)->size())->display() ) else ( execute ((impairs)->size())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lb=list(map(int,input().split())) sb=sum(lb) t=0 for b in lb : if(sb-b)% 2==0 : t+=1 print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lb : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sb : OclAny := (lb)->sum() ; var t : int := 0 ; for b : lb do ( if (sb - b) mod 2 = 0 then ( t := t + 1 ) else skip) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- number=int(input()) arr=list(map(int,input().split())) counter=0 count=0 for i in arr : counter+=i for i in arr : if(counter-i)% 2==0 : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var number : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var counter : int := 0 ; var count : int := 0 ; for i : arr do ( counter := counter + i) ; for i : arr do ( if (counter - i) mod 2 = 0 then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) s=sum(l) t=0 for b in l : if(s-b)% 2==0 : t+=1 print(t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : OclAny := (l)->sum() ; var t : int := 0 ; for b : l do ( if (s - b) mod 2 = 0 then ( t := t + 1 ) else skip) ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) hor1=[int(read)for read in input().split()] hor2=[int(read)for read in input().split()] vert=[int(read)for read in input().split()] pref1=[0]*(n) pref2=[0]*(n) for i in range(1,n): pref1[i]=pref1[i-1]+hor1[i-1] pref2[i]=pref2[i-1]+hor2[i-1] mini=10**9 prev=10**9 ans=set() for i in range(n): x=pref1[i]+(pref2[n-1]-pref2[i])+vert[i] if x<=mini : prev=mini mini=x elif xtoInteger() ; var hor1 : Sequence := input().split()->select(read | true)->collect(read | (("" + ((read)))->toInteger())) ; var hor2 : Sequence := input().split()->select(read | true)->collect(read | (("" + ((read)))->toInteger())) ; var vert : Sequence := input().split()->select(read | true)->collect(read | (("" + ((read)))->toInteger())) ; var pref1 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n)) ; var pref2 : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n)) ; for i : Integer.subrange(1, n-1) do ( pref1[i+1] := pref1[i - 1+1] + hor1[i - 1+1] ; pref2[i+1] := pref2[i - 1+1] + hor2[i - 1+1]) ; var mini : double := (10)->pow(9) ; var prev : double := (10)->pow(9) ; var ans : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := pref1[i+1] + (pref2[n - 1+1] - pref2[i+1]) + vert[i+1] ; if (x->compareTo(mini)) <= 0 then ( prev := mini ; mini := x ) else (if (x->compareTo(prev)) < 0 then ( prev := x ) else skip)) ; execute (mini + prev)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mn=int(input()) a_b=list(map(int,input().split())) c_b=sum(a_b) nn=0 for b in a_b : if(c_b-b)% 2==0 : nn+=1 print(nn) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mn : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a_b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c_b : OclAny := (a_b)->sum() ; var nn : int := 0 ; for b : a_b do ( if (c_b - b) mod 2 = 0 then ( nn := nn + 1 ) else skip) ; execute (nn)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k2,k3,k5,k6=map(int,input().split()) sum256=0 sum32=0 if k2==k5==k6 : print(k2*256) elif k2==k3 and(k5==0 or k6==0): print(k2*32) else : if k2<=k5 and k2<=k6 : sum256+=k2 elif k5<=k2 and k5<=k6 : sum256+=k5 k2-=k5 if k3!=0 and k2<=k3 : sum32+=k2 elif k3!=0 and k3<=k2 : sum32+=k3 elif k6<=k2 and k6<=k5 : sum256+=k6 k2-=k6 if k3!=0 and k2<=k3 : sum32+=k2 elif k3!=0 and k3<=k2 : sum32+=k3 print(sum32*32+sum256*256) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k2 : OclAny := null; var k3 : OclAny := null; var k5 : OclAny := null; var k6 : OclAny := null; Sequence{k2,k3,k5,k6} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sum256 : int := 0 ; var sum32 : int := 0 ; if k2 = k5 & (k5 == k6) then ( execute (k2 * 256)->display() ) else (if k2 = k3 & (k5 = 0 or k6 = 0) then ( execute (k2 * 32)->display() ) else ( if (k2->compareTo(k5)) <= 0 & (k2->compareTo(k6)) <= 0 then ( sum256 := sum256 + k2 ) else (if (k5->compareTo(k2)) <= 0 & (k5->compareTo(k6)) <= 0 then ( sum256 := sum256 + k5 ; k2 := k2 - k5 ; if k3 /= 0 & (k2->compareTo(k3)) <= 0 then ( sum32 := sum32 + k2 ) else (if k3 /= 0 & (k3->compareTo(k2)) <= 0 then ( sum32 := sum32 + k3 ) else skip) ) else (if (k6->compareTo(k2)) <= 0 & (k6->compareTo(k5)) <= 0 then ( sum256 := sum256 + k6 ; k2 := k2 - k6 ; if k3 /= 0 & (k2->compareTo(k3)) <= 0 then ( sum32 := sum32 + k2 ) else (if k3 /= 0 & (k3->compareTo(k2)) <= 0 then ( sum32 := sum32 + k3 ) else skip) ) else skip ) ) ; execute (sum32 * 32 + sum256 * 256)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=list(map(int,input().split())) count=min(k[0],k[2],k[3]) k[0]-=count sum=256*count count=min(k[0],k[1]) sum+=32*count print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : OclAny := Set{k->first(), k[2+1], k[3+1]}->min() ; k->first() := k->first() - count ; var sum : double := 256 * count ; count := Set{k->first(), k[1+1]}->min() ; sum := sum + 32 * count ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k2,k3,k5,k6=map(int,input().split()) u=0 p=min(k2,k5,k6) u+=p*256 k2-=p q=min(k2,k3) u+=q*32 print(u) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k2 : OclAny := null; var k3 : OclAny := null; var k5 : OclAny := null; var k6 : OclAny := null; Sequence{k2,k3,k5,k6} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var u : int := 0 ; var p : OclAny := Set{k2, k5, k6}->min() ; u := u + p * 256 ; k2 := k2 - p ; var q : OclAny := Set{k2, k3}->min() ; u := u + q * 32 ; execute (u)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=list(map(int,input().split())) k2,k3,k5,k6=l[0],l[1],l[2],l[3] l.remove(k3) m=min(l) s=m*256 k=k2-m if k>k3 : y=32*k3 else : y=32*k print(s+y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k2 : OclAny := null; var k3 : OclAny := null; var k5 : OclAny := null; var k6 : OclAny := null; Sequence{k2,k3,k5,k6} := Sequence{l->first(),l[1+1],l[2+1],l[3+1]} ; execute ((k3) /: l) ; var m : OclAny := (l)->min() ; var s : double := m * 256 ; var k : double := k2 - m ; if (k->compareTo(k3)) > 0 then ( var y : double := 32 * k3 ) else ( y := 32 * k ) ; execute (s + y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkUtil(num,dig,base): if(dig==1 and num1 and num>=base): return checkUtil(num/base,--dig,base) return False def check(num,dig): for base in range(2,33): if(checkUtil(num,dig,base)): return True return False num=8 dig=3 if(check(num,dig)==True): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; num := 8 ; dig := 3 ; if (check(num, dig) = true) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation checkUtil(num : OclAny, dig : OclAny, base : OclAny) : OclAny pre: true post: true activity: if (dig = 1 & (num->compareTo(base)) < 0) then ( return true ) else skip ; if (dig > 1 & (num->compareTo(base)) >= 0) then ( return checkUtil(num / base, --dig, base) ) else skip ; return false; operation check(num : OclAny, dig : OclAny) : OclAny pre: true post: true activity: for base : Integer.subrange(2, 33-1) do ( if (checkUtil(num, dig, base)) then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k2,k3,k5,k6=list(map(int,input().split())) a=min(k2,k5,k6) b=min(k2-a,k3) print((a*256)+(b*32)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k2 : OclAny := null; var k3 : OclAny := null; var k5 : OclAny := null; var k6 : OclAny := null; Sequence{k2,k3,k5,k6} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := Set{k2, k5, k6}->min() ; var b : OclAny := Set{k2 - a, k3}->min() ; execute ((a * 256) + (b * 32))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math r,x1,y1,x2,y2=map(int,input().split()) a=math.pow((x1-x2),2) b=math.pow((y1-y2),2) distance=math.sqrt(a+b) answer=math.ceil(distance/(r*2)) print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var r : OclAny := null; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{r,x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : double := ((x1 - x2))->pow(2) ; var b : double := ((y1 - y2))->pow(2) ; var distance : double := (a + b)->sqrt() ; var answer : double := (distance / (r * 2))->ceil() ; execute (answer)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt r,x,y,x1,y1=map(int,input().split()) s=sqrt((x1-x)**2+(y1-y)**2) k=s//(2*r) if s==0 : print(0) elif s<=2*r : print(1) elif s==2*r*k : print(int(k)) else : print(int(k+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var r : OclAny := null; var x : OclAny := null; var y : OclAny := null; var x1 : OclAny := null; var y1 : OclAny := null; Sequence{r,x,y,x1,y1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : OclAny := sqrt(((x1 - x))->pow(2) + ((y1 - y))->pow(2)) ; var k : int := s div (2 * r) ; if s = 0 then ( execute (0)->display() ) else (if (s->compareTo(2 * r)) <= 0 then ( execute (1)->display() ) else (if s = 2 * r * k then ( execute (("" + ((k)))->toInteger())->display() ) else ( execute (("" + ((k + 1)))->toInteger())->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math r,x1,y1,x2,y2=map(int,input().split()) a=abs(x2-x1) b=abs(y2-y1) z=((a*a)+(b*b))**0.5 k=math.ceil(z/(2*r)) print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var r : OclAny := null; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{r,x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : double := (x2 - x1)->abs() ; var b : double := (y2 - y1)->abs() ; var z : double := (((a * a) + (b * b)))->pow(0.5) ; var k : double := (z / (2 * r))->ceil() ; execute (k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math u,H1,M1,H2,M2=map(int,input().split()) e=abs(H2-H1) r=abs(M2-M1) z=((e*e)+(r*r))**0.5 k=math.ceil(z/(2*u)) print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var u : OclAny := null; var H1 : OclAny := null; var M1 : OclAny := null; var H2 : OclAny := null; var M2 : OclAny := null; Sequence{u,H1,M1,H2,M2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var e : double := (H2 - H1)->abs() ; var r : double := (M2 - M1)->abs() ; var z : double := (((e * e) + (r * r)))->pow(0.5) ; var k : double := (z / (2 * u))->ceil() ; execute (k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(i)for i in input().split(" ")] c=[int(i)for i in input().split(" ")] b=[int(i)for i in input().split(" ")] d=[] s1=0 s2=sum(c) z=b[0]+s2 d.append(z) for i in range(1,n): z=b[i]; s1+=a[i-1] s2-=c[i-1] z+=s1+s2 d.append(z) d.sort() print(d[0]+d[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var c : Sequence := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var b : Sequence := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var d : Sequence := Sequence{} ; var s1 : int := 0 ; var s2 : OclAny := (c)->sum() ; var z : OclAny := b->first() + s2 ; execute ((z) : d) ; for i : Integer.subrange(1, n-1) do ( z := b[i+1]; ; s1 := s1 + a[i - 1+1] ; s2 := s2 - c[i - 1+1] ; z := z + s1 + s2 ; execute ((z) : d)) ; d := d->sort() ; execute (d->first() + d[1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil,sqrt r,x1,y1,x2,y2=map(int,input().split()) print(ceil(sqrt((x1-x2)**2+(y1-y2)**2)/(r*2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var r : OclAny := null; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{r,x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (ceil(sqrt(((x1 - x2))->pow(2) + ((y1 - y2))->pow(2)) / (r * 2)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a,b=int(input()),int(input()) n=round(math.log(b,a)) if a**n!=b or n<1 : print('NO') else : print('YES\n'+str(n-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),("" + (((OclFile["System.in"]).readLine())))->toInteger()} ; var n : double := ((b, a)->log())->round() ; if (a)->pow(n) /= b or n < 1 then ( execute ('NO')->display() ) else ( execute ('YES ' + ("" + ((n - 1))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) i=1 while a**i<=b : if a**i==b : break i+=1 if a**i==b : print("YES") print(i-1) else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 1 ; while ((a)->pow(i)->compareTo(b)) <= 0 do ( if (a)->pow(i) = b then ( break ) else skip ; i := i + 1) ; if (a)->pow(i) = b then ( execute ("YES")->display() ; execute (i - 1)->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) i=1 while a**i<=b : if a**i==b : break i+=1 if a**i==b : print("YES") print(i-1) else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 1 ; while ((a)->pow(i)->compareTo(b)) <= 0 do ( if (a)->pow(i) = b then ( break ) else skip ; i := i + 1) ; if (a)->pow(i) = b then ( execute ("YES")->display() ; execute (i - 1)->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np N,M,X=map(int,input().split()) a=np.zeros((N,M+1)) for i in range(N): a[i]=[int(x)for x in input().split()] b=np.zeros(N) c=np.zeros(M+1) min_cost=9999999999999999 for i in range(2**N): ii=i for j in range(N): b[j]=ii % 2 ii=ii//2 c=np.zeros(M+1) flg="ok" for k in range(M+1): for j in range(N): c[k]+=a[j,k]*b[j] if k>0 and c[k]collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := MatrixLib.singleValueMatrix(Sequence{N, M + 1}, 0.0) ; for i : Integer.subrange(0, N-1) do ( a[i+1] := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger()))) ; var b : Sequence := MatrixLib.singleValueMatrix(N, 0.0) ; var c : Sequence := MatrixLib.singleValueMatrix(M + 1, 0.0) ; var min_cost : int := 9999999999999999 ; for i : Integer.subrange(0, (2)->pow(N)-1) do ( var ii : OclAny := i ; for j : Integer.subrange(0, N-1) do ( b[j+1] := ii mod 2 ; ii := ii div 2) ; c := MatrixLib.singleValueMatrix(M + 1, 0.0) ; var flg : String := "ok" ; for k : Integer.subrange(0, M + 1-1) do ( for j : Integer.subrange(0, N-1) do ( c[k+1] := c[k+1] + a[j+1][k+1] * b[j+1]) ; if k > 0 & (c[k+1]->compareTo(X)) < 0 then ( flg := "ng" ; continue ) else skip) ; if flg = "ok" then ( min_cost := Set{min_cost, c->first()}->min() ) else skip) ; if min_cost = 9999999999999999 then ( execute (-1)->display() ) else ( execute (("" + ((min_cost)))->toInteger())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) l=int(input()) for i in range(31): if k**i==l : print("YES") print(i-1) break else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 31))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name k))) ** (expr (atom (name i))))) == (comparison (expr (atom (name l))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) l=int(input()) c=0 while(l>1 and l % k==0): l=l//k c+=1 if(l==1): print('YES') print(c-1) else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := 0 ; while (l > 1 & l mod k = 0) do ( l := l div k ; c := c + 1) ; if (l = 1) then ( execute ('YES')->display() ; execute (c - 1)->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from operator import xor def findXOR(n): mod=n % 4 ; if(mod==0): return n ; elif(mod==1): return 1 ; elif(mod==2): return n+1 ; elif(mod==3): return 0 ; def findXORFun(l,r): return(xor(findXOR(l-1),findXOR(r))); l=4 ; r=8 ; print(findXORFun(l,r)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; l := 4; r := 8; ; execute (findXORFun(l, r))->display();; operation findXOR(n : OclAny) pre: true post: true activity: var mod : int := n mod 4; ; if (mod = 0) then ( return n; ) else (if (mod = 1) then ( return 1; ) else (if (mod = 2) then ( return n + 1; ) else (if (mod = 3) then ( return 0; ) else skip ) ) ) ; operation findXORFun(l : OclAny, r : OclAny) pre: true post: true activity: return (xor(findXOR(l - 1), findXOR(r)));; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Arrive(a,b,n): if(n>=abs(a)+abs(b)and(n-(abs(a)+abs(b)))% 2==0): return True return False a=5 b=5 n=11 if(Arrive(a,b,n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 5 ; b := 5 ; n := 11 ; if (Arrive(a, b, n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation Arrive(a : OclAny, b : OclAny, n : OclAny) : OclAny pre: true post: true activity: if ((n->compareTo((a)->abs() + (b)->abs())) >= 0 & (n - ((a)->abs() + (b)->abs())) mod 2 = 0) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,p,k=map(int,input().split()) a=list(map(int,input().split())) cnt=defaultdict(lambda : 0) ans=0 for i in a : u=(pow(i,4,p)-k*i % p)% p ans+=cnt[u] cnt[u]+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : OclAny := null; var p : OclAny := null; var k : OclAny := null; Sequence{n,p,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; var ans : int := 0 ; for i : a do ( var u : int := ((i)->pow(4) - k * i mod p) mod p ; ans := ans + cnt[u+1] ; cnt[u+1] := cnt[u+1] + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter def pr(x): return(x*(x-1))//2 n,p,k=map(int,input().split()) a=map(int,input().split()) a=Counter([(x**4-x*k+p)% p for x in a]) print(sum(pr(a[x])for x in a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var p : OclAny := null; var k : OclAny := null; Sequence{n,p,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := Counter(a->select(x | true)->collect(x | (((x)->pow(4) - x * k + p) mod p))) ; execute (((argument (test (logical_test (comparison (expr (atom (name pr)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ])))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a))))))))->sum())->display(); operation pr(x : OclAny) : OclAny pre: true post: true activity: return (x * (x - 1)) div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) fr,sr=[int(i)for i in input().split()],[int(i)for i in input().split()] cross=[int(i)for i in input().split()] spend_time=[sum(sr)+cross[0]] for i in range(1,N): summ=spend_time[-1]-sr[i-1]-cross[i-1] summ=summ+fr[i-1]+cross[i] spend_time.append(summ) spend_time.sort() print(spend_time[0]+spend_time[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var fr : OclAny := null; var sr : OclAny := null; Sequence{fr,sr} := Sequence{input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())),input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))} ; var cross : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var spend_time : Sequence := Sequence{ (sr)->sum() + cross->first() } ; for i : Integer.subrange(1, N-1) do ( var summ : double := spend_time->last() - sr[i - 1+1] - cross[i - 1+1] ; summ := summ + fr[i - 1+1] + cross[i+1] ; execute ((summ) : spend_time)) ; spend_time := spend_time->sort() ; execute (spend_time->first() + spend_time[1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict n,p,k=map(int,input().split()) counter=defaultdict(int) for a in map(int,input().split()): num=a**4-k*a num %=p counter[num]+=1 ans=0 for key,value in counter.items(): ans+=value*(value-1)//2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var p : OclAny := null; var k : OclAny := null; Sequence{n,p,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var counter : OclAny := defaultdict(OclType["int"]) ; for a : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( var num : double := (a)->pow(4) - k * a ; num := num mod p ; counter[num+1] := counter[num+1] + 1) ; var ans : int := 0 ; for _tuple : counter->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); ans := ans + value * (value - 1) div 2) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,p,k=map(int,input().split()); pairs={} count=0 for i in map(int,input().split()): t=(i**4-k*i)% p if t in pairs : count=count+pairs[t] pairs[t]+=1 else : pairs[t]=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var p : OclAny := null; var k : OclAny := null; Sequence{n,p,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); ; var pairs : OclAny := Set{} ; var count : int := 0 ; for i : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( var t : int := ((i)->pow(4) - k * i) mod p ; if (pairs)->includes(t) then ( count := count + pairs[t+1] ; pairs[t+1] := pairs[t+1] + 1 ) else ( pairs[t+1] := 1 )) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=5 def largestSideLen(matrix): result=1 for i in range(int(n/2)): element=matrix[i][i] isSquare=1 for j in range(i,n-i): if(matrix[i][j]!=element): isSquare=0 if(matrix[n-i-1][j]!=element): isSquare=0 if(matrix[j][i]!=element): isSquare=0 if(matrix[j][n-i-1]!=element): isSquare=0 if(isSquare): return n-2*i return result if __name__=='__main__' : matrix=[[1,1,1,1,1],[1,2,2,2,1],[1,2,1,2,1],[1,2,2,2,1],[1,1,1,1,1]] print(largestSideLen(matrix)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := 5 ; skip ; if __name__ = '__main__' then ( matrix := Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))))}->union(Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 1 }))))}->union(Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 1 }))))}->union(Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 1 }))))}->union(Sequence{ Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 })))) })))) ; execute (largestSideLen(matrix))->display() ) else skip; operation largestSideLen(matrix : OclAny) : OclAny pre: true post: true activity: var result : int := 1 ; for i : Integer.subrange(0, ("" + ((n / 2)))->toInteger()-1) do ( var element : OclAny := matrix[i+1][i+1] ; var isSquare : int := 1 ; for j : Integer.subrange(i, n - i-1) do ( if (matrix[i+1][j+1] /= element) then ( isSquare := 0 ) else skip ; if (matrix[n - i - 1+1][j+1] /= element) then ( isSquare := 0 ) else skip ; if (matrix[j+1][i+1] /= element) then ( isSquare := 0 ) else skip ; if (matrix[j+1][n - i - 1+1] /= element) then ( isSquare := 0 ) else skip) ; if (isSquare) then ( return n - 2 * i ) else skip) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy def comall(depth,n,x,a,usum,vsum): allok=True for i in range(1,len(usum)): if usum[i]=n : return 10000000 else : v1=comall(depth+1,n,x,a,copy.copy(usum),vsum) for i in range(1,len(usum)): usum[i]+=a[depth][i] v2=comall(depth+1,n,x,a,copy.copy(usum),vsum+a[depth][0]) return min(v1,v2) def main(): nmx=input().split() n=int(nmx[0]) m=int(nmx[1]) x=int(nmx[2]) c=[] for i in range(n): cn=list(map(lambda x : int(x),input().split())) c.append(cn) ans=comall(0,n,x,c,[0]*(m+1),0) if ans==10000000 : print(-1) else : print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; main(); operation comall(depth : OclAny, n : OclAny, x : OclAny, a : OclAny, usum : OclAny, vsum : OclAny) : OclAny pre: true post: true activity: var allok : boolean := true ; for i : Integer.subrange(1, (usum)->size()-1) do ( if (usum[i+1]->compareTo(x)) < 0 then ( allok := false ; break ) else skip) ; if allok then ( return vsum ) else ( if (depth->compareTo(n)) >= 0 then ( return 10000000 ) else ( var v1 : OclAny := comall(depth + 1, n, x, a, copy->copy(), vsum) ; for i : Integer.subrange(1, (usum)->size()-1) do ( usum[i+1] := usum[i+1] + a[depth+1][i+1]) ; var v2 : OclAny := comall(depth + 1, n, x, a, copy->copy(), vsum + a[depth+1]->first()) ; return Set{v1, v2}->min() ) ); operation main() pre: true post: true activity: var nmx : OclAny := input().split() ; n := ("" + ((nmx->first())))->toInteger() ; var m : int := ("" + ((nmx[1+1])))->toInteger() ; x := ("" + ((nmx[2+1])))->toInteger() ; var c : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var cn : Sequence := ((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) )) ; execute ((cn) : c)) ; var ans : OclAny := comall(0, n, x, c, MatrixLib.elementwiseMult(Sequence{ 0 }, (m + 1)), 0) ; if ans = 10000000 then ( execute (-1)->display() ) else ( execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) even=0 odd=0 for i in range(n): if((i % 2)!=(l[i]% 2)): if(i % 2==0): even=even+1 else : odd=odd+1 if(even==odd): print(odd) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var even : int := 0 ; var odd : int := 0 ; for i : Integer.subrange(0, n-1) do ( if ((i mod 2) /= (l[i+1] mod 2)) then ( if (i mod 2 = 0) then ( even := even + 1 ) else ( odd := odd + 1 ) ) else skip) ; if (even = odd) then ( execute (odd)->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=[int(i)for i in input().strip().split()] c0=0 c1=0 for i in range(n): if i % 2==0 : if a[i]% 2!=0 : c0+=1 else : if a[i]% 2!=1 : c1+=1 if c0!=c1 : print(-1) else : print(c0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input()->trim().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var c0 : int := 0 ; var c1 : int := 0 ; for i : Integer.subrange(0, n-1) do ( if i mod 2 = 0 then ( if a[i+1] mod 2 /= 0 then ( c0 := c0 + 1 ) else skip ) else ( if a[i+1] mod 2 /= 1 then ( c1 := c1 + 1 ) else skip )) ; if c0 /= c1 then ( execute (-1)->display() ) else ( execute (c0)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) re=[] for a in range(a): temp=int(input()) arr=[int(arr)for arr in input().split()] even=0 odd=0 move=0 for i in range(len(arr)): if(i % 2!=arr[i]% 2): if(i % 2==0): even=even+1 else : odd=odd+1 if(even>0 and odd>0): move=move+1 even=even-1 odd=odd-1 if(even>0 or odd>0): re.append(-1) else : re.append(move) for i in re : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var re : Sequence := Sequence{} ; for a : Integer.subrange(0, a-1) do ( var temp : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := input().split()->select(arr | true)->collect(arr | (("" + ((arr)))->toInteger())) ; var even : int := 0 ; var odd : int := 0 ; var move : int := 0 ; for i : Integer.subrange(0, (arr)->size()-1) do ( if (i mod 2 /= arr[i+1] mod 2) then ( if (i mod 2 = 0) then ( even := even + 1 ) else ( odd := odd + 1 ) ) else skip ; if (even > 0 & odd > 0) then ( move := move + 1 ; even := even - 1 ; odd := odd - 1 ) else skip) ; if (even > 0 or odd > 0) then ( execute ((-1) : re) ) else ( execute ((move) : re) )) ; for i : re do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) ls=list(map(int,input().split())) a,b=0,0 for i in range(n): if i % 2!=ls[i]% 2 : if i % 2==0 : a+=1 else : b+=1 if a!=b : print(-1) else : print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ls : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{0,0} ; for i : Integer.subrange(0, n-1) do ( if i mod 2 /= ls[i+1] mod 2 then ( if i mod 2 = 0 then ( a := a + 1 ) else ( b := b + 1 ) ) else skip) ; if a /= b then ( execute (-1)->display() ) else ( execute (a)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): input() L=list(map(int,input().split())) count=0 flag=False for idx in range(len(L)): a=idx % 2 if a!=L[idx]% 2 : for k in range(idx+1,len(L)): if k % 2!=a and L[k]% 2==a : L[idx],L[k]=L[k],L[idx] count+=1 break else : print(-1) flag=True break if flag : break else : print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( input() ; var L : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : int := 0 ; var flag : boolean := false ; (compound_stmt for (exprlist (expr (atom (name idx)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)))))))) ))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name a)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name idx))) % (expr (atom (number (integer 2)))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name a)))) != (comparison (expr (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name idx)))))))) ]))) % (expr (atom (number (integer 2))))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name k)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name idx))) + (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name L)))))))) ))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (expr (atom (name k))) % (expr (atom (number (integer 2)))))) != (comparison (expr (atom (name a)))))) and (logical_test (comparison (comparison (expr (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ]))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (name a)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name idx)))))))) ])))))) , (test (logical_test (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ]))))))) (assign_part = (testlist_star_expr (test (logical_test (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])))))) , (test (logical_test (comparison (expr (atom (name L)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name idx)))))))) ]))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name count)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name flag)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name True)))))))))))) (stmt (simple_stmt (small_stmt break)))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name flag)))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name count)))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fact(n): res=1 for i in range(2,n+1): res=res*i return res def Count_number(N): return(N*fact(N)) N=2 print(Count_number(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; N := 2 ; execute (Count_number(N))->display(); operation fact(n : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; for i : Integer.subrange(2, n + 1-1) do ( res := res * i) ; return res; operation Count_number(N : OclAny) : OclAny pre: true post: true activity: return (N * fact(N)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printOrder(arr,n): arr.sort() for i in range(n//2): print(arr[i],end=" ") for j in range(n-1,n//2-1,-1): print(arr[j],end=" ") if __name__=="__main__" : arr=[5,4,6,2,1,3,8,-1] n=len(arr) printOrder(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{5}->union(Sequence{4}->union(Sequence{6}->union(Sequence{2}->union(Sequence{1}->union(Sequence{3}->union(Sequence{8}->union(Sequence{ -1 }))))))) ; n := (arr)->size() ; printOrder(arr, n) ) else skip; operation printOrder(arr : OclAny, n : OclAny) pre: true post: true activity: arr := arr->sort() ; for i : Integer.subrange(0, n div 2-1) do ( execute (arr[i+1])->display()) ; for j : Integer.subrange(n div 2 - 1 + 1, n - 1)->reverse() do ( execute (arr[j+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(raw_input()) ns=map(int,raw_input().split()) dp=[[0]*21 for _ in xrange(n)] for i in xrange(n-1): for j in xrange(21): if i==0 : if ns[i]==j : dp[i+1][j]=1 break continue if j-ns[i]>=0 and j+ns[i]<=20 : dp[i+1][j]=dp[i][j-ns[i]]+dp[i][j+ns[i]] elif j-ns[i]>=0 : dp[i+1][j]=dp[i][j-ns[i]] else : dp[i+1][j]=dp[i][j+ns[i]] print(dp[n-1][ns[-1]]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + ((raw_input())))->toInteger() ; var ns : Sequence := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dp : Sequence := xrange(n)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 21))) ; for i : xrange(n - 1) do ( for j : xrange(21) do ( if i = 0 then ( if ns[i+1] = j then ( dp[i + 1+1][j+1] := 1 ; break ) else skip ; continue ) else skip ; if j - ns[i+1] >= 0 & j + ns[i+1] <= 20 then ( dp[i + 1+1][j+1] := dp[i+1][j - ns[i+1]+1] + dp[i+1][j + ns[i+1]+1] ) else (if j - ns[i+1] >= 0 then ( dp[i + 1+1][j+1] := dp[i+1][j - ns[i+1]+1] ) else ( dp[i + 1+1][j+1] := dp[i+1][j + ns[i+1]+1] ) ) )) ; execute (dp[n - 1+1][ns->last()+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) across=[list(map(int,input().split()))for i in range(2)] down=list(map(int,input().split())) path=down[0]+sum(across[1]) costs=[path] for i,top in enumerate(across[0]): bottom=across[1][i] path=path-down[i]-bottom+down[i+1]+top costs.append(path) costs.sort() print(costs[0]+costs[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var across : Sequence := Integer.subrange(0, 2-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var down : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var path : OclAny := down->first() + (across[1+1])->sum() ; var costs : Sequence := Sequence{ path } ; for _tuple : Integer.subrange(1, (across->first())->size())->collect( _indx | Sequence{_indx-1, (across->first())->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var top : OclAny := _tuple->at(_indx); var bottom : OclAny := across[1+1][i+1] ; path := path - down[i+1] - bottom + down[i + 1+1] + top ; execute ((path) : costs)) ; costs := costs->sort() ; execute (costs->first() + costs[1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isOrthogonal(a,m,n): if(m!=n): return False trans=[[0 for x in range(n)]for y in range(n)] for i in range(0,n): for j in range(0,n): trans[i][j]=a[j][i] prod=[[0 for x in range(n)]for y in range(n)] for i in range(0,n): for j in range(0,n): sum=0 for k in range(0,n): sum=sum+(a[i][k]*a[j][k]) prod[i][j]=sum for i in range(0,n): for j in range(0,n): if(i!=j and prod[i][j]!=0): return False if(i==j and prod[i][j]!=1): return False return True a=[[1,0,0],[0,1,0],[0,0,1]] if(isOrthogonal(a,3,3)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{Sequence{1}->union(Sequence{0}->union(Sequence{ 0 }))}->union(Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{ 0 }))}->union(Sequence{ Sequence{0}->union(Sequence{0}->union(Sequence{ 1 })) })) ; if (isOrthogonal(a, 3, 3)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isOrthogonal(a : OclAny, m : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (m /= n) then ( return false ) else skip ; var trans : Sequence := Integer.subrange(0, n-1)->select(y | true)->collect(y | (Integer.subrange(0, n-1)->select(x | true)->collect(x | (0)))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( trans[i+1][j+1] := a[j+1][i+1])) ; var prod : Sequence := Integer.subrange(0, n-1)->select(y | true)->collect(y | (Integer.subrange(0, n-1)->select(x | true)->collect(x | (0)))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( var sum : int := 0 ; for k : Integer.subrange(0, n-1) do ( sum := sum + (a[i+1][k+1] * a[j+1][k+1])) ; prod[i+1][j+1] := sum)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if (i /= j & prod[i+1][j+1] /= 0) then ( return false ) else skip ; if (i = j & prod[i+1][j+1] /= 1) then ( return false ) else skip)) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,x=map(int,input().split()) c=[0]*n a=[] ans=float('inf') for i in range(n): l=list(map(int,input().split())) c[i]=l.pop(0) a.append(l) for bit in range(1<>i): sumnum+=c[i] for j in range(m): s[j]+=a[i][j] flag=True for k in range(m): if s[k]collect( _x | (OclType["int"])->apply(_x) ) ; var c : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var a : Sequence := Sequence{} ; var ans : double := ("" + (('inf')))->toReal() ; for i : Integer.subrange(0, n-1) do ( var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; c[i+1] := l->at(0`firstArg+1) ; l := l->excludingAt(0+1) ; execute ((l) : a)) ; for bit : Integer.subrange(0, 1 * (2->pow(n))-1) do ( var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; var sumnum : int := 0 ; for i : Integer.subrange(0, n-1) do ( if MathLib.bitwiseAnd(1, (bit /(2->pow(i)))) then ( sumnum := sumnum + c[i+1] ; for j : Integer.subrange(0, m-1) do ( s[j+1] := s[j+1] + a[i+1][j+1]) ) else skip) ; var flag : boolean := true ; for k : Integer.subrange(0, m-1) do ( if (s[k+1]->compareTo(x)) < 0 then ( flag := false ; break ) else skip) ; if flag then ( ans := Set{ans, sumnum}->min() ) else skip) ; if ans /= ("" + (('inf')))->toReal() then ( execute (ans)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def removeElements(arr,n,l,r): mp={i : 0 for i in range(len(arr))} for i in range(n): mp[arr[i]]+=1 for i in range(n): if(mp[arr[i]]r]): print(arr[i],end=" ") if __name__=='__main__' : arr=[1,2,3,3,2,2,5] n=len(arr) l=2 r=3 removeElements(arr,n,l,r); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{3}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 5 })))))) ; n := (arr)->size() ; l := 2 ; r := 3 ; removeElements(arr, n, l, r); ) else skip; operation removeElements(arr : OclAny, n : OclAny, l : OclAny, r : OclAny) pre: true post: true activity: var mp : Map := Integer.subrange(0, (arr)->size()-1)->select(i | true)->collect(i | Map{i |-> 0})->unionAll() ; for i : Integer.subrange(0, n-1) do ( mp[arr[i+1]+1] := mp[arr[i+1]+1] + 1) ; for i : Integer.subrange(0, n-1) do ( if ((mp[arr[i+1]+1]->compareTo(l)) < 0 or mp->select((arr[i+1]->compareTo(r)) > 0)) then ( execute (arr[i+1])->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- d={} for _ in range(int(input())): op,key,x=(input().split()+[''])[: 3] if op=='0' : d[key]=x else : print(d[key]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var d : OclAny := Set{} ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var op : OclAny := null; var key : OclAny := null; var x : OclAny := null; Sequence{op,key,x} := (input().split()->union(Sequence{ '' })).subrange(1,3) ; if op = '0' then ( d[key+1] := x ) else ( execute (d[key+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): q=int(input()) d={} for i in range(q): query=input() cmd=int(query[0]) if cmd==0 : _,k,v=query.split(' ') v=int(v) d[k]=v elif cmd==1 : _,k=query.split(' ') v=d.get(k,None) if v : print(v) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : OclAny := Set{} ; for i : Integer.subrange(0, q-1) do ( var query : String := (OclFile["System.in"]).readLine() ; var cmd : int := ("" + ((query->first())))->toInteger() ; if cmd = 0 then ( var _anon : OclAny := null; var k : OclAny := null; var v : OclAny := null; Sequence{_anon,k,v} := query.split(' ') ; var v : int := ("" + ((v)))->toInteger() ; d[k+1] := v ) else (if cmd = 1 then ( var _anon : OclAny := null; var k : OclAny := null; Sequence{_anon,k} := query.split(' ') ; v := d.get(k, null) ; if v then ( execute (v)->display() ) else skip ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- readline=open(0).readline Q=int(readline()) ans=[] M={} C=[M.__setitem__,lambda key,push=ans.append : push("%s\n" % M[key])].__getitem__ for q in range(Q): t,*a=readline().split() C(int(t))(*a) open(1,'w').writelines(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var readline : OclAny := open(0).readline ; var Q : int := ("" + ((readline())))->toInteger() ; var ans : Sequence := Sequence{} ; var M : OclAny := Set{} ; var C : OclAny := Sequence{M.__setitem__}->union(Sequence{ lambda key : OclAny, push : OclAny in (push(StringLib.format("%s\n",M[key+1]))) }).__getitem__ ; for q : Integer.subrange(0, Q-1) do ( var t : OclAny := null; var a : OclAny := null; Sequence{t,a} := readline().split() ; (expr (atom (name C)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) ))))))))) ))) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; (expr (atom (name open)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom 'w'))))))) ))) (trailer . (name writelines) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect D=[] N=[] count=0 def insert(D,N,count,key,x): y=bisect.bisect_left(D,key) if ytoInteger() ; for i : Integer.subrange(0, q-1) do ( var query : Sequence := ((input().split())->collect( _x | (OclType["String"])->apply(_x) )) ; query->first() := ("" + ((query->first())))->toInteger() ; if query->first() = 0 then ( Sequence{D,N,count} := insert(D, N, count, query[1+1], ("" + ((query[2+1])))->toInteger()) ) else ( get(D, N, query[1+1]) )); operation insert(D : OclAny, N : OclAny, count : OclAny, key : OclAny, x : OclAny) : OclAny pre: true post: true activity: var y : OclAny := bisect.bisect_left(D, key) ; if (y->compareTo(count)) < 0 & D[y+1] = key then ( N[y+1] := x ) else ( D := D.insertAt(y+1, key) ; N := N.insertAt(y+1, x) ; count := count + 1 ) ; return D, N, count; operation get(D : OclAny, N : OclAny, key : OclAny) pre: true post: true activity: y := bisect.bisect_left(D, key) ; execute (N[y+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict if __name__=="__main__" : num_query=int(input()) d : defaultdict=defaultdict() for _ in range(num_query): op,*v=input().split() if("0"==op): d[v[0]]=v[1] else : print(d[v[0]]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var num_query : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : OclAny := defaultdict() ; for _anon : Integer.subrange(0, num_query-1) do ( var op : OclAny := null; var v : OclAny := null; Sequence{op,v} := input().split() ; if ("0" = op) then ( d[v->first()+1] := v[1+1] ) else ( execute (d[v->first()+1])->display() )) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l1=input() l2=input() s=input() ans='' for i in s : if i.islower(): ans+=l2[l1.find(i)] elif i.isupper(): ans+=l2[l1.find(i.lower())].upper() else : ans+=i print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l1 : String := (OclFile["System.in"]).readLine() ; var l2 : String := (OclFile["System.in"]).readLine() ; var s : String := (OclFile["System.in"]).readLine() ; var ans : String := '' ; for i : s->characters() do ( if i->matches("[a-z ]*") then ( ans := ans + l2[l1->indexOf(i) - 1+1] ) else (if i->matches("[A-Z ]*") then ( ans := ans + l2[l1->indexOf(i->toLowerCase()) - 1+1]->toUpperCase() ) else ( ans := ans + i ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s1=input() s2=input() s3=input() s4='' for i in s3 : x=i.lower() if x in s1 : p=s1.index(x) q=s2[p] if i.islower(): s4+=q else : s4+=q.upper() else : s4+=i print(s4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s1 : String := (OclFile["System.in"]).readLine() ; var s2 : String := (OclFile["System.in"]).readLine() ; var s3 : String := (OclFile["System.in"]).readLine() ; var s4 : String := '' ; for i : s3->characters() do ( var x : String := i->toLowerCase() ; if (s1)->characters()->includes(x) then ( var p : int := s1->indexOf(x) - 1 ; var q : OclAny := s2[p+1] ; if i->matches("[a-z ]*") then ( s4 := s4 + q ) else ( s4 := s4 + q->toUpperCase() ) ) else ( s4 := s4 + i )) ; execute (s4)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q={} l=input() m=input() n=input() for i in range(26): q[l[i]]=m[i] for j in range(len(n)): if(n[j].isupper()==True): t=n[j].lower() t=q[t] t=t.upper() print(t,end="") elif(n[j].isdigit()==True): print(n[j],end="") else : print(q[n[j]],end="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var q : OclAny := Set{} ; var l : String := (OclFile["System.in"]).readLine() ; var m : String := (OclFile["System.in"]).readLine() ; var n : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, 26-1) do ( q[l[i+1]+1] := m[i+1]) ; for j : Integer.subrange(0, (n)->size()-1) do ( if (n[j+1]->matches("[A-Z ]*") = true) then ( var t : OclAny := n[j+1]->toLowerCase() ; t := q[t+1] ; t := t->toUpperCase() ; execute (t)->display() ) else (if (n[j+1]->matches("[0-9]*") = true) then ( execute (n[j+1])->display() ) else ( execute (q[n[j+1]+1])->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()); a=[[],[0],[0]]; b=[0]; ans=1e9 ; a[1].extend([int(v)for v in input().split(' ')]); a[2].extend([int(v)for v in input().split(' ')]); b.extend([int(v)for v in input().split(' ')]); for i in range(1,n): a[1][i]+=a[1][i-1]; for i in range(n-2,0,-1): a[2][i]+=a[2][i+1]; a[1].append(0),a[2].append(0); for i in range(1,n+1): for j in range(1,n+1): if i!=j : ans=min(ans,a[1][i-1]+b[i]+a[2][i]+a[1][j-1]+b[j]+a[2][j]); print(ans); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); ; var a : Sequence := Sequence{Sequence{}}->union(Sequence{Sequence{ 0 }}->union(Sequence{ Sequence{ 0 } })); ; var b : Sequence := Sequence{ 0 }; ; var ans : double := ("1e9")->toReal(); ; (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) (trailer . (name extend) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) ))))))) (comp_for for (exprlist (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ' '))))))) )))))))) ]))))))) )))); ; (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) (trailer . (name extend) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) ))))))) (comp_for for (exprlist (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ' '))))))) )))))))) ]))))))) )))); ; b := b->union(input().split(' ')->select(v | true)->collect(v | (("" + ((v)))->toInteger()))); ; for i : Integer.subrange(1, n-1) do ( a[1+1][i+1] := a[1+1][i+1] + a[1+1][i - 1+1];) ; for i : Integer.subrange(0 + 1, n - 2)->reverse() do ( a[2+1][i+1] := a[2+1][i+1] + a[2+1][i + 1+1];) ; a[1+1].append(0) ; (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))); ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, n + 1-1) do ( if i /= j then ( ans := Set{ans, a[1+1][i - 1+1] + b[i+1] + a[2+1][i+1] + a[1+1][j - 1+1] + b[j+1] + a[2+1][j+1]}->min(); ) else skip)) ; execute (ans)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math N,M,X=map(int,input().split()) A={} B={} ANS=100000000000 for i in range(1,N+1): A[i]=list(map(int,input().split())) for i in range(1,2**N): l=str(bin(i)) n=len(l) ans=0 for s in range(1,M+1): B[s]=0 for k in range(1,n+1): if l[-k]=="1" : ans=ans+A[k][0] for s in range(1,M+1): B[s]+=A[k][s] if all((B[l]>=X for l in range(1,M+1))): ANS=min(ans,ANS) if ANS==100000000000 : print("-1") else : print(ANS) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var M : OclAny := null; var X : OclAny := null; Sequence{N,M,X} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : OclAny := Set{} ; var B : OclAny := Set{} ; var ANS : int := 100000000000 ; for i : Integer.subrange(1, N + 1-1) do ( A[i+1] := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; for i : Integer.subrange(1, (2)->pow(N)-1) do ( var l : String := ("" + ((bin(i)))) ; var n : int := (l)->size() ; var ans : int := 0 ; for s : Integer.subrange(1, M + 1-1) do ( B[s+1] := 0) ; for k : Integer.subrange(1, n + 1-1) do ( if l->reverse()->at(-(-k)) = "1" then ( ans := ans + A[k+1]->first() ; for s : Integer.subrange(1, M + 1-1) do ( B[s+1] := B[s+1] + A[k+1][s+1]) ) else skip) ; if (Sequence{(testlist_comp (test (logical_test (comparison (comparison (expr (atom (name B)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name l)))))))) ])))) >= (comparison (expr (atom (name X))))))) (comp_for for (exprlist (expr (atom (name l)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name M))) + (expr (atom (number (integer 1)))))))))) ))))))))})->forAll( _x | _x = true ) then ( ANS := Set{ans, ANS}->min() ) else skip) ; if ANS = 100000000000 then ( execute ("-1")->display() ) else ( execute (ANS)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=input() d=dict(zip(a+a.upper(),b+b.upper())) print(''.join(d.get(c,c)for c in input())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; var d : Map := ((expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name a))) + (expr (atom (name a)) (trailer . (name upper) (arguments ( ))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name b))) + (expr (atom (name b)) (trailer . (name upper) (arguments ( )))))))))) ))))) ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name d)) (trailer . (name get) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c))))))) , (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t1,t2,t3=input(),input(),input().strip() d={} for i in range(48,58): x=chr(i) d[x]=x for i in range(26): d[t1[i]]=t2[i] d[chr(ord(t1[i])-32)]=chr(ord(t2[i])-32) ans="" for x in t3 : ans+=d[x] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t1 : OclAny := null; var t2 : OclAny := null; var t3 : OclAny := null; Sequence{t1,t2,t3} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine(),input()->trim()} ; var d : OclAny := Set{} ; for i : Integer.subrange(48, 58-1) do ( var x : String := (i)->byte2char() ; d->at(x) := x) ; for i : Integer.subrange(0, 26-1) do ( d[t1[i+1]+1] := t2[i+1] ; d[((t1[i+1])->char2byte() - 32)->byte2char()+1] := ((t2[i+1])->char2byte() - 32)->byte2char()) ; var ans : String := "" ; for x : t3 do ( ans := ans + d->at(x)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculatePower(b,e): ans=1 ; while(e>0): if(e % 2==1): ans=ans*b ; e=e//2 ; b=b*b ; return ans ; def CountSubSet(arr,n,X): count=0 ; checkX=0 ; for i in range(n): if(arr[i]==X): checkX=1 ; break ; if(checkX==1): count=calculatePower(2,n-1); else : count=0 ; return count ; if __name__=="__main__" : arr=[4,5,6,7]; X=5 ; n=len(arr); print(CountSubSet(arr,n,X)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 7 }))); ; X := 5; ; n := (arr)->size(); ; execute (CountSubSet(arr, n, X))->display(); ) else skip; operation calculatePower(b : OclAny, e : OclAny) pre: true post: true activity: var ans : int := 1; ; while (e > 0) do ( if (e mod 2 = 1) then ( ans := ans * b; ) else skip ; e := e div 2; ; b := b * b;) ; return ans;; operation CountSubSet(arr : OclAny, n : OclAny, X : OclAny) pre: true post: true activity: var count : int := 0; var checkX : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] = X) then ( checkX := 1; ; break; ) else skip) ; if (checkX = 1) then ( count := calculatePower(2, n - 1); ) else ( count := 0; ) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- M=100 def minAdjustmentCost(A,n,target): dp=[[0 for i in range(M+1)]for i in range(n)] for j in range(M+1): dp[0][j]=abs(j-A[0]) for i in range(1,n): for j in range(M+1): dp[i][j]=100000000 for k in range(max(j-target,0),min(M,j+target)+1): dp[i][j]=min(dp[i][j],dp[i-1][k]+abs(A[i]-j)) res=10000000 for j in range(M+1): res=min(res,dp[n-1][j]) return res arr=[55,77,52,61,39,6,25,60,49,47] n=len(arr) target=10 print("Minimum adjustment cost is",minAdjustmentCost(arr,n,target),sep=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var M : int := 100 ; skip ; var arr : Sequence := Sequence{55}->union(Sequence{77}->union(Sequence{52}->union(Sequence{61}->union(Sequence{39}->union(Sequence{6}->union(Sequence{25}->union(Sequence{60}->union(Sequence{49}->union(Sequence{ 47 }))))))))) ; n := (arr)->size() ; target := 10 ; execute ("Minimum adjustment cost is")->display(); operation minAdjustmentCost(A : OclAny, n : OclAny, target : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, M + 1-1)->select(i | true)->collect(i | (0)))) ; for j : Integer.subrange(0, M + 1-1) do ( dp->first()[j+1] := (j - A->first())->abs()) ; for i : Integer.subrange(1, n-1) do ( for j : Integer.subrange(0, M + 1-1) do ( dp[i+1][j+1] := 100000000 ; for k : Integer.subrange(Set{j - target, 0}->max(), Set{M, j + target}->min() + 1-1) do ( dp[i+1][j+1] := Set{dp[i+1][j+1], dp[i - 1+1][k+1] + (A[i+1] - j)->abs()}->min()))) ; var res : int := 10000000 ; for j : Integer.subrange(0, M + 1-1) do ( res := Set{res, dp[n - 1+1][j+1]}->min()) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- max2=lambda x,y : x if x>y else y def solve(N,A,B): if A+B>N+1 : return None if A*Bp[i]: dp[i]=max2(dp[i],dp[j]+1) b=max(dp) if a==A and b==B : return p return None if __name__=='__main__' : N,A,B=map(int,input().split()) res=solve(N,A,B) if res is None : print(-1) else : print(*(v+1 for v in res)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var max2 : Function := lambda x : OclAny, y : OclAny in (if (x->compareTo(y)) > 0 then x else y endif) ; skip ; skip ; skip ; if __name__ = '__main__' then ( Sequence{N,A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; res := solve(N, A, B) ; if res <>= null then ( execute (-1)->display() ) else ( execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name v))) + (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name res))))))) ))))))))->display() ) ) else skip; operation solve(N : OclAny, A : OclAny, B : OclAny) : OclAny pre: true post: true activity: if (A + B->compareTo(N + 1)) > 0 then ( return null ) else skip ; if (A * B->compareTo(N)) < 0 then ( return null ) else skip ; var res : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, N) ; var rem : OclAny := A ; var i : int := 0 ; while (i + B + rem - 1->compareTo(N)) < 0 do ( rem := rem - 1 ; var o : int := i + B ; for k : Integer.subrange(0, B-1) do ( res[i + k+1] := o - k - 1) ; i := i + B) ; var p : double := N - i - rem + 1 ; for k : Integer.subrange(0, p-1) do ( res[i + k+1] := i + p - k - 1) ; i := i + p ; rem := rem - 1 ; for k : Integer.subrange(i, N-1) do ( res[k+1] := k) ; return res; operation naive(N : OclAny, A : OclAny, B : OclAny) : OclAny pre: true post: true activity: for p : permutations(Integer.subrange(0, N-1)) do ( var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, N) ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, i-1) do ( if (p[j+1]->compareTo(p[i+1])) < 0 then ( dp[i+1] := max2->apply(dp[i+1], dp[j+1] + 1) ) else skip)) ; var a : OclAny := (dp)->max() ; dp := MatrixLib.elementwiseMult(Sequence{ 1 }, N) ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, i-1) do ( if (p[j+1]->compareTo(p[i+1])) > 0 then ( dp[i+1] := max2->apply(dp[i+1], dp[j+1] + 1) ) else skip)) ; var b : OclAny := (dp)->max() ; if a = A & b = B then ( return p ) else skip) ; return null; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N,A,B=map(int,input().split()) if Ncollect( _x | (OclType["int"])->apply(_x) ) ; if (N->compareTo(A)) < 0 then ( execute (-1)->display() ; return ) else skip ; var x : int := -(-N div A) ; if (B->compareTo(x)) < 0 or ((N - A + 1)->compareTo(B)) < 0 then ( execute (-1)->display() ; return ) else skip ; var lst : Sequence := (Integer.subrange(1, N + 1-1)) ; var seq : Sequence := Sequence{ lst.subrange(1,A) } ; var idx : OclAny := A ; for i : Integer.subrange(0, B - 1-1) do ( var rem : double := B - 1 - i ; var nidx : double := idx - (-(N - idx) div rem) ; execute ((lst.subrange(idx+1, nidx)) : seq) ; idx := nidx) ; var ans : Sequence := Sequence{} ; for s : (seq)->reverse() do ( ans := ans + s) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input_methods=['clipboard','file','key'] using_method=1 input_method=input_methods[using_method] tin=lambda : map(int,input().split()) lin=lambda : list(tin()) mod=1000000007 def main(): n,a,b=tin() if na*b : return-1 if a==1 : print(*list(range(n,0,-1))) return if b==1 : print(*list(range(1,n+1))) return al=list(range(1,n+1)) cc=(n-a)//(b-1) amari=(n-a)%(b-1) ret=al[-a :] st=n-a for bi in range(b-1): na=cc+(1 if biunion(Sequence{'file'}->union(Sequence{ 'key' })) ; var using_method : int := 1 ; var input_method : OclAny := input_methods[using_method+1] ; var tin : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lin : Function := lambda $$ : OclAny in ((tin->apply())) ; var mod : int := 1000000007 ; skip ; var isTest : boolean := false ; skip ; skip ; if __name__ = "__main__" then ( if OclProcess.getEnvironmentProperty("OS") = 'ios' then ( if input_method = input_methods->first() then ( var ic : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.input_clipboard(_i)) ; var input : Function := lambda $$ : OclAny in (ic.__next__()) ) else (if input_method = input_methods[1+1] then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('inputFile.txt')) ) else ( skip ) ) ; isTest := true ) else ( skip ) ; ret := main() ; if not(ret <>= null) then ( execute (ret)->display() ) else skip ) else skip; operation main() : OclAny pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := tin->apply() ; if (n->compareTo(a + b - 1)) < 0 then ( return -1 ) else skip ; if (n->compareTo(a * b)) > 0 then ( return -1 ) else skip ; if a = 1 then ( execute ((argument * (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ))))))))) )))))))))->display() ; return ) else skip ; if b = 1 then ( execute ((argument * (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name n))) + (expr (atom (number (integer 1)))))))))) ))))))))) )))))))))->display() ; return ) else skip ; var al : Sequence := (Integer.subrange(1, n + 1-1)) ; var cc : int := (n - a) div (b - 1) ; var amari : int := (n - a) mod (b - 1) ; var ret : OclAny := al.subrange(-a+1) ; var st : double := n - a ; for bi : Integer.subrange(0, b - 1-1) do ( var na : int := cc + (if (bi->compareTo(amari)) < 0 then 1 else 0 endif) ; st := st - na ; for ai : Integer.subrange(0, na-1) do ( execute ((al[st + ai+1]) : ret))) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ret))))))))->display(); operation pa(v : OclAny) pre: true post: true activity: if isTest then ( execute (v)->display() ) else skip; operation input_clipboard(_position_ : int) : OclAny pre: true post: true activity: var _yieldCount_ : int := 0; skip ; var input_text : OclAny := clipboard.get() ; var input_l : OclAny := input_text.splitlines() ; for l : input_l do ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return l); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def distribute(n,person,min,max,mode="even"): if person==0 and n==0 : return[] elif not min*person<=n<=max*person : return None elif mode=="even" : q,m=divmod(n,person) if m==0 : return[[q,person]] else : return[[q,person-m],[q+1,m]] elif mode=="greedy" : n-=min*person q,m=divmod(n,max-min) if m==0 : return[[min,person-q],[max,q]] else : return[[min,person-1-q],[min+m,1],[max,q]] else : raise ValueError("'mode' must be 'even' or 'greedy'.") import numpy as np N,A,B=map(int,input().split()) Ans=np.arange(N,0,-1,dtype=np.int64) Ans[: A]=np.flipud(Ans[: A]) c=N-A D=distribute(c,B-1,min=1,max=A,mode="even") if D is None : print(-1) exit() idx=A for p,n in D : for _ in range(n): Ans[idx : idx+p]=np.flipud(Ans[idx : idx+p]) idx+=p print(" ".join(str(int(a))for a in Ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{N,A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var Ans : Sequence := ; Ans.subrange(1,A) := ; var c : double := N - A ; var D : OclAny := distribute(c, B - 1, (argument (test (logical_test (comparison (expr (atom (name min)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))), (argument (test (logical_test (comparison (expr (atom (name max)))))) = (test (logical_test (comparison (expr (atom (name A))))))), (argument (test (logical_test (comparison (expr (atom (name mode)))))) = (test (logical_test (comparison (expr (atom "even"))))))) ; if D <>= null then ( execute (-1)->display() ; exit() ) else skip ; var idx : OclAny := A ; for _tuple : D do (var _indx : int := 1; var p : OclAny := _tuple->at(_indx); _indx := _indx + 1; var n : OclAny := _tuple->at(_indx); for _anon : Integer.subrange(0, n-1) do ( Ans.subrange(idx+1, idx + p) := ; idx := idx + p)) ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name Ans)))))))), " "))->display(); operation distribute(n : OclAny, person : OclAny, min : OclAny, max : OclAny, mode : String) : OclAny pre: true post: true activity: if mode->oclIsUndefined() then mode := "even" else skip; if person = 0 & n = 0 then ( return Sequence{} ) else (if not((min * person->compareTo(n)) <= 0 & (n <= max * person)) then ( return null ) else (if mode = "even" then ( var q : OclAny := null; var m : OclAny := null; Sequence{q,m} := Sequence{(n div person), (n mod person)} ; if m = 0 then ( return Sequence{ Sequence{q}->union(Sequence{ person }) } ) else ( return Sequence{Sequence{q}->union(Sequence{ person - m })}->union(Sequence{ Sequence{q + 1}->union(Sequence{ m }) }) ) ) else (if mode = "greedy" then ( n := n - min * person ; var q : OclAny := null; var m : OclAny := null; Sequence{q,m} := Sequence{(n div max - min), (n mod max - min)} ; if m = 0 then ( return Sequence{Sequence{min}->union(Sequence{ person - q })}->union(Sequence{ Sequence{max}->union(Sequence{ q }) }) ) else ( return Sequence{Sequence{min}->union(Sequence{ person - 1 - q })}->union(Sequence{Sequence{min + m}->union(Sequence{ 1 })}->union(Sequence{ Sequence{max}->union(Sequence{ q }) })) ) ) else ( error IncorrectElementException.newIncorrectElementException("'mode' must be 'even' or 'greedy'.") ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,A,B=map(int,input().split()) if A*BN : print(-1) exit() rev=(B>A) A,B=max(A,B),min(A,B) B-=1 M=N ans1=[] ans2=[] while M>0 : if len(ans1)==len(ans2): temp=[i for i in range(M+1-A,M+1)] ans1.append(temp) M=M-A A-=1 else : temp=[i for i in range(M+1-B,M+1)] temp=temp[: :-1] ans2.append(temp) M=M-B B-=1 ans2=ans2[: :-1] res=[] for L in ans1 : res+=L for L in ans2 : res+=L res=[val for val in res if val>0] if rev : res=res[: :-1] print(*res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{N,A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (A * B->compareTo(N)) < 0 or (A + B - 1->compareTo(N)) > 0 then ( execute (-1)->display() ; exit() ) else skip ; var rev : boolean := ((B->compareTo(A)) > 0) ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := Sequence{Set{A, B}->max(),Set{A, B}->min()} ; B := B - 1 ; var M : OclAny := N ; var ans1 : Sequence := Sequence{} ; var ans2 : Sequence := Sequence{} ; while M > 0 do ( if (ans1)->size() = (ans2)->size() then ( var temp : Sequence := Integer.subrange(M + 1 - A, M + 1-1)->select(i | true)->collect(i | (i)) ; execute ((temp) : ans1) ; M := M - A ; A := A - 1 ) else ( temp := Integer.subrange(M + 1 - B, M + 1-1)->select(i | true)->collect(i | (i)) ; temp := temp(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; execute ((temp) : ans2) ; M := M - B ; B := B - 1 )) ; ans2 := ans2(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var res : Sequence := Sequence{} ; for L : ans1 do ( res := res + L) ; for L : ans2 do ( res := res + L) ; res := res->select(val | val > 0)->collect(val | (val)) ; if rev then ( res := res(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ) else skip ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxSum(arr,n,k): if(nunion(Sequence{4}->union(Sequence{2}->union(Sequence{10}->union(Sequence{2}->union(Sequence{3}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 20 })))))))) ; k := 4 ; n := (arr)->size() ; execute (maxSum(arr, n, k))->display(); operation maxSum(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if ((n->compareTo(k)) < 0) then ( execute ("Invalid")->display() ; return -1 ) else skip ; var res : int := 0 ; for i : Integer.subrange(0, k-1) do ( res := res + arr[i+1]) ; var curr_sum : int := res ; for i : Integer.subrange(k, n-1) do ( curr_sum := curr_sum + arr[i+1] - arr[i - k+1] ; res := Set{res, curr_sum}->max()) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np import itertools n,m,x=list(map(int,input().split())) c=np.array([list(map(int,input().split()))for _ in range(n)]) pre=np.arange(n) l=[] rem=[] ans=0 for i in pre+1 : for j in itertools.combinations(pre,i): l.append(list(j)) for i in range(1,m+1): for j,k in enumerate(l): ca=0 for ii in k : ca+=c[ii,i] if ca0 : for j in rem : l.pop(j) rem=[] if len(l)==0 : print(-1) break else : for i in l : ca=0 for j in i : ca+=c[j,0] if ans==0 : ans=ca else : ans=min(ans,ca) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var m : OclAny := null; var x : OclAny := null; Sequence{n,m,x} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : Sequence := (Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))) ; var pre : Sequence := MathLib.numericRange(0, (n), 1) ; var l : Sequence := Sequence{} ; var rem : Sequence := Sequence{} ; var ans : int := 0 ; for i : MatrixLib.elementwiseAdd(pre, 1) do ( for j : itertools.combinations(pre, i) do ( execute (((j)) : l))) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name m))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name j))) , (expr (atom (name k)))) in (testlist (test (logical_test (comparison (expr (atom (name enumerate)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ca)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name ii)))) in (testlist (test (logical_test (comparison (expr (atom (name k))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ca)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ii))))))) , (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name ca)))) < (comparison (expr (atom (name x))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name rem)) (trailer . (name insert) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0)))))))) , (argument (test (logical_test (comparison (expr (atom (name j)))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt pass)))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name rem)))))))) ))))) > (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name rem))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)) (trailer . (name pop) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name j)))))))) ))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name rem)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom [ ])))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)))))))) ))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name l))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ca)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name i))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ca)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j))))))) , (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name ans)))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ca))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans))))))) , (argument (test (logical_test (comparison (expr (atom (name ca)))))))) )))))))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np MAX=100 ; store=[0]*MAX ; graph=np.zeros((MAX,MAX)); d=[0]*MAX ; def is_clique(b): for i in range(1,b): for j in range(i+1,b): if(graph[store[i]][store[j]]==0): return False ; return True ; def print_cli(n): for i in range(1,n): print(store[i],end=" "); print(",",end=" "); def findCliques(i,l,s): for j in range(i+1,n-(s-l)+1): if(d[j]>=s-1): store[l]=j ; if(is_clique(l+1)): if(lunion(Sequence{ 2 })}->union(Sequence{Sequence{2}->union(Sequence{ 3 })}->union(Sequence{Sequence{3}->union(Sequence{ 1 })}->union(Sequence{Sequence{4}->union(Sequence{ 3 })}->union(Sequence{Sequence{4}->union(Sequence{ 5 })}->union(Sequence{ Sequence{5}->union(Sequence{ 3 }) }))))); ; var k : int := 3; ; var size : int := (edges)->size(); ; n := 5; ; for i : Integer.subrange(0, size-1) do ( graph[edges[i+1]->first()+1][edges[i+1][1+1]+1] := 1; ; graph[edges[i+1][1+1]+1][edges[i+1]->first()+1] := 1; ; d[edges[i+1]->first()+1] := d[edges[i+1]->first()+1] + 1; ; d[edges[i+1][1+1]+1] := d[edges[i+1][1+1]+1] + 1;) ; findCliques(0, 1, k); ) else skip; operation is_clique(b : OclAny) pre: true post: true activity: for i : Integer.subrange(1, b-1) do ( for j : Integer.subrange(i + 1, b-1) do ( if (graph[store[i+1]+1][store[j+1]+1] = 0) then ( return false; ) else skip)) ; return true;; operation print_cli(n : OclAny) pre: true post: true activity: for i : Integer.subrange(1, n-1) do ( execute (store[i+1])->display();) ; execute (",")->display();; operation findCliques(i : OclAny, l : OclAny, s : OclAny) pre: true post: true activity: for j : Integer.subrange(i + 1, n - (s - l) + 1-1) do ( if ((d[j+1]->compareTo(s - 1)) >= 0) then ( store[l+1] := j; ; if (is_clique(l + 1)) then ( if ((l->compareTo(s)) < 0) then ( findCliques(j, l + 1, s); ) else ( print_cli(l + 1); ) ) else skip ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): _=int(input()) values=list(map(int,input().split())) c=0 s=set() for v in reversed(values): if v in s : break s.add(v) c+=1 print(len(values)-c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var _anon : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var values : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; var s : Set := Set{}->union(()) ; for v : (values)->reverse() do ( if (s)->includes(v) then ( break ) else skip ; execute ((v) : s) ; c := c + 1) ; execute ((values)->size() - c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) d=dict() count=0 for i,x in enumerate(a): if x in d : count=max(count,d[x]) d[x]=i+1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : Map := (arguments ( )) ; var count : int := 0 ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); if (d)->includes(x) then ( count := Set{count, d[x+1]}->max() ) else skip ; d[x+1] := i + 1) ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def max_cuts(n,a,b,c): if(n==0): return 0 elif(n<0): return-1 result=max(max_cuts(n-a,a,b,c),max_cuts(n-b,a,b,c),max_cuts(n-c,a,b,c)) if(result==-1): return-1 return result+1 def freq(list1): freq_count={} for i in list1 : if(i in freq_count): freq_count[i]+=1 else : freq_count[i]=1 return freq_count t=int(input()) for t1 in range(t): n=int(input()) a=list(map(int,input().split(" "))) uniq=set() for i in a[: :-1]: if(i not in uniq): uniq.add(i) else : break print(n-len(uniq)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for t1 : Integer.subrange(0, t-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var uniq : Set := Set{}->union(()) ; for i : a(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if ((uniq)->excludes(i)) then ( execute ((i) : uniq) ) else ( break )) ; execute (n - (uniq)->size())->display()); operation max_cuts(n : OclAny, a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return 0 ) else (if (n < 0) then ( return -1 ) else skip) ; var result : OclAny := Set{max_cuts(n - a, a, b, c), max_cuts(n - b, a, b, c), max_cuts(n - c, a, b, c)}->max() ; if (result = -1) then ( return -1 ) else skip ; return result + 1; operation freq(list1 : OclAny) : OclAny pre: true post: true activity: var freq_count : OclAny := Set{} ; for i : list1 do ( if ((freq_count)->includes(i)) then ( freq_count[i+1] := freq_count[i+1] + 1 ) else ( freq_count[i+1] := 1 )) ; return freq_count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) nums=list(map(int,input().split())) unique=set() reached_end=True for i,c in enumerate(nums[: :-1]): if c not in unique : unique.add(c) else : print(n-i) reached_end=False break if reached_end : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nums : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var unique : Set := Set{}->union(()) ; var reached_end : boolean := true ; for _tuple : Integer.subrange(1, (nums(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->size())->collect( _indx | Sequence{_indx-1, (nums(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if (unique)->excludes(c) then ( execute ((c) : unique) ) else ( execute (n - i)->display() ; reached_end := false ; break )) ; if reached_end then ( execute (0)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) l1=list(map(int,input().split())) s=0 d1={} for i in l1 : d1[i]=0 high=len(l1)-1 while high>=0 : if d1[l1[high]]==0 : s+=1 d1[l1[high]]=d1[l1[high]]+1 high-=1 else : break print(len(l1)-s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : int := 0 ; var d1 : OclAny := Set{} ; for i : l1 do ( d1[i+1] := 0) ; var high : double := (l1)->size() - 1 ; while high >= 0 do ( if d1[l1[high+1]+1] = 0 then ( s := s + 1 ; d1[l1[high+1]+1] := d1[l1[high+1]+1] + 1 ; high := high - 1 ) else ( break )) ; execute ((l1)->size() - s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100001 phi=[0]*MAX result=[0]*MAX def computeTotient(): phi[1]=1 for i in range(2,MAX): if not phi[i]: phi[i]=i-1 for j in range(i<<1,MAX,i): if not phi[j]: phi[j]=j phi[j]=((phi[j]//i)*(i-1)) def sumOfGcdPairs(): computeTotient() for i in range(MAX): for j in range(2,MAX): if i*j>=MAX : break result[i*j]+=i*phi[j] for i in range(2,MAX): result[i]+=result[i-1] sumOfGcdPairs() N=4 print("Summation of",N,"=",result[N]) N=12 print("Summation of",N,"=",result[N]) N=5000 print("Summation of",N,"=",result[N]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 100001 ; var phi : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX) ; var result : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX) ; skip ; skip ; sumOfGcdPairs() ; var N : int := 4 ; execute ("Summation of")->display() ; N := 12 ; execute ("Summation of")->display() ; N := 5000 ; execute ("Summation of")->display(); operation computeTotient() pre: true post: true activity: phi[1+1] := 1 ; for i : Integer.subrange(2, MAX-1) do ( if not(phi[i+1]) then ( phi[i+1] := i - 1 ; for j : Integer.subrange(i * (2->pow(1)), MAX-1)->select( $x | ($x - i * (2->pow(1))) mod i = 0 ) do ( if not(phi[j+1]) then ( phi[j+1] := j ) else skip ; phi[j+1] := ((phi[j+1] div i) * (i - 1))) ) else skip); operation sumOfGcdPairs() pre: true post: true activity: computeTotient() ; for i : Integer.subrange(0, MAX-1) do ( for j : Integer.subrange(2, MAX-1) do ( if (i * j->compareTo(MAX)) >= 0 then ( break ) else skip ; result[i * j+1] := result[i * j+1] + i * phi[j+1])) ; for i : Integer.subrange(2, MAX-1) do ( result[i+1] := result[i+1] + result[i - 1+1]); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=1000000007 ; def powerLL(x,n): result=1 ; while(n): if(n & 1): result=result*x % MOD ; n=int(n/2); x=x*x % MOD ; return result ; def powerStrings(sa,sb): a=0 ; b=0 ; for i in range(len(sa)): a=(a*10+(ord(sa[i])-ord('0')))% MOD ; for i in range(len(sb)): b=(b*10+(ord(sb[i])-ord('0')))%(MOD-1); return powerLL(a,b); sa="2" ; sb="3" ; print(powerStrings(sa,sb)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : int := 1000000007; ; skip ; skip ; sa := "2"; ; sb := "3"; ; execute (powerStrings(sa, sb))->display();; operation powerLL(x : OclAny, n : OclAny) pre: true post: true activity: var result : int := 1; ; while (n) do ( if (MathLib.bitwiseAnd(n, 1)) then ( result := result * x mod MOD; ) else skip ; n := ("" + ((n / 2)))->toInteger(); ; x := x * x mod MOD;) ; return result;; operation powerStrings(sa : OclAny, sb : OclAny) pre: true post: true activity: var a : int := 0; ; var b : int := 0; ; for i : Integer.subrange(0, (sa)->size()-1) do ( a := (a * 10 + ((sa[i+1])->char2byte() - ('0')->char2byte())) mod MOD;) ; for i : Integer.subrange(0, (sb)->size()-1) do ( b := (b * 10 + ((sb[i+1])->char2byte() - ('0')->char2byte())) mod (MOD - 1);) ; return powerLL(a, b);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- NO_OF_CHARS=256 def canFormPalindrome(st): count=[0]*(NO_OF_CHARS) for i in range(0,len(st)): count[ord(st[i])]=count[ord(st[i])]+1 odd=0 for i in range(0,NO_OF_CHARS): if(count[i]& 1): odd=odd+1 if(odd>1): return False return True if(canFormPalindrome("geeksforgeeks")): print("Yes") else : print("No") if(canFormPalindrome("geeksogeeks")): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var NO_OF_CHARS : int := 256 ; skip ; if (canFormPalindrome("geeksforgeeks")) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ; if (canFormPalindrome("geeksogeeks")) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation canFormPalindrome(st : OclAny) : OclAny pre: true post: true activity: var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (NO_OF_CHARS)) ; for i : Integer.subrange(0, (st)->size()-1) do ( count[(st[i+1])->char2byte()+1] := count[(st[i+1])->char2byte()+1] + 1) ; var odd : int := 0 ; for i : Integer.subrange(0, NO_OF_CHARS-1) do ( if (MathLib.bitwiseAnd(count[i+1], 1)) then ( odd := odd + 1 ) else skip ; if (odd > 1) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) imos=[0]*(10**5+2) for _ in range(n): a,b=map(int,input().split()) imos[a-1]+=1 imos[b]-=1 for i in range(n): imos[i+1]+=imos[i] ans=0 for i in range(n+1): if imos[i]>=i : ans=max(ans,i) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var imos : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ((10)->pow(5) + 2)) ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; imos[a - 1+1] := imos[a - 1+1] + 1 ; imos[b+1] := imos[b+1] - 1) ; for i : Integer.subrange(0, n-1) do ( imos[i + 1+1] := imos[i + 1+1] + imos[i+1]) ; var ans : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( if (imos[i+1]->compareTo(i)) >= 0 then ( ans := Set{ans, i}->max() ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printArray(arr,n): for i in range(n): print(arr[i],end="") def getMin(arr,i,j): minVal=arr[i] i+=1 while(i<=j): minVal=min(minVal,arr[i]) i+=1 return minVal def getMax(arr,i,j): maxVal=arr[i] i+=1 while(i<=j): maxVal=max(maxVal,arr[i]) i+=1 return maxVal def generateArr(arr,n): if(n==0): return if(n==1): print(arr[0],end="") return tmpArr=[0 for i in range(n)] tmpArr[0]=getMax(arr,1,n-1) for i in range(1,n-1): tmpArr[i]=abs(getMax(arr,i+1,n-1)-getMin(arr,0,i-1)) tmpArr[n-1]=getMin(arr,0,n-2) printArray(tmpArr,n) arr=[1,5,2,4,3] n=len(arr) generateArr(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; arr := Sequence{1}->union(Sequence{5}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 3 })))) ; n := (arr)->size() ; generateArr(arr, n); operation printArray(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); operation getMin(arr : OclAny, i : OclAny, j : OclAny) : OclAny pre: true post: true activity: var minVal : OclAny := arr[i+1] ; i := i + 1 ; while ((i->compareTo(j)) <= 0) do ( minVal := Set{minVal, arr[i+1]}->min() ; i := i + 1) ; return minVal; operation getMax(arr : OclAny, i : OclAny, j : OclAny) : OclAny pre: true post: true activity: var maxVal : OclAny := arr[i+1] ; i := i + 1 ; while ((i->compareTo(j)) <= 0) do ( maxVal := Set{maxVal, arr[i+1]}->max() ; i := i + 1) ; return maxVal; operation generateArr(arr : OclAny, n : OclAny) pre: true post: true activity: if (n = 0) then ( return ) else skip ; if (n = 1) then ( execute (arr->first())->display() ; return ) else skip ; var tmpArr : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; tmpArr->first() := getMax(arr, 1, n - 1) ; for i : Integer.subrange(1, n - 1-1) do ( tmpArr[i+1] := (getMax(arr, i + 1, n - 1) - getMin(arr, 0, i - 1))->abs()) ; tmpArr[n - 1+1] := getMin(arr, 0, n - 2) ; printArray(tmpArr, n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] while True : n=I() aa=[LI()for _ in range(n)] t=[0]*100003 for a,b in aa : t[a]+=1 t[b+1]-=1 s=0 r=0 for i in range(100002): s+=t[i] if i-1<=s : r=i-1 rr.append(r) break return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var n : OclAny := I() ; var aa : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI())) ; var t : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100003) ; for _tuple : aa do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); t[a+1] := t[a+1] + 1 ; t[b + 1+1] := t[b + 1+1] - 1) ; s := 0 ; var r : int := 0 ; for i : Integer.subrange(0, 100002-1) do ( s := s + t[i+1] ; if (i - 1->compareTo(s)) <= 0 then ( r := i - 1 ) else skip) ; execute ((r) : rr) ; break) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- teams={'h' : input(),'a' : input()}; n=int(input()) a={'h' :[],'a' :[]} for i in range(101): a['h'].append(0); a['a'].append(0); for i in range(n): [time,team,num,color]=input().split(); num=int(num) if a[team][num]>=2 : continue if color=='r' : a[team][num]=2 else : a[team][num]+=1 if a[team][num]==2 : print(teams[team]+' '+str(num)+' '+time) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var teams : Map := Map{ 'h' |-> (OclFile["System.in"]).readLine() }->union(Map{ 'a' |-> (OclFile["System.in"]).readLine() }); ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Map := Map{ 'h' |-> Sequence{} }->union(Map{ 'a' |-> Sequence{} }) ; for i : Integer.subrange(0, 101-1) do ((expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'h'))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))));(expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom 'a'))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))));) ; for i : Integer.subrange(0, n-1) do ( ; Sequence{time}->union(Sequence{team}->union(Sequence{num}->union(Sequence{ color }))) := input().split(); var num : int := ("" + ((num)))->toInteger() ; if a[team+1][num+1] >= 2 then ( continue ) else skip ; if color = 'r' then ( a[team+1][num+1] := 2 ) else ( a[team+1][num+1] := a[team+1][num+1] + 1 ) ; if a[team+1][num+1] = 2 then ( execute (teams[team+1] + ' ' + ("" + ((num))) + ' ' + time)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) friendlist=[0 for i in range(N+2)] ab=[[int(i)for i in input().split(" ")]for j in range(N)] a=[ab[i][0]for i in range(N)] b=[ab[i][1]for i in range(N)] a.sort() b.sort() for i in range(1,N): for j in range(a[i-1],min(a[i],N+2)): friendlist[j]+=i for i in range(a[N-1],N+2): friendlist[i]+=N for i in range(1,N): for j in range(b[i-1]+1,min(b[i]+1,N+2)): friendlist[j]-=i for i in range(b[N-1]+1,N+2): friendlist[i]-=N k=N+1 i=0 while k>=0 : if friendlist[k]>=k-1 : i=k-1 break k-=1 print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var friendlist : Sequence := Integer.subrange(0, N + 2-1)->select(i | true)->collect(i | (0)) ; var ab : Sequence := Integer.subrange(0, N-1)->select(j | true)->collect(j | (input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())))) ; var a : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (ab[i+1]->first())) ; var b : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (ab[i+1][1+1])) ; a := a->sort() ; b := b->sort() ; for i : Integer.subrange(1, N-1) do ( for j : Integer.subrange(a[i - 1+1], Set{a[i+1], N + 2}->min()-1) do ( friendlist[j+1] := friendlist[j+1] + i)) ; for i : Integer.subrange(a[N - 1+1], N + 2-1) do ( friendlist[i+1] := friendlist[i+1] + N) ; for i : Integer.subrange(1, N-1) do ( for j : Integer.subrange(b[i - 1+1] + 1, Set{b[i+1] + 1, N + 2}->min()-1) do ( friendlist[j+1] := friendlist[j+1] - i)) ; for i : Integer.subrange(b[N - 1+1] + 1, N + 2-1) do ( friendlist[i+1] := friendlist[i+1] - N) ; var k : int := N + 1 ; var i : int := 0 ; while k >= 0 do ( if (friendlist[k+1]->compareTo(k - 1)) >= 0 then ( i := k - 1 ; break ) else skip ; k := k - 1) ; execute (i)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque import sys,heapq,bisect,math,itertools,string,queue,copy,time sys.setrecursionlimit(10**8) INF=float('inf') mod=10**9+7 eps=10**-7 def inp(): return int(input()) def inpl(): return list(map(int,input().split())) def inpl_str(): return list(input().split()) N=inp() MAX=100005 imos=[0]*MAX for _ in range(N): a,b=inpl() imos[a]+=1 imos[b+1]-=1 for i in range(1,MAX): imos[i]+=imos[i-1] ans=0 for i in range(MAX): if imos[i]>=i-1 : ans=max(ans,i-1) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var eps : double := (10)->pow(-7) ; skip ; skip ; skip ; var N : OclAny := inp() ; var MAX : int := 100005 ; var imos : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX) ; for _anon : Integer.subrange(0, N-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := inpl() ; imos[a+1] := imos[a+1] + 1 ; imos[b + 1+1] := imos[b + 1+1] - 1) ; for i : Integer.subrange(1, MAX-1) do ( imos[i+1] := imos[i+1] + imos[i - 1+1]) ; var ans : int := 0 ; for i : Integer.subrange(0, MAX-1) do ( if (imos[i+1]->compareTo(i - 1)) >= 0 then ( ans := Set{ans, i - 1}->max() ) else skip) ; execute (ans)->display(); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inpl_str() : OclAny pre: true post: true activity: return (input().split()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) l=[list(map(int,input().split()))for _ in range(N)] diff=[0]*100002 for k in l : diff[k[0]-1]+=1 diff[k[1]]-=1 hist=[0,0] for i in range(2,N+2): hist.append(hist[-1]+diff[i-1]) print(max([0]+[y-1 for(x,y)in zip(hist,range(N+2))if x+1>=y])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var diff : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100002) ; for k : l do ( diff[k->first() - 1+1] := diff[k->first() - 1+1] + 1 ; diff[k[1+1]+1] := diff[k[1+1]+1] - 1) ; var hist : Sequence := Sequence{0}->union(Sequence{ 0 }) ; for i : Integer.subrange(2, N + 2-1) do ( execute ((hist->last() + diff[i - 1+1]) : hist)) ; execute ((Sequence{ 0 }->union(Integer.subrange(1, hist->size())->collect( _indx | Sequence{hist->at(_indx), Integer.subrange(0, N + 2-1)->at(_indx)} )->select(Sequence{x, y} | (x + 1->compareTo(y)) >= 0)->collect(Sequence{x, y} | (y - 1))))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) k=2 x=1.1 while((x<1)or(x % 1!=0)): x=-n/(1-2**k) k+=1 print(int(x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := 2 ; var x : double := 1.1 ; while ((x < 1) or (x mod 1 /= 0)) do ( x := -n / (1 - (2)->pow(k)) ; k := k + 1) ; execute (("" + ((x)))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) a=[] for i in range(t): a.append(int(input())) b=[] for j in range(2,500): b.append(2**j-1) for i in range(t): summ=a[i] for elem in b : if summ % elem==0 : print(summ//elem) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : a)) ; var b : Sequence := Sequence{} ; for j : Integer.subrange(2, 500-1) do ( execute (((2)->pow(j) - 1) : b)) ; for i : Integer.subrange(0, t-1) do ( var summ : OclAny := a[i+1] ; for elem : b do ( if summ mod elem = 0 then ( execute (summ div elem)->display() ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for test in range(t): n=int(input()) for k in range(2,n): if n/(2**k-1)==int(n/(2**k-1)): print(int(n/(2**k-1))) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for test : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for k : Integer.subrange(2, n-1) do ( if n / ((2)->pow(k) - 1) = ("" + ((n / ((2)->pow(k) - 1))))->toInteger() then ( execute (("" + ((n / ((2)->pow(k) - 1))))->toInteger())->display() ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) temp=3 while(n % temp>0): temp=temp*2+1 print(int(n/temp)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var temp : int := 3 ; while (n mod temp > 0) do ( temp := temp * 2 + 1) ; execute (("" + ((n / temp)))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairs(arr,k): arr.sort() pair=0 index=0 while(indexunion(Sequence{4}->union(Sequence{3}->union(Sequence{7}->union(Sequence{ 5 })))) ; k := 2 ; var count : OclAny := countPairs(arr, k) ; execute (count)->display() ) else skip; operation countPairs(arr : OclAny, k : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var pair : int := 0 ; var index : int := 0 ; while ((index->compareTo((arr)->size() - 1)) < 0) do ( if (arr[index + 1+1] - arr[index+1]->compareTo(k)) <= 0 then ( pair := pair + 1 ; index := index + 2 ) else ( index := index + 1 )) ; return pair; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math for i in range(int(input())): n=int(input()) val=list(map(int,input().split())) val.sort() cnt=1 for i in range(n): if val[i]<=i+1 : cnt=i+2 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var val : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; val := val->sort() ; var cnt : int := 1 ; for i : Integer.subrange(0, n-1) do ( if (val[i+1]->compareTo(i + 1)) <= 0 then ( cnt := i + 2 ) else skip) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import itertools f=sys.stdin g=itertools.accumulate n=int(f.readline()) p=list(map(int,f.readline().split())) c=f.readline() v=[-x if y=='B' else x for x,y in zip(p,c)] s=sum(p[i]if c[i]=='B' else 0 for i in range(n)) print(s+max(0,max(g(v)),max(g(v[: :-1])))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var f : OclFile := OclFile["System.in"] ; var g : OclAny := itertools.accumulate ; var n : int := ("" + ((f.readLine())))->toInteger() ; var p : Sequence := ((f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : String := f.readLine() ; var v : Sequence := Integer.subrange(1, p->size())->collect( _indx | Sequence{p->at(_indx), c->at(_indx)} )->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (if y = 'B' then -x else x endif)) ; var s : OclAny := ((argument (test (logical_test (comparison (expr (atom (name p)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))) if (logical_test (comparison (comparison (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom 'B'))))) else (test (logical_test (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->sum() ; execute (s + Set{0, (g(v))->max(), (g(v(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))))->max()}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import string letter=string.ascii_lowercase for _ in range(int(input())): s=input() if len(s)% 2==0 : c=0 for i in s : c+=letter.index(i)+1 print(f'Alice{c}') elif len(s)==1 : print('Bob',letter.index(s)+1) else : a=letter.index(s[0])+1 b=letter.index(s[-1])+1 if a>=b : c=0 for i in s[0 :-1]: c+=letter.index(i)+1 print(f'Alice{abs(c-b)}') else : c=0 for i in s[1 : :]: c+=letter.index(i)+1 print(f'Alice{abs(c-a)}') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var letter : OclAny := string.ascii_lowercase ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if (s)->size() mod 2 = 0 then ( var c : int := 0 ; for i : s->characters() do ( c := c + letter->indexOf(i) - 1 + 1) ; execute (StringLib.formattedString('Alice{c}'))->display() ) else (if (s)->size() = 1 then ( execute ('Bob')->display() ) else ( var a : int := letter->indexOf(s->first()) - 1 + 1 ; var b : int := letter->indexOf(s->last()) - 1 + 1 ; if (a->compareTo(b)) >= 0 then ( c := 0 ; for i : s.subrange(0+1, -1) do ( c := c + letter->indexOf(i) - 1 + 1) ; execute (StringLib.formattedString('Alice{abs(c-b)}'))->display() ) else ( c := 0 ; for i : s(subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) : (sliceop :)) do ( c := c + letter->indexOf(i) - 1 + 1) ; execute (StringLib.formattedString('Alice{abs(c-a)}'))->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inp=int(input()) for i in range(inp): Alice,Bob=0,0 string=input() if len(string)==1 : Bob+=(ord(string)-96) else : for s in string : Alice+=(ord(s)-96) if len(string)>1 and len(string)% 2!=0 : first=(ord(string[0])-96) last=(ord(string[len(string)-1])-96) if firstBob : print("Alice",(Alice-Bob)) else : print("Bob",(Bob-Alice)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inp : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, inp-1) do ( var Alice : OclAny := null; var Bob : OclAny := null; Sequence{Alice,Bob} := Sequence{0,0} ; var string : String := (OclFile["System.in"]).readLine() ; if (string)->size() = 1 then ( Bob := Bob + ((string)->char2byte() - 96) ) else ( for s : string->characters() do ( Alice := Alice + ((s)->char2byte() - 96)) ) ; if (string)->size() > 1 & (string)->size() mod 2 /= 0 then ( var first : double := ((string->first())->char2byte() - 96) ; var last : double := ((string[(string)->size() - 1+1])->char2byte() - 96) ; if (first->compareTo(last)) < 0 then ( Alice := Alice - first ; Bob := Bob + first ) else ( Alice := Alice - last ; Bob := Bob + last ) ) else skip ; if (Alice->compareTo(Bob)) > 0 then ( execute ("Alice")->display() ) else ( execute ("Bob")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- homeTeam=input() awayTeam=input() n=int(input()) result=[] awayMap={} homeMap={} for _ in range(n): a,b,c,d=map(str,input().split()) if b=='a' : if c in awayMap : if awayMap[c][0]>=2 : pass else : if d=='y' : awayMap[c][0]+=1 else : awayMap[c][0]+=2 awayMap[c][1]=a else : if(d=='r'): awayMap[c]=[2,a] else : awayMap[c]=[1,a] else : if c in homeMap : if homeMap[c][0]>=2 : pass else : if d=='y' : homeMap[c][0]+=1 else : homeMap[c][0]+=2 homeMap[c][1]=a else : if(d=='r'): homeMap[c]=[2,a] else : homeMap[c]=[1,a] for i in homeMap : if homeMap[i][0]>=2 : result.append([int(homeMap[i][1]),homeTeam,i]) for i in awayMap : if awayMap[i][0]>=2 : result.append([int(awayMap[i][1]),awayTeam,i]) result.sort() for i in result : print(i[1],i[2],i[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var homeTeam : String := (OclFile["System.in"]).readLine() ; var awayTeam : String := (OclFile["System.in"]).readLine() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var result : Sequence := Sequence{} ; var awayMap : OclAny := Set{} ; var homeMap : OclAny := Set{} ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; if b = 'a' then ( if (awayMap)->includes(c) then ( if awayMap[c+1]->first() >= 2 then ( skip ) else ( if d = 'y' then ( awayMap[c+1]->first() := awayMap[c+1]->first() + 1 ) else ( awayMap[c+1]->first() := awayMap[c+1]->first() + 2 ) ; awayMap[c+1][1+1] := a ) ) else ( if (d = 'r') then ( awayMap[c+1] := Sequence{2}->union(Sequence{ a }) ) else ( awayMap[c+1] := Sequence{1}->union(Sequence{ a }) ) ) ) else ( if (homeMap)->includes(c) then ( if homeMap[c+1]->first() >= 2 then ( skip ) else ( if d = 'y' then ( homeMap[c+1]->first() := homeMap[c+1]->first() + 1 ) else ( homeMap[c+1]->first() := homeMap[c+1]->first() + 2 ) ; homeMap[c+1][1+1] := a ) ) else ( if (d = 'r') then ( homeMap[c+1] := Sequence{2}->union(Sequence{ a }) ) else ( homeMap[c+1] := Sequence{1}->union(Sequence{ a }) ) ) )) ; for i : homeMap do ( if homeMap[i+1]->first() >= 2 then ( execute ((Sequence{("" + ((homeMap[i+1][1+1])))->toInteger()}->union(Sequence{homeTeam}->union(Sequence{ i }))) : result) ) else skip) ; for i : awayMap do ( if awayMap[i+1]->first() >= 2 then ( execute ((Sequence{("" + ((awayMap[i+1][1+1])))->toInteger()}->union(Sequence{awayTeam}->union(Sequence{ i }))) : result) ) else skip) ; result := result->sort() ; for i : result do ( execute (i[1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p=int(input()) for i in range(p): Alice,Bob=0,0 string=input() if len(string)==1 : Bob+=(ord(string)-96) else : for s in string : Alice+=(ord(s)-96) if len(string)>1 and len(string)% 2!=0 : first=(ord(string[0])-96) last=(ord(string[len(string)-1])-96) if firstBob : print("Alice",(Alice-Bob)) else : print("Bob",(Bob-Alice)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, p-1) do ( var Alice : OclAny := null; var Bob : OclAny := null; Sequence{Alice,Bob} := Sequence{0,0} ; var string : String := (OclFile["System.in"]).readLine() ; if (string)->size() = 1 then ( Bob := Bob + ((string)->char2byte() - 96) ) else ( for s : string->characters() do ( Alice := Alice + ((s)->char2byte() - 96)) ) ; if (string)->size() > 1 & (string)->size() mod 2 /= 0 then ( var first : double := ((string->first())->char2byte() - 96) ; var last : double := ((string[(string)->size() - 1+1])->char2byte() - 96) ; if (first->compareTo(last)) < 0 then ( Alice := Alice - first ; Bob := Bob + first ) else ( Alice := Alice - last ; Bob := Bob + last ) ) else skip ; if (Alice->compareTo(Bob)) > 0 then ( execute ("Alice")->display() ) else ( execute ("Bob")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=lambda : stdin.readline()[:-1] def main(t): s=input() ans=0 for i in range(len(s)): ans+=ord(s[i])-96 if len(s)% 2==1 : ans-=2*min(ord(s[0])-96,ord(s[-1])-96) if ans>0 : print("Alice",ans) else : print("Bob",-ans) T=int(input()) t=1 while t<=T : main(t) t+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (stdin.readLine()->front()) ; skip ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; t := 1 ; while (t->compareTo(T)) <= 0 do ( main(t) ; t := t + 1); operation main(t : OclAny) pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var ans : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( ans := ans + (s[i+1])->char2byte() - 96) ; if (s)->size() mod 2 = 1 then ( ans := ans - 2 * Set{(s->first())->char2byte() - 96, (s->last())->char2byte() - 96}->min() ) else skip ; if ans > 0 then ( execute ("Alice")->display() ) else ( execute ("Bob")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): s=input() sum=0 for i in s : sum+=(ord(i)-96) if len(s)% 2==0 : print('Alice',sum) else : if len(s)==1 : print('Bob',sum) else : k=min(ord(s[0])-96,ord(s[-1])-96) sum-=k if sum>k : print('Alice',(sum-k)) else : print('Bob',(k-sum)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var sum : int := 0 ; for i : s->characters() do ( sum := sum + ((i)->char2byte() - 96)) ; if (s)->size() mod 2 = 0 then ( execute ('Alice')->display() ) else ( if (s)->size() = 1 then ( execute ('Bob')->display() ) else ( var k : OclAny := Set{(s->first())->char2byte() - 96, (s->last())->char2byte() - 96}->min() ; sum := sum - k ; if (sum->compareTo(k)) > 0 then ( execute ('Alice')->display() ) else ( execute ('Bob')->display() ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxSubarrayXOR(arr,n): ans=-2147483648 for i in range(n): curr_xor=0 for j in range(i,n): curr_xor=curr_xor ^ arr[j] ans=max(ans,curr_xor) return ans arr=[8,1,2,12] n=len(arr) print("Max subarray XOR is ",maxSubarrayXOR(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{8}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 12 }))) ; n := (arr)->size() ; execute ("Max subarray XOR is ")->display(); operation maxSubarrayXOR(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := -2147483648 ; for i : Integer.subrange(0, n-1) do ( var curr_xor : int := 0 ; for j : Integer.subrange(i, n-1) do ( curr_xor := MathLib.bitwiseXor(curr_xor, arr[j+1]) ; ans := Set{ans, curr_xor}->max())) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import heapq def minProduct(arr,n,k): heapq.heapify(arr) count=0 ans=1 while(arr)and countunion(Sequence{76}->union(Sequence{544}->union(Sequence{123}->union(Sequence{154}->union(Sequence{ 675 }))))) ; k := 2 ; n := (arr)->size() ; execute ("Minimum product is")->display(); operation minProduct(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: heapq.heapify(arr) ; var count : int := 0 ; var ans : int := 1 ; while (arr) & (count->compareTo(k)) < 0 do ( var x : OclAny := heapq.heappop(arr) ; ans := ans * x ; count := count + 1) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) s="" for i in range(n): s+=input() s1=set(s) for i in s1 : if s.count(i)% n!=0 : print("NO") break else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := "" ; for i : Integer.subrange(0, n-1) do ( s := s + (OclFile["System.in"]).readLine()) ; var s1 : Set := Set{}->union((s)) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name s1))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name s)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) % (expr (atom (name n))))) != (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) w={} for _ in range(n): a=input() for i in a : if i in w : w[i]+=1 else : w[i]=1 for i in w : if w[i]% n!=0 : return "NO" return "YES" t=int(input()) ans=[] while t : ans.append(str(solve())) t-=1 print("\n".join(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := Sequence{} ; while t do ( execute ((("" + ((solve())))) : ans) ; t := t - 1) ; execute (StringLib.sumStringsWithSeparator((ans), "\n"))->display(); operation solve() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : OclAny := Set{} ; for _anon : Integer.subrange(0, n-1) do ( var a : String := (OclFile["System.in"]).readLine() ; for i : a->characters() do ( if (w)->includes(i) then ( w[i+1] := w[i+1] + 1 ) else ( w[i+1] := 1 ))) ; for i : w do ( if w[i+1] mod n /= 0 then ( return "NO" ) else skip) ; return "YES"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) safe=list() for i in range(n-1): for j in range(i+1,n): pro=a[i]*a[j] digit=[pro %(10**k)//(10**(k-1))for k in range(1,10)] while digit[-1]==0 : digit=digit[:-1] if len(digit)==1 : safe.append(pro) continue flag=True for k in range(len(digit)-1): if digit[k+1]-digit[k]!=-1 : flag=False break if flag : safe.append(pro) if safe : safe.sort() print(safe[-1]) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var safe : Sequence := () ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(i + 1, n-1) do ( var pro : double := a[i+1] * a[j+1] ; var digit : Sequence := Integer.subrange(1, 10-1)->select(k | true)->collect(k | (pro mod ((10)->pow(k)) div ((10)->pow((k - 1))))) ; while digit->last() = 0 do ( digit := digit->front()) ; if (digit)->size() = 1 then ( execute ((pro) : safe) ; continue ) else skip ; var flag : boolean := true ; for k : Integer.subrange(0, (digit)->size() - 1-1) do ( if digit[k + 1+1] - digit[k+1] /= -1 then ( flag := false ; break ) else skip) ; if flag then ( execute ((pro) : safe) ) else skip)) ; if safe then ( safe := safe->sort() ; execute (safe->last())->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) st="" a=set() flag=0 for _ in range(n): s=input() st+=s for x in st : a.add(x) for y in a : if(st.count(y))% n!=0 : flag=1 if flag==1 : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var st : String := "" ; var a : Set := Set{}->union(()) ; var flag : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; st := st + s) ; for x : st->characters() do ( execute ((x) : a)) ; for y : a do ( if (st->count(y)) mod n /= 0 then ( flag := 1 ) else skip) ; if flag = 1 then ( execute ("NO")->display() ) else ( execute ("YES")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input exec(int(I())*"n=int(I());s='';exec('s+=I();'*n);print('YNEOS'[any(s.count(x)%n for x in s)::2]);") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name I)) (trailer (arguments ( ))))))))) )))) * (expr (atom "n=int(I());s='';exec('s+=I();'*n);print('YNEOS'[any(s.count(x)%n for x in s)::2]);"))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) d={} for __ in range(n): s=input() for x in s : if x not in d : d[x]=0 d[x]+=1 is_possible=True for k in d : if d[k]% n : is_possible=False break if is_possible : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : OclAny := Set{} ; for __ : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; for x : s->characters() do ( if (d)->excludes(x) then ( d[x+1] := 0 ) else skip ; d[x+1] := d[x+1] + 1)) ; var is_possible : boolean := true ; for k : d do ( if d[k+1] mod n then ( is_possible := false ; break ) else skip) ; if is_possible then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input(); b=input() ta={}; tb={} for x in range(int(input())): m,t,n,c=input().split() if t=='a' and((True if ta[n]<2 else False)if n in ta else True): if n in ta : ta[n]+=1 if c=='y' else 2 else : ta[n]=1 if c=='y' else 2 if ta[n]>1 : print(b,n,m) elif t=='h' and((True if tb[n]<2 else False)if n in tb else True): if n in tb : tb[n]+=1 if c=='y' else 2 else : tb[n]=1 if c=='y' else 2 if tb[n]>1 : print(a,n,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine(); var b : String := (OclFile["System.in"]).readLine() ; var ta : OclAny := Set{}; var tb : OclAny := Set{} ; for x : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var m : OclAny := null; var t : OclAny := null; var n : OclAny := null; var c : OclAny := null; Sequence{m,t,n,c} := input().split() ; if t = 'a' & (if (ta)->includes(n) then (if ta[n+1] < 2 then true else false endif) else true endif) then ( if (ta)->includes(n) then ( ta[n+1] := ta[n+1] + if c = 'y' then 1 else 2 endif ) else ( ta[n+1] := if c = 'y' then 1 else 2 endif ) ; if ta[n+1] > 1 then ( execute (b)->display() ) else skip ) else (if t = 'h' & (if (tb)->includes(n) then (if tb[n+1] < 2 then true else false endif) else true endif) then ( if (tb)->includes(n) then ( tb[n+1] := tb[n+1] + if c = 'y' then 1 else 2 endif ) else ( tb[n+1] := if c = 'y' then 1 else 2 endif ) ; if tb[n+1] > 1 then ( execute (a)->display() ) else skip ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) graph=[] for rows in range(n): graph.append(input()) final_rows=[] final_columns=[] for row_index in range(n): for char_index in range(m): if graph[row_index][char_index]=="*" : final_rows.append(row_index) final_columns.append(char_index) a=min(final_rows) b=max(final_rows) c=min(final_columns) d=max(final_columns) for i in range(a,b+1): print(graph[i][c : d+1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var graph : Sequence := Sequence{} ; for rows : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : graph)) ; var final_rows : Sequence := Sequence{} ; var final_columns : Sequence := Sequence{} ; for row_index : Integer.subrange(0, n-1) do ( for char_index : Integer.subrange(0, m-1) do ( if graph[row_index+1][char_index+1] = "*" then ( execute ((row_index) : final_rows) ; execute ((char_index) : final_columns) ) else skip)) ; var a : OclAny := (final_rows)->min() ; var b : OclAny := (final_rows)->max() ; var c : OclAny := (final_columns)->min() ; var d : OclAny := (final_columns)->max() ; for i : Integer.subrange(a, b + 1-1) do ( execute (graph[i+1].subrange(c+1, d + 1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=[int(i)for i in input().split()] a=[input()for i in range(s[0])] for _ in range(4): a.reverse() d,b=[],0 for c in zip(*a): if '*' in c : b=1 if b : d+=[c] a=d for i in a : print(''.join(i)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a : Sequence := Integer.subrange(0, s->first()-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; for _anon : Integer.subrange(0, 4-1) do ( a := a->reverse() ; var d : OclAny := null; var b : OclAny := null; Sequence{d,b} := Sequence{Sequence{},0} ; for c : Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name a)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name a)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name a)))))))`third->at(_indx)} ) do ( if (c)->includes('*') then ( var b : int := 1 ) else skip ; if b then ( d := d + Sequence{ c } ) else skip) ; a := d) ; for i : a do ( execute (StringLib.sumStringsWithSeparator((i), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math temp=input().split() r,c=int(temp[0]),int(temp[1]) m=0 together=[] right=0 sile=[] l=0 flag=0 for i in range(r): temp=input() s=temp.count("*") if flag==0 and s>0 : flag=1 l=i sile.append([temp,s]) right=len(sile)-1 while right>=0 : if sile[right][1]!=0 : break right-=1 low,high=math.inf,0 for i in range(l,right+1): for j in range(len(sile[i][0])): if sile[i][0][j]=="*" : low=min(j,low) high=max(high,j) for i in range(l,right+1): print(sile[i][0][low : high+1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var temp : OclAny := input().split() ; var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := Sequence{("" + ((temp->first())))->toInteger(),("" + ((temp[1+1])))->toInteger()} ; var m : int := 0 ; var together : Sequence := Sequence{} ; var right : int := 0 ; var sile : Sequence := Sequence{} ; var l : int := 0 ; var flag : int := 0 ; for i : Integer.subrange(0, r-1) do ( temp := (OclFile["System.in"]).readLine() ; var s : int := temp->count("*") ; if flag = 0 & s > 0 then ( flag := 1 ; l := i ) else skip ; execute ((Sequence{temp}->union(Sequence{ s })) : sile)) ; right := (sile)->size() - 1 ; while right >= 0 do ( if sile[right+1][1+1] /= 0 then ( break ) else skip ; right := right - 1) ; var low : OclAny := null; var high : OclAny := null; Sequence{low,high} := Sequence{,0} ; for i : Integer.subrange(l, right + 1-1) do ( for j : Integer.subrange(0, (sile[i+1]->first())->size()-1) do ( if sile[i+1]->first()[j+1] = "*" then ( var low : OclAny := Set{j, low}->min() ; var high : OclAny := Set{high, j}->max() ) else skip)) ; for i : Integer.subrange(l, right + 1-1) do ( execute (sile[i+1]->first().subrange(low+1, high + 1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,l,nl=[int(i)for i in input().split()],[],[] u=d=lf=r=0 for i in range(n[0]): l.extend([i for i in input().split()]) vl,dl=["".join([l[j][i]for j in range(n[0])])for i in range(n[1])],l.copy() for i in l : if "*" in i : u=l.index(i) break l.reverse() for i in l : if "*" in i : d=l.index(i) break for i in vl : if "*" in i : lf=vl.index(i) break vl.reverse() for i in vl : if "*" in i : r=vl.index(i) break d,r=n[0]-d-1,n[1]-r-1 for i in range(u,d+1): nl.append(dl[i][lf : r+1]) print("\n".join(nl)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; var nl : OclAny := null; Sequence{n,l,nl} := Sequence{input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())),Sequence{},Sequence{}} ; u := u(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name d)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name lf)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name r)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for i : Integer.subrange(0, n->first()-1) do ( l := l->union(input().split()->select(i | true)->collect(i | (i)))) ; var vl : OclAny := null; var dl : OclAny := null; Sequence{vl,dl} := Sequence{Integer.subrange(0, n[1+1]-1)->select(i | true)->collect(i | (StringLib.sumStringsWithSeparator((Integer.subrange(0, n->first()-1)->select(j | true)->collect(j | (l[j+1][i+1]))), ""))),l->copy()} ; for i : l do ( if (i)->includes("*") then ( var u : int := l->indexOf(i) - 1 ; break ) else skip) ; l := l->reverse() ; for i : l do ( if (i)->includes("*") then ( var d : int := l->indexOf(i) - 1 ; break ) else skip) ; for i : vl do ( if (i)->includes("*") then ( var lf : int := vl->indexOf(i) - 1 ; break ) else skip) ; vl := vl->reverse() ; for i : vl do ( if (i)->includes("*") then ( var r : int := vl->indexOf(i) - 1 ; break ) else skip) ; Sequence{d,r} := Sequence{n->first() - d - 1,n[1+1] - r - 1} ; for i : Integer.subrange(u, d + 1-1) do ( execute ((dl[i+1].subrange(lf+1, r + 1)) : nl)) ; execute (StringLib.sumStringsWithSeparator((nl), "\n"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) b=[] d=[] q=[] p=[] w=[] po=[] for i in range(n): a=input() b.append(a) for j in range(n): for k in range(m): if b[j][k]=='*' : d+=[k] break t=min(d) for l in range(n): for e in range(m): if b[l][: :-1][e]=='*' : q+=[m-e] break x=max(q) for u in range(n): p+=[b[u][t : x]] for qw in range(n): if '*' in b[qw]: w+=[qw] for qwe in range(min(w),max(w)+1): po+=[p[qwe]] for poi in po : print(poi) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var b : Sequence := Sequence{} ; var d : Sequence := Sequence{} ; var q : Sequence := Sequence{} ; var p : Sequence := Sequence{} ; var w : Sequence := Sequence{} ; var po : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var a : String := (OclFile["System.in"]).readLine() ; execute ((a) : b)) ; for j : Integer.subrange(0, n-1) do ( for k : Integer.subrange(0, m-1) do ( if b[j+1][k+1] = '*' then ( d := d + Sequence{ k } ; break ) else skip)) ; var t : OclAny := (d)->min() ; for l : Integer.subrange(0, n-1) do ( for e : Integer.subrange(0, m-1) do ( if b[l+1](subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))[e+1] = '*' then ( q := q + Sequence{ m - e } ; break ) else skip)) ; var x : OclAny := (q)->max() ; for u : Integer.subrange(0, n-1) do ( p := p + Sequence{ b[u+1].subrange(t+1, x) }) ; for qw : Integer.subrange(0, n-1) do ( if (b[qw+1])->includes('*') then ( w := w + Sequence{ qw } ) else skip) ; for qwe : Integer.subrange((w)->min(), (w)->max() + 1-1) do ( po := po + Sequence{ p[qwe+1] }) ; for poi : po do ( execute (poi)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): x=int(input()) s=list(map(int,input())) ans=len(s) l=1 while l<=x : c=s[l-1] ans=((ans-l)*(c)+l)%(10**9+7) r=len(s) for i in range(c-1): if len(s)toInteger() ; for i : Integer.subrange(0, t-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := (((OclFile["System.in"]).readLine())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := (s)->size() ; var l : int := 1 ; while (l->compareTo(x)) <= 0 do ( var c : OclAny := s[l - 1+1] ; ans := ((ans - l) * (c) + l) mod ((10)->pow(9) + 7) ; var r : int := (s)->size() ; for i : Integer.subrange(0, c - 1-1) do ( if ((s)->size()->compareTo(x)) < 0 then ( s := s + s.subrange(l+1, r) ) else ( break )) ; l := l + 1) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) p=list(map(int,input().split())) s=list(input().rstrip()) m=0 for i in range(n): if s[i]=="B" : m+=p[i] ans=m c=m for i in range(n): if s[i]=="A" : c+=p[i] else : c-=p[i] ans=max(ans,c) c=m for i in range(n-1,-1,-1): if s[i]=="A" : c+=p[i] else : c-=p[i] ans=max(ans,c) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Sequence := (input().rstrip()) ; var m : int := 0 ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = "B" then ( m := m + p[i+1] ) else skip) ; var ans : int := m ; var c : int := m ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = "A" then ( c := c + p[i+1] ) else ( c := c - p[i+1] ) ; ans := Set{ans, c}->max()) ; c := m ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if s[i+1] = "A" then ( c := c + p[i+1] ) else ( c := c - p[i+1] ) ; ans := Set{ans, c}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=10**9+7 for nt in range(int(input())): x=int(input()) s=input() n=len(s) ans=n for i in range(x): if len(s)pow(9) + 7 ; for nt : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var n : int := (s)->size() ; var ans : int := n ; for i : Integer.subrange(0, x-1) do ( if ((s)->size()->compareTo(x)) < 0 then ( s := s + ((("" + ((s[i+1])))->toInteger() - 1) * s.subrange(i + 1+1)) ; ans := (s)->size() ) else ( ans := ans + ((("" + ((s[i+1])))->toInteger() - 1) * (ans - i - 1)) ) ; ans := ans mod mod) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=10**9+7 for nt in range(int(input())): x=int(input()) s=input() n=len(s) ans=n for i in range(x): if len(s)pow(9) + 7 ; for nt : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var n : int := (s)->size() ; var ans : int := n ; for i : Integer.subrange(0, x-1) do ( if ((s)->size()->compareTo(x)) < 0 then ( s := s + ((("" + ((s[i+1])))->toInteger() - 1) * s.subrange(i + 1+1)) ; ans := (s)->size() ) else ( ans := ans + ((("" + ((s[i+1])))->toInteger() - 1) * (ans - i - 1)) ) ; ans := ans mod mod) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Cat : def __init__(self,input): self.id=int(input[1]) self.size=int(input[2]) def sleep(self,index): self.index=index def last(self): return self.index+self.size def lastindex(list,val): result=len(list)-1 for n in range(len(list)): if list[n]==val : result=n return result def indexSleepable(wall,size): index=0 while indexexists( _x | result = _x ); attribute id : int := ("" + (((OclFile["System.in"]).readLine[1+1])))->toInteger(); attribute size : int := ("" + (((OclFile["System.in"]).readLine[2+1])))->toInteger(); operation initialise(input : OclAny) : Cat pre: true post: true activity: self.id := ("" + (((OclFile["System.in"]).readLine[1+1])))->toInteger() ; self.size := ("" + (((OclFile["System.in"]).readLine[2+1])))->toInteger(); return self; operation sleep(index : OclAny) pre: true post: true activity: self.index := index; operation last() : OclAny pre: true post: true activity: return self.index + self.size; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; while true do ( var W : OclAny := null; var Q : OclAny := null; Sequence{W,Q} := input().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; if W = Q & (Q == 0) then ( break ) else skip ; var lines : Sequence := Integer.subrange(0, Q-1)->select(n | true)->collect(n | (input()->trim().split())) ; wall := MatrixLib.elementwiseMult(Sequence{ false }, W) ; var Catdict : OclAny := Set{} ; for l : lines do ( if l->first() = "s" then ( var cat : Cat := (Cat.newCat()).initialise(l) ; index := indexSleepable(wall, cat.size) ; if index /= -1 then ( catOclProcess.sleepSeconds(index) ; execute (index)->display() ; wall.subrange(cat.index+1, cat.last()) := MatrixLib.elementwiseMult(Sequence{ true }, cat.size) ; Catdict[cat.id+1] := cat ) else ( execute ("impossible")->display() ) ) else (if l->first() = "w" then ( cat := Catdict[("" + ((l[1+1])))->toInteger()+1] ; wall.subrange(cat.index+1, cat.last()) := MatrixLib.elementwiseMult(Sequence{ false }, cat.size) ) else skip)) ; execute ("END")->display()); operation lastindex(list : OclAny, val : OclAny) : OclAny pre: true post: true activity: var result : double := (OclType["Sequence"])->size() - 1 ; for n : Integer.subrange(0, (OclType["Sequence"])->size()-1) do ( if [n+1] = val then ( result := n ) else skip) ; return result; operation indexSleepable(wall : OclAny, size : OclAny) pre: true post: true activity: index := 0 ; (compound_stmt while (test (logical_test (comparison (comparison (expr (atom (name index)))) < (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name wall)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name target)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name wall)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name index)))))) : (test (logical_test (comparison (expr (expr (atom (name index))) + (expr (atom (name size))))))))) ])))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name target)))) == (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name False))))))) ])) * (expr (atom (name size)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name index))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name next_index)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name lastindex)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name target))))))) , (argument (test (logical_test (comparison (expr (atom (name True)))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name index)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name next_index))) + (expr (atom (number (integer 1)))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : W,Q=map(int,input().split()) if W==Q==0 : break A=[0]*W for i in range(Q): s,*qs=input().split() if s=='s' : x,w=map(int,qs) su=sum(A[: w-1]) k=-1 for i in range(W-w+1): su+=A[i+w-1] if su==0 : k=i break su-=A[i] if k==-1 : print("impossible") else : print(k) for i in range(w): A[k+i]=x+1 else : x=int(qs[0]) for i in range(W): if A[i]==x+1 : A[i]=0 print("END") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var W : OclAny := null; var Q : OclAny := null; Sequence{W,Q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if W = Q & (Q == 0) then ( break ) else skip ; var A : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, W) ; for i : Integer.subrange(0, Q-1) do ( var s : OclAny := null; var qs : OclAny := null; Sequence{s,qs} := input().split() ; if s = 's' then ( var x : OclAny := null; var w : OclAny := null; Sequence{x,w} := (qs)->collect( _x | (OclType["int"])->apply(_x) ) ; var su : OclAny := (A.subrange(1,w - 1))->sum() ; var k : int := -1 ; for i : Integer.subrange(0, W - w + 1-1) do ( su := su + A[i + w - 1+1] ; if su = 0 then ( k := i ; break ) else skip ; su := su - A[i+1]) ; if k = -1 then ( execute ("impossible")->display() ) else ( execute (k)->display() ; for i : Integer.subrange(0, w-1) do ( A[k + i+1] := x + 1) ) ) else ( var x : int := ("" + ((qs->first())))->toInteger() ; for i : Integer.subrange(0, W-1) do ( if A[i+1] = x + 1 then ( A[i+1] := 0 ) else skip) )) ; execute ("END")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def read_input(input_path=None): if input_path is None : f=sys.stdin else : f=open(input_path,'r') home=f.readline().rstrip() away=f.readline().rstrip() n=int(f.readline()) fouls=[] for _ in range(n): moment,team,jersey,card=f.readline().rstrip().split() fouls.append((int(moment),team,int(jersey),card)) return n,home,away,fouls def sol(n,home,away,fouls): fouls=sorted(fouls) is_yellow={"a" : set(),"h" : set()} suspend=[] suspend_players=set() for foul in fouls : moment,team,jersey,card=foul if f"{team}{jersey}" in suspend_players : continue if card=="r" : suspend.append((home if team=="h" else away,jersey,moment)) suspend_players.add(f"{team}{jersey}") elif card=="y" : if jersey in is_yellow[team]: suspend.append((home if team=="h" else away,jersey,moment)) suspend_players.add(f"{team}{jersey}") else : is_yellow[team].add(jersey) res=[] for player in suspend : res.append(' '.join(map(str,player))) return res def solve(input_path=None): return sol(*read_input(input_path)) def main(): for line in sol(*read_input()): print(f"{line}") if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation read_input(input_path : OclAny) : OclAny pre: true post: true activity: if input_path->oclIsUndefined() then input_path := null else skip; if input_path <>= null then ( var f : OclFile := OclFile["System.in"] ) else ( f := OclFile.newOclFile_Write(OclFile.newOclFile(input_path)) ) ; var home : OclAny := f.readLine().rstrip() ; var away : OclAny := f.readLine().rstrip() ; var n : int := ("" + ((f.readLine())))->toInteger() ; var fouls : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var moment : OclAny := null; var team : OclAny := null; var jersey : OclAny := null; var card : OclAny := null; Sequence{moment,team,jersey,card} := f.readLine().rstrip().split() ; execute ((Sequence{("" + ((moment)))->toInteger(), team, ("" + ((jersey)))->toInteger(), card}) : fouls)) ; return n, home, away, fouls; operation sol(n : OclAny, home : OclAny, away : OclAny, fouls : OclAny) : OclAny pre: true post: true activity: fouls := fouls->sort() ; var is_yellow : Map := Map{ "a" |-> Set{}->union(()) }->union(Map{ "h" |-> Set{}->union(()) }) ; var suspend : Sequence := Sequence{} ; var suspend_players : Set := Set{}->union(()) ; for foul : fouls do ( var moment : OclAny := null; var team : OclAny := null; var jersey : OclAny := null; var card : OclAny := null; Sequence{moment,team,jersey,card} := foul ; if (suspend_players)->includes(StringLib.formattedString("{team}{jersey}")) then ( continue ) else skip ; if card = "r" then ( execute ((Sequence{if team = "h" then home else away endif, jersey, moment}) : suspend) ; execute ((StringLib.formattedString("{team}{jersey}")) : suspend_players) ) else (if card = "y" then ( if (is_yellow[team+1])->includes(jersey) then ( execute ((Sequence{if team = "h" then home else away endif, jersey, moment}) : suspend) ; execute ((StringLib.formattedString("{team}{jersey}")) : suspend_players) ) else ( (expr (atom (name is_yellow)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name team)))))))) ])) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name jersey)))))))) )))) ) ) else skip)) ; var res : Sequence := Sequence{} ; for player : suspend do ( execute ((StringLib.sumStringsWithSeparator(((player)->collect( _x | (OclType["String"])->apply(_x) )), ' ')) : res)) ; return res; operation solve(input_path : OclAny) : OclAny pre: true post: true activity: if input_path->oclIsUndefined() then input_path := null else skip; return sol((argument * (test (logical_test (comparison (expr (atom (name read_input)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input_path)))))))) ))))))))); operation main() pre: true post: true activity: for line : sol((argument * (test (logical_test (comparison (expr (atom (name read_input)) (trailer (arguments ( ))))))))) do ( execute (StringLib.formattedString("{line}"))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : w,q=map(int,input().split()) if w==0 and q==0 : break wall=[None]*w for _ in range(q): inp=input().split() if inp[0]=="s" : ind,wid=int(inp[1]),int(inp[2]) for i in range(w-wid+1): if all(x==None for x in wall[i : i+wid]): print(i) for j in range(i,i+wid): wall[j]=ind break else : print("impossible") else : ind=int(inp[1]) for i in range(w): if wall[i]==ind : wall[i]=None print("END") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var w : OclAny := null; var q : OclAny := null; Sequence{w,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if w = 0 & q = 0 then ( break ) else skip ; var wall : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, w) ; for _anon : Integer.subrange(0, q-1) do ( var inp : OclAny := input().split() ; if inp->first() = "s" then ( var ind : OclAny := null; var wid : OclAny := null; Sequence{ind,wid} := Sequence{("" + ((inp[1+1])))->toInteger(),("" + ((inp[2+1])))->toInteger()} ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name w))) - (expr (atom (name wid)))) + (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name all)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (comparison (expr (atom (name x)))) == (comparison (expr (atom None)))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name wall)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))) : (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name wid))))))))) ])))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name wid))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name wall)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ind))))))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "impossible"))))))) ))))))))))))))) ) else ( var ind : int := ("" + ((inp[1+1])))->toInteger() ; for i : Integer.subrange(0, w-1) do ( if wall[i+1] = ind then ( wall[i+1] := null ) else skip) )) ; execute ("END")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMaxNum(arr,n): hash=[0]*10 for i in range(n): hash[arr[i]]+=1 for i in range(9,-1,-1): for j in range(hash[i]): print(i,end="") if __name__=="__main__" : arr=[1,2,3,4,5,0] n=len(arr) findMaxNum(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 0 }))))) ; n := (arr)->size() ; findMaxNum(arr, n) ) else skip; operation findMaxNum(arr : OclAny, n : OclAny) pre: true post: true activity: var hash : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 10) ; for i : Integer.subrange(0, n-1) do ( hash[arr[i+1]+1] := hash[arr[i+1]+1] + 1) ; for i : Integer.subrange(-1 + 1, 9)->reverse() do ( for j : Integer.subrange(0, hash[i+1]-1) do ( execute (i)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break g=[[]for _ in range(n)] for u in range(n): v1,w1,v2,w2=map(int,input().split()) g[u].append((v1,w1)) g[u].append((v2,w2)) res=1 vis=[False]*n for i in range(n): if vis[i]: continue ws=[] p,u=-1,i while True : vis[u]=True for v,w in g[u]: if v!=p : ws.append(w) p,u=u,v break if u==i : break res=res*ws.count(max(ws))% 10007 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var g : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for u : Integer.subrange(0, n-1) do ( var v1 : OclAny := null; var w1 : OclAny := null; var v2 : OclAny := null; var w2 : OclAny := null; Sequence{v1,w1,v2,w2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name v1)))))) , (test (logical_test (comparison (expr (atom (name w1))))))) )))))))) )))) ; (expr (atom (name g)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name v2)))))) , (test (logical_test (comparison (expr (atom (name w2))))))) )))))))) ))))) ; var res : int := 1 ; var vis : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ; for i : Integer.subrange(0, n-1) do ( if vis[i+1] then ( continue ) else skip ; var ws : Sequence := Sequence{} ; var p : OclAny := null; var u : OclAny := null; Sequence{p,u} := Sequence{-1,i} ; while true do ( vis[u+1] := true ; for _tuple : g[u+1] do (var _indx : int := 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var w : OclAny := _tuple->at(_indx); if v /= p then ( execute ((w) : ws) ; var p : OclAny := null; var u : OclAny := null; Sequence{p,u} := Sequence{u,v} ; break ) else skip) ; if u = i then ( break ) else skip) ; res := res * ws->count((ws)->max()) mod 10007) ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def winner(X,S,L): if S*L % X : return 'RICHARD' if X<=2 : return 'GABRIEL' if X>=7 : return 'RICHARD' if LtoInteger() ; for case : Integer.subrange(1, T + 1-1) do ( var R : OclAny := null; var C : OclAny := null; Sequence{X,R,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{case, winner(X, Set{R, C}->min(), Set{R, C}->max())}))->display()); operation winner(X : OclAny, S : OclAny, L : OclAny) : OclAny pre: true post: true activity: if S * L mod X then ( return 'RICHARD' ) else skip ; if X <= 2 then ( return 'GABRIEL' ) else skip ; if X >= 7 then ( return 'RICHARD' ) else skip ; if (L->compareTo(X)) < 0 then ( return 'RICHARD' ) else skip ; if (2 * S->compareTo(X)) <= 0 then ( return 'RICHARD' ) else skip ; if Sequence{X, S, L} = Sequence{5, 3, 5} then ( return 'RICHARD' ) else skip ; return 'GABRIEL'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import re def solve(x,r,c): if x>=7 : return "RICHARD" if(r*c)% x!=0 : return "RICHARD" if max(r,c)size()-1) do ( var l : Sequence := (lines[i+1])->split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; out.write("Case #" + ("" + ((i))) + ": " + solve(l->first(), l[1+1], l[2+1]) + "\n")) ; out.closeFile() ; inp.closeFile(); operation solve(x : OclAny, r : OclAny, c : OclAny) : OclAny pre: true post: true activity: if x >= 7 then ( return "RICHARD" ) else skip ; if (r * c) mod x /= 0 then ( return "RICHARD" ) else skip ; if (Set{r, c}->max()->compareTo(x)) < 0 then ( return "RICHARD" ) else skip ; if (Set{r, c}->min()->compareTo((x + 1) / 2)) < 0 then ( return "RICHARD" ) else skip ; if Set{r, c}->max() = 5 & Set{r, c}->min() = 3 & x = 5 then ( return "RICHARD" ) else skip ; if Set{r, c}->min() = x / 2 & x /= 2 then ( return "RICHARD" ) else skip ; return "GABRIEL"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): input() pieces=tuple(zip(map(int,input().split()),input())) return Bob_sMaxStrength(pieces) def Bob_sMaxStrength(pieces): pScore=sScore=pMaxScore=sMaxScore=sum(piece[0]for piece in pieces if piece[1]=='B') for piece in pieces : if piece[1]=='A' : pScore+=piece[0] if pScore>pMaxScore : pMaxScore=pScore else : pScore-=piece[0] for i in range(len(pieces)-1,-1,-1): if pieces[i][1]=='A' : sScore+=pieces[i][0] if sScore>sMaxScore : sMaxScore=sScore else : sScore-=pieces[i][0] if pMaxScore>sMaxScore : return pMaxScore return sMaxScore if __name__=='__main__' : print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( execute (main())->display() ) else skip; operation main() : OclAny pre: true post: true activity: input() ; var pieces : Sequence := (Integer.subrange(1, (input().split())->collect( _x | (OclType["int"])->apply(_x) )->size())->collect( _indx | Sequence{(input().split())->collect( _x | (OclType["int"])->apply(_x) )->at(_indx), (OclFile["System.in"]).readLine()->at(_indx)} )) ; return Bob_sMaxStrength(pieces); operation Bob_sMaxStrength(pieces : OclAny) : OclAny pre: true post: true activity: pScore := pScore(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sScore)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name pMaxScore)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sMaxScore)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name piece)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))) (comp_for for (exprlist (expr (atom (name piece)))) in (logical_test (comparison (expr (atom (name pieces))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name piece)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) == (comparison (expr (atom 'B')))))))))) )))))))))) ; for piece : pieces do ( if piece[1+1] = 'A' then ( pScore := pScore + piece->first() ; if (pScore->compareTo(pMaxScore)) > 0 then ( var pMaxScore : OclAny := pScore ) else skip ) else ( pScore := pScore - piece->first() )) ; for i : Integer.subrange(-1 + 1, (pieces)->size() - 1)->reverse() do ( if pieces[i+1][1+1] = 'A' then ( sScore := sScore + pieces[i+1]->first() ; if (sScore->compareTo(sMaxScore)) > 0 then ( var sMaxScore : OclAny := sScore ) else skip ) else ( sScore := sScore - pieces[i+1]->first() )) ; if (pMaxScore->compareTo(sMaxScore)) > 0 then ( return pMaxScore ) else skip ; return sMaxScore; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys if __name__=='__main__' : n=int(sys.stdin.readline()) for i in range(n): sys.stdout.write("Case #{}: ".format(i+1)) x,r,c=map(int,sys.stdin.readline().split(' ')) r,c=min(r,c),max(r,c) ans='GABRIEL' if x==1 : pass elif x>6 : ans='RICHARD' elif(r*c)% x!=0 : ans='RICHARD' elif c2 and r==1 : ans='RICHARD' elif x>4 and r<3 : ans='RICHARD' elif(x,r)==(4,2): ans='RICHARD' elif(x,r,c)==(5,3,5): ans='RICHARD' elif(x,r)==(6,3): ans='RICHARD' sys.stdout.write("{}\n".format(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ((expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Case #{}: ") (trailer . (name format) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ))))))))) )))) ; var x : OclAny := null; var r : OclAny := null; var c : OclAny := null; Sequence{x,r,c} := (sys.stdin.readLine().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := Sequence{Set{r, c}->min(),Set{r, c}->max()} ; var ans : String := 'GABRIEL' ; if x = 1 then ( skip ) else (if x > 6 then ( ans := 'RICHARD' ) else (if (r * c) mod x /= 0 then ( ans := 'RICHARD' ) else (if (c->compareTo(x)) < 0 then ( ans := 'RICHARD' ) else (if x > 2 & r = 1 then ( ans := 'RICHARD' ) else (if x > 4 & r < 3 then ( ans := 'RICHARD' ) else (if Sequence{x, r} = Sequence{4, 2} then ( ans := 'RICHARD' ) else (if Sequence{x, r, c} = Sequence{5, 3, 5} then ( ans := 'RICHARD' ) else (if Sequence{x, r} = Sequence{6, 3} then ( ans := 'RICHARD' ) else skip ) ) ) ) ) ) ) ) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "{}\n") (trailer . (name format) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solver(x,r,c): if x>6 : return 'RICHARD' if(r*c)% x!=0 : return 'RICHARD' if x<=2 : return 'GABRIEL' if x==3 : if min(r,c)>1 : return 'GABRIEL' else : return 'RICHARD' if x==4 : if min(r,c)>2 : return 'GABRIEL' else : return 'RICHARD' if x==5 : if min(r,c)>2 and r+c>8 : return 'GABRIEL' else : return 'RICHARD' if x==6 : if min(r,c)>3 : return 'GABRIEL' else : return 'RICHARD' import sys with open(sys.argv[1],"r")as fileIN : inputLines=fileIN.readlines() inputLines=[line.strip()for line in inputLines] with open(sys.argv[2],"w")as fileOUT : numberOfCases=int(inputLines.pop(0)) for num in range(numberOfCases): inputlist=inputLines.pop(0).rstrip().split(' ') x=int(inputlist[0]) r=int(inputlist[1]) c=int(inputlist[2]) fileOUT.write('Case #'+str(num+1)+': '+solver(x,r,c)+'\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; try (var fileIN : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))); var inputLines : OclAny := fileIN.readlines()) catch (_e : OclException) do skip ; inputLines := inputLines->select(line | true)->collect(line | (line->trim())) ; try (var fileOUT : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ])))); var numberOfCases : int := ("" + ((inputLines->at(0`firstArg+1))))->toInteger() ; for num : Integer.subrange(0, numberOfCases-1) do ( var inputlist : OclAny := inputLines->at(0`firstArg+1).rstrip().split(' ') ; x := ("" + ((inputlist->first())))->toInteger() ; r := ("" + ((inputlist[1+1])))->toInteger() ; c := ("" + ((inputlist[2+1])))->toInteger() ; fileOUT.write('Case #' + ("" + ((num + 1))) + ': ' + solver(x, r, c) + ' '))) catch (_e : OclException) do skip; operation solver(x : OclAny, r : OclAny, c : OclAny) : OclAny pre: true post: true activity: if x > 6 then ( return 'RICHARD' ) else skip ; if (r * c) mod x /= 0 then ( return 'RICHARD' ) else skip ; if x <= 2 then ( return 'GABRIEL' ) else skip ; if x = 3 then ( if Set{r, c}->min() > 1 then ( return 'GABRIEL' ) else ( return 'RICHARD' ) ) else skip ; if x = 4 then ( if Set{r, c}->min() > 2 then ( return 'GABRIEL' ) else ( return 'RICHARD' ) ) else skip ; if x = 5 then ( if Set{r, c}->min() > 2 & r + c > 8 then ( return 'GABRIEL' ) else ( return 'RICHARD' ) ) else skip ; if x = 6 then ( if Set{r, c}->min() > 3 then ( return 'GABRIEL' ) else ( return 'RICHARD' ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- __author__='Reuben' def solution(dom_size,width,height): if dom_size>=7 or width*height % dom_size!=0 or dom_size>max(width,height): return "RICHARD" if dom_size==1 or dom_size==2 : return "GABRIEL" if dom_size==3 : if height==1 or width==1 : return "RICHARD" else : return "GABRIEL" if dom_size==4 : if(height<=2 or width<=2): return "RICHARD" else : return "GABRIEL" if dom_size==5 : if(height<=2 or width<=2)or(width==3 and(height<10 or height % 5!=0))or(height==3 and(width<10 or width % 5!=0)): return "RICHARD" else : return "GABRIEL" if dom_size==6 : if(height<=3 or width<=3): return "RICHARD" else : return "GABRIEL" f_in=open('file.in') f_out=open('file.out','w') cases=int(f_in.readline()) for i in range(1,cases+1): line=f_in.readline().split() dom_size=int(line[0]) width=int(line[1]) height=int(line[2]) s=solution(dom_size,width,height) f_out.write("Case #"+str(i)+": "+s+"\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var __author__ : String := 'Reuben' ; skip ; var f_in : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('file.in')) ; var f_out : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('file.out')) ; var cases : int := ("" + ((f_in.readLine())))->toInteger() ; for i : Integer.subrange(1, cases + 1-1) do ( var line : OclAny := f_in.readLine().split() ; dom_size := ("" + ((line->first())))->toInteger() ; width := ("" + ((line[1+1])))->toInteger() ; height := ("" + ((line[2+1])))->toInteger() ; var s : OclAny := solution(dom_size, width, height) ; f_out.write("Case #" + ("" + ((i))) + ": " + s + "\n")); operation solution(dom_size : OclAny, width : OclAny, height : OclAny) : OclAny pre: true post: true activity: if dom_size >= 7 or width * height mod dom_size /= 0 or (dom_size->compareTo(Set{width, height}->max())) > 0 then ( return "RICHARD" ) else skip ; if dom_size = 1 or dom_size = 2 then ( return "GABRIEL" ) else skip ; if dom_size = 3 then ( if height = 1 or width = 1 then ( return "RICHARD" ) else ( return "GABRIEL" ) ) else skip ; if dom_size = 4 then ( if (height <= 2 or width <= 2) then ( return "RICHARD" ) else ( return "GABRIEL" ) ) else skip ; if dom_size = 5 then ( if (height <= 2 or width <= 2) or (width = 3 & (height < 10 or height mod 5 /= 0)) or (height = 3 & (width < 10 or width mod 5 /= 0)) then ( return "RICHARD" ) else ( return "GABRIEL" ) ) else skip ; if dom_size = 6 then ( if (height <= 3 or width <= 3) then ( return "RICHARD" ) else ( return "GABRIEL" ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=10000 prime=[True for i in range(MAX+1)] def SieveOfEratosthenes(): prime[1]=False for p in range(2,MAX+1): if(prime[p]==True): for i in range(2*p,MAX+1,p): prime[i]=False def xorFirstNPrime(n): count=0 num=1 xorVal=0 while(countselect(i | true)->collect(i | (true)) ; skip ; skip ; SieveOfEratosthenes() ; n := 4 ; execute (xorFirstNPrime(n))->display(); operation SieveOfEratosthenes() pre: true post: true activity: prime[1+1] := false ; for p : Integer.subrange(2, MAX + 1-1) do ( if (prime[p+1] = true) then ( for i : Integer.subrange(2 * p, MAX + 1-1)->select( $x | ($x - 2 * p) mod p = 0 ) do ( prime[i+1] := false) ) else skip); operation xorFirstNPrime(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var num : int := 1 ; var xorVal : int := 0 ; while ((count->compareTo(n)) < 0) do ( if (prime[num+1]) then ( xorVal := xorVal xor num ; count := count + 1 ) else skip ; num := num + 1) ; return xorVal; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numberOfPaths(m,n): if(m==1 or n==1): return 1 return numberOfPaths(m-1,n)+numberOfPaths(m,n-1) m=3 n=3 print(numberOfPaths(m,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; m := 3 ; n := 3 ; execute (numberOfPaths(m, n))->display(); operation numberOfPaths(m : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (m = 1 or n = 1) then ( return 1 ) else skip ; return numberOfPaths(m - 1, n) + numberOfPaths(m, n - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def half(arr,n): flag=0 for i in range(n): if arr[i]% 2==0 : print(arr[i]//2,end=" ") else : if flag==0 : print(arr[i]//2,end=" ") flag=1 else : q=arr[i]//2 q+=1 print(q,end=" ") flag=0 arr=[-7,14,-7] half(arr,len(arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{-7}->union(Sequence{14}->union(Sequence{ -7 })) ; half(arr, (arr)->size()); operation half(arr : OclAny, n : OclAny) pre: true post: true activity: var flag : int := 0 ; for i : Integer.subrange(0, n-1) do ( if arr[i+1] mod 2 = 0 then ( execute (arr[i+1] div 2)->display() ) else ( if flag = 0 then ( execute (arr[i+1] div 2)->display() ; flag := 1 ) else ( var q : int := arr[i+1] div 2 ; q := q + 1 ; execute (q)->display() ; flag := 0 ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=input() minn=101 for i in range(n//2+1): s=a[: i]*2+a[i*2 :] if(s==a): minn=min(minn,i+1*int(i!=0)+(n-i*2)) print(minn) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : String := (OclFile["System.in"]).readLine() ; var minn : int := 101 ; for i : Integer.subrange(0, n div 2 + 1-1) do ( var s : double := a.subrange(1,i) * 2 + a.subrange(i * 2+1) ; if (s = a) then ( minn := Set{minn, i + 1 * ("" + ((i /= 0)))->toInteger() + (n - i * 2)}->min() ) else skip) ; execute (minn)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,collections,math,bisect,heapq,random,functools,io,os input=sys.stdin.readline out=sys.stdout.flush class UnionFind : def __init__(self,x)->None : self.uf=[-1]*x def find(self,x): r=x while self.uf[x]>=0 : x=self.uf[x] while r!=x : self.uf[r],r=x,self.uf[r] return x def union(self,x,y): ux,uy=self.find(x),self.find(y) if ux==uy : return if self.uf[ux]>=self.uf[uy]: self.uf[uy]+=self.uf[ux] self.uf[ux]=uy else : self.uf[ux]+=self.uf[uy] self.uf[uy]=ux return def solve(): n=int(input()) s=input().rstrip('\n') ans=n for i in range(n//2): if s[0 : i+1]==s[i+1 : 2*(i+1)]: ans=min(ans,i+1+1+n-2*(i+1)) print(ans) if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class UnionFind { static operation newUnionFind() : UnionFind pre: true post: UnionFind->exists( _x | result = _x ); operation __init__(x : OclAny) : OclAny pre: true post: true activity: self.uf := MatrixLib.elementwiseMult(Sequence{ -1 }, x); operation find(x : OclAny) : OclAny pre: true post: true activity: var r : OclAny := x ; while self.uf[x+1] >= 0 do ( x := self.uf[x+1]) ; while r /= x do ( var self.uf[r+1] : OclAny := null; Sequence{self.uf[r+1],r} := Sequence{x,self.uf[r+1]}) ; return x; operation union(x : OclAny,y : OclAny) pre: true post: true activity: var ux : OclAny := null; var uy : OclAny := null; Sequence{ux,uy} := Sequence{self->indexOf(x) - 1,self->indexOf(y) - 1} ; if ux = uy then ( return ) else skip ; if (self.uf[ux+1]->compareTo(self.uf[uy+1])) >= 0 then ( self.uf[uy+1] := self.uf[uy+1] + self.uf[ux+1] ; self.uf[ux+1] := uy ) else ( self.uf[ux+1] := self.uf[ux+1] + self.uf[uy+1] ; self.uf[uy+1] := ux ) ; return; } class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var out : OclAny := (OclFile["System.out"]).flush ; skip ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := input().rstrip(' ') ; var ans : int := n ; for i : Integer.subrange(0, n div 2-1) do ( if s.subrange(0+1, i + 1) = s.subrange(i + 1+1, 2 * (i + 1)) then ( ans := Set{ans, i + 1 + 1 + n - 2 * (i + 1)}->min() ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def inp(): return int(input()) def st(): return input().rstrip('\n') def lis(): return list(map(int,input().split())) def ma(): return map(int,input().split()) def func(a,b,c): z1=min(len(a),len(b)) for i in range(z1): c.append([a.pop(),b.pop()]) t=1 while(t): t-=1 n=inp() s=st() cost=n for i in range(n//2): if(s[: i+1]==s[i+1 : 2*(i+1)]): cost=min(cost,i+2+(n-(2*(i+1)))) print(cost) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; skip ; var t : int := 1 ; while (t) do ( t := t - 1 ; var n : OclAny := inp() ; var s : OclAny := st() ; var cost : OclAny := n ; for i : Integer.subrange(0, n div 2-1) do ( if (s.subrange(1,i + 1) = s.subrange(i + 1+1, 2 * (i + 1))) then ( cost := Set{cost, i + 2 + (n - (2 * (i + 1)))}->min() ) else skip) ; execute (cost)->display()); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation st() : OclAny pre: true post: true activity: return input().rstrip(' '); operation lis() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ma() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation func(a : OclAny, b : OclAny, c : OclAny) pre: true post: true activity: var z1 : OclAny := Set{(a)->size(), (b)->size()}->min() ; for i : Integer.subrange(0, z1-1) do ( execute ((Sequence{a->last()}->union(Sequence{ b->last() })) : c)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX_VAL=200000 def countIntervals(arr,V,N): minimum=float("inf") maximum=0 freq=[0]*(MAX_VAL) for i in range(0,N): li=arr[i][0] freq[li]=freq[li]+1 ri=arr[i][1] freq[ri+1]=freq[ri+1]-1 if limaximum : maximum=ri for i in range(minimum,maximum+1): freq[i]=freq[i]+freq[i-1] return freq[V] if __name__=="__main__" : arr=[[1,10],[5,10],[15,25],[7,12],[20,25]] V=7 N=len(arr) print(countIntervals(arr,V,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX_VAL : int := 200000 ; skip ; if __name__ = "__main__" then ( arr := Sequence{Sequence{1}->union(Sequence{ 10 })}->union(Sequence{Sequence{5}->union(Sequence{ 10 })}->union(Sequence{Sequence{15}->union(Sequence{ 25 })}->union(Sequence{Sequence{7}->union(Sequence{ 12 })}->union(Sequence{ Sequence{20}->union(Sequence{ 25 }) })))) ; V := 7 ; N := (arr)->size() ; execute (countIntervals(arr, V, N))->display() ) else skip; operation countIntervals(arr : OclAny, V : OclAny, N : OclAny) : OclAny pre: true post: true activity: var minimum : double := ("" + (("inf")))->toReal() ; var maximum : int := 0 ; var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX_VAL)) ; for i : Integer.subrange(0, N-1) do ( var li : OclAny := arr[i+1]->first() ; freq[li+1] := freq[li+1] + 1 ; var ri : OclAny := arr[i+1][1+1] ; freq[ri + 1+1] := freq[ri + 1+1] - 1 ; if (li->compareTo(minimum)) < 0 then ( minimum := li ) else skip ; if (ri->compareTo(maximum)) > 0 then ( maximum := ri ) else skip) ; for i : Integer.subrange(minimum, maximum + 1-1) do ( freq[i+1] := freq[i+1] + freq[i - 1+1]) ; return freq[V+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) P=list(map(int,input().split())) s=list(str(input())) A=[0]*(n+1) B=[0]*(n+1) for i in range(n): if s[i]=='A' : A[i+1]+=P[i] else : B[i+1]+=P[i] from itertools import accumulate A=list(accumulate(A)) B=list(accumulate(B)) ans=0 for i in range(n+1): ans=max(ans,A[i]+B[-1]-B[i]) P.reverse() s.reverse() A=[0]*(n+1) B=[0]*(n+1) for i in range(n): if s[i]=='A' : A[i+1]+=P[i] else : B[i+1]+=P[i] A=list(accumulate(A)) B=list(accumulate(B)) for i in range(n+1): ans=max(ans,A[i]+B[-1]-B[i]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var P : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Sequence := (("" + (((OclFile["System.in"]).readLine()))))->characters() ; var A : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; var B : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = 'A' then ( A[i + 1+1] := A[i + 1+1] + P[i+1] ) else ( B[i + 1+1] := B[i + 1+1] + P[i+1] )) ; skip ; A := (accumulate(A)) ; B := (accumulate(B)) ; var ans : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( ans := Set{ans, A[i+1] + B->last() - B[i+1]}->max()) ; P := P->reverse() ; s := s->reverse() ; A := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; B := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; for i : Integer.subrange(0, n-1) do ( if s[i+1] = 'A' then ( A[i + 1+1] := A[i + 1+1] + P[i+1] ) else ( B[i + 1+1] := B[i + 1+1] + P[i+1] )) ; A := (accumulate(A)) ; B := (accumulate(B)) ; for i : Integer.subrange(0, n + 1-1) do ( ans := Set{ans, A[i+1] + B->last() - B[i+1]}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): a,b=map(int,input().split()) print(a*(len(str(b+1))-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (a * ((("" + ((b + 1))))->size() - 1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import log10,floor if __name__=='__main__' : for _ in range(int(input())): A,B=map(int,input().split()) print(A*floor(log10(B+1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (A * floor(log10(B + 1)))->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inf=10**18 mod=10**9+7 minn=inf def _input(): return map(int,input().split()) def f(): A,B=_input() s=str(B) if '9'*len(s)==s : print(A*len(s)) else : n=len(s)-1 print(n*A) for _ in range(int(input())): f() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Math_PINFINITY : double := (10)->pow(18) ; var mod : double := (10)->pow(9) + 7 ; var minn : double := Math_PINFINITY ; skip ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( f()); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation f() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := _input() ; var s : String := ("" + ((B))) ; if StringLib.nCopies('9', (s)->size()) = s then ( execute (A * (s)->size())->display() ) else ( var n : double := (s)->size() - 1 ; execute (n * A)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range((int)(input())): n,m=(list)(map(int,input().split())) print(n*(len((str)(m+1))-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, (OclType["int"])((OclFile["System.in"]).readLine())-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (OclType["Sequence"])((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (n * (((OclType["String"])(m + 1))->size() - 1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): a,b=[i for i in input().split()] toadd=0 cmpr='9'*len(b) if int(b)==int(cmpr): toadd=1 print(int(a)*(len(b)-1+toadd)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(i | true)->collect(i | (i)) ; var toadd : int := 0 ; var cmpr : String := StringLib.nCopies('9', (b)->size()) ; if ("" + ((b)))->toInteger() = ("" + ((cmpr)))->toInteger() then ( toadd := 1 ) else skip ; execute (("" + ((a)))->toInteger() * ((b)->size() - 1 + toadd))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p=int(input()) while p : p-=1 n=input() k=len(n) if k>=2 : i=0 b='' while(itoInteger() ; while p do ( p := p - 1 ; var n : String := (OclFile["System.in"]).readLine() ; var k : int := (n)->size() ; if k >= 2 then ( var i : int := 0 ; var b : String := '' ; while ((i->compareTo(k)) < 0) do ( b := b + n[i+1] ; i := i + 2) ; b := b + n->last() ; execute (b)->display() ) else ( execute (n)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countStrings(n): a=[0 for i in range(n)] b=[0 for i in range(n)] a[0]=b[0]=1 for i in range(1,n): a[i]=a[i-1]+b[i-1] b[i]=a[i-1] return a[n-1]+b[n-1] print(countStrings(3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (countStrings(3))->display(); operation countStrings(n : OclAny) : OclAny pre: true post: true activity: var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var b : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; a->first() := 1; var b->first() : int := 1 ; for i : Integer.subrange(1, n-1) do ( a[i+1] := a[i - 1+1] + b[i - 1+1] ; b[i+1] := a[i - 1+1]) ; return a[n - 1+1] + b[n - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): b=input() print(b[: : 2]+b[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var b : String := (OclFile["System.in"]).readLine() ; execute (b(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) + b->last())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): b=input() print(b[: : 2]+b[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var b : String := (OclFile["System.in"]).readLine() ; execute (b(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) + b->last())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): b=input() print(b[: : 2]+b[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var b : String := (OclFile["System.in"]).readLine() ; execute (b(subscript : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) + b->last())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) v=list(map(int,input().split())) c=list(map(int,input().split())) ans=0 for i in range(n): if(v[i]-c[i]>=0): ans+=v[i]-c[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var v : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (v[i+1] - c[i+1] >= 0) then ( ans := ans + v[i+1] - c[i+1] ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : t-=1 n=input() k=len(n) if k>=2 : i=0 b='' while(itoInteger() ; while t do ( t := t - 1 ; var n : String := (OclFile["System.in"]).readLine() ; var k : int := (n)->size() ; if k >= 2 then ( var i : int := 0 ; var b : String := '' ; while ((i->compareTo(k)) < 0) do ( b := b + n[i+1] ; i := i + 2) ; b := b + n->last() ; execute (b)->display() ) else ( execute (n)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=[] n=int(input()) for i in range(n): x=input() a.append(x) def cmp(x): return len(x) a.sort(key=cmp) temp=True for i in range(len(a)-1): if not a[i]in a[i+1]: temp=False break if temp : print("YES") for i in range(len(a)): print(a[i]) else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Sequence{} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var x : String := (OclFile["System.in"]).readLine() ; execute ((x) : a)) ; skip ; a := a->sort() ; var temp : boolean := true ; for i : Integer.subrange(0, (a)->size() - 1-1) do ( if not((a[i + 1+1])->includes(a[i+1])) then ( temp := false ; break ) else skip) ; if temp then ( execute ("YES")->display() ; for i : Integer.subrange(0, (a)->size()-1) do ( execute (a[i+1])->display()) ) else ( execute ("NO")->display() ); operation cmp(x : OclAny) : OclAny pre: true post: true activity: return (x)->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(input()) lst=[] for _ in range(n): lst.append(input()) a=sorted(lst,key=len) for i in range(1,n): if a[i-1]not in a[i]: print('NO') sys.exit() print('YES') for i in a : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : lst)) ; var a : Sequence := lst->sortedBy($x | (len)->apply($x)) ; for i : Integer.subrange(1, n-1) do ( if (a[i+1])->excludes(a[i - 1+1]) then ( execute ('NO')->display() ; sys.exit() ) else skip) ; execute ('YES')->display() ; for i : a do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(input()) lst=[] for _ in range(n): lst.append(input()) a=sorted(lst,key=len) for i in range(1,n): if a[i-1]not in a[i]: print('NO') sys.exit() print('YES') for i in a : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : lst)) ; var a : Sequence := lst->sortedBy($x | (len)->apply($x)) ; for i : Integer.subrange(1, n-1) do ( if (a[i+1])->excludes(a[i - 1+1]) then ( execute ('NO')->display() ; sys.exit() ) else skip) ; execute ('YES')->display() ; for i : a do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lst=[] for _ in range(n): lst.append(input()) ls=sorted(lst,key=len) a=1 for i in range(1,n): if ls[i-1]not in ls[i]: print("NO") a=0 break if a==1 : print("YES") for i in ls : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : lst)) ; var ls : Sequence := lst->sortedBy($x | (len)->apply($x)) ; var a : int := 1 ; for i : Integer.subrange(1, n-1) do ( if (ls[i+1])->excludes(ls[i - 1+1]) then ( execute ("NO")->display() ; a := 0 ; break ) else skip) ; if a = 1 then ( execute ("YES")->display() ; for i : ls do ( execute (i)->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- stdin=lambda type_="int",sep=" " : list(map(eval(type_),input().split(sep))) joint=lambda sep=" ",*args : sep.join(str(i)if type(i)!=list else sep.join(map(str,i))for i in args) def iters(): return map(int(input())) n=int(input()) a=sorted((input()for _ in range(n)),key=lambda x : len(x)) v=all(a[i]in a[i+1]for i in range(n-1)) print('YES\n'+"\n".join(a)if v else 'NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var stdin : Function := lambda type_ : String, sep : String in (((input().split(sep))->collect( _x | (type_)->apply(_x) ))) ; var joint : Function := lambda sep : String, args : Sequence(OclAny) in (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))) if (logical_test (comparison (comparison (expr (atom (name type)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) != (comparison (expr (atom (name list)))))) else (test (logical_test (comparison (expr (atom (name sep)) (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))) )))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name args)))))))), sep)) ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))}->sortedBy($x | (lambda x : OclAny in ((x)->size()))->apply($x)) ; var v : boolean := ((argument (test (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) in (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) )))))))))->forAll( _x | _x = true ) ; execute (if v then 'YES ' + StringLib.sumStringsWithSeparator((a), "\n") else 'NO' endif)->display(); operation iters() : OclAny pre: true post: true activity: return (("" + (((OclFile["System.in"]).readLine())))->toInteger()`third)->collect( _x | (("" + (((OclFile["System.in"]).readLine())))->toInteger())->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPrime(n): for i in range(2,int(n**(1/2))+1): if(n % i==0): return False ; return True ; def printMinCountPrime(N): if(isPrime(N)): minCount=1 ; elif(N % 2==0): minCount=2 ; else : if(isPrime(N-2)): minCount=2 ; else : minCount=3 ; print(minCount); if __name__=="__main__" : N=100 ; printMinCountPrime(N); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( N := 100; ; printMinCountPrime(N); ) else skip; operation isPrime(n : OclAny) pre: true post: true activity: for i : Integer.subrange(2, ("" + (((n)->pow((1 / 2)))))->toInteger() + 1-1) do ( if (n mod i = 0) then ( return false; ) else skip) ; return true;; operation printMinCountPrime(N : OclAny) pre: true post: true activity: if (isPrime(N)) then ( var minCount : int := 1; ) else (if (N mod 2 = 0) then ( minCount := 2; ) else ( if (isPrime(N - 2)) then ( minCount := 2; ) else ( minCount := 3; ) ) ) ; execute (minCount)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bubble(list_nums): swap_bool=True while swap_bool : swap_bool=False for i in range(len(list_nums)-1): if abs(int(list_nums[i]))=max_TVs : for i in range(max_TVs): if int(TVs_sorted[i])<=0 : SUM+=abs(int(TVs_sorted[i])) else : for i in range(len(TVs_sorted)): if int(TVs_sorted[i])<=0 : SUM+=abs(int(TVs_sorted[i])) print(SUM) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation bubble(list_nums : OclAny) : OclAny pre: true post: true activity: var swap_bool : boolean := true ; while swap_bool do ( swap_bool := false ; for i : Integer.subrange(0, (list_nums)->size() - 1-1) do ( if ((("" + ((list_nums[i+1])))->toInteger())->abs()->compareTo((("" + ((list_nums[i + 1+1])))->toInteger())->abs())) < 0 then ( var list_nums[i+1] : OclAny := null; var list_nums[i + 1+1] : OclAny := null; Sequence{list_nums[i+1],list_nums[i + 1+1]} := Sequence{list_nums[i + 1+1],list_nums[i+1]} ; swap_bool := true ) else skip)) ; return list_nums; operation main() pre: true post: true activity: var n : OclAny := input().split() ; var amount_of_TV : int := ("" + ((n->first())))->toInteger() ; var max_TVs : int := ("" + ((n[1+1])))->toInteger() ; var TVs : OclAny := input().split() ; var TVs_sorted : Sequence := Sequence{} ; for i : Integer.subrange(0, (TVs)->size()-1) do ( if ("" + ((TVs[i+1])))->toInteger() < 0 then ( execute ((TVs[i+1]) : TVs_sorted) ) else skip) ; TVs_sorted := bubble(TVs_sorted) ; var SUM : int := 0 ; if ((TVs_sorted)->size()->compareTo(max_TVs)) >= 0 then ( for i : Integer.subrange(0, max_TVs-1) do ( if ("" + ((TVs_sorted[i+1])))->toInteger() <= 0 then ( SUM := SUM + (("" + ((TVs_sorted[i+1])))->toInteger())->abs() ) else skip) ) else ( for i : Integer.subrange(0, (TVs_sorted)->size()-1) do ( if ("" + ((TVs_sorted[i+1])))->toInteger() <= 0 then ( SUM := SUM + (("" + ((TVs_sorted[i+1])))->toInteger())->abs() ) else skip) ) ; execute (SUM)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def next_permutation(arr): arrCount=len(arr); i=arrCount-1 ; while(i>0 and arr[i]<=arr[i-1]): i-=1 ; if(i<=0): return[False,arr]; pivotIndex=i-1 ; j=arrCount-1 ; while(arr[j]<=arr[pivotIndex]): j-=1 ; temp=arr[pivotIndex]; arr[pivotIndex]=arr[j]; arr[j]=temp ; j=arrCount-1 ; while(iunion(Sequence{2}->union(Sequence{ 3 })); ; n := (a)->size(); ; execute (numberOfPermutations(a, n))->display();; operation next_permutation(arr : OclAny) pre: true post: true activity: var arrCount : int := (arr)->size(); ; var i : double := arrCount - 1; ; while (i > 0 & (arr[i+1]->compareTo(arr[i - 1+1])) <= 0) do ( i := i - 1;) ; if (i <= 0) then ( return Sequence{false}->union(Sequence{ arr }); ) else skip ; var pivotIndex : double := i - 1; ; var j : double := arrCount - 1; ; while ((arr[j+1]->compareTo(arr[pivotIndex+1])) <= 0) do ( j := j - 1;) ; var temp : OclAny := arr[pivotIndex+1]; ; arr[pivotIndex+1] := arr[j+1]; ; arr[j+1] := temp; ; j := arrCount - 1; ; while ((i->compareTo(j)) < 0) do ( temp := arr[i+1]; ; arr[i+1] := arr[j+1]; ; arr[j+1] := temp; ; i := i + 1; ; j := j - 1;) ; return Sequence{true}->union(Sequence{ arr });; operation numberOfPermutations(a : OclAny, n : OclAny) pre: true post: true activity: var sumEven : int := 0; ; var sumOdd : int := 0; ; var c : int := 0; ; while (true) do ( sumEven := 0; ; sumOdd := 0; ; for i : Integer.subrange(0, n-1) do ( if (i mod 2) then ( sumOdd := sumOdd + a[i+1]; ) else ( sumEven := sumEven + a[i+1]; )) ; if (sumOdd = sumEven) then ( c := c + 1; ) else skip ; var xx : OclAny := next_permutation(a); ; if (xx->first() = false) then ( break; ) else skip ; a := xx[1+1];) ; return c;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def prefix(string): k=1 ; n=len(string); g=[]; flag=0 ; for i in range(1,n): if(string[i]==string[0]): g.append(i); flag=1 ; if(flag==0): print(string); else : length=len(g); while(ksize(); ; var g : Sequence := Sequence{}; ; var flag : int := 0; ; for i : Integer.subrange(1, n-1) do ( if (string[i+1] = string->first()) then ( execute ((i) : g); ; flag := 1; ) else skip) ; if (flag = 0) then ( execute (string)->display(); ) else ( var length : int := (g)->size(); ; while ((k->compareTo(g->first())) < 0) do ( var cnt : int := 0; ; for j : Integer.subrange(0, length-1) do ( if (string[g[j+1] + k+1] = string[k+1]) then ( cnt := cnt + 1; ) else skip) ; if (cnt = len) then ( k := k + 1; ) else ( break; )) ; for i : Integer.subrange(0, k + 1-1) do ( execute (string[i+1])->display();) ; execute (->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) V=[int(i)for i in input().split()] C=[int(i)for i in input().split()] scores=[V[i]-C[i]for i in range(N)] ans=0 for score in scores : if score>0 : ans+=score print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var V : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var C : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var scores : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (V[i+1] - C[i+1])) ; var ans : int := 0 ; for score : scores do ( if score > 0 then ( ans := ans + score ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,q=map(int,input().split()) li=list(map(int,input().split())) ones=li.count(1) for _ in range(q): t,xork=map(int,input().split()) if t==1 : temp=1-li[xork-1] li[xork-1]=temp if temp==0 : ones-=1 else : ones+=1 else : print(1 if xork<=ones else 0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var li : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ones : int := li->count(1) ; for _anon : Integer.subrange(0, q-1) do ( var t : OclAny := null; var xork : OclAny := null; Sequence{t,xork} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if t = 1 then ( var temp : double := 1 - li[xork - 1+1] ; li[xork - 1+1] := temp ; if temp = 0 then ( ones := ones - 1 ) else ( ones := ones + 1 ) ) else ( execute (if (xork->compareTo(ones)) <= 0 then 1 else 0 endif)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t,n=map(int,input().split()) a=list(map(int,input().split())) kol=0 for i in range(len(a)): if a[i]>0 : kol+=1 for z in range(n): t1,n1=map(int,input().split()) if t1==2 : if n1<=kol : print(1) else : print(0) if t1==1 : a[n1-1]=1-a[n1-1] if a[n1-1]==0 : kol-=1 else : kol+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := null; var n : OclAny := null; Sequence{t,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var kol : int := 0 ; for i : Integer.subrange(0, (a)->size()-1) do ( if a[i+1] > 0 then ( kol := kol + 1 ) else skip) ; for z : Integer.subrange(0, n-1) do ( var t1 : OclAny := null; var n1 : OclAny := null; Sequence{t1,n1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if t1 = 2 then ( if (n1->compareTo(kol)) <= 0 then ( execute (1)->display() ) else ( execute (0)->display() ) ) else skip ; if t1 = 1 then ( a[n1 - 1+1] := 1 - a[n1 - 1+1] ; if a[n1 - 1+1] = 0 then ( kol := kol - 1 ) else ( kol := kol + 1 ) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,q=map(int,input().split()) a=list(map(int,input().split())) zero=a.count(0) one=n-zero for _ in range(q): t,x=map(int,input().split()) if t==1 : if a[x-1]==1 : zero+=1 one-=1 a[x-1]=0 else : zero-=1 one+=1 a[x-1]=1 else : if x<=one : print(1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var zero : int := a->count(0) ; var one : double := n - zero ; for _anon : Integer.subrange(0, q-1) do ( var t : OclAny := null; var x : OclAny := null; Sequence{t,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if t = 1 then ( if a[x - 1+1] = 1 then ( zero := zero + 1 ; one := one - 1 ; a[x - 1+1] := 0 ) else ( zero := zero - 1 ; one := one + 1 ; a[x - 1+1] := 1 ) ) else ( if (x->compareTo(one)) <= 0 then ( execute (1)->display() ) else ( execute (0)->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,q=map(int,input().split()) a=list(map(int,input().split())) zero=a.count(0) one=n-zero for _ in range(q): t,x=map(int,input().split()) if t==1 : if a[x-1]==1 : zero+=1 one-=1 a[x-1]=0 else : zero-=1 one+=1 a[x-1]=1 else : if x<=one : print(1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var zero : int := a->count(0) ; var one : double := n - zero ; for _anon : Integer.subrange(0, q-1) do ( var t : OclAny := null; var x : OclAny := null; Sequence{t,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if t = 1 then ( if a[x - 1+1] = 1 then ( zero := zero + 1 ; one := one - 1 ; a[x - 1+1] := 0 ) else ( zero := zero - 1 ; one := one + 1 ; a[x - 1+1] := 1 ) ) else ( if (x->compareTo(one)) <= 0 then ( execute (1)->display() ) else ( execute (0)->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) l=list(map(int,input().split())) c=l.count(1) for _ in range(m): a,b=map(int,input().split()) if a==1 : q=l[b-1] if q==0 : c+=1 else : c-=1 l[b-1]=1-q else : if b-1collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := l->count(1) ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a = 1 then ( var q : OclAny := l[b - 1+1] ; if q = 0 then ( c := c + 1 ) else ( c := c - 1 ) ; l[b - 1+1] := 1 - q ) else ( if (b - 1->compareTo(c)) < 0 then ( execute (1)->display() ) else ( execute (0)->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math t=int(input()) solutions=[] for i in range(t): s=int(input()) solutions.append(math.ceil(s**(1/2))) for x in solutions : print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var solutions : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((((s)->pow((1 / 2)))->ceil()) : solutions)) ; for x : solutions do ( execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,ceil for _ in range(int(input())): n=int(input()) print(ceil(sqrt(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (ceil(sqrt(n)))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil t=int(input()) for _ in range(t): s=int(input()) ans=0 min_el=1 while s>0 : s-=min_el min_el+=2 ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; var min_el : int := 1 ; while s > 0 do ( s := s - min_el ; min_el := min_el + 2 ; ans := ans + 1) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys DoD=["Thursday","Friday","Saturday","Sunday","Monday","Tuesday","Wednesday"] def getPNoD(n): if n==1 : return 0 elif n==3 : return 29+getPNoD(n-1) elif(n % 2==0 and n<=8)or(n % 2!=0 and n>8): return 31+getPNoD(n-1) else : return 30+getPNoD(n-1) for line in sys.stdin : m,d=[int(i)for i in line.split()] if m==0 : break n=getPNoD(m)+d-1 print(DoD[n % 7]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var DoD : Sequence := Sequence{"Thursday"}->union(Sequence{"Friday"}->union(Sequence{"Saturday"}->union(Sequence{"Sunday"}->union(Sequence{"Monday"}->union(Sequence{"Tuesday"}->union(Sequence{ "Wednesday" })))))) ; skip ; for line : OclFile["System.in"] do ( var m : OclAny := null; var d : OclAny := null; Sequence{m,d} := line.split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if m = 0 then ( break ) else skip ; n := getPNoD(m) + d - 1 ; execute (DoD[n mod 7+1])->display()); operation getPNoD(n : OclAny) : OclAny pre: true post: true activity: if n = 1 then ( return 0 ) else (if n = 3 then ( return 29 + getPNoD(n - 1) ) else (if (n mod 2 = 0 & n <= 8) or (n mod 2 /= 0 & n > 8) then ( return 31 + getPNoD(n - 1) ) else ( return 30 + getPNoD(n - 1) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import heapq from collections import deque from enum import Enum import sys import math from _heapq import heappush,heappop import copy from test.support import _MemoryWatchdog BIG_NUM=2000000000 HUGE_NUM=99999999999999999 MOD=1000000007 EPS=0.000000001 sys.setrecursionlimit(100000) MIN=0 MAX=20 SIZE=21 N=int(input()) dp=[[0]*SIZE for _ in range(N-1)] table=list(map(int,input().split())) dp[0][table[0]]=1 for i in range(1,N-1): for k in range(MIN,MAX+1): if dp[i-1][k]==0 : continue if k+table[i]<=MAX : dp[i][k+table[i]]+=dp[i-1][k] if k-table[i]>=MIN : dp[i][k-table[i]]+=dp[i-1][k] print("%d" %(dp[N-2][table[N-1]])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var BIG_NUM : int := 2000000000 ; var HUGE_NUM : int := 99999999999999999 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; sys.setrecursionlimit(100000) ; var MIN : int := 0 ; var MAX : int := 20 ; var SIZE : int := 21 ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var dp : Sequence := Integer.subrange(0, N - 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, SIZE))) ; var table : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; dp->first()[table->first()+1] := 1 ; for i : Integer.subrange(1, N - 1-1) do ( for k : Integer.subrange(MIN, MAX + 1-1) do ( if dp[i - 1+1][k+1] = 0 then ( continue ) else skip ; if (k + table[i+1]->compareTo(MAX)) <= 0 then ( dp[i+1][k + table[i+1]+1] := dp[i+1][k + table[i+1]+1] + dp[i - 1+1][k+1] ) else skip ; if (k - table[i+1]->compareTo(MIN)) >= 0 then ( dp[i+1][k - table[i+1]+1] := dp[i+1][k - table[i+1]+1] + dp[i - 1+1][k+1] ) else skip)) ; execute (StringLib.format("%d",(dp[N - 2+1][table[N - 1+1]+1])))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def resolve(): n=int(input()) lv=list(map(int,input().split())) lc=list(map(int,input().split())) ans=0 for i in range(n): if lv[i]>lc[i]: ans+=lv[i]-lc[i] print(ans) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; resolve(); operation resolve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lv : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lc : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (lv[i+1]->compareTo(lc[i+1])) > 0 then ( ans := ans + lv[i+1] - lc[i+1] ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=list(input().split()) for i in range(len(a)): a[i]=int(a[i]) n=a[0] m=a[1] b=list(input().split()) for i in range(len(b)): b[i]=int(b[i]) b.sort() sum=0 count=0 for i in b : if i/(-1)==abs(i): count+=1 if count<=m : for i in range(count): sum+=b[i] elif count>m : for i in range(m): sum+=b[i] print(abs(sum)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := (input().split()) ; for i : Integer.subrange(0, (a)->size()-1) do ( a[i+1] := ("" + ((a[i+1])))->toInteger()) ; var n : OclAny := a->first() ; var m : OclAny := a[1+1] ; var b : Sequence := (input().split()) ; for i : Integer.subrange(0, (b)->size()-1) do ( b[i+1] := ("" + ((b[i+1])))->toInteger()) ; b := b->sort() ; var sum : int := 0 ; var count : int := 0 ; for i : b do ( if i / (-1) = (i)->abs() then ( count := count + 1 ) else skip) ; if (count->compareTo(m)) <= 0 then ( for i : Integer.subrange(0, count-1) do ( sum := sum + b[i+1]) ) else (if (count->compareTo(m)) > 0 then ( for i : Integer.subrange(0, m-1) do ( sum := sum + b[i+1]) ) else skip) ; execute ((sum)->abs())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): s=int(input()) cnt=1 _sum=1 ini=1 while _sumtoInteger()-1) do ( var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cnt : int := 1 ; var _sum : int := 1 ; var ini : int := 1 ; while (_sum->compareTo(s)) < 0 do ( ini := ini + 2 ; _sum := _sum + ini ; cnt := cnt + 1) ; execute (cnt)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): x=int(input()) l=[] i=1 while sum(l)toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; var i : int := 1 ; while ((l)->sum()->compareTo(x)) < 0 do ( if i mod 2 /= 0 then ( execute ((i) : l) ) else skip ; i := i + 1) ; l := l->front() ; execute ((x - (l)->sum()) : l) ; execute ((l)->size())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) x=list(map(int,input().split())) c=0 p=0 r=0 while c!=n-1 : m=x[c]+k i=c while x[i]collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; var p : int := 0 ; var r : int := 0 ; while c /= n - 1 do ( var m : OclAny := x[c+1] + k ; var i : int := c ; while (x[i+1]->compareTo(m)) < 0 do ( i := i + 1 ; if i = n then ( break ) else skip) ; if i = n then ( c := i - 1 ; r := r + 1 ; break ) else skip ; if x[i+1] = m then ( c := i ) else ( c := i - 1 ) ; r := r + 1 ; if c = p then ( break ) else ( p := c )) ; if c = n - 1 then ( execute (r)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fast(k,a): c=1 s=k for pr,cur in zip(a[:-1],a[1 :]): dist=cur-pr if dist>k : c=-1 break elif dist>s : c+=1 s=k s-=dist return c n,k=[int(x)for x in input().split()] a=[int(x)for x in input().split()] print(fast(k,a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; Sequence{n,k} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; a := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (fast(k, a))->display(); operation fast(k : OclAny, a : OclAny) : OclAny pre: true post: true activity: var c : int := 1 ; var s : OclAny := k ; for _tuple : Integer.subrange(1, a->front()->size())->collect( _indx | Sequence{a->front()->at(_indx), a->tail()->at(_indx)} ) do (var _indx : int := 1; var pr : OclAny := _tuple->at(_indx); _indx := _indx + 1; var cur : OclAny := _tuple->at(_indx); var dist : double := cur - pr ; if (dist->compareTo(k)) > 0 then ( c := -1 ; break ) else (if (dist->compareTo(s)) > 0 then ( c := c + 1 ; s := k ) else skip) ; s := s - dist) ; return c; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) w=list(map(int,input().split())) last_start=w[0] cnt=1 failed=False for i in range(n-1): if(w[i+1]-last_start>k): last_start=w[i] cnt+=1 if(w[i+1]-w[i]>k): failed=True if failed : print(-1) else : print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var last_start : OclAny := w->first() ; var cnt : int := 1 ; var failed : boolean := false ; for i : Integer.subrange(0, n - 1-1) do ( if ((w[i + 1+1] - last_start->compareTo(k)) > 0) then ( last_start := w[i+1] ; cnt := cnt + 1 ) else skip ; if ((w[i + 1+1] - w[i+1]->compareTo(k)) > 0) then ( failed := true ) else skip) ; if failed then ( execute (-1)->display() ) else ( execute (cnt)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split(" ")) x=tuple(map(int,input().split(" "))) res=1 i=0 while ik : i=j-2 res+=1 break else : res=-1 break i+=1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; var res : int := 1 ; var i : int := 0 ; while (i->compareTo(n - 1)) < 0 do ( if (x[i + 1+1] - x[i+1]->compareTo(k)) <= 0 then ( for j : Integer.subrange(i + 1, n-1) do ( if (x[j+1] - x[i+1]->compareTo(k)) > 0 then ( i := j - 2 ; res := res + 1 ; break ) else skip) ) else ( res := -1 ; break ) ; i := i + 1) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=[int(i)for i in input().split()] x=[int(i)for i in input().split()] ans=0 pos=x[0] prev_pos=-1 while pos!=x[-1]: prev_pos=pos pos+=k ans+=1 if pos not in x : while pos not in x : pos-=1 if pos==prev_pos : ans=-1 break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var x : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : int := 0 ; var pos : OclAny := x->first() ; var prev_pos : int := -1 ; while pos /= x->last() do ( prev_pos := pos ; pos := pos + k ; ans := ans + 1 ; if (x)->excludes(pos) then ( while (x)->excludes(pos) do ( pos := pos - 1) ; if pos = prev_pos then ( ans := -1 ; break ) else skip ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printCoins(arr,n): oddSum=0 for i in range(0,n,2): oddSum+=arr[i] evenSum=0 for i in range(1,n,2): evenSum+=arr[i] if oddSum>evenSum : start=0 else : start=1 for i in range(start,n,2): print(arr[i],end=" ") if __name__=="__main__" : arr1=[8,15,3,7] n=len(arr1) printCoins(arr1,n) print() arr2=[2,2,2,2] n=len(arr2) printCoins(arr2,n) print() arr3=[20,30,2,2,2,10] n=len(arr3) printCoins(arr3,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var arr1 : Sequence := Sequence{8}->union(Sequence{15}->union(Sequence{3}->union(Sequence{ 7 }))) ; n := (arr1)->size() ; printCoins(arr1, n) ; execute (->display() ; var arr2 : Sequence := Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 2 }))) ; n := (arr2)->size() ; printCoins(arr2, n) ; execute (->display() ; var arr3 : Sequence := Sequence{20}->union(Sequence{30}->union(Sequence{2}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 10 }))))) ; n := (arr3)->size() ; printCoins(arr3, n) ) else skip; operation printCoins(arr : OclAny, n : OclAny) pre: true post: true activity: var oddSum : int := 0 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( oddSum := oddSum + arr[i+1]) ; var evenSum : int := 0 ; for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( evenSum := evenSum + arr[i+1]) ; if (oddSum->compareTo(evenSum)) > 0 then ( var start : int := 0 ) else ( start := 1 ) ; for i : Integer.subrange(start, n-1)->select( $x | ($x - start) mod 2 = 0 ) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def min_changes(a,n): ans_a=0 ; ans_b=0 ; for i in range(n): if(i % 2==0): if(a[i]==0): ans_a+=1 ; else : ans_b+=1 ; else : if(a[i]==0): ans_b+=1 ; else : ans_a+=1 ; return min(ans_a,ans_b); if __name__=='__main__' : a=[1,0,0,1,0,0,1,0]; n=len(a); print(min_changes(a,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 0 }))))))); ; n := (a)->size(); ; execute (min_changes(a, n))->display(); ) else skip; operation min_changes(a : OclAny, n : OclAny) pre: true post: true activity: var ans_a : int := 0; ; var ans_b : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (i mod 2 = 0) then ( if (a[i+1] = 0) then ( ans_a := ans_a + 1; ) else ( ans_b := ans_b + 1; ) ) else ( if (a[i+1] = 0) then ( ans_b := ans_b + 1; ) else ( ans_a := ans_a + 1; ) )) ; return Set{ans_a, ans_b}->min();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) V=input().split(" ") V=[int(i)for i in V] C=input().split(" ") C=[int(i)for i in C] list=[0] ans=0 X=0 Y=0 for i in range(N): if V[i]-C[i]>0 : X=V[i] Y=C[i] list.append(X-Y) print(sum(list)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var V : OclAny := input().split(" ") ; V := V->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var C : OclAny := input().split(" ") ; C := C->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var OclType["Sequence"] : Sequence := Sequence{ 0 } ; var ans : int := 0 ; var X : int := 0 ; var Y : int := 0 ; for i : Integer.subrange(0, N-1) do ( if V[i+1] - C[i+1] > 0 then ( X := V[i+1] ; Y := C[i+1] ; execute ((X - Y) : OclType["Sequence"]) ) else skip) ; execute ((OclType["Sequence"])->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input().split() n[0]=int(n[0]) n[1]=int(n[1]) total=240 total-=n[1] res=0 for i in range(1,n[0]+1): if i=0 : total-=i*5 else : res=i-1 break else : if total-i*5>=0 : res=i else : res=i-1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := input().split() ; n->first() := ("" + ((n->first())))->toInteger() ; n[1+1] := ("" + ((n[1+1])))->toInteger() ; var total : int := 240 ; total := total - n[1+1] ; var res : int := 0 ; for i : Integer.subrange(1, n->first() + 1-1) do ( if (i->compareTo(n->first())) < 0 then ( if total - 5 * i >= 0 then ( total := total - i * 5 ) else ( res := i - 1 ; break ) ) else ( if total - i * 5 >= 0 then ( res := i ) else ( res := i - 1 ) )) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) print(-sum(sorted(int(x)for x in input().split()if x[0]=='-')[: m])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (-(sorted((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) == (comparison (expr (atom '-')))))))))).subrange(1,m))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : n,k=map(int,input().split()) total=0 result=0 min_per_24h=1440 min_per_20h=1200 for i in range(1,n+1): total+=5*i if min_per_20h+total<=min_per_24h-k : result=i else : break print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var total : int := 0 ; var result : int := 0 ; var min_per:= 14404h : int := 1440 ; var min_per:= 12000h : int := 1200 ; for i : Integer.subrange(1, n + 1-1) do ( total := total + 5 * i ; if (min_pertotal0h + total->compareTo(min_perk4h - k)) <= 0 then ( result := i ) else ( break )) ; execute (result)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) solve_time=240-k problem_count=0 time_count=0 while True : if((problem_count+1)*5)+time_count<=solve_time and problem_countcollect( _x | (OclType["int"])->apply(_x) ) ; var solve_time : double := 240 - k ; var problem_count : int := 0 ; var time_count : int := 0 ; while true do ( if (((problem_count + 1) * 5) + time_count->compareTo(solve_time)) <= 0 & (problem_count->compareTo(n)) < 0 then ( problem_count := problem_count + 1 ; time_count := time_count + problem_count * 5 ) else ( break )) ; execute (problem_count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def newYearAndHurry(): (problems,timesToGet)=map(int,input().split()) timeFree=240-timesToGet count=0 for i in range(1,problems+1): timeFree-=i*5 if(timeFree<0): break count+=1 print(count) return newYearAndHurry() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; newYearAndHurry(); operation newYearAndHurry() pre: true post: true activity: ; var Sequence{problems, timesToGet} : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var timeFree : double := 240 - timesToGet ; var count : int := 0 ; for i : Integer.subrange(1, problems + 1-1) do ( timeFree := timeFree - i * 5 ; if (timeFree < 0) then ( break ) else skip ; count := count + 1) ; execute (count)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input().split() n[0]=int(n[0]) n[1]=int(n[1]) total=240 total-=n[1] res=0 for i in range(1,n[0]+1): if i=0 : total-=i*5 else : res=i-1 break else : if total-i*5>=0 : res=i else : res=i-1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := input().split() ; n->first() := ("" + ((n->first())))->toInteger() ; n[1+1] := ("" + ((n[1+1])))->toInteger() ; var total : int := 240 ; total := total - n[1+1] ; var res : int := 0 ; for i : Integer.subrange(1, n->first() + 1-1) do ( if (i->compareTo(n->first())) < 0 then ( if total - 5 * i >= 0 then ( total := total - i * 5 ) else ( res := i - 1 ; break ) ) else ( if total - i * 5 >= 0 then ( res := i ) else ( res := i - 1 ) )) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque import sys input=sys.stdin.readline N,M=map(int,input().split()) G=[[]for _ in[0]*N] deg=[0]*N for _ in[0]*M : a,b=map(int,input().split()) G[a].append(b) deg[b]+=1 q=deque() for v,d in enumerate(deg): if d==0 : print(v) q.append(v) while q : v=q.popleft() for u in G[v]: deg[u]-=1 if deg[u]==0 : print(u) q.append(u) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var G : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N)->select(_anon | true)->collect(_anon | (Sequence{})) ; var deg : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, M) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; deg[b+1] := deg[b+1] + 1) ; var q : Sequence := () ; for _tuple : Integer.subrange(1, (deg)->size())->collect( _indx | Sequence{_indx-1, (deg)->at(_indx)} ) do (var _indx : int := 1; var v : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); if d = 0 then ( execute (v)->display() ; execute ((v) : q) ) else skip) ; while q do ( var v : OclAny := q->first() ; q := q->tail() ; for u : G[v+1] do ( deg[u+1] := deg[u+1] - 1 ; if deg[u+1] = 0 then ( execute (u)->display() ; execute ((u) : q) ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def topological_sort(nodes,edges)->[]: visited=set() result=[] def dfs(v): if v not in visited : visited.add(v) for u in edges[v]: dfs(u) result.append(v) for s in nodes : dfs(s) return result def aoj_system_test(): V,E=map(int,input().split()) nodes=[] edges=[] for i in range(V): nodes.append(i) edges.append([]) for _ in range(E): a,b=map(int,input().split()) edges[b].append(a) ret=topological_sort(nodes,edges) for v in ret : print(v) if __name__=='__main__' : aoj_system_test() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( aoj_system_test() ) else skip; operation topological_sort(nodes : OclAny, edges : OclAny) : Sequence pre: true post: true activity: var visited : Set := Set{}->union(()) ; var result : Sequence := Sequence{} ; skip ; for s : nodes do ( dfs(s)) ; return result; operation aoj_system_test() pre: true post: true activity: var V : OclAny := null; var E : OclAny := null; Sequence{V,E} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; nodes := Sequence{} ; edges := Sequence{} ; for i : Integer.subrange(0, V-1) do ( execute ((i) : nodes) ; execute ((Sequence{}) : edges)) ; for _anon : Integer.subrange(0, E-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name b)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; var ret : OclAny := topological_sort(nodes, edges) ; for v : ret do ( execute (v)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from operator import itemgetter INF=10**30 sys.setrecursionlimit(10000000) from collections import deque G=[] into=[] def topological_sort(n): global into ans=[] unvisited=[True]*n for i in range(n): if into[i]==0 and unvisited[i]: q=deque() q.append(i) while len(q)>0 : node=q.popleft() ans.append(node) unvisited[node]=False for v in G[node]: into[v]-=1 if into[v]==0 : q.append(v) return ans visited=[] answer=deque() def rec(v): global visited visited[v]=True for node in G[v]: if not visited[node]: rec(node) answer.appendleft(v) def dfs_topolo(n): for i in range(n): if not visited[i]: rec(i) def main(): global G,into,visited v,e=list(map(int,input().strip().split())) G=[[]for _ in range(v)] visited=[False]*v into=[0]*v for i in range(e): s,t=list(map(int,input().strip().split())) G[s].append(t) into[t]+=1 dfs_topolo(v) for p in answer : print(p) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute into : OclAny; attribute visited : OclAny; attribute G : OclAny; attribute into : OclAny; attribute visited : OclAny; operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var INF : double := (10)->pow(30) ; sys.setrecursionlimit(10000000) ; skip ; var G : Sequence := Sequence{} ; var into : Sequence := Sequence{} ; skip ; var visited : Sequence := Sequence{} ; var answer : Sequence := () ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation topological_sort(n : OclAny) : OclAny pre: true post: true activity: skip ; var ans : Sequence := Sequence{} ; var unvisited : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, n) ; for i : Integer.subrange(0, n-1) do ( if into[i+1] = 0 & unvisited[i+1] then ( var q : Sequence := () ; execute ((i) : q) ; while (q)->size() > 0 do ( var node : OclAny := q->first() ; q := q->tail() ; execute ((node) : ans) ; unvisited[node+1] := false ; for v : G[node+1] do ( into[v+1] := into[v+1] - 1 ; if into[v+1] = 0 then ( execute ((v) : q) ) else skip)) ) else skip) ; return ans; operation rec(v : OclAny) pre: true post: true activity: skip ; visited[v+1] := true ; for node : G[v+1] do ( if not(visited[node+1]) then ( rec(node) ) else skip) ; answer := answer->prepend(v); operation dfs_topolo(n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if not(visited[i+1]) then ( rec(i) ) else skip); operation main() pre: true post: true activity: skip; skip; skip ; var e : OclAny := null; Sequence{v,e} := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; G := Integer.subrange(0, v-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; visited := MatrixLib.elementwiseMult(Sequence{ false }, v) ; into := MatrixLib.elementwiseMult(Sequence{ 0 }, v) ; for i : Integer.subrange(0, e-1) do ( var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) )))) ; into[t+1] := into[t+1] + 1) ; dfs_topolo(v) ; for p : answer do ( execute (p)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): nvertices,nedges=map(int,input().split()) Adj=[[]for i in range(nvertices)] for i in range(nedges): s,t=map(int,input().split()) Adj[s].append(t) visited=[False]*nvertices ordering=[] for u in range(nvertices): if not visited[u]: dfs(u,Adj,visited,ordering) for v in reversed(ordering): print(v) def dfs(u,Adj,visited,ordering): visited[u]=True for v in Adj[u]: if not visited[v]: dfs(v,Adj,visited,ordering) ordering.append(u) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: var nvertices : OclAny := null; var nedges : OclAny := null; Sequence{nvertices,nedges} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var Adj : Sequence := Integer.subrange(0, nvertices-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, nedges-1) do ( var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name Adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name s)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) ))))) ; var visited : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, nvertices) ; var ordering : Sequence := Sequence{} ; for u : Integer.subrange(0, nvertices-1) do ( if not(visited[u+1]) then ( dfs(u, Adj, visited, ordering) ) else skip) ; for v : (ordering)->reverse() do ( execute (v)->display()); operation dfs(u : OclAny, Adj : OclAny, visited : OclAny, ordering : OclAny) pre: true post: true activity: visited[u+1] := true ; for v : Adj[u+1] do ( if not(visited[v+1]) then ( dfs(v, Adj, visited, ordering) ) else skip) ; execute ((u) : ordering); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _=int(input()) prices=list(input().split()) costs=list(input().split()) benefit=0 for price,cost in zip(prices,costs): if int(price)>int(cost): benefit+=int(price)-int(cost) print(benefit) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _anon : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var prices : Sequence := (input().split()) ; var costs : Sequence := (input().split()) ; var benefit : int := 0 ; for _tuple : Integer.subrange(1, prices->size())->collect( _indx | Sequence{prices->at(_indx), costs->at(_indx)} ) do (var _indx : int := 1; var price : OclAny := _tuple->at(_indx); _indx := _indx + 1; var cost : OclAny := _tuple->at(_indx); if (("" + ((price)))->toInteger()->compareTo(("" + ((cost)))->toInteger())) > 0 then ( benefit := benefit + ("" + ((price)))->toInteger() - ("" + ((cost)))->toInteger() ) else skip) ; execute (benefit)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin from collections import deque UNVISITED,VISITED_IN_QUEUE,POPPED_OUT=0,1,2 def generate_adj_matrix(_v_info,_input_adj_table,_in_deg_list): for v_detail in _v_info : v_from,v_to=map(int,v_detail) _input_adj_table[v_from].append(v_to) _in_deg_list[v_to]+=1 return _input_adj_table,_in_deg_list def topological_sort(): for v in range(vertices): if not in_deg_list[v]and status[v]is UNVISITED : bfs(v) return ans def bfs(v): v_queue.append(v) status[v]=VISITED_IN_QUEUE while v_queue : current=v_queue.popleft() ans.append(current) for v_adj in adj_table[current]: in_deg_list[v_adj]-=1 if not in_deg_list[v_adj]and status[v_adj]is UNVISITED : status[v_adj]=VISITED_IN_QUEUE v_queue.appendleft(v_adj) status[current]=POPPED_OUT return None if __name__=='__main__' : _input=stdin.readlines() vertices,edges=map(int,_input[0].split()) v_info=map(lambda x : x.split(),_input[1 :]) status=[UNVISITED]*vertices v_queue=deque() init_adj_table=tuple([]for _ in range(vertices)) init_in_deg_list=[0]*vertices ans=[] adj_table,in_deg_list=generate_adj_matrix(v_info,init_adj_table,init_in_deg_list) print(*topological_sort()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var UNVISITED : OclAny := null; var VISITED_IN_QUEUE : OclAny := null; var POPPED_OUT : OclAny := null; Sequence{UNVISITED,VISITED_IN_QUEUE,POPPED_OUT} := Sequence{0,1,2} ; skip ; skip ; skip ; if __name__ = '__main__' then ( var _input : OclAny := stdin.readlines() ; var vertices : OclAny := null; var edges : OclAny := null; Sequence{vertices,edges} := (_input->first().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var v_info : Sequence := (_input->tail())->collect( _x | (lambda x : OclAny in (x.split()))->apply(_x) ) ; var status : Sequence := MatrixLib.elementwiseMult(Sequence{ UNVISITED }, vertices) ; var v_queue : Sequence := () ; var init_adj_table : Sequence := ((argument (test (logical_test (comparison (expr (atom [ ]))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name vertices)))))))) ))))))))) ; var init_in_deg_list : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, vertices) ; var ans : Sequence := Sequence{} ; var adj_table : OclAny := null; var in_deg_list : OclAny := null; Sequence{adj_table,in_deg_list} := generate_adj_matrix(v_info, init_adj_table, init_in_deg_list) ; execute ((argument * (test (logical_test (comparison (expr (atom (name topological_sort)) (trailer (arguments ( )))))))))->display() ) else skip; operation generate_adj_matrix(_v_info : OclAny, _input_adj_table : OclAny, _in_deg_list : OclAny) : OclAny pre: true post: true activity: for v_detail : _v_info do ( var v_from : OclAny := null; var v_to : OclAny := null; Sequence{v_from,v_to} := (v_detail)->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name _input_adj_table)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v_from)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v_to)))))))) )))) ; _in_deg_list[v_to+1] := _in_deg_list[v_to+1] + 1) ; return _input_adj_table, _in_deg_list; operation topological_sort() : OclAny pre: true post: true activity: for v : Integer.subrange(0, vertices-1) do ( if not(in_deg_list[v+1]) & status[v+1] <>= UNVISITED then ( bfs(v) ) else skip) ; return ans; operation bfs(v : OclAny) : OclAny pre: true post: true activity: execute ((v) : v_queue) ; status[v+1] := VISITED_IN_QUEUE ; while v_queue do ( var current : OclAny := v_queue->first() ; v_queue := v_queue->tail() ; execute ((current) : ans) ; for v_adj : adj_table[current+1] do ( in_deg_list[v_adj+1] := in_deg_list[v_adj+1] - 1 ; if not(in_deg_list[v_adj+1]) & status[v_adj+1] <>= UNVISITED then ( status[v_adj+1] := VISITED_IN_QUEUE ; v_queue := v_queue->prepend(v_adj) ) else skip) ; status[current+1] := POPPED_OUT) ; return null; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def hut_pattern(n): if n % 2==0 : n=n+1 for i in range(0,n-n//3+1,1): for j in range(0,n,1): t=2*n/5 if t % 2!=0 : t=t-1 if((i==n/5)or(i==n-n/3)or(j==n-1 and i>=n/5)or(j>=n/5 and j=n/5)or(j==t and i>n/5)or(i<=n/5 and(i+j==n/5 or j-i==n/5))or(j-i==n-n/5)): print("*",end=" ") elif((i==n//5+n//7)and(j>=n//7 and j<=t-n//7)): print("_",end=" ") elif((i>=n//5+n//7)and(j==n//7 or j==t-n//7)): print("|",end=" ") else : print(" ",end=" ") print("\n"); if __name__=='__main__' : n=15 hut_pattern(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 15 ; hut_pattern(n) ) else skip; operation hut_pattern(n : OclAny) pre: true post: true activity: if n mod 2 = 0 then ( n := n + 1 ) else skip ; for i : Integer.subrange(0, n - n div 3 + 1-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( for j : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( var t : double := 2 * n / 5 ; if t mod 2 /= 0 then ( t := t - 1 ) else skip ; if ((i = n / 5) or (i = n - n / 3) or (j = n - 1 & (i->compareTo(n / 5)) >= 0) or ((j->compareTo(n / 5)) >= 0 & (j->compareTo(n - n / 5)) < 0 & i = 0) or (j = 0 & (i->compareTo(n / 5)) >= 0) or (j = t & (i->compareTo(n / 5)) > 0) or ((i->compareTo(n / 5)) <= 0 & (i + j = n / 5 or j - i = n / 5)) or (j - i = n - n / 5)) then ( execute ("*")->display() ) else (if ((i = n div 5 + n div 7) & ((j->compareTo(n div 7)) >= 0 & (j->compareTo(t - n div 7)) <= 0)) then ( execute ("_")->display() ) else (if (((i->compareTo(n div 5 + n div 7)) >= 0) & (j = n div 7 or j = t - n div 7)) then ( execute ("|")->display() ) else ( execute (" ")->display() ) ) ) ) ; execute ("\n")->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) arr=list(map(int,input().split())) arr.sort() res=0 for i in range(m): if arr[i]<0 : res-=arr[i] print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := arr->sort() ; var res : int := 0 ; for i : Integer.subrange(0, m-1) do ( if arr[i+1] < 0 then ( res := res - arr[i+1] ) else skip) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for k in range(int(input())): n=int(input()) a=list(map(int,input().split())) answer=0 for i,t in enumerate(a,2): for j in range(-i % t,i-2,t): if i+j==t*a[j]: answer+=1 print(answer) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for k : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var answer : int := 0 ; for _tuple : Integer.subrange(1, (a, 2)->size())->collect( _indx | Sequence{_indx-1, (a, 2)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); for j : Integer.subrange(-i mod t, i - 2-1)->select( $x | ($x - -i mod t) mod t = 0 ) do ( if i + j = t * a[j+1] then ( answer := answer + 1 ) else skip)) ; execute (answer)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) c=0 for i in range(n): for j in range(l[i]-i-2,n,l[i]): if i+j+2==l[i]*l[j]and itoInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(l[i+1] - i - 2, n-1)->select( $x | ($x - l[i+1] - i - 2) mod l[i+1] = 0 ) do ( if i + j + 2 = l[i+1] * l[j+1] & (i->compareTo(j)) < 0 then ( c := c + 1 ) else skip)) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) a=list(map(int,input().split())) ans=0 for i,x in enumerate(a,2): for j in range(-i % x,i-2,x): if i+j==x*a[j]: ans+=1 print(ans) for _ in range(int(input())): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( solve()); operation solve() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; for _tuple : Integer.subrange(1, (a, 2)->size())->collect( _indx | Sequence{_indx-1, (a, 2)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); for j : Integer.subrange(-i mod x, i - 2-1)->select( $x | ($x - -i mod x) mod x = 0 ) do ( if i + j = x * a[j+1] then ( ans := ans + 1 ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cases=int(input()) for _ in range(cases): n=int(input()) arr=list(map(int,input().split())) pair=0 for i in range(n): for j in range(arr[i]-2-i,n,arr[i]): if itoInteger() ; for _anon : Integer.subrange(0, cases-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var pair : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(arr[i+1] - 2 - i, n-1)->select( $x | ($x - arr[i+1] - 2 - i) mod arr[i+1] = 0 ) do ( if (i->compareTo(j)) < 0 then ( if (i + j + 2 = arr[i+1] * arr[j+1]) then ( pair := pair + 1 ) else skip ) else skip)) ; execute (pair)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(0,t): n=int(input()) a1=input().split() a=[int(x)for x in a1] cont=0 for i in range(0,n): p=a[i] for j in range(i+p-2*(i+1)% p,n,p): if(p*a[j]==i+j+2): cont+=1 print(cont) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a1 : OclAny := input().split() ; var a : Sequence := a1->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var cont : int := 0 ; for i : Integer.subrange(0, n-1) do ( var p : OclAny := a[i+1] ; for j : Integer.subrange(i + p - 2 * (i + 1) mod p, n-1)->select( $x | ($x - i + p - 2 * (i + 1) mod p) mod p = 0 ) do ( if (p * a[j+1] = i + j + 2) then ( cont := cont + 1 ) else skip)) ; execute (cont)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minMaxLengthWords(inp): length=len(inp) si=ei=0 min_length=length min_start_index=max_length=max_start_index=0 while ei<=length : if(eimax_length : max_length=curr_length max_start_index=si ei+=1 si=ei minWord=inp[min_start_index : min_start_index+min_length] maxWord=inp[max_start_index : max_length] print("Minimum length word: ",minWord) print("Maximum length word: ",maxWord) a="GeeksforGeeks A Computer Science portal for Geeks" minMaxLengthWords(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : String := "GeeksforGeeks A Computer Science portal for Geeks" ; minMaxLengthWords(a); operation minMaxLengthWords(inp : OclAny) pre: true post: true activity: var length : int := (inp)->size() ; var si : OclAny := 0; var ei : int := 0 ; var min_length : int := length ; min_start_index := min_start_index(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name max_length)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name max_start_index)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; while (ei->compareTo(length)) <= 0 do ( if ((ei->compareTo(length)) < 0) & (inp[ei+1] /= " ") then ( ei := ei + 1 ) else ( var curr_length : double := ei - si ; if (curr_length->compareTo(min_length)) < 0 then ( min_length := curr_length ; var min_start_index : OclAny := si ) else skip ; if (curr_length->compareTo(max_length)) > 0 then ( var max_length : OclAny := curr_length ; var max_start_index : OclAny := si ) else skip ; ei := ei + 1 ; si := ei )) ; var minWord : OclAny := inp.subrange(min_start_index+1, min_start_index + min_length) ; var maxWord : OclAny := inp.subrange(max_start_index+1, max_length) ; execute ("Minimum length word: ")->display() ; execute ("Maximum length word: ")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) t=n i=0 k={} while i0 : if t in k : print(k[t],end=" ") t=t-1 else : print() break i=i+1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : int := n ; var i : int := 0 ; var k : OclAny := Set{} ; while (i->compareTo(n)) < 0 do ( k[l[i+1]+1] := l[i+1] ; while t > 0 do ( if (k)->includes(t) then ( execute (k[t+1])->display() ; t := t - 1 ) else ( execute (->display() ; break )) ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout def input(): return stdin.buffer.readline() def mi(): return map(int,input().split()) def li(): return list(map(int,input().split())) n=int(input()) s=li() a=max(s) sm=sum(s) if 2*a-sm<=0 and sm % 2==0 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := li() ; var a : OclAny := (s)->max() ; var sm : OclAny := (s)->sum() ; if 2 * a - sm <= 0 & sm mod 2 = 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); operation input() : OclAny pre: true post: true activity: return stdin.buffer.readLine(); operation mi() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation li() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) a=list(map(int,input().split(" "))) a.sort() ans=0 for i in range(0,n): if a[i]<=i+1 : ans=i+1 print(ans+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1]->compareTo(i + 1)) <= 0 then ( ans := i + 1 ) else skip) ; execute (ans + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in[0]*int(input()): a,b,c,d,e,f,g,h=map(float,input().split()) print(['NO','YES'][abs((a-c)*(f-h)-(e-g)*(b-d))<1e-10]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; var e : OclAny := null; var f : OclAny := null; var g : OclAny := null; var h : OclAny := null; Sequence{a,b,c,d,e,f,g,h} := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; execute (Sequence{'NO'}->union(Sequence{ 'YES' })->select(((a - c) * (f - h) - (e - g) * (b - d))->abs() < ("1e-10")->toReal()))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) x=[i for i in range(n,0,-1)] for i in range(n): x[-arr[i]]=i+1 for i in range(1,n+1): arr=[] while len(x)>0 and x[0]<=i : arr.append(len(x)) x.pop(0) print(' '.join(map(str,arr))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : Sequence := Integer.subrange(0 + 1, n)->reverse()->select(i | true)->collect(i | (i)) ; for i : Integer.subrange(0, n-1) do ( x->reverse()->at(-(-arr[i+1])) := i + 1) ; for i : Integer.subrange(1, n + 1-1) do ( arr := Sequence{} ; while (x)->size() > 0 & (x->first()->compareTo(i)) <= 0 do ( execute (((x)->size()) : arr) ; x := x->excludingAt(0+1)) ; execute (StringLib.sumStringsWithSeparator(((arr)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) s=sorted(l,reverse=True) d=set() i=0 for x in l : d.add(x) while s[i]in d : print(s[i],end=' ') i+=1 if i==n : break print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Sequence := l->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var d : Set := Set{}->union(()) ; var i : int := 0 ; for x : l do ( execute ((x) : d) ; while (d)->includes(s[i+1]) do ( execute (s[i+1])->display() ; i := i + 1 ; if i = n then ( break ) else skip) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) t=n i=0 k={} while i0 : if t in k : print(k[t],end=" ") t=t-1 else : print() break i=i+1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : int := n ; var i : int := 0 ; var k : OclAny := Set{} ; while (i->compareTo(n)) < 0 do ( k[l[i+1]+1] := l[i+1] ; while t > 0 do ( if (k)->includes(t) then ( execute (k[t+1])->display() ; t := t - 1 ) else ( execute (->display() ; break )) ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) score=list(map(int,input().split(' '))) score.sort() sums=0 for i in range(m): if score[i]<=0 : sums+=abs(score[i]) print(sums) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var score : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; score := score->sort() ; var sums : int := 0 ; for i : Integer.subrange(0, m-1) do ( if score[i+1] <= 0 then ( sums := sums + (score[i+1])->abs() ) else skip) ; execute (sums)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) t=n i=0 k={} while i0 : if t in k : print(k[t],end=" ") t=t-1 else : print() break i=i+1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var t : int := n ; var i : int := 0 ; var k : OclAny := Set{} ; while (i->compareTo(n)) < 0 do ( k[l[i+1]+1] := l[i+1] ; while t > 0 do ( if (k)->includes(t) then ( execute (k[t+1])->display() ; t := t - 1 ) else ( execute (->display() ; break )) ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x=input() y=input() x,y=x[: :-1],y[: :-1] n=len(x) m=len(y) for i in range(m): if(y[i]=='1'): break for j in range(i,n): if(x[j]=='1'): break print(j-i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : String := (OclFile["System.in"]).readLine() ; var y : String := (OclFile["System.in"]).readLine() ; Sequence{x,y} := Sequence{x(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))),y(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))} ; var n : int := (x)->size() ; var m : int := (y)->size() ; for i : Integer.subrange(0, m-1) do ( if (y[i+1] = '1') then ( break ) else skip) ; for j : Integer.subrange(i, n-1) do ( if (x[j+1] = '1') then ( break ) else skip) ; execute (j - i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): x=input() y=input() l=y[: :-1].index('1') r=x[: :-1].index('1',l,len(x)) print(r-l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : String := (OclFile["System.in"]).readLine() ; var y : String := (OclFile["System.in"]).readLine() ; var l : OclAny := y(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->indexOf('1') - 1 ; var r : OclAny := x(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->indexOf('1', l, (x)->size()) - 1 ; execute (r - l)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): x,y=input(),input() pos=y[: :-1].find('1') if pos!=0 : p=x[:-pos][: :-1].find('1') else : p=x[: :-1].find('1') print(p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{(OclFile["System.in"]).readLine(),(OclFile["System.in"]).readLine()} ; var pos : OclAny := y(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->indexOf('1') - 1 ; if pos /= 0 then ( var p : OclAny := x.subrange(1,-pos)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->indexOf('1') - 1 ) else ( p := x(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->indexOf('1') - 1 ) ; execute (p)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): times=int(input()) for _ in range(times): data1=input() data2=input() size1,size2=len(data1),len(data2) least=0 ans=0 for i in range(size2-1,-1,-1): if data2[i]=='1' : break else : least+=1 for j in range(size1-1-least,-1,-1): if data1[j]=='1' : break else : ans+=1 print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var times : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, times-1) do ( var data1 : String := (OclFile["System.in"]).readLine() ; var data2 : String := (OclFile["System.in"]).readLine() ; var size1 : OclAny := null; var size2 : OclAny := null; Sequence{size1,size2} := Sequence{(data1)->size(),(data2)->size()} ; var least : int := 0 ; var ans : int := 0 ; for i : Integer.subrange(-1 + 1, size2 - 1)->reverse() do ( if data2[i+1] = '1' then ( break ) else ( least := least + 1 )) ; for j : Integer.subrange(-1 + 1, size1 - 1 - least)->reverse() do ( if data1[j+1] = '1' then ( break ) else ( ans := ans + 1 )) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline for _ in range(int(input())): x=input()[:-1][: :-1] a=len(x) y=input()[:-1][: :-1] d=y.find('1') if d>=a-1 : print(0) else : c=0 for i in x[d :]: if i!='1' : c+=1 else : break print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := input()->front()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var a : int := (x)->size() ; var y : OclAny := input()->front()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var d : int := y->indexOf('1') - 1 ; if (d->compareTo(a - 1)) >= 0 then ( execute (0)->display() ) else ( var c : int := 0 ; for i : x.subrange(d+1) do ( if i /= '1' then ( c := c + 1 ) else ( break )) ; execute (c)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from decimal import Decimal def is_parallel(x1,y1,x2,y2,x3,y3,x4,y4): d1x=x2-x1 d1y=y2-y1 d2x=x4-x3 d2y=y4-y3 return d1x*d2y==d1y*d2x def main(): n=int(sys.stdin.readline().strip()) for _ in range(n): data=sys.stdin.readline().strip().split(' ') x1=Decimal(data[0]) y1=Decimal(data[1]) x2=Decimal(data[2]) y2=Decimal(data[3]) x3=Decimal(data[4]) y3=Decimal(data[5]) x4=Decimal(data[6]) y4=Decimal(data[7]) if is_parallel(x1,y1,x2,y2,x3,y3,x4,y4): print('YES') else : print('NO') if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation is_parallel(x1 : OclAny, y1 : OclAny, x2 : OclAny, y2 : OclAny, x3 : OclAny, y3 : OclAny, x4 : OclAny, y4 : OclAny) : OclAny pre: true post: true activity: var d1x : double := x2 - x1 ; var d1y : double := y2 - y1 ; var d2x : double := x4 - x3 ; var d2y : double := y4 - y3 ; return d1x * d2y = d1y * d2x; operation main() pre: true post: true activity: var n : int := ("" + ((sys.stdin.readLine()->trim())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var data : OclAny := sys.stdin.readLine()->trim().split(' ') ; x1 := Decimal(data->first()) ; y1 := Decimal(data[1+1]) ; x2 := Decimal(data[2+1]) ; y2 := Decimal(data[3+1]) ; x3 := Decimal(data[4+1]) ; y3 := Decimal(data[5+1]) ; x4 := Decimal(data[6+1]) ; y4 := Decimal(data[7+1]) ; if is_parallel(x1, y1, x2, y2, x3, y3, x4, y4) then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n=int(input()) s=input() sc=Counter(s).most_common() ans=1 for i,j in sc : ans=ans*(j+1)% 1000000007 print(ans-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var sc : OclAny := Counter(s).most_common() ; var ans : int := 1 ; for _tuple : sc do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); ans := ans * (j + 1) mod 1000000007) ; execute (ans - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() count=[0]*26 for i in s : count[ord(i)-ord("a")]+=1 mod=10**9+7 ans=1 for i in count : ans*=(i+1) ans %=mod print(ans-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for i : s->characters() do ( count[(i)->char2byte() - ("a")->char2byte()+1] := count[(i)->char2byte() - ("a")->char2byte()+1] + 1) ; var mod : double := (10)->pow(9) + 7 ; var ans : int := 1 ; for i : count do ( ans := ans * (i + 1) ; ans := ans mod mod) ; execute (ans - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() d=dict() ans=1 for i in range(n): if s[i]not in d : d[s[i]]=1 else : d[s[i]]+=1 ld=list(d.values()) for i in range(len(ld)): if ld[i]==1 : ans*=2 else : ans*=ld[i]+1 print((ans-1)%(10**9+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var d : Map := (arguments ( )) ; var ans : int := 1 ; for i : Integer.subrange(0, n-1) do ( if (d)->excludes(s[i+1]) then ( d[s[i+1]+1] := 1 ) else ( d[s[i+1]+1] := d[s[i+1]+1] + 1 )) ; var ld : Sequence := (d.values()) ; for i : Integer.subrange(0, (ld)->size()-1) do ( if ld[i+1] = 1 then ( ans := ans * 2 ) else ( ans := ans * ld[i+1] + 1 )) ; execute ((ans - 1) mod ((10)->pow(9) + 7))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import reduce N=int(input()) DIV=10**9+7 S={chr(i): 0 for i in range(ord('a'),ord('z')+1)} for c in input(): S[c]+=1 print(reduce(lambda acc,n : acc*(n+1)% DIV,S.values(),1)-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var DIV : double := (10)->pow(9) + 7 ; var S : Map := Integer.subrange(('a')->char2byte(), ('z')->char2byte() + 1-1)->select(i | true)->collect(i | Map{(i)->byte2char() |-> 0})->unionAll() ; for c : (OclFile["System.in"]).readLine() do ( S[c+1] := S[c+1] + 1) ; execute (reduce(lambda acc : OclAny, n : OclAny in (acc * (n + 1) mod DIV), S.values(), 1) - 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,input().split()) P=list(map(int,input().split())) C=list(map(int,input().split())) lim=60 nex=[[0]*N for _ in range(lim)] val=[[0]*N for _ in range(lim)] cnd=[[0]*N for _ in range(lim)] for i in range(N): nex[0][i]=P[i]-1 val[0][i]=C[i] cnd[0][i]=C[i] for d in range(lim-1): for i in range(N): nex[d+1][i]=nex[d][nex[d][i]] val[d+1][i]=val[d][i]+val[d][nex[d][i]] cnd[d+1][i]=max(cnd[d][i],val[d][i]+cnd[d][nex[d][i]]) res=-10**9 for i in range(N): sum_=0 offset=i for d in reversed(range(lim)): if K & 1<collect( _x | (OclType["int"])->apply(_x) ) ; var P : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var C : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lim : int := 60 ; var nex : Sequence := Integer.subrange(0, lim-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, N))) ; var val : Sequence := Integer.subrange(0, lim-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, N))) ; var cnd : Sequence := Integer.subrange(0, lim-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, N))) ; for i : Integer.subrange(0, N-1) do ( nex->first()[i+1] := P[i+1] - 1 ; val->first()[i+1] := C[i+1] ; cnd->first()[i+1] := C[i+1]) ; for d : Integer.subrange(0, lim - 1-1) do ( for i : Integer.subrange(0, N-1) do ( nex[d + 1+1][i+1] := nex[d+1][nex[d+1][i+1]+1] ; val[d + 1+1][i+1] := val[d+1][i+1] + val[d+1][nex[d+1][i+1]+1] ; cnd[d + 1+1][i+1] := Set{cnd[d+1][i+1], val[d+1][i+1] + cnd[d+1][nex[d+1][i+1]+1]}->max())) ; var res : double := (-10)->pow(9) ; for i : Integer.subrange(0, N-1) do ( var sum_ : int := 0 ; var offset : OclAny := i ; for d : (Integer.subrange(0, lim-1))->reverse() do ( if MathLib.bitwiseAnd(K, 1 * (2->pow(d))) then ( res := Set{res, sum_ + cnd[d+1][offset+1]}->max() ; sum_ := sum_ + val[d+1][offset+1] ; offset := nex[d+1][offset+1] ) else skip)) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) S=input() Q=10**9+7 A=[1]*26 ANS=[0]*26 for i in range(N): s=ord(S[i])-ord("a") ans=1 for j in range(26): if j!=s : ans*=A[j] ans %=Q ANS[j]=(ANS[j]+ans)% Q A[s]+=1 print(sum(ANS)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : String := (OclFile["System.in"]).readLine() ; var Q : double := (10)->pow(9) + 7 ; var A : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, 26) ; var ANS : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for i : Integer.subrange(0, N-1) do ( var s : double := (S[i+1])->char2byte() - ("a")->char2byte() ; var ans : int := 1 ; for j : Integer.subrange(0, 26-1) do ( if j /= s then ( ans := ans * A[j+1] ; ans := ans mod Q ) else skip) ; ANS[j+1] := (ANS[j+1] + ans) mod Q ; A[s+1] := A[s+1] + 1) ; execute ((ANS)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import queue class node : def __init__(self,val,level): self.val=val self.level=level def minOperations(x,y): visit=set() q=queue.Queue() n=node(x,0) q.put(n) while(not q.empty()): t=q.get() if(t.val==y): return t.level visit.add(t.val) if(t.val*2==y or t.val-1==y): return t.level+1 if(t.val*2 not in visit): n.val=t.val*2 n.level=t.level+1 q.put(n) if(t.val-1>=0 and t.val-1 not in visit): n.val=t.val-1 n.level=t.level+1 q.put(n) if __name__=='__main__' : x=4 y=7 print(minOperations(x,y)) ------------------------------------------------------------ OCL File: --------- class node { static operation newnode() : node pre: true post: node->exists( _x | result = _x ); attribute val : OclAny := val; attribute level : OclAny := level; operation initialise(val : OclAny,level : OclAny) : node pre: true post: true activity: self.val := val ; self.level := level; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( x := 4 ; y := 7 ; execute (minOperations(x, y))->display() ) else skip; operation minOperations(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var visit : Set := Set{}->union(()) ; var q : OclAny := queue.Queue() ; var n : node := (node.newnode()).initialise(x, 0) ; q.put(n) ; while (not(q.empty())) do ( var t : OclAny := q.get() ; if (t.val = y) then ( return t.level ) else skip ; execute ((t.val) : visit) ; if (t.val * 2 = y or t.val - 1 = y) then ( return t.level + 1 ) else skip ; if ((visit)->excludes(t.val * 2)) then ( n.val := t.val * 2 ; n.level := t.level + 1 ; q.put(n) ) else skip ; if (t.val - 1 >= 0 & (visit)->excludes(t.val - 1)) then ( n.val := t.val - 1 ; n.level := t.level + 1 ; q.put(n) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) if(a==b and a!=c)or(b==c and b!=a)or(c==a and c!=b): print('Yes') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a = b & a /= c) or (b = c & b /= a) or (c = a & c /= b) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): A,B,C=map(int,input().split()) s=set([A,B,C]) if len(s)==2 : return "Yes" return "No" if __name__=='__main__' : print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( execute (main())->display() ) else skip; operation main() : OclAny pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{A,B,C} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Set := Set{}->union((Sequence{A}->union(Sequence{B}->union(Sequence{ C })))) ; if (s)->size() = 2 then ( return "Yes" ) else skip ; return "No"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def s_in(): return input() def n_in(): return int(input()) def l_in(): return list(map(int,input().split())) class Interval(): def __init__(self,li): self.li=li self.n=len(li) self.sum_li=[li[0]] for i in range(1,self.n): self.sum_li.append(self.sum_li[i-1]+li[i]) def sum(self,a,b=None): if b is None : return self.sum(0,a) res=self.sum_li[min(self.n-1,b-1)] if a>0 : res-=self.sum_li[a-1] return res a,b,c=l_in() if a==b and b==c : print("No") elif a==b or a==c or b==c : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class Interval { static operation newInterval() : Interval pre: true post: Interval->exists( _x | result = _x ); attribute li : OclAny := li; attribute n : int := (li)->size(); attribute sum_li : Sequence := Sequence{ li->first() }; operation initialise(li : OclAny) : pre: true post: true activity: self.li := li ; self.n := (li)->size() ; self.sum_li := Sequence{ li->first() } ; for i : Integer.subrange(1, self.n-1) do ((expr (atom (name self)) (trailer . (name sum_li)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name self)) (trailer . (name sum_li) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ]))) + (expr (atom (name li)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))) ))))); return self; operation sum(a : OclAny,b : OclAny) : OclAny pre: true post: true activity: if b <>= null then ( return self.sum(0, a) ) else skip ; var res : OclAny := self.sum_li[Set{self.n - 1, b - 1}->min()+1] ; if a > 0 then ( res := res - self.sum_li[a - 1+1] ) else skip ; return res; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var c : OclAny := null; Sequence{a,b,c} := l_in() ; if a = b & b = c then ( execute ("No")->display() ) else (if a = b or a = c or b = c then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) ; operation s_in() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation n_in() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation l_in() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find(dividend,divisor,start,end): if(start>end): return(0,dividend); mid=start+(end-start)//2 ; n=dividend-divisor*mid ; if(n>divisor): start=mid+1 ; elif(n<0): end=mid-1 ; else : if(n==divisor): mid+=1 ; n=0 ; return(mid,n); return find(dividend,divisor,start,end); def divide(dividend,divisor): return find(dividend,divisor,1,dividend); if __name__=="__main__" : dividend=10 ; divisor=3 ; ans=divide(dividend,divisor); print(ans[0],",",ans[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( dividend := 10; divisor := 3; ; var ans : OclAny := divide(dividend, divisor); ; execute (ans->first())->display() ) else skip; operation find(dividend : OclAny, divisor : OclAny, start : OclAny, end : OclAny) pre: true post: true activity: if ((start->compareTo(end)) > 0) then ( return Sequence{0, dividend}; ) else skip ; var mid : OclAny := start + (end - start) div 2; ; var n : double := dividend - divisor * mid; ; if ((n->compareTo(divisor)) > 0) then ( start := mid + 1; ) else (if (n < 0) then ( end := mid - 1; ) else ( if (n = divisor) then ( mid := mid + 1; ; n := 0; ) else skip ; return Sequence{mid, n}; ) ) ; return find(dividend, divisor, start, end);; operation divide(dividend : OclAny, divisor : OclAny) pre: true post: true activity: return find(dividend, divisor, 1, dividend);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input().split(" ") a1,a2,a3=int(a[0]),int(a[1]),int(a[2]) ans="No" if a1!=a2 and(a1==a3 or a2==a3): ans="Yes" if a1!=a3 and(a1==a2 or a2==a3): ans="Yes" if a2!=a3 and(a1==a2 or a1==a3): ans="Yes" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := input().split(" ") ; var a1 : OclAny := null; var a2 : OclAny := null; var a3 : OclAny := null; Sequence{a1,a2,a3} := Sequence{("" + ((a->first())))->toInteger(),("" + ((a[1+1])))->toInteger(),("" + ((a[2+1])))->toInteger()} ; var ans : String := "No" ; if a1 /= a2 & (a1 = a3 or a2 = a3) then ( ans := "Yes" ) else skip ; if a1 /= a3 & (a1 = a2 or a2 = a3) then ( ans := "Yes" ) else skip ; if a2 /= a3 & (a1 = a2 or a1 = a3) then ( ans := "Yes" ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A=list(map(int,input().split())) ans='Yes' if(len(A)-1)==len(set(A))else 'No' print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : String := if ((A)->size() - 1) = (Set{}->union((A)))->size() then 'Yes' else 'No' endif ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cards=int(input()) nums=[int(x)for x in input().split()] s,d,=0,0 l,r=0,cards-1 state='s' while(l<=r): if state=='s' : if nums[l]>nums[r]: s+=nums[l] l+=1 else : s+=nums[r] r-=1 state='d' else : if nums[l]>nums[r]: d+=nums[l] l+=1 else : d+=nums[r] r-=1 state='s' print(f"{s}{d}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cards : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nums : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var s : OclAny := null; (declareIfNecessary (test (logical_test (comparison (expr (atom (name d)))))) ,) Sequence{s,(testlist_star_expr (test (logical_test (comparison (expr (atom (name d)))))) ,)} := Sequence{0,0} ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,cards - 1} ; var state : String := 's' ; while ((l->compareTo(r)) <= 0) do ( if state = 's' then ( if (nums[l+1]->compareTo(nums[r+1])) > 0 then ( s := s + nums[l+1] ; l := l + 1 ) else ( s := s + nums[r+1] ; r := r - 1 ) ; state := 'd' ) else ( if (nums[l+1]->compareTo(nums[r+1])) > 0 then ( d := d + nums[l+1] ; l := l + 1 ) else ( d := d + nums[r+1] ; r := r - 1 ) ; state := 's' )) ; execute (StringLib.formattedString("{s}{d}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) b=list(map(int,input().split())) cnt1=0 cnt2=0 for i in range(n): if i % 2==0 : cnt1+=max(b[0],b[-1]) b.pop(b.index(max(b[0],b[-1]))) else : cnt2+=max(b[0],b[-1]) b.pop(b.index(max(b[0],b[-1]))) print(cnt1,cnt2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt1 : int := 0 ; var cnt2 : int := 0 ; for i : Integer.subrange(0, n-1) do ( if i mod 2 = 0 then ( cnt1 := cnt1 + Set{b->first(), b->last()}->max() ; b := b->excludingAt(b->indexOf(Set{b->first(), b->last()}->max()) - 1+1) ) else ( cnt2 := cnt2 + Set{b->first(), b->last()}->max() ; b := b->excludingAt(b->indexOf(Set{b->first(), b->last()}->max()) - 1+1) )) ; execute (cnt1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- col_vo=int(input()) Ser=0 Dim=0 flag=True lis=[int(x)for x in list(input().split())] while(len(lis)): if flag : if lis[-1]>lis[0]: Ser+=lis[-1] lis.pop(-1) else : Ser+=lis[0] lis.pop(0) else : if lis[-1]>lis[0]: Dim+=lis[-1] lis.pop(-1) else : Dim+=lis[0] lis.pop(0) flag=not flag print(Ser,Dim) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var col_vo : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var Ser : int := 0 ; var Dim : int := 0 ; var flag : boolean := true ; var lis : Sequence := (input().split())->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; while ((lis)->size()) do ( if flag then ( if (lis->last()->compareTo(lis->first())) > 0 then ( Ser := Ser + lis->last() ; lis := lis->excludingAt(-1+1) ) else ( Ser := Ser + lis->first() ; lis := lis->excludingAt(0+1) ) ) else ( if (lis->last()->compareTo(lis->first())) > 0 then ( Dim := Dim + lis->last() ; lis := lis->excludingAt(-1+1) ) else ( Dim := Dim + lis->first() ; lis := lis->excludingAt(0+1) ) ) ; flag := not(flag)) ; execute (Ser)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys mINF=-float('inf') n,k=map(int,sys.stdin.readline().rstrip("\n").split()) p=[int(s)-1 for s in sys.stdin.readline().rstrip("\n").split()] c=[int(s)for s in sys.stdin.readline().rstrip("\n").split()] loop=[] for i in range(n): loop_costs=[] lc=0 np=i while True : lc+=c[p[np]] loop_costs.append(lc) np=p[np] if np==i : break loop.append(loop_costs) ans=mINF for i in range(n): loop_i=loop[i] if len(loop_i)0 : q,mod=divmod(k,len(loop_i)) if mod==0 : q=q-1 modmax=max(loop_i) else : modmax=max(loop_i[: mod]) ans=max(ans,loop_i[-1]*q+modmax) else : ans=max(ans,max(loop_i)) else : ans=max(ans,max(loop_i[: k])) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var mINF : double := -("" + (('inf')))->toReal() ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (sys.stdin.readLine().rstrip("\n").split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p : Sequence := sys.stdin.readLine().rstrip("\n").split()->select(s | true)->collect(s | (("" + ((s)))->toInteger() - 1)) ; var c : Sequence := sys.stdin.readLine().rstrip("\n").split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; var loop : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var loop_costs : Sequence := Sequence{} ; var lc : int := 0 ; var np : OclAny := i ; while true do ( lc := lc + c[p[np+1]+1] ; execute ((lc) : loop_costs) ; np := p[np+1] ; if np = i then ( break ) else skip) ; execute ((loop_costs) : loop)) ; var ans : OclAny := mINF ; for i : Integer.subrange(0, n-1) do ( var loop_i : OclAny := loop[i+1] ; if ((loop_i)->size()->compareTo(k)) < 0 then ( if loop_i->last() > 0 then ( var q : OclAny := null; var mod : OclAny := null; Sequence{q,mod} := Sequence{(k div (loop_i)->size()), (k mod (loop_i)->size())} ; if mod = 0 then ( var q : double := q - 1 ; var modmax : OclAny := (loop_i)->max() ) else ( modmax := (loop_i.subrange(1,mod))->max() ) ; ans := Set{ans, loop_i->last() * q + modmax}->max() ) else ( ans := Set{ans, (loop_i)->max()}->max() ) ) else ( ans := Set{ans, (loop_i.subrange(1,k))->max()}->max() )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cards=int(input()) nums=[int(x)for x in input().split()] s,d,=0,0 l,r=0,cards-1 state='s' while(l<=r): if state=='s' : if nums[l]>nums[r]: s+=nums[l] l+=1 else : s+=nums[r] r-=1 state='d' else : if nums[l]>nums[r]: d+=nums[l] l+=1 else : d+=nums[r] r-=1 state='s' print(f"{s}{d}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cards : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nums : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var s : OclAny := null; (declareIfNecessary (test (logical_test (comparison (expr (atom (name d)))))) ,) Sequence{s,(testlist_star_expr (test (logical_test (comparison (expr (atom (name d)))))) ,)} := Sequence{0,0} ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,cards - 1} ; var state : String := 's' ; while ((l->compareTo(r)) <= 0) do ( if state = 's' then ( if (nums[l+1]->compareTo(nums[r+1])) > 0 then ( s := s + nums[l+1] ; l := l + 1 ) else ( s := s + nums[r+1] ; r := r - 1 ) ; state := 'd' ) else ( if (nums[l+1]->compareTo(nums[r+1])) > 0 then ( d := d + nums[l+1] ; l := l + 1 ) else ( d := d + nums[r+1] ; r := r - 1 ) ; state := 's' )) ; execute (StringLib.formattedString("{s}{d}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cards=int(input()) nums=[int(x)for x in input().split()] s,d,=0,0 l,r=0,cards-1 state='s' while(l<=r): if state=='s' : if nums[l]>nums[r]: s+=nums[l] l+=1 else : s+=nums[r] r-=1 state='d' else : if nums[l]>nums[r]: d+=nums[l] l+=1 else : d+=nums[r] r-=1 state='s' print(f"{s}{d}") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cards : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nums : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var s : OclAny := null; (declareIfNecessary (test (logical_test (comparison (expr (atom (name d)))))) ,) Sequence{s,(testlist_star_expr (test (logical_test (comparison (expr (atom (name d)))))) ,)} := Sequence{0,0} ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,cards - 1} ; var state : String := 's' ; while ((l->compareTo(r)) <= 0) do ( if state = 's' then ( if (nums[l+1]->compareTo(nums[r+1])) > 0 then ( s := s + nums[l+1] ; l := l + 1 ) else ( s := s + nums[r+1] ; r := r - 1 ) ; state := 'd' ) else ( if (nums[l+1]->compareTo(nums[r+1])) > 0 then ( d := d + nums[l+1] ; l := l + 1 ) else ( d := d + nums[r+1] ; r := r - 1 ) ; state := 's' )) ; execute (StringLib.formattedString("{s}{d}"))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findLength(string,n): current_sum=0 max_sum=0 for i in range(n): current_sum+=(1 if string[i]=='0' else-1) if current_sum<0 : current_sum=0 max_sum=max(current_sum,max_sum) return max_sum if max_sum else 0 s="11000010001" n=11 print(findLength(s,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : String := "11000010001" ; n := 11 ; execute (findLength(s, n))->display(); operation findLength(string : OclAny, n : OclAny) : OclAny pre: true post: true activity: var current_sum : int := 0 ; var max_sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( current_sum := current_sum + (if string[i+1] = '0' then 1 else -1 endif) ; if current_sum < 0 then ( current_sum := 0 ) else skip ; max_sum := Set{current_sum, max_sum}->max()) ; return if max_sum then max_sum else 0 endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib,sys def compute(): sys.setrecursionlimit(3000) NUMBER=10**25 ans=count_ways(NUMBER,NUMBER.bit_length()-1,2) return str(ans) @ eulerlib.memoize def count_ways(number,exponent,repetitions): if exponent<0 : return 1 if number==0 else 0 else : result=count_ways(number,exponent-1,2) power=1<0 and power<=number (comparison (expr (atom (number (integer 0))))))) and (logical_test (comparison (comparison (comparison (expr (atom (name power)))) <= (comparison (expr (atom (name number))))) < (comparison (expr (atom (name upper)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name result)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name count_ways)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name number))) - (expr (atom (name power)))))))) , (argument (test (logical_test (comparison (expr (atom (name exponent))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name repetitions))) - (expr (atom (number (integer 1)))))))))) ))))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name result))))))))))))))))) ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: sys.setrecursionlimit(3000) ; var NUMBER : double := (10)->pow(25) ; var ans : OclAny := count_ways(NUMBER, NUMBER.bit_length() - 1, 2) ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def equal(x,y): return math.fabs(x-y)<=10**(-10) def spam(_x1,_y1,_x2,_y2): if _x1>_x2 : return _x1,_y1,_x2,_y2 else : return _x2,_y2,_x1,_y1 for i in range(int(input())): x1,y1,x2,y2,x3,y3,x4,y4=list(map(float,input().split())) b1=(x1-x2,y1-y2) b2=(x3-x4,y3-y4) p=0 if b2[0]!=0 else 1 q=1 if b2[0]!=0 else 0 t=b1[p]/b2[p] if equal(b1[q],b2[q]*t): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; var x3 : OclAny := null; var y3 : OclAny := null; var x4 : OclAny := null; var y4 : OclAny := null; Sequence{x1,y1,x2,y2,x3,y3,x4,y4} := ((input().split())->collect( _x | (OclType["double"])->apply(_x) )) ; var b1 : OclAny := Sequence{x1 - x2, y1 - y2} ; var b2 : OclAny := Sequence{x3 - x4, y3 - y4} ; var p : int := if b2->first() /= 0 then 0 else 1 endif ; var q : int := if b2->first() /= 0 then 1 else 0 endif ; var t : double := b1[p+1] / b2[p+1] ; if equal(b1[q+1], b2[q+1] * t) then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); operation equal(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return ((x - y)->abs()->compareTo((10)->pow((-10)))) <= 0; operation spam(_x1 : OclAny, _y1 : OclAny, _x2 : OclAny, _y2 : OclAny) : OclAny pre: true post: true activity: if (_x1->compareTo(_x2)) > 0 then ( return _x1, _y1, _x2, _y2 ) else ( return _x2, _y2, _x1, _y1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) c=0 if n % 2!=0 and n!=1 : print(1) elif n==1 : print(3) else : for m in range(1,1001): t=n*m+1 for _ in range(2,t): if t % _==0 : c=1 print(m) break if c==1 : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := 0 ; if n mod 2 /= 0 & n /= 1 then ( execute (1)->display() ) else (if n = 1 then ( execute (3)->display() ) else ( for m : Integer.subrange(1, 1001-1) do ( var t : double := n * m + 1 ; for _anon : Integer.subrange(2, t-1) do ( if t mod _anon = 0 then ( c := 1 ; execute (m)->display() ; break ) else skip) ; if c = 1 then ( break ) else skip) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n==1 : print(3) elif n==2 : print(4) elif n>2 : print(n-2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( execute (3)->display() ) else (if n = 2 then ( execute (4)->display() ) else (if n > 2 then ( execute (n - 2)->display() ) else skip ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) if n==1 : return 3 if n==2 : return 4 if n % 2==1 : return 1 i=3 while idisplay(); operation main() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 1 then ( return 3 ) else skip ; if n = 2 then ( return 4 ) else skip ; if n mod 2 = 1 then ( return 1 ) else skip ; var i : int := 3 ; while (i->compareTo(n)) < 0 do ( var s : double := (i)->pow(2) - 1 ; if s / n = s div n then ( return s div n ) else skip ; i := i + 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def is_prime(I): if I==1 : return False if I==2 : return True else : for i in range(2,int(I**0.5)+1): if I % i==0 : return False return True n=int(input()) i=1 while True : if is_prime((i*n)+1)!=True : print(i) break i=i+1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var i : int := 1 ; while true do ( if is_prime((i * n) + 1) /= true then ( execute (i)->display() ; break ) else skip ; i := i + 1); operation is_prime(I : OclAny) : OclAny pre: true post: true activity: if I = 1 then ( return false ) else skip ; if I = 2 then ( return true ) else ( for i : Integer.subrange(2, ("" + (((I)->pow(0.5))))->toInteger() + 1-1) do ( if I mod i = 0 then ( return false ) else skip) ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isprime(n): if n==1 : return 0 i=2 while itoInteger() ; var m : int := 1 ; while true do ( var d : double := n * m + 1 ; if isprime(d) = 0 then ( execute (m)->display() ; break ) else skip ; m := m + 1); operation isprime(n : OclAny) : OclAny pre: true post: true activity: if n = 1 then ( return 0 ) else skip ; var i : int := 2 ; while (i->compareTo(n)) < 0 do ( if n mod i = 0 then ( return 0 ) else skip ; i := i + 1) ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numbers=list(map(int,input().split())) arr=list(map(int,input().split())) sum=0 min=float('inf') for i in range(0,len(arr)): if arr[i]<0 and numbers[1]>0 : arr[i]*=-1 numbers[1]-=1 sum+=arr[i] min=min if mincollect( _x | (OclType["int"])->apply(_x) )) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sum : int := 0 ; var min : double := ("" + (('inf')))->toReal() ; for i : Integer.subrange(0, (arr)->size()-1) do ( if arr[i+1] < 0 & numbers[1+1] > 0 then ( arr[i+1] := arr[i+1] * -1 ; numbers[1+1] := numbers[1+1] - 1 ) else skip ; sum := sum + arr[i+1] ; min := if (min->compareTo(arr[i+1])) < 0 then min else arr[i+1] endif) ; if numbers[1+1] mod 2 /= 0 then ( sum := (sum - min) + (min * -1) ) else skip ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline read=sys.stdin.read n,k,=map(int,readline().split()) *p,=map(int,readline().split()) *c,=map(int,readline().split()) for i in range(n): p[i]-=1 ans=[-1<<31]*n pos=list(range(n)) val=[0]*n for i in range(min(k,n)): for j in range(n): pos[j]=p[pos[j]] val[j]+=c[pos[j]] if ans[j]>=1 for i in range(n): for j in range(n): pos[j]=p[pos[j]] val[j]+=c[pos[j]] if ans[j]collect( _x | (OclType["int"])->apply(_x) ) ; (testlist_star_expr (star_expr * (expr (atom (name p)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name p)))) ,)} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (testlist_star_expr (star_expr * (expr (atom (name c)))) ,) Sequence{(testlist_star_expr (star_expr * (expr (atom (name c)))) ,)} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, n-1) do ( p[i+1] := p[i+1] - 1) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 * (2->pow(31)) }, n) ; var pos : Sequence := (Integer.subrange(0, n-1)) ; var val : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, Set{k, n}->min()-1) do ( for j : Integer.subrange(0, n-1) do ( pos[j+1] := p[pos[j+1]+1] ; val[j+1] := val[j+1] + c[pos[j+1]+1] ; if (ans[j+1]->compareTo(val[j+1])) < 0 then ( ans[j+1] := val[j+1] ) else skip)) ; pos := (Integer.subrange(0, n-1)) ; val := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var pp : Sequence := p ; var vv : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (c[p[j+1]+1])) ; k := k - n ; if k < 0 then ( execute ((ans)->max())->display() ; exit() ) else skip ; for i : Integer.subrange(0, 31-1) do ( var vvv : Sequence := vv ; var ppp : Sequence := pp ; if MathLib.bitwiseAnd(k, 1) then ( for j : Integer.subrange(0, n-1) do ( val[j+1] := val[j+1] + vvv[pos[j+1]+1] ; pos[j+1] := pp[pos[j+1]+1]) ) else skip ; for j : Integer.subrange(0, n-1) do ( vvv[j+1] := vvv[j+1] + vv[pp[j+1]+1]) ; for j : Integer.subrange(0, n-1) do ( ppp[j+1] := pp[pp[j+1]+1]) ; vv := vvv ; pp := ppp ; k := k div (2->pow(1))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( pos[j+1] := p[pos[j+1]+1] ; val[j+1] := val[j+1] + c[pos[j+1]+1] ; if (ans[j+1]->compareTo(val[j+1])) < 0 then ( ans[j+1] := val[j+1] ) else skip)) ; execute ((ans)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,changes=map(int,input().split()) incomes=sorted(list(map(int,input().split()))) for index,income in enumerate(incomes): if income<0 and changes>0 : incomes[index]*=-1 changes-=1 else : break incomes=sorted(incomes) changes %=2 if changes==1 : incomes[0]*=-1 print(sum(incomes)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var changes : OclAny := null; Sequence{n,changes} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var incomes : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; for _tuple : Integer.subrange(1, (incomes)->size())->collect( _indx | Sequence{_indx-1, (incomes)->at(_indx)} ) do (var _indx : int := 1; var index : OclAny := _tuple->at(_indx); _indx := _indx + 1; var income : OclAny := _tuple->at(_indx); if income < 0 & changes > 0 then ( incomes[index+1] := incomes[index+1] * -1 ; changes := changes - 1 ) else ( break )) ; incomes := incomes->sort() ; changes := changes mod 2 ; if changes = 1 then ( incomes->first() := incomes->first() * -1 ) else skip ; execute ((incomes)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,changes=map(int,input().split()) incomes=sorted(list(map(int,input().split()))) diff=0 i=0 while i0 : diff+=(incomes[i]*-2) changes-=1 i+=1 if changes % 2==1 : diff-=abs(sorted(incomes,key=lambda l : abs(l))[0])*2 print(sum(incomes)+diff) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var changes : OclAny := null; Sequence{n,changes} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var incomes : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var diff : int := 0 ; var i : int := 0 ; while (i->compareTo((incomes)->size())) < 0 & incomes[i+1] <= 0 & changes > 0 do ( diff := diff + (incomes[i+1] * -2) ; changes := changes - 1 ; i := i + 1) ; if changes mod 2 = 1 then ( diff := diff - (sorted(incomes, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name l)))) : (test (logical_test (comparison (expr (atom (name abs)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name l)))))))) ))))))))))->first())->abs() * 2 ) else skip ; execute ((incomes)->sum() + diff)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numbers=list(map(int,input().split())) arr=list(map(int,input().split())) arr.sort() sum=0 for i in range(0,len(arr)): if arr[i]<0 and numbers[1]!=0 : arr[i]=arr[i]*-1 numbers[1]-=1 else : break arr.sort() numbers[1]=numbers[1]% 2 arr[0]=arr[0]*-1 if numbers[1]==1 else arr[0] for i in arr : sum+=i print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var numbers : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := arr->sort() ; var sum : int := 0 ; for i : Integer.subrange(0, (arr)->size()-1) do ( if arr[i+1] < 0 & numbers[1+1] /= 0 then ( arr[i+1] := arr[i+1] * -1 ; numbers[1+1] := numbers[1+1] - 1 ) else ( break )) ; arr := arr->sort() ; numbers[1+1] := numbers[1+1] mod 2 ; arr->first() := if numbers[1+1] = 1 then arr->first() * -1 else arr->first() endif ; for i : arr do ( sum := sum + i) ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import Fraction def sroap(x1,y1,x2,y2): if x2-x1==0 : return float("inf") else : return Fraction(y2-y1,x2-x1) N=int(input()) for n in range(N): Ax,Ay,Bx,By,Cx,Cy,Dx,Dy=map(lambda x : round(x*10**5),(map(float,input().split()))) if sroap(Ax,Ay,Bx,By)==sroap(Cx,Cy,Dx,Dy): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for n : Integer.subrange(0, N-1) do ( var Ax : OclAny := null; var Ay : OclAny := null; var Bx : OclAny := null; var By : OclAny := null; var Cx : OclAny := null; var Cy : OclAny := null; var Dx : OclAny := null; var Dy : OclAny := null; Sequence{Ax,Ay,Bx,By,Cx,Cy,Dx,Dy} := (((input().split())->collect( _x | (OclType["double"])->apply(_x) )))->collect( _x | (lambda x : OclAny in ((x * (10)->pow(5))->round()))->apply(_x) ) ; if sroap(Ax, Ay, Bx, By) = sroap(Cx, Cy, Dx, Dy) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); operation sroap(x1 : OclAny, y1 : OclAny, x2 : OclAny, y2 : OclAny) : OclAny pre: true post: true activity: if x2 - x1 = 0 then ( return ("" + (("inf")))->toReal() ) else ( return Fraction(y2 - y1, x2 - x1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- numbers=list(map(int,input().split())) arr=list(map(int,input().split())) arr.sort() sum=0 min=float('inf') for i in range(0,len(arr)): if arr[i]<0 and numbers[1]>0 : arr[i]*=-1 numbers[1]-=1 sum+=arr[i] min=min if mincollect( _x | (OclType["int"])->apply(_x) )) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := arr->sort() ; var sum : int := 0 ; var min : double := ("" + (('inf')))->toReal() ; for i : Integer.subrange(0, (arr)->size()-1) do ( if arr[i+1] < 0 & numbers[1+1] > 0 then ( arr[i+1] := arr[i+1] * -1 ; numbers[1+1] := numbers[1+1] - 1 ) else skip ; sum := sum + arr[i+1] ; min := if (min->compareTo(arr[i+1])) < 0 then min else arr[i+1] endif) ; if numbers[1+1] mod 2 /= 0 then ( sum := (sum - min) + (min * -1) ) else skip ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math ; def deleteFromStart(num,n): d=(math.log10(num)+1); rev_new_num=0 ; i=0 ; while(num!=0): digit=num % 10 ; num=int(num/10); if(i!=(int(d)-n)): rev_new_num=((rev_new_num*10)+digit); i+=1 ; new_num=0 ; i=0 ; while(rev_new_num!=0): new_num=((new_num*10)+(rev_new_num % 10)); rev_new_num=int(rev_new_num/10); i+=1 ; return new_num ; def deleteFromEnd(num,n): rev_new_num=0 ; i=1 ; while(num!=0): digit=num % 10 ; num=int(num/10); if(i!=n): rev_new_num=((rev_new_num*10)+digit); i+=1 ; new_num=0 ; i=0 ; while(rev_new_num!=0): new_num=((new_num*10)+(rev_new_num % 10)); rev_new_num=int(rev_new_num/10); i+=1 ; return new_num ; num=1234 ; print("Number:",num); n=3 ; print("Digit to be deleted:",n); print("Number after",n,"digit deleted from starting:",deleteFromStart(num,n)); print("Number after",n,"digit deleted from ending:",deleteFromEnd(num,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; ; skip ; skip ; num := 1234; ; execute ("Number:")->display(); ; n := 3; ; execute ("Digit to be deleted:")->display(); ; execute ("Number after")->display(); ; execute ("Number after")->display();; operation deleteFromStart(num : OclAny, n : OclAny) pre: true post: true activity: var d : double := ((num)->log10() + 1); ; var rev_new_num : int := 0; ; var i : int := 0; ; while (num /= 0) do ( var digit : int := num mod 10; ; num := ("" + ((num / 10)))->toInteger(); ; if (i /= (("" + ((d)))->toInteger() - n)) then ( rev_new_num := ((rev_new_num * 10) + digit); ) else skip ; i := i + 1;) ; var new_num : int := 0; ; i := 0; ; while (rev_new_num /= 0) do ( new_num := ((new_num * 10) + (rev_new_num mod 10)); ; rev_new_num := ("" + ((rev_new_num / 10)))->toInteger(); ; i := i + 1;) ; return new_num;; operation deleteFromEnd(num : OclAny, n : OclAny) pre: true post: true activity: rev_new_num := 0; ; i := 1; ; while (num /= 0) do ( digit := num mod 10; ; num := ("" + ((num / 10)))->toInteger(); ; if (i /= n) then ( rev_new_num := ((rev_new_num * 10) + digit); ) else skip ; i := i + 1;) ; new_num := 0; ; i := 0; ; while (rev_new_num /= 0) do ( new_num := ((new_num * 10) + (rev_new_num mod 10)); ; rev_new_num := ("" + ((rev_new_num / 10)))->toInteger(); ; i := i + 1;) ; return new_num;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairs(arr1,arr2,m,n,x): count=0 for i in range(m): for j in range(n): if arr1[i]+arr2[j]==x : count=count+1 return count arr1=[1,3,5,7] arr2=[2,3,5,8] m=len(arr1) n=len(arr2) x=10 print("Count=",countPairs(arr1,arr2,m,n,x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr1 := Sequence{1}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 7 }))) ; arr2 := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 8 }))) ; m := (arr1)->size() ; n := (arr2)->size() ; x := 10 ; execute ("Count=")->display(); operation countPairs(arr1 : OclAny, arr2 : OclAny, m : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, m-1) do ( for j : Integer.subrange(0, n-1) do ( if arr1[i+1] + arr2[j+1] = x then ( count := count + 1 ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def largestPower(x,P): res=0 while(x): x=int(x/P) res+=x return res def sumOfDivisblePowers(L,R,P): return largestPower(R,P)-largestPower(L-1,P) L=1 R=10 P=2 print(sumOfDivisblePowers(L,R,P)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; L := 1 ; R := 10 ; P := 2 ; execute (sumOfDivisblePowers(L, R, P))->display(); operation largestPower(x : OclAny, P : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; while (x) do ( x := ("" + ((x / P)))->toInteger() ; res := res + x) ; return res; operation sumOfDivisblePowers(L : OclAny, R : OclAny, P : OclAny) : OclAny pre: true post: true activity: return largestPower(R, P) - largestPower(L - 1, P); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfDivisblePowers(L,R,P): res=0 for i in range(L,R+1): x=i while(x % P==0): res+=1 x/=P return res L=1 R=10 P=2 print(sumOfDivisblePowers(L,R,P)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; L := 1 ; R := 10 ; P := 2 ; execute (sumOfDivisblePowers(L, R, P))->display(); operation sumOfDivisblePowers(L : OclAny, R : OclAny, P : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; for i : Integer.subrange(L, R + 1-1) do ( var x : OclAny := i ; while (x mod P = 0) do ( res := res + 1 ; x := x / P)) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import exit,setrecursionlimit,stderr from functools import reduce from itertools import* from collections import* from bisect import bisect def read(): return int(input()) def reads(): return[int(x)for x in input().split()] ls=[n for n in range(2,30001)if n % 2==0 or n % 3==0] def gcd(x,y): return x if y==0 else gcd(y,x % y) def check(N,ans): assert len(ans)==len(set(ans))==N S=sum(ans) assert reduce(gcd,ans)==1 assert all(gcd(S-a,a)!=1 for a in ans) def solve(N): if N==3 : return[2,5,63] q,r=divmod(N,8) t=q*8 ans=ls[: t] if r % 2==1 : ans+=[ls[t+3]] r//=2 if r==1 : ans+=[ls[t],ls[t+2]] elif r==2 : ans+=ls[t : t+3]+[ls[t+5]] elif r==3 : ans+=ls[t : t+3]+ls[t+4 : t+7] return ans N=read() print(' '.join(str(a)for a in solve(N))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var ls : Sequence := Integer.subrange(2, 30001-1)->select(n | n mod 2 = 0 or n mod 3 = 0)->collect(n | (n)) ; skip ; skip ; skip ; N := read() ; execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name solve)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name N)))))))) ))))))))), ' '))->display(); operation read() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation reads() : OclAny pre: true post: true activity: return input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation gcd(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return if y = 0 then x else gcd(y, x mod y) endif; operation check(N : OclAny, ans : OclAny) pre: true post: true activity: assert (ans)->size() = (Set{}->union((ans)))->size() & ((Set{}->union((ans)))->size() == N) do "assertion failed" ; var S : OclAny := (ans)->sum() ; assert reduce(gcd, ans) = 1 do "assertion failed" ; assert ((argument (test (logical_test (comparison (comparison (expr (atom (name gcd)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name S))) - (expr (atom (name a)))))))) , (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))) != (comparison (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name ans))))))))->forAll( _x | _x = true ) do "assertion failed"; operation solve(N : OclAny) : OclAny pre: true post: true activity: if N = 3 then ( return Sequence{2}->union(Sequence{5}->union(Sequence{ 63 })) ) else skip ; var q : OclAny := null; var r : OclAny := null; Sequence{q,r} := Sequence{(N div 8), (N mod 8)} ; var t : double := q * 8 ; ans := ls.subrange(1,t) ; if r mod 2 = 1 then ( ans := ans + Sequence{ ls[t + 3+1] } ) else skip ; r := r div 2 ; if r = 1 then ( ans := ans + Sequence{ls[t+1]}->union(Sequence{ ls[t + 2+1] }) ) else (if r = 2 then ( ans := ans + ls.subrange(t+1, t + 3)->union(Sequence{ ls[t + 5+1] }) ) else (if r = 3 then ( ans := ans + ls.subrange(t+1, t + 3) + ls.subrange(t + 4+1, t + 7) ) else skip ) ) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) div,mod=divmod(n,4) ans=[] if n==3 : print(2,5,63) exit() if n==4 : print(2,5,20,63) exit() if n==5 : print(2,5,20,30,63) exit() cnt=0 i=0 for i in range(div): cnt+=15 ans.append(6*i+2) ans.append(6*i+3) ans.append(6*i+4) ans.append(6*i+6) if mod==1 : i+=1 cnt+=2 ans.append(6*i+2) if mod==2 : i+=1 cnt+=5 ans.append(6*i+2) ans.append(6*i+3) if mod==3 : i+=1 cnt+=9 ans.append(6*i+2) ans.append(6*i+3) ans.append(6*i+4) if cnt % 6==0 : pass if cnt % 6==2 : ans=ans[0 : 4]+ans[5 :]+[ans[-1]-ans[-1]% 6+6] if cnt % 6==3 : ans=ans[0 : 5]+ans[6 :]+[ans[-1]-ans[-1]% 6+6] if cnt % 6==5 : ans=ans[0 : 5]+ans[6 :]+[6*(ans[-1]//6)+4] print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var div : OclAny := null; var mod : OclAny := null; Sequence{div,mod} := Sequence{(n div 4), (n mod 4)} ; var ans : Sequence := Sequence{} ; if n = 3 then ( execute (2)->display() ; exit() ) else skip ; if n = 4 then ( execute (2)->display() ; exit() ) else skip ; if n = 5 then ( execute (2)->display() ; exit() ) else skip ; var cnt : int := 0 ; var i : int := 0 ; for i : Integer.subrange(0, div-1) do ( cnt := cnt + 15 ; execute ((6 * i + 2) : ans) ; execute ((6 * i + 3) : ans) ; execute ((6 * i + 4) : ans) ; execute ((6 * i + 6) : ans)) ; if mod = 1 then ( i := i + 1 ; cnt := cnt + 2 ; execute ((6 * i + 2) : ans) ) else skip ; if mod = 2 then ( i := i + 1 ; cnt := cnt + 5 ; execute ((6 * i + 2) : ans) ; execute ((6 * i + 3) : ans) ) else skip ; if mod = 3 then ( i := i + 1 ; cnt := cnt + 9 ; execute ((6 * i + 2) : ans) ; execute ((6 * i + 3) : ans) ; execute ((6 * i + 4) : ans) ) else skip ; if cnt mod 6 = 0 then ( skip ) else skip ; if cnt mod 6 = 2 then ( ans := ans.subrange(0+1, 4) + ans.subrange(5+1)->union(Sequence{ ans->last() - ans->last() mod 6 + 6 }) ) else skip ; if cnt mod 6 = 3 then ( ans := ans.subrange(0+1, 5) + ans.subrange(6+1)->union(Sequence{ ans->last() - ans->last() mod 6 + 6 }) ) else skip ; if cnt mod 6 = 5 then ( ans := ans.subrange(0+1, 5) + ans.subrange(6+1)->union(Sequence{ 6 * (ans->last() div 6) + 4 }) ) else skip ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=(int(T)for T in input().split()) Next=[int(T)-1 for T in input().split()] GetP=[int(T)for T in input().split()] Disp=-10**9 for TN in range(0,N): Now=Next[TN] Point=GetP[Now] MAXP=Point RoopC=1 RoopFlag=False for TK in range(1,K): Now=Next[Now] Point+=GetP[Now] RoopC+=1 MAXP=max(MAXP,Point) if Now==TN : RoopFlag=True break if RoopFlag and Point>0 : Omit=K-RoopC*(K//RoopC) PointO=0 MAXO=0 for TO in range(0,Omit): Now=Next[Now] PointO+=GetP[Now] MAXO=max(MAXO,PointO) Disp=max(Disp,max(Point*(K//RoopC)+MAXO,Point*((K//RoopC)-1)+MAXP)) else : Disp=max(Disp,MAXP) print(Disp) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name T)))))))) ))))))) (comp_for for (exprlist (expr (atom (name T)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var Next : Sequence := input().split()->select(T | true)->collect(T | (("" + ((T)))->toInteger() - 1)) ; var GetP : Sequence := input().split()->select(T | true)->collect(T | (("" + ((T)))->toInteger())) ; var Disp : double := (-10)->pow(9) ; for TN : Integer.subrange(0, N-1) do ( var Now : OclAny := Next[TN+1] ; var Point : OclAny := GetP[Now+1] ; var MAXP : OclAny := Point ; var RoopC : int := 1 ; var RoopFlag : boolean := false ; for TK : Integer.subrange(1, K-1) do ( Now := Next[Now+1] ; Point := Point + GetP[Now+1] ; RoopC := RoopC + 1 ; MAXP := Set{MAXP, Point}->max() ; if Now = TN then ( RoopFlag := true ; break ) else skip) ; if RoopFlag & Point > 0 then ( var Omit : double := K - RoopC * (K div RoopC) ; var PointO : int := 0 ; var MAXO : int := 0 ; for TO : Integer.subrange(0, Omit-1) do ( Now := Next[Now+1] ; PointO := PointO + GetP[Now+1] ; MAXO := Set{MAXO, PointO}->max()) ; Disp := Set{Disp, Set{Point * (K div RoopC) + MAXO, Point * ((K div RoopC) - 1) + MAXP}->max()}->max() ) else ( Disp := Set{Disp, MAXP}->max() )) ; execute (Disp)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[] cnt=0 ans="" s=0 if n>=6 : for j in range(2,30001): if j % 6==0 or j % 6==2 or j % 6==3 or j % 6==4 : a.append(j) cnt+=1 s+=j if cnt==n : if s % 6==0 : for i in range(n-1): ans+=str(a[i])+" " ans+=str(a[-1]) print(ans) elif s % 6==2 : a[4]=30000 for i in range(n-1): ans+=str(a[i])+" " ans+=str(a[-1]) print(ans) elif s % 6==3 : a[5]=30000 for i in range(n-1): ans+=str(a[i])+" " ans+=str(a[-1]) print(ans) else : a[5]=29998 for i in range(n-1): ans+=str(a[i])+" " ans+=str(a[-1]) print(ans) elif n==3 : print(str(2)+" "+str(5)+" "+str(63)) elif n==4 : print(str(2)+" "+str(5)+" "+str(20)+" "+str(63)) else : print(str(2)+" "+str(5)+" "+str(20)+" "+str(30)+" "+str(63)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; var cnt : int := 0 ; var ans : String := "" ; var s : int := 0 ; if n >= 6 then ( for j : Integer.subrange(2, 30001-1) do ( if j mod 6 = 0 or j mod 6 = 2 or j mod 6 = 3 or j mod 6 = 4 then ( execute ((j) : a) ; cnt := cnt + 1 ; s := s + j ; if cnt = n then ( if s mod 6 = 0 then ( for i : Integer.subrange(0, n - 1-1) do ( ans := ans + ("" + ((a[i+1]))) + " ") ; ans := ans + ("" + ((a->last()))) ; execute (ans)->display() ) else (if s mod 6 = 2 then ( a[4+1] := 30000 ; for i : Integer.subrange(0, n - 1-1) do ( ans := ans + ("" + ((a[i+1]))) + " ") ; ans := ans + ("" + ((a->last()))) ; execute (ans)->display() ) else (if s mod 6 = 3 then ( a[5+1] := 30000 ; for i : Integer.subrange(0, n - 1-1) do ( ans := ans + ("" + ((a[i+1]))) + " ") ; ans := ans + ("" + ((a->last()))) ; execute (ans)->display() ) else ( a[5+1] := 29998 ; for i : Integer.subrange(0, n - 1-1) do ( ans := ans + ("" + ((a[i+1]))) + " ") ; ans := ans + ("" + ((a->last()))) ; execute (ans)->display() ) ) ) ) else skip ) else skip) ) else (if n = 3 then ( execute (("" + ((2))) + " " + ("" + ((5))) + " " + ("" + ((63))))->display() ) else (if n = 4 then ( execute (("" + ((2))) + " " + ("" + ((5))) + " " + ("" + ((20))) + " " + ("" + ((63))))->display() ) else ( execute (("" + ((2))) + " " + ("" + ((5))) + " " + ("" + ((20))) + " " + ("" + ((30))) + " " + ("" + ((63))))->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys printn=lambda x : sys.stdout.write(x) inn=lambda : int(input()) inl=lambda : list(map(int,input().split())) inm=lambda : map(int,input().split()) DBG=True def ddprint(x): if DBG : print(x) n=inn() if n<=8 : a=[0,0,0,'2 5 63','2 5 20 63','2 3 4 6 9','2 3 4 6 9 12','2 3 4 6 8 9 10','2 3 4 6 8 9 10 12'] print(a[n]) exit() m=(n-1)//8 r=(n-1)% 8 b=['6 ','2 4 ','2 4 6 ','2 3 4 9 ','2 3 4 6 9 ','2 3 4 8 9 10 ','2 3 4 6 8 9 10 ','2 3 4 6 8 9 10 12 '] printn(b[r]) for i in range(1,m+1): p=12*i printn('{}{}{}{}{}{}{}{}'.format(p+2,p+3,p+4,p+6,p+8,p+9,p+10,p+12)) print('') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var printn : Function := lambda x : OclAny in ((OclFile["System.out"]).write(x)) ; var inn : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var inl : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var inm : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var DBG : boolean := true ; skip ; var n : OclAny := inn->apply() ; if n <= 8 then ( var a : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{'2 5 63'}->union(Sequence{'2 5 20 63'}->union(Sequence{'2 3 4 6 9'}->union(Sequence{'2 3 4 6 9 12'}->union(Sequence{'2 3 4 6 8 9 10'}->union(Sequence{ '2 3 4 6 8 9 10 12' })))))))) ; execute (a[n+1])->display() ; exit() ) else skip ; var m : int := (n - 1) div 8 ; var r : int := (n - 1) mod 8 ; var b : Sequence := Sequence{'6 '}->union(Sequence{'2 4 '}->union(Sequence{'2 4 6 '}->union(Sequence{'2 3 4 9 '}->union(Sequence{'2 3 4 6 9 '}->union(Sequence{'2 3 4 8 9 10 '}->union(Sequence{'2 3 4 6 8 9 10 '}->union(Sequence{ '2 3 4 6 8 9 10 12 ' }))))))) ; printn(b[r+1]) ; for i : Integer.subrange(1, m + 1-1) do ( var p : double := 12 * i ; printn(StringLib.interpolateStrings('{}{}{}{}{}{}{}{}', Sequence{p + 2, p + 3, p + 4, p + 6, p + 8, p + 9, p + 10, p + 12}))) ; execute ('')->display(); operation ddprint(x : OclAny) pre: true post: true activity: if DBG then ( execute (x)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num=int(input()) l=[] for i in range(num): lst=list(map(float,input().split())) x1,y1=lst[0],lst[1] x2,y2=lst[2],lst[3] x3,y3=lst[4],lst[5] x4,y4=lst[6],lst[7] d=(x2-x1)*(y4-y3)-(x4-x3)*(y2-y1) k=abs(d) if k<=1e-11 : l.append('YES') else : l.append('NO') for i in l : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, num-1) do ( var lst : Sequence := ((input().split())->collect( _x | (OclType["double"])->apply(_x) )) ; var x1 : OclAny := null; var y1 : OclAny := null; Sequence{x1,y1} := Sequence{lst->first(),lst[1+1]} ; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x2,y2} := Sequence{lst[2+1],lst[3+1]} ; var x3 : OclAny := null; var y3 : OclAny := null; Sequence{x3,y3} := Sequence{lst[4+1],lst[5+1]} ; var x4 : OclAny := null; var y4 : OclAny := null; Sequence{x4,y4} := Sequence{lst[6+1],lst[7+1]} ; var d : double := (x2 - x1) * (y4 - y3) - (x4 - x3) * (y2 - y1) ; var k : double := (d)->abs() ; if k <= ("1e-11")->toReal() then ( execute (('YES') : l) ) else ( execute (('NO') : l) )) ; for i : l do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): while b!=0 : a,b=b,a % b return a n=int(input()) ans=[0]*n k=0 i=2 while ktoInteger() ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var k : int := 0 ; var i : int := 2 ; while (k->compareTo(n - 1)) < 0 do ( if i mod 2 = 0 or i mod 3 = 0 then ( ans[k+1] := i ; k := k + 1 ) else skip ; i := i + 1) ; var x : OclAny := (ans)->sum() ; ans->last() := 30000 + x div 6 * 6 - x ; while gcd(ans->last(), x) = 1 do ( ans->last() := ans->last() - 6) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: while b /= 0 do ( Sequence{a,b} := Sequence{b,a mod b}) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): SET_SIZE=12 def catalan(n): return eulerlib.binomial(n*2,n)//(n+1) ans=sum(eulerlib.binomial(SET_SIZE,i*2)*(eulerlib.binomial(i*2,i)//2-catalan(i))for i in range(2,SET_SIZE//2+1)) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var SET_SIZE : int := 12 ; skip ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (name eulerlib)) (trailer . (name binomial) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name SET_SIZE))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom (number (integer 2)))))))))) )))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name eulerlib)) (trailer . (name binomial) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) // (expr (atom (number (integer 2))))) - (expr (atom (name catalan)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (expr (expr (atom (name SET_SIZE))) // (expr (atom (number (integer 2))))) + (expr (atom (number (integer 1)))))))))) )))))))))->sum() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSubseq(arr,n): um={i : 0 for i in range(8)} count=1 for i in range(n): um[arr[i]]+=1 for key,values in um.items(): if(values>0): count*=values return count if __name__=='__main__' : arr=[4,7,6,7] n=len(arr) print("Count=",countSubseq(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{4}->union(Sequence{7}->union(Sequence{6}->union(Sequence{ 7 }))) ; n := (arr)->size() ; execute ("Count=")->display() ) else skip; operation countSubseq(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var um : Map := Integer.subrange(0, 8-1)->select(i | true)->collect(i | Map{i |-> 0})->unionAll() ; var count : int := 1 ; for i : Integer.subrange(0, n-1) do ( um[arr[i+1]+1] := um[arr[i+1]+1] + 1) ; for _tuple : um->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var values : OclAny := _tuple->at(_indx); if (values > 0) then ( count := count * values ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def firstDigit(n): while n>=10 : n=n/10 ; return int(n) def lastDigit(n): return(n % 10) n=98562 ; print(firstDigit(n),end=" ") print(lastDigit(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 98562; ; execute (firstDigit(n))->display() ; execute (lastDigit(n))->display(); operation firstDigit(n : OclAny) : OclAny pre: true post: true activity: while n >= 10 do ( n := n / 10;) ; return ("" + ((n)))->toInteger(); operation lastDigit(n : OclAny) : OclAny pre: true post: true activity: return (n mod 10); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPowerOfFour(n): if(n==0): return False while(n!=1): if(n % 4!=0): return False n=n//4 return True test_no=64 if(isPowerOfFour(64)): print(test_no,'is a power of 4') else : print(test_no,'is not a power of 4') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var test_no : int := 64 ; if (isPowerOfFour(64)) then ( execute (test_no)->display() ) else ( execute (test_no)->display() ); operation isPowerOfFour(n : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return false ) else skip ; while (n /= 1) do ( if (n mod 4 /= 0) then ( return false ) else skip ; n := n div 4) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPowerOfFour(n): count=0 if(n and(not(n &(n-1)))): while(n>1): n>>=1 count+=1 if(count % 2==0): return True else : return False test_no=64 if(isPowerOfFour(64)): print(test_no,'is a power of 4') else : print(test_no,'is not a power of 4') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var test_no : int := 64 ; if (isPowerOfFour(64)) then ( execute (test_no)->display() ) else ( execute (test_no)->display() ); operation isPowerOfFour(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; if (n & (not((MathLib.bitwiseAnd(n, (n - 1)))))) then ( while (n > 1) do ( n := n div (2->pow(1)) ; count := count + 1) ; if (count mod 2 = 0) then ( return true ) else ( return false ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPowerOfFour(n): return(n!=0 and((n &(n-1))==0)and not(n & 0xAAAAAAAA)); test_no=64 ; if(isPowerOfFour(test_no)): print(test_no,"is a power of 4"); else : print(test_no,"is not a power of 4"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var test_no : int := 64; ; if (isPowerOfFour(test_no)) then ( execute (test_no)->display(); ) else ( execute (test_no)->display(); ); operation isPowerOfFour(n : OclAny) pre: true post: true activity: return (n /= 0 & ((MathLib.bitwiseAnd(n, (n - 1))) = 0) & not((MathLib.bitwiseAnd(n, 0xAAAAAAAA))));; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def recursiveFun(n): if(n==1): return "int" return "gcd(int,"+recursiveFun(n-1)+")" if __name__=='__main__' : n=5 print(recursiveFun(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 5 ; execute (recursiveFun(n))->display() ) else skip; operation recursiveFun(n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( return "int" ) else skip ; return "gcd(int," + recursiveFun(n - 1) + ")"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import defaultdict from queue import deque readline=sys.stdin.buffer.readline from collections import Counter def geta(fn=lambda s : s.decode()): return map(fn,readline().split()) def gete(fn=lambda s : s.decode()): return fn(readline().rstrip()) def accumurate(l): ret=[0]*len(l) ret[0]=l[0] for i in range(1,len(l)): ret[i]=ret[i-1]+l[i] return ret def main(): n,k=geta(int) p=[0]+list(geta(int)) c=[0]+list(geta(int)) inf=1<<32 used=[False]*(n+1) ans=-inf for i in range(1,n+1): if used[i]: continue else : used[i]=True c_loop=[] j=p[i] c_loop+=[c[j]] while j!=i : used[j]=True j=p[j] c_loop+=[c[j]] n_loop=len(c_loop) cs_loop=accumurate(c_loop+c_loop) tot_loop=cs_loop[n_loop-1] _jmax=min(k,n_loop) for _i in range(n_loop): for _j in range(1,_jmax+1): _tmp=cs_loop[_j+_i]-cs_loop[_i] if tot_loop>0 and k>_j : _tmp+=(k-_j)//n_loop*tot_loop if ans<_tmp : ans=_tmp print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var readline : OclAny := sys.stdin.buffer.readline ; skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation geta(fn : OclAny) : OclAny pre: true post: true activity: if fn->oclIsUndefined() then fn := lambda s : OclAny in (s.decode()) else skip; return (readline().split())->collect( _x | (fn)->apply(_x) ); operation gete(fn : OclAny) : OclAny pre: true post: true activity: if fn->oclIsUndefined() then fn := lambda s : OclAny in (s.decode()) else skip; return fn(readline().rstrip()); operation accumurate(l : OclAny) : OclAny pre: true post: true activity: var ret : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (l)->size()) ; ret->first() := l->first() ; for i : Integer.subrange(1, (l)->size()-1) do ( ret[i+1] := ret[i - 1+1] + l[i+1]) ; return ret; operation main() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := geta(OclType["int"]) ; var p : Sequence := Sequence{ 0 }->union((geta(OclType["int"]))) ; var c : Sequence := Sequence{ 0 }->union((geta(OclType["int"]))) ; var Math_PINFINITY : int := 1 * (2->pow(32)) ; var used : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (n + 1)) ; var ans : double := -Math_PINFINITY ; for i : Integer.subrange(1, n + 1-1) do ( if used[i+1] then ( continue ) else ( used[i+1] := true ) ; var c_loop : Sequence := Sequence{} ; var j : OclAny := p[i+1] ; c_loop := c_loop + Sequence{ c[j+1] } ; while j /= i do ( used[j+1] := true ; j := p[j+1] ; c_loop := c_loop + Sequence{ c[j+1] }) ; var n_loop : int := (c_loop)->size() ; var cs_loop : OclAny := accumurate(c_loop->union(c_loop)) ; var tot_loop : OclAny := cs_loop[n_loop - 1+1] ; var _jmax : OclAny := Set{k, n_loop}->min() ; for _i : Integer.subrange(0, n_loop-1) do ( for _j : Integer.subrange(1, _jmax + 1-1) do ( var _tmp : double := cs_loop[_j + _i+1] - cs_loop[_i+1] ; if tot_loop > 0 & (k->compareTo(_j)) > 0 then ( _tmp := _tmp + (k - _j) div n_loop * tot_loop ) else skip ; if (ans->compareTo(_tmp)) < 0 then ( ans := _tmp ) else skip))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) lst=[int(x)for x in input().split()]; lst.append(m); lst.insert(0,0) time=[lst[i+1]-lst[i]for i in range(0,len(lst)-1)] ji=0 for k in range(0,len(time),2): ji+=time[k] ou=0 for k in range(1,len(time),2): ou+=time[k] ji0=0 answ=max(ji,ou) for i in range(len(time)): if i % 2==0 and time[i]>1 : ji-=time[i]; ji0+=time[i]; ji1=ou answ=max(answ,(ji0)-1+ji1) elif i % 2==0 and time[i]==1 : ji-=1 ; ji0+=1 ; ji1=ou elif i % 2!=0 and time[i]>1 : ou-=time[i]; ou1=ji answ=max(answ,ji0+1+ou) else : ou-=1 ; ou1=ji print(answ) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lst : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); execute ((m) : lst); lst := lst.insertAt(0+1, 0) ; var time : Sequence := Integer.subrange(0, (lst)->size() - 1-1)->select(i | true)->collect(i | (lst[i + 1+1] - lst[i+1])) ; var ji : int := 0 ; for k : Integer.subrange(0, (time)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( ji := ji + time[k+1]) ; var ou : int := 0 ; for k : Integer.subrange(1, (time)->size()-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( ou := ou + time[k+1]) ; var ji0 : int := 0 ; var answ : OclAny := Set{ji, ou}->max() ; for i : Integer.subrange(0, (time)->size()-1) do ( if i mod 2 = 0 & time[i+1] > 1 then ( ji := ji - time[i+1]; ji0 := ji0 + time[i+1]; var ji1 : int := ou ; answ := Set{answ, (ji0) - 1 + ji1}->max() ) else (if i mod 2 = 0 & time[i+1] = 1 then ( ji := ji - 1; ji0 := ji0 + 1; ji1 := ou ) else (if i mod 2 /= 0 & time[i+1] > 1 then ( ou := ou - time[i+1]; var ou1 : int := ji ; answ := Set{answ, ji0 + 1 + ou}->max() ) else ( ou := ou - 1; ou1 := ji ) ) ) ) ; execute (answ)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthXorFib(n,a,b): if n==0 : return a if n==1 : return b if n==2 : return a ^ b return nthXorFib(n % 3,a,b) a=1 b=2 n=10 print(nthXorFib(n,a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 1 ; b := 2 ; n := 10 ; execute (nthXorFib(n, a, b))->display(); operation nthXorFib(n : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if n = 0 then ( return a ) else skip ; if n = 1 then ( return b ) else skip ; if n = 2 then ( return MathLib.bitwiseXor(a, b) ) else skip ; return nthXorFib(n mod 3, a, b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) s=list(map(int,input().split())) s.append(m) t=(n+1)*[0] t[0]=s[0] for i in range(1,n+1): if i % 2==0 : t[i]=t[i-2]+(s[i]-s[i-1]) if i % 2!=0 : t[i]=t[i-1] ans=t[n] for i in range(0,n,2): ans=max(ans,t[i]-1+m-s[i]-t[n]+t[i]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((m) : s) ; var t : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; t->first() := s->first() ; for i : Integer.subrange(1, n + 1-1) do ( if i mod 2 = 0 then ( t[i+1] := t[i - 2+1] + (s[i+1] - s[i - 1+1]) ) else skip ; if i mod 2 /= 0 then ( t[i+1] := t[i - 1+1] ) else skip) ; var ans : OclAny := t[n+1] ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( ans := Set{ans, t[i+1] - 1 + m - s[i+1] - t[n+1] + t[i+1]}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,M=map(int,input().split()) a=list(map(int,input().split())) a.insert(0,0) a.append(M) x=[[0,0]for i in range(n+2)] for i in range(n+1,0,-1): a[i]-=a[i-1] x[i-1][i % 2]=x[i][i % 2]+a[i] x[i-1][not(i % 2)]=x[i][not(i % 2)] Max=x[0][1] for i in range(1,n+2): if a[i]!=1 : Sum=(x[0][1]-x[i-1][1])+x[i][0]+a[i]-1 Max=max(Max,Sum) print(Max) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var M : OclAny := null; Sequence{n,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a.insertAt(0+1, 0) ; execute ((M) : a) ; var x : Sequence := Integer.subrange(0, n + 2-1)->select(i | true)->collect(i | (Sequence{0}->union(Sequence{ 0 }))) ; for i : Integer.subrange(0 + 1, n + 1)->reverse() do ( a[i+1] := a[i+1] - a[i - 1+1] ; x[i - 1+1][i mod 2+1] := x[i+1][i mod 2+1] + a[i+1] ; x[i - 1+1]->select(not((i mod 2))) := x[i+1]->select(not((i mod 2)))) ; var Max : OclAny := x->first()[1+1] ; for i : Integer.subrange(1, n + 2-1) do ( if a[i+1] /= 1 then ( var Sum : double := (x->first()[1+1] - x[i - 1+1][1+1]) + x[i+1]->first() + a[i+1] - 1 ; Max := Set{Max, Sum}->max() ) else skip) ; execute (Max)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,M=map(int,input().split()) list1=list(map(int,input().split())) list2=list() list3=list() list3.append(0) s=0 gap1=-1 gap2=0 list2.append(list1[0]) for i in range(1,n): list2.append(list1[i]-list1[i-1]) list2.append(M-list1[n-1]) list2.reverse() if n % 2==0 : for u in range(0,n+1,2): s+=list2[u] gap2+=list2[1]-1-list2[0] if gap2>0 : list3.append(gap2) for q in range(2,n+1,2): gap1+=list2[q-1]-list2[q-2] if gap1>0 : list3.append(gap1) for r in range(3,n+1,2): gap2+=list2[r]-list2[r-1] if gap2>0 : list3.append(gap2) else : for k in range(1,n+2,2): s+=list2[k] gap3=list2[0]-1 gap4=list2[0]-1 if gap3>0 : list3.append(gap3) for v in range(2,n+1,2): gap3+=list2[v]-list2[v-1] if gap3>0 : list3.append(gap3) for t in range(3,n+1,2): gap4+=list2[t-1]-list2[t-2] m=max(list3) print(m+s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var M : OclAny := null; Sequence{n,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var list1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var list2 : Sequence := () ; var list3 : Sequence := () ; execute ((0) : list3) ; var s : int := 0 ; var gap1 : int := -1 ; var gap2 : int := 0 ; execute ((list1->first()) : list2) ; for i : Integer.subrange(1, n-1) do ( execute ((list1[i+1] - list1[i - 1+1]) : list2)) ; execute ((M - list1[n - 1+1]) : list2) ; list2 := list2->reverse() ; if n mod 2 = 0 then ( for u : Integer.subrange(0, n + 1-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( s := s + list2[u+1]) ; gap2 := gap2 + list2[1+1] - 1 - list2->first() ; if gap2 > 0 then ( execute ((gap2) : list3) ) else skip ; for q : Integer.subrange(2, n + 1-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( gap1 := gap1 + list2[q - 1+1] - list2[q - 2+1] ; if gap1 > 0 then ( execute ((gap1) : list3) ) else skip) ; for r : Integer.subrange(3, n + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( gap2 := gap2 + list2[r+1] - list2[r - 1+1] ; if gap2 > 0 then ( execute ((gap2) : list3) ) else skip) ) else ( for k : Integer.subrange(1, n + 2-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( s := s + list2[k+1]) ; var gap3 : double := list2->first() - 1 ; var gap4 : double := list2->first() - 1 ; if gap3 > 0 then ( execute ((gap3) : list3) ) else skip ; for v : Integer.subrange(2, n + 1-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( gap3 := gap3 + list2[v+1] - list2[v - 1+1] ; if gap3 > 0 then ( execute ((gap3) : list3) ) else skip) ; for t : Integer.subrange(3, n + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( gap4 := gap4 + list2[t - 1+1] - list2[t - 2+1]) ) ; var m : OclAny := (list3)->max() ; execute (m + s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) alist=list(map(int,input().split())) alist=[0]+alist+[m] n+=2 on,off=[0],[0] for i in range(1,n): if i % 2!=0 : on.append(alist[i]-alist[i-1]+on[i-1]) off.append(off[i-1]) else : on.append(on[i-1]) off.append(alist[i]-alist[i-1]+off[i-1]) time=on[-1] for i in range(0,n-1): if alist[i]+1collect( _x | (OclType["int"])->apply(_x) ) ; var alist : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; alist := Sequence{ 0 }->union(alist)->union(Sequence{ m }) ; n := n + 2 ; var on : OclAny := null; var off : OclAny := null; Sequence{on,off} := Sequence{Sequence{ 0 },Sequence{ 0 }} ; for i : Integer.subrange(1, n-1) do ( if i mod 2 /= 0 then ( execute ((alist[i+1] - alist[i - 1+1] + on[i - 1+1]) : on) ; execute ((off[i - 1+1]) : off) ) else ( execute ((on[i - 1+1]) : on) ; execute ((alist[i+1] - alist[i - 1+1] + off[i - 1+1]) : off) )) ; var time : OclAny := on->last() ; for i : Integer.subrange(0, n - 1-1) do ( if (alist[i+1] + 1->compareTo(alist[i + 1+1])) < 0 then ( if i mod 2 = 0 then ( time := Set{time, on[i + 1+1] + off->last() - off[i + 1+1] - 1}->max() ) else ( time := Set{time, on[i+1] + off->last() - off[i+1] - 1}->max() ) ) else skip) ; execute (time)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ss_3(t): s='' while t!=0 : s+=str(t % 3) t//=3 return s[: :-1] a,b=map(int,input().split()) if a==b and a==0 : print(0) else : a,b=ss_3(a),ss_3(b) n=max(len(a),len(b)) a=(n-len(a))*'0'+a b=(n-len(b))*'0'+b c='' for i in range(len(a)): if int(b[i])collect( _x | (OclType["int"])->apply(_x) ) ; if a = b & a = 0 then ( execute (0)->display() ) else ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{ss_3(a),ss_3(b)} ; var n : OclAny := Set{(a)->size(), (b)->size()}->max() ; var a : double := (n - (a)->size()) * '0' + a ; var b : double := (n - (b)->size()) * '0' + b ; var c : String := '' ; for i : Integer.subrange(0, (a)->size()-1) do ( if (("" + ((b[i+1])))->toInteger()->compareTo(("" + ((a[i+1])))->toInteger())) < 0 then ( c := c + ("" + ((("" + ((b[i+1])))->toInteger() + 3 - ("" + ((a[i+1])))->toInteger()))) ) else ( c := c + ("" + ((("" + ((b[i+1])))->toInteger() - ("" + ((a[i+1])))->toInteger()))) )) ; execute (("" + ((c, 3)))->toInteger())->display() ); operation ss var s : String := '' ; while t /= 0 do ( s := s + ("" + ((t mod 3))) ; t := t div 3) ; return s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))(t : OclAny) : OclAny pre: true post: true activity: var s : String := '' ; while t /= 0 do ( s := s + ("" + ((t mod 3))) ; t := t div 3) ; return s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline a,c=map(int,input().split()) x='' y='' while a : x+=str(a % 3) a//=3 while c : y+=str(c % 3) c//=3 n=max(len(x),len(y)) x+=(n-len(x))*'0' y+=(n-len(y))*'0' b=0 for i in range(n-1,-1,-1): b+=((int(y[i])-int(x[i])+3)% 3) b*=3 print(b//3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var a : OclAny := null; var c : OclAny := null; Sequence{a,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : String := '' ; var y : String := '' ; while a do ( x := x + ("" + ((a mod 3))) ; a := a div 3) ; while c do ( y := y + ("" + ((c mod 3))) ; c := c div 3) ; var n : OclAny := Set{(x)->size(), (y)->size()}->max() ; x := x + (n - (x)->size()) * '0' ; y := y + (n - (y)->size()) * '0' ; var b : int := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( b := b + ((("" + ((y[i+1])))->toInteger() - ("" + ((x[i+1])))->toInteger() + 3) mod 3) ; b := b * 3) ; execute (b div 3)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def decimal2ternary(n : int): result="" while n>0 : result=str(n % 3)+result n//=3 return result def ternary2decimal(t : str): result=0 t=t[: :-1] for i in range(len(t)): result+=(3**i)*int(t[i]) return result a,c=map(int,input().split()) a_ternary=decimal2ternary(a) c_ternary=decimal2ternary(c) if len(a_ternary)>len(c_ternary): c_ternary="0"*(len(a_ternary)-len(c_ternary))+c_ternary elif len(c_ternary)>len(a_ternary): a_ternary="0"*(len(c_ternary)-len(a_ternary))+a_ternary b="" for _a,_c in zip(a_ternary,c_ternary): if int(_a)<=int(_c): b+=str(int(_c)-int(_a)) else : b+=str(3+int(_c)-int(_a)) print(ternary2decimal(b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var a : OclAny := null; var c : OclAny := null; Sequence{a,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a_ternary : OclAny := decimal2ternary(a) ; var c_ternary : OclAny := decimal2ternary(c) ; if ((a_ternary)->size()->compareTo((c_ternary)->size())) > 0 then ( c_ternary := StringLib.nCopies("0", ((a_ternary)->size() - (c_ternary)->size())) + c_ternary ) else (if ((c_ternary)->size()->compareTo((a_ternary)->size())) > 0 then ( a_ternary := StringLib.nCopies("0", ((c_ternary)->size() - (a_ternary)->size())) + a_ternary ) else skip) ; var b : String := "" ; for _tuple : Integer.subrange(1, a_ternary->size())->collect( _indx | Sequence{a_ternary->at(_indx), c_ternary->at(_indx)} ) do (var _indx : int := 1; var _a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var _c : OclAny := _tuple->at(_indx); if (("" + ((_a)))->toInteger()->compareTo(("" + ((_c)))->toInteger())) <= 0 then ( b := b + ("" + ((("" + ((_c)))->toInteger() - ("" + ((_a)))->toInteger()))) ) else ( b := b + ("" + ((3 + ("" + ((_c)))->toInteger() - ("" + ((_a)))->toInteger()))) )) ; execute (ternary2decimal(b))->display(); operation decimal2ternary(n : int) : OclAny pre: true post: true activity: var result : String := "" ; while n > 0 do ( result := ("" + ((n mod 3))) + result ; n := n div 3) ; return result; operation ternary2decimal(t : String) : OclAny pre: true post: true activity: result := 0 ; var t : OclAny := t(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; for i : Integer.subrange(0, (t)->size()-1) do ( result := result + ((3)->pow(i)) * ("" + ((t[i+1])))->toInteger()) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def tor(num): list=[] while num>0 : list.insert(0,num % 3) num//=3 return list x,y=map(int,input().split()) x=tor(x) y=tor(y) out=[] sol=0 while len(x)!=len(y): if len(x)>len(y): y.insert(0,0) else : x.insert(0,0) for i in range(len(x)): if y[i]==0 : if x[i]==0 : out.append(0) elif x[i]==1 : out.append(2) elif x[i]==2 : out.append(1) elif y[i]==1 : if x[i]==0 : out.append(1) elif x[i]==1 : out.append(0) elif x[i]==2 : out.append(2) elif y[i]==2 : if x[i]==0 : out.append(2) elif x[i]==1 : out.append(1) elif x[i]==2 : out.append(0) Len=len(out)-1 for i in range(len(out)): sol+=(out[i]*pow(3,Len)) Len-=1 print(sol) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := tor(x) ; var y : OclAny := tor(y) ; var out : Sequence := Sequence{} ; var sol : int := 0 ; while (x)->size() /= (y)->size() do ( if ((x)->size()->compareTo((y)->size())) > 0 then ( y := y.insertAt(0+1, 0) ) else ( x := x.insertAt(0+1, 0) )) ; for i : Integer.subrange(0, (x)->size()-1) do ( if y[i+1] = 0 then ( if x[i+1] = 0 then ( execute ((0) : out) ) else (if x[i+1] = 1 then ( execute ((2) : out) ) else (if x[i+1] = 2 then ( execute ((1) : out) ) else skip ) ) ) else (if y[i+1] = 1 then ( if x[i+1] = 0 then ( execute ((1) : out) ) else (if x[i+1] = 1 then ( execute ((0) : out) ) else (if x[i+1] = 2 then ( execute ((2) : out) ) else skip ) ) ) else (if y[i+1] = 2 then ( if x[i+1] = 0 then ( execute ((2) : out) ) else (if x[i+1] = 1 then ( execute ((1) : out) ) else (if x[i+1] = 2 then ( execute ((0) : out) ) else skip ) ) ) else skip ) ) ) ; var Len : double := (out)->size() - 1 ; for i : Integer.subrange(0, (out)->size()-1) do ( sol := sol + (out[i+1] * (3)->pow(Len)) ; Len := Len - 1) ; execute (sol)->display(); operation tor(num : OclAny) : OclAny pre: true post: true activity: var OclType["Sequence"] : Sequence := Sequence{} ; while num > 0 do ( OclType["Sequence"] := OclType["Sequence"].insertAt(0+1, num mod 3) ; num := num div 3) ; return OclType["Sequence"]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import reduce a,c=map(int,input().split(' ')) def ff(x): return ff(x//3)+[x % 3]if x>0 else[] a=list(reversed(ff(a))) c=list(reversed(ff(c))) d=len(c)-len(a) a=a+[0]*max(0,d) c=c+[0]*max(0,-d) res=reduce(lambda s,x : 3*s+x,reversed([(3+ci-ai)% 3 for(ai,ci)in zip(a,c)]),0) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var c : OclAny := null; Sequence{a,c} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; var a : Sequence := ((ff(a))->reverse()) ; var c : Sequence := ((ff(c))->reverse()) ; var d : double := (c)->size() - (a)->size() ; a := a->union(MatrixLib.elementwiseMult(Sequence{ 0 }, Set{0, d}->max())) ; c := c->union(MatrixLib.elementwiseMult(Sequence{ 0 }, Set{0, -d}->max())) ; var res : OclAny := reduce(lambda s : OclAny, x : OclAny in (3 * s + x), (Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), c->at(_indx)} )->select(Sequence{ai, ci} | true)->collect(Sequence{ai, ci} | ((3 + ci - ai) mod 3)))->reverse(), 0) ; execute (res)->display(); operation ff(x : OclAny) : OclAny pre: true post: true activity: return if x > 0 then ff(x div 3)->union(Sequence{ x mod 3 }) else Sequence{} endif; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def solve(): n,k=map(int,input().split()) if k==1 : print('0'*(n-1)+'1') return z=((n-k)//2)+1 s=''.join(['0' if i % z==0 else '1' for i in range(n)]) print(s) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; solve(); operation solve() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if k = 1 then ( execute (StringLib.nCopies('0', (n - 1)) + '1')->display() ; return ) else skip ; var z : int := ((n - k) div 2) + 1 ; var s : String := StringLib.sumStringsWithSeparator((Integer.subrange(0, n-1)->select(i | true)->collect(i | (if i mod z = 0 then '0' else '1' endif))), '') ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(): n=int(sys.stdin.readline().strip('\n')) taro_score=0 hanako_score=0 for turn in range(n): animals=[animal for animal in sys.stdin.readline().strip('\n').split(' ')] if animals[0]==animals[1]: taro_score+=1 hanako_score+=1 elif max(animals[0],animals[1])==animals[0]: taro_score+=3 elif max(animals[0],animals[1])==animals[1]: hanako_score+=3 print('%d %d' %(taro_score,hanako_score)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + ((sys.stdin.readLine()->trim())))->toInteger() ; var taro_score : int := 0 ; var hanako_score : int := 0 ; for turn : Integer.subrange(0, n-1) do ( var animals : Sequence := sys.stdin.readLine()->trim().split(' ')->select(animal | true)->collect(animal | (animal)) ; if animals->first() = animals[1+1] then ( taro_score := taro_score + 1 ; hanako_score := hanako_score + 1 ) else (if Set{animals->first(), animals[1+1]}->max() = animals->first() then ( taro_score := taro_score + 3 ) else (if Set{animals->first(), animals[1+1]}->max() = animals[1+1] then ( hanako_score := hanako_score + 3 ) else skip ) ) ) ; execute (StringLib.format('%d %d',Sequence{taro_score, hanako_score}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def NumberOfSolutions(a,b,c,d): ans=0 for i in range(a,b+1): if d>=max(c,i+1): ans+=d-max(c,i+1)+1 return ans if __name__=="__main__" : a,b,c,d=2,3,3,4 print(NumberOfSolutions(a,b,c,d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{a,b,c,d} := Sequence{2,3,3,4} ; execute (NumberOfSolutions(a, b, c, d))->display() ) else skip; operation NumberOfSolutions(a : OclAny, b : OclAny, c : OclAny, d : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(a, b + 1-1) do ( if (d->compareTo(Set{c, i + 1}->max())) >= 0 then ( ans := ans + d - Set{c, i + 1}->max() + 1 ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) A=list(map(int,input().split())) a=A[0] b=A[1] x=0 for i in A[2 :]: x ^=i d={} def F(a,b,xor): if(a,b,xor)in d : return d[(a,b,xor)] if a & 1 ^ b & 1!=xor & 1 : return float("INF") if xor==0 : if a=a : print(-1) else : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := A->first() ; var b : OclAny := A[1+1] ; var x : int := 0 ; for i : A.subrange(2+1) do ( x := x xor i) ; var d : OclAny := Set{} ; skip ; var ans : OclAny := F(a, b, x) ; if (ans->compareTo(a)) >= 0 then ( execute (-1)->display() ) else ( execute (ans)->display() ); operation F(a : OclAny, b : OclAny, xor : OclAny) : OclAny pre: true post: true activity: if (d)->includes(Sequence{a, b, xor}) then ( return d[Sequence{a, b, xor}+1] ) else skip ; if MathLib.bitwiseXor(MathLib.bitwiseAnd(a, 1), MathLib.bitwiseAnd(b, 1)) /= MathLib.bitwiseAnd(xor, 1) then ( return ("" + (("INF")))->toReal() ) else skip ; if xor = 0 then ( if (a->compareTo(b)) < 0 then ( return ("" + (("INF")))->toReal() ) else ( return (a - b) div 2 ) ) else skip ; var c1 : double := 2 * F(a div 2, b div 2, xor div 2) ; var c2 : double := 2 * F((a - 1) div 2, (b + 1) div 2, xor div 2) + 1 ; var f : OclAny := Set{c1, c2}->min() ; d[Sequence{a, b, xor}+1] := f ; return f; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict mem=defaultdict(lambda : None) mem[(0,0,0)]=0 def dp(a,b,s): if mem[(a,b,s)]is not None : return mem[(a,b,s)] x=a & 1 y=b & 1 xor=s & 1 res=float("inf") if x ^ y!=xor : mem[(a,b,s)]=res return res else : res=2*dp(a>>1,b>>1,s>>1) if a>1 : pants=2*dp((a-1)>>1,(b+1)>>1,s>>1)+1 if pantstoInteger() ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; s := 0 ; for i : a.subrange(2+1) do ( s := s xor i) ; b := a[1+1] ; a := a->first() ; var ans : OclAny := dp(a, b, s) ; if ans = ("" + (("inf")))->toReal() then ( ans := -1 ) else skip ; execute (ans)->display(); operation dp(a : OclAny, b : OclAny, s : OclAny) : OclAny pre: true post: true activity: if not(mem[Sequence{a, b, s}+1] <>= null) then ( return mem[Sequence{a, b, s}+1] ) else skip ; var x : int := MathLib.bitwiseAnd(a, 1) ; var y : int := MathLib.bitwiseAnd(b, 1) ; var xor : int := MathLib.bitwiseAnd(s, 1) ; var res : double := ("" + (("inf")))->toReal() ; if MathLib.bitwiseXor(x, y) /= xor then ( mem[Sequence{a, b, s}+1] := res ; return res ) else ( res := 2 * dp(a /(2->pow(1)), b /(2->pow(1)), s /(2->pow(1))) ; if a > 1 then ( var pants : double := 2 * dp((a - 1) /(2->pow(1)), (b + 1) /(2->pow(1)), s /(2->pow(1))) + 1 ; if (pants->compareTo(res)) < 0 then ( res := pants ) else skip ) else skip ) ; mem[Sequence{a, b, s}+1] := res ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000,10**9)) write=lambda x : sys.stdout.write(x+"\n") n=int(input()) a=list(map(int,input().split())) val=0 for num in a[2 :]: val ^=num k=a[0]+a[1] if(k-val)% 2!=0 or kk : ans=-1 else : v1=tmp v2=tmp kouho=[] ans=None if tmp>a[0]: ans=-1 diff=k-2*tmp for i in range(diff.bit_length()): if(diff & 1<pow(9)}->max()) ; var write : Function := lambda x : OclAny in ((OclFile["System.out"]).write(x + "\n")) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var val : int := 0 ; for num : a.subrange(2+1) do ( val := val xor num) ; var k : OclAny := a->first() + a[1+1] ; if (k - val) mod 2 /= 0 or (k->compareTo(val)) < 0 then ( var ans : int := -1 ) else ( var tmp : int := (k - val) div 2 ; if tmp < 0 or (2 * tmp->compareTo(k)) > 0 then ( ans := -1 ) else ( var v1 : int := tmp ; var v2 : int := tmp ; var kouho : Sequence := Sequence{} ; ans := null ; if (tmp->compareTo(a->first())) > 0 then ( ans := -1 ) else skip ; var diff : double := k - 2 * tmp ; for i : Integer.subrange(0, diff.bit_length()-1) do ( if MathLib.bitwiseAnd((MathLib.bitwiseAnd(diff, 1 * (2->pow(i)))), tmp) then ( ans := -1 ; break ) else (if MathLib.bitwiseAnd(diff, 1 * (2->pow(i))) then ( execute ((1 * (2->pow(i))) : kouho) ) else skip)) ; var s : OclAny := (kouho)->sum() ; if ans <>= null then ( for num : kouho(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( s := s - num ; if (v2 + s->compareTo(a[1+1])) < 0 then ( v2 := v2 + num ) else (if (v1 + num->compareTo(a->first())) <= 0 then ( v1 := v1 + num ) else ( v2 := v2 + num ) ) ) ; if v1 = 0 then ( ans := -1 ) else ( ans := a->first() - v1 ) ) else ( ans := -1 ) ) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) A=[int(i)for i in input().split()] A1=A[0] A2=A[1] c=0 for ele in A[2 :]: c ^=ele d=A1+A2-c if d % 2==1 : print(-1) else : d=d//2 flgs=[] for i in range(41): fand=d &(1<A1 : print(-1) else : for i in range(len(flgs)): if flgs[i]==2 : if ans+2**(41-i-1)<=A1 : ans+=2**(41-i-1) if ans==0 : print(-1) else : print(A1-ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var A1 : OclAny := A->first() ; var A2 : OclAny := A[1+1] ; var c : int := 0 ; for ele : A.subrange(2+1) do ( c := c xor ele) ; var d : double := A1 + A2 - c ; if d mod 2 = 1 then ( execute (-1)->display() ) else ( d := d div 2 ; var flgs : Sequence := Sequence{} ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 41))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name fand)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name d))) & (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name i)))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name fxor)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name c))) & (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name i)))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (expr (atom (name fand))) & (expr (atom (name fxor))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))) (elif_clause elif (test (logical_test (comparison (expr (atom (name fand)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name flgs)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))))))))))) (elif_clause elif (test (logical_test (comparison (expr (atom (name fxor)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name flgs)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name flgs)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name flgs)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name flgs)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name flgs)))))))) ))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name flgs)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) ** (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (number (integer 41)))) - (expr (atom (name i)))) - (expr (atom (number (integer 1))))))))) )))))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name ans)))) > (comparison (expr (atom (name A1))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ))))))))))))) (else_clause else : (suite (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name flgs)))))))) ))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name flgs)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (number (integer 2)))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name ans))) + (expr (expr (atom (number (integer 2)))) ** (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (number (integer 41)))) - (expr (atom (name i)))) - (expr (atom (number (integer 1))))))))) )))))) <= (comparison (expr (atom (name A1))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) ** (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (number (integer 41)))) - (expr (atom (name i)))) - (expr (atom (number (integer 1))))))))) ))))))))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name ans)))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name A1))) - (expr (atom (name ans))))))))) ))))))))))))))))))))))) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) N=I() A=LI() a=A[0] b=A[1] c=0 if len(A)>=3 : for i in range(2,N): c ^=A[i] INF=10**12 from functools import lru_cache @ lru_cache(maxsize=None) def f(s,t,u): if s==0 : if t==u : return 0 else : return INF else : if(s & 1)^(t & 1)==u & 1 : return min(2*f(s//2,t//2,u//2),2*f((s-1)//2,(t+1)//2,u//2)+1) else : return INF ans=f(a,b,c) if ans>=a : print(-1) else : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; skip ; var N : OclAny := I() ; var A : OclAny := LI() ; var a : OclAny := A->first() ; var b : OclAny := A[1+1] ; var c : int := 0 ; if (A)->size() >= 3 then ( for i : Integer.subrange(2, N-1) do ( c := c xor A[i+1]) ) else skip ; var INF : double := (10)->pow(12) ; skip ; (compound_stmt (decorator @ (dotted_name (name lru_cache)) ( (arglist (argument (test (logical_test (comparison (expr (atom (name maxsize)))))) = (test (logical_test (comparison (expr (atom None))))))) )) (funcdef def (name f) ( (typedargslist (def_parameters (def_parameter (named_parameter (name s))) , (def_parameter (named_parameter (name t))) , (def_parameter (named_parameter (name u))))) ) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name s)))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name t)))) == (comparison (expr (atom (name u))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name INF))))))))))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name s))) & (expr (atom (number (integer 1))))))))) ))) ^ (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name t))) & (expr (atom (number (integer 1))))))))) ))))) == (comparison (expr (expr (atom (name u))) & (expr (atom (number (integer 1))))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) * (expr (atom (name f)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name s))) // (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name t))) // (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name u))) // (expr (atom (number (integer 2)))))))))) ))))))))) , (argument (test (logical_test (comparison (expr (expr (expr (atom (number (integer 2)))) * (expr (atom (name f)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name s))) - (expr (atom (number (integer 1))))))))) ))) // (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name t))) + (expr (atom (number (integer 1))))))))) ))) // (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name u))) // (expr (atom (number (integer 2)))))))))) ))))) + (expr (atom (number (integer 1)))))))))) )))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name INF))))))))))))))))))))) ; var ans : String := f(a, b, c) ; if ans >= a then ( execute (-1)->display() ) else ( execute (ans)->display() ); operation I() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.readLine().rstrip())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reverse(string,length,l,r): if(l<0 or r>=length or l>r): return string ; string=list(string) while(lsize(); ; l := 5; r := 7; ; execute (reverse(string, length, l, r))->display(); ) else skip; operation reverse(string : OclAny, length : OclAny, l : OclAny, r : OclAny) pre: true post: true activity: if (l < 0 or (r->compareTo(length)) >= 0 or (l->compareTo(r)) > 0) then ( return string; ) else skip ; string := (string)->characters() ; while ((l->compareTo(r)) < 0) do ( var c : OclAny := string[l+1]; ; string[l+1] := string[r+1]; ; string[r+1] := c; ; l := l + 1; ; r := r - 1;) ; return StringLib.sumStringsWithSeparator((string), "");; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- val=input().split() val=[int(x)for x in val] n=val[0] m=val[1] t=input().split() t=[int(x)for x in t] t.sort() mini=100000000 for i in range(m-n+1): mini=min(mini,t[i+n-1]-t[i]) print(mini) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var val : OclAny := input().split() ; val := val->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var n : OclAny := val->first() ; var m : OclAny := val[1+1] ; var t : OclAny := input().split() ; t := t->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; t := t->sort() ; var mini : int := 100000000 ; for i : Integer.subrange(0, m - n + 1-1) do ( mini := Set{mini, t[i + n - 1+1] - t[i+1]}->min()) ; execute (mini)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inp=input().split() n,m=int(inp[0]),int(inp[1]) s=input().split() l=[int(i)for i in s] l.sort() min_val=l[m-1] for i in range(m-n+1): val=l[n-1+i]-l[i] min_val=min(min_val,val) min_val=min(min_val,l[-1]-l[0]) print(min_val) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inp : OclAny := input().split() ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := Sequence{("" + ((inp->first())))->toInteger(),("" + ((inp[1+1])))->toInteger()} ; var s : OclAny := input().split() ; var l : Sequence := s->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; l := l->sort() ; var min_val : OclAny := l[m - 1+1] ; for i : Integer.subrange(0, m - n + 1-1) do ( var val : double := l[n - 1 + i+1] - l[i+1] ; min_val := Set{min_val, val}->min()) ; min_val := Set{min_val, l->last() - l->first()}->min() ; execute (min_val)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) f=sorted(map(int,input().split())) diff=[] n-=1 for i in range(len(f)-n): diff.append(f[i+n]-f[i]) print(min(diff)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var f : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var diff : Sequence := Sequence{} ; n := n - 1 ; for i : Integer.subrange(0, (f)->size() - n-1) do ( execute ((f[i + n+1] - f[i+1]) : diff)) ; execute ((diff)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from enum import Enum import sys BIG_NUM=2000000000 MOD=1000000007 EPS=0.000000001 class Type(Enum): win_Taro=0 win_Hanako=1 EVEN=2 def comp_str(A,B): if A>B : return Type.win_Taro elif Aexists( _x | result = _x ); static attribute win_Taro : int := 0; static attribute win_Hanako : int := 1; static attribute EVEN : int := 2; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var BIG_NUM : int := 2000000000 ; var MOD : int := 1000000007 ; var EPS : double := 0.000000001 ; skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var point_Taro : int := 0 ; var point_Hanako : int := 0 ; for loop : Integer.subrange(0, N-1) do ( var line : OclAny := OclType["String"]((OclFile["System.in"]).readLine()).split() ; var ret_type : OclAny := comp_str(line->first(), line[1+1]) ; if ret_type = (Type.newType()).initialise.win_Taro then ( point_Taro := point_Taro + 3 ) else (if ret_type = (Type.newType()).initialise.win_Hanako then ( point_Hanako := point_Hanako + 3 ) else ( point_Taro := point_Taro + 1 ; point_Hanako := point_Hanako + 1 ) ) ) ; execute (StringLib.format("%d %d",Sequence{point_Taro, point_Hanako}))->display(); operation comp_str(A : OclAny, B : OclAny) : OclAny pre: true post: true activity: if (A->compareTo(B)) > 0 then ( return (Type.newType()).initialise.win_Taro ) else (if (A->compareTo(B)) < 0 then ( return (Type.newType()).initialise.win_Hanako ) else ( return (Type.newType()).initialise.EVEN ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from collections import Counter def solve(numbers): status=Counter({numbers[0]: 1}) for n in numbers[1 :-1]: u=Counter() for k,v in status.items(): u[k+n]+=v*(0<=k+n<=20) u[k-n]+=v*(0<=k-n<=20) status=Counter({k : v for k,v in u.items()if v>0}) return status[numbers[-1]] def main(args): input() numbers=[int(n)for n in input().split()] ans=solve(numbers) print(ans) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation solve(numbers : OclAny) : OclAny pre: true post: true activity: var status : OclAny := Counter(Map{ numbers->first() |-> 1 }) ; for n : numbers.subrange(1+1, -1) do ( var u : OclAny := Counter() ; for _tuple : status->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); u[k + n+1] := u[k + n+1] + v * (0 <= k + n & (k + n <= 20)) ; u[k - n+1] := u[k - n+1] + v * (0 <= k - n & (k - n <= 20))) ; status := Counter(u->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->select(_tuple | let k : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in v > 0)->collect(_tuple | Map{k |-> v})->unionAll())) ; return status[numbers->last()+1]; operation main(args : OclAny) pre: true post: true activity: input() ; numbers := input().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; var ans : OclAny := solve(numbers) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import* from fractions import gcd readints=lambda : map(int,input().strip('\n').split()) def hasUnique(s,n,k): freq={} for i in range(n-k+1): x=s[i : i+k] if x not in freq : freq[x]=0 freq[x]+=1 for k in freq : if freq[k]==1 : return True return False def good(s,n,k): for i in range(1,k): if hasUnique(s,n,i): return False freq={} for i in range(n-k+1): x=s[i : i+k] if x not in freq : freq[x]=0 freq[x]+=1 st=set() for x in freq : if freq[x]==1 : if len(st)>0 : return False st.add(x) return len(st)==1 def gen(i,s,n,k): if i==n : if good(s,n,k): print(s) else : gen(i+1,s+'0',n,k) gen(i+1,s+'1',n,k) n,k=readints() if n==k : print('0'*n) sys.exit(0) s='' while len(s)trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; skip ; skip ; Sequence{n,k} := readints->apply() ; if n = k then ( execute (StringLib.nCopies('0', n))->display() ; sys.exit(0) ) else skip ; s := '' ; while ((s)->size()->compareTo(n)) < 0 do ( var r : int := ("" + (((n - k) div 2)))->toInteger() ; s := s + ((StringLib.nCopies('0', r)) + '1')) ; s := s.subrange(1,n) ; execute (s)->display(); operation hasUnique(s : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var freq : OclAny := Set{} ; for i : Integer.subrange(0, n - k + 1-1) do ( var x : OclAny := s.subrange(i+1, i + k) ; if (freq)->excludes(x) then ( freq[x+1] := 0 ) else skip ; freq[x+1] := freq[x+1] + 1) ; for k : freq do ( if freq[k+1] = 1 then ( return true ) else skip) ; return false; operation good(s : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(1, k-1) do ( if hasUnique(s, n, i) then ( return false ) else skip) ; freq := Set{} ; for i : Integer.subrange(0, n - k + 1-1) do ( x := s.subrange(i+1, i + k) ; if (freq)->excludes(x) then ( freq[x+1] := 0 ) else skip ; freq[x+1] := freq[x+1] + 1) ; var st : Set := Set{}->union(()) ; for x : freq do ( if freq[x+1] = 1 then ( if (st)->size() > 0 then ( return false ) else skip ; execute ((x) : st) ) else skip) ; return (st)->size() = 1; operation gen(i : OclAny, s : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: if i = n then ( if good(s, n, k) then ( execute (s)->display() ) else skip ) else ( gen(i + 1, s + '0', n, k) ; gen(i + 1, s + '1', n, k) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_of_child,num_of_puzz=map(int,input().split(' ')) pices=list(map(int,input().split(' '))) pices.sort() ans=max(pices)-min(pices) for i in range(len(pices)): pices2=pices[i : i+num_of_child] if len(pices2)==num_of_child : if ans>max(pices2)-min(pices2): ans=max(pices2)-min(pices2) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_of_child : OclAny := null; var num_of_puzz : OclAny := null; Sequence{num_of_child,num_of_puzz} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var pices : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; pices := pices->sort() ; var ans : double := (pices)->max() - (pices)->min() ; for i : Integer.subrange(0, (pices)->size()-1) do ( var pices2 : OclAny := pices.subrange(i+1, i + num_of_child) ; if (pices2)->size() = num_of_child then ( if (ans->compareTo((pices2)->max() - (pices2)->min())) > 0 then ( ans := (pices2)->max() - (pices2)->min() ) else skip ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split(" ")) ar=list(map(int,input().split(" "))) ar=sorted(ar) min=ar[len(ar)-1]-ar[0] for i in range(len(ar)): for j in range(i+1,len(ar)): if ar[j]-ar[i]collect( _x | (OclType["int"])->apply(_x) ) ; var ar : Sequence := ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; ar := ar->sort() ; var min : double := ar[(ar)->size() - 1+1] - ar->first() ; for i : Integer.subrange(0, (ar)->size()-1) do ( for j : Integer.subrange(i + 1, (ar)->size()-1) do ( if (ar[j+1] - ar[i+1]->compareTo(min)) < 0 & j - i = n - 1 then ( min := ar[j+1] - ar[i+1] ) else skip)) ; execute (min)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def search(arr,n,x): i=0 while(iunion(Sequence{7}->union(Sequence{6}->union(Sequence{7}->union(Sequence{6}->union(Sequence{5}->union(Sequence{4}->union(Sequence{3}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 3 }))))))))))) ; n := (arr)->size() ; x := 3 ; execute ("Element")->display(); operation search(arr : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; while ((i->compareTo(n)) < 0) do ( if (arr[i+1] = x) then ( return i ) else skip ; i := i + (arr[i+1] - x)->abs()) ; execute ("number is not present!")->display() ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import pow def no_of_characters(M): k=1 while(True): if(pow(2,k+1)-20): num=pow(2,k-1) if(num>=N): print("A",end="") else : print("B",end="") N-=num k-=1 print("\n",end="") if __name__=='__main__' : M=30 ; print_string(M) M=55 print_string(M) M=100 print_string(M) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( M := 30; ; print_string(M) ; M := 55 ; print_string(M) ; M := 100 ; print_string(M) ) else skip; operation no_of_characters(M : OclAny) : OclAny pre: true post: true activity: var k : int := 1 ; while (true) do ( if (((2)->pow(k + 1) - 2->compareTo(M)) < 0) then ( k := k + 1 ) else ( break )) ; return k; operation print_string(M : OclAny) pre: true post: true activity: k := no_of_characters(M) ; var N : double := M - ((2)->pow(k) - 2) ; while (k > 0) do ( var num : double := (2)->pow(k - 1) ; if ((num->compareTo(N)) >= 0) then ( execute ("A")->display() ) else ( execute ("B")->display() ; N := N - num ) ; k := k - 1) ; execute ("\n")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printRepeating(arr,size): print("Repeating elements are ",end='') for i in range(0,size): for j in range(i+1,size): if arr[i]==arr[j]: print(arr[i],end=' ') arr=[4,2,4,5,2,3,1] arr_size=len(arr) printRepeating(arr,arr_size) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{4}->union(Sequence{2}->union(Sequence{4}->union(Sequence{5}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 1 })))))) ; var arr_size : int := (arr)->size() ; printRepeating(arr, arr_size); operation printRepeating(arr : OclAny, size : OclAny) pre: true post: true activity: execute ("Repeating elements are ")->display() ; for i : Integer.subrange(0, size-1) do ( for j : Integer.subrange(i + 1, size-1) do ( if arr[i+1] = arr[j+1] then ( execute (arr[i+1])->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printRepeating(arr,size): count=[0]*size print(" Repeating elements are ",end="") for i in range(0,size): if(count[arr[i]]==1): print(arr[i],end=" ") else : count[arr[i]]=count[arr[i]]+1 arr=[4,2,4,5,2,3,1] arr_size=len(arr) printRepeating(arr,arr_size) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{4}->union(Sequence{2}->union(Sequence{4}->union(Sequence{5}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 1 })))))) ; var arr_size : int := (arr)->size() ; printRepeating(arr, arr_size); operation printRepeating(arr : OclAny, size : OclAny) pre: true post: true activity: var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, size) ; execute (" Repeating elements are ")->display() ; for i : Integer.subrange(0, size-1) do ( if (count[arr[i+1]+1] = 1) then ( execute (arr[i+1])->display() ) else ( count[arr[i+1]+1] := count[arr[i+1]+1] + 1 )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def areConsecutives(arr,n): first_term=sys.maxsize for i in range(n): if arr[i]union(Sequence{1}->union(Sequence{0}->union(Sequence{-3}->union(Sequence{-1}->union(Sequence{ -2 }))))) ; n := (arr)->size() ; if areConsecutives(arr, n) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation areConsecutives(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var first_term : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1]->compareTo(first_term)) < 0 then ( first_term := arr[i+1] ) else skip) ; var ap_sum : int := ((n * (2 * first_term + (n - 1) * 1)) div 2) ; var arr_sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( arr_sum := arr_sum + arr[i+1]) ; return ap_sum = arr_sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100005 def Min_Replace(arr,n,k): arr.sort(reverse=False) freq=[0 for i in range(MAX)] p=0 freq[p]=1 for i in range(1,n,1): if(arr[i]==arr[i-1]): freq[p]+=1 else : p+=1 freq[p]+=1 freq.sort(reverse=True) ans=0 for i in range(k,p+1,1): ans+=freq[i] return ans if __name__=='__main__' : arr=[1,2,7,8,2,3,2,3] n=len(arr) k=2 print(Min_Replace(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 100005 ; skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{7}->union(Sequence{8}->union(Sequence{2}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 3 }))))))) ; n := (arr)->size() ; k := 2 ; execute (Min_Replace(arr, n, k))->display() ) else skip; operation Min_Replace(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var freq : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)) ; var p : int := 0 ; freq[p+1] := 1 ; for i : Integer.subrange(1, n-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if (arr[i+1] = arr[i - 1+1]) then ( freq[p+1] := freq[p+1] + 1 ) else ( p := p + 1 ; freq[p+1] := freq[p+1] + 1 )) ; freq := freq->sort() ; var ans : int := 0 ; for i : Integer.subrange(k, p + 1-1)->select( $x | ($x - k) mod 1 = 0 ) do ( ans := ans + freq[i+1]) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- turn=int(input()) duel=[input().split(" ")for i in range(turn)] point=[0,0] for i in duel : if i[0]==i[1]: point[0],point[1]=point[0]+1,point[1]+1 if i[0]>i[1]: point[0]+=3 if i[0]toInteger() ; var duel : Sequence := Integer.subrange(0, turn-1)->select(i | true)->collect(i | (input().split(" "))) ; var point : Sequence := Sequence{0}->union(Sequence{ 0 }) ; for i : duel do ( if i->first() = i[1+1] then ( var point->first() : OclAny := null; var point[1+1] : OclAny := null; Sequence{point->first(),point[1+1]} := Sequence{point->first() + 1,point[1+1] + 1} ) else skip ; if (i->first()->compareTo(i[1+1])) > 0 then ( point->first() := point->first() + 3 ) else skip ; if (i->first()->compareTo(i[1+1])) < 0 then ( point[1+1] := point[1+1] + 3 ) else skip) ; execute (StringLib.sumStringsWithSeparator(((point)->collect( _x | (OclType["String"])->apply(_x) )), " "))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(a): first=a[0]-1 last=a[-1]-len(a) zeroes=0 for i,e in enumerate(a): if e-(i+1)==0 : zeroes+=1 if zeroes==len(a): return 0 if first==len(a)-1 and last==-(len(a)-1): return 3 if first==0 or last==0 : return 1 return 2 t=int(input()) for _ in range(t): n=input() a=[int(x)for x in input().split()] print(solve(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : String := (OclFile["System.in"]).readLine() ; a := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (solve(a))->display()); operation solve(a : OclAny) : OclAny pre: true post: true activity: var first : double := a->first() - 1 ; var last : double := a->last() - (a)->size() ; var zeroes : int := 0 ; for _tuple : Integer.subrange(1, (a)->size())->collect( _indx | Sequence{_indx-1, (a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var e : OclAny := _tuple->at(_indx); if e - (i + 1) = 0 then ( zeroes := zeroes + 1 ) else skip) ; if zeroes = (a)->size() then ( return 0 ) else skip ; if first = (a)->size() - 1 & last = -((a)->size() - 1) then ( return 3 ) else skip ; if first = 0 or last = 0 then ( return 1 ) else skip ; return 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) w=list(map(int,input().split())) s=sorted(w) if w[0]==s[-1]and w[-1]==s[0]: print(3) elif w[0]==s[0]and w[-1]==s[-1]: c=0 for i in range(n): if w[i]==s[i]: c+=1 if c==n : print(0) else : print(1) elif(w[0]==s[0]and w[-1]!=s[-1])or(w[0]!=s[0]and w[-1]==s[-1]): print(1) else : print(2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : Sequence := w->sort() ; if w->first() = s->last() & w->last() = s->first() then ( execute (3)->display() ) else (if w->first() = s->first() & w->last() = s->last() then ( var c : int := 0 ; for i : Integer.subrange(0, n-1) do ( if w[i+1] = s[i+1] then ( c := c + 1 ) else skip) ; if c = n then ( execute (0)->display() ) else ( execute (1)->display() ) ) else (if (w->first() = s->first() & w->last() /= s->last()) or (w->first() /= s->first() & w->last() = s->last()) then ( execute (1)->display() ) else ( execute (2)->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) if(n==k): print("1"*n) exit() a=(n-k)>>1 i=0 Ans="" while(in-1): break Ans+="1" i+=1 if(i>n-1): break print(Ans[: n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (n = k) then ( execute (StringLib.nCopies("1", n))->display() ; exit() ) else skip ; var a : int := (n - k) /(2->pow(1)) ; var i : int := 0 ; var Ans : String := "" ; while ((i->compareTo(n)) < 0) do ( Ans := Ans + StringLib.nCopies("0", (a)) ; i := i + a ; if ((i->compareTo(n - 1)) > 0) then ( break ) else skip ; Ans := Ans + "1" ; i := i + 1 ; if ((i->compareTo(n - 1)) > 0) then ( break ) else skip) ; execute (Ans.subrange(1,n))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) arr=list(map(int,input().split())) cnt=0 f=True for i in range(n-1): if arr[i]>arr[i+1]: f=False break if f : print(0) else : if arr[0]==1 or arr[n-1]==n : print(1) elif arr[0]==n and arr[n-1]==1 : print(3) else : print(2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : int := 0 ; var f : boolean := true ; for i : Integer.subrange(0, n - 1-1) do ( if (arr[i+1]->compareTo(arr[i + 1+1])) > 0 then ( f := false ; break ) else skip) ; if f then ( execute (0)->display() ) else ( if arr->first() = 1 or arr[n - 1+1] = n then ( execute (1)->display() ) else (if arr->first() = n & arr[n - 1+1] = 1 then ( execute (3)->display() ) else ( execute (2)->display() ) ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math read=lambda : list(map(int,input().split())) t=int(input()) while t>0 : t-=1 n=int(input()) a=read() sum=0 if a[0]==1 or a[n-1]==n : ok=1 for i in range(1,n): if a[i]-a[i-1]!=1 : ok=0 break if ok==1 : sum=0 else : sum=1 elif a[0]==n and a[n-1]==1 : sum=3 else : sum=2 print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( t := t - 1 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := read->apply() ; var sum : int := 0 ; if a->first() = 1 or a[n - 1+1] = n then ( var ok : int := 1 ; for i : Integer.subrange(1, n-1) do ( if a[i+1] - a[i - 1+1] /= 1 then ( ok := 0 ; break ) else skip) ; if ok = 1 then ( sum := 0 ) else ( sum := 1 ) ) else (if a->first() = n & a[n - 1+1] = 1 then ( sum := 3 ) else ( sum := 2 ) ) ; execute (sum)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(a): movements=[a[x]-(x+1)for x in range(len(a))] if movements.count(0)==len(movements): return 0 if movements[0]==len(a)-1 and movements[-1]==-(len(a)-1): return 3 if movements[0]==0 or movements[-1]==0 : return 1 return 2 t=int(input()) for _ in range(t): n=input() a=[int(x)for x in input().split()] print(solve(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : String := (OclFile["System.in"]).readLine() ; a := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (solve(a))->display()); operation solve(a : OclAny) : OclAny pre: true post: true activity: var movements : Sequence := Integer.subrange(0, (a)->size()-1)->select(x | true)->collect(x | (a[x+1] - (x + 1))) ; if movements->count(0) = (movements)->size() then ( return 0 ) else skip ; if movements->first() = (a)->size() - 1 & movements->last() = -((a)->size() - 1) then ( return 3 ) else skip ; if movements->first() = 0 or movements->last() = 0 then ( return 1 ) else skip ; return 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- road=int(input()) while road>0 : answer=[[float("inf")if n!=m else 0 for n in range(10)]for m in range(10)] city=0 for _ in range(road): c1,c2,w=(int(n)for n in input().split(" ")) answer[c1][c2]=w answer[c2][c1]=w city=max(city,c1,c2) city+=1 for i in range(city): for j in range(city): for k in range(city): answer[j][k]=min(answer[j][k],answer[j][i]+answer[i][k]) sum_ans=[-1,float("inf")] for i in range(city): if sum(answer[i][: city])toInteger() ; while road > 0 do ( var answer : Sequence := Integer.subrange(0, 10-1)->select(m | true)->collect(m | (Integer.subrange(0, 10-1)->select(n | true)->collect(n | (if n /= m then ("" + (("inf")))->toReal() else 0 endif)))) ; var city : int := 0 ; for _anon : Integer.subrange(0, road-1) do ( var c1 : OclAny := null; var c2 : OclAny := null; var w : OclAny := null; Sequence{c1,c2,w} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " "))))))) ))))))))} ; answer[c1+1][c2+1] := w ; answer[c2+1][c1+1] := w ; city := Set{city, c1, c2}->max()) ; city := city + 1 ; for i : Integer.subrange(0, city-1) do ( for j : Integer.subrange(0, city-1) do ( for k : Integer.subrange(0, city-1) do ( answer[j+1][k+1] := Set{answer[j+1][k+1], answer[j+1][i+1] + answer[i+1][k+1]}->min()))) ; var sum_ans : Sequence := Sequence{-1}->union(Sequence{ ("" + (("inf")))->toReal() }) ; for i : Integer.subrange(0, city-1) do ( if ((answer[i+1].subrange(1,city))->sum()->compareTo(sum_ans[1+1])) < 0 then ( sum_ans := Sequence{i}->union(Sequence{ (answer[i+1].subrange(1,city))->sum() }) ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name sum_ans))))))))->display() ; road := ("" + (((OclFile["System.in"]).readLine())))->toInteger()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,bisect PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") while True : n=int(input()) if n==0 : break L=[] cities=set() for _ in range(n): city1,city2,weight=[int(_)for _ in input().split()] L.append([city1,city2,weight]) cities.add(city1) cities.add(city2) m=len(cities) dist=[[2**31]*m for _ in range(m)] for i in range(m): dist[i][i]=0 for city1,city2,weight in L : dist[city1][city2]=weight dist[city2][city1]=weight for k in range(m): for i in range(m): for j in range(m): dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]) city,time=-1,2**31 for k in range(m): S=sum(dist[k]) if Scollect( _x | (OclType["int"])->apply(_x) ) ; var now : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (s + 1)) ; var mod1 : OclAny := null; var mod2 : OclAny := null; Sequence{mod1,mod2} := Sequence{(10)->pow(9) + 7,998244353} ; var mod : OclAny := mod2 ; var ans : int := 0 ; for a : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( now->first() := now->first() + 1 ; for i : Integer.subrange(-1 + 1, s)->reverse() do ( now[i+1] := (now[i+1] + (if (i->compareTo(a)) < 0 then 0 else now[i - a+1] endif)) mod mod) ; ans := (ans + now->last()) mod mod) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000005 def SieveOfEratosthenes(prime): prime[1]=False ; prime[0]=False ; for p in range(2,int(MAX**(1/2))): if(prime[p]==True): for i in range(p*2,MAX,p): prime[i]=False ; def prime_xor(arr,n,k): prime=[True]*MAX ; SieveOfEratosthenes(prime); ans=0 ; for i in range(n): if(prime[arr[i]]): if((i+1)% k==0): ans ^=arr[i]; print(ans); if __name__=="__main__" : arr=[2,3,5,7,11,8]; n=len(arr); K=2 ; prime_xor(arr,n,K); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1000005 ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{7}->union(Sequence{11}->union(Sequence{ 8 }))))); ; n := (arr)->size(); ; var K : int := 2; ; prime_xor(arr, n, K); ) else skip; operation SieveOfEratosthenes(prime : OclAny) pre: true post: true activity: prime[1+1] := false; ; prime->first() := false; ; for p : Integer.subrange(2, ("" + (((MAX)->pow((1 / 2)))))->toInteger()-1) do ( if (prime[p+1] = true) then ( for i : Integer.subrange(p * 2, MAX-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( prime[i+1] := false;) ) else skip); operation prime_xor(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: prime := MatrixLib.elementwiseMult(Sequence{ true }, MAX); ; SieveOfEratosthenes(prime); ; var ans : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (prime[arr[i+1]+1]) then ( if ((i + 1) mod k = 0) then ( ans := ans xor arr[i+1]; ) else skip ) else skip) ; execute (ans)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from collections import defaultdict from bisect import bisect_left,bisect_right sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod=998244353 def I(): return int(input()) def LI(): return list(map(int,input().split())) def LIR(row,col): if row<=0 : return[[]for _ in range(col)] elif col==1 : return[I()for _ in range(row)] else : read_all=[LI()for _ in range(row)] return map(list,zip(*read_all)) N,S=LI() A=LI() d=defaultdict(int) ans=0 for i in range(N): temp=defaultdict(int) for k,v in d.items(): temp[k]=v ans+=d[S-A[i]]*(N-i) if S==A[i]: ans+=(i+1)*(N-i) ans %=mod d[A[i]]+=i+1 for k in range(A[i]+1,3001): d[k]+=temp[k-A[i]] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; var mod : int := 998244353 ; skip ; skip ; skip ; var N : OclAny := null; var S : OclAny := null; Sequence{N,S} := LI() ; var A : OclAny := LI() ; var d : OclAny := defaultdict(OclType["int"]) ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( var temp : OclAny := defaultdict(OclType["int"]) ; for _tuple : d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); temp[k+1] := v) ; ans := ans + d[S - A[i+1]+1] * (N - i) ; if S = A[i+1] then ( ans := ans + (i + 1) * (N - i) ) else skip ; ans := ans mod mod ; d[A[i+1]+1] := d[A[i+1]+1] + i + 1 ; for k : Integer.subrange(A[i+1] + 1, 3001-1) do ( d[k+1] := d[k+1] + temp[k - A[i+1]+1])) ; execute (ans)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LIR(row : OclAny, col : OclAny) : OclAny pre: true post: true activity: if row <= 0 then ( return Integer.subrange(0, col-1)->select(_anon | true)->collect(_anon | (Sequence{})) ) else (if col = 1 then ( return Integer.subrange(0, row-1)->select(_anon | true)->collect(_anon | (I())) ) else ( var read_all : Sequence := Integer.subrange(0, row-1)->select(_anon | true)->collect(_anon | (LI())) ; return (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name read_all)))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name read_all)))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name read_all)))))))`third->at(_indx)} ))->collect( _x | (OclType["Sequence"])->apply(_x) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- K=32 P=998244353 pa=(1<<30)-((1<<30)% P) M=[] N,S=map(int,input().split()) m=int(("1"*2+"0"*30)*(S+1),2) mm=1<>a*K s-=((s & m)>>30)*pa ans+=s & mmm print(ans % P) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var K : int := 32 ; var P : int := 998244353 ; var pa : double := (1 * (2->pow(30))) - ((1 * (2->pow(30))) mod P) ; var M : Sequence := Sequence{} ; var N : OclAny := null; var S : OclAny := null; Sequence{N,S} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : int := ("" + (((StringLib.nCopies("1", 2) + StringLib.nCopies("0", 30)) * (S + 1), 2)))->toInteger() ; var mm : int := 1 * (2->pow(K * S)) ; var mmm : double := (1 * (2->pow(K))) - 1 ; var A : Sequence := input().split()->select(a | true)->collect(a | (("" + ((a)))->toInteger())) ; var s : int := 0 ; var ans : int := 0 ; for a : A do ( s := s + mm ; s := s + s /(2->pow(a * K)) ; s := s - ((MathLib.bitwiseAnd(s, m)) /(2->pow(30))) * pa ; ans := ans + MathLib.bitwiseAnd(s, mmm)) ; execute (ans mod P)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from heapq import heappush,heappop from itertools import permutations,accumulate import sys import math import bisect def LI(): return[int(x)for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return[list(x)for x in sys.stdin.readline().split()] def S(): res=list(sys.stdin.readline()) if res[-1]=="\n" : return res[:-1] return res def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] sys.setrecursionlimit(1000000) mod=998244353 def solve(): n,s=LI() a=LI() ans=0 f=[0]*(s+1) f[0]=0 for i in a : f[0]+=1 for j in range(s+1)[: :-1]: nj=j+i if nj>s : continue f[nj]+=f[j] f[nj]%=mod ans+=f[s] ans %=mod print(ans) return if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1000000) ; var mod : int := 998244353 ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | ((x))); operation S() : OclAny pre: true post: true activity: var res : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if res->last() = "\n" then ( return res->front() ) else skip ; return res; operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation solve() pre: true post: true activity: var s : OclAny := null; Sequence{n,s} := LI() ; var a : OclAny := LI() ; var ans : int := 0 ; var f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (s + 1)) ; f->first() := 0 ; for i : a do ( f->first() := f->first() + 1 ; for j : range(s + 1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( var nj : OclAny := j + i ; if (nj->compareTo(s)) > 0 then ( continue ) else skip ; f[nj+1] := f[nj+1] + f[j+1] ; f[nj+1] := f[nj+1] mod mod) ; ans := ans + f[s+1] ; ans := ans mod mod) ; execute (ans)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): import sys input=sys.stdin.readline n,s=map(int,input().split()) A=list(map(int,input().split())) mod=998244353 dp=[[0]*(s+1)for _ in range(n+1)] dp[0][0]=1 for i in range(1,n+1): for j in range(s+1): a=A[n-i] if j-a>0 : dp[i][j]=(dp[i-1][j]+dp[i-1][j-a])% mod elif j==a : dp[i][j]=(dp[i-1][j]+i)% mod else : dp[i][j]=dp[i-1][j] ans=0 for i in range(1,n+1): a=A[i-1] if s>a : ans=(ans+dp[n-i][s-a]*i)% mod elif s==a : ans=(ans+(n-i+1)*i)% mod print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var mod : int := 998244353 ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (s + 1)))) ; dp->first()->first() := 1 ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(0, s + 1-1) do ( var a : OclAny := A[n - i+1] ; if j - a > 0 then ( dp[i+1][j+1] := (dp[i - 1+1][j+1] + dp[i - 1+1][j - a+1]) mod mod ) else (if j = a then ( dp[i+1][j+1] := (dp[i - 1+1][j+1] + i) mod mod ) else ( dp[i+1][j+1] := dp[i - 1+1][j+1] ) ) )) ; var ans : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( a := A[i - 1+1] ; if (s->compareTo(a)) > 0 then ( ans := (ans + dp[n - i+1][s - a+1] * i) mod mod ) else (if s = a then ( ans := (ans + (n - i + 1) * i) mod mod ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) cities=list(map(int,input().split())) for i in range(len(cities)): if i==0 : print(abs(cities[0]-cities[1]),abs(cities[0]-cities[-1])) elif i==len(cities)-1 : print(abs(cities[-1]-cities[i-1]),abs(cities[0]-cities[-1])) else : mn=min(abs(cities[i]-cities[i-1]),abs(cities[i]-cities[i+1])) mx=max(abs(cities[i]-cities[0]),abs(cities[i]-cities[-1])) print(mn,mx) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cities : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, (cities)->size()-1) do ( if i = 0 then ( execute ((cities->first() - cities[1+1])->abs())->display() ) else (if i = (cities)->size() - 1 then ( execute ((cities->last() - cities[i - 1+1])->abs())->display() ) else ( var mn : OclAny := Set{(cities[i+1] - cities[i - 1+1])->abs(), (cities[i+1] - cities[i + 1+1])->abs()}->min() ; var mx : OclAny := Set{(cities[i+1] - cities->first())->abs(), (cities[i+1] - cities->last())->abs()}->max() ; execute (mn)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printNonConsecutive(n): p=(1<pow(n))) ; for i : Integer.subrange(1, p-1) do ( if ((MathLib.bitwiseAnd(i, (i * (2->pow(1))))) = 0) then ( execute (i)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countMaxSetBits(left,right): while(left |(left+1))<=right : left |=left+1 return left l=1 r=5 print(countMaxSetBits(l,r)) l=1 r=10 print(countMaxSetBits(l,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var l : int := 1 ; var r : int := 5 ; execute (countMaxSetBits(l, r))->display() ; l := 1 ; r := 10 ; execute (countMaxSetBits(l, r))->display(); operation countMaxSetBits(left : OclAny, right : OclAny) : OclAny pre: true post: true activity: while ((MathLib.bitwiseOr(left, (left + 1)))->compareTo(right)) <= 0 do ( left := left or left + 1) ; return left; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxval(a,n): if(n<2): print("Invalid Input") return-9999 (max1,max2)=(0,0) for i in range(n): x=a[i]+i if(x>max1): max2=max1 max1=x elif(x>max2 and x!=max1): max2=x return(max1*max2) print(maxval([4,5,3,1,10],5)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var Sequence{max1, max2} : OclAny := Sequence{0, 0}; operation maxval(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n < 2) then ( execute ("Invalid Input")->display() ; return -9999 ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=lambda : map(int,input().split()) for _ in range(int(input())): n,k=I(); l=[*I()]; x=set(l) print('YNEOS'[1-any(k+i in x for i in l): : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := I->apply(); var l : Sequence := I->apply(); var x : Set := Set{}->union((l)) ; execute ('YNEOS'(subscript (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) - (expr (atom (name any)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (comparison (expr (expr (atom (name k))) + (expr (atom (name i))))) in (comparison (expr (atom (name x))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name l)))))))) )))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for _ in range(T): n,k=map(int,input().split()) k=abs(k) a=sorted(map(int,input().split())) ans=False start=0 end=1 cur=a[1]-a[0] while startk : if cur>k : start+=1 cur=a[end]-a[start] elif cur==k : break if ans : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, T-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : double := (k)->abs() ; var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var ans : boolean := false ; var start : int := 0 ; var end : int := 1 ; var cur : double := a[1+1] - a->first() ; while (start->compareTo(n)) < 0 do ( if (cur->compareTo(k)) < 0 & end /= n - 1 then ( end := end + 1 ; cur := a[end+1] - a[start+1] ) else (if (cur->compareTo(k)) < 0 & end = n - 1 then ( break ) else (if cur = k then ( ans := true ; break ) else ( while (cur->compareTo(k)) > 0 do ( if (cur->compareTo(k)) > 0 then ( start := start + 1 ; cur := a[end+1] - a[start+1] ) else (if cur = k then ( break ) else skip)) ) ) ) ) ; if ans then ( execute ('YES')->display() ) else ( execute ('NO')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binary_search(arr,x,i): low=i high=len(arr)-1 mid=0 while low<=high : mid=(high+low)//2 if arr[mid]x : high=mid-1 else : return True return False n=int(input()) while(n): li=[int(x)for x in input().split()] lis=[int(x)for x in input().split()] lis.sort() flag=0 for i in range(len(lis)): ele=lis[i]+li[1] if(binary_search(lis,ele,i+1)): print("YES") flag=1 break if(flag==0): print("NO") n-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (n) do ( var li : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var lis : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; lis := lis->sort() ; var flag : int := 0 ; for i : Integer.subrange(0, (lis)->size()-1) do ( var ele : OclAny := lis[i+1] + li[1+1] ; if (binary_search(lis, ele, i + 1)) then ( execute ("YES")->display() ; flag := 1 ; break ) else skip) ; if (flag = 0) then ( execute ("NO")->display() ) else skip ; n := n - 1); operation binary_search(arr : OclAny, x : OclAny, i : OclAny) : OclAny pre: true post: true activity: var low : OclAny := i ; var high : double := (arr)->size() - 1 ; var mid : int := 0 ; while (low->compareTo(high)) <= 0 do ( mid := (high + low) div 2 ; if (arr[mid+1]->compareTo(x)) < 0 then ( low := mid + 1 ) else (if (arr[mid+1]->compareTo(x)) > 0 then ( high := mid - 1 ) else ( return true ) ) ) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dig(a): count=0 ; while(a>0): a/=10 count+=1 return count def required_number(num,n,d): flag=0 power=0 a=0 for i in range(num,0,-1): power=pow(10,i) a=n % power if(d>a): flag=1 break if(flag): t=0 for j in range(0,i): t+=9*pow(10,j) if(n % power==t): print(n,end="") else : print((n-(n % power)-1),end="") else : print(n,end="") if __name__=="__main__" : n=1029 d=102 num=dig(n) required_number(num,n,d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 1029 ; d := 102 ; num := dig(n) ; required_number(num, n, d) ) else skip; operation dig(a : OclAny) : OclAny pre: true post: true activity: var count : int := 0; ; while (a > 0) do ( a := a / 10 ; count := count + 1) ; return count; operation required_number(num : OclAny, n : OclAny, d : OclAny) pre: true post: true activity: var flag : int := 0 ; var power : int := 0 ; a := 0 ; for i : Integer.subrange(0 + 1, num)->reverse() do ( power := (10)->pow(i) ; a := n mod power ; if ((d->compareTo(a)) > 0) then ( flag := 1 ; break ) else skip) ; if (flag) then ( var t : int := 0 ; for j : Integer.subrange(0, i-1) do ( t := t + 9 * (10)->pow(j)) ; if (n mod power = t) then ( execute (n)->display() ) else ( execute ((n - (n mod power) - 1))->display() ) ) else ( execute (n)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- testcase=int(input()) while testcase>=1 : total,target=map(int,input().split()); match="no" ; elements=list(map(int,input().split())); elements.sort(); start=0 ; end=1 while starttoInteger() ; while testcase >= 1 do ( var total : OclAny := null; var target : OclAny := null; Sequence{total,target} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var match : String := "no"; ; var elements : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); elements := elements->sort(); var start : int := 0; var end : int := 1 ; while (start->compareTo((elements)->size())) < 0 & (end->compareTo((elements)->size())) < 0 do ( if elements[end+1] - elements[start+1] = target then ( execute ("YES")->display(); match := "yes"; break; ) else skip ; if (elements[end+1] - elements[start+1]->compareTo(target)) < 0 then ( end := end + 1 ) else ( start := start + 1 )) ; if match = "no" then ( execute ("NO")->display() ) else skip ; testcase := testcase - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) lst=set(map(int,input().split())) for i in lst : if(i+k in lst): print("YES") break else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lst : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name lst))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (expr (atom (name i))) + (expr (atom (name k))))) in (comparison (expr (atom (name lst)))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) da=list(map(int,input().split())) Min=2 Max=2 ju=True for i in da[: :-1]: mi=(Min+i-1)//i ma=Max//i if mi*i>Max or ma*itoInteger() ; var da : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var Min : int := 2 ; var Max : int := 2 ; var ju : boolean := true ; for i : da(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( var mi : int := (Min + i - 1) div i ; var ma : int := Max div i ; if (mi * i->compareTo(Max)) > 0 or (ma * i->compareTo(Min)) < 0 then ( ju := false ; break ) else skip ; Min := mi * i ; Max := ma * i + i - 1) ; if ju then ( execute (Min)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- hairu=input() koi=hairu.split(" ") ne=input() kak=ne.split() ka=[] for ne in range(len(kak)): ka.append(int(kak[ne])) ka.sort() total=0 for i in range(int(koi[1])): total+=int(ka[i]) print(total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var hairu : String := (OclFile["System.in"]).readLine() ; var koi : OclAny := hairu.split(" ") ; var ne : String := (OclFile["System.in"]).readLine() ; var kak : OclAny := ne.split() ; var ka : Sequence := Sequence{} ; for ne : Integer.subrange(0, (kak)->size()-1) do ( execute ((("" + ((kak->at(ne))))->toInteger()) : ka)) ; ka := ka->sort() ; var total : int := 0 ; for i : Integer.subrange(0, ("" + ((koi[1+1])))->toInteger()-1) do ( total := total + ("" + ((ka[i+1])))->toInteger()) ; execute (total)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re,os from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,radians,acos,atan,asin from itertools import permutations,combinations,product,accumulate from operator import itemgetter,mul from copy import deepcopy from string import ascii_lowercase,ascii_uppercase,digits from fractions import gcd def input(): return sys.stdin.readline().strip() def STR(): return input() def INT(): return int(input()) def MAP(): return map(int,input().split()) def S_MAP(): return map(str,input().split()) def LIST(): return list(map(int,input().split())) def S_LIST(): return list(map(str,input().split())) sys.setrecursionlimit(10**9) inf=sys.maxsize mod=10**9+7 k=INT() a=LIST() l=2 r=2 for i in reversed(range(k)): l=(l+a[i]-1)//a[i]*a[i] r=r//a[i]*a[i]+a[i]-1 if l>r : print(-1) exit() print(l,r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var Math_PINFINITY : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; var mod : double := (10)->pow(9) + 7 ; var k : OclAny := INT() ; var a : OclAny := LIST() ; var l : int := 2 ; var r : int := 2 ; for i : (Integer.subrange(0, k-1))->reverse() do ( l := (l + a[i+1] - 1) div a[i+1] * a[i+1] ; r := r div a[i+1] * a[i+1] + a[i+1] - 1 ; if (l->compareTo(r)) > 0 then ( execute (-1)->display() ; exit() ) else skip) ; execute (l)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation STR() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation S_MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["String"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation S_LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["String"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys K=int(sys.stdin.readline()) A=list(map(int,sys.stdin.readline().split())) l=0 r=2*10**15 ans1=-1 while l!=r : n=(l+r)//2 res=n for a in A : res=res-res % a if res>=2 : r=n if res==2 : ans1=n else : l=n+1 l=0 r=2*10**15 ans2=-1 while l!=r : n=(l+r)//2 res=n for a in A : res=res-res % a if res<=2 : l=n+1 if res==2 : ans2=n else : r=n if ans1!=-1 : print(ans1,ans2) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : int := 0 ; var r : double := 2 * (10)->pow(15) ; var ans1 : int := -1 ; while l /= r do ( var n : int := (l + r) div 2 ; var res : int := n ; for a : A do ( res := res - res mod a) ; if res >= 2 then ( r := n ; if res = 2 then ( ans1 := n ) else skip ) else ( l := n + 1 )) ; l := 0 ; r := 2 * (10)->pow(15) ; var ans2 : int := -1 ; while l /= r do ( n := (l + r) div 2 ; res := n ; for a : A do ( res := res - res mod a) ; if res <= 2 then ( l := n + 1 ; if res = 2 then ( ans2 := n ) else skip ) else ( r := n )) ; if ans1 /= -1 then ( execute (ans1)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) nums=reversed([int(s)for s in input().split(" ")]) pass_min=2 pass_max=2 for n in nums : aaa=pass_min+(n-pass_min % n)% n bbb=pass_max-pass_max % n if aaa>pass_max or bbbtoInteger() ; var nums : Sequence := (input().split(" ")->select(s | true)->collect(s | (("" + ((s)))->toInteger())))->reverse() ; var pass_min : int := 2 ; var pass_max : int := 2 ; for n : nums do ( var aaa : int := pass_min + (n - pass_min mod n) mod n ; var bbb : double := pass_max - pass_max mod n ; if (aaa->compareTo(pass_max)) > 0 or (bbb->compareTo(pass_min)) < 0 then ( execute (-1)->display() ; exit() ) else skip ; pass_min := aaa ; pass_max := bbb + (n - 1)) ; execute (pass_min)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- K=int(input()) A=list(map(int,input().split())) if A[-1]!=2 : print(-1) exit() big=2 small=2 for i in reversed(range(K)): if small//A[i]>0 and small % A[i]>0 : small=(small//A[i]+1)*A[i] elif small//A[i]>0 and small % A[i]==0 : small=small elif small//A[i]==0 : small=A[i] big=(big//A[i])*A[i]+A[i]-1 if bigtoInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if A->last() /= 2 then ( execute (-1)->display() ; exit() ) else skip ; var big : int := 2 ; var small : int := 2 ; for i : (Integer.subrange(0, K-1))->reverse() do ( if small div A[i+1] > 0 & small mod A[i+1] > 0 then ( small := (small div A[i+1] + 1) * A[i+1] ) else (if small div A[i+1] > 0 & small mod A[i+1] = 0 then ( small := small ) else (if small div A[i+1] = 0 then ( small := A[i+1] ) else skip ) ) ; big := (big div A[i+1]) * A[i+1] + A[i+1] - 1 ; if (big->compareTo(small)) < 0 then ( execute (-1)->display() ; exit() ) else skip) ; execute (small)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) nums=list(map(int,input().split())) sub_suf=[0]*n max_suf=[0]*n total=sum(nums[: k]) sub_suf[0]=total for l in range(0,n-k): r=l+k total+=nums[r] total-=nums[l] sub_suf[l+1]=total max_suf[-1]=(sub_suf[-1],n-1) for i in range(n-2,-1,-1): if sub_suf[i]>=max_suf[i+1][0]: max_suf[i]=(sub_suf[i],i) else : max_suf[i]=max_suf[i+1] total=0 l,r=0,0 for i in range(n-k): a=max_suf[i+k][0]+sub_suf[i] if a>total : total=a l,r=i+1,max_suf[i+k][1]+1 print(l,r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var nums : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sub_suf : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var max_suf : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var total : OclAny := (nums.subrange(1,k))->sum() ; sub_suf->first() := total ; for l : Integer.subrange(0, n - k-1) do ( var r : OclAny := l + k ; total := total + nums[r+1] ; total := total - nums[l+1] ; sub_suf[l + 1+1] := total) ; max_suf->last() := Sequence{sub_suf->last(), n - 1} ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( if (sub_suf[i+1]->compareTo(max_suf[i + 1+1]->first())) >= 0 then ( max_suf[i+1] := Sequence{sub_suf[i+1], i} ) else ( max_suf[i+1] := max_suf[i + 1+1] )) ; total := 0 ; var l : OclAny := null; Sequence{l,r} := Sequence{0,0} ; for i : Integer.subrange(0, n - k-1) do ( var a : OclAny := max_suf[i + k+1]->first() + sub_suf[i+1] ; if (a->compareTo(total)) > 0 then ( total := a ; var l : OclAny := null; Sequence{l,r} := Sequence{i + 1,max_suf[i + k+1][1+1] + 1} ) else skip) ; execute (l)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=list(map(int,input().split())) x=list(map(int,input().split())) sums=[0,x[0]] def f(x): return str(x+1) for i in x[1 :]: sums.append(sums[-1]+i) dp=[] for i in range(n+1): dp.append([[0,[0,0]],[0,[0,0]],[0,[0,0]]]) for i in range(k,n+1): for j in range(1,3): first=dp[i-1][j][0] second=dp[i-k][j-1][0]+sums[i]-sums[i-k] if(j==1): if(first>=second): dp[i][j][0]=first dp[i][j][1]=[dp[i-1][j][1][0],0] else : dp[i][j][0]=second dp[i][j][1]=[i-k,0] else : if(first>=second): dp[i][j][0]=first dp[i][j][1]=dp[i-1][j][1] else : dp[i][j][0]=second dp[i][j][1]=[dp[i-k][j-1][1][0],i-k] print(*list(map(f,dp[-1][-1][1]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sums : Sequence := Sequence{0}->union(Sequence{ x->first() }) ; skip ; for i : x->tail() do ( execute ((sums->last() + i) : sums)) ; var dp : Sequence := Sequence{} ; for i : Integer.subrange(0, n + 1-1) do ( execute ((Sequence{Sequence{0}->union(Sequence{ Sequence{0}->union(Sequence{ 0 }) })}->union(Sequence{Sequence{0}->union(Sequence{ Sequence{0}->union(Sequence{ 0 }) })}->union(Sequence{ Sequence{0}->union(Sequence{ Sequence{0}->union(Sequence{ 0 }) }) }))) : dp)) ; for i : Integer.subrange(k, n + 1-1) do ( for j : Integer.subrange(1, 3-1) do ( var first : OclAny := dp[i - 1+1][j+1]->first() ; var second : double := dp[i - k+1][j - 1+1]->first() + sums[i+1] - sums[i - k+1] ; if (j = 1) then ( if ((first->compareTo(second)) >= 0) then ( dp[i+1][j+1]->first() := first ; dp[i+1][j+1][1+1] := Sequence{dp[i - 1+1][j+1][1+1]->first()}->union(Sequence{ 0 }) ) else ( dp[i+1][j+1]->first() := second ; dp[i+1][j+1][1+1] := Sequence{i - k}->union(Sequence{ 0 }) ) ) else ( if ((first->compareTo(second)) >= 0) then ( dp[i+1][j+1]->first() := first ; dp[i+1][j+1][1+1] := dp[i - 1+1][j+1][1+1] ) else ( dp[i+1][j+1]->first() := second ; dp[i+1][j+1][1+1] := Sequence{dp[i - k+1][j - 1+1][1+1]->first()}->union(Sequence{ i - k }) ) ))) ; execute ((argument * (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name f))))))) , (argument (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) ))))))))) )))))))))->display(); operation f(x : OclAny) : OclAny pre: true post: true activity: return ("" + ((MatrixLib.elementwiseAdd(x, 1)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): x,y=[int(c)for c in input().split()] print('yes' if x>3 or x>=y or(x==2 and y==3)else 'no') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := input().split()->select(c | true)->collect(c | (("" + ((c)))->toInteger())) ; execute (if x > 3 or (x->compareTo(y)) >= 0 or (x = 2 & y = 3) then 'yes' else 'no' endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def makePairs(pairs,a,b): for i in range(a,b+1,1): sumOfDigits=0 k=i while(k>0): sumOfDigits+=k % 10 k=int(k/10) if(sumOfDigits<=162): pairs.append(sumOfDigits) def countCoPrime(a,b): pairs=[] makePairs(pairs,a,b) count=0 for i in range(0,len(pairs),1): for j in range(i+1,len(pairs),1): if(gcd(pairs[i],pairs[j])==1): count+=1 return count if __name__=='__main__' : a=12 b=15 print(countCoPrime(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( a := 12 ; b := 15 ; execute (countCoPrime(a, b))->display() ) else skip; operation makePairs(pairs : OclAny, a : OclAny, b : OclAny) pre: true post: true activity: for i : Integer.subrange(a, b + 1-1)->select( $x | ($x - a) mod 1 = 0 ) do ( var sumOfDigits : int := 0 ; var k : OclAny := i ; while (k > 0) do ( sumOfDigits := sumOfDigits + k mod 10 ; k := ("" + ((k / 10)))->toInteger()) ; if (sumOfDigits <= 162) then ( execute ((sumOfDigits) : pairs) ) else skip); operation countCoPrime(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: pairs := Sequence{} ; makePairs(pairs, a, b) ; var count : int := 0 ; for i : Integer.subrange(0, (pairs)->size()-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( for j : Integer.subrange(i + 1, (pairs)->size()-1)->select( $x | ($x - i + 1) mod 1 = 0 ) do ( if (gcd(pairs[i+1], pairs[j+1]) = 1) then ( count := count + 1 ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for pratyush in range(int(input())): x,y=map(int,input().split()) if x>3 : print("YES") elif x==1 : if y==1 : print("YES") else : print("NO") else : if y<=3 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for pratyush : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if x > 3 then ( execute ("YES")->display() ) else (if x = 1 then ( if y = 1 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else ( if y <= 3 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- test=int(input()) for i in range(test): t=input().split(" ") x=int(t[0]) y=int(t[1]) if x==2 and y==3 : print('yes') continue while x3 : if x % 2==0 : x=(x*3)//2 else : x-=1 if x>=y : print("yes") else : print("no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var test : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, test-1) do ( var t : OclAny := input().split(" ") ; var x : int := ("" + ((t->first())))->toInteger() ; var y : int := ("" + ((t[1+1])))->toInteger() ; if x = 2 & y = 3 then ( execute ('yes')->display() ; continue ) else skip ; while (x->compareTo(y)) < 0 & x > 3 do ( if x mod 2 = 0 then ( x := (x * 3) div 2 ) else ( x := x - 1 )) ; if (x->compareTo(y)) >= 0 then ( execute ("yes")->display() ) else ( execute ("no")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=[int(x)for x in input().split()] nums=[int(x)for x in input().split()] print(sum(sorted(nums)[: K])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var nums : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((sorted(nums).subrange(1,K))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def _input(): return map(int,input().split()) for _ in range(int(input())): x,y=_input() if x>=y : print("YES") elif x==2 and y==3 : print("YES") elif x<=3 : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := _input() ; if (x->compareTo(y)) >= 0 then ( execute ("YES")->display() ) else (if x = 2 & y = 3 then ( execute ("YES")->display() ) else (if x <= 3 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ) ) ) ); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): x,y=map(int,input().split()) if(x==1 and y>1)or(x>1 and x<4 and y>3): print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (x = 1 & y > 1) or (x > 1 & x < 4 & y > 3) then ( execute ("NO")->display() ) else ( execute ("YES")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 2==1 or n<=4 : print(0) else : if n % 4==0 : n=n/2 if n/2-1<1 : print(1) else : h=int((n/2-1)) print(h) else : print(int(n/4)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 1 or n <= 4 then ( execute (0)->display() ) else ( if n mod 4 = 0 then ( n := n / 2 ; if n / 2 - 1 < 1 then ( execute (1)->display() ) else ( var h : int := ("" + (((n / 2 - 1))))->toInteger() ; execute (h)->display() ) ) else ( execute (("" + ((n / 4)))->toInteger())->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 2 : print(0) else : print((n//2-1)//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 then ( execute (0)->display() ) else ( execute ((n div 2 - 1) div 2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if(n % 2!=0): print("0") else : if(n % 2==0)and(n % 4!=0): n=n//4 elif(n % 4==0): n=(n//4)-1 print(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n mod 2 /= 0) then ( execute ("0")->display() ) else ( if (n mod 2 = 0) & (n mod 4 /= 0) then ( n := n div 4 ) else (if (n mod 4 = 0) then ( n := (n div 4) - 1 ) else skip) ; execute (n)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ans=0 if n<5 or n % 2==1 : ans=0 print(ans) else : n=n/2 if n % 2==0 : print(int(n/2-1)) else : ans=int(n/2) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; if n < 5 or n mod 2 = 1 then ( ans := 0 ; execute (ans)->display() ) else ( n := n / 2 ; if n mod 2 = 0 then ( execute (("" + ((n / 2 - 1)))->toInteger())->display() ) else ( ans := ("" + ((n / 2)))->toInteger() ; execute (ans)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) if n % 2!=0 : print(0) else : m=math.floor((n//2)//2) if n % 4==0 : m-=1 print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 /= 0 then ( execute (0)->display() ) else ( var m : double := ((n div 2) div 2)->floor() ; if n mod 4 = 0 then ( m := m - 1 ) else skip ; execute (m)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def centereddecagonalnum(n): return(5*n*n+5*n+1) if __name__=='__main__' : n=5 print(n,"th centered decagonal "+"number : ",centereddecagonalnum(n)) n=9 print(n,"th centered decagonal "+"number : ",centereddecagonalnum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 5 ; execute (n)->display() ; n := 9 ; execute (n)->display() ) else skip; operation centereddecagonalnum(n : OclAny) : OclAny pre: true post: true activity: return (5 * n * n + 5 * n + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def closetAND(arr,n,k): ans=sys.maxsize ; for i in range(n): X=arr[i]; for j in range(i,n): X &=arr[j]; ans=min(ans,abs(k-X)); if(X<=k): break ; return ans ; arr=[4,7,10]; n=len(arr); k=2 ; print(closetAND(arr,n,k)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{4}->union(Sequence{7}->union(Sequence{ 10 })); ; n := (arr)->size(); ; k := 2; ; execute (closetAND(arr, n, k))->display();; operation closetAND(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var ans : (trailer . (name maxsize)) := (trailer . (name maxsize)); ; for i : Integer.subrange(0, n-1) do ( var X : OclAny := arr[i+1]; ; for j : Integer.subrange(i, n-1) do ( X := X & arr[j+1]; ; ans := Set{ans, (k - X)->abs()}->min(); ; if ((X->compareTo(k)) <= 0) then ( break; ) else skip)) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findEvenPair(A,N): count=0 for i in range(N): if(not(A[i]& 1)): count+=1 return count*(count-1)//2 if __name__=="__main__" : A=[5,6,2,8] N=len(A) print(findEvenPair(A,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( A := Sequence{5}->union(Sequence{6}->union(Sequence{2}->union(Sequence{ 8 }))) ; N := (A)->size() ; execute (findEvenPair(A, N))->display() ) else skip; operation findEvenPair(A : OclAny, N : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, N-1) do ( if (not((MathLib.bitwiseAnd(A[i+1], 1)))) then ( count := count + 1 ) else skip) ; return count * (count - 1) div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin def main(): n,k=[int(x)for x in stdin.readline().rstrip().split()] p=[int(x)for x in stdin.readline().rstrip().split()] p.sort() fee=0 for i in range(k): fee+=p[i] print(fee) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := stdin.readLine().rstrip().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var p : Sequence := stdin.readLine().rstrip().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; p := p->sort() ; var fee : int := 0 ; for i : Integer.subrange(0, k-1) do ( fee := fee + p[i+1]) ; execute (fee)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,m=list(map(int,input().split())) a=set(map(int,input().split())) b=set(map(int,input().split())) found=False for x in b : if x in a : print("YES") print(1,x) found=True break if not found : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var b : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var found : boolean := false ; for x : b do ( if (a)->includes(x) then ( execute ("YES")->display() ; execute (1)->display() ; found := true ; break ) else skip) ; if not(found) then ( execute ("NO")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,m=[int(s)for s in input().split()] a=set([int(s)for s in input().split()]) b=set([int(s)for s in input().split()]) inter=a.intersection(b) if inter : print("YES") print(1,list(inter)[0]) else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; var a : Set := Set{}->union((input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())))) ; var b : Set := Set{}->union((input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())))) ; var inter : OclAny := a->intersection(b) ; if inter then ( execute ("YES")->display() ; execute (1)->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- test_cases=int(input()) for i in range(test_cases): (n,m)=map(int,input().split(' ')) elements_of_first_array=list(map(int,input().split(' '))) elements_of_second_array=list(map(int,input().split(' '))) mutual_element=[] for element in elements_of_first_array : if element in elements_of_second_array : mutual_element.append(element) break if len(mutual_element)==0 : print('NO') else : print('YES') print('1',mutual_element[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var test_cases : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, test_cases-1) do ( ; var Sequence{n, m} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var elements_of_first_array : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var elements_of_second_array : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var mutual_element : Sequence := Sequence{} ; for element : elements_of_first_array do ( if (elements_of_second_array)->includes(element) then ( execute ((element) : mutual_element) ; break ) else skip) ; if (mutual_element)->size() = 0 then ( execute ('NO')->display() ) else ( execute ('YES')->display() ; execute ('1')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from ast import Break t=int(input()) for z in range(t): n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) kol=0 for i in range(n): if a[i]in b : print("Yes") print("1 ",a[i]) break else : kol+=1 if kol==n : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for z : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var kol : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (b)->includes(a[i+1]) then ( execute ("Yes")->display() ; execute ("1 ")->display() ; break ) else ( kol := kol + 1 )) ; if kol = n then ( execute ("No")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=map(int,input().split()) s={*map(int,input().split())} s &={*map(int,input().split())} if s : print("YES\n1",s.pop()) else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Set := Set{ (input().split())->collect( _x | (OclType["int"])->apply(_x) ) } ; s := s & Set{ (input().split())->collect( _x | (OclType["int"])->apply(_x) ) } ; if s then ( execute ("YES\n1")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Find_Sequence(array,n): inc_arr,dec_arr=[],[] inc,dec=-1,1e7 for i in range(n): if incarray[i]: dec=array[i] dec_arr.append(array[i]) else : print('-1') break else : print(inc_arr,dec_arr) arr=[5,1,3,6,8,2,9,0,10] n=len(arr) Find_Sequence(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var arr : Sequence := Sequence{5}->union(Sequence{1}->union(Sequence{3}->union(Sequence{6}->union(Sequence{8}->union(Sequence{2}->union(Sequence{9}->union(Sequence{0}->union(Sequence{ 10 })))))))) ; n := (arr)->size() ; Find_Sequence(arr, n); operation Find_Sequence(array : OclAny, n : OclAny) pre: true post: true activity: var inc_arr : OclAny := null; var dec_arr : OclAny := null; Sequence{inc_arr,dec_arr} := Sequence{Sequence{},Sequence{}} ; var inc : OclAny := null; var dec : OclAny := null; Sequence{inc,dec} := Sequence{-1,("1e7")->toReal()} ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (comparison (expr (atom (name inc)))) < (comparison (expr (atom (name array)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))) < (comparison (expr (atom (name dec))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name array)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) < (comparison (expr (atom (name array)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name inc)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name array)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name inc_arr)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name array)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dec)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name array)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dec_arr)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name array)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))))))))))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name inc)))) < (comparison (expr (atom (name array)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name inc)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name array)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name inc_arr)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name array)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))))))))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name dec)))) > (comparison (expr (atom (name array)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dec)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name array)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dec_arr)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name array)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '-1'))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name inc_arr))))))) , (argument (test (logical_test (comparison (expr (atom (name dec_arr)))))))) ))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import floor,pow import sys def digitSum(n): ans=0 ; while(n): ans+=n % 10 ; n=int(n/10); return ans def findInt(n,m): minDigit=floor(m/9) start=(int(pow(10,minDigit))-int(pow(10,minDigit))% n) while(startdisplay() ) else skip; operation digitSum(n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0; ; while (n) do ( ans := ans + n mod 10; ; n := ("" + ((n / 10)))->toInteger();) ; return ans; operation findInt(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var minDigit : OclAny := floor(m / 9) ; var start : double := (("" + (((10)->pow(minDigit))))->toInteger() - ("" + (((10)->pow(minDigit))))->toInteger() mod n) ; while ((start->compareTo((trailer . (name maxsize)))) < 0) do ( if (digitSum(start) = m) then ( return start ) else ( start := start + n )) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) print(t*3//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (t * 3 div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print((n//2)*3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((n div 2) * 3)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y,z=map(int,input().split()) print(z,x,y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (z)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() b=a.split() c=input() d=c.split() N=int(b[0]) K=int(b[1]) p=[] for i in range(len(d)): p.append(int(d[i])) p.sort() ans=0 for i in range(K): ans=ans+p[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var b : OclAny := a.split() ; var c : String := (OclFile["System.in"]).readLine() ; var d : OclAny := c.split() ; var N : int := ("" + ((b->first())))->toInteger() ; var K : int := ("" + ((b[1+1])))->toInteger() ; var p : Sequence := Sequence{} ; for i : Integer.subrange(0, (d)->size()-1) do ( execute ((("" + ((d[i+1])))->toInteger()) : p)) ; p := p->sort() ; var ans : int := 0 ; for i : Integer.subrange(0, K-1) do ( ans := ans + p[i+1]) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(int(input())//2*3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (("" + (((OclFile["System.in"]).readLine())))->toInteger() div 2 * 3)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def miis(): return map(int,input().split()) n=int(input()) print(n+n//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n + n div 2)->display(); operation miis() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(n*2-n//2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (n * 2 - n div 2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- PQR=[int(i)for i in input().split()] PQR.remove(max(PQR)) ans=sum(PQR) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var PQR : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute (((PQR)->max()) /: PQR) ; var ans : OclAny := (PQR)->sum() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p,q,r=map(int,input().split()) if p>q : if p>r : print(q+r) else : print(p+q) else : if q>r : print(p+r) else : print(p+q) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : OclAny := null; var q : OclAny := null; var r : OclAny := null; Sequence{p,q,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (p->compareTo(q)) > 0 then ( if (p->compareTo(r)) > 0 then ( execute (q + r)->display() ) else ( execute (p + q)->display() ) ) else ( if (q->compareTo(r)) > 0 then ( execute (p + r)->display() ) else ( execute (p + q)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import numpy as np sr=lambda : sys.stdin.readline().rstrip() ir=lambda : int(sr()) lr=lambda : list(map(int,sr().split())) P,Q,R=lr() print(P+Q+R-max([P,Q,R])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var sr : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; var ir : Function := lambda $$ : OclAny in (("" + ((sr->apply())))->toInteger()) ; var lr : Function := lambda $$ : OclAny in (((sr->apply().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var P : OclAny := null; var Q : OclAny := null; var R : OclAny := null; Sequence{P,Q,R} := lr->apply() ; execute (P + Q + R - (Sequence{P}->union(Sequence{Q}->union(Sequence{ R })))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p,q,r=map(int,input().split()) lst=[p,q,r] A=lst[0]+lst[1] B=lst[1]+lst[2] C=lst[0]+lst[2] print(min([A,B,C])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : OclAny := null; var q : OclAny := null; var r : OclAny := null; Sequence{p,q,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lst : Sequence := Sequence{p}->union(Sequence{q}->union(Sequence{ r })) ; var A : OclAny := lst->first() + lst[1+1] ; var B : OclAny := lst[1+1] + lst[2+1] ; var C : OclAny := lst->first() + lst[2+1] ; execute ((Sequence{A}->union(Sequence{B}->union(Sequence{ C })))->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=[int(i)for i in input().split(" ")] print(sum(l)-max(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute ((l)->sum() - (l)->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) stx=input() cnt=0 for m in stx : if m=='+' : cnt+=1 elif cnt==0 and m=='-' : pass else : cnt-=1 print(max(cnt,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var stx : String := (OclFile["System.in"]).readLine() ; var cnt : int := 0 ; for m : stx->characters() do ( if m = '+' then ( cnt := cnt + 1 ) else (if cnt = 0 & m = '-' then ( skip ) else ( cnt := cnt - 1 ) ) ) ; execute (Set{cnt, 0}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- operations=int(input()) s=input() stones=0 for action in s : if action=='-' : stones-=1 else : stones+=1 if stones==-1 : stones=0 print(stones) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var operations : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var stones : int := 0 ; for action : s->characters() do ( if action = '-' then ( stones := stones - 1 ) else ( stones := stones + 1 ) ; if stones = -1 then ( stones := 0 ) else skip) ; execute (stones)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) print(sum(sorted(list(map(int,input().split())))[: k])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((sorted(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))).subrange(1,k))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(X : int,Y : int,Z : int): print("{}{}{}".format(Z,X,Y)) return def main(): def iterate_tokens(): for line in sys.stdin : for word in line.split(): yield word tokens=iterate_tokens() X=int(next(tokens)) Y=int(next(tokens)) Z=int(next(tokens)) solve(X,Y,Z) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(X : int, Y : int, Z : int) pre: true post: true activity: execute (StringLib.interpolateStrings("{}{}{}", Sequence{Z, X, Y}))->display() ; return; operation main() pre: true post: true activity: skip ; var tokens : OclIterator := OclIterator.newOclIterator_Function(lambda _i : int in self.iterate_tokens(_i)) ; var X : int := ("" + (((tokens).next())))->toInteger() ; var Y : int := ("" + (((tokens).next())))->toInteger() ; var Z : int := ("" + (((tokens).next())))->toInteger() ; solve(X, Y, Z); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) count=0 str=input() for i in str : if(i=='+'): count+=1 if(count==-1): count=0 if(i=='-'): count-=1 if(count==-1): count=0 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := 0 ; var OclType["String"] : String := (OclFile["System.in"]).readLine() ; for i : OclType["String"]->characters() do ( if (i = '+') then ( count := count + 1 ; if (count = -1) then ( count := 0 ) else skip ) else skip ; if (i = '-') then ( count := count - 1 ; if (count = -1) then ( count := 0 ) else skip ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) s=list(input().rstrip()) mi,now=0,0 for i in reversed(s): if i ^ 45 : now-=1 else : now+=1 mi=min(mi,now) ans=-mi print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := (input().rstrip()) ; var mi : OclAny := null; var now : OclAny := null; Sequence{mi,now} := Sequence{0,0} ; for i : (s)->reverse() do ( if MathLib.bitwiseXor(i, 45) then ( now := now - 1 ) else ( now := now + 1 ) ; var mi : OclAny := Set{mi, now}->min()) ; var ans : OclAny := -mi ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) stones=input() total=0 for item in stones : if item=='+' : total+=1 elif item=='-' and total>0 : total-=1 print(total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var stones : String := (OclFile["System.in"]).readLine() ; var total : int := 0 ; for item : stones->characters() do ( if item = '+' then ( total := total + 1 ) else (if item = '-' & total > 0 then ( total := total - 1 ) else skip)) ; execute (total)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printFun(test): if(test<1): return else : print(test,end=" ") printFun(test-1) print(test,end=" ") return test=3 printFun(test) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; test := 3 ; printFun(test); operation printFun(test : OclAny) pre: true post: true activity: if (test < 1) then ( return ) else ( execute (test)->display() ; printFun(test - 1) ; execute (test)->display() ; return ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000 f=[0 for i in range(MAX)] def fib(n): if(n==0): return 0 if(n==1 or n==2): f[n]=1 if(f[n]): return f[n] k=(n+1)//2 if(n & 1)else n//2 f[n]=(fib(k)*fib(k)+fib(k-1)*fib(k-1))if(n & 1)else((2*fib(k-1)+fib(k))*fib(k)) return f[n] def gcd(M,N): if(M==0): return N return gcd(N % M,M) def findGCDofFibMFibN(M,N): return fib(gcd(M,N)) M=3 N=12 print(findGCDofFibMFibN(M,N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1000 ; var f : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)) ; skip ; skip ; skip ; M := 3 ; N := 12 ; execute (findGCDofFibMFibN(M, N))->display(); operation fib(n : OclAny) : OclAny pre: true post: true activity: if (n = 0) then ( return 0 ) else skip ; if (n = 1 or n = 2) then ( f[n+1] := 1 ) else skip ; if (f[n+1]) then ( return f[n+1] ) else skip ; var k : int := if (MathLib.bitwiseAnd(n, 1)) then (n + 1) div 2 else n div 2 endif ; f[n+1] := if (MathLib.bitwiseAnd(n, 1)) then (fib(k) * fib(k) + fib(k - 1) * fib(k - 1)) else ((2 * fib(k - 1) + fib(k)) * fib(k)) endif ; return f[n+1]; operation gcd(M : OclAny, N : OclAny) : OclAny pre: true post: true activity: if (M = 0) then ( return N ) else skip ; return gcd(N mod M, M); operation findGCDofFibMFibN(M : OclAny, N : OclAny) : OclAny pre: true post: true activity: return fib(gcd(M, N)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import copy for tc in range(int(input())): n=int(input()) a=list(map(int,input().split())) if(a[n-1]=0 : if(a[x]toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if ((a[n - 1+1]->compareTo(n - 1)) < 0) then ( execute (-1)->display() ; continue ) else skip ; var c : int := 0 ; var x : double := n - 2 ; var tracker : boolean := false ; while x >= 0 do ( if ((a[x+1]->compareTo(x)) < 0) then ( execute (-1)->display() ; tracker := true ; break ) else skip ; if ((a[x + 1+1]->compareTo(a[x+1])) <= 0) then ( var y : int := a[x+1] div a[x + 1+1] ; var z : int := ("" + (()))->toInteger() + 1 ; a[x+1] := a[x+1] div (2)->pow(z) ; c := c + z ) else ( x := x - 1 )) ; if not(tracker) then ( execute (c)->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import floor,log2 num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() t=num_inp() for _ in range(t): n=num_inp() l=arr_inp() count=0 for i in range(n-2,-1,-1): if(l[i+1]==0): print(-1) break if(l[i+1]<=l[i]): val=floor(log2(l[i]/l[i+1]))+1 count+=val l[i]=floor(l[i]/(2**val)) else : print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var t : OclAny := num_inp->apply() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := num_inp->apply() ; var l : OclAny := arr_inp->apply() ; var count : int := 0 ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 2))))))))) , (argument (test (logical_test (comparison (expr (atom - (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])))) == (comparison (expr (atom (number (integer 0))))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])))) <= (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name val)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name floor)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name log2)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) / (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))))))))) ))))))))) )))) + (expr (atom (number (integer 1)))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name count)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name val))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name floor)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) / (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) ** (expr (atom (name val)))))))) ))))))))) ))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name count)))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def u(): n=int(input()) a=list(map(int,input().split())) un=0 last=a[-1] for j in range(n-2,-1,-1): if last==0 : return-1 while a[j]>=last : a[j]//=2 un+=1 last=a[j] return un for i in range(int(input())): print(u()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (u())->display()); operation u() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var un : int := 0 ; var last : OclAny := a->last() ; for j : Integer.subrange(-1 + 1, n - 2)->reverse() do ( if last = 0 then ( return -1 ) else skip ; while (a[j+1]->compareTo(last)) >= 0 do ( a[j+1] := a[j+1] div 2 ; un := un + 1) ; last := a[j+1]) ; return un; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import log t=int(input()) for _ in range(t): n=int(input()) arr=list(map(int,input().split())) cnt=0 f=True for i in range(n-1,0,-1): if arr[i]==0 : f=False break if arr[i-1]>=arr[i]: v=int(1+log(arr[i-1]//arr[i],2)) arr[i-1]>>=v cnt+=v print(cnt if f else-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : int := 0 ; var f : boolean := true ; for i : Integer.subrange(0 + 1, n - 1)->reverse() do ( if arr[i+1] = 0 then ( f := false ; break ) else skip ; if (arr[i - 1+1]->compareTo(arr[i+1])) >= 0 then ( var v : int := ("" + ((1 + log(arr[i - 1+1] div arr[i+1], 2))))->toInteger() ; arr[i - 1+1] := arr[i - 1+1] div (2->pow(v)) ; cnt := cnt + v ) else skip) ; execute (if f then cnt else -1 endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): ans=0 stack=[(1,3,1,2)] while len(stack)>0 : leftn,leftd,rightn,rightd=stack.pop() d=leftd+rightd if d<=12000 : n=leftn+rightn ans+=1 stack.append((n,d,rightn,rightd)) stack.append((leftn,leftd,n,d)) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : int := 0 ; var stack : Sequence := Sequence{ Sequence{1, 3, 1, 2} } ; while (stack)->size() > 0 do ( var leftn : OclAny := null; var leftd : OclAny := null; var rightn : OclAny := null; var rightd : OclAny := null; Sequence{leftn,leftd,rightn,rightd} := stack->last() ; stack := stack->front() ; var d : OclAny := leftd + rightd ; if d <= 12000 then ( var n : OclAny := leftn + rightn ; ans := ans + 1 ; execute ((Sequence{n, d, rightn, rightd}) : stack) ; execute ((Sequence{leftn, leftd, n, d}) : stack) ) else skip) ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def fn(arr,n): count=0 if n==1 : return count curr=arr[n-1] for i in range(n-2,-1,-1): if curr==0 : return-1 if arr[i]//curr==0 : temp=0 else : temp=int(math.log(arr[i]//curr,2))+1 curr=arr[i]//(2**temp) count+=temp return count n=int(input()) for i in range(n): m=int(input()) arr=list(map(int,input().split())) print(fn(arr,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; arr := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (fn(arr, m))->display()); operation fn(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; if n = 1 then ( return count ) else skip ; var curr : OclAny := arr[n - 1+1] ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( if curr = 0 then ( return -1 ) else skip ; if arr[i+1] div curr = 0 then ( var temp : int := 0 ) else ( temp := ("" + (((arr[i+1] div curr, 2)->log())))->toInteger() + 1 ) ; curr := arr[i+1] div ((2)->pow(temp)) ; count := count + temp) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import division,print_function try : input=raw_input except NameError : pass def make_matrix(N,M,v): ret=[] for i in range(N): l=[] for j in range(M): l.append(v) ret.append(l) return ret def solve(numbers): MAX_NUMBER=20 SIGN=[-1,+1] rightside_of_expression=numbers[-1] leftside_of_expession=numbers[:-1] way_to_make=make_matrix(len(leftside_of_expession),MAX_NUMBER+1,0) for i in range(len(leftside_of_expession)): v=leftside_of_expession[i] if i==0 : way_to_make[0][v]=1 else : for j in range(MAX_NUMBER+1): for s in SIGN : p=j+s*numbers[i] if 0<=p<=MAX_NUMBER : way_to_make[i][j]+=way_to_make[i-1][p] return way_to_make[-1][rightside_of_expression] def main(): N=int(input()) string_of_numbers=input().split(" ") numbers=[] for s in string_of_numbers : numbers.append(int(s)) print(solve(numbers)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; try ( var input : OclAny := raw_input) (except_clause except (test (logical_test (comparison (expr (atom (name NameError)))))) : (suite (stmt (simple_stmt (small_stmt pass))))) ; skip ; skip ; skip ; main(); operation make_matrix(N : OclAny, M : OclAny, v : OclAny) : OclAny pre: true post: true activity: var ret : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var l : Sequence := Sequence{} ; for j : Integer.subrange(0, M-1) do ( execute ((v) : l)) ; execute ((l) : ret)) ; return ret; operation solve(numbers : OclAny) : OclAny pre: true post: true activity: var MAX_NUMBER : int := 20 ; var SIGN : Sequence := Sequence{-1}->union(Sequence{ 1 }) ; var rightside_of_expression : OclAny := numbers->last() ; var leftside_of_expession : OclAny := numbers->front() ; var way_to_make : OclAny := make_matrix((leftside_of_expession)->size(), MAX_NUMBER + 1, 0) ; for i : Integer.subrange(0, (leftside_of_expession)->size()-1) do ( v := leftside_of_expession[i+1] ; if i = 0 then ( way_to_make->first()[v+1] := 1 ) else ( for j : Integer.subrange(0, MAX_NUMBER + 1-1) do ( for s : SIGN do ( var p : OclAny := j + s * numbers[i+1] ; if 0 <= p & (p <= MAX_NUMBER) then ( way_to_make[i+1][j+1] := way_to_make[i+1][j+1] + way_to_make[i - 1+1][p+1] ) else skip)) )) ; return way_to_make->last()[rightside_of_expression+1]; operation main() pre: true post: true activity: N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var string_of_numbers : OclAny := input().split(" ") ; numbers := Sequence{} ; for s : string_of_numbers do ( execute ((("" + ((s)))->toInteger()) : numbers)) ; execute (solve(numbers))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ls=input().split(" ") temp=ls[0] ls[0]=ls[1] ls[1]=temp temp=ls[0] ls[0]=ls[2] ls[2]=temp print(("{}{}{}").format(ls[0],ls[1],ls[2])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ls : OclAny := input().split(" ") ; var temp : OclAny := ls->first() ; ls->first() := ls[1+1] ; ls[1+1] := temp ; temp := ls->first() ; ls->first() := ls[2+1] ; ls[2+1] := temp ; execute (StringLib.interpolateStrings(("{}{}{}"), Sequence{ls->first(), ls[1+1], ls[2+1]}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : s=int(input()) if(s==0): break price=[int(input())for i in range(9)] print(s-sum(price)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var s : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (s = 0) then ( break ) else skip ; var price : Sequence := Integer.subrange(0, 9-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; execute (s - (price)->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for e in iter(input,'0'): print(int(e)-sum(int(input())for _ in[0]*9)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for e : OclIterator.newOclIterator_Sequence(input, '0') do ( execute (("" + ((e)))->toInteger() - ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])) * (expr (atom (number (integer 9))))))))))->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans=0 for i in range(50): a=int(input()) if i % 10==0 and a!=0 : ans+=a elif a!=0 : ans-=a if i % 10==9 : print(ans) ans=0 else : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, 50-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if i mod 10 = 0 & a /= 0 then ( ans := ans + a ) else (if a /= 0 then ( ans := ans - a ; if i mod 10 = 9 then ( execute (ans)->display() ; ans := 0 ) else skip ) else ( break ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(sum_val): tmp=0 for x in range(9): tmp+=int(input()) print(sum_val-tmp) ipt=int(input()) while ipt!=0 : solve(ipt) ipt=int(input()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var ipt : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while ipt /= 0 do ( solve(ipt) ; ipt := ("" + (((OclFile["System.in"]).readLine())))->toInteger()); operation solve(sum_val : OclAny) pre: true post: true activity: var tmp : int := 0 ; for x : Integer.subrange(0, 9-1) do ( tmp := tmp + ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; execute (sum_val - tmp)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : k=int(input()) if k==0 : exit() else : for i in range(9): k-=int(input()) print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if k = 0 then ( exit() ) else ( for i : Integer.subrange(0, 9-1) do ( k := k - ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; execute (k)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(k,x,y): if k % 2==0 and(x+y)% 2==1 : print(-1) return x_sign=1 ; y_sign=1 xy_inv=False if x<0 : x*=-1 x_sign=-1 if y<0 : y*=-1 y_sign=-1 if x=l : print_xy(0,now_y) now_y-=k now_x=l-now_y while now_x<=x : print_xy(now_x,l) now_x+=k now_y=l+now_x-x while now_y<=y : print_xy(x,now_y) now_y+=k return k=int(input()) x,y=map(int,input().split()) solve(k,x,y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; k := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; solve(k, x, y); operation solve(k : OclAny, x : OclAny, y : OclAny) pre: true post: true activity: if k mod 2 = 0 & (x + y) mod 2 = 1 then ( execute (-1)->display() ; return ) else skip ; var x_sign : int := 1; var y_sign : int := 1 ; var xy_inv : boolean := false ; if x < 0 then ( x := x * -1 ; x_sign := -1 ) else skip ; if y < 0 then ( y := y * -1 ; y_sign := -1 ) else skip ; if (x->compareTo(y)) < 0 then ( xy_inv := true ; Sequence{x,y} := Sequence{y,x} ) else skip ; skip ; if (x + y->compareTo(k)) < 0 & (x + y) mod 2 = 1 then ( execute (3)->display() ; var now_y : double := x - k ; print_xy(x, now_y) ; var now_x : OclAny := x + (k + x - y) div 2 ; now_y := now_y + k - (k + x - y) div 2 ; print_xy(now_x, now_y) ; print_xy(x, y) ; return ) else skip ; var c : int := (k - ((x + y) mod k)) mod k ; if (x + y->compareTo(k)) < 0 then ( var n : int := 2 ) else ( n := ((x + y + k - 1) div k) + (c mod 2) ) ; execute (n)->display() ; var ans : int := 0 ; now_y := -k ; var l : int := -(k * n - x - y) div 2 ; while (now_y->compareTo(l)) >= 0 do ( print_xy(0, now_y) ; now_y := now_y - k) ; now_x := l - now_y ; while (now_x->compareTo(x)) <= 0 do ( print_xy(now_x, l) ; now_x := now_x + k) ; now_y := l + now_x - x ; while (now_y->compareTo(y)) <= 0 do ( print_xy(x, now_y) ; now_y := now_y + k) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) readline=sys.stdin.readline k=int(input()) x,y=[int(i)for i in readline().split()] if k % 2==0 and(x+y)% 2 : print(-1) exit() ans=[(x,y)] while(abs(x)+abs(y)>2*k): if x>=k : x-=k elif x<=-k : x+=k else : d=abs(x) x=0 if y>0 : y-=(k-d) else : y+=(k-d) ans.append((x,y)) if abs(x)+abs(y)==k : pass else : if(x+y)% 2 : if x>=k : x-=k elif x<=-k : x+=k else : d=abs(x) x=0 if y>0 : y-=(k-d) else : y+=(k-d) ans.append((x,y)) sx=1 if x>0 else-1 sy=1 if y>0 else-1 x,y=abs(x),abs(y) swap=0 if x>y : swap=1 x,y=y,x x,y=(x-y+2*k)//2,(y-x)//2 if swap : x,y=y,x ans.append((x*sx,y*sy)) print(len(ans)) for i in reversed(ans): print(*i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; var readline : OclAny := (OclFile["System.in"]).readline ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := readline().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if k mod 2 = 0 & (x + y) mod 2 then ( execute (-1)->display() ; exit() ) else skip ; var ans : Sequence := Sequence{ Sequence{x, y} } ; while (((x)->abs() + (y)->abs()->compareTo(2 * k)) > 0) do ( if (x->compareTo(k)) >= 0 then ( x := x - k ) else (if (x->compareTo(-k)) <= 0 then ( x := x + k ) else ( var d : double := (x)->abs() ; var x : int := 0 ; if y > 0 then ( y := y - (k - d) ) else ( y := y + (k - d) ) ) ) ; execute ((Sequence{x, y}) : ans)) ; if (x)->abs() + (y)->abs() = k then ( skip ) else ( if (x + y) mod 2 then ( if (x->compareTo(k)) >= 0 then ( x := x - k ) else (if (x->compareTo(-k)) <= 0 then ( x := x + k ) else ( d := (x)->abs() ; x := 0 ; if y > 0 then ( y := y - (k - d) ) else ( y := y + (k - d) ) ) ) ; execute ((Sequence{x, y}) : ans) ) else skip ; var sx : int := if x > 0 then 1 else -1 endif ; var sy : int := if y > 0 then 1 else -1 endif ; var y : OclAny := null; Sequence{x,y} := Sequence{(x)->abs(),(y)->abs()} ; var swap : int := 0 ; if (x->compareTo(y)) > 0 then ( swap := 1 ; var y : OclAny := null; Sequence{x,y} := Sequence{y,x} ) else skip ; var y : OclAny := null; Sequence{x,y} := Sequence{(x - y + 2 * k) div 2,(y - x) div 2} ; if swap then ( var y : OclAny := null; Sequence{x,y} := Sequence{y,x} ) else skip ; execute ((Sequence{x * sx, y * sy}) : ans) ) ; execute ((ans)->size())->display() ; for i : (ans)->reverse() do ( execute ((argument * (test (logical_test (comparison (expr (atom (name i))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break print(str(oct(n)[2 :]).translate(str.maketrans("4567","5789"))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; execute (OclType["String"](oct(n).subrange(2+1)).translate(("" + (.maketrans("4567", "5789")))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 2==0 : ans=2**(n//2) else : ans=0 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 0 then ( var ans : double := (2)->pow((n div 2)) ) else ( ans := 0 ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- K=int(input()) X,Y=map(int,input().split()) dis=abs(X)+abs(Y) if K % 2==0 and dis % 2==1 : print(-1) exit() time=-(-dis//K) if time==1 : if dis!=K : time+=1 if(time*K)% 2!=dis % 2 : time+=1 print(time) detour=(time*K-dis)//2 Xdir=1 Ydir=1 Xdis=abs(X) Ydis=abs(Y) Xcur=0 Ycur=0 if X<0 : Xdir=-1 if Y<0 : Ydir=-1 while time : if detour>0 : if detour<=K : if Ydis>=K-detour : Xcur+=-Xdir*detour Xdis+=detour Ycur+=Ydir*(K-detour) Ydis-=K-detour detour=0 else : Ycur+=-Ydir*detour Ydis+=detour Xcur+=Xdir*(K-detour) Xdis-=K-detour detour=0 else : Ycur+=-Ydir*K Ydis+=K detour-=K else : if Xdis>=K : Xdis-=K Xcur+=Xdir*K else : Ycur+=Ydir*(K-Xdis) Ydis-=K-Xdis Xcur+=Xdir*Xdis Xdis=0 print(Xcur,Ycur) time-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var X : OclAny := null; var Y : OclAny := null; Sequence{X,Y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dis : double := (X)->abs() + (Y)->abs() ; if K mod 2 = 0 & dis mod 2 = 1 then ( execute (-1)->display() ; exit() ) else skip ; var time : int := -(-dis div K) ; if time = 1 then ( if dis /= K then ( time := time + 1 ) else skip ) else skip ; if (time * K) mod 2 /= dis mod 2 then ( time := time + 1 ) else skip ; execute (time)->display() ; var detour : int := (time * K - dis) div 2 ; var Xdir : int := 1 ; var Ydir : int := 1 ; var Xdis : double := (X)->abs() ; var Ydis : double := (Y)->abs() ; var Xcur : int := 0 ; var Ycur : int := 0 ; if X < 0 then ( Xdir := -1 ) else skip ; if Y < 0 then ( Ydir := -1 ) else skip ; while time do ( if detour > 0 then ( if (detour->compareTo(K)) <= 0 then ( if (Ydis->compareTo(K - detour)) >= 0 then ( Xcur := Xcur + -Xdir * detour ; Xdis := Xdis + detour ; Ycur := Ycur + Ydir * (K - detour) ; Ydis := Ydis - K - detour ; detour := 0 ) else ( Ycur := Ycur + -Ydir * detour ; Ydis := Ydis + detour ; Xcur := Xcur + Xdir * (K - detour) ; Xdis := Xdis - K - detour ; detour := 0 ) ) else ( Ycur := Ycur + -Ydir * K ; Ydis := Ydis + K ; detour := detour - K ) ) else ( if (Xdis->compareTo(K)) >= 0 then ( Xdis := Xdis - K ; Xcur := Xcur + Xdir * K ) else ( Ycur := Ycur + Ydir * (K - Xdis) ; Ydis := Ydis - K - Xdis ; Xcur := Xcur + Xdir * Xdis ; Xdis := 0 ) ) ; execute (Xcur)->display() ; time := time - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): K=int(input()) X,Y=map(int,input().split()) if K % 2==0 and(X+Y)% 2!=0 : print(-1) return def next_vec(x,y): if x<0 : dx,dy=next_vec(-x,y) return-dx,dy if y<0 : dx,dy=next_vec(x,-y) return dx,-dy if xtoInteger() ; var X : OclAny := null; var Y : OclAny := null; Sequence{X,Y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if K mod 2 = 0 & (X + Y) mod 2 /= 0 then ( execute (-1)->display() ; return ) else skip ; skip ; Sequence{x,y} := Sequence{0,0} ; var ans : Sequence := Sequence{} ; while Sequence{x, y} /= Sequence{X, Y} do ( var dx : OclAny := null; var dy : OclAny := null; Sequence{dx,dy} := next_vec(X - x, Y - y) ; x := x + dx ; y := y + dy ; execute ((StringLib.interpolateStrings('{}{}', Sequence{x, y})) : ans)) ; execute ((ans)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math k=int(input()) x,y=map(int,input().split()) if k % 2==0 and(x+y)% 2==1 : print(-1) exit() a=1 b=1 d=0 if x<0 : x*=-1 a=-1 if y<0 : y*=-1 b=-1 if x=temp : show_xy(temp_x,temp_y) else : temp_x=temp-temp_y temp_y=temp break while temp_x<=x : show_xy(temp_x,temp_y) temp_x+=k temp_y+=temp_x-x temp_x=x while temp_y<=y : show_xy(temp_x,temp_y) temp_y+=k ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if k mod 2 = 0 & (x + y) mod 2 = 1 then ( execute (-1)->display() ; exit() ) else skip ; var a : int := 1 ; var b : int := 1 ; var d : int := 0 ; if x < 0 then ( x := x * -1 ; a := -1 ) else skip ; if y < 0 then ( y := y * -1 ; b := -1 ) else skip ; if (x->compareTo(y)) < 0 then ( d := 1 ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{y,x} ) else skip ; skip ; if (x + y->compareTo(k)) < 0 & (x + y) mod 2 = 1 then ( execute (3)->display() ; var temp_x : OclAny := x ; var temp_y : double := x - k ; show_xy(temp_x, temp_y) ; temp_x := x + (k + x - y) div 2 ; temp_y := temp_y + k - (k + x - y) div 2 ; show_xy(temp_x, temp_y) ; temp_x := x ; temp_y := y ; show_xy(temp_x, temp_y) ; exit() ) else skip ; var c : int := (k - ((x + y) mod k)) mod k ; if (x + y->compareTo(k)) < 0 then ( var n : int := 2 ) else ( n := ((x + y) / k)->ceil() + (c mod 2) ) ; execute (n)->display() ; var ans : int := 0 ; temp_x := 0 ; temp_y := 0 ; var temp : int := -(k * n - x - y) div 2 ; while 1 do ( temp_y := temp_y - k ; if (temp_y->compareTo(temp)) >= 0 then ( show_xy(temp_x, temp_y) ) else ( temp_x := temp - temp_y ; temp_y := temp ; break )) ; while (temp_x->compareTo(x)) <= 0 do ( show_xy(temp_x, temp_y) ; temp_x := temp_x + k) ; temp_y := temp_y + temp_x - x ; temp_x := x ; while (temp_y->compareTo(y)) <= 0 do ( show_xy(temp_x, temp_y) ; temp_y := temp_y + k); operation show_xy(tx : OclAny, ty : OclAny) pre: true post: true activity: if d = 1 then ( execute (ty * a)->display() ) else ( execute (tx * a)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=list(map(int,input().split())) l2=l[1] l[1]=l[0] l[0]=l2 l3=l[2] l[2]=l[0] l[0]=l3 L=[str(a)for a in l] L=" ".join(L) print(L) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l2 : OclAny := l[1+1] ; l[1+1] := l->first() ; l->first() := l2 ; var l3 : OclAny := l[2+1] ; l[2+1] := l->first() ; l->first() := l3 ; var L : Sequence := l->select(a | true)->collect(a | (("" + ((a))))) ; L := StringLib.sumStringsWithSeparator((L), " ") ; execute (L)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def myCopy(s1,s2): for i in range(len(s1)): s2[i]=s1[i]; s1="GEEKSFORGEEKS" ; s2=['']*(len(s1)); myCopy(s1,s2); print(("".join(s2))); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s1 := "GEEKSFORGEEKS"; ; s2 := MatrixLib.elementwiseMult(Sequence{ '' }, ((s1)->size())); ; myCopy(s1, s2); ; execute ((StringLib.sumStringsWithSeparator((s2), "")))->display();; operation myCopy(s1 : OclAny, s2 : OclAny) pre: true post: true activity: for i : Integer.subrange(0, (s1)->size()-1) do ( s2[i+1] := s1[i+1];); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a,b,c=sorted(map(int,input().split())) s=[a,b,c,a,b] print(['NO','YES'][c==a+b or any(s[i]==s[i+1]and s[i+2]% 2==0 for i in range(3))]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var s : Sequence := Sequence{a}->union(Sequence{b}->union(Sequence{c}->union(Sequence{a}->union(Sequence{ b })))) ; execute (Sequence{'NO'}->union(Sequence{ 'YES' })->select(c = a + b or ((argument (test (logical_test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])))))) and (logical_test (comparison (comparison (expr (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 2)))))))))) ]))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 0))))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 3))))))))) )))))))))->exists( _x | _x = true )))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): l1,l2,l3=map(int,input().split()) if l1!=l2 and l2!=l3 and l1!=l3 : if l1==l2+l3 or l2==l1+l3 or l3==l1+l2 : print('YES') else : print('NO') elif l1==l2 and l3 % 2==0 : print('YES') elif l2==l3 and l1 % 2==0 : print('YES') elif l3==l1 and l2 % 2==0 : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var l1 : OclAny := null; var l2 : OclAny := null; var l3 : OclAny := null; Sequence{l1,l2,l3} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if l1 /= l2 & l2 /= l3 & l1 /= l3 then ( if l1 = l2 + l3 or l2 = l1 + l3 or l3 = l1 + l2 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) else (if l1 = l2 & l3 mod 2 = 0 then ( execute ('YES')->display() ) else (if l2 = l3 & l1 mod 2 = 0 then ( execute ('YES')->display() ) else (if l3 = l1 & l2 mod 2 = 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): s=list(map(int,input().split())) a,r=[],s[0] for i in s : if(i not in a): a.append(i) if(s.count(i)>1): r=i l=len(a) if(l==1): if(a[0]% 2==0): print("YES") else : print("NO") elif(l==2): ans=a[0] if(a[1]!=r): ans=a[1] if(ans % 2==0): print("YES") else : print("NO") elif(l==3): if(s[0]==s[1]+s[2]or s[1]==s[0]+s[2]or s[2]==s[1]+s[0]): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := null; var r : OclAny := null; Sequence{a,r} := Sequence{Sequence{},s->first()} ; for i : s do ( if ((a)->excludes(i)) then ( execute ((i) : a) ) else skip ; if (s->count(i) > 1) then ( var r : OclAny := i ) else skip) ; var l : int := (a)->size() ; if (l = 1) then ( if (a->first() mod 2 = 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else (if (l = 2) then ( var ans : OclAny := a->first() ; if (a[1+1] /= r) then ( ans := a[1+1] ) else skip ; if (ans mod 2 = 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else (if (l = 3) then ( if (s->first() = s[1+1] + s[2+1] or s[1+1] = s->first() + s[2+1] or s[2+1] = s[1+1] + s->first()) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for k in range(0,t): a,b,c=[int(i)for i in input().split()] if(a==b or a==c or b==c): if(a==b): if(c % 2==0): print("YES") else : print("NO") elif(a==c): if(b % 2==0): print("YES") else : print("NO") elif(b==c): if(a % 2==0): print("YES") else : print("NO") else : if(a+b==c or b+c==a or a+c==b): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for k : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if (a = b or a = c or b = c) then ( if (a = b) then ( if (c mod 2 = 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else (if (a = c) then ( if (b mod 2 = 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else (if (b = c) then ( if (a mod 2 = 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip ) ) ) else ( if (a + b = c or b + c = a or a + c = b) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a,b,c=sorted(map(int,input().split())) s=[a,b,c,a,b] print(['NO','YES'][c==a+b or any(s[i]==s[i+1]and s[i+2]% 2==0 for i in range(3))]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var s : Sequence := Sequence{a}->union(Sequence{b}->union(Sequence{c}->union(Sequence{a}->union(Sequence{ b })))) ; execute (Sequence{'NO'}->union(Sequence{ 'YES' })->select(c = a + b or ((argument (test (logical_test (logical_test (comparison (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])))))) and (logical_test (comparison (comparison (expr (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 2)))))))))) ]))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 0))))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 3))))))))) )))))))))->exists( _x | _x = true )))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) if t % 2==0 : print(2**(t//2)) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if t mod 2 = 0 then ( execute ((2)->pow((t div 2)))->display() ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import fabs,cos def cal_cos(n): accuracy=0.0001 n=n*(3.142/180.0) x1=1 cosx=x1 cosval=cos(n) i=1 denominator=2*i*(2*i-1) x1=-x1*n*n/denominator cosx=cosx+x1 i=i+1 while(accuracy<=fabs(cosval-cosx)): denominator=2*i*(2*i-1) x1=-x1*n*n/denominator cosx=cosx+x1 i=i+1 print('{0:.6}'.format(cosx)) if __name__=='__main__' : n=30 cal_cos(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( n := 30 ; cal_cos(n) ) else skip; operation cal_cos(n : OclAny) pre: true post: true activity: var accuracy : double := 0.0001 ; n := n * (3.142 / 180.0) ; var x1 : int := 1 ; var cosx : int := x1 ; var cosval : OclAny := cos(n) ; var i : int := 1 ; var denominator : double := 2 * i * (2 * i - 1) ; x1 := -x1 * n * n / denominator ; cosx := cosx + x1 ; i := i + 1 ; while ((accuracy->compareTo(fabs(cosval - cosx))) <= 0) do ( denominator := 2 * i * (2 * i - 1) ; x1 := -x1 * n * n / denominator ; cosx := cosx + x1 ; i := i + 1) ; execute (StringLib.interpolateStrings('{0:.6}', Sequence{cosx}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=list(map(int,input().split())) s=input() res=0 step=0 bo=1 long=step+d while bo and long!=n-1 : long=step+d if long>=n : long=n-1 for i in range(long,step,-1): if s[i]=='1' : step=i res+=1 bo=1 break else : bo=0 if n==2 or n-1==d : print(1) elif bo : print(res) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : String := (OclFile["System.in"]).readLine() ; var res : int := 0 ; var step : int := 0 ; var bo : int := 1 ; var long : int := step + d ; while bo & long /= n - 1 do ( long := step + d ; if (long->compareTo(n)) >= 0 then ( long := n - 1 ) else skip ; for i : Integer.subrange(step + 1, long)->reverse() do ( if s[i+1] = '1' then ( step := i ; res := res + 1 ; bo := 1 ; break ) else ( bo := 0 ))) ; if n = 2 or n - 1 = d then ( execute (1)->display() ) else (if bo then ( execute (res)->display() ) else ( execute (-1)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=list(map(int,input().split())) n=input() l1=[] d={} p=[] for i in range(len(n)): if n[i]=='1' : l1.append(i) for i in range(len(l1)-1): if l1[i+1]-l1[i]>l[-1]: print(-1) exit() for i in l1 : p=[] for j in range(1,l[-1]+1): if i+jcollect( _x | (OclType["int"])->apply(_x) )) ; var n : String := (OclFile["System.in"]).readLine() ; var l1 : Sequence := Sequence{} ; var d : OclAny := Set{} ; var p : Sequence := Sequence{} ; for i : Integer.subrange(0, (n)->size()-1) do ( if n[i+1] = '1' then ( execute ((i) : l1) ) else skip) ; for i : Integer.subrange(0, (l1)->size() - 1-1) do ( if (l1[i + 1+1] - l1[i+1]->compareTo(l->last())) > 0 then ( execute (-1)->display() ; exit() ) else skip) ; for i : l1 do ( p := Sequence{} ; for j : Integer.subrange(1, l->last() + 1-1) do ( if (i + j->compareTo((n)->size())) < 0 & n[i + j+1] = '1' then ( execute ((i + j) : p) ) else skip) ; d[i+1] := p) ; var x : int := 0 ; var count : int := 0 ; var i : int := 0 ; while x = 0 do ( i := (d.get(i)) ; if (i)->includes(l->first() - 1) then ( break ) else ( count := count + 1 ; i := (i)->max() )) ; execute (count + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=list(map(int,input().split(' '))) s=list(map(int,list(input()))) frog=0 steps_counter=0 while frogcollect( _x | (OclType["int"])->apply(_x) )) ; var s : Sequence := ((((OclFile["System.in"]).readLine())->characters())->collect( _x | (OclType["int"])->apply(_x) )) ; var frog : int := 0 ; var steps_counter : int := 0 ; while (frog->compareTo(n - 1)) < 0 do ( var next_step : int := -1 ; for i : Integer.subrange(frog + 1, Set{frog + d + 1, n}->min()-1) do ( if s[i+1] = 1 then ( next_step := i ) else skip) ; frog := next_step ; if next_step = -1 then ( steps_counter := -1 ; break ) else ( steps_counter := steps_counter + 1 )) ; execute (steps_counter)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y,z=(int(x)for x in input().split()) temp=y y=x x=temp temp=z z=x x=temp print(x,y,z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var temp : OclAny := y ; var y : OclAny := x ; var x : OclAny := temp ; temp := z ; var z : OclAny := x ; x := temp ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=map(int,input().split()) is_flower=list(input()) if is_flower[0]=="0" : print(-1) else : dp=[float("inf")for _ in range(n)] dp[0]=0 for i in range(n-1): for j in range(i+1,min(i+d+1,n)): if is_flower[j]=="1" : dp[j]=min(dp[j],dp[i]+1) if dp[n-1]==float("inf"): print(-1) else : print(dp[n-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var is_flower : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if is_flower->first() = "0" then ( execute (-1)->display() ) else ( var dp : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (("inf")))->toReal())) ; dp->first() := 0 ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(i + 1, Set{i + d + 1, n}->min()-1) do ( if is_flower[j+1] = "1" then ( dp[j+1] := Set{dp[j+1], dp[i+1] + 1}->min() ) else skip)) ; if dp[n - 1+1] = ("" + (("inf")))->toReal() then ( execute (-1)->display() ) else ( execute (dp[n - 1+1])->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,d=map(int,input().split()) s=input() ans=0 ; pos=0 ; while pos=n : break if s[pos+i]=='1' : npos=pos+i if npos==pos : break pos=npos ans+=1 if npos==n-1 : print(ans) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : String := (OclFile["System.in"]).readLine() ; var ans : int := 0; ; var pos : int := 0; ; while (pos->compareTo(n - 1)) < 0 do ( var npos : int := pos ; for i : Integer.subrange(1, d + 1-1) do ( if (pos + i->compareTo(n)) >= 0 then ( break ) else skip ; if s[pos + i+1] = '1' then ( npos := pos + i ) else skip) ; if npos = pos then ( break ) else skip ; pos := npos ; ans := ans + 1) ; if npos = n - 1 then ( execute (ans)->display() ) else ( execute (-1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkPandigital(b,n): if(len(n)='0' and n[i]<='9'): hash[ord(n[i])-ord('0')]=1 ; elif(ord(n[i])-ord('A')<=b-11): hash[ord(n[i])-ord('A')+10]=1 ; for i in range(b): if(hash[i]==0): return 0 ; return 1 ; b=13 ; n="1298450376ABC" ; if(checkPandigital(b,n)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; b := 13; ; n := "1298450376ABC"; ; if (checkPandigital(b, n)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ); operation checkPandigital(b : OclAny, n : OclAny) pre: true post: true activity: if (((n)->size()->compareTo(b)) < 0) then ( return 0; ) else skip ; var hash : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, b); ; for i : Integer.subrange(0, (n)->size()-1) do ( if (n[i+1] >= '0' & n[i+1] <= '9') then ( hash[(n[i+1])->char2byte() - ('0')->char2byte()+1] := 1; ) else (if (((n[i+1])->char2byte() - ('A')->char2byte()->compareTo(b - 11)) <= 0) then ( hash[(n[i+1])->char2byte() - ('A')->char2byte() + 10+1] := 1; ) else skip)) ; for i : Integer.subrange(0, b-1) do ( if (hash[i+1] = 0) then ( return 0; ) else skip) ; return 1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def IsPossible(s): n=len(s); count=set(); map=dict.fromkeys(s,0); for i in range(n): count.add(s[i]); map[s[i]]+=1 ; if(len(count)==1): return True ; if(len(count)>2): return False ; j=0 it=list(count)[j]; x=0 ; y=0 ; x=map[it]; j+=1 it=list(count)[j]; y=map[it]; if(abs(x-y)<=1): return True ; return False ; if __name__=="__main__" : s="aaaddad" ; if(IsPossible(s)): print("YES"); else : print("NO"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( s := "aaaddad"; ; if (IsPossible(s)) then ( execute ("YES")->display(); ) else ( execute ("NO")->display(); ) ) else skip; operation IsPossible(s : OclAny) pre: true post: true activity: var n : int := (s)->size(); ; var count : Set := Set{}->union(()); ; var map : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))); ; for i : Integer.subrange(0, n-1) do ( execute ((s[i+1]) : count); ; ([s[i+1]+1]`third)->collect( _x | ([s[i+1]+1])->apply(_x) ) := ([s[i+1]+1]`third)->collect( _x | ([s[i+1]+1])->apply(_x) ) + 1;) ; if ((count)->size() = 1) then ( return true; ) else skip ; if ((count)->size() > 2) then ( return false; ) else skip ; var j : int := 0 ; var it : OclAny := OclType["Sequence"](count)[j+1]; ; var x : int := 0; var y : int := 0; ; x := ([it+1]`third)->collect( _x | ([it+1])->apply(_x) ); ; j := j + 1 ; it := OclType["Sequence"](count)[j+1]; ; y := ([it+1]`third)->collect( _x | ([it+1])->apply(_x) ); ; if ((x - y)->abs() <= 1) then ( return true; ) else skip ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def arraySum(arr,n): x=(n+1)/2 return(arr[0]-1)*n+x*x arr=[10,11,12,13,12,11,10] n=len(arr) print(arraySum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{10}->union(Sequence{11}->union(Sequence{12}->union(Sequence{13}->union(Sequence{12}->union(Sequence{11}->union(Sequence{ 10 })))))) ; n := (arr)->size() ; execute (arraySum(arr, n))->display(); operation arraySum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var x : double := (n + 1) / 2 ; return (arr->first() - 1) * n + x * x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 2==1 : print(0) else : print(2**(n//2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 1 then ( execute (0)->display() ) else ( execute ((2)->pow((n div 2)))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,p=(int(_)for _ in input().split()) a=[input()for i in range(n)][: :-1] ans=0 apple=0 for s in a : apple*=2 if s=='halfplus' : apple+=1 ans+=p*apple//2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name _)))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var a : OclAny := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine()))(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var ans : int := 0 ; var apple : int := 0 ; for s : a do ( apple := apple * 2 ; if s = 'halfplus' then ( apple := apple + 1 ) else skip ; ans := ans + p * apple div 2) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,p=map(int,input().split()) s=[] for i in range(n): s.append(input().strip()) cnt=0 ans=0 for c in reversed(s): ans+=p*cnt cnt*=2 if c=='halfplus' : cnt+=1 ans+=p//2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var p : OclAny := null; Sequence{n,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var s : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((input()->trim()) : s)) ; var cnt : int := 0 ; var ans : int := 0 ; for c : (s)->reverse() do ( ans := ans + p * cnt ; cnt := cnt * 2 ; if c = 'halfplus' then ( cnt := cnt + 1 ; ans := ans + p div 2 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,p=map(int,input().split()) a=sum(1<collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := ((argument (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name i))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name input)) (trailer (arguments ( ))))) == (comparison (expr (atom 'halfplus'))))))))))->sum() ; execute (((argument (test (logical_test (comparison (expr (expr (expr (expr (atom (name a))) // (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (number (integer 1)))) << (expr (atom (name i)))))))) )))) * (expr (atom (name p)))) // (expr (atom (number (integer 2)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin N,P=map(int,stdin.readline().strip().split(" ")) sales=[len(stdin.readline())for n in range(N)] apples=0 profit=0 for x in reversed(sales): if x==5 : profit+=P*apples apples*=2 else : profit+=P*(apples+0.5) apples+=0.5 apples*=2 print(round(profit)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : OclAny := null; var P : OclAny := null; Sequence{N,P} := (stdin.readLine()->trim().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var sales : Sequence := Integer.subrange(0, N-1)->select(n | true)->collect(n | ((stdin.readLine())->size())) ; var apples : int := 0 ; var profit : int := 0 ; for x : (sales)->reverse() do ( if x = 5 then ( profit := profit + P * apples ; apples := apples * 2 ) else ( profit := profit + P * (apples + 0.5) ; apples := apples + 0.5 ; apples := apples * 2 )) ; execute ((profit)->round())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- money=0 apples=0 customers=[] num_customers,apple_price=[int(x)for x in(input().split(' '))] for i in range(0,num_customers): arg=input() customers.append(arg) customers=reversed(customers) for c in customers : if c=='halfplus' : money+=(apples+0.5)*float(apple_price) apples=2*apples+1 elif c=='half' : money+=(apples)*float(apple_price) apples=2*apples print(int(money)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var money : int := 0 ; var apples : int := 0 ; var customers : Sequence := Sequence{} ; var num_customers : OclAny := null; var apple_price : OclAny := null; Sequence{num_customers,apple_price} := (input().split(' '))->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for i : Integer.subrange(0, num_customers-1) do ( var arg : String := (OclFile["System.in"]).readLine() ; execute ((arg) : customers)) ; customers := (customers)->reverse() ; for c : customers do ( if c = 'halfplus' then ( money := money + (apples + 0.5) * ("" + ((apple_price)))->toReal() ; apples := 2 * apples + 1 ) else (if c = 'half' then ( money := money + (apples) * ("" + ((apple_price)))->toReal() ; apples := 2 * apples ) else skip)) ; execute (("" + ((money)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,q=map(int,input().split()) for _ in range(q): x,y=map(int,input().split()) c=(n**2+1)//2*((x+y)% 2)+(((x-1)*n+y+1)//2) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for _anon : Integer.subrange(0, q-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : int := ((n)->pow(2) + 1) div 2 * ((x + y) mod 2) + (((x - 1) * n + y + 1) div 2) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=4 def shiftMatrixByK(mat,k): if(k>N): print("shifting is"" not possible") return j=0 while(junion(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })))}->union(Sequence{Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{ 8 })))}->union(Sequence{Sequence{9}->union(Sequence{10}->union(Sequence{11}->union(Sequence{ 12 })))}->union(Sequence{ Sequence{13}->union(Sequence{14}->union(Sequence{15}->union(Sequence{ 16 }))) }))) ; k := 2 ; shiftMatrixByK(mat, k); operation shiftMatrixByK(mat : OclAny, k : OclAny) pre: true post: true activity: if ((k->compareTo(N)) > 0) then ( execute ((atom "shifting is" " not possible"))->display() ; return ) else skip ; var j : int := 0 ; while ((j->compareTo(N)) < 0) do ( for i : Integer.subrange(k, N-1) do ( execute (StringLib.interpolateStrings("{}", Sequence{mat[j+1][i+1]}))->display()) ; for i : Integer.subrange(0, k-1) do ( execute (StringLib.interpolateStrings("{}", Sequence{mat[j+1][i+1]}))->display()) ; execute ("")->display() ; j := j + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,sys from collections import defaultdict,deque import bisect as bi def yes(): print('YES') def no(): print('NO') def I(): return(int(sys.stdin.readline())) def In(): return(map(int,sys.stdin.readline().split())) def Sn(): return sys.stdin.readline().strip() def dict(a): d={} for x in a : if d.get(x,-1)!=-1 : d[x]+=1 else : d[x]=1 return d def find_gt(a,x): i=bi.bisect_left(a,x) if i!=len(a): return i else : return-1 def main(): try : a,b=In() if a>b : print(a+b) else : print(b-(b % a)//2) except : pass M=998244353 P=1000000007 if __name__=='__main__' : for _ in range(I()): main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var M : int := 998244353 ; var P : int := 1000000007 ; if __name__ = '__main__' then ( for _anon : Integer.subrange(0, I()-1) do ( main()) ) else skip; operation yes() pre: true post: true activity: execute ('YES')->display(); operation no() pre: true post: true activity: execute ('NO')->display(); operation I() : OclAny pre: true post: true activity: return (("" + (((OclFile["System.in"]).readLine())))->toInteger()); operation In() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation Sn() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation dict(a : OclAny) : OclAny pre: true post: true activity: var d : OclAny := Set{} ; for x : a do ( if d.get(x, -1) /= -1 then ( d[x+1] := d[x+1] + 1 ) else ( d[x+1] := 1 )) ; return d; operation find_gt(a : OclAny, x : OclAny) : OclAny pre: true post: true activity: var i : OclAny := bi.bisect_left(a, x) ; if i /= (a)->size() then ( return i ) else ( return -1 ); operation main() pre: true post: true activity: try ( var b : OclAny := null; Sequence{a,b} := In() ; if (a->compareTo(b)) > 0 then ( execute (a + b)->display() ) else ( execute (b - (b mod a) div 2)->display() )) catch (_e : OclException) do ( skip) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import sys import math from collections import deque,defaultdict import bisect import heapq sys.setrecursionlimit(100000) input=sys.stdin.readline def multiple(): a=map(int,input().split()) return a def array(): a=input().split() return a def intarray(): a=list(map(int,input().split())) return a def intinput(): n=int(input()) return n def strinput(): s=input().strip() return s def isPrime(n): val=int(math.sqrt(n))+1 for i in range(2,val): if n % i==0 : return False return True def power(x,y,p): res=1 x=x % p if(x==0): return 0 while(y>0): if((y & 1)==1): res=(res*x)% p y=y>>1 x=(x*x)% p return res def solution(): x,y=multiple() if y % x==0 : print(y) return if ytoInteger() ; for _anon : Integer.subrange(0, t-1) do ( solution()); operation multiple() : OclAny pre: true post: true activity: var a : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; return a; operation array() : OclAny pre: true post: true activity: a := input().split() ; return a; operation intarray() : OclAny pre: true post: true activity: a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; return a; operation intinput() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; return n; operation strinput() : OclAny pre: true post: true activity: var s : OclAny := input()->trim() ; return s; operation isPrime(n : OclAny) : OclAny pre: true post: true activity: var val : int := ("" + (((n)->sqrt())))->toInteger() + 1 ; for i : Integer.subrange(2, val-1) do ( if n mod i = 0 then ( return false ) else skip) ; return true; operation power(x : OclAny, y : OclAny, p : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; x := x mod p ; if (x = 0) then ( return 0 ) else skip ; while (y > 0) do ( if ((MathLib.bitwiseAnd(y, 1)) = 1) then ( res := (res * x) mod p ) else skip ; y := y /(2->pow(1)) ; x := (x * x) mod p) ; return res; operation solution() pre: true post: true activity: Sequence{x,y} := multiple() ; if y mod x = 0 then ( execute (y)->display() ; return ) else skip ; if (y->compareTo(x)) < 0 then ( execute (x + y)->display() ; return ) else skip ; var k : int := y mod x ; execute (y - (k div 2))->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys i=sys.stdin.readline for _ in range(int(i())): x,y=map(int,i().split()) print(x+y if x>y else y-(y % x)//2 if xtoInteger()-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (i().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (if (x->compareTo(y)) > 0 then x + y else if (x->compareTo(y)) < 0 then y - (y mod x) div 2 else x endif endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) print(0)if n % 2!=0 else print(2**(n//2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) )))))) if (logical_test (comparison (comparison (expr (expr (atom (name n))) % (expr (atom (number (integer 2)))))) != (comparison (expr (atom (number (integer 0))))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (number (integer 2)))) ** (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name n))) // (expr (atom (number (integer 2))))))))) ))))))))) )))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): my_list=list(map(int,input().split())) x=my_list[0] y=my_list[1] if x>y : ans=x+y print(ans) else : ans=int(y-((y % x)/2)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var my_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : OclAny := my_list->first() ; var y : OclAny := my_list[1+1] ; if (x->compareTo(y)) > 0 then ( var ans : OclAny := x + y ; execute (ans)->display() ) else ( ans := ("" + ((y - ((y mod x) / 2))))->toInteger() ; execute (ans)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def minValidNumber(p,q): if(q % p==0): return gcd(p,q) else : return-1 if __name__=="__main__" : p,q=2,6 ; print(minValidNumber(p,q)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( Sequence{p,q} := Sequence{2,6}; ; execute (minValidNumber(p, q))->display() ) else skip; operation minValidNumber(p : OclAny, q : OclAny) : OclAny pre: true post: true activity: if (q mod p = 0) then ( return gcd(p, q) ) else ( return -1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def permutation(arr,N): hash=[0]*(N+1); for i in range(N): hash[arr[i]]+=1 ; for i in range(1,N+1): if(hash[i]!=1): return "No" ; return "Yes" ; if __name__=="__main__" : arr=[1,1,5,5,3]; n=len(arr); print(permutation(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{1}->union(Sequence{5}->union(Sequence{5}->union(Sequence{ 3 })))); ; var n : int := (arr)->size(); ; execute (permutation(arr, n))->display(); ) else skip; operation permutation(arr : OclAny, N : OclAny) pre: true post: true activity: var hash : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)); ; for i : Integer.subrange(0, N-1) do ( hash[arr[i+1]+1] := hash[arr[i+1]+1] + 1;) ; for i : Integer.subrange(1, N + 1-1) do ( if (hash[i+1] /= 1) then ( return "No"; ) else skip) ; return "Yes";; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque def main(): N=int(input()) A=deque(sorted(list(map(int,input().split())))) ans=A.pop() for i in range(N-2): if i % 2==0 : x=A.pop() ans+=x print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort()) ; var ans : OclAny := A->last() ; A := A->front() ; for i : Integer.subrange(0, N - 2-1) do ( if i mod 2 = 0 then ( var x : OclAny := A->last() ; A := A->front() ) else skip ; ans := ans + x) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- printn=lambda x : print(x,end='') inn=lambda : int(input()) inl=lambda : list(map(int,input().split())) inm=lambda : map(int,input().split()) ins=lambda : input().strip() DBG=True BIG=10**18 R=10**9+7 def ddprint(x): if DBG : print(x) n=inn() a=inl() a.sort(reverse=True) sm=0 for i in range(1,n): sm+=a[i//2] print(sm) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var printn : Function := lambda x : OclAny in ((x)->display()) ; var inn : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var inl : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var inm : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ins : Function := lambda $$ : OclAny in (input()->trim()) ; var DBG : boolean := true ; var BIG : double := (10)->pow(18) ; var R : double := (10)->pow(9) + 7 ; skip ; var n : OclAny := inn->apply() ; var a : OclAny := inl->apply() ; a := a->sort() ; var sm : int := 0 ; for i : Integer.subrange(1, n-1) do ( sm := sm + a[i div 2+1]) ; execute (sm)->display(); operation ddprint(x : OclAny) pre: true post: true activity: if DBG then ( execute (x)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,*a=map(int,open(0).read().split()) a.sort(reverse=True) ans=a[0] if n % 2==0 : for i in range(1,n//2): ans+=a[i]*2 else : for i in range(1,int(n/2)): ans+=a[i]*2 ans+=a[i+1] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := a->sort() ; var ans : OclAny := a->first() ; if n mod 2 = 0 then ( for i : Integer.subrange(1, n div 2-1) do ( ans := ans + a[i+1] * 2) ) else ( for i : Integer.subrange(1, ("" + ((n / 2)))->toInteger()-1) do ( ans := ans + a[i+1] * 2) ; ans := ans + a[i + 1+1] ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline m=1 def solve(): n,q=map(int,input().split()) m=(n*n+1)//2 for i in range(q): x,y=map(int,input().split(" ")) r=((x-1)*n+y+1)//2 if(x+y)% 2==1 : r+=m print(r) for i in range(m): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var m : int := 1 ; skip ; for i : Integer.subrange(0, m-1) do ( solve()); operation solve() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; m := (n * n + 1) div 2 ; for i : Integer.subrange(0, q-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var r : int := ((x - 1) * n + y + 1) div 2 ; if (x + y) mod 2 = 1 then ( r := r + m ) else skip ; execute (r)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from functools import reduce from collections import deque import sys sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline().strip() def get_nums_l(): return[int(s)for s in input().split(" ")] def get_all_int(): return map(int,open(0).read().split()) def log(*args): print("DEBUG:",*args,file=sys.stderr) def main(): INF=999999999999999999999999 MOD=10**9+7 n,*A=get_all_int() A=list(A) A.sort(reverse=True) c=1 ans=A[0] i=1 flag=False while(cpow(7)) ; skip ; skip ; skip ; skip ; skip ; main(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation get_nums_l() : OclAny pre: true post: true activity: return input().split(" ")->select(s | true)->collect(s | (("" + ((s)))->toInteger())); operation get_all_int() : OclAny pre: true post: true activity: return (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ); operation log(args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) execute ("DEBUG:")->display(); operation main() pre: true post: true activity: var INF : double := 999999999999999999999999 ; var MOD : double := (10)->pow(9) + 7 ; var n : OclAny := null; var A : OclAny := null; Sequence{n,A} := get_all_int() ; var A : Sequence := (A) ; A := A->sort() ; var c : int := 1 ; var ans : OclAny := A->first() ; var i : int := 1 ; var flag : boolean := false ; while ((c->compareTo(n - 1)) < 0) do ( ans := ans + A[i+1] ; c := c + 1 ; if flag then ( i := i + 1 ; flag := false ) else ( flag := true )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=2*list(map(int,input().split())) A.sort() print(sum(A[N :-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := MatrixLib.elementwiseMult(((input().split())->collect( _x | (OclType["int"])->apply(_x) )), 2) ; A := A->sort() ; execute ((A.subrange(N+1, -1))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n,n1,n2=map(int,input().split()) arr=list(map(int,input().split())) arr.sort(reverse=True) if n1>n2 : n1,n2=n2,n1 print(sum(arr[: n1])/n1+sum(arr[n1 : n1+n2])/n2) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: var n : OclAny := null; var n1 : OclAny := null; var n2 : OclAny := null; Sequence{n,n1,n2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := arr->sort() ; if (n1->compareTo(n2)) > 0 then ( var n1 : OclAny := null; var n2 : OclAny := null; Sequence{n1,n2} := Sequence{n2,n1} ) else skip ; execute ((arr.subrange(1,n1))->sum() / n1 + (arr.subrange(n1+1, n1 + n2))->sum() / n2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inp=int(input()) lista=[] lista=[int(x)for x in input().split()] for i in range(len(lista)): if i==0 : print(f"{lista[i+1]-lista[i]}{lista[len(lista)-1]-lista[i]}") continue elif i==len(lista)-1 : print(f"{lista[len(lista)-1]-lista[len(lista)-2]}{lista[len(lista)-1]-lista[0]}") continue elif lista[i]-lista[i-1]>lista[i+1]-lista[i]: print(lista[i+1]-lista[i],end=" ") else : print(lista[i]-lista[i-1],end=" ") if lista[len(lista)-1]-lista[i]>lista[i]-lista[0]: print(lista[len(lista)-1]-lista[i]) else : print(lista[i]-lista[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inp : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lista : Sequence := Sequence{} ; lista := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for i : Integer.subrange(0, (lista)->size()-1) do ( if i = 0 then ( execute (StringLib.formattedString("{lista[i+1]-lista[i]}{lista[len(lista)-1]-lista[i]}"))->display() ; continue ) else (if i = (lista)->size() - 1 then ( execute (StringLib.formattedString("{lista[len(lista)-1]-lista[len(lista)-2]}{lista[len(lista)-1]-lista[0]}"))->display() ; continue ) else (if (lista[i+1] - lista[i - 1+1]->compareTo(lista[i + 1+1] - lista[i+1])) > 0 then ( execute (lista[i + 1+1] - lista[i+1])->display() ) else ( execute (lista[i+1] - lista[i - 1+1])->display() ) ) ) ; if (lista[(lista)->size() - 1+1] - lista[i+1]->compareTo(lista[i+1] - lista->first())) > 0 then ( execute (lista[(lista)->size() - 1+1] - lista[i+1])->display() ) else ( execute (lista[i+1] - lista->first())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline from statistics import mean n,n1,n2=map(int,input().split()) w=sorted(map(int,input().split())) n1,n2=sorted([n1,n2]) a=mean(w[n-n1 :]) b=mean(w[n-n1-n2 : n-n1]) print(a+b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var n : OclAny := null; var n1 : OclAny := null; var n2 : OclAny := null; Sequence{n,n1,n2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var n1 : OclAny := null; var n2 : OclAny := null; Sequence{n1,n2} := Sequence{n1}->union(Sequence{ n2 })->sort() ; var a : OclAny := mean(w.subrange(n - n1+1)) ; var b : OclAny := mean(w.subrange(n - n1 - n2+1, n - n1)) ; execute (a + b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def _input(): return map(int,input().split()) n,n1,n2=_input() m=min(n1,n2) M=max(n1,n2) lst=list(_input()) arr=sorted(list(set(lst)),reverse=True) l={} for i in lst : if i not in l : l[i]=1 else : l[i]+=1 r1=0 ; r2=0 ; i=0 ; j=-1 while imin() ; var M : OclAny := Set{n1, n2}->max() ; var lst : Sequence := (_input()) ; var arr : Sequence := (Set{}->union((lst)))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var l : OclAny := Set{} ; for i : lst do ( if (l)->excludes(i) then ( l[i+1] := 1 ) else ( l[i+1] := l[i+1] + 1 )) ; var r1 : int := 0; var r2 : int := 0; var i : int := 0; var j : int := -1 ; while (i->compareTo(m)) < 0 do ( j := j + 1 ; var k : OclAny := Set{l[arr[j+1]+1], (m - i)}->min() ; r1 := r1 + (k * arr[j+1]) ; l[arr[j+1]+1] := l[arr[j+1]+1] - k ; i := i + k) ; r1 := r1 / m ; if l[arr[j+1]+1] = 0 then ( j := j + 1 ) else skip ; i := 0 ; while (i->compareTo(M)) < 0 do ( k := Set{l[arr[j+1]+1], (M - i)}->min() ; r2 := r2 + (k * arr[j+1]) ; l[arr[j+1]+1] := l[arr[j+1]+1] - k ; j := j + 1 ; i := i + k) ; r2 := r2 / M ; execute (r1 + r2)->display(); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def _input(): return map(int,input().split()) n,n1,n2=_input() m=min(n1,n2) M=max(n1,n2) lst=sorted(list(_input()),reverse=True) print(sum(lst[: m])/m+sum(lst[m : m+M])/M) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var n1 : OclAny := null; var n2 : OclAny := null; Sequence{n,n1,n2} := _input() ; var m : OclAny := Set{n1, n2}->min() ; var M : OclAny := Set{n1, n2}->max() ; var lst : Sequence := (_input())->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; execute ((lst.subrange(1,m))->sum() / m + (lst.subrange(m+1, m + M))->sum() / M)->display(); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(b,c,v): v.sort() if b>c : b,c=c,b n=len(v) i=n-1 ansx=0 ansy=0 while i>=n-b-c : if i>=n-b : ansx+=v[i] else : ansy+=v[i] i-=1 ans=ansx/b+ansy/c return ans n,b,c=map(int,input().split()) v=list(map(int,input().split())) print(solve(b,c,v)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{n,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; v := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (solve(b, c, v))->display(); operation solve(b : OclAny, c : OclAny, v : OclAny) : OclAny pre: true post: true activity: v := v->sort() ; if (b->compareTo(c)) > 0 then ( Sequence{b,c} := Sequence{c,b} ) else skip ; var n : int := (v)->size() ; var i : double := n - 1 ; var ansx : int := 0 ; var ansy : int := 0 ; while (i->compareTo(n - b - c)) >= 0 do ( if (i->compareTo(n - b)) >= 0 then ( ansx := ansx + v[i+1] ) else ( ansy := ansy + v[i+1] ) ; i := i - 1) ; var ans : double := ansx / b + ansy / c ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def lcm(x,y): temp=(x*y)//gcd(x,y); return temp ; def findNumbers(a,n,b,m): lcmA=1 ; __gcdB=0 ; for i in range(n): lcmA=lcm(lcmA,a[i]); for i in range(m): __gcdB=gcd(__gcdB,b[i]); if(__gcdB % lcmA!=0): print("-1"); return ; num=lcmA ; while(num<=__gcdB): if(__gcdB % num==0): print(num,end=" "); num+=lcmA ; if __name__=="__main__" : a=[1,2,2,4]; b=[16,32,64]; n=len(a); m=len(b); findNumbers(a,n,b,m); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( a := Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 4 }))); ; b := Sequence{16}->union(Sequence{32}->union(Sequence{ 64 })); ; n := (a)->size(); ; m := (b)->size(); ; findNumbers(a, n, b, m); ) else skip; operation lcm(x : OclAny, y : OclAny) pre: true post: true activity: var temp : int := (x * y) div gcd(x, y); ; return temp;; operation findNumbers(a : OclAny, n : OclAny, b : OclAny, m : OclAny) : OclAny pre: true post: true activity: var lcmA : int := 1; var __gcdB : int := 0; ; for i : Integer.subrange(0, n-1) do ( lcmA := lcm(lcmA, a[i+1]);) ; for i : Integer.subrange(0, m-1) do ( __gcdB := gcd(__gcdB, b[i+1]);) ; if (__gcdB mod lcmA /= 0) then ( execute ("-1")->display(); ; return; ) else skip ; var num : int := lcmA; ; while ((num->compareTo(__gcdB)) <= 0) do ( if (__gcdB mod num = 0) then ( execute (num)->display(); ) else skip ; num := num + lcmA;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def print_result(a,n,k,m): v=[[]for i in range(m)] for i in range(0,n): rem=a[i]% m v[rem].append(a[i]) if(len(v[rem])==k): for j in range(0,k): print(v[rem][j],end=" ") return print(-1) if __name__=='__main__' : a=[1,8,4] n=len(a) print_result(a,n,2,3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := Sequence{1}->union(Sequence{8}->union(Sequence{ 4 })) ; n := (a)->size() ; print_result(a, n, 2, 3) ) else skip; operation print_result(a : OclAny, n : OclAny, k : OclAny, m : OclAny) pre: true post: true activity: var v : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, n-1) do ( var rem : int := a[i+1] mod m ; (expr (atom (name v)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name rem)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))) ; if ((v[rem+1])->size() = k) then ( for j : Integer.subrange(0, k-1) do ( execute (v[rem+1][j+1])->display()) ; return ) else skip) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) c=int(input()) d=int(input()) ans_b=min([a,b]) ans_t=min([c,d]) print(ans_b+ans_t) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans_b : OclAny := (Sequence{a}->union(Sequence{ b }))->min() ; var ans_t : OclAny := (Sequence{c}->union(Sequence{ d }))->min() ; execute (ans_b + ans_t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math class Table(): def __init__(self,n): self.n=n def give_adress(self,y,x): odd_mode=True n=self.n starter=(n**2)//2+((n**2)% 2)+1 if(y+x)% 2==0 : odd_mode=False if not odd_mode : starter=1 if n % 2==0 : line_1=n//2 line_2=n//2 else : line_1=n-n//2 line_2=n//2 else : starter=(n**2)//2+((n**2)% 2) if n % 2==0 : line_1=n//2 line_2=n//2 else : line_2=n-n//2 line_1=n//2 count_lines=y-1 at_the_start=(line_2*(count_lines//2))+line_1*(count_lines-count_lines//2) if odd_mode : at_the_start+=starter x-=1 times=x//2 at_the_start+=times+1 return at_the_start def main(): n,q=[int(i)for i in input().split(" ")] table=Table(n) collector=[] for i in range(q): y,x=[int(i)for i in input().split(" ")] collector.append(table.give_adress(y,x)) for i in collector : print(i) main() ------------------------------------------------------------ OCL File: --------- class Table { static operation newTable() : Table pre: true post: Table->exists( _x | result = _x ); attribute n : OclAny := n; operation initialise(n : OclAny) : pre: true post: true activity: self.n := n; return self; operation give_adress(y : OclAny,x : OclAny) : OclAny pre: true post: true activity: var odd_mode : boolean := true ; n := self.n ; var starter : int := ((n)->pow(2)) div 2 + (((n)->pow(2)) mod 2) + 1 ; if (y + x) mod 2 = 0 then ( odd_mode := false ) else skip ; if not(odd_mode) then ( starter := 1 ; if n mod 2 = 0 then ( var line starter := 1 : int := n div 2 ; var line:= n div 2 : int := n div 2 ) else ( line starter := 1 := n - n div 2 ; line:= n div 2 := n div 2 ) ) else ( starter := ((n)->pow(2)) div 2 + (((n)->pow(2)) mod 2) ; if n mod 2 = 0 then ( line starter := ((n)->pow(2)) div 2 + (((n)->pow(2)) mod 2) := n div 2 ; line:= n div 2 := n div 2 ) else ( line:= n - n div 2 := n - n div 2 ; line line:= n - n div 2 := n - n div 2 := n div 2 ) ) ; var count_lines : double := y - 1 ; var at_the_start : int := (line(count_lines div 2) * (count_lines div 2)) + line var odd_mode : boolean := true * (count_lines - count_lines div 2) ; if odd_mode then ( at_the_start := at_the_start + starter ) else skip ; x := x - 1 ; var times : int := x div 2 ; at_the_start := at_the_start + times + 1 ; return at_the_start; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; main(); operation main() pre: true post: true activity: var q : OclAny := null; Sequence{n,q} := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var table : Table := (Table.newTable()).initialise(n) ; var collector : Sequence := Sequence{} ; for i : Integer.subrange(0, q-1) do ( Sequence{y,x} := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute ((table.give_adress(y, x)) : collector)) ; for i : collector do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A=int(input()) B=int(input()) C=int(input()) D=int(input()) sum=0 if A>B : sum+=B else : sum+=A if C>D : print(sum+D) else : print(sum+C) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var C : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var D : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sum : int := 0 ; if (A->compareTo(B)) > 0 then ( sum := sum + B ) else ( sum := sum + A ) ; if (C->compareTo(D)) > 0 then ( execute (sum + D)->display() ) else ( execute (sum + C)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cost=[int(input())for _ in range(4)] print(min(cost[0],cost[1])+min(cost[2],cost[3])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var cost : Sequence := Integer.subrange(0, 4-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; execute (Set{cost->first(), cost[1+1]}->min() + Set{cost[2+1], cost[3+1]}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 2!=0 : print(0) else : print(int(2**(n/2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 /= 0 then ( execute (0)->display() ) else ( execute (("" + (((2)->pow((n / 2)))))->toInteger())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def resolve(): A=int(input()) B=int(input()) C=int(input()) D=int(input()) print(min([A,B])+min([C,D])) if '__main__'==__name__ : resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if '__main__' = __name__ then ( resolve() ) else skip; operation resolve() pre: true post: true activity: var A : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var B : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var C : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var D : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((Sequence{A}->union(Sequence{ B }))->min() + (Sequence{C}->union(Sequence{ D }))->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- aa=[input()for _ in range(4)] a,b,c,d=map(int,aa) print(min(a,b)+min(c,d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var aa : Sequence := Integer.subrange(0, 4-1)->select(_anon | true)->collect(_anon | ((OclFile["System.in"]).readLine())) ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (aa)->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{a, b}->min() + Set{c, d}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findPair(arr,n): found=False for i in range(0,n): for j in range(i+1,n): for k in range(0,n): if(arr[i]+arr[j]==arr[k]): print(arr[i],arr[j]) found=True if(found==False): print("Not exist") if __name__=='__main__' : arr=[10,4,8,13,5] n=len(arr) findPair(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{10}->union(Sequence{4}->union(Sequence{8}->union(Sequence{13}->union(Sequence{ 5 })))) ; n := (arr)->size() ; findPair(arr, n) ) else skip; operation findPair(arr : OclAny, n : OclAny) pre: true post: true activity: var found : boolean := false ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( for k : Integer.subrange(0, n-1) do ( if (arr[i+1] + arr[j+1] = arr[k+1]) then ( execute (arr[i+1])->display() ; found := true ) else skip))) ; if (found = false) then ( execute ("Not exist")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findFlips(str,n): last=' ' res=0 for i in range(n): if(last!=str[i]): res+=1 last=str[i] return res//2 if __name__=="__main__" : str="00011110001110" n=len(str) print(findFlips(str,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( OclType["String"] := "00011110001110" ; n := (OclType["String"])->size() ; execute (findFlips(OclType["String"], n))->display() ) else skip; operation findFlips(OclType["String"] : OclAny, n : OclAny) : OclAny pre: true post: true activity: var last : String := ' ' ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (last /= ("" + ([i+1]))) then ( res := res + 1 ) else skip ; last := ("" + ([i+1]))) ; return res div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=1000000007 N,M=(int(x)for x in input().split()) pow=[0]*(N+1) dp=[0]*(N+1) pow[0]=1 for i in range(1,N+1): pow[i]=pow[i-1]*2 pow[i]%=MOD dp[0]=1 for i in range(1,M+1): dp[i]=pow[i] dp[M]-=1 for i in range(M+1,N+1): dp[i]=dp[i-1]+(dp[i-1]-dp[i-1-M]) dp[i]%=MOD print((pow[N]-dp[N]+MOD)% MOD) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : int := 1000000007 ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var pow : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; (->first())->pow(->first()`third) := 1 ; for i : Integer.subrange(1, N + 1-1) do ( ([i+1])->pow([i+1]`third) := ([i - 1+1])->pow([i - 1+1]`third) * 2 ; ([i+1])->pow([i+1]`third) := ([i+1])->pow([i+1]`third) mod MOD) ; dp->first() := 1 ; for i : Integer.subrange(1, M + 1-1) do ( dp[i+1] := ([i+1])->pow([i+1]`third)) ; dp[M+1] := dp[M+1] - 1 ; for i : Integer.subrange(M + 1, N + 1-1) do ( dp[i+1] := dp[i - 1+1] + (dp[i - 1+1] - dp[i - 1 - M+1]) ; dp[i+1] := dp[i+1] mod MOD) ; execute ((([N+1])->pow([N+1]`third) - dp[N+1] + MOD) mod MOD)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findStartIndexOfArray(arr,low,high): if(low>high): return-1 ; if(low==high): return low ; mid=low+(high-low)/2 ; if(arr[mid]>arr[mid+1]): return mid+1 ; if(arr[mid-1]>arr[mid]): return mid ; if(arr[low]>arr[mid]): return findStartIndexOfArray(arr,low,mid-1); else : return findStartIndexOfArray(arr,mid+1,high); def restoreSortedArray(arr,n): if(arr[0]union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))); ; n := (arr)->size(); ; restoreSortedArray(arr, n); ; printArray(arr, n); ) else skip; operation findStartIndexOfArray(arr : OclAny, low : OclAny, high : OclAny) pre: true post: true activity: if ((low->compareTo(high)) > 0) then ( return -1; ) else skip ; if (low = high) then ( return low; ) else skip ; var mid : OclAny := low + (high - low) / 2; ; if ((arr[mid+1]->compareTo(arr[mid + 1+1])) > 0) then ( return mid + 1; ) else skip ; if ((arr[mid - 1+1]->compareTo(arr[mid+1])) > 0) then ( return mid; ) else skip ; if ((arr[low+1]->compareTo(arr[mid+1])) > 0) then ( return findStartIndexOfArray(arr, low, mid - 1); ) else ( return findStartIndexOfArray(arr, mid + 1, high); ); operation restoreSortedArray(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: if ((arr->first()->compareTo(arr[n - 1+1])) < 0) then ( return; ) else skip ; var start : OclAny := findStartIndexOfArray(arr, 0, n - 1); ; reverse(arr, 0, start); ; reverse(arr, start, n); ; reverse(arr);; operation printArray(arr : OclAny, size : OclAny) pre: true post: true activity: for i : Integer.subrange(0, size-1) do ( execute (arr[i+1])->display();); operation reverse(arr : OclAny, i : OclAny, j : OclAny) pre: true post: true activity: while ((i->compareTo(j)) < 0) do ( var temp : OclAny := arr[i+1]; ; arr[i+1] := arr[j+1]; ; arr[j+1] := temp; ; i := i + 1; ; j := j - 1;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def candies(n,k): count=0 ; ind=1 ; arr=[0]*k ; low=0 ; high=n ; while(low<=high): mid=(low+high)>>1 ; sum=(mid*(mid+1))>>1 ; if(sum<=n): count=int(mid/k); low=mid+1 ; else : high=mid-1 ; last=(count*k); n-=int((last*(last+1))/2); i=0 ; term=(count*k)+1 ; while(n): if(term<=n): arr[i]=term ; i+=1 ; n-=term ; term+=1 ; else : arr[i]+=n ; n=0 ; for i in range(k): arr[i]+=((count*(i+1))+int(k*(count*(count-1))/2)); for i in range(k): print(arr[i],end=" "); n=7 ; k=4 ; candies(n,k); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 7; ; k := 4; ; candies(n, k);; operation candies(n : OclAny, k : OclAny) pre: true post: true activity: var count : int := 0; ; var ind : int := 1; ; var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, k); ; var low : int := 0; ; var high : OclAny := n; ; while ((low->compareTo(high)) <= 0) do ( var mid : int := (low + high) /(2->pow(1)); ; var sum : int := (mid * (mid + 1)) /(2->pow(1)); ; if ((sum->compareTo(n)) <= 0) then ( count := ("" + ((mid / k)))->toInteger(); ; low := mid + 1; ) else ( high := mid - 1; )) ; var last : double := (count * k); ; n := n - ("" + (((last * (last + 1)) / 2)))->toInteger(); ; var i : int := 0; ; var term : double := (count * k) + 1; ; while (n) do ( if ((term->compareTo(n)) <= 0) then ( arr[i+1] := term; ; i := i + 1; ; n := n - term; ; term := term + 1; ) else ( arr[i+1] := arr[i+1] + n; ; n := 0; )) ; for i : Integer.subrange(0, k-1) do ( arr[i+1] := arr[i+1] + ((count * (i + 1)) + ("" + ((k * (count * (count - 1)) / 2)))->toInteger());) ; for i : Integer.subrange(0, k-1) do ( execute (arr[i+1])->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math ; cups=[int(x)for x in input().split()] medals=[int(x)for x in input().split()] n=int(input()) numCups,numMedals=0,0 for c in cups : numCups+=c for m in medals : numMedals+=m requiredShelves=0 requiredShelves+=math.ceil(numCups/5) requiredShelves+=math.ceil(numMedals/10) if requiredShelves<=n : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; ; var cups : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var medals : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var numCups : OclAny := null; var numMedals : OclAny := null; Sequence{numCups,numMedals} := Sequence{0,0} ; for c : cups do ( numCups := numCups + c) ; for m : medals do ( numMedals := numMedals + m) ; var requiredShelves : int := 0 ; requiredShelves := requiredShelves + (numCups / 5)->ceil() ; requiredShelves := requiredShelves + (numMedals / 10)->ceil() ; if (requiredShelves->compareTo(n)) <= 0 then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- size,num_queries=input().split() size=int(size) num_queries=int(num_queries) def get_num(j,k): if(j+k)% 2==0 : return(size*j+k)//2+1 else : return get_num(size-1,size-1)+(size*j+k)//2+1 for i in range(num_queries): j,k=input().split() j=int(j)-1 k=int(k)-1 print(get_num(j,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var size : OclAny := null; var num_queries : OclAny := null; Sequence{size,num_queries} := input().split() ; var size : int := ("" + ((size)))->toInteger() ; var num_queries : int := ("" + ((num_queries)))->toInteger() ; skip ; for i : Integer.subrange(0, num_queries-1) do ( Sequence{j,k} := input().split() ; j := ("" + ((j)))->toInteger() - 1 ; k := ("" + ((k)))->toInteger() - 1 ; execute (get_num(j, k))->display()); operation get_num(j : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (j + k) mod 2 = 0 then ( return (size * j + k) div 2 + 1 ) else ( return get_num(size - 1, size - 1) + (size * j + k) div 2 + 1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=list(map(int,input().split())) b=list(map(int,input().split())) shelves=int(input()) out=0 temp=0 for n in a : temp+=n out+=temp//5 if(temp % 5!=0): out+=1 temp=0 for n in b : temp+=n out+=temp//10 if(temp % 10!=0): out+=1 print("YES" if shelves>=out else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var shelves : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var out : int := 0 ; var temp : int := 0 ; for n : a do ( temp := temp + n) ; out := out + temp div 5 ; if (temp mod 5 /= 0) then ( out := out + 1 ) else skip ; temp := 0 ; for n : b do ( temp := temp + n) ; out := out + temp div 10 ; if (temp mod 10 /= 0) then ( out := out + 1 ) else skip ; execute (if (shelves->compareTo(out)) >= 0 then "YES" else "NO" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a,b,h,m=map(int,input().split()) theta_h=2.5*math.pi-(2*math.pi*((h+(m/60))/12)) theta_m=2.5*math.pi-(2*math.pi*(m/60)) x_h=a*math.cos(theta_h) y_h=a*math.sin(theta_h) x_m=b*math.cos(theta_m) y_m=b*math.sin(theta_m) print(((x_h-x_m)**2+(y_h-y_m)**2)**0.5) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; var h : OclAny := null; var m : OclAny := null; Sequence{a,b,h,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var theta_h : double := 2.5 * - (2 * * ((h + (m / 60)) / 12)) ; var theta_m : double := 2.5 * - (2 * * (m / 60)) ; var x_h : double := a * ; var y_h : double := a * (theta_h)->sin() ; var x_m : double := b * ; var y_m : double := b * (theta_m)->sin() ; execute (((((x_h - x_m))->pow(2) + ((y_h - y_m))->pow(2)))->pow(0.5))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input().split() for i in range(len(a)): a[i]=int(a[i]) b=input().split() for i in range(len(b)): b[i]=int(b[i]) n=int(input()) cupShelf=(a[0]+a[1]+a[2])//5 if(a[0]+a[1]+a[2])% 5!=0 : cupShelf+=1 medalShelf=(b[0]+b[1]+b[2])//10 if(b[0]+b[1]+b[2])% 10!=0 : medalShelf+=1 if cupShelf+medalShelf>n : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := input().split() ; for i : Integer.subrange(0, (a)->size()-1) do ( a[i+1] := ("" + ((a[i+1])))->toInteger()) ; var b : OclAny := input().split() ; for i : Integer.subrange(0, (b)->size()-1) do ( b[i+1] := ("" + ((b[i+1])))->toInteger()) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cupShelf : int := (a->first() + a[1+1] + a[2+1]) div 5 ; if (a->first() + a[1+1] + a[2+1]) mod 5 /= 0 then ( cupShelf := cupShelf + 1 ) else skip ; var medalShelf : int := (b->first() + b[1+1] + b[2+1]) div 10 ; if (b->first() + b[1+1] + b[2+1]) mod 10 /= 0 then ( medalShelf := medalShelf + 1 ) else skip ; if (cupShelf + medalShelf->compareTo(n)) > 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=sum(map(int,input().split())) b=sum(map(int,input().split())) n=int(input()) if n<(a+4)//5+(b+9)//10 : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum() ; var b : OclAny := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum() ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n->compareTo((a + 4) div 5 + (b + 9) div 10)) < 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=lambda k :-(-sum(map(int,input().split()))//k) print('YNEOS'[i(5)+i(10)>i(1): : 2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : Function := lambda k : OclAny in (-(-((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum() div k)) ; execute ('YNEOS'(subscript (test (logical_test (comparison (comparison (expr (expr (atom (name i)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 5))))))))) )))) + (expr (atom (name i)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 10))))))))) )))))) > (comparison (expr (atom (name i)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) )))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def y(x): num=1 ; denom=float(1.0+x*x); return num/denom ; def WeedleRule(a,b): h=(b-a)/6 ; sum=0 ; sum=sum+(((3*h)/10)*(y(a)+y(a+2*h)+5*y(a+h)+6*y(a+3*h)+y(a+4*h)+5*y(a+5*h)+y(a+6*h))); return sum ; if __name__=='__main__' : a=0 ; b=6 ; num=WeedleRule(a,b); print("f(x)={0:.6f}".format(num)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( a := 0; ; b := 6; ; num := WeedleRule(a, b); ; execute (StringLib.interpolateStrings("f(x)={0:.6f}", Sequence{num}))->display(); ) else skip; operation y(x : OclAny) pre: true post: true activity: var num : int := 1; ; var denom : double := ("" + ((1.0 + x * x)))->toReal(); ; return num / denom;; operation WeedleRule(a : OclAny, b : OclAny) pre: true post: true activity: var h : double := (b - a) / 6; ; var sum : int := 0; ; sum := sum + (((3 * h) / 10) * (y(a) + y(a + 2 * h) + 5 * y(a + h) + 6 * y(a + 3 * h) + y(a + 4 * h) + 5 * y(a + 5 * h) + y(a + 6 * h))); ; return sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.buffer.readline def process(n,m,k): if kselect(x | true)->collect(x | (("" + ((x)))->toInteger())) ; process(n, m, k); operation process(n : OclAny, m : OclAny, k : OclAny) pre: true post: true activity: if (k->compareTo(n)) < 0 then ( (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom f '{k+1}1 '))))))) )))) ; return ) else skip ; k := k - n ; var k1 : int := k div (m - 1) ; var k2 : int := k mod (m - 1) ; var x : double := n - k1 ; if k1 mod 2 = 0 then ( var y : int := k2 + 2 ) else ( y := m - k2 ) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom f '{x}{y} '))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) if 0<=k<=n-1 : print(1+k,1) else : k-=n q,r=divmod(k,m-1) if q % 2==0 : x=2+r y=n-q else : x=m-r y=n-q print(y,x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if 0 <= k & (k <= n - 1) then ( execute (1 + k)->display() ) else ( k := k - n ; var q : OclAny := null; var r : OclAny := null; Sequence{q,r} := Sequence{(k div m - 1), (k mod m - 1)} ; if q mod 2 = 0 then ( var x : int := 2 + r ; var y : double := n - q ) else ( x := m - r ; y := n - q ) ; execute (y)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) if kcollect( _x | (OclType["int"])->apply(_x) ) ; if (k->compareTo(n)) < 0 then ( var y : OclAny := null; var x : OclAny := null; Sequence{y,x} := Sequence{k + 1,1} ) else ( k := k - n ; var y : double := n - k div (m - 1) ; if y mod 2 = 0 then ( var x : int := k mod (m - 1) + 2 ) else ( x := m - k mod (m - 1) ) ) ; execute (("" + ((y))) + ' ' + ("" + ((x))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for line in open(0).readlines(): p,q=map(int,line.split()) U=[0]*q d=1 ans=[] while U[p]==0 and p>0 : U[p]=d k,p=divmod(10*p,q) ans.append(str(k)) d+=1 print("".join(ans)) if p : print(" "*(U[p]-1)+"^"*(d-U[p])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for line : open(0).readlines() do ( var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := (line.split())->collect( _x | (OclType["int"])->apply(_x) ) ; var U : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, q) ; var d : int := 1 ; var ans : Sequence := Sequence{} ; while U[p+1] = 0 & p > 0 do ( U[p+1] := d ; var k : OclAny := null; var p : OclAny := null; Sequence{k,p} := Sequence{(10 * p div q), (10 * p mod q)} ; execute ((("" + ((k)))) : ans) ; d := d + 1) ; execute (StringLib.sumStringsWithSeparator((ans), ""))->display() ; if p then ( execute (StringLib.nCopies(" ", (U[p+1] - 1)) + StringLib.nCopies("^", (d - U[p+1])))->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from decimal import* import re def solve2(m,n): maxreplen=160 PREC=200 getcontext().prec=PREC x=Decimal(m)/Decimal(n) s=x.to_eng_string() if len(s)maxreplen : raise ValueError('This cannot happen.') u=s[2 : a.start()+len(a.group(1))] v=(''*PREC+'^'*len(a.group(1)))[-len(u):] return(u,v) while True : try : m,n=map(int,input().strip().split()) s,t=solve2(m,n) print(s) if t!='' : print(t) except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; while true do ( try ( Sequence{m,n} := (input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : OclAny := null; Sequence{s,t} := solve2(m, n) ; execute (s)->display() ; if t /= '' then ( execute (t)->display() ) else skip) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); operation solve2(m : OclAny, n : OclAny) : OclAny pre: true post: true activity: var maxreplen : int := 160 ; var PREC : int := 200 ; getcontext().prec := PREC ; var x : double := Decimal(m) / Decimal(n) ; var s : OclAny := x.to_eng_string() ; if ((s)->size()->compareTo(PREC)) < 0 then ( return Sequence{s.subrange(2+1), ''} ) else skip ; var rep : int := 1 ; while true do ( var r : int := StringLib.rawString('(.{%d})\1{%d,}') mod Sequence{rep, ("" + ((maxreplen / rep)))->toInteger() - 1} ; var a : String := (s)->firstMatch(r) ; if a then ( break ) else skip ; rep := rep + 1 ; if (rep->compareTo(maxreplen)) > 0 then ( error IncorrectElementException.newIncorrectElementException('This cannot happen.') ) else skip) ; var u : OclAny := s.subrange(2+1, a.start() + (a.group(1))->size()) ; var v : OclAny := (StringLib.nCopies('', PREC) + StringLib.nCopies('^', (a.group(1))->size())).subrange(-(u)->size()+1) ; return Sequence{u, v}; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkPattern(string,pattern): l=len(pattern) if len(string)first : return False return True if __name__=="__main__" : string="engineers rock" pattern="gsr" print(checkPattern(string,pattern)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( string := "engineers rock" ; pattern := "gsr" ; execute (checkPattern(string, pattern))->display() ) else skip; operation checkPattern(string : OclAny, pattern : OclAny) : OclAny pre: true post: true activity: var l : int := (pattern)->size() ; if ((string)->size()->compareTo(l)) < 0 then ( return false ) else skip ; for i : Integer.subrange(0, l - 1-1) do ( var x : OclAny := pattern[i+1] ; var y : OclAny := pattern[i + 1+1] ; var last : OclAny := string.rindex(x) ; var first : int := string->indexOf(y) - 1 ; if last = -1 or first = -1 or (last->compareTo(first)) > 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import random import math LI=lambda : list(map(int,input().split())) MI=lambda : map(int,input().split()) yes=lambda : print("Yes") no=lambda : print("No") I=lambda : list(input()) J=lambda x : "".join(x) II=lambda : int(input()) SI=lambda : input() a,b,h,m=MI() h*=5 h+=m/12 al=abs(h-m)*6 ans=math.sqrt(a**2+b**2-2*a*b*math.cos(al*math.pi/180)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var LI : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var MI : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var yes : Function := lambda $$ : OclAny in (("Yes")->display()) ; var no : Function := lambda $$ : OclAny in (("No")->display()) ; var I : Function := lambda $$ : OclAny in (((OclFile["System.in"]).readLine())->characters()) ; var J : Function := lambda x : OclAny in (StringLib.sumStringsWithSeparator((x), "")) ; var II : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var SI : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var a : OclAny := null; var b : OclAny := null; var h : OclAny := null; var m : OclAny := null; Sequence{a,b,h,m} := MI->apply() ; h := h * 5 ; h := h + m / 12 ; var al : double := (h - m)->abs() * 6 ; var ans : double := ((a)->pow(2) + (b)->pow(2) - 2 * a * b * )->sqrt() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def divide(p,q): a=p*10//q b=p*10-a*q arr1.append(a) if b==0 : return-1 elif b in arr2 : return arr2.index(b) else : arr2.append(b) return divide(b,q) for line in sys.stdin : p,q=map(int,line.split()) arr1=[] arr2=[p] repeat=[] r=divide(p,q) if r==-1 : print(''.join(map(str,arr1))) else : for i in range(len(arr1)): if icollect( _x | (OclType["int"])->apply(_x) ) ; var arr1 : Sequence := Sequence{} ; var arr2 : Sequence := Sequence{ p } ; var repeat : Sequence := Sequence{} ; var r : OclAny := divide(p, q) ; if r = -1 then ( execute (StringLib.sumStringsWithSeparator(((arr1)->collect( _x | (OclType["String"])->apply(_x) )), ''))->display() ) else ( for i : Integer.subrange(0, (arr1)->size()-1) do ( if (i->compareTo(r)) < 0 then ( execute (('') : repeat) ) else ( execute (('^') : repeat) )) ; execute (StringLib.sumStringsWithSeparator(((arr1)->collect( _x | (OclType["String"])->apply(_x) )), ''))->display() ; execute (StringLib.sumStringsWithSeparator((repeat), ''))->display() )); operation divide(p : OclAny, q : OclAny) : OclAny pre: true post: true activity: var a : int := p * 10 div q ; var b : double := p * 10 - a * q ; execute ((a) : arr1) ; if b = 0 then ( return -1 ) else (if (arr2)->includes(b) then ( return arr2->indexOf(b) - 1 ) else ( execute ((b) : arr2) ; return divide(b, q) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : p,q=list(map(int,input().split())) except : break rr=[-1]*q rr[p]=0 ans='' for k in range(1,q): p*=10 ans+=str(p//q) r=p % q if r==0 or rr[r]>=0 : print(ans) if rr[r]>=0 : print(*['']*rr[r],*['^']*(k-rr[r]),sep='') break rr[r],p=k,r ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) catch (_e : OclException) do ( break) ; var rr : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, q) ; rr[p+1] := 0 ; var ans : String := '' ; for k : Integer.subrange(1, q-1) do ( p := p * 10 ; ans := ans + ("" + ((p div q))) ; var r : int := p mod q ; if r = 0 or rr[r+1] >= 0 then ( execute (ans)->display() ; if rr[r+1] >= 0 then ( execute ((argument * (test (logical_test (comparison (expr (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom '')))))) ])) * (expr (atom (name rr)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name r)))))))) ])))))))))->display() ) else skip ; break ) else skip ; var rr[r+1] : OclAny := null; var p : OclAny := null; Sequence{rr[r+1],p} := Sequence{k,r})); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import division,print_function from sys import stdin,exit def main(): for line in stdin : p,q=(int(s)for s in line.split()) div_list=[] mod_list=[] d,m=divmod(p,q) p=m*10 mod_list.append(m) while m : d,m=divmod(p,q) div_list.append(d) p=m*10 if m in mod_list : break mod_list.append(m) print(*div_list,sep='') if m : space=mod_list.index(m) circum=len(mod_list)-space print(' '*space+'^'*circum) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: for line : stdin do ( var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name s)))))))) ))))))) (comp_for for (exprlist (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name line)) (trailer . (name split) (arguments ( ))))))))} ; var div_list : Sequence := Sequence{} ; var mod_list : Sequence := Sequence{} ; var d : OclAny := null; var m : OclAny := null; Sequence{d,m} := Sequence{(p div q), (p mod q)} ; var p : double := m * 10 ; execute ((m) : mod_list) ; while m do ( var d : OclAny := null; var m : OclAny := null; Sequence{d,m} := Sequence{(p div q), (p mod q)} ; execute ((d) : div_list) ; p := m * 10 ; if (mod_list)->includes(m) then ( break ) else skip ; execute ((m) : mod_list)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name div_list))))))))->display() ; if m then ( var space : int := mod_list->indexOf(m) - 1 ; var circum : double := (mod_list)->size() - space ; execute (StringLib.nCopies(' ', space) + StringLib.nCopies('^', circum))->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find_ans(ar,j,k): l=len(ar) for i in range(1,l): ar[i]=ar[i]+ar[i-1] print(ar[k]-ar[j-1]) return ; pr=[1,2,3,4,5] ar=pr[:] find_ans(ar,1,3) ar=pr[:] find_ans(ar,2,4) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var pr : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ; ar := pr ; find_ans(ar, 1, 3) ; ar := pr ; find_ans(ar, 2, 4); operation find_ans(ar : OclAny, j : OclAny, k : OclAny) : OclAny pre: true post: true activity: var l : int := (ar)->size() ; for i : Integer.subrange(1, l-1) do ( ar[i+1] := ar[i+1] + ar[i - 1+1]) ; execute (ar[k+1] - ar[j - 1+1])->display() ; return;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findFactors(a,b): c=a+b-1 print(c) if __name__=='__main__' : a=13 b=36 findFactors(a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := 13 ; b := 36 ; findFactors(a, b) ) else skip; operation findFactors(a : OclAny, b : OclAny) pre: true post: true activity: var c : double := a + b - 1 ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def solve(): n=int(input()) arr=list(map(int,input().split())) if n % 2==0 : return "YES" else : for i in range(1,n): if arr[i]<=arr[i-1]: return "YES" return "NO" for _ in range(int(input())): print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (solve())->display()); operation solve() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if n mod 2 = 0 then ( return "YES" ) else ( for i : Integer.subrange(1, n-1) do ( if (arr[i+1]->compareTo(arr[i - 1+1])) <= 0 then ( return "YES" ) else skip) ; return "NO" ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while(t>0): n=int(input()) l=[int(x)for x in input().split()] if(n % 2==0): print("YES") else : for i in range(1,n): if(l[i]<=l[i-1]): print("YES") break else : print("NO") t=t-1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (t > 0) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if (n mod 2 = 0) then ( execute ("YES")->display() ) else ( (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) <= (comparison (expr (atom (name l)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])))))))) )))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) ))))))))))))))) ) ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input for _ in range(int(I())): n=int(I()) lst=list(map(int,I().split())) if all(lst[i+1]>lst[i]for i in range(n-1))and n & 1==1 : print('NO') else : print('YES') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; for _anon : Integer.subrange(0, ("" + ((I())))->toInteger()-1) do ( var n : int := ("" + ((I())))->toInteger() ; var lst : Sequence := ((I().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if ((argument (test (logical_test (comparison (comparison (expr (atom (name lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])))) > (comparison (expr (atom (name lst)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) )))))))))->forAll( _x | _x = true ) & MathLib.bitwiseAnd(n, 1) = 1 then ( execute ('NO')->display() ) else ( execute ('YES')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) a=list(map(int,input().split())) f=0 if n % 2==0 : print("YES") else : for i in range(n-1): if a[i]>=a[i+1]: print("YES") f=1 break if f==0 : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var f : int := 0 ; if n mod 2 = 0 then ( execute ("YES")->display() ) else ( for i : Integer.subrange(0, n - 1-1) do ( if (a[i+1]->compareTo(a[i + 1+1])) >= 0 then ( execute ("YES")->display() ; f := 1 ; break ) else skip) ; if f = 0 then ( execute ("NO")->display() ) else skip )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n=int(input()) a=list(map(int,input().split())) if n & 1 : for i in range(n-1): if a[i]>=a[i+1]: return 'YES' return 'NO' else : return 'YES' for _ in range(int(input())): print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (solve())->display()); operation solve() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if MathLib.bitwiseAnd(n, 1) then ( for i : Integer.subrange(0, n - 1-1) do ( if (a[i+1]->compareTo(a[i + 1+1])) >= 0 then ( return 'YES' ) else skip) ; return 'NO' ) else ( return 'YES' ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import cos,radians,sqrt A,B,H,M=[int(el)for el in input().split()] minutes=H*60+M h=360.0/60.0*(minutes % 60) m=360.0/720.0*(minutes % 720) ang=abs(h-m) print(sqrt(A*A+B*B-2.0*A*B*cos(radians(ang)))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var A : OclAny := null; var B : OclAny := null; var H : OclAny := null; var M : OclAny := null; Sequence{A,B,H,M} := input().split()->select(el | true)->collect(el | (("" + ((el)))->toInteger())) ; var minutes : double := H * 60 + M ; var h : double := 360.0 / 60.0 * (minutes mod 60) ; var m : double := 360.0 / 720.0 * (minutes mod 720) ; var ang : double := (h - m)->abs() ; execute (sqrt(A * A + B * B - 2.0 * A * B * cos(radians(ang))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a=map(int,input().split()) arvores=list(map(int,input().split())) caso=-1 melhor_caso=10000 for i in range(n): b=arvores[i]-i*a if b>0 : alteracoes=0 for j in range(n): y=b+j*a if y!=arvores[j]: alteracoes+=1 if alteracoesy : print(f"-{i+1}{tam-y}") elif tamcollect( _x | (OclType["int"])->apply(_x) ) ; var arvores : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var caso : int := -1 ; var melhor_caso : int := 10000 ; for i : Integer.subrange(0, n-1) do ( var b : double := arvores[i+1] - i * a ; if b > 0 then ( var alteracoes : int := 0 ; for j : Integer.subrange(0, n-1) do ( var y : OclAny := b + j * a ; if y /= arvores[j+1] then ( alteracoes := alteracoes + 1 ) else skip) ; if (alteracoes->compareTo(melhor_caso)) < 0 then ( caso := i ; melhor_caso := alteracoes ) else skip ) else skip) ; if melhor_caso = 0 then ( execute (0)->display() ; quit() ) else skip ; execute (melhor_caso)->display() ; y := arvores[caso+1] - caso * a ; for i : Integer.subrange(0, n-1) do ( var tam : OclAny := arvores[i+1] ; if (tam->compareTo(y)) > 0 then ( execute (StringLib.formattedString("-{i+1}{tam-y}"))->display() ) else (if (tam->compareTo(y)) < 0 then ( execute (StringLib.formattedString("+{i+1}{y-tam}"))->display() ) else skip) ; y := y + a); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t : t-=1 a=[int(x)for x in input().split()] for i in range(a[0]): for j in range(a[1]): if i % 4==0 or i % 4==3 : if j % 4==0 or j % 4==3 : print("1",end=" ") else : print("0",end=" ") else : if j % 4==0 or j % 4==3 : print("0",end=" ") else : print("1",end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t do ( t := t - 1 ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for i : Integer.subrange(0, a->first()-1) do ( for j : Integer.subrange(0, a[1+1]-1) do ( if i mod 4 = 0 or i mod 4 = 3 then ( if j mod 4 = 0 or j mod 4 = 3 then ( execute ("1")->display() ) else ( execute ("0")->display() ) ) else ( if j mod 4 = 0 or j mod 4 = 3 then ( execute ("0")->display() ) else ( execute ("1")->display() ) )) ; execute (->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): h,w=map(int,input().split()) a='' b='' for i in range(1,(w//2)+1): if i % 2==0 : a+='1 0 ' b+='0 1 ' else : a+='0 1 ' b+='1 0 ' for i in range(1,(h//2)+1): if i % 2==0 : print(b) print(a) else : print(a) print(b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var h : OclAny := null; var w : OclAny := null; Sequence{h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : String := '' ; var b : String := '' ; for i : Integer.subrange(1, (w div 2) + 1-1) do ( if i mod 2 = 0 then ( a := a + '1 0 ' ; b := b + '0 1 ' ) else ( a := a + '0 1 ' ; b := b + '1 0 ' )) ; for i : Integer.subrange(1, (h div 2) + 1-1) do ( if i mod 2 = 0 then ( execute (b)->display() ; execute (a)->display() ) else ( execute (a)->display() ; execute (b)->display() ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=map(int,input().split()) for i in range(1,n+1): for j in range(1,m+1): a=int((i % 4<=1)!=(j % 4<=1)) print(a,end=" ") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, m + 1-1) do ( var a : int := ("" + (((i mod 4 <= 1) /= (j mod 4 <= 1))))->toInteger() ; execute (a)->display()) ; execute (->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) a=[[0,1,1,0],[1,0,0,1],[1,0,0,1],[0,1,1,0]] for _ in range(t): n,m=list(map(int,input().split())) arr=[[0]*m for _ in range(n)] for i in range(n): for j in range(m): print(a[i % 4][j % 4],end=' ') print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 0 })))}->union(Sequence{Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 1 })))}->union(Sequence{Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 1 })))}->union(Sequence{ Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 0 }))) }))) ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var arr : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, m))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( execute (a[i mod 4+1][j mod 4+1])->display()) ; execute (->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binarysearch(lst,l,r,key): result=-1 while l<=r : mid=l+(r-l)//2 if lst[mid]<=key : result=mid l=mid+1 else : r=mid-1 return result+1 n,m=map(int,input().split()) arr=list(map(int,input().split())) lst=sorted(arr) brr=list(map(int,input().split())) for i in brr : answer=binarysearch(lst,0,len(arr)-1,i) print(str(answer),end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; lst := arr->sort() ; var brr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : brr do ( var answer : OclAny := binarysearch(lst, 0, (arr)->size() - 1, i) ; execute (("" + ((answer))))->display()); operation binarysearch(lst : OclAny, l : OclAny, r : OclAny, key : OclAny) : OclAny pre: true post: true activity: var result : int := -1 ; while (l->compareTo(r)) <= 0 do ( var mid : OclAny := l + (r - l) div 2 ; if (lst[mid+1]->compareTo(key)) <= 0 then ( result := mid ; l := mid + 1 ) else ( r := mid - 1 )) ; return result + 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def s(a,k): l,r=0,len(a)-1 while l<=r : m=(l+r)//2 if a[m]==k : l=m+1 elif a[m]>k : r=m-1 else : l=m+1 return l n,k=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) a.sort() for i in b : y=s(a,i) print(y,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; for i : b do ( var y : OclAny := s(a, i) ; execute (y)->display()); operation s(a : OclAny, k : OclAny) : OclAny pre: true post: true activity: var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := Sequence{0,(a)->size() - 1} ; while (l->compareTo(r)) <= 0 do ( var m : int := (l + r) div 2 ; if a[m+1] = k then ( var l : int := m + 1 ) else (if (a[m+1]->compareTo(k)) > 0 then ( var r : double := m - 1 ) else ( l := m + 1 ) ) ) ; return l; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bins(arr,l,r,t): while l<=r : m=l+(r-l)//2 if arr[m]>t : r=m-1 else : l=m+1 return r n,k=map(int,input().split()) a=list(map(int,input().split())) a.sort() b=list(map(int,input().split())) for i in b : print(bins(a,0,n-1,i)+1,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : b do ( execute (bins(a, 0, n - 1, i) + 1)->display()); operation bins(arr : OclAny, l : OclAny, r : OclAny, t : OclAny) : OclAny pre: true post: true activity: while (l->compareTo(r)) <= 0 do ( var m : OclAny := l + (r - l) div 2 ; if (arr[m+1]->compareTo(t)) > 0 then ( r := m - 1 ) else ( l := m + 1 )) ; return r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bins(arr,l,r,t): while l<=r : m=l+(r-l)//2 if arr[m]>t : r=m-1 else : l=m+1 return r n,k=map(int,input().split()) a=list(map(int,input().split())) a.sort() b=list(map(int,input().split())) for i in b : print(bins(a,0,n-1,i)+1,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : b do ( execute (bins(a, 0, n - 1, i) + 1)->display()); operation bins(arr : OclAny, l : OclAny, r : OclAny, t : OclAny) : OclAny pre: true post: true activity: while (l->compareTo(r)) <= 0 do ( var m : OclAny := l + (r - l) div 2 ; if (arr[m+1]->compareTo(t)) > 0 then ( r := m - 1 ) else ( l := m + 1 )) ; return r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def sph(r,R,h): if(r<0 and R<0 and h<0): return-1 x=r V=(4*3.14*pow(r,3))/3 return V r,R,h=5,8,11 print(sph(r,R,h)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{r,R,h} := Sequence{5,8,11} ; execute (sph(r, R, h))->display(); operation sph(r : OclAny, R : OclAny, h : OclAny) : OclAny pre: true post: true activity: if (r < 0 & R < 0 & h < 0) then ( return -1 ) else skip ; var x : OclAny := r ; var V : double := (4 * 3.14 * (r)->pow(3)) / 3 ; return V; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import numpy as np int1=lambda x : int(x)-1 read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines sys.setrecursionlimit(500000) A,B,H,M=map(int,readline().split()) ang_H=(360/12*H)+(360/12/60*M) ang_M=(360/60*M) ang_between=max(ang_H,ang_M)-min(ang_H,ang_M) cos=math.cos(math.radians(ang_between)) L=np.sqrt(pow(A,2)+pow(B,2)-(2*A*B*cos)) print(L) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; sys.setrecursionlimit(500000) ; var A : OclAny := null; var B : OclAny := null; var H : OclAny := null; var M : OclAny := null; Sequence{A,B,H,M} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ang_H : double := (360 / 12 * H) + (360 / 12 / 60 * M) ; var ang_M : double := (360 / 60 * M) ; var ang_between : double := Set{ang_H, ang_M}->max() - Set{ang_H, ang_M}->min() ; var cos : OclAny := ; var L : Sequence := MatrixLib.elementwiseApply((A)->pow(2) + (B)->pow(2) - (2 * A * B * cos), lambda x : double in (x->sqrt())) ; execute (L)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkDuplicatesWithinK(arr,n,k): myset=[] for i in range(n): if arr[i]in myset : return True myset.append(arr[i]) if(i>=k): myset.remove(arr[i-k]) return False if __name__=="__main__" : arr=[10,5,3,4,3,5,6] n=len(arr) if(checkDuplicatesWithinK(arr,n,3)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{10}->union(Sequence{5}->union(Sequence{3}->union(Sequence{4}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 6 })))))) ; n := (arr)->size() ; if (checkDuplicatesWithinK(arr, n, 3)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ) ) else skip; operation checkDuplicatesWithinK(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var myset : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( if (myset)->includes(arr[i+1]) then ( return true ) else skip ; execute ((arr[i+1]) : myset) ; if ((i->compareTo(k)) >= 0) then ( execute ((arr[i - k+1]) /: myset) ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=input().split() n,k=int(n),int(k) lista=list(map(int,input().split())) flagg,posicao,contador=0,0,0 while contador!=n : flagC=0 for j in range(n): if((j-contador)*k+lista[contador])<=0 : break if((j-contador)*k+lista[contador])==lista[j]: flagC+=1 if flagg=lista[posicao]-k*queenDiff : calcI=lista[counter]-lista[posicao]+k*queenDiff print("-%d %d" %(armazena,calcI)) else : calcO=lista[posicao]-k*queenDiff-lista[counter] print("+%d %d" %(armazena,calcO)) counter+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split() ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := Sequence{("" + ((n)))->toInteger(),("" + ((k)))->toInteger()} ; var lista : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var flagg : OclAny := null; var posicao : OclAny := null; var contador : OclAny := null; Sequence{flagg,posicao,contador} := Sequence{0,0,0} ; while contador /= n do ( var flagC : int := 0 ; for j : Integer.subrange(0, n-1) do ( if ((j - contador) * k + lista[contador+1]) <= 0 then ( break ) else skip ; if ((j - contador) * k + lista[contador+1]) = lista[j+1] then ( flagC := flagC + 1 ) else skip) ; if (flagg->compareTo(flagC)) < 0 then ( var flagg : int := flagC ; var posicao : OclAny := contador ) else skip ; contador := contador + 1) ; var a : int := 0 ; var diferenca : double := n - flagg ; execute (diferenca)->display() ; var counter : int := 0 ; while counter /= n do ( if lista[counter+1] /= lista[posicao+1] - (posicao - counter) * k then ( var armazena : int := counter + 1 ; var queenDiff : double := posicao - counter ; if (lista[counter+1]->compareTo(lista[posicao+1] - k * queenDiff)) >= 0 then ( var calcI : double := lista[counter+1] - lista[posicao+1] + k * queenDiff ; execute (StringLib.format("-%d %d",Sequence{armazena, calcI}))->display() ) else ( var calcO : double := lista[posicao+1] - k * queenDiff - lista[counter+1] ; execute (StringLib.format("+%d %d",Sequence{armazena, calcO}))->display() ) ) else skip ; counter := counter + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def leastLexiString(s): if(len(s)& 1!=0): return s x=leastLexiString(s[0 : int(len(s)/2)]) y=leastLexiString(s[int(len(s)/2): len(s)]) return min(x+y,y+x) def areEquivalent(a,b): return(leastLexiString(a)==leastLexiString(b)) if __name__=='__main__' : a="aaba" b="abaa" if(areEquivalent(a,b)): print("YES") else : print("NO") a="aabb" b="abab" if(areEquivalent(a,b)): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( a := "aaba" ; b := "abaa" ; if (areEquivalent(a, b)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ; a := "aabb" ; b := "abab" ; if (areEquivalent(a, b)) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ) else skip; operation leastLexiString(s : OclAny) : OclAny pre: true post: true activity: if (MathLib.bitwiseAnd((s)->size(), 1) /= 0) then ( return s ) else skip ; var x : OclAny := leastLexiString(s.subrange(0+1, ("" + (((s)->size() / 2)))->toInteger())) ; var y : OclAny := leastLexiString(s.subrange(("" + (((s)->size() / 2)))->toInteger()+1, (s)->size())) ; return Set{x + y, y + x}->min(); operation areEquivalent(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (leastLexiString(a) = leastLexiString(b)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printMatrix(n,m): if(n<5 or m<5): print(-1,end=" "); return ; s="aeiou" ; s=list(s); for i in range(n): for j in range(m): print(s[j % 5],end=" "); print() c=s[0]; for i in range(4): s[i]=s[i+1]; s[4]=c ; if __name__=="__main__" : n=5 ; m=5 ; printMatrix(n,m); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 5; m := 5; ; printMatrix(n, m); ) else skip; operation printMatrix(n : OclAny, m : OclAny) : OclAny pre: true post: true activity: if (n < 5 or m < 5) then ( execute (-1)->display(); ; return; ) else skip ; var s : String := "aeiou"; ; s := (s)->characters(); ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( execute (s[j mod 5+1])->display();) ; execute (->display() ; var c : OclAny := s->first(); ; for i : Integer.subrange(0, 4-1) do ( s[i+1] := s[i + 1+1];) ; s[4+1] := c;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def diameterOfBinaryTree(self,root): self.ans=1 def depth(node): if not node : return 0 L=depth(node.left) R=depth(node.right) self.ans=max(self.ans,L+R+1) return max(L,R)+1 depth(root) return self.ans-1 ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation diameterOfBinaryTree(root : OclAny) : OclAny pre: true post: true activity: self.ans := 1 ; skip ; depth(root) ; return self.ans - 1; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findElement(arr,n): leftMax=[None]*n leftMax[0]=float('-inf') for i in range(1,n): leftMax[i]=max(leftMax[i-1],arr[i-1]) rightMin=float('inf') for i in range(n-1,-1,-1): if leftMax[i]arr[i]: return i rightMin=min(rightMin,arr[i]) return-1 if __name__=="__main__" : arr=[5,1,4,3,6,8,10,7,9] n=len(arr) print("Index of the element is",findElement(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{5}->union(Sequence{1}->union(Sequence{4}->union(Sequence{3}->union(Sequence{6}->union(Sequence{8}->union(Sequence{10}->union(Sequence{7}->union(Sequence{ 9 })))))))) ; n := (arr)->size() ; execute ("Index of the element is")->display() ) else skip; operation findElement(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var leftMax : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; leftMax->first() := ("" + (('-inf')))->toReal() ; for i : Integer.subrange(1, n-1) do ( leftMax[i+1] := Set{leftMax[i - 1+1], arr[i - 1+1]}->max()) ; var rightMin : double := ("" + (('inf')))->toReal() ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if (leftMax[i+1]->compareTo(arr[i+1])) < 0 & (rightMin->compareTo(arr[i+1])) > 0 then ( return i ) else skip ; rightMin := Set{rightMin, arr[i+1]}->min()) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() w=s.count("W") b=n-w if b % 2==w % 2==1 : print(-1) else : c=0 p=0 ans=[] x="W" if w % 2==0 else "B" for i in range(n): if(s[i]==x and p==0)or(s[i]!=x and p==1): p=1 c+=1 ans.append(i+1) else : p=0 print(c) print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var w : int := s->count("W") ; var b : double := n - w ; if b mod 2 = w mod 2 & (w mod 2 == 1) then ( execute (-1)->display() ) else ( var c : int := 0 ; var p : int := 0 ; var ans : Sequence := Sequence{} ; var x : String := if w mod 2 = 0 then "W" else "B" endif ; for i : Integer.subrange(0, n-1) do ( if (s[i+1] = x & p = 0) or (s[i+1] /= x & p = 1) then ( p := 1 ; c := c + 1 ; execute ((i + 1) : ans) ) else ( p := 0 )) ; execute (c)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def swapper(blocks,block): i=0 ans=[] while i3*n : ans=swapper(blocks,'W') if impossible or len(ans)>3*n : print(-1) else : print(len(ans)) print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; blocks := (OclFile["System.in"]).readLine() ; var b : OclAny := null; var w : OclAny := null; Sequence{b,w} := Sequence{0,0} ; for i : Integer.subrange(0, n-1) do ( if blocks[i+1] = 'B' then ( b := b + 1 ) else ( w := w + 1 )) ; var impossible : boolean := false ; if b mod 2 = 1 & w mod 2 = 1 then ( impossible := true ) else (if b mod 2 = 1 & w mod 2 = 0 then ( ans := swapper(blocks, 'W') ) else (if b mod 2 = 0 & w mod 2 = 1 then ( ans := swapper(blocks, 'B') ) else ( ans := swapper(blocks, 'B') ; if ((ans)->size()->compareTo(3 * n)) > 0 then ( ans := swapper(blocks, 'W') ) else skip ) ) ) ; if impossible or ((ans)->size()->compareTo(3 * n)) > 0 then ( execute (-1)->display() ) else ( execute ((ans)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ); operation swapper(blocks : OclAny, block : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; var ans : Sequence := Sequence{} ; while (i->compareTo((blocks)->size() - 1)) < 0 do ( if blocks[i+1] = block then ( var j : int := i + 1 ; while blocks[j+1] /= block do ( execute ((j) : ans) ; j := j + 1) ; execute ((j) : ans) ; i := j + 1 ) else ( i := i + 1 )) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=list(map(int,input().split()))[0] s=list(list(map(str,input().split()))[0]) w=s.count('W') b=n-w if w & 1 and b & 1 : print(-1) else : i=0 v="W" if not w & 1 else "B" ans=[] while icollect( _x | (OclType["int"])->apply(_x) ))->first() ; var s : Sequence := (OclType["Sequence"]((input().split())->collect( _x | (OclType["String"])->apply(_x) ))->first()) ; var w : int := s->count('W') ; var b : double := n - w ; if MathLib.bitwiseAnd(w, 1) & MathLib.bitwiseAnd(b, 1) then ( execute (-1)->display() ) else ( var i : int := 0 ; var v : String := if not(MathLib.bitwiseAnd(w, 1)) then "W" else "B" endif ; var ans : Sequence := Sequence{} ; while (i->compareTo(n - 1)) < 0 do ( if s[i+1] = v then ( if s[i+1] /= s[i + 1+1] then ( execute ((i + 1) : ans) ; var s[i+1] : OclAny := null; var s[i + 1+1] : OclAny := null; Sequence{s[i+1],s[i + 1+1]} := Sequence{s[i + 1+1],s[i+1]} ) else ( execute ((i + 1) : ans) ; i := i + 1 ) ) else skip ; i := i + 1) ; execute ((ans)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n=int(input()) s=list(input().rstrip()) for i in range(n): s[i]//=70 c=sum(s) if not c % 2 : ans=[] for i in range(n-1): if s[i]: s[i]^=1 s[i+1]^=1 ans.append(i+1) elif n % 2 : ans=[] for i in range(n-1): if not s[i]: s[i]^=1 s[i+1]^=1 ans.append(i+1) else : ans=-1 print(ans) exit() k=len(ans) print(k) sys.stdout.write(" ".join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := (input().rstrip()) ; for i : Integer.subrange(0, n-1) do ( s[i+1] := s[i+1] div 70) ; var c : OclAny := (s)->sum() ; if not(c mod 2) then ( var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( if s[i+1] then ( s[i+1] := s[i+1] xor 1 ; s[i + 1+1] := s[i + 1+1] xor 1 ; execute ((i + 1) : ans) ) else skip) ) else (if n mod 2 then ( ans := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( if not(s[i+1]) then ( s[i+1] := s[i+1] xor 1 ; s[i + 1+1] := s[i + 1+1] xor 1 ; execute ((i + 1) : ans) ) else skip) ) else ( ans := -1 ; execute (ans)->display() ; exit() ) ) ; var k : int := (ans)->size() ; execute (k)->display() ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " ") (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name ans)))))))) ))))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- octD={"0" : 0,"1" : 1,"2" : 2,"3" : 3,"4" : 5,"5" : 7,"6" : 8,"7" : 9} while True : n=int(input()) if n==0 : break else : N=list(format(n,"o")) for i in range(len(N)): print(octD[N[i]],end="") print() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var octD : Map := Map{ "0" |-> 0 }->union(Map{ "1" |-> 1 }->union(Map{ "2" |-> 2 }->union(Map{ "3" |-> 3 }->union(Map{ "4" |-> 5 }->union(Map{ "5" |-> 7 }->union(Map{ "6" |-> 8 }->union(Map{ "7" |-> 9 }))))))) ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else ( var N : Sequence := ((n + ""))->characters() ; for i : Integer.subrange(0, (N)->size()-1) do ( execute (octD[N[i+1]+1])->display()) ; execute (->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,h,m=map(int,input().split()) import math C=abs(360/60*m-360/12*h-360/12/60*m) if C>180 : C=360-C cosC=math.cos(math.radians(C)) print(math.sqrt(a**2+b**2-2*a*b*cosC)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var h : OclAny := null; var m : OclAny := null; Sequence{a,b,h,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; skip ; var C : double := (360 / 60 * m - 360 / 12 * h - 360 / 12 / 60 * m)->abs() ; if C > 180 then ( C := 360 - C ) else skip ; var cosC : OclAny := ; execute (((a)->pow(2) + (b)->pow(2) - 2 * a * b * cosC)->sqrt())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline inp=lambda : list(map(int,input().split())) def answer(): cw,cb=0,0 for i in range(n): cw+=(a[i]=='W') cb+=(a[i]=='B') if(cw & 1 and cb & 1): print(-1) return ans=[] if(cw & 1==0): for i in range(n-1): if(a[i]=='W'): ans.append(i+1) a[i]='B' if(a[i+1]=='W'): a[i+1]='B' else : a[i+1]='W' else : for i in range(n-1): if(a[i]=='B'): ans.append(i+1) a[i]='W' if(a[i+1]=='W'): a[i+1]='B' else : a[i+1]='W' print(len(ans)) print(*ans) for T in range(1): n=int(input()) a=list(input().strip()) answer() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; var inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; skip ; for T : Integer.subrange(0, 1-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (input()->trim()) ; answer()); operation answer() pre: true post: true activity: var cw : OclAny := null; var cb : OclAny := null; Sequence{cw,cb} := Sequence{0,0} ; for i : Integer.subrange(0, n-1) do ( cw := cw + (a[i+1] = 'W') ; cb := cb + (a[i+1] = 'B')) ; if (MathLib.bitwiseAnd(cw, 1) & MathLib.bitwiseAnd(cb, 1)) then ( execute (-1)->display() ; return ) else skip ; var ans : Sequence := Sequence{} ; if (MathLib.bitwiseAnd(cw, 1) = 0) then ( for i : Integer.subrange(0, n - 1-1) do ( if (a[i+1] = 'W') then ( execute ((i + 1) : ans) ; a[i+1] := 'B' ; if (a[i + 1+1] = 'W') then ( a[i + 1+1] := 'B' ) else ( a[i + 1+1] := 'W' ) ) else skip) ) else ( for i : Integer.subrange(0, n - 1-1) do ( if (a[i+1] = 'B') then ( execute ((i + 1) : ans) ; a[i+1] := 'W' ; if (a[i + 1+1] = 'W') then ( a[i + 1+1] := 'B' ) else ( a[i + 1+1] := 'W' ) ) else skip) ) ; execute ((ans)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNthOddDigitNumber(n): count=0 i=1 while True : num=i isMadeOfOdd=True while num!=0 : if(num % 10==0 or num % 10==2 or num % 10==4 or num % 10==6 or num % 10==8): isMadeOfOdd=False break num/=10 if isMadeOfOdd==True : count+=1 if count==n : return i i+=1 if __name__=="__main__" : n=10 print(findNthOddDigitNumber(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 10 ; execute (findNthOddDigitNumber(n))->display() ) else skip; operation findNthOddDigitNumber(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var i : int := 1 ; while true do ( var num : int := i ; var isMadeOfOdd : boolean := true ; while num /= 0 do ( if (num mod 10 = 0 or num mod 10 = 2 or num mod 10 = 4 or num mod 10 = 6 or num mod 10 = 8) then ( isMadeOfOdd := false ; break ) else skip ; num := num / 10) ; if isMadeOfOdd = true then ( count := count + 1 ) else skip ; if count = n then ( return i ) else skip ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p=[[0 for j in range(21)]for i in range(2)] n=int(input()) d=list(map(int,input().split())) p[0][d[0]]=1 s=d[n-1] for i in range(1,n): x=d[i]; for j in range(21): p[i & 1][j]=0 for j in range(21-x): p[i & 1][j+x]+=p[1-(i & 1)][j] for j in range(x,21): p[i & 1][j-x]+=p[1-(i & 1)][j]; print(p[n & 1][s]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : Sequence := Integer.subrange(0, 2-1)->select(i | true)->collect(i | (Integer.subrange(0, 21-1)->select(j | true)->collect(j | (0)))) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; p->first()[d->first()+1] := 1 ; var s : OclAny := d[n - 1+1] ; for i : Integer.subrange(1, n-1) do ( var x : OclAny := d[i+1]; ; for j : Integer.subrange(0, 21-1) do ( p[MathLib.bitwiseAnd(i, 1)+1][j+1] := 0) ; for j : Integer.subrange(0, 21 - x-1) do ( p[MathLib.bitwiseAnd(i, 1)+1][j + x+1] := p[MathLib.bitwiseAnd(i, 1)+1][j + x+1] + p[1 - (MathLib.bitwiseAnd(i, 1))+1][j+1]) ; for j : Integer.subrange(x, 21-1) do ( p[MathLib.bitwiseAnd(i, 1)+1][j - x+1] := p[MathLib.bitwiseAnd(i, 1)+1][j - x+1] + p[1 - (MathLib.bitwiseAnd(i, 1))+1][j+1];)) ; execute (p[MathLib.bitwiseAnd(n, 1)+1][s+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=[int(i)for i in input().split()] cm=0 hF=0 for x in range(1,1001): cmt=0 for j in range(n): cmt+=(a[j]==x+j*k) if cmt>cm : cm=cmt hF=x print(n-cm) for z in range(n): if a[z]!=hF+z*k : if a[z]>hF+z*k : print('-',z+1,a[z]-hF-z*k) else : print('+',z+1,abs(a[z]-hF-z*k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var cm : int := 0 ; var hF : int := 0 ; for x : Integer.subrange(1, 1001-1) do ( var cmt : int := 0 ; for j : Integer.subrange(0, n-1) do ( cmt := cmt + (a[j+1] = x + j * k)) ; if (cmt->compareTo(cm)) > 0 then ( cm := cmt ; hF := x ) else skip) ; execute (n - cm)->display() ; for z : Integer.subrange(0, n-1) do ( if a[z+1] /= hF + z * k then ( if (a[z+1]->compareTo(hF + z * k)) > 0 then ( execute ('-')->display() ) else ( execute ('+')->display() ) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMaximumPieces(n): x=n//2 return((x+1)*(n-x+1)) if __name__=="__main__" : n=3 print("Max number of pieces for n="+str(n)+" is "+str(findMaximumPieces(3))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 3 ; execute ("Max number of pieces for n=" + ("" + ((n))) + " is " + ("" + ((findMaximumPieces(3)))))->display() ) else skip; operation findMaximumPieces(n : OclAny) : OclAny pre: true post: true activity: var x : int := n div 2 ; return ((x + 1) * (n - x + 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def findCount(d): return 9*((int)(math.pow(10,d-1))-(int)(math.pow(9,d-1))); d=1 print(findCount(d)) d=2 print(findCount(d)) d=4 print(findCount(d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; d := 1 ; execute (findCount(d))->display() ; d := 2 ; execute (findCount(d))->display() ; d := 4 ; execute (findCount(d))->display(); operation findCount(d : OclAny) pre: true post: true activity: return 9 * ((OclType["int"])((10)->pow(d - 1)) - (OclType["int"])((9)->pow(d - 1)));; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printArr(arr,n): for i in range(n): print(arr[i],"",end="") print() def generateUtil(A,B,C,i,j,m,n,len,flag): if(flag): if(len): printArr(C,len+1) for k in range(i,m): if(not len): C[len]=A[k] generateUtil(A,B,C,k+1,j,m,n,len,not flag) else : if(A[k]>C[len]): C[len+1]=A[k] generateUtil(A,B,C,k+1,j,m,n,len+1,not flag) else : for l in range(j,n): if(B[l]>C[len]): C[len+1]=B[l] generateUtil(A,B,C,i,l+1,m,n,len+1,not flag) def generate(A,B,m,n): C=[] for i in range(m+n+1): C.append(0) generateUtil(A,B,C,0,0,m,n,0,True) A=[10,15,25] B=[5,20,30] n=len(A) m=len(B) generate(A,B,n,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; A := Sequence{10}->union(Sequence{15}->union(Sequence{ 25 })) ; B := Sequence{5}->union(Sequence{20}->union(Sequence{ 30 })) ; n := (A)->size() ; m := (B)->size() ; generate(A, B, n, m); operation printArr(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()) ; execute (->display(); operation generateUtil(A : OclAny, B : OclAny, C : OclAny, i : OclAny, j : OclAny, m : OclAny, n : OclAny, len : OclAny, flag : OclAny) pre: true post: true activity: if (flag) then ( if (len) then ( printArr(C, len + 1) ) else skip ; for k : Integer.subrange(i, m-1) do ( if (not(len)) then ( C[len+1] := A[k+1] ; generateUtil(A, B, C, k + 1, j, m, n, len, not(flag)) ) else ( if ((A[k+1]->compareTo(C[len+1])) > 0) then ( C[len + 1+1] := A[k+1] ; generateUtil(A, B, C, k + 1, j, m, n, len + 1, not(flag)) ) else skip )) ) else ( for l : Integer.subrange(j, n-1) do ( if ((B[l+1]->compareTo(C[len+1])) > 0) then ( C[len + 1+1] := B[l+1] ; generateUtil(A, B, C, i, l + 1, m, n, len + 1, not(flag)) ) else skip) ); operation generate(A : OclAny, B : OclAny, m : OclAny, n : OclAny) pre: true post: true activity: C := Sequence{} ; for i : Integer.subrange(0, m + n + 1-1) do ( execute ((0) : C)) ; generateUtil(A, B, C, 0, 0, m, n, 0, true); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMissing(a,b,n,m): s=dict() for i in range(m): s[b[i]]=1 for i in range(n): if a[i]not in s.keys(): print(a[i],end=" ") a=[1,2,6,3,4,5] b=[2,4,3,1,0] n=len(a) m=len(b) findMissing(a,b,n,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{1}->union(Sequence{2}->union(Sequence{6}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 }))))) ; b := Sequence{2}->union(Sequence{4}->union(Sequence{3}->union(Sequence{1}->union(Sequence{ 0 })))) ; n := (a)->size() ; m := (b)->size() ; findMissing(a, b, n, m); operation findMissing(a : OclAny, b : OclAny, n : OclAny, m : OclAny) pre: true post: true activity: var s : Map := (arguments ( )) ; for i : Integer.subrange(0, m-1) do ( s[b[i+1]+1] := 1) ; for i : Integer.subrange(0, n-1) do ( if (s.keys())->excludes(a[i+1]) then ( execute (a[i+1])->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSum(str1,str2): if len(str1)>len(str2): temp=str1 str1=str2 str2=temp str3="" n1=len(str1) n2=len(str2) diff=n2-n1 carry=0 for i in range(n1-1,-1,-1): sum=((ord(str1[i])-ord('0'))+int((ord(str2[i+diff])-ord('0')))+carry) str3=str3+str(sum % 10) carry=sum//10 for i in range(n2-n1-1,-1,-1): sum=((ord(str2[i])-ord('0'))+carry) str3=str3+str(sum % 10) carry=sum//10 if(carry): str3+str(carry+'0') str3=str3[: :-1] return str3 if __name__=="__main__" : str1="12" str2="198111" print(findSum(str1,str2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( str1 := "12" ; str2 := "198111" ; execute (findSum(str1, str2))->display() ) else skip; operation findSum(str1 : OclAny, str2 : OclAny) : OclAny pre: true post: true activity: if ((str1)->size()->compareTo((str2)->size())) > 0 then ( var temp : OclAny := str1 ; str1 := str2 ; str2 := temp ) else skip ; var str3 : String := "" ; var n1 : int := (str1)->size() ; var n2 : int := (str2)->size() ; var diff : double := n2 - n1 ; var carry : int := 0 ; for i : Integer.subrange(-1 + 1, n1 - 1)->reverse() do ( var sum : double := (((str1[i+1])->char2byte() - ('0')->char2byte()) + ("" + ((((str2[i + diff+1])->char2byte() - ('0')->char2byte()))))->toInteger() + carry) ; str3 := str3 + ("" + ((sum mod 10))) ; carry := sum div 10) ; for i : Integer.subrange(-1 + 1, n2 - n1 - 1)->reverse() do ( sum := (((str2[i+1])->char2byte() - ('0')->char2byte()) + carry) ; str3 := str3 + ("" + ((sum mod 10))) ; carry := sum div 10) ; if (carry) then ( (expr (expr (atom (name str3))) + (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name carry))) + (expr (atom '0')))))))) ))))) ) else skip ; str3 := str3(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; return str3; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSum(str1,str2): if(len(str1)>len(str2)): t=str1 ; str1=str2 ; str2=t ; str="" ; n1=len(str1); n2=len(str2); str1=str1[: :-1]; str2=str2[: :-1]; carry=0 ; for i in range(n1): sum=((ord(str1[i])-48)+((ord(str2[i])-48)+carry)); str+=chr(sum % 10+48); carry=int(sum/10); for i in range(n1,n2): sum=((ord(str2[i])-48)+carry); str+=chr(sum % 10+48); carry=(int)(sum/10); if(carry): str+=chr(carry+48); str=str[: :-1]; return str ; str1="12" ; str2="198111" ; print(findSum(str1,str2)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; str1 := "12"; ; str2 := "198111"; ; execute (findSum(str1, str2))->display();; operation findSum(str1 : OclAny, str2 : OclAny) pre: true post: true activity: if (((str1)->size()->compareTo((str2)->size())) > 0) then ( var t : OclAny := str1; ; str1 := str2; ; str2 := t; ) else skip ; var OclType["String"] : String := ""; ; var n1 : int := (str1)->size(); ; var n2 : int := (str2)->size(); ; str1 := str1(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); ; str2 := str2(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); ; var carry : int := 0; ; for i : Integer.subrange(0, n1-1) do ( var sum : double := (((str1[i+1])->char2byte() - 48) + (((str2[i+1])->char2byte() - 48) + carry)); ; OclType["String"] := OclType["String"] + (sum mod 10 + 48)->byte2char(); ; carry := ("" + ((sum / 10)))->toInteger();) ; for i : Integer.subrange(n1, n2-1) do ( sum := (((str2[i+1])->char2byte() - 48) + carry); ; OclType["String"] := OclType["String"] + (sum mod 10 + 48)->byte2char(); ; carry := (OclType["int"])(sum / 10);) ; if (carry) then ( OclType["String"] := OclType["String"] + (carry + 48)->byte2char(); ) else skip ; OclType["String"] := ("" + ((subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))); ; return OclType["String"];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def sieve(prime,n): prime[0]=False ; prime[1]=False ; for p in range(2,int(sqrt(n))+1): if(prime[p]==True): for i in range(p*p,n+1,p): prime[i]=False ; def sumPrime(d): maxVal=(10**d)-1 ; prime=[True]*(maxVal+1); sieve(prime,maxVal); sum=0 ; for i in range(2,maxVal+1): if(prime[i]): sum+=i ; return sum ; if __name__=="__main__" : d=3 ; print(sumPrime(d)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( d := 3; ; execute (sumPrime(d))->display(); ) else skip; operation sieve(prime : OclAny, n : OclAny) pre: true post: true activity: prime->first() := false; ; prime[1+1] := false; ; for p : Integer.subrange(2, ("" + ((sqrt(n))))->toInteger() + 1-1) do ( if (prime[p+1] = true) then ( for i : Integer.subrange(p * p, n + 1-1)->select( $x | ($x - p * p) mod p = 0 ) do ( prime[i+1] := false;) ) else skip); operation sumPrime(d : OclAny) pre: true post: true activity: var maxVal : double := ((10)->pow(d)) - 1; ; prime := MatrixLib.elementwiseMult(Sequence{ true }, (maxVal + 1)); ; sieve(prime, maxVal); ; var sum : int := 0; ; for i : Integer.subrange(2, maxVal + 1-1) do ( if (prime[i+1]) then ( sum := sum + i; ) else skip) ; return sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findPhoneNumber(n): temp=n sum=0 while(temp!=0): sum+=temp % 10 temp=temp//10 if(sum<10): print(n,"0",sum) else : n=str(n) sum=str(sum) n+=sum print(n) if __name__=='__main__' : n=98765432 findPhoneNumber(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 98765432 ; findPhoneNumber(n) ) else skip; operation findPhoneNumber(n : OclAny) pre: true post: true activity: var temp : OclAny := n ; var sum : int := 0 ; while (temp /= 0) do ( sum := sum + temp mod 10 ; temp := temp div 10) ; if (sum < 10) then ( execute (n)->display() ) else ( n := ("" + ((n))) ; sum := ("" + ((sum))) ; n := n + sum ; execute (n)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sum(arr,n): i=n if(arr[i]<9): arr[i]=arr[i]+1 return arr[i]=0 i-=1 sum(arr,i) if(arr[0]>0): print(arr[0],",",end="") for i in range(1,n+1): print(arr[i],end="") if(iunion(Sequence{1}->union(Sequence{9}->union(Sequence{3}->union(Sequence{ 9 })))) ; sum(arr, n); operation sum(arr : OclAny, n : OclAny) pre: true post: true activity: var i : OclAny := n ; if (arr[i+1] < 9) then ( arr[i+1] := arr[i+1] + 1 ; return ) else skip ; arr[i+1] := 0 ; i := i - 1 ; sum(arr, i) ; if (arr->first() > 0) then ( execute (arr->first())->display() ) else skip ; for i : Integer.subrange(1, n + 1-1) do ( execute (arr[i+1])->display() ; if ((i->compareTo(n)) < 0) then ( execute (",")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(grid): count=0 while True : done=True for i in range(99,-1,-1): for j in range(99,-1,-1): north=i>0 and grid[i-1][j] west=j>0 and grid[i][j-1] if grid[i][j]: done=False if not(north or west): grid[i][j]=False else : if north and west : grid[i][j]=True if done : return count count+=1 def main(): T=int(input()) for x in range(1,T+1): grid=[[False for i in range(100)]for j in range(100)] R=int(input()) for k in range(R): X1,Y1,X2,Y2=map(int,input().split()) for i in range(Y1-1,Y2): for j in range(X1-1,X2): grid[i][j]=True print("Case #{}:".format(x),solve(grid)) if __name__=="__main__" : with open("C-small-attempt0.in")as sys.stdin : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( try (var OclFile["System.in"] : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("C-small-attempt0.in")); main()) catch (_e : OclException) do skip ) else skip; operation solve(grid : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while true do ( var done : boolean := true ; for i : Integer.subrange(-1 + 1, 99)->reverse() do ( for j : Integer.subrange(-1 + 1, 99)->reverse() do ( var north : boolean := i > 0 & grid[i - 1+1][j+1] ; var west : boolean := j > 0 & grid[i+1][j - 1+1] ; if grid[i+1][j+1] then ( done := false ; if not((north or west)) then ( grid[i+1][j+1] := false ) else skip ) else ( if north & west then ( grid[i+1][j+1] := true ) else skip ))) ; if done then ( return count ) else skip ; count := count + 1); operation main() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for x : Integer.subrange(1, T + 1-1) do ( grid := Integer.subrange(0, 100-1)->select(j | true)->collect(j | (Integer.subrange(0, 100-1)->select(i | true)->collect(i | (false)))) ; var R : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for k : Integer.subrange(0, R-1) do ( var X1 : OclAny := null; var Y1 : OclAny := null; var X2 : OclAny := null; var Y2 : OclAny := null; Sequence{X1,Y1,X2,Y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(Y1 - 1, Y2-1) do ( for j : Integer.subrange(X1 - 1, X2-1) do ( grid[i+1][j+1] := true))) ; execute (StringLib.interpolateStrings("Case #{}:", Sequence{x}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,k=map(int,input().split()) l=list(map(int,input().split())) a=set(l) b=len(a) ans=[] if b>k : print(-1) else : c=0 o=1 while btoInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Set := Set{}->union((l)) ; var b : int := (a)->size() ; var ans : Sequence := Sequence{} ; if (b->compareTo(k)) > 0 then ( execute (-1)->display() ) else ( var c : int := 0 ; var o : int := 1 ; while (b->compareTo(k)) < 0 do ( if (a)->excludes(o) then ( execute ((o) : a) ; b := b + 1 ) else skip ; o := o + 1) ; for x : a do ( execute ((x) : ans)) ; c := n ; execute (k * c)->display() ; for _anon : Integer.subrange(0, c-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name ans))))))) ))))))))->display()) ; execute ("")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=[int(x)for x in input().split()] min_count=999999999 res_a1=0 for i in range(1,1001): a1=i count=0 for ai in range(len(a)): if a[ai]!=a1 : count+=1 a1+=k if countcollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var min_count : int := 999999999 ; var res_a1 : int := 0 ; for i : Integer.subrange(1, 1001-1) do ( var a1 : OclAny := i ; var count : int := 0 ; for ai : Integer.subrange(0, (a)->size()-1) do ( if a[ai+1] /= a1 then ( count := count + 1 ) else skip ; a1 := a1 + k) ; if (count->compareTo(min_count)) < 0 then ( res_a1 := i ; min_count := count ) else skip) ; execute (min_count)->display() ; var res_array : Sequence := MatrixLib.elementwiseMult(Sequence{ res_a1 }, (a)->size()) ; for i : Integer.subrange(1, n-1) do ( res_array[i+1] := res_array[i - 1+1] + k) ; for i : Integer.subrange(0, n-1) do ( if res_array[i+1] /= a[i+1] then ( var dif : double := res_array[i+1] - a[i+1] ; if dif < 0 then ( execute ("-")->display() ) else ( execute ("+")->display() ) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt from collections import defaultdict,deque from bisect import bisect_left as b_l from bisect import bisect_right as b_r import sys mod=10**9+7 INT_MAX=sys.maxsize INT_MIN=-sys.maxsize-1 for _ in range(int(input())): n,k=map(int,input().split()) a=list(map(int,input().split())) cnt=list(set(a)) if(len(cnt)<=k): print(k*n) if(len(cnt)pow(9) + 7 ; var INT_MAX : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; var INT_MIN : double := -(trailer . (name maxsize)) - 1 ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cnt : Sequence := (Set{}->union((a))) ; if (((cnt)->size()->compareTo(k)) <= 0) then ( execute (k * n)->display() ; if (((cnt)->size()->compareTo(k)) < 0) then ( while (((cnt)->size()->compareTo(k)) < 0) do ( execute ((cnt->last()) : cnt)) ) else skip ; for j : Integer.subrange(0, n-1) do ( for i : Integer.subrange(0, (cnt)->size()-1) do ( execute (cnt[i+1])->display())) ; execute (->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math T=int(input()) for _ in range(T): temp=input().split(); n,k=[int(x)for x in temp] arr=input().split(); arr=[int(x)for x in arr] arrv=set(arr) if len(arrv)>k : print("-1") else : dk={}; z=0 for i in arrv : dk.update({z : i}) z+=1 for i in range(z,k): dk.update({i : 1}) n=0 ; p=0 ; arr2=[] while ntoInteger() ; for _anon : Integer.subrange(0, T-1) do ( var temp : OclAny := input().split(); var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := temp->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var arr : OclAny := input().split(); arr := arr->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var arrv : Set := Set{}->union((arr)) ; if ((arrv)->size()->compareTo(k)) > 0 then ( execute ("-1")->display() ) else ( var dk : OclAny := Set{}; var z : int := 0 ; for i : arrv do ( execute ((Map{ z |-> i }) <: dk) ; z := z + 1) ; for i : Integer.subrange(z, k-1) do ( execute ((Map{ i |-> 1 }) <: dk)) ; var n : int := 0; var p : int := 0; var arr2 : Sequence := Sequence{} ; while (n->compareTo((arr)->size())) < 0 do ( var x : OclAny := dk[p mod k+1] ; if x = arr[n+1] then ( n := n + 1 ) else skip ; execute ((x) : arr2) ; p := p + 1) ; execute ((arr2)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name arr2))))))))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (n,k),t=map(int,input().split()),sorted(map(int,input().split())) i,d,s=1,t[0],sum(t) while it[i]*(100*n-k*(n-i)): d+=t[i]; i+=1 print((100*s-k*(s-d))/(100*n-k*(n-i))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{n, k} : OclAny := null; var t : OclAny := null; Sequence{Sequence{n, k},t} := Sequence{(input().split())->collect( _x | (OclType["int"])->apply(_x) ),(input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort()} ; var i : OclAny := null; var d : OclAny := null; var s : OclAny := null; Sequence{i,d,s} := Sequence{1,t->first(),(t)->sum()} ; while (i->compareTo(n)) < 0 & ((100 * s - k * (s - d))->compareTo(t[i+1] * (100 * n - k * (n - i)))) > 0 do ( d := d + t[i+1]; i := i + 1) ; execute ((100 * s - k * (s - d)) / (100 * n - k * (n - i)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=list(map(int,input().split())) l=0 r=1000 while r-l>1e-7 : mid=(l+r)/2 ans=0 for i in range(n): if a[i]>mid : ans+=(100-k)/100*(a[i]-mid) else : ans-=mid-a[i] if ans>=0 : l=mid else : r=mid print('%.9f' % l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : int := 0 ; var r : int := 1000 ; while r - l > ("1e-7")->toReal() do ( var mid : double := (l + r) / 2 ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1]->compareTo(mid)) > 0 then ( ans := ans + (100 - k) / 100 * (a[i+1] - mid) ) else ( ans := ans - mid - a[i+1] )) ; if ans >= 0 then ( l := mid ) else ( r := mid )) ; execute (StringLib.format('%.9f',l))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=list(map(int,input().split())) l=0 r=1000 p=1-k/100 while r-l>1e-7 : mid=(l+r)/2 ans=0 for i in range(n): if a[i]>mid : ans+=(a[i]-mid)*p else : ans-=mid-a[i] if ans>=0 : l=mid else : r=mid print('%.9f' % l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var l : int := 0 ; var r : int := 1000 ; var p : double := 1 - k / 100 ; while r - l > ("1e-7")->toReal() do ( var mid : double := (l + r) / 2 ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1]->compareTo(mid)) > 0 then ( ans := ans + (a[i+1] - mid) * p ) else ( ans := ans - mid - a[i+1] )) ; if ans >= 0 then ( l := mid ) else ( r := mid )) ; execute (StringLib.format('%.9f',l))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,pow def sieve(prime,n): prime[0]=False prime[1]=False for p in range(2,int(sqrt(n))+1,1): if(prime[p]==True): for i in range(p*p,n+1,p): prime[i]=False def sumPrime(d): maxVal=int(pow(2,d))-1 ; prime=[True for i in range(maxVal+1)] sieve(prime,maxVal) sum=0 for i in range(2,maxVal+1,1): if(prime[i]): sum+=i return sum if __name__=='__main__' : d=8 print(sumPrime(d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( d := 8 ; execute (sumPrime(d))->display() ) else skip; operation sieve(prime : OclAny, n : OclAny) pre: true post: true activity: prime->first() := false ; prime[1+1] := false ; for p : Integer.subrange(2, ("" + ((sqrt(n))))->toInteger() + 1-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (prime[p+1] = true) then ( for i : Integer.subrange(p * p, n + 1-1)->select( $x | ($x - p * p) mod p = 0 ) do ( prime[i+1] := false) ) else skip); operation sumPrime(d : OclAny) : OclAny pre: true post: true activity: var maxVal : double := ("" + (((2)->pow(d))))->toInteger() - 1; ; prime := Integer.subrange(0, maxVal + 1-1)->select(i | true)->collect(i | (true)) ; sieve(prime, maxVal) ; var sum : int := 0 ; for i : Integer.subrange(2, maxVal + 1-1)->select( $x | ($x - 2) mod 1 = 0 ) do ( if (prime[i+1]) then ( sum := sum + i ) else skip) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) lst=list(map(int,input().split())) sum_energy=sum(lst) left=0 right=1000 while right-left>1e-7 : mid=(left+right)/2 sum_transfer=0 for x in lst : if x>mid : sum_transfer+=x-mid if mid*ncollect( _x | (OclType["int"])->apply(_x) ) ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sum_energy : OclAny := (lst)->sum() ; var left : int := 0 ; var right : int := 1000 ; while right - left > ("1e-7")->toReal() do ( var mid : double := (left + right) / 2 ; var sum_transfer : int := 0 ; for x : lst do ( if (x->compareTo(mid)) > 0 then ( sum_transfer := sum_transfer + x - mid ) else skip) ; if (mid * n->compareTo(sum_energy - sum_transfer * k / 100)) < 0 then ( left := mid ) else ( right := mid )) ; execute (StringLib.format('%.9f',left))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(e): s=0 for x in a : if x>e : s+=(x-e)*k/100 return s n,k=map(int,input().split()) a=[int(x)for x in input().split()] s=sum(a) L=-1 R=max(a) for i in range(200): m=(L+R)/2 if s-m*n>f(m): L=m else : R=m print(R) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; s := (a)->sum() ; var L : int := -1 ; var R : OclAny := (a)->max() ; for i : Integer.subrange(0, 200-1) do ( var m : double := (L + R) / 2 ; if (s - m * n->compareTo(f(m))) > 0 then ( L := m ) else ( R := m )) ; execute (R)->display(); operation f(e : OclAny) : OclAny pre: true post: true activity: var s : int := 0 ; for x : a do ( if (x->compareTo(e)) > 0 then ( s := s + (x - e) * k / 100 ) else skip) ; return s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def modInverse(a,prime): a=a % prime for x in range(1,prime): if((a*x)% prime==1): return x return-1 def printModIverses(n,prime): for i in range(1,n+1): print(modInverse(i,prime),end=" ") n=10 prime=17 printModIverses(n,prime) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 10 ; prime := 17 ; printModIverses(n, prime); operation modInverse(a : OclAny, prime : OclAny) : OclAny pre: true post: true activity: a := a mod prime ; for x : Integer.subrange(1, prime-1) do ( if ((a * x) mod prime = 1) then ( return x ) else skip) ; return -1; operation printModIverses(n : OclAny, prime : OclAny) pre: true post: true activity: for i : Integer.subrange(1, n + 1-1) do ( execute (modInverse(i, prime))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def kBitDifferencePairs(arr,n,k): MAX=max(arr) count=[0 for i in range(MAX+1)] for i in range(n): count[arr[i]]+=1 ans=0 if(k==0): for i in range(MAX+1): ans+=(count[i]*(count[i]-1))//2 return ans for i in range(MAX+1): if(count[i]==0): continue for j in range(i+1,MAX+1): if(bin(i ^ j).count('1')==k): ans+=count[i]*count[j] return ans k=2 arr=[2,4,1,3,1] n=len(arr) print("Total pairs for k=",k,"are",kBitDifferencePairs(arr,n,k)) k=3 print("Total pairs for k=",k,"are",kBitDifferencePairs(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; k := 2 ; arr := Sequence{2}->union(Sequence{4}->union(Sequence{1}->union(Sequence{3}->union(Sequence{ 1 })))) ; n := (arr)->size() ; execute ("Total pairs for k=")->display() ; k := 3 ; execute ("Total pairs for k=")->display(); operation kBitDifferencePairs(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var MAX : OclAny := (arr)->max() ; var count : Sequence := Integer.subrange(0, MAX + 1-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( count[arr[i+1]+1] := count[arr[i+1]+1] + 1) ; var ans : int := 0 ; if (k = 0) then ( for i : Integer.subrange(0, MAX + 1-1) do ( ans := ans + (count[i+1] * (count[i+1] - 1)) div 2) ; return ans ) else skip ; for i : Integer.subrange(0, MAX + 1-1) do ( if (count[i+1] = 0) then ( continue ) else skip ; for j : Integer.subrange(i + 1, MAX + 1-1) do ( if (bin(MathLib.bitwiseXor(i, j))->count('1') = k) then ( ans := ans + count[i+1] * count[j+1] ) else skip)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calcFiboTerms(fiboTerms,K): i=3 fiboTerms.append(0) fiboTerms.append(1) fiboTerms.append(1) while True : nextTerm=(fiboTerms[i-1]+fiboTerms[i-2]) if nextTerm>K : return fiboTerms.append(nextTerm) i+=1 def findMinTerms(K): fiboTerms=[] calcFiboTerms(fiboTerms,K) count,j=0,len(fiboTerms)-1 while K>0 : count+=K//fiboTerms[j] K %=fiboTerms[j] j-=1 return count if __name__=="__main__" : K=17 print(findMinTerms(K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( K := 17 ; execute (findMinTerms(K))->display() ) else skip; operation calcFiboTerms(fiboTerms : OclAny, K : OclAny) pre: true post: true activity: var i : int := 3 ; execute ((0) : fiboTerms) ; execute ((1) : fiboTerms) ; execute ((1) : fiboTerms) ; while true do ( var nextTerm : OclAny := (fiboTerms[i - 1+1] + fiboTerms[i - 2+1]) ; if (nextTerm->compareTo(K)) > 0 then ( return ) else skip ; execute ((nextTerm) : fiboTerms) ; i := i + 1); operation findMinTerms(K : OclAny) : OclAny pre: true post: true activity: fiboTerms := Sequence{} ; calcFiboTerms(fiboTerms, K) ; var count : OclAny := null; var j : OclAny := null; Sequence{count,j} := Sequence{0,(fiboTerms)->size() - 1} ; while K > 0 do ( count := count + K div fiboTerms[j+1] ; K := K mod fiboTerms[j+1] ; j := j - 1) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- array=input().split() a_teleports=int(array[0]) location=int(array[1]) pig=0 for _ in range(a_teleports): information=input().split() teleport=int(information[0]) range=int(information[1]) if pig>=teleport and range>pig : pig=range elif pig>=teleport and range<=pig : pig=pig else : break if pig>=location : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var array : OclAny := input().split() ; var a_teleports : int := ("" + ((array->first())))->toInteger() ; var location : int := ("" + ((array[1+1])))->toInteger() ; var pig : int := 0 ; for _anon : Integer.subrange(0, a_teleports-1) do ( var information : OclAny := input().split() ; var teleport : int := ("" + ((information->first())))->toInteger() ; var range : int := ("" + ((information[1+1])))->toInteger() ; if (pig->compareTo(teleport)) >= 0 & (range->compareTo(pig)) > 0 then ( pig := range ) else (if (pig->compareTo(teleport)) >= 0 & (range->compareTo(pig)) <= 0 then ( pig := pig ) else ( break ) ) ) ; if (pig->compareTo(location)) >= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isWordPresent(sentence,word): s=sentence.split(" ") for i in s : if(i==word): return True return False s="Geeks for Geeks" word="Geeks" if(isWordPresent(s,word)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := "Geeks for Geeks" ; word := "Geeks" ; if (isWordPresent(s, word)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isWordPresent(sentence : OclAny, word : OclAny) : OclAny pre: true post: true activity: var s : OclAny := sentence.split(" ") ; for i : s do ( if (i = word) then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumNatural(n): sum=(n*(n+1)) return int(sum) def sumEven(l,r): return(sumNatural(int(r/2))-sumNatural(int((l-1)/2))) l,r=2,5 print("Sum of Natural numbers","from L to R is",sumEven(l,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{l,r} := Sequence{2,5} ; execute ("Sum of Natural numbers")->display(); operation sumNatural(n : OclAny) : OclAny pre: true post: true activity: var sum : double := (n * (n + 1)) ; return ("" + ((sum)))->toInteger(); operation sumEven(l : OclAny, r : OclAny) : OclAny pre: true post: true activity: return (sumNatural(("" + ((r / 2)))->toInteger()) - sumNatural(("" + (((l - 1) / 2)))->toInteger())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumNatural(n): sum=(n*(n+1))//2 return sum def suminRange(l,r): return sumNatural(r)-sumNatural(l-1) l=2 ; r=5 print("Sum of Natural numbers from L to R is ",suminRange(l,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; l := 2; r := 5 ; execute ("Sum of Natural numbers from L to R is ")->display(); operation sumNatural(n : OclAny) : OclAny pre: true post: true activity: var sum : int := (n * (n + 1)) div 2 ; return sum; operation suminRange(l : OclAny, r : OclAny) : OclAny pre: true post: true activity: return sumNatural(r) - sumNatural(l - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def isPerfectSquare(n): if(n<0): return False root=round(math.sqrt(n)) return(n==root*root) def printnonsquare(n): count=0 i=1 while(countsqrt())->round() ; return (n = root * root); operation printnonsquare(n : OclAny) pre: true post: true activity: var count : int := 0 ; var i : int := 1 ; while ((count->compareTo(n)) < 0) do ( if (isPerfectSquare(i) = false) then ( execute (i)->display() ; count := count + 1 ) else skip ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a,b=map(int,input().split()) z=sorted(map(int,input().split())) z.reverse() q,w=0,0 for i in range(a): q+=z[i] if q/(i+1)>=b : w+=1 print(w) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var z : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; z := z->reverse() ; var q : OclAny := null; var w : OclAny := null; Sequence{q,w} := Sequence{0,0} ; for i : Integer.subrange(0, a-1) do ( q := q + z[i+1] ; if (q / (i + 1)->compareTo(b)) >= 0 then ( w := w + 1 ) else skip) ; execute (w)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil,floor def Alcuin(n): _n=n ans=0 ans=(round((_n*_n)/12)-floor(_n/4)*floor((_n+2)/4)) return ans def solve(n): for i in range(1,n+1): print(Alcuin(i),end=",") n=15 solve(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 15 ; solve(n); operation Alcuin(n : OclAny) : OclAny pre: true post: true activity: var _n : OclAny := n ; var ans : int := 0 ; ans := (((_n * _n) / 12)->round() - floor(_n / 4) * floor((_n + 2) / 4)) ; return ans; operation solve(n : OclAny) pre: true post: true activity: for i : Integer.subrange(1, n + 1-1) do ( execute (Alcuin(i))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lds(arr,n): lds=[0]*n max=0 for i in range(n): lds[i]=1 for i in range(1,n): for j in range(i): if(arr[i]union(Sequence{27}->union(Sequence{14}->union(Sequence{38}->union(Sequence{63}->union(Sequence{55}->union(Sequence{46}->union(Sequence{65}->union(Sequence{ 85 })))))))) ; n := (arr)->size() ; execute ("Length of LDS is")->display() ) else skip; operation lds(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var lds : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var max : int := 0 ; for i : Integer.subrange(0, n-1) do ( lds[i+1] := 1) ; for i : Integer.subrange(1, n-1) do ( for j : Integer.subrange(0, i-1) do ( if ((arr[i+1]->compareTo(arr[j+1])) < 0 & (lds[i+1]->compareTo(lds[j+1] + 1)) < 0) then ( lds[i+1] := lds[j+1] + 1 ) else skip)) ; for i : Integer.subrange(0, n-1) do ( if ((max->compareTo(lds[i+1])) < 0) then ( max := lds[i+1] ) else skip) ; return max; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : K=int(input()) if K==0 : break print(sum(list(map(int,input().split())))//(K-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if K = 0 then ( break ) else skip ; execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) )))->sum() div (K - 1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : K=int(input()) if K==0 : break elif K==1 : print(int(input())) else : po=[int(i)for i in input().split()] print(int(sum(po)/(K-1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if K = 0 then ( break ) else (if K = 1 then ( execute (("" + (((OclFile["System.in"]).readLine())))->toInteger())->display() ) else ( var po : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute (("" + (((po)->sum() / (K - 1))))->toInteger())->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : k=int(input())-1 if k<0 : break print(sum(map(int,input().split()))//k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var k : double := ("" + (((OclFile["System.in"]).readLine())))->toInteger() - 1 ; if k < 0 then ( break ) else skip ; execute (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum() div k)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : K=int(input()) if K==0 : break c=[int(i)for i in input().split()] S=0 for i in range(len(c)): S=S+c[i] print(int(S/(K-1))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var K : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if K = 0 then ( break ) else skip ; var c : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var S : int := 0 ; for i : Integer.subrange(0, (c)->size()-1) do ( S := S + c[i+1]) ; execute (("" + ((S / (K - 1))))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- axis=[0]*105 n,m=map(int,input().split()) for _ in range(n): x,y=map(int,input().split()) axis[x+1 : y+1]=[1]*(y-x) for i in range(1,m+1): if not axis[i]: print("No") exit(0) print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var axis : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 105) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; axis.subrange(x + 1+1, y + 1) := MatrixLib.elementwiseMult(Sequence{ 1 }, (y - x))) ; for i : Integer.subrange(1, m + 1-1) do ( if not(axis[i+1]) then ( execute ("No")->display() ; exit(0) ) else skip) ; execute ("YES")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : k=int(input()) if k==0 : break print(sum(map(int,input().split()))//(k-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if k = 0 then ( break ) else skip ; execute (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum() div (k - 1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for test in range(t): n=int(input()) numbers1=list(map(int,input().split())) numbers2=[numbers1[0]] for x in numbers1 : if x not in numbers2 : numbers2.append(x) for i in numbers2 : print(i,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for test : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var numbers1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var numbers2 : Sequence := Sequence{ numbers1->first() } ; for x : numbers1 do ( if (numbers2)->excludes(x) then ( execute ((x) : numbers2) ) else skip) ; for i : numbers2 do ( execute (i)->display())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): list1=[] m=int(input()) t=[int(num)for num in input().split()] for j in range(len(t)): for k in range(j+1,len(t)): if t[j]==t[k]: t[k]=0 for num in t : if num!=0 : list1.append(num) print(*list1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var list1 : Sequence := Sequence{} ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t : Sequence := input().split()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; for j : Integer.subrange(0, (t)->size()-1) do ( for k : Integer.subrange(j + 1, (t)->size()-1) do ( if t[j+1] = t[k+1] then ( t[k+1] := 0 ) else skip)) ; for num : t do ( if num /= 0 then ( execute ((num) : list1) ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name list1))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for p in range(int(input())): n,x=list(map(int,input().split())) a=list(map(int,input().split())) a.sort(reverse=True) s=a[0] if s>=x : f,g,y=0,1,2 for i in range(1,n): s+=a[i] c=s/(y) if ctoInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var s : OclAny := a->first() ; if (s->compareTo(x)) >= 0 then ( var f : OclAny := null; var g : OclAny := null; var y : OclAny := null; Sequence{f,g,y} := Sequence{0,1,2} ; for i : Integer.subrange(1, n-1) do ( s := s + a[i+1] ; var c : double := s / (y) ; if (c->compareTo(x)) < 0 then ( var f : int := 1 ; break ) else skip ; y := y + 1) ; if f then ( execute (i)->display() ) else ( execute (n)->display() ) ) else ( execute (0)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for x in range(t): n=int(input()) a=list(map(int,input().split())) c=[] for x in a : if x not in c : c.append(x) print(*c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for x : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : Sequence := Sequence{} ; for x : a do ( if (c)->excludes(x) then ( execute ((x) : c) ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name c))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=eval(input()) for i in range(t): n=eval(input()) input_list=input().split(" ") output_list=[] count=1 for j in range(len(input_list)): if input_list[j]not in output_list : output_list.append(input_list[j]) count+=1 if count>n : break print(" ".join(output_list)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : OclAny := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := (OclFile["System.in"]).readLine() ; var input_list : OclAny := input().split(" ") ; var output_list : Sequence := Sequence{} ; var count : int := 1 ; for j : Integer.subrange(0, (input_list)->size()-1) do ( if (output_list)->excludes(input_list[j+1]) then ( execute ((input_list[j+1]) : output_list) ; count := count + 1 ; if (count->compareTo(n)) > 0 then ( break ) else skip ) else skip) ; execute (StringLib.sumStringsWithSeparator((output_list), " "))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=input() t=int(t) for i in range(t): n=input() set=input() set=set.split() set=list(dict.fromkeys(set)) for j in range(len(set)): print(set[j],end=" ") print("\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : String := (OclFile["System.in"]).readLine() ; t := ("" + ((t)))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : String := (OclFile["System.in"]).readLine() ; var OclType["Set"] : String := (OclFile["System.in"]).readLine() ; OclType["Set"] := Set{}->union(.split()) ; OclType["Set"] := ((trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name set)))))))) ))))->keys()->asSequence() ; for j : Integer.subrange(0, (OclType["Set"])->size()-1) do ( execute (Set{}->union([j+1]))->display()) ; execute ("\n")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys for s in sys.stdin : a=map(int,s.split(" ")) w=a[0] a=sorted(a[1 :]) A=[] while a : A+=[a.pop(0)] if a==[]: break A=[a.pop()]+A if a==[]: break A+=[a.pop()] if a==[]: break A=[a.pop(0)]+A a=A[0]+A[-1] for i in range(len(A)-1): a+=2*(A[i]*A[i+1])**.5 print["OK","NA"][a>w] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for s : OclFile["System.in"] do ( var a : Sequence := (s.split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; var w : OclAny := a->first() ; a := a->tail()->sort() ; var A : Sequence := Sequence{} ; while a do ( A := A + Sequence{ a->at(0`firstArg+1) } ; if a = Sequence{} then ( break ) else skip ; A := Sequence{ a->last() }->union(A) ; if a = Sequence{} then ( break ) else skip ; A := A + Sequence{ a->last() } ; if a = Sequence{} then ( break ) else skip ; A := Sequence{ a->at(0`firstArg+1) }->union(A)) ; a := A->first() + A->last() ; for i : Integer.subrange(0, (A)->size() - 1-1) do ( a := a + 2 * ((A[i+1] * A[i + 1+1]))->pow(.5)) ; (expr (atom print) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom "OK")))))) , (subscript (test (logical_test (comparison (expr (atom "NA"))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (comparison (expr (atom (name a)))) > (comparison (expr (atom (name w))))))))) ])))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=10**20 def get_dist(r1,r2): c=r1+r2 b=abs(r1-r2) return(c**2-b**2)**(1/2) def minimum_width(rest,r,dic): if(rest,r)in dic : return dic[(rest,r)] if rest==(): return r ret=INF lenr=len(rest) for i,c in enumerate(rest): ret=min(ret,minimum_width(tuple(rest[j]for j in range(lenr)if i!=j),rest[i],dic)+get_dist(r,rest[i])) dic[(rest,r)]=ret return ret while True : try : lst=list(map(int,input().split())) w=lst[0] cakes=lst[1 :] cakes.sort() lenc=len(cakes) dic={} ans=INF for i in range(lenc): ans=min(ans,minimum_width(tuple(cakes[j]for j in range(lenc)if i!=j),cakes[i],dic)+cakes[i]) if w>=ans : print("OK") else : print("NA") except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INF : double := (10)->pow(20) ; skip ; skip ; while true do ( try ( var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var w : OclAny := lst->first() ; var cakes : OclAny := lst->tail() ; cakes := cakes->sort() ; var lenc : int := (cakes)->size() ; dic := Set{} ; var ans : OclAny := INF ; for i : Integer.subrange(0, lenc-1) do ( ans := Set{ans, minimum_width(((argument (test (logical_test (comparison (expr (atom (name cakes)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name lenc)))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name i)))) != (comparison (expr (atom (name j))))))))))), cakes[i+1], dic) + cakes[i+1]}->min()) ; if (w->compareTo(ans)) >= 0 then ( execute ("OK")->display() ) else ( execute ("NA")->display() )) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); operation get_dist(r1 : OclAny, r2 : OclAny) : OclAny pre: true post: true activity: var c : OclAny := r1 + r2 ; var b : double := (r1 - r2)->abs() ; return (((c)->pow(2) - (b)->pow(2)))->pow((1 / 2)); operation minimum_width(rest : OclAny, r : OclAny, dic : OclAny) : OclAny pre: true post: true activity: if (dic)->includes(Sequence{rest, r}) then ( return dic[Sequence{rest, r}+1] ) else skip ; if rest = () then ( return r ) else skip ; var ret : OclAny := INF ; var lenr : int := (rest)->size() ; for _tuple : Integer.subrange(1, (rest)->size())->collect( _indx | Sequence{_indx-1, (rest)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); ret := Set{ret, minimum_width(((argument (test (logical_test (comparison (expr (atom (name rest)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))) (comp_for for (exprlist (expr (atom (name j)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name lenr)))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name i)))) != (comparison (expr (atom (name j))))))))))), rest[i+1], dic) + get_dist(r, rest[i+1])}->min()) ; dic[Sequence{rest, r}+1] := ret ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin input=stdin.readline def calc_width(cakes): if len(cakes)==1 : return cakes[0]*2 prev_r=cakes[0] width=prev_r for r in cakes[1 :]: h_diff=abs(prev_r-r) w=((prev_r+r)**2-h_diff**2)**0.5 width+=w prev_r=r width+=cakes[-1] return width def main(args): for line in sys.stdin : data=[int(x)for x in line.strip().split()] box_size=data[0] temp=data[1 :] temp.sort() min_width=float('inf') cakes=[temp[0]] temp=temp[1 :] pick_large=True while temp : if pick_large : pick=temp[-1] temp=temp[:-1] pick_large=False diff_front=abs(pick-cakes[0]) diff_rear=abs(pick-cakes[-1]) if diff_front>diff_rear : cakes.insert(0,pick) else : cakes.append(pick) else : pick=temp[0] temp=temp[1 :] pick_large=True diff_front=abs(pick-cakes[0]) diff_rear=abs(pick-cakes[-1]) if diff_front>diff_rear : cakes.insert(0,pick) else : cakes.append(pick) result=calc_width(cakes) min_width=min(result,min_width) if min_width<=box_size : print('OK') else : print('NA') if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation calc_width(cakes : OclAny) : OclAny pre: true post: true activity: if (cakes)->size() = 1 then ( return cakes->first() * 2 ) else skip ; var prev_r : OclAny := cakes->first() ; var width : OclAny := prev_r ; for r : cakes->tail() do ( var h_diff : double := (prev_r - r)->abs() ; var w : double := ((((prev_r + r))->pow(2) - (h_diff)->pow(2)))->pow(0.5) ; width := width + w ; prev_r := r) ; width := width + cakes->last() ; return width; operation main(args : OclAny) pre: true post: true activity: for line : OclFile["System.in"] do ( var data : Sequence := line->trim().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var box_size : OclAny := data->first() ; var temp : OclAny := data->tail() ; temp := temp->sort() ; var min_width : double := ("" + (('inf')))->toReal() ; cakes := Sequence{ temp->first() } ; temp := temp->tail() ; var pick_large : boolean := true ; while temp do ( if pick_large then ( var pick : OclAny := temp->last() ; temp := temp->front() ; pick_large := false ; var diff_front : double := (pick - cakes->first())->abs() ; var diff_rear : double := (pick - cakes->last())->abs() ; if (diff_front->compareTo(diff_rear)) > 0 then ( cakes := cakes.insertAt(0+1, pick) ) else ( execute ((pick) : cakes) ) ) else ( pick := temp->first() ; temp := temp->tail() ; pick_large := true ; diff_front := (pick - cakes->first())->abs() ; diff_rear := (pick - cakes->last())->abs() ; if (diff_front->compareTo(diff_rear)) > 0 then ( cakes := cakes.insertAt(0+1, pick) ) else ( execute ((pick) : cakes) ) )) ; var result : OclAny := calc_width(cakes) ; min_width := Set{result, min_width}->min() ; if (min_width->compareTo(box_size)) <= 0 then ( execute ('OK')->display() ) else ( execute ('NA')->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=0x7fffffff R=100000 d=[[0 for j in range(13)]for i in range(13)] for i in range(3,11): ii=i*i for j in range(i,11): d[i][j]=d[j][i]=int(2*R*ii**0.5) ii+=i while 1 : try : r=list(map(int,input().split())) except : break W=r.pop(0) if 2*sum(r)<=W : print("OK") continue n=len(r) W*=R dp=[[INF for j in range(1<select(i | true)->collect(i | (Integer.subrange(0, 13-1)->select(j | true)->collect(j | (0)))) ; for i : Integer.subrange(3, 11-1) do ( var ii : double := i * i ; for j : Integer.subrange(i, 11-1) do ( d[i+1][j+1] := ("" + ((2 * R * (ii)->pow(0.5))))->toInteger(); var d[j+1][i+1] : int := ("" + ((2 * R * (ii)->pow(0.5))))->toInteger() ; ii := ii + i)) ; while 1 do ( try ( var r : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) catch (_e : OclException) do ( break) ; var W : String := r->at(0`firstArg+1) ; r := r->excludingAt(0+1) ; if 2 * (r)->sum() <= W then ( execute ("OK")->display() ; continue ) else skip ; var n : int := (r)->size() ; W := W * R ; var dp : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (Integer.subrange(0, 1 * (2->pow(n))-1)->select(j | true)->collect(j | (INF)))) ; for i : Integer.subrange(0, n-1) do ( dp[i+1][1 * (2->pow(i))+1] := r[i+1] * R) ; var lim : int := 1 * (2->pow(n)) ; for k : Integer.subrange(0, lim-1) do ( for i : Integer.subrange(0, n-1) do ( if MathLib.bitwiseAnd(k, (1 * (2->pow(i)))) then ( continue ) else skip ; for j : Integer.subrange(0, n-1) do ( dp[i+1][MathLib.bitwiseOr(k, (1 * (2->pow(i))))+1] := Set{dp[i+1][MathLib.bitwiseOr(k, (1 * (2->pow(i))))+1], dp[j+1][k+1] + d[r[i+1]+1][r[j+1]+1]}->min()))) ; var w : int := 240 * R ; for i : Integer.subrange(0, n-1) do ( dp[i+1][lim - 1+1] := dp[i+1][lim - 1+1] + r[i+1] * R ; if (dp[i+1][lim - 1+1]->compareTo(w)) < 0 then ( w := dp[i+1][lim - 1+1]; ) else skip) ; execute (if w <= W then "OK" else "NA" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from multiprocessing.resource_sharer import stop input_1=input().split() [n,m]=list(map(int,input_1)) position=int(0) friend=False for i in range(n): input_2=input().split() [a_i,b_i]=list(map(int,input_2)) if a_i<=position and b_i>position : position=b_i if position>=m : friend=True print("Yes") break if friend==False : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input skip : OclAny := input().split() ; Sequence{n}->union(Sequence{ m }) := ((inputOclType["int"], inputOclType["int"])->collect( _x | (OclType["int"])->apply(_x) )) ; var position : int := ("" + ((0)))->toInteger() ; var friend : boolean := false ; for i : Integer.subrange(0, n-1) do ( var input:= input().split() : OclAny := input().split()) ; Sequence{a_i}->union(Sequence{ b_i }) := ((input_2)->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from math import sqrt def rec(state,v): if state==(1<>i & 1): ret=min(ret,rec(state | 1<select(line | true)->collect(line | (line.split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())))) ; for testcase : testcases do ( var box : OclAny := null; var cakes : OclAny := null; Sequence{box,cakes} := testcase ; var N : int := (cakes)->size() ; var INF : OclAny := box + 1 ; var dp : Sequence := Integer.subrange(0, 1 * (2->pow(N))-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ -1 }, N))) ; execute (if (rec(0, 0)->compareTo(box)) <= 0 then 'OK' else 'NA' endif)->display()); operation rec(state : OclAny, v : OclAny) : OclAny pre: true post: true activity: if state = (1 * (2->pow(N))) - 1 then ( return cakes[v+1] ) else skip ; if dp[state+1][v+1] /= -1 then ( return dp[state+1][v+1] ) else skip ; var ret : OclAny := INF ; for i : Integer.subrange(0, N-1) do ( if state = 0 then ( ret := Set{ret, rec(1 * (2->pow(i)), i) + cakes[i+1]}->min() ) else (if not((MathLib.bitwiseAnd(state /(2->pow(i)), 1))) then ( ret := Set{ret, rec(MathLib.bitwiseOr(state, 1 * (2->pow(i))), i) + sqrt((cakes[i+1] + cakes[v+1])->pow(2) - (cakes[i+1] - cakes[v+1])->pow(2))}->min() ) else skip)) ; dp[state+1][v+1] := ret ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(N,A): ret=0 for idx in range(N): ret+=A[idx]//2 A[idx]%=2 if A[idx]and idx+1toInteger() ; A := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (0)) ; for idx : Integer.subrange(0, N-1) do ( A[idx+1] := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; execute (solve(N, A))->display() ) else skip; operation solve(N : OclAny, A : OclAny) : OclAny pre: true post: true activity: var ret : int := 0 ; for idx : Integer.subrange(0, N-1) do ( ret := ret + A[idx+1] div 2 ; A[idx+1] := A[idx+1] mod 2 ; if A[idx+1] & (idx + 1->compareTo(N)) < 0 & A[idx + 1+1] then ( ret := ret + 1 ; A[idx + 1+1] := A[idx + 1+1] - 1 ) else skip) ; return ret; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=input().split() inl=[] for i in l : x=int(i) inl.append(x) for i in range(len(l)): Max=max(abs(inl[i]-inl[-1]),abs(inl[i]-inl[0])) Min=min(abs(inl[i]-inl[(i+1)% len(inl)]),abs(inl[i]-inl[i-1])) print(Min,Max) Max=0 Min=0 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : OclAny := input().split() ; var inl : Sequence := Sequence{} ; for i : l do ( var x : int := ("" + ((i)))->toInteger() ; execute ((x) : inl)) ; for i : Integer.subrange(0, (l)->size()-1) do ( var Max : OclAny := Set{(inl[i+1] - inl->last())->abs(), (inl[i+1] - inl->first())->abs()}->max() ; var Min : OclAny := Set{(inl[i+1] - inl[(i + 1) mod (inl)->size()+1])->abs(), (inl[i+1] - inl[i - 1+1])->abs()}->min() ; execute (Min)->display() ; Max := 0 ; Min := 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.readline().strip() def mapint(): return map(int,input().split()) sys.setrecursionlimit(10**9) N=int(input()) Xs=[int(input())for _ in range(N)] last=0 ans=0 for i in range(1,N+1): cnt=Xs[i-1] if cnt<=last : ans+=cnt last=0 else : ans+=last cnt-=last ans+=cnt//2 last=cnt % 2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var Xs : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var last : int := 0 ; var ans : int := 0 ; for i : Integer.subrange(1, N + 1-1) do ( var cnt : OclAny := Xs[i - 1+1] ; if (cnt->compareTo(last)) <= 0 then ( ans := ans + cnt ; last := 0 ) else ( ans := ans + last ; cnt := cnt - last ; ans := ans + cnt div 2 ; last := cnt mod 2 )) ; execute (ans)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation mapint() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,*a=map(int,open(0).read().split()) ans=a[0]//2 a[0]%=2 for i in range(n-1): if a[i]==1 and a[i+1]!=0 : ans+=1 a[i+1]-=1 if a[i+1]>1 : ans+=a[i+1]//2 a[i+1]%=2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := (open(0).readAll().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := a->first() div 2 ; a->first() := a->first() mod 2 ; for i : Integer.subrange(0, n - 1-1) do ( if a[i+1] = 1 & a[i + 1+1] /= 0 then ( ans := ans + 1 ; a[i + 1+1] := a[i + 1+1] - 1 ) else skip ; if a[i + 1+1] > 1 then ( ans := ans + a[i + 1+1] div 2 ; a[i + 1+1] := a[i + 1+1] mod 2 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def input(): return sys.stdin.readline().strip() def list2d(a,b,c): return[[c]*b for i in range(a)] def list3d(a,b,c,d): return[[[d]*c for j in range(b)]for i in range(a)] def list4d(a,b,c,d,e): return[[[[e]*d for j in range(c)]for j in range(b)]for i in range(a)] def ceil(x,y=1): return int(-(-x//y)) def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(N=None): return list(MAP())if N is None else[INT()for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10**9) INF=float('inf') MOD=10**9+7 N=INT() A=LIST(N) ans=A[0]//2 mod=A[0]% 2 for i in range(1,N): ans+=A[i]//2 tmpmod=A[i]% 2 if mod==tmpmod==1 : ans+=1 mod=0 elif tmpmod==1 : mod=1 elif A[i]==0 : mod=0 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; N := INT() ; var A : OclAny := LIST(N) ; var ans : int := A->first() div 2 ; var mod : int := A->first() mod 2 ; for i : Integer.subrange(1, N-1) do ( ans := ans + A[i+1] div 2 ; var tmpmod : int := A[i+1] mod 2 ; if mod = tmpmod & (tmpmod == 1) then ( ans := ans + 1 ; mod := 0 ) else (if tmpmod = 1 then ( mod := 1 ) else (if A[i+1] = 0 then ( mod := 0 ) else skip ) ) ) ; execute (ans)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation list2d(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, a-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ c }, b))); operation list3d(a : OclAny, b : OclAny, c : OclAny, d : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, a-1)->select(i | true)->collect(i | (Integer.subrange(0, b-1)->select(j | true)->collect(j | (MatrixLib.elementwiseMult(Sequence{ d }, c))))); operation list4d(a : OclAny, b : OclAny, c : OclAny, d : OclAny, e : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, a-1)->select(i | true)->collect(i | (Integer.subrange(0, b-1)->select(j | true)->collect(j | (Integer.subrange(0, c-1)->select(j | true)->collect(j | (MatrixLib.elementwiseMult(Sequence{ e }, d))))))); operation ceil(x : OclAny, y : int) : OclAny pre: true post: true activity: if y->oclIsUndefined() then y := 1 else skip; return ("" + ((-(-x div y))))->toInteger(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST(N : OclAny) : OclAny pre: true post: true activity: if N->oclIsUndefined() then N := null else skip; return if N <>= null then (MAP()) else Integer.subrange(0, N-1)->select(i | true)->collect(i | (INT())) endif; operation Yes() pre: true post: true activity: execute ('Yes')->display(); operation No() pre: true post: true activity: execute ('No')->display(); operation YES() pre: true post: true activity: execute ('YES')->display(); operation NO() pre: true post: true activity: execute ('NO')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math import bisect import queue def input(): return sys.stdin.readline().rstrip() def main(): N=int(input()) A=[] for _ in range(N): a=int(input()) A.append(a) B=[] C=[] for a in A : if a!=0 : C.append(a) else : B.append(C) C=[] if len(C)>0 : B.append(C) res=0 for b in B : res+=sum(b)//2 print(res) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine().rstrip(); operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := Sequence{} ; for _anon : Integer.subrange(0, N-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((a) : A)) ; var B : Sequence := Sequence{} ; var C : Sequence := Sequence{} ; for a : A do ( if a /= 0 then ( execute ((a) : C) ) else ( execute ((C) : B) ; C := Sequence{} )) ; if (C)->size() > 0 then ( execute ((C) : B) ) else skip ; var res : int := 0 ; for b : B do ( res := res + (b)->sum() div 2) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairs(arr,N): M=dict.fromkeys(arr,0); for i in range(N): M[arr[i]]+=1 ; maxFreq=0 ; for it in M.values(): maxFreq=max(maxFreq,it); print(N-maxFreq); if __name__=="__main__" : arr=[1,8,5,9,8,8,7,7,5,7,7]; N=len(arr); countPairs(arr,N); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{8}->union(Sequence{5}->union(Sequence{9}->union(Sequence{8}->union(Sequence{8}->union(Sequence{7}->union(Sequence{7}->union(Sequence{5}->union(Sequence{7}->union(Sequence{ 7 })))))))))); ; N := (arr)->size(); ; countPairs(arr, N); ) else skip; operation countPairs(arr : OclAny, N : OclAny) pre: true post: true activity: var M : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))); ; for i : Integer.subrange(0, N-1) do ( M[arr[i+1]+1] := M[arr[i+1]+1] + 1;) ; var maxFreq : int := 0; ; for it : M.values() do ( maxFreq := Set{maxFreq, it}->max();) ; execute (N - maxFreq)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W,K=map(int,input().split()) MOD=10**9+7 dp=[[0]*W for _ in range(H+1)] dp[0][0]=1 for h in range(H): for x in range(W): for b in range(2**(W-1)): if not '11' in bin(b): if x>=1 and(b>>(x-1))& 1 : dp[h+1][x-1]+=dp[h][x] dp[h+1][x-1]%=MOD elif x<=W-2 and(b>>x)& 1 : dp[h+1][x+1]+=dp[h][x] dp[h+1][x+1]%=MOD else : dp[h+1][x]+=dp[h][x] dp[h+1][x]%=MOD print(dp[H][K-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; var K : OclAny := null; Sequence{H,W,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var MOD : double := (10)->pow(9) + 7 ; var dp : Sequence := Integer.subrange(0, H + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, W))) ; dp->first()->first() := 1 ; for h : Integer.subrange(0, H-1) do ( for x : Integer.subrange(0, W-1) do ( for b : Integer.subrange(0, (2)->pow((W - 1))-1) do ( if not((bin(b))->includes('11')) then ( if x >= 1 & MathLib.bitwiseAnd((b /(2->pow((x - 1)))), 1) then ( dp[h + 1+1][x - 1+1] := dp[h + 1+1][x - 1+1] + dp[h+1][x+1] ; dp[h + 1+1][x - 1+1] := dp[h + 1+1][x - 1+1] mod MOD ) else (if (x->compareTo(W - 2)) <= 0 & MathLib.bitwiseAnd((b /(2->pow(x))), 1) then ( dp[h + 1+1][x + 1+1] := dp[h + 1+1][x + 1+1] + dp[h+1][x+1] ; dp[h + 1+1][x + 1+1] := dp[h + 1+1][x + 1+1] mod MOD ) else ( dp[h + 1+1][x+1] := dp[h + 1+1][x+1] + dp[h+1][x+1] ; dp[h + 1+1][x+1] := dp[h + 1+1][x+1] mod MOD ) ) ) else skip))) ; execute (dp[H+1][K - 1+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W,K=(int(i)for i in input().split()) if W==1 : print(1) else : wnum=[0]*(W-1) for i in range(W-1): wsum=0 for j in range(2**(W-1)): bit=format(j,"0{}b".format(W-1)) cc=0 for k in range(W-2): if bit[k]=="1" and bit[k+1]=="1" : break else : if bit[i]=="1" : wnum[i]+=1 wsum+=1 dp=[[0]*W for i in range(H+1)] dp[0][0]=1 for i in range(H): for j in range(W): if 1<=j<=W-2 : dp[i+1][j]=dp[i][j-1]*wnum[j-1]+dp[i][j+1]*wnum[j]+dp[i][j]*(wsum-wnum[j-1]-wnum[j]) elif j==0 : dp[i+1][j]=dp[i][j+1]*wnum[j]+dp[i][j]*(wsum-wnum[j]) else : dp[i+1][j]=dp[i][j-1]*wnum[j-1]+dp[i][j]*(wsum-wnum[j-1]) dp[i+1][j]=dp[i+1][j]% 1000000007 print(dp[H][K-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; var K : OclAny := null; Sequence{H,W,K} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; if W = 1 then ( execute (1)->display() ) else ( var wnum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (W - 1)) ; for i : Integer.subrange(0, W - 1-1) do ( var wsum : int := 0 ; for j : Integer.subrange(0, (2)->pow((W - 1))-1) do ( var bit : String := (j + "") ; var cc : int := 0 ; (compound_stmt for (exprlist (expr (atom (name k)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name W))) - (expr (atom (number (integer 2)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name bit)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k)))))))) ])))) == (comparison (expr (atom "1"))))) and (logical_test (comparison (comparison (expr (atom (name bit)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name k))) + (expr (atom (number (integer 1)))))))))) ])))) == (comparison (expr (atom "1"))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name bit)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) == (comparison (expr (atom "1")))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name wnum)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name wsum)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))))))) ; var dp : Sequence := Integer.subrange(0, H + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, W))) ; dp->first()->first() := 1 ; for i : Integer.subrange(0, H-1) do ( for j : Integer.subrange(0, W-1) do ( if 1 <= j & (j <= W - 2) then ( dp[i + 1+1][j+1] := dp[i+1][j - 1+1] * wnum[j - 1+1] + dp[i+1][j + 1+1] * wnum[j+1] + dp[i+1][j+1] * (wsum - wnum[j - 1+1] - wnum[j+1]) ) else (if j = 0 then ( dp[i + 1+1][j+1] := dp[i+1][j + 1+1] * wnum[j+1] + dp[i+1][j+1] * (wsum - wnum[j+1]) ) else ( dp[i + 1+1][j+1] := dp[i+1][j - 1+1] * wnum[j - 1+1] + dp[i+1][j+1] * (wsum - wnum[j - 1+1]) ) ) ; dp[i + 1+1][j+1] := dp[i + 1+1][j+1] mod 1000000007)) ; execute (dp[H+1][K - 1+1])->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools h,w,k=[int(i)for i in input().split()] dp=[[0 for i in range(w)]for j in range(h+1)] dp[0][0]=1 if w==1 : print(1) exit() for i in range(1,h+1): for kuji_list in itertools.product([0,1],repeat=w-1): for l in range(len(kuji_list)-1): if kuji_list[l]==1 and kuji_list[l+1]==1 : break else : for j in range(w): if j==0 : if kuji_list[j]==1 : dp[i][j]+=dp[i-1][j+1] else : dp[i][j]+=dp[i-1][j] elif j==w-1 : if kuji_list[j-1]==1 : dp[i][j]+=dp[i-1][j-1] else : dp[i][j]+=dp[i-1][j] else : if kuji_list[j-1]==1 : dp[i][j]+=dp[i-1][j-1] elif kuji_list[j]==1 : dp[i][j]+=dp[i-1][j+1] else : dp[i][j]+=dp[i-1][j] dp[i][j]%=(10**9+7) ans=dp[-1][k-1]%(10**9+7) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var h : OclAny := null; var w : OclAny := null; var k : OclAny := null; Sequence{h,w,k} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var dp : Sequence := Integer.subrange(0, h + 1-1)->select(j | true)->collect(j | (Integer.subrange(0, w-1)->select(i | true)->collect(i | (0)))) ; dp->first()->first() := 1 ; if w = 1 then ( execute (1)->display() ; exit() ) else skip ; for i : Integer.subrange(1, h + 1-1) do ( for kuji_list : itertools.product(Sequence{0}->union(Sequence{ 1 }), (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (expr (atom (name w))) - (expr (atom (number (integer 1)))))))))) do ((compound_stmt for (exprlist (expr (atom (name l)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name kuji_list)))))))) )))) - (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name kuji_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name l)))))))) ])))) == (comparison (expr (atom (number (integer 1))))))) and (logical_test (comparison (comparison (expr (atom (name kuji_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name l))) + (expr (atom (number (integer 1)))))))))) ])))) == (comparison (expr (atom (number (integer 1))))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name w)))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name j)))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name kuji_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 1)))))))))) ])))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))))))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name j)))) == (comparison (expr (expr (atom (name w))) - (expr (atom (number (integer 1))))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name kuji_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name j))) - (expr (atom (number (integer 1)))))))))) ])))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name j))) - (expr (atom (number (integer 1)))))))))) ])))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))))))))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name kuji_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name j))) - (expr (atom (number (integer 1)))))))))) ])))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name j))) - (expr (atom (number (integer 1)))))))))) ])))))))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name kuji_list)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name j))) + (expr (atom (number (integer 1)))))))))) ]))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))))))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))))))) (assign_part %= (testlist (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (number (integer 10)))) ** (expr (atom (number (integer 9))))) + (expr (atom (number (integer 7))))))))) ))))))))))))))))))) ; var ans : int := dp->last()[k - 1+1] mod ((10)->pow(9) + 7) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dimensions=input().split(' ') n=int(dimensions[0]) m=int(dimensions[1]) end=0 for i in range(n): teleport=input().split(' ') start=int(teleport[0]) if start>end : break else : end=max(end,int(teleport[1])) if end>=m : print("YES") break if endfirst())))->toInteger() ; var m : int := ("" + ((dimensions[1+1])))->toInteger() ; var end : int := 0 ; for i : Integer.subrange(0, n-1) do ( var teleport : OclAny := input().split(' ') ; var start : int := ("" + ((teleport->first())))->toInteger() ; if (start->compareTo(end)) > 0 then ( break ) else ( end := Set{end, ("" + ((teleport[1+1])))->toInteger()}->max() ) ; if (end->compareTo(m)) >= 0 then ( execute ("YES")->display() ; break ) else skip) ; if (end->compareTo(m)) < 0 then ( execute ("NO")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- H,W,K=map(int,input().split()) MOD=10**9+7 dp={i :{j : 0 for j in range(1,W+1)}for i in range(H+1)} dp[0][1]=1 n_valid_patterns={i :-1 for i in range(W+1)} def valid_patterns(n): if n_valid_patterns[n]!=-1 : return n_valid_patterns[n] elif n<=1 : return 1 elif n==2 : return 2 else : n_valid_patterns[n]=(valid_patterns(n-2)+valid_patterns(n-1))% MOD return n_valid_patterns[n] for i in range(1,H+1): for j in range(1,W+1): if j>1 : dp[i][j]+=dp[i-1][j-1]*(valid_patterns(j-2)*valid_patterns(W-j))% MOD dp[i][j]+=dp[i-1][j]*(valid_patterns(j-1)*valid_patterns(W-j))% MOD if jcollect( _x | (OclType["int"])->apply(_x) ) ; var MOD : double := (10)->pow(9) + 7 ; var dp : Map := Integer.subrange(0, H + 1-1)->select(i | true)->collect(i | Map{i |-> Integer.subrange(1, W + 1-1)->select(j | true)->collect(j | Map{j |-> 0})->unionAll()})->unionAll() ; dp->first()[1+1] := 1 ; var n_valid_patterns : Map := Integer.subrange(0, W + 1-1)->select(i | true)->collect(i | Map{i |-> -1})->unionAll() ; skip ; for i : Integer.subrange(1, H + 1-1) do ( for j : Integer.subrange(1, W + 1-1) do ( if j > 1 then ( dp[i+1][j+1] := dp[i+1][j+1] + dp[i - 1+1][j - 1+1] * (valid_patterns(j - 2) * valid_patterns(W - j)) mod MOD ) else skip ; dp[i+1][j+1] := dp[i+1][j+1] + dp[i - 1+1][j+1] * (valid_patterns(j - 1) * valid_patterns(W - j)) mod MOD ; if (j->compareTo(W)) < 0 then ( dp[i+1][j+1] := dp[i+1][j+1] + dp[i - 1+1][j + 1+1] * (valid_patterns(j - 1) * valid_patterns(W - j - 1)) mod MOD ) else skip ; dp[i+1][j+1] := dp[i+1][j+1] mod MOD)) ; execute (dp[H+1][K+1])->display(); operation valid_patterns(n : OclAny) : OclAny pre: true post: true activity: if n_valid_patterns[n+1] /= -1 then ( return n_valid_patterns[n+1] ) else (if n <= 1 then ( return 1 ) else (if n = 2 then ( return 2 ) else ( n_valid_patterns[n+1] := (valid_patterns(n - 2) + valid_patterns(n - 1)) mod MOD ; return n_valid_patterns[n+1] ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for tt in range(int(input())): n,x=map(int,input().split()) l=sorted(list(map(int,input().split()))) s=sum(l) sm=0 for i in range(n+1): if(n-i)*x<=s-sm : print(n-i) break sm+=l[i] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for tt : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var s : OclAny := (l)->sum() ; var sm : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( if ((n - i) * x->compareTo(s - sm)) <= 0 then ( execute (n - i)->display() ; break ) else skip ; sm := sm + l[i+1])); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline INF=10**9 MOD=10**9+7 def main(): h,w,k=map(int,input().split()) dp=[[0]*w for _ in range(h+1)] dp[0][0]=1 for i in range(h): for bit in range(1<<(w-1)): flag=False before=-2 line=[0]*(w-1) for j in range(w-1): if(bit>>j)& 1 : if before+1==j : flag=True break else : before=j line[j]=1 if flag : continue j=0 while jpow(9) ; var MOD : double := (10)->pow(9) + 7 ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var h : OclAny := null; var w : OclAny := null; var k : OclAny := null; Sequence{h,w,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dp : Sequence := Integer.subrange(0, h + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, w))) ; dp->first()->first() := 1 ; for i : Integer.subrange(0, h-1) do ( for bit : Integer.subrange(0, 1 * (2->pow((w - 1)))-1) do ( var flag : boolean := false ; var before : int := -2 ; var line : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (w - 1)) ; for j : Integer.subrange(0, w - 1-1) do ( if MathLib.bitwiseAnd((bit /(2->pow(j))), 1) then ( if before + 1 = j then ( flag := true ; break ) else ( before := j ; line[j+1] := 1 ) ) else skip) ; if flag then ( continue ) else skip ; var j : int := 0 ; while (j->compareTo(w)) < 0 do ( if j = w - 1 then ( dp[i + 1+1][j+1] := dp[i + 1+1][j+1] + dp[i+1][j+1] ; dp[i + 1+1][j+1] := dp[i + 1+1][j+1] mod MOD ; break ) else skip ; if line[j+1] then ( dp[i + 1+1][j+1] := dp[i + 1+1][j+1] + dp[i+1][j + 1+1] ; dp[i + 1+1][j+1] := dp[i + 1+1][j+1] mod MOD ; dp[i + 1+1][j + 1+1] := dp[i + 1+1][j + 1+1] + dp[i+1][j+1] ; dp[i + 1+1][j + 1+1] := dp[i + 1+1][j + 1+1] mod MOD ; j := j + 2 ) else ( dp[i + 1+1][j+1] := dp[i + 1+1][j+1] + dp[i+1][j+1] ; dp[i + 1+1][j+1] := dp[i + 1+1][j+1] mod MOD ; j := j + 1 )))) ; execute (dp->last()[k - 1+1] mod MOD)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=3 def findStepsForDDM(arr): result=0 for i in range(N): sum=0 for j in range(N): sum+=abs(arr[i][j]) sum-=abs(arr[i][i]) if(abs(arr[i][i])union(Sequence{-2}->union(Sequence{ 1 }))}->union(Sequence{Sequence{1}->union(Sequence{-3}->union(Sequence{ 2 }))}->union(Sequence{ Sequence{-1}->union(Sequence{2}->union(Sequence{ 4 })) })) ; execute (findStepsForDDM(arr))->display(); operation findStepsForDDM(arr : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; for i : Integer.subrange(0, N-1) do ( var sum : int := 0 ; for j : Integer.subrange(0, N-1) do ( sum := sum + (arr[i+1][j+1])->abs()) ; sum := sum - (arr[i+1][i+1])->abs() ; if (((arr[i+1][i+1])->abs()->compareTo((sum)->abs())) < 0) then ( result := result + ((arr[i+1][i+1])->abs() - (sum)->abs())->abs() ) else skip) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- first=input() second=input() third=input() fourth=input() rows=first+"-"+second+"-"+third+"-"+fourth if "xx." in rows or ".xx" in rows or "x.x" in rows : print("YES") else : columns=first[0]+second[1]+third[2]+fourth[3]+"-"+first[3]+second[2]+third[1]+fourth[0]+"-"+second[0]+third[1]+fourth[2]+"-"+second[3]+third[2]+fourth[1]+"-"+first[2]+second[1]+third[0]+"-"+first[1]+second[2]+third[3]+"-" for i in range(4): columns+=first[i]+second[i]+third[i]+fourth[i]+"-" if "xx." in columns or ".xx" in columns or "x.x" in columns : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var first : String := (OclFile["System.in"]).readLine() ; var second : String := (OclFile["System.in"]).readLine() ; var third : String := (OclFile["System.in"]).readLine() ; var fourth : String := (OclFile["System.in"]).readLine() ; var rows : String := first + "-" + second + "-" + third + "-" + fourth ; if (rows)->characters()->includes("xx.") or (rows)->characters()->includes(".xx") or (rows)->characters()->includes("x.x") then ( execute ("YES")->display() ) else ( var columns : OclAny := first->first() + second[1+1] + third[2+1] + fourth[3+1] + "-" + first[3+1] + second[2+1] + third[1+1] + fourth->first() + "-" + second->first() + third[1+1] + fourth[2+1] + "-" + second[3+1] + third[2+1] + fourth[1+1] + "-" + first[2+1] + second[1+1] + third->first() + "-" + first[1+1] + second[2+1] + third[3+1] + "-" ; for i : Integer.subrange(0, 4-1) do ( columns := columns + first[i+1] + second[i+1] + third[i+1] + fourth[i+1] + "-") ; if (columns)->includes("xx.") or (columns)->includes(".xx") or (columns)->includes("x.x") then ( execute ("YES")->display() ) else ( execute ("NO")->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import functools import multiprocessing import fractions def pow2(x): return x!=0 and((x &(x-1))==0) def solve(cs,f): if not pow2(f.denominator): return cs,'impossible' ret=1 while ftoInteger() ; l := Sequence{} ; try (var pool : OclAny := multiprocessing.Pool((argument (test (logical_test (comparison (expr (atom (name processes)))))) = (test (logical_test (comparison (expr (atom (number (integer 8))))))))); for cs : Integer.subrange(0, T-1) do ( f := fractions.Fraction((OclFile["System.in"]).readLine()) ; solve(cs, f) ; pool.apply_async(solve, (argument (test (logical_test (comparison (expr (atom (name args)))))) = (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name cs))) + (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (atom (name f)))))) ,) ))))))), (argument (test (logical_test (comparison (expr (atom (name callback)))))) = (test (logical_test (comparison (expr (atom (name functools)) (trailer . (name partial) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name reducer))))))) , (argument (test (logical_test (comparison (expr (atom (name l)))))))) )))))))))) ; pool.closeFile() ; pool.join()) catch (_e : OclException) do skip ; for _tuple : l->sortedBy($x | (lambda x : OclAny in (x->first()))->apply($x)) do (var _indx : int := 1; var cs : OclAny := _tuple->at(_indx); _indx := _indx + 1; var result : OclAny := _tuple->at(_indx); execute (StringLib.interpolateStrings('Case #{}:{}', Sequence{cs, result}))->display()) ) else skip; operation pow2(x : OclAny) : OclAny pre: true post: true activity: return x /= 0 & ((MathLib.bitwiseAnd(x, (x - 1))) = 0); operation solve(cs : OclAny, f : OclAny) : OclAny pre: true post: true activity: if not(pow2(f.denominator)) then ( return cs, 'impossible' ) else skip ; var ret : int := 1 ; while (f->compareTo(fractions.Fraction(1, 2))) < 0 do ( ret := ret + 1 ; f := f * 2) ; return cs, ret; operation reducer(l : OclAny, result : OclAny) pre: true post: true activity: execute ((result) : l); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from fractions import gcd def debug(*args): print(*args,file=sys.stderr) fin=sys.stdin T=int(fin.readline()) for case in range(1,T+1): p,q=map(int,fin.readline().split('/')) g=gcd(p,q) p//=g q//=g result=None if p>q : result="impossible" else : is_power=None for i in range(0,41): power=2**i if q==power : is_power=power if is_power is None : result="impossible" else : result="broken" for i in range(1,41): qq=2**i if p*qq>=q : result=str(i) break print("Case #%d: %s" %(case,result)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var fin : OclFile := OclFile["System.in"] ; var T : int := ("" + ((fin.readLine())))->toInteger() ; for case : Integer.subrange(1, T + 1-1) do ( var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := (fin.readLine().split('/'))->collect( _x | (OclType["int"])->apply(_x) ) ; var g : OclAny := gcd(p, q) ; p := p div g ; q := q div g ; var result : OclAny := null ; if (p->compareTo(q)) > 0 then ( result := "impossible" ) else ( var is_power : OclAny := null ; for i : Integer.subrange(0, 41-1) do ( var power : double := (2)->pow(i) ; if q = power then ( is_power := power ) else skip) ; if is_power <>= null then ( result := "impossible" ) else ( result := "broken" ; for i : Integer.subrange(1, 41-1) do ( var qq : double := (2)->pow(i) ; if (p * qq->compareTo(q)) >= 0 then ( result := ("" + ((i))) ; break ) else skip) ) ) ; execute (StringLib.format("Case #%d: %s",Sequence{case, result}))->display()); operation debug(args : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name args))) execute ((argument * (test (logical_test (comparison (expr (atom (name args))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(raw_input()) def gcd(a,b): r=a % b if r==0 : return b else : return gcd(b,r) def p2(x): if x==0 : return 1 else : return 2*p2(x-1) for t in range(T): inpArr=raw_input().strip().split('/') P=int(inpArr[0]) Q=int(inpArr[1]) g=gcd(P,Q) P/=g Q/=g if(P*p2(40))% Q==0 : gen=0 while PtoInteger() ; skip ; skip ; for t : Integer.subrange(0, T-1) do ( var inpArr : OclAny := raw_input()->trim().split('/') ; var P : int := ("" + ((inpArr->first())))->toInteger() ; var Q : int := ("" + ((inpArr[1+1])))->toInteger() ; var g : OclAny := gcd(P, Q) ; P := P / g ; Q := Q / g ; if (P * p2(40)) mod Q = 0 then ( var gen : int := 0 ; while (P->compareTo(Q)) < 0 do ( gen := gen + 1 ; P := P * 2) ; execute ("Case #" + ("" + ((t + 1))) + ": " + ("" + ((gen))))->display() ) else ( execute ("Case #" + ("" + ((t + 1))) + ": impossible")->display() )); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var r : int := a mod b ; if r = 0 then ( return b ) else ( return gcd(b, r) ); operation p2(x : OclAny) : OclAny pre: true post: true activity: if x = 0 then ( return 1 ) else ( return 2 * p2(x - 1) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): while b!=0 : a,b=b,a % b return a def IsPower(n): while n % 2==0 : n//=2 return n==1 def solve(num): P,Q=map(int,input().split("/")) d=gcd(P,Q) P//=d Q//=d if not IsPower(Q): ans="impossible" else : ans=1 while 2*PtoInteger() ; for i : Integer.subrange(0, T-1) do ( solve(i + 1)); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: while b /= 0 do ( Sequence{a,b} := Sequence{b,a mod b}) ; return a; operation IsPower(n : OclAny) : OclAny pre: true post: true activity: while n mod 2 = 0 do ( n := n div 2) ; return n = 1; operation solve(num : OclAny) pre: true post: true activity: var P : OclAny := null; var Q : OclAny := null; Sequence{P,Q} := (input().split("/"))->collect( _x | (OclType["int"])->apply(_x) ) ; var d : OclAny := gcd(P, Q) ; P := P div d ; Q := Q div d ; if not(IsPower(Q)) then ( var ans : String := "impossible" ) else ( ans := 1 ; while (2 * P->compareTo(Q)) < 0 do ( ans := ans + 1 ; P := P * 2) ) ; execute ("Case #" + ("" + ((num))) + ":")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from fractions import gcd with open("in.txt","r")as f : with open("out.txt","w")as fout : n=int(f.readline()) for i in range(n): line=f.readline() p,q=map(int,line.strip().split('/')) x=gcd(p,q) p/=x q/=x k,ss=0,1 res="" while k<41 and ss*p % q!=0 : k+=1 ss*=2 if ss*p>=q and res=="" : res=k if k==41 : res="impossible" print>>fout,"Case #%d: %s" %(i+1,res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; try (var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("in.txt")); try (var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("out.txt")); var n : int := ("" + ((f.readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var line : String := f.readLine() ; var p : OclAny := null; var q : OclAny := null; Sequence{p,q} := (line->trim().split('/'))->collect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := gcd(p, q) ; p := p / x ; q := q / x ; var k : OclAny := null; var ss : OclAny := null; Sequence{k,ss} := Sequence{0,1} ; var res : String := "" ; while k < 41 & ss * p mod q /= 0 do ( k := k + 1 ; ss := ss * 2 ; if (ss * p->compareTo(q)) >= 0 & res = "" then ( res := k ) else skip) ; if k = 41 then ( res := "impossible" ) else skip ; print /(2->pow(fout)) ; (expr (expr (atom "Case #%d: %s")) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (atom (name res))))))) )))))) catch (_e : OclException) do skip) catch (_e : OclException) do skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def surface_area_octahedron(side): return(2*(math.sqrt(3))*(side*side)) side=7 print("Surface area of octahedron=",surface_area_octahedron(side)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; side := 7 ; execute ("Surface area of octahedron=")->display(); operation surface_area_octahedron(side : OclAny) : OclAny pre: true post: true activity: return (2 * ((3)->sqrt()) * (side * side)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def eprint(*args,**kwargs): print(*args,file=sys.stderr,**kwargs) (n,m)=input().split() n=int(n) m=int(m) teleports={} eprint(n,m) for _ in range(n): (a,b)=input().split() bla=teleports.get(int(a)) if bla is None : teleports[int(a)]=int(b) else : teleports[int(a)]=max(bla,int(b)) i=0 limit=0 while limit=m : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var Sequence{n, m} : OclAny := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var m : int := ("" + ((m)))->toInteger() ; var teleports : OclAny := Set{} ; eprint(n, m) ; for _anon : Integer.subrange(0, n-1) do ( ; var Sequence{a, b} : OclAny := input().split() ; var bla : OclAny := teleports.get(("" + ((a)))->toInteger()) ; if bla <>= null then ( teleports[("" + ((a)))->toInteger()+1] := ("" + ((b)))->toInteger() ) else ( teleports[("" + ((a)))->toInteger()+1] := Set{bla, ("" + ((b)))->toInteger()}->max() )) ; var i : int := 0 ; var limit : int := 0 ; while (limit->compareTo(m)) < 0 & (i->compareTo(limit)) <= 0 do ( eprint(i, limit) ; var tel : OclAny := teleports.get(i) ; if not(tel <>= null) then ( limit := Set{limit, tel}->max() ) else skip ; i := i + 1) ; if (limit->compareTo(m)) >= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); operation eprint(args : OclAny : Sequence(OclAny), kwargs : OclAny : Map(String, OclAny)) pre: true post: true activity: (args * (named_parameter (name args)))(kwargs ** (named_parameter (name kwargs))) execute ((argument * (test (logical_test (comparison (expr (atom (name args))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- num_inp=lambda : int(input()) arr_inp=lambda : list(map(int,input().split())) sp_inp=lambda : map(int,input().split()) str_inp=lambda : input() I=lambda : list(map(int,input().split())) for _ in range(int(input())): n,x=I() w=sorted(I()) an=n ; s=sum(w) for i in range(n): if x<=s/an : break an-=1 ; s-=w[i] print(an) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var num_inp : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var arr_inp : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var sp_inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var str_inp : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var I : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := I->apply() ; var w : Sequence := I->apply()->sort() ; var an : OclAny := n; var s : OclAny := (w)->sum() ; for i : Integer.subrange(0, n-1) do ( if (x->compareTo(s / an)) <= 0 then ( break ) else skip ; an := an - 1; s := s - w[i+1]) ; execute (an)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=1000000007 def solve(test): size=len(test) total=0 for i in range(9): x=i y=i+1 newtest="" for j in range(size): if(ord(test[j])==x+48 or ord(test[j])==y+48): newtest+=test[j] if(len(newtest)>0): size1=len(newtest) prefix=[0 for i in range(size1)] for j in range(size1): if(ord(newtest[j])==y+48): prefix[j]+=1 for j in range(1,size1): prefix[j]+=prefix[j-1] count=0 firstcount=0 ss=0 prev=0 for j in range(size1): if(ord(newtest[j])==x+48): count+=1 firstcount+=1 else : ss+=count*count pairsum=(firstcount*firstcount-ss)//2 temp=pairsum pairsum-=prev prev=temp secondway=prefix[size1-1] if(j!=0): secondway-=prefix[j-1] answer=count*(count-1)*secondway*(secondway-1) answer//=4 answer+=(pairsum*secondway*(secondway-1))//2 total+=answer count=0 return total test="13134422" print(solve(test)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : int := 1000000007 ; skip ; test := "13134422" ; execute (solve(test))->display(); operation solve(test : OclAny) : OclAny pre: true post: true activity: var size : int := (test)->size() ; var total : int := 0 ; for i : Integer.subrange(0, 9-1) do ( var x : OclAny := i ; var y : OclAny := i + 1 ; var newtest : String := "" ; for j : Integer.subrange(0, size-1) do ( if ((test[j+1])->char2byte() = x + 48 or (test[j+1])->char2byte() = y + 48) then ( newtest := newtest + test[j+1] ) else skip) ; if ((newtest)->size() > 0) then ( var size1 : int := (newtest)->size() ; var prefix : Sequence := Integer.subrange(0, size1-1)->select(i | true)->collect(i | (0)) ; for j : Integer.subrange(0, size1-1) do ( if ((newtest[j+1])->char2byte() = y + 48) then ( prefix[j+1] := prefix[j+1] + 1 ) else skip) ; for j : Integer.subrange(1, size1-1) do ( prefix[j+1] := prefix[j+1] + prefix[j - 1+1]) ; var count : int := 0 ; var firstcount : int := 0 ; var ss : int := 0 ; var prev : int := 0 ; for j : Integer.subrange(0, size1-1) do ( if ((newtest[j+1])->char2byte() = x + 48) then ( count := count + 1 ; firstcount := firstcount + 1 ) else ( ss := ss + count * count ; var pairsum : int := (firstcount * firstcount - ss) div 2 ; var temp : int := pairsum ; pairsum := pairsum - prev ; prev := temp ; var secondway : OclAny := prefix[size1 - 1+1] ; if (j /= 0) then ( secondway := secondway - prefix[j - 1+1] ) else skip ; var answer : double := count * (count - 1) * secondway * (secondway - 1) ; answer := answer div 4 ; answer := answer + (pairsum * secondway * (secondway - 1)) div 2 ; total := total + answer ; count := 0 )) ) else skip) ; return total; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkEvenOdd(arr,n): for i in range(n): if(arr[i]% 2==0): print("Even",end=""); return ; print("Odd",end=""); if __name__=="__main__" : arr=[2,12,20,36,38]; n=len(arr); checkEvenOdd(arr,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{2}->union(Sequence{12}->union(Sequence{20}->union(Sequence{36}->union(Sequence{ 38 })))); ; n := (arr)->size(); ; checkEvenOdd(arr, n); ) else skip; operation checkEvenOdd(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( if (arr[i+1] mod 2 = 0) then ( execute ("Even")->display(); ; return; ) else skip) ; execute ("Odd")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printGroups(n,a): ct=[0 for i in range(7)] grps=n//3 i=0 for i in range(n): ct[a[i]]+=1 if(ct[1]!=grps or(ct[4]+ct[6])!=grps or(ct[2]+ct[3])!=grps or ct[4]>ct[2]): print(-1) return for i in range(ct[4]): print("1 2 4") for i in range(ct[2]-ct[4]): print("1 2 6") for i in range(ct[3]): print("1 3 6") n=6 a=[2,2,1,1,4,6] printGroups(n,a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 6 ; a := Sequence{2}->union(Sequence{2}->union(Sequence{1}->union(Sequence{1}->union(Sequence{4}->union(Sequence{ 6 }))))) ; printGroups(n, a); operation printGroups(n : OclAny, a : OclAny) pre: true post: true activity: var ct : Sequence := Integer.subrange(0, 7-1)->select(i | true)->collect(i | (0)) ; var grps : int := n div 3 ; var i : int := 0 ; for i : Integer.subrange(0, n-1) do ( ct[a[i+1]+1] := ct[a[i+1]+1] + 1) ; if (ct[1+1] /= grps or (ct[4+1] + ct[6+1]) /= grps or (ct[2+1] + ct[3+1]) /= grps or (ct[4+1]->compareTo(ct[2+1])) > 0) then ( execute (-1)->display() ; return ) else skip ; for i : Integer.subrange(0, ct[4+1]-1) do ( execute ("1 2 4")->display()) ; for i : Integer.subrange(0, ct[2+1] - ct[4+1]-1) do ( execute ("1 2 6")->display()) ; for i : Integer.subrange(0, ct[3+1]-1) do ( execute ("1 3 6")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def first(a,b,c): a %=b for i in range(1,b+1): a=a*10 if int(a/b)==c : return i a %=b return-1 a=1 b=4 c=5 print(first(a,b,c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 1 ; b := 4 ; c := 5 ; execute (first(a, b, c))->display(); operation first(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: a := a mod b ; for i : Integer.subrange(1, b + 1-1) do ( a := a * 10 ; if ("" + ((a / b)))->toInteger() = c then ( return i ) else skip ; a := a mod b) ; return -1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd as __gcd def getMinCost(arr,n,cost): mp=dict() mp[0]=0 for i in range(n): for it in list(mp): gcd=__gcd(arr[i],it) if(gcd in mp): mp[gcd]=min(mp[gcd],mp[it]+cost[i]) else : mp[gcd]=mp[it]+cost[i] if(mp[1]==0): return-1 else : return mp[1] arr=[5,10,12,1] cost=[2,1,2,6] n=len(arr) print(getMinCost(arr,n,cost)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{5}->union(Sequence{10}->union(Sequence{12}->union(Sequence{ 1 }))) ; cost := Sequence{2}->union(Sequence{1}->union(Sequence{2}->union(Sequence{ 6 }))) ; n := (arr)->size() ; execute (getMinCost(arr, n, cost))->display(); operation getMinCost(arr : OclAny, n : OclAny, cost : OclAny) : OclAny pre: true post: true activity: var mp : Map := (arguments ( )) ; mp->first() := 0 ; for i : Integer.subrange(0, n-1) do ( for it : (mp) do ( var gcd : OclAny := __gcd(arr[i+1], it) ; if ((mp)->includes(gcd)) then ( mp[gcd+1] := Set{mp[gcd+1], mp[it+1] + cost[i+1]}->min() ) else ( mp[gcd+1] := mp[it+1] + cost[i+1] ))) ; if (mp[1+1] = 0) then ( return -1 ) else ( return mp[1+1] ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=4 def isDiagonalMatrix(mat): for i in range(0,N): for j in range(0,N): if((i!=j)and(mat[i][j]!=0)): return False return True mat=[[4,0,0,0],[0,7,0,0],[0,0,5,0],[0,0,0,1]] if(isDiagonalMatrix(mat)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := 4 ; skip ; mat := Sequence{Sequence{4}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 0 })))}->union(Sequence{Sequence{0}->union(Sequence{7}->union(Sequence{0}->union(Sequence{ 0 })))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{5}->union(Sequence{ 0 })))}->union(Sequence{ Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{ 1 }))) }))) ; if (isDiagonalMatrix(mat)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isDiagonalMatrix(mat : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( if ((i /= j) & (mat[i+1][j+1] /= 0)) then ( return false ) else skip)) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def decToBinary(n): for i in range(31,-1,-1): k=n>>i ; if(k & 1): print("1",end=""); else : print("0",end=""); n=32 ; decToBinary(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 32; ; decToBinary(n);; operation decToBinary(n : OclAny) pre: true post: true activity: for i : Integer.subrange(-1 + 1, 31)->reverse() do ( var k : int := n /(2->pow(i)); ; if (MathLib.bitwiseAnd(k, 1)) then ( execute ("1")->display(); ) else ( execute ("0")->display(); )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def LongestSubarray(a,n,k): pre=[0 for i in range(n)] for i in range(n): if(a[i]>k): pre[i]=1 else : pre[i]=-1 for i in range(1,n): pre[i]=pre[i-1]+pre[i] Len=0 lo=1 hi=n while(lo<=hi): mid=(lo+hi)//2 ok=False for i in range(mid-1,n): x=pre[i] if(i-mid>=0): x-=pre[i-mid] if(x>0): ok=True break if(ok==True): Len=mid lo=mid+1 else : hi=mid-1 return Len a=[2,3,4,5,3,7] k=3 n=len(a) print(LongestSubarray(a,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{3}->union(Sequence{ 7 }))))) ; k := 3 ; n := (a)->size() ; execute (LongestSubarray(a, n, k))->display(); operation LongestSubarray(a : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var pre : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( if ((a[i+1]->compareTo(k)) > 0) then ( pre[i+1] := 1 ) else ( pre[i+1] := -1 )) ; for i : Integer.subrange(1, n-1) do ( pre[i+1] := pre[i - 1+1] + pre[i+1]) ; var Len : int := 0 ; var lo : int := 1 ; var hi : OclAny := n ; while ((lo->compareTo(hi)) <= 0) do ( var mid : int := (lo + hi) div 2 ; var ok : boolean := false ; for i : Integer.subrange(mid - 1, n-1) do ( var x : OclAny := pre[i+1] ; if (i - mid >= 0) then ( x := x - pre[i - mid+1] ) else skip ; if (x > 0) then ( ok := true ; break ) else skip) ; if (ok = true) then ( Len := mid ; lo := mid + 1 ) else ( hi := mid - 1 )) ; return Len; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def distance(x1,y1,x2,y2): k=(((x1-x2)**2)+((y1-y2)**2))**0.5 return k x,y=map(int,input().split()) r=[] for _ in range(int(input(''))): l=list(map(int,input().split())) x1,y1,v=l[0],l[1],l[2] t=distance(x,y,x1,y1)/v r.append(t) print(min(r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var r : Sequence := Sequence{} ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine(''))))->toInteger()-1) do ( var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var v : OclAny := null; Sequence{x1,y1,v} := Sequence{l->first(),l[1+1],l[2+1]} ; var t : double := distance(x, y, x1, y1) / v ; execute ((t) : r)) ; execute ((r)->min())->display(); operation distance(x1 : OclAny, y1 : OclAny, x2 : OclAny, y2 : OclAny) : OclAny pre: true post: true activity: var k : double := (((((x1 - x2))->pow(2)) + (((y1 - y2))->pow(2))))->pow(0.5) ; return k; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) n,d=int(input()),[] for i in range(n): x,y,v=map(int,input().split()) z=((a-x)**2+(b-y)**2)**0.5/v d.append(z) d.sort() print(d[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),Sequence{}} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; var v : OclAny := null; Sequence{x,y,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var z : double := ((((a - x))->pow(2) + ((b - y))->pow(2)))->pow(0.5) / v ; execute ((z) : d)) ; d := d->sort() ; execute (d->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,x=map(int,input().split()) a=list(map(int,input().split())) a.sort(reverse=True) total=0 count=0 for i in range(0,n): total+=a[i] if total/(i+1)>=x : count=i+1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var total : int := 0 ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( total := total + a[i+1] ; if (total / (i + 1)->compareTo(x)) >= 0 then ( count := i + 1 ) else skip) ; execute (count)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check(n): sum=0 while n!=0 : sum+=n % 10 n=n//10 if sum % 7==0 : return 1 else : return 0 if __name__=="__main__" : n=25 print(("YES")if check(n)==1 else print("NO")) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 25 ; execute (if check(n) = 1 then ("YES") else ("NO")->display() endif)->display() ) else skip; operation check(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; while n /= 0 do ( sum := sum + n mod 10 ; n := n div 10) ; if sum mod 7 = 0 then ( return 1 ) else ( return 0 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a,b=[int(i)for i in input().split()] n=int(input()) minimum=float("inf") for i in range(n): x,y,v=[int(i)for i in input().split()] ab=math.sqrt((x-a)**2+(b-y)**2) c=ab/v if cselect(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var minimum : double := ("" + (("inf")))->toReal() ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; var v : OclAny := null; Sequence{x,y,v} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ab : double := (((x - a))->pow(2) + ((b - y))->pow(2))->sqrt() ; var c : double := ab / v ; if (c->compareTo(minimum)) < 0 then ( minimum := c ) else skip) ; execute (minimum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=lambda : map(int,input().split()) a,b=I() m=9**9 for _ in range(next(I())): x,y,v=I(); m=min(m,(((x-a)**2+(y-b)**2)**.5)/v) print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := I->apply() ; var m : double := (9)->pow(9) ; for _anon : Integer.subrange(0, (I->apply()).next()-1) do ( var x : OclAny := null; var y : OclAny := null; var v : OclAny := null; Sequence{x,y,v} := I->apply(); m := Set{m, (((((x - a))->pow(2) + ((y - b))->pow(2)))->pow(.5)) / v}->min()) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt a,b=map(int,input().split()) n=int(input()) m=10**10 for i in range(n): c,d,v=map(int,input().split()) t=sqrt(pow((a-c),2)+pow((b-d),2))/v m=min(m,t) print(m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : double := (10)->pow(10) ; for i : Integer.subrange(0, n-1) do ( var c : OclAny := null; var d : OclAny := null; var v : OclAny := null; Sequence{c,d,v} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : double := sqrt(((a - c))->pow(2) + ((b - d))->pow(2)) / v ; m := Set{m, t}->min()) ; execute (m)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n_pings=int(input()) packets=[[0,0],[0,0]] for _ in range(n_pings): t,x,y=map(int,input().split()) packets[t-1][0]+=x packets[t-1][1]+=x+y if packets[0][1]==0 or packets[0][0]/packets[0][1]>=0.5 : print("LIVE") else : print("DEAD") if packets[1][1]==0 or packets[1][0]/packets[1][1]>=0.5 : print("LIVE") else : print("DEAD") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n_pings : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var packets : Sequence := Sequence{Sequence{0}->union(Sequence{ 0 })}->union(Sequence{ Sequence{0}->union(Sequence{ 0 }) }) ; for _anon : Integer.subrange(0, n_pings-1) do ( var t : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{t,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; packets[t - 1+1]->first() := packets[t - 1+1]->first() + x ; packets[t - 1+1][1+1] := packets[t - 1+1][1+1] + x + y) ; if packets->first()[1+1] = 0 or packets->first()->first() / packets->first()[1+1] >= 0.5 then ( execute ("LIVE")->display() ) else ( execute ("DEAD")->display() ) ; if packets[1+1][1+1] = 0 or packets[1+1]->first() / packets[1+1][1+1] >= 0.5 then ( execute ("LIVE")->display() ) else ( execute ("DEAD")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) server1x=0 server2x=0 server1y=0 server2y=0 for _ in range(n): t,x,y=list(map(int,input().split())) if t==1 : server1x+=x server1y+=y else : server2x+=x server2y+=y if server1x>=server1y : print("LIVE") else : print("DEAD") if server2x>=server2y : print("LIVE") else : print("DEAD") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var server1x : int := 0 ; var server2x : int := 0 ; var server1y : int := 0 ; var server2y : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var t : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{t,x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if t = 1 then ( server1x := server1x + x ; server1y := server1y + y ) else ( server2x := server2x + x ; server2y := server2y + y )) ; if (server1x->compareTo(server1y)) >= 0 then ( execute ("LIVE")->display() ) else ( execute ("DEAD")->display() ) ; if (server2x->compareTo(server2y)) >= 0 then ( execute ("LIVE")->display() ) else ( execute ("DEAD")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ax=0 ; bx=0 ay=0 ; by=0 for i in range(n): t,x,y=map(int,input().split()) if t==1 : ax+=x ay+=y else : bx+=x by+=y if ax>=(ax+ay)//2 : print('LIVE') else : print('DEAD') if bx>=(bx+by)//2 : print('LIVE') else : print('DEAD') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ax : int := 0; var bx : int := 0 ; var ay : int := 0; var by : int := 0 ; for i : Integer.subrange(0, n-1) do ( var t : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{t,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if t = 1 then ( ax := ax + x ; ay := ay + y ) else ( bx := bx + x ; by := by + y )) ; if (ax->compareTo((ax + ay) div 2)) >= 0 then ( execute ('LIVE')->display() ) else ( execute ('DEAD')->display() ) ; if (bx->compareTo((bx + by) div 2)) >= 0 then ( execute ('LIVE')->display() ) else ( execute ('DEAD')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) total_a=0 total_b=0 recieved_a=0 recieved_b=0 for poop in range(n): [server,x,y]=map(int,input().split()) if server==1 : total_a+=10 recieved_a+=x else : total_b+=10 recieved_b+=x if recieved_a>=(total_a/2): print("LIVE") else : print("DEAD") if recieved_b>=(total_b/2): print("LIVE") else : print("DEAD") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var total_a : int := 0 ; var total_b : int := 0 ; var recieved_a : int := 0 ; var recieved_b : int := 0 ; for poop : Integer.subrange(0, n-1) do ( ; Sequence{server}->union(Sequence{x}->union(Sequence{ y })) := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if server = 1 then ( total_a := total_a + 10 ; recieved_a := recieved_a + x ) else ( total_b := total_b + 10 ; recieved_b := recieved_b + x )) ; if (recieved_a->compareTo((total_a / 2))) >= 0 then ( execute ("LIVE")->display() ) else ( execute ("DEAD")->display() ) ; if (recieved_b->compareTo((total_b / 2))) >= 0 then ( execute ("LIVE")->display() ) else ( execute ("DEAD")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=int(input()) cnt1=cnt2=0 s1=s2=x1=x2=0 for l in range(m): t,x,y=map(int,input().split()) if t==1 : cnt1+=x+y x1+=x else : cnt2+=x+y x2+=x if cnt1<=2*x1 : s1=1 if cnt2<=2*x2 : s2=1 if s1==1 : print("LIVE") else : print("DEAD") if s2==1 : print("LIVE") else : print("DEAD") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cnt1 : OclAny := 0; var cnt2 : int := 0 ; s1 := s1(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s2)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x1)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x2)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for l : Integer.subrange(0, m-1) do ( var t : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{t,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if t = 1 then ( cnt1 := cnt1 + x + y ; x1 := x1 + x ) else ( cnt2 := cnt2 + x + y ; x2 := x2 + x )) ; if (cnt1->compareTo(2 * x1)) <= 0 then ( var s1 : int := 1 ) else skip ; if (cnt2->compareTo(2 * x2)) <= 0 then ( var s2 : int := 1 ) else skip ; if s1 = 1 then ( execute ("LIVE")->display() ) else ( execute ("DEAD")->display() ) ; if s2 = 1 then ( execute ("LIVE")->display() ) else ( execute ("DEAD")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(m,n): r=m % n return gcd(n,r)if r else n def f(v): d=v.find(".") if d==-1 : return int(v),1 a=int(v[: d]+v[d+1 :]) n=10**(len(v)-d-1) if a==0 : return 0,1 g=gcd(n,a) return int(a/g),int(n/g) s=input() d=s.find(".") l=s.find("(") r=s.find(")") if l==-1 : res=f(s) else : assert l>=2 and r==len(s)-1 aa,na=f(s[: l]) ab,nb=f("0."+"0"*(l-d-1)+s[l+1 : r]) t=r-l-1 a=(10**t-1)*aa*nb+10**t*ab*na n=(10**t-1)*na*nb g=gcd(a,n) res=int(a/g),int(n/g) print("%d/%d" % res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var s : String := (OclFile["System.in"]).readLine() ; d := s->indexOf(".") - 1 ; var l : int := s->indexOf("(") - 1 ; r := s->indexOf(")") - 1 ; if l = -1 then ( var res : String := f(s) ) else ( assert l >= 2 & r = (s)->size() - 1 do "assertion failed" ; var aa : OclAny := null; var na : OclAny := null; Sequence{aa,na} := f(s.subrange(1,l)) ; var ab : OclAny := null; var nb : OclAny := null; Sequence{ab,nb} := f("0." + StringLib.nCopies("0", (l - d - 1)) + s.subrange(l + 1+1, r)) ; var t : double := r - l - 1 ; a := ((10)->pow(t) - 1) * aa * nb + (10)->pow(t) * ab * na ; n := ((10)->pow(t) - 1) * na * nb ; g := gcd(a, n) ; res := ("" + ((a / g)))->toInteger(),("" + ((n / g)))->toInteger() ) ; execute (StringLib.format("%d/%d",res))->display(); operation gcd(m : OclAny, n : OclAny) : OclAny pre: true post: true activity: var r : int := m mod n ; return if r then gcd(n, r) else n endif; operation f(v : OclAny) : OclAny pre: true post: true activity: var d : int := v->indexOf(".") - 1 ; if d = -1 then ( return ("" + ((v)))->toInteger(), 1 ) else skip ; var a : int := ("" + ((v.subrange(1,d) + v.subrange(d + 1+1))))->toInteger() ; n := (10)->pow(((v)->size() - d - 1)) ; if a = 0 then ( return 0, 1 ) else skip ; var g : OclAny := gcd(n, a) ; return ("" + ((a / g)))->toInteger(), ("" + ((n / g)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=sorted([tuple(map(int,input().split()))for _ in[0,0]]) print(a[1][0]-a[0][0]+(1 if a[1][1]>a[0][1]or(a[1][1]==a[0][1]and a[1][2]>a[0][2])else 0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := Sequence{0}->union(Sequence{ 0 })->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))->sort() ; execute (a[1+1]->first() - a->first()->first() + (if (a[1+1][1+1]->compareTo(a->first()[1+1])) > 0 or (a[1+1][1+1] = a->first()[1+1] & (a[1+1][2+1]->compareTo(a->first()[2+1])) > 0) then 1 else 0 endif))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd s=input() x,y=s.split(".") if "(" in s : da=y.index("(") db=y.index(")")-1 ya,b=y.split("(") lb=len(b)-1 a=int(x+ya) b=int(b[:-1]) deco=a*(10**db-10**(db-lb))+b*10**da nume=10**da*(10**db-10**(db-lb)) div=gcd(deco,nume) print(deco//div,nume//div,sep="/") else : da=len(y) a=int(x+y) deco=a nume=10**da div=gcd(deco,nume) print(deco//div,nume//div,sep="/") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : String := (OclFile["System.in"]).readLine() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := s.split(".") ; if (s)->characters()->includes("(") then ( var da : int := y->indexOf("(") - 1 ; var db : double := y->indexOf(")") - 1 - 1 ; var ya : OclAny := null; var b : OclAny := null; Sequence{ya,b} := y.split("(") ; var lb : double := (b)->size() - 1 ; var a : int := ("" + ((x + ya)))->toInteger() ; var b : int := ("" + ((b->front())))->toInteger() ; var deco : double := a * ((10)->pow(db) - (10)->pow((db - lb))) + b * (10)->pow(da) ; var nume : double := (10)->pow(da) * ((10)->pow(db) - (10)->pow((db - lb))) ; var div : OclAny := gcd(deco, nume) ; execute (deco div div)->display() ) else ( da := (y)->size() ; a := ("" + ((x + y)))->toInteger() ; deco := a ; nume := (10)->pow(da) ; div := gcd(deco, nume) ; execute (deco div div)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def constructPalin(string,l): string=list(string) i=-1 j=l while isize() ; execute (constructPalin(string, l))->display() ) else skip; operation constructPalin(string : OclAny, l : OclAny) : OclAny pre: true post: true activity: string := (string)->characters() ; var i : int := -1 ; var j : OclAny := l ; while (i->compareTo(j)) < 0 do ( i := i + 1 ; j := j - 1 ; if (string[i+1] = string[j+1] & string[i+1] /= '*') then ( continue ) else (if (string[i+1] = string[j+1] & string[i+1] = '*') then ( string[i+1] := 'a' ; string[j+1] := 'a' ; continue ) else (if string[i+1] = '*' then ( string[i+1] := string[j+1] ; continue ) else (if string[j+1] = '*' then ( string[j+1] := string[i+1] ; continue ) else skip ) ) ) ; execute ("Not Possible")->display() ; return "") ; return StringLib.sumStringsWithSeparator((string), ''); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(x,y): return gcd(y,x % y)if y else x def printV(x,y): g=gcd(x,y) print(str(x//g)+"/"+str(y//g)) S=input() all="" sub="" p=-1 for i in range(len(S)): if S[i]=='.' : o=i elif S[i]=='(' : p=i sub=all elif S[i]!=')' : all+=S[i] d=len(S)-o-1 l=p-o-1 if p==-1 : printV(int(all),10**d) else : d-=2 printV(int(all)-int(sub),10**d-10**l) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var S : String := (OclFile["System.in"]).readLine() ; var all : String := "" ; var sub : String := "" ; var p : int := -1 ; for i : Integer.subrange(0, (S)->size()-1) do ( if S[i+1] = '.' then ( var o : OclAny := i ) else (if S[i+1] = '(' then ( p := i ; sub := all ) else (if S[i+1] /= ')' then ( all := all + S[i+1] ) else skip ) ) ) ; var d : double := (S)->size() - o - 1 ; var l : double := p - o - 1 ; if p = -1 then ( printV(("" + ((all)))->toInteger(), (10)->pow(d)) ) else ( d := d - 2 ; printV(("" + ((all)))->toInteger() - ("" + ((sub)))->toInteger(), (10)->pow(d) - (10)->pow(l)) ); operation gcd(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return if y then gcd(y, x mod y) else x endif; operation printV(x : OclAny, y : OclAny) pre: true post: true activity: var g : OclAny := gcd(x, y) ; execute (("" + ((x div g))) + "/" + ("" + ((y div g))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import gcd def solve(p,q): GCD=gcd(p,q) p=p//GCD q=q//GCD print(p,q,sep="/") s=input() x,y=s.split('.') if(y[-1]!=')'): p=int(x)*pow(10,len(y))+int(y) q=pow(10,len(y)) solve(p,q) else : y,z=y.split('(')[0],y.split('(')[1][:-1] a=int(x+y+z) b=int(x+y) solve(a-b,(pow(10,len(z))-1)*pow(10,len(y))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var s : String := (OclFile["System.in"]).readLine() ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := s.split('.') ; if (y->last() /= ')') then ( p := ("" + ((x)))->toInteger() * (10)->pow((y)->size()) + ("" + ((y)))->toInteger() ; q := (10)->pow((y)->size()) ; solve(p, q) ) else ( var y : OclAny := null; var z : OclAny := null; Sequence{y,z} := Sequence{y.split('(')->first(),y.split('(')[1+1]->front()} ; var a : int := ("" + ((x + y + z)))->toInteger() ; var b : int := ("" + ((x + y)))->toInteger() ; solve(a - b, ((10)->pow((z)->size()) - 1) * (10)->pow((y)->size())) ); operation solve(p : OclAny, q : OclAny) pre: true post: true activity: var GCD : OclAny := gcd(p, q) ; p := p div GCD ; q := q div GCD ; execute (p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n,a=[int(i)for i in input().split()] if n==3 : print(1,2,3) return s=(n-2)*180 a1=s/n f=(a1-a)/(180-a1)*2 c=2 b=n-f if b-int(b)>0.50 : b=max(min(int(b)+1,n),3) else : b=max(min(int(b),n),3) if c-int(c)>0.50 : c=max(int(c)+1,2) else : c=max(int(c),2) print(c,1,b) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if n = 3 then ( execute (1)->display() ; return ) else skip ; var s : double := (n - 2) * 180 ; var a1 : double := s / n ; var f : double := (a1 - a) / (180 - a1) * 2 ; var c : int := 2 ; var b : double := n - f ; if b - ("" + ((b)))->toInteger() > 0.50 then ( b := Set{Set{("" + ((b)))->toInteger() + 1, n}->min(), 3}->max() ) else ( b := Set{Set{("" + ((b)))->toInteger(), n}->min(), 3}->max() ) ; if c - ("" + ((c)))->toInteger() > 0.50 then ( c := Set{("" + ((c)))->toInteger() + 1, 2}->max() ) else ( c := Set{("" + ((c)))->toInteger(), 2}->max() ) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) x=180/n y=int(m/x) z=y*x w=(y+1)*x if m-z<=w-m : v=y else : v=y+1 if v==0 : v=1 if 2+v>n : print(2,1,n) else : print(2,1,2+v) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : double := 180 / n ; var y : int := ("" + ((m / x)))->toInteger() ; var z : double := y * x ; var w : double := (y + 1) * x ; if (m - z->compareTo(w - m)) <= 0 then ( var v : int := y ) else ( v := y + 1 ) ; if v = 0 then ( v := 1 ) else skip ; if (2 + v->compareTo(n)) > 0 then ( execute (2)->display() ) else ( execute (2)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): return bestAngle_sVertices(*map(int,input().split())) def bestAngle_sVertices(nVertices,angle): optimalAngle=180/nVertices if angle/(nVertices-2)>optimalAngle : return f'2 1{nVertices}' elif angledisplay() ) else skip; operation main() : OclAny pre: true post: true activity: return bestAngle_sVertices((argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))); operation bestAngle_sVertices(nVertices : OclAny, angle : OclAny) : OclAny pre: true post: true activity: var optimalAngle : double := 180 / nVertices ; if (angle / (nVertices - 2)->compareTo(optimalAngle)) > 0 then ( return StringLib.formattedString('2 1{nVertices}') ) else (if (angle->compareTo(optimalAngle)) < 0 then ( return '2 1 3' ) else skip) ; return StringLib.formattedString('2 1{2+round(angle/optimalAngle)}'); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a=map(int,input().split()) min_abs=360 vertex=0 for i in range(3,n+1): angle=180*(i-2)/n if abs(angle-a)collect( _x | (OclType["int"])->apply(_x) ) ; var min_abs : int := 360 ; var vertex : int := 0 ; for i : Integer.subrange(3, n + 1-1) do ( var angle : double := 180 * (i - 2) / n ; if ((angle - a)->abs()->compareTo(min_abs)) < 0 then ( min_abs := (angle - a)->abs() ; vertex := i ) else skip) ; execute (vertex)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- arr=list(map(int,input().rstrip().split())) n=arr[0] a=arr[1] fa=(180-((180*(n-2))/n))/2 na=fa ind=[] for i in range(n-2): ind.append(abs(a-na)) na+=fa flg=-1 ix=-1 gg=min(ind) ff=ind.index(gg) print('1 2',end=" ") print(str(n-ff)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var arr : Sequence := ((input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := arr->first() ; var a : OclAny := arr[1+1] ; var fa : double := (180 - ((180 * (n - 2)) / n)) / 2 ; var na : OclAny := fa ; var ind : Sequence := Sequence{} ; for i : Integer.subrange(0, n - 2-1) do ( execute (((a - na)->abs()) : ind) ; na := na + fa) ; var flg : int := -1 ; var ix : int := -1 ; var gg : OclAny := (ind)->min() ; var ff : int := ind->indexOf(gg) - 1 ; execute ('1 2')->display() ; execute (("" + ((n - ff))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() s=list(map(int,input().split())) m=max(s) print(max(0,2*m+1-sum(s))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : OclAny := (s)->max() ; execute (Set{0, 2 * m + 1 - (s)->sum()}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print(*[''.join('01235789'[int(i)]for i in oct(int(x))[2 :])for x in open(0).read().split()[:-1]],sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom '') (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '01235789') (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))))) ])))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name oct)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))))) ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) :)) ])))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name open)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))) (trailer . (name read) (arguments ( ))) (trailer . (name split) (arguments ( ))) (trailer (arguments [ (subscriptlist (subscript : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ]))))))) ])))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- y1,m1,d1=map(int,input().split()) y2,m2,d2=map(int,input().split()) if y1>y2 or(y1==y2 and(m1>m2 or(m1==m2 and d1>d2))): y1,y2=y2,y1 m1,m2=m2,m1 d1,d2=d2,d1 if m1collect( _x | (OclType["int"])->apply(_x) ) ; var y2 : OclAny := null; var m2 : OclAny := null; var d2 : OclAny := null; Sequence{y2,m2,d2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (y1->compareTo(y2)) > 0 or (y1 = y2 & ((m1->compareTo(m2)) > 0 or (m1 = m2 & (d1->compareTo(d2)) > 0))) then ( var y1 : OclAny := null; var y2 : OclAny := null; Sequence{y1,y2} := Sequence{y2,y1} ; var m1 : OclAny := null; var m2 : OclAny := null; Sequence{m1,m2} := Sequence{m2,m1} ; var d1 : OclAny := null; var d2 : OclAny := null; Sequence{d1,d2} := Sequence{d2,d1} ) else skip ; if (m1->compareTo(m2)) < 0 or (m1 = m2 & (d1->compareTo(d2)) < 0) then ( execute (y2 - y1 + 1)->display() ) else ( execute (y2 - y1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() v=list(map(int,input().split())) print(-sum(v)+2*max(v)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var v : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (-(v)->sum() + 2 * (v)->max() + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=list(map(int,input().split())) x.sort() aux=sum(x[0 : n-1]) print(x[n-1]-aux+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; x := x->sort() ; var aux : OclAny := (x.subrange(0+1, n - 1))->sum() ; execute (x[n - 1+1] - aux + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNumbers(n): odd=pow(10,n)-1 even=odd-1 print("Even=",even) print("Odd=",odd) n=4 findNumbers(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; findNumbers(n); operation findNumbers(n : OclAny) pre: true post: true activity: var odd : double := (10)->pow(n) - 1 ; var even : double := odd - 1 ; execute ("Even=")->display() ; execute ("Odd=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) rods=input() rods=rods.split(' ') a=0 b=0 for i in range(n): if int(rods[i])>a : b+=a a=int(rods[i]) else : b+=int(rods[i]) print(a-b+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var rods : String := (OclFile["System.in"]).readLine() ; rods := rods.split(' ') ; var a : int := 0 ; var b : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (("" + ((rods[i+1])))->toInteger()->compareTo(a)) > 0 then ( b := b + a ; a := ("" + ((rods[i+1])))->toInteger() ) else ( b := b + ("" + ((rods[i+1])))->toInteger() )) ; execute (a - b + 1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) w=sorted(map(int,input().split())) a=sum(w[:-1]) if a<=w[-1]: print(w[-1]-a+1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var w : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var a : OclAny := (w->front())->sum() ; if (a->compareTo(w->last())) <= 0 then ( execute (w->last() - a + 1)->display() ) else ( execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSubStr(S,X): cnt=0 N=len(S) for i in range(0,N): if(S[i]!='0'): j=1 while((j+i)<=N): num=int(S[i : i+j]) if(num>X): cnt=cnt+1 j=j+1 return cnt ; S="2222" ; X=97 ; print(countSubStr(S,X)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; S := "2222"; ; X := 97; ; execute (countSubStr(S, X))->display(); operation countSubStr(S : OclAny, X : OclAny) pre: true post: true activity: var cnt : int := 0 ; var N : int := (S)->size() ; for i : Integer.subrange(0, N-1) do ( if (S[i+1] /= '0') then ( var j : int := 1 ; while (((j + i)->compareTo(N)) <= 0) do ( var num : int := ("" + ((S.subrange(i+1, i + j))))->toInteger() ; if ((num->compareTo(X)) > 0) then ( cnt := cnt + 1 ) else skip ; j := j + 1) ) else skip) ; return cnt;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def stringReduction(str): n=len(str) count=[0]*3 for i in range(n): count[ord(str[i])-ord('a')]+=1 if(count[0]==n or count[1]==n or count[2]==n): return n if((count[0]% 2)==(count[1]% 2)and(count[1]% 2)==(count[2]% 2)): return 2 return 1 if __name__=="__main__" : str="abcbbaacb" print(stringReduction(str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( OclType["String"] := "abcbbaacb" ; execute (stringReduction(OclType["String"]))->display() ) else skip; operation stringReduction(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var n : int := (OclType["String"])->size() ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 3) ; for i : Integer.subrange(0, n-1) do ( count[(("" + ([i+1])))->char2byte() - ('a')->char2byte()+1] := count[(("" + ([i+1])))->char2byte() - ('a')->char2byte()+1] + 1) ; if (count->first() = n or count[1+1] = n or count[2+1] = n) then ( return n ) else skip ; if ((count->first() mod 2) = (count[1+1] mod 2) & (count[1+1] mod 2) = (count[2+1] mod 2)) then ( return 2 ) else skip ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dydx(x,y): return(x+y-2); def rungeKutta(x0,y0,x,h): n=round((x-x0)/h); y=y0 ; for i in range(1,n+1): k1=h*dydx(x0,y); k2=h*dydx(x0+0.5*h,y+0.5*k1); y=y+(1.0/6.0)*(k1+2*k2); x0=x0+h ; return y ; if __name__=="__main__" : x0=0 ; y=1 ; x=2 ; h=0.2 ; print("y(x)=",rungeKutta(x0,y,x,h)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( x0 := 0; y := 1; ; x := 2; h := 0.2; ; execute ("y(x)=")->display(); ) else skip; operation dydx(x : OclAny, y : OclAny) pre: true post: true activity: return (x + y - 2);; operation rungeKutta(x0 : OclAny, y0 : OclAny, x : OclAny, h : OclAny) pre: true post: true activity: var n : double := ((x - x0) / h)->round(); ; y := y0; ; for i : Integer.subrange(1, n + 1-1) do ( var k1 : double := h * dydx(x0, y); ; var k2 : double := h * dydx(x0 + 0.5 * h, y + 0.5 * k1); ; y := y + (1.0 / 6.0) * (k1 + 2 * k2); ; x0 := x0 + h;) ; return y;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import copy import random import bisect import fractions import math import sys mod=10**9+7 sys.setrecursionlimit(mod) def LI(): return list(map(int,sys.stdin.readline().split())) N=int(input()) A=[0 for i in range(N)] for i in range(N): A[i]=int(input()) A_c=copy.deepcopy(A) A_c.sort() for i in range(N): if A_c[-1]==A[i]: print(A_c[-2]) else : print(A_c[-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; sys.setrecursionlimit(mod) ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, N-1) do ( A[i+1] := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var A_c : OclAny := copy.deepcopy(A) ; A_c := A_c->sort() ; for i : Integer.subrange(0, N-1) do ( if A_c->last() = A[i+1] then ( execute (A_c->front()->last())->display() ) else ( execute (A_c->last())->display() )); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(int(input())for _ in range(n)) b=sorted(a,reverse=True) for i in range(n): if b[0]!=a[i]: print(b[0]) else : print(b[1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))) ; var b : Sequence := a->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; for i : Integer.subrange(0, n-1) do ( if b->first() /= a[i+1] then ( execute (b->first())->display() ) else ( execute (b[1+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) d,e,f=map(int,input().split()) if b==e and c==f : print(abs(a-d)) exit() if a>d : num=100*b+c nu=100*e+f elif anu : print(abs(a-d)+1) else : print(abs(a-d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : OclAny := null; var e : OclAny := null; var f : OclAny := null; Sequence{d,e,f} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if b = e & c = f then ( execute ((a - d)->abs())->display() ; exit() ) else skip ; if (a->compareTo(d)) > 0 then ( var num : double := 100 * b + c ; var nu : double := 100 * e + f ) else (if (a->compareTo(d)) < 0 then ( num := 100 * e + f ; nu := 100 * b + c ) else ( execute (1)->display() ; exit() ) ) ; if (num->compareTo(nu)) > 0 then ( execute ((a - d)->abs() + 1)->display() ) else ( execute ((a - d)->abs())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) lst=[] for i in range(0,N): lst.append([i,int(input())]) lst.sort(lambda v : v[1],reverse=True) index=lst[0][0] for i in range(0,N): if i==index : print(lst[1][1]) else : print(lst[0][1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute ((Sequence{i}->union(Sequence{ ("" + (((OclFile["System.in"]).readLine())))->toInteger() })) : lst)) ; lst := lst->sort() ; var index : OclAny := lst->first()->first() ; for i : Integer.subrange(0, N-1) do ( if i = index then ( execute (lst[1+1][1+1])->display() ) else ( execute (lst->first()[1+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A_max=0 A_max_s=0 flag=0 A=[] for i in range(N): a=int(input()) A.append(a) if a>A_max : A_max_s=A_max A_max=a ind_max=i flag=0 elif A_max_s=1 : for i in range(N): print(A_max) elif flag==0 : for i in range(N): if i!=ind_max : print(A_max) else : print(A_max_s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A_max : int := 0 ; var A_max_s : int := 0 ; var flag : int := 0 ; var A : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((a) : A) ; if (a->compareTo(A_max)) > 0 then ( A_max_s := A_max ; A_max := a ; var ind_max : OclAny := i ; flag := 0 ) else (if (A_max_s->compareTo(a)) < 0 & (a < A_max) then ( A_max_s := a ) else (if a = A_max then ( flag := flag + 1 ) else skip ) ) ) ; if flag >= 1 then ( for i : Integer.subrange(0, N-1) do ( execute (A_max)->display()) ) else (if flag = 0 then ( for i : Integer.subrange(0, N-1) do ( if i /= ind_max then ( execute (A_max)->display() ) else ( execute (A_max_s)->display() )) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) values=[0]*N value_count_map={} for i in range(N): in_value=int(input()) values[i]=in_value value_count=0 if in_value in value_count_map : value_count=value_count_map[in_value] value_count_map[in_value]=value_count+1 sorted_values=sorted(value_count_map.keys(),reverse=True) max_value=sorted_values[0] max_value_count=value_count_map[max_value] next_max_value=max_value if len(sorted_values)>1 : next_max_value=sorted_values[1] for row in range(N): if values[row]==max_value and max_value_count==1 : print(next_max_value) else : print(max_value) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var values : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; var value_count_map : OclAny := Set{} ; for i : Integer.subrange(0, N-1) do ( var in_value : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; values[i+1] := in_value ; var value_count : int := 0 ; if (value_count_map)->includes(in_value) then ( value_count := value_count_map[in_value+1] ) else skip ; value_count_map[in_value+1] := value_count + 1) ; var sorted_values : Sequence := value_count_map.keys()->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var max_value : OclAny := sorted_values->first() ; var max_value_count : OclAny := value_count_map[max_value+1] ; var next_max_value : OclAny := max_value ; if (sorted_values)->size() > 1 then ( next_max_value := sorted_values[1+1] ) else skip ; for row : Integer.subrange(0, N-1) do ( if values[row+1] = max_value & max_value_count = 1 then ( execute (next_max_value)->display() ) else ( execute (max_value)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def noOfDeletions(string,k): ans=0 ; cnt=0 ; pos=0 ; while(posdisplay(); ; var str2 : String := "kprkkoinkopt"; ; var k2 : String := 'k'; ; execute (noOfDeletions(str2, k2))->display(); ) else skip; operation noOfDeletions(string : OclAny, k : OclAny) pre: true post: true activity: var ans : int := 0; var cnt : int := 0; var pos : int := 0; ; while ((pos->compareTo((string)->size())) < 0 & string[pos+1] /= k) do ( pos := pos + 1;) ; var i : int := pos; ; while ((i->compareTo((string)->size())) < 0) do ( while ((i->compareTo((string)->size())) < 0 & string[i+1] = k) do ( i := i + 1;) ; ans := ans + cnt; ; cnt := 0; ; while ((i->compareTo((string)->size())) < 0 & string[i+1] /= k) do ( i := i + 1; ; cnt := cnt + 1;)) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=lambda : map(int,input().split()) N=int(input()) T=list(I()) M=int(input()) ans=[sum(T)]*M for i in range(M): p,x=I() ans[i]=ans[i]-T[p-1]+x print('\n'.join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var T : Sequence := (I->apply()) ; var M : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ (T)->sum() }, M) ; for i : Integer.subrange(0, M-1) do ( var p : OclAny := null; var x : OclAny := null; Sequence{p,x} := I->apply() ; ans[i+1] := ans[i+1] - T[p - 1+1] + x) ; execute (StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- candidates=int(input()) votes=list(map(int,input().split(' '))) limak=votes[0] other_candidates=sorted(votes[1 :]) if limak>max(other_candidates): print(0) elif limak==max(other_candidates): print(1) else : while limak<=max(other_candidates): for i in range(candidates-1): if limak>max(other_candidates): break if other_candidates[i]==max(other_candidates): other_candidates[i]-=1 limak+=1 print(-votes[0]+limak) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var candidates : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var votes : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var limak : OclAny := votes->first() ; var other_candidates : Sequence := votes->tail()->sort() ; if (limak->compareTo((other_candidates)->max())) > 0 then ( execute (0)->display() ) else (if limak = (other_candidates)->max() then ( execute (1)->display() ) else ( while (limak->compareTo((other_candidates)->max())) <= 0 do ( for i : Integer.subrange(0, candidates - 1-1) do ( if (limak->compareTo((other_candidates)->max())) > 0 then ( break ) else skip ; if other_candidates[i+1] = (other_candidates)->max() then ( other_candidates[i+1] := other_candidates[i+1] - 1 ; limak := limak + 1 ) else skip)) ; execute (-votes->first() + limak)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) bears=list(map(int,input().split())) my_bear=bears.pop(0) bears.sort(reverse=True) count=0 while my_bear<=bears[0]: bears[0]-=1 my_bear+=1 count+=1 bears.sort(reverse=True) print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var bears : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var my_bear : OclAny := bears->at(0`firstArg+1) ; bears := bears->excludingAt(0+1) ; bears := bears->sort() ; var count : int := 0 ; while (my_bear->compareTo(bears->first())) <= 0 do ( bears->first() := bears->first() - 1 ; my_bear := my_bear + 1 ; count := count + 1 ; bears := bears->sort()) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _=int(input()) a=list(map(int,input().split())) counter=0 while a[0]!=max(a): a[a.index(max(a))]-=1 a[0]+=1 counter+=1 a.sort() if a[-1]==a[-2]: counter+=1 print(counter) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _anon : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var counter : int := 0 ; while a->first() /= (a)->max() do ( a[a->indexOf((a)->max()) - 1+1] := a[a->indexOf((a)->max()) - 1+1] - 1 ; a->first() := a->first() + 1 ; counter := counter + 1) ; a := a->sort() ; if a->last() = a->front()->last() then ( counter := counter + 1 ) else skip ; execute (counter)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) a,*w=list(map(int,input().split())) c=a while a<=max(w): w=sorted(w) a+=1 w[-1]-=1 print(a-c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := null; var w : OclAny := null; Sequence{a,w} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : OclAny := a ; while (a->compareTo((w)->max())) <= 0 do ( var w : Sequence := w->sort() ; a := a + 1 ; w->last() := w->last() - 1) ; execute (a - c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- candidates=int(input()) votes=list(map(int,input().split(' '))) limak=votes[0] other_candidates=sorted(votes[1 :]) if limak>max(other_candidates): print(0) elif limak==max(other_candidates): print(1) else : while limak<=max(other_candidates): for i in range(candidates-1): if other_candidates[i]==max(other_candidates): other_candidates[i]-=1 limak+=1 if limak>max(other_candidates): break print(-votes[0]+limak) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var candidates : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var votes : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var limak : OclAny := votes->first() ; var other_candidates : Sequence := votes->tail()->sort() ; if (limak->compareTo((other_candidates)->max())) > 0 then ( execute (0)->display() ) else (if limak = (other_candidates)->max() then ( execute (1)->display() ) else ( while (limak->compareTo((other_candidates)->max())) <= 0 do ( for i : Integer.subrange(0, candidates - 1-1) do ( if other_candidates[i+1] = (other_candidates)->max() then ( other_candidates[i+1] := other_candidates[i+1] - 1 ; limak := limak + 1 ; if (limak->compareTo((other_candidates)->max())) > 0 then ( break ) else skip ) else skip)) ; execute (-votes->first() + limak)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countMaxContiguous(arr,n): current_max=0 max_so_far=0 for i in range(n): if(arr[i]% 2!=0): current_max=0 else : current_max+=1 max_so_far=max(current_max,max_so_far) return max_so_far if __name__=="__main__" : arr=[1,0,2,4,3,8,9] n=len(arr) print(countMaxContiguous(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{0}->union(Sequence{2}->union(Sequence{4}->union(Sequence{3}->union(Sequence{8}->union(Sequence{ 9 })))))) ; n := (arr)->size() ; execute (countMaxContiguous(arr, n))->display() ) else skip; operation countMaxContiguous(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var current_max : int := 0 ; var max_so_far : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] mod 2 /= 0) then ( current_max := 0 ) else ( current_max := current_max + 1 ; max_so_far := Set{current_max, max_so_far}->max() )) ; return max_so_far; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=int(input()) result=list() number=1 fiveCount=0 while True : curFiveCount=fiveCount tempNumber=number while tempNumber % 5==0 : curFiveCount=curFiveCount+1 tempNumber=tempNumber//5 if curFiveCount==m : result.append(number) if curFiveCount>m : break fiveCount=curFiveCount number=number+1 print(len(result)) for ele in result : print(ele,end=(' ')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var result : Sequence := () ; var number : int := 1 ; var fiveCount : int := 0 ; while true do ( var curFiveCount : int := fiveCount ; var tempNumber : int := number ; while tempNumber mod 5 = 0 do ( curFiveCount := curFiveCount + 1 ; tempNumber := tempNumber div 5) ; if curFiveCount = m then ( execute ((number) : result) ) else skip ; if (curFiveCount->compareTo(m)) > 0 then ( break ) else skip ; fiveCount := curFiveCount ; number := number + 1) ; execute ((result)->size())->display() ; for ele : result do ( execute (ele)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count5(num): c=0 while(num % 5==0): num=num//5 c+=1 return(c) m=int(input()) k=0 num=0 while(ktoInteger() ; var k : int := 0 ; num := 0 ; while ((k->compareTo(m)) < 0) do ( num := num + 5 ; k := k + count5(num)) ; if (k = m) then ( execute (5)->display() ; execute (StringLib.formattedString("{num}{num+1}{num+2}{num+3}{num+4}"))->display() ) else ( execute (0)->display() ); operation count5(num : OclAny) : OclAny pre: true post: true activity: var c : int := 0 ; while (num mod 5 = 0) do ( num := num div 5 ; c := c + 1) ; return (c); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=lambda : sys.stdin.readline().strip() import math as mt from math import ceil as cl from math import log2 as l2 from collections import Counter as CNT mod=10**9+7 def ii(): return int(input()) def fi(): return float(input()) def lii(): return list(map(int,input().split())) def ss(): return input() def lss(): return input().split() def yes(): print("YES") def no(): print("NO") def count_zeroes(n): ans=0 while n>=5 : ans+=n//5 n//=5 return ans x=ii() num=1 ans=0 li=[] for i in range(1,10**6): if count_zeroes(i)==x : ans+=1 li.append(i) if ans>0 : print(ans) print(*li) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine()->trim()) ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var x : OclAny := ii() ; var num : int := 1 ; ans := 0 ; var li : Sequence := Sequence{} ; for i : Integer.subrange(1, (10)->pow(6)-1) do ( if count_zeroes(i) = x then ( ans := ans + 1 ; execute ((i) : li) ) else skip) ; if ans > 0 then ( execute (ans)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name li))))))))->display() ) else ( execute (0)->display() ); operation ii() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation fi() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation lii() : OclAny pre: true post: true activity: return ((input->apply().split())->collect( _x | (OclType["int"])->apply(_x) )); operation ss() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation lss() : OclAny pre: true post: true activity: return input->apply().split(); operation yes() pre: true post: true activity: execute ("YES")->display(); operation no() pre: true post: true activity: execute ("NO")->display(); operation count_zeroes(n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; while n >= 5 do ( ans := ans + n div 5 ; n := n div 5) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=(int(input())) l=[5,25,125,625,3125,15625,78125,390625,1953125] l2=[] for i in range(1,500000): c=0 for j in range(len(l)): if i>=l[j]: c+=i//l[j] if c==m : l2.append(i) print(len(l2)) print(*l2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : int := (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var l : Sequence := Sequence{5}->union(Sequence{25}->union(Sequence{125}->union(Sequence{625}->union(Sequence{3125}->union(Sequence{15625}->union(Sequence{78125}->union(Sequence{390625}->union(Sequence{ 1953125 })))))))) ; var l2 : Sequence := Sequence{} ; for i : Integer.subrange(1, 500000-1) do ( var c : int := 0 ; for j : Integer.subrange(0, (l)->size()-1) do ( if (i->compareTo(l[j+1])) >= 0 then ( c := c + i div l[j+1] ) else skip) ; if c = m then ( execute ((i) : l2) ) else skip) ; execute ((l2)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name l2))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a,b=1,0 for i in range(n): q,x=map(int,input().split()) if q==1 : a*=x b*=x elif q==2 : b+=x elif q==3 : b-=x print(-b,a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{1,0} ; for i : Integer.subrange(0, n-1) do ( var q : OclAny := null; var x : OclAny := null; Sequence{q,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if q = 1 then ( a := a * x ; b := b * x ) else (if q = 2 then ( b := b + x ) else (if q = 3 then ( b := b - x ) else skip ) ) ) ; execute (-b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin def I(): return int(stdin.readline().rstrip()) def LI(): return list(map(int,stdin.readline().rstrip().split())) n=I() t=LI() m=I() p=[] x=[] for i in range(m): tmp=LI() p.append(tmp.pop(0)-1) x.append(tmp.pop(0)) for i in range(m): sum=0 for j in range(n): if j==p[i]: sum+=x[i] else : sum+=t[j] print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var n : OclAny := I() ; var t : OclAny := LI() ; var m : OclAny := I() ; var p : Sequence := Sequence{} ; var x : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var tmp : OclAny := LI() ; execute ((tmp->at(0`firstArg+1) - 1) : p) ; execute ((tmp->at(0`firstArg+1)) : x)) ; for i : Integer.subrange(0, m-1) do ( var sum : int := 0 ; for j : Integer.subrange(0, n-1) do ( if j = p[i+1] then ( sum := sum + x[i+1] ) else ( sum := sum + t[j+1] )) ; execute (sum)->display()); operation I() : OclAny pre: true post: true activity: return ("" + ((stdin.readLine().rstrip())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return ((stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from heapq import heappush,heappop import sys import math import bisect import random def LI(): return[int(x)for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return[list(x)for x in sys.stdin.readline().split()] def S(): res=list(sys.stdin.readline()) if res[-1]=="\n" : return res[:-1] return res def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] sys.setrecursionlimit(1000000) mod=1000000007 def solve(): n=I() a,b=0,1 for i in range(n): q,x=LI() if q==1 : a*=x b*=x elif q==2 : a+=x b+=x else : a-=x b-=x B=b-a print(B-b,B) return if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1000000) ; var mod : int := 1000000007 ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | ((x))); operation S() : OclAny pre: true post: true activity: var res : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if res->last() = "\n" then ( return res->front() ) else skip ; return res; operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation solve() pre: true post: true activity: n := I() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{0,1} ; for i : Integer.subrange(0, n-1) do ( var q : OclAny := null; var x : OclAny := null; Sequence{q,x} := LI() ; if q = 1 then ( a := a * x ; b := b * x ) else (if q = 2 then ( a := a + x ; b := b + x ) else ( a := a - x ; b := b - x ) ) ) ; var B : double := b - a ; execute (B - b)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) queries=[list(map(int,input().split()))for i in range(n)] s,t=1,0 for q in queries : if q[0]==1 : s*=q[1] t*=q[1] elif q[0]==2 : t+=q[1] else : t-=q[1] print(-t,s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var queries : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := Sequence{1,0} ; for q : queries do ( if q->first() = 1 then ( s := s * q[1+1] ; t := t * q[1+1] ) else (if q->first() = 2 then ( t := t + q[1+1] ) else ( t := t - q[1+1] ) ) ) ; execute (-t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) a,b=1,0 for _ in range(N): q,x=map(int,input().split()) if q==1 : a*=x ; b*=x elif q==2 : b+=x else : b-=x print(-b,a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{1,0} ; for _anon : Integer.subrange(0, N-1) do ( var q : OclAny := null; var x : OclAny := null; Sequence{q,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if q = 1 then ( a := a * x; b := b * x ) else (if q = 2 then ( b := b + x ) else ( b := b - x ) ) ) ; execute (-b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairs(n): if(n==2): return 4 num=((n//2)+1); max=n % num ; count=n-max ; return count if __name__=="__main__" : n=5 ; print(countPairs(n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 5; ) else skip ; execute (countPairs(n))->display();; operation countPairs(n : OclAny) : OclAny pre: true post: true activity: if (n = 2) then ( return 4 ) else skip ; var num : int := ((n div 2) + 1); ; var max : int := n mod num; ; var count : double := n - max; ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxPartitions(arr,n): ans=0 ; max_so_far=0 for i in range(0,n): max_so_far=max(max_so_far,arr[i]) if(max_so_far==i): ans+=1 return ans arr=[1,0,2,3,4] n=len(arr) print(maxPartitions(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{0}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 })))) ; n := (arr)->size() ; execute (maxPartitions(arr, n))->display(); operation maxPartitions(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0; var max_so_far : int := 0 ; for i : Integer.subrange(0, n-1) do ( max_so_far := Set{max_so_far, arr[i+1]}->max() ; if (max_so_far = i) then ( ans := ans + 1 ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def split(x,n): if(x=zp): print(pp+1,end=" ") else : print(pp,end=" ") x=5 n=3 split(x,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; x := 5 ; n := 3 ; split(x, n); operation split(x : OclAny, n : OclAny) pre: true post: true activity: if ((x->compareTo(n)) < 0) then ( execute (-1)->display() ) else (if (x mod n = 0) then ( for i : Integer.subrange(0, n-1) do ( execute (x div n)->display()) ) else ( var zp : double := n - (x mod n) ; var pp : int := x div n ; for i : Integer.subrange(0, n-1) do ( if ((i->compareTo(zp)) >= 0) then ( execute (pp + 1)->display() ) else ( execute (pp)->display() )) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def checkDivisibility(n,digit): return(digit!=0 and n % digit==0) def allDigitsDivide(n): temp=n while(temp>0): digit=n % 10 if((checkDivisibility(n,digit))==False): return False temp=temp//10 return True n=128 if(allDigitsDivide(n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 128 ; if (allDigitsDivide(n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation checkDivisibility(n : OclAny, digit : OclAny) : OclAny pre: true post: true activity: return (digit /= 0 & n mod digit = 0); operation allDigitsDivide(n : OclAny) : OclAny pre: true post: true activity: var temp : OclAny := n ; while (temp > 0) do ( digit := n mod 10 ; if ((checkDivisibility(n, digit)) = false) then ( return false ) else skip ; temp := temp div 10) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=set([i*(i+1)//2 for i in range(1,50000)]) n=int(input()) print("YES" if any(n-t in a for t in a)else "NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Set := Set{}->union((Integer.subrange(1, 50000-1)->select(i | true)->collect(i | (i * (i + 1) div 2)))) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (if ((argument (test (logical_test (comparison (comparison (expr (expr (atom (name n))) - (expr (atom (name t))))) in (comparison (expr (atom (name a))))))) (comp_for for (exprlist (expr (atom (name t)))) in (logical_test (comparison (expr (atom (name a))))))))->exists( _x | _x = true ) then "YES" else "NO" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=set([i*(i+1)/2 for i in range(1,1000000)]) n=int(input()) print(["NO","YES"][any(n-t in s for t in s)]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Set := Set{}->union((Integer.subrange(1, 1000000-1)->select(i | true)->collect(i | (i * (i + 1) / 2)))) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (Sequence{"NO"}->union(Sequence{ "YES" })->select(((argument (test (logical_test (comparison (comparison (expr (expr (atom (name n))) - (expr (atom (name t))))) in (comparison (expr (atom (name s))))))) (comp_for for (exprlist (expr (atom (name t)))) in (logical_test (comparison (expr (atom (name s))))))))->exists( _x | _x = true )))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=1 while x*(x+1)//2t : r=m else : l=m r=round(r) if r*(r+1)//2==t : print("YES") quit() x+=1 print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := 1 ; while (x * (x + 1) div 2->compareTo(n)) < 0 do ( var t : double := n - x * (x + 1) div 2 ; var l : int := 0 ; var r : int := 100000 ; for i : Integer.subrange(0, 40-1) do ( var m : double := (l + r) / 2 ; if (m * (m + 1) / 2->compareTo(t)) > 0 then ( r := m ) else ( l := m )) ; r := (r)->round() ; if r * (r + 1) div 2 = t then ( execute ("YES")->display() ; quit() ) else skip ; x := x + 1) ; execute ("NO")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): n=int(input()) n*=2 sh=set() for i in range(1,int(math.sqrt(n))+1): val=i*i+i sh.add(val) if n-val in sh : print("YES") return print("NO") def main(): t=1 for _ in range(t): solution() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; main(); operation solution() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; n := n * 2 ; var sh : Set := Set{}->union(()) ; for i : Integer.subrange(1, ("" + (((n)->sqrt())))->toInteger() + 1-1) do ( var val : double := i * i + i ; execute ((val) : sh) ; if (sh)->includes(n - val) then ( execute ("YES")->display() ; return ) else skip) ; execute ("NO")->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) first=list(map(int,input().split())) drink_count=int(input()) count=0 Total=sum(first) drink=[list(map(int,input().split()))for i in range(drink_count)] for T in range(drink_count): change_num=drink[count][0] score=first[change_num-1]-drink[count][1] print(Total-score) count+=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var first : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var drink_count : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := 0 ; var Total : OclAny := (first)->sum() ; var drink : Sequence := Integer.subrange(0, drink_count-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for T : Integer.subrange(0, drink_count-1) do ( var change_num : OclAny := drink[count+1]->first() ; var score : double := first[change_num - 1+1] - drink[count+1][1+1] ; execute (Total - score)->display() ; count := count + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): n=int(input()) arr=[] for i in range(1,2*int(math.sqrt(n))+2): arr.append((i*(i+1))//2) left=0 right=len(arr)-1 while left<=right : cur=arr[left]+arr[right] if cur==n : print("YES") return if cur>n : right-=1 else : left+=1 print("NO") def main(): t=1 for _ in range(t): solution() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; main(); operation solution() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Sequence{} ; for i : Integer.subrange(1, 2 * ("" + (((n)->sqrt())))->toInteger() + 2-1) do ( execute (((i * (i + 1)) div 2) : arr)) ; var left : int := 0 ; var right : double := (arr)->size() - 1 ; while (left->compareTo(right)) <= 0 do ( var cur : OclAny := arr[left+1] + arr[right+1] ; if cur = n then ( execute ("YES")->display() ; return ) else skip ; if (cur->compareTo(n)) > 0 then ( right := right - 1 ) else ( left := left + 1 )) ; execute ("NO")->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): N=20000000 K=15000000 smallestprimefactor=eulerlib.list_smallest_prime_factors(N) def factorial_prime_factor_sum(n): result=0 for i in range(n+1): j=i while j>1 : p=smallestprimefactor[j] result+=p j//=p return result ans=factorial_prime_factor_sum(N)-factorial_prime_factor_sum(K)-factorial_prime_factor_sum(N-K) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var N : int := 20000000 ; var K : int := 15000000 ; var smallestprimefactor : OclAny := eulerlib.list_smallest_prime_factors(N) ; skip ; var ans : double := factorial_prime_factor_sum(N) - factorial_prime_factor_sum(K) - factorial_prime_factor_sum(N - K) ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def singleNumber(nums): return(3*sum(set(nums))-sum(nums))/2 a=[12,1,12,3,12,1,1,2,3,2,2,3,7] print("The element with single occurrence is ",int(singleNumber(a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : Sequence := Sequence{12}->union(Sequence{1}->union(Sequence{12}->union(Sequence{3}->union(Sequence{12}->union(Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{2}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 7 })))))))))))) ; execute ("The element with single occurrence is ")->display(); operation singleNumber(nums : OclAny) : OclAny pre: true post: true activity: return (3 * (Set{}->union((nums)))->sum() - (nums)->sum()) / 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def cubeSide(h,r): if(h<0 and r<0): return-1 a=((h*r*math.sqrt(2))/(h+math.sqrt(2)*r)) return a h=5 ; r=6 ; print(cubeSide(h,r),"\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; h := 5; r := 6; ; execute (cubeSide(h, r))->display(); operation cubeSide(h : OclAny, r : OclAny) : OclAny pre: true post: true activity: if (h < 0 & r < 0) then ( return -1 ) else skip ; var a : double := ((h * r * (2)->sqrt()) / (h + (2)->sqrt() * r)) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- arr=list(map(int,input().split())) if abs(arr[0]-arr[1])>0 : print(1) else : print(arr[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if (arr->first() - arr[1+1])->abs() > 0 then ( execute (1)->display() ) else ( execute (arr->first())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()); print([n,1][n!=m]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); execute (Sequence{n}->union(Sequence{ 1 })->select(n /= m))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=input().split(); print([a,1][a!=b]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split(); execute (Sequence{a}->union(Sequence{ 1 })->select(a /= b))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=input().split(); print([1,n][n==m]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split(); execute (Sequence{1}->union(Sequence{ n })->select(n = m))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=input().split(); print([1,a][a==b]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split(); execute (Sequence{1}->union(Sequence{ a })->select(a = b))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil a,b,x1,y1,x2,y2=map(int,input().split()) a1=(x1+y1)//(2*a) a2=(x2+y2)//(2*a) b1=(x1-y1)//(2*b) b2=(x2-y2)//(2*b) print(max(abs(a1-a2),abs(b1-b2))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{a,b,x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a1 : int := (x1 + y1) div (2 * a) ; var a2 : int := (x2 + y2) div (2 * a) ; var b1 : int := (x1 - y1) div (2 * b) ; var b2 : int := (x2 - y2) div (2 * b) ; execute (Set{(a1 - a2)->abs(), (b1 - b2)->abs()}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,x1,y1,x2,y2=map(int,input().split()) X1,Y1=x1+y1,x1-y1 X2,Y2=x2+y2,x2-y2 A,B=2*a,2*b def solve(x,y,z): if x>=0>y or x<0<=y : x=max(x,-x) y=max(y,-y) tmp=x//z+y//z+1 return tmp else : if xcollect( _x | (OclType["int"])->apply(_x) ) ; var X1 : OclAny := null; var Y1 : OclAny := null; Sequence{X1,Y1} := Sequence{x1 + y1,x1 - y1} ; var X2 : OclAny := null; var Y2 : OclAny := null; Sequence{X2,Y2} := Sequence{x2 + y2,x2 - y2} ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := Sequence{2 * a,2 * b} ; skip ; var ans1 : OclAny := solve(X1, X2, A) ; var ans2 : OclAny := solve(Y1, Y2, B) ; execute (Set{ans1, ans2}->max())->display(); operation solve(x : OclAny, y : OclAny, z : OclAny) : OclAny pre: true post: true activity: if x >= 0 & (0 > y) or x < 0 & (0 <= y) then ( x := Set{x, -x}->max() ; y := Set{y, -y}->max() ; var tmp : int := x div z + y div z + 1 ; return tmp ) else ( if (x->compareTo(y)) < 0 then ( Sequence{x,y} := Sequence{y,x} ) else skip ; tmp := x div z - y div z ; return tmp ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys stdin=sys.stdin sys.setrecursionlimit(10**5) def li(): return map(int,stdin.readline().split()) def li_(): return map(lambda x : int(x)-1,stdin.readline().split()) def lf(): return map(float,stdin.readline().split()) def ls(): return stdin.readline().split() def ns(): return stdin.readline().rstrip() def lc(): return list(ns()) def ni(): return int(stdin.readline()) def nf(): return float(stdin.readline()) n=ni() t=list(li()) total=sum(t) m=ni() px=[] for _ in range(m): p,x=li() p-=1 print(total-t[p]+x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var stdin : OclFile := OclFile["System.in"] ; sys.setrecursionlimit((10)->pow(5)) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var n : OclAny := ni() ; var t : Sequence := (li()) ; var total : OclAny := (t)->sum() ; var m : OclAny := ni() ; var px : Sequence := Sequence{} ; for _anon : Integer.subrange(0, m-1) do ( var p : OclAny := null; var x : OclAny := null; Sequence{p,x} := li() ; p := p - 1 ; execute (total - t[p+1] + x)->display()); operation li() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation li_() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) ); operation lf() : OclAny pre: true post: true activity: return (stdin.readLine().split())->collect( _x | (OclType["double"])->apply(_x) ); operation ls() : OclAny pre: true post: true activity: return stdin.readLine().split(); operation ns() : OclAny pre: true post: true activity: return stdin.readLine().rstrip(); operation lc() : OclAny pre: true post: true activity: return (ns()); operation ni() : OclAny pre: true post: true activity: return ("" + ((stdin.readLine())))->toInteger(); operation nf() : OclAny pre: true post: true activity: return ("" + ((stdin.readLine())))->toReal(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,x1,y1,x2,y2=[int(k)for k in input().split()] x1+=10**10*a*b x2+=10**10*a*b y1+=10**10*a*b y2+=10**10*a*b res=0 x=abs((x2+y2)//(2*a)-(x1+y1)//(2*a)) y=abs((x2-y2)//(2*b)-(x1-y1)//(2*b)) print(max(x,y)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{a,b,x1,y1,x2,y2} := input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger())) ; x1 := x1 + (10)->pow(10) * a * b ; x2 := x2 + (10)->pow(10) * a * b ; y1 := y1 + (10)->pow(10) * a * b ; y2 := y2 + (10)->pow(10) * a * b ; var res : int := 0 ; var x : double := ((x2 + y2) div (2 * a) - (x1 + y1) div (2 * a))->abs() ; var y : double := ((x2 - y2) div (2 * b) - (x1 - y1) div (2 * b))->abs() ; execute (Set{x, y}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin inp=stdin.readline a,b,x1,y1,x2,y2=map(int,inp().split()) m=max(x1+y1,x2+y2)%(2*a) x=abs(x1+y1-x2-y2) if x>=m : ansA=(x-m)//(2*a)+1 else : ansA=0 m=max(x1-y1,x2-y2)%(2*b) x=abs(x1-y1-x2+y2) if x>=m : ansB=(x-m)//(2*b)+1 else : ansB=0 print(max(ansA,ansB)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var inp : OclAny := stdin.readline ; var a : OclAny := null; var b : OclAny := null; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{a,b,x1,y1,x2,y2} := (inp().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : int := Set{x1 + y1, x2 + y2}->max() mod (2 * a) ; var x : double := (x1 + y1 - x2 - y2)->abs() ; if (x->compareTo(m)) >= 0 then ( var ansA : int := (x - m) div (2 * a) + 1 ) else ( ansA := 0 ) ; m := Set{x1 - y1, x2 - y2}->max() mod (2 * b) ; x := (x1 - y1 - x2 + y2)->abs() ; if (x->compareTo(m)) >= 0 then ( var ansB : int := (x - m) div (2 * b) + 1 ) else ( ansB := 0 ) ; execute (Set{ansA, ansB}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pattern(rows_no): for i in range(1,rows_no+1): for k in range(1,i): print("",end="") for j in range(i,rows_no+1): print(j,end="") print() for i in range(rows_no-1,0,-1): for k in range(1,i): print("",end="") for j in range(i,rows_no+1): print(j,end="") print() rows_no=7 pattern(rows_no) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; rows_no := 7 ; pattern(rows_no); operation pattern(rows_no : OclAny) pre: true post: true activity: for i : Integer.subrange(1, rows_no + 1-1) do ( for k : Integer.subrange(1, i-1) do ( execute ("")->display()) ; for j : Integer.subrange(i, rows_no + 1-1) do ( execute (j)->display()) ; execute (->display()) ; for i : Integer.subrange(0 + 1, rows_no - 1)->reverse() do ( for k : Integer.subrange(1, i-1) do ( execute ("")->display()) ; for j : Integer.subrange(i, rows_no + 1-1) do ( execute (j)->display()) ; execute (->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline a,b,x0,y0,x1,y1=map(int,readline().split()) X0,X1=x0+y0,x1+y1 if X0>X1 : X0,X1=X1,X0 Y0,Y1=x0-y0,x1-y1 if Y0>Y1 : Y0,Y1=Y1,Y0 ans=max(X1//(2*a)-(X0-1)//(2*a),Y1//(2*b)-(Y0-1)//(2*b)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var a : OclAny := null; var b : OclAny := null; var x0 : OclAny := null; var y0 : OclAny := null; var x1 : OclAny := null; var y1 : OclAny := null; Sequence{a,b,x0,y0,x1,y1} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var X0 : OclAny := null; var X1 : OclAny := null; Sequence{X0,X1} := Sequence{x0 + y0,x1 + y1} ; if (X0->compareTo(X1)) > 0 then ( var X0 : OclAny := null; var X1 : OclAny := null; Sequence{X0,X1} := Sequence{X1,X0} ) else skip ; var Y0 : OclAny := null; var Y1 : OclAny := null; Sequence{Y0,Y1} := Sequence{x0 - y0,x1 - y1} ; if (Y0->compareTo(Y1)) > 0 then ( var Y0 : OclAny := null; var Y1 : OclAny := null; Sequence{Y0,Y1} := Sequence{Y1,Y0} ) else skip ; var ans : OclAny := Set{X1 div (2 * a) - (X0 - 1) div (2 * a), Y1 div (2 * b) - (Y0 - 1) div (2 * b)}->max() ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def MaximumHeight(a,n): return(-1+int(math.sqrt(1+(8*n))))//2 arr=[40,100,20,30] n=len(arr) print(MaximumHeight(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var arr : Sequence := Sequence{40}->union(Sequence{100}->union(Sequence{20}->union(Sequence{ 30 }))) ; n := (arr)->size() ; execute (MaximumHeight(arr, n))->display(); operation MaximumHeight(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: return (-1 + ("" + (((1 + (8 * n))->sqrt())))->toInteger()) div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfDiv(x): sum=1 for i in range(2,x): if x % i==0 : sum+=i return sum def isAmicable(a,b): if sumOfDiv(a)==b and sumOfDiv(b)==a : return True else : return False def countPairs(arr,n): count=0 for i in range(0,n): for j in range(i+1,n): if isAmicable(arr[i],arr[j]): count=count+1 return count arr1=[220,284,1184,1210,2,5] n1=len(arr1) print(countPairs(arr1,n1)) arr2=[2620,2924,5020,5564,6232,6368] n2=len(arr2) print(countPairs(arr2,n2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var arr1 : Sequence := Sequence{220}->union(Sequence{284}->union(Sequence{1184}->union(Sequence{1210}->union(Sequence{2}->union(Sequence{ 5 }))))) ; var n1 : int := (arr1)->size() ; execute (countPairs(arr1, n1))->display() ; var arr2 : Sequence := Sequence{2620}->union(Sequence{2924}->union(Sequence{5020}->union(Sequence{5564}->union(Sequence{6232}->union(Sequence{ 6368 }))))) ; var n2 : int := (arr2)->size() ; execute (countPairs(arr2, n2))->display(); operation sumOfDiv(x : OclAny) : OclAny pre: true post: true activity: var sum : int := 1 ; for i : Integer.subrange(2, x-1) do ( if x mod i = 0 then ( sum := sum + i ) else skip) ; return sum; operation isAmicable(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if sumOfDiv(a) = b & sumOfDiv(b) = a then ( return true ) else ( return false ); operation countPairs(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if isAmicable(arr[i+1], arr[j+1]) then ( count := count + 1 ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bitCount(n): count=0 while(n): if(n & 1): count+=1 n>>=1 return count def countPairsWithKDiff(arr,n,k): ans=0 for i in range(0,n-1,1): for j in range(i+1,n,1): xoredNum=arr[i]^ arr[j] if(k==bitCount(xoredNum)): ans+=1 return ans if __name__=='__main__' : k=2 arr=[2,4,1,3,1] n=len(arr) print("Total pairs for k=",k,"are",countPairsWithKDiff(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( k := 2 ; arr := Sequence{2}->union(Sequence{4}->union(Sequence{1}->union(Sequence{3}->union(Sequence{ 1 })))) ; n := (arr)->size() ; execute ("Total pairs for k=")->display() ) else skip; operation bitCount(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while (n) do ( if (MathLib.bitwiseAnd(n, 1)) then ( count := count + 1 ) else skip ; n := n div (2->pow(1))) ; return count; operation countPairsWithKDiff(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, n - 1-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( for j : Integer.subrange(i + 1, n-1)->select( $x | ($x - i + 1) mod 1 = 0 ) do ( var xoredNum : int := MathLib.bitwiseXor(arr[i+1], arr[j+1]) ; if (k = bitCount(xoredNum)) then ( ans := ans + 1 ) else skip)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,a,b=map(int,input().split()) if n==0 : break f=[0]*(n+max(a,b)+1) f[0],f[a],f[b]=1,1,1 s=min(a,b) for k in range(s,n+1): if f[k]: f[a+k]=1 ; f[b+k]=1 print(n-sum(f[s : n+1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + Set{a, b}->max() + 1)) ; var f->first() : OclAny := null; var f[a+1] : OclAny := null; var f[b+1] : OclAny := null; Sequence{f->first(),f[a+1],f[b+1]} := Sequence{1,1,1} ; var s : OclAny := Set{a, b}->min() ; for k : Integer.subrange(s, n + 1-1) do ( if f[k+1] then ( f[a + k+1] := 1; f[b + k+1] := 1 ) else skip) ; execute (n - (f.subrange(s+1, n + 1))->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,a,b=map(int,input().split()) if not n : break if a>b : a,b=b,a dp=[False]*(n+b-a+1) dp[1 : n+1]=[True]*n for i in range(n-a+1): if not dp[i]: dp[i+a]=False dp[i+b]=False print(dp.count(True)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if not(n) then ( break ) else skip ; if (a->compareTo(b)) > 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a} ) else skip ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (n + b - a + 1)) ; dp.subrange(1+1, n + 1) := MatrixLib.elementwiseMult(Sequence{ true }, n) ; for i : Integer.subrange(0, n - a + 1-1) do ( if not(dp[i+1]) then ( dp[i + a+1] := false ; dp[i + b+1] := false ) else skip) ; execute (dp->count(true))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n,a,b=map(int,input().split()) if n==a==b==0 : break c=0 ; d=[1]+[0]*1000000 for i in range(0,n+1): if d[i]: if i+a<=n : d[i+a]=1 if i+b<=n : d[i+b]=1 else : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = a & (a == b) & (b == 0) then ( break ) else skip ; var c : int := 0; var d : Sequence := Sequence{ 1 }->union(MatrixLib.elementwiseMult(Sequence{ 0 }, 1000000)) ; for i : Integer.subrange(0, n + 1-1) do ( if d[i+1] then ( if (i + a->compareTo(n)) <= 0 then ( d[i + a+1] := 1 ) else skip ; if (i + b->compareTo(n)) <= 0 then ( d[i + b+1] := 1 ) else skip ) else ( c := c + 1 )) ; execute (c)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,a,b=map(int,input().split()) if n==0 : break ok=[1]*(n+1) for i in range(b): for j in range(0,n-i*a+1,b): ok[i*a+j]=0 print(sum(ok)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var ok : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ; for i : Integer.subrange(0, b-1) do ( for j : Integer.subrange(0, n - i * a + 1-1)->select( $x | ($x - 0) mod b = 0 ) do ( ok[i * a + j+1] := 0)) ; execute ((ok)->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from copy import deepcopy n=input() a=[int(x)for x in input().split()] m=int(input()) for _ in range(m): t=deepcopy(a) b,c=[int(x)for x in input().split()] t[b-1]=c print(sum(t)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : String := (OclFile["System.in"]).readLine() ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, m-1) do ( var t : OclAny := deepcopy(a) ; var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; t[b - 1+1] := c ; execute ((t)->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n,a,b=map(int,input().split()) if n==a==b==0 : break c=0 ; d=[1]*(n+1) for x in range(a): for i in range(x*b,n+1,a): d[i]=0 print(sum(d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = a & (a == b) & (b == 0) then ( break ) else skip ; var c : int := 0; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ; for x : Integer.subrange(0, a-1) do ( for i : Integer.subrange(x * b, n + 1-1)->select( $x | ($x - x * b) mod a = 0 ) do ( d[i+1] := 0)) ; execute ((d)->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() ans="" flag=False for c in s : if c=="A" and not flag : flag=True if c=="Z" and flag : ans+="AZ" flag=False if ans=="" : print(-1) else : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var ans : String := "" ; var flag : boolean := false ; for c : s->characters() do ( if c = "A" & not(flag) then ( flag := true ) else skip ; if c = "Z" & flag then ( ans := ans + "AZ" ; flag := false ) else skip) ; if ans = "" then ( execute (-1)->display() ) else ( execute (ans)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=1e9+7 n,m,k=map(int,input().split()) if(n+m)% 2==1 and k==-1 : print(0) exit() a=(n-1)*(m-1) print(pow(2,a,int(mod))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : double := ("1e9")->toReal() + 7 ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (n + m) mod 2 = 1 & k = -1 then ( execute (0)->display() ; exit() ) else skip ; var a : double := (n - 1) * (m - 1) ; execute ((2)->pow(a))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split(" ")) if a % 2!=b % 2 and c==-1 : print(0) else : mod=int(1e9+7) print(pow(2,(a-1)*(b-1),mod)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; if a mod 2 /= b mod 2 & c = -1 then ( execute (0)->display() ) else ( var mod : int := ("" + ((("1e9")->toReal() + 7)))->toInteger() ; execute ((2)->pow((a - 1) * (b - 1)))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p=10**9+7 def power(x,y,p): b=bin(y)[2 :] start=x % p answer=1 for i in range(len(b)): if b[len(b)-1-i]=='1' : answer=(start*answer)% p start=(start*start)% p return answer def process(n,m,k): if k==-1 and n % 2!=m % 2 : return 0 return power(2,(n-1)*(m-1),p) n,m,k=[int(x)for x in input().split()] print(process(n,m,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : double := (10)->pow(9) + 7 ; skip ; skip ; Sequence{n,m,k} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (process(n, m, k))->display(); operation power(x : OclAny, y : OclAny, p : OclAny) : OclAny pre: true post: true activity: var b : OclAny := bin(y).subrange(2+1) ; var start : int := x mod p ; var answer : int := 1 ; for i : Integer.subrange(0, (b)->size()-1) do ( if b[(b)->size() - 1 - i+1] = '1' then ( answer := (start * answer) mod p ) else skip ; start := (start * start) mod p) ; return answer; operation process(n : OclAny, m : OclAny, k : OclAny) : OclAny pre: true post: true activity: if k = -1 & n mod 2 /= m mod 2 then ( return 0 ) else skip ; return power(2, (n - 1) * (m - 1), p); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=input().split() n,m,k=int(n),int(m),int(k) if(k==-1 and n % 2!=m % 2): print(0) else : print(pow(2,(m-1)*(n-1),10**9+7)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := input().split() ; var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := Sequence{("" + ((n)))->toInteger(),("" + ((m)))->toInteger(),("" + ((k)))->toInteger()} ; if (k = -1 & n mod 2 /= m mod 2) then ( execute (0)->display() ) else ( execute ((2)->pow((m - 1) * (n - 1)))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m,k=map(int,input().split()) MOD=1000000007 p=(n-1)*(m-1) if k<0 and n % 2!=m % 2 : r=0 else : r=pow(2,p,MOD) print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; var k : OclAny := null; Sequence{n,m,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var MOD : int := 1000000007 ; var p : double := (n - 1) * (m - 1) ; if k < 0 & n mod 2 /= m mod 2 then ( var r : int := 0 ) else ( r := (2)->pow(p) ) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() mu=['A','H','I','M','O','o','T','U','V','v','W','w','X','x','Y'] slen=len(s) flag=1 for i in range(slen): if s[i]==s[-i-1]and s[i]in mu : pass elif(s[i]=='b' and s[-i-1]=='d')or(s[i]=='d' and s[-i-1]=='b'): pass elif(s[i]=='p' and s[-i-1]=='q')or(s[i]=='q' and s[-i-1]=='p'): pass else : flag=0 if flag==1 : print("TAK") else : print("NIE") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var mu : Sequence := Sequence{'A'}->union(Sequence{'H'}->union(Sequence{'I'}->union(Sequence{'M'}->union(Sequence{'O'}->union(Sequence{'o'}->union(Sequence{'T'}->union(Sequence{'U'}->union(Sequence{'V'}->union(Sequence{'v'}->union(Sequence{'W'}->union(Sequence{'w'}->union(Sequence{'X'}->union(Sequence{'x'}->union(Sequence{ 'Y' })))))))))))))) ; var slen : int := (s)->size() ; var flag : int := 1 ; for i : Integer.subrange(0, slen-1) do ( if s[i+1] = s->reverse()->at(-(-i - 1)) & (mu)->includes(s[i+1]) then ( skip ) else (if (s[i+1] = 'b' & s->reverse()->at(-(-i - 1)) = 'd') or (s[i+1] = 'd' & s->reverse()->at(-(-i - 1)) = 'b') then ( skip ) else (if (s[i+1] = 'p' & s->reverse()->at(-(-i - 1)) = 'q') or (s[i+1] = 'q' & s->reverse()->at(-(-i - 1)) = 'p') then ( skip ) else ( flag := 0 ) ) ) ) ; if flag = 1 then ( execute ("TAK")->display() ) else ( execute ("NIE")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=input() k=len(t)//2+1 p=zip(t[: k],t[-k :][: :-1]) u,v='AHIMOoTUVvWwXxY','bd db pq qp' s=all(a in u and a==b or a+b in v for a,b in p) print(['NIE','TAK'][s]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : String := (OclFile["System.in"]).readLine() ; var k : int := (t)->size() div 2 + 1 ; var p : Sequence := Integer.subrange(1, t.subrange(1,k)->size())->collect( _indx | Sequence{t.subrange(1,k)->at(_indx), t.subrange(-k+1)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))->at(_indx)} ) ; var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := Sequence{'AHIMOoTUVvWwXxY','bd db pq qp'} ; var s : boolean := ((argument (test (logical_test (logical_test (logical_test (comparison (comparison (expr (atom (name a)))) in (comparison (expr (atom (name u)))))) and (logical_test (comparison (comparison (expr (atom (name a)))) == (comparison (expr (atom (name b))))))) or (logical_test (comparison (comparison (expr (expr (atom (name a))) + (expr (atom (name b))))) in (comparison (expr (atom (name v)))))))) (comp_for for (exprlist (expr (atom (name a))) , (expr (atom (name b)))) in (logical_test (comparison (expr (atom (name p))))))))->forAll( _x | _x = true ) ; execute (Sequence{'NIE'}->union(Sequence{ 'TAK' })[s+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=str(input()) t='AHIMOoTUVvWwXxY' d={'p' : 'q','q' : 'p','b' : 'd','d' : 'b'} for c in t : d[c]=c for i,c in enumerate(s): if c in d and s[len(s)-1-i]==d[c]: continue else : print('NIE') exit() print('TAK') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := ("" + (((OclFile["System.in"]).readLine()))) ; var t : String := 'AHIMOoTUVvWwXxY' ; var d : Map := Map{ 'p' |-> 'q' }->union(Map{ 'q' |-> 'p' }->union(Map{ 'b' |-> 'd' }->union(Map{ 'd' |-> 'b' }))) ; for c : t->characters() do ( d[c+1] := c) ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if (d)->includes(c) & s[(s)->size() - 1 - i+1] = d[c+1] then ( continue ) else ( execute ('NIE')->display() ; exit() )) ; execute ('TAK')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- palindrom_letters={'A' : 'A','b' : 'd','d' : 'b','H' : 'H','I' : 'I','M' : 'M','O' : 'O','o' : 'o','p' : 'q','q' : 'p','T' : 'T','U' : 'U','V' : 'V','v' : 'v','W' : 'W','w' : 'w','X' : 'X','x' : 'x','Y' : 'Y'} start_word=input() new_word1=start_word[: :-1] new_word2='' for letter in new_word1 : if letter in palindrom_letters.keys(): new_word2+=palindrom_letters[letter] else : print('NIE') exit() if new_word2==start_word : print('TAK') else : print('NIE') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var palindrom_letters : Map := Map{ 'A' |-> 'A' }->union(Map{ 'b' |-> 'd' }->union(Map{ 'd' |-> 'b' }->union(Map{ 'H' |-> 'H' }->union(Map{ 'I' |-> 'I' }->union(Map{ 'M' |-> 'M' }->union(Map{ 'O' |-> 'O' }->union(Map{ 'o' |-> 'o' }->union(Map{ 'p' |-> 'q' }->union(Map{ 'q' |-> 'p' }->union(Map{ 'T' |-> 'T' }->union(Map{ 'U' |-> 'U' }->union(Map{ 'V' |-> 'V' }->union(Map{ 'v' |-> 'v' }->union(Map{ 'W' |-> 'W' }->union(Map{ 'w' |-> 'w' }->union(Map{ 'X' |-> 'X' }->union(Map{ 'x' |-> 'x' }->union(Map{ 'Y' |-> 'Y' })))))))))))))))))) ; var start_word : String := (OclFile["System.in"]).readLine() ; var new_word1 : OclAny := start_word(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var new_word2 : String := '' ; for letter : new_word1 do ( if (palindrom_letters.keys())->includes(letter) then ( new_word2 := new_word2 + palindrom_letters[letter+1] ) else ( execute ('NIE')->display() ; exit() )) ; if new_word2 = start_word then ( execute ('TAK')->display() ) else ( execute ('NIE')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isNumber(s): for i in range(len(s)): if s[i].isdigit()!=True : return False return True if __name__=="__main__" : str="6790" if isNumber(str): print("Integer") else : print("String") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var OclType["String"] : String := "6790" ; if isNumber(OclType["String"]) then ( execute ("Integer")->display() ) else ( execute ("String")->display() ) ) else skip; operation isNumber(s : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, (s)->size()-1) do ( if s[i+1]->matches("[0-9]*") /= true then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x=int(input()),list(map(int,input().split())) for i in range(n): print(min(abs(x[i-1]-x[i]),abs(x[i]-x[i-n+1])),max(x[i]-x[0],x[n-1]-x[i])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; Sequence{n,x} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),((input().split())->collect( _x | (OclType["int"])->apply(_x) ))} ; for i : Integer.subrange(0, n-1) do ( execute (Set{(x[i - 1+1] - x[i+1])->abs(), (x[i+1] - x[i - n + 1+1])->abs()}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a='AAHHMMTTUUVVWWXXYYOOMMIIbddboovvxxwwqppq' a1=[] for i in range(0,len(a),2): a1.append(a[i]+a[i+1]) s=input() t='AHMTUVWMXYOMIoxvw' x=True if len(s)% 2==1 : if s[len(s)//2]in t : for i in range(len(s)//2): if s[i]+s[len(s)-i-1]in a1 : x=True else : x=False break else : x=False elif x==True : for i in range(len(s)//2): if s[i]+s[len(s)-i-1]in a1 : x=True else : x=False break if x==True : print('TAK') else : print('NIE') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := 'AAHHMMTTUUVVWWXXYYOOMMIIbddboovvxxwwqppq' ; var a1 : Sequence := Sequence{} ; for i : Integer.subrange(0, (a)->size()-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( execute ((a[i+1] + a[i + 1+1]) : a1)) ; var s : String := (OclFile["System.in"]).readLine() ; var t : String := 'AHMTUVWMXYOMIoxvw' ; var x : boolean := true ; if (s)->size() mod 2 = 1 then ( if (t)->characters()->includes(s[(s)->size() div 2+1]) then ( for i : Integer.subrange(0, (s)->size() div 2-1) do ( if (a1)->includes(s[i+1] + s[(s)->size() - i - 1+1]) then ( x := true ) else ( x := false ; break )) ) else ( x := false ) ) else (if x = true then ( for i : Integer.subrange(0, (s)->size() div 2-1) do ( if (a1)->includes(s[i+1] + s[(s)->size() - i - 1+1]) then ( x := true ) else ( x := false ; break )) ) else skip) ; if x = true then ( execute ('TAK')->display() ) else ( execute ('NIE')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def repeated_digit(n): a=[] while n!=0 : d=n % 10 if d in a : return 0 a.append(d) n=n//10 return 1 def calculate(L,R): answer=0 for i in range(L,R+1): answer=answer+repeated_digit(i) return answer L=1 R=100 print(calculate(L,R)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; L := 1 ; R := 100 ; execute (calculate(L, R))->display(); operation repeated_digit(n : OclAny) : OclAny pre: true post: true activity: var a : Sequence := Sequence{} ; while n /= 0 do ( var d : int := n mod 10 ; if (a)->includes(d) then ( return 0 ) else skip ; execute ((d) : a) ; n := n div 10) ; return 1; operation calculate(L : OclAny, R : OclAny) : OclAny pre: true post: true activity: var answer : int := 0 ; for i : Integer.subrange(L, R + 1-1) do ( answer := answer + repeated_digit(i)) ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reverse(num): rev_num=0 while(num>0): rev_num=rev_num*10+num % 10 num=num//10 return rev_num def countReverse(arr,n): res=0 for i in range(n): for j in range(i+1,n): if(reverse(arr[i])==arr[j]): res+=1 return res if __name__=='__main__' : a=[16,61,12,21,25] n=len(a) print(countReverse(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var a : Sequence := Sequence{16}->union(Sequence{61}->union(Sequence{12}->union(Sequence{21}->union(Sequence{ 25 })))) ; n := (a)->size() ; execute (countReverse(a, n))->display() ) else skip; operation reverse(num : OclAny) : OclAny pre: true post: true activity: var rev_num : int := 0 ; while (num > 0) do ( rev_num := rev_num * 10 + num mod 10 ; num := num div 10) ; return rev_num; operation countReverse(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if (reverse(arr[i+1]) = arr[j+1]) then ( res := res + 1 ) else skip)) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def factorsListFunc(first,each_prod,n,single_result_list): if(first>n or each_prod>n): return if(each_prod==n): print(*single_result_list) return for i in range(first,n): if(i*each_prod>n): break if(n % i==0): single_result_list.append(i) factorsListFunc(i,i*each_prod,n,single_result_list) single_result_list.remove(single_result_list[-1]) def factComb(n): single_result_list=[] factorsListFunc(2,1,n,single_result_list) n=16 factComb(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 16 ; factComb(n); operation factorsListFunc(first : OclAny, each_prod : OclAny, n : OclAny, single_result_list : OclAny) pre: true post: true activity: if ((first->compareTo(n)) > 0 or (each_prod->compareTo(n)) > 0) then ( return ) else skip ; if (each_prod = n) then ( execute ((argument * (test (logical_test (comparison (expr (atom (name single_result_list))))))))->display() ; return ) else skip ; for i : Integer.subrange(first, n-1) do ( if ((i * each_prod->compareTo(n)) > 0) then ( break ) else skip ; if (n mod i = 0) then ( execute ((i) : single_result_list) ; factorsListFunc(i, i * each_prod, n, single_result_list) ; execute ((single_result_list->last()) /: single_result_list) ) else skip); operation factComb(n : OclAny) pre: true post: true activity: single_result_list := Sequence{} ; factorsListFunc(2, 1, n, single_result_list); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a,b=map(int,input().split()) c=int(input()) topping=[] for _ in range(n): d=int(input()) topping.append(d) topping.sort(reverse=True) ans=c//a total=c for i,t in enumerate(topping): total+=t cal=total//(a+(i+1)*b) if ans<=cal : ans=cal else : break print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var topping : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var d : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((d) : topping)) ; topping := topping->sort() ; var ans : int := c div a ; var total : int := c ; for _tuple : Integer.subrange(1, (topping)->size())->collect( _indx | Sequence{_indx-1, (topping)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); total := total + t ; var cal : int := total div (a + (i + 1) * b) ; if (ans->compareTo(cal)) <= 0 then ( ans := cal ) else ( break )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): t_n=int(input()) price_a,price_b=map(int,input().split()) cal_a=int(input()) t_c=sorted([int(input())for _ in range(t_n)],reverse=True) cpd_a=cal_a/price_a cal_sum=cal_a price_sum=price_a b_sum=0 for i in range(t_n): b_sum+=t_c[i] new_cpd_a=(cal_a+b_sum)/(price_a+(i+1)*price_b) if new_cpd_a>cpd_a : cal_sum+=t_c[i] price_sum+=price_b cpd_a=new_cpd_a print(int(cal_sum/price_sum)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var t_n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var price_a : OclAny := null; var price_b : OclAny := null; Sequence{price_a,price_b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cal_a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t_c : Sequence := Integer.subrange(0, t_n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var cpd_a : double := cal_a / price_a ; var cal_sum : int := cal_a ; var price_sum : OclAny := price_a ; var b_sum : int := 0 ; for i : Integer.subrange(0, t_n-1) do ( b_sum := b_sum + t_c[i+1] ; var new_cpd_a : double := (cal_a + b_sum) / (price_a + (i + 1) * price_b) ; if (new_cpd_a->compareTo(cpd_a)) > 0 then ( cal_sum := cal_sum + t_c[i+1] ; price_sum := price_sum + price_b ; cpd_a := new_cpd_a ) else skip) ; execute (("" + ((cal_sum / price_sum)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin from collections import deque input=stdin.readline from collections import namedtuple item=namedtuple('item',['cal','pri']) def Cond(x,n,items,pizza): y=[0]*n for i in range(n): y[i]=items[i].cal-x*items[i].pri y.sort(reverse=True) total=pizza.cal-x*pizza.pri for i in range(n): if y[i]>0 : total+=y[i] else : break return total>=0 def main(args): N=int(input()) A,B=map(int,input().split()) C=int(input()) toppings=[] for i in range(N): toppings.append(item(int(input()),B)) pizza=item(C,A) lb=0 ub=1e5 for i in range(100): mid=(lb+ub)/2 if Cond(mid,N,toppings,pizza): lb=mid else : ub=mid print(int(ub)) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := stdin.readline ; skip ; var item : OclAny := namedtuple('item', Sequence{'cal'}->union(Sequence{ 'pri' })) ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation Cond(x : OclAny, n : OclAny, items : OclAny, pizza : OclAny) : OclAny pre: true post: true activity: var y : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( y[i+1] := items[i+1].cal - x * items[i+1].pri) ; y := y->sort() ; var total : double := pizza.cal - x * pizza.pri ; for i : Integer.subrange(0, n-1) do ( if y[i+1] > 0 then ( total := total + y[i+1] ) else ( break )) ; return total >= 0; operation main(args : OclAny) pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var C : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var toppings : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( execute ((item(("" + (((OclFile["System.in"]).readLine())))->toInteger(), B)) : toppings)) ; pizza := item(C, A) ; var lb : int := 0 ; var ub : double := ("1e5")->toReal() ; for i : Integer.subrange(0, 100-1) do ( var mid : double := (lb + ub) / 2 ; if Cond(mid, N, toppings, pizza) then ( lb := mid ) else ( ub := mid )) ; execute (("" + ((ub)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate num=int(input()) a,b=[int(x)for x in input().split()] p=int(input()) T=[] C=[] for _ in range(num): T.append(int(input())) C.append(int(p/a)) T.sort(reverse=True) for i,c in enumerate(accumulate(T),start=1): C.append(int((p+c)/(a+i*b))) print(sorted(C,reverse=True)[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var p : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var T : Sequence := Sequence{} ; var C : Sequence := Sequence{} ; for _anon : Integer.subrange(0, num-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : T)) ; execute ((("" + ((p / a)))->toInteger()) : C) ; T := T->sort() ; for _tuple : Integer.subrange(1, (accumulate(T), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->size())->collect( _indx | Sequence{_indx-1, (accumulate(T), (argument (test (logical_test (comparison (expr (atom (name start)))))) = (test (logical_test (comparison (expr (atom (number (integer 1)))))))))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); execute ((("" + (((p + c) / (a + i * b))))->toInteger()) : C)) ; execute (sorted(C, (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True))))))))->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) p_cost,t_cost=map(int,input().split()) p_cal=int(input()) t_cal=[] for i in range(n): t_cal.append(int(input())) t_cal.sort(reverse=True) total_cost=p_cost total_cal=p_cal max_total_cal_par_doll=total_cal//total_cost for i in range(n): total_cost+=t_cost total_cal+=t_cal[i] total_cal_par_doll=total_cal//total_cost if max_total_cal_par_dolltoInteger() ; var p_cost : OclAny := null; var t_cost : OclAny := null; Sequence{p_cost,t_cost} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var p_cal : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var t_cal : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : t_cal)) ; t_cal := t_cal->sort() ; var total_cost : OclAny := p_cost ; var total_cal : int := p_cal ; var max_total_cal_par_doll : int := total_cal div total_cost ; for i : Integer.subrange(0, n-1) do ( total_cost := total_cost + t_cost ; total_cal := total_cal + t_cal[i+1] ; var total_cal_par_doll : int := total_cal div total_cost ; if (max_total_cal_par_doll->compareTo(total_cal div total_cost)) < 0 then ( max_total_cal_par_doll := total_cal div total_cost ) else skip) ; execute (max_total_cal_par_doll)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=input().split() a1=int(input()) b1=input().split() z=0 c=[] c1=[] for i in range(a): c.append(0) b[i]=int(b[i]) for i in range(a1): c1.append(0) b1[i]=int(b1[i]) b=sorted(b) b1=sorted(b1) if a>=a1 : for i in range(len(b)): b[i]=int(b[i]) for j in range(len(b1)): b1[j]=int(b1[j]) if abs(b1[j]-b[i])<=1 and c[j]==0 : z+=1 c[j]=1 break else : for i in range(len(b1)): b1[i]=int(b1[i]) for j in range(len(b)): b[j]=int(b[j]) if abs(b[j]-b1[i])<=1 and c1[j]==0 : z+=1 c1[j]=1 break print(z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : OclAny := input().split() ; var a1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b1 : OclAny := input().split() ; var z : int := 0 ; var c : Sequence := Sequence{} ; var c1 : Sequence := Sequence{} ; for i : Integer.subrange(0, a-1) do ( execute ((0) : c) ; b[i+1] := ("" + ((b[i+1])))->toInteger()) ; for i : Integer.subrange(0, a1-1) do ( execute ((0) : c1) ; b1[i+1] := ("" + ((b1[i+1])))->toInteger()) ; b := b->sort() ; b1 := b1->sort() ; if (a->compareTo(a1)) >= 0 then ( for i : Integer.subrange(0, (b)->size()-1) do ( b[i+1] := ("" + ((b[i+1])))->toInteger() ; for j : Integer.subrange(0, (b1)->size()-1) do ( b1[j+1] := ("" + ((b1[j+1])))->toInteger() ; if (b1[j+1] - b[i+1])->abs() <= 1 & c[j+1] = 0 then ( z := z + 1 ; c[j+1] := 1 ; break ) else skip)) ) else ( for i : Integer.subrange(0, (b1)->size()-1) do ( b1[i+1] := ("" + ((b1[i+1])))->toInteger() ; for j : Integer.subrange(0, (b)->size()-1) do ( b[j+1] := ("" + ((b[j+1])))->toInteger() ; if (b[j+1] - b1[i+1])->abs() <= 1 & c1[j+1] = 0 then ( z := z + 1 ; c1[j+1] := 1 ; break ) else skip)) ) ; execute (z)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque import sys,heapq,bisect,math,itertools,string,queue,datetime sys.setrecursionlimit(10**8) INF=float('inf') mod=10**9+7 def inpl(): return list(map(int,input().split())) def inpls(): return list(input().split()) N=int(input()) def dsum(x): return sum(map(int,list(str(x)))) ans=INF for a in range(1,N): b=N-a ans=min(ans,dsum(a)+dsum(b)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(8)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; skip ; var ans : OclAny := INF ; for a : Integer.subrange(1, N-1) do ( var b : double := N - a ; ans := Set{ans, dsum(a) + dsum(b)}->min()) ; execute (ans)->display(); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inpls() : OclAny pre: true post: true activity: return (input().split()); operation dsum(x : OclAny) : OclAny pre: true post: true activity: return (((("" + ((x))))->characters())->collect( _x | (OclType["int"])->apply(_x) ))->sum(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def power(x,y,p): res=1 ; x=x % p ; while(y>0): if(y % 2==1): res=(res*x)% p ; y=y>>1 ; x=(x*x)% p ; return res ; L=2 ; P=pow(10,9); ans=power(325,L,P); print(ans); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var L : int := 2; var P : double := (10)->pow(9); ; var ans : OclAny := power(325, L, P); ; execute (ans)->display();; operation power(x : OclAny, y : OclAny, p : OclAny) pre: true post: true activity: var res : int := 1; ; x := x mod p; ; while (y > 0) do ( if (y mod 2 = 1) then ( res := (res * x) mod p; ) else skip ; y := y /(2->pow(1)); ; x := (x * x) mod p;) ; return res;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) boys=sorted(list(map(int,input().split()))) m=int(input()) girls=sorted(list(map(int,input().split()))) result=0 for i in range(len(boys)): for j in range(len(girls)): if abs(boys[i]-girls[j])<=1 : girls[j]=1000 result+=1 break print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var boys : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var girls : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var result : int := 0 ; for i : Integer.subrange(0, (boys)->size()-1) do ( for j : Integer.subrange(0, (girls)->size()-1) do ( if (boys[i+1] - girls[j+1])->abs() <= 1 then ( girls[j+1] := 1000 ; result := result + 1 ; break ) else skip)) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) sn=[int(x)for x in input().split()] m=int(input()) sm=[int(y)for y in input().split()] sn1=sorted(list(sn)) sm1=sorted(list(sm)) count=0 for i in range(len(sn1)): for j in range(len(sm1)): if abs(sn1[i]-sm1[j])<=1 : count+=1 sn1[i]=200 sm1[j]=200 break print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sn : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sm : Sequence := input().split()->select(y | true)->collect(y | (("" + ((y)))->toInteger())) ; var sn1 : Sequence := (sn)->sort() ; var sm1 : Sequence := (sm)->sort() ; var count : int := 0 ; for i : Integer.subrange(0, (sn1)->size()-1) do ( for j : Integer.subrange(0, (sm1)->size()-1) do ( if (sn1[i+1] - sm1[j+1])->abs() <= 1 then ( count := count + 1 ; sn1[i+1] := 200 ; sm1[j+1] := 200 ; break ) else skip)) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) m=int(input()) b=list(map(int,input().split())) a.sort() b.sort() i=0 count=0 while(i<(n if n>m else m))and i<=len(a)-1 : k=0 while(k<(n if n>m else m))and k<=len(b)-1 : if abs(a[i]-b[k])<=1 : del a[i] del b[k] count+=1 i-=1 k-=1 break k+=1 i+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; b := b->sort() ; var i : int := 0 ; var count : int := 0 ; while ((i->compareTo((if (n->compareTo(m)) > 0 then n else m endif))) < 0) & (i->compareTo((a)->size() - 1)) <= 0 do ( var k : int := 0 ; while ((k->compareTo((if (n->compareTo(m)) > 0 then n else m endif))) < 0) & (k->compareTo((b)->size() - 1)) <= 0 do ( if (a[i+1] - b[k+1])->abs() <= 1 then ( execute (a[i+1])->isDeleted() ; execute (b[k+1])->isDeleted() ; count := count + 1 ; i := i - 1 ; k := k - 1 ; break ) else skip ; k := k + 1) ; i := i + 1) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) m=int(input()) b=list(map(int,input().split())) a.sort() b.sort() res=0 for i in range(n): for j in range(m): if abs(a[i]-b[j])<=1 : b[j]=1000 res+=1 break print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; b := b->sort() ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if (a[i+1] - b[j+1])->abs() <= 1 then ( b[j+1] := 1000 ; res := res + 1 ; break ) else skip)) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) c=a+b a=str(a) b=str(b) c=str(c) fa=int(a[0]) fb=int(b[0]) fc=int(c[0]) for i in a[1 :]: if i!='0' : fa*=10 fa+=int(i) for y in b[1 :]: if y!='0' : fb*=10 fb+=int(y) for u in c[1 :]: if u!='0' : fc*=10 fc+=int(u) if fa+fb==fc : print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := a + b ; a := ("" + ((a))) ; b := ("" + ((b))) ; c := ("" + ((c))) ; var fa : int := ("" + ((a->first())))->toInteger() ; var fb : int := ("" + ((b->first())))->toInteger() ; var fc : int := ("" + ((c->first())))->toInteger() ; for i : a->tail() do ( if i /= '0' then ( fa := fa * 10 ; fa := fa + ("" + ((i)))->toInteger() ) else skip) ; for y : b->tail() do ( if y /= '0' then ( fb := fb * 10 ; fb := fb + ("" + ((y)))->toInteger() ) else skip) ; for u : c->tail() do ( if u /= '0' then ( fc := fc * 10 ; fc := fc + ("" + ((u)))->toInteger() ) else skip) ; if fa + fb = fc then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) c1=a+b a=int(str(a).replace("0","")) b=int(str(b).replace("0","")) c1=int(str(c1).replace("0","")) c2=a+b if c1==c2 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c1 : int := a + b ; a := ("" + ((OclType["String"](a).replace("0", ""))))->toInteger() ; b := ("" + ((OclType["String"](b).replace("0", ""))))->toInteger() ; c1 := ("" + ((OclType["String"](c1).replace("0", ""))))->toInteger() ; var c2 : int := a + b ; if c1 = c2 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) for i in str(a): c=str(a).replace('0','') for i in str(b): d=str(b).replace('0','') sum=a+b for i in str(sum): e=str(sum).replace('0','') if int(c)+int(d)==int(e): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : ("" + ((a))) do ( var c : OclAny := OclType["String"](a).replace('0', '')) ; for i : ("" + ((b))) do ( var d : OclAny := OclType["String"](b).replace('0', '')) ; var sum : int := a + b ; for i : ("" + ((sum))) do ( var e : OclAny := OclType["String"](sum).replace('0', '')) ; if ("" + ((c)))->toInteger() + ("" + ((d)))->toInteger() = ("" + ((e)))->toInteger() then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) b=int(input()) c=a+b a=str(a) b=str(b) c=str(c) a1="" b1="" c12="" for i in range(len(a)): if a[i]!="0" : a1+=a[i] for i in range(len(b)): if b[i]!="0" : b1+=b[i] for i in range(len(c)): if c[i]!="0" : c12+=c[i] c1=int(a1)+int(b1) if int(c12)==c1 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var b : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : int := a + b ; a := ("" + ((a))) ; b := ("" + ((b))) ; c := ("" + ((c))) ; var a1 : String := "" ; var b1 : String := "" ; var c12 : String := "" ; for i : Integer.subrange(0, (a)->size()-1) do ( if a[i+1] /= "0" then ( a1 := a1 + a[i+1] ) else skip) ; for i : Integer.subrange(0, (b)->size()-1) do ( if b[i+1] /= "0" then ( b1 := b1 + b[i+1] ) else skip) ; for i : Integer.subrange(0, (c)->size()-1) do ( if c[i+1] /= "0" then ( c12 := c12 + c[i+1] ) else skip) ; var c1 : int := ("" + ((a1)))->toInteger() + ("" + ((b1)))->toInteger() ; if ("" + ((c12)))->toInteger() = c1 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) k=int(input()) p=n+k a=b=c='' n=str(n) for i in n : if i!='0' : a+=i k=str(k) for i in k : if i!='0' : b+=i q=str(p) for i in q : if i!='0' : c+=i if int(a)+int(b)==int(c): print('YES') else : print('NO') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : int := n + k ; a := a(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name c)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom '')))))))) ; n := ("" + ((n))) ; for i : n do ( if i /= '0' then ( a := a + i ) else skip) ; k := ("" + ((k))) ; for i : k do ( if i /= '0' then ( b := b + i ) else skip) ; var q : String := ("" + ((p))) ; for i : q->characters() do ( if i /= '0' then ( c := c + i ) else skip) ; if ("" + ((a)))->toInteger() + ("" + ((b)))->toInteger() = ("" + ((c)))->toInteger() then ( execute ('YES')->display() ) else ( execute ('NO')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() a=["10","100","1000","10000","100000"] new=sum(list(map(int,n))) if n in a : print(10) else : print(new) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var a : Sequence := Sequence{"10"}->union(Sequence{"100"}->union(Sequence{"1000"}->union(Sequence{"10000"}->union(Sequence{ "100000" })))) ; var new : OclAny := (((n)->collect( _x | (OclType["int"])->apply(_x) )))->sum() ; if (a)->includes(n) then ( execute (10)->display() ) else ( execute (new)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import* c,d=map(int,input().split()) n,m=map(int,input().split()) k=int(input()) res=n*m-k if res<=0 : print(0) exit() x=100000 dp=[0]*x for i in range(c,x): dp[i]=max(dp[i],dp[i-c]+n) for i in range(d,x): dp[i]=max(dp[i],dp[i-d]+1) for i in range(x): if(dp[i]>=res): print(i) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : double := n * m - k ; if res <= 0 then ( execute (0)->display() ; exit() ) else skip ; var x : int := 100000 ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, x) ; for i : Integer.subrange(c, x-1) do ( dp[i+1] := Set{dp[i+1], dp[i - c+1] + n}->max()) ; for i : Integer.subrange(d, x-1) do ( dp[i+1] := Set{dp[i+1], dp[i - d+1] + 1}->max()) ; for i : Integer.subrange(0, x-1) do ( if ((dp[i+1]->compareTo(res)) >= 0) then ( execute (i)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def main(): n,m=map(int,input().split()) data=[] for _ in range(m): k,f=map(int,input().split()) data.append((k,f)) candidates=[] for i in range(1,101): for elem in data : k,f=elem if(k-1)//i!=f-1 : break else : candidates.append(i) answers=[] for candidate in candidates : answers.append(math.ceil(n/candidate)) flag=False for i in range(len(answers)-1): if answers[i]!=answers[i+1]: flag=True if flag : print(-1) else : print(answers[0]) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var data : Sequence := Sequence{} ; for _anon : Integer.subrange(0, m-1) do ( var k : OclAny := null; var f : OclAny := null; Sequence{k,f} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{k, f}) : data)) ; var candidates : Sequence := Sequence{} ; for i : Integer.subrange(1, 101-1) do ((compound_stmt for (exprlist (expr (atom (name elem)))) in (testlist (test (logical_test (comparison (expr (atom (name data))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name k)))))) , (test (logical_test (comparison (expr (atom (name f))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name elem)))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name k))) - (expr (atom (number (integer 1))))))))) ))) // (expr (atom (name i))))) != (comparison (expr (expr (atom (name f))) - (expr (atom (number (integer 1))))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name candidates)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))))))))))))) ; var answers : Sequence := Sequence{} ; for candidate : candidates do ( execute (((n / candidate)->ceil()) : answers)) ; var flag : boolean := false ; for i : Integer.subrange(0, (answers)->size() - 1-1) do ( if answers[i+1] /= answers[i + 1+1] then ( flag := true ) else skip) ; if flag then ( execute (-1)->display() ) else ( execute (answers->first())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math c,d=map(int,input().split()) n,m=map(int,input().split()) k=int(input()) if k>=n*m : print(0) exit() left=n*m-k print(min(math.ceil(left/n)*c,(left//n)*c+(left % n)*d,left*d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (k->compareTo(n * m)) >= 0 then ( execute (0)->display() ; exit() ) else skip ; var left : double := n * m - k ; execute (Set{(left / n)->ceil() * c, (left div n) * c + (left mod n) * d, left * d}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,sys,atexit from io import BytesIO,StringIO input=BytesIO(os.read(0,os.fstat(0).st_size)).readline _OUTPUT_BUFFER=StringIO() sys.stdout=_OUTPUT_BUFFER @ atexit.register def write(): sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) c,d=map(int,input().split()) n,m=map(int,input().split()) k=int(input()) require=n*m-k ans=999999999 for i in range(10000): for j in range(10000): if i*n+j>=require : ans=min(ans,c*i+d*j) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := BytesIO(os.readAll()).readline ; var _OUTPUT_BUFFER : OclAny := StringIO() ; OclFile["System.out"] := _OUTPUT_BUFFER ; (compound_stmt (decorator @ (dotted_name (dotted_name (name atexit)) . (name register))) (funcdef def (name write) ( ) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name __stdout__)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name _OUTPUT_BUFFER)) (trailer . (name getvalue) (arguments ( ))))))))) ))))))))))))))) ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var require : double := n * m - k ; var ans : int := 999999999 ; for i : Integer.subrange(0, 10000-1) do ( for j : Integer.subrange(0, 10000-1) do ( if (i * n + j->compareTo(require)) >= 0 then ( ans := Set{ans, c * i + d * j}->min() ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c,d=map(int,input().split()) n,m=map(int,input().split()) k=int(input()) r=n*m-k if r<=0 : print(0) exit() cnt=0 x=min(d*n,c) while r>=n : r-=n cnt+=x if r==0 : print(cnt) exit() y=min(r*d,c) print(cnt+y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var r : double := n * m - k ; if r <= 0 then ( execute (0)->display() ; exit() ) else skip ; var cnt : int := 0 ; var x : OclAny := Set{d * n, c}->min() ; while (r->compareTo(n)) >= 0 do ( r := r - n ; cnt := cnt + x) ; if r = 0 then ( execute (cnt)->display() ; exit() ) else skip ; var y : OclAny := Set{r * d, c}->min() ; execute (cnt + y)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import* c,d=map(int,input().split()) n,m=map(int,input().split()) k=int(input()) res=n*m-k if res<=0 : print(0) exit() x=100000 dp=[0]*x for i in range(c,x): dp[i]=max(dp[i],dp[i-c]+n) for i in range(d,x): dp[i]=max(dp[i],dp[i-d]+1) for i in range(x): if(dp[i]>=res): print(i) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var c : OclAny := null; var d : OclAny := null; Sequence{c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : double := n * m - k ; if res <= 0 then ( execute (0)->display() ; exit() ) else skip ; var x : int := 100000 ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, x) ; for i : Integer.subrange(c, x-1) do ( dp[i+1] := Set{dp[i+1], dp[i - c+1] + n}->max()) ; for i : Integer.subrange(d, x-1) do ( dp[i+1] := Set{dp[i+1], dp[i - d+1] + 1}->max()) ; for i : Integer.subrange(0, x-1) do ( if ((dp[i+1]->compareTo(res)) >= 0) then ( execute (i)->display() ; break ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def findkth(n,k): v=[] p=int(sqrt(n))+1 for i in range(1,p,1): if(n % i==0): v.append(i) if(i!=sqrt(n)): v.append(n/i); v.sort(reverse=False) if(k>len(v)): print("Doesn't Exist") else : print(v[k-1]) if __name__=='__main__' : n=15 k=2 findkth(n,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( n := 15 ; k := 2 ; findkth(n, k) ) else skip; operation findkth(n : OclAny, k : OclAny) pre: true post: true activity: var v : Sequence := Sequence{} ; var p : int := ("" + ((sqrt(n))))->toInteger() + 1 ; for i : Integer.subrange(1, p-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( if (n mod i = 0) then ( execute ((i) : v) ; if (i /= sqrt(n)) then ( execute ((n / i) : v); ) else skip ) else skip) ; v := v->sort() ; if ((k->compareTo((v)->size())) > 0) then ( execute ("Doesn't Exist")->display() ) else ( execute (v[k - 1+1])->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def numUniqueEmails(self,emails): email_set=set() for email in emails : elements=email.split('@') email_set.add(elements[0].split('+')[0].replace('.','')+elements[1]) return len(email_set) ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation numUniqueEmails(emails : OclAny) : OclAny pre: true post: true activity: var email_set : Set := Set{}->union(()) ; for email : emails do ( var elements : OclAny := email.split('@') ; execute ((elements->first().split('+')->first().replace('.', '') + elements[1+1]) : email_set)) ; return (email_set)->size(); } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def extrapolate(d,x): y=(d[0][1]+(x-d[0][0])/(d[1][0]-d[0][0])*(d[1][1]-d[0][1])); return y ; d=[[1.2,2.7],[1.4,3.1]]; x=2.1 ; print("Value of y at x=2.1 :",extrapolate(d,x)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; d := Sequence{Sequence{1.2}->union(Sequence{ 2.7 })}->union(Sequence{ Sequence{1.4}->union(Sequence{ 3.1 }) }); ; x := 2.1; ; execute ("Value of y at x=2.1 :")->display();; operation extrapolate(d : OclAny, x : OclAny) pre: true post: true activity: var y : OclAny := (d->first()[1+1] + (x - d->first()->first()) / (d[1+1]->first() - d->first()->first()) * (d[1+1][1+1] - d->first()[1+1])); ; return y;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairsWithDiffK(arr,n,k): count=0 for i in range(0,n): for j in range(i+1,n): if arr[i]-arr[j]==k or arr[j]-arr[i]==k : count+=1 return count arr=[1,5,3,4,2] n=len(arr) k=3 print("Count of pairs with given diff is ",countPairsWithDiffK(arr,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{5}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 2 })))) ; n := (arr)->size() ; k := 3 ; execute ("Count of pairs with given diff is ")->display(); operation countPairsWithDiffK(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if arr[i+1] - arr[j+1] = k or arr[j+1] - arr[i+1] = k then ( count := count + 1 ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") while True : n=int(input()) if n==0 : break print(oct(n)[2 :].replace('7','9').replace('6','8').replace('5','7').replace('4','5')) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var PYDEV : OclAny := os.environ.get('PYDEV') ; if PYDEV = "True" then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("sample-input.txt")) ) else skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; execute (oct(n).subrange(2+1).replace('7', '9').replace('6', '8').replace('5', '7').replace('4', '5'))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys n=int(input()) ans=0 flag=0 while n % 10==0 : n=n//10 if n==1 : print(10) sys.exit() s=str(n) for i in range(len(s)): ans+=int(s[i]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; var flag : int := 0 ; while n mod 10 = 0 do ( n := n div 10) ; if n = 1 then ( execute (10)->display() ; sys.exit() ) else skip ; var s : String := ("" + ((n))) ; for i : Integer.subrange(0, (s)->size()-1) do ( ans := ans + ("" + ((s[i+1])))->toInteger()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout from os import path rd=lambda : stdin.readline().strip() wr=stdout.write if(path.exists('input.txt')): stdin=open("input.txt","r") import time,math x=int(rd()) capacity=0 roomCount=0 amr=dict() mx=-1 prev=-1 for _ in range(x): sign,id=map(str,rd().split()) if sign=='+' : roomCount+=1 capacity=max(capacity,roomCount) else : if id in amr : roomCount-=1 else : capacity+=1 amr[id]=1 print(capacity) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var rd : Function := lambda $$ : OclAny in (stdin.readLine()->trim()) ; var wr : OclAny := stdout.write ; if (path.exists('input.txt')) then ( var stdin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("input.txt")) ) else skip ; skip ; var x : int := ("" + ((rd->apply())))->toInteger() ; var capacity : int := 0 ; var roomCount : int := 0 ; var amr : Map := (arguments ( )) ; var mx : int := -1 ; var prev : int := -1 ; for _anon : Integer.subrange(0, x-1) do ( var sign : OclAny := null; var id : OclAny := null; Sequence{sign,id} := (rd->apply().split())->collect( _x | (OclType["String"])->apply(_x) ) ; if sign = '+' then ( roomCount := roomCount + 1 ; capacity := Set{capacity, roomCount}->max() ) else ( if (amr)->includes(id) then ( roomCount := roomCount - 1 ) else ( capacity := capacity + 1 ) ) ; amr[id+1] := 1) ; execute (capacity)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,l,m,a=int(input()),[0]*1000000,0,[] for _ in range(n): a.append(input()) for i in range(n): if a[i][0]=='+' : l[int(a[i][2 :])-1]=1 elif not l[int(a[i][2 :])-1]: m+=1 ans=m for i in range(n): if a[i][0]=='+' : m+=1 ; ans=max(m,ans) else : m-=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; var m : OclAny := null; var a : OclAny := null; Sequence{n,l,m,a} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),MatrixLib.elementwiseMult(Sequence{ 0 }, 1000000),0,Sequence{}} ; for _anon : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : a)) ; for i : Integer.subrange(0, n-1) do ( if a[i+1]->first() = '+' then ( l[("" + ((a[i+1].subrange(2+1))))->toInteger() - 1+1] := 1 ) else (if not(l[("" + ((a[i+1].subrange(2+1))))->toInteger() - 1+1]) then ( m := m + 1 ) else skip)) ; var ans : OclAny := m ; for i : Integer.subrange(0, n-1) do ( if a[i+1]->first() = '+' then ( m := m + 1; ans := Set{m, ans}->max() ) else ( m := m - 1 )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=1 for qwe in range(t): n,m=map(int,input().split()) listt=[] for i in range(m): k,f1=map(int,input().split()) ttup=(k,f1) listt.append(ttup) listt.sort(key=lambda a :(a[1],a[0])) listtans=set() for kol in range(1,101): for i in listt : if not(i[1]*kol>=i[0]and i[0]>i[1]*kol-kol): break else : listtans.add((n+kol-1)//kol) if len(listtans)==1 : print(*listtans) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := 1 ; for qwe : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var listt : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var k : OclAny := null; var f1 : OclAny := null; Sequence{k,f1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ttup : OclAny := Sequence{k, f1} ; execute ((ttup) : listt)) ; listt := listt->sort() ; var listtans : Set := Set{}->union(()) ; for kol : Integer.subrange(1, 101-1) do ((compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name listt))))))) : (suite (stmt (compound_stmt if (test (logical_test not (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (expr (atom (name i)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) * (expr (atom (name kol))))) >= (comparison (expr (atom (name i)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))) and (logical_test (comparison (comparison (expr (atom (name i)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) > (comparison (expr (expr (expr (atom (name i)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) * (expr (atom (name kol)))) - (expr (atom (name kol)))))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name listtans)) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name n))) + (expr (atom (name kol)))) - (expr (atom (number (integer 1))))))))) ))) // (expr (atom (name kol))))))))) )))))))))))))))) ; if (listtans)->size() = 1 then ( execute ((argument * (test (logical_test (comparison (expr (atom (name listtans))))))))->display() ) else ( execute (-1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,l,m,a=int(input()),[0]*1000000,0,[] for _ in range(n): a.append(input()) for i in range(n): v=int(a[i][2 :]) if a[i][0]=='+' : l[v-1]=1 elif not l[v-1]: m+=1 ans=m for i in range(n): if a[i][0]=='+' : m+=1 ; ans=max(m,ans) else : m-=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var l : OclAny := null; var m : OclAny := null; var a : OclAny := null; Sequence{n,l,m,a} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),MatrixLib.elementwiseMult(Sequence{ 0 }, 1000000),0,Sequence{}} ; for _anon : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : a)) ; for i : Integer.subrange(0, n-1) do ( var v : int := ("" + ((a[i+1].subrange(2+1))))->toInteger() ; if a[i+1]->first() = '+' then ( l[v - 1+1] := 1 ) else (if not(l[v - 1+1]) then ( m := m + 1 ) else skip)) ; var ans : OclAny := m ; for i : Integer.subrange(0, n-1) do ( if a[i+1]->first() = '+' then ( m := m + 1; ans := Set{m, ans}->max() ) else ( m := m - 1 )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- in_persons=0 total_cap=0 entered=[] for i in range(int(input())): entry=input() if(entry[0]=='+'): in_persons+=1 entered.append(int(entry[2 :])) elif(entry[0]=='-'): if(int(entry[2 :])not in entered): total_cap+=1 else : in_persons-=1 total_cap=max(total_cap,in_persons) print(total_cap) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var in_persons : int := 0 ; var total_cap : int := 0 ; var entered : Sequence := Sequence{} ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var entry : String := (OclFile["System.in"]).readLine() ; if (entry->first() = '+') then ( in_persons := in_persons + 1 ; execute ((("" + ((entry.subrange(2+1))))->toInteger()) : entered) ) else (if (entry->first() = '-') then ( if ((entered)->excludes(("" + ((entry.subrange(2+1))))->toInteger())) then ( total_cap := total_cap + 1 ) else ( in_persons := in_persons - 1 ) ) else skip) ; total_cap := Set{total_cap, in_persons}->max()) ; execute (total_cap)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) mp=dict() ans,cur=0,0 for i in range(n): c,x=[_ for _ in input().split()] x=int(x) if c=='-' : if mp.get(x)==True : cur-=1 mp[x]=False elif mp.get(x)is None : ans+=1 mp[x]=False elif c=='+' : cur+=1 mp[x]=True ans=max(ans,cur) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mp : Map := (arguments ( )) ; var ans : OclAny := null; var cur : OclAny := null; Sequence{ans,cur} := Sequence{0,0} ; for i : Integer.subrange(0, n-1) do ( var c : OclAny := null; var x : OclAny := null; Sequence{c,x} := input().split()->select(_anon | true)->collect(_anon | (_anon)) ; var x : int := ("" + ((x)))->toInteger() ; if c = '-' then ( if mp.get(x) = true then ( cur := cur - 1 ; mp[x+1] := false ) else (if mp.get(x) <>= null then ( ans := ans + 1 ; mp[x+1] := false ) else skip) ) else (if c = '+' then ( cur := cur + 1 ; mp[x+1] := true ) else skip) ; var ans : OclAny := Set{ans, cur}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def max1(r): z=[i for i in range(len(r))if r[i]==1] if(z==[]): return 0 else : return max(z) def solve(inp): inp=[max1(s)for s in inp] ans=0 for i in range(len(inp)): z=min([q for q in range(len(inp))if q>=i and inp[q]<=i]) r=list(range(i,z)) r.reverse() for j in r : inp[j],inp[j+1]=inp[j+1],inp[j] ans+=1 return ans rdln=sys.stdin.readline T=int(rdln()) for t in range(T): N=int(rdln()) print("Case #",t+1,": ",solve([[int(c)for c in rdln().strip()]for w in range(N)]),sep="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var rdln : OclAny := (OclFile["System.in"]).readline ; var T : int := ("" + ((rdln())))->toInteger() ; for t : Integer.subrange(0, T-1) do ( var N : int := ("" + ((rdln())))->toInteger() ; execute ("Case #")->display()); operation max1(r : OclAny) : OclAny pre: true post: true activity: var z : Sequence := Integer.subrange(0, (r)->size()-1)->select(i | r[i+1] = 1)->collect(i | (i)) ; if (z = Sequence{}) then ( return 0 ) else ( return (z)->max() ); operation solve(inp : OclAny) : OclAny pre: true post: true activity: inp := inp->select(s | true)->collect(s | (max1(s))) ; var ans : int := 0 ; for i : Integer.subrange(0, (inp)->size()-1) do ( z := (Integer.subrange(0, (inp)->size()-1)->select(q | (q->compareTo(i)) >= 0 & (inp[q+1]->compareTo(i)) <= 0)->collect(q | (q)))->min() ; r := (Integer.subrange(i, z-1)) ; r := r->reverse() ; for j : r do ( var inp[j+1] : OclAny := null; var inp[j + 1+1] : OclAny := null; Sequence{inp[j+1],inp[j + 1+1]} := Sequence{inp[j + 1+1],inp[j+1]} ; ans := ans + 1)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def make_swaps(matrix,i,j): moves=0 while j>i : matrix[j],matrix[j-1]=matrix[j-1],matrix[j] j-=1 moves+=1 return moves def last_one(row): positions=[pos for pos,num in enumerate(row)if num=='1'] return 0 if len(positions)==0 else max(positions) def solve(matrix): moves=0 N=len(matrix) for i in range(0,N): for j in range(i,N): if last_one(matrix[j])<=i : moves+=make_swaps(matrix,i,j) break return moves def main(): file=open("input.in") tests=int(file.readline()) for case in range(1,tests+1): N=int(file.readline()) matrix=[file.readline().strip()for i in range(N)] print("Case #",case,": ",solve(matrix),sep="") if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation make_swaps(matrix : OclAny, i : OclAny, j : OclAny) : OclAny pre: true post: true activity: var moves : int := 0 ; while (j->compareTo(i)) > 0 do ( var matrix[j+1] : OclAny := null; var matrix[j - 1+1] : OclAny := null; Sequence{matrix[j+1],matrix[j - 1+1]} := Sequence{matrix[j - 1+1],matrix[j+1]} ; j := j - 1 ; moves := moves + 1) ; return moves; operation last_one(row : OclAny) : OclAny pre: true post: true activity: var positions : Sequence := Integer.subrange(1, (row)->size())->collect( _indx | Sequence{_indx-1, (row)->at(_indx)} )->select(_tuple | let pos : OclAny = _tuple->at(1) in let num : OclAny = _tuple->at(2) in num = '1')->collect(_tuple | let pos : OclAny = _tuple->at(1) in let num : OclAny = _tuple->at(2) in (pos)) ; return if (positions)->size() = 0 then 0 else (positions)->max() endif; operation solve(matrix : OclAny) : OclAny pre: true post: true activity: moves := 0 ; var N : int := (matrix)->size() ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(i, N-1) do ( if (last_one(matrix[j+1])->compareTo(i)) <= 0 then ( moves := moves + make_swaps(matrix, i, j) ; break ) else skip)) ; return moves; operation main() pre: true post: true activity: var file : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("input.in")) ; var tests : int := ("" + ((file.readLine())))->toInteger() ; for case : Integer.subrange(1, tests + 1-1) do ( N := ("" + ((file.readLine())))->toInteger() ; matrix := Integer.subrange(0, N-1)->select(i | true)->collect(i | (file.readLine()->trim())) ; execute ("Case #")->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Swap(arr,i): arr[i-1],arr[i]=arr[i],arr[i-1] for tc in range(1,int(input())+1): n=int(input()) nums=[] for i in range(n): s=input() nums.append(s.rfind("1")+1) ans=0 for i in range(n): upperBound=i+1 if nums[i]>upperBound : for j in range(i+1,n): if nums[j]<=upperBound : for k in range(j,i,-1): Swap(nums,k) ans+=1 break print("Case #%d: %d" %(tc,ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for tc : Integer.subrange(1, ("" + (((OclFile["System.in"]).readLine())))->toInteger() + 1-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nums : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; execute ((s.rfind("1") + 1) : nums)) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var upperBound : OclAny := i + 1 ; if (nums[i+1]->compareTo(upperBound)) > 0 then ( for j : Integer.subrange(i + 1, n-1) do ( if (nums[j+1]->compareTo(upperBound)) <= 0 then ( for k : Integer.subrange(i + 1, j)->reverse() do ( Swap(nums, k) ; ans := ans + 1) ; break ) else skip) ) else skip) ; execute (StringLib.format("Case #%d: %d",Sequence{tc, ans}))->display()); operation Swap(arr : OclAny, i : OclAny) pre: true post: true activity: var arr[i - 1+1] : OclAny := null; var arr[i+1] : OclAny := null; Sequence{arr[i - 1+1],arr[i+1]} := Sequence{arr[i+1],arr[i - 1+1]}; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- name='A' typ='large' base=name+'-'+typ+'.' lines=file(base+'in').readlines() lines=[line.replace('\n','')for line in lines] T=int(lines[0]) fpos=1 def swap(data,a,b): temp=data[a] data[a]=data[b] data[b]=temp def solve(data): steps=0 for i in xrange(len(data)): if data[i]>i : j=i+1 while data[j]>i : j+=1 steps+=j-i for j in xrange(j,i,-1): swap(data,j,j-1) return steps out=file(base+'out','wb') for case in xrange(1,T+1): size=int(lines[fpos]) fpos+=1 data=[line.rfind('1')for line in lines[fpos : fpos+size]] fpos+=size out.write('Case #%d: %d\n' %(case,solve(data))) out.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var name : String := 'A' ; var typ : String := 'large' ; var base : String := name + '-' + typ + '.' ; var lines : OclAny := file(base + 'in').readlines() ; lines := lines->select(line | true)->collect(line | (line.replace(' ', ''))) ; var T : int := ("" + ((lines->first())))->toInteger() ; var fpos : int := 1 ; skip ; skip ; var out : OclAny := file(base + 'out', 'wb') ; for case : xrange(1, T + 1) do ( var size : int := ("" + ((lines[fpos+1])))->toInteger() ; fpos := fpos + 1 ; data := lines.subrange(fpos+1, fpos + size)->select(line | true)->collect(line | (line.rfind('1'))) ; fpos := fpos + size ; out.write(StringLib.format('Case #%d: %d ',Sequence{case, solve(data)}))) ; out.closeFile(); operation swap(data : OclAny, a : OclAny, b : OclAny) pre: true post: true activity: var temp : OclAny := data[a+1] ; data[a+1] := data[b+1] ; data[b+1] := temp; operation solve(data : OclAny) : OclAny pre: true post: true activity: var steps : int := 0 ; for i : xrange((data)->size()) do ( if (data[i+1]->compareTo(i)) > 0 then ( var j : OclAny := i + 1 ; while (data[j+1]->compareTo(i)) > 0 do ( j := j + 1) ; steps := steps + j - i ; for j : xrange(j, i, -1) do ( swap(data, j, j - 1)) ) else skip) ; return steps; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): from itertools import zip_longest N=int(input()) ans=1<<60 for i in range(1,N//2+1): cur=0 for c,d in zip_longest(str(i),str(N-i),fillvalue=0): cur+=int(c)+int(d) ans=min(ans,cur) print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 1 * (2->pow(60)) ; for i : Integer.subrange(1, N div 2 + 1-1) do ( var cur : int := 0 ; for _tuple : zip_longest(("" + ((i))), ("" + ((N - i))), (argument (test (logical_test (comparison (expr (atom (name fillvalue)))))) = (test (logical_test (comparison (expr (atom (number (integer 0))))))))) do (var _indx : int := 1; var c : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); cur := cur + ("" + ((c)))->toInteger() + ("" + ((d)))->toInteger()) ; ans := Set{ans, cur}->min()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break f,tbl=[0]*31,[] for i in range(n): a=input().split() nm=a.pop(0) m=int(a.pop(0)) d=list(map(int,a)) tbl.append([0,nm,d]) for i in d : f[i]+=1 for i in range(n): for j in tbl[i][2]: tbl[i][0]+=n-f[j]+1 tbl.sort(key=lambda x :(x[0],x[1])) print(tbl[0][0],tbl[0][1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var f : OclAny := null; var tbl : OclAny := null; Sequence{f,tbl} := Sequence{MatrixLib.elementwiseMult(Sequence{ 0 }, 31),Sequence{}} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := input().split() ; var nm : OclAny := a->at(0`firstArg+1) ; a := a->excludingAt(0+1) ; var m : int := ("" + ((a->at(0`firstArg+1))))->toInteger() ; var d : Sequence := ((a)->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((Sequence{0}->union(Sequence{nm}->union(Sequence{ d }))) : tbl) ; for i : d do ( f[i+1] := f[i+1] + 1)) ; for i : Integer.subrange(0, n-1) do ( for j : tbl[i+1][2+1] do ( tbl[i+1]->first() := tbl[i+1]->first() + n - f[j+1] + 1)) ; tbl := tbl->sort() ; execute (tbl->first()->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : player_nun=int(input()) if player_nun==0 : break whole_data=[] for i in range(0,player_nun): dat=input().split() p_data=[] p_data.append(dat[0]) for x in dat[1 :]: p_data.append(int(x)) whole_data.append(p_data) xel={} for i in whole_data : for x in i[2 :]: if x in xel : xel[x]+=1 else : xel[x]=1 score={} for y in xel.keys(): score[y]=player_nun+1-xel[y] result=[] for i in whole_data : player_score=[] player_score.append(i[0]) player_score.append(0) for x in i[2 :]: player_score[1]+=score[x] result.append(player_score) min_score=min(x[1]for x in result) winners=[] for x in result : if x[1]==min_score : winners.append(x[0]) print(str(min_score)+" "+sorted(winners)[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var player_nun : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if player_nun = 0 then ( break ) else skip ; var whole_data : Sequence := Sequence{} ; for i : Integer.subrange(0, player_nun-1) do ( var dat : OclAny := input().split() ; var p_data : Sequence := Sequence{} ; execute ((dat->first()) : p_data) ; for x : dat->tail() do ( execute ((("" + ((x)))->toInteger()) : p_data)) ; execute ((p_data) : whole_data)) ; var xel : OclAny := Set{} ; for i : whole_data do ( for x : i.subrange(2+1) do ( if (xel)->includes(x) then ( xel[x+1] := xel[x+1] + 1 ) else ( xel[x+1] := 1 ))) ; var score : OclAny := Set{} ; for y : xel.keys() do ( score[y+1] := player_nun + 1 - xel[y+1]) ; var result : Sequence := Sequence{} ; for i : whole_data do ( var player_score : Sequence := Sequence{} ; execute ((i->first()) : player_score) ; execute ((0) : player_score) ; for x : i.subrange(2+1) do ( player_score[1+1] := player_score[1+1] + score[x+1]) ; execute ((player_score) : result)) ; var min_score : OclAny := ((argument (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name result))))))))->min() ; var winners : Sequence := Sequence{} ; for x : result do ( if x[1+1] = min_score then ( execute ((x->first()) : winners) ) else skip) ; execute (("" + ((min_score))) + " " + sorted(winners)->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict while 1 : N=int(input()) if N==0 : break D=defaultdict(list) S=[None]*N for i in range(N): name,_,*ts=input().split() S[i]=name for t in map(int,ts): D[t].append(i) P=[0]*N for vs in D.values(): p=N+1-len(vs) for v in vs : P[v]+=p m=min(P) U=[S[i]for i in range(N)if P[i]==m] print(m,min(U)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while 1 do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var D : OclAny := defaultdict(OclType["Sequence"]) ; var S : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, N) ; for i : Integer.subrange(0, N-1) do ( var name : OclAny := null; var _anon : OclAny := null; var ts : OclAny := null; Sequence{name,_anon,ts} := input().split() ; S[i+1] := name ; for t : (ts)->collect( _x | (OclType["int"])->apply(_x) ) do ((expr (atom (name D)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name t)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))))) ; var P : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; for vs : D.values() do ( var p : double := N + 1 - (vs)->size() ; for v : vs do ( P[v+1] := P[v+1] + p)) ; var m : OclAny := (P)->min() ; var U : Sequence := Integer.subrange(0, N-1)->select(i | P[i+1] = m)->collect(i | (S[i+1])) ; execute (m)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=[int(i)for i in input().split()] a=[] for i in range(m): k,l=[int(i)for i in input().split()] a.append([k,l]) b=set() for x in range(1,105): for i in range(len(a)): q=(a[i][1]-1)*x+1 e=a[i][1]*x if a[i][0]e : break else : b.add((n+x-1)//x) if len(b)>1 : print(-1) else : print(*b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var k : OclAny := null; var l : OclAny := null; Sequence{k,l} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute ((Sequence{k}->union(Sequence{ l })) : a)) ; var b : Set := Set{}->union(()) ; for x : Integer.subrange(1, 105-1) do ((compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name q)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) - (expr (atom (number (integer 1))))))))) ))) * (expr (atom (name x)))) + (expr (atom (number (integer 1)))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name e)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))) * (expr (atom (name x))))))))))))) (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) < (comparison (expr (atom (name q)))))) or (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) > (comparison (expr (atom (name e)))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name b)) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name n))) + (expr (atom (name x)))) - (expr (atom (number (integer 1))))))))) ))) // (expr (atom (name x))))))))) )))))))))))))))) ; if (b)->size() > 1 then ( execute (-1)->display() ) else ( execute ((argument * (test (logical_test (comparison (expr (atom (name b))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import combinations as C while True : n=int(input()) if n==0 : break d,dd,ddd={},{},{} names=[] for i in range(n): nmd=input().split() d[nmd[0]]=nmd[2 :] names.append(nmd[0]) for cc in list(C(d.items(),n-1)): t,tt=[],[] for c in cc : t.append(c[0]) tt+=c[1] for name in names : if name not in t : dd[name]=tt break for k in d.keys(): tmp=0 for v in d[k]: tmp+=n-dd[k].count(v) ddd[k]=tmp ans=sorted(ddd.items(),key=lambda x :(x[1],x[0]))[0] print(ans[1],ans[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var d : OclAny := null; var dd : OclAny := null; var ddd : OclAny := null; Sequence{d,dd,ddd} := Sequence{Set{},Set{},Set{}} ; var names : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var nmd : OclAny := input().split() ; d[nmd->first()+1] := nmd.subrange(2+1) ; execute ((nmd->first()) : names)) ; for cc : (C(d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}), n - 1)) do ( var t : OclAny := null; var tt : OclAny := null; Sequence{t,tt} := Sequence{Sequence{},Sequence{}} ; for c : cc do ( execute ((c->first()) : t) ; tt := tt + c[1+1]) ; for name : names do ( if (t)->excludes(name) then ( dd[name+1] := tt ; break ) else skip)) ; for k : d.keys() do ( var tmp : int := 0 ; for v : d[k+1] do ( tmp := tmp + n - dd[k+1]->count(v)) ; ddd[k+1] := tmp) ; var ans : OclAny := sorted(ddd->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}), (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))) , (test (logical_test (comparison (expr (atom (name x)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))) )))))))))->first() ; execute (ans[1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : n=int(input()) except : break if n==0 : break char=[] name=[] times=[] scores={i : n+1 for i in range(30)} for i in range(n): char=input().split() name.append(char[0]) times.append(list(map(int,char[2 :]))) for t in times[i]: scores[t]=scores[t]-1 res={} for i in range(n): res[i]=sum([scores[t]for t in times[i]]) score=min(res.values()) names=[name[i]for i in range(n)if score==res[i]] names.sort() print(score,names[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()) catch (_e : OclException) do ( break) ; if n = 0 then ( break ) else skip ; var char : Sequence := Sequence{} ; var name : Sequence := Sequence{} ; var times : Sequence := Sequence{} ; var scores : Map := Integer.subrange(0, 30-1)->select(i | true)->collect(i | Map{i |-> n + 1})->unionAll() ; for i : Integer.subrange(0, n-1) do ( char := input().split() ; execute ((char->first()) : name) ; execute ((((char.subrange(2+1))->collect( _x | (OclType["int"])->apply(_x) ))) : times) ; for t : times[i+1] do ( scores[t+1] := scores[t+1] - 1)) ; var res : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( res[i+1] := (times[i+1]->select(t | true)->collect(t | (scores[t+1])))->sum()) ; var score : OclAny := (res.values())->min() ; var names : Sequence := Integer.subrange(0, n-1)->select(i | score = res[i+1])->collect(i | (name[i+1])) ; names := names->sort() ; execute (score)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAXN=256 def checkHalfFrequency(Str): L=len(Str) fre=[0 for i in range(MAXN)] for i in range(L): fre[ord(Str[i])]+=1 for i in range(MAXN): if(fre[i]>L//2): return True return False Str="GeeksforGeeks" if(checkHalfFrequency(Str)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAXN : int := 256 ; skip ; Str := "GeeksforGeeks" ; if (checkHalfFrequency(Str)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation checkHalfFrequency(Str : OclAny) : OclAny pre: true post: true activity: var L : int := (Str)->size() ; var fre : Sequence := Integer.subrange(0, MAXN-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, L-1) do ( fre[(Str[i+1])->char2byte()+1] := fre[(Str[i+1])->char2byte()+1] + 1) ; for i : Integer.subrange(0, MAXN-1) do ( if ((fre[i+1]->compareTo(L div 2)) > 0) then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : MAX=100 arr=[0 for i in range(MAX)] arr[0]=0 arr[1]=1 for i in range(2,MAX): arr[i]=arr[i-1]+arr[i-2] print("Fibonacci numbers divisible by their indexes are :") for i in range(1,MAX): if(arr[i]% i==0): print(i,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var MAX : int := 100 ; var arr : Sequence := Integer.subrange(0, MAX-1)->select(i | true)->collect(i | (0)) ; arr->first() := 0 ; arr[1+1] := 1 ; for i : Integer.subrange(2, MAX-1) do ( arr[i+1] := arr[i - 1+1] + arr[i - 2+1]) ; execute ("Fibonacci numbers divisible by their indexes are :")->display() ; for i : Integer.subrange(1, MAX-1) do ( if (arr[i+1] mod i = 0) then ( execute (i)->display() ) else skip) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countWords(str): count=1 for i in range(1,len(str)-1): if(str[i].isupper()): count+=1 return count str="geeksForGeeks" ; print(countWords(str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclType["String"] := "geeksForGeeks"; ; execute (countWords(OclType["String"]))->display(); operation countWords(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var count : int := 1 ; for i : Integer.subrange(1, (OclType["String"])->size() - 1-1) do ( if (OclType["String"][i+1]->matches("[A-Z ]*")) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Nth_Term(n): return(2*pow(n,3)-3*pow(n,2)+n+6)//6 N=8 print(Nth_Term(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 8 ; execute (Nth_Term(N))->display(); operation Nth_Term(n : OclAny) : OclAny pre: true post: true activity: return (2 * (n)->pow(3) - 3 * (n)->pow(2) + n + 6) div 6; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from heapq import heappush,heappop from bisect import bisect_left,bisect_right import sys,random,itertools,math sys.setrecursionlimit(10**5) input=sys.stdin.readline sqrt=math.sqrt def LI(): return list(map(int,input().split())) def LF(): return list(map(float,input().split())) def LI_(): return list(map(lambda x : int(x)-1,input().split())) def II(): return int(input()) def IF(): return float(input()) def LS(): return list(map(list,input().split())) def S(): return list(input().rstrip()) def IR(n): return[II()for _ in range(n)] def LIR(n): return[LI()for _ in range(n)] def FR(n): return[IF()for _ in range(n)] def LFR(n): return[LI()for _ in range(n)] def LIR_(n): return[LI_()for _ in range(n)] def SR(n): return[S()for _ in range(n)] def LSR(n): return[LS()for _ in range(n)] mod=1000000007 inf=1e10 def solve(): n=input().rstrip() ans=sum(map(int,list(n))) if int(n)==10**(len(n)-1): ans=10 print(ans) return if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(5)) ; var input : OclAny := (OclFile["System.in"]).readline ; var sqrt : OclAny := ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : int := 1000000007 ; var Math_PINFINITY : double := ("1e10")->toReal() ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation LI() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LF() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["double"])->apply(_x) )); operation LI_() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() - 1))->apply(_x) )); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation IF() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation LS() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["Sequence"])->apply(_x) )); operation S() : OclAny pre: true post: true activity: return (input().rstrip()); operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (II())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI())); operation FR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (IF())); operation LFR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI())); operation LIR_(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI_())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LS())); operation solve() pre: true post: true activity: n := input().rstrip() ; var ans : OclAny := (((n))->collect( _x | (OclType["int"])->apply(_x) ))->sum() ; if ("" + ((n)))->toInteger() = (10)->pow(((n)->size() - 1)) then ( ans := 10 ) else skip ; execute (ans)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthTerm(n): return 2*pow(n,2)+3*n-5 N=4 print(nthTerm(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 4 ; execute (nthTerm(N))->display(); operation nthTerm(n : OclAny) : OclAny pre: true post: true activity: return 2 * (n)->pow(2) + 3 * n - 5; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthTerm(n): return 3*pow(n,2)+2*n-5 N=4 print(nthTerm(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 4 ; execute (nthTerm(N))->display(); operation nthTerm(n : OclAny) : OclAny pre: true post: true activity: return 3 * (n)->pow(2) + 2 * n - 5; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthTerm(n): return 3*pow(n,2)-4*n+2 N=4 print(nthTerm(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 4 ; execute (nthTerm(N))->display(); operation nthTerm(n : OclAny) : OclAny pre: true post: true activity: return 3 * (n)->pow(2) - 4 * n + 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthTerm(n): return n**2+4*n ; N=4 print(nthTerm(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 4 ; execute (nthTerm(N))->display(); operation nthTerm(n : OclAny) pre: true post: true activity: return (n)->pow(2) + 4 * n;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) ltr_ls=list(input()) try : R_idx=ltr_ls.index("R") except ValueError : R_idx=1000 try : B_idx=ltr_ls.index("B") except ValueError : B_idx=1000 first=min(R_idx,B_idx) if first==1000 : first=0 for i in range(first-1,-1,-1): if ltr_ls[i+1]=="B" : ltr_ls[i]="R" else : ltr_ls[i]="B" for i in range(first,n): if ltr_ls[i]!="?" : continue if ltr_ls[i-1]=="R" : ltr_ls[i]="B" else : ltr_ls[i]="R" print("".join(ltr_ls)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ltr_ls : Sequence := ((OclFile["System.in"]).readLine())->characters() ; try ( var R_idx : int := ltr_ls->indexOf("R") - 1) (except_clause except (test (logical_test (comparison (expr (atom (name ValueError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name R_idx)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1000))))))))))))))) ; try ( var B_idx : int := ltr_ls->indexOf("B") - 1) (except_clause except (test (logical_test (comparison (expr (atom (name ValueError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name B_idx)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 1000))))))))))))))) ; var first : OclAny := Set{R_idx, B_idx}->min() ; if first = 1000 then ( first := 0 ) else skip ; for i : Integer.subrange(-1 + 1, first - 1)->reverse() do ( if ltr_ls[i + 1+1] = "B" then ( ltr_ls[i+1] := "R" ) else ( ltr_ls[i+1] := "B" )) ; for i : Integer.subrange(first, n-1) do ( if ltr_ls[i+1] /= "?" then ( continue ) else skip ; if ltr_ls[i - 1+1] = "R" then ( ltr_ls[i+1] := "B" ) else ( ltr_ls[i+1] := "R" )) ; execute (StringLib.sumStringsWithSeparator((ltr_ls), ""))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def process(A,n): if A==[]: if n==1 : return 1 return-1 M_min=0 M_max=float('inf') for k,f in A : this_min=k/f M_min=max(this_min,M_min) if f>1 : this_max=(k-1)/(f-1) M_max=min(this_max,M_max) M_min=math.ceil(M_min) a1=(n-1)//M_min if M_maxselect(x | true)->collect(x | (("" + ((x)))->toInteger())) ; A := Sequence{} ; for i : Integer.subrange(0, m-1) do ( var k : OclAny := null; var f : OclAny := null; Sequence{k,f} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((Sequence{k}->union(Sequence{ f })) : A)) ; execute (process(A, n))->display(); operation process(A : OclAny, n : OclAny) : OclAny pre: true post: true activity: if A = Sequence{} then ( if n = 1 then ( return 1 ) else skip ; return -1 ) else skip ; var M_min : int := 0 ; var M_max : double := ("" + (('inf')))->toReal() ; for _tuple : A do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var f : OclAny := _tuple->at(_indx); var this_min : double := k / f ; M_min := Set{this_min, M_min}->max() ; if f > 1 then ( var this_max : double := (k - 1) / (f - 1) ; M_max := Set{this_max, M_max}->min() ) else skip) ; M_min := (M_min)->ceil() ; var a1 : int := (n - 1) div M_min ; if (M_max->compareTo(("" + (('inf')))->toReal())) < 0 then ( M_max := (M_max)->floor() ; var a2 : int := (n - 1) div M_max ) else ( a2 := 0 ) ; if a1 = a2 then ( return a1 + 1 ) else ( return -1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthTerm(n): return 4*pow(n,2)-3*n+2 N=4 print(nthTerm(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 4 ; execute (nthTerm(N))->display(); operation nthTerm(n : OclAny) : OclAny pre: true post: true activity: return 4 * (n)->pow(2) - 3 * n + 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def nthTerm(n): return 2*pow(n,2)+n-3 N=4 print(nthTerm(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 4 ; execute (nthTerm(N))->display(); operation nthTerm(n : OclAny) : OclAny pre: true post: true activity: return 2 * (n)->pow(2) + n - 3; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Nth_Term(n): return(3*pow(n,2)-n+2)//(2) N=5 print(Nth_Term(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 5 ; execute (Nth_Term(N))->display(); operation Nth_Term(n : OclAny) : OclAny pre: true post: true activity: return (3 * (n)->pow(2) - n + 2) div (2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def XandYandZintercept(A,B,C,D): x=-D/A y=-D/B z=-D/C return[x,y,z] def equation_plane(p,q,r): x1=p[0] y1=p[1] z1=p[2] x2=q[0] y2=q[1] z2=q[2] x3=r[0] y3=r[1] z3=r[2] a1=x2-x1 b1=y2-y1 c1=z2-z1 a2=x3-x1 b2=y3-y1 c2=z3-z1 A=b1*c2-b2*c1 B=a2*c1-a1*c2 C=a1*b2-b1*a2 D=(-A*x1-B*y1-C*z1) print(XandYandZintercept(A,B,C,D)) x1=-1 y1=2 z1=1 x2=0 y2=-3 z2=2 x3=1 y3=1 z3=-4 equation_plane((x1,y1,z1),(x2,y2,z2),(x3,y3,z3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; x1 := -1 ; y1 := 2 ; z1 := 1 ; x2 := 0 ; y2 := -3 ; z2 := 2 ; x3 := 1 ; y3 := 1 ; z3 := -4 ; equation_plane(Sequence{x1, y1, z1}, Sequence{x2, y2, z2}, Sequence{x3, y3, z3}); operation XandYandZintercept(A : OclAny, B : OclAny, C : OclAny, D : OclAny) : OclAny pre: true post: true activity: var x : double := -D / A ; var y : double := -D / B ; var z : double := -D / C ; return Sequence{x}->union(Sequence{y}->union(Sequence{ z })); operation equation_plane(p : OclAny, q : OclAny, r : OclAny) pre: true post: true activity: var x1 : OclAny := p->first() ; var y1 : OclAny := p[1+1] ; var z1 : OclAny := p[2+1] ; var x2 : OclAny := q->first() ; var y2 : OclAny := q[1+1] ; var z2 : OclAny := q[2+1] ; var x3 : String := r->first() ; var y3 : String := r[1+1] ; var z3 : String := r[2+1] ; var a1 : double := x2 - x1 ; var b1 : double := y2 - y1 ; var c1 : double := z2 - z1 ; var a2 : double := x3 - x1 ; var b2 : double := y3 - y1 ; var c2 : double := z3 - z1 ; A := b1 * c2 - b2 * c1 ; B := a2 * c1 - a1 * c2 ; C := a1 * b2 - b1 * a2 ; D := (-A * x1 - B * y1 - C * z1) ; execute (XandYandZintercept(A, B, C, D))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check_digits(n): while(n): if((n % 10)% 2==0): return 0 n=int(n/10) return 1 def smallest_number(n): i=n while(1): if(check_digits(i)): return i i+=1 if __name__=='__main__' : N=2397 print(smallest_number(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var N : int := 2397 ; execute (smallest_number(N))->display() ) else skip; operation check_digits(n : OclAny) : OclAny pre: true post: true activity: while (n) do ( if ((n mod 10) mod 2 = 0) then ( return 0 ) else skip ; n := ("" + ((n / 10)))->toInteger()) ; return 1; operation smallest_number(n : OclAny) : OclAny pre: true post: true activity: var i : OclAny := n ; while (1) do ( if (check_digits(i)) then ( return i ) else skip ; i := i + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMinDifference(arr,n): arr.sort() diff1=arr[n-1]-arr[1] diff2=arr[n-2]-arr[0] return min(diff1,diff2) if __name__=="__main__" : arr=[1,2,4,3,4] n=len(arr) print(findMinDifference(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{3}->union(Sequence{ 4 })))) ; n := (arr)->size() ; execute (findMinDifference(arr, n))->display() ) else skip; operation findMinDifference(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: arr := arr->sort() ; var diff1 : double := arr[n - 1+1] - arr[1+1] ; var diff2 : double := arr[n - 2+1] - arr->first() ; return Set{diff1, diff2}->min(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=[*input()] for i in range(int(input())): l,r,k=map(int,input().split()) k=k %(r-l+1) s[l-1 : r]=s[r-k : r]+s[l-1 : r-k] print("".join(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var l : OclAny := null; var r : OclAny := null; var k : OclAny := null; Sequence{l,r,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : int := k mod (r - l + 1) ; s.subrange(l - 1+1, r) := s.subrange(r - k+1, r) + s.subrange(l - 1+1, r - k)) ; execute (StringLib.sumStringsWithSeparator((s), ""))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from os import path if path.exists('input.txt'): sys.stdin=open('input.txt','r') sys.stdout=open('output.txt','w') s=input() for _ in range(int(input())): l,r,k=map(int,input().split()) l-=1 ; r-=1 k %=r-l+1 s=s[: l]+s[r-k+1 : r+1]+s[l : r-k+1]+s[r+1 :] print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if path.exists('input.txt') then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('input.txt')) ; OclFile["System.out"] := OclFile.newOclFile_Write(OclFile.newOclFile('output.txt')) ) else skip ; var s : String := (OclFile["System.in"]).readLine() ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var l : OclAny := null; var r : OclAny := null; var k : OclAny := null; Sequence{l,r,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; l := l - 1; r := r - 1 ; k := k mod r - l + 1 ; s := s.subrange(1,l) + s.subrange(r - k + 1+1, r + 1) + s.subrange(l+1, r - k + 1) + s.subrange(r + 1+1)) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline S=list(readline().rstrip()) M=int(readline()) for _ in range(M): l,r,k=map(int,readline().split()) l-=1 SS=S[l : r] k %=len(SS) SS=SS[len(SS)-k :]+SS[: len(SS)-k] S[l : r]=SS print(*S,sep="") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var S : Sequence := (readline().rstrip()) ; var M : int := ("" + ((readline())))->toInteger() ; for _anon : Integer.subrange(0, M-1) do ( var l : OclAny := null; var r : OclAny := null; var k : OclAny := null; Sequence{l,r,k} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; l := l - 1 ; var SS : OclAny := S.subrange(l+1, r) ; k := k mod (SS)->size() ; SS := SS.subrange((SS)->size() - k+1) + SS.subrange(1,(SS)->size() - k) ; S.subrange(l+1, r) := SS) ; execute ((argument * (test (logical_test (comparison (expr (atom (name S))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=list(input()) m=int(input()) while m : l,r,k=map(int,input().split()) l=l-1 k=k %(r-l) s[l : r]=s[l : r][: :-1] s[l : l+k]=s[l : l+k][: :-1] s[l+k : r]=s[l+k : r][: :-1] m=m-1 print(''.join(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while m do ( var l : OclAny := null; var r : OclAny := null; var k : OclAny := null; Sequence{l,r,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : double := l - 1 ; var k : int := k mod (r - l) ; s.subrange(l+1, r) := s.subrange(l+1, r)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; s.subrange(l+1, l + k) := s.subrange(l+1, l + k)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; s.subrange(l + k+1, r) := s.subrange(l + k+1, r)(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; m := m - 1) ; execute (StringLib.sumStringsWithSeparator((s), ''))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def shift(l,r,k,s): len=r-l+1 shift=k % len end=r-shift+1 out=s[: l]+s[end : r+1]+s[l : end]+s[r+1 :] return out s=input() m=int(input()) for _ in range(m): l,r,k=tuple(map(int,input().split())) s=shift(l-1,r-1,k,s) print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s := (OclFile["System.in"]).readLine() ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, m-1) do ( Sequence{l,r,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; s := shift(l - 1, r - 1, k, s)) ; execute (s)->display(); operation shift(l : OclAny, r : OclAny, k : OclAny, s : OclAny) : OclAny pre: true post: true activity: var len : double := r - l + 1 ; var shift : int := k mod len ; var end : double := r - shift + 1 ; var out : OclAny := s.subrange(1,l) + s.subrange(end+1, r + 1) + s.subrange(l+1, end) + s.subrange(r + 1+1) ; return out; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) k=list() f=list() for _ in range(m): x,y=map(int,input().split()) k.append(x) f.append(y) a=set() for i in range(1,101): for j in range(m): q=(f[j]-1)*i+1 e=f[j]*i if(k[j]e): break else : a.add((n+i-1)//i) if(len(a)>1): print(-1) else : print(*a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var k : Sequence := () ; var f : Sequence := () ; for _anon : Integer.subrange(0, m-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((x) : k) ; execute ((y) : f)) ; var a : Set := Set{}->union(()) ; for i : Integer.subrange(1, 101-1) do ((compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name m)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name q)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name f)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))) - (expr (atom (number (integer 1))))))))) ))) * (expr (atom (name i)))) + (expr (atom (number (integer 1)))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name e)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name f)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ]))) * (expr (atom (name i))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom (name k)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) < (comparison (expr (atom (name q)))))) or (logical_test (comparison (comparison (expr (atom (name k)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])))) > (comparison (expr (atom (name e))))))))) )))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name a)) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name n))) + (expr (atom (name i)))) - (expr (atom (number (integer 1))))))))) ))) // (expr (atom (name i))))))))) )))))))))))))))) ; if ((a)->size() > 1) then ( execute (-1)->display() ) else ( execute ((argument * (test (logical_test (comparison (expr (atom (name a))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) count=0 for i in range(n): a=input() if a=="Tetrahedron" : count+=4 elif a=="Cube" : count+=6 elif a=="Octahedron" : count+=8 elif a=="Dodecahedron" : count+=12 elif a=="Icosahedron" : count+=20 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( var a : String := (OclFile["System.in"]).readLine() ; if a = "Tetrahedron" then ( count := count + 4 ) else (if a = "Cube" then ( count := count + 6 ) else (if a = "Octahedron" then ( count := count + 8 ) else (if a = "Dodecahedron" then ( count := count + 12 ) else (if a = "Icosahedron" then ( count := count + 20 ) else skip ) ) ) ) ) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) d={"Tetrahedron" : 4,"Cube" : 6,"Octahedron" : 8,"Dodecahedron" : 12,"Icosahedron" : 20} x=0 for _ in range(n): i=input() x+=d[i] print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : Map := Map{ "Tetrahedron" |-> 4 }->union(Map{ "Cube" |-> 6 }->union(Map{ "Octahedron" |-> 8 }->union(Map{ "Dodecahedron" |-> 12 }->union(Map{ "Icosahedron" |-> 20 })))) ; var x : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var i : String := (OclFile["System.in"]).readLine() ; x := x + d->at(i)) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) count=0 for i in range(n): nazwa=input() if nazwa=='Tetrahedron' : count=count+4 if nazwa=='Cube' : count=count+6 if nazwa=='Octahedron' : count=count+8 if nazwa=='Dodecahedron' : count=count+12 if nazwa=='Icosahedron' : count=count+20 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( var nazwa : String := (OclFile["System.in"]).readLine() ; if nazwa = 'Tetrahedron' then ( count := count + 4 ) else skip ; if nazwa = 'Cube' then ( count := count + 6 ) else skip ; if nazwa = 'Octahedron' then ( count := count + 8 ) else skip ; if nazwa = 'Dodecahedron' then ( count := count + 12 ) else skip ; if nazwa = 'Icosahedron' then ( count := count + 20 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check_digits(n): while(n): if((n % 10)% 2): return 0 n=int(n/10) return 1 def smallest_number(n): for i in range(n,2401): if(check_digits(i)==1): return(i) N=2397 print(str(smallest_number(N))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := 2397 ; execute (("" + ((smallest_number(N)))))->display(); operation check_digits(n : OclAny) : OclAny pre: true post: true activity: while (n) do ( if ((n mod 10) mod 2) then ( return 0 ) else skip ; n := ("" + ((n / 10)))->toInteger()) ; return 1; operation smallest_number(n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(n, 2401-1) do ( if (check_digits(i) = 1) then ( return (i) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) dic={"Tetrahedron" : 4,"Cube" : 6,"Octahedron" : 8,"Dodecahedron" : 12,"Icosahedron" : 20} sum=0 for _ in range(n): s=input() sum+=dic[s] print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var dic : Map := Map{ "Tetrahedron" |-> 4 }->union(Map{ "Cube" |-> 6 }->union(Map{ "Octahedron" |-> 8 }->union(Map{ "Dodecahedron" |-> 12 }->union(Map{ "Icosahedron" |-> 20 })))) ; var sum : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; sum := sum + dic->at(s)) ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) dict={'Tetrahedron' : 4,'Cube' : 6,'Octahedron' : 8,'Dodecahedron' : 12,'Icosahedron' : 20} num=0 for i in range(n): num+=int(dict[input()]) print(num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var OclType["Map"] : Map := Map{ 'Tetrahedron' |-> 4 }->union(Map{ 'Cube' |-> 6 }->union(Map{ 'Octahedron' |-> 8 }->union(Map{ 'Dodecahedron' |-> 12 }->union(Map{ 'Icosahedron' |-> 20 })))) ; var num : int := 0 ; for i : Integer.subrange(0, n-1) do ( num := num + ("" + (((arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ]))))->toInteger()) ; execute (num)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=map(int,input().split()) print(((a-1)^(b-1)).bit_length()%(n.bit_length()-1)or 'Final!') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((MathLib.bitwiseXor((a - 1), (b - 1))).bit_length() mod (n.bit_length() - 1) or 'Final!')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil n,a,b=map(int,input().split()) r,p=1,1 while ceil(a/2**p)!=ceil(b/2**p): p+=1 if 2**(p)==n : print("Final!") else : print(p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var r : OclAny := null; var p : OclAny := null; Sequence{r,p} := Sequence{1,1} ; while ceil(a / (2)->pow(p)) /= ceil(b / (2)->pow(p)) do ( p := p + 1) ; if (2)->pow((p)) = n then ( execute ("Final!")->display() ) else ( execute (p)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n,a,b=map(int,input().split()) c=0 while a!=b : a=(a+1)//2 b=(b+1)//2 c+=1 n=n//2 if n==1 : print("Final!") else : print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : int := 0 ; while a /= b do ( var a : int := (a + 1) div 2 ; var b : int := (b + 1) div 2 ; c := c + 1 ; var n : int := n div 2) ; if n = 1 then ( execute ("Final!")->display() ) else ( execute (c)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,a,b=map(int,input().split()) x=len(bin(n-1)[2 :]) a=bin(a-1)[2 :].rjust(x,'0') b=bin(b-1)[2 :].rjust(x,'0') for i in range(x): if a[i]!=b[i]: if i==0 : print('Final!') break else : print(x-i) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : int := (bin(n - 1).subrange(2+1))->size() ; var a : OclAny := bin(a - 1).subrange(2+1).rjust(x, '0') ; var b : OclAny := bin(b - 1).subrange(2+1).rjust(x, '0') ; for i : Integer.subrange(0, x-1) do ( if a[i+1] /= b[i+1] then ( if i = 0 then ( execute ('Final!')->display() ; break ) else ( execute (x - i)->display() ; break ) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a,b=[int(i)for i in input().split()] ans=[] for i in range(1,n+1): ans.append(i) nd=0 while len(ans)>=2 : newans=[] for i in range(0,len(ans)-1,2): if(ans[i]==a and ans[i+1]==b)or(ans[i]==b and ans[i+1]==a): if(len(ans)==2): print('Final!') else : print(nd+1) break elif ans[i]==a or ans[i+1]==a : newans.append(a) elif ans[i]==b or ans[i+1]==b : newans.append(b) else : newans.append(ans[i]) nd+=1 ans=newans ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{n,a,b} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(1, n + 1-1) do ( execute ((i) : ans)) ; var nd : int := 0 ; while (ans)->size() >= 2 do ( var newans : Sequence := Sequence{} ; for i : Integer.subrange(0, (ans)->size() - 1-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( if (ans[i+1] = a & ans[i + 1+1] = b) or (ans[i+1] = b & ans[i + 1+1] = a) then ( if ((ans)->size() = 2) then ( execute ('Final!')->display() ) else ( execute (nd + 1)->display() ) ; break ) else (if ans[i+1] = a or ans[i + 1+1] = a then ( execute ((a) : newans) ) else (if ans[i+1] = b or ans[i + 1+1] = b then ( execute ((b) : newans) ) else ( execute ((ans[i+1]) : newans) ) ) ) ) ; nd := nd + 1 ; ans := newans); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- nick=int(input()) sam=input() l_1=list() l_2=list() for c in sam[: nick]: l_1.append(int(c)) for c in sam[nick :]: l_2.append(int(c)) l_1.sort() l_2.sort() if(l_1[0]==l_2[0]): print("NO") quit() else : g=l_1[0]>l_2[0] for i in range(1,nick): if g and l_1[i]>l_2[i]: pass elif not g and l_1[i]toInteger() ; var sam : String := (OclFile["System.in"]).readLine() ; var l var nick : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() : Sequence := () ; var l:= () : Sequence := () ; for c : sam.subrange(1,nick) do ( execute ((("" + ((c)))->toInteger()) : lllllll var nick : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger().append(("" + ((c)))->toInteger()).append(("" + ((c)))->toInteger()).append(("" + ((c)))->toInteger()).append(("" + ((c)))->toInteger()).append(("" + ((c)))->toInteger()).append(("" + ((c)))->toInteger()))) ; for c : sam.subrange(nick+1) do ( execute ((("" + ((c)))->toInteger()) : l.append(("" + ((c)))->toInteger()))) ; lllllll var nick : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()->sort()->sort()->sort()->sort()->sort()->sort() := lllllll var nick : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()->sort()->sort()->sort()->sort()->sort()->sort()->sort() ; l->sort() := l->sort()->sort() ; if (l var nick : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()->first() = l execute ("NO")->display() ; quit()->first()) then ( execute ("NO")->display() ; quit() ) else ( var g : boolean := (l var nick : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()->first()->compareTo(l_2->first())) > 0 ) ; for i : Integer.subrange(1, nick-1) do ( if g & (l var nick : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()[i+1]->compareTo(l skip[i+1])) > 0 then ( skip ) else (if not(g) & (l var nick : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()[i+1]->compareTo(l skip[i+1])) < 0 then ( skip ) else ( execute ("NO")->display() ; quit() ) ) ) ; execute ("YES")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- X,A,B=map(int,input().split()) N=int(input()) for i in range(N): word=input() if word=="nobiro" : X=X+A elif word=="tidime" : X=X+B elif word=="karero" : X=0 if X<0 : X=0 print(X) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var X : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{X,A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, N-1) do ( var word : String := (OclFile["System.in"]).readLine() ; if word = "nobiro" then ( var X : OclAny := X + A ) else (if word = "tidime" then ( X := X + B ) else (if word = "karero" then ( X := 0 ) else skip ) ) ; if X < 0 then ( X := 0 ) else skip) ; execute (X)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from heapq import heappush,heappop import sys import math import bisect import random def LI(): return[int(x)for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return[list(x)for x in sys.stdin.readline().split()] def S(): res=list(sys.stdin.readline()) if res[-1]=="\n" : return res[:-1] return res def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] sys.setrecursionlimit(1000000) mod=1000000007 def solve(): x,a,b=LI() n=I() ans=x for _ in range(n): s=input() if s=="nobiro" : if ans+a>=0 : ans+=a else : ans=0 elif s=="tidime" : if ans+b>=0 : ans+=b else : ans=0 else : ans=0 print(ans) return if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1000000) ; var mod : int := 1000000007 ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | ((x))); operation S() : OclAny pre: true post: true activity: var res : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if res->last() = "\n" then ( return res->front() ) else skip ; return res; operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation solve() pre: true post: true activity: var x : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{x,a,b} := LI() ; n := I() ; var ans : OclAny := x ; for _anon : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if s = "nobiro" then ( if ans + a >= 0 then ( ans := ans + a ) else ( ans := 0 ) ) else (if s = "tidime" then ( if ans + b >= 0 then ( ans := ans + b ) else ( ans := 0 ) ) else ( ans := 0 ) ) ) ; execute (ans)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def triangular_series(n): j=1 k=1 for i in range(1,n+1): print(k,end=' ') j=j+1 k=k+j n=5 triangular_series(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5 ; triangular_series(n); operation triangular_series(n : OclAny) pre: true post: true activity: var j : int := 1 ; var k : int := 1 ; for i : Integer.subrange(1, n + 1-1) do ( execute (k)->display() ; j := j + 1 ; k := k + j); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def inpl(): return list(map(int,input().split())) X,A,B=inpl() for _ in range(int(input())): S=input() if S=="karero" : X=0 else : X=max(0,X+[A,B][S=="tidime"]) print(X) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var X : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{X,A,B} := inpl() ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var S : String := (OclFile["System.in"]).readLine() ; if S = "karero" then ( var X : int := 0 ) else ( X := Set{0, X + Sequence{A}->union(Sequence{ B })->select(S = "tidime")}->max() )) ; execute (X)->display(); operation inpl() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,a,b=(int(y)for y in input().split()) n=int(input()) for i in range(n): s=input() if s[0]=="n" : x=max(0,x+a) elif s[0]=="t" : x=max(0,x+b) else : x=0 print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var a : OclAny := null; var b : OclAny := null; Sequence{x,a,b} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y)))))))) ))))))) (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if s->first() = "n" then ( var x : OclAny := Set{0, x + a}->max() ) else (if s->first() = "t" then ( x := Set{0, x + b}->max() ) else ( x := 0 ) ) ) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- X,A,B=map(int,input().split()) N=int(input()) S=[input()for i in range(N)] for s in S : if s=='nobiro' : X+=A elif s=='tidime' : X+=B else : X=0 if X<0 : X=0 print(X) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var X : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{X,A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; for s : S do ( if s = 'nobiro' then ( X := X + A ) else (if s = 'tidime' then ( X := X + B ) else ( var X : int := 0 ) ) ; if X < 0 then ( X := 0 ) else skip) ; execute (X)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): import sys input=sys.stdin.readline while True : a,b=map(int,input().split()) if a==0 : break m=int(input()) xy=[list(map(int,input().split()))for _ in[0]*m] memo=[[True]*a for _ in[0]*b] for x,y in xy : memo[y-1][x-1]=False def check(i,j): ans=0 if i+1collect( _x | (OclType["int"])->apply(_x) ) ; if a = 0 then ( break ) else skip ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var xy : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var memo : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, b)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ true }, a))) ; for _tuple : xy do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); memo[y - 1+1][x - 1+1] := false) ; skip ; execute (check(0, 0))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from functools import lru_cache def main(): while True : W,H=map(int,input().split(" ")) if H==W==0 : break N=int(input()) forbid={tuple(map(int,input().split(" ")))for _ in range(N)} @ lru_cache(maxsize=None) def route(x,y): if x==0 or y==0 : return 0 if(x,y)in forbid : return 0 if x==y==1 : return 1 return route(x-1,y)+route(x,y-1) print(route(W,H)) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: while true do ( var W : OclAny := null; var H : OclAny := null; Sequence{W,H} := (input().split(" "))->collect( _x | (OclType["int"])->apply(_x) ) ; if H = W & (W == 0) then ( break ) else skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var forbid : Set := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | ((input().split(" "))->collect( _x | (OclType["int"])->apply(_x) )))->asSet() ; (compound_stmt (decorator @ (dotted_name (name lru_cache)) ( (arglist (argument (test (logical_test (comparison (expr (atom (name maxsize)))))) = (test (logical_test (comparison (expr (atom None))))))) )) (funcdef def (name route) ( (typedargslist (def_parameters (def_parameter (named_parameter (name x))) , (def_parameter (named_parameter (name y))))) ) : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (comparison (expr (atom (name x)))) == (comparison (expr (atom (number (integer 0))))))) or (logical_test (comparison (comparison (expr (atom (name y)))) == (comparison (expr (atom (number (integer 0))))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name x)))))) , (test (logical_test (comparison (expr (atom (name y))))))) )))) in (comparison (expr (atom (name forbid))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (comparison (expr (atom (name x)))) == (comparison (expr (atom (name y))))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))) (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (expr (atom (name route)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (number (integer 1))))))))) , (argument (test (logical_test (comparison (expr (atom (name y)))))))) )))) + (expr (atom (name route)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (number (integer 1)))))))))) ))))))))))))))) ; execute (route(W, H))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import copy def main(): line=sys.stdin.readline() while line.split()!=["0","0"]: analy(line) line=sys.stdin.readline() return def analy(line): field=[int(n)for n in line.split()] num=int(sys.stdin.readline()) data=[] for i in range(num): a=sys.stdin.readline() b=[int(n)for n in a.split()] data.append(b) print(compute(field,data)) def compute(field,ng): list=[] for i in range(field[1]): for j in range(field[0]): if i==0 : if[j+1,i+1]in ng : list.append(0) elif j==0 : list.append(1) else : list.append(list[j-1]) else : if[j+1,i+1]in ng : list[j]=0 elif j!=0 : list[j]=list[j-1]+list[j] return list[len(list)-1] if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var line : String := (OclFile["System.in"]).readLine() ; while line.split() /= Sequence{"0"}->union(Sequence{ "0" }) do ( analy(line) ; line := (OclFile["System.in"]).readLine()) ; return; operation analy(line : OclAny) pre: true post: true activity: var field : Sequence := line.split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var data : Sequence := Sequence{} ; for i : Integer.subrange(0, num-1) do ( var a : String := (OclFile["System.in"]).readLine() ; var b : Sequence := a.split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; execute ((b) : data)) ; execute (compute(field, data))->display(); operation compute(field : OclAny, ng : OclAny) : OclAny pre: true post: true activity: var OclType["Sequence"] : Sequence := Sequence{} ; for i : Integer.subrange(0, field[1+1]-1) do ( for j : Integer.subrange(0, field->first()-1) do ( if i = 0 then ( if (ng)->includes(Sequence{j + 1}->union(Sequence{ i + 1 })) then ( execute ((0) : OclType["Sequence"]) ) else (if j = 0 then ( execute ((1) : OclType["Sequence"]) ) else ( execute (([j - 1+1]) : OclType["Sequence"]) ) ) ) else ( if (ng)->includes(Sequence{j + 1}->union(Sequence{ i + 1 })) then ( [j+1] := 0 ) else (if j /= 0 then ( [j+1] := [j - 1+1]->union([j+1]) ) else skip) ))) ; return [(OclType["Sequence"])->size() - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for e in iter(input,'0 0'): a,b=map(int,e.split()) m=[[0]*b for _ in[0]*a] for _ in[0]*int(input()): i,j=map(int,input().split()) m[~-i][~-j]=-1 for s in range(a): for t in range(b): u,v=m[s-1][t],m[s][t-1] if m[s][t]>=0 : m[s][t]=(u*(u>0)+v*(v>0))+(s+t==0) print(m[~-a][~-b]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for e : OclIterator.newOclIterator_Sequence(input, '0 0') do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (e.split())->collect( _x | (OclType["int"])->apply(_x) ) ; var m : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, a)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, b))) ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; m[MathLib.bitwiseNot(-i)+1][MathLib.bitwiseNot(-j)+1] := -1) ; for s : Integer.subrange(0, a-1) do ( for t : Integer.subrange(0, b-1) do ( var u : OclAny := null; var v : OclAny := null; Sequence{u,v} := Sequence{m[s - 1+1][t+1],m[s+1][t - 1+1]} ; if m[s+1][t+1] >= 0 then ( m[s+1][t+1] := (u * (u > 0) + v * (v > 0)) + (s + t = 0) ) else skip)) ; execute (m[MathLib.bitwiseNot(-a)+1][MathLib.bitwiseNot(-b)+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : a,b=(lambda row :[int(row[i])for i in range(len(row))])(input().split()) n=int(input()) obstacle=[(lambda row :[int(row[i])for i in range(len(row))])(input().split())for __ in range(n)] roads=[[0 for __ in range(b+1)]for __ in range(a+1)] roads[1][1]=1 for i in range(1,a+1): for j in range(1,b+1): if not[i,j]in obstacle : roads[i][j]+=roads[i-1][j]+roads[i][j-1] print(str(roads[a][b])) except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (lambda row : OclAny in (Integer.subrange(0, (row)->size()-1)->select(i | true)->collect(i | (("" + ((row[i+1])))->toInteger()))))(input().split()) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var obstacle : Sequence := Integer.subrange(0, n-1)->select(__ | true)->collect(__ | ((lambda row : OclAny in (Integer.subrange(0, (row)->size()-1)->select(i | true)->collect(i | (("" + ((row[i+1])))->toInteger()))))(input().split()))) ; var roads : Sequence := Integer.subrange(0, a + 1-1)->select(__ | true)->collect(__ | (Integer.subrange(0, b + 1-1)->select(__ | true)->collect(__ | (0)))) ; roads[1+1][1+1] := 1 ; for i : Integer.subrange(1, a + 1-1) do ( for j : Integer.subrange(1, b + 1-1) do ( if not((obstacle)->includes(Sequence{i}->union(Sequence{ j }))) then ( roads[i+1][j+1] := roads[i+1][j+1] + roads[i - 1+1][j+1] + roads[i+1][j - 1+1] ) else skip)) ; execute (("" + ((roads[a+1][b+1]))))->display()) catch (_e : OclException) do ( break) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() z=sorted(s[n :]) x=sorted(s[: n]) flag=True flag2=True for i in range(n): if int(x[i])>=int(z[i]): flag=False for i in range(n): if int(x[i])<=int(z[i]): flag2=False if flag or flag2 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var z : Sequence := s.subrange(n+1)->sort() ; var x : Sequence := s.subrange(1,n)->sort() ; var flag : boolean := true ; var flag2 : boolean := true ; for i : Integer.subrange(0, n-1) do ( if (("" + ((x[i+1])))->toInteger()->compareTo(("" + ((z[i+1])))->toInteger())) >= 0 then ( flag := false ) else skip) ; for i : Integer.subrange(0, n-1) do ( if (("" + ((x[i+1])))->toInteger()->compareTo(("" + ((z[i+1])))->toInteger())) <= 0 then ( flag2 := false ) else skip) ; if flag or flag2 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys ; def solve(X,A): minimum=sys.maxsize ; ind=-1 ; for i in range(len(A)): if(A[i]union(Sequence{6}->union(Sequence{4}->union(Sequence{ 8 }))); ; X := 18; ; ans := solve(X, A); ; for i : Integer.subrange(0, (ans)->size()-1) do ( execute (ans[i+1])->display();) ) else skip; operation solve(X : OclAny, A : OclAny) pre: true post: true activity: var minimum : (trailer . (name maxsize)) := (trailer . (name maxsize)); ; var ind : int := -1; ; for i : Integer.subrange(0, (A)->size()-1) do ( if ((A[i+1]->compareTo(minimum)) < 0) then ( minimum := A[i+1]; ; ind := i; ) else skip) ; var maxIndChosen : int := X div minimum; ; var ans : Sequence := Sequence{}; ; if (maxIndChosen = 0) then ( return ans; ) else skip ; for i : Integer.subrange(0, maxIndChosen-1) do ( execute ((ind) : ans);) ; var temp : int := maxIndChosen; ; var sum : double := maxIndChosen * A[ind+1]; ; for i : Integer.subrange(0, ind-1) do ( if (sum - X = 0 or temp = 0) then ( break; ) else skip ; while (((sum - A[ind+1] + A[i+1])->compareTo(X)) <= 0 & temp /= 0) do ( execute ((ans->first()))->isDeleted(); ; execute ((i) : ans); ; temp := temp - 1; ; sum := sum + (A[i+1] - A[ind+1]);)) ; ans := ans->sort(); ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def _input(): return map(int,input().split()) n,m=_input() lst=list(_input()) l={} for i in range(n): if lst[i]not in l : l[lst[i]]=1 else : l[lst[i]]+=1 res=0 for i in range(n): if l[lst[i]]>1 : res+=n-i-l[lst[i]] l[lst[i]]-=1 else : res+=n-i-1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := _input() ; var lst : Sequence := (_input()) ; var l : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( if (l)->excludes(lst[i+1]) then ( l[lst[i+1]+1] := 1 ) else ( l[lst[i+1]+1] := l[lst[i+1]+1] + 1 )) ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( if l[lst[i+1]+1] > 1 then ( res := res + n - i - l[lst[i+1]+1] ; l[lst[i+1]+1] := l[lst[i+1]+1] - 1 ) else ( res := res + n - i - 1 )) ; execute (res)->display(); operation _input() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fact(n): res=1 for i in range(2,n+1): res=res*i return res def nCr(n,r): return fact(n)//(fact(r)*fact(n-r)) def number_of_subsequences(arr,k,n): s=0 m=dict() for i in arr : m[i]=m.get(i,0)+1 for j in m : s=s+nCr(m[j],k) return s arr=[1,1,1,1,2,2,2] k=2 n=len(arr) print(number_of_subsequences(arr,k,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; arr := Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{2}->union(Sequence{ 2 })))))) ; k := 2 ; n := (arr)->size() ; execute (number_of_subsequences(arr, k, n))->display(); operation fact(n : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; for i : Integer.subrange(2, n + 1-1) do ( res := res * i) ; return res; operation nCr(n : OclAny, r : OclAny) : OclAny pre: true post: true activity: return fact(n) div (fact(r) * fact(n - r)); operation number_of_subsequences(arr : OclAny, k : OclAny, n : OclAny) : OclAny pre: true post: true activity: var s : int := 0 ; var m : Map := (arguments ( )) ; for i : arr do ( m[i+1] := m.get(i, 0) + 1) ; for j : m->keys() do ( s := s + nCr(m[j+1], k)) ; return s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for u in range(int(input())): n=int(input()) a=[int(w)for w in input().split()] b=[int(w)for w in input().split()] c=[int(w)for w in input().split()] ans=[a[0]] for i in range(1,n): temp=0 if(ans[-1]!=a[i]): temp=a[i] else : if(ans[-1]!=b[i]): temp=b[i] else : temp=c[i] ans.append(temp) if(ans[0]==ans[-1]): if(ans[-1]==a[-1]): if(ans[-2]!=b[-1]): ans[-1]=b[-1] else : ans[-1]=c[-1] elif(ans[-1]==b[-1]): if(ans[-2]!=a[-1]): ans[-1]=a[-1] else : ans[-1]=c[-1] else : if(ans[-2]!=b[-1]): ans[-1]=b[-1] else : ans[-1]=c[-1] print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for u : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input().split()->select(w | true)->collect(w | (("" + ((w)))->toInteger())) ; var b : Sequence := input().split()->select(w | true)->collect(w | (("" + ((w)))->toInteger())) ; var c : Sequence := input().split()->select(w | true)->collect(w | (("" + ((w)))->toInteger())) ; var ans : Sequence := Sequence{ a->first() } ; for i : Integer.subrange(1, n-1) do ( var temp : int := 0 ; if (ans->last() /= a[i+1]) then ( temp := a[i+1] ) else ( if (ans->last() /= b[i+1]) then ( temp := b[i+1] ) else ( temp := c[i+1] ) ) ; execute ((temp) : ans)) ; if (ans->first() = ans->last()) then ( if (ans->last() = a->last()) then ( if (ans->front()->last() /= b->last()) then ( ans->last() := b->last() ) else ( ans->last() := c->last() ) ) else (if (ans->last() = b->last()) then ( if (ans->front()->last() /= a->last()) then ( ans->last() := a->last() ) else ( ans->last() := c->last() ) ) else ( if (ans->front()->last() /= b->last()) then ( ans->last() := b->last() ) else ( ans->last() := c->last() ) ) ) ) else skip ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for f in range(int(input())): n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) p=a for i in range(n): if p[i]==p[(i+1)% n]: if p[i]!=b[i]and p[(i-1)% n]!=b[i]: p[i]=b[i] else : p[i]=c[i] print(*p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for f : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var p : Sequence := a ; for i : Integer.subrange(0, n-1) do ( if p[i+1] = p[(i + 1) mod n+1] then ( if p[i+1] /= b[i+1] & p[(i - 1) mod n+1] /= b[i+1] then ( p[i+1] := b[i+1] ) else ( p[i+1] := c[i+1] ) ) else skip) ; execute ((argument * (test (logical_test (comparison (expr (atom (name p))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- y=lambda :[*map(int,input().split())] for _ in range(int(input())): n=int(input()) a,b,c=y(),y(),y() j=[a[0]] for i in range(1,n-1): if j[-1]!=a[i]: j.append(a[i]) else : j.append(b[i]) if j[-1]!=a[-1]and j[0]!=a[-1]: j.append(a[-1]) elif j[-1]!=b[-1]and j[0]!=b[-1]: j.append(b[-1]) else : j.append(c[-1]) print(' '.join(map(str,j))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var y : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := Sequence{y->apply(),y->apply(),y->apply()} ; var j : Sequence := Sequence{ a->first() } ; for i : Integer.subrange(1, n - 1-1) do ( if j->last() /= a[i+1] then ( execute ((a[i+1]) : j) ) else ( execute ((b[i+1]) : j) )) ; if j->last() /= a->last() & j->first() /= a->last() then ( execute ((a->last()) : j) ) else (if j->last() /= b->last() & j->first() /= b->last() then ( execute ((b->last()) : j) ) else ( execute ((c->last()) : j) ) ) ; execute (StringLib.sumStringsWithSeparator(((j)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) t,=R() exec(t*'n,=R();r=[0]*n;i=0\nfor t in zip(R(),R(),R()):i+=1;r[i-1],*_={*t}-{r[i-2],r[i%n]}\nprint(*r)\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name t)))))) ,)} := R->apply() ; (expr (expr (atom (name t))) * (expr (atom 'n,=R();r=[0]*n;i=0 for t in zip(R(),R(),R()):i+=1;r[i-1],*_={*t}-{r[i-2],r[i%n]} print(*r) '))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()); a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) ans=[a[0]] for i in range(1,n): s={ans[-1],ans[0]} if a[i]not in s : ans.append(a[i]) elif b[i]not in s : ans.append(b[i]) else : ans.append(c[i]) print(' '.join(map(str,ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : Sequence := Sequence{ a->first() } ; for i : Integer.subrange(1, n-1) do ( var s : Set := Set{ans->last()}->union(Set{ ans->first() }) ; if (s)->excludes(a[i+1]) then ( execute ((a[i+1]) : ans) ) else (if (s)->excludes(b[i+1]) then ( execute ((b[i+1]) : ans) ) else ( execute ((c[i+1]) : ans) ) ) ) ; execute (StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math x1,y1,x2,y2=map(float,input().split()) dist=math.sqrt((x1-x2)**2+(y1-y2)**2) print("{:.5f}".format(dist)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; var dist : double := (((x1 - x2))->pow(2) + ((y1 - y2))->pow(2))->sqrt() ; execute (StringLib.interpolateStrings("{:.5f}", Sequence{dist}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x1,y1,x2,y2=[float(i)for i in input().split()] xdistance=x1-x2 ydistance=y1-y2 print(((xdistance**2)+(ydistance**2))**0.5) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toReal())) ; var xdistance : double := x1 - x2 ; var ydistance : double := y1 - y2 ; execute (((((xdistance)->pow(2)) + ((ydistance)->pow(2))))->pow(0.5))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math x1,y1,x2,y2=input().split() x1,y1,x2,y2=float(x1),float(y1),float(x2),float(y2) l=math.sqrt((x1-x2)**2+(y1-y2)**2) print('{0:.6f}'.format(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := input().split() ; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := Sequence{("" + ((x1)))->toReal(),("" + ((y1)))->toReal(),("" + ((x2)))->toReal(),("" + ((y2)))->toReal()} ; var l : double := (((x1 - x2))->pow(2) + ((y1 - y2))->pow(2))->sqrt() ; execute (StringLib.interpolateStrings('{0:.6f}', Sequence{l}))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=input() z=sorted(s[n :]) x=sorted(s[: n]) flag=True flag2=True for i in range(n): if int(x[i])>=int(z[i]): flag=False break for i in range(n): if int(x[i])<=int(z[i]): flag2=False break if flag or flag2 : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var z : Sequence := s.subrange(n+1)->sort() ; var x : Sequence := s.subrange(1,n)->sort() ; var flag : boolean := true ; var flag2 : boolean := true ; for i : Integer.subrange(0, n-1) do ( if (("" + ((x[i+1])))->toInteger()->compareTo(("" + ((z[i+1])))->toInteger())) >= 0 then ( flag := false ; break ) else skip) ; for i : Integer.subrange(0, n-1) do ( if (("" + ((x[i+1])))->toInteger()->compareTo(("" + ((z[i+1])))->toInteger())) <= 0 then ( flag2 := false ; break ) else skip) ; if flag or flag2 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict n,m=map(int,input().split()) l=[int(_)for _ in input().split()] d=defaultdict(); c=0 for i in range(len(l)): if d.get(l[i]): d[l[i]]+=1 else : d[l[i]]=1 for i in range(len(l)): d[l[i]]-=1 c+=n-(i+1)-d[l[i]] print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var d : OclAny := defaultdict(); var c : int := 0 ; for i : Integer.subrange(0, (l)->size()-1) do ( if d.get(l[i+1]) then ( d[l[i+1]+1] := d[l[i+1]+1] + 1 ) else ( d[l[i+1]+1] := 1 )) ; for i : Integer.subrange(0, (l)->size()-1) do ( d[l[i+1]+1] := d[l[i+1]+1] - 1 ; c := c + n - (i + 1) - d[l[i+1]+1]) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x1,y1,x2,y2=[float(x)for x in input().split(" ")] print(((x2-x1)**2+(y2-y1)**2)**(1/2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toReal())) ; execute (((((x2 - x1))->pow(2) + ((y2 - y1))->pow(2)))->pow((1 / 2)))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as m x1,y1,x2,y2=map(float,input().split()) X=x2-x1 Y=y2-y1 X=m.pow(X,2) Y=m.pow(Y,2) distance=m.sqrt((X+Y)) print(f'{distance}',end='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; var X : double := x2 - x1 ; var Y : double := y2 - y1 ; X := m.pow(X, 2) ; Y := m.pow(Y, 2) ; var distance : double := m.sqrt((X + Y)) ; execute (StringLib.formattedString('{distance}'))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a,b,c,d=map(int,input().split()) t=[a,b,c,d] if k<=n or n==4 : print(-1) else : ans=[a,c] for i in range(1,n+1): if i not in t : ans.append(i) ans.append(d) ans.append(b) print(*ans) print(c,a,end=' ') for i in range(n,0,-1): if i not in t : print(i,end=' ') print(b,d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : Sequence := Sequence{a}->union(Sequence{b}->union(Sequence{c}->union(Sequence{ d }))) ; if (k->compareTo(n)) <= 0 or n = 4 then ( execute (-1)->display() ) else ( var ans : Sequence := Sequence{a}->union(Sequence{ c }) ; for i : Integer.subrange(1, n + 1-1) do ( if (t)->excludes(i) then ( execute ((i) : ans) ) else skip) ; execute ((d) : ans) ; execute ((b) : ans) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ; execute (c)->display() ; for i : Integer.subrange(0 + 1, n)->reverse() do ( if (t)->excludes(i) then ( execute (i)->display() ) else skip) ; execute (b)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a,b,c,d=map(int,input().split()) if(k-1collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if ((k - 1->compareTo(n)) < 0 or n < 5) then ( execute (-1)->display() ) else ( execute (a)->display() ; for i : Integer.subrange(1, n + 1-1) do ( if ((Sequence{a}->union(Sequence{b}->union(Sequence{c}->union(Sequence{ d }))))->excludes(i)) then ( execute (i)->display() ) else skip) ; execute (d)->display() ; execute (c)->display() ; for i : Integer.subrange(1, n + 1-1) do ( if ((Sequence{a}->union(Sequence{b}->union(Sequence{c}->union(Sequence{ d }))))->excludes(i)) then ( execute (i)->display() ) else skip) ; execute (b)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a,b,c,d=map(int,input().split()) if n==4 or kcollect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 4 or (k->compareTo(n + 1)) < 0 then ( execute (-1)->display() ) else ( var A : Sequence := Sequence{} ; var B : Sequence := Sequence{} ; execute ((a) : A) ; execute ((c) : A) ; execute ((c) : B) ; execute ((a) : B) ; var i : int := 1 ; while (i->compareTo(n + 1)) < 0 do ( if i /= a & i /= b & i /= c & i /= d then ( execute ((i) : A) ; execute ((i) : B) ) else skip ; i := i + 1) ; execute ((d) : A) ; execute ((b) : A) ; execute ((b) : B) ; execute ((d) : B) ; execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name A))))))) ))))))))->display() ; execute ((argument * (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name B))))))) ))))))))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n,k,m=map(int,input().split()) if not n and not k and not m : break l=list(range(1,n+1)) p=l.index(m) while len(l)>1 : l.pop(p) p=(p+k-1)% len(l) print(l[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : OclAny := null; var k : OclAny := null; var m : OclAny := null; Sequence{n,k,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if not(n) & not(k) & not(m) then ( break ) else skip ; var l : Sequence := (Integer.subrange(1, n + 1-1)) ; var p : int := l->indexOf(m) - 1 ; while (l)->size() > 1 do ( l := l->excludingAt(p+1) ; p := (p + k - 1) mod (l)->size()) ; execute (l->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**10 mod=998244353 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] while True : n,k,m=LI() if n==0 : break a=list(range(1,n+1)) t=m-1 for i in range(n-1): a=a[: t]+a[t+1 :] t=(t-1+k)% len(a) rr.append(a[0]) return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : int := 998244353 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var n : OclAny := null; var k : OclAny := null; var m : OclAny := null; Sequence{n,k,m} := LI() ; if n = 0 then ( break ) else skip ; var a : Sequence := (Integer.subrange(1, n + 1-1)) ; var t : double := m - 1 ; for i : Integer.subrange(0, n - 1-1) do ( a := a.subrange(1,t) + a.subrange(t + 1+1) ; t := (t - 1 + k) mod (a)->size()) ; execute ((a->first()) : rr)) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,k,m): table=[i+1 for i in range(n)] taget=m-1 while(len(table)>1): table.pop(taget) taget-=1 taget=(taget+k)% len(table) return table[0] if __name__=='__main__' : ans=[] while(True): n,k,m=map(int,input().split()) if n==0 and k==0 and m==0 : break ans.append(solve(n,k,m)) print(*ans,sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var ans : Sequence := Sequence{} ; while (true) do ( Sequence{n,k,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 & k = 0 & m = 0 then ( break ) else skip ; execute ((solve(n, k, m)) : ans)) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ) else skip; operation solve(n : OclAny, k : OclAny, m : OclAny) : OclAny pre: true post: true activity: var table : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (i + 1)) ; var taget : double := m - 1 ; while ((table)->size() > 1) do ( table := table->excludingAt(taget+1) ; taget := taget - 1 ; taget := (taget + k) mod (table)->size()) ; return table->first(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ans=[] while True : N,K,M=map(int,input().split()) if not N and not K and not M : break remind=[i for i in range(N)] now=M-1 while len(remind)>1 : remind.pop(now) now=(now+K-1)% len(remind) ans.append(remind[0]) [print(i+1)for i in ans] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ans : Sequence := Sequence{} ; while true do ( var N : OclAny := null; var K : OclAny := null; var M : OclAny := null; Sequence{N,K,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if not(N) & not(K) & not(M) then ( break ) else skip ; var remind : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (i)) ; var now : double := M - 1 ; while (remind)->size() > 1 do ( remind := remind->excludingAt(now+1) ; now := (now + K - 1) mod (remind)->size()) ; execute ((remind->first()) : ans)) ; ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(): for line in sys.stdin : n,k,m=map(int,line.split()) if not(n or k or m): break stone=list(range(1,n+1)) m-=1 while len(stone)>1 : stone.pop(m) m=(m+k-1)% len(stone) print(stone[0]) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: for line : OclFile["System.in"] do ( var n : OclAny := null; var k : OclAny := null; var m : OclAny := null; Sequence{n,k,m} := (line.split())->collect( _x | (OclType["int"])->apply(_x) ) ; if not((n or k or m)) then ( break ) else skip ; var stone : Sequence := (Integer.subrange(1, n + 1-1)) ; m := m - 1 ; while (stone)->size() > 1 do ( stone := stone->excludingAt(m+1) ; var m : int := (m + k - 1) mod (stone)->size()) ; execute (stone->first())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()); x=list(map(int,input().split())) for i in range(n): t=x[i]; print(min(abs(t-x[i-1]),abs(x[i-n+1]-t)),max(t-x[0],x[n-1]-t)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( var t : OclAny := x[i+1]; execute (Set{(t - x[i - 1+1])->abs(), (x[i - n + 1+1] - t)->abs()}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=str(input()) x=[int(num)for num in list(arr)] half_1=x[: n] half_1.sort() half_2=x[n :] half_2.sort() s_inc=True s_dec=True for i in range(0,n): if half_1[i]half_2[i]: s_inc=False else : s_inc=s_dec=False if not(s_inc or s_dec): break print("YES")if(s_inc or s_dec)else print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : String := ("" + (((OclFile["System.in"]).readLine()))) ; var x : Sequence := (arr)->characters()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var half var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() : OclAny := x.subrange(1,n) ; halfhalfhalfhalfhalfhalfhalf var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()->sort()->sort()->sort()->sort()->sort()->sort() := halfhalfhalfhalfhalfhalfhalf var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()->sort()->sort()->sort()->sort()->sort()->sort()->sort() ; var half:= x.subrange(n+1) : OclAny := x.subrange(n+1) ; half->sort() := half->sort()->sort() ; var s_inc : boolean := true ; var s_dec : boolean := true ; for i : Integer.subrange(0, n-1) do ( if (half var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()[i+1]->compareTo(half s_dec := false[i+1])) < 0 then ( s_dec := false ) else (if (half var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()[i+1]->compareTo(half s_inc := false[i+1])) > 0 then ( s_inc := false ) else ( s_inc := false; s_dec := false ) ) ; if not((s_inc or s_dec)) then ( break ) else skip) ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))) if (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (expr (atom (name s_inc))))) or (logical_test (comparison (expr (atom (name s_dec)))))))) ))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def linear_search(A,key): N=len(A) A[N-1]=key i=0 while A[i]!=key : i+=1 return i!=(N-1) if __name__=="__main__" : N=int(input()) num_list=list(map(int,input().split())) M=int(input()) target_list=list(map(int,input().split())) count=0 for target in target_list : if(linear_search(num_list,target)): count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var num_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var M : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var target_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : int := 0 ; for target : target_list do ( if (linear_search(num_list, target)) then ( count := count + 1 ) else skip) ; execute (count)->display() ) else skip; operation linear_search(A : OclAny, key : OclAny) : OclAny pre: true post: true activity: var N : int := (A)->size() ; A[N - 1+1] := key ; var i : int := 0 ; while A[i+1] /= key do ( i := i + 1) ; return i /= (N - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) S=[int(x)for x in input().split()] q=int(input()) T=[int(x)for x in input().split()] ans=0 for i in range(q): find=0 for j in range(n): if S[j]==T[i]: find=1 ans=ans+find print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var T : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : int := 0 ; for i : Integer.subrange(0, q-1) do ( var find : int := 0 ; for j : Integer.subrange(0, n-1) do ( if S[j+1] = T[i+1] then ( find := 1 ) else skip) ; ans := ans + find) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,collections input=lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(10**7) INF=10**10 def I(): return int(input()) def F(): return float(input()) def SS(): 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 LSS(): return input().split() def resolve(): n=I() S=LI() q=I() T=LI() cnt=0 for i in T : if i in S : cnt+=1 print(cnt) if __name__=='__main__' : resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : Function := lambda $$ : OclAny in (sys.stdin.readLine().rstrip()) ; sys.setrecursionlimit((10)->pow(7)) ; var INF : double := (10)->pow(10) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( resolve() ) else skip; operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation SS() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation LI() : OclAny pre: true post: true activity: return input->apply().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return input->apply().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return input->apply().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LSS() : OclAny pre: true post: true activity: return input->apply().split(); operation resolve() pre: true post: true activity: var n : OclAny := I() ; var S : OclAny := LI() ; var q : OclAny := I() ; var T : OclAny := LI() ; var cnt : int := 0 ; for i : T do ( if (S)->includes(i) then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,s,q,t=input(),set(map(int,input().split())),input(),set(map(int,input().split())) print(sum(i in s for i in t)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var s : OclAny := null; var q : OclAny := null; var t : OclAny := null; Sequence{n,s,q,t} := Sequence{(OclFile["System.in"]).readLine(),Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))),(OclFile["System.in"]).readLine(),Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) )))} ; execute (((argument (test (logical_test (comparison (comparison (expr (atom (name i)))) in (comparison (expr (atom (name s))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name t))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def judge(array,key): if key in array : return True else : return False s_length=int(input()) array_s=[int(i)for i in input().split()] t_length=int(input()) array_t=[int(i)for i in input().split()] cnt=0 for i in range(t_length): key=array_t[i] if judge(array_s,key): cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s_length : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var array_s : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var t_length : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var array_t : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var cnt : int := 0 ; for i : Integer.subrange(0, t_length-1) do ( key := array_t[i+1] ; if judge(array_s, key) then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display(); operation judge(array : OclAny, key : OclAny) : OclAny pre: true post: true activity: if (array)->includes(key) then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pairAndSum(arr,n): ans=0 for i in range(0,32): k=0 for j in range(0,n): if((arr[j]&(1<union(Sequence{10}->union(Sequence{ 15 })) ; n := (arr)->size() ; execute (pairAndSum(arr, n))->display(); operation pairAndSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, 32-1) do ( var k : int := 0 ; for j : Integer.subrange(0, n-1) do ( if ((MathLib.bitwiseAnd(arr[j+1], (1 * (2->pow(i)))))) then ( k := k + 1 ) else skip) ; ans := ans + (1 * (2->pow(i))) * (k * (k - 1) div 2)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairs(arr,n): cnt=0 ; for i in range(n): for j in range(i+1,n): if(arr[i]!=arr[j]): cnt+=1 ; return cnt ; if __name__=='__main__' : arr=[1,1,2]; n=len(arr); print(countPairs(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{1}->union(Sequence{ 2 })); ; n := (arr)->size(); ; execute (countPairs(arr, n))->display(); ) else skip; operation countPairs(arr : OclAny, n : OclAny) pre: true post: true activity: var cnt : int := 0; ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if (arr[i+1] /= arr[j+1]) then ( cnt := cnt + 1; ) else skip)) ; return cnt;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pairORSum(arr,n): ans=0 for i in range(0,n): for j in range((i+1),n): ans=ans+arr[i]| arr[j] return ans arr=[1,2,3,4] n=len(arr) print(pairORSum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))) ; n := (arr)->size() ; execute (pairORSum(arr, n))->display(); operation pairORSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange((i + 1), n-1) do ( ans := MathLib.bitwiseOr(ans + arr[i+1], arr[j+1]))) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairs(arr,n): ans=0 for i in range(0,n): j=i-1 while(j>=0): if(arr[i]*arr[j]>arr[i]+arr[j]): ans=ans+1 j=j-1 return ans arr=[3,4,5] n=len(arr) k=countPairs(arr,n) print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })) ; n := (arr)->size() ; var k : OclAny := countPairs(arr, n) ; execute (k)->display(); operation countPairs(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var j : double := i - 1 ; while (j >= 0) do ( if ((arr[i+1] * arr[j+1]->compareTo(arr[i+1] + arr[j+1])) > 0) then ( ans := ans + 1 ) else skip ; j := j - 1)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) arr=list(map(int,input().split())) brr=[0]*m for i in range(n): brr[arr[i]-1]=brr[arr[i]-1]+1 result=0 for i in range(m-1): result=result+brr[i]*sum(brr[i+1 :]) print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var brr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; for i : Integer.subrange(0, n-1) do ( brr[arr[i+1] - 1+1] := brr[arr[i+1] - 1+1] + 1) ; var result : int := 0 ; for i : Integer.subrange(0, m - 1-1) do ( result := result + brr[i+1] * (brr.subrange(i + 1+1))->sum()) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pairAndSum(arr,n): ans=0 for i in range(0,n): for j in range((i+1),n): ans=ans+arr[i]& arr[j] return ans arr=[5,10,15] n=len(arr) print(pairAndSum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{5}->union(Sequence{10}->union(Sequence{ 15 })) ; n := (arr)->size() ; execute (pairAndSum(arr, n))->display(); operation pairAndSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange((i + 1), n-1) do ( ans := MathLib.bitwiseAnd(ans + arr[i+1], arr[j+1]))) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=str(input()) x=[int(num)for num in list(arr)] half_1=x[: n] half_1.sort() half_2=x[n :] half_2.sort() s_inc=True s_dec=True for i in range(0,n): if half_1[i]half_2[i]: s_inc=False else : s_inc=s_dec=False if not(s_inc or s_dec): break print("YES")if(s_inc or s_dec)else print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : String := ("" + (((OclFile["System.in"]).readLine()))) ; var x : Sequence := (arr)->characters()->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var half var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() : OclAny := x.subrange(1,n) ; halfhalfhalfhalfhalfhalfhalf var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()->sort()->sort()->sort()->sort()->sort()->sort() := halfhalfhalfhalfhalfhalfhalf var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()->sort()->sort()->sort()->sort()->sort()->sort()->sort() ; var half:= x.subrange(n+1) : OclAny := x.subrange(n+1) ; half->sort() := half->sort()->sort() ; var s_inc : boolean := true ; var s_dec : boolean := true ; for i : Integer.subrange(0, n-1) do ( if (half var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()[i+1]->compareTo(half s_dec := false[i+1])) < 0 then ( s_dec := false ) else (if (half var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger()[i+1]->compareTo(half s_inc := false[i+1])) > 0 then ( s_inc := false ) else ( s_inc := false; s_dec := false ) ) ; if not((s_inc or s_dec)) then ( break ) else skip) ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))) if (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (expr (atom (name s_inc))))) or (logical_test (comparison (expr (atom (name s_dec)))))))) ))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairs(arr,n): cnt=0 for i in range(n-1): for j in range(i+1,n,1): if((arr[i]| arr[j])<=max(arr[i],arr[j])): cnt+=1 return cnt if __name__=='__main__' : arr=[1,2,3] n=len(arr) print(countPairs(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; n := (arr)->size() ; execute (countPairs(arr, n))->display() ) else skip; operation countPairs(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(i + 1, n-1)->select( $x | ($x - i + 1) mod 1 = 0 ) do ( if (((MathLib.bitwiseOr(arr[i+1], arr[j+1]))->compareTo(Set{arr[i+1], arr[j+1]}->max())) <= 0) then ( cnt := cnt + 1 ) else skip)) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairs(arr,n): ans=0 for i in range(0,n): for j in range(i+1,n): if(arr[i]==arr[j]): ans+=1 return ans arr=[1,1,2] n=len(arr) print(countPairs(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{1}->union(Sequence{ 2 })) ; n := (arr)->size() ; execute (countPairs(arr, n))->display(); operation countPairs(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if (arr[i+1] = arr[j+1]) then ( ans := ans + 1 ) else skip)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CountPairs(arr,n): count=0 ; for i in range(n): for j in range(i+1,n): if(arr[i]+arr[j]>0): count+=1 ; return count ; if __name__=="__main__" : arr=[-7,-1,3,2]; n=len(arr); print(CountPairs(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{-7}->union(Sequence{-1}->union(Sequence{3}->union(Sequence{ 2 }))); ; n := (arr)->size(); ; execute (CountPairs(arr, n))->display(); ) else skip; operation CountPairs(arr : OclAny, n : OclAny) pre: true post: true activity: var count : int := 0; ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if (arr[i+1] + arr[j+1] > 0) then ( count := count + 1; ) else skip)) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pairORSum(arr,n): ans=0 for i in range(0,32): k1=0 k0=0 for j in range(0,n): if((arr[j]&(1<union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))) ; n := (arr)->size() ; execute (pairORSum(arr, n))->display(); operation pairORSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, 32-1) do ( var k1 : int := 0 ; var k0 : int := 0 ; for j : Integer.subrange(0, n-1) do ( if ((MathLib.bitwiseAnd(arr[j+1], (1 * (2->pow(i)))))) then ( k1 := k1 + 1 ) else ( k0 := k0 + 1 )) ; ans := ans + (1 * (2->pow(i))) * (k1 * (k1 - 1) div 2) + (1 * (2->pow(i))) * (k1 * k0)) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countPairs(arr,n): count=0 ; for i in range(n-1): for j in range(i+1,n): if(arr[i]*arr[j]==arr[i]+arr[j]): count+=1 ; return count ; if __name__=="__main__" : arr=[2,0,3,2,0]; n=len(arr); print(countPairs(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{2}->union(Sequence{0}->union(Sequence{3}->union(Sequence{2}->union(Sequence{ 0 })))); ; n := (arr)->size(); ; execute (countPairs(arr, n))->display(); ) else skip; operation countPairs(arr : OclAny, n : OclAny) pre: true post: true activity: var count : int := 0; ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if (arr[i+1] * arr[j+1] = arr[i+1] + arr[j+1]) then ( count := count + 1; ) else skip)) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def pairORSum(arr,n): ans=0 for i in range(0,n): for j in range(i+1,n): ans=ans+(arr[i]^ arr[j]) return ans arr=[5,9,7,6] n=len(arr) print(pairORSum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{5}->union(Sequence{9}->union(Sequence{7}->union(Sequence{ 6 }))) ; n := (arr)->size() ; execute (pairORSum(arr, n))->display(); operation pairORSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( ans := ans + (MathLib.bitwiseXor(arr[i+1], arr[j+1])))) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findString(str,n,k): if(k==0): print(str) return str2=str p=0 for i in range(0,n,1): if(str2[i]!='a'): str2=str2.replace(str2[i],'a') p+=1 if(p==k): break if(p=0): if(str[i]=='a'): str2=str2.replace(str2[i],'b') p+=1 if(p==k): break i-=1 print(str2) if __name__=='__main__' : str="pqrs" n=len(str) k=2 findString(str,n,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( OclType["String"] := "pqrs" ; n := (OclType["String"])->size() ; k := 2 ; findString(OclType["String"], n, k) ) else skip; operation findString(OclType["String"] : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: if (k = 0) then ( execute (OclType["String"])->display() ; return ) else skip ; var str2 : String := OclType["String"] ; var p : int := 0 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (str2[i+1] /= 'a') then ( str2 := str2.replace(str2[i+1], 'a') ; p := p + 1 ; if (p = k) then ( break ) else skip ) else skip) ; if ((p->compareTo(k)) < 0) then ( var i : double := n - 1 ; while (i >= 0) do ( if (("" + ([i+1])) = 'a') then ( str2 := str2.replace(str2[i+1], 'b') ; p := p + 1 ) else skip ; if (p = k) then ( break ) else skip ; i := i - 1) ) else skip ; execute (str2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSum(arr,n,k): ans=arr[n-k-1]-arr[0]; for i in range(1,k+1): ans=min(arr[n-1-(k-i)]-arr[i],ans); return ans ; if __name__=="__main__" : arr=[1,2,100,120,140]; k=2 ; n=len(arr); print(findSum(arr,n,k)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{100}->union(Sequence{120}->union(Sequence{ 140 })))); ; k := 2; ; n := (arr)->size(); ; execute (findSum(arr, n, k))->display(); ) else skip; operation findSum(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var ans : double := arr[n - k - 1+1] - arr->first(); ; for i : Integer.subrange(1, k + 1-1) do ( ans := Set{arr[n - 1 - (k - i)+1] - arr[i+1], ans}->min();) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def convert(dec): s="" d=dec while True : div=d//8 rem=d % 8 d=div if rem==4 : rem=5 elif rem==5 : rem=7 elif rem==6 : rem=8 elif rem==7 : rem=9 s=str(rem)+s if div<=0 : break return s for s in sys.stdin : if int(s)==0 : break print(convert(int(s))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; for s : OclFile["System.in"] do ( if ("" + ((s)))->toInteger() = 0 then ( break ) else skip ; execute (convert(("" + ((s)))->toInteger()))->display()); operation convert(dec : OclAny) : OclAny pre: true post: true activity: var s : String := "" ; var d : OclAny := dec ; while true do ( var div : int := d div 8 ; var rem : int := d mod 8 ; d := div ; if rem = 4 then ( rem := 5 ) else (if rem = 5 then ( rem := 7 ) else (if rem = 6 then ( rem := 8 ) else (if rem = 7 then ( rem := 9 ) else skip ) ) ) ; s := ("" + ((rem))) + s ; if div <= 0 then ( break ) else skip) ; return s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) a=list(map(int,input().split())) from collections import defaultdict cnt=defaultdict(int) for x in a : cnt[x]+=1 print(sum(cnt[x]*cnt[y]for x in cnt for y in cnt if xcollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; var cnt : OclAny := defaultdict(OclType["int"]) ; for x : a do ( cnt[x+1] := cnt[x+1] + 1) ; execute (((argument (test (logical_test (comparison (expr (expr (atom (name cnt)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name x)))))))) ]))) * (expr (atom (name cnt)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name y)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name cnt))))) (comp_iter (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name cnt))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name x)))) < (comparison (expr (atom (name y)))))))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isReachable(sx,sy,dx,dy): if(sx>dx or sy>dy): return False if(sx==dx and sy==dy): return True return(isReachable(sx+sy,sy,dx,dy)or isReachable(sx,sy+sx,dx,dy)) source_x,source_y=2,10 dest_x,dest_y=26,12 if(isReachable(source_x,source_y,dest_x,dest_y)): print("True") else : print("False") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var source_x : OclAny := null; var source_y : OclAny := null; Sequence{source_x,source_y} := Sequence{2,10} ; var dest_x : OclAny := null; var dest_y : OclAny := null; Sequence{dest_x,dest_y} := Sequence{26,12} ; if (isReachable(source_x, source_y, dest_x, dest_y)) then ( execute ("True")->display() ) else ( execute ("False")->display() ); operation isReachable(sx : OclAny, sy : OclAny, dx : OclAny, dy : OclAny) : OclAny pre: true post: true activity: if ((sx->compareTo(dx)) > 0 or (sy->compareTo(dy)) > 0) then ( return false ) else skip ; if (sx = dx & sy = dy) then ( return true ) else skip ; return (isReachable(sx + sy, sy, dx, dy) or isReachable(sx, sy + sx, dx, dy)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections def solve(rows): cnt=collections.Counter() for i in rows : cnt.update(i) rst=[] for k,v in cnt.items(): if v % 2 : rst.append(k) return ' '.join(map(str,sorted(rst))) def main(): nr_case=int(input()) for case in range(nr_case): N=int(input()) rows=[] for i in range(N*2-1): rows.append(list(map(int,input().split()))) print('Case #{}:{}'.format(case+1,solve(rows))) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(rows : OclAny) : OclAny pre: true post: true activity: var cnt : OclAny := .Counter() ; for i : rows do ( execute ((i) <: cnt)) ; var rst : Sequence := Sequence{} ; for _tuple : cnt->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if v mod 2 then ( execute ((k) : rst) ) else skip) ; return StringLib.sumStringsWithSeparator(((rst->sort())->collect( _x | (OclType["String"])->apply(_x) )), ' '); operation main() pre: true post: true activity: var nr_case : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for case : Integer.subrange(0, nr_case-1) do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; rows := Sequence{} ; for i : Integer.subrange(0, N * 2 - 1-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : rows)) ; execute (StringLib.interpolateStrings('Case #{}:{}', Sequence{case + 1, solve(rows)}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): x=int(input()) print("%s %s" %(1,x-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (StringLib.format("%s %s",Sequence{1, x - 1}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- task='B' type=2 from collections import Counter if type==0 : inp=open('sample.in','r') elif type==1 : inp=open('%s-small.in' %(task,)) else : inp=open('%s-large.in' %(task),) outp=open('%s.out' %(task,),'w') T=int(inp.readline()[:-1]) for i in range(T): ans=[] N=int(inp.readline()[:-1]) c=Counter() for j in range(2*N-1): s=inp.readline()[:-1].split() for k in s : c[k]+=1 for val in c.items(): if val[1]% 2==1 : ans.append(val[0]) ans.sort(key=int) outp.write("Case #%s: %s\n" %(i+1," ".join(ans))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var task : String := 'B' ; var type : int := 2 ; skip ; if type = 0 then ( var inp : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('sample.in')) ) else (if type = 1 then ( inp := OclFile.newOclFile_Write(OclFile.newOclFile(StringLib.format('%s-small.in',Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name task)))))) ,)}))) ) else ( inp := OclFile.newOclFile_Write(OclFile.newOclFile(StringLib.format('%s-large.in',(task)))) ) ) ; var outp : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(StringLib.format('%s.out',Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name task)))))) ,)}))) ; var T : int := ("" + ((inp.readLine()->front())))->toInteger() ; for i : Integer.subrange(0, T-1) do ( var ans : Sequence := Sequence{} ; var N : int := ("" + ((inp.readLine()->front())))->toInteger() ; var c : OclAny := Counter() ; for j : Integer.subrange(0, 2 * N - 1-1) do ( var s : OclAny := inp.readLine()->front().split() ; for k : s do ( c[k+1] := c[k+1] + 1)) ; for val : c->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do ( if val[1+1] mod 2 = 1 then ( execute ((val->first()) : ans) ) else skip) ; ans := ans->sort() ; outp.write(StringLib.format("Case #%s: %s\n",Sequence{i + 1, StringLib.sumStringsWithSeparator((ans), " ")}))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys fin=open(sys.argv[1],"r") fout=open("p2.out","w") T=int(fin.readline()) for tt in xrange(T): N=int(fin.readline()) times={} for i in xrange(2*N-1): info=map(int,fin.readline().split()) for x in info : if x not in times : times[x]=1 else : times[x]+=1 ans=[] for x in times : if times[x]% 2==1 : ans.append(x) ans=' '.join(map(str,sorted(ans))) fout.write("Case #"+str(tt+1)+": "+ans+"\n") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var fin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) ; var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("p2.out")) ; var T : int := ("" + ((fin.readLine())))->toInteger() ; for tt : xrange(T) do ( var N : int := ("" + ((fin.readLine())))->toInteger() ; var times : OclAny := Set{} ; for i : xrange(2 * N - 1) do ( var info : Sequence := (fin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for x : info do ( if (times)->excludes(x) then ( times[x+1] := 1 ) else ( times[x+1] := times[x+1] + 1 ))) ; var ans : Sequence := Sequence{} ; for x : times do ( if times[x+1] mod 2 = 1 then ( execute ((x) : ans) ) else skip) ; ans := StringLib.sumStringsWithSeparator(((ans->sort())->collect( _x | (OclType["String"])->apply(_x) )), ' ') ; fout.write("Case #" + ("" + ((tt + 1))) + ": "->union(ans) + "\n")); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import io,sys import datetime,copy fin=None def solve(): n=num() cnts={} for _ in range(2*n-1): t=nums() for x in t : if x in cnts : cnts[x]+=1 else : cnts[x]=1 res=[] for k,v in cnts.items(): if v % 2==1 : res.append(k) res.sort() return ' '.join([str(x)for x in res]) def main(): fname='a.in' if len(sys.argv)>1 : fname=sys.argv[1] global fin fin=io.open(fname) fout=io.open(fname+'.out','w') t0=datetime.datetime.now() t=int(fin.readline()) for i in range(t): fout.write('Case #%d: ' %(i+1)) fout.write('%s\n' % str(solve())) print('Time=%s' % str(datetime.datetime.now()-t0)) fin.close() fout.close() def nums(): return[int(x)for x in fin.readline().split()] def fnums(): return[float(x)for x in fin.readline().split()] def num(): return int(fin.readline()) def sstrip(): return fin.readline().strip() def strs(): return fin.readline().split() def arrstr(a,sep=' '): return sep.join([str(x)for x in a]) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { attribute fin : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; var fin : OclAny := null ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve() : OclAny pre: true post: true activity: var n : OclAny := num() ; var cnts : OclAny := Set{} ; for _anon : Integer.subrange(0, 2 * n - 1-1) do ( var t : OclAny := nums() ; for x : t do ( if (cnts)->includes(x) then ( cnts[x+1] := cnts[x+1] + 1 ) else ( cnts[x+1] := 1 ))) ; var res : Sequence := Sequence{} ; for _tuple : cnts->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if v mod 2 = 1 then ( execute ((k) : res) ) else skip) ; res := res->sort() ; return StringLib.sumStringsWithSeparator((res->select(x | true)->collect(x | (("" + ((x)))))), ' '); operation main() pre: true post: true activity: var fname : String := 'a.in' ; if ((trailer . (name argv)))->size() > 1 then ( fname := (trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])) ) else skip ; skip ; fin := io.open(fname) ; var fout : OclAny := io.open(fname + '.out', 'w') ; var t0 : OclAny := datetime.datetime.now() ; t := ("" + ((fin.readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( fout.write(StringLib.format('Case #%d: ',(i + 1))) ; fout.write(StringLib.format('%s ',("" + ((solve())))))) ; execute (StringLib.format('Time=%s',("" + ((datetime.datetime.now() - t0)))))->display() ; fin.closeFile() ; fout.closeFile(); operation nums() : OclAny pre: true post: true activity: return fin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation fnums() : OclAny pre: true post: true activity: return fin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation num() : OclAny pre: true post: true activity: return ("" + ((fin.readLine())))->toInteger(); operation sstrip() : OclAny pre: true post: true activity: return fin.readLine()->trim(); operation strs() : OclAny pre: true post: true activity: return fin.readLine().split(); operation arrstr(a : OclAny, sep : String) : OclAny pre: true post: true activity: if sep->oclIsUndefined() then sep := ' ' else skip; return StringLib.sumStringsWithSeparator((a->select(x | true)->collect(x | (("" + ((x)))))), sep); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter def one_test(): n=int(input()) a=[] for i in range(2*n-1): a.extend(map(int,input().split())) c=Counter(a) ans=sorted(k for k,v in c.items()if v % 2==1) return ' '.join(map(str,ans)) t=int(input()) for i in range(1,t+1): print("Case #{}:{}".format(i,one_test())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(1, t + 1-1) do ( execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{i, one_test()}))->display()); operation one_test() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, 2 * n - 1-1) do ( a := a->union((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var c : OclAny := Counter(a) ; var ans : Sequence := (argument (test (logical_test (comparison (expr (atom (name k)))))) (comp_for for (exprlist (expr (atom (name k))) , (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name c)) (trailer . (name items) (arguments ( )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (expr (atom (name v))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 1)))))))))))->sort() ; return StringLib.sumStringsWithSeparator(((ans)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def totalFruit(self,tree): ans=i=0 count=collections.Counter() for j,x in enumerate(tree): count[x]+=1 while len(count)>=3 : count[tree[i]]-=1 if count[tree[i]]==0 : del count[tree[i]] i+=1 ans=max(ans,j-i+1) return ans ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation totalFruit(tree : OclAny) : OclAny pre: true post: true activity: var ans : OclAny := 0; var i : int := 0 ; var count : OclAny := .Counter() ; for _tuple : Integer.subrange(1, (tree)->size())->collect( _indx | Sequence{_indx-1, (tree)->at(_indx)} ) do (var _indx : int := 1; var j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); count[x+1] := count[x+1] + 1 ; while (count)->size() >= 3 do ( count[tree[i+1]+1] := count[tree[i+1]+1] - 1 ; if count[tree[i+1]+1] = 0 then ( execute (count[tree[i+1]+1])->isDeleted() ) else skip ; i := i + 1) ; ans := Set{ans, j - i + 1}->max()) ; return ans; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N,K=map(int,input().split()) ans=0 for b in range(1,N+1): p=N//b r=N % b ans+=p*max(0,b-K)+max(0,r+1-K)-(K==0) print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; for b : Integer.subrange(1, N + 1-1) do ( var p : int := N div b ; var r : int := N mod b ; ans := ans + p * Set{0, b - K}->max() + Set{0, r + 1 - K}->max() - (K = 0)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from heapq import heappush,heappop from itertools import permutations,accumulate import sys import math import bisect def LI(): return[int(x)for x in sys.stdin.buffer.readline().split()] def I(): return int(sys.stdin.buffer.readline()) def LS(): return[list(x)for x in sys.stdin.readline().split()] def S(): res=list(sys.stdin.readline()) if res[-1]=="\n" : return res[:-1] return res def IR(n): return[I()for i in range(n)] def LIR(n): return[LI()for i in range(n)] def SR(n): return[S()for i in range(n)] def LSR(n): return[LS()for i in range(n)] sys.setrecursionlimit(1000000) mod=1000000007 def solve(): n,k=LI() if k==0 : print(n**2) return ans=0 for b in range(k+1,n+1): s=n//b ans+=s*(b-k) ans+=max(0,n-s*b-k+1) print(ans) return if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(1000000) ; var mod : int := 1000000007 ; skip ; if __name__ = "__main__" then ( solve() ) else skip; operation LI() : OclAny pre: true post: true activity: return sys.stdin.buffer.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation I() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.buffer.readLine())))->toInteger(); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | ((x))); operation S() : OclAny pre: true post: true activity: var res : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if res->last() = "\n" then ( return res->front() ) else skip ; return res; operation IR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (I())); operation LIR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LI())); operation SR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (S())); operation LSR(n : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, n-1)->select(i | true)->collect(i | (LS())); operation solve() pre: true post: true activity: var k : OclAny := null; Sequence{n,k} := LI() ; if k = 0 then ( execute ((n)->pow(2))->display() ; return ) else skip ; var ans : int := 0 ; for b : Integer.subrange(k + 1, n + 1-1) do ( var s : int := n div b ; ans := ans + s * (b - k) ; ans := ans + Set{0, n - s * b - k + 1}->max()) ; execute (ans)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findPosition(k,n): f1=0 f2=1 i=2 ; while i!=0 : f3=f1+f2 ; f1=f2 ; f2=f3 ; if f2 % k==0 : return n*i i+=1 return n=5 ; k=4 ; print("Position of n'th multiple of k in" "Fibonacci Seires is",findPosition(k,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5; ; k := 4; ; execute ((atom "Position of n'th multiple of k in" "Fibonacci Seires is"))->display();; operation findPosition(k : OclAny, n : OclAny) : OclAny pre: true post: true activity: var f1 : int := 0 ; var f2 : int := 1 ; var i : int := 2; ; while i /= 0 do ( var f3 : int := f1 + f2; ; f1 := f2; ; f2 := f3; ; if f2 mod k = 0 then ( return n * i ) else skip ; i := i + 1) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,K=map(int,input().split(' ')) ans=(N-K)*(N-K+1)//2 if K==0 : print(N**2) exit() for n,i in enumerate(list(range(K+1,N+1))): ans+=(n+1)*((N-i+1)//i)+max(0,(N-i+1)% i-K) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := (N - K) * (N - K + 1) div 2 ; if K = 0 then ( execute ((N)->pow(2))->display() ; exit() ) else skip ; for _tuple : Integer.subrange(1, ((Integer.subrange(K + 1, N + 1-1)))->size())->collect( _indx | Sequence{_indx-1, ((Integer.subrange(K + 1, N + 1-1)))->at(_indx)} ) do (var _indx : int := 1; var n : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); ans := ans + (n + 1) * ((N - i + 1) div i) + Set{0, (N - i + 1) mod i - K}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**9) input=sys.stdin.readline N,K=map(int,input().split()) ans=0 if K==0 : ans=N*N else : for b in range(K+1,N+1): ans+=(N//b)*(b-K) r=N % b if K<=rpow(9)) ; var input : OclAny := (OclFile["System.in"]).readline ; var N : OclAny := null; var K : OclAny := null; Sequence{N,K} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; if K = 0 then ( ans := N * N ) else ( for b : Integer.subrange(K + 1, N + 1-1) do ( ans := ans + (N div b) * (b - K) ; var r : int := N mod b ; if (K->compareTo(r)) <= 0 & (r < b) then ( ans := ans + Set{0, r - K + 1}->max() ) else skip) ) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=list(map(int,input().split())) sub=0 for i in range(1,n+1): s=n//i sub+=s*(min(i,k)) sub+=min(n % i,max(0,k-1)) print(n**2-sub) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var sub : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( var s : int := n div i ; sub := sub + s * (Set{i, k}->min()) ; sub := sub + Set{n mod i, Set{0, k - 1}->max()}->min()) ; execute ((n)->pow(2) - sub)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): print(1,int(input())-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( execute (1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math a,b,x=map(int,input().split()) if a*a*b>=x*2 : c=x*2/(b*a) print(math.degrees(math.atan(b/c))) else : d=2*(b-x/a/a) print(math.degrees(math.atan(d/a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : OclAny := null; var b : OclAny := null; var x : OclAny := null; Sequence{a,b,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a * a * b->compareTo(x * 2)) >= 0 then ( var c : double := x * 2 / (b * a) ; execute ()->display() ) else ( var d : double := 2 * (b - x / a / a) ; execute ()->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np a,b,x=list(map(lambda x : int(x),input().split(" "))) lim_x=float(a*a*b)/2.0 if(x>=lim_x): x_non=float(a*a*b-x) tmp_b=float(2*x_non)/float(a*a) r=np.sqrt(a*a+tmp_b*tmp_b) tmp_a=a tmp_c=r cos_sita=(tmp_a**2+tmp_c**2-tmp_b**2)/(2*tmp_a*tmp_c) sita=np.arccos(cos_sita) print(np.rad2deg(sita)) elif(xcollect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger()))->apply(_x) )) ; var lim_x : double := ("" + ((a * a * b)))->toReal() / 2.0 ; if ((x->compareTo(lim_x)) >= 0) then ( var x_non : double := ("" + ((a * a * b - x)))->toReal() ; var tmp_b : double := ("" + ((2 * x_non)))->toReal() / ("" + ((a * a)))->toReal() ; var r : Sequence := MatrixLib.elementwiseApply(a * a + tmp_b * tmp_b, lambda x : double in (x->sqrt())) ; var tmp_a : OclAny := a ; var tmp_c : Sequence := r ; var cos_sita : double := ((tmp_a)->pow(2) + (tmp_c)->pow(2) - (tmp_b)->pow(2)) / (MatrixLib.elementwiseMult(tmp_c, 2 * tmp_a)) ; var sita : Sequence := MatrixLib.elementwiseApply(cos_sita, lambda x : double in (x->acos())) ; execute ()->display() ) else (if ((x->compareTo(lim_x)) < 0) then ( var a_x : double := (2.0 * x) / (a * b) ; var scale : double := a_x / MatrixLib.elementwiseApply(b * b + a_x * a_x, lambda x : double in (x->sqrt())) ; var under_a : double := a_x * scale ; var under_b : double := b * scale ; tmp_a := a_x ; tmp_b := under_b ; tmp_c := under_a ; cos_sita := ((tmp_a)->pow(2) + (tmp_c)->pow(2) - (tmp_b)->pow(2)) / (MatrixLib.elementwiseMult(tmp_c, 2 * tmp_a)) ; sita := MatrixLib.elementwiseApply(cos_sita, lambda x : double in (x->acos())) ; execute ()->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math from decimal import Decimal a,b,x=list(map(int,input().split())) ans=0 def fb(tilt,a,b): g=b-a*tilt y=g x=-g/tilt if x>0 : return abs(0*0-(x-a)*b)/2 elif y>0 : return(b+y)*a/2 else : return abs(a*b-a*0)/2 def f(angle): a=math.tan(math.radians(angle)) return a high=90 low=0 for i in range(1000): mid=(high+low)/2 m=fb(f(mid),a,b)*a if m>x : low=mid elif mcollect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 0 ; skip ; skip ; var high : int := 90 ; var low : int := 0 ; for i : Integer.subrange(0, 1000-1) do ( var mid : double := (high + low) / 2 ; var m : double := fb(f(mid), a, b) * a ; if (m->compareTo(x)) > 0 then ( low := mid ) else (if (m->compareTo(x)) < 0 then ( high := mid ) else ( ans := mid ; break ) ) ) ; execute (mid)->display(); operation fb(tilt : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var g : double := b - a * tilt ; var y : OclAny := g ; var x : double := -g / tilt ; if x > 0 then ( return (0 * 0 - (x - a) * b)->abs() / 2 ) else (if y > 0 then ( return (b + y) * a / 2 ) else ( return (a * b - a * 0)->abs() / 2 ) ) ; operation f(angle : OclAny) : OclAny pre: true post: true activity: a := ()->tan() ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def calcAgree(n): [a,b,x]=n if a*a*b/2>=x : length1=x/a/b*2 length2=(b**2+length1**2)**0.5 target_angle=math.acos(length1/length2) return target_angle/(2*math.pi)*360 else : air_taiseki=a*a*b-x length1=air_taiseki/a/a*2 length2=(a**2+length1**2)**0.5 target_angle=math.asin(length1/length2) return target_angle/(2*math.pi)*360 input_data=[int(x)for x in input().split()] print(calcAgree(input_data)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input_data : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (calcAgree(input_data))->display(); operation calcAgree(n : OclAny) pre: true post: true activity: ; Sequence{a}->union(Sequence{b}->union(Sequence{ x })) := n ; if (a * a * b / 2->compareTo(x)) >= 0 then ( var length1 : double := x / a / b * 2 ; var length2 : double := (((b)->pow(2) + (length1)->pow(2)))->pow(0.5) ; var target_angle : double := (length1 / length2)->acos() ; return target_angle / (2 * ) * 360 ) else ( var air_taiseki : double := a * a * b - x ; length1 := air_taiseki / a / a * 2 ; length2 := (((a)->pow(2) + (length1)->pow(2)))->pow(0.5) ; target_angle := (length1 / length2)->asin() ; return target_angle / (2 * ) * 360 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys sys.setrecursionlimit(10**5+10) def input(): return sys.stdin.readline().strip() def resolve(): def main(): a,b,x=map(int,input().split()) x=x/a l=0 r=math.pi/2 while l+10**(-10)=x : l=estimate else : r=estimate else : if a*b-(a*a*math.tan(estimate)*0.5)>=x : l=estimate else : r=estimate return math.degrees(l) print(main()) resolve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(5) + 10) ; skip ; skip ; resolve(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation resolve() pre: true post: true activity: skip ; execute (main())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findCount(str): result=0 for i in range(len(str)): if((i==ord(str[i])-ord('a'))or(i==ord(str[i])-ord('A'))): result+=1 return result str='AbgdeF' print(findCount(str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; OclType["String"] := 'AbgdeF' ; execute (findCount(OclType["String"]))->display(); operation findCount(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var result : int := 0 ; for i : Integer.subrange(0, (OclType["String"])->size()-1) do ( if ((i = (("" + ([i+1])))->char2byte() - ('a')->char2byte()) or (i = (("" + ([i+1])))->char2byte() - ('A')->char2byte())) then ( result := result + 1 ) else skip) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): s=input() print(["First","Second"][((s[0]==s[-1])^(len(s)% 2==0))]) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; execute (Sequence{"First"}->union(Sequence{ "Second" })[(MathLib.bitwiseXor((s->first() = s->last()), ((s)->size() mod 2 = 0)))+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- kN=1000000 ; def maxPeople(p): sums=[0]*kN ; sums[0]=0 ; for i in range(1,kN): sums[i]=(i*i)+sums[i-1]; it=lower_bound(sums,0,kN,p); if(it>p): it-=1 ; return it ; def lower_bound(a,low,high,element): while(lowa[middle]): low=middle+1 ; else : high=middle ; return low ; if __name__=='__main__' : p=14 ; print(maxPeople(p)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var kN : int := 1000000; ; skip ; skip ; if __name__ = '__main__' then ( p := 14; ; execute (maxPeople(p))->display(); ) else skip; operation maxPeople(p : OclAny) pre: true post: true activity: var sums : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, kN); ; sums->first() := 0; ; for i : Integer.subrange(1, kN-1) do ( sums[i+1] := (i * i) + sums[i - 1+1];) ; var it : OclAny := lower_bound(sums, 0, kN, p); ; if ((it->compareTo(p)) > 0) then ( it := it - 1; ) else skip ; return it;; operation lower_bound(a : OclAny, low : OclAny, high : OclAny, element : OclAny) pre: true post: true activity: while ((low->compareTo(high)) < 0) do ( var middle : int := ("" + ((low + (high - low) / 2)))->toInteger(); ; if ((element->compareTo(a[middle+1])) > 0) then ( low := middle + 1; ) else ( high := middle; )) ; return low;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import floor,ceil,log2 def powOfPositive(n): pos=floor(log2(n)); return 2**pos ; def powOfNegative(n): pos=ceil(log2(n)); return(-1*pow(2,pos)); def highestPowerOf2(n): if(n>0): print(powOfPositive(n)); else : n=-n ; print(powOfNegative(n)); if __name__=="__main__" : n=-24 ; highestPowerOf2(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = "__main__" then ( n := -24; ; highestPowerOf2(n); ) else skip; operation powOfPositive(n : OclAny) pre: true post: true activity: var pos : OclAny := floor(log2(n)); ; return (2)->pow(pos);; operation powOfNegative(n : OclAny) pre: true post: true activity: pos := ceil(log2(n)); ; return (-1 * (2)->pow(pos));; operation highestPowerOf2(n : OclAny) pre: true post: true activity: if (n > 0) then ( execute (powOfPositive(n))->display(); ) else ( n := -n; ; execute (powOfNegative(n))->display(); ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def turnOffK(n,k): if(k<=0): return n return(n & ~(1<<(k-1))) n=15 k=4 print(turnOffK(n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 15 ; k := 4 ; execute (turnOffK(n, k))->display(); operation turnOffK(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (k <= 0) then ( return n ) else skip ; return (MathLib.bitwiseAnd(n, MathLib.bitwiseNot((1 * (2->pow((k - 1))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate n=int(input()) a=[[0]*1001 for _ in range(1001)] for x1,y1,x2,y2 in(map(int,input().split())for _ in range(n)): a[x1][y1]+=1 a[x1][y2]-=1 a[x2][y1]-=1 a[x2][y2]+=1 print(max(map(max,map(accumulate,zip(*map(accumulate,a)))))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Integer.subrange(0, 1001-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 1001))) ; for _tuple : Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))} do (var _indx : int := 1; var x1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x2 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y2 : OclAny := _tuple->at(_indx); a[x1+1][y1+1] := a[x1+1][y1+1] + 1 ; a[x1+1][y2+1] := a[x1+1][y2+1] - 1 ; a[x2+1][y1+1] := a[x2+1][y1+1] - 1 ; a[x2+1][y2+1] := a[x2+1][y2+1] + 1) ; execute ((((Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name accumulate))))))) , (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name accumulate))))))) , (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name accumulate))))))) , (argument (test (logical_test (comparison (expr (atom (name a)))))))) ))))))))`third->at(_indx)} ))->collect( _x | (accumulate)->apply(_x) ))->collect( _x | (max)->apply(_x) ))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()) for i in range(x): n=int(input()) if n==2 : print(1,1) else : print(1,(n-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, x-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 2 then ( execute (1)->display() ) else ( execute (1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) Z=1000 D=[[0]*(Z+1)for i in range(Z+1)] for i in range(N): x1,y1,x2,y2=map(int,input().split()) D[y1][x1]+=1 D[y1][x2]-=1 D[y2][x1]-=1 D[y2][x2]+=1 for i in range(Z): for j in range(Z): D[i][j+1]+=D[i][j] for j in range(Z): for i in range(Z): D[i+1][j]+=D[i][j] print(max(max(d)for d in D)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var Z : int := 1000 ; var D : Sequence := Integer.subrange(0, Z + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (Z + 1)))) ; for i : Integer.subrange(0, N-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; D[y1+1][x1+1] := D[y1+1][x1+1] + 1 ; D[y1+1][x2+1] := D[y1+1][x2+1] - 1 ; D[y2+1][x1+1] := D[y2+1][x1+1] - 1 ; D[y2+1][x2+1] := D[y2+1][x2+1] + 1) ; for i : Integer.subrange(0, Z-1) do ( for j : Integer.subrange(0, Z-1) do ( D[i+1][j + 1+1] := D[i+1][j + 1+1] + D[i+1][j+1])) ; for j : Integer.subrange(0, Z-1) do ( for i : Integer.subrange(0, Z-1) do ( D[i + 1+1][j+1] := D[i + 1+1][j+1] + D[i+1][j+1])) ; execute (((argument (test (logical_test (comparison (expr (atom (name max)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name d)))))))) ))))))) (comp_for for (exprlist (expr (atom (name d)))) in (logical_test (comparison (expr (atom (name D))))))))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate import sys if __name__=='__main__' : n=int(input()) ys=[0]*1001 rects=[None]*2*n i=0 for line in sys.stdin : x1,y1,x2,y2=[int(j)for j in line.split()] rects[i]=(x2,-1,y1,y2) rects[i+n]=(x1,1,y1,y2) i+=1 rects.sort(key=lambda x : x[0]) max_overlap=0 for x,t,y1,y2 in rects : if t>0 : ys[y1]+=1 ys[y2]-=1 else : overlap=max(accumulate(ys)) if overlap>max_overlap : max_overlap=overlap ys[y1]-=1 ys[y2]+=1 print(max_overlap) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ys : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 1001) ; var rects : Sequence := MatrixLib.elementwiseMult(MatrixLib.elementwiseMult(Sequence{ null }, 2), n) ; var i : int := 0 ; for line : OclFile["System.in"] do ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := line.split()->select(j | true)->collect(j | (("" + ((j)))->toInteger())) ; rects[i+1] := Sequence{x2, -1, y1, y2} ; rects[i + n+1] := Sequence{x1, 1, y1, y2} ; i := i + 1) ; rects := rects->sort() ; var max_overlap : int := 0 ; for _tuple : rects do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var t : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y2 : OclAny := _tuple->at(_indx); if t > 0 then ( ys[y1+1] := ys[y1+1] + 1 ; ys[y2+1] := ys[y2+1] - 1 ) else ( var overlap : OclAny := (accumulate(ys))->max() ; if (overlap->compareTo(max_overlap)) > 0 then ( max_overlap := overlap ) else skip ; ys[y1+1] := ys[y1+1] - 1 ; ys[y2+1] := ys[y2+1] + 1 )) ; execute (max_overlap)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) xs=set(); ys=set() P=[] for i in range(N): x1,y1,x2,y2=map(int,input().split()) xs.add(x1); xs.add(x2) ys.add(y1); ys.add(y2) P.append((x1,x2,y1,y2)) X=sorted(xs); Y=sorted(ys) MX={x : i for i,x in enumerate(X)} MY={y : i for i,y in enumerate(Y)} H=len(Y); W=len(X) S=[[0]*(W+1)for i in range(H+1)] for x1,x2,y1,y2 in P : p1=MY[y1]; q1=MX[x1] p2=MY[y2]; q2=MX[x2] S[p1][q1]+=1 S[p1][q2]-=1 S[p2][q1]-=1 S[p2][q2]+=1 for i in range(H): for j in range(W): S[i][j+1]+=S[i][j] ans=0 for j in range(W): for i in range(H): S[i+1][j]+=S[i][j] ans=max(ans,S[i][j]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var xs : Set := Set{}->union(()); var ys : Set := Set{}->union(()) ; var P : Sequence := Sequence{} ; for i : Integer.subrange(0, N-1) do ( var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((x1) : xs); execute ((x2) : xs) ; execute ((y1) : ys); execute ((y2) : ys) ; execute ((Sequence{x1, x2, y1, y2}) : P)) ; var X : Sequence := xs->sort(); var Y : Sequence := ys->sort() ; var MX : Map := Integer.subrange(1, (X)->size())->collect( _indx | Sequence{_indx-1, (X)->at(_indx)} )->select(_tuple | true)->collect(_tuple | Map{x |-> i})->unionAll() ; var MY : Map := Integer.subrange(1, (Y)->size())->collect( _indx | Sequence{_indx-1, (Y)->at(_indx)} )->select(_tuple | true)->collect(_tuple | Map{y |-> i})->unionAll() ; var H : int := (Y)->size(); var W : int := (X)->size() ; var S : Sequence := Integer.subrange(0, H + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (W + 1)))) ; for _tuple : P do (var _indx : int := 1; var x1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x2 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y2 : OclAny := _tuple->at(_indx); var p1 : OclAny := MY[y1+1]; var q1 : OclAny := MX[x1+1] ; var p2 : OclAny := MY[y2+1]; var q2 : OclAny := MX[x2+1] ; S[p1+1][q1+1] := S[p1+1][q1+1] + 1 ; S[p1+1][q2+1] := S[p1+1][q2+1] - 1 ; S[p2+1][q1+1] := S[p2+1][q1+1] - 1 ; S[p2+1][q2+1] := S[p2+1][q2+1] + 1) ; for i : Integer.subrange(0, H-1) do ( for j : Integer.subrange(0, W-1) do ( S[i+1][j + 1+1] := S[i+1][j + 1+1] + S[i+1][j+1])) ; var ans : int := 0 ; for j : Integer.subrange(0, W-1) do ( for i : Integer.subrange(0, H-1) do ( S[i + 1+1][j+1] := S[i + 1+1][j+1] + S[i+1][j+1] ; ans := Set{ans, S[i+1][j+1]}->max())) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import accumulate N=int(input()) xys=[] m_x=0 m_y=0 for i in range(N): xy=list(map(int,input().split())) xys+=[xy] x_1,y_1,x_2,y_2=xy m_x=max(x_2,m_x) m_y=max(y_2,m_y) im=[[0]*(m_x+1)for i in range(m_y+1)] for xy in xys : x_1,y_1,x_2,y_2=xy im[y_1][x_1]+=1 im[y_1][x_2]-=1 im[y_2][x_1]-=1 im[y_2][x_2]+=1 print(max(map(max,map(accumulate,zip(*map(accumulate,im)))))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var xys : Sequence := Sequence{} ; var m_x : int := 0 ; var m_y : int := 0 ; for i : Integer.subrange(0, N-1) do ( var xy : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; xys := xys + Sequence{ xy } ; var xx var xy : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )),yx var xy : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )),x:= xy,y:= xy : OclAny := null; var yxx var xy : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )),yx var xy : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )),x:= xy,y:= xy : OclAny := null; var x:= xy : OclAny := null; var y:= xy : OclAny := null; Sequence{x var xy : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )),yx var xy : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )),x:= xy,y:= xy} := xy ; m_x := Set{x_2, m_x}->max() ; m_y := Set{y_2, m_y}->max()) ; var im : Sequence := Integer.subrange(0, m_y + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (m_x + 1)))) ; for xy : xys do ( var xx skip,yx skip,x:= xy,y:= xy : OclAny := null; var yxx skip,yx skip,x:= xy,y:= xy : OclAny := null; var x:= xy : OclAny := null; var y:= xy : OclAny := null; Sequence{x skip,yx skip,x:= xy,y:= xy} := xy ; im[y var xx skip,yx skip,x:= xy,y:= xy : OclAny := null; var yxx skip,yx skip,x:= xy,y:= xy : OclAny := null; var x:= xy : OclAny := null; var y:= xy : OclAny := null; Sequence{x skip,yx skip,x:= xy,y:= xy} := xy+1][x var xx skip,yx skip,x:= xy,y:= xy : OclAny := null; var yxx skip,yx skip,x:= xy,y:= xy : OclAny := null; var x:= xy : OclAny := null; var y:= xy : OclAny := null; Sequence{x skip,yx skip,x:= xy,y:= xy} := xy+1] := im[y var xx skip,yx skip,x:= xy,y:= xy : OclAny := null; var yxx skip,yx skip,x:= xy,y:= xy : OclAny := null; var x:= xy : OclAny := null; var y:= xy : OclAny := null; Sequence{x skip,yx skip,x:= xy,y:= xy} := xy+1][x var xx skip,yx skip,x:= xy,y:= xy : OclAny := null; var yxx skip,yx skip,x:= xy,y:= xy : OclAny := null; var x:= xy : OclAny := null; var y:= xy : OclAny := null; Sequence{x skip,yx skip,x:= xy,y:= xy} := xy+1] + 1 ; im[y var xx skip,yx skip,x:= xy,y:= xy : OclAny := null; var yxx skip,yx skip,x:= xy,y:= xy : OclAny := null; var x:= xy : OclAny := null; var y:= xy : OclAny := null; Sequence{x skip,yx skip,x:= xy,y:= xy} := xy+1][x - 1+1] := im[y var xx skip,yx skip,x:= xy,y:= xy : OclAny := null; var yxx skip,yx skip,x:= xy,y:= xy : OclAny := null; var x:= xy : OclAny := null; var y:= xy : OclAny := null; Sequence{x skip,yx skip,x:= xy,y:= xy} := xy+1][x - 1+1] - 1 ; im[y - 1+1][x var xx skip,yx skip,x:= xy,y:= xy : OclAny := null; var yxx skip,yx skip,x:= xy,y:= xy : OclAny := null; var x:= xy : OclAny := null; var y:= xy : OclAny := null; Sequence{x skip,yx skip,x:= xy,y:= xy} := xy+1] := im[y - 1+1][x var xx skip,yx skip,x:= xy,y:= xy : OclAny := null; var yxx skip,yx skip,x:= xy,y:= xy : OclAny := null; var x:= xy : OclAny := null; var y:= xy : OclAny := null; Sequence{x skip,yx skip,x:= xy,y:= xy} := xy+1] - 1 ; im[y + 1+1][x + 1+1] := im[y + 1+1][x + 1+1] + 1) ; execute ((((Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name accumulate))))))) , (argument (test (logical_test (comparison (expr (atom (name im)))))))) ))))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name accumulate))))))) , (argument (test (logical_test (comparison (expr (atom (name im)))))))) ))))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name accumulate))))))) , (argument (test (logical_test (comparison (expr (atom (name im)))))))) ))))))))`third->at(_indx)} ))->collect( _x | (accumulate)->apply(_x) ))->collect( _x | (max)->apply(_x) ))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def primeFactors(n): res=[] while n % 2==0 : res.append(2) n//=2 x=3 while n>1 and n>=x*x : while n % x==0 : res.append(x) n//=x x+=2 if n>1 : res.append(n) return res def modpow(a,n,m): res=1 while n>0 : if n % 2==1 : res=(res*a)% m a=(a*a)% m n=n//2 return res MOD=10**9+7 n=int(input()) d=defaultdict(int) for i in range(1,n+1): for r in primeFactors(i): d[r]+=1 res=1 for k in d.keys(): res*=(d[k]+1) res %=MOD print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var MOD : double := (10)->pow(9) + 7 ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : OclAny := defaultdict(OclType["int"]) ; for i : Integer.subrange(1, n + 1-1) do ( for r : primeFactors(i) do ( d[r+1] := d[r+1] + 1)) ; res := 1 ; for k : d.keys() do ( res := res * (d[k+1] + 1) ; res := res mod MOD) ; execute (res)->display(); operation primeFactors(n : OclAny) : OclAny pre: true post: true activity: var res : Sequence := Sequence{} ; while n mod 2 = 0 do ( execute ((2) : res) ; n := n div 2) ; var x : int := 3 ; while n > 1 & (n->compareTo(x * x)) >= 0 do ( while n mod x = 0 do ( execute ((x) : res) ; n := n div x) ; x := x + 2) ; if n > 1 then ( execute ((n) : res) ) else skip ; return res; operation modpow(a : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: res := 1 ; while n > 0 do ( if n mod 2 = 1 then ( res := (MatrixLib.elementwiseMult(res, a)) mod m ) else skip ; a := (a * a) mod m ; n := n div 2) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import heapq import itertools import math import os import re import string import sys from collections import Counter,deque,defaultdict from decimal import Decimal from fractions import gcd from functools import lru_cache,reduce from operator import itemgetter import numpy as np if os.getenv("LOCAL"): sys.stdin=open("_in.txt","r") sys.setrecursionlimit(2147483647) INF=float("inf") IINF=10**18 S=sys.stdin.readline().rstrip() if S[0]==S[-1]: if len(S)% 2==0 : print('First') else : print('Second') else : if len(S)% 2==1 : print('First') else : print('Second') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if os.getenv("LOCAL") then ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile("_in.txt")) ) else skip ; sys.setrecursionlimit(2147483647) ; var INF : double := ("" + (("inf")))->toReal() ; var IINF : double := (10)->pow(18) ; var S : OclAny := sys.stdin.readLine().rstrip() ; if S->first() = S->last() then ( if (S)->size() mod 2 = 0 then ( execute ('First')->display() ) else ( execute ('Second')->display() ) ) else ( if (S)->size() mod 2 = 1 then ( execute ('First')->display() ) else ( execute ('Second')->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) mod=10**9+7 is_prime=[True for _ in range(1100)] is_prime[0]=is_prime[1]=False for i in range(2,1100): if not is_prime[i]: continue for j in range(i*i,1100,i): is_prime[j]=False ind=[] for p in range(2,1100): if is_prime[p]: cnt=0 for m in range(2,n+1): while m % p==0 : m//=p cnt+=1 if cnt!=0 : ind.append(cnt) ans=1 for i in range(len(ind)): ans*=(ind[i]+1) print(ans % mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var mod : double := (10)->pow(9) + 7 ; var is_prime : Sequence := Integer.subrange(0, 1100-1)->select(_anon | true)->collect(_anon | (true)) ; is_prime->first() := false; var is_prime[1+1] : boolean := false ; for i : Integer.subrange(2, 1100-1) do ( if not(is_prime[i+1]) then ( continue ) else skip ; for j : Integer.subrange(i * i, 1100-1)->select( $x | ($x - i * i) mod i = 0 ) do ( is_prime[j+1] := false)) ; var ind : Sequence := Sequence{} ; for p : Integer.subrange(2, 1100-1) do ( if is_prime[p+1] then ( var cnt : int := 0 ; for m : Integer.subrange(2, n + 1-1) do ( while m mod p = 0 do ( m := m div p ; cnt := cnt + 1)) ; if cnt /= 0 then ( execute ((cnt) : ind) ) else skip ) else skip) ; var ans : int := 1 ; for i : Integer.subrange(0, (ind)->size()-1) do ( ans := ans * (ind[i+1] + 1)) ; execute (ans mod mod)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def the_sieve_of_eratosthenes(i): s=[j for j in range(2,i+1)] j=0 while True : if j>=i-3 : for k in range(len(s)-1,0,-1): if s[k]==0 : del s[k] return s if s[j]!=0 : for k in range(2*s[j]-2,i-1,s[j]): s[k]=0 j+=1 n=int(input()) p=the_sieve_of_eratosthenes(10**3+9) c=[0]*len(p) j=0 for i in range(2,n+1): if i==p[j]: c[j]+=1 j+=1 else : k=0 m=i while True : if m==1 : break if m % p[k]==0 : c[k]+=1 m/=p[k] else : k+=1 ans=1 for i in c : ans*=i+1 if ans>=10**9+7 : ans %=10**9+7 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var p : OclAny := the_sieve_of_eratosthenes((10)->pow(3) + 9) ; var c : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (p)->size()) ; j := 0 ; for i : Integer.subrange(2, n + 1-1) do ( if i = p[j+1] then ( c[j+1] := c[j+1] + 1 ; j := j + 1 ) else ( var k : int := 0 ; var m : OclAny := i ; while true do ( if m = 1 then ( break ) else skip ; if m mod p[k+1] = 0 then ( c[k+1] := c[k+1] + 1 ; m := m / p[k+1] ) else ( k := k + 1 )) )) ; var ans : int := 1 ; for i : c do ( ans := ans * i + 1 ; if (ans->compareTo((10)->pow(9) + 7)) >= 0 then ( ans := ans mod (10)->pow(9) + 7 ) else skip) ; execute (ans)->display(); operation the_sieve_of_eratosthenes(i : OclAny) : OclAny pre: true post: true activity: var s : Sequence := Integer.subrange(2, i + 1-1)->select(j | true)->collect(j | (j)) ; var j : int := 0 ; while true do ( if (j->compareTo(i - 3)) >= 0 then ( for k : Integer.subrange(0 + 1, (s)->size() - 1)->reverse() do ( if s[k+1] = 0 then ( execute (s[k+1])->isDeleted() ) else skip) ; return s ) else skip ; if s[j+1] /= 0 then ( for k : Integer.subrange(2 * s[j+1] - 2, i - 1-1)->select( $x | ($x - 2 * s[j+1] - 2) mod s[j+1] = 0 ) do ( s[k+1] := 0) ) else skip ; j := j + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline def main(): N=int(input()) MOD=int(1e9)+7 MAX_PRIME=N primes=[] is_prime=[True]*(MAX_PRIME+1) for i in range(2,MAX_PRIME+1): if is_prime[i]: primes.append(i) for j in range(2*i,MAX_PRIME+1,i): is_prime[j]=False count=[0]*len(primes) for i in range(2,N+1): tmp=i for j in range(len(primes)): while tmp % primes[j]==0 : count[j]+=1 tmp//=primes[j] ans=1 for c in count : if c>0 : ans*=c+1 ans %=MOD print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var MOD : int := ("" + ((("1e9")->toReal())))->toInteger() + 7 ; var MAX_PRIME : int := N ; var primes : Sequence := Sequence{} ; var is_prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (MAX_PRIME + 1)) ; for i : Integer.subrange(2, MAX_PRIME + 1-1) do ( if is_prime[i+1] then ( execute ((i) : primes) ; for j : Integer.subrange(2 * i, MAX_PRIME + 1-1)->select( $x | ($x - 2 * i) mod i = 0 ) do ( is_prime[j+1] := false) ) else skip) ; var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (primes)->size()) ; for i : Integer.subrange(2, N + 1-1) do ( var tmp : OclAny := i ; for j : Integer.subrange(0, (primes)->size()-1) do ( while tmp mod primes[j+1] = 0 do ( count[j+1] := count[j+1] + 1 ; tmp := tmp div primes[j+1]))) ; var ans : int := 1 ; for c : count do ( if c > 0 then ( ans := ans * c + 1 ; ans := ans mod MOD ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math mod=int(1e9+7) N=int(input()) factorial_of_n=math.factorial(N) def countOfPrimeFactors(n): count_of_prime_factors={} if n>1 : count=0 while n % 2==0 : n//=2 count+=1 if count!=0 : count_of_prime_factors.update({2 : count}) if n==1 : return count_of_prime_factors for i in range(3,n,2): count=0 while n % i==0 : n//=i count+=1 if count!=0 : count_of_prime_factors.update({i : count}) if n==1 : return count_of_prime_factors count_of_prime_factors.update({n : 1}) return count_of_prime_factors else : return{} ans=1 for prime_factor,count in countOfPrimeFactors(factorial_of_n).items(): ans*=count+1 print(ans % mod) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var mod : int := ("" + ((("1e9")->toReal() + 7)))->toInteger() ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var factorial_of_n : long := MathLib.factorial(N) ; skip ; var ans : int := 1 ; for _tuple : countOfPrimeFactors(factorial_of_n)->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var prime_factor : OclAny := _tuple->at(_indx); _indx := _indx + 1; var count : OclAny := _tuple->at(_indx); ans := ans * count + 1) ; execute (ans mod mod)->display(); operation countOfPrimeFactors(n : OclAny) : OclAny pre: true post: true activity: var count_of_prime_factors : OclAny := Set{} ; if n > 1 then ( var count : int := 0 ; while n mod 2 = 0 do ( n := n div 2 ; count := count + 1) ; if count /= 0 then ( execute ((Map{ 2 |-> count }) <: count_of_prime_factors) ) else skip ; if n = 1 then ( return count_of_prime_factors ) else skip ; for i : Integer.subrange(3, n-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( count := 0 ; while n mod i = 0 do ( n := n div i ; count := count + 1) ; if count /= 0 then ( execute ((Map{ i |-> count }) <: count_of_prime_factors) ) else skip ; if n = 1 then ( return count_of_prime_factors ) else skip) ; execute ((Map{ n |-> 1 }) <: count_of_prime_factors) ; return count_of_prime_factors ) else ( return Set{} ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def minMeetingRooms(self,intervals): timeline=[] for interval in intervals : timeline.append((interval.start,1)) timeline.append((interval.end,-1)) timeline.sort() ans=curr=0 for _,v in timeline : curr+=v ans=max(ans,curr) return ans ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation minMeetingRooms(intervals : OclAny) : OclAny pre: true post: true activity: var timeline : Sequence := Sequence{} ; for interval : intervals do ( execute ((Sequence{interval.start, 1}) : timeline) ; execute ((Sequence{interval.end, -1}) : timeline)) ; timeline := timeline->sort() ; var ans : OclAny := 0; var curr : int := 0 ; for _tuple : timeline do (var _indx : int := 1; var _anon : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); curr := curr + v ; ans := Set{ans, curr}->max()) ; return ans; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) s=input() if('R' not in s)and('B' not in s): s=s.replace('?','B',1) while("?" in s): s=s.replace('?R','BR') s=s.replace('?B','RB') s=s.replace('B?','BR') s=s.replace('R?','RB') print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; if ((s)->characters()->excludes('R')) & ((s)->characters()->excludes('B')) then ( s := s.replace('?', 'B', 1) ) else skip ; while ((s)->characters()->includes("?")) do ( s := s.replace('?R', 'BR') ; s := s.replace('?B', 'RB') ; s := s.replace('B?', 'BR') ; s := s.replace('R?', 'RB')) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): x=int(input()) res=x-1,1 print(*res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : OclAny := x - 1,1 ; execute ((argument * (test (logical_test (comparison (expr (atom (name res))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : s=input() if s=="#" : break g,y,m,d=s.split() if int(y)>=32 : g="?" y=str(int(y)-30) elif int(y)==31 : if int(m)>=5 : g="?" y=str(int(y)-30) print(g,y,m,d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var s : String := (OclFile["System.in"]).readLine() ; if s = "#" then ( break ) else skip ; var g : OclAny := null; var y : OclAny := null; var m : OclAny := null; var d : OclAny := null; Sequence{g,y,m,d} := s.split() ; if ("" + ((y)))->toInteger() >= 32 then ( var g : String := "?" ; var y : String := ("" + ((("" + ((y)))->toInteger() - 30))) ) else (if ("" + ((y)))->toInteger() = 31 then ( if ("" + ((m)))->toInteger() >= 5 then ( g := "?" ; y := ("" + ((("" + ((y)))->toInteger() - 30))) ) else skip ) else skip) ; execute (g)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**20 eps=1.0/10**13 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] def f(s): g,y,m,d=s.split() y=int(y) m=int(m) d=int(d) if(y,m,d)>=(31,5,1): g='?' y=y-30 return '{}{}{}{}'.format(g,y,m,d) while 1 : s=S() if s=='#' : break rr.append(f(s)) return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(20) ; var eps : double := 1.0 / (10)->pow(13) ; var mod : double := (10)->pow(9) + 7 ; var dd : Sequence := Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{ Sequence{0, -1} }))) ; var ddn : Sequence := Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{-1, 1}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{1, 1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{Sequence{1, -1}}->union(Sequence{Sequence{0, -1}}->union(Sequence{ Sequence{-1, -1} }))))))) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; skip ; while 1 do ( s := S() ; if s = '#' then ( break ) else skip ; execute ((f(s)) : rr)) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : g,y,m,d=map(str,input().split()) y=int(y) m=int(m) d=int(d) if(y<=30): print('HEISEI',y,m,d) elif(y==31 and m<=4): print('HEISEI',y,m,d) else : y=y-30 print('?',y,m,d) except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var g : OclAny := null; var y : OclAny := null; var m : OclAny := null; var d : OclAny := null; Sequence{g,y,m,d} := (input().split())->collect( _x | (OclType["String"])->apply(_x) ) ; var y : int := ("" + ((y)))->toInteger() ; var m : int := ("" + ((m)))->toInteger() ; var d : int := ("" + ((d)))->toInteger() ; if (y <= 30) then ( execute ('HEISEI')->display() ) else (if (y = 31 & m <= 4) then ( execute ('HEISEI')->display() ) else ( y := y - 30 ; execute ('?')->display() ) ) ) catch (_e : OclException) do ( break) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from copy import deepcopy s=input() t=deepcopy(s) n=len(s) flg=0 x=2 if s[0]==s[n-1]: if n % 2 : print("Second") else : print("First") exit() for i in range(1,n-1): if s[i]==s[0]and flg : x+=1 flg=0 elif s[i]==s[n-1]and not flg : x+=1 flg=1 if(n-x+flg)% 2 : print("First") else : print("Second") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : String := (OclFile["System.in"]).readLine() ; var t : OclAny := deepcopy(s) ; var n : int := (s)->size() ; var flg : int := 0 ; var x : int := 2 ; if s->first() = s[n - 1+1] then ( if n mod 2 then ( execute ("Second")->display() ) else ( execute ("First")->display() ) ; exit() ) else skip ; for i : Integer.subrange(1, n - 1-1) do ( if s[i+1] = s->first() & flg then ( x := x + 1 ; flg := 0 ) else (if s[i+1] = s[n - 1+1] & not(flg) then ( x := x + 1 ; flg := 1 ) else skip)) ; if (n - x + flg) mod 2 then ( execute ("First")->display() ) else ( execute ("Second")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- ls_g=[] ls_y=[] ls_m=[] ls_d=[] cnt=-1 while True : try : ls=input().split() ls_g.append(ls[0]) ls_y.append(int(ls[1])) ls_m.append(int(ls[2])) ls_d.append(int(ls[3])) cnt+=1 except : break ; for _ in range(cnt+1): if ls_y[_]>31 : ls_g[_]="?" ls_y[_]-=30 elif ls_y[_]==31 and ls_m[_]>=5 : ls_g[_]="?" ls_y[_]-=30 for i in range(cnt+1): print(ls_g[i]+" "+str(ls_y[i])+" "+str(ls_m[i])+" "+str(ls_d[i])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var ls_g : Sequence := Sequence{} ; var ls_y : Sequence := Sequence{} ; var ls_m : Sequence := Sequence{} ; var ls_d : Sequence := Sequence{} ; var cnt : int := -1 ; while true do ( try ( var ls : OclAny := input().split() ; execute ((ls->first()) : ls_g) ; execute ((("" + ((ls[1+1])))->toInteger()) : ls_y) ; execute ((("" + ((ls[2+1])))->toInteger()) : ls_m) ; execute ((("" + ((ls[3+1])))->toInteger()) : ls_d) ; cnt := cnt + 1) catch (_e : OclException) do ( break;) ) ; for _anon : Integer.subrange(0, cnt + 1-1) do ( if ls_y[_anon+1] > 31 then ( ls_g[_anon+1] := "?" ; ls_y[_anon+1] := ls_y[_anon+1] - 30 ) else (if ls_y[_anon+1] = 31 & ls_m[_anon+1] >= 5 then ( ls_g[_anon+1] := "?" ; ls_y[_anon+1] := ls_y[_anon+1] - 30 ) else skip)) ; for i : Integer.subrange(0, cnt + 1-1) do ( execute (ls_g[i+1] + " " + ("" + ((ls_y[i+1]))) + " " + ("" + ((ls_m[i+1]))) + " " + ("" + ((ls_d[i+1]))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_four_data(): four_data=input().split() return four_data def change_era_name(four_data): era,year,month,day=four_data year=int(year) month=int(month) if year>31 or(year>=31 and month>=5): era="?" year-=30 return era,year,month,day if __name__=="__main__" : while True : four_data=get_four_data() if four_data[0]=="#" : break era,year,month,day=change_era_name(four_data) print(era,year,month,day) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( while true do ( four_data := get_four_data() ; if four_data->first() = "#" then ( break ) else skip ; var day : OclAny := null; Sequence{era,year,month,day} := change_era_name(four_data) ; execute (era)->display()) ) else skip; operation get_four_data() : OclAny pre: true post: true activity: var four_data : OclAny := input().split() ; return four_data; operation change_era_name(four_data : OclAny) : OclAny pre: true post: true activity: var era : OclAny := null; var year : OclAny := null; var month : OclAny := null; var day : OclAny := null; Sequence{era,year,month,day} := four_data ; var year : int := ("" + ((year)))->toInteger() ; var month : int := ("" + ((month)))->toInteger() ; if year > 31 or (year >= 31 & month >= 5) then ( var era : String := "?" ; year := year - 30 ) else skip ; return era, year, month, day; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=input().split() a=0 for item in l : a+=int(item) ans=0 for j in range(1,6): if(a+j)%(n+1)!=1 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : OclAny := input().split() ; var a : int := 0 ; for item : l do ( a := a + ("" + ((item)))->toInteger()) ; var ans : int := 0 ; for j : Integer.subrange(1, 6-1) do ( if (a + j) mod (n + 1) /= 1 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) numbers=[int(num)for num in input().split(" ",n-1)] sum=0 for num in numbers : sum+=num j=0 for i in range(1,6): if(sum+i)%(n+1)!=1 : j+=1 print(j) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var numbers : Sequence := input().split(" ", n - 1)->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var sum : int := 0 ; for num : numbers do ( sum := sum + num) ; var j : int := 0 ; for i : Integer.subrange(1, 6-1) do ( if (sum + i) mod (n + 1) /= 1 then ( j := j + 1 ) else skip) ; execute (j)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) numbers=[int(num)for num in input().split(" ",n-1)] sum=0 for num in numbers : sum+=num j=0 for i in range(1,6): if(sum+i)%(n+1)!=1 : j+=1 print(j) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var numbers : Sequence := input().split(" ", n - 1)->select(num | true)->collect(num | (("" + ((num)))->toInteger())) ; var sum : int := 0 ; for num : numbers do ( sum := sum + num) ; var j : int := 0 ; for i : Integer.subrange(1, 6-1) do ( if (sum + i) mod (n + 1) /= 1 then ( j := j + 1 ) else skip) ; execute (j)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input())+1 a=sum(map(int,input().split()))-1 print(sum((a+x)% n>0 for x in range(1,6))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() + 1 ; var a : double := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum() - 1 ; execute (((argument (test (logical_test (comparison (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name a))) + (expr (atom (name x)))))))) ))) % (expr (atom (name n))))) > (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 6))))))))) )))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) s=sum(arr) ans=0 for i in range(1,6): if((s+i)%(n+1)!=1): ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : OclAny := (arr)->sum() ; var ans : int := 0 ; for i : Integer.subrange(1, 6-1) do ( if ((s + i) mod (n + 1) /= 1) then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : for _ in range(int(input())): n=int(input()) print(f'1{n-1}') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (StringLib.formattedString('1{n-1}'))->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- arr=[int(x)for x in input().split(' ')] counter=0 for i in set(arr): counter+=arr.count(i)-1 print(counter) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var arr : Sequence := input().split(' ')->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var counter : int := 0 ; for i : Set{}->union((arr)) do ( counter := counter + arr->count(i) - 1) ; execute (counter)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- arr=list(map(int,input().split())) k=set(arr) z=len(k) print(4-z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var k : Set := Set{}->union((arr)) ; var z : int := (k)->size() ; execute (4 - z)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): S=input() p=1 even=False if len(S)% 2==0 : even=True if S[0]==S[-1]: if even : return-p else : return p else : if even : return p else : return-p if __name__=='__main__' : res=solve() if res<0 : print("First") else : print("Second") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var res : OclAny := solve() ; if res < 0 then ( execute ("First")->display() ) else ( execute ("Second")->display() ) ) else skip; operation solve() : OclAny pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var p : int := 1 ; var even : boolean := false ; if (S)->size() mod 2 = 0 then ( even := true ) else skip ; if S->first() = S->last() then ( if even then ( return -p ) else ( return p ) ) else ( if even then ( return p ) else ( return -p ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=set(map(int,input().split())) print(4-len(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; execute (4 - (a)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=set(input().split()) co=0 print(4-len(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : Set := Set{}->union((input().split())) ; var co : int := 0 ; execute (4 - (n)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=list(map(int,input().split())) print(len(a)-len(set(a))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((a)->size() - (Set{}->union((a)))->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys a=int(input()) if a % 2==1 : print("-1") else : for i in range(1,a+1): if i % 2==1 : sys.stdout.write(str(i+1)+" ") else : sys.stdout.write(str(i-1)+" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if a mod 2 = 1 then ( execute ("-1")->display() ) else ( for i : Integer.subrange(1, a + 1-1) do ( if i mod 2 = 1 then ( (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) )))) + (expr (atom " ")))))))) )))) ) else ( (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (number (integer 1)))))))))) )))) + (expr (atom " ")))))))) )))) )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) str1="" if n % 2==1 : print(-1) else : for i in range(2,n+1,2): str1+="{0}{1}".format(str(i),str(i-1)) str1.strip() print(str1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var str1 : String := "" ; if n mod 2 = 1 then ( execute (-1)->display() ) else ( for i : Integer.subrange(2, n + 1-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( str1 := str1 + StringLib.interpolateStrings("{0}{1}", Sequence{("" + ((i))), ("" + ((i - 1)))})) ; str1->trim() ; execute (str1)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if(n % 2==1): print(-1) else : for i in range(0,n): if(i % 2==0): print(i+2) else : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (n mod 2 = 1) then ( execute (-1)->display() ) else ( for i : Integer.subrange(0, n-1) do ( if (i mod 2 = 0) then ( execute (i + 2)->display() ) else ( execute (i)->display() )) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) if n % 2==1 : print(-1) else : for i in range(2,n+1,2): print(i,i-1,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 2 = 1 then ( execute (-1)->display() ) else ( for i : Integer.subrange(2, n + 1-1)->select( $x | ($x - 2) mod 2 = 0 ) do ( execute (i)->display()) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) list=[] if n % 2!=0 : print(-1) else : for i in range(1,n+1): if i % 2!=0 : list.append(i+1) else : list.append(i-1) ans=' '.join([str(elem)for elem in list]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var OclType["Sequence"] : Sequence := Sequence{} ; if n mod 2 /= 0 then ( execute (-1)->display() ) else ( for i : Integer.subrange(1, n + 1-1) do ( if i mod 2 /= 0 then ( execute ((i + 1) : OclType["Sequence"]) ) else ( execute ((i - 1) : OclType["Sequence"]) )) ) ; var ans : String := StringLib.sumStringsWithSeparator((OclType["Sequence"]->select(elem | true)->collect(elem | (("" + ((elem)))))), ' ') ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def check_last(arr,n,p): _sum=0 for i in range(n): _sum=_sum+arr[i] if p==1 : if _sum % 2==0 : return "ODD" else : return "EVEN" return "EVEN" arr=[5,7,10] p=1 n=len(arr) print(check_last(arr,n,p)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{5}->union(Sequence{7}->union(Sequence{ 10 })) ; p := 1 ; n := (arr)->size() ; execute (check_last(arr, n, p))->display(); operation check_last(arr : OclAny, n : OclAny, p : OclAny) : OclAny pre: true post: true activity: var _sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( _sum := _sum + arr[i+1]) ; if p = 1 then ( if _sum mod 2 = 0 then ( return "ODD" ) else ( return "EVEN" ) ) else skip ; return "EVEN"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=[int(_)for _ in input().split()] max_p=s[0] min_p=s[0] amazing=0 for i in range(n-1): if s[i+1]>max_p : max_p=s[i+1] amazing+=1 if s[i+1]toInteger() ; var s : Sequence := input().split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toInteger())) ; var max_p : OclAny := s->first() ; var min_p : OclAny := s->first() ; var amazing : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( if (s[i + 1+1]->compareTo(max_p)) > 0 then ( max_p := s[i + 1+1] ; amazing := amazing + 1 ) else skip ; if (s[i + 1+1]->compareTo(min_p)) < 0 then ( min_p := s[i + 1+1] ; amazing := amazing + 1 ) else skip) ; execute (amazing)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,re from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,radians from itertools import permutations,combinations,product from operator import itemgetter,mul from copy import deepcopy from string import ascii_lowercase,ascii_uppercase,digits def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) sys.setrecursionlimit(10**9) INF=float('inf') MOD=10**9+7 s=input() if s[0]==s[-1]: if len(s)% 2==0 : print("First") else : print("Second") else : if len(s)% 2==0 : print("Second") else : print("First") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var MOD : double := (10)->pow(9) + 7 ; var s : String := (OclFile["System.in"]).readLine() ; if s->first() = s->last() then ( if (s)->size() mod 2 = 0 then ( execute ("First")->display() ) else ( execute ("Second")->display() ) ) else ( if (s)->size() mod 2 = 0 then ( execute ("Second")->display() ) else ( execute ("First")->display() ) ); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) list1=list(map(int,input().split())) count=0 min1,max1=list1[0],list1[0] for i in range(1,t): if min1>list1[i]: count+=1 min1=list1[i] elif max1toInteger() ; var list1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : int := 0 ; var min1 : OclAny := null; var max1 : OclAny := null; Sequence{min1,max1} := Sequence{list1->first(),list1->first()} ; for i : Integer.subrange(1, t-1) do ( if (min1->compareTo(list1[i+1])) > 0 then ( count := count + 1 ; var min1 : OclAny := list1[i+1] ) else (if (max1->compareTo(list1[i+1])) < 0 then ( count := count + 1 ; var max1 : OclAny := list1[i+1] ) else skip)) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a=int(input()),(int(i)for i in input().split()) mi=ma=next(a) res=0 for i in a : if ima : res+=1 mi,ma=min(i,mi),max(i,ma) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))}} ; var mi : OclAny := (a).next(); var ma : OclAny := (a).next() ; var res : int := 0 ; for i : a do ( if (i->compareTo(mi)) < 0 or (i->compareTo(ma)) > 0 then ( res := res + 1 ; Sequence{mi,ma} := Sequence{Set{i, mi}->min(),Set{i, ma}->max()} ) else skip) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) alst=list(map(int,input().split())) minA=maxA=alst[0] acount=0 for i in range(1,len(alst)): if alst[i]maxA : acount+=1 maxA=alst[i] print(acount) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var alst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var minA : OclAny := alst->first(); var maxA : OclAny := alst->first() ; var acount : int := 0 ; for i : Integer.subrange(1, (alst)->size()-1) do ( if (alst[i+1]->compareTo(minA)) < 0 then ( acount := acount + 1 ; minA := alst[i+1] ) else (if (alst[i+1]->compareTo(maxA)) > 0 then ( acount := acount + 1 ; maxA := alst[i+1] ) else skip)) ; execute (acount)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) ar1=list(map(int,input().split())) max_record=ar1[0] min_record=ar1[0] count=0 for i in range(1,N): if ar1[i]>max_record : max_record=ar1[i] count+=1 if ar1[i]toInteger() ; var ar1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var max_record : OclAny := ar1->first() ; var min_record : OclAny := ar1->first() ; var count : int := 0 ; for i : Integer.subrange(1, N-1) do ( if (ar1[i+1]->compareTo(max_record)) > 0 then ( max_record := ar1[i+1] ; count := count + 1 ) else skip ; if (ar1[i+1]->compareTo(min_record)) < 0 then ( min_record := ar1[i+1] ; count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): s=input() x=[] x=set(x) for i in range(len(s)): x.add(s[i]) if(len(x)% 2==0): print("CHAT WITH HER!") else : print("IGNORE HIM!") if __name__=="__main__" : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( solve() ) else skip; operation solve() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var x : Sequence := Sequence{} ; x := Set{}->union((x)) ; for i : Integer.subrange(0, (s)->size()-1) do ( execute ((s[i+1]) : x)) ; if ((x)->size() mod 2 = 0) then ( execute ("CHAT WITH HER!")->display() ) else ( execute ("IGNORE HIM!")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- kondi=(input()) saik=[x for x in kondi] dadyy=list(set(saik)) if(len(dadyy)% 2!=0): print("IGNORE HIM!") else : print("CHAT WITH HER!") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var kondi : String := ((OclFile["System.in"]).readLine()) ; var saik : Sequence := kondi->characters()->select(x | true)->collect(x | (x)) ; var dadyy : Sequence := (Set{}->union((saik))) ; if ((dadyy)->size() mod 2 /= 0) then ( execute ("IGNORE HIM!")->display() ) else ( execute ("CHAT WITH HER!")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() c=0 y=list(set(x)) if(len(y)% 2==0): print("CHAT WITH HER!") else : print("IGNORE HIM!") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : String := (OclFile["System.in"]).readLine() ; var c : int := 0 ; var y : Sequence := (Set{}->union((x))) ; if ((y)->size() mod 2 = 0) then ( execute ("CHAT WITH HER!")->display() ) else ( execute ("IGNORE HIM!")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=input() a1='' for i in range(len(a)): if a[i]not in a1 : a1+=a[i] if len(a1)% 2==0 : print('CHAT WITH HER!') else : print('IGNORE HIM!') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : String := (OclFile["System.in"]).readLine() ; var a1 : String := '' ; for i : Integer.subrange(0, (a)->size()-1) do ( if (a1)->characters()->excludes(a[i+1]) then ( a1 := a1 + a[i+1] ) else skip) ; if (a1)->size() mod 2 = 0 then ( execute ('CHAT WITH HER!')->display() ) else ( execute ('IGNORE HIM!')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() a=list(n) b=set(a) A=len(b) if A % 2==0 : print("CHAT WITH HER!") else : print("IGNORE HIM!") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var a : Sequence := (n)->characters() ; var b : Set := Set{}->union((a)) ; var A : int := (b)->size() ; if A mod 2 = 0 then ( execute ("CHAT WITH HER!")->display() ) else ( execute ("IGNORE HIM!")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) arr=[list(map(int,input().split()))for r in range(n)] a,b=map(int,input().split()) mx=10000000 ; for i in range(n-a+1): for j in range(m-b+1): count=0 ; for w in range(i,i+a): for e in range(j,j+b): count+=arr[w][e] mx=min(mx,count) for i in range(n-b+1): for j in range(m-a+1): count=0 ; for w in range(i,i+b): for e in range(j,j+a): count+=arr[w][e] mx=min(mx,count) print(mx) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := Integer.subrange(0, n-1)->select(r | true)->collect(r | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mx : int := 10000000; ; for i : Integer.subrange(0, n - a + 1-1) do ( for j : Integer.subrange(0, m - b + 1-1) do ( var count : int := 0; ; for w : Integer.subrange(i, i + a-1) do ( for e : Integer.subrange(j, j + b-1) do ( count := count + arr[w+1][e+1])) ; mx := Set{mx, count}->min())) ; for i : Integer.subrange(0, n - b + 1-1) do ( for j : Integer.subrange(0, m - a + 1-1) do ( count := 0; ; for w : Integer.subrange(i, i + b-1) do ( for e : Integer.subrange(j, j + a-1) do ( count := count + arr[w+1][e+1])) ; mx := Set{mx, count}->min())) ; execute (mx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countMinimumMoves(arr,n,k): for i in range(k-1,n): if(arr[i]!=arr[k-1]): return-1 for i in range(k-1,-1,-1): if(arr[i]!=arr[k-1]): return i+1 return 0 if __name__=="__main__" : arr=[1,2,3,4] K=4 n=len(arr) print(countMinimumMoves(arr,n,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))) ; var K : int := 4 ; n := (arr)->size() ; execute (countMinimumMoves(arr, n, K))->display() ) else skip; operation countMinimumMoves(arr : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(k - 1, n-1) do ( if (arr[i+1] /= arr[k - 1+1]) then ( return -1 ) else skip) ; for i : Integer.subrange(-1 + 1, k - 1)->reverse() do ( if (arr[i+1] /= arr[k - 1+1]) then ( return i + 1 ) else skip) ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find_value(a,n,k): sum=0 for i in range(n): sum+=a[i] return sum % k if __name__=="__main__" : n,k=5,3 ; a=[12,4,13,0,5]; print(find_value(a,n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{n,k} := Sequence{5,3}; ; a := Sequence{12}->union(Sequence{4}->union(Sequence{13}->union(Sequence{0}->union(Sequence{ 5 })))); ; execute (find_value(a, n, k))->display() ) else skip; operation find_value(a : OclAny, n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( sum := sum + a[i+1]) ; return sum mod k; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CountingEvenOdd(arr,arr_size): even_count=0 odd_count=0 for i in range(arr_size): if(arr[i]& 1==1): odd_count+=1 else : even_count+=1 print("Number of even elements=",even_count) print("Number of odd elements=",odd_count) arr=[2,3,4,5,6] n=len(arr) CountingEvenOdd(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 })))) ; var n : int := (arr)->size() ; CountingEvenOdd(arr, n); operation CountingEvenOdd(arr : OclAny, arr_size : OclAny) pre: true post: true activity: var even_count : int := 0 ; var odd_count : int := 0 ; for i : Integer.subrange(0, arr_size-1) do ( if (MathLib.bitwiseAnd(arr[i+1], 1) = 1) then ( odd_count := odd_count + 1 ) else ( even_count := even_count + 1 )) ; execute ("Number of even elements=")->display() ; execute ("Number of odd elements=")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def harmonicMean(arr,n): sm=0 for i in range(0,n): sm=sm+(1)/arr[i]; return n/sm arr=[13.5,14.5,14.8,15.2,16.1]; n=len(arr) print(harmonicMean(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{13.5}->union(Sequence{14.5}->union(Sequence{14.8}->union(Sequence{15.2}->union(Sequence{ 16.1 })))); ; n := (arr)->size() ; execute (harmonicMean(arr, n))->display(); operation harmonicMean(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sm : int := 0 ; for i : Integer.subrange(0, n-1) do ( sm := sm + (1) / arr[i+1];) ; return n / sm; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for d in[0]*int(input()): a=[input()for f in[0]*int(input().split()[0])]; b,c=([x.count('.')for x in y]for y in(a,zip(*a))); print(min(s+t-(x>'*')for r,s in zip(a,b)for x,t in zip(r,c))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for d : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + ((input().split()->first())))->toInteger())->select(f | true)->collect(f | ((OclFile["System.in"]).readLine())); var b : OclAny := null; var c : OclAny := null; Sequence{b,c} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name x)) (trailer . (name count) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom '.'))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name y))))))) ]))))) (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name a)))))) , (test (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom (name a)))))))) )))))))) )))))))}; execute (((argument (test (logical_test (comparison (expr (expr (expr (atom (name s))) + (expr (atom (name t)))) - (expr (atom ( (testlist_comp (test (logical_test (comparison (comparison (expr (atom (name x)))) > (comparison (expr (atom '*'))))))) ))))))) (comp_for for (exprlist (expr (atom (name r))) , (expr (atom (name s)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a))))))) , (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name x))) , (expr (atom (name t)))) in (logical_test (comparison (expr (atom (name zip)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name r))))))) , (argument (test (logical_test (comparison (expr (atom (name c)))))))) )))))))))))->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=map(int,input().split()) N=[0]*n M=[0]*m l=[] for i in range(n): o=input() l+=[o] N[i]+=o.count("*") for j in range(m): if o[j]=="*" : M[j]+=1 o=0 for i in range(n): for j in range(m): o=max(o,N[i]+M[j]-(l[i][j]=="*")) print(n+m-o-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var N : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var M : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var o : String := (OclFile["System.in"]).readLine() ; l := l + Sequence{ o } ; N[i+1] := N[i+1] + o->count("*") ; for j : Integer.subrange(0, m-1) do ( if o[j+1] = "*" then ( M[j+1] := M[j+1] + 1 ) else skip)) ; o := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( o := Set{o, N[i+1] + M[j+1] - (l[i+1][j+1] = "*")}->max())) ; execute (n + m - o - 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m=map(int,input().split()) a=[input()for x in range(n)] row=[0 for x in range(n)] col=[0 for x in range(m)] for i in range(n): for j in range(m): if a[i][j]=='*' : row[i]+=1 col[j]+=1 ans=1<<64 for i in range(n): for j in range(m): c=n-row[i]+m-col[j] if a[i][j]=='.' : c-=1 ans=min(ans,c) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, n-1)->select(x | true)->collect(x | ((OclFile["System.in"]).readLine())) ; var row : Sequence := Integer.subrange(0, n-1)->select(x | true)->collect(x | (0)) ; var col : Sequence := Integer.subrange(0, m-1)->select(x | true)->collect(x | (0)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if a[i+1][j+1] = '*' then ( row[i+1] := row[i+1] + 1 ; col[j+1] := col[j+1] + 1 ) else skip)) ; var ans : int := 1 * (2->pow(64)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( var c : double := n - row[i+1] + m - col[j+1] ; if a[i+1][j+1] = '.' then ( c := c - 1 ) else skip ; ans := Set{ans, c}->min())) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): for i in range(int(input())): n,m=map(int,input().split()) hlp=[] for i in range(n): hlp.append(input()) f=[0]*n s=[0]*m ans=10**10 for i in range(n): for j in range(m): if(hlp[i][j]=='*'): f[i]+=1 s[j]+=1 for i in range(n): for j in range(m): tmp=0 if(hlp[i][j]!='*'): tmp=-1 tmp+=(n-f[i])+(m-s[j]) ans=min(ans,tmp) print(ans) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var hlp : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : hlp)) ; var f : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var s : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; var ans : double := (10)->pow(10) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if (hlp[i+1][j+1] = '*') then ( f[i+1] := f[i+1] + 1 ; s[j+1] := s[j+1] + 1 ) else skip)) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( var tmp : int := 0 ; if (hlp[i+1][j+1] /= '*') then ( tmp := -1 ) else skip ; tmp := tmp + (n - f[i+1]) + (m - s[j+1]) ; ans := Set{ans, tmp}->min())) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict import sys from typing import Counter input=sys.stdin.readline for _ in range(int(input())): n,m=list(map(int,input().split())) arr=[] for _ in range(n): s=list(map(str,input().split()))[0] arr.append(s) a=[0]*n b=[0]*m for i in range(n): for j in range(m): if arr[i][j]=='*' : a[i]+=1 b[j]+=1 ans=0 for i in range(n): for j in range(m): ans=max(ans,a[i]+b[j]-(arr[i][j]=="*")) print(n+m-1-ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var arr : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var s : OclAny := OclType["Sequence"]((input().split())->collect( _x | (OclType["String"])->apply(_x) ))->first() ; execute ((s) : arr)) ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if arr[i+1][j+1] = '*' then ( a[i+1] := a[i+1] + 1 ; b[j+1] := b[j+1] + 1 ) else skip)) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( ans := Set{ans, a[i+1] + b[j+1] - (arr[i+1][j+1] = "*")}->max())) ; execute (n + m - 1 - ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxLengthSubSeq(a,n): temp=[0 for i in range(n)] print1=[0 for i in range(n)] y=0 for i in range(0,n,1): j=0 x=0 temp[j]=a[x] j+=1 x=a[x]+x while(xunion(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ; n := (a)->size() ; maxLengthSubSeq(a, n) ) else skip; operation maxLengthSubSeq(a : OclAny, n : OclAny) pre: true post: true activity: var temp : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var print1 : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)) ; var y : int := 0 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( var j : int := 0 ; var x : int := 0 ; temp[j+1] := a[x+1] ; j := j + 1 ; x := a[x+1] + x ; while ((x->compareTo(n)) < 0) do ( temp[j+1] := a[x+1] ; j := j + 1 ; x := a[x+1] + x) ; if ((y->compareTo(j)) < 0) then ( for k : Integer.subrange(0, j-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( print1[k+1] := temp[k+1] ; y := j) ) else skip) ; for i : Integer.subrange(0, y-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( execute (print1[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin def main(): n,m,q=map(int,input().split()) chm=list(range(n+m)) r=[0]*(n+m) n-=1 res=n+m for s in stdin.read().splitlines(): a,b=map(int,s.split()) a-=1 b+=n l=[] while a!=chm[a]: l.append(a) a=chm[a] for c in l : chm[c]=a l=[] while b!=chm[b]: l.append(b) b=chm[b] for c in l : chm[c]=b if a!=b : if r[a]collect( _x | (OclType["int"])->apply(_x) ) ; var chm : Sequence := (Integer.subrange(0, n + m-1)) ; var r : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + m)) ; n := n - 1 ; var res : OclAny := n + m ; for s : stdin.readAll().splitlines() do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (s.split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := a - 1 ; b := b + n ; var l : Sequence := Sequence{} ; while a /= chm[a+1] do ( execute ((a) : l) ; var a : OclAny := chm[a+1]) ; for c : l do ( chm[c+1] := a) ; l := Sequence{} ; while b /= chm[b+1] do ( execute ((b) : l) ; var b : OclAny := chm[b+1]) ; for c : l do ( chm[c+1] := b) ; if a /= b then ( if (r[a+1]->compareTo(r[b+1])) < 0 then ( chm[a+1] := b ) else (if (r[b+1]->compareTo(r[a+1])) < 0 then ( chm[b+1] := a ) else ( chm[a+1] := b ; r[b+1] := r[b+1] + 1 ) ) ; res := res - 1 ) else skip) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def power(x,y,p): res=1 x=x % p while(y>0): if(y & 1): res=(res*x)% p y=y>>1 x=(x*x)% p return res def gcd(a,b): if(a==0): return b return gcd(b % a,a) def powerGCD(a,b,n): e=power(a,n,b) return gcd(e,b) if __name__=="__main__" : a=5 b=4 n=2 print(powerGCD(a,b,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( a := 5 ; b := 4 ; n := 2 ; execute (powerGCD(a, b, n))->display() ) else skip; operation power(x : OclAny, y : OclAny, p : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; x := x mod p ; while (y > 0) do ( if (MathLib.bitwiseAnd(y, 1)) then ( res := (res * x) mod p ) else skip ; y := y /(2->pow(1)) ; x := (x * x) mod p) ; return res; operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0) then ( return b ) else skip ; return gcd(b mod a, a); operation powerGCD(a : OclAny, b : OclAny, n : OclAny) : OclAny pre: true post: true activity: var e : OclAny := power(a, n, b) ; return gcd(e, b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countTrees(arr,startRow,endRow,startCol,endCol): counter=0 for row in range(startRow,endRow): for col in range(startCol,endCol): counter+=arr[row][col] return counter n,m=[int(item)for item in input().split(' ')] arr=[] for i in range(n): arr.append([int(item)for item in input().split(' ')]) a,b=[int(item)for item in input().split(' ')] ans=a*b for i in range(n): for j in range(m): if i<=n-a and j<=m-b : helper=countTrees(arr,i,i+a,j,j+b) if ans>helper : ans=helper if i<=n-b and j<=m-a : helper=countTrees(arr,i,i+b,j,j+a) if ans>helper : ans=helper print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split(' ')->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; arr := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((input().split(' ')->select(item | true)->collect(item | (("" + ((item)))->toInteger()))) : arr)) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split(' ')->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; var ans : double := a * b ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if (i->compareTo(n - a)) <= 0 & (j->compareTo(m - b)) <= 0 then ( var helper : OclAny := countTrees(arr, i, i + a, j, j + b) ; if (ans->compareTo(helper)) > 0 then ( ans := helper ) else skip ) else skip ; if (i->compareTo(n - b)) <= 0 & (j->compareTo(m - a)) <= 0 then ( helper := countTrees(arr, i, i + b, j, j + a) ; if (ans->compareTo(helper)) > 0 then ( ans := helper ) else skip ) else skip)) ; execute (ans)->display(); operation countTrees(arr : OclAny, startRow : OclAny, endRow : OclAny, startCol : OclAny, endCol : OclAny) : OclAny pre: true post: true activity: var counter : int := 0 ; for row : Integer.subrange(startRow, endRow-1) do ( for col : Integer.subrange(startCol, endCol-1) do ( counter := counter + arr[row+1][col+1])) ; return counter; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout class DSU : def __init__(self,n): self.root=[-1 for x in range(0,n)] def find(self,i): if self.root[i]==-1 : return i else : self.root[i]=self.find(self.root[i]) return self.root[i] def link(self,i,j): if self.find(i)==self.find(j): return False self.root[self.find(i)]=self.find(j) return True n,m,q=map(int,stdin.readline().split()) dsu=DSU(n+m+1) groups=n+m for line in stdin : r,c=map(int,line.split()) groups-=dsu.link(r,n+c) stdout.write(str(groups-1)+'\n') ------------------------------------------------------------ OCL File: --------- class DSU { static operation newDSU() : DSU pre: true post: DSU->exists( _x | result = _x ); attribute root : Sequence := Integer.subrange(0, n-1)->select(x | true)->collect(x | (-1)); operation initialise(n : OclAny) : DSU pre: true post: true activity: self.root := Integer.subrange(0, n-1)->select(x | true)->collect(x | (-1)); return self; operation find(i : OclAny) : OclAny pre: true post: true activity: if self.root[i+1] = -1 then ( return i ) else ( self.root[i+1] := self->indexOf(self.root[i+1]) - 1 ; return self.root[i+1] ); operation link(i : OclAny,j : OclAny) : OclAny pre: true post: true activity: if self->indexOf(i) - 1 = self->indexOf(j) - 1 then ( return false ) else skip ; self.root[self->indexOf(i) - 1+1] := self->indexOf(j) - 1 ; return true; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var m : OclAny := null; var q : OclAny := null; Sequence{n,m,q} := (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dsu : DSU := (DSU.newDSU()).initialise(n + m + 1) ; var groups : OclAny := n + m ; for line : stdin do ( var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := (line.split())->collect( _x | (OclType["int"])->apply(_x) ) ; groups := groups - dsu.link(r, n + c)) ; stdout.write(("" + ((groups - 1))) + ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin,stdout class DSU : def __init__(self,n): self.root=[-1 for x in range(0,n)] def find(self,i): if self.root[i]==-1 : return i else : self.root[i]=self.find(self.root[i]) return self.root[i] def link(self,i,j): if self.find(i)==self.find(j): return False self.root[self.find(i)]=self.find(j) return True n,m,q=map(int,stdin.readline().split()) dsu=DSU(n+m+1) groups=n+m for line in stdin : r,c=map(int,line.split()) groups-=dsu.link(r,n+c) stdout.write(str(groups-1)+'\n') ------------------------------------------------------------ OCL File: --------- class DSU { static operation newDSU() : DSU pre: true post: DSU->exists( _x | result = _x ); attribute root : Sequence := Integer.subrange(0, n-1)->select(x | true)->collect(x | (-1)); operation initialise(n : OclAny) : DSU pre: true post: true activity: self.root := Integer.subrange(0, n-1)->select(x | true)->collect(x | (-1)); return self; operation find(i : OclAny) : OclAny pre: true post: true activity: if self.root[i+1] = -1 then ( return i ) else ( self.root[i+1] := self->indexOf(self.root[i+1]) - 1 ; return self.root[i+1] ); operation link(i : OclAny,j : OclAny) : OclAny pre: true post: true activity: if self->indexOf(i) - 1 = self->indexOf(j) - 1 then ( return false ) else skip ; self.root[self->indexOf(i) - 1+1] := self->indexOf(j) - 1 ; return true; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var m : OclAny := null; var q : OclAny := null; Sequence{n,m,q} := (stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dsu : DSU := (DSU.newDSU()).initialise(n + m + 1) ; var groups : OclAny := n + m ; for line : stdin do ( var r : OclAny := null; var c : OclAny := null; Sequence{r,c} := (line.split())->collect( _x | (OclType["int"])->apply(_x) ) ; groups := groups - dsu.link(r, n + c)) ; stdout.write(("" + ((groups - 1))) + ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n=int(input()) if n==0 : break grid=[[0 for i in range(21)]for i in range(21)] for i in range(n): x,y=list(map(int,input().split())) grid[x][y]=1 x,y=10,10 grid[x][y]=0 m=int(input()) for i in range(m): d,l=input().split() l=int(l) nx,ny=x,y if d=="N" : ny+=l for j in range(y,ny+1): grid[x][j]=0 elif d=="S" : ny-=l for j in range(y,ny-1,-1): grid[x][j]=0 elif d=="E" : nx+=l for j in range(x,nx+1): grid[j][y]=0 else : nx-=l for j in range(x,nx-1,-1): grid[j][y]=0 x,y=nx,ny flag=True for i in range(21): for j in range(21): if grid[i][j]==1 : flag=False if flag : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var grid : Sequence := Integer.subrange(0, 21-1)->select(i | true)->collect(i | (Integer.subrange(0, 21-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; grid[x+1][y+1] := 1) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{10,10} ; grid[x+1][y+1] := 0 ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, m-1) do ( var d : OclAny := null; var l : OclAny := null; Sequence{d,l} := input().split() ; var l : int := ("" + ((l)))->toInteger() ; var nx : OclAny := null; var ny : OclAny := null; Sequence{nx,ny} := Sequence{x,y} ; if d = "N" then ( ny := ny + l ; for j : Integer.subrange(y, ny + 1-1) do ( grid[x+1][j+1] := 0) ) else (if d = "S" then ( ny := ny - l ; for j : Integer.subrange(ny - 1 + 1, y)->reverse() do ( grid[x+1][j+1] := 0) ) else (if d = "E" then ( nx := nx + l ; for j : Integer.subrange(x, nx + 1-1) do ( grid[j+1][y+1] := 0) ) else ( nx := nx - l ; for j : Integer.subrange(nx - 1 + 1, x)->reverse() do ( grid[j+1][y+1] := 0) ) ) ) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{nx,ny}) ; var flag : boolean := true ; for i : Integer.subrange(0, 21-1) do ( for j : Integer.subrange(0, 21-1) do ( if grid[i+1][j+1] = 1 then ( flag := false ) else skip)) ; if flag then ( execute ("Yes")->display() ) else ( execute ("No")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def move(cmd,gems): n=0 x=y=10 for c in cmd : d=c[0] l=c[1] for s in range(0,l): if d=="N" : y+=1 elif d=="E" : x+=1 elif d=="S" : y-=1 elif d=="W" : x-=1 if gems[y][x]==1 : n+=1 gems[y][x]=0 return n gems=[] cmd=[] att="gemsN" for line in sys.stdin : if att=="gemsN" : n=w_n=int(line) if n==0 : break att="gemsXY" gems=[[0 for i in range(0,21)]for j in range(0,21)] elif att=="gemsXY" and w_n>0 : xy=list(map(int,line.strip().split(" "))) gems[xy[1]][xy[0]]=1 w_n-=1 elif att=="gemsXY" and w_n==0 : att="cmd" cmd=[] m=int(line) elif att=="cmd" and m>0 : dl=line.strip().split(" ") cmd.append([dl[0],int(dl[1])]) m-=1 if m==0 : a=move(cmd,gems) ans="Yes" if a==n else "No" print(ans) att="gemsN" ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; gems := Sequence{} ; cmd := Sequence{} ; var att : String := "gemsN" ; for line : OclFile["System.in"] do ( if att = "gemsN" then ( n := ("" + ((line)))->toInteger(); var w_n : int := ("" + ((line)))->toInteger() ; if n = 0 then ( break ) else skip ; att := "gemsXY" ; gems := Integer.subrange(0, 21-1)->select(j | true)->collect(j | (Integer.subrange(0, 21-1)->select(i | true)->collect(i | (0)))) ) else (if att = "gemsXY" & w_n > 0 then ( var xy : Sequence := ((line->trim().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; gems[xy[1+1]+1][xy->first()+1] := 1 ; w_n := w_n - 1 ) else (if att = "gemsXY" & w_n = 0 then ( att := "cmd" ; cmd := Sequence{} ; var m : int := ("" + ((line)))->toInteger() ) else (if att = "cmd" & m > 0 then ( var dl : OclAny := line->trim().split(" ") ; execute ((Sequence{dl->first()}->union(Sequence{ ("" + ((dl[1+1])))->toInteger() })) : cmd) ; m := m - 1 ; if m = 0 then ( var a : OclAny := move(cmd, gems) ; var ans : String := if a = n then "Yes" else "No" endif ; execute (ans)->display() ; att := "gemsN" ) else skip ) else skip ) ) ) ); operation move(cmd : OclAny, gems : OclAny) : OclAny pre: true post: true activity: var n : int := 0 ; var x : OclAny := 10; var y : int := 10 ; for c : cmd do ( var d : OclAny := c->first() ; var l : OclAny := c[1+1] ; for s : Integer.subrange(0, l-1) do ( if d = "N" then ( y := y + 1 ) else (if d = "E" then ( x := x + 1 ) else (if d = "S" then ( y := y - 1 ) else (if d = "W" then ( x := x - 1 ) else skip ) ) ) ; if gems[y+1][x+1] = 1 then ( n := n + 1 ; gems[y+1][x+1] := 0 ) else skip)) ; return n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys while True : n=int(input()) if n!=0 : jewels=[[int(i)for i in input().split()]for j in range(n)] n=int(input()) moves=[[i for i in input().split()]for k in range(n)] for i,j in enumerate(moves): moves[i][1]=int(moves[i][1]) coodinates=[[10,10]] current_cell=[10,10] for i,k in enumerate(moves): direction=moves[i][0] vector=moves[i][1] if direction=='N' : for j in range(1,vector+1): coodinates.append([current_cell[0],current_cell[1]+j]) current_cell[1]=current_cell[1]+vector elif direction=='S' : for j in range(1,vector+1): coodinates.append([current_cell[0],current_cell[1]-j]) current_cell[1]=current_cell[1]-vector elif direction=='W' : for j in range(1,vector+1): coodinates.append([current_cell[0]-j,current_cell[1]]) current_cell[0]=current_cell[0]-vector elif direction=='E' : for j in range(1,vector+1): coodinates.append([current_cell[0]+j,current_cell[1]]) current_cell[0]=current_cell[0]+vector flag=True for i in jewels : if i not in coodinates : flag=False break if flag : print('Yes') else : print('No') else : sys.exit() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n /= 0 then ( var jewels : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())))) ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var moves : Sequence := Integer.subrange(0, n-1)->select(k | true)->collect(k | (input().split()->select(i | true)->collect(i | (i)))) ; for _tuple : Integer.subrange(1, (moves)->size())->collect( _indx | Sequence{_indx-1, (moves)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); moves[i+1][1+1] := ("" + ((moves[i+1][1+1])))->toInteger()) ; var coodinates : Sequence := Sequence{ Sequence{10}->union(Sequence{ 10 }) } ; var current_cell : Sequence := Sequence{10}->union(Sequence{ 10 }) ; for _tuple : Integer.subrange(1, (moves)->size())->collect( _indx | Sequence{_indx-1, (moves)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var k : OclAny := _tuple->at(_indx); var direction : OclAny := moves[i+1]->first() ; var vector : OclAny := moves[i+1][1+1] ; if direction = 'N' then ( for j : Integer.subrange(1, vector + 1-1) do ( execute ((Sequence{current_cell->first()}->union(Sequence{ current_cell[1+1] + j })) : coodinates)) ; current_cell[1+1] := current_cell[1+1] + vector ) else (if direction = 'S' then ( for j : Integer.subrange(1, vector + 1-1) do ( execute ((Sequence{current_cell->first()}->union(Sequence{ current_cell[1+1] - j })) : coodinates)) ; current_cell[1+1] := current_cell[1+1] - vector ) else (if direction = 'W' then ( for j : Integer.subrange(1, vector + 1-1) do ( execute ((Sequence{current_cell->first() - j}->union(Sequence{ current_cell[1+1] })) : coodinates)) ; current_cell->first() := current_cell->first() - vector ) else (if direction = 'E' then ( for j : Integer.subrange(1, vector + 1-1) do ( execute ((Sequence{current_cell->first() + j}->union(Sequence{ current_cell[1+1] })) : coodinates)) ; current_cell->first() := current_cell->first() + vector ) else skip ) ) ) ) ; var flag : boolean := true ; for i : jewels do ( if (coodinates)->excludes(i) then ( flag := false ; break ) else skip) ; if flag then ( execute ('Yes')->display() ) else ( execute ('No')->display() ) ) else ( sys.exit() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _robotXY=[] def RobotMove(dir,amt,stPoint): global _robotXY isXMove=True orgX,orgY=_robotXY if dir=="N" : isXMove=False _robotXY[1]+=amt elif dir=="E" : _robotXY[0]+=amt elif dir=="S" : isXMove=False _robotXY[1]-=amt elif dir=="W" : _robotXY[0]-=amt if isXMove : startX=min(orgX,_robotXY[0]) endX=max(orgX,_robotXY[0]) for i in range(startX,endX+1): if[i,_robotXY[1]]in stPoint : stPoint.remove([i,_robotXY[1]]) else : startY=min(orgY,_robotXY[1]) endY=max(orgY,_robotXY[1]) for i in range(startY,endY+1): if[_robotXY[0],i]in stPoint : stPoint.remove([_robotXY[0],i]) while True : _robotXY=[10,10] n=int(input()) if n==0 : break stPoint=[list(map(int,input().split()))for _ in range(n)] m=int(input()) for _ in range(m): dir,amt=input().split() RobotMove(dir,int(amt),stPoint) if stPoint : print("No") else : print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { attribute _robotXY : OclAny; operation initialise() pre: true post: true activity: var _robotXY : Sequence := Sequence{} ; skip ; while true do ( _robotXY := Sequence{10}->union(Sequence{ 10 }) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; stPoint := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, m-1) do ( Sequence{dir,amt} := input().split() ; RobotMove(dir, ("" + ((amt)))->toInteger(), stPoint)) ; if stPoint then ( execute ("No")->display() ) else ( execute ("Yes")->display() )); operation RobotMove(dir : OclAny, amt : OclAny, stPoint : OclAny) pre: true post: true activity: skip ; var isXMove : boolean := true ; var orgX : OclAny := null; var orgY : OclAny := null; Sequence{orgX,orgY} := _robotXY ; if dir = "N" then ( isXMove := false ; _robotXY[1+1] := _robotXY[1+1] + amt ) else (if dir = "E" then ( _robotXY->first() := _robotXY->first() + amt ) else (if dir = "S" then ( isXMove := false ; _robotXY[1+1] := _robotXY[1+1] - amt ) else (if dir = "W" then ( _robotXY->first() := _robotXY->first() - amt ) else skip ) ) ) ; if isXMove then ( var startX : OclAny := Set{orgX, _robotXY->first()}->min() ; var endX : OclAny := Set{orgX, _robotXY->first()}->max() ; for i : Integer.subrange(startX, endX + 1-1) do ( if (stPoint)->includes(Sequence{i}->union(Sequence{ _robotXY[1+1] })) then ( execute ((Sequence{i}->union(Sequence{ _robotXY[1+1] })) /: stPoint) ) else skip) ) else ( var startY : OclAny := Set{orgY, _robotXY[1+1]}->min() ; var endY : OclAny := Set{orgY, _robotXY[1+1]}->max() ; for i : Integer.subrange(startY, endY + 1-1) do ( if (stPoint)->includes(Sequence{_robotXY->first()}->union(Sequence{ i })) then ( execute ((Sequence{_robotXY->first()}->union(Sequence{ i })) /: stPoint) ) else skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import exit,stderr,stdin input=stdin.readline def debug(var,name="hoge"): print(name+":"+str(type(var))+"="+repr(var),file=stderr) return def main(): while(1): N=int(input()) if N==0 : break p=[10,10] g=set() for _ in range(N): g.add(tuple([int(n)for n in input().split()])) M=int(input()) if tuple(p)in g : g.remove(p) for _ in range(M): d,l=input().split() l=int(l) if d=="N" : b=[0,1] elif d=="E" : b=[1,0] elif d=="S" : b=[0,-1] else : b=[-1,0] while(l>0): p[0]+=b[0] p[1]+=b[1] if tuple(p)in g : g.remove(tuple(p)) l-=1 print("Yes" if len(g)==0 else "No") if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation debug(var : OclAny, name : String) pre: true post: true activity: if name->oclIsUndefined() then name := "hoge" else skip; execute (name + ":" + ("" + (((var)->oclType()))) + "=" + ("" + ((var))))->display() ; return; operation main() pre: true post: true activity: while (1) do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if N = 0 then ( break ) else skip ; var p : Sequence := Sequence{10}->union(Sequence{ 10 }) ; var g : Set := Set{}->union(()) ; for _anon : Integer.subrange(0, N-1) do ( execute (((input().split()->select(n | true)->collect(n | (("" + ((n)))->toInteger())))) : g)) ; var M : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (g)->includes((p)) then ( execute ((p) /: g) ) else skip ; for _anon : Integer.subrange(0, M-1) do ( var d : OclAny := null; var l : OclAny := null; Sequence{d,l} := input().split() ; var l : int := ("" + ((l)))->toInteger() ; if d = "N" then ( var b : Sequence := Sequence{0}->union(Sequence{ 1 }) ) else (if d = "E" then ( b := Sequence{1}->union(Sequence{ 0 }) ) else (if d = "S" then ( b := Sequence{0}->union(Sequence{ -1 }) ) else ( b := Sequence{-1}->union(Sequence{ 0 }) ) ) ) ; while (l > 0) do ( p->first() := p->first() + b->first() ; p[1+1] := p[1+1] + b[1+1] ; if (g)->includes((p)) then ( execute (((p)) /: g) ) else skip ; l := l - 1)) ; execute (if (g)->size() = 0 then "Yes" else "No" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def checkPerfectcube(n): cube_root=n**(1./3.) if round(cube_root)**3==n : return True else : return False def largestNonPerfectcubeNumber(a,n): maxi=-1 for i in range(0,n,1): if(checkPerfectcube(a[i])==False): maxi=max(a[i],maxi) return maxi if __name__=='__main__' : a=[16,64,25,2,3,10] n=len(a) print(largestNonPerfectcubeNumber(a,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( a := Sequence{16}->union(Sequence{64}->union(Sequence{25}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 10 }))))) ; n := (a)->size() ; execute (largestNonPerfectcubeNumber(a, n))->display() ) else skip; operation checkPerfectcube(n : OclAny) : OclAny pre: true post: true activity: var cube_root : double := (n)->pow((1. / 3.)) ; if ((cube_root)->round())->pow(3) = n then ( return true ) else ( return false ); operation largestNonPerfectcubeNumber(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var maxi : int := -1 ; for i : Integer.subrange(0, n-1)->select( $x | ($x - 0) mod 1 = 0 ) do ( if (checkPerfectcube(a[i+1]) = false) then ( maxi := Set{a[i+1], maxi}->max() ) else skip) ; return maxi; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys readline=sys.stdin.readline write=sys.stdout.write def solve(): MOD=10**9+7 D=int(readline()) L=[int(readline())for i in range(D)] S=int(readline()) dp=[0]*(S+1) dp[S]=1 for i in range(D): l=L[i] for i in range(l,S+1): dp[i-l]-=dp[i] ans=0 for i in range(S+1): ans+=pow(i,D,MOD)*dp[i] ans %=MOD write("%d\n" % ans) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var readline : OclAny := (OclFile["System.in"]).readline ; var write : OclAny := (OclFile["System.out"]).write ; skip ; solve(); operation solve() pre: true post: true activity: var MOD : double := (10)->pow(9) + 7 ; var D : int := ("" + ((readline())))->toInteger() ; var L : Sequence := Integer.subrange(0, D-1)->select(i | true)->collect(i | (("" + ((readline())))->toInteger())) ; var S : int := ("" + ((readline())))->toInteger() ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (S + 1)) ; dp[S+1] := 1 ; for i : Integer.subrange(0, D-1) do ( var l : OclAny := L[i+1] ; for i : Integer.subrange(l, S + 1-1) do ( dp[i - l+1] := dp[i - l+1] - dp[i+1])) ; var ans : int := 0 ; for i : Integer.subrange(0, S + 1-1) do ( ans := ans + (i)->pow(D) * dp[i+1]) ; ans := ans mod MOD ; write(StringLib.format("%d\n",ans)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): n,i=map(int,input().split()) ns=sorted([*map(int,input().split())]) k=1<<(i*8//n) lis=[] for i in range(n-1): if ns[i]!=ns[i+1]: lis.append(i+1) lis.append(n) print(0 if len(lis)<=k else n-max(lis[i+k]-lis[i]for i in range(len(lis)-k))) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: var n : OclAny := null; var i : OclAny := null; Sequence{n,i} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ns : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; var k : int := 1 * (2->pow((i * 8 div n))) ; var lis : Sequence := Sequence{} ; for i : Integer.subrange(0, n - 1-1) do ( if ns[i+1] /= ns[i + 1+1] then ( execute ((i + 1) : lis) ) else skip) ; execute ((n) : lis) ; execute (if ((lis)->size()->compareTo(k)) <= 0 then 0 else n - ((argument (test (logical_test (comparison (expr (expr (atom (name lis)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (name k))))))))) ]))) - (expr (atom (name lis)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name lis)))))))) )))) - (expr (atom (name k))))))))) )))))))))->max() endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def shufleArray(a,f,l): if(l>f): return if(l-f==1): return mid=int((f+l)/2) temp=mid+1 mmid=int((f+mid)/2) for i in range(mmid+1,mid+1): (a[i],a[temp])=(a[temp],a[i]) temp+=1 shufleArray(a,f,mid) shufleArray(a,mid+1,l) a=[1,3,5,7,2,4,6,8] n=len(a) shufleArray(a,0,n-1) for i in range(0,n): print(a[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { suite`nestedAttributeDefinitions operation initialise() pre: true post: true activity: skip ; Sequence{a[i+1], a[temp+1]} := Sequence{a[temp+1], a[i+1]}; operation shufleArray(a : OclAny, f : OclAny, l : OclAny) pre: true post: true activity: if ((l->compareTo(f)) > 0) then ( return ) else skip ; if (l - f = 1) then ( return ) else skip ; var mid : int := ("" + (((f + l) / 2)))->toInteger() ; var temp : int := mid + 1 ; var mmid : int := ("" + (((f + mid) / 2)))->toInteger() ; for i : Integer.subrange(mmid + 1, mid + 1-1) do (suite); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calcTrees(cont,startRow,startCol,a,b): trees=0 for i in range(a): for j in range(b): if cont[startRow+i][startCol+j]==1 : trees+=1 return trees n,m=list(map(int,input().split(' '))) cont=[] for i in range(n): cont.append([int(item)for item in input().split(' ')]) a,b=list(map(int,input().split(' '))) ans=a*b for i in range(n): for j in range(m): if i<=n-a and j<=m-b : helper=calcTrees(cont,i,j,a,b) if ans>helper : ans=helper if i<=n-b and j<=m-a : helper=calcTrees(cont,i,j,b,a) if ans>helper : ans=helper print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; cont := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((input().split(' ')->select(item | true)->collect(item | (("" + ((item)))->toInteger()))) : cont)) ; Sequence{a,b} := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : double := a * b ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if (i->compareTo(n - a)) <= 0 & (j->compareTo(m - b)) <= 0 then ( var helper : OclAny := calcTrees(cont, i, j, a, b) ; if (ans->compareTo(helper)) > 0 then ( ans := helper ) else skip ) else skip ; if (i->compareTo(n - b)) <= 0 & (j->compareTo(m - a)) <= 0 then ( helper := calcTrees(cont, i, j, b, a) ; if (ans->compareTo(helper)) > 0 then ( ans := helper ) else skip ) else skip)) ; execute (ans)->display(); operation calcTrees(cont : OclAny, startRow : OclAny, startCol : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var trees : int := 0 ; for i : Integer.subrange(0, a-1) do ( for j : Integer.subrange(0, b-1) do ( if cont[startRow + i+1][startCol + j+1] = 1 then ( trees := trees + 1 ) else skip)) ; return trees; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p=1000000007 def power(x,y): res=1 x=x % p while(y>0): if(y & 1): res=(res*x)% p ; y=y>>1 x=(x*x)% p return res % p n=3 x=(power(3,n)% p+1)% p x=(x-power(2,n+1)+p)% p x=(x*power(2,p-2))% p print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : int := 1000000007 ; skip ; var n : int := 3 ; x := (power(3, n) mod p + 1) mod p ; x := (x - power(2, n + 1) + p) mod p ; x := (x * power(2, p - 2)) mod p ; execute (x)->display(); operation power(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; x := x mod p ; while (y > 0) do ( if (MathLib.bitwiseAnd(y, 1)) then ( res := (res * x) mod p; ) else skip ; y := y /(2->pow(1)) ; x := (x * x) mod p) ; return res mod p; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def checkplusperfect(x): temp=x n=0 while(x!=0): x=x//10 n=n+1 x=temp sm=0 while(x!=0): sm=sm+(int)(math.pow(x % 10,n)) x=x//10 return(sm==temp) x=9474 if(checkplusperfect(x)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; x := 9474 ; if (checkplusperfect(x)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation checkplusperfect(x : OclAny) : OclAny pre: true post: true activity: var temp : OclAny := x ; var n : int := 0 ; while (x /= 0) do ( x := x div 10 ; n := n + 1) ; x := temp ; var sm : int := 0 ; while (x /= 0) do ( sm := sm + (OclType["int"])((x mod 10)->pow(n)) ; x := x div 10) ; return (sm = temp); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque n,m=map(int,input().split()) abx=[[0]*(n+2)for i in range(n+2)] for i in range(m): ai,bi,xi=map(int,input().split()) abx[ai][bi]=max(abx[ai][bi],xi) pp=[[0]*(n+2)for i in range(n+2)] for j in range(1,n+2): dq=deque() for i in range(j,n+2): if abx[i][j]>0 : dq.append([i,abx[i][j]]) iiii=j-1 while len(dq): ii,xi=dq.popleft() if ii+xi>iiii : for iii in range(max(ii,iiii+1),ii+xi+1): pp[iii][j]=iii-ii+1 iiii=iii icnt=0 for i in range(1,n+1): for j in range(1,i+1): abij=pp[i][j-1]-1 pp[i][j]=max(pp[i][j],abij) if pp[i][j]>0 : icnt+=1 print(icnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var abx : Sequence := Integer.subrange(0, n + 2-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 2)))) ; for i : Integer.subrange(0, m-1) do ( var ai : OclAny := null; var bi : OclAny := null; var xi : OclAny := null; Sequence{ai,bi,xi} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; abx[ai+1][bi+1] := Set{abx[ai+1][bi+1], xi}->max()) ; var pp : Sequence := Integer.subrange(0, n + 2-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 2)))) ; for j : Integer.subrange(1, n + 2-1) do ( var dq : Sequence := () ; for i : Integer.subrange(j, n + 2-1) do ( if abx[i+1][j+1] > 0 then ( execute ((Sequence{i}->union(Sequence{ abx[i+1][j+1] })) : dq) ) else skip) ; var iiii : double := j - 1 ; while (dq)->size() do ( var ii : OclAny := null; var xi : OclAny := null; Sequence{ii,xi} := dq->first() ; dq := dq->tail() ; if (ii + xi->compareTo(iiii)) > 0 then ( for iii : Integer.subrange(Set{ii, iiii + 1}->max(), ii + xi + 1-1) do ( pp[iii+1][j+1] := iii - ii + 1 ; iiii := iii) ) else skip)) ; var icnt : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(1, i + 1-1) do ( var abij : double := pp[i+1][j - 1+1] - 1 ; pp[i+1][j+1] := Set{pp[i+1][j+1], abij}->max() ; if pp[i+1][j+1] > 0 then ( icnt := icnt + 1 ) else skip)) ; execute (icnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,M=map(int,input().split()) d=[[0]*(N+2)for _ in range(N+2)] for i in range(M): a,b,x=map(int,input().split()) a-=1 b-=1 d[a][b]+=1 d[a][b+1]-=1 d[a+x+1][b]-=1 d[a+x+2][b+1]+=1 d[a+x+1][b+x+2]+=1 d[a+x+2][b+x+2]-=1 for i in range(N+2): for j in range(1,N+2): d[i][j]+=d[i][j-1] for i in range(N+2): for j in range(1,N+2): d[j][i]+=d[j-1][i] for i in range(1,N+2): for j in range(1,N+2): d[i][j]+=d[i-1][j-1] res=0 for i in range(N+2): for j in range(N+2): if d[i][j]!=0 : res+=1 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := Integer.subrange(0, N + 2-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 2)))) ; for i : Integer.subrange(0, M-1) do ( var a : OclAny := null; var b : OclAny := null; var x : OclAny := null; Sequence{a,b,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := a - 1 ; b := b - 1 ; d[a+1][b+1] := d[a+1][b+1] + 1 ; d[a+1][b + 1+1] := d[a+1][b + 1+1] - 1 ; d[a + x + 1+1][b+1] := d[a + x + 1+1][b+1] - 1 ; d[a + x + 2+1][b + 1+1] := d[a + x + 2+1][b + 1+1] + 1 ; d[a + x + 1+1][b + x + 2+1] := d[a + x + 1+1][b + x + 2+1] + 1 ; d[a + x + 2+1][b + x + 2+1] := d[a + x + 2+1][b + x + 2+1] - 1) ; for i : Integer.subrange(0, N + 2-1) do ( for j : Integer.subrange(1, N + 2-1) do ( d[i+1][j+1] := d[i+1][j+1] + d[i+1][j - 1+1])) ; for i : Integer.subrange(0, N + 2-1) do ( for j : Integer.subrange(1, N + 2-1) do ( d[j+1][i+1] := d[j+1][i+1] + d[j - 1+1][i+1])) ; for i : Integer.subrange(1, N + 2-1) do ( for j : Integer.subrange(1, N + 2-1) do ( d[i+1][j+1] := d[i+1][j+1] + d[i - 1+1][j - 1+1])) ; var res : int := 0 ; for i : Integer.subrange(0, N + 2-1) do ( for j : Integer.subrange(0, N + 2-1) do ( if d[i+1][j+1] /= 0 then ( res := res + 1 ) else skip)) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) t=[[0]*(n+2)for i in range(n+2)] for i in range(m): a,b,x=map(int,input().split()) a-=1 b-=1 t[a][b]+=1 t[a][b+1]-=1 t[a+x+1][b]-=1 t[a+x+1][b+x+2]+=1 t[a+x+2][b+1]+=1 t[a+x+2][b+x+2]-=1 for i in range(n+2): for j in range(1,n+2): t[i][j]+=t[i][j-1] for i in range(n+2): for j in range(1,n+2): t[j][i]+=t[j-1][i] for i in range(1,n+2): for j in range(1,n+2): t[i][j]+=t[i-1][j-1] ans=0 for i in range(n): for j in range(i+1): if t[i][j]!=0 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : Sequence := Integer.subrange(0, n + 2-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 2)))) ; for i : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; var x : OclAny := null; Sequence{a,b,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a := a - 1 ; b := b - 1 ; t[a+1][b+1] := t[a+1][b+1] + 1 ; t[a+1][b + 1+1] := t[a+1][b + 1+1] - 1 ; t[a + x + 1+1][b+1] := t[a + x + 1+1][b+1] - 1 ; t[a + x + 1+1][b + x + 2+1] := t[a + x + 1+1][b + x + 2+1] + 1 ; t[a + x + 2+1][b + 1+1] := t[a + x + 2+1][b + 1+1] + 1 ; t[a + x + 2+1][b + x + 2+1] := t[a + x + 2+1][b + x + 2+1] - 1) ; for i : Integer.subrange(0, n + 2-1) do ( for j : Integer.subrange(1, n + 2-1) do ( t[i+1][j+1] := t[i+1][j+1] + t[i+1][j - 1+1])) ; for i : Integer.subrange(0, n + 2-1) do ( for j : Integer.subrange(1, n + 2-1) do ( t[j+1][i+1] := t[j+1][i+1] + t[j - 1+1][i+1])) ; for i : Integer.subrange(1, n + 2-1) do ( for j : Integer.subrange(1, n + 2-1) do ( t[i+1][j+1] := t[i+1][j+1] + t[i - 1+1][j - 1+1])) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, i + 1-1) do ( if t[i+1][j+1] /= 0 then ( ans := ans + 1 ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def properDivisorSum(n): sum=0 for i in range(1,n+1): sum+=(n//i)*i return sum-n*(n+1)//2 n=4 print(properDivisorSum(n)) n=5 print(properDivisorSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; execute (properDivisorSum(n))->display() ; n := 5 ; execute (properDivisorSum(n))->display(); operation properDivisorSum(n : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( sum := sum + (n div i) * i) ; return sum - n * (n + 1) div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): txt=input() if hello(txt): print("YES") else : print("NO") def hello(txt,n=0): list=["h","e","l","l","o"] for s in txt : if s==list[n]: n+=1 if n<5 : hello(txt[txt.index(s)+1 :],n) else : break if n==5 : return True else : return False main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; main(); operation main() pre: true post: true activity: var txt : String := (OclFile["System.in"]).readLine() ; if hello(txt) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); operation hello(txt : OclAny, n : int) : OclAny pre: true post: true activity: if n->oclIsUndefined() then n := 0 else skip; var OclType["Sequence"] : Sequence := Sequence{"h"}->union(Sequence{"e"}->union(Sequence{"l"}->union(Sequence{"l"}->union(Sequence{ "o" })))) ; for s : txt->characters() do ( if s = [n+1] then ( n := n + 1 ; if n < 5 then ( hello(txt.subrange(txt->indexOf(s) - 1 + 1+1), n) ) else ( break ) ) else skip) ; if n = 5 then ( return true ) else ( return false ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() count=0 isHello=False for i in range(len(s)): if(count==0 and s[i]=="h"): count+=1 elif(count==1 and s[i]=="e"): count+=1 elif(count==2 and s[i]=="l"): count+=1 elif(count==3 and s[i]=="l"): count+=1 elif(count==4 and s[i]=="o"): count+=1 if count==5 : isHello=True break if isHello : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var count : int := 0 ; var isHello : boolean := false ; for i : Integer.subrange(0, (s)->size()-1) do ( if (count = 0 & s[i+1] = "h") then ( count := count + 1 ) else (if (count = 1 & s[i+1] = "e") then ( count := count + 1 ) else (if (count = 2 & s[i+1] = "l") then ( count := count + 1 ) else (if (count = 3 & s[i+1] = "l") then ( count := count + 1 ) else (if (count = 4 & s[i+1] = "o") then ( count := count + 1 ) else skip ) ) ) ) ; if count = 5 then ( isHello := true ; break ) else skip) ; if isHello then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=3 def MaxTraceSub(mat): max_trace=0 for i in range(N): for j in range(N): r=i s=j trace=0 while(runion(Sequence{2}->union(Sequence{ 5 }))}->union(Sequence{Sequence{6}->union(Sequence{10}->union(Sequence{ 4 }))}->union(Sequence{ Sequence{2}->union(Sequence{7}->union(Sequence{ -10 })) })) ; execute (MaxTraceSub(mat))->display() ) else skip; operation MaxTraceSub(mat : OclAny) : OclAny pre: true post: true activity: var max_trace : int := 0 ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( var r : OclAny := i ; var s : OclAny := j ; var trace : int := 0 ; while ((r->compareTo(N)) < 0 & (s->compareTo(N)) < 0) do ( trace := trace + mat[r+1] ; r := r + 1 ; s := s + 1 ; max_trace := Set{trace, max_trace}->max()))) ; return max_trace; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T,s,q=map(int,input().split()) v=(q-1)/q tm=1 t=s/(1-v) while(T-s)/v-t>0 : if(T-s)/v-t<1e-10 : break tm+=1 s+=v*t t=s/(1-v) print(tm) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : OclAny := null; var s : OclAny := null; var q : OclAny := null; Sequence{T,s,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var v : double := (q - 1) / q ; var tm : int := 1 ; var t : double := s / (1 - v) ; while (T - s) / v - t > 0 do ( if (T - s) / v - t < ("1e-10")->toReal() then ( break ) else skip ; tm := tm + 1 ; s := s + v * t ; t := s / (1 - v)) ; execute (tm)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=input() h=x.find("h") e=x.find("e",h) l=x.find("l",e) o=x.find("o",l) ln=len(x) if ln<5 : print("NO") elif eindexOf("h") - 1 ; var e : int := x->indexOf("e", h) - 1 ; var l : int := x->indexOf("l", e) - 1 ; var o : int := x->indexOf("o", l) - 1 ; var ln : int := (x)->size() ; if ln < 5 then ( execute ("NO")->display() ) else (if (e->compareTo(h)) < 0 then ( execute ("NO")->display() ) else (if (l->compareTo(e)) < 0 then ( execute ("NO")->display() ) else (if (o->compareTo(l)) < 0 or x->count("l", l) < 2 then ( execute ("NO")->display() ) else ( execute ("YES")->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() h=0 e=0 l=0 o=0 s1='' for i in s : if i=='h' and h==0 : s1=s1+i h+=1 if i=='e' and e==0 and h==1 : s1=s1+i e+=1 if i=='l' and l<=1 and e==1 : s1=s1+i l+=1 if i=='o' and o==0 and l==2 : s1=s1+i o+=1 if s1=='hello' : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var h : int := 0 ; var e : int := 0 ; var l : int := 0 ; var o : int := 0 ; var s1 : String := '' ; for i : s->characters() do ( if i = 'h' & h = 0 then ( s1 := s1 + i ; h := h + 1 ) else skip ; if i = 'e' & e = 0 & h = 1 then ( s1 := s1 + i ; e := e + 1 ) else skip ; if i = 'l' & l <= 1 & e = 1 then ( s1 := s1 + i ; l := l + 1 ) else skip ; if i = 'o' & o = 0 & l = 2 then ( s1 := s1 + i ; o := o + 1 ) else skip) ; if s1 = 'hello' then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calcTrees(cont,startRow,startCol,a,b): counter=0 for i in range(startRow,startRow+a): for j in range(startCol,startCol+b): counter+=cont[i][j] return counter n,m=[int(item)for item in input().split(' ')] cont=[] for i in range(n): cont.append([int(item)for item in input().split(' ')]) a,b=[int(item)for item in input().split(' ')] ans=a*b for i in range(n): for j in range(m): if i<=n-a and j<=m-b : helper=calcTrees(cont,i,j,a,b) if ans>helper : ans=helper if i<=n-b and j<=m-a : helper=calcTrees(cont,i,j,b,a) if ans>helper : ans=helper print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := input().split(' ')->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; cont := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((input().split(' ')->select(item | true)->collect(item | (("" + ((item)))->toInteger()))) : cont)) ; Sequence{a,b} := input().split(' ')->select(item | true)->collect(item | (("" + ((item)))->toInteger())) ; var ans : double := a * b ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if (i->compareTo(n - a)) <= 0 & (j->compareTo(m - b)) <= 0 then ( var helper : OclAny := calcTrees(cont, i, j, a, b) ; if (ans->compareTo(helper)) > 0 then ( ans := helper ) else skip ) else skip ; if (i->compareTo(n - b)) <= 0 & (j->compareTo(m - a)) <= 0 then ( helper := calcTrees(cont, i, j, b, a) ; if (ans->compareTo(helper)) > 0 then ( ans := helper ) else skip ) else skip)) ; execute (ans)->display(); operation calcTrees(cont : OclAny, startRow : OclAny, startCol : OclAny, a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var counter : int := 0 ; for i : Integer.subrange(startRow, startRow + a-1) do ( for j : Integer.subrange(startCol, startCol + b-1) do ( counter := counter + cont[i+1][j+1])) ; return counter; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math while(True): n=input() if(n==0): break s=map(int,raw_input().split()) sum=0 for i in range(len(s)): sum+=s[i] average=float(sum)/n ; temp=0.0 for i in range(len(s)): temp+=(s[i]-average)*(s[i]-average); print(math.sqrt(temp/n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while (true) do ( var n : String := (OclFile["System.in"]).readLine() ; if (n = 0) then ( break ) else skip ; var s : Sequence := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sum : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( sum := sum + s[i+1]) ; var average : double := ("" + ((sum)))->toReal() / n; ; var temp : double := 0.0 ; for i : Integer.subrange(0, (s)->size()-1) do ( temp := temp + (s[i+1] - average) * (s[i+1] - average);) ; execute ((temp / n)->sqrt())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt while True : n=int(input()) if n==0 : break a=list(map(int,input().strip().split())) print(sqrt(n*sum(x*x for x in a)-sum(a)**2)/n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var a : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (sqrt(n * ((argument (test (logical_test (comparison (expr (expr (atom (name x))) * (expr (atom (name x))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name a))))))))->sum() - ((a)->sum())->pow(2)) / n)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math while True : n=int(input().strip()) if n==0 : break else : line=input().strip().split() scores=list(map(float,line)) sum=0.0 ss=0.0 for score in scores : sum+=score ss+=score**2 sd=math.sqrt((n*ss-sum**2)/n**2) print("%.5f" % sd) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : int := ("" + ((input()->trim())))->toInteger() ; if n = 0 then ( break ) else ( var line : OclAny := input()->trim().split() ; var scores : Sequence := ((line)->collect( _x | (OclType["double"])->apply(_x) )) ; var sum : double := 0.0 ; var ss : double := 0.0 ; for score : scores do ( sum := sum + score ; ss := ss + (score)->pow(2)) ; var sd : double := ((n * ss - (sum)->pow(2)) / (n)->pow(2))->sqrt() ; execute (StringLib.format("%.5f",sd))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while 1 : n=input() if n==0 : break L=map(float,raw_input().split()) avg=sum(L)/len(L) print(sum((x-avg)**2 for x in L)/n)**0.5 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while 1 do ( var n : String := (OclFile["System.in"]).readLine() ; if n = 0 then ( break ) else skip ; var L : Sequence := (raw_input().split())->collect( _x | (OclType["double"])->apply(_x) ) ; var avg : double := (L)->sum() / (L)->size() ; (expr (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name sum)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) - (expr (atom (name avg)))))))) ))) ** (expr (atom (number (integer 2)))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name L)))))))) )))) / (expr (atom (name n))))))))) )))) ** (expr (atom (number 0.5))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math while True : n=int(input()) if n==0 : break S=list(map(int,input().split())) average=sum(S)/len(S) square_sum=sum(math.pow((score-average),2)for score in S) variance=square_sum/len(S) print(math.sqrt(variance)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var S : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var average : double := (S)->sum() / (S)->size() ; var square_sum : OclAny := ((argument (test (logical_test (comparison (expr (atom (name math)) (trailer . (name pow) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name score))) - (expr (atom (name average)))))))) ))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) ))))))) (comp_for for (exprlist (expr (atom (name score)))) in (logical_test (comparison (expr (atom (name S))))))))->sum() ; var variance : double := square_sum / (S)->size() ; execute ((variance)->sqrt())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,m=map(int,input().split()) if n==0 and m==0 : break a=list(map(int,input().split())) a.sort() list1=[] for i in range(n): for j in range(i+1,n): price1=a[i]+a[j] list1.append(price1) list1.sort() list2=list(filter(lambda p : m>=p,list1)) if list2 : print(max(list2)) else : print("NONE") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 & m = 0 then ( break ) else skip ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var list1 : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( var price1 : OclAny := a[i+1] + a[j+1] ; execute ((price1) : list1))) ; list1 := list1->sort() ; var list2 : Sequence := ((list1)->select( _x | (lambda p : OclAny in ((m->compareTo(p)) >= 0))->apply(_x) = true )) ; if list2 then ( execute ((list2)->max())->display() ) else ( execute ("NONE")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import re from collections import deque,defaultdict,Counter from math import ceil,sqrt,hypot,factorial,pi,sin,cos,radians,log2,gcd from itertools import permutations,combinations,product from operator import itemgetter,mul from copy import deepcopy from string import ascii_lowercase,ascii_uppercase,digits def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(map(int,input().split())) sys.setrecursionlimit(10**9) INF=float('inf') mod=10**9+7 ans=[] while 1 : n,m=MAP() if n==0 and m==0 : break else : a=LIST() lis=[sum(x)for x in list(combinations(a,2))if sum(x)<=m] if not lis : ans.append('NONE') else : ans.append(max(lis)) for x in ans : print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := ("" + (('inf')))->toReal() ; var mod : double := (10)->pow(9) + 7 ; var ans : Sequence := Sequence{} ; while 1 do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := MAP() ; if n = 0 & m = 0 then ( break ) else ( var a : OclAny := LIST() ; var lis : Sequence := (combinations(a, 2))->select(x | ((x)->sum()->compareTo(m)) <= 0)->collect(x | ((x)->sum())) ; if not(lis) then ( execute (('NONE') : ans) ) else ( execute (((lis)->max()) : ans) ) )) ; for x : ans do ( execute (x)->display()); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t,s,q=map(int,input().split()) p=0 while scollect( _x | (OclType["int"])->apply(_x) ) ; var p : int := 0 ; while (s->compareTo(t)) < 0 do ( var s : double := s * q; p := p + 1) ; execute (p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,re,sys,operator,math from collections import Counter,deque from operator import itemgetter from itertools import accumulate,combinations,groupby from sys import stdin,setrecursionlimit from copy import deepcopy import heapq setrecursionlimit(10**6) while 1 : n,m=map(int,stdin.readline().rstrip().split()) if(n,m)==(0,0): break a=[int(i)for i in stdin.readline().rstrip().split()] ans=0 for i in range(n-1): for j in range(i+1,n): t=a[i]+a[j] if t<=m : ans=max(ans,t) print(ans if ans!=0 else "NONE") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; setrecursionlimit((10)->pow(6)) ; while 1 do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if Sequence{n, m} = Sequence{0, 0} then ( break ) else skip ; var a : Sequence := stdin.readLine().rstrip().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(i + 1, n-1) do ( var t : OclAny := a[i+1] + a[j+1] ; if (t->compareTo(m)) <= 0 then ( ans := Set{ans, t}->max() ) else skip)) ; execute (if ans /= 0 then ans else "NONE" endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools def rdp_connect()->bool : global n,m,a n,m=map(int,input().split()) if n==0 and m==0 : return False a=list(map(int,input().split())) return True if __name__=='__main__' : while rdp_connect(): lis=filter(lambda e : e<=m,map(sum,itertools.combinations(a,2))) try : print(max(lis)) except ValueError : print('NONE') ------------------------------------------------------------ OCL File: --------- class FromPython { attribute n : OclAny; attribute m : OclAny; attribute a : OclAny; operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( while rdp_connect() do ( var lis : Sequence := ((itertools.combinations(a, 2))->collect( _x | (sum)->apply(_x) ))->select( _x | (lambda e : OclAny in ((e->compareTo(m)) <= 0))->apply(_x) = true ) ; try ( execute ((lis)->max())->display()) (except_clause except (test (logical_test (comparison (expr (atom (name ValueError)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NONE'))))))) ))))))))))))))) ) else skip; operation rdp_connect() : boolean pre: true post: true activity: skip; skip; skip ; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 & m = 0 then ( return false ) else skip ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- maxes=[] cnt=0 while True : s=input() d=s.split() n=int(d[0]) m=int(d[1]) if n==0 and m==0 : break s=input() d=s.split() a=[] for i in range(n): a.append(int(d[i])) p=[[0 for i in range(n)]for j in range(n)] for i in range(n): for j in range(i+1,n): p[i][j]=(a[i]+a[j]) max=0 for i in range(n): for j in range(i+1,n): if p[i][j]>m : continue if maxfirst())))->toInteger() ; var m : int := ("" + ((d[1+1])))->toInteger() ; if n = 0 & m = 0 then ( break ) else skip ; s := (OclFile["System.in"]).readLine() ; d := s.split() ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + ((d[i+1])))->toInteger()) : a)) ; var p : Sequence := Integer.subrange(0, n-1)->select(j | true)->collect(j | (Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( p[i+1][j+1] := (a[i+1] + a[j+1]))) ; var max : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if (p[i+1][j+1]->compareTo(m)) > 0 then ( continue ) else skip ; if (max->compareTo(p[i+1][j+1])) < 0 then ( max := p[i+1][j+1] ) else skip)) ; if max = 0 then ( execute ((-1) : maxes) ) else ( execute ((max) : maxes) ) ; cnt := cnt + 1) ; for i : Integer.subrange(0, cnt-1) do ( if maxes[i+1] = -1 then ( execute ("NONE")->display() ) else ( execute (maxes[i+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n,m=map(int,input().split()) w=[list(map(int,input().split()))for _ in range(n)] a,b=map(int,input().split()) c=3000 for i in range(n-a+1): for j in range(m-b+1): c=min(c,sum([sum(w[k][j : j+b])for k in range(i,i+a)])) for i in range(n-b+1): for j in range(m-a+1): c=min(c,sum([sum(w[k][j : j+a])for k in range(i,i+b)])) print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var c : int := 3000 ; for i : Integer.subrange(0, n - a + 1-1) do ( for j : Integer.subrange(0, m - b + 1-1) do ( c := Set{c, (Integer.subrange(i, i + a-1)->select(k | true)->collect(k | ((w[k+1].subrange(j+1, j + b))->sum())))->sum()}->min())) ; for i : Integer.subrange(0, n - b + 1-1) do ( for j : Integer.subrange(0, m - a + 1-1) do ( c := Set{c, (Integer.subrange(i, i + b-1)->select(k | true)->collect(k | ((w[k+1].subrange(j+1, j + a))->sum())))->sum()}->min())) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import factorial,pow a=input() b=input() if('?' not in b): if(sorted(list(a))==sorted(list(b))): print(1) else : print(0) else : x=y=0 for i in a : if(i=='+'): x+=1 else : x-=1 for i in b : if(i=='+'): y+=1 elif(i=='-'): y-=1 c=b.count('?') if(y-c<=x<=y+c): y-=c if((x-y)% 2!=0): print(0) else : z=(x-y)//2 print((factorial(c)/(factorial(z)*factorial(c-z)))/pow(2,c)) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; if ((b)->characters()->excludes('?')) then ( if ((a)->characters()->sort() = (b)->characters()->sort()) then ( execute (1)->display() ) else ( execute (0)->display() ) ) else ( var x : OclAny := 0; var y : int := 0 ; for i : a->characters() do ( if (i = '+') then ( x := x + 1 ) else ( x := x - 1 )) ; for i : b->characters() do ( if (i = '+') then ( y := y + 1 ) else (if (i = '-') then ( y := y - 1 ) else skip)) ; var c : int := b->count('?') ; if ((y - c->compareTo(x)) <= 0 & (x <= y + c)) then ( y := y - c ; if ((x - y) mod 2 /= 0) then ( execute (0)->display() ) else ( var z : int := (x - y) div 2 ; execute ((factorial(c) / (factorial(z) * factorial(c - z))) / (2)->pow(c))->display() ) ) else ( execute (0)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def func(s,i=0): if(i==len(s)): return 0 if(s[i]=="+"): return func(s,i+1)+1 else : return func(s,i+1)-1 def generate(lst,s,i=0): if(i==len(s)): lst.append(s) return if(s[i]=="?"): s=s[: i]+'+'+s[i+1 :] generate(lst,s,i+1) s=s[: i]+"-"+s[i+1 :] generate(lst,s,i+1) s=s[: i]+"?"+s[i+1 :] else : generate(lst,s,i+1) def init(): s=input() t=input() x=func(s) ct=0 lst=[] generate(lst,t) for cat in lst : if(func(cat)==x): ct+=1 print(ct/len(lst)) init() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; init(); operation func(s : OclAny, i : int) : OclAny pre: true post: true activity: if i->oclIsUndefined() then i := 0 else skip; if (i = (s)->size()) then ( return 0 ) else skip ; if (s[i+1] = "+") then ( return func(s, i + 1) + 1 ) else ( return func(s, i + 1) - 1 ); operation generate(lst : OclAny, s : OclAny, i : int) pre: true post: true activity: if i->oclIsUndefined() then i := 0 else skip; if (i = (s)->size()) then ( execute ((s) : lst) ; return ) else skip ; if (s[i+1] = "?") then ( s := s.subrange(1,i) + '+' + s.subrange(i + 1+1) ; generate(lst, s, i + 1) ; s := s.subrange(1,i) + "-" + s.subrange(i + 1+1) ; generate(lst, s, i + 1) ; s := s.subrange(1,i) + "?" + s.subrange(i + 1+1) ) else ( generate(lst, s, i + 1) ); operation init() pre: true post: true activity: s := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var x : OclAny := func(s) ; var ct : int := 0 ; lst := Sequence{} ; generate(lst, t) ; for cat : lst do ( if (func(cat) = x) then ( ct := ct + 1 ) else skip) ; execute (ct / (lst)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math correct_command=input() received_command=input() final_pos_correct=0 for char in correct_command : if char=='+' : final_pos_correct+=1 else : final_pos_correct-=1 received_pos=0 unknown=0 for char in received_command : if char=='+' : received_pos+=1 elif char=='-' : received_pos-=1 else : unknown+=1 if unknown==0 : if final_pos_correct==received_pos : print(1) else : print(0) else : diff=abs(received_pos-final_pos_correct) if unknowncharacters() do ( if char = '+' then ( final_pos_correct := final_pos_correct + 1 ) else ( final_pos_correct := final_pos_correct - 1 )) ; var received_pos : int := 0 ; var unknown : int := 0 ; for char : received_command->characters() do ( if char = '+' then ( received_pos := received_pos + 1 ) else (if char = '-' then ( received_pos := received_pos - 1 ) else ( unknown := unknown + 1 ) ) ) ; if unknown = 0 then ( if final_pos_correct = received_pos then ( execute (1)->display() ) else ( execute (0)->display() ) ) else ( var diff : double := (received_pos - final_pos_correct)->abs() ; if (unknown->compareTo(diff)) < 0 then ( execute (0)->display() ) else ( var a : int := (unknown - diff) div 2 ; var b : double := unknown - a ; var combinations : double := MathLib.factorial(unknown) / (MathLib.factorial(a) * MathLib.factorial(b)) ; var denom : double := (2)->pow(unknown) ; execute (combinations / denom)->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s1=input() s2=input() n=len(s1) ta=0 fa=0 q=0 for i in range(n): if s1[i]=="+" : ta+=1 else : ta-=1 if s2[i]=='+' : fa+=1 elif s2[i]=='-' : fa-=1 else : q+=1 if q==0 : if(fa==ta): print(float(1)) else : print(float(0)) else : a=0 l=[-1,1] q-=1 if q!=0 : for i in range(q): for j in range(len(l)): l.append(l[j]+1) l[j]-=1 for ans in l : if(ans==ta-fa): a+=1 print(a/len(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s1 : String := (OclFile["System.in"]).readLine() ; var s2 : String := (OclFile["System.in"]).readLine() ; var n : int := (s1)->size() ; var ta : int := 0 ; var fa : int := 0 ; var q : int := 0 ; for i : Integer.subrange(0, n-1) do ( if s1[i+1] = "+" then ( ta := ta + 1 ) else ( ta := ta - 1 ) ; if s2[i+1] = '+' then ( fa := fa + 1 ) else (if s2[i+1] = '-' then ( fa := fa - 1 ) else ( q := q + 1 ) ) ) ; if q = 0 then ( if (fa = ta) then ( execute (("" + ((1)))->toReal())->display() ) else ( execute (("" + ((0)))->toReal())->display() ) ) else ( var a : int := 0 ; var l : Sequence := Sequence{-1}->union(Sequence{ 1 }) ; q := q - 1 ; if q /= 0 then ( for i : Integer.subrange(0, q-1) do ( for j : Integer.subrange(0, (l)->size()-1) do ( execute ((l[j+1] + 1) : l) ; l[j+1] := l[j+1] - 1)) ) else skip ; for ans : l do ( if (ans = ta - fa) then ( a := a + 1 ) else skip) ; execute (a / (l)->size())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMaximumBefore(arr,n): for i in range(n): currAns=-1 for j in range(i-1,-1,-1): if(arr[j]>currAns and arr[j]union(Sequence{7}->union(Sequence{6}->union(Sequence{8}->union(Sequence{ 5 })))) ; n := (arr)->size() ; findMaximumBefore(arr, n) ) else skip; operation findMaximumBefore(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( var currAns : int := -1 ; for j : Integer.subrange(-1 + 1, i - 1)->reverse() do ( if ((arr[j+1]->compareTo(currAns)) > 0 & (arr[j+1]->compareTo(arr[i+1])) < 0) then ( currAns := arr[j+1] ) else skip) ; execute (currAns)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as ma def find(a): count_odd=0 for i in a : if(i % 2!=0): count_odd+=1 result=pow(2,len(a))-1 result=result-(pow(2,count_odd)-1) print(result) a=[2,2,3] find(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; a := Sequence{2}->union(Sequence{2}->union(Sequence{ 3 })) ; find(a); operation find(a : OclAny) pre: true post: true activity: var count_odd : int := 0 ; for i : a do ( if (i mod 2 /= 0) then ( count_odd := count_odd + 1 ) else skip) ; var result : double := (2)->pow((a)->size()) - 1 ; result := result - ((2)->pow(count_odd) - 1) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t,s,q=map(int,input().split()) count=0 while scollect( _x | (OclType["int"])->apply(_x) ) ; var count : int := 0 ; while (s->compareTo(t)) < 0 do ( s := s * q ; count := count + 1) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def doMatch(A,B): for i in range(len(A)): if A[i]!='*' and B[i]!='*' : if A[i]!=B[i]: return False return True if __name__=='__main__' : A="gee*sforgeeks" B="geeksforgeeks" print(int(doMatch(A,B))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( A := "gee*sforgeeks" ; B := "geeksforgeeks" ; execute (("" + ((doMatch(A, B))))->toInteger())->display() ) else skip; operation doMatch(A : OclAny, B : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, (A)->size()-1) do ( if A[i+1] /= '*' & B[i+1] /= '*' then ( if A[i+1] /= B[i+1] then ( return false ) else skip ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bonacciseries(n,m): a=[0 for i in range(m)] a[n-1]=1 a[n]=1 for i in range(n+1,m): a[i]=2*a[i-1]-a[i-n-1] for i in range(0,m): print(a[i],end=" ") if __name__=='__main__' : N,M=5,15 bonacciseries(N,M) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := Sequence{5,15} ; bonacciseries(N, M) ) else skip; operation bonacciseries(n : OclAny, m : OclAny) pre: true post: true activity: var a : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (0)) ; a[n - 1+1] := 1 ; a[n+1] := 1 ; for i : Integer.subrange(n + 1, m-1) do ( a[i+1] := 2 * a[i - 1+1] - a[i - n - 1+1]) ; for i : Integer.subrange(0, m-1) do ( execute (a[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bonacciseries(n,m): a=[0]*m a[n-1]=1 for i in range(n,m): for j in range(i-n,i): a[i]=a[i]+a[j] for i in range(0,m): print(a[i],end=" ") N=5 M=15 bonacciseries(N,M) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 5 ; var M : int := 15 ; bonacciseries(N, M); operation bonacciseries(n : OclAny, m : OclAny) pre: true post: true activity: var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; a[n - 1+1] := 1 ; for i : Integer.subrange(n, m-1) do ( for j : Integer.subrange(i - n, i-1) do ( a[i+1] := a[i+1] + a[j+1])) ; for i : Integer.subrange(0, m-1) do ( execute (a[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) table=list(map(int,input().split())) table.sort() def solve(table,n): positiveOdds=[e for e in table if e % 2==1 and e>=0] negativeOdds=[e for e in table if e % 2==1 and e<0] positiveEvens=[e for e in table if e % 2==0 and e>=0] negativeEvens=[e for e in table if e % 2==0 and e<0] if len(positiveOdds)% 2==1 : out=sum(positiveEvens)+sum(positiveOdds) elif len(positiveOdds)>0 or len(negativeOdds)>0 : a=b=float("-inf") if len(positiveOdds): a=sum(positiveOdds[-1 : 0 :-1])+sum(positiveEvens) if len(negativeOdds): b=sum(positiveOdds)+sum(positiveEvens)+negativeOdds[-1] out=max(a,b) elif len(positiveOdds)==0 : out=sum(positiveEvens)+negativeOdds[-1] elif len(negativeOdds)==0 : out=sum(positiveEvens)+negativeOdds[-1] print(out) solve(table,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var table : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; table := table->sort() ; skip ; solve(table, n); operation solve(table : OclAny, n : OclAny) pre: true post: true activity: var positiveOdds : Sequence := table->select(e | e mod 2 = 1 & e >= 0)->collect(e | (e)) ; var negativeOdds : Sequence := table->select(e | e mod 2 = 1 & e < 0)->collect(e | (e)) ; var positiveEvens : Sequence := table->select(e | e mod 2 = 0 & e >= 0)->collect(e | (e)) ; var negativeEvens : Sequence := table->select(e | e mod 2 = 0 & e < 0)->collect(e | (e)) ; if (positiveOdds)->size() mod 2 = 1 then ( var out : OclAny := (positiveEvens)->sum() + (positiveOdds)->sum() ) else (if (positiveOdds)->size() > 0 or (negativeOdds)->size() > 0 then ( var a : OclAny := ("" + (("-inf")))->toReal(); var b : double := ("" + (("-inf")))->toReal() ; if (positiveOdds)->size() then ( a := (positiveOdds(subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))) : (test (logical_test (comparison (expr (atom (number (integer 0))))))) (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))->sum() + (positiveEvens)->sum() ) else skip ; if (negativeOdds)->size() then ( b := (positiveOdds)->sum() + (positiveEvens)->sum() + negativeOdds->last() ) else skip ; out := Set{a, b}->max() ) else (if (positiveOdds)->size() = 0 then ( out := (positiveEvens)->sum() + negativeOdds->last() ) else (if (negativeOdds)->size() = 0 then ( out := (positiveEvens)->sum() + negativeOdds->last() ) else skip ) ) ) ; execute (out)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys R=5 C=5 def findMaxCock(ar): if(R<3 or C<3): return-1 max_sum=-sys.maxsize-1 for i in range(R-2): for j in range(C-2): sum=((ar[i][j]+ar[i][j+2])+(ar[i+1][j+1])+(ar[i+2][j]+ar[i+2][j+1]+ar[i+2][j+2])) max_sum=max(max_sum,sum) return max_sum ; if __name__=='__main__' : ar=[[0,3,0,6,0],[0,1,1,0,0],[1,1,1,0,0],[0,0,2,0,1],[0,2,0,1,3]] print(findMaxCock(ar)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var R : int := 5 ; var C : int := 5 ; skip ; if __name__ = '__main__' then ( ar := Sequence{Sequence{0}->union(Sequence{3}->union(Sequence{0}->union(Sequence{6}->union(Sequence{ 0 }))))}->union(Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 0 }))))}->union(Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 0 }))))}->union(Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{2}->union(Sequence{0}->union(Sequence{ 1 }))))}->union(Sequence{ Sequence{0}->union(Sequence{2}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 3 })))) })))) ; execute (findMaxCock(ar))->display() ) else skip; operation findMaxCock(ar : OclAny) : OclAny pre: true post: true activity: if (R < 3 or C < 3) then ( return -1 ) else skip ; var max_sum : double := -(trailer . (name maxsize)) - 1 ; for i : Integer.subrange(0, R - 2-1) do ( for j : Integer.subrange(0, C - 2-1) do ( var sum : OclAny := ((ar[i+1][j+1] + ar[i+1][j + 2+1]) + (ar[i + 1+1][j + 1+1]) + (ar[i + 2+1][j+1] + ar[i + 2+1][j + 1+1] + ar[i + 2+1][j + 2+1])) ; max_sum := Set{max_sum, sum}->max())) ; return max_sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) seq=list(map(int,input().split())) pos=[] neg=[] posver=[] both=[] for x in seq : if x>=0 : pos.append(x) both.append(x) else : neg.append(x) both.append(0-x) possum=sum(pos) both.sort() if possum % 2==1 : print(possum) else : for x in both : if x % 2==1 : print(possum-x) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var seq : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var pos : Sequence := Sequence{} ; var neg : Sequence := Sequence{} ; var posver : Sequence := Sequence{} ; var both : Sequence := Sequence{} ; for x : seq do ( if x >= 0 then ( execute ((x) : pos) ; execute ((x) : both) ) else ( execute ((x) : neg) ; execute ((0 - x) : both) )) ; var possum : OclAny := (pos)->sum() ; both := both->sort() ; if possum mod 2 = 1 then ( execute (possum)->display() ) else ( for x : both do ( if x mod 2 = 1 then ( execute (possum - x)->display() ; break ) else skip) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) nums=[int(x)for x in input().split()] posi=[] nega=[] odd=[] sum=0 for x in nums : if x>=0 : posi.append(x) else : nega.append(x) sort=sorted(posi,reverse=True)+sorted(nega,reverse=True) ans=[] for x in range(len(sort)): sum+=sort[x] ans.append(sum) if sort[x]% 2==1 : odd.append(abs(sort[x])) if max(ans)<0 : print(0-min(odd)) elif max(ans)% 2==1 : print(max(ans)) else : print(max(ans)-min(odd)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nums : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var posi : Sequence := Sequence{} ; var nega : Sequence := Sequence{} ; var odd : Sequence := Sequence{} ; var sum : int := 0 ; for x : nums do ( if x >= 0 then ( execute ((x) : posi) ) else ( execute ((x) : nega) )) ; var sort : Sequence := posi->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True))))))))->union(nega->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True))))))))) ; var ans : Sequence := Sequence{} ; for x : Integer.subrange(0, (sort)->size()-1) do ( sum := sum + sort[x+1] ; execute ((sum) : ans) ; if sort[x+1] mod 2 = 1 then ( execute (((sort[x+1])->abs()) : odd) ) else skip) ; if (ans)->max() < 0 then ( execute (0 - (odd)->min())->display() ) else (if (ans)->max() mod 2 = 1 then ( execute ((ans)->max())->display() ) else ( execute ((ans)->max() - (odd)->min())->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) mas=list(map(int,input().split())) summ=0 maxx=-10**4-1 minn=10**4+1 for i in mas : if i>0 : summ+=i if i<0 and i % 2!=0 and i>maxx : maxx=i if i>0 and i % 2!=0 and itoInteger() ; var mas : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var summ : int := 0 ; var maxx : double := (-10)->pow(4) - 1 ; var minn : double := (10)->pow(4) + 1 ; for i : mas do ( if i > 0 then ( summ := summ + i ) else skip ; if i < 0 & i mod 2 /= 0 & (i->compareTo(maxx)) > 0 then ( maxx := i ) else skip ; if i > 0 & i mod 2 /= 0 & (i->compareTo(minn)) < 0 then ( minn := i ) else skip) ; if summ mod 2 = 0 then ( summ := summ - Set{minn, -maxx}->min() ) else skip ; execute (summ)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=3 m=4 def maxMatrixScore(A,K): update={} for i in range(0,n): if A[i][0]==0 : ans=0 for j in range(1,m): ans=ans+A[i][j]*2**(m-j-1) update[ans]=i for idx in update.values(): for j in range(0,m): A[idx][j]=(A[idx][j]+1)% 2 K-=1 if K<=0 : break ans=0 for j in range(0,m): zero,one=0,0 for i in range(0,n): if A[i][j]==0 : zero+=1 else : one+=1 if K>0 and zero>one : ans+=zero*2**(m-j-1) K-=1 else : ans+=one*2**(m-j-1) return ans if __name__=="__main__" : A=[[0,0,1,1],[1,0,1,0],[1,1,0,0]] K=2 print(maxMatrixScore(A,K)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := 3 ; var m : int := 4 ; skip ; if __name__ = "__main__" then ( A := Sequence{Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 1 })))}->union(Sequence{Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 0 })))}->union(Sequence{ Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ 0 }))) })) ; K := 2 ; execute (maxMatrixScore(A, K))->display() ) else skip; operation maxMatrixScore(A : OclAny, K : OclAny) : OclAny pre: true post: true activity: var update : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( if A[i+1]->first() = 0 then ( var ans : int := 0 ; for j : Integer.subrange(1, m-1) do ( ans := ans + A[i+1][j+1] * (2)->pow((m - j - 1))) ; update[ans+1] := i ) else skip) ; for idx : update.values() do ( for j : Integer.subrange(0, m-1) do ( A[idx+1][j+1] := (A[idx+1][j+1] + 1) mod 2) ; K := K - 1 ; if K <= 0 then ( break ) else skip) ; ans := 0 ; for j : Integer.subrange(0, m-1) do ( var zero : OclAny := null; var one : OclAny := null; Sequence{zero,one} := Sequence{0,0} ; for i : Integer.subrange(0, n-1) do ( if A[i+1][j+1] = 0 then ( zero := zero + 1 ) else ( one := one + 1 )) ; if K > 0 & (zero->compareTo(one)) > 0 then ( ans := ans + zero * (2)->pow((m - j - 1)) ; K := K - 1 ) else ( ans := ans + one * (2)->pow((m - j - 1)) )) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=list(map(int,input().split())) ave=round(sum(A)/N) ans=0 for a in A : ans+=(a-ave)**2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ave : double := ((A)->sum() / N)->round() ; var ans : int := 0 ; for a : A do ( ans := ans + ((a - ave))->pow(2)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t,s,q=map(int,input().split()) ans=0 while(scollect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; while ((s->compareTo(t)) < 0) do ( s := s * q ; ans := ans + 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math import numpy as np input=sys.stdin.readline N=int(input()) a=np.array(list(map(int,input().split()))) c=int(round(sum(a)/N)) print(sum((a-c)**2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var c : int := ("" + ((((a)->sum() / N)->round())))->toInteger() ; execute ((((a - c))->pow(2))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): N=int(input()) A=list(map(int,input().split())) ans=float('inf') for k in range(min(A),max(A)+1): cost=0 for a in A : cost+=(a-k)**2 ans=min(ans,cost) if ans==0 : break print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : double := ("" + (('inf')))->toReal() ; for k : Integer.subrange((A)->min(), (A)->max() + 1-1) do ( var cost : int := 0 ; for a : A do ( cost := cost + ((a - k))->pow(2)) ; ans := Set{ans, cost}->min() ; if ans = 0 then ( break ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) s=sum(l) a,b=s//n,-(-s//n) print(min(sum([(z-a)**2 for z in l]),sum([(x-b)**2 for x in l]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : OclAny := (l)->sum() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{s div n,-(-s div n)} ; execute (Set{(l->select(z | true)->collect(z | (((z - a))->pow(2))))->sum(), (l->select(x | true)->collect(x | (((x - b))->pow(2))))->sum()}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math N=int(input()) A=list(map(int,input().split())) if all(a==A[0]for a in A): print(0) sys.exit() cm=math.ceil(sum(A)/len(A)) fm=math.floor(sum(A)/len(A)) kouho1,kouho2=0,0 for a in A : kouho1+=(a-cm)**2 kouho2+=(a-fm)**2 print(min(kouho1,kouho2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if ((argument (test (logical_test (comparison (comparison (expr (atom (name a)))) == (comparison (expr (atom (name A)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))) (comp_for for (exprlist (expr (atom (name a)))) in (logical_test (comparison (expr (atom (name A))))))))->forAll( _x | _x = true ) then ( execute (0)->display() ; sys.exit() ) else skip ; var cm : double := ((A)->sum() / (A)->size())->ceil() ; var fm : double := ((A)->sum() / (A)->size())->floor() ; var kouho1 : OclAny := null; var kouho2 : OclAny := null; Sequence{kouho1,kouho2} := Sequence{0,0} ; for a : A do ( kouho1 := kouho1 + ((a - cm))->pow(2) ; kouho2 := kouho2 + ((a - fm))->pow(2)) ; execute (Set{kouho1, kouho2}->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=10 def getMaxEven(string,length): string=list(string) freq=[0]*MAX minEvenDigit=MAX ; minDigit=MAX ; for i in range(length): digit=ord(string[i])-ord('0'); freq[digit]+=1 ; if(digit % 2==0): minEvenDigit=min(digit,minEvenDigit); minDigit=min(digit,minDigit); if(minEvenDigit==MAX): return "-1" ; freq[minEvenDigit]-=1 ; freq[minDigit]-=1 ; i=0 ; for j in range(MAX-1,-1,-1): for k in range(freq[j]): string[i]=chr(j+ord('0')); i+=1 if(j==minEvenDigit): string[i]=chr(minDigit+ord('0')); i+=1 return "".join(string); if __name__=="__main__" : string="1023422" ; length=len(string); print(getMaxEven(string,length)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 10 ; skip ; if __name__ = "__main__" then ( string := "1023422"; ; length := (string)->size(); ; execute (getMaxEven(string, length))->display(); ) else skip; operation getMaxEven(string : OclAny, length : OclAny) pre: true post: true activity: string := (string)->characters() ; var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX) ; var minEvenDigit : int := MAX; ; var minDigit : int := MAX; ; for i : Integer.subrange(0, length-1) do ( var digit : double := (string[i+1])->char2byte() - ('0')->char2byte(); ; freq[digit+1] := freq[digit+1] + 1; ; if (digit mod 2 = 0) then ( minEvenDigit := Set{digit, minEvenDigit}->min(); ) else skip ; minDigit := Set{digit, minDigit}->min();) ; if (minEvenDigit = MAX) then ( return "-1"; ) else skip ; freq[minEvenDigit+1] := freq[minEvenDigit+1] - 1; ; freq[minDigit+1] := freq[minDigit+1] - 1; ; var i : int := 0; ; for j : Integer.subrange(-1 + 1, MAX - 1)->reverse() do ( for k : Integer.subrange(0, freq[j+1]-1) do ( string[i+1] := (j + ('0')->char2byte())->byte2char(); ; i := i + 1) ; if (j = minEvenDigit) then ( string[i+1] := (minDigit + ('0')->char2byte())->byte2char(); ; i := i + 1 ) else skip) ; return StringLib.sumStringsWithSeparator((string), "");; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printArray(X,d,first_ele): while(X>0): count_ele,pow_of_two=0,2 while(X-pow_of_two+1>=0): count_ele+=1 pow_of_two*=2 X=X-(pow_of_two/2)+1 for j in range(count_ele): print(first_ele,end=" ") first_ele+=d if __name__=='__main__' : d,X=100,25 printArray(X,d,1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( Sequence{d,X} := Sequence{100,25} ; printArray(X, d, 1) ) else skip; operation printArray(X : OclAny, d : OclAny, first_ele : OclAny) pre: true post: true activity: while (X > 0) do ( var count_ele : OclAny := null; var pow_of_two : OclAny := null; Sequence{count_ele,pow_of_two} := Sequence{0,2} ; while (X - pow_of_two + 1 >= 0) do ( count_ele := count_ele + 1 ; pow_of_two := pow_of_two * 2) ; X := X - (pow_of_two / 2) + 1 ; for j : Integer.subrange(0, count_ele-1) do ( execute (first_ele)->display()) ; first_ele := first_ele + d); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def count_of_ways(n): count=0 count=(n+1)*(n+2)//2 return count n=3 print(count_of_ways(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 3 ; execute (count_of_ways(n))->display(); operation count_of_ways(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; count := (n + 1) * (n + 2) div 2 ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOdd(n): terms=(n+1)//2 sum1=terms*terms return sum1 def suminRange(l,r): return sumOdd(r)-sumOdd(l-1) l=2 ; r=5 print("Sum of odd natural number","from L to R is",suminRange(l,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; l := 2; r := 5 ; execute ("Sum of odd natural number")->display(); operation sumOdd(n : OclAny) : OclAny pre: true post: true activity: var terms : int := (n + 1) div 2 ; var sum1 : int := terms * terms ; return sum1; operation suminRange(l : OclAny, r : OclAny) : OclAny pre: true post: true activity: return sumOdd(r) - sumOdd(l - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def __gcd(a,b): if(b==0): return a else : return __gcd(b,a % b) def power(x,y,m): if(y==0): return 1 p=power(x,y//2,m)% m p=(p*p)% m return p if(y % 2==0)else(x*p)% m def modInverse(a,m): if(__gcd(a,m)!=1): print("Inverse doesn't exist") else : print("Modular multiplicative inverse is ",power(a,m-2,m)) a=3 m=11 modInverse(a,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; a := 3 ; m := 11 ; modInverse(a, m); operation __gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (b = 0) then ( return a ) else ( return __gcd(b, a mod b) ); operation power(x : OclAny, y : OclAny, m : OclAny) : OclAny pre: true post: true activity: if (y = 0) then ( return 1 ) else skip ; var p : int := power(x, y div 2, m) mod m ; p := (p * p) mod m ; return if (y mod 2 = 0) then p else (x * p) mod m endif; operation modInverse(a : OclAny, m : OclAny) pre: true post: true activity: if (__gcd(a, m) /= 1) then ( execute ("Inverse doesn't exist")->display() ) else ( execute ("Modular multiplicative inverse is ")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Count_subarray(arr,n): total_sum=0 ; count=0 ; for i in range(n): total_sum+=arr[i]; for i in range(n): subarray_sum=0 ; for j in range(i,n): subarray_sum+=arr[j]; remaining_sum=total_sum-subarray_sum ; if(subarray_sum>remaining_sum): count+=1 ; return count ; if __name__=="__main__" : arr=[10,9,12,6]; n=len(arr); print(Count_subarray(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{10}->union(Sequence{9}->union(Sequence{12}->union(Sequence{ 6 }))); ; n := (arr)->size(); ; execute (Count_subarray(arr, n))->display(); ) else skip; operation Count_subarray(arr : OclAny, n : OclAny) pre: true post: true activity: var total_sum : int := 0; ; var count : int := 0; ; for i : Integer.subrange(0, n-1) do ( total_sum := total_sum + arr[i+1];) ; for i : Integer.subrange(0, n-1) do ( var subarray_sum : int := 0; ; for j : Integer.subrange(i, n-1) do ( subarray_sum := subarray_sum + arr[j+1]; ; var remaining_sum : double := total_sum - subarray_sum; ; if ((subarray_sum->compareTo(remaining_sum)) > 0) then ( count := count + 1; ) else skip)) ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) print((a-2)**2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute (((a - 2))->pow(2))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(): table=list() n,m=map(int,sys.stdin.readline().split()) columns=list(map(int,input().split())) for i in range(n): table.append(0) for i in range(m): colum=columns[i] table[colum-1]+=1 print(min(table)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var table : Sequence := () ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var columns : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( execute ((0) : table)) ; for i : Integer.subrange(0, m-1) do ( var colum : OclAny := columns[i+1] ; table[colum - 1+1] := table[colum - 1+1] + 1) ; execute ((table)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) n=list(map(int,input().split())) res=1000 for sq in range(1,a+1): res=min(res,n.count(sq)) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var n : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : int := 1000 ; for sq : Integer.subrange(1, a + 1-1) do ( res := Set{res, n->count(sq)}->min()) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def entrada(): entrada=input() ENTRADALIST=entrada.split(" ") n=int(ENTRADALIST[0]) m=int(ENTRADALIST[1]) return n,m def CreateBoard(): BOARD=[] for i in range(n): BOARD.append(0) return BOARD def AddSquares(TAB): squares=input() SQUARELIST=squares.split(" ") for i in SQUARELIST : key=int(i) TAB[key-1]=TAB[key-1]+1 return TAB def SquareScore(TAB): score=0 while min(TAB)>0 : score+=1 for i in range(len(TAB)): TAB[i]=TAB[i]-1 else : return score n,m=entrada() tabuleiro=CreateBoard() tabuleiro=AddSquares(tabuleiro) pontuacao=SquareScore(tabuleiro) print(pontuacao) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; Sequence{n,m} := entrada() ; var tabuleiro : OclAny := CreateBoard() ; tabuleiro := AddSquares(tabuleiro) ; var pontuacao : OclAny := SquareScore(tabuleiro) ; execute (pontuacao)->display(); operation entrada() : OclAny pre: true post: true activity: var entrada : String := (OclFile["System.in"]).readLine() ; var ENTRADALIST : OclAny := entrada.split(" ") ; var n : int := ("" + ((ENTRADALIST->first())))->toInteger() ; var m : int := ("" + ((ENTRADALIST[1+1])))->toInteger() ; return n, m; operation CreateBoard() : OclAny pre: true post: true activity: var BOARD : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((0) : BOARD)) ; return BOARD; operation AddSquares(TAB : OclAny) : OclAny pre: true post: true activity: var squares : String := (OclFile["System.in"]).readLine() ; var SQUARELIST : OclAny := squares.split(" ") ; for i : SQUARELIST do ( var key : int := ("" + ((i)))->toInteger() ; TAB[key - 1+1] := TAB[key - 1+1] + 1) ; return TAB; operation SquareScore(TAB : OclAny) pre: true post: true activity: var score : int := 0 ; (compound_stmt while (test (logical_test (comparison (comparison (expr (atom (name min)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name TAB)))))))) ))))) > (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name score)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name TAB)))))))) ))))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name TAB)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name TAB)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))) - (expr (atom (number (integer 1)))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name score))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) squares=map(int,input().split()) platform=[0 for col in range(n)] points=[0 for col in range(n)] for i in squares : points[i-1]+=1 print(min(points)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var squares : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var platform : Sequence := Integer.subrange(0, n-1)->select(col | true)->collect(col | (0)) ; var points : Sequence := Integer.subrange(0, n-1)->select(col | true)->collect(col | (0)) ; for i : squares do ( points[i - 1+1] := points[i - 1+1] + 1) ; execute ((points)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) n,m=R() a=[0]*n for c in R(): a[c-1]+=1 print(min(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := R->apply() ; var a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for c : R->apply() do ( a[c - 1+1] := a[c - 1+1] + 1) ; execute ((a)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNumbers(s): n=len(s) count=1 result=0 left=0 right=1 while(rightsize() ; var count : int := 1 ; var result : int := 0 ; var left : int := 0 ; var right : int := 1 ; while ((right->compareTo(n)) < 0) do ( if (s[left+1] = s[right+1]) then ( count := count + 1 ) else ( result := result + count * (count + 1) div 2 ; left := right ; count := 1 ) ; right := right + 1) ; result := result + count * (count + 1) div 2 ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) s=input() i=0 last=False for i in range(n): if s[i]!="?" : last=(s[i]=="B")!=bool(i % 2) break result="" for i in s : if i=="?" : result+="B" if last else "R" last=not last else : result+=i last=(i=="R") print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var i : int := 0 ; var last : boolean := false ; for i : Integer.subrange(0, n-1) do ( if s[i+1] /= "?" then ( last := (s[i+1] = "B") /= (i mod 2)->toBoolean() ; break ) else skip) ; var result : String := "" ; for i : s->characters() do ( if i = "?" then ( result := result + if last then "B" else "R" endif ; last := not(last) ) else ( result := result + i ; last := (i = "R") )) ; execute (result)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def productSumDivisible(n,size): sum=0 product=1 while(n>0): if(size % 2==0): product*=n % 10 else : sum+=n % 10 n=n//10 size-=1 if(product % sum==0): return True return False if __name__=="__main__" : n=1234 len=4 if(productSumDivisible(n,len)): print("TRUE") else : print("FALSE") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 1234 ; var len : int := 4 ; if (productSumDivisible(n, len)) then ( execute ("TRUE")->display() ) else ( execute ("FALSE")->display() ) ) else skip; operation productSumDivisible(n : OclAny, size : OclAny) : OclAny pre: true post: true activity: var sum : int := 0 ; var product : int := 1 ; while (n > 0) do ( if (size mod 2 = 0) then ( product := product * n mod 10 ) else ( sum := sum + n mod 10 ) ; n := n div 10 ; size := size - 1) ; if (product mod sum = 0) then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=10 def findSubarray(array,n): mp=dict() mp[0]=1 answer=0 preXor=0 for i in range(n): value=1 preXor ^=array[i] for j in range(1,MAX+1): Y=value ^ preXor if(Y in mp.keys()): answer+=mp[Y] value*=2 if(preXor in mp.keys()): mp[preXor]+=1 else : mp[preXor]=1 return answer array=[2,6,7,5,8] n=len(array) print(findSubarray(array,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 10 ; skip ; array := Sequence{2}->union(Sequence{6}->union(Sequence{7}->union(Sequence{5}->union(Sequence{ 8 })))) ; n := (array)->size() ; execute (findSubarray(array, n))->display(); operation findSubarray(array : OclAny, n : OclAny) : OclAny pre: true post: true activity: var mp : Map := (arguments ( )) ; mp->first() := 1 ; var answer : int := 0 ; var preXor : int := 0 ; for i : Integer.subrange(0, n-1) do ( var value : int := 1 ; preXor := preXor xor array[i+1] ; for j : Integer.subrange(1, MAX + 1-1) do ( var Y : int := MathLib.bitwiseXor(value, preXor) ; if ((mp.keys())->includes(Y)) then ( answer := answer + mp[Y+1] ) else skip ; value := value * 2) ; if ((mp.keys())->includes(preXor)) then ( mp[preXor+1] := mp[preXor+1] + 1 ) else ( mp[preXor+1] := 1 )) ; return answer; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=eval(input()) cnt=0 lt=0 mn=0 for i in range(n): t,c=input().split() t,c=int(t),int(c) cnt-=t-lt lt=t if cnt<0 : cnt=0 cnt+=c if cnt>mn : mn=cnt print(cnt+t,mn) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := (OclFile["System.in"]).readLine() ; var cnt : int := 0 ; var lt : int := 0 ; var mn : int := 0 ; for i : Integer.subrange(0, n-1) do ( var t : OclAny := null; var c : OclAny := null; Sequence{t,c} := input().split() ; var t : OclAny := null; var c : OclAny := null; Sequence{t,c} := Sequence{("" + ((t)))->toInteger(),("" + ((c)))->toInteger()} ; cnt := cnt - t - lt ; lt := t ; if cnt < 0 then ( cnt := 0 ) else skip ; cnt := cnt + c ; if (cnt->compareTo(mn)) > 0 then ( mn := cnt ) else skip) ; execute (cnt + t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline print((int(input())-2)**2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; execute (((("" + (((OclFile["System.in"]).readLine())))->toInteger() - 2))->pow(2))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[] for i in range(n): c,t=map(int,input().split()) l.append((c,t)) queue=l[0][1] z=queue for i in range(1,n): queue=queue-min((l[i][0]-l[i-1][0]),queue) queue=queue+l[i][1] z=max(z,queue) print(l[-1][0]+queue,z) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var c : OclAny := null; var t : OclAny := null; Sequence{c,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{c, t}) : l)) ; var queue : OclAny := l->first()[1+1] ; var z : OclAny := queue ; for i : Integer.subrange(1, n-1) do ( queue := queue - Set{(l[i+1]->first() - l[i - 1+1]->first()), queue}->min() ; queue := queue + l[i+1][1+1] ; z := Set{z, queue}->max()) ; execute (l->last()->first() + queue)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=[] for _ in range(n): arr.append([int(i)for i in input().split()]) arr.sort(key=lambda x : x[0]) queue_size=0 time=0 max_queue_size=0 last_time=0 for t,c in arr : sent=t-last_time queue_size=max(0,queue_size-sent) queue_size+=c time=t max_queue_size=max(max_queue_size,queue_size) last_time=time print(time+queue_size,max_queue_size) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger()))) : arr)) ; arr := arr->sort() ; var queue_size : int := 0 ; var time : int := 0 ; var max_queue_size : int := 0 ; var last_time : int := 0 ; for _tuple : arr do (var _indx : int := 1; var t : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); var sent : double := t - last_time ; queue_size := Set{0, queue_size - sent}->max() ; queue_size := queue_size + c ; time := t ; max_queue_size := Set{max_queue_size, queue_size}->max() ; last_time := time) ; execute (time + queue_size)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- i=int(input()) t=q=m=0 for x in range(i): a,b=map(int,input().split()) q-=a-t if q<0 : q=0 q+=b if q>m : m=q t=a t+=q print(t,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var i : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; t := t(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name q)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name m)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))) ; for x : Integer.subrange(0, i-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; q := q - a - t ; if q < 0 then ( var q : int := 0 ) else skip ; q := q + b ; if (q->compareTo(m)) > 0 then ( var m : int := q ) else skip ; var t : OclAny := a) ; t := t + q ; execute (t)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from decimal import* import math import sys rasp_final="" def transformare_baza(numar,baza): transformare="" while numar>=baza : rest=numar % baza numar=numar//baza transformare+=str(rest) transformare+=str(numar) noua_baza=transformare[: :-1] return noua_baza c=int(input()) for z in range(0,c): a,b=list(map(int,input().split())) if z==0 : timp=a maximul_timp=a+b cate_maxim=b ramase=b if z>0 : ramase=max(0,ramase-(a-timp)) ramase=ramase+b timp=a maximul_timp=max(a+ramase,maximul_timp) cate_maxim=max(ramase,cate_maxim) print(maximul_timp,cate_maxim) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var rasp_final : String := "" ; skip ; var c : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for z : Integer.subrange(0, c-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; if z = 0 then ( var timp : OclAny := a ; var maximul_timp : OclAny := a + b ; var cate_maxim : OclAny := b ; var ramase : OclAny := b ) else skip ; if z > 0 then ( ramase := Set{0, ramase - (a - timp)}->max() ; ramase := ramase + b ; timp := a ; maximul_timp := Set{a + ramase, maximul_timp}->max() ; cate_maxim := Set{ramase, cate_maxim}->max() ) else skip) ; execute (maximul_timp)->display(); operation transformare_baza(numar : OclAny, baza : OclAny) : OclAny pre: true post: true activity: var transformare : String := "" ; while (numar->compareTo(baza)) >= 0 do ( var rest : int := numar mod baza ; numar := numar div baza ; transformare := transformare + ("" + ((rest)))) ; transformare := transformare + ("" + ((numar))) ; var noua_baza : OclAny := transformare(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; return noua_baza; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin import sys import math from functools import reduce import functools import itertools from collections import deque,Counter,defaultdict from operator import mul import copy import heapq sys.setrecursionlimit(10**6) INF=float("inf") import bisect s=input() n=len(s) if s[n-1]=="1" or s[0]=="0" : print(-1) sys.exit() for i in range((n-1)//2): if s[i]!=s[n-2-i]: print(-1) sys.exit() j=0 for i in range(1,n): if s[i]=="1" : for k in range(j,i): print(k+1,i+1) j=i for k in range(j+1,n): print(j+1,k+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(6)) ; var INF : double := ("" + (("inf")))->toReal() ; skip ; var s : String := (OclFile["System.in"]).readLine() ; var n : int := (s)->size() ; if s[n - 1+1] = "1" or s->first() = "0" then ( execute (-1)->display() ; sys.exit() ) else skip ; for i : Integer.subrange(0, (n - 1) div 2-1) do ( if s[i+1] /= s[n - 2 - i+1] then ( execute (-1)->display() ; sys.exit() ) else skip) ; var j : int := 0 ; for i : Integer.subrange(1, n-1) do ( if s[i+1] = "1" then ( for k : Integer.subrange(j, i-1) do ( execute (k + 1)->display()) ; j := i ) else skip) ; for k : Integer.subrange(j + 1, n-1) do ( execute (j + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline S='-'+input().rstrip() N=len(S)-1 def solve(S): if S[1]=='0' : print(-1) exit() if S[N]=='1' : print(-1) exit() prev=1 graph=[] for n in range(1,N//2+1): if S[n]!=S[N-n]: return None if S[n]=='0' : continue for i in range(prev,n): graph.append('{}{}'.format(i,n)) prev=n for i in range(prev,N): graph.append('{}{}'.format(i,N)) return graph graph=solve(S) if graph is None : print(-1) else : print('\n'.join(graph)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var S : String := '-' + input().rstrip() ; var N : double := (S)->size() - 1 ; skip ; graph := solve(S) ; if graph <>= null then ( execute (-1)->display() ) else ( execute (StringLib.sumStringsWithSeparator((graph), ' '))->display() ); operation solve(S : OclAny) : OclAny pre: true post: true activity: if S[1+1] = '0' then ( execute (-1)->display() ; exit() ) else skip ; if S[N+1] = '1' then ( execute (-1)->display() ; exit() ) else skip ; var prev : int := 1 ; var graph : Sequence := Sequence{} ; for n : Integer.subrange(1, N div 2 + 1-1) do ( if S[n+1] /= S[N - n+1] then ( return null ) else skip ; if S[n+1] = '0' then ( continue ) else skip ; for i : Integer.subrange(prev, n-1) do ( execute ((StringLib.interpolateStrings('{}{}', Sequence{i, n})) : graph)) ; prev := n) ; for i : Integer.subrange(prev, N-1) do ( execute ((StringLib.interpolateStrings('{}{}', Sequence{i, N})) : graph)) ; return graph; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() n=len(s) s2=s[: n-1] if s[0]!='1' or s[-1]!='0' or(s2[: :-1]!=s2): print("-1") exit(0) ans="{0}{1}" par=n for i in range(n-2,-1,-1): print(ans.format(par,i+1)) if s[i]=='1' : par=(i+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var n : int := (s)->size() ; var s2 : OclAny := s.subrange(1,n - 1) ; if s->first() /= '1' or s->last() /= '0' or (s2(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) /= s2) then ( execute ("-1")->display() ; exit(0) ) else skip ; var ans : String := "{0}{1}" ; var par : int := n ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( execute (StringLib.interpolateStrings(ans, Sequence{par, i + 1}))->display() ; if s[i+1] = '1' then ( par := (i + 1) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) int1=lambda x : int(x)-1 p2D=lambda x : print(*x,sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int,sys.stdin.readline().split()) def LI(): return list(map(int,sys.stdin.readline().split())) def LLI(rows_number): return[LI()for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] def ng(): if s[0]=="0" or s[-1]=="1" : return True for i in range(n): if i>n-2-i : break if s[i]!=s[n-2-i]: return True return False s=SI() n=len(s) if ng(): print(-1) exit() aa=[] for i in range(n//2): if s[i]=="1" : aa.append(i+1) aa.append(n) ans=[] for i in range(len(aa)-1): ans.append([i+1,i+2]) j=len(aa)+1 for i,(a0,a1)in enumerate(zip(aa,aa[1 :])): for _ in range(a1-a0-1): ans.append([i+2,j]) j+=1 for u,v in ans : print(u,v) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; var int1 : Function := lambda x : OclAny in (("" + ((x)))->toInteger() - 1) ; var p2D : Function := lambda x : OclAny in (((argument * (test (logical_test (comparison (expr (atom (name x))))))))->display()) ; skip ; skip ; skip ; skip ; skip ; skip ; var s : OclAny := SI() ; var n : int := (s)->size() ; if ng() then ( execute (-1)->display() ; exit() ) else skip ; var aa : Sequence := Sequence{} ; for i : Integer.subrange(0, n div 2-1) do ( if s[i+1] = "1" then ( execute ((i + 1) : aa) ) else skip) ; execute ((n) : aa) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(0, (aa)->size() - 1-1) do ( execute ((Sequence{i + 1}->union(Sequence{ i + 2 })) : ans)) ; var j : int := (aa)->size() + 1 ; for _tuple : Integer.subrange(1, (Integer.subrange(1, aa->size())->collect( _indx | Sequence{aa->at(_indx), aa->tail()->at(_indx)} ))->size())->collect( _indx | Sequence{_indx-1, (Integer.subrange(1, aa->size())->collect( _indx | Sequence{aa->at(_indx), aa->tail()->at(_indx)} ))->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var Sequence{a0, a1} : OclAny := _tuple->at(_indx); for _anon : Integer.subrange(0, a1 - a0 - 1-1) do ( execute ((Sequence{i + 2}->union(Sequence{ j })) : ans) ; j := j + 1)) ; for _tuple : ans do (var _indx : int := 1; var u : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); execute (u)->display()); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation LLI(rows_number : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, rows_number-1)->select(_anon | true)->collect(_anon | (LI())); operation SI() : OclAny pre: true post: true activity: return sys.stdin.readLine()->front(); operation ng() : OclAny pre: true post: true activity: if s->first() = "0" or s->last() = "1" then ( return true ) else skip ; for i : Integer.subrange(0, n-1) do ( if (i->compareTo(n - 2 - i)) > 0 then ( break ) else skip ; if s[i+1] /= s[n - 2 - i+1] then ( return true ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import permutations def main(): rows=[] for _ in range(5): rows.append(list(map(int,input().split(' ')))) max_val=0 for perms in permutations([0,1,2,3,4]): g12=rows[perms[0]][perms[1]] g21=rows[perms[1]][perms[0]] g23=rows[perms[1]][perms[2]] g32=rows[perms[2]][perms[1]] g34=rows[perms[2]][perms[3]] g43=rows[perms[3]][perms[2]] g45=rows[perms[3]][perms[4]] g54=rows[perms[4]][perms[3]] val=g12+g21+g23+g32+2*(g34+g43)+2*(g45+g54) if val>max_val : max_val=val print(max_val) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var rows : Sequence := Sequence{} ; for _anon : Integer.subrange(0, 5-1) do ( execute ((((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ))) : rows)) ; var max_val : int := 0 ; for perms : permutations(Sequence{0}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))))) do ( var g12 : OclAny := rows[perms->first()+1][perms[1+1]+1] ; var g21 : OclAny := rows[perms[1+1]+1][perms->first()+1] ; var g23 : OclAny := rows[perms[1+1]+1][perms[2+1]+1] ; var g32 : OclAny := rows[perms[2+1]+1][perms[1+1]+1] ; var g34 : OclAny := rows[perms[2+1]+1][perms[3+1]+1] ; var g43 : OclAny := rows[perms[3+1]+1][perms[2+1]+1] ; var g45 : OclAny := rows[perms[3+1]+1][perms[4+1]+1] ; var g54 : OclAny := rows[perms[4+1]+1][perms[3+1]+1] ; var val : OclAny := g12 + g21 + g23 + g32 + 2 * (g34 + g43) + 2 * (g45 + g54) ; if (val->compareTo(max_val)) > 0 then ( max_val := val ) else skip) ; execute (max_val)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(s): n=len(s) if s[-1]=='1' or s[-2]=='0' or s[0]=='0' : print(-1) return i,j=0,n-2 while isize() ; if s->last() = '1' or s->front()->last() = '0' or s->first() = '0' then ( execute (-1)->display() ; return ) else skip ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,n - 2} ; while (i->compareTo(j)) < 0 do ( if s[i+1] /= s[j+1] then ( execute (-1)->display() ; return ) else skip ; i := i + 1 ; j := j - 1) ; var e : Sequence := Sequence{} ; var k : int := 0 ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if c = '1' then ( if i = 0 then ( k := 0 ; continue ) else skip ; for j : Integer.subrange(0, k + 1-1) do ( execute ((Sequence{i - k + j, i + 1}) : e)) ; k := 0 ) else ( k := k + 1 )) ; execute ((Sequence{n - k, n}) : e) ; for _tuple : e do (var _indx : int := 1; var u : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); execute (u)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) sum=1 if n==3 : print(1) else : for i in range(1,n-2): sum+=(2*i+1) print(sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var sum : int := 1 ; if n = 3 then ( execute (1)->display() ) else ( for i : Integer.subrange(1, n - 2-1) do ( sum := sum + (2 * i + 1)) ; execute (sum)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printRLE(s): i=0 while(icompareTo((s)->size() - 1)) < 0) do ( var count : int := 1 ; while s[i+1] = s[i + 1+1] do ( i := i + 1 ; count := count + 1 ; if i + 1 = (s)->size() then ( break ) else skip) ; execute (("" + ((s[i+1]))) + ("" + ((count))))->display() ; i := i + 1) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,lst): if lst[n-1]==1 : return 1 sum=lst[n-1] for i in range(n-2,-1,-1): if lst[i]toInteger() ; lst := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute (solve(n, lst))->display(); operation solve(n : OclAny, lst : OclAny) : OclAny pre: true post: true activity: if lst[n - 1+1] = 1 then ( return 1 ) else skip ; var sum : OclAny := lst[n - 1+1] ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( if (lst[i+1]->compareTo(lst[i + 1+1])) < 0 then ( if lst[i+1] = 1 then ( sum := sum + lst[i+1] ; return sum ) else ( sum := sum + lst[i+1] ) ) else ( sum := sum + (lst[i + 1+1] - 1) ; lst[i+1] := (lst[i + 1+1] - 1) ; if lst[i+1] = 1 then ( return sum ) else skip )) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) res=0 cur=99999999999999 for i in range(n-1,-1,-1): t=min(cur-1,arr[i]) if t==0 : break res+=t cur=t print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var res : int := 0 ; var cur : int := 99999999999999 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( var t : OclAny := Set{cur - 1, arr[i+1]}->min() ; if t = 0 then ( break ) else skip ; res := res + t ; cur := t) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[int(i)for i in input().strip().split()] ans=0 curr_max=float('inf') for i in range(n-1,-1,-1): if curr_max==0 : curr_max=0 elif curr_max<=a[i]: curr_max-=1 else : curr_max=a[i] ans+=curr_max print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := input()->trim().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var ans : int := 0 ; var curr_max : double := ("" + (('inf')))->toReal() ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( if curr_max = 0 then ( curr_max := 0 ) else (if (curr_max->compareTo(a[i+1])) <= 0 then ( curr_max := curr_max - 1 ) else ( curr_max := a[i+1] ) ) ; ans := ans + curr_max) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[int(i)for i in input().split()] l=l[: :-1] b=[l[0]] for i in range(1,len(l)): if(b[i-1]==0): b.append(0) elif(b[i-1]0): b.append(b[i-1]-1) else : b.append(0) else : b.append(l[i]) print(sum(b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; l := l(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var b : Sequence := Sequence{ l->first() } ; for i : Integer.subrange(1, (l)->size()-1) do ( if (b[i - 1+1] = 0) then ( execute ((0) : b) ) else (if ((b[i - 1+1]->compareTo(l[i+1])) < 0) then ( execute ((b[i - 1+1] - 1) : b) ) else (if (b[i - 1+1] = l[i+1]) then ( if (b[i - 1+1] > 0) then ( execute ((b[i - 1+1] - 1) : b) ) else ( execute ((0) : b) ) ) else ( execute ((l[i+1]) : b) ) ) ) ) ; execute ((b)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) arr=list(map(int,input().split())) need=float('inf') ans=0 for i in range(n-1,-1,-1): n=arr[i] if need==0 : break if n>need : ans+=need need-=1 else : ans+=n need=n-1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var need : double := ("" + (('inf')))->toReal() ; var ans : int := 0 ; for i : Integer.subrange(-1 + 1, n - 1)->reverse() do ( n := arr[i+1] ; if need = 0 then ( break ) else skip ; if (n->compareTo(need)) > 0 then ( ans := ans + need ; need := need - 1 ) else ( ans := ans + n ; need := n - 1 )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,D=map(int,input().split()) counter=0 for _ in range(N): x,y=map(int,input().split()) d=(x**2+y**2)**(1/2) if d<=D : counter+=1 print(counter) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var D : OclAny := null; Sequence{N,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var counter : int := 0 ; for _anon : Integer.subrange(0, N-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : double := (((x)->pow(2) + (y)->pow(2)))->pow((1 / 2)) ; if (d->compareTo(D)) <= 0 then ( counter := counter + 1 ) else skip) ; execute (counter)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement from collections import deque,defaultdict,Counter from bisect import bisect_left,bisect_right from operator import itemgetter from heapq import heapify,heappop,heappush from queue import Queue,LifoQueue,PriorityQueue from copy import deepcopy from time import time from functools import reduce import string import sys sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(): return list(MAP()) n,d=MAP() ans=0 for i in range(n): x,y=MAP() if x**2+y**2<=d**2 : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(7)) ; skip ; skip ; skip ; skip ; var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := MAP() ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := MAP() ; if ((x)->pow(2) + (y)->pow(2)->compareTo((d)->pow(2))) <= 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST() : OclAny pre: true post: true activity: return (MAP()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _INPUT="""\ 4 5 0 5 -2 4 3 4 4-4 """ def main(): N,D=map(int,input().split()) xy=[list(map(int,input().split()))for i in range(N)] answer=[] for j in range(len(xy)): distance=math.sqrt((xy[j][0]**2+xy[j][1]**2)) if D>=distance : answer.append(distance) print(len(answer)) if __name__=='__main__' : import io import sys import math main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _INPUT : String := (atom "" "\\r\n4 5\r\n0 5\r\n-2 4\r\n3 4\r\n4-4\r\n" "") ; skip ; if __name__ = '__main__' then ( skip ; skip ; skip ; main() ) else skip; operation main() pre: true post: true activity: var N : OclAny := null; var D : OclAny := null; Sequence{N,D} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var xy : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var answer : Sequence := Sequence{} ; for j : Integer.subrange(0, (xy)->size()-1) do ( var distance : double := (((xy[j+1]->first())->pow(2) + (xy[j+1][1+1])->pow(2)))->sqrt() ; if (D->compareTo(distance)) >= 0 then ( execute ((distance) : answer) ) else skip) ; execute ((answer)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_permutations(set): if len(set)==2 : return[set,[set[1],set[0]]] elif len(set)<2 : return set perms=[] prev=get_permutations(set[1 :]) for i in range(len(set)): for perm in prev : perms.append(perm[: i]+[set[0]]+perm[i :]) return perms def evaluate(p,mat): value=mat[p[0]][p[1]]+mat[p[1]][p[0]]+mat[p[2]][p[3]]+mat[p[3]][p[2]] value+=mat[p[1]][p[2]]+mat[p[2]][p[1]]+mat[p[3]][p[4]]+mat[p[4]][p[3]] value+=mat[p[2]][p[3]]+mat[p[3]][p[2]] value+=mat[p[3]][p[4]]+mat[p[4]][p[3]] return value def main(): matrix=[] for i in range(5): matrix.append(list(map(int,input().split()))) result=0 perms=get_permutations([0,1,2,3,4]) for perm in perms : value=evaluate(perm,matrix) result=result if result>=value else value print(result) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; main(); operation get_permutations(set : OclAny) : OclAny pre: true post: true activity: if (OclType["Set"])->size() = 2 then ( return Sequence{OclType["Set"]}->union(Sequence{ Sequence{Set{}->union([1+1])}->union(Sequence{ Set{}->union(->first()) }) }) ) else (if (OclType["Set"])->size() < 2 then ( return OclType["Set"] ) else skip) ; var perms : Sequence := Sequence{} ; var prev : OclAny := get_permutations(Set{}->union(->tail())) ; for i : Integer.subrange(0, (OclType["Set"])->size()-1) do ( for perm : prev do ( execute ((perm.subrange(1,i)->union(Sequence{ Set{}->union(->first()) }) + perm.subrange(i+1)) : perms))) ; return perms; operation evaluate(p : OclAny, mat : OclAny) : OclAny pre: true post: true activity: var value : OclAny := mat[p->first()+1][p[1+1]+1] + mat[p[1+1]+1][p->first()+1] + mat[p[2+1]+1][p[3+1]+1] + mat[p[3+1]+1][p[2+1]+1] ; value := value + mat[p[1+1]+1][p[2+1]+1] + mat[p[2+1]+1][p[1+1]+1] + mat[p[3+1]+1][p[4+1]+1] + mat[p[4+1]+1][p[3+1]+1] ; value := value + mat[p[2+1]+1][p[3+1]+1] + mat[p[3+1]+1][p[2+1]+1] ; value := value + mat[p[3+1]+1][p[4+1]+1] + mat[p[4+1]+1][p[3+1]+1] ; return value; operation main() pre: true post: true activity: var matrix : Sequence := Sequence{} ; for i : Integer.subrange(0, 5-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : matrix)) ; var result : int := 0 ; perms := get_permutations(Sequence{0}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))))) ; for perm : perms do ( value := evaluate(perm, matrix) ; result := if (result->compareTo(value)) >= 0 then result else value endif) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=int(input()) print((a-2)*(a-2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; execute ((a - 2) * (a - 2))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,D=(int(x)for x in input().split()) table=[[int(i)for i in input().split()]for N in range(N)] cnt=0 for i in range(N): if D**2>=(table[i][0]*table[i][0]+table[i][1]*table[i][1]): cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var D : OclAny := null; Sequence{N,D} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var table : Sequence := Integer.subrange(0, N-1)->select(N | true)->collect(N | (input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())))) ; var cnt : int := 0 ; for i : Integer.subrange(0, N-1) do ( if ((D)->pow(2)->compareTo((table[i+1]->first() * table[i+1]->first() + table[i+1][1+1] * table[i+1][1+1]))) >= 0 then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines n,d=map(int,readline().split()) xy=list(map(int,read().split())) d2=d*d ans=0 it=iter(xy) for x,y in zip(it,it): if(x**2+y**2<=d2): ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var read : OclAny := sys.stdin.buffer.read ; var readline : OclAny := sys.stdin.buffer.readline ; var readlines : OclAny := sys.stdin.buffer.readlines ; var n : OclAny := null; var d : OclAny := null; Sequence{n,d} := (readline().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var xy : Sequence := ((read().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d2 : double := d * d ; var ans : int := 0 ; var it : OclAny := OclIterator.newOclIterator_Sequence(xy) ; for _tuple : Integer.subrange(1, it->size())->collect( _indx | Sequence{it->at(_indx), it->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); if (((x)->pow(2) + (y)->pow(2)->compareTo(d2)) <= 0) then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline a,b=(int(x)for x in input().split()) min_=min([a,b]) ret=a*b for i in reversed(range(1,min_+1)): if a % i==0 and b % i==0 : ret=int(a*b/i) break print(ret) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x)))))))) ))))))) (comp_for for (exprlist (expr (atom (name x)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var min_ : OclAny := (Sequence{a}->union(Sequence{ b }))->min() ; var ret : double := a * b ; for i : (Integer.subrange(1, min_ + 1-1))->reverse() do ( if a mod i = 0 & b mod i = 0 then ( ret := ("" + ((a * b / i)))->toInteger() ; break ) else skip) ; execute (ret)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from fractions import gcd a=list(map(int,input().split())) print(int((a[0]*a[1])/gcd(a[0],a[1]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (("" + (((a->first() * a[1+1]) / gcd(a->first(), a[1+1]))))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from fractions import gcd def input(): return sys.stdin.readline().strip() def list2d(a,b,c): return[[c]*b for i in range(a)] def list3d(a,b,c,d): return[[[d]*c for j in range(b)]for i in range(a)] def list4d(a,b,c,d,e): return[[[[e]*d for j in range(c)]for j in range(b)]for i in range(a)] def ceil(x,y=1): return int(-(-x//y)) def INT(): return int(input()) def MAP(): return map(int,input().split()) def LIST(N=None): return list(MAP())if N is None else[INT()for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10**9) INF=10**18 MOD=10**9+7 def lcm(x,y): return(x*y)//gcd(x,y) A,B=MAP() print(lcm(A,B)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var INF : double := (10)->pow(18) ; var MOD : double := (10)->pow(9) + 7 ; skip ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := MAP() ; execute (lcm(A, B))->display(); operation input() : OclAny pre: true post: true activity: return sys.stdin.readLine()->trim(); operation list2d(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, a-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ c }, b))); operation list3d(a : OclAny, b : OclAny, c : OclAny, d : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, a-1)->select(i | true)->collect(i | (Integer.subrange(0, b-1)->select(j | true)->collect(j | (MatrixLib.elementwiseMult(Sequence{ d }, c))))); operation list4d(a : OclAny, b : OclAny, c : OclAny, d : OclAny, e : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, a-1)->select(i | true)->collect(i | (Integer.subrange(0, b-1)->select(j | true)->collect(j | (Integer.subrange(0, c-1)->select(j | true)->collect(j | (MatrixLib.elementwiseMult(Sequence{ e }, d))))))); operation ceil(x : OclAny, y : int) : OclAny pre: true post: true activity: if y->oclIsUndefined() then y := 1 else skip; return ("" + ((-(-x div y))))->toInteger(); operation INT() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation MAP() : OclAny pre: true post: true activity: return (input().split())->collect( _x | (OclType["int"])->apply(_x) ); operation LIST(N : OclAny) : OclAny pre: true post: true activity: if N->oclIsUndefined() then N := null else skip; return if N <>= null then (MAP()) else Integer.subrange(0, N-1)->select(i | true)->collect(i | (INT())) endif; operation Yes() pre: true post: true activity: execute ('Yes')->display(); operation No() pre: true post: true activity: execute ('No')->display(); operation YES() pre: true post: true activity: execute ('YES')->display(); operation NO() pre: true post: true activity: execute ('NO')->display(); operation lcm(x : OclAny, y : OclAny) : OclAny pre: true post: true activity: return (x * y) div gcd(x, y); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=list(map(int,input().split())) a=n[0] b=n[1] if acollect( _x | (OclType["int"])->apply(_x) )) ; var a : OclAny := n->first() ; var b : OclAny := n[1+1] ; if (a->compareTo(b)) < 0 then ( var min : OclAny := a ) else ( min := b ) ; var c : Sequence := Sequence{} ; var i : int := 2 ; while (i->compareTo(min)) <= 0 do ( if a mod i = 0 & b mod i = 0 then ( a := a div i ; b := b div i ; min := min div i ; c := c + Sequence{ i } ) else ( i := i + 1 )) ; n := 1 ; for i : Integer.subrange(0, (c)->size()-1) do ( n := n * c[i+1]) ; var l : Sequence := MatrixLib.elementwiseMult(MatrixLib.elementwiseMult(n, a), b) ; execute (l)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd_core(a,b): if b==0 : return a else : return gcd_core(b,a % b) def lcm_core(a,b): g=gcd_core(a,b) return(a*b)//g a,b=map(int,input().split()) print(lcm_core(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (lcm_core(a, b))->display(); operation gcd_core(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if b = 0 then ( return a ) else ( return gcd_core(b, a mod b) ); operation lcm_core(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var g : OclAny := gcd_core(a, b) ; return (a * b) div g; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPossibleToZero(a,n): num=0 ; for i in range(n): num=num*10+a[i]; return(num % 11==0); arr=[0,1,1,0]; n=len(arr); if(isPossibleToZero(arr,n)): print("YES"); else : print("NO"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var arr : Sequence := Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 0 }))); ; n := (arr)->size(); ; if (isPossibleToZero(arr, n)) then ( execute ("YES")->display(); ) else ( execute ("NO")->display(); ); operation isPossibleToZero(a : OclAny, n : OclAny) pre: true post: true activity: var num : int := 0; ; for i : Integer.subrange(0, n-1) do ( num := num * 10 + a[i+1];) ; return (num mod 11 = 0);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNDigitNumsUtil(n,out,index,evenSum,oddSum): if(index>n): return if(index==n): if(abs(evenSum-oddSum)==1): out[index]='' out=''.join(out) print(out,end=" ") return if(index & 1): for i in range(10): out[index]=chr(i+ord('0')) findNDigitNumsUtil(n,out,index+1,evenSum,oddSum+i) else : for i in range(10): out[index]=chr(i+ord('0')) findNDigitNumsUtil(n,out,index+1,evenSum+i,oddSum) def findNDigitNums(n): out=[0]*(n+1) index=0 evenSum=0 oddSum=0 for i in range(1,10): out[index]=chr(i+ord('0')) findNDigitNumsUtil(n,out,index+1,evenSum+i,oddSum) if __name__=="__main__" : n=3 findNDigitNums(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 3 ; findNDigitNums(n) ) else skip; operation findNDigitNumsUtil(n : OclAny, out : OclAny, index : OclAny, evenSum : OclAny, oddSum : OclAny) pre: true post: true activity: if ((index->compareTo(n)) > 0) then ( return ) else skip ; if (index = n) then ( if ((evenSum - oddSum)->abs() = 1) then ( out[index+1] := '' ; out := StringLib.sumStringsWithSeparator((out), '') ; execute (out)->display() ) else skip ; return ) else skip ; if (MathLib.bitwiseAnd(index, 1)) then ( for i : Integer.subrange(0, 10-1) do ( out[index+1] := (i + ('0')->char2byte())->byte2char() ; findNDigitNumsUtil(n, out, index + 1, evenSum, oddSum + i)) ) else ( for i : Integer.subrange(0, 10-1) do ( out[index+1] := (i + ('0')->char2byte())->byte2char() ; findNDigitNumsUtil(n, out, index + 1, evenSum + i, oddSum)) ); operation findNDigitNums(n : OclAny) pre: true post: true activity: out := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; index := 0 ; evenSum := 0 ; oddSum := 0 ; for i : Integer.subrange(1, 10-1) do ( out[index+1] := (i + ('0')->char2byte())->byte2char() ; findNDigitNumsUtil(n, out, index + 1, evenSum + i, oddSum)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def center_nonadecagon_num(n): return(19*n*n-19*n+2)//2 if __name__=='__main__' : n=2 print(n,"nd centered nonadecagonal "+"number : ",center_nonadecagon_num(n)) n=7 print(n,"nd centered nonadecagonal "+"number : ",center_nonadecagon_num(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 2 ; execute (n)->display() ; n := 7 ; execute (n)->display() ) else skip; operation center_nonadecagon_num(n : OclAny) : OclAny pre: true post: true activity: return (19 * n * n - 19 * n + 2) div 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import heapq import sys import math import itertools import bisect from io import BytesIO,IOBase import os def valid(i,j,n,m): if i=0 and j>=0 and jcompareTo(n)) < 0 & i >= 0 & j >= 0 & (j->compareTo(m)) < 0 then ( return true ) else skip ; return false; operation sumn(i : OclAny, n : OclAny) : OclAny pre: true post: true activity: return (n - i) * (i + n) / 2; operation sqfun(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: return (-b + (b * b - 4 * a * c)->sqrt()) / 2 * a; operation getprime(num : OclAny) : OclAny pre: true post: true activity: if ((argument (test (logical_test (comparison (comparison (expr (expr (atom (name num))) % (expr (atom (name i))))) != (comparison (expr (atom (number (integer 0)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name math)) (trailer . (name sqrt) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name num)))))))) ))))))))) )))) + (expr (atom (number (integer 1)))))))))) )))))))))->forAll( _x | _x = true ) then ( return true ) else skip; operation value() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation values() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inlsts() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inps() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation instr() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation stlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (i)); operation solve() pre: true post: true activity: n := inp() ; execute (((n - 2))->pow(2))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter,deque,defaultdict from math import* import itertools from bisect import bisect_right mod=1000000007 def solve(): mat=[] for _ in range(5): mat.append(list(map(int,input().split()))) ans=0 l=itertools.permutations([1,2,3,4,0]) for i in l : cur=0 for j in range(5): x=j+1 if x==5 : cur+=(mat[i[4]][i[3]]+mat[i[3]][i[4]])*2 elif x==4 : cur+=(mat[i[3]][i[2]]+mat[i[2]][i[3]])*2 elif x==3 : cur+=(mat[i[2]][i[1]]+mat[i[1]][i[2]]) elif x==2 : cur+=(mat[i[1]][i[0]]+mat[i[0]][i[1]]) ans=max(cur,ans) print(ans) t=1 for num in range(t): solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var mod : int := 1000000007 ; skip ; var t : int := 1 ; for num : Integer.subrange(0, t-1) do ( solve()); operation solve() pre: true post: true activity: var mat : Sequence := Sequence{} ; for _anon : Integer.subrange(0, 5-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : mat)) ; var ans : int := 0 ; var l : OclAny := itertools.permutations(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 0 }))))) ; for i : l do ( var cur : int := 0 ; for j : Integer.subrange(0, 5-1) do ( var x : OclAny := j + 1 ; if x = 5 then ( cur := cur + (mat[i[4+1]+1][i[3+1]+1] + mat[i[3+1]+1][i[4+1]+1]) * 2 ) else (if x = 4 then ( cur := cur + (mat[i[3+1]+1][i[2+1]+1] + mat[i[2+1]+1][i[3+1]+1]) * 2 ) else (if x = 3 then ( cur := cur + (mat[i[2+1]+1][i[1+1]+1] + mat[i[1+1]+1][i[2+1]+1]) ) else (if x = 2 then ( cur := cur + (mat[i[1+1]+1][i->first()+1] + mat[i->first()+1][i[1+1]+1]) ) else skip ) ) ) ) ; ans := Set{cur, ans}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math while True : try : a,b=map(int,input().split()) print(math.gcd(a,b),a*b//math.gcd(a,b)) except : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; while true do ( try ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((a)->gcd(b))->display()) catch (_e : OclException) do ( break) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys for m,n in[map(int,x.split())for x in list(sys.stdin)]: g,r=m,n while r!=0 : g,r=r,g % r print(g,m//g*n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _tuple : (OclFile["System.in"])->select(x | true)->collect(x | ((x.split())->collect( _x | (OclType["int"])->apply(_x) ))) do (var _indx : int := 1; var m : OclAny := _tuple->at(_indx); _indx := _indx + 1; var n : OclAny := _tuple->at(_indx); var g : OclAny := null; var r : OclAny := null; Sequence{g,r} := Sequence{m,n} ; while r /= 0 do ( var g : OclAny := null; var r : OclAny := null; Sequence{g,r} := Sequence{r,g mod r}) ; execute (g)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def gcd(m,n): r=m % n if r==0 : return n else : return gcd(n,r) lines=sys.stdin.readlines() for line in lines : a,b=map(int,line.split()) m=max(a,b) n=min(a,b) print(gcd(m,n),m*n//gcd(m,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var lines : OclAny := (OclFile["System.in"]).readlines() ; for line : lines do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (line.split())->collect( _x | (OclType["int"])->apply(_x) ) ; m := Set{a, b}->max() ; n := Set{a, b}->min() ; execute (gcd(m, n))->display()); operation gcd(m : OclAny, n : OclAny) : OclAny pre: true post: true activity: var r : int := m mod n ; if r = 0 then ( return n ) else ( return gcd(n, r) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def lcm(a,b): return a//gcd(a,b)*b def gcd(a,b): while b!=0 : r=a % b a=b b=r return a while True : try : a=list(map(int,input().split())) print(gcd(a[0],a[1]),lcm(a[0],a[1])) except EOFError : break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while true do ( try ( a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (gcd(a->first(), a[1+1]))->display()) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break)))))); operation lcm(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return a div gcd(a, b) * b; operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: while b /= 0 do ( var r : int := a mod b ; a := b ; b := r) ; return a; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys for i in sys.stdin : a,b=map(int,i.split()) if a0 : x,y=y,x % y return x def lcm(x,y): return x*y/gcd(x,y) print(gcd(a,b),int(lcm(a,b))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for i : OclFile["System.in"] do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (i.split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(b)) < 0 then ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{b,a} ) else skip ; skip ; skip ; execute (gcd(a, b))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,h=map(int,input().split()) a=list(map(int,input().split())) count=0 for i in range(n): if a[i]<=h : count+=1 else : count+=2 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var h : OclAny := null; Sequence{n,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (a[i+1]->compareTo(h)) <= 0 then ( count := count + 1 ) else ( count := count + 2 )) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def inp(): return sys.stdin.readline() n,v=map(int,inp().split()) l=map(int,inp().split()) w=0 for _ in l : if _>v : w+=1 print(n+w) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; var v : OclAny := null; Sequence{n,v} := (inp().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := (inp().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var w : int := 0 ; for _anon : l do ( if (_anon->compareTo(v)) > 0 then ( w := w + 1 ) else skip) ; execute (n + w)->display(); operation inp() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,h=input().split() arr=[int(x)for x in input().split()] i=0 sum=0 while iselect(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var i : int := 0 ; var sum : int := 0 ; while (i->compareTo(("" + ((n)))->toInteger())) < 0 do ( if (arr[i+1]->compareTo(("" + ((h)))->toInteger())) <= 0 then ( sum := sum + 1 ) else ( sum := sum + 2 ) ; i := i + 1) ; execute (sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,h=map(int,input().split()) list1=list(map(int,input().split())) x=0 for i in range(n): if list1[i]>h : x+=2 elif list1[i]<=h : x+=1 print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var h : OclAny := null; Sequence{n,h} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var list1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (list1[i+1]->compareTo(h)) > 0 then ( x := x + 2 ) else (if (list1[i+1]->compareTo(h)) <= 0 then ( x := x + 1 ) else skip)) ; execute (x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countIdenticalRows(mat): count=0 for i in range(len(mat)): hs=dict() for j in range(len(mat[i])): hs[mat[i][j]]=1 if(len(hs)==1): count+=1 return count mat=[[1,1,1],[1,2,3],[5,5,5]] print(countIdenticalRows(mat)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; mat := Sequence{Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))}->union(Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{ Sequence{5}->union(Sequence{5}->union(Sequence{ 5 })) })) ; execute (countIdenticalRows(mat))->display(); operation countIdenticalRows(mat : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, (mat)->size()-1) do ( var hs : Map := (arguments ( )) ; for j : Integer.subrange(0, (mat[i+1])->size()-1) do ( hs[mat[i+1][j+1]+1] := 1) ; if ((hs)->size() = 1) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m,n=map(int,input().split()) x=list(map(int,input().split())) num=0 for i in x : if i>n : num+=2 else : num+=1 print(num) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : OclAny := null; var n : OclAny := null; Sequence{m,n} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var num : int := 0 ; for i : x do ( if (i->compareTo(n)) > 0 then ( num := num + 2 ) else ( num := num + 1 )) ; execute (num)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mat=[] for i in range(5): tmp=[int(x)for x in input().split()] mat.append(tmp) def cal_hap(mat,op): hp=0 i=0 while(i<4): j=i while(j<4): hp+=mat[op[j]][op[j+1]] hp+=mat[op[j+1]][op[j]] j+=2 i+=1 return hp op=[[]] for i in range(5): cs=[] for j in range(len(op)): for k in range(5): if k not in op[j]: cs.append(op[j]+[k]) op=cs mx=0 for st in op : tmp=cal_hap(mat,st) if tmp>mx : mx=tmp print(mx) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mat : Sequence := Sequence{} ; for i : Integer.subrange(0, 5-1) do ( var tmp : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((tmp) : mat)) ; skip ; op := Sequence{ Sequence{} } ; for i : Integer.subrange(0, 5-1) do ( var cs : Sequence := Sequence{} ; for j : Integer.subrange(0, (op)->size()-1) do ( for k : Integer.subrange(0, 5-1) do ( if (op[j+1])->excludes(k) then ( execute ((op[j+1]->union(Sequence{ k })) : cs) ) else skip)) ; op := cs) ; var mx : int := 0 ; for st : op do ( tmp := cal_hap(mat, st) ; if (tmp->compareTo(mx)) > 0 then ( mx := tmp ) else skip) ; execute (mx)->display(); operation cal_hap(mat : OclAny, op : OclAny) : OclAny pre: true post: true activity: var hp : int := 0 ; var i : int := 0 ; while (i < 4) do ( var j : int := i ; while (j < 4) do ( hp := hp + mat[op[j+1]+1][op[j + 1+1]+1] ; hp := hp + mat[op[j + 1+1]+1][op[j+1]+1] ; j := j + 2) ; i := i + 1) ; return hp; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNextWord(s,m): m+=97 n=len(s) i=len(s)-1 s[i]=chr(ord(s[i])+1) while i>=0 and i<=n-1 : if ord(s[i])>=m : s[i]='a' i-=1 s[i]=chr(ord(s[i])+1) elif s[i]==s[i-1]or s[i]==s[i-2]: s[i]=chr(ord(s[i])+1) else : i+=1 if i<=-1 : print("-1") else : print(''.join(s)) if __name__=="__main__" : string="abcd" k=4 findNextWord(list(string),k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var string : String := "abcd" ; var k : int := 4 ; findNextWord((string)->characters(), k) ) else skip; operation findNextWord(s : OclAny, m : OclAny) pre: true post: true activity: m := m + 97 ; var n : int := (s)->size() ; var i : double := (s)->size() - 1 ; s[i+1] := ((s[i+1])->char2byte() + 1)->byte2char() ; while i >= 0 & (i->compareTo(n - 1)) <= 0 do ( if ((s[i+1])->char2byte()->compareTo(m)) >= 0 then ( s[i+1] := 'a' ; i := i - 1 ; s[i+1] := ((s[i+1])->char2byte() + 1)->byte2char() ) else (if s[i+1] = s[i - 1+1] or s[i+1] = s[i - 2+1] then ( s[i+1] := ((s[i+1])->char2byte() + 1)->byte2char() ) else ( i := i + 1 ) ) ) ; if i <= -1 then ( execute ("-1")->display() ) else ( execute (StringLib.sumStringsWithSeparator((s), ''))->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): PERIMETER=1000 for a in range(1,PERIMETER+1): for b in range(a+1,PERIMETER+1): c=PERIMETER-a-b if a*a+b*b==c*c : return str(a*b*c) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var PERIMETER : int := 1000 ; for a : Integer.subrange(1, PERIMETER + 1-1) do ( for b : Integer.subrange(a + 1, PERIMETER + 1-1) do ( var c : double := PERIMETER - a - b ; if a * a + b * b = c * c then ( return ("" + ((a * b * c))) ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from functools import cmp_to_key from collections import OrderedDict sys.setrecursionlimit(10**9) def solve(): n,k,q=list(map(int,input().split())) arr=[0 for i in range(200001)] for i in range(n): l,r=list(map(int,input().split())) arr[l]+=1 if r+1<200001 : arr[r+1]+=-1 for i in range(1,200001): arr[i]+=arr[i-1] if arr[0]>=k : arr[0]=1 else : arr[0]=0 for i in range(1,len(arr)): if arr[i]>=k : arr[i]=1 else : arr[i]=0 for i in range(1,200001): arr[i]+=arr[i-1] for i in range(q): a,b=list(map(int,input().split())) print(arr[b]-arr[a-1]) if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var q : OclAny := null; Sequence{n,k,q} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var arr : Sequence := Integer.subrange(0, 200001-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr[l+1] := arr[l+1] + 1 ; if r + 1 < 200001 then ( arr[r + 1+1] := arr[r + 1+1] + -1 ) else skip) ; for i : Integer.subrange(1, 200001-1) do ( arr[i+1] := arr[i+1] + arr[i - 1+1]) ; if (arr->first()->compareTo(k)) >= 0 then ( arr->first() := 1 ) else ( arr->first() := 0 ) ; for i : Integer.subrange(1, (arr)->size()-1) do ( if (arr[i+1]->compareTo(k)) >= 0 then ( arr[i+1] := 1 ) else ( arr[i+1] := 0 )) ; for i : Integer.subrange(1, 200001-1) do ( arr[i+1] := arr[i+1] + arr[i - 1+1]) ; for i : Integer.subrange(0, q-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (arr[b+1] - arr[a - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import heapq import sys import math import itertools import bisect from io import BytesIO,IOBase import os def value(): return tuple(map(int,input().split())) def values(): return tuple(map(int,sys.stdin.readline().split())) def inlst(): return[int(i)for i in input().split()] def inlsts(): return[int(i)for i in sys.stdin.readline().split()] def inp(): return int(input()) def inps(): return int(sys.stdin.readline()) def instr(): return input() def stlst(): return[i for i in input().split()] def solve(): n,k,q=values() l=[0]*(200003) mn,mx=200003,0 for i in range(n): a,b=values() mn=min(mn,a) mx=max(mx,b) l[a]+=1 l[b+1]-=1 arr=[0]*(200003) for i in range(200001): l[i+1]+=l[i] if l[i]>=k : arr[i]=1 for i in range(1,200001): arr[i]+=arr[i-1] for _ in range(q): a,b=values() tot=arr[b]-arr[a-1] sys.stdout.write(str(tot)+"\n") solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; solve(); operation value() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation values() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inlsts() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inps() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation instr() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation stlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (i)); operation solve() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var q : OclAny := null; Sequence{n,k,q} := values() ; var l : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (200003)) ; var mn : OclAny := null; var mx : OclAny := null; Sequence{mn,mx} := Sequence{200003,0} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := values() ; var mn : OclAny := Set{mn, a}->min() ; var mx : OclAny := Set{mx, b}->max() ; l[a+1] := l[a+1] + 1 ; l[b + 1+1] := l[b + 1+1] - 1) ; var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (200003)) ; for i : Integer.subrange(0, 200001-1) do ( l[i + 1+1] := l[i + 1+1] + l[i+1] ; if (l[i+1]->compareTo(k)) >= 0 then ( arr[i+1] := 1 ) else skip) ; for i : Integer.subrange(1, 200001-1) do ( arr[i+1] := arr[i+1] + arr[i - 1+1]) ; for _anon : Integer.subrange(0, q-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := values() ; var tot : double := arr[b+1] - arr[a - 1+1] ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name tot)))))))) )))) + (expr (atom "\n")))))))) ))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections import heapq import sys import math import itertools import bisect from io import BytesIO,IOBase import os def value(): return tuple(map(int,input().split())) def values(): return tuple(map(int,sys.stdin.readline().split())) def inlst(): return[int(i)for i in input().split()] def inlsts(): return[int(i)for i in sys.stdin.readline().split()] def inp(): return int(input()) def inps(): return int(sys.stdin.readline()) def instr(): return input() def stlst(): return[i for i in input().split()] def solve(): n,k,q=values() l=[0]*(200003) mn,mx=200003,0 for i in range(n): a,b=values() mn=min(mn,a) mx=max(mx,b) l[a]+=1 l[b+1]-=1 arr=[0]*(200003) for i in range(200001): l[i+1]+=l[i] if l[i]>=k : arr[i]=1 for i in range(1,200001): arr[i]+=arr[i-1] for _ in range(q): a,b=values() tot=arr[b]-arr[a-1] sys.stdout.write(str(tot)+"\n") solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; solve(); operation value() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation values() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation inlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inlsts() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation inp() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation inps() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation instr() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation stlst() : OclAny pre: true post: true activity: return input().split()->select(i | true)->collect(i | (i)); operation solve() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var q : OclAny := null; Sequence{n,k,q} := values() ; var l : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (200003)) ; var mn : OclAny := null; var mx : OclAny := null; Sequence{mn,mx} := Sequence{200003,0} ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := values() ; var mn : OclAny := Set{mn, a}->min() ; var mx : OclAny := Set{mx, b}->max() ; l[a+1] := l[a+1] + 1 ; l[b + 1+1] := l[b + 1+1] - 1) ; var arr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (200003)) ; for i : Integer.subrange(0, 200001-1) do ( l[i + 1+1] := l[i + 1+1] + l[i+1] ; if (l[i+1]->compareTo(k)) >= 0 then ( arr[i+1] := 1 ) else skip) ; for i : Integer.subrange(1, 200001-1) do ( arr[i+1] := arr[i+1] + arr[i - 1+1]) ; for _anon : Integer.subrange(0, q-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := values() ; var tot : double := arr[b+1] - arr[a - 1+1] ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name tot)))))))) )))) + (expr (atom "\n")))))))) ))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from functools import cmp_to_key from collections import OrderedDict sys.setrecursionlimit(10**9) def solve(): n,k,q=list(map(int,input().split())) arr=[0 for i in range(200001)] for i in range(n): l,r=list(map(int,input().split())) arr[l]+=1 if r+1<200001 : arr[r+1]+=-1 for i in range(1,200001): arr[i]+=arr[i-1] if arr[0]>=k : arr[0]=1 else : arr[0]=0 for i in range(1,len(arr)): if arr[i]>=k : arr[i]=1 else : arr[i]=0 arr[i]+=arr[i-1] for i in range(q): a,b=list(map(int,input().split())) print(arr[b]-arr[a-1]) if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var q : OclAny := null; Sequence{n,k,q} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var arr : Sequence := Integer.subrange(0, 200001-1)->select(i | true)->collect(i | (0)) ; for i : Integer.subrange(0, n-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr[l+1] := arr[l+1] + 1 ; if r + 1 < 200001 then ( arr[r + 1+1] := arr[r + 1+1] + -1 ) else skip) ; for i : Integer.subrange(1, 200001-1) do ( arr[i+1] := arr[i+1] + arr[i - 1+1]) ; if (arr->first()->compareTo(k)) >= 0 then ( arr->first() := 1 ) else ( arr->first() := 0 ) ; for i : Integer.subrange(1, (arr)->size()-1) do ( if (arr[i+1]->compareTo(k)) >= 0 then ( arr[i+1] := 1 ) else ( arr[i+1] := 0 ) ; arr[i+1] := arr[i+1] + arr[i - 1+1]) ; for i : Integer.subrange(0, q-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute (arr[b+1] - arr[a - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPossible(a,n): k=0 ; for i in range(n): if(a[i]!=i+1): k+=1 ; if(k<=2): return True ; return False ; if __name__=="__main__" : a=[5,2,3,4,1]; n=len(a); if(isPossible(a,n)): print("Yes"); else : print("No"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( a := Sequence{5}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 1 })))); ; n := (a)->size(); ; if (isPossible(a, n)) then ( execute ("Yes")->display(); ) else ( execute ("No")->display(); ) ) else skip; operation isPossible(a : OclAny, n : OclAny) pre: true post: true activity: var k : int := 0; ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] /= i + 1) then ( k := k + 1; ) else skip) ; if (k <= 2) then ( return true; ) else skip ; return false;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : w,d=[int(i)for i in input().split()] if w==0 : break h=[int(i)for i in input().split()] h_=[int(i)for i in input().split()] h=sorted(h) h_=sorted(h_) hdic={} h_dic={} for i in h : if i in hdic.keys(): hdic[i]+=1 else : hdic[i]=1 for i in h_ : if i in h_dic.keys(): h_dic[i]+=1 else : h_dic[i]=1 ans=sum(h)+sum(h_) for num in hdic.keys(): if num in h_dic.keys(): ans-=num*min(hdic[num],h_dic[num]) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var w : OclAny := null; var d : OclAny := null; Sequence{w,d} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if w = 0 then ( break ) else skip ; var h : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var h_ : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; h := h->sort() ; h_ := h_->sort() ; var hdic : OclAny := Set{} ; var h_dic : OclAny := Set{} ; for i : h do ( if (hdic.keys())->includes(i) then ( hdic[i+1] := hdic[i+1] + 1 ) else ( hdic[i+1] := 1 )) ; for i : h_ do ( if (h_dic.keys())->includes(i) then ( h_dic[i+1] := h_dic[i+1] + 1 ) else ( h_dic[i+1] := 1 )) ; var ans : OclAny := (h)->sum() + (h_)->sum() ; for num : hdic.keys() do ( if (h_dic.keys())->includes(num) then ( ans := ans - num * Set{hdic[num+1], h_dic[num+1]}->min() ) else skip) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxAlternateSum(arr,n): if(n==1): return arr[0] dec=[0 for i in range(n+1)] inc=[0 for i in range(n+1)] dec[0]=inc[0]=arr[0] flag=0 for i in range(1,n): for j in range(i): if(arr[j]>arr[i]): dec[i]=max(dec[i],inc[j]+arr[i]) flag=1 elif(arr[j]apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ll : Sequence := Sequence{} ; var last : int := -1 ; l := l->sort() ; for i : l do ( if (i /= last) then ( execute ((1) : ll) ; last := i ) else ( ll->last() := ll->last() + 1 )) ; var k : int := (ll)->size() ; while (k->compareTo((1 * (2->pow(((8 * I) div n)))))) > 0 do ( k := k - 1) ; var ans : int := 0 ; for i : Integer.subrange(0, k-1) do ( ans := ans + ll[i+1]) ; var res : int := ans ; for i : Integer.subrange(k, (ll)->size()-1) do ( ans := ans + ll[i+1] - ll[i - k+1] ; res := Set{res, ans}->max()) ; execute ((ll)->sum() - res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**3 eps=1.0/10**10 mod=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] while True : w,d=LI() if w==0 : break a=sorted(LI()) b=sorted(LI()) ai=0 bi=0 r=0 while ai=w : r+=sum(b[bi :]) break if bi>=d : r+=sum(a[ai :]) break if a[ai]==b[bi]: r+=a[ai] ai+=1 bi+=1 elif a[ai]pow(7)) ; var Math_PINFINITY : double := (10)->pow(3) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var w : OclAny := null; var d : OclAny := null; Sequence{w,d} := LI() ; if w = 0 then ( break ) else skip ; var a : Sequence := LI()->sort() ; var b : Sequence := LI()->sort() ; var ai : int := 0 ; var bi : int := 0 ; var r : int := 0 ; while (ai->compareTo(w)) < 0 or (bi->compareTo(d)) < 0 do ( if (ai->compareTo(w)) >= 0 then ( r := r + (b.subrange(bi+1))->sum() ; break ) else skip ; if (bi->compareTo(d)) >= 0 then ( r := r + (a.subrange(ai+1))->sum() ; break ) else skip ; if a[ai+1] = b[bi+1] then ( r := r + a[ai+1] ; ai := ai + 1 ; bi := bi + 1 ) else (if (a[ai+1]->compareTo(b[bi+1])) < 0 then ( r := r + a[ai+1] ; ai := ai + 1 ) else ( r := r + b[bi+1] ; bi := bi + 1 ) ) ) ; execute ((r) : rr)) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : n,m=map(int,raw_input().split()) if n==0 : break a=raw_input().split() b=raw_input().split() out=0 for i in range(21): out+=i*max(a.count(str(i)),b.count(str(i))) print(out) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 0 then ( break ) else skip ; var a : OclAny := raw_input().split() ; var b : OclAny := raw_input().split() ; var out : int := 0 ; for i : Integer.subrange(0, 21-1) do ( out := out + i * Set{a->count(("" + ((i)))), b->count(("" + ((i))))}->max()) ; execute (out)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import permutations mat=[] for _ in range(5): mat.append(list(map(int,input().split()))) arr=[1,2,3,4,5] ans=0 for perm in permutations(arr,5): res=0 k=1 for i in range(1,5): x=perm[i] y=perm[i-1] if i>=3 : k=2 res+=(mat[y-1][x-1]+mat[x-1][y-1])*k ans=max(ans,res) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var mat : Sequence := Sequence{} ; for _anon : Integer.subrange(0, 5-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : mat)) ; var arr : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 5 })))) ; var ans : int := 0 ; for perm : permutations(arr, 5) do ( var res : int := 0 ; var k : int := 1 ; for i : Integer.subrange(1, 5-1) do ( var x : OclAny := perm[i+1] ; var y : OclAny := perm[i - 1+1] ; if i >= 3 then ( k := 2 ) else skip ; res := res + (mat[y - 1+1][x - 1+1] + mat[x - 1+1][y - 1+1]) * k) ; ans := Set{ans, res}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): from sys import stdin from collections import Counter f_i=stdin while True : w,d=map(int,f_i.readline().split()) if w==0 : break h_w=Counter(map(int,f_i.readline().split())) h_d=Counter(map(int,f_i.readline().split())) for k,v in h_w.items(): if v>h_d.setdefault(k,v): h_d[k]=v print(sum(k*v for k,v in h_d.items())) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; solve(); operation solve() pre: true post: true activity: skip ; skip ; var f_i : OclAny := stdin ; while true do ( var w : OclAny := null; var d : OclAny := null; Sequence{w,d} := (f_i.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if w = 0 then ( break ) else skip ; var h_w : OclAny := Counter((f_i.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var h_d : OclAny := Counter((f_i.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for _tuple : h_w->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var k : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if (v->compareTo(h_d.setdefault(k, v))) > 0 then ( h_d[k+1] := v ) else skip) ; execute (((argument (test (logical_test (comparison (expr (expr (atom (name k))) * (expr (atom (name v))))))) (comp_for for (exprlist (expr (atom (name k))) , (expr (atom (name v)))) in (logical_test (comparison (expr (atom (name h_d)) (trailer . (name items) (arguments ( )))))))))->sum())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict import sys sys.setrecursionlimit(10**9) input=sys.stdin.readline def solve(): H,W=map(int,input().split()) if H==0 and W==0 : exit() A=list(map(int,input().split())) B=list(map(int,input().split())) d_a=defaultdict(int) for a in A : d_a[a]+=1 d_b=defaultdict(int) for b in B : d_b[b]+=1 ans=0 for v in set(A+B): ans+=v*max(d_a[v],d_b[v]) print(ans) while True : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; sys.setrecursionlimit((10)->pow(9)) ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; while true do ( solve()); operation solve() pre: true post: true activity: var H : OclAny := null; var W : OclAny := null; Sequence{H,W} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if H = 0 & W = 0 then ( exit() ) else skip ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var B : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d_a : OclAny := defaultdict(OclType["int"]) ; for a : A do ( d_a[a+1] := d_a[a+1] + 1) ; var d_b : OclAny := defaultdict(OclType["int"]) ; for b : B do ( d_b[b+1] := d_b[b+1] + 1) ; var ans : int := 0 ; for v : Set{}->union((A->union(B))) do ( ans := ans + v * Set{d_a[v+1], d_b[v+1]}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sort_shell_metzner(arr,n): m=n ; while(m>0): m//=2 k=n-m j=0 while(j=0): l=i+m if(arr[i]>arr[l]): arr[i],arr[l]=arr[l],arr[i] i-=m else : break j+=1 def printArray(arr,n): for i in range(n): print(arr[i],end=" ") if __name__=="__main__" : arr=[0,-2,8,5,1] n=len(arr) sort_shell_metzner(arr,n) printArray(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{0}->union(Sequence{-2}->union(Sequence{8}->union(Sequence{5}->union(Sequence{ 1 })))) ; n := (arr)->size() ; sort_shell_metzner(arr, n) ; printArray(arr, n) ) else skip; operation sort_shell_metzner(arr : OclAny, n : OclAny) pre: true post: true activity: var m : OclAny := n; ; while (m > 0) do ( m := m div 2 ; var k : double := n - m ; var j : int := 0 ; while ((j->compareTo(k)) < 0) do ( var i : int := j ; while (i >= 0) do ( var l : int := i + m ; if ((arr[i+1]->compareTo(arr[l+1])) > 0) then ( var arr[i+1] : OclAny := null; var arr[l+1] : OclAny := null; Sequence{arr[i+1],arr[l+1]} := Sequence{arr[l+1],arr[i+1]} ; i := i - m ) else ( break )) ; j := j + 1)); operation printArray(arr : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def solve(): n,q=map(int,sys.stdin.readline().split()) ft=FenwickTree(n) for qi in range(q): query=sys.stdin.readline().rstrip() if query[0]=='0' : c,s,t,x=map(int,query.split()) ft.add(s,x) ft.add(t+1,-x) else : c,i=map(int,query.split()) print(ft.get_sum(i)) class FenwickTree : def __init__(self,size): self.n=size self.data=[0]*(size+1) def add(self,i,x): while i<=self.n : self.data[i]+=x i+=i &(-i) def get_sum(self,r): res=0 while r>0 : res+=self.data[r] r-=r &(-r) return res if __name__=='__main__' : solve() ------------------------------------------------------------ OCL File: --------- class FenwickTree { static operation newFenwickTree() : FenwickTree pre: true post: FenwickTree->exists( _x | result = _x ); attribute n : OclAny := size; attribute data : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (size + 1)); operation initialise(size : OclAny) : FenwickTree pre: true post: true activity: self.n := size ; self.data := MatrixLib.elementwiseMult(Sequence{ 0 }, (size + 1)); return self; operation add(i : OclAny,x : OclAny) pre: true post: true activity: while (i->compareTo(self.n)) <= 0 do ( self.data[i+1] := self.data[i+1] + x ; i := i + MathLib.bitwiseAnd(i, (-i))); operation get_sum(r : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; while r > 0 do ( res := res + self.data[r+1] ; r := r - MathLib.bitwiseAnd(r, (-r))) ; return res; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( solve() ) else skip; operation solve() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ft : OclAny := FenwickTree(n) ; for qi : Integer.subrange(0, q-1) do ( var query : OclAny := sys.stdin.readLine().rstrip() ; if query->first() = '0' then ( var c : OclAny := null; var s : OclAny := null; var t : OclAny := null; var x : OclAny := null; Sequence{c,s,t,x} := (query.split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((s, x) : ft) ; execute ((t + 1, -x) : ft) ) else ( var c : OclAny := null; var i : OclAny := null; Sequence{c,i} := (query.split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (ft.get_sum(i))->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline class Tree : def __init__(self,n): self.size=2**((n-1).bit_length()) self.a=[0]*(self.size*2) def find(self,c,l,r,i): if l==r : return self.a[c] mid=(l+r)//2 if i<=mid : return self.a[c]+self.find(c*2,l,mid,i) else : return self.a[c]+self.find(c*2+1,mid+1,r,i) def add(self,c,l,r,s,t,x): if l==r or(l==s and t==r): self.a[c]+=x return mid=(l+r)//2 if t<=mid : self.add(c*2,l,mid,s,t,x) elif s>mid : self.add(c*2+1,mid+1,r,s,t,x) else : self.add(c*2,l,mid,s,mid,x) self.add(c*2+1,mid+1,r,mid+1,t,x) n,q=map(int,input().split()) st=Tree(n) for _ in range(q): cmt,*b=map(int,input().split()) if cmt==0 : st.add(1,1,st.size,b[0],b[1],b[2]) else : print(st.find(1,1,st.size,b[0])) ------------------------------------------------------------ OCL File: --------- class Tree { static operation newTree() : Tree pre: true post: Tree->exists( _x | result = _x ); attribute size : double := (2)->pow(((n - 1).bit_length())); attribute a : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (self.size * 2)); operation initialise(n : OclAny) : Tree pre: true post: true activity: self.size := (2)->pow(((n - 1).bit_length())) ; self.a := MatrixLib.elementwiseMult(Sequence{ 0 }, (self.size * 2)); return self; operation find(c : OclAny,l : OclAny,r : OclAny,i : OclAny) : OclAny pre: true post: true activity: if l = r then ( return self.a[c+1] ) else skip ; var mid : int := (l + r) div 2 ; if (i->compareTo(mid)) <= 0 then ( return self.a[c+1] + self->indexOf(c * 2, l, mid, i) - 1 ) else ( return self.a[c+1] + self->indexOf(c * 2 + 1, mid + 1, r, i) - 1 ); operation add(c : OclAny,l : OclAny,r : OclAny,s : OclAny,t : OclAny,x : OclAny) pre: true post: true activity: if l = r or (l = s & t = r) then ( self.a[c+1] := self.a[c+1] + x ; return ) else skip ; mid := (l + r) div 2 ; if (t->compareTo(mid)) <= 0 then ( execute ((c * 2, l, mid, s, t, x) : self) ) else (if (s->compareTo(mid)) > 0 then ( execute ((c * 2 + 1, mid + 1, r, s, t, x) : self) ) else ( execute ((c * 2, l, mid, s, mid, x) : self) ; execute ((c * 2 + 1, mid + 1, r, mid + 1, t, x) : self) ) ) ; } class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var st : Tree := (Tree.newTree()).initialise(n) ; for _anon : Integer.subrange(0, q-1) do ( var cmt : OclAny := null; var b : OclAny := null; Sequence{cmt,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if cmt = 0 then ( execute ((1, 1, st.size, b->first(), b[1+1], b[2+1]) : st) ) else ( execute (st->indexOf(1, 1, st.size, b->first()) - 1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class SegmentTree : seg_len=1 node=[] def __init__(self,n): while self.seg_len>=1 ; r>>=1 ; def get(self,idx): idx+=self.seg_len ret=self.node[idx] while True : idx>>=1 if idx==0 : break ret+=self.node[idx] return ret n,q=map(int,input().split()) seg_tree=SegmentTree(n) for _ in range(q): query=[int(x)for x in input().split()] if len(query)==4 : _,l,r,x=query l-=1 ; r-=1 seg_tree.add(l,r+1,x) if len(query)==2 : _,i=query i-=1 ; print(seg_tree.get(i)) ------------------------------------------------------------ OCL File: --------- class SegmentTree { static operation newSegmentTree() : SegmentTree pre: true post: SegmentTree->exists( _x | result = _x ); static attribute seg_len : int := 1; static attribute node : Sequence := Sequence{}; attribute node : Sequence := Integer.subrange(0, self.seg_len * 2-1)->select(_anon | true)->collect(_anon | (0)); operation initialise(n : OclAny) : SegmentTree pre: true post: true activity: while (self.seg_len->compareTo(n)) < 0 do ( self.seg_len := self.seg_len * (2->pow(1))) ; self.node := Integer.subrange(0, self.seg_len * 2-1)->select(_anon | true)->collect(_anon | (0)); return self; operation add(l : OclAny,r : OclAny,x : OclAny) pre: true post: true activity: l := l + self.seg_len ; r := r + self.seg_len ; while (l->compareTo(r)) < 0 do ( if MathLib.bitwiseAnd(l, 1) = 1 then ( self.node[l+1] := self.node[l+1] + x ; l := l + 1 ) else skip ; if MathLib.bitwiseAnd(r, 1) = 1 then ( self.node[r - 1+1] := self.node[r - 1+1] + x ; r := r - 1 ) else skip ; l := l div (2->pow(1)); r := r div (2->pow(1));); operation get(idx : OclAny) : OclAny pre: true post: true activity: idx := idx + self.seg_len ; var ret : OclAny := self.node[idx+1] ; while true do ( idx := idx div (2->pow(1)) ; if idx = 0 then ( break ) else skip ; ret := ret + self.node[idx+1]) ; return ret; } class FromPython { operation initialise() pre: true post: true activity: skip ; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var seg_tree : SegmentTree := (SegmentTree.newSegmentTree()).initialise(n) ; for _anon : Integer.subrange(0, q-1) do ( var query : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if (query)->size() = 4 then ( var _anon : OclAny := null; Sequence{_anon,l,r,x} := query ; l := l - 1; r := r - 1 ; execute ((l, r + 1, x) : seg_tree) ) else skip ; if (query)->size() = 2 then ( var _anon : OclAny := null; var i : OclAny := null; Sequence{_anon,i} := query ; i := i - 1; ; execute (seg_tree.get(i))->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,q=map(int,input().split()) Q=[list(map(int,input().split()))for i in range(q)] for i in range(30): if n<1<=0 : ANS+=SEG[i] i=(i-1)//2 height+=1 return ANS for query in Q : if query[0]==0 : update(query[1],query[2]+1,query[3],0,0,seg_el) else : print(getvalue(query[1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var Q : Sequence := Integer.subrange(0, q-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; for i : Integer.subrange(0, 30-1) do ( if (n->compareTo(1 * (2->pow(i)))) < 0 then ( var seg_el : int := 1 * (2->pow(i)) ; break ) else skip) ; var SEG : Sequence := Integer.subrange(0, 2 * seg_el - 1-1)->select(i | true)->collect(i | (0)) ; skip ; skip ; for query : Q do ( if query->first() = 0 then ( update(query[1+1], query[2+1] + 1, query[3+1], 0, 0, seg_el) ) else ( execute (getvalue(query[1+1]))->display() )); operation update(a : OclAny, b : OclAny, x : OclAny, k : OclAny, l : OclAny, r : OclAny) pre: true post: true activity: if (r->compareTo(a)) <= 0 or (b->compareTo(l)) <= 0 then ( return ) else skip ; if (a->compareTo(l)) <= 0 & (r->compareTo(b)) <= 0 then ( SEG[k+1] := SEG[k+1] + x ; return ) else skip ; update(a, b, x, k * 2 + 1, l, (l + r) div 2) ; update(a, b, x, k * 2 + 2, (l + r) div 2, r); operation getvalue(n : OclAny) : OclAny pre: true post: true activity: var i : double := n + seg_el - 1 ; var ANS : OclAny := SEG[i+1] ; i := (i - 1) div 2 ; var height : int := 1 ; while i >= 0 do ( ANS := ANS + SEG[i+1] ; i := (i - 1) div 2 ; height := height + 1) ; return ANS; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def createSorted(a : list,n : int): b=[] for j in range(n): if len(b)==0 : b.append(a[j]) else : start=0 end=len(b)-1 pos=0 while start<=end : mid=start+(end-start)//2 if b[mid]==a[j]: b.insert(max(0,mid+1),a[j]) break elif b[mid]>a[j]: pos=end=mid-1 else : pos=start=mid+1 if start>end : pos=start b.insert(max(0,pos),a[j]) break for i in range(n): print(b[i],end=" ") if __name__=="__main__" : a=[2,5,4,9,8] n=len(a) createSorted(a,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var a : Sequence := Sequence{2}->union(Sequence{5}->union(Sequence{4}->union(Sequence{9}->union(Sequence{ 8 })))) ; var n : int := (a)->size() ; createSorted(a, n) ) else skip; operation createSorted(a : Sequence(OclAny), n : int) pre: true post: true activity: var b : Sequence := Sequence{} ; for j : Integer.subrange(0, n-1) do ( if (b)->size() = 0 then ( execute ((a[j+1]) : b) ) else ( var start : int := 0 ; var end : double := (b)->size() - 1 ; var pos : int := 0 ; while (start->compareTo(end)) <= 0 do ( var mid : int := start + (end - start) div 2 ; if b[mid+1] = a[j+1] then ( b := b.insertAt(Set{0, mid + 1}->max()+1, a[j+1]) ; break ) else (if (b[mid+1]->compareTo(a[j+1])) > 0 then ( pos := mid - 1; end := mid - 1 ) else ( pos := mid + 1; start := mid + 1 ) ) ; if (start->compareTo(end)) > 0 then ( pos := start ; b := b.insertAt(Set{0, pos}->max()+1, a[j+1]) ; break ) else skip) )) ; for i : Integer.subrange(0, n-1) do ( execute (b[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- line=input() n,q=list(map(int,line.split())) N=1 while N=N-1 : break return z def add(s,t,x,k,l,r): if r<=s or t<=l : return elif s<=l and r<=t : a[k]+=x return m=(l+r)//2 add(s,t,x,k*2+1,l,m) add(s,t,x,k*2+2,m,r) return for t in range(0,q): line=input() qu=list(map(int,line.split())) if qu[0]==0 : add(qu[1],qu[2]+1,qu[3],0,0,N) elif qu[0]==1 : ans=get(qu[1],0,0,N) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var line : String := (OclFile["System.in"]).readLine() ; var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := ((line.split())->collect( _x | (OclType["int"])->apply(_x) )) ; var N : int := 1 ; while (N->compareTo(n + 1)) < 0 do ( N := N * 2) ; var a : Sequence := Integer.subrange(0, 2 * N - 1-1)->select(_anon | true)->collect(_anon | (0)) ; skip ; skip ; for t : Integer.subrange(0, q-1) do ( line := (OclFile["System.in"]).readLine() ; var qu : Sequence := ((line.split())->collect( _x | (OclType["int"])->apply(_x) )) ; if qu->first() = 0 then ( add(qu[1+1], qu[2+1] + 1, qu[3+1], 0, 0, N) ) else (if qu->first() = 1 then ( var ans : OclAny := get(qu[1+1], 0, 0, N) ; execute (ans)->display() ) else skip)); operation get(i : OclAny, k : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var z : OclAny := a->first() ; while true do ( var m : int := (l + r) div 2 ; if (i->compareTo(m)) < 0 then ( k := k * 2 + 1 ; r := m ) else ( k := k * 2 + 2 ; l := m ) ; z := z + a[k+1] ; if (k->compareTo(N - 1)) >= 0 then ( break ) else skip) ; return z; operation add(s : OclAny, t : OclAny, x : OclAny, k : OclAny, l : OclAny, r : OclAny) pre: true post: true activity: if (r->compareTo(s)) <= 0 or (t->compareTo(l)) <= 0 then ( return ) else (if (s->compareTo(l)) <= 0 & (r->compareTo(t)) <= 0 then ( a[k+1] := a[k+1] + x ; return ) else skip) ; m := (l + r) div 2 ; add(s, t, x, k * 2 + 1, l, m) ; add(s, t, x, k * 2 + 2, m, r) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getCount(a,b): if(len(b)% len(a)!=0): return-1 ; count=int(len(b)/len(a)) a=a*count if(a==b): return count return-1 ; if __name__=='__main__' : a='geeks' b='geeksgeeks' print(getCount(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := 'geeks' ; b := 'geeksgeeks' ; execute (getCount(a, b))->display() ) else skip; operation getCount(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if ((b)->size() mod (a)->size() /= 0) then ( return -1; ) else skip ; var count : int := ("" + (((b)->size() / (a)->size())))->toInteger() ; a := a * count ; if (a = b) then ( return count ) else skip ; return -1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,busCap=map(int,input().split()) groups=list(map(int,input().split())) buses=1 temp=busCap for groupCount in groups : if groupCount>temp : buses+=1 temp=busCap temp-=groupCount print(buses) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var busCap : OclAny := null; Sequence{n,busCap} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var groups : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var buses : int := 1 ; var temp : OclAny := busCap ; for groupCount : groups do ( if (groupCount->compareTo(temp)) > 0 then ( buses := buses + 1 ; temp := busCap ) else skip ; temp := temp - groupCount) ; execute (buses)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- rocks={} num_ways={} mod=10007 def num_u_ways(r,c,H,W): if(r>=H or c>=W): return 0 if((r,c)in rocks): return 0 if(r==H-1 and c==W-1): return 1 if((r,c)in num_ways): return num_ways[(r,c)] a=num_u_ways(r+2,c+1,H,W) b=num_u_ways(r+1,c+2,H,W) num_ways[(r,c)]=(a+b)% mod return num_ways[(r,c)] filename="D-small-attempt0.in" f=open(filename,'r') of=open("D-small.out",'w') N=int(f.readline()) for x in xrange(N): l=f.readline().split(' ') H=int(l[0]) W=int(l[1]) R=int(l[2]) rocks={} for y in xrange(R): l=f.readline().split(' ') rocks[(int(l[0])-1,int(l[1])-1)]=True num_ways={} ans=num_u_ways(0,0,H,W) print>>of,"Case #%d: %d" %(x+1,ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var rocks : OclAny := Set{} ; var num_ways : OclAny := Set{} ; var mod : int := 10007 ; skip ; var filename : String := "D-small-attempt0.in" ; var f : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(filename)) ; var of : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile("D-small.out")) ; var N : int := ("" + ((f.readLine())))->toInteger() ; for x : xrange(N) do ( var l : OclAny := f.readLine().split(' ') ; H := ("" + ((l->first())))->toInteger() ; W := ("" + ((l[1+1])))->toInteger() ; var R : int := ("" + ((l[2+1])))->toInteger() ; rocks := Set{} ; for y : xrange(R) do ( l := f.readLine().split(' ') ; rocks[Sequence{("" + ((l->first())))->toInteger() - 1, ("" + ((l[1+1])))->toInteger() - 1}+1] := true) ; num_ways := Set{} ; var ans : OclAny := num_u_ways(0, 0, H, W) ; print /(2->pow(of)) ; (expr (expr (atom "Case #%d: %d")) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (atom (name ans))))))) ))))); operation num_u_ways(r : OclAny, c : OclAny, H : OclAny, W : OclAny) : OclAny pre: true post: true activity: if ((r->compareTo(H)) >= 0 or (c->compareTo(W)) >= 0) then ( return 0 ) else skip ; if ((rocks)->includes(Sequence{r, c})) then ( return 0 ) else skip ; if (r = H - 1 & c = W - 1) then ( return 1 ) else skip ; if ((num_ways)->includes(Sequence{r, c})) then ( return num_ways[Sequence{r, c}+1] ) else skip ; var a : OclAny := num_u_ways(r + 2, c + 1, H, W) ; var b : OclAny := num_u_ways(r + 1, c + 2, H, W) ; num_ways[Sequence{r, c}+1] := (a + b) mod mod ; return num_ways[Sequence{r, c}+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) l=list(map(int,input().split())) s=0 j=0 i=0 while icollect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : int := 0 ; var j : int := 0 ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( if (j + l[i+1]->compareTo(m)) <= 0 then ( j := j + l[i+1] ; i := i + 1 ) else ( s := s + 1 ; j := 0 )) ; if j /= 0 then ( s := s + 1 ) else skip ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=list(map(int,input().split())) lst=list(map(int,input().split())) ans=1 people=0 for i in range(len(lst)): if people+lst[i]<=m : people+=lst[i] else : ans+=1 people=lst[i] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : int := 1 ; var people : int := 0 ; for i : Integer.subrange(0, (lst)->size()-1) do ( if (people + lst[i+1]->compareTo(m)) <= 0 then ( people := people + lst[i+1] ) else ( ans := ans + 1 ; people := lst[i+1] )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- groupsCount,busCapacity=list(map(int,input().split())) groups=list(map(int,input().split())) buses=1 tempBC=busCapacity for group in groups : if group>tempBC : buses+=1 tempBC=busCapacity tempBC-=group print(buses) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var groupsCount : OclAny := null; var busCapacity : OclAny := null; Sequence{groupsCount,busCapacity} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var groups : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var buses : int := 1 ; var tempBC : OclAny := busCapacity ; for group : groups do ( if (group->compareTo(tempBC)) > 0 then ( buses := buses + 1 ; tempBC := busCapacity ) else skip ; tempBC := tempBC - group) ; execute (buses)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,input().split()) mm=m a=list(map(int,input().split())) b=0 i=0 while icollect( _x | (OclType["int"])->apply(_x) ) ; var mm : OclAny := m ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : int := 0 ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( m := m - a[i+1] ; if m < 0 then ( b := b + 1 ; var m : OclAny := mm ; i := i - 1 ) else skip ; i := i + 1) ; b := b + 1 ; execute (b)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ksmallest(arr,n,k): arr.sort(); if(karr[n-1]): return k+n ; if(arr[0]==1): k-=1 ; else : k-=(arr[0]-1); for i in range(1,n): c=arr[i]-arr[i-1]-1 ; if(k<=c): return arr[i-1]+k ; else : k-=c ; return arr[n-1]+k ; k=1 ; arr=[1]; n=len(arr); print(ksmallest(arr,n,k)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; k := 1; ; arr := Sequence{ 1 }; ; n := (arr)->size(); ; execute (ksmallest(arr, n, k))->display();; operation ksmallest(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: arr := arr->sort(); ; if ((k->compareTo(arr->first())) < 0) then ( return k; ) else skip ; if (k = arr->first()) then ( return arr->first() + 1; ) else skip ; if ((k->compareTo(arr[n - 1+1])) > 0) then ( return k + n; ) else skip ; if (arr->first() = 1) then ( k := k - 1; ) else ( k := k - (arr->first() - 1); ) ; for i : Integer.subrange(1, n-1) do ( var c : double := arr[i+1] - arr[i - 1+1] - 1; ; if ((k->compareTo(c)) <= 0) then ( return arr[i - 1+1] + k; ) else ( k := k - c; )) ; return arr[n - 1+1] + k;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r={"*" : 2,"/" : 2,"+" : 1,"-" : 1,"(" : 0,")" : 0} for _ in[0]*int(input()): L=[]; t='' for e in input()[:-1]: if e.isdigit(): t+=e else : if t : L+=[t]; t='' L+=e if t : L+=[t] P,S=[],[] for i in L : if "("==i : S+=i elif ")"==i : while "("!=S[-1]: P+=S.pop() S.pop() elif i in r : while S and r[S[-1]]>=r[i]: P+=S.pop() S+=i else : P+=[i] while S : P+=S.pop() for x in P : if x in '+-*/' : t=S.pop(); S+=[str(int(eval(S.pop()+x+t)))] else : S+=[x] print(*S) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var r : Map := Map{ "*" |-> 2 }->union(Map{ "/" |-> 2 }->union(Map{ "+" |-> 1 }->union(Map{ "-" |-> 1 }->union(Map{ "(" |-> 0 }->union(Map{ ")" |-> 0 }))))) ; for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var L : Sequence := Sequence{}; var t : String := '' ; for e : input()->front() do ( if e->matches("[0-9]*") then ( t := t + e ) else ( if t then ( L := L + Sequence{ t }; t := '' ) else skip ; L := L + e )) ; if t then ( L := L + Sequence{ t } ) else skip ; var P : OclAny := null; var S : OclAny := null; Sequence{P,S} := Sequence{Sequence{},Sequence{}} ; for i : L do ( if "(" = i then ( S := S + i ) else (if ")" = i then ( while "(" /= S->last() do ( P := P + S->last() ; S := S->front()) ; S := S->front() ) else (if (r)->includes(i) then ( while S & (r[S->last()+1]->compareTo(r[i+1])) >= 0 do ( P := P + S->last() ; S := S->front()) ; S := S + i ) else ( P := P + Sequence{ i } ) ) ) ) ; while S do ( P := P + S->last() ; S := S->front()) ; for x : P do ( if ('+-*/')->characters()->includes(x) then ( t := S->last() ; S := S->front(); S := S + Sequence{ ("" + ((("" + ((S->last() + x + t)))->toInteger()))) } ) else ( S := S + Sequence{ x } )) ; execute ((argument * (test (logical_test (comparison (expr (atom (name S))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countTotalDistinct(string): cnt=0 ; items=set(); for i in range(len(string)): temp="" ; ans=set(); for j in range(i,len(string)): temp=temp+string[j]; ans.add(string[j]); if temp not in items : items.add(temp); cnt+=len(ans); return cnt ; if __name__=="__main__" : string="ABCA" ; print(countTotalDistinct(string)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( string := "ABCA"; ; execute (countTotalDistinct(string))->display(); ) else skip; operation countTotalDistinct(string : OclAny) pre: true post: true activity: var cnt : int := 0; ; var items : Set := Set{}->union(()); ; for i : Integer.subrange(0, (string)->size()-1) do ( var temp : String := ""; ; var ans : Set := Set{}->union(()); ; for j : Integer.subrange(i, (string)->size()-1) do ( temp := temp + string[j+1]; ; execute ((string[j+1]) : ans); ; if (items)->excludes(temp) then ( execute ((temp) : items); ; cnt := cnt + (ans)->size(); ) else skip)) ; return cnt;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def digit(): global S global cur if S[cur].isdigit(): n=int(S[cur]) cur+=1 return n def number(): global S L=len(S) global cur n=digit() while(curtrim())))->toInteger() ; for _anon : Integer.subrange(0, N-1) do ( S := ("" + ((input()->trim()))) ; S := S->front() ; cur := 0 ; var ans : OclAny := expression() ; execute (ans)->display()); operation digit() : OclAny pre: true post: true activity: skip ; skip ; if S[cur+1]->matches("[0-9]*") then ( var n : int := ("" + ((S[cur+1])))->toInteger() ; cur := cur + 1 ; return n ) else skip; operation number() : OclAny pre: true post: true activity: skip ; var L : int := (S)->size() ; skip ; n := digit() ; while ((cur->compareTo(L)) < 0 & S[cur+1]->matches("[0-9]*")) do ( n := n * 10 + digit()) ; return n; operation expression() : OclAny pre: true post: true activity: skip ; skip ; L := (S)->size() ; var a : OclAny := term() ; while ((cur->compareTo(L)) < 0 & (S[cur+1] = '+' or S[cur+1] = '-')) do ( var op : OclAny := S[cur+1] ; cur := cur + 1 ; var b : OclAny := term() ; if op = '+' then ( a := a + b ) else ( a := a - b )) ; return a; operation term() : OclAny pre: true post: true activity: skip ; skip ; L := (S)->size() ; a := factor() ; while ((cur->compareTo(L)) < 0 & (S[cur+1] = '*' or S[cur+1] = '/')) do ( op := S[cur+1] ; cur := cur + 1 ; b := factor() ; if op = '*' then ( a := a * b ) else ( a := (a / b)->oclAsType(int) )) ; return a; operation factor() : OclAny pre: true post: true activity: skip ; skip ; if (S[cur+1] /= '(') then ( return number() ) else ( cur := cur + 1 ; n := expression() ; if S[cur+1] = ')' then ( cur := cur + 1 ; return n ) else skip ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import re class Num : def __str__(self): return str(self.x) def __init__(self,value): self.x=value def __add__(self,value): return Num(self.x+value.x) def __sub__(self,value): return Num(self.x-value.x) def __mul__(self,value): return Num(self.x*value.x) def __truediv__(self,value): return Num(int(self.x/value.x)) N=int(input()) for i in range(N): s=input()[:-1] s=re.sub(r'(\d+)',r'Num(\1)',s) print(eval(s)) ------------------------------------------------------------ OCL File: --------- class Num { static operation newNum() : Num pre: true post: Num->exists( _x | result = _x ); operation __str__() : OclAny pre: true post: true activity: return ("" + ((self.x))); attribute x : OclAny := value; operation initialise(value : OclAny) : Num pre: true post: true activity: self.x := value; return self; operation __add__(value : OclAny) : OclAny pre: true post: true activity: return Num(self.x + value.x); operation __sub__(value : OclAny) : OclAny pre: true post: true activity: return Num(self.x - value.x); operation __mul__(value : OclAny) : OclAny pre: true post: true activity: return Num(self.x * value.x); operation __truediv__(value : OclAny) : OclAny pre: true post: true activity: return Num(("" + ((self.x / value.x)))->toInteger()); } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, N-1) do ( var s : OclAny := input()->front() ; s := (s).replaceAllMatches(StringLib.rawString('(\d+)'), StringLib.rawString('Num(\1)')) ; execute (s)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def prec(op): if op in "+-" : return 1 if op in "*/" : return 2 raise NotImplementedError() def postFix(expr): stack=[] operators=[] num=0 isdigit=False for ch in expr : if ch.isdigit(): isdigit=True num*=10 num+=int(ch) continue else : if isdigit : stack.append(num) num=0 isdigit=False if ch==')' : while len(operators)>0 : op=operators.pop() if op=='(' : break else : stack.append(op) else : raise ValueError elif ch=='(' : operators.append(ch) else : while len(operators)>0 and operators[-1]!='(' and prec(operators[-1])>=prec(ch): stack.append(operators.pop()) operators.append(ch) if isdigit : stack.append(num) for op in operators[: :-1]: if op not in "()" : stack.append(op) return stack def evaluate(stack): op=stack.pop() if type(op)is int : return op ; else : b=evaluate(stack); a=evaluate(stack); return int(eval(str(a)+op+str(b))) def solve(): for _ in range(int(sys.stdin.readline())): expr=sys.stdin.readline()[:-1].strip("=") print(evaluate(postFix(expr))) solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; solve(); operation prec(op : OclAny) : OclAny pre: true post: true activity: if ("+-")->characters()->includes(op) then ( return 1 ) else skip ; if ("*/")->characters()->includes(op) then ( return 2 ) else skip ; error NotImplementedError.newNotImplementedError(); operation postFix(expr : OclAny) : OclAny pre: true post: true activity: var stack : Sequence := Sequence{} ; var operators : Sequence := Sequence{} ; var num : int := 0 ; var isdigit : boolean := false ; for ch : expr do ( if ch->matches("[0-9]*") then ( isdigit := true ; num := num * 10 ; num := num + ("" + ((ch)))->toInteger() ; continue ) else ( if isdigit then ( execute ((num) : stack) ; num := 0 ) else skip ; isdigit := false ; if ch = ')' then ( (compound_stmt while (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name operators)))))))) ))))) > (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name op)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name operators)) (trailer . (name pop) (arguments ( ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name op)))) == (comparison (expr (atom '(')))))) : (suite (stmt (simple_stmt (small_stmt break)))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name stack)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name op)))))))) ))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt raise (test (logical_test (comparison (expr (atom (name ValueError)))))))))))) ) else (if ch = '(' then ( execute ((ch) : operators) ) else ( while (operators)->size() > 0 & operators->last() /= '(' & (prec(operators->last())->compareTo(prec(ch))) >= 0 do ( execute ((operators->last()) : stack)) ; execute ((ch) : operators) ) ) )) ; if isdigit then ( execute ((num) : stack) ) else skip ; for op : operators(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( if ("()")->characters()->excludes(op) then ( execute ((op) : stack) ) else skip) ; return stack; operation evaluate(stack : OclAny) : OclAny pre: true post: true activity: op := stack->last() ; stack := stack->front() ; if (op)->oclType() <>= OclType["int"] then ( return op; ) else ( var b : OclAny := evaluate(stack); ; var a : OclAny := evaluate(stack); ; return ("" + ((("" + ((a))) + op + ("" + ((b))))))->toInteger() ); operation solve() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( expr := sys.stdin.readLine()->front()->trim() ; execute (evaluate(postFix(expr)))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(s): def expr(l): left,mid=term(l) return edum(mid,left) def edum(l,lval): if s[l]=='+' : val,mid=term(l+1) return edum(mid,lval+val) if s[l]=='-' : val,mid=term(l+1) return edum(mid,lval-val) else : return lval,l def term(l): left,mid=value(l) return tdum(mid,left) def tdum(l,lval): if s[l]=='*' : l+=1 val1,mid=value(l) return tdum(mid,lval*val1) if s[l]=='/' : l+=1 val1,mid=value(l) return tdum(mid,(abs(lval)//abs(val1))*(-1 if(lval<0)^(val1<0)else 1)) else : return lval,l def value(l): if s[l]=='(' : val1,mid=expr(l+1) return val1,mid+1 else : val=0 fl=s[l]=='-' if fl : l+=1 while s[l].isdecimal(): val*=10 val+=int(s[l]) l+=1 if fl : val*=-1 return val,l res=expr(0)[0] print(res) def main(): q=int(input()) for _ in range(q): solve(list(input())) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation solve(s : OclAny) pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var res : OclAny := expr(0)->first() ; execute (res)->display(); operation main() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, q-1) do ( solve(((OclFile["System.in"]).readLine())->characters())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def doublefactorial(n): res=1 ; for i in range(n,-1,-2): if(i==0 or i==1): return res ; else : res*=i ; print("Double factorial is",doublefactorial(5)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute ("Double factorial is")->display();; operation doublefactorial(n : OclAny) pre: true post: true activity: var res : int := 1; ; for i : Integer.subrange(n, -1-1)->select( $x | ($x - n) mod -2 = 0 ) do ( if (i = 0 or i = 1) then ( return res; ) else ( res := res * i; )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=10**9+7 def ways(arr,n): dp=[0]*(n+1) dp[n-1]=1 for i in range(n-2,-1,-1): dp[i]=0 j=1 while((j+i)pow(9) + 7 ; skip ; arr := Sequence{5}->union(Sequence{3}->union(Sequence{1}->union(Sequence{4}->union(Sequence{ 3 })))) ; n := (arr)->size() ; execute (ways(arr, n) mod mod)->display(); operation ways(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n + 1)) ; dp[n - 1+1] := 1 ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( dp[i+1] := 0 ; var j : int := 1 ; while (((j + i)->compareTo(n)) < 0 & (j->compareTo(arr[i+1])) <= 0) do ( dp[i+1] := dp[i+1] + dp[i + j+1] ; dp[i+1] := dp[i+1] mod mod ; j := j + 1)) ; return dp->first() mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,floor def lowerWythoff(n): phi=(1+sqrt(5))/2 ; for i in range(1,n+1): ans=floor(i*phi); print(ans,end=""); if(i!=n): print(",",end=""); if __name__=="__main__" : n=5 ; lowerWythoff(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( n := 5; ; lowerWythoff(n); ) else skip; operation lowerWythoff(n : OclAny) pre: true post: true activity: var phi : double := (1 + sqrt(5)) / 2; ; for i : Integer.subrange(1, n + 1-1) do ( var ans : OclAny := floor(i * phi); ; execute (ans)->display(); ; if (i /= n) then ( execute (",")->display(); ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,d): self.data=d self.left=None self.right=None def sortedArrayToBST(arr): if not arr : return None mid=int((len(arr))/2) root=Node(arr[mid]) root.left=sortedArrayToBST(arr[: mid]) root.right=sortedArrayToBST(arr[mid+1 :]) return root def printLevelOrder(root): if not root : return q=[] q.append(root) while q!=[]: node=q.pop(0) print(node.data,end=" ") if node.left : q.append(node.left) if node.right : q.append(node.right) arr=[1,2,3,4,5,6,7] root=sortedArrayToBST(arr) printLevelOrder(root) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := d; attribute left : OclAny := null; attribute right : OclAny := null; operation initialise(d : OclAny) : Node pre: true post: true activity: self.data := d ; self.left := null ; self.right := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{ 7 })))))) ; root := sortedArrayToBST(arr) ; printLevelOrder(root); operation sortedArrayToBST(arr : OclAny) : OclAny pre: true post: true activity: if not(arr) then ( return null ) else skip ; var mid : int := ("" + ((((arr)->size()) / 2)))->toInteger() ; var root : Node := (Node.newNode()).initialise(arr[mid+1]) ; root.left := sortedArrayToBST(arr.subrange(1,mid)) ; root.right := sortedArrayToBST(arr.subrange(mid + 1+1)) ; return root; operation printLevelOrder(root : OclAny) pre: true post: true activity: if not(root) then ( return ) else skip ; var q : Sequence := Sequence{} ; execute ((root) : q) ; while q /= Sequence{} do ( var node : OclAny := q->at(0`firstArg+1) ; q := q->excludingAt(0+1) ; execute (node.data)->display() ; if node.left then ( execute ((node.left) : q) ) else skip ; if node.right then ( execute ((node.right) : q) ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def MaximumNumbers(string): n=len(string) remIndex=[-1 for i in range(3)] remIndex[0]=0 res=[-1 for i in range(n+1)] r=0 for i in range(n+1): r=(r+ord(string[i-1])-ord('0'))% 3 res[i]=res[i-1] if(remIndex[r]!=-1): res[i]=max(res[i],res[remIndex[r]]+1) remIndex[r]=i+1 return res[n] s="12345" print(MaximumNumbers(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var s : String := "12345" ; execute (MaximumNumbers(s))->display(); operation MaximumNumbers(string : OclAny) : OclAny pre: true post: true activity: var n : int := (string)->size() ; var remIndex : Sequence := Integer.subrange(0, 3-1)->select(i | true)->collect(i | (-1)) ; remIndex->first() := 0 ; var res : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (-1)) ; var r : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( r := (r + (string[i - 1+1])->char2byte() - ('0')->char2byte()) mod 3 ; res[i+1] := res[i - 1+1] ; if (remIndex[r+1] /= -1) then ( res[i+1] := Set{res[i+1], res[remIndex[r+1]+1] + 1}->max() ) else skip ; remIndex[r+1] := i + 1) ; return res[n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def calculateSum(n): a=int(n) return(2*(pow(n,6)+15*pow(n,4)+15*pow(n,2)+1)) if __name__=='__main__' : n=1.4142 print(math.ceil(calculateSum(n))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( n := 1.4142 ; execute ((calculateSum(n))->ceil())->display() ) else skip; operation calculateSum(n : OclAny) : OclAny pre: true post: true activity: var a : int := ("" + ((n)))->toInteger() ; return (2 * ((n)->pow(6) + 15 * (n)->pow(4) + 15 * (n)->pow(2) + 1)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def firstDigit(n): digits=(int)(math.log10(n)) n=(int)(n/pow(10,digits)) return n ; def lastDigit(n): return(n % 10) n=98562 ; print(firstDigit(n),end=" ") print(lastDigit(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; n := 98562; ; execute (firstDigit(n))->display() ; execute (lastDigit(n))->display(); operation firstDigit(n : OclAny) pre: true post: true activity: var digits : OclAny := (OclType["int"])((n)->log10()) ; n := (OclType["int"])(n / (10)->pow(digits)) ; return n;; operation lastDigit(n : OclAny) : OclAny pre: true post: true activity: return (n mod 10); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def maxLines(n,x1,y1,x2,y2): s=[]; slope=sys.maxsize ; for i in range(n): if(x1[i]==x2[i]): slope=sys.maxsize ; else : slope=(y2[i]-y1[i])*1.0/(x2[i]-x1[i])*1.0 ; s.append(slope); return len(s); n=2 ; x1=[1,2]; y1=[1,2]; x2=[2,4]; y2=[2,10]; print(maxLines(n,x1,y1,x2,y2)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 2; ; x1 := Sequence{1}->union(Sequence{ 2 }); ; y1 := Sequence{1}->union(Sequence{ 2 }); ; x2 := Sequence{2}->union(Sequence{ 4 }); ; y2 := Sequence{2}->union(Sequence{ 10 }); ; execute (maxLines(n, x1, y1, x2, y2))->display();; operation maxLines(n : OclAny, x1 : OclAny, y1 : OclAny, x2 : OclAny, y2 : OclAny) pre: true post: true activity: var s : Sequence := Sequence{}; ; var slope : (trailer . (name maxsize)) := (trailer . (name maxsize)); ; for i : Integer.subrange(0, n-1) do ( if (x1[i+1] = x2[i+1]) then ( slope := (trailer . (name maxsize)); ) else ( slope := (y2[i+1] - y1[i+1]) * 1.0 / (x2[i+1] - x1[i+1]) * 1.0; ) ; execute ((slope) : s);) ; return (s)->size();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countStr(n,bCount,cCount): if(bCount<0 or cCount<0): return 0 if(n==0): return 1 if(bCount==0 and cCount==0): return 1 res=countStr(n-1,bCount,cCount) res+=countStr(n-1,bCount-1,cCount) res+=countStr(n-1,bCount,cCount-1) return res if __name__=="__main__" : n=3 print(countStr(n,1,2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( n := 3 ; execute (countStr(n, 1, 2))->display() ) else skip; operation countStr(n : OclAny, bCount : OclAny, cCount : OclAny) : OclAny pre: true post: true activity: if (bCount < 0 or cCount < 0) then ( return 0 ) else skip ; if (n = 0) then ( return 1 ) else skip ; if (bCount = 0 & cCount = 0) then ( return 1 ) else skip ; var res : OclAny := countStr(n - 1, bCount, cCount) ; res := res + countStr(n - 1, bCount - 1, cCount) ; res := res + countStr(n - 1, bCount, cCount - 1) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findTwoThreePrime(l,r): if(l==1): l+=1 count=0 for i in range(l,r+1): num=i while(num % 2==0): num//=2 ; while(num % 3==0): num//=3 if(num==1): count+=1 return count if __name__=="__main__" : l=1 r=10 print(findTwoThreePrime(l,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( l := 1 ; r := 10 ; execute (findTwoThreePrime(l, r))->display() ) else skip; operation findTwoThreePrime(l : OclAny, r : OclAny) : OclAny pre: true post: true activity: if (l = 1) then ( l := l + 1 ) else skip ; var count : int := 0 ; for i : Integer.subrange(l, r + 1-1) do ( var num : OclAny := i ; while (num mod 2 = 0) do ( num := num div 2;) ; while (num mod 3 = 0) do ( num := num div 3) ; if (num = 1) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def read_input(input_path=None): if input_path is None : f=sys.stdin else : f=open(input_path,'r') n,start=map(int,f.readline().split()) checkpoints=list(map(int,f.readline().split())) return n,start,checkpoints def f(a,left,right): dl,dr=a-left,right-a return 2*max(0,min(dl,dr))+max(dl,dr) def sol(n,start,checkpoints): if n==1 : return["0"] checkpoints=sorted(checkpoints) ans=min(f(start,checkpoints[0],checkpoints[-2]),f(start,checkpoints[1],checkpoints[-1])) return[f"{ans}"] def solve(input_path=None): return sol(*read_input(input_path)) def main(): for line in sol(*read_input()): print(f"{line}") if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation read_input(input_path : OclAny) : OclAny pre: true post: true activity: if input_path->oclIsUndefined() then input_path := null else skip; if input_path <>= null then ( var f : OclFile := OclFile["System.in"] ) else ( f := OclFile.newOclFile_Write(OclFile.newOclFile(input_path)) ) ; var n : OclAny := null; var start : OclAny := null; Sequence{n,start} := (f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var checkpoints : Sequence := ((f.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; return n, start, checkpoints; operation f(a : OclAny, left : OclAny, right : OclAny) : OclAny pre: true post: true activity: var dl : OclAny := null; var dr : OclAny := null; Sequence{dl,dr} := Sequence{a - left,right - a} ; return 2 * Set{0, Set{dl, dr}->min()}->max() + Set{dl, dr}->max(); operation sol(n : OclAny, start : OclAny, checkpoints : OclAny) : OclAny pre: true post: true activity: if n = 1 then ( return Sequence{ "0" } ) else skip ; checkpoints := checkpoints->sort() ; var ans : OclAny := Set{f(start, checkpoints->first(), checkpoints->front()->last()), f(start, checkpoints[1+1], checkpoints->last())}->min() ; return Sequence{ StringLib.formattedString("{ans}") }; operation solve(input_path : OclAny) : OclAny pre: true post: true activity: if input_path->oclIsUndefined() then input_path := null else skip; return sol((argument * (test (logical_test (comparison (expr (atom (name read_input)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input_path)))))))) ))))))))); operation main() pre: true post: true activity: for line : sol((argument * (test (logical_test (comparison (expr (atom (name read_input)) (trailer (arguments ( ))))))))) do ( execute (StringLib.formattedString("{line}"))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a=map(int,input().split()) l=sorted(list(map(int,input().split()))) c=10**9 if n>2 : c=min(abs(l[1]-a)+abs(l[-1]-l[1]),c) c=min(abs(l[-1]-a)+abs(l[-1]-l[1]),c) c=min(abs(l[0]-a)+abs(l[-2]-l[0]),c) c=min(abs(l[-2]-a)+abs(l[-2]-l[0]),c) print(c) elif n==2 : print(min(abs(a-l[0]),abs(a-l[1]))) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var c : double := (10)->pow(9) ; if n > 2 then ( c := Set{(l[1+1] - a)->abs() + (l->last() - l[1+1])->abs(), c}->min() ; c := Set{(l->last() - a)->abs() + (l->last() - l[1+1])->abs(), c}->min() ; c := Set{(l->first() - a)->abs() + (l->front()->last() - l->first())->abs(), c}->min() ; c := Set{(l->front()->last() - a)->abs() + (l->front()->last() - l->first())->abs(), c}->min() ; execute (c)->display() ) else (if n = 2 then ( execute (Set{(a - l->first())->abs(), (a - l[1+1])->abs()}->min())->display() ) else ( execute (0)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x1=2 ; x2=1 ; x3=3 ; y1=2 ; y2=1 ; y3=1 ; a=2 ; b=1 ; c=1 ; x=(a*x1+b*x2+c*x3)/(a+b+c); y=(a*y1+b*y2+c*y3)/(a+b+c); print("Incenter=(",x,",",y,")"); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x1 : int := 2; var x2 : int := 1; var x3 : int := 3; ; var y1 : int := 2; var y2 : int := 1; var y3 : int := 1; ; var a : int := 2; var b : int := 1; var c : int := 1; ; var x : double := (a * x1 + b * x2 + c * x3) / (a + b + c); ; var y : double := (a * y1 + b * y2 + c * y3) / (a + b + c); ; execute ("Incenter=(")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,a=map(int,input().split()) arr=list(map(int,input().split())) arr.sort() i=0 while i=len(arr): arr.append(a) else : arr=arr[: i]+[a]+arr[i :] if i==0 : print(arr[-2]-arr[0]) elif i==len(arr)-1 : print(arr[-1]-arr[1]) else : print(min(arr[-2]+arr[i]-2*arr[0],abs(arr[i]+arr[0]-2*arr[-2]),arr[i]+arr[-1]-2*arr[1],abs(arr[i]+arr[1]-2*arr[-1]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var a : OclAny := null; Sequence{n,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; arr := arr->sort() ; var i : int := 0 ; while (i->compareTo((arr)->size())) < 0 do ( if (a->compareTo(arr[i+1])) <= 0 then ( break ) else skip ; i := i + 1) ; if (i->compareTo((arr)->size())) >= 0 then ( execute ((a) : arr) ) else ( arr := arr.subrange(1,i)->union(Sequence{ a }) + arr.subrange(i+1) ) ; if i = 0 then ( execute (arr->front()->last() - arr->first())->display() ) else (if i = (arr)->size() - 1 then ( execute (arr->last() - arr[1+1])->display() ) else ( execute (Set{arr->front()->last() + arr[i+1] - 2 * arr->first(), (arr[i+1] + arr->first() - 2 * arr->front()->last())->abs(), arr[i+1] + arr->last() - 2 * arr[1+1], (arr[i+1] + arr[1+1] - 2 * arr->last())->abs()}->min())->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,s=map(int,input().split()) l=list(map(int,input().split())) l.sort() if n==1 : print(0) else : t1=l[1] t2=l[-1] a1=t2-t1+min(abs(t1-s),abs(t2-s)) t1=l[0] t2=l[-2] a2=t2-t1+min(abs(t1-s),abs(t2-s)) print(min(a1,a2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := l->sort() ; if n = 1 then ( execute (0)->display() ) else ( var t1 : OclAny := l[1+1] ; var t2 : OclAny := l->last() ; var a1 : double := t2 - t1 + Set{(t1 - s)->abs(), (t2 - s)->abs()}->min() ; t1 := l->first() ; t2 := l->front()->last() ; var a2 : double := t2 - t1 + Set{(t1 - s)->abs(), (t2 - s)->abs()}->min() ; execute (Set{a1, a2}->min())->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(a,l,r): dl,dr=a-l,r-a return 2*max(0,min(dl,dr))+max(dl,dr) n,a=map(int,input().split()) if n==1 : print(0) exit() x=sorted(map(int,input().split())) print(min(f(a,x[0],x[-2]),f(a,x[1],x[-1]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : OclAny := null; Sequence{n,a} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = 1 then ( execute (0)->display() ; exit() ) else skip ; var x : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) )->sort() ; execute (Set{f(a, x->first(), x->front()->last()), f(a, x[1+1], x->last())}->min())->display(); operation f(a : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var dl : OclAny := null; var dr : OclAny := null; Sequence{dl,dr} := Sequence{a - l,r - a} ; return 2 * Set{0, Set{dl, dr}->min()}->max() + Set{dl, dr}->max(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,k,a): b=sorted(a) a_idx=0 k_idx=0 for i in range(1,n*k+1): if i!=b[a_idx][0]: if len(a[k_idx])==n : k_idx+=1 a[k_idx].append(i) elif a_idxselect(x | true)->collect(x | (("" + ((x)))->toInteger())) ; a := input().split()->select(x | true)->collect(x | (Sequence{ ("" + ((x)))->toInteger() })) ; print_res(solve(n, k, a)); operation solve(n : OclAny, k : OclAny, a : OclAny) : OclAny pre: true post: true activity: var b : Sequence := a->sort() ; var a_idx : int := 0 ; var k_idx : int := 0 ; for i : Integer.subrange(1, n * k + 1-1) do ( if i /= b[a_idx+1]->first() then ( if (a[k_idx+1])->size() = n then ( k_idx := k_idx + 1 ) else skip ; (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k_idx)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ) else (if (a_idx->compareTo((a)->size() - 1)) < 0 then ( a_idx := a_idx + 1 ) else skip)) ; return a; operation print_res(a : OclAny) pre: true post: true activity: for e : a do ( execute (StringLib.sumStringsWithSeparator((e->select(x | true)->collect(x | (("" + ((x)))))), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def removeZeros(a,n): ind=-1 ; for i in range(n): if(a[i]!=0): ind=i ; break ; if(ind==-1): print("Array has leading zeros only"); return ; b=[0]*(n-ind); for i in range(n-ind): b[i]=a[ind+i]; for i in range(n-ind): print(b[i],end=" "); a=[0,0,0,1,2,0,3]; n=len(a); removeZeros(a,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := Sequence{0}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{2}->union(Sequence{0}->union(Sequence{ 3 })))))); ; n := (a)->size(); ; removeZeros(a, n);; operation removeZeros(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ind : int := -1; ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] /= 0) then ( ind := i; ; break; ) else skip) ; if (ind = -1) then ( execute ("Array has leading zeros only")->display(); ; return; ) else skip ; var b : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (n - ind)); ; for i : Integer.subrange(0, n - ind-1) do ( b[i+1] := a[ind + i+1];) ; for i : Integer.subrange(0, n - ind-1) do ( execute (b[i+1])->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter import math hpop=heappop hpush=heappush def solution(): n,_=map(int,input().split()) arr=list(map(int,input().split())) h=set(arr) cur=1 for val in arr : print(val,end=" ") i=0 while ipow(30))) ; threading.stack_size(1 * (2->pow(27))) ; var thread : OclAny := threading.Thread((argument (test (logical_test (comparison (expr (atom (name target)))))) = (test (logical_test (comparison (expr (atom (name main)))))))) ; thread.start(); thread.join(); operation solution() pre: true post: true activity: var n : OclAny := null; var _anon : OclAny := null; Sequence{n,_anon} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var h : Set := Set{}->union((arr)) ; var cur : int := 1 ; for val : arr do ( execute (val)->display() ; var i : int := 0 ; while (i->compareTo(n - 1)) < 0 do ( if (h)->excludes(cur) then ( i := i + 1 ; execute (cur)->display() ) else skip ; cur := cur + 1) ; execute (->display()); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=lambda : list(map(int,input().split())) n,k=I() a=I() s=list(range(1,n*k+1)) for i in a : s.remove(i) for i in range(k): print(' '.join(map(str,[a[i]]+s[i : : k]))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : Function := lambda $$ : OclAny in (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := I->apply() ; var a : OclAny := I->apply() ; var s : Sequence := (Integer.subrange(1, n * k + 1-1)) ; for i : a do ( execute ((i) /: s)) ; for i : Integer.subrange(0, k-1) do ( execute (StringLib.sumStringsWithSeparator(((Sequence{ a[i+1] }->union(s(subscript (test (logical_test (comparison (expr (atom (name i)))))) : (sliceop : (test (logical_test (comparison (expr (atom (name k))))))))))->collect( _x | (OclType["String"])->apply(_x) )), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) a=list(map(int,input().split())) divided_oranges=[] for i in range(k): divided_oranges.append([a[i]]) remaining=[segment for segment in range(1,n*k+1)if segment not in a] for i in range(len(remaining)): divided_oranges[i % k].append(remaining[i]) for child_orange in divided_oranges : print(" ".join(str(orange)for orange in child_orange)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var divided_oranges : Sequence := Sequence{} ; for i : Integer.subrange(0, k-1) do ( execute ((Sequence{ a[i+1] }) : divided_oranges)) ; var remaining : Sequence := Integer.subrange(1, n * k + 1-1)->select(segment | (a)->excludes(segment))->collect(segment | (segment)) ; for i : Integer.subrange(0, (remaining)->size()-1) do ((expr (atom (name divided_oranges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) % (expr (atom (name k))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name remaining)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))) ; for child_orange : divided_oranges do ( execute (StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name orange)))))))) ))))))) (comp_for for (exprlist (expr (atom (name orange)))) in (logical_test (comparison (expr (atom (name child_orange)))))))), " "))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(n,k,a): b=sorted(a) a_idx=0 k_idx=0 for i in range(1,n*k+1): if i!=b[a_idx][0]: if len(a[k_idx])==n : k_idx+=1 a[k_idx].append(i) elif a_idxselect(x | true)->collect(x | (("" + ((x)))->toInteger())) ; a := input().split()->select(x | true)->collect(x | (Sequence{ ("" + ((x)))->toInteger() })) ; print_res(solve(n, k, a)); operation solve(n : OclAny, k : OclAny, a : OclAny) : OclAny pre: true post: true activity: var b : Sequence := a->sort() ; var a_idx : int := 0 ; var k_idx : int := 0 ; for i : Integer.subrange(1, n * k + 1-1) do ( if i /= b[a_idx+1]->first() then ( if (a[k_idx+1])->size() = n then ( k_idx := k_idx + 1 ) else skip ; (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name k_idx)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ) else (if (a_idx->compareTo((a)->size() - 1)) < 0 then ( a_idx := a_idx + 1 ) else skip)) ; return a; operation print_res(a : OclAny) pre: true post: true activity: for e : a do ( execute (StringLib.sumStringsWithSeparator((e->select(x | true)->collect(x | (("" + ((x)))))), ' '))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def encodedChar(string,k): n=len(string) i=0 while inum : k-=num i=j else : k-=1 k %=length return string[i+k] return string[k-1] if __name__=="__main__" : string="abced" k=4 print(encodedChar(string,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( string := "abced" ; k := 4 ; execute (encodedChar(string, k))->display() ) else skip; operation encodedChar(string : OclAny, k : OclAny) : OclAny pre: true post: true activity: var n : int := (string)->size() ; var i : int := 0 ; while (i->compareTo(n)) < 0 do ( var j : int := i ; var length : int := 0 ; var freq : int := 0 ; while (j->compareTo(n)) < 0 & string[j+1]->matches("[a-zA-Z]*") do ( j := j + 1 ; length := length + 1) ; while (j->compareTo(n)) < 0 & string[j+1]->matches("[0-9]*") do ( freq := freq * 10 + ("" + ((string[j+1])))->toInteger() ; j := j + 1) ; var num : int := freq * length ; if (k->compareTo(num)) > 0 then ( k := k - num ; i := j ) else ( k := k - 1 ; k := k mod length ; return string[i + k+1] )) ; return string[k - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=input() solved=set() for i in range(n-1): if a[i+1]!=a[i]: if a[i]in solved : print("NO") break solved.add(a[i]) if a[i+1]in solved : print("NO") break else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : String := (OclFile["System.in"]).readLine() ; var solved : Set := Set{}->union(()) ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])))) != (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))) in (comparison (expr (atom (name solved))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name solved)) (trailer . (name add) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ))))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ])))) in (comparison (expr (atom (name solved))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "NO"))))))) )))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "YES"))))))) )))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calSum(n): a=3 b=0 c=2 if(n==0): return 3 if(n==1): return 3 if(n==2): return 5 sum=5 while(n>2): d=a+b sum=sum+d a=b b=c c=d n=n-1 return sum n=9 print(calSum(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 9 ; execute (calSum(n))->display(); operation calSum(n : OclAny) : OclAny pre: true post: true activity: var a : int := 3 ; var b : int := 0 ; var c : int := 2 ; if (n = 0) then ( return 3 ) else skip ; if (n = 1) then ( return 3 ) else skip ; if (n = 2) then ( return 5 ) else skip ; var sum : int := 5 ; while (n > 2) do ( var d : int := a + b ; sum := sum + d ; a := b ; b := c ; c := d ; n := n - 1) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) s=input() cnt=[0]*26 ok=1 for i in range(1,n): if cnt[ord(s[i])-65]==1 : ok=0 break if s[i]!=s[i-1]: cnt[ord(s[i-1])-65]=1 if ok==1 : print("yes") else : print("no") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; var ok : int := 1 ; for i : Integer.subrange(1, n-1) do ( if cnt[(s[i+1])->char2byte() - 65+1] = 1 then ( ok := 0 ; break ) else skip ; if s[i+1] /= s[i - 1+1] then ( cnt[(s[i - 1+1])->char2byte() - 65+1] := 1 ) else skip) ; if ok = 1 then ( execute ("yes")->display() ) else ( execute ("no")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) done=[] for x in range(t): r="YES" n=int(input()) yet=input() for i in range(n): if yet[i]in done and yet[i]!=done[-1]: r="NO" break done.append(yet[i]) done=[] print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var done : Sequence := Sequence{} ; for x : Integer.subrange(0, t-1) do ( var r : String := "YES" ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var yet : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, n-1) do ( if (done)->includes(yet[i+1]) & yet[i+1] /= done->last() then ( r := "NO" ; break ) else skip ; execute ((yet[i+1]) : done)) ; done := Sequence{} ; execute (r)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(s): d={} prev_c=s[0] d[prev_c]=True for c in s : if c!=prev_c : if c not in d : d[c]=True prev_c=c else : return 'NO' return 'YES' t=int(input()) for _ in range(t): n=input() s=input() print(solve(s)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : String := (OclFile["System.in"]).readLine() ; s := (OclFile["System.in"]).readLine() ; execute (solve(s))->display()); operation solve(s : OclAny) : OclAny pre: true post: true activity: var d : OclAny := Set{} ; var prev_c : OclAny := s->first() ; d[prev_c+1] := true ; for c : s do ( if c /= prev_c then ( if (d)->excludes(c) then ( d[c+1] := true ; prev_c := c ) else ( return 'NO' ) ) else skip) ; return 'YES'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def find_maxm(arr,n): mpp={} for i in range(0,n): if(arr[i]in mpp): mpp.update({arr[i]: mpp[arr[i]]+1}) else : mpp[arr[i]]=1 ans=0 for value,freq in mpp.items(): if(value==freq): ans=max(ans,value) return ans arr=[3,2,2,3,4,3] n=len(arr) print(find_maxm(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{3}->union(Sequence{2}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{ 3 }))))) ; n := (arr)->size() ; execute (find_maxm(arr, n))->display(); operation find_maxm(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var mpp : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( if ((mpp)->includes(arr[i+1])) then ( execute ((Map{ arr[i+1] |-> mpp[arr[i+1]+1] + 1 }) <: mpp) ) else ( mpp[arr[i+1]+1] := 1 )) ; var ans : int := 0 ; for _tuple : mpp->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var value : OclAny := _tuple->at(_indx); _indx := _indx + 1; var freq : OclAny := _tuple->at(_indx); if (value = freq) then ( ans := Set{ans, value}->max() ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) solutions=[] for i in range(t): n=int(input()) s=input() chars=[] flag=0 char=s[0] for x in s : if x!=char : if x in chars : flag=1 ; break chars.append(char) char=x if flag==0 : solutions.append("YES") else : solutions.append("NO") for j in solutions : print(j) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var solutions : Sequence := Sequence{} ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : String := (OclFile["System.in"]).readLine() ; var chars : Sequence := Sequence{} ; var flag : int := 0 ; var char : OclAny := s->first() ; for x : s->characters() do ( if x /= char then ( if (chars)->includes(x) then ( flag := 1; ; break ) else skip ; execute ((char) : chars) ; char := x ) else skip) ; if flag = 0 then ( execute (("YES") : solutions) ) else ( execute (("NO") : solutions) )) ; for j : solutions do ( execute (j)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=100 def check(i,add,n,k,a,dp): if add<=0 : return False if i>=n : if add==k : return True return False if dp[i][add]!=-1 : return dp[i][add] dp[i][add]=(check(i+1,add-2*a[i],n,k,a,dp)or check(i+1,add,n,k,a,dp)) dp[i][add]=(check(i+1,add-(i+1),n,k,a,dp)or dp[i][add]) dp[i][add]=(check(i+1,add+i+1,n,k,a,dp)or dp[i][add]) return dp[i][add] def wrapper(n,k,a): add=0 for i in range(n): add+=a[i] dp=[-1]*MAX for i in range(MAX): dp[i]=[-1]*MAX return check(0,add,n,k,a,dp) if __name__=="__main__" : a=[1,2,3,4] n=4 k=5 print("Yes")if wrapper(n,k,a)else print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 100 ; skip ; skip ; if __name__ = "__main__" then ( a := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 4 }))) ; n := 4 ; k := 5 ; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "Yes"))))))) )))))) if (logical_test (comparison (expr (atom (name wrapper)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n))))))) , (argument (test (logical_test (comparison (expr (atom (name k))))))) , (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))))) else (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "No"))))))) )))))))) ) else skip; operation check(i : OclAny, add : OclAny, n : OclAny, k : OclAny, a : OclAny, dp : OclAny) : OclAny pre: true post: true activity: if add <= 0 then ( return false ) else skip ; if (i->compareTo(n)) >= 0 then ( if add = k then ( return true ) else skip ; return false ) else skip ; if dp[i+1][add+1] /= -1 then ( return dp[i+1][add+1] ) else skip ; dp[i+1][add+1] := (check(i + 1, add - 2 * a[i+1], n, k, a, dp) or check(i + 1, add, n, k, a, dp)) ; dp[i+1][add+1] := (check(i + 1, add - (i + 1), n, k, a, dp) or dp[i+1][add+1]) ; dp[i+1][add+1] := (check(i + 1, add + i + 1, n, k, a, dp) or dp[i+1][add+1]) ; return dp[i+1][add+1]; operation wrapper(n : OclAny, k : OclAny, a : OclAny) : OclAny pre: true post: true activity: add := 0 ; for i : Integer.subrange(0, n-1) do ( add := add + a[i+1]) ; dp := MatrixLib.elementwiseMult(Sequence{ -1 }, MAX) ; for i : Integer.subrange(0, MAX-1) do ( dp[i+1] := MatrixLib.elementwiseMult(Sequence{ -1 }, MAX)) ; return check(0, add, n, k, a, dp); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(lambda x : int(x)% 2,input().split()) if a+b+c>=2 : print("Hom") else : print("Tem") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() mod 2))->apply(_x) ) ; if a + b + c >= 2 then ( execute ("Hom")->display() ) else ( execute ("Tem")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from operator import itemgetter from fractions import gcd from math import ceil,floor,sqrt from copy import deepcopy from collections import Counter,deque import heapq from functools import reduce sys.setrecursionlimit(200000) input=sys.stdin.readline def ii(): return int(input()) def mi(): return map(int,input().rstrip().split()) def lmi(): return list(map(int,input().rstrip().split())) def li(): return list(input().rstrip()) def debug(*args,sep=" ",end="\n"): print("debug:",*args,file=sys.stderr,sep=sep,end=end)if not __debug__ else None def exit(*arg): print(*arg); sys.exit() def main(): A,B,C=mi() if(A*B)% 2==0 and(B*C)% 2==0 and(C*A)% 2==0 : print('Tem') else : print('Hom') if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(200000) ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation ii() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation mi() : OclAny pre: true post: true activity: return (input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ); operation lmi() : OclAny pre: true post: true activity: return ((input().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )); operation li() : OclAny pre: true post: true activity: return (input().rstrip()); operation debug(args : OclAny : Sequence(OclAny), sep : String, end : String) pre: true post: true activity: (args * (named_parameter (name args))) if sep->oclIsUndefined() then sep := " " else skip; if end->oclIsUndefined() then end := "\n" else skip; (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom "debug:")))))) , (argument * (test (logical_test (comparison (expr (atom (name args))))))) , (argument (test (logical_test (comparison (expr (atom (name file)))))) = (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stderr))))))) , (argument (test (logical_test (comparison (expr (atom (name sep)))))) = (test (logical_test (comparison (expr (atom (name sep))))))) , (argument (test (logical_test (comparison (expr (atom (name end)))))) = (test (logical_test (comparison (expr (atom (name end)))))))) )))))) if (logical_test not (logical_test (comparison (expr (atom (name __debug__)))))) else (test (logical_test (comparison (expr (atom None)))))); operation exit(arg : OclAny : Sequence(OclAny)) pre: true post: true activity: (args * (named_parameter (name arg))) execute ((argument * (test (logical_test (comparison (expr (atom (name arg))))))))->display(); sys.exit(); operation main() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; Sequence{A,B,C} := mi() ; if (A * B) mod 2 = 0 & (B * C) mod 2 = 0 & (C * A) mod 2 = 0 then ( execute ('Tem')->display() ) else ( execute ('Hom')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print('Hom' if len(list(i for i in map(int,input().split())if i % 2==1))>=2 else 'Tem') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (if (((argument (test (logical_test (comparison (expr (atom (name i)))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (expr (atom (name i))) % (expr (atom (number (integer 2)))))) == (comparison (expr (atom (number (integer 1)))))))))))))->size() >= 2 then 'Hom' else 'Tem' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print('Hom' if sum(map(lambda x : int(x)% 2,input().split()))>1 else 'Tem') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute (if ((input().split())->collect( _x | (lambda x : OclAny in (("" + ((x)))->toInteger() mod 2))->apply(_x) ))->sum() > 1 then 'Hom' else 'Tem' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) cnt=0 if a % 2==0 : cnt+=1 if b % 2==0 : cnt+=1 if c % 2==0 : cnt+=1 if cnt>=2 : print('Tem') else : print('Hom') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var cnt : int := 0 ; if a mod 2 = 0 then ( cnt := cnt + 1 ) else skip ; if b mod 2 = 0 then ( cnt := cnt + 1 ) else skip ; if c mod 2 = 0 then ( cnt := cnt + 1 ) else skip ; if cnt >= 2 then ( execute ('Tem')->display() ) else ( execute ('Hom')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- case=int(input()) for i in range(case): num=int(input()) puz=list(input()) if('R' not in puz)and('B' not in puz): ans='RB'*num ans=ans[0 : num] print(ans) continue while '?' in puz : if puz[0]=='?' : if puz[1]=='R' : puz[0]='B' elif puz[1]=='B' : puz[0]='R' if puz[-1]=='?' : if puz[-2]=='R' : puz[-1]='B' elif puz[-2]=='B' : puz[-1]='R' try : for j in range(puz.index('?'),num-1): if puz[j]=='?' : if puz[j+1]=='R' : puz[j]='B' elif puz[j+1]=='B' : puz[j]='R' if puz[j]=='?' and j>0 : if puz[j-1]=='R' : puz[j]='B' elif puz[j-1]=='B' : puz[j]='R' except : break ans=''.join(puz) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var case : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, case-1) do ( var num : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var puz : Sequence := ((OclFile["System.in"]).readLine())->characters() ; if ((puz)->excludes('R')) & ((puz)->excludes('B')) then ( var ans : String := StringLib.nCopies('RB', num) ; ans := ans.subrange(0+1, num) ; execute (ans)->display() ; continue ) else skip ; while (puz)->includes('?') do ( if puz->first() = '?' then ( if puz[1+1] = 'R' then ( puz->first() := 'B' ) else (if puz[1+1] = 'B' then ( puz->first() := 'R' ) else skip) ) else skip ; if puz->last() = '?' then ( if puz->front()->last() = 'R' then ( puz->last() := 'B' ) else (if puz->front()->last() = 'B' then ( puz->last() := 'R' ) else skip) ) else skip ; try ( for j : Integer.subrange(puz->indexOf('?') - 1, num - 1-1) do ( if puz[j+1] = '?' then ( if puz[j + 1+1] = 'R' then ( puz[j+1] := 'B' ) else (if puz[j + 1+1] = 'B' then ( puz[j+1] := 'R' ) else skip) ) else skip ; if puz[j+1] = '?' & j > 0 then ( if puz[j - 1+1] = 'R' then ( puz[j+1] := 'B' ) else (if puz[j - 1+1] = 'B' then ( puz[j+1] := 'R' ) else skip) ) else skip)) catch (_e : OclException) do ( break) ) ; ans := StringLib.sumStringsWithSeparator((puz), '') ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def reversingString(str,start,end): while(startdisplay();; operation reversingString(OclType["String"] : OclAny, start : OclAny, end : OclAny) pre: true post: true activity: while ((start->compareTo(end)) < 0) do ( OclType["String"] := (("" + (.subrange(1,start))) + (MathLib.bitwiseXor((("" + ([start+1])))->char2byte(), (("" + ([end+1])))->char2byte()))->byte2char() + ("" + (.subrange(start + 1+1)))); ; OclType["String"] := (("" + (.subrange(1,end))) + (MathLib.bitwiseXor((("" + ([start+1])))->char2byte(), (("" + ([end+1])))->char2byte()))->byte2char() + ("" + (.subrange(end + 1+1)))); ; OclType["String"] := (("" + (.subrange(1,start))) + (MathLib.bitwiseXor((("" + ([start+1])))->char2byte(), (("" + ([end+1])))->char2byte()))->byte2char() + ("" + (.subrange(start + 1+1)))); ; start := start + 1; ; end := end - 1;) ; return OclType["String"];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b=map(int,input().split()) red=2*a green=5*a blue=8*a book=0 if red % b==0 : book+=(red//b) else : book+=((red//b)+1) if green % b==0 : book+=(green//b) else : book+=((green//b)+1) if blue % b==0 : book+=(blue//b) else : book+=((blue//b)+1) print(book) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var red : double := 2 * a ; var green : double := 5 * a ; var blue : double := 8 * a ; var book : int := 0 ; if red mod b = 0 then ( book := book + (red div b) ) else ( book := book + ((red div b) + 1) ) ; if green mod b = 0 then ( book := book + (green div b) ) else ( book := book + ((green div b) + 1) ) ; if blue mod b = 0 then ( book := book + (blue div b) ) else ( book := book + ((blue div b) + 1) ) ; execute (book)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) def check(x): b=n r=0 y=0 D=[0]*(2*n+1) for i in range(n): D[b]+=1 if a[i]c//2 : break else : l,m=m,(m+r)//2 else : m,r=(m+l)//2,m+1 print(alpha[m]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; var alpha : Sequence := a->sort() ; var l : OclAny := null; Sequence{l,r} := Sequence{0,n} ; var m : OclAny := null; var c : OclAny := null; Sequence{m,c} := Sequence{n div 2,n * (n + 1) div 2} ; while true do ( if (check(alpha[m+1])->compareTo(c div 2)) <= 0 then ( if m = n - 1 then ( break ) else (if (check(alpha[m + 1+1])->compareTo(c div 2)) > 0 then ( break ) else ( var l : OclAny := null; var m : OclAny := null; Sequence{l,m} := Sequence{m,(m + r) div 2} ) ) ) else ( var m : OclAny := null; Sequence{m,r} := Sequence{(m + l) div 2,m + 1} )) ; execute (alpha[m+1])->display(); operation check(x : OclAny) : OclAny pre: true post: true activity: var b : int := n ; var r : int := 0 ; var y : int := 0 ; var D : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * n + 1)) ; for i : Integer.subrange(0, n-1) do ( D[b+1] := D[b+1] + 1 ; if (a[i+1]->compareTo(x)) < 0 then ( r := r + D[b+1] ; b := b + 1 ) else ( b := b - 1 ; r := r - D[b+1] ) ; y := y + r) ; return y; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) red=2*n green=5*n blue=8*n s=0 if red % k==0 : r1=red//k else : r1=red//k+1 if green % k==0 : g1=green//k else : g1=green//k+1 if blue % k==0 : b1=blue//k else : b1=blue//k+1 print(r1+g1+b1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var red : double := 2 * n ; var green : double := 5 * n ; var blue : double := 8 * n ; var s : int := 0 ; if red mod k = 0 then ( var r1 : int := red div k ) else ( r1 := red div k + 1 ) ; if green mod k = 0 then ( var g1 : int := green div k ) else ( g1 := green div k + 1 ) ; if blue mod k = 0 then ( var b1 : int := blue div k ) else ( b1 := blue div k + 1 ) ; execute (r1 + g1 + b1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) d=0 a=2*n b=5*n c=8*n if(a % k!=0): d+=(a//k)+1 elif(a % k==0): d+=a//k if(b % k!=0): d+=(b//k)+1 elif(b % k==0): d+=b//k if(c % k!=0): d+=(c//k)+1 elif(c % k==0): d+=c//k print(d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : int := 0 ; var a : double := 2 * n ; var b : double := 5 * n ; var c : double := 8 * n ; if (a mod k /= 0) then ( d := d + (a div k) + 1 ) else (if (a mod k = 0) then ( d := d + a div k ) else skip) ; if (b mod k /= 0) then ( d := d + (b div k) + 1 ) else (if (b mod k = 0) then ( d := d + b div k ) else skip) ; if (c mod k /= 0) then ( d := d + (c div k) + 1 ) else (if (c mod k = 0) then ( d := d + c div k ) else skip) ; execute (d)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=input().split() n=int(n) k=int(k) if n*2 % k!=0 : red=n*2//k+1 else : red=n*2//k if n*5 % k!=0 : green=n*5//k+1 else : green=n*5//k if n*8 % k!=0 : blue=n*8//k+1 else : blue=n*8//k print(red+green+blue) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var k : int := ("" + ((k)))->toInteger() ; if n * 2 mod k /= 0 then ( var red : int := n * 2 div k + 1 ) else ( red := n * 2 div k ) ; if n * 5 mod k /= 0 then ( var green : int := n * 5 div k + 1 ) else ( green := n * 5 div k ) ; if n * 8 mod k /= 0 then ( var blue : int := n * 8 div k + 1 ) else ( blue := n * 8 div k ) ; execute (red + green + blue)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math nk=input() nk=nk.split() red=math.ceil(int(nk[0])*2/int(nk[1])) green=math.ceil(int(nk[0])*5/int(nk[1])) blue=math.ceil(int(nk[0])*8/int(nk[1])) print(red+green+blue) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var nk : String := (OclFile["System.in"]).readLine() ; nk := nk.split() ; var red : double := (("" + ((nk->first())))->toInteger() * 2 / ("" + ((nk[1+1])))->toInteger())->ceil() ; var green : double := (("" + ((nk->first())))->toInteger() * 5 / ("" + ((nk[1+1])))->toInteger())->ceil() ; var blue : double := (("" + ((nk->first())))->toInteger() * 8 / ("" + ((nk[1+1])))->toInteger())->ceil() ; execute (red + green + blue)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def factorial(start,end): res=1 for i in range(start,end+1): res*=i return res def sumofsquare(n): return int(factorial(n+1,2*n)/factorial(1,n)) n=4 print(sumofsquare(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 4 ; execute (sumofsquare(n))->display(); operation factorial(start : OclAny, end : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; for i : Integer.subrange(start, end + 1-1) do ( res := res * i) ; return res; operation sumofsquare(n : OclAny) : OclAny pre: true post: true activity: return ("" + ((factorial(n + 1, 2 * n) / factorial(1, n))))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def numberOfTriangles(n): answer=[None]*(n+1); answer[0]=1 ; i=1 while i<=n : answer[i]=answer[i-1]*3+2 ; i=i+1 return answer[n]; n=2 print(numberOfTriangles(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 2 ; execute (numberOfTriangles(n))->display(); operation numberOfTriangles(n : OclAny) pre: true post: true activity: var answer : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, (n + 1)); ; answer->first() := 1; ; var i : int := 1 ; while (i->compareTo(n)) <= 0 do ( answer[i+1] := answer[i - 1+1] * 3 + 2; ; i := i + 1) ; return answer[n+1];; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def smallestFreq(S1,S2): banned=defaultdict(lambda : 0) i=0 while ifreq or(result[s]==freq and sdisplay() ) else skip; operation smallestFreq(S1 : OclAny, S2 : OclAny) : OclAny pre: true post: true activity: var banned : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; var i : int := 0 ; while (i->compareTo((S2)->size())) < 0 do ( var s : String := "" ; while (i->compareTo((S2)->size())) < 0 & S2[i+1] /= ' ' do ( s := s + S2[i+1] ; i := i + 1) ; i := i + 1 ; banned->at(s) := banned->at(s) + 1) ; var result : OclAny := defaultdict(lambda $$ : OclAny in (0)) ; var ans : String := "" ; var freq : int := 0 ; i := 0 ; while (i->compareTo((S1)->size())) < 0 do ( s := "" ; while (i->compareTo((S1)->size())) < 0 & S1[i+1] /= ' ' do ( s := s + S1[i+1] ; i := i + 1) ; i := i + 1 ; if banned->at(s) = 0 then ( result->at(s) := result->at(s) + 1 ; if ((result->at(s)->compareTo(freq)) > 0 or (result->at(s) = freq & s < ans)) then ( ans := s ; freq := result->at(s) ) else skip ) else skip) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import division from gcj import* FLAGS='' def case(): N,=ints() titles=[line().split()for i in range(N)] for t in titles : a,b=t t[:]=['a:'+a,'b:'+b] pprint(titles) source=0 sink=1 node2id=dict(source=source,sink=sink) wordcounts={} for a,b in titles : for x in a,b : node2id.setdefault(x,len(node2id)) wordcounts.setdefault(x,0) wordcounts[x]+=1 pprint(node2id) pprint(wordcounts) N=len(node2id) capacity=[[0]*N for i in range(N)] for word,count in wordcounts.items(): if word.startswith('a'): capacity[source][node2id[word]]=count-1 else : capacity[node2id[word]][sink]=count-1 for a,b in titles : assert capacity[node2id[a]][node2id[b]]==0 capacity[node2id[a]][node2id[b]]=1 def dfs(pos,visited): if pos==sink : return True for t in range(N): if capacity[pos][t]: if t in visited : continue visited.add(t) capacity[pos][t]-=1 capacity[t][pos]+=1 res=dfs(t,visited) if res : return res capacity[t][pos]-=1 capacity[pos][t]+=1 n=0 while True : res=dfs(source,set()) if not res : break n+=1 return n if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var FLAGS : String := '' ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation case() : OclAny pre: true post: true activity: (testlist_star_expr (test (logical_test (comparison (expr (atom (name N)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name N)))))) ,)} := ints() ; var titles : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (line().split())) ; for t : titles do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := t ; t := Sequence{'a:' + a}->union(Sequence{ 'b:' + b })) ; pprint(titles) ; var source : int := 0 ; var sink : int := 1 ; var node2id : Map := ((arglist (argument (test (logical_test (comparison (expr (atom (name source)))))) = (test (logical_test (comparison (expr (atom (name source))))))) , (argument (test (logical_test (comparison (expr (atom (name sink)))))) = (test (logical_test (comparison (expr (atom (name sink))))))))) ; var wordcounts : OclAny := Set{} ; for _tuple : titles do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); for x : a, b do ( node2id.setdefault(x, (node2id)->size()) ; wordcounts.setdefault(x, 0) ; wordcounts[x+1] := wordcounts[x+1] + 1)) ; pprint(node2id) ; pprint(wordcounts) ; var N : int := (node2id)->size() ; var capacity : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, N))) ; for _tuple : wordcounts->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var word : OclAny := _tuple->at(_indx); _indx := _indx + 1; var count : OclAny := _tuple->at(_indx); if word->hasPrefix('a') then ( capacity[source+1][node2id[word+1]+1] := count - 1 ) else ( capacity[node2id[word+1]+1][sink+1] := count - 1 )) ; for _tuple : titles do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); assert capacity[node2id[a+1]+1][node2id[b+1]+1] = 0 do "assertion failed" ; capacity[node2id[a+1]+1][node2id[b+1]+1] := 1) ; skip ; var n : int := 0 ; while true do ( res := dfs(source, Set{}->union(())) ; if not(res) then ( break ) else skip ; n := n + 1) ; return n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import heapq import bisect import operator from itertools import* def read(): return int(input()) def reads(): return[int(s)for s in input().split()] T=read() for case in range(1,T+1): N=read() G=dict() V=set() for _ in range(N): (S,T)=input().split() V.add((S,0)); V.add((T,1)) if not(S,0)in G : G[(S,0)]=[] G[(S,0)].append((T,1)) if not(T,1)in G : G[(T,1)]=[] G[(T,1)].append((S,0)) res=0 match={v :-1 for v in V} def dfs(v,used): used[v]=True for u in G[v]: w=match[u] if(w==-1)or(not used[w])and dfs(w,used): match[v]=u match[u]=v return True return False for v in V : if match[v]==-1 : used={v : 0 for v in V} if dfs(v,used): res+=1 result=N-(res+sum(match[v]==-1 for v in V)) print("Case #{0}:{1}".format(case,result)) ------------------------------------------------------------ OCL File: --------- class FromPython { suite`nestedAttributeDefinitions operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; var T : OclAny := read() ; for case : Integer.subrange(1, T + 1-1) do ( var N : OclAny := read() ; var G : Map := (arguments ( )) ; var V : Set := Set{}->union(()) ; for _anon : Integer.subrange(0, N-1) do (suite)) ; var Sequence{S, T} : OclAny := input().split(); operation read() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation reads() : OclAny pre: true post: true activity: return input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printDistinct(arr,n): s=dict(); for i in range(n): if(arr[i]not in s.keys()): s[arr[i]]=arr[i]; print(arr[i],end=" "); arr=[10,5,3,4,3,5,6]; n=7 ; printDistinct(arr,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{10}->union(Sequence{5}->union(Sequence{3}->union(Sequence{4}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 6 })))))); ; n := 7; ; printDistinct(arr, n);; operation printDistinct(arr : OclAny, n : OclAny) pre: true post: true activity: var s : Map := (arguments ( )); ; for i : Integer.subrange(0, n-1) do ( if ((s.keys())->excludes(arr[i+1])) then ( s[arr[i+1]+1] := arr[i+1]; ; execute (arr[i+1])->display(); ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from itertools import accumulate def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) class BIT : def __init__(self,init_value): self.n=len(init_value) self.tree=[0]*(self.n+1) for i in range(1,self.n+1): x=init_value[i-1] while i<=self.n : self.tree[i]+=x i+=i &(-i) def update(self,i,x): while i<=self.n : self.tree[i]+=x i+=i &(-i) return def query(self,i): res=0 while i>0 : res+=self.tree[i] i-=i &(-i) return res N=I() A=LI() def f(x): B=[0]+[1 if A[i]>=x else-1 for i in range(N)] B=list(accumulate(B)) B=[b+N+1 for b in B] bit=BIT([0]*(2*N+2)) count=0 for i in range(N+1): b=B[i] count+=bit.query(b) bit.update(b,1) if count>=(N*(N+1)+3)//4 : return True return False ok=1 ng=10**9+1 while ok+1exists( _x | result = _x ); attribute n : int := (init_value)->size(); attribute tree : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (self.n + 1)); operation initialise(init_value : OclAny) : BIT pre: true post: true activity: self.n := (init_value)->size() ; self.tree := MatrixLib.elementwiseMult(Sequence{ 0 }, (self.n + 1)) ; for i : Integer.subrange(1, self.n + 1-1) do ( var x : OclAny := init_value[i - 1+1] ; while (i->compareTo(self.n)) <= 0 do ( self.tree[i+1] := self.tree[i+1] + x ; i := i + MathLib.bitwiseAnd(i, (-i)))); return self; operation update(i : OclAny,x : OclAny) pre: true post: true activity: while (i->compareTo(self.n)) <= 0 do ( self.tree[i+1] := self.tree[i+1] + x ; i := i + MathLib.bitwiseAnd(i, (-i))) ; return; operation query(i : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; while i > 0 do ( res := res + self.tree[i+1] ; i := i - MathLib.bitwiseAnd(i, (-i))) ; return res; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; var N : OclAny := I() ; var A : OclAny := LI() ; skip ; var ok : int := 1 ; var ng : double := (10)->pow(9) + 1 ; while (ok + 1->compareTo(ng)) < 0 do ( var mid : int := (ok + ng) div 2 ; if f(mid) then ( ok := mid ) else ( ng := mid )) ; execute (ok)->display(); operation I() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.readLine().rstrip())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) )); operation f(x : OclAny) : OclAny pre: true post: true activity: var B : Sequence := Sequence{ 0 }->union(Integer.subrange(0, N-1)->select(i | true)->collect(i | (if (A[i+1]->compareTo(x)) >= 0 then 1 else -1 endif))) ; B := (accumulate(B)) ; B := B->select(b | true)->collect(b | (b + N + 1)) ; var bit : BIT := (BIT.newBIT()).initialise(MatrixLib.elementwiseMult(Sequence{ 0 }, (2 * N + 2))) ; var count : int := 0 ; for i : Integer.subrange(0, N + 1-1) do ( var b : OclAny := B[i+1] ; count := count + bit.query(b) ; execute ((b, 1) <: bit)) ; if (count->compareTo((N * (N + 1) + 3) div 4)) >= 0 then ( return true ) else skip ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import re import bipartite_matching input_file=open(sys.argv[1],'r') nb_tests=int(input_file.readline()) for i in range(nb_tests): nb_titles=int(input_file.readline()) titles={} first_titles=set({}) second_titles=set({}) for j in range(nb_titles): title=input_file.readline()[:-1].split('') first_titles=first_titles |{title[0]} second_titles=second_titles |{title[1]} if title[0]in titles : titles[title[0]].append(title[1]) else : titles[title[0]]=[title[1]] matching=bipartite_matching.bipartiteMatch(titles)[0] len_m=len(matching) len_f=len(first_titles) len_s=len(second_titles) cover=len_f+len_s-len_m print('Case #',i+1,': ',nb_titles-cover,sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input_file : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) ; var nb_tests : int := ("" + ((input_file.readLine())))->toInteger() ; for i : Integer.subrange(0, nb_tests-1) do ( var nb_titles : int := ("" + ((input_file.readLine())))->toInteger() ; var titles : OclAny := Set{} ; var first_titles : Set := Set{}->union((Set{})) ; var second_titles : Set := Set{}->union((Set{})) ; for j : Integer.subrange(0, nb_titles-1) do ( var title : OclAny := input_file.readLine()->front().split('') ; first_titles := MathLib.bitwiseOr(first_titles, Set{ title->first() }) ; second_titles := MathLib.bitwiseOr(second_titles, Set{ title[1+1] }) ; if (titles)->includes(title->first()) then ( (expr (atom (name titles)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name title)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name title)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) )))) ) else ( titles[title->first()+1] := Sequence{ title[1+1] } )) ; var matching : OclAny := bipartite_matching.bipartiteMatch(titles)->first() ; var len_m : int := (matching)->size() ; var len_f : int := (first_titles)->size() ; var len_s : int := (second_titles)->size() ; var cover : double := len_f + len_s - len_m ; execute ('Case #')->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def DFS(G,U,V,x): V[x]=True for y in G[x]: if U[y]==-1 or(not V[U[y]]and DFS(G,U,V,U[y])): U[y]=x return True return False def maximum_matching(G,na,nb): U=[-1]*nb size=0 for i in range(na): V=[False]*na if DFS(G,U,V,i): size+=1 return size def get_index(M,x): if x in M : return M[x] y=len(M) M[x]=y return y def solve(): m=int(input()) MA={} MB={} E=[] for _ in range(m): a,b=input().split() xa=get_index(MA,a) xb=get_index(MB,b) E.append((xa,xb)) G=[[]for _ in range(len(MA))] for u,v in E : G[u].append(v) return m-len(MA)-len(MB)+maximum_matching(G,len(MA),len(MB)) t=int(input()) for i in range(t): print('Case #{}:{}'.format(i+1,solve())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( execute (StringLib.interpolateStrings('Case #{}:{}', Sequence{i + 1, solve()}))->display()); operation DFS(G : OclAny, U : OclAny, V : OclAny, x : OclAny) : OclAny pre: true post: true activity: V[x+1] := true ; for y : G[x+1] do ( if U[y+1] = -1 or (not(V[U[y+1]+1]) & DFS(G, U, V, U[y+1])) then ( U[y+1] := x ; return true ) else skip) ; return false; operation maximum_matching(G : OclAny, na : OclAny, nb : OclAny) : OclAny pre: true post: true activity: U := MatrixLib.elementwiseMult(Sequence{ -1 }, nb) ; var size : int := 0 ; for i : Integer.subrange(0, na-1) do ( V := MatrixLib.elementwiseMult(Sequence{ false }, na) ; if DFS(G, U, V, i) then ( size := size + 1 ) else skip) ; return size; operation get_index(M : OclAny, x : OclAny) : OclAny pre: true post: true activity: if (M)->includes(x) then ( return M[x+1] ) else skip ; var y : int := (M)->size() ; M[x+1] := y ; return y; operation solve() : OclAny pre: true post: true activity: var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var MA : OclAny := Set{} ; var MB : OclAny := Set{} ; var E : Sequence := Sequence{} ; for _anon : Integer.subrange(0, m-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := input().split() ; var xa : OclAny := get_index(MA, a) ; var xb : OclAny := get_index(MB, b) ; execute ((Sequence{xa, xb}) : E)) ; G := Integer.subrange(0, (MA)->size()-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _tuple : E do (var _indx : int := 1; var u : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) ))))) ; return m - (MA)->size() - (MB)->size() + maximum_matching(G, (MA)->size(), (MB)->size()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dfs(e,ma,u,v): if v in u : return False u[v]=True for x in e[v]: if(not x in ma)or dfs(e,ma,u,ma[x]): ma[x]=v return True return False def solve(): n=int(input()) e={} av={} bv={} ac=0 bc=0 for i in range(n): a,b=list(input().split()) if not a in e : e[a]=[] e[a].append(b) if not a in av : av[a]=True ac+=1 if not b in bv : bv[b]=True bc+=1 m=0 ma={} for a in av : u={} if dfs(e,ma,u,a): m+=1 return str(n-(ac+bc-m)) nt=int(input()) for tt in range(nt): print('Case #'+str(tt+1)+': '+str(solve())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var nt : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for tt : Integer.subrange(0, nt-1) do ( execute ('Case #' + ("" + ((tt + 1))) + ': ' + ("" + ((solve()))))->display()); operation dfs(e : OclAny, ma : OclAny, u : OclAny, v : OclAny) : OclAny pre: true post: true activity: if (u)->includes(v) then ( return false ) else skip ; u[v+1] := true ; for x : e[v+1] do ( if (not((ma)->includes(x))) or dfs(e, ma, u, ma[x+1]) then ( ma[x+1] := v ; return true ) else skip) ; return false; operation solve() : OclAny pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; e := Set{} ; var av : OclAny := Set{} ; var bv : OclAny := Set{} ; var ac : int := 0 ; var bc : int := 0 ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split()) ; if not((e)->includes(a)) then ( e[a+1] := Sequence{} ) else skip ; (expr (atom (name e)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name a)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name b)))))))) )))) ; if not((av)->includes(a)) then ( av[a+1] := true ; ac := ac + 1 ) else skip ; if not((bv)->includes(b)) then ( bv[b+1] := true ; bc := bc + 1 ) else skip) ; var m : int := 0 ; ma := Set{} ; for a : av do ( u := Set{} ; if dfs(e, ma, u, a) then ( m := m + 1 ) else skip) ; return ("" + ((n - (ac + bc - m)))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minimumFlip(s,x,y): s=s+s isOpposite=False if(x>y): temp=y y=x ; x=temp isOpposite=True valClockwise=0 cur=s[x] for i in range(x,y+1,1): if(s[i]!=cur): cur=s[i] valClockwise+=1 valAnticlockwise=0 cur=s[y] x+=len(s)-1 for i in range(y,x+1,1): if(s[i]!=cur): cur=s[i] valAnticlockwise+=1 if(valClockwise<=valAnticlockwise): if(isOpposite==False): print("Clockwise",valClockwise) else : print("Anti-clockwise",valAnticlockwise) else : if(isOpposite==False): print("Anti-clockwise",valAnticlockwise) else : print("Clockwise",valClockwise) if __name__=='__main__' : x=0 y=8 s="000110" minimumFlip(s,x,y) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( x := 0 ; y := 8 ; s := "000110" ; minimumFlip(s, x, y) ) else skip; operation minimumFlip(s : OclAny, x : OclAny, y : OclAny) pre: true post: true activity: s := s + s ; var isOpposite : boolean := false ; if ((x->compareTo(y)) > 0) then ( var temp : OclAny := y ; y := x; ; x := temp ; isOpposite := true ) else skip ; var valClockwise : int := 0 ; var cur : OclAny := s[x+1] ; for i : Integer.subrange(x, y + 1-1)->select( $x | ($x - x) mod 1 = 0 ) do ( if (s[i+1] /= cur) then ( cur := s[i+1] ; valClockwise := valClockwise + 1 ) else skip) ; var valAnticlockwise : int := 0 ; cur := s[y+1] ; x := x + (s)->size() - 1 ; for i : Integer.subrange(y, x + 1-1)->select( $x | ($x - y) mod 1 = 0 ) do ( if (s[i+1] /= cur) then ( cur := s[i+1] ; valAnticlockwise := valAnticlockwise + 1 ) else skip) ; if ((valClockwise->compareTo(valAnticlockwise)) <= 0) then ( if (isOpposite = false) then ( execute ("Clockwise")->display() ) else ( execute ("Anti-clockwise")->display() ) ) else ( if (isOpposite = false) then ( execute ("Anti-clockwise")->display() ) else ( execute ("Clockwise")->display() ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printRepeating(arr,size): print("The repeating elements are: ") for i in range(0,size): if arr[abs(arr[i])]>=0 : arr[abs(arr[i])]=-arr[abs(arr[i])] else : print(abs(arr[i]),end=" ") arr=[1,2,3,1,3,6,6] arr_size=len(arr) printRepeating(arr,arr_size) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{1}->union(Sequence{3}->union(Sequence{6}->union(Sequence{ 6 })))))) ; var arr_size : int := (arr)->size() ; printRepeating(arr, arr_size); operation printRepeating(arr : OclAny, size : OclAny) pre: true post: true activity: execute ("The repeating elements are: ")->display() ; for i : Integer.subrange(0, size-1) do ( if arr[(arr[i+1])->abs()+1] >= 0 then ( arr[(arr[i+1])->abs()+1] := -arr[(arr[i+1])->abs()+1] ) else ( execute ((arr[i+1])->abs())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printRepeating(arr,size): print(" The repeating elements are",end=" ") for i in range(0,size): if(arr[abs(arr[i])]>0): arr[abs(arr[i])]=(-1)*arr[abs(arr[i])] else : print(abs(arr[i]),end=" ") arr=[4,2,4,5,2,3,1] arr_size=len(arr) printRepeating(arr,arr_size) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{4}->union(Sequence{2}->union(Sequence{4}->union(Sequence{5}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 1 })))))) ; var arr_size : int := (arr)->size() ; printRepeating(arr, arr_size); operation printRepeating(arr : OclAny, size : OclAny) pre: true post: true activity: execute (" The repeating elements are")->display() ; for i : Integer.subrange(0, size-1) do ( if (arr[(arr[i+1])->abs()+1] > 0) then ( arr[(arr[i+1])->abs()+1] := (-1) * arr[(arr[i+1])->abs()+1] ) else ( execute ((arr[i+1])->abs())->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k,b,n,t=map(int,input().split()) x=1 a=0 flag=False for _ in range(n): z=k*x+b x=z a+=1 if z>t : flag=True break if flag : print(n-a+1) else : print(n-a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : OclAny := null; var b : OclAny := null; var n : OclAny := null; var t : OclAny := null; Sequence{k,b,n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : int := 1 ; var a : int := 0 ; var flag : boolean := false ; for _anon : Integer.subrange(0, n-1) do ( var z : double := k * x + b ; x := z ; a := a + 1 ; if (z->compareTo(t)) > 0 then ( flag := true ; break ) else skip) ; if flag then ( execute (n - a + 1)->display() ) else ( execute (n - a)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k,b,n,t=map(int,input().split()) z=1 res=n for i in range(n): z=(k*z)+b if z<=t : res-=1 else : break print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : OclAny := null; var b : OclAny := null; var n : OclAny := null; var t : OclAny := null; Sequence{k,b,n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var z : int := 1 ; var res : OclAny := n ; for i : Integer.subrange(0, n-1) do ( z := (k * z) + b ; if (z->compareTo(t)) <= 0 then ( res := res - 1 ) else ( break )) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k,b,n,t=[int(x)for x in input().split(" ")] z=1 while k*z+b<=t : z=k*z+b n-=1 print(max(n,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : OclAny := null; var b : OclAny := null; var n : OclAny := null; var t : OclAny := null; Sequence{k,b,n,t} := input().split(" ")->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var z : int := 1 ; while (k * z + b->compareTo(t)) <= 0 do ( z := k * z + b ; n := n - 1) ; execute (Set{n, 0}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- arrSize=51 dp=[0 for i in range(arrSize)] v=[False for i in range(arrSize)] def sumMax(i,arr,n): if(i>=n-1): return 0 if(v[i]): return dp[i] v[i]=True dp[i]=max(arr[i]+arr[i+1]+sumMax(i+3,arr,n),sumMax(i+1,arr,n)) return dp[i] if __name__=='__main__' : arr=[1,1,1,1] n=len(arr) print(sumMax(0,arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var arrSize : int := 51 ; var dp : Sequence := Integer.subrange(0, arrSize-1)->select(i | true)->collect(i | (0)) ; var v : Sequence := Integer.subrange(0, arrSize-1)->select(i | true)->collect(i | (false)) ; skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))) ; n := (arr)->size() ; execute (sumMax(0, arr, n))->display() ) else skip; operation sumMax(i : OclAny, arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: if ((i->compareTo(n - 1)) >= 0) then ( return 0 ) else skip ; if (v[i+1]) then ( return dp[i+1] ) else skip ; v[i+1] := true ; dp[i+1] := Set{arr[i+1] + arr[i + 1+1] + sumMax(i + 3, arr, n), sumMax(i + 1, arr, n)}->max() ; return dp[i+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(n,a): x=list(sorted(set(a))) n_sub_half=n*(n+1)//2//2 n_plus_minus=n*2+1 Li=0 Ri=len(x) while Ri>Li+1 : i=(Li+Ri)//2 xi=x[i] cnt_sum=[0]*n_plus_minus cumsum=0 cnt_sum[cumsum]=1 judge=0 s=0 for ak in a : if ak>=xi : cumsum+=1 s+=cnt_sum[cumsum]+1 else : cumsum-=1 s-=cnt_sum[cumsum+1]-1 cnt_sum[cumsum]+=1 judge+=s if judge>=n_sub_half : Li=i break else : Ri=i print(x[Li]) n=int(input()) a=list(map(int,input().split())) f(n,a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; f(n, a); operation f(n : OclAny, a : OclAny) pre: true post: true activity: var x : Sequence := (Set{}->union((a))->sort()) ; var n_sub_half : int := n * (n + 1) div 2 div 2 ; var n_plus_minus : double := n * 2 + 1 ; var Li : int := 0 ; var Ri : int := (x)->size() ; while (Ri->compareTo(Li + 1)) > 0 do ( var i : int := (Li + Ri) div 2 ; var xi : OclAny := x[i+1] ; var cnt_sum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n_plus_minus) ; var cumsum : int := 0 ; cnt_sum[cumsum+1] := 1 ; var judge : int := 0 ; var s : int := 0 ; (compound_stmt for (exprlist (expr (atom (name ak)))) in (testlist (test (logical_test (comparison (expr (atom (name a))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name ak)))) >= (comparison (expr (atom (name xi))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cumsum)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name cnt_sum)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name cumsum)))))))) ]))) + (expr (atom (number (integer 1)))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cumsum)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name s)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (expr (atom (name cnt_sum)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name cumsum))) + (expr (atom (number (integer 1)))))))))) ]))) - (expr (atom (number (integer 1))))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cnt_sum)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name cumsum)))))))) ])))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name judge)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (name s))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name judge)))) >= (comparison (expr (atom (name n_sub_half))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name Li)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))))))) (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name Ri)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name i)))))))))))))))) ; execute (x[Li+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math as mt def divisibilityCheck(arr,n): s=dict() max_ele=-10**9 for i in range(n): s[arr[i]]=1 max_ele=max(max_ele,arr[i]) res=dict() for i in range(n): if(arr[i]!=0): for j in range(arr[i]*2,max_ele+1,arr[i]): if(j in s.keys()): res[j]=1 for x in res : print(x,end=" ") arr=[2,3,8,6,9,10] n=len(arr) divisibilityCheck(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr := Sequence{2}->union(Sequence{3}->union(Sequence{8}->union(Sequence{6}->union(Sequence{9}->union(Sequence{ 10 }))))) ; n := (arr)->size() ; divisibilityCheck(arr, n); operation divisibilityCheck(arr : OclAny, n : OclAny) pre: true post: true activity: var s : Map := (arguments ( )) ; var max_ele : double := (-10)->pow(9) ; for i : Integer.subrange(0, n-1) do ( s[arr[i+1]+1] := 1 ; max_ele := Set{max_ele, arr[i+1]}->max()) ; var res : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] /= 0) then ( for j : Integer.subrange(arr[i+1] * 2, max_ele + 1-1)->select( $x | ($x - arr[i+1] * 2) mod arr[i+1] = 0 ) do ( if ((s.keys())->includes(j)) then ( res[j+1] := 1 ) else skip) ) else skip) ; for x : res->keys() do ( execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class newNode : def __init__(self,data): self.data=data ; self.left=None ; self.right=None ; def sumOfNodesAtNthLevel(root,k): if(root==None): return 0 ; que=[]; que.append(root); level=0 ; sum=0 ; flag=0 ; while(len(que)!=0): size=len(que); while(size!=0): size-=1 ; ptr=que[0]; que.pop(0); if(level==k): flag=1 ; sum+=ptr.data ; else : if(ptr.left): que.append(ptr.left); if(ptr.right): que.append(ptr.right); level+=1 ; if(flag==1): break ; return sum ; if __name__=="__main__" : root=newNode(50); root.left=newNode(30); root.right=newNode(70); root.left.left=newNode(20); root.left.right=newNode(40); root.right.left=newNode(60); level=2 ; result=sumOfNodesAtNthLevel(root,level); print(result); ------------------------------------------------------------ OCL File: --------- class newNode { static operation newnewNode() : newNode pre: true post: newNode->exists( _x | result = _x ); operation initialise(data : OclAny) : newNode pre: true post: true activity: self.data := data; ; self.left := null; ; self.right := null;; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( root := (newNode.newnewNode()).initialise(50); ; root.left := (newNode.newnewNode()).initialise(30); ; root.right := (newNode.newnewNode()).initialise(70); ; root.left.left := (newNode.newnewNode()).initialise(20); ; root.left.right := (newNode.newnewNode()).initialise(40); ; root.right.left := (newNode.newnewNode()).initialise(60); ; level := 2; ; var result : OclAny := sumOfNodesAtNthLevel(root, level); ; execute (result)->display(); ) else skip; operation sumOfNodesAtNthLevel(root : OclAny, k : OclAny) pre: true post: true activity: if (root = null) then ( return 0; ) else skip ; var que : Sequence := Sequence{}; ; execute ((root) : que); ; var level : int := 0; ; var sum : int := 0; ; var flag : int := 0; ; while ((que)->size() /= 0) do ( var size : int := (que)->size(); ; while (size /= 0) do ( size := size - 1; ; var ptr : OclAny := que->first(); ; que := que->excludingAt(0+1); ; if (level = k) then ( flag := 1; ; sum := sum + ptr.data; ) else ( if (ptr.left) then ( execute ((ptr.left) : que); ) else skip ; if (ptr.right) then ( execute ((ptr.right) : que); ) else skip )) ; level := level + 1; ; if (flag = 1) then ( break; ) else skip) ; return sum;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def min_visible_bottles(arr,n): m=dict() ans=0 for i in range(n): m[arr[i]]=m.get(arr[i],0)+1 ans=max(ans,m[arr[i]]) print("Minimum number of","Visible Bottles are: ",ans) n=8 arr=[1,1,2,3,4,5,5,4] min_visible_bottles(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 8 ; arr := Sequence{1}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{5}->union(Sequence{ 4 }))))))) ; min_visible_bottles(arr, n); operation min_visible_bottles(arr : OclAny, n : OclAny) pre: true post: true activity: var m : Map := (arguments ( )) ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( m[arr[i+1]+1] := m.get(arr[i+1], 0) + 1 ; ans := Set{ans, m[arr[i+1]+1]}->max()) ; execute ("Minimum number of")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSubstrings(s,k): ans=0 n=len(s) for i in range(n): cnt=[0]*26 for j in range(i,n): cnt[ord(s[j])-ord('a')]+=1 if(cnt[ord(s[j])-ord('a')]<=k): ans+=1 else : break return ans if __name__=="__main__" : S="aaabb" k=2 print(findSubstrings(S,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var S : String := "aaabb" ; k := 2 ; execute (findSubstrings(S, k))->display() ) else skip; operation findSubstrings(s : OclAny, k : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; var n : int := (s)->size() ; for i : Integer.subrange(0, n-1) do ( var cnt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26) ; for j : Integer.subrange(i, n-1) do ( cnt[(s[j+1])->char2byte() - ('a')->char2byte()+1] := cnt[(s[j+1])->char2byte() - ('a')->char2byte()+1] + 1 ; if ((cnt[(s[j+1])->char2byte() - ('a')->char2byte()+1]->compareTo(k)) <= 0) then ( ans := ans + 1 ) else ( break ))) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ___gcd(a,b): if(a==0 or b==0): return 0 if(a==b): return a if(a>b): return ___gcd(a-b,b) return ___gcd(a,b-a) def lcmOfArray(arr,n): ans=arr[0] for i in range(1,n): ans=(arr[i]*ans)/___gcd(arr[i],ans) return ans def checkArray(arr,prime,n,m): lcm=lcmOfArray(arr,n) for i in range(n): val=lcm/arr[i] for j in range(m and val!=1): while(val % prime[j]==0): val=val/prime[j] if(val!=1): return 0 return 1 arr=[50,200] prime=[2,3] n=len(arr) m=len(prime) if(checkArray(arr,prime,n,m)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; arr := Sequence{50}->union(Sequence{ 200 }) ; prime := Sequence{2}->union(Sequence{ 3 }) ; n := (arr)->size() ; m := (prime)->size() ; if (checkArray(arr, prime, n, m)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation ___gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0 or b = 0) then ( return 0 ) else skip ; if (a = b) then ( return a ) else skip ; if ((a->compareTo(b)) > 0) then ( return ___gcd(a - b, b) ) else skip ; return ___gcd(a, b - a); operation lcmOfArray(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : OclAny := arr->first() ; for i : Integer.subrange(1, n-1) do ( ans := (arr[i+1] * ans) / ___gcd(arr[i+1], ans)) ; return ans; operation checkArray(arr : OclAny, prime : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var lcm : OclAny := lcmOfArray(arr, n) ; for i : Integer.subrange(0, n-1) do ( var val : double := lcm / arr[i+1] ; for j : Integer.subrange(0, m & val /= 1-1) do ( while (val mod prime[j+1] = 0) do ( val := val / prime[j+1])) ; if (val /= 1) then ( return 0 ) else skip) ; return 1; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=1000000 prime=[True]*(MAX+1) sum=[0]*(MAX+1) def SieveOfEratosthenes(): prime[1]=False p=2 while p*p<=MAX : if(prime[p]): i=p*2 while i<=MAX : prime[i]=False i+=p p+=1 for i in range(1,MAX+1): if(prime[i]==True): sum[i]=1 sum[i]+=sum[i-1] if __name__=="__main__" : SieveOfEratosthenes() l=3 r=9 c=(sum[r]-sum[l-1]) print("Count:",c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 1000000 ; var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (MAX + 1)) ; var sum : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (MAX + 1)) ; skip ; if __name__ = "__main__" then ( SieveOfEratosthenes() ; var l : int := 3 ; var r : int := 9 ; var c : double := ([r+1]->sum() - [l - 1+1]->sum()) ; execute ("Count:")->display() ) else skip; operation SieveOfEratosthenes() pre: true post: true activity: prime[1+1] := false ; var p : int := 2 ; while (p * p->compareTo(MAX)) <= 0 do ( if (prime[p+1]) then ( var i : int := p * 2 ; while (i->compareTo(MAX)) <= 0 do ( prime[i+1] := false ; i := i + p) ) else skip ; p := p + 1) ; for i : Integer.subrange(1, MAX + 1-1) do ( if (prime[i+1] = true) then ( [i+1]->sum() := 1 ) else skip ; [i+1]->sum() := [i+1]->sum() + [i - 1+1]->sum()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=int(input()) c=list(map(int,input().split())) hired=0 unthreated=0 for i in c : if i>0 : hired+=i continue if i<0 and hired>0 : hired-=1 continue if i<0 : unthreated+=1 print(unthreated) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var hired : int := 0 ; var unthreated : int := 0 ; for i : c do ( if i > 0 then ( hired := hired + i ; continue ) else skip ; if i < 0 & hired > 0 then ( hired := hired - 1 ; continue ) else skip ; if i < 0 then ( unthreated := unthreated + 1 ) else skip) ; execute (unthreated)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def policeRecruits(): n=int(input()) result=[int(i)for i in input().split()] res=0 total=0 for i in range(n): total+=result[i] if(total<0): res-=total total=0 print(res) return policeRecruits() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; policeRecruits(); operation policeRecruits() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var result : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var res : int := 0 ; var total : int := 0 ; for i : Integer.subrange(0, n-1) do ( total := total + result[i+1] ; if (total < 0) then ( res := res - total ; total := 0 ) else skip) ; execute (res)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n_=input() n=input().split() s1=0 s2=0 for i in n : if i=='-1' : if s1-1<0 : s2+=1 elif s1-1>=0 : s1-=1 if i!='-1' : s1+=int(i) print(s2) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n_ : String := (OclFile["System.in"]).readLine() ; var n : OclAny := input().split() ; var s1 : int := 0 ; var s2 : int := 0 ; for i : n do ( if i = '-1' then ( if s1 - 1 < 0 then ( s2 := s2 + 1 ) else (if s1 - 1 >= 0 then ( s1 := s1 - 1 ) else skip) ) else skip ; if i /= '-1' then ( s1 := s1 + ("" + ((i)))->toInteger() ) else skip) ; execute (s2)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- length,myList=int(input()),list(map(int,input().split())) counter=police=0 for i in myList : if i>0 : police+=i elif i<0 : if police>0 : police+=i else : counter+=1 print(counter) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var length : OclAny := null; var myList : OclAny := null; Sequence{length,myList} := Sequence{("" + (((OclFile["System.in"]).readLine())))->toInteger(),((input().split())->collect( _x | (OclType["int"])->apply(_x) ))} ; var counter : OclAny := 0; var police : int := 0 ; for i : myList do ( if i > 0 then ( police := police + i ) else (if i < 0 then ( if police > 0 then ( police := police + i ) else ( counter := counter + 1 ) ) else skip)) ; execute (counter)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) a=list(map(int,input().split())) assert len(a)==N def mergesort(S,f,t,T=None): if t-f<=1 : return 0 if T==None : T=[0]*len(S) mid=(f+t)//2 n1=mergesort(S,f,mid,T) n2=mergesort(S,mid,t,T) n=n1+n2 i=f j=mid k=f while i=t or S[i]<=S[j]: T[k]=S[i] i+=1 n+=t-j else : T[k]=S[j] j+=1 k+=1 for i in range(f,k): S[i]=T[i] return n def n_median_larger_than_or_equal_to(x): b=[-1 if e=(ncomb+1)//2 : lo=mid else : hi=mid-1 print(lo) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; assert (a)->size() = N do "assertion failed" ; skip ; skip ; var lo : int := 1 ; var hi : OclAny := (a)->max() ; var ncomb : int := N * (N + 1) div 2 ; while (lo->compareTo(hi)) < 0 do ( mid := (lo + hi + 1) div 2 ; var nm : OclAny := n_median_larger_than_or_equal_to(mid) ; if (nm->compareTo((ncomb + 1) div 2)) >= 0 then ( lo := mid ) else ( hi := mid - 1 )) ; execute (lo)->display(); operation mergesort(S : OclAny, f : OclAny, t : OclAny, T : OclAny) : OclAny pre: true post: true activity: if T->oclIsUndefined() then T := null else skip; if t - f <= 1 then ( return 0 ) else skip ; if T = null then ( T := MatrixLib.elementwiseMult(Sequence{ 0 }, (S)->size()) ) else skip ; var mid : int := (f + t) div 2 ; var n1 : OclAny := mergesort(S, f, mid, T) ; var n2 : OclAny := mergesort(S, mid, t, T) ; var n : OclAny := n1 + n2 ; var i : OclAny := f ; var j : int := mid ; var k : OclAny := f ; while (i->compareTo(mid)) < 0 do ( if (j->compareTo(t)) >= 0 or (S[i+1]->compareTo(S[j+1])) <= 0 then ( T[k+1] := S[i+1] ; i := i + 1 ; n := n + t - j ) else ( T[k+1] := S[j+1] ; j := j + 1 ) ; k := k + 1) ; for i : Integer.subrange(f, k-1) do ( S[i+1] := T[i+1]) ; return n; operation n_median_larger_than_or_equal_to(x : OclAny) : OclAny pre: true post: true activity: var b : Sequence := a->select(e | true)->collect(e | (if (e->compareTo(x)) < 0 then -1 else 1 endif)) ; S := Sequence{ 0 } ; for e : b do ( execute ((S->last() + e) : S)) ; return mergesort(S, 0, (S)->size()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) kq=0 cs=0 a=list(map(int,input().split())) for i in range(n): if(a[i]<0): if(cs==0): kq+=1 else : cs-=1 else : cs+=a[i] print(kq) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var kq : int := 0 ; var cs : int := 0 ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, n-1) do ( if (a[i+1] < 0) then ( if (cs = 0) then ( kq := kq + 1 ) else ( cs := cs - 1 ) ) else ( cs := cs + a[i+1] )) ; execute (kq)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt,gcd def SieveOfEratosthenes(prime,p_size): prime[0]=False ; prime[1]=False ; for p in range(2,int(sqrt(p_size))+1): if(prime[p]): for i in range(2*p,p_size,p): prime[i]=False ; def gcdPrimeFreq(arr,n): prime=[True]*(n+1); SieveOfEratosthenes(prime,n+1); m=dict.fromkeys(arr,0); for i in range(n): m[arr[i]]+=1 ; __gcd=0 ; for key,value in m.items(): if(prime[value]): __gcd=gcd(__gcd,key); return __gcd ; if __name__=="__main__" : arr=[5,4,6,5,4,6]; n=len(arr); print(gcdPrimeFreq(arr,n)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{5}->union(Sequence{4}->union(Sequence{6}->union(Sequence{5}->union(Sequence{4}->union(Sequence{ 6 }))))); ; n := (arr)->size(); ; execute (gcdPrimeFreq(arr, n))->display(); ) else skip; operation SieveOfEratosthenes(prime : OclAny, p_size : OclAny) pre: true post: true activity: prime->first() := false; ; prime[1+1] := false; ; for p : Integer.subrange(2, ("" + ((sqrt(p_size))))->toInteger() + 1-1) do ( if (prime[p+1]) then ( for i : Integer.subrange(2 * p, p_size-1)->select( $x | ($x - 2 * p) mod p = 0 ) do ( prime[i+1] := false;) ) else skip); operation gcdPrimeFreq(arr : OclAny, n : OclAny) pre: true post: true activity: prime := MatrixLib.elementwiseMult(Sequence{ true }, (n + 1)); ; SieveOfEratosthenes(prime, n + 1); ; var m : Map := (trailer . (name fromkeys) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arr))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))); ; for i : Integer.subrange(0, n-1) do ( m[arr[i+1]+1] := m[arr[i+1]+1] + 1;) ; var __gcd : int := 0; ; for _tuple : m->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); if (prime[value+1]) then ( __gcd := gcd(__gcd, key); ) else skip) ; return __gcd;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printSum(a,b): res,temp1,temp2=0,0,0 while a>0 : temp1=temp1*10+(a % 10) a//=10 a=temp1 while b>0 : temp2=temp2*10+(b % 10) b//=10 b=temp2 while a : Sum=a % 10+b % 10 if Sum//10==0 : res=res*10+Sum else : temp1=0 while Sum>0 : temp1=temp1*10+(Sum % 10) Sum//=10 Sum=temp1 while Sum>0 : res=res*10+(Sum % 10) Sum//=10 a//=10 b//=10 return res if __name__=="__main__" : a,b=7752,8834 print(printSum(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{a,b} := Sequence{7752,8834} ; execute (printSum(a, b))->display() ) else skip; operation printSum(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: var res : OclAny := null; var temp1 : OclAny := null; var temp2 : OclAny := null; Sequence{res,temp1,temp2} := Sequence{0,0,0} ; while a > 0 do ( var temp1 : double := temp1 * 10 + (a mod 10) ; a := a div 10) ; a := temp1 ; while b > 0 do ( var temp2 : double := temp2 * 10 + (b mod 10) ; b := b div 10) ; b := temp2 ; while a do ( var Sum : int := a mod 10 + b mod 10 ; if Sum div 10 = 0 then ( var res : double := res * 10 + Sum ) else ( temp1 := 0 ; while Sum > 0 do ( temp1 := temp1 * 10 + (Sum mod 10) ; Sum := Sum div 10) ; Sum := temp1 ; while Sum > 0 do ( res := res * 10 + (Sum mod 10) ; Sum := Sum div 10) ) ; a := a div 10 ; b := b div 10) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maximumChars(str): n=len(str) res=-1 for i in range(0,n-1): for j in range(i+1,n): if(str[i]==str[j]): res=max(res,abs(j-i-1)) return res if __name__=='__main__' : str="abba" print(maximumChars(str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( OclType["String"] := "abba" ; execute (maximumChars(OclType["String"]))->display() ) else skip; operation maximumChars(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var n : int := (OclType["String"])->size() ; var res : int := -1 ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if (("" + ([i+1])) = ("" + ([j+1]))) then ( res := Set{res, (j - i - 1)->abs()}->max() ) else skip)) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def subsetGraph(C): global N vertices=set() for i in range(N): vertices.add(i) while(len(vertices)!=0): if(len(vertices)==1): return 1 someone_removed=False for x in vertices : values=set() for y in vertices : if(y!=x): values.add(C[x][y]) if(len(values)==1): vertices.remove(x) someone_removed=True break if(not someone_removed): break return len(vertices) N=6 C=[[0,9,2,4,7,8],[9,0,9,9,7,9],[2,9,0,3,7,6],[4,9,3,0,7,1],[7,7,7,7,0,7],[8,9,6,1,7,0]] print(subsetGraph(C)) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute N : OclAny; operation initialise() pre: true post: true activity: skip ; N := 6 ; C := Sequence{Sequence{0}->union(Sequence{9}->union(Sequence{2}->union(Sequence{4}->union(Sequence{7}->union(Sequence{ 8 })))))}->union(Sequence{Sequence{9}->union(Sequence{0}->union(Sequence{9}->union(Sequence{9}->union(Sequence{7}->union(Sequence{ 9 })))))}->union(Sequence{Sequence{2}->union(Sequence{9}->union(Sequence{0}->union(Sequence{3}->union(Sequence{7}->union(Sequence{ 6 })))))}->union(Sequence{Sequence{4}->union(Sequence{9}->union(Sequence{3}->union(Sequence{0}->union(Sequence{7}->union(Sequence{ 1 })))))}->union(Sequence{Sequence{7}->union(Sequence{7}->union(Sequence{7}->union(Sequence{7}->union(Sequence{0}->union(Sequence{ 7 })))))}->union(Sequence{ Sequence{8}->union(Sequence{9}->union(Sequence{6}->union(Sequence{1}->union(Sequence{7}->union(Sequence{ 0 }))))) }))))) ; execute (subsetGraph(C))->display(); operation subsetGraph(C : OclAny) : OclAny pre: true post: true activity: skip ; var vertices : Set := Set{}->union(()) ; for i : Integer.subrange(0, N-1) do ( execute ((i) : vertices)) ; while ((vertices)->size() /= 0) do ( if ((vertices)->size() = 1) then ( return 1 ) else skip ; var someone_removed : boolean := false ; for x : vertices do ( var values : Set := Set{}->union(()) ; for y : vertices do ( if (y /= x) then ( execute ((C[x+1][y+1]) : values) ) else skip) ; if ((values)->size() = 1) then ( execute ((x) /: vertices) ; someone_removed := true ; break ) else skip) ; if (not(someone_removed)) then ( break ) else skip) ; return (vertices)->size(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def merge(arr,temp,left,mid,right): inv_count=0 i=left j=mid k=left while((i<=mid-1)and(j<=right)): if(arr[i]<=arr[j]): temp[k]=arr[i] i+=1 k+=1 else : temp[k]=arr[j] k+=1 j+=1 inv_count=inv_count+(mid-i) while(i<=mid-1): temp[k]=arr[i] i+=1 k+=1 while(j<=right): temp[k]=arr[j] k+=1 j+=1 for i in range(left,right+1): arr[i]=temp[i] return inv_count def _mergeSort(arr,temp,left,right): inv_count=0 if(right>left): mid=(right+left)//2 inv_count=_mergeSort(arr,temp,left,mid) inv_count+=_mergeSort(arr,temp,mid+1,right) inv_count+=merge(arr,temp,left,mid+1,right) return inv_count def countPairs(arr,n): for i in range(n): arr[i]=i*arr[i] temp=[0]*n return _mergeSort(arr,temp,0,n-1) if __name__=="__main__" : arr=[5,0,10,2,4,1,6] n=len(arr) print("Count of Pairs : ",countPairs(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{5}->union(Sequence{0}->union(Sequence{10}->union(Sequence{2}->union(Sequence{4}->union(Sequence{1}->union(Sequence{ 6 })))))) ; n := (arr)->size() ; execute ("Count of Pairs : ")->display() ) else skip; operation merge(arr : OclAny, temp : OclAny, left : OclAny, mid : OclAny, right : OclAny) : OclAny pre: true post: true activity: var inv_count : int := 0 ; var i : OclAny := left ; var j : OclAny := mid ; var k : OclAny := left ; while (((i->compareTo(mid - 1)) <= 0) & ((j->compareTo(right)) <= 0)) do ( if ((arr[i+1]->compareTo(arr[j+1])) <= 0) then ( temp[k+1] := arr[i+1] ; i := i + 1 ; k := k + 1 ) else ( temp[k+1] := arr[j+1] ; k := k + 1 ; j := j + 1 ; inv_count := inv_count + (mid - i) )) ; while ((i->compareTo(mid - 1)) <= 0) do ( temp[k+1] := arr[i+1] ; i := i + 1 ; k := k + 1) ; while ((j->compareTo(right)) <= 0) do ( temp[k+1] := arr[j+1] ; k := k + 1 ; j := j + 1) ; for i : Integer.subrange(left, right + 1-1) do ( arr[i+1] := temp[i+1]) ; return inv_count; operation _mergeSort(arr : OclAny, temp : OclAny, left : OclAny, right : OclAny) : OclAny pre: true post: true activity: inv_count := 0 ; if ((right->compareTo(left)) > 0) then ( mid := (right + left) div 2 ; inv_count := _mergeSort(arr, temp, left, mid) ; inv_count := inv_count + _mergeSort(arr, temp, mid + 1, right) ; inv_count := inv_count + merge(arr, temp, left, mid + 1, right) ) else skip ; return inv_count; operation countPairs(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( arr[i+1] := i * arr[i+1]) ; temp := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; return _mergeSort(arr, temp, 0, n - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Calculate_area(): b=3 h=4 s1=3 s2=6 s3=6 Ht=8 SA=b*h+(s1+s2+s3)*Ht print("The area of triangular prism is :",SA) if __name__=='__main__' : Calculate_area() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( Calculate_area() ) else skip; operation Calculate_area() pre: true post: true activity: var b : int := 3 ; var h : int := 4 ; var s1 : int := 3 ; var s2 : int := 6 ; var s3 : int := 6 ; var Ht : int := 8 ; var SA : int := b * h + (s1 + s2 + s3) * Ht ; execute ("The area of triangular prism is :")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _=input() a_L=map(int,input().split()) a_L=sorted(a_L) print(abs(a_L[0]-a_L[-1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _anon : String := (OclFile["System.in"]).readLine() ; var a_L : Sequence := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a_L := a_L->sort() ; execute ((a_L->first() - a_L->last())->abs())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10000000) MOD=10**9+7 INF=10**15 def main(): N=int(input()) A=list(map(int,input().split())) ans=-INF for i in range(N): for j in range(i+1,N): ans=max(ans,abs(A[i]-A[j])) print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit(10000000) ; var MOD : double := (10)->pow(9) + 7 ; var INF : double := (10)->pow(15) ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : OclAny := -INF ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(i + 1, N-1) do ( ans := Set{ans, (A[i+1] - A[j+1])->abs()}->max())) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) As=[int(x)for x in input().split()] ans=0 for i in range(N): for j in range(N): if i==j : continue ans=max(abs(As[i]-As[j]),ans) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var As : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( if i = j then ( continue ) else skip ; ans := Set{(As[i+1] - As[j+1])->abs(), ans}->max())) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def generateArr(arr,n): if(n==1): print(arr[0]); return ; barr=[0]*n ; barr[0]=arr[0]& arr[1]; barr[n-1]=arr[n-1]& arr[n-2]; for i in range(1,n-1): barr[i]=arr[i-1]& arr[i+1]; for i in range(n): print(barr[i],end=" "); if __name__=='__main__' : arr=[1,2,3,4,5,6]; n=len(arr); generateArr(arr,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))))); ; n := (arr)->size(); ; generateArr(arr, n); ) else skip; operation generateArr(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: if (n = 1) then ( execute (arr->first())->display(); ; return; ) else skip ; var barr : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n); ; barr->first() := MathLib.bitwiseAnd(arr->first(), arr[1+1]); ; barr[n - 1+1] := MathLib.bitwiseAnd(arr[n - 1+1], arr[n - 2+1]); ; for i : Integer.subrange(1, n - 1-1) do ( barr[i+1] := MathLib.bitwiseAnd(arr[i - 1+1], arr[i + 1+1]);) ; for i : Integer.subrange(0, n-1) do ( execute (barr[i+1])->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class BIT : def __init__(self,N): self.size=N self.tree=[0]*(N+1) self.depth=n.bit_length() def _bitsum(self,i): ret=0 while i : ret+=self.tree[i] i ^=i &-i return ret def bitsum(self,l,r=None): if r is None : return self._bitsum(l) else : return self._bitsum(r)-self._bitsum(l) def bitadd(self,i,x): i+=1 while i<=self.size : self.tree[i]+=x i+=i &-i return n=int(input()) m=n*(n+1)//4 a=list(map(int,input().split())) d=dict() _a=sorted(set(a+[0])) for i,x in enumerate(_a): d[x]=i a=[d[x]for x in a] def check(X): b=[0]+[(y>=X)*2-1 for y in a] for i in range(n): b[i+1]+=b[i] c=min(b) b=[x-c for x in b] bit=BIT(max(b)+2) ans=0 for x in b : ans+=bit.bitsum(x+1) bit.bitadd(x,1) return ans>=m t=[len(_a),0] while t[0]-t[1]>1 : mid=(t[0]+t[1])//2 t[check(mid)]=mid print(_a[t[1]]) ------------------------------------------------------------ OCL File: --------- class BIT { static operation newBIT() : BIT pre: true post: BIT->exists( _x | result = _x ); attribute size : OclAny := N; attribute tree : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)); attribute depth : OclAny := n.bit_length(); operation initialise(N : OclAny) : BIT pre: true post: true activity: self.size := N ; self.tree := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; self.depth := n.bit_length(); return self; operation _bitsum(i : OclAny) : OclAny pre: true post: true activity: var ret : int := 0 ; while i do ( ret := ret + self.tree[i+1] ; i := i xor MathLib.bitwiseAnd(i, -i)) ; return ret; operation bitsum(l : OclAny,r : OclAny) : OclAny pre: true post: true activity: if r <>= null then ( return self._bitsum(l) ) else ( return self._bitsum(r) - self._bitsum(l) ); operation bitadd(i : OclAny,x : OclAny) pre: true post: true activity: i := i + 1 ; while (i->compareTo(self.size)) <= 0 do ( self.tree[i+1] := self.tree[i+1] + x ; i := i + MathLib.bitwiseAnd(i, -i)) ; return; } class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := n * (n + 1) div 4 ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : Map := (arguments ( )) ; var _a : Sequence := Set{}->union((a->union(Sequence{ 0 })))->sort() ; for _tuple : Integer.subrange(1, (_a)->size())->collect( _indx | Sequence{_indx-1, (_a)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var x : OclAny := _tuple->at(_indx); d[x+1] := i) ; a := a->select(x | true)->collect(x | (d[x+1])) ; skip ; var t : Sequence := Sequence{(_a)->size()}->union(Sequence{ 0 }) ; while t->first() - t[1+1] > 1 do ( var mid : int := (t->first() + t[1+1]) div 2 ; t[check(mid)+1] := mid) ; execute (_a[t[1+1]+1])->display(); operation check(X : OclAny) : OclAny pre: true post: true activity: var b : Sequence := Sequence{ 0 }->union(a->select(y | true)->collect(y | (((y->compareTo(X)) >= 0) * 2 - 1))) ; for i : Integer.subrange(0, n-1) do ( b[i + 1+1] := b[i + 1+1] + b[i+1]) ; var c : OclAny := (b)->min() ; b := b->select(x | true)->collect(x | (x - c)) ; var bit : BIT := (BIT.newBIT()).initialise((b)->max() + 2) ; var ans : int := 0 ; for x : b do ( ans := ans + bit.bitsum(x + 1) ; bit.bitadd(x, 1)) ; return (ans->compareTo(m)) >= 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import combinations N=int(input()) A=list(map(int,input().split())) ls=list(combinations(A,2)) ans=0 for(a,b)in ls : ans=max(ans,abs(a-b)) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ls : Sequence := (combinations(A, 2)) ; var ans : int := 0 ; for Sequence{a, b} : ls do ( ans := Set{ans, (a - b)->abs()}->max()) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() A=[int(i)for i in input().split()] print(max(A)-min(A)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var A : Sequence := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute ((A)->max() - (A)->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=1000000007 def SieveOfEratosthenes(prime,p_size): prime[0]=False prime[1]=False for p in range(2,p_size): if(prime[p]): for i in range(2*p,p_size,p): prime[i]=False def productPrimeFreq(arr,n): prime=[True for i in range(n+1)] SieveOfEratosthenes(prime,n+1) i,j=0,0 m=dict() for i in range(n): m[arr[i]]=m.get(arr[i],0)+1 product=1 for it in m : if(prime[m[it]]): product*=it % MOD product %=MOD return product arr=[5,4,6,5,4,6] n=len(arr) print(productPrimeFreq(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MOD : int := 1000000007 ; skip ; skip ; arr := Sequence{5}->union(Sequence{4}->union(Sequence{6}->union(Sequence{5}->union(Sequence{4}->union(Sequence{ 6 }))))) ; n := (arr)->size() ; execute (productPrimeFreq(arr, n))->display(); operation SieveOfEratosthenes(prime : OclAny, p_size : OclAny) pre: true post: true activity: prime->first() := false ; prime[1+1] := false ; for p : Integer.subrange(2, p_size-1) do ( if (prime[p+1]) then ( for i : Integer.subrange(2 * p, p_size-1)->select( $x | ($x - 2 * p) mod p = 0 ) do ( prime[i+1] := false) ) else skip); operation productPrimeFreq(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: prime := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (true)) ; SieveOfEratosthenes(prime, n + 1) ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,0} ; var m : Map := (arguments ( )) ; for i : Integer.subrange(0, n-1) do ( m[arr[i+1]+1] := m.get(arr[i+1], 0) + 1) ; var product : int := 1 ; for it : m->keys() do ( if (prime[m[it+1]+1]) then ( product := product * it mod MOD ; product := product mod MOD ) else skip) ; return product; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calculateSum(n,k): res=1 MOD=1000000007 while k>0 : if(k & 1)==1 : res=(res*n)% MOD k=k//2 n=(n*n)% MOD return res n=4 k=3 print(calculateSum(n,k)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; k := 3 ; execute (calculateSum(n, k))->display(); operation calculateSum(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: var res : int := 1 ; var MOD : int := 1000000007 ; while k > 0 do ( if (MathLib.bitwiseAnd(k, 1)) = 1 then ( res := (res * n) mod MOD ) else skip ; k := k div 2 ; n := (n * n) mod MOD) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- infilecode="ALI" import sys mapping={"A" : "A","B" : "B","C" : "C","D" : "D","E" : "E","X" : "example","S" : "-small","L" : "-large","P" : "-practice","0" : "-attempt0","1" : "-attempt1","2" : "-attempt2","I" : ".in","T" : ".txt"} infile="".join(mapping[c]for c in infilecode) outfile=infile.replace(".in","")+".out.txt" sys.stdin=open(infile,'r') output=open(outfile,'w') T=int(input()) for case in range(1,T+1): S,K=input().split() print(S,K) K=int(K) S=list(S) L=len(S) flips=0 for i in range(L-K+1): if S[i]=="-" : flips+=1 for j in range(i,i+K): S[j]={"+" : "-","-" : "+"}[S[j]] if S==["+"]*L : answer=flips else : answer="IMPOSSIBLE" print("Case #%d:" % case,answer) print("Case #%d:" % case,answer,file=output) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var infilecode : String := "ALI" ; skip ; var mapping : Map := Map{ "A" |-> "A" }->union(Map{ "B" |-> "B" }->union(Map{ "C" |-> "C" }->union(Map{ "D" |-> "D" }->union(Map{ "E" |-> "E" }->union(Map{ "X" |-> "example" }->union(Map{ "S" |-> "-small" }->union(Map{ "L" |-> "-large" }->union(Map{ "P" |-> "-practice" }->union(Map{ "0" |-> "-attempt0" }->union(Map{ "1" |-> "-attempt1" }->union(Map{ "2" |-> "-attempt2" }->union(Map{ "I" |-> ".in" }->union(Map{ "T" |-> ".txt" }))))))))))))) ; var infile : String := StringLib.sumStringsWithSeparator(((argument (test (logical_test (comparison (expr (atom (name mapping)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name c)))))))) ])))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name infilecode)))))))), "") ; var outfile : String := infile.replace(".in", "") + ".out.txt" ; OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile(infile)) ; var output : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(outfile)) ; var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for case : Integer.subrange(1, T + 1-1) do ( var S : OclAny := null; var K : OclAny := null; Sequence{S,K} := input().split() ; execute (S)->display() ; var K : int := ("" + ((K)))->toInteger() ; var S : Sequence := (S) ; var L : int := (S)->size() ; var flips : int := 0 ; for i : Integer.subrange(0, L - K + 1-1) do ( if S[i+1] = "-" then ( flips := flips + 1 ; for j : Integer.subrange(i, i + K-1) do ( S[j+1] := Map{ "+" |-> "-" }->union(Map{ "-" |-> "+" })[S[j+1]+1]) ) else skip) ; if S = MatrixLib.elementwiseMult(Sequence{ "+" }, L) then ( var answer : int := flips ) else ( answer := "IMPOSSIBLE" ) ; execute (StringLib.format("Case #%d:",case))->display() ; execute (StringLib.format("Case #%d:",case))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def flip(row): return row.translate(str.maketrans('-+','+-')) def solve(row,k): flips=0 for i in range(len(row)): if row[i]=='-' and i+k<=len(row): row=row[: i]+flip(row[i : i+k])+row[i+k :] flips+=1 if '-' in row : return "IMPOSSIBLE" else : return flips def main(): t=int(input()) for ti in range(t): row,k=input().split(" ") print("Case #{}:{}".format(ti+1,solve(row,int(k)))) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation flip(row : OclAny) : OclAny pre: true post: true activity: return row.translate(("" + (.maketrans('-+', '+-')))); operation solve(row : OclAny, k : OclAny) : OclAny pre: true post: true activity: var flips : int := 0 ; for i : Integer.subrange(0, (row)->size()-1) do ( if row[i+1] = '-' & (i + k->compareTo((row)->size())) <= 0 then ( row := row.subrange(1,i) + flip(row.subrange(i+1, i + k)) + row.subrange(i + k+1) ; flips := flips + 1 ) else skip) ; if (row)->includes('-') then ( return "IMPOSSIBLE" ) else ( return flips ); operation main() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for ti : Integer.subrange(0, t-1) do ( Sequence{row,k} := input().split(" ") ; execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{ti + 1, solve(row, ("" + ((k)))->toInteger())}))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from __future__ import print_function import sys from sys import stdin def eprint(*args,**kwargs): print(*args,file=sys.stderr,**kwargs) def ln(f=int): return list(map(f,stdin.readline().strip().split())) T,=ln() INF=float('inf') for test in range(T): s,K=ln(str) K=int(K) s=[0 if c=="+" else 1 for c in s] best=0 for i in range(len(s)-K+1): if s[i]!=0 : for j in range(i,i+K): s[j]^=1 best+=1 if sum(s)!=0 : best="IMPOSSIBLE" print("Case #"+str(test+1)+": "+str(best)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; (testlist_star_expr (test (logical_test (comparison (expr (atom (name T)))))) ,) Sequence{(testlist_star_expr (test (logical_test (comparison (expr (atom (name T)))))) ,)} := ln() ; var INF : double := ("" + (('inf')))->toReal() ; for test : Integer.subrange(0, T-1) do ( var s : OclAny := null; var K : OclAny := null; Sequence{s,K} := ln(OclType["String"]) ; var K : int := ("" + ((K)))->toInteger() ; var s : Sequence := s->select(c | true)->collect(c | (if c = "+" then 0 else 1 endif)) ; var best : int := 0 ; for i : Integer.subrange(0, (s)->size() - K + 1-1) do ( if s[i+1] /= 0 then ( for j : Integer.subrange(i, i + K-1) do ( s[j+1] := s[j+1] xor 1) ; best := best + 1 ) else skip) ; if (s)->sum() /= 0 then ( best := "IMPOSSIBLE" ) else skip ; execute ("Case #" + ("" + ((test + 1))) + ": " + ("" + ((best))))->display()); operation eprint(args : OclAny : Sequence(OclAny), kwargs : OclAny : Map(String, OclAny)) pre: true post: true activity: (args * (named_parameter (name args)))(kwargs ** (named_parameter (name kwargs))) execute ((argument * (test (logical_test (comparison (expr (atom (name args))))))))->display(); operation ln(f : OclAny) : OclAny pre: true post: true activity: if f->oclIsUndefined() then f := OclType["int"] else skip; return ((stdin.readLine()->trim().split())->collect( _x | (f)->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import numpy as np def solve(state,K): N=len(state) xs=np.array([1 if s=='+' else 0 for s in state]) ret=0 for i in range(N-K+1): if xs[i]==0 : ret+=1 xs[i : i+K]=1-xs[i : i+K] if xs[-K :].sum()==K : return "%d" % ret return "IMPOSSIBLE" if __name__=="__main__" : fd_input=open(sys.argv[1]) fd_output=open(sys.argv[1].replace(".in",".out"),"w") T=int(fd_input.readline().strip()) for t in range(T): line=fd_input.readline().strip().split(" ") sol=solve(line[0],int(line[1])) fd_output.write("Case #%d: %s\n" %(t+1,sol)) fd_input.close() fd_output.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( var fd_input : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) ; var fd_output : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))).replace(".in", ".out"))) ; var T : int := ("" + ((fd_input.readLine()->trim())))->toInteger() ; for t : Integer.subrange(0, T-1) do ( var line : OclAny := fd_input.readLine()->trim().split(" ") ; var sol : OclAny := solve(line->first(), ("" + ((line[1+1])))->toInteger()) ; fd_output.write(StringLib.format("Case #%d: %s\n",Sequence{t + 1, sol}))) ; fd_input.closeFile() ; fd_output.closeFile() ) else skip; operation solve(state : OclAny, K : OclAny) : OclAny pre: true post: true activity: var N : int := (state)->size() ; var xs : Sequence := (state->select(s | true)->collect(s | (if s = '+' then 1 else 0 endif))) ; var ret : int := 0 ; for i : Integer.subrange(0, N - K + 1-1) do ( if xs[i+1] = 0 then ( ret := ret + 1 ; xs.subrange(i+1, i + K) := 1 - xs.subrange(i+1, i + K) ) else skip) ; if xs.subrange(-K+1).sum() = K then ( return StringLib.format("%d",ret) ) else skip ; return "IMPOSSIBLE"; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10000) def solve(data,k): l=len(data) if l==k : if data==["+"]*k : return 0 elif data==["-"]*k : return 1 else : return-1 if ltoInteger() ; for i : Integer.subrange(1, t + 1-1) do ( var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := raw_input().split(" ")->select(s | true)->collect(s | (s)) ; data := (("" + ((n))))->characters() ; k := ("" + ((m)))->toInteger() ; result := solve(data, k) ; if result = -1 then ( result := "IMPOSSIBLE" ) else skip ; execute (StringLib.interpolateStrings("Case #{}:{}", Sequence{i, result}))->display()); operation solve(data : OclAny, k : OclAny) : OclAny pre: true post: true activity: var l : int := (data)->size() ; if l = k then ( if data = MatrixLib.elementwiseMult(Sequence{ "+" }, k) then ( return 0 ) else (if data = MatrixLib.elementwiseMult(Sequence{ "-" }, k) then ( return 1 ) else ( return -1 ) ) ) else skip ; if (l->compareTo(k)) < 0 then ( if data = MatrixLib.elementwiseMult(Sequence{ "+" }, l) then ( return 0 ) else ( return -1 ) ) else skip ; var flips : int := 0 ; if data->first() = '-' then ( for i : Integer.subrange(0, k-1) do ( if data[i+1] = "+" then ( data[i+1] := "-" ) else ( data[i+1] := "+" )) ; flips := 1 ) else skip ; var result : OclAny := solve(data->tail(), k) ; if result < 0 then ( return -1 ) else skip ; return result + flips; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=list(map(int,input().split())) ans=[] for i in range(1,82): x=(i**a)*b+c if x<0 or x>=10**9 : continue if sum(map(int,list(str(x))))==i : ans.append(x) print(len(ans)) print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : Sequence := Sequence{} ; for i : Integer.subrange(1, 82-1) do ( var x : double := ((i)->pow(a)) * b + c ; if x < 0 or (x->compareTo((10)->pow(9))) >= 0 then ( continue ) else skip ; if (((("" + ((x))))->characters())->collect( _x | (OclType["int"])->apply(_x) ))->sum() = i then ( execute ((x) : ans) ) else skip) ; execute ((ans)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools import math import sys import queue import itertools from heapq import heappop,heappush import random def solve(): n,I=map(int,sys.stdin.readline().split()) a=list(map(int,sys.stdin.readline().split())) a.sort() m={} for i in range(n): if a[i]not in m : m[a[i]]=1 else : m[a[i]]+=1 f=[m[key]for key in m] df=len(f) need=2**math.floor(8*I/n) need_del=(df-need) l=-1 curent=0 for i in range(need_del): curent+=f[i] l+=1 res=curent*1 for i in range(need_del): curent-=f[l] curent+=f[-1-i] l-=1 res=min(res,curent) sys.stdout.write(str(res)) if __name__=='__main__' : multi_test=0 if multi_test : t=int(sys.stdin.readline()) for _ in range(t): solve() else : solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var multi_test : int := 0 ; if multi_test then ( var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( solve()) ) else ( solve() ) ) else skip; operation solve() pre: true post: true activity: var n : OclAny := null; var I : OclAny := null; Sequence{n,I} := (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var m : OclAny := Set{} ; for i : Integer.subrange(0, n-1) do ( if (m)->excludes(a[i+1]) then ( m[a[i+1]+1] := 1 ) else ( m[a[i+1]+1] := m[a[i+1]+1] + 1 )) ; var f : Sequence := m->select(key | true)->collect(key | (m[key+1])) ; var df : int := (f)->size() ; var need : double := (2)->pow((8 * I / n)->floor()) ; var need_del : double := (df - need) ; var l : int := -1 ; var curent : int := 0 ; for i : Integer.subrange(0, need_del-1) do ( curent := curent + f[i+1] ; l := l + 1) ; var res : int := curent * 1 ; for i : Integer.subrange(0, need_del-1) do ( curent := curent - f[l+1] ; curent := curent + f->reverse()->at(-(-1 - i)) ; l := l - 1 ; res := Set{res, curent}->min()) ; (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name res)))))))) ))))))))) )))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()) l=[] for n in range(1,82): k=b*pow(n,a)+c if k>=0 and sum(map(int,str(k)))==n and k<1000000000 : l.append(k) print(len(l)) for k in l : print(k,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := Sequence{} ; for n : Integer.subrange(1, 82-1) do ( var k : double := b * (n)->pow(a) + c ; if k >= 0 & ((("" + ((k))))->collect( _x | (OclType["int"])->apply(_x) ))->sum() = n & k < 1000000000 then ( execute ((k) : l) ) else skip) ; execute ((l)->size())->display() ; for k : l do ( execute (k)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=list(map(int,input().split())) k=[] for i in range(1,82): x=b*(i)**a+c if 0collect( _x | (OclType["int"])->apply(_x) )) ; var k : Sequence := Sequence{} ; for i : Integer.subrange(1, 82-1) do ( var x : double := b * ((i))->pow(a) + c ; if 0 < x & (x < (10)->pow(9)) & ((("" + ((x))))->collect( _x | (OclType["int"])->apply(_x) ))->sum() = i then ( execute ((x) : k) ) else skip) ; execute ((k)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name k))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import collections import math def gcd(a,b): return math.gcd(a,b) a,b,c=map(int,input().split()) ans=[] cnt=0 for i in range(1,82): x=b*(i**a)+c sumDigit=0 temp=x while x>0 : sumDigit+=x % 10 x=x//10 if sumDigit==i and temp<10**9 : cnt+=1 ans.append(temp) print(cnt) print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := Sequence{} ; var cnt : int := 0 ; for i : Integer.subrange(1, 82-1) do ( var x : double := b * ((i)->pow(a)) + c ; var sumDigit : int := 0 ; var temp : OclAny := x ; while x > 0 do ( sumDigit := sumDigit + x mod 10 ; x := x div 10) ; if sumDigit = i & (temp->compareTo((10)->pow(9))) < 0 then ( cnt := cnt + 1 ; execute ((temp) : ans) ) else skip) ; execute (cnt)->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a)->gcd(b); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- mod=998244353 from bisect import bisect_left from operator import itemgetter N=int(input()) xd=[list(map(int,input().split()))for _ in range(N)] xd.sort(key=itemgetter(0)) X=[xd[i][0]for i in range(N)] D=[xd[i][1]for i in range(N)] N0=2**(N-1).bit_length() INF=2**31-1 data=[INF]*(4*N0) def update(k,x): k+=N0-1 data[k]=x while k>=0 : k=(k-1)//2 data[k]=min(data[2*k+1],data[2*k+2]) def query(l,r): L=l+N0 ; R=r+N0 s=INF while L>=1 ; R>>=1 return s for i in range(N-1,-1,-1): j=bisect_left(X,X[i]+D[i]) update(i,-i) update(i,query(i,j)) dp=[0]*(N+1) dp[-1]=1 for i in range(N-1,-1,-1): dp[i]+=dp[i+1] dp[i]+=dp[-query(i,i+1)+1] dp[i]%=mod print(dp[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var mod : int := 998244353 ; skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var xd : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; xd := xd->sort() ; var X : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (xd[i+1]->first())) ; var D : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (xd[i+1][1+1])) ; var N0 : double := (2)->pow((N - 1).bit_length()) ; var INF : double := (2)->pow(31) - 1 ; var data : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, (4 * N0)) ; skip ; skip ; for i : Integer.subrange(-1 + 1, N - 1)->reverse() do ( var j : OclAny := bisect_left(X, X[i+1] + D[i+1]) ; update(i, -i) ; update(i, query(i, j))) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; dp->last() := 1 ; for i : Integer.subrange(-1 + 1, N - 1)->reverse() do ( dp[i+1] := dp[i+1] + dp[i + 1+1] ; dp[i+1] := dp[i+1] + dp->reverse()->at(-(-query(i, i + 1) + 1)) ; dp[i+1] := dp[i+1] mod mod) ; execute (dp->first())->display(); operation update(k : OclAny, x : OclAny) pre: true post: true activity: k := k + N0 - 1 ; data[k+1] := x ; while k >= 0 do ( k := (k - 1) div 2 ; data[k+1] := Set{data[2 * k + 1+1], data[2 * k + 2+1]}->min()); operation query(l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var L : OclAny := l + N0; var R : OclAny := r + N0 ; var s : OclAny := INF ; while (L->compareTo(R)) < 0 do ( if MathLib.bitwiseAnd(R, 1) then ( R := R - 1 ; s := Set{s, data[R - 1+1]}->min() ) else skip ; if MathLib.bitwiseAnd(L, 1) then ( s := Set{s, data[L - 1+1]}->min() ; L := L + 1 ) else skip ; L := L div (2->pow(1)); R := R div (2->pow(1))) ; return s; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=[] a,b,c=list(map(int,input().split())); k=[] for i in range(1,82): x=b*(i)**a+c if 0collect( _x | (OclType["int"])->apply(_x) )); k := Sequence{} ; for i : Integer.subrange(1, 82-1) do ( var x : double := b * ((i))->pow(a) + c ; if 0 < x & (x < (10)->pow(9)) & ((("" + ((x))))->collect( _x | (OclType["int"])->apply(_x) ))->sum() = i then ( execute ((x) : k) ) else skip) ; execute ((k)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name k))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Node : def __init__(self,data): self.data=data self.next=next def printList(node): while(node!=None): print(node.data,end=" ") node=node.next print("\n") def newNode(key): temp=Node(0) temp.data=key temp.next=None return temp def insertBeg(head,val): temp=newNode(val) temp.next=head head=temp return head def rearrangeOddEven(head): odd=[] even=[] i=1 while(head!=None): if(head.data % 2!=0 and i % 2==0): odd.append(head) elif(head.data % 2==0 and i % 2!=0): even.append(head) head=head.next i=i+1 while(len(odd)!=0 and len(even)!=0): odd[-1].data,even[-1].data=even[-1].data,odd[-1].data odd.pop() even.pop() return head head=newNode(8) head=insertBeg(head,7) head=insertBeg(head,6) head=insertBeg(head,5) head=insertBeg(head,3) head=insertBeg(head,2) head=insertBeg(head,1) print("Linked List:") printList(head) rearrangeOddEven(head) print("Linked List after ","Rearranging:") printList(head) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute next : OclAny := next; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.next := next; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; head := newNode(8) ; head := insertBeg(head, 7) ; head := insertBeg(head, 6) ; head := insertBeg(head, 5) ; head := insertBeg(head, 3) ; head := insertBeg(head, 2) ; head := insertBeg(head, 1) ; execute ("Linked List:")->display() ; printList(head) ; rearrangeOddEven(head) ; execute ("Linked List after ")->display() ; printList(head); operation printList(node : OclAny) pre: true post: true activity: while (node /= null) do ( execute (node.data)->display() ; node := node.next) ; execute ("\n")->display(); operation newNode(key : OclAny) : OclAny pre: true post: true activity: var temp : Node := (Node.newNode()).initialise(0) ; temp.data := key ; temp.next := null ; return temp; operation insertBeg(head : OclAny, val : OclAny) : OclAny pre: true post: true activity: temp := newNode(val) ; temp.next := head ; head := temp ; return head; operation rearrangeOddEven(head : OclAny) : OclAny pre: true post: true activity: var odd : Sequence := Sequence{} ; var even : Sequence := Sequence{} ; var i : int := 1 ; while (head /= null) do ( if (head.data mod 2 /= 0 & i mod 2 = 0) then ( execute ((head) : odd) ) else (if (head.data mod 2 = 0 & i mod 2 /= 0) then ( execute ((head) : even) ) else skip) ; head := head.next ; i := i + 1) ; while ((odd)->size() /= 0 & (even)->size() /= 0) do ( var odd->last().data : OclAny := null; var even->last().data : OclAny := null; Sequence{odd->last().data,even->last().data} := Sequence{even->last().data,odd->last().data} ; odd := odd->front() ; even := even->front()) ; return head; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class RecentCounter(object): def __init__(self): self.queue=[] def ping(self,t): self.queue.append(t) while self.queue and self.queue[0]exists( _x | result = _x ); attribute queue : Sequence := Sequence{}; operation initialise() : pre: true post: true activity: self.queue := Sequence{}; return self; operation ping(t : OclAny) : OclAny pre: true post: true activity: (expr (atom (name self)) (trailer . (name queue)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) )))) ; while self.queue & (self.queue->first()->compareTo(t - 3000)) < 0 do ((expr (atom (name self)) (trailer . (name queue)) (trailer . (name pop) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))))) ; return (self.queue)->size(); } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def countDivisors(n): cnt=0 for i in range(1,(int)(math.sqrt(n))+1): if(n % i==0): if(n/i==i): cnt=cnt+1 else : cnt=cnt+2 return cnt print("Total distinct divisors of 100 are : ",countDivisors(100)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; execute ("Total distinct divisors of 100 are : ")->display(); operation countDivisors(n : OclAny) : OclAny pre: true post: true activity: var cnt : int := 0 ; for i : Integer.subrange(1, (OclType["int"])((n)->sqrt()) + 1-1) do ( if (n mod i = 0) then ( if (n / i = i) then ( cnt := cnt + 1 ) else ( cnt := cnt + 2 ) ) else skip) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from bisect import bisect_left def printMissing(arr,n,low,high): arr.sort() ptr=bisect_left(arr,low) index=ptr i=index x=low while(iunion(Sequence{3}->union(Sequence{5}->union(Sequence{ 4 }))) ; n := (arr)->size() ; low := 1 ; high := 10 ; printMissing(arr, n, low, high);; operation printMissing(arr : OclAny, n : OclAny, low : OclAny, high : OclAny) pre: true post: true activity: arr := arr->sort() ; var ptr : OclAny := bisect_left(arr, low) ; var index : OclAny := ptr ; var i : OclAny := index ; var x : OclAny := low ; while ((i->compareTo(n)) < 0 & (x->compareTo(high)) <= 0) do ( if (arr[i+1] /= x) then ( execute (x)->display() ) else ( i := i + 1 ) ; x := x + 1) ; while ((x->compareTo(high)) <= 0) do ( execute (x)->display() ; x := x + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def calcSum(arr,n,k): sum=0 for i in range(k): sum+=arr[i] print(sum,end=" ") for i in range(k,n): sum=(sum-arr[i-k])+arr[i] print(sum,end=" ") if __name__=="__main__" : arr=[1,2,3,4,5,6] n=len(arr) k=3 calcSum(arr,n,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))))) ; n := (arr)->size() ; k := 3 ; calcSum(arr, n, k) ) else skip; operation calcSum(arr : OclAny, n : OclAny, k : OclAny) pre: true post: true activity: var sum : int := 0 ; for i : Integer.subrange(0, k-1) do ( sum := sum + arr[i+1]) ; execute (sum)->display() ; for i : Integer.subrange(k, n-1) do ( sum := (sum - arr[i - k+1]) + arr[i+1] ; execute (sum)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sumOfDigitsSingle(x): ans=0 while x : ans+=x % 10 x//=10 return ans def closest(x): ans=0 while(ans*10+9<=x): ans=ans*10+9 return ans def sumOfDigitsTwoParts(N): A=closest(N) return sumOfDigitsSingle(A)+sumOfDigitsSingle(N-A) if __name__=="__main__" : N=35 print(sumOfDigitsTwoParts(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( N := 35 ; execute (sumOfDigitsTwoParts(N))->display() ) else skip; operation sumOfDigitsSingle(x : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; while x do ( ans := ans + x mod 10 ; x := x div 10) ; return ans; operation closest(x : OclAny) : OclAny pre: true post: true activity: ans := 0 ; while ((ans * 10 + 9->compareTo(x)) <= 0) do ( ans := ans * 10 + 9) ; return ans; operation sumOfDigitsTwoParts(N : OclAny) : OclAny pre: true post: true activity: var A : OclAny := closest(N) ; return sumOfDigitsSingle(A) + sumOfDigitsSingle(N - A); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- days=int(input()) needed,prices=[],[] for _ in range(days): need,prix=[int(x)for x in input().split()] needed.append(need) prices.append(prix) total=needed[0]*prices[0] indice_old=0 indice=1 while indicetoInteger() ; var needed : OclAny := null; var prices : OclAny := null; Sequence{needed,prices} := Sequence{Sequence{},Sequence{}} ; for _anon : Integer.subrange(0, days-1) do ( var need : OclAny := null; var prix : OclAny := null; Sequence{need,prix} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; execute ((need) : needed) ; execute ((prix) : prices)) ; var total : double := needed->first() * prices->first() ; var indice_old : int := 0 ; var indice : int := 1 ; while (indice->compareTo((needed)->size())) < 0 do ( if (prices[indice+1]->compareTo(prices[indice_old+1])) <= 0 then ( total := total + prices[indice+1] * needed[indice+1] ; indice_old := indice ; indice := indice + 1 ) else ( total := total + prices[indice_old+1] * needed[indice+1] ; indice := indice + 1 )) ; execute (total)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- days=int(input()) records=[] for i in range(days): (meat_needs,cost_of_meat_per_kg)=map(int,input().split(' ')) records.append([meat_needs,cost_of_meat_per_kg]) spending=records[0][0]*records[0][1] initial_cost_per_kg=records[0][1] for i in range(1,days): if records[i][1]toInteger() ; var records : Sequence := Sequence{} ; for i : Integer.subrange(0, days-1) do ( ; var Sequence{meat_needs, cost_of_meat_per_kg} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{meat_needs}->union(Sequence{ cost_of_meat_per_kg })) : records)) ; var spending : double := records->first()->first() * records->first()[1+1] ; var initial_cost_per_kg : OclAny := records->first()[1+1] ; for i : Integer.subrange(1, days-1) do ( if (records[i+1][1+1]->compareTo(initial_cost_per_kg)) < 0 then ( initial_cost_per_kg := records[i+1][1+1] ) else skip ; spending := spending + (initial_cost_per_kg * records[i+1]->first())) ; execute (spending)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) m=100 r=0 while n : a,b=map(int,input().split()); m=min(b,m); r+=a*m ; n-=1 print(r) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : int := 100 ; var r : int := 0 ; while n do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); m := Set{b, m}->min(); r := r + a * m; n := n - 1) ; execute (r)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) cost=0 mini=101 for i in range(n): a,b=list(map(int,input().split())) mini=min(mini,b) cost=cost+(a*mini) print(cost) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cost : int := 0 ; var mini : int := 101 ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; mini := Set{mini, b}->min() ; cost := cost + (a * mini)) ; execute (cost)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) x=[list(map(int,input().split()))for i in range(n)]+[[11**9]] x.sort(lambda x : x[0]) a=x[:-2] y=a+[n] a+=[2,1] for i in range(n-2,-1,-1): y[i]=i+1 while x[y[i]][0]toInteger() ; var x : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))))->union(Sequence{ Sequence{ (11)->pow(9) } }) ; x := x->sort() ; var a : OclAny := x->front()->front() ; var y : OclAny := a->union(Sequence{ n }) ; a := a + Sequence{2}->union(Sequence{ 1 }) ; for i : Integer.subrange(-1 + 1, n - 2)->reverse() do ( y[i+1] := i + 1 ; while (x[y[i+1]+1]->first()->compareTo((x[i+1])->sum())) < 0 do ( y[i+1] := y[y[i+1]+1]) ; a[i+1] := (a[i + 1+1] + a[y[i+1]+1]) mod 998244353) ; execute (a->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) minc=101 s=0 for i in range(n): a,p=map(int,input().split()) if minc>p : minc=p s+=a*minc print(s) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var minc : int := 101 ; var s : int := 0 ; for i : Integer.subrange(0, n-1) do ( var a : OclAny := null; var p : OclAny := null; Sequence{a,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (minc->compareTo(p)) > 0 then ( minc := p ) else skip ; s := s + a * minc) ; execute (s)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import eulerlib def compute(): TARGET=2000000 end=eulerlib.sqrt(TARGET)+1 gen=((w,h)for w in range(1,end)for h in range(1,end)) func=lambda wh : abs(num_rectangles(*wh)-TARGET) ans=min(gen,key=func) return str(ans[0]*ans[1]) def num_rectangles(m,n): return(m+1)*m*(n+1)*n//4 if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var TARGET : int := 2000000 ; var end : double := eulerlib.sqrt(TARGET) + 1 ; var gen : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name w)))))) , (test (logical_test (comparison (expr (atom (name h))))))) )))))) (comp_for for (exprlist (expr (atom (name w)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name end)))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name h)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name end)))))))) ))))))))))} ; var func : Function := lambda wh : OclAny in ((num_rectangles((argument * (test (logical_test (comparison (expr (atom (name wh)))))))) - TARGET)->abs()) ; var ans : OclAny := Set{gen, (argument (test (logical_test (comparison (expr (atom (name key)))))) = (test (logical_test (comparison (expr (atom (name func)))))))}->min() ; return ("" + ((ans->first() * ans[1+1]))); operation num_rectangles(m : OclAny, n : OclAny) : OclAny pre: true post: true activity: return (m + 1) * m * (n + 1) * n div 4; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isSubsetAndZero(array,length,N): arrAnd=array[0] for i in range(1,length): arrAnd=arrAnd & array[i] if((arrAnd & N)==0): print("YES") else : print("NO") if __name__=="__main__" : array=[1,2,4] length=len(array) N=3 isSubsetAndZero(array,length,N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( array := Sequence{1}->union(Sequence{2}->union(Sequence{ 4 })) ; length := (array)->size() ; N := 3 ; isSubsetAndZero(array, length, N) ) else skip; operation isSubsetAndZero(array : OclAny, length : OclAny, N : OclAny) pre: true post: true activity: var arrAnd : OclAny := array->first() ; for i : Integer.subrange(1, length-1) do ( arrAnd := MathLib.bitwiseAnd(arrAnd, array[i+1])) ; if ((MathLib.bitwiseAnd(arrAnd, N)) = 0) then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,A,B=map(int,input().split()) X=list(map(int,input().split())) nowX=X[0] ans=0 for x in X[1 :]: ans+=min((x-nowX)*A,B) nowX=x print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{N,A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var X : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var nowX : OclAny := X->first() ; var ans : int := 0 ; for x : X->tail() do ( ans := ans + Set{(x - nowX) * A, B}->min() ; nowX := x) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,Counter from itertools import product,groupby,count,permutations,combinations from math import pi,sqrt from collections import deque from bisect import bisect,bisect_left,bisect_right from string import ascii_lowercase from functools import lru_cache import sys sys.setrecursionlimit(10000) INF=float("inf") YES,Yes,yes,NO,No,no="YES","Yes","yes","NO","No","no" dy4,dx4=[0,1,0,-1],[1,0,-1,0] dy8,dx8=[0,-1,0,1,1,-1,-1,1],[1,0,-1,0,1,1,-1,-1] def inside(y,x,H,W): return 0<=ytoReal() ; var YES : OclAny := null; var Yes : OclAny := null; var yes : OclAny := null; var NO : OclAny := null; var No : OclAny := null; var no : OclAny := null; Sequence{YES,Yes,yes,NO,No,no} := Sequence{"YES","Yes","yes","NO","No","no"} ; var dy4 : OclAny := null; var dx4 : OclAny := null; Sequence{dy4,dx4} := Sequence{Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ -1 }))),Sequence{1}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{ 0 })))} ; var dy8 : OclAny := null; var dx8 : OclAny := null; Sequence{dy8,dx8} := Sequence{Sequence{0}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{-1}->union(Sequence{-1}->union(Sequence{ 1 }))))))),Sequence{1}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{-1}->union(Sequence{ -1 })))))))} ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation inside(y : OclAny, x : OclAny, H : OclAny, W : OclAny) : OclAny pre: true post: true activity: return 0 <= y & (y < H) & 0 <= x & (x < W); operation ceil(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (a + b - 1) div b; operation main() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{N,A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var X : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var cost : int := 0 ; for i : Integer.subrange(0, N - 1-1) do ( var d : double := X[i + 1+1] - X[i+1] ; cost := cost + Set{d * A, B}->min()) ; execute (cost)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B=map(int,input().split()) grid=[] for h in range(100): str="#"*50+"."*50 grid.append(list(str)) cntA=0 while cntAcollect( _x | (OclType["int"])->apply(_x) ) ; var grid : Sequence := Sequence{} ; for h : Integer.subrange(0, 100-1) do ( var OclType["String"] : String := StringLib.nCopies("#", 50) + StringLib.nCopies(".", 50) ; execute (((OclType["String"])->characters()) : grid)) ; var cntA : int := 0 ; while (cntA->compareTo(A - 1)) < 0 do ( var w : int := cntA mod 25 ; var h : int := cntA div 25 ; grid[2 * h+1][2 * w+1] := "." ; cntA := cntA + 1) ; var cntB : int := 0 ; while (cntB->compareTo(B - 1)) < 0 do ( w := cntB mod 25 + 25 ; h := cntB div 25 ; grid[2 * h+1][2 * w + 1+1] := "#" ; cntB := cntB + 1) ; execute (100)->display() ; for s : grid do ( execute (StringLib.sumStringsWithSeparator((s), ""))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : [N,A,B]=map(int,input().split()) xs=list(map(int,input().split())) d_xs=[xs[i]-xs[i-1]for i in range(1,len(xs))] s=0 for d in d_xs : if(d*A ; Sequence{N}->union(Sequence{A}->union(Sequence{ B })) := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var xs : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d_xs : Sequence := Integer.subrange(1, (xs)->size()-1)->select(i | true)->collect(i | (xs[i+1] - xs[i - 1+1])) ; var s : int := 0 ; for d : d_xs do ( if ((d * A->compareTo(B)) < 0) then ( s := s + d * A ) else ( s := s + B )) ; execute (s)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def d_walk_and_teleport(N,A,B,X): ans=sum([min(A*(X[k+1]-X[k]),B)for k in range(N-1)]) return ans N,A,B=[int(i)for i in input().split()] X=[int(i)for i in input().split()] print(d_walk_and_teleport(N,A,B,X)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{N,A,B} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; X := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute (d_walk_and_teleport(N, A, B, X))->display(); operation d_walk_and_teleport(N : OclAny, A : OclAny, B : OclAny, X : OclAny) : OclAny pre: true post: true activity: var ans : OclAny := (Integer.subrange(0, N - 1-1)->select(k | true)->collect(k | (Set{A * (X[k + 1+1] - X[k+1]), B}->min())))->sum() ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N,A,B=[int(s)for s in input().split()] X=[int(s)for s in input().split()] d1=[X[i+1]-X[i]for i in range(N-1)] d2=[min(d*A,B)for d in d1] print(sum(d2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : OclAny := null; var A : OclAny := null; var B : OclAny := null; Sequence{N,A,B} := input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; var X : Sequence := input().split()->select(s | true)->collect(s | (("" + ((s)))->toInteger())) ; var d1 : Sequence := Integer.subrange(0, N - 1-1)->select(i | true)->collect(i | (X[i + 1+1] - X[i+1])) ; var d2 : Sequence := d1->select(d | true)->collect(d | (Set{d * A, B}->min())) ; execute ((d2)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,k=map(int,input().split()) ans=0 if a>=k : print(1*k) elif a+b>=k : print(1*a) else : print(1*a+(k-(a+b))*-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var k : OclAny := null; Sequence{a,b,c,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : int := 0 ; if (a->compareTo(k)) >= 0 then ( execute (1 * k)->display() ) else (if (a + b->compareTo(k)) >= 0 then ( execute (1 * a)->display() ) else ( execute (1 * a + (k - (a + b)) * -1)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math A,B,C,K=list(map(int,input().split())) s=K ans=0 s-=min(A,K) ans+=min(A,K) if(s>0): s-=B if(s>0): ans-=s print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var A : OclAny := null; var B : OclAny := null; var C : OclAny := null; var K : OclAny := null; Sequence{A,B,C,K} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : OclAny := K ; var ans : int := 0 ; s := s - Set{A, K}->min() ; ans := ans + Set{A, K}->min() ; if (s > 0) then ( s := s - B ; if (s > 0) then ( ans := ans - s ) else skip ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- M=998244353 n=int(input()) xs=[0]*n ds=[0]*n for i in range(n): x,d=(int(c)for c in input().split()) ds[i]=d xs[i]=(x,i) import sys sys.setrecursionlimit(max(1000,n)) xs.sort() index=[x[1]for x in xs] xs=[x[0]for x in xs] ds=[ds[ind]for ind in index] def _sub(i): if i==n-1 : return 2,n res=1 ind=i+1 while True : if(xs[i]+ds[i]<=xs[ind]): break o,ind=_sub(ind) res*=o res %=M if ind>=n : break return res+1,ind out=[] done=0 while True : o,done=_sub(done) out.append(o) if done>=n : break result=1 for o in out : result*=o result %=M print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var M : int := 998244353 ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var xs : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var ds : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var d : OclAny := null; Sequence{x,d} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))) (comp_for for (exprlist (expr (atom (name c)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; ds[i+1] := d ; xs[i+1] := Sequence{x, i}) ; skip ; sys.setrecursionlimit(Set{1000, n}->max()) ; xs := xs->sort() ; var index : Sequence := xs->select(x | true)->collect(x | (x[1+1])) ; xs := xs->select(x | true)->collect(x | (x->first())) ; ds := index->select(ind | true)->collect(ind | (ds[ind+1])) ; skip ; var out : Sequence := Sequence{} ; var done : int := 0 ; while true do ( var o : OclAny := null; Sequence{o,done} := _sub(done) ; execute ((o) : out) ; if (done->compareTo(n)) >= 0 then ( break ) else skip) ; var result : int := 1 ; for o : out do ( result := result * o ; result := result mod M) ; execute (result)->display(); operation _sub(i : OclAny) : OclAny pre: true post: true activity: if i = n - 1 then ( return 2, n ) else skip ; var res : int := 1 ; var ind : OclAny := i + 1 ; while true do ( if ((xs[i+1] + ds[i+1]->compareTo(xs[ind+1])) <= 0) then ( break ) else skip ; var o : OclAny := null; Sequence{o,ind} := _sub(ind) ; res := res * o ; res := res mod M ; if (ind->compareTo(n)) >= 0 then ( break ) else skip) ; return res + 1, ind; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush,heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod=10**9+7 inf=float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) a,b,c,k=LI() if a+b>=k : print(min(a,k)) else : print(a-(k-a-b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; sys.setrecursionlimit(2147483647) ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var mod : double := (10)->pow(9) + 7 ; var Math_PINFINITY : double := ("" + (('inf')))->toReal() ; skip ; skip ; var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var k : OclAny := null; Sequence{a,b,c,k} := LI() ; if (a + b->compareTo(k)) >= 0 then ( execute (Set{a, k}->min())->display() ) else ( execute (a - (k - a - b))->display() ); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation LI() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,k=map(int,input().split()) res=0 tmp=min(a,k) res+=tmp k-=tmp if k<=0 : print(res) exit(0) tmp=min(b,k) k-=tmp if k<=0 : print(res) exit(0) tmp=min(c,k) res-=tmp print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var k : OclAny := null; Sequence{a,b,c,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var res : int := 0 ; var tmp : OclAny := Set{a, k}->min() ; res := res + tmp ; k := k - tmp ; if k <= 0 then ( execute (res)->display() ; exit(0) ) else skip ; tmp := Set{b, k}->min() ; k := k - tmp ; if k <= 0 then ( execute (res)->display() ; exit(0) ) else skip ; tmp := Set{c, k}->min() ; res := res - tmp ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,k=[int(i)for i in input().split(" ")] print(min(a,k)-max(0,k-a-b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var k : OclAny := null; Sequence{a,b,c,k} := input().split(" ")->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute (Set{a, k}->min() - Set{0, k - a - b}->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def answerQuery(a,n,l,r): count=0 l=l-1 for i in range(l,r,1): element=a[i] divisors=0 for j in range(l,r,1): if(a[j]% a[i]==0): divisors+=1 else : break if(divisors==(r-l)): count+=1 return count if __name__=='__main__' : a=[1,2,3,5] n=len(a) l=1 r=4 print(answerQuery(a,n,l,r)) l=2 r=4 print(answerQuery(a,n,l,r)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{ 5 }))) ; n := (a)->size() ; l := 1 ; r := 4 ; execute (answerQuery(a, n, l, r))->display() ; l := 2 ; r := 4 ; execute (answerQuery(a, n, l, r))->display() ) else skip; operation answerQuery(a : OclAny, n : OclAny, l : OclAny, r : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; l := l - 1 ; for i : Integer.subrange(l, r-1)->select( $x | ($x - l) mod 1 = 0 ) do ( var element : OclAny := a[i+1] ; var divisors : int := 0 ; for j : Integer.subrange(l, r-1)->select( $x | ($x - l) mod 1 = 0 ) do ( if (a[j+1] mod a[i+1] = 0) then ( divisors := divisors + 1 ) else ( break )) ; if (divisors = (r - l)) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np import math a,b=map(int,input().split()) h=100 w=100 char_white='.' char_black='#' fields_w=[[char_white for _ in range(int(w/2))]for _ in range(h)] fields_b=[[char_black for _ in range(int(w/2))]for _ in range(h)] spaces_per_row=math.ceil((int(w/2)-2)/2.0) for i in range(a-1): col=i % spaces_per_row row=i//spaces_per_row fields_b[row*2+1][col*2+1]=char_white for i in range(b-1): col=i % spaces_per_row row=i//spaces_per_row fields_w[row*2+1][col*2+1]=char_black res=np.concatenate((fields_w,fields_b),1) print(str(h)+''+str(w)) for row in res : print(''.join(row)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var h : int := 100 ; var w : int := 100 ; var char_white : String := '.' ; var char_black : String := '#' ; var fields_w : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, ("" + ((w / 2)))->toInteger()-1)->select(_anon | true)->collect(_anon | (char_white)))) ; var fields_b : Sequence := Integer.subrange(0, h-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, ("" + ((w / 2)))->toInteger()-1)->select(_anon | true)->collect(_anon | (char_black)))) ; var spaces_per_row : double := ((("" + ((w / 2)))->toInteger() - 2) / 2.0)->ceil() ; for i : Integer.subrange(0, a - 1-1) do ( var col : int := i mod spaces_per_row ; var row : int := i div spaces_per_row ; fields_b[row * 2 + 1+1][col * 2 + 1+1] := char_white) ; for i : Integer.subrange(0, b - 1-1) do ( col := i mod spaces_per_row ; row := i div spaces_per_row ; fields_w[row * 2 + 1+1][col * 2 + 1+1] := char_black) ; var res : (trailer . (name concatenate) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name fields_w)))))) , (test (logical_test (comparison (expr (atom (name fields_b))))))) ))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ))) := ; execute (("" + ((h))) + '' + ("" + ((w))))->display() ; for row : res do ( execute (StringLib.sumStringsWithSeparator((row), ''))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printUncommon(arr1,arr2,n1,n2): i=0 j=0 k=0 while(iunion(Sequence{20}->union(Sequence{ 30 })) ; arr2 := Sequence{20}->union(Sequence{25}->union(Sequence{30}->union(Sequence{40}->union(Sequence{ 50 })))) ; n1 := (arr1)->size() ; n2 := (arr2)->size() ; printUncommon(arr1, arr2, n1, n2); operation printUncommon(arr1 : OclAny, arr2 : OclAny, n1 : OclAny, n2 : OclAny) pre: true post: true activity: var i : int := 0 ; var j : int := 0 ; var k : int := 0 ; while ((i->compareTo(n1)) < 0 & (j->compareTo(n2)) < 0) do ( if ((arr1[i+1]->compareTo(arr2[j+1])) < 0) then ( execute (arr1[i+1])->display() ; i := i + 1 ; k := k + 1 ) else (if ((arr2[j+1]->compareTo(arr1[i+1])) < 0) then ( execute (arr2[j+1])->display() ; k := k + 1 ; j := j + 1 ) else ( i := i + 1 ; j := j + 1 ) ) ) ; while ((i->compareTo(n1)) < 0) do ( execute (arr1[i+1])->display() ; i := i + 1 ; k := k + 1) ; while ((j->compareTo(n2)) < 0) do ( execute (arr2[j+1])->display() ; j := j + 1 ; k := k + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def dfs(x,y,x1,y1): v.add((x,y)) for dx,dy in[(-1,0),(0,1),(1,0),(0,-1)]: if x+dx>=0 and x+dx=0 and y+dycollect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | ((OclFile["System.in"]).readLine())) ; var v : Set := Set{}->union(()) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( if not((v)->includes(Sequence{i, j})) & dfs(i, j, -1, -1) then ( execute ('Yes')->display() ; quit() ) else skip)) ; execute ('No')->display(); operation dfs(x : OclAny, y : OclAny, x1 : OclAny, y1 : OclAny) : OclAny pre: true post: true activity: execute ((Sequence{x, y}) : v) ; for _tuple : Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{1, 0}}->union(Sequence{ Sequence{0, -1} }))) do (var _indx : int := 1; var dx : OclAny := _tuple->at(_indx); _indx := _indx + 1; var dy : OclAny := _tuple->at(_indx); if x + dx >= 0 & (x + dx->compareTo(n)) < 0 & y + dy >= 0 & (y + dy->compareTo(m)) < 0 & Sequence{x + dx, y + dy} /= Sequence{x1, y1} & a[x + dx+1][y + dy+1] = a[x+1][y+1] then ( if (v)->includes(Sequence{x + dx, y + dy}) or dfs(x + dx, y + dy, x, y) then ( return true ) else skip ) else skip) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**6) def dfs(y,x,caractere): global ladj,visited,altura,largura if y<0 or x<0 or y>=altura or x>=largura : return False if ladj[y][x]!=caractere : return False if visited[y][x]==1 : return False if visited[y][x]==2 : return True visited[y][x]=1 if dfs(y+1,x,caractere)or dfs(y-1,x,caractere)or dfs(y,x+1,caractere)or dfs(y,x-1,caractere): return True visited[y][x]=2 altura,largura=map(int,input().split()) ladj=[] visited=[] for i in range(altura): ladj.append(list(input())) visited.append([0]*largura) for i in range(altura): for j in range(largura): if visited[i][j]==0 : if dfs(i,j,ladj[i][j]): print('Yes') exit() print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { attribute ladj : OclAny; attribute visited : OclAny; attribute altura : OclAny; attribute largura : OclAny; operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(6)) ; skip ; Sequence{altura,largura} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; ladj := Sequence{} ; visited := Sequence{} ; for i : Integer.subrange(0, altura-1) do ( execute ((((OclFile["System.in"]).readLine())->characters()) : ladj) ; execute ((MatrixLib.elementwiseMult(Sequence{ 0 }, largura)) : visited)) ; for i : Integer.subrange(0, altura-1) do ( for j : Integer.subrange(0, largura-1) do ( if visited[i+1][j+1] = 0 then ( if dfs(i, j, ladj[i+1][j+1]) then ( execute ('Yes')->display() ; exit() ) else skip ) else skip)) ; execute ('No')->display(); operation dfs(y : OclAny, x : OclAny, caractere : OclAny) : OclAny pre: true post: true activity: skip; skip; skip; skip ; if y < 0 or x < 0 or (y->compareTo(altura)) >= 0 or (x->compareTo(largura)) >= 0 then ( return false ) else skip ; if ladj[y+1][x+1] /= caractere then ( return false ) else skip ; if visited[y+1][x+1] = 1 then ( return false ) else skip ; if visited[y+1][x+1] = 2 then ( return true ) else skip ; visited[y+1][x+1] := 1 ; if dfs(y + 1, x, caractere) or dfs(y - 1, x, caractere) or dfs(y, x + 1, caractere) or dfs(y, x - 1, caractere) then ( return true ) else skip ; visited[y+1][x+1] := 2; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin def isvaild(x,y): if x>=0 and x=0 and y= 0 & (x->compareTo(a)) < 0 & y >= 0 & (y->compareTo(b)) < 0 then ( return true ) else ( return false ); operation dfs(i : OclAny, j : OclAny) : OclAny pre: true post: true activity: var q : Sequence := Sequence{ Sequence{i}->union(Sequence{ j }) } ; var indexs : Sequence := Sequence{Sequence{1}->union(Sequence{ 0 })}->union(Sequence{Sequence{0}->union(Sequence{ 1 })}->union(Sequence{Sequence{-1}->union(Sequence{ 0 })}->union(Sequence{ Sequence{0}->union(Sequence{ -1 }) }))) ; while q do ( Sequence{x,y} := q->last() ; q := q->front() ; for item : indexs do ( var k : OclAny := null; var h : OclAny := null; Sequence{k,h} := item ; if isvaild(x + k, y + h) & visit[x + k+1][y + h+1] & l[x+1][y+1] = l[x + k+1][y + h+1] then ( if (q)->includes(Sequence{x + k}->union(Sequence{ y + h })) then ( return true ) else skip ; execute ((Sequence{x + k}->union(Sequence{ y + h })) : q) ) else skip) ; visit[x+1][y+1] := false); operation solve(a : OclAny, b : OclAny, l : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, a-1) do ( for j : Integer.subrange(0, b-1) do ( if visit[i+1][j+1] then ( if dfs(i, j) then ( return true ) else skip ) else skip)) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from typing import List def exists_a_cycle_on_the_field(n : int,m : int,colors : List[str])->str : graph=[[]for i in range(n*m)] for i in range(n): for j in range(m): u=i*m+j u_color=colors[i][j] if i+1collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : a)) ; execute (exists_a_cycle_on_the_field(n, m, a))->display(); operation exists_a_cycle_on_the_field(n : int, m : int, colors : List[OclType["String"]+1]) : String pre: true post: true activity: var graph : Sequence := Integer.subrange(0, n * m-1)->select(i | true)->collect(i | (Sequence{})) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, m-1) do ( var u : double := i * m + j ; var u_color : OclAny := colors[i+1][j+1] ; if (i + 1->compareTo(n)) < 0 & u_color = colors[i + 1+1][j+1] then ( var v : double := (i + 1) * m + j ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)))))))) )))) ) else skip ; if (j + 1->compareTo(m)) < 0 & u_color = colors[i+1][j + 1+1] then ( var w : double := i * m + j + 1 ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name w)))))))) )))) ; (expr (atom (name graph)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name w)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name u)))))))) )))) ) else skip)) ; skip ; skip ; size := n * m ; if isCyclic(size) = true then ( return 'Yes' ) else skip ; return 'No'; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isPrime(x): if(x==0 or x==1): return 0 i=2 while i*i<=x : if(x % i==0): return 0 i=i+1 return 1 def findPrimes(n): if(isPrime(n)): print(n,end=" ") elif(isPrime(n-2)): print("2",end=" ") print(n-2,end=" ") else : print("3",end=" ") n=n-3 i=0 while i; operation isPrime(x : OclAny) : OclAny pre: true post: true activity: if (x = 0 or x = 1) then ( return 0 ) else skip ; var i : int := 2 ; while (i * i->compareTo(x)) <= 0 do ( if (x mod i = 0) then ( return 0 ) else skip ; i := i + 1) ; return 1; operation findPrimes(n : OclAny) pre: true post: true activity: if (isPrime(n)) then ( execute (n)->display() ) else (if (isPrime(n - 2)) then ( execute ("2")->display() ; execute (n - 2)->display() ) else ( execute ("3")->display() ; n := n - 3 ; i := 0 ; while (i->compareTo(n)) < 0 do ( if (isPrime(i) & isPrime(n - i)) then ( execute (i)->display() ; execute ((n - i))->display() ; break ) else skip ; i := i + 1) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect import sys input=sys.stdin.readline class SegmentTreeRMQ(object): def __init__(self,size,value): self.len=1<0 : self.array[i]=max(self.array[i],x) i>>=1 def get(self,i): return self.array[i+self.len] def get_maximum(self,l,r): L=l+self.len R=r+self.len ANS=-1<<30 while L>=1 R>>=1 return ANS N=int(input()) xd_array=[list(map(int,input().split()))for _ in range(N)] xd_array=sorted(xd_array,key=lambda x : x[0]) x_array=[i[0]for i in xd_array] d_array=[i[1]for i in xd_array] mod=998244353 tree=SegmentTreeRMQ(N,-1) ans_array=[0]*(N+1) ans_array[-1]=1 for i in range(N-1,-1,-1): move=x_array[i]+d_array[i]-0.1 max_index=bisect.bisect_left(x_array,move) max_move=max(i,tree.get_maximum(i,max_index)) tree.update(i,max_move) ans_array[i]=(ans_array[i+1]+ans_array[max_move+1])% mod print(ans_array[0]) ------------------------------------------------------------ OCL File: --------- class SegmentTreeRMQ extends object { static operation newSegmentTreeRMQ() : SegmentTreeRMQ pre: true post: SegmentTreeRMQ->exists( _x | result = _x ); attribute len : int := 1 * (2->pow(size.bit_length())); attribute array : Sequence := MatrixLib.elementwiseMult(Sequence{ value }, (2 * self.len)); operation initialise(size : OclAny,value : OclAny) : pre: true post: true activity: self.len := 1 * (2->pow(size.bit_length())) ; self.array := MatrixLib.elementwiseMult(Sequence{ value }, (2 * self.len)); return self; operation update(i : OclAny,x : OclAny) pre: true post: true activity: i := i + self.len ; while i > 0 do ( self.array[i+1] := Set{self.array[i+1], x}->max() ; i := i div (2->pow(1))); operation get(i : OclAny) : OclAny pre: true post: true activity: return self.array[i + self.len+1]; operation get_maximum(l : OclAny,r : OclAny) : OclAny pre: true post: true activity: var L : OclAny := l + self.len ; var R : OclAny := r + self.len ; var ANS : int := -1 * (2->pow(30)) ; while (L->compareTo(R)) < 0 do ( if MathLib.bitwiseAnd(L, 1) then ( ANS := Set{ANS, self.array[L+1]}->max() ; L := L + 1 ) else skip ; if MathLib.bitwiseAnd(R, 1) then ( R := R - 1 ; ANS := Set{ANS, self.array[R+1]}->max() ) else skip ; L := L div (2->pow(1)) ; R := R div (2->pow(1))) ; return ANS; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var xd_array : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; xd_array := xd_array->sortedBy($x | (lambda x : OclAny in (x->first()))->apply($x)) ; var x_array : Sequence := xd_array->select(i | true)->collect(i | (i->first())) ; var d_array : Sequence := xd_array->select(i | true)->collect(i | (i[1+1])) ; var mod : int := 998244353 ; var tree : SegmentTreeRMQ := (SegmentTreeRMQ.newSegmentTreeRMQ()).initialise(N, -1) ; var ans_array : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (N + 1)) ; ans_array->last() := 1 ; for i : Integer.subrange(-1 + 1, N - 1)->reverse() do ( var move : double := x_array[i+1] + d_array[i+1] - 0.1 ; var max_index : OclAny := bisect.bisect_left(x_array, move) ; var max_move : OclAny := Set{i, tree.get_maximum(i, max_index)}->max() ; execute ((i, max_move) <: tree) ; ans_array[i+1] := (ans_array[i + 1+1] + ans_array[max_move + 1+1]) mod mod) ; execute (ans_array->first())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math t=eval(input()) for i in range(t): n=eval(input()) h1=math.ceil(n/3) h2=h1 h3=h1 if n-(h1+h2+h3)<0 : h3-=(h1+h2+h3)-n elif n-(h1+h2+h3)==0 : h1+=1 if h1==h2 : h1+=1 h2-=1 if h2==h3 and(h1+h2+h3)==n : h2+=1 h3-=1 elif h2==h3 : h3-=(h1+h2+h3)-n print(h2,h1,h3) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var t : OclAny := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := (OclFile["System.in"]).readLine() ; var h1 : double := (n / 3)->ceil() ; var h2 : OclAny := h1 ; var h3 : OclAny := h1 ; if n - (h1 + h2 + h3) < 0 then ( h3 := h3 - (h1 + h2 + h3) - n ) else (if n - (h1 + h2 + h3) = 0 then ( h1 := h1 + 1 ) else skip) ; if h1 = h2 then ( h1 := h1 + 1 ; h2 := h2 - 1 ) else skip ; if h2 = h3 & (h1 + h2 + h3) = n then ( h2 := h2 + 1 ; h3 := h3 - 1 ) else (if h2 = h3 then ( h3 := h3 - (h1 + h2 + h3) - n ) else skip) ; execute (h2)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): x=int(input()) if(x % 3==0): print(x//3,x//3+1,x//3-1) elif(x % 3==1): print(x//3,x//3+2,x//3-1) else : print(x//3+1,x//3+2,x//3-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if (x mod 3 = 0) then ( execute (x div 3)->display() ) else (if (x mod 3 = 1) then ( execute (x div 3)->display() ) else ( execute (x div 3 + 1)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) if n % 3==0 : d=(n-3)//3 print(d+1,d+2,d) elif n % 3==1 : d=(n-4)//3 print(d+1,d+3,d) else : d=(n-5)//3 print(d+2,d+3,d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n mod 3 = 0 then ( var d : int := (n - 3) div 3 ; execute (d + 1)->display() ) else (if n mod 3 = 1 then ( d := (n - 4) div 3 ; execute (d + 1)->display() ) else ( d := (n - 5) div 3 ; execute (d + 2)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def MI(): return map(int,sys.stdin.readline().rstrip().split()) A,B=MI() q1,r1=(B-1)//50,(B-1)% 50 q1+=1 q2,r2=(A-1)//50,(A-1)% 50 q2+=1 if B>1 and A>1 : print(2*(q1+q2),100) elif(B==1 and A>1)or(B>1 and A==1): print(2*(q1+q2)-1,100) else : print(2,100) if B>1 : for i in range(2*q1): if i % 2==1 : print(''.join(['.']*100)) elif i!=2*q1-2 : print(''.join(['.','#']*50)) else : print(''.join(['.','#']*r1+['.']*(100-2*r1))) else : print(''.join(['.']*100)) if A>1 : for i in range(2*q2): if i % 2==0 : print(''.join(['#']*100)) elif i!=2*q2-1 : print(''.join(['#','.']*50)) else : print(''.join(['#','.']*r2+['#']*(100-2*r2))) else : print(''.join(['#']*100)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := MI() ; var q1 : OclAny := null; var r1 : OclAny := null; Sequence{q1,r1} := Sequence{(B - 1) div 50,(B - 1) mod 50} ; q1 := q1 + 1 ; var q2 : OclAny := null; var r2 : OclAny := null; Sequence{q2,r2} := Sequence{(A - 1) div 50,(A - 1) mod 50} ; q2 := q2 + 1 ; if B > 1 & A > 1 then ( execute (2 * (q1 + q2))->display() ) else (if (B = 1 & A > 1) or (B > 1 & A = 1) then ( execute (2 * (q1 + q2) - 1)->display() ) else ( execute (2)->display() ) ) ; if B > 1 then ( for i : Integer.subrange(0, 2 * q1-1) do ( if i mod 2 = 1 then ( execute (StringLib.sumStringsWithSeparator((MatrixLib.elementwiseMult(Sequence{ '.' }, 100)), ''))->display() ) else (if i /= 2 * q1 - 2 then ( execute (StringLib.sumStringsWithSeparator((MatrixLib.elementwiseMult(Sequence{'.'}->union(Sequence{ '#' }), 50)), ''))->display() ) else ( execute (StringLib.sumStringsWithSeparator((MatrixLib.elementwiseMult(Sequence{'.'}->union(Sequence{ '#' }), r1)->union(MatrixLib.elementwiseMult(Sequence{ '.' }, (100 - 2 * r1)))), ''))->display() ) ) ) ) else ( execute (StringLib.sumStringsWithSeparator((MatrixLib.elementwiseMult(Sequence{ '.' }, 100)), ''))->display() ) ; if A > 1 then ( for i : Integer.subrange(0, 2 * q2-1) do ( if i mod 2 = 0 then ( execute (StringLib.sumStringsWithSeparator((MatrixLib.elementwiseMult(Sequence{ '#' }, 100)), ''))->display() ) else (if i /= 2 * q2 - 1 then ( execute (StringLib.sumStringsWithSeparator((MatrixLib.elementwiseMult(Sequence{'#'}->union(Sequence{ '.' }), 50)), ''))->display() ) else ( execute (StringLib.sumStringsWithSeparator((MatrixLib.elementwiseMult(Sequence{'#'}->union(Sequence{ '.' }), r2)->union(MatrixLib.elementwiseMult(Sequence{ '#' }, (100 - 2 * r2)))), ''))->display() ) ) ) ) else ( execute (StringLib.sumStringsWithSeparator((MatrixLib.elementwiseMult(Sequence{ '#' }, 100)), ''))->display() ); operation MI() : OclAny pre: true post: true activity: return (sys.stdin.readLine().rstrip().split())->collect( _x | (OclType["int"])->apply(_x) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : n=int(input()) a=3 b=2 c=1 r=n-6 while r>=3 : c+=1 b+=1 a+=1 r-=3 while r>=2 : b+=1 a+=1 r-=2 if r==1 : a+=1 print(b,a,c) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : int := 3 ; var b : int := 2 ; var c : int := 1 ; var r : double := n - 6 ; while r >= 3 do ( c := c + 1 ; b := b + 1 ; a := a + 1 ; r := r - 3) ; while r >= 2 do ( b := b + 1 ; a := a + 1 ; r := r - 2) ; if r = 1 then ( a := a + 1 ) else skip ; execute (b)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- _t=int(input()) for i in range(0,_t): _n=int(input()) if _n % 3==0 : print(int(_n/3),int(_n/3+1),int(_n/3-1)) elif _n % 3==1 : print(int(_n/3),int(_n/3+2),int(_n/3-1)) else : print(int(_n/3+1),int(_n/3+2),int(_n/3-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var _t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, _t-1) do ( var _n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if _n mod 3 = 0 then ( execute (("" + ((_n / 3)))->toInteger())->display() ) else (if _n mod 3 = 1 then ( execute (("" + ((_n / 3)))->toInteger())->display() ) else ( execute (("" + ((_n / 3 + 1)))->toInteger())->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def dist(p1,p2): return sqrt((p1[0]-p2[0])**2+(p1[1]-p2[1])**2) x1,y1,x2,y2=[int(x)for x in input().split()] x1,x2=min(x1,x2),max(x1,x2) y1,y2=min(y1,y2),max(y1,y2) gs={} for x in[x1,x2]: for y in range(y1,y2+1): gs[(x,y)]=False for y in[y1,y2]: for x in range(x1,x2+1): gs[(x,y)]=False n=int(input()) for _ in range(n): x,y,r=[int(x)for x in input().split()] for g in gs : if not gs[g]: d=dist(g,(x,y)) if d<=r : gs[g]=True res=sum([1 for v in gs.values()if not v]) print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var x1 : OclAny := null; var x2 : OclAny := null; Sequence{x1,x2} := Sequence{Set{x1, x2}->min(),Set{x1, x2}->max()} ; var y1 : OclAny := null; var y2 : OclAny := null; Sequence{y1,y2} := Sequence{Set{y1, y2}->min(),Set{y1, y2}->max()} ; var gs : OclAny := Set{} ; for x : Sequence{x1}->union(Sequence{ x2 }) do ( for y : Integer.subrange(y1, y2 + 1-1) do ( gs[Sequence{x, y}+1] := false)) ; for y : Sequence{y1}->union(Sequence{ y2 }) do ( for x : Integer.subrange(x1, x2 + 1-1) do ( gs[Sequence{x, y}+1] := false)) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; var r : OclAny := null; Sequence{x,y,r} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for g : gs do ( if not(gs[g+1]) then ( var d : OclAny := dist(g, Sequence{x, y}) ; if (d->compareTo(r)) <= 0 then ( gs[g+1] := true ) else skip ) else skip)) ; var res : OclAny := (gs.values()->select(v | not(v))->collect(v | (1)))->sum() ; execute (res)->display(); operation dist(p1 : OclAny, p2 : OclAny) : OclAny pre: true post: true activity: return sqrt(((p1->first() - p2->first()))->pow(2) + ((p1[1+1] - p2[1+1]))->pow(2)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c,d=map(int,input().split()) if a>c : a,c=c,a if b>d : b,d=d,b z=[tuple(map(int,input().split()))for _ in " "*int(input())] ans=0 for i in range(a,c+1): for x,y,r in z : if(i-x)**2+(y-b)**2<=r**2 : break else : ans+=1 for i in range(b+1,d): for x,y,r in z : if(c-x)**2+(i-y)**2<=r**2 : break else : ans+=1 for i in range(a,c+1): for x,y,r in z : if(i-x)**2+(y-d)**2<=r**2 : break else : ans+=1 for i in range(b+1,d): for x,y,r in z : if(a-x)**2+(i-y)**2<=r**2 : break else : ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var d : OclAny := null; Sequence{a,b,c,d} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (a->compareTo(c)) > 0 then ( var a : OclAny := null; var c : OclAny := null; Sequence{a,c} := Sequence{c,a} ) else skip ; if (b->compareTo(d)) > 0 then ( var b : OclAny := null; var d : OclAny := null; Sequence{b,d} := Sequence{d,b} ) else skip ; var z : Sequence := StringLib.nCopies(" ", ("" + (((OclFile["System.in"]).readLine())))->toInteger())->select(_anon | true)->collect(_anon | (((input().split())->collect( _x | (OclType["int"])->apply(_x) )))) ; var ans : int := 0 ; for i : Integer.subrange(a, c + 1-1) do ((compound_stmt for (exprlist (expr (atom (name x))) , (expr (atom (name y))) , (expr (atom (name r)))) in (testlist (test (logical_test (comparison (expr (atom (name z))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (name x)))))))) ))) ** (expr (atom (number (integer 2))))) + (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (name b)))))))) ))) ** (expr (atom (number (integer 2))))))) <= (comparison (expr (expr (atom (name r))) ** (expr (atom (number (integer 2))))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))))) ; for i : Integer.subrange(b + 1, d-1) do ((compound_stmt for (exprlist (expr (atom (name x))) , (expr (atom (name y))) , (expr (atom (name r)))) in (testlist (test (logical_test (comparison (expr (atom (name z))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name c))) - (expr (atom (name x)))))))) ))) ** (expr (atom (number (integer 2))))) + (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (name y)))))))) ))) ** (expr (atom (number (integer 2))))))) <= (comparison (expr (expr (atom (name r))) ** (expr (atom (number (integer 2))))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))))) ; for i : Integer.subrange(a, c + 1-1) do ((compound_stmt for (exprlist (expr (atom (name x))) , (expr (atom (name y))) , (expr (atom (name r)))) in (testlist (test (logical_test (comparison (expr (atom (name z))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (name x)))))))) ))) ** (expr (atom (number (integer 2))))) + (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name y))) - (expr (atom (name d)))))))) ))) ** (expr (atom (number (integer 2))))))) <= (comparison (expr (expr (atom (name r))) ** (expr (atom (number (integer 2))))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))))) ; for i : Integer.subrange(b + 1, d-1) do ((compound_stmt for (exprlist (expr (atom (name x))) , (expr (atom (name y))) , (expr (atom (name r)))) in (testlist (test (logical_test (comparison (expr (atom (name z))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name a))) - (expr (atom (name x)))))))) ))) ** (expr (atom (number (integer 2))))) + (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name i))) - (expr (atom (name y)))))))) ))) ** (expr (atom (number (integer 2))))))) <= (comparison (expr (expr (atom (name r))) ** (expr (atom (number (integer 2))))))))) : (suite (stmt (simple_stmt (small_stmt break))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=lambda : map(int,input().split()) x1,y1,x2,y2=I() if x1>x2 : x2,x1=x1,x2 if y1>y2 : y2,y1=y1,y2 n=int(input()) ans=0 l=[] z=[] for _ in range(n): a,b,c=I() l.append((a,b,c)) for i in range(x1,x2+1): z.append((i,y1)) z.append((i,y2)) for i in range(y1,y2+1): z.append((x1,i)) z.append((x2,i)) z=set(z) for p in z : for q in l : if((p[0]-q[0])**2+(p[1]-q[1])**2)<=q[2]**2 : ans+=1 break print(len(z)-ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var x1 : OclAny := null; var y1 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{x1,y1,x2,y2} := I->apply() ; if (x1->compareTo(x2)) > 0 then ( var x2 : OclAny := null; var x1 : OclAny := null; Sequence{x2,x1} := Sequence{x1,x2} ) else skip ; if (y1->compareTo(y2)) > 0 then ( var y2 : OclAny := null; var y1 : OclAny := null; Sequence{y2,y1} := Sequence{y1,y2} ) else skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ans : int := 0 ; var l : Sequence := Sequence{} ; var z : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := I->apply() ; execute ((Sequence{a, b, c}) : l)) ; for i : Integer.subrange(x1, x2 + 1-1) do ( execute ((Sequence{i, y1}) : z) ; execute ((Sequence{i, y2}) : z)) ; for i : Integer.subrange(y1, y2 + 1-1) do ( execute ((Sequence{x1, i}) : z) ; execute ((Sequence{x2, i}) : z)) ; z := Set{}->union((z)) ; for p : z do ( for q : l do ( if ((((p->first() - q->first()))->pow(2) + ((p[1+1] - q[1+1]))->pow(2))->compareTo((q[2+1])->pow(2))) <= 0 then ( ans := ans + 1 ; break ) else skip)) ; execute ((z)->size() - ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countWays(s): count=[0]*26 ; for x in s : count[ord(x)-ord('a')]=(count[ord(x)-ord('a')])+1 ; count[ord(s[0])-ord('a')]=1 ; ans=1 ; for i in range(26): if(count[i]!=0): ans*=count[i]; return ans ; if __name__=='__main__' : s="acbbcc" ; print(countWays(s)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( s := "acbbcc"; ; execute (countWays(s))->display(); ) else skip; operation countWays(s : OclAny) pre: true post: true activity: var count : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 26); ; for x : s do ( count[(x)->char2byte() - ('a')->char2byte()+1] := (count[(x)->char2byte() - ('a')->char2byte()+1]) + 1;) ; count[(s->first())->char2byte() - ('a')->char2byte()+1] := 1; ; var ans : int := 1; ; for i : Integer.subrange(0, 26-1) do ( if (count[i+1] /= 0) then ( ans := ans * count[i+1]; ) else skip) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def sieve(n,prime): p=2 while(p*p<=n): if(prime[p]==True): i=p*2 while(i<=n): prime[i]=False i=i+p p=p+1 def printPrimeTriplets(n): prime=[True]*(n+1) sieve(n,prime) print("The prime triplets from 1 to ",n,"are :") for i in range(2,n-6+1): if(prime[i]and prime[i+2]and prime[i+6]): print(i,(i+2),(i+6)) elif(prime[i]and prime[i+4]and prime[i+6]): print(i,(i+4),(i+6)) n=25 printPrimeTriplets(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; n := 25 ; printPrimeTriplets(n); operation sieve(n : OclAny, prime : OclAny) pre: true post: true activity: var p : int := 2 ; while ((p * p->compareTo(n)) <= 0) do ( if (prime[p+1] = true) then ( var i : int := p * 2 ; while ((i->compareTo(n)) <= 0) do ( prime[i+1] := false ; i := i + p) ) else skip ; p := p + 1); operation printPrimeTriplets(n : OclAny) pre: true post: true activity: prime := MatrixLib.elementwiseMult(Sequence{ true }, (n + 1)) ; sieve(n, prime) ; execute ("The prime triplets from 1 to ")->display() ; for i : Integer.subrange(2, n - 6 + 1-1) do ( if (prime[i+1] & prime[i + 2+1] & prime[i + 6+1]) then ( execute (i)->display() ) else (if (prime[i+1] & prime[i + 4+1] & prime[i + 6+1]) then ( execute (i)->display() ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()) xd=[map(int,input().split())for _ in range(n)] mod=998244353 INF=10**10 xx=[(x,x+d,i)for i,(x,d)in enumerate(xd,1)] xx.sort() adj=[[]for _ in range(n+1)] stack=[(INF,0)] for l,r,i in xx : while stack[-1][0]<=l : stack.pop() ip=stack[-1][1] adj[ip].append(i) stack.append((r,i)) stack2=[0] d=[-1]*(n+1) d[0]=0 c=[[]for _ in range(n+1)] order=[] while stack2 : u=stack2.pop() order.append(u) for v in adj[u]: if d[v]==-1 : d[v]=d[u]+1 c[u].append(v) stack2.append(v) dp=[1]*(n+1) for u in order[: :-1]: for v in c[u]: dp[u]*=dp[v] dp[u]%=mod dp[u]+=1 dp[u]%=mod ans=dp[0]-1 ans %=mod print(ans) if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var xd : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var mod : int := 998244353 ; var INF : double := (10)->pow(10) ; var xx : Sequence := Integer.subrange(1, (xd, 1)->size())->collect( _indx | Sequence{_indx-1, (xd, 1)->at(_indx)} )->select(_tuple | true)->collect(_tuple | let i : OclAny = _tuple->at(1) in let Sequence{x, d} : OclAny = _tuple->at(2) in (Sequence{x, x + d, i})) ; xx := xx->sort() ; var adj : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var stack : Sequence := Sequence{ Sequence{INF, 0} } ; for _tuple : xx do (var _indx : int := 1; var l : OclAny := _tuple->at(_indx); _indx := _indx + 1; var r : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); while (stack->last()->first()->compareTo(l)) <= 0 do ( stack := stack->front()) ; var ip : OclAny := stack->last()[1+1] ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name ip)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) )))) ; execute ((Sequence{r, i}) : stack)) ; var stack2 : Sequence := Sequence{ 0 } ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, (n + 1)) ; d->first() := 0 ; var c : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; var order : Sequence := Sequence{} ; while stack2 do ( var u : OclAny := stack2->last() ; stack2 := stack2->front() ; execute ((u) : order) ; for v : adj[u+1] do ( if d[v+1] = -1 then ( d[v+1] := d[u+1] + 1 ; (expr (atom (name c)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name v)))))))) )))) ; execute ((v) : stack2) ) else skip)) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (n + 1)) ; for u : order(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( for v : c[u+1] do ( dp[u+1] := dp[u+1] * dp[v+1] ; dp[u+1] := dp[u+1] mod mod) ; dp[u+1] := dp[u+1] + 1 ; dp[u+1] := dp[u+1] mod mod) ; var ans : double := dp->first() - 1 ; ans := ans mod mod ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countOfMultiples(n): return(int(n/3)+int(n/5)-int(n/15)); print(countOfMultiples(6)) print(countOfMultiples(16)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; execute (countOfMultiples(6))->display() ; execute (countOfMultiples(16))->display(); operation countOfMultiples(n : OclAny) pre: true post: true activity: return (("" + ((n / 3)))->toInteger() + ("" + ((n / 5)))->toInteger() - ("" + ((n / 15)))->toInteger());; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math def isDvisibleBy12(num): if(len(num)>=3): d1=int(num[len(num)-1]); if(d1 % 2!=0): return False d2=int(num[len(num)-2]) sum=0 for i in range(0,len(num)): sum+=int(num[i]) return(sum % 3==0 and(d2*10+d1)% 4==0) else : number=int(num) return(number % 12==0) num="12244824607284961224" if(isDvisibleBy12(num)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; num := "12244824607284961224" ; if (isDvisibleBy12(num)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isDvisibleBy12(num : OclAny) : OclAny pre: true post: true activity: if ((num)->size() >= 3) then ( var d1 : int := ("" + ((num[(num)->size() - 1+1])))->toInteger(); ; if (d1 mod 2 /= 0) then ( return false ) else skip ; var d2 : int := ("" + ((num[(num)->size() - 2+1])))->toInteger() ; var sum : int := 0 ; for i : Integer.subrange(0, (num)->size()-1) do ( sum := sum + ("" + ((num[i+1])))->toInteger()) ; return (sum mod 3 = 0 & (d2 * 10 + d1) mod 4 = 0) ) else ( var number : int := ("" + ((num)))->toInteger() ; return (number mod 12 = 0) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B=map(int,input().split()) ans=[[None for _ in range(100)]for _ in range(100)] for i in range(100): for j in range(100): ans[i][j]='#' if i<50 else '.' A-=1 B-=1 i,j=0,0 while A>0 : ans[i][j]='.' A-=1 j+=2 if j>=100 : j=0 i+=2 i,j=51,0 while B>0 : ans[i][j]='#' B-=1 j+=2 if j>=100 : j=0 i+=2 print(100,100) for i in range(100): print(*ans[i],sep='') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : Sequence := Integer.subrange(0, 100-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, 100-1)->select(_anon | true)->collect(_anon | (null)))) ; for i : Integer.subrange(0, 100-1) do ( for j : Integer.subrange(0, 100-1) do ( ans[i+1][j+1] := if i < 50 then '#' else '.' endif)) ; A := A - 1 ; B := B - 1 ; var i : OclAny := null; var j : OclAny := null; Sequence{i,j} := Sequence{0,0} ; while A > 0 do ( ans[i+1][j+1] := '.' ; A := A - 1 ; j := j + 2 ; if j >= 100 then ( var j : int := 0 ; i := i + 2 ) else skip) ; var i : OclAny := null; Sequence{i,j} := Sequence{51,0} ; while B > 0 do ( ans[i+1][j+1] := '#' ; B := B - 1 ; j := j + 2 ; if j >= 100 then ( j := 0 ; i := i + 2 ) else skip) ; execute (100)->display() ; for i : Integer.subrange(0, 100-1) do ( execute ((argument * (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from heapq import heappush,heappop INF=10**20 while True : n=int(input()) if n==0 : break buil_point=[None]*n for _ in range(n): b,x,y=map(int,input().split()) buil_point[b-1]=(x,y) edges=[[]for _ in range(n)] for i in range(n): for j in range(i+1,n): ix,iy=buil_point[i] jx,jy=buil_point[j] cost=((jx-ix)**2+(jy-iy)**2)**(1/2) if cost<=50 : edges[i].append((cost,j)) edges[j].append((cost,i)) m=int(input()) for _ in range(m): s,g=map(int,input().split()) costs=[INF]*n costs[s-1]=0 paths=[[]]*n paths[s-1]=[s-1] que=[] heappush(que,(0,[s-1])) while que : dist,path=heappop(que) last=path[-1] for cost,to in edges[last]: if costs[to]>dist+cost : costs[to]=dist+cost paths[to]=path+[to] heappush(que,(dist+cost,path+[to])) if paths[g-1]: print(*list(map(lambda x : x+1,paths[g-1]))) else : print("NA") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var INF : double := (10)->pow(20) ; while true do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if n = 0 then ( break ) else skip ; var buil_point : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, n) ; for _anon : Integer.subrange(0, n-1) do ( var b : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{b,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; buil_point[b - 1+1] := Sequence{x, y}) ; var edges : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i + 1, n-1) do ( var ix : OclAny := null; var iy : OclAny := null; Sequence{ix,iy} := buil_point[i+1] ; var jx : OclAny := null; var jy : OclAny := null; Sequence{jx,jy} := buil_point[j+1] ; var cost : double := ((((jx - ix))->pow(2) + ((jy - iy))->pow(2)))->pow((1 / 2)) ; if cost <= 50 then ( (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name cost)))))) , (test (logical_test (comparison (expr (atom (name j))))))) )))))))) )))) ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name cost)))))) , (test (logical_test (comparison (expr (atom (name i))))))) )))))))) )))) ) else skip)) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, m-1) do ( var s : OclAny := null; var g : OclAny := null; Sequence{s,g} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var costs : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, n) ; costs[s - 1+1] := 0 ; var paths : Sequence := MatrixLib.elementwiseMult(Sequence{ Sequence{} }, n) ; paths[s - 1+1] := Sequence{ s - 1 } ; var que : Sequence := Sequence{} ; heappush(que, Sequence{0, Sequence{ s - 1 }}) ; while que do ( var dist : OclAny := null; var path : OclAny := null; Sequence{dist,path} := heappop(que) ; var last : OclAny := path->last() ; for _tuple : edges[last+1] do (var _indx : int := 1; var cost : OclAny := _tuple->at(_indx); _indx := _indx + 1; var to : OclAny := _tuple->at(_indx); if (costs[to+1]->compareTo(dist + cost)) > 0 then ( costs[to+1] := dist + cost ; paths[to+1] := path->union(Sequence{ to }) ; heappush(que, Sequence{dist + cost, path->union(Sequence{ to })}) ) else skip)) ; if paths[g - 1+1] then ( execute ((argument * (test (logical_test (comparison (expr (atom (name list)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test lambda (varargslist (vardef_parameters (vardef_parameter (name x)))) : (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (number (integer 1)))))))))) , (argument (test (logical_test (comparison (expr (atom (name paths)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name g))) - (expr (atom (number (integer 1)))))))))) ])))))))) ))))))))) )))))))))->display() ) else ( execute ("NA")->display() ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt from heapq import heappush,heappop while 1 : N=int(input()) if N==0 : break G=[[]for i in range(N)] P=[None]*N for i in range(N): b,x,y=map(int,input().split()) P[b-1]=(x,y) for i in range(N): xi,yi=P[i] for j in range(i): xj,yj=P[j] dd=(xi-xj)**2+(yi-yj)**2 if dd<=2500 : d=sqrt(dd) G[i].append((j,d)) G[j].append((i,d)) INF=10**18 M=int(input()) for i in range(M): s,t=map(int,input().split()); s-=1 ; t-=1 que=[(0,s)] dist=[INF]*N prv=[0]*N dist[s]=0 while que : cost,v=heappop(que) if dist[v]toInteger() ; if N = 0 then ( break ) else skip ; var G : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (Sequence{})) ; var P : Sequence := MatrixLib.elementwiseMult(Sequence{ null }, N) ; for i : Integer.subrange(0, N-1) do ( var b : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{b,x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; P[b - 1+1] := Sequence{x, y}) ; for i : Integer.subrange(0, N-1) do ( var xi : OclAny := null; var yi : OclAny := null; Sequence{xi,yi} := P[i+1] ; for j : Integer.subrange(0, i-1) do ( var xj : OclAny := null; var yj : OclAny := null; Sequence{xj,yj} := P[j+1] ; var dd : double := ((xi - xj))->pow(2) + ((yi - yj))->pow(2) ; if dd <= 2500 then ( var d : OclAny := sqrt(dd) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name j)))))) , (test (logical_test (comparison (expr (atom (name d))))))) )))))))) )))) ; (expr (atom (name G)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name j)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name i)))))) , (test (logical_test (comparison (expr (atom (name d))))))) )))))))) )))) ) else skip)) ; var INF : double := (10)->pow(18) ; var M : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, M-1) do ( var s : OclAny := null; var t : OclAny := null; Sequence{s,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); s := s - 1; t := t - 1 ; var que : Sequence := Sequence{ Sequence{0, s} } ; var dist : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, N) ; var prv : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, N) ; dist[s+1] := 0 ; while que do ( var cost : OclAny := null; var v : OclAny := null; Sequence{cost,v} := heappop(que) ; if (dist[v+1]->compareTo(cost)) < 0 then ( continue ) else skip ; for _tuple : G[v+1] do (var _indx : int := 1; var w : OclAny := _tuple->at(_indx); _indx := _indx + 1; var d : OclAny := _tuple->at(_indx); if (dist[v+1] + d->compareTo(dist[w+1])) < 0 then ( dist[w+1] := dist[v+1] + d; var r : OclAny := dist[v+1] + d ; heappush(que, Sequence{r, w}) ; prv[w+1] := v ) else skip)) ; if dist[t+1] = INF then ( execute ("NA")->display() ) else ( var ans : Sequence := Sequence{} ; var v : OclAny := t ; while v /= s do ( execute ((v + 1) : ans) ; v := prv[v+1]) ; execute ((s + 1) : ans) ; ans := ans->reverse() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display() ))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(): from sys import stdin from itertools import combinations from heapq import heappush,heappop f_i=stdin while True : n=int(f_i.readline()) if n==0 : break bldgs=(tuple(map(int,f_i.readline().split()))for i in range(n)) adj=[[]for i in range(n+1)] for b1,b2 in combinations(bldgs,2): n1,x1,y1=b1 n2,x2,y2=b2 d=(x1-x2)**2+(y1-y2)**2 if d<=2500 : d**=0.5 adj[n1].append((n2,d)) adj[n2].append((n1,d)) m=int(f_i.readline()) for i in range(m): s,g=map(int,f_i.readline().split()) pq=[[0,s]] isCalculated=[False]*(n+1) distance=[250000]*(n+1) distance[s]=0 while pq : path1=heappop(pq) n1=path1[-1] if n1==g : print(*path1[1 :]) break if path1[0]>distance[n1]: continue isCalculated[n1]=True for n2,d2 in adj[n1]: if isCalculated[n2]: continue t_d=distance[n1]+d2 if t_dtoInteger() ; if n = 0 then ( break ) else skip ; var bldgs : OclAny := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name tuple)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int))))))) , (argument (test (logical_test (comparison (expr (atom (name f_i)) (trailer . (name readline) (arguments ( ))) (trailer . (name split) (arguments ( ))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))} ; var adj : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (Sequence{})) ; for _tuple : combinations(bldgs, 2) do (var _indx : int := 1; var b1 : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b2 : OclAny := _tuple->at(_indx); var n1 : OclAny := null; var x1 : OclAny := null; var y1 : OclAny := null; Sequence{n1,x1,y1} := b1 ; var n2 : OclAny := null; var x2 : OclAny := null; var y2 : OclAny := null; Sequence{n2,x2,y2} := b2 ; var d : double := ((x1 - x2))->pow(2) + ((y1 - y2))->pow(2) ; if d <= 2500 then ( d := d->pow(0.5) ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n1)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name n2)))))) , (test (logical_test (comparison (expr (atom (name d))))))) )))))))) )))) ; (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n2)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name n1)))))) , (test (logical_test (comparison (expr (atom (name d))))))) )))))))) )))) ) else skip) ; var m : int := ("" + ((f_i.readLine())))->toInteger() ; for i : Integer.subrange(0, m-1) do ( var s : OclAny := null; var g : OclAny := null; Sequence{s,g} := (f_i.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var pq : Sequence := Sequence{ Sequence{0}->union(Sequence{ s }) } ; var isCalculated : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, (n + 1)) ; var distance : Sequence := MatrixLib.elementwiseMult(Sequence{ 250000 }, (n + 1)) ; distance[s+1] := 0 ; (compound_stmt while (test (logical_test (comparison (expr (atom (name pq)))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name path1)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name heappop)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name pq)))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name n1)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name path1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name n1)))) == (comparison (expr (atom (name g))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom (name path1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name path1)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) > (comparison (expr (atom (name distance)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n1)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt continue)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name isCalculated)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n1)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name True)))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name n2))) , (expr (atom (name d2)))) in (testlist (test (logical_test (comparison (expr (atom (name adj)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n1)))))))) ]))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (expr (atom (name isCalculated)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n2)))))))) ])))))) : (suite (stmt (simple_stmt (small_stmt continue)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name t_d)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name distance)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n1)))))))) ]))) + (expr (atom (name d2))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name t_d)))) < (comparison (expr (atom (name distance)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n2)))))))) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name distance)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name n2)))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name t_d)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name path2)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name path1)) (trailer (arguments [ (subscriptlist (subscript :)) ])))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name path2)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name t_d)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name path2)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n2)))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name heappush)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name pq))))))) , (argument (test (logical_test (comparison (expr (atom (name path2)))))))) ))))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom 'NA'))))))) ))))))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def cal_minimum_time(X): t=0 sum=0 while(sumdisplay() ) else skip; operation cal_minimum_time(X : OclAny) pre: true post: true activity: var t : int := 0 ; var sum : int := 0 ; while ((sum->compareTo(X)) < 0) do ( t := t + 1 ; sum := sum + t;) ; return t;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve(a,b,n): s=0 for i in range(0,n): s+=a[i]+b[i] if n==1 : return a[0]+b[0] if s % n!=0 : return-1 x=s//n for i in range(0,n): if a[i]>x : return-1 if i>0 : a[i]+=b[i-1] b[i-1]=0 if a[i]==x : continue y=a[i]+b[i] if i+1union(Sequence{14}->union(Sequence{21}->union(Sequence{ 1 }))) ; b := Sequence{15}->union(Sequence{7}->union(Sequence{10}->union(Sequence{ 10 }))) ; n := (a)->size() ; execute (solve(a, b, n))->display() ) else skip; operation solve(a : OclAny, b : OclAny, n : OclAny) : OclAny pre: true post: true activity: var s : int := 0 ; for i : Integer.subrange(0, n-1) do ( s := s + a[i+1] + b[i+1]) ; if n = 1 then ( return a->first() + b->first() ) else skip ; if s mod n /= 0 then ( return -1 ) else skip ; var x : int := s div n ; for i : Integer.subrange(0, n-1) do ( if (a[i+1]->compareTo(x)) > 0 then ( return -1 ) else skip ; if i > 0 then ( a[i+1] := a[i+1] + b[i - 1+1] ; b[i - 1+1] := 0 ) else skip ; if a[i+1] = x then ( continue ) else skip ; var y : OclAny := a[i+1] + b[i+1] ; if (i + 1->compareTo(n)) < 0 then ( y := y + b[i + 1+1] ) else skip ; if y = x then ( a[i+1] := y ; b[i+1] := 0 ; if (i + 1->compareTo(n)) < 0 then ( b[i + 1+1] := 0 ) else skip ; continue ) else skip ; if a[i+1] + b[i+1] = x then ( a[i+1] := a[i+1] + b[i+1] ; b[i+1] := 0 ; continue ) else skip ; if (i + 1->compareTo(n)) < 0 & a[i+1] + b[i + 1+1] = x then ( a[i+1] := a[i+1] + b[i + 1+1] ; b[i + 1+1] := 0 ; continue ) else skip ; return -1) ; for i : Integer.subrange(0, n-1) do ( if b[i+1] /= 0 then ( return -1 ) else skip) ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y,m=map(int,input().split()) if(x>y): x,y=y,x if(y>=m): print('0') elif(x+y<=x): print('-1') else : ans=(y-x+y-1)//y x+=y*ans while(xcollect( _x | (OclType["int"])->apply(_x) ) ; if ((x->compareTo(y)) > 0) then ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{y,x} ) else skip ; if ((y->compareTo(m)) >= 0) then ( execute ('0')->display() ) else (if ((x + y->compareTo(x)) <= 0) then ( execute ('-1')->display() ) else ( var ans : int := (y - x + y - 1) div y ; x := x + y * ans ; while ((x->compareTo(m)) < 0) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{x + y,x} ; ans := ans + 1) ; execute (ans)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x,y,m=map(int,input().split()) if x>y : x,y=y,x if y>=m : print(0) exit(0) if y<=0 : print(-1) exit() anw=0 if x<0 : anw+=abs(x)//y x+=(abs(x)//y)*y while max(x,y)y : x,y=y,x x=y+x anw+=1 print(anw) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; var m : OclAny := null; Sequence{x,y,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (x->compareTo(y)) > 0 then ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{y,x} ) else skip ; if (y->compareTo(m)) >= 0 then ( execute (0)->display() ; exit(0) ) else skip ; if y <= 0 then ( execute (-1)->display() ; exit() ) else skip ; var anw : int := 0 ; if x < 0 then ( anw := anw + (x)->abs() div y ; x := x + ((x)->abs() div y) * y ) else skip ; while (Set{x, y}->max()->compareTo(m)) < 0 do ( if (x->compareTo(y)) > 0 then ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{y,x} ) else skip ; var x : OclAny := y + x ; anw := anw + 1) ; execute (anw)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inp=input().split(" ") x=int(inp[0]) y=int(inp[1]) m=int(inp[2]) def f(x,y,m): i=0 while(x=m or y>=m): print("0") elif(x<=0 and y<=0): print("-1") elif((y<0 and x>0)or(x<0 and y>0)): if(y<0): print(-(y//x)+f(x,y % x,m)) else : print(-(x//y)+f(x % y,y,m)) else : print(f(x,y,m)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inp : OclAny := input().split(" ") ; var x : int := ("" + ((inp->first())))->toInteger() ; var y : int := ("" + ((inp[1+1])))->toInteger() ; var m : int := ("" + ((inp[2+1])))->toInteger() ; skip ; if ((x->compareTo(m)) >= 0 or (y->compareTo(m)) >= 0) then ( execute ("0")->display() ) else (if (x <= 0 & y <= 0) then ( execute ("-1")->display() ) else (if ((y < 0 & x > 0) or (x < 0 & y > 0)) then ( if (y < 0) then ( execute (-(y div x) + f(x, y mod x, m))->display() ) else ( execute (-(x div y) + f(x mod y, y, m))->display() ) ) else ( execute (f(x, y, m))->display() ) ) ) ; operation f(x : OclAny, y : OclAny, m : OclAny) : OclAny pre: true post: true activity: var i : int := 0 ; while ((x->compareTo(m)) < 0 & (y->compareTo(m)) < 0) do ( if ((x->compareTo(y)) < 0) then ( x := x + y ) else ( y := y + x ) ; i := i + 1) ; return i; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSubarrWithEqualZeroAndOne(arr,n): mp=dict() Sum=0 count=0 for i in range(n): if(arr[i]==0): arr[i]=-1 Sum+=arr[i] if(Sum==0): count+=1 if(Sum in mp.keys()): count+=mp[Sum] mp[Sum]=mp.get(Sum,0)+1 return count arr=[1,0,0,1,0,1,1] n=len(arr) print("count=",countSubarrWithEqualZeroAndOne(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{1}->union(Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{ 1 })))))) ; n := (arr)->size() ; execute ("count=")->display(); operation countSubarrWithEqualZeroAndOne(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var mp : Map := (arguments ( )) ; var Sum : int := 0 ; var count : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (arr[i+1] = 0) then ( arr[i+1] := -1 ) else skip ; Sum := Sum + arr[i+1] ; if (Sum = 0) then ( count := count + 1 ) else skip ; if ((mp.keys())->includes(Sum)) then ( count := count + mp[Sum+1] ) else skip ; mp[Sum+1] := mp.get(Sum, 0) + 1) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- r,s=[63],''.join(input()+'T' for i in range(8))+'T'*9 for i in range(0,72,9): t=set() for x in r : for y in(x,x-1,x+1,x-9,x+9,x-10,x-8,x+10,x+8): if s[y]=='T' : continue if(yselect( $x | ($x - 0) mod 9 = 0 ) do ( var t : Set := Set{}->union(()) ; for x : r do ( for y : Sequence{x, x - 1, x + 1, x - 9, x + 9, x - 10, x - 8, x + 10, x + 8} do ( if s[y+1] = 'T' then ( continue ) else skip ; if ((y->compareTo(i)) < 0 or s[y - i+1] /= 'S') & ((y->compareTo(i + 9)) < 0 or s[y - i - 9+1] /= 'S') then ( execute ((y) : t) ) else skip)) ; var r : OclAny := t) ; execute (if r then 'WIN' else 'LOSE' endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A,B=map(int,input().split()) if A<=B : mincolor="." maxcolor="#" minnum=A maxnum=B else : mincolor="#" maxcolor="." minnum=B maxnum=A gridmap=[] for i in range(100): gridmap.append([mincolor]*100) for i in range(1,100,2): for j in range(1,98,2): gridmap[i][j]=maxcolor maxnum-=1 if maxnum==0 : break if maxnum==0 : break for k in range(0,100,2): for l in range(0,98,2): if minnum==1 : break gridmap[k][l+1],gridmap[k+1][l]=maxcolor,maxcolor minnum-=1 gridmap[i][j]=maxcolor if j==97 : j=1 i+=2 else : j+=2 if minnum==1 : break print(100,100) for i in range(100): ans="" for j in range(100): ans+=gridmap[i][j] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A : OclAny := null; var B : OclAny := null; Sequence{A,B} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (A->compareTo(B)) <= 0 then ( var mincolor : String := "." ; var maxcolor : String := "#" ; var minnum : OclAny := A ; var maxnum : OclAny := B ) else ( mincolor := "#" ; maxcolor := "." ; minnum := B ; maxnum := A ) ; var gridmap : Sequence := Sequence{} ; for i : Integer.subrange(0, 100-1) do ( execute ((MatrixLib.elementwiseMult(Sequence{ mincolor }, 100)) : gridmap)) ; for i : Integer.subrange(1, 100-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( for j : Integer.subrange(1, 98-1)->select( $x | ($x - 1) mod 2 = 0 ) do ( gridmap[i+1][j+1] := maxcolor ; maxnum := maxnum - 1 ; if maxnum = 0 then ( break ) else skip) ; if maxnum = 0 then ( break ) else skip) ; for k : Integer.subrange(0, 100-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( for l : Integer.subrange(0, 98-1)->select( $x | ($x - 0) mod 2 = 0 ) do ( if minnum = 1 then ( break ) else skip ; var gridmap[k+1][l + 1+1] : OclAny := null; var gridmap[k + 1+1][l+1] : OclAny := null; Sequence{gridmap[k+1][l + 1+1],gridmap[k + 1+1][l+1]} := Sequence{maxcolor,maxcolor} ; minnum := minnum - 1 ; gridmap[i+1][j+1] := maxcolor ; if j = 97 then ( var j : int := 1 ; i := i + 2 ) else ( j := j + 2 )) ; if minnum = 1 then ( break ) else skip) ; execute (100)->display() ; for i : Integer.subrange(0, 100-1) do ( var ans : String := "" ; for j : Integer.subrange(0, 100-1) do ( ans := ans + gridmap[i+1][j+1]) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=str(input()).split() b,c,m=int(a[0]),int(a[1]),int(a[2]) cnt=0 if m==0 : if b<0 and c<0 : cnt=-1 elif m<0 : if b=m or c>=m : print(cnt) else : if b<0 : cnt+=(-b)//c b+=((-b)//c)*c elif c<0 : cnt+=(-c)//b c+=((-c)//b)*b while True : if b>=m or c>=m : break if b>=c : c+=b else : b+=c cnt+=1 print(cnt) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := OclType["String"]((OclFile["System.in"]).readLine()).split() ; var b : OclAny := null; var c : OclAny := null; var m : OclAny := null; Sequence{b,c,m} := Sequence{("" + ((a->first())))->toInteger(),("" + ((a[1+1])))->toInteger(),("" + ((a[2+1])))->toInteger()} ; var cnt : int := 0 ; if m = 0 then ( if b < 0 & c < 0 then ( cnt := -1 ) else skip ) else (if m < 0 then ( if (b->compareTo(m)) < 0 & (c->compareTo(m)) < 0 then ( cnt := -1 ) else skip ) else ( if b <= 0 & c <= 0 then ( cnt := -1 ) else skip ) ) ; if cnt = -1 then ( execute (cnt)->display() ) else ( if m <= 0 then ( execute (cnt)->display() ) else ( if (b->compareTo(m)) >= 0 or (c->compareTo(m)) >= 0 then ( execute (cnt)->display() ) else ( if b < 0 then ( cnt := cnt + (-b) div c ; b := b + ((-b) div c) * c ) else (if c < 0 then ( cnt := cnt + (-c) div b ; c := c + ((-c) div b) * b ) else skip) ; while true do ( if (b->compareTo(m)) >= 0 or (c->compareTo(m)) >= 0 then ( break ) else skip ; if (b->compareTo(c)) >= 0 then ( c := c + b ) else ( b := b + c ) ; cnt := cnt + 1) ; execute (cnt)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys x,y,m=map(int,input().split()) x,y=min(x,y),max(x,y) if x<=0 and y<=0 : print(0 if max(x,y)>=m else-1) elif max(x,y)>=m : print(0) else : dem=0 if x<0 : dem=(-x+y-1)//y x+=dem*y while ycollect( _x | (OclType["int"])->apply(_x) ) ; var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{Set{x, y}->min(),Set{x, y}->max()} ; if x <= 0 & y <= 0 then ( execute (if (Set{x, y}->max()->compareTo(m)) >= 0 then 0 else -1 endif)->display() ) else (if (Set{x, y}->max()->compareTo(m)) >= 0 then ( execute (0)->display() ) else ( var dem : int := 0 ; if x < 0 then ( dem := (-x + y - 1) div y ; x := x + dem * y ) else skip ; while (y->compareTo(m)) < 0 do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := Sequence{y,x + y} ; dem := dem + 1) ; execute (dem)->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[0]+list(map(int,input().split())) b=[0]+list(map(int,input().split())) d1=[n] seen=[[-1]*2 for i in range(n+1)] seen[n][0]=-2 seen[n][1]=-2 while d1 : d2=[] for i in d1 : if seen[i-a[i]][1]==-1 : d2.append((i-a[i],i)) d1=[] while d2 : x,y=d2.pop() if seen[x][1]==-1 : seen[x][1]=y if seen[x+1][1]==-1 : d2.append((x+1,y)) if seen[x+b[x]][0]==-1 : seen[x+b[x]][0]=x d1.append(x+b[x]) if seen[0][1]==-1 : print(-1) exit() ans=[] tmp=0 while tmp!=-2 : ans.append(tmp) tmp=seen[seen[tmp][1]][0] print(len(ans)) print(*ans[: :-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var b : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var d1 : Sequence := Sequence{ n } ; var seen : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ -1 }, 2))) ; seen[n+1]->first() := -2 ; seen[n+1][1+1] := -2 ; while d1 do ( var d2 : Sequence := Sequence{} ; for i : d1 do ( if seen[i - a[i+1]+1][1+1] = -1 then ( execute ((Sequence{i - a[i+1], i}) : d2) ) else skip) ; d1 := Sequence{} ; while d2 do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := d2->last() ; d2 := d2->front() ; if seen[x+1][1+1] = -1 then ( seen[x+1][1+1] := y ) else skip ; if seen[x + 1+1][1+1] = -1 then ( execute ((Sequence{x + 1, y}) : d2) ) else skip ; if seen[x + b[x+1]+1]->first() = -1 then ( seen[x + b[x+1]+1]->first() := x ; execute ((x + b[x+1]) : d1) ) else skip)) ; if seen->first()[1+1] = -1 then ( execute (-1)->display() ; exit() ) else skip ; var ans : Sequence := Sequence{} ; var tmp : int := 0 ; while tmp /= -2 do ( execute ((tmp) : ans) ; tmp := seen[seen[tmp+1][1+1]+1]->first()) ; execute ((ans)->size())->display() ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ]))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque import io,os input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def frog(n,a,b): queue=deque() levels={i : None for i in range(n+1)} levels[n]=(0,None,None) queue.append(n) best_jump=n while len(queue)>0 : current_pos=queue.popleft() no_of_jumps,pos_before_slip,came_from=levels[current_pos] starting_jump=current_pos-best_jump best_jump=min(best_jump,current_pos-a[current_pos-1]) jumps=[0]+list(range(starting_jump,a[current_pos-1]+1)) for jump in jumps : position_after_jump=current_pos-jump if position_after_jump<=0 : sequence=find_sequence(current_pos,levels) print(len(sequence)) print(" ".join(map(str,sequence))) return position_after_slip=position_after_jump+b[position_after_jump-1] if levels[position_after_slip]is None : levels[position_after_slip]=(no_of_jumps+1,position_after_jump,current_pos) queue.append(position_after_slip) print(-1) return def find_sequence(current_pos,levels): sequence=[0] while True : no_of_jumps,pos_before_slip,came_from=levels[current_pos] if pos_before_slip is None : break sequence+=[pos_before_slip] current_pos=came_from return sequence[: :-1] n=int(input()) a=list(map(int,input().decode().split(" "))) b=list(map(int,input().decode().split(" "))) frog(n,a,b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := io.BytesIO(os.readAll()).readline ; skip ; skip ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := ((input().decode().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; b := ((input().decode().split(" "))->collect( _x | (OclType["int"])->apply(_x) )) ; frog(n, a, b); operation frog(n : OclAny, a : OclAny, b : OclAny) pre: true post: true activity: var queue : Sequence := () ; var levels : Map := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | Map{i |-> null})->unionAll() ; levels[n+1] := Sequence{0, null, null} ; execute ((n) : queue) ; var best_jump : OclAny := n ; while (queue)->size() > 0 do ( var current_pos : OclAny := queue->first() ; queue := queue->tail() ; var no_of_jumps : OclAny := null; var pos_before_slip : OclAny := null; var came_from : OclAny := null; Sequence{no_of_jumps,pos_before_slip,came_from} := levels[current_pos+1] ; var starting_jump : double := current_pos - best_jump ; best_jump := Set{best_jump, current_pos - a[current_pos - 1+1]}->min() ; var jumps : Sequence := Sequence{ 0 }->union((Integer.subrange(starting_jump, a[current_pos - 1+1] + 1-1))) ; for jump : jumps do ( var position_after_jump : double := current_pos - jump ; if position_after_jump <= 0 then ( var sequence : OclAny := find_sequence(current_pos, levels) ; execute ((sequence)->size())->display() ; execute (StringLib.sumStringsWithSeparator(((sequence)->collect( _x | (OclType["String"])->apply(_x) )), " "))->display() ; return ) else skip ; var position_after_slip : OclAny := position_after_jump + b[position_after_jump - 1+1] ; if levels[position_after_slip+1] <>= null then ( levels[position_after_slip+1] := Sequence{no_of_jumps + 1, position_after_jump, current_pos} ; execute ((position_after_slip) : queue) ) else skip)) ; execute (-1)->display() ; return; operation find_sequence(current_pos : OclAny, levels : OclAny) : OclAny pre: true post: true activity: sequence := Sequence{ 0 } ; while true do ( var no_of_jumps : OclAny := null; var pos_before_slip : OclAny := null; var came_from : OclAny := null; Sequence{no_of_jumps,pos_before_slip,came_from} := levels[current_pos+1] ; if pos_before_slip <>= null then ( break ) else skip ; sequence := sequence + Sequence{ pos_before_slip } ; current_pos := came_from) ; return sequence(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=[0]+list(map(int,input().split())) b=[0]+list(map(int,input().split())) c=[10**9]*len(a) for i in range(n,0,-1): c[i]=max(0,i+b[i]-a[i+b[i]]) mn=[10**9 for i in range(len(a)+2)] rs=[10**9 for i in range(len(a)+1)] for i in range(n,0,-1): if min(i,c[i])=hi : break hi=mn[hi] if hi!=0 : print(-1) else : print(len(ans)) for i in ans[1 :]: print(i,end=' ') print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var b : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var c : Sequence := MatrixLib.elementwiseMult(Sequence{ (10)->pow(9) }, (a)->size()) ; for i : Integer.subrange(0 + 1, n)->reverse() do ( c[i+1] := Set{0, i + b[i+1] - a[i + b[i+1]+1]}->max()) ; var mn : Sequence := Integer.subrange(0, (a)->size() + 2-1)->select(i | true)->collect(i | ((10)->pow(9))) ; var rs : Sequence := Integer.subrange(0, (a)->size() + 1-1)->select(i | true)->collect(i | ((10)->pow(9))) ; for i : Integer.subrange(0 + 1, n)->reverse() do ( if (Set{i, c[i+1]}->min()->compareTo(mn[i + 1+1])) < 0 then ( mn[i+1] := Set{i, c[i+1]}->min() ; rs[i+1] := i ) else ( mn[i+1] := mn[i + 1+1] ; rs[i+1] := rs[i + 1+1] )) ; var hi : int := n ; var ans : Sequence := Sequence{} ; var i : int := 1 ; while (i->compareTo((n & hi))) <= 0 do ( execute ((rs[hi+1]) : ans) ; if (mn[hi+1]->compareTo(hi)) >= 0 then ( break ) else skip ; hi := mn[hi+1]) ; if hi /= 0 then ( execute (-1)->display() ) else ( execute ((ans)->size())->display() ; for i : ans->tail() do ( execute (i)->display()) ; execute (0)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def task5(n,a,b): F=[None]*(n+1) paths=[[]for i in range(n+1)] F[n]=0 visited=set() current=[n] high=n while True : new_vertexes=[] for i in current : for j in range(i-a[i],high+1): k=j+b[j] if k not in visited : new_vertexes.append(k) visited.add(k) if F[k]is None : paths[k]=(i,j) F[k]=F[i]+1 elif F[i]+1select(i | true)->collect(i | (Sequence{})) ; F[n+1] := 0 ; var visited : Set := Set{}->union(()) ; var current : Sequence := Sequence{ n } ; var high : OclAny := n ; while true do ( var new_vertexes : Sequence := Sequence{} ; for i : current do ( for j : Integer.subrange(i - a[i+1], high + 1-1) do ( var k : OclAny := j + b[j+1] ; if (visited)->excludes(k) then ( execute ((k) : new_vertexes) ; execute ((k) : visited) ) else skip ; if F[k+1] <>= null then ( paths[k+1] := Sequence{i, j} ; F[k+1] := F[i+1] + 1 ) else (if (F[i+1] + 1->compareTo(F[k+1])) < 0 then ( paths[k+1] := Sequence{i, j} ; F[k+1] := F[i+1] + 1 ) else skip)) ; high := Set{high, i - a[i+1]}->min()) ; current := new_vertexes ; if not(current) then ( break ) else skip) ; var path : Sequence := Sequence{} ; if not(F->first() <>= null) then ( current := paths->first() ; while current->first() /= n do ( execute ((current[1+1]) : path) ; current := paths[current->first()+1]) ; execute ((current[1+1]) : path) ) else skip ; return if F->first() <>= null then -1 else F->first() endif, path(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))); operation main() pre: true post: true activity: n := ("" + ((input()->trim())))->toInteger() ; var arr_a : Sequence := Sequence{ 0 }->union(((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var arr_b : Sequence := Sequence{ 0 }->union(((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var result : OclAny := task5(n, arr_a, arr_b) ; execute (result->first())->display() ; if result[1+1] then ( execute ((argument * (test (logical_test (comparison (expr (atom (name result)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countSubString(s,c,k): leftCount=0 rightCount=0 left=0 right=0 freq=0 result=0 Len=len(s) while(s[left]!=c and leftdisplay(); operation countSubString(s : OclAny, c : OclAny, k : OclAny) : OclAny pre: true post: true activity: var leftCount : int := 0 ; var rightCount : int := 0 ; var left : int := 0 ; var right : int := 0 ; var freq : int := 0 ; var result : int := 0 ; var Len : int := (s)->size() ; while (s[left+1] /= c & (left->compareTo(Len)) < 0) do ( left := left + 1 ; leftCount := leftCount + 1) ; right := left + 1 ; while (freq /= (k - 1) & ((right - 1)->compareTo(Len)) < 0) do ( if (s[right+1] = c) then ( freq := freq + 1 ) else skip ; right := right + 1) ; while ((left->compareTo(Len)) < 0 & ((right - 1)->compareTo(Len)) < 0) do ( while (s[left+1] /= c & (left->compareTo(Len)) < 0) do ( left := left + 1 ; leftCount := leftCount + 1) ; while ((right->compareTo(Len)) < 0 & s[right+1] /= c) do ( if (s[right+1] = c) then ( freq := freq + 1 ) else skip ; right := right + 1 ; rightCount := rightCount + 1) ; result := (result + (leftCount + 1) * (rightCount + 1)) ; freq := k - 1 ; leftCount := 0 ; rightCount := 0 ; left := left + 1 ; right := right + 1) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) c_lst=[0]+list(map(int,input().split())) edges=[[]for _ in range(n)] for _ in range(n-1): u,v,p=map(int,input().split()) edges[u].append((v,p)) edges[v].append((u,p)) INF=10**20 used=[False]*n def cost(x): used[x]=True ret=0 pre_cost=0 if x!=0 else INF for to,p in edges[x]: if used[to]: pre_cost=p else : ret+=cost(to) if c_lst[x]==0 : return min(ret,pre_cost) else : return pre_cost print(cost(0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c_lst : Sequence := Sequence{ 0 }->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var edges : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _anon : Integer.subrange(0, n - 1-1) do ( var u : OclAny := null; var v : OclAny := null; var p : OclAny := null; Sequence{u,v,p} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name u)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name v)))))) , (test (logical_test (comparison (expr (atom (name p))))))) )))))))) )))) ; (expr (atom (name edges)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name v)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (atom (name u)))))) , (test (logical_test (comparison (expr (atom (name p))))))) )))))))) ))))) ; var INF : double := (10)->pow(20) ; var used : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, n) ; skip ; execute (cost(0))->display(); operation cost(x : OclAny) : OclAny pre: true post: true activity: used[x+1] := true ; var ret : int := 0 ; var pre_cost : int := if x /= 0 then 0 else INF endif ; for _tuple : edges[x+1] do (var _indx : int := 1; var to : OclAny := _tuple->at(_indx); _indx := _indx + 1; var p : OclAny := _tuple->at(_indx); if used[to+1] then ( pre_cost := p ) else ( ret := ret + cost(to) )) ; if c_lst[x+1] = 0 then ( return Set{ret, pre_cost}->min() ) else ( return pre_cost ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split()) covered=0 for _ in range(n): a,b=map(int,input().split()) covered+=b-a+1 if covered % k==0 : print(0) else : next=covered//k+1 print(next*k-covered) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var covered : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; covered := covered + b - a + 1) ; if covered mod k = 0 then ( execute (0)->display() ) else ( var next : int := covered div k + 1 ; execute (next * k - covered)->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=map(int,input().split(' ')) count=0 while n : n-=1 l,r=map(int,input().split(' ')) count+=r-l+1 print(0 if count % k==0 else k-count % k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var count : int := 0 ; while n do ( n := n - 1 ; var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; count := count + r - l + 1) ; execute (if count mod k = 0 then 0 else k - count mod k endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin readlines=stdin.readlines badge=['AAA','AA','A','B','C','D','E','NA'] limit={500 :[35.50,37.50,40.00,43.00,50.00,55.00,70.00,float('inf')],1000 :[71.00,77.00,83.00,89.00,105.00,116.00,148.00,float('inf')]} def rank(time,limit): for i,l in enumerate(limit): if timeunion(Sequence{'AA'}->union(Sequence{'A'}->union(Sequence{'B'}->union(Sequence{'C'}->union(Sequence{'D'}->union(Sequence{'E'}->union(Sequence{ 'NA' }))))))) ; var limit : Map := Map{ 500 |-> Sequence{35.50}->union(Sequence{37.50}->union(Sequence{40.00}->union(Sequence{43.00}->union(Sequence{50.00}->union(Sequence{55.00}->union(Sequence{70.00}->union(Sequence{ ("" + (('inf')))->toReal() }))))))) }->union(Map{ 1000 |-> Sequence{71.00}->union(Sequence{77.00}->union(Sequence{83.00}->union(Sequence{89.00}->union(Sequence{105.00}->union(Sequence{116.00}->union(Sequence{148.00}->union(Sequence{ ("" + (('inf')))->toReal() }))))))) }) ; skip ; for line : readlines() do ( var t500 : OclAny := null; var t1000 : OclAny := null; Sequence{t500,t1000} := (line.split())->collect( _x | (OclType["double"])->apply(_x) ) ; execute (badge[Set{rank(t500, limit[500+1]), rank(t1000, limit[1000+1])}->max()+1])->display()); operation rank(time : OclAny, limit : OclAny) : OclAny pre: true post: true activity: for _tuple : Integer.subrange(1, (limit)->size())->collect( _indx | Sequence{_indx-1, (limit)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var l : OclAny := _tuple->at(_indx); if (time->compareTo(l)) < 0 then ( return i ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a=list(input()for i in range(8)) ok1=list() ok2=set() ok1.append((7,0)) w=[(1,0),(-1,0),(0,1),(0,-1),(1,-1),(1,1),(-1,-1),(-1,1),(0,0)] for i in range(8): for pos in ok1 : if pos[0]>=i and a[pos[0]-i][pos[1]]=='S' : continue for j in w : to=(pos[0]+j[0],pos[1]+j[1]) if to[0]<8 and to[1]<8 and to[0]>-1 and to[1]>-1 : if to[0]0 else "LOSE") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : Sequence := ((argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 8))))))))) ))))))))) ; var ok1 : Sequence := () ; var ok2 : Set := Set{}->union(()) ; execute ((Sequence{7, 0}) : ok1) ; var w : Sequence := Sequence{Sequence{1, 0}}->union(Sequence{Sequence{-1, 0}}->union(Sequence{Sequence{0, 1}}->union(Sequence{Sequence{0, -1}}->union(Sequence{Sequence{1, -1}}->union(Sequence{Sequence{1, 1}}->union(Sequence{Sequence{-1, -1}}->union(Sequence{Sequence{-1, 1}}->union(Sequence{ Sequence{0, 0} })))))))) ; for i : Integer.subrange(0, 8-1) do ( for pos : ok1 do ( if (pos->first()->compareTo(i)) >= 0 & a[pos->first() - i+1][pos[1+1]+1] = 'S' then ( continue ) else skip ; for j : w do ( var to : OclAny := Sequence{pos->first() + j->first(), pos[1+1] + j[1+1]} ; if to->first() < 8 & to[1+1] < 8 & to->first() > -1 & to[1+1] > -1 then ( if (to->first()->compareTo(i)) < 0 or a[to->first() - i+1][to[1+1]+1] /= 'S' then ( execute ((to) : ok2) ) else skip ) else skip)) ; execute (ok1 /<: ok1) ; ok1 := (ok2->copy()) ; execute (ok2 /<: ok2)) ; execute (if (ok1)->size() > 0 then "WIN" else "LOSE" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : n,k=input().split() n=int(n) k=int(k) sum=0 for i in range(n): number1,number2=input().split() number1=int(number1) number2=int(number2) sum+=(number2-number1)+1 if(sum % k!=0): print(((sum+k)-(sum+k)% k)-sum) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := input().split() ; var n : int := ("" + ((n)))->toInteger() ; var k : int := ("" + ((k)))->toInteger() ; var sum : int := 0 ; for i : Integer.subrange(0, n-1) do ( var number1 : OclAny := null; var number2 : OclAny := null; Sequence{number1,number2} := input().split() ; var number1 : int := ("" + ((number1)))->toInteger() ; var number2 : int := ("" + ((number2)))->toInteger() ; sum := sum + (number2 - number1) + 1) ; if (sum mod k /= 0) then ( execute (((sum + k) - (sum + k) mod k) - sum)->display() ) else ( execute (0)->display() ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import ceil import sys input=sys.stdin.readline def print(*args,end='\n',sep=' ')->None : sys.stdout.write(sep.join(map(str,args))+end) def Solve(): n,k=list(map(int,input().split())) Sum=0 for _ in range(n): l,r=list(map(int,input().split())) Sum+=(r-l+1) print(ceil(Sum/k)*k-Sum) if __name__=="__main__" : Solve() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var input : OclAny := (OclFile["System.in"]).readline ; skip ; skip ; if __name__ = "__main__" then ( Solve() ) else skip; (funcdef def name print ( (typedargslist (args * (named_parameter (name args))) , (def_parameters (def_parameter (named_parameter (name end)) = (test (logical_test (comparison (expr (atom ' ')))))) , (def_parameter (named_parameter (name sep)) = (test (logical_test (comparison (expr (atom ' ')))))))) ) -> (test (logical_test (comparison (expr (atom None))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name sep)) (trailer . (name join) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name map)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name str))))))) , (argument (test (logical_test (comparison (expr (atom (name args)))))))) ))))))))) )))) + (expr (atom (name end))))))))) )))))))))))))) operation Solve() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var Sum : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var l : OclAny := null; var r : OclAny := null; Sequence{l,r} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; Sum := Sum + (r - l + 1)) ; execute (ceil(Sum / k) * k - Sum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k=list(map(int,input().split())) summ=0 for _ in range(n): a,b=list(map(int,input().split())) summ+=(b-a+1) print((k-(summ % k))% k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var summ : int := 0 ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; summ := summ + (b - a + 1)) ; execute ((k - (summ mod k)) mod k)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from sys import stdin from itertools import product input=stdin.readline def is_prime(n): if n<2 : return False if n==2 : return True if n % 2==0 : return False for i in range(3,int(n**0.5)+1,2): if n % i==0 : return False return True def solve(n,c): if c>=0 : dummy=int('9'*n+str(c)+'9'*n) else : dummy=int('9'*n+'9'*n) if n>4 : return dummy found=False ans=-1 for p in product('9876543210',repeat=n): if p[0]=='0' : continue t=''.join(p) if c>=0 : ans=int(t+str(c)+t[: :-1]) else : ans=int(t+t[: :-1]) if is_prime(ans): found=True break if found : return ans else : return dummy def main(args): n,c=map(int,input().split()) result=solve(n,c) print(result) if __name__=='__main__' : main(sys.argv[1 :]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var input : OclAny := stdin.readline ; skip ; skip ; skip ; if __name__ = '__main__' then ( main((trailer . (name argv) (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))) ) else skip; operation is_prime(n : OclAny) : OclAny pre: true post: true activity: if n < 2 then ( return false ) else skip ; if n = 2 then ( return true ) else skip ; if n mod 2 = 0 then ( return false ) else skip ; for i : Integer.subrange(3, ("" + (((n)->pow(0.5))))->toInteger() + 1-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if n mod i = 0 then ( return false ) else skip) ; return true; operation solve(n : OclAny, c : OclAny) : OclAny pre: true post: true activity: if c >= 0 then ( var dummy : int := ("" + ((StringLib.nCopies('9', n) + ("" + ((c))) + StringLib.nCopies('9', n))))->toInteger() ) else ( dummy := ("" + ((StringLib.nCopies('9', n) + StringLib.nCopies('9', n))))->toInteger() ) ; if n > 4 then ( return dummy ) else skip ; var found : boolean := false ; var ans : int := -1 ; for p : product('9876543210', (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (name n)))))))) do ( if p->first() = '0' then ( continue ) else skip ; var t : String := StringLib.sumStringsWithSeparator((p), '') ; if c >= 0 then ( ans := ("" + ((t + ("" + ((c))) + t(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))))->toInteger() ) else ( ans := ("" + ((t + t(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))))->toInteger() ) ; if is_prime(ans) then ( found := true ; break ) else skip) ; if found then ( return ans ) else ( return dummy ); operation main(args : OclAny) pre: true post: true activity: Sequence{n,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var result : OclAny := solve(n, c) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import random import sys def gcd(a,b): if a==b : return a if a>b : return gcd(b,a) if b % a==0 : return a return gcd(b % a,a) def rabin(n): for t in range(100): x=random.randint(2,n-1) if gcd(n,x)!=1 : return False if pow(x,n-1,n)!=1 : return False return True def main(): x,y=map(int,input().split()) if y<0 : if x==1 : print(11) else : for _ in range(2*x): print(9,end='') print() return r=10**x r-=1 rr=10**(x-1)-1 while r!=rr : s=str(r) c=str(y) t=s[: :-1] w=int(s+c+t) if rabin(w): print(w) return r=r-1 for _ in range(x): print(9,end='') print(y,end='') for _ in range(x): print(9,end='') print() if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a = b then ( return a ) else skip ; if (a->compareTo(b)) > 0 then ( return gcd(b, a) ) else skip ; if b mod a = 0 then ( return a ) else skip ; return gcd(b mod a, a); operation rabin(n : OclAny) : OclAny pre: true post: true activity: for t : Integer.subrange(0, 100-1) do ( var x : int := (2 + (OclRandom.defaultInstanceOclRandom()).nextInt(n - 1 - 2)) ; if gcd(n, x) /= 1 then ( return false ) else skip ; if (x)->pow(n - 1) /= 1 then ( return false ) else skip) ; return true; operation main() pre: true post: true activity: var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if y < 0 then ( if x = 1 then ( execute (11)->display() ) else ( for _anon : Integer.subrange(0, 2 * x-1) do ( execute (9)->display()) ; execute (->display() ) ; return ) else skip ; var r : double := (10)->pow(x) ; r := r - 1 ; var rr : double := (10)->pow((x - 1)) - 1 ; while r /= rr do ( var s : String := ("" + ((r))) ; var c : String := ("" + ((y))) ; var t : OclAny := s(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var w : int := ("" + ((s + c + t)))->toInteger() ; if rabin(w) then ( execute (w)->display() ; return ) else skip ; r := r - 1) ; for _anon : Integer.subrange(0, x-1) do ( execute (9)->display()) ; execute (y)->display() ; for _anon : Integer.subrange(0, x-1) do ( execute (9)->display()) ; execute (->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def p(x): if 2 in[x,pow(2,x,x)]: for i in range(7,int(x**.5+1),2): if x % i==0 : return 0 else : return 1 def f(): n,c=map(int,input().split()) if c<0 : return(11,'9'*n*2)[n>1] for h in '9731' : if n-1 : for m in range(int(10**(n-1)),0,-1): if((int(h)+m-1)*2+c)% 3 : t=h+str(m-1).zfill(n-1) a=int(t+str(c)+t[: :-1]) if p(a): return a else : a=int(h+str(c)+h) if p(a): return a return '9'*n+b+'9'*n print(f()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; execute (f())->display(); operation p(x : OclAny) pre: true post: true activity: if (Sequence{x}->union(Sequence{ (2)->pow(x) }))->includes(2) then ( (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 7)))))))) , (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (atom (name x))) ** (expr (atom (number .5)))) + (expr (atom (number (integer 1)))))))))) )))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (expr (atom (name x))) % (expr (atom (name i))))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 0)))))))))))))) (else_clause else : (suite (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (number (integer 1))))))))))))) ) else skip; operation f() : OclAny pre: true post: true activity: var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if c < 0 then ( return Sequence{11, StringLib.nCopies('9', n) * 2}->select(n > 1) ) else skip ; for h : '9731'->characters() do ( if n - 1 then ( for m : Integer.subrange(0 + 1, ("" + (((10)->pow((n - 1)))))->toInteger())->reverse() do ( if ((("" + ((h)))->toInteger() + m - 1) * 2 + c) mod 3 then ( var t : OclAny := h + OclType["String"](m - 1).zfill(n - 1) ; var a : int := ("" + ((t + ("" + ((c))) + t(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))))->toInteger() ; if p(a) then ( return a ) else skip ) else skip) ) else ( a := ("" + ((h + ("" + ((c))) + h)))->toInteger() ; if p(a) then ( return a ) else skip )) ; return StringLib.nCopies('9', n) + b + StringLib.nCopies('9', n); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def palindrome(k,c): a=10*k+c ; while k : a=10*a+(k % 10) k//=10 return a def isPrime(p): if(p & 1)==0 : return False for i in range(3,1+int(p**0.5),2): if(p % i)==0 : return False return True n,c=map(int,input().split()) if c<0 : print('9'*(2*n)if n>1 else '11') else : k=int('9'*n)+1 while True : k-=1 x=palindrome(k,c) if isPrime(x): print(x) break ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var n : OclAny := null; Sequence{n,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if c < 0 then ( execute (if n > 1 then StringLib.nCopies('9', (2 * n)) else '11' endif)->display() ) else ( k := ("" + ((StringLib.nCopies('9', n))))->toInteger() + 1 ; while true do ( k := k - 1 ; var x : OclAny := palindrome(k, c) ; if isPrime(x) then ( execute (x)->display() ; break ) else skip) ); operation palindrome(k : OclAny, c : OclAny) : OclAny pre: true post: true activity: var a : double := 10 * k + c; ; while k do ( a := 10 * a + (k mod 10) ; k := k div 10) ; return a; operation isPrime(p : OclAny) : OclAny pre: true post: true activity: if (MathLib.bitwiseAnd(p, 1)) = 0 then ( return false ) else skip ; for i : Integer.subrange(3, 1 + ("" + (((p)->pow(0.5))))->toInteger()-1)->select( $x | ($x - 3) mod 2 = 0 ) do ( if (p mod i) = 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def p(x): for i in range(7,int(x**.5+1),2): if x % i==0 : return 0 return 1 def f(): n,c=map(int,input().split()); s='9'*n if c<0 : return(11,s+s)[n>1] for h in '9731' : if n-1 : for m in range(int(10**~-n),0,-1): m=str(m-1) if(sum(int(k)for k in h+m)*2+c)% 3 : t=h+m.zfill(n-1); a=int(t+str(c)+t[: :-1]) if p(a): return a else : a=int(h+str(c)+h) if p(a): return a print(f()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; execute (f())->display(); operation p(x : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(7, ("" + (((x)->pow(.5) + 1)))->toInteger()-1)->select( $x | ($x - 7) mod 2 = 0 ) do ( if x mod i = 0 then ( return 0 ) else skip) ; return 1; operation f() : OclAny pre: true post: true activity: var n : OclAny := null; var c : OclAny := null; Sequence{n,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); var s : String := StringLib.nCopies('9', n) ; if c < 0 then ( return Sequence{11, s + s}->select(n > 1) ) else skip ; for h : '9731'->characters() do ( if n - 1 then ( for m : Integer.subrange(0 + 1, ("" + (((10)->pow(MathLib.bitwiseNot(-n)))))->toInteger())->reverse() do ( var m : String := ("" + ((m - 1))) ; if (((argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name k)))))))) ))))))) (comp_for for (exprlist (expr (atom (name k)))) in (logical_test (comparison (expr (expr (atom (name h))) + (expr (atom (name m)))))))))->sum() * 2 + c) mod 3 then ( var t : OclAny := h + m.zfill(n - 1); var a : int := ("" + ((t + ("" + ((c))) + t(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))))))->toInteger() ; if p(a) then ( return a ) else skip ) else skip) ) else ( a := ("" + ((h + ("" + ((c))) + h)))->toInteger() ; if p(a) then ( return a ) else skip )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() n='N' in S s='S' in S e='E' in S w='W' in S if(n and s)or(n==False and s==False): if(e and w)or(e==False and w==False): print('Yes') else : print('No') else : print('No') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var n : boolean := (S)->characters()->includes('N') ; var s : boolean := (S)->characters()->includes('S') ; var e : boolean := (S)->characters()->includes('E') ; var w : boolean := (S)->characters()->includes('W') ; if (n & s) or (n = false & s = false) then ( if (e & w) or (e = false & w = false) then ( execute ('Yes')->display() ) else ( execute ('No')->display() ) ) else ( execute ('No')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys judgeTable={0 : "AAA",1 : "AA",2 : "A",3 : "B",4 : "C",5 : "D",6 : "E",7 : "NA"} def Judge500(time): if time<35.5 : return 0 elif time<37.5 : return 1 elif time<40.0 : return 2 elif time<43.0 : return 3 elif time<50.0 : return 4 elif time<55.0 : return 5 elif time<70.0 : return 6 else : return 7 def Judge1000(time): if time<71.0 : return 0 elif time<77.0 : return 1 elif time<83.0 : return 2 elif time<89.0 : return 3 elif time<105.0 : return 4 elif time<116.0 : return 5 elif time<148.0 : return 6 else : return 7 for line in sys.stdin : line=line[:-1] time1,time2=[float(item)for item in line.split(" ")] rank1,rank2=Judge500(time1),Judge1000(time2) result=judgeTable[max(rank1,rank2)] print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var judgeTable : Map := Map{ 0 |-> "AAA" }->union(Map{ 1 |-> "AA" }->union(Map{ 2 |-> "A" }->union(Map{ 3 |-> "B" }->union(Map{ 4 |-> "C" }->union(Map{ 5 |-> "D" }->union(Map{ 6 |-> "E" }->union(Map{ 7 |-> "NA" }))))))) ; skip ; skip ; for line : OclFile["System.in"] do ( var line : OclAny := line->front() ; var time1 : OclAny := null; var time2 : OclAny := null; Sequence{time1,time2} := line.split(" ")->select(item | true)->collect(item | (("" + ((item)))->toReal())) ; var rank1 : OclAny := null; var rank2 : OclAny := null; Sequence{rank1,rank2} := Sequence{Judge500(time1),Judge1000(time2)} ; var result : OclAny := judgeTable[Set{rank1, rank2}->max()+1] ; execute (result)->display()); operation Judge500(time : OclAny) : OclAny pre: true post: true activity: if time < 35.5 then ( return 0 ) else (if time < 37.5 then ( return 1 ) else (if time < 40.0 then ( return 2 ) else (if time < 43.0 then ( return 3 ) else (if time < 50.0 then ( return 4 ) else (if time < 55.0 then ( return 5 ) else (if time < 70.0 then ( return 6 ) else ( return 7 ) ) ) ) ) ) ) ; operation Judge1000(time : OclAny) : OclAny pre: true post: true activity: if time < 71.0 then ( return 0 ) else (if time < 77.0 then ( return 1 ) else (if time < 83.0 then ( return 2 ) else (if time < 89.0 then ( return 3 ) else (if time < 105.0 then ( return 4 ) else (if time < 116.0 then ( return 5 ) else (if time < 148.0 then ( return 6 ) else ( return 7 ) ) ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections s=list(input()) ans="Yes" c=collections.Counter(s) if c["N"]*c["S"]==0 : if c["N"]!=c["S"]: ans="No" if c["W"]*c["E"]==0 : if c["W"]!=c["E"]: ans="No" print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var ans : String := "Yes" ; var c : OclAny := .Counter(s) ; if c->at("N") * c->at("S") = 0 then ( if c->at("N") /= c->at("S") then ( ans := "No" ) else skip ) else skip ; if c->at("W") * c->at("E") = 0 then ( if c->at("W") /= c->at("E") then ( ans := "No" ) else skip ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import deque mp,blk=[],set() dx=[0,-1,-1,0,1,1,1,0,-1] dy=[0,0,1,1,1,0,-1,-1,-1] for i in range(8): tmp=input().strip() mp.append(tmp) for i in range(8): for j in range(8): if mp[i][j]=='S' : blk.add((i,j)) depth=0 q=deque([[7,0,0]]) while len(q): now=q.popleft() if now[2]==7 or not len(blk): depth=7 print('WIN') break if now[2]!=depth : tmp=set() for each in blk : if each[0]<7 : tmp.add((each[0]+1,each[1])) blk=tmp.copy() depth=now[2] for x,y in zip(dx,dy): xx=now[0]+x yy=now[1]+y if 0<=xx<8 and 0<=yy<8 and(xx,yy)not in blk and(xx-1,yy)not in blk : q.append([xx,yy,now[2]+1]) if depth!=7 : print('LOSE') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var mp : OclAny := null; var blk : OclAny := null; Sequence{mp,blk} := Sequence{Sequence{},Set{}->union(())} ; var dx : Sequence := Sequence{0}->union(Sequence{-1}->union(Sequence{-1}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{ -1 })))))))) ; var dy : Sequence := Sequence{0}->union(Sequence{0}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{0}->union(Sequence{-1}->union(Sequence{-1}->union(Sequence{ -1 })))))))) ; for i : Integer.subrange(0, 8-1) do ( var tmp : OclAny := input()->trim() ; execute ((tmp) : mp)) ; for i : Integer.subrange(0, 8-1) do ( for j : Integer.subrange(0, 8-1) do ( if mp[i+1][j+1] = 'S' then ( execute ((Sequence{i, j}) : blk) ) else skip)) ; var depth : int := 0 ; var q : Sequence := (Sequence{ Sequence{7}->union(Sequence{0}->union(Sequence{ 0 })) }) ; while (q)->size() do ( var now : OclAny := q->first() ; q := q->tail() ; if now[2+1] = 7 or not((blk)->size()) then ( depth := 7 ; execute ('WIN')->display() ; break ) else skip ; if now[2+1] /= depth then ( tmp := Set{}->union(()) ; for each : blk do ( if each->first() < 7 then ( execute ((Sequence{each->first() + 1, each[1+1]}) : tmp) ) else skip) ; var blk : OclAny := tmp->copy() ; depth := now[2+1] ) else skip ; for _tuple : Integer.subrange(1, dx->size())->collect( _indx | Sequence{dx->at(_indx), dy->at(_indx)} ) do (var _indx : int := 1; var x : OclAny := _tuple->at(_indx); _indx := _indx + 1; var y : OclAny := _tuple->at(_indx); var xx : OclAny := now->first() + x ; var yy : OclAny := now[1+1] + y ; if 0 <= xx & (xx < 8) & 0 <= yy & (yy < 8) & (blk)->excludes(Sequence{xx, yy}) & (blk)->excludes(Sequence{xx - 1, yy}) then ( execute ((Sequence{xx}->union(Sequence{yy}->union(Sequence{ now[2+1] + 1 }))) : q) ) else skip)) ; if depth /= 7 then ( execute ('LOSE')->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from statistics import median from fractions import gcd from itertools import combinations from collections import deque from collections import defaultdict import bisect import sys sys.setrecursionlimit(10000000) mod=10**9+7 def readInts(): return list(map(int,input().split())) def main(): s=input() N=s.count('N') W=s.count('W') S=s.count('S') E=s.count('E') if N : if S : pass else : print('No') exit() if S : if N : pass else : print('No') exit() if W : if E : pass else : print('No') exit() if E : if W : pass else : print('No') exit() print('Yes') if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; sys.setrecursionlimit(10000000) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation readInts() : OclAny pre: true post: true activity: return ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); operation main() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var N : int := s->count('N') ; var W : int := s->count('W') ; var S : int := s->count('S') ; var E : int := s->count('E') ; if N then ( if S then ( skip ) else ( execute ('No')->display() ; exit() ) ) else skip ; if S then ( if N then ( skip ) else ( execute ('No')->display() ; exit() ) ) else skip ; if W then ( if E then ( skip ) else ( execute ('No')->display() ; exit() ) ) else skip ; if E then ( if W then ( skip ) else ( execute ('No')->display() ; exit() ) ) else skip ; execute ('Yes')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- letterlist=['N','E','S','W'] S=input() news=[False,False,False,False] for i in range(0,len(S)): for j in range(0,4): if S[i]==letterlist[j]: news[j]=True if(news[0]^ news[2])or(news[1]^ news[3]): print('No') else : print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var letterlist : Sequence := Sequence{'N'}->union(Sequence{'E'}->union(Sequence{'S'}->union(Sequence{ 'W' }))) ; var S : String := (OclFile["System.in"]).readLine() ; var news : Sequence := Sequence{false}->union(Sequence{false}->union(Sequence{false}->union(Sequence{ false }))) ; for i : Integer.subrange(0, (S)->size()-1) do ( for j : Integer.subrange(0, 4-1) do ( if S[i+1] = letterlist[j+1] then ( news[j+1] := true ) else skip)) ; if (MathLib.bitwiseXor(news->first(), news[2+1])) or (MathLib.bitwiseXor(news[1+1], news[3+1])) then ( execute ('No')->display() ) else ( execute ('Yes')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() S=sorted(set(S)) if S.count("N")==1 : if S.count("S")==0 : print("No") exit() if S.count("S")==1 : if S.count("N")==0 : print("No") exit() if S.count("E")==1 : if S.count("W")==0 : print("No") exit() if S.count("W")==1 : if S.count("E")==0 : print("No") exit() print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; S := Set{}->union((S))->sort() ; if S->count("N") = 1 then ( if S->count("S") = 0 then ( execute ("No")->display() ; exit() ) else skip ) else skip ; if S->count("S") = 1 then ( if S->count("N") = 0 then ( execute ("No")->display() ; exit() ) else skip ) else skip ; if S->count("E") = 1 then ( if S->count("W") = 0 then ( execute ("No")->display() ; exit() ) else skip ) else skip ; if S->count("W") = 1 then ( if S->count("E") = 0 then ( execute ("No")->display() ; exit() ) else skip ) else skip ; execute ("Yes")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n,m,r,c=list(map(int,input().split())) is_black=black_row=black_col=has_black=False for i in range(1,n+1): row=input() if i!=r : if row[c-1]=='B' : black_col=True else : if row[c-1]=='B' : is_black=True if row!='W'*m : black_row=True if row!='W'*m : has_black=True if is_black : print(0) elif black_row or black_col : print(1) elif has_black : print(2) else : print(-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; var r : OclAny := null; var c : OclAny := null; Sequence{n,m,r,c} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; is_black := is_black(assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name black_row)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name black_col)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name has_black)))))))) = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name False))))))))) ; for i : Integer.subrange(1, n + 1-1) do ( var row : String := (OclFile["System.in"]).readLine() ; if i /= r then ( if row[c - 1+1] = 'B' then ( var black_col : boolean := true ) else skip ) else ( if row[c - 1+1] = 'B' then ( var is_black : boolean := true ) else skip ; if row /= StringLib.nCopies('W', m) then ( var black_row : boolean := true ) else skip ) ; if row /= StringLib.nCopies('W', m) then ( var has_black : boolean := true ) else skip) ; if is_black then ( execute (0)->display() ) else (if black_row or black_col then ( execute (1)->display() ) else (if has_black then ( execute (2)->display() ) else ( execute (-1)->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- total_loops=input() for i in range(int(total_loops)): vals=input().split(' ') ints=[] for v in vals : v=int(v) ints.append(v) black=False rows=False col=False cell=False for j in range(ints[0]): row=input() for i in range(ints[1]): if row[i]=='B' : black=True if j==ints[2]-1 : if row[i]=='B' : rows=True if i==ints[3]-1 : if row[i]=='B' : col=True if j==ints[2]-1 and i==ints[3]-1 : if row[i]=='B' : cell=True if cell==True : print("0") if(rows==True or col==True)and cell==False : print("1") if black==True and rows==False and col==False and cell==False : print("2") if black==False : print("-1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var total_loops : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, ("" + ((total_loops)))->toInteger()-1) do ( var vals : OclAny := input().split(' ') ; var ints : Sequence := Sequence{} ; for v : vals do ( var v : int := ("" + ((v)))->toInteger() ; execute ((v) : ints)) ; var black : boolean := false ; var rows : boolean := false ; var col : boolean := false ; var cell : boolean := false ; for j : Integer.subrange(0, ints->first()-1) do ( var row : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, ints[1+1]-1) do ( if row[i+1] = 'B' then ( black := true ) else skip ; if j = ints[2+1] - 1 then ( if row[i+1] = 'B' then ( rows := true ) else skip ) else skip ; if i = ints[3+1] - 1 then ( if row[i+1] = 'B' then ( col := true ) else skip ) else skip ; if j = ints[2+1] - 1 & i = ints[3+1] - 1 then ( if row[i+1] = 'B' then ( cell := true ) else skip ) else skip)) ; if cell = true then ( execute ("0")->display() ) else skip ; if (rows = true or col = true) & cell = false then ( execute ("1")->display() ) else skip ; if black = true & rows = false & col = false & cell = false then ( execute ("2")->display() ) else skip ; if black = false then ( execute ("-1")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- total_loops=input() for i in range(int(total_loops)): vals=input().split(' ') ints=[] for v in vals : v=int(v) ints.append(v) black=False rows=False col=False cell=False for j in range(ints[0]): row=input() for i in range(ints[1]): if row[i]=='B' : black=True if j==ints[2]-1 : if row[i]=='B' : rows=True if i==ints[3]-1 : if row[i]=='B' : col=True if j==ints[2]-1 and i==ints[3]-1 : if row[i]=='B' : cell=True print("0") break if(rows==True or col==True)and cell==False : print("1") if black==True and rows==False and col==False and cell==False : print("2") if black==False : print("-1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var total_loops : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, ("" + ((total_loops)))->toInteger()-1) do ( var vals : OclAny := input().split(' ') ; var ints : Sequence := Sequence{} ; for v : vals do ( var v : int := ("" + ((v)))->toInteger() ; execute ((v) : ints)) ; var black : boolean := false ; var rows : boolean := false ; var col : boolean := false ; var cell : boolean := false ; for j : Integer.subrange(0, ints->first()-1) do ( var row : String := (OclFile["System.in"]).readLine() ; for i : Integer.subrange(0, ints[1+1]-1) do ( if row[i+1] = 'B' then ( black := true ) else skip ; if j = ints[2+1] - 1 then ( if row[i+1] = 'B' then ( rows := true ) else skip ) else skip ; if i = ints[3+1] - 1 then ( if row[i+1] = 'B' then ( col := true ) else skip ) else skip ; if j = ints[2+1] - 1 & i = ints[3+1] - 1 then ( if row[i+1] = 'B' then ( cell := true ; execute ("0")->display() ; break ) else skip ) else skip)) ; if (rows = true or col = true) & cell = false then ( execute ("1")->display() ) else skip ; if black = true & rows = false & col = false & cell = false then ( execute ("2")->display() ) else skip ; if black = false then ( execute ("-1")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- I=input exec(int(I())*"n,m,r,c=map(int,I().split());a=''.join(I()for _ in[0]*n);r*=m;print(3*('B'in a)-('B'in a[r-m:r]+a[c-1::m])-(a[r-m+c-1]<'W')-1);") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var I : OclAny := input ; (expr (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name I)) (trailer (arguments ( ))))))))) )))) * (expr (atom "n,m,r,c=map(int,I().split());a=''.join(I()for _ in[0]*n);r*=m;print(3*('B'in a)-('B'in a[r-m:r]+a[c-1::m])-(a[r-m+c-1]<'W')-1);"))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=map(int,input().split()) l=[[0]*(i+1)for i in range(n+1)] l[0][0]=t ans=0 for i in range(n): for j in range(i+1): if l[i][j]>=1 : ans+=1 l[i+1][j]+=(l[i][j]-1)/2 l[i+1][j+1]+=(l[i][j]-1)/2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (i + 1)))) ; l->first()->first() := t ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, i + 1-1) do ( if l[i+1][j+1] >= 1 then ( ans := ans + 1 ; l[i + 1+1][j+1] := l[i + 1+1][j+1] + (l[i+1][j+1] - 1) / 2 ; l[i + 1+1][j + 1+1] := l[i + 1+1][j + 1+1] + (l[i+1][j+1] - 1) / 2 ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- c1=int(input()) l1=[int(x)for x in input().split()] a=[] b=1 for i in range(c1): a+=[b]*l1[i] b+=1 input() l2=[int(x)for x in input().split()] for i in l2 : print(a[i-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var c1 : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l1 : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a : Sequence := Sequence{} ; var b : int := 1 ; for i : Integer.subrange(0, c1-1) do ( a := a + MatrixLib.elementwiseMult(Sequence{ b }, l1[i+1]) ; b := b + 1) ; input() ; var l2 : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for i : l2 do ( execute (a[i - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ReplaceElements(arr,n): if n<=1 : return prev=arr[0] arr[0]=arr[0]^ arr[1] for i in range(1,n-1): curr=arr[i] arr[i]=prev ^ arr[i+1] prev=curr arr[n-1]=prev ^ arr[n-1] arr=[2,3,4,5,6] n=len(arr) ReplaceElements(arr,n) for i in range(n): print(arr[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 })))) ; n := (arr)->size() ; ReplaceElements(arr, n) ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()); operation ReplaceElements(arr : OclAny, n : OclAny) pre: true post: true activity: if n <= 1 then ( return ) else skip ; var prev : OclAny := arr->first() ; arr->first() := MathLib.bitwiseXor(arr->first(), arr[1+1]) ; for i : Integer.subrange(1, n - 1-1) do ( var curr : OclAny := arr[i+1] ; arr[i+1] := MathLib.bitwiseXor(prev, arr[i + 1+1]) ; prev := curr) ; arr[n - 1+1] := MathLib.bitwiseXor(prev, arr[n - 1+1]); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : t1,t2=map(float,input().split()) except : break t1,t2=int(t1*100),int(t2*100) if t1<3550 and t2<7100 : print("AAA") elif t1<3750 and t2<7700 : print("AA") elif t1<4000 and t2<8300 : print("A") elif t1<4300 and t2<8900 : print("B") elif t1<5000 and t2<10500 : print("C") elif t1<5500 and t2<11600 : print("D") elif t1<7000 and t2<14800 : print("E") else : print("NA") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var t1 : OclAny := null; var t2 : OclAny := null; Sequence{t1,t2} := (input().split())->collect( _x | (OclType["double"])->apply(_x) )) catch (_e : OclException) do ( break) ; var t1 : OclAny := null; var t2 : OclAny := null; Sequence{t1,t2} := Sequence{("" + ((t1 * 100)))->toInteger(),("" + ((t2 * 100)))->toInteger()} ; if t1 < 3550 & t2 < 7100 then ( execute ("AAA")->display() ) else (if t1 < 3750 & t2 < 7700 then ( execute ("AA")->display() ) else (if t1 < 4000 & t2 < 8300 then ( execute ("A")->display() ) else (if t1 < 4300 & t2 < 8900 then ( execute ("B")->display() ) else (if t1 < 5000 & t2 < 10500 then ( execute ("C")->display() ) else (if t1 < 5500 & t2 < 11600 then ( execute ("D")->display() ) else (if t1 < 7000 & t2 < 14800 then ( execute ("E")->display() ) else ( execute ("NA")->display() ) ) ) ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class PyramidGlasses : def __init__(self): self.pyramid=[[0]*i for i in range(1,11)] self.noFillGlasses=0 def printfillFlasses(self,n : int,t : int)->int : self.fillPyramid(n,t,0,0) return self.noFillGlasses def fillPyramid(self,n,t,level,index): if(t<=0)|(level==n): return tmp=self.pyramid[level][index]+t if tmp>=1 : if self.pyramid[level][index]<1 : self.noFillGlasses+=1 self.pyramid[level][index]=1 self.fillPyramid(n,(tmp-1)/2,level+1,index) self.fillPyramid(n,(tmp-1)/2,level+1,index+1) else : self.pyramid[level][index]+=t if __name__=='__main__' : n,t=list(map(int,input().strip().split())) obj=PyramidGlasses() print(obj.printfillFlasses(n,t)) ------------------------------------------------------------ OCL File: --------- class PyramidGlasses { static operation newPyramidGlasses() : PyramidGlasses pre: true post: PyramidGlasses->exists( _x | result = _x ); attribute pyramid : Sequence := Integer.subrange(1, 11-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, i))); attribute noFillGlasses : int := 0; operation initialise() : PyramidGlasses pre: true post: true activity: self.pyramid := Integer.subrange(1, 11-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, i))) ; self.noFillGlasses := 0; return self; operation printfillFlasses(n : int,t : int) : int pre: true post: true activity: self.fillPyramid(n, t, 0, 0) ; return self.noFillGlasses; operation fillPyramid(n : OclAny,t : OclAny,level : OclAny,index : OclAny) pre: true post: true activity: if MathLib.bitwiseOr((t <= 0), (level = n)) then ( return ) else skip ; var tmp : OclAny := self.pyramid[level+1][index+1] + t ; if tmp >= 1 then ( if self.pyramid[level+1][index+1] < 1 then ( self.noFillGlasses := self.noFillGlasses + 1 ) else skip ; self.pyramid[level+1][index+1] := 1 ; self.fillPyramid(n, (tmp - 1) / 2, level + 1, index) ; self.fillPyramid(n, (tmp - 1) / 2, level + 1, index + 1) ) else ( self.pyramid[level+1][index+1] := self.pyramid[level+1][index+1] + t ); } class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( Sequence{n,t} := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var obj : PyramidGlasses := (PyramidGlasses.newPyramidGlasses()).initialise() ; execute (obj.printfillFlasses(n, t))->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def glassesFilled(n,t,level,idx,arr): if t<=0 or level==n : return temp=arr[level][idx]+t if temp>=1 : if arr[level][idx]<1 : ans[0]+=1 arr[level][idx]=1 glassesFilled(n,(temp-1)/2,level+1,idx,arr) glassesFilled(n,(temp-1)/2,level+1,idx+1,arr) else : arr[level][idx]+=t return n,t=map(int,input().split()) arr=[[0]*i for i in range(1,11)] ans=[0] glassesFilled(n,t,0,0,arr) print(ans[0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; arr := Integer.subrange(1, 11-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, i))) ; var ans : Sequence := Sequence{ 0 } ; glassesFilled(n, t, 0, 0, arr) ; execute (ans->first())->display(); operation glassesFilled(n : OclAny, t : OclAny, level : OclAny, idx : OclAny, arr : OclAny) pre: true post: true activity: if t <= 0 or level = n then ( return ) else skip ; var temp : OclAny := arr[level+1][idx+1] + t ; if temp >= 1 then ( if arr[level+1][idx+1] < 1 then ( ans->first() := ans->first() + 1 ) else skip ; arr[level+1][idx+1] := 1 ; glassesFilled(n, (temp - 1) / 2, level + 1, idx, arr) ; glassesFilled(n, (temp - 1) / 2, level + 1, idx + 1, arr) ) else ( arr[level+1][idx+1] := arr[level+1][idx+1] + t ) ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MAX=26 ; def compressString(s,n): freq=[0]*MAX ; for i in range(n): freq[ord(s[i])-ord('a')]+=1 ; for i in range(MAX): if(freq[i]==0): continue ; print((chr)(i+ord('a'))+str(freq[i]),end=""); if __name__=="__main__" : s="geeksforgeeks" ; n=len(s); compressString(s,n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var MAX : int := 26; ; skip ; if __name__ = "__main__" then ( s := "geeksforgeeks"; ; n := (s)->size(); ; compressString(s, n); ) else skip; operation compressString(s : OclAny, n : OclAny) pre: true post: true activity: var freq : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, MAX); ; for i : Integer.subrange(0, n-1) do ( freq[(s[i+1])->char2byte() - ('a')->char2byte()+1] := freq[(s[i+1])->char2byte() - ('a')->char2byte()+1] + 1;) ; for i : Integer.subrange(0, MAX-1) do ( if (freq[i+1] = 0) then ( continue; ) else skip ; execute ((chr)(i + ('a')->char2byte()) + ("" + ((freq[i+1]))))->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=map(int,input().split()) l=[[0]*(i+1)for i in range(n+1)] l[0][0]=t ans=0 for i in range(n): for j in range(i+1): if l[i][j]>=1 : ans+=1 l[i+1][j]+=(l[i][j]-1)/2 l[i+1][j+1]+=(l[i][j]-1)/2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, (i + 1)))) ; l->first()->first() := t ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, i + 1-1) do ( if l[i+1][j+1] >= 1 then ( ans := ans + 1 ; l[i + 1+1][j+1] := l[i + 1+1][j+1] + (l[i+1][j+1] - 1) / 2 ; l[i + 1+1][j + 1+1] := l[i + 1+1][j + 1+1] + (l[i+1][j+1] - 1) / 2 ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,t=map(int,input().split()) ans,b=0,1<=b : a[i+1][j]+=(a[i][j]-b)//2 ; a[i+1][j+1]+=(a[i][j]-b)//2 ; ans+=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var t : OclAny := null; Sequence{n,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : OclAny := null; var b : OclAny := null; Sequence{ans,b} := Sequence{0,1 * (2->pow(n))} ; var a : Sequence := Integer.subrange(0, 11-1)->select(i | true)->collect(i | (MatrixLib.elementwiseMult(Sequence{ 0 }, 11))) ; a->first()->first() := t * (1 * (2->pow(n))) ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, i + 1-1) do ( if (a[i+1][j+1]->compareTo(b)) >= 0 then ( a[i + 1+1][j+1] := a[i + 1+1][j+1] + (a[i+1][j+1] - b) div 2; a[i + 1+1][j + 1+1] := a[i + 1+1][j + 1+1] + (a[i+1][j+1] - b) div 2; ans := ans + 1 ) else skip)) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def actual(N,S): number_of_hina_arare_types=len(set(S)) color_map={3 : 'Three',4 : 'Four'} return color_map[number_of_hina_arare_types] N=int(input()) S=input().split() print(actual(N,S)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; S := input().split() ; execute (actual(N, S))->display(); operation actual(N : OclAny, S : OclAny) : OclAny pre: true post: true activity: var number_of_hina_arare_types : int := (Set{}->union((S)))->size() ; var color_map : Map := Map{ 3 |-> 'Three' }->union(Map{ 4 |-> 'Four' }) ; return color_map[number_of_hina_arare_types+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import itertools import sys import copy N=int(input()) S=list(map(str,input().split())) for i in range(N): if S[i]=="Y" : print("Four") exit() print("Three") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var S : Sequence := ((input().split())->collect( _x | (OclType["String"])->apply(_x) )) ; for i : Integer.subrange(0, N-1) do ( if S[i+1] = "Y" then ( execute ("Four")->display() ; exit() ) else skip) ; execute ("Three")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter n=int(input()) A=[i for i in input().split()] c=Counter(A) if len(c.keys())==3 : print('Three') else : print('Four') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(i | true)->collect(i | (i)) ; var c : OclAny := Counter(A) ; if (c.keys())->size() = 3 then ( execute ('Three')->display() ) else ( execute ('Four')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) Tmp=[] Tmp=input().rstrip().split(' ') nAns=[0 for i in range(4)] Flag=0 for i in range(N): S=Tmp[i] if S=='Y' : Flag=1 if Flag==1 : print('Four') else : print('Three') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var Tmp : Sequence := Sequence{} ; Tmp := input().rstrip().split(' ') ; var nAns : Sequence := Integer.subrange(0, 4-1)->select(i | true)->collect(i | (0)) ; var Flag : int := 0 ; for i : Integer.subrange(0, N-1) do ( var S : OclAny := Tmp[i+1] ; if S = 'Y' then ( Flag := 1 ) else skip) ; if Flag = 1 then ( execute ('Four')->display() ) else ( execute ('Three')->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) lst=input().rstrip().split() print("Four" if "Y" in lst else "Three") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var lst : OclAny := input().rstrip().split() ; execute (if (lst)->includes("Y") then "Four" else "Three" endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m500=[35.5,37.5,40.0,43.0,50.0,55.0,70.0,1000.0] m1000=[71.0,77.0,83.0,89.0,105.0,116.0,148.0,1000.0] clas=["AAA","AA","A","B","C","D","E","NA"] while True : try : t500,t1000=list(map(float,input().split())) except : break for i in range(len(m500)): if t500union(Sequence{37.5}->union(Sequence{40.0}->union(Sequence{43.0}->union(Sequence{50.0}->union(Sequence{55.0}->union(Sequence{70.0}->union(Sequence{ 1000.0 }))))))) ; var m1000 : Sequence := Sequence{71.0}->union(Sequence{77.0}->union(Sequence{83.0}->union(Sequence{89.0}->union(Sequence{105.0}->union(Sequence{116.0}->union(Sequence{148.0}->union(Sequence{ 1000.0 }))))))) ; var clas : Sequence := Sequence{"AAA"}->union(Sequence{"AA"}->union(Sequence{"A"}->union(Sequence{"B"}->union(Sequence{"C"}->union(Sequence{"D"}->union(Sequence{"E"}->union(Sequence{ "NA" }))))))) ; while true do ( try ( var t500 : OclAny := null; var t1000 : OclAny := null; Sequence{t500,t1000} := ((input().split())->collect( _x | (OclType["double"])->apply(_x) ))) catch (_e : OclException) do ( break) ; for i : Integer.subrange(0, (m500)->size()-1) do ( if (t500->compareTo(m500[i+1])) < 0 & (t1000->compareTo(m1000[i+1])) < 0 then ( execute (clas[i+1])->display() ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def factorial(N): fact=1 for i in range(1,N+1): fact=fact*i return fact def nthTerm(N): return(factorial(N)*(N+2)//2) if __name__=="__main__" : N=6 print(nthTerm(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( N := 6 ; execute (nthTerm(N))->display() ) else skip; operation factorial(N : OclAny) : OclAny pre: true post: true activity: var fact : int := 1 ; for i : Integer.subrange(1, N + 1-1) do ( fact := fact * i) ; return fact; operation nthTerm(N : OclAny) : OclAny pre: true post: true activity: return (factorial(N) * (N + 2) div 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def factorial(N): fact=1 for i in range(1,N+1): fact=fact*i return fact def nthTerm(N): return(factorial(N+1)//2) if __name__=="__main__" : N=6 print(nthTerm(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( N := 6 ; execute (nthTerm(N))->display() ) else skip; operation factorial(N : OclAny) : OclAny pre: true post: true activity: var fact : int := 1 ; for i : Integer.subrange(1, N + 1-1) do ( fact := fact * i) ; return fact; operation nthTerm(N : OclAny) : OclAny pre: true post: true activity: return (factorial(N + 1) div 2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def longestPermutation(a,n): freq=defaultdict(int) for i in range(n): freq[a[i]]+=1 length=0 for i in range(1,n+1): if(freq[i]==0): break length+=1 return length if __name__=="__main__" : arr=[3,2,1,6,5] n=len(arr) print(longestPermutation(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var arr : Sequence := Sequence{3}->union(Sequence{2}->union(Sequence{1}->union(Sequence{6}->union(Sequence{ 5 })))) ; n := (arr)->size() ; execute (longestPermutation(arr, n))->display() ) else skip; operation longestPermutation(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: var freq : OclAny := defaultdict(OclType["int"]) ; for i : Integer.subrange(0, n-1) do ( freq[a[i+1]+1] := freq[a[i+1]+1] + 1) ; var length : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( if (freq[i+1] = 0) then ( break ) else skip ; length := length + 1) ; return length; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNthTerm(N): ans=0 for i in range(N): if(i % 2==0): ans=ans+6 else : ans=ans+2 print(ans) if __name__=='__main__' : N=3 findNthTerm(N) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( N := 3 ; findNthTerm(N) ) else skip; operation findNthTerm(N : OclAny) pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(0, N-1) do ( if (i mod 2 = 0) then ( ans := ans + 6 ) else ( ans := ans + 2 )) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=[int(i)for i in input().split()] d,e,f=[int(i)for i in input().split()] if(a==0 and b==0 and c!=0)or(d==0 and e==0 and f!=0): print('0') elif(a==0 and b==0 and c==0)or(d==0 and e==0 and f==0): print('-1') else : if b==0 and e==0 : if a*f==d*c : print('-1') else : print('0') elif-a*e==-d*b : if-c*e==-f*b : print('-1') else : print('0') else : print('1') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; var d : OclAny := null; var e : OclAny := null; var f : OclAny := null; Sequence{d,e,f} := input().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; if (a = 0 & b = 0 & c /= 0) or (d = 0 & e = 0 & f /= 0) then ( execute ('0')->display() ) else (if (a = 0 & b = 0 & c = 0) or (d = 0 & e = 0 & f = 0) then ( execute ('-1')->display() ) else ( if b = 0 & e = 0 then ( if a * f = d * c then ( execute ('-1')->display() ) else ( execute ('0')->display() ) ) else (if -a * e = -d * b then ( if -c * e = -f * b then ( execute ('-1')->display() ) else ( execute ('0')->display() ) ) else ( execute ('1')->display() ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def solve2(a,b,c): if a==0 and b==0 : if c==0 : return-1 else : return 0 return-1 def solve(): if a1==0 and b1==0 : if c1!=0 : return 0 else : return solve2(a2,b2,c2) elif a2==0 and b2==0 : if c2!=0 : return 0 else : return solve2(a1,b1,c1) d=a1*b2-a2*b1 if d!=0 : return 1 if(b1*c2)==(b2*c1)and(a1*c2)==(a2*c1): return-1 return 0 a1,b1,c1=map(int,input().split()) a2,b2,c2=map(int,input().split()) print(solve()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var a1 : OclAny := null; var b1 : OclAny := null; var c1 : OclAny := null; Sequence{a1,b1,c1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a2 : OclAny := null; var b2 : OclAny := null; var c2 : OclAny := null; Sequence{a2,b2,c2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (solve())->display(); operation solve2(a : OclAny, b : OclAny, c : OclAny) : OclAny pre: true post: true activity: if a = 0 & b = 0 then ( if c = 0 then ( return -1 ) else ( return 0 ) ) else skip ; return -1; operation solve() : OclAny pre: true post: true activity: if a1 = 0 & b1 = 0 then ( if c1 /= 0 then ( return 0 ) else ( return solve2(a2, b2, c2) ) ) else (if a2 = 0 & b2 = 0 then ( if c2 /= 0 then ( return 0 ) else ( return solve2(a1, b1, c1) ) ) else skip) ; var d : double := a1 * b2 - a2 * b1 ; if d /= 0 then ( return 1 ) else skip ; if (b1 * c2) = (b2 * c1) & (a1 * c2) = (a2 * c1) then ( return -1 ) else skip ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- A1,B1,C1=map(int,input().split()) A2,B2,C2=map(int,input().split()) if(A1==0 and B1==0 and C1!=0)or(A2==0 and B2==0 and C2!=0): print(0) elif(A1==0 and B1==0 and C1==0)or(A2==0 and B2==0 and C2==0): print(-1) elif A1==0 : if A2==0 : if C1*B2==C2*B1 : print(-1) else : print(0) else : print(1) elif B1==0 : if B2==0 : if C1*A2==C2*A1 : print(-1) else : print(0) else : print(1) elif A1*B2==A2*B1 : print(-1 if C1*A2==C2*A1 else 0) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var A1 : OclAny := null; var B1 : OclAny := null; var C1 : OclAny := null; Sequence{A1,B1,C1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var A2 : OclAny := null; var B2 : OclAny := null; var C2 : OclAny := null; Sequence{A2,B2,C2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if (A1 = 0 & B1 = 0 & C1 /= 0) or (A2 = 0 & B2 = 0 & C2 /= 0) then ( execute (0)->display() ) else (if (A1 = 0 & B1 = 0 & C1 = 0) or (A2 = 0 & B2 = 0 & C2 = 0) then ( execute (-1)->display() ) else (if A1 = 0 then ( if A2 = 0 then ( if C1 * B2 = C2 * B1 then ( execute (-1)->display() ) else ( execute (0)->display() ) ) else ( execute (1)->display() ) ) else (if B1 = 0 then ( if B2 = 0 then ( if C1 * A2 = C2 * A1 then ( execute (-1)->display() ) else ( execute (0)->display() ) ) else ( execute (1)->display() ) ) else (if A1 * B2 = A2 * B1 then ( execute (if C1 * A2 = C2 * A1 then -1 else 0 endif)->display() ) else ( execute (1)->display() ) ) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a1,b1,c1=map(int,input().split()) a2,b2,c2=map(int,input().split()) if a1==b1==0 and a2==b2==0 : if c1==c2==0 : print(-1) else : print(0) elif(a1*b2!=a2*b1): print(1) elif(a1*c2==a2*c1 and b1*c2==b2*c1): print(-1) else : print(0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a1 : OclAny := null; var b1 : OclAny := null; var c1 : OclAny := null; Sequence{a1,b1,c1} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a2 : OclAny := null; var b2 : OclAny := null; var c2 : OclAny := null; Sequence{a2,b2,c2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if a1 = b1 & (b1 == 0) & a2 = b2 & (b2 == 0) then ( if c1 = c2 & (c2 == 0) then ( execute (-1)->display() ) else ( execute (0)->display() ) ) else (if (a1 * b2 /= a2 * b1) then ( execute (1)->display() ) else (if (a1 * c2 = a2 * c1 & b1 * c2 = b2 * c1) then ( execute (-1)->display() ) else ( execute (0)->display() ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- R=lambda : map(int,input().split()) a1,b1,c1=R() a2,b2,c2=R() Z=lambda x,y,z : not x and not y and z if a1*b2-a2*b1!=0 : print("1") elif Z(a1,b1,c1)or Z(a2,b2,c2)or c1*b2-b1*c2 or c1*a2-c2*a1 : print("0") else : print("-1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var R : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a1 : OclAny := null; var b1 : OclAny := null; var c1 : OclAny := null; Sequence{a1,b1,c1} := R->apply() ; var a2 : OclAny := null; var b2 : OclAny := null; var c2 : OclAny := null; Sequence{a2,b2,c2} := R->apply() ; var Z : Function := lambda x : OclAny, y : OclAny, z : OclAny in (not(x) & not(y) & z) ; if a1 * b2 - a2 * b1 /= 0 then ( execute ("1")->display() ) else (if Z->apply(a1, b1, c1) or Z->apply(a2, b2, c2) or c1 * b2 - b1 * c2 or c1 * a2 - c2 * a1 then ( execute ("0")->display() ) else ( execute ("-1")->display() ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) L=list(map(int,input().split())) c=0 for i in range(N): for j in range(N): for k in range(N): if i!=j and j!=k and k!=i : if L[i]!=L[j]and L[j]!=L[k]and L[k]!=L[i]: if L[i]+L[j]>L[k]and L[j]+L[k]>L[i]and L[k]+L[i]>L[j]: c=c+1 print(int(c/6)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var L : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 0 ; for i : Integer.subrange(0, N-1) do ( for j : Integer.subrange(0, N-1) do ( for k : Integer.subrange(0, N-1) do ( if i /= j & j /= k & k /= i then ( if L[i+1] /= L[j+1] & L[j+1] /= L[k+1] & L[k+1] /= L[i+1] then ( if (L[i+1] + L[j+1]->compareTo(L[k+1])) > 0 & (L[j+1] + L[k+1]->compareTo(L[i+1])) > 0 & (L[k+1] + L[i+1]->compareTo(L[j+1])) > 0 then ( c := c + 1 ) else skip ) else skip ) else skip))) ; execute (("" + ((c / 6)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import gc import math import sqlite3 from collections import Counter,deque,defaultdict from sys import stdout import time from math import factorial,log,gcd import sys from decimal import Decimal import threading from heapq import* def S(): return sys.stdin.readline().split() def I(): return[int(i)for i in sys.stdin.readline().split()] def II(): return int(sys.stdin.readline()) def IS(): return sys.stdin.readline().replace('\n','') def main(): n,m=I() a=I() m=m*8//n s,c=1,0 while sc : print(0) return m=2**m counter=list(sorted(Counter(a).items(),key=lambda x : x[0])) _len=len(counter) if _len<=m : print(0) return idx=0 g=0 for i in range(_len-1,idx+m-1,-1): g+=counter[i][1] mn=g for i in range(1,_len-m): g+=counter[i-1][1]-counter[i+m-1][1] mn=min(g,mn) print(mn) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation S() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(i | true)->collect(i | (("" + ((i)))->toInteger())); operation II() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation IS() : OclAny pre: true post: true activity: return sys.stdin.readLine().replace(' ', ''); operation main() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := I() ; var a : OclAny := I() ; var m : int := m * 8 div n ; var s : OclAny := null; var c : OclAny := null; Sequence{s,c} := Sequence{1,0} ; while (s->compareTo(n)) < 0 do ( s := s * 2 ; c := c + 1) ; c := c - 1 ; if (m->compareTo(c)) > 0 then ( execute (0)->display() ; return ) else skip ; m := (2)->pow(m) ; var counter : Sequence := (Counter(a)->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->sortedBy($x | (lambda x : OclAny in (x->first()))->apply($x))) ; var _len : int := (counter)->size() ; if (_len->compareTo(m)) <= 0 then ( execute (0)->display() ; return ) else skip ; var idx : int := 0 ; var g : int := 0 ; for i : Integer.subrange(idx + m - 1 + 1, _len - 1)->reverse() do ( g := g + counter[i+1][1+1]) ; var mn : int := g ; for i : Integer.subrange(1, _len - m-1) do ( g := g + counter[i - 1+1][1+1] - counter[i + m - 1+1][1+1] ; mn := Set{g, mn}->min()) ; execute (mn)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys from itertools import combinations def _i(): return int(sys.stdin.readline().strip()) def _ia(): return map(int,sys.stdin.readline().strip().split()) def main(): n=_i() a=list(_ia()) cnt=0 for c in combinations(a,3): l1,l2,l3=sorted(c) if l1==l2 or l2==l3 or l3==l1 : continue if l1display() ) else skip; operation _i() : OclAny pre: true post: true activity: return ("" + ((sys.stdin.readLine()->trim())))->toInteger(); operation _ia() : OclAny pre: true post: true activity: return (sys.stdin.readLine()->trim().split())->collect( _x | (OclType["int"])->apply(_x) ); operation main() : OclAny pre: true post: true activity: var n : OclAny := _i() ; var a : Sequence := (_ia()) ; var cnt : int := 0 ; for c : combinations(a, 3) do ( var l1 : OclAny := null; var l2 : OclAny := null; var l3 : OclAny := null; Sequence{l1,l2,l3} := c->sort() ; if l1 = l2 or l2 = l3 or l3 = l1 then ( continue ) else skip ; if (l1->compareTo(l2 + l3)) < 0 & (l2->compareTo(l3 + l1)) < 0 & (l3->compareTo(l1 + l2)) < 0 then ( cnt := cnt + 1 ) else skip) ; return cnt; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools def get_input()->tuple : N=int(input()) L=list(map(int,input().split())) return N,L def main(L : list)->None : ans=0 for L_i,L_j,L_k in itertools.combinations(L,3): if(L_i==L_j)or(L_j==L_k)or(L_k==L_i): continue if L_i+L_j+L_k>2*max(L_i,L_j,L_k): ans+=1 print(ans) if __name__=="__main__" : N,L=get_input() main(L) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( Sequence{N,L} := get_input() ; main(L) ) else skip; operation get_input() : Sequence pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var L : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; return N, L; operation main(L : Sequence(OclAny)) : OclAny pre: true post: true activity: var ans : int := 0 ; for _tuple : itertools.combinations(L, 3) do (var _indx : int := 1; var L_i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var L_j : OclAny := _tuple->at(_indx); _indx := _indx + 1; var L_k : OclAny := _tuple->at(_indx); if (L_i = L_j) or (L_j = L_k) or (L_k = L_i) then ( continue ) else skip ; if (L_i + L_j + L_k->compareTo(2 * Set{L_i, L_j, L_k}->max())) > 0 then ( ans := ans + 1 ) else skip) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) Lall=input() L_l=Lall.split() L_l_spl=[int(n)for n in L_l] L=sorted(L_l_spl) c=0 for x in range(N-2): for y in range(x+1,N-1): if L[x]==L[y]: pass else : for z in range(y+1,N): if L[z]==L[y]: pass else : xy=L[x]+L[y] zint=L[z] if zinttoInteger() ; var Lall : String := (OclFile["System.in"]).readLine() ; var L_l : OclAny := Lall.split() ; var L_l_spl : Sequence := L_l->select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; var L : Sequence := L_l_spl->sort() ; var c : int := 0 ; for x : Integer.subrange(0, N - 2-1) do ( for y : Integer.subrange(x + 1, N - 1-1) do ( if L[x+1] = L[y+1] then ( skip ) else ( for z : Integer.subrange(y + 1, N-1) do ( if L[z+1] = L[y+1] then ( skip ) else ( var xy : OclAny := L[x+1] + L[y+1] ; var zint : OclAny := L[z+1] ; if (zint->compareTo(xy)) < 0 then ( c := c + 1 ) else skip )) ))) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from itertools import combinations as comb N=int(input()) L=list(map(int,input().split())) count=0 for a,b,c in comb(L,3): if a!=b and b!=c and c!=a and a+b>c and b+c>a and c+a>b : count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var L : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var count : int := 0 ; for _tuple : comb(L, 3) do (var _indx : int := 1; var a : OclAny := _tuple->at(_indx); _indx := _indx + 1; var b : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if a /= b & b /= c & c /= a & (a + b->compareTo(c)) > 0 & (b + c->compareTo(a)) > 0 & (c + a->compareTo(b)) > 0 then ( count := count + 1 ) else skip) ; execute (count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,h,w=map(int,input().split()) x=list(map(int,input().split())) wide_total=n*w wide_cover=[False]*wide_total for i in range(n): if(i+1)% 2==1 : for j in range(i*w+x[i],i*w+x[i]+w): wide_cover[j]=True else : for j in range(i*w-x[i],i*w-x[i]+w): wide_cover[j]=True cnt=0 for c in wide_cover : if c==False : cnt+=1 print(cnt*h) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var h : OclAny := null; var w : OclAny := null; Sequence{n,h,w} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var x : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var wide_total : double := n * w ; var wide_cover : Sequence := MatrixLib.elementwiseMult(Sequence{ false }, wide_total) ; for i : Integer.subrange(0, n-1) do ( if (i + 1) mod 2 = 1 then ( for j : Integer.subrange(i * w + x[i+1], i * w + x[i+1] + w-1) do ( wide_cover[j+1] := true) ) else ( for j : Integer.subrange(i * w - x[i+1], i * w - x[i+1] + w-1) do ( wide_cover[j+1] := true) )) ; var cnt : int := 0 ; for c : wide_cover do ( if c = false then ( cnt := cnt + 1 ) else skip) ; execute (cnt * h)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt def elementCount(arr1,arr2): count=0 hash=frozenset(arr2) for x in arr1 : for j in range(1,int(sqrt(x))+1): if x % j==0 : if(j in hash or x/j in hash): count+=1 break return count arr1=[10,2,13,4,15] arr2=[2,4,5,6] print(elementCount(arr1,arr2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; arr1 := Sequence{10}->union(Sequence{2}->union(Sequence{13}->union(Sequence{4}->union(Sequence{ 15 })))) ; arr2 := Sequence{2}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))) ; execute (elementCount(arr1, arr2))->display(); operation elementCount(arr1 : OclAny, arr2 : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; var hash : Set := Set{} ; for x : arr1 do ( for j : Integer.subrange(1, ("" + ((sqrt(x))))->toInteger() + 1-1) do ( if x mod j = 0 then ( if ((hash)->includes(j) or (hash)->includes(x / j)) then ( count := count + 1 ; break ) else skip ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countDivisibles(A,B,M): counter=0 ; for i in range(A,B): if(i % M==0): counter=counter+1 return counter A=30 B=100 M=30 print(countDivisibles(A,B,M)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; A := 30 ; B := 100 ; M := 30 ; execute (countDivisibles(A, B, M))->display(); operation countDivisibles(A : OclAny, B : OclAny, M : OclAny) : OclAny pre: true post: true activity: var counter : int := 0; ; for i : Integer.subrange(A, B-1) do ( if (i mod M = 0) then ( counter := counter + 1 ) else skip) ; return counter; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def squareSide(a): if(a<0): return-1 x=0.423*a return x if __name__=='__main__' : a=8 print(squareSide(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( a := 8 ; execute (squareSide(a))->display() ) else skip; operation squareSide(a : OclAny) : OclAny pre: true post: true activity: if (a < 0) then ( return -1 ) else skip ; var x : double := 0.423 * a ; return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def CPwithProfit(sellingPrice,profit): costPrice=((sellingPrice*100.0)/(100+profit)) return costPrice def CPwithLoss(sellingPrice,loss): costPrice=((sellingPrice*100.0)/(100-loss)) return costPrice if __name__=='__main__' : SP=1020 profit=20 print("Cost Price=",CPwithProfit(SP,profit)) SP=900 loss=10 print("Cost Price=",CPwithLoss(SP,loss)) SP=42039 profit=8 print("Cost Price=",int(CPwithProfit(SP,profit))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( var SP : int := 1020 ; profit := 20 ; execute ("Cost Price=")->display() ; SP := 900 ; loss := 10 ; execute ("Cost Price=")->display() ; SP := 42039 ; profit := 8 ; execute ("Cost Price=")->display() ) else skip; operation CPwithProfit(sellingPrice : OclAny, profit : OclAny) : OclAny pre: true post: true activity: var costPrice : double := ((sellingPrice * 100.0) / (100 + profit)) ; return costPrice; operation CPwithLoss(sellingPrice : OclAny, loss : OclAny) : OclAny pre: true post: true activity: costPrice := ((sellingPrice * 100.0) / (100 - loss)) ; return costPrice; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): n,k=list(map(int,input().split())) a=list(map(int,input().split())) a.sort(reverse=True) result=0 for i in range(k+1): result+=a[i] print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var result : int := 0 ; for i : Integer.subrange(0, k + 1-1) do ( result := result + a[i+1]) ; execute (result)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys,math,os,copy PYDEV=os.environ.get('PYDEV') if PYDEV=="True" : sys.stdin=open("sample-input.txt","rt") grades=["AAA","AA","A","B","C","D","E","NA"] limits=[[35.5,71],[37.5,77],[40,83],[43,89],[50,105],[55,116],[70,148],[99999999,999999999]] for line in sys.stdin : t1,t2=[float(_)for _ in line.split()] for k in range(8): if t1union(Sequence{"AA"}->union(Sequence{"A"}->union(Sequence{"B"}->union(Sequence{"C"}->union(Sequence{"D"}->union(Sequence{"E"}->union(Sequence{ "NA" }))))))) ; var limits : Sequence := Sequence{Sequence{35.5}->union(Sequence{ 71 })}->union(Sequence{Sequence{37.5}->union(Sequence{ 77 })}->union(Sequence{Sequence{40}->union(Sequence{ 83 })}->union(Sequence{Sequence{43}->union(Sequence{ 89 })}->union(Sequence{Sequence{50}->union(Sequence{ 105 })}->union(Sequence{Sequence{55}->union(Sequence{ 116 })}->union(Sequence{Sequence{70}->union(Sequence{ 148 })}->union(Sequence{ Sequence{99999999}->union(Sequence{ 999999999 }) }))))))) ; for line : OclFile["System.in"] do ( var t1 : OclAny := null; var t2 : OclAny := null; Sequence{t1,t2} := line.split()->select(_anon | true)->collect(_anon | (("" + ((_anon)))->toReal())) ; for k : Integer.subrange(0, 8-1) do ( if (t1->compareTo(limits[k+1]->first())) < 0 & (t2->compareTo(limits[k+1][1+1])) < 0 then ( execute (grades[k+1])->display() ; break ) else skip)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ms(a): if len(a)<2 : return a mid=len(a)//2 b=a[: mid] c=a[mid :] b=ms(b) c=ms(c) a=[] i=j=0 while itoInteger() ; while t do ( f() ; t := t - 1); operation ms(a : OclAny) : OclAny pre: true post: true activity: if (a)->size() < 2 then ( return a ) else skip ; var mid : int := (a)->size() div 2 ; var b : OclAny := a.subrange(1,mid) ; var c : OclAny := a.subrange(mid+1) ; b := ms(b) ; c := ms(c) ; a := Sequence{} ; var i : OclAny := 0; var j : int := 0 ; while (i->compareTo((b)->size())) < 0 & (j->compareTo((c)->size())) < 0 do ( if (b[i+1]->compareTo(c[j+1])) < 0 then ( a := a + Sequence{ b[i+1] } ; i := i + 1 ) else ( a := a + Sequence{ c[j+1] } ; j := j + 1 )) ; a := a + b.subrange(i+1) + c.subrange(j+1) ; return a; operation f() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; a := ((input()->trim().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; a := ms(a) ; var ans : OclAny := (a.subrange(n - k - 1+1))->sum() ; execute (ans)->display() ; return; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n,k=map(int,input().split()) a=list(map(int,input().split())) a.sort() a.reverse() ans=0 for _ in range(k+1): ans+=a[_] print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; a := a->reverse() ; var ans : int := 0 ; for _anon : Integer.subrange(0, k + 1-1) do ( ans := ans + a[_anon+1]) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=="__main__" : for i in range(int(input())): n,k=map(int,input().split()) l=list(map(int,input().split())) l.sort(reverse=True) a=sum(l[: k+1]) print(a) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = "__main__" then ( for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; l := l->sort() ; var a : OclAny := (l.subrange(1,k + 1))->sum() ; execute (a)->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for u in range(t): n,k=map(int,input().split()) lst=list(map(int,input().split())) lst.sort() for x in range(n-k-1,n-1): lst[n-1]+=lst[x] print(lst[n-1]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for u : Integer.subrange(0, t-1) do ( var n : OclAny := null; var k : OclAny := null; Sequence{n,k} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; lst := lst->sort() ; for x : Integer.subrange(n - k - 1, n - 1-1) do ( lst[n - 1+1] := lst[n - 1+1] + lst[x+1]) ; execute (lst[n - 1+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools def compute(): LIMIT=10**12 strongrepunits={1} for length in range(3,LIMIT.bit_length()+1): for base in itertools.count(2): value=(base**length-1)//(base-1) if value>=LIMIT : break strongrepunits.add(value) ans=sum(strongrepunits) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var LIMIT : double := (10)->pow(12) ; var strongrepunits : Set := Set{ 1 } ; for length : Integer.subrange(3, LIMIT.bit_length() + 1-1) do ( for base : itertools->count(2) do ( var value : int := ((base)->pow(length) - 1) div (base - 1) ; if (value->compareTo(LIMIT)) >= 0 then ( break ) else skip ; execute ((value) : strongrepunits))) ; var ans : OclAny := (strongrepunits)->sum() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for test in range(t): keyboard=input() s=input() last=0 time=-keyboard.index(s[0]) for x in s : i=keyboard.index(x) time+=abs(i-last) last=i print(time) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for test : Integer.subrange(0, t-1) do ( var keyboard : String := (OclFile["System.in"]).readLine() ; var s : String := (OclFile["System.in"]).readLine() ; var last : int := 0 ; var time : int := -keyboard->indexOf(s->first()) - 1 ; for x : s->characters() do ( var i : int := keyboard->indexOf(x) - 1 ; time := time + (i - last)->abs() ; last := i) ; execute (time)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import itertools n=int(input()) id=input()[: :-1] count=0 a=[] odd,even=0,0 tmp=0 for i in range(1,n+1): if id[i-1]=="*" : if i % 2 : odd+=1 else : even+=1 elif i % 2==0 : x=int(id[i-1]) if x>=5 : tmp+=(x*2-9) else : tmp+=(x*2) else : tmp+=(int(id[i-1])) m=int(input()) data=list(map(int,input().split())) def sum2(ls): ans=0 for k in ls : if k>=5 : ans+=(k*2-9) else : ans+=(k*2) return ans odd_list=list(map(lambda x :(sum(x)% 10),list(itertools.product(data,repeat=odd)))) even_list=list(map(lambda x :((sum2(x))% 10),list(itertools.product(data,repeat=even)))) odd_mod=[odd_list.count(i)for i in range(10)] even_mod=[even_list.count(i)for i in range(10)] for i in range(10): for j in range(10): if((i+j+tmp)% 10)==0 : count+=odd_mod[i]*even_mod[j] print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var id : OclAny := input()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var count : int := 0 ; var a : Sequence := Sequence{} ; var odd : OclAny := null; var even : OclAny := null; Sequence{odd,even} := Sequence{0,0} ; var tmp : int := 0 ; for i : Integer.subrange(1, n + 1-1) do ( if ?[i - 1+1] = "*" then ( if i mod 2 then ( odd := odd + 1 ) else ( even := even + 1 ) ) else (if i mod 2 = 0 then ( var x : int := ("" + ((?[i - 1+1])))->toInteger() ; if x >= 5 then ( tmp := tmp + (x * 2 - 9) ) else ( tmp := tmp + (x * 2) ) ) else ( tmp := tmp + (("" + ((?[i - 1+1])))->toInteger()) ) ) ) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var data : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; skip ; var odd_list : Sequence := (((itertools.product(data, (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (name odd))))))))))->collect( _x | (lambda x : OclAny in (((x)->sum() mod 10)))->apply(_x) )) ; var even_list : Sequence := (((itertools.product(data, (argument (test (logical_test (comparison (expr (atom (name repeat)))))) = (test (logical_test (comparison (expr (atom (name even))))))))))->collect( _x | (lambda x : OclAny in (((sum2(x)) mod 10)))->apply(_x) )) ; var odd_mod : Sequence := Integer.subrange(0, 10-1)->select(i | true)->collect(i | (odd_list->count(i))) ; var even_mod : Sequence := Integer.subrange(0, 10-1)->select(i | true)->collect(i | (even_list->count(i))) ; for i : Integer.subrange(0, 10-1) do ( for j : Integer.subrange(0, 10-1) do ( if ((i + j + tmp) mod 10) = 0 then ( count := count + odd_mod[i+1] * even_mod[j+1] ) else skip)) ; execute (count)->display(); operation sum2(ls : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for k : ls do ( if k >= 5 then ( ans := ans + (k * 2 - 9) ) else ( ans := ans + (k * 2) )) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) ID=input()[: :-1] m=int(input()) a_lst=list(map(int,input().split())) dp=[[0]*10 for _ in range(n+1)] dp[0][0]=1 def fix(a): if a<10 : return a return a % 10+a//10 for i in range(n): c=ID[i] mag=1 if i % 2==0 else 2 for j in range(10): if c=="*" : for a in a_lst : a=fix(a*mag) dp[i+1][(j+a)% 10]+=dp[i][j] else : a=fix(int(c)*mag) dp[i+1][(j+a)% 10]+=dp[i][j] print(dp[n][0]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ID : OclAny := input()(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a_lst : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var dp : Sequence := Integer.subrange(0, n + 1-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ 0 }, 10))) ; dp->first()->first() := 1 ; skip ; for i : Integer.subrange(0, n-1) do ( var c : OclAny := ID[i+1] ; var mag : int := if i mod 2 = 0 then 1 else 2 endif ; for j : Integer.subrange(0, 10-1) do ( if c = "*" then ( for a : a_lst do ( a := fix(a * mag) ; dp[i + 1+1][(j + a) mod 10+1] := dp[i + 1+1][(j + a) mod 10+1] + dp[i+1][j+1]) ) else ( a := fix(("" + ((c)))->toInteger() * mag) ; dp[i + 1+1][(j + a) mod 10+1] := dp[i + 1+1][(j + a) mod 10+1] + dp[i+1][j+1] ))) ; execute (dp[n+1]->first())->display(); operation fix(a : OclAny) : OclAny pre: true post: true activity: if a < 10 then ( return a ) else skip ; return a mod 10 + a div 10; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxCountAB(s,n): A=0 B=0 BA=0 ans=0 for i in range(n): S=s[i] L=len(S) for j in range(L-1): if(S[j]=='A' and S[j+1]=='B'): ans+=1 if(S[0]=='B' and S[L-1]=='A'): BA+=1 elif(S[0]=='B'): B+=1 elif(S[L-1]=='A'): A+=1 if(BA==0): ans+=min(B,A) elif(A+B==0): ans+=BA-1 else : ans+=BA+min(B,A) return ans if __name__=='__main__' : s=["ABCA","BOOK","BAND"] n=len(s) print(maxCountAB(s,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( s := Sequence{"ABCA"}->union(Sequence{"BOOK"}->union(Sequence{ "BAND" })) ; n := (s)->size() ; execute (maxCountAB(s, n))->display() ) else skip; operation maxCountAB(s : OclAny, n : OclAny) : OclAny pre: true post: true activity: var A : int := 0 ; var B : int := 0 ; var BA : int := 0 ; var ans : int := 0 ; for i : Integer.subrange(0, n-1) do ( var S : OclAny := s[i+1] ; var L : int := (S)->size() ; for j : Integer.subrange(0, L - 1-1) do ( if (S[j+1] = 'A' & S[j + 1+1] = 'B') then ( ans := ans + 1 ) else skip) ; if (S->first() = 'B' & S[L - 1+1] = 'A') then ( BA := BA + 1 ) else (if (S->first() = 'B') then ( B := B + 1 ) else (if (S[L - 1+1] = 'A') then ( A := A + 1 ) else skip ) ) ) ; if (BA = 0) then ( ans := ans + Set{B, A}->min() ) else (if (A + B = 0) then ( ans := ans + BA - 1 ) else ( ans := ans + BA + Set{B, A}->min() ) ) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,x,y=[int(k)for k in input().split()] w=[int(k)for k in input().split()] z=[int(k)for k in input().split()] q=[abs(w[k]-z[k])for k in range(n)] length=2**len(bin(len(q))[2 :]) eta=[0 for k in range(2*length-1)] for j in range(n): eta[length-1+j]=q[j] def upward(u,k): if k>length-1 : return u[k-1] else : u[k-1]=max(upward(u,2*k),upward(u,2*k+1)) return u[k-1] def findmax(u,k): if k>length-1 : u[k-1]-=1 return k-1 else : if u[2*k-1]>=u[2*k]: return findmax(u,2*k) else : return findmax(u,2*k+1) def update(u,k): while k>1 : k//=2 u[k-1]=max(u[2*k-1],u[2*k]) upward(eta,1) for j in range(x+y): if eta[0]==0 : print((x+y-j)% 2) break else : zxc=findmax(eta,1) update(eta,zxc+1) else : res=0 for k in eta[length-1 :]: res+=k**2 print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var x : OclAny := null; var y : OclAny := null; Sequence{n,x,y} := input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger())) ; var w : Sequence := input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger())) ; var z : Sequence := input().split()->select(k | true)->collect(k | (("" + ((k)))->toInteger())) ; var q : Sequence := Integer.subrange(0, n-1)->select(k | true)->collect(k | ((w[k+1] - z[k+1])->abs())) ; var length : double := (2)->pow((bin((q)->size()).subrange(2+1))->size()) ; var eta : Sequence := Integer.subrange(0, 2 * length - 1-1)->select(k | true)->collect(k | (0)) ; for j : Integer.subrange(0, n-1) do ( eta[length - 1 + j+1] := q[j+1]) ; skip ; skip ; skip ; upward(eta, 1) ; (compound_stmt for (exprlist (expr (atom (name j)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name x))) + (expr (atom (name y))))))))) )))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name eta)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) == (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name x))) + (expr (atom (name y)))) - (expr (atom (name j)))))))) ))) % (expr (atom (number (integer 2)))))))))) )))))))))))) (stmt (simple_stmt (small_stmt break)))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name zxc)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name findmax)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name eta))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name update)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name eta))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name zxc))) + (expr (atom (number (integer 1)))))))))) ))))))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name res)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (number (integer 0))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name k)))) in (testlist (test (logical_test (comparison (expr (atom (name eta)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name length))) - (expr (atom (number (integer 1)))))))) :)) ]))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name res)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name k))) ** (expr (atom (number (integer 2)))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name res)))))))) ))))))))))))))); operation upward(u : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (k->compareTo(length - 1)) > 0 then ( return u[k - 1+1] ) else ( u[k - 1+1] := Set{upward(u, 2 * k), upward(u, 2 * k + 1)}->max() ; return u[k - 1+1] ); operation findmax(u : OclAny, k : OclAny) : OclAny pre: true post: true activity: if (k->compareTo(length - 1)) > 0 then ( u[k - 1+1] := u[k - 1+1] - 1 ; return k - 1 ) else ( if (u[2 * k - 1+1]->compareTo(u[2 * k+1])) >= 0 then ( return findmax(u, 2 * k) ) else ( return findmax(u, 2 * k + 1) ) ); operation update(u : OclAny, k : OclAny) pre: true post: true activity: while k > 1 do ( k := k div 2 ; u[k - 1+1] := Set{u[2 * k - 1+1], u[2 * k+1]}->max()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n,m,r,c=map(int,input().split()) print(max(abs(n-r),r-1)+max(abs(m-c),c-1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; var r : OclAny := null; var c : OclAny := null; Sequence{n,m,r,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{(n - r)->abs(), r - 1}->max() + Set{(m - c)->abs(), c - 1}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- inp=lambda : map(int,input().split()) n,k1,k2=inp() a=[abs(x-y)for x,y in zip(list(inp()),list(inp()))] for i in range(k1+k2): id=a.index(max(a)) a[id]=abs(a[id]-1) print(sum(i**2 for i in a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var inp : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var k1 : OclAny := null; var k2 : OclAny := null; Sequence{n,k1,k2} := inp->apply() ; var a : Sequence := Integer.subrange(1, (inp->apply())->size())->collect( _indx | Sequence{(inp->apply())->at(_indx), (inp->apply())->at(_indx)} )->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in ((x - y)->abs())) ; for i : Integer.subrange(0, k1 + k2-1) do ( var id : int := a->indexOf((a)->max()) - 1 ; a[id+1] := (a[id+1] - 1)->abs()) ; execute (((argument (test (logical_test (comparison (expr (expr (atom (name i))) ** (expr (atom (number (integer 2)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name a))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- p=lambda : map(int,input().split()) n,k,l=p(); a=[abs(x-y)for x,y in zip(list(p()),list(p()))] for _ in range(k+l): d=a.index(max(a)); a[d]=abs(a[d]-1) print(sum(i*i for i in a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var p : Function := lambda $$ : OclAny in ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : OclAny := null; var k : OclAny := null; var l : OclAny := null; Sequence{n,k,l} := p->apply(); var a : Sequence := Integer.subrange(1, (p->apply())->size())->collect( _indx | Sequence{(p->apply())->at(_indx), (p->apply())->at(_indx)} )->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in ((x - y)->abs())) ; for _anon : Integer.subrange(0, k + l-1) do ( var d : int := a->indexOf((a)->max()) - 1; a[d+1] := (a[d+1] - 1)->abs()) ; execute (((argument (test (logical_test (comparison (expr (expr (atom (name i))) * (expr (atom (name i))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name a))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k1,k2=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) c=[] for i in range(n): c.append(abs(a[i]-b[i])) for i in range(k1+k2): k=-1 max1=0 for j in range(n): if(c[j]>max1): max1=c[j] k=j c[k]=abs(c[k]-1) sumx=0 for i in range(n): sumx+=c[i]**2 print(sumx) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k1 : OclAny := null; var k2 : OclAny := null; Sequence{n,k1,k2} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute (((a[i+1] - b[i+1])->abs()) : c)) ; for i : Integer.subrange(0, k1 + k2-1) do ( var k : int := -1 ; var max1 : int := 0 ; for j : Integer.subrange(0, n-1) do ( if ((c[j+1]->compareTo(max1)) > 0) then ( max1 := c[j+1] ; k := j ) else skip) ; c[k+1] := (c[k+1] - 1)->abs()) ; var sumx : int := 0 ; for i : Integer.subrange(0, n-1) do ( sumx := sumx + (c[i+1])->pow(2)) ; execute (sumx)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k1,k2=[int(x)for x in input().split()] a=[int(x)for x in input().split()] b=[int(x)for x in input().split()] d=[-abs(x-y)for x,y in zip(a,b)] k=k1+k2 import heapq as hq hq.heapify(d) chained=1 ans=-1 while len(d)>0 : curr=-hq.heappop(d) next=-d[0]if len(d)>0 else 0 if k>=(curr-next)*chained : k-=(curr-next)*chained chained+=1 continue dd,m=k//chained,k % chained ans=(curr-dd-1)**2*m+(curr-dd)**2*(chained-m) for x in d : ans+=x**2 break else : ans=k % 2 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k1 : OclAny := null; var k2 : OclAny := null; Sequence{n,k1,k2} := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var b : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var d : Sequence := Integer.subrange(1, a->size())->collect( _indx | Sequence{a->at(_indx), b->at(_indx)} )->select(_tuple | true)->collect(_tuple | let x : OclAny = _tuple->at(1) in let y : OclAny = _tuple->at(2) in (-(x - y)->abs())) ; var k : OclAny := k1 + k2 ; skip ; hq.heapify(d) ; var chained : int := 1 ; var ans : int := -1 ; (compound_stmt while (test (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name d)))))))) ))))) > (comparison (expr (atom (number (integer 0)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name curr)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr - (expr (atom (name hq)) (trailer . (name heappop) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name d)))))))) )))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name next)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr - (expr (atom (name d)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))) if (logical_test (comparison (comparison (expr (atom (name len)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name d)))))))) ))))) > (comparison (expr (atom (number (integer 0))))))) else (test (logical_test (comparison (expr (atom (number (integer 0)))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name k)))) >= (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name curr))) - (expr (atom (name next)))))))) ))) * (expr (atom (name chained)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name k)))))))) (assign_part -= (testlist (test (logical_test (comparison (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name curr))) - (expr (atom (name next)))))))) ))) * (expr (atom (name chained)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name chained)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))) (stmt (simple_stmt (small_stmt continue)))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (test (logical_test (comparison (expr (atom (name dd)))))) , (test (logical_test (comparison (expr (atom (name m))))))) (assign_part = (testlist_star_expr (test (logical_test (comparison (expr (expr (atom (name k))) // (expr (atom (name chained))))))) , (test (logical_test (comparison (expr (expr (atom (name k))) % (expr (atom (name chained)))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (expr (atom (name curr))) - (expr (atom (name dd)))) - (expr (atom (number (integer 1))))))))) ))) ** (expr (atom (number (integer 2))))) * (expr (atom (name m)))) + (expr (expr (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name curr))) - (expr (atom (name dd)))))))) ))) ** (expr (atom (number (integer 2))))) * (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name chained))) - (expr (atom (name m)))))))) )))))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name x)))) in (testlist (test (logical_test (comparison (expr (atom (name d))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part += (testlist (test (logical_test (comparison (expr (expr (atom (name x))) ** (expr (atom (number (integer 2)))))))))))))))) (stmt (simple_stmt (small_stmt break)))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name ans)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name k))) % (expr (atom (number (integer 2))))))))))))))))) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isVowel(ch): return ch.upper()in['A','E','I','O','U'] def countVowels(str): count=0 for i in range(len(str)): if isVowel(str[i]): count+=1 return count str='abc de' print(countVowels(str)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; OclType["String"] := 'abc de' ; execute (countVowels(OclType["String"]))->display(); operation isVowel(ch : OclAny) : OclAny pre: true post: true activity: return (Sequence{'A'}->union(Sequence{'E'}->union(Sequence{'I'}->union(Sequence{'O'}->union(Sequence{ 'U' })))))->includes(ch->toUpperCase()); operation countVowels(OclType["String"] : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, (OclType["String"])->size()-1) do ( if isVowel(("" + ([i+1]))) then ( count := count + 1 ) else skip) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from sys import stdin input=stdin.readline from collections import Counter n=int(input()); arr=list(map(int,input().split())); count=Counter(arr); dic=dict(); c=0 for i in range(1,5001): dic[i]=0 for i in count : dic[i]=count[i] for i in range(1,n+1): if dic[i]==0 : c+=1 print(c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := stdin.readline ; skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); var count : OclAny := Counter(arr); var dic : Map := (arguments ( )); var c : int := 0 ; for i : Integer.subrange(1, 5001-1) do ( dic[i+1] := 0) ; for i : count do ( dic[i+1] := count[i+1]) ; for i : Integer.subrange(1, n + 1-1) do ( if dic[i+1] = 0 then ( c := c + 1 ) else skip) ; execute (c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): d={} c=1 n=input() b=input() for i in n : d[i]=c c+=1 k=0 for i in range(len(b)-1): k+=abs(d[b[i]]-d[b[i+1]]) print(k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var d : OclAny := Set{} ; var c : int := 1 ; var n : String := (OclFile["System.in"]).readLine() ; var b : String := (OclFile["System.in"]).readLine() ; for i : n->characters() do ( d[i+1] := c ; c := c + 1) ; var k : int := 0 ; for i : Integer.subrange(0, (b)->size() - 1-1) do ( k := k + (d[b[i+1]+1] - d[b[i + 1+1]+1])->abs()) ; execute (k)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=set(map(int,input().split())) counter=0 for i in range(n): if i+1 not in a : counter+=1 print(counter) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Set := Set{}->union(((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var counter : int := 0 ; for i : Integer.subrange(0, n-1) do ( if (a)->excludes(i + 1) then ( counter := counter + 1 ) else skip) ; execute (counter)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- x=int(input()); l1=list(map(int,input().split())); l=[] for i in l1 : if i<=x and i not in l : l.append(i) print(x-len(l)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var x : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); var l1 : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )); var l : Sequence := Sequence{} ; for i : l1 do ( if (i->compareTo(x)) <= 0 & (l)->excludes(i) then ( execute ((i) : l) ) else skip) ; execute (x - (l)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) res=0 arr=list(map(int,input().split())) arr1=set(arr) for i in arr1 : if i>t : res+=1 print((len(arr)-len(arr1))+res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var res : int := 0 ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var arr1 : Set := Set{}->union((arr)) ; for i : arr1 do ( if (i->compareTo(t)) > 0 then ( res := res + 1 ) else skip) ; execute (((arr)->size() - (arr1)->size()) + res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for z in range(t): n,m,r,c=map(int,input().split()) a=r-1 b=c-1 if a<=n-r : a=n-r if b<=m-c : b=m-c print(a+b) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for z : Integer.subrange(0, t-1) do ( var n : OclAny := null; var m : OclAny := null; var r : OclAny := null; var c : OclAny := null; Sequence{n,m,r,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : double := r - 1 ; var b : double := c - 1 ; if (a->compareTo(n - r)) <= 0 then ( a := n - r ) else skip ; if (b->compareTo(m - c)) <= 0 then ( b := m - c ) else skip ; execute (a + b)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) s=list(map(int,input().split())) z=[] for i in s : if i not in z and i<=n : z.append(i) print(n-len(z)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var z : Sequence := Sequence{} ; for i : s do ( if (z)->excludes(i) & (i->compareTo(n)) <= 0 then ( execute ((i) : z) ) else skip) ; execute (n - (z)->size())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def printDiamond(n): print("") j=0 for i in range(0,n): for j in range(i,n): print("*",end="") for j in range(0,2*i+1): print("",end="") for j in range(i,n): print("*",end="") print("") for i in range(0,n-1): for j in range(0,i+2): print("*",end="") for j in range(0,2*(n-1-i)-1): print("",end="") for j in range(0,i+2): print("*",end="") print("") print("") if __name__=='__main__' : n=3 print("Inverse Diamond Pattern for n=",n) printDiamond(n) n=7 print("\nInverse Diamond Pattern for n=",n) printDiamond(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( n := 3 ; execute ("Inverse Diamond Pattern for n=")->display() ; printDiamond(n) ; n := 7 ; execute ("\nInverse Diamond Pattern for n=")->display() ; printDiamond(n) ) else skip; operation printDiamond(n : OclAny) pre: true post: true activity: execute ("")->display() ; var j : int := 0 ; for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(i, n-1) do ( execute ("*")->display()) ; for j : Integer.subrange(0, 2 * i + 1-1) do ( execute ("")->display()) ; for j : Integer.subrange(i, n-1) do ( execute ("*")->display()) ; execute ("")->display()) ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(0, i + 2-1) do ( execute ("*")->display()) ; for j : Integer.subrange(0, 2 * (n - 1 - i) - 1-1) do ( execute ("")->display()) ; for j : Integer.subrange(0, i + 2-1) do ( execute ("*")->display()) ; execute ("")->display()) ; execute ("")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def Series(Arr,N,K): count=0 for i in range(N): if Arr[i]==1 : count+=1 if K>=(N-count): return 1 return 0 Arr=[5,1,2] N=len(Arr) K=2 result=Series(Arr,N,K) if result==1 : print("Possible") else : print("Not Possible") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Arr := Sequence{5}->union(Sequence{1}->union(Sequence{ 2 })) ; N := (Arr)->size() ; K := 2 ; var result : OclAny := Series(Arr, N, K) ; if result = 1 then ( execute ("Possible")->display() ) else ( execute ("Not Possible")->display() ); operation Series(Arr : OclAny, N : OclAny, K : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, N-1) do ( if Arr[i+1] = 1 then ( count := count + 1 ) else skip) ; if (K->compareTo((N - count))) >= 0 then ( return 1 ) else skip ; return 0; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def usingBinarySearch(start,end,N,S): if(start>=end): return start ; mid=start+(end-start)//2 ; totalSum=(N*(N+1))//2 ; midSum=(mid*(mid+1))//2 ; if((totalSum-midSum)<=S): return usingBinarySearch(start,mid,N,S); return usingBinarySearch(mid+1,end,N,S); if __name__=="__main__" : N=5 ; S=11 ; print(N-usingBinarySearch(1,N,N,S)+1); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( N := 5; ; S := 11; ; execute (N - usingBinarySearch(1, N, N, S) + 1)->display(); ) else skip; operation usingBinarySearch(start : OclAny, end : OclAny, N : OclAny, S : OclAny) pre: true post: true activity: if ((start->compareTo(end)) >= 0) then ( return start; ) else skip ; var mid : OclAny := start + (end - start) div 2; ; var totalSum : int := (N * (N + 1)) div 2; ; var midSum : int := (mid * (mid + 1)) div 2; ; if (((totalSum - midSum)->compareTo(S)) <= 0) then ( return usingBinarySearch(start, mid, N, S); ) else skip ; return usingBinarySearch(mid + 1, end, N, S);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) As=list(map(int,input().split())) num_count={} count_comb={} num_ans={} sum_combs=0 def comb2(n): if n not in count_comb : count_comb[n]=(n*(n-1))//2 return count_comb[n] def ans(ex_num): ex_count=num_count[ex_num] return sum_combs+comb2(ex_count-1)-comb2(ex_count) for a in As : if a not in num_count : num_count[a]=0 num_count[a]+=1 for _,c in num_count.items(): sum_combs+=comb2(c) for a in As : print(ans(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var As : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var num_count : OclAny := Set{} ; var count_comb : OclAny := Set{} ; var num_ans : OclAny := Set{} ; var sum_combs : int := 0 ; skip ; skip ; for a : As do ( if (num_count)->excludes(a) then ( num_count[a+1] := 0 ) else skip ; num_count[a+1] := num_count[a+1] + 1) ; for _tuple : num_count->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var _anon : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); sum_combs := sum_combs + comb2(c)) ; for a : As do ( execute (ans(a))->display()); operation comb2(n : OclAny) : OclAny pre: true post: true activity: if (count_comb)->excludes(n) then ( count_comb[n+1] := (n * (n - 1)) div 2 ) else skip ; return count_comb[n+1]; operation ans(ex_num : OclAny) : OclAny pre: true post: true activity: var ex_count : OclAny := num_count[ex_num+1] ; return sum_combs + comb2(ex_count - 1) - comb2(ex_count); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter def main(): n=int(input()) A=[int(x)for x in input().split()] a_c=Counter(A) res=[int(v*(v-1)/2)for v in a_c.values()] cnt=sum(res) for a in A : ans=(cnt-(a_c[a]-1)) print(ans) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; var a_c : OclAny := Counter(A) ; var res : Sequence := a_c.values()->select(v | true)->collect(v | (("" + ((v * (v - 1) / 2)))->toInteger())) ; var cnt : OclAny := (res)->sum() ; for a : A do ( var ans : double := (cnt - (a_c[a+1] - 1)) ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import numpy as np N=int(input()) A=np.array(list(map(int,input().split()))) unique_num,counts=np.unique(A,return_counts=True) dic0={} dic1={} dic2={} Combination_pattern=[] for i in range(len(counts)): Combination=counts[i]*(counts[i]-1)//2 dic0[unique_num[i]]=counts[i] dic1[unique_num[i]]=Combination dic2.setdefault(unique_num[i]) Combination_pattern.append(Combination) totalcombination=sum(Combination_pattern) for j in range(N): n=A[j] if dic2[n]==None : reduced_pattern=(dic0[n]-1)*(dic0[n]-2)//2 ans=totalcombination-dic1[n]+reduced_pattern dic2[n]=ans print(ans) else : print(dic2[n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := (((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) ; var unique_num : OclAny := null; var counts : OclAny := null; Sequence{unique_num,counts} := ; var dic0 : OclAny := Set{} ; var dic1 : OclAny := Set{} ; var dic2 : OclAny := Set{} ; var Combination_pattern : Sequence := Sequence{} ; for i : Integer.subrange(0, (counts)->size()-1) do ( var Combination : int := counts[i+1] * (counts[i+1] - 1) div 2 ; dic0[unique_num[i+1]+1] := counts[i+1] ; dic1[unique_num[i+1]+1] := Combination ; dic2.setdefault(unique_num[i+1]) ; execute ((Combination) : Combination_pattern)) ; var totalcombination : OclAny := (Combination_pattern)->sum() ; for j : Integer.subrange(0, N-1) do ( var n : OclAny := A[j+1] ; if dic2[n+1] = null then ( var reduced_pattern : int := (dic0[n+1] - 1) * (dic0[n+1] - 2) div 2 ; var ans : double := totalcombination - dic1[n+1] + reduced_pattern ; dic2[n+1] := ans ; execute (ans)->display() ) else ( execute (dic2[n+1])->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while(t>0): s=input() s1=input() k=0 for i in range(0,len(s1)-1): k+=abs((s.index(s1[i])+1)-(s.index(s1[i+1])+1)) print(k) t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while (t > 0) do ( var s : String := (OclFile["System.in"]).readLine() ; var s1 : String := (OclFile["System.in"]).readLine() ; var k : int := 0 ; for i : Integer.subrange(0, (s1)->size() - 1-1) do ( k := k + ((s->indexOf(s1[i+1]) - 1 + 1) - (s->indexOf(s1[i + 1+1]) - 1 + 1))->abs()) ; execute (k)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() n=int(s[0]) s=input().split() d={} dc={} summ=0 for i in s : if i not in d : d[i]=1 else : d[i]+=1 for i in d : n=d[i] if n>1 : e=n*(n-1)/2 summ+=e dc[i]=e else : dc[i]=0 for i in s : n=d[i]-1 e=n*(n-1)/2 print(int(summ-dc[i]+e)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var n : int := ("" + ((s->first())))->toInteger() ; s := input().split() ; var d : OclAny := Set{} ; var dc : OclAny := Set{} ; var summ : int := 0 ; for i : s->characters() do ( if (d)->excludes(i) then ( d[i+1] := 1 ) else ( d[i+1] := d[i+1] + 1 )) ; for i : d do ( n := d[i+1] ; if n > 1 then ( var e : double := n * (n - 1) / 2 ; summ := summ + e ; dc[i+1] := e ) else ( dc[i+1] := 0 )) ; for i : s->characters() do ( n := d[i+1] - 1 ; e := n * (n - 1) / 2 ; execute (("" + ((summ - dc[i+1] + e)))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter N=int(input()) A=list(map(int,input().split())) a=list(set(A)) cc=Counter(A) dup=set([x for x in a if cc[x]>1]) c_l=[(cc[i]-1)*(cc[i])/2 for i in a] al=sum(c_l) [print(int(al-cc[k]+1))if k in dup else print(int(al))for k in A] ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := (Set{}->union((A))) ; var cc : OclAny := Counter(A) ; var dup : Set := Set{}->union((a->select(x | cc[x+1] > 1)->collect(x | (x)))) ; var c_l : Sequence := a->select(i | true)->collect(i | ((cc[i+1] - 1) * (cc[i+1]) / 2)) ; var al : OclAny := (c_l)->sum() ; ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- result=[] for t in range(int(input())): n,m,r,c=map(int,input().split()) t=0 t=c-1 if c-1>m-c else m-c t+=r-1 if r-1>n-r else n-r result.append(t) for i in result : print(i) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var result : Sequence := Sequence{} ; for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; var r : OclAny := null; var c : OclAny := null; Sequence{n,m,r,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : int := 0 ; t := if (c - 1->compareTo(m - c)) > 0 then c - 1 else m - c endif ; t := t + if (r - 1->compareTo(n - r)) > 0 then r - 1 else n - r endif ; execute ((t) : result)) ; for i : result do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from operator import mul from fractions import Fraction from functools import reduce sol_super_comb={i : 0 for i in range(61)} def luntik_and_subsequence(): t=int(input()) for _ in range(t): n=int(input()) seq=list(map(int,input().split())) seq.sort(reverse=True) if(1 in seq): if(0 not in seq): print(seq.count(1)) elif(0 in seq and len(seq)==2): print(2) else : print(seq.count(1)*super_comb(seq.count(0))+seq.count(1)) else : print(0) def super_comb(n): if(sol_super_comb[n]>0): return sol_super_comb[n] soma=0 for i in range(n+1): if(i>=1): soma+=comb(n,i) sol_super_comb[n]=soma return soma def comb(n,k): return int(reduce(mul,(Fraction(n-i,i+1)for i in range(k)),1)) luntik_and_subsequence() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var sol_super_comb : Map := Integer.subrange(0, 61-1)->select(i | true)->collect(i | Map{i |-> 0})->unionAll() ; skip ; skip ; skip ; luntik_and_subsequence(); operation luntik_and_subsequence() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var seq : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; seq := seq->sort() ; if ((seq)->includes(1)) then ( if ((seq)->excludes(0)) then ( execute (seq->count(1))->display() ) else (if ((seq)->includes(0) & (seq)->size() = 2) then ( execute (2)->display() ) else ( execute (seq->count(1) * super_comb(seq->count(0)) + seq->count(1))->display() ) ) ) else ( execute (0)->display() )); operation super_comb(n : OclAny) : OclAny pre: true post: true activity: if (sol_super_comb[n+1] > 0) then ( return sol_super_comb[n+1] ) else skip ; var soma : int := 0 ; for i : Integer.subrange(0, n + 1-1) do ( if (i >= 1) then ( soma := soma + comb(n, i) ) else skip) ; sol_super_comb[n+1] := soma ; return soma; operation comb(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: return ("" + ((reduce(mul, Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name Fraction)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (name i)))))))) , (argument (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name k)))))))) ))))))))}, 1))))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): input() array=input().split() total=0 for j in array : if j=='1' : total+=1 for j in array : if j=='0' : total*=2 print(total) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( input() ; var array : OclAny := input().split() ; var total : int := 0 ; for j : array do ( if j = '1' then ( total := total + 1 ) else skip) ; for j : array do ( if j = '0' then ( total := total * 2 ) else skip) ; execute (total)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def fatorial(n): aux=n result=1 if(n==0): return 1 while(aux>0): result=result*aux aux=aux-1 return result test=int(input()) for i in range(0,test): n=int(input()) array=list(map(int,input().split()[: n])) ones=0 zeros=0 for k in array : if k==1 : ones=ones+1 elif k==0 : zeros=zeros+1 if(ones<1): print(0) else : comb=ones if(zeros>0): comb=comb*(2**zeros) print(int(comb)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var test : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, test-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var array : Sequence := ((input().split().subrange(1,n))->collect( _x | (OclType["int"])->apply(_x) )) ; var ones : int := 0 ; var zeros : int := 0 ; for k : array do ( if k = 1 then ( ones := ones + 1 ) else (if k = 0 then ( zeros := zeros + 1 ) else skip)) ; if (ones < 1) then ( execute (0)->display() ) else ( var comb : int := ones ; if (zeros > 0) then ( comb := comb * ((2)->pow(zeros)) ) else skip ; execute (("" + ((comb)))->toInteger())->display() )); operation fatorial(n : OclAny) : OclAny pre: true post: true activity: var aux : OclAny := n ; var result : int := 1 ; if (n = 0) then ( return 1 ) else skip ; while (aux > 0) do ( result := result * aux ; aux := aux - 1) ; return result; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for i in range(t): n=int(input()) zeros=0 ones=0 arr=input().split(' ') for tmp in arr : if(tmp=='0'): zeros+=1 if(tmp=='1'): ones+=1 print(ones*(2**zeros)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var zeros : int := 0 ; var ones : int := 0 ; var arr : OclAny := input().split(' ') ; for tmp : arr do ( if (tmp = '0') then ( zeros := zeros + 1 ) else skip ; if (tmp = '1') then ( ones := ones + 1 ) else skip) ; execute (ones * ((2)->pow(zeros)))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): casos=int(input()); for i in range(casos): lista=[]; n=int(input()); entrada=input().split(); for j in entrada : lista.append(int(j)); ones=lista.count(1); zeros=lista.count(0); print(ones*(2**zeros)); main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var casos : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); ; for i : Integer.subrange(0, casos-1) do ( var lista : Sequence := Sequence{}; ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); ; var entrada : OclAny := input().split(); ; for j : entrada do ( execute ((("" + ((j)))->toInteger()) : lista);) ; var ones : int := lista->count(1); ; var zeros : int := lista->count(0); ; execute (ones * ((2)->pow(zeros)))->display();); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt N=100005 def ABUNDANT(): v=set(); for i in range(1,N): sum=1 for j in range(2,int(sqrt(i))+1): if(i % j==0): sum+=j if(i/j!=j): sum+=i//j if(sum>i): v.add(i) return v def SumOfAbundant(n): v=ABUNDANT() for i in range(1,n+1): if(list(v).count(i)and list(v).count(n-i)): print(i," ",n-i) return print(-1) if __name__=="__main__" : n=24 SumOfAbundant(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := 100005 ; skip ; skip ; if __name__ = "__main__" then ( n := 24 ; SumOfAbundant(n) ) else skip; operation ABUNDANT() : OclAny pre: true post: true activity: var v : Set := Set{}->union(()); ; for i : Integer.subrange(1, N-1) do ( var sum : int := 1 ; for j : Integer.subrange(2, ("" + ((sqrt(i))))->toInteger() + 1-1) do ( if (i mod j = 0) then ( sum := sum + j ) else skip ; if (i / j /= j) then ( sum := sum + i div j ) else skip) ; if ((sum->compareTo(i)) > 0) then ( execute ((i) : v) ) else skip) ; return v; operation SumOfAbundant(n : OclAny) pre: true post: true activity: v := ABUNDANT() ; for i : Integer.subrange(1, n + 1-1) do ( if (OclType["Sequence"](v)->count(i) & OclType["Sequence"](v)->count(n - i)) then ( execute (i)->display() ; return ) else skip) ; execute (-1)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if(a==0 or b==0): return False if(a==b): return a if(a>b): return gcd(a-b,b) return gcd(a,b-a) def coprime(a,b): return(gcd(a,b)==1) def numOfPairs(arr,n): count=0 for i in range(0,n-1): for j in range(i+1,n): if(coprime(arr[i],arr[j])): count=count+1 return count arr=[1,2,5,4,8,3,9] n=len(arr) print(numOfPairs(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; arr := Sequence{1}->union(Sequence{2}->union(Sequence{5}->union(Sequence{4}->union(Sequence{8}->union(Sequence{3}->union(Sequence{ 9 })))))) ; n := (arr)->size() ; execute (numOfPairs(arr, n))->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if (a = 0 or b = 0) then ( return false ) else skip ; if (a = b) then ( return a ) else skip ; if ((a->compareTo(b)) > 0) then ( return gcd(a - b, b) ) else skip ; return gcd(a, b - a); operation coprime(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: return (gcd(a, b) = 1); operation numOfPairs(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; for i : Integer.subrange(0, n - 1-1) do ( for j : Integer.subrange(i + 1, n-1) do ( if (coprime(arr[i+1], arr[j+1])) then ( count := count + 1 ) else skip)) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n=int(input()) a=list(map(int,input().split())) p=sum(a) if p % n==0 : print(0) else : print(1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var p : OclAny := (a)->sum() ; if p mod n = 0 then ( execute (0)->display() ) else ( execute (1)->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) for i in range(n): list1=[] abs_sum=0 kb=[*input()] w=[*input()] for char in w : if char in kb : list1.append(kb.index(char)+1) for j in range(len(list1)-1): abs_sum+=abs(list1[j+1]-list1[j]) print(abs_sum) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( var list1 : Sequence := Sequence{} ; var abs_sum : int := 0 ; var kb : Sequence := (OclFile["System.in"]).readLine() ; var w : Sequence := (OclFile["System.in"]).readLine() ; for char : w do ( if (kb)->includes(char) then ( execute ((kb->indexOf(char) - 1 + 1) : list1) ) else skip) ; for j : Integer.subrange(0, (list1)->size() - 1-1) do ( abs_sum := abs_sum + (list1[j + 1+1] - list1[j+1])->abs()) ; execute (abs_sum)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for k in range(t): n=int(input()) l=list(map(int,input().split())) s=sum(l) if s % n==0 : print("0") else : print("1") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for k : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var s : OclAny := (l)->sum() ; if s mod n = 0 then ( execute ("0")->display() ) else ( execute ("1")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,m,r,c=map(int,input().split()) print(max(r-1,n-r)+max(c-1,m-c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; var r : OclAny := null; var c : OclAny := null; Sequence{n,m,r,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{r - 1, n - r}->max() + Set{c - 1, m - c}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def main(): s=sys.stdin.read().strip().split('\n') r=[] for i in s[2 : : 2]: l=list(map(int,i.split())) r.append(int(bool(sum(l)% len(l)))) return r print(*main(),sep='\n') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; execute ((argument * (test (logical_test (comparison (expr (atom (name main)) (trailer (arguments ( )))))))))->display(); operation main() : OclAny pre: true post: true activity: var s : OclAny := sys.stdin.readAll()->trim().split(' ') ; var r : Sequence := Sequence{} ; for i : s(subscript (test (logical_test (comparison (expr (atom (number (integer 2))))))) : (sliceop : (test (logical_test (comparison (expr (atom (number (integer 2))))))))) do ( var l : Sequence := ((i.split())->collect( _x | (OclType["int"])->apply(_x) )) ; execute ((("" + ((((l)->sum() mod (l)->size())->toBoolean())))->toInteger()) : r)) ; return r; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for _ in range(T): N=int(input()) A=list(map(int,input().split())) S=sum(A) print(int(bool(S % N))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, T-1) do ( var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var S : OclAny := (A)->sum() ; execute (("" + (((S mod N)->toBoolean())))->toInteger())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) s=sum(map(int,input().split())) print(1 if s % n else 0) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var s : OclAny := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sum() ; execute (if s mod n then 1 else 0 endif)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): n=int(input()) arr=[] for _ in range(n): val,move=map(int,input().split()) arr.append((move,val)) arr.sort() moves=1 res=0 while moves and arr : moves-=1 move,score=arr.pop() moves+=move res+=score print(res) def main(): t=1 for _ in range(t): solution() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; main(); operation solution() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var val : OclAny := null; var move : OclAny := null; Sequence{val,move} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{move, val}) : arr)) ; arr := arr->sort() ; var moves : int := 1 ; var res : int := 0 ; while moves & arr do ( moves := moves - 1 ; var move : OclAny := null; var score : OclAny := null; Sequence{move,score} := arr->last() ; arr := arr->front() ; moves := moves + move ; res := res + score) ; execute (res)->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys a=[[0 for i in range(2)]for i in range(3000)] n=int(input()) arr=[] for i in range(n): x,y=map(int,input().split()) a[i][1]+=x a[i][0]+=y if a[i][0]==0 : arr.append(a[i][1]) a.sort(reverse=True) ans=0 moves=1 for i in range(n): if a[i][0]!=0 : ans+=a[i][1] moves+=a[i][0]-1 else : break arr.sort() i=len(arr)-1 while moves>0 and len(arr)>0 and i>=0 : ans+=arr[i] moves-=1 i-=1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : Sequence := Integer.subrange(0, 3000-1)->select(i | true)->collect(i | (Integer.subrange(0, 2-1)->select(i | true)->collect(i | (0)))) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var x : OclAny := null; var y : OclAny := null; Sequence{x,y} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; a[i+1][1+1] := a[i+1][1+1] + x ; a[i+1]->first() := a[i+1]->first() + y ; if a[i+1]->first() = 0 then ( execute ((a[i+1][1+1]) : arr) ) else skip) ; a := a->sort() ; var ans : int := 0 ; var moves : int := 1 ; for i : Integer.subrange(0, n-1) do ( if a[i+1]->first() /= 0 then ( ans := ans + a[i+1][1+1] ; moves := moves + a[i+1]->first() - 1 ) else ( break )) ; arr := arr->sort() ; var i : double := (arr)->size() - 1 ; while moves > 0 & (arr)->size() > 0 & i >= 0 do ( ans := ans + arr[i+1] ; moves := moves - 1 ; i := i - 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[] for i in range(n): l.append(list(map(int,input().split()))) l.sort(key=lambda x :(-x[1],-x[0])) c=1 ind=0 ans=0 while c>0 and indtoInteger() ; var l : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : l)) ; l := l->sort() ; var c : int := 1 ; var ind : int := 0 ; var ans : int := 0 ; while c > 0 & (ind->compareTo(n)) < 0 do ( ans := ans + l[ind+1]->first() ; c := c + l[ind+1][1+1] ; ind := ind + 1 ; c := c - 1) ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) cards=[] for _ in range(n): cards.append(tuple(map(int,input().split()))) cards.sort(reverse=True,key=lambda x :(x[1],x[0])) result=0 counter=1 for card in cards : if counter==0 : break counter-=1 result+=card[0] counter+=card[1] print(result) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cards : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((((input().split())->collect( _x | (OclType["int"])->apply(_x) ))) : cards)) ; cards := cards->sort() ; var result : int := 0 ; var counter : int := 1 ; for card : cards do ( if counter = 0 then ( break ) else skip ; counter := counter - 1 ; result := result + card->first() ; counter := counter + card[1+1]) ; execute (result)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=[] for _ in range(n): a,b=map(int,input().split()) l.append([a,b]) l.sort(key=lambda l : l[0],reverse=True) l.sort(key=lambda l : l[1],reverse=True) c=1 p=0 for x in l : if c==0 : break p+=x[0] c+=x[1] c-=1 print(p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute ((Sequence{a}->union(Sequence{ b })) : l)) ; l := l->sort() ; l := l->sort() ; var c : int := 1 ; var p : int := 0 ; for x : l do ( if c = 0 then ( break ) else skip ; p := p + x->first() ; c := c + x[1+1] ; c := c - 1) ; execute (p)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : n=int(input()) a=[i for i in input()] b=[i for i in input()] d=True p=0 for i in range(len(a)-1): if p==0 : if a[i]=='0' : if a[i+1]=='1' : if b[i+1]=='0' : p=1 else : d=False ; break else : p=0 else : if b[i]=='0' : if b[i+1]=='1' : if a[i+1]=='0' : p=0 else : d=False ; break else : p=1 print('YES' if d else 'NO') t-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while t > 0 do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (OclFile["System.in"]).readLine()->select(i | true)->collect(i | (i)) ; var b : Sequence := (OclFile["System.in"]).readLine()->select(i | true)->collect(i | (i)) ; var d : boolean := true ; var p : int := 0 ; for i : Integer.subrange(0, (a)->size() - 1-1) do ( if p = 0 then ( if a[i+1] = '0' then ( if a[i + 1+1] = '1' then ( if b[i + 1+1] = '0' then ( p := 1 ) else ( d := false; break ) ) else ( p := 0 ) ) else skip ) else ( if b[i+1] = '0' then ( if b[i + 1+1] = '1' then ( if a[i + 1+1] = '0' then ( p := 0 ) else ( d := false; break ) ) else ( p := 1 ) ) else skip )) ; execute (if d then 'YES' else 'NO' endif)->display() ; t := t - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,m,r,c=map(int,input().split()) print(max(r-1,n-r)+max(c-1,m-c)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var m : OclAny := null; var r : OclAny := null; var c : OclAny := null; Sequence{n,m,r,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; execute (Set{r - 1, n - r}->max() + Set{c - 1, m - c}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) a.sort() flag=True for i in range(1,n): if(a[i]-a[i-1]>1): flag=False break if flag==True : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; var flag : boolean := true ; for i : Integer.subrange(1, n-1) do ( if (a[i+1] - a[i - 1+1] > 1) then ( flag := false ; break ) else skip) ; if flag = true then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ReplaceElements(arr,n): if(n<=1): return prev=arr[0] arr[0]=arr[0]+arr[1] for i in range(1,n-1): curr=arr[i] arr[i]=prev+arr[i+1] prev=curr arr[n-1]=prev+arr[n-1] if __name__=="__main__" : arr=[2,3,4,5,6] n=len(arr) ReplaceElements(arr,n) for i in range(n): print(arr[i],end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( arr := Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 })))) ; n := (arr)->size() ; ReplaceElements(arr, n) ; for i : Integer.subrange(0, n-1) do ( execute (arr[i+1])->display()) ) else skip; operation ReplaceElements(arr : OclAny, n : OclAny) pre: true post: true activity: if (n <= 1) then ( return ) else skip ; var prev : OclAny := arr->first() ; arr->first() := arr->first() + arr[1+1] ; for i : Integer.subrange(1, n - 1-1) do ( var curr : OclAny := arr[i+1] ; arr[i+1] := prev + arr[i + 1+1] ; prev := curr) ; arr[n - 1+1] := prev + arr[n - 1+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): n=int(input()) arr=list(map(int,input().split())) a=list(set(arr)) a.sort() if(max(a)-min(a))toInteger()-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var arr : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : Sequence := (Set{}->union((arr))) ; a := a->sort() ; if (((a)->max() - (a)->min())->compareTo((a)->size())) < 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for _ in range(t): n=int(input()) a=sorted(int(i)for i in input().split()) res="NO" if any(a[i+1]-a[i]>1 for i in range(n-1))else "YES" print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for _anon : Integer.subrange(0, t-1) do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))->sort() ; var res : String := if ((argument (test (logical_test (comparison (comparison (expr (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (expr (atom (name i))) + (expr (atom (number (integer 1)))))))))) ]))) - (expr (atom (name a)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ]))))) > (comparison (expr (atom (number (integer 1)))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1)))))))))) )))))))))->exists( _x | _x = true ) then "NO" else "YES" endif ; execute (res)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def can_remove(a,n): for i in range(n-1): if a[i+1]-a[i]>1 : return False return True for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) a.sort() if can_remove(a,n): print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; a := a->sort() ; if can_remove(a, n) then ( execute ("YES")->display() ) else ( execute ("NO")->display() )); operation can_remove(a : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n - 1-1) do ( if a[i + 1+1] - a[i+1] > 1 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def towerOfHanoi(n,from_rod,to_rod,aux_rod1,aux_rod2): if(n==0): return if(n==1): print("Move disk",n,"from rod",from_rod,"c to rod",to_rod) return towerOfHanoi(n-2,from_rod,aux_rod1,aux_rod2,to_rod) print("Move disk",n-1,"from rod",from_rod,"c to rod",aux_rod2) print("Move disk",n,"from rod",from_rod,"c to rod",to_rod) print("Move disk",n-1,"from rod",aux_rod2,"c to rod",to_rod) towerOfHanoi(n-2,aux_rod1,to_rod,from_rod,aux_rod2) n=4 towerOfHanoi(n,'A','D','B','C') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 4 ; towerOfHanoi(n, 'A', 'D', 'B', 'C'); operation towerOfHanoi(n : OclAny, from_rod : OclAny, to_rod : OclAny, aux_rod1 : OclAny, aux_rod2 : OclAny) pre: true post: true activity: if (n = 0) then ( return ) else skip ; if (n = 1) then ( execute ("Move disk")->display() ; return ) else skip ; towerOfHanoi(n - 2, from_rod, aux_rod1, aux_rod2, to_rod) ; execute ("Move disk")->display() ; execute ("Move disk")->display() ; execute ("Move disk")->display() ; towerOfHanoi(n - 2, aux_rod1, to_rod, from_rod, aux_rod2); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- k=int(input()) while k : n=int(input()) a=list(map(int,input().split())) c=1 a=sorted(a) for i in range(1,n): if a[i]-a[i-1]>1 : print('NO') break else : c+=1 if c==n : print('YES') k-=1 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; while k do ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var c : int := 1 ; a := a->sort() ; for i : Integer.subrange(1, n-1) do ( if a[i+1] - a[i - 1+1] > 1 then ( execute ('NO')->display() ; break ) else ( c := c + 1 )) ; if c = n then ( execute ('YES')->display() ) else skip ; k := k - 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math ; def cal_sin(n): accuracy=0.0001 ; n=n*(3.142/180.0); x1=n ; sinx=n ; sinval=math.sin(n); i=1 ; while(True): denominator=2*i*(2*i+1); x1=-x1*n*n/denominator ; sinx=sinx+x1 ; i=i+1 ; if(accuracy<=abs(sinval-sinx)): break ; print(round(sinx)); n=90 ; cal_sin(n); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip; ; skip ; n := 90; ; cal_sin(n);; operation cal_sin(n : OclAny) pre: true post: true activity: var accuracy : double := 0.0001; ; n := n * (3.142 / 180.0); ; var x1 : OclAny := n; ; var sinx : OclAny := n; ; var sinval : double := (n)->sin(); ; var i : int := 1; ; while (true) do ( var denominator : int := 2 * i * (2 * i + 1); ; x1 := -x1 * n * n / denominator; ; sinx := sinx + x1; ; i := i + 1; ; if ((accuracy->compareTo((sinval - sinx)->abs())) <= 0) then ( break; ) else skip) ; execute ((sinx)->round())->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def multiply(array,n): pro=1 for i in range(n): pro=pro*array[i] return pro array=[1,2,3,4,5,6] n=len(array) print(multiply(array,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; array := Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))))) ; n := (array)->size() ; execute (multiply(array, n))->display(); operation multiply(array : OclAny, n : OclAny) : OclAny pre: true post: true activity: var pro : int := 1 ; for i : Integer.subrange(0, n-1) do ( pro := pro * array[i+1]) ; return pro; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- l=[0 for _ in range(64)] for i in range(int(input())): query=list(input().split()) order=query[0] if order=="0" : print(1 if l[int(query[1])]else 0) elif order=="1" : l[int(query[1])]=1 elif order=="2" : l[int(query[1])]=0 elif order=="3" : l[int(query[1])]^=1 elif order=="4" : print(1 if all(l)else 0) elif order=="5" : print(1 if any(l)else 0) elif order=="6" : print(1 if not any(l)else 0) elif order=="7" : print(sum(l)) elif order=="8" : tmp=0 for i in reversed(range(64)): tmp+=l[i]*2**i print(tmp) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var l : Sequence := Integer.subrange(0, 64-1)->select(_anon | true)->collect(_anon | (0)) ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var query : Sequence := (input().split()) ; var order : OclAny := query->first() ; if order = "0" then ( execute (if l[("" + ((query[1+1])))->toInteger()+1] then 1 else 0 endif)->display() ) else (if order = "1" then ( l[("" + ((query[1+1])))->toInteger()+1] := 1 ) else (if order = "2" then ( l[("" + ((query[1+1])))->toInteger()+1] := 0 ) else (if order = "3" then ( l[("" + ((query[1+1])))->toInteger()+1] := l[("" + ((query[1+1])))->toInteger()+1] xor 1 ) else (if order = "4" then ( execute (if (l)->forAll( _x | _x = true ) then 1 else 0 endif)->display() ) else (if order = "5" then ( execute (if (l)->exists( _x | _x = true ) then 1 else 0 endif)->display() ) else (if order = "6" then ( execute (if not((l)->exists( _x | _x = true )) then 1 else 0 endif)->display() ) else (if order = "7" then ( execute ((l)->sum())->display() ) else (if order = "8" then ( var tmp : int := 0 ; for i : (Integer.subrange(0, 64-1))->reverse() do ( tmp := tmp + l[i+1] * (2)->pow(i)) ; execute (tmp)->display() ) else skip ) ) ) ) ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- q=int(input()) x=0 MASK=2**64-1 def x_test(i): return int((x &(1<0) def x_set(i): global x x |=1<0) def x_none(): return int(x & MASK==0) def x_count(): return bin(x).count("1") def x_val(): return x command=[x_test,x_set,x_clear,x_flip,x_all,x_any,x_none,x_count,x_val] for j in range(q): t,*cmd=map(int,input().split()) ans=command[t](*cmd) if ans is not None : print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { attribute x : OclAny; attribute x : OclAny; attribute x : OclAny; operation initialise() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var x : int := 0 ; var MASK : double := (2)->pow(64) - 1 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; var command : Sequence := Sequence{x_test}->union(Sequence{x_set}->union(Sequence{x_clear}->union(Sequence{x_flip}->union(Sequence{x_all}->union(Sequence{x_any}->union(Sequence{x_none}->union(Sequence{x_count}->union(Sequence{ x_val })))))))) ; for j : Integer.subrange(0, q-1) do ( var t : OclAny := null; var cmd : OclAny := null; Sequence{t,cmd} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ans : OclAny := command[t+1]((argument * (test (logical_test (comparison (expr (atom (name cmd)))))))) ; if not(ans <>= null) then ( execute (ans)->display() ) else skip); operation x_test(i : OclAny) : OclAny pre: true post: true activity: return ("" + (((MathLib.bitwiseAnd(x, (1 * (2->pow(i))))) > 0)))->toInteger(); operation x_set(i : OclAny) pre: true post: true activity: skip ; x := x or 1 * (2->pow(i)); operation x_clear(i : OclAny) pre: true post: true activity: skip ; if MathLib.bitwiseAnd(x, (1 * (2->pow(i)))) then ( x := x xor 1 * (2->pow(i)) ) else skip; operation x_flip(i : OclAny) pre: true post: true activity: skip ; x := x xor 1 * (2->pow(i)); operation x_all() : OclAny pre: true post: true activity: return ("" + ((MathLib.bitwiseAnd(x, MASK) = MASK)))->toInteger(); operation x_any() : OclAny pre: true post: true activity: return ("" + ((MathLib.bitwiseAnd(x, MASK) > 0)))->toInteger(); operation x_none() : OclAny pre: true post: true activity: return ("" + ((MathLib.bitwiseAnd(x, MASK) = 0)))->toInteger(); operation x_count() : OclAny pre: true post: true activity: return bin(x)->count("1"); operation x_val() : OclAny pre: true post: true activity: return x; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ope_all(l): cnt=[1 if sum(l)==64 else 0] return print(*cnt) def ope_any(l): cnt=[0 if sum(l)==0 else 1] return print(*cnt) def ope_none(l): cnt=[1 if sum(l)==0 else 0] return print(*cnt) li=[0]*64 n=int(input()) ope=[input().split()for i in range(n)] ope=[[int(j)for j in ope[i]]for i in range(len(ope))] for i in range(n): if ope[i][0]==0 : n=[1 if li[ope[i][1]]==1 else 0] print(*n) elif ope[i][0]==1 : li[ope[i][1]]=1 elif ope[i][0]==2 : li[ope[i][1]]=0 elif ope[i][0]==3 : if li[ope[i][1]]==1 : li[ope[i][1]]=0 else : li[ope[i][1]]=1 elif ope[i][0]==4 : ope_all(li) elif ope[i][0]==5 : ope_any(li) elif ope[i][0]==6 : ope_none(li) elif ope[i][0]==7 : print(li.count(1)) else : int_li="".join(map(str,li)) int_li="".join(list(reversed(int_li))) print(int(int_li,2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; var li : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 64) ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var ope : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (input().split())) ; ope := Integer.subrange(0, (ope)->size()-1)->select(i | true)->collect(i | (ope[i+1]->select(j | true)->collect(j | (("" + ((j)))->toInteger())))) ; for i : Integer.subrange(0, n-1) do ( if ope[i+1]->first() = 0 then ( n := Sequence{ if li[ope[i+1][1+1]+1] = 1 then 1 else 0 endif } ; execute ((argument * (test (logical_test (comparison (expr (atom (name n))))))))->display() ) else (if ope[i+1]->first() = 1 then ( li[ope[i+1][1+1]+1] := 1 ) else (if ope[i+1]->first() = 2 then ( li[ope[i+1][1+1]+1] := 0 ) else (if ope[i+1]->first() = 3 then ( if li[ope[i+1][1+1]+1] = 1 then ( li[ope[i+1][1+1]+1] := 0 ) else ( li[ope[i+1][1+1]+1] := 1 ) ) else (if ope[i+1]->first() = 4 then ( ope_all(li) ) else (if ope[i+1]->first() = 5 then ( ope_any(li) ) else (if ope[i+1]->first() = 6 then ( ope_none(li) ) else (if ope[i+1]->first() = 7 then ( execute (li->count(1))->display() ) else ( var int_li : String := StringLib.sumStringsWithSeparator(((li)->collect( _x | (OclType["String"])->apply(_x) )), "") ; int_li := StringLib.sumStringsWithSeparator((((int_li)->reverse())), "") ; execute (("" + ((int_li, 2)))->toInteger())->display() ) ) ) ) ) ) ) ) ); operation ope_all(l : OclAny) : OclAny pre: true post: true activity: var cnt : Sequence := Sequence{ if (l)->sum() = 64 then 1 else 0 endif } ; return ((argument * (test (logical_test (comparison (expr (atom (name cnt))))))))->display(); operation ope_any(l : OclAny) : OclAny pre: true post: true activity: cnt := Sequence{ if (l)->sum() = 0 then 0 else 1 endif } ; return ((argument * (test (logical_test (comparison (expr (atom (name cnt))))))))->display(); operation ope_none(l : OclAny) : OclAny pre: true post: true activity: cnt := Sequence{ if (l)->sum() = 0 then 1 else 0 endif } ; return ((argument * (test (logical_test (comparison (expr (atom (name cnt))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countTriplets(A,B,C): ans=0 for i in range(1,A+1): for j in range(1,B+1): for k in range(1,C+1): if(i*k>j*j): ans+=1 return ans A=3 B=2 C=2 print(countTriplets(A,B,C)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; A := 3 ; B := 2 ; C := 2 ; execute (countTriplets(A, B, C))->display(); operation countTriplets(A : OclAny, B : OclAny, C : OclAny) : OclAny pre: true post: true activity: var ans : int := 0 ; for i : Integer.subrange(1, A + 1-1) do ( for j : Integer.subrange(1, B + 1-1) do ( for k : Integer.subrange(1, C + 1-1) do ( if ((i * k->compareTo(j * j)) > 0) then ( ans := ans + 1 ) else skip))) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): q=int(input()) state=0 flag=1 for _ in range(q): param=input().split() c=int(param[0]) if len(param)>=2 : param[1]=int(param[1]) if c==0 : if state &(flag<<(param[1])): print("1") else : print("0") elif c==1 : state=state |(flag<<(param[1])) elif c==2 : state=state &(~(flag<<(param[1]))& 0xffffffffffffffff) elif c==3 : state=state ^(flag<<(param[1])) elif c==4 : if state & 0xffffffffffffffff==0xffffffffffffffff : print("1") else : print("0") elif c==5 : if(state & 0xffffffffffffffff)!=0 : print("1") else : print("0") elif c==6 : if(state & 0xffffffffffffffff)==0 : print("1") else : print("0") elif c==7 : print(format(state,"064b").count("1")) elif c==8 : print(int(state)) main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main(); operation main() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var state : int := 0 ; var flag : int := 1 ; for _anon : Integer.subrange(0, q-1) do ( var param : OclAny := input().split() ; var c : int := ("" + ((param->first())))->toInteger() ; if (param)->size() >= 2 then ( param[1+1] := ("" + ((param[1+1])))->toInteger() ) else skip ; if c = 0 then ( if MathLib.bitwiseAnd(state, (flag * (2->pow((param[1+1]))))) then ( execute ("1")->display() ) else ( execute ("0")->display() ) ) else (if c = 1 then ( state := MathLib.bitwiseOr(state, (flag * (2->pow((param[1+1]))))) ) else (if c = 2 then ( state := MathLib.bitwiseAnd(state, (MathLib.bitwiseAnd(MathLib.bitwiseNot((flag * (2->pow((param[1+1]))))), 0xffffffffffffffff))) ) else (if c = 3 then ( state := MathLib.bitwiseXor(state, (flag * (2->pow((param[1+1]))))) ) else (if c = 4 then ( if MathLib.bitwiseAnd(state, 0xffffffffffffffff) = 0xffffffffffffffff then ( execute ("1")->display() ) else ( execute ("0")->display() ) ) else (if c = 5 then ( if (MathLib.bitwiseAnd(state, 0xffffffffffffffff)) /= 0 then ( execute ("1")->display() ) else ( execute ("0")->display() ) ) else (if c = 6 then ( if (MathLib.bitwiseAnd(state, 0xffffffffffffffff)) = 0 then ( execute ("1")->display() ) else ( execute ("0")->display() ) ) else (if c = 7 then ( execute (format(state, "064b")->count("1"))->display() ) else (if c = 8 then ( execute (("" + ((state)))->toInteger())->display() ) else skip ) ) ) ) ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Bit : def __init__(self): self.data=0 def process(self,op,arg): funcs=(self.test,self.set,self.clear,self.flip,self.all,self.any,self.none,self.count,self.val) funcs[int(op)](arg) def test(self,arg): print(int(bool(self.data & 1<exists( _x | result = _x ); attribute data : int := 0; operation initialise() : Bit pre: true post: true activity: self.data := 0; return self; operation process(op : OclAny,arg : OclAny) pre: true post: true activity: var funcs : OclAny := Sequence{self.test, self.set, self.clear, self.flip, self.all, self.any, self.none, self.count, self.val} ; (expr (atom (name funcs)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name op)))))))) ))))))))) ])) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name arg)))))))) )))); operation test(arg : OclAny) pre: true post: true activity: execute (("" + (((MathLib.bitwiseAnd(self.data, 1 * (2->pow(("" + ((arg)))->toInteger()))))->toBoolean())))->toInteger())->display(); operation set(arg : OclAny) pre: true post: true activity: self.data := self.data or 1 * (2->pow(("" + ((arg)))->toInteger())); operation clear(arg : OclAny) pre: true post: true activity: self.data := self.data & MathLib.bitwiseNot((1 * (2->pow(("" + ((arg)))->toInteger())))); operation flip(arg : OclAny) pre: true post: true activity: self.data := self.data xor 1 * (2->pow(("" + ((arg)))->toInteger())); operation all(arg : OclAny) pre: true post: true activity: execute (("" + ((bin(self.data)->count('1') = 64)))->toInteger())->display(); operation any(arg : OclAny) pre: true post: true activity: execute (("" + ((self.data /= 0)))->toInteger())->display(); operation none(arg : OclAny) pre: true post: true activity: execute (("" + ((self.data = 0)))->toInteger())->display(); operation count(arg : OclAny) pre: true post: true activity: execute (bin(self.data)->count('1'))->display(); operation val(arg : OclAny) pre: true post: true activity: execute (self.data)->display(); } class FromPython { operation initialise() pre: true post: true activity: skip ; var b : Bit := (Bit.newBit()).initialise() ; for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( Sequence{op,arg} := ((OclFile["System.in"]).readLine() + ' 1').split().subrange(1,2) ; b.process(op, arg)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def bit(n): count=0 while(n): count+=1 n=n &(n-1) return count def maxSumOfBits(arr,n): for i in range(n): arr[i]=bit(arr[i]) incl=arr[0] excl=0 for i in range(1,n): if incl>excl : excl_new=incl else : excl_new=excl incl=excl+arr[i]; excl=excl_new if incl>excl : return incl else : return excl if __name__=="__main__" : arr=[1,2,4,5,6,7,20,25] n=len(arr) print(maxSumOfBits(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( arr := Sequence{1}->union(Sequence{2}->union(Sequence{4}->union(Sequence{5}->union(Sequence{6}->union(Sequence{7}->union(Sequence{20}->union(Sequence{ 25 }))))))) ; n := (arr)->size() ; execute (maxSumOfBits(arr, n))->display() ) else skip; operation bit(n : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; while (n) do ( count := count + 1 ; n := MathLib.bitwiseAnd(n, (n - 1))) ; return count; operation maxSumOfBits(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( arr[i+1] := bit(arr[i+1])) ; var incl : OclAny := arr->first() ; var excl : int := 0 ; for i : Integer.subrange(1, n-1) do ( if (incl->compareTo(excl)) > 0 then ( var excl_new : OclAny := incl ) else ( excl_new := excl ) ; incl := excl + arr[i+1]; ; excl := excl_new) ; if (incl->compareTo(excl)) > 0 then ( return incl ) else ( return excl ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) pares=0 bolo=[] for i in range(n): camada=input() bolo.append(camada) for i in range(n): contador=0 for j in range(n): if bolo[i][j]=='C' : contador+=1 pares+=((contador*(contador-1))//2) for j in range(n): contador=0 for i in range(n): if bolo[i][j]=='C' : contador+=1 pares+=((contador*(contador-1))//2) print(pares) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var pares : int := 0 ; var bolo : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( var camada : String := (OclFile["System.in"]).readLine() ; execute ((camada) : bolo)) ; for i : Integer.subrange(0, n-1) do ( var contador : int := 0 ; for j : Integer.subrange(0, n-1) do ( if bolo[i+1][j+1] = 'C' then ( contador := contador + 1 ) else skip) ; pares := pares + ((contador * (contador - 1)) div 2)) ; for j : Integer.subrange(0, n-1) do ( contador := 0 ; for i : Integer.subrange(0, n-1) do ( if bolo[i+1][j+1] = 'C' then ( contador := contador + 1 ) else skip) ; pares := pares + ((contador * (contador - 1)) div 2)) ; execute (pares)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os,sys,io,math from tokenize import Triple from array import array from math import* I=lambda :[*map(int,sys.stdin.readline().split())] IS=lambda : input() IN=lambda : int(input()) IF=lambda : float(input()) a='1000' b='1001' c='1010' d='1011' e='1100' f='1101' g='1110' h='1111' s=IS() res='' for i in s : if i=='>' : res+=a elif i=='<' : res+=b elif i=='+' : res+=c elif i=='-' : res+=d elif i=='.' : res+=e elif i==',' : res+=f elif i=='[' : res+=g else : res+=h print((int(res,2))%(10**6+3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; var I : Function := lambda $$ : OclAny in ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var IS : Function := lambda $$ : OclAny in ((OclFile["System.in"]).readLine()) ; var IN : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toInteger()) ; var IF : Function := lambda $$ : OclAny in (("" + (((OclFile["System.in"]).readLine())))->toReal()) ; var a : String := '1000' ; var b : String := '1001' ; var c : String := '1010' ; var d : String := '1011' ; var e : String := '1100' ; var f : String := '1101' ; var g : String := '1110' ; var h : String := '1111' ; var s : OclAny := IS->apply() ; var res : String := '' ; for i : s do ( if i = '>' then ( res := res + a ) else (if i = '<' then ( res := res + b ) else (if i = '+' then ( res := res + c ) else (if i = '-' then ( res := res + d ) else (if i = '.' then ( res := res + e ) else (if i = ',' then ( res := res + f ) else (if i = '[' then ( res := res + g ) else ( res := res + h ) ) ) ) ) ) ) ) ; execute ((("" + ((res, 2)))->toInteger()) mod ((10)->pow(6) + 3))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) cake=[] happiness=0 chocCount=0 nfat=1 for i in range(n): line=str(input()) cake.append(line) for j in line : if(j=='C'): chocCount+=1 if(chocCount>1): for i in range(chocCount,chocCount-2,-1): nfat*=i happiness+=nfat/2 nfat=1 chocCount=0 posCount=0 for j in range(n): for i in range(n): if(cake[i][j]=='C'): chocCount+=1 if(chocCount>1): for i in range(chocCount,chocCount-2,-1): nfat*=i happiness+=nfat/2 nfat=1 chocCount=0 print(int(happiness)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var cake : Sequence := Sequence{} ; var happiness : int := 0 ; var chocCount : int := 0 ; var nfat : int := 1 ; for i : Integer.subrange(0, n-1) do ( var line : String := ("" + (((OclFile["System.in"]).readLine()))) ; execute ((line) : cake) ; for j : line->characters() do ( if (j = 'C') then ( chocCount := chocCount + 1 ) else skip) ; if (chocCount > 1) then ( for i : Integer.subrange(chocCount - 2 + 1, chocCount)->reverse() do ( nfat := nfat * i) ; happiness := happiness + nfat / 2 ) else skip ; nfat := 1 ; chocCount := 0) ; var posCount : int := 0 ; for j : Integer.subrange(0, n-1) do ( for i : Integer.subrange(0, n-1) do ( if (cake[i+1][j+1] = 'C') then ( chocCount := chocCount + 1 ) else skip) ; if (chocCount > 1) then ( for i : Integer.subrange(chocCount - 2 + 1, chocCount)->reverse() do ( nfat := nfat * i) ; happiness := happiness + nfat / 2 ) else skip ; nfat := 1 ; chocCount := 0) ; execute (("" + ((happiness)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def main(): n=int(input()); linhas=[0 for i in range(n)]; colunas=[0 for i in range(n)]; pares=0 ; for i in range(n): entrada=input(); for j in range(n): if(entrada[j]=='C'): linhas[i]+=1 ; colunas[j]+=1 ; for i in range(n): pares+=(linhas[i]*(linhas[i]-1))/2 ; pares+=(colunas[i]*(colunas[i]-1))/2 ; print(int(pares)); main(); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; main();; operation main() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger(); ; var linhas : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)); ; var colunas : Sequence := Integer.subrange(0, n-1)->select(i | true)->collect(i | (0)); ; var pares : int := 0; ; for i : Integer.subrange(0, n-1) do ( var entrada : String := (OclFile["System.in"]).readLine(); ; for j : Integer.subrange(0, n-1) do ( if (entrada[j+1] = 'C') then ( linhas[i+1] := linhas[i+1] + 1; ; colunas[j+1] := colunas[j+1] + 1; ) else skip)) ; for i : Integer.subrange(0, n-1) do ( pares := pares + (linhas[i+1] * (linhas[i+1] - 1)) / 2; ; pares := pares + (colunas[i+1] * (colunas[i+1] - 1)) / 2;) ; execute (("" + ((pares)))->toInteger())->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- if __name__=='__main__' : n=int(input()) m=[] felicidade=0 for i in range(n): m.append(input()) for i in range(n): auxLinha=m[i].count('C') felicidade+=auxLinha*(auxLinha-1)//2 for i in range(n): auxColuna=0 for j in range(n): if m[j][i]=='C' : auxColuna+=1 felicidade+=auxColuna*(auxColuna-1)//2 print(felicidade) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: if __name__ = '__main__' then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var m : Sequence := Sequence{} ; var felicidade : int := 0 ; for i : Integer.subrange(0, n-1) do ( execute (((OclFile["System.in"]).readLine()) : m)) ; for i : Integer.subrange(0, n-1) do ( var auxLinha : OclAny := m[i+1]->count('C') ; felicidade := felicidade + auxLinha * (auxLinha - 1) div 2) ; for i : Integer.subrange(0, n-1) do ( var auxColuna : int := 0 ; for j : Integer.subrange(0, n-1) do ( if m[j+1][i+1] = 'C' then ( auxColuna := auxColuna + 1 ) else skip) ; felicidade := felicidade + auxColuna * (auxColuna - 1) div 2) ; execute (felicidade)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) c=[0]*n t=0 for j in range(n): x=0 a=input() for k in range(n): if a[k]=="C" : x+=1 c[k]+=1 t+=(x-1)/2*x for i in range(n): t+=(c[i]-1)/2*c[i] print(int(t)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var c : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; var t : int := 0 ; for j : Integer.subrange(0, n-1) do ( var x : int := 0 ; var a : String := (OclFile["System.in"]).readLine() ; for k : Integer.subrange(0, n-1) do ( if a[k+1] = "C" then ( x := x + 1 ; c[k+1] := c[k+1] + 1 ) else skip) ; t := t + (x - 1) / 2 * x) ; for i : Integer.subrange(0, n-1) do ( t := t + (c[i+1] - 1) / 2 * c[i+1]) ; execute (("" + ((t)))->toInteger())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findMinIndex(arr,low,high): if(highlow and arr[mid]arr[mid]): return findMinIndex(arr,low,mid-1) return findMinIndex(arr,mid+1,high) def binary_search(arr,l,h,x): while(l<=h): mid=(l+h)//2 if(arr[mid]<=x): l=mid+1 else : h=mid-1 return h def countEleLessThanOrEqual(arr,n,x): min_index=findMinIndex(arr,0,n-1) if(x<=arr[n-1]): return(binary_search(arr,min_index,n-1,x)+1-min_index) if((min_index-1)>=0 and x<=arr[min_index-1]): return(n-min_index+binary_search(arr,0,min_index-1,x)+1) return n arr=[6,10,12,15,2,4,5] n=len(arr) x=14 print("Count=",end="") print(countEleLessThanOrEqual(arr,n,x)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; arr := Sequence{6}->union(Sequence{10}->union(Sequence{12}->union(Sequence{15}->union(Sequence{2}->union(Sequence{4}->union(Sequence{ 5 })))))) ; n := (arr)->size() ; x := 14 ; execute ("Count=")->display() ; execute (countEleLessThanOrEqual(arr, n, x))->display(); operation findMinIndex(arr : OclAny, low : OclAny, high : OclAny) : OclAny pre: true post: true activity: if ((high->compareTo(low)) < 0) then ( return 0 ) else skip ; if (high = low) then ( return low ) else skip ; var mid : int := (low + high) div 2 ; if ((mid->compareTo(high)) < 0 & (arr[mid + 1+1]->compareTo(arr[mid+1])) < 0) then ( return (mid + 1) ) else skip ; if ((mid->compareTo(low)) > 0 & (arr[mid+1]->compareTo(arr[mid - 1+1])) < 0) then ( return mid ) else skip ; if ((arr[high+1]->compareTo(arr[mid+1])) > 0) then ( return findMinIndex(arr, low, mid - 1) ) else skip ; return findMinIndex(arr, mid + 1, high); operation binary_search(arr : OclAny, l : OclAny, h : OclAny, x : OclAny) : OclAny pre: true post: true activity: while ((l->compareTo(h)) <= 0) do ( mid := (l + h) div 2 ; if ((arr[mid+1]->compareTo(x)) <= 0) then ( l := mid + 1 ) else ( h := mid - 1 )) ; return h; operation countEleLessThanOrEqual(arr : OclAny, n : OclAny, x : OclAny) : OclAny pre: true post: true activity: var min_index : OclAny := findMinIndex(arr, 0, n - 1) ; if ((x->compareTo(arr[n - 1+1])) <= 0) then ( return (binary_search(arr, min_index, n - 1, x) + 1 - min_index) ) else skip ; if ((min_index - 1) >= 0 & (x->compareTo(arr[min_index - 1+1])) <= 0) then ( return (n - min_index + binary_search(arr, 0, min_index - 1, x) + 1) ) else skip ; return n; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import sqrt MAX=100000 prime=[True]*(MAX+1) def SieveOfEratosthenes(): for p in range(2,int(sqrt(MAX))+1): if(prime[p]==True): for i in range(p*p,MAX+1,p): prime[i]=False ; def smallestPrime(d): l=10**(d-1); r=(10**d)-1 ; for i in range(l,r+1): if(prime[i]): return i ; return-1 ; def largestPrime(d): l=10**(d-1); r=(10**d)-1 ; for i in range(r,l,-1): if(prime[i]): return i ; return-1 ; if __name__=="__main__" : SieveOfEratosthenes(); queries=[2,5]; q=len(queries); for i in range(q): print(smallestPrime(queries[i])," ",largestPrime(queries[i])); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var MAX : int := 100000 ; var prime : Sequence := MatrixLib.elementwiseMult(Sequence{ true }, (MAX + 1)) ; skip ; skip ; skip ; if __name__ = "__main__" then ( SieveOfEratosthenes(); ; var queries : Sequence := Sequence{2}->union(Sequence{ 5 }); ; var q : int := (queries)->size(); ; for i : Integer.subrange(0, q-1) do ( execute (smallestPrime(queries[i+1]))->display();) ) else skip; operation SieveOfEratosthenes() pre: true post: true activity: for p : Integer.subrange(2, ("" + ((sqrt(MAX))))->toInteger() + 1-1) do ( if (prime[p+1] = true) then ( for i : Integer.subrange(p * p, MAX + 1-1)->select( $x | ($x - p * p) mod p = 0 ) do ( prime[i+1] := false;) ) else skip); operation smallestPrime(d : OclAny) pre: true post: true activity: var l : double := (10)->pow((d - 1)); ; var r : double := ((10)->pow(d)) - 1; ; for i : Integer.subrange(l, r + 1-1) do ( if (prime[i+1]) then ( return i; ) else skip) ; return -1;; operation largestPrime(d : OclAny) pre: true post: true activity: l := (10)->pow((d - 1)); ; r := ((10)->pow(d)) - 1; ; for i : Integer.subrange(l + 1, r)->reverse() do ( if (prime[i+1]) then ( return i; ) else skip) ; return -1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def f(x,y): v=y-2*x*x+1 ; return v ; def predict(x,y,h): y1p=y+h*f(x,y); return y1p ; def correct(x,y,x1,y1,h): e=0.00001 ; y1c=y1 ; while(abs(y1c-y1)>e+1): y1=y1c ; y1c=y+0.5*h*(f(x,y)+f(x1,y1)); return y1c ; def printFinalValues(x,xn,y,h): while(xabs()->compareTo(e + 1)) > 0) do ( y1 := y1c; ; y1c := y + 0.5 * h * (f(x, y) + f(x1, y1));) ; return y1c;; operation printFinalValues(x : OclAny, xn : OclAny, y : OclAny, h : OclAny) pre: true post: true activity: while ((x->compareTo(xn)) < 0) do ( x1 := x + h; ; y1p := predict(x, y, h); ; y1c := correct(x, y, x1, y1p, h); ; x := x1; ; y := y1c;) ; execute ("The final value of y at x=")->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def D_Pattern(string,n): for i in range(0,n): for j in range(0,n): if(j==1 or((i==0 or i==n-1)and(j>1 and jdisplay();; operation D_Pattern(string : OclAny, n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, n-1) do ( for j : Integer.subrange(0, n-1) do ( if (j = 1 or ((i = 0 or i = n - 1) & (j > 1 & (j->compareTo(n - 2)) < 0)) or (j = n - 2 & i /= 0 & i /= n - 1)) then ( string := string + "*" ) else ( string := string + "" )) ; string := string + "\n") ; return (string);; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def kthString(n,k): total=0 i=1 while(total1): print("x",end="") second_y_position-=1 j+=1 print("y",end="") while(jcompareTo(k)) < 0) do ( total := total + n - i ; i := i + 1) ; var first_y_position : double := i - 1 ; var second_y_position : double := k - (total - n + first_y_position) ; for j : Integer.subrange(1, first_y_position-1)->select( $x | ($x - 1) mod 1 = 0 ) do ( execute ("x")->display()) ; execute ("y")->display() ; var j : OclAny := first_y_position + 1 ; while (second_y_position > 1) do ( execute ("x")->display() ; second_y_position := second_y_position - 1 ; j := j + 1) ; execute ("y")->display() ; while ((j->compareTo(n)) < 0) do ( execute ("x")->display() ; j := j + 1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def binomialCoeff(n,k): C=[0]*(k+1); C[0]=1 ; for i in range(1,n+1): for j in range(min(i,k),0,-1): C[j]=C[j]+C[j-1]; return C[k]; def count_of_subarrays(N): count=binomialCoeff(2*N-1,N); return count ; if __name__=="__main__" : N=3 ; print(count_of_subarrays(N)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( N := 3; ; execute (count_of_subarrays(N))->display(); ) else skip; operation binomialCoeff(n : OclAny, k : OclAny) pre: true post: true activity: var C : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (k + 1)); ; C->first() := 1; ; for i : Integer.subrange(1, n + 1-1) do ( for j : Integer.subrange(0 + 1, Set{i, k}->min())->reverse() do ( C[j+1] := C[j+1] + C[j - 1+1];)) ; return C[k+1];; operation count_of_subarrays(N : OclAny) pre: true post: true activity: var count : OclAny := binomialCoeff(2 * N - 1, N); ; return count;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def productExceptSelf(self,nums): ans=[1]*len(nums) for i in range(1,len(nums)): ans[i]=ans[i-1]*nums[i-1] right=1 for i in range(len(nums)-1,-1,-1): ans[i]*=right right*=nums[i] return ans ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation productExceptSelf(nums : OclAny) : OclAny pre: true post: true activity: var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 1 }, (nums)->size()) ; for i : Integer.subrange(1, (nums)->size()-1) do ( ans[i+1] := ans[i - 1+1] * nums[i - 1+1]) ; var right : int := 1 ; for i : Integer.subrange(-1 + 1, (nums)->size() - 1)->reverse() do ( ans[i+1] := ans[i+1] * right ; right := right * nums[i+1]) ; return ans; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() d={'>' : "1000",'<' : '1001','+' : '1010','-' : '1011','.' : '1100',',' : "1101","[" : "1110",']' : "1111"} ans="" for i in s : ans+=d[i] ans=ans[: :-1] ret=0 temp=1 mod=int(1e6+3) for i in ans : ret+=int(i)*temp ret %=mod temp<<=1 temp %=mod print(ret) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var d : Map := Map{ '>' |-> "1000" }->union(Map{ '<' |-> '1001' }->union(Map{ '+' |-> '1010' }->union(Map{ '-' |-> '1011' }->union(Map{ '.' |-> '1100' }->union(Map{ ',' |-> "1101" }->union(Map{ "[" |-> "1110" }->union(Map{ ']' |-> "1111" }))))))) ; var ans : String := "" ; for i : s->characters() do ( ans := ans + d[i+1]) ; ans := ans(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ; var ret : int := 0 ; var temp : int := 1 ; var mod : int := ("" + ((("1e6")->toReal() + 3)))->toInteger() ; for i : ans->characters() do ( ret := ret + ("" + ((i)))->toInteger() * temp ; ret := ret mod mod ; temp := temp * (2->pow(1)) ; temp := temp mod mod) ; execute (ret)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getSmallestAndLargest(s,k): currStr=s[: k] lexMin=currStr lexMax=currStr for i in range(k,len(s)): currStr=currStr[1 : k]+s[i] if(lexMaxcurrStr): lexMin=currStr print(lexMin) print(lexMax) if __name__=='__main__' : str1="GeeksForGeeks" k=3 getSmallestAndLargest(str1,k) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( var str1 : String := "GeeksForGeeks" ; k := 3 ; getSmallestAndLargest(str1, k) ) else skip; operation getSmallestAndLargest(s : OclAny, k : OclAny) pre: true post: true activity: var currStr : OclAny := s.subrange(1,k) ; var lexMin : OclAny := currStr ; var lexMax : OclAny := currStr ; for i : Integer.subrange(k, (s)->size()-1) do ( currStr := currStr.subrange(1+1, k) + s[i+1] ; if ((lexMax->compareTo(currStr)) < 0) then ( lexMax := currStr ) else skip ; if ((lexMin->compareTo(currStr)) > 0) then ( lexMin := currStr ) else skip) ; execute (lexMin)->display() ; execute (lexMax)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) d=[0]*m class struct : def __init__(self,value,idx): self.value=value self.idx=idx for i in range(m): b[i]=struct(b[i],i) a.sort(reverse=True) b.sort(key=lambda x : x.value) for i in range(m): d[b[i].idx]=a[i] for i in range(m): print(d[i],'',end='') ------------------------------------------------------------ OCL File: --------- class struct { static operation newstruct() : struct pre: true post: struct->exists( _x | result = _x ); attribute value : OclAny := value; attribute idx : OclAny := idx; operation initialise(value : OclAny,idx : OclAny) : struct pre: true post: true activity: self.value := value ; self.idx := idx; return self; } class FromPython { operation initialise() pre: true post: true activity: var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; skip ; for i : Integer.subrange(0, m-1) do ( b[i+1] := (struct.newstruct()).initialise(b[i+1], i)) ; a := a->sort() ; b := b->sort() ; for i : Integer.subrange(0, m-1) do ( d[b[i+1].idx+1] := a[i+1]) ; for i : Integer.subrange(0, m-1) do ( execute (d[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=int(input()) la=sorted(list(map(int,input().split())),reverse=True) lb=list(map(int,input().split())) answer=[0 for i in range(m)] lb=[(lb[i],i)for i in range(m)] lb.sort() for i in range(m): answer[lb[i][1]]=la[i] for ans in answer : print(ans,end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var la : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sortedBy($x | (argument (test (logical_test (comparison (expr (atom (name reverse)))))) = (test (logical_test (comparison (expr (atom (name True)))))))) ; var lb : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var answer : Sequence := Integer.subrange(0, m-1)->select(i | true)->collect(i | (0)) ; lb := Integer.subrange(0, m-1)->select(i | true)->collect(i | (Sequence{lb[i+1], i})) ; lb := lb->sort() ; for i : Integer.subrange(0, m-1) do ( answer[lb[i+1][1+1]+1] := la[i+1]) ; for ans : answer do ( execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a=list(map(int,input().split())) tmp=list(map(int,input().split())) b=[] for i in range(n): b.append([tmp[i],i]) a.sort(reverse=True) b.sort() tmp=[] for i in range(n): tmp.append([a[i],b[i][1]]) ans=[-1]*n for i in range(n): ans[tmp[i][1]]=tmp[i][0] print(*ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var tmp : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((Sequence{tmp[i+1]}->union(Sequence{ i })) : b)) ; a := a->sort() ; b := b->sort() ; tmp := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((Sequence{a[i+1]}->union(Sequence{ b[i+1][1+1] })) : tmp)) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, n) ; for i : Integer.subrange(0, n-1) do ( ans[tmp[i+1][1+1]+1] := tmp[i+1]->first()) ; execute ((argument * (test (logical_test (comparison (expr (atom (name ans))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INF=10**20 n,m=map(int,input().split()) dist=[] weth=[] for _ in range(n): dist.append(int(input())) for _ in range(m): weth.append(int(input())) dp=[INF]*(n+1) dp[0]=0 for i in range(m): for j in range(n,0,-1): dp[j]=min(dp[j],dp[j-1]+dist[j-1]*weth[i]) print(dp[n]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var INF : double := (10)->pow(20) ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var dist : Sequence := Sequence{} ; var weth : Sequence := Sequence{} ; for _anon : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : dist)) ; for _anon : Integer.subrange(0, m-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : weth)) ; var dp : Sequence := MatrixLib.elementwiseMult(Sequence{ INF }, (n + 1)) ; dp->first() := 0 ; for i : Integer.subrange(0, m-1) do ( for j : Integer.subrange(0 + 1, n)->reverse() do ( dp[j+1] := Set{dp[j+1], dp[j - 1+1] + dist[j - 1+1] * weth[i+1]}->min())) ; execute (dp[n+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) a,b=list(map(int,input().split())),list(map(int,input().split())) c=[] a.sort(reverse=True) for i in range(n): c.append([b[i],i]) c=sorted(c,key=lambda x :(x[0],-x[1])) d=[0]*n for i in range(n): d[c[i][1]]=a[i] print(*d) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{((input().split())->collect( _x | (OclType["int"])->apply(_x) )),((input().split())->collect( _x | (OclType["int"])->apply(_x) ))} ; var c : Sequence := Sequence{} ; a := a->sort() ; for i : Integer.subrange(0, n-1) do ( execute ((Sequence{b[i+1]}->union(Sequence{ i })) : c)) ; c := c->sortedBy($x | (lambda x : OclAny in (Sequence{x->first(), -x[1+1]}))->apply($x)) ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; for i : Integer.subrange(0, n-1) do ( d[c[i+1][1+1]+1] := a[i+1]) ; execute ((argument * (test (logical_test (comparison (expr (atom (name d))))))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- m=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) d=[0]*m class struct : def __init__(self,value,idx): self.value=value self.idx=idx for i in range(m): b[i]=struct(b[i],i) a.sort(reverse=True) b.sort(key=lambda x : x.value) for i in range(m): d[b[i].idx]=a[i] for i in range(m): print(d[i],'',end='') ------------------------------------------------------------ OCL File: --------- class struct { static operation newstruct() : struct pre: true post: struct->exists( _x | result = _x ); attribute value : OclAny := value; attribute idx : OclAny := idx; operation initialise(value : OclAny,idx : OclAny) : struct pre: true post: true activity: self.value := value ; self.idx := idx; return self; } class FromPython { operation initialise() pre: true post: true activity: var m : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var b : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var d : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m) ; skip ; for i : Integer.subrange(0, m-1) do ( b[i+1] := (struct.newstruct()).initialise(b[i+1], i)) ; a := a->sort() ; b := b->sort() ; for i : Integer.subrange(0, m-1) do ( d[b[i+1].idx+1] := a[i+1]) ; for i : Integer.subrange(0, m-1) do ( execute (d[i+1])->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- INT_BITS=32 def maxSubarrayXOR(set,n): index=0 for i in range(INT_BITS-1,-1,-1): maxInd=index maxEle=-2147483648 for j in range(index,n): if((set[j]&(1<maxEle): maxEle=set[j] maxInd=j if(maxEle==-2147483648): continue temp=set[index] set[index]=set[maxInd] set[maxInd]=temp maxInd=index for j in range(n): if(j!=maxInd and(set[j]&(1<union(Sequence{8}->union(Sequence{ 5 })) ; n := (OclType["Set"])->size() ; execute ("Max subset XOR is ")->display() ; execute (maxSubarrayXOR(OclType["Set"], n))->display(); operation maxSubarrayXOR(set : OclAny, n : OclAny) : OclAny pre: true post: true activity: var index : int := 0 ; for i : Integer.subrange(-1 + 1, INT_BITS - 1)->reverse() do ( var maxInd : int := index ; var maxEle : int := -2147483648 ; for j : Integer.subrange(index, n-1) do ( if ((MathLib.bitwiseAnd(Set{}->union([j+1]), (1 * (2->pow(i))))) /= 0 & (Set{}->union([j+1])->compareTo(maxEle)) > 0) then ( maxEle := Set{}->union([j+1]) ; maxInd := j ) else skip) ; if (maxEle = -2147483648) then ( continue ) else skip ; var temp : Set := Set{}->union([index+1]) ; Set{}->union([index+1]) := Set{}->union([maxInd+1]) ; Set{}->union([maxInd+1]) := temp ; maxInd := index ; for j : Integer.subrange(0, n-1) do ( if (j /= maxInd & (MathLib.bitwiseAnd(Set{}->union([j+1]), (1 * (2->pow(i))))) /= 0) then ( Set{}->union([j+1]) := MathLib.bitwiseXor(Set{}->union([j+1]), Set{}->union([maxInd+1])) ) else skip) ; index := index + 1) ; var res : int := 0 ; for i : Integer.subrange(0, n-1) do ( res := MathLib.bitwiseXor(res, Set{}->union([i+1]))) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- input() b=input().split() print(max(map(b.count,b)),len(set(b))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: input() ; var b : OclAny := input().split() ; execute (((b)->collect( _x | (b.count)->apply(_x) ))->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import Counter input() d=Counter(input().split()) print(max(d.values()),len(d.keys())) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; input() ; var d : OclAny := Counter(input().split()) ; execute ((d.values())->max())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) l=list(map(int,input().split())) high=1 tower=n maximum=1 l.sort() for i in range(1,n): if l[i]==l[i-1]: tower-=1 high+=1 else : if high>maximum : maximum=high high=1 if high>maximum : maximum=high print(maximum,tower) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var high : int := 1 ; var tower : int := n ; var maximum : int := 1 ; l := l->sort() ; for i : Integer.subrange(1, n-1) do ( if l[i+1] = l[i - 1+1] then ( tower := tower - 1 ; high := high + 1 ) else ( if (high->compareTo(maximum)) > 0 then ( maximum := high ) else skip ; high := 1 )) ; if (high->compareTo(maximum)) > 0 then ( maximum := high ) else skip ; execute (maximum)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=input() s="" d={">" : "1000","<" : "1001","+" : "1010","-" : "1011","." : "1100","," : "1101","[" : "1110","]" : "1111"} for i in n : s+=d[i] print(int(s,2)%((10**6)+3)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : String := (OclFile["System.in"]).readLine() ; var s : String := "" ; var d : Map := Map{ ">" |-> "1000" }->union(Map{ "<" |-> "1001" }->union(Map{ "+" |-> "1010" }->union(Map{ "-" |-> "1011" }->union(Map{ "." |-> "1100" }->union(Map{ "," |-> "1101" }->union(Map{ "[" |-> "1110" }->union(Map{ "]" |-> "1111" }))))))) ; for i : n->characters() do ( s := s + d[i+1]) ; execute (("" + ((s, 2)))->toInteger() mod (((10)->pow(6)) + 3))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) input_list=list(map(int,input().split())) max_count=0 max_times=0 for i in range(0,N): count=0 for j in range(0,N): if(input_list[i]==input_list[j]): count+=1 if(count>max_count): max_count=count max_times=input_list[i] res=[*set(input_list)] length=len(res) print(max_count,length) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var input_list : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var max_count : int := 0 ; var max_times : int := 0 ; for i : Integer.subrange(0, N-1) do ( var count : int := 0 ; for j : Integer.subrange(0, N-1) do ( if (input_list[i+1] = input_list[j+1]) then ( count := count + 1 ) else skip) ; if ((count->compareTo(max_count)) > 0) then ( max_count := count ; max_times := input_list[i+1] ) else skip) ; var res : Sequence := Set{}->union((input_list)) ; var length : int := (res)->size() ; execute (max_count)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- u=input() o1=1 o2=0 s=1 bl=sorted(list(map(int,input().split()))) bs=sorted(list(set(bl))) for i in bs : exec(f's{i}=1') for i in bl : try : if i==bs[0]: bs.pop(0) o2+=1 else : exec(f's{i}+=1') except : exec(f's{i}+=1') o1=max([o1,eval(f's{i}')]) print(str(o1)+' '+str(o2)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var u : String := (OclFile["System.in"]).readLine() ; var o1 : int := 1 ; var o2 : int := 0 ; var s : int := 1 ; var bl : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ))->sort() ; var bs : Sequence := (Set{}->union((bl)))->sort() ; for i : bs do () ; for i : bl do ( try ( if i = bs->first() then ( bs := bs->excludingAt(0+1) ; o2 := o2 + 1 ) else ( )) catch (_e : OclException) do () ; o1 := (Sequence{o1}->union(Sequence{ StringLib.formattedString('s{i}') }))->max()) ; execute (("" + ((o1))) + ' ' + ("" + ((o2))))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def partition(arr,si,ei): x=arr[ei] i=(si-1) for j in range(si,ei): if(arr[j]<=x): i+=1 arr[i],arr[j]=arr[j],arr[i] arr[i+1],arr[ei]=arr[ei],arr[i+1] return(i+1) def quickSort(arr,si,ei): pi=0 if(siunion(Sequence{60}->union(Sequence{-10}->union(Sequence{70}->union(Sequence{-80}->union(Sequence{ 85 }))))) ; n := (arr)->size() ; minAbsSumPair(arr, n); operation partition(arr : OclAny, si : OclAny, ei : OclAny) : OclAny pre: true post: true activity: var x : OclAny := arr[ei+1] ; var i : double := (si - 1) ; for j : Integer.subrange(si, ei-1) do ( if ((arr[j+1]->compareTo(x)) <= 0) then ( i := i + 1 ; var arr[i+1] : OclAny := null; var arr[j+1] : OclAny := null; Sequence{arr[i+1],arr[j+1]} := Sequence{arr[j+1],arr[i+1]} ) else skip) ; var arr[i + 1+1] : OclAny := null; var arr[ei+1] : OclAny := null; Sequence{arr[i + 1+1],arr[ei+1]} := Sequence{arr[ei+1],arr[i + 1+1]} ; return (i + 1); operation quickSort(arr : OclAny, si : OclAny, ei : OclAny) pre: true post: true activity: var pi : int := 0 ; if ((si->compareTo(ei)) < 0) then ( pi := partition(arr, si, ei) ; quickSort(arr, si, pi - 1) ; quickSort(arr, pi + 1, ei) ) else skip; operation minAbsSumPair(arr : OclAny, n : OclAny) pre: true post: true activity: var sum : OclAny := null; var min_sum : OclAny := null; Sequence{sum,min_sum} := Sequence{0,(10)->pow(9)} ; var l : int := 0 ; var r : double := n - 1 ; var min_l : int := l ; var min_r : double := n - 1 ; if (n < 2) then ( execute ("Invalid Input")->display() ; return ) else skip ; quickSort(arr, l, r) ; while ((l->compareTo(r)) < 0) do ( var sum : OclAny := arr[l+1] + arr[r+1] ; if (((sum)->abs()->compareTo((min_sum)->abs())) < 0) then ( var min_sum : OclAny := sum ; min_l := l ; min_r := r ) else skip ; if (sum < 0) then ( l := l + 1 ) else ( r := r - 1 )) ; execute ("The two elements whose sum is minimum are")->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**8) def ii(): return int(sys.stdin.readline()) def mi(): return map(int,sys.stdin.readline().split()) def li(): return list(map(int,sys.stdin.readline().split())) def li2(N): return[list(map(int,sys.stdin.readline().split()))for _ in range(N)] def dp2(ini,i,j): return[[ini]*i for _ in range(j)] def dp3(ini,i,j,k): return[[[ini]*i for _ in range(j)]for _ in range(k)] N,M=mi() C=[ii()for _ in range(N)] W=[ii()for _ in range(M)] dp=dp2(float('inf'),N+1,M+1) dp[0][0]=0 for i in range(M): for j in range(N+1): if j+1<=N : dp[i+1][j+1]=min(dp[i][j]+W[i]*C[j],dp[i+1][j+1]) dp[i+1][j]=min(dp[i][j],dp[i+1][j]) print(dp[M][N]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(8)) ; skip ; skip ; skip ; skip ; skip ; skip ; var M : OclAny := null; Sequence{N,M} := mi() ; var C : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (ii())) ; var W : Sequence := Integer.subrange(0, M-1)->select(_anon | true)->collect(_anon | (ii())) ; var dp : OclAny := dp2(("" + (('inf')))->toReal(), N + 1, M + 1) ; dp->first()->first() := 0 ; for i : Integer.subrange(0, M-1) do ( for j : Integer.subrange(0, N + 1-1) do ( if (j + 1->compareTo(N)) <= 0 then ( dp[i + 1+1][j + 1+1] := Set{dp[i+1][j+1] + W[i+1] * C[j+1], dp[i + 1+1][j + 1+1]}->min() ) else skip ; dp[i + 1+1][j+1] := Set{dp[i+1][j+1], dp[i + 1+1][j+1]}->min())) ; execute (dp[M+1][N+1])->display(); operation ii() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation mi() : OclAny pre: true post: true activity: return (sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) ); operation li() : OclAny pre: true post: true activity: return ((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )); operation li2(N : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (((sys.stdin.readLine().split())->collect( _x | (OclType["int"])->apply(_x) )))); operation dp2(ini : OclAny, i : OclAny, j : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, j-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ ini }, i))); operation dp3(ini : OclAny, i : OclAny, j : OclAny, k : OclAny) : OclAny pre: true post: true activity: return Integer.subrange(0, k-1)->select(_anon | true)->collect(_anon | (Integer.subrange(0, j-1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ ini }, i))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Solution(object): def firstUniqChar(self,s): count_map={} for c in s : count_map[c]=count_map.get(c,0)+1 for i,c in enumerate(s): if count_map[c]==1 : return i return-1 ------------------------------------------------------------ OCL File: --------- class Solution extends object { static operation newSolution() : Solution pre: true post: Solution->exists( _x | result = _x ); operation firstUniqChar(s : OclAny) : OclAny pre: true post: true activity: var count_map : OclAny := Set{} ; for c : s do ( count_map[c+1] := count_map.get(c, 0) + 1) ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); if count_map[c+1] = 1 then ( return i ) else skip) ; return -1; } class FromPython { operation initialise() pre: true post: true activity: skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from queue import Queue def checkStackPermutation(ip,op,n): Input=Queue() for i in range(n): Input.put(ip[i]) output=Queue() for i in range(n): output.put(op[i]) tempStack=[] while(not Input.empty()): ele=Input.queue[0] Input.get() if(ele==output.queue[0]): output.get() while(len(tempStack)!=0): if(tempStack[-1]==output.queue[0]): tempStack.pop() output.get() else : break else : tempStack.append(ele) return(Input.empty()and len(tempStack)==0) if __name__=='__main__' : Input=[1,2,3] output=[2,1,3] n=3 if(checkStackPermutation(Input,output,n)): print("Yes") else : print("Not Possible") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = '__main__' then ( Input := Sequence{1}->union(Sequence{2}->union(Sequence{ 3 })) ; output := Sequence{2}->union(Sequence{1}->union(Sequence{ 3 })) ; n := 3 ; if (checkStackPermutation(Input, output, n)) then ( execute ("Yes")->display() ) else ( execute ("Not Possible")->display() ) ) else skip; operation checkStackPermutation(ip : OclAny, op : OclAny, n : OclAny) : OclAny pre: true post: true activity: var Input : OclAny := Queue() ; for i : Integer.subrange(0, n-1) do ( Input.put(ip[i+1])) ; var output : OclAny := Queue() ; for i : Integer.subrange(0, n-1) do ( output.put(op[i+1])) ; var tempStack : Sequence := Sequence{} ; while (not(Input.empty())) do ( var ele : OclAny := Input.queue->first() ; Input.get() ; if (ele = output.queue->first()) then ( output.get() ; while ((tempStack)->size() /= 0) do ( if (tempStack->last() = output.queue->first()) then ( tempStack := tempStack->front() ; output.get() ) else ( break )) ) else ( execute ((ele) : tempStack) )) ; return (Input.empty() & (tempStack)->size() = 0); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict s=defaultdict(list) t=defaultdict(list) S=list(input()) T=list(input()) for i in range(len(S)): if T[i]not in s[S[i]]: s[S[i]].append(T[i]) if len(s[S[i]])>=2 : print("No") break if S[i]not in t[T[i]]: t[T[i]].append(S[i]) if len(t[T[i]])>=2 : print("No") break if i==len(S)-1 : print("Yes") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var s : OclAny := defaultdict(OclType["Sequence"]) ; var t : OclAny := defaultdict(OclType["Sequence"]) ; var S : Sequence := ((OclFile["System.in"]).readLine())->characters() ; var T : Sequence := ((OclFile["System.in"]).readLine())->characters() ; for i : Integer.subrange(0, (S)->size()-1) do ( if (s[S[i+1]+1])->excludes(T[i+1]) then ( (expr (atom (name s)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name T)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))) ; if (s[S[i+1]+1])->size() >= 2 then ( execute ("No")->display() ; break ) else skip ) else skip ; if (t[T[i+1]+1])->excludes(S[i+1]) then ( (expr (atom (name t)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name T)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name S)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name i)))))))) ])))))))) )))) ; if (t[T[i+1]+1])->size() >= 2 then ( execute ("No")->display() ; break ) else skip ) else skip ; if i = (S)->size() - 1 then ( execute ("Yes")->display() ) else skip); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- S=input() T=input() k={} o={} res="Yes" for i in range(len(S)): if S[i]in k : if k[S[i]]!=T[i]: res="No" break else : k[S[i]]=T[i] for i in range(len(T)): if T[i]in o : if o[T[i]]!=S[i]: res="No" break else : o[T[i]]=S[i] print(res) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var S : String := (OclFile["System.in"]).readLine() ; var T : String := (OclFile["System.in"]).readLine() ; var k : OclAny := Set{} ; var o : OclAny := Set{} ; var res : String := "Yes" ; for i : Integer.subrange(0, (S)->size()-1) do ( if (k)->includes(S[i+1]) then ( if k[S[i+1]+1] /= T[i+1] then ( res := "No" ; break ) else skip ) else ( k[S[i+1]+1] := T[i+1] )) ; for i : Integer.subrange(0, (T)->size()-1) do ( if (o)->includes(T[i+1]) then ( if o[T[i+1]+1] /= S[i+1] then ( res := "No" ; break ) else skip ) else ( o[T[i+1]+1] := S[i+1] )) ; execute (res)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys use_clipboard=True bbn=1000000007 def check(sc,tc): sc.sort() tc.sort() for u,v in zip(sc,tc): if len(u)!=len(v): return False for i,j in zip(u,v): if i!=j : return False return True def main(): s=input() t=input() c2i=lambda c : ord(c)-ord('a') sc=[[]for _ in range(26)] tc=[[]for _ in range(26)] for i,c in enumerate(s): sc[c2i(c)].append(i) for i,c in enumerate(t): tc[c2i(c)].append(i) ret='Yes' if check(sc,tc)else 'No' print(ret) isTest=False def pa(v): if isTest : print(v) class input_clipboard : def __init__(self,s): self.input_l=s.splitlines() self.ii=0 def input(self): ret=self.input_l[self.ii] self.ii+=1 return ret if __name__=="__main__" : if sys.platform=='ios' : if use_clipboard : import clipboard input_text=clipboard.get() ic=input_clipboard(input_text) input=lambda : ic.input() else : sys.stdin=open('inputFile.txt') isTest=True else : pass ret=main() if ret is not None : print(ret) ------------------------------------------------------------ OCL File: --------- class input_clipboard { static operation newinput_clipboard() : input_clipboard pre: true post: input_clipboard->exists( _x | result = _x ); attribute input_l : OclAny := s.splitlines(); attribute ii : int := 0; operation initialise(s : OclAny) : input_clipboard pre: true post: true activity: self.input_l := s.splitlines() ; self.ii := 0; return self; operation input() : OclAny pre: true post: true activity: ret := self.input_l[self.ii+1] ; self.ii := self.ii + 1 ; return ret; } class FromPython { operation initialise() pre: true post: true activity: skip ; var use_clipboard : boolean := true ; var bbn : int := 1000000007 ; skip ; skip ; var isTest : boolean := false ; skip ; skip ; if __name__ = "__main__" then ( if OclProcess.getEnvironmentProperty("OS") = 'ios' then ( if use_clipboard then ( skip ; var input_text : OclAny := clipboard.get() ; var ic : input_clipboard := (input_clipboard.newinput_clipboard()).initialise(input_text) ; var input : Function := lambda $$ : OclAny in (ic.input()) ) else ( OclFile["System.in"] := OclFile.newOclFile_Write(OclFile.newOclFile('inputFile.txt')) ) ; isTest := true ) else ( skip ) ; ret := main() ; if not(ret <>= null) then ( execute (ret)->display() ) else skip ) else skip; operation check(sc : OclAny, tc : OclAny) : OclAny pre: true post: true activity: sc := sc->sort() ; tc := tc->sort() ; for _tuple : Integer.subrange(1, sc->size())->collect( _indx | Sequence{sc->at(_indx), tc->at(_indx)} ) do (var _indx : int := 1; var u : OclAny := _tuple->at(_indx); _indx := _indx + 1; var v : OclAny := _tuple->at(_indx); if (u)->size() /= (v)->size() then ( return false ) else skip ; for _tuple : Integer.subrange(1, u->size())->collect( _indx | Sequence{u->at(_indx), v->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var j : OclAny := _tuple->at(_indx); if i /= j then ( return false ) else skip)) ; return true; operation main() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var c2i : Function := lambda c : OclAny in ((c)->char2byte() - ('a')->char2byte()) ; sc := Integer.subrange(0, 26-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; tc := Integer.subrange(0, 26-1)->select(_anon | true)->collect(_anon | (Sequence{})) ; for _tuple : Integer.subrange(1, (s)->size())->collect( _indx | Sequence{_indx-1, (s)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); (expr (atom (name sc)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name c2i)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; for _tuple : Integer.subrange(1, (t)->size())->collect( _indx | Sequence{_indx-1, (t)->at(_indx)} ) do (var _indx : int := 1; var i : OclAny := _tuple->at(_indx); _indx := _indx + 1; var c : OclAny := _tuple->at(_indx); (expr (atom (name tc)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name c2i)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name c)))))))) ))))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))) ; var ret : String := if check(sc, tc) then 'Yes' else 'No' endif ; execute (ret)->display(); operation pa(v : OclAny) pre: true post: true activity: if isTest then ( execute (v)->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s=input() t=input() sset=set() tset=set() j=1 alp={} ds=[0]*len(s) for i in range(len(s)): if not s[i]in sset : alp[s[i]]=j ds[i]=j sset.add(s[i]) j+=1 else : ds[i]=alp[s[i]] j=1 alp={} dt=[0]*len(t) for i in range(len(t)): if not t[i]in tset : alp[t[i]]=j dt[i]=j tset.add(t[i]) j+=1 else : dt[i]=alp[t[i]] for i in range(len(s)): if ds[i]!=dt[i]: print('No') exit() print('Yes') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var t : String := (OclFile["System.in"]).readLine() ; var sset : Set := Set{}->union(()) ; var tset : Set := Set{}->union(()) ; var j : int := 1 ; var alp : OclAny := Set{} ; var ds : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (s)->size()) ; for i : Integer.subrange(0, (s)->size()-1) do ( if not((sset)->includes(s[i+1])) then ( alp[s[i+1]+1] := j ; ds[i+1] := j ; execute ((s[i+1]) : sset) ; j := j + 1 ) else ( ds[i+1] := alp[s[i+1]+1] )) ; j := 1 ; alp := Set{} ; var dt : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (t)->size()) ; for i : Integer.subrange(0, (t)->size()-1) do ( if not((tset)->includes(t[i+1])) then ( alp[t[i+1]+1] := j ; dt[i+1] := j ; execute ((t[i+1]) : tset) ; j := j + 1 ) else ( dt[i+1] := alp[t[i+1]+1] )) ; for i : Integer.subrange(0, (s)->size()-1) do ( if ds[i+1] /= dt[i+1] then ( execute ('No')->display() ; exit() ) else skip) ; execute ('Yes')->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import collections def run(s,t): ss=sorted(list(collections.Counter(s).values())) tt=sorted(list(collections.Counter(t).values())) if ss==tt : return 'Yes' else : return 'No' def main(): s=input() t=input() print(run(s,t)) if __name__=='__main__' : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = '__main__' then ( main() ) else skip; operation run(s : OclAny, t : OclAny) : OclAny pre: true post: true activity: var ss : Sequence := (collections.Counter(s).values())->sort() ; var tt : Sequence := (collections.Counter(t).values())->sort() ; if ss = tt then ( return 'Yes' ) else ( return 'No' ); operation main() pre: true post: true activity: s := (OclFile["System.in"]).readLine() ; t := (OclFile["System.in"]).readLine() ; execute (run(s, t))->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- s,a,c=input(),1,0 for x in s : if x=='A' : a=0 elif x=='Z' and not a : a,c=1,c+1 print('AZ'*c if c else-1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var s : OclAny := null; var a : OclAny := null; var c : OclAny := null; Sequence{s,a,c} := Sequence{(OclFile["System.in"]).readLine(),1,0} ; for x : s do ( if x = 'A' then ( var a : int := 0 ) else (if x = 'Z' & not(a) then ( var c : OclAny := null; Sequence{a,c} := Sequence{1,c + 1} ) else skip)) ; execute (if c then StringLib.nCopies('AZ', c) else -1 endif)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- hashMap={">" : "1000","<" : "1001","+" : "1010","-" : "1011","." : "1100","," : "1101","[" : "1110","]" : "1111"} string=input() res='' for s in string : res+=hashMap[s] print(int(res,2)% 1000003) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var hashMap : Map := Map{ ">" |-> "1000" }->union(Map{ "<" |-> "1001" }->union(Map{ "+" |-> "1010" }->union(Map{ "-" |-> "1011" }->union(Map{ "." |-> "1100" }->union(Map{ "," |-> "1101" }->union(Map{ "[" |-> "1110" }->union(Map{ "]" |-> "1111" }))))))) ; var string : String := (OclFile["System.in"]).readLine() ; var res : String := '' ; for s : string->characters() do ( res := res + hashMap[s+1]) ; execute (("" + ((res, 2)))->toInteger() mod 1000003)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getSum(n,d): sum=0 ; for i in range(n+1): if(i % 10==d): sum+=i return sum if __name__=="__main__" : n,d=30,3 print(getSum(n,d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{n,d} := Sequence{30,3} ; execute (getSum(n, d))->display() ) else skip; operation getSum(n : OclAny, d : OclAny) : OclAny pre: true post: true activity: var sum : int := 0; ; for i : Integer.subrange(0, n + 1-1) do ( if (i mod 10 = d) then ( sum := sum + i ) else skip) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dp=[[1<<30 for _ in range(1001)]for _ in range(1001)] dp[0][0]=0 n,m=map(int,input().split()) d=[int(input())for _ in range(n)]+[0] c=[int(input())for _ in range(m)]+[0] for i in range(m): for j in range(n+1): if dp[i][j]select(_anon | true)->collect(_anon | (Integer.subrange(0, 1001-1)->select(_anon | true)->collect(_anon | (1 * (2->pow(30)))))) ; dp->first()->first() := 0 ; var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))->union(Sequence{ 0 }) ; var c : Sequence := Integer.subrange(0, m-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger()))->union(Sequence{ 0 }) ; for i : Integer.subrange(0, m-1) do ( for j : Integer.subrange(0, n + 1-1) do ( if (dp[i+1][j+1]->compareTo(dp[i + 1+1][j+1])) < 0 then ( dp[i + 1+1][j+1] := dp[i+1][j+1] ) else skip ; var e : double := d[j+1] * c[i+1] ; if (dp[i+1][j+1] + e->compareTo(dp[i + 1+1][j + 1+1])) < 0 then ( dp[i + 1+1][j + 1+1] := dp[i+1][j+1] + e; ) else skip)) ; dp := (Integer.subrange(1, (argument * (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ])))))))->size())->collect( _indx | Sequence{(argument * (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ])))))))->at(_indx), (argument * (test (logical_test (comparison (expr (atom (name dp)) (trailer (arguments [ (subscriptlist (subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1)))))))))) ])))))))`third->at(_indx)} )) ; execute ((dp[n+1])->min())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline t=int(input()) for testcases in range(t): a,b,c,r=map(int,input().split()) MINC=c-r MAXC=c+r if a==b : print(0) elif ab : print(min(b-a,max(0,MINC-a))) else : if a>=c>=b : print(max(0,MINC-b)+max(0,a-MAXC)) elif ca : print(min(a-b,max(0,MINC-b))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for testcases : Integer.subrange(0, t-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var r : OclAny := null; Sequence{a,b,c,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var MINC : double := c - r ; var MAXC : OclAny := c + r ; if a = b then ( execute (0)->display() ) else (if (a->compareTo(b)) < 0 then ( if (a->compareTo(c)) <= 0 & (c <= b) then ( execute (Set{0, MINC - a}->max() + Set{0, b - MAXC}->max())->display() ) else (if (c->compareTo(a)) < 0 then ( execute (Set{b - a, Set{0, b - MAXC}->max()}->min())->display() ) else (if (c->compareTo(b)) > 0 then ( execute (Set{b - a, Set{0, MINC - a}->max()}->min())->display() ) else skip ) ) ) else ( if (a->compareTo(c)) >= 0 & (c >= b) then ( execute (Set{0, MINC - b}->max() + Set{0, a - MAXC}->max())->display() ) else (if (c->compareTo(b)) < 0 then ( execute (Set{a - b, Set{0, a - MAXC}->max()}->min())->display() ) else (if (c->compareTo(a)) > 0 then ( execute (Set{a - b, Set{0, MINC - b}->max()}->min())->display() ) else skip ) ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(int(input())): a,b,c,r=map(int,input().split()); print(min(abs(a-b),max(0,abs(a-c)-r)+max(0,abs(b-c)-r))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var r : OclAny := null; Sequence{a,b,c,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); execute (Set{(a - b)->abs(), Set{0, (a - c)->abs() - r}->max() + Set{0, (b - c)->abs() - r}->max()}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): a,b,c,r=map(int,input().split(' ')) l_,r_=c-r,c+r if a>b : a=a+b b=a-b a=a-b if r_=l_ : if b<=r_ : print(0) else : print(b-r_) elif a<=l_ : if b<=r_ : print(l_-a) else : print(l_-a+b-r_) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var r : OclAny := null; Sequence{a,b,c,r} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var l_ : OclAny := null; var r_ : OclAny := null; Sequence{l_,r_} := Sequence{c - r,c + r} ; if (a->compareTo(b)) > 0 then ( var a : OclAny := a + b ; var b : double := a - b ; a := a - b ) else skip ; if (r_->compareTo(a)) < 0 or (b->compareTo(l_)) < 0 then ( execute (b - a)->display() ) else (if (a->compareTo(l_)) >= 0 then ( if (b->compareTo(r_)) <= 0 then ( execute (0)->display() ) else ( execute (b - r_)->display() ) ) else (if (a->compareTo(l_)) <= 0 then ( if (b->compareTo(r_)) <= 0 then ( execute (l_ - a)->display() ) else ( execute (l_ - a + b - r_)->display() ) ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math import sys import itertools import fractions if __name__=='__main__' : wtf=sys.stdin.read() wtf=wtf.strip().split('\n') T=int(wtf[0]) for t in wtf[1 :]: a,b,c,r=map(int,t.split()) d=c-r e=c+r A=min(a,b) B=max(a,b) a=A b=B ans=0 if d>=a and d<=b : ans+=abs(d-a) if e>=a and e<=b : ans+=abs(e-b) if ans==0 : if d<=a and e>=b : ans=0 else : ans=abs(a-b) print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( var wtf : String := (OclFile["System.in"]).readAll() ; wtf := wtf->trim().split(' ') ; var T : int := ("" + ((wtf->first())))->toInteger() ; for t : wtf->tail() do ( var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; var r : OclAny := null; Sequence{a,b,c,r} := (t.split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : double := c - r ; var e : OclAny := c + r ; var A : OclAny := Set{a, b}->min() ; var B : OclAny := Set{a, b}->max() ; var a : OclAny := A ; var b : OclAny := B ; var ans : int := 0 ; if (d->compareTo(a)) >= 0 & (d->compareTo(b)) <= 0 then ( ans := ans + (d - a)->abs() ) else skip ; if (e->compareTo(a)) >= 0 & (e->compareTo(b)) <= 0 then ( ans := ans + (e - b)->abs() ) else skip ; if ans = 0 then ( if (d->compareTo(a)) <= 0 & (e->compareTo(b)) >= 0 then ( ans := 0 ) else ( ans := (a - b)->abs() ) ) else skip ; execute (ans)->display()) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in[0]*int(input()): *a,c,r=map(int,input().split()) a,b=sorted(a) print(b-a-max(0,min(b,c+r)-max(a,c-r))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( ; var a : OclAny := null; var c : OclAny := null; var r : OclAny := null; Sequence{a,c,r} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := a->sort() ; execute (b - a - Set{0, Set{b, c + r}->min() - Set{a, c - r}->max()}->max())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for i in range(int(input())): n,s,t=map(int,input().split(' ')) print(n-min(s,t)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var n : OclAny := null; var s : OclAny := null; var t : OclAny := null; Sequence{n,s,t} := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; execute (n - Set{s, t}->min() + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for t in range(int(input())): a=input().split() n,s,t=int(a[0]),int(a[1]),int(a[2]) ans=max(n-s,n-t)+1 print(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for t : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var a : OclAny := input().split() ; var n : OclAny := null; var s : OclAny := null; var t : OclAny := null; Sequence{n,s,t} := Sequence{("" + ((a->first())))->toInteger(),("" + ((a[1+1])))->toInteger(),("" + ((a[2+1])))->toInteger()} ; var ans : OclAny := Set{n - s, n - t}->max() + 1 ; execute (ans)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tt=int(input()) for i in range(tt): string=input().split(" ") string_int=[int(i)for i in string] print(string_int[0]-min(string_int[1],string_int[2])+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var tt : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, tt-1) do ( var string : OclAny := input().split(" ") ; var string_int : Sequence := string->select(i | true)->collect(i | (("" + ((i)))->toInteger())) ; execute (string_int->first() - Set{string_int[1+1], string_int[2+1]}->min() + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- tt=int(input()) for i in range(tt): x,y,z=input().split(" ") print(int(x)-min(int(y),int(z))+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var tt : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, tt-1) do ( var x : OclAny := null; var y : OclAny := null; var z : OclAny := null; Sequence{x,y,z} := input().split(" ") ; execute (("" + ((x)))->toInteger() - Set{("" + ((y)))->toInteger(), ("" + ((z)))->toInteger()}->min() + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict,deque from functools import lru_cache from heapq import heappush,heappop from typing import Counter from bisect import bisect_right,bisect_left import math hpop=heappop hpush=heappush def solution(): s=input() num_value={">" : int("1000",2),"<" : int("1001",2),"+" : int("1010",2),"-" : int("1011",2),"." : int("1100",2),"," : int("1101",2),"[" : int("1110",2),"]" : int("1111",2)} Mod=10**6+3 res=0 cur=1 for i in range(len(s))[: :-1]: val=((cur % Mod)*num_value[s[i]]% Mod)% Mod res=(res % Mod+val % Mod)% Mod cur<<=4 print(res) def main(): t=1 for _ in range(t): solution() main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; skip ; skip ; var hpop : OclAny := heappop ; var hpush : OclAny := heappush ; skip ; skip ; main(); operation solution() pre: true post: true activity: var s : String := (OclFile["System.in"]).readLine() ; var num_value : Map := Map{ ">" |-> ("" + (("1000", 2)))->toInteger() }->union(Map{ "<" |-> ("" + (("1001", 2)))->toInteger() }->union(Map{ "+" |-> ("" + (("1010", 2)))->toInteger() }->union(Map{ "-" |-> ("" + (("1011", 2)))->toInteger() }->union(Map{ "." |-> ("" + (("1100", 2)))->toInteger() }->union(Map{ "," |-> ("" + (("1101", 2)))->toInteger() }->union(Map{ "[" |-> ("" + (("1110", 2)))->toInteger() }->union(Map{ "]" |-> ("" + (("1111", 2)))->toInteger() }))))))) ; var Mod : double := (10)->pow(6) + 3 ; var res : int := 0 ; var cur : int := 1 ; for i : range((s)->size())(subscript : (sliceop : (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) do ( var val : int := ((cur mod Mod) * num_value[s[i+1]+1] mod Mod) mod Mod ; res := (res mod Mod + val mod Mod) mod Mod ; cur := cur * (2->pow(4))) ; execute (res)->display(); operation main() pre: true post: true activity: var t : int := 1 ; for _anon : Integer.subrange(0, t-1) do ( solution()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,m=map(int,raw_input().split()) d=[int(raw_input())for _ in xrange(n)] c=[int(raw_input())for _ in xrange(m)] dp=[[float('inf')]*(m+1)for _ in xrange(n+1)] for i in xrange(m+1): dp[0][i]=0 for i in xrange(n): for j in xrange(m): dp[i+1][j+1]=min(min(dp[i+1]),dp[i][j]+d[i]*c[j]) print(dp[n][m]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var m : OclAny := null; Sequence{n,m} := (raw_input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var d : Sequence := xrange(n)->select(_anon | true)->collect(_anon | (("" + ((raw_input())))->toInteger())) ; var c : Sequence := xrange(m)->select(_anon | true)->collect(_anon | (("" + ((raw_input())))->toInteger())) ; var dp : Sequence := xrange(n + 1)->select(_anon | true)->collect(_anon | (MatrixLib.elementwiseMult(Sequence{ ("" + (('inf')))->toReal() }, (m + 1)))) ; for i : xrange(m + 1) do ( dp->first()[i+1] := 0) ; for i : xrange(n) do ( for j : xrange(m) do ( dp[i + 1+1][j + 1+1] := Set{(dp[i + 1+1])->min(), dp[i+1][j+1] + d[i+1] * c[j+1]}->min())) ; execute (dp[n+1][m+1])->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in[0]*int(input()): n,*s=map(int,input().split()); print(n-min(s)+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: for _anon : MatrixLib.elementwiseMult(Sequence{ 0 }, ("" + (((OclFile["System.in"]).readLine())))->toInteger()) do ( var n : OclAny := null; var s : OclAny := null; Sequence{n,s} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); execute (n - (s)->min() + 1)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findSum(N,K): ans=0 ; for i in range(1,N+1): ans+=(i % K); return ans ; N=10 ; K=2 ; print(findSum(N,K)); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 10; ; K := 2; ; execute (findSum(N, K))->display();; operation findSum(N : OclAny, K : OclAny) pre: true post: true activity: var ans : int := 0; ; for i : Integer.subrange(1, N + 1-1) do ( ans := ans + (i mod K);) ; return ans;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def decode(s,base): c2v={} res=0 next=1 for c in s : if not c in c2v : if len(c2v)dRes[1]: mn=dRes[1] print>>fOut,"Case #%d: %d" %(t+1,mn) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var sIn : String := "A-large(2).in"; var sOut : String := "A-large(2).out" ; var fIn : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(sIn)) ; var fOut : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile(sOut)) ; var nT : int := ("" + ((fIn.readLine()->trim())))->toInteger() ; for t : xrange(nT) do ( var inp : OclAny := fIn.readLine()->trim() ; var mn : int := -1 ; for base : xrange(2, 100) do ( var dRes : OclAny := decode(inp, base) ; if dRes->first() then ( if mn = -1 or (mn->compareTo(dRes[1+1])) > 0 then ( mn := dRes[1+1] ) else skip ) else skip) ; print /(2->pow(fOut)) ; (expr (expr (atom "Case #%d: %d")) % (expr (atom ( (testlist_comp (test (logical_test (comparison (expr (expr (atom (name t))) + (expr (atom (number (integer 1)))))))) , (test (logical_test (comparison (expr (atom (name mn))))))) ))))); operation decode(s : OclAny, base : OclAny) : OclAny pre: true post: true activity: var c2v : OclAny := Set{} ; var res : int := 0 ; var next : int := 1 ; for c : s do ( if not((c2v)->includes(c)) then ( if ((c2v)->size()->compareTo(base)) < 0 then ( c2v[c+1] := next ; if next = 1 then ( next := 0 ) else (if next = 0 then ( next := 2 ) else ( next := next + 1 ) ) ) else ( return Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name False)))))) ,)} ) ) else skip ; var dig : OclAny := c2v[c+1] ; res := base * res + dig) ; return Sequence{true, res}; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Gcjt(object): class Testcase(object): def __init__(self,num,gcjt): self.num=num self.gcjt=gcjt def answer(self,answer): self.gcjt.outs.write('Case #{num}:{ans}'.format(num=self.num,ans=answer)+'\n') def ws(self,string): self.gcjt.outs.write(string) def rl(self): return self.gcjt.ins.readline() def ri(self): return(int(s)for s in self.rl().split()) def __init__(self): filename=input('file name : ') self.fin=filename+'.in' self.fout=filename+'.out' def __enter__(self): self.ins=open(self.fin) self.outs=open(self.fout,'w') def __exit__(self,errtype=None,errvalu=None,errtrace=None): self.ins.close() self.outs.close() def tests(self,num=None): with self : if num is None : num=int(self.ins.readline()) for t in range(num): yield self.Testcase(t+1,self) def array(*dim): if len(dim)==1 : return[None]*(dim[0]) else : return[array(*dim[1 :])for i in range(dim[0])] def tests(): return Gcjt().tests() ------------------------------------------------------------ OCL File: --------- class Gcjt extends object { static operation newGcjt() : Gcjt pre: true post: Gcjt->exists( _x | result = _x ); attribute fin : String := filename + '.in'; attribute fout : String := filename + '.out'; operation initialise() : pre: true post: true activity: var filename : String := (OclFile["System.in"]).readLine('file name : ') ; self.fin := filename + '.in' ; self.fout := filename + '.out'; return self; operation __enter__() pre: true post: true activity: self.ins := OclFile.newOclFile_Write(OclFile.newOclFile(self.fin)) ; self.outs := OclFile.newOclFile_Write(OclFile.newOclFile(self.fout)); operation __exit__(errtype : OclAny,errvalu : OclAny,errtrace : OclAny) pre: true post: true activity: (expr (atom (name self)) (trailer . (name ins)) (trailer . (name close) (arguments ( )))) ; (expr (atom (name self)) (trailer . (name outs)) (trailer . (name close) (arguments ( )))); operation tests(num : OclAny) pre: true post: true activity: try ((with_item (test (logical_test (comparison (expr (atom (name self))))))) if num <>= null then ( num := ("" + ((self.ins.readLine())))->toInteger() ) else skip ; for t : Integer.subrange(0, num-1) do ( if _yieldCount_ < _position_ then _yieldCount_ := _yieldCount_ + 1 else return self.Testcase(t + 1, self))) catch (_e : OclException) do skip; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip; operation array(dim : OclAny : Sequence(OclAny)) : OclAny pre: true post: true activity: (args * (named_parameter (name dim))) if (dim)->size() = 1 then ( return MatrixLib.elementwiseMult(Sequence{ null }, (dim->first())) ) else ( return Integer.subrange(0, dim->first()-1)->select(i | true)->collect(i | (array((argument * (test (logical_test (comparison (expr (atom (name dim)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ])))))))))) ); operation tests() : OclAny pre: true post: true activity: return Gcjt().tests(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- T=int(input()) for case in range(1,T+1): i=input() chars=list("1023456789abcdefghijklmnopqrstuvwxyz") oldnew={} s="" for ch in i : if ch not in oldnew : oldnew[ch]=chars.pop(0) s+=oldnew[ch] base=len(oldnew) base=max(base,2) ans=int(s,base) print("Case #"+str(case)+": "+str(ans)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var T : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for case : Integer.subrange(1, T + 1-1) do ( var i : String := (OclFile["System.in"]).readLine() ; var chars : Sequence := ("1023456789abcdefghijklmnopqrstuvwxyz")->characters() ; var oldnew : OclAny := Set{} ; var s : String := "" ; for ch : i->characters() do ( if (oldnew)->excludes(ch) then ( oldnew[ch+1] := chars->at(0`firstArg+1) ; chars := chars->excludingAt(0+1) ) else skip ; s := s + oldnew[ch+1]) ; var base : int := (oldnew)->size() ; base := Set{base, 2}->max() ; var ans : int := ("" + ((s, base)))->toInteger() ; execute ("Case #" + ("" + ((case))) + ": " + ("" + ((ans))))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys fin=open('input.txt','r') fout=open('output.txt','w') l=int(fin.readline()) for case in range(l): v=fin.readline().strip() alen=len(set(list(v))) if alen<2 : alen=2 val=0 mapping={} usable=0 first=True for i in v : val*=alen if i not in mapping : if first : mapping[i]=1 first=False else : if usable==0 : mapping[i]=0 else : mapping[i]=usable+1 usable+=1 val+=mapping[i] fout.write("Case #%d: %d\n" %(case+1,val)) fin.close() fout.close() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var fin : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('input.txt')) ; var fout : OclFile := OclFile.newOclFile_Write(OclFile.newOclFile('output.txt')) ; var l : int := ("" + ((fin.readLine())))->toInteger() ; for case : Integer.subrange(0, l-1) do ( var v : OclAny := fin.readLine()->trim() ; var alen : int := (Set{}->union(((v))))->size() ; if alen < 2 then ( alen := 2 ) else skip ; var val : int := 0 ; var mapping : OclAny := Set{} ; var usable : int := 0 ; var first : boolean := true ; for i : v do ( val := val * alen ; if (mapping)->excludes(i) then ( if first then ( mapping[i+1] := 1 ; first := false ) else ( if usable = 0 then ( mapping[i+1] := 0 ) else ( mapping[i+1] := usable + 1 ) ; usable := usable + 1 ) ) else skip ; val := val + mapping[i+1]) ; fout.write(StringLib.format("Case #%d: %d\n",Sequence{case + 1, val}))) ; fin.closeFile() ; fout.closeFile(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math n=int(input()) a=list(map(int,input().split())) for i in a : print(1+((4*i*(i+1))//math.gcd(4*i,i+1))//(i+1)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for i : a do ( execute (1 + ((4 * i * (i + 1)) div (4 * i)->gcd(i + 1)) div (i + 1))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) a=list(map(int,input().strip().split())) ans=[-1]*t for i in range(t): if a[i]% 4==0 : ans[i]=a[i]*4+1 elif a[i]% 4==1 : ans[i]=a[i]*2+1 elif a[i]% 4==2 : ans[i]=a[i]*4+1 else : ans[i]=a[i]+1 for x in ans : print(x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var a : Sequence := ((input()->trim().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ -1 }, t) ; for i : Integer.subrange(0, t-1) do ( if a[i+1] mod 4 = 0 then ( ans[i+1] := a[i+1] * 4 + 1 ) else (if a[i+1] mod 4 = 1 then ( ans[i+1] := a[i+1] * 2 + 1 ) else (if a[i+1] mod 4 = 2 then ( ans[i+1] := a[i+1] * 4 + 1 ) else ( ans[i+1] := a[i+1] + 1 ) ) ) ) ; for x : ans do ( execute (x)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) l=[int(x)for x in input().split()] for i in l : if i % 4==1 : print(2*i+1) elif i % 4==3 : print(i+1) else : print(4*i+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var l : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for i : l do ( if i mod 4 = 1 then ( execute (2 * i + 1)->display() ) else (if i mod 4 = 3 then ( execute (i + 1)->display() ) else ( execute (4 * i + 1)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys input=sys.stdin.readline n=int(input()) for i in map(int,input().split()): if i % 2==0 : print(i*4+1) elif i % 4==1 : print(i*2+1) else : print(i+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var input : OclAny := (OclFile["System.in"]).readline ; var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : (input().split())->collect( _x | (OclType["int"])->apply(_x) ) do ( if i mod 2 = 0 then ( execute (i * 4 + 1)->display() ) else (if i mod 4 = 1 then ( execute (i * 2 + 1)->display() ) else ( execute (i + 1)->display() ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : try : xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2=map(float,input().split()) except EOFError : break if xb2xa2 or yb2ya2 : print("NO") else : print("YES") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( try ( var xa1 : OclAny := null; var ya1 : OclAny := null; var xa2 : OclAny := null; var ya2 : OclAny := null; var xb1 : OclAny := null; var yb1 : OclAny := null; var xb2 : OclAny := null; var yb2 : OclAny := null; Sequence{xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2} := (input().split())->collect( _x | (OclType["double"])->apply(_x) )) (except_clause except (test (logical_test (comparison (expr (atom (name EOFError)))))) : (suite (stmt (simple_stmt (small_stmt break))))) ; if (xb2->compareTo(xa1)) < 0 or (xb1->compareTo(xa2)) > 0 or (yb2->compareTo(ya1)) < 0 or (yb1->compareTo(ya2)) > 0 then ( execute ("NO")->display() ) else ( execute ("YES")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- M={} for i in range(int(input())): query=input().split() if query[0]=='0' : M[query[1]]=query[2] elif query[0]=='1' : if query[1]in M : print(M[query[1]]) else : print(0) else : M[query[1]]=0 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var M : OclAny := Set{} ; for i : Integer.subrange(0, ("" + (((OclFile["System.in"]).readLine())))->toInteger()-1) do ( var query : OclAny := input().split() ; if query->first() = '0' then ( M[query[1+1]+1] := query[2+1] ) else (if query->first() = '1' then ( if (M)->includes(query[1+1]) then ( execute (M[query[1+1]+1])->display() ) else ( execute (0)->display() ) ) else ( M[query[1+1]+1] := 0 ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) innput=input() listn=innput.split() for k in range(0,len(listn)): listn[k]=int(listn[k]) for n in listn : c=n % 4 if c==0 : print(4*n+1) elif c==1 : print(2*n+1) elif c==2 : print(4*n+1) else : print(n+1) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var innput : String := (OclFile["System.in"]).readLine() ; var listn : OclAny := innput.split() ; for k : Integer.subrange(0, (listn)->size()-1) do ( listn[k+1] := ("" + ((listn[k+1])))->toInteger()) ; for n : listn do ( var c : int := n mod 4 ; if c = 0 then ( execute (4 * n + 1)->display() ) else (if c = 1 then ( execute (2 * n + 1)->display() ) else (if c = 2 then ( execute (4 * n + 1)->display() ) else ( execute (n + 1)->display() ) ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- PI=3.14 from math import pow,sqrt def find_area(r,d): R=d/PI R+=pow(r,2) R=sqrt(R) area=PI*pow(R,2) return area if __name__=='__main__' : r=4 d=5 print(find_area(r,d)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var PI : double := 3.14 ; skip ; skip ; if __name__ = '__main__' then ( r := 4 ; d := 5 ; execute (find_area(r, d))->display() ) else skip; operation find_area(r : OclAny, d : OclAny) : OclAny pre: true post: true activity: var R : double := d / PI ; R := R + (r)->pow(2) ; R := sqrt(R) ; var area : double := PI * (R)->pow(2) ; return area; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minimumNumbers(n,s): if(s % n): return s/n+1 ; else : return s/n ; n=5 ; s=11 ; print(int(minimumNumbers(n,s))); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 5; ; s := 11; ; execute (("" + ((minimumNumbers(n, s))))->toInteger())->display();; operation minimumNumbers(n : OclAny, s : OclAny) pre: true post: true activity: if (s mod n) then ( return s / n + 1; ) else ( return s / n; ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countTriplets(arr,n,m): count=0 arr.sort() for end in range(n-1,1,-1): start=0 mid=end-1 while(startm): mid-=1 elif(produnion(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{1}->union(Sequence{ 1 }))))) ; n := (arr)->size() ; m := 1 ; execute (countTriplets(arr, n, m))->display() ) else skip; operation countTriplets(arr : OclAny, n : OclAny, m : OclAny) : OclAny pre: true post: true activity: var count : int := 0 ; arr := arr->sort() ; for end : Integer.subrange(1 + 1, n - 1)->reverse() do ( var start : int := 0 ; var mid : double := end - 1 ; while ((start->compareTo(mid)) < 0) do ( var prod : double := (arr[end+1] * arr[start+1] * arr[mid+1]) ; if ((prod->compareTo(m)) > 0) then ( mid := mid - 1 ) else (if ((prod->compareTo(m)) < 0) then ( start := start + 1 ) else (if (prod = m) then ( count := count + 1 ; mid := mid - 1 ; start := start + 1 ) else skip ) ) )) ; return count; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findIndex(n): if(n<=1): return n a=0 b=1 c=1 res=1 while(cdisplay(); operation findIndex(n : OclAny) : OclAny pre: true post: true activity: if (n <= 1) then ( return n ) else skip ; var a : int := 0 ; var b : int := 1 ; var c : int := 1 ; var res : int := 1 ; while ((c->compareTo(n)) < 0) do ( c := a + b ; res := res + 1 ; a := b ; b := c) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isVowel(ch): if ch in['i','a','e','o','u']: return True else : return False def isSatisfied(st,n): for i in range(1,n): if(isVowel(st[i])==False and isVowel(st[i-1])==False): return False for i in range(1,n-1): if(isVowel(st[i])and isVowel(st[i-1])==False and isVowel(st[i+1])==False): return False return True st="acaba" n=len(st) if(isSatisfied(st,n)): print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; st := "acaba" ; n := (st)->size() ; if (isSatisfied(st, n)) then ( execute ("Yes")->display() ) else ( execute ("No")->display() ); operation isVowel(ch : OclAny) : OclAny pre: true post: true activity: if (Sequence{'i'}->union(Sequence{'a'}->union(Sequence{'e'}->union(Sequence{'o'}->union(Sequence{ 'u' })))))->includes(ch) then ( return true ) else ( return false ); operation isSatisfied(st : OclAny, n : OclAny) : OclAny pre: true post: true activity: for i : Integer.subrange(1, n-1) do ( if (isVowel(st[i+1]) = false & isVowel(st[i - 1+1]) = false) then ( return false ) else skip) ; for i : Integer.subrange(1, n - 1-1) do ( if (isVowel(st[i+1]) & isVowel(st[i - 1+1]) = false & isVowel(st[i + 1+1]) = false) then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def countWays(n): dp=[0 for i in range(n+1)] dp[0]=0 dp[1]=1 dp[2]=1 for i in range(3,n+1): dp[i]=dp[i-1]+dp[i-3]+1 return dp[n] n=6 print(countWays(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 6 ; execute (countWays(n))->display(); operation countWays(n : OclAny) : OclAny pre: true post: true activity: var dp : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (0)) ; dp->first() := 0 ; dp[1+1] := 1 ; dp[2+1] := 1 ; for i : Integer.subrange(3, n + 1-1) do ( dp[i+1] := dp[i - 1+1] + dp[i - 3+1] + 1) ; return dp[n+1]; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def expect(m,n): ans=0.0 i=m while(i): ans+=(pow(i/m,n)-pow((i-1)/m,n))*i i-=1 return ans if __name__=="__main__" : m,n=6,3 print(expect(m,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( Sequence{m,n} := Sequence{6,3} ; execute (expect(m, n))->display() ) else skip; operation expect(m : OclAny, n : OclAny) : OclAny pre: true post: true activity: var ans : double := 0.0 ; var i : OclAny := m ; while (i) do ( ans := ans + ((i / m)->pow(n) - ((i - 1) / m)->pow(n)) * i ; i := i - 1) ; return ans; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def ProdOfPrimes(n): prime=[True for i in range(n+1)] p=2 while(p*p<=n): if(prime[p]==True): i=p*2 while(i<=n): prime[i]=False i+=p p+=1 prod=1 for i in range(2,n+1): if(prime[i]): prod*=i return prod n=10 print(ProdOfPrimes(n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; n := 10 ; execute (ProdOfPrimes(n))->display(); operation ProdOfPrimes(n : OclAny) : OclAny pre: true post: true activity: var prime : Sequence := Integer.subrange(0, n + 1-1)->select(i | true)->collect(i | (true)) ; var p : int := 2 ; while ((p * p->compareTo(n)) <= 0) do ( if (prime[p+1] = true) then ( var i : int := p * 2 ; while ((i->compareTo(n)) <= 0) do ( prime[i+1] := false ; i := i + p) ) else skip ; p := p + 1) ; var prod : int := 1 ; for i : Integer.subrange(2, n + 1-1) do ( if (prime[i+1]) then ( prod := prod * i ) else skip) ; return prod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys sys.setrecursionlimit(10**7) N,M=map(int,input().split()) D=[int(input())for i in range(N)] C=[int(input())for i in range(M)] memo={} def dfs(i,j): if i==N : return 0 if j==M : return 10**9 if(i,j)in memo : return memo[i,j] memo[i,j]=res=min(dfs(i+1,j+1)+D[i]*C[j],dfs(i,j+1)) return res print(dfs(0,0)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var N : OclAny := null; var M : OclAny := null; Sequence{N,M} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var D : Sequence := Integer.subrange(0, N-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var C : Sequence := Integer.subrange(0, M-1)->select(i | true)->collect(i | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; var memo : OclAny := Set{} ; skip ; execute (dfs(0, 0))->display(); operation dfs(i : OclAny, j : OclAny) : OclAny pre: true post: true activity: if i = N then ( return 0 ) else skip ; if j = M then ( return (10)->pow(9) ) else skip ; if (memo)->includes(Sequence{i, j}) then ( return memo[i+1][j+1] ) else skip ; memo[i+1][j+1] := Set{dfs(i + 1, j + 1) + D[i+1] * C[j+1], dfs(i, j + 1)}->min(); var res : OclAny := Set{dfs(i + 1, j + 1) + D[i+1] * C[j+1], dfs(i, j + 1)}->min() ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- dic={} for num1 in range(ord("a"),ord("z")+1): c1=chr(num1) dic[c1]=[] for num2 in range(ord("a"),ord("z")+1): c2=chr(num2) for num3 in range(ord("a"),ord("z")+1): c3=chr(num3) dic[c1].append(c1+c2+c3+"a") print("?"+dic["a"].pop()) used=set() while True : s=input() if s in used or s[0]!="a" : print("!OUT") break used.add(s) print("?"+dic[s[-1]].pop()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var dic : OclAny := Set{} ; for num1 : Integer.subrange(("a")->char2byte(), ("z")->char2byte() + 1-1) do ( var c1 : String := (num1)->byte2char() ; dic->at(c1) := Sequence{} ; for num2 : Integer.subrange(("a")->char2byte(), ("z")->char2byte() + 1-1) do ( var c2 : String := (num2)->byte2char() ; for num3 : Integer.subrange(("a")->char2byte(), ("z")->char2byte() + 1-1) do ( var c3 : String := (num3)->byte2char() ; (expr (atom (name dic)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (name c1)))))))) ])) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (expr (expr (atom (name c1))) + (expr (atom (name c2)))) + (expr (atom (name c3)))) + (expr (atom "a")))))))) ))))))) ; execute ("?" + dic->at("a")->last())->display() ; var used : Set := Set{}->union(()) ; while true do ( var s : String := (OclFile["System.in"]).readLine() ; if (used)->includes(s) or s->first() /= "a" then ( execute ("!OUT")->display() ; break ) else skip ; execute ((s) : used) ; execute ("?" + dic[s->last()+1]->last())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import bisect keys=[] q=int(input()) d={} def find(x): index=bisect.bisect_left(keys,x) if index==len(keys): return-1 if keys[index]==x : return index else : return-1 for _ in range(q): query=input().split(" ") if query[0]=="0" : if find(query[1])!=-1 : pass else : bisect.insort_left(keys,query[1]) d[query[1]]=query[2] elif query[0]=="1" : if find(query[1])!=-1 : print(d[query[1]]) else : print(0) elif query[0]=="2" : while find(query[1])>=0 : keys.pop(find(query[1])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var keys : Sequence := Sequence{} ; var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : OclAny := Set{} ; skip ; for _anon : Integer.subrange(0, q-1) do ( var query : OclAny := input().split(" ") ; if query->first() = "0" then ( if find(query[1+1]) /= -1 then ( skip ) else ( bisect.insort_left(keys, query[1+1]) ) ; d[query[1+1]+1] := query[2+1] ) else (if query->first() = "1" then ( if find(query[1+1]) /= -1 then ( execute (d[query[1+1]+1])->display() ) else ( execute (0)->display() ) ) else (if query->first() = "2" then ( while find(query[1+1]) >= 0 do ( keys := keys->excludingAt(find(query[1+1])+1)) ) else skip ) ) ); operation find(x : OclAny) : OclAny pre: true post: true activity: var index : OclAny := bisect.bisect_left(keys, x) ; if index = (keys)->size() then ( return -1 ) else skip ; if keys[index+1] = x then ( return index ) else ( return -1 ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- print("?za") use=["za"] can=[chr(i)for i in range(98,98+24)] can.extend(["a"+chr(i)for i in range(97,97+26)]) while 1 : s=input() if s[0]!="a" or s in use : print("!OUT") break use.append(s) if s=="a" : p="aa" elif s=="aa" : p="a" else : p=s[-1]+can.pop(0)+"a" print("?"+p) use.append(p) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: execute ("?za")->display() ; var use : Sequence := Sequence{ "za" } ; var can : Sequence := Integer.subrange(98, 98 + 24-1)->select(i | true)->collect(i | ((i)->byte2char())) ; can := can->union(Integer.subrange(97, 97 + 26-1)->select(i | true)->collect(i | ("a" + (i)->byte2char()))) ; while 1 do ( var s : String := (OclFile["System.in"]).readLine() ; if s->first() /= "a" or (use)->includes(s) then ( execute ("!OUT")->display() ; break ) else skip ; execute ((s) : use) ; if s = "a" then ( var p : String := "aa" ) else (if s = "aa" then ( p := "a" ) else ( p := s->last() + can->at(0`firstArg+1) + "a" ) ) ; execute ("?" + p)->display() ; execute ((p) : use)); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import datetime def compute(): ans=sum(1 for y in range(1901,2001)for m in range(1,13)if datetime.date(y,m,1).weekday()==6) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name y)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1901)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2001))))))))) )))))) (comp_iter (comp_for for (exprlist (expr (atom (name m)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 13))))))))) )))))) (comp_iter if (test (logical_test (comparison (comparison (expr (atom (name datetime)) (trailer . (name date) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name y))))))) , (argument (test (logical_test (comparison (expr (atom (name m))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ))) (trailer . (name weekday) (arguments ( ))))) == (comparison (expr (atom (number (integer 6))))))))))))))->sum() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- class Date : def __init__(self,d,m,y): self.d=d self.m=m self.y=y monthDays=[31,28,31,30,31,30,31,31,30,31,30,31] def countLeapYears(d): years=d.y if(d.m<=2): years-=1 return int(years/4-years/100+years/400) def getDifference(dt1,dt2): n1=dt1.y*365+dt1.d for i in range(0,dt1.m-1): n1+=monthDays[i] n1+=countLeapYears(dt1) n2=dt2.y*365+dt2.d for i in range(0,dt2.m-1): n2+=monthDays[i] n2+=countLeapYears(dt2) return(n2-n1) dt1=Date(1,2,2000) dt2=Date(1,2,2004) print("Difference between two dates is",getDifference(dt1,dt2)) ------------------------------------------------------------ OCL File: --------- class Date { static operation newDate() : Date pre: true post: Date->exists( _x | result = _x ); attribute d : OclAny := d; attribute m : OclAny := m; attribute y : OclAny := y; operation initialise(d : OclAny,m : OclAny,y : OclAny) : Date pre: true post: true activity: self.d := d ; self.m := m ; self.y := y; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; var monthDays : Sequence := Sequence{31}->union(Sequence{28}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{31}->union(Sequence{30}->union(Sequence{31}->union(Sequence{30}->union(Sequence{ 31 }))))))))))) ; skip ; skip ; dt1 := (Date.newDate()).initialise(1, 2, 2000) ; dt2 := (Date.newDate()).initialise(1, 2, 2004) ; execute ("Difference between two dates is")->display(); operation countLeapYears(d : OclAny) : OclAny pre: true post: true activity: var years : OclAny := d.y ; if (d.m <= 2) then ( years := years - 1 ) else skip ; return ("" + ((years / 4 - years / 100 + years / 400)))->toInteger(); operation getDifference(dt1 : OclAny, dt2 : OclAny) : OclAny pre: true post: true activity: var n1 : double := dt1.y * 365 + dt1.d ; for i : Integer.subrange(0, dt1.m - 1-1) do ( n1 := n1 + monthDays[i+1]) ; n1 := n1 + countLeapYears(dt1) ; var n2 : double := dt2.y * 365 + dt2.d ; for i : Integer.subrange(0, dt2.m - 1-1) do ( n2 := n2 + monthDays[i+1]) ; n2 := n2 + countLeapYears(dt2) ; return (n2 - n1); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- st=set() def generateNumbers(n,num,a,b): if(num>0 and num=n): return if(num*10+a>num): generateNumbers(n,num*10+a,a,b) generateNumbers(n,num*10+b,a,b) def printNumbers(n): for i in range(10): for j in range(i+1,10,1): generateNumbers(n,0,i,j) print("The numbers are:",end=" ") l=list(st) for i in l : print(i,end=" ") if __name__=='__main__' : n=12 printNumbers(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var st : Set := Set{}->union(()) ; skip ; skip ; if __name__ = '__main__' then ( n := 12 ; printNumbers(n) ) else skip; operation generateNumbers(n : OclAny, num : OclAny, a : OclAny, b : OclAny) pre: true post: true activity: if (num > 0 & (num->compareTo(n)) < 0) then ( execute ((num) : st) ) else skip ; if ((num->compareTo(n)) >= 0) then ( return ) else skip ; if ((num * 10 + a->compareTo(num)) > 0) then ( generateNumbers(n, num * 10 + a, a, b) ) else skip ; generateNumbers(n, num * 10 + b, a, b); operation printNumbers(n : OclAny) pre: true post: true activity: for i : Integer.subrange(0, 10-1) do ( for j : Integer.subrange(i + 1, 10-1)->select( $x | ($x - i + 1) mod 1 = 0 ) do ( generateNumbers(n, 0, i, j))) ; execute ("The numbers are:")->display() ; var l : Sequence := (st) ; for i : l do ( execute (i)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k,t=map(int,input().split()) t=(n*k*t)//100 for i in range(n): print(min(max(0,t-i*k),k),end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var t : OclAny := null; Sequence{n,k,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var t : int := (n * k * t) div 100 ; for i : Integer.subrange(0, n-1) do ( execute (Set{Set{0, t - i * k}->max(), k}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k,t=map(int,input().split()) for i in range(n): print(min(k,max(0,n*k*t//100-i*k)),end=' ') ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var t : OclAny := null; Sequence{n,k,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; for i : Integer.subrange(0, n-1) do ( execute (Set{k, Set{0, n * k * t div 100 - i * k}->max()}->min())->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def s(): [n,k,t]=list(map(int,input().split())) a=n*t//100 b=n*t % 100*k//100 c=n-a-1 print(*[k for _ in range(a)],end='') if n>a : print('' if a>0 else '',b,end='',sep='') if c>0 : print('',*[0 for _ in range(c)]) s() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; s(); operation s() pre: true post: true activity: ; Sequence{n}->union(Sequence{k}->union(Sequence{ t })) := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; var a : int := n * t div 100 ; var b : int := n * t mod 100 * k div 100 ; var c : double := n - a - 1 ; execute ((argument * (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name k)))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name a)))))))) )))))))) ])))))))->display() ; if (n->compareTo(a)) > 0 then ( execute (if a > 0 then '' else '' endif)->display() ) else skip ; if c > 0 then ( execute ('')->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys a=[int(l)for l in input().split()] n=a[0]; k=a[1]; t=a[2] i=0 t=int(t*n*k/100) while i=k : sys.stdout.write(str(k)+" ") t-=k else : sys.stdout.write(str(t)+" ") t=0 i+=1 ; ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var a : Sequence := input().split()->select(l | true)->collect(l | (("" + ((l)))->toInteger())) ; var n : OclAny := a->first(); var k : OclAny := a[1+1]; var t : OclAny := a[2+1] ; var i : int := 0 ; t := ("" + ((t * n * k / 100)))->toInteger() ; while (i->compareTo(n)) < 0 do ( if (t->compareTo(k)) >= 0 then ( (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name k)))))))) )))) + (expr (atom " ")))))))) )))) ; t := t - k ) else ( (expr (atom (name sys)) (trailer . (name stdout)) (trailer . (name write) (arguments ( (arglist (argument (test (logical_test (comparison (expr (expr (atom (name str)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) )))) + (expr (atom " ")))))))) )))) ; t := 0 ) ; i := i + 1;); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- N=int(input()) A=[int(x)for x in input().split()] A.sort() sum=0 for i in range(N-1): sum+=A[i] if(sum+A[N-1])% 2==0 and A[N-1]<=sum : print("YES") else : print("NO") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var A : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; A := A->sort() ; var sum : int := 0 ; for i : Integer.subrange(0, N - 1-1) do ( sum := sum + A[i+1]) ; if (sum + A[N - 1+1]) mod 2 = 0 & (A[N - 1+1]->compareTo(sum)) <= 0 then ( execute ("YES")->display() ) else ( execute ("NO")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k,x=map(int,input().split()) ls=list(map(int,input().split())) for m in range(1,k+1): ls[-m]=x print(sum(ls)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var x : OclAny := null; Sequence{n,k,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var ls : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for m : Integer.subrange(1, k + 1-1) do ( ls->reverse()->at(-(-m)) := x) ; execute ((ls)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k,t=map(int,input().split()) sum=(n*k*t//100) a,b=sum//k,sum % k ans=[0]*n ans[0 : a]=[k]*a if b>0 : ans[a]=b for t in ans : print(t,end=" ") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var t : OclAny := null; Sequence{n,k,t} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var sum : int := (n * k * t div 100) ; var a : OclAny := null; var b : OclAny := null; Sequence{a,b} := Sequence{sum div k,sum mod k} ; var ans : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, n) ; ans.subrange(0+1, a) := MatrixLib.elementwiseMult(Sequence{ k }, a) ; if b > 0 then ( ans[a+1] := b ) else skip ; for t : ans do ( execute (t)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict def main(n,m): d=defaultdict(int) for _ in range(n): M=list(map(int,input().split())) for num,i in enumerate(M): if num==0 : continue d[i]+=1 ans=10**20 for key,value in d.items(): if value>m : ans=key m=value elif value==m : ans=min(ans,key) if ans==10**20 : ans=0 print(ans) while 1 : n,m=map(int,input().split()) if n==m==0 : break main(n,m) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; while 1 do ( Sequence{n,m} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; if n = m & (m == 0) then ( break ) else skip ; main(n, m)); operation main(n : OclAny, m : OclAny) pre: true post: true activity: var d : OclAny := defaultdict(OclType["int"]) ; for _anon : Integer.subrange(0, n-1) do ( var M : Sequence := ((input().split())->collect( _x | (OclType["int"])->apply(_x) )) ; for _tuple : Integer.subrange(1, (M)->size())->collect( _indx | Sequence{_indx-1, (M)->at(_indx)} ) do (var _indx : int := 1; var num : OclAny := _tuple->at(_indx); _indx := _indx + 1; var i : OclAny := _tuple->at(_indx); if num = 0 then ( continue ) else skip ; d[i+1] := d[i+1] + 1)) ; var ans : double := (10)->pow(20) ; for _tuple : d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()}) do (var _indx : int := 1; var key : OclAny := _tuple->at(_indx); _indx := _indx + 1; var value : OclAny := _tuple->at(_indx); if (value->compareTo(m)) > 0 then ( ans := key ; m := value ) else (if value = m then ( ans := Set{ans, key}->min() ) else skip)) ; if ans = (10)->pow(20) then ( ans := 0 ) else skip ; execute (ans)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- readline=open(0).readline Q=int(readline()) ans=[] M={} get=lambda key,push=ans.append,get=M.get : push("%s\n" % get(key,"0")) def delete(key): if key in M : del M[key] C=[M.__setitem__,get,delete].__getitem__ for q in range(Q): t,*a=readline().split() C(int(t))(*a) open(1,'w').writelines(ans) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var readline : OclAny := open(0).readline ; var Q : int := ("" + ((readline())))->toInteger() ; var ans : Sequence := Sequence{} ; var M : OclAny := Set{} ; var get : Function := lambda key : OclAny, push : OclAny, get : OclAny in (push(StringLib.format("%s\n",get(key, "0")))) ; skip ; var C : OclAny := Sequence{M.__setitem__}->union(Sequence{get}->union(Sequence{ delete })).__getitem__ ; for q : Integer.subrange(0, Q-1) do ( var t : OclAny := null; var a : OclAny := null; Sequence{t,a} := readline().split() ; (expr (atom (name C)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name t)))))))) ))))))))) ))) (trailer (arguments ( (arglist (argument * (test (logical_test (comparison (expr (atom (name a)))))))) ))))) ; (expr (atom (name open)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom 'w'))))))) ))) (trailer . (name writelines) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name ans)))))))) )))); operation delete(key : OclAny) pre: true post: true activity: if (M)->includes(key) then ( execute (M[key+1])->isDeleted() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- while True : (N,Q)=[int(x)for x in input().split()] if N==0 and Q==0 : exit() Date=[0]*100 meeting_day=0 member_num=0 for i in range(N): M=[int(x)for x in input().split()] for j in range(1,M[0]+1): Date[M[j]-1]+=1 for i in range(100): if Date[i]>=Q and Date[i]>member_num : meeting_day=i+1 member_num=Date[i] print(meeting_day) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: while true do ( ; var Sequence{N, Q} : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; if N = 0 & Q = 0 then ( exit() ) else skip ; var Date : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, 100) ; var meeting_day : int := 0 ; var member_num : int := 0 ; for i : Integer.subrange(0, N-1) do ( var M : Sequence := input().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())) ; for j : Integer.subrange(1, M->first() + 1-1) do ( Date[M[j+1] - 1+1] := Date[M[j+1] - 1+1] + 1)) ; for i : Integer.subrange(0, 100-1) do ( if (Date[i+1]->compareTo(Q)) >= 0 & (Date[i+1]->compareTo(member_num)) > 0 then ( meeting_day := i + 1 ; member_num := Date[i+1] ) else skip) ; execute (meeting_day)->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf=10**3 eps=1.0/10**10 mod=10**9+7 def LI(): return[int(x)for x in sys.stdin.readline().split()] def LI_(): return[int(x)-1 for x in sys.stdin.readline().split()] def LF(): return[float(x)for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s,flush=True) def main(): rr=[] while True : n,q=LI() if n==0 : break a=[LI()for _ in range(n)] d=collections.defaultdict(int) for c in a : for cc in c[1 :]: d[cc]+=1 t=sorted([[-v,k]for k,v in d.items()if v>=q]) if len(t)==0 : rr.append(0) else : rr.append(t[0][1]) return '\n'.join(map(str,rr)) print(main()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; sys.setrecursionlimit((10)->pow(7)) ; var Math_PINFINITY : double := (10)->pow(3) ; var eps : double := 1.0 / (10)->pow(10) ; var mod : double := (10)->pow(9) + 7 ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; skip ; execute (main())->display(); operation LI() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger())); operation LI_() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toInteger() - 1)); operation LF() : OclAny pre: true post: true activity: return sys.stdin.readLine().split()->select(x | true)->collect(x | (("" + ((x)))->toReal())); operation LS() : OclAny pre: true post: true activity: return sys.stdin.readLine().split(); operation I() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toInteger(); operation F() : OclAny pre: true post: true activity: return ("" + (((OclFile["System.in"]).readLine())))->toReal(); operation S() : OclAny pre: true post: true activity: return (OclFile["System.in"]).readLine(); operation pf(s : OclAny) : OclAny pre: true post: true activity: return (s)->display(); operation main() : OclAny pre: true post: true activity: var rr : Sequence := Sequence{} ; while true do ( var n : OclAny := null; var q : OclAny := null; Sequence{n,q} := LI() ; if n = 0 then ( break ) else skip ; var a : Sequence := Integer.subrange(0, n-1)->select(_anon | true)->collect(_anon | (LI())) ; var d : OclAny := .defaultdict(OclType["int"]) ; for c : a do ( for cc : c->tail() do ( d[cc+1] := d[cc+1] + 1)) ; var t : Sequence := d->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->select(_tuple | let k : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in (v->compareTo(q)) >= 0)->collect(_tuple | let k : OclAny = _tuple->at(1) in let v : OclAny = _tuple->at(2) in (Sequence{-v}->union(Sequence{ k })))->sort() ; if (t)->size() = 0 then ( execute ((0) : rr) ) else ( execute ((t->first()[1+1]) : rr) )) ; return StringLib.sumStringsWithSeparator(((rr)->collect( _x | (OclType["String"])->apply(_x) )), ' '); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def get_input(): data_list=input().split() for i in range(len(data_list)): data_list[i]=int(data_list[i]) return data_list def make_dict(day_dict,data_list): candidate_num=data_list[0]+1 for i in range(1,candidate_num): data=data_list[i] if data in day_dict : day_dict[data]+=1 else : day_dict[data]=1 return day_dict def decide_open_day(day_dict,quorum): max_num=max(day_dict.values()) if max_numdisplay() ) else ( open_day := decide_open_day(day_dict, quorum) ; execute (open_day)->display() )) ) else skip; operation get_input() : OclAny pre: true post: true activity: var data_list : OclAny := input().split() ; for i : Integer.subrange(0, (data_list)->size()-1) do ( data_list[i+1] := ("" + ((data_list[i+1])))->toInteger()) ; return data_list; operation make_dict(day_dict : OclAny, data_list : OclAny) : OclAny pre: true post: true activity: var candidate_num : OclAny := data_list->first() + 1 ; for i : Integer.subrange(1, candidate_num-1) do ( var data : OclAny := data_list[i+1] ; if (day_dict)->includes(data) then ( day_dict[data+1] := day_dict[data+1] + 1 ) else ( day_dict[data+1] := 1 )) ; return day_dict; operation decide_open_day(day_dict : OclAny, quorum : OclAny) : OclAny pre: true post: true activity: var max_num : OclAny := (day_dict.values())->max() ; if (max_num->compareTo(quorum)) < 0 then ( return 0 ) else skip ; var max_k_list : Sequence := day_dict->asSequence()->collect( _mx | Sequence{_mx->keys()->any(), _mx->values()->any()})->select(kv | kv[1+1] = max_num)->collect(kv | (kv->first())) ; var open_day : OclAny := (max_k_list)->min() ; return open_day; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- cond=[int(n)for n in input().split(" ")] while True : answer=[101,0] case=[] sets=set() for c in range(cond[0]): case.append([int(n)for n in input().split(" ")[1 :]]) sets=sets |{n for n in case[-1]} else : for num in sets : disp=[num,0] for c in case : if num in c : disp[1]+=1 else : if(disp[1]>=cond[1]and disp[1]>answer[1])or(disp[1]==answer[1]and disp[0]select(n | true)->collect(n | (("" + ((n)))->toInteger())) ; while true do ( var answer : Sequence := Sequence{101}->union(Sequence{ 0 }) ; var case : Sequence := Sequence{} ; var sets : Set := Set{}->union(()) ; (compound_stmt for (exprlist (expr (atom (name c)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name cond)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name case)) (trailer . (name append) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " "))))))) ))) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))) :)) ]))))))) ]))))))) )))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name sets)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (expr (atom (name sets))) | (expr (atom { (dictorsetmaker (testlist_comp (test (logical_test (comparison (expr (atom (name n)))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name case)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom - (number (integer 1))))))))) ])))))))) }))))))))))))) (else_clause else : (suite (stmt (compound_stmt for (exprlist (expr (atom (name num)))) in (testlist (test (logical_test (comparison (expr (atom (name sets))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name disp)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name num)))))) , (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ]))))))))))) (stmt (compound_stmt for (exprlist (expr (atom (name c)))) in (testlist (test (logical_test (comparison (expr (atom (name case))))))) : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name num)))) in (comparison (expr (atom (name c))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name disp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))))) (assign_part += (testlist (test (logical_test (comparison (expr (atom (number (integer 1)))))))))))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom (name disp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) >= (comparison (expr (atom (name cond)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))) and (logical_test (comparison (comparison (expr (atom (name disp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) > (comparison (expr (atom (name answer)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ]))))))))) ))))) or (logical_test (comparison (expr (atom ( (testlist_comp (test (logical_test (logical_test (comparison (comparison (expr (atom (name disp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))) == (comparison (expr (atom (name answer)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 1))))))))) ])))))) and (logical_test (comparison (comparison (expr (atom (name disp)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) < (comparison (expr (atom (name answer)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ]))))))))) ))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name answer)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name disp)))))))))))))))))))) (else_clause else : (suite (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name answer)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))) == (comparison (expr (atom (number (integer 101)))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ))))))))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom print) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name answer)) (trailer (arguments [ (subscriptlist (subscript (test (logical_test (comparison (expr (atom (number (integer 0))))))))) ])))))))) )))))))))))))))) (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name cond)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))) (comp_for for (exprlist (expr (atom (name n)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom " "))))))) )))))))) ]))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name cond)))) == (comparison (expr (atom [ (testlist_comp (test (logical_test (comparison (expr (atom (number (integer 0))))))) , (test (logical_test (comparison (expr (atom (number (integer 0)))))))) ])))))) : (suite (stmt (simple_stmt (small_stmt break)))))))))))))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getOddOccurrence(arr): res=0 for element in arr : res=res ^ element return res arr=[2,3,5,4,5,2,4,3,5,2,4,4,2] print("%d" % getOddOccurrence(arr)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{4}->union(Sequence{5}->union(Sequence{2}->union(Sequence{4}->union(Sequence{3}->union(Sequence{5}->union(Sequence{2}->union(Sequence{4}->union(Sequence{4}->union(Sequence{ 2 })))))))))))) ; execute (StringLib.format("%d",getOddOccurrence(arr)))->display(); operation getOddOccurrence(arr : OclAny) : OclAny pre: true post: true activity: var res : int := 0 ; for element : arr do ( res := MathLib.bitwiseXor(res, element)) ; return res; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def isKthBitSet(x,k): if((x &(1<<(k-1)))!=0): return True else : return False def isPalindrome(x): l=1 r=2*8 while(lpow(15 + 1)) * (2->pow(16)) ; execute (("" + ((isPalindrome(x))))->toInteger())->display() ; x := 1 * (2->pow(31 + 1)) ; execute (("" + ((isPalindrome(x))))->toInteger())->display() ) else skip; operation isKthBitSet(x : OclAny, k : OclAny) : OclAny pre: true post: true activity: if ((MathLib.bitwiseAnd(x, (1 * (2->pow((k - 1)))))) /= 0) then ( return true ) else ( return false ); operation isPalindrome(x : OclAny) : OclAny pre: true post: true activity: var l : int := 1 ; var r : int := 2 * 8 ; while ((l->compareTo(r)) < 0) do ( if (isKthBitSet(x, l) /= isKthBitSet(x, r)) then ( return false ) else skip ; l := l + 1 ; r := r - 1) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* def SieveOfEratosthenes(n,isPrime): isPrime[0],isPrime[1]=False,False for i in range(2,n+1): isPrime[i]=True for p in range(2,int(sqrt(n))+1): if isPrime[p]==True : for i in range(p*2,n+1,p): isPrime[i]=False def findPrimePair(n): flag=0 isPrime=[False]*(n+1) SieveOfEratosthenes(n,isPrime) for i in range(2,n): x=int(n/i) if(isPrime[i]& isPrime[x]and x!=i and x*i==n): print(i,x) flag=1 break if not flag : print("No such pair found") if __name__=="__main__" : n=39 ; findPrimePair(n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( n := 39; ; findPrimePair(n) ) else skip; operation SieveOfEratosthenes(n : OclAny, isPrime : OclAny) pre: true post: true activity: var isPrime->first() : OclAny := null; var isPrime[1+1] : OclAny := null; Sequence{isPrime->first(),isPrime[1+1]} := Sequence{false,false} ; for i : Integer.subrange(2, n + 1-1) do ( isPrime[i+1] := true) ; for p : Integer.subrange(2, ("" + ((sqrt(n))))->toInteger() + 1-1) do ( if isPrime[p+1] = true then ( for i : Integer.subrange(p * 2, n + 1-1)->select( $x | ($x - p * 2) mod p = 0 ) do ( isPrime[i+1] := false) ) else skip); operation findPrimePair(n : OclAny) pre: true post: true activity: var flag : int := 0 ; isPrime := MatrixLib.elementwiseMult(Sequence{ false }, (n + 1)) ; SieveOfEratosthenes(n, isPrime) ; for i : Integer.subrange(2, n-1) do ( var x : int := ("" + ((n / i)))->toInteger() ; if (MathLib.bitwiseAnd(isPrime[i+1], isPrime[x+1]) & x /= i & x * i = n) then ( execute (i)->display() ; flag := 1 ; break ) else skip) ; if not(flag) then ( execute ("No such pair found")->display() ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- a,b,c=map(int,input().split()); print(sum(map(int,input().split()[: a-b]))+b*c) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var a : OclAny := null; var b : OclAny := null; var c : OclAny := null; Sequence{a,b,c} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ); execute (((input().split().subrange(1,a - b))->collect( _x | (OclType["int"])->apply(_x) ))->sum() + b * c)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if a==0 : return b return gcd(b % a,a) a=10 b=15 print("gcd(",a,",",b,")=",gcd(a,b)) a=35 b=10 print("gcd(",a,",",b,")=",gcd(a,b)) a=31 b=2 print("gcd(",a,",",b,")=",gcd(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 10 ; b := 15 ; execute ("gcd(")->display() ; a := 35 ; b := 10 ; execute ("gcd(")->display() ; a := 31 ; b := 2 ; execute ("gcd(")->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a = 0 then ( return b ) else skip ; return gcd(b mod a, a); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def gcd(a,b): if a==0 : return b return gcd(b % a,a) a=10 b=15 print("gcd(",a,",",b,")=",gcd(a,b)) a=35 b=10 print("gcd(",a,",",b,")=",gcd(a,b)) a=31 b=2 print("gcd(",a,",",b,")=",gcd(a,b)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; a := 10 ; b := 15 ; execute ("gcd(")->display() ; a := 35 ; b := 10 ; execute ("gcd(")->display() ; a := 31 ; b := 2 ; execute ("gcd(")->display(); operation gcd(a : OclAny, b : OclAny) : OclAny pre: true post: true activity: if a = 0 then ( return b ) else skip ; return gcd(b mod a, a); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def compute(): SIZE_LIMIT=1000000 TYPE_LIMIT=10 type=[0]*(SIZE_LIMIT+1) for n in range(3,SIZE_LIMIT//4+2): for m in range(n-2,0,-2): tiles=n*n-m*m if tiles>SIZE_LIMIT : break type[tiles]+=1 ans=sum(1 for t in type if 1<=t<=TYPE_LIMIT) return str(ans) if __name__=="__main__" : print(compute()) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( execute (compute())->display() ) else skip; operation compute() : OclAny pre: true post: true activity: var SIZE_LIMIT : int := 1000000 ; var TYPE_LIMIT : int := 10 ; var type : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, (SIZE_LIMIT + 1)) ; for n : Integer.subrange(3, SIZE_LIMIT div 4 + 2-1) do ( for m : Integer.subrange(n - 2, 0-1)->select( $x | ($x - n - 2) mod -2 = 0 ) do ( var tiles : double := n * n - m * m ; if (tiles->compareTo(SIZE_LIMIT)) > 0 then ( break ) else skip ; OclType.newOclType([tiles+1]) := OclType.newOclType([tiles+1]) + 1)) ; var ans : OclAny := ((argument (test (logical_test (comparison (expr (atom (number (integer 1))))))) (comp_for for (exprlist (expr (atom (name t)))) in (logical_test (comparison (expr (atom (name type))))) (comp_iter if (test (logical_test (comparison (comparison (comparison (expr (atom (number (integer 1))))) <= (comparison (expr (atom (name t))))) <= (comparison (expr (atom (name TYPE_LIMIT)))))))))))->sum() ; return ("" + ((ans))); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import os import sys def main(): q=int(input()) dictionary={} for _ in range(q): command=list(input().split()) if command[0]=='0' : dictionary[command[1]]=int(command[2]) elif command[0]=='1' : if command[1]in dictionary.keys(): print(dictionary[command[1]]) else : print(0) else : if command[1]in dictionary.keys(): del dictionary[command[1]] if __name__=="__main__" : main() ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; if __name__ = "__main__" then ( main() ) else skip; operation main() pre: true post: true activity: var q : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var dictionary : OclAny := Set{} ; for _anon : Integer.subrange(0, q-1) do ( var command : Sequence := (input().split()) ; if command->first() = '0' then ( dictionary[command[1+1]+1] := ("" + ((command[2+1])))->toInteger() ) else (if command->first() = '1' then ( if (dictionary.keys())->includes(command[1+1]) then ( execute (dictionary[command[1+1]+1])->display() ) else ( execute (0)->display() ) ) else ( if (dictionary.keys())->includes(command[1+1]) then ( execute (dictionary[command[1+1]+1])->isDeleted() ) else skip ) ) ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) while t>0 : t-=1 S=input() s=list(S) stack=[] pos=[] check0=0 for i in range(0,len(s)): j=len(s)-i-1 stack.append([j,int(s[j])]) if s[j]=="0" : if check0==0 : if not pos : stack.pop() pos.append(j) else : if pos[-1]-j>1 : stack.pop() pos.append(j) if stack : if stack[-1][1]==0 : check0=1 if check0==1 : if s[j]=="1" : if pos[-1]-j>1 : stack.pop() pos.append(j) stack2=[] check=0 for i in range(0,len(stack)-1): if stack[i][1]toInteger() ; while t > 0 do ( t := t - 1 ; var S : String := (OclFile["System.in"]).readLine() ; var s : Sequence := (S)->characters() ; var stack : Sequence := Sequence{} ; var pos : Sequence := Sequence{} ; var check0 : int := 0 ; for i : Integer.subrange(0, (s)->size()-1) do ( var j : double := (s)->size() - i - 1 ; execute ((Sequence{j}->union(Sequence{ ("" + ((s[j+1])))->toInteger() })) : stack) ; if s[j+1] = "0" then ( if check0 = 0 then ( if not(pos) then ( stack := stack->front() ; execute ((j) : pos) ) else ( if pos->last() - j > 1 then ( stack := stack->front() ; execute ((j) : pos) ) else skip ) ; if stack then ( if stack->last()[1+1] = 0 then ( check0 := 1 ) else skip ) else skip ) else skip ) else skip ; if check0 = 1 then ( if s[j+1] = "1" then ( if pos->last() - j > 1 then ( stack := stack->front() ; execute ((j) : pos) ) else skip ) else skip ) else skip) ; var stack2 : Sequence := Sequence{} ; var check : int := 0 ; for i : Integer.subrange(0, (stack)->size() - 1-1) do ( if (stack[i+1][1+1]->compareTo(stack[i + 1+1][1+1])) < 0 then ( check := 1 ) else skip) ; if check = 1 then ( execute ("NO")->display() ) else ( execute ("YES")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for r in range(t): s=input() one=False res=False for i in range(len(s)-1): if s[i]=='1' and s[i+1]=='1' : one=True if s[i]=='0' and s[i+1]=='0' and one : res=True if not res : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for r : Integer.subrange(0, t-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var one : boolean := false ; var res : boolean := false ; for i : Integer.subrange(0, (s)->size() - 1-1) do ( if s[i+1] = '1' & s[i + 1+1] = '1' then ( one := true ) else skip ; if s[i+1] = '0' & s[i + 1+1] = '0' & one then ( res := true ) else skip) ; if not(res) then ( execute ("Yes")->display() ) else ( execute ("No")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- t=int(input()) for r in range(t): s=input() one=False res=False for i in range(len(s)-1): if s[i]=='1' and s[i+1]=='1' and not one : one=True if s[i]=='0' and s[i+1]=='0' and one : res=True break if not res : print("Yes") else : print("No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var t : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for r : Integer.subrange(0, t-1) do ( var s : String := (OclFile["System.in"]).readLine() ; var one : boolean := false ; var res : boolean := false ; for i : Integer.subrange(0, (s)->size() - 1-1) do ( if s[i+1] = '1' & s[i + 1+1] = '1' & not(one) then ( one := true ) else skip ; if s[i+1] = '0' & s[i + 1+1] = '0' & one then ( res := true ; break ) else skip) ; if not(res) then ( execute ("Yes")->display() ) else ( execute ("No")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for _ in range(0,int(input())): s=list(map(int,input())) n=[] i=0 while itoInteger()-1) do ( var s : Sequence := (((OclFile["System.in"]).readLine())->collect( _x | (OclType["int"])->apply(_x) )) ; var n : Sequence := Sequence{} ; var i : int := 0 ; while (i->compareTo((s)->size() - 1)) < 0 do ( if (s[i + 1+1] = s[i+1]) then ( var w : Sequence := Sequence{ s[i+1] } ; while (i->compareTo((s)->size() - 1)) < 0 & s[i + 1+1] = s[i+1] do ( i := i + 1 ; execute ((s[i+1]) : w)) ; n := n->union(w) ) else ( i := i + 1 )) ; execute (Sequence{"NO"}->union(Sequence{ "YES" })->select(n = n->sort()))->display()); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- for j in range(1): pass for _ in range(int(input())): s=input() if s.find("11")toInteger()-1) do ( var s : String := (OclFile["System.in"]).readLine() ; if (s->indexOf("11") - 1->compareTo(s.rfind("00"))) < 0 & (s->indexOf("11") - 1 /= -1 & s.rfind("00") /= -1) then ( execute ("NO")->display() ) else ( execute ("YES")->display() )); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maxZeros(N): maxm=-1 cnt=0 while(N): if(not(N & 1)): cnt+=1 N>>=1 maxm=max(maxm,cnt) else : maxm=max(maxm,cnt) cnt=0 N>>=1 return maxm N=14 print(maxZeros(N)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; N := 14 ; execute (maxZeros(N))->display(); operation maxZeros(N : OclAny) : OclAny pre: true post: true activity: var maxm : int := -1 ; var cnt : int := 0 ; while (N) do ( if (not((MathLib.bitwiseAnd(N, 1)))) then ( cnt := cnt + 1 ; N := N div (2->pow(1)) ; maxm := Set{maxm, cnt}->max() ) else ( maxm := Set{maxm, cnt}->max() ; cnt := 0 ; N := N div (2->pow(1)) )) ; return maxm; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- (n,k,x)=map(int,input().split(' ')) a=list(map(int,input().split(' '))) for i in range(k): a[~ i]=x print(sum(a)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var Sequence{n, k, x} : Sequence := (input().split(' '))->collect( _x | (OclType["int"])->apply(_x) ) ; var a : Sequence := ((input().split(' '))->collect( _x | (OclType["int"])->apply(_x) )) ; for i : Integer.subrange(0, k-1) do ( a[MathLib.bitwiseNot(i)+1] := x) ; execute ((a)->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def getLongestSeq(a,n): maxIdx=0 maxLen=0 currLen=0 currIdx=0 for k in range(n): if a[k]>0 : currLen+=1 if currLen==1 : currIdx=k else : if currLen>maxLen : maxLen=currLen maxIdx=currIdx currLen=0 if maxLen>0 : print('Index : ',maxIdx,',Length : ',maxLen,) else : print("No positive sequence detected.") arr=[1,2,-3,2,3,4,-6,1,2,3,4,5,-8,5,6] n=len(arr) getLongestSeq(arr,n) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var arr : Sequence := Sequence{1}->union(Sequence{2}->union(Sequence{-3}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{-6}->union(Sequence{1}->union(Sequence{2}->union(Sequence{3}->union(Sequence{4}->union(Sequence{5}->union(Sequence{-8}->union(Sequence{5}->union(Sequence{ 6 })))))))))))))) ; n := (arr)->size() ; getLongestSeq(arr, n); operation getLongestSeq(a : OclAny, n : OclAny) pre: true post: true activity: var maxIdx : int := 0 ; var maxLen : int := 0 ; var currLen : int := 0 ; var currIdx : int := 0 ; for k : Integer.subrange(0, n-1) do ( if a[k+1] > 0 then ( currLen := currLen + 1 ; if currLen = 1 then ( currIdx := k ) else skip ) else ( if (currLen->compareTo(maxLen)) > 0 then ( maxLen := currLen ; maxIdx := currIdx ) else skip ; currLen := 0 )) ; if maxLen > 0 then ( execute ('Index : ')->display() ) else ( execute ("No positive sequence detected.")->display() ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math class Node : def __init__(self,data): self.data=data self.right=None self.down=None def construct(arr,i,j,m,n): if(i>n-1 or j>m-1): return None temp=Node(arr[i][j]) temp.data=arr[i][j] temp.right=construct(arr,i,j+1,m,n) temp.down=construct(arr,i+1,j,m,n) return temp def display(head): Dp=head while(Dp): Rp=Dp while(Rp): print(Rp.data,end=" ") Rp=Rp.right print() Dp=Dp.down if __name__=='__main__' : arr=[[1,2,3],[4,5,6],[7,8,9]] m,n=3,3 head=construct(arr,0,0,m,n) display(head) ------------------------------------------------------------ OCL File: --------- class Node { static operation newNode() : Node pre: true post: Node->exists( _x | result = _x ); attribute data : OclAny := data; attribute right : OclAny := null; attribute down : OclAny := null; operation initialise(data : OclAny) : Node pre: true post: true activity: self.data := data ; self.right := null ; self.down := null; return self; } class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; skip ; skip ; if __name__ = '__main__' then ( arr := Sequence{Sequence{1}->union(Sequence{2}->union(Sequence{ 3 }))}->union(Sequence{Sequence{4}->union(Sequence{5}->union(Sequence{ 6 }))}->union(Sequence{ Sequence{7}->union(Sequence{8}->union(Sequence{ 9 })) })) ; Sequence{m,n} := Sequence{3,3} ; head := construct(arr, 0, 0, m, n) ; display(head) ) else skip; operation construct(arr : OclAny, i : OclAny, j : OclAny, m : OclAny, n : OclAny) : OclAny pre: true post: true activity: if ((i->compareTo(n - 1)) > 0 or (j->compareTo(m - 1)) > 0) then ( return null ) else skip ; var temp : Node := (Node.newNode()).initialise(arr[i+1][j+1]) ; temp.data := arr[i+1][j+1] ; temp.right := construct(arr, i, j + 1, m, n) ; temp.down := construct(arr, i + 1, j, m, n) ; return temp; operation display(head : OclAny) pre: true post: true activity: var Dp : OclAny := head ; while (Dp) do ( var Rp : OclAny := Dp ; while (Rp) do ( execute (Rp.data)->display() ; Rp := Rp.right) ; execute (->display() ; Dp := Dp.down); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math N=int(input()) nums=[int(input())for _ in range(N)] def is_prime(num): if num<2 : return False else : num_sqrt=math.floor(math.sqrt(num)) for prime in range(2,num_sqrt+1): if num % prime==0 : return False break return True print(len([n for n in nums if is_prime(n)])) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; var N : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var nums : Sequence := Integer.subrange(0, N-1)->select(_anon | true)->collect(_anon | (("" + (((OclFile["System.in"]).readLine())))->toInteger())) ; skip ; execute ((nums->select(n | is_prime(n))->collect(n | (n)))->size())->display(); operation is_prime(num : OclAny) : OclAny pre: true post: true activity: if num < 2 then ( return false ) else ( var num_sqrt : double := ((num)->sqrt())->floor() ; for prime : Integer.subrange(2, num_sqrt + 1-1) do ( if num mod prime = 0 then ( return false ; break ) else skip) ; return true ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- f=lambda x : 1 if x==2 or x==3 or(not x<2 and not x & 1==0 and pow(2,x-1,x)==1)else 0 print(sum(f(int(input()))for _ in range(int(input())))) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var f : Function := lambda x : OclAny in (if x = 2 or x = 3 or (not(x < 2) & not(MathLib.bitwiseAnd(x, 1) = 0) & (2)->pow(x - 1) = 1) then 1 else 0 endif) ; execute (((argument (test (logical_test (comparison (expr (atom (name f)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))) ))))))) (comp_for for (exprlist (expr (atom (name _)))) in (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))))))))) ))))))))) )))))))))->sum())->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from collections import defaultdict if __name__=="__main__" : num_query=int(input()) d : defaultdict=defaultdict() for _ in range(num_query): op,*v=input().split() if("0"==op): d[v[0]]=v[1] elif("1"==op): if d.get(v[0]): print(d.get(v[0])) else : print(0) else : d[v[0]]=0 ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = "__main__" then ( var num_query : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var d : OclAny := defaultdict() ; for _anon : Integer.subrange(0, num_query-1) do ( var op : OclAny := null; var v : OclAny := null; Sequence{op,v} := input().split() ; if ("0" = op) then ( d[v->first()+1] := v[1+1] ) else (if ("1" = op) then ( if d.get(v->first()) then ( execute (d.get(v->first()))->display() ) else ( execute (0)->display() ) ) else ( d[v->first()+1] := 0 ) ) ) ) else skip; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def maybe_prime(d,s,n): for a in(2,3,5,7): x=pow(a,d,n) if x==1 or x==n-1 : continue for i in range(1,s): x=pow(x,2,n) if x==1 : return False elif x==n-1 : break else : return False return True def is_prime(n): if n in(2,3,5,7): return True elif 0 in(n % 2,n % 3,n % 5,n % 7): return False elif 0 in[n % i for i in range(11,min(n-1,50),2)]: 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) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; var cnt : int := 0 ; n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; for i : Integer.subrange(0, n-1) do ( n := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if is_prime(n) then ( cnt := cnt + 1 ) else skip) ; execute (cnt)->display(); operation maybe_prime(d : OclAny, s : OclAny, n : OclAny) : OclAny pre: true post: true activity: for a : Sequence{2, 3, 5, 7} do ( var x : double := (a)->pow(d) ; if x = 1 or x = n - 1 then ( continue ) else skip ; (compound_stmt for (exprlist (expr (atom (name i)))) in (testlist (test (logical_test (comparison (expr (atom (name range)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (number (integer 1)))))))) , (argument (test (logical_test (comparison (expr (atom (name s)))))))) )))))))) : (suite (stmt (simple_stmt (small_stmt (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name x)))))))) (assign_part = (testlist_star_expr (testlist (test (logical_test (comparison (expr (atom (name pow)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name x))))))) , (argument (test (logical_test (comparison (expr (atom (number (integer 2)))))))) , (argument (test (logical_test (comparison (expr (atom (name n)))))))) ))))))))))))) (stmt (compound_stmt if (test (logical_test (comparison (comparison (expr (atom (name x)))) == (comparison (expr (atom (number (integer 1)))))))) : (suite (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name False)))))))))) (elif_clause elif (test (logical_test (comparison (comparison (expr (atom (name x)))) == (comparison (expr (expr (atom (name n))) - (expr (atom (number (integer 1))))))))) : (suite (stmt (simple_stmt (small_stmt break)))))))) (else_clause else : (suite (stmt (simple_stmt (small_stmt return (testlist (test (logical_test (comparison (expr (atom (name False)))))))))))))) ; return true; operation is_prime(n : OclAny) : OclAny pre: true post: true activity: if (Sequence{2, 3, 5, 7})->includes(n) then ( return true ) else (if (Sequence{n mod 2, n mod 3, n mod 5, n mod 7})->includes(0) then ( return false ) else (if (Integer.subrange(11, Set{n - 1, 50}->min()-1)->select( $x | ($x - 11) mod 2 = 0 )->select(i | true)->collect(i | (n mod i)))->includes(0) then ( return false ) else ( Sequence{d,s} := Sequence{n - 1,0} ; while not(d mod 2) do ( Sequence{d,s} := Sequence{d /(2->pow(1)),s + 1}) ; return maybe_prime(d, s, n) ) ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import random def is_prime3(q,k=50): q=abs(q) if q==2 : return True if q<2 or q & 1==0 : return False d=(q-1)>>1 while d & 1==0 : d>>=1 for i in range(k): a=random.randint(1,q-1) t=d y=pow(a,t,q) while t!=q-1 and y!=1 and y!=q-1 : y=pow(y,2,q) t<<=1 if y!=q-1 and t & 1==0 : return False return True if __name__=="__main__" : n=int(input()) a=[] for i in range(n): a.append(int(input())) b=[] for i in range(n): b.append(is_prime3(a[i])) print(b.count(True)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; a := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((("" + (((OclFile["System.in"]).readLine())))->toInteger()) : a)) ; var b : Sequence := Sequence{} ; for i : Integer.subrange(0, n-1) do ( execute ((is_prime3(a[i+1])) : b)) ; execute (b->count(true))->display() ) else skip; operation is_prime3(q : OclAny, k : int) : OclAny pre: true post: true activity: if k->oclIsUndefined() then k := 50 else skip; q := (q)->abs() ; if q = 2 then ( return true ) else skip ; if q < 2 or MathLib.bitwiseAnd(q, 1) = 0 then ( return false ) else skip ; var d : int := (q - 1) /(2->pow(1)) ; while MathLib.bitwiseAnd(d, 1) = 0 do ( d := d div (2->pow(1))) ; for i : Integer.subrange(0, k-1) do ( var a : int := (1 + (OclRandom.defaultInstanceOclRandom()).nextInt(q - 1 - 1)) ; var t : int := d ; var y : double := (a)->pow(t) ; while t /= q - 1 & y /= 1 & y /= q - 1 do ( y := (y)->pow(2) ; t := t * (2->pow(1))) ; if y /= q - 1 & MathLib.bitwiseAnd(t, 1) = 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n=int(input()) count=0 def prime(m): for t in range(2,int(m**(1/2))+1): if m % t==0 : return False return True for i in range(n): k=int(input()) if k!=2 and k % 2==0 : continue if prime(k): count+=1 print(count) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; var count : int := 0 ; skip ; for i : Integer.subrange(0, n-1) do ( var k : int := ("" + (((OclFile["System.in"]).readLine())))->toInteger() ; if k /= 2 & k mod 2 = 0 then ( continue ) else skip ; if prime(k) then ( count := count + 1 ) else skip) ; execute (count)->display(); operation prime(m : OclAny) : OclAny pre: true post: true activity: for t : Integer.subrange(2, ("" + (((m)->pow((1 / 2)))))->toInteger() + 1-1) do ( if m mod t = 0 then ( return false ) else skip) ; return true; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def findNthTerm(N): ans=0 ; if(N % 2==0): ans=(N//2)*6+(N//2)*2 ; else : ans=(N//2+1)*6+(N//2)*2 ; print(ans); if __name__=='__main__' : N=3 ; findNthTerm(N); ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; if __name__ = '__main__' then ( N := 3; ; findNthTerm(N); ) else skip; operation findNthTerm(N : OclAny) pre: true post: true activity: var ans : int := 0; ; if (N mod 2 = 0) then ( ans := (N div 2) * 6 + (N div 2) * 2; ) else ( ans := (N div 2 + 1) * 6 + (N div 2) * 2; ) ; execute (ans)->display();; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def isRectangle(a,b,c,d): if a==b==c==d : return True elif a==b and c==d : return True elif a==d and c==b : return True elif a==c and d==b : return True return False a,b,c,d=1,2,3,4 print("Yes" if isRectangle(a,b,c,d)else "No") ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; Sequence{a,b,c,d} := Sequence{1,2,3,4} ; execute (if isRectangle(a, b, c, d) then "Yes" else "No" endif)->display(); operation isRectangle(a : OclAny, b : OclAny, c : OclAny, d : OclAny) : OclAny pre: true post: true activity: if a = b & (b == c) & (c == d) then ( return true ) else (if a = b & c = d then ( return true ) else (if a = d & c = b then ( return true ) else (if a = c & d = b then ( return true ) else skip ) ) ) ; return false; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- n,k,x=map(int,input().split()) l=sum([*map(int,input().split())][: n-k]) print(l+k*x) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var n : OclAny := null; var k : OclAny := null; var x : OclAny := null; Sequence{n,k,x} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var l : OclAny := ((input().split())->collect( _x | (OclType["int"])->apply(_x) ).subrange(1,n - k))->sum() ; execute (l + k * x)->display(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import math ; def discreteLogarithm(a,b,m): n=int(math.sqrt(m)+1); an=1 ; for i in range(n): an=(an*a)% m ; value=[0]*m ; cur=an ; for i in range(1,n+1): if(value[cur]==0): value[cur]=i ; cur=(cur*an)% m ; cur=b ; for i in range(n+1): if(value[cur]>0): ans=value[cur]*n-i ; if(ansdisplay(); ; a := 3; ; b := 7; ; m := 11; ; execute (discreteLogarithm(a, b, m))->display();; operation discreteLogarithm(a : OclAny, b : OclAny, m : OclAny) pre: true post: true activity: var n : int := ("" + (((m)->sqrt() + 1)))->toInteger(); ; var an : int := 1; ; for i : Integer.subrange(0, n-1) do ( an := (an * a) mod m;) ; var value : Sequence := MatrixLib.elementwiseMult(Sequence{ 0 }, m); ; var cur : int := an; ; for i : Integer.subrange(1, n + 1-1) do ( if (value[cur+1] = 0) then ( value[cur+1] := i; ) else skip ; cur := (cur * an) mod m;) ; cur := b; ; for i : Integer.subrange(0, n + 1-1) do ( if (value[cur+1] > 0) then ( var ans : double := value[cur+1] * n - i; ; if ((ans->compareTo(m)) < 0) then ( return ans; ) else skip ) else skip ; cur := (cur * a) mod m;) ; return -1;; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- import sys def FindMinimumCost(ind,a,n,k,dp): if(ind==(n-1)): return 0 elif(dp[ind]!=-1): return dp[ind] else : ans=sys.maxsize for i in range(1,k+1): if(ind+iunion(Sequence{30}->union(Sequence{40}->union(Sequence{50}->union(Sequence{ 20 })))) ; k := 3 ; n := (a)->size() ; dp := Integer.subrange(0, n-1)->select(i | true)->collect(i | (-1)) ; execute (FindMinimumCost(0, a, n, k, dp))->display() ) else skip; operation FindMinimumCost(ind : OclAny, a : OclAny, n : OclAny, k : OclAny, dp : OclAny) : OclAny pre: true post: true activity: if (ind = (n - 1)) then ( return 0 ) else (if (dp[ind+1] /= -1) then ( return dp[ind+1] ) else ( var ans : (trailer . (name maxsize)) := (trailer . (name maxsize)) ; for i : Integer.subrange(1, k + 1-1) do ( if ((ind + i->compareTo(n)) < 0) then ( ans := Set{ans, (a[ind + i+1] - a[ind+1])->abs() + FindMinimumCost(ind + i, a, n, k, dp)}->min() ) else ( break )) ; dp[ind+1] := ans ; return ans ) ) ; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- from math import* def Probability(sum,times): favorable,total,probability=0.0,36.0,0 for i in range(7): for j in range(7): if((i+j)==sum): favorable+=1 gcd1=gcd(int(favorable),int(total)) favorable=favorable/gcd1 total=total/gcd1 probability=pow(total,times) return int(probability) if __name__=="__main__" : sum,times=7,7 print("1","/",Probability(sum,times)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; skip ; if __name__ = "__main__" then ( Sequence{sum,times} := Sequence{7,7} ; execute ("1")->display() ) else skip; operation Probability(sum : OclAny, times : OclAny) : OclAny pre: true post: true activity: var favorable : OclAny := null; var total : OclAny := null; var probability : OclAny := null; Sequence{favorable,total,probability} := Sequence{0.0,36.0,0} ; for i : Integer.subrange(0, 7-1) do ( for j : Integer.subrange(0, 7-1) do ( if ((i + j) = sum) then ( favorable := favorable + 1 ) else skip)) ; var gcd1 : OclAny := gcd(("" + ((favorable)))->toInteger(), ("" + ((total)))->toInteger()) ; var favorable : double := favorable / gcd1 ; var total : double := total / gcd1 ; var probability : double := (total)->pow(times) ; return ("" + ((probability)))->toInteger(); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- K,N=map(int,input().split()) mod=998244353 def inved(a): x,y,u,v,k,l=1,0,0,1,a,mod while l!=0 : x,y,u,v=u,v,x-u*(k//l),y-v*(k//l) k,l=l,k % l return x % mod X=[0 for i in range(2*K-1)] frac=[1] for i in range(N+K): frac.append(((i+1)*frac[i])% mod) invf=[] for i in range(N+K+1): invf.append(inved(frac[i])) for k in range(2,K+2): S=0 sign=1 l=k//2 for m in range(min(l+1,N//2+1)): prod=(sign*(frac[l]*frac[N+K-2*m-1]))% mod prod*=(invf[m]*invf[l-m])% mod prod %=mod prod*=(invf[N-2*m]*invf[K-1])% mod prod %=mod S+=prod S %=mod sign*=-1 X[k-2],X[2*K-k]=S,S for i in range(2*K-1): print(X[i]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var K : OclAny := null; var N : OclAny := null; Sequence{K,N} := (input().split())->collect( _x | (OclType["int"])->apply(_x) ) ; var mod : int := 998244353 ; skip ; var X : Sequence := Integer.subrange(0, 2 * K - 1-1)->select(i | true)->collect(i | (0)) ; var frac : Sequence := Sequence{ 1 } ; for i : Integer.subrange(0, N + K-1) do ( execute ((((i + 1) * frac[i+1]) mod mod) : frac)) ; var invf : Sequence := Sequence{} ; for i : Integer.subrange(0, N + K + 1-1) do ( execute ((inved(frac[i+1])) : invf)) ; for k : Integer.subrange(2, K + 2-1) do ( var S : int := 0 ; var sign : int := 1 ; var l : int := k div 2 ; for m : Integer.subrange(0, Set{l + 1, N div 2 + 1}->min()-1) do ( var prod : int := (sign * (frac[l+1] * frac[N + K - 2 * m - 1+1])) mod mod ; prod := prod * (invf[m+1] * invf[l - m+1]) mod mod ; prod := prod mod mod ; prod := prod * (invf[N - 2 * m+1] * invf[K - 1+1]) mod mod ; prod := prod mod mod ; S := S + prod ; S := S mod mod ; sign := sign * -1) ; var X[k - 2+1] : OclAny := null; var X[2 * K - k+1] : OclAny := null; Sequence{X[k - 2+1],X[2 * K - k+1]} := Sequence{S,S}) ; for i : Integer.subrange(0, 2 * K - 1-1) do ( execute (X[i+1])->display()); operation inved(a : OclAny) : OclAny pre: true post: true activity: var x : OclAny := null; var y : OclAny := null; var u : OclAny := null; var v : OclAny := null; var k : OclAny := null; var l : OclAny := null; Sequence{x,y,u,v,k,l} := Sequence{1,0,0,1,a,mod} ; while l /= 0 do ( var x : OclAny := null; var y : OclAny := null; var u : OclAny := null; var v : OclAny := null; Sequence{x,y,u,v} := Sequence{u,v,x - u * (k div l),y - v * (k div l)} ; var k : OclAny := null; var l : OclAny := null; Sequence{k,l} := Sequence{l,k mod l}) ; return x mod mod; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- K,N=(int(i)for i in input().split()) mod,ans,kn=998244353,[],K+N fn,fk=[1]*kn,[1]*kn for i in range(kn-1): fn[i+1]=(fn[i]*(i+2))% mod def power(n,k): if k==1 : return n elif k % 2==0 : return power((n**2)% mod,k//2) else : return(n*power(n,k-1))% mod def comb(n,k): if n==0 or k==0 or n==k : return 1 else : return(((fn[n-1]*fk[n-k-1])% mod)*fk[k-1])% mod fk[-1]=power(fn[-1],mod-2) for i in range(2,kn+1): fk[-i]=(fk[-i+1]*(kn+2-i))% mod x=comb(kn-1,N) for i in range(2,K+2): num,c,y,p=N-2,1,0,i//2 while num>-1 and c<=p : if c % 2 : y=(y+comb(p,c)*comb(K+num-1,num))% mod else : y=(y-comb(p,c)*comb(K+num-1,num))% mod num,c=num-2,c+1 ans.append((x-y)% mod) for i in range(2,K+2): print(ans[i-2]) for i in range(K,1,-1): print(ans[i-2]) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: var K : OclAny := null; var N : OclAny := null; Sequence{K,N} := Sequence{(testlist_comp (test (logical_test (comparison (expr (atom (name int)) (trailer (arguments ( (arglist (argument (test (logical_test (comparison (expr (atom (name i)))))))) ))))))) (comp_for for (exprlist (expr (atom (name i)))) in (logical_test (comparison (expr (atom (name input)) (trailer (arguments ( ))) (trailer . (name split) (arguments ( ))))))))} ; var mod : OclAny := null; var ans : OclAny := null; var kn : OclAny := null; Sequence{mod,ans,kn} := Sequence{998244353,Sequence{},K + N} ; var fn : OclAny := null; var fk : OclAny := null; Sequence{fn,fk} := Sequence{MatrixLib.elementwiseMult(Sequence{ 1 }, kn),MatrixLib.elementwiseMult(Sequence{ 1 }, kn)} ; for i : Integer.subrange(0, kn - 1-1) do ( fn[i + 1+1] := (fn[i+1] * (i + 2)) mod mod) ; skip ; skip ; fk->last() := power(fn->last(), mod - 2) ; for i : Integer.subrange(2, kn + 1-1) do ( fk->reverse()->at(-(-i)) := (fk->reverse()->at(-(-i + 1)) * (kn + 2 - i)) mod mod) ; var x : OclAny := comb(kn - 1, N) ; for i : Integer.subrange(2, K + 2-1) do ( var num : OclAny := null; var c : OclAny := null; var y : OclAny := null; var p : OclAny := null; Sequence{num,c,y,p} := Sequence{N - 2,1,0,i div 2} ; while num > -1 & (c->compareTo(p)) <= 0 do ( if c mod 2 then ( var y : int := (y + comb(p, c) * comb(K + num - 1, num)) mod mod ) else ( y := (y - comb(p, c) * comb(K + num - 1, num)) mod mod ) ; var num : OclAny := null; var c : OclAny := null; Sequence{num,c} := Sequence{num - 2,c + 1}) ; execute (((x - y) mod mod) : ans)) ; for i : Integer.subrange(2, K + 2-1) do ( execute (ans[i - 2+1])->display()) ; for i : Integer.subrange(1 + 1, K)->reverse() do ( execute (ans[i - 2+1])->display()); operation power(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if k = 1 then ( return n ) else (if k mod 2 = 0 then ( return power(((n)->pow(2)) mod mod, k div 2) ) else ( return (n * power(n, k - 1)) mod mod ) ) ; operation comb(n : OclAny, k : OclAny) : OclAny pre: true post: true activity: if n = 0 or k = 0 or n = k then ( return 1 ) else ( return (((fn[n - 1+1] * fk[n - k - 1+1]) mod mod) * fk[k - 1+1]) mod mod ); } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- def minSum(arr,n): sum=arr[0]; prev=arr[0] for i in range(1,n): if arr[i]<=prev : prev=prev+1 sum=sum+prev else : sum=sum+arr[i] prev=arr[i] return sum arr=[2,2,3,5,6] n=len(arr) print(minSum(arr,n)) ------------------------------------------------------------ OCL File: --------- class FromPython { operation initialise() pre: true post: true activity: skip ; arr := Sequence{2}->union(Sequence{2}->union(Sequence{3}->union(Sequence{5}->union(Sequence{ 6 })))) ; n := (arr)->size() ; execute (minSum(arr, n))->display(); operation minSum(arr : OclAny, n : OclAny) : OclAny pre: true post: true activity: var sum : OclAny := arr->first(); var prev : OclAny := arr->first() ; for i : Integer.subrange(1, n-1) do ( if (arr[i+1]->compareTo(prev)) <= 0 then ( prev := prev + 1 ; sum := sum + prev ) else ( sum := sum + arr[i+1] ; prev := arr[i+1] )) ; return sum; } ------------------------------------------------------------ ------------------------------------------------------------ Python Program: --------------- MOD=998244353 k,n=map(int,input().split()) facts=[1] invs=[1] pow2=[1] for i in range(1,n+k): f=i*facts[i-1]% MOD facts.append(f) invs.append(pow(f,MOD-2,MOD)) pow2.append(2**i % MOD) def nCk(n,k): return(facts[n]*invs[k]*invs[n-k])% MOD def nHk(n,k): return nCk(n+k-1,n-1) ans=[] for i in range(2,k+2): p=i//2 ans_i=0 for q in range(min(p+1,n+1)): if k-i+q<0 : continue if i % 2>0 : ans_i=ans[-1] break else : ans_iq=0 if q>0 and k-i+q>0 : ans_iq=(ans_iq+pow2[q-1]*nCk(p-1,q-1)*nHk(k-(i-1)+(q-1),n-q))% MOD if q